2009-04-23 Carlos O'Donell <carlos@codesourcery.com>
[glibc.git] / sysdeps / hppa / dl-machine.h
blobe462fd33549308e4b342b3e4ee7496d1e0f4dd1c
1 /* Machine-dependent ELF dynamic relocation inline functions. PA-RISC version.
2 Copyright (C) 1995-1997,1999-2003
3 Free Software Foundation, Inc.
4 Contributed by David Huggins-Daines <dhd@debian.org>
5 This file is part of the GNU C Library.
7 The GNU C Library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
12 The GNU C Library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
17 You should have received a copy of the GNU Lesser General Public
18 License along with the GNU C Library; if not, write to the Free
19 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20 02111-1307 USA. */
22 #ifndef dl_machine_h
23 #define dl_machine_h 1
25 #define ELF_MACHINE_NAME "hppa"
27 #include <sys/param.h>
28 #include <assert.h>
29 #include <string.h>
30 #include <link.h>
31 #include <errno.h>
32 #include <dl-fptr.h>
33 #include <abort-instr.h>
34 #include <tls.h>
36 /* These two definitions must match the definition of the stub in
37 bfd/elf32-hppa.c (see plt_stub[]).
39 a. Define the size of the *entire* stub we place at the end of the PLT
40 table (right up against the GOT).
42 b. Define the number of bytes back from the GOT to the entry point of
43 the PLT stub. You see the PLT stub must be entered in the middle
44 so it can depwi to find it's own address (long jump stub)
46 c. Define the size of a single PLT entry so we can jump over the
47 last entry to get the stub address */
49 #define SIZEOF_PLT_STUB (7*4)
50 #define GOT_FROM_PLT_STUB (4*4)
51 #define PLT_ENTRY_SIZE (2*4)
53 /* Initialize the function descriptor table before relocations */
54 static inline void
55 __hppa_init_bootstrap_fdesc_table (struct link_map *map)
57 ElfW(Addr) *boot_table;
59 /* Careful: this will be called before got has been relocated... */
60 ELF_MACHINE_LOAD_ADDRESS(boot_table,_dl_boot_fptr_table);
62 map->l_mach.fptr_table_len = ELF_MACHINE_BOOT_FPTR_TABLE_LEN;
63 map->l_mach.fptr_table = boot_table;
66 #define ELF_MACHINE_BEFORE_RTLD_RELOC(dynamic_info) \
67 __hppa_init_bootstrap_fdesc_table (&bootstrap_map);
69 /* Return nonzero iff ELF header is compatible with the running host. */
70 static inline int
71 elf_machine_matches_host (const Elf32_Ehdr *ehdr)
73 return ehdr->e_machine == EM_PARISC;
76 /* Return the link-time address of _DYNAMIC. */
77 static inline Elf32_Addr
78 elf_machine_dynamic (void) __attribute__ ((const));
80 static inline Elf32_Addr
81 elf_machine_dynamic (void)
83 Elf32_Addr dynamic;
85 asm ("b,l 1f,%0\n"
86 " depi 0,31,2,%0\n"
87 "1: addil L'_GLOBAL_OFFSET_TABLE_ - ($PIC_pcrel$0 - 8),%0\n"
88 " ldw R'_GLOBAL_OFFSET_TABLE_ - ($PIC_pcrel$0 - 12)(%%r1),%0\n"
89 : "=r" (dynamic) : : "r1");
91 return dynamic;
94 /* Return the run-time load address of the shared object. */
95 static inline Elf32_Addr
96 elf_machine_load_address (void) __attribute__ ((const));
98 static inline Elf32_Addr
99 elf_machine_load_address (void)
101 Elf32_Addr dynamic;
103 asm (
104 " b,l 1f,%0\n"
105 " depi 0,31,2,%0\n"
106 "1: addil L'_DYNAMIC - ($PIC_pcrel$0 - 8),%0\n"
107 " ldo R'_DYNAMIC - ($PIC_pcrel$0 - 12)(%%r1),%0\n"
108 : "=r" (dynamic) : : "r1");
110 return dynamic - elf_machine_dynamic ();
113 /* Fixup a PLT entry to bounce directly to the function at VALUE. */
114 static inline struct fdesc __attribute__ ((always_inline))
115 elf_machine_fixup_plt (struct link_map *map, lookup_t t,
116 const Elf32_Rela *reloc,
117 Elf32_Addr *reloc_addr, struct fdesc value)
119 volatile Elf32_Addr *rfdesc = reloc_addr;
120 /* map is the link_map for the caller, t is the link_map for the object
121 being called */
122 rfdesc[1] = value.gp;
123 /* Need to ensure that the gp is visible before the code
124 entry point is updated */
125 rfdesc[0] = value.ip;
126 return value;
129 /* Return the final value of a plt relocation. */
130 static inline struct fdesc
131 elf_machine_plt_value (struct link_map *map, const Elf32_Rela *reloc,
132 struct fdesc value)
134 /* We are rela only, return a function descriptor as a plt entry. */
135 return (struct fdesc) { value.ip + reloc->r_addend, value.gp };
138 /* Set up the loaded object described by L so its unrelocated PLT
139 entries will jump to the on-demand fixup code in dl-runtime.c. */
141 static inline int
142 elf_machine_runtime_setup (struct link_map *l, int lazy, int profile)
144 Elf32_Addr *got = NULL;
145 Elf32_Addr l_addr, iplt, jmprel, end_jmprel, r_type, r_sym;
146 const Elf32_Rela *reloc;
147 struct fdesc *fptr;
148 static union {
149 unsigned char c[8];
150 Elf32_Addr i[2];
151 } sig = {{0x00,0xc0,0xff,0xee, 0xde,0xad,0xbe,0xef}};
153 /* If we don't have a PLT we can just skip all this... */
154 if (__builtin_expect (l->l_info[DT_JMPREL] == NULL,0))
155 return lazy;
157 /* All paths use these values */
158 l_addr = l->l_addr;
159 jmprel = D_PTR(l, l_info[DT_JMPREL]);
160 end_jmprel = jmprel + l->l_info[DT_PLTRELSZ]->d_un.d_val;
162 extern void _dl_runtime_resolve (void);
163 extern void _dl_runtime_profile (void);
165 /* Linking lazily */
166 if (lazy)
168 /* FIXME: Search for the got, but backwards through the relocs, technically we should
169 find it on the first try. However, assuming the relocs got out of order the
170 routine is made a bit more robust by searching them all in case of failure. */
171 for (iplt = (end_jmprel - sizeof(Elf32_Rela)); iplt >= jmprel; iplt -= sizeof (Elf32_Rela))
174 reloc = (const Elf32_Rela *) iplt;
175 r_type = ELF32_R_TYPE (reloc->r_info);
176 r_sym = ELF32_R_SYM (reloc->r_info);
178 got = (Elf32_Addr *) (reloc->r_offset + l_addr + PLT_ENTRY_SIZE + SIZEOF_PLT_STUB);
180 /* If we aren't an IPLT, and we aren't NONE then it's a bad reloc */
181 if (__builtin_expect (r_type != R_PARISC_IPLT, 0))
183 if (__builtin_expect (r_type != R_PARISC_NONE, 0))
184 _dl_reloc_bad_type (l, r_type, 1);
185 continue;
188 /* Check for the plt_stub that binutils placed here for us
189 to use with _dl_runtime_resolve */
190 if (got[-2] != sig.i[0] || got[-1] != sig.i[1])
192 got = NULL; /* Not the stub... keep looking */
194 else
196 /* Found the GOT! */
197 register Elf32_Addr ltp __asm__ ("%r19");
199 /* Identify this shared object. Second entry in the got. */
200 got[1] = (Elf32_Addr) l;
202 /* This function will be called to perform the relocation. */
203 if (__builtin_expect (!profile, 1))
205 /* If a static application called us, then _dl_runtime_resolve is not
206 a function descriptor, but the *real* address of the function... */
207 if((unsigned long) &_dl_runtime_resolve & 3)
209 got[-2] = (Elf32_Addr) ((struct fdesc *)
210 ((unsigned long) &_dl_runtime_resolve & ~3))->ip;
212 else
214 /* Static executable! */
215 got[-2] = (Elf32_Addr) &_dl_runtime_resolve;
218 else
220 if (GLRO(dl_profile) != NULL
221 && _dl_name_match_p (GLRO(dl_profile), l))
223 /* This is the object we are looking for. Say that
224 we really want profiling and the timers are
225 started. */
226 GL(dl_profile_map) = l;
229 if((unsigned long) &_dl_runtime_profile & 3)
231 got[-2] = (Elf32_Addr) ((struct fdesc *)
232 ((unsigned long) &_dl_runtime_profile & ~3))->ip;
234 else
236 /* Static executable */
237 got[-2] = (Elf32_Addr) &_dl_runtime_profile;
240 /* Plunk in the gp of this function descriptor so we
241 can make the call to _dl_runtime_xxxxxx */
242 got[-1] = ltp;
243 break;
244 /* Done looking for the GOT, and stub is setup */
245 } /* else we found the GOT */
246 } /* for, walk the relocs backwards */
248 if(!got)
249 return 0; /* No lazy linking for you! */
251 /* Process all the relocs, now that we know the GOT... */
252 for (iplt = jmprel; iplt < end_jmprel; iplt += sizeof (Elf32_Rela))
254 reloc = (const Elf32_Rela *) iplt;
255 r_type = ELF32_R_TYPE (reloc->r_info);
256 r_sym = ELF32_R_SYM (reloc->r_info);
258 if (__builtin_expect (r_type == R_PARISC_IPLT, 1))
260 fptr = (struct fdesc *) (reloc->r_offset + l_addr);
261 if (r_sym != 0)
263 /* Relocate the pointer to the stub. */
264 fptr->ip = (Elf32_Addr) got - GOT_FROM_PLT_STUB;
266 /* Instead of the LTP value, we put the reloc offset
267 here. The trampoline code will load the proper
268 LTP and pass the reloc offset to the fixup
269 function. */
270 fptr->gp = iplt - jmprel;
271 } /* r_sym != 0 */
272 else
274 /* Relocate this *ABS* entry. */
275 fptr->ip = reloc->r_addend + l_addr;
276 fptr->gp = D_PTR (l, l_info[DT_PLTGOT]);
278 } /* r_type == R_PARISC_IPLT */
279 } /* for all the relocations */
280 } /* if lazy */
281 else
283 for (iplt = jmprel; iplt < end_jmprel; iplt += sizeof (Elf32_Rela))
285 reloc = (const Elf32_Rela *) iplt;
286 r_type = ELF32_R_TYPE (reloc->r_info);
287 r_sym = ELF32_R_SYM (reloc->r_info);
289 if (__builtin_expect ((r_type == R_PARISC_IPLT) && (r_sym == 0), 1))
291 fptr = (struct fdesc *) (reloc->r_offset + l_addr);
292 /* Relocate this *ABS* entry, set only the gp, the rest is set later
293 when elf_machine_rela_relative is called (WITHOUT the linkmap) */
294 fptr->gp = D_PTR (l, l_info[DT_PLTGOT]);
295 } /* r_type == R_PARISC_IPLT */
296 } /* for all the relocations */
298 return lazy;
302 /* Names of the architecture-specific auditing callback functions. */
303 #define ARCH_LA_PLTENTER hppa_gnu_pltenter
304 #define ARCH_LA_PLTEXIT hppa_gnu_pltexit
306 /* Initial entry point code for the dynamic linker.
307 The C function `_dl_start' is the real entry point;
308 its return value is the user program's entry point. */
310 #define RTLD_START \
311 /* Set up dp for any non-PIC lib constructors that may be called. */ \
312 static struct link_map * __attribute__((used)) \
313 set_dp (struct link_map *map) \
315 register Elf32_Addr dp asm ("%r27"); \
316 dp = D_PTR (map, l_info[DT_PLTGOT]); \
317 asm volatile ("" : : "r" (dp)); \
318 return map; \
321 asm ( \
322 " .text\n" \
323 " .globl _start\n" \
324 " .type _start,@function\n" \
325 "_start:\n" \
326 /* The kernel does not give us an initial stack frame. */ \
327 " ldo 64(%sp),%sp\n" \
328 /* Save the relevant arguments (yes, those are the correct \
329 registers, the kernel is weird) in their stack slots. */ \
330 " stw %r25,-40(%sp)\n" /* argc */ \
331 " stw %r24,-44(%sp)\n" /* argv */ \
333 /* We need the LTP, and we need it now. \
334 $PIC_pcrel$0 points 8 bytes past the current instruction, \
335 just like a branch reloc. This sequence gets us the \
336 runtime address of _DYNAMIC. */ \
337 " bl 0f,%r19\n" \
338 " depi 0,31,2,%r19\n" /* clear priviledge bits */ \
339 "0: addil L'_DYNAMIC - ($PIC_pcrel$0 - 8),%r19\n" \
340 " ldo R'_DYNAMIC - ($PIC_pcrel$0 - 12)(%r1),%r26\n" \
342 /* The link time address is stored in the first entry of the \
343 GOT. */ \
344 " addil L'_GLOBAL_OFFSET_TABLE_ - ($PIC_pcrel$0 - 16),%r19\n" \
345 " ldw R'_GLOBAL_OFFSET_TABLE_ - ($PIC_pcrel$0 - 20)(%r1),%r20\n" \
347 " sub %r26,%r20,%r20\n" /* Calculate load offset */ \
349 /* Rummage through the dynamic entries, looking for \
350 DT_PLTGOT. */ \
351 " ldw,ma 8(%r26),%r19\n" \
352 "1: cmpib,=,n 3,%r19,2f\n" /* tag == DT_PLTGOT? */ \
353 " cmpib,<>,n 0,%r19,1b\n" \
354 " ldw,ma 8(%r26),%r19\n" \
356 /* Uh oh! We didn't find one. Abort. */ \
357 " iitlbp %r0,(%sr0,%r0)\n" \
359 "2: ldw -4(%r26),%r19\n" /* Found it, load value. */ \
360 " add %r19,%r20,%r19\n" /* And add the load offset. */ \
362 /* Our initial stack layout is rather different from everyone \
363 else's due to the unique PA-RISC ABI. As far as I know it \
364 looks like this: \
366 ----------------------------------- (this frame created above) \
367 | 32 bytes of magic | \
368 |---------------------------------| \
369 | 32 bytes argument/sp save area | \
370 |---------------------------------| ((current->mm->env_end) \
371 | N bytes of slack | + 63 & ~63) \
372 |---------------------------------| \
373 | envvar and arg strings | \
374 |---------------------------------| \
375 | ELF auxiliary info | \
376 | (up to 28 words) | \
377 |---------------------------------| \
378 | Environment variable pointers | \
379 | upwards to NULL | \
380 |---------------------------------| \
381 | Argument pointers | \
382 | upwards to NULL | \
383 |---------------------------------| \
384 | argc (1 word) | \
385 ----------------------------------- \
387 So, obviously, we can't just pass %sp to _dl_start. That's \
388 okay, argv-4 will do just fine. \
390 The pleasant part of this is that if we need to skip \
391 arguments we can just decrement argc and move argv, because \
392 the stack pointer is utterly unrelated to the location of \
393 the environment and argument vectors. */ \
395 /* This is always within range so we'll be okay. */ \
396 " bl _dl_start,%rp\n" \
397 " ldo -4(%r24),%r26\n" \
399 " .globl _dl_start_user\n" \
400 " .type _dl_start_user,@function\n" \
401 "_dl_start_user:\n" \
402 /* Save the entry point in %r3. */ \
403 " copy %ret0,%r3\n" \
405 /* Remember the lowest stack address. */ \
406 " addil LT'__libc_stack_end,%r19\n" \
407 " ldw RT'__libc_stack_end(%r1),%r20\n" \
408 " stw %sp,0(%r20)\n" \
410 /* See if we were called as a command with the executable file \
411 name as an extra leading argument. */ \
412 " addil LT'_dl_skip_args,%r19\n" \
413 " ldw RT'_dl_skip_args(%r1),%r20\n" \
414 " ldw 0(%r20),%r20\n" \
416 " ldw -40(%sp),%r25\n" /* argc */ \
417 " comib,= 0,%r20,.Lnofix\n" /* FIXME: Mispredicted branch */\
418 " ldw -44(%sp),%r24\n" /* argv (delay slot) */ \
420 " sub %r25,%r20,%r25\n" \
421 " stw %r25,-40(%sp)\n" \
422 " sh2add %r20,%r24,%r24\n" \
423 " stw %r24,-44(%sp)\n" \
425 ".Lnofix:\n" \
426 " addil LT'_rtld_local,%r19\n" \
427 " ldw RT'_rtld_local(%r1),%r26\n" \
428 " bl set_dp, %r2\n" \
429 " ldw 0(%r26),%r26\n" \
431 /* Call _dl_init(_dl_loaded, argc, argv, envp). */ \
432 " copy %r28,%r26\n" \
434 /* envp = argv + argc + 1 */ \
435 " sh2add %r25,%r24,%r23\n" \
436 " bl _dl_init_internal,%r2\n" \
437 " ldo 4(%r23),%r23\n" /* delay slot */ \
439 /* Reload argc, argv to the registers start.S expects. */ \
440 " ldw -40(%sp),%r25\n" \
441 " ldw -44(%sp),%r24\n" \
443 /* _dl_fini is a local function in the loader, so we construct \
444 a false OPD here and pass this to the application. */ \
445 /* FIXME: Should be able to use P%, and LR RR to have the \
446 the linker construct a proper OPD. */ \
447 " .section .data\n" \
448 "__dl_fini_plabel:\n" \
449 " .word _dl_fini\n" \
450 " .word 0xdeadbeef\n" \
451 " .previous\n" \
453 /* %r3 contains a function pointer, we need to mask out the \
454 lower bits and load the gp and jump address. */ \
455 " depi 0,31,2,%r3\n" \
456 " ldw 0(%r3),%r2\n" \
457 " addil LT'__dl_fini_plabel,%r19\n" \
458 " ldw RT'__dl_fini_plabel(%r1),%r23\n" \
459 " stw %r19,4(%r23)\n" \
460 " ldw 4(%r3),%r19\n" /* load the object's gp */ \
461 " bv %r0(%r2)\n" \
462 " depi 2,31,2,%r23\n" /* delay slot */ \
465 /* ELF_RTYPE_CLASS_PLT iff TYPE describes relocation of a PLT entry or
466 a TLS variable, so references should not be allowed to define the value.
467 ELF_RTYPE_CLASS_NOCOPY iff TYPE should not be allowed to resolve to one
468 of the main executable's symbols, as for a COPY reloc. */
469 #if defined USE_TLS && (!defined RTLD_BOOTSTRAP || USE___THREAD)
470 # define elf_machine_type_class(type) \
471 ((((type) == R_PARISC_IPLT \
472 || (type) == R_PARISC_EPLT \
473 || (type) == R_PARISC_TLS_DTPMOD32 \
474 || (type) == R_PARISC_TLS_DTPOFF32 \
475 || (type) == R_PARISC_TLS_TPREL32) \
476 * ELF_RTYPE_CLASS_PLT) \
477 | (((type) == R_PARISC_COPY) * ELF_RTYPE_CLASS_COPY))
478 #else
479 #define elf_machine_type_class(type) \
480 ((((type) == R_PARISC_IPLT \
481 || (type) == R_PARISC_EPLT) \
482 * ELF_RTYPE_CLASS_PLT) \
483 | (((type) == R_PARISC_COPY) * ELF_RTYPE_CLASS_COPY))
484 #endif
486 /* Used by the runtime in fixup to figure out if reloc is *really* PLT */
487 #define ELF_MACHINE_JMP_SLOT R_PARISC_IPLT
488 #define ELF_MACHINE_SIZEOF_JMP_SLOT PLT_ENTRY_SIZE
490 /* We only use RELA. */
491 #define ELF_MACHINE_NO_REL 1
493 /* Return the address of the entry point. */
494 #define ELF_MACHINE_START_ADDRESS(map, start) \
495 DL_STATIC_FUNCTION_ADDRESS (map, start)
497 /* We define an initialization functions. This is called very early in
498 * _dl_sysdep_start. */
499 #define DL_PLATFORM_INIT dl_platform_init ()
501 static inline void __attribute__ ((unused))
502 dl_platform_init (void)
504 if (GLRO(dl_platform) != NULL && *GLRO(dl_platform) == '\0')
505 /* Avoid an empty string which would disturb us. */
506 GLRO(dl_platform) = NULL;
509 #endif /* !dl_machine_h */
511 /* These are only actually used where RESOLVE_MAP is defined, anyway. */
512 #ifdef RESOLVE_MAP
514 #define reassemble_21(as21) \
515 ( (((as21) & 0x100000) >> 20) \
516 | (((as21) & 0x0ffe00) >> 8) \
517 | (((as21) & 0x000180) << 7) \
518 | (((as21) & 0x00007c) << 14) \
519 | (((as21) & 0x000003) << 12))
521 #define reassemble_14(as14) \
522 ( (((as14) & 0x1fff) << 1) \
523 | (((as14) & 0x2000) >> 13))
525 auto void __attribute__((always_inline))
526 elf_machine_rela (struct link_map *map,
527 const Elf32_Rela *reloc,
528 const Elf32_Sym *sym,
529 const struct r_found_version *version,
530 void *const reloc_addr_arg)
532 Elf32_Addr *const reloc_addr = reloc_addr_arg;
533 const Elf32_Sym *const refsym = sym;
534 unsigned long const r_type = ELF32_R_TYPE (reloc->r_info);
535 struct link_map *sym_map;
536 Elf32_Addr value;
538 # if !defined RTLD_BOOTSTRAP && !defined HAVE_Z_COMBRELOC && !defined SHARED
539 /* This is defined in rtld.c, but nowhere in the static libc.a; make the
540 reference weak so static programs can still link. This declaration
541 cannot be done when compiling rtld.c (i.e. #ifdef RTLD_BOOTSTRAP)
542 because rtld.c contains the common defn for _dl_rtld_map, which is
543 incompatible with a weak decl in the same file. */
544 weak_extern (GL(dl_rtld_map));
545 # endif
547 /* RESOLVE_MAP will return a null value for undefined syms, and
548 non-null for all other syms. In particular, relocs with no
549 symbol (symbol index of zero), also called *ABS* relocs, will be
550 resolved to MAP. (The first entry in a symbol table is all
551 zeros, and an all zero Elf32_Sym has a binding of STB_LOCAL.)
552 See RESOLVE_MAP definition in elf/dl-reloc.c */
553 # ifdef RTLD_BOOTSTRAP
554 /* RESOLVE_MAP in rtld.c doesn't have the local sym test. */
555 sym_map = (ELF32_ST_BIND (sym->st_info) != STB_LOCAL
556 ? RESOLVE_MAP (&sym, version, r_type) : map);
557 # else
558 sym_map = RESOLVE_MAP (&sym, version, r_type);
559 # endif
561 if (sym_map)
563 value = sym ? sym_map->l_addr + sym->st_value : 0;
564 value += reloc->r_addend;
566 else
567 value = 0;
569 switch (r_type)
571 case R_PARISC_DIR32:
572 /* .eh_frame can have unaligned relocs. */
573 if ((unsigned long) reloc_addr_arg & 3)
575 char *rel_addr = (char *) reloc_addr_arg;
576 rel_addr[0] = value >> 24;
577 rel_addr[1] = value >> 16;
578 rel_addr[2] = value >> 8;
579 rel_addr[3] = value;
580 return;
582 break;
584 case R_PARISC_DIR21L:
586 unsigned int insn = *(unsigned int *)reloc_addr;
587 value = sym_map->l_addr + sym->st_value
588 + ((reloc->r_addend + 0x1000) & -0x2000);
589 value = value >> 11;
590 insn = (insn &~ 0x1fffff) | reassemble_21 (value);
591 *(unsigned int *)reloc_addr = insn;
593 return;
595 case R_PARISC_DIR14R:
597 unsigned int insn = *(unsigned int *)reloc_addr;
598 value = ((sym_map->l_addr + sym->st_value) & 0x7ff)
599 + (((reloc->r_addend & 0x1fff) ^ 0x1000) - 0x1000);
600 insn = (insn &~ 0x3fff) | reassemble_14 (value);
601 *(unsigned int *)reloc_addr = insn;
603 return;
605 case R_PARISC_PLABEL32:
606 /* Easy rule: If there is a symbol and it is global, then we
607 need to make a dynamic function descriptor. Otherwise we
608 have the address of a PLT slot for a local symbol which we
609 know to be unique. */
610 if (sym == NULL
611 || sym_map == NULL
612 || ELF32_ST_BIND (sym->st_info) == STB_LOCAL)
614 break;
616 /* Set bit 30 to indicate to $$dyncall that this is a PLABEL.
617 We have to do this outside of the generic function descriptor
618 code, since it doesn't know about our requirement for setting
619 protection bits */
620 value = (Elf32_Addr)((unsigned int)_dl_make_fptr (sym_map, sym, value) | 2);
621 break;
623 case R_PARISC_PLABEL21L:
624 case R_PARISC_PLABEL14R:
626 unsigned int insn = *(unsigned int *)reloc_addr;
628 if (__builtin_expect (sym == NULL, 0))
629 break;
631 value = (Elf32_Addr)((unsigned int)_dl_make_fptr (sym_map, sym, value) | 2);
633 if (r_type == R_PARISC_PLABEL21L)
635 value >>= 11;
636 insn = (insn &~ 0x1fffff) | reassemble_21 (value);
638 else
640 value &= 0x7ff;
641 insn = (insn &~ 0x3fff) | reassemble_14 (value);
644 *(unsigned int *)reloc_addr = insn;
646 return;
648 case R_PARISC_IPLT:
649 if (__builtin_expect (sym_map != NULL, 1))
651 elf_machine_fixup_plt (NULL, sym_map, reloc, reloc_addr,
652 DL_FIXUP_MAKE_VALUE(sym_map, value));
654 else
656 /* If we get here, it's a (weak) undefined sym. */
657 elf_machine_fixup_plt (NULL, map, reloc, reloc_addr,
658 DL_FIXUP_MAKE_VALUE(map, value));
660 return;
662 case R_PARISC_COPY:
663 if (__builtin_expect (sym == NULL, 0))
664 /* This can happen in trace mode if an object could not be
665 found. */
666 break;
667 if (__builtin_expect (sym->st_size > refsym->st_size, 0)
668 || (__builtin_expect (sym->st_size < refsym->st_size, 0)
669 && __builtin_expect (GLRO(dl_verbose), 0)))
671 const char *strtab;
673 strtab = (const char *) D_PTR (map, l_info[DT_STRTAB]);
674 _dl_error_printf ("%s: Symbol `%s' has different size in shared object, "
675 "consider re-linking\n",
676 rtld_progname ?: "<program name unknown>",
677 strtab + refsym->st_name);
679 memcpy (reloc_addr_arg, (void *) value,
680 MIN (sym->st_size, refsym->st_size));
681 return;
683 #if defined USE_TLS && (!defined RTLD_BOOTSTRAP)
684 case R_PARISC_TLS_DTPMOD32:
685 value = sym_map->l_tls_modid;
686 break;
688 case R_PARISC_TLS_DTPOFF32:
689 /* During relocation all TLS symbols are defined and used.
690 Therefore the offset is already correct. */
691 if (sym != NULL)
692 *reloc_addr = sym->st_value;
693 return;
695 case R_PARISC_TLS_TPREL32:
696 /* The offset is negative, forward from the thread pointer */
697 if (sym != NULL)
699 CHECK_STATIC_TLS (map, sym_map);
700 value = sym_map->l_tls_offset + sym->st_value + reloc->r_addend;
702 break;
703 #endif /* use TLS */
705 case R_PARISC_NONE: /* Alright, Wilbur. */
706 return;
708 default:
709 _dl_reloc_bad_type (map, r_type, 0);
712 *reloc_addr = value;
715 /* hppa doesn't have an R_PARISC_RELATIVE reloc, but uses relocs with
716 ELF32_R_SYM (info) == 0 for a similar purpose. */
717 auto void __attribute__((always_inline))
718 elf_machine_rela_relative (Elf32_Addr l_addr,
719 const Elf32_Rela *reloc,
720 void *const reloc_addr_arg)
722 unsigned long const r_type = ELF32_R_TYPE (reloc->r_info);
723 Elf32_Addr *const reloc_addr = reloc_addr_arg;
724 static char msgbuf[] = { "Unknown" };
725 struct link_map map;
726 Elf32_Addr value;
728 value = l_addr + reloc->r_addend;
730 if (ELF32_R_SYM (reloc->r_info) != 0){
731 _dl_error_printf ("%s: In elf_machine_rela_relative "
732 "ELF32_R_SYM (reloc->r_info) != 0. Aborting.",
733 rtld_progname ?: "<program name unknown>");
734 ABORT_INSTRUCTION; /* Crash. */
737 switch (r_type)
739 case R_PARISC_DIR32:
740 /* .eh_frame can have unaligned relocs. */
741 if ((unsigned long) reloc_addr_arg & 3)
743 char *rel_addr = (char *) reloc_addr_arg;
744 rel_addr[0] = value >> 24;
745 rel_addr[1] = value >> 16;
746 rel_addr[2] = value >> 8;
747 rel_addr[3] = value;
748 return;
750 break;
752 case R_PARISC_PLABEL32:
753 break;
755 case R_PARISC_IPLT: /* elf_machine_runtime_setup already set gp */
756 break;
758 case R_PARISC_NONE:
759 return;
761 default: /* Bad reloc, map unknown (really it's the current map) */
762 map.l_name = msgbuf;
763 _dl_reloc_bad_type (&map, r_type, 0);
764 return;
767 *reloc_addr = value;
770 auto void __attribute__((always_inline))
771 elf_machine_lazy_rel (struct link_map *map,
772 Elf32_Addr l_addr, const Elf32_Rela *reloc)
774 /* We don't have anything to do here. elf_machine_runtime_setup has
775 done all the relocs already. */
778 #endif /* RESOLVE_MAP */