Skip to content

Commit d23f781

Browse files
authored
[lld][WebAssembly] Fix visibility of __stack_pointer global (#161284)
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.
1 parent 5d739cf commit d23f781

File tree

4 files changed

+19
-5
lines changed

4 files changed

+19
-5
lines changed

lld/test/wasm/archive-export.test

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ CHECK: Exports:
1414
CHECK-NEXT: - Name: memory
1515
CHECK-NEXT: Kind: MEMORY
1616
CHECK-NEXT: Index: 0
17+
CHECK-NEXT: - Name: __stack_pointer
18+
CHECK-NEXT: Kind: GLOBAL
19+
CHECK-NEXT: Index: 0
1720
CHECK-NEXT: - Name: foo
1821
CHECK-NEXT: Kind: FUNCTION
1922
CHECK-NEXT: Index: 1

lld/test/wasm/comdats.ll

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ entry:
3535
; CHECK-NEXT: - Name: memory
3636
; CHECK-NEXT: Kind: MEMORY
3737
; CHECK-NEXT: Index: 0
38+
; CHECK-NEXT: - Name: __stack_pointer
39+
; CHECK-NEXT: Kind: GLOBAL
40+
; CHECK-NEXT: Index: 0
3841
; CHECK-NEXT: - Name: _start
3942
; CHECK-NEXT: Kind: FUNCTION
4043
; CHECK-NEXT: Index: 1

lld/test/wasm/visibility-hidden.ll

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ entry:
4343
; CHECK-NEXT: - Name: memory
4444
; CHECK-NEXT: Kind: MEMORY
4545
; CHECK-NEXT: Index: 0
46+
; CHECK-NEXT: - Name: __stack_pointer
47+
; CHECK-NEXT: Kind: GLOBAL
48+
; CHECK-NEXT: Index: 0
4649
; CHECK-NEXT: - Name: objectDefault
4750
; CHECK-NEXT: Kind: FUNCTION
4851
; CHECK-NEXT: Index: 1

lld/wasm/Driver.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -914,9 +914,10 @@ static InputGlobal *createGlobal(StringRef name, bool isMutable) {
914914
return make<InputGlobal>(wasmGlobal, nullptr);
915915
}
916916

917-
static GlobalSymbol *createGlobalVariable(StringRef name, bool isMutable) {
917+
static GlobalSymbol *createGlobalVariable(StringRef name, bool isMutable,
918+
uint32_t flags = 0) {
918919
InputGlobal *g = createGlobal(name, isMutable);
919-
return symtab->addSyntheticGlobal(name, WASM_SYMBOL_VISIBILITY_HIDDEN, g);
920+
return symtab->addSyntheticGlobal(name, flags, g);
920921
}
921922

922923
static GlobalSymbol *createOptionalGlobal(StringRef name, bool isMutable) {
@@ -966,9 +967,13 @@ static void createSyntheticSymbols() {
966967
}
967968

968969
if (ctx.arg.sharedMemory) {
969-
ctx.sym.tlsBase = createGlobalVariable("__tls_base", true);
970-
ctx.sym.tlsSize = createGlobalVariable("__tls_size", false);
971-
ctx.sym.tlsAlign = createGlobalVariable("__tls_align", false);
970+
// TLS symbols are all hidden/dso-local
971+
ctx.sym.tlsBase =
972+
createGlobalVariable("__tls_base", true, WASM_SYMBOL_VISIBILITY_HIDDEN);
973+
ctx.sym.tlsSize = createGlobalVariable("__tls_size", false,
974+
WASM_SYMBOL_VISIBILITY_HIDDEN);
975+
ctx.sym.tlsAlign = createGlobalVariable("__tls_align", false,
976+
WASM_SYMBOL_VISIBILITY_HIDDEN);
972977
ctx.sym.initTLS = symtab->addSyntheticFunction(
973978
"__wasm_init_tls", WASM_SYMBOL_VISIBILITY_HIDDEN,
974979
make<SyntheticFunction>(is64 ? i64ArgSignature : i32ArgSignature,

0 commit comments

Comments
 (0)