diff options
| author | Guanzhong Chen <gzchen@google.com> | 2019-07-24 21:48:14 +0000 |
|---|---|---|
| committer | Guanzhong Chen <gzchen@google.com> | 2019-07-24 21:48:14 +0000 |
| commit | 87186b2447c8b42927fb3a25a42e97fe3bc51716 (patch) | |
| tree | 459c51410185c4a5d98a276bc85bc1785686d69c | |
| parent | 5202b55ca6d8373a68c769cc366fa14f4496ebfb (diff) | |
| download | bcm5719-llvm-87186b2447c8b42927fb3a25a42e97fe3bc51716.tar.gz bcm5719-llvm-87186b2447c8b42927fb3a25a42e97fe3bc51716.zip | |
[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
llvm-svn: 366948
| -rw-r--r-- | lld/test/wasm/no-tls.test | 41 | ||||
| -rw-r--r-- | lld/wasm/Driver.cpp | 11 |
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")); |

