Update build-many-glibcs.py for binutils ia64 obsoletion.
[glibc.git] / sysdeps / i386 / dl-machine.h
blob0f08079e48a296ed10f19639ddf1a18874c1c589
1 /* Machine-dependent ELF dynamic relocation inline functions. i386 version.
2 Copyright (C) 1995-2020 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 <https://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;
70 extern void _dl_runtime_resolve_shstk (Elf32_Word) attribute_hidden;
71 extern void _dl_runtime_profile_shstk (Elf32_Word) attribute_hidden;
72 /* Check if SHSTK is enabled by kernel. */
73 bool shstk_enabled
74 = (GL(dl_x86_feature_1) & GNU_PROPERTY_X86_FEATURE_1_SHSTK) != 0;
76 if (l->l_info[DT_JMPREL] && lazy)
78 /* The GOT entries for functions in the PLT have not yet been filled
79 in. Their initial contents will arrange when called to push an
80 offset into the .rel.plt section, push _GLOBAL_OFFSET_TABLE_[1],
81 and then jump to _GLOBAL_OFFSET_TABLE[2]. */
82 got = (Elf32_Addr *) D_PTR (l, l_info[DT_PLTGOT]);
83 /* If a library is prelinked but we have to relocate anyway,
84 we have to be able to undo the prelinking of .got.plt.
85 The prelinker saved us here address of .plt + 0x16. */
86 if (got[1])
88 l->l_mach.plt = got[1] + l->l_addr;
89 l->l_mach.gotplt = (Elf32_Addr) &got[3];
91 got[1] = (Elf32_Addr) l; /* Identify this shared object. */
93 /* The got[2] entry contains the address of a function which gets
94 called to get the address of a so far unresolved function and
95 jump to it. The profiling extension of the dynamic linker allows
96 to intercept the calls to collect information. In this case we
97 don't store the address in the GOT so that all future calls also
98 end in this function. */
99 if (__glibc_unlikely (profile))
101 got[2] = (shstk_enabled
102 ? (Elf32_Addr) &_dl_runtime_profile_shstk
103 : (Elf32_Addr) &_dl_runtime_profile);
105 if (GLRO(dl_profile) != NULL
106 && _dl_name_match_p (GLRO(dl_profile), l))
107 /* This is the object we are looking for. Say that we really
108 want profiling and the timers are started. */
109 GL(dl_profile_map) = l;
111 else
112 /* This function will get called to fix up the GOT entry indicated by
113 the offset on the stack, and then jump to the resolved address. */
114 got[2] = (shstk_enabled
115 ? (Elf32_Addr) &_dl_runtime_resolve_shstk
116 : (Elf32_Addr) &_dl_runtime_resolve);
119 return lazy;
122 #ifdef IN_DL_RUNTIME
124 # ifndef PROF
125 /* We add a declaration of this function here so that in dl-runtime.c
126 the ELF_MACHINE_RUNTIME_TRAMPOLINE macro really can pass the parameters
127 in registers.
129 We cannot use this scheme for profiling because the _mcount call
130 destroys the passed register information. */
131 #define ARCH_FIXUP_ATTRIBUTE __attribute__ ((regparm (3), stdcall, unused))
133 extern ElfW(Addr) _dl_fixup (struct link_map *l,
134 ElfW(Word) reloc_offset)
135 ARCH_FIXUP_ATTRIBUTE;
136 extern ElfW(Addr) _dl_profile_fixup (struct link_map *l,
137 ElfW(Word) reloc_offset,
138 ElfW(Addr) retaddr, void *regs,
139 long int *framesizep)
140 ARCH_FIXUP_ATTRIBUTE;
141 # endif
143 #endif
145 /* Mask identifying addresses reserved for the user program,
146 where the dynamic linker should not map anything. */
147 #define ELF_MACHINE_USER_ADDRESS_MASK 0xf8000000UL
149 /* Initial entry point code for the dynamic linker.
150 The C function `_dl_start' is the real entry point;
151 its return value is the user program's entry point. */
153 #define RTLD_START asm ("\n\
154 .text\n\
155 .align 16\n\
156 0: movl (%esp), %ebx\n\
157 ret\n\
158 .align 16\n\
159 .globl _start\n\
160 .globl _dl_start_user\n\
161 _start:\n\
162 movl %esp, %eax\n\
163 subl $12, %esp\n\
164 pushl %eax\n\
165 call _dl_start\n\
166 addl $16, %esp\n\
167 _dl_start_user:\n\
168 # Save the user entry point address in %edi.\n\
169 movl %eax, %edi\n\
170 # Point %ebx at the GOT.\n\
171 call 0b\n\
172 addl $_GLOBAL_OFFSET_TABLE_, %ebx\n\
173 # See if we were run as a command with the executable file\n\
174 # name as an extra leading argument.\n\
175 movl _dl_skip_args@GOTOFF(%ebx), %eax\n\
176 # Pop the original argument count.\n\
177 popl %edx\n\
178 # Adjust the stack pointer to skip _dl_skip_args words.\n\
179 leal (%esp,%eax,4), %esp\n\
180 # Subtract _dl_skip_args from argc.\n\
181 subl %eax, %edx\n\
182 # Push argc back on the stack.\n\
183 push %edx\n\
184 # The special initializer gets called with the stack just\n\
185 # as the application's entry point will see it; it can\n\
186 # switch stacks if it moves these contents over.\n\
187 " RTLD_START_SPECIAL_INIT "\n\
188 # Load the parameters again.\n\
189 # (eax, edx, ecx, esi) = (_dl_loaded, argc, argv, envp)\n\
190 movl _rtld_local@GOTOFF(%ebx), %eax\n\
191 leal 8(%esp,%edx,4), %esi\n\
192 leal 4(%esp), %ecx\n\
193 movl %esp, %ebp\n\
194 # Make sure _dl_init is run with 16 byte aligned stack.\n\
195 andl $-16, %esp\n\
196 subl $12, %esp\n\
197 pushl %ebp\n\
198 # Arguments for _dl_init.\n\
199 pushl %esi\n\
200 pushl %ecx\n\
201 pushl %edx\n\
202 pushl %eax\n\
203 # Clear %ebp, so that even constructors have terminated backchain.\n\
204 xorl %ebp, %ebp\n\
205 # Call the function to run the initializers.\n\
206 call _dl_init\n\
207 # Pass our finalizer function to the user in %edx, as per ELF ABI.\n\
208 leal _dl_fini@GOTOFF(%ebx), %edx\n\
209 # Restore %esp _start expects.\n\
210 movl 16(%esp), %esp\n\
211 # Jump to the user's entry point.\n\
212 jmp *%edi\n\
213 .previous\n\
216 #ifndef RTLD_START_SPECIAL_INIT
217 # define RTLD_START_SPECIAL_INIT /* nothing */
218 #endif
220 /* ELF_RTYPE_CLASS_PLT iff TYPE describes relocation of a PLT entry or
221 TLS variable, so undefined references should not be allowed to
222 define the value.
223 ELF_RTYPE_CLASS_COPY iff TYPE should not be allowed to resolve to one
224 of the main executable's symbols, as for a COPY reloc.
225 ELF_RTYPE_CLASS_EXTERN_PROTECTED_DATA iff TYPE describes relocation may
226 against protected data whose address be external due to copy relocation.
228 # define elf_machine_type_class(type) \
229 ((((type) == R_386_JMP_SLOT || (type) == R_386_TLS_DTPMOD32 \
230 || (type) == R_386_TLS_DTPOFF32 || (type) == R_386_TLS_TPOFF32 \
231 || (type) == R_386_TLS_TPOFF || (type) == R_386_TLS_DESC) \
232 * ELF_RTYPE_CLASS_PLT) \
233 | (((type) == R_386_COPY) * ELF_RTYPE_CLASS_COPY) \
234 | (((type) == R_386_GLOB_DAT) * ELF_RTYPE_CLASS_EXTERN_PROTECTED_DATA))
236 /* A reloc type used for ld.so cmdline arg lookups to reject PLT entries. */
237 #define ELF_MACHINE_JMP_SLOT R_386_JMP_SLOT
239 /* The i386 never uses Elf32_Rela relocations for the dynamic linker.
240 Prelinked libraries may use Elf32_Rela though. */
241 #define ELF_MACHINE_PLT_REL 1
243 /* We define an initialization functions. This is called very early in
244 _dl_sysdep_start. */
245 #define DL_PLATFORM_INIT dl_platform_init ()
247 static inline void __attribute__ ((unused))
248 dl_platform_init (void)
250 #if IS_IN (rtld)
251 /* init_cpu_features has been called early from __libc_start_main in
252 static executable. */
253 init_cpu_features (&GLRO(dl_x86_cpu_features));
254 #else
255 if (GLRO(dl_platform) != NULL && *GLRO(dl_platform) == '\0')
256 /* Avoid an empty string which would disturb us. */
257 GLRO(dl_platform) = NULL;
258 #endif
261 static inline Elf32_Addr
262 elf_machine_fixup_plt (struct link_map *map, lookup_t t,
263 const ElfW(Sym) *refsym, const ElfW(Sym) *sym,
264 const Elf32_Rel *reloc,
265 Elf32_Addr *reloc_addr, Elf32_Addr value)
267 return *reloc_addr = value;
270 /* Return the final value of a plt relocation. */
271 static inline Elf32_Addr
272 elf_machine_plt_value (struct link_map *map, const Elf32_Rel *reloc,
273 Elf32_Addr value)
275 return value;
279 /* Names of the architecture-specific auditing callback functions. */
280 #define ARCH_LA_PLTENTER i86_gnu_pltenter
281 #define ARCH_LA_PLTEXIT i86_gnu_pltexit
283 #endif /* !dl_machine_h */
285 /* The i386 never uses Elf32_Rela relocations for the dynamic linker.
286 Prelinked libraries may use Elf32_Rela though. */
287 #define ELF_MACHINE_NO_RELA defined RTLD_BOOTSTRAP
288 #define ELF_MACHINE_NO_REL 0
290 #ifdef RESOLVE_MAP
292 /* Perform the relocation specified by RELOC and SYM (which is fully resolved).
293 MAP is the object containing the reloc. */
295 auto inline void
296 __attribute ((always_inline))
297 elf_machine_rel (struct link_map *map, const Elf32_Rel *reloc,
298 const Elf32_Sym *sym, const struct r_found_version *version,
299 void *const reloc_addr_arg, int skip_ifunc)
301 Elf32_Addr *const reloc_addr = reloc_addr_arg;
302 const unsigned int r_type = ELF32_R_TYPE (reloc->r_info);
304 # if !defined RTLD_BOOTSTRAP || !defined HAVE_Z_COMBRELOC
305 if (__glibc_unlikely (r_type == R_386_RELATIVE))
307 # if !defined RTLD_BOOTSTRAP && !defined HAVE_Z_COMBRELOC
308 /* This is defined in rtld.c, but nowhere in the static libc.a;
309 make the reference weak so static programs can still link.
310 This declaration cannot be done when compiling rtld.c
311 (i.e. #ifdef RTLD_BOOTSTRAP) because rtld.c contains the
312 common defn for _dl_rtld_map, which is incompatible with a
313 weak decl in the same file. */
314 # ifndef SHARED
315 weak_extern (_dl_rtld_map);
316 # endif
317 if (map != &GL(dl_rtld_map)) /* Already done in rtld itself. */
318 # endif
319 *reloc_addr += map->l_addr;
321 # ifndef RTLD_BOOTSTRAP
322 else if (__glibc_unlikely (r_type == R_386_NONE))
323 return;
324 # endif
325 else
326 # endif /* !RTLD_BOOTSTRAP and have no -z combreloc */
328 # ifndef RTLD_BOOTSTRAP
329 const Elf32_Sym *const refsym = sym;
330 # endif
331 struct link_map *sym_map = RESOLVE_MAP (&sym, version, r_type);
332 Elf32_Addr value = SYMBOL_ADDRESS (sym_map, sym, true);
334 if (sym != NULL
335 && __glibc_unlikely (ELFW(ST_TYPE) (sym->st_info) == STT_GNU_IFUNC)
336 && __glibc_likely (sym->st_shndx != SHN_UNDEF)
337 && __glibc_likely (!skip_ifunc))
339 # ifndef RTLD_BOOTSTRAP
340 if (sym_map != map
341 && sym_map->l_type != lt_executable
342 && !sym_map->l_relocated)
344 const char *strtab
345 = (const char *) D_PTR (map, l_info[DT_STRTAB]);
346 _dl_error_printf ("\
347 %s: Relink `%s' with `%s' for IFUNC symbol `%s'\n",
348 RTLD_PROGNAME, map->l_name,
349 sym_map->l_name,
350 strtab + refsym->st_name);
352 # endif
353 value = ((Elf32_Addr (*) (void)) value) ();
356 switch (r_type)
358 # ifndef RTLD_BOOTSTRAP
359 case R_386_SIZE32:
360 /* Set to symbol size plus addend. */
361 *reloc_addr += sym->st_size;
362 break;
363 # endif
364 case R_386_GLOB_DAT:
365 case R_386_JMP_SLOT:
366 *reloc_addr = value;
367 break;
369 case R_386_TLS_DTPMOD32:
370 # ifdef RTLD_BOOTSTRAP
371 /* During startup the dynamic linker is always the module
372 with index 1.
373 XXX If this relocation is necessary move before RESOLVE
374 call. */
375 *reloc_addr = 1;
376 # else
377 /* Get the information from the link map returned by the
378 resolv function. */
379 if (sym_map != NULL)
380 *reloc_addr = sym_map->l_tls_modid;
381 # endif
382 break;
383 case R_386_TLS_DTPOFF32:
384 # ifndef RTLD_BOOTSTRAP
385 /* During relocation all TLS symbols are defined and used.
386 Therefore the offset is already correct. */
387 if (sym != NULL)
388 *reloc_addr = sym->st_value;
389 # endif
390 break;
391 case R_386_TLS_DESC:
393 struct tlsdesc volatile *td =
394 (struct tlsdesc volatile *)reloc_addr;
396 # ifndef RTLD_BOOTSTRAP
397 if (! sym)
398 td->entry = _dl_tlsdesc_undefweak;
399 else
400 # endif
402 # ifndef RTLD_BOOTSTRAP
403 # ifndef SHARED
404 CHECK_STATIC_TLS (map, sym_map);
405 # else
406 if (!TRY_STATIC_TLS (map, sym_map))
408 td->arg = _dl_make_tlsdesc_dynamic
409 (sym_map, sym->st_value + (ElfW(Word))td->arg);
410 td->entry = _dl_tlsdesc_dynamic;
412 else
413 # endif
414 # endif
416 td->arg = (void*)(sym->st_value - sym_map->l_tls_offset
417 + (ElfW(Word))td->arg);
418 td->entry = _dl_tlsdesc_return;
421 break;
423 case R_386_TLS_TPOFF32:
424 /* The offset is positive, backward from the thread pointer. */
425 # ifdef RTLD_BOOTSTRAP
426 *reloc_addr += map->l_tls_offset - sym->st_value;
427 # else
428 /* We know the offset of object the symbol is contained in.
429 It is a positive value which will be subtracted from the
430 thread pointer. To get the variable position in the TLS
431 block we subtract the offset from that of the TLS block. */
432 if (sym != NULL)
434 CHECK_STATIC_TLS (map, sym_map);
435 *reloc_addr += sym_map->l_tls_offset - sym->st_value;
437 # endif
438 break;
439 case R_386_TLS_TPOFF:
440 /* The offset is negative, forward from the thread pointer. */
441 # ifdef RTLD_BOOTSTRAP
442 *reloc_addr += sym->st_value - map->l_tls_offset;
443 # else
444 /* We know the offset of object the symbol is contained in.
445 It is a negative value which will be added to the
446 thread pointer. */
447 if (sym != NULL)
449 CHECK_STATIC_TLS (map, sym_map);
450 *reloc_addr += sym->st_value - sym_map->l_tls_offset;
452 # endif
453 break;
455 # ifndef RTLD_BOOTSTRAP
456 case R_386_32:
457 *reloc_addr += value;
458 break;
459 case R_386_PC32:
460 *reloc_addr += (value - (Elf32_Addr) reloc_addr);
461 break;
462 case R_386_COPY:
463 if (sym == NULL)
464 /* This can happen in trace mode if an object could not be
465 found. */
466 break;
467 if (__glibc_unlikely (sym->st_size > refsym->st_size)
468 || (__glibc_unlikely(sym->st_size < refsym->st_size)
469 && GLRO(dl_verbose)))
471 const char *strtab;
473 strtab = (const char *) D_PTR (map, l_info[DT_STRTAB]);
474 _dl_error_printf ("\
475 %s: Symbol `%s' has different size in shared object, consider re-linking\n",
476 RTLD_PROGNAME, strtab + refsym->st_name);
478 memcpy (reloc_addr_arg, (void *) value,
479 MIN (sym->st_size, refsym->st_size));
480 break;
481 case R_386_IRELATIVE:
482 value = map->l_addr + *reloc_addr;
483 if (__glibc_likely (!skip_ifunc))
484 value = ((Elf32_Addr (*) (void)) value) ();
485 *reloc_addr = value;
486 break;
487 default:
488 _dl_reloc_bad_type (map, r_type, 0);
489 break;
490 # endif /* !RTLD_BOOTSTRAP */
495 # ifndef RTLD_BOOTSTRAP
496 auto inline void
497 __attribute__ ((always_inline))
498 elf_machine_rela (struct link_map *map, const Elf32_Rela *reloc,
499 const Elf32_Sym *sym, const struct r_found_version *version,
500 void *const reloc_addr_arg, int skip_ifunc)
502 Elf32_Addr *const reloc_addr = reloc_addr_arg;
503 const unsigned int r_type = ELF32_R_TYPE (reloc->r_info);
505 if (ELF32_R_TYPE (reloc->r_info) == R_386_RELATIVE)
506 *reloc_addr = map->l_addr + reloc->r_addend;
507 else if (r_type != R_386_NONE)
509 # ifndef RESOLVE_CONFLICT_FIND_MAP
510 const Elf32_Sym *const refsym = sym;
511 # endif
512 struct link_map *sym_map = RESOLVE_MAP (&sym, version, r_type);
513 Elf32_Addr value = SYMBOL_ADDRESS (sym_map, sym, true);
515 if (sym != NULL
516 && __glibc_likely (sym->st_shndx != SHN_UNDEF)
517 && __glibc_unlikely (ELFW(ST_TYPE) (sym->st_info) == STT_GNU_IFUNC)
518 && __glibc_likely (!skip_ifunc))
519 value = ((Elf32_Addr (*) (void)) value) ();
521 switch (ELF32_R_TYPE (reloc->r_info))
523 case R_386_SIZE32:
524 /* Set to symbol size plus addend. */
525 value = sym->st_size;
526 /* Fall through. */
527 case R_386_GLOB_DAT:
528 case R_386_JMP_SLOT:
529 case R_386_32:
530 *reloc_addr = value + reloc->r_addend;
531 break;
532 # ifndef RESOLVE_CONFLICT_FIND_MAP
533 /* Not needed for dl-conflict.c. */
534 case R_386_PC32:
535 *reloc_addr = (value + reloc->r_addend - (Elf32_Addr) reloc_addr);
536 break;
538 case R_386_TLS_DTPMOD32:
539 /* Get the information from the link map returned by the
540 resolv function. */
541 if (sym_map != NULL)
542 *reloc_addr = sym_map->l_tls_modid;
543 break;
544 case R_386_TLS_DTPOFF32:
545 /* During relocation all TLS symbols are defined and used.
546 Therefore the offset is already correct. */
547 *reloc_addr = (sym == NULL ? 0 : sym->st_value) + reloc->r_addend;
548 break;
549 case R_386_TLS_DESC:
551 struct tlsdesc volatile *td =
552 (struct tlsdesc volatile *)reloc_addr;
554 # ifndef RTLD_BOOTSTRAP
555 if (!sym)
557 td->arg = (void*)reloc->r_addend;
558 td->entry = _dl_tlsdesc_undefweak;
560 else
561 # endif
563 # ifndef RTLD_BOOTSTRAP
564 # ifndef SHARED
565 CHECK_STATIC_TLS (map, sym_map);
566 # else
567 if (!TRY_STATIC_TLS (map, sym_map))
569 td->arg = _dl_make_tlsdesc_dynamic
570 (sym_map, sym->st_value + reloc->r_addend);
571 td->entry = _dl_tlsdesc_dynamic;
573 else
574 # endif
575 # endif
577 td->arg = (void*)(sym->st_value - sym_map->l_tls_offset
578 + reloc->r_addend);
579 td->entry = _dl_tlsdesc_return;
583 break;
584 case R_386_TLS_TPOFF32:
585 /* The offset is positive, backward from the thread pointer. */
586 /* We know the offset of object the symbol is contained in.
587 It is a positive value which will be subtracted from the
588 thread pointer. To get the variable position in the TLS
589 block we subtract the offset from that of the TLS block. */
590 if (sym != NULL)
592 CHECK_STATIC_TLS (map, sym_map);
593 *reloc_addr = sym_map->l_tls_offset - sym->st_value
594 + reloc->r_addend;
596 break;
597 case R_386_TLS_TPOFF:
598 /* The offset is negative, forward from the thread pointer. */
599 /* We know the offset of object the symbol is contained in.
600 It is a negative value which will be added to the
601 thread pointer. */
602 if (sym != NULL)
604 CHECK_STATIC_TLS (map, sym_map);
605 *reloc_addr = sym->st_value - sym_map->l_tls_offset
606 + reloc->r_addend;
608 break;
609 case R_386_COPY:
610 if (sym == NULL)
611 /* This can happen in trace mode if an object could not be
612 found. */
613 break;
614 if (__glibc_unlikely (sym->st_size > refsym->st_size)
615 || (__glibc_unlikely (sym->st_size < refsym->st_size)
616 && GLRO(dl_verbose)))
618 const char *strtab;
620 strtab = (const char *) D_PTR (map, l_info[DT_STRTAB]);
621 _dl_error_printf ("\
622 %s: Symbol `%s' has different size in shared object, consider re-linking\n",
623 RTLD_PROGNAME, strtab + refsym->st_name);
625 memcpy (reloc_addr_arg, (void *) value,
626 MIN (sym->st_size, refsym->st_size));
627 break;
628 # endif /* !RESOLVE_CONFLICT_FIND_MAP */
629 case R_386_IRELATIVE:
630 value = map->l_addr + reloc->r_addend;
631 if (__glibc_likely (!skip_ifunc))
632 value = ((Elf32_Addr (*) (void)) value) ();
633 *reloc_addr = value;
634 break;
635 default:
636 /* We add these checks in the version to relocate ld.so only
637 if we are still debugging. */
638 _dl_reloc_bad_type (map, r_type, 0);
639 break;
643 # endif /* !RTLD_BOOTSTRAP */
645 auto inline void
646 __attribute ((always_inline))
647 elf_machine_rel_relative (Elf32_Addr l_addr, const Elf32_Rel *reloc,
648 void *const reloc_addr_arg)
650 Elf32_Addr *const reloc_addr = reloc_addr_arg;
651 assert (ELF32_R_TYPE (reloc->r_info) == R_386_RELATIVE);
652 *reloc_addr += l_addr;
655 # ifndef RTLD_BOOTSTRAP
656 auto inline void
657 __attribute__ ((always_inline))
658 elf_machine_rela_relative (Elf32_Addr l_addr, const Elf32_Rela *reloc,
659 void *const reloc_addr_arg)
661 Elf32_Addr *const reloc_addr = reloc_addr_arg;
662 *reloc_addr = l_addr + reloc->r_addend;
664 # endif /* !RTLD_BOOTSTRAP */
666 auto inline void
667 __attribute__ ((always_inline))
668 elf_machine_lazy_rel (struct link_map *map,
669 Elf32_Addr l_addr, const Elf32_Rel *reloc,
670 int skip_ifunc)
672 Elf32_Addr *const reloc_addr = (void *) (l_addr + reloc->r_offset);
673 const unsigned int r_type = ELF32_R_TYPE (reloc->r_info);
674 /* Check for unexpected PLT reloc type. */
675 if (__glibc_likely (r_type == R_386_JMP_SLOT))
677 /* Prelink has been deprecated. */
678 if (__glibc_likely (map->l_mach.plt == 0))
679 *reloc_addr += l_addr;
680 else
681 *reloc_addr = (map->l_mach.plt
682 + (((Elf32_Addr) reloc_addr) - map->l_mach.gotplt) * 4);
684 else if (__glibc_likely (r_type == R_386_TLS_DESC))
686 struct tlsdesc volatile * __attribute__((__unused__)) td =
687 (struct tlsdesc volatile *)reloc_addr;
689 /* Handle relocations that reference the local *ABS* in a simple
690 way, so as to preserve a potential addend. */
691 if (ELF32_R_SYM (reloc->r_info) == 0)
692 td->entry = _dl_tlsdesc_resolve_abs_plus_addend;
693 /* Given a known-zero addend, we can store a pointer to the
694 reloc in the arg position. */
695 else if (td->arg == 0)
697 td->arg = (void*)reloc;
698 td->entry = _dl_tlsdesc_resolve_rel;
700 else
702 /* We could handle non-*ABS* relocations with non-zero addends
703 by allocating dynamically an arg to hold a pointer to the
704 reloc, but that sounds pointless. */
705 const Elf32_Rel *const r = reloc;
706 /* The code below was borrowed from elf_dynamic_do_rel(). */
707 const ElfW(Sym) *const symtab =
708 (const void *) D_PTR (map, l_info[DT_SYMTAB]);
710 # ifdef RTLD_BOOTSTRAP
711 /* The dynamic linker always uses versioning. */
712 assert (map->l_info[VERSYMIDX (DT_VERSYM)] != NULL);
713 # else
714 if (map->l_info[VERSYMIDX (DT_VERSYM)])
715 # endif
717 const ElfW(Half) *const version =
718 (const void *) D_PTR (map, l_info[VERSYMIDX (DT_VERSYM)]);
719 ElfW(Half) ndx = version[ELFW(R_SYM) (r->r_info)] & 0x7fff;
720 elf_machine_rel (map, r, &symtab[ELFW(R_SYM) (r->r_info)],
721 &map->l_versions[ndx],
722 (void *) (l_addr + r->r_offset), skip_ifunc);
724 # ifndef RTLD_BOOTSTRAP
725 else
726 elf_machine_rel (map, r, &symtab[ELFW(R_SYM) (r->r_info)], NULL,
727 (void *) (l_addr + r->r_offset), skip_ifunc);
728 # endif
731 else if (__glibc_unlikely (r_type == R_386_IRELATIVE))
733 Elf32_Addr value = map->l_addr + *reloc_addr;
734 if (__glibc_likely (!skip_ifunc))
735 value = ((Elf32_Addr (*) (void)) value) ();
736 *reloc_addr = value;
738 else
739 _dl_reloc_bad_type (map, r_type, 1);
742 # ifndef RTLD_BOOTSTRAP
744 auto inline void
745 __attribute__ ((always_inline))
746 elf_machine_lazy_rela (struct link_map *map,
747 Elf32_Addr l_addr, const Elf32_Rela *reloc,
748 int skip_ifunc)
750 Elf32_Addr *const reloc_addr = (void *) (l_addr + reloc->r_offset);
751 const unsigned int r_type = ELF32_R_TYPE (reloc->r_info);
752 if (__glibc_likely (r_type == R_386_JMP_SLOT))
754 else if (__glibc_likely (r_type == R_386_TLS_DESC))
756 struct tlsdesc volatile * __attribute__((__unused__)) td =
757 (struct tlsdesc volatile *)reloc_addr;
759 td->arg = (void*)reloc;
760 td->entry = _dl_tlsdesc_resolve_rela;
762 else if (__glibc_unlikely (r_type == R_386_IRELATIVE))
764 Elf32_Addr value = map->l_addr + reloc->r_addend;
765 if (__glibc_likely (!skip_ifunc))
766 value = ((Elf32_Addr (*) (void)) value) ();
767 *reloc_addr = value;
769 else
770 _dl_reloc_bad_type (map, r_type, 1);
773 # endif /* !RTLD_BOOTSTRAP */
775 #endif /* RESOLVE_MAP */