aboutsummaryrefslogtreecommitdiffstats
path: root/test/MC/MachO/darwin-x86_64-reloc-offsets.s
blob: f748064b2bf932b2880762ab3132a0fd97a4272c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
// RUN: llvm-mc -triple x86_64-apple-darwin10 %s -filetype=obj -o - | macho-dump --dump-section-data | FileCheck %s

        .data

        .org 0x10
L0:
        .long 0
        .long 0
        .long 0
        .long 0

_d:
        .long 0
L1:
        .long 0

        .text

// These generate normal x86_64 (external) relocations. They could all use
// SIGNED, but don't for pedantic compatibility with Darwin 'as'.

        // SIGNED1
 	movb  $0x12, _d(%rip)

        // SIGNED
 	movb  $0x12, _d + 1(%rip)

        // SIGNED4
 	movl  $0x12345678, _d(%rip)

        // SIGNED
 	movl  $0x12345678, _d + 1(%rip)

        // SIGNED2
 	movl  $0x12345678, _d + 2(%rip)

        // SIGNED1
 	movl  $0x12345678, _d + 3(%rip)

        // SIGNED
 	movl  $0x12345678, _d + 4(%rip)

	movb  %al, _d(%rip)
 	movb  %al, _d + 1(%rip)
 	movl  %eax, _d(%rip)
 	movl  %eax, _d + 1(%rip)
 	movl  %eax, _d + 2(%rip)
 	movl  %eax, _d + 3(%rip)
 	movl  %eax, _d + 4(%rip)

// These have to use local relocations. Since that uses an offset into the
// section in x86_64 (as opposed to a scattered relocation), and since the
// linker can only decode this to an atom + offset by scanning the section,
// it is not possible to correctly encode these without SIGNED<N>. This is
// ultimately due to a design flaw in the x86_64 relocation format, it is
// not possible to encode an address (L<foo> + <constant>) which is outside the
// atom containing L<foo>.

        // SIGNED1
 	movb  $0x12, L0(%rip)

        // SIGNED
 	movb  $0x12, L0 + 1(%rip)

        // SIGNED4
 	movl  $0x12345678, L0(%rip)

        // SIGNED
 	movl  $0x12345678, L0 + 1(%rip)

        // SIGNED2
 	movl  $0x12345678, L0 + 2(%rip)

        // SIGNED1
 	movl  $0x12345678, L0 + 3(%rip)

        // SIGNED
 	movl  $0x12345678, L0 + 4(%rip)

 	movb  %al, L0(%rip)
 	movb  %al, L0 + 1(%rip)
 	movl  %eax, L0(%rip)
 	movl  %eax, L0 + 1(%rip)
 	movl  %eax, L0 + 2(%rip)
 	movl  %eax, L0 + 3(%rip)
 	movl  %eax, L0 + 4(%rip)

        // SIGNED1
 	movb  $0x12, L1(%rip)

        // SIGNED
 	movb  $0x12, L1 + 1(%rip)

        // SIGNED4
 	movl  $0x12345678, L1(%rip)

        // SIGNED
 	movl  $0x12345678, L1 + 1(%rip)

        // SIGNED2
 	movl  $0x12345678, L1 + 2(%rip)

        // SIGNED1
 	movl  $0x12345678, L1 + 3(%rip)

        // SIGNED
 	movl  $0x12345678, L1 + 4(%rip)

 	movb  %al, L1(%rip)
 	movb  %al, L1 + 1(%rip)
 	movl  %eax, L1(%rip)
 	movl  %eax, L1 + 1(%rip)
 	movl  %eax, L1 + 2(%rip)
 	movl  %eax, L1 + 3(%rip)
 	movl  %eax, L1 + 4(%rip)

