]> git.saurik.com Git - apple/ld64.git/blame - unit-tests/test-cases/relocs-asm/relocs-asm.s
ld64-47.2.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
193 # test that pointer-diff relocs are preserved
194 .text
195_test_diffs:
196 .align 2
197Llocal2:
198 .long 0
199 .long Llocal2-_test_branches
200#if __ppc64__
201 .quad Llocal2-_test_branches
202#endif
203
204
205 .data
206_a:
207 .long 0
208
209_b:
210#if __ppc__ || __i386__
211 .long _test_calls
212 .long _test_calls+16
213 .long _external
214 .long _external+16
215#elif __ppc64__
216 .quad _test_calls
217 .quad _test_calls+16
218 .quad _external
219 .quad _external+16
220#endif
221
222 # test that reloc sizes are the same
223Llocal3:
224 .long 0
225
226Llocal4:
227 .long 0
228
229 .long Llocal4-Llocal3
230
231Lfiller:
232 .space 0x9000
233_c:
234 .long 0
235