1 /* Support for HPPA 64-bit ELF 2 Copyright (C) 1999-2014 Free Software Foundation, Inc. 3 4 This file is part of BFD, the Binary File Descriptor library. 5 6 This program is free software; you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation; either version 3 of the License, or 9 (at your option) any later version. 10 11 This program 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 14 GNU General Public License for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with this program; if not, write to the Free Software 18 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, 19 MA 02110-1301, USA. */ 20 21 #include "sysdep.h" 22 #include "alloca-conf.h" 23 #include "bfd.h" 24 #include "libbfd.h" 25 #include "elf-bfd.h" 26 #include "elf/hppa.h" 27 #include "libhppa.h" 28 #include "elf64-hppa.h" 29 30 31 #define ARCH_SIZE 64 32 33 #define PLT_ENTRY_SIZE 0x10 34 #define DLT_ENTRY_SIZE 0x8 35 #define OPD_ENTRY_SIZE 0x20 36 37 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/pa20_64/dld.sl" 38 39 /* The stub is supposed to load the target address and target's DP 40 value out of the PLT, then do an external branch to the target 41 address. 42 43 LDD PLTOFF(%r27),%r1 44 BVE (%r1) 45 LDD PLTOFF+8(%r27),%r27 46 47 Note that we must use the LDD with a 14 bit displacement, not the one 48 with a 5 bit displacement. */ 49 static char plt_stub[] = {0x53, 0x61, 0x00, 0x00, 0xe8, 0x20, 0xd0, 0x00, 50 0x53, 0x7b, 0x00, 0x00 }; 51 52 struct elf64_hppa_link_hash_entry 53 { 54 struct elf_link_hash_entry eh; 55 56 /* Offsets for this symbol in various linker sections. */ 57 bfd_vma dlt_offset; 58 bfd_vma plt_offset; 59 bfd_vma opd_offset; 60 bfd_vma stub_offset; 61 62 /* The index of the (possibly local) symbol in the input bfd and its 63 associated BFD. Needed so that we can have relocs against local 64 symbols in shared libraries. */ 65 long sym_indx; 66 bfd *owner; 67 68 /* Dynamic symbols may need to have two different values. One for 69 the dynamic symbol table, one for the normal symbol table. 70 71 In such cases we store the symbol's real value and section 72 index here so we can restore the real value before we write 73 the normal symbol table. */ 74 bfd_vma st_value; 75 int st_shndx; 76 77 /* Used to count non-got, non-plt relocations for delayed sizing 78 of relocation sections. */ 79 struct elf64_hppa_dyn_reloc_entry 80 { 81 /* Next relocation in the chain. */ 82 struct elf64_hppa_dyn_reloc_entry *next; 83 84 /* The type of the relocation. */ 85 int type; 86 87 /* The input section of the relocation. */ 88 asection *sec; 89 90 /* Number of relocs copied in this section. */ 91 bfd_size_type count; 92 93 /* The index of the section symbol for the input section of 94 the relocation. Only needed when building shared libraries. */ 95 int sec_symndx; 96 97 /* The offset within the input section of the relocation. */ 98 bfd_vma offset; 99 100 /* The addend for the relocation. */ 101 bfd_vma addend; 102 103 } *reloc_entries; 104 105 /* Nonzero if this symbol needs an entry in one of the linker 106 sections. */ 107 unsigned want_dlt; 108 unsigned want_plt; 109 unsigned want_opd; 110 unsigned want_stub; 111 }; 112 113 struct elf64_hppa_link_hash_table 114 { 115 struct elf_link_hash_table root; 116 117 /* Shortcuts to get to the various linker defined sections. */ 118 asection *dlt_sec; 119 asection *dlt_rel_sec; 120 asection *plt_sec; 121 asection *plt_rel_sec; 122 asection *opd_sec; 123 asection *opd_rel_sec; 124 asection *other_rel_sec; 125 126 /* Offset of __gp within .plt section. When the PLT gets large we want 127 to slide __gp into the PLT section so that we can continue to use 128 single DP relative instructions to load values out of the PLT. */ 129 bfd_vma gp_offset; 130 131 /* Note this is not strictly correct. We should create a stub section for 132 each input section with calls. The stub section should be placed before 133 the section with the call. */ 134 asection *stub_sec; 135 136 bfd_vma text_segment_base; 137 bfd_vma data_segment_base; 138 139 /* We build tables to map from an input section back to its 140 symbol index. This is the BFD for which we currently have 141 a map. */ 142 bfd *section_syms_bfd; 143 144 /* Array of symbol numbers for each input section attached to the 145 current BFD. */ 146 int *section_syms; 147 }; 148 149 #define hppa_link_hash_table(p) \ 150 (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \ 151 == HPPA64_ELF_DATA ? ((struct elf64_hppa_link_hash_table *) ((p)->hash)) : NULL) 152 153 #define hppa_elf_hash_entry(ent) \ 154 ((struct elf64_hppa_link_hash_entry *)(ent)) 155 156 #define eh_name(eh) \ 157 (eh ? eh->root.root.string : "<undef>") 158 159 typedef struct bfd_hash_entry *(*new_hash_entry_func) 160 (struct bfd_hash_entry *, struct bfd_hash_table *, const char *); 161 162 static struct bfd_link_hash_table *elf64_hppa_hash_table_create 163 (bfd *abfd); 164 165 /* This must follow the definitions of the various derived linker 166 hash tables and shared functions. */ 167 #include "elf-hppa.h" 168 169 static bfd_boolean elf64_hppa_object_p 170 (bfd *); 171 172 static void elf64_hppa_post_process_headers 173 (bfd *, struct bfd_link_info *); 174 175 static bfd_boolean elf64_hppa_create_dynamic_sections 176 (bfd *, struct bfd_link_info *); 177 178 static bfd_boolean elf64_hppa_adjust_dynamic_symbol 179 (struct bfd_link_info *, struct elf_link_hash_entry *); 180 181 static bfd_boolean elf64_hppa_mark_milli_and_exported_functions 182 (struct elf_link_hash_entry *, void *); 183 184 static bfd_boolean elf64_hppa_size_dynamic_sections 185 (bfd *, struct bfd_link_info *); 186 187 static int elf64_hppa_link_output_symbol_hook 188 (struct bfd_link_info *, const char *, Elf_Internal_Sym *, 189 asection *, struct elf_link_hash_entry *); 190 191 static bfd_boolean elf64_hppa_finish_dynamic_symbol 192 (bfd *, struct bfd_link_info *, 193 struct elf_link_hash_entry *, Elf_Internal_Sym *); 194 195 static bfd_boolean elf64_hppa_finish_dynamic_sections 196 (bfd *, struct bfd_link_info *); 197 198 static bfd_boolean elf64_hppa_check_relocs 199 (bfd *, struct bfd_link_info *, 200 asection *, const Elf_Internal_Rela *); 201 202 static bfd_boolean elf64_hppa_dynamic_symbol_p 203 (struct elf_link_hash_entry *, struct bfd_link_info *); 204 205 static bfd_boolean elf64_hppa_mark_exported_functions 206 (struct elf_link_hash_entry *, void *); 207 208 static bfd_boolean elf64_hppa_finalize_opd 209 (struct elf_link_hash_entry *, void *); 210 211 static bfd_boolean elf64_hppa_finalize_dlt 212 (struct elf_link_hash_entry *, void *); 213 214 static bfd_boolean allocate_global_data_dlt 215 (struct elf_link_hash_entry *, void *); 216 217 static bfd_boolean allocate_global_data_plt 218 (struct elf_link_hash_entry *, void *); 219 220 static bfd_boolean allocate_global_data_stub 221 (struct elf_link_hash_entry *, void *); 222 223 static bfd_boolean allocate_global_data_opd 224 (struct elf_link_hash_entry *, void *); 225 226 static bfd_boolean get_reloc_section 227 (bfd *, struct elf64_hppa_link_hash_table *, asection *); 228 229 static bfd_boolean count_dyn_reloc 230 (bfd *, struct elf64_hppa_link_hash_entry *, 231 int, asection *, int, bfd_vma, bfd_vma); 232 233 static bfd_boolean allocate_dynrel_entries 234 (struct elf_link_hash_entry *, void *); 235 236 static bfd_boolean elf64_hppa_finalize_dynreloc 237 (struct elf_link_hash_entry *, void *); 238 239 static bfd_boolean get_opd 240 (bfd *, struct bfd_link_info *, struct elf64_hppa_link_hash_table *); 241 242 static bfd_boolean get_plt 243 (bfd *, struct bfd_link_info *, struct elf64_hppa_link_hash_table *); 244 245 static bfd_boolean get_dlt 246 (bfd *, struct bfd_link_info *, struct elf64_hppa_link_hash_table *); 247 248 static bfd_boolean get_stub 249 (bfd *, struct bfd_link_info *, struct elf64_hppa_link_hash_table *); 250 251 static int elf64_hppa_elf_get_symbol_type 252 (Elf_Internal_Sym *, int); 253 254 /* Initialize an entry in the link hash table. */ 255 256 static struct bfd_hash_entry * 257 hppa64_link_hash_newfunc (struct bfd_hash_entry *entry, 258 struct bfd_hash_table *table, 259 const char *string) 260 { 261 /* Allocate the structure if it has not already been allocated by a 262 subclass. */ 263 if (entry == NULL) 264 { 265 entry = bfd_hash_allocate (table, 266 sizeof (struct elf64_hppa_link_hash_entry)); 267 if (entry == NULL) 268 return entry; 269 } 270 271 /* Call the allocation method of the superclass. */ 272 entry = _bfd_elf_link_hash_newfunc (entry, table, string); 273 if (entry != NULL) 274 { 275 struct elf64_hppa_link_hash_entry *hh; 276 277 /* Initialize our local data. All zeros. */ 278 hh = hppa_elf_hash_entry (entry); 279 memset (&hh->dlt_offset, 0, 280 (sizeof (struct elf64_hppa_link_hash_entry) 281 - offsetof (struct elf64_hppa_link_hash_entry, dlt_offset))); 282 } 283 284 return entry; 285 } 286 287 /* Create the derived linker hash table. The PA64 ELF port uses this 288 derived hash table to keep information specific to the PA ElF 289 linker (without using static variables). */ 290 291 static struct bfd_link_hash_table* 292 elf64_hppa_hash_table_create (bfd *abfd) 293 { 294 struct elf64_hppa_link_hash_table *htab; 295 bfd_size_type amt = sizeof (*htab); 296 297 htab = bfd_zmalloc (amt); 298 if (htab == NULL) 299 return NULL; 300 301 if (!_bfd_elf_link_hash_table_init (&htab->root, abfd, 302 hppa64_link_hash_newfunc, 303 sizeof (struct elf64_hppa_link_hash_entry), 304 HPPA64_ELF_DATA)) 305 { 306 free (htab); 307 return NULL; 308 } 309 310 htab->text_segment_base = (bfd_vma) -1; 311 htab->data_segment_base = (bfd_vma) -1; 312 313 return &htab->root.root; 314 } 315 316 /* Return nonzero if ABFD represents a PA2.0 ELF64 file. 318 319 Additionally we set the default architecture and machine. */ 320 static bfd_boolean 321 elf64_hppa_object_p (bfd *abfd) 322 { 323 Elf_Internal_Ehdr * i_ehdrp; 324 unsigned int flags; 325 326 i_ehdrp = elf_elfheader (abfd); 327 if (strcmp (bfd_get_target (abfd), "elf64-hppa-linux") == 0) 328 { 329 /* GCC on hppa-linux produces binaries with OSABI=GNU, 330 but the kernel produces corefiles with OSABI=SysV. */ 331 if (i_ehdrp->e_ident[EI_OSABI] != ELFOSABI_GNU 332 && i_ehdrp->e_ident[EI_OSABI] != ELFOSABI_NONE) /* aka SYSV */ 333 return FALSE; 334 } 335 else 336 { 337 /* HPUX produces binaries with OSABI=HPUX, 338 but the kernel produces corefiles with OSABI=SysV. */ 339 if (i_ehdrp->e_ident[EI_OSABI] != ELFOSABI_HPUX 340 && i_ehdrp->e_ident[EI_OSABI] != ELFOSABI_NONE) /* aka SYSV */ 341 return FALSE; 342 } 343 344 flags = i_ehdrp->e_flags; 345 switch (flags & (EF_PARISC_ARCH | EF_PARISC_WIDE)) 346 { 347 case EFA_PARISC_1_0: 348 return bfd_default_set_arch_mach (abfd, bfd_arch_hppa, 10); 349 case EFA_PARISC_1_1: 350 return bfd_default_set_arch_mach (abfd, bfd_arch_hppa, 11); 351 case EFA_PARISC_2_0: 352 if (i_ehdrp->e_ident[EI_CLASS] == ELFCLASS64) 353 return bfd_default_set_arch_mach (abfd, bfd_arch_hppa, 25); 354 else 355 return bfd_default_set_arch_mach (abfd, bfd_arch_hppa, 20); 356 case EFA_PARISC_2_0 | EF_PARISC_WIDE: 357 return bfd_default_set_arch_mach (abfd, bfd_arch_hppa, 25); 358 } 359 /* Don't be fussy. */ 360 return TRUE; 361 } 362 363 /* Given section type (hdr->sh_type), return a boolean indicating 364 whether or not the section is an elf64-hppa specific section. */ 365 static bfd_boolean 366 elf64_hppa_section_from_shdr (bfd *abfd, 367 Elf_Internal_Shdr *hdr, 368 const char *name, 369 int shindex) 370 { 371 switch (hdr->sh_type) 372 { 373 case SHT_PARISC_EXT: 374 if (strcmp (name, ".PARISC.archext") != 0) 375 return FALSE; 376 break; 377 case SHT_PARISC_UNWIND: 378 if (strcmp (name, ".PARISC.unwind") != 0) 379 return FALSE; 380 break; 381 case SHT_PARISC_DOC: 382 case SHT_PARISC_ANNOT: 383 default: 384 return FALSE; 385 } 386 387 if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex)) 388 return FALSE; 389 390 return TRUE; 391 } 392 393 /* SEC is a section containing relocs for an input BFD when linking; return 394 a suitable section for holding relocs in the output BFD for a link. */ 395 396 static bfd_boolean 397 get_reloc_section (bfd *abfd, 398 struct elf64_hppa_link_hash_table *hppa_info, 399 asection *sec) 400 { 401 const char *srel_name; 402 asection *srel; 403 bfd *dynobj; 404 405 srel_name = (bfd_elf_string_from_elf_section 406 (abfd, elf_elfheader(abfd)->e_shstrndx, 407 _bfd_elf_single_rel_hdr(sec)->sh_name)); 408 if (srel_name == NULL) 409 return FALSE; 410 411 dynobj = hppa_info->root.dynobj; 412 if (!dynobj) 413 hppa_info->root.dynobj = dynobj = abfd; 414 415 srel = bfd_get_linker_section (dynobj, srel_name); 416 if (srel == NULL) 417 { 418 srel = bfd_make_section_anyway_with_flags (dynobj, srel_name, 419 (SEC_ALLOC 420 | SEC_LOAD 421 | SEC_HAS_CONTENTS 422 | SEC_IN_MEMORY 423 | SEC_LINKER_CREATED 424 | SEC_READONLY)); 425 if (srel == NULL 426 || !bfd_set_section_alignment (dynobj, srel, 3)) 427 return FALSE; 428 } 429 430 hppa_info->other_rel_sec = srel; 431 return TRUE; 432 } 433 434 /* Add a new entry to the list of dynamic relocations against DYN_H. 435 436 We use this to keep a record of all the FPTR relocations against a 437 particular symbol so that we can create FPTR relocations in the 438 output file. */ 439 440 static bfd_boolean 441 count_dyn_reloc (bfd *abfd, 442 struct elf64_hppa_link_hash_entry *hh, 443 int type, 444 asection *sec, 445 int sec_symndx, 446 bfd_vma offset, 447 bfd_vma addend) 448 { 449 struct elf64_hppa_dyn_reloc_entry *rent; 450 451 rent = (struct elf64_hppa_dyn_reloc_entry *) 452 bfd_alloc (abfd, (bfd_size_type) sizeof (*rent)); 453 if (!rent) 454 return FALSE; 455 456 rent->next = hh->reloc_entries; 457 rent->type = type; 458 rent->sec = sec; 459 rent->sec_symndx = sec_symndx; 460 rent->offset = offset; 461 rent->addend = addend; 462 hh->reloc_entries = rent; 463 464 return TRUE; 465 } 466 467 /* Return a pointer to the local DLT, PLT and OPD reference counts 468 for ABFD. Returns NULL if the storage allocation fails. */ 469 470 static bfd_signed_vma * 471 hppa64_elf_local_refcounts (bfd *abfd) 472 { 473 Elf_Internal_Shdr *symtab_hdr = &elf_tdata (abfd)->symtab_hdr; 474 bfd_signed_vma *local_refcounts; 475 476 local_refcounts = elf_local_got_refcounts (abfd); 477 if (local_refcounts == NULL) 478 { 479 bfd_size_type size; 480 481 /* Allocate space for local DLT, PLT and OPD reference 482 counts. Done this way to save polluting elf_obj_tdata 483 with another target specific pointer. */ 484 size = symtab_hdr->sh_info; 485 size *= 3 * sizeof (bfd_signed_vma); 486 local_refcounts = bfd_zalloc (abfd, size); 487 elf_local_got_refcounts (abfd) = local_refcounts; 488 } 489 return local_refcounts; 490 } 491 492 /* Scan the RELOCS and record the type of dynamic entries that each 493 referenced symbol needs. */ 494 495 static bfd_boolean 496 elf64_hppa_check_relocs (bfd *abfd, 497 struct bfd_link_info *info, 498 asection *sec, 499 const Elf_Internal_Rela *relocs) 500 { 501 struct elf64_hppa_link_hash_table *hppa_info; 502 const Elf_Internal_Rela *relend; 503 Elf_Internal_Shdr *symtab_hdr; 504 const Elf_Internal_Rela *rel; 505 unsigned int sec_symndx; 506 507 if (info->relocatable) 508 return TRUE; 509 510 /* If this is the first dynamic object found in the link, create 511 the special sections required for dynamic linking. */ 512 if (! elf_hash_table (info)->dynamic_sections_created) 513 { 514 if (! _bfd_elf_link_create_dynamic_sections (abfd, info)) 515 return FALSE; 516 } 517 518 hppa_info = hppa_link_hash_table (info); 519 if (hppa_info == NULL) 520 return FALSE; 521 symtab_hdr = &elf_tdata (abfd)->symtab_hdr; 522 523 /* If necessary, build a new table holding section symbols indices 524 for this BFD. */ 525 526 if (info->shared && hppa_info->section_syms_bfd != abfd) 527 { 528 unsigned long i; 529 unsigned int highest_shndx; 530 Elf_Internal_Sym *local_syms = NULL; 531 Elf_Internal_Sym *isym, *isymend; 532 bfd_size_type amt; 533 534 /* We're done with the old cache of section index to section symbol 535 index information. Free it. 536 537 ?!? Note we leak the last section_syms array. Presumably we 538 could free it in one of the later routines in this file. */ 539 if (hppa_info->section_syms) 540 free (hppa_info->section_syms); 541 542 /* Read this BFD's local symbols. */ 543 if (symtab_hdr->sh_info != 0) 544 { 545 local_syms = (Elf_Internal_Sym *) symtab_hdr->contents; 546 if (local_syms == NULL) 547 local_syms = bfd_elf_get_elf_syms (abfd, symtab_hdr, 548 symtab_hdr->sh_info, 0, 549 NULL, NULL, NULL); 550 if (local_syms == NULL) 551 return FALSE; 552 } 553 554 /* Record the highest section index referenced by the local symbols. */ 555 highest_shndx = 0; 556 isymend = local_syms + symtab_hdr->sh_info; 557 for (isym = local_syms; isym < isymend; isym++) 558 { 559 if (isym->st_shndx > highest_shndx 560 && isym->st_shndx < SHN_LORESERVE) 561 highest_shndx = isym->st_shndx; 562 } 563 564 /* Allocate an array to hold the section index to section symbol index 565 mapping. Bump by one since we start counting at zero. */ 566 highest_shndx++; 567 amt = highest_shndx; 568 amt *= sizeof (int); 569 hppa_info->section_syms = (int *) bfd_malloc (amt); 570 571 /* Now walk the local symbols again. If we find a section symbol, 572 record the index of the symbol into the section_syms array. */ 573 for (i = 0, isym = local_syms; isym < isymend; i++, isym++) 574 { 575 if (ELF_ST_TYPE (isym->st_info) == STT_SECTION) 576 hppa_info->section_syms[isym->st_shndx] = i; 577 } 578 579 /* We are finished with the local symbols. */ 580 if (local_syms != NULL 581 && symtab_hdr->contents != (unsigned char *) local_syms) 582 { 583 if (! info->keep_memory) 584 free (local_syms); 585 else 586 { 587 /* Cache the symbols for elf_link_input_bfd. */ 588 symtab_hdr->contents = (unsigned char *) local_syms; 589 } 590 } 591 592 /* Record which BFD we built the section_syms mapping for. */ 593 hppa_info->section_syms_bfd = abfd; 594 } 595 596 /* Record the symbol index for this input section. We may need it for 597 relocations when building shared libraries. When not building shared 598 libraries this value is never really used, but assign it to zero to 599 prevent out of bounds memory accesses in other routines. */ 600 if (info->shared) 601 { 602 sec_symndx = _bfd_elf_section_from_bfd_section (abfd, sec); 603 604 /* If we did not find a section symbol for this section, then 605 something went terribly wrong above. */ 606 if (sec_symndx == SHN_BAD) 607 return FALSE; 608 609 if (sec_symndx < SHN_LORESERVE) 610 sec_symndx = hppa_info->section_syms[sec_symndx]; 611 else 612 sec_symndx = 0; 613 } 614 else 615 sec_symndx = 0; 616 617 relend = relocs + sec->reloc_count; 618 for (rel = relocs; rel < relend; ++rel) 619 { 620 enum 621 { 622 NEED_DLT = 1, 623 NEED_PLT = 2, 624 NEED_STUB = 4, 625 NEED_OPD = 8, 626 NEED_DYNREL = 16, 627 }; 628 629 unsigned long r_symndx = ELF64_R_SYM (rel->r_info); 630 struct elf64_hppa_link_hash_entry *hh; 631 int need_entry; 632 bfd_boolean maybe_dynamic; 633 int dynrel_type = R_PARISC_NONE; 634 static reloc_howto_type *howto; 635 636 if (r_symndx >= symtab_hdr->sh_info) 637 { 638 /* We're dealing with a global symbol -- find its hash entry 639 and mark it as being referenced. */ 640 long indx = r_symndx - symtab_hdr->sh_info; 641 hh = hppa_elf_hash_entry (elf_sym_hashes (abfd)[indx]); 642 while (hh->eh.root.type == bfd_link_hash_indirect 643 || hh->eh.root.type == bfd_link_hash_warning) 644 hh = hppa_elf_hash_entry (hh->eh.root.u.i.link); 645 646 /* PR15323, ref flags aren't set for references in the same 647 object. */ 648 hh->eh.root.non_ir_ref = 1; 649 hh->eh.ref_regular = 1; 650 } 651 else 652 hh = NULL; 653 654 /* We can only get preliminary data on whether a symbol is 655 locally or externally defined, as not all of the input files 656 have yet been processed. Do something with what we know, as 657 this may help reduce memory usage and processing time later. */ 658 maybe_dynamic = FALSE; 659 if (hh && ((info->shared 660 && (!info->symbolic 661 || info->unresolved_syms_in_shared_libs == RM_IGNORE)) 662 || !hh->eh.def_regular 663 || hh->eh.root.type == bfd_link_hash_defweak)) 664 maybe_dynamic = TRUE; 665 666 howto = elf_hppa_howto_table + ELF64_R_TYPE (rel->r_info); 667 need_entry = 0; 668 switch (howto->type) 669 { 670 /* These are simple indirect references to symbols through the 671 DLT. We need to create a DLT entry for any symbols which 672 appears in a DLTIND relocation. */ 673 case R_PARISC_DLTIND21L: 674 case R_PARISC_DLTIND14R: 675 case R_PARISC_DLTIND14F: 676 case R_PARISC_DLTIND14WR: 677 case R_PARISC_DLTIND14DR: 678 need_entry = NEED_DLT; 679 break; 680 681 /* ?!? These need a DLT entry. But I have no idea what to do with 682 the "link time TP value. */ 683 case R_PARISC_LTOFF_TP21L: 684 case R_PARISC_LTOFF_TP14R: 685 case R_PARISC_LTOFF_TP14F: 686 case R_PARISC_LTOFF_TP64: 687 case R_PARISC_LTOFF_TP14WR: 688 case R_PARISC_LTOFF_TP14DR: 689 case R_PARISC_LTOFF_TP16F: 690 case R_PARISC_LTOFF_TP16WF: 691 case R_PARISC_LTOFF_TP16DF: 692 need_entry = NEED_DLT; 693 break; 694 695 /* These are function calls. Depending on their precise target we 696 may need to make a stub for them. The stub uses the PLT, so we 697 need to create PLT entries for these symbols too. */ 698 case R_PARISC_PCREL12F: 699 case R_PARISC_PCREL17F: 700 case R_PARISC_PCREL22F: 701 case R_PARISC_PCREL32: 702 case R_PARISC_PCREL64: 703 case R_PARISC_PCREL21L: 704 case R_PARISC_PCREL17R: 705 case R_PARISC_PCREL17C: 706 case R_PARISC_PCREL14R: 707 case R_PARISC_PCREL14F: 708 case R_PARISC_PCREL22C: 709 case R_PARISC_PCREL14WR: 710 case R_PARISC_PCREL14DR: 711 case R_PARISC_PCREL16F: 712 case R_PARISC_PCREL16WF: 713 case R_PARISC_PCREL16DF: 714 /* Function calls might need to go through the .plt, and 715 might need a long branch stub. */ 716 if (hh != NULL && hh->eh.type != STT_PARISC_MILLI) 717 need_entry = (NEED_PLT | NEED_STUB); 718 else 719 need_entry = 0; 720 break; 721 722 case R_PARISC_PLTOFF21L: 723 case R_PARISC_PLTOFF14R: 724 case R_PARISC_PLTOFF14F: 725 case R_PARISC_PLTOFF14WR: 726 case R_PARISC_PLTOFF14DR: 727 case R_PARISC_PLTOFF16F: 728 case R_PARISC_PLTOFF16WF: 729 case R_PARISC_PLTOFF16DF: 730 need_entry = (NEED_PLT); 731 break; 732 733 case R_PARISC_DIR64: 734 if (info->shared || maybe_dynamic) 735 need_entry = (NEED_DYNREL); 736 dynrel_type = R_PARISC_DIR64; 737 break; 738 739 /* This is an indirect reference through the DLT to get the address 740 of a OPD descriptor. Thus we need to make a DLT entry that points 741 to an OPD entry. */ 742 case R_PARISC_LTOFF_FPTR21L: 743 case R_PARISC_LTOFF_FPTR14R: 744 case R_PARISC_LTOFF_FPTR14WR: 745 case R_PARISC_LTOFF_FPTR14DR: 746 case R_PARISC_LTOFF_FPTR32: 747 case R_PARISC_LTOFF_FPTR64: 748 case R_PARISC_LTOFF_FPTR16F: 749 case R_PARISC_LTOFF_FPTR16WF: 750 case R_PARISC_LTOFF_FPTR16DF: 751 if (info->shared || maybe_dynamic) 752 need_entry = (NEED_DLT | NEED_OPD | NEED_PLT); 753 else 754 need_entry = (NEED_DLT | NEED_OPD | NEED_PLT); 755 dynrel_type = R_PARISC_FPTR64; 756 break; 757 758 /* This is a simple OPD entry. */ 759 case R_PARISC_FPTR64: 760 if (info->shared || maybe_dynamic) 761 need_entry = (NEED_OPD | NEED_PLT | NEED_DYNREL); 762 else 763 need_entry = (NEED_OPD | NEED_PLT); 764 dynrel_type = R_PARISC_FPTR64; 765 break; 766 767 /* Add more cases as needed. */ 768 } 769 770 if (!need_entry) 771 continue; 772 773 if (hh) 774 { 775 /* Stash away enough information to be able to find this symbol 776 regardless of whether or not it is local or global. */ 777 hh->owner = abfd; 778 hh->sym_indx = r_symndx; 779 } 780 781 /* Create what's needed. */ 782 if (need_entry & NEED_DLT) 783 { 784 /* Allocate space for a DLT entry, as well as a dynamic 785 relocation for this entry. */ 786 if (! hppa_info->dlt_sec 787 && ! get_dlt (abfd, info, hppa_info)) 788 goto err_out; 789 790 if (hh != NULL) 791 { 792 hh->want_dlt = 1; 793 hh->eh.got.refcount += 1; 794 } 795 else 796 { 797 bfd_signed_vma *local_dlt_refcounts; 798 799 /* This is a DLT entry for a local symbol. */ 800 local_dlt_refcounts = hppa64_elf_local_refcounts (abfd); 801 if (local_dlt_refcounts == NULL) 802 return FALSE; 803 local_dlt_refcounts[r_symndx] += 1; 804 } 805 } 806 807 if (need_entry & NEED_PLT) 808 { 809 if (! hppa_info->plt_sec 810 && ! get_plt (abfd, info, hppa_info)) 811 goto err_out; 812 813 if (hh != NULL) 814 { 815 hh->want_plt = 1; 816 hh->eh.needs_plt = 1; 817 hh->eh.plt.refcount += 1; 818 } 819 else 820 { 821 bfd_signed_vma *local_dlt_refcounts; 822 bfd_signed_vma *local_plt_refcounts; 823 824 /* This is a PLT entry for a local symbol. */ 825 local_dlt_refcounts = hppa64_elf_local_refcounts (abfd); 826 if (local_dlt_refcounts == NULL) 827 return FALSE; 828 local_plt_refcounts = local_dlt_refcounts + symtab_hdr->sh_info; 829 local_plt_refcounts[r_symndx] += 1; 830 } 831 } 832 833 if (need_entry & NEED_STUB) 834 { 835 if (! hppa_info->stub_sec 836 && ! get_stub (abfd, info, hppa_info)) 837 goto err_out; 838 if (hh) 839 hh->want_stub = 1; 840 } 841 842 if (need_entry & NEED_OPD) 843 { 844 if (! hppa_info->opd_sec 845 && ! get_opd (abfd, info, hppa_info)) 846 goto err_out; 847 848 /* FPTRs are not allocated by the dynamic linker for PA64, 849 though it is possible that will change in the future. */ 850 851 if (hh != NULL) 852 hh->want_opd = 1; 853 else 854 { 855 bfd_signed_vma *local_dlt_refcounts; 856 bfd_signed_vma *local_opd_refcounts; 857 858 /* This is a OPD for a local symbol. */ 859 local_dlt_refcounts = hppa64_elf_local_refcounts (abfd); 860 if (local_dlt_refcounts == NULL) 861 return FALSE; 862 local_opd_refcounts = (local_dlt_refcounts 863 + 2 * symtab_hdr->sh_info); 864 local_opd_refcounts[r_symndx] += 1; 865 } 866 } 867 868 /* Add a new dynamic relocation to the chain of dynamic 869 relocations for this symbol. */ 870 if ((need_entry & NEED_DYNREL) && (sec->flags & SEC_ALLOC)) 871 { 872 if (! hppa_info->other_rel_sec 873 && ! get_reloc_section (abfd, hppa_info, sec)) 874 goto err_out; 875 876 /* Count dynamic relocations against global symbols. */ 877 if (hh != NULL 878 && !count_dyn_reloc (abfd, hh, dynrel_type, sec, 879 sec_symndx, rel->r_offset, rel->r_addend)) 880 goto err_out; 881 882 /* If we are building a shared library and we just recorded 883 a dynamic R_PARISC_FPTR64 relocation, then make sure the 884 section symbol for this section ends up in the dynamic 885 symbol table. */ 886 if (info->shared && dynrel_type == R_PARISC_FPTR64 887 && ! (bfd_elf_link_record_local_dynamic_symbol 888 (info, abfd, sec_symndx))) 889 return FALSE; 890 } 891 } 892 893 return TRUE; 894 895 err_out: 896 return FALSE; 897 } 898 899 struct elf64_hppa_allocate_data 900 { 901 struct bfd_link_info *info; 902 bfd_size_type ofs; 903 }; 904 905 /* Should we do dynamic things to this symbol? */ 906 907 static bfd_boolean 908 elf64_hppa_dynamic_symbol_p (struct elf_link_hash_entry *eh, 909 struct bfd_link_info *info) 910 { 911 /* ??? What, if anything, needs to happen wrt STV_PROTECTED symbols 912 and relocations that retrieve a function descriptor? Assume the 913 worst for now. */ 914 if (_bfd_elf_dynamic_symbol_p (eh, info, 1)) 915 { 916 /* ??? Why is this here and not elsewhere is_local_label_name. */ 917 if (eh->root.root.string[0] == '$' && eh->root.root.string[1] == '$') 918 return FALSE; 919 920 return TRUE; 921 } 922 else 923 return FALSE; 924 } 925 926 /* Mark all functions exported by this file so that we can later allocate 927 entries in .opd for them. */ 928 929 static bfd_boolean 930 elf64_hppa_mark_exported_functions (struct elf_link_hash_entry *eh, void *data) 931 { 932 struct elf64_hppa_link_hash_entry *hh = hppa_elf_hash_entry (eh); 933 struct bfd_link_info *info = (struct bfd_link_info *)data; 934 struct elf64_hppa_link_hash_table *hppa_info; 935 936 hppa_info = hppa_link_hash_table (info); 937 if (hppa_info == NULL) 938 return FALSE; 939 940 if (eh 941 && (eh->root.type == bfd_link_hash_defined 942 || eh->root.type == bfd_link_hash_defweak) 943 && eh->root.u.def.section->output_section != NULL 944 && eh->type == STT_FUNC) 945 { 946 if (! hppa_info->opd_sec 947 && ! get_opd (hppa_info->root.dynobj, info, hppa_info)) 948 return FALSE; 949 950 hh->want_opd = 1; 951 952 /* Put a flag here for output_symbol_hook. */ 953 hh->st_shndx = -1; 954 eh->needs_plt = 1; 955 } 956 957 return TRUE; 958 } 959 960 /* Allocate space for a DLT entry. */ 961 962 static bfd_boolean 963 allocate_global_data_dlt (struct elf_link_hash_entry *eh, void *data) 964 { 965 struct elf64_hppa_link_hash_entry *hh = hppa_elf_hash_entry (eh); 966 struct elf64_hppa_allocate_data *x = (struct elf64_hppa_allocate_data *)data; 967 968 if (hh->want_dlt) 969 { 970 if (x->info->shared) 971 { 972 /* Possibly add the symbol to the local dynamic symbol 973 table since we might need to create a dynamic relocation 974 against it. */ 975 if (eh->dynindx == -1 && eh->type != STT_PARISC_MILLI) 976 { 977 bfd *owner = eh->root.u.def.section->owner; 978 979 if (! (bfd_elf_link_record_local_dynamic_symbol 980 (x->info, owner, hh->sym_indx))) 981 return FALSE; 982 } 983 } 984 985 hh->dlt_offset = x->ofs; 986 x->ofs += DLT_ENTRY_SIZE; 987 } 988 return TRUE; 989 } 990 991 /* Allocate space for a DLT.PLT entry. */ 992 993 static bfd_boolean 994 allocate_global_data_plt (struct elf_link_hash_entry *eh, void *data) 995 { 996 struct elf64_hppa_link_hash_entry *hh = hppa_elf_hash_entry (eh); 997 struct elf64_hppa_allocate_data *x = (struct elf64_hppa_allocate_data *) data; 998 999 if (hh->want_plt 1000 && elf64_hppa_dynamic_symbol_p (eh, x->info) 1001 && !((eh->root.type == bfd_link_hash_defined 1002 || eh->root.type == bfd_link_hash_defweak) 1003 && eh->root.u.def.section->output_section != NULL)) 1004 { 1005 hh->plt_offset = x->ofs; 1006 x->ofs += PLT_ENTRY_SIZE; 1007 if (hh->plt_offset < 0x2000) 1008 { 1009 struct elf64_hppa_link_hash_table *hppa_info; 1010 1011 hppa_info = hppa_link_hash_table (x->info); 1012 if (hppa_info == NULL) 1013 return FALSE; 1014 1015 hppa_info->gp_offset = hh->plt_offset; 1016 } 1017 } 1018 else 1019 hh->want_plt = 0; 1020 1021 return TRUE; 1022 } 1023 1024 /* Allocate space for a STUB entry. */ 1025 1026 static bfd_boolean 1027 allocate_global_data_stub (struct elf_link_hash_entry *eh, void *data) 1028 { 1029 struct elf64_hppa_link_hash_entry *hh = hppa_elf_hash_entry (eh); 1030 struct elf64_hppa_allocate_data *x = (struct elf64_hppa_allocate_data *)data; 1031 1032 if (hh->want_stub 1033 && elf64_hppa_dynamic_symbol_p (eh, x->info) 1034 && !((eh->root.type == bfd_link_hash_defined 1035 || eh->root.type == bfd_link_hash_defweak) 1036 && eh->root.u.def.section->output_section != NULL)) 1037 { 1038 hh->stub_offset = x->ofs; 1039 x->ofs += sizeof (plt_stub); 1040 } 1041 else 1042 hh->want_stub = 0; 1043 return TRUE; 1044 } 1045 1046 /* Allocate space for a FPTR entry. */ 1047 1048 static bfd_boolean 1049 allocate_global_data_opd (struct elf_link_hash_entry *eh, void *data) 1050 { 1051 struct elf64_hppa_link_hash_entry *hh = hppa_elf_hash_entry (eh); 1052 struct elf64_hppa_allocate_data *x = (struct elf64_hppa_allocate_data *)data; 1053 1054 if (hh && hh->want_opd) 1055 { 1056 /* We never need an opd entry for a symbol which is not 1057 defined by this output file. */ 1058 if (hh && (hh->eh.root.type == bfd_link_hash_undefined 1059 || hh->eh.root.type == bfd_link_hash_undefweak 1060 || hh->eh.root.u.def.section->output_section == NULL)) 1061 hh->want_opd = 0; 1062 1063 /* If we are creating a shared library, took the address of a local 1064 function or might export this function from this object file, then 1065 we have to create an opd descriptor. */ 1066 else if (x->info->shared 1067 || hh == NULL 1068 || (hh->eh.dynindx == -1 && hh->eh.type != STT_PARISC_MILLI) 1069 || (hh->eh.root.type == bfd_link_hash_defined 1070 || hh->eh.root.type == bfd_link_hash_defweak)) 1071 { 1072 /* If we are creating a shared library, then we will have to 1073 create a runtime relocation for the symbol to properly 1074 initialize the .opd entry. Make sure the symbol gets 1075 added to the dynamic symbol table. */ 1076 if (x->info->shared 1077 && (hh == NULL || (hh->eh.dynindx == -1))) 1078 { 1079 bfd *owner; 1080 /* PR 6511: Default to using the dynamic symbol table. */ 1081 owner = (hh->owner ? hh->owner: eh->root.u.def.section->owner); 1082 1083 if (!bfd_elf_link_record_local_dynamic_symbol 1084 (x->info, owner, hh->sym_indx)) 1085 return FALSE; 1086 } 1087 1088 /* This may not be necessary or desirable anymore now that 1089 we have some support for dealing with section symbols 1090 in dynamic relocs. But name munging does make the result 1091 much easier to debug. ie, the EPLT reloc will reference 1092 a symbol like .foobar, instead of .text + offset. */ 1093 if (x->info->shared && eh) 1094 { 1095 char *new_name; 1096 struct elf_link_hash_entry *nh; 1097 1098 new_name = alloca (strlen (eh->root.root.string) + 2); 1099 new_name[0] = '.'; 1100 strcpy (new_name + 1, eh->root.root.string); 1101 1102 nh = elf_link_hash_lookup (elf_hash_table (x->info), 1103 new_name, TRUE, TRUE, TRUE); 1104 1105 nh->root.type = eh->root.type; 1106 nh->root.u.def.value = eh->root.u.def.value; 1107 nh->root.u.def.section = eh->root.u.def.section; 1108 1109 if (! bfd_elf_link_record_dynamic_symbol (x->info, nh)) 1110 return FALSE; 1111 1112 } 1113 hh->opd_offset = x->ofs; 1114 x->ofs += OPD_ENTRY_SIZE; 1115 } 1116 1117 /* Otherwise we do not need an opd entry. */ 1118 else 1119 hh->want_opd = 0; 1120 } 1121 return TRUE; 1122 } 1123 1124 /* HP requires the EI_OSABI field to be filled in. The assignment to 1125 EI_ABIVERSION may not be strictly necessary. */ 1126 1127 static void 1128 elf64_hppa_post_process_headers (bfd *abfd, 1129 struct bfd_link_info *link_info ATTRIBUTE_UNUSED) 1130 { 1131 Elf_Internal_Ehdr * i_ehdrp; 1132 1133 i_ehdrp = elf_elfheader (abfd); 1134 1135 i_ehdrp->e_ident[EI_OSABI] = get_elf_backend_data (abfd)->elf_osabi; 1136 i_ehdrp->e_ident[EI_ABIVERSION] = 1; 1137 } 1138 1139 /* Create function descriptor section (.opd). This section is called .opd 1140 because it contains "official procedure descriptors". The "official" 1141 refers to the fact that these descriptors are used when taking the address 1142 of a procedure, thus ensuring a unique address for each procedure. */ 1143 1144 static bfd_boolean 1145 get_opd (bfd *abfd, 1146 struct bfd_link_info *info ATTRIBUTE_UNUSED, 1147 struct elf64_hppa_link_hash_table *hppa_info) 1148 { 1149 asection *opd; 1150 bfd *dynobj; 1151 1152 opd = hppa_info->opd_sec; 1153 if (!opd) 1154 { 1155 dynobj = hppa_info->root.dynobj; 1156 if (!dynobj) 1157 hppa_info->root.dynobj = dynobj = abfd; 1158 1159 opd = bfd_make_section_anyway_with_flags (dynobj, ".opd", 1160 (SEC_ALLOC 1161 | SEC_LOAD 1162 | SEC_HAS_CONTENTS 1163 | SEC_IN_MEMORY 1164 | SEC_LINKER_CREATED)); 1165 if (!opd 1166 || !bfd_set_section_alignment (abfd, opd, 3)) 1167 { 1168 BFD_ASSERT (0); 1169 return FALSE; 1170 } 1171 1172 hppa_info->opd_sec = opd; 1173 } 1174 1175 return TRUE; 1176 } 1177 1178 /* Create the PLT section. */ 1179 1180 static bfd_boolean 1181 get_plt (bfd *abfd, 1182 struct bfd_link_info *info ATTRIBUTE_UNUSED, 1183 struct elf64_hppa_link_hash_table *hppa_info) 1184 { 1185 asection *plt; 1186 bfd *dynobj; 1187 1188 plt = hppa_info->plt_sec; 1189 if (!plt) 1190 { 1191 dynobj = hppa_info->root.dynobj; 1192 if (!dynobj) 1193 hppa_info->root.dynobj = dynobj = abfd; 1194 1195 plt = bfd_make_section_anyway_with_flags (dynobj, ".plt", 1196 (SEC_ALLOC 1197 | SEC_LOAD 1198 | SEC_HAS_CONTENTS 1199 | SEC_IN_MEMORY 1200 | SEC_LINKER_CREATED)); 1201 if (!plt 1202 || !bfd_set_section_alignment (abfd, plt, 3)) 1203 { 1204 BFD_ASSERT (0); 1205 return FALSE; 1206 } 1207 1208 hppa_info->plt_sec = plt; 1209 } 1210 1211 return TRUE; 1212 } 1213 1214 /* Create the DLT section. */ 1215 1216 static bfd_boolean 1217 get_dlt (bfd *abfd, 1218 struct bfd_link_info *info ATTRIBUTE_UNUSED, 1219 struct elf64_hppa_link_hash_table *hppa_info) 1220 { 1221 asection *dlt; 1222 bfd *dynobj; 1223 1224 dlt = hppa_info->dlt_sec; 1225 if (!dlt) 1226 { 1227 dynobj = hppa_info->root.dynobj; 1228 if (!dynobj) 1229 hppa_info->root.dynobj = dynobj = abfd; 1230 1231 dlt = bfd_make_section_anyway_with_flags (dynobj, ".dlt", 1232 (SEC_ALLOC 1233 | SEC_LOAD 1234 | SEC_HAS_CONTENTS 1235 | SEC_IN_MEMORY 1236 | SEC_LINKER_CREATED)); 1237 if (!dlt 1238 || !bfd_set_section_alignment (abfd, dlt, 3)) 1239 { 1240 BFD_ASSERT (0); 1241 return FALSE; 1242 } 1243 1244 hppa_info->dlt_sec = dlt; 1245 } 1246 1247 return TRUE; 1248 } 1249 1250 /* Create the stubs section. */ 1251 1252 static bfd_boolean 1253 get_stub (bfd *abfd, 1254 struct bfd_link_info *info ATTRIBUTE_UNUSED, 1255 struct elf64_hppa_link_hash_table *hppa_info) 1256 { 1257 asection *stub; 1258 bfd *dynobj; 1259 1260 stub = hppa_info->stub_sec; 1261 if (!stub) 1262 { 1263 dynobj = hppa_info->root.dynobj; 1264 if (!dynobj) 1265 hppa_info->root.dynobj = dynobj = abfd; 1266 1267 stub = bfd_make_section_anyway_with_flags (dynobj, ".stub", 1268 (SEC_ALLOC | SEC_LOAD 1269 | SEC_HAS_CONTENTS 1270 | SEC_IN_MEMORY 1271 | SEC_READONLY 1272 | SEC_LINKER_CREATED)); 1273 if (!stub 1274 || !bfd_set_section_alignment (abfd, stub, 3)) 1275 { 1276 BFD_ASSERT (0); 1277 return FALSE; 1278 } 1279 1280 hppa_info->stub_sec = stub; 1281 } 1282 1283 return TRUE; 1284 } 1285 1286 /* Create sections necessary for dynamic linking. This is only a rough 1287 cut and will likely change as we learn more about the somewhat 1288 unusual dynamic linking scheme HP uses. 1289 1290 .stub: 1291 Contains code to implement cross-space calls. The first time one 1292 of the stubs is used it will call into the dynamic linker, later 1293 calls will go straight to the target. 1294 1295 The only stub we support right now looks like 1296 1297 ldd OFFSET(%dp),%r1 1298 bve %r0(%r1) 1299 ldd OFFSET+8(%dp),%dp 1300 1301 Other stubs may be needed in the future. We may want the remove 1302 the break/nop instruction. It is only used right now to keep the 1303 offset of a .plt entry and a .stub entry in sync. 1304 1305 .dlt: 1306 This is what most people call the .got. HP used a different name. 1307 Losers. 1308 1309 .rela.dlt: 1310 Relocations for the DLT. 1311 1312 .plt: 1313 Function pointers as address,gp pairs. 1314 1315 .rela.plt: 1316 Should contain dynamic IPLT (and EPLT?) relocations. 1317 1318 .opd: 1319 FPTRS 1320 1321 .rela.opd: 1322 EPLT relocations for symbols exported from shared libraries. */ 1323 1324 static bfd_boolean 1325 elf64_hppa_create_dynamic_sections (bfd *abfd, 1326 struct bfd_link_info *info) 1327 { 1328 asection *s; 1329 struct elf64_hppa_link_hash_table *hppa_info; 1330 1331 hppa_info = hppa_link_hash_table (info); 1332 if (hppa_info == NULL) 1333 return FALSE; 1334 1335 if (! get_stub (abfd, info, hppa_info)) 1336 return FALSE; 1337 1338 if (! get_dlt (abfd, info, hppa_info)) 1339 return FALSE; 1340 1341 if (! get_plt (abfd, info, hppa_info)) 1342 return FALSE; 1343 1344 if (! get_opd (abfd, info, hppa_info)) 1345 return FALSE; 1346 1347 s = bfd_make_section_anyway_with_flags (abfd, ".rela.dlt", 1348 (SEC_ALLOC | SEC_LOAD 1349 | SEC_HAS_CONTENTS 1350 | SEC_IN_MEMORY 1351 | SEC_READONLY 1352 | SEC_LINKER_CREATED)); 1353 if (s == NULL 1354 || !bfd_set_section_alignment (abfd, s, 3)) 1355 return FALSE; 1356 hppa_info->dlt_rel_sec = s; 1357 1358 s = bfd_make_section_anyway_with_flags (abfd, ".rela.plt", 1359 (SEC_ALLOC | SEC_LOAD 1360 | SEC_HAS_CONTENTS 1361 | SEC_IN_MEMORY 1362 | SEC_READONLY 1363 | SEC_LINKER_CREATED)); 1364 if (s == NULL 1365 || !bfd_set_section_alignment (abfd, s, 3)) 1366 return FALSE; 1367 hppa_info->plt_rel_sec = s; 1368 1369 s = bfd_make_section_anyway_with_flags (abfd, ".rela.data", 1370 (SEC_ALLOC | SEC_LOAD 1371 | SEC_HAS_CONTENTS 1372 | SEC_IN_MEMORY 1373 | SEC_READONLY 1374 | SEC_LINKER_CREATED)); 1375 if (s == NULL 1376 || !bfd_set_section_alignment (abfd, s, 3)) 1377 return FALSE; 1378 hppa_info->other_rel_sec = s; 1379 1380 s = bfd_make_section_anyway_with_flags (abfd, ".rela.opd", 1381 (SEC_ALLOC | SEC_LOAD 1382 | SEC_HAS_CONTENTS 1383 | SEC_IN_MEMORY 1384 | SEC_READONLY 1385 | SEC_LINKER_CREATED)); 1386 if (s == NULL 1387 || !bfd_set_section_alignment (abfd, s, 3)) 1388 return FALSE; 1389 hppa_info->opd_rel_sec = s; 1390 1391 return TRUE; 1392 } 1393 1394 /* Allocate dynamic relocations for those symbols that turned out 1395 to be dynamic. */ 1396 1397 static bfd_boolean 1398 allocate_dynrel_entries (struct elf_link_hash_entry *eh, void *data) 1399 { 1400 struct elf64_hppa_link_hash_entry *hh = hppa_elf_hash_entry (eh); 1401 struct elf64_hppa_allocate_data *x = (struct elf64_hppa_allocate_data *)data; 1402 struct elf64_hppa_link_hash_table *hppa_info; 1403 struct elf64_hppa_dyn_reloc_entry *rent; 1404 bfd_boolean dynamic_symbol, shared; 1405 1406 hppa_info = hppa_link_hash_table (x->info); 1407 if (hppa_info == NULL) 1408 return FALSE; 1409 1410 dynamic_symbol = elf64_hppa_dynamic_symbol_p (eh, x->info); 1411 shared = x->info->shared; 1412 1413 /* We may need to allocate relocations for a non-dynamic symbol 1414 when creating a shared library. */ 1415 if (!dynamic_symbol && !shared) 1416 return TRUE; 1417 1418 /* Take care of the normal data relocations. */ 1419 1420 for (rent = hh->reloc_entries; rent; rent = rent->next) 1421 { 1422 /* Allocate one iff we are building a shared library, the relocation 1423 isn't a R_PARISC_FPTR64, or we don't want an opd entry. */ 1424 if (!shared && rent->type == R_PARISC_FPTR64 && hh->want_opd) 1425 continue; 1426 1427 hppa_info->other_rel_sec->size += sizeof (Elf64_External_Rela); 1428 1429 /* Make sure this symbol gets into the dynamic symbol table if it is 1430 not already recorded. ?!? This should not be in the loop since 1431 the symbol need only be added once. */ 1432 if (eh->dynindx == -1 && eh->type != STT_PARISC_MILLI) 1433 if (!bfd_elf_link_record_local_dynamic_symbol 1434 (x->info, rent->sec->owner, hh->sym_indx)) 1435 return FALSE; 1436 } 1437 1438 /* Take care of the GOT and PLT relocations. */ 1439 1440 if ((dynamic_symbol || shared) && hh->want_dlt) 1441 hppa_info->dlt_rel_sec->size += sizeof (Elf64_External_Rela); 1442 1443 /* If we are building a shared library, then every symbol that has an 1444 opd entry will need an EPLT relocation to relocate the symbol's address 1445 and __gp value based on the runtime load address. */ 1446 if (shared && hh->want_opd) 1447 hppa_info->opd_rel_sec->size += sizeof (Elf64_External_Rela); 1448 1449 if (hh->want_plt && dynamic_symbol) 1450 { 1451 bfd_size_type t = 0; 1452 1453 /* Dynamic symbols get one IPLT relocation. Local symbols in 1454 shared libraries get two REL relocations. Local symbols in 1455 main applications get nothing. */ 1456 if (dynamic_symbol) 1457 t = sizeof (Elf64_External_Rela); 1458 else if (shared) 1459 t = 2 * sizeof (Elf64_External_Rela); 1460 1461 hppa_info->plt_rel_sec->size += t; 1462 } 1463 1464 return TRUE; 1465 } 1466 1467 /* Adjust a symbol defined by a dynamic object and referenced by a 1468 regular object. */ 1469 1470 static bfd_boolean 1471 elf64_hppa_adjust_dynamic_symbol (struct bfd_link_info *info ATTRIBUTE_UNUSED, 1472 struct elf_link_hash_entry *eh) 1473 { 1474 /* ??? Undefined symbols with PLT entries should be re-defined 1475 to be the PLT entry. */ 1476 1477 /* If this is a weak symbol, and there is a real definition, the 1478 processor independent code will have arranged for us to see the 1479 real definition first, and we can just use the same value. */ 1480 if (eh->u.weakdef != NULL) 1481 { 1482 BFD_ASSERT (eh->u.weakdef->root.type == bfd_link_hash_defined 1483 || eh->u.weakdef->root.type == bfd_link_hash_defweak); 1484 eh->root.u.def.section = eh->u.weakdef->root.u.def.section; 1485 eh->root.u.def.value = eh->u.weakdef->root.u.def.value; 1486 return TRUE; 1487 } 1488 1489 /* If this is a reference to a symbol defined by a dynamic object which 1490 is not a function, we might allocate the symbol in our .dynbss section 1491 and allocate a COPY dynamic relocation. 1492 1493 But PA64 code is canonically PIC, so as a rule we can avoid this sort 1494 of hackery. */ 1495 1496 return TRUE; 1497 } 1498 1499 /* This function is called via elf_link_hash_traverse to mark millicode 1500 symbols with a dynindx of -1 and to remove the string table reference 1501 from the dynamic symbol table. If the symbol is not a millicode symbol, 1502 elf64_hppa_mark_exported_functions is called. */ 1503 1504 static bfd_boolean 1505 elf64_hppa_mark_milli_and_exported_functions (struct elf_link_hash_entry *eh, 1506 void *data) 1507 { 1508 struct bfd_link_info *info = (struct bfd_link_info *) data; 1509 1510 if (eh->type == STT_PARISC_MILLI) 1511 { 1512 if (eh->dynindx != -1) 1513 { 1514 eh->dynindx = -1; 1515 _bfd_elf_strtab_delref (elf_hash_table (info)->dynstr, 1516 eh->dynstr_index); 1517 } 1518 return TRUE; 1519 } 1520 1521 return elf64_hppa_mark_exported_functions (eh, data); 1522 } 1523 1524 /* Set the final sizes of the dynamic sections and allocate memory for 1525 the contents of our special sections. */ 1526 1527 static bfd_boolean 1528 elf64_hppa_size_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info) 1529 { 1530 struct elf64_hppa_link_hash_table *hppa_info; 1531 struct elf64_hppa_allocate_data data; 1532 bfd *dynobj; 1533 bfd *ibfd; 1534 asection *sec; 1535 bfd_boolean plt; 1536 bfd_boolean relocs; 1537 bfd_boolean reltext; 1538 1539 hppa_info = hppa_link_hash_table (info); 1540 if (hppa_info == NULL) 1541 return FALSE; 1542 1543 dynobj = elf_hash_table (info)->dynobj; 1544 BFD_ASSERT (dynobj != NULL); 1545 1546 /* Mark each function this program exports so that we will allocate 1547 space in the .opd section for each function's FPTR. If we are 1548 creating dynamic sections, change the dynamic index of millicode 1549 symbols to -1 and remove them from the string table for .dynstr. 1550 1551 We have to traverse the main linker hash table since we have to 1552 find functions which may not have been mentioned in any relocs. */ 1553 elf_link_hash_traverse (elf_hash_table (info), 1554 (elf_hash_table (info)->dynamic_sections_created 1555 ? elf64_hppa_mark_milli_and_exported_functions 1556 : elf64_hppa_mark_exported_functions), 1557 info); 1558 1559 if (elf_hash_table (info)->dynamic_sections_created) 1560 { 1561 /* Set the contents of the .interp section to the interpreter. */ 1562 if (info->executable) 1563 { 1564 sec = bfd_get_linker_section (dynobj, ".interp"); 1565 BFD_ASSERT (sec != NULL); 1566 sec->size = sizeof ELF_DYNAMIC_INTERPRETER; 1567 sec->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER; 1568 } 1569 } 1570 else 1571 { 1572 /* We may have created entries in the .rela.got section. 1573 However, if we are not creating the dynamic sections, we will 1574 not actually use these entries. Reset the size of .rela.dlt, 1575 which will cause it to get stripped from the output file 1576 below. */ 1577 sec = bfd_get_linker_section (dynobj, ".rela.dlt"); 1578 if (sec != NULL) 1579 sec->size = 0; 1580 } 1581 1582 /* Set up DLT, PLT and OPD offsets for local syms, and space for local 1583 dynamic relocs. */ 1584 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next) 1585 { 1586 bfd_signed_vma *local_dlt; 1587 bfd_signed_vma *end_local_dlt; 1588 bfd_signed_vma *local_plt; 1589 bfd_signed_vma *end_local_plt; 1590 bfd_signed_vma *local_opd; 1591 bfd_signed_vma *end_local_opd; 1592 bfd_size_type locsymcount; 1593 Elf_Internal_Shdr *symtab_hdr; 1594 asection *srel; 1595 1596 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour) 1597 continue; 1598 1599 for (sec = ibfd->sections; sec != NULL; sec = sec->next) 1600 { 1601 struct elf64_hppa_dyn_reloc_entry *hdh_p; 1602 1603 for (hdh_p = ((struct elf64_hppa_dyn_reloc_entry *) 1604 elf_section_data (sec)->local_dynrel); 1605 hdh_p != NULL; 1606 hdh_p = hdh_p->next) 1607 { 1608 if (!bfd_is_abs_section (hdh_p->sec) 1609 && bfd_is_abs_section (hdh_p->sec->output_section)) 1610 { 1611 /* Input section has been discarded, either because 1612 it is a copy of a linkonce section or due to 1613 linker script /DISCARD/, so we'll be discarding 1614 the relocs too. */ 1615 } 1616 else if (hdh_p->count != 0) 1617 { 1618 srel = elf_section_data (hdh_p->sec)->sreloc; 1619 srel->size += hdh_p->count * sizeof (Elf64_External_Rela); 1620 if ((hdh_p->sec->output_section->flags & SEC_READONLY) != 0) 1621 info->flags |= DF_TEXTREL; 1622 } 1623 } 1624 } 1625 1626 local_dlt = elf_local_got_refcounts (ibfd); 1627 if (!local_dlt) 1628 continue; 1629 1630 symtab_hdr = &elf_tdata (ibfd)->symtab_hdr; 1631 locsymcount = symtab_hdr->sh_info; 1632 end_local_dlt = local_dlt + locsymcount; 1633 sec = hppa_info->dlt_sec; 1634 srel = hppa_info->dlt_rel_sec; 1635 for (; local_dlt < end_local_dlt; ++local_dlt) 1636 { 1637 if (*local_dlt > 0) 1638 { 1639 *local_dlt = sec->size; 1640 sec->size += DLT_ENTRY_SIZE; 1641 if (info->shared) 1642 { 1643 srel->size += sizeof (Elf64_External_Rela); 1644 } 1645 } 1646 else 1647 *local_dlt = (bfd_vma) -1; 1648 } 1649 1650 local_plt = end_local_dlt; 1651 end_local_plt = local_plt + locsymcount; 1652 if (! hppa_info->root.dynamic_sections_created) 1653 { 1654 /* Won't be used, but be safe. */ 1655 for (; local_plt < end_local_plt; ++local_plt) 1656 *local_plt = (bfd_vma) -1; 1657 } 1658 else 1659 { 1660 sec = hppa_info->plt_sec; 1661 srel = hppa_info->plt_rel_sec; 1662 for (; local_plt < end_local_plt; ++local_plt) 1663 { 1664 if (*local_plt > 0) 1665 { 1666 *local_plt = sec->size; 1667 sec->size += PLT_ENTRY_SIZE; 1668 if (info->shared) 1669 srel->size += sizeof (Elf64_External_Rela); 1670 } 1671 else 1672 *local_plt = (bfd_vma) -1; 1673 } 1674 } 1675 1676 local_opd = end_local_plt; 1677 end_local_opd = local_opd + locsymcount; 1678 if (! hppa_info->root.dynamic_sections_created) 1679 { 1680 /* Won't be used, but be safe. */ 1681 for (; local_opd < end_local_opd; ++local_opd) 1682 *local_opd = (bfd_vma) -1; 1683 } 1684 else 1685 { 1686 sec = hppa_info->opd_sec; 1687 srel = hppa_info->opd_rel_sec; 1688 for (; local_opd < end_local_opd; ++local_opd) 1689 { 1690 if (*local_opd > 0) 1691 { 1692 *local_opd = sec->size; 1693 sec->size += OPD_ENTRY_SIZE; 1694 if (info->shared) 1695 srel->size += sizeof (Elf64_External_Rela); 1696 } 1697 else 1698 *local_opd = (bfd_vma) -1; 1699 } 1700 } 1701 } 1702 1703 /* Allocate the GOT entries. */ 1704 1705 data.info = info; 1706 if (hppa_info->dlt_sec) 1707 { 1708 data.ofs = hppa_info->dlt_sec->size; 1709 elf_link_hash_traverse (elf_hash_table (info), 1710 allocate_global_data_dlt, &data); 1711 hppa_info->dlt_sec->size = data.ofs; 1712 } 1713 1714 if (hppa_info->plt_sec) 1715 { 1716 data.ofs = hppa_info->plt_sec->size; 1717 elf_link_hash_traverse (elf_hash_table (info), 1718 allocate_global_data_plt, &data); 1719 hppa_info->plt_sec->size = data.ofs; 1720 } 1721 1722 if (hppa_info->stub_sec) 1723 { 1724 data.ofs = 0x0; 1725 elf_link_hash_traverse (elf_hash_table (info), 1726 allocate_global_data_stub, &data); 1727 hppa_info->stub_sec->size = data.ofs; 1728 } 1729 1730 /* Allocate space for entries in the .opd section. */ 1731 if (hppa_info->opd_sec) 1732 { 1733 data.ofs = hppa_info->opd_sec->size; 1734 elf_link_hash_traverse (elf_hash_table (info), 1735 allocate_global_data_opd, &data); 1736 hppa_info->opd_sec->size = data.ofs; 1737 } 1738 1739 /* Now allocate space for dynamic relocations, if necessary. */ 1740 if (hppa_info->root.dynamic_sections_created) 1741 elf_link_hash_traverse (elf_hash_table (info), 1742 allocate_dynrel_entries, &data); 1743 1744 /* The sizes of all the sections are set. Allocate memory for them. */ 1745 plt = FALSE; 1746 relocs = FALSE; 1747 reltext = FALSE; 1748 for (sec = dynobj->sections; sec != NULL; sec = sec->next) 1749 { 1750 const char *name; 1751 1752 if ((sec->flags & SEC_LINKER_CREATED) == 0) 1753 continue; 1754 1755 /* It's OK to base decisions on the section name, because none 1756 of the dynobj section names depend upon the input files. */ 1757 name = bfd_get_section_name (dynobj, sec); 1758 1759 if (strcmp (name, ".plt") == 0) 1760 { 1761 /* Remember whether there is a PLT. */ 1762 plt = sec->size != 0; 1763 } 1764 else if (strcmp (name, ".opd") == 0 1765 || CONST_STRNEQ (name, ".dlt") 1766 || strcmp (name, ".stub") == 0 1767 || strcmp (name, ".got") == 0) 1768 { 1769 /* Strip this section if we don't need it; see the comment below. */ 1770 } 1771 else if (CONST_STRNEQ (name, ".rela")) 1772 { 1773 if (sec->size != 0) 1774 { 1775 asection *target; 1776 1777 /* Remember whether there are any reloc sections other 1778 than .rela.plt. */ 1779 if (strcmp (name, ".rela.plt") != 0) 1780 { 1781 const char *outname; 1782 1783 relocs = TRUE; 1784 1785 /* If this relocation section applies to a read only 1786 section, then we probably need a DT_TEXTREL 1787 entry. The entries in the .rela.plt section 1788 really apply to the .got section, which we 1789 created ourselves and so know is not readonly. */ 1790 outname = bfd_get_section_name (output_bfd, 1791 sec->output_section); 1792 target = bfd_get_section_by_name (output_bfd, outname + 4); 1793 if (target != NULL 1794 && (target->flags & SEC_READONLY) != 0 1795 && (target->flags & SEC_ALLOC) != 0) 1796 reltext = TRUE; 1797 } 1798 1799 /* We use the reloc_count field as a counter if we need 1800 to copy relocs into the output file. */ 1801 sec->reloc_count = 0; 1802 } 1803 } 1804 else 1805 { 1806 /* It's not one of our sections, so don't allocate space. */ 1807 continue; 1808 } 1809 1810 if (sec->size == 0) 1811 { 1812 /* If we don't need this section, strip it from the 1813 output file. This is mostly to handle .rela.bss and 1814 .rela.plt. We must create both sections in 1815 create_dynamic_sections, because they must be created 1816 before the linker maps input sections to output 1817 sections. The linker does that before 1818 adjust_dynamic_symbol is called, and it is that 1819 function which decides whether anything needs to go 1820 into these sections. */ 1821 sec->flags |= SEC_EXCLUDE; 1822 continue; 1823 } 1824 1825 if ((sec->flags & SEC_HAS_CONTENTS) == 0) 1826 continue; 1827 1828 /* Allocate memory for the section contents if it has not 1829 been allocated already. We use bfd_zalloc here in case 1830 unused entries are not reclaimed before the section's 1831 contents are written out. This should not happen, but this 1832 way if it does, we get a R_PARISC_NONE reloc instead of 1833 garbage. */ 1834 if (sec->contents == NULL) 1835 { 1836 sec->contents = (bfd_byte *) bfd_zalloc (dynobj, sec->size); 1837 if (sec->contents == NULL) 1838 return FALSE; 1839 } 1840 } 1841 1842 if (elf_hash_table (info)->dynamic_sections_created) 1843 { 1844 /* Always create a DT_PLTGOT. It actually has nothing to do with 1845 the PLT, it is how we communicate the __gp value of a load 1846 module to the dynamic linker. */ 1847 #define add_dynamic_entry(TAG, VAL) \ 1848 _bfd_elf_add_dynamic_entry (info, TAG, VAL) 1849 1850 if (!add_dynamic_entry (DT_HP_DLD_FLAGS, 0) 1851 || !add_dynamic_entry (DT_PLTGOT, 0)) 1852 return FALSE; 1853 1854 /* Add some entries to the .dynamic section. We fill in the 1855 values later, in elf64_hppa_finish_dynamic_sections, but we 1856 must add the entries now so that we get the correct size for 1857 the .dynamic section. The DT_DEBUG entry is filled in by the 1858 dynamic linker and used by the debugger. */ 1859 if (! info->shared) 1860 { 1861 if (!add_dynamic_entry (DT_DEBUG, 0) 1862 || !add_dynamic_entry (DT_HP_DLD_HOOK, 0) 1863 || !add_dynamic_entry (DT_HP_LOAD_MAP, 0)) 1864 return FALSE; 1865 } 1866 1867 /* Force DT_FLAGS to always be set. 1868 Required by HPUX 11.00 patch PHSS_26559. */ 1869 if (!add_dynamic_entry (DT_FLAGS, (info)->flags)) 1870 return FALSE; 1871 1872 if (plt) 1873 { 1874 if (!add_dynamic_entry (DT_PLTRELSZ, 0) 1875 || !add_dynamic_entry (DT_PLTREL, DT_RELA) 1876 || !add_dynamic_entry (DT_JMPREL, 0)) 1877 return FALSE; 1878 } 1879 1880 if (relocs) 1881 { 1882 if (!add_dynamic_entry (DT_RELA, 0) 1883 || !add_dynamic_entry (DT_RELASZ, 0) 1884 || !add_dynamic_entry (DT_RELAENT, sizeof (Elf64_External_Rela))) 1885 return FALSE; 1886 } 1887 1888 if (reltext) 1889 { 1890 if (!add_dynamic_entry (DT_TEXTREL, 0)) 1891 return FALSE; 1892 info->flags |= DF_TEXTREL; 1893 } 1894 } 1895 #undef add_dynamic_entry 1896 1897 return TRUE; 1898 } 1899 1900 /* Called after we have output the symbol into the dynamic symbol 1901 table, but before we output the symbol into the normal symbol 1902 table. 1903 1904 For some symbols we had to change their address when outputting 1905 the dynamic symbol table. We undo that change here so that 1906 the symbols have their expected value in the normal symbol 1907 table. Ick. */ 1908 1909 static int 1910 elf64_hppa_link_output_symbol_hook (struct bfd_link_info *info ATTRIBUTE_UNUSED, 1911 const char *name, 1912 Elf_Internal_Sym *sym, 1913 asection *input_sec ATTRIBUTE_UNUSED, 1914 struct elf_link_hash_entry *eh) 1915 { 1916 struct elf64_hppa_link_hash_entry *hh = hppa_elf_hash_entry (eh); 1917 1918 /* We may be called with the file symbol or section symbols. 1919 They never need munging, so it is safe to ignore them. */ 1920 if (!name || !eh) 1921 return 1; 1922 1923 /* Function symbols for which we created .opd entries *may* have been 1924 munged by finish_dynamic_symbol and have to be un-munged here. 1925 1926 Note that finish_dynamic_symbol sometimes turns dynamic symbols 1927 into non-dynamic ones, so we initialize st_shndx to -1 in 1928 mark_exported_functions and check to see if it was overwritten 1929 here instead of just checking eh->dynindx. */ 1930 if (hh->want_opd && hh->st_shndx != -1) 1931 { 1932 /* Restore the saved value and section index. */ 1933 sym->st_value = hh->st_value; 1934 sym->st_shndx = hh->st_shndx; 1935 } 1936 1937 return 1; 1938 } 1939 1940 /* Finish up dynamic symbol handling. We set the contents of various 1941 dynamic sections here. */ 1942 1943 static bfd_boolean 1944 elf64_hppa_finish_dynamic_symbol (bfd *output_bfd, 1945 struct bfd_link_info *info, 1946 struct elf_link_hash_entry *eh, 1947 Elf_Internal_Sym *sym) 1948 { 1949 struct elf64_hppa_link_hash_entry *hh = hppa_elf_hash_entry (eh); 1950 asection *stub, *splt, *sopd, *spltrel; 1951 struct elf64_hppa_link_hash_table *hppa_info; 1952 1953 hppa_info = hppa_link_hash_table (info); 1954 if (hppa_info == NULL) 1955 return FALSE; 1956 1957 stub = hppa_info->stub_sec; 1958 splt = hppa_info->plt_sec; 1959 sopd = hppa_info->opd_sec; 1960 spltrel = hppa_info->plt_rel_sec; 1961 1962 /* Incredible. It is actually necessary to NOT use the symbol's real 1963 value when building the dynamic symbol table for a shared library. 1964 At least for symbols that refer to functions. 1965 1966 We will store a new value and section index into the symbol long 1967 enough to output it into the dynamic symbol table, then we restore 1968 the original values (in elf64_hppa_link_output_symbol_hook). */ 1969 if (hh->want_opd) 1970 { 1971 BFD_ASSERT (sopd != NULL); 1972 1973 /* Save away the original value and section index so that we 1974 can restore them later. */ 1975 hh->st_value = sym->st_value; 1976 hh->st_shndx = sym->st_shndx; 1977 1978 /* For the dynamic symbol table entry, we want the value to be 1979 address of this symbol's entry within the .opd section. */ 1980 sym->st_value = (hh->opd_offset 1981 + sopd->output_offset 1982 + sopd->output_section->vma); 1983 sym->st_shndx = _bfd_elf_section_from_bfd_section (output_bfd, 1984 sopd->output_section); 1985 } 1986 1987 /* Initialize a .plt entry if requested. */ 1988 if (hh->want_plt 1989 && elf64_hppa_dynamic_symbol_p (eh, info)) 1990 { 1991 bfd_vma value; 1992 Elf_Internal_Rela rel; 1993 bfd_byte *loc; 1994 1995 BFD_ASSERT (splt != NULL && spltrel != NULL); 1996 1997 /* We do not actually care about the value in the PLT entry 1998 if we are creating a shared library and the symbol is 1999 still undefined, we create a dynamic relocation to fill 2000 in the correct value. */ 2001 if (info->shared && eh->root.type == bfd_link_hash_undefined) 2002 value = 0; 2003 else 2004 value = (eh->root.u.def.value + eh->root.u.def.section->vma); 2005 2006 /* Fill in the entry in the procedure linkage table. 2007 2008 The format of a plt entry is 2009 <funcaddr> <__gp>. 2010 2011 plt_offset is the offset within the PLT section at which to 2012 install the PLT entry. 2013 2014 We are modifying the in-memory PLT contents here, so we do not add 2015 in the output_offset of the PLT section. */ 2016 2017 bfd_put_64 (splt->owner, value, splt->contents + hh->plt_offset); 2018 value = _bfd_get_gp_value (splt->output_section->owner); 2019 bfd_put_64 (splt->owner, value, splt->contents + hh->plt_offset + 0x8); 2020 2021 /* Create a dynamic IPLT relocation for this entry. 2022 2023 We are creating a relocation in the output file's PLT section, 2024 which is included within the DLT secton. So we do need to include 2025 the PLT's output_offset in the computation of the relocation's 2026 address. */ 2027 rel.r_offset = (hh->plt_offset + splt->output_offset 2028 + splt->output_section->vma); 2029 rel.r_info = ELF64_R_INFO (hh->eh.dynindx, R_PARISC_IPLT); 2030 rel.r_addend = 0; 2031 2032 loc = spltrel->contents; 2033 loc += spltrel->reloc_count++ * sizeof (Elf64_External_Rela); 2034 bfd_elf64_swap_reloca_out (splt->output_section->owner, &rel, loc); 2035 } 2036 2037 /* Initialize an external call stub entry if requested. */ 2038 if (hh->want_stub 2039 && elf64_hppa_dynamic_symbol_p (eh, info)) 2040 { 2041 bfd_vma value; 2042 int insn; 2043 unsigned int max_offset; 2044 2045 BFD_ASSERT (stub != NULL); 2046 2047 /* Install the generic stub template. 2048 2049 We are modifying the contents of the stub section, so we do not 2050 need to include the stub section's output_offset here. */ 2051 memcpy (stub->contents + hh->stub_offset, plt_stub, sizeof (plt_stub)); 2052 2053 /* Fix up the first ldd instruction. 2054 2055 We are modifying the contents of the STUB section in memory, 2056 so we do not need to include its output offset in this computation. 2057 2058 Note the plt_offset value is the value of the PLT entry relative to 2059 the start of the PLT section. These instructions will reference 2060 data relative to the value of __gp, which may not necessarily have 2061 the same address as the start of the PLT section. 2062 2063 gp_offset contains the offset of __gp within the PLT section. */ 2064 value = hh->plt_offset - hppa_info->gp_offset; 2065 2066 insn = bfd_get_32 (stub->owner, stub->contents + hh->stub_offset); 2067 if (output_bfd->arch_info->mach >= 25) 2068 { 2069 /* Wide mode allows 16 bit offsets. */ 2070 max_offset = 32768; 2071 insn &= ~ 0xfff1; 2072 insn |= re_assemble_16 ((int) value); 2073 } 2074 else 2075 { 2076 max_offset = 8192; 2077 insn &= ~ 0x3ff1; 2078 insn |= re_assemble_14 ((int) value); 2079 } 2080 2081 if ((value & 7) || value + max_offset >= 2*max_offset - 8) 2082 { 2083 (*_bfd_error_handler) (_("stub entry for %s cannot load .plt, dp offset = %ld"), 2084 hh->eh.root.root.string, 2085 (long) value); 2086 return FALSE; 2087 } 2088 2089 bfd_put_32 (stub->owner, (bfd_vma) insn, 2090 stub->contents + hh->stub_offset); 2091 2092 /* Fix up the second ldd instruction. */ 2093 value += 8; 2094 insn = bfd_get_32 (stub->owner, stub->contents + hh->stub_offset + 8); 2095 if (output_bfd->arch_info->mach >= 25) 2096 { 2097 insn &= ~ 0xfff1; 2098 insn |= re_assemble_16 ((int) value); 2099 } 2100 else 2101 { 2102 insn &= ~ 0x3ff1; 2103 insn |= re_assemble_14 ((int) value); 2104 } 2105 bfd_put_32 (stub->owner, (bfd_vma) insn, 2106 stub->contents + hh->stub_offset + 8); 2107 } 2108 2109 return TRUE; 2110 } 2111 2112 /* The .opd section contains FPTRs for each function this file 2113 exports. Initialize the FPTR entries. */ 2114 2115 static bfd_boolean 2116 elf64_hppa_finalize_opd (struct elf_link_hash_entry *eh, void *data) 2117 { 2118 struct elf64_hppa_link_hash_entry *hh = hppa_elf_hash_entry (eh); 2119 struct bfd_link_info *info = (struct bfd_link_info *)data; 2120 struct elf64_hppa_link_hash_table *hppa_info; 2121 asection *sopd; 2122 asection *sopdrel; 2123 2124 hppa_info = hppa_link_hash_table (info); 2125 if (hppa_info == NULL) 2126 return FALSE; 2127 2128 sopd = hppa_info->opd_sec; 2129 sopdrel = hppa_info->opd_rel_sec; 2130 2131 if (hh->want_opd) 2132 { 2133 bfd_vma value; 2134 2135 /* The first two words of an .opd entry are zero. 2136 2137 We are modifying the contents of the OPD section in memory, so we 2138 do not need to include its output offset in this computation. */ 2139 memset (sopd->contents + hh->opd_offset, 0, 16); 2140 2141 value = (eh->root.u.def.value 2142 + eh->root.u.def.section->output_section->vma 2143 + eh->root.u.def.section->output_offset); 2144 2145 /* The next word is the address of the function. */ 2146 bfd_put_64 (sopd->owner, value, sopd->contents + hh->opd_offset + 16); 2147 2148 /* The last word is our local __gp value. */ 2149 value = _bfd_get_gp_value (sopd->output_section->owner); 2150 bfd_put_64 (sopd->owner, value, sopd->contents + hh->opd_offset + 24); 2151 } 2152 2153 /* If we are generating a shared library, we must generate EPLT relocations 2154 for each entry in the .opd, even for static functions (they may have 2155 had their address taken). */ 2156 if (info->shared && hh->want_opd) 2157 { 2158 Elf_Internal_Rela rel; 2159 bfd_byte *loc; 2160 int dynindx; 2161 2162 /* We may need to do a relocation against a local symbol, in 2163 which case we have to look up it's dynamic symbol index off 2164 the local symbol hash table. */ 2165 if (eh->dynindx != -1) 2166 dynindx = eh->dynindx; 2167 else 2168 dynindx 2169 = _bfd_elf_link_lookup_local_dynindx (info, hh->owner, 2170 hh->sym_indx); 2171 2172 /* The offset of this relocation is the absolute address of the 2173 .opd entry for this symbol. */ 2174 rel.r_offset = (hh->opd_offset + sopd->output_offset 2175 + sopd->output_section->vma); 2176 2177 /* If H is non-null, then we have an external symbol. 2178 2179 It is imperative that we use a different dynamic symbol for the 2180 EPLT relocation if the symbol has global scope. 2181 2182 In the dynamic symbol table, the function symbol will have a value 2183 which is address of the function's .opd entry. 2184 2185 Thus, we can not use that dynamic symbol for the EPLT relocation 2186 (if we did, the data in the .opd would reference itself rather 2187 than the actual address of the function). Instead we have to use 2188 a new dynamic symbol which has the same value as the original global 2189 function symbol. 2190 2191 We prefix the original symbol with a "." and use the new symbol in 2192 the EPLT relocation. This new symbol has already been recorded in 2193 the symbol table, we just have to look it up and use it. 2194 2195 We do not have such problems with static functions because we do 2196 not make their addresses in the dynamic symbol table point to 2197 the .opd entry. Ultimately this should be safe since a static 2198 function can not be directly referenced outside of its shared 2199 library. 2200 2201 We do have to play similar games for FPTR relocations in shared 2202 libraries, including those for static symbols. See the FPTR 2203 handling in elf64_hppa_finalize_dynreloc. */ 2204 if (eh) 2205 { 2206 char *new_name; 2207 struct elf_link_hash_entry *nh; 2208 2209 new_name = alloca (strlen (eh->root.root.string) + 2); 2210 new_name[0] = '.'; 2211 strcpy (new_name + 1, eh->root.root.string); 2212 2213 nh = elf_link_hash_lookup (elf_hash_table (info), 2214 new_name, TRUE, TRUE, FALSE); 2215 2216 /* All we really want from the new symbol is its dynamic 2217 symbol index. */ 2218 if (nh) 2219 dynindx = nh->dynindx; 2220 } 2221 2222 rel.r_addend = 0; 2223 rel.r_info = ELF64_R_INFO (dynindx, R_PARISC_EPLT); 2224 2225 loc = sopdrel->contents; 2226 loc += sopdrel->reloc_count++ * sizeof (Elf64_External_Rela); 2227 bfd_elf64_swap_reloca_out (sopd->output_section->owner, &rel, loc); 2228 } 2229 return TRUE; 2230 } 2231 2232 /* The .dlt section contains addresses for items referenced through the 2233 dlt. Note that we can have a DLTIND relocation for a local symbol, thus 2234 we can not depend on finish_dynamic_symbol to initialize the .dlt. */ 2235 2236 static bfd_boolean 2237 elf64_hppa_finalize_dlt (struct elf_link_hash_entry *eh, void *data) 2238 { 2239 struct elf64_hppa_link_hash_entry *hh = hppa_elf_hash_entry (eh); 2240 struct bfd_link_info *info = (struct bfd_link_info *)data; 2241 struct elf64_hppa_link_hash_table *hppa_info; 2242 asection *sdlt, *sdltrel; 2243 2244 hppa_info = hppa_link_hash_table (info); 2245 if (hppa_info == NULL) 2246 return FALSE; 2247 2248 sdlt = hppa_info->dlt_sec; 2249 sdltrel = hppa_info->dlt_rel_sec; 2250 2251 /* H/DYN_H may refer to a local variable and we know it's 2252 address, so there is no need to create a relocation. Just install 2253 the proper value into the DLT, note this shortcut can not be 2254 skipped when building a shared library. */ 2255 if (! info->shared && hh && hh->want_dlt) 2256 { 2257 bfd_vma value; 2258 2259 /* If we had an LTOFF_FPTR style relocation we want the DLT entry 2260 to point to the FPTR entry in the .opd section. 2261 2262 We include the OPD's output offset in this computation as 2263 we are referring to an absolute address in the resulting 2264 object file. */ 2265 if (hh->want_opd) 2266 { 2267 value = (hh->opd_offset 2268 + hppa_info->opd_sec->output_offset 2269 + hppa_info->opd_sec->output_section->vma); 2270 } 2271 else if ((eh->root.type == bfd_link_hash_defined 2272 || eh->root.type == bfd_link_hash_defweak) 2273 && eh->root.u.def.section) 2274 { 2275 value = eh->root.u.def.value + eh->root.u.def.section->output_offset; 2276 if (eh->root.u.def.section->output_section) 2277 value += eh->root.u.def.section->output_section->vma; 2278 else 2279 value += eh->root.u.def.section->vma; 2280 } 2281 else 2282 /* We have an undefined function reference. */ 2283 value = 0; 2284 2285 /* We do not need to include the output offset of the DLT section 2286 here because we are modifying the in-memory contents. */ 2287 bfd_put_64 (sdlt->owner, value, sdlt->contents + hh->dlt_offset); 2288 } 2289 2290 /* Create a relocation for the DLT entry associated with this symbol. 2291 When building a shared library the symbol does not have to be dynamic. */ 2292 if (hh->want_dlt 2293 && (elf64_hppa_dynamic_symbol_p (eh, info) || info->shared)) 2294 { 2295 Elf_Internal_Rela rel; 2296 bfd_byte *loc; 2297 int dynindx; 2298 2299 /* We may need to do a relocation against a local symbol, in 2300 which case we have to look up it's dynamic symbol index off 2301 the local symbol hash table. */ 2302 if (eh && eh->dynindx != -1) 2303 dynindx = eh->dynindx; 2304 else 2305 dynindx 2306 = _bfd_elf_link_lookup_local_dynindx (info, hh->owner, 2307 hh->sym_indx); 2308 2309 /* Create a dynamic relocation for this entry. Do include the output 2310 offset of the DLT entry since we need an absolute address in the 2311 resulting object file. */ 2312 rel.r_offset = (hh->dlt_offset + sdlt->output_offset 2313 + sdlt->output_section->vma); 2314 if (eh && eh->type == STT_FUNC) 2315 rel.r_info = ELF64_R_INFO (dynindx, R_PARISC_FPTR64); 2316 else 2317 rel.r_info = ELF64_R_INFO (dynindx, R_PARISC_DIR64); 2318 rel.r_addend = 0; 2319 2320 loc = sdltrel->contents; 2321 loc += sdltrel->reloc_count++ * sizeof (Elf64_External_Rela); 2322 bfd_elf64_swap_reloca_out (sdlt->output_section->owner, &rel, loc); 2323 } 2324 return TRUE; 2325 } 2326 2327 /* Finalize the dynamic relocations. Specifically the FPTR relocations 2328 for dynamic functions used to initialize static data. */ 2329 2330 static bfd_boolean 2331 elf64_hppa_finalize_dynreloc (struct elf_link_hash_entry *eh, 2332 void *data) 2333 { 2334 struct elf64_hppa_link_hash_entry *hh = hppa_elf_hash_entry (eh); 2335 struct bfd_link_info *info = (struct bfd_link_info *)data; 2336 struct elf64_hppa_link_hash_table *hppa_info; 2337 int dynamic_symbol; 2338 2339 dynamic_symbol = elf64_hppa_dynamic_symbol_p (eh, info); 2340 2341 if (!dynamic_symbol && !info->shared) 2342 return TRUE; 2343 2344 if (hh->reloc_entries) 2345 { 2346 struct elf64_hppa_dyn_reloc_entry *rent; 2347 int dynindx; 2348 2349 hppa_info = hppa_link_hash_table (info); 2350 if (hppa_info == NULL) 2351 return FALSE; 2352 2353 /* We may need to do a relocation against a local symbol, in 2354 which case we have to look up it's dynamic symbol index off 2355 the local symbol hash table. */ 2356 if (eh->dynindx != -1) 2357 dynindx = eh->dynindx; 2358 else 2359 dynindx 2360 = _bfd_elf_link_lookup_local_dynindx (info, hh->owner, 2361 hh->sym_indx); 2362 2363 for (rent = hh->reloc_entries; rent; rent = rent->next) 2364 { 2365 Elf_Internal_Rela rel; 2366 bfd_byte *loc; 2367 2368 /* Allocate one iff we are building a shared library, the relocation 2369 isn't a R_PARISC_FPTR64, or we don't want an opd entry. */ 2370 if (!info->shared && rent->type == R_PARISC_FPTR64 && hh->want_opd) 2371 continue; 2372 2373 /* Create a dynamic relocation for this entry. 2374 2375 We need the output offset for the reloc's section because 2376 we are creating an absolute address in the resulting object 2377 file. */ 2378 rel.r_offset = (rent->offset + rent->sec->output_offset 2379 + rent->sec->output_section->vma); 2380 2381 /* An FPTR64 relocation implies that we took the address of 2382 a function and that the function has an entry in the .opd 2383 section. We want the FPTR64 relocation to reference the 2384 entry in .opd. 2385 2386 We could munge the symbol value in the dynamic symbol table 2387 (in fact we already do for functions with global scope) to point 2388 to the .opd entry. Then we could use that dynamic symbol in 2389 this relocation. 2390 2391 Or we could do something sensible, not munge the symbol's 2392 address and instead just use a different symbol to reference 2393 the .opd entry. At least that seems sensible until you 2394 realize there's no local dynamic symbols we can use for that 2395 purpose. Thus the hair in the check_relocs routine. 2396 2397 We use a section symbol recorded by check_relocs as the 2398 base symbol for the relocation. The addend is the difference 2399 between the section symbol and the address of the .opd entry. */ 2400 if (info->shared && rent->type == R_PARISC_FPTR64 && hh->want_opd) 2401 { 2402 bfd_vma value, value2; 2403 2404 /* First compute the address of the opd entry for this symbol. */ 2405 value = (hh->opd_offset 2406 + hppa_info->opd_sec->output_section->vma 2407 + hppa_info->opd_sec->output_offset); 2408 2409 /* Compute the value of the start of the section with 2410 the relocation. */ 2411 value2 = (rent->sec->output_section->vma 2412 + rent->sec->output_offset); 2413 2414 /* Compute the difference between the start of the section 2415 with the relocation and the opd entry. */ 2416 value -= value2; 2417 2418 /* The result becomes the addend of the relocation. */ 2419 rel.r_addend = value; 2420 2421 /* The section symbol becomes the symbol for the dynamic 2422 relocation. */ 2423 dynindx 2424 = _bfd_elf_link_lookup_local_dynindx (info, 2425 rent->sec->owner, 2426 rent->sec_symndx); 2427 } 2428 else 2429 rel.r_addend = rent->addend; 2430 2431 rel.r_info = ELF64_R_INFO (dynindx, rent->type); 2432 2433 loc = hppa_info->other_rel_sec->contents; 2434 loc += (hppa_info->other_rel_sec->reloc_count++ 2435 * sizeof (Elf64_External_Rela)); 2436 bfd_elf64_swap_reloca_out (hppa_info->other_rel_sec->output_section->owner, 2437 &rel, loc); 2438 } 2439 } 2440 2441 return TRUE; 2442 } 2443 2444 /* Used to decide how to sort relocs in an optimal manner for the 2445 dynamic linker, before writing them out. */ 2446 2447 static enum elf_reloc_type_class 2448 elf64_hppa_reloc_type_class (const struct bfd_link_info *info ATTRIBUTE_UNUSED, 2449 const asection *rel_sec ATTRIBUTE_UNUSED, 2450 const Elf_Internal_Rela *rela) 2451 { 2452 if (ELF64_R_SYM (rela->r_info) == STN_UNDEF) 2453 return reloc_class_relative; 2454 2455 switch ((int) ELF64_R_TYPE (rela->r_info)) 2456 { 2457 case R_PARISC_IPLT: 2458 return reloc_class_plt; 2459 case R_PARISC_COPY: 2460 return reloc_class_copy; 2461 default: 2462 return reloc_class_normal; 2463 } 2464 } 2465 2466 /* Finish up the dynamic sections. */ 2467 2468 static bfd_boolean 2469 elf64_hppa_finish_dynamic_sections (bfd *output_bfd, 2470 struct bfd_link_info *info) 2471 { 2472 bfd *dynobj; 2473 asection *sdyn; 2474 struct elf64_hppa_link_hash_table *hppa_info; 2475 2476 hppa_info = hppa_link_hash_table (info); 2477 if (hppa_info == NULL) 2478 return FALSE; 2479 2480 /* Finalize the contents of the .opd section. */ 2481 elf_link_hash_traverse (elf_hash_table (info), 2482 elf64_hppa_finalize_opd, 2483 info); 2484 2485 elf_link_hash_traverse (elf_hash_table (info), 2486 elf64_hppa_finalize_dynreloc, 2487 info); 2488 2489 /* Finalize the contents of the .dlt section. */ 2490 dynobj = elf_hash_table (info)->dynobj; 2491 /* Finalize the contents of the .dlt section. */ 2492 elf_link_hash_traverse (elf_hash_table (info), 2493 elf64_hppa_finalize_dlt, 2494 info); 2495 2496 sdyn = bfd_get_linker_section (dynobj, ".dynamic"); 2497 2498 if (elf_hash_table (info)->dynamic_sections_created) 2499 { 2500 Elf64_External_Dyn *dyncon, *dynconend; 2501 2502 BFD_ASSERT (sdyn != NULL); 2503 2504 dyncon = (Elf64_External_Dyn *) sdyn->contents; 2505 dynconend = (Elf64_External_Dyn *) (sdyn->contents + sdyn->size); 2506 for (; dyncon < dynconend; dyncon++) 2507 { 2508 Elf_Internal_Dyn dyn; 2509 asection *s; 2510 2511 bfd_elf64_swap_dyn_in (dynobj, dyncon, &dyn); 2512 2513 switch (dyn.d_tag) 2514 { 2515 default: 2516 break; 2517 2518 case DT_HP_LOAD_MAP: 2519 /* Compute the absolute address of 16byte scratchpad area 2520 for the dynamic linker. 2521 2522 By convention the linker script will allocate the scratchpad 2523 area at the start of the .data section. So all we have to 2524 to is find the start of the .data section. */ 2525 s = bfd_get_section_by_name (output_bfd, ".data"); 2526 if (!s) 2527 return FALSE; 2528 dyn.d_un.d_ptr = s->vma; 2529 bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon); 2530 break; 2531 2532 case DT_PLTGOT: 2533 /* HP's use PLTGOT to set the GOT register. */ 2534 dyn.d_un.d_ptr = _bfd_get_gp_value (output_bfd); 2535 bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon); 2536 break; 2537 2538 case DT_JMPREL: 2539 s = hppa_info->plt_rel_sec; 2540 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset; 2541 bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon); 2542 break; 2543 2544 case DT_PLTRELSZ: 2545 s = hppa_info->plt_rel_sec; 2546 dyn.d_un.d_val = s->size; 2547 bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon); 2548 break; 2549 2550 case DT_RELA: 2551 s = hppa_info->other_rel_sec; 2552 if (! s || ! s->size) 2553 s = hppa_info->dlt_rel_sec; 2554 if (! s || ! s->size) 2555 s = hppa_info->opd_rel_sec; 2556 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset; 2557 bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon); 2558 break; 2559 2560 case DT_RELASZ: 2561 s = hppa_info->other_rel_sec; 2562 dyn.d_un.d_val = s->size; 2563 s = hppa_info->dlt_rel_sec; 2564 dyn.d_un.d_val += s->size; 2565 s = hppa_info->opd_rel_sec; 2566 dyn.d_un.d_val += s->size; 2567 /* There is some question about whether or not the size of 2568 the PLT relocs should be included here. HP's tools do 2569 it, so we'll emulate them. */ 2570 s = hppa_info->plt_rel_sec; 2571 dyn.d_un.d_val += s->size; 2572 bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon); 2573 break; 2574 2575 } 2576 } 2577 } 2578 2579 return TRUE; 2580 } 2581 2582 /* Support for core dump NOTE sections. */ 2583 2584 static bfd_boolean 2585 elf64_hppa_grok_prstatus (bfd *abfd, Elf_Internal_Note *note) 2586 { 2587 int offset; 2588 size_t size; 2589 2590 switch (note->descsz) 2591 { 2592 default: 2593 return FALSE; 2594 2595 case 760: /* Linux/hppa */ 2596 /* pr_cursig */ 2597 elf_tdata (abfd)->core->signal = bfd_get_16 (abfd, note->descdata + 12); 2598 2599 /* pr_pid */ 2600 elf_tdata (abfd)->core->lwpid = bfd_get_32 (abfd, note->descdata + 32); 2601 2602 /* pr_reg */ 2603 offset = 112; 2604 size = 640; 2605 2606 break; 2607 } 2608 2609 /* Make a ".reg/999" section. */ 2610 return _bfd_elfcore_make_pseudosection (abfd, ".reg", 2611 size, note->descpos + offset); 2612 } 2613 2614 static bfd_boolean 2615 elf64_hppa_grok_psinfo (bfd *abfd, Elf_Internal_Note *note) 2616 { 2617 char * command; 2618 int n; 2619 2620 switch (note->descsz) 2621 { 2622 default: 2623 return FALSE; 2624 2625 case 136: /* Linux/hppa elf_prpsinfo. */ 2626 elf_tdata (abfd)->core->program 2627 = _bfd_elfcore_strndup (abfd, note->descdata + 40, 16); 2628 elf_tdata (abfd)->core->command 2629 = _bfd_elfcore_strndup (abfd, note->descdata + 56, 80); 2630 } 2631 2632 /* Note that for some reason, a spurious space is tacked 2633 onto the end of the args in some (at least one anyway) 2634 implementations, so strip it off if it exists. */ 2635 command = elf_tdata (abfd)->core->command; 2636 n = strlen (command); 2637 2638 if (0 < n && command[n - 1] == ' ') 2639 command[n - 1] = '\0'; 2640 2641 return TRUE; 2642 } 2643 2644 /* Return the number of additional phdrs we will need. 2645 2646 The generic ELF code only creates PT_PHDRs for executables. The HP 2647 dynamic linker requires PT_PHDRs for dynamic libraries too. 2648 2649 This routine indicates that the backend needs one additional program 2650 header for that case. 2651 2652 Note we do not have access to the link info structure here, so we have 2653 to guess whether or not we are building a shared library based on the 2654 existence of a .interp section. */ 2655 2656 static int 2657 elf64_hppa_additional_program_headers (bfd *abfd, 2658 struct bfd_link_info *info ATTRIBUTE_UNUSED) 2659 { 2660 asection *s; 2661 2662 /* If we are creating a shared library, then we have to create a 2663 PT_PHDR segment. HP's dynamic linker chokes without it. */ 2664 s = bfd_get_section_by_name (abfd, ".interp"); 2665 if (! s) 2666 return 1; 2667 return 0; 2668 } 2669 2670 /* Allocate and initialize any program headers required by this 2671 specific backend. 2672 2673 The generic ELF code only creates PT_PHDRs for executables. The HP 2674 dynamic linker requires PT_PHDRs for dynamic libraries too. 2675 2676 This allocates the PT_PHDR and initializes it in a manner suitable 2677 for the HP linker. 2678 2679 Note we do not have access to the link info structure here, so we have 2680 to guess whether or not we are building a shared library based on the 2681 existence of a .interp section. */ 2682 2683 static bfd_boolean 2684 elf64_hppa_modify_segment_map (bfd *abfd, 2685 struct bfd_link_info *info ATTRIBUTE_UNUSED) 2686 { 2687 struct elf_segment_map *m; 2688 asection *s; 2689 2690 s = bfd_get_section_by_name (abfd, ".interp"); 2691 if (! s) 2692 { 2693 for (m = elf_seg_map (abfd); m != NULL; m = m->next) 2694 if (m->p_type == PT_PHDR) 2695 break; 2696 if (m == NULL) 2697 { 2698 m = ((struct elf_segment_map *) 2699 bfd_zalloc (abfd, (bfd_size_type) sizeof *m)); 2700 if (m == NULL) 2701 return FALSE; 2702 2703 m->p_type = PT_PHDR; 2704 m->p_flags = PF_R | PF_X; 2705 m->p_flags_valid = 1; 2706 m->p_paddr_valid = 1; 2707 m->includes_phdrs = 1; 2708 2709 m->next = elf_seg_map (abfd); 2710 elf_seg_map (abfd) = m; 2711 } 2712 } 2713 2714 for (m = elf_seg_map (abfd); m != NULL; m = m->next) 2715 if (m->p_type == PT_LOAD) 2716 { 2717 unsigned int i; 2718 2719 for (i = 0; i < m->count; i++) 2720 { 2721 /* The code "hint" is not really a hint. It is a requirement 2722 for certain versions of the HP dynamic linker. Worse yet, 2723 it must be set even if the shared library does not have 2724 any code in its "text" segment (thus the check for .hash 2725 to catch this situation). */ 2726 if (m->sections[i]->flags & SEC_CODE 2727 || (strcmp (m->sections[i]->name, ".hash") == 0)) 2728 m->p_flags |= (PF_X | PF_HP_CODE); 2729 } 2730 } 2731 2732 return TRUE; 2733 } 2734 2735 /* Called when writing out an object file to decide the type of a 2736 symbol. */ 2737 static int 2738 elf64_hppa_elf_get_symbol_type (Elf_Internal_Sym *elf_sym, 2739 int type) 2740 { 2741 if (ELF_ST_TYPE (elf_sym->st_info) == STT_PARISC_MILLI) 2742 return STT_PARISC_MILLI; 2743 else 2744 return type; 2745 } 2746 2747 /* Support HP specific sections for core files. */ 2748 2749 static bfd_boolean 2750 elf64_hppa_section_from_phdr (bfd *abfd, Elf_Internal_Phdr *hdr, int sec_index, 2751 const char *typename) 2752 { 2753 if (hdr->p_type == PT_HP_CORE_KERNEL) 2754 { 2755 asection *sect; 2756 2757 if (!_bfd_elf_make_section_from_phdr (abfd, hdr, sec_index, typename)) 2758 return FALSE; 2759 2760 sect = bfd_make_section_anyway (abfd, ".kernel"); 2761 if (sect == NULL) 2762 return FALSE; 2763 sect->size = hdr->p_filesz; 2764 sect->filepos = hdr->p_offset; 2765 sect->flags = SEC_HAS_CONTENTS | SEC_READONLY; 2766 return TRUE; 2767 } 2768 2769 if (hdr->p_type == PT_HP_CORE_PROC) 2770 { 2771 int sig; 2772 2773 if (bfd_seek (abfd, hdr->p_offset, SEEK_SET) != 0) 2774 return FALSE; 2775 if (bfd_bread (&sig, 4, abfd) != 4) 2776 return FALSE; 2777 2778 elf_tdata (abfd)->core->signal = sig; 2779 2780 if (!_bfd_elf_make_section_from_phdr (abfd, hdr, sec_index, typename)) 2781 return FALSE; 2782 2783 /* GDB uses the ".reg" section to read register contents. */ 2784 return _bfd_elfcore_make_pseudosection (abfd, ".reg", hdr->p_filesz, 2785 hdr->p_offset); 2786 } 2787 2788 if (hdr->p_type == PT_HP_CORE_LOADABLE 2789 || hdr->p_type == PT_HP_CORE_STACK 2790 || hdr->p_type == PT_HP_CORE_MMF) 2791 hdr->p_type = PT_LOAD; 2792 2793 return _bfd_elf_make_section_from_phdr (abfd, hdr, sec_index, typename); 2794 } 2795 2796 /* Hook called by the linker routine which adds symbols from an object 2797 file. HP's libraries define symbols with HP specific section 2798 indices, which we have to handle. */ 2799 2800 static bfd_boolean 2801 elf_hppa_add_symbol_hook (bfd *abfd, 2802 struct bfd_link_info *info ATTRIBUTE_UNUSED, 2803 Elf_Internal_Sym *sym, 2804 const char **namep ATTRIBUTE_UNUSED, 2805 flagword *flagsp ATTRIBUTE_UNUSED, 2806 asection **secp, 2807 bfd_vma *valp) 2808 { 2809 unsigned int sec_index = sym->st_shndx; 2810 2811 switch (sec_index) 2812 { 2813 case SHN_PARISC_ANSI_COMMON: 2814 *secp = bfd_make_section_old_way (abfd, ".PARISC.ansi.common"); 2815 (*secp)->flags |= SEC_IS_COMMON; 2816 *valp = sym->st_size; 2817 break; 2818 2819 case SHN_PARISC_HUGE_COMMON: 2820 *secp = bfd_make_section_old_way (abfd, ".PARISC.huge.common"); 2821 (*secp)->flags |= SEC_IS_COMMON; 2822 *valp = sym->st_size; 2823 break; 2824 } 2825 2826 return TRUE; 2827 } 2828 2829 static bfd_boolean 2830 elf_hppa_unmark_useless_dynamic_symbols (struct elf_link_hash_entry *h, 2831 void *data) 2832 { 2833 struct bfd_link_info *info = data; 2834 2835 /* If we are not creating a shared library, and this symbol is 2836 referenced by a shared library but is not defined anywhere, then 2837 the generic code will warn that it is undefined. 2838 2839 This behavior is undesirable on HPs since the standard shared 2840 libraries contain references to undefined symbols. 2841 2842 So we twiddle the flags associated with such symbols so that they 2843 will not trigger the warning. ?!? FIXME. This is horribly fragile. 2844 2845 Ultimately we should have better controls over the generic ELF BFD 2846 linker code. */ 2847 if (! info->relocatable 2848 && info->unresolved_syms_in_shared_libs != RM_IGNORE 2849 && h->root.type == bfd_link_hash_undefined 2850 && h->ref_dynamic 2851 && !h->ref_regular) 2852 { 2853 h->ref_dynamic = 0; 2854 h->pointer_equality_needed = 1; 2855 } 2856 2857 return TRUE; 2858 } 2859 2860 static bfd_boolean 2861 elf_hppa_remark_useless_dynamic_symbols (struct elf_link_hash_entry *h, 2862 void *data) 2863 { 2864 struct bfd_link_info *info = data; 2865 2866 /* If we are not creating a shared library, and this symbol is 2867 referenced by a shared library but is not defined anywhere, then 2868 the generic code will warn that it is undefined. 2869 2870 This behavior is undesirable on HPs since the standard shared 2871 libraries contain references to undefined symbols. 2872 2873 So we twiddle the flags associated with such symbols so that they 2874 will not trigger the warning. ?!? FIXME. This is horribly fragile. 2875 2876 Ultimately we should have better controls over the generic ELF BFD 2877 linker code. */ 2878 if (! info->relocatable 2879 && info->unresolved_syms_in_shared_libs != RM_IGNORE 2880 && h->root.type == bfd_link_hash_undefined 2881 && !h->ref_dynamic 2882 && !h->ref_regular 2883 && h->pointer_equality_needed) 2884 { 2885 h->ref_dynamic = 1; 2886 h->pointer_equality_needed = 0; 2887 } 2888 2889 return TRUE; 2890 } 2891 2892 static bfd_boolean 2893 elf_hppa_is_dynamic_loader_symbol (const char *name) 2894 { 2895 return (! strcmp (name, "__CPU_REVISION") 2896 || ! strcmp (name, "__CPU_KEYBITS_1") 2897 || ! strcmp (name, "__SYSTEM_ID_D") 2898 || ! strcmp (name, "__FPU_MODEL") 2899 || ! strcmp (name, "__FPU_REVISION") 2900 || ! strcmp (name, "__ARGC") 2901 || ! strcmp (name, "__ARGV") 2902 || ! strcmp (name, "__ENVP") 2903 || ! strcmp (name, "__TLS_SIZE_D") 2904 || ! strcmp (name, "__LOAD_INFO") 2905 || ! strcmp (name, "__systab")); 2906 } 2907 2908 /* Record the lowest address for the data and text segments. */ 2909 static void 2910 elf_hppa_record_segment_addrs (bfd *abfd, 2911 asection *section, 2912 void *data) 2913 { 2914 struct elf64_hppa_link_hash_table *hppa_info = data; 2915 2916 if ((section->flags & (SEC_ALLOC | SEC_LOAD)) == (SEC_ALLOC | SEC_LOAD)) 2917 { 2918 bfd_vma value; 2919 Elf_Internal_Phdr *p; 2920 2921 p = _bfd_elf_find_segment_containing_section (abfd, section->output_section); 2922 BFD_ASSERT (p != NULL); 2923 value = p->p_vaddr; 2924 2925 if (section->flags & SEC_READONLY) 2926 { 2927 if (value < hppa_info->text_segment_base) 2928 hppa_info->text_segment_base = value; 2929 } 2930 else 2931 { 2932 if (value < hppa_info->data_segment_base) 2933 hppa_info->data_segment_base = value; 2934 } 2935 } 2936 } 2937 2938 /* Called after we have seen all the input files/sections, but before 2939 final symbol resolution and section placement has been determined. 2940 2941 We use this hook to (possibly) provide a value for __gp, then we 2942 fall back to the generic ELF final link routine. */ 2943 2944 static bfd_boolean 2945 elf_hppa_final_link (bfd *abfd, struct bfd_link_info *info) 2946 { 2947 bfd_boolean retval; 2948 struct elf64_hppa_link_hash_table *hppa_info = hppa_link_hash_table (info); 2949 2950 if (hppa_info == NULL) 2951 return FALSE; 2952 2953 if (! info->relocatable) 2954 { 2955 struct elf_link_hash_entry *gp; 2956 bfd_vma gp_val; 2957 2958 /* The linker script defines a value for __gp iff it was referenced 2959 by one of the objects being linked. First try to find the symbol 2960 in the hash table. If that fails, just compute the value __gp 2961 should have had. */ 2962 gp = elf_link_hash_lookup (elf_hash_table (info), "__gp", FALSE, 2963 FALSE, FALSE); 2964 2965 if (gp) 2966 { 2967 2968 /* Adjust the value of __gp as we may want to slide it into the 2969 .plt section so that the stubs can access PLT entries without 2970 using an addil sequence. */ 2971 gp->root.u.def.value += hppa_info->gp_offset; 2972 2973 gp_val = (gp->root.u.def.section->output_section->vma 2974 + gp->root.u.def.section->output_offset 2975 + gp->root.u.def.value); 2976 } 2977 else 2978 { 2979 asection *sec; 2980 2981 /* First look for a .plt section. If found, then __gp is the 2982 address of the .plt + gp_offset. 2983 2984 If no .plt is found, then look for .dlt, .opd and .data (in 2985 that order) and set __gp to the base address of whichever 2986 section is found first. */ 2987 2988 sec = hppa_info->plt_sec; 2989 if (sec && ! (sec->flags & SEC_EXCLUDE)) 2990 gp_val = (sec->output_offset 2991 + sec->output_section->vma 2992 + hppa_info->gp_offset); 2993 else 2994 { 2995 sec = hppa_info->dlt_sec; 2996 if (!sec || (sec->flags & SEC_EXCLUDE)) 2997 sec = hppa_info->opd_sec; 2998 if (!sec || (sec->flags & SEC_EXCLUDE)) 2999 sec = bfd_get_section_by_name (abfd, ".data"); 3000 if (!sec || (sec->flags & SEC_EXCLUDE)) 3001 gp_val = 0; 3002 else 3003 gp_val = sec->output_offset + sec->output_section->vma; 3004 } 3005 } 3006 3007 /* Install whatever value we found/computed for __gp. */ 3008 _bfd_set_gp_value (abfd, gp_val); 3009 } 3010 3011 /* We need to know the base of the text and data segments so that we 3012 can perform SEGREL relocations. We will record the base addresses 3013 when we encounter the first SEGREL relocation. */ 3014 hppa_info->text_segment_base = (bfd_vma)-1; 3015 hppa_info->data_segment_base = (bfd_vma)-1; 3016 3017 /* HP's shared libraries have references to symbols that are not 3018 defined anywhere. The generic ELF BFD linker code will complain 3019 about such symbols. 3020 3021 So we detect the losing case and arrange for the flags on the symbol 3022 to indicate that it was never referenced. This keeps the generic 3023 ELF BFD link code happy and appears to not create any secondary 3024 problems. Ultimately we need a way to control the behavior of the 3025 generic ELF BFD link code better. */ 3026 elf_link_hash_traverse (elf_hash_table (info), 3027 elf_hppa_unmark_useless_dynamic_symbols, 3028 info); 3029 3030 /* Invoke the regular ELF backend linker to do all the work. */ 3031 retval = bfd_elf_final_link (abfd, info); 3032 3033 elf_link_hash_traverse (elf_hash_table (info), 3034 elf_hppa_remark_useless_dynamic_symbols, 3035 info); 3036 3037 /* If we're producing a final executable, sort the contents of the 3038 unwind section. */ 3039 if (retval && !info->relocatable) 3040 retval = elf_hppa_sort_unwind (abfd); 3041 3042 return retval; 3043 } 3044 3045 /* Relocate the given INSN. VALUE should be the actual value we want 3046 to insert into the instruction, ie by this point we should not be 3047 concerned with computing an offset relative to the DLT, PC, etc. 3048 Instead this routine is meant to handle the bit manipulations needed 3049 to insert the relocation into the given instruction. */ 3050 3051 static int 3052 elf_hppa_relocate_insn (int insn, int sym_value, unsigned int r_type) 3053 { 3054 switch (r_type) 3055 { 3056 /* This is any 22 bit branch. In PA2.0 syntax it corresponds to 3057 the "B" instruction. */ 3058 case R_PARISC_PCREL22F: 3059 case R_PARISC_PCREL22C: 3060 return (insn & ~0x3ff1ffd) | re_assemble_22 (sym_value); 3061 3062 /* This is any 12 bit branch. */ 3063 case R_PARISC_PCREL12F: 3064 return (insn & ~0x1ffd) | re_assemble_12 (sym_value); 3065 3066 /* This is any 17 bit branch. In PA2.0 syntax it also corresponds 3067 to the "B" instruction as well as BE. */ 3068 case R_PARISC_PCREL17F: 3069 case R_PARISC_DIR17F: 3070 case R_PARISC_DIR17R: 3071 case R_PARISC_PCREL17C: 3072 case R_PARISC_PCREL17R: 3073 return (insn & ~0x1f1ffd) | re_assemble_17 (sym_value); 3074 3075 /* ADDIL or LDIL instructions. */ 3076 case R_PARISC_DLTREL21L: 3077 case R_PARISC_DLTIND21L: 3078 case R_PARISC_LTOFF_FPTR21L: 3079 case R_PARISC_PCREL21L: 3080 case R_PARISC_LTOFF_TP21L: 3081 case R_PARISC_DPREL21L: 3082 case R_PARISC_PLTOFF21L: 3083 case R_PARISC_DIR21L: 3084 return (insn & ~0x1fffff) | re_assemble_21 (sym_value); 3085 3086 /* LDO and integer loads/stores with 14 bit displacements. */ 3087 case R_PARISC_DLTREL14R: 3088 case R_PARISC_DLTREL14F: 3089 case R_PARISC_DLTIND14R: 3090 case R_PARISC_DLTIND14F: 3091 case R_PARISC_LTOFF_FPTR14R: 3092 case R_PARISC_PCREL14R: 3093 case R_PARISC_PCREL14F: 3094 case R_PARISC_LTOFF_TP14R: 3095 case R_PARISC_LTOFF_TP14F: 3096 case R_PARISC_DPREL14R: 3097 case R_PARISC_DPREL14F: 3098 case R_PARISC_PLTOFF14R: 3099 case R_PARISC_PLTOFF14F: 3100 case R_PARISC_DIR14R: 3101 case R_PARISC_DIR14F: 3102 return (insn & ~0x3fff) | low_sign_unext (sym_value, 14); 3103 3104 /* PA2.0W LDO and integer loads/stores with 16 bit displacements. */ 3105 case R_PARISC_LTOFF_FPTR16F: 3106 case R_PARISC_PCREL16F: 3107 case R_PARISC_LTOFF_TP16F: 3108 case R_PARISC_GPREL16F: 3109 case R_PARISC_PLTOFF16F: 3110 case R_PARISC_DIR16F: 3111 case R_PARISC_LTOFF16F: 3112 return (insn & ~0xffff) | re_assemble_16 (sym_value); 3113 3114 /* Doubleword loads and stores with a 14 bit displacement. */ 3115 case R_PARISC_DLTREL14DR: 3116 case R_PARISC_DLTIND14DR: 3117 case R_PARISC_LTOFF_FPTR14DR: 3118 case R_PARISC_LTOFF_FPTR16DF: 3119 case R_PARISC_PCREL14DR: 3120 case R_PARISC_PCREL16DF: 3121 case R_PARISC_LTOFF_TP14DR: 3122 case R_PARISC_LTOFF_TP16DF: 3123 case R_PARISC_DPREL14DR: 3124 case R_PARISC_GPREL16DF: 3125 case R_PARISC_PLTOFF14DR: 3126 case R_PARISC_PLTOFF16DF: 3127 case R_PARISC_DIR14DR: 3128 case R_PARISC_DIR16DF: 3129 case R_PARISC_LTOFF16DF: 3130 return (insn & ~0x3ff1) | (((sym_value & 0x2000) >> 13) 3131 | ((sym_value & 0x1ff8) << 1)); 3132 3133 /* Floating point single word load/store instructions. */ 3134 case R_PARISC_DLTREL14WR: 3135 case R_PARISC_DLTIND14WR: 3136 case R_PARISC_LTOFF_FPTR14WR: 3137 case R_PARISC_LTOFF_FPTR16WF: 3138 case R_PARISC_PCREL14WR: 3139 case R_PARISC_PCREL16WF: 3140 case R_PARISC_LTOFF_TP14WR: 3141 case R_PARISC_LTOFF_TP16WF: 3142 case R_PARISC_DPREL14WR: 3143 case R_PARISC_GPREL16WF: 3144 case R_PARISC_PLTOFF14WR: 3145 case R_PARISC_PLTOFF16WF: 3146 case R_PARISC_DIR16WF: 3147 case R_PARISC_DIR14WR: 3148 case R_PARISC_LTOFF16WF: 3149 return (insn & ~0x3ff9) | (((sym_value & 0x2000) >> 13) 3150 | ((sym_value & 0x1ffc) << 1)); 3151 3152 default: 3153 return insn; 3154 } 3155 } 3156 3157 /* Compute the value for a relocation (REL) during a final link stage, 3158 then insert the value into the proper location in CONTENTS. 3159 3160 VALUE is a tentative value for the relocation and may be overridden 3161 and modified here based on the specific relocation to be performed. 3162 3163 For example we do conversions for PC-relative branches in this routine 3164 or redirection of calls to external routines to stubs. 3165 3166 The work of actually applying the relocation is left to a helper 3167 routine in an attempt to reduce the complexity and size of this 3168 function. */ 3169 3170 static bfd_reloc_status_type 3171 elf_hppa_final_link_relocate (Elf_Internal_Rela *rel, 3172 bfd *input_bfd, 3173 bfd *output_bfd, 3174 asection *input_section, 3175 bfd_byte *contents, 3176 bfd_vma value, 3177 struct bfd_link_info *info, 3178 asection *sym_sec, 3179 struct elf_link_hash_entry *eh) 3180 { 3181 struct elf64_hppa_link_hash_table *hppa_info = hppa_link_hash_table (info); 3182 struct elf64_hppa_link_hash_entry *hh = hppa_elf_hash_entry (eh); 3183 bfd_vma *local_offsets; 3184 Elf_Internal_Shdr *symtab_hdr; 3185 int insn; 3186 bfd_vma max_branch_offset = 0; 3187 bfd_vma offset = rel->r_offset; 3188 bfd_signed_vma addend = rel->r_addend; 3189 reloc_howto_type *howto = elf_hppa_howto_table + ELF_R_TYPE (rel->r_info); 3190 unsigned int r_symndx = ELF_R_SYM (rel->r_info); 3191 unsigned int r_type = howto->type; 3192 bfd_byte *hit_data = contents + offset; 3193 3194 if (hppa_info == NULL) 3195 return bfd_reloc_notsupported; 3196 3197 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; 3198 local_offsets = elf_local_got_offsets (input_bfd); 3199 insn = bfd_get_32 (input_bfd, hit_data); 3200 3201 switch (r_type) 3202 { 3203 case R_PARISC_NONE: 3204 break; 3205 3206 /* Basic function call support. 3207 3208 Note for a call to a function defined in another dynamic library 3209 we want to redirect the call to a stub. */ 3210 3211 /* PC relative relocs without an implicit offset. */ 3212 case R_PARISC_PCREL21L: 3213 case R_PARISC_PCREL14R: 3214 case R_PARISC_PCREL14F: 3215 case R_PARISC_PCREL14WR: 3216 case R_PARISC_PCREL14DR: 3217 case R_PARISC_PCREL16F: 3218 case R_PARISC_PCREL16WF: 3219 case R_PARISC_PCREL16DF: 3220 { 3221 /* If this is a call to a function defined in another dynamic 3222 library, then redirect the call to the local stub for this 3223 function. */ 3224 if (sym_sec == NULL || sym_sec->output_section == NULL) 3225 value = (hh->stub_offset + hppa_info->stub_sec->output_offset 3226 + hppa_info->stub_sec->output_section->vma); 3227 3228 /* Turn VALUE into a proper PC relative address. */ 3229 value -= (offset + input_section->output_offset 3230 + input_section->output_section->vma); 3231 3232 /* Adjust for any field selectors. */ 3233 if (r_type == R_PARISC_PCREL21L) 3234 value = hppa_field_adjust (value, -8 + addend, e_lsel); 3235 else if (r_type == R_PARISC_PCREL14F 3236 || r_type == R_PARISC_PCREL16F 3237 || r_type == R_PARISC_PCREL16WF 3238 || r_type == R_PARISC_PCREL16DF) 3239 value = hppa_field_adjust (value, -8 + addend, e_fsel); 3240 else 3241 value = hppa_field_adjust (value, -8 + addend, e_rsel); 3242 3243 /* Apply the relocation to the given instruction. */ 3244 insn = elf_hppa_relocate_insn (insn, (int) value, r_type); 3245 break; 3246 } 3247 3248 case R_PARISC_PCREL12F: 3249 case R_PARISC_PCREL22F: 3250 case R_PARISC_PCREL17F: 3251 case R_PARISC_PCREL22C: 3252 case R_PARISC_PCREL17C: 3253 case R_PARISC_PCREL17R: 3254 { 3255 /* If this is a call to a function defined in another dynamic 3256 library, then redirect the call to the local stub for this 3257 function. */ 3258 if (sym_sec == NULL || sym_sec->output_section == NULL) 3259 value = (hh->stub_offset + hppa_info->stub_sec->output_offset 3260 + hppa_info->stub_sec->output_section->vma); 3261 3262 /* Turn VALUE into a proper PC relative address. */ 3263 value -= (offset + input_section->output_offset 3264 + input_section->output_section->vma); 3265 addend -= 8; 3266 3267 if (r_type == (unsigned int) R_PARISC_PCREL22F) 3268 max_branch_offset = (1 << (22-1)) << 2; 3269 else if (r_type == (unsigned int) R_PARISC_PCREL17F) 3270 max_branch_offset = (1 << (17-1)) << 2; 3271 else if (r_type == (unsigned int) R_PARISC_PCREL12F) 3272 max_branch_offset = (1 << (12-1)) << 2; 3273 3274 /* Make sure we can reach the branch target. */ 3275 if (max_branch_offset != 0 3276 && value + addend + max_branch_offset >= 2*max_branch_offset) 3277 { 3278 (*_bfd_error_handler) 3279 (_("%B(%A+0x%" BFD_VMA_FMT "x): cannot reach %s"), 3280 input_bfd, 3281 input_section, 3282 offset, 3283 eh ? eh->root.root.string : "unknown"); 3284 bfd_set_error (bfd_error_bad_value); 3285 return bfd_reloc_overflow; 3286 } 3287 3288 /* Adjust for any field selectors. */ 3289 if (r_type == R_PARISC_PCREL17R) 3290 value = hppa_field_adjust (value, addend, e_rsel); 3291 else 3292 value = hppa_field_adjust (value, addend, e_fsel); 3293 3294 /* All branches are implicitly shifted by 2 places. */ 3295 value >>= 2; 3296 3297 /* Apply the relocation to the given instruction. */ 3298 insn = elf_hppa_relocate_insn (insn, (int) value, r_type); 3299 break; 3300 } 3301 3302 /* Indirect references to data through the DLT. */ 3303 case R_PARISC_DLTIND14R: 3304 case R_PARISC_DLTIND14F: 3305 case R_PARISC_DLTIND14DR: 3306 case R_PARISC_DLTIND14WR: 3307 case R_PARISC_DLTIND21L: 3308 case R_PARISC_LTOFF_FPTR14R: 3309 case R_PARISC_LTOFF_FPTR14DR: 3310 case R_PARISC_LTOFF_FPTR14WR: 3311 case R_PARISC_LTOFF_FPTR21L: 3312 case R_PARISC_LTOFF_FPTR16F: 3313 case R_PARISC_LTOFF_FPTR16WF: 3314 case R_PARISC_LTOFF_FPTR16DF: 3315 case R_PARISC_LTOFF_TP21L: 3316 case R_PARISC_LTOFF_TP14R: 3317 case R_PARISC_LTOFF_TP14F: 3318 case R_PARISC_LTOFF_TP14WR: 3319 case R_PARISC_LTOFF_TP14DR: 3320 case R_PARISC_LTOFF_TP16F: 3321 case R_PARISC_LTOFF_TP16WF: 3322 case R_PARISC_LTOFF_TP16DF: 3323 case R_PARISC_LTOFF16F: 3324 case R_PARISC_LTOFF16WF: 3325 case R_PARISC_LTOFF16DF: 3326 { 3327 bfd_vma off; 3328 3329 /* If this relocation was against a local symbol, then we still 3330 have not set up the DLT entry (it's not convenient to do so 3331 in the "finalize_dlt" routine because it is difficult to get 3332 to the local symbol's value). 3333 3334 So, if this is a local symbol (h == NULL), then we need to 3335 fill in its DLT entry. 3336 3337 Similarly we may still need to set up an entry in .opd for 3338 a local function which had its address taken. */ 3339 if (hh == NULL) 3340 { 3341 bfd_vma *local_opd_offsets, *local_dlt_offsets; 3342 3343 if (local_offsets == NULL) 3344 abort (); 3345 3346 /* Now do .opd creation if needed. */ 3347 if (r_type == R_PARISC_LTOFF_FPTR14R 3348 || r_type == R_PARISC_LTOFF_FPTR14DR 3349 || r_type == R_PARISC_LTOFF_FPTR14WR 3350 || r_type == R_PARISC_LTOFF_FPTR21L 3351 || r_type == R_PARISC_LTOFF_FPTR16F 3352 || r_type == R_PARISC_LTOFF_FPTR16WF 3353 || r_type == R_PARISC_LTOFF_FPTR16DF) 3354 { 3355 local_opd_offsets = local_offsets + 2 * symtab_hdr->sh_info; 3356 off = local_opd_offsets[r_symndx]; 3357 3358 /* The last bit records whether we've already initialised 3359 this local .opd entry. */ 3360 if ((off & 1) != 0) 3361 { 3362 BFD_ASSERT (off != (bfd_vma) -1); 3363 off &= ~1; 3364 } 3365 else 3366 { 3367 local_opd_offsets[r_symndx] |= 1; 3368 3369 /* The first two words of an .opd entry are zero. */ 3370 memset (hppa_info->opd_sec->contents + off, 0, 16); 3371 3372 /* The next word is the address of the function. */ 3373 bfd_put_64 (hppa_info->opd_sec->owner, value + addend, 3374 (hppa_info->opd_sec->contents + off + 16)); 3375 3376 /* The last word is our local __gp value. */ 3377 value = _bfd_get_gp_value 3378 (hppa_info->opd_sec->output_section->owner); 3379 bfd_put_64 (hppa_info->opd_sec->owner, value, 3380 (hppa_info->opd_sec->contents + off + 24)); 3381 } 3382 3383 /* The DLT value is the address of the .opd entry. */ 3384 value = (off 3385 + hppa_info->opd_sec->output_offset 3386 + hppa_info->opd_sec->output_section->vma); 3387 addend = 0; 3388 } 3389 3390 local_dlt_offsets = local_offsets; 3391 off = local_dlt_offsets[r_symndx]; 3392 3393 if ((off & 1) != 0) 3394 { 3395 BFD_ASSERT (off != (bfd_vma) -1); 3396 off &= ~1; 3397 } 3398 else 3399 { 3400 local_dlt_offsets[r_symndx] |= 1; 3401 bfd_put_64 (hppa_info->dlt_sec->owner, 3402 value + addend, 3403 hppa_info->dlt_sec->contents + off); 3404 } 3405 } 3406 else 3407 off = hh->dlt_offset; 3408 3409 /* We want the value of the DLT offset for this symbol, not 3410 the symbol's actual address. Note that __gp may not point 3411 to the start of the DLT, so we have to compute the absolute 3412 address, then subtract out the value of __gp. */ 3413 value = (off 3414 + hppa_info->dlt_sec->output_offset 3415 + hppa_info->dlt_sec->output_section->vma); 3416 value -= _bfd_get_gp_value (output_bfd); 3417 3418 /* All DLTIND relocations are basically the same at this point, 3419 except that we need different field selectors for the 21bit 3420 version vs the 14bit versions. */ 3421 if (r_type == R_PARISC_DLTIND21L 3422 || r_type == R_PARISC_LTOFF_FPTR21L 3423 || r_type == R_PARISC_LTOFF_TP21L) 3424 value = hppa_field_adjust (value, 0, e_lsel); 3425 else if (r_type == R_PARISC_DLTIND14F 3426 || r_type == R_PARISC_LTOFF_FPTR16F 3427 || r_type == R_PARISC_LTOFF_FPTR16WF 3428 || r_type == R_PARISC_LTOFF_FPTR16DF 3429 || r_type == R_PARISC_LTOFF16F 3430 || r_type == R_PARISC_LTOFF16DF 3431 || r_type == R_PARISC_LTOFF16WF 3432 || r_type == R_PARISC_LTOFF_TP16F 3433 || r_type == R_PARISC_LTOFF_TP16WF 3434 || r_type == R_PARISC_LTOFF_TP16DF) 3435 value = hppa_field_adjust (value, 0, e_fsel); 3436 else 3437 value = hppa_field_adjust (value, 0, e_rsel); 3438 3439 insn = elf_hppa_relocate_insn (insn, (int) value, r_type); 3440 break; 3441 } 3442 3443 case R_PARISC_DLTREL14R: 3444 case R_PARISC_DLTREL14F: 3445 case R_PARISC_DLTREL14DR: 3446 case R_PARISC_DLTREL14WR: 3447 case R_PARISC_DLTREL21L: 3448 case R_PARISC_DPREL21L: 3449 case R_PARISC_DPREL14WR: 3450 case R_PARISC_DPREL14DR: 3451 case R_PARISC_DPREL14R: 3452 case R_PARISC_DPREL14F: 3453 case R_PARISC_GPREL16F: 3454 case R_PARISC_GPREL16WF: 3455 case R_PARISC_GPREL16DF: 3456 { 3457 /* Subtract out the global pointer value to make value a DLT 3458 relative address. */ 3459 value -= _bfd_get_gp_value (output_bfd); 3460 3461 /* All DLTREL relocations are basically the same at this point, 3462 except that we need different field selectors for the 21bit 3463 version vs the 14bit versions. */ 3464 if (r_type == R_PARISC_DLTREL21L 3465 || r_type == R_PARISC_DPREL21L) 3466 value = hppa_field_adjust (value, addend, e_lrsel); 3467 else if (r_type == R_PARISC_DLTREL14F 3468 || r_type == R_PARISC_DPREL14F 3469 || r_type == R_PARISC_GPREL16F 3470 || r_type == R_PARISC_GPREL16WF 3471 || r_type == R_PARISC_GPREL16DF) 3472 value = hppa_field_adjust (value, addend, e_fsel); 3473 else 3474 value = hppa_field_adjust (value, addend, e_rrsel); 3475 3476 insn = elf_hppa_relocate_insn (insn, (int) value, r_type); 3477 break; 3478 } 3479 3480 case R_PARISC_DIR21L: 3481 case R_PARISC_DIR17R: 3482 case R_PARISC_DIR17F: 3483 case R_PARISC_DIR14R: 3484 case R_PARISC_DIR14F: 3485 case R_PARISC_DIR14WR: 3486 case R_PARISC_DIR14DR: 3487 case R_PARISC_DIR16F: 3488 case R_PARISC_DIR16WF: 3489 case R_PARISC_DIR16DF: 3490 { 3491 /* All DIR relocations are basically the same at this point, 3492 except that branch offsets need to be divided by four, and 3493 we need different field selectors. Note that we don't 3494 redirect absolute calls to local stubs. */ 3495 3496 if (r_type == R_PARISC_DIR21L) 3497 value = hppa_field_adjust (value, addend, e_lrsel); 3498 else if (r_type == R_PARISC_DIR17F 3499 || r_type == R_PARISC_DIR16F 3500 || r_type == R_PARISC_DIR16WF 3501 || r_type == R_PARISC_DIR16DF 3502 || r_type == R_PARISC_DIR14F) 3503 value = hppa_field_adjust (value, addend, e_fsel); 3504 else 3505 value = hppa_field_adjust (value, addend, e_rrsel); 3506 3507 if (r_type == R_PARISC_DIR17R || r_type == R_PARISC_DIR17F) 3508 /* All branches are implicitly shifted by 2 places. */ 3509 value >>= 2; 3510 3511 insn = elf_hppa_relocate_insn (insn, (int) value, r_type); 3512 break; 3513 } 3514 3515 case R_PARISC_PLTOFF21L: 3516 case R_PARISC_PLTOFF14R: 3517 case R_PARISC_PLTOFF14F: 3518 case R_PARISC_PLTOFF14WR: 3519 case R_PARISC_PLTOFF14DR: 3520 case R_PARISC_PLTOFF16F: 3521 case R_PARISC_PLTOFF16WF: 3522 case R_PARISC_PLTOFF16DF: 3523 { 3524 /* We want the value of the PLT offset for this symbol, not 3525 the symbol's actual address. Note that __gp may not point 3526 to the start of the DLT, so we have to compute the absolute 3527 address, then subtract out the value of __gp. */ 3528 value = (hh->plt_offset 3529 + hppa_info->plt_sec->output_offset 3530 + hppa_info->plt_sec->output_section->vma); 3531 value -= _bfd_get_gp_value (output_bfd); 3532 3533 /* All PLTOFF relocations are basically the same at this point, 3534 except that we need different field selectors for the 21bit 3535 version vs the 14bit versions. */ 3536 if (r_type == R_PARISC_PLTOFF21L) 3537 value = hppa_field_adjust (value, addend, e_lrsel); 3538 else if (r_type == R_PARISC_PLTOFF14F 3539 || r_type == R_PARISC_PLTOFF16F 3540 || r_type == R_PARISC_PLTOFF16WF 3541 || r_type == R_PARISC_PLTOFF16DF) 3542 value = hppa_field_adjust (value, addend, e_fsel); 3543 else 3544 value = hppa_field_adjust (value, addend, e_rrsel); 3545 3546 insn = elf_hppa_relocate_insn (insn, (int) value, r_type); 3547 break; 3548 } 3549 3550 case R_PARISC_LTOFF_FPTR32: 3551 { 3552 /* We may still need to create the FPTR itself if it was for 3553 a local symbol. */ 3554 if (hh == NULL) 3555 { 3556 /* The first two words of an .opd entry are zero. */ 3557 memset (hppa_info->opd_sec->contents + hh->opd_offset, 0, 16); 3558 3559 /* The next word is the address of the function. */ 3560 bfd_put_64 (hppa_info->opd_sec->owner, value + addend, 3561 (hppa_info->opd_sec->contents 3562 + hh->opd_offset + 16)); 3563 3564 /* The last word is our local __gp value. */ 3565 value = _bfd_get_gp_value 3566 (hppa_info->opd_sec->output_section->owner); 3567 bfd_put_64 (hppa_info->opd_sec->owner, value, 3568 hppa_info->opd_sec->contents + hh->opd_offset + 24); 3569 3570 /* The DLT value is the address of the .opd entry. */ 3571 value = (hh->opd_offset 3572 + hppa_info->opd_sec->output_offset 3573 + hppa_info->opd_sec->output_section->vma); 3574 3575 bfd_put_64 (hppa_info->dlt_sec->owner, 3576 value, 3577 hppa_info->dlt_sec->contents + hh->dlt_offset); 3578 } 3579 3580 /* We want the value of the DLT offset for this symbol, not 3581 the symbol's actual address. Note that __gp may not point 3582 to the start of the DLT, so we have to compute the absolute 3583 address, then subtract out the value of __gp. */ 3584 value = (hh->dlt_offset 3585 + hppa_info->dlt_sec->output_offset 3586 + hppa_info->dlt_sec->output_section->vma); 3587 value -= _bfd_get_gp_value (output_bfd); 3588 bfd_put_32 (input_bfd, value, hit_data); 3589 return bfd_reloc_ok; 3590 } 3591 3592 case R_PARISC_LTOFF_FPTR64: 3593 case R_PARISC_LTOFF_TP64: 3594 { 3595 /* We may still need to create the FPTR itself if it was for 3596 a local symbol. */ 3597 if (eh == NULL && r_type == R_PARISC_LTOFF_FPTR64) 3598 { 3599 /* The first two words of an .opd entry are zero. */ 3600 memset (hppa_info->opd_sec->contents + hh->opd_offset, 0, 16); 3601 3602 /* The next word is the address of the function. */ 3603 bfd_put_64 (hppa_info->opd_sec->owner, value + addend, 3604 (hppa_info->opd_sec->contents 3605 + hh->opd_offset + 16)); 3606 3607 /* The last word is our local __gp value. */ 3608 value = _bfd_get_gp_value 3609 (hppa_info->opd_sec->output_section->owner); 3610 bfd_put_64 (hppa_info->opd_sec->owner, value, 3611 hppa_info->opd_sec->contents + hh->opd_offset + 24); 3612 3613 /* The DLT value is the address of the .opd entry. */ 3614 value = (hh->opd_offset 3615 + hppa_info->opd_sec->output_offset 3616 + hppa_info->opd_sec->output_section->vma); 3617 3618 bfd_put_64 (hppa_info->dlt_sec->owner, 3619 value, 3620 hppa_info->dlt_sec->contents + hh->dlt_offset); 3621 } 3622 3623 /* We want the value of the DLT offset for this symbol, not 3624 the symbol's actual address. Note that __gp may not point 3625 to the start of the DLT, so we have to compute the absolute 3626 address, then subtract out the value of __gp. */ 3627 value = (hh->dlt_offset 3628 + hppa_info->dlt_sec->output_offset 3629 + hppa_info->dlt_sec->output_section->vma); 3630 value -= _bfd_get_gp_value (output_bfd); 3631 bfd_put_64 (input_bfd, value, hit_data); 3632 return bfd_reloc_ok; 3633 } 3634 3635 case R_PARISC_DIR32: 3636 bfd_put_32 (input_bfd, value + addend, hit_data); 3637 return bfd_reloc_ok; 3638 3639 case R_PARISC_DIR64: 3640 bfd_put_64 (input_bfd, value + addend, hit_data); 3641 return bfd_reloc_ok; 3642 3643 case R_PARISC_GPREL64: 3644 /* Subtract out the global pointer value to make value a DLT 3645 relative address. */ 3646 value -= _bfd_get_gp_value (output_bfd); 3647 3648 bfd_put_64 (input_bfd, value + addend, hit_data); 3649 return bfd_reloc_ok; 3650 3651 case R_PARISC_LTOFF64: 3652 /* We want the value of the DLT offset for this symbol, not 3653 the symbol's actual address. Note that __gp may not point 3654 to the start of the DLT, so we have to compute the absolute 3655 address, then subtract out the value of __gp. */ 3656 value = (hh->dlt_offset 3657 + hppa_info->dlt_sec->output_offset 3658 + hppa_info->dlt_sec->output_section->vma); 3659 value -= _bfd_get_gp_value (output_bfd); 3660 3661 bfd_put_64 (input_bfd, value + addend, hit_data); 3662 return bfd_reloc_ok; 3663 3664 case R_PARISC_PCREL32: 3665 { 3666 /* If this is a call to a function defined in another dynamic 3667 library, then redirect the call to the local stub for this 3668 function. */ 3669 if (sym_sec == NULL || sym_sec->output_section == NULL) 3670 value = (hh->stub_offset + hppa_info->stub_sec->output_offset 3671 + hppa_info->stub_sec->output_section->vma); 3672 3673 /* Turn VALUE into a proper PC relative address. */ 3674 value -= (offset + input_section->output_offset 3675 + input_section->output_section->vma); 3676 3677 value += addend; 3678 value -= 8; 3679 bfd_put_32 (input_bfd, value, hit_data); 3680 return bfd_reloc_ok; 3681 } 3682 3683 case R_PARISC_PCREL64: 3684 { 3685 /* If this is a call to a function defined in another dynamic 3686 library, then redirect the call to the local stub for this 3687 function. */ 3688 if (sym_sec == NULL || sym_sec->output_section == NULL) 3689 value = (hh->stub_offset + hppa_info->stub_sec->output_offset 3690 + hppa_info->stub_sec->output_section->vma); 3691 3692 /* Turn VALUE into a proper PC relative address. */ 3693 value -= (offset + input_section->output_offset 3694 + input_section->output_section->vma); 3695 3696 value += addend; 3697 value -= 8; 3698 bfd_put_64 (input_bfd, value, hit_data); 3699 return bfd_reloc_ok; 3700 } 3701 3702 case R_PARISC_FPTR64: 3703 { 3704 bfd_vma off; 3705 3706 /* We may still need to create the FPTR itself if it was for 3707 a local symbol. */ 3708 if (hh == NULL) 3709 { 3710 bfd_vma *local_opd_offsets; 3711 3712 if (local_offsets == NULL) 3713 abort (); 3714 3715 local_opd_offsets = local_offsets + 2 * symtab_hdr->sh_info; 3716 off = local_opd_offsets[r_symndx]; 3717 3718 /* The last bit records whether we've already initialised 3719 this local .opd entry. */ 3720 if ((off & 1) != 0) 3721 { 3722 BFD_ASSERT (off != (bfd_vma) -1); 3723 off &= ~1; 3724 } 3725 else 3726 { 3727 /* The first two words of an .opd entry are zero. */ 3728 memset (hppa_info->opd_sec->contents + off, 0, 16); 3729 3730 /* The next word is the address of the function. */ 3731 bfd_put_64 (hppa_info->opd_sec->owner, value + addend, 3732 (hppa_info->opd_sec->contents + off + 16)); 3733 3734 /* The last word is our local __gp value. */ 3735 value = _bfd_get_gp_value 3736 (hppa_info->opd_sec->output_section->owner); 3737 bfd_put_64 (hppa_info->opd_sec->owner, value, 3738 hppa_info->opd_sec->contents + off + 24); 3739 } 3740 } 3741 else 3742 off = hh->opd_offset; 3743 3744 if (hh == NULL || hh->want_opd) 3745 /* We want the value of the OPD offset for this symbol. */ 3746 value = (off 3747 + hppa_info->opd_sec->output_offset 3748 + hppa_info->opd_sec->output_section->vma); 3749 else 3750 /* We want the address of the symbol. */ 3751 value += addend; 3752 3753 bfd_put_64 (input_bfd, value, hit_data); 3754 return bfd_reloc_ok; 3755 } 3756 3757 case R_PARISC_SECREL32: 3758 if (sym_sec) 3759 value -= sym_sec->output_section->vma; 3760 bfd_put_32 (input_bfd, value + addend, hit_data); 3761 return bfd_reloc_ok; 3762 3763 case R_PARISC_SEGREL32: 3764 case R_PARISC_SEGREL64: 3765 { 3766 /* If this is the first SEGREL relocation, then initialize 3767 the segment base values. */ 3768 if (hppa_info->text_segment_base == (bfd_vma) -1) 3769 bfd_map_over_sections (output_bfd, elf_hppa_record_segment_addrs, 3770 hppa_info); 3771 3772 /* VALUE holds the absolute address. We want to include the 3773 addend, then turn it into a segment relative address. 3774 3775 The segment is derived from SYM_SEC. We assume that there are 3776 only two segments of note in the resulting executable/shlib. 3777 A readonly segment (.text) and a readwrite segment (.data). */ 3778 value += addend; 3779 3780 if (sym_sec->flags & SEC_CODE) 3781 value -= hppa_info->text_segment_base; 3782 else 3783 value -= hppa_info->data_segment_base; 3784 3785 if (r_type == R_PARISC_SEGREL32) 3786 bfd_put_32 (input_bfd, value, hit_data); 3787 else 3788 bfd_put_64 (input_bfd, value, hit_data); 3789 return bfd_reloc_ok; 3790 } 3791 3792 /* Something we don't know how to handle. */ 3793 default: 3794 return bfd_reloc_notsupported; 3795 } 3796 3797 /* Update the instruction word. */ 3798 bfd_put_32 (input_bfd, (bfd_vma) insn, hit_data); 3799 return bfd_reloc_ok; 3800 } 3801 3802 /* Relocate an HPPA ELF section. */ 3803 3804 static bfd_boolean 3805 elf64_hppa_relocate_section (bfd *output_bfd, 3806 struct bfd_link_info *info, 3807 bfd *input_bfd, 3808 asection *input_section, 3809 bfd_byte *contents, 3810 Elf_Internal_Rela *relocs, 3811 Elf_Internal_Sym *local_syms, 3812 asection **local_sections) 3813 { 3814 Elf_Internal_Shdr *symtab_hdr; 3815 Elf_Internal_Rela *rel; 3816 Elf_Internal_Rela *relend; 3817 struct elf64_hppa_link_hash_table *hppa_info; 3818 3819 hppa_info = hppa_link_hash_table (info); 3820 if (hppa_info == NULL) 3821 return FALSE; 3822 3823 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; 3824 3825 rel = relocs; 3826 relend = relocs + input_section->reloc_count; 3827 for (; rel < relend; rel++) 3828 { 3829 int r_type; 3830 reloc_howto_type *howto = elf_hppa_howto_table + ELF_R_TYPE (rel->r_info); 3831 unsigned long r_symndx; 3832 struct elf_link_hash_entry *eh; 3833 Elf_Internal_Sym *sym; 3834 asection *sym_sec; 3835 bfd_vma relocation; 3836 bfd_reloc_status_type r; 3837 3838 r_type = ELF_R_TYPE (rel->r_info); 3839 if (r_type < 0 || r_type >= (int) R_PARISC_UNIMPLEMENTED) 3840 { 3841 bfd_set_error (bfd_error_bad_value); 3842 return FALSE; 3843 } 3844 if (r_type == (unsigned int) R_PARISC_GNU_VTENTRY 3845 || r_type == (unsigned int) R_PARISC_GNU_VTINHERIT) 3846 continue; 3847 3848 /* This is a final link. */ 3849 r_symndx = ELF_R_SYM (rel->r_info); 3850 eh = NULL; 3851 sym = NULL; 3852 sym_sec = NULL; 3853 if (r_symndx < symtab_hdr->sh_info) 3854 { 3855 /* This is a local symbol, hh defaults to NULL. */ 3856 sym = local_syms + r_symndx; 3857 sym_sec = local_sections[r_symndx]; 3858 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sym_sec, rel); 3859 } 3860 else 3861 { 3862 /* This is not a local symbol. */ 3863 struct elf_link_hash_entry **sym_hashes = elf_sym_hashes (input_bfd); 3864 3865 /* It seems this can happen with erroneous or unsupported 3866 input (mixing a.out and elf in an archive, for example.) */ 3867 if (sym_hashes == NULL) 3868 return FALSE; 3869 3870 eh = sym_hashes[r_symndx - symtab_hdr->sh_info]; 3871 3872 if (info->wrap_hash != NULL 3873 && (input_section->flags & SEC_DEBUGGING) != 0) 3874 eh = ((struct elf_link_hash_entry *) 3875 unwrap_hash_lookup (info, input_bfd, &eh->root)); 3876 3877 while (eh->root.type == bfd_link_hash_indirect 3878 || eh->root.type == bfd_link_hash_warning) 3879 eh = (struct elf_link_hash_entry *) eh->root.u.i.link; 3880 3881 relocation = 0; 3882 if (eh->root.type == bfd_link_hash_defined 3883 || eh->root.type == bfd_link_hash_defweak) 3884 { 3885 sym_sec = eh->root.u.def.section; 3886 if (sym_sec != NULL 3887 && sym_sec->output_section != NULL) 3888 relocation = (eh->root.u.def.value 3889 + sym_sec->output_section->vma 3890 + sym_sec->output_offset); 3891 } 3892 else if (eh->root.type == bfd_link_hash_undefweak) 3893 ; 3894 else if (info->unresolved_syms_in_objects == RM_IGNORE 3895 && ELF_ST_VISIBILITY (eh->other) == STV_DEFAULT) 3896 ; 3897 else if (!info->relocatable 3898 && elf_hppa_is_dynamic_loader_symbol (eh->root.root.string)) 3899 continue; 3900 else if (!info->relocatable) 3901 { 3902 bfd_boolean err; 3903 err = (info->unresolved_syms_in_objects == RM_GENERATE_ERROR 3904 || ELF_ST_VISIBILITY (eh->other) != STV_DEFAULT); 3905 if (!info->callbacks->undefined_symbol (info, 3906 eh->root.root.string, 3907 input_bfd, 3908 input_section, 3909 rel->r_offset, err)) 3910 return FALSE; 3911 } 3912 3913 if (!info->relocatable 3914 && relocation == 0 3915 && eh->root.type != bfd_link_hash_defined 3916 && eh->root.type != bfd_link_hash_defweak 3917 && eh->root.type != bfd_link_hash_undefweak) 3918 { 3919 if (info->unresolved_syms_in_objects == RM_IGNORE 3920 && ELF_ST_VISIBILITY (eh->other) == STV_DEFAULT 3921 && eh->type == STT_PARISC_MILLI) 3922 { 3923 if (! info->callbacks->undefined_symbol 3924 (info, eh_name (eh), input_bfd, 3925 input_section, rel->r_offset, FALSE)) 3926 return FALSE; 3927 } 3928 } 3929 } 3930 3931 if (sym_sec != NULL && discarded_section (sym_sec)) 3932 RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section, 3933 rel, 1, relend, howto, 0, contents); 3934 3935 if (info->relocatable) 3936 continue; 3937 3938 r = elf_hppa_final_link_relocate (rel, input_bfd, output_bfd, 3939 input_section, contents, 3940 relocation, info, sym_sec, 3941 eh); 3942 3943 if (r != bfd_reloc_ok) 3944 { 3945 switch (r) 3946 { 3947 default: 3948 abort (); 3949 case bfd_reloc_overflow: 3950 { 3951 const char *sym_name; 3952 3953 if (eh != NULL) 3954 sym_name = NULL; 3955 else 3956 { 3957 sym_name = bfd_elf_string_from_elf_section (input_bfd, 3958 symtab_hdr->sh_link, 3959 sym->st_name); 3960 if (sym_name == NULL) 3961 return FALSE; 3962 if (*sym_name == '\0') 3963 sym_name = bfd_section_name (input_bfd, sym_sec); 3964 } 3965 3966 if (!((*info->callbacks->reloc_overflow) 3967 (info, (eh ? &eh->root : NULL), sym_name, 3968 howto->name, (bfd_vma) 0, input_bfd, 3969 input_section, rel->r_offset))) 3970 return FALSE; 3971 } 3972 break; 3973 } 3974 } 3975 } 3976 return TRUE; 3977 } 3978 3979 static const struct bfd_elf_special_section elf64_hppa_special_sections[] = 3980 { 3981 { STRING_COMMA_LEN (".fini"), 0, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE }, 3982 { STRING_COMMA_LEN (".init"), 0, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE }, 3983 { STRING_COMMA_LEN (".plt"), 0, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE + SHF_PARISC_SHORT }, 3984 { STRING_COMMA_LEN (".dlt"), 0, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE + SHF_PARISC_SHORT }, 3985 { STRING_COMMA_LEN (".sdata"), 0, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE + SHF_PARISC_SHORT }, 3986 { STRING_COMMA_LEN (".sbss"), 0, SHT_NOBITS, SHF_ALLOC + SHF_WRITE + SHF_PARISC_SHORT }, 3987 { STRING_COMMA_LEN (".tbss"), 0, SHT_NOBITS, SHF_ALLOC + SHF_WRITE + SHF_HP_TLS }, 3988 { NULL, 0, 0, 0, 0 } 3989 }; 3990 3991 /* The hash bucket size is the standard one, namely 4. */ 3992 3993 const struct elf_size_info hppa64_elf_size_info = 3994 { 3995 sizeof (Elf64_External_Ehdr), 3996 sizeof (Elf64_External_Phdr), 3997 sizeof (Elf64_External_Shdr), 3998 sizeof (Elf64_External_Rel), 3999 sizeof (Elf64_External_Rela), 4000 sizeof (Elf64_External_Sym), 4001 sizeof (Elf64_External_Dyn), 4002 sizeof (Elf_External_Note), 4003 4, 4004 1, 4005 64, 3, 4006 ELFCLASS64, EV_CURRENT, 4007 bfd_elf64_write_out_phdrs, 4008 bfd_elf64_write_shdrs_and_ehdr, 4009 bfd_elf64_checksum_contents, 4010 bfd_elf64_write_relocs, 4011 bfd_elf64_swap_symbol_in, 4012 bfd_elf64_swap_symbol_out, 4013 bfd_elf64_slurp_reloc_table, 4014 bfd_elf64_slurp_symbol_table, 4015 bfd_elf64_swap_dyn_in, 4016 bfd_elf64_swap_dyn_out, 4017 bfd_elf64_swap_reloc_in, 4018 bfd_elf64_swap_reloc_out, 4019 bfd_elf64_swap_reloca_in, 4020 bfd_elf64_swap_reloca_out 4021 }; 4022 4023 #define TARGET_BIG_SYM hppa_elf64_vec 4024 #define TARGET_BIG_NAME "elf64-hppa" 4025 #define ELF_ARCH bfd_arch_hppa 4026 #define ELF_TARGET_ID HPPA64_ELF_DATA 4027 #define ELF_MACHINE_CODE EM_PARISC 4028 /* This is not strictly correct. The maximum page size for PA2.0 is 4029 64M. But everything still uses 4k. */ 4030 #define ELF_MAXPAGESIZE 0x1000 4031 #define ELF_OSABI ELFOSABI_HPUX 4032 4033 #define bfd_elf64_bfd_reloc_type_lookup elf_hppa_reloc_type_lookup 4034 #define bfd_elf64_bfd_reloc_name_lookup elf_hppa_reloc_name_lookup 4035 #define bfd_elf64_bfd_is_local_label_name elf_hppa_is_local_label_name 4036 #define elf_info_to_howto elf_hppa_info_to_howto 4037 #define elf_info_to_howto_rel elf_hppa_info_to_howto_rel 4038 4039 #define elf_backend_section_from_shdr elf64_hppa_section_from_shdr 4040 #define elf_backend_object_p elf64_hppa_object_p 4041 #define elf_backend_final_write_processing \ 4042 elf_hppa_final_write_processing 4043 #define elf_backend_fake_sections elf_hppa_fake_sections 4044 #define elf_backend_add_symbol_hook elf_hppa_add_symbol_hook 4045 4046 #define elf_backend_relocate_section elf_hppa_relocate_section 4047 4048 #define bfd_elf64_bfd_final_link elf_hppa_final_link 4049 4050 #define elf_backend_create_dynamic_sections \ 4051 elf64_hppa_create_dynamic_sections 4052 #define elf_backend_post_process_headers elf64_hppa_post_process_headers 4053 4054 #define elf_backend_omit_section_dynsym \ 4055 ((bfd_boolean (*) (bfd *, struct bfd_link_info *, asection *)) bfd_true) 4056 #define elf_backend_adjust_dynamic_symbol \ 4057 elf64_hppa_adjust_dynamic_symbol 4058 4059 #define elf_backend_size_dynamic_sections \ 4060 elf64_hppa_size_dynamic_sections 4061 4062 #define elf_backend_finish_dynamic_symbol \ 4063 elf64_hppa_finish_dynamic_symbol 4064 #define elf_backend_finish_dynamic_sections \ 4065 elf64_hppa_finish_dynamic_sections 4066 #define elf_backend_grok_prstatus elf64_hppa_grok_prstatus 4067 #define elf_backend_grok_psinfo elf64_hppa_grok_psinfo 4068 4069 /* Stuff for the BFD linker: */ 4070 #define bfd_elf64_bfd_link_hash_table_create \ 4071 elf64_hppa_hash_table_create 4072 4073 #define elf_backend_check_relocs \ 4074 elf64_hppa_check_relocs 4075 4076 #define elf_backend_size_info \ 4077 hppa64_elf_size_info 4078 4079 #define elf_backend_additional_program_headers \ 4080 elf64_hppa_additional_program_headers 4081 4082 #define elf_backend_modify_segment_map \ 4083 elf64_hppa_modify_segment_map 4084 4085 #define elf_backend_link_output_symbol_hook \ 4086 elf64_hppa_link_output_symbol_hook 4087 4088 #define elf_backend_want_got_plt 0 4089 #define elf_backend_plt_readonly 0 4090 #define elf_backend_want_plt_sym 0 4091 #define elf_backend_got_header_size 0 4092 #define elf_backend_type_change_ok TRUE 4093 #define elf_backend_get_symbol_type elf64_hppa_elf_get_symbol_type 4094 #define elf_backend_reloc_type_class elf64_hppa_reloc_type_class 4095 #define elf_backend_rela_normal 1 4096 #define elf_backend_special_sections elf64_hppa_special_sections 4097 #define elf_backend_action_discarded elf_hppa_action_discarded 4098 #define elf_backend_section_from_phdr elf64_hppa_section_from_phdr 4099 4100 #define elf64_bed elf64_hppa_hpux_bed 4101 4102 #include "elf64-target.h" 4103 4104 #undef TARGET_BIG_SYM 4105 #define TARGET_BIG_SYM hppa_elf64_linux_vec 4106 #undef TARGET_BIG_NAME 4107 #define TARGET_BIG_NAME "elf64-hppa-linux" 4108 #undef ELF_OSABI 4109 #define ELF_OSABI ELFOSABI_GNU 4110 #undef elf64_bed 4111 #define elf64_bed elf64_hppa_linux_bed 4112 4113 #include "elf64-target.h" 4114