Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / lld / test / wasm / tls-non-shared-memory.s
bloba2e2257cc9392ebce908a9504dfdfce676d81730
1 # Test that linking without shared memory causes __tls_base to be
2 # internalized.
4 # RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown -o %t.o %s
6 .globaltype __tls_base, i32
8 .globl get_tls1
9 get_tls1:
10 .functype get_tls1 () -> (i32)
11 global.get __tls_base
12 i32.const tls1@TLSREL
13 i32.add
14 end_function
16 .globl get_tls1_got
17 get_tls1_got:
18 .functype get_tls1_got () -> (i32)
19 global.get tls1@GOT@TLS
20 end_function
22 .section .data.no_tls,"",@
23 .globl no_tls
24 .p2align 2
25 no_tls:
26 .int32 42
27 .size no_tls, 4
29 .section .tdata.tls1,"T",@
30 .globl tls1
31 .p2align 2
32 tls1:
33 .int32 43
34 .size tls1, 2
36 .section .custom_section.target_features,"",@
37 .int8 2
38 .int8 43
39 .int8 7
40 .ascii "atomics"
41 .int8 43
42 .int8 11
43 .ascii "bulk-memory"
45 # RUN: wasm-ld --no-gc-sections --no-entry -o %t.wasm %t.o
46 # RUN: obj2yaml %t.wasm | FileCheck %s
48 # RUN: wasm-ld --experimental-pic -shared -o %t.so %t.o
49 # RUN: obj2yaml %t.so | FileCheck %s --check-prefixes=SHARED,PIC
51 # RUN: wasm-ld --experimental-pic --no-gc-sections --no-entry -pie -o %t-pie.wasm %t.o
52 # RUN: obj2yaml %t-pie.wasm | FileCheck %s --check-prefixes=PIE,PIC
54 # RUN: wasm-ld --experimental-pic --features=atomics,bulk-memory,extended-const --no-gc-sections --no-entry -pie -o %t-extended-const.wasm %t.o
55 # RUN: obj2yaml %t-extended-const.wasm | FileCheck %s --check-prefixes=EXT-CONST
57 # CHECK: - Type: GLOBAL
58 # __stack_pointer
59 # CHECK-NEXT: Globals:
60 # CHECK-NEXT: - Index: 0
61 # CHECK-NEXT: Type: I32
62 # CHECK-NEXT: Mutable: true
63 # CHECK-NEXT: InitExpr:
64 # CHECK-NEXT: Opcode: I32_CONST
65 # CHECK-NEXT: Value: 66576
66 # __tls_base
67 # CHECK-NEXT: - Index: 1
68 # CHECK-NEXT: Type: I32
69 # CHECK-NEXT: Mutable: false
70 # CHECK-NEXT: InitExpr:
71 # CHECK-NEXT: Opcode: I32_CONST
72 # CHECK-NEXT: Value: 1024
73 # GOT.data.internal.tls1
74 # CHECK-NEXT: - Index: 2
75 # CHECK-NEXT: Type: I32
76 # CHECK-NEXT: Mutable: false
77 # CHECK-NEXT: InitExpr:
78 # CHECK-NEXT: Opcode: I32_CONST
79 # CHECK-NEXT: Value: 1024
80 # CHECK-NEXT: - Type: EXPORT
82 # CHECK: - Type: DATA
83 # .data
84 # CHECK-NEXT: Segments:
85 # CHECK-NEXT: - SectionOffset: 7
86 # CHECK-NEXT: InitFlags: 0
87 # CHECK-NEXT: Offset:
88 # CHECK-NEXT: Opcode: I32_CONST
89 # CHECK-NEXT: Value: 1024
90 # CHECK-NEXT: Content: 2B000000
91 # .tdata
92 # CHECK-NEXT: - SectionOffset: 17
93 # CHECK-NEXT: InitFlags: 0
94 # CHECK-NEXT: Offset:
95 # CHECK-NEXT: Opcode: I32_CONST
96 # CHECK-NEXT: Value: 1028
97 # CHECK-NEXT: Content: 2A000000
98 # CHECK-NEXT: - Type: CUSTOM
101 # In PIC mode we expect TLS data and non-TLS data to be merged into
102 # a single segment which is initialized via the __memory_base import
104 # SHARED: - Type: IMPORT
105 # SHARED-NEXT: Imports:
106 # SHARED-NEXT: - Module: env
107 # SHARED-NEXT: Field: memory
108 # SHARED-NEXT: Kind: MEMORY
109 # SHARED-NEXT: Memory:
110 # SHARED-NEXT: Minimum: 0x1
111 # SHARED-NEXT: - Module: env
112 # SHARED-NEXT: Field: __memory_base
113 # SHARED-NEXT: Kind: GLOBAL
114 # SHARED-NEXT: GlobalType: I32
116 # In SHARED mode we export the address of all data symbols.
117 # SHARED: - Type: EXPORT
118 # SHARED-NEXT: Exports:
119 # SHARED: - Name: tls1
120 # SHARED-NEXT: Kind: GLOBAL
121 # SHARED: - Name: no_tls
122 # SHARED-NEXT: Kind: GLOBAL
124 # In PIE mode we don't export data address by default.
125 # PIE: - Type: EXPORT
126 # PIE-NEXT: Exports:
127 # PIE-NEXT: - Name: memory
128 # PIE-NEXT: Kind: MEMORY
129 # PIE-NEXT: Index: 0
130 # PIE-NEXT: - Name: __wasm_apply_data_relocs
131 # PIE-NEXT: Kind: FUNCTION
132 # PIE-NEXT: Index: 1
133 # PIE-NEXT: - Type:
135 # .tdata and .data are combined into single segment in PIC mode.
136 # PIC: - Type: DATA
137 # PIC-NEXT: Segments:
138 # PIC-NEXT: - SectionOffset: 6
139 # PIC-NEXT: InitFlags: 0
140 # PIC-NEXT: Offset:
141 # PIC-NEXT: Opcode: GLOBAL_GET
142 # PIC-NEXT: Index: {{\d*}}
143 # PIC-NEXT: Content: 2B0000002A000000
144 # PIC-NEXT: - Type: CUSTOM
146 # Unless we have extended-const, in which case the merging is not needed.
147 # The first segment is placed directly at `__memory_base` and the second
148 # one is offset from `__memory_base` using `i32.add` and a constant.
150 # EXT-CONST: - Type: DATA
151 # EXT-CONST-NEXT: Segments:
152 # EXT-CONST-NEXT: - SectionOffset: 6
153 # EXT-CONST-NEXT: InitFlags: 0
154 # EXT-CONST-NEXT: Offset:
155 # EXT-CONST-NEXT: Opcode: GLOBAL_GET
156 # EXT-CONST-NEXT: Index: 1
157 # EXT-CONST-NEXT: Content: 2B000000
158 # EXT-CONST-NEXT: - SectionOffset: 18
159 # EXT-CONST-NEXT: InitFlags: 0
160 # EXT-CONST-NEXT: Offset:
161 # EXT-CONST-NEXT: Extended: true
162 # This instruction sequence decodes to:
163 # (global.get[0x23] 0x1 i32.const[0x41] 0x04 i32.add[0x6A] end[0x0b])
164 # EXT-CONST-NEXT: Body: 230141046A0B
165 # EXT-CONST-NEXT: Content: 2A000000