conformtest: clean up POSIX expectations for unistd.h.
[glibc.git] / sysdeps / i386 / dl-machine.h
blob04f9247bfa00ab1fdb20f837a7f8c68be6ede78f
1 /* Machine-dependent ELF dynamic relocation inline functions. i386 version.
2 Copyright (C) 1995-2015 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 /* Return the link-time address of _DYNAMIC. Conveniently, this is the
38 first element of the GOT, a special entry that is never relocated. */
39 static inline Elf32_Addr __attribute__ ((unused, const))
40 elf_machine_dynamic (void)
42 /* This produces a GOTOFF reloc that resolves to zero at link time, so in
43 fact just loads from the GOT register directly. By doing it without
44 an asm we can let the compiler choose any register. */
45 extern const Elf32_Addr _GLOBAL_OFFSET_TABLE_[] attribute_hidden;
46 return _GLOBAL_OFFSET_TABLE_[0];
49 /* Return the run-time load address of the shared object. */
50 static inline Elf32_Addr __attribute__ ((unused))
51 elf_machine_load_address (void)
53 /* Compute the difference between the runtime address of _DYNAMIC as seen
54 by a GOTOFF reference, and the link-time address found in the special
55 unrelocated first GOT entry. */
56 extern Elf32_Dyn bygotoff[] asm ("_DYNAMIC") attribute_hidden;
57 return (Elf32_Addr) &bygotoff - elf_machine_dynamic ();
60 /* Set up the loaded object described by L so its unrelocated PLT
61 entries will jump to the on-demand fixup code in dl-runtime.c. */
63 static inline int __attribute__ ((unused, always_inline))
64 elf_machine_runtime_setup (struct link_map *l, int lazy, int profile)
66 Elf32_Addr *got;
67 extern void _dl_runtime_resolve (Elf32_Word) attribute_hidden;
68 extern void _dl_runtime_profile (Elf32_Word) attribute_hidden;
70 if (l->l_info[DT_JMPREL] && lazy)
72 /* The GOT entries for functions in the PLT have not yet been filled
73 in. Their initial contents will arrange when called to push an
74 offset into the .rel.plt section, push _GLOBAL_OFFSET_TABLE_[1],
75 and then jump to _GLOBAL_OFFSET_TABLE[2]. */
76 got = (Elf32_Addr *) D_PTR (l, l_info[DT_PLTGOT]);
77 /* If a library is prelinked but we have to relocate anyway,
78 we have to be able to undo the prelinking of .got.plt.
79 The prelinker saved us here address of .plt + 0x16. */
80 if (got[1])
82 l->l_mach.plt = got[1] + l->l_addr;
83 l->l_mach.gotplt = (Elf32_Addr) &got[3];
85 got[1] = (Elf32_Addr) l; /* Identify this shared object. */
87 /* The got[2] entry contains the address of a function which gets
88 called to get the address of a so far unresolved function and
89 jump to it. The profiling extension of the dynamic linker allows
90 to intercept the calls to collect information. In this case we
91 don't store the address in the GOT so that all future calls also
92 end in this function. */
93 if (__glibc_unlikely (profile))
95 got[2] = (Elf32_Addr) &_dl_runtime_profile;
97 if (GLRO(dl_profile) != NULL
98 && _dl_name_match_p (GLRO(dl_profile), l))
99 /* This is the object we are looking for. Say that we really
100 want profiling and the timers are started. */
101 GL(dl_profile_map) = l;
103 else
104 /* This function will get called to fix up the GOT entry indicated by
105 the offset on the stack, and then jump to the resolved address. */
106 got[2] = (Elf32_Addr) &_dl_runtime_resolve;
109 return lazy;
112 #ifdef IN_DL_RUNTIME
114 # ifndef PROF
115 /* We add a declaration of this function here so that in dl-runtime.c
116 the ELF_MACHINE_RUNTIME_TRAMPOLINE macro really can pass the parameters
117 in registers.
119 We cannot use this scheme for profiling because the _mcount call
120 destroys the passed register information. */
121 #define ARCH_FIXUP_ATTRIBUTE __attribute__ ((regparm (3), stdcall, unused))
123 extern ElfW(Addr) _dl_fixup (struct link_map *l,
124 ElfW(Word) reloc_offset)
125 ARCH_FIXUP_ATTRIBUTE;
126 extern ElfW(Addr) _dl_profile_fixup (struct link_map *l,
127 ElfW(Word) reloc_offset,
128 ElfW(Addr) retaddr, void *regs,
129 long int *framesizep)
130 ARCH_FIXUP_ATTRIBUTE;
131 # endif
133 #endif
135 /* Mask identifying addresses reserved for the user program,
136 where the dynamic linker should not map anything. */
137 #define ELF_MACHINE_USER_ADDRESS_MASK 0xf8000000UL
139 /* Initial entry point code for the dynamic linker.
140 The C function `_dl_start' is the real entry point;
141 its return value is the user program's entry point. */
143 #define RTLD_START asm ("\n\
144 .text\n\
145 .align 16\n\
146 0: movl (%esp), %ebx\n\
147 ret\n\
148 .align 16\n\
149 .globl _start\n\
150 .globl _dl_start_user\n\
151 _start:\n\
152 # Note that _dl_start gets the parameter in %eax.\n\
153 movl %esp, %eax\n\
154 call _dl_start\n\
155 _dl_start_user:\n\
156 # Save the user entry point address in %edi.\n\
157 movl %eax, %edi\n\
158 # Point %ebx at the GOT.\n\
159 call 0b\n\
160 addl $_GLOBAL_OFFSET_TABLE_, %ebx\n\
161 # See if we were run as a command with the executable file\n\
162 # name as an extra leading argument.\n\
163 movl _dl_skip_args@GOTOFF(%ebx), %eax\n\
164 # Pop the original argument count.\n\
165 popl %edx\n\
166 # Adjust the stack pointer to skip _dl_skip_args words.\n\
167 leal (%esp,%eax,4), %esp\n\
168 # Subtract _dl_skip_args from argc.\n\
169 subl %eax, %edx\n\
170 # Push argc back on the stack.\n\
171 push %edx\n\
172 # The special initializer gets called with the stack just\n\
173 # as the application's entry point will see it; it can\n\
174 # switch stacks if it moves these contents over.\n\
175 " RTLD_START_SPECIAL_INIT "\n\
176 # Load the parameters again.\n\
177 # (eax, edx, ecx, *--esp) = (_dl_loaded, argc, argv, envp)\n\
178 movl _rtld_local@GOTOFF(%ebx), %eax\n\
179 leal 8(%esp,%edx,4), %esi\n\
180 leal 4(%esp), %ecx\n\
181 movl %esp, %ebp\n\
182 # Make sure _dl_init is run with 16 byte aligned stack.\n\
183 andl $-16, %esp\n\
184 pushl %eax\n\
185 pushl %eax\n\
186 pushl %ebp\n\
187 pushl %esi\n\
188 # Clear %ebp, so that even constructors have terminated backchain.\n\
189 xorl %ebp, %ebp\n\
190 # Call the function to run the initializers.\n\
191 call _dl_init\n\
192 # Pass our finalizer function to the user in %edx, as per ELF ABI.\n\
193 leal _dl_fini@GOTOFF(%ebx), %edx\n\
194 # Restore %esp _start expects.\n\
195 movl (%esp), %esp\n\
196 # Jump to the user's entry point.\n\
197 jmp *%edi\n\
198 .previous\n\
201 #ifndef RTLD_START_SPECIAL_INIT
202 # define RTLD_START_SPECIAL_INIT /* nothing */
203 #endif
205 /* ELF_RTYPE_CLASS_PLT iff TYPE describes relocation of a PLT entry or
206 TLS variable, so undefined references should not be allowed to
207 define the value.
208 ELF_RTYPE_CLASS_COPY iff TYPE should not be allowed to resolve to one
209 of the main executable's symbols, as for a COPY reloc.
210 ELF_RTYPE_CLASS_EXTERN_PROTECTED_DATA iff TYPE describes relocation may
211 against protected data whose address be external due to copy relocation.
213 # define elf_machine_type_class(type) \
214 ((((type) == R_386_JMP_SLOT || (type) == R_386_TLS_DTPMOD32 \
215 || (type) == R_386_TLS_DTPOFF32 || (type) == R_386_TLS_TPOFF32 \
216 || (type) == R_386_TLS_TPOFF || (type) == R_386_TLS_DESC) \
217 * ELF_RTYPE_CLASS_PLT) \
218 | (((type) == R_386_COPY) * ELF_RTYPE_CLASS_COPY) \
219 | (((type) == R_386_GLOB_DAT) * ELF_RTYPE_CLASS_EXTERN_PROTECTED_DATA))
221 /* A reloc type used for ld.so cmdline arg lookups to reject PLT entries. */
222 #define ELF_MACHINE_JMP_SLOT R_386_JMP_SLOT
224 /* The i386 never uses Elf32_Rela relocations for the dynamic linker.
225 Prelinked libraries may use Elf32_Rela though. */
226 #define ELF_MACHINE_PLT_REL 1
228 /* We define an initialization functions. This is called very early in
229 _dl_sysdep_start. */
230 #define DL_PLATFORM_INIT dl_platform_init ()
232 static inline void __attribute__ ((unused))
233 dl_platform_init (void)
235 if (GLRO(dl_platform) != NULL && *GLRO(dl_platform) == '\0')
236 /* Avoid an empty string which would disturb us. */
237 GLRO(dl_platform) = NULL;
240 static inline Elf32_Addr
241 elf_machine_fixup_plt (struct link_map *map, lookup_t t,
242 const Elf32_Rel *reloc,
243 Elf32_Addr *reloc_addr, Elf32_Addr value)
245 return *reloc_addr = value;
248 /* Return the final value of a plt relocation. */
249 static inline Elf32_Addr
250 elf_machine_plt_value (struct link_map *map, const Elf32_Rel *reloc,
251 Elf32_Addr value)
253 return value;
257 /* Names of the architecture-specific auditing callback functions. */
258 #define ARCH_LA_PLTENTER i86_gnu_pltenter
259 #define ARCH_LA_PLTEXIT i86_gnu_pltexit
261 #endif /* !dl_machine_h */
263 /* The i386 never uses Elf32_Rela relocations for the dynamic linker.
264 Prelinked libraries may use Elf32_Rela though. */
265 #define ELF_MACHINE_NO_RELA defined RTLD_BOOTSTRAP
266 #define ELF_MACHINE_NO_REL 0
268 #ifdef RESOLVE_MAP
270 /* Perform the relocation specified by RELOC and SYM (which is fully resolved).
271 MAP is the object containing the reloc. */
273 auto inline void
274 __attribute ((always_inline))
275 elf_machine_rel (struct link_map *map, const Elf32_Rel *reloc,
276 const Elf32_Sym *sym, const struct r_found_version *version,
277 void *const reloc_addr_arg, int skip_ifunc)
279 Elf32_Addr *const reloc_addr = reloc_addr_arg;
280 const unsigned int r_type = ELF32_R_TYPE (reloc->r_info);
282 # if !defined RTLD_BOOTSTRAP || !defined HAVE_Z_COMBRELOC
283 if (__glibc_unlikely (r_type == R_386_RELATIVE))
285 # if !defined RTLD_BOOTSTRAP && !defined HAVE_Z_COMBRELOC
286 /* This is defined in rtld.c, but nowhere in the static libc.a;
287 make the reference weak so static programs can still link.
288 This declaration cannot be done when compiling rtld.c
289 (i.e. #ifdef RTLD_BOOTSTRAP) because rtld.c contains the
290 common defn for _dl_rtld_map, which is incompatible with a
291 weak decl in the same file. */
292 # ifndef SHARED
293 weak_extern (_dl_rtld_map);
294 # endif
295 if (map != &GL(dl_rtld_map)) /* Already done in rtld itself. */
296 # endif
297 *reloc_addr += map->l_addr;
299 # ifndef RTLD_BOOTSTRAP
300 else if (__glibc_unlikely (r_type == R_386_NONE))
301 return;
302 # endif
303 else
304 # endif /* !RTLD_BOOTSTRAP and have no -z combreloc */
306 # ifndef RTLD_BOOTSTRAP
307 const Elf32_Sym *const refsym = sym;
308 # endif
309 struct link_map *sym_map = RESOLVE_MAP (&sym, version, r_type);
310 Elf32_Addr value = sym_map == NULL ? 0 : sym_map->l_addr + sym->st_value;
312 if (sym != NULL
313 && __builtin_expect (ELFW(ST_TYPE) (sym->st_info) == STT_GNU_IFUNC,
315 && __builtin_expect (sym->st_shndx != SHN_UNDEF, 1)
316 && __builtin_expect (!skip_ifunc, 1))
317 value = ((Elf32_Addr (*) (void)) value) ();
319 switch (r_type)
321 # ifndef RTLD_BOOTSTRAP
322 case R_386_SIZE32:
323 /* Set to symbol size plus addend. */
324 *reloc_addr += sym->st_size;
325 break;
326 # endif
327 case R_386_GLOB_DAT:
328 case R_386_JMP_SLOT:
329 *reloc_addr = value;
330 break;
332 case R_386_TLS_DTPMOD32:
333 # ifdef RTLD_BOOTSTRAP
334 /* During startup the dynamic linker is always the module
335 with index 1.
336 XXX If this relocation is necessary move before RESOLVE
337 call. */
338 *reloc_addr = 1;
339 # else
340 /* Get the information from the link map returned by the
341 resolv function. */
342 if (sym_map != NULL)
343 *reloc_addr = sym_map->l_tls_modid;
344 # endif
345 break;
346 case R_386_TLS_DTPOFF32:
347 # ifndef RTLD_BOOTSTRAP
348 /* During relocation all TLS symbols are defined and used.
349 Therefore the offset is already correct. */
350 if (sym != NULL)
351 *reloc_addr = sym->st_value;
352 # endif
353 break;
354 case R_386_TLS_DESC:
356 struct tlsdesc volatile *td =
357 (struct tlsdesc volatile *)reloc_addr;
359 # ifndef RTLD_BOOTSTRAP
360 if (! sym)
361 td->entry = _dl_tlsdesc_undefweak;
362 else
363 # endif
365 # ifndef RTLD_BOOTSTRAP
366 # ifndef SHARED
367 CHECK_STATIC_TLS (map, sym_map);
368 # else
369 if (!TRY_STATIC_TLS (map, sym_map))
371 td->arg = _dl_make_tlsdesc_dynamic
372 (sym_map, sym->st_value + (ElfW(Word))td->arg);
373 td->entry = _dl_tlsdesc_dynamic;
375 else
376 # endif
377 # endif
379 td->arg = (void*)(sym->st_value - sym_map->l_tls_offset
380 + (ElfW(Word))td->arg);
381 td->entry = _dl_tlsdesc_return;
384 break;
386 case R_386_TLS_TPOFF32:
387 /* The offset is positive, backward from the thread pointer. */
388 # ifdef RTLD_BOOTSTRAP
389 *reloc_addr += map->l_tls_offset - sym->st_value;
390 # else
391 /* We know the offset of object the symbol is contained in.
392 It is a positive value which will be subtracted from the
393 thread pointer. To get the variable position in the TLS
394 block we subtract the offset from that of the TLS block. */
395 if (sym != NULL)
397 CHECK_STATIC_TLS (map, sym_map);
398 *reloc_addr += sym_map->l_tls_offset - sym->st_value;
400 # endif
401 break;
402 case R_386_TLS_TPOFF:
403 /* The offset is negative, forward from the thread pointer. */
404 # ifdef RTLD_BOOTSTRAP
405 *reloc_addr += sym->st_value - map->l_tls_offset;
406 # else
407 /* We know the offset of object the symbol is contained in.
408 It is a negative value which will be added to the
409 thread pointer. */
410 if (sym != NULL)
412 CHECK_STATIC_TLS (map, sym_map);
413 *reloc_addr += sym->st_value - sym_map->l_tls_offset;
415 # endif
416 break;
418 # ifndef RTLD_BOOTSTRAP
419 case R_386_32:
420 *reloc_addr += value;
421 break;
422 case R_386_PC32:
423 *reloc_addr += (value - (Elf32_Addr) reloc_addr);
424 break;
425 case R_386_COPY:
426 if (sym == NULL)
427 /* This can happen in trace mode if an object could not be
428 found. */
429 break;
430 if (__builtin_expect (sym->st_size > refsym->st_size, 0)
431 || (__builtin_expect (sym->st_size < refsym->st_size, 0)
432 && GLRO(dl_verbose)))
434 const char *strtab;
436 strtab = (const char *) D_PTR (map, l_info[DT_STRTAB]);
437 _dl_error_printf ("\
438 %s: Symbol `%s' has different size in shared object, consider re-linking\n",
439 RTLD_PROGNAME, strtab + refsym->st_name);
441 memcpy (reloc_addr_arg, (void *) value,
442 MIN (sym->st_size, refsym->st_size));
443 break;
444 case R_386_IRELATIVE:
445 value = map->l_addr + *reloc_addr;
446 value = ((Elf32_Addr (*) (void)) value) ();
447 *reloc_addr = value;
448 break;
449 default:
450 _dl_reloc_bad_type (map, r_type, 0);
451 break;
452 # endif /* !RTLD_BOOTSTRAP */
457 # ifndef RTLD_BOOTSTRAP
458 auto inline void
459 __attribute__ ((always_inline))
460 elf_machine_rela (struct link_map *map, const Elf32_Rela *reloc,
461 const Elf32_Sym *sym, const struct r_found_version *version,
462 void *const reloc_addr_arg, int skip_ifunc)
464 Elf32_Addr *const reloc_addr = reloc_addr_arg;
465 const unsigned int r_type = ELF32_R_TYPE (reloc->r_info);
467 if (ELF32_R_TYPE (reloc->r_info) == R_386_RELATIVE)
468 *reloc_addr = map->l_addr + reloc->r_addend;
469 else if (r_type != R_386_NONE)
471 # ifndef RESOLVE_CONFLICT_FIND_MAP
472 const Elf32_Sym *const refsym = sym;
473 # endif
474 struct link_map *sym_map = RESOLVE_MAP (&sym, version, r_type);
475 Elf32_Addr value = sym == NULL ? 0 : sym_map->l_addr + sym->st_value;
477 if (sym != NULL
478 && __builtin_expect (sym->st_shndx != SHN_UNDEF, 1)
479 && __builtin_expect (ELFW(ST_TYPE) (sym->st_info) == STT_GNU_IFUNC, 0)
480 && __builtin_expect (!skip_ifunc, 1))
481 value = ((Elf32_Addr (*) (void)) value) ();
483 switch (ELF32_R_TYPE (reloc->r_info))
485 case R_386_SIZE32:
486 /* Set to symbol size plus addend. */
487 value = sym->st_size;
488 case R_386_GLOB_DAT:
489 case R_386_JMP_SLOT:
490 case R_386_32:
491 *reloc_addr = value + reloc->r_addend;
492 break;
493 # ifndef RESOLVE_CONFLICT_FIND_MAP
494 /* Not needed for dl-conflict.c. */
495 case R_386_PC32:
496 *reloc_addr = (value + reloc->r_addend - (Elf32_Addr) reloc_addr);
497 break;
499 case R_386_TLS_DTPMOD32:
500 /* Get the information from the link map returned by the
501 resolv function. */
502 if (sym_map != NULL)
503 *reloc_addr = sym_map->l_tls_modid;
504 break;
505 case R_386_TLS_DTPOFF32:
506 /* During relocation all TLS symbols are defined and used.
507 Therefore the offset is already correct. */
508 *reloc_addr = (sym == NULL ? 0 : sym->st_value) + reloc->r_addend;
509 break;
510 case R_386_TLS_DESC:
512 struct tlsdesc volatile *td =
513 (struct tlsdesc volatile *)reloc_addr;
515 # ifndef RTLD_BOOTSTRAP
516 if (!sym)
518 td->arg = (void*)reloc->r_addend;
519 td->entry = _dl_tlsdesc_undefweak;
521 else
522 # endif
524 # ifndef RTLD_BOOTSTRAP
525 # ifndef SHARED
526 CHECK_STATIC_TLS (map, sym_map);
527 # else
528 if (!TRY_STATIC_TLS (map, sym_map))
530 td->arg = _dl_make_tlsdesc_dynamic
531 (sym_map, sym->st_value + reloc->r_addend);
532 td->entry = _dl_tlsdesc_dynamic;
534 else
535 # endif
536 # endif
538 td->arg = (void*)(sym->st_value - sym_map->l_tls_offset
539 + reloc->r_addend);
540 td->entry = _dl_tlsdesc_return;
544 break;
545 case R_386_TLS_TPOFF32:
546 /* The offset is positive, backward from the thread pointer. */
547 /* We know the offset of object the symbol is contained in.
548 It is a positive value which will be subtracted from the
549 thread pointer. To get the variable position in the TLS
550 block we subtract the offset from that of the TLS block. */
551 if (sym != NULL)
553 CHECK_STATIC_TLS (map, sym_map);
554 *reloc_addr = sym_map->l_tls_offset - sym->st_value
555 + reloc->r_addend;
557 break;
558 case R_386_TLS_TPOFF:
559 /* The offset is negative, forward from the thread pointer. */
560 /* We know the offset of object the symbol is contained in.
561 It is a negative value which will be added to the
562 thread pointer. */
563 if (sym != NULL)
565 CHECK_STATIC_TLS (map, sym_map);
566 *reloc_addr = sym->st_value - sym_map->l_tls_offset
567 + reloc->r_addend;
569 break;
570 case R_386_COPY:
571 if (sym == NULL)
572 /* This can happen in trace mode if an object could not be
573 found. */
574 break;
575 if (__builtin_expect (sym->st_size > refsym->st_size, 0)
576 || (__builtin_expect (sym->st_size < refsym->st_size, 0)
577 && GLRO(dl_verbose)))
579 const char *strtab;
581 strtab = (const char *) D_PTR (map, l_info[DT_STRTAB]);
582 _dl_error_printf ("\
583 %s: Symbol `%s' has different size in shared object, consider re-linking\n",
584 RTLD_PROGNAME, strtab + refsym->st_name);
586 memcpy (reloc_addr_arg, (void *) value,
587 MIN (sym->st_size, refsym->st_size));
588 break;
589 # endif /* !RESOLVE_CONFLICT_FIND_MAP */
590 case R_386_IRELATIVE:
591 value = map->l_addr + reloc->r_addend;
592 value = ((Elf32_Addr (*) (void)) value) ();
593 *reloc_addr = value;
594 break;
595 default:
596 /* We add these checks in the version to relocate ld.so only
597 if we are still debugging. */
598 _dl_reloc_bad_type (map, r_type, 0);
599 break;
603 # endif /* !RTLD_BOOTSTRAP */
605 auto inline void
606 __attribute ((always_inline))
607 elf_machine_rel_relative (Elf32_Addr l_addr, const Elf32_Rel *reloc,
608 void *const reloc_addr_arg)
610 Elf32_Addr *const reloc_addr = reloc_addr_arg;
611 assert (ELF32_R_TYPE (reloc->r_info) == R_386_RELATIVE);
612 *reloc_addr += l_addr;
615 # ifndef RTLD_BOOTSTRAP
616 auto inline void
617 __attribute__ ((always_inline))
618 elf_machine_rela_relative (Elf32_Addr l_addr, const Elf32_Rela *reloc,
619 void *const reloc_addr_arg)
621 Elf32_Addr *const reloc_addr = reloc_addr_arg;
622 *reloc_addr = l_addr + reloc->r_addend;
624 # endif /* !RTLD_BOOTSTRAP */
626 auto inline void
627 __attribute__ ((always_inline))
628 elf_machine_lazy_rel (struct link_map *map,
629 Elf32_Addr l_addr, const Elf32_Rel *reloc,
630 int skip_ifunc)
632 Elf32_Addr *const reloc_addr = (void *) (l_addr + reloc->r_offset);
633 const unsigned int r_type = ELF32_R_TYPE (reloc->r_info);
634 /* Check for unexpected PLT reloc type. */
635 if (__glibc_likely (r_type == R_386_JMP_SLOT))
637 if (__builtin_expect (map->l_mach.plt, 0) == 0)
638 *reloc_addr += l_addr;
639 else
640 *reloc_addr = (map->l_mach.plt
641 + (((Elf32_Addr) reloc_addr) - map->l_mach.gotplt) * 4);
643 else if (__glibc_likely (r_type == R_386_TLS_DESC))
645 struct tlsdesc volatile * __attribute__((__unused__)) td =
646 (struct tlsdesc volatile *)reloc_addr;
648 /* Handle relocations that reference the local *ABS* in a simple
649 way, so as to preserve a potential addend. */
650 if (ELF32_R_SYM (reloc->r_info) == 0)
651 td->entry = _dl_tlsdesc_resolve_abs_plus_addend;
652 /* Given a known-zero addend, we can store a pointer to the
653 reloc in the arg position. */
654 else if (td->arg == 0)
656 td->arg = (void*)reloc;
657 td->entry = _dl_tlsdesc_resolve_rel;
659 else
661 /* We could handle non-*ABS* relocations with non-zero addends
662 by allocating dynamically an arg to hold a pointer to the
663 reloc, but that sounds pointless. */
664 const Elf32_Rel *const r = reloc;
665 /* The code below was borrowed from elf_dynamic_do_rel(). */
666 const ElfW(Sym) *const symtab =
667 (const void *) D_PTR (map, l_info[DT_SYMTAB]);
669 # ifdef RTLD_BOOTSTRAP
670 /* The dynamic linker always uses versioning. */
671 assert (map->l_info[VERSYMIDX (DT_VERSYM)] != NULL);
672 # else
673 if (map->l_info[VERSYMIDX (DT_VERSYM)])
674 # endif
676 const ElfW(Half) *const version =
677 (const void *) D_PTR (map, l_info[VERSYMIDX (DT_VERSYM)]);
678 ElfW(Half) ndx = version[ELFW(R_SYM) (r->r_info)] & 0x7fff;
679 elf_machine_rel (map, r, &symtab[ELFW(R_SYM) (r->r_info)],
680 &map->l_versions[ndx],
681 (void *) (l_addr + r->r_offset), skip_ifunc);
683 # ifndef RTLD_BOOTSTRAP
684 else
685 elf_machine_rel (map, r, &symtab[ELFW(R_SYM) (r->r_info)], NULL,
686 (void *) (l_addr + r->r_offset), skip_ifunc);
687 # endif
690 else if (__glibc_unlikely (r_type == R_386_IRELATIVE))
692 Elf32_Addr value = map->l_addr + *reloc_addr;
693 if (__glibc_likely (!skip_ifunc))
694 value = ((Elf32_Addr (*) (void)) value) ();
695 *reloc_addr = value;
697 else
698 _dl_reloc_bad_type (map, r_type, 1);
701 # ifndef RTLD_BOOTSTRAP
703 auto inline void
704 __attribute__ ((always_inline))
705 elf_machine_lazy_rela (struct link_map *map,
706 Elf32_Addr l_addr, const Elf32_Rela *reloc,
707 int skip_ifunc)
709 Elf32_Addr *const reloc_addr = (void *) (l_addr + reloc->r_offset);
710 const unsigned int r_type = ELF32_R_TYPE (reloc->r_info);
711 if (__glibc_likely (r_type == R_386_JMP_SLOT))
713 else if (__glibc_likely (r_type == R_386_TLS_DESC))
715 struct tlsdesc volatile * __attribute__((__unused__)) td =
716 (struct tlsdesc volatile *)reloc_addr;
718 td->arg = (void*)reloc;
719 td->entry = _dl_tlsdesc_resolve_rela;
721 else if (__glibc_unlikely (r_type == R_386_IRELATIVE))
723 Elf32_Addr value = map->l_addr + reloc->r_addend;
724 if (__glibc_likely (!skip_ifunc))
725 value = ((Elf32_Addr (*) (void)) value) ();
726 *reloc_addr = value;
728 else
729 _dl_reloc_bad_type (map, r_type, 1);
732 # endif /* !RTLD_BOOTSTRAP */
734 #endif /* RESOLVE_MAP */