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