diff --git a/lld/test/wasm/no-tls.test b/lld/test/wasm/no-tls.test new file mode 100644 --- /dev/null +++ b/lld/test/wasm/no-tls.test @@ -0,0 +1,38 @@ +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 --- a/lld/wasm/Driver.cpp +++ b/lld/wasm/Driver.cpp @@ -450,10 +450,11 @@ return sym; } -static GlobalSymbol *createGlobalVariable(StringRef name, bool isMutable) { +static GlobalSymbol *createGlobalVariable(StringRef name, bool isMutable, + int value = 0) { 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, @@ -529,7 +530,7 @@ if (config->sharedMemory && !config->shared) { WasmSym::tlsBase = createGlobalVariable("__tls_base", true); WasmSym::tlsSize = createGlobalVariable("__tls_size", false); - WasmSym::tlsAlign = createGlobalVariable("__tls_align", false); + WasmSym::tlsAlign = createGlobalVariable("__tls_align", false, 1); WasmSym::initTLS = symtab->addSyntheticFunction( "__wasm_init_tls", WASM_SYMBOL_VISIBILITY_HIDDEN, make(i32ArgSignature, "__wasm_init_tls"));