1 # RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown -o %t.o %s
3 .globaltype __tls_base, i32
4 .globaltype __tls_align, i32, immutable
8 .functype tls1_addr () -> (i32)
16 .functype tls2_addr () -> (i32)
24 .functype tls3_addr () -> (i32)
32 .functype tls_align () -> (i32)
33 global.get __tls_align
36 # TLS symbols can also be accessed by `global.get tls1@GOT@TLS`
37 # which is the pattern emitted for non-DSO-local symbols.
38 # In this case the global that holds that address must be
39 # initialized by `__wasm_apply_global_tls_relocs` which is
40 # called by `__wasm_init_tls`.
43 .functype tls1_got_addr () -> (i32)
44 global.get tls1@GOT@TLS
47 .section .bss.no_tls,"",@
54 // Older versions of LLVM did
not use the
"T" flag so we need to support
55 // infering TLS from the name alone.
56 .section .tdata.tls1,"",@
63 .section sec_tls2,"T",@
70 .section sec_tls3,"T",@
77 .section .custom_section.target_features,"",@
86 # RUN: wasm-ld -no-gc-sections --shared-memory --max-memory=131072 --no-entry -o %t.wasm %t.o
87 # RUN: obj2yaml %t.wasm | FileCheck %s
88 # RUN: llvm-objdump -d --no-show-raw-insn --no-leading-addr %t.wasm | FileCheck --check-prefix=ASM %s --
90 # RUN: wasm-ld -no-gc-sections --shared-memory --max-memory=131072 --no-merge-data-segments --no-entry -o %t2.wasm %t.o
91 # RUN: obj2yaml %t2.wasm | FileCheck %s
93 # CHECK: - Type: GLOBAL
95 # CHECK-NEXT: Globals:
96 # CHECK-NEXT: - Index: 0
97 # CHECK-NEXT: Type: I32
98 # CHECK-NEXT: Mutable: true
99 # CHECK-NEXT: InitExpr:
100 # CHECK-NEXT: Opcode: I32_CONST
101 # CHECK-NEXT: Value: 66592
104 # CHECK-NEXT: - Index: 1
105 # CHECK-NEXT: Type: I32
106 # CHECK-NEXT: Mutable: true
107 # CHECK-NEXT: InitExpr:
108 # CHECK-NEXT: Opcode: I32_CONST
109 # CHECK-NEXT: Value: 0
112 # CHECK-NEXT: - Index: 2
113 # CHECK-NEXT: Type: I32
114 # CHECK-NEXT: Mutable: false
115 # CHECK-NEXT: InitExpr:
116 # CHECK-NEXT: Opcode: I32_CONST
117 # CHECK-NEXT: Value: 12
120 # CHECK-NEXT: - Index: 3
121 # CHECK-NEXT: Type: I32
122 # CHECK-NEXT: Mutable: false
123 # CHECK-NEXT: InitExpr:
124 # CHECK-NEXT: Opcode: I32_CONST
125 # CHECK-NEXT: Value: 4
128 # ASM-LABEL: <__wasm_init_tls>:
130 # ASM-NEXT: local.get 0
131 # ASM-NEXT: global.set 1
132 # ASM-NEXT: local.get 0
133 # ASM-NEXT: i32.const 0
134 # ASM-NEXT: i32.const 12
135 # ASM-NEXT: memory.init 0, 0
136 # call to __wasm_apply_global_tls_relocs>
140 # ASM-LABEL: <__wasm_apply_global_tls_relocs>:
142 # ASM-NEXT: global.get 1
143 # ASM-NEXT: i32.const 0
145 # ASM-NEXT: global.set 4
148 # ASM-LABEL: <tls1_addr>:
150 # ASM-NEXT: global.get 1
151 # ASM-NEXT: i32.const 0
155 # ASM-LABEL: <tls2_addr>:
157 # ASM-NEXT: global.get 1
158 # ASM-NEXT: i32.const 4
162 # ASM-LABEL: <tls3_addr>:
164 # ASM-NEXT: global.get 1
165 # ASM-NEXT: i32.const 8
169 # ASM-LABEL: <tls_align>:
171 # ASM-NEXT: global.get 3
174 # Also verify TLS usage with --relocatable
175 # RUN: wasm-ld --relocatable -o %t3.wasm %t.o
176 # RUN: obj2yaml %t3.wasm | FileCheck %s --check-prefix=RELOC
178 # RELOC: - Type: IMPORT
179 # RELOC-NEXT: Imports:
180 # RELOC-NEXT: - Module: env
181 # RELOC-NEXT: Field: __tls_base
182 # RELOC-NEXT: Kind: GLOBAL
183 # RELOC-NEXT: GlobalType: I32
184 # RELOC-NEXT: GlobalMutable: true
185 # RELOC-NEXT: - Module: env
186 # RELOC-NEXT: Field: __tls_align
187 # RELOC-NEXT: Kind: GLOBAL
188 # RELOC-NEXT: GlobalType: I32
189 # RELOC-NEXT: GlobalMutable: false
191 # RELOC: GlobalNames:
192 # RELOC-NEXT: - Index: 0
193 # RELOC-NEXT: Name: __tls_base
194 # RELOC-NEXT: - Index: 1
195 # RELOC-NEXT: Name: __tls_align
196 # RELOC-NEXT: - Index: 2
197 # RELOC-NEXT: Name: GOT.data.internal.tls1
198 # RELOC-NEXT: DataSegmentNames:
199 # RELOC-NEXT: - Index: 0
200 # RELOC-NEXT: Name: .tdata
201 # RELOC-NEXT: - Index: 1
202 # RELOC-NEXT: Name: .bss.no_tls