1 # RUN: rm -rf %t && mkdir -p %t
2 # RUN: llvm-mc -triple=x86_64-apple-macosx10.9 -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
17 # Check X86_64_RELOC_BRANCH handling with a call to a local function.
19 # jitlink-check: decode_operand(test_local_call, 0) = named_func - next_pc(test_local_call)
20 .globl test_local_call
31 # Check X86_64_RELOC_GOTPCREL handling with a load from an external symbol.
32 # Validate both the reference to the GOT entry, and also the content of the GOT
35 # jitlink-check: decode_operand(test_gotld, 4) = got_addr(macho_reloc.o, external_data) - next_pc(test_gotld)
36 # jitlink-check: *{8}(got_addr(macho_reloc.o, external_data)) = external_data
40 movq external_data@GOTPCREL
(%rip
), %rax
43 # Check that calls to external functions trigger the generation of stubs and GOT
46 # jitlink-check: decode_operand(test_external_call, 0) = stub_addr(macho_reloc.o, external_func) - next_pc(test_external_call)
47 # jitlink-check: *{8}(got_addr(macho_reloc.o, external_func)) = external_func
48 .globl test_external_call
54 # Check signed relocation handling:
56 # X86_64_RELOC_SIGNED / Extern -- movq address of linker global
57 # X86_64_RELOC_SIGNED1 / Extern -- movb immediate byte to linker global
58 # X86_64_RELOC_SIGNED2 / Extern -- movw immediate word to linker global
59 # X86_64_RELOC_SIGNED4 / Extern -- movl immediate long to linker global
61 # X86_64_RELOC_SIGNED / Anon -- movq address of linker private into register
62 # X86_64_RELOC_SIGNED1 / Anon -- movb immediate byte to linker private
63 # X86_64_RELOC_SIGNED2 / Anon -- movw immediate word to linker private
64 # X86_64_RELOC_SIGNED4 / Anon -- movl immediate long to linker private
67 # jitlink-check: decode_operand(signed, 4) = named_data - next_pc(signed)
69 movq named_data
(%rip
), %rax
72 # jitlink-check: decode_operand(signed1, 3) = named_data - next_pc(signed1)
74 movb $
0xAA, named_data
(%rip
)
77 # jitlink-check: decode_operand(signed2, 3) = named_data - next_pc(signed2)
79 movw $
0xAAAA, named_data
(%rip
)
82 # jitlink-check: decode_operand(signed4, 3) = named_data - next_pc(signed4)
84 movl $
0xAAAAAAAA, named_data
(%rip
)
87 # jitlink-check: decode_operand(signedanon, 4) = section_addr(macho_reloc.o, __data) - next_pc(signedanon)
89 movq Lanon_data
(%rip
), %rax
92 # jitlink-check: decode_operand(signed1anon, 3) = section_addr(macho_reloc.o, __data) - next_pc(signed1anon)
94 movb $
0xAA, Lanon_data
(%rip
)
97 # jitlink-check: decode_operand(signed2anon, 3) = section_addr(macho_reloc.o, __data) - next_pc(signed2anon)
99 movw $
0xAAAA, Lanon_data
(%rip
)
102 # jitlink-check: decode_operand(signed4anon, 3) = section_addr(macho_reloc.o, __data) - next_pc(signed4anon)
104 movl $
0xAAAAAAAA, Lanon_data
(%rip
)
108 .section __DATA,__data
110 # Storage target for non-extern X86_64_RELOC_SIGNED_(1/2/4) relocs.
113 .quad 0x1111111111111111
115 # Check X86_64_RELOC_SUBTRACTOR Quad/Long in anonymous storage with anonymous
116 # minuend: "LA: .quad LA - B + C". The anonymous subtrahend form
117 # "LA: .quad B - LA + C" is not tested as subtrahends are not permitted to be
120 # Note: +8 offset in expression below to accounts for sizeof(Lanon_data).
121 # jitlink-check: *{8}(section_addr(macho_reloc.o, __data) + 8) = (section_addr(macho_reloc.o, __data) + 8) - named_data + 2
124 .quad Lanon_minuend_quad - named_data + 2
126 # Note: +16 offset in expression below to accounts for sizeof(Lanon_data) + sizeof(Lanon_minuend_long).
127 # jitlink-check: *{4}(section_addr(macho_reloc.o, __data) + 16) = ((section_addr(macho_reloc.o, __data) + 16) - named_data + 2)[31:0]
130 .long Lanon_minuend_long - named_data + 2
132 # Check X86_64_RELOC_GOT handling.
133 # X86_64_RELOC_GOT is the data-section counterpart to X86_64_RELOC_GOTLD. It is
134 # handled exactly the same way, including having an implicit PC-rel offset of -4
135 # (despite this not making sense in a data section, and requiring an explicit
136 # +4 addend to cancel it out and get the correct result).
138 # jitlink-check: *{4}test_got = (got_addr(macho_reloc.o, external_data) - test_got)[31:0]
142 .long external_data@GOTPCREL + 4
144 # Named quad storage target (first named atom in __data).
148 .quad 0x2222222222222222
150 # An alt-entry point for named_data
151 .globl named_data_alt_entry
153 .alt_entry named_data_alt_entry
154 named_data_alt_entry
:
157 # Check X86_64_RELOC_UNSIGNED / extern handling by putting the address of a
158 # local named function in a pointer variable.
160 # jitlink-check: *{8}named_func_addr = named_func
161 .globl named_func_addr
166 # Check X86_64_RELOC_UNSIGNED / non-extern handling by putting the address of a
167 # local anonymous function in a pointer variable.
169 # jitlink-check: *{8}anon_func_addr = section_addr(macho_reloc.o, __text)
170 .globl anon_func_addr
175 # X86_64_RELOC_SUBTRACTOR Quad/Long in named storage with anonymous minuend
177 # jitlink-check: *{8}anon_minuend_quad1 = section_addr(macho_reloc.o, __data) - anon_minuend_quad1 + 2
178 # Only the form "B: .quad LA - B + C" is tested. The form "B: .quad B - LA + C" is
179 # invalid because the subtrahend can not be local.
180 .globl anon_minuend_quad1
183 .quad Lanon_data - anon_minuend_quad1 + 2
185 # jitlink-check: *{4}anon_minuend_long1 = (section_addr(macho_reloc.o, __data) - anon_minuend_long1 + 2)[31:0]
186 .globl anon_minuend_long1
189 .long Lanon_data - anon_minuend_long1 + 2
191 # Check X86_64_RELOC_SUBTRACTOR Quad/Long in named storage with minuend and subtrahend.
192 # Both forms "A: .quad A - B + C" and "A: .quad B - A + C" are tested.
194 # Check "A: .quad B - A + C".
195 # jitlink-check: *{8}subtrahend_quad2 = (named_data - subtrahend_quad2 - 2)
196 .globl subtrahend_quad2
199 .quad named_data - subtrahend_quad2 - 2
201 # Check "A: .long B - A + C".
202 # jitlink-check: *{4}subtrahend_long2 = (named_data - subtrahend_long2 - 2)[31:0]
203 .globl subtrahend_long2
206 .long named_data - subtrahend_long2 - 2
208 # Check "A: .quad A - B + C".
209 # jitlink-check: *{8}minuend_quad3 = (minuend_quad3 - named_data - 2)
213 .quad minuend_quad3 - named_data - 2
215 # Check "A: .long B - A + C".
216 # jitlink-check: *{4}minuend_long3 = (minuend_long3 - named_data - 2)[31:0]
220 .long minuend_long3 - named_data - 2
222 # Check X86_64_RELOC_SUBTRACTOR handling for exprs of the form
223 # "A: .quad/long B - C + D", where 'B' or 'C' is at a fixed offset from 'A'
224 # (i.e. is part of an alt_entry chain that includes 'A').
226 # Check "A: .long B - C + D" where 'B' is an alt_entry for 'A'.
227 # jitlink-check: *{4}subtractor_with_alt_entry_minuend_long = (subtractor_with_alt_entry_minuend_long_B - named_data + 2)[31:0]
228 .globl subtractor_with_alt_entry_minuend_long
230 subtractor_with_alt_entry_minuend_long
:
231 .long subtractor_with_alt_entry_minuend_long_B - named_data + 2
233 .globl subtractor_with_alt_entry_minuend_long_B
235 .alt_entry subtractor_with_alt_entry_minuend_long_B
236 subtractor_with_alt_entry_minuend_long_B
:
239 # Check "A: .quad B - C + D" where 'B' is an alt_entry for 'A'.
240 # jitlink-check: *{8}subtractor_with_alt_entry_minuend_quad = (subtractor_with_alt_entry_minuend_quad_B - named_data + 2)
241 .globl subtractor_with_alt_entry_minuend_quad
243 subtractor_with_alt_entry_minuend_quad
:
244 .quad subtractor_with_alt_entry_minuend_quad_B - named_data + 2
246 .globl subtractor_with_alt_entry_minuend_quad_B
248 .alt_entry subtractor_with_alt_entry_minuend_quad_B
249 subtractor_with_alt_entry_minuend_quad_B
:
252 # Check "A: .long B - C + D" where 'C' is an alt_entry for 'A'.
253 # jitlink-check: *{4}subtractor_with_alt_entry_subtrahend_long = (named_data - subtractor_with_alt_entry_subtrahend_long_B + 2)[31:0]
254 .globl subtractor_with_alt_entry_subtrahend_long
256 subtractor_with_alt_entry_subtrahend_long
:
257 .long named_data - subtractor_with_alt_entry_subtrahend_long_B + 2
259 .globl subtractor_with_alt_entry_subtrahend_long_B
261 .alt_entry subtractor_with_alt_entry_subtrahend_long_B
262 subtractor_with_alt_entry_subtrahend_long_B
:
265 # Check "A: .quad B - C + D" where 'B' is an alt_entry for 'A'.
266 # jitlink-check: *{8}subtractor_with_alt_entry_subtrahend_quad = (named_data - subtractor_with_alt_entry_subtrahend_quad_B + 2)
267 .globl subtractor_with_alt_entry_subtrahend_quad
269 subtractor_with_alt_entry_subtrahend_quad
:
270 .quad named_data - subtractor_with_alt_entry_subtrahend_quad_B + 2
272 .globl subtractor_with_alt_entry_subtrahend_quad_B
274 .alt_entry subtractor_with_alt_entry_subtrahend_quad_B
275 subtractor_with_alt_entry_subtrahend_quad_B
:
278 # Check that unreferenced atoms in no-dead-strip sections are not dead stripped.
279 # We need to use a local symbol for this as any named symbol will end up in the
280 # ORC responsibility set, which is automatically marked live and would couse
283 # jitlink-check: *{8}section_addr(macho_reloc.o, __nds_test_sect) = 0
284 .section __DATA,__nds_test_sect,regular,no_dead_strip
287 # Check that unreferenced local symbols that have been marked no-dead-strip are
290 # jitlink-check: *{8}section_addr(macho_reloc.o, __nds_test_nlst) = 0
291 .section __DATA,__nds_test_nlst,regular
292 .no_dead_strip no_dead_strip_test_symbol
293 no_dead_strip_test_symbol
:
296 # Check that explicit zero-fill symbols are supported
297 # jitlink-check: *{8}zero_fill_test = 0
298 .globl zero_fill_test
299 .zerofill __DATA,__zero_fill_test,zero_fill_test,8,3
301 # Check that section alignments are respected.
302 # We test this by introducing two segments with alignment 8, each containing one
303 # byte of data. We require both symbols to have an aligned address.
305 # jitlink-check: section_alignment_check1[2:0] = 0
306 # jitlink-check: section_alignment_check2[2:0] = 0
307 .section __DATA,__sec_align_chk1
310 .globl section_alignment_check1
311 section_alignment_check1
:
314 .section __DATA,__sec_align_chk2
317 .globl section_alignment_check2
318 section_alignment_check2
:
321 .subsections_via_symbols