Skip to content

[lld][WebAssembly] Abide by configured page size for memory imports #146916

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

fitzgen
Copy link
Contributor

@fitzgen fitzgen commented Jul 3, 2025

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

r? @sbc100

This was an oversight in llvm#128942 where
I forgot to add the configured page size to the `WasmLimits` in the import we
emit when importing a memory.

Fixes llvm#146713
@llvmbot
Copy link
Member

llvmbot commented Jul 3, 2025

@llvm/pr-subscribers-lld

@llvm/pr-subscribers-lld-wasm

Author: Nick Fitzgerald (fitzgen)

Changes

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

r? @sbc100


Full diff: https://github.com/llvm/llvm-project/pull/146916.diff

2 Files Affected:

  • (modified) lld/test/wasm/page-size.s (+18)
  • (modified) lld/wasm/SyntheticSections.cpp (+4)
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);
   }
 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[lld][WebAssembly] using --import-memory cancels out --page-size=N options without telling user.
2 participants