26abbfb64a6f801a1b1ec0eaf507b016828d3559
[platform/upstream/linaro-glibc.git] / sysdeps / i386 / dl-machine.h
1 /* Machine-dependent ELF dynamic relocation inline functions.  i386 version.
2    Copyright (C) 1995-2002, 2003, 2004 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, write to the Free
17    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18    02111-1307 USA.  */
19
20 #ifndef dl_machine_h
21 #define dl_machine_h
22
23 #define ELF_MACHINE_NAME "i386"
24
25 #include <sys/param.h>
26 #include <sysdep.h>
27 #include <tls.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 #if defined PI_STATIC_AND_HIDDEN \
38     && defined HAVE_VISIBILITY_ATTRIBUTE && defined HAVE_HIDDEN \
39     && !defined HAVE_BROKEN_VISIBILITY_ATTRIBUTE
40
41 /* Return the link-time address of _DYNAMIC.  Conveniently, this is the
42    first element of the GOT, a special entry that is never relocated.  */
43 static inline Elf32_Addr __attribute__ ((unused, const))
44 elf_machine_dynamic (void)
45 {
46   /* This produces a GOTOFF reloc that resolves to zero at link time, so in
47      fact just loads from the GOT register directly.  By doing it without
48      an asm we can let the compiler choose any register.  */
49   extern const Elf32_Addr _GLOBAL_OFFSET_TABLE_[] attribute_hidden;
50   return _GLOBAL_OFFSET_TABLE_[0];
51 }
52
53 /* Return the run-time load address of the shared object.  */
54 static inline Elf32_Addr __attribute__ ((unused))
55 elf_machine_load_address (void)
56 {
57   /* Compute the difference between the runtime address of _DYNAMIC as seen
58      by a GOTOFF reference, and the link-time address found in the special
59      unrelocated first GOT entry.  */
60   extern Elf32_Dyn bygotoff[] asm ("_DYNAMIC") attribute_hidden;
61   return (Elf32_Addr) &bygotoff - elf_machine_dynamic ();
62 }
63
64 #else  /* Without .hidden support, we can't compile the code above.  */
65
66 /* Return the link-time address of _DYNAMIC.  Conveniently, this is the
67    first element of the GOT.  This must be inlined in a function which
68    uses global data.  */
69 static inline Elf32_Addr __attribute__ ((unused))
70 elf_machine_dynamic (void)
71 {
72   register Elf32_Addr *got asm ("%ebx");
73   return *got;
74 }
75
76
77 /* Return the run-time load address of the shared object.  */
78 static inline Elf32_Addr __attribute__ ((unused))
79 elf_machine_load_address (void)
80 {
81   /* It doesn't matter what variable this is, the reference never makes
82      it to assembly.  We need a dummy reference to some global variable
83      via the GOT to make sure the compiler initialized %ebx in time.  */
84   extern int _dl_argc;
85   Elf32_Addr addr;
86   asm ("leal _dl_start@GOTOFF(%%ebx), %0\n"
87        "subl _dl_start@GOT(%%ebx), %0"
88        : "=r" (addr) : "m" (_dl_argc) : "cc");
89   return addr;
90 }
91
92 #endif
93
94
95 /* Set up the loaded object described by L so its unrelocated PLT
96    entries will jump to the on-demand fixup code in dl-runtime.c.  */
97
98 static inline int __attribute__ ((unused, always_inline))
99 elf_machine_runtime_setup (struct link_map *l, int lazy, int profile)
100 {
101   Elf32_Addr *got;
102   extern void _dl_runtime_resolve (Elf32_Word) attribute_hidden;
103   extern void _dl_runtime_profile (Elf32_Word) attribute_hidden;
104
105   if (l->l_info[DT_JMPREL] && lazy)
106     {
107       /* The GOT entries for functions in the PLT have not yet been filled
108          in.  Their initial contents will arrange when called to push an
109          offset into the .rel.plt section, push _GLOBAL_OFFSET_TABLE_[1],
110          and then jump to _GLOBAL_OFFSET_TABLE[2].  */
111       got = (Elf32_Addr *) D_PTR (l, l_info[DT_PLTGOT]);
112       /* If a library is prelinked but we have to relocate anyway,
113          we have to be able to undo the prelinking of .got.plt.
114          The prelinker saved us here address of .plt + 0x16.  */
115       if (got[1])
116         {
117           l->l_mach.plt = got[1] + l->l_addr;
118           l->l_mach.gotplt = (Elf32_Addr) &got[3];
119         }
120       got[1] = (Elf32_Addr) l;  /* Identify this shared object.  */
121
122       /* The got[2] entry contains the address of a function which gets
123          called to get the address of a so far unresolved function and
124          jump to it.  The profiling extension of the dynamic linker allows
125          to intercept the calls to collect information.  In this case we
126          don't store the address in the GOT so that all future calls also
127          end in this function.  */
128       if (__builtin_expect (profile, 0))
129         {
130           got[2] = (Elf32_Addr) &_dl_runtime_profile;
131
132           if (_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;
136         }
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;
141     }
142
143   return lazy;
144 }
145
146 #ifdef IN_DL_RUNTIME
147
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.
152
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), unused))
158
159 static ElfW(Addr) fixup (struct link_map *__unbounded l,
160                          ElfW(Word) reloc_offset)
161      ARCH_FIXUP_ATTRIBUTE;
162 static ElfW(Addr) profile_fixup (struct link_map *l, ElfW(Word) reloc_offset,
163                                  ElfW(Addr) retaddr)
164      ARCH_FIXUP_ATTRIBUTE;
165 # endif
166
167 /* This code is used in dl-runtime.c to call the `fixup' function
168    and then redirect to the address it returns.  */
169 # if !defined PROF && !__BOUNDED_POINTERS__
170 #  define ELF_MACHINE_RUNTIME_TRAMPOLINE asm ("\
171         .text\n\
172         .globl _dl_runtime_resolve\n\
173         .type _dl_runtime_resolve, @function\n\
174         " CFI_STARTPROC "\n\
175         .align 16\n\
176 _dl_runtime_resolve:\n\
177         " CFI_ADJUST_CFA_OFFSET (8) "\n\
178         pushl %eax              # Preserve registers otherwise clobbered.\n\
179         " CFI_ADJUST_CFA_OFFSET (4) "\n\
180         pushl %ecx\n\
181         " CFI_ADJUST_CFA_OFFSET (4) "\n\
182         pushl %edx\n\
183         " CFI_ADJUST_CFA_OFFSET (4) "\n\
184         movl 16(%esp), %edx     # Copy args pushed by PLT in register.  Note\n\
185         movl 12(%esp), %eax     # that `fixup' takes its parameters in regs.\n\
186         call fixup              # Call resolver.\n\
187         popl %edx               # Get register content back.\n\
188         " CFI_ADJUST_CFA_OFFSET (-4) "\n\
189         popl %ecx\n\
190         " CFI_ADJUST_CFA_OFFSET (-4) "\n\
191         xchgl %eax, (%esp)      # Get %eax contents end store function address.\n\
192         ret $8                  # Jump to function address.\n\
193         " CFI_ENDPROC "\n\
194         .size _dl_runtime_resolve, .-_dl_runtime_resolve\n\
195 \n\
196         .globl _dl_runtime_profile\n\
197         .type _dl_runtime_profile, @function\n\
198         " CFI_STARTPROC "\n\
199         .align 16\n\
200 _dl_runtime_profile:\n\
201         " CFI_ADJUST_CFA_OFFSET (8) "\n\
202         pushl %eax              # Preserve registers otherwise clobbered.\n\
203         " CFI_ADJUST_CFA_OFFSET (4) "\n\
204         pushl %ecx\n\
205         " CFI_ADJUST_CFA_OFFSET (4) "\n\
206         pushl %edx\n\
207         " CFI_ADJUST_CFA_OFFSET (4) "\n\
208         movl 20(%esp), %ecx     # Load return address\n\
209         movl 16(%esp), %edx     # Copy args pushed by PLT in register.  Note\n\
210         movl 12(%esp), %eax     # that `fixup' takes its parameters in regs.\n\
211         call profile_fixup      # Call resolver.\n\
212         popl %edx               # Get register content back.\n\
213         " CFI_ADJUST_CFA_OFFSET (-4) "\n\
214         popl %ecx\n\
215         " CFI_ADJUST_CFA_OFFSET (-4) "\n\
216         xchgl %eax, (%esp)      # Get %eax contents end store function address.\n\
217         ret $8                  # Jump to function address.\n\
218         " CFI_ENDPROC "\n\
219         .size _dl_runtime_profile, .-_dl_runtime_profile\n\
220         .previous\n\
221 ");
222 # else
223 #  define ELF_MACHINE_RUNTIME_TRAMPOLINE asm ("\n\
224         .text\n\
225         .globl _dl_runtime_resolve\n\
226         .globl _dl_runtime_profile\n\
227         .type _dl_runtime_resolve, @function\n\
228         .type _dl_runtime_profile, @function\n\
229         " CFI_STARTPROC "\n\
230         .align 16\n\
231 _dl_runtime_resolve:\n\
232 _dl_runtime_profile:\n\
233         " CFI_ADJUST_CFA_OFFSET (8) "\n\
234         pushl %eax              # Preserve registers otherwise clobbered.\n\
235         " CFI_ADJUST_CFA_OFFSET (4) "\n\
236         pushl %ecx\n\
237         " CFI_ADJUST_CFA_OFFSET (4) "\n\
238         pushl %edx\n\
239         " CFI_ADJUST_CFA_OFFSET (4) "\n\
240         movl 16(%esp), %edx     # Push the arguments for `fixup'\n\
241         movl 12(%esp), %eax\n\
242         pushl %edx\n\
243         " CFI_ADJUST_CFA_OFFSET (4) "\n\
244         pushl %eax\n\
245         " CFI_ADJUST_CFA_OFFSET (4) "\n\
246         call fixup              # Call resolver.\n\
247         popl %edx               # Pop the parameters\n\
248         " CFI_ADJUST_CFA_OFFSET (-4) "\n\
249         popl %ecx\n\
250         " CFI_ADJUST_CFA_OFFSET (-4) "\n\
251         popl %edx               # Get register content back.\n\
252         " CFI_ADJUST_CFA_OFFSET (-4) "\n\
253         popl %ecx\n\
254         " CFI_ADJUST_CFA_OFFSET (-4) "\n\
255         xchgl %eax, (%esp)      # Get %eax contents end store function address.\n\
256         ret $8                  # Jump to function address.\n\
257         " CFI_ENDPROC "\n\
258         .size _dl_runtime_resolve, .-_dl_runtime_resolve\n\
259         .size _dl_runtime_profile, .-_dl_runtime_profile\n\
260         .previous\n\
261 ");
262 # endif
263 #endif
264
265 /* Mask identifying addresses reserved for the user program,
266    where the dynamic linker should not map anything.  */
267 #define ELF_MACHINE_USER_ADDRESS_MASK   0xf8000000UL
268
269 /* Initial entry point code for the dynamic linker.
270    The C function `_dl_start' is the real entry point;
271    its return value is the user program's entry point.  */
272
273 #define RTLD_START asm ("\n\
274         .text\n\
275         .align 16\n\
276 0:      movl (%esp), %ebx\n\
277         ret\n\
278         .align 16\n\
279 .globl _start\n\
280 .globl _dl_start_user\n\
281 _start:\n\
282         # Note that _dl_start gets the parameter in %eax.\n\
283         movl %esp, %eax\n\
284         call _dl_start\n\
285 _dl_start_user:\n\
286         # Save the user entry point address in %edi.\n\
287         movl %eax, %edi\n\
288         # Point %ebx at the GOT.\n\
289         call 0b\n\
290         addl $_GLOBAL_OFFSET_TABLE_, %ebx\n\
291         # See if we were run as a command with the executable file\n\
292         # name as an extra leading argument.\n\
293         movl _dl_skip_args@GOTOFF(%ebx), %eax\n\
294         # Pop the original argument count.\n\
295         popl %edx\n\
296         # Adjust the stack pointer to skip _dl_skip_args words.\n\
297         leal (%esp,%eax,4), %esp\n\
298         # Subtract _dl_skip_args from argc.\n\
299         subl %eax, %edx\n\
300         # Push argc back on the stack.\n\
301         push %edx\n\
302         # The special initializer gets called with the stack just\n\
303         # as the application's entry point will see it; it can\n\
304         # switch stacks if it moves these contents over.\n\
305 " RTLD_START_SPECIAL_INIT "\n\
306         # Load the parameters again.\n\
307         # (eax, edx, ecx, *--esp) = (_dl_loaded, argc, argv, envp)\n\
308         movl _rtld_local@GOTOFF(%ebx), %eax\n\
309         leal 8(%esp,%edx,4), %esi\n\
310         leal 4(%esp), %ecx\n\
311         pushl %esi\n\
312         # Call the function to run the initializers.\n\
313         call _dl_init_internal@PLT\n\
314         # Pass our finalizer function to the user in %edx, as per ELF ABI.\n\
315         leal _dl_fini@GOTOFF(%ebx), %edx\n\
316         # Jump to the user's entry point.\n\
317         jmp *%edi\n\
318         .previous\n\
319 ");
320
321 #ifndef RTLD_START_SPECIAL_INIT
322 # define RTLD_START_SPECIAL_INIT /* nothing */
323 #endif
324
325 /* ELF_RTYPE_CLASS_PLT iff TYPE describes relocation of a PLT entry or
326    TLS variable, so undefined references should not be allowed to
327    define the value.
328    ELF_RTYPE_CLASS_NOCOPY iff TYPE should not be allowed to resolve to one
329    of the main executable's symbols, as for a COPY reloc.  */
330 #if defined USE_TLS && (!defined RTLD_BOOTSTRAP || USE___THREAD)
331 # define elf_machine_type_class(type) \
332   ((((type) == R_386_JMP_SLOT || (type) == R_386_TLS_DTPMOD32                 \
333      || (type) == R_386_TLS_DTPOFF32 || (type) == R_386_TLS_TPOFF32           \
334      || (type) == R_386_TLS_TPOFF)                                            \
335     * ELF_RTYPE_CLASS_PLT)                                                    \
336    | (((type) == R_386_COPY) * ELF_RTYPE_CLASS_COPY))
337 #else
338 # define elf_machine_type_class(type) \
339   ((((type) == R_386_JMP_SLOT) * ELF_RTYPE_CLASS_PLT)                         \
340    | (((type) == R_386_COPY) * ELF_RTYPE_CLASS_COPY))
341 #endif
342
343 /* A reloc type used for ld.so cmdline arg lookups to reject PLT entries.  */
344 #define ELF_MACHINE_JMP_SLOT    R_386_JMP_SLOT
345
346 /* The i386 never uses Elf32_Rela relocations for the dynamic linker.
347    Prelinked libraries may use Elf32_Rela though.  */
348 #define ELF_MACHINE_PLT_REL 1
349
350 /* We define an initialization functions.  This is called very early in
351    _dl_sysdep_start.  */
352 #define DL_PLATFORM_INIT dl_platform_init ()
353
354 static inline void __attribute__ ((unused))
355 dl_platform_init (void)
356 {
357   if (GLRO(dl_platform) != NULL && *GLRO(dl_platform) == '\0')
358     /* Avoid an empty string which would disturb us.  */
359     GLRO(dl_platform) = NULL;
360 }
361
362 static inline Elf32_Addr
363 elf_machine_fixup_plt (struct link_map *map, lookup_t t,
364                        const Elf32_Rel *reloc,
365                        Elf32_Addr *reloc_addr, Elf32_Addr value)
366 {
367   return *reloc_addr = value;
368 }
369
370 /* Return the final value of a plt relocation.  */
371 static inline Elf32_Addr
372 elf_machine_plt_value (struct link_map *map, const Elf32_Rel *reloc,
373                        Elf32_Addr value)
374 {
375   return value;
376 }
377
378 #endif /* !dl_machine_h */
379
380 #ifdef RESOLVE
381
382 /* The i386 never uses Elf32_Rela relocations for the dynamic linker.
383    Prelinked libraries may use Elf32_Rela though.  */
384 #ifdef RTLD_BOOTSTRAP
385 # define ELF_MACHINE_NO_RELA 1
386 #endif
387
388 /* Perform the relocation specified by RELOC and SYM (which is fully resolved).
389    MAP is the object containing the reloc.  */
390
391 static inline void
392 elf_machine_rel (struct link_map *map, const Elf32_Rel *reloc,
393                  const Elf32_Sym *sym, const struct r_found_version *version,
394                  void *const reloc_addr_arg)
395 {
396   Elf32_Addr *const reloc_addr = reloc_addr_arg;
397   const unsigned int r_type = ELF32_R_TYPE (reloc->r_info);
398
399 #if !defined RTLD_BOOTSTRAP || !defined HAVE_Z_COMBRELOC
400   if (__builtin_expect (r_type == R_386_RELATIVE, 0))
401     {
402 # if !defined RTLD_BOOTSTRAP && !defined HAVE_Z_COMBRELOC
403       /* This is defined in rtld.c, but nowhere in the static libc.a;
404          make the reference weak so static programs can still link.
405          This declaration cannot be done when compiling rtld.c
406          (i.e. #ifdef RTLD_BOOTSTRAP) because rtld.c contains the
407          common defn for _dl_rtld_map, which is incompatible with a
408          weak decl in the same file.  */
409 #  ifndef SHARED
410       weak_extern (_dl_rtld_map);
411 #  endif
412       if (map != &GL(dl_rtld_map)) /* Already done in rtld itself.  */
413 # endif
414         *reloc_addr += map->l_addr;
415     }
416 # ifndef RTLD_BOOTSTRAP
417   else if (__builtin_expect (r_type == R_386_NONE, 0))
418     return;
419 # endif
420   else
421 #endif  /* !RTLD_BOOTSTRAP and have no -z combreloc */
422     {
423       const Elf32_Sym *const refsym = sym;
424 #if defined USE_TLS && !defined RTLD_BOOTSTRAP
425       struct link_map *sym_map = RESOLVE_MAP (&sym, version, r_type);
426       Elf32_Addr value = sym == NULL ? 0 : sym_map->l_addr + sym->st_value;
427 #else
428       Elf32_Addr value = RESOLVE (&sym, version, r_type);
429
430 # ifndef RTLD_BOOTSTRAP
431       if (sym != NULL)
432 # endif
433         value += sym->st_value;
434 #endif  /* use TLS and !RTLD_BOOTSTRAP */
435
436       switch (r_type)
437         {
438         case R_386_GLOB_DAT:
439         case R_386_JMP_SLOT:
440           *reloc_addr = value;
441           break;
442
443 #if defined USE_TLS && (!defined RTLD_BOOTSTRAP || USE___THREAD)
444         case R_386_TLS_DTPMOD32:
445 # ifdef RTLD_BOOTSTRAP
446           /* During startup the dynamic linker is always the module
447              with index 1.
448              XXX If this relocation is necessary move before RESOLVE
449              call.  */
450           *reloc_addr = 1;
451 # else
452           /* Get the information from the link map returned by the
453              resolv function.  */
454           if (sym_map != NULL)
455             *reloc_addr = sym_map->l_tls_modid;
456 # endif
457           break;
458         case R_386_TLS_DTPOFF32:
459 # ifndef RTLD_BOOTSTRAP
460           /* During relocation all TLS symbols are defined and used.
461              Therefore the offset is already correct.  */
462           if (sym != NULL)
463             *reloc_addr = sym->st_value;
464 # endif
465           break;
466         case R_386_TLS_TPOFF32:
467           /* The offset is positive, backward from the thread pointer.  */
468 # ifdef RTLD_BOOTSTRAP
469           *reloc_addr += map->l_tls_offset - sym->st_value;
470 # else
471           /* We know the offset of object the symbol is contained in.
472              It is a positive value which will be subtracted from the
473              thread pointer.  To get the variable position in the TLS
474              block we subtract the offset from that of the TLS block.  */
475           if (sym != NULL)
476             {
477               CHECK_STATIC_TLS (map, sym_map);
478               *reloc_addr += sym_map->l_tls_offset - sym->st_value;
479             }
480 # endif
481           break;
482         case R_386_TLS_TPOFF:
483           /* The offset is negative, forward from the thread pointer.  */
484 # ifdef RTLD_BOOTSTRAP
485           *reloc_addr += sym->st_value - map->l_tls_offset;
486 # else
487           /* We know the offset of object the symbol is contained in.
488              It is a negative value which will be added to the
489              thread pointer.  */
490           if (sym != NULL)
491             {
492               CHECK_STATIC_TLS (map, sym_map);
493               *reloc_addr += sym->st_value - sym_map->l_tls_offset;
494             }
495 # endif
496           break;
497 #endif  /* use TLS */
498
499 #ifndef RTLD_BOOTSTRAP
500         case R_386_32:
501           *reloc_addr += value;
502           break;
503         case R_386_PC32:
504           *reloc_addr += (value - (Elf32_Addr) reloc_addr);
505           break;
506         case R_386_COPY:
507           if (sym == NULL)
508             /* This can happen in trace mode if an object could not be
509                found.  */
510             break;
511           if (__builtin_expect (sym->st_size > refsym->st_size, 0)
512               || (__builtin_expect (sym->st_size < refsym->st_size, 0)
513                   && GLRO(dl_verbose)))
514             {
515               const char *strtab;
516
517               strtab = (const char *) D_PTR (map, l_info[DT_STRTAB]);
518               _dl_error_printf ("\
519 %s: Symbol `%s' has different size in shared object, consider re-linking\n",
520                                 rtld_progname ?: "<program name unknown>",
521                                 strtab + refsym->st_name);
522             }
523           memcpy (reloc_addr_arg, (void *) value,
524                   MIN (sym->st_size, refsym->st_size));
525           break;
526         default:
527           _dl_reloc_bad_type (map, r_type, 0);
528           break;
529 #endif  /* !RTLD_BOOTSTRAP */
530         }
531     }
532 }
533
534 #ifndef RTLD_BOOTSTRAP
535 static inline void
536 elf_machine_rela (struct link_map *map, const Elf32_Rela *reloc,
537                   const Elf32_Sym *sym, const struct r_found_version *version,
538                   void *const reloc_addr_arg)
539 {
540   Elf32_Addr *const reloc_addr = reloc_addr_arg;
541   const unsigned int r_type = ELF32_R_TYPE (reloc->r_info);
542
543   if (ELF32_R_TYPE (reloc->r_info) == R_386_RELATIVE)
544     *reloc_addr = map->l_addr + reloc->r_addend;
545   else if (r_type != R_386_NONE)
546     {
547 # ifndef RESOLVE_CONFLICT_FIND_MAP
548       const Elf32_Sym *const refsym = sym;
549 # endif
550 # ifdef USE_TLS
551       struct link_map *sym_map = RESOLVE_MAP (&sym, version, r_type);
552       Elf32_Addr value = sym == NULL ? 0 : sym_map->l_addr + sym->st_value;
553 # else
554       Elf32_Addr value = RESOLVE (&sym, version, r_type);
555       if (sym != NULL)
556         value += sym->st_value;
557 # endif
558
559       switch (ELF32_R_TYPE (reloc->r_info))
560         {
561         case R_386_GLOB_DAT:
562         case R_386_JMP_SLOT:
563         case R_386_32:
564           *reloc_addr = value + reloc->r_addend;
565           break;
566 # ifndef RESOLVE_CONFLICT_FIND_MAP
567           /* Not needed for dl-conflict.c.  */
568         case R_386_PC32:
569           *reloc_addr = (value + reloc->r_addend - (Elf32_Addr) reloc_addr);
570           break;
571
572 #  ifdef USE_TLS
573         case R_386_TLS_DTPMOD32:
574           /* Get the information from the link map returned by the
575              resolv function.  */
576           if (sym_map != NULL)
577             *reloc_addr = sym_map->l_tls_modid;
578           break;
579         case R_386_TLS_DTPOFF32:
580           /* During relocation all TLS symbols are defined and used.
581              Therefore the offset is already correct.  */
582           *reloc_addr = (sym == NULL ? 0 : sym->st_value) + reloc->r_addend;
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           CHECK_STATIC_TLS (map, sym_map);
591           *reloc_addr
592             = (sym == NULL ? 0 : sym_map->l_tls_offset - sym->st_value)
593               + reloc->r_addend;
594           break;
595         case R_386_TLS_TPOFF:
596           /* The offset is negative, forward from the thread pointer.  */
597           /* We know the offset of object the symbol is contained in.
598              It is a negative value which will be added to the
599              thread pointer.  */
600           CHECK_STATIC_TLS (map, sym_map);
601           *reloc_addr
602             = (sym == NULL ? 0 : sym->st_value - sym_map->l_tls_offset)
603               + reloc->r_addend;
604           break;
605 #  endif        /* use TLS */
606         case R_386_COPY:
607           if (sym == NULL)
608             /* This can happen in trace mode if an object could not be
609                found.  */
610             break;
611           if (__builtin_expect (sym->st_size > refsym->st_size, 0)
612               || (__builtin_expect (sym->st_size < refsym->st_size, 0)
613                   && GLRO(dl_verbose)))
614             {
615               const char *strtab;
616
617               strtab = (const char *) D_PTR (map, l_info[DT_STRTAB]);
618               _dl_error_printf ("\
619 %s: Symbol `%s' has different size in shared object, consider re-linking\n",
620                                 rtld_progname ?: "<program name unknown>",
621                                 strtab + refsym->st_name);
622             }
623           memcpy (reloc_addr_arg, (void *) value,
624                   MIN (sym->st_size, refsym->st_size));
625           break;
626 # endif /* !RESOLVE_CONFLICT_FIND_MAP */
627         default:
628           /* We add these checks in the version to relocate ld.so only
629              if we are still debugging.  */
630           _dl_reloc_bad_type (map, r_type, 0);
631           break;
632         }
633     }
634 }
635 #endif  /* !RTLD_BOOTSTRAP */
636
637 static inline void
638 elf_machine_rel_relative (Elf32_Addr l_addr, const Elf32_Rel *reloc,
639                           void *const reloc_addr_arg)
640 {
641   Elf32_Addr *const reloc_addr = reloc_addr_arg;
642   assert (ELF32_R_TYPE (reloc->r_info) == R_386_RELATIVE);
643   *reloc_addr += l_addr;
644 }
645
646 #ifndef RTLD_BOOTSTRAP
647 static inline void
648 elf_machine_rela_relative (Elf32_Addr l_addr, const Elf32_Rela *reloc,
649                            void *const reloc_addr_arg)
650 {
651   Elf32_Addr *const reloc_addr = reloc_addr_arg;
652   *reloc_addr = l_addr + reloc->r_addend;
653 }
654 #endif  /* !RTLD_BOOTSTRAP */
655
656 static inline void
657 elf_machine_lazy_rel (struct link_map *map,
658                       Elf32_Addr l_addr, const Elf32_Rel *reloc)
659 {
660   Elf32_Addr *const reloc_addr = (void *) (l_addr + reloc->r_offset);
661   const unsigned int r_type = ELF32_R_TYPE (reloc->r_info);
662   /* Check for unexpected PLT reloc type.  */
663   if (__builtin_expect (r_type == R_386_JMP_SLOT, 1))
664     {
665       if (__builtin_expect (map->l_mach.plt, 0) == 0)
666         *reloc_addr += l_addr;
667       else
668         *reloc_addr = (map->l_mach.plt
669                        + (((Elf32_Addr) reloc_addr) - map->l_mach.gotplt) * 4);
670     }
671   else
672     _dl_reloc_bad_type (map, r_type, 1);
673 }
674
675 #ifndef RTLD_BOOTSTRAP
676
677 static inline void
678 elf_machine_lazy_rela (struct link_map *map,
679                        Elf32_Addr l_addr, const Elf32_Rela *reloc)
680 {
681 }
682
683 #endif  /* !RTLD_BOOTSTRAP */
684
685 #endif /* RESOLVE */