[lld] [lld][WebAssembly] Fix visibility of `__stack_pointer` global (PR #161284)
Sam Clegg via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 29 14:51:07 PDT 2025
https://github.com/sbc100 updated https://github.com/llvm/llvm-project/pull/161284
>From 895d9ded7e807187442b72c30178f52131d9b89c Mon Sep 17 00:00:00 2001
From: Sam Clegg <sbc at chromium.org>
Date: Fri, 26 Sep 2025 16:50:07 -0700
Subject: [PATCH] [lld][WebAssembly] Fix visibility of `__stack_pointer` global
The stack pointer should be global, not hidden / dso-local. Marking it
as global allows it to be exported from the main module and imported
into side modules.
---
lld/test/wasm/archive-export.test | 3 +++
lld/test/wasm/comdats.ll | 3 +++
lld/test/wasm/visibility-hidden.ll | 3 +++
lld/wasm/Driver.cpp | 15 ++++++++++-----
4 files changed, 19 insertions(+), 5 deletions(-)
diff --git a/lld/test/wasm/archive-export.test b/lld/test/wasm/archive-export.test
index 9a76d60d63d91..c67e500e46dd2 100644
--- a/lld/test/wasm/archive-export.test
+++ b/lld/test/wasm/archive-export.test
@@ -14,6 +14,9 @@ CHECK: Exports:
CHECK-NEXT: - Name: memory
CHECK-NEXT: Kind: MEMORY
CHECK-NEXT: Index: 0
+CHECK-NEXT: - Name: __stack_pointer
+CHECK-NEXT: Kind: GLOBAL
+CHECK-NEXT: Index: 0
CHECK-NEXT: - Name: foo
CHECK-NEXT: Kind: FUNCTION
CHECK-NEXT: Index: 1
diff --git a/lld/test/wasm/comdats.ll b/lld/test/wasm/comdats.ll
index 8fc301e9a10e0..2dd687fbad1ef 100644
--- a/lld/test/wasm/comdats.ll
+++ b/lld/test/wasm/comdats.ll
@@ -35,6 +35,9 @@ entry:
; CHECK-NEXT: - Name: memory
; CHECK-NEXT: Kind: MEMORY
; CHECK-NEXT: Index: 0
+; CHECK-NEXT: - Name: __stack_pointer
+; CHECK-NEXT: Kind: GLOBAL
+; CHECK-NEXT: Index: 0
; CHECK-NEXT: - Name: _start
; CHECK-NEXT: Kind: FUNCTION
; CHECK-NEXT: Index: 1
diff --git a/lld/test/wasm/visibility-hidden.ll b/lld/test/wasm/visibility-hidden.ll
index 36c29a8e47385..6ed7ba3afdc02 100644
--- a/lld/test/wasm/visibility-hidden.ll
+++ b/lld/test/wasm/visibility-hidden.ll
@@ -43,6 +43,9 @@ entry:
; CHECK-NEXT: - Name: memory
; CHECK-NEXT: Kind: MEMORY
; CHECK-NEXT: Index: 0
+; CHECK-NEXT: - Name: __stack_pointer
+; CHECK-NEXT: Kind: GLOBAL
+; CHECK-NEXT: Index: 0
; CHECK-NEXT: - Name: objectDefault
; CHECK-NEXT: Kind: FUNCTION
; CHECK-NEXT: Index: 1
diff --git a/lld/wasm/Driver.cpp b/lld/wasm/Driver.cpp
index 9b85b6c00b26d..46c848d5c1232 100644
--- a/lld/wasm/Driver.cpp
+++ b/lld/wasm/Driver.cpp
@@ -914,9 +914,10 @@ static InputGlobal *createGlobal(StringRef name, bool isMutable) {
return make<InputGlobal>(wasmGlobal, nullptr);
}
-static GlobalSymbol *createGlobalVariable(StringRef name, bool isMutable) {
+static GlobalSymbol *createGlobalVariable(StringRef name, bool isMutable,
+ uint32_t flags = 0) {
InputGlobal *g = createGlobal(name, isMutable);
- return symtab->addSyntheticGlobal(name, WASM_SYMBOL_VISIBILITY_HIDDEN, g);
+ return symtab->addSyntheticGlobal(name, flags, g);
}
static GlobalSymbol *createOptionalGlobal(StringRef name, bool isMutable) {
@@ -966,9 +967,13 @@ static void createSyntheticSymbols() {
}
if (ctx.arg.sharedMemory) {
- ctx.sym.tlsBase = createGlobalVariable("__tls_base", true);
- ctx.sym.tlsSize = createGlobalVariable("__tls_size", false);
- ctx.sym.tlsAlign = createGlobalVariable("__tls_align", false);
+ // TLS symbols are all hidden/dso-local
+ ctx.sym.tlsBase =
+ createGlobalVariable("__tls_base", true, WASM_SYMBOL_VISIBILITY_HIDDEN);
+ ctx.sym.tlsSize = createGlobalVariable("__tls_size", false,
+ WASM_SYMBOL_VISIBILITY_HIDDEN);
+ ctx.sym.tlsAlign = createGlobalVariable("__tls_align", false,
+ WASM_SYMBOL_VISIBILITY_HIDDEN);
ctx.sym.initTLS = symtab->addSyntheticFunction(
"__wasm_init_tls", WASM_SYMBOL_VISIBILITY_HIDDEN,
make<SyntheticFunction>(is64 ? i64ArgSignature : i32ArgSignature,
More information about the llvm-commits
mailing list