-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[lld][WebAssembly] Fix visibility of __stack_pointer
global
#161284
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
Conversation
@llvm/pr-subscribers-lld-wasm Author: Sam Clegg (sbc100) ChangesThe 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. Full diff: https://github.com/llvm/llvm-project/pull/161284.diff 4 Files Affected:
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..2b50a02b79637 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,
|
@llvm/pr-subscribers-lld Author: Sam Clegg (sbc100) ChangesThe 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. Full diff: https://github.com/llvm/llvm-project/pull/161284.diff 4 Files Affected:
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..2b50a02b79637 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,
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
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.
c8a4f1f
to
895d9de
Compare
…61284) 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.
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.