Skip to content

Commit 87186b2

Browse files
committedJul 24, 2019
[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
1 parent 5202b55 commit 87186b2

File tree

2 files changed

+47
-5
lines changed

2 files changed

+47
-5
lines changed
 

‎lld/test/wasm/no-tls.test

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
; Testing that __tls_size and __tls_align are correctly emitted when there are
2+
; no thread_local variables.
3+
4+
RUN: llc -mattr=+bulk-memory -filetype=obj %p/Inputs/start.ll -o %t.o
5+
6+
RUN: wasm-ld -no-gc-sections --shared-memory --max-memory=131072 --allow-undefined -o %t.wasm %t.o
7+
RUN: obj2yaml %t.wasm | FileCheck %s
8+
CHECK: - Type: GLOBAL
9+
CHECK-NEXT: Globals:
10+
11+
; __stack_pointer
12+
CHECK-NEXT: - Index: 0
13+
CHECK-NEXT: Type: I32
14+
CHECK-NEXT: Mutable: true
15+
CHECK-NEXT: InitExpr:
16+
CHECK-NEXT: Opcode: I32_CONST
17+
CHECK-NEXT: Value: 66560
18+
19+
; __tls_base
20+
CHECK-NEXT: - Index: 1
21+
CHECK-NEXT: Type: I32
22+
CHECK-NEXT: Mutable: true
23+
CHECK-NEXT: InitExpr:
24+
CHECK-NEXT: Opcode: I32_CONST
25+
CHECK-NEXT: Value: 0
26+
27+
; __tls_size
28+
CHECK-NEXT: - Index: 2
29+
CHECK-NEXT: Type: I32
30+
CHECK-NEXT: Mutable: false
31+
CHECK-NEXT: InitExpr:
32+
CHECK-NEXT: Opcode: I32_CONST
33+
CHECK-NEXT: Value: 0
34+
35+
; __tls_align
36+
CHECK-NEXT: - Index: 3
37+
CHECK-NEXT: Type: I32
38+
CHECK-NEXT: Mutable: false
39+
CHECK-NEXT: InitExpr:
40+
CHECK-NEXT: Opcode: I32_CONST
41+
CHECK-NEXT: Value: 1

‎lld/wasm/Driver.cpp

+6-5
Original file line numberDiff line numberDiff line change
@@ -450,10 +450,11 @@ createUndefinedGlobal(StringRef name, llvm::wasm::WasmGlobalType *type) {
450450
return sym;
451451
}
452452

453-
static GlobalSymbol *createGlobalVariable(StringRef name, bool isMutable) {
453+
static GlobalSymbol *createGlobalVariable(StringRef name, bool isMutable,
454+
int value) {
454455
llvm::wasm::WasmGlobal wasmGlobal;
455456
wasmGlobal.Type = {WASM_TYPE_I32, isMutable};
456-
wasmGlobal.InitExpr.Value.Int32 = 0;
457+
wasmGlobal.InitExpr.Value.Int32 = value;
457458
wasmGlobal.InitExpr.Opcode = WASM_OPCODE_I32_CONST;
458459
wasmGlobal.SymbolName = name;
459460
return symtab->addSyntheticGlobal(name, WASM_SYMBOL_VISIBILITY_HIDDEN,
@@ -527,9 +528,9 @@ static void createSyntheticSymbols() {
527528
}
528529

529530
if (config->sharedMemory && !config->shared) {
530-
WasmSym::tlsBase = createGlobalVariable("__tls_base", true);
531-
WasmSym::tlsSize = createGlobalVariable("__tls_size", false);
532-
WasmSym::tlsAlign = createGlobalVariable("__tls_align", false);
531+
WasmSym::tlsBase = createGlobalVariable("__tls_base", true, 0);
532+
WasmSym::tlsSize = createGlobalVariable("__tls_size", false, 0);
533+
WasmSym::tlsAlign = createGlobalVariable("__tls_align", false, 1);
533534
WasmSym::initTLS = symtab->addSyntheticFunction(
534535
"__wasm_init_tls", WASM_SYMBOL_VISIBILITY_HIDDEN,
535536
make<SyntheticFunction>(i32ArgSignature, "__wasm_init_tls"));

0 commit comments

Comments
 (0)
Please sign in to comment.