[lld] [lld][WebAssembly] Allow linker-synthetic symbols to be undefine when… (PR #153537)

YAMAMOTO Takashi via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 13 23:14:52 PDT 2025


================
@@ -985,23 +985,35 @@ static void createOptionalSymbols() {
 
   ctx.sym.dsoHandle = symtab->addOptionalDataSymbol("__dso_handle");
 
-  if (!ctx.arg.shared)
-    ctx.sym.dataEnd = symtab->addOptionalDataSymbol("__data_end");
-
+  auto addDataLayoutSymbol = [&](StringRef s) -> DefinedData * {
+    // Data layout symbols are either defined by lld, or (in the case
+    // of PIC code) defined by the dynamic linker / embedder.
+    if (ctx.isPic) {
+      ctx.arg.allowUndefinedSymbols.insert(s);
+      return nullptr;
+    } else {
+      return symtab->addOptionalDataSymbol(s);
+    }
+  };
+
+  ctx.sym.dataEnd = addDataLayoutSymbol("__data_end");
+  ctx.sym.stackLow = addDataLayoutSymbol("__stack_low");
+  ctx.sym.stackHigh = addDataLayoutSymbol("__stack_high");
+  ctx.sym.globalBase = addDataLayoutSymbol("__global_base");
+  ctx.sym.heapBase = addDataLayoutSymbol("__heap_base");
+  ctx.sym.heapEnd = addDataLayoutSymbol("__heap_end");
+
+  // for pic,
+  // - __memory_base and __table_base are handled in createSyntheticSymbols.
+  // - how __wasm_first_page_end should be is not clear yet.
----------------
yamt wrote:

i'm not sure how __wasm_first_page_end should work with dynamic-linking.
this PR is leaning towards the conservative side for now. ie. do not provide the symbol.

right now i can think of two ways:

a. make the runtime linker provide the global.
b. declare dynamic-linking and custom-page-sizes are not compatible.

both of them have obvious downsides.

@sbc100 @fitzgen any ideas?


https://github.com/llvm/llvm-project/pull/153537


More information about the llvm-commits mailing list