1 /* VAX series support for 32-bit ELF 2 Copyright 1993, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 3 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 4 Free Software Foundation, Inc. 5 Contributed by Matt Thomas <matt@3am-software.com>. 6 7 This file is part of BFD, the Binary File Descriptor library. 8 9 This program is free software; you can redistribute it and/or modify 10 it under the terms of the GNU General Public License as published by 11 the Free Software Foundation; either version 3 of the License, or 12 (at your option) any later version. 13 14 This program is distributed in the hope that it will be useful, 15 but WITHOUT ANY WARRANTY; without even the implied warranty of 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 GNU General Public License for more details. 18 19 You should have received a copy of the GNU General Public License 20 along with this program; if not, write to the Free Software 21 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, 22 MA 02110-1301, USA. */ 23 24 #include "sysdep.h" 25 #include "bfd.h" 26 #include "bfdlink.h" 27 #include "libbfd.h" 28 #include "elf-bfd.h" 29 #include "elf/vax.h" 30 31 static reloc_howto_type *reloc_type_lookup (bfd *, bfd_reloc_code_real_type); 32 static void rtype_to_howto (bfd *, arelent *, Elf_Internal_Rela *); 33 static struct bfd_hash_entry *elf_vax_link_hash_newfunc (struct bfd_hash_entry *, 34 struct bfd_hash_table *, 35 const char *); 36 static struct bfd_link_hash_table *elf_vax_link_hash_table_create (bfd *); 37 static bfd_boolean elf_vax_check_relocs (bfd *, struct bfd_link_info *, 38 asection *, const Elf_Internal_Rela *); 39 static bfd_boolean elf_vax_adjust_dynamic_symbol (struct bfd_link_info *, 40 struct elf_link_hash_entry *); 41 static bfd_boolean elf_vax_size_dynamic_sections (bfd *, struct bfd_link_info *); 42 static bfd_boolean elf_vax_relocate_section (bfd *, struct bfd_link_info *, 43 bfd *, asection *, bfd_byte *, 44 Elf_Internal_Rela *, 45 Elf_Internal_Sym *, asection **); 46 static bfd_boolean elf_vax_finish_dynamic_symbol (bfd *, struct bfd_link_info *, 47 struct elf_link_hash_entry *, 48 Elf_Internal_Sym *); 49 static bfd_boolean elf_vax_finish_dynamic_sections (bfd *, 50 struct bfd_link_info *); 51 static bfd_vma elf_vax_plt_sym_val (bfd_vma, const asection *, 52 const arelent *); 53 54 static bfd_boolean elf32_vax_set_private_flags (bfd *, flagword); 55 static bfd_boolean elf32_vax_merge_private_bfd_data (bfd *, bfd *); 56 static bfd_boolean elf32_vax_print_private_bfd_data (bfd *, void *); 57 58 static reloc_howto_type howto_table[] = { 59 HOWTO (R_VAX_NONE, /* type */ 60 0, /* rightshift */ 61 0, /* size (0 = byte, 1 = short, 2 = long) */ 62 0, /* bitsize */ 63 FALSE, /* pc_relative */ 64 0, /* bitpos */ 65 complain_overflow_dont, /* complain_on_overflow */ 66 bfd_elf_generic_reloc, /* special_function */ 67 "R_VAX_NONE", /* name */ 68 FALSE, /* partial_inplace */ 69 0, /* src_mask */ 70 0x00000000, /* dst_mask */ 71 FALSE), /* pcrel_offset */ 72 73 HOWTO (R_VAX_32, /* type */ 74 0, /* rightshift */ 75 2, /* size (0 = byte, 1 = short, 2 = long) */ 76 32, /* bitsize */ 77 FALSE, /* pc_relative */ 78 0, /* bitpos */ 79 complain_overflow_bitfield, /* complain_on_overflow */ 80 bfd_elf_generic_reloc, /* special_function */ 81 "R_VAX_32", /* name */ 82 FALSE, /* partial_inplace */ 83 0, /* src_mask */ 84 0xffffffff, /* dst_mask */ 85 FALSE), /* pcrel_offset */ 86 87 HOWTO (R_VAX_16, /* type */ 88 0, /* rightshift */ 89 1, /* size (0 = byte, 1 = short, 2 = long) */ 90 16, /* bitsize */ 91 FALSE, /* pc_relative */ 92 0, /* bitpos */ 93 complain_overflow_bitfield, /* complain_on_overflow */ 94 bfd_elf_generic_reloc, /* special_function */ 95 "R_VAX_16", /* name */ 96 FALSE, /* partial_inplace */ 97 0, /* src_mask */ 98 0x0000ffff, /* dst_mask */ 99 FALSE), /* pcrel_offset */ 100 101 HOWTO (R_VAX_8, /* type */ 102 0, /* rightshift */ 103 0, /* size (0 = byte, 1 = short, 2 = long) */ 104 8, /* bitsize */ 105 FALSE, /* pc_relative */ 106 0, /* bitpos */ 107 complain_overflow_bitfield, /* complain_on_overflow */ 108 bfd_elf_generic_reloc, /* special_function */ 109 "R_VAX_8", /* name */ 110 FALSE, /* partial_inplace */ 111 0, /* src_mask */ 112 0x000000ff, /* dst_mask */ 113 FALSE), /* pcrel_offset */ 114 115 HOWTO (R_VAX_PC32, /* type */ 116 0, /* rightshift */ 117 2, /* size (0 = byte, 1 = short, 2 = long) */ 118 32, /* bitsize */ 119 TRUE, /* pc_relative */ 120 0, /* bitpos */ 121 complain_overflow_bitfield, /* complain_on_overflow */ 122 bfd_elf_generic_reloc, /* special_function */ 123 "R_VAX_PC32", /* name */ 124 FALSE, /* partial_inplace */ 125 0, /* src_mask */ 126 0xffffffff, /* dst_mask */ 127 TRUE), /* pcrel_offset */ 128 129 HOWTO (R_VAX_PC16, /* type */ 130 0, /* rightshift */ 131 1, /* size (0 = byte, 1 = short, 2 = long) */ 132 16, /* bitsize */ 133 TRUE, /* pc_relative */ 134 0, /* bitpos */ 135 complain_overflow_signed, /* complain_on_overflow */ 136 bfd_elf_generic_reloc, /* special_function */ 137 "R_VAX_PC16", /* name */ 138 FALSE, /* partial_inplace */ 139 0, /* src_mask */ 140 0x0000ffff, /* dst_mask */ 141 TRUE), /* pcrel_offset */ 142 143 HOWTO (R_VAX_PC8, /* type */ 144 0, /* rightshift */ 145 0, /* size (0 = byte, 1 = short, 2 = long) */ 146 8, /* bitsize */ 147 TRUE, /* pc_relative */ 148 0, /* bitpos */ 149 complain_overflow_signed, /* complain_on_overflow */ 150 bfd_elf_generic_reloc, /* special_function */ 151 "R_VAX_PC8", /* name */ 152 FALSE, /* partial_inplace */ 153 0, /* src_mask */ 154 0x000000ff, /* dst_mask */ 155 TRUE), /* pcrel_offset */ 156 157 HOWTO (R_VAX_GOT32, /* type */ 158 0, /* rightshift */ 159 2, /* size (0 = byte, 1 = short, 2 = long) */ 160 32, /* bitsize */ 161 TRUE, /* pc_relative */ 162 0, /* bitpos */ 163 complain_overflow_bitfield, /* complain_on_overflow */ 164 bfd_elf_generic_reloc, /* special_function */ 165 "R_VAX_GOT32", /* name */ 166 FALSE, /* partial_inplace */ 167 0, /* src_mask */ 168 0xffffffff, /* dst_mask */ 169 TRUE), /* pcrel_offset */ 170 171 EMPTY_HOWTO (-1), 172 EMPTY_HOWTO (-1), 173 EMPTY_HOWTO (-1), 174 EMPTY_HOWTO (-1), 175 EMPTY_HOWTO (-1), 176 177 HOWTO (R_VAX_PLT32, /* type */ 178 0, /* rightshift */ 179 2, /* size (0 = byte, 1 = short, 2 = long) */ 180 32, /* bitsize */ 181 TRUE, /* pc_relative */ 182 0, /* bitpos */ 183 complain_overflow_bitfield, /* complain_on_overflow */ 184 bfd_elf_generic_reloc, /* special_function */ 185 "R_VAX_PLT32", /* name */ 186 FALSE, /* partial_inplace */ 187 0, /* src_mask */ 188 0xffffffff, /* dst_mask */ 189 TRUE), /* pcrel_offset */ 190 191 EMPTY_HOWTO (-1), 192 EMPTY_HOWTO (-1), 193 EMPTY_HOWTO (-1), 194 EMPTY_HOWTO (-1), 195 EMPTY_HOWTO (-1), 196 197 HOWTO (R_VAX_COPY, /* type */ 198 0, /* rightshift */ 199 0, /* size (0 = byte, 1 = short, 2 = long) */ 200 0, /* bitsize */ 201 FALSE, /* pc_relative */ 202 0, /* bitpos */ 203 complain_overflow_dont, /* complain_on_overflow */ 204 bfd_elf_generic_reloc, /* special_function */ 205 "R_VAX_COPY", /* name */ 206 FALSE, /* partial_inplace */ 207 0, /* src_mask */ 208 0xffffffff, /* dst_mask */ 209 FALSE), /* pcrel_offset */ 210 211 HOWTO (R_VAX_GLOB_DAT, /* type */ 212 0, /* rightshift */ 213 2, /* size (0 = byte, 1 = short, 2 = long) */ 214 32, /* bitsize */ 215 FALSE, /* pc_relative */ 216 0, /* bitpos */ 217 complain_overflow_dont, /* complain_on_overflow */ 218 bfd_elf_generic_reloc, /* special_function */ 219 "R_VAX_GLOB_DAT", /* name */ 220 FALSE, /* partial_inplace */ 221 0, /* src_mask */ 222 0xffffffff, /* dst_mask */ 223 FALSE), /* pcrel_offset */ 224 225 HOWTO (R_VAX_JMP_SLOT, /* type */ 226 0, /* rightshift */ 227 2, /* size (0 = byte, 1 = short, 2 = long) */ 228 32, /* bitsize */ 229 FALSE, /* pc_relative */ 230 0, /* bitpos */ 231 complain_overflow_dont, /* complain_on_overflow */ 232 bfd_elf_generic_reloc, /* special_function */ 233 "R_VAX_JMP_SLOT", /* name */ 234 FALSE, /* partial_inplace */ 235 0, /* src_mask */ 236 0xffffffff, /* dst_mask */ 237 FALSE), /* pcrel_offset */ 238 239 HOWTO (R_VAX_RELATIVE, /* type */ 240 0, /* rightshift */ 241 2, /* size (0 = byte, 1 = short, 2 = long) */ 242 32, /* bitsize */ 243 FALSE, /* pc_relative */ 244 0, /* bitpos */ 245 complain_overflow_dont, /* complain_on_overflow */ 246 bfd_elf_generic_reloc, /* special_function */ 247 "R_VAX_RELATIVE", /* name */ 248 FALSE, /* partial_inplace */ 249 0, /* src_mask */ 250 0xffffffff, /* dst_mask */ 251 FALSE), /* pcrel_offset */ 252 253 /* GNU extension to record C++ vtable hierarchy */ 254 HOWTO (R_VAX_GNU_VTINHERIT, /* type */ 255 0, /* rightshift */ 256 2, /* size (0 = byte, 1 = short, 2 = long) */ 257 0, /* bitsize */ 258 FALSE, /* pc_relative */ 259 0, /* bitpos */ 260 complain_overflow_dont, /* complain_on_overflow */ 261 NULL, /* special_function */ 262 "R_VAX_GNU_VTINHERIT", /* name */ 263 FALSE, /* partial_inplace */ 264 0, /* src_mask */ 265 0, /* dst_mask */ 266 FALSE), /* pcrel_offset */ 267 268 /* GNU extension to record C++ vtable member usage */ 269 HOWTO (R_VAX_GNU_VTENTRY, /* type */ 270 0, /* rightshift */ 271 2, /* size (0 = byte, 1 = short, 2 = long) */ 272 0, /* bitsize */ 273 FALSE, /* pc_relative */ 274 0, /* bitpos */ 275 complain_overflow_dont, /* complain_on_overflow */ 276 _bfd_elf_rel_vtable_reloc_fn, /* special_function */ 277 "R_VAX_GNU_VTENTRY", /* name */ 278 FALSE, /* partial_inplace */ 279 0, /* src_mask */ 280 0, /* dst_mask */ 281 FALSE), /* pcrel_offset */ 282 }; 283 284 static void 285 rtype_to_howto (bfd *abfd ATTRIBUTE_UNUSED, arelent *cache_ptr, 286 Elf_Internal_Rela *dst) 287 { 288 BFD_ASSERT (ELF32_R_TYPE(dst->r_info) < (unsigned int) R_VAX_max); 289 cache_ptr->howto = &howto_table[ELF32_R_TYPE(dst->r_info)]; 290 } 291 292 #define elf_info_to_howto rtype_to_howto 293 294 static const struct 295 { 296 bfd_reloc_code_real_type bfd_val; 297 int elf_val; 298 } reloc_map[] = { 299 { BFD_RELOC_NONE, R_VAX_NONE }, 300 { BFD_RELOC_32, R_VAX_32 }, 301 { BFD_RELOC_16, R_VAX_16 }, 302 { BFD_RELOC_8, R_VAX_8 }, 303 { BFD_RELOC_32_PCREL, R_VAX_PC32 }, 304 { BFD_RELOC_16_PCREL, R_VAX_PC16 }, 305 { BFD_RELOC_8_PCREL, R_VAX_PC8 }, 306 { BFD_RELOC_32_GOT_PCREL, R_VAX_GOT32 }, 307 { BFD_RELOC_32_PLT_PCREL, R_VAX_PLT32 }, 308 { BFD_RELOC_NONE, R_VAX_COPY }, 309 { BFD_RELOC_VAX_GLOB_DAT, R_VAX_GLOB_DAT }, 310 { BFD_RELOC_VAX_JMP_SLOT, R_VAX_JMP_SLOT }, 311 { BFD_RELOC_VAX_RELATIVE, R_VAX_RELATIVE }, 312 { BFD_RELOC_CTOR, R_VAX_32 }, 313 { BFD_RELOC_VTABLE_INHERIT, R_VAX_GNU_VTINHERIT }, 314 { BFD_RELOC_VTABLE_ENTRY, R_VAX_GNU_VTENTRY }, 315 }; 316 317 static reloc_howto_type * 318 reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED, bfd_reloc_code_real_type code) 319 { 320 unsigned int i; 321 for (i = 0; i < sizeof (reloc_map) / sizeof (reloc_map[0]); i++) 322 { 323 if (reloc_map[i].bfd_val == code) 324 return &howto_table[reloc_map[i].elf_val]; 325 } 326 return 0; 327 } 328 329 static reloc_howto_type * 330 reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, 331 const char *r_name) 332 { 333 unsigned int i; 334 335 for (i = 0; i < sizeof (howto_table) / sizeof (howto_table[0]); i++) 336 if (howto_table[i].name != NULL 337 && strcasecmp (howto_table[i].name, r_name) == 0) 338 return &howto_table[i]; 339 340 return NULL; 341 } 342 343 #define bfd_elf32_bfd_reloc_type_lookup reloc_type_lookup 344 #define bfd_elf32_bfd_reloc_name_lookup reloc_name_lookup 345 #define ELF_ARCH bfd_arch_vax 346 /* end code generated by elf.el */ 347 348 /* Functions for the VAX ELF linker. */ 349 350 /* The name of the dynamic interpreter. This is put in the .interp 351 section. */ 352 353 #define ELF_DYNAMIC_INTERPRETER "/usr/libexec/ld.elf_so" 354 355 /* The size in bytes of an entry in the procedure linkage table. */ 356 357 #define PLT_ENTRY_SIZE 12 358 359 /* The first entry in a procedure linkage table looks like this. See 360 the SVR4 ABI VAX supplement to see how this works. */ 361 362 static const bfd_byte elf_vax_plt0_entry[PLT_ENTRY_SIZE] = 363 { 364 0xdd, 0xef, /* pushl l^ */ 365 0, 0, 0, 0, /* offset to .plt.got + 4 */ 366 0x17, 0xff, /* jmp @L^(pc) */ 367 0, 0, 0, 0, /* offset to .plt.got + 8 */ 368 }; 369 370 /* Subsequent entries in a procedure linkage table look like this. */ 371 372 static const bfd_byte elf_vax_plt_entry[PLT_ENTRY_SIZE] = 373 { 374 0xfc, 0x0f, /* .word ^M<r11:r2> */ 375 0x16, 0xef, /* jsb L^(pc) */ 376 0, 0, 0, 0, /* replaced with offset to start of .plt */ 377 0, 0, 0, 0, /* index into .rela.plt */ 378 }; 379 380 /* The VAX linker needs to keep track of the number of relocs that it 381 decides to copy in check_relocs for each symbol. This is so that it 382 can discard PC relative relocs if it doesn't need them when linking 383 with -Bsymbolic. We store the information in a field extending the 384 regular ELF linker hash table. */ 385 386 /* This structure keeps track of the number of PC relative relocs we have 387 copied for a given symbol. */ 388 389 struct elf_vax_pcrel_relocs_copied 390 { 391 /* Next section. */ 392 struct elf_vax_pcrel_relocs_copied *next; 393 /* A section in dynobj. */ 394 asection *section; 395 /* Number of relocs copied in this section. */ 396 bfd_size_type count; 397 }; 398 399 /* VAX ELF linker hash entry. */ 400 401 struct elf_vax_link_hash_entry 402 { 403 struct elf_link_hash_entry root; 404 405 /* Number of PC relative relocs copied for this symbol. */ 406 struct elf_vax_pcrel_relocs_copied *pcrel_relocs_copied; 407 408 bfd_vma got_addend; 409 }; 410 411 /* Declare this now that the above structures are defined. */ 412 413 static bfd_boolean elf_vax_discard_copies (struct elf_vax_link_hash_entry *, 414 void *); 415 416 /* Declare this now that the above structures are defined. */ 417 418 static bfd_boolean elf_vax_instantiate_got_entries (struct elf_link_hash_entry *, 419 void *); 420 421 /* Traverse an VAX ELF linker hash table. */ 422 423 #define elf_vax_link_hash_traverse(table, func, info) \ 424 (elf_link_hash_traverse \ 425 ((table), \ 426 (bfd_boolean (*) (struct elf_link_hash_entry *, void *)) (func), \ 427 (info))) 428 429 /* Create an entry in an VAX ELF linker hash table. */ 430 431 static struct bfd_hash_entry * 432 elf_vax_link_hash_newfunc (struct bfd_hash_entry *entry, 433 struct bfd_hash_table *table, 434 const char *string) 435 { 436 struct elf_vax_link_hash_entry *ret = 437 (struct elf_vax_link_hash_entry *) entry; 438 439 /* Allocate the structure if it has not already been allocated by a 440 subclass. */ 441 if (ret == NULL) 442 ret = ((struct elf_vax_link_hash_entry *) 443 bfd_hash_allocate (table, 444 sizeof (struct elf_vax_link_hash_entry))); 445 if (ret == NULL) 446 return (struct bfd_hash_entry *) ret; 447 448 /* Call the allocation method of the superclass. */ 449 ret = ((struct elf_vax_link_hash_entry *) 450 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret, 451 table, string)); 452 if (ret != NULL) 453 { 454 ret->pcrel_relocs_copied = NULL; 455 } 456 457 return (struct bfd_hash_entry *) ret; 458 } 459 460 /* Create an VAX ELF linker hash table. */ 461 462 static struct bfd_link_hash_table * 463 elf_vax_link_hash_table_create (bfd *abfd) 464 { 465 struct elf_link_hash_table *ret; 466 bfd_size_type amt = sizeof (struct elf_link_hash_table); 467 468 ret = bfd_malloc (amt); 469 if (ret == NULL) 470 return NULL; 471 472 if (!_bfd_elf_link_hash_table_init (ret, abfd, 473 elf_vax_link_hash_newfunc, 474 sizeof (struct elf_vax_link_hash_entry), 475 GENERIC_ELF_DATA)) 476 { 477 free (ret); 478 return NULL; 479 } 480 481 return &ret->root; 482 } 483 484 /* Keep vax-specific flags in the ELF header */ 485 static bfd_boolean 486 elf32_vax_set_private_flags (bfd *abfd, flagword flags) 487 { 488 elf_elfheader (abfd)->e_flags = flags; 489 elf_flags_init (abfd) = TRUE; 490 return TRUE; 491 } 492 493 /* Copy vax-specific data from one module to another */ 494 static bfd_boolean 495 elf32_vax_copy_private_bfd_data (bfd *ibfd, bfd *obfd) 496 { 497 flagword in_flags; 498 499 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour 500 || bfd_get_flavour (obfd) != bfd_target_elf_flavour) 501 return TRUE; 502 503 in_flags = elf_elfheader (ibfd)->e_flags; 504 505 elf_elfheader (obfd)->e_flags = in_flags; 506 elf_flags_init (obfd) = TRUE; 507 508 return TRUE; 509 } 510 511 /* Merge backend specific data from an object file to the output 512 object file when linking. */ 513 static bfd_boolean 514 elf32_vax_merge_private_bfd_data (bfd *ibfd, bfd *obfd) 515 { 516 flagword in_flags; 517 518 if ( bfd_get_flavour (ibfd) != bfd_target_elf_flavour 519 || bfd_get_flavour (obfd) != bfd_target_elf_flavour) 520 return TRUE; 521 522 in_flags = elf_elfheader (ibfd)->e_flags; 523 524 if (!elf_flags_init (obfd)) 525 { 526 elf_flags_init (obfd) = TRUE; 527 elf_elfheader (obfd)->e_flags = in_flags; 528 } 529 530 return TRUE; 531 } 532 533 /* Display the flags field */ 534 static bfd_boolean 535 elf32_vax_print_private_bfd_data (bfd *abfd, void * ptr) 536 { 537 FILE *file = (FILE *) ptr; 538 539 BFD_ASSERT (abfd != NULL && ptr != NULL); 540 541 /* Print normal ELF private data. */ 542 _bfd_elf_print_private_bfd_data (abfd, ptr); 543 544 /* Ignore init flag - it may not be set, despite the flags field containing valid data. */ 545 546 /* xgettext:c-format */ 547 fprintf (file, _("private flags = %lx:"), elf_elfheader (abfd)->e_flags); 548 549 if (elf_elfheader (abfd)->e_flags & EF_VAX_NONPIC) 550 fprintf (file, _(" [nonpic]")); 551 552 if (elf_elfheader (abfd)->e_flags & EF_VAX_DFLOAT) 553 fprintf (file, _(" [d-float]")); 554 555 if (elf_elfheader (abfd)->e_flags & EF_VAX_GFLOAT) 556 fprintf (file, _(" [g-float]")); 557 558 fputc ('\n', file); 559 560 return TRUE; 561 } 562 /* Look through the relocs for a section during the first phase, and 563 allocate space in the global offset table or procedure linkage 564 table. */ 565 566 static bfd_boolean 567 elf_vax_check_relocs (bfd *abfd, struct bfd_link_info *info, asection *sec, 568 const Elf_Internal_Rela *relocs) 569 { 570 bfd *dynobj; 571 Elf_Internal_Shdr *symtab_hdr; 572 struct elf_link_hash_entry **sym_hashes; 573 const Elf_Internal_Rela *rel; 574 const Elf_Internal_Rela *rel_end; 575 asection *sgot; 576 asection *srelgot; 577 asection *sreloc; 578 579 if (info->relocatable) 580 return TRUE; 581 582 dynobj = elf_hash_table (info)->dynobj; 583 symtab_hdr = &elf_tdata (abfd)->symtab_hdr; 584 sym_hashes = elf_sym_hashes (abfd); 585 586 sgot = NULL; 587 srelgot = NULL; 588 sreloc = NULL; 589 590 rel_end = relocs + sec->reloc_count; 591 for (rel = relocs; rel < rel_end; rel++) 592 { 593 unsigned long r_symndx; 594 struct elf_link_hash_entry *h; 595 596 r_symndx = ELF32_R_SYM (rel->r_info); 597 598 if (r_symndx < symtab_hdr->sh_info) 599 h = NULL; 600 else 601 { 602 h = sym_hashes[r_symndx - symtab_hdr->sh_info]; 603 while (h->root.type == bfd_link_hash_indirect 604 || h->root.type == bfd_link_hash_warning) 605 h = (struct elf_link_hash_entry *) h->root.u.i.link; 606 } 607 608 switch (ELF32_R_TYPE (rel->r_info)) 609 { 610 case R_VAX_GOT32: 611 BFD_ASSERT (h != NULL); 612 if (h->forced_local 613 || h == elf_hash_table (info)->hgot 614 || h == elf_hash_table (info)->hplt) 615 break; 616 617 /* If this is a local symbol, we resolve it directly without 618 creating a global offset table entry. */ 619 if (h == NULL || ELF_ST_VISIBILITY (h->other) != STV_DEFAULT) 620 break; 621 622 /* This symbol requires a global offset table entry. */ 623 624 if (dynobj == NULL) 625 { 626 /* Create the .got section. */ 627 elf_hash_table (info)->dynobj = dynobj = abfd; 628 if (!_bfd_elf_create_got_section (dynobj, info)) 629 return FALSE; 630 } 631 632 if (sgot == NULL) 633 { 634 sgot = bfd_get_linker_section (dynobj, ".got"); 635 BFD_ASSERT (sgot != NULL); 636 } 637 638 if (srelgot == NULL 639 && (h != NULL || info->shared)) 640 { 641 srelgot = bfd_get_linker_section (dynobj, ".rela.got"); 642 if (srelgot == NULL) 643 { 644 flagword flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS 645 | SEC_IN_MEMORY | SEC_LINKER_CREATED 646 | SEC_READONLY); 647 648 srelgot = bfd_make_section_anyway_with_flags (dynobj, 649 ".rela.got", 650 flags); 651 if (srelgot == NULL 652 || !bfd_set_section_alignment (dynobj, srelgot, 2)) 653 return FALSE; 654 } 655 } 656 657 if (h != NULL) 658 { 659 struct elf_vax_link_hash_entry *eh; 660 661 eh = (struct elf_vax_link_hash_entry *) h; 662 if (h->got.refcount == -1) 663 { 664 h->got.refcount = 1; 665 eh->got_addend = rel->r_addend; 666 } 667 else 668 { 669 h->got.refcount++; 670 if (eh->got_addend != (bfd_vma) rel->r_addend) 671 (*_bfd_error_handler) 672 (_("%s: warning: GOT addend of %ld to `%s' does" 673 " not match previous GOT addend of %ld"), 674 bfd_get_filename (abfd), rel->r_addend, 675 h->root.root.string, 676 eh->got_addend); 677 678 } 679 } 680 break; 681 682 case R_VAX_PLT32: 683 /* This symbol requires a procedure linkage table entry. We 684 actually build the entry in adjust_dynamic_symbol, 685 because this might be a case of linking PIC code which is 686 never referenced by a dynamic object, in which case we 687 don't need to generate a procedure linkage table entry 688 after all. */ 689 690 /* If this is a local symbol, we resolve it directly without 691 creating a procedure linkage table entry. */ 692 BFD_ASSERT (h != NULL); 693 if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT || h->forced_local) 694 break; 695 696 h->needs_plt = 1; 697 if (h->plt.refcount == -1) 698 h->plt.refcount = 1; 699 else 700 h->plt.refcount++; 701 break; 702 703 case R_VAX_PC8: 704 case R_VAX_PC16: 705 case R_VAX_PC32: 706 /* If we are creating a shared library and this is not a local 707 symbol, we need to copy the reloc into the shared library. 708 However when linking with -Bsymbolic and this is a global 709 symbol which is defined in an object we are including in the 710 link (i.e., DEF_REGULAR is set), then we can resolve the 711 reloc directly. At this point we have not seen all the input 712 files, so it is possible that DEF_REGULAR is not set now but 713 will be set later (it is never cleared). We account for that 714 possibility below by storing information in the 715 pcrel_relocs_copied field of the hash table entry. */ 716 if (!(info->shared 717 && (sec->flags & SEC_ALLOC) != 0 718 && h != NULL 719 && (!info->symbolic 720 || !h->def_regular))) 721 { 722 if (h != NULL 723 && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT 724 && !h->forced_local) 725 { 726 /* Make sure a plt entry is created for this symbol if 727 it turns out to be a function defined by a dynamic 728 object. */ 729 if (h->plt.refcount == -1) 730 h->plt.refcount = 1; 731 else 732 h->plt.refcount++; 733 } 734 break; 735 } 736 /* If this is a local symbol, we can resolve it directly. */ 737 if (h != NULL 738 && (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT 739 || h->forced_local)) 740 break; 741 742 /* Fall through. */ 743 case R_VAX_8: 744 case R_VAX_16: 745 case R_VAX_32: 746 if (h != NULL && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT) 747 { 748 /* Make sure a plt entry is created for this symbol if it 749 turns out to be a function defined by a dynamic object. */ 750 if (h->plt.refcount == -1) 751 h->plt.refcount = 1; 752 else 753 h->plt.refcount++; 754 } 755 756 /* If we are creating a shared library, we need to copy the 757 reloc into the shared library. */ 758 if (info->shared 759 && (sec->flags & SEC_ALLOC) != 0) 760 { 761 /* When creating a shared object, we must copy these 762 reloc types into the output file. We create a reloc 763 section in dynobj and make room for this reloc. */ 764 if (sreloc == NULL) 765 { 766 sreloc = _bfd_elf_make_dynamic_reloc_section 767 (sec, dynobj, 2, abfd, /*rela?*/ TRUE); 768 769 if (sreloc == NULL) 770 return FALSE; 771 772 if (sec->flags & SEC_READONLY) 773 { 774 if (info->warn_shared_textrel) 775 (*_bfd_error_handler) 776 (_("warning: dynamic relocation in readonly section `%s'"), 777 sec->name); 778 info->flags |= DF_TEXTREL; 779 } 780 } 781 782 sreloc->size += sizeof (Elf32_External_Rela); 783 784 /* If we are linking with -Bsymbolic, we count the number of 785 PC relative relocations we have entered for this symbol, 786 so that we can discard them again if the symbol is later 787 defined by a regular object. Note that this function is 788 only called if we are using a vaxelf linker hash table, 789 which means that h is really a pointer to an 790 elf_vax_link_hash_entry. */ 791 if ((ELF32_R_TYPE (rel->r_info) == R_VAX_PC8 792 || ELF32_R_TYPE (rel->r_info) == R_VAX_PC16 793 || ELF32_R_TYPE (rel->r_info) == R_VAX_PC32) 794 && info->symbolic) 795 { 796 struct elf_vax_link_hash_entry *eh; 797 struct elf_vax_pcrel_relocs_copied *p; 798 799 eh = (struct elf_vax_link_hash_entry *) h; 800 801 for (p = eh->pcrel_relocs_copied; p != NULL; p = p->next) 802 if (p->section == sreloc) 803 break; 804 805 if (p == NULL) 806 { 807 p = ((struct elf_vax_pcrel_relocs_copied *) 808 bfd_alloc (dynobj, (bfd_size_type) sizeof *p)); 809 if (p == NULL) 810 return FALSE; 811 p->next = eh->pcrel_relocs_copied; 812 eh->pcrel_relocs_copied = p; 813 p->section = sreloc; 814 p->count = 0; 815 } 816 817 ++p->count; 818 } 819 } 820 821 break; 822 823 /* This relocation describes the C++ object vtable hierarchy. 824 Reconstruct it for later use during GC. */ 825 case R_VAX_GNU_VTINHERIT: 826 if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset)) 827 return FALSE; 828 break; 829 830 /* This relocation describes which C++ vtable entries are actually 831 used. Record for later use during GC. */ 832 case R_VAX_GNU_VTENTRY: 833 BFD_ASSERT (h != NULL); 834 if (h != NULL 835 && !bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend)) 836 return FALSE; 837 break; 838 839 default: 840 break; 841 } 842 } 843 844 return TRUE; 845 } 846 847 /* Return the section that should be marked against GC for a given 848 relocation. */ 849 850 static asection * 851 elf_vax_gc_mark_hook (asection *sec, 852 struct bfd_link_info *info, 853 Elf_Internal_Rela *rel, 854 struct elf_link_hash_entry *h, 855 Elf_Internal_Sym *sym) 856 { 857 if (h != NULL) 858 switch (ELF32_R_TYPE (rel->r_info)) 859 { 860 case R_VAX_GNU_VTINHERIT: 861 case R_VAX_GNU_VTENTRY: 862 return NULL; 863 } 864 865 return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym); 866 } 867 868 /* Update the got entry reference counts for the section being removed. */ 869 870 static bfd_boolean 871 elf_vax_gc_sweep_hook (bfd *abfd, struct bfd_link_info *info, asection *sec, 872 const Elf_Internal_Rela *relocs) 873 { 874 Elf_Internal_Shdr *symtab_hdr; 875 struct elf_link_hash_entry **sym_hashes; 876 const Elf_Internal_Rela *rel, *relend; 877 bfd *dynobj; 878 879 if (info->relocatable) 880 return TRUE; 881 882 dynobj = elf_hash_table (info)->dynobj; 883 if (dynobj == NULL) 884 return TRUE; 885 886 symtab_hdr = &elf_tdata (abfd)->symtab_hdr; 887 sym_hashes = elf_sym_hashes (abfd); 888 889 relend = relocs + sec->reloc_count; 890 for (rel = relocs; rel < relend; rel++) 891 { 892 unsigned long r_symndx; 893 struct elf_link_hash_entry *h = NULL; 894 895 r_symndx = ELF32_R_SYM (rel->r_info); 896 if (r_symndx >= symtab_hdr->sh_info) 897 { 898 h = sym_hashes[r_symndx - symtab_hdr->sh_info]; 899 while (h->root.type == bfd_link_hash_indirect 900 || h->root.type == bfd_link_hash_warning) 901 h = (struct elf_link_hash_entry *) h->root.u.i.link; 902 } 903 904 switch (ELF32_R_TYPE (rel->r_info)) 905 { 906 case R_VAX_GOT32: 907 if (h != NULL && h->got.refcount > 0) 908 --h->got.refcount; 909 break; 910 911 case R_VAX_PLT32: 912 case R_VAX_PC8: 913 case R_VAX_PC16: 914 case R_VAX_PC32: 915 case R_VAX_8: 916 case R_VAX_16: 917 case R_VAX_32: 918 if (h != NULL && h->plt.refcount > 0) 919 --h->plt.refcount; 920 break; 921 922 default: 923 break; 924 } 925 } 926 927 return TRUE; 928 } 929 930 /* Adjust a symbol defined by a dynamic object and referenced by a 931 regular object. The current definition is in some section of the 932 dynamic object, but we're not including those sections. We have to 933 change the definition to something the rest of the link can 934 understand. */ 935 936 static bfd_boolean 937 elf_vax_adjust_dynamic_symbol (info, h) 938 struct bfd_link_info *info; 939 struct elf_link_hash_entry *h; 940 { 941 bfd *dynobj; 942 asection *s; 943 944 dynobj = elf_hash_table (info)->dynobj; 945 946 /* Make sure we know what is going on here. */ 947 BFD_ASSERT (dynobj != NULL 948 && (h->needs_plt 949 || h->u.weakdef != NULL 950 || (h->def_dynamic 951 && h->ref_regular 952 && !h->def_regular))); 953 954 /* If this is a function, put it in the procedure linkage table. We 955 will fill in the contents of the procedure linkage table later, 956 when we know the address of the .got section. */ 957 if (h->type == STT_FUNC 958 || h->needs_plt) 959 { 960 if (h->plt.refcount <= 0 961 || SYMBOL_CALLS_LOCAL (info, h) 962 || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT 963 && h->root.type == bfd_link_hash_undefweak)) 964 { 965 /* This case can occur if we saw a PLTxx reloc in an input 966 file, but the symbol was never referred to by a dynamic 967 object, or if all references were garbage collected. In 968 such a case, we don't actually need to build a procedure 969 linkage table, and we can just do a PCxx reloc instead. */ 970 h->plt.offset = (bfd_vma) -1; 971 h->needs_plt = 0; 972 return TRUE; 973 } 974 975 s = bfd_get_linker_section (dynobj, ".plt"); 976 BFD_ASSERT (s != NULL); 977 978 /* If this is the first .plt entry, make room for the special 979 first entry. */ 980 if (s->size == 0) 981 { 982 s->size += PLT_ENTRY_SIZE; 983 } 984 985 /* If this symbol is not defined in a regular file, and we are 986 not generating a shared library, then set the symbol to this 987 location in the .plt. This is required to make function 988 pointers compare as equal between the normal executable and 989 the shared library. */ 990 if (!info->shared 991 && !h->def_regular) 992 { 993 h->root.u.def.section = s; 994 h->root.u.def.value = s->size; 995 } 996 997 h->plt.offset = s->size; 998 999 /* Make room for this entry. */ 1000 s->size += PLT_ENTRY_SIZE; 1001 1002 /* We also need to make an entry in the .got.plt section, which 1003 will be placed in the .got section by the linker script. */ 1004 1005 s = bfd_get_linker_section (dynobj, ".got.plt"); 1006 BFD_ASSERT (s != NULL); 1007 s->size += 4; 1008 1009 /* We also need to make an entry in the .rela.plt section. */ 1010 1011 s = bfd_get_linker_section (dynobj, ".rela.plt"); 1012 BFD_ASSERT (s != NULL); 1013 s->size += sizeof (Elf32_External_Rela); 1014 1015 return TRUE; 1016 } 1017 1018 /* Reinitialize the plt offset now that it is not used as a reference 1019 count any more. */ 1020 h->plt.offset = (bfd_vma) -1; 1021 1022 /* If this is a weak symbol, and there is a real definition, the 1023 processor independent code will have arranged for us to see the 1024 real definition first, and we can just use the same value. */ 1025 if (h->u.weakdef != NULL) 1026 { 1027 BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined 1028 || h->u.weakdef->root.type == bfd_link_hash_defweak); 1029 h->root.u.def.section = h->u.weakdef->root.u.def.section; 1030 h->root.u.def.value = h->u.weakdef->root.u.def.value; 1031 return TRUE; 1032 } 1033 1034 /* This is a reference to a symbol defined by a dynamic object which 1035 is not a function. */ 1036 1037 /* If we are creating a shared library, we must presume that the 1038 only references to the symbol are via the global offset table. 1039 For such cases we need not do anything here; the relocations will 1040 be handled correctly by relocate_section. */ 1041 if (info->shared) 1042 return TRUE; 1043 1044 /* We must allocate the symbol in our .dynbss section, which will 1045 become part of the .bss section of the executable. There will be 1046 an entry for this symbol in the .dynsym section. The dynamic 1047 object will contain position independent code, so all references 1048 from the dynamic object to this symbol will go through the global 1049 offset table. The dynamic linker will use the .dynsym entry to 1050 determine the address it must put in the global offset table, so 1051 both the dynamic object and the regular object will refer to the 1052 same memory location for the variable. */ 1053 1054 s = bfd_get_linker_section (dynobj, ".dynbss"); 1055 BFD_ASSERT (s != NULL); 1056 1057 /* We must generate a R_VAX_COPY reloc to tell the dynamic linker to 1058 copy the initial value out of the dynamic object and into the 1059 runtime process image. We need to remember the offset into the 1060 .rela.bss section we are going to use. */ 1061 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0 && h->size != 0) 1062 { 1063 asection *srel; 1064 1065 srel = bfd_get_linker_section (dynobj, ".rela.bss"); 1066 BFD_ASSERT (srel != NULL); 1067 srel->size += sizeof (Elf32_External_Rela); 1068 h->needs_copy = 1; 1069 } 1070 1071 return _bfd_elf_adjust_dynamic_copy (h, s); 1072 } 1073 1074 /* Set the sizes of the dynamic sections. */ 1075 1076 static bfd_boolean 1077 elf_vax_size_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info) 1078 { 1079 bfd *dynobj; 1080 asection *s; 1081 bfd_boolean plt; 1082 bfd_boolean relocs; 1083 bfd_boolean reltext; 1084 1085 dynobj = elf_hash_table (info)->dynobj; 1086 BFD_ASSERT (dynobj != NULL); 1087 1088 if (elf_hash_table (info)->dynamic_sections_created) 1089 { 1090 /* Set the contents of the .interp section to the interpreter. */ 1091 if (info->executable) 1092 { 1093 s = bfd_get_linker_section (dynobj, ".interp"); 1094 BFD_ASSERT (s != NULL); 1095 s->size = sizeof ELF_DYNAMIC_INTERPRETER; 1096 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER; 1097 } 1098 } 1099 else 1100 { 1101 /* We may have created entries in the .rela.got and .got sections. 1102 However, if we are not creating the dynamic sections, we will 1103 not actually use these entries. Reset the size of .rela.got 1104 and .got, which will cause it to get stripped from the output 1105 file below. */ 1106 s = bfd_get_linker_section (dynobj, ".rela.got"); 1107 if (s != NULL) 1108 s->size = 0; 1109 s = bfd_get_linker_section (dynobj, ".got.plt"); 1110 if (s != NULL) 1111 s->size = 0; 1112 s = bfd_get_linker_section (dynobj, ".got"); 1113 if (s != NULL) 1114 s->size = 0; 1115 } 1116 1117 /* If this is a -Bsymbolic shared link, then we need to discard all PC 1118 relative relocs against symbols defined in a regular object. We 1119 allocated space for them in the check_relocs routine, but we will not 1120 fill them in in the relocate_section routine. */ 1121 if (info->shared && info->symbolic) 1122 elf_vax_link_hash_traverse (elf_hash_table (info), 1123 elf_vax_discard_copies, 1124 NULL); 1125 1126 /* If this is a -Bsymbolic shared link or a static link, we need to 1127 discard all the got entries we've recorded. Otherwise, we need to 1128 instantiate (allocate space for them). */ 1129 elf_link_hash_traverse (elf_hash_table (info), 1130 elf_vax_instantiate_got_entries, 1131 info); 1132 1133 /* The check_relocs and adjust_dynamic_symbol entry points have 1134 determined the sizes of the various dynamic sections. Allocate 1135 memory for them. */ 1136 plt = FALSE; 1137 relocs = FALSE; 1138 reltext = FALSE; 1139 for (s = dynobj->sections; s != NULL; s = s->next) 1140 { 1141 const char *name; 1142 1143 if ((s->flags & SEC_LINKER_CREATED) == 0) 1144 continue; 1145 1146 /* It's OK to base decisions on the section name, because none 1147 of the dynobj section names depend upon the input files. */ 1148 name = bfd_get_section_name (dynobj, s); 1149 1150 if (strcmp (name, ".plt") == 0) 1151 { 1152 /* Remember whether there is a PLT. */ 1153 plt = s->size != 0; 1154 } 1155 else if (CONST_STRNEQ (name, ".rela")) 1156 { 1157 if (s->size != 0) 1158 { 1159 asection *target; 1160 1161 /* Remember whether there are any reloc sections other 1162 than .rela.plt. */ 1163 if (strcmp (name, ".rela.plt") != 0) 1164 { 1165 const char *outname; 1166 1167 relocs = TRUE; 1168 1169 /* If this relocation section applies to a read only 1170 section, then we probably need a DT_TEXTREL 1171 entry. .rela.plt is actually associated with 1172 .got.plt, which is never readonly. */ 1173 outname = bfd_get_section_name (output_bfd, 1174 s->output_section); 1175 target = bfd_get_section_by_name (output_bfd, outname + 5); 1176 if (target != NULL 1177 && (target->flags & SEC_READONLY) != 0 1178 && (target->flags & SEC_ALLOC) != 0) 1179 reltext = TRUE; 1180 } 1181 1182 /* We use the reloc_count field as a counter if we need 1183 to copy relocs into the output file. */ 1184 s->reloc_count = 0; 1185 } 1186 } 1187 else if (! CONST_STRNEQ (name, ".got") 1188 && strcmp (name, ".dynbss") != 0) 1189 { 1190 /* It's not one of our sections, so don't allocate space. */ 1191 continue; 1192 } 1193 1194 if (s->size == 0) 1195 { 1196 /* If we don't need this section, strip it from the 1197 output file. This is mostly to handle .rela.bss and 1198 .rela.plt. We must create both sections in 1199 create_dynamic_sections, because they must be created 1200 before the linker maps input sections to output 1201 sections. The linker does that before 1202 adjust_dynamic_symbol is called, and it is that 1203 function which decides whether anything needs to go 1204 into these sections. */ 1205 s->flags |= SEC_EXCLUDE; 1206 continue; 1207 } 1208 1209 if ((s->flags & SEC_HAS_CONTENTS) == 0) 1210 continue; 1211 1212 /* Allocate memory for the section contents. */ 1213 /* FIXME: This should be a call to bfd_alloc not bfd_zalloc. 1214 Unused entries should be reclaimed before the section's contents 1215 are written out, but at the moment this does not happen. Thus in 1216 order to prevent writing out garbage, we initialise the section's 1217 contents to zero. */ 1218 s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size); 1219 if (s->contents == NULL) 1220 return FALSE; 1221 } 1222 1223 if (elf_hash_table (info)->dynamic_sections_created) 1224 { 1225 /* Add some entries to the .dynamic section. We fill in the 1226 values later, in elf_vax_finish_dynamic_sections, but we 1227 must add the entries now so that we get the correct size for 1228 the .dynamic section. The DT_DEBUG entry is filled in by the 1229 dynamic linker and used by the debugger. */ 1230 #define add_dynamic_entry(TAG, VAL) \ 1231 _bfd_elf_add_dynamic_entry (info, TAG, VAL) 1232 1233 if (!info->shared) 1234 { 1235 if (!add_dynamic_entry (DT_DEBUG, 0)) 1236 return FALSE; 1237 } 1238 1239 if (plt) 1240 { 1241 if (!add_dynamic_entry (DT_PLTGOT, 0) 1242 || !add_dynamic_entry (DT_PLTRELSZ, 0) 1243 || !add_dynamic_entry (DT_PLTREL, DT_RELA) 1244 || !add_dynamic_entry (DT_JMPREL, 0)) 1245 return FALSE; 1246 } 1247 1248 if (relocs) 1249 { 1250 if (!add_dynamic_entry (DT_RELA, 0) 1251 || !add_dynamic_entry (DT_RELASZ, 0) 1252 || !add_dynamic_entry (DT_RELAENT, sizeof (Elf32_External_Rela))) 1253 return FALSE; 1254 } 1255 1256 if (reltext || (info->flags & DF_TEXTREL) != 0) 1257 { 1258 if (!add_dynamic_entry (DT_TEXTREL, 0)) 1259 return FALSE; 1260 } 1261 } 1262 #undef add_dynamic_entry 1263 1264 return TRUE; 1265 } 1266 1267 /* This function is called via elf_vax_link_hash_traverse if we are 1268 creating a shared object with -Bsymbolic. It discards the space 1269 allocated to copy PC relative relocs against symbols which are defined 1270 in regular objects. We allocated space for them in the check_relocs 1271 routine, but we won't fill them in in the relocate_section routine. */ 1272 1273 static bfd_boolean 1274 elf_vax_discard_copies (struct elf_vax_link_hash_entry *h, 1275 void * ignore ATTRIBUTE_UNUSED) 1276 { 1277 struct elf_vax_pcrel_relocs_copied *s; 1278 1279 /* We only discard relocs for symbols defined in a regular object. */ 1280 if (!h->root.def_regular) 1281 return TRUE; 1282 1283 for (s = h->pcrel_relocs_copied; s != NULL; s = s->next) 1284 s->section->size -= s->count * sizeof (Elf32_External_Rela); 1285 1286 return TRUE; 1287 } 1288 1289 /* This function is called via elf_link_hash_traverse. It looks for entries 1290 that have GOT or PLT (.GOT) references. If creating a static object or a 1291 shared object with -Bsymbolic, it resets the reference count back to 0 1292 and sets the offset to -1 so normal PC32 relocation will be done. If 1293 creating a shared object or executable, space in the .got and .rela.got 1294 will be reserved for the symbol. */ 1295 1296 static bfd_boolean 1297 elf_vax_instantiate_got_entries (struct elf_link_hash_entry *h, void * infoptr) 1298 { 1299 struct bfd_link_info *info = (struct bfd_link_info *) infoptr; 1300 bfd *dynobj; 1301 asection *sgot; 1302 asection *srelgot; 1303 1304 /* We don't care about non-GOT (and non-PLT) entries. */ 1305 if (h->got.refcount <= 0 && h->plt.refcount <= 0) 1306 return TRUE; 1307 1308 dynobj = elf_hash_table (info)->dynobj; 1309 if (dynobj == NULL) 1310 return TRUE; 1311 1312 sgot = bfd_get_linker_section (dynobj, ".got"); 1313 srelgot = bfd_get_linker_section (dynobj, ".rela.got"); 1314 1315 if (!elf_hash_table (info)->dynamic_sections_created 1316 || (info->shared && info->symbolic) 1317 || ELF_ST_VISIBILITY (h->other) != STV_DEFAULT 1318 || h->forced_local) 1319 { 1320 h->got.refcount = 0; 1321 h->got.offset = (bfd_vma) -1; 1322 h->plt.refcount = 0; 1323 h->plt.offset = (bfd_vma) -1; 1324 } 1325 else if (h->got.refcount > 0) 1326 { 1327 bfd_boolean dyn; 1328 1329 /* Make sure this symbol is output as a dynamic symbol. */ 1330 if (h->dynindx == -1) 1331 { 1332 if (!bfd_elf_link_record_dynamic_symbol (info, h)) 1333 return FALSE; 1334 } 1335 1336 dyn = elf_hash_table (info)->dynamic_sections_created; 1337 /* Allocate space in the .got and .rela.got sections. */ 1338 if (info->shared || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h)) 1339 { 1340 sgot->size += 4; 1341 srelgot->size += sizeof (Elf32_External_Rela); 1342 } 1343 } 1344 1345 return TRUE; 1346 } 1347 1348 /* Relocate an VAX ELF section. */ 1349 1350 static bfd_boolean 1351 elf_vax_relocate_section (bfd *output_bfd, 1352 struct bfd_link_info *info, 1353 bfd *input_bfd, 1354 asection *input_section, 1355 bfd_byte *contents, 1356 Elf_Internal_Rela *relocs, 1357 Elf_Internal_Sym *local_syms, 1358 asection **local_sections) 1359 { 1360 bfd *dynobj; 1361 Elf_Internal_Shdr *symtab_hdr; 1362 struct elf_link_hash_entry **sym_hashes; 1363 bfd_vma plt_index; 1364 bfd_vma got_offset; 1365 asection *sgot; 1366 asection *splt; 1367 asection *sgotplt; 1368 asection *sreloc; 1369 Elf_Internal_Rela *rel; 1370 Elf_Internal_Rela *relend; 1371 1372 dynobj = elf_hash_table (info)->dynobj; 1373 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; 1374 sym_hashes = elf_sym_hashes (input_bfd); 1375 1376 sgot = NULL; 1377 splt = NULL; 1378 sgotplt = NULL; 1379 sreloc = NULL; 1380 1381 rel = relocs; 1382 relend = relocs + input_section->reloc_count; 1383 for (; rel < relend; rel++) 1384 { 1385 int r_type; 1386 reloc_howto_type *howto; 1387 unsigned long r_symndx; 1388 struct elf_link_hash_entry *h; 1389 Elf_Internal_Sym *sym; 1390 asection *sec; 1391 bfd_vma relocation; 1392 bfd_reloc_status_type r; 1393 1394 r_type = ELF32_R_TYPE (rel->r_info); 1395 if (r_type < 0 || r_type >= (int) R_VAX_max) 1396 { 1397 bfd_set_error (bfd_error_bad_value); 1398 return FALSE; 1399 } 1400 howto = howto_table + r_type; 1401 1402 r_symndx = ELF32_R_SYM (rel->r_info); 1403 h = NULL; 1404 sym = NULL; 1405 sec = NULL; 1406 if (r_symndx < symtab_hdr->sh_info) 1407 { 1408 sym = local_syms + r_symndx; 1409 sec = local_sections[r_symndx]; 1410 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel); 1411 } 1412 else 1413 { 1414 bfd_boolean unresolved_reloc; 1415 bfd_boolean warned; 1416 1417 RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel, 1418 r_symndx, symtab_hdr, sym_hashes, 1419 h, sec, relocation, 1420 unresolved_reloc, warned); 1421 1422 if ((h->root.type == bfd_link_hash_defined 1423 || h->root.type == bfd_link_hash_defweak) 1424 && ((r_type == R_VAX_PLT32 1425 && h->plt.offset != (bfd_vma) -1 1426 && !h->forced_local 1427 && elf_hash_table (info)->dynamic_sections_created) 1428 || (r_type == R_VAX_GOT32 1429 && h->got.offset != (bfd_vma) -1 1430 && !h->forced_local 1431 && elf_hash_table (info)->dynamic_sections_created 1432 && (! info->shared 1433 || (! info->symbolic && h->dynindx != -1) 1434 || !h->def_regular)) 1435 || (info->shared 1436 && ((! info->symbolic && h->dynindx != -1) 1437 || !h->def_regular) 1438 && ((input_section->flags & SEC_ALLOC) != 0 1439 /* DWARF will emit R_VAX_32 relocations in its 1440 sections against symbols defined externally 1441 in shared libraries. We can't do anything 1442 with them here. */ 1443 1444 || ((input_section->flags & SEC_DEBUGGING) != 0 1445 && h->def_dynamic)) 1446 && (r_type == R_VAX_8 1447 || r_type == R_VAX_16 1448 || r_type == R_VAX_32)))) 1449 /* In these cases, we don't need the relocation 1450 value. We check specially because in some 1451 obscure cases sec->output_section will be NULL. */ 1452 relocation = 0; 1453 } 1454 1455 if (sec != NULL && discarded_section (sec)) 1456 RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section, 1457 rel, 1, relend, howto, 0, contents); 1458 1459 if (info->relocatable) 1460 continue; 1461 1462 switch (r_type) 1463 { 1464 case R_VAX_GOT32: 1465 /* Relocation is to the address of the entry for this symbol 1466 in the global offset table. */ 1467 if (h == NULL 1468 || ELF_ST_VISIBILITY (h->other) != STV_DEFAULT 1469 || h->got.offset == (bfd_vma) -1 1470 || h->forced_local) 1471 break; 1472 1473 /* Relocation is the offset of the entry for this symbol in 1474 the global offset table. */ 1475 1476 { 1477 bfd_boolean dyn; 1478 bfd_vma off; 1479 1480 if (sgot == NULL) 1481 { 1482 sgot = bfd_get_linker_section (dynobj, ".got"); 1483 BFD_ASSERT (sgot != NULL); 1484 } 1485 1486 BFD_ASSERT (h != NULL); 1487 off = h->got.offset; 1488 BFD_ASSERT (off != (bfd_vma) -1); 1489 BFD_ASSERT (off < sgot->size); 1490 1491 dyn = elf_hash_table (info)->dynamic_sections_created; 1492 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h) 1493 || (info->shared 1494 && SYMBOL_REFERENCES_LOCAL (info, h))) 1495 { 1496 /* The symbol was forced to be local 1497 because of a version file.. We must initialize 1498 this entry in the global offset table. Since 1499 the offset must always be a multiple of 4, we 1500 use the least significant bit to record whether 1501 we have initialized it already. 1502 1503 When doing a dynamic link, we create a .rela.got 1504 relocation entry to initialize the value. This 1505 is done in the finish_dynamic_symbol routine. */ 1506 if ((off & 1) != 0) 1507 off &= ~1; 1508 else 1509 { 1510 bfd_put_32 (output_bfd, relocation + rel->r_addend, 1511 sgot->contents + off); 1512 h->got.offset |= 1; 1513 } 1514 } else { 1515 bfd_put_32 (output_bfd, rel->r_addend, sgot->contents + off); 1516 } 1517 1518 relocation = sgot->output_offset + off; 1519 /* The GOT relocation uses the addend. */ 1520 rel->r_addend = 0; 1521 1522 /* Change the reference to be indirect. */ 1523 contents[rel->r_offset - 1] |= 0x10; 1524 relocation += sgot->output_section->vma; 1525 } 1526 break; 1527 1528 case R_VAX_PC32: 1529 /* If we are creating an executable and the function this 1530 reloc refers to is in a shared lib, then we made a PLT 1531 entry for this symbol and need to handle the reloc like 1532 a PLT reloc. */ 1533 if (info->shared) 1534 goto r_vax_pc32_shared; 1535 /* Fall through. */ 1536 case R_VAX_PLT32: 1537 /* Relocation is to the entry for this symbol in the 1538 procedure linkage table. */ 1539 1540 /* Resolve a PLTxx reloc against a local symbol directly, 1541 without using the procedure linkage table. */ 1542 if (h == NULL 1543 || ELF_ST_VISIBILITY (h->other) != STV_DEFAULT 1544 || h->forced_local) 1545 break; 1546 1547 if (h->plt.offset == (bfd_vma) -1 1548 || !elf_hash_table (info)->dynamic_sections_created) 1549 { 1550 /* We didn't make a PLT entry for this symbol. This 1551 happens when statically linking PIC code, or when 1552 using -Bsymbolic. */ 1553 break; 1554 } 1555 1556 if (splt == NULL) 1557 { 1558 splt = bfd_get_linker_section (dynobj, ".plt"); 1559 BFD_ASSERT (splt != NULL); 1560 } 1561 1562 if (sgotplt == NULL) 1563 { 1564 sgotplt = bfd_get_linker_section (dynobj, ".got.plt"); 1565 BFD_ASSERT (sgotplt != NULL); 1566 } 1567 1568 plt_index = h->plt.offset / PLT_ENTRY_SIZE - 1; 1569 1570 /* Get the offset into the .got table of the entry that 1571 corresponds to this function. Each .got entry is 4 bytes. 1572 The first two are reserved. */ 1573 got_offset = (plt_index + 3) * 4; 1574 1575 /* We want the relocation to point into the .got.plt instead 1576 of the plt itself. */ 1577 relocation = (sgotplt->output_section->vma 1578 + sgotplt->output_offset 1579 + got_offset); 1580 contents[rel->r_offset-1] |= 0x10; /* make indirect */ 1581 if (rel->r_addend == 2) 1582 { 1583 h->plt.offset |= 1; 1584 } 1585 else if (rel->r_addend != 0) 1586 (*_bfd_error_handler) 1587 (_("%s: warning: PLT addend of %d to `%s' from %s section ignored"), 1588 bfd_get_filename (input_bfd), rel->r_addend, 1589 h->root.root.string, 1590 bfd_get_section_name (input_bfd, input_section)); 1591 rel->r_addend = 0; 1592 1593 break; 1594 1595 case R_VAX_PC8: 1596 case R_VAX_PC16: 1597 r_vax_pc32_shared: 1598 if (h == NULL 1599 || ELF_ST_VISIBILITY (h->other) != STV_DEFAULT 1600 || h->forced_local) 1601 break; 1602 /* Fall through. */ 1603 case R_VAX_8: 1604 case R_VAX_16: 1605 case R_VAX_32: 1606 if (info->shared 1607 && r_symndx != STN_UNDEF 1608 && (input_section->flags & SEC_ALLOC) != 0 1609 && ((r_type != R_VAX_PC8 1610 && r_type != R_VAX_PC16 1611 && r_type != R_VAX_PC32) 1612 || ((input_section->flags & SEC_CODE) 1613 && (!info->symbolic 1614 || (!h->def_regular && h->type != STT_SECTION))))) 1615 { 1616 Elf_Internal_Rela outrel; 1617 bfd_byte *loc; 1618 bfd_boolean skip, relocate; 1619 1620 /* When generating a shared object, these relocations 1621 are copied into the output file to be resolved at run 1622 time. */ 1623 if (sreloc == NULL) 1624 { 1625 sreloc = _bfd_elf_get_dynamic_reloc_section 1626 (input_bfd, input_section, /*rela?*/ TRUE); 1627 if (sreloc == NULL) 1628 return FALSE; 1629 } 1630 1631 skip = FALSE; 1632 relocate = FALSE; 1633 1634 outrel.r_offset = 1635 _bfd_elf_section_offset (output_bfd, info, input_section, 1636 rel->r_offset); 1637 if (outrel.r_offset == (bfd_vma) -1) 1638 skip = TRUE; 1639 if (outrel.r_offset == (bfd_vma) -2) 1640 skip = TRUE, relocate = TRUE; 1641 outrel.r_offset += (input_section->output_section->vma 1642 + input_section->output_offset); 1643 1644 if (skip) 1645 memset (&outrel, 0, sizeof outrel); 1646 /* h->dynindx may be -1 if the symbol was marked to 1647 become local. */ 1648 else if (h != NULL 1649 && ((! info->symbolic && h->dynindx != -1) 1650 || !h->def_regular)) 1651 { 1652 BFD_ASSERT (h->dynindx != -1); 1653 outrel.r_info = ELF32_R_INFO (h->dynindx, r_type); 1654 outrel.r_addend = relocation + rel->r_addend; 1655 } 1656 else 1657 { 1658 if (r_type == R_VAX_32) 1659 { 1660 relocate = TRUE; 1661 outrel.r_info = ELF32_R_INFO (0, R_VAX_RELATIVE); 1662 outrel.r_addend = bfd_get_signed_32(input_bfd, 1663 &contents[rel->r_offset]) 1664 + relocation + rel->r_addend; 1665 } 1666 else 1667 { 1668 long indx; 1669 1670 if (bfd_is_abs_section (sec)) 1671 indx = 0; 1672 else if (sec == NULL || sec->owner == NULL) 1673 { 1674 bfd_set_error (bfd_error_bad_value); 1675 return FALSE; 1676 } 1677 else 1678 { 1679 asection *osec; 1680 1681 /* We are turning this relocation into one 1682 against a section symbol. It would be 1683 proper to subtract the symbol's value, 1684 osec->vma, from the emitted reloc addend, 1685 but ld.so expects buggy relocs. */ 1686 osec = sec->output_section; 1687 indx = elf_section_data (osec)->dynindx; 1688 if (indx == 0) 1689 { 1690 struct elf_link_hash_table *htab; 1691 htab = elf_hash_table (info); 1692 osec = htab->text_index_section; 1693 indx = elf_section_data (osec)->dynindx; 1694 } 1695 BFD_ASSERT (indx != 0); 1696 } 1697 1698 outrel.r_info = ELF32_R_INFO (indx, r_type); 1699 outrel.r_addend = relocation + rel->r_addend; 1700 } 1701 } 1702 1703 if (input_section->flags & SEC_CODE) 1704 info->flags |= DF_TEXTREL; 1705 1706 if ((input_section->flags & SEC_CODE) != 0 1707 || (ELF32_R_TYPE (outrel.r_info) != R_VAX_32 1708 && ELF32_R_TYPE (outrel.r_info) != R_VAX_RELATIVE 1709 && ELF32_R_TYPE (outrel.r_info) != R_VAX_COPY 1710 && ELF32_R_TYPE (outrel.r_info) != R_VAX_JMP_SLOT 1711 && ELF32_R_TYPE (outrel.r_info) != R_VAX_GLOB_DAT)) 1712 { 1713 if (h != NULL) 1714 (*_bfd_error_handler) 1715 (_("%s: warning: %s relocation against symbol `%s' from %s section"), 1716 bfd_get_filename (input_bfd), howto->name, 1717 h->root.root.string, 1718 bfd_get_section_name (input_bfd, input_section)); 1719 else 1720 (*_bfd_error_handler) 1721 (_("%s: warning: %s relocation to 0x%x from %s section"), 1722 bfd_get_filename (input_bfd), howto->name, 1723 outrel.r_addend, 1724 bfd_get_section_name (input_bfd, input_section)); 1725 } 1726 loc = sreloc->contents; 1727 loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rela); 1728 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc); 1729 1730 /* This reloc will be computed at runtime, so there's no 1731 need to do anything now, except for R_VAX_32 1732 relocations that have been turned into 1733 R_VAX_RELATIVE. */ 1734 if (!relocate) 1735 continue; 1736 } 1737 1738 break; 1739 1740 case R_VAX_GNU_VTINHERIT: 1741 case R_VAX_GNU_VTENTRY: 1742 /* These are no-ops in the end. */ 1743 continue; 1744 1745 default: 1746 break; 1747 } 1748 1749 /* VAX PCREL relocations are from the end of relocation, not the start. 1750 So subtract the difference from the relocation amount since we can't 1751 add it to the offset. */ 1752 if (howto->pc_relative && howto->pcrel_offset) 1753 relocation -= bfd_get_reloc_size(howto); 1754 1755 r = _bfd_final_link_relocate (howto, input_bfd, input_section, 1756 contents, rel->r_offset, 1757 relocation, rel->r_addend); 1758 1759 if (r != bfd_reloc_ok) 1760 { 1761 switch (r) 1762 { 1763 default: 1764 case bfd_reloc_outofrange: 1765 abort (); 1766 case bfd_reloc_overflow: 1767 { 1768 const char *name; 1769 1770 if (h != NULL) 1771 name = NULL; 1772 else 1773 { 1774 name = bfd_elf_string_from_elf_section (input_bfd, 1775 symtab_hdr->sh_link, 1776 sym->st_name); 1777 if (name == NULL) 1778 return FALSE; 1779 if (*name == '\0') 1780 name = bfd_section_name (input_bfd, sec); 1781 } 1782 if (!(info->callbacks->reloc_overflow 1783 (info, (h ? &h->root : NULL), name, howto->name, 1784 (bfd_vma) 0, input_bfd, input_section, 1785 rel->r_offset))) 1786 return FALSE; 1787 } 1788 break; 1789 } 1790 } 1791 } 1792 1793 return TRUE; 1794 } 1795 1796 /* Finish up dynamic symbol handling. We set the contents of various 1797 dynamic sections here. */ 1798 1799 static bfd_boolean 1800 elf_vax_finish_dynamic_symbol (bfd *output_bfd, struct bfd_link_info *info, 1801 struct elf_link_hash_entry *h, 1802 Elf_Internal_Sym *sym) 1803 { 1804 bfd *dynobj; 1805 1806 dynobj = elf_hash_table (info)->dynobj; 1807 1808 if (h->plt.offset != (bfd_vma) -1) 1809 { 1810 asection *splt; 1811 asection *sgot; 1812 asection *srela; 1813 bfd_vma plt_index; 1814 bfd_vma got_offset; 1815 bfd_vma addend; 1816 Elf_Internal_Rela rela; 1817 bfd_byte *loc; 1818 1819 /* This symbol has an entry in the procedure linkage table. Set 1820 it up. */ 1821 BFD_ASSERT (h->dynindx != -1); 1822 1823 splt = bfd_get_linker_section (dynobj, ".plt"); 1824 sgot = bfd_get_linker_section (dynobj, ".got.plt"); 1825 srela = bfd_get_linker_section (dynobj, ".rela.plt"); 1826 BFD_ASSERT (splt != NULL && sgot != NULL && srela != NULL); 1827 1828 addend = 2 * (h->plt.offset & 1); 1829 h->plt.offset &= ~1; 1830 1831 /* Get the index in the procedure linkage table which 1832 corresponds to this symbol. This is the index of this symbol 1833 in all the symbols for which we are making plt entries. The 1834 first entry in the procedure linkage table is reserved. */ 1835 plt_index = h->plt.offset / PLT_ENTRY_SIZE - 1; 1836 1837 /* Get the offset into the .got table of the entry that 1838 corresponds to this function. Each .got entry is 4 bytes. 1839 The first two are reserved. */ 1840 got_offset = (plt_index + 3) * 4; 1841 1842 /* Fill in the entry in the procedure linkage table. */ 1843 memcpy (splt->contents + h->plt.offset, elf_vax_plt_entry, 1844 PLT_ENTRY_SIZE); 1845 1846 /* The offset is relative to the first extension word. */ 1847 bfd_put_32 (output_bfd, 1848 -(h->plt.offset + 8), 1849 splt->contents + h->plt.offset + 4); 1850 1851 bfd_put_32 (output_bfd, plt_index * sizeof (Elf32_External_Rela), 1852 splt->contents + h->plt.offset + 8); 1853 1854 /* Fill in the entry in the global offset table. */ 1855 bfd_put_32 (output_bfd, 1856 (splt->output_section->vma 1857 + splt->output_offset 1858 + h->plt.offset) + addend, 1859 sgot->contents + got_offset); 1860 1861 /* Fill in the entry in the .rela.plt section. */ 1862 rela.r_offset = (sgot->output_section->vma 1863 + sgot->output_offset 1864 + got_offset); 1865 rela.r_info = ELF32_R_INFO (h->dynindx, R_VAX_JMP_SLOT); 1866 rela.r_addend = addend; 1867 loc = srela->contents + plt_index * sizeof (Elf32_External_Rela); 1868 bfd_elf32_swap_reloca_out (output_bfd, &rela, loc); 1869 1870 if (!h->def_regular) 1871 { 1872 /* Mark the symbol as undefined, rather than as defined in 1873 the .plt section. Leave the value alone. */ 1874 sym->st_shndx = SHN_UNDEF; 1875 } 1876 } 1877 1878 if (h->got.offset != (bfd_vma) -1) 1879 { 1880 asection *sgot; 1881 asection *srela; 1882 Elf_Internal_Rela rela; 1883 bfd_byte *loc; 1884 1885 /* This symbol has an entry in the global offset table. Set it 1886 up. */ 1887 sgot = bfd_get_linker_section (dynobj, ".got"); 1888 srela = bfd_get_linker_section (dynobj, ".rela.got"); 1889 BFD_ASSERT (sgot != NULL && srela != NULL); 1890 1891 rela.r_offset = (sgot->output_section->vma 1892 + sgot->output_offset 1893 + (h->got.offset &~ 1)); 1894 1895 /* If the symbol was forced to be local because of a version file 1896 locally we just want to emit a RELATIVE reloc. The entry in 1897 the global offset table will already have been initialized in 1898 the relocate_section function. */ 1899 if (info->shared 1900 && h->dynindx == -1 1901 && h->def_regular) 1902 { 1903 rela.r_info = ELF32_R_INFO (0, R_VAX_RELATIVE); 1904 } 1905 else 1906 { 1907 rela.r_info = ELF32_R_INFO (h->dynindx, R_VAX_GLOB_DAT); 1908 } 1909 rela.r_addend = bfd_get_signed_32 (output_bfd, 1910 (sgot->contents 1911 + (h->got.offset & ~1))); 1912 1913 loc = srela->contents; 1914 loc += srela->reloc_count++ * sizeof (Elf32_External_Rela); 1915 bfd_elf32_swap_reloca_out (output_bfd, &rela, loc); 1916 } 1917 1918 if (h->needs_copy) 1919 { 1920 asection *s; 1921 Elf_Internal_Rela rela; 1922 bfd_byte *loc; 1923 1924 /* This symbol needs a copy reloc. Set it up. */ 1925 BFD_ASSERT (h->dynindx != -1 1926 && (h->root.type == bfd_link_hash_defined 1927 || h->root.type == bfd_link_hash_defweak)); 1928 1929 s = bfd_get_linker_section (dynobj, ".rela.bss"); 1930 BFD_ASSERT (s != NULL); 1931 1932 rela.r_offset = (h->root.u.def.value 1933 + h->root.u.def.section->output_section->vma 1934 + h->root.u.def.section->output_offset); 1935 rela.r_info = ELF32_R_INFO (h->dynindx, R_VAX_COPY); 1936 rela.r_addend = 0; 1937 loc = s->contents + s->reloc_count++ * sizeof (Elf32_External_Rela); 1938 bfd_elf32_swap_reloca_out (output_bfd, &rela, loc); 1939 } 1940 1941 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */ 1942 if (strcmp (h->root.root.string, "_DYNAMIC") == 0 1943 || h == elf_hash_table (info)->hgot) 1944 sym->st_shndx = SHN_ABS; 1945 1946 return TRUE; 1947 } 1948 1949 /* Finish up the dynamic sections. */ 1950 1951 static bfd_boolean 1952 elf_vax_finish_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info) 1953 { 1954 bfd *dynobj; 1955 asection *sgot; 1956 asection *sdyn; 1957 1958 dynobj = elf_hash_table (info)->dynobj; 1959 1960 sgot = bfd_get_linker_section (dynobj, ".got.plt"); 1961 BFD_ASSERT (sgot != NULL); 1962 sdyn = bfd_get_linker_section (dynobj, ".dynamic"); 1963 1964 if (elf_hash_table (info)->dynamic_sections_created) 1965 { 1966 asection *splt; 1967 Elf32_External_Dyn *dyncon, *dynconend; 1968 1969 splt = bfd_get_linker_section (dynobj, ".plt"); 1970 BFD_ASSERT (splt != NULL && sdyn != NULL); 1971 1972 dyncon = (Elf32_External_Dyn *) sdyn->contents; 1973 dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size); 1974 for (; dyncon < dynconend; dyncon++) 1975 { 1976 Elf_Internal_Dyn dyn; 1977 const char *name; 1978 asection *s; 1979 1980 bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn); 1981 1982 switch (dyn.d_tag) 1983 { 1984 default: 1985 break; 1986 1987 case DT_PLTGOT: 1988 name = ".got"; 1989 goto get_vma; 1990 case DT_JMPREL: 1991 name = ".rela.plt"; 1992 get_vma: 1993 s = bfd_get_section_by_name (output_bfd, name); 1994 BFD_ASSERT (s != NULL); 1995 dyn.d_un.d_ptr = s->vma; 1996 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); 1997 break; 1998 1999 case DT_PLTRELSZ: 2000 s = bfd_get_section_by_name (output_bfd, ".rela.plt"); 2001 BFD_ASSERT (s != NULL); 2002 dyn.d_un.d_val = s->size; 2003 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); 2004 break; 2005 2006 case DT_RELASZ: 2007 /* The procedure linkage table relocs (DT_JMPREL) should 2008 not be included in the overall relocs (DT_RELA). 2009 Therefore, we override the DT_RELASZ entry here to 2010 make it not include the JMPREL relocs. Since the 2011 linker script arranges for .rela.plt to follow all 2012 other relocation sections, we don't have to worry 2013 about changing the DT_RELA entry. */ 2014 s = bfd_get_section_by_name (output_bfd, ".rela.plt"); 2015 if (s != NULL) 2016 dyn.d_un.d_val -= s->size; 2017 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); 2018 break; 2019 } 2020 } 2021 2022 /* Fill in the first entry in the procedure linkage table. */ 2023 if (splt->size > 0) 2024 { 2025 memcpy (splt->contents, elf_vax_plt0_entry, PLT_ENTRY_SIZE); 2026 bfd_put_32 (output_bfd, 2027 (sgot->output_section->vma 2028 + sgot->output_offset + 4 2029 - (splt->output_section->vma + 6)), 2030 splt->contents + 2); 2031 bfd_put_32 (output_bfd, 2032 (sgot->output_section->vma 2033 + sgot->output_offset + 8 2034 - (splt->output_section->vma + 12)), 2035 splt->contents + 8); 2036 elf_section_data (splt->output_section)->this_hdr.sh_entsize 2037 = PLT_ENTRY_SIZE; 2038 } 2039 } 2040 2041 /* Fill in the first three entries in the global offset table. */ 2042 if (sgot->size > 0) 2043 { 2044 if (sdyn == NULL) 2045 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents); 2046 else 2047 bfd_put_32 (output_bfd, 2048 sdyn->output_section->vma + sdyn->output_offset, 2049 sgot->contents); 2050 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 4); 2051 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 8); 2052 } 2053 2054 elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4; 2055 2056 return TRUE; 2057 } 2058 2059 static enum elf_reloc_type_class 2060 elf_vax_reloc_type_class (const Elf_Internal_Rela *rela) 2061 { 2062 switch ((int) ELF32_R_TYPE (rela->r_info)) 2063 { 2064 case R_VAX_RELATIVE: 2065 return reloc_class_relative; 2066 case R_VAX_JMP_SLOT: 2067 return reloc_class_plt; 2068 case R_VAX_COPY: 2069 return reloc_class_copy; 2070 default: 2071 return reloc_class_normal; 2072 } 2073 } 2074 2075 static bfd_vma 2076 elf_vax_plt_sym_val (bfd_vma i, const asection *plt, 2077 const arelent *rel ATTRIBUTE_UNUSED) 2078 { 2079 return plt->vma + (i + 1) * PLT_ENTRY_SIZE; 2080 } 2081 2082 #define TARGET_LITTLE_SYM bfd_elf32_vax_vec 2083 #define TARGET_LITTLE_NAME "elf32-vax" 2084 #define ELF_MACHINE_CODE EM_VAX 2085 #define ELF_MAXPAGESIZE 0x10000 2086 2087 #define elf_backend_create_dynamic_sections \ 2088 _bfd_elf_create_dynamic_sections 2089 #define bfd_elf32_bfd_link_hash_table_create \ 2090 elf_vax_link_hash_table_create 2091 #define bfd_elf32_bfd_copy_private_bfd_data \ 2092 elf32_vax_copy_private_bfd_data 2093 2094 #define bfd_elf32_bfd_final_link bfd_elf_gc_common_final_link 2095 2096 #define elf_backend_check_relocs elf_vax_check_relocs 2097 #define elf_backend_adjust_dynamic_symbol \ 2098 elf_vax_adjust_dynamic_symbol 2099 #define elf_backend_size_dynamic_sections \ 2100 elf_vax_size_dynamic_sections 2101 #define elf_backend_init_index_section _bfd_elf_init_1_index_section 2102 #define elf_backend_relocate_section elf_vax_relocate_section 2103 #define elf_backend_finish_dynamic_symbol \ 2104 elf_vax_finish_dynamic_symbol 2105 #define elf_backend_finish_dynamic_sections \ 2106 elf_vax_finish_dynamic_sections 2107 #define elf_backend_reloc_type_class elf_vax_reloc_type_class 2108 #define elf_backend_gc_mark_hook elf_vax_gc_mark_hook 2109 #define elf_backend_gc_sweep_hook elf_vax_gc_sweep_hook 2110 #define elf_backend_plt_sym_val elf_vax_plt_sym_val 2111 #define bfd_elf32_bfd_merge_private_bfd_data \ 2112 elf32_vax_merge_private_bfd_data 2113 #define bfd_elf32_bfd_set_private_flags \ 2114 elf32_vax_set_private_flags 2115 #define bfd_elf32_bfd_print_private_bfd_data \ 2116 elf32_vax_print_private_bfd_data 2117 2118 #define elf_backend_can_gc_sections 1 2119 #define elf_backend_want_got_plt 1 2120 #define elf_backend_plt_readonly 1 2121 #define elf_backend_want_plt_sym 0 2122 #define elf_backend_got_header_size 16 2123 #define elf_backend_rela_normal 1 2124 2125 #include "elf32-target.h" 2126