Skip to content

Commit 463b3cb

Browse files
authored
[lld][WebAssembly] Abide by configured page size for memory imports (#146916)
This was an oversight in #128942 where I forgot to add the configured page size to the `WasmLimits` in the import we emit when importing a memory. Fixes: #146713
1 parent c30b5b1 commit 463b3cb

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

lld/test/wasm/page-size.s

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,21 @@ foo:
4141
# CHECK-DEFAULT-DIS: <_start>:
4242
# CHECK-DEFAULT-DIS: i32.const 65536
4343
# CHECK-DEFAULT-DIS-NEXT: end
44+
45+
# RUN: wasm-ld -no-gc-sections -o %t.custom-import.wasm %t.o --page-size=1 --import-memory
46+
# RUN: obj2yaml %t.custom-import.wasm | FileCheck %s --check-prefix=CHECK-CUSTOM-IMPORT
47+
48+
# CHECK-CUSTOM-IMPORT: Imports:
49+
# CHECK-CUSTOM-IMPORT-NEXT: - Module: env
50+
# CHECK-CUSTOM-IMPORT-NEXT: Field: memory
51+
# CHECK-CUSTOM-IMPORT-NEXT: Kind: MEMORY
52+
# CHECK-CUSTOM-IMPORT-NEXT: Memory:
53+
# CHECK-CUSTOM-IMPORT-NEXT: Flags: [ HAS_PAGE_SIZE ]
54+
# CHECK-CUSTOM-IMPORT-NEXT: Minimum: 0x10410
55+
# CHECK-CUSTOM-IMPORT-NEXT: PageSize: 0x1
56+
57+
# RUN: llvm-objdump --disassemble-symbols=_start %t.custom-import.wasm | FileCheck %s --check-prefix=CHECK-CUSTOM-IMPORT-DIS
58+
59+
# CHECK-CUSTOM-IMPORT-DIS: <_start>:
60+
# CHECK-CUSTOM-IMPORT-DIS: i32.const 1
61+
# CHECK-CUSTOM-IMPORT-DIS-NEXT: end

lld/wasm/SyntheticSections.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,10 @@ void ImportSection::writeBody() {
258258
import.Memory.Flags |= WASM_LIMITS_FLAG_IS_SHARED;
259259
if (is64)
260260
import.Memory.Flags |= WASM_LIMITS_FLAG_IS_64;
261+
if (ctx.arg.pageSize != WasmDefaultPageSize) {
262+
import.Memory.Flags |= WASM_LIMITS_FLAG_HAS_PAGE_SIZE;
263+
import.Memory.PageSize = ctx.arg.pageSize;
264+
}
261265
writeImport(os, import);
262266
}
263267

0 commit comments

Comments
 (0)