1 /* Alpha specific support for 64-bit ELF 2 Copyright (C) 1996-2016 Free Software Foundation, Inc. 3 Contributed by Richard Henderson <rth (at) tamu.edu>. 4 5 This file is part of BFD, the Binary File Descriptor library. 6 7 This program is free software; you can redistribute it and/or modify 8 it under the terms of the GNU General Public License as published by 9 the Free Software Foundation; either version 3 of the License, or 10 (at your option) any later version. 11 12 This program is distributed in the hope that it will be useful, 13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 GNU General Public License for more details. 16 17 You should have received a copy of the GNU General Public License 18 along with this program; if not, write to the Free Software 19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, 20 MA 02110-1301, USA. */ 21 22 23 /* We need a published ABI spec for this. Until one comes out, don't 24 assume this'll remain unchanged forever. */ 25 26 #include "sysdep.h" 27 #include "bfd.h" 28 #include "libbfd.h" 29 #include "elf-bfd.h" 30 31 #include "elf/alpha.h" 32 33 #define ALPHAECOFF 34 35 #define NO_COFF_RELOCS 36 #define NO_COFF_SYMBOLS 37 #define NO_COFF_LINENOS 38 39 /* Get the ECOFF swapping routines. Needed for the debug information. */ 40 #include "coff/internal.h" 41 #include "coff/sym.h" 42 #include "coff/symconst.h" 43 #include "coff/ecoff.h" 44 #include "coff/alpha.h" 45 #include "aout/ar.h" 46 #include "libcoff.h" 47 #include "libecoff.h" 48 #define ECOFF_64 49 #include "ecoffswap.h" 50 51 52 /* Instruction data for plt generation and relaxation. */ 54 55 #define OP_LDA 0x08 56 #define OP_LDAH 0x09 57 #define OP_LDQ 0x29 58 #define OP_BR 0x30 59 #define OP_BSR 0x34 60 61 #define INSN_LDA (OP_LDA << 26) 62 #define INSN_LDAH (OP_LDAH << 26) 63 #define INSN_LDQ (OP_LDQ << 26) 64 #define INSN_BR (OP_BR << 26) 65 66 #define INSN_ADDQ 0x40000400 67 #define INSN_RDUNIQ 0x0000009e 68 #define INSN_SUBQ 0x40000520 69 #define INSN_S4SUBQ 0x40000560 70 #define INSN_UNOP 0x2ffe0000 71 72 #define INSN_JSR 0x68004000 73 #define INSN_JMP 0x68000000 74 #define INSN_JSR_MASK 0xfc00c000 75 76 #define INSN_A(I,A) (I | (A << 21)) 77 #define INSN_AB(I,A,B) (I | (A << 21) | (B << 16)) 78 #define INSN_ABC(I,A,B,C) (I | (A << 21) | (B << 16) | C) 79 #define INSN_ABO(I,A,B,O) (I | (A << 21) | (B << 16) | ((O) & 0xffff)) 80 #define INSN_AD(I,A,D) (I | (A << 21) | (((D) >> 2) & 0x1fffff)) 81 82 /* PLT/GOT Stuff */ 83 84 /* Set by ld emulation. Putting this into the link_info or hash structure 85 is simply working too hard. */ 86 #ifdef USE_SECUREPLT 87 bfd_boolean elf64_alpha_use_secureplt = TRUE; 88 #else 89 bfd_boolean elf64_alpha_use_secureplt = FALSE; 90 #endif 91 92 #define OLD_PLT_HEADER_SIZE 32 93 #define OLD_PLT_ENTRY_SIZE 12 94 #define NEW_PLT_HEADER_SIZE 36 95 #define NEW_PLT_ENTRY_SIZE 4 96 97 #define PLT_HEADER_SIZE \ 98 (elf64_alpha_use_secureplt ? NEW_PLT_HEADER_SIZE : OLD_PLT_HEADER_SIZE) 99 #define PLT_ENTRY_SIZE \ 100 (elf64_alpha_use_secureplt ? NEW_PLT_ENTRY_SIZE : OLD_PLT_ENTRY_SIZE) 101 102 #define MAX_GOT_SIZE (64*1024) 103 104 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so" 105 106 108 /* Used to implement multiple .got subsections. */ 109 struct alpha_elf_got_entry 110 { 111 struct alpha_elf_got_entry *next; 112 113 /* Which .got subsection? */ 114 bfd *gotobj; 115 116 /* The addend in effect for this entry. */ 117 bfd_vma addend; 118 119 /* The .got offset for this entry. */ 120 int got_offset; 121 122 /* The .plt offset for this entry. */ 123 int plt_offset; 124 125 /* How many references to this entry? */ 126 int use_count; 127 128 /* The relocation type of this entry. */ 129 unsigned char reloc_type; 130 131 /* How a LITERAL is used. */ 132 unsigned char flags; 133 134 /* Have we initialized the dynamic relocation for this entry? */ 135 unsigned char reloc_done; 136 137 /* Have we adjusted this entry for SEC_MERGE? */ 138 unsigned char reloc_xlated; 139 }; 140 141 struct alpha_elf_reloc_entry 142 { 143 struct alpha_elf_reloc_entry *next; 144 145 /* Which .reloc section? */ 146 asection *srel; 147 148 /* What kind of relocation? */ 149 unsigned int rtype; 150 151 /* Is this against read-only section? */ 152 unsigned int reltext : 1; 153 154 /* How many did we find? */ 155 unsigned long count; 156 }; 157 158 struct alpha_elf_link_hash_entry 159 { 160 struct elf_link_hash_entry root; 161 162 /* External symbol information. */ 163 EXTR esym; 164 165 /* Cumulative flags for all the .got entries. */ 166 int flags; 167 168 /* Contexts in which a literal was referenced. */ 169 #define ALPHA_ELF_LINK_HASH_LU_ADDR 0x01 170 #define ALPHA_ELF_LINK_HASH_LU_MEM 0x02 171 #define ALPHA_ELF_LINK_HASH_LU_BYTE 0x04 172 #define ALPHA_ELF_LINK_HASH_LU_JSR 0x08 173 #define ALPHA_ELF_LINK_HASH_LU_TLSGD 0x10 174 #define ALPHA_ELF_LINK_HASH_LU_TLSLDM 0x20 175 #define ALPHA_ELF_LINK_HASH_LU_JSRDIRECT 0x40 176 #define ALPHA_ELF_LINK_HASH_LU_PLT 0x38 177 #define ALPHA_ELF_LINK_HASH_TLS_IE 0x80 178 179 /* Used to implement multiple .got subsections. */ 180 struct alpha_elf_got_entry *got_entries; 181 182 /* Used to count non-got, non-plt relocations for delayed sizing 183 of relocation sections. */ 184 struct alpha_elf_reloc_entry *reloc_entries; 185 }; 186 187 /* Alpha ELF linker hash table. */ 188 189 struct alpha_elf_link_hash_table 190 { 191 struct elf_link_hash_table root; 192 193 /* The head of a list of .got subsections linked through 194 alpha_elf_tdata(abfd)->got_link_next. */ 195 bfd *got_list; 196 197 /* The most recent relax pass that we've seen. The GOTs 198 should be regenerated if this doesn't match. */ 199 int relax_trip; 200 }; 201 202 /* Look up an entry in a Alpha ELF linker hash table. */ 203 204 #define alpha_elf_link_hash_lookup(table, string, create, copy, follow) \ 205 ((struct alpha_elf_link_hash_entry *) \ 206 elf_link_hash_lookup (&(table)->root, (string), (create), \ 207 (copy), (follow))) 208 209 /* Traverse a Alpha ELF linker hash table. */ 210 211 #define alpha_elf_link_hash_traverse(table, func, info) \ 212 (elf_link_hash_traverse \ 213 (&(table)->root, \ 214 (bfd_boolean (*) (struct elf_link_hash_entry *, void *)) (func), \ 215 (info))) 216 217 /* Get the Alpha ELF linker hash table from a link_info structure. */ 218 219 #define alpha_elf_hash_table(p) \ 220 (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \ 221 == ALPHA_ELF_DATA ? ((struct alpha_elf_link_hash_table *) ((p)->hash)) : NULL) 222 223 /* Get the object's symbols as our own entry type. */ 224 225 #define alpha_elf_sym_hashes(abfd) \ 226 ((struct alpha_elf_link_hash_entry **)elf_sym_hashes(abfd)) 227 228 /* Should we do dynamic things to this symbol? This differs from the 229 generic version in that we never need to consider function pointer 230 equality wrt PLT entries -- we don't create a PLT entry if a symbol's 231 address is ever taken. */ 232 233 static inline bfd_boolean 234 alpha_elf_dynamic_symbol_p (struct elf_link_hash_entry *h, 235 struct bfd_link_info *info) 236 { 237 return _bfd_elf_dynamic_symbol_p (h, info, 0); 238 } 239 240 /* Create an entry in a Alpha ELF linker hash table. */ 241 242 static struct bfd_hash_entry * 243 elf64_alpha_link_hash_newfunc (struct bfd_hash_entry *entry, 244 struct bfd_hash_table *table, 245 const char *string) 246 { 247 struct alpha_elf_link_hash_entry *ret = 248 (struct alpha_elf_link_hash_entry *) entry; 249 250 /* Allocate the structure if it has not already been allocated by a 251 subclass. */ 252 if (ret == (struct alpha_elf_link_hash_entry *) NULL) 253 ret = ((struct alpha_elf_link_hash_entry *) 254 bfd_hash_allocate (table, 255 sizeof (struct alpha_elf_link_hash_entry))); 256 if (ret == (struct alpha_elf_link_hash_entry *) NULL) 257 return (struct bfd_hash_entry *) ret; 258 259 /* Call the allocation method of the superclass. */ 260 ret = ((struct alpha_elf_link_hash_entry *) 261 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret, 262 table, string)); 263 if (ret != (struct alpha_elf_link_hash_entry *) NULL) 264 { 265 /* Set local fields. */ 266 memset (&ret->esym, 0, sizeof (EXTR)); 267 /* We use -2 as a marker to indicate that the information has 268 not been set. -1 means there is no associated ifd. */ 269 ret->esym.ifd = -2; 270 ret->flags = 0; 271 ret->got_entries = NULL; 272 ret->reloc_entries = NULL; 273 } 274 275 return (struct bfd_hash_entry *) ret; 276 } 277 278 /* Create a Alpha ELF linker hash table. */ 279 280 static struct bfd_link_hash_table * 281 elf64_alpha_bfd_link_hash_table_create (bfd *abfd) 282 { 283 struct alpha_elf_link_hash_table *ret; 284 bfd_size_type amt = sizeof (struct alpha_elf_link_hash_table); 285 286 ret = (struct alpha_elf_link_hash_table *) bfd_zmalloc (amt); 287 if (ret == (struct alpha_elf_link_hash_table *) NULL) 288 return NULL; 289 290 if (!_bfd_elf_link_hash_table_init (&ret->root, abfd, 291 elf64_alpha_link_hash_newfunc, 292 sizeof (struct alpha_elf_link_hash_entry), 293 ALPHA_ELF_DATA)) 294 { 295 free (ret); 296 return NULL; 297 } 298 299 return &ret->root.root; 300 } 301 302 /* Alpha ELF follows MIPS ELF in using a special find_nearest_line 304 routine in order to handle the ECOFF debugging information. */ 305 306 struct alpha_elf_find_line 307 { 308 struct ecoff_debug_info d; 309 struct ecoff_find_line i; 310 }; 311 312 /* We have some private fields hanging off of the elf_tdata structure. */ 313 314 struct alpha_elf_obj_tdata 315 { 316 struct elf_obj_tdata root; 317 318 /* For every input file, these are the got entries for that object's 319 local symbols. */ 320 struct alpha_elf_got_entry ** local_got_entries; 321 322 /* For every input file, this is the object that owns the got that 323 this input file uses. */ 324 bfd *gotobj; 325 326 /* For every got, this is a linked list through the objects using this got */ 327 bfd *in_got_link_next; 328 329 /* For every got, this is a link to the next got subsegment. */ 330 bfd *got_link_next; 331 332 /* For every got, this is the section. */ 333 asection *got; 334 335 /* For every got, this is it's total number of words. */ 336 int total_got_size; 337 338 /* For every got, this is the sum of the number of words required 339 to hold all of the member object's local got. */ 340 int local_got_size; 341 342 /* Used by elf64_alpha_find_nearest_line entry point. */ 343 struct alpha_elf_find_line *find_line_info; 344 345 }; 346 347 #define alpha_elf_tdata(abfd) \ 348 ((struct alpha_elf_obj_tdata *) (abfd)->tdata.any) 349 350 #define is_alpha_elf(bfd) \ 351 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \ 352 && elf_tdata (bfd) != NULL \ 353 && elf_object_id (bfd) == ALPHA_ELF_DATA) 354 355 static bfd_boolean 356 elf64_alpha_mkobject (bfd *abfd) 357 { 358 return bfd_elf_allocate_object (abfd, sizeof (struct alpha_elf_obj_tdata), 359 ALPHA_ELF_DATA); 360 } 361 362 static bfd_boolean 363 elf64_alpha_object_p (bfd *abfd) 364 { 365 /* Set the right machine number for an Alpha ELF file. */ 366 return bfd_default_set_arch_mach (abfd, bfd_arch_alpha, 0); 367 } 368 369 /* A relocation function which doesn't do anything. */ 371 372 static bfd_reloc_status_type 373 elf64_alpha_reloc_nil (bfd *abfd ATTRIBUTE_UNUSED, arelent *reloc, 374 asymbol *sym ATTRIBUTE_UNUSED, 375 void * data ATTRIBUTE_UNUSED, asection *sec, 376 bfd *output_bfd, char **error_message ATTRIBUTE_UNUSED) 377 { 378 if (output_bfd) 379 reloc->address += sec->output_offset; 380 return bfd_reloc_ok; 381 } 382 383 /* A relocation function used for an unsupported reloc. */ 384 385 static bfd_reloc_status_type 386 elf64_alpha_reloc_bad (bfd *abfd ATTRIBUTE_UNUSED, arelent *reloc, 387 asymbol *sym ATTRIBUTE_UNUSED, 388 void * data ATTRIBUTE_UNUSED, asection *sec, 389 bfd *output_bfd, char **error_message ATTRIBUTE_UNUSED) 390 { 391 if (output_bfd) 392 reloc->address += sec->output_offset; 393 return bfd_reloc_notsupported; 394 } 395 396 /* Do the work of the GPDISP relocation. */ 397 398 static bfd_reloc_status_type 399 elf64_alpha_do_reloc_gpdisp (bfd *abfd, bfd_vma gpdisp, bfd_byte *p_ldah, 400 bfd_byte *p_lda) 401 { 402 bfd_reloc_status_type ret = bfd_reloc_ok; 403 bfd_vma addend; 404 unsigned long i_ldah, i_lda; 405 406 i_ldah = bfd_get_32 (abfd, p_ldah); 407 i_lda = bfd_get_32 (abfd, p_lda); 408 409 /* Complain if the instructions are not correct. */ 410 if (((i_ldah >> 26) & 0x3f) != 0x09 411 || ((i_lda >> 26) & 0x3f) != 0x08) 412 ret = bfd_reloc_dangerous; 413 414 /* Extract the user-supplied offset, mirroring the sign extensions 415 that the instructions perform. */ 416 addend = ((i_ldah & 0xffff) << 16) | (i_lda & 0xffff); 417 addend = (addend ^ 0x80008000) - 0x80008000; 418 419 gpdisp += addend; 420 421 if ((bfd_signed_vma) gpdisp < -(bfd_signed_vma) 0x80000000 422 || (bfd_signed_vma) gpdisp >= (bfd_signed_vma) 0x7fff8000) 423 ret = bfd_reloc_overflow; 424 425 /* compensate for the sign extension again. */ 426 i_ldah = ((i_ldah & 0xffff0000) 427 | (((gpdisp >> 16) + ((gpdisp >> 15) & 1)) & 0xffff)); 428 i_lda = (i_lda & 0xffff0000) | (gpdisp & 0xffff); 429 430 bfd_put_32 (abfd, (bfd_vma) i_ldah, p_ldah); 431 bfd_put_32 (abfd, (bfd_vma) i_lda, p_lda); 432 433 return ret; 434 } 435 436 /* The special function for the GPDISP reloc. */ 437 438 static bfd_reloc_status_type 439 elf64_alpha_reloc_gpdisp (bfd *abfd, arelent *reloc_entry, 440 asymbol *sym ATTRIBUTE_UNUSED, void * data, 441 asection *input_section, bfd *output_bfd, 442 char **err_msg) 443 { 444 bfd_reloc_status_type ret; 445 bfd_vma gp, relocation; 446 bfd_vma high_address; 447 bfd_byte *p_ldah, *p_lda; 448 449 /* Don't do anything if we're not doing a final link. */ 450 if (output_bfd) 451 { 452 reloc_entry->address += input_section->output_offset; 453 return bfd_reloc_ok; 454 } 455 456 high_address = bfd_get_section_limit (abfd, input_section); 457 if (reloc_entry->address > high_address 458 || reloc_entry->address + reloc_entry->addend > high_address) 459 return bfd_reloc_outofrange; 460 461 /* The gp used in the portion of the output object to which this 462 input object belongs is cached on the input bfd. */ 463 gp = _bfd_get_gp_value (abfd); 464 465 relocation = (input_section->output_section->vma 466 + input_section->output_offset 467 + reloc_entry->address); 468 469 p_ldah = (bfd_byte *) data + reloc_entry->address; 470 p_lda = p_ldah + reloc_entry->addend; 471 472 ret = elf64_alpha_do_reloc_gpdisp (abfd, gp - relocation, p_ldah, p_lda); 473 474 /* Complain if the instructions are not correct. */ 475 if (ret == bfd_reloc_dangerous) 476 *err_msg = _("GPDISP relocation did not find ldah and lda instructions"); 477 478 return ret; 479 } 480 481 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value 482 from smaller values. Start with zero, widen, *then* decrement. */ 483 #define MINUS_ONE (((bfd_vma)0) - 1) 484 485 486 #define SKIP_HOWTO(N) \ 487 HOWTO(N, 0, 0, 0, 0, 0, complain_overflow_dont, elf64_alpha_reloc_bad, 0, 0, 0, 0, 0) 488 489 static reloc_howto_type elf64_alpha_howto_table[] = 490 { 491 HOWTO (R_ALPHA_NONE, /* type */ 492 0, /* rightshift */ 493 3, /* size (0 = byte, 1 = short, 2 = long) */ 494 0, /* bitsize */ 495 TRUE, /* pc_relative */ 496 0, /* bitpos */ 497 complain_overflow_dont, /* complain_on_overflow */ 498 elf64_alpha_reloc_nil, /* special_function */ 499 "NONE", /* name */ 500 FALSE, /* partial_inplace */ 501 0, /* src_mask */ 502 0, /* dst_mask */ 503 TRUE), /* pcrel_offset */ 504 505 /* A 32 bit reference to a symbol. */ 506 HOWTO (R_ALPHA_REFLONG, /* type */ 507 0, /* rightshift */ 508 2, /* size (0 = byte, 1 = short, 2 = long) */ 509 32, /* bitsize */ 510 FALSE, /* pc_relative */ 511 0, /* bitpos */ 512 complain_overflow_bitfield, /* complain_on_overflow */ 513 bfd_elf_generic_reloc, /* special_function */ 514 "REFLONG", /* name */ 515 FALSE, /* partial_inplace */ 516 0xffffffff, /* src_mask */ 517 0xffffffff, /* dst_mask */ 518 FALSE), /* pcrel_offset */ 519 520 /* A 64 bit reference to a symbol. */ 521 HOWTO (R_ALPHA_REFQUAD, /* type */ 522 0, /* rightshift */ 523 4, /* size (0 = byte, 1 = short, 2 = long) */ 524 64, /* bitsize */ 525 FALSE, /* pc_relative */ 526 0, /* bitpos */ 527 complain_overflow_bitfield, /* complain_on_overflow */ 528 bfd_elf_generic_reloc, /* special_function */ 529 "REFQUAD", /* name */ 530 FALSE, /* partial_inplace */ 531 MINUS_ONE, /* src_mask */ 532 MINUS_ONE, /* dst_mask */ 533 FALSE), /* pcrel_offset */ 534 535 /* A 32 bit GP relative offset. This is just like REFLONG except 536 that when the value is used the value of the gp register will be 537 added in. */ 538 HOWTO (R_ALPHA_GPREL32, /* type */ 539 0, /* rightshift */ 540 2, /* size (0 = byte, 1 = short, 2 = long) */ 541 32, /* bitsize */ 542 FALSE, /* pc_relative */ 543 0, /* bitpos */ 544 complain_overflow_bitfield, /* complain_on_overflow */ 545 bfd_elf_generic_reloc, /* special_function */ 546 "GPREL32", /* name */ 547 FALSE, /* partial_inplace */ 548 0xffffffff, /* src_mask */ 549 0xffffffff, /* dst_mask */ 550 FALSE), /* pcrel_offset */ 551 552 /* Used for an instruction that refers to memory off the GP register. */ 553 HOWTO (R_ALPHA_LITERAL, /* type */ 554 0, /* rightshift */ 555 1, /* size (0 = byte, 1 = short, 2 = long) */ 556 16, /* bitsize */ 557 FALSE, /* pc_relative */ 558 0, /* bitpos */ 559 complain_overflow_signed, /* complain_on_overflow */ 560 bfd_elf_generic_reloc, /* special_function */ 561 "ELF_LITERAL", /* name */ 562 FALSE, /* partial_inplace */ 563 0xffff, /* src_mask */ 564 0xffff, /* dst_mask */ 565 FALSE), /* pcrel_offset */ 566 567 /* This reloc only appears immediately following an ELF_LITERAL reloc. 568 It identifies a use of the literal. The symbol index is special: 569 1 means the literal address is in the base register of a memory 570 format instruction; 2 means the literal address is in the byte 571 offset register of a byte-manipulation instruction; 3 means the 572 literal address is in the target register of a jsr instruction. 573 This does not actually do any relocation. */ 574 HOWTO (R_ALPHA_LITUSE, /* type */ 575 0, /* rightshift */ 576 1, /* size (0 = byte, 1 = short, 2 = long) */ 577 32, /* bitsize */ 578 FALSE, /* pc_relative */ 579 0, /* bitpos */ 580 complain_overflow_dont, /* complain_on_overflow */ 581 elf64_alpha_reloc_nil, /* special_function */ 582 "LITUSE", /* name */ 583 FALSE, /* partial_inplace */ 584 0, /* src_mask */ 585 0, /* dst_mask */ 586 FALSE), /* pcrel_offset */ 587 588 /* Load the gp register. This is always used for a ldah instruction 589 which loads the upper 16 bits of the gp register. The symbol 590 index of the GPDISP instruction is an offset in bytes to the lda 591 instruction that loads the lower 16 bits. The value to use for 592 the relocation is the difference between the GP value and the 593 current location; the load will always be done against a register 594 holding the current address. 595 596 NOTE: Unlike ECOFF, partial in-place relocation is not done. If 597 any offset is present in the instructions, it is an offset from 598 the register to the ldah instruction. This lets us avoid any 599 stupid hackery like inventing a gp value to do partial relocation 600 against. Also unlike ECOFF, we do the whole relocation off of 601 the GPDISP rather than a GPDISP_HI16/GPDISP_LO16 pair. An odd, 602 space consuming bit, that, since all the information was present 603 in the GPDISP_HI16 reloc. */ 604 HOWTO (R_ALPHA_GPDISP, /* type */ 605 16, /* rightshift */ 606 2, /* size (0 = byte, 1 = short, 2 = long) */ 607 16, /* bitsize */ 608 FALSE, /* pc_relative */ 609 0, /* bitpos */ 610 complain_overflow_dont, /* complain_on_overflow */ 611 elf64_alpha_reloc_gpdisp, /* special_function */ 612 "GPDISP", /* name */ 613 FALSE, /* partial_inplace */ 614 0xffff, /* src_mask */ 615 0xffff, /* dst_mask */ 616 TRUE), /* pcrel_offset */ 617 618 /* A 21 bit branch. */ 619 HOWTO (R_ALPHA_BRADDR, /* type */ 620 2, /* rightshift */ 621 2, /* size (0 = byte, 1 = short, 2 = long) */ 622 21, /* bitsize */ 623 TRUE, /* pc_relative */ 624 0, /* bitpos */ 625 complain_overflow_signed, /* complain_on_overflow */ 626 bfd_elf_generic_reloc, /* special_function */ 627 "BRADDR", /* name */ 628 FALSE, /* partial_inplace */ 629 0x1fffff, /* src_mask */ 630 0x1fffff, /* dst_mask */ 631 TRUE), /* pcrel_offset */ 632 633 /* A hint for a jump to a register. */ 634 HOWTO (R_ALPHA_HINT, /* type */ 635 2, /* rightshift */ 636 1, /* size (0 = byte, 1 = short, 2 = long) */ 637 14, /* bitsize */ 638 TRUE, /* pc_relative */ 639 0, /* bitpos */ 640 complain_overflow_dont, /* complain_on_overflow */ 641 bfd_elf_generic_reloc, /* special_function */ 642 "HINT", /* name */ 643 FALSE, /* partial_inplace */ 644 0x3fff, /* src_mask */ 645 0x3fff, /* dst_mask */ 646 TRUE), /* pcrel_offset */ 647 648 /* 16 bit PC relative offset. */ 649 HOWTO (R_ALPHA_SREL16, /* type */ 650 0, /* rightshift */ 651 1, /* size (0 = byte, 1 = short, 2 = long) */ 652 16, /* bitsize */ 653 TRUE, /* pc_relative */ 654 0, /* bitpos */ 655 complain_overflow_signed, /* complain_on_overflow */ 656 bfd_elf_generic_reloc, /* special_function */ 657 "SREL16", /* name */ 658 FALSE, /* partial_inplace */ 659 0xffff, /* src_mask */ 660 0xffff, /* dst_mask */ 661 TRUE), /* pcrel_offset */ 662 663 /* 32 bit PC relative offset. */ 664 HOWTO (R_ALPHA_SREL32, /* type */ 665 0, /* rightshift */ 666 2, /* size (0 = byte, 1 = short, 2 = long) */ 667 32, /* bitsize */ 668 TRUE, /* pc_relative */ 669 0, /* bitpos */ 670 complain_overflow_signed, /* complain_on_overflow */ 671 bfd_elf_generic_reloc, /* special_function */ 672 "SREL32", /* name */ 673 FALSE, /* partial_inplace */ 674 0xffffffff, /* src_mask */ 675 0xffffffff, /* dst_mask */ 676 TRUE), /* pcrel_offset */ 677 678 /* A 64 bit PC relative offset. */ 679 HOWTO (R_ALPHA_SREL64, /* type */ 680 0, /* rightshift */ 681 4, /* size (0 = byte, 1 = short, 2 = long) */ 682 64, /* bitsize */ 683 TRUE, /* pc_relative */ 684 0, /* bitpos */ 685 complain_overflow_signed, /* complain_on_overflow */ 686 bfd_elf_generic_reloc, /* special_function */ 687 "SREL64", /* name */ 688 FALSE, /* partial_inplace */ 689 MINUS_ONE, /* src_mask */ 690 MINUS_ONE, /* dst_mask */ 691 TRUE), /* pcrel_offset */ 692 693 /* Skip 12 - 16; deprecated ECOFF relocs. */ 694 SKIP_HOWTO (12), 695 SKIP_HOWTO (13), 696 SKIP_HOWTO (14), 697 SKIP_HOWTO (15), 698 SKIP_HOWTO (16), 699 700 /* The high 16 bits of the displacement from GP to the target. */ 701 HOWTO (R_ALPHA_GPRELHIGH, 702 0, /* rightshift */ 703 1, /* size (0 = byte, 1 = short, 2 = long) */ 704 16, /* bitsize */ 705 FALSE, /* pc_relative */ 706 0, /* bitpos */ 707 complain_overflow_signed, /* complain_on_overflow */ 708 bfd_elf_generic_reloc, /* special_function */ 709 "GPRELHIGH", /* name */ 710 FALSE, /* partial_inplace */ 711 0xffff, /* src_mask */ 712 0xffff, /* dst_mask */ 713 FALSE), /* pcrel_offset */ 714 715 /* The low 16 bits of the displacement from GP to the target. */ 716 HOWTO (R_ALPHA_GPRELLOW, 717 0, /* rightshift */ 718 1, /* size (0 = byte, 1 = short, 2 = long) */ 719 16, /* bitsize */ 720 FALSE, /* pc_relative */ 721 0, /* bitpos */ 722 complain_overflow_dont, /* complain_on_overflow */ 723 bfd_elf_generic_reloc, /* special_function */ 724 "GPRELLOW", /* name */ 725 FALSE, /* partial_inplace */ 726 0xffff, /* src_mask */ 727 0xffff, /* dst_mask */ 728 FALSE), /* pcrel_offset */ 729 730 /* A 16-bit displacement from the GP to the target. */ 731 HOWTO (R_ALPHA_GPREL16, 732 0, /* rightshift */ 733 1, /* size (0 = byte, 1 = short, 2 = long) */ 734 16, /* bitsize */ 735 FALSE, /* pc_relative */ 736 0, /* bitpos */ 737 complain_overflow_signed, /* complain_on_overflow */ 738 bfd_elf_generic_reloc, /* special_function */ 739 "GPREL16", /* name */ 740 FALSE, /* partial_inplace */ 741 0xffff, /* src_mask */ 742 0xffff, /* dst_mask */ 743 FALSE), /* pcrel_offset */ 744 745 /* Skip 20 - 23; deprecated ECOFF relocs. */ 746 SKIP_HOWTO (20), 747 SKIP_HOWTO (21), 748 SKIP_HOWTO (22), 749 SKIP_HOWTO (23), 750 751 /* Misc ELF relocations. */ 752 753 /* A dynamic relocation to copy the target into our .dynbss section. */ 754 /* Not generated, as all Alpha objects use PIC, so it is not needed. It 755 is present because every other ELF has one, but should not be used 756 because .dynbss is an ugly thing. */ 757 HOWTO (R_ALPHA_COPY, 758 0, 759 0, 760 0, 761 FALSE, 762 0, 763 complain_overflow_dont, 764 bfd_elf_generic_reloc, 765 "COPY", 766 FALSE, 767 0, 768 0, 769 TRUE), 770 771 /* A dynamic relocation for a .got entry. */ 772 HOWTO (R_ALPHA_GLOB_DAT, 773 0, 774 0, 775 0, 776 FALSE, 777 0, 778 complain_overflow_dont, 779 bfd_elf_generic_reloc, 780 "GLOB_DAT", 781 FALSE, 782 0, 783 0, 784 TRUE), 785 786 /* A dynamic relocation for a .plt entry. */ 787 HOWTO (R_ALPHA_JMP_SLOT, 788 0, 789 0, 790 0, 791 FALSE, 792 0, 793 complain_overflow_dont, 794 bfd_elf_generic_reloc, 795 "JMP_SLOT", 796 FALSE, 797 0, 798 0, 799 TRUE), 800 801 /* A dynamic relocation to add the base of the DSO to a 64-bit field. */ 802 HOWTO (R_ALPHA_RELATIVE, 803 0, 804 0, 805 0, 806 FALSE, 807 0, 808 complain_overflow_dont, 809 bfd_elf_generic_reloc, 810 "RELATIVE", 811 FALSE, 812 0, 813 0, 814 TRUE), 815 816 /* A 21 bit branch that adjusts for gp loads. */ 817 HOWTO (R_ALPHA_BRSGP, /* type */ 818 2, /* rightshift */ 819 2, /* size (0 = byte, 1 = short, 2 = long) */ 820 21, /* bitsize */ 821 TRUE, /* pc_relative */ 822 0, /* bitpos */ 823 complain_overflow_signed, /* complain_on_overflow */ 824 bfd_elf_generic_reloc, /* special_function */ 825 "BRSGP", /* name */ 826 FALSE, /* partial_inplace */ 827 0x1fffff, /* src_mask */ 828 0x1fffff, /* dst_mask */ 829 TRUE), /* pcrel_offset */ 830 831 /* Creates a tls_index for the symbol in the got. */ 832 HOWTO (R_ALPHA_TLSGD, /* type */ 833 0, /* rightshift */ 834 1, /* size (0 = byte, 1 = short, 2 = long) */ 835 16, /* bitsize */ 836 FALSE, /* pc_relative */ 837 0, /* bitpos */ 838 complain_overflow_signed, /* complain_on_overflow */ 839 bfd_elf_generic_reloc, /* special_function */ 840 "TLSGD", /* name */ 841 FALSE, /* partial_inplace */ 842 0xffff, /* src_mask */ 843 0xffff, /* dst_mask */ 844 FALSE), /* pcrel_offset */ 845 846 /* Creates a tls_index for the (current) module in the got. */ 847 HOWTO (R_ALPHA_TLSLDM, /* type */ 848 0, /* rightshift */ 849 1, /* size (0 = byte, 1 = short, 2 = long) */ 850 16, /* bitsize */ 851 FALSE, /* pc_relative */ 852 0, /* bitpos */ 853 complain_overflow_signed, /* complain_on_overflow */ 854 bfd_elf_generic_reloc, /* special_function */ 855 "TLSLDM", /* name */ 856 FALSE, /* partial_inplace */ 857 0xffff, /* src_mask */ 858 0xffff, /* dst_mask */ 859 FALSE), /* pcrel_offset */ 860 861 /* A dynamic relocation for a DTP module entry. */ 862 HOWTO (R_ALPHA_DTPMOD64, /* type */ 863 0, /* rightshift */ 864 4, /* size (0 = byte, 1 = short, 2 = long) */ 865 64, /* bitsize */ 866 FALSE, /* pc_relative */ 867 0, /* bitpos */ 868 complain_overflow_bitfield, /* complain_on_overflow */ 869 bfd_elf_generic_reloc, /* special_function */ 870 "DTPMOD64", /* name */ 871 FALSE, /* partial_inplace */ 872 MINUS_ONE, /* src_mask */ 873 MINUS_ONE, /* dst_mask */ 874 FALSE), /* pcrel_offset */ 875 876 /* Creates a 64-bit offset in the got for the displacement 877 from DTP to the target. */ 878 HOWTO (R_ALPHA_GOTDTPREL, /* type */ 879 0, /* rightshift */ 880 1, /* size (0 = byte, 1 = short, 2 = long) */ 881 16, /* bitsize */ 882 FALSE, /* pc_relative */ 883 0, /* bitpos */ 884 complain_overflow_signed, /* complain_on_overflow */ 885 bfd_elf_generic_reloc, /* special_function */ 886 "GOTDTPREL", /* name */ 887 FALSE, /* partial_inplace */ 888 0xffff, /* src_mask */ 889 0xffff, /* dst_mask */ 890 FALSE), /* pcrel_offset */ 891 892 /* A dynamic relocation for a displacement from DTP to the target. */ 893 HOWTO (R_ALPHA_DTPREL64, /* type */ 894 0, /* rightshift */ 895 4, /* size (0 = byte, 1 = short, 2 = long) */ 896 64, /* bitsize */ 897 FALSE, /* pc_relative */ 898 0, /* bitpos */ 899 complain_overflow_bitfield, /* complain_on_overflow */ 900 bfd_elf_generic_reloc, /* special_function */ 901 "DTPREL64", /* name */ 902 FALSE, /* partial_inplace */ 903 MINUS_ONE, /* src_mask */ 904 MINUS_ONE, /* dst_mask */ 905 FALSE), /* pcrel_offset */ 906 907 /* The high 16 bits of the displacement from DTP to the target. */ 908 HOWTO (R_ALPHA_DTPRELHI, /* type */ 909 0, /* rightshift */ 910 1, /* size (0 = byte, 1 = short, 2 = long) */ 911 16, /* bitsize */ 912 FALSE, /* pc_relative */ 913 0, /* bitpos */ 914 complain_overflow_signed, /* complain_on_overflow */ 915 bfd_elf_generic_reloc, /* special_function */ 916 "DTPRELHI", /* name */ 917 FALSE, /* partial_inplace */ 918 0xffff, /* src_mask */ 919 0xffff, /* dst_mask */ 920 FALSE), /* pcrel_offset */ 921 922 /* The low 16 bits of the displacement from DTP to the target. */ 923 HOWTO (R_ALPHA_DTPRELLO, /* type */ 924 0, /* rightshift */ 925 1, /* size (0 = byte, 1 = short, 2 = long) */ 926 16, /* bitsize */ 927 FALSE, /* pc_relative */ 928 0, /* bitpos */ 929 complain_overflow_dont, /* complain_on_overflow */ 930 bfd_elf_generic_reloc, /* special_function */ 931 "DTPRELLO", /* name */ 932 FALSE, /* partial_inplace */ 933 0xffff, /* src_mask */ 934 0xffff, /* dst_mask */ 935 FALSE), /* pcrel_offset */ 936 937 /* A 16-bit displacement from DTP to the target. */ 938 HOWTO (R_ALPHA_DTPREL16, /* type */ 939 0, /* rightshift */ 940 1, /* size (0 = byte, 1 = short, 2 = long) */ 941 16, /* bitsize */ 942 FALSE, /* pc_relative */ 943 0, /* bitpos */ 944 complain_overflow_signed, /* complain_on_overflow */ 945 bfd_elf_generic_reloc, /* special_function */ 946 "DTPREL16", /* name */ 947 FALSE, /* partial_inplace */ 948 0xffff, /* src_mask */ 949 0xffff, /* dst_mask */ 950 FALSE), /* pcrel_offset */ 951 952 /* Creates a 64-bit offset in the got for the displacement 953 from TP to the target. */ 954 HOWTO (R_ALPHA_GOTTPREL, /* type */ 955 0, /* rightshift */ 956 1, /* size (0 = byte, 1 = short, 2 = long) */ 957 16, /* bitsize */ 958 FALSE, /* pc_relative */ 959 0, /* bitpos */ 960 complain_overflow_signed, /* complain_on_overflow */ 961 bfd_elf_generic_reloc, /* special_function */ 962 "GOTTPREL", /* name */ 963 FALSE, /* partial_inplace */ 964 0xffff, /* src_mask */ 965 0xffff, /* dst_mask */ 966 FALSE), /* pcrel_offset */ 967 968 /* A dynamic relocation for a displacement from TP to the target. */ 969 HOWTO (R_ALPHA_TPREL64, /* type */ 970 0, /* rightshift */ 971 4, /* size (0 = byte, 1 = short, 2 = long) */ 972 64, /* bitsize */ 973 FALSE, /* pc_relative */ 974 0, /* bitpos */ 975 complain_overflow_bitfield, /* complain_on_overflow */ 976 bfd_elf_generic_reloc, /* special_function */ 977 "TPREL64", /* name */ 978 FALSE, /* partial_inplace */ 979 MINUS_ONE, /* src_mask */ 980 MINUS_ONE, /* dst_mask */ 981 FALSE), /* pcrel_offset */ 982 983 /* The high 16 bits of the displacement from TP to the target. */ 984 HOWTO (R_ALPHA_TPRELHI, /* type */ 985 0, /* rightshift */ 986 1, /* size (0 = byte, 1 = short, 2 = long) */ 987 16, /* bitsize */ 988 FALSE, /* pc_relative */ 989 0, /* bitpos */ 990 complain_overflow_signed, /* complain_on_overflow */ 991 bfd_elf_generic_reloc, /* special_function */ 992 "TPRELHI", /* name */ 993 FALSE, /* partial_inplace */ 994 0xffff, /* src_mask */ 995 0xffff, /* dst_mask */ 996 FALSE), /* pcrel_offset */ 997 998 /* The low 16 bits of the displacement from TP to the target. */ 999 HOWTO (R_ALPHA_TPRELLO, /* type */ 1000 0, /* rightshift */ 1001 1, /* size (0 = byte, 1 = short, 2 = long) */ 1002 16, /* bitsize */ 1003 FALSE, /* pc_relative */ 1004 0, /* bitpos */ 1005 complain_overflow_dont, /* complain_on_overflow */ 1006 bfd_elf_generic_reloc, /* special_function */ 1007 "TPRELLO", /* name */ 1008 FALSE, /* partial_inplace */ 1009 0xffff, /* src_mask */ 1010 0xffff, /* dst_mask */ 1011 FALSE), /* pcrel_offset */ 1012 1013 /* A 16-bit displacement from TP to the target. */ 1014 HOWTO (R_ALPHA_TPREL16, /* type */ 1015 0, /* rightshift */ 1016 1, /* size (0 = byte, 1 = short, 2 = long) */ 1017 16, /* bitsize */ 1018 FALSE, /* pc_relative */ 1019 0, /* bitpos */ 1020 complain_overflow_signed, /* complain_on_overflow */ 1021 bfd_elf_generic_reloc, /* special_function */ 1022 "TPREL16", /* name */ 1023 FALSE, /* partial_inplace */ 1024 0xffff, /* src_mask */ 1025 0xffff, /* dst_mask */ 1026 FALSE), /* pcrel_offset */ 1027 }; 1028 1029 /* A mapping from BFD reloc types to Alpha ELF reloc types. */ 1030 1031 struct elf_reloc_map 1032 { 1033 bfd_reloc_code_real_type bfd_reloc_val; 1034 int elf_reloc_val; 1035 }; 1036 1037 static const struct elf_reloc_map elf64_alpha_reloc_map[] = 1038 { 1039 {BFD_RELOC_NONE, R_ALPHA_NONE}, 1040 {BFD_RELOC_32, R_ALPHA_REFLONG}, 1041 {BFD_RELOC_64, R_ALPHA_REFQUAD}, 1042 {BFD_RELOC_CTOR, R_ALPHA_REFQUAD}, 1043 {BFD_RELOC_GPREL32, R_ALPHA_GPREL32}, 1044 {BFD_RELOC_ALPHA_ELF_LITERAL, R_ALPHA_LITERAL}, 1045 {BFD_RELOC_ALPHA_LITUSE, R_ALPHA_LITUSE}, 1046 {BFD_RELOC_ALPHA_GPDISP, R_ALPHA_GPDISP}, 1047 {BFD_RELOC_23_PCREL_S2, R_ALPHA_BRADDR}, 1048 {BFD_RELOC_ALPHA_HINT, R_ALPHA_HINT}, 1049 {BFD_RELOC_16_PCREL, R_ALPHA_SREL16}, 1050 {BFD_RELOC_32_PCREL, R_ALPHA_SREL32}, 1051 {BFD_RELOC_64_PCREL, R_ALPHA_SREL64}, 1052 {BFD_RELOC_ALPHA_GPREL_HI16, R_ALPHA_GPRELHIGH}, 1053 {BFD_RELOC_ALPHA_GPREL_LO16, R_ALPHA_GPRELLOW}, 1054 {BFD_RELOC_GPREL16, R_ALPHA_GPREL16}, 1055 {BFD_RELOC_ALPHA_BRSGP, R_ALPHA_BRSGP}, 1056 {BFD_RELOC_ALPHA_TLSGD, R_ALPHA_TLSGD}, 1057 {BFD_RELOC_ALPHA_TLSLDM, R_ALPHA_TLSLDM}, 1058 {BFD_RELOC_ALPHA_DTPMOD64, R_ALPHA_DTPMOD64}, 1059 {BFD_RELOC_ALPHA_GOTDTPREL16, R_ALPHA_GOTDTPREL}, 1060 {BFD_RELOC_ALPHA_DTPREL64, R_ALPHA_DTPREL64}, 1061 {BFD_RELOC_ALPHA_DTPREL_HI16, R_ALPHA_DTPRELHI}, 1062 {BFD_RELOC_ALPHA_DTPREL_LO16, R_ALPHA_DTPRELLO}, 1063 {BFD_RELOC_ALPHA_DTPREL16, R_ALPHA_DTPREL16}, 1064 {BFD_RELOC_ALPHA_GOTTPREL16, R_ALPHA_GOTTPREL}, 1065 {BFD_RELOC_ALPHA_TPREL64, R_ALPHA_TPREL64}, 1066 {BFD_RELOC_ALPHA_TPREL_HI16, R_ALPHA_TPRELHI}, 1067 {BFD_RELOC_ALPHA_TPREL_LO16, R_ALPHA_TPRELLO}, 1068 {BFD_RELOC_ALPHA_TPREL16, R_ALPHA_TPREL16}, 1069 }; 1070 1071 /* Given a BFD reloc type, return a HOWTO structure. */ 1072 1073 static reloc_howto_type * 1074 elf64_alpha_bfd_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED, 1075 bfd_reloc_code_real_type code) 1076 { 1077 const struct elf_reloc_map *i, *e; 1078 i = e = elf64_alpha_reloc_map; 1079 e += sizeof (elf64_alpha_reloc_map) / sizeof (struct elf_reloc_map); 1080 for (; i != e; ++i) 1081 { 1082 if (i->bfd_reloc_val == code) 1083 return &elf64_alpha_howto_table[i->elf_reloc_val]; 1084 } 1085 return 0; 1086 } 1087 1088 static reloc_howto_type * 1089 elf64_alpha_bfd_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, 1090 const char *r_name) 1091 { 1092 unsigned int i; 1093 1094 for (i = 0; 1095 i < (sizeof (elf64_alpha_howto_table) 1096 / sizeof (elf64_alpha_howto_table[0])); 1097 i++) 1098 if (elf64_alpha_howto_table[i].name != NULL 1099 && strcasecmp (elf64_alpha_howto_table[i].name, r_name) == 0) 1100 return &elf64_alpha_howto_table[i]; 1101 1102 return NULL; 1103 } 1104 1105 /* Given an Alpha ELF reloc type, fill in an arelent structure. */ 1106 1107 static void 1108 elf64_alpha_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, arelent *cache_ptr, 1109 Elf_Internal_Rela *dst) 1110 { 1111 unsigned r_type = ELF64_R_TYPE(dst->r_info); 1112 1113 if (r_type >= R_ALPHA_max) 1114 { 1115 (*_bfd_error_handler) (_("%B: unrecognised Alpha reloc number: %d"), 1116 abfd, r_type); 1117 bfd_set_error (bfd_error_bad_value); 1118 r_type = R_ALPHA_NONE; 1119 } 1120 cache_ptr->howto = &elf64_alpha_howto_table[r_type]; 1121 } 1122 1123 /* These two relocations create a two-word entry in the got. */ 1124 #define alpha_got_entry_size(r_type) \ 1125 (r_type == R_ALPHA_TLSGD || r_type == R_ALPHA_TLSLDM ? 16 : 8) 1126 1127 /* This is PT_TLS segment p_vaddr. */ 1128 #define alpha_get_dtprel_base(info) \ 1129 (elf_hash_table (info)->tls_sec->vma) 1130 1131 /* Main program TLS (whose template starts at PT_TLS p_vaddr) 1132 is assigned offset round(16, PT_TLS p_align). */ 1133 #define alpha_get_tprel_base(info) \ 1134 (elf_hash_table (info)->tls_sec->vma \ 1135 - align_power ((bfd_vma) 16, \ 1136 elf_hash_table (info)->tls_sec->alignment_power)) 1137 1138 /* Handle an Alpha specific section when reading an object file. This 1140 is called when bfd_section_from_shdr finds a section with an unknown 1141 type. 1142 FIXME: We need to handle the SHF_ALPHA_GPREL flag, but I'm not sure 1143 how to. */ 1144 1145 static bfd_boolean 1146 elf64_alpha_section_from_shdr (bfd *abfd, 1147 Elf_Internal_Shdr *hdr, 1148 const char *name, 1149 int shindex) 1150 { 1151 asection *newsect; 1152 1153 /* There ought to be a place to keep ELF backend specific flags, but 1154 at the moment there isn't one. We just keep track of the 1155 sections by their name, instead. Fortunately, the ABI gives 1156 suggested names for all the MIPS specific sections, so we will 1157 probably get away with this. */ 1158 switch (hdr->sh_type) 1159 { 1160 case SHT_ALPHA_DEBUG: 1161 if (strcmp (name, ".mdebug") != 0) 1162 return FALSE; 1163 break; 1164 default: 1165 return FALSE; 1166 } 1167 1168 if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex)) 1169 return FALSE; 1170 newsect = hdr->bfd_section; 1171 1172 if (hdr->sh_type == SHT_ALPHA_DEBUG) 1173 { 1174 if (! bfd_set_section_flags (abfd, newsect, 1175 (bfd_get_section_flags (abfd, newsect) 1176 | SEC_DEBUGGING))) 1177 return FALSE; 1178 } 1179 1180 return TRUE; 1181 } 1182 1183 /* Convert Alpha specific section flags to bfd internal section flags. */ 1184 1185 static bfd_boolean 1186 elf64_alpha_section_flags (flagword *flags, const Elf_Internal_Shdr *hdr) 1187 { 1188 if (hdr->sh_flags & SHF_ALPHA_GPREL) 1189 *flags |= SEC_SMALL_DATA; 1190 1191 return TRUE; 1192 } 1193 1194 /* Set the correct type for an Alpha ELF section. We do this by the 1195 section name, which is a hack, but ought to work. */ 1196 1197 static bfd_boolean 1198 elf64_alpha_fake_sections (bfd *abfd, Elf_Internal_Shdr *hdr, asection *sec) 1199 { 1200 register const char *name; 1201 1202 name = bfd_get_section_name (abfd, sec); 1203 1204 if (strcmp (name, ".mdebug") == 0) 1205 { 1206 hdr->sh_type = SHT_ALPHA_DEBUG; 1207 /* In a shared object on Irix 5.3, the .mdebug section has an 1208 entsize of 0. FIXME: Does this matter? */ 1209 if ((abfd->flags & DYNAMIC) != 0 ) 1210 hdr->sh_entsize = 0; 1211 else 1212 hdr->sh_entsize = 1; 1213 } 1214 else if ((sec->flags & SEC_SMALL_DATA) 1215 || strcmp (name, ".sdata") == 0 1216 || strcmp (name, ".sbss") == 0 1217 || strcmp (name, ".lit4") == 0 1218 || strcmp (name, ".lit8") == 0) 1219 hdr->sh_flags |= SHF_ALPHA_GPREL; 1220 1221 return TRUE; 1222 } 1223 1224 /* Hook called by the linker routine which adds symbols from an object 1225 file. We use it to put .comm items in .sbss, and not .bss. */ 1226 1227 static bfd_boolean 1228 elf64_alpha_add_symbol_hook (bfd *abfd, struct bfd_link_info *info, 1229 Elf_Internal_Sym *sym, 1230 const char **namep ATTRIBUTE_UNUSED, 1231 flagword *flagsp ATTRIBUTE_UNUSED, 1232 asection **secp, bfd_vma *valp) 1233 { 1234 if (sym->st_shndx == SHN_COMMON 1235 && !bfd_link_relocatable (info) 1236 && sym->st_size <= elf_gp_size (abfd)) 1237 { 1238 /* Common symbols less than or equal to -G nn bytes are 1239 automatically put into .sbss. */ 1240 1241 asection *scomm = bfd_get_section_by_name (abfd, ".scommon"); 1242 1243 if (scomm == NULL) 1244 { 1245 scomm = bfd_make_section_with_flags (abfd, ".scommon", 1246 (SEC_ALLOC 1247 | SEC_IS_COMMON 1248 | SEC_LINKER_CREATED)); 1249 if (scomm == NULL) 1250 return FALSE; 1251 } 1252 1253 *secp = scomm; 1254 *valp = sym->st_size; 1255 } 1256 1257 return TRUE; 1258 } 1259 1260 /* Create the .got section. */ 1261 1262 static bfd_boolean 1263 elf64_alpha_create_got_section (bfd *abfd, 1264 struct bfd_link_info *info ATTRIBUTE_UNUSED) 1265 { 1266 flagword flags; 1267 asection *s; 1268 1269 if (! is_alpha_elf (abfd)) 1270 return FALSE; 1271 1272 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY 1273 | SEC_LINKER_CREATED); 1274 s = bfd_make_section_anyway_with_flags (abfd, ".got", flags); 1275 if (s == NULL 1276 || !bfd_set_section_alignment (abfd, s, 3)) 1277 return FALSE; 1278 1279 alpha_elf_tdata (abfd)->got = s; 1280 1281 /* Make sure the object's gotobj is set to itself so that we default 1282 to every object with its own .got. We'll merge .gots later once 1283 we've collected each object's info. */ 1284 alpha_elf_tdata (abfd)->gotobj = abfd; 1285 1286 return TRUE; 1287 } 1288 1289 /* Create all the dynamic sections. */ 1290 1291 static bfd_boolean 1292 elf64_alpha_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info) 1293 { 1294 asection *s; 1295 flagword flags; 1296 struct elf_link_hash_entry *h; 1297 1298 if (! is_alpha_elf (abfd)) 1299 return FALSE; 1300 1301 /* We need to create .plt, .rela.plt, .got, and .rela.got sections. */ 1302 1303 flags = (SEC_ALLOC | SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS | SEC_IN_MEMORY 1304 | SEC_LINKER_CREATED 1305 | (elf64_alpha_use_secureplt ? SEC_READONLY : 0)); 1306 s = bfd_make_section_anyway_with_flags (abfd, ".plt", flags); 1307 if (s == NULL || ! bfd_set_section_alignment (abfd, s, 4)) 1308 return FALSE; 1309 1310 /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the 1311 .plt section. */ 1312 h = _bfd_elf_define_linkage_sym (abfd, info, s, 1313 "_PROCEDURE_LINKAGE_TABLE_"); 1314 elf_hash_table (info)->hplt = h; 1315 if (h == NULL) 1316 return FALSE; 1317 1318 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY 1319 | SEC_LINKER_CREATED | SEC_READONLY); 1320 s = bfd_make_section_anyway_with_flags (abfd, ".rela.plt", flags); 1321 if (s == NULL || ! bfd_set_section_alignment (abfd, s, 3)) 1322 return FALSE; 1323 1324 if (elf64_alpha_use_secureplt) 1325 { 1326 flags = SEC_ALLOC | SEC_LINKER_CREATED; 1327 s = bfd_make_section_anyway_with_flags (abfd, ".got.plt", flags); 1328 if (s == NULL || ! bfd_set_section_alignment (abfd, s, 3)) 1329 return FALSE; 1330 } 1331 1332 /* We may or may not have created a .got section for this object, but 1333 we definitely havn't done the rest of the work. */ 1334 1335 if (alpha_elf_tdata(abfd)->gotobj == NULL) 1336 { 1337 if (!elf64_alpha_create_got_section (abfd, info)) 1338 return FALSE; 1339 } 1340 1341 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY 1342 | SEC_LINKER_CREATED | SEC_READONLY); 1343 s = bfd_make_section_anyway_with_flags (abfd, ".rela.got", flags); 1344 if (s == NULL 1345 || !bfd_set_section_alignment (abfd, s, 3)) 1346 return FALSE; 1347 1348 /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the 1349 dynobj's .got section. We don't do this in the linker script 1350 because we don't want to define the symbol if we are not creating 1351 a global offset table. */ 1352 h = _bfd_elf_define_linkage_sym (abfd, info, alpha_elf_tdata(abfd)->got, 1353 "_GLOBAL_OFFSET_TABLE_"); 1354 elf_hash_table (info)->hgot = h; 1355 if (h == NULL) 1356 return FALSE; 1357 1358 return TRUE; 1359 } 1360 1361 /* Read ECOFF debugging information from a .mdebug section into a 1363 ecoff_debug_info structure. */ 1364 1365 static bfd_boolean 1366 elf64_alpha_read_ecoff_info (bfd *abfd, asection *section, 1367 struct ecoff_debug_info *debug) 1368 { 1369 HDRR *symhdr; 1370 const struct ecoff_debug_swap *swap; 1371 char *ext_hdr = NULL; 1372 1373 swap = get_elf_backend_data (abfd)->elf_backend_ecoff_debug_swap; 1374 memset (debug, 0, sizeof (*debug)); 1375 1376 ext_hdr = (char *) bfd_malloc (swap->external_hdr_size); 1377 if (ext_hdr == NULL && swap->external_hdr_size != 0) 1378 goto error_return; 1379 1380 if (! bfd_get_section_contents (abfd, section, ext_hdr, (file_ptr) 0, 1381 swap->external_hdr_size)) 1382 goto error_return; 1383 1384 symhdr = &debug->symbolic_header; 1385 (*swap->swap_hdr_in) (abfd, ext_hdr, symhdr); 1386 1387 /* The symbolic header contains absolute file offsets and sizes to 1388 read. */ 1389 #define READ(ptr, offset, count, size, type) \ 1390 if (symhdr->count == 0) \ 1391 debug->ptr = NULL; \ 1392 else \ 1393 { \ 1394 bfd_size_type amt = (bfd_size_type) size * symhdr->count; \ 1395 debug->ptr = (type) bfd_malloc (amt); \ 1396 if (debug->ptr == NULL) \ 1397 goto error_return; \ 1398 if (bfd_seek (abfd, (file_ptr) symhdr->offset, SEEK_SET) != 0 \ 1399 || bfd_bread (debug->ptr, amt, abfd) != amt) \ 1400 goto error_return; \ 1401 } 1402 1403 READ (line, cbLineOffset, cbLine, sizeof (unsigned char), unsigned char *); 1404 READ (external_dnr, cbDnOffset, idnMax, swap->external_dnr_size, void *); 1405 READ (external_pdr, cbPdOffset, ipdMax, swap->external_pdr_size, void *); 1406 READ (external_sym, cbSymOffset, isymMax, swap->external_sym_size, void *); 1407 READ (external_opt, cbOptOffset, ioptMax, swap->external_opt_size, void *); 1408 READ (external_aux, cbAuxOffset, iauxMax, sizeof (union aux_ext), 1409 union aux_ext *); 1410 READ (ss, cbSsOffset, issMax, sizeof (char), char *); 1411 READ (ssext, cbSsExtOffset, issExtMax, sizeof (char), char *); 1412 READ (external_fdr, cbFdOffset, ifdMax, swap->external_fdr_size, void *); 1413 READ (external_rfd, cbRfdOffset, crfd, swap->external_rfd_size, void *); 1414 READ (external_ext, cbExtOffset, iextMax, swap->external_ext_size, void *); 1415 #undef READ 1416 1417 debug->fdr = NULL; 1418 1419 return TRUE; 1420 1421 error_return: 1422 if (ext_hdr != NULL) 1423 free (ext_hdr); 1424 if (debug->line != NULL) 1425 free (debug->line); 1426 if (debug->external_dnr != NULL) 1427 free (debug->external_dnr); 1428 if (debug->external_pdr != NULL) 1429 free (debug->external_pdr); 1430 if (debug->external_sym != NULL) 1431 free (debug->external_sym); 1432 if (debug->external_opt != NULL) 1433 free (debug->external_opt); 1434 if (debug->external_aux != NULL) 1435 free (debug->external_aux); 1436 if (debug->ss != NULL) 1437 free (debug->ss); 1438 if (debug->ssext != NULL) 1439 free (debug->ssext); 1440 if (debug->external_fdr != NULL) 1441 free (debug->external_fdr); 1442 if (debug->external_rfd != NULL) 1443 free (debug->external_rfd); 1444 if (debug->external_ext != NULL) 1445 free (debug->external_ext); 1446 return FALSE; 1447 } 1448 1449 /* Alpha ELF local labels start with '$'. */ 1450 1451 static bfd_boolean 1452 elf64_alpha_is_local_label_name (bfd *abfd ATTRIBUTE_UNUSED, const char *name) 1453 { 1454 return name[0] == '$'; 1455 } 1456 1457 static bfd_boolean 1458 elf64_alpha_find_nearest_line (bfd *abfd, asymbol **symbols, 1459 asection *section, bfd_vma offset, 1460 const char **filename_ptr, 1461 const char **functionname_ptr, 1462 unsigned int *line_ptr, 1463 unsigned int *discriminator_ptr) 1464 { 1465 asection *msec; 1466 1467 if (_bfd_dwarf2_find_nearest_line (abfd, symbols, NULL, section, offset, 1468 filename_ptr, functionname_ptr, 1469 line_ptr, discriminator_ptr, 1470 dwarf_debug_sections, 0, 1471 &elf_tdata (abfd)->dwarf2_find_line_info)) 1472 return TRUE; 1473 1474 msec = bfd_get_section_by_name (abfd, ".mdebug"); 1475 if (msec != NULL) 1476 { 1477 flagword origflags; 1478 struct alpha_elf_find_line *fi; 1479 const struct ecoff_debug_swap * const swap = 1480 get_elf_backend_data (abfd)->elf_backend_ecoff_debug_swap; 1481 1482 /* If we are called during a link, alpha_elf_final_link may have 1483 cleared the SEC_HAS_CONTENTS field. We force it back on here 1484 if appropriate (which it normally will be). */ 1485 origflags = msec->flags; 1486 if (elf_section_data (msec)->this_hdr.sh_type != SHT_NOBITS) 1487 msec->flags |= SEC_HAS_CONTENTS; 1488 1489 fi = alpha_elf_tdata (abfd)->find_line_info; 1490 if (fi == NULL) 1491 { 1492 bfd_size_type external_fdr_size; 1493 char *fraw_src; 1494 char *fraw_end; 1495 struct fdr *fdr_ptr; 1496 bfd_size_type amt = sizeof (struct alpha_elf_find_line); 1497 1498 fi = (struct alpha_elf_find_line *) bfd_zalloc (abfd, amt); 1499 if (fi == NULL) 1500 { 1501 msec->flags = origflags; 1502 return FALSE; 1503 } 1504 1505 if (!elf64_alpha_read_ecoff_info (abfd, msec, &fi->d)) 1506 { 1507 msec->flags = origflags; 1508 return FALSE; 1509 } 1510 1511 /* Swap in the FDR information. */ 1512 amt = fi->d.symbolic_header.ifdMax * sizeof (struct fdr); 1513 fi->d.fdr = (struct fdr *) bfd_alloc (abfd, amt); 1514 if (fi->d.fdr == NULL) 1515 { 1516 msec->flags = origflags; 1517 return FALSE; 1518 } 1519 external_fdr_size = swap->external_fdr_size; 1520 fdr_ptr = fi->d.fdr; 1521 fraw_src = (char *) fi->d.external_fdr; 1522 fraw_end = (fraw_src 1523 + fi->d.symbolic_header.ifdMax * external_fdr_size); 1524 for (; fraw_src < fraw_end; fraw_src += external_fdr_size, fdr_ptr++) 1525 (*swap->swap_fdr_in) (abfd, fraw_src, fdr_ptr); 1526 1527 alpha_elf_tdata (abfd)->find_line_info = fi; 1528 1529 /* Note that we don't bother to ever free this information. 1530 find_nearest_line is either called all the time, as in 1531 objdump -l, so the information should be saved, or it is 1532 rarely called, as in ld error messages, so the memory 1533 wasted is unimportant. Still, it would probably be a 1534 good idea for free_cached_info to throw it away. */ 1535 } 1536 1537 if (_bfd_ecoff_locate_line (abfd, section, offset, &fi->d, swap, 1538 &fi->i, filename_ptr, functionname_ptr, 1539 line_ptr)) 1540 { 1541 msec->flags = origflags; 1542 return TRUE; 1543 } 1544 1545 msec->flags = origflags; 1546 } 1547 1548 /* Fall back on the generic ELF find_nearest_line routine. */ 1549 1550 return _bfd_elf_find_nearest_line (abfd, symbols, section, offset, 1551 filename_ptr, functionname_ptr, 1552 line_ptr, discriminator_ptr); 1553 } 1554 1555 /* Structure used to pass information to alpha_elf_output_extsym. */ 1557 1558 struct extsym_info 1559 { 1560 bfd *abfd; 1561 struct bfd_link_info *info; 1562 struct ecoff_debug_info *debug; 1563 const struct ecoff_debug_swap *swap; 1564 bfd_boolean failed; 1565 }; 1566 1567 static bfd_boolean 1568 elf64_alpha_output_extsym (struct alpha_elf_link_hash_entry *h, void * data) 1569 { 1570 struct extsym_info *einfo = (struct extsym_info *) data; 1571 bfd_boolean strip; 1572 asection *sec, *output_section; 1573 1574 if (h->root.indx == -2) 1575 strip = FALSE; 1576 else if ((h->root.def_dynamic 1577 || h->root.ref_dynamic 1578 || h->root.root.type == bfd_link_hash_new) 1579 && !h->root.def_regular 1580 && !h->root.ref_regular) 1581 strip = TRUE; 1582 else if (einfo->info->strip == strip_all 1583 || (einfo->info->strip == strip_some 1584 && bfd_hash_lookup (einfo->info->keep_hash, 1585 h->root.root.root.string, 1586 FALSE, FALSE) == NULL)) 1587 strip = TRUE; 1588 else 1589 strip = FALSE; 1590 1591 if (strip) 1592 return TRUE; 1593 1594 if (h->esym.ifd == -2) 1595 { 1596 h->esym.jmptbl = 0; 1597 h->esym.cobol_main = 0; 1598 h->esym.weakext = 0; 1599 h->esym.reserved = 0; 1600 h->esym.ifd = ifdNil; 1601 h->esym.asym.value = 0; 1602 h->esym.asym.st = stGlobal; 1603 1604 if (h->root.root.type != bfd_link_hash_defined 1605 && h->root.root.type != bfd_link_hash_defweak) 1606 h->esym.asym.sc = scAbs; 1607 else 1608 { 1609 const char *name; 1610 1611 sec = h->root.root.u.def.section; 1612 output_section = sec->output_section; 1613 1614 /* When making a shared library and symbol h is the one from 1615 the another shared library, OUTPUT_SECTION may be null. */ 1616 if (output_section == NULL) 1617 h->esym.asym.sc = scUndefined; 1618 else 1619 { 1620 name = bfd_section_name (output_section->owner, output_section); 1621 1622 if (strcmp (name, ".text") == 0) 1623 h->esym.asym.sc = scText; 1624 else if (strcmp (name, ".data") == 0) 1625 h->esym.asym.sc = scData; 1626 else if (strcmp (name, ".sdata") == 0) 1627 h->esym.asym.sc = scSData; 1628 else if (strcmp (name, ".rodata") == 0 1629 || strcmp (name, ".rdata") == 0) 1630 h->esym.asym.sc = scRData; 1631 else if (strcmp (name, ".bss") == 0) 1632 h->esym.asym.sc = scBss; 1633 else if (strcmp (name, ".sbss") == 0) 1634 h->esym.asym.sc = scSBss; 1635 else if (strcmp (name, ".init") == 0) 1636 h->esym.asym.sc = scInit; 1637 else if (strcmp (name, ".fini") == 0) 1638 h->esym.asym.sc = scFini; 1639 else 1640 h->esym.asym.sc = scAbs; 1641 } 1642 } 1643 1644 h->esym.asym.reserved = 0; 1645 h->esym.asym.index = indexNil; 1646 } 1647 1648 if (h->root.root.type == bfd_link_hash_common) 1649 h->esym.asym.value = h->root.root.u.c.size; 1650 else if (h->root.root.type == bfd_link_hash_defined 1651 || h->root.root.type == bfd_link_hash_defweak) 1652 { 1653 if (h->esym.asym.sc == scCommon) 1654 h->esym.asym.sc = scBss; 1655 else if (h->esym.asym.sc == scSCommon) 1656 h->esym.asym.sc = scSBss; 1657 1658 sec = h->root.root.u.def.section; 1659 output_section = sec->output_section; 1660 if (output_section != NULL) 1661 h->esym.asym.value = (h->root.root.u.def.value 1662 + sec->output_offset 1663 + output_section->vma); 1664 else 1665 h->esym.asym.value = 0; 1666 } 1667 1668 if (! bfd_ecoff_debug_one_external (einfo->abfd, einfo->debug, einfo->swap, 1669 h->root.root.root.string, 1670 &h->esym)) 1671 { 1672 einfo->failed = TRUE; 1673 return FALSE; 1674 } 1675 1676 return TRUE; 1677 } 1678 1679 /* Search for and possibly create a got entry. */ 1681 1682 static struct alpha_elf_got_entry * 1683 get_got_entry (bfd *abfd, struct alpha_elf_link_hash_entry *h, 1684 unsigned long r_type, unsigned long r_symndx, 1685 bfd_vma r_addend) 1686 { 1687 struct alpha_elf_got_entry *gotent; 1688 struct alpha_elf_got_entry **slot; 1689 1690 if (h) 1691 slot = &h->got_entries; 1692 else 1693 { 1694 /* This is a local .got entry -- record for merge. */ 1695 1696 struct alpha_elf_got_entry **local_got_entries; 1697 1698 local_got_entries = alpha_elf_tdata(abfd)->local_got_entries; 1699 if (!local_got_entries) 1700 { 1701 bfd_size_type size; 1702 Elf_Internal_Shdr *symtab_hdr; 1703 1704 symtab_hdr = &elf_tdata(abfd)->symtab_hdr; 1705 size = symtab_hdr->sh_info; 1706 size *= sizeof (struct alpha_elf_got_entry *); 1707 1708 local_got_entries 1709 = (struct alpha_elf_got_entry **) bfd_zalloc (abfd, size); 1710 if (!local_got_entries) 1711 return NULL; 1712 1713 alpha_elf_tdata (abfd)->local_got_entries = local_got_entries; 1714 } 1715 1716 slot = &local_got_entries[r_symndx]; 1717 } 1718 1719 for (gotent = *slot; gotent ; gotent = gotent->next) 1720 if (gotent->gotobj == abfd 1721 && gotent->reloc_type == r_type 1722 && gotent->addend == r_addend) 1723 break; 1724 1725 if (!gotent) 1726 { 1727 int entry_size; 1728 bfd_size_type amt; 1729 1730 amt = sizeof (struct alpha_elf_got_entry); 1731 gotent = (struct alpha_elf_got_entry *) bfd_alloc (abfd, amt); 1732 if (!gotent) 1733 return NULL; 1734 1735 gotent->gotobj = abfd; 1736 gotent->addend = r_addend; 1737 gotent->got_offset = -1; 1738 gotent->plt_offset = -1; 1739 gotent->use_count = 1; 1740 gotent->reloc_type = r_type; 1741 gotent->reloc_done = 0; 1742 gotent->reloc_xlated = 0; 1743 1744 gotent->next = *slot; 1745 *slot = gotent; 1746 1747 entry_size = alpha_got_entry_size (r_type); 1748 alpha_elf_tdata (abfd)->total_got_size += entry_size; 1749 if (!h) 1750 alpha_elf_tdata(abfd)->local_got_size += entry_size; 1751 } 1752 else 1753 gotent->use_count += 1; 1754 1755 return gotent; 1756 } 1757 1758 static bfd_boolean 1759 elf64_alpha_want_plt (struct alpha_elf_link_hash_entry *ah) 1760 { 1761 return ((ah->root.type == STT_FUNC 1762 || ah->root.root.type == bfd_link_hash_undefweak 1763 || ah->root.root.type == bfd_link_hash_undefined) 1764 && (ah->flags & ALPHA_ELF_LINK_HASH_LU_PLT) != 0 1765 && (ah->flags & ~ALPHA_ELF_LINK_HASH_LU_PLT) == 0); 1766 } 1767 1768 /* Whether to sort relocs output by ld -r or ld --emit-relocs, by r_offset. 1769 Don't do so for code sections. We want to keep ordering of LITERAL/LITUSE 1770 as is. On the other hand, elf-eh-frame.c processing requires .eh_frame 1771 relocs to be sorted. */ 1772 1773 static bfd_boolean 1774 elf64_alpha_sort_relocs_p (asection *sec) 1775 { 1776 return (sec->flags & SEC_CODE) == 0; 1777 } 1778 1779 1780 /* Handle dynamic relocations when doing an Alpha ELF link. */ 1781 1782 static bfd_boolean 1783 elf64_alpha_check_relocs (bfd *abfd, struct bfd_link_info *info, 1784 asection *sec, const Elf_Internal_Rela *relocs) 1785 { 1786 bfd *dynobj; 1787 asection *sreloc; 1788 Elf_Internal_Shdr *symtab_hdr; 1789 struct alpha_elf_link_hash_entry **sym_hashes; 1790 const Elf_Internal_Rela *rel, *relend; 1791 bfd_size_type amt; 1792 1793 if (bfd_link_relocatable (info)) 1794 return TRUE; 1795 1796 /* Don't do anything special with non-loaded, non-alloced sections. 1797 In particular, any relocs in such sections should not affect GOT 1798 and PLT reference counting (ie. we don't allow them to create GOT 1799 or PLT entries), there's no possibility or desire to optimize TLS 1800 relocs, and there's not much point in propagating relocs to shared 1801 libs that the dynamic linker won't relocate. */ 1802 if ((sec->flags & SEC_ALLOC) == 0) 1803 return TRUE; 1804 1805 BFD_ASSERT (is_alpha_elf (abfd)); 1806 1807 dynobj = elf_hash_table (info)->dynobj; 1808 if (dynobj == NULL) 1809 elf_hash_table (info)->dynobj = dynobj = abfd; 1810 1811 sreloc = NULL; 1812 symtab_hdr = &elf_symtab_hdr (abfd); 1813 sym_hashes = alpha_elf_sym_hashes (abfd); 1814 1815 relend = relocs + sec->reloc_count; 1816 for (rel = relocs; rel < relend; ++rel) 1817 { 1818 enum { 1819 NEED_GOT = 1, 1820 NEED_GOT_ENTRY = 2, 1821 NEED_DYNREL = 4 1822 }; 1823 1824 unsigned long r_symndx, r_type; 1825 struct alpha_elf_link_hash_entry *h; 1826 unsigned int gotent_flags; 1827 bfd_boolean maybe_dynamic; 1828 unsigned int need; 1829 bfd_vma addend; 1830 1831 r_symndx = ELF64_R_SYM (rel->r_info); 1832 if (r_symndx < symtab_hdr->sh_info) 1833 h = NULL; 1834 else 1835 { 1836 h = sym_hashes[r_symndx - symtab_hdr->sh_info]; 1837 1838 while (h->root.root.type == bfd_link_hash_indirect 1839 || h->root.root.type == bfd_link_hash_warning) 1840 h = (struct alpha_elf_link_hash_entry *)h->root.root.u.i.link; 1841 1842 /* PR15323, ref flags aren't set for references in the same 1843 object. */ 1844 h->root.root.non_ir_ref = 1; 1845 h->root.ref_regular = 1; 1846 } 1847 1848 /* We can only get preliminary data on whether a symbol is 1849 locally or externally defined, as not all of the input files 1850 have yet been processed. Do something with what we know, as 1851 this may help reduce memory usage and processing time later. */ 1852 maybe_dynamic = FALSE; 1853 if (h && ((bfd_link_pic (info) 1854 && (!info->symbolic 1855 || info->unresolved_syms_in_shared_libs == RM_IGNORE)) 1856 || !h->root.def_regular 1857 || h->root.root.type == bfd_link_hash_defweak)) 1858 maybe_dynamic = TRUE; 1859 1860 need = 0; 1861 gotent_flags = 0; 1862 r_type = ELF64_R_TYPE (rel->r_info); 1863 addend = rel->r_addend; 1864 1865 switch (r_type) 1866 { 1867 case R_ALPHA_LITERAL: 1868 need = NEED_GOT | NEED_GOT_ENTRY; 1869 1870 /* Remember how this literal is used from its LITUSEs. 1871 This will be important when it comes to decide if we can 1872 create a .plt entry for a function symbol. */ 1873 while (++rel < relend && ELF64_R_TYPE (rel->r_info) == R_ALPHA_LITUSE) 1874 if (rel->r_addend >= 1 && rel->r_addend <= 6) 1875 gotent_flags |= 1 << rel->r_addend; 1876 --rel; 1877 1878 /* No LITUSEs -- presumably the address is used somehow. */ 1879 if (gotent_flags == 0) 1880 gotent_flags = ALPHA_ELF_LINK_HASH_LU_ADDR; 1881 break; 1882 1883 case R_ALPHA_GPDISP: 1884 case R_ALPHA_GPREL16: 1885 case R_ALPHA_GPREL32: 1886 case R_ALPHA_GPRELHIGH: 1887 case R_ALPHA_GPRELLOW: 1888 case R_ALPHA_BRSGP: 1889 need = NEED_GOT; 1890 break; 1891 1892 case R_ALPHA_REFLONG: 1893 case R_ALPHA_REFQUAD: 1894 if (bfd_link_pic (info) || maybe_dynamic) 1895 need = NEED_DYNREL; 1896 break; 1897 1898 case R_ALPHA_TLSLDM: 1899 /* The symbol for a TLSLDM reloc is ignored. Collapse the 1900 reloc to the STN_UNDEF (0) symbol so that they all match. */ 1901 r_symndx = STN_UNDEF; 1902 h = 0; 1903 maybe_dynamic = FALSE; 1904 /* FALLTHRU */ 1905 1906 case R_ALPHA_TLSGD: 1907 case R_ALPHA_GOTDTPREL: 1908 need = NEED_GOT | NEED_GOT_ENTRY; 1909 break; 1910 1911 case R_ALPHA_GOTTPREL: 1912 need = NEED_GOT | NEED_GOT_ENTRY; 1913 gotent_flags = ALPHA_ELF_LINK_HASH_TLS_IE; 1914 if (bfd_link_pic (info)) 1915 info->flags |= DF_STATIC_TLS; 1916 break; 1917 1918 case R_ALPHA_TPREL64: 1919 if (bfd_link_dll (info)) 1920 { 1921 info->flags |= DF_STATIC_TLS; 1922 need = NEED_DYNREL; 1923 } 1924 else if (maybe_dynamic) 1925 need = NEED_DYNREL; 1926 break; 1927 } 1928 1929 if (need & NEED_GOT) 1930 { 1931 if (alpha_elf_tdata(abfd)->gotobj == NULL) 1932 { 1933 if (!elf64_alpha_create_got_section (abfd, info)) 1934 return FALSE; 1935 } 1936 } 1937 1938 if (need & NEED_GOT_ENTRY) 1939 { 1940 struct alpha_elf_got_entry *gotent; 1941 1942 gotent = get_got_entry (abfd, h, r_type, r_symndx, addend); 1943 if (!gotent) 1944 return FALSE; 1945 1946 if (gotent_flags) 1947 { 1948 gotent->flags |= gotent_flags; 1949 if (h) 1950 { 1951 gotent_flags |= h->flags; 1952 h->flags = gotent_flags; 1953 1954 /* Make a guess as to whether a .plt entry is needed. */ 1955 /* ??? It appears that we won't make it into 1956 adjust_dynamic_symbol for symbols that remain 1957 totally undefined. Copying this check here means 1958 we can create a plt entry for them too. */ 1959 h->root.needs_plt 1960 = (maybe_dynamic && elf64_alpha_want_plt (h)); 1961 } 1962 } 1963 } 1964 1965 if (need & NEED_DYNREL) 1966 { 1967 /* We need to create the section here now whether we eventually 1968 use it or not so that it gets mapped to an output section by 1969 the linker. If not used, we'll kill it in size_dynamic_sections. */ 1970 if (sreloc == NULL) 1971 { 1972 sreloc = _bfd_elf_make_dynamic_reloc_section 1973 (sec, dynobj, 3, abfd, /*rela?*/ TRUE); 1974 1975 if (sreloc == NULL) 1976 return FALSE; 1977 } 1978 1979 if (h) 1980 { 1981 /* Since we havn't seen all of the input symbols yet, we 1982 don't know whether we'll actually need a dynamic relocation 1983 entry for this reloc. So make a record of it. Once we 1984 find out if this thing needs dynamic relocation we'll 1985 expand the relocation sections by the appropriate amount. */ 1986 1987 struct alpha_elf_reloc_entry *rent; 1988 1989 for (rent = h->reloc_entries; rent; rent = rent->next) 1990 if (rent->rtype == r_type && rent->srel == sreloc) 1991 break; 1992 1993 if (!rent) 1994 { 1995 amt = sizeof (struct alpha_elf_reloc_entry); 1996 rent = (struct alpha_elf_reloc_entry *) bfd_alloc (abfd, amt); 1997 if (!rent) 1998 return FALSE; 1999 2000 rent->srel = sreloc; 2001 rent->rtype = r_type; 2002 rent->count = 1; 2003 rent->reltext = (sec->flags & SEC_READONLY) != 0; 2004 2005 rent->next = h->reloc_entries; 2006 h->reloc_entries = rent; 2007 } 2008 else 2009 rent->count++; 2010 } 2011 else if (bfd_link_pic (info)) 2012 { 2013 /* If this is a shared library, and the section is to be 2014 loaded into memory, we need a RELATIVE reloc. */ 2015 sreloc->size += sizeof (Elf64_External_Rela); 2016 if (sec->flags & SEC_READONLY) 2017 info->flags |= DF_TEXTREL; 2018 } 2019 } 2020 } 2021 2022 return TRUE; 2023 } 2024 2025 /* Return the section that should be marked against GC for a given 2026 relocation. */ 2027 2028 static asection * 2029 elf64_alpha_gc_mark_hook (asection *sec, struct bfd_link_info *info, 2030 Elf_Internal_Rela *rel, 2031 struct elf_link_hash_entry *h, Elf_Internal_Sym *sym) 2032 { 2033 /* These relocations don't really reference a symbol. Instead we store 2034 extra data in their addend slot. Ignore the symbol. */ 2035 switch (ELF64_R_TYPE (rel->r_info)) 2036 { 2037 case R_ALPHA_LITUSE: 2038 case R_ALPHA_GPDISP: 2039 case R_ALPHA_HINT: 2040 return NULL; 2041 } 2042 2043 return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym); 2044 } 2045 2046 /* Update the got entry reference counts for the section being removed. */ 2047 2048 static bfd_boolean 2049 elf64_alpha_gc_sweep_hook (bfd *abfd, struct bfd_link_info *info, 2050 asection *sec, const Elf_Internal_Rela *relocs) 2051 { 2052 Elf_Internal_Shdr *symtab_hdr; 2053 struct alpha_elf_link_hash_entry **sym_hashes; 2054 const Elf_Internal_Rela *rel, *relend; 2055 2056 if (bfd_link_relocatable (info)) 2057 return TRUE; 2058 2059 symtab_hdr = &elf_symtab_hdr (abfd); 2060 sym_hashes = alpha_elf_sym_hashes (abfd); 2061 2062 relend = relocs + sec->reloc_count; 2063 for (rel = relocs; rel < relend; rel++) 2064 { 2065 unsigned long r_symndx, r_type; 2066 struct alpha_elf_link_hash_entry *h = NULL; 2067 struct alpha_elf_got_entry *gotent; 2068 2069 r_symndx = ELF64_R_SYM (rel->r_info); 2070 if (r_symndx >= symtab_hdr->sh_info) 2071 { 2072 h = sym_hashes[r_symndx - symtab_hdr->sh_info]; 2073 while (h->root.root.type == bfd_link_hash_indirect 2074 || h->root.root.type == bfd_link_hash_warning) 2075 h = (struct alpha_elf_link_hash_entry *) h->root.root.u.i.link; 2076 } 2077 2078 r_type = ELF64_R_TYPE (rel->r_info); 2079 switch (r_type) 2080 { 2081 case R_ALPHA_LITERAL: 2082 /* ??? Ignore re-computation of gotent_flags. We're not 2083 carrying a use-count for each bit in that mask. */ 2084 2085 case R_ALPHA_TLSGD: 2086 case R_ALPHA_GOTDTPREL: 2087 case R_ALPHA_GOTTPREL: 2088 /* Fetch the got entry from the tables. */ 2089 gotent = get_got_entry (abfd, h, r_type, r_symndx, rel->r_addend); 2090 2091 /* The got entry *must* exist, since we should have created it 2092 before during check_relocs. Also note that get_got_entry 2093 assumed this was going to be another use, and so incremented 2094 the use count again. Thus the use count must be at least the 2095 one real use and the "use" we just added. */ 2096 if (gotent == NULL || gotent->use_count < 2) 2097 { 2098 abort (); 2099 return FALSE; 2100 } 2101 gotent->use_count -= 2; 2102 break; 2103 2104 default: 2105 break; 2106 } 2107 } 2108 2109 return TRUE; 2110 } 2111 2112 /* Adjust a symbol defined by a dynamic object and referenced by a 2113 regular object. The current definition is in some section of the 2114 dynamic object, but we're not including those sections. We have to 2115 change the definition to something the rest of the link can 2116 understand. */ 2117 2118 static bfd_boolean 2119 elf64_alpha_adjust_dynamic_symbol (struct bfd_link_info *info, 2120 struct elf_link_hash_entry *h) 2121 { 2122 bfd *dynobj; 2123 asection *s; 2124 struct alpha_elf_link_hash_entry *ah; 2125 2126 dynobj = elf_hash_table(info)->dynobj; 2127 ah = (struct alpha_elf_link_hash_entry *)h; 2128 2129 /* Now that we've seen all of the input symbols, finalize our decision 2130 about whether this symbol should get a .plt entry. Irritatingly, it 2131 is common for folk to leave undefined symbols in shared libraries, 2132 and they still expect lazy binding; accept undefined symbols in lieu 2133 of STT_FUNC. */ 2134 if (alpha_elf_dynamic_symbol_p (h, info) && elf64_alpha_want_plt (ah)) 2135 { 2136 h->needs_plt = TRUE; 2137 2138 s = bfd_get_linker_section (dynobj, ".plt"); 2139 if (!s && !elf64_alpha_create_dynamic_sections (dynobj, info)) 2140 return FALSE; 2141 2142 /* We need one plt entry per got subsection. Delay allocation of 2143 the actual plt entries until size_plt_section, called from 2144 size_dynamic_sections or during relaxation. */ 2145 2146 return TRUE; 2147 } 2148 else 2149 h->needs_plt = FALSE; 2150 2151 /* If this is a weak symbol, and there is a real definition, the 2152 processor independent code will have arranged for us to see the 2153 real definition first, and we can just use the same value. */ 2154 if (h->u.weakdef != NULL) 2155 { 2156 BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined 2157 || h->u.weakdef->root.type == bfd_link_hash_defweak); 2158 h->root.u.def.section = h->u.weakdef->root.u.def.section; 2159 h->root.u.def.value = h->u.weakdef->root.u.def.value; 2160 return TRUE; 2161 } 2162 2163 /* This is a reference to a symbol defined by a dynamic object which 2164 is not a function. The Alpha, since it uses .got entries for all 2165 symbols even in regular objects, does not need the hackery of a 2166 .dynbss section and COPY dynamic relocations. */ 2167 2168 return TRUE; 2169 } 2170 2171 /* Record STO_ALPHA_NOPV and STO_ALPHA_STD_GPLOAD. */ 2172 2173 static void 2174 elf64_alpha_merge_symbol_attribute (struct elf_link_hash_entry *h, 2175 const Elf_Internal_Sym *isym, 2176 bfd_boolean definition, 2177 bfd_boolean dynamic) 2178 { 2179 if (!dynamic && definition) 2180 h->other = ((h->other & ELF_ST_VISIBILITY (-1)) 2181 | (isym->st_other & ~ELF_ST_VISIBILITY (-1))); 2182 } 2183 2184 /* Symbol versioning can create new symbols, and make our old symbols 2185 indirect to the new ones. Consolidate the got and reloc information 2186 in these situations. */ 2187 2188 static void 2189 elf64_alpha_copy_indirect_symbol (struct bfd_link_info *info, 2190 struct elf_link_hash_entry *dir, 2191 struct elf_link_hash_entry *ind) 2192 { 2193 struct alpha_elf_link_hash_entry *hi 2194 = (struct alpha_elf_link_hash_entry *) ind; 2195 struct alpha_elf_link_hash_entry *hs 2196 = (struct alpha_elf_link_hash_entry *) dir; 2197 2198 /* Do the merging in the superclass. */ 2199 _bfd_elf_link_hash_copy_indirect(info, dir, ind); 2200 2201 /* Merge the flags. Whee. */ 2202 hs->flags |= hi->flags; 2203 2204 /* ??? It's unclear to me what's really supposed to happen when 2205 "merging" defweak and defined symbols, given that we don't 2206 actually throw away the defweak. This more-or-less copies 2207 the logic related to got and plt entries in the superclass. */ 2208 if (ind->root.type != bfd_link_hash_indirect) 2209 return; 2210 2211 /* Merge the .got entries. Cannibalize the old symbol's list in 2212 doing so, since we don't need it anymore. */ 2213 2214 if (hs->got_entries == NULL) 2215 hs->got_entries = hi->got_entries; 2216 else 2217 { 2218 struct alpha_elf_got_entry *gi, *gs, *gin, *gsh; 2219 2220 gsh = hs->got_entries; 2221 for (gi = hi->got_entries; gi ; gi = gin) 2222 { 2223 gin = gi->next; 2224 for (gs = gsh; gs ; gs = gs->next) 2225 if (gi->gotobj == gs->gotobj 2226 && gi->reloc_type == gs->reloc_type 2227 && gi->addend == gs->addend) 2228 { 2229 gi->use_count += gs->use_count; 2230 goto got_found; 2231 } 2232 gi->next = hs->got_entries; 2233 hs->got_entries = gi; 2234 got_found:; 2235 } 2236 } 2237 hi->got_entries = NULL; 2238 2239 /* And similar for the reloc entries. */ 2240 2241 if (hs->reloc_entries == NULL) 2242 hs->reloc_entries = hi->reloc_entries; 2243 else 2244 { 2245 struct alpha_elf_reloc_entry *ri, *rs, *rin, *rsh; 2246 2247 rsh = hs->reloc_entries; 2248 for (ri = hi->reloc_entries; ri ; ri = rin) 2249 { 2250 rin = ri->next; 2251 for (rs = rsh; rs ; rs = rs->next) 2252 if (ri->rtype == rs->rtype && ri->srel == rs->srel) 2253 { 2254 rs->count += ri->count; 2255 goto found_reloc; 2256 } 2257 ri->next = hs->reloc_entries; 2258 hs->reloc_entries = ri; 2259 found_reloc:; 2260 } 2261 } 2262 hi->reloc_entries = NULL; 2263 } 2264 2265 /* Is it possible to merge two object file's .got tables? */ 2266 2267 static bfd_boolean 2268 elf64_alpha_can_merge_gots (bfd *a, bfd *b) 2269 { 2270 int total = alpha_elf_tdata (a)->total_got_size; 2271 bfd *bsub; 2272 2273 /* Trivial quick fallout test. */ 2274 if (total + alpha_elf_tdata (b)->total_got_size <= MAX_GOT_SIZE) 2275 return TRUE; 2276 2277 /* By their nature, local .got entries cannot be merged. */ 2278 if ((total += alpha_elf_tdata (b)->local_got_size) > MAX_GOT_SIZE) 2279 return FALSE; 2280 2281 /* Failing the common trivial comparison, we must effectively 2282 perform the merge. Not actually performing the merge means that 2283 we don't have to store undo information in case we fail. */ 2284 for (bsub = b; bsub ; bsub = alpha_elf_tdata (bsub)->in_got_link_next) 2285 { 2286 struct alpha_elf_link_hash_entry **hashes = alpha_elf_sym_hashes (bsub); 2287 Elf_Internal_Shdr *symtab_hdr = &elf_tdata (bsub)->symtab_hdr; 2288 int i, n; 2289 2290 n = NUM_SHDR_ENTRIES (symtab_hdr) - symtab_hdr->sh_info; 2291 for (i = 0; i < n; ++i) 2292 { 2293 struct alpha_elf_got_entry *ae, *be; 2294 struct alpha_elf_link_hash_entry *h; 2295 2296 h = hashes[i]; 2297 while (h->root.root.type == bfd_link_hash_indirect 2298 || h->root.root.type == bfd_link_hash_warning) 2299 h = (struct alpha_elf_link_hash_entry *)h->root.root.u.i.link; 2300 2301 for (be = h->got_entries; be ; be = be->next) 2302 { 2303 if (be->use_count == 0) 2304 continue; 2305 if (be->gotobj != b) 2306 continue; 2307 2308 for (ae = h->got_entries; ae ; ae = ae->next) 2309 if (ae->gotobj == a 2310 && ae->reloc_type == be->reloc_type 2311 && ae->addend == be->addend) 2312 goto global_found; 2313 2314 total += alpha_got_entry_size (be->reloc_type); 2315 if (total > MAX_GOT_SIZE) 2316 return FALSE; 2317 global_found:; 2318 } 2319 } 2320 } 2321 2322 return TRUE; 2323 } 2324 2325 /* Actually merge two .got tables. */ 2326 2327 static void 2328 elf64_alpha_merge_gots (bfd *a, bfd *b) 2329 { 2330 int total = alpha_elf_tdata (a)->total_got_size; 2331 bfd *bsub; 2332 2333 /* Remember local expansion. */ 2334 { 2335 int e = alpha_elf_tdata (b)->local_got_size; 2336 total += e; 2337 alpha_elf_tdata (a)->local_got_size += e; 2338 } 2339 2340 for (bsub = b; bsub ; bsub = alpha_elf_tdata (bsub)->in_got_link_next) 2341 { 2342 struct alpha_elf_got_entry **local_got_entries; 2343 struct alpha_elf_link_hash_entry **hashes; 2344 Elf_Internal_Shdr *symtab_hdr; 2345 int i, n; 2346 2347 /* Let the local .got entries know they are part of a new subsegment. */ 2348 local_got_entries = alpha_elf_tdata (bsub)->local_got_entries; 2349 if (local_got_entries) 2350 { 2351 n = elf_tdata (bsub)->symtab_hdr.sh_info; 2352 for (i = 0; i < n; ++i) 2353 { 2354 struct alpha_elf_got_entry *ent; 2355 for (ent = local_got_entries[i]; ent; ent = ent->next) 2356 ent->gotobj = a; 2357 } 2358 } 2359 2360 /* Merge the global .got entries. */ 2361 hashes = alpha_elf_sym_hashes (bsub); 2362 symtab_hdr = &elf_tdata (bsub)->symtab_hdr; 2363 2364 n = NUM_SHDR_ENTRIES (symtab_hdr) - symtab_hdr->sh_info; 2365 for (i = 0; i < n; ++i) 2366 { 2367 struct alpha_elf_got_entry *ae, *be, **pbe, **start; 2368 struct alpha_elf_link_hash_entry *h; 2369 2370 h = hashes[i]; 2371 while (h->root.root.type == bfd_link_hash_indirect 2372 || h->root.root.type == bfd_link_hash_warning) 2373 h = (struct alpha_elf_link_hash_entry *)h->root.root.u.i.link; 2374 2375 pbe = start = &h->got_entries; 2376 while ((be = *pbe) != NULL) 2377 { 2378 if (be->use_count == 0) 2379 { 2380 *pbe = be->next; 2381 memset (be, 0xa5, sizeof (*be)); 2382 goto kill; 2383 } 2384 if (be->gotobj != b) 2385 goto next; 2386 2387 for (ae = *start; ae ; ae = ae->next) 2388 if (ae->gotobj == a 2389 && ae->reloc_type == be->reloc_type 2390 && ae->addend == be->addend) 2391 { 2392 ae->flags |= be->flags; 2393 ae->use_count += be->use_count; 2394 *pbe = be->next; 2395 memset (be, 0xa5, sizeof (*be)); 2396 goto kill; 2397 } 2398 be->gotobj = a; 2399 total += alpha_got_entry_size (be->reloc_type); 2400 2401 next:; 2402 pbe = &be->next; 2403 kill:; 2404 } 2405 } 2406 2407 alpha_elf_tdata (bsub)->gotobj = a; 2408 } 2409 alpha_elf_tdata (a)->total_got_size = total; 2410 2411 /* Merge the two in_got chains. */ 2412 { 2413 bfd *next; 2414 2415 bsub = a; 2416 while ((next = alpha_elf_tdata (bsub)->in_got_link_next) != NULL) 2417 bsub = next; 2418 2419 alpha_elf_tdata (bsub)->in_got_link_next = b; 2420 } 2421 } 2422 2423 /* Calculate the offsets for the got entries. */ 2424 2425 static bfd_boolean 2426 elf64_alpha_calc_got_offsets_for_symbol (struct alpha_elf_link_hash_entry *h, 2427 void * arg ATTRIBUTE_UNUSED) 2428 { 2429 struct alpha_elf_got_entry *gotent; 2430 2431 for (gotent = h->got_entries; gotent; gotent = gotent->next) 2432 if (gotent->use_count > 0) 2433 { 2434 struct alpha_elf_obj_tdata *td; 2435 bfd_size_type *plge; 2436 2437 td = alpha_elf_tdata (gotent->gotobj); 2438 plge = &td->got->size; 2439 gotent->got_offset = *plge; 2440 *plge += alpha_got_entry_size (gotent->reloc_type); 2441 } 2442 2443 return TRUE; 2444 } 2445 2446 static void 2447 elf64_alpha_calc_got_offsets (struct bfd_link_info *info) 2448 { 2449 bfd *i, *got_list; 2450 struct alpha_elf_link_hash_table * htab; 2451 2452 htab = alpha_elf_hash_table (info); 2453 if (htab == NULL) 2454 return; 2455 got_list = htab->got_list; 2456 2457 /* First, zero out the .got sizes, as we may be recalculating the 2458 .got after optimizing it. */ 2459 for (i = got_list; i ; i = alpha_elf_tdata(i)->got_link_next) 2460 alpha_elf_tdata(i)->got->size = 0; 2461 2462 /* Next, fill in the offsets for all the global entries. */ 2463 alpha_elf_link_hash_traverse (htab, 2464 elf64_alpha_calc_got_offsets_for_symbol, 2465 NULL); 2466 2467 /* Finally, fill in the offsets for the local entries. */ 2468 for (i = got_list; i ; i = alpha_elf_tdata(i)->got_link_next) 2469 { 2470 bfd_size_type got_offset = alpha_elf_tdata(i)->got->size; 2471 bfd *j; 2472 2473 for (j = i; j ; j = alpha_elf_tdata(j)->in_got_link_next) 2474 { 2475 struct alpha_elf_got_entry **local_got_entries, *gotent; 2476 int k, n; 2477 2478 local_got_entries = alpha_elf_tdata(j)->local_got_entries; 2479 if (!local_got_entries) 2480 continue; 2481 2482 for (k = 0, n = elf_tdata(j)->symtab_hdr.sh_info; k < n; ++k) 2483 for (gotent = local_got_entries[k]; gotent; gotent = gotent->next) 2484 if (gotent->use_count > 0) 2485 { 2486 gotent->got_offset = got_offset; 2487 got_offset += alpha_got_entry_size (gotent->reloc_type); 2488 } 2489 } 2490 2491 alpha_elf_tdata(i)->got->size = got_offset; 2492 } 2493 } 2494 2495 /* Constructs the gots. */ 2496 2497 static bfd_boolean 2498 elf64_alpha_size_got_sections (struct bfd_link_info *info, 2499 bfd_boolean may_merge) 2500 { 2501 bfd *i, *got_list, *cur_got_obj = NULL; 2502 struct alpha_elf_link_hash_table * htab; 2503 2504 htab = alpha_elf_hash_table (info); 2505 if (htab == NULL) 2506 return FALSE; 2507 got_list = htab->got_list; 2508 2509 /* On the first time through, pretend we have an existing got list 2510 consisting of all of the input files. */ 2511 if (got_list == NULL) 2512 { 2513 for (i = info->input_bfds; i ; i = i->link.next) 2514 { 2515 bfd *this_got; 2516 2517 if (! is_alpha_elf (i)) 2518 continue; 2519 2520 this_got = alpha_elf_tdata (i)->gotobj; 2521 if (this_got == NULL) 2522 continue; 2523 2524 /* We are assuming no merging has yet occurred. */ 2525 BFD_ASSERT (this_got == i); 2526 2527 if (alpha_elf_tdata (this_got)->total_got_size > MAX_GOT_SIZE) 2528 { 2529 /* Yikes! A single object file has too many entries. */ 2530 (*_bfd_error_handler) 2531 (_("%B: .got subsegment exceeds 64K (size %d)"), 2532 i, alpha_elf_tdata (this_got)->total_got_size); 2533 return FALSE; 2534 } 2535 2536 if (got_list == NULL) 2537 got_list = this_got; 2538 else 2539 alpha_elf_tdata(cur_got_obj)->got_link_next = this_got; 2540 cur_got_obj = this_got; 2541 } 2542 2543 /* Strange degenerate case of no got references. */ 2544 if (got_list == NULL) 2545 return TRUE; 2546 2547 htab->got_list = got_list; 2548 } 2549 2550 cur_got_obj = got_list; 2551 if (cur_got_obj == NULL) 2552 return FALSE; 2553 2554 if (may_merge) 2555 { 2556 i = alpha_elf_tdata(cur_got_obj)->got_link_next; 2557 while (i != NULL) 2558 { 2559 if (elf64_alpha_can_merge_gots (cur_got_obj, i)) 2560 { 2561 elf64_alpha_merge_gots (cur_got_obj, i); 2562 2563 alpha_elf_tdata(i)->got->size = 0; 2564 i = alpha_elf_tdata(i)->got_link_next; 2565 alpha_elf_tdata(cur_got_obj)->got_link_next = i; 2566 } 2567 else 2568 { 2569 cur_got_obj = i; 2570 i = alpha_elf_tdata(i)->got_link_next; 2571 } 2572 } 2573 } 2574 2575 /* Once the gots have been merged, fill in the got offsets for 2576 everything therein. */ 2577 elf64_alpha_calc_got_offsets (info); 2578 2579 return TRUE; 2580 } 2581 2582 static bfd_boolean 2583 elf64_alpha_size_plt_section_1 (struct alpha_elf_link_hash_entry *h, 2584 void * data) 2585 { 2586 asection *splt = (asection *) data; 2587 struct alpha_elf_got_entry *gotent; 2588 bfd_boolean saw_one = FALSE; 2589 2590 /* If we didn't need an entry before, we still don't. */ 2591 if (!h->root.needs_plt) 2592 return TRUE; 2593 2594 /* For each LITERAL got entry still in use, allocate a plt entry. */ 2595 for (gotent = h->got_entries; gotent ; gotent = gotent->next) 2596 if (gotent->reloc_type == R_ALPHA_LITERAL 2597 && gotent->use_count > 0) 2598 { 2599 if (splt->size == 0) 2600 splt->size = PLT_HEADER_SIZE; 2601 gotent->plt_offset = splt->size; 2602 splt->size += PLT_ENTRY_SIZE; 2603 saw_one = TRUE; 2604 } 2605 2606 /* If there weren't any, there's no longer a need for the PLT entry. */ 2607 if (!saw_one) 2608 h->root.needs_plt = FALSE; 2609 2610 return TRUE; 2611 } 2612 2613 /* Called from relax_section to rebuild the PLT in light of potential changes 2614 in the function's status. */ 2615 2616 static void 2617 elf64_alpha_size_plt_section (struct bfd_link_info *info) 2618 { 2619 asection *splt, *spltrel, *sgotplt; 2620 unsigned long entries; 2621 bfd *dynobj; 2622 struct alpha_elf_link_hash_table * htab; 2623 2624 htab = alpha_elf_hash_table (info); 2625 if (htab == NULL) 2626 return; 2627 2628 dynobj = elf_hash_table(info)->dynobj; 2629 splt = bfd_get_linker_section (dynobj, ".plt"); 2630 if (splt == NULL) 2631 return; 2632 2633 splt->size = 0; 2634 2635 alpha_elf_link_hash_traverse (htab, 2636 elf64_alpha_size_plt_section_1, splt); 2637 2638 /* Every plt entry requires a JMP_SLOT relocation. */ 2639 spltrel = bfd_get_linker_section (dynobj, ".rela.plt"); 2640 entries = 0; 2641 if (splt->size) 2642 { 2643 if (elf64_alpha_use_secureplt) 2644 entries = (splt->size - NEW_PLT_HEADER_SIZE) / NEW_PLT_ENTRY_SIZE; 2645 else 2646 entries = (splt->size - OLD_PLT_HEADER_SIZE) / OLD_PLT_ENTRY_SIZE; 2647 } 2648 spltrel->size = entries * sizeof (Elf64_External_Rela); 2649 2650 /* When using the secureplt, we need two words somewhere in the data 2651 segment for the dynamic linker to tell us where to go. This is the 2652 entire contents of the .got.plt section. */ 2653 if (elf64_alpha_use_secureplt) 2654 { 2655 sgotplt = bfd_get_linker_section (dynobj, ".got.plt"); 2656 sgotplt->size = entries ? 16 : 0; 2657 } 2658 } 2659 2660 static bfd_boolean 2661 elf64_alpha_always_size_sections (bfd *output_bfd ATTRIBUTE_UNUSED, 2662 struct bfd_link_info *info) 2663 { 2664 bfd *i; 2665 struct alpha_elf_link_hash_table * htab; 2666 2667 if (bfd_link_relocatable (info)) 2668 return TRUE; 2669 2670 htab = alpha_elf_hash_table (info); 2671 if (htab == NULL) 2672 return FALSE; 2673 2674 if (!elf64_alpha_size_got_sections (info, TRUE)) 2675 return FALSE; 2676 2677 /* Allocate space for all of the .got subsections. */ 2678 i = htab->got_list; 2679 for ( ; i ; i = alpha_elf_tdata(i)->got_link_next) 2680 { 2681 asection *s = alpha_elf_tdata(i)->got; 2682 if (s->size > 0) 2683 { 2684 s->contents = (bfd_byte *) bfd_zalloc (i, s->size); 2685 if (s->contents == NULL) 2686 return FALSE; 2687 } 2688 } 2689 2690 return TRUE; 2691 } 2692 2693 /* The number of dynamic relocations required by a static relocation. */ 2694 2695 static int 2696 alpha_dynamic_entries_for_reloc (int r_type, int dynamic, int shared, int pie) 2697 { 2698 switch (r_type) 2699 { 2700 /* May appear in GOT entries. */ 2701 case R_ALPHA_TLSGD: 2702 return (dynamic ? 2 : shared ? 1 : 0); 2703 case R_ALPHA_TLSLDM: 2704 return shared; 2705 case R_ALPHA_LITERAL: 2706 return dynamic || shared; 2707 case R_ALPHA_GOTTPREL: 2708 return dynamic || (shared && !pie); 2709 case R_ALPHA_GOTDTPREL: 2710 return dynamic; 2711 2712 /* May appear in data sections. */ 2713 case R_ALPHA_REFLONG: 2714 case R_ALPHA_REFQUAD: 2715 return dynamic || shared; 2716 case R_ALPHA_TPREL64: 2717 return dynamic || (shared && !pie); 2718 2719 /* Everything else is illegal. We'll issue an error during 2720 relocate_section. */ 2721 default: 2722 return 0; 2723 } 2724 } 2725 2726 /* Work out the sizes of the dynamic relocation entries. */ 2727 2728 static bfd_boolean 2729 elf64_alpha_calc_dynrel_sizes (struct alpha_elf_link_hash_entry *h, 2730 struct bfd_link_info *info) 2731 { 2732 bfd_boolean dynamic; 2733 struct alpha_elf_reloc_entry *relent; 2734 unsigned long entries; 2735 2736 /* If the symbol was defined as a common symbol in a regular object 2737 file, and there was no definition in any dynamic object, then the 2738 linker will have allocated space for the symbol in a common 2739 section but the ELF_LINK_HASH_DEF_REGULAR flag will not have been 2740 set. This is done for dynamic symbols in 2741 elf_adjust_dynamic_symbol but this is not done for non-dynamic 2742 symbols, somehow. */ 2743 if (!h->root.def_regular 2744 && h->root.ref_regular 2745 && !h->root.def_dynamic 2746 && (h->root.root.type == bfd_link_hash_defined 2747 || h->root.root.type == bfd_link_hash_defweak) 2748 && !(h->root.root.u.def.section->owner->flags & DYNAMIC)) 2749 h->root.def_regular = 1; 2750 2751 /* If the symbol is dynamic, we'll need all the relocations in their 2752 natural form. If this is a shared object, and it has been forced 2753 local, we'll need the same number of RELATIVE relocations. */ 2754 dynamic = alpha_elf_dynamic_symbol_p (&h->root, info); 2755 2756 /* If the symbol is a hidden undefined weak, then we never have any 2757 relocations. Avoid the loop which may want to add RELATIVE relocs 2758 based on bfd_link_pic (info). */ 2759 if (h->root.root.type == bfd_link_hash_undefweak && !dynamic) 2760 return TRUE; 2761 2762 for (relent = h->reloc_entries; relent; relent = relent->next) 2763 { 2764 entries = alpha_dynamic_entries_for_reloc (relent->rtype, dynamic, 2765 bfd_link_pic (info), 2766 bfd_link_pie (info)); 2767 if (entries) 2768 { 2769 relent->srel->size += 2770 entries * sizeof (Elf64_External_Rela) * relent->count; 2771 if (relent->reltext) 2772 info->flags |= DT_TEXTREL; 2773 } 2774 } 2775 2776 return TRUE; 2777 } 2778 2779 /* Subroutine of elf64_alpha_size_rela_got_section for doing the 2780 global symbols. */ 2781 2782 static bfd_boolean 2783 elf64_alpha_size_rela_got_1 (struct alpha_elf_link_hash_entry *h, 2784 struct bfd_link_info *info) 2785 { 2786 bfd_boolean dynamic; 2787 struct alpha_elf_got_entry *gotent; 2788 unsigned long entries; 2789 2790 /* If we're using a plt for this symbol, then all of its relocations 2791 for its got entries go into .rela.plt. */ 2792 if (h->root.needs_plt) 2793 return TRUE; 2794 2795 /* If the symbol is dynamic, we'll need all the relocations in their 2796 natural form. If this is a shared object, and it has been forced 2797 local, we'll need the same number of RELATIVE relocations. */ 2798 dynamic = alpha_elf_dynamic_symbol_p (&h->root, info); 2799 2800 /* If the symbol is a hidden undefined weak, then we never have any 2801 relocations. Avoid the loop which may want to add RELATIVE relocs 2802 based on bfd_link_pic (info). */ 2803 if (h->root.root.type == bfd_link_hash_undefweak && !dynamic) 2804 return TRUE; 2805 2806 entries = 0; 2807 for (gotent = h->got_entries; gotent ; gotent = gotent->next) 2808 if (gotent->use_count > 0) 2809 entries += alpha_dynamic_entries_for_reloc (gotent->reloc_type, dynamic, 2810 bfd_link_pic (info), 2811 bfd_link_pie (info)); 2812 2813 if (entries > 0) 2814 { 2815 bfd *dynobj = elf_hash_table(info)->dynobj; 2816 asection *srel = bfd_get_linker_section (dynobj, ".rela.got"); 2817 BFD_ASSERT (srel != NULL); 2818 srel->size += sizeof (Elf64_External_Rela) * entries; 2819 } 2820 2821 return TRUE; 2822 } 2823 2824 /* Set the sizes of the dynamic relocation sections. */ 2825 2826 static void 2827 elf64_alpha_size_rela_got_section (struct bfd_link_info *info) 2828 { 2829 unsigned long entries; 2830 bfd *i, *dynobj; 2831 asection *srel; 2832 struct alpha_elf_link_hash_table * htab; 2833 2834 htab = alpha_elf_hash_table (info); 2835 if (htab == NULL) 2836 return; 2837 2838 /* Shared libraries often require RELATIVE relocs, and some relocs 2839 require attention for the main application as well. */ 2840 2841 entries = 0; 2842 for (i = htab->got_list; 2843 i ; i = alpha_elf_tdata(i)->got_link_next) 2844 { 2845 bfd *j; 2846 2847 for (j = i; j ; j = alpha_elf_tdata(j)->in_got_link_next) 2848 { 2849 struct alpha_elf_got_entry **local_got_entries, *gotent; 2850 int k, n; 2851 2852 local_got_entries = alpha_elf_tdata(j)->local_got_entries; 2853 if (!local_got_entries) 2854 continue; 2855 2856 for (k = 0, n = elf_tdata(j)->symtab_hdr.sh_info; k < n; ++k) 2857 for (gotent = local_got_entries[k]; 2858 gotent ; gotent = gotent->next) 2859 if (gotent->use_count > 0) 2860 entries += (alpha_dynamic_entries_for_reloc 2861 (gotent->reloc_type, 0, bfd_link_pic (info), 2862 bfd_link_pie (info))); 2863 } 2864 } 2865 2866 dynobj = elf_hash_table(info)->dynobj; 2867 srel = bfd_get_linker_section (dynobj, ".rela.got"); 2868 if (!srel) 2869 { 2870 BFD_ASSERT (entries == 0); 2871 return; 2872 } 2873 srel->size = sizeof (Elf64_External_Rela) * entries; 2874 2875 /* Now do the non-local symbols. */ 2876 alpha_elf_link_hash_traverse (htab, 2877 elf64_alpha_size_rela_got_1, info); 2878 } 2879 2880 /* Set the sizes of the dynamic sections. */ 2881 2882 static bfd_boolean 2883 elf64_alpha_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED, 2884 struct bfd_link_info *info) 2885 { 2886 bfd *dynobj; 2887 asection *s; 2888 bfd_boolean relplt; 2889 struct alpha_elf_link_hash_table * htab; 2890 2891 htab = alpha_elf_hash_table (info); 2892 if (htab == NULL) 2893 return FALSE; 2894 2895 dynobj = elf_hash_table(info)->dynobj; 2896 BFD_ASSERT(dynobj != NULL); 2897 2898 if (elf_hash_table (info)->dynamic_sections_created) 2899 { 2900 /* Set the contents of the .interp section to the interpreter. */ 2901 if (bfd_link_executable (info) && !info->nointerp) 2902 { 2903 s = bfd_get_linker_section (dynobj, ".interp"); 2904 BFD_ASSERT (s != NULL); 2905 s->size = sizeof ELF_DYNAMIC_INTERPRETER; 2906 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER; 2907 } 2908 2909 /* Now that we've seen all of the input files, we can decide which 2910 symbols need dynamic relocation entries and which don't. We've 2911 collected information in check_relocs that we can now apply to 2912 size the dynamic relocation sections. */ 2913 alpha_elf_link_hash_traverse (htab, 2914 elf64_alpha_calc_dynrel_sizes, info); 2915 2916 elf64_alpha_size_rela_got_section (info); 2917 elf64_alpha_size_plt_section (info); 2918 } 2919 /* else we're not dynamic and by definition we don't need such things. */ 2920 2921 /* The check_relocs and adjust_dynamic_symbol entry points have 2922 determined the sizes of the various dynamic sections. Allocate 2923 memory for them. */ 2924 relplt = FALSE; 2925 for (s = dynobj->sections; s != NULL; s = s->next) 2926 { 2927 const char *name; 2928 2929 if (!(s->flags & SEC_LINKER_CREATED)) 2930 continue; 2931 2932 /* It's OK to base decisions on the section name, because none 2933 of the dynobj section names depend upon the input files. */ 2934 name = bfd_get_section_name (dynobj, s); 2935 2936 if (CONST_STRNEQ (name, ".rela")) 2937 { 2938 if (s->size != 0) 2939 { 2940 if (strcmp (name, ".rela.plt") == 0) 2941 relplt = TRUE; 2942 2943 /* We use the reloc_count field as a counter if we need 2944 to copy relocs into the output file. */ 2945 s->reloc_count = 0; 2946 } 2947 } 2948 else if (! CONST_STRNEQ (name, ".got") 2949 && strcmp (name, ".plt") != 0 2950 && strcmp (name, ".dynbss") != 0) 2951 { 2952 /* It's not one of our dynamic sections, so don't allocate space. */ 2953 continue; 2954 } 2955 2956 if (s->size == 0) 2957 { 2958 /* If we don't need this section, strip it from the output file. 2959 This is to handle .rela.bss and .rela.plt. We must create it 2960 in create_dynamic_sections, because it must be created before 2961 the linker maps input sections to output sections. The 2962 linker does that before adjust_dynamic_symbol is called, and 2963 it is that function which decides whether anything needs to 2964 go into these sections. */ 2965 if (!CONST_STRNEQ (name, ".got")) 2966 s->flags |= SEC_EXCLUDE; 2967 } 2968 else if ((s->flags & SEC_HAS_CONTENTS) != 0) 2969 { 2970 /* Allocate memory for the section contents. */ 2971 s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size); 2972 if (s->contents == NULL) 2973 return FALSE; 2974 } 2975 } 2976 2977 if (elf_hash_table (info)->dynamic_sections_created) 2978 { 2979 /* Add some entries to the .dynamic section. We fill in the 2980 values later, in elf64_alpha_finish_dynamic_sections, but we 2981 must add the entries now so that we get the correct size for 2982 the .dynamic section. The DT_DEBUG entry is filled in by the 2983 dynamic linker and used by the debugger. */ 2984 #define add_dynamic_entry(TAG, VAL) \ 2985 _bfd_elf_add_dynamic_entry (info, TAG, VAL) 2986 2987 if (bfd_link_executable (info)) 2988 { 2989 if (!add_dynamic_entry (DT_DEBUG, 0)) 2990 return FALSE; 2991 } 2992 2993 if (relplt) 2994 { 2995 if (!add_dynamic_entry (DT_PLTGOT, 0) 2996 || !add_dynamic_entry (DT_PLTRELSZ, 0) 2997 || !add_dynamic_entry (DT_PLTREL, DT_RELA) 2998 || !add_dynamic_entry (DT_JMPREL, 0)) 2999 return FALSE; 3000 3001 if (elf64_alpha_use_secureplt 3002 && !add_dynamic_entry (DT_ALPHA_PLTRO, 1)) 3003 return FALSE; 3004 } 3005 3006 if (!add_dynamic_entry (DT_RELA, 0) 3007 || !add_dynamic_entry (DT_RELASZ, 0) 3008 || !add_dynamic_entry (DT_RELAENT, sizeof (Elf64_External_Rela))) 3009 return FALSE; 3010 3011 if (info->flags & DF_TEXTREL) 3012 { 3013 if (!add_dynamic_entry (DT_TEXTREL, 0)) 3014 return FALSE; 3015 } 3016 } 3017 #undef add_dynamic_entry 3018 3019 return TRUE; 3020 } 3021 3022 /* These functions do relaxation for Alpha ELF. 3024 3025 Currently I'm only handling what I can do with existing compiler 3026 and assembler support, which means no instructions are removed, 3027 though some may be nopped. At this time GCC does not emit enough 3028 information to do all of the relaxing that is possible. It will 3029 take some not small amount of work for that to happen. 3030 3031 There are a couple of interesting papers that I once read on this 3032 subject, that I cannot find references to at the moment, that 3033 related to Alpha in particular. They are by David Wall, then of 3034 DEC WRL. */ 3035 3036 struct alpha_relax_info 3037 { 3038 bfd *abfd; 3039 asection *sec; 3040 bfd_byte *contents; 3041 Elf_Internal_Shdr *symtab_hdr; 3042 Elf_Internal_Rela *relocs, *relend; 3043 struct bfd_link_info *link_info; 3044 bfd_vma gp; 3045 bfd *gotobj; 3046 asection *tsec; 3047 struct alpha_elf_link_hash_entry *h; 3048 struct alpha_elf_got_entry **first_gotent; 3049 struct alpha_elf_got_entry *gotent; 3050 bfd_boolean changed_contents; 3051 bfd_boolean changed_relocs; 3052 unsigned char other; 3053 }; 3054 3055 static Elf_Internal_Rela * 3056 elf64_alpha_find_reloc_at_ofs (Elf_Internal_Rela *rel, 3057 Elf_Internal_Rela *relend, 3058 bfd_vma offset, int type) 3059 { 3060 while (rel < relend) 3061 { 3062 if (rel->r_offset == offset 3063 && ELF64_R_TYPE (rel->r_info) == (unsigned int) type) 3064 return rel; 3065 ++rel; 3066 } 3067 return NULL; 3068 } 3069 3070 static bfd_boolean 3071 elf64_alpha_relax_got_load (struct alpha_relax_info *info, bfd_vma symval, 3072 Elf_Internal_Rela *irel, unsigned long r_type) 3073 { 3074 unsigned int insn; 3075 bfd_signed_vma disp; 3076 3077 /* Get the instruction. */ 3078 insn = bfd_get_32 (info->abfd, info->contents + irel->r_offset); 3079 3080 if (insn >> 26 != OP_LDQ) 3081 { 3082 reloc_howto_type *howto = elf64_alpha_howto_table + r_type; 3083 ((*_bfd_error_handler) 3084 ("%B: %A+0x%lx: warning: %s relocation against unexpected insn", 3085 info->abfd, info->sec, 3086 (unsigned long) irel->r_offset, howto->name)); 3087 return TRUE; 3088 } 3089 3090 /* Can't relax dynamic symbols. */ 3091 if (alpha_elf_dynamic_symbol_p (&info->h->root, info->link_info)) 3092 return TRUE; 3093 3094 /* Can't use local-exec relocations in shared libraries. */ 3095 if (r_type == R_ALPHA_GOTTPREL 3096 && bfd_link_dll (info->link_info)) 3097 return TRUE; 3098 3099 if (r_type == R_ALPHA_LITERAL) 3100 { 3101 /* Look for nice constant addresses. This includes the not-uncommon 3102 special case of 0 for undefweak symbols. */ 3103 if ((info->h && info->h->root.root.type == bfd_link_hash_undefweak) 3104 || (!bfd_link_pic (info->link_info) 3105 && (symval >= (bfd_vma)-0x8000 || symval < 0x8000))) 3106 { 3107 disp = 0; 3108 insn = (OP_LDA << 26) | (insn & (31 << 21)) | (31 << 16); 3109 insn |= (symval & 0xffff); 3110 r_type = R_ALPHA_NONE; 3111 } 3112 else 3113 { 3114 /* We may only create GPREL relocs during the second pass. */ 3115 if (info->link_info->relax_pass == 0) 3116 return TRUE; 3117 3118 disp = symval - info->gp; 3119 insn = (OP_LDA << 26) | (insn & 0x03ff0000); 3120 r_type = R_ALPHA_GPREL16; 3121 } 3122 } 3123 else 3124 { 3125 bfd_vma dtp_base, tp_base; 3126 3127 BFD_ASSERT (elf_hash_table (info->link_info)->tls_sec != NULL); 3128 dtp_base = alpha_get_dtprel_base (info->link_info); 3129 tp_base = alpha_get_tprel_base (info->link_info); 3130 disp = symval - (r_type == R_ALPHA_GOTDTPREL ? dtp_base : tp_base); 3131 3132 insn = (OP_LDA << 26) | (insn & (31 << 21)) | (31 << 16); 3133 3134 switch (r_type) 3135 { 3136 case R_ALPHA_GOTDTPREL: 3137 r_type = R_ALPHA_DTPREL16; 3138 break; 3139 case R_ALPHA_GOTTPREL: 3140 r_type = R_ALPHA_TPREL16; 3141 break; 3142 default: 3143 BFD_ASSERT (0); 3144 return FALSE; 3145 } 3146 } 3147 3148 if (disp < -0x8000 || disp >= 0x8000) 3149 return TRUE; 3150 3151 bfd_put_32 (info->abfd, (bfd_vma) insn, info->contents + irel->r_offset); 3152 info->changed_contents = TRUE; 3153 3154 /* Reduce the use count on this got entry by one, possibly 3155 eliminating it. */ 3156 if (--info->gotent->use_count == 0) 3157 { 3158 int sz = alpha_got_entry_size (r_type); 3159 alpha_elf_tdata (info->gotobj)->total_got_size -= sz; 3160 if (!info->h) 3161 alpha_elf_tdata (info->gotobj)->local_got_size -= sz; 3162 } 3163 3164 /* Smash the existing GOT relocation for its 16-bit immediate pair. */ 3165 irel->r_info = ELF64_R_INFO (ELF64_R_SYM (irel->r_info), r_type); 3166 info->changed_relocs = TRUE; 3167 3168 /* ??? Search forward through this basic block looking for insns 3169 that use the target register. Stop after an insn modifying the 3170 register is seen, or after a branch or call. 3171 3172 Any such memory load insn may be substituted by a load directly 3173 off the GP. This allows the memory load insn to be issued before 3174 the calculated GP register would otherwise be ready. 3175 3176 Any such jsr insn can be replaced by a bsr if it is in range. 3177 3178 This would mean that we'd have to _add_ relocations, the pain of 3179 which gives one pause. */ 3180 3181 return TRUE; 3182 } 3183 3184 static bfd_vma 3185 elf64_alpha_relax_opt_call (struct alpha_relax_info *info, bfd_vma symval) 3186 { 3187 /* If the function has the same gp, and we can identify that the 3188 function does not use its function pointer, we can eliminate the 3189 address load. */ 3190 3191 /* If the symbol is marked NOPV, we are being told the function never 3192 needs its procedure value. */ 3193 if ((info->other & STO_ALPHA_STD_GPLOAD) == STO_ALPHA_NOPV) 3194 return symval; 3195 3196 /* If the symbol is marked STD_GP, we are being told the function does 3197 a normal ldgp in the first two words. */ 3198 else if ((info->other & STO_ALPHA_STD_GPLOAD) == STO_ALPHA_STD_GPLOAD) 3199 ; 3200 3201 /* Otherwise, we may be able to identify a GP load in the first two 3202 words, which we can then skip. */ 3203 else 3204 { 3205 Elf_Internal_Rela *tsec_relocs, *tsec_relend, *tsec_free, *gpdisp; 3206 bfd_vma ofs; 3207 3208 /* Load the relocations from the section that the target symbol is in. */ 3209 if (info->sec == info->tsec) 3210 { 3211 tsec_relocs = info->relocs; 3212 tsec_relend = info->relend; 3213 tsec_free = NULL; 3214 } 3215 else 3216 { 3217 tsec_relocs = (_bfd_elf_link_read_relocs 3218 (info->abfd, info->tsec, NULL, 3219 (Elf_Internal_Rela *) NULL, 3220 info->link_info->keep_memory)); 3221 if (tsec_relocs == NULL) 3222 return 0; 3223 tsec_relend = tsec_relocs + info->tsec->reloc_count; 3224 tsec_free = (info->link_info->keep_memory ? NULL : tsec_relocs); 3225 } 3226 3227 /* Recover the symbol's offset within the section. */ 3228 ofs = (symval - info->tsec->output_section->vma 3229 - info->tsec->output_offset); 3230 3231 /* Look for a GPDISP reloc. */ 3232 gpdisp = (elf64_alpha_find_reloc_at_ofs 3233 (tsec_relocs, tsec_relend, ofs, R_ALPHA_GPDISP)); 3234 3235 if (!gpdisp || gpdisp->r_addend != 4) 3236 { 3237 if (tsec_free) 3238 free (tsec_free); 3239 return 0; 3240 } 3241 if (tsec_free) 3242 free (tsec_free); 3243 } 3244 3245 /* We've now determined that we can skip an initial gp load. Verify 3246 that the call and the target use the same gp. */ 3247 if (info->link_info->output_bfd->xvec != info->tsec->owner->xvec 3248 || info->gotobj != alpha_elf_tdata (info->tsec->owner)->gotobj) 3249 return 0; 3250 3251 return symval + 8; 3252 } 3253 3254 static bfd_boolean 3255 elf64_alpha_relax_with_lituse (struct alpha_relax_info *info, 3256 bfd_vma symval, Elf_Internal_Rela *irel) 3257 { 3258 Elf_Internal_Rela *urel, *erel, *irelend = info->relend; 3259 int flags; 3260 bfd_signed_vma disp; 3261 bfd_boolean fits16; 3262 bfd_boolean fits32; 3263 bfd_boolean lit_reused = FALSE; 3264 bfd_boolean all_optimized = TRUE; 3265 bfd_boolean changed_contents; 3266 bfd_boolean changed_relocs; 3267 bfd_byte *contents = info->contents; 3268 bfd *abfd = info->abfd; 3269 bfd_vma sec_output_vma; 3270 unsigned int lit_insn; 3271 int relax_pass; 3272 3273 lit_insn = bfd_get_32 (abfd, contents + irel->r_offset); 3274 if (lit_insn >> 26 != OP_LDQ) 3275 { 3276 ((*_bfd_error_handler) 3277 ("%B: %A+0x%lx: warning: LITERAL relocation against unexpected insn", 3278 abfd, info->sec, 3279 (unsigned long) irel->r_offset)); 3280 return TRUE; 3281 } 3282 3283 /* Can't relax dynamic symbols. */ 3284 if (alpha_elf_dynamic_symbol_p (&info->h->root, info->link_info)) 3285 return TRUE; 3286 3287 changed_contents = info->changed_contents; 3288 changed_relocs = info->changed_relocs; 3289 sec_output_vma = info->sec->output_section->vma + info->sec->output_offset; 3290 relax_pass = info->link_info->relax_pass; 3291 3292 /* Summarize how this particular LITERAL is used. */ 3293 for (erel = irel+1, flags = 0; erel < irelend; ++erel) 3294 { 3295 if (ELF64_R_TYPE (erel->r_info) != R_ALPHA_LITUSE) 3296 break; 3297 if (erel->r_addend <= 6) 3298 flags |= 1 << erel->r_addend; 3299 } 3300 3301 /* A little preparation for the loop... */ 3302 disp = symval - info->gp; 3303 3304 for (urel = irel+1; urel < erel; ++urel) 3305 { 3306 bfd_vma urel_r_offset = urel->r_offset; 3307 unsigned int insn; 3308 int insn_disp; 3309 bfd_signed_vma xdisp; 3310 Elf_Internal_Rela nrel; 3311 3312 insn = bfd_get_32 (abfd, contents + urel_r_offset); 3313 3314 switch (urel->r_addend) 3315 { 3316 case LITUSE_ALPHA_ADDR: 3317 default: 3318 /* This type is really just a placeholder to note that all 3319 uses cannot be optimized, but to still allow some. */ 3320 all_optimized = FALSE; 3321 break; 3322 3323 case LITUSE_ALPHA_BASE: 3324 /* We may only create GPREL relocs during the second pass. */ 3325 if (relax_pass == 0) 3326 { 3327 all_optimized = FALSE; 3328 break; 3329 } 3330 3331 /* We can always optimize 16-bit displacements. */ 3332 3333 /* Extract the displacement from the instruction, sign-extending 3334 it if necessary, then test whether it is within 16 or 32 bits 3335 displacement from GP. */ 3336 insn_disp = ((insn & 0xffff) ^ 0x8000) - 0x8000; 3337 3338 xdisp = disp + insn_disp; 3339 fits16 = (xdisp >= - (bfd_signed_vma) 0x8000 && xdisp < 0x8000); 3340 fits32 = (xdisp >= - (bfd_signed_vma) 0x80000000 3341 && xdisp < 0x7fff8000); 3342 3343 if (fits16) 3344 { 3345 /* Take the op code and dest from this insn, take the base 3346 register from the literal insn. Leave the offset alone. */ 3347 insn = (insn & 0xffe0ffff) | (lit_insn & 0x001f0000); 3348 bfd_put_32 (abfd, (bfd_vma) insn, contents + urel_r_offset); 3349 changed_contents = TRUE; 3350 3351 nrel = *urel; 3352 nrel.r_info = ELF64_R_INFO (ELF64_R_SYM (irel->r_info), 3353 R_ALPHA_GPREL16); 3354 nrel.r_addend = irel->r_addend; 3355 3356 /* As we adjust, move the reloc to the end so that we don't 3357 break the LITERAL+LITUSE chain. */ 3358 if (urel < --erel) 3359 *urel-- = *erel; 3360 *erel = nrel; 3361 changed_relocs = TRUE; 3362 } 3363 3364 /* If all mem+byte, we can optimize 32-bit mem displacements. */ 3365 else if (fits32 && !(flags & ~6)) 3366 { 3367 /* FIXME: sanity check that lit insn Ra is mem insn Rb. */ 3368 3369 irel->r_info = ELF64_R_INFO (ELF64_R_SYM (irel->r_info), 3370 R_ALPHA_GPRELHIGH); 3371 lit_insn = (OP_LDAH << 26) | (lit_insn & 0x03ff0000); 3372 bfd_put_32 (abfd, (bfd_vma) lit_insn, contents + irel->r_offset); 3373 lit_reused = TRUE; 3374 changed_contents = TRUE; 3375 3376 /* Since all relocs must be optimized, don't bother swapping 3377 this relocation to the end. */ 3378 urel->r_info = ELF64_R_INFO (ELF64_R_SYM (irel->r_info), 3379 R_ALPHA_GPRELLOW); 3380 urel->r_addend = irel->r_addend; 3381 changed_relocs = TRUE; 3382 } 3383 else 3384 all_optimized = FALSE; 3385 break; 3386 3387 case LITUSE_ALPHA_BYTOFF: 3388 /* We can always optimize byte instructions. */ 3389 3390 /* FIXME: sanity check the insn for byte op. Check that the 3391 literal dest reg is indeed Rb in the byte insn. */ 3392 3393 insn &= ~ (unsigned) 0x001ff000; 3394 insn |= ((symval & 7) << 13) | 0x1000; 3395 bfd_put_32 (abfd, (bfd_vma) insn, contents + urel_r_offset); 3396 changed_contents = TRUE; 3397 3398 nrel = *urel; 3399 nrel.r_info = ELF64_R_INFO (0, R_ALPHA_NONE); 3400 nrel.r_addend = 0; 3401 3402 /* As we adjust, move the reloc to the end so that we don't 3403 break the LITERAL+LITUSE chain. */ 3404 if (urel < --erel) 3405 *urel-- = *erel; 3406 *erel = nrel; 3407 changed_relocs = TRUE; 3408 break; 3409 3410 case LITUSE_ALPHA_JSR: 3411 case LITUSE_ALPHA_TLSGD: 3412 case LITUSE_ALPHA_TLSLDM: 3413 case LITUSE_ALPHA_JSRDIRECT: 3414 { 3415 bfd_vma optdest, org; 3416 bfd_signed_vma odisp; 3417 3418 /* For undefined weak symbols, we're mostly interested in getting 3419 rid of the got entry whenever possible, so optimize this to a 3420 use of the zero register. */ 3421 if (info->h && info->h->root.root.type == bfd_link_hash_undefweak) 3422 { 3423 insn |= 31 << 16; 3424 bfd_put_32 (abfd, (bfd_vma) insn, contents + urel_r_offset); 3425 3426 changed_contents = TRUE; 3427 break; 3428 } 3429 3430 /* If not zero, place to jump without needing pv. */ 3431 optdest = elf64_alpha_relax_opt_call (info, symval); 3432 org = sec_output_vma + urel_r_offset + 4; 3433 odisp = (optdest ? optdest : symval) - org; 3434 3435 if (odisp >= -0x400000 && odisp < 0x400000) 3436 { 3437 Elf_Internal_Rela *xrel; 3438 3439 /* Preserve branch prediction call stack when possible. */ 3440 if ((insn & INSN_JSR_MASK) == INSN_JSR) 3441 insn = (OP_BSR << 26) | (insn & 0x03e00000); 3442 else 3443 insn = (OP_BR << 26) | (insn & 0x03e00000); 3444 bfd_put_32 (abfd, (bfd_vma) insn, contents + urel_r_offset); 3445 changed_contents = TRUE; 3446 3447 nrel = *urel; 3448 nrel.r_info = ELF64_R_INFO (ELF64_R_SYM (irel->r_info), 3449 R_ALPHA_BRADDR); 3450 nrel.r_addend = irel->r_addend; 3451 3452 if (optdest) 3453 nrel.r_addend += optdest - symval; 3454 else 3455 all_optimized = FALSE; 3456 3457 /* Kill any HINT reloc that might exist for this insn. */ 3458 xrel = (elf64_alpha_find_reloc_at_ofs 3459 (info->relocs, info->relend, urel_r_offset, 3460 R_ALPHA_HINT)); 3461 if (xrel) 3462 xrel->r_info = ELF64_R_INFO (0, R_ALPHA_NONE); 3463 3464 /* As we adjust, move the reloc to the end so that we don't 3465 break the LITERAL+LITUSE chain. */ 3466 if (urel < --erel) 3467 *urel-- = *erel; 3468 *erel = nrel; 3469 3470 info->changed_relocs = TRUE; 3471 } 3472 else 3473 all_optimized = FALSE; 3474 3475 /* Even if the target is not in range for a direct branch, 3476 if we share a GP, we can eliminate the gp reload. */ 3477 if (optdest) 3478 { 3479 Elf_Internal_Rela *gpdisp 3480 = (elf64_alpha_find_reloc_at_ofs 3481 (info->relocs, irelend, urel_r_offset + 4, 3482 R_ALPHA_GPDISP)); 3483 if (gpdisp) 3484 { 3485 bfd_byte *p_ldah = contents + gpdisp->r_offset; 3486 bfd_byte *p_lda = p_ldah + gpdisp->r_addend; 3487 unsigned int ldah = bfd_get_32 (abfd, p_ldah); 3488 unsigned int lda = bfd_get_32 (abfd, p_lda); 3489 3490 /* Verify that the instruction is "ldah $29,0($26)". 3491 Consider a function that ends in a noreturn call, 3492 and that the next function begins with an ldgp, 3493 and that by accident there is no padding between. 3494 In that case the insn would use $27 as the base. */ 3495 if (ldah == 0x27ba0000 && lda == 0x23bd0000) 3496 { 3497 bfd_put_32 (abfd, (bfd_vma) INSN_UNOP, p_ldah); 3498 bfd_put_32 (abfd, (bfd_vma) INSN_UNOP, p_lda); 3499 3500 gpdisp->r_info = ELF64_R_INFO (0, R_ALPHA_NONE); 3501 changed_contents = TRUE; 3502 changed_relocs = TRUE; 3503 } 3504 } 3505 } 3506 } 3507 break; 3508 } 3509 } 3510 3511 /* If we reused the literal instruction, we must have optimized all. */ 3512 BFD_ASSERT(!lit_reused || all_optimized); 3513 3514 /* If all cases were optimized, we can reduce the use count on this 3515 got entry by one, possibly eliminating it. */ 3516 if (all_optimized) 3517 { 3518 if (--info->gotent->use_count == 0) 3519 { 3520 int sz = alpha_got_entry_size (R_ALPHA_LITERAL); 3521 alpha_elf_tdata (info->gotobj)->total_got_size -= sz; 3522 if (!info->h) 3523 alpha_elf_tdata (info->gotobj)->local_got_size -= sz; 3524 } 3525 3526 /* If the literal instruction is no longer needed (it may have been 3527 reused. We can eliminate it. */ 3528 /* ??? For now, I don't want to deal with compacting the section, 3529 so just nop it out. */ 3530 if (!lit_reused) 3531 { 3532 irel->r_info = ELF64_R_INFO (0, R_ALPHA_NONE); 3533 changed_relocs = TRUE; 3534 3535 bfd_put_32 (abfd, (bfd_vma) INSN_UNOP, contents + irel->r_offset); 3536 changed_contents = TRUE; 3537 } 3538 } 3539 3540 info->changed_contents = changed_contents; 3541 info->changed_relocs = changed_relocs; 3542 3543 if (all_optimized || relax_pass == 0) 3544 return TRUE; 3545 return elf64_alpha_relax_got_load (info, symval, irel, R_ALPHA_LITERAL); 3546 } 3547 3548 static bfd_boolean 3549 elf64_alpha_relax_tls_get_addr (struct alpha_relax_info *info, bfd_vma symval, 3550 Elf_Internal_Rela *irel, bfd_boolean is_gd) 3551 { 3552 bfd_byte *pos[5]; 3553 unsigned int insn, tlsgd_reg; 3554 Elf_Internal_Rela *gpdisp, *hint; 3555 bfd_boolean dynamic, use_gottprel; 3556 unsigned long new_symndx; 3557 3558 dynamic = alpha_elf_dynamic_symbol_p (&info->h->root, info->link_info); 3559 3560 /* If a TLS symbol is accessed using IE at least once, there is no point 3561 to use dynamic model for it. */ 3562 if (is_gd && info->h && (info->h->flags & ALPHA_ELF_LINK_HASH_TLS_IE)) 3563 ; 3564 3565 /* If the symbol is local, and we've already committed to DF_STATIC_TLS, 3566 then we might as well relax to IE. */ 3567 else if (bfd_link_pic (info->link_info) && !dynamic 3568 && (info->link_info->flags & DF_STATIC_TLS)) 3569 ; 3570 3571 /* Otherwise we must be building an executable to do anything. */ 3572 else if (bfd_link_pic (info->link_info)) 3573 return TRUE; 3574 3575 /* The TLSGD/TLSLDM relocation must be followed by a LITERAL and 3576 the matching LITUSE_TLS relocations. */ 3577 if (irel + 2 >= info->relend) 3578 return TRUE; 3579 if (ELF64_R_TYPE (irel[1].r_info) != R_ALPHA_LITERAL 3580 || ELF64_R_TYPE (irel[2].r_info) != R_ALPHA_LITUSE 3581 || irel[2].r_addend != (is_gd ? LITUSE_ALPHA_TLSGD : LITUSE_ALPHA_TLSLDM)) 3582 return TRUE; 3583 3584 /* There must be a GPDISP relocation positioned immediately after the 3585 LITUSE relocation. */ 3586 gpdisp = elf64_alpha_find_reloc_at_ofs (info->relocs, info->relend, 3587 irel[2].r_offset + 4, R_ALPHA_GPDISP); 3588 if (!gpdisp) 3589 return TRUE; 3590 3591 pos[0] = info->contents + irel[0].r_offset; 3592 pos[1] = info->contents + irel[1].r_offset; 3593 pos[2] = info->contents + irel[2].r_offset; 3594 pos[3] = info->contents + gpdisp->r_offset; 3595 pos[4] = pos[3] + gpdisp->r_addend; 3596 3597 /* Beware of the compiler hoisting part of the sequence out a loop 3598 and adjusting the destination register for the TLSGD insn. If this 3599 happens, there will be a move into $16 before the JSR insn, so only 3600 transformations of the first insn pair should use this register. */ 3601 tlsgd_reg = bfd_get_32 (info->abfd, pos[0]); 3602 tlsgd_reg = (tlsgd_reg >> 21) & 31; 3603 3604 /* Generally, the positions are not allowed to be out of order, lest the 3605 modified insn sequence have different register lifetimes. We can make 3606 an exception when pos 1 is adjacent to pos 0. */ 3607 if (pos[1] + 4 == pos[0]) 3608 { 3609 bfd_byte *tmp = pos[0]; 3610 pos[0] = pos[1]; 3611 pos[1] = tmp; 3612 } 3613 if (pos[1] >= pos[2] || pos[2] >= pos[3]) 3614 return TRUE; 3615 3616 /* Reduce the use count on the LITERAL relocation. Do this before we 3617 smash the symndx when we adjust the relocations below. */ 3618 { 3619 struct alpha_elf_got_entry *lit_gotent; 3620 struct alpha_elf_link_hash_entry *lit_h; 3621 unsigned long indx; 3622 3623 BFD_ASSERT (ELF64_R_SYM (irel[1].r_info) >= info->symtab_hdr->sh_info); 3624 indx = ELF64_R_SYM (irel[1].r_info) - info->symtab_hdr->sh_info; 3625 lit_h = alpha_elf_sym_hashes (info->abfd)[indx]; 3626 3627 while (lit_h->root.root.type == bfd_link_hash_indirect 3628 || lit_h->root.root.type == bfd_link_hash_warning) 3629 lit_h = (struct alpha_elf_link_hash_entry *) lit_h->root.root.u.i.link; 3630 3631 for (lit_gotent = lit_h->got_entries; lit_gotent ; 3632 lit_gotent = lit_gotent->next) 3633 if (lit_gotent->gotobj == info->gotobj 3634 && lit_gotent->reloc_type == R_ALPHA_LITERAL 3635 && lit_gotent->addend == irel[1].r_addend) 3636 break; 3637 BFD_ASSERT (lit_gotent); 3638 3639 if (--lit_gotent->use_count == 0) 3640 { 3641 int sz = alpha_got_entry_size (R_ALPHA_LITERAL); 3642 alpha_elf_tdata (info->gotobj)->total_got_size -= sz; 3643 } 3644 } 3645 3646 /* Change 3647 3648 lda $16,x($gp) !tlsgd!1 3649 ldq $27,__tls_get_addr($gp) !literal!1 3650 jsr $26,($27),__tls_get_addr !lituse_tlsgd!1 3651 ldah $29,0($26) !gpdisp!2 3652 lda $29,0($29) !gpdisp!2 3653 to 3654 ldq $16,x($gp) !gottprel 3655 unop 3656 call_pal rduniq 3657 addq $16,$0,$0 3658 unop 3659 or the first pair to 3660 lda $16,x($gp) !tprel 3661 unop 3662 or 3663 ldah $16,x($gp) !tprelhi 3664 lda $16,x($16) !tprello 3665 3666 as appropriate. */ 3667 3668 use_gottprel = FALSE; 3669 new_symndx = is_gd ? ELF64_R_SYM (irel->r_info) : STN_UNDEF; 3670 3671 /* Some compilers warn about a Boolean-looking expression being 3672 used in a switch. The explicit cast silences them. */ 3673 switch ((int) (!dynamic && !bfd_link_pic (info->link_info))) 3674 { 3675 case 1: 3676 { 3677 bfd_vma tp_base; 3678 bfd_signed_vma disp; 3679 3680 BFD_ASSERT (elf_hash_table (info->link_info)->tls_sec != NULL); 3681 tp_base = alpha_get_tprel_base (info->link_info); 3682 disp = symval - tp_base; 3683 3684 if (disp >= -0x8000 && disp < 0x8000) 3685 { 3686 insn = (OP_LDA << 26) | (tlsgd_reg << 21) | (31 << 16); 3687 bfd_put_32 (info->abfd, (bfd_vma) insn, pos[0]); 3688 bfd_put_32 (info->abfd, (bfd_vma) INSN_UNOP, pos[1]); 3689 3690 irel[0].r_offset = pos[0] - info->contents; 3691 irel[0].r_info = ELF64_R_INFO (new_symndx, R_ALPHA_TPREL16); 3692 irel[1].r_info = ELF64_R_INFO (0, R_ALPHA_NONE); 3693 break; 3694 } 3695 else if (disp >= -(bfd_signed_vma) 0x80000000 3696 && disp < (bfd_signed_vma) 0x7fff8000 3697 && pos[0] + 4 == pos[1]) 3698 { 3699 insn = (OP_LDAH << 26) | (tlsgd_reg << 21) | (31 << 16); 3700 bfd_put_32 (info->abfd, (bfd_vma) insn, pos[0]); 3701 insn = (OP_LDA << 26) | (tlsgd_reg << 21) | (tlsgd_reg << 16); 3702 bfd_put_32 (info->abfd, (bfd_vma) insn, pos[1]); 3703 3704 irel[0].r_offset = pos[0] - info->contents; 3705 irel[0].r_info = ELF64_R_INFO (new_symndx, R_ALPHA_TPRELHI); 3706 irel[1].r_offset = pos[1] - info->contents; 3707 irel[1].r_info = ELF64_R_INFO (new_symndx, R_ALPHA_TPRELLO); 3708 break; 3709 } 3710 } 3711 /* FALLTHRU */ 3712 3713 default: 3714 use_gottprel = TRUE; 3715 3716 insn = (OP_LDQ << 26) | (tlsgd_reg << 21) | (29 << 16); 3717 bfd_put_32 (info->abfd, (bfd_vma) insn, pos[0]); 3718 bfd_put_32 (info->abfd, (bfd_vma) INSN_UNOP, pos[1]); 3719 3720 irel[0].r_offset = pos[0] - info->contents; 3721 irel[0].r_info = ELF64_R_INFO (new_symndx, R_ALPHA_GOTTPREL); 3722 irel[1].r_info = ELF64_R_INFO (0, R_ALPHA_NONE); 3723 break; 3724 } 3725 3726 bfd_put_32 (info->abfd, (bfd_vma) INSN_RDUNIQ, pos[2]); 3727 3728 insn = INSN_ADDQ | (16 << 21) | (0 << 16) | (0 << 0); 3729 bfd_put_32 (info->abfd, (bfd_vma) insn, pos[3]); 3730 3731 bfd_put_32 (info->abfd, (bfd_vma) INSN_UNOP, pos[4]); 3732 3733 irel[2].r_info = ELF64_R_INFO (0, R_ALPHA_NONE); 3734 gpdisp->r_info = ELF64_R_INFO (0, R_ALPHA_NONE); 3735 3736 hint = elf64_alpha_find_reloc_at_ofs (info->relocs, info->relend, 3737 irel[2].r_offset, R_ALPHA_HINT); 3738 if (hint) 3739 hint->r_info = ELF64_R_INFO (0, R_ALPHA_NONE); 3740 3741 info->changed_contents = TRUE; 3742 info->changed_relocs = TRUE; 3743 3744 /* Reduce the use count on the TLSGD/TLSLDM relocation. */ 3745 if (--info->gotent->use_count == 0) 3746 { 3747 int sz = alpha_got_entry_size (info->gotent->reloc_type); 3748 alpha_elf_tdata (info->gotobj)->total_got_size -= sz; 3749 if (!info->h) 3750 alpha_elf_tdata (info->gotobj)->local_got_size -= sz; 3751 } 3752 3753 /* If we've switched to a GOTTPREL relocation, increment the reference 3754 count on that got entry. */ 3755 if (use_gottprel) 3756 { 3757 struct alpha_elf_got_entry *tprel_gotent; 3758 3759 for (tprel_gotent = *info->first_gotent; tprel_gotent ; 3760 tprel_gotent = tprel_gotent->next) 3761 if (tprel_gotent->gotobj == info->gotobj 3762 && tprel_gotent->reloc_type == R_ALPHA_GOTTPREL 3763 && tprel_gotent->addend == irel->r_addend) 3764 break; 3765 if (tprel_gotent) 3766 tprel_gotent->use_count++; 3767 else 3768 { 3769 if (info->gotent->use_count == 0) 3770 tprel_gotent = info->gotent; 3771 else 3772 { 3773 tprel_gotent = (struct alpha_elf_got_entry *) 3774 bfd_alloc (info->abfd, sizeof (struct alpha_elf_got_entry)); 3775 if (!tprel_gotent) 3776 return FALSE; 3777 3778 tprel_gotent->next = *info->first_gotent; 3779 *info->first_gotent = tprel_gotent; 3780 3781 tprel_gotent->gotobj = info->gotobj; 3782 tprel_gotent->addend = irel->r_addend; 3783 tprel_gotent->got_offset = -1; 3784 tprel_gotent->reloc_done = 0; 3785 tprel_gotent->reloc_xlated = 0; 3786 } 3787 3788 tprel_gotent->use_count = 1; 3789 tprel_gotent->reloc_type = R_ALPHA_GOTTPREL; 3790 } 3791 } 3792 3793 return TRUE; 3794 } 3795 3796 static bfd_boolean 3797 elf64_alpha_relax_section (bfd *abfd, asection *sec, 3798 struct bfd_link_info *link_info, bfd_boolean *again) 3799 { 3800 Elf_Internal_Shdr *symtab_hdr; 3801 Elf_Internal_Rela *internal_relocs; 3802 Elf_Internal_Rela *irel, *irelend; 3803 Elf_Internal_Sym *isymbuf = NULL; 3804 struct alpha_elf_got_entry **local_got_entries; 3805 struct alpha_relax_info info; 3806 struct alpha_elf_link_hash_table * htab; 3807 int relax_pass; 3808 3809 htab = alpha_elf_hash_table (link_info); 3810 if (htab == NULL) 3811 return FALSE; 3812 3813 /* There's nothing to change, yet. */ 3814 *again = FALSE; 3815 3816 if (bfd_link_relocatable (link_info) 3817 || ((sec->flags & (SEC_CODE | SEC_RELOC | SEC_ALLOC)) 3818 != (SEC_CODE | SEC_RELOC | SEC_ALLOC)) 3819 || sec->reloc_count == 0) 3820 return TRUE; 3821 3822 BFD_ASSERT (is_alpha_elf (abfd)); 3823 relax_pass = link_info->relax_pass; 3824 3825 /* Make sure our GOT and PLT tables are up-to-date. */ 3826 if (htab->relax_trip != link_info->relax_trip) 3827 { 3828 htab->relax_trip = link_info->relax_trip; 3829 3830 /* This should never fail after the initial round, since the only error 3831 is GOT overflow, and relaxation only shrinks the table. However, we 3832 may only merge got sections during the first pass. If we merge 3833 sections after we've created GPREL relocs, the GP for the merged 3834 section backs up which may put the relocs out of range. */ 3835 if (!elf64_alpha_size_got_sections (link_info, relax_pass == 0)) 3836 abort (); 3837 if (elf_hash_table (link_info)->dynamic_sections_created) 3838 { 3839 elf64_alpha_size_plt_section (link_info); 3840 elf64_alpha_size_rela_got_section (link_info); 3841 } 3842 } 3843 3844 symtab_hdr = &elf_symtab_hdr (abfd); 3845 local_got_entries = alpha_elf_tdata(abfd)->local_got_entries; 3846 3847 /* Load the relocations for this section. */ 3848 internal_relocs = (_bfd_elf_link_read_relocs 3849 (abfd, sec, NULL, (Elf_Internal_Rela *) NULL, 3850 link_info->keep_memory)); 3851 if (internal_relocs == NULL) 3852 return FALSE; 3853 3854 memset(&info, 0, sizeof (info)); 3855 info.abfd = abfd; 3856 info.sec = sec; 3857 info.link_info = link_info; 3858 info.symtab_hdr = symtab_hdr; 3859 info.relocs = internal_relocs; 3860 info.relend = irelend = internal_relocs + sec->reloc_count; 3861 3862 /* Find the GP for this object. Do not store the result back via 3863 _bfd_set_gp_value, since this could change again before final. */ 3864 info.gotobj = alpha_elf_tdata (abfd)->gotobj; 3865 if (info.gotobj) 3866 { 3867 asection *sgot = alpha_elf_tdata (info.gotobj)->got; 3868 info.gp = (sgot->output_section->vma 3869 + sgot->output_offset 3870 + 0x8000); 3871 } 3872 3873 /* Get the section contents. */ 3874 if (elf_section_data (sec)->this_hdr.contents != NULL) 3875 info.contents = elf_section_data (sec)->this_hdr.contents; 3876 else 3877 { 3878 if (!bfd_malloc_and_get_section (abfd, sec, &info.contents)) 3879 goto error_return; 3880 } 3881 3882 for (irel = internal_relocs; irel < irelend; irel++) 3883 { 3884 bfd_vma symval; 3885 struct alpha_elf_got_entry *gotent; 3886 unsigned long r_type = ELF64_R_TYPE (irel->r_info); 3887 unsigned long r_symndx = ELF64_R_SYM (irel->r_info); 3888 3889 /* Early exit for unhandled or unrelaxable relocations. */ 3890 if (r_type != R_ALPHA_LITERAL) 3891 { 3892 /* We complete everything except LITERAL in the first pass. */ 3893 if (relax_pass != 0) 3894 continue; 3895 if (r_type == R_ALPHA_TLSLDM) 3896 { 3897 /* The symbol for a TLSLDM reloc is ignored. Collapse the 3898 reloc to the STN_UNDEF (0) symbol so that they all match. */ 3899 r_symndx = STN_UNDEF; 3900 } 3901 else if (r_type != R_ALPHA_GOTDTPREL 3902 && r_type != R_ALPHA_GOTTPREL 3903 && r_type != R_ALPHA_TLSGD) 3904 continue; 3905 } 3906 3907 /* Get the value of the symbol referred to by the reloc. */ 3908 if (r_symndx < symtab_hdr->sh_info) 3909 { 3910 /* A local symbol. */ 3911 Elf_Internal_Sym *isym; 3912 3913 /* Read this BFD's local symbols. */ 3914 if (isymbuf == NULL) 3915 { 3916 isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents; 3917 if (isymbuf == NULL) 3918 isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr, 3919 symtab_hdr->sh_info, 0, 3920 NULL, NULL, NULL); 3921 if (isymbuf == NULL) 3922 goto error_return; 3923 } 3924 3925 isym = isymbuf + r_symndx; 3926 3927 /* Given the symbol for a TLSLDM reloc is ignored, this also 3928 means forcing the symbol value to the tp base. */ 3929 if (r_type == R_ALPHA_TLSLDM) 3930 { 3931 info.tsec = bfd_abs_section_ptr; 3932 symval = alpha_get_tprel_base (info.link_info); 3933 } 3934 else 3935 { 3936 symval = isym->st_value; 3937 if (isym->st_shndx == SHN_UNDEF) 3938 continue; 3939 else if (isym->st_shndx == SHN_ABS) 3940 info.tsec = bfd_abs_section_ptr; 3941 else if (isym->st_shndx == SHN_COMMON) 3942 info.tsec = bfd_com_section_ptr; 3943 else 3944 info.tsec = bfd_section_from_elf_index (abfd, isym->st_shndx); 3945 } 3946 3947 info.h = NULL; 3948 info.other = isym->st_other; 3949 if (local_got_entries) 3950 info.first_gotent = &local_got_entries[r_symndx]; 3951 else 3952 { 3953 info.first_gotent = &info.gotent; 3954 info.gotent = NULL; 3955 } 3956 } 3957 else 3958 { 3959 unsigned long indx; 3960 struct alpha_elf_link_hash_entry *h; 3961 3962 indx = r_symndx - symtab_hdr->sh_info; 3963 h = alpha_elf_sym_hashes (abfd)[indx]; 3964 BFD_ASSERT (h != NULL); 3965 3966 while (h->root.root.type == bfd_link_hash_indirect 3967 || h->root.root.type == bfd_link_hash_warning) 3968 h = (struct alpha_elf_link_hash_entry *)h->root.root.u.i.link; 3969 3970 /* If the symbol is undefined, we can't do anything with it. */ 3971 if (h->root.root.type == bfd_link_hash_undefined) 3972 continue; 3973 3974 /* If the symbol isn't defined in the current module, 3975 again we can't do anything. */ 3976 if (h->root.root.type == bfd_link_hash_undefweak) 3977 { 3978 info.tsec = bfd_abs_section_ptr; 3979 symval = 0; 3980 } 3981 else if (!h->root.def_regular) 3982 { 3983 /* Except for TLSGD relocs, which can sometimes be 3984 relaxed to GOTTPREL relocs. */ 3985 if (r_type != R_ALPHA_TLSGD) 3986 continue; 3987 info.tsec = bfd_abs_section_ptr; 3988 symval = 0; 3989 } 3990 else 3991 { 3992 info.tsec = h->root.root.u.def.section; 3993 symval = h->root.root.u.def.value; 3994 } 3995 3996 info.h = h; 3997 info.other = h->root.other; 3998 info.first_gotent = &h->got_entries; 3999 } 4000 4001 /* Search for the got entry to be used by this relocation. */ 4002 for (gotent = *info.first_gotent; gotent ; gotent = gotent->next) 4003 if (gotent->gotobj == info.gotobj 4004 && gotent->reloc_type == r_type 4005 && gotent->addend == irel->r_addend) 4006 break; 4007 info.gotent = gotent; 4008 4009 symval += info.tsec->output_section->vma + info.tsec->output_offset; 4010 symval += irel->r_addend; 4011 4012 switch (r_type) 4013 { 4014 case R_ALPHA_LITERAL: 4015 BFD_ASSERT(info.gotent != NULL); 4016 4017 /* If there exist LITUSE relocations immediately following, this 4018 opens up all sorts of interesting optimizations, because we 4019 now know every location that this address load is used. */ 4020 if (irel+1 < irelend 4021 && ELF64_R_TYPE (irel[1].r_info) == R_ALPHA_LITUSE) 4022 { 4023 if (!elf64_alpha_relax_with_lituse (&info, symval, irel)) 4024 goto error_return; 4025 } 4026 else 4027 { 4028 if (!elf64_alpha_relax_got_load (&info, symval, irel, r_type)) 4029 goto error_return; 4030 } 4031 break; 4032 4033 case R_ALPHA_GOTDTPREL: 4034 case R_ALPHA_GOTTPREL: 4035 BFD_ASSERT(info.gotent != NULL); 4036 if (!elf64_alpha_relax_got_load (&info, symval, irel, r_type)) 4037 goto error_return; 4038 break; 4039 4040 case R_ALPHA_TLSGD: 4041 case R_ALPHA_TLSLDM: 4042 BFD_ASSERT(info.gotent != NULL); 4043 if (!elf64_alpha_relax_tls_get_addr (&info, symval, irel, 4044 r_type == R_ALPHA_TLSGD)) 4045 goto error_return; 4046 break; 4047 } 4048 } 4049 4050 if (isymbuf != NULL 4051 && symtab_hdr->contents != (unsigned char *) isymbuf) 4052 { 4053 if (!link_info->keep_memory) 4054 free (isymbuf); 4055 else 4056 { 4057 /* Cache the symbols for elf_link_input_bfd. */ 4058 symtab_hdr->contents = (unsigned char *) isymbuf; 4059 } 4060 } 4061 4062 if (info.contents != NULL 4063 && elf_section_data (sec)->this_hdr.contents != info.contents) 4064 { 4065 if (!info.changed_contents && !link_info->keep_memory) 4066 free (info.contents); 4067 else 4068 { 4069 /* Cache the section contents for elf_link_input_bfd. */ 4070 elf_section_data (sec)->this_hdr.contents = info.contents; 4071 } 4072 } 4073 4074 if (elf_section_data (sec)->relocs != internal_relocs) 4075 { 4076 if (!info.changed_relocs) 4077 free (internal_relocs); 4078 else 4079 elf_section_data (sec)->relocs = internal_relocs; 4080 } 4081 4082 *again = info.changed_contents || info.changed_relocs; 4083 4084 return TRUE; 4085 4086 error_return: 4087 if (isymbuf != NULL 4088 && symtab_hdr->contents != (unsigned char *) isymbuf) 4089 free (isymbuf); 4090 if (info.contents != NULL 4091 && elf_section_data (sec)->this_hdr.contents != info.contents) 4092 free (info.contents); 4093 if (internal_relocs != NULL 4094 && elf_section_data (sec)->relocs != internal_relocs) 4095 free (internal_relocs); 4096 return FALSE; 4097 } 4098 4099 /* Emit a dynamic relocation for (DYNINDX, RTYPE, ADDEND) at (SEC, OFFSET) 4101 into the next available slot in SREL. */ 4102 4103 static void 4104 elf64_alpha_emit_dynrel (bfd *abfd, struct bfd_link_info *info, 4105 asection *sec, asection *srel, bfd_vma offset, 4106 long dynindx, long rtype, bfd_vma addend) 4107 { 4108 Elf_Internal_Rela outrel; 4109 bfd_byte *loc; 4110 4111 BFD_ASSERT (srel != NULL); 4112 4113 outrel.r_info = ELF64_R_INFO (dynindx, rtype); 4114 outrel.r_addend = addend; 4115 4116 offset = _bfd_elf_section_offset (abfd, info, sec, offset); 4117 if ((offset | 1) != (bfd_vma) -1) 4118 outrel.r_offset = sec->output_section->vma + sec->output_offset + offset; 4119 else 4120 memset (&outrel, 0, sizeof (outrel)); 4121 4122 loc = srel->contents; 4123 loc += srel->reloc_count++ * sizeof (Elf64_External_Rela); 4124 bfd_elf64_swap_reloca_out (abfd, &outrel, loc); 4125 BFD_ASSERT (sizeof (Elf64_External_Rela) * srel->reloc_count <= srel->size); 4126 } 4127 4128 /* Relocate an Alpha ELF section for a relocatable link. 4129 4130 We don't have to change anything unless the reloc is against a section 4131 symbol, in which case we have to adjust according to where the section 4132 symbol winds up in the output section. */ 4133 4134 static bfd_boolean 4135 elf64_alpha_relocate_section_r (bfd *output_bfd ATTRIBUTE_UNUSED, 4136 struct bfd_link_info *info ATTRIBUTE_UNUSED, 4137 bfd *input_bfd, asection *input_section, 4138 bfd_byte *contents ATTRIBUTE_UNUSED, 4139 Elf_Internal_Rela *relocs, 4140 Elf_Internal_Sym *local_syms, 4141 asection **local_sections) 4142 { 4143 unsigned long symtab_hdr_sh_info; 4144 Elf_Internal_Rela *rel; 4145 Elf_Internal_Rela *relend; 4146 struct elf_link_hash_entry **sym_hashes; 4147 bfd_boolean ret_val = TRUE; 4148 4149 symtab_hdr_sh_info = elf_symtab_hdr (input_bfd).sh_info; 4150 sym_hashes = elf_sym_hashes (input_bfd); 4151 4152 relend = relocs + input_section->reloc_count; 4153 for (rel = relocs; rel < relend; rel++) 4154 { 4155 unsigned long r_symndx; 4156 Elf_Internal_Sym *sym; 4157 asection *sec; 4158 unsigned long r_type; 4159 4160 r_type = ELF64_R_TYPE (rel->r_info); 4161 if (r_type >= R_ALPHA_max) 4162 { 4163 (*_bfd_error_handler) 4164 (_("%B: unknown relocation type %d"), 4165 input_bfd, (int) r_type); 4166 bfd_set_error (bfd_error_bad_value); 4167 ret_val = FALSE; 4168 continue; 4169 } 4170 4171 /* The symbol associated with GPDISP and LITUSE is 4172 immaterial. Only the addend is significant. */ 4173 if (r_type == R_ALPHA_GPDISP || r_type == R_ALPHA_LITUSE) 4174 continue; 4175 4176 r_symndx = ELF64_R_SYM (rel->r_info); 4177 if (r_symndx < symtab_hdr_sh_info) 4178 { 4179 sym = local_syms + r_symndx; 4180 sec = local_sections[r_symndx]; 4181 } 4182 else 4183 { 4184 struct elf_link_hash_entry *h; 4185 4186 h = sym_hashes[r_symndx - symtab_hdr_sh_info]; 4187 4188 while (h->root.type == bfd_link_hash_indirect 4189 || h->root.type == bfd_link_hash_warning) 4190 h = (struct elf_link_hash_entry *) h->root.u.i.link; 4191 4192 if (h->root.type != bfd_link_hash_defined 4193 && h->root.type != bfd_link_hash_defweak) 4194 continue; 4195 4196 sym = NULL; 4197 sec = h->root.u.def.section; 4198 } 4199 4200 if (sec != NULL && discarded_section (sec)) 4201 RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section, 4202 rel, 1, relend, 4203 elf64_alpha_howto_table + r_type, 0, 4204 contents); 4205 4206 if (sym != NULL && ELF_ST_TYPE (sym->st_info) == STT_SECTION) 4207 rel->r_addend += sec->output_offset; 4208 } 4209 4210 return ret_val; 4211 } 4212 4213 /* Relocate an Alpha ELF section. */ 4214 4215 static bfd_boolean 4216 elf64_alpha_relocate_section (bfd *output_bfd, struct bfd_link_info *info, 4217 bfd *input_bfd, asection *input_section, 4218 bfd_byte *contents, Elf_Internal_Rela *relocs, 4219 Elf_Internal_Sym *local_syms, 4220 asection **local_sections) 4221 { 4222 Elf_Internal_Shdr *symtab_hdr; 4223 Elf_Internal_Rela *rel; 4224 Elf_Internal_Rela *relend; 4225 asection *sgot, *srel, *srelgot; 4226 bfd *dynobj, *gotobj; 4227 bfd_vma gp, tp_base, dtp_base; 4228 struct alpha_elf_got_entry **local_got_entries; 4229 bfd_boolean ret_val; 4230 4231 BFD_ASSERT (is_alpha_elf (input_bfd)); 4232 4233 /* Handle relocatable links with a smaller loop. */ 4234 if (bfd_link_relocatable (info)) 4235 return elf64_alpha_relocate_section_r (output_bfd, info, input_bfd, 4236 input_section, contents, relocs, 4237 local_syms, local_sections); 4238 4239 /* This is a final link. */ 4240 4241 ret_val = TRUE; 4242 4243 symtab_hdr = &elf_symtab_hdr (input_bfd); 4244 4245 dynobj = elf_hash_table (info)->dynobj; 4246 if (dynobj) 4247 srelgot = bfd_get_linker_section (dynobj, ".rela.got"); 4248 else 4249 srelgot = NULL; 4250 4251 if (input_section->flags & SEC_ALLOC) 4252 { 4253 const char *section_name; 4254 section_name = (bfd_elf_string_from_elf_section 4255 (input_bfd, elf_elfheader(input_bfd)->e_shstrndx, 4256 _bfd_elf_single_rel_hdr (input_section)->sh_name)); 4257 BFD_ASSERT(section_name != NULL); 4258 srel = bfd_get_linker_section (dynobj, section_name); 4259 } 4260 else 4261 srel = NULL; 4262 4263 /* Find the gp value for this input bfd. */ 4264 gotobj = alpha_elf_tdata (input_bfd)->gotobj; 4265 if (gotobj) 4266 { 4267 sgot = alpha_elf_tdata (gotobj)->got; 4268 gp = _bfd_get_gp_value (gotobj); 4269 if (gp == 0) 4270 { 4271 gp = (sgot->output_section->vma 4272 + sgot->output_offset 4273 + 0x8000); 4274 _bfd_set_gp_value (gotobj, gp); 4275 } 4276 } 4277 else 4278 { 4279 sgot = NULL; 4280 gp = 0; 4281 } 4282 4283 local_got_entries = alpha_elf_tdata(input_bfd)->local_got_entries; 4284 4285 if (elf_hash_table (info)->tls_sec != NULL) 4286 { 4287 dtp_base = alpha_get_dtprel_base (info); 4288 tp_base = alpha_get_tprel_base (info); 4289 } 4290 else 4291 dtp_base = tp_base = 0; 4292 4293 relend = relocs + input_section->reloc_count; 4294 for (rel = relocs; rel < relend; rel++) 4295 { 4296 struct alpha_elf_link_hash_entry *h = NULL; 4297 struct alpha_elf_got_entry *gotent; 4298 bfd_reloc_status_type r; 4299 reloc_howto_type *howto; 4300 unsigned long r_symndx; 4301 Elf_Internal_Sym *sym = NULL; 4302 asection *sec = NULL; 4303 bfd_vma value; 4304 bfd_vma addend; 4305 bfd_boolean dynamic_symbol_p; 4306 bfd_boolean unresolved_reloc = FALSE; 4307 bfd_boolean undef_weak_ref = FALSE; 4308 unsigned long r_type; 4309 4310 r_type = ELF64_R_TYPE(rel->r_info); 4311 if (r_type >= R_ALPHA_max) 4312 { 4313 (*_bfd_error_handler) 4314 (_("%B: unknown relocation type %d"), 4315 input_bfd, (int) r_type); 4316 bfd_set_error (bfd_error_bad_value); 4317 ret_val = FALSE; 4318 continue; 4319 } 4320 4321 howto = elf64_alpha_howto_table + r_type; 4322 r_symndx = ELF64_R_SYM(rel->r_info); 4323 4324 /* The symbol for a TLSLDM reloc is ignored. Collapse the 4325 reloc to the STN_UNDEF (0) symbol so that they all match. */ 4326 if (r_type == R_ALPHA_TLSLDM) 4327 r_symndx = STN_UNDEF; 4328 4329 if (r_symndx < symtab_hdr->sh_info) 4330 { 4331 asection *msec; 4332 sym = local_syms + r_symndx; 4333 sec = local_sections[r_symndx]; 4334 msec = sec; 4335 value = _bfd_elf_rela_local_sym (output_bfd, sym, &msec, rel); 4336 4337 /* If this is a tp-relative relocation against sym STN_UNDEF (0), 4338 this is hackery from relax_section. Force the value to 4339 be the tls module base. */ 4340 if (r_symndx == STN_UNDEF 4341 && (r_type == R_ALPHA_TLSLDM 4342 || r_type == R_ALPHA_GOTTPREL 4343 || r_type == R_ALPHA_TPREL64 4344 || r_type == R_ALPHA_TPRELHI 4345 || r_type == R_ALPHA_TPRELLO 4346 || r_type == R_ALPHA_TPREL16)) 4347 value = dtp_base; 4348 4349 if (local_got_entries) 4350 gotent = local_got_entries[r_symndx]; 4351 else 4352 gotent = NULL; 4353 4354 /* Need to adjust local GOT entries' addends for SEC_MERGE 4355 unless it has been done already. */ 4356 if ((sec->flags & SEC_MERGE) 4357 && ELF_ST_TYPE (sym->st_info) == STT_SECTION 4358 && sec->sec_info_type == SEC_INFO_TYPE_MERGE 4359 && gotent 4360 && !gotent->reloc_xlated) 4361 { 4362 struct alpha_elf_got_entry *ent; 4363 4364 for (ent = gotent; ent; ent = ent->next) 4365 { 4366 ent->reloc_xlated = 1; 4367 if (ent->use_count == 0) 4368 continue; 4369 msec = sec; 4370 ent->addend = 4371 _bfd_merged_section_offset (output_bfd, &msec, 4372 elf_section_data (sec)-> 4373 sec_info, 4374 sym->st_value + ent->addend); 4375 ent->addend -= sym->st_value; 4376 ent->addend += msec->output_section->vma 4377 + msec->output_offset 4378 - sec->output_section->vma 4379 - sec->output_offset; 4380 } 4381 } 4382 4383 dynamic_symbol_p = FALSE; 4384 } 4385 else 4386 { 4387 bfd_boolean warned, ignored; 4388 struct elf_link_hash_entry *hh; 4389 struct elf_link_hash_entry **sym_hashes = elf_sym_hashes (input_bfd); 4390 4391 RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel, 4392 r_symndx, symtab_hdr, sym_hashes, 4393 hh, sec, value, 4394 unresolved_reloc, warned, ignored); 4395 4396 if (warned) 4397 continue; 4398 4399 if (value == 0 4400 && ! unresolved_reloc 4401 && hh->root.type == bfd_link_hash_undefweak) 4402 undef_weak_ref = TRUE; 4403 4404 h = (struct alpha_elf_link_hash_entry *) hh; 4405 dynamic_symbol_p = alpha_elf_dynamic_symbol_p (&h->root, info); 4406 gotent = h->got_entries; 4407 } 4408 4409 if (sec != NULL && discarded_section (sec)) 4410 RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section, 4411 rel, 1, relend, howto, 0, contents); 4412 4413 addend = rel->r_addend; 4414 value += addend; 4415 4416 /* Search for the proper got entry. */ 4417 for (; gotent ; gotent = gotent->next) 4418 if (gotent->gotobj == gotobj 4419 && gotent->reloc_type == r_type 4420 && gotent->addend == addend) 4421 break; 4422 4423 switch (r_type) 4424 { 4425 case R_ALPHA_GPDISP: 4426 { 4427 bfd_byte *p_ldah, *p_lda; 4428 4429 BFD_ASSERT(gp != 0); 4430 4431 value = (input_section->output_section->vma 4432 + input_section->output_offset 4433 + rel->r_offset); 4434 4435 p_ldah = contents + rel->r_offset; 4436 p_lda = p_ldah + rel->r_addend; 4437 4438 r = elf64_alpha_do_reloc_gpdisp (input_bfd, gp - value, 4439 p_ldah, p_lda); 4440 } 4441 break; 4442 4443 case R_ALPHA_LITERAL: 4444 BFD_ASSERT(sgot != NULL); 4445 BFD_ASSERT(gp != 0); 4446 BFD_ASSERT(gotent != NULL); 4447 BFD_ASSERT(gotent->use_count >= 1); 4448 4449 if (!gotent->reloc_done) 4450 { 4451 gotent->reloc_done = 1; 4452 4453 bfd_put_64 (output_bfd, value, 4454 sgot->contents + gotent->got_offset); 4455 4456 /* If the symbol has been forced local, output a 4457 RELATIVE reloc, otherwise it will be handled in 4458 finish_dynamic_symbol. */ 4459 if (bfd_link_pic (info) 4460 && !dynamic_symbol_p 4461 && !undef_weak_ref) 4462 elf64_alpha_emit_dynrel (output_bfd, info, sgot, srelgot, 4463 gotent->got_offset, 0, 4464 R_ALPHA_RELATIVE, value); 4465 } 4466 4467 value = (sgot->output_section->vma 4468 + sgot->output_offset 4469 + gotent->got_offset); 4470 value -= gp; 4471 goto default_reloc; 4472 4473 case R_ALPHA_GPREL32: 4474 case R_ALPHA_GPREL16: 4475 case R_ALPHA_GPRELLOW: 4476 if (dynamic_symbol_p) 4477 { 4478 (*_bfd_error_handler) 4479 (_("%B: gp-relative relocation against dynamic symbol %s"), 4480 input_bfd, h->root.root.root.string); 4481 ret_val = FALSE; 4482 } 4483 BFD_ASSERT(gp != 0); 4484 value -= gp; 4485 goto default_reloc; 4486 4487 case R_ALPHA_GPRELHIGH: 4488 if (dynamic_symbol_p) 4489 { 4490 (*_bfd_error_handler) 4491 (_("%B: gp-relative relocation against dynamic symbol %s"), 4492 input_bfd, h->root.root.root.string); 4493 ret_val = FALSE; 4494 } 4495 BFD_ASSERT(gp != 0); 4496 value -= gp; 4497 value = ((bfd_signed_vma) value >> 16) + ((value >> 15) & 1); 4498 goto default_reloc; 4499 4500 case R_ALPHA_HINT: 4501 /* A call to a dynamic symbol is definitely out of range of 4502 the 16-bit displacement. Don't bother writing anything. */ 4503 if (dynamic_symbol_p) 4504 { 4505 r = bfd_reloc_ok; 4506 break; 4507 } 4508 /* The regular PC-relative stuff measures from the start of 4509 the instruction rather than the end. */ 4510 value -= 4; 4511 goto default_reloc; 4512 4513 case R_ALPHA_BRADDR: 4514 if (dynamic_symbol_p) 4515 { 4516 (*_bfd_error_handler) 4517 (_("%B: pc-relative relocation against dynamic symbol %s"), 4518 input_bfd, h->root.root.root.string); 4519 ret_val = FALSE; 4520 } 4521 /* The regular PC-relative stuff measures from the start of 4522 the instruction rather than the end. */ 4523 value -= 4; 4524 goto default_reloc; 4525 4526 case R_ALPHA_BRSGP: 4527 { 4528 int other; 4529 const char *name; 4530 4531 /* The regular PC-relative stuff measures from the start of 4532 the instruction rather than the end. */ 4533 value -= 4; 4534 4535 /* The source and destination gp must be the same. Note that 4536 the source will always have an assigned gp, since we forced 4537 one in check_relocs, but that the destination may not, as 4538 it might not have had any relocations at all. Also take 4539 care not to crash if H is an undefined symbol. */ 4540 if (h != NULL && sec != NULL 4541 && alpha_elf_tdata (sec->owner)->gotobj 4542 && gotobj != alpha_elf_tdata (sec->owner)->gotobj) 4543 { 4544 (*_bfd_error_handler) 4545 (_("%B: change in gp: BRSGP %s"), 4546 input_bfd, h->root.root.root.string); 4547 ret_val = FALSE; 4548 } 4549 4550 /* The symbol should be marked either NOPV or STD_GPLOAD. */ 4551 if (h != NULL) 4552 other = h->root.other; 4553 else 4554 other = sym->st_other; 4555 switch (other & STO_ALPHA_STD_GPLOAD) 4556 { 4557 case STO_ALPHA_NOPV: 4558 break; 4559 case STO_ALPHA_STD_GPLOAD: 4560 value += 8; 4561 break; 4562 default: 4563 if (h != NULL) 4564 name = h->root.root.root.string; 4565 else 4566 { 4567 name = (bfd_elf_string_from_elf_section 4568 (input_bfd, symtab_hdr->sh_link, sym->st_name)); 4569 if (name == NULL) 4570 name = _("<unknown>"); 4571 else if (name[0] == 0) 4572 name = bfd_section_name (input_bfd, sec); 4573 } 4574 (*_bfd_error_handler) 4575 (_("%B: !samegp reloc against symbol without .prologue: %s"), 4576 input_bfd, name); 4577 ret_val = FALSE; 4578 break; 4579 } 4580 4581 goto default_reloc; 4582 } 4583 4584 case R_ALPHA_REFLONG: 4585 case R_ALPHA_REFQUAD: 4586 case R_ALPHA_DTPREL64: 4587 case R_ALPHA_TPREL64: 4588 { 4589 long dynindx, dyntype = r_type; 4590 bfd_vma dynaddend; 4591 4592 /* Careful here to remember RELATIVE relocations for global 4593 variables for symbolic shared objects. */ 4594 4595 if (dynamic_symbol_p) 4596 { 4597 BFD_ASSERT(h->root.dynindx != -1); 4598 dynindx = h->root.dynindx; 4599 dynaddend = addend; 4600 addend = 0, value = 0; 4601 } 4602 else if (r_type == R_ALPHA_DTPREL64) 4603 { 4604 BFD_ASSERT (elf_hash_table (info)->tls_sec != NULL); 4605 value -= dtp_base; 4606 goto default_reloc; 4607 } 4608 else if (r_type == R_ALPHA_TPREL64) 4609 { 4610 BFD_ASSERT (elf_hash_table (info)->tls_sec != NULL); 4611 if (!bfd_link_dll (info)) 4612 { 4613 value -= tp_base; 4614 goto default_reloc; 4615 } 4616 dynindx = 0; 4617 dynaddend = value - dtp_base; 4618 } 4619 else if (bfd_link_pic (info) 4620 && r_symndx != STN_UNDEF 4621 && (input_section->flags & SEC_ALLOC) 4622 && !undef_weak_ref 4623 && !(unresolved_reloc 4624 && (_bfd_elf_section_offset (output_bfd, info, 4625 input_section, 4626 rel->r_offset) 4627 == (bfd_vma) -1))) 4628 { 4629 if (r_type == R_ALPHA_REFLONG) 4630 { 4631 (*_bfd_error_handler) 4632 (_("%B: unhandled dynamic relocation against %s"), 4633 input_bfd, 4634 h->root.root.root.string); 4635 ret_val = FALSE; 4636 } 4637 dynindx = 0; 4638 dyntype = R_ALPHA_RELATIVE; 4639 dynaddend = value; 4640 } 4641 else 4642 goto default_reloc; 4643 4644 if (input_section->flags & SEC_ALLOC) 4645 elf64_alpha_emit_dynrel (output_bfd, info, input_section, 4646 srel, rel->r_offset, dynindx, 4647 dyntype, dynaddend); 4648 } 4649 goto default_reloc; 4650 4651 case R_ALPHA_SREL16: 4652 case R_ALPHA_SREL32: 4653 case R_ALPHA_SREL64: 4654 if (dynamic_symbol_p) 4655 { 4656 (*_bfd_error_handler) 4657 (_("%B: pc-relative relocation against dynamic symbol %s"), 4658 input_bfd, h->root.root.root.string); 4659 ret_val = FALSE; 4660 } 4661 else if (bfd_link_pic (info) 4662 && undef_weak_ref) 4663 { 4664 (*_bfd_error_handler) 4665 (_("%B: pc-relative relocation against undefined weak symbol %s"), 4666 input_bfd, h->root.root.root.string); 4667 ret_val = FALSE; 4668 } 4669 4670 4671 /* ??? .eh_frame references to discarded sections will be smashed 4672 to relocations against SHN_UNDEF. The .eh_frame format allows 4673 NULL to be encoded as 0 in any format, so this works here. */ 4674 if (r_symndx == STN_UNDEF 4675 || (unresolved_reloc 4676 && _bfd_elf_section_offset (output_bfd, info, 4677 input_section, 4678 rel->r_offset) == (bfd_vma) -1)) 4679 howto = (elf64_alpha_howto_table 4680 + (r_type - R_ALPHA_SREL32 + R_ALPHA_REFLONG)); 4681 goto default_reloc; 4682 4683 case R_ALPHA_TLSLDM: 4684 /* Ignore the symbol for the relocation. The result is always 4685 the current module. */ 4686 dynamic_symbol_p = 0; 4687 /* FALLTHRU */ 4688 4689 case R_ALPHA_TLSGD: 4690 if (!gotent->reloc_done) 4691 { 4692 gotent->reloc_done = 1; 4693 4694 /* Note that the module index for the main program is 1. */ 4695 bfd_put_64 (output_bfd, 4696 !bfd_link_pic (info) && !dynamic_symbol_p, 4697 sgot->contents + gotent->got_offset); 4698 4699 /* If the symbol has been forced local, output a 4700 DTPMOD64 reloc, otherwise it will be handled in 4701 finish_dynamic_symbol. */ 4702 if (bfd_link_pic (info) && !dynamic_symbol_p) 4703 elf64_alpha_emit_dynrel (output_bfd, info, sgot, srelgot, 4704 gotent->got_offset, 0, 4705 R_ALPHA_DTPMOD64, 0); 4706 4707 if (dynamic_symbol_p || r_type == R_ALPHA_TLSLDM) 4708 value = 0; 4709 else 4710 { 4711 BFD_ASSERT (elf_hash_table (info)->tls_sec != NULL); 4712 value -= dtp_base; 4713 } 4714 bfd_put_64 (output_bfd, value, 4715 sgot->contents + gotent->got_offset + 8); 4716 } 4717 4718 value = (sgot->output_section->vma 4719 + sgot->output_offset 4720 + gotent->got_offset); 4721 value -= gp; 4722 goto default_reloc; 4723 4724 case R_ALPHA_DTPRELHI: 4725 case R_ALPHA_DTPRELLO: 4726 case R_ALPHA_DTPREL16: 4727 if (dynamic_symbol_p) 4728 { 4729 (*_bfd_error_handler) 4730 (_("%B: dtp-relative relocation against dynamic symbol %s"), 4731 input_bfd, h->root.root.root.string); 4732 ret_val = FALSE; 4733 } 4734 BFD_ASSERT (elf_hash_table (info)->tls_sec != NULL); 4735 value -= dtp_base; 4736 if (r_type == R_ALPHA_DTPRELHI) 4737 value = ((bfd_signed_vma) value >> 16) + ((value >> 15) & 1); 4738 goto default_reloc; 4739 4740 case R_ALPHA_TPRELHI: 4741 case R_ALPHA_TPRELLO: 4742 case R_ALPHA_TPREL16: 4743 if (bfd_link_dll (info)) 4744 { 4745 (*_bfd_error_handler) 4746 (_("%B: TLS local exec code cannot be linked into shared objects"), 4747 input_bfd); 4748 ret_val = FALSE; 4749 } 4750 else if (dynamic_symbol_p) 4751 { 4752 (*_bfd_error_handler) 4753 (_("%B: tp-relative relocation against dynamic symbol %s"), 4754 input_bfd, h->root.root.root.string); 4755 ret_val = FALSE; 4756 } 4757 BFD_ASSERT (elf_hash_table (info)->tls_sec != NULL); 4758 value -= tp_base; 4759 if (r_type == R_ALPHA_TPRELHI) 4760 value = ((bfd_signed_vma) value >> 16) + ((value >> 15) & 1); 4761 goto default_reloc; 4762 4763 case R_ALPHA_GOTDTPREL: 4764 case R_ALPHA_GOTTPREL: 4765 BFD_ASSERT(sgot != NULL); 4766 BFD_ASSERT(gp != 0); 4767 BFD_ASSERT(gotent != NULL); 4768 BFD_ASSERT(gotent->use_count >= 1); 4769 4770 if (!gotent->reloc_done) 4771 { 4772 gotent->reloc_done = 1; 4773 4774 if (dynamic_symbol_p) 4775 value = 0; 4776 else 4777 { 4778 BFD_ASSERT (elf_hash_table (info)->tls_sec != NULL); 4779 if (r_type == R_ALPHA_GOTDTPREL) 4780 value -= dtp_base; 4781 else if (!bfd_link_pic (info)) 4782 value -= tp_base; 4783 else 4784 { 4785 elf64_alpha_emit_dynrel (output_bfd, info, sgot, srelgot, 4786 gotent->got_offset, 0, 4787 R_ALPHA_TPREL64, 4788 value - dtp_base); 4789 value = 0; 4790 } 4791 } 4792 bfd_put_64 (output_bfd, value, 4793 sgot->contents + gotent->got_offset); 4794 } 4795 4796 value = (sgot->output_section->vma 4797 + sgot->output_offset 4798 + gotent->got_offset); 4799 value -= gp; 4800 goto default_reloc; 4801 4802 default: 4803 default_reloc: 4804 r = _bfd_final_link_relocate (howto, input_bfd, input_section, 4805 contents, rel->r_offset, value, 0); 4806 break; 4807 } 4808 4809 switch (r) 4810 { 4811 case bfd_reloc_ok: 4812 break; 4813 4814 case bfd_reloc_overflow: 4815 { 4816 const char *name; 4817 4818 /* Don't warn if the overflow is due to pc relative reloc 4819 against discarded section. Section optimization code should 4820 handle it. */ 4821 4822 if (r_symndx < symtab_hdr->sh_info 4823 && sec != NULL && howto->pc_relative 4824 && discarded_section (sec)) 4825 break; 4826 4827 if (h != NULL) 4828 name = NULL; 4829 else 4830 { 4831 name = (bfd_elf_string_from_elf_section 4832 (input_bfd, symtab_hdr->sh_link, sym->st_name)); 4833 if (name == NULL) 4834 return FALSE; 4835 if (*name == '\0') 4836 name = bfd_section_name (input_bfd, sec); 4837 } 4838 (*info->callbacks->reloc_overflow) 4839 (info, (h ? &h->root.root : NULL), name, howto->name, 4840 (bfd_vma) 0, input_bfd, input_section, rel->r_offset); 4841 } 4842 break; 4843 4844 default: 4845 case bfd_reloc_outofrange: 4846 abort (); 4847 } 4848 } 4849 4850 return ret_val; 4851 } 4852 4853 /* Finish up dynamic symbol handling. We set the contents of various 4854 dynamic sections here. */ 4855 4856 static bfd_boolean 4857 elf64_alpha_finish_dynamic_symbol (bfd *output_bfd, struct bfd_link_info *info, 4858 struct elf_link_hash_entry *h, 4859 Elf_Internal_Sym *sym) 4860 { 4861 struct alpha_elf_link_hash_entry *ah = (struct alpha_elf_link_hash_entry *)h; 4862 bfd *dynobj = elf_hash_table(info)->dynobj; 4863 4864 if (h->needs_plt) 4865 { 4866 /* Fill in the .plt entry for this symbol. */ 4867 asection *splt, *sgot, *srel; 4868 Elf_Internal_Rela outrel; 4869 bfd_byte *loc; 4870 bfd_vma got_addr, plt_addr; 4871 bfd_vma plt_index; 4872 struct alpha_elf_got_entry *gotent; 4873 4874 BFD_ASSERT (h->dynindx != -1); 4875 4876 splt = bfd_get_linker_section (dynobj, ".plt"); 4877 BFD_ASSERT (splt != NULL); 4878 srel = bfd_get_linker_section (dynobj, ".rela.plt"); 4879 BFD_ASSERT (srel != NULL); 4880 4881 for (gotent = ah->got_entries; gotent ; gotent = gotent->next) 4882 if (gotent->reloc_type == R_ALPHA_LITERAL 4883 && gotent->use_count > 0) 4884 { 4885 unsigned int insn; 4886 int disp; 4887 4888 sgot = alpha_elf_tdata (gotent->gotobj)->got; 4889 BFD_ASSERT (sgot != NULL); 4890 4891 BFD_ASSERT (gotent->got_offset != -1); 4892 BFD_ASSERT (gotent->plt_offset != -1); 4893 4894 got_addr = (sgot->output_section->vma 4895 + sgot->output_offset 4896 + gotent->got_offset); 4897 plt_addr = (splt->output_section->vma 4898 + splt->output_offset 4899 + gotent->plt_offset); 4900 4901 plt_index = (gotent->plt_offset-PLT_HEADER_SIZE) / PLT_ENTRY_SIZE; 4902 4903 /* Fill in the entry in the procedure linkage table. */ 4904 if (elf64_alpha_use_secureplt) 4905 { 4906 disp = (PLT_HEADER_SIZE - 4) - (gotent->plt_offset + 4); 4907 insn = INSN_AD (INSN_BR, 31, disp); 4908 bfd_put_32 (output_bfd, insn, 4909 splt->contents + gotent->plt_offset); 4910 4911 plt_index = ((gotent->plt_offset - NEW_PLT_HEADER_SIZE) 4912 / NEW_PLT_ENTRY_SIZE); 4913 } 4914 else 4915 { 4916 disp = -(gotent->plt_offset + 4); 4917 insn = INSN_AD (INSN_BR, 28, disp); 4918 bfd_put_32 (output_bfd, insn, 4919 splt->contents + gotent->plt_offset); 4920 bfd_put_32 (output_bfd, INSN_UNOP, 4921 splt->contents + gotent->plt_offset + 4); 4922 bfd_put_32 (output_bfd, INSN_UNOP, 4923 splt->contents + gotent->plt_offset + 8); 4924 4925 plt_index = ((gotent->plt_offset - OLD_PLT_HEADER_SIZE) 4926 / OLD_PLT_ENTRY_SIZE); 4927 } 4928 4929 /* Fill in the entry in the .rela.plt section. */ 4930 outrel.r_offset = got_addr; 4931 outrel.r_info = ELF64_R_INFO(h->dynindx, R_ALPHA_JMP_SLOT); 4932 outrel.r_addend = 0; 4933 4934 loc = srel->contents + plt_index * sizeof (Elf64_External_Rela); 4935 bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc); 4936 4937 /* Fill in the entry in the .got. */ 4938 bfd_put_64 (output_bfd, plt_addr, 4939 sgot->contents + gotent->got_offset); 4940 } 4941 } 4942 else if (alpha_elf_dynamic_symbol_p (h, info)) 4943 { 4944 /* Fill in the dynamic relocations for this symbol's .got entries. */ 4945 asection *srel; 4946 struct alpha_elf_got_entry *gotent; 4947 4948 srel = bfd_get_linker_section (dynobj, ".rela.got"); 4949 BFD_ASSERT (srel != NULL); 4950 4951 for (gotent = ((struct alpha_elf_link_hash_entry *) h)->got_entries; 4952 gotent != NULL; 4953 gotent = gotent->next) 4954 { 4955 asection *sgot; 4956 long r_type; 4957 4958 if (gotent->use_count == 0) 4959 continue; 4960 4961 sgot = alpha_elf_tdata (gotent->gotobj)->got; 4962 4963 r_type = gotent->reloc_type; 4964 switch (r_type) 4965 { 4966 case R_ALPHA_LITERAL: 4967 r_type = R_ALPHA_GLOB_DAT; 4968 break; 4969 case R_ALPHA_TLSGD: 4970 r_type = R_ALPHA_DTPMOD64; 4971 break; 4972 case R_ALPHA_GOTDTPREL: 4973 r_type = R_ALPHA_DTPREL64; 4974 break; 4975 case R_ALPHA_GOTTPREL: 4976 r_type = R_ALPHA_TPREL64; 4977 break; 4978 case R_ALPHA_TLSLDM: 4979 default: 4980 abort (); 4981 } 4982 4983 elf64_alpha_emit_dynrel (output_bfd, info, sgot, srel, 4984 gotent->got_offset, h->dynindx, 4985 r_type, gotent->addend); 4986 4987 if (gotent->reloc_type == R_ALPHA_TLSGD) 4988 elf64_alpha_emit_dynrel (output_bfd, info, sgot, srel, 4989 gotent->got_offset + 8, h->dynindx, 4990 R_ALPHA_DTPREL64, gotent->addend); 4991 } 4992 } 4993 4994 /* Mark some specially defined symbols as absolute. */ 4995 if (h == elf_hash_table (info)->hdynamic 4996 || h == elf_hash_table (info)->hgot 4997 || h == elf_hash_table (info)->hplt) 4998 sym->st_shndx = SHN_ABS; 4999 5000 return TRUE; 5001 } 5002 5003 /* Finish up the dynamic sections. */ 5004 5005 static bfd_boolean 5006 elf64_alpha_finish_dynamic_sections (bfd *output_bfd, 5007 struct bfd_link_info *info) 5008 { 5009 bfd *dynobj; 5010 asection *sdyn; 5011 5012 dynobj = elf_hash_table (info)->dynobj; 5013 sdyn = bfd_get_linker_section (dynobj, ".dynamic"); 5014 5015 if (elf_hash_table (info)->dynamic_sections_created) 5016 { 5017 asection *splt, *sgotplt, *srelaplt; 5018 Elf64_External_Dyn *dyncon, *dynconend; 5019 bfd_vma plt_vma, gotplt_vma; 5020 5021 splt = bfd_get_linker_section (dynobj, ".plt"); 5022 srelaplt = bfd_get_linker_section (dynobj, ".rela.plt"); 5023 BFD_ASSERT (splt != NULL && sdyn != NULL); 5024 5025 plt_vma = splt->output_section->vma + splt->output_offset; 5026 5027 gotplt_vma = 0; 5028 if (elf64_alpha_use_secureplt) 5029 { 5030 sgotplt = bfd_get_linker_section (dynobj, ".got.plt"); 5031 BFD_ASSERT (sgotplt != NULL); 5032 if (sgotplt->size > 0) 5033 gotplt_vma = sgotplt->output_section->vma + sgotplt->output_offset; 5034 } 5035 5036 dyncon = (Elf64_External_Dyn *) sdyn->contents; 5037 dynconend = (Elf64_External_Dyn *) (sdyn->contents + sdyn->size); 5038 for (; dyncon < dynconend; dyncon++) 5039 { 5040 Elf_Internal_Dyn dyn; 5041 5042 bfd_elf64_swap_dyn_in (dynobj, dyncon, &dyn); 5043 5044 switch (dyn.d_tag) 5045 { 5046 case DT_PLTGOT: 5047 dyn.d_un.d_ptr 5048 = elf64_alpha_use_secureplt ? gotplt_vma : plt_vma; 5049 break; 5050 case DT_PLTRELSZ: 5051 dyn.d_un.d_val = srelaplt ? srelaplt->size : 0; 5052 break; 5053 case DT_JMPREL: 5054 dyn.d_un.d_ptr = srelaplt ? (srelaplt->output_section->vma 5055 + srelaplt->output_offset) : 0; 5056 break; 5057 5058 case DT_RELASZ: 5059 /* My interpretation of the TIS v1.1 ELF document indicates 5060 that RELASZ should not include JMPREL. This is not what 5061 the rest of the BFD does. It is, however, what the 5062 glibc ld.so wants. Do this fixup here until we found 5063 out who is right. */ 5064 if (srelaplt) 5065 dyn.d_un.d_val -= srelaplt->size; 5066 break; 5067 } 5068 5069 bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon); 5070 } 5071 5072 /* Initialize the plt header. */ 5073 if (splt->size > 0) 5074 { 5075 unsigned int insn; 5076 int ofs; 5077 5078 if (elf64_alpha_use_secureplt) 5079 { 5080 ofs = gotplt_vma - (plt_vma + PLT_HEADER_SIZE); 5081 5082 insn = INSN_ABC (INSN_SUBQ, 27, 28, 25); 5083 bfd_put_32 (output_bfd, insn, splt->contents); 5084 5085 insn = INSN_ABO (INSN_LDAH, 28, 28, (ofs + 0x8000) >> 16); 5086 bfd_put_32 (output_bfd, insn, splt->contents + 4); 5087 5088 insn = INSN_ABC (INSN_S4SUBQ, 25, 25, 25); 5089 bfd_put_32 (output_bfd, insn, splt->contents + 8); 5090 5091 insn = INSN_ABO (INSN_LDA, 28, 28, ofs); 5092 bfd_put_32 (output_bfd, insn, splt->contents + 12); 5093 5094 insn = INSN_ABO (INSN_LDQ, 27, 28, 0); 5095 bfd_put_32 (output_bfd, insn, splt->contents + 16); 5096 5097 insn = INSN_ABC (INSN_ADDQ, 25, 25, 25); 5098 bfd_put_32 (output_bfd, insn, splt->contents + 20); 5099 5100 insn = INSN_ABO (INSN_LDQ, 28, 28, 8); 5101 bfd_put_32 (output_bfd, insn, splt->contents + 24); 5102 5103 insn = INSN_AB (INSN_JMP, 31, 27); 5104 bfd_put_32 (output_bfd, insn, splt->contents + 28); 5105 5106 insn = INSN_AD (INSN_BR, 28, -PLT_HEADER_SIZE); 5107 bfd_put_32 (output_bfd, insn, splt->contents + 32); 5108 } 5109 else 5110 { 5111 insn = INSN_AD (INSN_BR, 27, 0); /* br $27, .+4 */ 5112 bfd_put_32 (output_bfd, insn, splt->contents); 5113 5114 insn = INSN_ABO (INSN_LDQ, 27, 27, 12); 5115 bfd_put_32 (output_bfd, insn, splt->contents + 4); 5116 5117 insn = INSN_UNOP; 5118 bfd_put_32 (output_bfd, insn, splt->contents + 8); 5119 5120 insn = INSN_AB (INSN_JMP, 27, 27); 5121 bfd_put_32 (output_bfd, insn, splt->contents + 12); 5122 5123 /* The next two words will be filled in by ld.so. */ 5124 bfd_put_64 (output_bfd, 0, splt->contents + 16); 5125 bfd_put_64 (output_bfd, 0, splt->contents + 24); 5126 } 5127 5128 elf_section_data (splt->output_section)->this_hdr.sh_entsize = 0; 5129 } 5130 } 5131 5132 return TRUE; 5133 } 5134 5135 /* We need to use a special link routine to handle the .mdebug section. 5136 We need to merge all instances of these sections together, not write 5137 them all out sequentially. */ 5138 5139 static bfd_boolean 5140 elf64_alpha_final_link (bfd *abfd, struct bfd_link_info *info) 5141 { 5142 asection *o; 5143 struct bfd_link_order *p; 5144 asection *mdebug_sec; 5145 struct ecoff_debug_info debug; 5146 const struct ecoff_debug_swap *swap 5147 = get_elf_backend_data (abfd)->elf_backend_ecoff_debug_swap; 5148 HDRR *symhdr = &debug.symbolic_header; 5149 void * mdebug_handle = NULL; 5150 struct alpha_elf_link_hash_table * htab; 5151 5152 htab = alpha_elf_hash_table (info); 5153 if (htab == NULL) 5154 return FALSE; 5155 5156 /* Go through the sections and collect the mdebug information. */ 5157 mdebug_sec = NULL; 5158 for (o = abfd->sections; o != (asection *) NULL; o = o->next) 5159 { 5160 if (strcmp (o->name, ".mdebug") == 0) 5161 { 5162 struct extsym_info einfo; 5163 5164 /* We have found the .mdebug section in the output file. 5165 Look through all the link_orders comprising it and merge 5166 the information together. */ 5167 symhdr->magic = swap->sym_magic; 5168 /* FIXME: What should the version stamp be? */ 5169 symhdr->vstamp = 0; 5170 symhdr->ilineMax = 0; 5171 symhdr->cbLine = 0; 5172 symhdr->idnMax = 0; 5173 symhdr->ipdMax = 0; 5174 symhdr->isymMax = 0; 5175 symhdr->ioptMax = 0; 5176 symhdr->iauxMax = 0; 5177 symhdr->issMax = 0; 5178 symhdr->issExtMax = 0; 5179 symhdr->ifdMax = 0; 5180 symhdr->crfd = 0; 5181 symhdr->iextMax = 0; 5182 5183 /* We accumulate the debugging information itself in the 5184 debug_info structure. */ 5185 debug.line = NULL; 5186 debug.external_dnr = NULL; 5187 debug.external_pdr = NULL; 5188 debug.external_sym = NULL; 5189 debug.external_opt = NULL; 5190 debug.external_aux = NULL; 5191 debug.ss = NULL; 5192 debug.ssext = debug.ssext_end = NULL; 5193 debug.external_fdr = NULL; 5194 debug.external_rfd = NULL; 5195 debug.external_ext = debug.external_ext_end = NULL; 5196 5197 mdebug_handle = bfd_ecoff_debug_init (abfd, &debug, swap, info); 5198 if (mdebug_handle == NULL) 5199 return FALSE; 5200 5201 if (1) 5202 { 5203 asection *s; 5204 EXTR esym; 5205 bfd_vma last = 0; 5206 unsigned int i; 5207 static const char * const name[] = 5208 { 5209 ".text", ".init", ".fini", ".data", 5210 ".rodata", ".sdata", ".sbss", ".bss" 5211 }; 5212 static const int sc[] = { scText, scInit, scFini, scData, 5213 scRData, scSData, scSBss, scBss }; 5214 5215 esym.jmptbl = 0; 5216 esym.cobol_main = 0; 5217 esym.weakext = 0; 5218 esym.reserved = 0; 5219 esym.ifd = ifdNil; 5220 esym.asym.iss = issNil; 5221 esym.asym.st = stLocal; 5222 esym.asym.reserved = 0; 5223 esym.asym.index = indexNil; 5224 for (i = 0; i < 8; i++) 5225 { 5226 esym.asym.sc = sc[i]; 5227 s = bfd_get_section_by_name (abfd, name[i]); 5228 if (s != NULL) 5229 { 5230 esym.asym.value = s->vma; 5231 last = s->vma + s->size; 5232 } 5233 else 5234 esym.asym.value = last; 5235 5236 if (! bfd_ecoff_debug_one_external (abfd, &debug, swap, 5237 name[i], &esym)) 5238 return FALSE; 5239 } 5240 } 5241 5242 for (p = o->map_head.link_order; 5243 p != (struct bfd_link_order *) NULL; 5244 p = p->next) 5245 { 5246 asection *input_section; 5247 bfd *input_bfd; 5248 const struct ecoff_debug_swap *input_swap; 5249 struct ecoff_debug_info input_debug; 5250 char *eraw_src; 5251 char *eraw_end; 5252 5253 if (p->type != bfd_indirect_link_order) 5254 { 5255 if (p->type == bfd_data_link_order) 5256 continue; 5257 abort (); 5258 } 5259 5260 input_section = p->u.indirect.section; 5261 input_bfd = input_section->owner; 5262 5263 if (! is_alpha_elf (input_bfd)) 5264 /* I don't know what a non ALPHA ELF bfd would be 5265 doing with a .mdebug section, but I don't really 5266 want to deal with it. */ 5267 continue; 5268 5269 input_swap = (get_elf_backend_data (input_bfd) 5270 ->elf_backend_ecoff_debug_swap); 5271 5272 BFD_ASSERT (p->size == input_section->size); 5273 5274 /* The ECOFF linking code expects that we have already 5275 read in the debugging information and set up an 5276 ecoff_debug_info structure, so we do that now. */ 5277 if (!elf64_alpha_read_ecoff_info (input_bfd, input_section, 5278 &input_debug)) 5279 return FALSE; 5280 5281 if (! (bfd_ecoff_debug_accumulate 5282 (mdebug_handle, abfd, &debug, swap, input_bfd, 5283 &input_debug, input_swap, info))) 5284 return FALSE; 5285 5286 /* Loop through the external symbols. For each one with 5287 interesting information, try to find the symbol in 5288 the linker global hash table and save the information 5289 for the output external symbols. */ 5290 eraw_src = (char *) input_debug.external_ext; 5291 eraw_end = (eraw_src 5292 + (input_debug.symbolic_header.iextMax 5293 * input_swap->external_ext_size)); 5294 for (; 5295 eraw_src < eraw_end; 5296 eraw_src += input_swap->external_ext_size) 5297 { 5298 EXTR ext; 5299 const char *name; 5300 struct alpha_elf_link_hash_entry *h; 5301 5302 (*input_swap->swap_ext_in) (input_bfd, eraw_src, &ext); 5303 if (ext.asym.sc == scNil 5304 || ext.asym.sc == scUndefined 5305 || ext.asym.sc == scSUndefined) 5306 continue; 5307 5308 name = input_debug.ssext + ext.asym.iss; 5309 h = alpha_elf_link_hash_lookup (htab, name, FALSE, FALSE, TRUE); 5310 if (h == NULL || h->esym.ifd != -2) 5311 continue; 5312 5313 if (ext.ifd != -1) 5314 { 5315 BFD_ASSERT (ext.ifd 5316 < input_debug.symbolic_header.ifdMax); 5317 ext.ifd = input_debug.ifdmap[ext.ifd]; 5318 } 5319 5320 h->esym = ext; 5321 } 5322 5323 /* Free up the information we just read. */ 5324 free (input_debug.line); 5325 free (input_debug.external_dnr); 5326 free (input_debug.external_pdr); 5327 free (input_debug.external_sym); 5328 free (input_debug.external_opt); 5329 free (input_debug.external_aux); 5330 free (input_debug.ss); 5331 free (input_debug.ssext); 5332 free (input_debug.external_fdr); 5333 free (input_debug.external_rfd); 5334 free (input_debug.external_ext); 5335 5336 /* Hack: reset the SEC_HAS_CONTENTS flag so that 5337 elf_link_input_bfd ignores this section. */ 5338 input_section->flags &=~ SEC_HAS_CONTENTS; 5339 } 5340 5341 /* Build the external symbol information. */ 5342 einfo.abfd = abfd; 5343 einfo.info = info; 5344 einfo.debug = &debug; 5345 einfo.swap = swap; 5346 einfo.failed = FALSE; 5347 elf_link_hash_traverse (elf_hash_table (info), 5348 elf64_alpha_output_extsym, 5349 &einfo); 5350 if (einfo.failed) 5351 return FALSE; 5352 5353 /* Set the size of the .mdebug section. */ 5354 o->size = bfd_ecoff_debug_size (abfd, &debug, swap); 5355 5356 /* Skip this section later on (I don't think this currently 5357 matters, but someday it might). */ 5358 o->map_head.link_order = (struct bfd_link_order *) NULL; 5359 5360 mdebug_sec = o; 5361 } 5362 } 5363 5364 /* Invoke the regular ELF backend linker to do all the work. */ 5365 if (! bfd_elf_final_link (abfd, info)) 5366 return FALSE; 5367 5368 /* Now write out the computed sections. */ 5369 5370 /* The .got subsections... */ 5371 { 5372 bfd *i, *dynobj = elf_hash_table(info)->dynobj; 5373 for (i = htab->got_list; 5374 i != NULL; 5375 i = alpha_elf_tdata(i)->got_link_next) 5376 { 5377 asection *sgot; 5378 5379 /* elf_bfd_final_link already did everything in dynobj. */ 5380 if (i == dynobj) 5381 continue; 5382 5383 sgot = alpha_elf_tdata(i)->got; 5384 if (! bfd_set_section_contents (abfd, sgot->output_section, 5385 sgot->contents, 5386 (file_ptr) sgot->output_offset, 5387 sgot->size)) 5388 return FALSE; 5389 } 5390 } 5391 5392 if (mdebug_sec != (asection *) NULL) 5393 { 5394 BFD_ASSERT (abfd->output_has_begun); 5395 if (! bfd_ecoff_write_accumulated_debug (mdebug_handle, abfd, &debug, 5396 swap, info, 5397 mdebug_sec->filepos)) 5398 return FALSE; 5399 5400 bfd_ecoff_debug_free (mdebug_handle, abfd, &debug, swap, info); 5401 } 5402 5403 return TRUE; 5404 } 5405 5406 static enum elf_reloc_type_class 5407 elf64_alpha_reloc_type_class (const struct bfd_link_info *info ATTRIBUTE_UNUSED, 5408 const asection *rel_sec ATTRIBUTE_UNUSED, 5409 const Elf_Internal_Rela *rela) 5410 { 5411 switch ((int) ELF64_R_TYPE (rela->r_info)) 5412 { 5413 case R_ALPHA_RELATIVE: 5414 return reloc_class_relative; 5415 case R_ALPHA_JMP_SLOT: 5416 return reloc_class_plt; 5417 case R_ALPHA_COPY: 5418 return reloc_class_copy; 5419 default: 5420 return reloc_class_normal; 5421 } 5422 } 5423 5424 static const struct bfd_elf_special_section elf64_alpha_special_sections[] = 5426 { 5427 { STRING_COMMA_LEN (".sbss"), -2, SHT_NOBITS, SHF_ALLOC + SHF_WRITE + SHF_ALPHA_GPREL }, 5428 { STRING_COMMA_LEN (".sdata"), -2, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE + SHF_ALPHA_GPREL }, 5429 { NULL, 0, 0, 0, 0 } 5430 }; 5431 5432 /* ECOFF swapping routines. These are used when dealing with the 5433 .mdebug section, which is in the ECOFF debugging format. Copied 5434 from elf32-mips.c. */ 5435 static const struct ecoff_debug_swap 5436 elf64_alpha_ecoff_debug_swap = 5437 { 5438 /* Symbol table magic number. */ 5439 magicSym2, 5440 /* Alignment of debugging information. E.g., 4. */ 5441 8, 5442 /* Sizes of external symbolic information. */ 5443 sizeof (struct hdr_ext), 5444 sizeof (struct dnr_ext), 5445 sizeof (struct pdr_ext), 5446 sizeof (struct sym_ext), 5447 sizeof (struct opt_ext), 5448 sizeof (struct fdr_ext), 5449 sizeof (struct rfd_ext), 5450 sizeof (struct ext_ext), 5451 /* Functions to swap in external symbolic data. */ 5452 ecoff_swap_hdr_in, 5453 ecoff_swap_dnr_in, 5454 ecoff_swap_pdr_in, 5455 ecoff_swap_sym_in, 5456 ecoff_swap_opt_in, 5457 ecoff_swap_fdr_in, 5458 ecoff_swap_rfd_in, 5459 ecoff_swap_ext_in, 5460 _bfd_ecoff_swap_tir_in, 5461 _bfd_ecoff_swap_rndx_in, 5462 /* Functions to swap out external symbolic data. */ 5463 ecoff_swap_hdr_out, 5464 ecoff_swap_dnr_out, 5465 ecoff_swap_pdr_out, 5466 ecoff_swap_sym_out, 5467 ecoff_swap_opt_out, 5468 ecoff_swap_fdr_out, 5469 ecoff_swap_rfd_out, 5470 ecoff_swap_ext_out, 5471 _bfd_ecoff_swap_tir_out, 5472 _bfd_ecoff_swap_rndx_out, 5473 /* Function to read in symbolic data. */ 5474 elf64_alpha_read_ecoff_info 5475 }; 5476 5477 /* Use a non-standard hash bucket size of 8. */ 5479 5480 static const struct elf_size_info alpha_elf_size_info = 5481 { 5482 sizeof (Elf64_External_Ehdr), 5483 sizeof (Elf64_External_Phdr), 5484 sizeof (Elf64_External_Shdr), 5485 sizeof (Elf64_External_Rel), 5486 sizeof (Elf64_External_Rela), 5487 sizeof (Elf64_External_Sym), 5488 sizeof (Elf64_External_Dyn), 5489 sizeof (Elf_External_Note), 5490 8, 5491 1, 5492 64, 3, 5493 ELFCLASS64, EV_CURRENT, 5494 bfd_elf64_write_out_phdrs, 5495 bfd_elf64_write_shdrs_and_ehdr, 5496 bfd_elf64_checksum_contents, 5497 bfd_elf64_write_relocs, 5498 bfd_elf64_swap_symbol_in, 5499 bfd_elf64_swap_symbol_out, 5500 bfd_elf64_slurp_reloc_table, 5501 bfd_elf64_slurp_symbol_table, 5502 bfd_elf64_swap_dyn_in, 5503 bfd_elf64_swap_dyn_out, 5504 bfd_elf64_swap_reloc_in, 5505 bfd_elf64_swap_reloc_out, 5506 bfd_elf64_swap_reloca_in, 5507 bfd_elf64_swap_reloca_out 5508 }; 5509 5510 #define TARGET_LITTLE_SYM alpha_elf64_vec 5511 #define TARGET_LITTLE_NAME "elf64-alpha" 5512 #define ELF_ARCH bfd_arch_alpha 5513 #define ELF_TARGET_ID ALPHA_ELF_DATA 5514 #define ELF_MACHINE_CODE EM_ALPHA 5515 #define ELF_MAXPAGESIZE 0x10000 5516 #define ELF_COMMONPAGESIZE 0x2000 5517 5518 #define bfd_elf64_bfd_link_hash_table_create \ 5519 elf64_alpha_bfd_link_hash_table_create 5520 5521 #define bfd_elf64_bfd_reloc_type_lookup \ 5522 elf64_alpha_bfd_reloc_type_lookup 5523 #define bfd_elf64_bfd_reloc_name_lookup \ 5524 elf64_alpha_bfd_reloc_name_lookup 5525 #define elf_info_to_howto \ 5526 elf64_alpha_info_to_howto 5527 5528 #define bfd_elf64_mkobject \ 5529 elf64_alpha_mkobject 5530 #define elf_backend_object_p \ 5531 elf64_alpha_object_p 5532 5533 #define elf_backend_section_from_shdr \ 5534 elf64_alpha_section_from_shdr 5535 #define elf_backend_section_flags \ 5536 elf64_alpha_section_flags 5537 #define elf_backend_fake_sections \ 5538 elf64_alpha_fake_sections 5539 5540 #define bfd_elf64_bfd_is_local_label_name \ 5541 elf64_alpha_is_local_label_name 5542 #define bfd_elf64_find_nearest_line \ 5543 elf64_alpha_find_nearest_line 5544 #define bfd_elf64_bfd_relax_section \ 5545 elf64_alpha_relax_section 5546 5547 #define elf_backend_add_symbol_hook \ 5548 elf64_alpha_add_symbol_hook 5549 #define elf_backend_relocs_compatible \ 5550 _bfd_elf_relocs_compatible 5551 #define elf_backend_sort_relocs_p \ 5552 elf64_alpha_sort_relocs_p 5553 #define elf_backend_check_relocs \ 5554 elf64_alpha_check_relocs 5555 #define elf_backend_create_dynamic_sections \ 5556 elf64_alpha_create_dynamic_sections 5557 #define elf_backend_adjust_dynamic_symbol \ 5558 elf64_alpha_adjust_dynamic_symbol 5559 #define elf_backend_merge_symbol_attribute \ 5560 elf64_alpha_merge_symbol_attribute 5561 #define elf_backend_copy_indirect_symbol \ 5562 elf64_alpha_copy_indirect_symbol 5563 #define elf_backend_always_size_sections \ 5564 elf64_alpha_always_size_sections 5565 #define elf_backend_size_dynamic_sections \ 5566 elf64_alpha_size_dynamic_sections 5567 #define elf_backend_omit_section_dynsym \ 5568 ((bfd_boolean (*) (bfd *, struct bfd_link_info *, asection *)) bfd_true) 5569 #define elf_backend_relocate_section \ 5570 elf64_alpha_relocate_section 5571 #define elf_backend_finish_dynamic_symbol \ 5572 elf64_alpha_finish_dynamic_symbol 5573 #define elf_backend_finish_dynamic_sections \ 5574 elf64_alpha_finish_dynamic_sections 5575 #define bfd_elf64_bfd_final_link \ 5576 elf64_alpha_final_link 5577 #define elf_backend_reloc_type_class \ 5578 elf64_alpha_reloc_type_class 5579 5580 #define elf_backend_can_gc_sections 1 5581 #define elf_backend_gc_mark_hook elf64_alpha_gc_mark_hook 5582 #define elf_backend_gc_sweep_hook elf64_alpha_gc_sweep_hook 5583 5584 #define elf_backend_ecoff_debug_swap \ 5585 &elf64_alpha_ecoff_debug_swap 5586 5587 #define elf_backend_size_info \ 5588 alpha_elf_size_info 5589 5590 #define elf_backend_special_sections \ 5591 elf64_alpha_special_sections 5592 5593 /* A few constants that determine how the .plt section is set up. */ 5594 #define elf_backend_want_got_plt 0 5595 #define elf_backend_plt_readonly 0 5596 #define elf_backend_want_plt_sym 1 5597 #define elf_backend_got_header_size 0 5598 5599 #include "elf64-target.h" 5600 5601 /* FreeBSD support. */ 5603 5604 #undef TARGET_LITTLE_SYM 5605 #define TARGET_LITTLE_SYM alpha_elf64_fbsd_vec 5606 #undef TARGET_LITTLE_NAME 5607 #define TARGET_LITTLE_NAME "elf64-alpha-freebsd" 5608 #undef ELF_OSABI 5609 #define ELF_OSABI ELFOSABI_FREEBSD 5610 5611 /* The kernel recognizes executables as valid only if they carry a 5612 "FreeBSD" label in the ELF header. So we put this label on all 5613 executables and (for simplicity) also all other object files. */ 5614 5615 static void 5616 elf64_alpha_fbsd_post_process_headers (bfd * abfd, 5617 struct bfd_link_info * link_info ATTRIBUTE_UNUSED) 5618 { 5619 Elf_Internal_Ehdr * i_ehdrp; /* ELF file header, internal form. */ 5620 5621 i_ehdrp = elf_elfheader (abfd); 5622 5623 /* Put an ABI label supported by FreeBSD >= 4.1. */ 5624 i_ehdrp->e_ident[EI_OSABI] = get_elf_backend_data (abfd)->elf_osabi; 5625 #ifdef OLD_FREEBSD_ABI_LABEL 5626 /* The ABI label supported by FreeBSD <= 4.0 is quite nonstandard. */ 5627 memcpy (&i_ehdrp->e_ident[EI_ABIVERSION], "FreeBSD", 8); 5628 #endif 5629 } 5630 5631 #undef elf_backend_post_process_headers 5632 #define elf_backend_post_process_headers \ 5633 elf64_alpha_fbsd_post_process_headers 5634 5635 #undef elf64_bed 5636 #define elf64_bed elf64_alpha_fbsd_bed 5637 5638 #include "elf64-target.h" 5639