1 /* PowerPC-specific support for 32-bit ELF 2 Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 3 2004 Free Software Foundation, Inc. 4 Written by Ian Lance Taylor, Cygnus Support. 5 6 This file is part of BFD, the Binary File Descriptor library. 7 8 This program is free software; you can redistribute it and/or modify 9 it under the terms of the GNU General Public License as published by 10 the Free Software Foundation; either version 2 of the License, or 11 (at your option) any later version. 12 13 This program is distributed in the hope that it will be useful, 14 but WITHOUT ANY WARRANTY; without even the implied warranty of 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 GNU General Public License for more details. 17 18 You should have received a copy of the GNU General Public License 19 along with this program; if not, write to the 20 Free Software Foundation, Inc., 59 Temple Place - Suite 330, 21 Boston, MA 02111-1307, USA. */ 22 23 /* This file is based on a preliminary PowerPC ELF ABI. The 24 information may not match the final PowerPC ELF ABI. It includes 25 suggestions from the in-progress Embedded PowerPC ABI, and that 26 information may also not match. */ 27 28 #include "bfd.h" 29 #include "sysdep.h" 30 #include "bfdlink.h" 31 #include "libbfd.h" 32 #include "elf-bfd.h" 33 #include "elf/ppc.h" 34 #include "elf32-ppc.h" 35 36 /* RELA relocations are used here. */ 37 38 static bfd_reloc_status_type ppc_elf_addr16_ha_reloc 39 (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); 40 static bfd_reloc_status_type ppc_elf_unhandled_reloc 41 (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); 42 43 /* Branch prediction bit for branch taken relocs. */ 44 #define BRANCH_PREDICT_BIT 0x200000 45 /* Mask to set RA in memory instructions. */ 46 #define RA_REGISTER_MASK 0x001f0000 47 /* Value to shift register by to insert RA. */ 48 #define RA_REGISTER_SHIFT 16 49 50 /* The name of the dynamic interpreter. This is put in the .interp 51 section. */ 52 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1" 53 54 /* The size in bytes of an entry in the procedure linkage table. */ 55 #define PLT_ENTRY_SIZE 12 56 /* The initial size of the plt reserved for the dynamic linker. */ 57 #define PLT_INITIAL_ENTRY_SIZE 72 58 /* The size of the gap between entries in the PLT. */ 59 #define PLT_SLOT_SIZE 8 60 /* The number of single-slot PLT entries (the rest use two slots). */ 61 #define PLT_NUM_SINGLE_ENTRIES 8192 62 63 /* Some nop instructions. */ 64 #define NOP 0x60000000 65 #define CROR_151515 0x4def7b82 66 #define CROR_313131 0x4ffffb82 67 68 /* Offset of tp and dtp pointers from start of TLS block. */ 69 #define TP_OFFSET 0x7000 70 #define DTP_OFFSET 0x8000 71 72 73 /* Enumeration to specify the special section. */ 74 enum elf_linker_section_enum 75 { 76 LINKER_SECTION_SDATA, 77 LINKER_SECTION_SDATA2 78 }; 79 80 /* Sections created by the linker. */ 81 82 typedef struct elf_linker_section 83 { 84 /* pointer to the section */ 85 asection *section; 86 /* pointer to the relocations needed for this section */ 87 asection *rel_section; 88 /* pointer to the created symbol hash value */ 89 struct elf_link_hash_entry *sym_hash; 90 /* offset of symbol from beginning of section */ 91 bfd_vma sym_offset; 92 } elf_linker_section_t; 93 94 /* Linked list of allocated pointer entries. This hangs off of the 95 symbol lists, and provides allows us to return different pointers, 96 based on different addend's. */ 97 98 typedef struct elf_linker_section_pointers 99 { 100 /* next allocated pointer for this symbol */ 101 struct elf_linker_section_pointers *next; 102 /* offset of pointer from beginning of section */ 103 bfd_vma offset; 104 /* addend used */ 105 bfd_vma addend; 106 /* which linker section this is */ 107 elf_linker_section_t *lsect; 108 /* whether address was written yet */ 109 bfd_boolean written_address_p; 110 } elf_linker_section_pointers_t; 111 112 struct ppc_elf_obj_tdata 113 { 114 struct elf_obj_tdata elf; 115 116 /* A mapping from local symbols to offsets into the various linker 117 sections added. This is index by the symbol index. */ 118 elf_linker_section_pointers_t **linker_section_pointers; 119 }; 120 121 #define ppc_elf_tdata(bfd) \ 122 ((struct ppc_elf_obj_tdata *) (bfd)->tdata.any) 123 124 #define elf_local_ptr_offsets(bfd) \ 125 (ppc_elf_tdata (bfd)->linker_section_pointers) 126 127 /* Override the generic function because we store some extras. */ 128 129 static bfd_boolean 130 ppc_elf_mkobject (bfd *abfd) 131 { 132 bfd_size_type amt = sizeof (struct ppc_elf_obj_tdata); 133 abfd->tdata.any = bfd_zalloc (abfd, amt); 134 if (abfd->tdata.any == NULL) 135 return FALSE; 136 return TRUE; 137 } 138 139 /* The PPC linker needs to keep track of the number of relocs that it 140 decides to copy as dynamic relocs in check_relocs for each symbol. 141 This is so that it can later discard them if they are found to be 142 unnecessary. We store the information in a field extending the 143 regular ELF linker hash table. */ 144 145 struct ppc_elf_dyn_relocs 146 { 147 struct ppc_elf_dyn_relocs *next; 148 149 /* The input section of the reloc. */ 150 asection *sec; 151 152 /* Total number of relocs copied for the input section. */ 153 bfd_size_type count; 154 155 /* Number of pc-relative relocs copied for the input section. */ 156 bfd_size_type pc_count; 157 }; 158 159 /* PPC ELF linker hash entry. */ 160 161 struct ppc_elf_link_hash_entry 162 { 163 struct elf_link_hash_entry elf; 164 165 /* If this symbol is used in the linker created sections, the processor 166 specific backend uses this field to map the field into the offset 167 from the beginning of the section. */ 168 elf_linker_section_pointers_t *linker_section_pointer; 169 170 /* Track dynamic relocs copied for this symbol. */ 171 struct ppc_elf_dyn_relocs *dyn_relocs; 172 173 /* Contexts in which symbol is used in the GOT (or TOC). 174 TLS_GD .. TLS_TLS bits are or'd into the mask as the 175 corresponding relocs are encountered during check_relocs. 176 tls_optimize clears TLS_GD .. TLS_TPREL when optimizing to 177 indicate the corresponding GOT entry type is not needed. */ 178 #define TLS_GD 1 /* GD reloc. */ 179 #define TLS_LD 2 /* LD reloc. */ 180 #define TLS_TPREL 4 /* TPREL reloc, => IE. */ 181 #define TLS_DTPREL 8 /* DTPREL reloc, => LD. */ 182 #define TLS_TLS 16 /* Any TLS reloc. */ 183 #define TLS_TPRELGD 32 /* TPREL reloc resulting from GD->IE. */ 184 char tls_mask; 185 }; 186 187 #define ppc_elf_hash_entry(ent) ((struct ppc_elf_link_hash_entry *) (ent)) 188 189 /* PPC ELF linker hash table. */ 190 191 struct ppc_elf_link_hash_table 192 { 193 struct elf_link_hash_table elf; 194 195 /* Short-cuts to get to dynamic linker sections. */ 196 asection *got; 197 asection *relgot; 198 asection *plt; 199 asection *relplt; 200 asection *dynbss; 201 asection *relbss; 202 asection *dynsbss; 203 asection *relsbss; 204 elf_linker_section_t *sdata; 205 elf_linker_section_t *sdata2; 206 asection *sbss; 207 208 /* Shortcut to .__tls_get_addr. */ 209 struct elf_link_hash_entry *tls_get_addr; 210 211 /* TLS local dynamic got entry handling. */ 212 union { 213 bfd_signed_vma refcount; 214 bfd_vma offset; 215 } tlsld_got; 216 217 /* Small local sym to section mapping cache. */ 218 struct sym_sec_cache sym_sec; 219 }; 220 221 /* Get the PPC ELF linker hash table from a link_info structure. */ 222 223 #define ppc_elf_hash_table(p) \ 224 ((struct ppc_elf_link_hash_table *) (p)->hash) 225 226 /* Create an entry in a PPC ELF linker hash table. */ 227 228 static struct bfd_hash_entry * 229 ppc_elf_link_hash_newfunc (struct bfd_hash_entry *entry, 230 struct bfd_hash_table *table, 231 const char *string) 232 { 233 /* Allocate the structure if it has not already been allocated by a 234 subclass. */ 235 if (entry == NULL) 236 { 237 entry = bfd_hash_allocate (table, 238 sizeof (struct ppc_elf_link_hash_entry)); 239 if (entry == NULL) 240 return entry; 241 } 242 243 /* Call the allocation method of the superclass. */ 244 entry = _bfd_elf_link_hash_newfunc (entry, table, string); 245 if (entry != NULL) 246 { 247 ppc_elf_hash_entry (entry)->linker_section_pointer = NULL; 248 ppc_elf_hash_entry (entry)->dyn_relocs = NULL; 249 ppc_elf_hash_entry (entry)->tls_mask = 0; 250 } 251 252 return entry; 253 } 254 255 /* Create a PPC ELF linker hash table. */ 256 257 static struct bfd_link_hash_table * 258 ppc_elf_link_hash_table_create (bfd *abfd) 259 { 260 struct ppc_elf_link_hash_table *ret; 261 262 ret = bfd_zmalloc (sizeof (struct ppc_elf_link_hash_table)); 263 if (ret == NULL) 264 return NULL; 265 266 if (! _bfd_elf_link_hash_table_init (&ret->elf, abfd, 267 ppc_elf_link_hash_newfunc)) 268 { 269 free (ret); 270 return NULL; 271 } 272 273 return &ret->elf.root; 274 } 275 276 /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid 277 copying dynamic variables from a shared lib into an app's dynbss 278 section, and instead use a dynamic relocation to point into the 279 shared lib. */ 280 #define ELIMINATE_COPY_RELOCS 1 281 282 /* Copy the extra info we tack onto an elf_link_hash_entry. */ 283 284 static void 285 ppc_elf_copy_indirect_symbol (const struct elf_backend_data *bed, 286 struct elf_link_hash_entry *dir, 287 struct elf_link_hash_entry *ind) 288 { 289 struct ppc_elf_link_hash_entry *edir, *eind; 290 291 edir = (struct ppc_elf_link_hash_entry *) dir; 292 eind = (struct ppc_elf_link_hash_entry *) ind; 293 294 if (eind->dyn_relocs != NULL) 295 { 296 if (edir->dyn_relocs != NULL) 297 { 298 struct ppc_elf_dyn_relocs **pp; 299 struct ppc_elf_dyn_relocs *p; 300 301 if (ind->root.type == bfd_link_hash_indirect) 302 abort (); 303 304 /* Add reloc counts against the weak sym to the strong sym 305 list. Merge any entries against the same section. */ 306 for (pp = &eind->dyn_relocs; (p = *pp) != NULL; ) 307 { 308 struct ppc_elf_dyn_relocs *q; 309 310 for (q = edir->dyn_relocs; q != NULL; q = q->next) 311 if (q->sec == p->sec) 312 { 313 q->pc_count += p->pc_count; 314 q->count += p->count; 315 *pp = p->next; 316 break; 317 } 318 if (q == NULL) 319 pp = &p->next; 320 } 321 *pp = edir->dyn_relocs; 322 } 323 324 edir->dyn_relocs = eind->dyn_relocs; 325 eind->dyn_relocs = NULL; 326 } 327 328 edir->tls_mask |= eind->tls_mask; 329 330 if (ELIMINATE_COPY_RELOCS 331 && ind->root.type != bfd_link_hash_indirect 332 && (dir->elf_link_hash_flags & ELF_LINK_HASH_DYNAMIC_ADJUSTED) != 0) 333 /* If called to transfer flags for a weakdef during processing 334 of elf_adjust_dynamic_symbol, don't copy ELF_LINK_NON_GOT_REF. 335 We clear it ourselves for ELIMINATE_COPY_RELOCS. */ 336 dir->elf_link_hash_flags |= 337 (ind->elf_link_hash_flags & (ELF_LINK_HASH_REF_DYNAMIC 338 | ELF_LINK_HASH_REF_REGULAR 339 | ELF_LINK_HASH_REF_REGULAR_NONWEAK 340 | ELF_LINK_HASH_NEEDS_PLT)); 341 else 342 _bfd_elf_link_hash_copy_indirect (bed, dir, ind); 343 } 344 345 static reloc_howto_type *ppc_elf_howto_table[R_PPC_max]; 346 347 static reloc_howto_type ppc_elf_howto_raw[] = { 348 /* This reloc does nothing. */ 349 HOWTO (R_PPC_NONE, /* type */ 350 0, /* rightshift */ 351 2, /* size (0 = byte, 1 = short, 2 = long) */ 352 32, /* bitsize */ 353 FALSE, /* pc_relative */ 354 0, /* bitpos */ 355 complain_overflow_bitfield, /* complain_on_overflow */ 356 bfd_elf_generic_reloc, /* special_function */ 357 "R_PPC_NONE", /* name */ 358 FALSE, /* partial_inplace */ 359 0, /* src_mask */ 360 0, /* dst_mask */ 361 FALSE), /* pcrel_offset */ 362 363 /* A standard 32 bit relocation. */ 364 HOWTO (R_PPC_ADDR32, /* type */ 365 0, /* rightshift */ 366 2, /* size (0 = byte, 1 = short, 2 = long) */ 367 32, /* bitsize */ 368 FALSE, /* pc_relative */ 369 0, /* bitpos */ 370 complain_overflow_bitfield, /* complain_on_overflow */ 371 bfd_elf_generic_reloc, /* special_function */ 372 "R_PPC_ADDR32", /* name */ 373 FALSE, /* partial_inplace */ 374 0, /* src_mask */ 375 0xffffffff, /* dst_mask */ 376 FALSE), /* pcrel_offset */ 377 378 /* An absolute 26 bit branch; the lower two bits must be zero. 379 FIXME: we don't check that, we just clear them. */ 380 HOWTO (R_PPC_ADDR24, /* type */ 381 0, /* rightshift */ 382 2, /* size (0 = byte, 1 = short, 2 = long) */ 383 26, /* bitsize */ 384 FALSE, /* pc_relative */ 385 0, /* bitpos */ 386 complain_overflow_bitfield, /* complain_on_overflow */ 387 bfd_elf_generic_reloc, /* special_function */ 388 "R_PPC_ADDR24", /* name */ 389 FALSE, /* partial_inplace */ 390 0, /* src_mask */ 391 0x3fffffc, /* dst_mask */ 392 FALSE), /* pcrel_offset */ 393 394 /* A standard 16 bit relocation. */ 395 HOWTO (R_PPC_ADDR16, /* type */ 396 0, /* rightshift */ 397 1, /* size (0 = byte, 1 = short, 2 = long) */ 398 16, /* bitsize */ 399 FALSE, /* pc_relative */ 400 0, /* bitpos */ 401 complain_overflow_bitfield, /* complain_on_overflow */ 402 bfd_elf_generic_reloc, /* special_function */ 403 "R_PPC_ADDR16", /* name */ 404 FALSE, /* partial_inplace */ 405 0, /* src_mask */ 406 0xffff, /* dst_mask */ 407 FALSE), /* pcrel_offset */ 408 409 /* A 16 bit relocation without overflow. */ 410 HOWTO (R_PPC_ADDR16_LO, /* type */ 411 0, /* rightshift */ 412 1, /* size (0 = byte, 1 = short, 2 = long) */ 413 16, /* bitsize */ 414 FALSE, /* pc_relative */ 415 0, /* bitpos */ 416 complain_overflow_dont,/* complain_on_overflow */ 417 bfd_elf_generic_reloc, /* special_function */ 418 "R_PPC_ADDR16_LO", /* name */ 419 FALSE, /* partial_inplace */ 420 0, /* src_mask */ 421 0xffff, /* dst_mask */ 422 FALSE), /* pcrel_offset */ 423 424 /* The high order 16 bits of an address. */ 425 HOWTO (R_PPC_ADDR16_HI, /* type */ 426 16, /* rightshift */ 427 1, /* size (0 = byte, 1 = short, 2 = long) */ 428 16, /* bitsize */ 429 FALSE, /* pc_relative */ 430 0, /* bitpos */ 431 complain_overflow_dont, /* complain_on_overflow */ 432 bfd_elf_generic_reloc, /* special_function */ 433 "R_PPC_ADDR16_HI", /* name */ 434 FALSE, /* partial_inplace */ 435 0, /* src_mask */ 436 0xffff, /* dst_mask */ 437 FALSE), /* pcrel_offset */ 438 439 /* The high order 16 bits of an address, plus 1 if the contents of 440 the low 16 bits, treated as a signed number, is negative. */ 441 HOWTO (R_PPC_ADDR16_HA, /* type */ 442 16, /* rightshift */ 443 1, /* size (0 = byte, 1 = short, 2 = long) */ 444 16, /* bitsize */ 445 FALSE, /* pc_relative */ 446 0, /* bitpos */ 447 complain_overflow_dont, /* complain_on_overflow */ 448 ppc_elf_addr16_ha_reloc, /* special_function */ 449 "R_PPC_ADDR16_HA", /* name */ 450 FALSE, /* partial_inplace */ 451 0, /* src_mask */ 452 0xffff, /* dst_mask */ 453 FALSE), /* pcrel_offset */ 454 455 /* An absolute 16 bit branch; the lower two bits must be zero. 456 FIXME: we don't check that, we just clear them. */ 457 HOWTO (R_PPC_ADDR14, /* type */ 458 0, /* rightshift */ 459 2, /* size (0 = byte, 1 = short, 2 = long) */ 460 16, /* bitsize */ 461 FALSE, /* pc_relative */ 462 0, /* bitpos */ 463 complain_overflow_bitfield, /* complain_on_overflow */ 464 bfd_elf_generic_reloc, /* special_function */ 465 "R_PPC_ADDR14", /* name */ 466 FALSE, /* partial_inplace */ 467 0, /* src_mask */ 468 0xfffc, /* dst_mask */ 469 FALSE), /* pcrel_offset */ 470 471 /* An absolute 16 bit branch, for which bit 10 should be set to 472 indicate that the branch is expected to be taken. The lower two 473 bits must be zero. */ 474 HOWTO (R_PPC_ADDR14_BRTAKEN, /* type */ 475 0, /* rightshift */ 476 2, /* size (0 = byte, 1 = short, 2 = long) */ 477 16, /* bitsize */ 478 FALSE, /* pc_relative */ 479 0, /* bitpos */ 480 complain_overflow_bitfield, /* complain_on_overflow */ 481 bfd_elf_generic_reloc, /* special_function */ 482 "R_PPC_ADDR14_BRTAKEN",/* name */ 483 FALSE, /* partial_inplace */ 484 0, /* src_mask */ 485 0xfffc, /* dst_mask */ 486 FALSE), /* pcrel_offset */ 487 488 /* An absolute 16 bit branch, for which bit 10 should be set to 489 indicate that the branch is not expected to be taken. The lower 490 two bits must be zero. */ 491 HOWTO (R_PPC_ADDR14_BRNTAKEN, /* type */ 492 0, /* rightshift */ 493 2, /* size (0 = byte, 1 = short, 2 = long) */ 494 16, /* bitsize */ 495 FALSE, /* pc_relative */ 496 0, /* bitpos */ 497 complain_overflow_bitfield, /* complain_on_overflow */ 498 bfd_elf_generic_reloc, /* special_function */ 499 "R_PPC_ADDR14_BRNTAKEN",/* name */ 500 FALSE, /* partial_inplace */ 501 0, /* src_mask */ 502 0xfffc, /* dst_mask */ 503 FALSE), /* pcrel_offset */ 504 505 /* A relative 26 bit branch; the lower two bits must be zero. */ 506 HOWTO (R_PPC_REL24, /* type */ 507 0, /* rightshift */ 508 2, /* size (0 = byte, 1 = short, 2 = long) */ 509 26, /* bitsize */ 510 TRUE, /* pc_relative */ 511 0, /* bitpos */ 512 complain_overflow_signed, /* complain_on_overflow */ 513 bfd_elf_generic_reloc, /* special_function */ 514 "R_PPC_REL24", /* name */ 515 FALSE, /* partial_inplace */ 516 0, /* src_mask */ 517 0x3fffffc, /* dst_mask */ 518 TRUE), /* pcrel_offset */ 519 520 /* A relative 16 bit branch; the lower two bits must be zero. */ 521 HOWTO (R_PPC_REL14, /* type */ 522 0, /* rightshift */ 523 2, /* size (0 = byte, 1 = short, 2 = long) */ 524 16, /* bitsize */ 525 TRUE, /* pc_relative */ 526 0, /* bitpos */ 527 complain_overflow_signed, /* complain_on_overflow */ 528 bfd_elf_generic_reloc, /* special_function */ 529 "R_PPC_REL14", /* name */ 530 FALSE, /* partial_inplace */ 531 0, /* src_mask */ 532 0xfffc, /* dst_mask */ 533 TRUE), /* pcrel_offset */ 534 535 /* A relative 16 bit branch. Bit 10 should be set to indicate that 536 the branch is expected to be taken. The lower two bits must be 537 zero. */ 538 HOWTO (R_PPC_REL14_BRTAKEN, /* type */ 539 0, /* rightshift */ 540 2, /* size (0 = byte, 1 = short, 2 = long) */ 541 16, /* bitsize */ 542 TRUE, /* pc_relative */ 543 0, /* bitpos */ 544 complain_overflow_signed, /* complain_on_overflow */ 545 bfd_elf_generic_reloc, /* special_function */ 546 "R_PPC_REL14_BRTAKEN", /* name */ 547 FALSE, /* partial_inplace */ 548 0, /* src_mask */ 549 0xfffc, /* dst_mask */ 550 TRUE), /* pcrel_offset */ 551 552 /* A relative 16 bit branch. Bit 10 should be set to indicate that 553 the branch is not expected to be taken. The lower two bits must 554 be zero. */ 555 HOWTO (R_PPC_REL14_BRNTAKEN, /* type */ 556 0, /* rightshift */ 557 2, /* size (0 = byte, 1 = short, 2 = long) */ 558 16, /* bitsize */ 559 TRUE, /* pc_relative */ 560 0, /* bitpos */ 561 complain_overflow_signed, /* complain_on_overflow */ 562 bfd_elf_generic_reloc, /* special_function */ 563 "R_PPC_REL14_BRNTAKEN",/* name */ 564 FALSE, /* partial_inplace */ 565 0, /* src_mask */ 566 0xfffc, /* dst_mask */ 567 TRUE), /* pcrel_offset */ 568 569 /* Like R_PPC_ADDR16, but referring to the GOT table entry for the 570 symbol. */ 571 HOWTO (R_PPC_GOT16, /* type */ 572 0, /* rightshift */ 573 1, /* size (0 = byte, 1 = short, 2 = long) */ 574 16, /* bitsize */ 575 FALSE, /* pc_relative */ 576 0, /* bitpos */ 577 complain_overflow_signed, /* complain_on_overflow */ 578 bfd_elf_generic_reloc, /* special_function */ 579 "R_PPC_GOT16", /* name */ 580 FALSE, /* partial_inplace */ 581 0, /* src_mask */ 582 0xffff, /* dst_mask */ 583 FALSE), /* pcrel_offset */ 584 585 /* Like R_PPC_ADDR16_LO, but referring to the GOT table entry for 586 the symbol. */ 587 HOWTO (R_PPC_GOT16_LO, /* type */ 588 0, /* rightshift */ 589 1, /* size (0 = byte, 1 = short, 2 = long) */ 590 16, /* bitsize */ 591 FALSE, /* pc_relative */ 592 0, /* bitpos */ 593 complain_overflow_dont, /* complain_on_overflow */ 594 bfd_elf_generic_reloc, /* special_function */ 595 "R_PPC_GOT16_LO", /* name */ 596 FALSE, /* partial_inplace */ 597 0, /* src_mask */ 598 0xffff, /* dst_mask */ 599 FALSE), /* pcrel_offset */ 600 601 /* Like R_PPC_ADDR16_HI, but referring to the GOT table entry for 602 the symbol. */ 603 HOWTO (R_PPC_GOT16_HI, /* type */ 604 16, /* rightshift */ 605 1, /* size (0 = byte, 1 = short, 2 = long) */ 606 16, /* bitsize */ 607 FALSE, /* pc_relative */ 608 0, /* bitpos */ 609 complain_overflow_bitfield, /* complain_on_overflow */ 610 bfd_elf_generic_reloc, /* special_function */ 611 "R_PPC_GOT16_HI", /* name */ 612 FALSE, /* partial_inplace */ 613 0, /* src_mask */ 614 0xffff, /* dst_mask */ 615 FALSE), /* pcrel_offset */ 616 617 /* Like R_PPC_ADDR16_HA, but referring to the GOT table entry for 618 the symbol. */ 619 HOWTO (R_PPC_GOT16_HA, /* type */ 620 16, /* rightshift */ 621 1, /* size (0 = byte, 1 = short, 2 = long) */ 622 16, /* bitsize */ 623 FALSE, /* pc_relative */ 624 0, /* bitpos */ 625 complain_overflow_bitfield, /* complain_on_overflow */ 626 ppc_elf_addr16_ha_reloc, /* special_function */ 627 "R_PPC_GOT16_HA", /* name */ 628 FALSE, /* partial_inplace */ 629 0, /* src_mask */ 630 0xffff, /* dst_mask */ 631 FALSE), /* pcrel_offset */ 632 633 /* Like R_PPC_REL24, but referring to the procedure linkage table 634 entry for the symbol. */ 635 HOWTO (R_PPC_PLTREL24, /* type */ 636 0, /* rightshift */ 637 2, /* size (0 = byte, 1 = short, 2 = long) */ 638 26, /* bitsize */ 639 TRUE, /* pc_relative */ 640 0, /* bitpos */ 641 complain_overflow_signed, /* complain_on_overflow */ 642 bfd_elf_generic_reloc, /* special_function */ 643 "R_PPC_PLTREL24", /* name */ 644 FALSE, /* partial_inplace */ 645 0, /* src_mask */ 646 0x3fffffc, /* dst_mask */ 647 TRUE), /* pcrel_offset */ 648 649 /* This is used only by the dynamic linker. The symbol should exist 650 both in the object being run and in some shared library. The 651 dynamic linker copies the data addressed by the symbol from the 652 shared library into the object, because the object being 653 run has to have the data at some particular address. */ 654 HOWTO (R_PPC_COPY, /* type */ 655 0, /* rightshift */ 656 2, /* size (0 = byte, 1 = short, 2 = long) */ 657 32, /* bitsize */ 658 FALSE, /* pc_relative */ 659 0, /* bitpos */ 660 complain_overflow_bitfield, /* complain_on_overflow */ 661 bfd_elf_generic_reloc, /* special_function */ 662 "R_PPC_COPY", /* name */ 663 FALSE, /* partial_inplace */ 664 0, /* src_mask */ 665 0, /* dst_mask */ 666 FALSE), /* pcrel_offset */ 667 668 /* Like R_PPC_ADDR32, but used when setting global offset table 669 entries. */ 670 HOWTO (R_PPC_GLOB_DAT, /* type */ 671 0, /* rightshift */ 672 2, /* size (0 = byte, 1 = short, 2 = long) */ 673 32, /* bitsize */ 674 FALSE, /* pc_relative */ 675 0, /* bitpos */ 676 complain_overflow_bitfield, /* complain_on_overflow */ 677 bfd_elf_generic_reloc, /* special_function */ 678 "R_PPC_GLOB_DAT", /* name */ 679 FALSE, /* partial_inplace */ 680 0, /* src_mask */ 681 0xffffffff, /* dst_mask */ 682 FALSE), /* pcrel_offset */ 683 684 /* Marks a procedure linkage table entry for a symbol. */ 685 HOWTO (R_PPC_JMP_SLOT, /* type */ 686 0, /* rightshift */ 687 2, /* size (0 = byte, 1 = short, 2 = long) */ 688 32, /* bitsize */ 689 FALSE, /* pc_relative */ 690 0, /* bitpos */ 691 complain_overflow_bitfield, /* complain_on_overflow */ 692 bfd_elf_generic_reloc, /* special_function */ 693 "R_PPC_JMP_SLOT", /* name */ 694 FALSE, /* partial_inplace */ 695 0, /* src_mask */ 696 0, /* dst_mask */ 697 FALSE), /* pcrel_offset */ 698 699 /* Used only by the dynamic linker. When the object is run, this 700 longword is set to the load address of the object, plus the 701 addend. */ 702 HOWTO (R_PPC_RELATIVE, /* type */ 703 0, /* rightshift */ 704 2, /* size (0 = byte, 1 = short, 2 = long) */ 705 32, /* bitsize */ 706 FALSE, /* pc_relative */ 707 0, /* bitpos */ 708 complain_overflow_bitfield, /* complain_on_overflow */ 709 bfd_elf_generic_reloc, /* special_function */ 710 "R_PPC_RELATIVE", /* name */ 711 FALSE, /* partial_inplace */ 712 0, /* src_mask */ 713 0xffffffff, /* dst_mask */ 714 FALSE), /* pcrel_offset */ 715 716 /* Like R_PPC_REL24, but uses the value of the symbol within the 717 object rather than the final value. Normally used for 718 _GLOBAL_OFFSET_TABLE_. */ 719 HOWTO (R_PPC_LOCAL24PC, /* type */ 720 0, /* rightshift */ 721 2, /* size (0 = byte, 1 = short, 2 = long) */ 722 26, /* bitsize */ 723 TRUE, /* pc_relative */ 724 0, /* bitpos */ 725 complain_overflow_signed, /* complain_on_overflow */ 726 bfd_elf_generic_reloc, /* special_function */ 727 "R_PPC_LOCAL24PC", /* name */ 728 FALSE, /* partial_inplace */ 729 0, /* src_mask */ 730 0x3fffffc, /* dst_mask */ 731 TRUE), /* pcrel_offset */ 732 733 /* Like R_PPC_ADDR32, but may be unaligned. */ 734 HOWTO (R_PPC_UADDR32, /* type */ 735 0, /* rightshift */ 736 2, /* size (0 = byte, 1 = short, 2 = long) */ 737 32, /* bitsize */ 738 FALSE, /* pc_relative */ 739 0, /* bitpos */ 740 complain_overflow_bitfield, /* complain_on_overflow */ 741 bfd_elf_generic_reloc, /* special_function */ 742 "R_PPC_UADDR32", /* name */ 743 FALSE, /* partial_inplace */ 744 0, /* src_mask */ 745 0xffffffff, /* dst_mask */ 746 FALSE), /* pcrel_offset */ 747 748 /* Like R_PPC_ADDR16, but may be unaligned. */ 749 HOWTO (R_PPC_UADDR16, /* type */ 750 0, /* rightshift */ 751 1, /* size (0 = byte, 1 = short, 2 = long) */ 752 16, /* bitsize */ 753 FALSE, /* pc_relative */ 754 0, /* bitpos */ 755 complain_overflow_bitfield, /* complain_on_overflow */ 756 bfd_elf_generic_reloc, /* special_function */ 757 "R_PPC_UADDR16", /* name */ 758 FALSE, /* partial_inplace */ 759 0, /* src_mask */ 760 0xffff, /* dst_mask */ 761 FALSE), /* pcrel_offset */ 762 763 /* 32-bit PC relative */ 764 HOWTO (R_PPC_REL32, /* type */ 765 0, /* rightshift */ 766 2, /* size (0 = byte, 1 = short, 2 = long) */ 767 32, /* bitsize */ 768 TRUE, /* pc_relative */ 769 0, /* bitpos */ 770 complain_overflow_bitfield, /* complain_on_overflow */ 771 bfd_elf_generic_reloc, /* special_function */ 772 "R_PPC_REL32", /* name */ 773 FALSE, /* partial_inplace */ 774 0, /* src_mask */ 775 0xffffffff, /* dst_mask */ 776 TRUE), /* pcrel_offset */ 777 778 /* 32-bit relocation to the symbol's procedure linkage table. 779 FIXME: not supported. */ 780 HOWTO (R_PPC_PLT32, /* type */ 781 0, /* rightshift */ 782 2, /* size (0 = byte, 1 = short, 2 = long) */ 783 32, /* bitsize */ 784 FALSE, /* pc_relative */ 785 0, /* bitpos */ 786 complain_overflow_bitfield, /* complain_on_overflow */ 787 bfd_elf_generic_reloc, /* special_function */ 788 "R_PPC_PLT32", /* name */ 789 FALSE, /* partial_inplace */ 790 0, /* src_mask */ 791 0, /* dst_mask */ 792 FALSE), /* pcrel_offset */ 793 794 /* 32-bit PC relative relocation to the symbol's procedure linkage table. 795 FIXME: not supported. */ 796 HOWTO (R_PPC_PLTREL32, /* type */ 797 0, /* rightshift */ 798 2, /* size (0 = byte, 1 = short, 2 = long) */ 799 32, /* bitsize */ 800 TRUE, /* pc_relative */ 801 0, /* bitpos */ 802 complain_overflow_bitfield, /* complain_on_overflow */ 803 bfd_elf_generic_reloc, /* special_function */ 804 "R_PPC_PLTREL32", /* name */ 805 FALSE, /* partial_inplace */ 806 0, /* src_mask */ 807 0, /* dst_mask */ 808 TRUE), /* pcrel_offset */ 809 810 /* Like R_PPC_ADDR16_LO, but referring to the PLT table entry for 811 the symbol. */ 812 HOWTO (R_PPC_PLT16_LO, /* type */ 813 0, /* rightshift */ 814 1, /* size (0 = byte, 1 = short, 2 = long) */ 815 16, /* bitsize */ 816 FALSE, /* pc_relative */ 817 0, /* bitpos */ 818 complain_overflow_dont, /* complain_on_overflow */ 819 bfd_elf_generic_reloc, /* special_function */ 820 "R_PPC_PLT16_LO", /* name */ 821 FALSE, /* partial_inplace */ 822 0, /* src_mask */ 823 0xffff, /* dst_mask */ 824 FALSE), /* pcrel_offset */ 825 826 /* Like R_PPC_ADDR16_HI, but referring to the PLT table entry for 827 the symbol. */ 828 HOWTO (R_PPC_PLT16_HI, /* type */ 829 16, /* rightshift */ 830 1, /* size (0 = byte, 1 = short, 2 = long) */ 831 16, /* bitsize */ 832 FALSE, /* pc_relative */ 833 0, /* bitpos */ 834 complain_overflow_bitfield, /* complain_on_overflow */ 835 bfd_elf_generic_reloc, /* special_function */ 836 "R_PPC_PLT16_HI", /* name */ 837 FALSE, /* partial_inplace */ 838 0, /* src_mask */ 839 0xffff, /* dst_mask */ 840 FALSE), /* pcrel_offset */ 841 842 /* Like R_PPC_ADDR16_HA, but referring to the PLT table entry for 843 the symbol. */ 844 HOWTO (R_PPC_PLT16_HA, /* type */ 845 16, /* rightshift */ 846 1, /* size (0 = byte, 1 = short, 2 = long) */ 847 16, /* bitsize */ 848 FALSE, /* pc_relative */ 849 0, /* bitpos */ 850 complain_overflow_bitfield, /* complain_on_overflow */ 851 ppc_elf_addr16_ha_reloc, /* special_function */ 852 "R_PPC_PLT16_HA", /* name */ 853 FALSE, /* partial_inplace */ 854 0, /* src_mask */ 855 0xffff, /* dst_mask */ 856 FALSE), /* pcrel_offset */ 857 858 /* A sign-extended 16 bit value relative to _SDA_BASE_, for use with 859 small data items. */ 860 HOWTO (R_PPC_SDAREL16, /* type */ 861 0, /* rightshift */ 862 1, /* size (0 = byte, 1 = short, 2 = long) */ 863 16, /* bitsize */ 864 FALSE, /* pc_relative */ 865 0, /* bitpos */ 866 complain_overflow_signed, /* complain_on_overflow */ 867 bfd_elf_generic_reloc, /* special_function */ 868 "R_PPC_SDAREL16", /* name */ 869 FALSE, /* partial_inplace */ 870 0, /* src_mask */ 871 0xffff, /* dst_mask */ 872 FALSE), /* pcrel_offset */ 873 874 /* 16-bit section relative relocation. */ 875 HOWTO (R_PPC_SECTOFF, /* type */ 876 0, /* rightshift */ 877 1, /* size (0 = byte, 1 = short, 2 = long) */ 878 16, /* bitsize */ 879 FALSE, /* pc_relative */ 880 0, /* bitpos */ 881 complain_overflow_bitfield, /* complain_on_overflow */ 882 bfd_elf_generic_reloc, /* special_function */ 883 "R_PPC_SECTOFF", /* name */ 884 FALSE, /* partial_inplace */ 885 0, /* src_mask */ 886 0xffff, /* dst_mask */ 887 FALSE), /* pcrel_offset */ 888 889 /* 16-bit lower half section relative relocation. */ 890 HOWTO (R_PPC_SECTOFF_LO, /* type */ 891 0, /* rightshift */ 892 1, /* size (0 = byte, 1 = short, 2 = long) */ 893 16, /* bitsize */ 894 FALSE, /* pc_relative */ 895 0, /* bitpos */ 896 complain_overflow_dont, /* complain_on_overflow */ 897 bfd_elf_generic_reloc, /* special_function */ 898 "R_PPC_SECTOFF_LO", /* name */ 899 FALSE, /* partial_inplace */ 900 0, /* src_mask */ 901 0xffff, /* dst_mask */ 902 FALSE), /* pcrel_offset */ 903 904 /* 16-bit upper half section relative relocation. */ 905 HOWTO (R_PPC_SECTOFF_HI, /* type */ 906 16, /* rightshift */ 907 1, /* size (0 = byte, 1 = short, 2 = long) */ 908 16, /* bitsize */ 909 FALSE, /* pc_relative */ 910 0, /* bitpos */ 911 complain_overflow_bitfield, /* complain_on_overflow */ 912 bfd_elf_generic_reloc, /* special_function */ 913 "R_PPC_SECTOFF_HI", /* name */ 914 FALSE, /* partial_inplace */ 915 0, /* src_mask */ 916 0xffff, /* dst_mask */ 917 FALSE), /* pcrel_offset */ 918 919 /* 16-bit upper half adjusted section relative relocation. */ 920 HOWTO (R_PPC_SECTOFF_HA, /* type */ 921 16, /* rightshift */ 922 1, /* size (0 = byte, 1 = short, 2 = long) */ 923 16, /* bitsize */ 924 FALSE, /* pc_relative */ 925 0, /* bitpos */ 926 complain_overflow_bitfield, /* complain_on_overflow */ 927 ppc_elf_addr16_ha_reloc, /* special_function */ 928 "R_PPC_SECTOFF_HA", /* name */ 929 FALSE, /* partial_inplace */ 930 0, /* src_mask */ 931 0xffff, /* dst_mask */ 932 FALSE), /* pcrel_offset */ 933 934 /* Marker reloc for TLS. */ 935 HOWTO (R_PPC_TLS, 936 0, /* rightshift */ 937 2, /* size (0 = byte, 1 = short, 2 = long) */ 938 32, /* bitsize */ 939 FALSE, /* pc_relative */ 940 0, /* bitpos */ 941 complain_overflow_dont, /* complain_on_overflow */ 942 bfd_elf_generic_reloc, /* special_function */ 943 "R_PPC_TLS", /* name */ 944 FALSE, /* partial_inplace */ 945 0, /* src_mask */ 946 0, /* dst_mask */ 947 FALSE), /* pcrel_offset */ 948 949 /* Computes the load module index of the load module that contains the 950 definition of its TLS sym. */ 951 HOWTO (R_PPC_DTPMOD32, 952 0, /* rightshift */ 953 2, /* size (0 = byte, 1 = short, 2 = long) */ 954 32, /* bitsize */ 955 FALSE, /* pc_relative */ 956 0, /* bitpos */ 957 complain_overflow_dont, /* complain_on_overflow */ 958 ppc_elf_unhandled_reloc, /* special_function */ 959 "R_PPC_DTPMOD32", /* name */ 960 FALSE, /* partial_inplace */ 961 0, /* src_mask */ 962 0xffffffff, /* dst_mask */ 963 FALSE), /* pcrel_offset */ 964 965 /* Computes a dtv-relative displacement, the difference between the value 966 of sym+add and the base address of the thread-local storage block that 967 contains the definition of sym, minus 0x8000. */ 968 HOWTO (R_PPC_DTPREL32, 969 0, /* rightshift */ 970 2, /* size (0 = byte, 1 = short, 2 = long) */ 971 32, /* bitsize */ 972 FALSE, /* pc_relative */ 973 0, /* bitpos */ 974 complain_overflow_dont, /* complain_on_overflow */ 975 ppc_elf_unhandled_reloc, /* special_function */ 976 "R_PPC_DTPREL32", /* name */ 977 FALSE, /* partial_inplace */ 978 0, /* src_mask */ 979 0xffffffff, /* dst_mask */ 980 FALSE), /* pcrel_offset */ 981 982 /* A 16 bit dtprel reloc. */ 983 HOWTO (R_PPC_DTPREL16, 984 0, /* rightshift */ 985 1, /* size (0 = byte, 1 = short, 2 = long) */ 986 16, /* bitsize */ 987 FALSE, /* pc_relative */ 988 0, /* bitpos */ 989 complain_overflow_signed, /* complain_on_overflow */ 990 ppc_elf_unhandled_reloc, /* special_function */ 991 "R_PPC_DTPREL16", /* name */ 992 FALSE, /* partial_inplace */ 993 0, /* src_mask */ 994 0xffff, /* dst_mask */ 995 FALSE), /* pcrel_offset */ 996 997 /* Like DTPREL16, but no overflow. */ 998 HOWTO (R_PPC_DTPREL16_LO, 999 0, /* rightshift */ 1000 1, /* size (0 = byte, 1 = short, 2 = long) */ 1001 16, /* bitsize */ 1002 FALSE, /* pc_relative */ 1003 0, /* bitpos */ 1004 complain_overflow_dont, /* complain_on_overflow */ 1005 ppc_elf_unhandled_reloc, /* special_function */ 1006 "R_PPC_DTPREL16_LO", /* name */ 1007 FALSE, /* partial_inplace */ 1008 0, /* src_mask */ 1009 0xffff, /* dst_mask */ 1010 FALSE), /* pcrel_offset */ 1011 1012 /* Like DTPREL16_LO, but next higher group of 16 bits. */ 1013 HOWTO (R_PPC_DTPREL16_HI, 1014 16, /* rightshift */ 1015 1, /* size (0 = byte, 1 = short, 2 = long) */ 1016 16, /* bitsize */ 1017 FALSE, /* pc_relative */ 1018 0, /* bitpos */ 1019 complain_overflow_dont, /* complain_on_overflow */ 1020 ppc_elf_unhandled_reloc, /* special_function */ 1021 "R_PPC_DTPREL16_HI", /* name */ 1022 FALSE, /* partial_inplace */ 1023 0, /* src_mask */ 1024 0xffff, /* dst_mask */ 1025 FALSE), /* pcrel_offset */ 1026 1027 /* Like DTPREL16_HI, but adjust for low 16 bits. */ 1028 HOWTO (R_PPC_DTPREL16_HA, 1029 16, /* rightshift */ 1030 1, /* size (0 = byte, 1 = short, 2 = long) */ 1031 16, /* bitsize */ 1032 FALSE, /* pc_relative */ 1033 0, /* bitpos */ 1034 complain_overflow_dont, /* complain_on_overflow */ 1035 ppc_elf_unhandled_reloc, /* special_function */ 1036 "R_PPC_DTPREL16_HA", /* name */ 1037 FALSE, /* partial_inplace */ 1038 0, /* src_mask */ 1039 0xffff, /* dst_mask */ 1040 FALSE), /* pcrel_offset */ 1041 1042 /* Computes a tp-relative displacement, the difference between the value of 1043 sym+add and the value of the thread pointer (r13). */ 1044 HOWTO (R_PPC_TPREL32, 1045 0, /* rightshift */ 1046 2, /* size (0 = byte, 1 = short, 2 = long) */ 1047 32, /* bitsize */ 1048 FALSE, /* pc_relative */ 1049 0, /* bitpos */ 1050 complain_overflow_dont, /* complain_on_overflow */ 1051 ppc_elf_unhandled_reloc, /* special_function */ 1052 "R_PPC_TPREL32", /* name */ 1053 FALSE, /* partial_inplace */ 1054 0, /* src_mask */ 1055 0xffffffff, /* dst_mask */ 1056 FALSE), /* pcrel_offset */ 1057 1058 /* A 16 bit tprel reloc. */ 1059 HOWTO (R_PPC_TPREL16, 1060 0, /* rightshift */ 1061 1, /* size (0 = byte, 1 = short, 2 = long) */ 1062 16, /* bitsize */ 1063 FALSE, /* pc_relative */ 1064 0, /* bitpos */ 1065 complain_overflow_signed, /* complain_on_overflow */ 1066 ppc_elf_unhandled_reloc, /* special_function */ 1067 "R_PPC_TPREL16", /* name */ 1068 FALSE, /* partial_inplace */ 1069 0, /* src_mask */ 1070 0xffff, /* dst_mask */ 1071 FALSE), /* pcrel_offset */ 1072 1073 /* Like TPREL16, but no overflow. */ 1074 HOWTO (R_PPC_TPREL16_LO, 1075 0, /* rightshift */ 1076 1, /* size (0 = byte, 1 = short, 2 = long) */ 1077 16, /* bitsize */ 1078 FALSE, /* pc_relative */ 1079 0, /* bitpos */ 1080 complain_overflow_dont, /* complain_on_overflow */ 1081 ppc_elf_unhandled_reloc, /* special_function */ 1082 "R_PPC_TPREL16_LO", /* name */ 1083 FALSE, /* partial_inplace */ 1084 0, /* src_mask */ 1085 0xffff, /* dst_mask */ 1086 FALSE), /* pcrel_offset */ 1087 1088 /* Like TPREL16_LO, but next higher group of 16 bits. */ 1089 HOWTO (R_PPC_TPREL16_HI, 1090 16, /* rightshift */ 1091 1, /* size (0 = byte, 1 = short, 2 = long) */ 1092 16, /* bitsize */ 1093 FALSE, /* pc_relative */ 1094 0, /* bitpos */ 1095 complain_overflow_dont, /* complain_on_overflow */ 1096 ppc_elf_unhandled_reloc, /* special_function */ 1097 "R_PPC_TPREL16_HI", /* name */ 1098 FALSE, /* partial_inplace */ 1099 0, /* src_mask */ 1100 0xffff, /* dst_mask */ 1101 FALSE), /* pcrel_offset */ 1102 1103 /* Like TPREL16_HI, but adjust for low 16 bits. */ 1104 HOWTO (R_PPC_TPREL16_HA, 1105 16, /* rightshift */ 1106 1, /* size (0 = byte, 1 = short, 2 = long) */ 1107 16, /* bitsize */ 1108 FALSE, /* pc_relative */ 1109 0, /* bitpos */ 1110 complain_overflow_dont, /* complain_on_overflow */ 1111 ppc_elf_unhandled_reloc, /* special_function */ 1112 "R_PPC_TPREL16_HA", /* name */ 1113 FALSE, /* partial_inplace */ 1114 0, /* src_mask */ 1115 0xffff, /* dst_mask */ 1116 FALSE), /* pcrel_offset */ 1117 1118 /* Allocates two contiguous entries in the GOT to hold a tls_index structure, 1119 with values (sym+add)@dtpmod and (sym+add)@dtprel, and computes the offset 1120 to the first entry. */ 1121 HOWTO (R_PPC_GOT_TLSGD16, 1122 0, /* rightshift */ 1123 1, /* size (0 = byte, 1 = short, 2 = long) */ 1124 16, /* bitsize */ 1125 FALSE, /* pc_relative */ 1126 0, /* bitpos */ 1127 complain_overflow_signed, /* complain_on_overflow */ 1128 ppc_elf_unhandled_reloc, /* special_function */ 1129 "R_PPC_GOT_TLSGD16", /* name */ 1130 FALSE, /* partial_inplace */ 1131 0, /* src_mask */ 1132 0xffff, /* dst_mask */ 1133 FALSE), /* pcrel_offset */ 1134 1135 /* Like GOT_TLSGD16, but no overflow. */ 1136 HOWTO (R_PPC_GOT_TLSGD16_LO, 1137 0, /* rightshift */ 1138 1, /* size (0 = byte, 1 = short, 2 = long) */ 1139 16, /* bitsize */ 1140 FALSE, /* pc_relative */ 1141 0, /* bitpos */ 1142 complain_overflow_dont, /* complain_on_overflow */ 1143 ppc_elf_unhandled_reloc, /* special_function */ 1144 "R_PPC_GOT_TLSGD16_LO", /* name */ 1145 FALSE, /* partial_inplace */ 1146 0, /* src_mask */ 1147 0xffff, /* dst_mask */ 1148 FALSE), /* pcrel_offset */ 1149 1150 /* Like GOT_TLSGD16_LO, but next higher group of 16 bits. */ 1151 HOWTO (R_PPC_GOT_TLSGD16_HI, 1152 16, /* rightshift */ 1153 1, /* size (0 = byte, 1 = short, 2 = long) */ 1154 16, /* bitsize */ 1155 FALSE, /* pc_relative */ 1156 0, /* bitpos */ 1157 complain_overflow_dont, /* complain_on_overflow */ 1158 ppc_elf_unhandled_reloc, /* special_function */ 1159 "R_PPC_GOT_TLSGD16_HI", /* name */ 1160 FALSE, /* partial_inplace */ 1161 0, /* src_mask */ 1162 0xffff, /* dst_mask */ 1163 FALSE), /* pcrel_offset */ 1164 1165 /* Like GOT_TLSGD16_HI, but adjust for low 16 bits. */ 1166 HOWTO (R_PPC_GOT_TLSGD16_HA, 1167 16, /* rightshift */ 1168 1, /* size (0 = byte, 1 = short, 2 = long) */ 1169 16, /* bitsize */ 1170 FALSE, /* pc_relative */ 1171 0, /* bitpos */ 1172 complain_overflow_dont, /* complain_on_overflow */ 1173 ppc_elf_unhandled_reloc, /* special_function */ 1174 "R_PPC_GOT_TLSGD16_HA", /* name */ 1175 FALSE, /* partial_inplace */ 1176 0, /* src_mask */ 1177 0xffff, /* dst_mask */ 1178 FALSE), /* pcrel_offset */ 1179 1180 /* Allocates two contiguous entries in the GOT to hold a tls_index structure, 1181 with values (sym+add)@dtpmod and zero, and computes the offset to the 1182 first entry. */ 1183 HOWTO (R_PPC_GOT_TLSLD16, 1184 0, /* rightshift */ 1185 1, /* size (0 = byte, 1 = short, 2 = long) */ 1186 16, /* bitsize */ 1187 FALSE, /* pc_relative */ 1188 0, /* bitpos */ 1189 complain_overflow_signed, /* complain_on_overflow */ 1190 ppc_elf_unhandled_reloc, /* special_function */ 1191 "R_PPC_GOT_TLSLD16", /* name */ 1192 FALSE, /* partial_inplace */ 1193 0, /* src_mask */ 1194 0xffff, /* dst_mask */ 1195 FALSE), /* pcrel_offset */ 1196 1197 /* Like GOT_TLSLD16, but no overflow. */ 1198 HOWTO (R_PPC_GOT_TLSLD16_LO, 1199 0, /* rightshift */ 1200 1, /* size (0 = byte, 1 = short, 2 = long) */ 1201 16, /* bitsize */ 1202 FALSE, /* pc_relative */ 1203 0, /* bitpos */ 1204 complain_overflow_dont, /* complain_on_overflow */ 1205 ppc_elf_unhandled_reloc, /* special_function */ 1206 "R_PPC_GOT_TLSLD16_LO", /* name */ 1207 FALSE, /* partial_inplace */ 1208 0, /* src_mask */ 1209 0xffff, /* dst_mask */ 1210 FALSE), /* pcrel_offset */ 1211 1212 /* Like GOT_TLSLD16_LO, but next higher group of 16 bits. */ 1213 HOWTO (R_PPC_GOT_TLSLD16_HI, 1214 16, /* rightshift */ 1215 1, /* size (0 = byte, 1 = short, 2 = long) */ 1216 16, /* bitsize */ 1217 FALSE, /* pc_relative */ 1218 0, /* bitpos */ 1219 complain_overflow_dont, /* complain_on_overflow */ 1220 ppc_elf_unhandled_reloc, /* special_function */ 1221 "R_PPC_GOT_TLSLD16_HI", /* name */ 1222 FALSE, /* partial_inplace */ 1223 0, /* src_mask */ 1224 0xffff, /* dst_mask */ 1225 FALSE), /* pcrel_offset */ 1226 1227 /* Like GOT_TLSLD16_HI, but adjust for low 16 bits. */ 1228 HOWTO (R_PPC_GOT_TLSLD16_HA, 1229 16, /* rightshift */ 1230 1, /* size (0 = byte, 1 = short, 2 = long) */ 1231 16, /* bitsize */ 1232 FALSE, /* pc_relative */ 1233 0, /* bitpos */ 1234 complain_overflow_dont, /* complain_on_overflow */ 1235 ppc_elf_unhandled_reloc, /* special_function */ 1236 "R_PPC_GOT_TLSLD16_HA", /* name */ 1237 FALSE, /* partial_inplace */ 1238 0, /* src_mask */ 1239 0xffff, /* dst_mask */ 1240 FALSE), /* pcrel_offset */ 1241 1242 /* Allocates an entry in the GOT with value (sym+add)@dtprel, and computes 1243 the offset to the entry. */ 1244 HOWTO (R_PPC_GOT_DTPREL16, 1245 0, /* rightshift */ 1246 1, /* size (0 = byte, 1 = short, 2 = long) */ 1247 16, /* bitsize */ 1248 FALSE, /* pc_relative */ 1249 0, /* bitpos */ 1250 complain_overflow_signed, /* complain_on_overflow */ 1251 ppc_elf_unhandled_reloc, /* special_function */ 1252 "R_PPC_GOT_DTPREL16", /* name */ 1253 FALSE, /* partial_inplace */ 1254 0, /* src_mask */ 1255 0xffff, /* dst_mask */ 1256 FALSE), /* pcrel_offset */ 1257 1258 /* Like GOT_DTPREL16, but no overflow. */ 1259 HOWTO (R_PPC_GOT_DTPREL16_LO, 1260 0, /* rightshift */ 1261 1, /* size (0 = byte, 1 = short, 2 = long) */ 1262 16, /* bitsize */ 1263 FALSE, /* pc_relative */ 1264 0, /* bitpos */ 1265 complain_overflow_dont, /* complain_on_overflow */ 1266 ppc_elf_unhandled_reloc, /* special_function */ 1267 "R_PPC_GOT_DTPREL16_LO", /* name */ 1268 FALSE, /* partial_inplace */ 1269 0, /* src_mask */ 1270 0xffff, /* dst_mask */ 1271 FALSE), /* pcrel_offset */ 1272 1273 /* Like GOT_DTPREL16_LO, but next higher group of 16 bits. */ 1274 HOWTO (R_PPC_GOT_DTPREL16_HI, 1275 16, /* rightshift */ 1276 1, /* size (0 = byte, 1 = short, 2 = long) */ 1277 16, /* bitsize */ 1278 FALSE, /* pc_relative */ 1279 0, /* bitpos */ 1280 complain_overflow_dont, /* complain_on_overflow */ 1281 ppc_elf_unhandled_reloc, /* special_function */ 1282 "R_PPC_GOT_DTPREL16_HI", /* name */ 1283 FALSE, /* partial_inplace */ 1284 0, /* src_mask */ 1285 0xffff, /* dst_mask */ 1286 FALSE), /* pcrel_offset */ 1287 1288 /* Like GOT_DTPREL16_HI, but adjust for low 16 bits. */ 1289 HOWTO (R_PPC_GOT_DTPREL16_HA, 1290 16, /* rightshift */ 1291 1, /* size (0 = byte, 1 = short, 2 = long) */ 1292 16, /* bitsize */ 1293 FALSE, /* pc_relative */ 1294 0, /* bitpos */ 1295 complain_overflow_dont, /* complain_on_overflow */ 1296 ppc_elf_unhandled_reloc, /* special_function */ 1297 "R_PPC_GOT_DTPREL16_HA", /* name */ 1298 FALSE, /* partial_inplace */ 1299 0, /* src_mask */ 1300 0xffff, /* dst_mask */ 1301 FALSE), /* pcrel_offset */ 1302 1303 /* Allocates an entry in the GOT with value (sym+add)@tprel, and computes the 1304 offset to the entry. */ 1305 HOWTO (R_PPC_GOT_TPREL16, 1306 0, /* rightshift */ 1307 1, /* size (0 = byte, 1 = short, 2 = long) */ 1308 16, /* bitsize */ 1309 FALSE, /* pc_relative */ 1310 0, /* bitpos */ 1311 complain_overflow_signed, /* complain_on_overflow */ 1312 ppc_elf_unhandled_reloc, /* special_function */ 1313 "R_PPC_GOT_TPREL16", /* name */ 1314 FALSE, /* partial_inplace */ 1315 0, /* src_mask */ 1316 0xffff, /* dst_mask */ 1317 FALSE), /* pcrel_offset */ 1318 1319 /* Like GOT_TPREL16, but no overflow. */ 1320 HOWTO (R_PPC_GOT_TPREL16_LO, 1321 0, /* rightshift */ 1322 1, /* size (0 = byte, 1 = short, 2 = long) */ 1323 16, /* bitsize */ 1324 FALSE, /* pc_relative */ 1325 0, /* bitpos */ 1326 complain_overflow_dont, /* complain_on_overflow */ 1327 ppc_elf_unhandled_reloc, /* special_function */ 1328 "R_PPC_GOT_TPREL16_LO", /* name */ 1329 FALSE, /* partial_inplace */ 1330 0, /* src_mask */ 1331 0xffff, /* dst_mask */ 1332 FALSE), /* pcrel_offset */ 1333 1334 /* Like GOT_TPREL16_LO, but next higher group of 16 bits. */ 1335 HOWTO (R_PPC_GOT_TPREL16_HI, 1336 16, /* rightshift */ 1337 1, /* size (0 = byte, 1 = short, 2 = long) */ 1338 16, /* bitsize */ 1339 FALSE, /* pc_relative */ 1340 0, /* bitpos */ 1341 complain_overflow_dont, /* complain_on_overflow */ 1342 ppc_elf_unhandled_reloc, /* special_function */ 1343 "R_PPC_GOT_TPREL16_HI", /* name */ 1344 FALSE, /* partial_inplace */ 1345 0, /* src_mask */ 1346 0xffff, /* dst_mask */ 1347 FALSE), /* pcrel_offset */ 1348 1349 /* Like GOT_TPREL16_HI, but adjust for low 16 bits. */ 1350 HOWTO (R_PPC_GOT_TPREL16_HA, 1351 16, /* rightshift */ 1352 1, /* size (0 = byte, 1 = short, 2 = long) */ 1353 16, /* bitsize */ 1354 FALSE, /* pc_relative */ 1355 0, /* bitpos */ 1356 complain_overflow_dont, /* complain_on_overflow */ 1357 ppc_elf_unhandled_reloc, /* special_function */ 1358 "R_PPC_GOT_TPREL16_HA", /* name */ 1359 FALSE, /* partial_inplace */ 1360 0, /* src_mask */ 1361 0xffff, /* dst_mask */ 1362 FALSE), /* pcrel_offset */ 1363 1364 /* The remaining relocs are from the Embedded ELF ABI, and are not 1365 in the SVR4 ELF ABI. */ 1366 1367 /* 32 bit value resulting from the addend minus the symbol. */ 1368 HOWTO (R_PPC_EMB_NADDR32, /* type */ 1369 0, /* rightshift */ 1370 2, /* size (0 = byte, 1 = short, 2 = long) */ 1371 32, /* bitsize */ 1372 FALSE, /* pc_relative */ 1373 0, /* bitpos */ 1374 complain_overflow_bitfield, /* complain_on_overflow */ 1375 bfd_elf_generic_reloc, /* special_function */ 1376 "R_PPC_EMB_NADDR32", /* name */ 1377 FALSE, /* partial_inplace */ 1378 0, /* src_mask */ 1379 0xffffffff, /* dst_mask */ 1380 FALSE), /* pcrel_offset */ 1381 1382 /* 16 bit value resulting from the addend minus the symbol. */ 1383 HOWTO (R_PPC_EMB_NADDR16, /* type */ 1384 0, /* rightshift */ 1385 1, /* size (0 = byte, 1 = short, 2 = long) */ 1386 16, /* bitsize */ 1387 FALSE, /* pc_relative */ 1388 0, /* bitpos */ 1389 complain_overflow_bitfield, /* complain_on_overflow */ 1390 bfd_elf_generic_reloc, /* special_function */ 1391 "R_PPC_EMB_NADDR16", /* name */ 1392 FALSE, /* partial_inplace */ 1393 0, /* src_mask */ 1394 0xffff, /* dst_mask */ 1395 FALSE), /* pcrel_offset */ 1396 1397 /* 16 bit value resulting from the addend minus the symbol. */ 1398 HOWTO (R_PPC_EMB_NADDR16_LO, /* type */ 1399 0, /* rightshift */ 1400 1, /* size (0 = byte, 1 = short, 2 = long) */ 1401 16, /* bitsize */ 1402 FALSE, /* pc_relative */ 1403 0, /* bitpos */ 1404 complain_overflow_dont,/* complain_on_overflow */ 1405 bfd_elf_generic_reloc, /* special_function */ 1406 "R_PPC_EMB_ADDR16_LO", /* name */ 1407 FALSE, /* partial_inplace */ 1408 0, /* src_mask */ 1409 0xffff, /* dst_mask */ 1410 FALSE), /* pcrel_offset */ 1411 1412 /* The high order 16 bits of the addend minus the symbol. */ 1413 HOWTO (R_PPC_EMB_NADDR16_HI, /* type */ 1414 16, /* rightshift */ 1415 1, /* size (0 = byte, 1 = short, 2 = long) */ 1416 16, /* bitsize */ 1417 FALSE, /* pc_relative */ 1418 0, /* bitpos */ 1419 complain_overflow_dont, /* complain_on_overflow */ 1420 bfd_elf_generic_reloc, /* special_function */ 1421 "R_PPC_EMB_NADDR16_HI", /* name */ 1422 FALSE, /* partial_inplace */ 1423 0, /* src_mask */ 1424 0xffff, /* dst_mask */ 1425 FALSE), /* pcrel_offset */ 1426 1427 /* The high order 16 bits of the result of the addend minus the address, 1428 plus 1 if the contents of the low 16 bits, treated as a signed number, 1429 is negative. */ 1430 HOWTO (R_PPC_EMB_NADDR16_HA, /* type */ 1431 16, /* rightshift */ 1432 1, /* size (0 = byte, 1 = short, 2 = long) */ 1433 16, /* bitsize */ 1434 FALSE, /* pc_relative */ 1435 0, /* bitpos */ 1436 complain_overflow_dont, /* complain_on_overflow */ 1437 ppc_elf_addr16_ha_reloc, /* special_function */ 1438 "R_PPC_EMB_NADDR16_HA", /* name */ 1439 FALSE, /* partial_inplace */ 1440 0, /* src_mask */ 1441 0xffff, /* dst_mask */ 1442 FALSE), /* pcrel_offset */ 1443 1444 /* 16 bit value resulting from allocating a 4 byte word to hold an 1445 address in the .sdata section, and returning the offset from 1446 _SDA_BASE_ for that relocation. */ 1447 HOWTO (R_PPC_EMB_SDAI16, /* type */ 1448 0, /* rightshift */ 1449 1, /* size (0 = byte, 1 = short, 2 = long) */ 1450 16, /* bitsize */ 1451 FALSE, /* pc_relative */ 1452 0, /* bitpos */ 1453 complain_overflow_bitfield, /* complain_on_overflow */ 1454 bfd_elf_generic_reloc, /* special_function */ 1455 "R_PPC_EMB_SDAI16", /* name */ 1456 FALSE, /* partial_inplace */ 1457 0, /* src_mask */ 1458 0xffff, /* dst_mask */ 1459 FALSE), /* pcrel_offset */ 1460 1461 /* 16 bit value resulting from allocating a 4 byte word to hold an 1462 address in the .sdata2 section, and returning the offset from 1463 _SDA2_BASE_ for that relocation. */ 1464 HOWTO (R_PPC_EMB_SDA2I16, /* type */ 1465 0, /* rightshift */ 1466 1, /* size (0 = byte, 1 = short, 2 = long) */ 1467 16, /* bitsize */ 1468 FALSE, /* pc_relative */ 1469 0, /* bitpos */ 1470 complain_overflow_bitfield, /* complain_on_overflow */ 1471 bfd_elf_generic_reloc, /* special_function */ 1472 "R_PPC_EMB_SDA2I16", /* name */ 1473 FALSE, /* partial_inplace */ 1474 0, /* src_mask */ 1475 0xffff, /* dst_mask */ 1476 FALSE), /* pcrel_offset */ 1477 1478 /* A sign-extended 16 bit value relative to _SDA2_BASE_, for use with 1479 small data items. */ 1480 HOWTO (R_PPC_EMB_SDA2REL, /* type */ 1481 0, /* rightshift */ 1482 1, /* size (0 = byte, 1 = short, 2 = long) */ 1483 16, /* bitsize */ 1484 FALSE, /* pc_relative */ 1485 0, /* bitpos */ 1486 complain_overflow_signed, /* complain_on_overflow */ 1487 bfd_elf_generic_reloc, /* special_function */ 1488 "R_PPC_EMB_SDA2REL", /* name */ 1489 FALSE, /* partial_inplace */ 1490 0, /* src_mask */ 1491 0xffff, /* dst_mask */ 1492 FALSE), /* pcrel_offset */ 1493 1494 /* Relocate against either _SDA_BASE_ or _SDA2_BASE_, filling in the 16 bit 1495 signed offset from the appropriate base, and filling in the register 1496 field with the appropriate register (0, 2, or 13). */ 1497 HOWTO (R_PPC_EMB_SDA21, /* type */ 1498 0, /* rightshift */ 1499 2, /* size (0 = byte, 1 = short, 2 = long) */ 1500 16, /* bitsize */ 1501 FALSE, /* pc_relative */ 1502 0, /* bitpos */ 1503 complain_overflow_signed, /* complain_on_overflow */ 1504 bfd_elf_generic_reloc, /* special_function */ 1505 "R_PPC_EMB_SDA21", /* name */ 1506 FALSE, /* partial_inplace */ 1507 0, /* src_mask */ 1508 0xffff, /* dst_mask */ 1509 FALSE), /* pcrel_offset */ 1510 1511 /* Relocation not handled: R_PPC_EMB_MRKREF */ 1512 /* Relocation not handled: R_PPC_EMB_RELSEC16 */ 1513 /* Relocation not handled: R_PPC_EMB_RELST_LO */ 1514 /* Relocation not handled: R_PPC_EMB_RELST_HI */ 1515 /* Relocation not handled: R_PPC_EMB_RELST_HA */ 1516 /* Relocation not handled: R_PPC_EMB_BIT_FLD */ 1517 1518 /* PC relative relocation against either _SDA_BASE_ or _SDA2_BASE_, filling 1519 in the 16 bit signed offset from the appropriate base, and filling in the 1520 register field with the appropriate register (0, 2, or 13). */ 1521 HOWTO (R_PPC_EMB_RELSDA, /* type */ 1522 0, /* rightshift */ 1523 1, /* size (0 = byte, 1 = short, 2 = long) */ 1524 16, /* bitsize */ 1525 TRUE, /* pc_relative */ 1526 0, /* bitpos */ 1527 complain_overflow_signed, /* complain_on_overflow */ 1528 bfd_elf_generic_reloc, /* special_function */ 1529 "R_PPC_EMB_RELSDA", /* name */ 1530 FALSE, /* partial_inplace */ 1531 0, /* src_mask */ 1532 0xffff, /* dst_mask */ 1533 FALSE), /* pcrel_offset */ 1534 1535 /* GNU extension to record C++ vtable hierarchy. */ 1536 HOWTO (R_PPC_GNU_VTINHERIT, /* type */ 1537 0, /* rightshift */ 1538 0, /* size (0 = byte, 1 = short, 2 = long) */ 1539 0, /* bitsize */ 1540 FALSE, /* pc_relative */ 1541 0, /* bitpos */ 1542 complain_overflow_dont, /* complain_on_overflow */ 1543 NULL, /* special_function */ 1544 "R_PPC_GNU_VTINHERIT", /* name */ 1545 FALSE, /* partial_inplace */ 1546 0, /* src_mask */ 1547 0, /* dst_mask */ 1548 FALSE), /* pcrel_offset */ 1549 1550 /* GNU extension to record C++ vtable member usage. */ 1551 HOWTO (R_PPC_GNU_VTENTRY, /* type */ 1552 0, /* rightshift */ 1553 0, /* size (0 = byte, 1 = short, 2 = long) */ 1554 0, /* bitsize */ 1555 FALSE, /* pc_relative */ 1556 0, /* bitpos */ 1557 complain_overflow_dont, /* complain_on_overflow */ 1558 NULL, /* special_function */ 1559 "R_PPC_GNU_VTENTRY", /* name */ 1560 FALSE, /* partial_inplace */ 1561 0, /* src_mask */ 1562 0, /* dst_mask */ 1563 FALSE), /* pcrel_offset */ 1564 1565 /* Phony reloc to handle AIX style TOC entries. */ 1566 HOWTO (R_PPC_TOC16, /* type */ 1567 0, /* rightshift */ 1568 1, /* size (0 = byte, 1 = short, 2 = long) */ 1569 16, /* bitsize */ 1570 FALSE, /* pc_relative */ 1571 0, /* bitpos */ 1572 complain_overflow_signed, /* complain_on_overflow */ 1573 bfd_elf_generic_reloc, /* special_function */ 1574 "R_PPC_TOC16", /* name */ 1575 FALSE, /* partial_inplace */ 1576 0, /* src_mask */ 1577 0xffff, /* dst_mask */ 1578 FALSE), /* pcrel_offset */ 1579 }; 1580 1581 /* Initialize the ppc_elf_howto_table, so that linear accesses can be done. */ 1582 1583 static void 1584 ppc_elf_howto_init (void) 1585 { 1586 unsigned int i, type; 1587 1588 for (i = 0; 1589 i < sizeof (ppc_elf_howto_raw) / sizeof (ppc_elf_howto_raw[0]); 1590 i++) 1591 { 1592 type = ppc_elf_howto_raw[i].type; 1593 if (type >= (sizeof (ppc_elf_howto_table) 1594 / sizeof (ppc_elf_howto_table[0]))) 1595 abort (); 1596 ppc_elf_howto_table[type] = &ppc_elf_howto_raw[i]; 1597 } 1598 } 1599 1600 #define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0])) 1601 1602 static const int shared_stub_entry[] = 1603 { 1604 0x7c0802a6, /* mflr 0 */ 1605 0x429f0005, /* bcl 20, 31, .Lxxx */ 1606 0x7d6802a6, /* mflr 11 */ 1607 0x3d6b0000, /* addis 11, 11, (xxx-.Lxxx)@ha */ 1608 0x396b0018, /* addi 11, 11, (xxx-.Lxxx)@l */ 1609 0x7c0803a6, /* mtlr 0 */ 1610 0x7d6903a6, /* mtctr 11 */ 1611 0x4e800420, /* bctr */ 1612 }; 1613 1614 static const int stub_entry[] = 1615 { 1616 0x3d600000, /* lis 11,xxx@ha */ 1617 0x396b0000, /* addi 11,11,xxx@l */ 1618 0x7d6903a6, /* mtctr 11 */ 1619 0x4e800420, /* bctr */ 1620 }; 1621 1622 1623 static bfd_boolean 1624 ppc_elf_relax_section (bfd *abfd, 1625 asection *isec, 1626 struct bfd_link_info *link_info, 1627 bfd_boolean *again) 1628 { 1629 struct one_fixup 1630 { 1631 struct one_fixup *next; 1632 asection *tsec; 1633 bfd_vma toff; 1634 bfd_vma trampoff; 1635 }; 1636 1637 Elf_Internal_Shdr *symtab_hdr; 1638 bfd_byte *contents = NULL; 1639 Elf_Internal_Sym *isymbuf = NULL; 1640 Elf_Internal_Rela *internal_relocs = NULL; 1641 Elf_Internal_Rela *irel, *irelend; 1642 struct one_fixup *fixups = NULL; 1643 bfd_boolean changed; 1644 struct ppc_elf_link_hash_table *ppc_info; 1645 bfd_size_type trampoff; 1646 1647 *again = FALSE; 1648 1649 /* Nothing to do if there are no relocations. */ 1650 if ((isec->flags & SEC_RELOC) == 0 || isec->reloc_count == 0) 1651 return TRUE; 1652 1653 /* If needed, initialize this section's cooked size. */ 1654 if (isec->_cooked_size == 0) 1655 isec->_cooked_size = isec->_raw_size; 1656 1657 trampoff = (isec->_cooked_size + 3) & (bfd_vma) -4; 1658 /* Space for a branch around any trampolines. */ 1659 trampoff += 4; 1660 1661 symtab_hdr = &elf_tdata (abfd)->symtab_hdr; 1662 1663 /* Get a copy of the native relocations. */ 1664 internal_relocs = _bfd_elf_link_read_relocs (abfd, isec, NULL, NULL, 1665 link_info->keep_memory); 1666 if (internal_relocs == NULL) 1667 goto error_return; 1668 1669 ppc_info = ppc_elf_hash_table (link_info); 1670 irelend = internal_relocs + isec->reloc_count; 1671 1672 /* Get the section contents. */ 1673 /* Get cached copy if it exists. */ 1674 if (elf_section_data (isec)->this_hdr.contents != NULL) 1675 contents = elf_section_data (isec)->this_hdr.contents; 1676 else 1677 { 1678 /* Go get them off disk. */ 1679 contents = bfd_malloc (isec->_raw_size); 1680 if (contents == NULL) 1681 goto error_return; 1682 1683 if (!bfd_get_section_contents (abfd, isec, contents, 0, isec->_raw_size)) 1684 goto error_return; 1685 } 1686 1687 for (irel = internal_relocs; irel < irelend; irel++) 1688 { 1689 unsigned long r_type = ELF32_R_TYPE (irel->r_info); 1690 bfd_vma symaddr, reladdr, toff, roff; 1691 asection *tsec; 1692 struct one_fixup *f; 1693 size_t insn_offset = 0; 1694 bfd_vma max_branch_offset, val; 1695 bfd_byte *hit_addr; 1696 unsigned long t0; 1697 1698 switch (r_type) 1699 { 1700 case R_PPC_REL24: 1701 case R_PPC_LOCAL24PC: 1702 case R_PPC_PLTREL24: 1703 max_branch_offset = 1 << 25; 1704 break; 1705 1706 case R_PPC_REL14: 1707 case R_PPC_REL14_BRTAKEN: 1708 case R_PPC_REL14_BRNTAKEN: 1709 max_branch_offset = 1 << 15; 1710 break; 1711 1712 default: 1713 continue; 1714 } 1715 1716 /* Get the value of the symbol referred to by the reloc. */ 1717 if (ELF32_R_SYM (irel->r_info) < symtab_hdr->sh_info) 1718 { 1719 /* A local symbol. */ 1720 Elf_Internal_Sym *isym; 1721 1722 /* Read this BFD's local symbols. */ 1723 if (isymbuf == NULL) 1724 { 1725 isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents; 1726 if (isymbuf == NULL) 1727 isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr, 1728 symtab_hdr->sh_info, 0, 1729 NULL, NULL, NULL); 1730 if (isymbuf == 0) 1731 goto error_return; 1732 } 1733 isym = isymbuf + ELF32_R_SYM (irel->r_info); 1734 if (isym->st_shndx == SHN_UNDEF) 1735 continue; /* We can't do anything with undefined symbols. */ 1736 else if (isym->st_shndx == SHN_ABS) 1737 tsec = bfd_abs_section_ptr; 1738 else if (isym->st_shndx == SHN_COMMON) 1739 tsec = bfd_com_section_ptr; 1740 else 1741 tsec = bfd_section_from_elf_index (abfd, isym->st_shndx); 1742 1743 toff = isym->st_value; 1744 } 1745 else 1746 { 1747 /* Global symbol handling. */ 1748 unsigned long indx; 1749 struct elf_link_hash_entry *h; 1750 1751 indx = ELF32_R_SYM (irel->r_info) - symtab_hdr->sh_info; 1752 h = elf_sym_hashes (abfd)[indx]; 1753 1754 while (h->root.type == bfd_link_hash_indirect 1755 || h->root.type == bfd_link_hash_warning) 1756 h = (struct elf_link_hash_entry *) h->root.u.i.link; 1757 1758 if (r_type == R_PPC_PLTREL24 1759 && ppc_info->plt != NULL 1760 && h->plt.offset != (bfd_vma) -1) 1761 { 1762 tsec = ppc_info->plt; 1763 toff = h->plt.offset; 1764 } 1765 else if (h->root.type == bfd_link_hash_defined 1766 || h->root.type == bfd_link_hash_defweak) 1767 { 1768 tsec = h->root.u.def.section; 1769 toff = h->root.u.def.value; 1770 } 1771 else 1772 continue; 1773 } 1774 1775 /* If the branch and target are in the same section, you have 1776 no hope of adding stubs. We'll error out later should the 1777 branch overflow. */ 1778 if (tsec == isec) 1779 continue; 1780 1781 toff += irel->r_addend; 1782 if (tsec->sec_info_type == ELF_INFO_TYPE_MERGE) 1783 toff = _bfd_merged_section_offset (abfd, &tsec, 1784 elf_section_data (tsec)->sec_info, 1785 toff, 0); 1786 1787 symaddr = tsec->output_section->vma + tsec->output_offset + toff; 1788 1789 roff = irel->r_offset; 1790 reladdr = isec->output_section->vma + isec->output_offset + roff; 1791 1792 /* If the branch is in range, no need to do anything. */ 1793 if (symaddr - reladdr + max_branch_offset < 2 * max_branch_offset) 1794 continue; 1795 1796 /* Look for an existing fixup to this address. */ 1797 for (f = fixups; f ; f = f->next) 1798 if (f->tsec == tsec && f->toff == toff) 1799 break; 1800 1801 if (f == NULL) 1802 { 1803 size_t size; 1804 unsigned long stub_rtype; 1805 1806 val = trampoff - roff; 1807 if (val >= max_branch_offset) 1808 /* Oh dear, we can't reach a trampoline. Don't try to add 1809 one. We'll report an error later. */ 1810 continue; 1811 1812 if (link_info->shared) 1813 { 1814 size = 4 * ARRAY_SIZE (shared_stub_entry); 1815 insn_offset = 12; 1816 stub_rtype = R_PPC_RELAX32PC; 1817 } 1818 else 1819 { 1820 size = 4 * ARRAY_SIZE (stub_entry); 1821 insn_offset = 0; 1822 stub_rtype = R_PPC_RELAX32; 1823 } 1824 1825 if (R_PPC_RELAX32_PLT - R_PPC_RELAX32 1826 != R_PPC_RELAX32PC_PLT - R_PPC_RELAX32PC) 1827 abort (); 1828 if (tsec == ppc_info->plt) 1829 stub_rtype += R_PPC_RELAX32_PLT - R_PPC_RELAX32; 1830 1831 /* Hijack the old relocation. Since we need two 1832 relocations for this use a "composite" reloc. */ 1833 irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info), 1834 stub_rtype); 1835 irel->r_offset = trampoff + insn_offset; 1836 1837 /* Record the fixup so we don't do it again this section. */ 1838 f = bfd_malloc (sizeof (*f)); 1839 f->next = fixups; 1840 f->tsec = tsec; 1841 f->toff = toff; 1842 f->trampoff = trampoff; 1843 fixups = f; 1844 1845 trampoff += size; 1846 } 1847 else 1848 { 1849 val = f->trampoff - roff; 1850 if (val >= max_branch_offset) 1851 continue; 1852 1853 /* Nop out the reloc, since we're finalizing things here. */ 1854 irel->r_info = ELF32_R_INFO (0, R_PPC_NONE); 1855 } 1856 1857 /* Fix up the existing branch to hit the trampoline. */ 1858 hit_addr = contents + roff; 1859 switch (r_type) 1860 { 1861 case R_PPC_REL24: 1862 case R_PPC_LOCAL24PC: 1863 case R_PPC_PLTREL24: 1864 t0 = bfd_get_32 (abfd, hit_addr); 1865 t0 &= ~0x3fffffc; 1866 t0 |= val & 0x3fffffc; 1867 bfd_put_32 (abfd, t0, hit_addr); 1868 break; 1869 1870 case R_PPC_REL14: 1871 case R_PPC_REL14_BRTAKEN: 1872 case R_PPC_REL14_BRNTAKEN: 1873 t0 = bfd_get_32 (abfd, hit_addr); 1874 t0 &= ~0xfffc; 1875 t0 |= val & 0xfffc; 1876 bfd_put_32 (abfd, t0, hit_addr); 1877 break; 1878 } 1879 } 1880 1881 /* Write out the trampolines. */ 1882 changed = fixups != NULL; 1883 if (fixups != NULL) 1884 { 1885 const int *stub; 1886 bfd_byte *dest; 1887 bfd_vma val; 1888 int i, size; 1889 1890 do 1891 { 1892 struct one_fixup *f = fixups; 1893 fixups = fixups->next; 1894 free (f); 1895 } 1896 while (fixups); 1897 1898 contents = bfd_realloc (contents, trampoff); 1899 if (contents == NULL) 1900 goto error_return; 1901 1902 isec->_cooked_size = (isec->_cooked_size + 3) & (bfd_vma) -4; 1903 /* Branch around the trampolines. */ 1904 val = trampoff - isec->_cooked_size + 0x48000000; 1905 dest = contents + isec->_cooked_size; 1906 isec->_cooked_size = trampoff; 1907 bfd_put_32 (abfd, val, dest); 1908 dest += 4; 1909 1910 if (link_info->shared) 1911 { 1912 stub = shared_stub_entry; 1913 size = ARRAY_SIZE (shared_stub_entry); 1914 } 1915 else 1916 { 1917 stub = stub_entry; 1918 size = ARRAY_SIZE (stub_entry); 1919 } 1920 1921 i = 0; 1922 while (dest < contents + trampoff) 1923 { 1924 bfd_put_32 (abfd, stub[i], dest); 1925 i++; 1926 if (i == size) 1927 i = 0; 1928 dest += 4; 1929 } 1930 BFD_ASSERT (i == 0); 1931 } 1932 1933 if (isymbuf != NULL 1934 && symtab_hdr->contents != (unsigned char *) isymbuf) 1935 { 1936 if (! link_info->keep_memory) 1937 free (isymbuf); 1938 else 1939 { 1940 /* Cache the symbols for elf_link_input_bfd. */ 1941 symtab_hdr->contents = (unsigned char *) isymbuf; 1942 } 1943 } 1944 1945 if (contents != NULL 1946 && elf_section_data (isec)->this_hdr.contents != contents) 1947 { 1948 if (!changed && !link_info->keep_memory) 1949 free (contents); 1950 else 1951 { 1952 /* Cache the section contents for elf_link_input_bfd. */ 1953 elf_section_data (isec)->this_hdr.contents = contents; 1954 } 1955 } 1956 1957 if (elf_section_data (isec)->relocs != internal_relocs) 1958 { 1959 if (!changed) 1960 free (internal_relocs); 1961 else 1962 elf_section_data (isec)->relocs = internal_relocs; 1963 } 1964 1965 *again = changed; 1966 return TRUE; 1967 1968 error_return: 1969 if (isymbuf != NULL && (unsigned char *) isymbuf != symtab_hdr->contents) 1970 free (isymbuf); 1971 if (contents != NULL 1972 && elf_section_data (isec)->this_hdr.contents != contents) 1973 free (contents); 1974 if (internal_relocs != NULL 1975 && elf_section_data (isec)->relocs != internal_relocs) 1976 free (internal_relocs); 1977 return FALSE; 1978 } 1979 1980 static reloc_howto_type * 1981 ppc_elf_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED, 1982 bfd_reloc_code_real_type code) 1983 { 1984 enum elf_ppc_reloc_type r; 1985 1986 /* Initialize howto table if not already done. */ 1987 if (!ppc_elf_howto_table[R_PPC_ADDR32]) 1988 ppc_elf_howto_init (); 1989 1990 switch (code) 1991 { 1992 default: 1993 return NULL; 1994 1995 case BFD_RELOC_NONE: r = R_PPC_NONE; break; 1996 case BFD_RELOC_32: r = R_PPC_ADDR32; break; 1997 case BFD_RELOC_PPC_BA26: r = R_PPC_ADDR24; break; 1998 case BFD_RELOC_16: r = R_PPC_ADDR16; break; 1999 case BFD_RELOC_LO16: r = R_PPC_ADDR16_LO; break; 2000 case BFD_RELOC_HI16: r = R_PPC_ADDR16_HI; break; 2001 case BFD_RELOC_HI16_S: r = R_PPC_ADDR16_HA; break; 2002 case BFD_RELOC_PPC_BA16: r = R_PPC_ADDR14; break; 2003 case BFD_RELOC_PPC_BA16_BRTAKEN: r = R_PPC_ADDR14_BRTAKEN; break; 2004 case BFD_RELOC_PPC_BA16_BRNTAKEN: r = R_PPC_ADDR14_BRNTAKEN; break; 2005 case BFD_RELOC_PPC_B26: r = R_PPC_REL24; break; 2006 case BFD_RELOC_PPC_B16: r = R_PPC_REL14; break; 2007 case BFD_RELOC_PPC_B16_BRTAKEN: r = R_PPC_REL14_BRTAKEN; break; 2008 case BFD_RELOC_PPC_B16_BRNTAKEN: r = R_PPC_REL14_BRNTAKEN; break; 2009 case BFD_RELOC_16_GOTOFF: r = R_PPC_GOT16; break; 2010 case BFD_RELOC_LO16_GOTOFF: r = R_PPC_GOT16_LO; break; 2011 case BFD_RELOC_HI16_GOTOFF: r = R_PPC_GOT16_HI; break; 2012 case BFD_RELOC_HI16_S_GOTOFF: r = R_PPC_GOT16_HA; break; 2013 case BFD_RELOC_24_PLT_PCREL: r = R_PPC_PLTREL24; break; 2014 case BFD_RELOC_PPC_COPY: r = R_PPC_COPY; break; 2015 case BFD_RELOC_PPC_GLOB_DAT: r = R_PPC_GLOB_DAT; break; 2016 case BFD_RELOC_PPC_LOCAL24PC: r = R_PPC_LOCAL24PC; break; 2017 case BFD_RELOC_32_PCREL: r = R_PPC_REL32; break; 2018 case BFD_RELOC_32_PLTOFF: r = R_PPC_PLT32; break; 2019 case BFD_RELOC_32_PLT_PCREL: r = R_PPC_PLTREL32; break; 2020 case BFD_RELOC_LO16_PLTOFF: r = R_PPC_PLT16_LO; break; 2021 case BFD_RELOC_HI16_PLTOFF: r = R_PPC_PLT16_HI; break; 2022 case BFD_RELOC_HI16_S_PLTOFF: r = R_PPC_PLT16_HA; break; 2023 case BFD_RELOC_GPREL16: r = R_PPC_SDAREL16; break; 2024 case BFD_RELOC_16_BASEREL: r = R_PPC_SECTOFF; break; 2025 case BFD_RELOC_LO16_BASEREL: r = R_PPC_SECTOFF_LO; break; 2026 case BFD_RELOC_HI16_BASEREL: r = R_PPC_SECTOFF_HI; break; 2027 case BFD_RELOC_HI16_S_BASEREL: r = R_PPC_SECTOFF_HA; break; 2028 case BFD_RELOC_CTOR: r = R_PPC_ADDR32; break; 2029 case BFD_RELOC_PPC_TOC16: r = R_PPC_TOC16; break; 2030 case BFD_RELOC_PPC_TLS: r = R_PPC_TLS; break; 2031 case BFD_RELOC_PPC_DTPMOD: r = R_PPC_DTPMOD32; break; 2032 case BFD_RELOC_PPC_TPREL16: r = R_PPC_TPREL16; break; 2033 case BFD_RELOC_PPC_TPREL16_LO: r = R_PPC_TPREL16_LO; break; 2034 case BFD_RELOC_PPC_TPREL16_HI: r = R_PPC_TPREL16_HI; break; 2035 case BFD_RELOC_PPC_TPREL16_HA: r = R_PPC_TPREL16_HA; break; 2036 case BFD_RELOC_PPC_TPREL: r = R_PPC_TPREL32; break; 2037 case BFD_RELOC_PPC_DTPREL16: r = R_PPC_DTPREL16; break; 2038 case BFD_RELOC_PPC_DTPREL16_LO: r = R_PPC_DTPREL16_LO; break; 2039 case BFD_RELOC_PPC_DTPREL16_HI: r = R_PPC_DTPREL16_HI; break; 2040 case BFD_RELOC_PPC_DTPREL16_HA: r = R_PPC_DTPREL16_HA; break; 2041 case BFD_RELOC_PPC_DTPREL: r = R_PPC_DTPREL32; break; 2042 case BFD_RELOC_PPC_GOT_TLSGD16: r = R_PPC_GOT_TLSGD16; break; 2043 case BFD_RELOC_PPC_GOT_TLSGD16_LO: r = R_PPC_GOT_TLSGD16_LO; break; 2044 case BFD_RELOC_PPC_GOT_TLSGD16_HI: r = R_PPC_GOT_TLSGD16_HI; break; 2045 case BFD_RELOC_PPC_GOT_TLSGD16_HA: r = R_PPC_GOT_TLSGD16_HA; break; 2046 case BFD_RELOC_PPC_GOT_TLSLD16: r = R_PPC_GOT_TLSLD16; break; 2047 case BFD_RELOC_PPC_GOT_TLSLD16_LO: r = R_PPC_GOT_TLSLD16_LO; break; 2048 case BFD_RELOC_PPC_GOT_TLSLD16_HI: r = R_PPC_GOT_TLSLD16_HI; break; 2049 case BFD_RELOC_PPC_GOT_TLSLD16_HA: r = R_PPC_GOT_TLSLD16_HA; break; 2050 case BFD_RELOC_PPC_GOT_TPREL16: r = R_PPC_GOT_TPREL16; break; 2051 case BFD_RELOC_PPC_GOT_TPREL16_LO: r = R_PPC_GOT_TPREL16_LO; break; 2052 case BFD_RELOC_PPC_GOT_TPREL16_HI: r = R_PPC_GOT_TPREL16_HI; break; 2053 case BFD_RELOC_PPC_GOT_TPREL16_HA: r = R_PPC_GOT_TPREL16_HA; break; 2054 case BFD_RELOC_PPC_GOT_DTPREL16: r = R_PPC_GOT_DTPREL16; break; 2055 case BFD_RELOC_PPC_GOT_DTPREL16_LO: r = R_PPC_GOT_DTPREL16_LO; break; 2056 case BFD_RELOC_PPC_GOT_DTPREL16_HI: r = R_PPC_GOT_DTPREL16_HI; break; 2057 case BFD_RELOC_PPC_GOT_DTPREL16_HA: r = R_PPC_GOT_DTPREL16_HA; break; 2058 case BFD_RELOC_PPC_EMB_NADDR32: r = R_PPC_EMB_NADDR32; break; 2059 case BFD_RELOC_PPC_EMB_NADDR16: r = R_PPC_EMB_NADDR16; break; 2060 case BFD_RELOC_PPC_EMB_NADDR16_LO: r = R_PPC_EMB_NADDR16_LO; break; 2061 case BFD_RELOC_PPC_EMB_NADDR16_HI: r = R_PPC_EMB_NADDR16_HI; break; 2062 case BFD_RELOC_PPC_EMB_NADDR16_HA: r = R_PPC_EMB_NADDR16_HA; break; 2063 case BFD_RELOC_PPC_EMB_SDAI16: r = R_PPC_EMB_SDAI16; break; 2064 case BFD_RELOC_PPC_EMB_SDA2I16: r = R_PPC_EMB_SDA2I16; break; 2065 case BFD_RELOC_PPC_EMB_SDA2REL: r = R_PPC_EMB_SDA2REL; break; 2066 case BFD_RELOC_PPC_EMB_SDA21: r = R_PPC_EMB_SDA21; break; 2067 case BFD_RELOC_PPC_EMB_MRKREF: r = R_PPC_EMB_MRKREF; break; 2068 case BFD_RELOC_PPC_EMB_RELSEC16: r = R_PPC_EMB_RELSEC16; break; 2069 case BFD_RELOC_PPC_EMB_RELST_LO: r = R_PPC_EMB_RELST_LO; break; 2070 case BFD_RELOC_PPC_EMB_RELST_HI: r = R_PPC_EMB_RELST_HI; break; 2071 case BFD_RELOC_PPC_EMB_RELST_HA: r = R_PPC_EMB_RELST_HA; break; 2072 case BFD_RELOC_PPC_EMB_BIT_FLD: r = R_PPC_EMB_BIT_FLD; break; 2073 case BFD_RELOC_PPC_EMB_RELSDA: r = R_PPC_EMB_RELSDA; break; 2074 case BFD_RELOC_VTABLE_INHERIT: r = R_PPC_GNU_VTINHERIT; break; 2075 case BFD_RELOC_VTABLE_ENTRY: r = R_PPC_GNU_VTENTRY; break; 2076 } 2077 2078 return ppc_elf_howto_table[r]; 2079 }; 2080 2081 /* Set the howto pointer for a PowerPC ELF reloc. */ 2082 2083 static void 2084 ppc_elf_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, 2085 arelent *cache_ptr, 2086 Elf_Internal_Rela *dst) 2087 { 2088 /* Initialize howto table if not already done. */ 2089 if (!ppc_elf_howto_table[R_PPC_ADDR32]) 2090 ppc_elf_howto_init (); 2091 2092 BFD_ASSERT (ELF32_R_TYPE (dst->r_info) < (unsigned int) R_PPC_max); 2093 cache_ptr->howto = ppc_elf_howto_table[ELF32_R_TYPE (dst->r_info)]; 2094 } 2095 2096 /* Handle the R_PPC_ADDR16_HA reloc. */ 2097 2098 static bfd_reloc_status_type 2099 ppc_elf_addr16_ha_reloc (bfd *abfd ATTRIBUTE_UNUSED, 2100 arelent *reloc_entry, 2101 asymbol *symbol, 2102 void *data ATTRIBUTE_UNUSED, 2103 asection *input_section, 2104 bfd *output_bfd, 2105 char **error_message ATTRIBUTE_UNUSED) 2106 { 2107 bfd_vma relocation; 2108 2109 if (output_bfd != NULL) 2110 { 2111 reloc_entry->address += input_section->output_offset; 2112 return bfd_reloc_ok; 2113 } 2114 2115 if (reloc_entry->address > input_section->_cooked_size) 2116 return bfd_reloc_outofrange; 2117 2118 if (bfd_is_com_section (symbol->section)) 2119 relocation = 0; 2120 else 2121 relocation = symbol->value; 2122 2123 relocation += symbol->section->output_section->vma; 2124 relocation += symbol->section->output_offset; 2125 relocation += reloc_entry->addend; 2126 2127 reloc_entry->addend += (relocation & 0x8000) << 1; 2128 2129 return bfd_reloc_continue; 2130 } 2131 2132 static bfd_reloc_status_type 2133 ppc_elf_unhandled_reloc (bfd *abfd, 2134 arelent *reloc_entry, 2135 asymbol *symbol, 2136 void *data, 2137 asection *input_section, 2138 bfd *output_bfd, 2139 char **error_message) 2140 { 2141 /* If this is a relocatable link (output_bfd test tells us), just 2142 call the generic function. Any adjustment will be done at final 2143 link time. */ 2144 if (output_bfd != NULL) 2145 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data, 2146 input_section, output_bfd, error_message); 2147 2148 if (error_message != NULL) 2149 { 2150 static char buf[60]; 2151 sprintf (buf, _("generic linker can't handle %s"), 2152 reloc_entry->howto->name); 2153 *error_message = buf; 2154 } 2155 return bfd_reloc_dangerous; 2156 } 2157 2158 /* Fix bad default arch selected for a 32 bit input bfd when the 2159 default is 64 bit. */ 2160 2161 static bfd_boolean 2162 ppc_elf_object_p (bfd *abfd) 2163 { 2164 if (abfd->arch_info->the_default && abfd->arch_info->bits_per_word == 64) 2165 { 2166 Elf_Internal_Ehdr *i_ehdr = elf_elfheader (abfd); 2167 2168 if (i_ehdr->e_ident[EI_CLASS] == ELFCLASS32) 2169 { 2170 /* Relies on arch after 64 bit default being 32 bit default. */ 2171 abfd->arch_info = abfd->arch_info->next; 2172 BFD_ASSERT (abfd->arch_info->bits_per_word == 32); 2173 } 2174 } 2175 return TRUE; 2176 } 2177 2178 /* Function to set whether a module needs the -mrelocatable bit set. */ 2179 2180 static bfd_boolean 2181 ppc_elf_set_private_flags (bfd *abfd, flagword flags) 2182 { 2183 BFD_ASSERT (!elf_flags_init (abfd) 2184 || elf_elfheader (abfd)->e_flags == flags); 2185 2186 elf_elfheader (abfd)->e_flags = flags; 2187 elf_flags_init (abfd) = TRUE; 2188 return TRUE; 2189 } 2190 2191 /* Merge backend specific data from an object file to the output 2192 object file when linking. */ 2193 2194 static bfd_boolean 2195 ppc_elf_merge_private_bfd_data (bfd *ibfd, bfd *obfd) 2196 { 2197 flagword old_flags; 2198 flagword new_flags; 2199 bfd_boolean error; 2200 2201 /* Check if we have the same endianess. */ 2202 if (! _bfd_generic_verify_endian_match (ibfd, obfd)) 2203 return FALSE; 2204 2205 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour 2206 || bfd_get_flavour (obfd) != bfd_target_elf_flavour) 2207 return TRUE; 2208 2209 new_flags = elf_elfheader (ibfd)->e_flags; 2210 old_flags = elf_elfheader (obfd)->e_flags; 2211 if (!elf_flags_init (obfd)) 2212 { 2213 /* First call, no flags set. */ 2214 elf_flags_init (obfd) = TRUE; 2215 elf_elfheader (obfd)->e_flags = new_flags; 2216 } 2217 2218 /* Compatible flags are ok. */ 2219 else if (new_flags == old_flags) 2220 ; 2221 2222 /* Incompatible flags. */ 2223 else 2224 { 2225 /* Warn about -mrelocatable mismatch. Allow -mrelocatable-lib 2226 to be linked with either. */ 2227 error = FALSE; 2228 if ((new_flags & EF_PPC_RELOCATABLE) != 0 2229 && (old_flags & (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB)) == 0) 2230 { 2231 error = TRUE; 2232 (*_bfd_error_handler) 2233 (_("%s: compiled with -mrelocatable and linked with " 2234 "modules compiled normally"), 2235 bfd_archive_filename (ibfd)); 2236 } 2237 else if ((new_flags & (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB)) == 0 2238 && (old_flags & EF_PPC_RELOCATABLE) != 0) 2239 { 2240 error = TRUE; 2241 (*_bfd_error_handler) 2242 (_("%s: compiled normally and linked with " 2243 "modules compiled with -mrelocatable"), 2244 bfd_archive_filename (ibfd)); 2245 } 2246 2247 /* The output is -mrelocatable-lib iff both the input files are. */ 2248 if (! (new_flags & EF_PPC_RELOCATABLE_LIB)) 2249 elf_elfheader (obfd)->e_flags &= ~EF_PPC_RELOCATABLE_LIB; 2250 2251 /* The output is -mrelocatable iff it can't be -mrelocatable-lib, 2252 but each input file is either -mrelocatable or -mrelocatable-lib. */ 2253 if (! (elf_elfheader (obfd)->e_flags & EF_PPC_RELOCATABLE_LIB) 2254 && (new_flags & (EF_PPC_RELOCATABLE_LIB | EF_PPC_RELOCATABLE)) 2255 && (old_flags & (EF_PPC_RELOCATABLE_LIB | EF_PPC_RELOCATABLE))) 2256 elf_elfheader (obfd)->e_flags |= EF_PPC_RELOCATABLE; 2257 2258 /* Do not warn about eabi vs. V.4 mismatch, just or in the bit if 2259 any module uses it. */ 2260 elf_elfheader (obfd)->e_flags |= (new_flags & EF_PPC_EMB); 2261 2262 new_flags &= ~(EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB | EF_PPC_EMB); 2263 old_flags &= ~(EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB | EF_PPC_EMB); 2264 2265 /* Warn about any other mismatches. */ 2266 if (new_flags != old_flags) 2267 { 2268 error = TRUE; 2269 (*_bfd_error_handler) 2270 (_("%s: uses different e_flags (0x%lx) fields " 2271 "than previous modules (0x%lx)"), 2272 bfd_archive_filename (ibfd), (long) new_flags, (long) old_flags); 2273 } 2274 2275 if (error) 2276 { 2277 bfd_set_error (bfd_error_bad_value); 2278 return FALSE; 2279 } 2280 } 2281 2282 return TRUE; 2283 } 2284 2285 /* Handle a PowerPC specific section when reading an object file. This 2286 is called when elfcode.h finds a section with an unknown type. */ 2287 2288 static bfd_boolean 2289 ppc_elf_section_from_shdr (bfd *abfd, Elf_Internal_Shdr *hdr, const char *name) 2290 { 2291 asection *newsect; 2292 flagword flags; 2293 2294 if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name)) 2295 return FALSE; 2296 2297 newsect = hdr->bfd_section; 2298 flags = bfd_get_section_flags (abfd, newsect); 2299 if (hdr->sh_flags & SHF_EXCLUDE) 2300 flags |= SEC_EXCLUDE; 2301 2302 if (hdr->sh_type == SHT_ORDERED) 2303 flags |= SEC_SORT_ENTRIES; 2304 2305 bfd_set_section_flags (abfd, newsect, flags); 2306 return TRUE; 2307 } 2308 2309 /* Set up any other section flags and such that may be necessary. */ 2310 2311 static bfd_boolean 2312 ppc_elf_fake_sections (bfd *abfd ATTRIBUTE_UNUSED, 2313 Elf_Internal_Shdr *shdr, 2314 asection *asect) 2315 { 2316 if ((asect->flags & SEC_EXCLUDE) != 0) 2317 shdr->sh_flags |= SHF_EXCLUDE; 2318 2319 if ((asect->flags & SEC_SORT_ENTRIES) != 0) 2320 shdr->sh_type = SHT_ORDERED; 2321 2322 return TRUE; 2323 } 2324 2325 /* Find a linker generated pointer with a given addend and type. */ 2326 2327 static elf_linker_section_pointers_t * 2328 elf_find_pointer_linker_section 2329 (elf_linker_section_pointers_t *linker_pointers, 2330 bfd_vma addend, 2331 elf_linker_section_t *lsect) 2332 { 2333 for ( ; linker_pointers != NULL; linker_pointers = linker_pointers->next) 2334 if (lsect == linker_pointers->lsect && addend == linker_pointers->addend) 2335 return linker_pointers; 2336 2337 return NULL; 2338 } 2339 2340 /* Allocate a pointer to live in a linker created section. */ 2341 2342 static bfd_boolean 2343 elf_create_pointer_linker_section (bfd *abfd, 2344 struct bfd_link_info *info, 2345 elf_linker_section_t *lsect, 2346 struct elf_link_hash_entry *h, 2347 const Elf_Internal_Rela *rel) 2348 { 2349 elf_linker_section_pointers_t **ptr_linker_section_ptr = NULL; 2350 elf_linker_section_pointers_t *linker_section_ptr; 2351 unsigned long r_symndx = ELF32_R_SYM (rel->r_info); 2352 bfd_size_type amt; 2353 2354 BFD_ASSERT (lsect != NULL); 2355 2356 /* Is this a global symbol? */ 2357 if (h != NULL) 2358 { 2359 struct ppc_elf_link_hash_entry *eh; 2360 2361 /* Has this symbol already been allocated? If so, our work is done. */ 2362 eh = (struct ppc_elf_link_hash_entry *) h; 2363 if (elf_find_pointer_linker_section (eh->linker_section_pointer, 2364 rel->r_addend, 2365 lsect)) 2366 return TRUE; 2367 2368 ptr_linker_section_ptr = &eh->linker_section_pointer; 2369 /* Make sure this symbol is output as a dynamic symbol. */ 2370 if (h->dynindx == -1) 2371 { 2372 if (! bfd_elf_link_record_dynamic_symbol (info, h)) 2373 return FALSE; 2374 } 2375 2376 if (lsect->rel_section) 2377 lsect->rel_section->_raw_size += sizeof (Elf32_External_Rela); 2378 } 2379 else 2380 { 2381 /* Allocation of a pointer to a local symbol. */ 2382 elf_linker_section_pointers_t **ptr = elf_local_ptr_offsets (abfd); 2383 2384 /* Allocate a table to hold the local symbols if first time. */ 2385 if (!ptr) 2386 { 2387 unsigned int num_symbols = elf_tdata (abfd)->symtab_hdr.sh_info; 2388 2389 amt = num_symbols; 2390 amt *= sizeof (elf_linker_section_pointers_t *); 2391 ptr = bfd_zalloc (abfd, amt); 2392 2393 if (!ptr) 2394 return FALSE; 2395 2396 elf_local_ptr_offsets (abfd) = ptr; 2397 } 2398 2399 /* Has this symbol already been allocated? If so, our work is done. */ 2400 if (elf_find_pointer_linker_section (ptr[r_symndx], 2401 rel->r_addend, 2402 lsect)) 2403 return TRUE; 2404 2405 ptr_linker_section_ptr = &ptr[r_symndx]; 2406 2407 if (info->shared) 2408 { 2409 /* If we are generating a shared object, we need to 2410 output a R_<xxx>_RELATIVE reloc so that the 2411 dynamic linker can adjust this GOT entry. */ 2412 BFD_ASSERT (lsect->rel_section != NULL); 2413 lsect->rel_section->_raw_size += sizeof (Elf32_External_Rela); 2414 } 2415 } 2416 2417 /* Allocate space for a pointer in the linker section, and allocate 2418 a new pointer record from internal memory. */ 2419 BFD_ASSERT (ptr_linker_section_ptr != NULL); 2420 amt = sizeof (elf_linker_section_pointers_t); 2421 linker_section_ptr = bfd_alloc (abfd, amt); 2422 2423 if (!linker_section_ptr) 2424 return FALSE; 2425 2426 linker_section_ptr->next = *ptr_linker_section_ptr; 2427 linker_section_ptr->addend = rel->r_addend; 2428 linker_section_ptr->lsect = lsect; 2429 linker_section_ptr->written_address_p = FALSE; 2430 *ptr_linker_section_ptr = linker_section_ptr; 2431 2432 linker_section_ptr->offset = lsect->section->_raw_size; 2433 lsect->section->_raw_size += 4; 2434 2435 #ifdef DEBUG 2436 fprintf (stderr, 2437 "Create pointer in linker section %s, offset = %ld, section size = %ld\n", 2438 lsect->name, (long) linker_section_ptr->offset, 2439 (long) lsect->section->_raw_size); 2440 #endif 2441 2442 return TRUE; 2443 } 2444 2445 #define bfd_put_ptr(BFD, VAL, ADDR) bfd_put_32 (BFD, VAL, ADDR) 2446 2447 /* Fill in the address for a pointer generated in a linker section. */ 2448 2449 static bfd_vma 2450 elf_finish_pointer_linker_section (bfd *output_bfd, 2451 bfd *input_bfd, 2452 struct bfd_link_info *info, 2453 elf_linker_section_t *lsect, 2454 struct elf_link_hash_entry *h, 2455 bfd_vma relocation, 2456 const Elf_Internal_Rela *rel, 2457 int relative_reloc) 2458 { 2459 elf_linker_section_pointers_t *linker_section_ptr; 2460 2461 BFD_ASSERT (lsect != NULL); 2462 2463 if (h != NULL) 2464 { 2465 /* Handle global symbol. */ 2466 struct ppc_elf_link_hash_entry *eh; 2467 2468 eh = (struct ppc_elf_link_hash_entry *) h; 2469 linker_section_ptr 2470 = elf_find_pointer_linker_section (eh->linker_section_pointer, 2471 rel->r_addend, 2472 lsect); 2473 2474 BFD_ASSERT (linker_section_ptr != NULL); 2475 2476 if (! elf_hash_table (info)->dynamic_sections_created 2477 || (info->shared 2478 && info->symbolic 2479 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR))) 2480 { 2481 /* This is actually a static link, or it is a 2482 -Bsymbolic link and the symbol is defined 2483 locally. We must initialize this entry in the 2484 global section. 2485 2486 When doing a dynamic link, we create a .rela.<xxx> 2487 relocation entry to initialize the value. This 2488 is done in the finish_dynamic_symbol routine. */ 2489 if (!linker_section_ptr->written_address_p) 2490 { 2491 linker_section_ptr->written_address_p = TRUE; 2492 bfd_put_ptr (output_bfd, 2493 relocation + linker_section_ptr->addend, 2494 (lsect->section->contents 2495 + linker_section_ptr->offset)); 2496 } 2497 } 2498 } 2499 else 2500 { 2501 /* Handle local symbol. */ 2502 unsigned long r_symndx = ELF32_R_SYM (rel->r_info); 2503 BFD_ASSERT (elf_local_ptr_offsets (input_bfd) != NULL); 2504 BFD_ASSERT (elf_local_ptr_offsets (input_bfd)[r_symndx] != NULL); 2505 linker_section_ptr = (elf_find_pointer_linker_section 2506 (elf_local_ptr_offsets (input_bfd)[r_symndx], 2507 rel->r_addend, 2508 lsect)); 2509 2510 BFD_ASSERT (linker_section_ptr != NULL); 2511 2512 /* Write out pointer if it hasn't been rewritten out before. */ 2513 if (!linker_section_ptr->written_address_p) 2514 { 2515 linker_section_ptr->written_address_p = TRUE; 2516 bfd_put_ptr (output_bfd, relocation + linker_section_ptr->addend, 2517 lsect->section->contents + linker_section_ptr->offset); 2518 2519 if (info->shared) 2520 { 2521 /* We need to generate a relative reloc for the dynamic 2522 linker. */ 2523 2524 asection *srel = lsect->rel_section; 2525 Elf_Internal_Rela outrel[MAX_INT_RELS_PER_EXT_REL]; 2526 bfd_byte *erel; 2527 const struct elf_backend_data *bed; 2528 unsigned int i; 2529 2530 BFD_ASSERT (srel != NULL); 2531 2532 bed = get_elf_backend_data (output_bfd); 2533 for (i = 0; i < bed->s->int_rels_per_ext_rel; i++) 2534 { 2535 outrel[i].r_offset = (lsect->section->output_section->vma 2536 + lsect->section->output_offset 2537 + linker_section_ptr->offset); 2538 outrel[i].r_info = 0; 2539 outrel[i].r_addend = 0; 2540 } 2541 outrel[0].r_info = ELF32_R_INFO (0, relative_reloc); 2542 erel = lsect->section->contents; 2543 erel += (elf_section_data (lsect->section)->rel_count++ 2544 * sizeof (Elf32_External_Rela)); 2545 bfd_elf32_swap_reloca_out (output_bfd, outrel, erel); 2546 } 2547 } 2548 } 2549 2550 relocation = (lsect->section->output_offset 2551 + linker_section_ptr->offset 2552 - lsect->sym_offset); 2553 2554 #ifdef DEBUG 2555 fprintf (stderr, 2556 "Finish pointer in linker section %s, offset = %ld (0x%lx)\n", 2557 lsect->name, (long) relocation, (long) relocation); 2558 #endif 2559 2560 /* Subtract out the addend, because it will get added back in by the normal 2561 processing. */ 2562 return relocation - linker_section_ptr->addend; 2563 } 2564 2565 /* Create a special linker section */ 2566 static elf_linker_section_t * 2567 ppc_elf_create_linker_section (bfd *abfd, 2568 struct bfd_link_info *info, 2569 enum elf_linker_section_enum which) 2570 { 2571 elf_linker_section_t *lsect; 2572 struct ppc_elf_link_hash_table *htab = ppc_elf_hash_table (info); 2573 asection *s; 2574 bfd_size_type amt; 2575 flagword flags; 2576 const char *name; 2577 const char *rel_name; 2578 const char *sym_name; 2579 bfd_vma sym_offset; 2580 2581 /* Both of these sections are (technically) created by the user 2582 putting data in them, so they shouldn't be marked 2583 SEC_LINKER_CREATED. 2584 2585 The linker creates them so it has somewhere to attach their 2586 respective symbols. In fact, if they were empty it would 2587 be OK to leave the symbol set to 0 (or any random number), because 2588 the appropriate register should never be used. */ 2589 flags = SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY; 2590 sym_offset = 32768; 2591 2592 switch (which) 2593 { 2594 default: 2595 abort (); 2596 return NULL; 2597 2598 case LINKER_SECTION_SDATA: /* .sdata/.sbss section */ 2599 name = ".sdata"; 2600 rel_name = ".rela.sdata"; 2601 sym_name = "_SDA_BASE_"; 2602 break; 2603 2604 case LINKER_SECTION_SDATA2: /* .sdata2/.sbss2 section */ 2605 name = ".sdata2"; 2606 rel_name = ".rela.sdata2"; 2607 sym_name = "_SDA2_BASE_"; 2608 flags |= SEC_READONLY; 2609 break; 2610 } 2611 2612 /* Record the first bfd that needs the special sections. */ 2613 if (!htab->elf.dynobj) 2614 htab->elf.dynobj = abfd; 2615 2616 amt = sizeof (elf_linker_section_t); 2617 lsect = bfd_zalloc (htab->elf.dynobj, amt); 2618 2619 lsect->sym_offset = sym_offset; 2620 2621 /* See if the sections already exist. */ 2622 s = bfd_get_section_by_name (htab->elf.dynobj, name); 2623 if (s == NULL || (s->flags & flags) != flags) 2624 { 2625 s = bfd_make_section_anyway (htab->elf.dynobj, name); 2626 if (s == NULL 2627 || !bfd_set_section_flags (htab->elf.dynobj, s, flags)) 2628 return NULL; 2629 } 2630 lsect->section = s; 2631 2632 if (bfd_get_section_alignment (htab->elf.dynobj, s) < 2 2633 && !bfd_set_section_alignment (htab->elf.dynobj, s, 2)) 2634 return NULL; 2635 2636 s->_raw_size = align_power (s->_raw_size, 2); 2637 2638 #ifdef DEBUG 2639 fprintf (stderr, "Creating section %s, current size = %ld\n", 2640 name, (long) s->_raw_size); 2641 #endif 2642 2643 if (sym_name) 2644 { 2645 struct elf_link_hash_entry *h; 2646 struct bfd_link_hash_entry *bh; 2647 2648 #ifdef DEBUG 2649 fprintf (stderr, "Adding %s to section %s\n", sym_name, name); 2650 #endif 2651 bh = bfd_link_hash_lookup (info->hash, sym_name, 2652 FALSE, FALSE, FALSE); 2653 2654 if ((bh == NULL || bh->type == bfd_link_hash_undefined) 2655 && !(_bfd_generic_link_add_one_symbol 2656 (info, abfd, sym_name, BSF_GLOBAL, s, sym_offset, NULL, 2657 FALSE, get_elf_backend_data (abfd)->collect, &bh))) 2658 return NULL; 2659 h = (struct elf_link_hash_entry *) bh; 2660 2661 h->type = STT_OBJECT; 2662 lsect->sym_hash = h; 2663 2664 if (info->shared 2665 && ! bfd_elf_link_record_dynamic_symbol (info, h)) 2666 return NULL; 2667 } 2668 2669 if (info->shared) 2670 { 2671 s = bfd_make_section_anyway (htab->elf.dynobj, rel_name); 2672 lsect->rel_section = s; 2673 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY 2674 | SEC_LINKER_CREATED | SEC_READONLY); 2675 if (s == NULL 2676 || ! bfd_set_section_flags (htab->elf.dynobj, s, flags) 2677 || ! bfd_set_section_alignment (htab->elf.dynobj, s, 2)) 2678 return NULL; 2679 } 2680 2681 return lsect; 2682 } 2683 2684 /* If we have a non-zero sized .sbss2 or .PPC.EMB.sbss0 sections, we 2685 need to bump up the number of section headers. */ 2686 2687 static int 2688 ppc_elf_additional_program_headers (bfd *abfd) 2689 { 2690 asection *s; 2691 int ret; 2692 2693 ret = 0; 2694 2695 s = bfd_get_section_by_name (abfd, ".interp"); 2696 if (s != NULL) 2697 ++ret; 2698 2699 s = bfd_get_section_by_name (abfd, ".sbss2"); 2700 if (s != NULL && (s->flags & SEC_LOAD) != 0 && s->_raw_size > 0) 2701 ++ret; 2702 2703 s = bfd_get_section_by_name (abfd, ".PPC.EMB.sbss0"); 2704 if (s != NULL && (s->flags & SEC_LOAD) != 0 && s->_raw_size > 0) 2705 ++ret; 2706 2707 return ret; 2708 } 2709 2710 /* Modify the segment map if needed. */ 2711 2712 static bfd_boolean 2713 ppc_elf_modify_segment_map (bfd *abfd ATTRIBUTE_UNUSED, 2714 struct bfd_link_info *info ATTRIBUTE_UNUSED) 2715 { 2716 return TRUE; 2717 } 2718 2719 /* The powerpc .got has a blrl instruction in it. Mark it executable. */ 2720 2721 static bfd_boolean 2722 ppc_elf_create_got (bfd *abfd, struct bfd_link_info *info) 2723 { 2724 struct ppc_elf_link_hash_table *htab; 2725 asection *s; 2726 flagword flags; 2727 2728 if (!_bfd_elf_create_got_section (abfd, info)) 2729 return FALSE; 2730 2731 htab = ppc_elf_hash_table (info); 2732 htab->got = s = bfd_get_section_by_name (abfd, ".got"); 2733 if (s == NULL) 2734 abort (); 2735 2736 flags = (SEC_ALLOC | SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS | SEC_IN_MEMORY 2737 | SEC_LINKER_CREATED); 2738 if (!bfd_set_section_flags (abfd, s, flags)) 2739 return FALSE; 2740 2741 htab->relgot = bfd_make_section (abfd, ".rela.got"); 2742 if (!htab->relgot 2743 || ! bfd_set_section_flags (abfd, htab->relgot, 2744 (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS 2745 | SEC_IN_MEMORY | SEC_LINKER_CREATED 2746 | SEC_READONLY)) 2747 || ! bfd_set_section_alignment (abfd, htab->relgot, 2)) 2748 return FALSE; 2749 2750 return TRUE; 2751 } 2752 2753 /* We have to create .dynsbss and .rela.sbss here so that they get mapped 2754 to output sections (just like _bfd_elf_create_dynamic_sections has 2755 to create .dynbss and .rela.bss). */ 2756 2757 static bfd_boolean 2758 ppc_elf_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info) 2759 { 2760 struct ppc_elf_link_hash_table *htab; 2761 asection *s; 2762 flagword flags; 2763 2764 htab = ppc_elf_hash_table (info); 2765 2766 if (htab->got == NULL 2767 && !ppc_elf_create_got (abfd, info)) 2768 return FALSE; 2769 2770 if (!_bfd_elf_create_dynamic_sections (abfd, info)) 2771 return FALSE; 2772 2773 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY 2774 | SEC_LINKER_CREATED); 2775 2776 htab->dynbss = bfd_get_section_by_name (abfd, ".dynbss"); 2777 htab->dynsbss = s = bfd_make_section (abfd, ".dynsbss"); 2778 if (s == NULL 2779 || ! bfd_set_section_flags (abfd, s, SEC_ALLOC)) 2780 return FALSE; 2781 2782 if (! info->shared) 2783 { 2784 htab->relbss = bfd_get_section_by_name (abfd, ".rela.bss"); 2785 htab->relsbss = s = bfd_make_section (abfd, ".rela.sbss"); 2786 if (s == NULL 2787 || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY) 2788 || ! bfd_set_section_alignment (abfd, s, 2)) 2789 return FALSE; 2790 } 2791 2792 htab->relplt = bfd_get_section_by_name (abfd, ".rela.plt"); 2793 htab->plt = s = bfd_get_section_by_name (abfd, ".plt"); 2794 if (s == NULL) 2795 abort (); 2796 2797 flags = SEC_ALLOC | SEC_CODE | SEC_IN_MEMORY | SEC_LINKER_CREATED; 2798 return bfd_set_section_flags (abfd, s, flags); 2799 } 2800 2801 /* Adjust a symbol defined by a dynamic object and referenced by a 2802 regular object. The current definition is in some section of the 2803 dynamic object, but we're not including those sections. We have to 2804 change the definition to something the rest of the link can 2805 understand. */ 2806 2807 static bfd_boolean 2808 ppc_elf_adjust_dynamic_symbol (struct bfd_link_info *info, 2809 struct elf_link_hash_entry *h) 2810 { 2811 struct ppc_elf_link_hash_table *htab; 2812 asection *s; 2813 unsigned int power_of_two; 2814 2815 #ifdef DEBUG 2816 fprintf (stderr, "ppc_elf_adjust_dynamic_symbol called for %s\n", 2817 h->root.root.string); 2818 #endif 2819 2820 /* Make sure we know what is going on here. */ 2821 htab = ppc_elf_hash_table (info); 2822 BFD_ASSERT (htab->elf.dynobj != NULL 2823 && ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) 2824 || h->weakdef != NULL 2825 || ((h->elf_link_hash_flags 2826 & ELF_LINK_HASH_DEF_DYNAMIC) != 0 2827 && (h->elf_link_hash_flags 2828 & ELF_LINK_HASH_REF_REGULAR) != 0 2829 && (h->elf_link_hash_flags 2830 & ELF_LINK_HASH_DEF_REGULAR) == 0))); 2831 2832 /* Deal with function syms. */ 2833 if (h->type == STT_FUNC 2834 || (h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0) 2835 { 2836 /* Clear procedure linkage table information for any symbol that 2837 won't need a .plt entry. */ 2838 if (h->plt.refcount <= 0 2839 || SYMBOL_CALLS_LOCAL (info, h) 2840 || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT 2841 && h->root.type == bfd_link_hash_undefweak)) 2842 { 2843 /* A PLT entry is not required/allowed when: 2844 2845 1. We are not using ld.so; because then the PLT entry 2846 can't be set up, so we can't use one. In this case, 2847 ppc_elf_adjust_dynamic_symbol won't even be called. 2848 2849 2. GC has rendered the entry unused. 2850 2851 3. We know for certain that a call to this symbol 2852 will go to this object, or will remain undefined. */ 2853 h->plt.offset = (bfd_vma) -1; 2854 h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT; 2855 } 2856 return TRUE; 2857 } 2858 else 2859 h->plt.offset = (bfd_vma) -1; 2860 2861 /* If this is a weak symbol, and there is a real definition, the 2862 processor independent code will have arranged for us to see the 2863 real definition first, and we can just use the same value. */ 2864 if (h->weakdef != NULL) 2865 { 2866 BFD_ASSERT (h->weakdef->root.type == bfd_link_hash_defined 2867 || h->weakdef->root.type == bfd_link_hash_defweak); 2868 h->root.u.def.section = h->weakdef->root.u.def.section; 2869 h->root.u.def.value = h->weakdef->root.u.def.value; 2870 if (ELIMINATE_COPY_RELOCS) 2871 h->elf_link_hash_flags 2872 = ((h->elf_link_hash_flags & ~ELF_LINK_NON_GOT_REF) 2873 | (h->weakdef->elf_link_hash_flags & ELF_LINK_NON_GOT_REF)); 2874 return TRUE; 2875 } 2876 2877 /* This is a reference to a symbol defined by a dynamic object which 2878 is not a function. */ 2879 2880 /* If we are creating a shared library, we must presume that the 2881 only references to the symbol are via the global offset table. 2882 For such cases we need not do anything here; the relocations will 2883 be handled correctly by relocate_section. */ 2884 if (info->shared) 2885 return TRUE; 2886 2887 /* If there are no references to this symbol that do not use the 2888 GOT, we don't need to generate a copy reloc. */ 2889 if ((h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0) 2890 return TRUE; 2891 2892 if (ELIMINATE_COPY_RELOCS) 2893 { 2894 struct ppc_elf_dyn_relocs *p; 2895 for (p = ppc_elf_hash_entry (h)->dyn_relocs; p != NULL; p = p->next) 2896 { 2897 s = p->sec->output_section; 2898 if (s != NULL && (s->flags & SEC_READONLY) != 0) 2899 break; 2900 } 2901 2902 /* If we didn't find any dynamic relocs in read-only sections, then 2903 we'll be keeping the dynamic relocs and avoiding the copy reloc. */ 2904 if (p == NULL) 2905 { 2906 h->elf_link_hash_flags &= ~ELF_LINK_NON_GOT_REF; 2907 return TRUE; 2908 } 2909 } 2910 2911 /* We must allocate the symbol in our .dynbss section, which will 2912 become part of the .bss section of the executable. There will be 2913 an entry for this symbol in the .dynsym section. The dynamic 2914 object will contain position independent code, so all references 2915 from the dynamic object to this symbol will go through the global 2916 offset table. The dynamic linker will use the .dynsym entry to 2917 determine the address it must put in the global offset table, so 2918 both the dynamic object and the regular object will refer to the 2919 same memory location for the variable. 2920 2921 Of course, if the symbol is sufficiently small, we must instead 2922 allocate it in .sbss. FIXME: It would be better to do this if and 2923 only if there were actually SDAREL relocs for that symbol. */ 2924 2925 if (h->size <= elf_gp_size (htab->elf.dynobj)) 2926 s = htab->dynsbss; 2927 else 2928 s = htab->dynbss; 2929 BFD_ASSERT (s != NULL); 2930 2931 /* We must generate a R_PPC_COPY reloc to tell the dynamic linker to 2932 copy the initial value out of the dynamic object and into the 2933 runtime process image. We need to remember the offset into the 2934 .rela.bss section we are going to use. */ 2935 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0) 2936 { 2937 asection *srel; 2938 2939 if (h->size <= elf_gp_size (htab->elf.dynobj)) 2940 srel = htab->relsbss; 2941 else 2942 srel = htab->relbss; 2943 BFD_ASSERT (srel != NULL); 2944 srel->_raw_size += sizeof (Elf32_External_Rela); 2945 h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_COPY; 2946 } 2947 2948 /* We need to figure out the alignment required for this symbol. I 2949 have no idea how ELF linkers handle this. */ 2950 power_of_two = bfd_log2 (h->size); 2951 if (power_of_two > 4) 2952 power_of_two = 4; 2953 2954 /* Apply the required alignment. */ 2955 s->_raw_size = BFD_ALIGN (s->_raw_size, 2956 (bfd_size_type) (1 << power_of_two)); 2957 if (power_of_two > bfd_get_section_alignment (htab->elf.dynobj, s)) 2958 { 2959 if (! bfd_set_section_alignment (htab->elf.dynobj, s, power_of_two)) 2960 return FALSE; 2961 } 2962 2963 /* Define the symbol as being at this point in the section. */ 2964 h->root.u.def.section = s; 2965 h->root.u.def.value = s->_raw_size; 2966 2967 /* Increment the section size to make room for the symbol. */ 2968 s->_raw_size += h->size; 2969 2970 return TRUE; 2971 } 2972 2973 /* Of those relocs that might be copied as dynamic relocs, this macro 2974 selects those that must be copied when linking a shared library, 2975 even when the symbol is local. */ 2976 2977 #define MUST_BE_DYN_RELOC(RTYPE) \ 2978 ((RTYPE) != R_PPC_REL24 \ 2979 && (RTYPE) != R_PPC_REL14 \ 2980 && (RTYPE) != R_PPC_REL14_BRTAKEN \ 2981 && (RTYPE) != R_PPC_REL14_BRNTAKEN \ 2982 && (RTYPE) != R_PPC_REL32) 2983 2984 /* Allocate space in associated reloc sections for dynamic relocs. */ 2985 2986 static bfd_boolean 2987 allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf) 2988 { 2989 struct bfd_link_info *info = inf; 2990 struct ppc_elf_link_hash_entry *eh; 2991 struct ppc_elf_link_hash_table *htab; 2992 struct ppc_elf_dyn_relocs *p; 2993 2994 if (h->root.type == bfd_link_hash_indirect) 2995 return TRUE; 2996 2997 if (h->root.type == bfd_link_hash_warning) 2998 /* When warning symbols are created, they **replace** the "real" 2999 entry in the hash table, thus we never get to see the real 3000 symbol in a hash traversal. So look at it now. */ 3001 h = (struct elf_link_hash_entry *) h->root.u.i.link; 3002 3003 htab = ppc_elf_hash_table (info); 3004 if (htab->elf.dynamic_sections_created 3005 && h->plt.refcount > 0) 3006 { 3007 /* Make sure this symbol is output as a dynamic symbol. */ 3008 if (h->dynindx == -1 3009 && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) 3010 { 3011 if (! bfd_elf_link_record_dynamic_symbol (info, h)) 3012 return FALSE; 3013 } 3014 3015 if (info->shared 3016 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h)) 3017 { 3018 asection *s = htab->plt; 3019 3020 /* If this is the first .plt entry, make room for the special 3021 first entry. */ 3022 if (s->_raw_size == 0) 3023 s->_raw_size += PLT_INITIAL_ENTRY_SIZE; 3024 3025 /* The PowerPC PLT is actually composed of two parts, the 3026 first part is 2 words (for a load and a jump), and then 3027 there is a remaining word available at the end. */ 3028 h->plt.offset = (PLT_INITIAL_ENTRY_SIZE 3029 + (PLT_SLOT_SIZE 3030 * ((s->_raw_size - PLT_INITIAL_ENTRY_SIZE) 3031 / PLT_ENTRY_SIZE))); 3032 3033 /* If this symbol is not defined in a regular file, and we 3034 are not generating a shared library, then set the symbol 3035 to this location in the .plt. This is required to make 3036 function pointers compare as equal between the normal 3037 executable and the shared library. */ 3038 if (! info->shared 3039 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0) 3040 { 3041 h->root.u.def.section = s; 3042 h->root.u.def.value = h->plt.offset; 3043 } 3044 3045 /* Make room for this entry. After the 8192nd entry, room 3046 for two entries is allocated. */ 3047 s->_raw_size += PLT_ENTRY_SIZE; 3048 if ((s->_raw_size - PLT_INITIAL_ENTRY_SIZE) / PLT_ENTRY_SIZE 3049 > PLT_NUM_SINGLE_ENTRIES) 3050 s->_raw_size += PLT_ENTRY_SIZE; 3051 3052 /* We also need to make an entry in the .rela.plt section. */ 3053 htab->relplt->_raw_size += sizeof (Elf32_External_Rela); 3054 } 3055 else 3056 { 3057 h->plt.offset = (bfd_vma) -1; 3058 h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT; 3059 } 3060 } 3061 else 3062 { 3063 h->plt.offset = (bfd_vma) -1; 3064 h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT; 3065 } 3066 3067 eh = (struct ppc_elf_link_hash_entry *) h; 3068 if (eh->elf.got.refcount > 0) 3069 { 3070 /* Make sure this symbol is output as a dynamic symbol. */ 3071 if (eh->elf.dynindx == -1 3072 && (eh->elf.elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) 3073 { 3074 if (!bfd_elf_link_record_dynamic_symbol (info, &eh->elf)) 3075 return FALSE; 3076 } 3077 3078 if (eh->tls_mask == (TLS_TLS | TLS_LD) 3079 && !(eh->elf.elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC)) 3080 /* If just an LD reloc, we'll just use htab->tlsld_got.offset. */ 3081 eh->elf.got.offset = (bfd_vma) -1; 3082 else 3083 { 3084 bfd_boolean dyn; 3085 eh->elf.got.offset = htab->got->_raw_size; 3086 if ((eh->tls_mask & TLS_TLS) != 0) 3087 { 3088 if ((eh->tls_mask & TLS_LD) != 0) 3089 htab->got->_raw_size += 8; 3090 if ((eh->tls_mask & TLS_GD) != 0) 3091 htab->got->_raw_size += 8; 3092 if ((eh->tls_mask & (TLS_TPREL | TLS_TPRELGD)) != 0) 3093 htab->got->_raw_size += 4; 3094 if ((eh->tls_mask & TLS_DTPREL) != 0) 3095 htab->got->_raw_size += 4; 3096 } 3097 else 3098 htab->got->_raw_size += 4; 3099 dyn = htab->elf.dynamic_sections_created; 3100 if ((info->shared 3101 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, &eh->elf)) 3102 && (ELF_ST_VISIBILITY (eh->elf.other) == STV_DEFAULT 3103 || eh->elf.root.type != bfd_link_hash_undefweak)) 3104 { 3105 /* All the entries we allocated need relocs. */ 3106 htab->relgot->_raw_size 3107 += ((htab->got->_raw_size - eh->elf.got.offset) / 4 3108 * sizeof (Elf32_External_Rela)); 3109 /* Except LD only needs one. */ 3110 if ((eh->tls_mask & TLS_LD) != 0) 3111 htab->relgot->_raw_size -= sizeof (Elf32_External_Rela); 3112 } 3113 } 3114 } 3115 else 3116 eh->elf.got.offset = (bfd_vma) -1; 3117 3118 if (eh->dyn_relocs == NULL) 3119 return TRUE; 3120 3121 /* In the shared -Bsymbolic case, discard space allocated for 3122 dynamic pc-relative relocs against symbols which turn out to be 3123 defined in regular objects. For the normal shared case, discard 3124 space for relocs that have become local due to symbol visibility 3125 changes. */ 3126 3127 if (info->shared) 3128 { 3129 /* Relocs that use pc_count are those that appear on a call insn, 3130 or certain REL relocs (see MUST_BE_DYN_RELOC) that can be 3131 generated via assembly. We want calls to protected symbols to 3132 resolve directly to the function rather than going via the plt. 3133 If people want function pointer comparisons to work as expected 3134 then they should avoid writing weird assembly. */ 3135 if (SYMBOL_CALLS_LOCAL (info, h)) 3136 { 3137 struct ppc_elf_dyn_relocs **pp; 3138 3139 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; ) 3140 { 3141 p->count -= p->pc_count; 3142 p->pc_count = 0; 3143 if (p->count == 0) 3144 *pp = p->next; 3145 else 3146 pp = &p->next; 3147 } 3148 } 3149 3150 /* Also discard relocs on undefined weak syms with non-default 3151 visibility. */ 3152 if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT 3153 && h->root.type == bfd_link_hash_undefweak) 3154 eh->dyn_relocs = NULL; 3155 3156 /* Make sure undefined weak symbols are output as a dynamic symbol 3157 in PIEs. */ 3158 if (info->pie 3159 && eh->dyn_relocs != NULL 3160 && h->dynindx == -1 3161 && h->root.type == bfd_link_hash_undefweak 3162 && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) 3163 { 3164 if (! bfd_elf_link_record_dynamic_symbol (info, h)) 3165 return FALSE; 3166 } 3167 } 3168 else if (ELIMINATE_COPY_RELOCS) 3169 { 3170 /* For the non-shared case, discard space for relocs against 3171 symbols which turn out to need copy relocs or are not 3172 dynamic. */ 3173 3174 if ((h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0 3175 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0 3176 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0) 3177 { 3178 /* Make sure this symbol is output as a dynamic symbol. 3179 Undefined weak syms won't yet be marked as dynamic. */ 3180 if (h->dynindx == -1 3181 && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) 3182 { 3183 if (! bfd_elf_link_record_dynamic_symbol (info, h)) 3184 return FALSE; 3185 } 3186 3187 /* If that succeeded, we know we'll be keeping all the 3188 relocs. */ 3189 if (h->dynindx != -1) 3190 goto keep; 3191 } 3192 3193 eh->dyn_relocs = NULL; 3194 3195 keep: ; 3196 } 3197 3198 /* Finally, allocate space. */ 3199 for (p = eh->dyn_relocs; p != NULL; p = p->next) 3200 { 3201 asection *sreloc = elf_section_data (p->sec)->sreloc; 3202 sreloc->_raw_size += p->count * sizeof (Elf32_External_Rela); 3203 } 3204 3205 return TRUE; 3206 } 3207 3208 /* Find any dynamic relocs that apply to read-only sections. */ 3209 3210 static bfd_boolean 3211 readonly_dynrelocs (struct elf_link_hash_entry *h, void *info) 3212 { 3213 struct ppc_elf_dyn_relocs *p; 3214 3215 if (h->root.type == bfd_link_hash_indirect) 3216 return TRUE; 3217 3218 if (h->root.type == bfd_link_hash_warning) 3219 h = (struct elf_link_hash_entry *) h->root.u.i.link; 3220 3221 for (p = ppc_elf_hash_entry (h)->dyn_relocs; p != NULL; p = p->next) 3222 { 3223 asection *s = p->sec->output_section; 3224 3225 if (s != NULL 3226 && ((s->flags & (SEC_READONLY | SEC_ALLOC)) 3227 == (SEC_READONLY | SEC_ALLOC))) 3228 { 3229 ((struct bfd_link_info *) info)->flags |= DF_TEXTREL; 3230 3231 /* Not an error, just cut short the traversal. */ 3232 return FALSE; 3233 } 3234 } 3235 return TRUE; 3236 } 3237 3238 /* Set the sizes of the dynamic sections. */ 3239 3240 static bfd_boolean 3241 ppc_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED, 3242 struct bfd_link_info *info) 3243 { 3244 struct ppc_elf_link_hash_table *htab; 3245 asection *s; 3246 bfd_boolean relocs; 3247 bfd *ibfd; 3248 3249 #ifdef DEBUG 3250 fprintf (stderr, "ppc_elf_size_dynamic_sections called\n"); 3251 #endif 3252 3253 htab = ppc_elf_hash_table (info); 3254 BFD_ASSERT (htab->elf.dynobj != NULL); 3255 3256 if (elf_hash_table (info)->dynamic_sections_created) 3257 { 3258 /* Set the contents of the .interp section to the interpreter. */ 3259 if (info->executable && !info->static_link) 3260 { 3261 s = bfd_get_section_by_name (htab->elf.dynobj, ".interp"); 3262 BFD_ASSERT (s != NULL); 3263 s->_raw_size = sizeof ELF_DYNAMIC_INTERPRETER; 3264 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER; 3265 } 3266 } 3267 3268 if (htab->tlsld_got.refcount > 0) 3269 { 3270 htab->tlsld_got.offset = htab->got->_raw_size; 3271 htab->got->_raw_size += 8; 3272 if (info->shared) 3273 htab->relgot->_raw_size += sizeof (Elf32_External_Rela); 3274 } 3275 else 3276 htab->tlsld_got.offset = (bfd_vma) -1; 3277 3278 /* Set up .got offsets for local syms, and space for local dynamic 3279 relocs. */ 3280 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next) 3281 { 3282 bfd_signed_vma *local_got; 3283 bfd_signed_vma *end_local_got; 3284 char *lgot_masks; 3285 bfd_size_type locsymcount; 3286 Elf_Internal_Shdr *symtab_hdr; 3287 asection *srel; 3288 3289 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour) 3290 continue; 3291 3292 for (s = ibfd->sections; s != NULL; s = s->next) 3293 { 3294 struct ppc_elf_dyn_relocs *p; 3295 3296 for (p = ((struct ppc_elf_dyn_relocs *) 3297 elf_section_data (s)->local_dynrel); 3298 p != NULL; 3299 p = p->next) 3300 { 3301 if (!bfd_is_abs_section (p->sec) 3302 && bfd_is_abs_section (p->sec->output_section)) 3303 { 3304 /* Input section has been discarded, either because 3305 it is a copy of a linkonce section or due to 3306 linker script /DISCARD/, so we'll be discarding 3307 the relocs too. */ 3308 } 3309 else if (p->count != 0) 3310 { 3311 elf_section_data (p->sec)->sreloc->_raw_size 3312 += p->count * sizeof (Elf32_External_Rela); 3313 if ((p->sec->output_section->flags 3314 & (SEC_READONLY | SEC_ALLOC)) 3315 == (SEC_READONLY | SEC_ALLOC)) 3316 info->flags |= DF_TEXTREL; 3317 } 3318 } 3319 } 3320 3321 local_got = elf_local_got_refcounts (ibfd); 3322 if (!local_got) 3323 continue; 3324 3325 symtab_hdr = &elf_tdata (ibfd)->symtab_hdr; 3326 locsymcount = symtab_hdr->sh_info; 3327 end_local_got = local_got + locsymcount; 3328 lgot_masks = (char *) end_local_got; 3329 s = htab->got; 3330 srel = htab->relgot; 3331 for (; local_got < end_local_got; ++local_got, ++lgot_masks) 3332 if (*local_got > 0) 3333 { 3334 if (*lgot_masks == (TLS_TLS | TLS_LD)) 3335 { 3336 /* If just an LD reloc, we'll just use 3337 htab->tlsld_got.offset. */ 3338 if (htab->tlsld_got.offset == (bfd_vma) -1) 3339 { 3340 htab->tlsld_got.offset = s->_raw_size; 3341 s->_raw_size += 8; 3342 if (info->shared) 3343 srel->_raw_size += sizeof (Elf32_External_Rela); 3344 } 3345 *local_got = (bfd_vma) -1; 3346 } 3347 else 3348 { 3349 *local_got = s->_raw_size; 3350 if ((*lgot_masks & TLS_TLS) != 0) 3351 { 3352 if ((*lgot_masks & TLS_GD) != 0) 3353 s->_raw_size += 8; 3354 if ((*lgot_masks & (TLS_TPREL | TLS_TPRELGD)) != 0) 3355 s->_raw_size += 4; 3356 if ((*lgot_masks & TLS_DTPREL) != 0) 3357 s->_raw_size += 4; 3358 } 3359 else 3360 s->_raw_size += 4; 3361 if (info->shared) 3362 srel->_raw_size += ((s->_raw_size - *local_got) / 4 3363 * sizeof (Elf32_External_Rela)); 3364 } 3365 } 3366 else 3367 *local_got = (bfd_vma) -1; 3368 } 3369 3370 /* Allocate space for global sym dynamic relocs. */ 3371 elf_link_hash_traverse (elf_hash_table (info), allocate_dynrelocs, info); 3372 3373 /* We've now determined the sizes of the various dynamic sections. 3374 Allocate memory for them. */ 3375 relocs = FALSE; 3376 for (s = htab->elf.dynobj->sections; s != NULL; s = s->next) 3377 { 3378 if ((s->flags & SEC_LINKER_CREATED) == 0) 3379 continue; 3380 3381 if (s == htab->plt 3382 || s == htab->got 3383 || (htab->sdata != NULL && s == htab->sdata->section) 3384 || (htab->sdata2 != NULL && s == htab->sdata2->section)) 3385 { 3386 /* Strip this section if we don't need it; see the 3387 comment below. */ 3388 } 3389 else if (strncmp (bfd_get_section_name (dynobj, s), ".rela", 5) == 0) 3390 { 3391 if (s->_raw_size == 0) 3392 { 3393 /* If we don't need this section, strip it from the 3394 output file. This is mostly to handle .rela.bss and 3395 .rela.plt. We must create both sections in 3396 create_dynamic_sections, because they must be created 3397 before the linker maps input sections to output 3398 sections. The linker does that before 3399 adjust_dynamic_symbol is called, and it is that 3400 function which decides whether anything needs to go 3401 into these sections. */ 3402 } 3403 else 3404 { 3405 /* Remember whether there are any relocation sections. */ 3406 relocs = TRUE; 3407 3408 /* We use the reloc_count field as a counter if we need 3409 to copy relocs into the output file. */ 3410 s->reloc_count = 0; 3411 } 3412 } 3413 else 3414 { 3415 /* It's not one of our sections, so don't allocate space. */ 3416 continue; 3417 } 3418 3419 if (s->_raw_size == 0) 3420 { 3421 _bfd_strip_section_from_output (info, s); 3422 continue; 3423 } 3424 3425 /* Allocate memory for the section contents. */ 3426 s->contents = bfd_zalloc (htab->elf.dynobj, s->_raw_size); 3427 if (s->contents == NULL) 3428 return FALSE; 3429 } 3430 3431 if (htab->elf.dynamic_sections_created) 3432 { 3433 /* Add some entries to the .dynamic section. We fill in the 3434 values later, in ppc_elf_finish_dynamic_sections, but we 3435 must add the entries now so that we get the correct size for 3436 the .dynamic section. The DT_DEBUG entry is filled in by the 3437 dynamic linker and used by the debugger. */ 3438 #define add_dynamic_entry(TAG, VAL) \ 3439 _bfd_elf_add_dynamic_entry (info, TAG, VAL) 3440 3441 if (info->executable) 3442 { 3443 if (!add_dynamic_entry (DT_DEBUG, 0)) 3444 return FALSE; 3445 } 3446 3447 if (htab->plt != NULL && htab->plt->_raw_size != 0) 3448 { 3449 if (!add_dynamic_entry (DT_PLTGOT, 0) 3450 || !add_dynamic_entry (DT_PLTRELSZ, 0) 3451 || !add_dynamic_entry (DT_PLTREL, DT_RELA) 3452 || !add_dynamic_entry (DT_JMPREL, 0)) 3453 return FALSE; 3454 } 3455 3456 if (relocs) 3457 { 3458 if (!add_dynamic_entry (DT_RELA, 0) 3459 || !add_dynamic_entry (DT_RELASZ, 0) 3460 || !add_dynamic_entry (DT_RELAENT, sizeof (Elf32_External_Rela))) 3461 return FALSE; 3462 } 3463 3464 /* If any dynamic relocs apply to a read-only section, then we 3465 need a DT_TEXTREL entry. */ 3466 if ((info->flags & DF_TEXTREL) == 0) 3467 elf_link_hash_traverse (elf_hash_table (info), readonly_dynrelocs, 3468 info); 3469 3470 if ((info->flags & DF_TEXTREL) != 0) 3471 { 3472 if (!add_dynamic_entry (DT_TEXTREL, 0)) 3473 return FALSE; 3474 } 3475 } 3476 #undef add_dynamic_entry 3477 3478 return TRUE; 3479 } 3480 3481 static bfd_boolean 3482 update_local_sym_info (bfd *abfd, 3483 Elf_Internal_Shdr *symtab_hdr, 3484 unsigned long r_symndx, 3485 int tls_type) 3486 { 3487 bfd_signed_vma *local_got_refcounts = elf_local_got_refcounts (abfd); 3488 char *local_got_tls_masks; 3489 3490 if (local_got_refcounts == NULL) 3491 { 3492 bfd_size_type size = symtab_hdr->sh_info; 3493 3494 size *= sizeof (*local_got_refcounts) + sizeof (*local_got_tls_masks); 3495 local_got_refcounts = bfd_zalloc (abfd, size); 3496 if (local_got_refcounts == NULL) 3497 return FALSE; 3498 elf_local_got_refcounts (abfd) = local_got_refcounts; 3499 } 3500 3501 local_got_refcounts[r_symndx] += 1; 3502 local_got_tls_masks = (char *) (local_got_refcounts + symtab_hdr->sh_info); 3503 local_got_tls_masks[r_symndx] |= tls_type; 3504 return TRUE; 3505 } 3506 3507 static void 3508 bad_shared_reloc (bfd *abfd, enum elf_ppc_reloc_type r_type) 3509 { 3510 (*_bfd_error_handler) 3511 (_("%s: relocation %s cannot be used when making a shared object"), 3512 bfd_archive_filename (abfd), 3513 ppc_elf_howto_table[r_type]->name); 3514 bfd_set_error (bfd_error_bad_value); 3515 } 3516 3517 /* Look through the relocs for a section during the first phase, and 3518 allocate space in the global offset table or procedure linkage 3519 table. */ 3520 3521 static bfd_boolean 3522 ppc_elf_check_relocs (bfd *abfd, 3523 struct bfd_link_info *info, 3524 asection *sec, 3525 const Elf_Internal_Rela *relocs) 3526 { 3527 struct ppc_elf_link_hash_table *htab; 3528 Elf_Internal_Shdr *symtab_hdr; 3529 struct elf_link_hash_entry **sym_hashes; 3530 const Elf_Internal_Rela *rel; 3531 const Elf_Internal_Rela *rel_end; 3532 asection *sreloc; 3533 3534 if (info->relocatable) 3535 return TRUE; 3536 3537 #ifdef DEBUG 3538 fprintf (stderr, "ppc_elf_check_relocs called for section %s in %s\n", 3539 bfd_get_section_name (abfd, sec), 3540 bfd_archive_filename (abfd)); 3541 #endif 3542 3543 /* Initialize howto table if not already done. */ 3544 if (!ppc_elf_howto_table[R_PPC_ADDR32]) 3545 ppc_elf_howto_init (); 3546 3547 /* Create the linker generated sections all the time so that the 3548 special symbols are created. */ 3549 htab = ppc_elf_hash_table (info); 3550 if (htab->sdata == NULL) 3551 { 3552 htab->sdata = ppc_elf_create_linker_section (abfd, info, 3553 LINKER_SECTION_SDATA); 3554 if (htab->sdata == NULL) 3555 return FALSE; 3556 } 3557 3558 if (htab->sdata2 == NULL) 3559 { 3560 htab->sdata2 = ppc_elf_create_linker_section (abfd, info, 3561 LINKER_SECTION_SDATA2); 3562 if (htab->sdata2 == NULL) 3563 return FALSE; 3564 } 3565 3566 symtab_hdr = &elf_tdata (abfd)->symtab_hdr; 3567 sym_hashes = elf_sym_hashes (abfd); 3568 sreloc = NULL; 3569 3570 rel_end = relocs + sec->reloc_count; 3571 for (rel = relocs; rel < rel_end; rel++) 3572 { 3573 unsigned long r_symndx; 3574 enum elf_ppc_reloc_type r_type; 3575 struct elf_link_hash_entry *h; 3576 int tls_type = 0; 3577 3578 r_symndx = ELF32_R_SYM (rel->r_info); 3579 if (r_symndx < symtab_hdr->sh_info) 3580 h = NULL; 3581 else 3582 h = sym_hashes[r_symndx - symtab_hdr->sh_info]; 3583 3584 /* If a relocation refers to _GLOBAL_OFFSET_TABLE_, create the .got. 3585 This shows up in particular in an R_PPC_ADDR32 in the eabi 3586 startup code. */ 3587 if (h && strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0) 3588 { 3589 if (htab->got == NULL) 3590 { 3591 if (htab->elf.dynobj == NULL) 3592 htab->elf.dynobj = abfd; 3593 if (!ppc_elf_create_got (htab->elf.dynobj, info)) 3594 return FALSE; 3595 } 3596 } 3597 3598 r_type = ELF32_R_TYPE (rel->r_info); 3599 switch (r_type) 3600 { 3601 case R_PPC_GOT_TLSLD16: 3602 case R_PPC_GOT_TLSLD16_LO: 3603 case R_PPC_GOT_TLSLD16_HI: 3604 case R_PPC_GOT_TLSLD16_HA: 3605 htab->tlsld_got.refcount += 1; 3606 tls_type = TLS_TLS | TLS_LD; 3607 goto dogottls; 3608 3609 case R_PPC_GOT_TLSGD16: 3610 case R_PPC_GOT_TLSGD16_LO: 3611 case R_PPC_GOT_TLSGD16_HI: 3612 case R_PPC_GOT_TLSGD16_HA: 3613 tls_type = TLS_TLS | TLS_GD; 3614 goto dogottls; 3615 3616 case R_PPC_GOT_TPREL16: 3617 case R_PPC_GOT_TPREL16_LO: 3618 case R_PPC_GOT_TPREL16_HI: 3619 case R_PPC_GOT_TPREL16_HA: 3620 if (info->shared) 3621 info->flags |= DF_STATIC_TLS; 3622 tls_type = TLS_TLS | TLS_TPREL; 3623 goto dogottls; 3624 3625 case R_PPC_GOT_DTPREL16: 3626 case R_PPC_GOT_DTPREL16_LO: 3627 case R_PPC_GOT_DTPREL16_HI: 3628 case R_PPC_GOT_DTPREL16_HA: 3629 tls_type = TLS_TLS | TLS_DTPREL; 3630 dogottls: 3631 sec->has_tls_reloc = 1; 3632 /* Fall thru */ 3633 3634 /* GOT16 relocations */ 3635 case R_PPC_GOT16: 3636 case R_PPC_GOT16_LO: 3637 case R_PPC_GOT16_HI: 3638 case R_PPC_GOT16_HA: 3639 /* This symbol requires a global offset table entry. */ 3640 if (htab->got == NULL) 3641 { 3642 if (htab->elf.dynobj == NULL) 3643 htab->elf.dynobj = abfd; 3644 if (!ppc_elf_create_got (htab->elf.dynobj, info)) 3645 return FALSE; 3646 } 3647 if (h != NULL) 3648 { 3649 h->got.refcount += 1; 3650 ppc_elf_hash_entry (h)->tls_mask |= tls_type; 3651 } 3652 else 3653 /* This is a global offset table entry for a local symbol. */ 3654 if (!update_local_sym_info (abfd, symtab_hdr, r_symndx, tls_type)) 3655 return FALSE; 3656 break; 3657 3658 /* Indirect .sdata relocation. */ 3659 case R_PPC_EMB_SDAI16: 3660 if (info->shared) 3661 { 3662 bad_shared_reloc (abfd, r_type); 3663 return FALSE; 3664 } 3665 if (!elf_create_pointer_linker_section (abfd, info, 3666 htab->sdata, h, rel)) 3667 return FALSE; 3668 break; 3669 3670 /* Indirect .sdata2 relocation. */ 3671 case R_PPC_EMB_SDA2I16: 3672 if (info->shared) 3673 { 3674 bad_shared_reloc (abfd, r_type); 3675 return FALSE; 3676 } 3677 if (!elf_create_pointer_linker_section (abfd, info, 3678 htab->sdata2, h, rel)) 3679 return FALSE; 3680 break; 3681 3682 case R_PPC_SDAREL16: 3683 case R_PPC_EMB_SDA2REL: 3684 case R_PPC_EMB_SDA21: 3685 case R_PPC_EMB_RELSDA: 3686 case R_PPC_EMB_NADDR32: 3687 case R_PPC_EMB_NADDR16: 3688 case R_PPC_EMB_NADDR16_LO: 3689 case R_PPC_EMB_NADDR16_HI: 3690 case R_PPC_EMB_NADDR16_HA: 3691 if (info->shared) 3692 { 3693 bad_shared_reloc (abfd, r_type); 3694 return FALSE; 3695 } 3696 break; 3697 3698 case R_PPC_PLT32: 3699 case R_PPC_PLTREL24: 3700 case R_PPC_PLTREL32: 3701 case R_PPC_PLT16_LO: 3702 case R_PPC_PLT16_HI: 3703 case R_PPC_PLT16_HA: 3704 #ifdef DEBUG 3705 fprintf (stderr, "Reloc requires a PLT entry\n"); 3706 #endif 3707 /* This symbol requires a procedure linkage table entry. We 3708 actually build the entry in finish_dynamic_symbol, 3709 because this might be a case of linking PIC code without 3710 linking in any dynamic objects, in which case we don't 3711 need to generate a procedure linkage table after all. */ 3712 3713 if (h == NULL) 3714 { 3715 /* It does not make sense to have a procedure linkage 3716 table entry for a local symbol. */ 3717 (*_bfd_error_handler) (_("%s(%s+0x%lx): %s reloc against " 3718 "local symbol"), 3719 bfd_archive_filename (abfd), 3720 sec->name, 3721 (long) rel->r_offset, 3722 ppc_elf_howto_table[r_type]->name); 3723 bfd_set_error (bfd_error_bad_value); 3724 return FALSE; 3725 } 3726 3727 h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT; 3728 h->plt.refcount++; 3729 break; 3730 3731 /* The following relocations don't need to propagate the 3732 relocation if linking a shared object since they are 3733 section relative. */ 3734 case R_PPC_SECTOFF: 3735 case R_PPC_SECTOFF_LO: 3736 case R_PPC_SECTOFF_HI: 3737 case R_PPC_SECTOFF_HA: 3738 case R_PPC_DTPREL16: 3739 case R_PPC_DTPREL16_LO: 3740 case R_PPC_DTPREL16_HI: 3741 case R_PPC_DTPREL16_HA: 3742 case R_PPC_TOC16: 3743 break; 3744 3745 /* This are just markers. */ 3746 case R_PPC_TLS: 3747 case R_PPC_EMB_MRKREF: 3748 case R_PPC_NONE: 3749 case R_PPC_max: 3750 break; 3751 3752 /* These should only appear in dynamic objects. */ 3753 case R_PPC_COPY: 3754 case R_PPC_GLOB_DAT: 3755 case R_PPC_JMP_SLOT: 3756 case R_PPC_RELATIVE: 3757 break; 3758 3759 /* These aren't handled yet. We'll report an error later. */ 3760 case R_PPC_ADDR30: 3761 case R_PPC_EMB_RELSEC16: 3762 case R_PPC_EMB_RELST_LO: 3763 case R_PPC_EMB_RELST_HI: 3764 case R_PPC_EMB_RELST_HA: 3765 case R_PPC_EMB_BIT_FLD: 3766 break; 3767 3768 /* This refers only to functions defined in the shared library. */ 3769 case R_PPC_LOCAL24PC: 3770 break; 3771 3772 /* This relocation describes the C++ object vtable hierarchy. 3773 Reconstruct it for later use during GC. */ 3774 case R_PPC_GNU_VTINHERIT: 3775 if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset)) 3776 return FALSE; 3777 break; 3778 3779 /* This relocation describes which C++ vtable entries are actually 3780 used. Record for later use during GC. */ 3781 case R_PPC_GNU_VTENTRY: 3782 if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend)) 3783 return FALSE; 3784 break; 3785 3786 /* We shouldn't really be seeing these. */ 3787 case R_PPC_TPREL32: 3788 if (info->shared) 3789 info->flags |= DF_STATIC_TLS; 3790 goto dodyn; 3791 3792 /* Nor these. */ 3793 case R_PPC_DTPMOD32: 3794 case R_PPC_DTPREL32: 3795 goto dodyn; 3796 3797 case R_PPC_TPREL16: 3798 case R_PPC_TPREL16_LO: 3799 case R_PPC_TPREL16_HI: 3800 case R_PPC_TPREL16_HA: 3801 if (info->shared) 3802 info->flags |= DF_STATIC_TLS; 3803 goto dodyn; 3804 3805 /* When creating a shared object, we must copy these 3806 relocs into the output file. We create a reloc 3807 section in dynobj and make room for the reloc. */ 3808 case R_PPC_REL24: 3809 case R_PPC_REL14: 3810 case R_PPC_REL14_BRTAKEN: 3811 case R_PPC_REL14_BRNTAKEN: 3812 case R_PPC_REL32: 3813 if (h == NULL 3814 || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0) 3815 break; 3816 /* fall through */ 3817 3818 case R_PPC_ADDR32: 3819 case R_PPC_ADDR24: 3820 case R_PPC_ADDR16: 3821 case R_PPC_ADDR16_LO: 3822 case R_PPC_ADDR16_HI: 3823 case R_PPC_ADDR16_HA: 3824 case R_PPC_ADDR14: 3825 case R_PPC_ADDR14_BRTAKEN: 3826 case R_PPC_ADDR14_BRNTAKEN: 3827 case R_PPC_UADDR32: 3828 case R_PPC_UADDR16: 3829 if (h != NULL && !info->shared) 3830 { 3831 /* We may need a plt entry if the symbol turns out to be 3832 a function defined in a dynamic object. */ 3833 h->plt.refcount++; 3834 3835 /* We may need a copy reloc too. */ 3836 h->elf_link_hash_flags |= ELF_LINK_NON_GOT_REF; 3837 } 3838 3839 dodyn: 3840 /* If we are creating a shared library, and this is a reloc 3841 against a global symbol, or a non PC relative reloc 3842 against a local symbol, then we need to copy the reloc 3843 into the shared library. However, if we are linking with 3844 -Bsymbolic, we do not need to copy a reloc against a 3845 global symbol which is defined in an object we are 3846 including in the link (i.e., DEF_REGULAR is set). At 3847 this point we have not seen all the input files, so it is 3848 possible that DEF_REGULAR is not set now but will be set 3849 later (it is never cleared). In case of a weak definition, 3850 DEF_REGULAR may be cleared later by a strong definition in 3851 a shared library. We account for that possibility below by 3852 storing information in the dyn_relocs field of the hash 3853 table entry. A similar situation occurs when creating 3854 shared libraries and symbol visibility changes render the 3855 symbol local. 3856 3857 If on the other hand, we are creating an executable, we 3858 may need to keep relocations for symbols satisfied by a 3859 dynamic library if we manage to avoid copy relocs for the 3860 symbol. */ 3861 if ((info->shared 3862 && (MUST_BE_DYN_RELOC (r_type) 3863 || (h != NULL 3864 && (! info->symbolic 3865 || h->root.type == bfd_link_hash_defweak 3866 || (h->elf_link_hash_flags 3867 & ELF_LINK_HASH_DEF_REGULAR) == 0)))) 3868 || (ELIMINATE_COPY_RELOCS 3869 && !info->shared 3870 && (sec->flags & SEC_ALLOC) != 0 3871 && h != NULL 3872 && (h->root.type == bfd_link_hash_defweak 3873 || (h->elf_link_hash_flags 3874 & ELF_LINK_HASH_DEF_REGULAR) == 0))) 3875 { 3876 struct ppc_elf_dyn_relocs *p; 3877 struct ppc_elf_dyn_relocs **head; 3878 3879 #ifdef DEBUG 3880 fprintf (stderr, 3881 "ppc_elf_check_relocs needs to " 3882 "create relocation for %s\n", 3883 (h && h->root.root.string 3884 ? h->root.root.string : "<unknown>")); 3885 #endif 3886 if (sreloc == NULL) 3887 { 3888 const char *name; 3889 3890 name = (bfd_elf_string_from_elf_section 3891 (abfd, 3892 elf_elfheader (abfd)->e_shstrndx, 3893 elf_section_data (sec)->rel_hdr.sh_name)); 3894 if (name == NULL) 3895 return FALSE; 3896 3897 BFD_ASSERT (strncmp (name, ".rela", 5) == 0 3898 && strcmp (bfd_get_section_name (abfd, sec), 3899 name + 5) == 0); 3900 3901 sreloc = bfd_get_section_by_name (htab->elf.dynobj, name); 3902 if (sreloc == NULL) 3903 { 3904 flagword flags; 3905 3906 sreloc = bfd_make_section (htab->elf.dynobj, name); 3907 flags = (SEC_HAS_CONTENTS | SEC_READONLY 3908 | SEC_IN_MEMORY | SEC_LINKER_CREATED); 3909 if ((sec->flags & SEC_ALLOC) != 0) 3910 flags |= SEC_ALLOC | SEC_LOAD; 3911 if (sreloc == NULL 3912 || ! bfd_set_section_flags (htab->elf.dynobj, 3913 sreloc, flags) 3914 || ! bfd_set_section_alignment (htab->elf.dynobj, 3915 sreloc, 2)) 3916 return FALSE; 3917 } 3918 elf_section_data (sec)->sreloc = sreloc; 3919 } 3920 3921 /* If this is a global symbol, we count the number of 3922 relocations we need for this symbol. */ 3923 if (h != NULL) 3924 { 3925 head = &ppc_elf_hash_entry (h)->dyn_relocs; 3926 } 3927 else 3928 { 3929 /* Track dynamic relocs needed for local syms too. 3930 We really need local syms available to do this 3931 easily. Oh well. */ 3932 3933 asection *s; 3934 s = bfd_section_from_r_symndx (abfd, &htab->sym_sec, 3935 sec, r_symndx); 3936 if (s == NULL) 3937 return FALSE; 3938 3939 head = ((struct ppc_elf_dyn_relocs **) 3940 &elf_section_data (s)->local_dynrel); 3941 } 3942 3943 p = *head; 3944 if (p == NULL || p->sec != sec) 3945 { 3946 p = bfd_alloc (htab->elf.dynobj, sizeof *p); 3947 if (p == NULL) 3948 return FALSE; 3949 p->next = *head; 3950 *head = p; 3951 p->sec = sec; 3952 p->count = 0; 3953 p->pc_count = 0; 3954 } 3955 3956 p->count += 1; 3957 if (!MUST_BE_DYN_RELOC (r_type)) 3958 p->pc_count += 1; 3959 } 3960 3961 break; 3962 } 3963 } 3964 3965 return TRUE; 3966 } 3967 3968 /* Return the section that should be marked against GC for a given 3969 relocation. */ 3970 3971 static asection * 3972 ppc_elf_gc_mark_hook (asection *sec, 3973 struct bfd_link_info *info ATTRIBUTE_UNUSED, 3974 Elf_Internal_Rela *rel, 3975 struct elf_link_hash_entry *h, 3976 Elf_Internal_Sym *sym) 3977 { 3978 if (h != NULL) 3979 { 3980 switch (ELF32_R_TYPE (rel->r_info)) 3981 { 3982 case R_PPC_GNU_VTINHERIT: 3983 case R_PPC_GNU_VTENTRY: 3984 break; 3985 3986 default: 3987 switch (h->root.type) 3988 { 3989 case bfd_link_hash_defined: 3990 case bfd_link_hash_defweak: 3991 return h->root.u.def.section; 3992 3993 case bfd_link_hash_common: 3994 return h->root.u.c.p->section; 3995 3996 default: 3997 break; 3998 } 3999 } 4000 } 4001 else 4002 return bfd_section_from_elf_index (sec->owner, sym->st_shndx); 4003 4004 return NULL; 4005 } 4006 4007 /* Update the got, plt and dynamic reloc reference counts for the 4008 section being removed. */ 4009 4010 static bfd_boolean 4011 ppc_elf_gc_sweep_hook (bfd *abfd, 4012 struct bfd_link_info *info, 4013 asection *sec, 4014 const Elf_Internal_Rela *relocs) 4015 { 4016 struct ppc_elf_link_hash_table *htab; 4017 Elf_Internal_Shdr *symtab_hdr; 4018 struct elf_link_hash_entry **sym_hashes; 4019 bfd_signed_vma *local_got_refcounts; 4020 const Elf_Internal_Rela *rel, *relend; 4021 4022 elf_section_data (sec)->local_dynrel = NULL; 4023 4024 htab = ppc_elf_hash_table (info); 4025 symtab_hdr = &elf_tdata (abfd)->symtab_hdr; 4026 sym_hashes = elf_sym_hashes (abfd); 4027 local_got_refcounts = elf_local_got_refcounts (abfd); 4028 4029 relend = relocs + sec->reloc_count; 4030 for (rel = relocs; rel < relend; rel++) 4031 { 4032 unsigned long r_symndx; 4033 enum elf_ppc_reloc_type r_type; 4034 struct elf_link_hash_entry *h = NULL; 4035 4036 r_symndx = ELF32_R_SYM (rel->r_info); 4037 if (r_symndx >= symtab_hdr->sh_info) 4038 { 4039 struct ppc_elf_dyn_relocs **pp, *p; 4040 struct ppc_elf_link_hash_entry *eh; 4041 4042 h = sym_hashes[r_symndx - symtab_hdr->sh_info]; 4043 eh = (struct ppc_elf_link_hash_entry *) h; 4044 4045 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next) 4046 if (p->sec == sec) 4047 { 4048 /* Everything must go for SEC. */ 4049 *pp = p->next; 4050 break; 4051 } 4052 } 4053 4054 r_type = ELF32_R_TYPE (rel->r_info); 4055 switch (r_type) 4056 { 4057 case R_PPC_GOT_TLSLD16: 4058 case R_PPC_GOT_TLSLD16_LO: 4059 case R_PPC_GOT_TLSLD16_HI: 4060 case R_PPC_GOT_TLSLD16_HA: 4061 htab->tlsld_got.refcount -= 1; 4062 /* Fall thru */ 4063 4064 case R_PPC_GOT_TLSGD16: 4065 case R_PPC_GOT_TLSGD16_LO: 4066 case R_PPC_GOT_TLSGD16_HI: 4067 case R_PPC_GOT_TLSGD16_HA: 4068 case R_PPC_GOT_TPREL16: 4069 case R_PPC_GOT_TPREL16_LO: 4070 case R_PPC_GOT_TPREL16_HI: 4071 case R_PPC_GOT_TPREL16_HA: 4072 case R_PPC_GOT_DTPREL16: 4073 case R_PPC_GOT_DTPREL16_LO: 4074 case R_PPC_GOT_DTPREL16_HI: 4075 case R_PPC_GOT_DTPREL16_HA: 4076 case R_PPC_GOT16: 4077 case R_PPC_GOT16_LO: 4078 case R_PPC_GOT16_HI: 4079 case R_PPC_GOT16_HA: 4080 if (h != NULL) 4081 { 4082 if (h->got.refcount > 0) 4083 h->got.refcount--; 4084 } 4085 else if (local_got_refcounts != NULL) 4086 { 4087 if (local_got_refcounts[r_symndx] > 0) 4088 local_got_refcounts[r_symndx]--; 4089 } 4090 break; 4091 4092 case R_PPC_REL24: 4093 case R_PPC_REL14: 4094 case R_PPC_REL14_BRTAKEN: 4095 case R_PPC_REL14_BRNTAKEN: 4096 case R_PPC_REL32: 4097 if (h == NULL 4098 || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0) 4099 break; 4100 /* Fall thru */ 4101 4102 case R_PPC_ADDR32: 4103 case R_PPC_ADDR24: 4104 case R_PPC_ADDR16: 4105 case R_PPC_ADDR16_LO: 4106 case R_PPC_ADDR16_HI: 4107 case R_PPC_ADDR16_HA: 4108 case R_PPC_ADDR14: 4109 case R_PPC_ADDR14_BRTAKEN: 4110 case R_PPC_ADDR14_BRNTAKEN: 4111 case R_PPC_UADDR32: 4112 case R_PPC_UADDR16: 4113 case R_PPC_PLT32: 4114 case R_PPC_PLTREL24: 4115 case R_PPC_PLT16_LO: 4116 case R_PPC_PLT16_HI: 4117 case R_PPC_PLT16_HA: 4118 if (h != NULL) 4119 { 4120 if (h->plt.refcount > 0) 4121 h->plt.refcount--; 4122 } 4123 break; 4124 4125 default: 4126 break; 4127 } 4128 } 4129 return TRUE; 4130 } 4131 4132 /* Set htab->tls_get_addr and call the generic ELF tls_setup function. */ 4133 4134 asection * 4135 ppc_elf_tls_setup (bfd *obfd, struct bfd_link_info *info) 4136 { 4137 struct ppc_elf_link_hash_table *htab; 4138 4139 htab = ppc_elf_hash_table (info); 4140 htab->tls_get_addr = elf_link_hash_lookup (&htab->elf, "__tls_get_addr", 4141 FALSE, FALSE, TRUE); 4142 4143 return _bfd_elf_tls_setup (obfd, info); 4144 } 4145 4146 /* Run through all the TLS relocs looking for optimization 4147 opportunities. */ 4148 4149 bfd_boolean 4150 ppc_elf_tls_optimize (bfd *obfd ATTRIBUTE_UNUSED, 4151 struct bfd_link_info *info) 4152 { 4153 bfd *ibfd; 4154 asection *sec; 4155 struct ppc_elf_link_hash_table *htab; 4156 4157 if (info->relocatable || info->shared) 4158 return TRUE; 4159 4160 htab = ppc_elf_hash_table (info); 4161 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next) 4162 { 4163 Elf_Internal_Sym *locsyms = NULL; 4164 Elf_Internal_Shdr *symtab_hdr = &elf_tdata (ibfd)->symtab_hdr; 4165 4166 for (sec = ibfd->sections; sec != NULL; sec = sec->next) 4167 if (sec->has_tls_reloc && !bfd_is_abs_section (sec->output_section)) 4168 { 4169 Elf_Internal_Rela *relstart, *rel, *relend; 4170 int expecting_tls_get_addr; 4171 4172 /* Read the relocations. */ 4173 relstart = _bfd_elf_link_read_relocs (ibfd, sec, NULL, NULL, 4174 info->keep_memory); 4175 if (relstart == NULL) 4176 return FALSE; 4177 4178 expecting_tls_get_addr = 0; 4179 relend = relstart + sec->reloc_count; 4180 for (rel = relstart; rel < relend; rel++) 4181 { 4182 enum elf_ppc_reloc_type r_type; 4183 unsigned long r_symndx; 4184 struct elf_link_hash_entry *h = NULL; 4185 char *tls_mask; 4186 char tls_set, tls_clear; 4187 bfd_boolean is_local; 4188 4189 r_symndx = ELF32_R_SYM (rel->r_info); 4190 if (r_symndx >= symtab_hdr->sh_info) 4191 { 4192 struct elf_link_hash_entry **sym_hashes; 4193 4194 sym_hashes = elf_sym_hashes (ibfd); 4195 h = sym_hashes[r_symndx - symtab_hdr->sh_info]; 4196 while (h->root.type == bfd_link_hash_indirect 4197 || h->root.type == bfd_link_hash_warning) 4198 h = (struct elf_link_hash_entry *) h->root.u.i.link; 4199 } 4200 4201 is_local = FALSE; 4202 if (h == NULL 4203 || !(h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC)) 4204 is_local = TRUE; 4205 4206 r_type = ELF32_R_TYPE (rel->r_info); 4207 switch (r_type) 4208 { 4209 case R_PPC_GOT_TLSLD16: 4210 case R_PPC_GOT_TLSLD16_LO: 4211 case R_PPC_GOT_TLSLD16_HI: 4212 case R_PPC_GOT_TLSLD16_HA: 4213 /* These relocs should never be against a symbol 4214 defined in a shared lib. Leave them alone if 4215 that turns out to be the case. */ 4216 expecting_tls_get_addr = 0; 4217 htab->tlsld_got.refcount -= 1; 4218 if (!is_local) 4219 continue; 4220 4221 /* LD -> LE */ 4222 tls_set = 0; 4223 tls_clear = TLS_LD; 4224 expecting_tls_get_addr = 1; 4225 break; 4226 4227 case R_PPC_GOT_TLSGD16: 4228 case R_PPC_GOT_TLSGD16_LO: 4229 case R_PPC_GOT_TLSGD16_HI: 4230 case R_PPC_GOT_TLSGD16_HA: 4231 if (is_local) 4232 /* GD -> LE */ 4233 tls_set = 0; 4234 else 4235 /* GD -> IE */ 4236 tls_set = TLS_TLS | TLS_TPRELGD; 4237 tls_clear = TLS_GD; 4238 expecting_tls_get_addr = 1; 4239 break; 4240 4241 case R_PPC_GOT_TPREL16: 4242 case R_PPC_GOT_TPREL16_LO: 4243 case R_PPC_GOT_TPREL16_HI: 4244 case R_PPC_GOT_TPREL16_HA: 4245 expecting_tls_get_addr = 0; 4246 if (is_local) 4247 { 4248 /* IE -> LE */ 4249 tls_set = 0; 4250 tls_clear = TLS_TPREL; 4251 break; 4252 } 4253 else 4254 continue; 4255 4256 case R_PPC_REL14: 4257 case R_PPC_REL14_BRTAKEN: 4258 case R_PPC_REL14_BRNTAKEN: 4259 case R_PPC_REL24: 4260 if (expecting_tls_get_addr 4261 && h != NULL 4262 && h == htab->tls_get_addr) 4263 { 4264 if (h->plt.refcount > 0) 4265 h->plt.refcount -= 1; 4266 } 4267 expecting_tls_get_addr = 0; 4268 continue; 4269 4270 default: 4271 expecting_tls_get_addr = 0; 4272 continue; 4273 } 4274 4275 if (h != NULL) 4276 { 4277 if (tls_set == 0) 4278 { 4279 /* We managed to get rid of a got entry. */ 4280 if (h->got.refcount > 0) 4281 h->got.refcount -= 1; 4282 } 4283 tls_mask = &ppc_elf_hash_entry (h)->tls_mask; 4284 } 4285 else 4286 { 4287 Elf_Internal_Sym *sym; 4288 bfd_signed_vma *lgot_refs; 4289 char *lgot_masks; 4290 4291 if (locsyms == NULL) 4292 { 4293 locsyms = (Elf_Internal_Sym *) symtab_hdr->contents; 4294 if (locsyms == NULL) 4295 locsyms = bfd_elf_get_elf_syms (ibfd, symtab_hdr, 4296 symtab_hdr->sh_info, 4297 0, NULL, NULL, NULL); 4298 if (locsyms == NULL) 4299 { 4300 if (elf_section_data (sec)->relocs != relstart) 4301 free (relstart); 4302 return FALSE; 4303 } 4304 } 4305 sym = locsyms + r_symndx; 4306 lgot_refs = elf_local_got_refcounts (ibfd); 4307 if (lgot_refs == NULL) 4308 abort (); 4309 if (tls_set == 0) 4310 { 4311 /* We managed to get rid of a got entry. */ 4312 if (lgot_refs[r_symndx] > 0) 4313 lgot_refs[r_symndx] -= 1; 4314 } 4315 lgot_masks = (char *) (lgot_refs + symtab_hdr->sh_info); 4316 tls_mask = &lgot_masks[r_symndx]; 4317 } 4318 4319 *tls_mask |= tls_set; 4320 *tls_mask &= ~tls_clear; 4321 } 4322 4323 if (elf_section_data (sec)->relocs != relstart) 4324 free (relstart); 4325 } 4326 4327 if (locsyms != NULL 4328 && (symtab_hdr->contents != (unsigned char *) locsyms)) 4329 { 4330 if (!info->keep_memory) 4331 free (locsyms); 4332 else 4333 symtab_hdr->contents = (unsigned char *) locsyms; 4334 } 4335 } 4336 return TRUE; 4337 } 4338 4339 /* Hook called by the linker routine which adds symbols from an object 4340 file. We use it to put .comm items in .sbss, and not .bss. */ 4341 4342 static bfd_boolean 4343 ppc_elf_add_symbol_hook (bfd *abfd, 4344 struct bfd_link_info *info, 4345 Elf_Internal_Sym *sym, 4346 const char **namep ATTRIBUTE_UNUSED, 4347 flagword *flagsp ATTRIBUTE_UNUSED, 4348 asection **secp, 4349 bfd_vma *valp) 4350 { 4351 if (sym->st_shndx == SHN_COMMON 4352 && !info->relocatable 4353 && sym->st_size <= elf_gp_size (abfd) 4354 && (info->hash->creator == abfd->xvec 4355 || info->hash->creator == abfd->xvec->alternative_target)) 4356 { 4357 /* Common symbols less than or equal to -G nn bytes are automatically 4358 put into .sbss. */ 4359 struct ppc_elf_link_hash_table *htab; 4360 4361 htab = ppc_elf_hash_table (info); 4362 if (htab->sbss == NULL) 4363 { 4364 flagword flags = SEC_IS_COMMON; 4365 4366 htab->sbss = bfd_make_section_anyway (abfd, ".sbss"); 4367 if (htab->sbss == NULL 4368 || ! bfd_set_section_flags (abfd, htab->sbss, flags)) 4369 return FALSE; 4370 } 4371 4372 *secp = htab->sbss; 4373 *valp = sym->st_size; 4374 } 4375 4376 return TRUE; 4377 } 4378 4379 /* Finish up dynamic symbol handling. We set the contents of various 4380 dynamic sections here. */ 4381 4382 static bfd_boolean 4383 ppc_elf_finish_dynamic_symbol (bfd *output_bfd, 4384 struct bfd_link_info *info, 4385 struct elf_link_hash_entry *h, 4386 Elf_Internal_Sym *sym) 4387 { 4388 struct ppc_elf_link_hash_table *htab; 4389 4390 #ifdef DEBUG 4391 fprintf (stderr, "ppc_elf_finish_dynamic_symbol called for %s", 4392 h->root.root.string); 4393 #endif 4394 4395 htab = ppc_elf_hash_table (info); 4396 BFD_ASSERT (htab->elf.dynobj != NULL); 4397 4398 if (h->plt.offset != (bfd_vma) -1) 4399 { 4400 Elf_Internal_Rela rela; 4401 bfd_byte *loc; 4402 bfd_vma reloc_index; 4403 4404 #ifdef DEBUG 4405 fprintf (stderr, ", plt_offset = %d", h->plt.offset); 4406 #endif 4407 4408 /* This symbol has an entry in the procedure linkage table. Set 4409 it up. */ 4410 4411 BFD_ASSERT (h->dynindx != -1); 4412 BFD_ASSERT (htab->plt != NULL && htab->relplt != NULL); 4413 4414 /* We don't need to fill in the .plt. The ppc dynamic linker 4415 will fill it in. */ 4416 4417 /* Fill in the entry in the .rela.plt section. */ 4418 rela.r_offset = (htab->plt->output_section->vma 4419 + htab->plt->output_offset 4420 + h->plt.offset); 4421 rela.r_info = ELF32_R_INFO (h->dynindx, R_PPC_JMP_SLOT); 4422 rela.r_addend = 0; 4423 4424 reloc_index = (h->plt.offset - PLT_INITIAL_ENTRY_SIZE) / PLT_SLOT_SIZE; 4425 if (reloc_index > PLT_NUM_SINGLE_ENTRIES) 4426 reloc_index -= (reloc_index - PLT_NUM_SINGLE_ENTRIES) / 2; 4427 loc = (htab->relplt->contents 4428 + reloc_index * sizeof (Elf32_External_Rela)); 4429 bfd_elf32_swap_reloca_out (output_bfd, &rela, loc); 4430 4431 if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0) 4432 { 4433 /* Mark the symbol as undefined, rather than as defined in 4434 the .plt section. Leave the value alone. */ 4435 sym->st_shndx = SHN_UNDEF; 4436 /* If the symbol is weak, we do need to clear the value. 4437 Otherwise, the PLT entry would provide a definition for 4438 the symbol even if the symbol wasn't defined anywhere, 4439 and so the symbol would never be NULL. */ 4440 if ((h->elf_link_hash_flags & ELF_LINK_HASH_REF_REGULAR_NONWEAK) 4441 == 0) 4442 sym->st_value = 0; 4443 } 4444 } 4445 4446 if ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_COPY) != 0) 4447 { 4448 asection *s; 4449 Elf_Internal_Rela rela; 4450 bfd_byte *loc; 4451 4452 /* This symbols needs a copy reloc. Set it up. */ 4453 4454 #ifdef DEBUG 4455 fprintf (stderr, ", copy"); 4456 #endif 4457 4458 BFD_ASSERT (h->dynindx != -1); 4459 4460 if (h->size <= elf_gp_size (htab->elf.dynobj)) 4461 s = htab->relsbss; 4462 else 4463 s = htab->relbss; 4464 BFD_ASSERT (s != NULL); 4465 4466 rela.r_offset = (h->root.u.def.value 4467 + h->root.u.def.section->output_section->vma 4468 + h->root.u.def.section->output_offset); 4469 rela.r_info = ELF32_R_INFO (h->dynindx, R_PPC_COPY); 4470 rela.r_addend = 0; 4471 loc = s->contents + s->reloc_count++ * sizeof (Elf32_External_Rela); 4472 bfd_elf32_swap_reloca_out (output_bfd, &rela, loc); 4473 } 4474 4475 #ifdef DEBUG 4476 fprintf (stderr, "\n"); 4477 #endif 4478 4479 /* Mark some specially defined symbols as absolute. */ 4480 if (strcmp (h->root.root.string, "_DYNAMIC") == 0 4481 || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0 4482 || strcmp (h->root.root.string, "_PROCEDURE_LINKAGE_TABLE_") == 0) 4483 sym->st_shndx = SHN_ABS; 4484 4485 return TRUE; 4486 } 4487 4488 /* Finish up the dynamic sections. */ 4489 4490 static bfd_boolean 4491 ppc_elf_finish_dynamic_sections (bfd *output_bfd, 4492 struct bfd_link_info *info) 4493 { 4494 asection *sdyn; 4495 struct ppc_elf_link_hash_table *htab; 4496 4497 #ifdef DEBUG 4498 fprintf (stderr, "ppc_elf_finish_dynamic_sections called\n"); 4499 #endif 4500 4501 htab = ppc_elf_hash_table (info); 4502 sdyn = bfd_get_section_by_name (htab->elf.dynobj, ".dynamic"); 4503 4504 if (htab->elf.dynamic_sections_created) 4505 { 4506 Elf32_External_Dyn *dyncon, *dynconend; 4507 4508 BFD_ASSERT (htab->plt != NULL && sdyn != NULL); 4509 4510 dyncon = (Elf32_External_Dyn *) sdyn->contents; 4511 dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->_raw_size); 4512 for (; dyncon < dynconend; dyncon++) 4513 { 4514 Elf_Internal_Dyn dyn; 4515 asection *s; 4516 4517 bfd_elf32_swap_dyn_in (htab->elf.dynobj, dyncon, &dyn); 4518 4519 switch (dyn.d_tag) 4520 { 4521 case DT_PLTGOT: 4522 s = htab->plt; 4523 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset; 4524 break; 4525 4526 case DT_PLTRELSZ: 4527 dyn.d_un.d_val = htab->relplt->_raw_size; 4528 break; 4529 4530 case DT_JMPREL: 4531 s = htab->relplt; 4532 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset; 4533 break; 4534 4535 default: 4536 continue; 4537 } 4538 4539 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); 4540 } 4541 } 4542 4543 /* Add a blrl instruction at _GLOBAL_OFFSET_TABLE_-4 so that a function can 4544 easily find the address of the _GLOBAL_OFFSET_TABLE_. */ 4545 if (htab->got) 4546 { 4547 unsigned char *contents = htab->got->contents; 4548 bfd_put_32 (output_bfd, 0x4e800021 /* blrl */, contents); 4549 4550 if (sdyn == NULL) 4551 bfd_put_32 (output_bfd, 0, contents + 4); 4552 else 4553 bfd_put_32 (output_bfd, 4554 sdyn->output_section->vma + sdyn->output_offset, 4555 contents + 4); 4556 4557 elf_section_data (htab->got->output_section)->this_hdr.sh_entsize = 4; 4558 } 4559 4560 return TRUE; 4561 } 4562 4563 /* The RELOCATE_SECTION function is called by the ELF backend linker 4564 to handle the relocations for a section. 4565 4566 The relocs are always passed as Rela structures; if the section 4567 actually uses Rel structures, the r_addend field will always be 4568 zero. 4569 4570 This function is responsible for adjust the section contents as 4571 necessary, and (if using Rela relocs and generating a 4572 relocatable output file) adjusting the reloc addend as 4573 necessary. 4574 4575 This function does not have to worry about setting the reloc 4576 address or the reloc symbol index. 4577 4578 LOCAL_SYMS is a pointer to the swapped in local symbols. 4579 4580 LOCAL_SECTIONS is an array giving the section in the input file 4581 corresponding to the st_shndx field of each local symbol. 4582 4583 The global hash table entry for the global symbols can be found 4584 via elf_sym_hashes (input_bfd). 4585 4586 When generating relocatable output, this function must handle 4587 STB_LOCAL/STT_SECTION symbols specially. The output symbol is 4588 going to be the section symbol corresponding to the output 4589 section, which means that the addend must be adjusted 4590 accordingly. */ 4591 4592 static bfd_boolean 4593 ppc_elf_relocate_section (bfd *output_bfd, 4594 struct bfd_link_info *info, 4595 bfd *input_bfd, 4596 asection *input_section, 4597 bfd_byte *contents, 4598 Elf_Internal_Rela *relocs, 4599 Elf_Internal_Sym *local_syms, 4600 asection **local_sections) 4601 { 4602 Elf_Internal_Shdr *symtab_hdr; 4603 struct elf_link_hash_entry **sym_hashes; 4604 struct ppc_elf_link_hash_table *htab; 4605 Elf_Internal_Rela *rel; 4606 Elf_Internal_Rela *relend; 4607 Elf_Internal_Rela outrel; 4608 bfd_byte *loc; 4609 asection *sreloc = NULL; 4610 bfd_vma *local_got_offsets; 4611 bfd_boolean ret = TRUE; 4612 4613 #ifdef DEBUG 4614 fprintf (stderr, "ppc_elf_relocate_section called for %s section %s, " 4615 "%ld relocations%s\n", 4616 bfd_archive_filename (input_bfd), 4617 bfd_section_name(input_bfd, input_section), 4618 (long) input_section->reloc_count, 4619 (info->relocatable) ? " (relocatable)" : ""); 4620 #endif 4621 4622 if (info->relocatable) 4623 return TRUE; 4624 4625 /* Initialize howto table if not already done. */ 4626 if (!ppc_elf_howto_table[R_PPC_ADDR32]) 4627 ppc_elf_howto_init (); 4628 4629 htab = ppc_elf_hash_table (info); 4630 local_got_offsets = elf_local_got_offsets (input_bfd); 4631 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; 4632 sym_hashes = elf_sym_hashes (input_bfd); 4633 rel = relocs; 4634 relend = relocs + input_section->reloc_count; 4635 for (; rel < relend; rel++) 4636 { 4637 enum elf_ppc_reloc_type r_type; 4638 bfd_vma addend; 4639 bfd_reloc_status_type r; 4640 Elf_Internal_Sym *sym; 4641 asection *sec; 4642 struct elf_link_hash_entry *h; 4643 const char *sym_name; 4644 reloc_howto_type *howto; 4645 unsigned long r_symndx; 4646 bfd_vma relocation; 4647 bfd_vma branch_bit, insn, from; 4648 bfd_boolean unresolved_reloc; 4649 bfd_boolean warned; 4650 unsigned int tls_type, tls_mask, tls_gd; 4651 4652 r_type = ELF32_R_TYPE (rel->r_info); 4653 sym = NULL; 4654 sec = NULL; 4655 h = NULL; 4656 unresolved_reloc = FALSE; 4657 warned = FALSE; 4658 r_symndx = ELF32_R_SYM (rel->r_info); 4659 4660 if (r_symndx < symtab_hdr->sh_info) 4661 { 4662 sym = local_syms + r_symndx; 4663 sec = local_sections[r_symndx]; 4664 sym_name = bfd_elf_local_sym_name (input_bfd, sym); 4665 4666 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel); 4667 } 4668 else 4669 { 4670 RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel, 4671 r_symndx, symtab_hdr, sym_hashes, 4672 h, sec, relocation, 4673 unresolved_reloc, warned); 4674 4675 sym_name = h->root.root.string; 4676 } 4677 4678 /* TLS optimizations. Replace instruction sequences and relocs 4679 based on information we collected in tls_optimize. We edit 4680 RELOCS so that --emit-relocs will output something sensible 4681 for the final instruction stream. */ 4682 tls_mask = 0; 4683 tls_gd = 0; 4684 if (IS_PPC_TLS_RELOC (r_type)) 4685 { 4686 if (h != NULL) 4687 tls_mask = ((struct ppc_elf_link_hash_entry *) h)->tls_mask; 4688 else if (local_got_offsets != NULL) 4689 { 4690 char *lgot_masks; 4691 lgot_masks = (char *) (local_got_offsets + symtab_hdr->sh_info); 4692 tls_mask = lgot_masks[r_symndx]; 4693 } 4694 } 4695 4696 /* Ensure reloc mapping code below stays sane. */ 4697 if ((R_PPC_GOT_TLSLD16 & 3) != (R_PPC_GOT_TLSGD16 & 3) 4698 || (R_PPC_GOT_TLSLD16_LO & 3) != (R_PPC_GOT_TLSGD16_LO & 3) 4699 || (R_PPC_GOT_TLSLD16_HI & 3) != (R_PPC_GOT_TLSGD16_HI & 3) 4700 || (R_PPC_GOT_TLSLD16_HA & 3) != (R_PPC_GOT_TLSGD16_HA & 3) 4701 || (R_PPC_GOT_TLSLD16 & 3) != (R_PPC_GOT_TPREL16 & 3) 4702 || (R_PPC_GOT_TLSLD16_LO & 3) != (R_PPC_GOT_TPREL16_LO & 3) 4703 || (R_PPC_GOT_TLSLD16_HI & 3) != (R_PPC_GOT_TPREL16_HI & 3) 4704 || (R_PPC_GOT_TLSLD16_HA & 3) != (R_PPC_GOT_TPREL16_HA & 3)) 4705 abort (); 4706 switch (r_type) 4707 { 4708 default: 4709 break; 4710 4711 case R_PPC_GOT_TPREL16: 4712 case R_PPC_GOT_TPREL16_LO: 4713 if (tls_mask != 0 4714 && (tls_mask & TLS_TPREL) == 0) 4715 { 4716 bfd_vma insn; 4717 insn = bfd_get_32 (output_bfd, contents + rel->r_offset - 2); 4718 insn &= 31 << 21; 4719 insn |= 0x3c020000; /* addis 0,2,0 */ 4720 bfd_put_32 (output_bfd, insn, contents + rel->r_offset - 2); 4721 r_type = R_PPC_TPREL16_HA; 4722 rel->r_info = ELF32_R_INFO (r_symndx, r_type); 4723 } 4724 break; 4725 4726 case R_PPC_TLS: 4727 if (tls_mask != 0 4728 && (tls_mask & TLS_TPREL) == 0) 4729 { 4730 bfd_vma insn, rtra; 4731 insn = bfd_get_32 (output_bfd, contents + rel->r_offset); 4732 if ((insn & ((31 << 26) | (31 << 11))) 4733 == ((31 << 26) | (2 << 11))) 4734 rtra = insn & ((1 << 26) - (1 << 16)); 4735 else if ((insn & ((31 << 26) | (31 << 16))) 4736 == ((31 << 26) | (2 << 16))) 4737 rtra = (insn & (31 << 21)) | ((insn & (31 << 11)) << 5); 4738 else 4739 abort (); 4740 if ((insn & ((1 << 11) - (1 << 1))) == 266 << 1) 4741 /* add -> addi. */ 4742 insn = 14 << 26; 4743 else if ((insn & (31 << 1)) == 23 << 1 4744 && ((insn & (31 << 6)) < 14 << 6 4745 || ((insn & (31 << 6)) >= 16 << 6 4746 && (insn & (31 << 6)) < 24 << 6))) 4747 /* load and store indexed -> dform. */ 4748 insn = (32 | ((insn >> 6) & 31)) << 26; 4749 else if ((insn & (31 << 1)) == 21 << 1 4750 && (insn & (0x1a << 6)) == 0) 4751 /* ldx, ldux, stdx, stdux -> ld, ldu, std, stdu. */ 4752 insn = (((58 | ((insn >> 6) & 4)) << 26) 4753 | ((insn >> 6) & 1)); 4754 else if ((insn & (31 << 1)) == 21 << 1 4755 && (insn & ((1 << 11) - (1 << 1))) == 341 << 1) 4756 /* lwax -> lwa. */ 4757 insn = (58 << 26) | 2; 4758 else 4759 abort (); 4760 insn |= rtra; 4761 bfd_put_32 (output_bfd, insn, contents + rel->r_offset); 4762 r_type = R_PPC_TPREL16_LO; 4763 rel->r_info = ELF32_R_INFO (r_symndx, r_type); 4764 /* Was PPC_TLS which sits on insn boundary, now 4765 PPC_TPREL16_LO which is at insn+2. */ 4766 rel->r_offset += 2; 4767 } 4768 break; 4769 4770 case R_PPC_GOT_TLSGD16_HI: 4771 case R_PPC_GOT_TLSGD16_HA: 4772 tls_gd = TLS_TPRELGD; 4773 if (tls_mask != 0 && (tls_mask & TLS_GD) == 0) 4774 goto tls_gdld_hi; 4775 break; 4776 4777 case R_PPC_GOT_TLSLD16_HI: 4778 case R_PPC_GOT_TLSLD16_HA: 4779 if (tls_mask != 0 && (tls_mask & TLS_LD) == 0) 4780 { 4781 tls_gdld_hi: 4782 if ((tls_mask & tls_gd) != 0) 4783 r_type = (((r_type - (R_PPC_GOT_TLSGD16 & 3)) & 3) 4784 + R_PPC_GOT_TPREL16); 4785 else 4786 { 4787 bfd_put_32 (output_bfd, NOP, contents + rel->r_offset); 4788 rel->r_offset -= 2; 4789 r_type = R_PPC_NONE; 4790 } 4791 rel->r_info = ELF32_R_INFO (r_symndx, r_type); 4792 } 4793 break; 4794 4795 case R_PPC_GOT_TLSGD16: 4796 case R_PPC_GOT_TLSGD16_LO: 4797 tls_gd = TLS_TPRELGD; 4798 if (tls_mask != 0 && (tls_mask & TLS_GD) == 0) 4799 goto tls_get_addr_check; 4800 break; 4801 4802 case R_PPC_GOT_TLSLD16: 4803 case R_PPC_GOT_TLSLD16_LO: 4804 if (tls_mask != 0 && (tls_mask & TLS_LD) == 0) 4805 { 4806 tls_get_addr_check: 4807 if (rel + 1 < relend) 4808 { 4809 enum elf_ppc_reloc_type r_type2; 4810 unsigned long r_symndx2; 4811 struct elf_link_hash_entry *h2; 4812 bfd_vma insn1, insn2; 4813 bfd_vma offset; 4814 4815 /* The next instruction should be a call to 4816 __tls_get_addr. Peek at the reloc to be sure. */ 4817 r_type2 = ELF32_R_TYPE (rel[1].r_info); 4818 r_symndx2 = ELF32_R_SYM (rel[1].r_info); 4819 if (r_symndx2 < symtab_hdr->sh_info 4820 || (r_type2 != R_PPC_REL14 4821 && r_type2 != R_PPC_REL14_BRTAKEN 4822 && r_type2 != R_PPC_REL14_BRNTAKEN 4823 && r_type2 != R_PPC_REL24 4824 && r_type2 != R_PPC_PLTREL24)) 4825 break; 4826 4827 h2 = sym_hashes[r_symndx2 - symtab_hdr->sh_info]; 4828 while (h2->root.type == bfd_link_hash_indirect 4829 || h2->root.type == bfd_link_hash_warning) 4830 h2 = (struct elf_link_hash_entry *) h2->root.u.i.link; 4831 if (h2 == NULL || h2 != htab->tls_get_addr) 4832 break; 4833 4834 /* OK, it checks out. Replace the call. */ 4835 offset = rel[1].r_offset; 4836 insn1 = bfd_get_32 (output_bfd, 4837 contents + rel->r_offset - 2); 4838 if ((tls_mask & tls_gd) != 0) 4839 { 4840 /* IE */ 4841 insn1 &= (1 << 26) - 1; 4842 insn1 |= 32 << 26; /* lwz */ 4843 insn2 = 0x7c631214; /* add 3,3,2 */ 4844 rel[1].r_info = ELF32_R_INFO (r_symndx2, R_PPC_NONE); 4845 r_type = (((r_type - (R_PPC_GOT_TLSGD16 & 3)) & 3) 4846 + R_PPC_GOT_TPREL16); 4847 rel->r_info = ELF32_R_INFO (r_symndx, r_type); 4848 } 4849 else 4850 { 4851 /* LE */ 4852 insn1 = 0x3c620000; /* addis 3,2,0 */ 4853 insn2 = 0x38630000; /* addi 3,3,0 */ 4854 if (tls_gd == 0) 4855 { 4856 /* Was an LD reloc. */ 4857 r_symndx = 0; 4858 rel->r_addend = htab->elf.tls_sec->vma + DTP_OFFSET; 4859 rel[1].r_addend = htab->elf.tls_sec->vma + DTP_OFFSET; 4860 } 4861 r_type = R_PPC_TPREL16_HA; 4862 rel->r_info = ELF32_R_INFO (r_symndx, r_type); 4863 rel[1].r_info = ELF32_R_INFO (r_symndx, 4864 R_PPC_TPREL16_LO); 4865 rel[1].r_offset += 2; 4866 } 4867 bfd_put_32 (output_bfd, insn1, contents + rel->r_offset - 2); 4868 bfd_put_32 (output_bfd, insn2, contents + offset); 4869 if (tls_gd == 0) 4870 { 4871 /* We changed the symbol on an LD reloc. Start over 4872 in order to get h, sym, sec etc. right. */ 4873 rel--; 4874 continue; 4875 } 4876 } 4877 } 4878 break; 4879 } 4880 4881 /* Handle other relocations that tweak non-addend part of insn. */ 4882 branch_bit = 0; 4883 switch (r_type) 4884 { 4885 default: 4886 break; 4887 4888 /* Branch taken prediction relocations. */ 4889 case R_PPC_ADDR14_BRTAKEN: 4890 case R_PPC_REL14_BRTAKEN: 4891 branch_bit = BRANCH_PREDICT_BIT; 4892 /* Fall thru */ 4893 4894 /* Branch not taken prediction relocations. */ 4895 case R_PPC_ADDR14_BRNTAKEN: 4896 case R_PPC_REL14_BRNTAKEN: 4897 insn = bfd_get_32 (output_bfd, contents + rel->r_offset); 4898 insn &= ~BRANCH_PREDICT_BIT; 4899 insn |= branch_bit; 4900 4901 from = (rel->r_offset 4902 + input_section->output_offset 4903 + input_section->output_section->vma); 4904 4905 /* Invert 'y' bit if not the default. */ 4906 if ((bfd_signed_vma) (relocation + rel->r_addend - from) < 0) 4907 insn ^= BRANCH_PREDICT_BIT; 4908 4909 bfd_put_32 (output_bfd, insn, contents + rel->r_offset); 4910 break; 4911 } 4912 4913 addend = rel->r_addend; 4914 tls_type = 0; 4915 howto = NULL; 4916 if (r_type < R_PPC_max) 4917 howto = ppc_elf_howto_table[r_type]; 4918 switch (r_type) 4919 { 4920 default: 4921 (*_bfd_error_handler) 4922 (_("%s: unknown relocation type %d for symbol %s"), 4923 bfd_archive_filename (input_bfd), (int) r_type, sym_name); 4924 4925 bfd_set_error (bfd_error_bad_value); 4926 ret = FALSE; 4927 continue; 4928 4929 case R_PPC_NONE: 4930 case R_PPC_TLS: 4931 case R_PPC_EMB_MRKREF: 4932 case R_PPC_GNU_VTINHERIT: 4933 case R_PPC_GNU_VTENTRY: 4934 continue; 4935 4936 /* GOT16 relocations. Like an ADDR16 using the symbol's 4937 address in the GOT as relocation value instead of the 4938 symbol's value itself. Also, create a GOT entry for the 4939 symbol and put the symbol value there. */ 4940 case R_PPC_GOT_TLSGD16: 4941 case R_PPC_GOT_TLSGD16_LO: 4942 case R_PPC_GOT_TLSGD16_HI: 4943 case R_PPC_GOT_TLSGD16_HA: 4944 tls_type = TLS_TLS | TLS_GD; 4945 goto dogot; 4946 4947 case R_PPC_GOT_TLSLD16: 4948 case R_PPC_GOT_TLSLD16_LO: 4949 case R_PPC_GOT_TLSLD16_HI: 4950 case R_PPC_GOT_TLSLD16_HA: 4951 tls_type = TLS_TLS | TLS_LD; 4952 goto dogot; 4953 4954 case R_PPC_GOT_TPREL16: 4955 case R_PPC_GOT_TPREL16_LO: 4956 case R_PPC_GOT_TPREL16_HI: 4957 case R_PPC_GOT_TPREL16_HA: 4958 tls_type = TLS_TLS | TLS_TPREL; 4959 goto dogot; 4960 4961 case R_PPC_GOT_DTPREL16: 4962 case R_PPC_GOT_DTPREL16_LO: 4963 case R_PPC_GOT_DTPREL16_HI: 4964 case R_PPC_GOT_DTPREL16_HA: 4965 tls_type = TLS_TLS | TLS_DTPREL; 4966 goto dogot; 4967 4968 case R_PPC_GOT16: 4969 case R_PPC_GOT16_LO: 4970 case R_PPC_GOT16_HI: 4971 case R_PPC_GOT16_HA: 4972 dogot: 4973 { 4974 /* Relocation is to the entry for this symbol in the global 4975 offset table. */ 4976 bfd_vma off; 4977 bfd_vma *offp; 4978 unsigned long indx; 4979 4980 if (htab->got == NULL) 4981 abort (); 4982 4983 indx = 0; 4984 if (tls_type == (TLS_TLS | TLS_LD) 4985 && (h == NULL 4986 || !(h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC))) 4987 offp = &htab->tlsld_got.offset; 4988 else if (h != NULL) 4989 { 4990 bfd_boolean dyn; 4991 dyn = htab->elf.dynamic_sections_created; 4992 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h) 4993 || (info->shared 4994 && SYMBOL_REFERENCES_LOCAL (info, h))) 4995 /* This is actually a static link, or it is a 4996 -Bsymbolic link and the symbol is defined 4997 locally, or the symbol was forced to be local 4998 because of a version file. */ 4999 ; 5000 else 5001 { 5002 indx = h->dynindx; 5003 unresolved_reloc = FALSE; 5004 } 5005 offp = &h->got.offset; 5006 } 5007 else 5008 { 5009 if (local_got_offsets == NULL) 5010 abort (); 5011 offp = &local_got_offsets[r_symndx]; 5012 } 5013 5014 /* The offset must always be a multiple of 4. We use the 5015 least significant bit to record whether we have already 5016 processed this entry. */ 5017 off = *offp; 5018 if ((off & 1) != 0) 5019 off &= ~1; 5020 else 5021 { 5022 unsigned int tls_m = (tls_mask 5023 & (TLS_LD | TLS_GD | TLS_DTPREL 5024 | TLS_TPREL | TLS_TPRELGD)); 5025 5026 if (offp == &htab->tlsld_got.offset) 5027 tls_m = TLS_LD; 5028 else if (h == NULL 5029 || !(h->elf_link_hash_flags 5030 & ELF_LINK_HASH_DEF_DYNAMIC)) 5031 tls_m &= ~TLS_LD; 5032 5033 /* We might have multiple got entries for this sym. 5034 Initialize them all. */ 5035 do 5036 { 5037 int tls_ty = 0; 5038 5039 if ((tls_m & TLS_LD) != 0) 5040 { 5041 tls_ty = TLS_TLS | TLS_LD; 5042 tls_m &= ~TLS_LD; 5043 } 5044 else if ((tls_m & TLS_GD) != 0) 5045 { 5046 tls_ty = TLS_TLS | TLS_GD; 5047 tls_m &= ~TLS_GD; 5048 } 5049 else if ((tls_m & TLS_DTPREL) != 0) 5050 { 5051 tls_ty = TLS_TLS | TLS_DTPREL; 5052 tls_m &= ~TLS_DTPREL; 5053 } 5054 else if ((tls_m & (TLS_TPREL | TLS_TPRELGD)) != 0) 5055 { 5056 tls_ty = TLS_TLS | TLS_TPREL; 5057 tls_m = 0; 5058 } 5059 5060 /* Generate relocs for the dynamic linker. */ 5061 if ((info->shared || indx != 0) 5062 && (h == NULL 5063 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT 5064 || h->root.type != bfd_link_hash_undefweak)) 5065 { 5066 outrel.r_offset = (htab->got->output_section->vma 5067 + htab->got->output_offset 5068 + off); 5069 outrel.r_addend = 0; 5070 if (tls_ty & (TLS_LD | TLS_GD)) 5071 { 5072 outrel.r_info = ELF32_R_INFO (indx, R_PPC_DTPMOD32); 5073 if (tls_ty == (TLS_TLS | TLS_GD)) 5074 { 5075 loc = htab->relgot->contents; 5076 loc += (htab->relgot->reloc_count++ 5077 * sizeof (Elf32_External_Rela)); 5078 bfd_elf32_swap_reloca_out (output_bfd, 5079 &outrel, loc); 5080 outrel.r_offset += 4; 5081 outrel.r_info 5082 = ELF32_R_INFO (indx, R_PPC_DTPREL32); 5083 } 5084 } 5085 else if (tls_ty == (TLS_TLS | TLS_DTPREL)) 5086 outrel.r_info = ELF32_R_INFO (indx, R_PPC_DTPREL32); 5087 else if (tls_ty == (TLS_TLS | TLS_TPREL)) 5088 outrel.r_info = ELF32_R_INFO (indx, R_PPC_TPREL32); 5089 else if (indx == 0) 5090 outrel.r_info = ELF32_R_INFO (indx, R_PPC_RELATIVE); 5091 else 5092 outrel.r_info = ELF32_R_INFO (indx, R_PPC_GLOB_DAT); 5093 if (indx == 0) 5094 { 5095 outrel.r_addend += relocation; 5096 if (tls_ty & (TLS_GD | TLS_DTPREL | TLS_TPREL)) 5097 outrel.r_addend -= htab->elf.tls_sec->vma; 5098 } 5099 loc = htab->relgot->contents; 5100 loc += (htab->relgot->reloc_count++ 5101 * sizeof (Elf32_External_Rela)); 5102 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc); 5103 } 5104 5105 /* Init the .got section contents if we're not 5106 emitting a reloc. */ 5107 else 5108 { 5109 bfd_vma value = relocation; 5110 5111 if (tls_ty == (TLS_TLS | TLS_LD)) 5112 value = 1; 5113 else if (tls_ty != 0) 5114 { 5115 value -= htab->elf.tls_sec->vma + DTP_OFFSET; 5116 if (tls_ty == (TLS_TLS | TLS_TPREL)) 5117 value += DTP_OFFSET - TP_OFFSET; 5118 5119 if (tls_ty == (TLS_TLS | TLS_GD)) 5120 { 5121 bfd_put_32 (output_bfd, value, 5122 htab->got->contents + off + 4); 5123 value = 1; 5124 } 5125 } 5126 bfd_put_32 (output_bfd, value, 5127 htab->got->contents + off); 5128 } 5129 5130 off += 4; 5131 if (tls_ty & (TLS_LD | TLS_GD)) 5132 off += 4; 5133 } 5134 while (tls_m != 0); 5135 5136 off = *offp; 5137 *offp = off | 1; 5138 } 5139 5140 if (off >= (bfd_vma) -2) 5141 abort (); 5142 5143 if ((tls_type & TLS_TLS) != 0) 5144 { 5145 if (tls_type != (TLS_TLS | TLS_LD)) 5146 { 5147 if ((tls_mask & TLS_LD) != 0 5148 && !(h == NULL 5149 || !(h->elf_link_hash_flags 5150 & ELF_LINK_HASH_DEF_DYNAMIC))) 5151 off += 8; 5152 if (tls_type != (TLS_TLS | TLS_GD)) 5153 { 5154 if ((tls_mask & TLS_GD) != 0) 5155 off += 8; 5156 if (tls_type != (TLS_TLS | TLS_DTPREL)) 5157 { 5158 if ((tls_mask & TLS_DTPREL) != 0) 5159 off += 4; 5160 } 5161 } 5162 } 5163 } 5164 5165 relocation = htab->got->output_offset + off - 4; 5166 5167 /* Addends on got relocations don't make much sense. 5168 x+off@got is actually x@got+off, and since the got is 5169 generated by a hash table traversal, the value in the 5170 got at entry m+n bears little relation to the entry m. */ 5171 if (addend != 0) 5172 (*_bfd_error_handler) 5173 (_("%s(%s+0x%lx): non-zero addend on %s reloc against `%s'"), 5174 bfd_archive_filename (input_bfd), 5175 bfd_get_section_name (input_bfd, input_section), 5176 (long) rel->r_offset, 5177 howto->name, 5178 sym_name); 5179 } 5180 break; 5181 5182 /* Relocations that need no special processing. */ 5183 case R_PPC_LOCAL24PC: 5184 /* It makes no sense to point a local relocation 5185 at a symbol not in this object. */ 5186 if (unresolved_reloc) 5187 { 5188 if (! (*info->callbacks->undefined_symbol) (info, 5189 h->root.root.string, 5190 input_bfd, 5191 input_section, 5192 rel->r_offset, 5193 TRUE)) 5194 return FALSE; 5195 continue; 5196 } 5197 break; 5198 5199 case R_PPC_DTPREL16: 5200 case R_PPC_DTPREL16_LO: 5201 case R_PPC_DTPREL16_HI: 5202 case R_PPC_DTPREL16_HA: 5203 addend -= htab->elf.tls_sec->vma + DTP_OFFSET; 5204 break; 5205 5206 /* Relocations that may need to be propagated if this is a shared 5207 object. */ 5208 case R_PPC_TPREL16: 5209 case R_PPC_TPREL16_LO: 5210 case R_PPC_TPREL16_HI: 5211 case R_PPC_TPREL16_HA: 5212 addend -= htab->elf.tls_sec->vma + TP_OFFSET; 5213 /* The TPREL16 relocs shouldn't really be used in shared 5214 libs as they will result in DT_TEXTREL being set, but 5215 support them anyway. */ 5216 goto dodyn; 5217 5218 case R_PPC_TPREL32: 5219 addend -= htab->elf.tls_sec->vma + TP_OFFSET; 5220 goto dodyn; 5221 5222 case R_PPC_DTPREL32: 5223 addend -= htab->elf.tls_sec->vma + DTP_OFFSET; 5224 goto dodyn; 5225 5226 case R_PPC_DTPMOD32: 5227 relocation = 1; 5228 addend = 0; 5229 goto dodyn; 5230 5231 case R_PPC_REL24: 5232 case R_PPC_REL32: 5233 case R_PPC_REL14: 5234 case R_PPC_REL14_BRTAKEN: 5235 case R_PPC_REL14_BRNTAKEN: 5236 /* If these relocations are not to a named symbol, they can be 5237 handled right here, no need to bother the dynamic linker. */ 5238 if (SYMBOL_REFERENCES_LOCAL (info, h) 5239 || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0) 5240 break; 5241 /* fall through */ 5242 5243 /* Relocations that always need to be propagated if this is a shared 5244 object. */ 5245 case R_PPC_ADDR32: 5246 case R_PPC_ADDR24: 5247 case R_PPC_ADDR16: 5248 case R_PPC_ADDR16_LO: 5249 case R_PPC_ADDR16_HI: 5250 case R_PPC_ADDR16_HA: 5251 case R_PPC_ADDR14: 5252 case R_PPC_ADDR14_BRTAKEN: 5253 case R_PPC_ADDR14_BRNTAKEN: 5254 case R_PPC_UADDR32: 5255 case R_PPC_UADDR16: 5256 /* r_symndx will be zero only for relocs against symbols 5257 from removed linkonce sections, or sections discarded by 5258 a linker script. */ 5259 dodyn: 5260 if (r_symndx == 0) 5261 break; 5262 /* Fall thru. */ 5263 5264 if ((info->shared 5265 && (h == NULL 5266 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT 5267 || h->root.type != bfd_link_hash_undefweak) 5268 && (MUST_BE_DYN_RELOC (r_type) 5269 || !SYMBOL_CALLS_LOCAL (info, h))) 5270 || (ELIMINATE_COPY_RELOCS 5271 && !info->shared 5272 && (input_section->flags & SEC_ALLOC) != 0 5273 && h != NULL 5274 && h->dynindx != -1 5275 && (h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0 5276 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0 5277 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)) 5278 { 5279 int skip; 5280 5281 #ifdef DEBUG 5282 fprintf (stderr, "ppc_elf_relocate_section needs to " 5283 "create relocation for %s\n", 5284 (h && h->root.root.string 5285 ? h->root.root.string : "<unknown>")); 5286 #endif 5287 5288 /* When generating a shared object, these relocations 5289 are copied into the output file to be resolved at run 5290 time. */ 5291 if (sreloc == NULL) 5292 { 5293 const char *name; 5294 5295 name = (bfd_elf_string_from_elf_section 5296 (input_bfd, 5297 elf_elfheader (input_bfd)->e_shstrndx, 5298 elf_section_data (input_section)->rel_hdr.sh_name)); 5299 if (name == NULL) 5300 return FALSE; 5301 5302 BFD_ASSERT (strncmp (name, ".rela", 5) == 0 5303 && strcmp (bfd_get_section_name (input_bfd, 5304 input_section), 5305 name + 5) == 0); 5306 5307 sreloc = bfd_get_section_by_name (htab->elf.dynobj, name); 5308 BFD_ASSERT (sreloc != NULL); 5309 } 5310 5311 skip = 0; 5312 5313 outrel.r_offset = 5314 _bfd_elf_section_offset (output_bfd, info, input_section, 5315 rel->r_offset); 5316 if (outrel.r_offset == (bfd_vma) -1 5317 || outrel.r_offset == (bfd_vma) -2) 5318 skip = (int) outrel.r_offset; 5319 outrel.r_offset += (input_section->output_section->vma 5320 + input_section->output_offset); 5321 5322 if (skip) 5323 memset (&outrel, 0, sizeof outrel); 5324 else if (!SYMBOL_REFERENCES_LOCAL (info, h)) 5325 { 5326 unresolved_reloc = FALSE; 5327 outrel.r_info = ELF32_R_INFO (h->dynindx, r_type); 5328 outrel.r_addend = rel->r_addend; 5329 } 5330 else 5331 { 5332 outrel.r_addend = relocation + rel->r_addend; 5333 5334 if (r_type == R_PPC_ADDR32) 5335 outrel.r_info = ELF32_R_INFO (0, R_PPC_RELATIVE); 5336 else 5337 { 5338 long indx; 5339 5340 if (bfd_is_abs_section (sec)) 5341 indx = 0; 5342 else if (sec == NULL || sec->owner == NULL) 5343 { 5344 bfd_set_error (bfd_error_bad_value); 5345 return FALSE; 5346 } 5347 else 5348 { 5349 asection *osec; 5350 5351 /* We are turning this relocation into one 5352 against a section symbol. It would be 5353 proper to subtract the symbol's value, 5354 osec->vma, from the emitted reloc addend, 5355 but ld.so expects buggy relocs. */ 5356 osec = sec->output_section; 5357 indx = elf_section_data (osec)->dynindx; 5358 BFD_ASSERT (indx > 0); 5359 #ifdef DEBUG 5360 if (indx <= 0) 5361 printf ("indx=%d section=%s flags=%08x name=%s\n", 5362 indx, osec->name, osec->flags, 5363 h->root.root.string); 5364 #endif 5365 } 5366 5367 outrel.r_info = ELF32_R_INFO (indx, r_type); 5368 } 5369 } 5370 5371 loc = sreloc->contents; 5372 loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rela); 5373 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc); 5374 5375 if (skip == -1) 5376 continue; 5377 5378 /* This reloc will be computed at runtime. We clear the memory 5379 so that it contains predictable value. */ 5380 if (! skip 5381 && ((input_section->flags & SEC_ALLOC) != 0 5382 || ELF32_R_TYPE (outrel.r_info) != R_PPC_RELATIVE)) 5383 { 5384 relocation = howto->pc_relative ? outrel.r_offset : 0; 5385 addend = 0; 5386 break; 5387 } 5388 } 5389 break; 5390 5391 case R_PPC_RELAX32PC_PLT: 5392 case R_PPC_RELAX32_PLT: 5393 BFD_ASSERT (h != NULL 5394 && h->plt.offset != (bfd_vma) -1 5395 && htab->plt != NULL); 5396 5397 relocation = (htab->plt->output_section->vma 5398 + htab->plt->output_offset 5399 + h->plt.offset); 5400 if (r_type == R_PPC_RELAX32_PLT) 5401 goto relax32; 5402 /* Fall thru */ 5403 5404 case R_PPC_RELAX32PC: 5405 relocation -= (input_section->output_section->vma 5406 + input_section->output_offset 5407 + rel->r_offset - 4); 5408 /* Fall thru */ 5409 5410 case R_PPC_RELAX32: 5411 relax32: 5412 { 5413 unsigned long t0; 5414 unsigned long t1; 5415 5416 t0 = bfd_get_32 (output_bfd, contents + rel->r_offset); 5417 t1 = bfd_get_32 (output_bfd, contents + rel->r_offset + 4); 5418 5419 /* We're clearing the bits for R_PPC_ADDR16_HA 5420 and R_PPC_ADDR16_LO here. */ 5421 t0 &= ~0xffff; 5422 t1 &= ~0xffff; 5423 5424 /* t0 is HA, t1 is LO */ 5425 relocation += addend; 5426 t0 |= ((relocation + 0x8000) >> 16) & 0xffff; 5427 t1 |= relocation & 0xffff; 5428 5429 bfd_put_32 (output_bfd, t0, contents + rel->r_offset); 5430 bfd_put_32 (output_bfd, t1, contents + rel->r_offset + 4); 5431 } 5432 continue; 5433 5434 /* Indirect .sdata relocation. */ 5435 case R_PPC_EMB_SDAI16: 5436 BFD_ASSERT (htab->sdata != NULL); 5437 relocation 5438 = elf_finish_pointer_linker_section (output_bfd, input_bfd, info, 5439 htab->sdata, h, relocation, 5440 rel, R_PPC_RELATIVE); 5441 break; 5442 5443 /* Indirect .sdata2 relocation. */ 5444 case R_PPC_EMB_SDA2I16: 5445 BFD_ASSERT (htab->sdata2 != NULL); 5446 relocation 5447 = elf_finish_pointer_linker_section (output_bfd, input_bfd, info, 5448 htab->sdata2, h, relocation, 5449 rel, R_PPC_RELATIVE); 5450 break; 5451 5452 /* Handle the TOC16 reloc. We want to use the offset within the .got 5453 section, not the actual VMA. This is appropriate when generating 5454 an embedded ELF object, for which the .got section acts like the 5455 AIX .toc section. */ 5456 case R_PPC_TOC16: /* phony GOT16 relocations */ 5457 BFD_ASSERT (sec != NULL); 5458 BFD_ASSERT (bfd_is_und_section (sec) 5459 || strcmp (bfd_get_section_name (abfd, sec), ".got") == 0 5460 || strcmp (bfd_get_section_name (abfd, sec), ".cgot") == 0) 5461 5462 addend -= sec->output_section->vma + sec->output_offset + 0x8000; 5463 break; 5464 5465 case R_PPC_PLTREL24: 5466 /* Relocation is to the entry for this symbol in the 5467 procedure linkage table. */ 5468 BFD_ASSERT (h != NULL); 5469 5470 if (h->plt.offset == (bfd_vma) -1 5471 || htab->plt == NULL) 5472 { 5473 /* We didn't make a PLT entry for this symbol. This 5474 happens when statically linking PIC code, or when 5475 using -Bsymbolic. */ 5476 break; 5477 } 5478 5479 unresolved_reloc = FALSE; 5480 relocation = (htab->plt->output_section->vma 5481 + htab->plt->output_offset 5482 + h->plt.offset); 5483 break; 5484 5485 /* Relocate against _SDA_BASE_. */ 5486 case R_PPC_SDAREL16: 5487 { 5488 const char *name; 5489 const struct elf_link_hash_entry *sh; 5490 5491 BFD_ASSERT (sec != NULL); 5492 name = bfd_get_section_name (abfd, sec->output_section); 5493 if (! ((strncmp (name, ".sdata", 6) == 0 5494 && (name[6] == 0 || name[6] == '.')) 5495 || (strncmp (name, ".sbss", 5) == 0 5496 && (name[5] == 0 || name[5] == '.')))) 5497 { 5498 (*_bfd_error_handler) 5499 (_("%s: the target (%s) of a %s relocation is " 5500 "in the wrong output section (%s)"), 5501 bfd_archive_filename (input_bfd), 5502 sym_name, 5503 howto->name, 5504 name); 5505 } 5506 sh = htab->sdata->sym_hash; 5507 addend -= (sh->root.u.def.value 5508 + sh->root.u.def.section->output_section->vma 5509 + sh->root.u.def.section->output_offset); 5510 } 5511 break; 5512 5513 /* Relocate against _SDA2_BASE_. */ 5514 case R_PPC_EMB_SDA2REL: 5515 { 5516 const char *name; 5517 const struct elf_link_hash_entry *sh; 5518 5519 BFD_ASSERT (sec != NULL); 5520 name = bfd_get_section_name (abfd, sec->output_section); 5521 if (! (strncmp (name, ".sdata2", 7) == 0 5522 || strncmp (name, ".sbss2", 6) == 0)) 5523 { 5524 (*_bfd_error_handler) 5525 (_("%s: the target (%s) of a %s relocation is " 5526 "in the wrong output section (%s)"), 5527 bfd_archive_filename (input_bfd), 5528 sym_name, 5529 howto->name, 5530 name); 5531 5532 bfd_set_error (bfd_error_bad_value); 5533 ret = FALSE; 5534 continue; 5535 } 5536 sh = htab->sdata2->sym_hash; 5537 addend -= (sh->root.u.def.value 5538 + sh->root.u.def.section->output_section->vma 5539 + sh->root.u.def.section->output_offset); 5540 } 5541 break; 5542 5543 /* Relocate against either _SDA_BASE_, _SDA2_BASE_, or 0. */ 5544 case R_PPC_EMB_SDA21: 5545 case R_PPC_EMB_RELSDA: 5546 { 5547 const char *name; 5548 const struct elf_link_hash_entry *sh; 5549 int reg; 5550 5551 BFD_ASSERT (sec != NULL); 5552 name = bfd_get_section_name (abfd, sec->output_section); 5553 if (((strncmp (name, ".sdata", 6) == 0 5554 && (name[6] == 0 || name[6] == '.')) 5555 || (strncmp (name, ".sbss", 5) == 0 5556 && (name[5] == 0 || name[5] == '.')))) 5557 { 5558 reg = 13; 5559 sh = htab->sdata->sym_hash; 5560 addend -= (sh->root.u.def.value 5561 + sh->root.u.def.section->output_section->vma 5562 + sh->root.u.def.section->output_offset); 5563 } 5564 5565 else if (strncmp (name, ".sdata2", 7) == 0 5566 || strncmp (name, ".sbss2", 6) == 0) 5567 { 5568 reg = 2; 5569 sh = htab->sdata2->sym_hash; 5570 addend -= (sh->root.u.def.value 5571 + sh->root.u.def.section->output_section->vma 5572 + sh->root.u.def.section->output_offset); 5573 } 5574 5575 else if (strcmp (name, ".PPC.EMB.sdata0") == 0 5576 || strcmp (name, ".PPC.EMB.sbss0") == 0) 5577 { 5578 reg = 0; 5579 } 5580 5581 else 5582 { 5583 (*_bfd_error_handler) 5584 (_("%s: the target (%s) of a %s relocation is " 5585 "in the wrong output section (%s)"), 5586 bfd_archive_filename (input_bfd), 5587 sym_name, 5588 howto->name, 5589 name); 5590 5591 bfd_set_error (bfd_error_bad_value); 5592 ret = FALSE; 5593 continue; 5594 } 5595 5596 if (r_type == R_PPC_EMB_SDA21) 5597 { /* fill in register field */ 5598 insn = bfd_get_32 (output_bfd, contents + rel->r_offset); 5599 insn = (insn & ~RA_REGISTER_MASK) | (reg << RA_REGISTER_SHIFT); 5600 bfd_put_32 (output_bfd, insn, contents + rel->r_offset); 5601 } 5602 } 5603 break; 5604 5605 /* Relocate against the beginning of the section. */ 5606 case R_PPC_SECTOFF: 5607 case R_PPC_SECTOFF_LO: 5608 case R_PPC_SECTOFF_HI: 5609 case R_PPC_SECTOFF_HA: 5610 BFD_ASSERT (sec != NULL); 5611 addend -= sec->output_section->vma; 5612 break; 5613 5614 /* Negative relocations. */ 5615 case R_PPC_EMB_NADDR32: 5616 case R_PPC_EMB_NADDR16: 5617 case R_PPC_EMB_NADDR16_LO: 5618 case R_PPC_EMB_NADDR16_HI: 5619 case R_PPC_EMB_NADDR16_HA: 5620 addend -= 2 * relocation; 5621 break; 5622 5623 case R_PPC_COPY: 5624 case R_PPC_GLOB_DAT: 5625 case R_PPC_JMP_SLOT: 5626 case R_PPC_RELATIVE: 5627 case R_PPC_PLT32: 5628 case R_PPC_PLTREL32: 5629 case R_PPC_PLT16_LO: 5630 case R_PPC_PLT16_HI: 5631 case R_PPC_PLT16_HA: 5632 case R_PPC_ADDR30: 5633 case R_PPC_EMB_RELSEC16: 5634 case R_PPC_EMB_RELST_LO: 5635 case R_PPC_EMB_RELST_HI: 5636 case R_PPC_EMB_RELST_HA: 5637 case R_PPC_EMB_BIT_FLD: 5638 (*_bfd_error_handler) 5639 (_("%s: relocation %s is not yet supported for symbol %s."), 5640 bfd_archive_filename (input_bfd), 5641 howto->name, 5642 sym_name); 5643 5644 bfd_set_error (bfd_error_invalid_operation); 5645 ret = FALSE; 5646 continue; 5647 } 5648 5649 /* Do any further special processing. */ 5650 switch (r_type) 5651 { 5652 default: 5653 break; 5654 5655 case R_PPC_ADDR16_HA: 5656 case R_PPC_GOT16_HA: 5657 case R_PPC_PLT16_HA: 5658 case R_PPC_SECTOFF_HA: 5659 case R_PPC_TPREL16_HA: 5660 case R_PPC_DTPREL16_HA: 5661 case R_PPC_GOT_TLSGD16_HA: 5662 case R_PPC_GOT_TLSLD16_HA: 5663 case R_PPC_GOT_TPREL16_HA: 5664 case R_PPC_GOT_DTPREL16_HA: 5665 case R_PPC_EMB_NADDR16_HA: 5666 case R_PPC_EMB_RELST_HA: 5667 /* It's just possible that this symbol is a weak symbol 5668 that's not actually defined anywhere. In that case, 5669 'sec' would be NULL, and we should leave the symbol 5670 alone (it will be set to zero elsewhere in the link). */ 5671 if (sec != NULL) 5672 /* Add 0x10000 if sign bit in 0:15 is set. 5673 Bits 0:15 are not used. */ 5674 addend += 0x8000; 5675 break; 5676 } 5677 5678 #ifdef DEBUG 5679 fprintf (stderr, "\ttype = %s (%d), name = %s, symbol index = %ld, " 5680 "offset = %ld, addend = %ld\n", 5681 howto->name, 5682 (int) r_type, 5683 sym_name, 5684 r_symndx, 5685 (long) rel->r_offset, 5686 (long) addend); 5687 #endif 5688 5689 if (unresolved_reloc 5690 && !((input_section->flags & SEC_DEBUGGING) != 0 5691 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0)) 5692 { 5693 (*_bfd_error_handler) 5694 (_("%s(%s+0x%lx): unresolvable %s relocation against symbol `%s'"), 5695 bfd_archive_filename (input_bfd), 5696 bfd_get_section_name (input_bfd, input_section), 5697 (long) rel->r_offset, 5698 howto->name, 5699 sym_name); 5700 ret = FALSE; 5701 } 5702 5703 r = _bfd_final_link_relocate (howto, 5704 input_bfd, 5705 input_section, 5706 contents, 5707 rel->r_offset, 5708 relocation, 5709 addend); 5710 5711 if (r != bfd_reloc_ok) 5712 { 5713 if (sym_name == NULL) 5714 sym_name = "(null)"; 5715 if (r == bfd_reloc_overflow) 5716 { 5717 if (warned) 5718 continue; 5719 if (h != NULL 5720 && h->root.type == bfd_link_hash_undefweak 5721 && howto->pc_relative) 5722 { 5723 /* Assume this is a call protected by other code that 5724 detect the symbol is undefined. If this is the case, 5725 we can safely ignore the overflow. If not, the 5726 program is hosed anyway, and a little warning isn't 5727 going to help. */ 5728 5729 continue; 5730 } 5731 5732 if (! (*info->callbacks->reloc_overflow) (info, 5733 sym_name, 5734 howto->name, 5735 rel->r_addend, 5736 input_bfd, 5737 input_section, 5738 rel->r_offset)) 5739 return FALSE; 5740 } 5741 else 5742 { 5743 (*_bfd_error_handler) 5744 (_("%s(%s+0x%lx): %s reloc against `%s': error %d"), 5745 bfd_archive_filename (input_bfd), 5746 bfd_get_section_name (input_bfd, input_section), 5747 (long) rel->r_offset, howto->name, sym_name, (int) r); 5748 ret = FALSE; 5749 } 5750 } 5751 } 5752 5753 #ifdef DEBUG 5754 fprintf (stderr, "\n"); 5755 #endif 5756 5757 return ret; 5758 } 5759 5760 static enum elf_reloc_type_class 5761 ppc_elf_reloc_type_class (const Elf_Internal_Rela *rela) 5762 { 5763 switch (ELF32_R_TYPE (rela->r_info)) 5764 { 5765 case R_PPC_RELATIVE: 5766 return reloc_class_relative; 5767 case R_PPC_REL24: 5768 case R_PPC_ADDR24: 5769 case R_PPC_JMP_SLOT: 5770 return reloc_class_plt; 5771 case R_PPC_COPY: 5772 return reloc_class_copy; 5773 default: 5774 return reloc_class_normal; 5775 } 5776 } 5777 5778 /* Support for core dump NOTE sections. */ 5779 5780 static bfd_boolean 5781 ppc_elf_grok_prstatus (bfd *abfd, Elf_Internal_Note *note) 5782 { 5783 int offset; 5784 unsigned int raw_size; 5785 5786 switch (note->descsz) 5787 { 5788 default: 5789 return FALSE; 5790 5791 case 268: /* Linux/PPC. */ 5792 /* pr_cursig */ 5793 elf_tdata (abfd)->core_signal = bfd_get_16 (abfd, note->descdata + 12); 5794 5795 /* pr_pid */ 5796 elf_tdata (abfd)->core_pid = bfd_get_32 (abfd, note->descdata + 24); 5797 5798 /* pr_reg */ 5799 offset = 72; 5800 raw_size = 192; 5801 5802 break; 5803 } 5804 5805 /* Make a ".reg/999" section. */ 5806 return _bfd_elfcore_make_pseudosection (abfd, ".reg", 5807 raw_size, note->descpos + offset); 5808 } 5809 5810 static bfd_boolean 5811 ppc_elf_grok_psinfo (bfd *abfd, Elf_Internal_Note *note) 5812 { 5813 switch (note->descsz) 5814 { 5815 default: 5816 return FALSE; 5817 5818 case 128: /* Linux/PPC elf_prpsinfo. */ 5819 elf_tdata (abfd)->core_program 5820 = _bfd_elfcore_strndup (abfd, note->descdata + 32, 16); 5821 elf_tdata (abfd)->core_command 5822 = _bfd_elfcore_strndup (abfd, note->descdata + 48, 80); 5823 } 5824 5825 /* Note that for some reason, a spurious space is tacked 5826 onto the end of the args in some (at least one anyway) 5827 implementations, so strip it off if it exists. */ 5828 5829 { 5830 char *command = elf_tdata (abfd)->core_command; 5831 int n = strlen (command); 5832 5833 if (0 < n && command[n - 1] == ' ') 5834 command[n - 1] = '\0'; 5835 } 5836 5837 return TRUE; 5838 } 5839 5840 /* Very simple linked list structure for recording apuinfo values. */ 5841 typedef struct apuinfo_list 5842 { 5843 struct apuinfo_list *next; 5844 unsigned long value; 5845 } 5846 apuinfo_list; 5847 5848 static apuinfo_list *head; 5849 5850 5851 static void 5852 apuinfo_list_init (void) 5853 { 5854 head = NULL; 5855 } 5856 5857 static void 5858 apuinfo_list_add (unsigned long value) 5859 { 5860 apuinfo_list *entry = head; 5861 5862 while (entry != NULL) 5863 { 5864 if (entry->value == value) 5865 return; 5866 entry = entry->next; 5867 } 5868 5869 entry = bfd_malloc (sizeof (* entry)); 5870 if (entry == NULL) 5871 return; 5872 5873 entry->value = value; 5874 entry->next = head; 5875 head = entry; 5876 } 5877 5878 static unsigned 5879 apuinfo_list_length (void) 5880 { 5881 apuinfo_list *entry; 5882 unsigned long count; 5883 5884 for (entry = head, count = 0; 5885 entry; 5886 entry = entry->next) 5887 ++ count; 5888 5889 return count; 5890 } 5891 5892 static inline unsigned long 5893 apuinfo_list_element (unsigned long number) 5894 { 5895 apuinfo_list * entry; 5896 5897 for (entry = head; 5898 entry && number --; 5899 entry = entry->next) 5900 ; 5901 5902 return entry ? entry->value : 0; 5903 } 5904 5905 static void 5906 apuinfo_list_finish (void) 5907 { 5908 apuinfo_list *entry; 5909 5910 for (entry = head; entry;) 5911 { 5912 apuinfo_list *next = entry->next; 5913 free (entry); 5914 entry = next; 5915 } 5916 5917 head = NULL; 5918 } 5919 5920 #define APUINFO_SECTION_NAME ".PPC.EMB.apuinfo" 5921 #define APUINFO_LABEL "APUinfo" 5922 5923 /* Scan the input BFDs and create a linked list of 5924 the APUinfo values that will need to be emitted. */ 5925 5926 static void 5927 ppc_elf_begin_write_processing (bfd *abfd, struct bfd_link_info *link_info) 5928 { 5929 bfd *ibfd; 5930 asection *asec; 5931 char *buffer; 5932 unsigned num_input_sections; 5933 bfd_size_type output_section_size; 5934 unsigned i; 5935 unsigned num_entries; 5936 unsigned long offset; 5937 unsigned long length; 5938 const char *error_message = NULL; 5939 5940 if (link_info == NULL) 5941 return; 5942 5943 /* Scan the input bfds, looking for apuinfo sections. */ 5944 num_input_sections = 0; 5945 output_section_size = 0; 5946 5947 for (ibfd = link_info->input_bfds; ibfd; ibfd = ibfd->link_next) 5948 { 5949 asec = bfd_get_section_by_name (ibfd, APUINFO_SECTION_NAME); 5950 if (asec) 5951 { 5952 ++ num_input_sections; 5953 output_section_size += asec->_raw_size; 5954 } 5955 } 5956 5957 /* We need at least one input sections 5958 in order to make merging worthwhile. */ 5959 if (num_input_sections < 1) 5960 return; 5961 5962 /* Just make sure that the output section exists as well. */ 5963 asec = bfd_get_section_by_name (abfd, APUINFO_SECTION_NAME); 5964 if (asec == NULL) 5965 return; 5966 5967 /* Allocate a buffer for the contents of the input sections. */ 5968 buffer = bfd_malloc (output_section_size); 5969 if (buffer == NULL) 5970 return; 5971 5972 offset = 0; 5973 apuinfo_list_init (); 5974 5975 /* Read in the input sections contents. */ 5976 for (ibfd = link_info->input_bfds; ibfd; ibfd = ibfd->link_next) 5977 { 5978 unsigned long datum; 5979 char *ptr; 5980 5981 asec = bfd_get_section_by_name (ibfd, APUINFO_SECTION_NAME); 5982 if (asec == NULL) 5983 continue; 5984 5985 length = asec->_raw_size; 5986 if (length < 24) 5987 { 5988 error_message = _("corrupt or empty %s section in %s"); 5989 goto fail; 5990 } 5991 5992 if (bfd_seek (ibfd, asec->filepos, SEEK_SET) != 0 5993 || (bfd_bread (buffer + offset, length, ibfd) != length)) 5994 { 5995 error_message = _("unable to read in %s section from %s"); 5996 goto fail; 5997 } 5998 5999 /* Process the contents of the section. */ 6000 ptr = buffer + offset; 6001 error_message = _("corrupt %s section in %s"); 6002 6003 /* Verify the contents of the header. Note - we have to 6004 extract the values this way in order to allow for a 6005 host whose endian-ness is different from the target. */ 6006 datum = bfd_get_32 (ibfd, ptr); 6007 if (datum != sizeof APUINFO_LABEL) 6008 goto fail; 6009 6010 datum = bfd_get_32 (ibfd, ptr + 8); 6011 if (datum != 0x2) 6012 goto fail; 6013 6014 if (strcmp (ptr + 12, APUINFO_LABEL) != 0) 6015 goto fail; 6016 6017 /* Get the number of bytes used for apuinfo entries. */ 6018 datum = bfd_get_32 (ibfd, ptr + 4); 6019 if (datum + 20 != length) 6020 goto fail; 6021 6022 /* Make sure that we do not run off the end of the section. */ 6023 if (offset + length > output_section_size) 6024 goto fail; 6025 6026 /* Scan the apuinfo section, building a list of apuinfo numbers. */ 6027 for (i = 0; i < datum; i += 4) 6028 apuinfo_list_add (bfd_get_32 (ibfd, ptr + 20 + i)); 6029 6030 /* Update the offset. */ 6031 offset += length; 6032 } 6033 6034 error_message = NULL; 6035 6036 /* Compute the size of the output section. */ 6037 num_entries = apuinfo_list_length (); 6038 output_section_size = 20 + num_entries * 4; 6039 6040 asec = bfd_get_section_by_name (abfd, APUINFO_SECTION_NAME); 6041 6042 if (! bfd_set_section_size (abfd, asec, output_section_size)) 6043 ibfd = abfd, 6044 error_message = _("warning: unable to set size of %s section in %s"); 6045 6046 fail: 6047 free (buffer); 6048 6049 if (error_message) 6050 (*_bfd_error_handler) (error_message, APUINFO_SECTION_NAME, 6051 bfd_archive_filename (ibfd)); 6052 } 6053 6054 6055 /* Prevent the output section from accumulating the input sections' 6056 contents. We have already stored this in our linked list structure. */ 6057 6058 static bfd_boolean 6059 ppc_elf_write_section (bfd *abfd ATTRIBUTE_UNUSED, 6060 asection *asec, 6061 bfd_byte *contents ATTRIBUTE_UNUSED) 6062 { 6063 return (apuinfo_list_length () 6064 && strcmp (asec->name, APUINFO_SECTION_NAME) == 0); 6065 } 6066 6067 6068 /* Finally we can generate the output section. */ 6069 6070 static void 6071 ppc_elf_final_write_processing (bfd *abfd, bfd_boolean linker ATTRIBUTE_UNUSED) 6072 { 6073 bfd_byte *buffer; 6074 asection *asec; 6075 unsigned i; 6076 unsigned num_entries; 6077 bfd_size_type length; 6078 6079 asec = bfd_get_section_by_name (abfd, APUINFO_SECTION_NAME); 6080 if (asec == NULL) 6081 return; 6082 6083 if (apuinfo_list_length () == 0) 6084 return; 6085 6086 length = asec->_raw_size; 6087 if (length < 20) 6088 return; 6089 6090 buffer = bfd_malloc (length); 6091 if (buffer == NULL) 6092 { 6093 (*_bfd_error_handler) 6094 (_("failed to allocate space for new APUinfo section.")); 6095 return; 6096 } 6097 6098 /* Create the apuinfo header. */ 6099 num_entries = apuinfo_list_length (); 6100 bfd_put_32 (abfd, sizeof APUINFO_LABEL, buffer); 6101 bfd_put_32 (abfd, num_entries * 4, buffer + 4); 6102 bfd_put_32 (abfd, 0x2, buffer + 8); 6103 strcpy (buffer + 12, APUINFO_LABEL); 6104 6105 length = 20; 6106 for (i = 0; i < num_entries; i++) 6107 { 6108 bfd_put_32 (abfd, apuinfo_list_element (i), buffer + length); 6109 length += 4; 6110 } 6111 6112 if (length != asec->_raw_size) 6113 (*_bfd_error_handler) (_("failed to compute new APUinfo section.")); 6114 6115 if (! bfd_set_section_contents (abfd, asec, buffer, (file_ptr) 0, length)) 6116 (*_bfd_error_handler) (_("failed to install new APUinfo section.")); 6117 6118 free (buffer); 6119 6120 apuinfo_list_finish (); 6121 } 6122 6123 /* Add extra PPC sections -- Note, for now, make .sbss2 and 6124 .PPC.EMB.sbss0 a normal section, and not a bss section so 6125 that the linker doesn't crater when trying to make more than 6126 2 sections. */ 6127 6128 static struct bfd_elf_special_section const ppc_elf_special_sections[]= 6129 { 6130 { ".tags", 5, 0, SHT_ORDERED, SHF_ALLOC }, 6131 { ".sdata", 6, -2, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE }, 6132 { ".sbss", 5, -2, SHT_NOBITS, SHF_ALLOC + SHF_WRITE }, 6133 { ".sdata2", 7, -2, SHT_PROGBITS, SHF_ALLOC }, 6134 { ".sbss2", 6, -2, SHT_PROGBITS, SHF_ALLOC }, 6135 { ".PPC.EMB.apuinfo", 16, 0, SHT_NOTE, 0 }, 6136 { ".PPC.EMB.sdata0", 15, 0, SHT_PROGBITS, SHF_ALLOC }, 6137 { ".PPC.EMB.sbss0", 14, 0, SHT_PROGBITS, SHF_ALLOC }, 6138 { ".plt", 4, 0, SHT_NOBITS, SHF_ALLOC + SHF_EXECINSTR }, 6139 { NULL, 0, 0, 0, 0 } 6140 }; 6141 6142 #define TARGET_LITTLE_SYM bfd_elf32_powerpcle_vec 6143 #define TARGET_LITTLE_NAME "elf32-powerpcle" 6144 #define TARGET_BIG_SYM bfd_elf32_powerpc_vec 6145 #define TARGET_BIG_NAME "elf32-powerpc" 6146 #define ELF_ARCH bfd_arch_powerpc 6147 #define ELF_MACHINE_CODE EM_PPC 6148 #ifdef __QNXTARGET__ 6149 #define ELF_MAXPAGESIZE 0x1000 6150 #else 6151 #define ELF_MAXPAGESIZE 0x10000 6152 #endif 6153 #define elf_info_to_howto ppc_elf_info_to_howto 6154 6155 #ifdef EM_CYGNUS_POWERPC 6156 #define ELF_MACHINE_ALT1 EM_CYGNUS_POWERPC 6157 #endif 6158 6159 #ifdef EM_PPC_OLD 6160 #define ELF_MACHINE_ALT2 EM_PPC_OLD 6161 #endif 6162 6163 #define elf_backend_plt_not_loaded 1 6164 #define elf_backend_got_symbol_offset 4 6165 #define elf_backend_can_gc_sections 1 6166 #define elf_backend_can_refcount 1 6167 #define elf_backend_got_header_size 12 6168 #define elf_backend_rela_normal 1 6169 6170 #define bfd_elf32_mkobject ppc_elf_mkobject 6171 #define bfd_elf32_bfd_merge_private_bfd_data ppc_elf_merge_private_bfd_data 6172 #define bfd_elf32_bfd_relax_section ppc_elf_relax_section 6173 #define bfd_elf32_bfd_reloc_type_lookup ppc_elf_reloc_type_lookup 6174 #define bfd_elf32_bfd_set_private_flags ppc_elf_set_private_flags 6175 #define bfd_elf32_bfd_link_hash_table_create ppc_elf_link_hash_table_create 6176 6177 #define elf_backend_object_p ppc_elf_object_p 6178 #define elf_backend_gc_mark_hook ppc_elf_gc_mark_hook 6179 #define elf_backend_gc_sweep_hook ppc_elf_gc_sweep_hook 6180 #define elf_backend_section_from_shdr ppc_elf_section_from_shdr 6181 #define elf_backend_relocate_section ppc_elf_relocate_section 6182 #define elf_backend_create_dynamic_sections ppc_elf_create_dynamic_sections 6183 #define elf_backend_check_relocs ppc_elf_check_relocs 6184 #define elf_backend_copy_indirect_symbol ppc_elf_copy_indirect_symbol 6185 #define elf_backend_adjust_dynamic_symbol ppc_elf_adjust_dynamic_symbol 6186 #define elf_backend_add_symbol_hook ppc_elf_add_symbol_hook 6187 #define elf_backend_size_dynamic_sections ppc_elf_size_dynamic_sections 6188 #define elf_backend_finish_dynamic_symbol ppc_elf_finish_dynamic_symbol 6189 #define elf_backend_finish_dynamic_sections ppc_elf_finish_dynamic_sections 6190 #define elf_backend_fake_sections ppc_elf_fake_sections 6191 #define elf_backend_additional_program_headers ppc_elf_additional_program_headers 6192 #define elf_backend_modify_segment_map ppc_elf_modify_segment_map 6193 #define elf_backend_grok_prstatus ppc_elf_grok_prstatus 6194 #define elf_backend_grok_psinfo ppc_elf_grok_psinfo 6195 #define elf_backend_reloc_type_class ppc_elf_reloc_type_class 6196 #define elf_backend_begin_write_processing ppc_elf_begin_write_processing 6197 #define elf_backend_final_write_processing ppc_elf_final_write_processing 6198 #define elf_backend_write_section ppc_elf_write_section 6199 #define elf_backend_special_sections ppc_elf_special_sections 6200 6201 #include "elf32-target.h" 6202