203 lines · plain
1# RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown -o %t.o %s2 3.globaltype __tls_base, i324.globaltype __tls_align, i32, immutable5 6.globl tls1_addr7tls1_addr:8 .functype tls1_addr () -> (i32)9 global.get __tls_base10 i32.const tls1@TLSREL11 i32.add12 end_function13 14.globl tls2_addr15tls2_addr:16 .functype tls2_addr () -> (i32)17 global.get __tls_base18 i32.const tls2@TLSREL19 i32.add20 end_function21 22.globl tls3_addr23tls3_addr:24 .functype tls3_addr () -> (i32)25 global.get __tls_base26 i32.const tls327 i32.add28 end_function29 30.globl tls_align31tls_align:32 .functype tls_align () -> (i32)33 global.get __tls_align34 end_function35 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 be39# initialized by `__wasm_apply_global_tls_relocs` which is40# called by `__wasm_init_tls`.41.globl tls1_got_addr42tls1_got_addr:43 .functype tls1_got_addr () -> (i32)44 global.get tls1@GOT@TLS45 end_function46 47.section .bss.no_tls,"",@48.globl no_tls49.p2align 250no_tls:51 .int32 052 .size no_tls, 453 54// Older versions of LLVM did not use the "T" flag so we need to support55// infering TLS from the name alone.56.section .tdata.tls1,"",@57.globl tls158.p2align 259tls1:60 .int32 161 .size tls1, 462 63.section sec_tls2,"T",@64.globl tls265.p2align 266tls2:67 .int32 168 .size tls2, 469 70.section sec_tls3,"T",@71.globl tls372.p2align 273tls3:74 .int32 075 .size tls3, 476 77.section .custom_section.target_features,"",@78 .int8 279 .int8 4380 .int8 781 .ascii "atomics"82 .int8 4383 .int8 1184 .ascii "bulk-memory"85 86# RUN: wasm-ld -no-gc-sections --shared-memory --max-memory=131072 --no-entry -o %t.wasm %t.o87# RUN: obj2yaml %t.wasm | FileCheck %s88# RUN: llvm-objdump -d --no-show-raw-insn --no-leading-addr %t.wasm | FileCheck --check-prefix=ASM %s --89 90# RUN: wasm-ld -no-gc-sections --shared-memory --max-memory=131072 --no-merge-data-segments --no-entry -o %t2.wasm %t.o91# RUN: obj2yaml %t2.wasm | FileCheck %s92 93# CHECK: - Type: GLOBAL94# __stack_pointer95# CHECK-NEXT: Globals:96# CHECK-NEXT: - Index: 097# CHECK-NEXT: Type: I3298# CHECK-NEXT: Mutable: true99# CHECK-NEXT: InitExpr:100# CHECK-NEXT: Opcode: I32_CONST101# CHECK-NEXT: Value: 65536102 103# __tls_base104# CHECK-NEXT: - Index: 1105# CHECK-NEXT: Type: I32106# CHECK-NEXT: Mutable: true107# CHECK-NEXT: InitExpr:108# CHECK-NEXT: Opcode: I32_CONST109# CHECK-NEXT: Value: 0110 111# __tls_size112# CHECK-NEXT: - Index: 2113# CHECK-NEXT: Type: I32114# CHECK-NEXT: Mutable: false115# CHECK-NEXT: InitExpr:116# CHECK-NEXT: Opcode: I32_CONST117# CHECK-NEXT: Value: 12118 119# __tls_align120# CHECK-NEXT: - Index: 3121# CHECK-NEXT: Type: I32122# CHECK-NEXT: Mutable: false123# CHECK-NEXT: InitExpr:124# CHECK-NEXT: Opcode: I32_CONST125# CHECK-NEXT: Value: 4126 127 128# ASM-LABEL: <__wasm_init_tls>:129# ASM-EMPTY:130# ASM-NEXT: local.get 0131# ASM-NEXT: global.set 1132# ASM-NEXT: local.get 0133# ASM-NEXT: i32.const 0134# ASM-NEXT: i32.const 12135# ASM-NEXT: memory.init 0, 0136# call to __wasm_apply_global_tls_relocs137# ASM-NEXT: call 3138# ASM-NEXT: end139 140# ASM-LABEL: <__wasm_apply_global_tls_relocs>:141# ASM-EMPTY:142# ASM-NEXT: global.get 1143# ASM-NEXT: i32.const 0144# ASM-NEXT: i32.add145# ASM-NEXT: global.set 4146# ASM-NEXT: end147 148# ASM-LABEL: <tls1_addr>:149# ASM-EMPTY:150# ASM-NEXT: global.get 1151# ASM-NEXT: i32.const 0152# ASM-NEXT: i32.add153# ASM-NEXT: end154 155# ASM-LABEL: <tls2_addr>:156# ASM-EMPTY:157# ASM-NEXT: global.get 1158# ASM-NEXT: i32.const 4159# ASM-NEXT: i32.add160# ASM-NEXT: end161 162# ASM-LABEL: <tls3_addr>:163# ASM-EMPTY:164# ASM-NEXT: global.get 1165# ASM-NEXT: i32.const 8166# ASM-NEXT: i32.add167# ASM-NEXT: end168 169# ASM-LABEL: <tls_align>:170# ASM-EMPTY:171# ASM-NEXT: global.get 3172# ASM-NEXT: end173 174# Also verify TLS usage with --relocatable175# RUN: wasm-ld --relocatable -o %t3.wasm %t.o176# RUN: obj2yaml %t3.wasm | FileCheck %s --check-prefix=RELOC177 178# RELOC: - Type: IMPORT179# RELOC-NEXT: Imports:180# RELOC-NEXT: - Module: env181# RELOC-NEXT: Field: __tls_base182# RELOC-NEXT: Kind: GLOBAL183# RELOC-NEXT: GlobalType: I32184# RELOC-NEXT: GlobalMutable: true185# RELOC-NEXT: - Module: env186# RELOC-NEXT: Field: __tls_align187# RELOC-NEXT: Kind: GLOBAL188# RELOC-NEXT: GlobalType: I32189# RELOC-NEXT: GlobalMutable: false190 191# RELOC: GlobalNames:192# RELOC-NEXT: - Index: 0193# RELOC-NEXT: Name: __tls_base194# RELOC-NEXT: - Index: 1195# RELOC-NEXT: Name: __tls_align196# RELOC-NEXT: - Index: 2197# RELOC-NEXT: Name: GOT.data.internal.tls1198# RELOC-NEXT: DataSegmentNames:199# RELOC-NEXT: - Index: 0200# RELOC-NEXT: Name: .tdata201# RELOC-NEXT: - Index: 1202# RELOC-NEXT: Name: .bss.no_tls203