]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/i386/dl-machine.h
e38fae6e19d802faea84fad016bc98d456279ca7
[thirdparty/glibc.git] / sysdeps / i386 / dl-machine.h
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.
4
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.
9
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.
14
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/>. */
18
19 #ifndef dl_machine_h
20 #define dl_machine_h
21
22 #define ELF_MACHINE_NAME "i386"
23
24 #include <sys/param.h>
25 #include <sysdep.h>
26 #include <tls.h>
27 #include <dl-tlsdesc.h>
28
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)
32 {
33 return ehdr->e_machine == EM_386;
34 }
35
36
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)
41 {
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];
47 }
48
49 /* Return the run-time load address of the shared object. */
50 static inline Elf32_Addr __attribute__ ((unused))
51 elf_machine_load_address (void)
52 {
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 ();
58 }
59
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. */
62
63 static inline int __attribute__ ((unused, always_inline))
64 elf_machine_runtime_setup (struct link_map *l, int lazy, int profile)
65 {
66 Elf32_Addr *got;
67 extern void _dl_runtime_resolve (Elf32_Word) attribute_hidden;
68 extern void _dl_runtime_profile (Elf32_Word) attribute_hidden;
69
70 if (l->l_info[DT_JMPREL] && lazy)
71 {
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])
81 {
82 l->l_mach.plt = got[1] + l->l_addr;
83 l->l_mach.gotplt = (Elf32_Addr) &got[3];
84 }
85 got[1] = (Elf32_Addr) l; /* Identify this shared object. */
86
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))
94 {
95 got[2] = (Elf32_Addr) &_dl_runtime_profile;
96
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;
102 }
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;
107 }
108
109 return lazy;
110 }
111
112 #ifdef IN_DL_RUNTIME
113
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.
118
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))
122
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
132
133 #endif
134
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
138
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. */
142
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\
199 ");
200
201 #ifndef RTLD_START_SPECIAL_INIT
202 # define RTLD_START_SPECIAL_INIT /* nothing */
203 #endif
204
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_NOCOPY iff TYPE should not be allowed to resolve to one
209 of the main executable's symbols, as for a COPY reloc. */
210 # define elf_machine_type_class(type) \
211 ((((type) == R_386_JMP_SLOT || (type) == R_386_TLS_DTPMOD32 \
212 || (type) == R_386_TLS_DTPOFF32 || (type) == R_386_TLS_TPOFF32 \
213 || (type) == R_386_TLS_TPOFF || (type) == R_386_TLS_DESC) \
214 * ELF_RTYPE_CLASS_PLT) \
215 | (((type) == R_386_COPY) * ELF_RTYPE_CLASS_COPY))
216
217 /* A reloc type used for ld.so cmdline arg lookups to reject PLT entries. */
218 #define ELF_MACHINE_JMP_SLOT R_386_JMP_SLOT
219
220 /* The i386 never uses Elf32_Rela relocations for the dynamic linker.
221 Prelinked libraries may use Elf32_Rela though. */
222 #define ELF_MACHINE_PLT_REL 1
223
224 /* We define an initialization functions. This is called very early in
225 _dl_sysdep_start. */
226 #define DL_PLATFORM_INIT dl_platform_init ()
227
228 static inline void __attribute__ ((unused))
229 dl_platform_init (void)
230 {
231 if (GLRO(dl_platform) != NULL && *GLRO(dl_platform) == '\0')
232 /* Avoid an empty string which would disturb us. */
233 GLRO(dl_platform) = NULL;
234 }
235
236 static inline Elf32_Addr
237 elf_machine_fixup_plt (struct link_map *map, lookup_t t,
238 const Elf32_Rel *reloc,
239 Elf32_Addr *reloc_addr, Elf32_Addr value)
240 {
241 return *reloc_addr = value;
242 }
243
244 /* Return the final value of a plt relocation. */
245 static inline Elf32_Addr
246 elf_machine_plt_value (struct link_map *map, const Elf32_Rel *reloc,
247 Elf32_Addr value)
248 {
249 return value;
250 }
251
252
253 /* Names of the architecture-specific auditing callback functions. */
254 #define ARCH_LA_PLTENTER i86_gnu_pltenter
255 #define ARCH_LA_PLTEXIT i86_gnu_pltexit
256
257 #endif /* !dl_machine_h */
258
259 /* The i386 never uses Elf32_Rela relocations for the dynamic linker.
260 Prelinked libraries may use Elf32_Rela though. */
261 #define ELF_MACHINE_NO_RELA defined RTLD_BOOTSTRAP
262 #define ELF_MACHINE_NO_REL 0
263
264 #ifdef RESOLVE_MAP
265
266 /* Perform the relocation specified by RELOC and SYM (which is fully resolved).
267 MAP is the object containing the reloc. */
268
269 auto inline void
270 __attribute ((always_inline))
271 elf_machine_rel (struct link_map *map, const Elf32_Rel *reloc,
272 const Elf32_Sym *sym, const struct r_found_version *version,
273 void *const reloc_addr_arg, int skip_ifunc)
274 {
275 Elf32_Addr *const reloc_addr = reloc_addr_arg;
276 const unsigned int r_type = ELF32_R_TYPE (reloc->r_info);
277
278 # if !defined RTLD_BOOTSTRAP || !defined HAVE_Z_COMBRELOC
279 if (__glibc_unlikely (r_type == R_386_RELATIVE))
280 {
281 # if !defined RTLD_BOOTSTRAP && !defined HAVE_Z_COMBRELOC
282 /* This is defined in rtld.c, but nowhere in the static libc.a;
283 make the reference weak so static programs can still link.
284 This declaration cannot be done when compiling rtld.c
285 (i.e. #ifdef RTLD_BOOTSTRAP) because rtld.c contains the
286 common defn for _dl_rtld_map, which is incompatible with a
287 weak decl in the same file. */
288 # ifndef SHARED
289 weak_extern (_dl_rtld_map);
290 # endif
291 if (map != &GL(dl_rtld_map)) /* Already done in rtld itself. */
292 # endif
293 *reloc_addr += map->l_addr;
294 }
295 # ifndef RTLD_BOOTSTRAP
296 else if (__glibc_unlikely (r_type == R_386_NONE))
297 return;
298 # endif
299 else
300 # endif /* !RTLD_BOOTSTRAP and have no -z combreloc */
301 {
302 # ifndef RTLD_BOOTSTRAP
303 const Elf32_Sym *const refsym = sym;
304 # endif
305 struct link_map *sym_map = RESOLVE_MAP (&sym, version, r_type);
306 Elf32_Addr value = sym_map == NULL ? 0 : sym_map->l_addr + sym->st_value;
307
308 if (sym != NULL
309 && __builtin_expect (ELFW(ST_TYPE) (sym->st_info) == STT_GNU_IFUNC,
310 0)
311 && __builtin_expect (sym->st_shndx != SHN_UNDEF, 1)
312 && __builtin_expect (!skip_ifunc, 1))
313 value = ((Elf32_Addr (*) (void)) value) ();
314
315 switch (r_type)
316 {
317 # ifndef RTLD_BOOTSTRAP
318 case R_386_SIZE32:
319 /* Set to symbol size plus addend. */
320 *reloc_addr += sym->st_size;
321 break;
322 # endif
323 case R_386_GLOB_DAT:
324 case R_386_JMP_SLOT:
325 *reloc_addr = value;
326 break;
327
328 case R_386_TLS_DTPMOD32:
329 # ifdef RTLD_BOOTSTRAP
330 /* During startup the dynamic linker is always the module
331 with index 1.
332 XXX If this relocation is necessary move before RESOLVE
333 call. */
334 *reloc_addr = 1;
335 # else
336 /* Get the information from the link map returned by the
337 resolv function. */
338 if (sym_map != NULL)
339 *reloc_addr = sym_map->l_tls_modid;
340 # endif
341 break;
342 case R_386_TLS_DTPOFF32:
343 # ifndef RTLD_BOOTSTRAP
344 /* During relocation all TLS symbols are defined and used.
345 Therefore the offset is already correct. */
346 if (sym != NULL)
347 *reloc_addr = sym->st_value;
348 # endif
349 break;
350 case R_386_TLS_DESC:
351 {
352 struct tlsdesc volatile *td =
353 (struct tlsdesc volatile *)reloc_addr;
354
355 # ifndef RTLD_BOOTSTRAP
356 if (! sym)
357 td->entry = _dl_tlsdesc_undefweak;
358 else
359 # endif
360 {
361 # ifndef RTLD_BOOTSTRAP
362 # ifndef SHARED
363 CHECK_STATIC_TLS (map, sym_map);
364 # else
365 if (!TRY_STATIC_TLS (map, sym_map))
366 {
367 td->arg = _dl_make_tlsdesc_dynamic
368 (sym_map, sym->st_value + (ElfW(Word))td->arg);
369 td->entry = _dl_tlsdesc_dynamic;
370 }
371 else
372 # endif
373 # endif
374 {
375 td->arg = (void*)(sym->st_value - sym_map->l_tls_offset
376 + (ElfW(Word))td->arg);
377 td->entry = _dl_tlsdesc_return;
378 }
379 }
380 break;
381 }
382 case R_386_TLS_TPOFF32:
383 /* The offset is positive, backward from the thread pointer. */
384 # ifdef RTLD_BOOTSTRAP
385 *reloc_addr += map->l_tls_offset - sym->st_value;
386 # else
387 /* We know the offset of object the symbol is contained in.
388 It is a positive value which will be subtracted from the
389 thread pointer. To get the variable position in the TLS
390 block we subtract the offset from that of the TLS block. */
391 if (sym != NULL)
392 {
393 CHECK_STATIC_TLS (map, sym_map);
394 *reloc_addr += sym_map->l_tls_offset - sym->st_value;
395 }
396 # endif
397 break;
398 case R_386_TLS_TPOFF:
399 /* The offset is negative, forward from the thread pointer. */
400 # ifdef RTLD_BOOTSTRAP
401 *reloc_addr += sym->st_value - map->l_tls_offset;
402 # else
403 /* We know the offset of object the symbol is contained in.
404 It is a negative value which will be added to the
405 thread pointer. */
406 if (sym != NULL)
407 {
408 CHECK_STATIC_TLS (map, sym_map);
409 *reloc_addr += sym->st_value - sym_map->l_tls_offset;
410 }
411 # endif
412 break;
413
414 # ifndef RTLD_BOOTSTRAP
415 case R_386_32:
416 *reloc_addr += value;
417 break;
418 case R_386_PC32:
419 *reloc_addr += (value - (Elf32_Addr) reloc_addr);
420 break;
421 case R_386_COPY:
422 if (sym == NULL)
423 /* This can happen in trace mode if an object could not be
424 found. */
425 break;
426 if (__builtin_expect (sym->st_size > refsym->st_size, 0)
427 || (__builtin_expect (sym->st_size < refsym->st_size, 0)
428 && GLRO(dl_verbose)))
429 {
430 const char *strtab;
431
432 strtab = (const char *) D_PTR (map, l_info[DT_STRTAB]);
433 _dl_error_printf ("\
434 %s: Symbol `%s' has different size in shared object, consider re-linking\n",
435 RTLD_PROGNAME, strtab + refsym->st_name);
436 }
437 memcpy (reloc_addr_arg, (void *) value,
438 MIN (sym->st_size, refsym->st_size));
439 break;
440 case R_386_IRELATIVE:
441 value = map->l_addr + *reloc_addr;
442 value = ((Elf32_Addr (*) (void)) value) ();
443 *reloc_addr = value;
444 break;
445 default:
446 _dl_reloc_bad_type (map, r_type, 0);
447 break;
448 # endif /* !RTLD_BOOTSTRAP */
449 }
450 }
451 }
452
453 # ifndef RTLD_BOOTSTRAP
454 auto inline void
455 __attribute__ ((always_inline))
456 elf_machine_rela (struct link_map *map, const Elf32_Rela *reloc,
457 const Elf32_Sym *sym, const struct r_found_version *version,
458 void *const reloc_addr_arg, int skip_ifunc)
459 {
460 Elf32_Addr *const reloc_addr = reloc_addr_arg;
461 const unsigned int r_type = ELF32_R_TYPE (reloc->r_info);
462
463 if (ELF32_R_TYPE (reloc->r_info) == R_386_RELATIVE)
464 *reloc_addr = map->l_addr + reloc->r_addend;
465 else if (r_type != R_386_NONE)
466 {
467 # ifndef RESOLVE_CONFLICT_FIND_MAP
468 const Elf32_Sym *const refsym = sym;
469 # endif
470 struct link_map *sym_map = RESOLVE_MAP (&sym, version, r_type);
471 Elf32_Addr value = sym == NULL ? 0 : sym_map->l_addr + sym->st_value;
472
473 if (sym != NULL
474 && __builtin_expect (sym->st_shndx != SHN_UNDEF, 1)
475 && __builtin_expect (ELFW(ST_TYPE) (sym->st_info) == STT_GNU_IFUNC, 0)
476 && __builtin_expect (!skip_ifunc, 1))
477 value = ((Elf32_Addr (*) (void)) value) ();
478
479 switch (ELF32_R_TYPE (reloc->r_info))
480 {
481 case R_386_SIZE32:
482 /* Set to symbol size plus addend. */
483 value = sym->st_size;
484 case R_386_GLOB_DAT:
485 case R_386_JMP_SLOT:
486 case R_386_32:
487 *reloc_addr = value + reloc->r_addend;
488 break;
489 # ifndef RESOLVE_CONFLICT_FIND_MAP
490 /* Not needed for dl-conflict.c. */
491 case R_386_PC32:
492 *reloc_addr = (value + reloc->r_addend - (Elf32_Addr) reloc_addr);
493 break;
494
495 case R_386_TLS_DTPMOD32:
496 /* Get the information from the link map returned by the
497 resolv function. */
498 if (sym_map != NULL)
499 *reloc_addr = sym_map->l_tls_modid;
500 break;
501 case R_386_TLS_DTPOFF32:
502 /* During relocation all TLS symbols are defined and used.
503 Therefore the offset is already correct. */
504 *reloc_addr = (sym == NULL ? 0 : sym->st_value) + reloc->r_addend;
505 break;
506 case R_386_TLS_DESC:
507 {
508 struct tlsdesc volatile *td =
509 (struct tlsdesc volatile *)reloc_addr;
510
511 # ifndef RTLD_BOOTSTRAP
512 if (!sym)
513 {
514 td->arg = (void*)reloc->r_addend;
515 td->entry = _dl_tlsdesc_undefweak;
516 }
517 else
518 # endif
519 {
520 # ifndef RTLD_BOOTSTRAP
521 # ifndef SHARED
522 CHECK_STATIC_TLS (map, sym_map);
523 # else
524 if (!TRY_STATIC_TLS (map, sym_map))
525 {
526 td->arg = _dl_make_tlsdesc_dynamic
527 (sym_map, sym->st_value + reloc->r_addend);
528 td->entry = _dl_tlsdesc_dynamic;
529 }
530 else
531 # endif
532 # endif
533 {
534 td->arg = (void*)(sym->st_value - sym_map->l_tls_offset
535 + reloc->r_addend);
536 td->entry = _dl_tlsdesc_return;
537 }
538 }
539 }
540 break;
541 case R_386_TLS_TPOFF32:
542 /* The offset is positive, backward from the thread pointer. */
543 /* We know the offset of object the symbol is contained in.
544 It is a positive value which will be subtracted from the
545 thread pointer. To get the variable position in the TLS
546 block we subtract the offset from that of the TLS block. */
547 if (sym != NULL)
548 {
549 CHECK_STATIC_TLS (map, sym_map);
550 *reloc_addr = sym_map->l_tls_offset - sym->st_value
551 + reloc->r_addend;
552 }
553 break;
554 case R_386_TLS_TPOFF:
555 /* The offset is negative, forward from the thread pointer. */
556 /* We know the offset of object the symbol is contained in.
557 It is a negative value which will be added to the
558 thread pointer. */
559 if (sym != NULL)
560 {
561 CHECK_STATIC_TLS (map, sym_map);
562 *reloc_addr = sym->st_value - sym_map->l_tls_offset
563 + reloc->r_addend;
564 }
565 break;
566 case R_386_COPY:
567 if (sym == NULL)
568 /* This can happen in trace mode if an object could not be
569 found. */
570 break;
571 if (__builtin_expect (sym->st_size > refsym->st_size, 0)
572 || (__builtin_expect (sym->st_size < refsym->st_size, 0)
573 && GLRO(dl_verbose)))
574 {
575 const char *strtab;
576
577 strtab = (const char *) D_PTR (map, l_info[DT_STRTAB]);
578 _dl_error_printf ("\
579 %s: Symbol `%s' has different size in shared object, consider re-linking\n",
580 RTLD_PROGNAME, strtab + refsym->st_name);
581 }
582 memcpy (reloc_addr_arg, (void *) value,
583 MIN (sym->st_size, refsym->st_size));
584 break;
585 # endif /* !RESOLVE_CONFLICT_FIND_MAP */
586 case R_386_IRELATIVE:
587 value = map->l_addr + reloc->r_addend;
588 value = ((Elf32_Addr (*) (void)) value) ();
589 *reloc_addr = value;
590 break;
591 default:
592 /* We add these checks in the version to relocate ld.so only
593 if we are still debugging. */
594 _dl_reloc_bad_type (map, r_type, 0);
595 break;
596 }
597 }
598 }
599 # endif /* !RTLD_BOOTSTRAP */
600
601 auto inline void
602 __attribute ((always_inline))
603 elf_machine_rel_relative (Elf32_Addr l_addr, const Elf32_Rel *reloc,
604 void *const reloc_addr_arg)
605 {
606 Elf32_Addr *const reloc_addr = reloc_addr_arg;
607 assert (ELF32_R_TYPE (reloc->r_info) == R_386_RELATIVE);
608 *reloc_addr += l_addr;
609 }
610
611 # ifndef RTLD_BOOTSTRAP
612 auto inline void
613 __attribute__ ((always_inline))
614 elf_machine_rela_relative (Elf32_Addr l_addr, const Elf32_Rela *reloc,
615 void *const reloc_addr_arg)
616 {
617 Elf32_Addr *const reloc_addr = reloc_addr_arg;
618 *reloc_addr = l_addr + reloc->r_addend;
619 }
620 # endif /* !RTLD_BOOTSTRAP */
621
622 auto inline void
623 __attribute__ ((always_inline))
624 elf_machine_lazy_rel (struct link_map *map,
625 Elf32_Addr l_addr, const Elf32_Rel *reloc,
626 int skip_ifunc)
627 {
628 Elf32_Addr *const reloc_addr = (void *) (l_addr + reloc->r_offset);
629 const unsigned int r_type = ELF32_R_TYPE (reloc->r_info);
630 /* Check for unexpected PLT reloc type. */
631 if (__glibc_likely (r_type == R_386_JMP_SLOT))
632 {
633 if (__builtin_expect (map->l_mach.plt, 0) == 0)
634 *reloc_addr += l_addr;
635 else
636 *reloc_addr = (map->l_mach.plt
637 + (((Elf32_Addr) reloc_addr) - map->l_mach.gotplt) * 4);
638 }
639 else if (__glibc_likely (r_type == R_386_TLS_DESC))
640 {
641 struct tlsdesc volatile * __attribute__((__unused__)) td =
642 (struct tlsdesc volatile *)reloc_addr;
643
644 /* Handle relocations that reference the local *ABS* in a simple
645 way, so as to preserve a potential addend. */
646 if (ELF32_R_SYM (reloc->r_info) == 0)
647 td->entry = _dl_tlsdesc_resolve_abs_plus_addend;
648 /* Given a known-zero addend, we can store a pointer to the
649 reloc in the arg position. */
650 else if (td->arg == 0)
651 {
652 td->arg = (void*)reloc;
653 td->entry = _dl_tlsdesc_resolve_rel;
654 }
655 else
656 {
657 /* We could handle non-*ABS* relocations with non-zero addends
658 by allocating dynamically an arg to hold a pointer to the
659 reloc, but that sounds pointless. */
660 const Elf32_Rel *const r = reloc;
661 /* The code below was borrowed from elf_dynamic_do_rel(). */
662 const ElfW(Sym) *const symtab =
663 (const void *) D_PTR (map, l_info[DT_SYMTAB]);
664
665 # ifdef RTLD_BOOTSTRAP
666 /* The dynamic linker always uses versioning. */
667 assert (map->l_info[VERSYMIDX (DT_VERSYM)] != NULL);
668 # else
669 if (map->l_info[VERSYMIDX (DT_VERSYM)])
670 # endif
671 {
672 const ElfW(Half) *const version =
673 (const void *) D_PTR (map, l_info[VERSYMIDX (DT_VERSYM)]);
674 ElfW(Half) ndx = version[ELFW(R_SYM) (r->r_info)] & 0x7fff;
675 elf_machine_rel (map, r, &symtab[ELFW(R_SYM) (r->r_info)],
676 &map->l_versions[ndx],
677 (void *) (l_addr + r->r_offset), skip_ifunc);
678 }
679 # ifndef RTLD_BOOTSTRAP
680 else
681 elf_machine_rel (map, r, &symtab[ELFW(R_SYM) (r->r_info)], NULL,
682 (void *) (l_addr + r->r_offset), skip_ifunc);
683 # endif
684 }
685 }
686 else if (__glibc_unlikely (r_type == R_386_IRELATIVE))
687 {
688 Elf32_Addr value = map->l_addr + *reloc_addr;
689 if (__glibc_likely (!skip_ifunc))
690 value = ((Elf32_Addr (*) (void)) value) ();
691 *reloc_addr = value;
692 }
693 else
694 _dl_reloc_bad_type (map, r_type, 1);
695 }
696
697 # ifndef RTLD_BOOTSTRAP
698
699 auto inline void
700 __attribute__ ((always_inline))
701 elf_machine_lazy_rela (struct link_map *map,
702 Elf32_Addr l_addr, const Elf32_Rela *reloc,
703 int skip_ifunc)
704 {
705 Elf32_Addr *const reloc_addr = (void *) (l_addr + reloc->r_offset);
706 const unsigned int r_type = ELF32_R_TYPE (reloc->r_info);
707 if (__glibc_likely (r_type == R_386_JMP_SLOT))
708 ;
709 else if (__glibc_likely (r_type == R_386_TLS_DESC))
710 {
711 struct tlsdesc volatile * __attribute__((__unused__)) td =
712 (struct tlsdesc volatile *)reloc_addr;
713
714 td->arg = (void*)reloc;
715 td->entry = _dl_tlsdesc_resolve_rela;
716 }
717 else if (__glibc_unlikely (r_type == R_386_IRELATIVE))
718 {
719 Elf32_Addr value = map->l_addr + reloc->r_addend;
720 if (__glibc_likely (!skip_ifunc))
721 value = ((Elf32_Addr (*) (void)) value) ();
722 *reloc_addr = value;
723 }
724 else
725 _dl_reloc_bad_type (map, r_type, 1);
726 }
727
728 # endif /* !RTLD_BOOTSTRAP */
729
730 #endif /* RESOLVE_MAP */