Fix sparc struct fpu definition.
[glibc.git] / sysdeps / i386 / dl-machine.h
bloba3a632cda28e1cbb13dbf25dc1dc52c19982f219
1 /* Machine-dependent ELF dynamic relocation inline functions. i386 version.
2 Copyright (C) 1995-2014 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 (__glibc_unlikely (profile))
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 # ifndef PROF
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 #define ARCH_FIXUP_ATTRIBUTE __attribute__ ((regparm (3), stdcall, unused))
156 extern ElfW(Addr) _dl_fixup (struct link_map *l,
157 ElfW(Word) reloc_offset)
158 ARCH_FIXUP_ATTRIBUTE;
159 extern ElfW(Addr) _dl_profile_fixup (struct link_map *l,
160 ElfW(Word) reloc_offset,
161 ElfW(Addr) retaddr, void *regs,
162 long int *framesizep)
163 ARCH_FIXUP_ATTRIBUTE;
164 # endif
166 #endif
168 /* Mask identifying addresses reserved for the user program,
169 where the dynamic linker should not map anything. */
170 #define ELF_MACHINE_USER_ADDRESS_MASK 0xf8000000UL
172 /* Initial entry point code for the dynamic linker.
173 The C function `_dl_start' is the real entry point;
174 its return value is the user program's entry point. */
176 #define RTLD_START asm ("\n\
177 .text\n\
178 .align 16\n\
179 0: movl (%esp), %ebx\n\
180 ret\n\
181 .align 16\n\
182 .globl _start\n\
183 .globl _dl_start_user\n\
184 _start:\n\
185 # Note that _dl_start gets the parameter in %eax.\n\
186 movl %esp, %eax\n\
187 call _dl_start\n\
188 _dl_start_user:\n\
189 # Save the user entry point address in %edi.\n\
190 movl %eax, %edi\n\
191 # Point %ebx at the GOT.\n\
192 call 0b\n\
193 addl $_GLOBAL_OFFSET_TABLE_, %ebx\n\
194 # See if we were run as a command with the executable file\n\
195 # name as an extra leading argument.\n\
196 movl _dl_skip_args@GOTOFF(%ebx), %eax\n\
197 # Pop the original argument count.\n\
198 popl %edx\n\
199 # Adjust the stack pointer to skip _dl_skip_args words.\n\
200 leal (%esp,%eax,4), %esp\n\
201 # Subtract _dl_skip_args from argc.\n\
202 subl %eax, %edx\n\
203 # Push argc back on the stack.\n\
204 push %edx\n\
205 # The special initializer gets called with the stack just\n\
206 # as the application's entry point will see it; it can\n\
207 # switch stacks if it moves these contents over.\n\
208 " RTLD_START_SPECIAL_INIT "\n\
209 # Load the parameters again.\n\
210 # (eax, edx, ecx, *--esp) = (_dl_loaded, argc, argv, envp)\n\
211 movl _rtld_local@GOTOFF(%ebx), %eax\n\
212 leal 8(%esp,%edx,4), %esi\n\
213 leal 4(%esp), %ecx\n\
214 movl %esp, %ebp\n\
215 # Make sure _dl_init is run with 16 byte aligned stack.\n\
216 andl $-16, %esp\n\
217 pushl %eax\n\
218 pushl %eax\n\
219 pushl %ebp\n\
220 pushl %esi\n\
221 # Clear %ebp, so that even constructors have terminated backchain.\n\
222 xorl %ebp, %ebp\n\
223 # Call the function to run the initializers.\n\
224 call _dl_init_internal@PLT\n\
225 # Pass our finalizer function to the user in %edx, as per ELF ABI.\n\
226 leal _dl_fini@GOTOFF(%ebx), %edx\n\
227 # Restore %esp _start expects.\n\
228 movl (%esp), %esp\n\
229 # Jump to the user's entry point.\n\
230 jmp *%edi\n\
231 .previous\n\
234 #ifndef RTLD_START_SPECIAL_INIT
235 # define RTLD_START_SPECIAL_INIT /* nothing */
236 #endif
238 /* ELF_RTYPE_CLASS_PLT iff TYPE describes relocation of a PLT entry or
239 TLS variable, so undefined references should not be allowed to
240 define the value.
241 ELF_RTYPE_CLASS_NOCOPY iff TYPE should not be allowed to resolve to one
242 of the main executable's symbols, as for a COPY reloc. */
243 # define elf_machine_type_class(type) \
244 ((((type) == R_386_JMP_SLOT || (type) == R_386_TLS_DTPMOD32 \
245 || (type) == R_386_TLS_DTPOFF32 || (type) == R_386_TLS_TPOFF32 \
246 || (type) == R_386_TLS_TPOFF || (type) == R_386_TLS_DESC) \
247 * ELF_RTYPE_CLASS_PLT) \
248 | (((type) == R_386_COPY) * ELF_RTYPE_CLASS_COPY))
250 /* A reloc type used for ld.so cmdline arg lookups to reject PLT entries. */
251 #define ELF_MACHINE_JMP_SLOT R_386_JMP_SLOT
253 /* The i386 never uses Elf32_Rela relocations for the dynamic linker.
254 Prelinked libraries may use Elf32_Rela though. */
255 #define ELF_MACHINE_PLT_REL 1
257 /* We define an initialization functions. This is called very early in
258 _dl_sysdep_start. */
259 #define DL_PLATFORM_INIT dl_platform_init ()
261 static inline void __attribute__ ((unused))
262 dl_platform_init (void)
264 if (GLRO(dl_platform) != NULL && *GLRO(dl_platform) == '\0')
265 /* Avoid an empty string which would disturb us. */
266 GLRO(dl_platform) = NULL;
269 static inline Elf32_Addr
270 elf_machine_fixup_plt (struct link_map *map, lookup_t t,
271 const Elf32_Rel *reloc,
272 Elf32_Addr *reloc_addr, Elf32_Addr value)
274 return *reloc_addr = value;
277 /* Return the final value of a plt relocation. */
278 static inline Elf32_Addr
279 elf_machine_plt_value (struct link_map *map, const Elf32_Rel *reloc,
280 Elf32_Addr value)
282 return value;
286 /* Names of the architecture-specific auditing callback functions. */
287 #define ARCH_LA_PLTENTER i86_gnu_pltenter
288 #define ARCH_LA_PLTEXIT i86_gnu_pltexit
290 #endif /* !dl_machine_h */
292 /* The i386 never uses Elf32_Rela relocations for the dynamic linker.
293 Prelinked libraries may use Elf32_Rela though. */
294 #define ELF_MACHINE_NO_RELA defined RTLD_BOOTSTRAP
295 #define ELF_MACHINE_NO_REL 0
297 #ifdef RESOLVE_MAP
299 /* Perform the relocation specified by RELOC and SYM (which is fully resolved).
300 MAP is the object containing the reloc. */
302 auto inline void
303 __attribute ((always_inline))
304 elf_machine_rel (struct link_map *map, const Elf32_Rel *reloc,
305 const Elf32_Sym *sym, const struct r_found_version *version,
306 void *const reloc_addr_arg, int skip_ifunc)
308 Elf32_Addr *const reloc_addr = reloc_addr_arg;
309 const unsigned int r_type = ELF32_R_TYPE (reloc->r_info);
311 # if !defined RTLD_BOOTSTRAP || !defined HAVE_Z_COMBRELOC
312 if (__glibc_unlikely (r_type == R_386_RELATIVE))
314 # if !defined RTLD_BOOTSTRAP && !defined HAVE_Z_COMBRELOC
315 /* This is defined in rtld.c, but nowhere in the static libc.a;
316 make the reference weak so static programs can still link.
317 This declaration cannot be done when compiling rtld.c
318 (i.e. #ifdef RTLD_BOOTSTRAP) because rtld.c contains the
319 common defn for _dl_rtld_map, which is incompatible with a
320 weak decl in the same file. */
321 # ifndef SHARED
322 weak_extern (_dl_rtld_map);
323 # endif
324 if (map != &GL(dl_rtld_map)) /* Already done in rtld itself. */
325 # endif
326 *reloc_addr += map->l_addr;
328 # ifndef RTLD_BOOTSTRAP
329 else if (__glibc_unlikely (r_type == R_386_NONE))
330 return;
331 # endif
332 else
333 # endif /* !RTLD_BOOTSTRAP and have no -z combreloc */
335 # ifndef RTLD_BOOTSTRAP
336 const Elf32_Sym *const refsym = sym;
337 # endif
338 struct link_map *sym_map = RESOLVE_MAP (&sym, version, r_type);
339 Elf32_Addr value = sym_map == NULL ? 0 : sym_map->l_addr + sym->st_value;
341 if (sym != NULL
342 && __builtin_expect (ELFW(ST_TYPE) (sym->st_info) == STT_GNU_IFUNC,
344 && __builtin_expect (sym->st_shndx != SHN_UNDEF, 1)
345 && __builtin_expect (!skip_ifunc, 1))
346 value = ((Elf32_Addr (*) (void)) value) ();
348 switch (r_type)
350 # ifndef RTLD_BOOTSTRAP
351 case R_386_SIZE32:
352 /* Set to symbol size plus addend. */
353 *reloc_addr += sym->st_size;
354 break;
355 # endif
356 case R_386_GLOB_DAT:
357 case R_386_JMP_SLOT:
358 *reloc_addr = value;
359 break;
361 case R_386_TLS_DTPMOD32:
362 # ifdef RTLD_BOOTSTRAP
363 /* During startup the dynamic linker is always the module
364 with index 1.
365 XXX If this relocation is necessary move before RESOLVE
366 call. */
367 *reloc_addr = 1;
368 # else
369 /* Get the information from the link map returned by the
370 resolv function. */
371 if (sym_map != NULL)
372 *reloc_addr = sym_map->l_tls_modid;
373 # endif
374 break;
375 case R_386_TLS_DTPOFF32:
376 # ifndef RTLD_BOOTSTRAP
377 /* During relocation all TLS symbols are defined and used.
378 Therefore the offset is already correct. */
379 if (sym != NULL)
380 *reloc_addr = sym->st_value;
381 # endif
382 break;
383 case R_386_TLS_DESC:
385 struct tlsdesc volatile *td =
386 (struct tlsdesc volatile *)reloc_addr;
388 # ifndef RTLD_BOOTSTRAP
389 if (! sym)
390 td->entry = _dl_tlsdesc_undefweak;
391 else
392 # endif
394 # ifndef RTLD_BOOTSTRAP
395 # ifndef SHARED
396 CHECK_STATIC_TLS (map, sym_map);
397 # else
398 if (!TRY_STATIC_TLS (map, sym_map))
400 td->arg = _dl_make_tlsdesc_dynamic
401 (sym_map, sym->st_value + (ElfW(Word))td->arg);
402 td->entry = _dl_tlsdesc_dynamic;
404 else
405 # endif
406 # endif
408 td->arg = (void*)(sym->st_value - sym_map->l_tls_offset
409 + (ElfW(Word))td->arg);
410 td->entry = _dl_tlsdesc_return;
413 break;
415 case R_386_TLS_TPOFF32:
416 /* The offset is positive, backward from the thread pointer. */
417 # ifdef RTLD_BOOTSTRAP
418 *reloc_addr += map->l_tls_offset - sym->st_value;
419 # else
420 /* We know the offset of object the symbol is contained in.
421 It is a positive value which will be subtracted from the
422 thread pointer. To get the variable position in the TLS
423 block we subtract the offset from that of the TLS block. */
424 if (sym != NULL)
426 CHECK_STATIC_TLS (map, sym_map);
427 *reloc_addr += sym_map->l_tls_offset - sym->st_value;
429 # endif
430 break;
431 case R_386_TLS_TPOFF:
432 /* The offset is negative, forward from the thread pointer. */
433 # ifdef RTLD_BOOTSTRAP
434 *reloc_addr += sym->st_value - map->l_tls_offset;
435 # else
436 /* We know the offset of object the symbol is contained in.
437 It is a negative value which will be added to the
438 thread pointer. */
439 if (sym != NULL)
441 CHECK_STATIC_TLS (map, sym_map);
442 *reloc_addr += sym->st_value - sym_map->l_tls_offset;
444 # endif
445 break;
447 # ifndef RTLD_BOOTSTRAP
448 case R_386_32:
449 *reloc_addr += value;
450 break;
451 case R_386_PC32:
452 *reloc_addr += (value - (Elf32_Addr) reloc_addr);
453 break;
454 case R_386_COPY:
455 if (sym == NULL)
456 /* This can happen in trace mode if an object could not be
457 found. */
458 break;
459 if (__builtin_expect (sym->st_size > refsym->st_size, 0)
460 || (__builtin_expect (sym->st_size < refsym->st_size, 0)
461 && GLRO(dl_verbose)))
463 const char *strtab;
465 strtab = (const char *) D_PTR (map, l_info[DT_STRTAB]);
466 _dl_error_printf ("\
467 %s: Symbol `%s' has different size in shared object, consider re-linking\n",
468 RTLD_PROGNAME, strtab + refsym->st_name);
470 memcpy (reloc_addr_arg, (void *) value,
471 MIN (sym->st_size, refsym->st_size));
472 break;
473 case R_386_IRELATIVE:
474 value = map->l_addr + *reloc_addr;
475 value = ((Elf32_Addr (*) (void)) value) ();
476 *reloc_addr = value;
477 break;
478 default:
479 _dl_reloc_bad_type (map, r_type, 0);
480 break;
481 # endif /* !RTLD_BOOTSTRAP */
486 # ifndef RTLD_BOOTSTRAP
487 auto inline void
488 __attribute__ ((always_inline))
489 elf_machine_rela (struct link_map *map, const Elf32_Rela *reloc,
490 const Elf32_Sym *sym, const struct r_found_version *version,
491 void *const reloc_addr_arg, int skip_ifunc)
493 Elf32_Addr *const reloc_addr = reloc_addr_arg;
494 const unsigned int r_type = ELF32_R_TYPE (reloc->r_info);
496 if (ELF32_R_TYPE (reloc->r_info) == R_386_RELATIVE)
497 *reloc_addr = map->l_addr + reloc->r_addend;
498 else if (r_type != R_386_NONE)
500 # ifndef RESOLVE_CONFLICT_FIND_MAP
501 const Elf32_Sym *const refsym = sym;
502 # endif
503 struct link_map *sym_map = RESOLVE_MAP (&sym, version, r_type);
504 Elf32_Addr value = sym == NULL ? 0 : sym_map->l_addr + sym->st_value;
506 if (sym != NULL
507 && __builtin_expect (sym->st_shndx != SHN_UNDEF, 1)
508 && __builtin_expect (ELFW(ST_TYPE) (sym->st_info) == STT_GNU_IFUNC, 0)
509 && __builtin_expect (!skip_ifunc, 1))
510 value = ((Elf32_Addr (*) (void)) value) ();
512 switch (ELF32_R_TYPE (reloc->r_info))
514 case R_386_SIZE32:
515 /* Set to symbol size plus addend. */
516 value = sym->st_size;
517 case R_386_GLOB_DAT:
518 case R_386_JMP_SLOT:
519 case R_386_32:
520 *reloc_addr = value + reloc->r_addend;
521 break;
522 # ifndef RESOLVE_CONFLICT_FIND_MAP
523 /* Not needed for dl-conflict.c. */
524 case R_386_PC32:
525 *reloc_addr = (value + reloc->r_addend - (Elf32_Addr) reloc_addr);
526 break;
528 case R_386_TLS_DTPMOD32:
529 /* Get the information from the link map returned by the
530 resolv function. */
531 if (sym_map != NULL)
532 *reloc_addr = sym_map->l_tls_modid;
533 break;
534 case R_386_TLS_DTPOFF32:
535 /* During relocation all TLS symbols are defined and used.
536 Therefore the offset is already correct. */
537 *reloc_addr = (sym == NULL ? 0 : sym->st_value) + reloc->r_addend;
538 break;
539 case R_386_TLS_DESC:
541 struct tlsdesc volatile *td =
542 (struct tlsdesc volatile *)reloc_addr;
544 # ifndef RTLD_BOOTSTRAP
545 if (!sym)
547 td->arg = (void*)reloc->r_addend;
548 td->entry = _dl_tlsdesc_undefweak;
550 else
551 # endif
553 # ifndef RTLD_BOOTSTRAP
554 # ifndef SHARED
555 CHECK_STATIC_TLS (map, sym_map);
556 # else
557 if (!TRY_STATIC_TLS (map, sym_map))
559 td->arg = _dl_make_tlsdesc_dynamic
560 (sym_map, sym->st_value + reloc->r_addend);
561 td->entry = _dl_tlsdesc_dynamic;
563 else
564 # endif
565 # endif
567 td->arg = (void*)(sym->st_value - sym_map->l_tls_offset
568 + reloc->r_addend);
569 td->entry = _dl_tlsdesc_return;
573 break;
574 case R_386_TLS_TPOFF32:
575 /* The offset is positive, backward from the thread pointer. */
576 /* We know the offset of object the symbol is contained in.
577 It is a positive value which will be subtracted from the
578 thread pointer. To get the variable position in the TLS
579 block we subtract the offset from that of the TLS block. */
580 if (sym != NULL)
582 CHECK_STATIC_TLS (map, sym_map);
583 *reloc_addr = sym_map->l_tls_offset - sym->st_value
584 + reloc->r_addend;
586 break;
587 case R_386_TLS_TPOFF:
588 /* The offset is negative, forward from the thread pointer. */
589 /* We know the offset of object the symbol is contained in.
590 It is a negative value which will be added to the
591 thread pointer. */
592 if (sym != NULL)
594 CHECK_STATIC_TLS (map, sym_map);
595 *reloc_addr = sym->st_value - sym_map->l_tls_offset
596 + reloc->r_addend;
598 break;
599 case R_386_COPY:
600 if (sym == NULL)
601 /* This can happen in trace mode if an object could not be
602 found. */
603 break;
604 if (__builtin_expect (sym->st_size > refsym->st_size, 0)
605 || (__builtin_expect (sym->st_size < refsym->st_size, 0)
606 && GLRO(dl_verbose)))
608 const char *strtab;
610 strtab = (const char *) D_PTR (map, l_info[DT_STRTAB]);
611 _dl_error_printf ("\
612 %s: Symbol `%s' has different size in shared object, consider re-linking\n",
613 RTLD_PROGNAME, strtab + refsym->st_name);
615 memcpy (reloc_addr_arg, (void *) value,
616 MIN (sym->st_size, refsym->st_size));
617 break;
618 # endif /* !RESOLVE_CONFLICT_FIND_MAP */
619 case R_386_IRELATIVE:
620 value = map->l_addr + reloc->r_addend;
621 value = ((Elf32_Addr (*) (void)) value) ();
622 *reloc_addr = value;
623 break;
624 default:
625 /* We add these checks in the version to relocate ld.so only
626 if we are still debugging. */
627 _dl_reloc_bad_type (map, r_type, 0);
628 break;
632 # endif /* !RTLD_BOOTSTRAP */
634 auto inline void
635 __attribute ((always_inline))
636 elf_machine_rel_relative (Elf32_Addr l_addr, const Elf32_Rel *reloc,
637 void *const reloc_addr_arg)
639 Elf32_Addr *const reloc_addr = reloc_addr_arg;
640 assert (ELF32_R_TYPE (reloc->r_info) == R_386_RELATIVE);
641 *reloc_addr += l_addr;
644 # ifndef RTLD_BOOTSTRAP
645 auto inline void
646 __attribute__ ((always_inline))
647 elf_machine_rela_relative (Elf32_Addr l_addr, const Elf32_Rela *reloc,
648 void *const reloc_addr_arg)
650 Elf32_Addr *const reloc_addr = reloc_addr_arg;
651 *reloc_addr = l_addr + reloc->r_addend;
653 # endif /* !RTLD_BOOTSTRAP */
655 auto inline void
656 __attribute__ ((always_inline))
657 elf_machine_lazy_rel (struct link_map *map,
658 Elf32_Addr l_addr, const Elf32_Rel *reloc,
659 int skip_ifunc)
661 Elf32_Addr *const reloc_addr = (void *) (l_addr + reloc->r_offset);
662 const unsigned int r_type = ELF32_R_TYPE (reloc->r_info);
663 /* Check for unexpected PLT reloc type. */
664 if (__glibc_likely (r_type == R_386_JMP_SLOT))
666 if (__builtin_expect (map->l_mach.plt, 0) == 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 */