• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// RUN: llvm-mc -triple x86_64-apple-darwin10 %s -filetype=obj -o - | llvm-readobj -file-headers -s -sd -r -t -macho-segment -macho-dysymtab -macho-indirect-symbols | FileCheck %s
2
3        .text
4
5// FIXME: llvm-mc doesn't handle this in a way we can make compatible with 'as',
6// currently, because of how we handle assembler variables.
7//
8// See <rdar://problem/7763719> improve handling of absolute symbols
9
10// _baz = 4
11
12_foo:
13        xorl %eax,%eax
14_g0:
15        xorl %eax,%eax
16L0:
17        jmp 4
18//        jmp _baz
19
20// FIXME: Darwin 'as' for historical reasons widens this jump, but doesn't emit
21// a relocation. It seems like 'as' widens any jump that is not to a temporary,
22// which is inherited from the x86_32 behavior, even though x86_64 could do
23// better.
24//        jmp _g0
25
26        jmp L0
27        jmp _g1
28
29// FIXME: Darwin 'as' gets this wrong as well, even though it could get it right
30// given the other things we do on x86_64. It is using a short jump here. This
31// is probably fallout of the hack that exists for x86_32.
32//        jmp L1
33
34// FIXME: We don't support this, and would currently get it wrong, it should be a jump to an absolute address.
35//        jmp L0 - _g0
36
37//        jmp _g1 - _g0
38// FIXME: Darwin 'as' comes up with 'SIGNED' here instead of 'BRANCH'.
39//        jmp _g1 - L1
40// FIXME: Darwin 'as' gets this completely wrong. It ends up with a single
41// branch relocation. Fallout from the other delta hack?
42//        jmp L1 - _g0
43
44        jmp _g2
45        jmp L2
46        jmp _g3
47        jmp L3
48// FIXME: Darwin 'as' gets this completely wrong. It ends up with a single
49// branch relocation. Fallout from the other delta hack?
50//        jmp L2 - _g3
51//        jmp _g3 - _g2
52// FIXME: Darwin 'as' comes up with 'SIGNED' here instead of 'BRANCH'.
53//        jmp _g3 - L3
54// FIXME: Darwin 'as' gets this completely wrong. It ends up with a single
55// branch relocation. Fallout from the other delta hack?
56//        jmp L3 - _g2
57
58        movl %eax,4(%rip)
59//        movl %eax,_baz(%rip)
60        movl %eax,_g0(%rip)
61        movl %eax,L0(%rip)
62        movl %eax,_g1(%rip)
63        movl %eax,L1(%rip)
64
65// FIXME: Darwin 'as' gets most of these wrong, and there is an ambiguity in ATT
66// syntax in what they should mean in the first place (absolute or
67// rip-relative address).
68//        movl %eax,L0 - _g0(%rip)
69//        movl %eax,_g1 - _g0(%rip)
70//        movl %eax,_g1 - L1(%rip)
71//        movl %eax,L1 - _g0(%rip)
72
73        movl %eax,_g2(%rip)
74        movl %eax,L2(%rip)
75        movl %eax,_g3(%rip)
76        movl %eax,L3(%rip)
77
78// FIXME: Darwin 'as' gets most of these wrong, and there is an ambiguity in ATT
79// syntax in what they should mean in the first place (absolute or
80// rip-relative address).
81//        movl %eax,L2 - _g2(%rip)
82//        movl %eax,_g3 - _g2(%rip)
83//        movl %eax,_g3 - L3(%rip)
84//        movl %eax,L3 - _g2(%rip)
85
86_g1:
87        xorl %eax,%eax
88L1:
89        xorl %eax,%eax
90
91        .data
92_g2:
93        xorl %eax,%eax
94L2:
95        .quad 4
96//        .quad _baz
97        .quad _g2
98        .quad L2
99        .quad _g3
100        .quad L3
101        .quad L2 - _g2
102        .quad _g3 - _g2
103        .quad L3 - _g2
104        .quad L3 - _g3
105
106        .quad _g0
107        .quad L0
108        .quad _g1
109        .quad L1
110        .quad L0 - _g0
111        .quad _g1 - _g0
112        .quad L1 - _g0
113        .quad L1 - _g1
114
115_g3:
116        xorl %eax,%eax
117L3:
118        xorl %eax,%eax
119
120// FIXME: Unfortunately, we do not get these relocations in exactly the same
121// order as Darwin 'as'. It turns out that 'as' *usually* ends up emitting
122// them in reverse address order, but sometimes it allocates some
123// additional relocations late so these end up precede the other entries. I
124// haven't figured out the exact criteria for this yet.
125
126// CHECK: File: <stdin>
127// CHECK: Format: Mach-O 64-bit x86-64
128// CHECK: Arch: x86_64
129// CHECK: AddressSize: 64bit
130// CHECK: MachHeader {
131// CHECK:   Magic: Magic64 (0xFEEDFACF)
132// CHECK:   CpuType: X86-64 (0x1000007)
133// CHECK:   CpuSubType: CPU_SUBTYPE_X86_64_ALL (0x3)
134// CHECK:   FileType: Relocatable (0x1)
135// CHECK:   NumOfLoadCommands: 4
136// CHECK:   SizeOfLoadCommands: 352
137// CHECK:   Flags [ (0x0)
138// CHECK:   ]
139// CHECK:   Reserved: 0x0
140// CHECK: }
141// CHECK: Sections [
142// CHECK:   Section {
143// CHECK:     Index: 0
144// CHECK:     Name: __text (5F 5F 74 65 78 74 00 00 00 00 00 00 00 00 00 00)
145// CHECK:     Segment: __TEXT (5F 5F 54 45 58 54 00 00 00 00 00 00 00 00 00 00)
146// CHECK:     Address: 0x0
147// CHECK:     Size: 0x5E
148// CHECK:     Offset: 384
149// CHECK:     Alignment: 0
150// CHECK:     RelocationOffset: 0x26C
151// CHECK:     RelocationCount: 12
152// CHECK:     Type: 0x0
153// CHECK:     Attributes [ (0x800004)
154// CHECK:       PureInstructions (0x800000)
155// CHECK:       SomeInstructions (0x4)
156// CHECK:     ]
157// CHECK:     Reserved1: 0x0
158// CHECK:     Reserved2: 0x0
159// CHECK:     Reserved3: 0x0
160// CHECK:     SectionData (
161// CHECK:       0000: 31C031C0 E9040000 00EBF9E9 00000000  |1.1.............|
162// CHECK:       0010: E9000000 00E90200 0000E900 000000E9  |................|
163// CHECK:       0020: 02000000 89050400 00008905 D2FFFFFF  |................|
164// CHECK:       0030: 8905CEFF FFFF8905 00000000 89050200  |................|
165// CHECK:       0040: 00008905 00000000 89050200 00008905  |................|
166// CHECK:       0050: 00000000 89050200 000031C0 31C0      |..........1.1.|
167// CHECK:     )
168// CHECK:   }
169// CHECK:   Section {
170// CHECK:     Index: 1
171// CHECK:     Name: __data (5F 5F 64 61 74 61 00 00 00 00 00 00 00 00 00 00)
172// CHECK:     Segment: __DATA (5F 5F 44 41 54 41 00 00 00 00 00 00 00 00 00 00)
173// CHECK:     Address: 0x5E
174// CHECK:     Size: 0x8E
175// CHECK:     Offset: 478
176// CHECK:     Alignment: 0
177// CHECK:     RelocationOffset: 0x2CC
178// CHECK:     RelocationCount: 16
179// CHECK:     Type: 0x0
180// CHECK:     Attributes [ (0x4)
181// CHECK:       SomeInstructions (0x4)
182// CHECK:     ]
183// CHECK:     Reserved1: 0x0
184// CHECK:     Reserved2: 0x0
185// CHECK:     Reserved3: 0x0
186// CHECK:     SectionData (
187// CHECK:       0000: 31C00400 00000000 00000000 00000000  |1...............|
188// CHECK:       0010: 00000200 00000000 00000000 00000000  |................|
189// CHECK:       0020: 00000200 00000000 00000200 00000000  |................|
190// CHECK:       0030: 00000000 00000000 00000200 00000000  |................|
191// CHECK:       0040: 00000200 00000000 00000000 00000000  |................|
192// CHECK:       0050: 00000200 00000000 00000000 00000000  |................|
193// CHECK:       0060: 00000200 00000000 00000200 00000000  |................|
194// CHECK:       0070: 00000000 00000000 00000200 00000000  |................|
195// CHECK:       0080: 00000200 00000000 000031C0 31C0      |..........1.1.|
196// CHECK:     )
197// CHECK:   }
198// CHECK: ]
199// CHECK: Relocations [
200// CHECK:   Section __text {
201// CHECK:     0x56 1 2 1 X86_64_RELOC_SIGNED 0 _g3
202// CHECK:     0x50 1 2 1 X86_64_RELOC_SIGNED 0 _g3
203// CHECK:     0x4A 1 2 1 X86_64_RELOC_SIGNED 0 _g2
204// CHECK:     0x44 1 2 1 X86_64_RELOC_SIGNED 0 _g2
205// CHECK:     0x3E 1 2 1 X86_64_RELOC_SIGNED 0 _g1
206// CHECK:     0x38 1 2 1 X86_64_RELOC_SIGNED 0 _g1
207// CHECK:     0x20 1 2 1 X86_64_RELOC_BRANCH 0 _g3
208// CHECK:     0x1B 1 2 1 X86_64_RELOC_BRANCH 0 _g3
209// CHECK:     0x16 1 2 1 X86_64_RELOC_BRANCH 0 _g2
210// CHECK:     0x11 1 2 1 X86_64_RELOC_BRANCH 0 _g2
211// CHECK:     0xC 1 2 1 X86_64_RELOC_BRANCH 0 _g1
212// CHECK:     0x5 1 2 1 X86_64_RELOC_BRANCH 0 _foo
213// CHECK:   }
214// CHECK:   Section __data {
215// CHECK:     0x7A 0 3 1 X86_64_RELOC_SUBTRACTOR 0 _g0
216// CHECK:     0x7A 0 3 1 X86_64_RELOC_UNSIGNED 0 _g1
217// CHECK:     0x72 0 3 1 X86_64_RELOC_SUBTRACTOR 0 _g0
218// CHECK:     0x72 0 3 1 X86_64_RELOC_UNSIGNED 0 _g1
219// CHECK:     0x62 0 3 1 X86_64_RELOC_UNSIGNED 0 _g1
220// CHECK:     0x5A 0 3 1 X86_64_RELOC_UNSIGNED 0 _g1
221// CHECK:     0x52 0 3 1 X86_64_RELOC_UNSIGNED 0 _g0
222// CHECK:     0x4A 0 3 1 X86_64_RELOC_UNSIGNED 0 _g0
223// CHECK:     0x3A 0 3 1 X86_64_RELOC_SUBTRACTOR 0 _g2
224// CHECK:     0x3A 0 3 1 X86_64_RELOC_UNSIGNED 0 _g3
225// CHECK:     0x32 0 3 1 X86_64_RELOC_SUBTRACTOR 0 _g2
226// CHECK:     0x32 0 3 1 X86_64_RELOC_UNSIGNED 0 _g3
227// CHECK:     0x22 0 3 1 X86_64_RELOC_UNSIGNED 0 _g3
228// CHECK:     0x1A 0 3 1 X86_64_RELOC_UNSIGNED 0 _g3
229// CHECK:     0x12 0 3 1 X86_64_RELOC_UNSIGNED 0 _g2
230// CHECK:     0xA 0 3 1 X86_64_RELOC_UNSIGNED 0 _g2
231// CHECK:   }
232// CHECK: ]
233// CHECK: Symbols [
234// CHECK:   Symbol {
235// CHECK:     Name: _foo (1)
236// CHECK:     Type: Section (0xE)
237// CHECK:     Section: __text (0x1)
238// CHECK:     RefType: UndefinedNonLazy (0x0)
239// CHECK:     Flags [ (0x0)
240// CHECK:     ]
241// CHECK:     Value: 0x0
242// CHECK:   }
243// CHECK:   Symbol {
244// CHECK:     Name: _g0 (18)
245// CHECK:     Type: Section (0xE)
246// CHECK:     Section: __text (0x1)
247// CHECK:     RefType: UndefinedNonLazy (0x0)
248// CHECK:     Flags [ (0x0)
249// CHECK:     ]
250// CHECK:     Value: 0x2
251// CHECK:   }
252// CHECK:   Symbol {
253// CHECK:     Name: _g1 (14)
254// CHECK:     Type: Section (0xE)
255// CHECK:     Section: __text (0x1)
256// CHECK:     RefType: UndefinedNonLazy (0x0)
257// CHECK:     Flags [ (0x0)
258// CHECK:     ]
259// CHECK:     Value: 0x5A
260// CHECK:   }
261// CHECK:   Symbol {
262// CHECK:     Name: _g2 (10)
263// CHECK:     Type: Section (0xE)
264// CHECK:     Section: __data (0x2)
265// CHECK:     RefType: UndefinedNonLazy (0x0)
266// CHECK:     Flags [ (0x0)
267// CHECK:     ]
268// CHECK:     Value: 0x5E
269// CHECK:   }
270// CHECK:   Symbol {
271// CHECK:     Name: _g3 (6)
272// CHECK:     Type: Section (0xE)
273// CHECK:     Section: __data (0x2)
274// CHECK:     RefType: UndefinedNonLazy (0x0)
275// CHECK:     Flags [ (0x0)
276// CHECK:     ]
277// CHECK:     Value: 0xE8
278// CHECK:   }
279// CHECK: ]
280// CHECK: Indirect Symbols {
281// CHECK:   Number: 0
282// CHECK:   Symbols [
283// CHECK:   ]
284// CHECK: }
285// CHECK: Segment {
286// CHECK:   Cmd: LC_SEGMENT_64
287// CHECK:   Name:
288// CHECK:   Size: 232
289// CHECK:   vmaddr: 0x0
290// CHECK:   vmsize: 0xEC
291// CHECK:   fileoff: 384
292// CHECK:   filesize: 236
293// CHECK:   maxprot: rwx
294// CHECK:   initprot: rwx
295// CHECK:   nsects: 2
296// CHECK:   flags: 0x0
297// CHECK: }
298// CHECK: Dysymtab {
299// CHECK:   ilocalsym: 0
300// CHECK:   nlocalsym: 5
301// CHECK:   iextdefsym: 5
302// CHECK:   nextdefsym: 0
303// CHECK:   iundefsym: 5
304// CHECK:   nundefsym: 0
305// CHECK:   tocoff: 0
306// CHECK:   ntoc: 0
307// CHECK:   modtaboff: 0
308// CHECK:   nmodtab: 0
309// CHECK:   extrefsymoff: 0
310// CHECK:   nextrefsyms: 0
311// CHECK:   indirectsymoff: 0
312// CHECK:   nindirectsyms: 0
313// CHECK:   extreloff: 0
314// CHECK:   nextrel: 0
315// CHECK:   locreloff: 0
316// CHECK:   nlocrel: 0
317// CHECK: }
318