[lld] 463b3cb - [lld][WebAssembly] Abide by configured page size for memory imports (#146916)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 7 09:40:12 PDT 2025
Author: Nick Fitzgerald
Date: 2025-07-07T09:40:09-07:00
New Revision: 463b3cb93fd83553f266994018f98f31854f4542
URL: https://github.com/llvm/llvm-project/commit/463b3cb93fd83553f266994018f98f31854f4542
DIFF: https://github.com/llvm/llvm-project/commit/463b3cb93fd83553f266994018f98f31854f4542.diff
LOG: [lld][WebAssembly] Abide by configured page size for memory imports (#146916)
This was an oversight in
https://github.com/llvm/llvm-project/pull/128942 where I forgot to add
the configured page size to the `WasmLimits` in the import we emit when
importing a memory.
Fixes: #146713
Added:
Modified:
lld/test/wasm/page-size.s
lld/wasm/SyntheticSections.cpp
Removed:
################################################################################
diff --git a/lld/test/wasm/page-size.s b/lld/test/wasm/page-size.s
index 9f5826109d27c..a2bf694936476 100644
--- a/lld/test/wasm/page-size.s
+++ b/lld/test/wasm/page-size.s
@@ -41,3 +41,21 @@ foo:
# CHECK-DEFAULT-DIS: <_start>:
# CHECK-DEFAULT-DIS: i32.const 65536
# CHECK-DEFAULT-DIS-NEXT: end
+
+# RUN: wasm-ld -no-gc-sections -o %t.custom-import.wasm %t.o --page-size=1 --import-memory
+# RUN: obj2yaml %t.custom-import.wasm | FileCheck %s --check-prefix=CHECK-CUSTOM-IMPORT
+
+# CHECK-CUSTOM-IMPORT: Imports:
+# CHECK-CUSTOM-IMPORT-NEXT: - Module: env
+# CHECK-CUSTOM-IMPORT-NEXT: Field: memory
+# CHECK-CUSTOM-IMPORT-NEXT: Kind: MEMORY
+# CHECK-CUSTOM-IMPORT-NEXT: Memory:
+# CHECK-CUSTOM-IMPORT-NEXT: Flags: [ HAS_PAGE_SIZE ]
+# CHECK-CUSTOM-IMPORT-NEXT: Minimum: 0x10410
+# CHECK-CUSTOM-IMPORT-NEXT: PageSize: 0x1
+
+# RUN: llvm-objdump --disassemble-symbols=_start %t.custom-import.wasm | FileCheck %s --check-prefix=CHECK-CUSTOM-IMPORT-DIS
+
+# CHECK-CUSTOM-IMPORT-DIS: <_start>:
+# CHECK-CUSTOM-IMPORT-DIS: i32.const 1
+# CHECK-CUSTOM-IMPORT-DIS-NEXT: end
diff --git a/lld/wasm/SyntheticSections.cpp b/lld/wasm/SyntheticSections.cpp
index 76719596c62e0..e1192706ea913 100644
--- a/lld/wasm/SyntheticSections.cpp
+++ b/lld/wasm/SyntheticSections.cpp
@@ -258,6 +258,10 @@ void ImportSection::writeBody() {
import.Memory.Flags |= WASM_LIMITS_FLAG_IS_SHARED;
if (is64)
import.Memory.Flags |= WASM_LIMITS_FLAG_IS_64;
+ if (ctx.arg.pageSize != WasmDefaultPageSize) {
+ import.Memory.Flags |= WASM_LIMITS_FLAG_HAS_PAGE_SIZE;
+ import.Memory.PageSize = ctx.arg.pageSize;
+ }
writeImport(os, import);
}
More information about the llvm-commits
mailing list