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