1// RUN: llvm-mc -n -triple x86_64-apple-darwin9 %s -filetype=obj -o - | llvm-readobj -r --expand-relocs - | FileCheck %s
2
3// These examples are taken from <mach-o/x86_64/reloc.h>.
4
5        .data
6        .long 0
7
8        .text
9_foo:
10        ret
11
12_baz:
13        call _foo
14 	call _foo+4
15 	movq _foo@GOTPCREL(%rip), %rax
16 	pushq _foo@GOTPCREL(%rip)
17 	movl _foo(%rip), %eax
18 	movl _foo+4(%rip), %eax
19 	movb  $0x12, _foo(%rip)
20 	movl  $0x12345678, _foo(%rip)
21 	.quad _foo
22_bar:
23 	.quad _foo+4
24 	.quad _foo - _bar
25 	.quad _foo - _bar + 4
26 	.long _foo - _bar
27 	leaq L1(%rip), %rax
28 	leaq L0(%rip), %rax
29        addl $6,L0(%rip)
30        addw $500,L0(%rip)
31        addl $500,L0(%rip)
32
33_prev:
34        .space 12,0x90
35 	.quad L1
36L0:
37        .quad L0
38L_pc:
39 	.quad _foo - L_pc
40 	.quad _foo - L1
41L1:
42 	.quad L1 - _prev
43
44        .data
45.long	_foobar@GOTPCREL+4
46.long	_foo@GOTPCREL+4
47
48        .section	__DWARF,__debug_frame,regular,debug
49        .quad L1
50        .quad _ext_foo
51
52// Make sure local label which overlaps with non-local one is assigned to the
53// right atom.
54        .text
55_f2:
56L2_0:
57        addl $0, %eax
58L2_1:
59_f3:
60        addl L2_1 - L2_0, %eax
61
62        .data
63L4:
64        .long 0
65        .text
66        movl L4(%rip), %eax
67
68        .section __TEXT,__literal8,8byte_literals
69	.quad 0
70L5:
71	.quad 0
72f6:
73        .quad 0
74L6:
75        .quad 0
76
77        .text
78	movl L5(%rip), %eax
79	movl f6(%rip), %eax
80	movl L6(%rip), %eax
81
82        .data
83        .quad L5
84        .quad f6
85	.quad L6
86
87        .text
88        cmpq $0, _foo@GOTPCREL(%rip)
89
90// CHECK:      Relocations [
91// CHECK-NEXT:   Section __data {
92// CHECK-NEXT:     Relocation {
93// CHECK-NEXT:       Offset: 0x20
94// CHECK-NEXT:       PCRel: 0
95// CHECK-NEXT:       Length: 3
96// CHECK-NEXT:       Type: X86_64_RELOC_UNSIGNED (0)
97// CHECK-NEXT:       Section: __literal8
98// CHECK-NEXT:     }
99// CHECK-NEXT:     Relocation {
100// CHECK-NEXT:       Offset: 0x18
101// CHECK-NEXT:       PCRel: 0
102// CHECK-NEXT:       Length: 3
103// CHECK-NEXT:       Type: X86_64_RELOC_UNSIGNED (0)
104// CHECK-NEXT:       Symbol: f6
105// CHECK-NEXT:     }
106// CHECK-NEXT:     Relocation {
107// CHECK-NEXT:       Offset: 0x10
108// CHECK-NEXT:       PCRel: 0
109// CHECK-NEXT:       Length: 3
110// CHECK-NEXT:       Type: X86_64_RELOC_UNSIGNED (0)
111// CHECK-NEXT:       Section: __literal8
112// CHECK-NEXT:     }
113// CHECK-NEXT:     Relocation {
114// CHECK-NEXT:       Offset: 0x8
115// CHECK-NEXT:       PCRel: 1
116// CHECK-NEXT:       Length: 2
117// CHECK-NEXT:       Type: X86_64_RELOC_GOT (4)
118// CHECK-NEXT:       Symbol: _foo
119// CHECK-NEXT:     }
120// CHECK-NEXT:     Relocation {
121// CHECK-NEXT:       Offset: 0x4
122// CHECK-NEXT:       PCRel: 1
123// CHECK-NEXT:       Length: 2
124// CHECK-NEXT:       Type: X86_64_RELOC_GOT (4)
125// CHECK-NEXT:       Symbol: _foobar
126// CHECK-NEXT:     }
127// CHECK-NEXT:   }
128// CHECK-NEXT:   Section __text {
129// CHECK-NEXT:     Relocation {
130// CHECK-NEXT:       Offset: 0xDA
131// CHECK-NEXT:       PCRel: 1
132// CHECK-NEXT:       Length: 2
133// CHECK-NEXT:       Type: X86_64_RELOC_GOT (4)
134// CHECK-NEXT:       Symbol: _foo
135// CHECK-NEXT:     }
136// CHECK-NEXT:     Relocation {
137// CHECK-NEXT:       Offset: 0xD3
138// CHECK-NEXT:       PCRel: 1
139// CHECK-NEXT:       Length: 2
140// CHECK-NEXT:       Type: X86_64_RELOC_SIGNED (1)
141// CHECK-NEXT:       Section: __literal8
142// CHECK-NEXT:     }
143// CHECK-NEXT:     Relocation {
144// CHECK-NEXT:       Offset: 0xCD
145// CHECK-NEXT:       PCRel: 1
146// CHECK-NEXT:       Length: 2
147// CHECK-NEXT:       Type: X86_64_RELOC_SIGNED (1)
148// CHECK-NEXT:       Symbol: f6
149// CHECK-NEXT:     }
150// CHECK-NEXT:     Relocation {
151// CHECK-NEXT:       Offset: 0xC7
152// CHECK-NEXT:       PCRel: 1
153// CHECK-NEXT:       Length: 2
154// CHECK-NEXT:       Type: X86_64_RELOC_SIGNED (1)
155// CHECK-NEXT:       Section: __literal8
156// CHECK-NEXT:     }
157// CHECK-NEXT:     Relocation {
158// CHECK-NEXT:       Offset: 0xC1
159// CHECK-NEXT:       PCRel: 1
160// CHECK-NEXT:       Length: 2
161// CHECK-NEXT:       Type: X86_64_RELOC_SIGNED (1)
162// CHECK-NEXT:       Section: __data
163// CHECK-NEXT:     }
164// CHECK-NEXT:     Relocation {
165// CHECK-NEXT:       Offset: 0xA5
166// CHECK-NEXT:       PCRel: 0
167// CHECK-NEXT:       Length: 3
168// CHECK-NEXT:       Type: X86_64_RELOC_SUBTRACTOR (5)
169// CHECK-NEXT:       Symbol: _prev
170// CHECK-NEXT:     }
171// CHECK-NEXT:     Relocation {
172// CHECK-NEXT:       Offset: 0xA5
173// CHECK-NEXT:       PCRel: 0
174// CHECK-NEXT:       Length: 3
175// CHECK-NEXT:       Type: X86_64_RELOC_UNSIGNED (0)
176// CHECK-NEXT:       Symbol: _foo
177// CHECK-NEXT:     }
178// CHECK-NEXT:     Relocation {
179// CHECK-NEXT:       Offset: 0x9D
180// CHECK-NEXT:       PCRel: 0
181// CHECK-NEXT:       Length: 3
182// CHECK-NEXT:       Type: X86_64_RELOC_SUBTRACTOR (5)
183// CHECK-NEXT:       Symbol: _prev
184// CHECK-NEXT:     }
185// CHECK-NEXT:     Relocation {
186// CHECK-NEXT:       Offset: 0x9D
187// CHECK-NEXT:       PCRel: 0
188// CHECK-NEXT:       Length: 3
189// CHECK-NEXT:       Type: X86_64_RELOC_UNSIGNED (0)
190// CHECK-NEXT:       Symbol: _foo
191// CHECK-NEXT:     }
192// CHECK-NEXT:     Relocation {
193// CHECK-NEXT:       Offset: 0x95
194// CHECK-NEXT:       PCRel: 0
195// CHECK-NEXT:       Length: 3
196// CHECK-NEXT:       Type: X86_64_RELOC_UNSIGNED (0)
197// CHECK-NEXT:       Symbol: _prev
198// CHECK-NEXT:     }
199// CHECK-NEXT:     Relocation {
200// CHECK-NEXT:       Offset: 0x8D
201// CHECK-NEXT:       PCRel: 0
202// CHECK-NEXT:       Length: 3
203// CHECK-NEXT:       Type: X86_64_RELOC_UNSIGNED (0)
204// CHECK-NEXT:       Symbol: _prev
205// CHECK-NEXT:     }
206// CHECK-NEXT:     Relocation {
207// CHECK-NEXT:       Offset: 0x79
208// CHECK-NEXT:       PCRel: 1
209// CHECK-NEXT:       Length: 2
210// CHECK-NEXT:       Type: X86_64_RELOC_SIGNED_4 (8)
211// CHECK-NEXT:       Symbol: _prev
212// CHECK-NEXT:     }
213// CHECK-NEXT:     Relocation {
214// CHECK-NEXT:       Offset: 0x71
215// CHECK-NEXT:       PCRel: 1
216// CHECK-NEXT:       Length: 2
217// CHECK-NEXT:       Type: X86_64_RELOC_SIGNED_2 (7)
218// CHECK-NEXT:       Symbol: _prev
219// CHECK-NEXT:     }
220// CHECK-NEXT:     Relocation {
221// CHECK-NEXT:       Offset: 0x69
222// CHECK-NEXT:       PCRel: 1
223// CHECK-NEXT:       Length: 2
224// CHECK-NEXT:       Type: X86_64_RELOC_SIGNED_1 (6)
225// CHECK-NEXT:       Symbol: _prev
226// CHECK-NEXT:     }
227// CHECK-NEXT:     Relocation {
228// CHECK-NEXT:       Offset: 0x63
229// CHECK-NEXT:       PCRel: 1
230// CHECK-NEXT:       Length: 2
231// CHECK-NEXT:       Type: X86_64_RELOC_SIGNED (1)
232// CHECK-NEXT:       Symbol: _prev
233// CHECK-NEXT:     }
234// CHECK-NEXT:     Relocation {
235// CHECK-NEXT:       Offset: 0x5C
236// CHECK-NEXT:       PCRel: 1
237// CHECK-NEXT:       Length: 2
238// CHECK-NEXT:       Type: X86_64_RELOC_SIGNED (1)
239// CHECK-NEXT:       Symbol: _prev
240// CHECK-NEXT:     }
241// CHECK-NEXT:     Relocation {
242// CHECK-NEXT:       Offset: 0x55
243// CHECK-NEXT:       PCRel: 0
244// CHECK-NEXT:       Length: 2
245// CHECK-NEXT:       Type: X86_64_RELOC_SUBTRACTOR (5)
246// CHECK-NEXT:       Symbol: _bar
247// CHECK-NEXT:     }
248// CHECK-NEXT:     Relocation {
249// CHECK-NEXT:       Offset: 0x55
250// CHECK-NEXT:       PCRel: 0
251// CHECK-NEXT:       Length: 2
252// CHECK-NEXT:       Type: X86_64_RELOC_UNSIGNED (0)
253// CHECK-NEXT:       Symbol: _foo
254// CHECK-NEXT:     }
255// CHECK-NEXT:     Relocation {
256// CHECK-NEXT:       Offset: 0x4D
257// CHECK-NEXT:       PCRel: 0
258// CHECK-NEXT:       Length: 3
259// CHECK-NEXT:       Type: X86_64_RELOC_SUBTRACTOR (5)
260// CHECK-NEXT:       Symbol: _bar
261// CHECK-NEXT:     }
262// CHECK-NEXT:     Relocation {
263// CHECK-NEXT:       Offset: 0x4D
264// CHECK-NEXT:       PCRel: 0
265// CHECK-NEXT:       Length: 3
266// CHECK-NEXT:       Type: X86_64_RELOC_UNSIGNED (0)
267// CHECK-NEXT:       Symbol: _foo
268// CHECK-NEXT:     }
269// CHECK-NEXT:     Relocation {
270// CHECK-NEXT:       Offset: 0x45
271// CHECK-NEXT:       PCRel: 0
272// CHECK-NEXT:       Length: 3
273// CHECK-NEXT:       Type: X86_64_RELOC_SUBTRACTOR (5)
274// CHECK-NEXT:       Symbol: _bar
275// CHECK-NEXT:     }
276// CHECK-NEXT:     Relocation {
277// CHECK-NEXT:       Offset: 0x45
278// CHECK-NEXT:       PCRel: 0
279// CHECK-NEXT:       Length: 3
280// CHECK-NEXT:       Type: X86_64_RELOC_UNSIGNED (0)
281// CHECK-NEXT:       Symbol: _foo
282// CHECK-NEXT:     }
283// CHECK-NEXT:     Relocation {
284// CHECK-NEXT:       Offset: 0x3D
285// CHECK-NEXT:       PCRel: 0
286// CHECK-NEXT:       Length: 3
287// CHECK-NEXT:       Type: X86_64_RELOC_UNSIGNED (0)
288// CHECK-NEXT:       Symbol: _foo
289// CHECK-NEXT:     }
290// CHECK-NEXT:     Relocation {
291// CHECK-NEXT:       Offset: 0x35
292// CHECK-NEXT:       PCRel: 0
293// CHECK-NEXT:       Length: 3
294// CHECK-NEXT:       Type: X86_64_RELOC_UNSIGNED (0)
295// CHECK-NEXT:       Symbol: _foo
296// CHECK-NEXT:     }
297// CHECK-NEXT:     Relocation {
298// CHECK-NEXT:       Offset: 0x2D
299// CHECK-NEXT:       PCRel: 1
300// CHECK-NEXT:       Length: 2
301// CHECK-NEXT:       Type: X86_64_RELOC_SIGNED_4 (8)
302// CHECK-NEXT:       Symbol: _foo
303// CHECK-NEXT:     }
304// CHECK-NEXT:     Relocation {
305// CHECK-NEXT:       Offset: 0x26
306// CHECK-NEXT:       PCRel: 1
307// CHECK-NEXT:       Length: 2
308// CHECK-NEXT:       Type: X86_64_RELOC_SIGNED_1 (6)
309// CHECK-NEXT:       Symbol: _foo
310// CHECK-NEXT:     }
311// CHECK-NEXT:     Relocation {
312// CHECK-NEXT:       Offset: 0x20
313// CHECK-NEXT:       PCRel: 1
314// CHECK-NEXT:       Length: 2
315// CHECK-NEXT:       Type: X86_64_RELOC_SIGNED (1)
316// CHECK-NEXT:       Symbol: _foo
317// CHECK-NEXT:     }
318// CHECK-NEXT:     Relocation {
319// CHECK-NEXT:       Offset: 0x1A
320// CHECK-NEXT:       PCRel: 1
321// CHECK-NEXT:       Length: 2
322// CHECK-NEXT:       Type: X86_64_RELOC_SIGNED (1)
323// CHECK-NEXT:       Symbol: _foo
324// CHECK-NEXT:     }
325// CHECK-NEXT:     Relocation {
326// CHECK-NEXT:       Offset: 0x14
327// CHECK-NEXT:       PCRel: 1
328// CHECK-NEXT:       Length: 2
329// CHECK-NEXT:       Type: X86_64_RELOC_GOT (4)
330// CHECK-NEXT:       Symbol: _foo
331// CHECK-NEXT:     }
332// CHECK-NEXT:     Relocation {
333// CHECK-NEXT:       Offset: 0xE
334// CHECK-NEXT:       PCRel: 1
335// CHECK-NEXT:       Length: 2
336// CHECK-NEXT:       Type: X86_64_RELOC_GOT_LOAD (3)
337// CHECK-NEXT:       Symbol: _foo
338// CHECK-NEXT:     }
339// CHECK-NEXT:     Relocation {
340// CHECK-NEXT:       Offset: 0x7
341// CHECK-NEXT:       PCRel: 1
342// CHECK-NEXT:       Length: 2
343// CHECK-NEXT:       Type: X86_64_RELOC_BRANCH (2)
344// CHECK-NEXT:       Symbol: _foo
345// CHECK-NEXT:     }
346// CHECK-NEXT:     Relocation {
347// CHECK-NEXT:       Offset: 0x2
348// CHECK-NEXT:       PCRel: 1
349// CHECK-NEXT:       Length: 2
350// CHECK-NEXT:       Type: X86_64_RELOC_BRANCH (2)
351// CHECK-NEXT:       Symbol: _foo
352// CHECK-NEXT:     }
353// CHECK-NEXT:   }
354// CHECK-NEXT:   Section __debug_frame {
355// CHECK-NEXT:     Relocation {
356// CHECK-NEXT:       Offset: 0x8
357// CHECK-NEXT:       PCRel: 0
358// CHECK-NEXT:       Length: 3
359// CHECK-NEXT:       Type: X86_64_RELOC_UNSIGNED (0)
360// CHECK-NEXT:       Symbol: _ext_foo
361// CHECK-NEXT:     }
362// CHECK-NEXT:     Relocation {
363// CHECK-NEXT:       Offset: 0x0
364// CHECK-NEXT:       PCRel: 0
365// CHECK-NEXT:       Length: 3
366// CHECK-NEXT:       Type: X86_64_RELOC_UNSIGNED (0)
367// CHECK-NEXT:       Section: __text
368// CHECK-NEXT:     }
369// CHECK-NEXT:   }
370// CHECK-NEXT: ]
371