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