]> git.ipfire.org Git - thirdparty/glibc.git/blame - sysdeps/x86_64/dl-machine.h
Update copyright dates with scripts/update-copyrights.
[thirdparty/glibc.git] / sysdeps / x86_64 / dl-machine.h
CommitLineData
c9cf6dde 1/* Machine-dependent ELF dynamic relocation inline functions. x86-64 version.
04277e02 2 Copyright (C) 2001-2019 Free Software Foundation, Inc.
c9cf6dde
AJ
3 This file is part of the GNU C Library.
4 Contributed by Andreas Jaeger <aj@suse.de>.
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
59ba27a6
PE
17 License along with the GNU C Library; if not, see
18 <http://www.gnu.org/licenses/>. */
c9cf6dde
AJ
19
20#ifndef dl_machine_h
21#define dl_machine_h
22
23#define ELF_MACHINE_NAME "x86_64"
24
25#include <sys/param.h>
2b1c0eea 26#include <sysdep.h>
b177ed2b 27#include <tls.h>
c9ff0187 28#include <dl-tlsdesc.h>
e2e4f560 29#include <cpu-features.c>
c9cf6dde
AJ
30
31/* Return nonzero iff ELF header is compatible with the running host. */
32static inline int __attribute__ ((unused))
4b30f61a 33elf_machine_matches_host (const ElfW(Ehdr) *ehdr)
c9cf6dde
AJ
34{
35 return ehdr->e_machine == EM_X86_64;
36}
37
38
39/* Return the link-time address of _DYNAMIC. Conveniently, this is the
40 first element of the GOT. This must be inlined in a function which
41 uses global data. */
4b30f61a 42static inline ElfW(Addr) __attribute__ ((unused))
c9cf6dde
AJ
43elf_machine_dynamic (void)
44{
5f30cfec
L
45 /* This produces an IP-relative reloc which is resolved at link time. */
46 extern const ElfW(Addr) _GLOBAL_OFFSET_TABLE_[] attribute_hidden;
47 return _GLOBAL_OFFSET_TABLE_[0];
c9cf6dde
AJ
48}
49
50
51/* Return the run-time load address of the shared object. */
4b30f61a 52static inline ElfW(Addr) __attribute__ ((unused))
c9cf6dde
AJ
53elf_machine_load_address (void)
54{
5f30cfec
L
55 /* Compute the difference between the runtime address of _DYNAMIC as seen
56 by an IP-relative reference, and the link-time address found in the
57 special unrelocated first GOT entry. */
02d2d892
L
58 extern ElfW(Dyn) _DYNAMIC[] attribute_hidden;
59 return (ElfW(Addr)) &_DYNAMIC - elf_machine_dynamic ();
c9cf6dde
AJ
60}
61
62/* Set up the loaded object described by L so its unrelocated PLT
63 entries will jump to the on-demand fixup code in dl-runtime.c. */
64
50441a98 65static inline int __attribute__ ((unused, always_inline))
c9cf6dde
AJ
66elf_machine_runtime_setup (struct link_map *l, int lazy, int profile)
67{
68 Elf64_Addr *got;
b52b0d79
L
69 extern void _dl_runtime_resolve_fxsave (ElfW(Word)) attribute_hidden;
70 extern void _dl_runtime_resolve_xsave (ElfW(Word)) attribute_hidden;
71 extern void _dl_runtime_resolve_xsavec (ElfW(Word)) attribute_hidden;
f3dcae82
L
72 extern void _dl_runtime_profile_sse (ElfW(Word)) attribute_hidden;
73 extern void _dl_runtime_profile_avx (ElfW(Word)) attribute_hidden;
74 extern void _dl_runtime_profile_avx512 (ElfW(Word)) attribute_hidden;
c9cf6dde
AJ
75
76 if (l->l_info[DT_JMPREL] && lazy)
77 {
78 /* The GOT entries for functions in the PLT have not yet been filled
79 in. Their initial contents will arrange when called to push an
80 offset into the .rel.plt section, push _GLOBAL_OFFSET_TABLE_[1],
530a3249 81 and then jump to _GLOBAL_OFFSET_TABLE_[2]. */
c9cf6dde 82 got = (Elf64_Addr *) D_PTR (l, l_info[DT_PLTGOT]);
32e6df36
UD
83 /* If a library is prelinked but we have to relocate anyway,
84 we have to be able to undo the prelinking of .got.plt.
85 The prelinker saved us here address of .plt + 0x16. */
86 if (got[1])
87 {
88 l->l_mach.plt = got[1] + l->l_addr;
4b30f61a 89 l->l_mach.gotplt = (ElfW(Addr)) &got[3];
32e6df36 90 }
4b30f61a
L
91 /* Identify this shared object. */
92 *(ElfW(Addr) *) (got + 1) = (ElfW(Addr)) l;
c9cf6dde
AJ
93
94 /* The got[2] entry contains the address of a function which gets
95 called to get the address of a so far unresolved function and
96 jump to it. The profiling extension of the dynamic linker allows
97 to intercept the calls to collect information. In this case we
98 don't store the address in the GOT so that all future calls also
99 end in this function. */
a1ffb40e 100 if (__glibc_unlikely (profile))
c9cf6dde 101 {
f3dcae82
L
102 if (HAS_ARCH_FEATURE (AVX512F_Usable))
103 *(ElfW(Addr) *) (got + 2) = (ElfW(Addr)) &_dl_runtime_profile_avx512;
104 else if (HAS_ARCH_FEATURE (AVX_Usable))
105 *(ElfW(Addr) *) (got + 2) = (ElfW(Addr)) &_dl_runtime_profile_avx;
106 else
107 *(ElfW(Addr) *) (got + 2) = (ElfW(Addr)) &_dl_runtime_profile_sse;
c9cf6dde 108
9dcafc55
UD
109 if (GLRO(dl_profile) != NULL
110 && _dl_name_match_p (GLRO(dl_profile), l))
c9cf6dde
AJ
111 /* This is the object we are looking for. Say that we really
112 want profiling and the timers are started. */
5688da55 113 GL(dl_profile_map) = l;
c9cf6dde
AJ
114 }
115 else
f3dcae82
L
116 {
117 /* This function will get called to fix up the GOT entry
118 indicated by the offset on the stack, and then jump to
119 the resolved address. */
b52b0d79
L
120 if (GLRO(dl_x86_cpu_features).xsave_state_size != 0)
121 *(ElfW(Addr) *) (got + 2)
122 = (HAS_ARCH_FEATURE (XSAVEC_Usable)
123 ? (ElfW(Addr)) &_dl_runtime_resolve_xsavec
124 : (ElfW(Addr)) &_dl_runtime_resolve_xsave);
f3dcae82 125 else
b52b0d79
L
126 *(ElfW(Addr) *) (got + 2)
127 = (ElfW(Addr)) &_dl_runtime_resolve_fxsave;
f3dcae82 128 }
c9cf6dde
AJ
129 }
130
c9ff0187 131 if (l->l_info[ADDRIDX (DT_TLSDESC_GOT)] && lazy)
4b30f61a
L
132 *(ElfW(Addr)*)(D_PTR (l, l_info[ADDRIDX (DT_TLSDESC_GOT)]) + l->l_addr)
133 = (ElfW(Addr)) &_dl_tlsdesc_resolve_rela;
c9ff0187 134
c9cf6dde
AJ
135 return lazy;
136}
137
c9cf6dde
AJ
138/* Initial entry point code for the dynamic linker.
139 The C function `_dl_start' is the real entry point;
140 its return value is the user program's entry point. */
141#define RTLD_START asm ("\n\
142.text\n\
143 .align 16\n\
144.globl _start\n\
145.globl _dl_start_user\n\
146_start:\n\
147 movq %rsp, %rdi\n\
148 call _dl_start\n\
149_dl_start_user:\n\
150 # Save the user entry point address in %r12.\n\
151 movq %rax, %r12\n\
c9cf6dde
AJ
152 # See if we were run as a command with the executable file\n\
153 # name as an extra leading argument.\n\
217ed70e 154 movl _dl_skip_args(%rip), %eax\n\
c9cf6dde
AJ
155 # Pop the original argument count.\n\
156 popq %rdx\n\
157 # Adjust the stack pointer to skip _dl_skip_args words.\n\
158 leaq (%rsp,%rax,8), %rsp\n\
159 # Subtract _dl_skip_args from argc.\n\
160 subl %eax, %edx\n\
161 # Push argc back on the stack.\n\
162 pushq %rdx\n\
163 # Call _dl_init (struct link_map *main_map, int argc, char **argv, char **env)\n\
164 # argc -> rsi\n\
165 movq %rdx, %rsi\n\
be184b1d
UD
166 # Save %rsp value in %r13.\n\
167 movq %rsp, %r13\n\
c5684fdb 168 # And align stack for the _dl_init call. \n\
be184b1d 169 andq $-16, %rsp\n\
c9cf6dde 170 # _dl_loaded -> rdi\n\
217ed70e 171 movq _rtld_local(%rip), %rdi\n\
c9cf6dde 172 # env -> rcx\n\
be184b1d 173 leaq 16(%r13,%rdx,8), %rcx\n\
c9cf6dde 174 # argv -> rdx\n\
be184b1d
UD
175 leaq 8(%r13), %rdx\n\
176 # Clear %rbp to mark outermost frame obviously even for constructors.\n\
ee618985 177 xorl %ebp, %ebp\n\
c9cf6dde 178 # Call the function to run the initializers.\n\
7432d613 179 call _dl_init\n\
c9cf6dde 180 # Pass our finalizer function to the user in %rdx, as per ELF ABI.\n\
217ed70e 181 leaq _dl_fini(%rip), %rdx\n\
be184b1d
UD
182 # And make sure %rsp points to argc stored on the stack.\n\
183 movq %r13, %rsp\n\
c9cf6dde
AJ
184 # Jump to the user's entry point.\n\
185 jmp *%r12\n\
186.previous\n\
187");
188
8323008c
RM
189/* ELF_RTYPE_CLASS_PLT iff TYPE describes relocation of a PLT entry or
190 TLS variable, so undefined references should not be allowed to
191 define the value.
209826bc 192 ELF_RTYPE_CLASS_COPY iff TYPE should not be allowed to resolve to one
62da1e3b
L
193 of the main executable's symbols, as for a COPY reloc.
194 ELF_RTYPE_CLASS_EXTERN_PROTECTED_DATA iff TYPE describes relocation may
195 against protected data whose address be external due to copy relocation.
196 */
d063d164 197#define elf_machine_type_class(type) \
82c02215
RM
198 ((((type) == R_X86_64_JUMP_SLOT \
199 || (type) == R_X86_64_DTPMOD64 \
c9ff0187
UD
200 || (type) == R_X86_64_DTPOFF64 \
201 || (type) == R_X86_64_TPOFF64 \
202 || (type) == R_X86_64_TLSDESC) \
82c02215 203 * ELF_RTYPE_CLASS_PLT) \
62da1e3b
L
204 | (((type) == R_X86_64_COPY) * ELF_RTYPE_CLASS_COPY) \
205 | (((type) == R_X86_64_GLOB_DAT) * ELF_RTYPE_CLASS_EXTERN_PROTECTED_DATA))
c9cf6dde
AJ
206
207/* A reloc type used for ld.so cmdline arg lookups to reject PLT entries. */
208#define ELF_MACHINE_JMP_SLOT R_X86_64_JUMP_SLOT
209
ad0f5cad
UD
210/* The relative ifunc relocation. */
211// XXX This is a work-around for a broken linker. Remove!
212#define ELF_MACHINE_IRELATIVE R_X86_64_IRELATIVE
213
4b30f61a 214/* The x86-64 never uses Elf64_Rel/Elf32_Rel relocations. */
c9cf6dde 215#define ELF_MACHINE_NO_REL 1
4cf5b6d0 216#define ELF_MACHINE_NO_RELA 0
c9cf6dde 217
530a3249 218/* We define an initialization function. This is called very early in
c9cf6dde
AJ
219 _dl_sysdep_start. */
220#define DL_PLATFORM_INIT dl_platform_init ()
221
c9cf6dde
AJ
222static inline void __attribute__ ((unused))
223dl_platform_init (void)
224{
1432d38e 225#if IS_IN (rtld)
4facca0b
L
226 /* init_cpu_features has been called early from __libc_start_main in
227 static executable. */
e2e4f560 228 init_cpu_features (&GLRO(dl_x86_cpu_features));
1432d38e
L
229#else
230 if (GLRO(dl_platform) != NULL && *GLRO(dl_platform) == '\0')
231 /* Avoid an empty string which would disturb us. */
232 GLRO(dl_platform) = NULL;
4facca0b 233#endif
c9cf6dde
AJ
234}
235
4b30f61a 236static inline ElfW(Addr)
c9cf6dde 237elf_machine_fixup_plt (struct link_map *map, lookup_t t,
0572433b 238 const ElfW(Sym) *refsym, const ElfW(Sym) *sym,
4b30f61a
L
239 const ElfW(Rela) *reloc,
240 ElfW(Addr) *reloc_addr, ElfW(Addr) value)
c9cf6dde
AJ
241{
242 return *reloc_addr = value;
243}
244
530a3249
MP
245/* Return the final value of a PLT relocation. On x86-64 the
246 JUMP_SLOT relocation ignores the addend. */
4b30f61a
L
247static inline ElfW(Addr)
248elf_machine_plt_value (struct link_map *map, const ElfW(Rela) *reloc,
249 ElfW(Addr) value)
c9cf6dde
AJ
250{
251 return value;
252}
253
9dcafc55
UD
254
255/* Names of the architecture-specific auditing callback functions. */
256#define ARCH_LA_PLTENTER x86_64_gnu_pltenter
257#define ARCH_LA_PLTEXIT x86_64_gnu_pltexit
258
c9cf6dde
AJ
259#endif /* !dl_machine_h */
260
9dcafc55 261#ifdef RESOLVE_MAP
c9cf6dde
AJ
262
263/* Perform the relocation specified by RELOC and SYM (which is fully resolved).
264 MAP is the object containing the reloc. */
265
7090d3ca
AJ
266auto inline void
267__attribute__ ((always_inline))
4b30f61a
L
268elf_machine_rela (struct link_map *map, const ElfW(Rela) *reloc,
269 const ElfW(Sym) *sym, const struct r_found_version *version,
3a62d00d 270 void *const reloc_addr_arg, int skip_ifunc)
c9cf6dde 271{
4b30f61a
L
272 ElfW(Addr) *const reloc_addr = reloc_addr_arg;
273 const unsigned long int r_type = ELFW(R_TYPE) (reloc->r_info);
c9cf6dde 274
e7f110cd 275# if !defined RTLD_BOOTSTRAP || !defined HAVE_Z_COMBRELOC
a1ffb40e 276 if (__glibc_unlikely (r_type == R_X86_64_RELATIVE))
c9cf6dde 277 {
e7f110cd 278# if !defined RTLD_BOOTSTRAP && !defined HAVE_Z_COMBRELOC
c9cf6dde
AJ
279 /* This is defined in rtld.c, but nowhere in the static libc.a;
280 make the reference weak so static programs can still link.
281 This declaration cannot be done when compiling rtld.c
282 (i.e. #ifdef RTLD_BOOTSTRAP) because rtld.c contains the
283 common defn for _dl_rtld_map, which is incompatible with a
284 weak decl in the same file. */
e7f110cd 285# ifndef SHARED
5688da55 286 weak_extern (GL(dl_rtld_map));
e7f110cd 287# endif
5688da55 288 if (map != &GL(dl_rtld_map)) /* Already done in rtld itself. */
e7f110cd 289# endif
c9cf6dde
AJ
290 *reloc_addr = map->l_addr + reloc->r_addend;
291 }
292 else
df8a552f
L
293# endif
294# if !defined RTLD_BOOTSTRAP
295 /* l_addr + r_addend may be > 0xffffffff and R_X86_64_RELATIVE64
296 relocation updates the whole 64-bit entry. */
a1ffb40e 297 if (__glibc_unlikely (r_type == R_X86_64_RELATIVE64))
df8a552f
L
298 *(Elf64_Addr *) reloc_addr = (Elf64_Addr) map->l_addr + reloc->r_addend;
299 else
e7f110cd 300# endif
a1ffb40e 301 if (__glibc_unlikely (r_type == R_X86_64_NONE))
c9cf6dde
AJ
302 return;
303 else
304 {
e7f110cd 305# ifndef RTLD_BOOTSTRAP
4b30f61a 306 const ElfW(Sym) *const refsym = sym;
e7f110cd 307# endif
8323008c 308 struct link_map *sym_map = RESOLVE_MAP (&sym, version, r_type);
10a446dd 309 ElfW(Addr) value = SYMBOL_ADDRESS (sym_map, sym, true);
c9cf6dde 310
e7f110cd 311 if (sym != NULL
06fbebff
L
312 && __glibc_unlikely (ELFW(ST_TYPE) (sym->st_info) == STT_GNU_IFUNC)
313 && __glibc_likely (sym->st_shndx != SHN_UNDEF)
314 && __glibc_likely (!skip_ifunc))
0e6d3adc
L
315 {
316# ifndef RTLD_BOOTSTRAP
317 if (sym_map != map
318 && sym_map->l_type != lt_executable
319 && !sym_map->l_relocated)
320 {
321 const char *strtab
322 = (const char *) D_PTR (map, l_info[DT_STRTAB]);
6fab532b 323 _dl_error_printf ("\
0e6d3adc
L
324%s: Relink `%s' with `%s' for IFUNC symbol `%s'\n",
325 RTLD_PROGNAME, map->l_name,
326 sym_map->l_name,
327 strtab + refsym->st_name);
328 }
329# endif
330 value = ((ElfW(Addr) (*) (void)) value) ();
331 }
e7f110cd 332
c9cf6dde
AJ
333 switch (r_type)
334 {
22676eaf
L
335# ifndef RTLD_BOOTSTRAP
336# ifdef __ILP32__
337 case R_X86_64_SIZE64:
338 /* Set to symbol size plus addend. */
339 *(Elf64_Addr *) (uintptr_t) reloc_addr
340 = (Elf64_Addr) sym->st_size + reloc->r_addend;
341 break;
342
343 case R_X86_64_SIZE32:
344# else
345 case R_X86_64_SIZE64:
346# endif
347 /* Set to symbol size plus addend. */
348 value = sym->st_size;
349# endif
c9cf6dde
AJ
350 case R_X86_64_GLOB_DAT:
351 case R_X86_64_JUMP_SLOT:
352 *reloc_addr = value + reloc->r_addend;
353 break;
8323008c 354
e7f110cd 355# ifndef RESOLVE_CONFLICT_FIND_MAP
8323008c 356 case R_X86_64_DTPMOD64:
e7f110cd 357# ifdef RTLD_BOOTSTRAP
8323008c
RM
358 /* During startup the dynamic linker is always the module
359 with index 1.
360 XXX If this relocation is necessary move before RESOLVE
361 call. */
362 *reloc_addr = 1;
e7f110cd 363# else
8323008c
RM
364 /* Get the information from the link map returned by the
365 resolve function. */
366 if (sym_map != NULL)
367 *reloc_addr = sym_map->l_tls_modid;
e7f110cd 368# endif
8323008c
RM
369 break;
370 case R_X86_64_DTPOFF64:
e7f110cd 371# ifndef RTLD_BOOTSTRAP
8323008c
RM
372 /* During relocation all TLS symbols are defined and used.
373 Therefore the offset is already correct. */
374 if (sym != NULL)
c8c59454
L
375 {
376 value = sym->st_value + reloc->r_addend;
377# ifdef __ILP32__
378 /* This relocation type computes a signed offset that is
379 usually negative. The symbol and addend values are 32
380 bits but the GOT entry is 64 bits wide and the whole
381 64-bit entry is used as a signed quantity, so we need
382 to sign-extend the computed value to 64 bits. */
b5c086a2 383 *(Elf64_Sxword *) reloc_addr = (Elf64_Sxword) (Elf32_Sword) value;
c8c59454
L
384# else
385 *reloc_addr = value;
386# endif
387 }
e7f110cd 388# endif
8323008c 389 break;
c9ff0187
UD
390 case R_X86_64_TLSDESC:
391 {
392 struct tlsdesc volatile *td =
393 (struct tlsdesc volatile *)reloc_addr;
394
e7f110cd 395# ifndef RTLD_BOOTSTRAP
c9ff0187
UD
396 if (! sym)
397 {
398 td->arg = (void*)reloc->r_addend;
399 td->entry = _dl_tlsdesc_undefweak;
400 }
401 else
e7f110cd 402# endif
c9ff0187 403 {
e7f110cd
UD
404# ifndef RTLD_BOOTSTRAP
405# ifndef SHARED
c9ff0187 406 CHECK_STATIC_TLS (map, sym_map);
e7f110cd 407# else
c9ff0187
UD
408 if (!TRY_STATIC_TLS (map, sym_map))
409 {
410 td->arg = _dl_make_tlsdesc_dynamic
411 (sym_map, sym->st_value + reloc->r_addend);
412 td->entry = _dl_tlsdesc_dynamic;
413 }
414 else
e7f110cd 415# endif
c9ff0187 416# endif
c9ff0187
UD
417 {
418 td->arg = (void*)(sym->st_value - sym_map->l_tls_offset
419 + reloc->r_addend);
420 td->entry = _dl_tlsdesc_return;
421 }
422 }
423 break;
424 }
8323008c
RM
425 case R_X86_64_TPOFF64:
426 /* The offset is negative, forward from the thread pointer. */
e7f110cd 427# ifndef RTLD_BOOTSTRAP
8323008c 428 if (sym != NULL)
e7f110cd 429# endif
2430d57a 430 {
e7f110cd 431# ifndef RTLD_BOOTSTRAP
eb775e67 432 CHECK_STATIC_TLS (map, sym_map);
e7f110cd 433# endif
2430d57a
RM
434 /* We know the offset of the object the symbol is contained in.
435 It is a negative value which will be added to the
436 thread pointer. */
c8c59454
L
437 value = (sym->st_value + reloc->r_addend
438 - sym_map->l_tls_offset);
439# ifdef __ILP32__
440 /* The symbol and addend values are 32 bits but the GOT
441 entry is 64 bits wide and the whole 64-bit entry is used
442 as a signed quantity, so we need to sign-extend the
443 computed value to 64 bits. */
444 *(Elf64_Sxword *) reloc_addr = (Elf64_Sxword) (Elf32_Sword) value;
445# else
446 *reloc_addr = value;
447# endif
2430d57a 448 }
8323008c 449 break;
e7f110cd 450# endif
8323008c 451
e7f110cd 452# ifndef RTLD_BOOTSTRAP
c9cf6dde 453 case R_X86_64_64:
df8a552f
L
454 /* value + r_addend may be > 0xffffffff and R_X86_64_64
455 relocation updates the whole 64-bit entry. */
456 *(Elf64_Addr *) reloc_addr = (Elf64_Addr) value + reloc->r_addend;
c9cf6dde 457 break;
22676eaf
L
458# ifndef __ILP32__
459 case R_X86_64_SIZE32:
460 /* Set to symbol size plus addend. */
461 value = sym->st_size;
462# endif
c9cf6dde 463 case R_X86_64_32:
e7f110cd
UD
464 value += reloc->r_addend;
465 *(unsigned int *) reloc_addr = value;
466
467 const char *fmt;
a1ffb40e 468 if (__glibc_unlikely (value > UINT_MAX))
6c2b2a19
AJ
469 {
470 const char *strtab;
471
e7f110cd
UD
472 fmt = "\
473%s: Symbol `%s' causes overflow in R_X86_64_32 relocation\n";
6cc8844f 474# ifndef RESOLVE_CONFLICT_FIND_MAP
e7f110cd 475 print_err:
6cc8844f 476# endif
6c2b2a19
AJ
477 strtab = (const char *) D_PTR (map, l_info[DT_STRTAB]);
478
b9375348 479 _dl_error_printf (fmt, RTLD_PROGNAME, strtab + refsym->st_name);
6c2b2a19 480 }
c9cf6dde 481 break;
e7f110cd 482# ifndef RESOLVE_CONFLICT_FIND_MAP
8e27f45e 483 /* Not needed for dl-conflict.c. */
c9cf6dde 484 case R_X86_64_PC32:
4b30f61a 485 value += reloc->r_addend - (ElfW(Addr)) reloc_addr;
e7f110cd 486 *(unsigned int *) reloc_addr = value;
a1ffb40e 487 if (__glibc_unlikely (value != (int) value))
6c2b2a19 488 {
e7f110cd
UD
489 fmt = "\
490%s: Symbol `%s' causes overflow in R_X86_64_PC32 relocation\n";
491 goto print_err;
6c2b2a19 492 }
c9cf6dde
AJ
493 break;
494 case R_X86_64_COPY:
495 if (sym == NULL)
496 /* This can happen in trace mode if an object could not be
497 found. */
498 break;
e7f110cd
UD
499 memcpy (reloc_addr_arg, (void *) value,
500 MIN (sym->st_size, refsym->st_size));
06fbebff
L
501 if (__glibc_unlikely (sym->st_size > refsym->st_size)
502 || (__glibc_unlikely (sym->st_size < refsym->st_size)
afdca0f2 503 && GLRO(dl_verbose)))
c9cf6dde 504 {
e7f110cd
UD
505 fmt = "\
506%s: Symbol `%s' has different size in shared object, consider re-linking\n";
507 goto print_err;
c9cf6dde 508 }
c9cf6dde 509 break;
e7f110cd 510# endif
74414708
UD
511 case R_X86_64_IRELATIVE:
512 value = map->l_addr + reloc->r_addend;
4b30f61a 513 value = ((ElfW(Addr) (*) (void)) value) ();
74414708
UD
514 *reloc_addr = value;
515 break;
c9cf6dde
AJ
516 default:
517 _dl_reloc_bad_type (map, r_type, 0);
518 break;
e7f110cd 519# endif
c9cf6dde 520 }
c9cf6dde
AJ
521 }
522}
523
7090d3ca
AJ
524auto inline void
525__attribute ((always_inline))
4b30f61a 526elf_machine_rela_relative (ElfW(Addr) l_addr, const ElfW(Rela) *reloc,
87d254a7 527 void *const reloc_addr_arg)
c9cf6dde 528{
4b30f61a 529 ElfW(Addr) *const reloc_addr = reloc_addr_arg;
0a10fb9e 530#if !defined RTLD_BOOTSTRAP
df8a552f
L
531 /* l_addr + r_addend may be > 0xffffffff and R_X86_64_RELATIVE64
532 relocation updates the whole 64-bit entry. */
a1ffb40e 533 if (__glibc_unlikely (ELFW(R_TYPE) (reloc->r_info) == R_X86_64_RELATIVE64))
df8a552f
L
534 *(Elf64_Addr *) reloc_addr = (Elf64_Addr) l_addr + reloc->r_addend;
535 else
0a10fb9e 536#endif
df8a552f
L
537 {
538 assert (ELFW(R_TYPE) (reloc->r_info) == R_X86_64_RELATIVE);
539 *reloc_addr = l_addr + reloc->r_addend;
540 }
c9cf6dde
AJ
541}
542
7090d3ca
AJ
543auto inline void
544__attribute ((always_inline))
c9cf6dde 545elf_machine_lazy_rel (struct link_map *map,
4b30f61a 546 ElfW(Addr) l_addr, const ElfW(Rela) *reloc,
3a62d00d 547 int skip_ifunc)
c9cf6dde 548{
4b30f61a
L
549 ElfW(Addr) *const reloc_addr = (void *) (l_addr + reloc->r_offset);
550 const unsigned long int r_type = ELFW(R_TYPE) (reloc->r_info);
c9cf6dde
AJ
551
552 /* Check for unexpected PLT reloc type. */
a1ffb40e 553 if (__glibc_likely (r_type == R_X86_64_JUMP_SLOT))
32e6df36 554 {
06fbebff
L
555 /* Prelink has been deprecated. */
556 if (__glibc_likely (map->l_mach.plt == 0))
32e6df36
UD
557 *reloc_addr += l_addr;
558 else
559 *reloc_addr =
560 map->l_mach.plt
4b30f61a 561 + (((ElfW(Addr)) reloc_addr) - map->l_mach.gotplt) * 2;
32e6df36 562 }
a1ffb40e 563 else if (__glibc_likely (r_type == R_X86_64_TLSDESC))
c9ff0187
UD
564 {
565 struct tlsdesc volatile * __attribute__((__unused__)) td =
566 (struct tlsdesc volatile *)reloc_addr;
567
568 td->arg = (void*)reloc;
569 td->entry = (void*)(D_PTR (map, l_info[ADDRIDX (DT_TLSDESC_PLT)])
570 + map->l_addr);
571 }
a1ffb40e 572 else if (__glibc_unlikely (r_type == R_X86_64_IRELATIVE))
74414708 573 {
4b30f61a 574 ElfW(Addr) value = map->l_addr + reloc->r_addend;
a1ffb40e 575 if (__glibc_likely (!skip_ifunc))
4b30f61a 576 value = ((ElfW(Addr) (*) (void)) value) ();
74414708
UD
577 *reloc_addr = value;
578 }
c9cf6dde
AJ
579 else
580 _dl_reloc_bad_type (map, r_type, 1);
581}
582
9dcafc55 583#endif /* RESOLVE_MAP */