]> git.ipfire.org Git - thirdparty/glibc.git/blame - sysdeps/sparc/sparc64/dl-machine.h
Remove sparc binutils GOTDATA checks in lieu of new minimum version requirement.
[thirdparty/glibc.git] / sysdeps / sparc / sparc64 / dl-machine.h
CommitLineData
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 39static inline int
ceb579a3 40elf_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) \
49do { 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. */
60static inline Elf64_Addr
61elf_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. */
71static inline Elf64_Addr
72elf_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 91static inline Elf64_Addr __attribute__ ((always_inline))
c47e78b1
UD
92elf_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. */
102static inline Elf64_Addr
103elf_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
ca34d7a7
UD
128/* The SPARC overlaps DT_RELA and DT_PLTREL. */
129#define ELF_MACHINE_PLTREL_OVERLAP 1
5ae3e846
UD
130
131/* Set up the loaded object described by L so its unrelocated PLT
132 entries will jump to the on-demand fixup code in dl-runtime.c. */
133
134static inline int
3996f34b 135elf_machine_runtime_setup (struct link_map *l, int lazy, int profile)
5ae3e846 136{
5ae3e846
UD
137 if (l->l_info[DT_JMPREL] && lazy)
138 {
9c4c0024
UD
139 extern void _dl_runtime_resolve_0 (void);
140 extern void _dl_runtime_resolve_1 (void);
141 extern void _dl_runtime_profile_0 (void);
142 extern void _dl_runtime_profile_1 (void);
143 Elf64_Addr res0_addr, res1_addr;
b86120ed 144 unsigned int *plt = (void *) D_PTR (l, l_info[DT_PLTGOT]);
9c4c0024 145
404a4e2f 146 if (__builtin_expect(profile, 0))
0ecb606c 147 {
a334319f
UD
148 res0_addr = (Elf64_Addr) &_dl_runtime_profile_0;
149 res1_addr = (Elf64_Addr) &_dl_runtime_profile_1;
404a4e2f
RM
150
151 if (GLRO(dl_profile) != NULL
152 && _dl_name_match_p (GLRO(dl_profile), l))
a334319f 153 GL(dl_profile_map) = l;
0ecb606c 154 }
404a4e2f
RM
155 else
156 {
157 res0_addr = (Elf64_Addr) &_dl_runtime_resolve_0;
158 res1_addr = (Elf64_Addr) &_dl_runtime_resolve_1;
159 }
9c4c0024
UD
160
161 /* PLT0 looks like:
162
d063d164 163 sethi %uhi(_dl_runtime_{resolve,profile}_0), %g4
404a4e2f
RM
164 sethi %hi(_dl_runtime_{resolve,profile}_0), %g5
165 or %g4, %ulo(_dl_runtime_{resolve,profile}_0), %g4
166 or %g5, %lo(_dl_runtime_{resolve,profile}_0), %g5
167 sllx %g4, 32, %g4
168 add %g4, %g5, %g5
169 jmpl %g5, %g4
170 nop
8cb079d4 171 */
9c4c0024 172
404a4e2f
RM
173 plt[0] = 0x09000000 | (res0_addr >> (64 - 22));
174 plt[1] = 0x0b000000 | ((res0_addr >> 10) & 0x003fffff);
175 plt[2] = 0x88112000 | ((res0_addr >> 32) & 0x3ff);
176 plt[3] = 0x8a116000 | (res0_addr & 0x3ff);
177 plt[4] = 0x89293020;
178 plt[5] = 0x8a010005;
179 plt[6] = 0x89c14000;
180 plt[7] = 0x01000000;
8cb079d4
UD
181
182 /* PLT1 looks like:
183
d063d164 184 sethi %uhi(_dl_runtime_{resolve,profile}_1), %g4
404a4e2f
RM
185 sethi %hi(_dl_runtime_{resolve,profile}_1), %g5
186 or %g4, %ulo(_dl_runtime_{resolve,profile}_1), %g4
187 or %g5, %lo(_dl_runtime_{resolve,profile}_1), %g5
188 sllx %g4, 32, %g4
189 add %g4, %g5, %g5
190 jmpl %g5, %g4
191 nop
8cb079d4 192 */
9c4c0024 193
404a4e2f
RM
194 plt[8] = 0x09000000 | (res1_addr >> (64 - 22));
195 plt[9] = 0x0b000000 | ((res1_addr >> 10) & 0x003fffff);
196 plt[10] = 0x88112000 | ((res1_addr >> 32) & 0x3ff);
197 plt[11] = 0x8a116000 | (res1_addr & 0x3ff);
198 plt[12] = 0x89293020;
199 plt[13] = 0x8a010005;
200 plt[14] = 0x89c14000;
201 plt[15] = 0x01000000;
9c4c0024 202
4c4b9518
UD
203 /* Now put the magic cookie at the beginning of .PLT2
204 Entry .PLT3 is unused by this implementation. */
404a4e2f 205 *((struct link_map **)(&plt[16])) = l;
32e6df36
UD
206
207 if (__builtin_expect (l->l_info[VALIDX(DT_GNU_PRELINKED)] != NULL, 0)
208 || __builtin_expect (l->l_info [VALIDX (DT_GNU_LIBLISTSZ)] != NULL, 0))
209 {
210 /* Need to reinitialize .plt to undo prelinking. */
211 Elf64_Rela *rela = (Elf64_Rela *) D_PTR (l, l_info[DT_JMPREL]);
212 Elf64_Rela *relaend
213 = (Elf64_Rela *) ((char *) rela
214 + l->l_info[DT_PLTRELSZ]->d_un.d_val);
215
216 /* prelink must ensure there are no R_SPARC_NONE relocs left
217 in .rela.plt. */
218 while (rela < relaend)
219 {
220 if (__builtin_expect (rela->r_addend, 0) != 0)
221 {
1d204bf2 222 Elf64_Addr slot = ((rela->r_offset + l->l_addr + 0x400
32e6df36
UD
223 - (Elf64_Addr) plt)
224 / 0x1400) * 0x1400
225 + (Elf64_Addr) plt - 0x400;
226 /* ldx [%o7 + X], %g1 */
227 unsigned int first_ldx = *(unsigned int *)(slot + 12);
228 Elf64_Addr ptr = slot + (first_ldx & 0xfff) + 4;
229
1d204bf2 230 *(Elf64_Addr *) (rela->r_offset + l->l_addr)
32e6df36 231 = (Elf64_Addr) plt
1d204bf2
JM
232 - (slot + ((rela->r_offset + l->l_addr - ptr) / 8) * 24
233 + 4);
32e6df36
UD
234 ++rela;
235 continue;
236 }
237
1d204bf2
JM
238 *(unsigned int *) (rela->r_offset + l->l_addr)
239 = 0x03000000 | (rela->r_offset + l->l_addr - (Elf64_Addr) plt);
240 *(unsigned int *) (rela->r_offset + l->l_addr + 4)
241 = 0x30680000 | ((((Elf64_Addr) plt + 32 - rela->r_offset
242 - l->l_addr - 4) >> 2) & 0x7ffff);
243 __asm __volatile ("flush %0" : : "r" (rela->r_offset
244 + l->l_addr));
245 __asm __volatile ("flush %0+4" : : "r" (rela->r_offset
246 + l->l_addr));
32e6df36
UD
247 ++rela;
248 }
249 }
5ae3e846
UD
250 }
251
252 return lazy;
253}
254
5ae3e846
UD
255/* The PLT uses Elf64_Rela relocs. */
256#define elf_machine_relplt elf_machine_rela
257
97716954 258/* Undo the sub %sp, 6*8, %sp; add %sp, STACK_BIAS + 22*8, %o0 below
2c0b250a 259 (but w/o STACK_BIAS) to get at the value we want in __libc_stack_end. */
97716954 260#define DL_STACK_END(cookie) \
2c0b250a 261 ((void *) (((long) (cookie)) - (22 - 6) * 8))
97716954 262
5ae3e846
UD
263/* Initial entry point code for the dynamic linker.
264 The C function `_dl_start' is the real entry point;
265 its return value is the user program's entry point. */
266
3d2b3019
DM
267#define RTLD_GOT_ADDRESS(pic_reg, reg, symbol) \
268 "sethi %gdop_hix22(" #symbol "), " #reg "\n\t" \
269 "xor " #reg ", %gdop_lox10(" #symbol "), " #reg "\n\t" \
270 "ldx [" #pic_reg " + " #reg "], " #reg ", %gdop(" #symbol ")\n"
3d2b3019 271
5ae3e846
UD
272#define __S1(x) #x
273#define __S(x) __S1(x)
274
ba77ce24
AJ
275#define RTLD_START __asm__ ( "\n" \
276" .text\n" \
277" .global _start\n" \
278" .type _start, @function\n" \
279" .align 32\n" \
280"_start:\n" \
281" /* Make room for functions to drop their arguments on the stack. */\n" \
282" sub %sp, 6*8, %sp\n" \
283" /* Pass pointer to argument block to _dl_start. */\n" \
284" call _dl_start\n" \
285" add %sp," __S(STACK_BIAS) "+22*8,%o0\n" \
286" /* FALLTHRU */\n" \
287" .size _start, .-_start\n" \
288"\n" \
289" .global _dl_start_user\n" \
290" .type _dl_start_user, @function\n" \
291"_dl_start_user:\n" \
292" /* Load the GOT register. */\n" \
293"1: call 11f\n" \
294" sethi %hi(_GLOBAL_OFFSET_TABLE_-(1b-.)), %l7\n" \
295"11: or %l7, %lo(_GLOBAL_OFFSET_TABLE_-(1b-.)), %l7\n" \
ba77ce24 296" add %l7, %o7, %l7\n" \
ba77ce24
AJ
297" /* Save the user entry point address in %l0. */\n" \
298" mov %o0, %l0\n" \
ba77ce24
AJ
299" /* See if we were run as a command with the executable file name as an\n" \
300" extra leading argument. If so, we must shift things around since we\n" \
301" must keep the stack doubleword aligned. */\n" \
3d2b3019
DM
302 RTLD_GOT_ADDRESS(%l7, %g5, _dl_skip_args) \
303" ld [%g5], %i0\n" \
ba77ce24
AJ
304" brz,pt %i0, 2f\n" \
305" ldx [%sp + " __S(STACK_BIAS) " + 22*8], %i5\n" \
306" /* Find out how far to shift. */\n" \
ba77ce24 307" sub %i5, %i0, %i5\n" \
ba77ce24 308" sllx %i0, 3, %l6\n" \
3d2b3019 309 RTLD_GOT_ADDRESS(%l7, %l4, _dl_argv) \
ba77ce24
AJ
310" stx %i5, [%sp + " __S(STACK_BIAS) " + 22*8]\n" \
311" add %sp, " __S(STACK_BIAS) " + 23*8, %i1\n" \
312" add %i1, %l6, %i2\n" \
313" ldx [%l4], %l5\n" \
314" /* Copy down argv. */\n" \
315"12: ldx [%i2], %i3\n" \
316" add %i2, 8, %i2\n" \
317" stx %i3, [%i1]\n" \
318" brnz,pt %i3, 12b\n" \
319" add %i1, 8, %i1\n" \
320" sub %l5, %l6, %l5\n" \
321" /* Copy down envp. */\n" \
322"13: ldx [%i2], %i3\n" \
323" add %i2, 8, %i2\n" \
324" stx %i3, [%i1]\n" \
325" brnz,pt %i3, 13b\n" \
326" add %i1, 8, %i1\n" \
327" /* Copy down auxiliary table. */\n" \
328"14: ldx [%i2], %i3\n" \
329" ldx [%i2 + 8], %i4\n" \
330" add %i2, 16, %i2\n" \
331" stx %i3, [%i1]\n" \
332" stx %i4, [%i1 + 8]\n" \
333" brnz,pt %i3, 14b\n" \
334" add %i1, 16, %i1\n" \
335" stx %l5, [%l4]\n" \
336" /* %o0 = _dl_loaded, %o1 = argc, %o2 = argv, %o3 = envp. */\n" \
3d2b3019 337"2:\t" RTLD_GOT_ADDRESS(%l7, %o0, _rtld_local) \
ba77ce24 338" sllx %i5, 3, %o3\n" \
3d2b3019 339" add %sp, " __S(STACK_BIAS) " + 23*8, %o2\n" \
ba77ce24
AJ
340" add %o3, 8, %o3\n" \
341" mov %i5, %o1\n" \
342" add %o2, %o3, %o3\n" \
7969407a 343" call _dl_init_internal\n" \
ba77ce24
AJ
344" ldx [%o0], %o0\n" \
345" /* Pass our finalizer function to the user in %g1. */\n" \
3d2b3019 346 RTLD_GOT_ADDRESS(%l7, %g1, _dl_fini) \
ba77ce24
AJ
347" /* Jump to the user's entry point and deallocate the extra stack we got. */\n" \
348" jmp %l0\n" \
349" add %sp, 6*8, %sp\n" \
350" .size _dl_start_user, . - _dl_start_user\n" \
351" .previous\n");
edac0e8f
UD
352
353#endif /* dl_machine_h */
354
355#define ARCH_LA_PLTENTER sparc64_gnu_pltenter
356#define ARCH_LA_PLTEXIT sparc64_gnu_pltexit
357
358#ifdef RESOLVE_MAP
359
360/* Perform the relocation specified by RELOC and SYM (which is fully resolved).
361 MAP is the object containing the reloc. */
362
363auto inline void
364__attribute__ ((always_inline))
365elf_machine_rela (struct link_map *map, const Elf64_Rela *reloc,
366 const Elf64_Sym *sym, const struct r_found_version *version,
3a62d00d 367 void *const reloc_addr_arg, int skip_ifunc)
edac0e8f
UD
368{
369 Elf64_Addr *const reloc_addr = reloc_addr_arg;
370#if !defined RTLD_BOOTSTRAP && !defined RESOLVE_CONFLICT_FIND_MAP
371 const Elf64_Sym *const refsym = sym;
372#endif
373 Elf64_Addr value;
374 const unsigned long int r_type = ELF64_R_TYPE_ID (reloc->r_info);
375#if !defined RESOLVE_CONFLICT_FIND_MAP
376 struct link_map *sym_map = NULL;
377#endif
378
379#if !defined RTLD_BOOTSTRAP && !defined HAVE_Z_COMBRELOC
380 /* This is defined in rtld.c, but nowhere in the static libc.a; make the
381 reference weak so static programs can still link. This declaration
382 cannot be done when compiling rtld.c (i.e. #ifdef RTLD_BOOTSTRAP)
383 because rtld.c contains the common defn for _dl_rtld_map, which is
384 incompatible with a weak decl in the same file. */
385 weak_extern (_dl_rtld_map);
386#endif
387
388 if (__builtin_expect (r_type == R_SPARC_NONE, 0))
389 return;
390
391#if !defined RTLD_BOOTSTRAP || !defined HAVE_Z_COMBRELOC
392 if (__builtin_expect (r_type == R_SPARC_RELATIVE, 0))
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 {
406 value = map->l_addr;
407 }
408 else
409 {
410 sym_map = RESOLVE_MAP (&sym, version, r_type);
411 value = sym_map == NULL ? 0 : sym_map->l_addr + sym->st_value;
412 }
413#else
414 value = 0;
415#endif
416
417 value += reloc->r_addend; /* Assume copy relocs have zero addend. */
418
311927f1
DM
419 if (sym != NULL
420 && __builtin_expect (ELFW(ST_TYPE) (sym->st_info) == STT_GNU_IFUNC, 0)
3a62d00d
AS
421 && __builtin_expect (sym->st_shndx != SHN_UNDEF, 1)
422 && __builtin_expect (!skip_ifunc, 1))
9b849836 423 value = ((Elf64_Addr (*) (int)) value) (GLRO(dl_hwcap));
311927f1 424
edac0e8f
UD
425 switch (r_type)
426 {
427#if !defined RTLD_BOOTSTRAP && !defined RESOLVE_CONFLICT_FIND_MAP
428 case R_SPARC_COPY:
429 if (sym == NULL)
430 /* This can happen in trace mode if an object could not be
431 found. */
432 break;
433 if (sym->st_size > refsym->st_size
434 || (GLRO(dl_verbose) && sym->st_size < refsym->st_size))
435 {
436 const char *strtab;
437
438 strtab = (const void *) D_PTR (map, l_info[DT_STRTAB]);
439 _dl_error_printf ("\
440%s: Symbol `%s' has different size in shared object, consider re-linking\n",
441 rtld_progname ?: "<program name unknown>",
442 strtab + refsym->st_name);
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));
311927f1 458 /* Fall thru */
edac0e8f
UD
459 case R_SPARC_JMP_SLOT:
460#ifdef RESOLVE_CONFLICT_FIND_MAP
461 /* R_SPARC_JMP_SLOT conflicts against .plt[32768+]
462 relocs should be turned into R_SPARC_64 relocs
463 in .gnu.conflict section.
464 r_addend non-zero does not mean it is a .plt[32768+]
465 reloc, instead it is the actual address of the function
466 to call. */
467 sparc64_fixup_plt (NULL, reloc, reloc_addr, value, 0, 0);
468#else
469 sparc64_fixup_plt (map, reloc, reloc_addr, value, reloc->r_addend, 0);
470#endif
471 break;
d063d164 472#ifndef RESOLVE_CONFLICT_FIND_MAP
edac0e8f
UD
473 case R_SPARC_TLS_DTPMOD64:
474 /* Get the information from the link map returned by the
475 resolv function. */
476 if (sym_map != NULL)
477 *reloc_addr = sym_map->l_tls_modid;
478 break;
479 case R_SPARC_TLS_DTPOFF64:
480 /* During relocation all TLS symbols are defined and used.
481 Therefore the offset is already correct. */
482 *reloc_addr = (sym == NULL ? 0 : sym->st_value) + reloc->r_addend;
483 break;
484 case R_SPARC_TLS_TPOFF64:
485 /* The offset is negative, forward from the thread pointer. */
486 /* We know the offset of object the symbol is contained in.
487 It is a negative value which will be added to the
488 thread pointer. */
489 if (sym != NULL)
490 {
491 CHECK_STATIC_TLS (map, sym_map);
492 *reloc_addr = sym->st_value - sym_map->l_tls_offset
493 + reloc->r_addend;
494 }
495 break;
496# ifndef RTLD_BOOTSTRAP
497 case R_SPARC_TLS_LE_HIX22:
498 case R_SPARC_TLS_LE_LOX10:
499 if (sym != NULL)
500 {
501 CHECK_STATIC_TLS (map, sym_map);
502 value = sym->st_value - sym_map->l_tls_offset
503 + reloc->r_addend;
504 if (r_type == R_SPARC_TLS_LE_HIX22)
d6d1c4c8
DM
505 *(unsigned int *)reloc_addr =
506 ((*(unsigned int *)reloc_addr & 0xffc00000)
507 | (((~value) >> 10) & 0x3fffff));
edac0e8f 508 else
d6d1c4c8
DM
509 *(unsigned int *)reloc_addr =
510 ((*(unsigned int *)reloc_addr & 0xffffe000) | (value & 0x3ff)
511 | 0x1c00);
edac0e8f
UD
512 }
513 break;
514# endif
515#endif
516#ifndef RTLD_BOOTSTRAP
517 case R_SPARC_8:
518 *(char *) reloc_addr = value;
519 break;
520 case R_SPARC_16:
521 *(short *) reloc_addr = value;
522 break;
523 case R_SPARC_32:
524 *(unsigned int *) reloc_addr = value;
525 break;
526 case R_SPARC_DISP8:
527 *(char *) reloc_addr = (value - (Elf64_Addr) reloc_addr);
528 break;
529 case R_SPARC_DISP16:
530 *(short *) reloc_addr = (value - (Elf64_Addr) reloc_addr);
531 break;
532 case R_SPARC_DISP32:
533 *(unsigned int *) reloc_addr = (value - (Elf64_Addr) reloc_addr);
534 break;
535 case R_SPARC_WDISP30:
536 *(unsigned int *) reloc_addr =
537 ((*(unsigned int *)reloc_addr & 0xc0000000) |
2b6a801e 538 (((value - (Elf64_Addr) reloc_addr) >> 2) & 0x3fffffff));
edac0e8f
UD
539 break;
540
541 /* MEDLOW code model relocs */
542 case R_SPARC_LO10:
543 *(unsigned int *) reloc_addr =
544 ((*(unsigned int *)reloc_addr & ~0x3ff) |
545 (value & 0x3ff));
546 break;
547 case R_SPARC_HI22:
548 *(unsigned int *) reloc_addr =
549 ((*(unsigned int *)reloc_addr & 0xffc00000) |
2b6a801e 550 ((value >> 10) & 0x3fffff));
edac0e8f
UD
551 break;
552 case R_SPARC_OLO10:
553 *(unsigned int *) reloc_addr =
554 ((*(unsigned int *)reloc_addr & ~0x1fff) |
555 (((value & 0x3ff) + ELF64_R_TYPE_DATA (reloc->r_info)) & 0x1fff));
556 break;
557
558 /* MEDMID code model relocs */
559 case R_SPARC_H44:
560 *(unsigned int *) reloc_addr =
561 ((*(unsigned int *)reloc_addr & 0xffc00000) |
2b6a801e 562 ((value >> 22) & 0x3fffff));
edac0e8f
UD
563 break;
564 case R_SPARC_M44:
565 *(unsigned int *) reloc_addr =
566 ((*(unsigned int *)reloc_addr & ~0x3ff) |
567 ((value >> 12) & 0x3ff));
568 break;
569 case R_SPARC_L44:
570 *(unsigned int *) reloc_addr =
571 ((*(unsigned int *)reloc_addr & ~0xfff) |
572 (value & 0xfff));
573 break;
574
575 /* MEDANY code model relocs */
576 case R_SPARC_HH22:
577 *(unsigned int *) reloc_addr =
578 ((*(unsigned int *)reloc_addr & 0xffc00000) |
579 (value >> 42));
580 break;
581 case R_SPARC_HM10:
582 *(unsigned int *) reloc_addr =
583 ((*(unsigned int *)reloc_addr & ~0x3ff) |
584 ((value >> 32) & 0x3ff));
585 break;
586 case R_SPARC_LM22:
587 *(unsigned int *) reloc_addr =
588 ((*(unsigned int *)reloc_addr & 0xffc00000) |
589 ((value >> 10) & 0x003fffff));
590 break;
591 case R_SPARC_UA16:
592 ((unsigned char *) reloc_addr_arg) [0] = value >> 8;
593 ((unsigned char *) reloc_addr_arg) [1] = value;
594 break;
595 case R_SPARC_UA32:
596 ((unsigned char *) reloc_addr_arg) [0] = value >> 24;
597 ((unsigned char *) reloc_addr_arg) [1] = value >> 16;
598 ((unsigned char *) reloc_addr_arg) [2] = value >> 8;
599 ((unsigned char *) reloc_addr_arg) [3] = value;
600 break;
601 case R_SPARC_UA64:
602 if (! ((long) reloc_addr_arg & 3))
603 {
604 /* Common in .eh_frame */
605 ((unsigned int *) reloc_addr_arg) [0] = value >> 32;
606 ((unsigned int *) reloc_addr_arg) [1] = value;
607 break;
608 }
609 ((unsigned char *) reloc_addr_arg) [0] = value >> 56;
610 ((unsigned char *) reloc_addr_arg) [1] = value >> 48;
611 ((unsigned char *) reloc_addr_arg) [2] = value >> 40;
612 ((unsigned char *) reloc_addr_arg) [3] = value >> 32;
613 ((unsigned char *) reloc_addr_arg) [4] = value >> 24;
614 ((unsigned char *) reloc_addr_arg) [5] = value >> 16;
615 ((unsigned char *) reloc_addr_arg) [6] = value >> 8;
616 ((unsigned char *) reloc_addr_arg) [7] = value;
617 break;
618#endif
619#if !defined RTLD_BOOTSTRAP || defined _NDEBUG
620 default:
621 _dl_reloc_bad_type (map, r_type, 0);
622 break;
623#endif
624 }
625}
626
627auto inline void
628__attribute__ ((always_inline))
629elf_machine_rela_relative (Elf64_Addr l_addr, const Elf64_Rela *reloc,
630 void *const reloc_addr_arg)
631{
632 Elf64_Addr *const reloc_addr = reloc_addr_arg;
633 *reloc_addr = l_addr + reloc->r_addend;
634}
635
636auto inline void
637__attribute__ ((always_inline))
638elf_machine_lazy_rel (struct link_map *map,
3a62d00d
AS
639 Elf64_Addr l_addr, const Elf64_Rela *reloc,
640 int skip_ifunc)
edac0e8f 641{
311927f1
DM
642 Elf64_Addr *const reloc_addr = (void *) (l_addr + reloc->r_offset);
643 const unsigned int r_type = ELF64_R_TYPE (reloc->r_info);
644
645 if (__builtin_expect (r_type == R_SPARC_JMP_SLOT, 1))
646 ;
647 else if (r_type == R_SPARC_JMP_IREL
648 || r_type == R_SPARC_IRELATIVE)
edac0e8f 649 {
311927f1 650 Elf64_Addr value = map->l_addr + reloc->r_addend;
3a62d00d
AS
651 if (__builtin_expect (!skip_ifunc, 1))
652 value = ((Elf64_Addr (*) (int)) value) (GLRO(dl_hwcap));
311927f1
DM
653 if (r_type == R_SPARC_JMP_IREL)
654 {
655 /* 'high' is always zero, for large PLT entries the linker
656 emits an R_SPARC_IRELATIVE. */
7ec1221f 657 sparc64_fixup_plt (map, reloc, reloc_addr, value, 0, 1);
311927f1
DM
658 }
659 else
660 *reloc_addr = value;
edac0e8f 661 }
311927f1
DM
662 else if (r_type == R_SPARC_NONE)
663 ;
664 else
665 _dl_reloc_bad_type (map, r_type, 1);
edac0e8f
UD
666}
667
668#endif /* RESOLVE_MAP */