Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / llvm / test / ExecutionEngine / JITLink / AArch64 / ELF_relocations.s
blobb260961f741d72ccacd9a29cf32de165920efaa4
1 # RUN: rm -rf %t && mkdir -p %t
2 # RUN: llvm-mc -triple=aarch64-unknown-linux-gnu -relax-relocations=false \
3 # RUN: -position-independent -filetype=obj -o %t/elf_reloc.o %s
4 # RUN: llvm-jitlink -noexec \
5 # RUN: -abs external_data=0xdeadbeef \
6 # RUN: -abs external_func=0xcafef00d \
7 # RUN: -check %s %t/elf_reloc.o
9 .text
11 .globl main
12 .p2align 2
13 .type main,@function
14 main:
15 ret
17 .size main, .-main
19 # Check R_AARCH64_CALL26 / R_AARCH64_JUMP26 relocation of a local function call
21 # jitlink-check: decode_operand(local_func_call26, 0)[25:0] = (local_func - local_func_call26)[27:2]
22 # jitlink-check: decode_operand(local_func_jump26, 0)[25:0] = (local_func - local_func_jump26)[27:2]
23 .globl local_func
24 .p2align 2
25 .type local_func,@function
26 local_func:
27 ret
28 .size local_func, .-local_func
30 .globl local_func_call26
31 .p2align 2
32 local_func_call26:
33 bl local_func
34 .size local_func_call26, .-local_func_call26
36 .globl local_func_jump26
37 .p2align 2
38 local_func_jump26:
39 b local_func
40 .size local_func_jump26, .-local_func_jump26
42 # Check R_AARCH64_ADR_PREL_LO21 relocation of a local symbol
44 # jitlink-check: decode_operand(test_adr_prel_lo21, 1) = (adr_data - test_adr_prel_lo21)[20:0]
45 .globl test_adr_prel_lo21, adr_data
46 .p2align 2
47 test_adr_prel_lo21:
48 adr x0, adr_data
49 .size test_adr_prel_lo21, .-test_adr_prel_lo21
50 ## ADR encoding is a bit tricky so use an offset with an irregular bit pattern
51 ## to test this bit better
52 adr_data = test_adr_prel_lo21 + 0xe46f2
54 # Check R_AARCH64_ADR_PREL_PG_HI21 / R_AARCH64_ADD_ABS_LO12_NC relocation of a local symbol
56 # For the ADR_PREL_PG_HI21/ADRP instruction we have the 21-bit delta to the 4k page
57 # containing the global.
59 # jitlink-check: decode_operand(test_adr_prel, 1) = (named_data - test_adr_prel)[32:12]
60 # jitlink-check: decode_operand(test_add_abs_lo12, 2) = (named_data + 0)[11:0]
61 .globl test_adr_prel
62 .p2align 2
63 test_adr_prel:
64 adrp x0, named_data
65 .size test_adr_prel, .-test_adr_prel
67 .globl test_add_abs_lo12
68 .p2align 2
69 test_add_abs_lo12:
70 add x0, x0, :lo12:named_data
71 .size test_add_abs_lo12, .-test_add_abs_lo12
73 # Check that calls/jumps to external functions trigger the generation of stubs and GOT
74 # entries.
76 # jitlink-check: decode_operand(test_external_call, 0) = (stub_addr(elf_reloc.o, external_func) - test_external_call)[27:2]
77 # jitlink-check: decode_operand(test_external_jump, 0) = (stub_addr(elf_reloc.o, external_func) - test_external_jump)[27:2]
78 # jitlink-check: *{8}(got_addr(elf_reloc.o, external_func)) = external_func
79 .globl test_external_call
80 .p2align 2
81 test_external_call:
82 bl external_func
83 .size test_external_call, .-test_external_call
85 .globl test_external_jump
86 .p2align 2
87 test_external_jump:
88 b external_func
89 .size test_external_jump, .-test_external_jump
91 # Check R_AARCH64_LDST*_ABS_LO12_NC relocation of a local symbol
93 # The immediate value should be the symbol address right shifted according to its instruction bitwidth.
95 # jitlink-check: decode_operand(test_ldrb, 2) = named_data[11:0]
96 # jitlink-check: decode_operand(test_ldrsb, 2) = (named_data + 0)[11:0]
97 # jitlink-check: decode_operand(test_ldrh, 2) = (named_data + 0)[11:1]
98 # jitlink-check: decode_operand(test_ldrsh, 2) = (named_data + 0)[11:1]
99 # jitlink-check: decode_operand(test_ldr_32bit, 2) = (named_data + 0)[11:2]
100 # jitlink-check: decode_operand(test_ldr_64bit, 2) = (named_data + 0)[11:3]
101 # jitlink-check: decode_operand(test_strb, 2) = named_data[11:0]
102 # jitlink-check: decode_operand(test_strh, 2) = (named_data + 0)[11:1]
103 # jitlink-check: decode_operand(test_str_32bit, 2) = (named_data + 0)[11:2]
104 # jitlink-check: decode_operand(test_str_64bit, 2) = (named_data + 0)[11:3]
106 .globl test_ldrb
107 test_ldrb:
108 ldrb w0, [x1, :lo12:named_data]
109 .size test_ldrb, .-test_ldrb
111 .globl test_ldrsb
112 test_ldrsb:
113 ldrsb w0, [x1, :lo12:named_data]
114 .size test_ldrsb, .-test_ldrsb
116 .globl test_ldrh
117 test_ldrh:
118 ldrh w0, [x1, :lo12:named_data]
119 .size test_ldrh, .-test_ldrh
121 .globl test_ldrsh
122 test_ldrsh:
123 ldrsh w0, [x1, :lo12:named_data]
124 .size test_ldrsh, .-test_ldrsh
126 .globl test_ldr_32bit
127 test_ldr_32bit:
128 ldr w0, [x1, :lo12:named_data]
129 .size test_ldr_32bit, .-test_ldr_32bit
131 .globl test_ldr_64bit
132 test_ldr_64bit:
133 ldr x0, [x1, :lo12:named_data]
134 .size test_ldr_64bit, .-test_ldr_64bit
136 .globl test_strb
137 test_strb:
138 strb w0, [x1, :lo12:named_data]
139 .size test_strb, .-test_strb
141 .globl test_strh
142 test_strh:
143 strh w0, [x1, :lo12:named_data]
144 .size test_strh, .-test_strh
146 .globl test_str_32bit
147 test_str_32bit:
148 str w0, [x1, :lo12:named_data]
149 .size test_str_32bit, .-test_str_32bit
151 .globl test_str_64bit
152 test_str_64bit:
153 str x0, [x1, :lo12:named_data]
154 .size test_str_64bit, .-test_str_64bit
157 # Check R_AARCH64_MOVW_UABS_G*_NC relocation of a local symbol
159 # The immediate value should be the symbol address right shifted according to LSL value
161 # jitlink-check: decode_operand(test_movz_g0_nc, 1) = named_data[15:0]
162 # jitlink-check: decode_operand(test_movk_g0_nc, 2) = named_data[15:0]
163 # jitlink-check: decode_operand(test_movz_g1_nc, 1) = named_data[31:16]
164 # jitlink-check: decode_operand(test_movk_g1_nc, 2) = named_data[31:16]
165 # jitlink-check: decode_operand(test_movz_g2_nc, 1) = named_data[47:32]
166 # jitlink-check: decode_operand(test_movk_g2_nc, 2) = named_data[47:32]
167 # jitlink-check: decode_operand(test_movz_g3, 1) = named_data[63:48]
168 # jitlink-check: decode_operand(test_movk_g3, 2) = named_data[63:48]
170 .globl test_movz_g0_nc
171 test_movz_g0_nc:
172 movz x0, #:abs_g0_nc:named_data
173 .size test_movz_g0_nc, .-test_movz_g0_nc
175 .globl test_movk_g0_nc
176 test_movk_g0_nc:
177 movk x0, #:abs_g0_nc:named_data
178 .size test_movk_g0_nc, .-test_movk_g0_nc
180 .globl test_movz_g1_nc
181 test_movz_g1_nc:
182 movz x0, #:abs_g1_nc:named_data
183 .size test_movz_g1_nc, .-test_movz_g1_nc
185 .globl test_movk_g1_nc
186 test_movk_g1_nc:
187 movk x0, #:abs_g1_nc:named_data
188 .size test_movk_g1_nc, .-test_movk_g1_nc
190 .globl test_movz_g2_nc
191 test_movz_g2_nc:
192 movz x0, #:abs_g2_nc:named_data
193 .size test_movz_g2_nc, .-test_movz_g2_nc
195 .globl test_movk_g2_nc
196 test_movk_g2_nc:
197 movk x0, #:abs_g2_nc:named_data
198 .size test_movk_g2_nc, .-test_movk_g2_nc
200 .globl test_movk_g3
201 test_movk_g3:
202 movk x0, #:abs_g3:named_data
203 .size test_movk_g3, .-test_movk_g3
205 .globl test_movz_g3
206 test_movz_g3:
207 movz x0, #:abs_g3:named_data
208 .size test_movz_g3, .-test_movz_g3
210 # Check R_AARCH64_ABS64 relocation of a function pointer to local symbol
212 # jitlink-check: *{8}local_func_addr_quad = named_func
213 .globl local_func_addr_quad
214 .p2align 3
215 local_func_addr_quad:
216 .xword named_func
217 .size local_func_addr_quad, 8
219 # Check R_AARCH64_ABS64 relocation of a function pointer to external symbol
221 # jitlink-check: *{8}external_func_addr_quad = external_func
222 .globl external_func_addr_quad
223 .p2align 3
224 external_func_addr_quad:
225 .xword external_func
226 .size external_func_addr_quad, 8
228 # Check R_AARCH64_ADR_GOT_PAGE / R_AARCH64_LD64_GOT_LO12_NC handling with a
229 # reference to an external symbol. Validate both the reference to the GOT entry,
230 # and also the content of the GOT entry.
232 # For the ADRP :got: instruction we have the 21-bit delta to the 4k page
233 # containing the GOT entry for external_data.
235 # For the LDR :got_lo12: instruction we have the 12-bit offset of the entry
236 # within the page.
238 # jitlink-check: *{8}(got_addr(elf_reloc.o, external_data)) = external_data
239 # jitlink-check: decode_operand(test_adr_gotpage_external, 1) = \
240 # jitlink-check: (got_addr(elf_reloc.o, external_data)[32:12] - \
241 # jitlink-check: test_adr_gotpage_external[32:12])
242 # jitlink-check: decode_operand(test_ld64_gotlo12_external, 2) = \
243 # jitlink-check: got_addr(elf_reloc.o, external_data)[11:3]
244 .globl test_adr_gotpage_external
245 .p2align 2
246 test_adr_gotpage_external:
247 adrp x0, :got:external_data
248 .size test_adr_gotpage_external, .-test_adr_gotpage_external
250 .globl test_ld64_gotlo12_external
251 .p2align 2
252 test_ld64_gotlo12_external:
253 ldr x0, [x0, :got_lo12:external_data]
254 .size test_ld64_gotlo12_external, .-test_ld64_gotlo12_external
256 # Check R_AARCH64_TSTBR14 for tbz
258 # jitlink-check: decode_operand(test_tstbr14_tbz, 2) = \
259 # jitlink-check: (test_tstbr14_tbz_target - test_tstbr14_tbz)[16:2]
260 .globl test_tstbr14_tbz, test_tstbr14_tbz_target
261 .p2align 2
262 test_tstbr14_tbz:
263 tbz x0, 0, test_tstbr14_tbz_target
264 .skip (1 << 14)
265 test_tstbr14_tbz_target:
266 .size test_tstbr14_tbz, .-test_tstbr14_tbz
268 # Check R_AARCH64_TSTBR14 for tbnz
270 # jitlink-check: decode_operand(test_tstbr14_tbnz, 2) = \
271 # jitlink-check: (test_tstbr14_tbnz_target - test_tstbr14_tbnz)[16:2]
272 .globl test_tstbr14_tbnz, test_tstbr14_tbnz_target
273 .p2align 2
274 test_tstbr14_tbnz:
275 tbnz x0, 0, test_tstbr14_tbnz_target
276 .skip (1 << 14)
277 test_tstbr14_tbnz_target:
278 .size test_tstbr14_tbnz, .-test_tstbr14_tbnz
280 # Check R_AARCH64_CONDBR19 for compare and branch instructions
282 # jitlink-check: decode_operand(test_condbr19_cbz, 1) = \
283 # jitlink-check: (test_condbr19_cbz_target - test_condbr19_cbz)[21:2]
284 .globl test_condbr19_cbz, test_condbr19_cbz_target
285 .p2align 2
286 test_condbr19_cbz:
287 cbz x0, test_condbr19_cbz_target
288 .skip (1 << 19)
289 test_condbr19_cbz_target:
290 .size test_condbr19_cbz, .-test_condbr19_cbz
292 # Check R_AARCH64_CONDBR19 for conditional branch instructions
294 # jitlink-check: decode_operand(test_condbr19_bc, 1) = \
295 # jitlink-check: (test_condbr19_bc_target - test_condbr19_bc)[21:2]
296 .globl test_condbr19_bc, test_condbr19_bc_target
297 .p2align 2
298 test_condbr19_bc:
299 b.eq test_condbr19_bc_target
300 .skip (1 << 19)
301 test_condbr19_bc_target:
302 .size test_condbr19_bc, .-test_condbr19_bc
304 .globl named_data
305 .p2align 4
306 .type named_data,@object
307 named_data:
308 .quad 0x2222222222222222
309 .quad 0x3333333333333333
310 .size named_data, .-named_data
312 .globl named_func
313 .p2align 2
314 .type named_func,@function
315 named_func:
317 .size named_func, .-named_func