Warning: That file was not part of the compilation database. It may have many parsing errors.

1/* Machine-dependent ELF dynamic relocation inline functions. i386 version.
2 Copyright (C) 1995-2019 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#include <cpu-features.c>
29
30/* Return nonzero iff ELF header is compatible with the running host. */
31static inline int __attribute__ ((unused))
32elf_machine_matches_host (const Elf32_Ehdr *ehdr)
33{
34 return ehdr->e_machine == EM_386;
35}
36
37
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. */
40static inline Elf32_Addr __attribute__ ((unused, const))
41elf_machine_dynamic (void)
42{
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];
48}
49
50/* Return the run-time load address of the shared object. */
51static inline Elf32_Addr __attribute__ ((unused))
52elf_machine_load_address (void)
53{
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 ();
59}
60
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. */
63
64static inline int __attribute__ ((unused, always_inline))
65elf_machine_runtime_setup (struct link_map *l, int lazy, int profile)
66{
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)[0] & GNU_PROPERTY_X86_FEATURE_1_SHSTK) != 0;
75
76 if (l->l_info[DT_JMPREL] && lazy)
77 {
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])
87 {
88 l->l_mach.plt = got[1] + l->l_addr;
89 l->l_mach.gotplt = (Elf32_Addr) &got[3];
90 }
91 got[1] = (Elf32_Addr) l; /* Identify this shared object. */
92
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))
100 {
101 got[2] = (shstk_enabled
102 ? (Elf32_Addr) &_dl_runtime_profile_shstk
103 : (Elf32_Addr) &_dl_runtime_profile);
104
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;
110 }
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);
117 }
118
119 return lazy;
120}
121
122#ifdef IN_DL_RUNTIME
123
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.
128
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))
132
133extern ElfW(Addr) _dl_fixup (struct link_map *l,
134 ElfW(Word) reloc_offset)
135 ARCH_FIXUP_ATTRIBUTE;
136extern 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
142
143#endif
144
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
148
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. */
152
153#define RTLD_START asm ("\n\
154 .text\n\
155 .align 16\n\
1560: 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\
214");
215
216#ifndef RTLD_START_SPECIAL_INIT
217# define RTLD_START_SPECIAL_INIT /* nothing */
218#endif
219
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.
227 */
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))
235
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
238
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
242
243/* We define an initialization functions. This is called very early in
244 _dl_sysdep_start. */
245#define DL_PLATFORM_INIT dl_platform_init ()
246
247static inline void __attribute__ ((unused))
248dl_platform_init (void)
249{
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
259}
260
261static inline Elf32_Addr
262elf_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)
266{
267 return *reloc_addr = value;
268}
269
270/* Return the final value of a plt relocation. */
271static inline Elf32_Addr
272elf_machine_plt_value (struct link_map *map, const Elf32_Rel *reloc,
273 Elf32_Addr value)
274{
275 return value;
276}
277
278
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
282
283#endif /* !dl_machine_h */
284
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
289
290#ifdef RESOLVE_MAP
291
292/* Perform the relocation specified by RELOC and SYM (which is fully resolved).
293 MAP is the object containing the reloc. */
294
295auto inline void
296__attribute ((always_inline))
297elf_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)
300{
301 Elf32_Addr *const reloc_addr = reloc_addr_arg;
302 const unsigned int r_type = ELF32_R_TYPE (reloc->r_info);
303
304# if !defined RTLD_BOOTSTRAP || !defined HAVE_Z_COMBRELOC
305 if (__glibc_unlikely (r_type == R_386_RELATIVE))
306 {
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;
320 }
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 */
327 {
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);
333
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))
338 {
339# ifndef RTLD_BOOTSTRAP
340 if (sym_map != map
341 && sym_map->l_type != lt_executable
342 && !sym_map->l_relocated)
343 {
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);
351 }
352# endif
353 value = ((Elf32_Addr (*) (void)) value) ();
354 }
355
356 switch (r_type)
357 {
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;
368
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:
392 {
393 struct tlsdesc volatile *td =
394 (struct tlsdesc volatile *)reloc_addr;
395
396# ifndef RTLD_BOOTSTRAP
397 if (! sym)
398 td->entry = _dl_tlsdesc_undefweak;
399 else
400# endif
401 {
402# ifndef RTLD_BOOTSTRAP
403# ifndef SHARED
404 CHECK_STATIC_TLS (map, sym_map);
405# else
406 if (!TRY_STATIC_TLS (map, sym_map))
407 {
408 td->arg = _dl_make_tlsdesc_dynamic
409 (sym_map, sym->st_value + (ElfW(Word))td->arg);
410 td->entry = _dl_tlsdesc_dynamic;
411 }
412 else
413# endif
414# endif
415 {
416 td->arg = (void*)(sym->st_value - sym_map->l_tls_offset
417 + (ElfW(Word))td->arg);
418 td->entry = _dl_tlsdesc_return;
419 }
420 }
421 break;
422 }
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)
433 {
434 CHECK_STATIC_TLS (map, sym_map);
435 *reloc_addr += sym_map->l_tls_offset - sym->st_value;
436 }
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)
448 {
449 CHECK_STATIC_TLS (map, sym_map);
450 *reloc_addr += sym->st_value - sym_map->l_tls_offset;
451 }
452# endif
453 break;
454
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)))
470 {
471 const char *strtab;
472
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);
477 }
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 value = ((Elf32_Addr (*) (void)) value) ();
484 *reloc_addr = value;
485 break;
486 default:
487 _dl_reloc_bad_type (map, r_type, 0);
488 break;
489# endif /* !RTLD_BOOTSTRAP */
490 }
491 }
492}
493
494# ifndef RTLD_BOOTSTRAP
495auto inline void
496__attribute__ ((always_inline))
497elf_machine_rela (struct link_map *map, const Elf32_Rela *reloc,
498 const Elf32_Sym *sym, const struct r_found_version *version,
499 void *const reloc_addr_arg, int skip_ifunc)
500{
501 Elf32_Addr *const reloc_addr = reloc_addr_arg;
502 const unsigned int r_type = ELF32_R_TYPE (reloc->r_info);
503
504 if (ELF32_R_TYPE (reloc->r_info) == R_386_RELATIVE)
505 *reloc_addr = map->l_addr + reloc->r_addend;
506 else if (r_type != R_386_NONE)
507 {
508# ifndef RESOLVE_CONFLICT_FIND_MAP
509 const Elf32_Sym *const refsym = sym;
510# endif
511 struct link_map *sym_map = RESOLVE_MAP (&sym, version, r_type);
512 Elf32_Addr value = SYMBOL_ADDRESS (sym_map, sym, true);
513
514 if (sym != NULL
515 && __glibc_likely (sym->st_shndx != SHN_UNDEF)
516 && __glibc_unlikely (ELFW(ST_TYPE) (sym->st_info) == STT_GNU_IFUNC)
517 && __glibc_likely (!skip_ifunc))
518 value = ((Elf32_Addr (*) (void)) value) ();
519
520 switch (ELF32_R_TYPE (reloc->r_info))
521 {
522 case R_386_SIZE32:
523 /* Set to symbol size plus addend. */
524 value = sym->st_size;
525 /* Fall through. */
526 case R_386_GLOB_DAT:
527 case R_386_JMP_SLOT:
528 case R_386_32:
529 *reloc_addr = value + reloc->r_addend;
530 break;
531# ifndef RESOLVE_CONFLICT_FIND_MAP
532 /* Not needed for dl-conflict.c. */
533 case R_386_PC32:
534 *reloc_addr = (value + reloc->r_addend - (Elf32_Addr) reloc_addr);
535 break;
536
537 case R_386_TLS_DTPMOD32:
538 /* Get the information from the link map returned by the
539 resolv function. */
540 if (sym_map != NULL)
541 *reloc_addr = sym_map->l_tls_modid;
542 break;
543 case R_386_TLS_DTPOFF32:
544 /* During relocation all TLS symbols are defined and used.
545 Therefore the offset is already correct. */
546 *reloc_addr = (sym == NULL ? 0 : sym->st_value) + reloc->r_addend;
547 break;
548 case R_386_TLS_DESC:
549 {
550 struct tlsdesc volatile *td =
551 (struct tlsdesc volatile *)reloc_addr;
552
553# ifndef RTLD_BOOTSTRAP
554 if (!sym)
555 {
556 td->arg = (void*)reloc->r_addend;
557 td->entry = _dl_tlsdesc_undefweak;
558 }
559 else
560# endif
561 {
562# ifndef RTLD_BOOTSTRAP
563# ifndef SHARED
564 CHECK_STATIC_TLS (map, sym_map);
565# else
566 if (!TRY_STATIC_TLS (map, sym_map))
567 {
568 td->arg = _dl_make_tlsdesc_dynamic
569 (sym_map, sym->st_value + reloc->r_addend);
570 td->entry = _dl_tlsdesc_dynamic;
571 }
572 else
573# endif
574# endif
575 {
576 td->arg = (void*)(sym->st_value - sym_map->l_tls_offset
577 + reloc->r_addend);
578 td->entry = _dl_tlsdesc_return;
579 }
580 }
581 }
582 break;
583 case R_386_TLS_TPOFF32:
584 /* The offset is positive, backward from the thread pointer. */
585 /* We know the offset of object the symbol is contained in.
586 It is a positive value which will be subtracted from the
587 thread pointer. To get the variable position in the TLS
588 block we subtract the offset from that of the TLS block. */
589 if (sym != NULL)
590 {
591 CHECK_STATIC_TLS (map, sym_map);
592 *reloc_addr = sym_map->l_tls_offset - sym->st_value
593 + reloc->r_addend;
594 }
595 break;
596 case R_386_TLS_TPOFF:
597 /* The offset is negative, forward from the thread pointer. */
598 /* We know the offset of object the symbol is contained in.
599 It is a negative value which will be added to the
600 thread pointer. */
601 if (sym != NULL)
602 {
603 CHECK_STATIC_TLS (map, sym_map);
604 *reloc_addr = sym->st_value - sym_map->l_tls_offset
605 + reloc->r_addend;
606 }
607 break;
608 case R_386_COPY:
609 if (sym == NULL)
610 /* This can happen in trace mode if an object could not be
611 found. */
612 break;
613 if (__glibc_unlikely (sym->st_size > refsym->st_size)
614 || (__glibc_unlikely (sym->st_size < refsym->st_size)
615 && GLRO(dl_verbose)))
616 {
617 const char *strtab;
618
619 strtab = (const char *) D_PTR (map, l_info[DT_STRTAB]);
620 _dl_error_printf ("\
621%s: Symbol `%s' has different size in shared object, consider re-linking\n",
622 RTLD_PROGNAME, strtab + refsym->st_name);
623 }
624 memcpy (reloc_addr_arg, (void *) value,
625 MIN (sym->st_size, refsym->st_size));
626 break;
627# endif /* !RESOLVE_CONFLICT_FIND_MAP */
628 case R_386_IRELATIVE:
629 value = map->l_addr + reloc->r_addend;
630 value = ((Elf32_Addr (*) (void)) value) ();
631 *reloc_addr = value;
632 break;
633 default:
634 /* We add these checks in the version to relocate ld.so only
635 if we are still debugging. */
636 _dl_reloc_bad_type (map, r_type, 0);
637 break;
638 }
639 }
640}
641# endif /* !RTLD_BOOTSTRAP */
642
643auto inline void
644__attribute ((always_inline))
645elf_machine_rel_relative (Elf32_Addr l_addr, const Elf32_Rel *reloc,
646 void *const reloc_addr_arg)
647{
648 Elf32_Addr *const reloc_addr = reloc_addr_arg;
649 assert (ELF32_R_TYPE (reloc->r_info) == R_386_RELATIVE);
650 *reloc_addr += l_addr;
651}
652
653# ifndef RTLD_BOOTSTRAP
654auto inline void
655__attribute__ ((always_inline))
656elf_machine_rela_relative (Elf32_Addr l_addr, const Elf32_Rela *reloc,
657 void *const reloc_addr_arg)
658{
659 Elf32_Addr *const reloc_addr = reloc_addr_arg;
660 *reloc_addr = l_addr + reloc->r_addend;
661}
662# endif /* !RTLD_BOOTSTRAP */
663
664auto inline void
665__attribute__ ((always_inline))
666elf_machine_lazy_rel (struct link_map *map,
667 Elf32_Addr l_addr, const Elf32_Rel *reloc,
668 int skip_ifunc)
669{
670 Elf32_Addr *const reloc_addr = (void *) (l_addr + reloc->r_offset);
671 const unsigned int r_type = ELF32_R_TYPE (reloc->r_info);
672 /* Check for unexpected PLT reloc type. */
673 if (__glibc_likely (r_type == R_386_JMP_SLOT))
674 {
675 /* Prelink has been deprecated. */
676 if (__glibc_likely (map->l_mach.plt == 0))
677 *reloc_addr += l_addr;
678 else
679 *reloc_addr = (map->l_mach.plt
680 + (((Elf32_Addr) reloc_addr) - map->l_mach.gotplt) * 4);
681 }
682 else if (__glibc_likely (r_type == R_386_TLS_DESC))
683 {
684 struct tlsdesc volatile * __attribute__((__unused__)) td =
685 (struct tlsdesc volatile *)reloc_addr;
686
687 /* Handle relocations that reference the local *ABS* in a simple
688 way, so as to preserve a potential addend. */
689 if (ELF32_R_SYM (reloc->r_info) == 0)
690 td->entry = _dl_tlsdesc_resolve_abs_plus_addend;
691 /* Given a known-zero addend, we can store a pointer to the
692 reloc in the arg position. */
693 else if (td->arg == 0)
694 {
695 td->arg = (void*)reloc;
696 td->entry = _dl_tlsdesc_resolve_rel;
697 }
698 else
699 {
700 /* We could handle non-*ABS* relocations with non-zero addends
701 by allocating dynamically an arg to hold a pointer to the
702 reloc, but that sounds pointless. */
703 const Elf32_Rel *const r = reloc;
704 /* The code below was borrowed from elf_dynamic_do_rel(). */
705 const ElfW(Sym) *const symtab =
706 (const void *) D_PTR (map, l_info[DT_SYMTAB]);
707
708# ifdef RTLD_BOOTSTRAP
709 /* The dynamic linker always uses versioning. */
710 assert (map->l_info[VERSYMIDX (DT_VERSYM)] != NULL);
711# else
712 if (map->l_info[VERSYMIDX (DT_VERSYM)])
713# endif
714 {
715 const ElfW(Half) *const version =
716 (const void *) D_PTR (map, l_info[VERSYMIDX (DT_VERSYM)]);
717 ElfW(Half) ndx = version[ELFW(R_SYM) (r->r_info)] & 0x7fff;
718 elf_machine_rel (map, r, &symtab[ELFW(R_SYM) (r->r_info)],
719 &map->l_versions[ndx],
720 (void *) (l_addr + r->r_offset), skip_ifunc);
721 }
722# ifndef RTLD_BOOTSTRAP
723 else
724 elf_machine_rel (map, r, &symtab[ELFW(R_SYM) (r->r_info)], NULL,
725 (void *) (l_addr + r->r_offset), skip_ifunc);
726# endif
727 }
728 }
729 else if (__glibc_unlikely (r_type == R_386_IRELATIVE))
730 {
731 Elf32_Addr value = map->l_addr + *reloc_addr;
732 if (__glibc_likely (!skip_ifunc))
733 value = ((Elf32_Addr (*) (void)) value) ();
734 *reloc_addr = value;
735 }
736 else
737 _dl_reloc_bad_type (map, r_type, 1);
738}
739
740# ifndef RTLD_BOOTSTRAP
741
742auto inline void
743__attribute__ ((always_inline))
744elf_machine_lazy_rela (struct link_map *map,
745 Elf32_Addr l_addr, const Elf32_Rela *reloc,
746 int skip_ifunc)
747{
748 Elf32_Addr *const reloc_addr = (void *) (l_addr + reloc->r_offset);
749 const unsigned int r_type = ELF32_R_TYPE (reloc->r_info);
750 if (__glibc_likely (r_type == R_386_JMP_SLOT))
751 ;
752 else if (__glibc_likely (r_type == R_386_TLS_DESC))
753 {
754 struct tlsdesc volatile * __attribute__((__unused__)) td =
755 (struct tlsdesc volatile *)reloc_addr;
756
757 td->arg = (void*)reloc;
758 td->entry = _dl_tlsdesc_resolve_rela;
759 }
760 else if (__glibc_unlikely (r_type == R_386_IRELATIVE))
761 {
762 Elf32_Addr value = map->l_addr + reloc->r_addend;
763 if (__glibc_likely (!skip_ifunc))
764 value = ((Elf32_Addr (*) (void)) value) ();
765 *reloc_addr = value;
766 }
767 else
768 _dl_reloc_bad_type (map, r_type, 1);
769}
770
771# endif /* !RTLD_BOOTSTRAP */
772
773#endif /* RESOLVE_MAP */
774

Warning: That file was not part of the compilation database. It may have many parsing errors.