// CHECK: ('cputype', 16777223)
// CHECK: ('cpusubtype', 3)
// CHECK: ('filetype', 1)
// CHECK: ('num_load_commands', 3)
// CHECK: ('load_commands_size', 336)
// CHECK: ('flag', 0)
// CHECK: ('reserved', 0)
// CHECK: ('load_commands', [
// CHECK:   # Load Command 0
// CHECK:  (('command', 25)
// CHECK:   ('size', 232)
// CHECK:   ('segment_name', '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
// CHECK:   ('vm_addr', 0)
// CHECK:   ('vm_size', 358)
// CHECK:   ('file_offset', 368)
// CHECK:   ('file_size', 358)
// CHECK:   ('maxprot', 7)
// CHECK:   ('initprot', 7)
// CHECK:   ('num_sections', 2)
// CHECK:   ('flags', 0)
// CHECK:   ('sections', [
// CHECK:     # Section 0
// CHECK:    (('section_name', '__text\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
// CHECK:     ('segment_name', '__TEXT\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
// CHECK:     ('address', 0)
// CHECK:     ('size', 318)
// CHECK:     ('offset', 368)
// CHECK:     ('alignment', 0)
// CHECK:     ('reloc_offset', 728)
// CHECK:     ('num_reloc', 42)
// CHECK:     ('flags', 0x80000400)
// CHECK:     ('reserved1', 0)
// CHECK:     ('reserved2', 0)
// CHECK:     ('reserved3', 0)
// CHECK:    ),
// CHECK:   ('_relocations', [
// CHECK:     # Relocation 0
// CHECK:     (('word-0', 0x13a),
// CHECK:      ('word-1', 0x1d000000)),
// CHECK:     # Relocation 1
// CHECK:     (('word-0', 0x134),
// CHECK:      ('word-1', 0x1d000000)),
// CHECK:     # Relocation 2
// CHECK:     (('word-0', 0x12e),
// CHECK:      ('word-1', 0x1d000000)),
// CHECK:     # Relocation 3
// CHECK:     (('word-0', 0x128),
// CHECK:      ('word-1', 0x1d000000)),
// CHECK:     # Relocation 4
// CHECK:     (('word-0', 0x122),
// CHECK:      ('word-1', 0x1d000000)),
// CHECK:     # Relocation 5
// CHECK:     (('word-0', 0x11c),
// CHECK:      ('word-1', 0x1d000000)),
// CHECK:     # Relocation 6
// CHECK:     (('word-0', 0x116),
// CHECK:      ('word-1', 0x1d000000)),
// CHECK:     # Relocation 7
// CHECK:     (('word-0', 0x10c),
// CHECK:      ('word-1', 0x1d000000)),
// CHECK:     # Relocation 8
// CHECK:     (('word-0', 0x102),
// CHECK:      ('word-1', 0x6d000000)),
// CHECK:     # Relocation 9
// CHECK:     (('word-0', 0xf8),
// CHECK:      ('word-1', 0x7d000000)),
// CHECK:     # Relocation 10
// CHECK:     (('word-0', 0xee),
// CHECK:      ('word-1', 0x1d000000)),
// CHECK:     # Relocation 11
// CHECK:     (('word-0', 0xe4),
// CHECK:      ('word-1', 0x8d000000)),
// CHECK:     # Relocation 12
// CHECK:     (('word-0', 0xdd),
// CHECK:      ('word-1', 0x1d000000)),
// CHECK:     # Relocation 13
// CHECK:     (('word-0', 0xd6),
// CHECK:      ('word-1', 0x6d000000)),
// CHECK:     # Relocation 14
// CHECK:     (('word-0', 0xd0),
// CHECK:      ('word-1', 0x15000002)),
// CHECK:     # Relocation 15
// CHECK:     (('word-0', 0xca),
// CHECK:      ('word-1', 0x15000002)),
// CHECK:     # Relocation 16
// CHECK:     (('word-0', 0xc4),
// CHECK:      ('word-1', 0x15000002)),
// CHECK:     # Relocation 17
// CHECK:     (('word-0', 0xbe),
// CHECK:      ('word-1', 0x15000002)),
// CHECK:     # Relocation 18
// CHECK:     (('word-0', 0xb8),
// CHECK:      ('word-1', 0x15000002)),
// CHECK:     # Relocation 19
// CHECK:     (('word-0', 0xb2),
// CHECK:      ('word-1', 0x15000002)),
// CHECK:     # Relocation 20
// CHECK:     (('word-0', 0xac),
// CHECK:      ('word-1', 0x15000002)),
// CHECK:     # Relocation 21
// CHECK:     (('word-0', 0xa2),
// CHECK:      ('word-1', 0x15000002)),
// CHECK:     # Relocation 22
// CHECK:     (('word-0', 0x98),
// CHECK:      ('word-1', 0x65000002)),
// CHECK:     # Relocation 23
// CHECK:     (('word-0', 0x8e),
// CHECK:      ('word-1', 0x75000002)),
// CHECK:     # Relocation 24
// CHECK:     (('word-0', 0x84),
// CHECK:      ('word-1', 0x15000002)),
// CHECK:     # Relocation 25
// CHECK:     (('word-0', 0x7a),
// CHECK:      ('word-1', 0x85000002)),
// CHECK:     # Relocation 26
// CHECK:     (('word-0', 0x73),
// CHECK:      ('word-1', 0x15000002)),
// CHECK:     # Relocation 27
// CHECK:     (('word-0', 0x6c),
// CHECK:      ('word-1', 0x65000002)),
// CHECK:     # Relocation 28
// CHECK:     (('word-0', 0x66),
// CHECK:      ('word-1', 0x1d000000)),
// CHECK:     # Relocation 29
// CHECK:     (('word-0', 0x60),
// CHECK:      ('word-1', 0x1d000000)),
// CHECK:     # Relocation 30
// CHECK:     (('word-0', 0x5a),
// CHECK:      ('word-1', 0x1d000000)),
// CHECK:     # Relocation 31
// CHECK:     (('word-0', 0x54),
// CHECK:      ('word-1', 0x1d000000)),
// CHECK:     # Relocation 32
// CHECK:     (('word-0', 0x4e),
// CHECK:      ('word-1', 0x1d000000)),
// CHECK:     # Relocation 33
// CHECK:     (('word-0', 0x48),
// CHECK:      ('word-1', 0x1d000000)),
// CHECK:     # Relocation 34
// CHECK:     (('word-0', 0x42),
// CHECK:      ('word-1', 0x1d000000)),
// CHECK:     # Relocation 35
// CHECK:     (('word-0', 0x38),
// CHECK:      ('word-1', 0x1d000000)),
// CHECK:     # Relocation 36
// CHECK:     (('word-0', 0x2e),
// CHECK:      ('word-1', 0x6d000000)),
// CHECK:     # Relocation 37
// CHECK:     (('word-0', 0x24),
// CHECK:      ('word-1', 0x7d000000)),
// CHECK:     # Relocation 38
// CHECK:     (('word-0', 0x1a),
// CHECK:      ('word-1', 0x1d000000)),
// CHECK:     # Relocation 39
// CHECK:     (('word-0', 0x10),
// CHECK:      ('word-1', 0x8d000000)),
// CHECK:     # Relocation 40
// CHECK:     (('word-0', 0x9),
// CHECK:      ('word-1', 0x1d000000)),
// CHECK:     # Relocation 41
// CHECK:     (('word-0', 0x2),
// CHECK:      ('word-1', 0x6d000000)),
// CHECK:   ])
// CHECK:   ('_section_data', 'c605ffff ffff12c6 05000000 0012c705 fcffffff 78563412 c705fdff ffff7856 3412c705 feffffff 78563412 c705ffff ffff7856 3412c705 00000000 78563412 88050000 00008805 01000000 89050000 00008905 01000000 89050200 00008905 03000000 89050400 0000c605 dd000000 12c605d7 00000012 c705cc00 00007856 3412c705 c3000000 78563412 c705ba00 00007856 3412c705 b1000000 78563412 c705a800 00007856 34128805 9e000000 88059900 00008905 92000000 89058d00 00008905 88000000 89058300 00008905 7e000000 c6050300 000012c6 05040000 0012c705 00000000 78563412 c7050100 00007856 3412c705 02000000 78563412 c7050300 00007856 3412c705 04000000 78563412 88050400 00008805 05000000 89050400 00008905 05000000 89050600 00008905 07000000 89050800 0000')
// CHECK:     # Section 1
// CHECK:    (('section_name', '__data\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
// CHECK:     ('segment_name', '__DATA\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
// CHECK:     ('address', 318)
// CHECK:     ('size', 40)
// CHECK:     ('offset', 686)
// CHECK:     ('alignment', 0)
// CHECK:     ('reloc_offset', 0)
// CHECK:     ('num_reloc', 0)
// CHECK:     ('flags', 0x0)
// CHECK:     ('reserved1', 0)
// CHECK:     ('reserved2', 0)
// CHECK:     ('reserved3', 0)
// CHECK:    ),
// CHECK:   ('_relocations', [
// CHECK:   ])
// CHECK:   ('_section_data', '00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000')
// CHECK:   ])
// CHECK:  ),
// CHECK:   # Load Command 1
// CHECK:  (('command', 2)
// CHECK:   ('size', 24)
// CHECK:   ('symoff', 1064)
// CHECK:   ('nsyms', 1)
// CHECK:   ('stroff', 1080)
// CHECK:   ('strsize', 4)
// CHECK:   ('_string_data', '\x00_d\x00')
// CHECK:   ('_symbols', [
// CHECK:     # Symbol 0
// CHECK:    (('n_strx', 1)
// CHECK:     ('n_type', 0xe)
// CHECK:     ('n_sect', 2)
// CHECK:     ('n_desc', 0)
// CHECK:     ('n_value', 350)
// CHECK:     ('_string', '_d')
// CHECK:    ),
// CHECK:   ])
// CHECK:  ),
// CHECK:   # Load Command 2
// CHECK:  (('command', 11)
// CHECK:   ('size', 80)
// CHECK:   ('ilocalsym', 0)
// CHECK:   ('nlocalsym', 1)
// CHECK:   ('iextdefsym', 1)
// CHECK:   ('nextdefsym', 0)
// CHECK:   ('iundefsym', 1)
// CHECK:   ('nundefsym', 0)
// CHECK:   ('tocoff', 0)
// CHECK:   ('ntoc', 0)
// CHECK:   ('modtaboff', 0)
// CHECK:   ('nmodtab', 0)
// CHECK:   ('extrefsymoff', 0)
// CHECK:   ('nextrefsyms', 0)
// CHECK:   ('indirectsymoff', 0)
// CHECK:   ('nindirectsyms', 0)
// CHECK:   ('extreloff', 0)
// CHECK:   ('nextrel', 0)
// CHECK:   ('locreloff', 0)
// CHECK:   ('nlocrel', 0)
// CHECK:   ('_indirect_symbols', [
// CHECK:   ])
// CHECK:  ),
// CHECK: ])