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