arm: Update elf_machine_load_address for static PIE
[glibc.git] / sysdeps / arm / dl-machine.h
blobefe2e1b3a3a0431ef3be571f66dd6b3b3ac5d1e6
1 /* Machine-dependent ELF dynamic relocation inline functions. ARM version.
2 Copyright (C) 1995-2017 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library. If not, see
17 <http://www.gnu.org/licenses/>. */
19 #ifndef dl_machine_h
20 #define dl_machine_h
22 #define ELF_MACHINE_NAME "ARM"
24 #include <sys/param.h>
25 #include <tls.h>
26 #include <dl-tlsdesc.h>
27 #include <dl-irel.h>
29 #ifndef CLEAR_CACHE
30 # error CLEAR_CACHE definition required to handle TEXTREL
31 #endif
33 /* Return nonzero iff ELF header is compatible with the running host. */
34 static inline int __attribute__ ((unused))
35 elf_machine_matches_host (const Elf32_Ehdr *ehdr)
37 return ehdr->e_machine == EM_ARM;
41 /* Return the link-time address of _DYNAMIC. Conveniently, this is the
42 first element of the GOT. */
43 static inline Elf32_Addr __attribute__ ((unused))
44 elf_machine_dynamic (void)
46 /* Declaring this hidden ensures that a PC-relative reference is used. */
47 extern const Elf32_Addr _GLOBAL_OFFSET_TABLE_[] attribute_hidden;
48 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 Elf32_Addr pcrel_addr;
57 #ifdef SHARED
58 extern Elf32_Addr __dl_start (void *) asm ("_dl_start");
59 Elf32_Addr got_addr = (Elf32_Addr) &__dl_start;
60 asm ("adr %0, _dl_start" : "=r" (pcrel_addr));
61 #else
62 extern Elf32_Dyn _DYNAMIC[] __attribute__((weak, visibility ("hidden")));
63 if (!_DYNAMIC)
64 return 0;
65 extern Elf32_Addr __dl_relocate_static_pie (void *)
66 asm ("_dl_relocate_static_pie") attribute_hidden;
67 Elf32_Addr got_addr = (Elf32_Addr) &__dl_relocate_static_pie;
68 asm ("adr %0, _dl_relocate_static_pie" : "=r" (pcrel_addr));
69 #endif
70 #ifdef __thumb__
71 /* Clear the low bit of the function address.
73 NOTE: got_addr is from GOT table whose lsb is always set by linker if it's
74 Thumb function address. PCREL_ADDR comes from PC-relative calculation
75 which will finish during assembling. GAS assembler before the fix for
76 PR gas/21458 was not setting the lsb but does after that. Always do the
77 strip for both, so the code works with various combinations of glibc and
78 Binutils. */
79 got_addr &= ~(Elf32_Addr) 1;
80 pcrel_addr &= ~(Elf32_Addr) 1;
81 #endif
82 return pcrel_addr - got_addr;
86 /* Set up the loaded object described by L so its unrelocated PLT
87 entries will jump to the on-demand fixup code in dl-runtime.c. */
89 static inline int __attribute__ ((unused))
90 elf_machine_runtime_setup (struct link_map *l, int lazy, int profile)
92 Elf32_Addr *got;
93 extern void _dl_runtime_resolve (Elf32_Word);
94 extern void _dl_runtime_profile (Elf32_Word);
96 if (l->l_info[DT_JMPREL] && lazy)
98 /* patb: this is different than i386 */
99 /* The GOT entries for functions in the PLT have not yet been filled
100 in. Their initial contents will arrange when called to push an
101 index into the .got section, load ip with &_GLOBAL_OFFSET_TABLE_[3],
102 and then jump to _GLOBAL_OFFSET_TABLE[2]. */
103 got = (Elf32_Addr *) D_PTR (l, l_info[DT_PLTGOT]);
104 /* If a library is prelinked but we have to relocate anyway,
105 we have to be able to undo the prelinking of .got.plt.
106 The prelinker saved us here address of .plt. */
107 if (got[1])
108 l->l_mach.plt = got[1] + l->l_addr;
109 got[1] = (Elf32_Addr) l; /* Identify this shared object. */
111 /* The got[2] entry contains the address of a function which gets
112 called to get the address of a so far unresolved function and
113 jump to it. The profiling extension of the dynamic linker allows
114 to intercept the calls to collect information. In this case we
115 don't store the address in the GOT so that all future calls also
116 end in this function. */
117 if (profile)
119 got[2] = (Elf32_Addr) &_dl_runtime_profile;
121 if (GLRO(dl_profile) != NULL
122 && _dl_name_match_p (GLRO(dl_profile), l))
123 /* Say that we really want profiling and the timers are
124 started. */
125 GL(dl_profile_map) = l;
127 else
128 /* This function will get called to fix up the GOT entry indicated by
129 the offset on the stack, and then jump to the resolved address. */
130 got[2] = (Elf32_Addr) &_dl_runtime_resolve;
133 if (l->l_info[ADDRIDX (DT_TLSDESC_GOT)] && lazy)
134 *(Elf32_Addr*)(D_PTR (l, l_info[ADDRIDX (DT_TLSDESC_GOT)]) + l->l_addr)
135 = (Elf32_Addr) &_dl_tlsdesc_lazy_resolver;
137 return lazy;
140 #if defined(ARCH_HAS_BX)
141 #define BX(x) "bx\t" #x
142 #else
143 #define BX(x) "mov\tpc, " #x
144 #endif
146 /* Mask identifying addresses reserved for the user program,
147 where the dynamic linker should not map anything. */
148 #define ELF_MACHINE_USER_ADDRESS_MASK 0xf8000000UL
150 /* Initial entry point code for the dynamic linker.
151 The C function `_dl_start' is the real entry point;
152 its return value is the user program's entry point. */
154 #define RTLD_START asm ("\
155 .text\n\
156 .globl _start\n\
157 .type _start, %function\n\
158 .globl _dl_start_user\n\
159 .type _dl_start_user, %function\n\
160 _start:\n\
161 @ we are PIC code, so get global offset table\n\
162 ldr sl, .L_GET_GOT\n\
163 @ See if we were run as a command with the executable file\n\
164 @ name as an extra leading argument.\n\
165 ldr r4, .L_SKIP_ARGS\n\
166 @ at start time, all the args are on the stack\n\
167 mov r0, sp\n\
168 bl _dl_start\n\
169 @ returns user entry point in r0\n\
170 _dl_start_user:\n\
171 adr r6, .L_GET_GOT\n\
172 add sl, sl, r6\n\
173 ldr r4, [sl, r4]\n\
174 @ save the entry point in another register\n\
175 mov r6, r0\n\
176 @ get the original arg count\n\
177 ldr r1, [sp]\n\
178 @ get the argv address\n\
179 add r2, sp, #4\n\
180 @ Fix up the stack if necessary.\n\
181 cmp r4, #0\n\
182 bne .L_fixup_stack\n\
183 .L_done_fixup:\n\
184 @ compute envp\n\
185 add r3, r2, r1, lsl #2\n\
186 add r3, r3, #4\n\
187 @ now we call _dl_init\n\
188 ldr r0, .L_LOADED\n\
189 ldr r0, [sl, r0]\n\
190 @ call _dl_init\n\
191 bl _dl_init(PLT)\n\
192 @ load the finalizer function\n\
193 ldr r0, .L_FINI_PROC\n\
194 add r0, sl, r0\n\
195 @ jump to the user_s entry point\n\
196 " BX(r6) "\n\
198 @ iWMMXt and EABI targets require the stack to be eight byte\n\
199 @ aligned - shuffle arguments etc.\n\
200 .L_fixup_stack:\n\
201 @ subtract _dl_skip_args from original arg count\n\
202 sub r1, r1, r4\n\
203 @ store the new argc in the new stack location\n\
204 str r1, [sp]\n\
205 @ find the first unskipped argument\n\
206 mov r3, r2\n\
207 add r4, r2, r4, lsl #2\n\
208 @ shuffle argv down\n\
209 1: ldr r5, [r4], #4\n\
210 str r5, [r3], #4\n\
211 cmp r5, #0\n\
212 bne 1b\n\
213 @ shuffle envp down\n\
214 1: ldr r5, [r4], #4\n\
215 str r5, [r3], #4\n\
216 cmp r5, #0\n\
217 bne 1b\n\
218 @ shuffle auxv down\n\
219 1: ldmia r4!, {r0, r5}\n\
220 stmia r3!, {r0, r5}\n\
221 cmp r0, #0\n\
222 bne 1b\n\
223 @ Update _dl_argv\n\
224 ldr r3, .L_ARGV\n\
225 str r2, [sl, r3]\n\
226 b .L_done_fixup\n\
228 .L_GET_GOT:\n\
229 .word _GLOBAL_OFFSET_TABLE_ - .L_GET_GOT\n\
230 .L_SKIP_ARGS:\n\
231 .word _dl_skip_args(GOTOFF)\n\
232 .L_FINI_PROC:\n\
233 .word _dl_fini(GOTOFF)\n\
234 .L_ARGV:\n\
235 .word _dl_argv(GOTOFF)\n\
236 .L_LOADED:\n\
237 .word _rtld_local(GOTOFF)\n\
238 .previous\n\
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_COPY iff TYPE should not be allowed to resolve to one
245 of the main executable's symbols, as for a COPY reloc.
246 ELF_RTYPE_CLASS_EXTERN_PROTECTED_DATA iff TYPE describes relocation against
247 protected data whose address may be external due to copy relocation. */
248 #ifndef RTLD_BOOTSTRAP
249 # define elf_machine_type_class(type) \
250 ((((type) == R_ARM_JUMP_SLOT || (type) == R_ARM_TLS_DTPMOD32 \
251 || (type) == R_ARM_TLS_DTPOFF32 || (type) == R_ARM_TLS_TPOFF32 \
252 || (type) == R_ARM_TLS_DESC) \
253 * ELF_RTYPE_CLASS_PLT) \
254 | (((type) == R_ARM_COPY) * ELF_RTYPE_CLASS_COPY) \
255 | (((type) == R_ARM_GLOB_DAT) * ELF_RTYPE_CLASS_EXTERN_PROTECTED_DATA))
256 #else
257 #define elf_machine_type_class(type) \
258 ((((type) == R_ARM_JUMP_SLOT) * ELF_RTYPE_CLASS_PLT) \
259 | (((type) == R_ARM_COPY) * ELF_RTYPE_CLASS_COPY) \
260 | (((type) == R_ARM_GLOB_DAT) * ELF_RTYPE_CLASS_EXTERN_PROTECTED_DATA))
261 #endif
263 /* A reloc type used for ld.so cmdline arg lookups to reject PLT entries. */
264 #define ELF_MACHINE_JMP_SLOT R_ARM_JUMP_SLOT
266 /* ARM never uses Elf32_Rela relocations for the dynamic linker.
267 Prelinked libraries may use Elf32_Rela though. */
268 #define ELF_MACHINE_PLT_REL 1
270 /* We define an initialization functions. This is called very early in
271 _dl_sysdep_start. */
272 #define DL_PLATFORM_INIT dl_platform_init ()
274 static inline void __attribute__ ((unused))
275 dl_platform_init (void)
277 if (GLRO(dl_platform) != NULL && *GLRO(dl_platform) == '\0')
278 /* Avoid an empty string which would disturb us. */
279 GLRO(dl_platform) = NULL;
282 static inline Elf32_Addr
283 elf_machine_fixup_plt (struct link_map *map, lookup_t t,
284 const ElfW(Sym) *refsym, const ElfW(Sym) *sym,
285 const Elf32_Rel *reloc,
286 Elf32_Addr *reloc_addr, Elf32_Addr value)
288 return *reloc_addr = value;
291 /* Return the final value of a plt relocation. */
292 static inline Elf32_Addr
293 elf_machine_plt_value (struct link_map *map, const Elf32_Rel *reloc,
294 Elf32_Addr value)
296 return value;
299 #endif /* !dl_machine_h */
302 /* ARM never uses Elf32_Rela relocations for the dynamic linker.
303 Prelinked libraries may use Elf32_Rela though. */
304 #define ELF_MACHINE_NO_RELA defined RTLD_BOOTSTRAP
305 #define ELF_MACHINE_NO_REL 0
307 /* Names of the architecture-specific auditing callback functions. */
308 #define ARCH_LA_PLTENTER arm_gnu_pltenter
309 #define ARCH_LA_PLTEXIT arm_gnu_pltexit
311 #ifdef RESOLVE_MAP
312 /* Handle a PC24 reloc, including the out-of-range case. */
313 auto void
314 relocate_pc24 (struct link_map *map, Elf32_Addr value,
315 Elf32_Addr *const reloc_addr, Elf32_Sword addend)
317 Elf32_Addr new_value;
319 /* Set NEW_VALUE based on V, and return true iff it overflows 24 bits. */
320 inline bool set_new_value (Elf32_Addr v)
322 new_value = v + addend - (Elf32_Addr) reloc_addr;
323 Elf32_Addr topbits = new_value & 0xfe000000;
324 return topbits != 0xfe000000 && topbits != 0x00000000;
327 if (set_new_value (value))
329 /* The PC-relative address doesn't fit in 24 bits! */
331 static void *fix_page;
332 static size_t fix_offset;
333 if (fix_page == NULL)
335 void *new_page = __mmap (NULL, GLRO(dl_pagesize),
336 PROT_READ | PROT_WRITE | PROT_EXEC,
337 MAP_PRIVATE | MAP_ANON, -1, 0);
338 if (new_page == MAP_FAILED)
339 _dl_signal_error (0, map->l_name, NULL,
340 "could not map page for fixup");
341 fix_page = new_page;
342 assert (fix_offset == 0);
345 Elf32_Word *fix_address = fix_page + fix_offset;
346 fix_address[0] = 0xe51ff004; /* ldr pc, [pc, #-4] */
347 fix_address[1] = value;
349 fix_offset += sizeof fix_address[0] * 2;
350 if (fix_offset >= GLRO(dl_pagesize))
352 fix_page = NULL;
353 fix_offset = 0;
356 if (set_new_value ((Elf32_Addr) fix_address))
357 _dl_signal_error (0, map->l_name, NULL,
358 "R_ARM_PC24 relocation out of range");
361 *reloc_addr = (*reloc_addr & 0xff000000) | ((new_value >> 2) & 0x00ffffff);
364 /* Perform the relocation specified by RELOC and SYM (which is fully resolved).
365 MAP is the object containing the reloc. */
367 auto inline void
368 __attribute__ ((always_inline))
369 elf_machine_rel (struct link_map *map, const Elf32_Rel *reloc,
370 const Elf32_Sym *sym, const struct r_found_version *version,
371 void *const reloc_addr_arg, int skip_ifunc)
373 Elf32_Addr *const reloc_addr = reloc_addr_arg;
374 const unsigned int r_type = ELF32_R_TYPE (reloc->r_info);
376 #if !defined RTLD_BOOTSTRAP || !defined HAVE_Z_COMBRELOC
377 if (__builtin_expect (r_type == R_ARM_RELATIVE, 0))
379 # if !defined RTLD_BOOTSTRAP && !defined HAVE_Z_COMBRELOC
380 /* This is defined in rtld.c, but nowhere in the static libc.a;
381 make the reference weak so static programs can still link.
382 This declaration cannot be done when compiling rtld.c
383 (i.e. #ifdef RTLD_BOOTSTRAP) because rtld.c contains the
384 common defn for _dl_rtld_map, which is incompatible with a
385 weak decl in the same file. */
386 # ifndef SHARED
387 weak_extern (_dl_rtld_map);
388 # endif
389 if (map != &GL(dl_rtld_map)) /* Already done in rtld itself. */
390 # endif
391 *reloc_addr += map->l_addr;
393 # ifndef RTLD_BOOTSTRAP
394 else if (__builtin_expect (r_type == R_ARM_NONE, 0))
395 return;
396 # endif
397 else
398 #endif
400 const Elf32_Sym *const refsym = sym;
401 struct link_map *sym_map = RESOLVE_MAP (&sym, version, r_type);
402 Elf32_Addr value = sym_map == NULL ? 0 : sym_map->l_addr + sym->st_value;
404 if (sym != NULL
405 && __builtin_expect (ELFW(ST_TYPE) (sym->st_info) == STT_GNU_IFUNC, 0)
406 && __builtin_expect (sym->st_shndx != SHN_UNDEF, 1)
407 && __builtin_expect (!skip_ifunc, 1))
408 value = elf_ifunc_invoke (value);
410 switch (r_type)
412 case R_ARM_COPY:
413 if (sym == NULL)
414 /* This can happen in trace mode if an object could not be
415 found. */
416 break;
417 if (sym->st_size > refsym->st_size
418 || (GLRO(dl_verbose) && sym->st_size < refsym->st_size))
420 const char *strtab;
422 strtab = (const void *) D_PTR (map, l_info[DT_STRTAB]);
423 _dl_error_printf ("\
424 %s: Symbol `%s' has different size in shared object, consider re-linking\n",
425 RTLD_PROGNAME, strtab + refsym->st_name);
427 memcpy (reloc_addr_arg, (void *) value,
428 MIN (sym->st_size, refsym->st_size));
429 break;
430 case R_ARM_GLOB_DAT:
431 case R_ARM_JUMP_SLOT:
432 # ifdef RTLD_BOOTSTRAP
433 /* Fix weak undefined references. */
434 if (sym != NULL && sym->st_value == 0)
435 *reloc_addr = 0;
436 else
437 # endif
438 *reloc_addr = value;
439 break;
440 case R_ARM_ABS32:
442 struct unaligned
444 Elf32_Addr x;
445 } __attribute__ ((packed, may_alias));
446 # ifndef RTLD_BOOTSTRAP
447 /* This is defined in rtld.c, but nowhere in the static
448 libc.a; make the reference weak so static programs can
449 still link. This declaration cannot be done when
450 compiling rtld.c (i.e. #ifdef RTLD_BOOTSTRAP) because
451 rtld.c contains the common defn for _dl_rtld_map, which
452 is incompatible with a weak decl in the same file. */
453 # ifndef SHARED
454 weak_extern (_dl_rtld_map);
455 # endif
456 if (map == &GL(dl_rtld_map))
457 /* Undo the relocation done here during bootstrapping.
458 Now we will relocate it anew, possibly using a
459 binding found in the user program or a loaded library
460 rather than the dynamic linker's built-in definitions
461 used while loading those libraries. */
462 value -= map->l_addr + refsym->st_value;
463 # endif
464 /* Support relocations on mis-aligned offsets. */
465 ((struct unaligned *) reloc_addr)->x += value;
466 break;
468 case R_ARM_TLS_DESC:
470 struct tlsdesc volatile *td =
471 (struct tlsdesc volatile *)reloc_addr;
473 # ifndef RTLD_BOOTSTRAP
474 if (! sym)
475 td->entry = _dl_tlsdesc_undefweak;
476 else
477 # endif
479 if (ELF32_R_SYM (reloc->r_info) == STN_UNDEF)
480 value = td->argument.value;
481 else
482 value = sym->st_value;
484 # ifndef RTLD_BOOTSTRAP
485 # ifndef SHARED
486 CHECK_STATIC_TLS (map, sym_map);
487 # else
488 if (!TRY_STATIC_TLS (map, sym_map))
490 td->argument.pointer
491 = _dl_make_tlsdesc_dynamic (sym_map, value);
492 td->entry = _dl_tlsdesc_dynamic;
494 else
495 # endif
496 # endif
498 td->argument.value = value + sym_map->l_tls_offset;
499 td->entry = _dl_tlsdesc_return;
503 break;
504 case R_ARM_PC24:
505 relocate_pc24 (map, value, reloc_addr,
506 /* Sign-extend the 24-bit addend in the
507 instruction (which counts instructions), and
508 then shift it up two so as to count bytes. */
509 (((Elf32_Sword) *reloc_addr << 8) >> 8) << 2);
510 break;
511 #if !defined RTLD_BOOTSTRAP
512 case R_ARM_TLS_DTPMOD32:
513 /* Get the information from the link map returned by the
514 resolv function. */
515 if (sym_map != NULL)
516 *reloc_addr = sym_map->l_tls_modid;
517 break;
519 case R_ARM_TLS_DTPOFF32:
520 if (sym != NULL)
521 *reloc_addr += sym->st_value;
522 break;
524 case R_ARM_TLS_TPOFF32:
525 if (sym != NULL)
527 CHECK_STATIC_TLS (map, sym_map);
528 *reloc_addr += sym->st_value + sym_map->l_tls_offset;
530 break;
531 case R_ARM_IRELATIVE:
532 value = map->l_addr + *reloc_addr;
533 value = ((Elf32_Addr (*) (int)) value) (GLRO(dl_hwcap));
534 *reloc_addr = value;
535 break;
536 #endif
537 default:
538 _dl_reloc_bad_type (map, r_type, 0);
539 break;
544 # ifndef RTLD_BOOTSTRAP
545 auto inline void
546 __attribute__ ((always_inline))
547 elf_machine_rela (struct link_map *map, const Elf32_Rela *reloc,
548 const Elf32_Sym *sym, const struct r_found_version *version,
549 void *const reloc_addr_arg, int skip_ifunc)
551 Elf32_Addr *const reloc_addr = reloc_addr_arg;
552 const unsigned int r_type = ELF32_R_TYPE (reloc->r_info);
554 if (__builtin_expect (r_type == R_ARM_RELATIVE, 0))
555 *reloc_addr = map->l_addr + reloc->r_addend;
556 else if (__builtin_expect (r_type == R_ARM_NONE, 0))
557 return;
558 else
560 # ifndef RESOLVE_CONFLICT_FIND_MAP
561 const Elf32_Sym *const refsym = sym;
562 # endif
563 struct link_map *sym_map = RESOLVE_MAP (&sym, version, r_type);
564 Elf32_Addr value = sym_map == NULL ? 0 : sym_map->l_addr + sym->st_value;
566 if (sym != NULL
567 && __builtin_expect (ELFW(ST_TYPE) (sym->st_info) == STT_GNU_IFUNC, 0)
568 && __builtin_expect (sym->st_shndx != SHN_UNDEF, 1)
569 && __builtin_expect (!skip_ifunc, 1))
570 value = elf_ifunc_invoke (value);
572 switch (r_type)
574 # ifndef RESOLVE_CONFLICT_FIND_MAP
575 /* Not needed for dl-conflict.c. */
576 case R_ARM_COPY:
577 if (sym == NULL)
578 /* This can happen in trace mode if an object could not be
579 found. */
580 break;
581 if (sym->st_size > refsym->st_size
582 || (GLRO(dl_verbose) && sym->st_size < refsym->st_size))
584 const char *strtab;
586 strtab = (const void *) D_PTR (map, l_info[DT_STRTAB]);
587 _dl_error_printf ("\
588 %s: Symbol `%s' has different size in shared object, consider re-linking\n",
589 RTLD_PROGNAME, strtab + refsym->st_name);
591 memcpy (reloc_addr_arg, (void *) value,
592 MIN (sym->st_size, refsym->st_size));
593 break;
594 # endif /* !RESOLVE_CONFLICT_FIND_MAP */
595 case R_ARM_GLOB_DAT:
596 case R_ARM_JUMP_SLOT:
597 case R_ARM_ABS32:
598 *reloc_addr = value + reloc->r_addend;
599 break;
600 # ifdef RESOLVE_CONFLICT_FIND_MAP
601 case R_ARM_TLS_DESC:
603 struct tlsdesc volatile *td __attribute__ ((unused)) =
604 (struct tlsdesc volatile *) reloc_addr;
606 RESOLVE_CONFLICT_FIND_MAP (map, reloc_addr);
608 /* Make sure we know what's going on. */
609 assert (td->entry
610 == (void *) (D_PTR (map, l_info[ADDRIDX (DT_TLSDESC_PLT)])
611 + map->l_addr));
612 assert (map->l_info[ADDRIDX (DT_TLSDESC_GOT)]);
614 /* Set up the lazy resolver and store the pointer to our link
615 map in _GLOBAL_OFFSET_TABLE[1] now as for a prelinked
616 binary elf_machine_runtime_setup() is not called and hence
617 neither has been initialized. */
618 *(Elf32_Addr *) (D_PTR (map, l_info[ADDRIDX (DT_TLSDESC_GOT)])
619 + map->l_addr)
620 = (Elf32_Addr) &_dl_tlsdesc_lazy_resolver;
621 ((Elf32_Addr *) D_PTR (map, l_info[DT_PLTGOT]))[1]
622 = (Elf32_Addr) map;
624 break;
625 # endif /* RESOLVE_CONFLICT_FIND_MAP */
626 case R_ARM_PC24:
627 relocate_pc24 (map, value, reloc_addr, reloc->r_addend);
628 break;
629 #if !defined RTLD_BOOTSTRAP
630 case R_ARM_TLS_DTPMOD32:
631 /* Get the information from the link map returned by the
632 resolv function. */
633 if (sym_map != NULL)
634 *reloc_addr = sym_map->l_tls_modid;
635 break;
637 case R_ARM_TLS_DTPOFF32:
638 *reloc_addr = (sym == NULL ? 0 : sym->st_value) + reloc->r_addend;
639 break;
641 case R_ARM_TLS_TPOFF32:
642 if (sym != NULL)
644 CHECK_STATIC_TLS (map, sym_map);
645 *reloc_addr = (sym->st_value + sym_map->l_tls_offset
646 + reloc->r_addend);
648 break;
649 case R_ARM_IRELATIVE:
650 value = map->l_addr + reloc->r_addend;
651 value = ((Elf32_Addr (*) (int)) value) (GLRO(dl_hwcap));
652 *reloc_addr = value;
653 break;
654 #endif
655 default:
656 _dl_reloc_bad_type (map, r_type, 0);
657 break;
661 # endif
663 auto inline void
664 __attribute__ ((always_inline))
665 elf_machine_rel_relative (Elf32_Addr l_addr, const Elf32_Rel *reloc,
666 void *const reloc_addr_arg)
668 Elf32_Addr *const reloc_addr = reloc_addr_arg;
669 *reloc_addr += l_addr;
672 # ifndef RTLD_BOOTSTRAP
673 auto inline void
674 __attribute__ ((always_inline))
675 elf_machine_rela_relative (Elf32_Addr l_addr, const Elf32_Rela *reloc,
676 void *const reloc_addr_arg)
678 Elf32_Addr *const reloc_addr = reloc_addr_arg;
679 *reloc_addr = l_addr + reloc->r_addend;
681 # endif
683 auto inline void
684 __attribute__ ((always_inline))
685 elf_machine_lazy_rel (struct link_map *map,
686 Elf32_Addr l_addr, const Elf32_Rel *reloc,
687 int skip_ifunc)
689 Elf32_Addr *const reloc_addr = (void *) (l_addr + reloc->r_offset);
690 const unsigned int r_type = ELF32_R_TYPE (reloc->r_info);
691 /* Check for unexpected PLT reloc type. */
692 if (__builtin_expect (r_type == R_ARM_JUMP_SLOT, 1))
694 if (__builtin_expect (map->l_mach.plt, 0) == 0)
695 *reloc_addr += l_addr;
696 else
697 *reloc_addr = map->l_mach.plt;
699 else if (__builtin_expect (r_type == R_ARM_TLS_DESC, 1))
701 struct tlsdesc volatile *td =
702 (struct tlsdesc volatile *)reloc_addr;
704 /* The linker must have given us the parameter we need in the
705 first GOT entry, and left the second one empty. The latter
706 will have been preset by the prelinker if used though.
707 We fill it with the resolver address. */
708 assert (td->entry == 0
709 || map->l_info[VALIDX (DT_GNU_PRELINKED)] != NULL);
710 td->entry = (void*)(D_PTR (map, l_info[ADDRIDX (DT_TLSDESC_PLT)])
711 + map->l_addr);
713 else
714 _dl_reloc_bad_type (map, r_type, 1);
717 #endif /* RESOLVE_MAP */