summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lld/test/wasm/no-tls.test41
-rw-r--r--lld/wasm/Driver.cpp11
2 files changed, 47 insertions, 5 deletions
diff --git a/lld/test/wasm/no-tls.test b/lld/test/wasm/no-tls.test
new file mode 100644
index 00000000000..ed2a09251d8
--- /dev/null
+++ b/lld/test/wasm/no-tls.test
@@ -0,0 +1,41 @@
+; Testing that __tls_size and __tls_align are correctly emitted when there are
+; no thread_local variables.
+
+RUN: llc -mattr=+bulk-memory -filetype=obj %p/Inputs/start.ll -o %t.o
+
+RUN: wasm-ld -no-gc-sections --shared-memory --max-memory=131072 --allow-undefined -o %t.wasm %t.o
+RUN: obj2yaml %t.wasm | FileCheck %s
+CHECK: - Type: GLOBAL
+CHECK-NEXT: Globals:
+
+; __stack_pointer
+CHECK-NEXT: - Index: 0
+CHECK-NEXT: Type: I32
+CHECK-NEXT: Mutable: true
+CHECK-NEXT: InitExpr:
+CHECK-NEXT: Opcode: I32_CONST
+CHECK-NEXT: Value: 66560
+
+; __tls_base
+CHECK-NEXT: - Index: 1
+CHECK-NEXT: Type: I32
+CHECK-NEXT: Mutable: true
+CHECK-NEXT: InitExpr:
+CHECK-NEXT: Opcode: I32_CONST
+CHECK-NEXT: Value: 0
+
+; __tls_size
+CHECK-NEXT: - Index: 2
+CHECK-NEXT: Type: I32
+CHECK-NEXT: Mutable: false
+CHECK-NEXT: InitExpr:
+CHECK-NEXT: Opcode: I32_CONST
+CHECK-NEXT: Value: 0
+
+; __tls_align
+CHECK-NEXT: - Index: 3
+CHECK-NEXT: Type: I32
+CHECK-NEXT: Mutable: false
+CHECK-NEXT: InitExpr:
+CHECK-NEXT: Opcode: I32_CONST
+CHECK-NEXT: Value: 1
diff --git a/lld/wasm/Driver.cpp b/lld/wasm/Driver.cpp
index c3f24bec262..a1d22bf662c 100644
--- a/lld/wasm/Driver.cpp
+++ b/lld/wasm/Driver.cpp
@@ -450,10 +450,11 @@ createUndefinedGlobal(StringRef name, llvm::wasm::WasmGlobalType *type) {
return sym;
}
-static GlobalSymbol *createGlobalVariable(StringRef name, bool isMutable) {
+static GlobalSymbol *createGlobalVariable(StringRef name, bool isMutable,
+ int value) {
llvm::wasm::WasmGlobal wasmGlobal;
wasmGlobal.Type = {WASM_TYPE_I32, isMutable};
- wasmGlobal.InitExpr.Value.Int32 = 0;
+ wasmGlobal.InitExpr.Value.Int32 = value;
wasmGlobal.InitExpr.Opcode = WASM_OPCODE_I32_CONST;
wasmGlobal.SymbolName = name;
return symtab->addSyntheticGlobal(name, WASM_SYMBOL_VISIBILITY_HIDDEN,
@@ -527,9 +528,9 @@ static void createSyntheticSymbols() {
}
if (config->sharedMemory && !config->shared) {
- WasmSym::tlsBase = createGlobalVariable("__tls_base", true);
- WasmSym::tlsSize = createGlobalVariable("__tls_size", false);
- WasmSym::tlsAlign = createGlobalVariable("__tls_align", false);
+ WasmSym::tlsBase = createGlobalVariable("__tls_base", true, 0);
+ WasmSym::tlsSize = createGlobalVariable("__tls_size", false, 0);
+ WasmSym::tlsAlign = createGlobalVariable("__tls_align", false, 1);
WasmSym::initTLS = symtab->addSyntheticFunction(
"__wasm_init_tls", WASM_SYMBOL_VISIBILITY_HIDDEN,
make<SyntheticFunction>(i32ArgSignature, "__wasm_init_tls"));
OpenPOWER on IntegriCloud