xref: /llvm-project/lld/test/wasm/tls-init-symbols.s (revision 3cd96a7309f67ab3b91ddcbd7e6d2ba9b714aba7)
1# Regression test based on https://github.com/llvm/llvm-project/issues/54386
2# Test that that linker synthetic functions such as __wasm_tls_init and
3# __wasm_apply_global_tls_relocs can be created successfully in programs
4# that don't reference __tls_base or __wasm_tls_init.  These function both
5# reference __tls_base which need to be marks as alive if they are generated.
6
7# This is very basic TLS-using program that doesn't reference any of the
8# linker-generated symbols.
9
10# RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown -o %t.o %s
11# RUN: wasm-ld -no-gc-sections --shared-memory -o %t.wasm %t.o
12# RUN: obj2yaml %t.wasm | FileCheck %s
13# RUN: llvm-objdump -d --no-show-raw-insn --no-leading-addr %t.wasm | FileCheck %s --check-prefixes DIS
14
15.globl _start
16_start:
17  .functype _start () -> (i32)
18  global.get tls_sym@GOT@TLS
19  end_function
20
21.section  .tdata.tls_sym,"",@
22.globl  tls_sym
23.p2align  2
24tls_sym:
25  .int32  1
26  .size tls_sym, 4
27
28.section  .custom_section.target_features,"",@
29  .int8 2
30  .int8 43
31  .int8 7
32  .ascii  "atomics"
33  .int8 43
34  .int8 11
35  .ascii  "bulk-memory"
36
37# CHECK:       - Type:            CUSTOM
38# CHECK-NEXT:    Name:            name
39# CHECK-NEXT:    FunctionNames:
40# CHECK-NEXT:      - Index:           0
41# CHECK-NEXT:        Name:            __wasm_call_ctors
42# CHECK-NEXT:      - Index:           1
43# CHECK-NEXT:        Name:            __wasm_init_tls
44# CHECK-NEXT:      - Index:           2
45# CHECK-NEXT:        Name:            __wasm_init_memory
46# CHECK-NEXT:      - Index:           3
47# CHECK-NEXT:        Name:            __wasm_apply_global_tls_relocs
48# CHECK-NEXT:      - Index:           4
49# CHECK-NEXT:        Name:            _start
50
51# DIS:       <__wasm_init_tls>:
52# DIS:        local.get 0
53# DIS-NEXT:   global.set  1
54# DIS-NEXT:   local.get 0
55# DIS-NEXT:   i32.const 0
56# DIS-NEXT:   i32.const 4
57# DIS-NEXT:   memory.init 0, 0
58# DIS-NEXT:   call  3
59# DIS-NEXT:   end
60
61# DIS:      <__wasm_apply_global_tls_relocs>:
62# DIS:        global.get  1
63# DIS-NEXT:   i32.const 0
64# DIS-NEXT:   i32.add
65# DIS-NEXT:   global.set  4
66# DIS-NEXT:   end
67
68# DIS:      <_start>:
69# DIS:        global.get  4
70# DIS-NEXT:   end
71
72