[lld] r366948 - [WebAssembly] Set __tls_align to 1 when there is no TLS

Guanzhong Chen via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 24 14:48:14 PDT 2019


Author: quantum
Date: Wed Jul 24 14:48:14 2019
New Revision: 366948

URL: http://llvm.org/viewvc/llvm-project?rev=366948&view=rev
Log:
[WebAssembly] Set __tls_align to 1 when there is no TLS

Summary:
We want the tool conventions to state that `__tls_align` will be a power of 2.
It makes sense to not have an exception for when there is no TLS.

Reviewers: tlively, sunfish

Reviewed By: tlively

Subscribers: dschuff, sbc100, jgravelle-google, aheejin, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D65177

Added:
    lld/trunk/test/wasm/no-tls.test
Modified:
    lld/trunk/wasm/Driver.cpp

Added: lld/trunk/test/wasm/no-tls.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/wasm/no-tls.test?rev=366948&view=auto
==============================================================================
--- lld/trunk/test/wasm/no-tls.test (added)
+++ lld/trunk/test/wasm/no-tls.test Wed Jul 24 14:48:14 2019
@@ -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

Modified: lld/trunk/wasm/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/Driver.cpp?rev=366948&r1=366947&r2=366948&view=diff
==============================================================================
--- lld/trunk/wasm/Driver.cpp (original)
+++ lld/trunk/wasm/Driver.cpp Wed Jul 24 14:48:14 2019
@@ -450,10 +450,11 @@ createUndefinedGlobal(StringRef name, ll
   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"));




More information about the llvm-commits mailing list