[DAGCombiner] Add target hook function to decide folding (mul (add x, c1), c2)
[llvm-project.git] / llvm / test / ExecutionEngine / JITLink / AArch64 / MachO_arm64_relocations.s
blob67f07857f820c647b360ab23336f7736f44345d7
1 # RUN: rm -rf %t && mkdir -p %t
2 # RUN: llvm-mc -triple=arm64-apple-darwin19 -filetype=obj -o %t/macho_reloc.o %s
3 # RUN: llvm-jitlink -noexec -define-abs external_data=0xdeadbeef -define-abs external_func=0xcafef00d -check=%s %t/macho_reloc.o
5 .section __TEXT,__text,regular,pure_instructions
7 .p2align 2
8 Lanon_func:
9 ret
11 .globl named_func
12 .p2align 2
13 named_func:
14 ret
16 # Check ARM64_RELOC_BRANCH26 handling with a call to a local function.
17 # The branch instruction only encodes 26 bits of the 28-bit possible branch
18 # range, since the low 2 bits will always be zero.
20 # jitlink-check: decode_operand(test_local_call, 0)[25:0] = (named_func - test_local_call)[27:2]
21 .globl test_local_call
22 .p2align 2
23 test_local_call:
24 bl named_func
26 .globl _main
27 .p2align 2
28 _main:
29 ret
31 # Check ARM64_RELOC_GOTPAGE21 / ARM64_RELOC_GOTPAGEOFF12 handling with a
32 # reference to an external symbol. Validate both the reference to the GOT entry,
33 # and also the content of the GOT entry.
35 # For the GOTPAGE21/ADRP instruction we have the 21-bit delta to the 4k page
36 # containing the GOT entry for external_data.
38 # For the GOTPAGEOFF/LDR instruction we have the 12-bit offset of the entry
39 # within the page.
41 # jitlink-check: *{8}(got_addr(macho_reloc.o, external_data)) = external_data
42 # jitlink-check: decode_operand(test_gotpage21_external, 1) = \
43 # jitlink-check: (got_addr(macho_reloc.o, external_data)[32:12] - \
44 # jitlink-check: test_gotpage21_external[32:12])
45 # jitlink-check: decode_operand(test_gotpageoff12_external, 2) = \
46 # jitlink-check: got_addr(macho_reloc.o, external_data)[11:3]
47 .globl test_gotpage21_external
48 .p2align 2
49 test_gotpage21_external:
50 adrp x0, external_data@GOTPAGE
51 .globl test_gotpageoff12_external
52 test_gotpageoff12_external:
53 ldr x0, [x0, external_data@GOTPAGEOFF]
55 # Check ARM64_RELOC_GOTPAGE21 / ARM64_RELOC_GOTPAGEOFF12 handling with a
56 # reference to a defined symbol. Validate both the reference to the GOT entry,
57 # and also the content of the GOT entry.
58 # jitlink-check: *{8}(got_addr(macho_reloc.o, named_data)) = named_data
59 # jitlink-check: decode_operand(test_gotpage21_defined, 1) = \
60 # jitlink-check: (got_addr(macho_reloc.o, named_data)[32:12] - \
61 # jitlink-check: test_gotpage21_defined[32:12])
62 # jitlink-check: decode_operand(test_gotpageoff12_defined, 2) = \
63 # jitlink-check: got_addr(macho_reloc.o, named_data)[11:3]
64 .globl test_gotpage21_defined
65 .p2align 2
66 test_gotpage21_defined:
67 adrp x0, named_data@GOTPAGE
68 .globl test_gotpageoff12_defined
69 test_gotpageoff12_defined:
70 ldr x0, [x0, named_data@GOTPAGEOFF]
72 # Check ARM64_RELOC_PAGE21 / ARM64_RELOC_PAGEOFF12 handling with a reference to
73 # a local symbol.
75 # For the PAGE21/ADRP instruction we have the 21-bit delta to the 4k page
76 # containing the global.
78 # For the GOTPAGEOFF12 relocation we test the ADD instruction, all LDR/GPR
79 # variants and all LDR/Neon variants.
81 # jitlink-check: decode_operand(test_page21, 1) = ((named_data + 256) - test_page21)[32:12]
82 # jitlink-check: decode_operand(test_pageoff12add, 2) = (named_data + 256)[11:0]
83 # jitlink-check: decode_operand(test_pageoff12gpr8, 2) = (named_data + 256)[11:0]
84 # jitlink-cherk: decode_operand(test_pageoff12gpr8s, 2) = (named_data + 256)[11:0]
85 # jitlink-check: decode_operand(test_pageoff12gpr16, 2) = (named_data + 256)[11:1]
86 # jitlink-check: decode_operand(test_pageoff12gpr16s, 2) = (named_data + 256)[11:1]
87 # jitlink-check: decode_operand(test_pageoff12gpr32, 2) = (named_data + 256)[11:2]
88 # jitlink-check: decode_operand(test_pageoff12gpr64, 2) = (named_data + 256)[11:3]
89 # jitlink-check: decode_operand(test_pageoff12neon8, 2) = (named_data + 256)[11:0]
90 # jitlink-check: decode_operand(test_pageoff12neon16, 2) = (named_data + 256)[11:1]
91 # jitlink-check: decode_operand(test_pageoff12neon32, 2) = (named_data + 256)[11:2]
92 # jitlink-check: decode_operand(test_pageoff12neon64, 2) = (named_data + 256)[11:3]
93 # jitlink-check: decode_operand(test_pageoff12neon128, 2) = (named_data + 256)[11:4]
94 .globl test_page21
95 .p2align 2
96 test_page21:
97 adrp x0, named_data@PAGE + 256
99 .globl test_pageoff12add
100 test_pageoff12add:
101 add x0, x0, named_data@PAGEOFF + 256
103 .globl test_pageoff12gpr8
104 test_pageoff12gpr8:
105 ldrb w0, [x0, named_data@PAGEOFF + 256]
107 .globl test_pageoff12gpr8s
108 test_pageoff12gpr8s:
109 ldrsb w0, [x0, named_data@PAGEOFF + 256]
111 .globl test_pageoff12gpr16
112 test_pageoff12gpr16:
113 ldrh w0, [x0, named_data@PAGEOFF + 256]
115 .globl test_pageoff12gpr16s
116 test_pageoff12gpr16s:
117 ldrsh w0, [x0, named_data@PAGEOFF + 256]
119 .globl test_pageoff12gpr32
120 test_pageoff12gpr32:
121 ldr w0, [x0, named_data@PAGEOFF + 256]
123 .globl test_pageoff12gpr64
124 test_pageoff12gpr64:
125 ldr x0, [x0, named_data@PAGEOFF + 256]
127 .globl test_pageoff12neon8
128 test_pageoff12neon8:
129 ldr b0, [x0, named_data@PAGEOFF + 256]
131 .globl test_pageoff12neon16
132 test_pageoff12neon16:
133 ldr h0, [x0, named_data@PAGEOFF + 256]
135 .globl test_pageoff12neon32
136 test_pageoff12neon32:
137 ldr s0, [x0, named_data@PAGEOFF + 256]
139 .globl test_pageoff12neon64
140 test_pageoff12neon64:
141 ldr d0, [x0, named_data@PAGEOFF + 256]
143 .globl test_pageoff12neon128
144 test_pageoff12neon128:
145 ldr q0, [x0, named_data@PAGEOFF + 256]
147 # Check that calls to external functions trigger the generation of stubs and GOT
148 # entries.
150 # jitlink-check: decode_operand(test_external_call, 0) = (stub_addr(macho_reloc.o, external_func) - test_external_call)[27:2]
151 # jitlink-check: *{8}(got_addr(macho_reloc.o, external_func)) = external_func
152 .globl test_external_call
153 .p2align 2
154 test_external_call:
155 bl external_func
157 .section __DATA,__data
159 # Storage target for non-extern ARM64_RELOC_SUBTRACTOR relocs.
160 .p2align 3
161 Lanon_data:
162 .quad 0x1111111111111111
164 # Check ARM64_RELOC_SUBTRACTOR Quad/Long in anonymous storage with anonymous
165 # minuend: "LA: .quad LA - B + C". The anonymous subtrahend form
166 # "LA: .quad B - LA + C" is not tested as subtrahends are not permitted to be
167 # anonymous.
169 # Note: +8 offset in expression below to accounts for sizeof(Lanon_data).
170 # jitlink-check: *{8}(section_addr(macho_reloc.o, __DATA,__data) + 8) = \
171 # jitlink-check: (section_addr(macho_reloc.o, __DATA,__data) + 8) - named_data + 2
172 .p2align 3
173 Lanon_minuend_quad:
174 .quad Lanon_minuend_quad - named_data + 2
176 # Note: +16 offset in expression below to accounts for sizeof(Lanon_data) + sizeof(Lanon_minuend_long).
177 # jitlink-check: *{4}(section_addr(macho_reloc.o, __DATA,__data) + 16) = \
178 # jitlink-check: ((section_addr(macho_reloc.o, __DATA,__data) + 16) - named_data + 2)[31:0]
179 .p2align 2
180 Lanon_minuend_long:
181 .long Lanon_minuend_long - named_data + 2
183 # Named quad storage target (first named atom in __data).
184 # Align to 16 for use as 128-bit load target.
185 .globl named_data
186 .p2align 4
187 named_data:
188 .quad 0x2222222222222222
189 .quad 0x3333333333333333
191 # An alt-entry point for named_data
192 .globl named_data_alt_entry
193 .p2align 3
194 .alt_entry named_data_alt_entry
195 named_data_alt_entry:
196 .quad 0
198 # Check ARM64_RELOC_UNSIGNED / quad / extern handling by putting the address of
199 # a local named function into a quad symbol.
201 # jitlink-check: *{8}named_func_addr_quad = named_func
202 .globl named_func_addr_quad
203 .p2align 3
204 named_func_addr_quad:
205 .quad named_func
207 # Check ARM64_RELOC_UNSIGNED / quad / non-extern handling by putting the
208 # address of a local anonymous function into a quad symbol.
210 # jitlink-check: *{8}anon_func_addr_quad = \
211 # jitlink-check: section_addr(macho_reloc.o, __TEXT,__text)
212 .globl anon_func_addr_quad
213 .p2align 3
214 anon_func_addr_quad:
215 .quad Lanon_func
217 # ARM64_RELOC_SUBTRACTOR Quad/Long in named storage with anonymous minuend
219 # jitlink-check: *{8}anon_minuend_quad1 = \
220 # jitlink-check: section_addr(macho_reloc.o, __DATA,__data) - anon_minuend_quad1 + 2
221 # Only the form "B: .quad LA - B + C" is tested. The form "B: .quad B - LA + C" is
222 # invalid because the subtrahend can not be local.
223 .globl anon_minuend_quad1
224 .p2align 3
225 anon_minuend_quad1:
226 .quad Lanon_data - anon_minuend_quad1 + 2
228 # jitlink-check: *{4}anon_minuend_long1 = \
229 # jitlink-check: (section_addr(macho_reloc.o, __DATA,__data) - anon_minuend_long1 + 2)[31:0]
230 .globl anon_minuend_long1
231 .p2align 2
232 anon_minuend_long1:
233 .long Lanon_data - anon_minuend_long1 + 2
235 # Check ARM64_RELOC_SUBTRACTOR Quad/Long in named storage with minuend and subtrahend.
236 # Both forms "A: .quad A - B + C" and "A: .quad B - A + C" are tested.
238 # Check "A: .quad B - A + C".
239 # jitlink-check: *{8}subtrahend_quad2 = (named_data - subtrahend_quad2 - 2)
240 .globl subtrahend_quad2
241 .p2align 3
242 subtrahend_quad2:
243 .quad named_data - subtrahend_quad2 - 2
245 # Check "A: .long B - A + C".
246 # jitlink-check: *{4}subtrahend_long2 = (named_data - subtrahend_long2 - 2)[31:0]
247 .globl subtrahend_long2
248 .p2align 2
249 subtrahend_long2:
250 .long named_data - subtrahend_long2 - 2
252 # Check "A: .quad A - B + C".
253 # jitlink-check: *{8}minuend_quad3 = (minuend_quad3 - named_data - 2)
254 .globl minuend_quad3
255 .p2align 3
256 minuend_quad3:
257 .quad minuend_quad3 - named_data - 2
259 # Check "A: .long B - A + C".
260 # jitlink-check: *{4}minuend_long3 = (minuend_long3 - named_data - 2)[31:0]
261 .globl minuend_long3
262 .p2align 2
263 minuend_long3:
264 .long minuend_long3 - named_data - 2
266 # Check ARM64_RELOC_SUBTRACTOR handling for exprs of the form
267 # "A: .quad/long B - C + D", where 'B' or 'C' is at a fixed offset from 'A'
268 # (i.e. is part of an alt_entry chain that includes 'A').
270 # Check "A: .long B - C + D" where 'B' is an alt_entry for 'A'.
271 # jitlink-check: *{4}subtractor_with_alt_entry_minuend_long = (subtractor_with_alt_entry_minuend_long_B - named_data + 2)[31:0]
272 .globl subtractor_with_alt_entry_minuend_long
273 .p2align 2
274 subtractor_with_alt_entry_minuend_long:
275 .long subtractor_with_alt_entry_minuend_long_B - named_data + 2
277 .globl subtractor_with_alt_entry_minuend_long_B
278 .p2align 2
279 .alt_entry subtractor_with_alt_entry_minuend_long_B
280 subtractor_with_alt_entry_minuend_long_B:
281 .long 0
283 # Check "A: .quad B - C + D" where 'B' is an alt_entry for 'A'.
284 # jitlink-check: *{8}subtractor_with_alt_entry_minuend_quad = (subtractor_with_alt_entry_minuend_quad_B - named_data + 2)
285 .globl subtractor_with_alt_entry_minuend_quad
286 .p2align 3
287 subtractor_with_alt_entry_minuend_quad:
288 .quad subtractor_with_alt_entry_minuend_quad_B - named_data + 2
290 .globl subtractor_with_alt_entry_minuend_quad_B
291 .p2align 3
292 .alt_entry subtractor_with_alt_entry_minuend_quad_B
293 subtractor_with_alt_entry_minuend_quad_B:
294 .quad 0
296 # Check "A: .long B - C + D" where 'C' is an alt_entry for 'A'.
297 # jitlink-check: *{4}subtractor_with_alt_entry_subtrahend_long = (named_data - subtractor_with_alt_entry_subtrahend_long_B + 2)[31:0]
298 .globl subtractor_with_alt_entry_subtrahend_long
299 .p2align 2
300 subtractor_with_alt_entry_subtrahend_long:
301 .long named_data - subtractor_with_alt_entry_subtrahend_long_B + 2
303 .globl subtractor_with_alt_entry_subtrahend_long_B
304 .p2align 2
305 .alt_entry subtractor_with_alt_entry_subtrahend_long_B
306 subtractor_with_alt_entry_subtrahend_long_B:
307 .long 0
309 # Check "A: .quad B - C + D" where 'B' is an alt_entry for 'A'.
310 # jitlink-check: *{8}subtractor_with_alt_entry_subtrahend_quad = (named_data - subtractor_with_alt_entry_subtrahend_quad_B + 2)
311 .globl subtractor_with_alt_entry_subtrahend_quad
312 .p2align 3
313 subtractor_with_alt_entry_subtrahend_quad:
314 .quad named_data - subtractor_with_alt_entry_subtrahend_quad_B + 2
316 .globl subtractor_with_alt_entry_subtrahend_quad_B
317 .p2align 3
318 .alt_entry subtractor_with_alt_entry_subtrahend_quad_B
319 subtractor_with_alt_entry_subtrahend_quad_B:
320 .quad 0
322 # Check ARM64_POINTER_TO_GOT handling.
323 # ARM64_POINTER_TO_GOT is a delta-32 to a GOT entry.
325 # jitlink-check: *{4}test_got = (got_addr(macho_reloc.o, external_data) - test_got)[31:0]
326 .globl test_got
327 .p2align 2
328 test_got:
329 .long external_data@got - .
331 # Check that unreferenced atoms in no-dead-strip sections are not dead stripped.
332 # We need to use a local symbol for this as any named symbol will end up in the
333 # ORC responsibility set, which is automatically marked live and would couse
334 # spurious passes.
336 # jitlink-check: *{8}section_addr(macho_reloc.o, __DATA,__nds_test_sect) = 0
337 .section __DATA,__nds_test_sect,regular,no_dead_strip
338 .quad 0
340 # Check that unreferenced local symbols that have been marked no-dead-strip are
341 # not dead-striped.
343 # jitlink-check: *{8}section_addr(macho_reloc.o, __DATA,__nds_test_nlst) = 0
344 .section __DATA,__nds_test_nlst,regular
345 .no_dead_strip no_dead_strip_test_symbol
346 no_dead_strip_test_symbol:
347 .quad 0
349 # Check that explicit zero-fill symbols are supported
350 # jitlink-check: *{8}zero_fill_test = 0
351 .globl zero_fill_test
352 .zerofill __DATA,__zero_fill_test,zero_fill_test,8,3
354 # Check that section alignments are respected.
355 # We test this by introducing two segments with alignment 8, each containing one
356 # byte of data. We require both symbols to have an aligned address.
358 # jitlink-check: section_alignment_check1[2:0] = 0
359 # jitlink-check: section_alignment_check2[2:0] = 0
360 .section __DATA,__sec_align_chk1
361 .p2align 3
363 .globl section_alignment_check1
364 section_alignment_check1:
365 .byte 0
367 .section __DATA,__sec_align_chk2
368 .p2align 3
370 .globl section_alignment_check2
371 section_alignment_check2:
372 .byte 0
374 .subsections_via_symbols