This commit adds support for WebAssembly's custom-page-sizes proposal to `wasm-ld`. An overview of the proposal can be found [here](https://github.com/WebAssembly/custom-page-sizes/blob/main/proposals/custom-page-sizes/Overview.md). In a sentence, it allows customizing a Wasm memory's page size, enabling Wasm to target environments with less than 64KiB of memory (the default Wasm page size) available for Wasm memories. This commit contains the following: * Adds a `--page-size=N` CLI flag to `wasm-ld` for configuring the linked Wasm binary's linear memory's page size. * When the page size is configured to a non-default value, then the final Wasm binary will use the encodings defined in the custom-page-sizes proposal to declare the linear memory's page size. * Defines a `__wasm_first_page_end` symbol, whose address points to the first page in the Wasm linear memory, a.k.a. is the Wasm memory's page size. This allows writing code that is compatible with any page size, and doesn't require re-compiling its object code. At the same time, because it just lowers to a constant rather than a memory access or something, it enables link-time optimization. * Adds tests for these new features. r? @sbc100 cc @sunfishcode
75 lines
2.6 KiB
YAML
75 lines
2.6 KiB
YAML
# RUN: yaml2obj %s -o %t1.o
|
|
|
|
# RUN: wasm-ld --no-entry --shared-memory --features=atomics,bulk-memory %t1.o -o - | obj2yaml | FileCheck %s --check-prefix SHARED
|
|
|
|
# RUN: not wasm-ld --no-entry --shared-memory --max-memory=100000 %t1.o -o - 2>&1 | FileCheck %s --check-prefix SHARED-UNALIGNED
|
|
|
|
# RUN: not wasm-ld --no-entry --shared-memory --max-memory=131072 --features=bulk-memory %t1.o -o - 2>&1 | FileCheck %s --check-prefix SHARED-NO-ATOMICS
|
|
|
|
# RUN: not wasm-ld --no-entry --shared-memory --max-memory=131072 --features=atomics %t1.o -o - 2>&1 | FileCheck %s --check-prefix SHARED-NO-BULK-MEM
|
|
|
|
# RUN: wasm-ld --relocatable --features=atomics %t1.o -o - | obj2yaml | FileCheck %s --check-prefix ATOMICS-RELOCATABLE
|
|
|
|
# RUN: wasm-ld --no-entry --shared-memory --max-memory=131072 --features=atomics,bulk-memory %t1.o -o - | obj2yaml | FileCheck %s --check-prefix SHARED
|
|
|
|
--- !WASM
|
|
FileHeader:
|
|
Version: 0x00000001
|
|
Sections:
|
|
- Type: IMPORT
|
|
Imports:
|
|
- Module: env
|
|
Field: __linear_memory
|
|
Kind: MEMORY
|
|
Memory:
|
|
Minimum: 0x00000001
|
|
- Module: env
|
|
Field: __indirect_function_table
|
|
Kind: TABLE
|
|
Table:
|
|
Index: 0
|
|
ElemType: FUNCREF
|
|
Limits:
|
|
Minimum: 0x00000000
|
|
- Type: DATA
|
|
Segments:
|
|
- SectionOffset: 6
|
|
InitFlags: 0
|
|
Offset:
|
|
Opcode: I32_CONST
|
|
Value: 0
|
|
Content: 68656C6C6F0A00
|
|
- Type: CUSTOM
|
|
Name: linking
|
|
Version: 2
|
|
SymbolTable:
|
|
- Index: 0
|
|
Kind: DATA
|
|
Name: hello_str
|
|
Flags: [ ]
|
|
Segment: 0
|
|
Size: 7
|
|
SegmentInfo:
|
|
- Index: 0
|
|
Name: .rodata.hello_str
|
|
Alignment: 0
|
|
Flags: [ ]
|
|
...
|
|
|
|
# SHARED-UNALIGNED: maximum memory must be aligned to the page size (65536 bytes)
|
|
|
|
# SHARED-NO-ATOMICS: 'atomics' feature must be used in order to use shared memory
|
|
|
|
# SHARED-NO-BULK-MEM: 'bulk-memory' feature must be used in order to use shared memory
|
|
|
|
# ATOMICS-RELOCATABLE: - Type: MEMORY
|
|
# ATOMICS-RELOCATABLE-NEXT: Memories:
|
|
# ATOMICS-RELOCATABLE-NEXT: Minimum: 0x1
|
|
# ATOMICS-RELOCATABLE-NEXT: - Type:
|
|
|
|
# SHARED: - Type: MEMORY
|
|
# SHARED-NEXT: Memories:
|
|
# SHARED-NEXT: - Flags: [ HAS_MAX, IS_SHARED ]
|
|
# SHARED-NEXT: Minimum: 0x2
|
|
# SHARED-NEXT: Maximum: 0x2
|