]> git.saurik.com Git - apple/ld64.git/blame - unit-tests/test-cases/relocs-asm/relocs-asm.s
ld64-59.3.tar.gz
[apple/ld64.git] / unit-tests / test-cases / relocs-asm / relocs-asm.s
CommitLineData
d696c285
A
1/*
2 * Copyright (c) 2005 Apple Computer, 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)
33Lpicbase:
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
133Lpicbase:
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#endif
190
191
192
69a49097
A
193#if __x86_64__
194 .text
195 .align 2
196
197 .globl _test_loads
198_test_loads:
199
200 # PIC load of a
201 movl _a(%rip), %eax
202
203 # PIC load of a + addend
204 movl _a+0x1234(%rip), %eax
205
206 # PIC lea
207 leaq _a(%rip), %rax
208
209 # PIC lea through GOT
210 movq _a@GOTPCREL(%rip), %rax
211
212 # PIC access of GOT
213 pushq _a@GOTPCREL(%rip)
214
215 # PIC lea external through GOT
216 movq _ax@GOTPCREL(%rip), %rax
217
218 # PIC external access of GOT
219 pushq _ax@GOTPCREL(%rip)
220
221 # 1-byte store
222 movb $0x12, _a(%rip)
223
224 # 4-byte store
225 movl $0x12345678, _a(%rip)
226
227 # test local labels
228# lea L1(%rip), %rax ### assembler bug
229# movl L0(%rip), %eax ### assembler bug
230
231 ret
232
233
234_test_calls:
235 # call internal
236 call _test_branches
237
238 # call internal + addend
239 call _test_branches+0x19000
240
241 # call external
242 call _external
243
244 # call external + addend
245 call _external+0x19000
246
247
248_test_branches:
249 # call internal
250 jne _test_calls
251
252 # call internal + addend
253 jne _test_calls+16
254
255 # call external
256 jne _external
257
258 # call external + addend
259 jne _external+16
260#endif
261
262
263
d696c285
A
264 # test that pointer-diff relocs are preserved
265 .text
266_test_diffs:
267 .align 2
268Llocal2:
269 .long 0
270 .long Llocal2-_test_branches
271#if __ppc64__
272 .quad Llocal2-_test_branches
273#endif
274
275
69a49097
A
276#if __x86_64__
277 .data
278L0: .quad _test_branches
279_prev:
280 .quad _test_branches+4
281L1: .quad _test_branches - _test_diffs
282 .quad _test_branches - _test_diffs + 4
283 .long _test_branches - _test_diffs
284# .long LCL0-. ### assembler bug: content value should be (address(LCL0) - 0x24)
285 .quad L1
286# .quad L0 ### assembler bug: should be internal reloc to L0
287 .quad _test_branches - .
288 .quad _test_branches - L1
289 .quad L1 - _prev
290
291# the following generates: _foo cannot be undefined in a subtraction expression
292# but it should be ok (it will be a linker error if _foo and _bar are not in same linkage unit)
293# .quad _foo - _bar ### assembler bug
294
295 .section __DATA,__data2
296LCL0: .long 2
297
298
299#endif
300
301
d696c285
A
302 .data
303_a:
304 .long 0
305
306_b:
307#if __ppc__ || __i386__
308 .long _test_calls
309 .long _test_calls+16
310 .long _external
311 .long _external+16
69a49097 312#elif __ppc64__ || __x86_64__
d696c285
A
313 .quad _test_calls
314 .quad _test_calls+16
315 .quad _external
316 .quad _external+16
317#endif
318
319 # test that reloc sizes are the same
320Llocal3:
321 .long 0
322
323Llocal4:
324 .long 0
325
326 .long Llocal4-Llocal3
327
328Lfiller:
329 .space 0x9000
330_c:
331 .long 0
332