1// RUN: llvm-mc -n -triple x86_64-apple-darwin9 %s -filetype=obj -o - | macho-dump --dump-section-data | 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: ('cputype', 16777223)
91// CHECK: ('cpusubtype', 3)
92// CHECK: ('filetype', 1)
93// CHECK: ('num_load_commands', 3)
94// CHECK: ('load_commands_size', 496)
95// CHECK: ('flag', 0)
96// CHECK: ('reserved', 0)
97// CHECK: ('load_commands', [
98// CHECK:   # Load Command 0
99// CHECK:  (('command', 25)
100// CHECK:   ('size', 392)
101// CHECK:   ('segment_name', '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
102// CHECK:   ('vm_addr', 0)
103// CHECK:   ('vm_size', 311)
104// CHECK:   ('file_offset', 528)
105// CHECK:   ('file_size', 311)
106// CHECK:   ('maxprot', 7)
107// CHECK:   ('initprot', 7)
108// CHECK:   ('num_sections', 4)
109// CHECK:   ('flags', 0)
110// CHECK:   ('sections', [
111// CHECK:     # Section 0
112// CHECK:    (('section_name', '__data\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
113// CHECK:     ('segment_name', '__DATA\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
114// CHECK:     ('address', 0)
115// CHECK:     ('size', 40)
116// CHECK:     ('offset', 528)
117// CHECK:     ('alignment', 0)
118// CHECK:     ('reloc_offset', 840)
119// CHECK:     ('num_reloc', 5)
120// CHECK:     ('flags', 0x0)
121// CHECK:     ('reserved1', 0)
122// CHECK:     ('reserved2', 0)
123// CHECK:     ('reserved3', 0)
124// CHECK:    ),
125// CHECK:   ('_relocations', [
126// CHECK:     # Relocation 0
127// CHECK:     (('word-0', 0x20),
128// CHECK:      ('word-1', 0x6000004)),
129// CHECK:     # Relocation 1
130// CHECK:     (('word-0', 0x18),
131// CHECK:      ('word-1', 0xe000006)),
132// CHECK:     # Relocation 2
133// CHECK:     (('word-0', 0x10),
134// CHECK:      ('word-1', 0x6000004)),
135// CHECK:     # Relocation 3
136// CHECK:     (('word-0', 0x8),
137// CHECK:      ('word-1', 0x4d000000)),
138// CHECK:     # Relocation 4
139// CHECK:     (('word-0', 0x4),
140// CHECK:      ('word-1', 0x4d000008)),
141// CHECK:   ])
142// CHECK:   ('_section_data', '00000000 04000000 04000000 00000000 1f010000 00000000 00000000 00000000 2f010000 00000000')
143// CHECK:     # Section 1
144// CHECK:    (('section_name', '__text\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
145// CHECK:     ('segment_name', '__TEXT\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
146// CHECK:     ('address', 40)
147// CHECK:     ('size', 223)
148// CHECK:     ('offset', 568)
149// CHECK:     ('alignment', 0)
150// CHECK:     ('reloc_offset', 880)
151// CHECK:     ('num_reloc', 32)
152// CHECK:     ('flags', 0x80000400)
153// CHECK:     ('reserved1', 0)
154// CHECK:     ('reserved2', 0)
155// CHECK:     ('reserved3', 0)
156// CHECK:    ),
157// CHECK:   ('_relocations', [
158// CHECK:     # Relocation 0
159// CHECK:     (('word-0', 0xda),
160// CHECK:      ('word-1', 0x4d000000)),
161// CHECK:     # Relocation 1
162// CHECK:     (('word-0', 0xd3),
163// CHECK:      ('word-1', 0x15000004)),
164// CHECK:     # Relocation 2
165// CHECK:     (('word-0', 0xcd),
166// CHECK:      ('word-1', 0x1d000006)),
167// CHECK:     # Relocation 3
168// CHECK:     (('word-0', 0xc7),
169// CHECK:      ('word-1', 0x15000004)),
170// CHECK:     # Relocation 4
171// CHECK:     (('word-0', 0xc1),
172// CHECK:      ('word-1', 0x15000001)),
173// CHECK:     # Relocation 5
174// CHECK:     (('word-0', 0xa5),
175// CHECK:      ('word-1', 0x5e000003)),
176// CHECK:     # Relocation 6
177// CHECK:     (('word-0', 0xa5),
178// CHECK:      ('word-1', 0xe000000)),
179// CHECK:     # Relocation 7
180// CHECK:     (('word-0', 0x9d),
181// CHECK:      ('word-1', 0x5e000003)),
182// CHECK:     # Relocation 8
183// CHECK:     (('word-0', 0x9d),
184// CHECK:      ('word-1', 0xe000000)),
185// CHECK:     # Relocation 9
186// CHECK:     (('word-0', 0x95),
187// CHECK:      ('word-1', 0xe000003)),
188// CHECK:     # Relocation 10
189// CHECK:     (('word-0', 0x8d),
190// CHECK:      ('word-1', 0xe000003)),
191// CHECK:     # Relocation 11
192// CHECK:     (('word-0', 0x79),
193// CHECK:      ('word-1', 0x8d000003)),
194// CHECK:     # Relocation 12
195// CHECK:     (('word-0', 0x71),
196// CHECK:      ('word-1', 0x7d000003)),
197// CHECK:     # Relocation 13
198// CHECK:     (('word-0', 0x69),
199// CHECK:      ('word-1', 0x6d000003)),
200// CHECK:     # Relocation 14
201// CHECK:     (('word-0', 0x63),
202// CHECK:      ('word-1', 0x1d000003)),
203// CHECK:     # Relocation 15
204// CHECK:     (('word-0', 0x5c),
205// CHECK:      ('word-1', 0x1d000003)),
206// CHECK:     # Relocation 16
207// CHECK:     (('word-0', 0x55),
208// CHECK:      ('word-1', 0x5c000002)),
209// CHECK:     # Relocation 17
210// CHECK:     (('word-0', 0x55),
211// CHECK:      ('word-1', 0xc000000)),
212// CHECK:     # Relocation 18
213// CHECK:     (('word-0', 0x4d),
214// CHECK:      ('word-1', 0x5e000002)),
215// CHECK:     # Relocation 19
216// CHECK:     (('word-0', 0x4d),
217// CHECK:      ('word-1', 0xe000000)),
218// CHECK:     # Relocation 20
219// CHECK:     (('word-0', 0x45),
220// CHECK:      ('word-1', 0x5e000002)),
221// CHECK:     # Relocation 21
222// CHECK:     (('word-0', 0x45),
223// CHECK:      ('word-1', 0xe000000)),
224// CHECK:     # Relocation 22
225// CHECK:     (('word-0', 0x3d),
226// CHECK:      ('word-1', 0xe000000)),
227// CHECK:     # Relocation 23
228// CHECK:     (('word-0', 0x35),
229// CHECK:      ('word-1', 0xe000000)),
230// CHECK:     # Relocation 24
231// CHECK:     (('word-0', 0x2d),
232// CHECK:      ('word-1', 0x8d000000)),
233// CHECK:     # Relocation 25
234// CHECK:     (('word-0', 0x26),
235// CHECK:      ('word-1', 0x6d000000)),
236// CHECK:     # Relocation 26
237// CHECK:     (('word-0', 0x20),
238// CHECK:      ('word-1', 0x1d000000)),
239// CHECK:     # Relocation 27
240// CHECK:     (('word-0', 0x1a),
241// CHECK:      ('word-1', 0x1d000000)),
242// CHECK:     # Relocation 28
243// CHECK:     (('word-0', 0x14),
244// CHECK:      ('word-1', 0x4d000000)),
245// CHECK:     # Relocation 29
246// CHECK:     (('word-0', 0xe),
247// CHECK:      ('word-1', 0x3d000000)),
248// CHECK:     # Relocation 30
249// CHECK:     (('word-0', 0x7),
250// CHECK:      ('word-1', 0x2d000000)),
251// CHECK:     # Relocation 31
252// CHECK:     (('word-0', 0x2),
253// CHECK:      ('word-1', 0x2d000000)),
254// CHECK:   ])
255// CHECK:   ('_section_data', 'c3e80000 0000e804 00000048 8b050000 0000ff35 00000000 8b050000 00008b05 04000000 c605ffff ffff12c7 05fcffff ff785634 12000000 00000000 00040000 00000000 00000000 00000000 00040000 00000000 00000000 00488d05 2c000000 488d0514 00000083 05130000 00066681 05120000 00f40181 05100000 00f40100 00909090 90909090 90909090 902c0000 00000000 00140000 00000000 00e4ffff ffffffff ffd4ffff ffffffff ff2c0000 00000000 0083c000 03042503 0000008b 051fffff ff8b052c 0000008b 05000000 008b0530 00000048 833dffff ffff00')
256// CHECK:     # Section 2
257// CHECK:    (('section_name', '__debug_frame\x00\x00\x00')
258// CHECK:     ('segment_name', '__DWARF\x00\x00\x00\x00\x00\x00\x00\x00\x00')
259// CHECK:     ('address', 263)
260// CHECK:     ('size', 16)
261// CHECK:     ('offset', 791)
262// CHECK:     ('alignment', 0)
263// CHECK:     ('reloc_offset', 1136)
264// CHECK:     ('num_reloc', 2)
265// CHECK:     ('flags', 0x2000000)
266// CHECK:     ('reserved1', 0)
267// CHECK:     ('reserved2', 0)
268// CHECK:     ('reserved3', 0)
269// CHECK:    ),
270// CHECK:   ('_relocations', [
271// CHECK:     # Relocation 0
272// CHECK:     (('word-0', 0x8),
273// CHECK:      ('word-1', 0xe000007)),
274// CHECK:     # Relocation 1
275// CHECK:     (('word-0', 0x0),
276// CHECK:      ('word-1', 0x6000002)),
277// CHECK:   ])
278// CHECK:   ('_section_data', 'd5000000 00000000 00000000 00000000')
279// CHECK:     # Section 3
280// CHECK:    (('section_name', '__literal8\x00\x00\x00\x00\x00\x00')
281// CHECK:     ('segment_name', '__TEXT\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
282// CHECK:     ('address', 279)
283// CHECK:     ('size', 32)
284// CHECK:     ('offset', 807)
285// CHECK:     ('alignment', 0)
286// CHECK:     ('reloc_offset', 0)
287// CHECK:     ('num_reloc', 0)
288// CHECK:     ('flags', 0x4)
289// CHECK:     ('reserved1', 0)
290// CHECK:     ('reserved2', 0)
291// CHECK:     ('reserved3', 0)
292// CHECK:    ),
293// CHECK:   ('_relocations', [
294// CHECK:   ])
295// CHECK:   ('_section_data', '00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000')
296// CHECK:   ])
297// CHECK:  ),
298// CHECK:   # Load Command 1
299// CHECK:  (('command', 2)
300// CHECK:   ('size', 24)
301// CHECK:   ('symoff', 1152)
302// CHECK:   ('nsyms', 9)
303// CHECK:   ('stroff', 1296)
304// CHECK:   ('strsize', 52)
305// CHECK:   ('_string_data', '\x00_foobar\x00_ext_foo\x00_foo\x00_baz\x00_bar\x00_prev\x00_f2\x00_f3\x00f6\x00\x00\x00')
306// CHECK:   ('_symbols', [
307// CHECK:     # Symbol 0
308// CHECK:    (('n_strx', 18)
309// CHECK:     ('n_type', 0xe)
310// CHECK:     ('n_sect', 2)
311// CHECK:     ('n_desc', 0)
312// CHECK:     ('n_value', 40)
313// CHECK:     ('_string', '_foo')
314// CHECK:    ),
315// CHECK:     # Symbol 1
316// CHECK:    (('n_strx', 23)
317// CHECK:     ('n_type', 0xe)
318// CHECK:     ('n_sect', 2)
319// CHECK:     ('n_desc', 0)
320// CHECK:     ('n_value', 41)
321// CHECK:     ('_string', '_baz')
322// CHECK:    ),
323// CHECK:     # Symbol 2
324// CHECK:    (('n_strx', 28)
325// CHECK:     ('n_type', 0xe)
326// CHECK:     ('n_sect', 2)
327// CHECK:     ('n_desc', 0)
328// CHECK:     ('n_value', 101)
329// CHECK:     ('_string', '_bar')
330// CHECK:    ),
331// CHECK:     # Symbol 3
332// CHECK:    (('n_strx', 33)
333// CHECK:     ('n_type', 0xe)
334// CHECK:     ('n_sect', 2)
335// CHECK:     ('n_desc', 0)
336// CHECK:     ('n_value', 169)
337// CHECK:     ('_string', '_prev')
338// CHECK:    ),
339// CHECK:     # Symbol 4
340// CHECK:    (('n_strx', 39)
341// CHECK:     ('n_type', 0xe)
342// CHECK:     ('n_sect', 2)
343// CHECK:     ('n_desc', 0)
344// CHECK:     ('n_value', 221)
345// CHECK:     ('_string', '_f2')
346// CHECK:    ),
347// CHECK:     # Symbol 5
348// CHECK:    (('n_strx', 43)
349// CHECK:     ('n_type', 0xe)
350// CHECK:     ('n_sect', 2)
351// CHECK:     ('n_desc', 0)
352// CHECK:     ('n_value', 224)
353// CHECK:     ('_string', '_f3')
354// CHECK:    ),
355// CHECK:     # Symbol 6
356// CHECK:    (('n_strx', 47)
357// CHECK:     ('n_type', 0xe)
358// CHECK:     ('n_sect', 4)
359// CHECK:     ('n_desc', 0)
360// CHECK:     ('n_value', 295)
361// CHECK:     ('_string', 'f6')
362// CHECK:    ),
363// CHECK:     # Symbol 7
364// CHECK:    (('n_strx', 9)
365// CHECK:     ('n_type', 0x1)
366// CHECK:     ('n_sect', 0)
367// CHECK:     ('n_desc', 0)
368// CHECK:     ('n_value', 0)
369// CHECK:     ('_string', '_ext_foo')
370// CHECK:    ),
371// CHECK:     # Symbol 8
372// CHECK:    (('n_strx', 1)
373// CHECK:     ('n_type', 0x1)
374// CHECK:     ('n_sect', 0)
375// CHECK:     ('n_desc', 0)
376// CHECK:     ('n_value', 0)
377// CHECK:     ('_string', '_foobar')
378// CHECK:    ),
379// CHECK:   ])
380// CHECK:  ),
381// CHECK:   # Load Command 2
382// CHECK:  (('command', 11)
383// CHECK:   ('size', 80)
384// CHECK:   ('ilocalsym', 0)
385// CHECK:   ('nlocalsym', 7)
386// CHECK:   ('iextdefsym', 7)
387// CHECK:   ('nextdefsym', 0)
388// CHECK:   ('iundefsym', 7)
389// CHECK:   ('nundefsym', 2)
390// CHECK:   ('tocoff', 0)
391// CHECK:   ('ntoc', 0)
392// CHECK:   ('modtaboff', 0)
393// CHECK:   ('nmodtab', 0)
394// CHECK:   ('extrefsymoff', 0)
395// CHECK:   ('nextrefsyms', 0)
396// CHECK:   ('indirectsymoff', 0)
397// CHECK:   ('nindirectsyms', 0)
398// CHECK:   ('extreloff', 0)
399// CHECK:   ('nextrel', 0)
400// CHECK:   ('locreloff', 0)
401// CHECK:   ('nlocrel', 0)
402// CHECK:   ('_indirect_symbols', [
403// CHECK:   ])
404// CHECK:  ),
405// CHECK: ])
406