Updated to fedora-glibc-20090427T1419
[glibc/history.git] / sysdeps / i386 / dl-machine.h
blob0e15878d4e905b742473ffc73ad41a511c1bb9ba
1 /* Machine-dependent ELF dynamic relocation inline functions. i386 version.
2 Copyright (C) 1995-2005, 2006, 2009 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, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 USA. */
20 #ifndef dl_machine_h
21 #define dl_machine_h
23 #define ELF_MACHINE_NAME "i386"
25 #include <sys/param.h>
26 #include <sysdep.h>
27 #include <tls.h>
28 #include <dl-tlsdesc.h>
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 #ifdef PI_STATIC_AND_HIDDEN
40 /* Return the link-time address of _DYNAMIC. Conveniently, this is the
41 first element of the GOT, a special entry that is never relocated. */
42 static inline Elf32_Addr __attribute__ ((unused, const))
43 elf_machine_dynamic (void)
45 /* This produces a GOTOFF reloc that resolves to zero at link time, so in
46 fact just loads from the GOT register directly. By doing it without
47 an asm we can let the compiler choose any register. */
48 extern const Elf32_Addr _GLOBAL_OFFSET_TABLE_[] attribute_hidden;
49 return _GLOBAL_OFFSET_TABLE_[0];
52 /* Return the run-time load address of the shared object. */
53 static inline Elf32_Addr __attribute__ ((unused))
54 elf_machine_load_address (void)
56 /* Compute the difference between the runtime address of _DYNAMIC as seen
57 by a GOTOFF reference, and the link-time address found in the special
58 unrelocated first GOT entry. */
59 extern Elf32_Dyn bygotoff[] asm ("_DYNAMIC") attribute_hidden;
60 return (Elf32_Addr) &bygotoff - elf_machine_dynamic ();
63 #else /* Without .hidden support, we can't compile the code above. */
65 /* Return the link-time address of _DYNAMIC. Conveniently, this is the
66 first element of the GOT. This must be inlined in a function which
67 uses global data. */
68 static inline Elf32_Addr __attribute__ ((unused))
69 elf_machine_dynamic (void)
71 register Elf32_Addr *got asm ("%ebx");
72 return *got;
76 /* Return the run-time load address of the shared object. */
77 static inline Elf32_Addr __attribute__ ((unused))
78 elf_machine_load_address (void)
80 /* It doesn't matter what variable this is, the reference never makes
81 it to assembly. We need a dummy reference to some global variable
82 via the GOT to make sure the compiler initialized %ebx in time. */
83 extern int _dl_argc;
84 Elf32_Addr addr;
85 asm ("leal _dl_start@GOTOFF(%%ebx), %0\n"
86 "subl _dl_start@GOT(%%ebx), %0"
87 : "=r" (addr) : "m" (_dl_argc) : "cc");
88 return addr;
91 #endif
94 /* Set up the loaded object described by L so its unrelocated PLT
95 entries will jump to the on-demand fixup code in dl-runtime.c. */
97 static inline int __attribute__ ((unused, always_inline))
98 elf_machine_runtime_setup (struct link_map *l, int lazy, int profile)
100 Elf32_Addr *got;
101 extern void _dl_runtime_resolve (Elf32_Word) attribute_hidden;
102 extern void _dl_runtime_profile (Elf32_Word) attribute_hidden;
104 if (l->l_info[DT_JMPREL] && lazy)
106 /* The GOT entries for functions in the PLT have not yet been filled
107 in. Their initial contents will arrange when called to push an
108 offset into the .rel.plt section, push _GLOBAL_OFFSET_TABLE_[1],
109 and then jump to _GLOBAL_OFFSET_TABLE[2]. */
110 got = (Elf32_Addr *) D_PTR (l, l_info[DT_PLTGOT]);
111 /* If a library is prelinked but we have to relocate anyway,
112 we have to be able to undo the prelinking of .got.plt.
113 The prelinker saved us here address of .plt + 0x16. */
114 if (got[1])
116 l->l_mach.plt = got[1] + l->l_addr;
117 l->l_mach.gotplt = (Elf32_Addr) &got[3];
119 got[1] = (Elf32_Addr) l; /* Identify this shared object. */
121 /* The got[2] entry contains the address of a function which gets
122 called to get the address of a so far unresolved function and
123 jump to it. The profiling extension of the dynamic linker allows
124 to intercept the calls to collect information. In this case we
125 don't store the address in the GOT so that all future calls also
126 end in this function. */
127 if (__builtin_expect (profile, 0))
129 got[2] = (Elf32_Addr) &_dl_runtime_profile;
131 if (GLRO(dl_profile) != NULL
132 && _dl_name_match_p (GLRO(dl_profile), l))
133 /* This is the object we are looking for. Say that we really
134 want profiling and the timers are started. */
135 GL(dl_profile_map) = l;
137 else
138 /* This function will get called to fix up the GOT entry indicated by
139 the offset on the stack, and then jump to the resolved address. */
140 got[2] = (Elf32_Addr) &_dl_runtime_resolve;
143 return lazy;
146 #ifdef IN_DL_RUNTIME
148 # if !defined PROF && !__BOUNDED_POINTERS__
149 /* We add a declaration of this function here so that in dl-runtime.c
150 the ELF_MACHINE_RUNTIME_TRAMPOLINE macro really can pass the parameters
151 in registers.
153 We cannot use this scheme for profiling because the _mcount call
154 destroys the passed register information. */
155 /* GKM FIXME: Fix trampoline to pass bounds so we can do
156 without the `__unbounded' qualifier. */
157 #define ARCH_FIXUP_ATTRIBUTE __attribute__ ((regparm (3), stdcall, unused))
159 extern ElfW(Addr) _dl_fixup (struct link_map *__unbounded l,
160 ElfW(Word) reloc_offset)
161 ARCH_FIXUP_ATTRIBUTE;
162 extern ElfW(Addr) _dl_profile_fixup (struct link_map *l,
163 ElfW(Word) reloc_offset,
164 ElfW(Addr) retaddr, void *regs,
165 long int *framesizep)
166 ARCH_FIXUP_ATTRIBUTE;
167 # endif
169 #endif
171 /* Mask identifying addresses reserved for the user program,
172 where the dynamic linker should not map anything. */
173 #define ELF_MACHINE_USER_ADDRESS_MASK 0xf8000000UL
175 /* Initial entry point code for the dynamic linker.
176 The C function `_dl_start' is the real entry point;
177 its return value is the user program's entry point. */
179 #define RTLD_START asm ("\n\
180 .text\n\
181 .align 16\n\
182 0: movl (%esp), %ebx\n\
183 ret\n\
184 .align 16\n\
185 .globl _start\n\
186 .globl _dl_start_user\n\
187 _start:\n\
188 # Note that _dl_start gets the parameter in %eax.\n\
189 movl %esp, %eax\n\
190 call _dl_start\n\
191 _dl_start_user:\n\
192 # Save the user entry point address in %edi.\n\
193 movl %eax, %edi\n\
194 # Point %ebx at the GOT.\n\
195 call 0b\n\
196 addl $_GLOBAL_OFFSET_TABLE_, %ebx\n\
197 # See if we were run as a command with the executable file\n\
198 # name as an extra leading argument.\n\
199 movl _dl_skip_args@GOTOFF(%ebx), %eax\n\
200 # Pop the original argument count.\n\
201 popl %edx\n\
202 # Adjust the stack pointer to skip _dl_skip_args words.\n\
203 leal (%esp,%eax,4), %esp\n\
204 # Subtract _dl_skip_args from argc.\n\
205 subl %eax, %edx\n\
206 # Push argc back on the stack.\n\
207 push %edx\n\
208 # The special initializer gets called with the stack just\n\
209 # as the application's entry point will see it; it can\n\
210 # switch stacks if it moves these contents over.\n\
211 " RTLD_START_SPECIAL_INIT "\n\
212 # Load the parameters again.\n\
213 # (eax, edx, ecx, *--esp) = (_dl_loaded, argc, argv, envp)\n\
214 movl _rtld_local@GOTOFF(%ebx), %eax\n\
215 leal 8(%esp,%edx,4), %esi\n\
216 leal 4(%esp), %ecx\n\
217 movl %esp, %ebp\n\
218 # Make sure _dl_init is run with 16 byte aligned stack.\n\
219 andl $-16, %esp\n\
220 pushl %eax\n\
221 pushl %eax\n\
222 pushl %ebp\n\
223 pushl %esi\n\
224 # Clear %ebp, so that even constructors have terminated backchain.\n\
225 xorl %ebp, %ebp\n\
226 # Call the function to run the initializers.\n\
227 call _dl_init_internal@PLT\n\
228 # Pass our finalizer function to the user in %edx, as per ELF ABI.\n\
229 leal _dl_fini@GOTOFF(%ebx), %edx\n\
230 # Restore %esp _start expects.\n\
231 movl (%esp), %esp\n\
232 # Jump to the user's entry point.\n\
233 jmp *%edi\n\
234 .previous\n\
237 #ifndef RTLD_START_SPECIAL_INIT
238 # define RTLD_START_SPECIAL_INIT /* nothing */
239 #endif
241 /* ELF_RTYPE_CLASS_PLT iff TYPE describes relocation of a PLT entry or
242 TLS variable, so undefined references should not be allowed to
243 define the value.
244 ELF_RTYPE_CLASS_NOCOPY iff TYPE should not be allowed to resolve to one
245 of the main executable's symbols, as for a COPY reloc. */
246 #if !defined RTLD_BOOTSTRAP || USE___THREAD
247 # define elf_machine_type_class(type) \
248 ((((type) == R_386_JMP_SLOT || (type) == R_386_TLS_DTPMOD32 \
249 || (type) == R_386_TLS_DTPOFF32 || (type) == R_386_TLS_TPOFF32 \
250 || (type) == R_386_TLS_TPOFF || (type) == R_386_TLS_DESC) \
251 * ELF_RTYPE_CLASS_PLT) \
252 | (((type) == R_386_COPY) * ELF_RTYPE_CLASS_COPY))
253 #else
254 # define elf_machine_type_class(type) \
255 ((((type) == R_386_JMP_SLOT) * ELF_RTYPE_CLASS_PLT) \
256 | (((type) == R_386_COPY) * ELF_RTYPE_CLASS_COPY))
257 #endif
259 /* A reloc type used for ld.so cmdline arg lookups to reject PLT entries. */
260 #define ELF_MACHINE_JMP_SLOT R_386_JMP_SLOT
262 /* The i386 never uses Elf32_Rela relocations for the dynamic linker.
263 Prelinked libraries may use Elf32_Rela though. */
264 #define ELF_MACHINE_PLT_REL 1
266 /* We define an initialization functions. This is called very early in
267 _dl_sysdep_start. */
268 #define DL_PLATFORM_INIT dl_platform_init ()
270 static inline void __attribute__ ((unused))
271 dl_platform_init (void)
273 if (GLRO(dl_platform) != NULL && *GLRO(dl_platform) == '\0')
274 /* Avoid an empty string which would disturb us. */
275 GLRO(dl_platform) = NULL;
278 static inline Elf32_Addr
279 elf_machine_fixup_plt (struct link_map *map, lookup_t t,
280 const Elf32_Rel *reloc,
281 Elf32_Addr *reloc_addr, Elf32_Addr value)
283 return *reloc_addr = value;
286 /* Return the final value of a plt relocation. */
287 static inline Elf32_Addr
288 elf_machine_plt_value (struct link_map *map, const Elf32_Rel *reloc,
289 Elf32_Addr value)
291 return value;
295 /* Names of the architecture-specific auditing callback functions. */
296 #define ARCH_LA_PLTENTER i86_gnu_pltenter
297 #define ARCH_LA_PLTEXIT i86_gnu_pltexit
299 #endif /* !dl_machine_h */
301 /* The i386 never uses Elf32_Rela relocations for the dynamic linker.
302 Prelinked libraries may use Elf32_Rela though. */
303 #define ELF_MACHINE_NO_RELA defined RTLD_BOOTSTRAP
305 #ifdef RESOLVE_MAP
307 /* Perform the relocation specified by RELOC and SYM (which is fully resolved).
308 MAP is the object containing the reloc. */
310 auto inline void
311 __attribute ((always_inline))
312 elf_machine_rel (struct link_map *map, const Elf32_Rel *reloc,
313 const Elf32_Sym *sym, const struct r_found_version *version,
314 void *const reloc_addr_arg)
316 Elf32_Addr *const reloc_addr = reloc_addr_arg;
317 const unsigned int r_type = ELF32_R_TYPE (reloc->r_info);
319 # if !defined RTLD_BOOTSTRAP || !defined HAVE_Z_COMBRELOC
320 if (__builtin_expect (r_type == R_386_RELATIVE, 0))
322 # if !defined RTLD_BOOTSTRAP && !defined HAVE_Z_COMBRELOC
323 /* This is defined in rtld.c, but nowhere in the static libc.a;
324 make the reference weak so static programs can still link.
325 This declaration cannot be done when compiling rtld.c
326 (i.e. #ifdef RTLD_BOOTSTRAP) because rtld.c contains the
327 common defn for _dl_rtld_map, which is incompatible with a
328 weak decl in the same file. */
329 # ifndef SHARED
330 weak_extern (_dl_rtld_map);
331 # endif
332 if (map != &GL(dl_rtld_map)) /* Already done in rtld itself. */
333 # endif
334 *reloc_addr += map->l_addr;
336 # ifndef RTLD_BOOTSTRAP
337 else if (__builtin_expect (r_type == R_386_NONE, 0))
338 return;
339 # endif
340 else
341 # endif /* !RTLD_BOOTSTRAP and have no -z combreloc */
343 const Elf32_Sym *const refsym = sym;
344 struct link_map *sym_map = RESOLVE_MAP (&sym, version, r_type);
345 Elf32_Addr value = sym_map == NULL ? 0 : sym_map->l_addr + sym->st_value;
347 if (sym != NULL
348 && __builtin_expect (ELFW(ST_TYPE) (sym->st_info) == STT_GNU_IFUNC,
350 value = ((Elf32_Addr (*) (void)) value) ();
352 switch (r_type)
354 case R_386_GLOB_DAT:
355 case R_386_JMP_SLOT:
356 *reloc_addr = value;
357 break;
359 # if !defined RTLD_BOOTSTRAP || USE___THREAD
360 case R_386_TLS_DTPMOD32:
361 # ifdef RTLD_BOOTSTRAP
362 /* During startup the dynamic linker is always the module
363 with index 1.
364 XXX If this relocation is necessary move before RESOLVE
365 call. */
366 *reloc_addr = 1;
367 # else
368 /* Get the information from the link map returned by the
369 resolv function. */
370 if (sym_map != NULL)
371 *reloc_addr = sym_map->l_tls_modid;
372 # endif
373 break;
374 case R_386_TLS_DTPOFF32:
375 # ifndef RTLD_BOOTSTRAP
376 /* During relocation all TLS symbols are defined and used.
377 Therefore the offset is already correct. */
378 if (sym != NULL)
379 *reloc_addr = sym->st_value;
380 # endif
381 break;
382 case R_386_TLS_DESC:
384 struct tlsdesc volatile *td =
385 (struct tlsdesc volatile *)reloc_addr;
387 # ifndef RTLD_BOOTSTRAP
388 if (! sym)
389 td->entry = _dl_tlsdesc_undefweak;
390 else
391 # endif
393 # ifndef RTLD_BOOTSTRAP
394 # ifndef SHARED
395 CHECK_STATIC_TLS (map, sym_map);
396 # else
397 if (!TRY_STATIC_TLS (map, sym_map))
399 td->arg = _dl_make_tlsdesc_dynamic
400 (sym_map, sym->st_value + (ElfW(Word))td->arg);
401 td->entry = _dl_tlsdesc_dynamic;
403 else
404 # endif
405 # endif
407 td->arg = (void*)(sym->st_value - sym_map->l_tls_offset
408 + (ElfW(Word))td->arg);
409 td->entry = _dl_tlsdesc_return;
412 break;
414 case R_386_TLS_TPOFF32:
415 /* The offset is positive, backward from the thread pointer. */
416 # ifdef RTLD_BOOTSTRAP
417 *reloc_addr += map->l_tls_offset - sym->st_value;
418 # else
419 /* We know the offset of object the symbol is contained in.
420 It is a positive value which will be subtracted from the
421 thread pointer. To get the variable position in the TLS
422 block we subtract the offset from that of the TLS block. */
423 if (sym != NULL)
425 CHECK_STATIC_TLS (map, sym_map);
426 *reloc_addr += sym_map->l_tls_offset - sym->st_value;
428 # endif
429 break;
430 case R_386_TLS_TPOFF:
431 /* The offset is negative, forward from the thread pointer. */
432 # ifdef RTLD_BOOTSTRAP
433 *reloc_addr += sym->st_value - map->l_tls_offset;
434 # else
435 /* We know the offset of object the symbol is contained in.
436 It is a negative value which will be added to the
437 thread pointer. */
438 if (sym != NULL)
440 CHECK_STATIC_TLS (map, sym_map);
441 *reloc_addr += sym->st_value - sym_map->l_tls_offset;
443 # endif
444 break;
445 # endif /* use TLS */
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 ?: "<program name unknown>",
469 strtab + refsym->st_name);
471 memcpy (reloc_addr_arg, (void *) value,
472 MIN (sym->st_size, refsym->st_size));
473 break;
474 default:
475 _dl_reloc_bad_type (map, r_type, 0);
476 break;
477 # endif /* !RTLD_BOOTSTRAP */
482 # ifndef RTLD_BOOTSTRAP
483 auto inline void
484 __attribute__ ((always_inline))
485 elf_machine_rela (struct link_map *map, const Elf32_Rela *reloc,
486 const Elf32_Sym *sym, const struct r_found_version *version,
487 void *const reloc_addr_arg)
489 Elf32_Addr *const reloc_addr = reloc_addr_arg;
490 const unsigned int r_type = ELF32_R_TYPE (reloc->r_info);
492 if (ELF32_R_TYPE (reloc->r_info) == R_386_RELATIVE)
493 *reloc_addr = map->l_addr + reloc->r_addend;
494 else if (r_type != R_386_NONE)
496 # ifndef RESOLVE_CONFLICT_FIND_MAP
497 const Elf32_Sym *const refsym = sym;
498 # endif
499 struct link_map *sym_map = RESOLVE_MAP (&sym, version, r_type);
500 Elf32_Addr value = sym == NULL ? 0 : sym_map->l_addr + sym->st_value;
502 if (sym != NULL
503 && __builtin_expect (ELFW(ST_TYPE) (sym->st_info) == STT_GNU_IFUNC,
505 value = ((Elf32_Addr (*) (void)) value) ();
507 switch (ELF32_R_TYPE (reloc->r_info))
509 case R_386_GLOB_DAT:
510 case R_386_JMP_SLOT:
511 case R_386_32:
512 *reloc_addr = value + reloc->r_addend;
513 break;
514 # ifndef RESOLVE_CONFLICT_FIND_MAP
515 /* Not needed for dl-conflict.c. */
516 case R_386_PC32:
517 *reloc_addr = (value + reloc->r_addend - (Elf32_Addr) reloc_addr);
518 break;
520 case R_386_TLS_DTPMOD32:
521 /* Get the information from the link map returned by the
522 resolv function. */
523 if (sym_map != NULL)
524 *reloc_addr = sym_map->l_tls_modid;
525 break;
526 case R_386_TLS_DTPOFF32:
527 /* During relocation all TLS symbols are defined and used.
528 Therefore the offset is already correct. */
529 *reloc_addr = (sym == NULL ? 0 : sym->st_value) + reloc->r_addend;
530 break;
531 case R_386_TLS_DESC:
533 struct tlsdesc volatile *td =
534 (struct tlsdesc volatile *)reloc_addr;
536 # ifndef RTLD_BOOTSTRAP
537 if (!sym)
539 td->arg = (void*)reloc->r_addend;
540 td->entry = _dl_tlsdesc_undefweak;
542 else
543 # endif
545 # ifndef RTLD_BOOTSTRAP
546 # ifndef SHARED
547 CHECK_STATIC_TLS (map, sym_map);
548 # else
549 if (!TRY_STATIC_TLS (map, sym_map))
551 td->arg = _dl_make_tlsdesc_dynamic
552 (sym_map, sym->st_value + reloc->r_addend);
553 td->entry = _dl_tlsdesc_dynamic;
555 else
556 # endif
557 # endif
559 td->arg = (void*)(sym->st_value - sym_map->l_tls_offset
560 + reloc->r_addend);
561 td->entry = _dl_tlsdesc_return;
565 break;
566 case R_386_TLS_TPOFF32:
567 /* The offset is positive, backward from the thread pointer. */
568 /* We know the offset of object the symbol is contained in.
569 It is a positive value which will be subtracted from the
570 thread pointer. To get the variable position in the TLS
571 block we subtract the offset from that of the TLS block. */
572 if (sym != NULL)
574 CHECK_STATIC_TLS (map, sym_map);
575 *reloc_addr = sym_map->l_tls_offset - sym->st_value
576 + reloc->r_addend;
578 break;
579 case R_386_TLS_TPOFF:
580 /* The offset is negative, forward from the thread pointer. */
581 /* We know the offset of object the symbol is contained in.
582 It is a negative value which will be added to the
583 thread pointer. */
584 if (sym != NULL)
586 CHECK_STATIC_TLS (map, sym_map);
587 *reloc_addr = sym->st_value - sym_map->l_tls_offset
588 + reloc->r_addend;
590 break;
591 case R_386_COPY:
592 if (sym == NULL)
593 /* This can happen in trace mode if an object could not be
594 found. */
595 break;
596 if (__builtin_expect (sym->st_size > refsym->st_size, 0)
597 || (__builtin_expect (sym->st_size < refsym->st_size, 0)
598 && GLRO(dl_verbose)))
600 const char *strtab;
602 strtab = (const char *) D_PTR (map, l_info[DT_STRTAB]);
603 _dl_error_printf ("\
604 %s: Symbol `%s' has different size in shared object, consider re-linking\n",
605 rtld_progname ?: "<program name unknown>",
606 strtab + refsym->st_name);
608 memcpy (reloc_addr_arg, (void *) value,
609 MIN (sym->st_size, refsym->st_size));
610 break;
611 # endif /* !RESOLVE_CONFLICT_FIND_MAP */
612 default:
613 /* We add these checks in the version to relocate ld.so only
614 if we are still debugging. */
615 _dl_reloc_bad_type (map, r_type, 0);
616 break;
620 # endif /* !RTLD_BOOTSTRAP */
622 auto inline void
623 __attribute ((always_inline))
624 elf_machine_rel_relative (Elf32_Addr l_addr, const Elf32_Rel *reloc,
625 void *const reloc_addr_arg)
627 Elf32_Addr *const reloc_addr = reloc_addr_arg;
628 assert (ELF32_R_TYPE (reloc->r_info) == R_386_RELATIVE);
629 *reloc_addr += l_addr;
632 # ifndef RTLD_BOOTSTRAP
633 auto inline void
634 __attribute__ ((always_inline))
635 elf_machine_rela_relative (Elf32_Addr l_addr, const Elf32_Rela *reloc,
636 void *const reloc_addr_arg)
638 Elf32_Addr *const reloc_addr = reloc_addr_arg;
639 *reloc_addr = l_addr + reloc->r_addend;
641 # endif /* !RTLD_BOOTSTRAP */
643 auto inline void
644 __attribute__ ((always_inline))
645 elf_machine_lazy_rel (struct link_map *map,
646 Elf32_Addr l_addr, const Elf32_Rel *reloc)
648 Elf32_Addr *const reloc_addr = (void *) (l_addr + reloc->r_offset);
649 const unsigned int r_type = ELF32_R_TYPE (reloc->r_info);
650 /* Check for unexpected PLT reloc type. */
651 if (__builtin_expect (r_type == R_386_JMP_SLOT, 1))
653 if (__builtin_expect (map->l_mach.plt, 0) == 0)
654 *reloc_addr += l_addr;
655 else
656 *reloc_addr = (map->l_mach.plt
657 + (((Elf32_Addr) reloc_addr) - map->l_mach.gotplt) * 4);
659 else if (__builtin_expect (r_type == R_386_TLS_DESC, 1))
661 struct tlsdesc volatile * __attribute__((__unused__)) td =
662 (struct tlsdesc volatile *)reloc_addr;
664 /* Handle relocations that reference the local *ABS* in a simple
665 way, so as to preserve a potential addend. */
666 if (ELF32_R_SYM (reloc->r_info) == 0)
667 td->entry = _dl_tlsdesc_resolve_abs_plus_addend;
668 /* Given a known-zero addend, we can store a pointer to the
669 reloc in the arg position. */
670 else if (td->arg == 0)
672 td->arg = (void*)reloc;
673 td->entry = _dl_tlsdesc_resolve_rel;
675 else
677 /* We could handle non-*ABS* relocations with non-zero addends
678 by allocating dynamically an arg to hold a pointer to the
679 reloc, but that sounds pointless. */
680 const Elf32_Rel *const r = reloc;
681 /* The code below was borrowed from elf_dynamic_do_rel(). */
682 const ElfW(Sym) *const symtab =
683 (const void *) D_PTR (map, l_info[DT_SYMTAB]);
685 # ifdef RTLD_BOOTSTRAP
686 /* The dynamic linker always uses versioning. */
687 assert (map->l_info[VERSYMIDX (DT_VERSYM)] != NULL);
688 # else
689 if (map->l_info[VERSYMIDX (DT_VERSYM)])
690 # endif
692 const ElfW(Half) *const version =
693 (const void *) D_PTR (map, l_info[VERSYMIDX (DT_VERSYM)]);
694 ElfW(Half) ndx = version[ELFW(R_SYM) (r->r_info)] & 0x7fff;
695 elf_machine_rel (map, r, &symtab[ELFW(R_SYM) (r->r_info)],
696 &map->l_versions[ndx],
697 (void *) (l_addr + r->r_offset));
699 # ifndef RTLD_BOOTSTRAP
700 else
701 elf_machine_rel (map, r, &symtab[ELFW(R_SYM) (r->r_info)], NULL,
702 (void *) (l_addr + r->r_offset));
703 # endif
706 else
707 _dl_reloc_bad_type (map, r_type, 1);
710 # ifndef RTLD_BOOTSTRAP
712 auto inline void
713 __attribute__ ((always_inline))
714 elf_machine_lazy_rela (struct link_map *map,
715 Elf32_Addr l_addr, const Elf32_Rela *reloc)
717 Elf32_Addr *const reloc_addr = (void *) (l_addr + reloc->r_offset);
718 const unsigned int r_type = ELF32_R_TYPE (reloc->r_info);
719 if (__builtin_expect (r_type == R_386_JMP_SLOT, 1))
721 else if (__builtin_expect (r_type == R_386_TLS_DESC, 1))
723 struct tlsdesc volatile * __attribute__((__unused__)) td =
724 (struct tlsdesc volatile *)reloc_addr;
726 td->arg = (void*)reloc;
727 td->entry = _dl_tlsdesc_resolve_rela;
729 else
730 _dl_reloc_bad_type (map, r_type, 1);
733 # endif /* !RTLD_BOOTSTRAP */
735 #endif /* RESOLVE_MAP */