449d2f593e732a697280bb7359419484f24113bd
[oota-llvm.git] / test / MC / MachO / darwin-x86_64-diff-relocs.s
1 // RUN: llvm-mc -triple x86_64-apple-darwin10 %s -filetype=obj -o - | macho-dump --dump-section-data | 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
16 L0:
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
88 L1:
89         xorl %eax,%eax
90
91         .data
92 _g2:
93         xorl %eax,%eax
94 L2:
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
117 L3:
118         xorl %eax,%eax
119
120 // CHECK: ('cputype', 16777223)
121 // CHECK: ('cpusubtype', 3)
122 // CHECK: ('filetype', 1)
123 // CHECK: ('num_load_commands', 3)
124 // CHECK: ('load_commands_size', 336)
125 // CHECK: ('flag', 0)
126 // CHECK: ('reserved', 0)
127 // CHECK: ('load_commands', [
128 // CHECK:   # Load Command 0
129 // CHECK:  (('command', 25)
130 // CHECK:   ('size', 232)
131 // CHECK:   ('segment_name', '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
132 // CHECK:   ('vm_addr', 0)
133 // CHECK:   ('vm_size', 236)
134 // CHECK:   ('file_offset', 368)
135 // CHECK:   ('file_size', 236)
136 // CHECK:   ('maxprot', 7)
137 // CHECK:   ('initprot', 7)
138 // CHECK:   ('num_sections', 2)
139 // CHECK:   ('flags', 0)
140 // CHECK:   ('sections', [
141 // CHECK:     # Section 0
142 // CHECK:    (('section_name', '__text\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
143 // CHECK:     ('segment_name', '__TEXT\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
144 // CHECK:     ('address', 0)
145 // CHECK:     ('size', 94)
146 // CHECK:     ('offset', 368)
147 // CHECK:     ('alignment', 0)
148 // CHECK:     ('reloc_offset', 604)
149 // CHECK:     ('num_reloc', 12)
150 // CHECK:     ('flags', 0x80000400)
151 // CHECK:     ('reserved1', 0)
152 // CHECK:     ('reserved2', 0)
153 // CHECK:     ('reserved3', 0)
154 // CHECK:    ),
155 // CHECK:   ('_relocations', [
156
157 // FIXME: Unfortunately, we do not get these relocations in exactly the same
158 // order as Darwin 'as'. It turns out that 'as' *usually* ends up emitting
159 // them in reverse address order, but sometimes it allocates some
160 // additional relocations late so these end up preceed the other entries. I
161 // haven't figured out the exact criteria for this yet.
162         
163 // CHECK:     (('word-0', 0x56),
164 // CHECK:      ('word-1', 0x1d000004)),
165 // CHECK:     (('word-0', 0x50),
166 // CHECK:      ('word-1', 0x1d000004)),
167 // CHECK:     (('word-0', 0x4a),
168 // CHECK:      ('word-1', 0x1d000003)),
169 // CHECK:     (('word-0', 0x44),
170 // CHECK:      ('word-1', 0x1d000003)),
171 // CHECK:     (('word-0', 0x3e),
172 // CHECK:      ('word-1', 0x1d000002)),
173 // CHECK:     (('word-0', 0x38),
174 // CHECK:      ('word-1', 0x1d000002)),
175 // CHECK:     (('word-0', 0x20),
176 // CHECK:      ('word-1', 0x2d000004)),
177 // CHECK:     (('word-0', 0x1b),
178 // CHECK:      ('word-1', 0x2d000004)),
179 // CHECK:     (('word-0', 0x16),
180 // CHECK:      ('word-1', 0x2d000003)),
181 // CHECK:     (('word-0', 0x11),
182 // CHECK:      ('word-1', 0x2d000003)),
183 // CHECK:     (('word-0', 0xc),
184 // CHECK:      ('word-1', 0x2d000002)),
185 // CHECK:     (('word-0', 0x5),
186 // CHECK:      ('word-1', 0x2d000000)),
187 // CHECK:   ])
188 // CHECK:     # Section 1
189 // CHECK:    (('section_name', '__data\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
190 // CHECK:     ('segment_name', '__DATA\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
191 // CHECK:     ('address', 94)
192 // CHECK:     ('size', 142)
193 // CHECK:     ('offset', 462)
194 // CHECK:     ('alignment', 0)
195 // CHECK:     ('reloc_offset', 700)
196 // CHECK:     ('num_reloc', 16)
197 // CHECK:     ('flags', 0x400)
198 // CHECK:     ('reserved1', 0)
199 // CHECK:     ('reserved2', 0)
200 // CHECK:     ('reserved3', 0)
201 // CHECK:    ),
202 // CHECK:   ('_relocations', [
203 // CHECK:     # Relocation 0
204 // CHECK:     (('word-0', 0x7a),
205 // CHECK:      ('word-1', 0x5e000001)),
206 // CHECK:     # Relocation 1
207 // CHECK:     (('word-0', 0x7a),
208 // CHECK:      ('word-1', 0xe000002)),
209 // CHECK:     # Relocation 2
210 // CHECK:     (('word-0', 0x72),
211 // CHECK:      ('word-1', 0x5e000001)),
212 // CHECK:     # Relocation 3
213 // CHECK:     (('word-0', 0x72),
214 // CHECK:      ('word-1', 0xe000002)),
215 // CHECK:     # Relocation 4
216 // CHECK:     (('word-0', 0x62),
217 // CHECK:      ('word-1', 0xe000002)),
218 // CHECK:     # Relocation 5
219 // CHECK:     (('word-0', 0x5a),
220 // CHECK:      ('word-1', 0xe000002)),
221 // CHECK:     # Relocation 6
222 // CHECK:     (('word-0', 0x52),
223 // CHECK:      ('word-1', 0xe000001)),
224 // CHECK:     # Relocation 7
225 // CHECK:     (('word-0', 0x4a),
226 // CHECK:      ('word-1', 0xe000001)),
227 // CHECK:     # Relocation 8
228 // CHECK:     (('word-0', 0x3a),
229 // CHECK:      ('word-1', 0x5e000003)),
230 // CHECK:     # Relocation 9
231 // CHECK:     (('word-0', 0x3a),
232 // CHECK:      ('word-1', 0xe000004)),
233 // CHECK:     # Relocation 10
234 // CHECK:     (('word-0', 0x32),
235 // CHECK:      ('word-1', 0x5e000003)),
236 // CHECK:     # Relocation 11
237 // CHECK:     (('word-0', 0x32),
238 // CHECK:      ('word-1', 0xe000004)),
239 // CHECK:     # Relocation 12
240 // CHECK:     (('word-0', 0x22),
241 // CHECK:      ('word-1', 0xe000004)),
242 // CHECK:     # Relocation 13
243 // CHECK:     (('word-0', 0x1a),
244 // CHECK:      ('word-1', 0xe000004)),
245 // CHECK:     # Relocation 14
246 // CHECK:     (('word-0', 0x12),
247 // CHECK:      ('word-1', 0xe000003)),
248 // CHECK:     # Relocation 15
249 // CHECK:     (('word-0', 0xa),
250 // CHECK:      ('word-1', 0xe000003)),
251 // CHECK:   ])
252 // CHECK:   ])
253 // CHECK:  ),
254 // CHECK:   # Load Command 1
255 // CHECK:  (('command', 2)
256 // CHECK:   ('size', 24)
257 // CHECK:   ('symoff', 828)
258 // CHECK:   ('nsyms', 5)
259 // CHECK:   ('stroff', 908)
260 // CHECK:   ('strsize', 24)
261 // CHECK:   ('_string_data', '\x00_foo\x00_g0\x00_g1\x00_g2\x00_g3\x00\x00\x00')
262 // CHECK:   ('_symbols', [
263 // CHECK:     # Symbol 0
264 // CHECK:    (('n_strx', 1)
265 // CHECK:     ('n_type', 0xe)
266 // CHECK:     ('n_sect', 1)
267 // CHECK:     ('n_desc', 0)
268 // CHECK:     ('n_value', 0)
269 // CHECK:     ('_string', '_foo')
270 // CHECK:    ),
271 // CHECK:     # Symbol 1
272 // CHECK:    (('n_strx', 6)
273 // CHECK:     ('n_type', 0xe)
274 // CHECK:     ('n_sect', 1)
275 // CHECK:     ('n_desc', 0)
276 // CHECK:     ('n_value', 2)
277 // CHECK:     ('_string', '_g0')
278 // CHECK:    ),
279 // CHECK:     # Symbol 2
280 // CHECK:    (('n_strx', 10)
281 // CHECK:     ('n_type', 0xe)
282 // CHECK:     ('n_sect', 1)
283 // CHECK:     ('n_desc', 0)
284 // CHECK:     ('n_value', 90)
285 // CHECK:     ('_string', '_g1')
286 // CHECK:    ),
287 // CHECK:     # Symbol 3
288 // CHECK:    (('n_strx', 14)
289 // CHECK:     ('n_type', 0xe)
290 // CHECK:     ('n_sect', 2)
291 // CHECK:     ('n_desc', 0)
292 // CHECK:     ('n_value', 94)
293 // CHECK:     ('_string', '_g2')
294 // CHECK:    ),
295 // CHECK:     # Symbol 4
296 // CHECK:    (('n_strx', 18)
297 // CHECK:     ('n_type', 0xe)
298 // CHECK:     ('n_sect', 2)
299 // CHECK:     ('n_desc', 0)
300 // CHECK:     ('n_value', 232)
301 // CHECK:     ('_string', '_g3')
302 // CHECK:    ),
303 // CHECK:   ])
304 // CHECK:  ),
305 // CHECK:   # Load Command 2
306 // CHECK:  (('command', 11)
307 // CHECK:   ('size', 80)
308 // CHECK:   ('ilocalsym', 0)
309 // CHECK:   ('nlocalsym', 5)
310 // CHECK:   ('iextdefsym', 5)
311 // CHECK:   ('nextdefsym', 0)
312 // CHECK:   ('iundefsym', 5)
313 // CHECK:   ('nundefsym', 0)
314 // CHECK:   ('tocoff', 0)
315 // CHECK:   ('ntoc', 0)
316 // CHECK:   ('modtaboff', 0)
317 // CHECK:   ('nmodtab', 0)
318 // CHECK:   ('extrefsymoff', 0)
319 // CHECK:   ('nextrefsyms', 0)
320 // CHECK:   ('indirectsymoff', 0)
321 // CHECK:   ('nindirectsyms', 0)
322 // CHECK:   ('extreloff', 0)
323 // CHECK:   ('nextrel', 0)
324 // CHECK:   ('locreloff', 0)
325 // CHECK:   ('nlocrel', 0)
326 // CHECK:   ('_indirect_symbols', [
327 // CHECK:   ])
328 // CHECK:  ),
329 // CHECK: ])