Replace FSF snail mail address with URLs.
[glibc.git] / sysdeps / i386 / dl-machine.h
blobe20a961f98dbe9a2d37e9e58e70f5d38ea1eab25
1 /* Machine-dependent ELF dynamic relocation inline functions. i386 version.
2 Copyright (C) 1995-2005, 2006, 2009, 2011 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>
29 /* Return nonzero iff ELF header is compatible with the running host. */
30 static inline int __attribute__ ((unused))
31 elf_machine_matches_host (const Elf32_Ehdr *ehdr)
33 return ehdr->e_machine == EM_386;
37 #ifdef PI_STATIC_AND_HIDDEN
39 /* Return the link-time address of _DYNAMIC. Conveniently, this is the
40 first element of the GOT, a special entry that is never relocated. */
41 static inline Elf32_Addr __attribute__ ((unused, const))
42 elf_machine_dynamic (void)
44 /* This produces a GOTOFF reloc that resolves to zero at link time, so in
45 fact just loads from the GOT register directly. By doing it without
46 an asm we can let the compiler choose any register. */
47 extern const Elf32_Addr _GLOBAL_OFFSET_TABLE_[] attribute_hidden;
48 return _GLOBAL_OFFSET_TABLE_[0];
51 /* Return the run-time load address of the shared object. */
52 static inline Elf32_Addr __attribute__ ((unused))
53 elf_machine_load_address (void)
55 /* Compute the difference between the runtime address of _DYNAMIC as seen
56 by a GOTOFF reference, and the link-time address found in the special
57 unrelocated first GOT entry. */
58 extern Elf32_Dyn bygotoff[] asm ("_DYNAMIC") attribute_hidden;
59 return (Elf32_Addr) &bygotoff - elf_machine_dynamic ();
62 #else /* Without .hidden support, we can't compile the code above. */
64 /* Return the link-time address of _DYNAMIC. Conveniently, this is the
65 first element of the GOT. This must be inlined in a function which
66 uses global data. */
67 static inline Elf32_Addr __attribute__ ((unused))
68 elf_machine_dynamic (void)
70 register Elf32_Addr *got asm ("%ebx");
71 return *got;
75 /* Return the run-time load address of the shared object. */
76 static inline Elf32_Addr __attribute__ ((unused))
77 elf_machine_load_address (void)
79 /* It doesn't matter what variable this is, the reference never makes
80 it to assembly. We need a dummy reference to some global variable
81 via the GOT to make sure the compiler initialized %ebx in time. */
82 extern int _dl_argc;
83 Elf32_Addr addr;
84 asm ("leal _dl_start@GOTOFF(%%ebx), %0\n"
85 "subl _dl_start@GOT(%%ebx), %0"
86 : "=r" (addr) : "m" (_dl_argc) : "cc");
87 return addr;
90 #endif
93 /* Set up the loaded object described by L so its unrelocated PLT
94 entries will jump to the on-demand fixup code in dl-runtime.c. */
96 static inline int __attribute__ ((unused, always_inline))
97 elf_machine_runtime_setup (struct link_map *l, int lazy, int profile)
99 Elf32_Addr *got;
100 extern void _dl_runtime_resolve (Elf32_Word) attribute_hidden;
101 extern void _dl_runtime_profile (Elf32_Word) attribute_hidden;
103 if (l->l_info[DT_JMPREL] && lazy)
105 /* The GOT entries for functions in the PLT have not yet been filled
106 in. Their initial contents will arrange when called to push an
107 offset into the .rel.plt section, push _GLOBAL_OFFSET_TABLE_[1],
108 and then jump to _GLOBAL_OFFSET_TABLE[2]. */
109 got = (Elf32_Addr *) D_PTR (l, l_info[DT_PLTGOT]);
110 /* If a library is prelinked but we have to relocate anyway,
111 we have to be able to undo the prelinking of .got.plt.
112 The prelinker saved us here address of .plt + 0x16. */
113 if (got[1])
115 l->l_mach.plt = got[1] + l->l_addr;
116 l->l_mach.gotplt = (Elf32_Addr) &got[3];
118 got[1] = (Elf32_Addr) l; /* Identify this shared object. */
120 /* The got[2] entry contains the address of a function which gets
121 called to get the address of a so far unresolved function and
122 jump to it. The profiling extension of the dynamic linker allows
123 to intercept the calls to collect information. In this case we
124 don't store the address in the GOT so that all future calls also
125 end in this function. */
126 if (__builtin_expect (profile, 0))
128 got[2] = (Elf32_Addr) &_dl_runtime_profile;
130 if (GLRO(dl_profile) != NULL
131 && _dl_name_match_p (GLRO(dl_profile), l))
132 /* This is the object we are looking for. Say that we really
133 want profiling and the timers are started. */
134 GL(dl_profile_map) = l;
136 else
137 /* This function will get called to fix up the GOT entry indicated by
138 the offset on the stack, and then jump to the resolved address. */
139 got[2] = (Elf32_Addr) &_dl_runtime_resolve;
142 return lazy;
145 #ifdef IN_DL_RUNTIME
147 # if !defined PROF && !__BOUNDED_POINTERS__
148 /* We add a declaration of this function here so that in dl-runtime.c
149 the ELF_MACHINE_RUNTIME_TRAMPOLINE macro really can pass the parameters
150 in registers.
152 We cannot use this scheme for profiling because the _mcount call
153 destroys the passed register information. */
154 /* GKM FIXME: Fix trampoline to pass bounds so we can do
155 without the `__unbounded' qualifier. */
156 #define ARCH_FIXUP_ATTRIBUTE __attribute__ ((regparm (3), stdcall, unused))
158 extern ElfW(Addr) _dl_fixup (struct link_map *__unbounded l,
159 ElfW(Word) reloc_offset)
160 ARCH_FIXUP_ATTRIBUTE;
161 extern ElfW(Addr) _dl_profile_fixup (struct link_map *l,
162 ElfW(Word) reloc_offset,
163 ElfW(Addr) retaddr, void *regs,
164 long int *framesizep)
165 ARCH_FIXUP_ATTRIBUTE;
166 # endif
168 #endif
170 /* Mask identifying addresses reserved for the user program,
171 where the dynamic linker should not map anything. */
172 #define ELF_MACHINE_USER_ADDRESS_MASK 0xf8000000UL
174 /* Initial entry point code for the dynamic linker.
175 The C function `_dl_start' is the real entry point;
176 its return value is the user program's entry point. */
178 #define RTLD_START asm ("\n\
179 .text\n\
180 .align 16\n\
181 0: movl (%esp), %ebx\n\
182 ret\n\
183 .align 16\n\
184 .globl _start\n\
185 .globl _dl_start_user\n\
186 _start:\n\
187 # Note that _dl_start gets the parameter in %eax.\n\
188 movl %esp, %eax\n\
189 call _dl_start\n\
190 _dl_start_user:\n\
191 # Save the user entry point address in %edi.\n\
192 movl %eax, %edi\n\
193 # Point %ebx at the GOT.\n\
194 call 0b\n\
195 addl $_GLOBAL_OFFSET_TABLE_, %ebx\n\
196 # See if we were run as a command with the executable file\n\
197 # name as an extra leading argument.\n\
198 movl _dl_skip_args@GOTOFF(%ebx), %eax\n\
199 # Pop the original argument count.\n\
200 popl %edx\n\
201 # Adjust the stack pointer to skip _dl_skip_args words.\n\
202 leal (%esp,%eax,4), %esp\n\
203 # Subtract _dl_skip_args from argc.\n\
204 subl %eax, %edx\n\
205 # Push argc back on the stack.\n\
206 push %edx\n\
207 # The special initializer gets called with the stack just\n\
208 # as the application's entry point will see it; it can\n\
209 # switch stacks if it moves these contents over.\n\
210 " RTLD_START_SPECIAL_INIT "\n\
211 # Load the parameters again.\n\
212 # (eax, edx, ecx, *--esp) = (_dl_loaded, argc, argv, envp)\n\
213 movl _rtld_local@GOTOFF(%ebx), %eax\n\
214 leal 8(%esp,%edx,4), %esi\n\
215 leal 4(%esp), %ecx\n\
216 movl %esp, %ebp\n\
217 # Make sure _dl_init is run with 16 byte aligned stack.\n\
218 andl $-16, %esp\n\
219 pushl %eax\n\
220 pushl %eax\n\
221 pushl %ebp\n\
222 pushl %esi\n\
223 # Clear %ebp, so that even constructors have terminated backchain.\n\
224 xorl %ebp, %ebp\n\
225 # Call the function to run the initializers.\n\
226 call _dl_init_internal@PLT\n\
227 # Pass our finalizer function to the user in %edx, as per ELF ABI.\n\
228 leal _dl_fini@GOTOFF(%ebx), %edx\n\
229 # Restore %esp _start expects.\n\
230 movl (%esp), %esp\n\
231 # Jump to the user's entry point.\n\
232 jmp *%edi\n\
233 .previous\n\
236 #ifndef RTLD_START_SPECIAL_INIT
237 # define RTLD_START_SPECIAL_INIT /* nothing */
238 #endif
240 /* ELF_RTYPE_CLASS_PLT iff TYPE describes relocation of a PLT entry or
241 TLS variable, so undefined references should not be allowed to
242 define the value.
243 ELF_RTYPE_CLASS_NOCOPY iff TYPE should not be allowed to resolve to one
244 of the main executable's symbols, as for a COPY reloc. */
245 # define elf_machine_type_class(type) \
246 ((((type) == R_386_JMP_SLOT || (type) == R_386_TLS_DTPMOD32 \
247 || (type) == R_386_TLS_DTPOFF32 || (type) == R_386_TLS_TPOFF32 \
248 || (type) == R_386_TLS_TPOFF || (type) == R_386_TLS_DESC) \
249 * ELF_RTYPE_CLASS_PLT) \
250 | (((type) == R_386_COPY) * ELF_RTYPE_CLASS_COPY))
252 /* A reloc type used for ld.so cmdline arg lookups to reject PLT entries. */
253 #define ELF_MACHINE_JMP_SLOT R_386_JMP_SLOT
255 /* The i386 never uses Elf32_Rela relocations for the dynamic linker.
256 Prelinked libraries may use Elf32_Rela though. */
257 #define ELF_MACHINE_PLT_REL 1
259 /* We define an initialization functions. This is called very early in
260 _dl_sysdep_start. */
261 #define DL_PLATFORM_INIT dl_platform_init ()
263 static inline void __attribute__ ((unused))
264 dl_platform_init (void)
266 if (GLRO(dl_platform) != NULL && *GLRO(dl_platform) == '\0')
267 /* Avoid an empty string which would disturb us. */
268 GLRO(dl_platform) = NULL;
271 static inline Elf32_Addr
272 elf_machine_fixup_plt (struct link_map *map, lookup_t t,
273 const Elf32_Rel *reloc,
274 Elf32_Addr *reloc_addr, Elf32_Addr value)
276 return *reloc_addr = value;
279 /* Return the final value of a plt relocation. */
280 static inline Elf32_Addr
281 elf_machine_plt_value (struct link_map *map, const Elf32_Rel *reloc,
282 Elf32_Addr value)
284 return value;
288 /* Names of the architecture-specific auditing callback functions. */
289 #define ARCH_LA_PLTENTER i86_gnu_pltenter
290 #define ARCH_LA_PLTEXIT i86_gnu_pltexit
292 #endif /* !dl_machine_h */
294 /* The i386 never uses Elf32_Rela relocations for the dynamic linker.
295 Prelinked libraries may use Elf32_Rela though. */
296 #define ELF_MACHINE_NO_RELA defined RTLD_BOOTSTRAP
298 #ifdef RESOLVE_MAP
300 /* Perform the relocation specified by RELOC and SYM (which is fully resolved).
301 MAP is the object containing the reloc. */
303 auto inline void
304 __attribute ((always_inline))
305 elf_machine_rel (struct link_map *map, const Elf32_Rel *reloc,
306 const Elf32_Sym *sym, const struct r_found_version *version,
307 void *const reloc_addr_arg, int skip_ifunc)
309 Elf32_Addr *const reloc_addr = reloc_addr_arg;
310 const unsigned int r_type = ELF32_R_TYPE (reloc->r_info);
312 # if !defined RTLD_BOOTSTRAP || !defined HAVE_Z_COMBRELOC
313 if (__builtin_expect (r_type == R_386_RELATIVE, 0))
315 # if !defined RTLD_BOOTSTRAP && !defined HAVE_Z_COMBRELOC
316 /* This is defined in rtld.c, but nowhere in the static libc.a;
317 make the reference weak so static programs can still link.
318 This declaration cannot be done when compiling rtld.c
319 (i.e. #ifdef RTLD_BOOTSTRAP) because rtld.c contains the
320 common defn for _dl_rtld_map, which is incompatible with a
321 weak decl in the same file. */
322 # ifndef SHARED
323 weak_extern (_dl_rtld_map);
324 # endif
325 if (map != &GL(dl_rtld_map)) /* Already done in rtld itself. */
326 # endif
327 *reloc_addr += map->l_addr;
329 # ifndef RTLD_BOOTSTRAP
330 else if (__builtin_expect (r_type == R_386_NONE, 0))
331 return;
332 # endif
333 else
334 # endif /* !RTLD_BOOTSTRAP and have no -z combreloc */
336 const Elf32_Sym *const refsym = sym;
337 struct link_map *sym_map = RESOLVE_MAP (&sym, version, r_type);
338 Elf32_Addr value = sym_map == NULL ? 0 : sym_map->l_addr + sym->st_value;
340 if (sym != NULL
341 && __builtin_expect (ELFW(ST_TYPE) (sym->st_info) == STT_GNU_IFUNC,
343 && __builtin_expect (sym->st_shndx != SHN_UNDEF, 1)
344 && __builtin_expect (!skip_ifunc, 1))
345 value = ((Elf32_Addr (*) (void)) value) ();
347 switch (r_type)
349 case R_386_GLOB_DAT:
350 case R_386_JMP_SLOT:
351 *reloc_addr = value;
352 break;
354 case R_386_TLS_DTPMOD32:
355 # ifdef RTLD_BOOTSTRAP
356 /* During startup the dynamic linker is always the module
357 with index 1.
358 XXX If this relocation is necessary move before RESOLVE
359 call. */
360 *reloc_addr = 1;
361 # else
362 /* Get the information from the link map returned by the
363 resolv function. */
364 if (sym_map != NULL)
365 *reloc_addr = sym_map->l_tls_modid;
366 # endif
367 break;
368 case R_386_TLS_DTPOFF32:
369 # ifndef RTLD_BOOTSTRAP
370 /* During relocation all TLS symbols are defined and used.
371 Therefore the offset is already correct. */
372 if (sym != NULL)
373 *reloc_addr = sym->st_value;
374 # endif
375 break;
376 case R_386_TLS_DESC:
378 struct tlsdesc volatile *td =
379 (struct tlsdesc volatile *)reloc_addr;
381 # ifndef RTLD_BOOTSTRAP
382 if (! sym)
383 td->entry = _dl_tlsdesc_undefweak;
384 else
385 # endif
387 # ifndef RTLD_BOOTSTRAP
388 # ifndef SHARED
389 CHECK_STATIC_TLS (map, sym_map);
390 # else
391 if (!TRY_STATIC_TLS (map, sym_map))
393 td->arg = _dl_make_tlsdesc_dynamic
394 (sym_map, sym->st_value + (ElfW(Word))td->arg);
395 td->entry = _dl_tlsdesc_dynamic;
397 else
398 # endif
399 # endif
401 td->arg = (void*)(sym->st_value - sym_map->l_tls_offset
402 + (ElfW(Word))td->arg);
403 td->entry = _dl_tlsdesc_return;
406 break;
408 case R_386_TLS_TPOFF32:
409 /* The offset is positive, backward from the thread pointer. */
410 # ifdef RTLD_BOOTSTRAP
411 *reloc_addr += map->l_tls_offset - sym->st_value;
412 # else
413 /* We know the offset of object the symbol is contained in.
414 It is a positive value which will be subtracted from the
415 thread pointer. To get the variable position in the TLS
416 block we subtract the offset from that of the TLS block. */
417 if (sym != NULL)
419 CHECK_STATIC_TLS (map, sym_map);
420 *reloc_addr += sym_map->l_tls_offset - sym->st_value;
422 # endif
423 break;
424 case R_386_TLS_TPOFF:
425 /* The offset is negative, forward from the thread pointer. */
426 # ifdef RTLD_BOOTSTRAP
427 *reloc_addr += sym->st_value - map->l_tls_offset;
428 # else
429 /* We know the offset of object the symbol is contained in.
430 It is a negative value which will be added to the
431 thread pointer. */
432 if (sym != NULL)
434 CHECK_STATIC_TLS (map, sym_map);
435 *reloc_addr += sym->st_value - sym_map->l_tls_offset;
437 # endif
438 break;
440 # ifndef RTLD_BOOTSTRAP
441 case R_386_32:
442 *reloc_addr += value;
443 break;
444 case R_386_PC32:
445 *reloc_addr += (value - (Elf32_Addr) reloc_addr);
446 break;
447 case R_386_COPY:
448 if (sym == NULL)
449 /* This can happen in trace mode if an object could not be
450 found. */
451 break;
452 if (__builtin_expect (sym->st_size > refsym->st_size, 0)
453 || (__builtin_expect (sym->st_size < refsym->st_size, 0)
454 && GLRO(dl_verbose)))
456 const char *strtab;
458 strtab = (const char *) D_PTR (map, l_info[DT_STRTAB]);
459 _dl_error_printf ("\
460 %s: Symbol `%s' has different size in shared object, consider re-linking\n",
461 rtld_progname ?: "<program name unknown>",
462 strtab + refsym->st_name);
464 memcpy (reloc_addr_arg, (void *) value,
465 MIN (sym->st_size, refsym->st_size));
466 break;
467 case R_386_IRELATIVE:
468 value = map->l_addr + *reloc_addr;
469 value = ((Elf32_Addr (*) (void)) value) ();
470 *reloc_addr = value;
471 break;
472 default:
473 _dl_reloc_bad_type (map, r_type, 0);
474 break;
475 # endif /* !RTLD_BOOTSTRAP */
480 # ifndef RTLD_BOOTSTRAP
481 auto inline void
482 __attribute__ ((always_inline))
483 elf_machine_rela (struct link_map *map, const Elf32_Rela *reloc,
484 const Elf32_Sym *sym, const struct r_found_version *version,
485 void *const reloc_addr_arg, int skip_ifunc)
487 Elf32_Addr *const reloc_addr = reloc_addr_arg;
488 const unsigned int r_type = ELF32_R_TYPE (reloc->r_info);
490 if (ELF32_R_TYPE (reloc->r_info) == R_386_RELATIVE)
491 *reloc_addr = map->l_addr + reloc->r_addend;
492 else if (r_type != R_386_NONE)
494 # ifndef RESOLVE_CONFLICT_FIND_MAP
495 const Elf32_Sym *const refsym = sym;
496 # endif
497 struct link_map *sym_map = RESOLVE_MAP (&sym, version, r_type);
498 Elf32_Addr value = sym == NULL ? 0 : sym_map->l_addr + sym->st_value;
500 if (sym != NULL
501 && __builtin_expect (sym->st_shndx != SHN_UNDEF, 1)
502 && __builtin_expect (ELFW(ST_TYPE) (sym->st_info) == STT_GNU_IFUNC, 0)
503 && __builtin_expect (!skip_ifunc, 1))
504 value = ((Elf32_Addr (*) (void)) value) ();
506 switch (ELF32_R_TYPE (reloc->r_info))
508 case R_386_GLOB_DAT:
509 case R_386_JMP_SLOT:
510 case R_386_32:
511 *reloc_addr = value + reloc->r_addend;
512 break;
513 # ifndef RESOLVE_CONFLICT_FIND_MAP
514 /* Not needed for dl-conflict.c. */
515 case R_386_PC32:
516 *reloc_addr = (value + reloc->r_addend - (Elf32_Addr) reloc_addr);
517 break;
519 case R_386_TLS_DTPMOD32:
520 /* Get the information from the link map returned by the
521 resolv function. */
522 if (sym_map != NULL)
523 *reloc_addr = sym_map->l_tls_modid;
524 break;
525 case R_386_TLS_DTPOFF32:
526 /* During relocation all TLS symbols are defined and used.
527 Therefore the offset is already correct. */
528 *reloc_addr = (sym == NULL ? 0 : sym->st_value) + reloc->r_addend;
529 break;
530 case R_386_TLS_DESC:
532 struct tlsdesc volatile *td =
533 (struct tlsdesc volatile *)reloc_addr;
535 # ifndef RTLD_BOOTSTRAP
536 if (!sym)
538 td->arg = (void*)reloc->r_addend;
539 td->entry = _dl_tlsdesc_undefweak;
541 else
542 # endif
544 # ifndef RTLD_BOOTSTRAP
545 # ifndef SHARED
546 CHECK_STATIC_TLS (map, sym_map);
547 # else
548 if (!TRY_STATIC_TLS (map, sym_map))
550 td->arg = _dl_make_tlsdesc_dynamic
551 (sym_map, sym->st_value + reloc->r_addend);
552 td->entry = _dl_tlsdesc_dynamic;
554 else
555 # endif
556 # endif
558 td->arg = (void*)(sym->st_value - sym_map->l_tls_offset
559 + reloc->r_addend);
560 td->entry = _dl_tlsdesc_return;
564 break;
565 case R_386_TLS_TPOFF32:
566 /* The offset is positive, backward from the thread pointer. */
567 /* We know the offset of object the symbol is contained in.
568 It is a positive value which will be subtracted from the
569 thread pointer. To get the variable position in the TLS
570 block we subtract the offset from that of the TLS block. */
571 if (sym != NULL)
573 CHECK_STATIC_TLS (map, sym_map);
574 *reloc_addr = sym_map->l_tls_offset - sym->st_value
575 + reloc->r_addend;
577 break;
578 case R_386_TLS_TPOFF:
579 /* The offset is negative, forward from the thread pointer. */
580 /* We know the offset of object the symbol is contained in.
581 It is a negative value which will be added to the
582 thread pointer. */
583 if (sym != NULL)
585 CHECK_STATIC_TLS (map, sym_map);
586 *reloc_addr = sym->st_value - sym_map->l_tls_offset
587 + reloc->r_addend;
589 break;
590 case R_386_COPY:
591 if (sym == NULL)
592 /* This can happen in trace mode if an object could not be
593 found. */
594 break;
595 if (__builtin_expect (sym->st_size > refsym->st_size, 0)
596 || (__builtin_expect (sym->st_size < refsym->st_size, 0)
597 && GLRO(dl_verbose)))
599 const char *strtab;
601 strtab = (const char *) D_PTR (map, l_info[DT_STRTAB]);
602 _dl_error_printf ("\
603 %s: Symbol `%s' has different size in shared object, consider re-linking\n",
604 rtld_progname ?: "<program name unknown>",
605 strtab + refsym->st_name);
607 memcpy (reloc_addr_arg, (void *) value,
608 MIN (sym->st_size, refsym->st_size));
609 break;
610 # endif /* !RESOLVE_CONFLICT_FIND_MAP */
611 case R_386_IRELATIVE:
612 value = map->l_addr + reloc->r_addend;
613 value = ((Elf32_Addr (*) (void)) value) ();
614 *reloc_addr = value;
615 break;
616 default:
617 /* We add these checks in the version to relocate ld.so only
618 if we are still debugging. */
619 _dl_reloc_bad_type (map, r_type, 0);
620 break;
624 # endif /* !RTLD_BOOTSTRAP */
626 auto inline void
627 __attribute ((always_inline))
628 elf_machine_rel_relative (Elf32_Addr l_addr, const Elf32_Rel *reloc,
629 void *const reloc_addr_arg)
631 Elf32_Addr *const reloc_addr = reloc_addr_arg;
632 assert (ELF32_R_TYPE (reloc->r_info) == R_386_RELATIVE);
633 *reloc_addr += l_addr;
636 # ifndef RTLD_BOOTSTRAP
637 auto inline void
638 __attribute__ ((always_inline))
639 elf_machine_rela_relative (Elf32_Addr l_addr, const Elf32_Rela *reloc,
640 void *const reloc_addr_arg)
642 Elf32_Addr *const reloc_addr = reloc_addr_arg;
643 *reloc_addr = l_addr + reloc->r_addend;
645 # endif /* !RTLD_BOOTSTRAP */
647 auto inline void
648 __attribute__ ((always_inline))
649 elf_machine_lazy_rel (struct link_map *map,
650 Elf32_Addr l_addr, const Elf32_Rel *reloc,
651 int skip_ifunc)
653 Elf32_Addr *const reloc_addr = (void *) (l_addr + reloc->r_offset);
654 const unsigned int r_type = ELF32_R_TYPE (reloc->r_info);
655 /* Check for unexpected PLT reloc type. */
656 if (__builtin_expect (r_type == R_386_JMP_SLOT, 1))
658 if (__builtin_expect (map->l_mach.plt, 0) == 0)
659 *reloc_addr += l_addr;
660 else
661 *reloc_addr = (map->l_mach.plt
662 + (((Elf32_Addr) reloc_addr) - map->l_mach.gotplt) * 4);
664 else if (__builtin_expect (r_type == R_386_TLS_DESC, 1))
666 struct tlsdesc volatile * __attribute__((__unused__)) td =
667 (struct tlsdesc volatile *)reloc_addr;
669 /* Handle relocations that reference the local *ABS* in a simple
670 way, so as to preserve a potential addend. */
671 if (ELF32_R_SYM (reloc->r_info) == 0)
672 td->entry = _dl_tlsdesc_resolve_abs_plus_addend;
673 /* Given a known-zero addend, we can store a pointer to the
674 reloc in the arg position. */
675 else if (td->arg == 0)
677 td->arg = (void*)reloc;
678 td->entry = _dl_tlsdesc_resolve_rel;
680 else
682 /* We could handle non-*ABS* relocations with non-zero addends
683 by allocating dynamically an arg to hold a pointer to the
684 reloc, but that sounds pointless. */
685 const Elf32_Rel *const r = reloc;
686 /* The code below was borrowed from elf_dynamic_do_rel(). */
687 const ElfW(Sym) *const symtab =
688 (const void *) D_PTR (map, l_info[DT_SYMTAB]);
690 # ifdef RTLD_BOOTSTRAP
691 /* The dynamic linker always uses versioning. */
692 assert (map->l_info[VERSYMIDX (DT_VERSYM)] != NULL);
693 # else
694 if (map->l_info[VERSYMIDX (DT_VERSYM)])
695 # endif
697 const ElfW(Half) *const version =
698 (const void *) D_PTR (map, l_info[VERSYMIDX (DT_VERSYM)]);
699 ElfW(Half) ndx = version[ELFW(R_SYM) (r->r_info)] & 0x7fff;
700 elf_machine_rel (map, r, &symtab[ELFW(R_SYM) (r->r_info)],
701 &map->l_versions[ndx],
702 (void *) (l_addr + r->r_offset), skip_ifunc);
704 # ifndef RTLD_BOOTSTRAP
705 else
706 elf_machine_rel (map, r, &symtab[ELFW(R_SYM) (r->r_info)], NULL,
707 (void *) (l_addr + r->r_offset), skip_ifunc);
708 # endif
711 else if (__builtin_expect (r_type == R_386_IRELATIVE, 0))
713 Elf32_Addr value = map->l_addr + *reloc_addr;
714 if (__builtin_expect (!skip_ifunc, 1))
715 value = ((Elf32_Addr (*) (void)) value) ();
716 *reloc_addr = value;
718 else
719 _dl_reloc_bad_type (map, r_type, 1);
722 # ifndef RTLD_BOOTSTRAP
724 auto inline void
725 __attribute__ ((always_inline))
726 elf_machine_lazy_rela (struct link_map *map,
727 Elf32_Addr l_addr, const Elf32_Rela *reloc,
728 int skip_ifunc)
730 Elf32_Addr *const reloc_addr = (void *) (l_addr + reloc->r_offset);
731 const unsigned int r_type = ELF32_R_TYPE (reloc->r_info);
732 if (__builtin_expect (r_type == R_386_JMP_SLOT, 1))
734 else if (__builtin_expect (r_type == R_386_TLS_DESC, 1))
736 struct tlsdesc volatile * __attribute__((__unused__)) td =
737 (struct tlsdesc volatile *)reloc_addr;
739 td->arg = (void*)reloc;
740 td->entry = _dl_tlsdesc_resolve_rela;
742 else if (__builtin_expect (r_type == R_386_IRELATIVE, 0))
744 Elf32_Addr value = map->l_addr + reloc->r_addend;
745 if (__builtin_expect (!skip_ifunc, 1))
746 value = ((Elf32_Addr (*) (void)) value) ();
747 *reloc_addr = value;
749 else
750 _dl_reloc_bad_type (map, r_type, 1);
753 # endif /* !RTLD_BOOTSTRAP */
755 #endif /* RESOLVE_MAP */