]>
Commit | Line | Data |
---|---|---|
d696c285 | 1 | /* |
a61fdf0a | 2 | * Copyright (c) 2005-2007 Apple Inc. All rights reserved. |
d696c285 A |
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 | ||
55e3d2f6 A |
24 | |
25 | ||
2f2f92e4 A |
26 | #if __arm__ |
27 | .text | |
28 | .align 2 | |
29 | ||
30 | .globl _test_loads | |
31 | _test_loads: | |
32 | @ PIC load of a | |
33 | ldr r0, L6 | |
34 | L0: | |
35 | ldr r0, [pc, r0] | |
36 | ||
37 | @ PIC load of c | |
38 | ldr r0, L6+4 | |
39 | L1: | |
40 | ldr r0, [pc, r0] | |
41 | ||
42 | @ sorta-absolute load of a | |
43 | ldr r0, L6+8 | |
44 | ldr r0, [r0, #0] | |
45 | ||
46 | @ sorta-absolute load of c | |
47 | ldr r0, L6+12 | |
48 | ldr r0, [r0, #0] | |
49 | ||
50 | @ sorta-absolute load of external | |
51 | ldr r0, L6+16 | |
52 | ldr r0, [r0, #0] | |
53 | ||
54 | @ PIC load of a + addend ?? | |
55 | bx lr | |
56 | ||
57 | L6: | |
58 | .long _a-(L0+8) | |
59 | .long _c-(L1+8) | |
60 | .long _a | |
61 | .long _c | |
62 | .long _ax | |
63 | ||
64 | _test_calls: | |
65 | @ call internal | |
66 | bl _test_branches | |
67 | ||
68 | @ call internal + addend | |
69 | bl _test_branches+0x19000 | |
70 | ||
71 | @ call external | |
72 | bl _external | |
73 | ||
74 | @ call external + addend | |
75 | bl _external+0x19000 | |
76 | ||
77 | ||
78 | _test_branches: | |
79 | @ call internal | |
80 | bne _test_calls | |
81 | ||
82 | @ call internal + addend | |
83 | bne _test_calls+16 | |
84 | ||
85 | @ call external | |
86 | bne _external | |
87 | ||
88 | @ call external + addend | |
89 | bne _external+16 | |
55e3d2f6 A |
90 | |
91 | _pointer_diffs: | |
92 | nop | |
93 | bl 1f | |
94 | 1: nop | |
95 | .long _foo-1b | |
96 | .long _foo+10-1b | |
97 | .long _test_branches-1b | |
98 | .long _test_branches+3-1b | |
99 | .long (_test_branches - _test_loads) + -2097152 | |
100 | .long (_test_calls - _test_loads) + -2097152 | |
101 | ||
2f2f92e4 A |
102 | #endif |
103 | ||
d696c285 A |
104 | #if __ppc__ || __ppc64__ |
105 | ||
106 | .text | |
107 | .align 2 | |
108 | ||
109 | .globl _test_loads | |
110 | _test_loads: | |
111 | stmw r30,-8(r1) | |
112 | stwu r1,-48(r1) | |
113 | Lpicbase: | |
114 | ||
115 | ; PIC load of a | |
116 | addis r2,r10,ha16(_a-Lpicbase) | |
117 | lwz r2,lo16(_a-Lpicbase)(r2) | |
118 | ||
119 | ; PIC load of c | |
120 | addis r2,r10,ha16(_c-Lpicbase) | |
121 | lwz r2,lo16(_c-Lpicbase)(r2) | |
122 | ||
123 | ; absolute load of a | |
124 | lis r2,ha16(_a) | |
125 | lwz r2,lo16(_a)(r2) | |
126 | ||
127 | ; absolute load of c | |
128 | lis r2,ha16(_c) | |
129 | lwz r2,lo16(_c)(r2) | |
130 | ||
131 | ; absolute load of external | |
132 | lis r2,ha16(_ax) | |
133 | lwz r2,lo16(_ax)(r2) | |
134 | ||
135 | ; absolute lea of external | |
136 | lis r2,hi16(_ax) | |
137 | ori r2,r2,lo16(_ax) | |
138 | ||
139 | ||
140 | ; PIC load of a + addend | |
141 | addis r2,r10,ha16(_a+0x19000-Lpicbase) | |
142 | lwz r2,lo16(_a+0x19000-Lpicbase)(r2) | |
143 | ||
144 | ; absolute load of a + addend | |
145 | lis r2,ha16(_a+0x19000) | |
146 | lwz r2,lo16(_a+0x19000)(r2) | |
147 | ||
2f2f92e4 A |
148 | ; lea of a + addend |
149 | lis r2,ha16(_a+0x19000) | |
150 | addi r2,r2,lo16(_a+0x19000) | |
151 | ||
152 | ; alt lea of a + addend | |
153 | lis r2,hi16(_a+0x19000) | |
154 | ori r2,r2,lo16(_a+0x19000) | |
155 | ||
d696c285 A |
156 | ; absolute load of external + addend |
157 | lis r2,ha16(_ax+0x19000) | |
158 | lwz r2,lo16(_ax+0x19000)(r2) | |
159 | ||
160 | ; absolute lea of external + addend | |
161 | lis r2,hi16(_ax+0x19000) | |
162 | ori r2,r2,lo16(_ax+0x19000) | |
163 | ||
164 | ||
165 | ; PIC load of a + addend | |
166 | addis r2,r10,ha16(_a+0x09000-Lpicbase) | |
167 | lwz r2,lo16(_a+0x09000-Lpicbase)(r2) | |
168 | ||
169 | ; absolute load of a + addend | |
170 | lis r2,ha16(_a+0x09000) | |
171 | lwz r2,lo16(_a+0x09000)(r2) | |
172 | ||
2f2f92e4 A |
173 | ; lea of a + addend |
174 | lis r2,ha16(_a+0x09000) | |
175 | addi r2,r2,lo16(_a+0x09000) | |
176 | ||
177 | ; alt lea of a + addend | |
178 | lis r2,hi16(_a+0x09000) | |
179 | ori r2,r2,lo16(_a+0x09000) | |
180 | ||
d696c285 A |
181 | ; absolute load of external + addend |
182 | lis r2,ha16(_ax+0x09000) | |
183 | lwz r2,lo16(_ax+0x09000)(r2) | |
184 | ||
185 | ; absolute lea of external + addend | |
186 | lis r2,hi16(_ax+0x09000) | |
187 | ori r2,r2,lo16(_ax+0x09000) | |
188 | ||
189 | blr | |
190 | ||
191 | ||
192 | _test_calls: | |
193 | ; call internal | |
194 | bl _test_branches | |
195 | ||
196 | ; call internal + addend | |
197 | bl _test_branches+0x19000 | |
198 | ||
199 | ; call external | |
200 | bl _external | |
201 | ||
202 | ; call external + addend | |
203 | bl _external+0x19000 | |
204 | ||
205 | ||
206 | _test_branches: | |
207 | ; call internal | |
208 | bne _test_calls | |
209 | ||
210 | ; call internal + addend | |
211 | bne _test_calls+16 | |
212 | ||
213 | ; call external | |
214 | bne _external | |
215 | ||
216 | ; call external + addend | |
217 | bne _external+16 | |
218 | #endif | |
219 | ||
220 | ||
221 | ||
222 | #if __i386__ | |
223 | .text | |
224 | .align 2 | |
225 | ||
226 | .globl _test_loads | |
227 | _test_loads: | |
228 | pushl %ebp | |
229 | Lpicbase: | |
230 | ||
231 | # PIC load of a | |
232 | movl _a-Lpicbase(%ebx), %eax | |
233 | ||
234 | # absolute load of a | |
235 | movl _a, %eax | |
236 | ||
237 | # absolute load of external | |
238 | movl _ax, %eax | |
239 | ||
240 | # absolute lea of external | |
241 | leal _ax, %eax | |
242 | ||
243 | ||
244 | # PIC load of a + addend | |
245 | movl _a-Lpicbase+0x19000(%ebx), %eax | |
246 | ||
247 | # absolute load of a + addend | |
248 | movl _a+0x19000(%ebx), %eax | |
249 | ||
250 | # absolute load of external + addend | |
251 | movl _ax+0x19000(%ebx), %eax | |
252 | ||
253 | # absolute lea of external + addend | |
254 | leal _ax+0x1900, %eax | |
255 | ||
256 | ret | |
257 | ||
258 | ||
259 | _test_calls: | |
260 | # call internal | |
261 | call _test_branches | |
262 | ||
263 | # call internal + addend | |
264 | call _test_branches+0x19000 | |
265 | ||
55e3d2f6 A |
266 | # 16-bit call internal |
267 | callw _test_branches | |
268 | ||
269 | # 16-bit call internal + addend | |
270 | callw _test_branches+13 | |
271 | ||
d696c285 A |
272 | # call external |
273 | call _external | |
274 | ||
275 | # call external + addend | |
276 | call _external+0x19000 | |
277 | ||
278 | ||
279 | _test_branches: | |
280 | # call internal | |
281 | jne _test_calls | |
282 | ||
283 | # call internal + addend | |
284 | jne _test_calls+16 | |
285 | ||
286 | # call external | |
287 | jne _external | |
288 | ||
289 | # call external + addend | |
290 | jne _external+16 | |
a61fdf0a A |
291 | |
292 | _pointer_diffs: | |
293 | nop | |
294 | call _get_ret_eax | |
295 | 1: movl _foo-1b(%eax),%esi | |
296 | movl _foo+10-1b(%eax),%esi | |
297 | movl _test_branches-1b(%eax),%esi | |
298 | movl _test_branches+3-1b(%eax),%esi | |
55e3d2f6 A |
299 | cmpl $(( (_test_branches - _test_loads) + -2097152 )),(%esp) |
300 | cmpl $(( (_test_calls - _test_loads) + -2097152 )),(%esp) | |
301 | ||
a61fdf0a A |
302 | |
303 | _word_relocs: | |
304 | callw _pointer_diffs | |
305 | ||
2f2f92e4 A |
306 | _byte_relocs: |
307 | mov $100, %ecx | |
308 | c_1: | |
309 | loop c_1 | |
310 | mov $100, %ecx | |
311 | c_2: | |
312 | sub $(1), %ecx | |
313 | jcxz c_2 | |
314 | ||
d696c285 A |
315 | #endif |
316 | ||
317 | ||
318 | ||
69a49097 A |
319 | #if __x86_64__ |
320 | .text | |
321 | .align 2 | |
322 | ||
323 | .globl _test_loads | |
324 | _test_loads: | |
325 | ||
326 | # PIC load of a | |
327 | movl _a(%rip), %eax | |
328 | ||
329 | # PIC load of a + addend | |
330 | movl _a+0x1234(%rip), %eax | |
331 | ||
332 | # PIC lea | |
333 | leaq _a(%rip), %rax | |
334 | ||
335 | # PIC lea through GOT | |
336 | movq _a@GOTPCREL(%rip), %rax | |
337 | ||
338 | # PIC access of GOT | |
339 | pushq _a@GOTPCREL(%rip) | |
340 | ||
341 | # PIC lea external through GOT | |
342 | movq _ax@GOTPCREL(%rip), %rax | |
343 | ||
344 | # PIC external access of GOT | |
345 | pushq _ax@GOTPCREL(%rip) | |
346 | ||
347 | # 1-byte store | |
348 | movb $0x12, _a(%rip) | |
74cfe461 A |
349 | movb $0x12, _a+2(%rip) |
350 | movb $0x12, L0(%rip) | |
69a49097 A |
351 | |
352 | # 4-byte store | |
353 | movl $0x12345678, _a(%rip) | |
74cfe461 A |
354 | movl $0x12345678, _a+4(%rip) |
355 | movl $0x12345678, L0(%rip) | |
69a49097 A |
356 | |
357 | # test local labels | |
74cfe461 A |
358 | lea L1(%rip), %rax |
359 | movl L0(%rip), %eax | |
69a49097 A |
360 | |
361 | ret | |
362 | ||
363 | ||
364 | _test_calls: | |
365 | # call internal | |
366 | call _test_branches | |
367 | ||
368 | # call internal + addend | |
369 | call _test_branches+0x19000 | |
370 | ||
371 | # call external | |
372 | call _external | |
373 | ||
374 | # call external + addend | |
375 | call _external+0x19000 | |
376 | ||
377 | ||
378 | _test_branches: | |
379 | # call internal | |
380 | jne _test_calls | |
381 | ||
382 | # call internal + addend | |
383 | jne _test_calls+16 | |
384 | ||
385 | # call external | |
386 | jne _external | |
387 | ||
388 | # call external + addend | |
389 | jne _external+16 | |
2f2f92e4 A |
390 | |
391 | _byte_relocs: | |
392 | mov $100, %ecx | |
393 | c_1: | |
394 | loop _byte_relocs | |
395 | nop | |
396 | ||
69a49097 A |
397 | #endif |
398 | ||
399 | ||
400 | ||
d696c285 A |
401 | # test that pointer-diff relocs are preserved |
402 | .text | |
403 | _test_diffs: | |
404 | .align 2 | |
405 | Llocal2: | |
406 | .long 0 | |
407 | .long Llocal2-_test_branches | |
a61fdf0a A |
408 | .long . - _test_branches |
409 | .long . - _test_branches + 8 | |
410 | .long _test_branches - . | |
411 | .long _test_branches - . + 8 | |
412 | .long _test_branches - . - 8 | |
d696c285 A |
413 | #if __ppc64__ |
414 | .quad Llocal2-_test_branches | |
415 | #endif | |
416 | ||
a61fdf0a A |
417 | _foo: nop |
418 | ||
419 | .align 2 | |
420 | _distance_from_foo: | |
421 | .long 0 | |
422 | .long . - _foo | |
423 | .long . - 8 - _foo | |
424 | ||
425 | ||
426 | _distance_to_foo: | |
427 | .long _foo - . | |
428 | .long _foo - . + 4 | |
429 | ||
430 | ||
431 | _distance_to_here: | |
432 | .long _foo - _distance_to_here | |
433 | .long _foo - _distance_to_here - 4 | |
434 | .long _foo - _distance_to_here - 12 | |
435 | .long 0 | |
436 | ||
d696c285 | 437 | |
69a49097 A |
438 | #if __x86_64__ |
439 | .data | |
440 | L0: .quad _test_branches | |
441 | _prev: | |
442 | .quad _test_branches+4 | |
443 | L1: .quad _test_branches - _test_diffs | |
444 | .quad _test_branches - _test_diffs + 4 | |
445 | .long _test_branches - _test_diffs | |
74cfe461 | 446 | # .long LCL0-. ### assembler bug: should SUB/UNSIGNED with content= LCL0-24, or single pc-rel SIGNED reloc with content = LCL0-.+4 |
69a49097 | 447 | .quad L1 |
74cfe461 | 448 | .quad L0 |
69a49097 A |
449 | .quad _test_branches - . |
450 | .quad _test_branches - L1 | |
451 | .quad L1 - _prev | |
55e3d2f6 A |
452 | #tests support for 32-bit absolute pointers |
453 | .long _prev | |
454 | .long L1 | |
69a49097 A |
455 | |
456 | # the following generates: _foo cannot be undefined in a subtraction expression | |
457 | # but it should be ok (it will be a linker error if _foo and _bar are not in same linkage unit) | |
458 | # .quad _foo - _bar ### assembler bug | |
459 | ||
460 | .section __DATA,__data2 | |
461 | LCL0: .long 2 | |
462 | ||
463 | ||
464 | #endif | |
465 | ||
466 | ||
d696c285 A |
467 | .data |
468 | _a: | |
469 | .long 0 | |
470 | ||
471 | _b: | |
2f2f92e4 | 472 | #if __ppc__ || __i386__ || __arm__ |
d696c285 A |
473 | .long _test_calls |
474 | .long _test_calls+16 | |
475 | .long _external | |
476 | .long _external+16 | |
69a49097 | 477 | #elif __ppc64__ || __x86_64__ |
d696c285 A |
478 | .quad _test_calls |
479 | .quad _test_calls+16 | |
480 | .quad _external | |
481 | .quad _external+16 | |
482 | #endif | |
483 | ||
484 | # test that reloc sizes are the same | |
485 | Llocal3: | |
486 | .long 0 | |
487 | ||
488 | Llocal4: | |
489 | .long 0 | |
490 | ||
491 | .long Llocal4-Llocal3 | |
492 | ||
493 | Lfiller: | |
494 | .space 0x9000 | |
495 | _c: | |
496 | .long 0 | |
497 |