i386: Use __glibc_likely/__glibc_likely in dl-machine.h
[glibc.git] / sysdeps / i386 / dl-machine.h
blob3d6fb9b99f0cdb101a42bdca6c4698f56880ab49
1 /* Machine-dependent ELF dynamic relocation inline functions. i386 version.
2 Copyright (C) 1995-2018 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 "i386"
24 #include <sys/param.h>
25 #include <sysdep.h>
26 #include <tls.h>
27 #include <dl-tlsdesc.h>
28 #include <cpu-features.c>
30 /* Return nonzero iff ELF header is compatible with the running host. */
31 static inline int __attribute__ ((unused))
32 elf_machine_matches_host (const Elf32_Ehdr *ehdr)
34 return ehdr->e_machine == EM_386;
38 /* Return the link-time address of _DYNAMIC. Conveniently, this is the
39 first element of the GOT, a special entry that is never relocated. */
40 static inline Elf32_Addr __attribute__ ((unused, const))
41 elf_machine_dynamic (void)
43 /* This produces a GOTOFF reloc that resolves to zero at link time, so in
44 fact just loads from the GOT register directly. By doing it without
45 an asm we can let the compiler choose any register. */
46 extern const Elf32_Addr _GLOBAL_OFFSET_TABLE_[] attribute_hidden;
47 return _GLOBAL_OFFSET_TABLE_[0];
50 /* Return the run-time load address of the shared object. */
51 static inline Elf32_Addr __attribute__ ((unused))
52 elf_machine_load_address (void)
54 /* Compute the difference between the runtime address of _DYNAMIC as seen
55 by a GOTOFF reference, and the link-time address found in the special
56 unrelocated first GOT entry. */
57 extern Elf32_Dyn bygotoff[] asm ("_DYNAMIC") attribute_hidden;
58 return (Elf32_Addr) &bygotoff - elf_machine_dynamic ();
61 /* Set up the loaded object described by L so its unrelocated PLT
62 entries will jump to the on-demand fixup code in dl-runtime.c. */
64 static inline int __attribute__ ((unused, always_inline))
65 elf_machine_runtime_setup (struct link_map *l, int lazy, int profile)
67 Elf32_Addr *got;
68 extern void _dl_runtime_resolve (Elf32_Word) attribute_hidden;
69 extern void _dl_runtime_profile (Elf32_Word) attribute_hidden;
71 if (l->l_info[DT_JMPREL] && lazy)
73 /* The GOT entries for functions in the PLT have not yet been filled
74 in. Their initial contents will arrange when called to push an
75 offset into the .rel.plt section, push _GLOBAL_OFFSET_TABLE_[1],
76 and then jump to _GLOBAL_OFFSET_TABLE[2]. */
77 got = (Elf32_Addr *) D_PTR (l, l_info[DT_PLTGOT]);
78 /* If a library is prelinked but we have to relocate anyway,
79 we have to be able to undo the prelinking of .got.plt.
80 The prelinker saved us here address of .plt + 0x16. */
81 if (got[1])
83 l->l_mach.plt = got[1] + l->l_addr;
84 l->l_mach.gotplt = (Elf32_Addr) &got[3];
86 got[1] = (Elf32_Addr) l; /* Identify this shared object. */
88 /* The got[2] entry contains the address of a function which gets
89 called to get the address of a so far unresolved function and
90 jump to it. The profiling extension of the dynamic linker allows
91 to intercept the calls to collect information. In this case we
92 don't store the address in the GOT so that all future calls also
93 end in this function. */
94 if (__glibc_unlikely (profile))
96 got[2] = (Elf32_Addr) &_dl_runtime_profile;
98 if (GLRO(dl_profile) != NULL
99 && _dl_name_match_p (GLRO(dl_profile), l))
100 /* This is the object we are looking for. Say that we really
101 want profiling and the timers are started. */
102 GL(dl_profile_map) = l;
104 else
105 /* This function will get called to fix up the GOT entry indicated by
106 the offset on the stack, and then jump to the resolved address. */
107 got[2] = (Elf32_Addr) &_dl_runtime_resolve;
110 return lazy;
113 #ifdef IN_DL_RUNTIME
115 # ifndef PROF
116 /* We add a declaration of this function here so that in dl-runtime.c
117 the ELF_MACHINE_RUNTIME_TRAMPOLINE macro really can pass the parameters
118 in registers.
120 We cannot use this scheme for profiling because the _mcount call
121 destroys the passed register information. */
122 #define ARCH_FIXUP_ATTRIBUTE __attribute__ ((regparm (3), stdcall, unused))
124 extern ElfW(Addr) _dl_fixup (struct link_map *l,
125 ElfW(Word) reloc_offset)
126 ARCH_FIXUP_ATTRIBUTE;
127 extern ElfW(Addr) _dl_profile_fixup (struct link_map *l,
128 ElfW(Word) reloc_offset,
129 ElfW(Addr) retaddr, void *regs,
130 long int *framesizep)
131 ARCH_FIXUP_ATTRIBUTE;
132 # endif
134 #endif
136 /* Mask identifying addresses reserved for the user program,
137 where the dynamic linker should not map anything. */
138 #define ELF_MACHINE_USER_ADDRESS_MASK 0xf8000000UL
140 /* Initial entry point code for the dynamic linker.
141 The C function `_dl_start' is the real entry point;
142 its return value is the user program's entry point. */
144 #define RTLD_START asm ("\n\
145 .text\n\
146 .align 16\n\
147 0: movl (%esp), %ebx\n\
148 ret\n\
149 .align 16\n\
150 .globl _start\n\
151 .globl _dl_start_user\n\
152 _start:\n\
153 movl %esp, %eax\n\
154 subl $12, %esp\n\
155 pushl %eax\n\
156 call _dl_start\n\
157 addl $16, %esp\n\
158 _dl_start_user:\n\
159 # Save the user entry point address in %edi.\n\
160 movl %eax, %edi\n\
161 # Point %ebx at the GOT.\n\
162 call 0b\n\
163 addl $_GLOBAL_OFFSET_TABLE_, %ebx\n\
164 # See if we were run as a command with the executable file\n\
165 # name as an extra leading argument.\n\
166 movl _dl_skip_args@GOTOFF(%ebx), %eax\n\
167 # Pop the original argument count.\n\
168 popl %edx\n\
169 # Adjust the stack pointer to skip _dl_skip_args words.\n\
170 leal (%esp,%eax,4), %esp\n\
171 # Subtract _dl_skip_args from argc.\n\
172 subl %eax, %edx\n\
173 # Push argc back on the stack.\n\
174 push %edx\n\
175 # The special initializer gets called with the stack just\n\
176 # as the application's entry point will see it; it can\n\
177 # switch stacks if it moves these contents over.\n\
178 " RTLD_START_SPECIAL_INIT "\n\
179 # Load the parameters again.\n\
180 # (eax, edx, ecx, esi) = (_dl_loaded, argc, argv, envp)\n\
181 movl _rtld_local@GOTOFF(%ebx), %eax\n\
182 leal 8(%esp,%edx,4), %esi\n\
183 leal 4(%esp), %ecx\n\
184 movl %esp, %ebp\n\
185 # Make sure _dl_init is run with 16 byte aligned stack.\n\
186 andl $-16, %esp\n\
187 subl $12, %esp\n\
188 pushl %ebp\n\
189 # Arguments for _dl_init.\n\
190 pushl %esi\n\
191 pushl %ecx\n\
192 pushl %edx\n\
193 pushl %eax\n\
194 # Clear %ebp, so that even constructors have terminated backchain.\n\
195 xorl %ebp, %ebp\n\
196 # Call the function to run the initializers.\n\
197 call _dl_init\n\
198 # Pass our finalizer function to the user in %edx, as per ELF ABI.\n\
199 leal _dl_fini@GOTOFF(%ebx), %edx\n\
200 # Restore %esp _start expects.\n\
201 movl 16(%esp), %esp\n\
202 # Jump to the user's entry point.\n\
203 jmp *%edi\n\
204 .previous\n\
207 #ifndef RTLD_START_SPECIAL_INIT
208 # define RTLD_START_SPECIAL_INIT /* nothing */
209 #endif
211 /* ELF_RTYPE_CLASS_PLT iff TYPE describes relocation of a PLT entry or
212 TLS variable, so undefined references should not be allowed to
213 define the value.
214 ELF_RTYPE_CLASS_COPY iff TYPE should not be allowed to resolve to one
215 of the main executable's symbols, as for a COPY reloc.
216 ELF_RTYPE_CLASS_EXTERN_PROTECTED_DATA iff TYPE describes relocation may
217 against protected data whose address be external due to copy relocation.
219 # define elf_machine_type_class(type) \
220 ((((type) == R_386_JMP_SLOT || (type) == R_386_TLS_DTPMOD32 \
221 || (type) == R_386_TLS_DTPOFF32 || (type) == R_386_TLS_TPOFF32 \
222 || (type) == R_386_TLS_TPOFF || (type) == R_386_TLS_DESC) \
223 * ELF_RTYPE_CLASS_PLT) \
224 | (((type) == R_386_COPY) * ELF_RTYPE_CLASS_COPY) \
225 | (((type) == R_386_GLOB_DAT) * ELF_RTYPE_CLASS_EXTERN_PROTECTED_DATA))
227 /* A reloc type used for ld.so cmdline arg lookups to reject PLT entries. */
228 #define ELF_MACHINE_JMP_SLOT R_386_JMP_SLOT
230 /* The i386 never uses Elf32_Rela relocations for the dynamic linker.
231 Prelinked libraries may use Elf32_Rela though. */
232 #define ELF_MACHINE_PLT_REL 1
234 /* We define an initialization functions. This is called very early in
235 _dl_sysdep_start. */
236 #define DL_PLATFORM_INIT dl_platform_init ()
238 static inline void __attribute__ ((unused))
239 dl_platform_init (void)
241 #if IS_IN (rtld)
242 /* init_cpu_features has been called early from __libc_start_main in
243 static executable. */
244 init_cpu_features (&GLRO(dl_x86_cpu_features));
245 #else
246 if (GLRO(dl_platform) != NULL && *GLRO(dl_platform) == '\0')
247 /* Avoid an empty string which would disturb us. */
248 GLRO(dl_platform) = NULL;
249 #endif
252 static inline Elf32_Addr
253 elf_machine_fixup_plt (struct link_map *map, lookup_t t,
254 const ElfW(Sym) *refsym, const ElfW(Sym) *sym,
255 const Elf32_Rel *reloc,
256 Elf32_Addr *reloc_addr, Elf32_Addr value)
258 return *reloc_addr = value;
261 /* Return the final value of a plt relocation. */
262 static inline Elf32_Addr
263 elf_machine_plt_value (struct link_map *map, const Elf32_Rel *reloc,
264 Elf32_Addr value)
266 return value;
270 /* Names of the architecture-specific auditing callback functions. */
271 #define ARCH_LA_PLTENTER i86_gnu_pltenter
272 #define ARCH_LA_PLTEXIT i86_gnu_pltexit
274 #endif /* !dl_machine_h */
276 /* The i386 never uses Elf32_Rela relocations for the dynamic linker.
277 Prelinked libraries may use Elf32_Rela though. */
278 #define ELF_MACHINE_NO_RELA defined RTLD_BOOTSTRAP
279 #define ELF_MACHINE_NO_REL 0
281 #ifdef RESOLVE_MAP
283 /* Perform the relocation specified by RELOC and SYM (which is fully resolved).
284 MAP is the object containing the reloc. */
286 auto inline void
287 __attribute ((always_inline))
288 elf_machine_rel (struct link_map *map, const Elf32_Rel *reloc,
289 const Elf32_Sym *sym, const struct r_found_version *version,
290 void *const reloc_addr_arg, int skip_ifunc)
292 Elf32_Addr *const reloc_addr = reloc_addr_arg;
293 const unsigned int r_type = ELF32_R_TYPE (reloc->r_info);
295 # if !defined RTLD_BOOTSTRAP || !defined HAVE_Z_COMBRELOC
296 if (__glibc_unlikely (r_type == R_386_RELATIVE))
298 # if !defined RTLD_BOOTSTRAP && !defined HAVE_Z_COMBRELOC
299 /* This is defined in rtld.c, but nowhere in the static libc.a;
300 make the reference weak so static programs can still link.
301 This declaration cannot be done when compiling rtld.c
302 (i.e. #ifdef RTLD_BOOTSTRAP) because rtld.c contains the
303 common defn for _dl_rtld_map, which is incompatible with a
304 weak decl in the same file. */
305 # ifndef SHARED
306 weak_extern (_dl_rtld_map);
307 # endif
308 if (map != &GL(dl_rtld_map)) /* Already done in rtld itself. */
309 # endif
310 *reloc_addr += map->l_addr;
312 # ifndef RTLD_BOOTSTRAP
313 else if (__glibc_unlikely (r_type == R_386_NONE))
314 return;
315 # endif
316 else
317 # endif /* !RTLD_BOOTSTRAP and have no -z combreloc */
319 # ifndef RTLD_BOOTSTRAP
320 const Elf32_Sym *const refsym = sym;
321 # endif
322 struct link_map *sym_map = RESOLVE_MAP (&sym, version, r_type);
323 Elf32_Addr value = sym_map == NULL ? 0 : sym_map->l_addr + sym->st_value;
325 if (sym != NULL
326 && __glibc_unlikely (ELFW(ST_TYPE) (sym->st_info) == STT_GNU_IFUNC)
327 && __glibc_likely (sym->st_shndx != SHN_UNDEF)
328 && __glibc_likely (!skip_ifunc))
330 # ifndef RTLD_BOOTSTRAP
331 if (sym_map != map
332 && sym_map->l_type != lt_executable
333 && !sym_map->l_relocated)
335 const char *strtab
336 = (const char *) D_PTR (map, l_info[DT_STRTAB]);
337 _dl_error_printf ("\
338 %s: Relink `%s' with `%s' for IFUNC symbol `%s'\n",
339 RTLD_PROGNAME, map->l_name,
340 sym_map->l_name,
341 strtab + refsym->st_name);
343 # endif
344 value = ((Elf32_Addr (*) (void)) value) ();
347 switch (r_type)
349 # ifndef RTLD_BOOTSTRAP
350 case R_386_SIZE32:
351 /* Set to symbol size plus addend. */
352 *reloc_addr += sym->st_size;
353 break;
354 # endif
355 case R_386_GLOB_DAT:
356 case R_386_JMP_SLOT:
357 *reloc_addr = value;
358 break;
360 case R_386_TLS_DTPMOD32:
361 # ifdef RTLD_BOOTSTRAP
362 /* During startup the dynamic linker is always the module
363 with index 1.
364 XXX If this relocation is necessary move before RESOLVE
365 call. */
366 *reloc_addr = 1;
367 # else
368 /* Get the information from the link map returned by the
369 resolv function. */
370 if (sym_map != NULL)
371 *reloc_addr = sym_map->l_tls_modid;
372 # endif
373 break;
374 case R_386_TLS_DTPOFF32:
375 # ifndef RTLD_BOOTSTRAP
376 /* During relocation all TLS symbols are defined and used.
377 Therefore the offset is already correct. */
378 if (sym != NULL)
379 *reloc_addr = sym->st_value;
380 # endif
381 break;
382 case R_386_TLS_DESC:
384 struct tlsdesc volatile *td =
385 (struct tlsdesc volatile *)reloc_addr;
387 # ifndef RTLD_BOOTSTRAP
388 if (! sym)
389 td->entry = _dl_tlsdesc_undefweak;
390 else
391 # endif
393 # ifndef RTLD_BOOTSTRAP
394 # ifndef SHARED
395 CHECK_STATIC_TLS (map, sym_map);
396 # else
397 if (!TRY_STATIC_TLS (map, sym_map))
399 td->arg = _dl_make_tlsdesc_dynamic
400 (sym_map, sym->st_value + (ElfW(Word))td->arg);
401 td->entry = _dl_tlsdesc_dynamic;
403 else
404 # endif
405 # endif
407 td->arg = (void*)(sym->st_value - sym_map->l_tls_offset
408 + (ElfW(Word))td->arg);
409 td->entry = _dl_tlsdesc_return;
412 break;
414 case R_386_TLS_TPOFF32:
415 /* The offset is positive, backward from the thread pointer. */
416 # ifdef RTLD_BOOTSTRAP
417 *reloc_addr += map->l_tls_offset - sym->st_value;
418 # else
419 /* We know the offset of object the symbol is contained in.
420 It is a positive value which will be subtracted from the
421 thread pointer. To get the variable position in the TLS
422 block we subtract the offset from that of the TLS block. */
423 if (sym != NULL)
425 CHECK_STATIC_TLS (map, sym_map);
426 *reloc_addr += sym_map->l_tls_offset - sym->st_value;
428 # endif
429 break;
430 case R_386_TLS_TPOFF:
431 /* The offset is negative, forward from the thread pointer. */
432 # ifdef RTLD_BOOTSTRAP
433 *reloc_addr += sym->st_value - map->l_tls_offset;
434 # else
435 /* We know the offset of object the symbol is contained in.
436 It is a negative value which will be added to the
437 thread pointer. */
438 if (sym != NULL)
440 CHECK_STATIC_TLS (map, sym_map);
441 *reloc_addr += sym->st_value - sym_map->l_tls_offset;
443 # endif
444 break;
446 # ifndef RTLD_BOOTSTRAP
447 case R_386_32:
448 *reloc_addr += value;
449 break;
450 case R_386_PC32:
451 *reloc_addr += (value - (Elf32_Addr) reloc_addr);
452 break;
453 case R_386_COPY:
454 if (sym == NULL)
455 /* This can happen in trace mode if an object could not be
456 found. */
457 break;
458 if (__glibc_unlikely (sym->st_size > refsym->st_size)
459 || (__glibc_unlikely(sym->st_size < refsym->st_size)
460 && GLRO(dl_verbose)))
462 const char *strtab;
464 strtab = (const char *) D_PTR (map, l_info[DT_STRTAB]);
465 _dl_error_printf ("\
466 %s: Symbol `%s' has different size in shared object, consider re-linking\n",
467 RTLD_PROGNAME, strtab + refsym->st_name);
469 memcpy (reloc_addr_arg, (void *) value,
470 MIN (sym->st_size, refsym->st_size));
471 break;
472 case R_386_IRELATIVE:
473 value = map->l_addr + *reloc_addr;
474 value = ((Elf32_Addr (*) (void)) value) ();
475 *reloc_addr = value;
476 break;
477 default:
478 _dl_reloc_bad_type (map, r_type, 0);
479 break;
480 # endif /* !RTLD_BOOTSTRAP */
485 # ifndef RTLD_BOOTSTRAP
486 auto inline void
487 __attribute__ ((always_inline))
488 elf_machine_rela (struct link_map *map, const Elf32_Rela *reloc,
489 const Elf32_Sym *sym, const struct r_found_version *version,
490 void *const reloc_addr_arg, int skip_ifunc)
492 Elf32_Addr *const reloc_addr = reloc_addr_arg;
493 const unsigned int r_type = ELF32_R_TYPE (reloc->r_info);
495 if (ELF32_R_TYPE (reloc->r_info) == R_386_RELATIVE)
496 *reloc_addr = map->l_addr + reloc->r_addend;
497 else if (r_type != R_386_NONE)
499 # ifndef RESOLVE_CONFLICT_FIND_MAP
500 const Elf32_Sym *const refsym = sym;
501 # endif
502 struct link_map *sym_map = RESOLVE_MAP (&sym, version, r_type);
503 Elf32_Addr value = sym == NULL ? 0 : sym_map->l_addr + sym->st_value;
505 if (sym != NULL
506 && __glibc_likely (sym->st_shndx != SHN_UNDEF)
507 && __glibc_unlikely (ELFW(ST_TYPE) (sym->st_info) == STT_GNU_IFUNC)
508 && __glibc_likely (!skip_ifunc))
509 value = ((Elf32_Addr (*) (void)) value) ();
511 switch (ELF32_R_TYPE (reloc->r_info))
513 case R_386_SIZE32:
514 /* Set to symbol size plus addend. */
515 value = sym->st_size;
516 case R_386_GLOB_DAT:
517 case R_386_JMP_SLOT:
518 case R_386_32:
519 *reloc_addr = value + reloc->r_addend;
520 break;
521 # ifndef RESOLVE_CONFLICT_FIND_MAP
522 /* Not needed for dl-conflict.c. */
523 case R_386_PC32:
524 *reloc_addr = (value + reloc->r_addend - (Elf32_Addr) reloc_addr);
525 break;
527 case R_386_TLS_DTPMOD32:
528 /* Get the information from the link map returned by the
529 resolv function. */
530 if (sym_map != NULL)
531 *reloc_addr = sym_map->l_tls_modid;
532 break;
533 case R_386_TLS_DTPOFF32:
534 /* During relocation all TLS symbols are defined and used.
535 Therefore the offset is already correct. */
536 *reloc_addr = (sym == NULL ? 0 : sym->st_value) + reloc->r_addend;
537 break;
538 case R_386_TLS_DESC:
540 struct tlsdesc volatile *td =
541 (struct tlsdesc volatile *)reloc_addr;
543 # ifndef RTLD_BOOTSTRAP
544 if (!sym)
546 td->arg = (void*)reloc->r_addend;
547 td->entry = _dl_tlsdesc_undefweak;
549 else
550 # endif
552 # ifndef RTLD_BOOTSTRAP
553 # ifndef SHARED
554 CHECK_STATIC_TLS (map, sym_map);
555 # else
556 if (!TRY_STATIC_TLS (map, sym_map))
558 td->arg = _dl_make_tlsdesc_dynamic
559 (sym_map, sym->st_value + reloc->r_addend);
560 td->entry = _dl_tlsdesc_dynamic;
562 else
563 # endif
564 # endif
566 td->arg = (void*)(sym->st_value - sym_map->l_tls_offset
567 + reloc->r_addend);
568 td->entry = _dl_tlsdesc_return;
572 break;
573 case R_386_TLS_TPOFF32:
574 /* The offset is positive, backward from the thread pointer. */
575 /* We know the offset of object the symbol is contained in.
576 It is a positive value which will be subtracted from the
577 thread pointer. To get the variable position in the TLS
578 block we subtract the offset from that of the TLS block. */
579 if (sym != NULL)
581 CHECK_STATIC_TLS (map, sym_map);
582 *reloc_addr = sym_map->l_tls_offset - sym->st_value
583 + reloc->r_addend;
585 break;
586 case R_386_TLS_TPOFF:
587 /* The offset is negative, forward from the thread pointer. */
588 /* We know the offset of object the symbol is contained in.
589 It is a negative value which will be added to the
590 thread pointer. */
591 if (sym != NULL)
593 CHECK_STATIC_TLS (map, sym_map);
594 *reloc_addr = sym->st_value - sym_map->l_tls_offset
595 + reloc->r_addend;
597 break;
598 case R_386_COPY:
599 if (sym == NULL)
600 /* This can happen in trace mode if an object could not be
601 found. */
602 break;
603 if (__glibc_unlikely (sym->st_size > refsym->st_size)
604 || (__glibc_unlikely (sym->st_size < refsym->st_size)
605 && GLRO(dl_verbose)))
607 const char *strtab;
609 strtab = (const char *) D_PTR (map, l_info[DT_STRTAB]);
610 _dl_error_printf ("\
611 %s: Symbol `%s' has different size in shared object, consider re-linking\n",
612 RTLD_PROGNAME, strtab + refsym->st_name);
614 memcpy (reloc_addr_arg, (void *) value,
615 MIN (sym->st_size, refsym->st_size));
616 break;
617 # endif /* !RESOLVE_CONFLICT_FIND_MAP */
618 case R_386_IRELATIVE:
619 value = map->l_addr + reloc->r_addend;
620 value = ((Elf32_Addr (*) (void)) value) ();
621 *reloc_addr = value;
622 break;
623 default:
624 /* We add these checks in the version to relocate ld.so only
625 if we are still debugging. */
626 _dl_reloc_bad_type (map, r_type, 0);
627 break;
631 # endif /* !RTLD_BOOTSTRAP */
633 auto inline void
634 __attribute ((always_inline))
635 elf_machine_rel_relative (Elf32_Addr l_addr, const Elf32_Rel *reloc,
636 void *const reloc_addr_arg)
638 Elf32_Addr *const reloc_addr = reloc_addr_arg;
639 assert (ELF32_R_TYPE (reloc->r_info) == R_386_RELATIVE);
640 *reloc_addr += l_addr;
643 # ifndef RTLD_BOOTSTRAP
644 auto inline void
645 __attribute__ ((always_inline))
646 elf_machine_rela_relative (Elf32_Addr l_addr, const Elf32_Rela *reloc,
647 void *const reloc_addr_arg)
649 Elf32_Addr *const reloc_addr = reloc_addr_arg;
650 *reloc_addr = l_addr + reloc->r_addend;
652 # endif /* !RTLD_BOOTSTRAP */
654 auto inline void
655 __attribute__ ((always_inline))
656 elf_machine_lazy_rel (struct link_map *map,
657 Elf32_Addr l_addr, const Elf32_Rel *reloc,
658 int skip_ifunc)
660 Elf32_Addr *const reloc_addr = (void *) (l_addr + reloc->r_offset);
661 const unsigned int r_type = ELF32_R_TYPE (reloc->r_info);
662 /* Check for unexpected PLT reloc type. */
663 if (__glibc_likely (r_type == R_386_JMP_SLOT))
665 /* Prelink has been deprecated. */
666 if (__glibc_likely (map->l_mach.plt == 0))
667 *reloc_addr += l_addr;
668 else
669 *reloc_addr = (map->l_mach.plt
670 + (((Elf32_Addr) reloc_addr) - map->l_mach.gotplt) * 4);
672 else if (__glibc_likely (r_type == R_386_TLS_DESC))
674 struct tlsdesc volatile * __attribute__((__unused__)) td =
675 (struct tlsdesc volatile *)reloc_addr;
677 /* Handle relocations that reference the local *ABS* in a simple
678 way, so as to preserve a potential addend. */
679 if (ELF32_R_SYM (reloc->r_info) == 0)
680 td->entry = _dl_tlsdesc_resolve_abs_plus_addend;
681 /* Given a known-zero addend, we can store a pointer to the
682 reloc in the arg position. */
683 else if (td->arg == 0)
685 td->arg = (void*)reloc;
686 td->entry = _dl_tlsdesc_resolve_rel;
688 else
690 /* We could handle non-*ABS* relocations with non-zero addends
691 by allocating dynamically an arg to hold a pointer to the
692 reloc, but that sounds pointless. */
693 const Elf32_Rel *const r = reloc;
694 /* The code below was borrowed from elf_dynamic_do_rel(). */
695 const ElfW(Sym) *const symtab =
696 (const void *) D_PTR (map, l_info[DT_SYMTAB]);
698 # ifdef RTLD_BOOTSTRAP
699 /* The dynamic linker always uses versioning. */
700 assert (map->l_info[VERSYMIDX (DT_VERSYM)] != NULL);
701 # else
702 if (map->l_info[VERSYMIDX (DT_VERSYM)])
703 # endif
705 const ElfW(Half) *const version =
706 (const void *) D_PTR (map, l_info[VERSYMIDX (DT_VERSYM)]);
707 ElfW(Half) ndx = version[ELFW(R_SYM) (r->r_info)] & 0x7fff;
708 elf_machine_rel (map, r, &symtab[ELFW(R_SYM) (r->r_info)],
709 &map->l_versions[ndx],
710 (void *) (l_addr + r->r_offset), skip_ifunc);
712 # ifndef RTLD_BOOTSTRAP
713 else
714 elf_machine_rel (map, r, &symtab[ELFW(R_SYM) (r->r_info)], NULL,
715 (void *) (l_addr + r->r_offset), skip_ifunc);
716 # endif
719 else if (__glibc_unlikely (r_type == R_386_IRELATIVE))
721 Elf32_Addr value = map->l_addr + *reloc_addr;
722 if (__glibc_likely (!skip_ifunc))
723 value = ((Elf32_Addr (*) (void)) value) ();
724 *reloc_addr = value;
726 else
727 _dl_reloc_bad_type (map, r_type, 1);
730 # ifndef RTLD_BOOTSTRAP
732 auto inline void
733 __attribute__ ((always_inline))
734 elf_machine_lazy_rela (struct link_map *map,
735 Elf32_Addr l_addr, const Elf32_Rela *reloc,
736 int skip_ifunc)
738 Elf32_Addr *const reloc_addr = (void *) (l_addr + reloc->r_offset);
739 const unsigned int r_type = ELF32_R_TYPE (reloc->r_info);
740 if (__glibc_likely (r_type == R_386_JMP_SLOT))
742 else if (__glibc_likely (r_type == R_386_TLS_DESC))
744 struct tlsdesc volatile * __attribute__((__unused__)) td =
745 (struct tlsdesc volatile *)reloc_addr;
747 td->arg = (void*)reloc;
748 td->entry = _dl_tlsdesc_resolve_rela;
750 else if (__glibc_unlikely (r_type == R_386_IRELATIVE))
752 Elf32_Addr value = map->l_addr + reloc->r_addend;
753 if (__glibc_likely (!skip_ifunc))
754 value = ((Elf32_Addr (*) (void)) value) ();
755 *reloc_addr = value;
757 else
758 _dl_reloc_bad_type (map, r_type, 1);
761 # endif /* !RTLD_BOOTSTRAP */
763 #endif /* RESOLVE_MAP */