]>
Commit | Line | Data |
---|---|---|
5ae3e846 | 1 | /* Machine-dependent ELF dynamic relocation inline functions. Sparc64 version. |
d063d164 | 2 | Copyright (C) 1997-2006, 2009, 2010, 2011 Free Software Foundation, Inc. |
5ae3e846 UD |
3 | This file is part of the GNU C Library. |
4 | ||
5 | The GNU C Library is free software; you can redistribute it and/or | |
41bdb6e2 AJ |
6 | modify it under the terms of the GNU Lesser General Public |
7 | License as published by the Free Software Foundation; either | |
8 | version 2.1 of the License, or (at your option) any later version. | |
5ae3e846 UD |
9 | |
10 | The GNU C Library is distributed in the hope that it will be useful, | |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
41bdb6e2 | 13 | Lesser General Public License for more details. |
5ae3e846 | 14 | |
41bdb6e2 | 15 | You should have received a copy of the GNU Lesser General Public |
59ba27a6 PE |
16 | License along with the GNU C Library; if not, see |
17 | <http://www.gnu.org/licenses/>. */ | |
5ae3e846 | 18 | |
edac0e8f UD |
19 | #ifndef dl_machine_h |
20 | #define dl_machine_h | |
21 | ||
5ae3e846 UD |
22 | #define ELF_MACHINE_NAME "sparc64" |
23 | ||
5ae3e846 | 24 | #include <string.h> |
5ae3e846 | 25 | #include <sys/param.h> |
a42195db | 26 | #include <ldsodefs.h> |
5ae3e846 | 27 | #include <sysdep.h> |
311927f1 | 28 | #include <dl-plt.h> |
5ae3e846 | 29 | |
32e6df36 UD |
30 | #ifndef VALIDX |
31 | # define VALIDX(tag) (DT_NUM + DT_THISPROCNUM + DT_VERSIONTAGNUM \ | |
32 | + DT_EXTRANUM + DT_VALTAGIDX (tag)) | |
33 | #endif | |
34 | ||
2e65ca2b UD |
35 | #define ELF64_R_TYPE_ID(info) ((info) & 0xff) |
36 | #define ELF64_R_TYPE_DATA(info) ((info) >> 8) | |
37 | ||
ceb579a3 | 38 | /* Return nonzero iff ELF header is compatible with the running host. */ |
5ae3e846 | 39 | static inline int |
ceb579a3 | 40 | elf_machine_matches_host (const Elf64_Ehdr *ehdr) |
5ae3e846 | 41 | { |
ceb579a3 | 42 | return ehdr->e_machine == EM_SPARCV9; |
5ae3e846 UD |
43 | } |
44 | ||
cf299341 UD |
45 | /* We have to do this because elf_machine_{dynamic,load_address} can be |
46 | invoked from functions that have no GOT references, and thus the compiler | |
47 | has no obligation to load the PIC register. */ | |
48 | #define LOAD_PIC_REG(PIC_REG) \ | |
49 | do { Elf64_Addr tmp; \ | |
50 | __asm("sethi %%hi(_GLOBAL_OFFSET_TABLE_-4), %1\n\t" \ | |
51 | "rd %%pc, %0\n\t" \ | |
52 | "add %1, %%lo(_GLOBAL_OFFSET_TABLE_+4), %1\n\t" \ | |
53 | "add %0, %1, %0" \ | |
54 | : "=r" (PIC_REG), "=r" (tmp)); \ | |
55 | } while (0) | |
56 | ||
5ae3e846 UD |
57 | /* Return the link-time address of _DYNAMIC. Conveniently, this is the |
58 | first element of the GOT. This must be inlined in a function which | |
59 | uses global data. */ | |
60 | static inline Elf64_Addr | |
61 | elf_machine_dynamic (void) | |
62 | { | |
9c4c0024 | 63 | register Elf64_Addr *elf_pic_register __asm__("%l7"); |
ca34d7a7 | 64 | |
cf299341 UD |
65 | LOAD_PIC_REG (elf_pic_register); |
66 | ||
9c4c0024 | 67 | return *elf_pic_register; |
5ae3e846 UD |
68 | } |
69 | ||
5ae3e846 UD |
70 | /* Return the run-time load address of the shared object. */ |
71 | static inline Elf64_Addr | |
72 | elf_machine_load_address (void) | |
73 | { | |
8243d6f1 RM |
74 | register Elf32_Addr *pc __asm ("%o7"); |
75 | register Elf64_Addr *got __asm ("%l7"); | |
76 | ||
77 | __asm ("sethi %%hi(_GLOBAL_OFFSET_TABLE_-4), %1\n\t" | |
d063d164 UD |
78 | "call 1f\n\t" |
79 | " add %1, %%lo(_GLOBAL_OFFSET_TABLE_+4), %1\n\t" | |
80 | "call _DYNAMIC\n\t" | |
81 | "call _GLOBAL_OFFSET_TABLE_\n" | |
82 | "1:\tadd %1, %0, %1\n\t" : "=r" (pc), "=r" (got)); | |
8243d6f1 RM |
83 | |
84 | /* got is now l_addr + _GLOBAL_OFFSET_TABLE_ | |
85 | *got is _DYNAMIC | |
86 | pc[2]*4 is l_addr + _DYNAMIC - (long)pc - 8 | |
87 | pc[3]*4 is l_addr + _GLOBAL_OFFSET_TABLE_ - (long)pc - 12 */ | |
88 | return (Elf64_Addr) got - *got + (Elf32_Sword) ((pc[2] - pc[3]) * 4) - 4; | |
5ae3e846 UD |
89 | } |
90 | ||
edac0e8f | 91 | static inline Elf64_Addr __attribute__ ((always_inline)) |
c47e78b1 UD |
92 | elf_machine_fixup_plt (struct link_map *map, lookup_t t, |
93 | const Elf64_Rela *reloc, | |
94 | Elf64_Addr *reloc_addr, Elf64_Addr value) | |
95 | { | |
96 | sparc64_fixup_plt (map, reloc, reloc_addr, value + reloc->r_addend, | |
97 | reloc->r_addend, 1); | |
c0282c06 | 98 | return value; |
a2b08ee5 UD |
99 | } |
100 | ||
dfd2257a UD |
101 | /* Return the final value of a plt relocation. */ |
102 | static inline Elf64_Addr | |
103 | elf_machine_plt_value (struct link_map *map, const Elf64_Rela *reloc, | |
104 | Elf64_Addr value) | |
105 | { | |
c47e78b1 UD |
106 | /* Don't add addend here, but in elf_machine_fixup_plt instead. |
107 | value + reloc->r_addend is the value which should actually be | |
108 | stored into .plt data slot. */ | |
109 | return value; | |
dfd2257a UD |
110 | } |
111 | ||
cf5a372e UD |
112 | /* ELF_RTYPE_CLASS_PLT iff TYPE describes relocation of a PLT entry, so |
113 | PLT entries should not be allowed to define the value. | |
114 | ELF_RTYPE_CLASS_NOCOPY iff TYPE should not be allowed to resolve to one | |
115 | of the main executable's symbols, as for a COPY reloc. */ | |
d063d164 | 116 | #define elf_machine_type_class(type) \ |
edac0e8f UD |
117 | ((((type) == R_SPARC_JMP_SLOT \ |
118 | || ((type) >= R_SPARC_TLS_GD_HI22 && (type) <= R_SPARC_TLS_TPOFF64)) \ | |
119 | * ELF_RTYPE_CLASS_PLT) \ | |
120 | | (((type) == R_SPARC_COPY) * ELF_RTYPE_CLASS_COPY)) | |
5ae3e846 UD |
121 | |
122 | /* A reloc type used for ld.so cmdline arg lookups to reject PLT entries. */ | |
a2b08ee5 | 123 | #define ELF_MACHINE_JMP_SLOT R_SPARC_JMP_SLOT |
5ae3e846 UD |
124 | |
125 | /* The SPARC never uses Elf64_Rel relocations. */ | |
126 | #define ELF_MACHINE_NO_REL 1 | |
127 | ||
5ae3e846 UD |
128 | /* Set up the loaded object described by L so its unrelocated PLT |
129 | entries will jump to the on-demand fixup code in dl-runtime.c. */ | |
130 | ||
131 | static inline int | |
3996f34b | 132 | elf_machine_runtime_setup (struct link_map *l, int lazy, int profile) |
5ae3e846 | 133 | { |
5ae3e846 UD |
134 | if (l->l_info[DT_JMPREL] && lazy) |
135 | { | |
9c4c0024 UD |
136 | extern void _dl_runtime_resolve_0 (void); |
137 | extern void _dl_runtime_resolve_1 (void); | |
138 | extern void _dl_runtime_profile_0 (void); | |
139 | extern void _dl_runtime_profile_1 (void); | |
140 | Elf64_Addr res0_addr, res1_addr; | |
b86120ed | 141 | unsigned int *plt = (void *) D_PTR (l, l_info[DT_PLTGOT]); |
9c4c0024 | 142 | |
404a4e2f | 143 | if (__builtin_expect(profile, 0)) |
0ecb606c | 144 | { |
a334319f UD |
145 | res0_addr = (Elf64_Addr) &_dl_runtime_profile_0; |
146 | res1_addr = (Elf64_Addr) &_dl_runtime_profile_1; | |
404a4e2f RM |
147 | |
148 | if (GLRO(dl_profile) != NULL | |
149 | && _dl_name_match_p (GLRO(dl_profile), l)) | |
a334319f | 150 | GL(dl_profile_map) = l; |
0ecb606c | 151 | } |
404a4e2f RM |
152 | else |
153 | { | |
154 | res0_addr = (Elf64_Addr) &_dl_runtime_resolve_0; | |
155 | res1_addr = (Elf64_Addr) &_dl_runtime_resolve_1; | |
156 | } | |
9c4c0024 UD |
157 | |
158 | /* PLT0 looks like: | |
159 | ||
d063d164 | 160 | sethi %uhi(_dl_runtime_{resolve,profile}_0), %g4 |
404a4e2f RM |
161 | sethi %hi(_dl_runtime_{resolve,profile}_0), %g5 |
162 | or %g4, %ulo(_dl_runtime_{resolve,profile}_0), %g4 | |
163 | or %g5, %lo(_dl_runtime_{resolve,profile}_0), %g5 | |
164 | sllx %g4, 32, %g4 | |
165 | add %g4, %g5, %g5 | |
166 | jmpl %g5, %g4 | |
167 | nop | |
8cb079d4 | 168 | */ |
9c4c0024 | 169 | |
404a4e2f RM |
170 | plt[0] = 0x09000000 | (res0_addr >> (64 - 22)); |
171 | plt[1] = 0x0b000000 | ((res0_addr >> 10) & 0x003fffff); | |
172 | plt[2] = 0x88112000 | ((res0_addr >> 32) & 0x3ff); | |
173 | plt[3] = 0x8a116000 | (res0_addr & 0x3ff); | |
174 | plt[4] = 0x89293020; | |
175 | plt[5] = 0x8a010005; | |
176 | plt[6] = 0x89c14000; | |
177 | plt[7] = 0x01000000; | |
8cb079d4 UD |
178 | |
179 | /* PLT1 looks like: | |
180 | ||
d063d164 | 181 | sethi %uhi(_dl_runtime_{resolve,profile}_1), %g4 |
404a4e2f RM |
182 | sethi %hi(_dl_runtime_{resolve,profile}_1), %g5 |
183 | or %g4, %ulo(_dl_runtime_{resolve,profile}_1), %g4 | |
184 | or %g5, %lo(_dl_runtime_{resolve,profile}_1), %g5 | |
185 | sllx %g4, 32, %g4 | |
186 | add %g4, %g5, %g5 | |
187 | jmpl %g5, %g4 | |
188 | nop | |
8cb079d4 | 189 | */ |
9c4c0024 | 190 | |
404a4e2f RM |
191 | plt[8] = 0x09000000 | (res1_addr >> (64 - 22)); |
192 | plt[9] = 0x0b000000 | ((res1_addr >> 10) & 0x003fffff); | |
193 | plt[10] = 0x88112000 | ((res1_addr >> 32) & 0x3ff); | |
194 | plt[11] = 0x8a116000 | (res1_addr & 0x3ff); | |
195 | plt[12] = 0x89293020; | |
196 | plt[13] = 0x8a010005; | |
197 | plt[14] = 0x89c14000; | |
198 | plt[15] = 0x01000000; | |
9c4c0024 | 199 | |
4c4b9518 UD |
200 | /* Now put the magic cookie at the beginning of .PLT2 |
201 | Entry .PLT3 is unused by this implementation. */ | |
404a4e2f | 202 | *((struct link_map **)(&plt[16])) = l; |
32e6df36 UD |
203 | |
204 | if (__builtin_expect (l->l_info[VALIDX(DT_GNU_PRELINKED)] != NULL, 0) | |
205 | || __builtin_expect (l->l_info [VALIDX (DT_GNU_LIBLISTSZ)] != NULL, 0)) | |
206 | { | |
207 | /* Need to reinitialize .plt to undo prelinking. */ | |
208 | Elf64_Rela *rela = (Elf64_Rela *) D_PTR (l, l_info[DT_JMPREL]); | |
209 | Elf64_Rela *relaend | |
210 | = (Elf64_Rela *) ((char *) rela | |
211 | + l->l_info[DT_PLTRELSZ]->d_un.d_val); | |
212 | ||
213 | /* prelink must ensure there are no R_SPARC_NONE relocs left | |
214 | in .rela.plt. */ | |
215 | while (rela < relaend) | |
216 | { | |
217 | if (__builtin_expect (rela->r_addend, 0) != 0) | |
218 | { | |
1d204bf2 | 219 | Elf64_Addr slot = ((rela->r_offset + l->l_addr + 0x400 |
32e6df36 UD |
220 | - (Elf64_Addr) plt) |
221 | / 0x1400) * 0x1400 | |
222 | + (Elf64_Addr) plt - 0x400; | |
223 | /* ldx [%o7 + X], %g1 */ | |
224 | unsigned int first_ldx = *(unsigned int *)(slot + 12); | |
225 | Elf64_Addr ptr = slot + (first_ldx & 0xfff) + 4; | |
226 | ||
1d204bf2 | 227 | *(Elf64_Addr *) (rela->r_offset + l->l_addr) |
32e6df36 | 228 | = (Elf64_Addr) plt |
1d204bf2 JM |
229 | - (slot + ((rela->r_offset + l->l_addr - ptr) / 8) * 24 |
230 | + 4); | |
32e6df36 UD |
231 | ++rela; |
232 | continue; | |
233 | } | |
234 | ||
1d204bf2 JM |
235 | *(unsigned int *) (rela->r_offset + l->l_addr) |
236 | = 0x03000000 | (rela->r_offset + l->l_addr - (Elf64_Addr) plt); | |
237 | *(unsigned int *) (rela->r_offset + l->l_addr + 4) | |
238 | = 0x30680000 | ((((Elf64_Addr) plt + 32 - rela->r_offset | |
239 | - l->l_addr - 4) >> 2) & 0x7ffff); | |
240 | __asm __volatile ("flush %0" : : "r" (rela->r_offset | |
241 | + l->l_addr)); | |
242 | __asm __volatile ("flush %0+4" : : "r" (rela->r_offset | |
243 | + l->l_addr)); | |
32e6df36 UD |
244 | ++rela; |
245 | } | |
246 | } | |
5ae3e846 UD |
247 | } |
248 | ||
249 | return lazy; | |
250 | } | |
251 | ||
5ae3e846 UD |
252 | /* The PLT uses Elf64_Rela relocs. */ |
253 | #define elf_machine_relplt elf_machine_rela | |
254 | ||
97716954 | 255 | /* Undo the sub %sp, 6*8, %sp; add %sp, STACK_BIAS + 22*8, %o0 below |
2c0b250a | 256 | (but w/o STACK_BIAS) to get at the value we want in __libc_stack_end. */ |
97716954 | 257 | #define DL_STACK_END(cookie) \ |
2c0b250a | 258 | ((void *) (((long) (cookie)) - (22 - 6) * 8)) |
97716954 | 259 | |
5ae3e846 UD |
260 | /* Initial entry point code for the dynamic linker. |
261 | The C function `_dl_start' is the real entry point; | |
262 | its return value is the user program's entry point. */ | |
263 | ||
3d2b3019 DM |
264 | #define RTLD_GOT_ADDRESS(pic_reg, reg, symbol) \ |
265 | "sethi %gdop_hix22(" #symbol "), " #reg "\n\t" \ | |
266 | "xor " #reg ", %gdop_lox10(" #symbol "), " #reg "\n\t" \ | |
267 | "ldx [" #pic_reg " + " #reg "], " #reg ", %gdop(" #symbol ")\n" | |
3d2b3019 | 268 | |
5ae3e846 UD |
269 | #define __S1(x) #x |
270 | #define __S(x) __S1(x) | |
271 | ||
ba77ce24 AJ |
272 | #define RTLD_START __asm__ ( "\n" \ |
273 | " .text\n" \ | |
274 | " .global _start\n" \ | |
275 | " .type _start, @function\n" \ | |
276 | " .align 32\n" \ | |
277 | "_start:\n" \ | |
278 | " /* Make room for functions to drop their arguments on the stack. */\n" \ | |
279 | " sub %sp, 6*8, %sp\n" \ | |
280 | " /* Pass pointer to argument block to _dl_start. */\n" \ | |
281 | " call _dl_start\n" \ | |
282 | " add %sp," __S(STACK_BIAS) "+22*8,%o0\n" \ | |
283 | " /* FALLTHRU */\n" \ | |
284 | " .size _start, .-_start\n" \ | |
285 | "\n" \ | |
286 | " .global _dl_start_user\n" \ | |
287 | " .type _dl_start_user, @function\n" \ | |
288 | "_dl_start_user:\n" \ | |
289 | " /* Load the GOT register. */\n" \ | |
290 | "1: call 11f\n" \ | |
291 | " sethi %hi(_GLOBAL_OFFSET_TABLE_-(1b-.)), %l7\n" \ | |
292 | "11: or %l7, %lo(_GLOBAL_OFFSET_TABLE_-(1b-.)), %l7\n" \ | |
ba77ce24 | 293 | " add %l7, %o7, %l7\n" \ |
ba77ce24 AJ |
294 | " /* Save the user entry point address in %l0. */\n" \ |
295 | " mov %o0, %l0\n" \ | |
ba77ce24 AJ |
296 | " /* See if we were run as a command with the executable file name as an\n" \ |
297 | " extra leading argument. If so, we must shift things around since we\n" \ | |
298 | " must keep the stack doubleword aligned. */\n" \ | |
3d2b3019 DM |
299 | RTLD_GOT_ADDRESS(%l7, %g5, _dl_skip_args) \ |
300 | " ld [%g5], %i0\n" \ | |
ba77ce24 AJ |
301 | " brz,pt %i0, 2f\n" \ |
302 | " ldx [%sp + " __S(STACK_BIAS) " + 22*8], %i5\n" \ | |
303 | " /* Find out how far to shift. */\n" \ | |
ba77ce24 | 304 | " sub %i5, %i0, %i5\n" \ |
ba77ce24 | 305 | " sllx %i0, 3, %l6\n" \ |
3d2b3019 | 306 | RTLD_GOT_ADDRESS(%l7, %l4, _dl_argv) \ |
ba77ce24 AJ |
307 | " stx %i5, [%sp + " __S(STACK_BIAS) " + 22*8]\n" \ |
308 | " add %sp, " __S(STACK_BIAS) " + 23*8, %i1\n" \ | |
309 | " add %i1, %l6, %i2\n" \ | |
310 | " ldx [%l4], %l5\n" \ | |
311 | " /* Copy down argv. */\n" \ | |
312 | "12: ldx [%i2], %i3\n" \ | |
313 | " add %i2, 8, %i2\n" \ | |
314 | " stx %i3, [%i1]\n" \ | |
315 | " brnz,pt %i3, 12b\n" \ | |
316 | " add %i1, 8, %i1\n" \ | |
317 | " sub %l5, %l6, %l5\n" \ | |
318 | " /* Copy down envp. */\n" \ | |
319 | "13: ldx [%i2], %i3\n" \ | |
320 | " add %i2, 8, %i2\n" \ | |
321 | " stx %i3, [%i1]\n" \ | |
322 | " brnz,pt %i3, 13b\n" \ | |
323 | " add %i1, 8, %i1\n" \ | |
324 | " /* Copy down auxiliary table. */\n" \ | |
325 | "14: ldx [%i2], %i3\n" \ | |
326 | " ldx [%i2 + 8], %i4\n" \ | |
327 | " add %i2, 16, %i2\n" \ | |
328 | " stx %i3, [%i1]\n" \ | |
329 | " stx %i4, [%i1 + 8]\n" \ | |
330 | " brnz,pt %i3, 14b\n" \ | |
331 | " add %i1, 16, %i1\n" \ | |
332 | " stx %l5, [%l4]\n" \ | |
333 | " /* %o0 = _dl_loaded, %o1 = argc, %o2 = argv, %o3 = envp. */\n" \ | |
3d2b3019 | 334 | "2:\t" RTLD_GOT_ADDRESS(%l7, %o0, _rtld_local) \ |
ba77ce24 | 335 | " sllx %i5, 3, %o3\n" \ |
3d2b3019 | 336 | " add %sp, " __S(STACK_BIAS) " + 23*8, %o2\n" \ |
ba77ce24 AJ |
337 | " add %o3, 8, %o3\n" \ |
338 | " mov %i5, %o1\n" \ | |
339 | " add %o2, %o3, %o3\n" \ | |
7969407a | 340 | " call _dl_init_internal\n" \ |
ba77ce24 AJ |
341 | " ldx [%o0], %o0\n" \ |
342 | " /* Pass our finalizer function to the user in %g1. */\n" \ | |
3d2b3019 | 343 | RTLD_GOT_ADDRESS(%l7, %g1, _dl_fini) \ |
ba77ce24 AJ |
344 | " /* Jump to the user's entry point and deallocate the extra stack we got. */\n" \ |
345 | " jmp %l0\n" \ | |
346 | " add %sp, 6*8, %sp\n" \ | |
347 | " .size _dl_start_user, . - _dl_start_user\n" \ | |
348 | " .previous\n"); | |
edac0e8f UD |
349 | |
350 | #endif /* dl_machine_h */ | |
351 | ||
352 | #define ARCH_LA_PLTENTER sparc64_gnu_pltenter | |
353 | #define ARCH_LA_PLTEXIT sparc64_gnu_pltexit | |
354 | ||
355 | #ifdef RESOLVE_MAP | |
356 | ||
357 | /* Perform the relocation specified by RELOC and SYM (which is fully resolved). | |
358 | MAP is the object containing the reloc. */ | |
359 | ||
360 | auto inline void | |
361 | __attribute__ ((always_inline)) | |
362 | elf_machine_rela (struct link_map *map, const Elf64_Rela *reloc, | |
363 | const Elf64_Sym *sym, const struct r_found_version *version, | |
3a62d00d | 364 | void *const reloc_addr_arg, int skip_ifunc) |
edac0e8f UD |
365 | { |
366 | Elf64_Addr *const reloc_addr = reloc_addr_arg; | |
367 | #if !defined RTLD_BOOTSTRAP && !defined RESOLVE_CONFLICT_FIND_MAP | |
368 | const Elf64_Sym *const refsym = sym; | |
369 | #endif | |
370 | Elf64_Addr value; | |
371 | const unsigned long int r_type = ELF64_R_TYPE_ID (reloc->r_info); | |
372 | #if !defined RESOLVE_CONFLICT_FIND_MAP | |
373 | struct link_map *sym_map = NULL; | |
374 | #endif | |
375 | ||
376 | #if !defined RTLD_BOOTSTRAP && !defined HAVE_Z_COMBRELOC | |
377 | /* This is defined in rtld.c, but nowhere in the static libc.a; make the | |
378 | reference weak so static programs can still link. This declaration | |
379 | cannot be done when compiling rtld.c (i.e. #ifdef RTLD_BOOTSTRAP) | |
380 | because rtld.c contains the common defn for _dl_rtld_map, which is | |
381 | incompatible with a weak decl in the same file. */ | |
382 | weak_extern (_dl_rtld_map); | |
383 | #endif | |
384 | ||
385 | if (__builtin_expect (r_type == R_SPARC_NONE, 0)) | |
386 | return; | |
387 | ||
5ed848f3 DM |
388 | if (__builtin_expect (r_type == R_SPARC_SIZE64, 0)) |
389 | { | |
390 | *reloc_addr = sym->st_size + reloc->r_addend; | |
391 | return; | |
392 | } | |
393 | ||
edac0e8f UD |
394 | #if !defined RTLD_BOOTSTRAP || !defined HAVE_Z_COMBRELOC |
395 | if (__builtin_expect (r_type == R_SPARC_RELATIVE, 0)) | |
396 | { | |
397 | # if !defined RTLD_BOOTSTRAP && !defined HAVE_Z_COMBRELOC | |
398 | if (map != &_dl_rtld_map) /* Already done in rtld itself. */ | |
399 | # endif | |
400 | *reloc_addr += map->l_addr + reloc->r_addend; | |
401 | return; | |
402 | } | |
403 | #endif | |
404 | ||
405 | #ifndef RESOLVE_CONFLICT_FIND_MAP | |
406 | if (__builtin_expect (ELF64_ST_BIND (sym->st_info) == STB_LOCAL, 0) | |
407 | && sym->st_shndx != SHN_UNDEF) | |
408 | { | |
409 | value = map->l_addr; | |
410 | } | |
411 | else | |
412 | { | |
413 | sym_map = RESOLVE_MAP (&sym, version, r_type); | |
414 | value = sym_map == NULL ? 0 : sym_map->l_addr + sym->st_value; | |
415 | } | |
416 | #else | |
417 | value = 0; | |
418 | #endif | |
419 | ||
420 | value += reloc->r_addend; /* Assume copy relocs have zero addend. */ | |
421 | ||
311927f1 DM |
422 | if (sym != NULL |
423 | && __builtin_expect (ELFW(ST_TYPE) (sym->st_info) == STT_GNU_IFUNC, 0) | |
3a62d00d AS |
424 | && __builtin_expect (sym->st_shndx != SHN_UNDEF, 1) |
425 | && __builtin_expect (!skip_ifunc, 1)) | |
9b849836 | 426 | value = ((Elf64_Addr (*) (int)) value) (GLRO(dl_hwcap)); |
311927f1 | 427 | |
edac0e8f UD |
428 | switch (r_type) |
429 | { | |
430 | #if !defined RTLD_BOOTSTRAP && !defined RESOLVE_CONFLICT_FIND_MAP | |
431 | case R_SPARC_COPY: | |
432 | if (sym == NULL) | |
433 | /* This can happen in trace mode if an object could not be | |
434 | found. */ | |
435 | break; | |
436 | if (sym->st_size > refsym->st_size | |
437 | || (GLRO(dl_verbose) && sym->st_size < refsym->st_size)) | |
438 | { | |
439 | const char *strtab; | |
440 | ||
441 | strtab = (const void *) D_PTR (map, l_info[DT_STRTAB]); | |
442 | _dl_error_printf ("\ | |
443 | %s: Symbol `%s' has different size in shared object, consider re-linking\n", | |
444 | rtld_progname ?: "<program name unknown>", | |
445 | strtab + refsym->st_name); | |
446 | } | |
447 | memcpy (reloc_addr_arg, (void *) value, | |
448 | MIN (sym->st_size, refsym->st_size)); | |
449 | break; | |
450 | #endif | |
451 | case R_SPARC_64: | |
452 | case R_SPARC_GLOB_DAT: | |
453 | *reloc_addr = value; | |
454 | break; | |
311927f1 | 455 | case R_SPARC_IRELATIVE: |
9b849836 | 456 | value = ((Elf64_Addr (*) (int)) value) (GLRO(dl_hwcap)); |
311927f1 DM |
457 | *reloc_addr = value; |
458 | break; | |
459 | case R_SPARC_JMP_IREL: | |
9b849836 | 460 | value = ((Elf64_Addr (*) (int)) value) (GLRO(dl_hwcap)); |
311927f1 | 461 | /* Fall thru */ |
edac0e8f UD |
462 | case R_SPARC_JMP_SLOT: |
463 | #ifdef RESOLVE_CONFLICT_FIND_MAP | |
464 | /* R_SPARC_JMP_SLOT conflicts against .plt[32768+] | |
465 | relocs should be turned into R_SPARC_64 relocs | |
466 | in .gnu.conflict section. | |
467 | r_addend non-zero does not mean it is a .plt[32768+] | |
468 | reloc, instead it is the actual address of the function | |
469 | to call. */ | |
470 | sparc64_fixup_plt (NULL, reloc, reloc_addr, value, 0, 0); | |
471 | #else | |
472 | sparc64_fixup_plt (map, reloc, reloc_addr, value, reloc->r_addend, 0); | |
473 | #endif | |
474 | break; | |
d063d164 | 475 | #ifndef RESOLVE_CONFLICT_FIND_MAP |
edac0e8f UD |
476 | case R_SPARC_TLS_DTPMOD64: |
477 | /* Get the information from the link map returned by the | |
478 | resolv function. */ | |
479 | if (sym_map != NULL) | |
480 | *reloc_addr = sym_map->l_tls_modid; | |
481 | break; | |
482 | case R_SPARC_TLS_DTPOFF64: | |
483 | /* During relocation all TLS symbols are defined and used. | |
484 | Therefore the offset is already correct. */ | |
485 | *reloc_addr = (sym == NULL ? 0 : sym->st_value) + reloc->r_addend; | |
486 | break; | |
487 | case R_SPARC_TLS_TPOFF64: | |
488 | /* The offset is negative, forward from the thread pointer. */ | |
489 | /* We know the offset of object the symbol is contained in. | |
490 | It is a negative value which will be added to the | |
491 | thread pointer. */ | |
492 | if (sym != NULL) | |
493 | { | |
494 | CHECK_STATIC_TLS (map, sym_map); | |
495 | *reloc_addr = sym->st_value - sym_map->l_tls_offset | |
496 | + reloc->r_addend; | |
497 | } | |
498 | break; | |
499 | # ifndef RTLD_BOOTSTRAP | |
500 | case R_SPARC_TLS_LE_HIX22: | |
501 | case R_SPARC_TLS_LE_LOX10: | |
502 | if (sym != NULL) | |
503 | { | |
504 | CHECK_STATIC_TLS (map, sym_map); | |
505 | value = sym->st_value - sym_map->l_tls_offset | |
506 | + reloc->r_addend; | |
507 | if (r_type == R_SPARC_TLS_LE_HIX22) | |
d6d1c4c8 DM |
508 | *(unsigned int *)reloc_addr = |
509 | ((*(unsigned int *)reloc_addr & 0xffc00000) | |
510 | | (((~value) >> 10) & 0x3fffff)); | |
edac0e8f | 511 | else |
d6d1c4c8 DM |
512 | *(unsigned int *)reloc_addr = |
513 | ((*(unsigned int *)reloc_addr & 0xffffe000) | (value & 0x3ff) | |
514 | | 0x1c00); | |
edac0e8f UD |
515 | } |
516 | break; | |
517 | # endif | |
518 | #endif | |
519 | #ifndef RTLD_BOOTSTRAP | |
520 | case R_SPARC_8: | |
521 | *(char *) reloc_addr = value; | |
522 | break; | |
523 | case R_SPARC_16: | |
524 | *(short *) reloc_addr = value; | |
525 | break; | |
526 | case R_SPARC_32: | |
527 | *(unsigned int *) reloc_addr = value; | |
528 | break; | |
529 | case R_SPARC_DISP8: | |
530 | *(char *) reloc_addr = (value - (Elf64_Addr) reloc_addr); | |
531 | break; | |
532 | case R_SPARC_DISP16: | |
533 | *(short *) reloc_addr = (value - (Elf64_Addr) reloc_addr); | |
534 | break; | |
535 | case R_SPARC_DISP32: | |
536 | *(unsigned int *) reloc_addr = (value - (Elf64_Addr) reloc_addr); | |
537 | break; | |
538 | case R_SPARC_WDISP30: | |
539 | *(unsigned int *) reloc_addr = | |
540 | ((*(unsigned int *)reloc_addr & 0xc0000000) | | |
2b6a801e | 541 | (((value - (Elf64_Addr) reloc_addr) >> 2) & 0x3fffffff)); |
edac0e8f UD |
542 | break; |
543 | ||
544 | /* MEDLOW code model relocs */ | |
545 | case R_SPARC_LO10: | |
546 | *(unsigned int *) reloc_addr = | |
547 | ((*(unsigned int *)reloc_addr & ~0x3ff) | | |
548 | (value & 0x3ff)); | |
549 | break; | |
550 | case R_SPARC_HI22: | |
551 | *(unsigned int *) reloc_addr = | |
552 | ((*(unsigned int *)reloc_addr & 0xffc00000) | | |
2b6a801e | 553 | ((value >> 10) & 0x3fffff)); |
edac0e8f UD |
554 | break; |
555 | case R_SPARC_OLO10: | |
556 | *(unsigned int *) reloc_addr = | |
557 | ((*(unsigned int *)reloc_addr & ~0x1fff) | | |
558 | (((value & 0x3ff) + ELF64_R_TYPE_DATA (reloc->r_info)) & 0x1fff)); | |
559 | break; | |
560 | ||
5ed848f3 DM |
561 | /* ABS34 code model reloc */ |
562 | case R_SPARC_H34: | |
563 | *(unsigned int *) reloc_addr = | |
564 | ((*(unsigned int *)reloc_addr & 0xffc00000) | | |
565 | ((value >> 12) & 0x3fffff)); | |
566 | ||
edac0e8f UD |
567 | /* MEDMID code model relocs */ |
568 | case R_SPARC_H44: | |
569 | *(unsigned int *) reloc_addr = | |
570 | ((*(unsigned int *)reloc_addr & 0xffc00000) | | |
2b6a801e | 571 | ((value >> 22) & 0x3fffff)); |
edac0e8f UD |
572 | break; |
573 | case R_SPARC_M44: | |
574 | *(unsigned int *) reloc_addr = | |
575 | ((*(unsigned int *)reloc_addr & ~0x3ff) | | |
576 | ((value >> 12) & 0x3ff)); | |
577 | break; | |
578 | case R_SPARC_L44: | |
579 | *(unsigned int *) reloc_addr = | |
580 | ((*(unsigned int *)reloc_addr & ~0xfff) | | |
581 | (value & 0xfff)); | |
582 | break; | |
583 | ||
584 | /* MEDANY code model relocs */ | |
585 | case R_SPARC_HH22: | |
586 | *(unsigned int *) reloc_addr = | |
587 | ((*(unsigned int *)reloc_addr & 0xffc00000) | | |
588 | (value >> 42)); | |
589 | break; | |
590 | case R_SPARC_HM10: | |
591 | *(unsigned int *) reloc_addr = | |
592 | ((*(unsigned int *)reloc_addr & ~0x3ff) | | |
593 | ((value >> 32) & 0x3ff)); | |
594 | break; | |
595 | case R_SPARC_LM22: | |
596 | *(unsigned int *) reloc_addr = | |
597 | ((*(unsigned int *)reloc_addr & 0xffc00000) | | |
598 | ((value >> 10) & 0x003fffff)); | |
599 | break; | |
600 | case R_SPARC_UA16: | |
601 | ((unsigned char *) reloc_addr_arg) [0] = value >> 8; | |
602 | ((unsigned char *) reloc_addr_arg) [1] = value; | |
603 | break; | |
604 | case R_SPARC_UA32: | |
605 | ((unsigned char *) reloc_addr_arg) [0] = value >> 24; | |
606 | ((unsigned char *) reloc_addr_arg) [1] = value >> 16; | |
607 | ((unsigned char *) reloc_addr_arg) [2] = value >> 8; | |
608 | ((unsigned char *) reloc_addr_arg) [3] = value; | |
609 | break; | |
610 | case R_SPARC_UA64: | |
611 | if (! ((long) reloc_addr_arg & 3)) | |
612 | { | |
613 | /* Common in .eh_frame */ | |
614 | ((unsigned int *) reloc_addr_arg) [0] = value >> 32; | |
615 | ((unsigned int *) reloc_addr_arg) [1] = value; | |
616 | break; | |
617 | } | |
618 | ((unsigned char *) reloc_addr_arg) [0] = value >> 56; | |
619 | ((unsigned char *) reloc_addr_arg) [1] = value >> 48; | |
620 | ((unsigned char *) reloc_addr_arg) [2] = value >> 40; | |
621 | ((unsigned char *) reloc_addr_arg) [3] = value >> 32; | |
622 | ((unsigned char *) reloc_addr_arg) [4] = value >> 24; | |
623 | ((unsigned char *) reloc_addr_arg) [5] = value >> 16; | |
624 | ((unsigned char *) reloc_addr_arg) [6] = value >> 8; | |
625 | ((unsigned char *) reloc_addr_arg) [7] = value; | |
626 | break; | |
627 | #endif | |
628 | #if !defined RTLD_BOOTSTRAP || defined _NDEBUG | |
629 | default: | |
630 | _dl_reloc_bad_type (map, r_type, 0); | |
631 | break; | |
632 | #endif | |
633 | } | |
634 | } | |
635 | ||
636 | auto inline void | |
637 | __attribute__ ((always_inline)) | |
638 | elf_machine_rela_relative (Elf64_Addr l_addr, const Elf64_Rela *reloc, | |
639 | void *const reloc_addr_arg) | |
640 | { | |
641 | Elf64_Addr *const reloc_addr = reloc_addr_arg; | |
642 | *reloc_addr = l_addr + reloc->r_addend; | |
643 | } | |
644 | ||
645 | auto inline void | |
646 | __attribute__ ((always_inline)) | |
647 | elf_machine_lazy_rel (struct link_map *map, | |
3a62d00d AS |
648 | Elf64_Addr l_addr, const Elf64_Rela *reloc, |
649 | int skip_ifunc) | |
edac0e8f | 650 | { |
311927f1 DM |
651 | Elf64_Addr *const reloc_addr = (void *) (l_addr + reloc->r_offset); |
652 | const unsigned int r_type = ELF64_R_TYPE (reloc->r_info); | |
653 | ||
654 | if (__builtin_expect (r_type == R_SPARC_JMP_SLOT, 1)) | |
655 | ; | |
656 | else if (r_type == R_SPARC_JMP_IREL | |
657 | || r_type == R_SPARC_IRELATIVE) | |
edac0e8f | 658 | { |
311927f1 | 659 | Elf64_Addr value = map->l_addr + reloc->r_addend; |
3a62d00d AS |
660 | if (__builtin_expect (!skip_ifunc, 1)) |
661 | value = ((Elf64_Addr (*) (int)) value) (GLRO(dl_hwcap)); | |
311927f1 DM |
662 | if (r_type == R_SPARC_JMP_IREL) |
663 | { | |
664 | /* 'high' is always zero, for large PLT entries the linker | |
665 | emits an R_SPARC_IRELATIVE. */ | |
7ec1221f | 666 | sparc64_fixup_plt (map, reloc, reloc_addr, value, 0, 1); |
311927f1 DM |
667 | } |
668 | else | |
669 | *reloc_addr = value; | |
edac0e8f | 670 | } |
311927f1 DM |
671 | else if (r_type == R_SPARC_NONE) |
672 | ; | |
673 | else | |
674 | _dl_reloc_bad_type (map, r_type, 1); | |
edac0e8f UD |
675 | } |
676 | ||
677 | #endif /* RESOLVE_MAP */ |