]> git.saurik.com Git - apple/ld64.git/blob - unit-tests/test-cases/relocs-asm/relocs-asm.s
28cfc566a66eb4bbede84bb4a878b7c1706f2dbf
[apple/ld64.git] / unit-tests / test-cases / relocs-asm / relocs-asm.s
1 /*
2 * Copyright (c) 2005-2007 Apple Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24 #if __ppc__ || __ppc64__
25
26 .text
27 .align 2
28
29 .globl _test_loads
30 _test_loads:
31 stmw r30,-8(r1)
32 stwu r1,-48(r1)
33 Lpicbase:
34
35 ; PIC load of a
36 addis r2,r10,ha16(_a-Lpicbase)
37 lwz r2,lo16(_a-Lpicbase)(r2)
38
39 ; PIC load of c
40 addis r2,r10,ha16(_c-Lpicbase)
41 lwz r2,lo16(_c-Lpicbase)(r2)
42
43 ; absolute load of a
44 lis r2,ha16(_a)
45 lwz r2,lo16(_a)(r2)
46
47 ; absolute load of c
48 lis r2,ha16(_c)
49 lwz r2,lo16(_c)(r2)
50
51 ; absolute load of external
52 lis r2,ha16(_ax)
53 lwz r2,lo16(_ax)(r2)
54
55 ; absolute lea of external
56 lis r2,hi16(_ax)
57 ori r2,r2,lo16(_ax)
58
59
60 ; PIC load of a + addend
61 addis r2,r10,ha16(_a+0x19000-Lpicbase)
62 lwz r2,lo16(_a+0x19000-Lpicbase)(r2)
63
64 ; absolute load of a + addend
65 lis r2,ha16(_a+0x19000)
66 lwz r2,lo16(_a+0x19000)(r2)
67
68 ; absolute load of external + addend
69 lis r2,ha16(_ax+0x19000)
70 lwz r2,lo16(_ax+0x19000)(r2)
71
72 ; absolute lea of external + addend
73 lis r2,hi16(_ax+0x19000)
74 ori r2,r2,lo16(_ax+0x19000)
75
76
77 ; PIC load of a + addend
78 addis r2,r10,ha16(_a+0x09000-Lpicbase)
79 lwz r2,lo16(_a+0x09000-Lpicbase)(r2)
80
81 ; absolute load of a + addend
82 lis r2,ha16(_a+0x09000)
83 lwz r2,lo16(_a+0x09000)(r2)
84
85 ; absolute load of external + addend
86 lis r2,ha16(_ax+0x09000)
87 lwz r2,lo16(_ax+0x09000)(r2)
88
89 ; absolute lea of external + addend
90 lis r2,hi16(_ax+0x09000)
91 ori r2,r2,lo16(_ax+0x09000)
92
93 blr
94
95
96 _test_calls:
97 ; call internal
98 bl _test_branches
99
100 ; call internal + addend
101 bl _test_branches+0x19000
102
103 ; call external
104 bl _external
105
106 ; call external + addend
107 bl _external+0x19000
108
109
110 _test_branches:
111 ; call internal
112 bne _test_calls
113
114 ; call internal + addend
115 bne _test_calls+16
116
117 ; call external
118 bne _external
119
120 ; call external + addend
121 bne _external+16
122 #endif
123
124
125
126 #if __i386__
127 .text
128 .align 2
129
130 .globl _test_loads
131 _test_loads:
132 pushl %ebp
133 Lpicbase:
134
135 # PIC load of a
136 movl _a-Lpicbase(%ebx), %eax
137
138 # absolute load of a
139 movl _a, %eax
140
141 # absolute load of external
142 movl _ax, %eax
143
144 # absolute lea of external
145 leal _ax, %eax
146
147
148 # PIC load of a + addend
149 movl _a-Lpicbase+0x19000(%ebx), %eax
150
151 # absolute load of a + addend
152 movl _a+0x19000(%ebx), %eax
153
154 # absolute load of external + addend
155 movl _ax+0x19000(%ebx), %eax
156
157 # absolute lea of external + addend
158 leal _ax+0x1900, %eax
159
160 ret
161
162
163 _test_calls:
164 # call internal
165 call _test_branches
166
167 # call internal + addend
168 call _test_branches+0x19000
169
170 # call external
171 call _external
172
173 # call external + addend
174 call _external+0x19000
175
176
177 _test_branches:
178 # call internal
179 jne _test_calls
180
181 # call internal + addend
182 jne _test_calls+16
183
184 # call external
185 jne _external
186
187 # call external + addend
188 jne _external+16
189
190 _pointer_diffs:
191 nop
192 call _get_ret_eax
193 1: movl _foo-1b(%eax),%esi
194 movl _foo+10-1b(%eax),%esi
195 movl _test_branches-1b(%eax),%esi
196 movl _test_branches+3-1b(%eax),%esi
197
198 _word_relocs:
199 callw _pointer_diffs
200
201 #endif
202
203
204
205 #if __x86_64__
206 .text
207 .align 2
208
209 .globl _test_loads
210 _test_loads:
211
212 # PIC load of a
213 movl _a(%rip), %eax
214
215 # PIC load of a + addend
216 movl _a+0x1234(%rip), %eax
217
218 # PIC lea
219 leaq _a(%rip), %rax
220
221 # PIC lea through GOT
222 movq _a@GOTPCREL(%rip), %rax
223
224 # PIC access of GOT
225 pushq _a@GOTPCREL(%rip)
226
227 # PIC lea external through GOT
228 movq _ax@GOTPCREL(%rip), %rax
229
230 # PIC external access of GOT
231 pushq _ax@GOTPCREL(%rip)
232
233 # 1-byte store
234 movb $0x12, _a(%rip)
235 movb $0x12, _a+2(%rip)
236 movb $0x12, L0(%rip)
237
238 # 4-byte store
239 movl $0x12345678, _a(%rip)
240 movl $0x12345678, _a+4(%rip)
241 movl $0x12345678, L0(%rip)
242
243 # test local labels
244 lea L1(%rip), %rax
245 movl L0(%rip), %eax
246
247 ret
248
249
250 _test_calls:
251 # call internal
252 call _test_branches
253
254 # call internal + addend
255 call _test_branches+0x19000
256
257 # call external
258 call _external
259
260 # call external + addend
261 call _external+0x19000
262
263
264 _test_branches:
265 # call internal
266 jne _test_calls
267
268 # call internal + addend
269 jne _test_calls+16
270
271 # call external
272 jne _external
273
274 # call external + addend
275 jne _external+16
276 #endif
277
278
279
280 # test that pointer-diff relocs are preserved
281 .text
282 _test_diffs:
283 .align 2
284 Llocal2:
285 .long 0
286 .long Llocal2-_test_branches
287 .long . - _test_branches
288 .long . - _test_branches + 8
289 .long _test_branches - .
290 .long _test_branches - . + 8
291 .long _test_branches - . - 8
292 #if __ppc64__
293 .quad Llocal2-_test_branches
294 #endif
295
296 _foo: nop
297
298 .align 2
299 _distance_from_foo:
300 .long 0
301 .long . - _foo
302 .long . - 8 - _foo
303
304
305 _distance_to_foo:
306 .long _foo - .
307 .long _foo - . + 4
308
309
310 _distance_to_here:
311 .long _foo - _distance_to_here
312 .long _foo - _distance_to_here - 4
313 .long _foo - _distance_to_here - 12
314 .long 0
315
316
317 #if __x86_64__
318 .data
319 L0: .quad _test_branches
320 _prev:
321 .quad _test_branches+4
322 L1: .quad _test_branches - _test_diffs
323 .quad _test_branches - _test_diffs + 4
324 .long _test_branches - _test_diffs
325 # .long LCL0-. ### assembler bug: should SUB/UNSIGNED with content= LCL0-24, or single pc-rel SIGNED reloc with content = LCL0-.+4
326 .quad L1
327 .quad L0
328 .quad _test_branches - .
329 .quad _test_branches - L1
330 .quad L1 - _prev
331
332 # the following generates: _foo cannot be undefined in a subtraction expression
333 # but it should be ok (it will be a linker error if _foo and _bar are not in same linkage unit)
334 # .quad _foo - _bar ### assembler bug
335
336 .section __DATA,__data2
337 LCL0: .long 2
338
339
340 #endif
341
342
343 .data
344 _a:
345 .long 0
346
347 _b:
348 #if __ppc__ || __i386__
349 .long _test_calls
350 .long _test_calls+16
351 .long _external
352 .long _external+16
353 #elif __ppc64__ || __x86_64__
354 .quad _test_calls
355 .quad _test_calls+16
356 .quad _external
357 .quad _external+16
358 #endif
359
360 # test that reloc sizes are the same
361 Llocal3:
362 .long 0
363
364 Llocal4:
365 .long 0
366
367 .long Llocal4-Llocal3
368
369 Lfiller:
370 .space 0x9000
371 _c:
372 .long 0
373