1 /* PowerPC-specific support for 32-bit ELF
2 Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
3 Free Software Foundation, Inc.
4 Written by Ian Lance Taylor, Cygnus Support.
6 This file is part of BFD, the Binary File Descriptor library.
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.
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.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
22 /* This file is based on a preliminary PowerPC ELF ABI. The
23 information may not match the final PowerPC ELF ABI. It includes
24 suggestions from the in-progress Embedded PowerPC ABI, and that
25 information may also not match. */
33 #include "elf32-ppc.h"
35 /* RELA relocations are used here. */
37 static struct bfd_hash_entry *ppc_elf_link_hash_newfunc
38 PARAMS ((struct bfd_hash_entry *entry, struct bfd_hash_table *table,
40 static struct bfd_link_hash_table *ppc_elf_link_hash_table_create
42 static void ppc_elf_copy_indirect_symbol
43 PARAMS ((struct elf_backend_data *bed, struct elf_link_hash_entry *dir,
44 struct elf_link_hash_entry *ind));
45 static reloc_howto_type *ppc_elf_reloc_type_lookup
46 PARAMS ((bfd *abfd, bfd_reloc_code_real_type code));
47 static void ppc_elf_info_to_howto
48 PARAMS ((bfd *abfd, arelent *cache_ptr, Elf_Internal_Rela *dst));
49 static void ppc_elf_howto_init
51 static int ppc_elf_sort_rela
52 PARAMS ((const PTR, const PTR));
53 static bfd_boolean ppc_elf_relax_section
54 PARAMS ((bfd *, asection *, struct bfd_link_info *, bfd_boolean *));
55 static bfd_reloc_status_type ppc_elf_addr16_ha_reloc
56 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
57 static bfd_reloc_status_type ppc_elf_unhandled_reloc
58 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
59 static bfd_boolean ppc_elf_object_p
61 static bfd_boolean ppc_elf_set_private_flags
62 PARAMS ((bfd *, flagword));
63 static bfd_boolean ppc_elf_merge_private_bfd_data
64 PARAMS ((bfd *, bfd *));
65 static int ppc_elf_additional_program_headers
67 static bfd_boolean ppc_elf_modify_segment_map
69 static bfd_boolean ppc_elf_create_got
70 PARAMS ((bfd *, struct bfd_link_info *));
71 static bfd_boolean ppc_elf_create_dynamic_sections
72 PARAMS ((bfd *, struct bfd_link_info *));
73 static bfd_boolean ppc_elf_section_from_shdr
74 PARAMS ((bfd *, Elf_Internal_Shdr *, const char *));
75 static bfd_boolean ppc_elf_fake_sections
76 PARAMS ((bfd *, Elf_Internal_Shdr *, asection *));
77 static elf_linker_section_t *ppc_elf_create_linker_section
78 PARAMS ((bfd *abfd, struct bfd_link_info *info,
79 enum elf_linker_section_enum));
80 static bfd_boolean update_local_sym_info
81 PARAMS ((bfd *, Elf_Internal_Shdr *, unsigned long, int));
82 static void bad_shared_reloc
83 PARAMS ((bfd *, enum elf_ppc_reloc_type));
84 static bfd_boolean ppc_elf_check_relocs
85 PARAMS ((bfd *, struct bfd_link_info *, asection *,
86 const Elf_Internal_Rela *));
87 static asection * ppc_elf_gc_mark_hook
88 PARAMS ((asection *sec, struct bfd_link_info *info, Elf_Internal_Rela *rel,
89 struct elf_link_hash_entry *h, Elf_Internal_Sym *sym));
90 static bfd_boolean ppc_elf_gc_sweep_hook
91 PARAMS ((bfd *abfd, struct bfd_link_info *info, asection *sec,
92 const Elf_Internal_Rela *relocs));
93 static bfd_boolean ppc_elf_adjust_dynamic_symbol
94 PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *));
95 static bfd_boolean allocate_dynrelocs
96 PARAMS ((struct elf_link_hash_entry *, PTR));
97 static bfd_boolean readonly_dynrelocs
98 PARAMS ((struct elf_link_hash_entry *, PTR));
99 static bfd_boolean ppc_elf_size_dynamic_sections
100 PARAMS ((bfd *, struct bfd_link_info *));
101 static bfd_boolean ppc_elf_relocate_section
102 PARAMS ((bfd *, struct bfd_link_info *info, bfd *, asection *, bfd_byte *,
103 Elf_Internal_Rela *relocs, Elf_Internal_Sym *local_syms,
105 static bfd_boolean ppc_elf_add_symbol_hook
106 PARAMS ((bfd *, struct bfd_link_info *, const Elf_Internal_Sym *,
107 const char **, flagword *, asection **, bfd_vma *));
108 static bfd_boolean ppc_elf_finish_dynamic_symbol
109 PARAMS ((bfd *, struct bfd_link_info *, struct elf_link_hash_entry *,
110 Elf_Internal_Sym *));
111 static bfd_boolean ppc_elf_finish_dynamic_sections
112 PARAMS ((bfd *, struct bfd_link_info *));
113 static enum elf_reloc_type_class ppc_elf_reloc_type_class
114 PARAMS ((const Elf_Internal_Rela *));
115 static bfd_boolean ppc_elf_grok_prstatus
116 PARAMS ((bfd *abfd, Elf_Internal_Note *note));
117 static bfd_boolean ppc_elf_grok_psinfo
118 PARAMS ((bfd *abfd, Elf_Internal_Note *note));
120 #define BRANCH_PREDICT_BIT 0x200000 /* Branch prediction bit for branch taken relocs. */
121 #define RA_REGISTER_MASK 0x001f0000 /* Mask to set RA in memory instructions. */
122 #define RA_REGISTER_SHIFT 16 /* Value to shift register by to insert RA. */
124 /* The name of the dynamic interpreter. This is put in the .interp
127 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
129 /* The size in bytes of an entry in the procedure linkage table. */
130 #define PLT_ENTRY_SIZE 12
131 /* The initial size of the plt reserved for the dynamic linker. */
132 #define PLT_INITIAL_ENTRY_SIZE 72
133 /* The size of the gap between entries in the PLT. */
134 #define PLT_SLOT_SIZE 8
135 /* The number of single-slot PLT entries (the rest use two slots). */
136 #define PLT_NUM_SINGLE_ENTRIES 8192
138 /* Some nop instructions. */
139 #define NOP 0x60000000
140 #define CROR_151515 0x4def7b82
141 #define CROR_313131 0x4ffffb82
143 /* Offset of tp and dtp pointers from start of TLS block. */
144 #define TP_OFFSET 0x7000
145 #define DTP_OFFSET 0x8000
147 /* Will references to this symbol always reference the symbol
149 #define SYMBOL_REFERENCES_LOCAL(INFO, H) \
152 || H->dynindx == -1 \
153 || ELF_ST_VISIBILITY (H->other) == STV_INTERNAL \
154 || ELF_ST_VISIBILITY (H->other) == STV_HIDDEN) \
155 && (H->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) != 0)
157 /* Will _calls_ to this symbol always call the version in this object? */
158 #define SYMBOL_CALLS_LOCAL(INFO, H) \
161 || H->dynindx == -1 \
162 || ELF_ST_VISIBILITY (H->other) != STV_DEFAULT) \
163 && (H->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) != 0)
165 /* The PPC linker needs to keep track of the number of relocs that it
166 decides to copy as dynamic relocs in check_relocs for each symbol.
167 This is so that it can later discard them if they are found to be
168 unnecessary. We store the information in a field extending the
169 regular ELF linker hash table. */
171 struct ppc_elf_dyn_relocs
173 struct ppc_elf_dyn_relocs *next;
175 /* The input section of the reloc. */
178 /* Total number of relocs copied for the input section. */
181 /* Number of pc-relative relocs copied for the input section. */
182 bfd_size_type pc_count;
185 /* PPC ELF linker hash entry. */
187 struct ppc_elf_link_hash_entry
189 struct elf_link_hash_entry elf;
191 /* Track dynamic relocs copied for this symbol. */
192 struct ppc_elf_dyn_relocs *dyn_relocs;
194 /* Contexts in which symbol is used in the GOT (or TOC).
195 TLS_GD .. TLS_EXPLICIT bits are or'd into the mask as the
196 corresponding relocs are encountered during check_relocs.
197 tls_optimize clears TLS_GD .. TLS_TPREL when optimizing to
198 indicate the corresponding GOT entry type is not needed. */
199 #define TLS_GD 1 /* GD reloc. */
200 #define TLS_LD 2 /* LD reloc. */
201 #define TLS_TPREL 4 /* TPREL reloc, => IE. */
202 #define TLS_DTPREL 8 /* DTPREL reloc, => LD. */
203 #define TLS_TLS 16 /* Any TLS reloc. */
204 #define TLS_TPRELGD 32 /* TPREL reloc resulting from GD->IE. */
208 #define ppc_elf_hash_entry(ent) ((struct ppc_elf_link_hash_entry *) (ent))
210 /* PPC ELF linker hash table. */
212 struct ppc_elf_link_hash_table
214 struct elf_link_hash_table elf;
216 /* Short-cuts to get to dynamic linker sections. */
225 elf_linker_section_t *sdata;
226 elf_linker_section_t *sdata2;
228 /* Short-cut to first output tls section. */
231 /* Shortcut to .__tls_get_addr. */
232 struct elf_link_hash_entry *tls_get_addr;
234 /* TLS local dynamic got entry handling. */
236 bfd_signed_vma refcount;
240 /* Small local sym to section mapping cache. */
241 struct sym_sec_cache sym_sec;
244 /* Get the PPC ELF linker hash table from a link_info structure. */
246 #define ppc_elf_hash_table(p) \
247 ((struct ppc_elf_link_hash_table *) (p)->hash)
249 /* Create an entry in a PPC ELF linker hash table. */
251 static struct bfd_hash_entry *
252 ppc_elf_link_hash_newfunc (entry, table, string)
253 struct bfd_hash_entry *entry;
254 struct bfd_hash_table *table;
257 /* Allocate the structure if it has not already been allocated by a
261 entry = bfd_hash_allocate (table,
262 sizeof (struct ppc_elf_link_hash_entry));
267 /* Call the allocation method of the superclass. */
268 entry = _bfd_elf_link_hash_newfunc (entry, table, string);
271 ppc_elf_hash_entry (entry)->dyn_relocs = NULL;
272 ppc_elf_hash_entry (entry)->tls_mask = 0;
278 /* Create a PPC ELF linker hash table. */
280 static struct bfd_link_hash_table *
281 ppc_elf_link_hash_table_create (abfd)
284 struct ppc_elf_link_hash_table *ret;
286 ret = ((struct ppc_elf_link_hash_table *)
287 bfd_malloc (sizeof (struct ppc_elf_link_hash_table)));
291 if (! _bfd_elf_link_hash_table_init (&ret->elf, abfd,
292 ppc_elf_link_hash_newfunc))
309 ret->tls_get_addr = NULL;
310 ret->tlsld_got.refcount = 0;
311 ret->sym_sec.abfd = NULL;
313 return &ret->elf.root;
316 /* Copy the extra info we tack onto an elf_link_hash_entry. */
319 ppc_elf_copy_indirect_symbol (bed, dir, ind)
320 struct elf_backend_data *bed;
321 struct elf_link_hash_entry *dir, *ind;
323 struct ppc_elf_link_hash_entry *edir, *eind;
325 edir = (struct ppc_elf_link_hash_entry *) dir;
326 eind = (struct ppc_elf_link_hash_entry *) ind;
328 if (eind->dyn_relocs != NULL)
330 if (edir->dyn_relocs != NULL)
332 struct ppc_elf_dyn_relocs **pp;
333 struct ppc_elf_dyn_relocs *p;
335 if (ind->root.type == bfd_link_hash_indirect)
338 /* Add reloc counts against the weak sym to the strong sym
339 list. Merge any entries against the same section. */
340 for (pp = &eind->dyn_relocs; (p = *pp) != NULL; )
342 struct ppc_elf_dyn_relocs *q;
344 for (q = edir->dyn_relocs; q != NULL; q = q->next)
345 if (q->sec == p->sec)
347 q->pc_count += p->pc_count;
348 q->count += p->count;
355 *pp = edir->dyn_relocs;
358 edir->dyn_relocs = eind->dyn_relocs;
359 eind->dyn_relocs = NULL;
362 edir->tls_mask |= eind->tls_mask;
364 _bfd_elf_link_hash_copy_indirect (bed, dir, ind);
367 static reloc_howto_type *ppc_elf_howto_table[(int) R_PPC_max];
369 static reloc_howto_type ppc_elf_howto_raw[] = {
370 /* This reloc does nothing. */
371 HOWTO (R_PPC_NONE, /* type */
373 2, /* size (0 = byte, 1 = short, 2 = long) */
375 FALSE, /* pc_relative */
377 complain_overflow_bitfield, /* complain_on_overflow */
378 bfd_elf_generic_reloc, /* special_function */
379 "R_PPC_NONE", /* name */
380 FALSE, /* partial_inplace */
383 FALSE), /* pcrel_offset */
385 /* A standard 32 bit relocation. */
386 HOWTO (R_PPC_ADDR32, /* type */
388 2, /* size (0 = byte, 1 = short, 2 = long) */
390 FALSE, /* pc_relative */
392 complain_overflow_bitfield, /* complain_on_overflow */
393 bfd_elf_generic_reloc, /* special_function */
394 "R_PPC_ADDR32", /* name */
395 FALSE, /* partial_inplace */
397 0xffffffff, /* dst_mask */
398 FALSE), /* pcrel_offset */
400 /* An absolute 26 bit branch; the lower two bits must be zero.
401 FIXME: we don't check that, we just clear them. */
402 HOWTO (R_PPC_ADDR24, /* type */
404 2, /* size (0 = byte, 1 = short, 2 = long) */
406 FALSE, /* pc_relative */
408 complain_overflow_bitfield, /* complain_on_overflow */
409 bfd_elf_generic_reloc, /* special_function */
410 "R_PPC_ADDR24", /* name */
411 FALSE, /* partial_inplace */
413 0x3fffffc, /* dst_mask */
414 FALSE), /* pcrel_offset */
416 /* A standard 16 bit relocation. */
417 HOWTO (R_PPC_ADDR16, /* type */
419 1, /* size (0 = byte, 1 = short, 2 = long) */
421 FALSE, /* pc_relative */
423 complain_overflow_bitfield, /* complain_on_overflow */
424 bfd_elf_generic_reloc, /* special_function */
425 "R_PPC_ADDR16", /* name */
426 FALSE, /* partial_inplace */
428 0xffff, /* dst_mask */
429 FALSE), /* pcrel_offset */
431 /* A 16 bit relocation without overflow. */
432 HOWTO (R_PPC_ADDR16_LO, /* type */
434 1, /* size (0 = byte, 1 = short, 2 = long) */
436 FALSE, /* pc_relative */
438 complain_overflow_dont,/* complain_on_overflow */
439 bfd_elf_generic_reloc, /* special_function */
440 "R_PPC_ADDR16_LO", /* name */
441 FALSE, /* partial_inplace */
443 0xffff, /* dst_mask */
444 FALSE), /* pcrel_offset */
446 /* The high order 16 bits of an address. */
447 HOWTO (R_PPC_ADDR16_HI, /* type */
449 1, /* size (0 = byte, 1 = short, 2 = long) */
451 FALSE, /* pc_relative */
453 complain_overflow_dont, /* complain_on_overflow */
454 bfd_elf_generic_reloc, /* special_function */
455 "R_PPC_ADDR16_HI", /* name */
456 FALSE, /* partial_inplace */
458 0xffff, /* dst_mask */
459 FALSE), /* pcrel_offset */
461 /* The high order 16 bits of an address, plus 1 if the contents of
462 the low 16 bits, treated as a signed number, is negative. */
463 HOWTO (R_PPC_ADDR16_HA, /* type */
465 1, /* size (0 = byte, 1 = short, 2 = long) */
467 FALSE, /* pc_relative */
469 complain_overflow_dont, /* complain_on_overflow */
470 ppc_elf_addr16_ha_reloc, /* special_function */
471 "R_PPC_ADDR16_HA", /* name */
472 FALSE, /* partial_inplace */
474 0xffff, /* dst_mask */
475 FALSE), /* pcrel_offset */
477 /* An absolute 16 bit branch; the lower two bits must be zero.
478 FIXME: we don't check that, we just clear them. */
479 HOWTO (R_PPC_ADDR14, /* type */
481 2, /* size (0 = byte, 1 = short, 2 = long) */
483 FALSE, /* pc_relative */
485 complain_overflow_bitfield, /* complain_on_overflow */
486 bfd_elf_generic_reloc, /* special_function */
487 "R_PPC_ADDR14", /* name */
488 FALSE, /* partial_inplace */
490 0xfffc, /* dst_mask */
491 FALSE), /* pcrel_offset */
493 /* An absolute 16 bit branch, for which bit 10 should be set to
494 indicate that the branch is expected to be taken. The lower two
495 bits must be zero. */
496 HOWTO (R_PPC_ADDR14_BRTAKEN, /* type */
498 2, /* size (0 = byte, 1 = short, 2 = long) */
500 FALSE, /* pc_relative */
502 complain_overflow_bitfield, /* complain_on_overflow */
503 bfd_elf_generic_reloc, /* special_function */
504 "R_PPC_ADDR14_BRTAKEN",/* name */
505 FALSE, /* partial_inplace */
507 0xfffc, /* dst_mask */
508 FALSE), /* pcrel_offset */
510 /* An absolute 16 bit branch, for which bit 10 should be set to
511 indicate that the branch is not expected to be taken. The lower
512 two bits must be zero. */
513 HOWTO (R_PPC_ADDR14_BRNTAKEN, /* type */
515 2, /* size (0 = byte, 1 = short, 2 = long) */
517 FALSE, /* pc_relative */
519 complain_overflow_bitfield, /* complain_on_overflow */
520 bfd_elf_generic_reloc, /* special_function */
521 "R_PPC_ADDR14_BRNTAKEN",/* name */
522 FALSE, /* partial_inplace */
524 0xfffc, /* dst_mask */
525 FALSE), /* pcrel_offset */
527 /* A relative 26 bit branch; the lower two bits must be zero. */
528 HOWTO (R_PPC_REL24, /* type */
530 2, /* size (0 = byte, 1 = short, 2 = long) */
532 TRUE, /* pc_relative */
534 complain_overflow_signed, /* complain_on_overflow */
535 bfd_elf_generic_reloc, /* special_function */
536 "R_PPC_REL24", /* name */
537 FALSE, /* partial_inplace */
539 0x3fffffc, /* dst_mask */
540 TRUE), /* pcrel_offset */
542 /* A relative 16 bit branch; the lower two bits must be zero. */
543 HOWTO (R_PPC_REL14, /* type */
545 2, /* size (0 = byte, 1 = short, 2 = long) */
547 TRUE, /* pc_relative */
549 complain_overflow_signed, /* complain_on_overflow */
550 bfd_elf_generic_reloc, /* special_function */
551 "R_PPC_REL14", /* name */
552 FALSE, /* partial_inplace */
554 0xfffc, /* dst_mask */
555 TRUE), /* pcrel_offset */
557 /* A relative 16 bit branch. Bit 10 should be set to indicate that
558 the branch is expected to be taken. The lower two bits must be
560 HOWTO (R_PPC_REL14_BRTAKEN, /* type */
562 2, /* size (0 = byte, 1 = short, 2 = long) */
564 TRUE, /* pc_relative */
566 complain_overflow_signed, /* complain_on_overflow */
567 bfd_elf_generic_reloc, /* special_function */
568 "R_PPC_REL14_BRTAKEN", /* name */
569 FALSE, /* partial_inplace */
571 0xfffc, /* dst_mask */
572 TRUE), /* pcrel_offset */
574 /* A relative 16 bit branch. Bit 10 should be set to indicate that
575 the branch is not expected to be taken. The lower two bits must
577 HOWTO (R_PPC_REL14_BRNTAKEN, /* type */
579 2, /* size (0 = byte, 1 = short, 2 = long) */
581 TRUE, /* pc_relative */
583 complain_overflow_signed, /* complain_on_overflow */
584 bfd_elf_generic_reloc, /* special_function */
585 "R_PPC_REL14_BRNTAKEN",/* name */
586 FALSE, /* partial_inplace */
588 0xfffc, /* dst_mask */
589 TRUE), /* pcrel_offset */
591 /* Like R_PPC_ADDR16, but referring to the GOT table entry for the
593 HOWTO (R_PPC_GOT16, /* type */
595 1, /* size (0 = byte, 1 = short, 2 = long) */
597 FALSE, /* pc_relative */
599 complain_overflow_signed, /* complain_on_overflow */
600 bfd_elf_generic_reloc, /* special_function */
601 "R_PPC_GOT16", /* name */
602 FALSE, /* partial_inplace */
604 0xffff, /* dst_mask */
605 FALSE), /* pcrel_offset */
607 /* Like R_PPC_ADDR16_LO, but referring to the GOT table entry for
609 HOWTO (R_PPC_GOT16_LO, /* type */
611 1, /* size (0 = byte, 1 = short, 2 = long) */
613 FALSE, /* pc_relative */
615 complain_overflow_dont, /* complain_on_overflow */
616 bfd_elf_generic_reloc, /* special_function */
617 "R_PPC_GOT16_LO", /* name */
618 FALSE, /* partial_inplace */
620 0xffff, /* dst_mask */
621 FALSE), /* pcrel_offset */
623 /* Like R_PPC_ADDR16_HI, but referring to the GOT table entry for
625 HOWTO (R_PPC_GOT16_HI, /* type */
627 1, /* size (0 = byte, 1 = short, 2 = long) */
629 FALSE, /* pc_relative */
631 complain_overflow_bitfield, /* complain_on_overflow */
632 bfd_elf_generic_reloc, /* special_function */
633 "R_PPC_GOT16_HI", /* name */
634 FALSE, /* partial_inplace */
636 0xffff, /* dst_mask */
637 FALSE), /* pcrel_offset */
639 /* Like R_PPC_ADDR16_HA, but referring to the GOT table entry for
641 HOWTO (R_PPC_GOT16_HA, /* type */
643 1, /* size (0 = byte, 1 = short, 2 = long) */
645 FALSE, /* pc_relative */
647 complain_overflow_bitfield, /* complain_on_overflow */
648 ppc_elf_addr16_ha_reloc, /* special_function */
649 "R_PPC_GOT16_HA", /* name */
650 FALSE, /* partial_inplace */
652 0xffff, /* dst_mask */
653 FALSE), /* pcrel_offset */
655 /* Like R_PPC_REL24, but referring to the procedure linkage table
656 entry for the symbol. */
657 HOWTO (R_PPC_PLTREL24, /* type */
659 2, /* size (0 = byte, 1 = short, 2 = long) */
661 TRUE, /* pc_relative */
663 complain_overflow_signed, /* complain_on_overflow */
664 bfd_elf_generic_reloc, /* special_function */
665 "R_PPC_PLTREL24", /* name */
666 FALSE, /* partial_inplace */
668 0x3fffffc, /* dst_mask */
669 TRUE), /* pcrel_offset */
671 /* This is used only by the dynamic linker. The symbol should exist
672 both in the object being run and in some shared library. The
673 dynamic linker copies the data addressed by the symbol from the
674 shared library into the object, because the object being
675 run has to have the data at some particular address. */
676 HOWTO (R_PPC_COPY, /* type */
678 2, /* size (0 = byte, 1 = short, 2 = long) */
680 FALSE, /* pc_relative */
682 complain_overflow_bitfield, /* complain_on_overflow */
683 bfd_elf_generic_reloc, /* special_function */
684 "R_PPC_COPY", /* name */
685 FALSE, /* partial_inplace */
688 FALSE), /* pcrel_offset */
690 /* Like R_PPC_ADDR32, but used when setting global offset table
692 HOWTO (R_PPC_GLOB_DAT, /* type */
694 2, /* size (0 = byte, 1 = short, 2 = long) */
696 FALSE, /* pc_relative */
698 complain_overflow_bitfield, /* complain_on_overflow */
699 bfd_elf_generic_reloc, /* special_function */
700 "R_PPC_GLOB_DAT", /* name */
701 FALSE, /* partial_inplace */
703 0xffffffff, /* dst_mask */
704 FALSE), /* pcrel_offset */
706 /* Marks a procedure linkage table entry for a symbol. */
707 HOWTO (R_PPC_JMP_SLOT, /* type */
709 2, /* size (0 = byte, 1 = short, 2 = long) */
711 FALSE, /* pc_relative */
713 complain_overflow_bitfield, /* complain_on_overflow */
714 bfd_elf_generic_reloc, /* special_function */
715 "R_PPC_JMP_SLOT", /* name */
716 FALSE, /* partial_inplace */
719 FALSE), /* pcrel_offset */
721 /* Used only by the dynamic linker. When the object is run, this
722 longword is set to the load address of the object, plus the
724 HOWTO (R_PPC_RELATIVE, /* type */
726 2, /* size (0 = byte, 1 = short, 2 = long) */
728 FALSE, /* pc_relative */
730 complain_overflow_bitfield, /* complain_on_overflow */
731 bfd_elf_generic_reloc, /* special_function */
732 "R_PPC_RELATIVE", /* name */
733 FALSE, /* partial_inplace */
735 0xffffffff, /* dst_mask */
736 FALSE), /* pcrel_offset */
738 /* Like R_PPC_REL24, but uses the value of the symbol within the
739 object rather than the final value. Normally used for
740 _GLOBAL_OFFSET_TABLE_. */
741 HOWTO (R_PPC_LOCAL24PC, /* type */
743 2, /* size (0 = byte, 1 = short, 2 = long) */
745 TRUE, /* pc_relative */
747 complain_overflow_signed, /* complain_on_overflow */
748 bfd_elf_generic_reloc, /* special_function */
749 "R_PPC_LOCAL24PC", /* name */
750 FALSE, /* partial_inplace */
752 0x3fffffc, /* dst_mask */
753 TRUE), /* pcrel_offset */
755 /* Like R_PPC_ADDR32, but may be unaligned. */
756 HOWTO (R_PPC_UADDR32, /* type */
758 2, /* size (0 = byte, 1 = short, 2 = long) */
760 FALSE, /* pc_relative */
762 complain_overflow_bitfield, /* complain_on_overflow */
763 bfd_elf_generic_reloc, /* special_function */
764 "R_PPC_UADDR32", /* name */
765 FALSE, /* partial_inplace */
767 0xffffffff, /* dst_mask */
768 FALSE), /* pcrel_offset */
770 /* Like R_PPC_ADDR16, but may be unaligned. */
771 HOWTO (R_PPC_UADDR16, /* type */
773 1, /* size (0 = byte, 1 = short, 2 = long) */
775 FALSE, /* pc_relative */
777 complain_overflow_bitfield, /* complain_on_overflow */
778 bfd_elf_generic_reloc, /* special_function */
779 "R_PPC_UADDR16", /* name */
780 FALSE, /* partial_inplace */
782 0xffff, /* dst_mask */
783 FALSE), /* pcrel_offset */
785 /* 32-bit PC relative */
786 HOWTO (R_PPC_REL32, /* type */
788 2, /* size (0 = byte, 1 = short, 2 = long) */
790 TRUE, /* pc_relative */
792 complain_overflow_bitfield, /* complain_on_overflow */
793 bfd_elf_generic_reloc, /* special_function */
794 "R_PPC_REL32", /* name */
795 FALSE, /* partial_inplace */
797 0xffffffff, /* dst_mask */
798 TRUE), /* pcrel_offset */
800 /* 32-bit relocation to the symbol's procedure linkage table.
801 FIXME: not supported. */
802 HOWTO (R_PPC_PLT32, /* type */
804 2, /* size (0 = byte, 1 = short, 2 = long) */
806 FALSE, /* pc_relative */
808 complain_overflow_bitfield, /* complain_on_overflow */
809 bfd_elf_generic_reloc, /* special_function */
810 "R_PPC_PLT32", /* name */
811 FALSE, /* partial_inplace */
814 FALSE), /* pcrel_offset */
816 /* 32-bit PC relative relocation to the symbol's procedure linkage table.
817 FIXME: not supported. */
818 HOWTO (R_PPC_PLTREL32, /* type */
820 2, /* size (0 = byte, 1 = short, 2 = long) */
822 TRUE, /* pc_relative */
824 complain_overflow_bitfield, /* complain_on_overflow */
825 bfd_elf_generic_reloc, /* special_function */
826 "R_PPC_PLTREL32", /* name */
827 FALSE, /* partial_inplace */
830 TRUE), /* pcrel_offset */
832 /* Like R_PPC_ADDR16_LO, but referring to the PLT table entry for
834 HOWTO (R_PPC_PLT16_LO, /* type */
836 1, /* size (0 = byte, 1 = short, 2 = long) */
838 FALSE, /* pc_relative */
840 complain_overflow_dont, /* complain_on_overflow */
841 bfd_elf_generic_reloc, /* special_function */
842 "R_PPC_PLT16_LO", /* name */
843 FALSE, /* partial_inplace */
845 0xffff, /* dst_mask */
846 FALSE), /* pcrel_offset */
848 /* Like R_PPC_ADDR16_HI, but referring to the PLT table entry for
850 HOWTO (R_PPC_PLT16_HI, /* type */
852 1, /* size (0 = byte, 1 = short, 2 = long) */
854 FALSE, /* pc_relative */
856 complain_overflow_bitfield, /* complain_on_overflow */
857 bfd_elf_generic_reloc, /* special_function */
858 "R_PPC_PLT16_HI", /* name */
859 FALSE, /* partial_inplace */
861 0xffff, /* dst_mask */
862 FALSE), /* pcrel_offset */
864 /* Like R_PPC_ADDR16_HA, but referring to the PLT table entry for
866 HOWTO (R_PPC_PLT16_HA, /* type */
868 1, /* size (0 = byte, 1 = short, 2 = long) */
870 FALSE, /* pc_relative */
872 complain_overflow_bitfield, /* complain_on_overflow */
873 ppc_elf_addr16_ha_reloc, /* special_function */
874 "R_PPC_PLT16_HA", /* name */
875 FALSE, /* partial_inplace */
877 0xffff, /* dst_mask */
878 FALSE), /* pcrel_offset */
880 /* A sign-extended 16 bit value relative to _SDA_BASE_, for use with
882 HOWTO (R_PPC_SDAREL16, /* type */
884 1, /* size (0 = byte, 1 = short, 2 = long) */
886 FALSE, /* pc_relative */
888 complain_overflow_signed, /* complain_on_overflow */
889 bfd_elf_generic_reloc, /* special_function */
890 "R_PPC_SDAREL16", /* name */
891 FALSE, /* partial_inplace */
893 0xffff, /* dst_mask */
894 FALSE), /* pcrel_offset */
896 /* 16-bit section relative relocation. */
897 HOWTO (R_PPC_SECTOFF, /* type */
899 1, /* size (0 = byte, 1 = short, 2 = long) */
901 FALSE, /* pc_relative */
903 complain_overflow_bitfield, /* complain_on_overflow */
904 bfd_elf_generic_reloc, /* special_function */
905 "R_PPC_SECTOFF", /* name */
906 FALSE, /* partial_inplace */
908 0xffff, /* dst_mask */
909 FALSE), /* pcrel_offset */
911 /* 16-bit lower half section relative relocation. */
912 HOWTO (R_PPC_SECTOFF_LO, /* type */
914 1, /* size (0 = byte, 1 = short, 2 = long) */
916 FALSE, /* pc_relative */
918 complain_overflow_dont, /* complain_on_overflow */
919 bfd_elf_generic_reloc, /* special_function */
920 "R_PPC_SECTOFF_LO", /* name */
921 FALSE, /* partial_inplace */
923 0xffff, /* dst_mask */
924 FALSE), /* pcrel_offset */
926 /* 16-bit upper half section relative relocation. */
927 HOWTO (R_PPC_SECTOFF_HI, /* type */
929 1, /* size (0 = byte, 1 = short, 2 = long) */
931 FALSE, /* pc_relative */
933 complain_overflow_bitfield, /* complain_on_overflow */
934 bfd_elf_generic_reloc, /* special_function */
935 "R_PPC_SECTOFF_HI", /* name */
936 FALSE, /* partial_inplace */
938 0xffff, /* dst_mask */
939 FALSE), /* pcrel_offset */
941 /* 16-bit upper half adjusted section relative relocation. */
942 HOWTO (R_PPC_SECTOFF_HA, /* type */
944 1, /* size (0 = byte, 1 = short, 2 = long) */
946 FALSE, /* pc_relative */
948 complain_overflow_bitfield, /* complain_on_overflow */
949 ppc_elf_addr16_ha_reloc, /* special_function */
950 "R_PPC_SECTOFF_HA", /* name */
951 FALSE, /* partial_inplace */
953 0xffff, /* dst_mask */
954 FALSE), /* pcrel_offset */
956 /* Marker reloc for TLS. */
959 2, /* size (0 = byte, 1 = short, 2 = long) */
961 FALSE, /* pc_relative */
963 complain_overflow_dont, /* complain_on_overflow */
964 bfd_elf_generic_reloc, /* special_function */
965 "R_PPC_TLS", /* name */
966 FALSE, /* partial_inplace */
969 FALSE), /* pcrel_offset */
971 /* Computes the load module index of the load module that contains the
972 definition of its TLS sym. */
973 HOWTO (R_PPC_DTPMOD32,
975 2, /* size (0 = byte, 1 = short, 2 = long) */
977 FALSE, /* pc_relative */
979 complain_overflow_dont, /* complain_on_overflow */
980 ppc_elf_unhandled_reloc, /* special_function */
981 "R_PPC_DTPMOD32", /* name */
982 FALSE, /* partial_inplace */
984 0xffffffff, /* dst_mask */
985 FALSE), /* pcrel_offset */
987 /* Computes a dtv-relative displacement, the difference between the value
988 of sym+add and the base address of the thread-local storage block that
989 contains the definition of sym, minus 0x8000. */
990 HOWTO (R_PPC_DTPREL32,
992 2, /* size (0 = byte, 1 = short, 2 = long) */
994 FALSE, /* pc_relative */
996 complain_overflow_dont, /* complain_on_overflow */
997 ppc_elf_unhandled_reloc, /* special_function */
998 "R_PPC_DTPREL32", /* name */
999 FALSE, /* partial_inplace */
1001 0xffffffff, /* dst_mask */
1002 FALSE), /* pcrel_offset */
1004 /* A 16 bit dtprel reloc. */
1005 HOWTO (R_PPC_DTPREL16,
1007 1, /* size (0 = byte, 1 = short, 2 = long) */
1009 FALSE, /* pc_relative */
1011 complain_overflow_signed, /* complain_on_overflow */
1012 ppc_elf_unhandled_reloc, /* special_function */
1013 "R_PPC_DTPREL16", /* name */
1014 FALSE, /* partial_inplace */
1016 0xffff, /* dst_mask */
1017 FALSE), /* pcrel_offset */
1019 /* Like DTPREL16, but no overflow. */
1020 HOWTO (R_PPC_DTPREL16_LO,
1022 1, /* size (0 = byte, 1 = short, 2 = long) */
1024 FALSE, /* pc_relative */
1026 complain_overflow_dont, /* complain_on_overflow */
1027 ppc_elf_unhandled_reloc, /* special_function */
1028 "R_PPC_DTPREL16_LO", /* name */
1029 FALSE, /* partial_inplace */
1031 0xffff, /* dst_mask */
1032 FALSE), /* pcrel_offset */
1034 /* Like DTPREL16_LO, but next higher group of 16 bits. */
1035 HOWTO (R_PPC_DTPREL16_HI,
1036 16, /* rightshift */
1037 1, /* size (0 = byte, 1 = short, 2 = long) */
1039 FALSE, /* pc_relative */
1041 complain_overflow_dont, /* complain_on_overflow */
1042 ppc_elf_unhandled_reloc, /* special_function */
1043 "R_PPC_DTPREL16_HI", /* name */
1044 FALSE, /* partial_inplace */
1046 0xffff, /* dst_mask */
1047 FALSE), /* pcrel_offset */
1049 /* Like DTPREL16_HI, but adjust for low 16 bits. */
1050 HOWTO (R_PPC_DTPREL16_HA,
1051 16, /* rightshift */
1052 1, /* size (0 = byte, 1 = short, 2 = long) */
1054 FALSE, /* pc_relative */
1056 complain_overflow_dont, /* complain_on_overflow */
1057 ppc_elf_unhandled_reloc, /* special_function */
1058 "R_PPC_DTPREL16_HA", /* name */
1059 FALSE, /* partial_inplace */
1061 0xffff, /* dst_mask */
1062 FALSE), /* pcrel_offset */
1064 /* Computes a tp-relative displacement, the difference between the value of
1065 sym+add and the value of the thread pointer (r13). */
1066 HOWTO (R_PPC_TPREL32,
1068 2, /* size (0 = byte, 1 = short, 2 = long) */
1070 FALSE, /* pc_relative */
1072 complain_overflow_dont, /* complain_on_overflow */
1073 ppc_elf_unhandled_reloc, /* special_function */
1074 "R_PPC_TPREL32", /* name */
1075 FALSE, /* partial_inplace */
1077 0xffffffff, /* dst_mask */
1078 FALSE), /* pcrel_offset */
1080 /* A 16 bit tprel reloc. */
1081 HOWTO (R_PPC_TPREL16,
1083 1, /* size (0 = byte, 1 = short, 2 = long) */
1085 FALSE, /* pc_relative */
1087 complain_overflow_signed, /* complain_on_overflow */
1088 ppc_elf_unhandled_reloc, /* special_function */
1089 "R_PPC_TPREL16", /* name */
1090 FALSE, /* partial_inplace */
1092 0xffff, /* dst_mask */
1093 FALSE), /* pcrel_offset */
1095 /* Like TPREL16, but no overflow. */
1096 HOWTO (R_PPC_TPREL16_LO,
1098 1, /* size (0 = byte, 1 = short, 2 = long) */
1100 FALSE, /* pc_relative */
1102 complain_overflow_dont, /* complain_on_overflow */
1103 ppc_elf_unhandled_reloc, /* special_function */
1104 "R_PPC_TPREL16_LO", /* name */
1105 FALSE, /* partial_inplace */
1107 0xffff, /* dst_mask */
1108 FALSE), /* pcrel_offset */
1110 /* Like TPREL16_LO, but next higher group of 16 bits. */
1111 HOWTO (R_PPC_TPREL16_HI,
1112 16, /* rightshift */
1113 1, /* size (0 = byte, 1 = short, 2 = long) */
1115 FALSE, /* pc_relative */
1117 complain_overflow_dont, /* complain_on_overflow */
1118 ppc_elf_unhandled_reloc, /* special_function */
1119 "R_PPC_TPREL16_HI", /* name */
1120 FALSE, /* partial_inplace */
1122 0xffff, /* dst_mask */
1123 FALSE), /* pcrel_offset */
1125 /* Like TPREL16_HI, but adjust for low 16 bits. */
1126 HOWTO (R_PPC_TPREL16_HA,
1127 16, /* rightshift */
1128 1, /* size (0 = byte, 1 = short, 2 = long) */
1130 FALSE, /* pc_relative */
1132 complain_overflow_dont, /* complain_on_overflow */
1133 ppc_elf_unhandled_reloc, /* special_function */
1134 "R_PPC_TPREL16_HA", /* name */
1135 FALSE, /* partial_inplace */
1137 0xffff, /* dst_mask */
1138 FALSE), /* pcrel_offset */
1140 /* Allocates two contiguous entries in the GOT to hold a tls_index structure,
1141 with values (sym+add)@dtpmod and (sym+add)@dtprel, and computes the offset
1142 to the first entry. */
1143 HOWTO (R_PPC_GOT_TLSGD16,
1145 1, /* size (0 = byte, 1 = short, 2 = long) */
1147 FALSE, /* pc_relative */
1149 complain_overflow_signed, /* complain_on_overflow */
1150 ppc_elf_unhandled_reloc, /* special_function */
1151 "R_PPC_GOT_TLSGD16", /* name */
1152 FALSE, /* partial_inplace */
1154 0xffff, /* dst_mask */
1155 FALSE), /* pcrel_offset */
1157 /* Like GOT_TLSGD16, but no overflow. */
1158 HOWTO (R_PPC_GOT_TLSGD16_LO,
1160 1, /* size (0 = byte, 1 = short, 2 = long) */
1162 FALSE, /* pc_relative */
1164 complain_overflow_dont, /* complain_on_overflow */
1165 ppc_elf_unhandled_reloc, /* special_function */
1166 "R_PPC_GOT_TLSGD16_LO", /* name */
1167 FALSE, /* partial_inplace */
1169 0xffff, /* dst_mask */
1170 FALSE), /* pcrel_offset */
1172 /* Like GOT_TLSGD16_LO, but next higher group of 16 bits. */
1173 HOWTO (R_PPC_GOT_TLSGD16_HI,
1174 16, /* rightshift */
1175 1, /* size (0 = byte, 1 = short, 2 = long) */
1177 FALSE, /* pc_relative */
1179 complain_overflow_dont, /* complain_on_overflow */
1180 ppc_elf_unhandled_reloc, /* special_function */
1181 "R_PPC_GOT_TLSGD16_HI", /* name */
1182 FALSE, /* partial_inplace */
1184 0xffff, /* dst_mask */
1185 FALSE), /* pcrel_offset */
1187 /* Like GOT_TLSGD16_HI, but adjust for low 16 bits. */
1188 HOWTO (R_PPC_GOT_TLSGD16_HA,
1189 16, /* rightshift */
1190 1, /* size (0 = byte, 1 = short, 2 = long) */
1192 FALSE, /* pc_relative */
1194 complain_overflow_dont, /* complain_on_overflow */
1195 ppc_elf_unhandled_reloc, /* special_function */
1196 "R_PPC_GOT_TLSGD16_HA", /* name */
1197 FALSE, /* partial_inplace */
1199 0xffff, /* dst_mask */
1200 FALSE), /* pcrel_offset */
1202 /* Allocates two contiguous entries in the GOT to hold a tls_index structure,
1203 with values (sym+add)@dtpmod and zero, and computes the offset to the
1205 HOWTO (R_PPC_GOT_TLSLD16,
1207 1, /* size (0 = byte, 1 = short, 2 = long) */
1209 FALSE, /* pc_relative */
1211 complain_overflow_signed, /* complain_on_overflow */
1212 ppc_elf_unhandled_reloc, /* special_function */
1213 "R_PPC_GOT_TLSLD16", /* name */
1214 FALSE, /* partial_inplace */
1216 0xffff, /* dst_mask */
1217 FALSE), /* pcrel_offset */
1219 /* Like GOT_TLSLD16, but no overflow. */
1220 HOWTO (R_PPC_GOT_TLSLD16_LO,
1222 1, /* size (0 = byte, 1 = short, 2 = long) */
1224 FALSE, /* pc_relative */
1226 complain_overflow_dont, /* complain_on_overflow */
1227 ppc_elf_unhandled_reloc, /* special_function */
1228 "R_PPC_GOT_TLSLD16_LO", /* name */
1229 FALSE, /* partial_inplace */
1231 0xffff, /* dst_mask */
1232 FALSE), /* pcrel_offset */
1234 /* Like GOT_TLSLD16_LO, but next higher group of 16 bits. */
1235 HOWTO (R_PPC_GOT_TLSLD16_HI,
1236 16, /* rightshift */
1237 1, /* size (0 = byte, 1 = short, 2 = long) */
1239 FALSE, /* pc_relative */
1241 complain_overflow_dont, /* complain_on_overflow */
1242 ppc_elf_unhandled_reloc, /* special_function */
1243 "R_PPC_GOT_TLSLD16_HI", /* name */
1244 FALSE, /* partial_inplace */
1246 0xffff, /* dst_mask */
1247 FALSE), /* pcrel_offset */
1249 /* Like GOT_TLSLD16_HI, but adjust for low 16 bits. */
1250 HOWTO (R_PPC_GOT_TLSLD16_HA,
1251 16, /* rightshift */
1252 1, /* size (0 = byte, 1 = short, 2 = long) */
1254 FALSE, /* pc_relative */
1256 complain_overflow_dont, /* complain_on_overflow */
1257 ppc_elf_unhandled_reloc, /* special_function */
1258 "R_PPC_GOT_TLSLD16_HA", /* name */
1259 FALSE, /* partial_inplace */
1261 0xffff, /* dst_mask */
1262 FALSE), /* pcrel_offset */
1264 /* Allocates an entry in the GOT with value (sym+add)@dtprel, and computes
1265 the offset to the entry. */
1266 HOWTO (R_PPC_GOT_DTPREL16,
1268 1, /* size (0 = byte, 1 = short, 2 = long) */
1270 FALSE, /* pc_relative */
1272 complain_overflow_signed, /* complain_on_overflow */
1273 ppc_elf_unhandled_reloc, /* special_function */
1274 "R_PPC_GOT_DTPREL16", /* name */
1275 FALSE, /* partial_inplace */
1277 0xffff, /* dst_mask */
1278 FALSE), /* pcrel_offset */
1280 /* Like GOT_DTPREL16, but no overflow. */
1281 HOWTO (R_PPC_GOT_DTPREL16_LO,
1283 1, /* size (0 = byte, 1 = short, 2 = long) */
1285 FALSE, /* pc_relative */
1287 complain_overflow_dont, /* complain_on_overflow */
1288 ppc_elf_unhandled_reloc, /* special_function */
1289 "R_PPC_GOT_DTPREL16_LO", /* name */
1290 FALSE, /* partial_inplace */
1292 0xffff, /* dst_mask */
1293 FALSE), /* pcrel_offset */
1295 /* Like GOT_DTPREL16_LO, but next higher group of 16 bits. */
1296 HOWTO (R_PPC_GOT_DTPREL16_HI,
1297 16, /* rightshift */
1298 1, /* size (0 = byte, 1 = short, 2 = long) */
1300 FALSE, /* pc_relative */
1302 complain_overflow_dont, /* complain_on_overflow */
1303 ppc_elf_unhandled_reloc, /* special_function */
1304 "R_PPC_GOT_DTPREL16_HI", /* name */
1305 FALSE, /* partial_inplace */
1307 0xffff, /* dst_mask */
1308 FALSE), /* pcrel_offset */
1310 /* Like GOT_DTPREL16_HI, but adjust for low 16 bits. */
1311 HOWTO (R_PPC_GOT_DTPREL16_HA,
1312 16, /* rightshift */
1313 1, /* size (0 = byte, 1 = short, 2 = long) */
1315 FALSE, /* pc_relative */
1317 complain_overflow_dont, /* complain_on_overflow */
1318 ppc_elf_unhandled_reloc, /* special_function */
1319 "R_PPC_GOT_DTPREL16_HA", /* name */
1320 FALSE, /* partial_inplace */
1322 0xffff, /* dst_mask */
1323 FALSE), /* pcrel_offset */
1325 /* Allocates an entry in the GOT with value (sym+add)@tprel, and computes the
1326 offset to the entry. */
1327 HOWTO (R_PPC_GOT_TPREL16,
1329 1, /* size (0 = byte, 1 = short, 2 = long) */
1331 FALSE, /* pc_relative */
1333 complain_overflow_signed, /* complain_on_overflow */
1334 ppc_elf_unhandled_reloc, /* special_function */
1335 "R_PPC_GOT_TPREL16", /* name */
1336 FALSE, /* partial_inplace */
1338 0xffff, /* dst_mask */
1339 FALSE), /* pcrel_offset */
1341 /* Like GOT_TPREL16, but no overflow. */
1342 HOWTO (R_PPC_GOT_TPREL16_LO,
1344 1, /* size (0 = byte, 1 = short, 2 = long) */
1346 FALSE, /* pc_relative */
1348 complain_overflow_dont, /* complain_on_overflow */
1349 ppc_elf_unhandled_reloc, /* special_function */
1350 "R_PPC_GOT_TPREL16_LO", /* name */
1351 FALSE, /* partial_inplace */
1353 0xffff, /* dst_mask */
1354 FALSE), /* pcrel_offset */
1356 /* Like GOT_TPREL16_LO, but next higher group of 16 bits. */
1357 HOWTO (R_PPC_GOT_TPREL16_HI,
1358 16, /* rightshift */
1359 1, /* size (0 = byte, 1 = short, 2 = long) */
1361 FALSE, /* pc_relative */
1363 complain_overflow_dont, /* complain_on_overflow */
1364 ppc_elf_unhandled_reloc, /* special_function */
1365 "R_PPC_GOT_TPREL16_HI", /* name */
1366 FALSE, /* partial_inplace */
1368 0xffff, /* dst_mask */
1369 FALSE), /* pcrel_offset */
1371 /* Like GOT_TPREL16_HI, but adjust for low 16 bits. */
1372 HOWTO (R_PPC_GOT_TPREL16_HA,
1373 16, /* rightshift */
1374 1, /* size (0 = byte, 1 = short, 2 = long) */
1376 FALSE, /* pc_relative */
1378 complain_overflow_dont, /* complain_on_overflow */
1379 ppc_elf_unhandled_reloc, /* special_function */
1380 "R_PPC_GOT_TPREL16_HA", /* name */
1381 FALSE, /* partial_inplace */
1383 0xffff, /* dst_mask */
1384 FALSE), /* pcrel_offset */
1386 /* The remaining relocs are from the Embedded ELF ABI, and are not
1387 in the SVR4 ELF ABI. */
1389 /* 32 bit value resulting from the addend minus the symbol. */
1390 HOWTO (R_PPC_EMB_NADDR32, /* type */
1392 2, /* size (0 = byte, 1 = short, 2 = long) */
1394 FALSE, /* pc_relative */
1396 complain_overflow_bitfield, /* complain_on_overflow */
1397 bfd_elf_generic_reloc, /* special_function */
1398 "R_PPC_EMB_NADDR32", /* name */
1399 FALSE, /* partial_inplace */
1401 0xffffffff, /* dst_mask */
1402 FALSE), /* pcrel_offset */
1404 /* 16 bit value resulting from the addend minus the symbol. */
1405 HOWTO (R_PPC_EMB_NADDR16, /* type */
1407 1, /* size (0 = byte, 1 = short, 2 = long) */
1409 FALSE, /* pc_relative */
1411 complain_overflow_bitfield, /* complain_on_overflow */
1412 bfd_elf_generic_reloc, /* special_function */
1413 "R_PPC_EMB_NADDR16", /* name */
1414 FALSE, /* partial_inplace */
1416 0xffff, /* dst_mask */
1417 FALSE), /* pcrel_offset */
1419 /* 16 bit value resulting from the addend minus the symbol. */
1420 HOWTO (R_PPC_EMB_NADDR16_LO, /* type */
1422 1, /* size (0 = byte, 1 = short, 2 = long) */
1424 FALSE, /* pc_relative */
1426 complain_overflow_dont,/* complain_on_overflow */
1427 bfd_elf_generic_reloc, /* special_function */
1428 "R_PPC_EMB_ADDR16_LO", /* name */
1429 FALSE, /* partial_inplace */
1431 0xffff, /* dst_mask */
1432 FALSE), /* pcrel_offset */
1434 /* The high order 16 bits of the addend minus the symbol. */
1435 HOWTO (R_PPC_EMB_NADDR16_HI, /* type */
1436 16, /* rightshift */
1437 1, /* size (0 = byte, 1 = short, 2 = long) */
1439 FALSE, /* pc_relative */
1441 complain_overflow_dont, /* complain_on_overflow */
1442 bfd_elf_generic_reloc, /* special_function */
1443 "R_PPC_EMB_NADDR16_HI", /* name */
1444 FALSE, /* partial_inplace */
1446 0xffff, /* dst_mask */
1447 FALSE), /* pcrel_offset */
1449 /* The high order 16 bits of the result of the addend minus the address,
1450 plus 1 if the contents of the low 16 bits, treated as a signed number,
1452 HOWTO (R_PPC_EMB_NADDR16_HA, /* type */
1453 16, /* rightshift */
1454 1, /* size (0 = byte, 1 = short, 2 = long) */
1456 FALSE, /* pc_relative */
1458 complain_overflow_dont, /* complain_on_overflow */
1459 ppc_elf_addr16_ha_reloc, /* special_function */
1460 "R_PPC_EMB_NADDR16_HA", /* name */
1461 FALSE, /* partial_inplace */
1463 0xffff, /* dst_mask */
1464 FALSE), /* pcrel_offset */
1466 /* 16 bit value resulting from allocating a 4 byte word to hold an
1467 address in the .sdata section, and returning the offset from
1468 _SDA_BASE_ for that relocation. */
1469 HOWTO (R_PPC_EMB_SDAI16, /* type */
1471 1, /* size (0 = byte, 1 = short, 2 = long) */
1473 FALSE, /* pc_relative */
1475 complain_overflow_bitfield, /* complain_on_overflow */
1476 bfd_elf_generic_reloc, /* special_function */
1477 "R_PPC_EMB_SDAI16", /* name */
1478 FALSE, /* partial_inplace */
1480 0xffff, /* dst_mask */
1481 FALSE), /* pcrel_offset */
1483 /* 16 bit value resulting from allocating a 4 byte word to hold an
1484 address in the .sdata2 section, and returning the offset from
1485 _SDA2_BASE_ for that relocation. */
1486 HOWTO (R_PPC_EMB_SDA2I16, /* type */
1488 1, /* size (0 = byte, 1 = short, 2 = long) */
1490 FALSE, /* pc_relative */
1492 complain_overflow_bitfield, /* complain_on_overflow */
1493 bfd_elf_generic_reloc, /* special_function */
1494 "R_PPC_EMB_SDA2I16", /* name */
1495 FALSE, /* partial_inplace */
1497 0xffff, /* dst_mask */
1498 FALSE), /* pcrel_offset */
1500 /* A sign-extended 16 bit value relative to _SDA2_BASE_, for use with
1501 small data items. */
1502 HOWTO (R_PPC_EMB_SDA2REL, /* type */
1504 1, /* size (0 = byte, 1 = short, 2 = long) */
1506 FALSE, /* pc_relative */
1508 complain_overflow_signed, /* complain_on_overflow */
1509 bfd_elf_generic_reloc, /* special_function */
1510 "R_PPC_EMB_SDA2REL", /* name */
1511 FALSE, /* partial_inplace */
1513 0xffff, /* dst_mask */
1514 FALSE), /* pcrel_offset */
1516 /* Relocate against either _SDA_BASE_ or _SDA2_BASE_, filling in the 16 bit
1517 signed offset from the appropriate base, and filling in the register
1518 field with the appropriate register (0, 2, or 13). */
1519 HOWTO (R_PPC_EMB_SDA21, /* type */
1521 2, /* size (0 = byte, 1 = short, 2 = long) */
1523 FALSE, /* pc_relative */
1525 complain_overflow_signed, /* complain_on_overflow */
1526 bfd_elf_generic_reloc, /* special_function */
1527 "R_PPC_EMB_SDA21", /* name */
1528 FALSE, /* partial_inplace */
1530 0xffff, /* dst_mask */
1531 FALSE), /* pcrel_offset */
1533 /* Relocation not handled: R_PPC_EMB_MRKREF */
1534 /* Relocation not handled: R_PPC_EMB_RELSEC16 */
1535 /* Relocation not handled: R_PPC_EMB_RELST_LO */
1536 /* Relocation not handled: R_PPC_EMB_RELST_HI */
1537 /* Relocation not handled: R_PPC_EMB_RELST_HA */
1538 /* Relocation not handled: R_PPC_EMB_BIT_FLD */
1540 /* PC relative relocation against either _SDA_BASE_ or _SDA2_BASE_, filling
1541 in the 16 bit signed offset from the appropriate base, and filling in the
1542 register field with the appropriate register (0, 2, or 13). */
1543 HOWTO (R_PPC_EMB_RELSDA, /* type */
1545 1, /* size (0 = byte, 1 = short, 2 = long) */
1547 TRUE, /* pc_relative */
1549 complain_overflow_signed, /* complain_on_overflow */
1550 bfd_elf_generic_reloc, /* special_function */
1551 "R_PPC_EMB_RELSDA", /* name */
1552 FALSE, /* partial_inplace */
1554 0xffff, /* dst_mask */
1555 FALSE), /* pcrel_offset */
1557 /* GNU extension to record C++ vtable hierarchy. */
1558 HOWTO (R_PPC_GNU_VTINHERIT, /* type */
1560 0, /* size (0 = byte, 1 = short, 2 = long) */
1562 FALSE, /* pc_relative */
1564 complain_overflow_dont, /* complain_on_overflow */
1565 NULL, /* special_function */
1566 "R_PPC_GNU_VTINHERIT", /* name */
1567 FALSE, /* partial_inplace */
1570 FALSE), /* pcrel_offset */
1572 /* GNU extension to record C++ vtable member usage. */
1573 HOWTO (R_PPC_GNU_VTENTRY, /* type */
1575 0, /* size (0 = byte, 1 = short, 2 = long) */
1577 FALSE, /* pc_relative */
1579 complain_overflow_dont, /* complain_on_overflow */
1580 NULL, /* special_function */
1581 "R_PPC_GNU_VTENTRY", /* name */
1582 FALSE, /* partial_inplace */
1585 FALSE), /* pcrel_offset */
1587 /* Phony reloc to handle AIX style TOC entries. */
1588 HOWTO (R_PPC_TOC16, /* type */
1590 1, /* size (0 = byte, 1 = short, 2 = long) */
1592 FALSE, /* pc_relative */
1594 complain_overflow_signed, /* complain_on_overflow */
1595 bfd_elf_generic_reloc, /* special_function */
1596 "R_PPC_TOC16", /* name */
1597 FALSE, /* partial_inplace */
1599 0xffff, /* dst_mask */
1600 FALSE), /* pcrel_offset */
1603 /* Initialize the ppc_elf_howto_table, so that linear accesses can be done. */
1606 ppc_elf_howto_init ()
1608 unsigned int i, type;
1610 for (i = 0; i < sizeof (ppc_elf_howto_raw) / sizeof (ppc_elf_howto_raw[0]); i++)
1612 type = ppc_elf_howto_raw[i].type;
1613 BFD_ASSERT (type < sizeof (ppc_elf_howto_table) / sizeof (ppc_elf_howto_table[0]));
1614 ppc_elf_howto_table[type] = &ppc_elf_howto_raw[i];
1618 /* This function handles relaxing for the PPC with option --mpc860c0[=<n>].
1620 The MPC860, revision C0 or earlier contains a bug in the die.
1621 If all of the following conditions are true, the next instruction
1622 to be executed *may* be treated as a no-op.
1623 1/ A forward branch is executed.
1624 2/ The branch is predicted as not taken.
1625 3/ The branch is taken.
1626 4/ The branch is located in the last 5 words of a page.
1627 (The EOP limit is 5 by default but may be specified as any value from 1-10.)
1629 Our software solution is to detect these problematic branches in a
1630 linker pass and modify them as follows:
1631 1/ Unconditional branches - Since these are always predicted taken,
1632 there is no problem and no action is required.
1633 2/ Conditional backward branches - No problem, no action required.
1634 3/ Conditional forward branches - Ensure that the "inverse prediction
1635 bit" is set (ensure it is predicted taken).
1636 4/ Conditional register branches - Ensure that the "y bit" is set
1637 (ensure it is predicted taken). */
1639 /* Sort sections by address. */
1642 ppc_elf_sort_rela (arg1, arg2)
1646 const Elf_Internal_Rela **rela1 = (const Elf_Internal_Rela**) arg1;
1647 const Elf_Internal_Rela **rela2 = (const Elf_Internal_Rela**) arg2;
1649 /* Sort by offset. */
1650 return ((*rela1)->r_offset - (*rela2)->r_offset);
1654 ppc_elf_relax_section (abfd, isec, link_info, again)
1657 struct bfd_link_info *link_info;
1660 #define PAGESIZE 0x1000
1662 bfd_byte *contents = NULL;
1663 bfd_byte *free_contents = NULL;
1664 Elf_Internal_Rela *internal_relocs = NULL;
1665 Elf_Internal_Rela *free_relocs = NULL;
1666 Elf_Internal_Rela **rela_comb = NULL;
1667 int comb_curr, comb_count;
1669 /* We never have to do this more than once per input section. */
1672 /* If needed, initialize this section's cooked size. */
1673 if (isec->_cooked_size == 0)
1674 isec->_cooked_size = isec->_raw_size;
1676 /* We're only interested in text sections which overlap the
1677 troublesome area at the end of a page. */
1678 if (link_info->mpc860c0 && (isec->flags & SEC_CODE) && isec->_cooked_size)
1680 bfd_vma dot, end_page, end_section;
1681 bfd_boolean section_modified;
1683 /* Get the section contents. */
1684 /* Get cached copy if it exists. */
1685 if (elf_section_data (isec)->this_hdr.contents != NULL)
1686 contents = elf_section_data (isec)->this_hdr.contents;
1689 /* Go get them off disk. */
1690 contents = (bfd_byte *) bfd_malloc (isec->_raw_size);
1691 if (contents == NULL)
1693 free_contents = contents;
1695 if (! bfd_get_section_contents (abfd, isec, contents,
1696 (file_ptr) 0, isec->_raw_size))
1702 if (isec->reloc_count)
1707 /* Get a copy of the native relocations. */
1708 internal_relocs = _bfd_elf32_link_read_relocs (
1709 abfd, isec, (PTR) NULL, (Elf_Internal_Rela *) NULL,
1710 link_info->keep_memory);
1711 if (internal_relocs == NULL)
1713 if (! link_info->keep_memory)
1714 free_relocs = internal_relocs;
1716 /* Setup a faster access method for the reloc info we need. */
1717 amt = isec->reloc_count;
1718 amt *= sizeof (Elf_Internal_Rela*);
1719 rela_comb = (Elf_Internal_Rela**) bfd_malloc (amt);
1720 if (rela_comb == NULL)
1722 for (n = 0; n < isec->reloc_count; ++n)
1726 r_type = ELF32_R_TYPE (internal_relocs[n].r_info);
1727 if (r_type < 0 || r_type >= (int) R_PPC_max)
1730 /* Prologue constants are sometimes present in the ".text"
1731 sections and they can be identified by their associated relocation.
1732 We don't want to process those words and some others which
1733 can also be identified by their relocations. However, not all
1734 conditional branches will have a relocation so we will
1735 only ignore words that 1) have a reloc, and 2) the reloc
1736 is not applicable to a conditional branch.
1737 The array rela_comb is built here for use in the EOP scan loop. */
1740 case R_PPC_ADDR14_BRNTAKEN: /* Absolute, predicted not taken */
1741 case R_PPC_REL14: /* Relative cond. br. */
1742 case R_PPC_REL14_BRNTAKEN: /* Rel. cond. br., predicted not taken */
1743 /* We should check the instruction. */
1746 /* The word is not a conditional branch - ignore it. */
1747 rela_comb[comb_count++] = &internal_relocs[n];
1752 qsort (rela_comb, (size_t) comb_count, sizeof (int), ppc_elf_sort_rela);
1755 /* Enumerate each EOP region that overlaps this section. */
1756 end_section = isec->vma + isec->_cooked_size;
1757 dot = end_page = (isec->vma | (PAGESIZE - 1)) + 1;
1758 dot -= link_info->mpc860c0;
1759 section_modified = FALSE;
1760 if (dot < isec->vma) /* Increment the start position if this section */
1761 dot = isec->vma; /* begins in the middle of its first EOP region. */
1764 dot += PAGESIZE, end_page += PAGESIZE)
1767 /* Check each word in this EOP region. */
1768 for (; dot < end_page; dot += 4)
1770 bfd_vma isec_offset;
1772 bfd_boolean skip, modified;
1774 /* Don't process this word if there is a relocation for it and
1775 the relocation indicates the word is not a conditional branch. */
1777 isec_offset = dot - isec->vma;
1778 for (; comb_curr<comb_count; ++comb_curr)
1782 r_offset = rela_comb[comb_curr]->r_offset;
1783 if (r_offset >= isec_offset)
1785 if (r_offset == isec_offset) skip = TRUE;
1791 /* Check the current word for a problematic conditional branch. */
1792 #define BO0(insn) ((insn) & 0x02000000)
1793 #define BO2(insn) ((insn) & 0x00800000)
1794 #define BO4(insn) ((insn) & 0x00200000)
1795 insn = (unsigned long) bfd_get_32 (abfd, contents + isec_offset);
1797 if ((insn & 0xFc000000) == 0x40000000)
1799 /* Instruction is BCx */
1800 if ((!BO0(insn) || !BO2(insn)) && !BO4(insn))
1803 /* This branch is predicted as "normal".
1804 If this is a forward branch, it is problematic. */
1806 target = insn & 0x0000Fffc; /*extract*/
1807 target = (target ^ 0x8000) - 0x8000; /*sign extend*/
1808 if ((insn & 0x00000002) == 0)
1809 target += dot; /*convert to abs*/
1812 insn |= 0x00200000; /* Set the prediction bit. */
1817 else if ((insn & 0xFc00Fffe) == 0x4c000420)
1819 /* Instruction is BCCTRx. */
1820 if ((!BO0(insn) || !BO2(insn)) && !BO4(insn))
1822 /* This branch is predicted as not-taken.
1823 If this is a forward branch, it is problematic.
1824 Since we can't tell statically if it will branch forward,
1825 always set the prediction bit. */
1826 insn |= 0x00200000; /* Set the prediction bit. */
1830 else if ((insn & 0xFc00Fffe) == 0x4c000020)
1832 /* Instruction is BCLRx */
1833 if ((!BO0(insn) || !BO2(insn)) && !BO4(insn))
1835 /* This branch is predicted as not-taken.
1836 If this is a forward branch, it is problematic.
1837 Since we can't tell statically if it will branch forward,
1838 always set the prediction bit. */
1839 insn |= 0x00200000; /* Set the prediction bit. */
1848 bfd_put_32 (abfd, (bfd_vma) insn, contents + isec_offset);
1849 section_modified = TRUE;
1853 if (section_modified)
1855 elf_section_data (isec)->this_hdr.contents = contents;
1856 free_contents = NULL;
1860 if (rela_comb != NULL)
1866 if (free_relocs != NULL)
1872 if (free_contents != NULL)
1874 if (! link_info->keep_memory)
1875 free (free_contents);
1878 /* Cache the section contents for elf_link_input_bfd. */
1879 elf_section_data (isec)->this_hdr.contents = contents;
1881 free_contents = NULL;
1887 if (rela_comb != NULL)
1889 if (free_relocs != NULL)
1891 if (free_contents != NULL)
1892 free (free_contents);
1896 static reloc_howto_type *
1897 ppc_elf_reloc_type_lookup (abfd, code)
1898 bfd *abfd ATTRIBUTE_UNUSED;
1899 bfd_reloc_code_real_type code;
1901 enum elf_ppc_reloc_type r;
1903 if (!ppc_elf_howto_table[R_PPC_ADDR32])
1904 /* Initialize howto table if needed. */
1905 ppc_elf_howto_init ();
1910 return (reloc_howto_type *) NULL;
1912 case BFD_RELOC_NONE: r = R_PPC_NONE; break;
1913 case BFD_RELOC_32: r = R_PPC_ADDR32; break;
1914 case BFD_RELOC_PPC_BA26: r = R_PPC_ADDR24; break;
1915 case BFD_RELOC_16: r = R_PPC_ADDR16; break;
1916 case BFD_RELOC_LO16: r = R_PPC_ADDR16_LO; break;
1917 case BFD_RELOC_HI16: r = R_PPC_ADDR16_HI; break;
1918 case BFD_RELOC_HI16_S: r = R_PPC_ADDR16_HA; break;
1919 case BFD_RELOC_PPC_BA16: r = R_PPC_ADDR14; break;
1920 case BFD_RELOC_PPC_BA16_BRTAKEN: r = R_PPC_ADDR14_BRTAKEN; break;
1921 case BFD_RELOC_PPC_BA16_BRNTAKEN: r = R_PPC_ADDR14_BRNTAKEN; break;
1922 case BFD_RELOC_PPC_B26: r = R_PPC_REL24; break;
1923 case BFD_RELOC_PPC_B16: r = R_PPC_REL14; break;
1924 case BFD_RELOC_PPC_B16_BRTAKEN: r = R_PPC_REL14_BRTAKEN; break;
1925 case BFD_RELOC_PPC_B16_BRNTAKEN: r = R_PPC_REL14_BRNTAKEN; break;
1926 case BFD_RELOC_16_GOTOFF: r = R_PPC_GOT16; break;
1927 case BFD_RELOC_LO16_GOTOFF: r = R_PPC_GOT16_LO; break;
1928 case BFD_RELOC_HI16_GOTOFF: r = R_PPC_GOT16_HI; break;
1929 case BFD_RELOC_HI16_S_GOTOFF: r = R_PPC_GOT16_HA; break;
1930 case BFD_RELOC_24_PLT_PCREL: r = R_PPC_PLTREL24; break;
1931 case BFD_RELOC_PPC_COPY: r = R_PPC_COPY; break;
1932 case BFD_RELOC_PPC_GLOB_DAT: r = R_PPC_GLOB_DAT; break;
1933 case BFD_RELOC_PPC_LOCAL24PC: r = R_PPC_LOCAL24PC; break;
1934 case BFD_RELOC_32_PCREL: r = R_PPC_REL32; break;
1935 case BFD_RELOC_32_PLTOFF: r = R_PPC_PLT32; break;
1936 case BFD_RELOC_32_PLT_PCREL: r = R_PPC_PLTREL32; break;
1937 case BFD_RELOC_LO16_PLTOFF: r = R_PPC_PLT16_LO; break;
1938 case BFD_RELOC_HI16_PLTOFF: r = R_PPC_PLT16_HI; break;
1939 case BFD_RELOC_HI16_S_PLTOFF: r = R_PPC_PLT16_HA; break;
1940 case BFD_RELOC_GPREL16: r = R_PPC_SDAREL16; break;
1941 case BFD_RELOC_16_BASEREL: r = R_PPC_SECTOFF; break;
1942 case BFD_RELOC_LO16_BASEREL: r = R_PPC_SECTOFF_LO; break;
1943 case BFD_RELOC_HI16_BASEREL: r = R_PPC_SECTOFF_HI; break;
1944 case BFD_RELOC_HI16_S_BASEREL: r = R_PPC_SECTOFF_HA; break;
1945 case BFD_RELOC_CTOR: r = R_PPC_ADDR32; break;
1946 case BFD_RELOC_PPC_TOC16: r = R_PPC_TOC16; break;
1947 case BFD_RELOC_PPC_TLS: r = R_PPC_TLS; break;
1948 case BFD_RELOC_PPC_DTPMOD: r = R_PPC_DTPMOD32; break;
1949 case BFD_RELOC_PPC_TPREL16: r = R_PPC_TPREL16; break;
1950 case BFD_RELOC_PPC_TPREL16_LO: r = R_PPC_TPREL16_LO; break;
1951 case BFD_RELOC_PPC_TPREL16_HI: r = R_PPC_TPREL16_HI; break;
1952 case BFD_RELOC_PPC_TPREL16_HA: r = R_PPC_TPREL16_HA; break;
1953 case BFD_RELOC_PPC_TPREL: r = R_PPC_TPREL32; break;
1954 case BFD_RELOC_PPC_DTPREL16: r = R_PPC_DTPREL16; break;
1955 case BFD_RELOC_PPC_DTPREL16_LO: r = R_PPC_DTPREL16_LO; break;
1956 case BFD_RELOC_PPC_DTPREL16_HI: r = R_PPC_DTPREL16_HI; break;
1957 case BFD_RELOC_PPC_DTPREL16_HA: r = R_PPC_DTPREL16_HA; break;
1958 case BFD_RELOC_PPC_DTPREL: r = R_PPC_DTPREL32; break;
1959 case BFD_RELOC_PPC_GOT_TLSGD16: r = R_PPC_GOT_TLSGD16; break;
1960 case BFD_RELOC_PPC_GOT_TLSGD16_LO: r = R_PPC_GOT_TLSGD16_LO; break;
1961 case BFD_RELOC_PPC_GOT_TLSGD16_HI: r = R_PPC_GOT_TLSGD16_HI; break;
1962 case BFD_RELOC_PPC_GOT_TLSGD16_HA: r = R_PPC_GOT_TLSGD16_HA; break;
1963 case BFD_RELOC_PPC_GOT_TLSLD16: r = R_PPC_GOT_TLSLD16; break;
1964 case BFD_RELOC_PPC_GOT_TLSLD16_LO: r = R_PPC_GOT_TLSLD16_LO; break;
1965 case BFD_RELOC_PPC_GOT_TLSLD16_HI: r = R_PPC_GOT_TLSLD16_HI; break;
1966 case BFD_RELOC_PPC_GOT_TLSLD16_HA: r = R_PPC_GOT_TLSLD16_HA; break;
1967 case BFD_RELOC_PPC_GOT_TPREL16: r = R_PPC_GOT_TPREL16; break;
1968 case BFD_RELOC_PPC_GOT_TPREL16_LO: r = R_PPC_GOT_TPREL16_LO; break;
1969 case BFD_RELOC_PPC_GOT_TPREL16_HI: r = R_PPC_GOT_TPREL16_HI; break;
1970 case BFD_RELOC_PPC_GOT_TPREL16_HA: r = R_PPC_GOT_TPREL16_HA; break;
1971 case BFD_RELOC_PPC_GOT_DTPREL16: r = R_PPC_GOT_DTPREL16; break;
1972 case BFD_RELOC_PPC_GOT_DTPREL16_LO: r = R_PPC_GOT_DTPREL16_LO; break;
1973 case BFD_RELOC_PPC_GOT_DTPREL16_HI: r = R_PPC_GOT_DTPREL16_HI; break;
1974 case BFD_RELOC_PPC_GOT_DTPREL16_HA: r = R_PPC_GOT_DTPREL16_HA; break;
1975 case BFD_RELOC_PPC_EMB_NADDR32: r = R_PPC_EMB_NADDR32; break;
1976 case BFD_RELOC_PPC_EMB_NADDR16: r = R_PPC_EMB_NADDR16; break;
1977 case BFD_RELOC_PPC_EMB_NADDR16_LO: r = R_PPC_EMB_NADDR16_LO; break;
1978 case BFD_RELOC_PPC_EMB_NADDR16_HI: r = R_PPC_EMB_NADDR16_HI; break;
1979 case BFD_RELOC_PPC_EMB_NADDR16_HA: r = R_PPC_EMB_NADDR16_HA; break;
1980 case BFD_RELOC_PPC_EMB_SDAI16: r = R_PPC_EMB_SDAI16; break;
1981 case BFD_RELOC_PPC_EMB_SDA2I16: r = R_PPC_EMB_SDA2I16; break;
1982 case BFD_RELOC_PPC_EMB_SDA2REL: r = R_PPC_EMB_SDA2REL; break;
1983 case BFD_RELOC_PPC_EMB_SDA21: r = R_PPC_EMB_SDA21; break;
1984 case BFD_RELOC_PPC_EMB_MRKREF: r = R_PPC_EMB_MRKREF; break;
1985 case BFD_RELOC_PPC_EMB_RELSEC16: r = R_PPC_EMB_RELSEC16; break;
1986 case BFD_RELOC_PPC_EMB_RELST_LO: r = R_PPC_EMB_RELST_LO; break;
1987 case BFD_RELOC_PPC_EMB_RELST_HI: r = R_PPC_EMB_RELST_HI; break;
1988 case BFD_RELOC_PPC_EMB_RELST_HA: r = R_PPC_EMB_RELST_HA; break;
1989 case BFD_RELOC_PPC_EMB_BIT_FLD: r = R_PPC_EMB_BIT_FLD; break;
1990 case BFD_RELOC_PPC_EMB_RELSDA: r = R_PPC_EMB_RELSDA; break;
1991 case BFD_RELOC_VTABLE_INHERIT: r = R_PPC_GNU_VTINHERIT; break;
1992 case BFD_RELOC_VTABLE_ENTRY: r = R_PPC_GNU_VTENTRY; break;
1995 return ppc_elf_howto_table[(int) r];
1998 /* Set the howto pointer for a PowerPC ELF reloc. */
2001 ppc_elf_info_to_howto (abfd, cache_ptr, dst)
2002 bfd *abfd ATTRIBUTE_UNUSED;
2004 Elf_Internal_Rela *dst;
2006 if (!ppc_elf_howto_table[R_PPC_ADDR32])
2007 /* Initialize howto table if needed. */
2008 ppc_elf_howto_init ();
2010 BFD_ASSERT (ELF32_R_TYPE (dst->r_info) < (unsigned int) R_PPC_max);
2011 cache_ptr->howto = ppc_elf_howto_table[ELF32_R_TYPE (dst->r_info)];
2014 /* Handle the R_PPC_ADDR16_HA reloc. */
2016 static bfd_reloc_status_type
2017 ppc_elf_addr16_ha_reloc (abfd, reloc_entry, symbol, data, input_section,
2018 output_bfd, error_message)
2019 bfd *abfd ATTRIBUTE_UNUSED;
2020 arelent *reloc_entry;
2022 PTR data ATTRIBUTE_UNUSED;
2023 asection *input_section;
2025 char **error_message ATTRIBUTE_UNUSED;
2029 if (output_bfd != NULL)
2031 reloc_entry->address += input_section->output_offset;
2032 return bfd_reloc_ok;
2035 if (reloc_entry->address > input_section->_cooked_size)
2036 return bfd_reloc_outofrange;
2038 if (bfd_is_com_section (symbol->section))
2041 relocation = symbol->value;
2043 relocation += symbol->section->output_section->vma;
2044 relocation += symbol->section->output_offset;
2045 relocation += reloc_entry->addend;
2047 reloc_entry->addend += (relocation & 0x8000) << 1;
2049 return bfd_reloc_continue;
2052 static bfd_reloc_status_type
2053 ppc_elf_unhandled_reloc (abfd, reloc_entry, symbol, data,
2054 input_section, output_bfd, error_message)
2056 arelent *reloc_entry;
2059 asection *input_section;
2061 char **error_message;
2063 /* If this is a relocatable link (output_bfd test tells us), just
2064 call the generic function. Any adjustment will be done at final
2066 if (output_bfd != NULL)
2067 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
2068 input_section, output_bfd, error_message);
2070 if (error_message != NULL)
2072 static char buf[60];
2073 sprintf (buf, "generic linker can't handle %s",
2074 reloc_entry->howto->name);
2075 *error_message = buf;
2077 return bfd_reloc_dangerous;
2080 /* Fix bad default arch selected for a 32 bit input bfd when the
2081 default is 64 bit. */
2084 ppc_elf_object_p (abfd)
2087 if (abfd->arch_info->the_default && abfd->arch_info->bits_per_word == 64)
2089 Elf_Internal_Ehdr *i_ehdr = elf_elfheader (abfd);
2091 if (i_ehdr->e_ident[EI_CLASS] == ELFCLASS32)
2093 /* Relies on arch after 64 bit default being 32 bit default. */
2094 abfd->arch_info = abfd->arch_info->next;
2095 BFD_ASSERT (abfd->arch_info->bits_per_word == 32);
2101 /* Function to set whether a module needs the -mrelocatable bit set. */
2104 ppc_elf_set_private_flags (abfd, flags)
2108 BFD_ASSERT (!elf_flags_init (abfd)
2109 || elf_elfheader (abfd)->e_flags == flags);
2111 elf_elfheader (abfd)->e_flags = flags;
2112 elf_flags_init (abfd) = TRUE;
2116 /* Merge backend specific data from an object file to the output
2117 object file when linking. */
2120 ppc_elf_merge_private_bfd_data (ibfd, obfd)
2128 /* Check if we have the same endianess. */
2129 if (! _bfd_generic_verify_endian_match (ibfd, obfd))
2132 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
2133 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
2136 new_flags = elf_elfheader (ibfd)->e_flags;
2137 old_flags = elf_elfheader (obfd)->e_flags;
2138 if (!elf_flags_init (obfd)) /* First call, no flags set. */
2140 elf_flags_init (obfd) = TRUE;
2141 elf_elfheader (obfd)->e_flags = new_flags;
2144 else if (new_flags == old_flags) /* Compatible flags are ok. */
2147 else /* Incompatible flags. */
2149 /* Warn about -mrelocatable mismatch. Allow -mrelocatable-lib to be linked
2152 if ((new_flags & EF_PPC_RELOCATABLE) != 0
2153 && (old_flags & (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB)) == 0)
2156 (*_bfd_error_handler)
2157 (_("%s: compiled with -mrelocatable and linked with modules compiled normally"),
2158 bfd_archive_filename (ibfd));
2160 else if ((new_flags & (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB)) == 0
2161 && (old_flags & EF_PPC_RELOCATABLE) != 0)
2164 (*_bfd_error_handler)
2165 (_("%s: compiled normally and linked with modules compiled with -mrelocatable"),
2166 bfd_archive_filename (ibfd));
2169 /* The output is -mrelocatable-lib iff both the input files are. */
2170 if (! (new_flags & EF_PPC_RELOCATABLE_LIB))
2171 elf_elfheader (obfd)->e_flags &= ~EF_PPC_RELOCATABLE_LIB;
2173 /* The output is -mrelocatable iff it can't be -mrelocatable-lib,
2174 but each input file is either -mrelocatable or -mrelocatable-lib. */
2175 if (! (elf_elfheader (obfd)->e_flags & EF_PPC_RELOCATABLE_LIB)
2176 && (new_flags & (EF_PPC_RELOCATABLE_LIB | EF_PPC_RELOCATABLE))
2177 && (old_flags & (EF_PPC_RELOCATABLE_LIB | EF_PPC_RELOCATABLE)))
2178 elf_elfheader (obfd)->e_flags |= EF_PPC_RELOCATABLE;
2180 /* Do not warn about eabi vs. V.4 mismatch, just or in the bit if any module uses it. */
2181 elf_elfheader (obfd)->e_flags |= (new_flags & EF_PPC_EMB);
2183 new_flags &= ~ (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB | EF_PPC_EMB);
2184 old_flags &= ~ (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB | EF_PPC_EMB);
2186 /* Warn about any other mismatches. */
2187 if (new_flags != old_flags)
2190 (*_bfd_error_handler)
2191 (_("%s: uses different e_flags (0x%lx) fields than previous modules (0x%lx)"),
2192 bfd_archive_filename (ibfd), (long) new_flags, (long) old_flags);
2197 bfd_set_error (bfd_error_bad_value);
2205 /* Handle a PowerPC specific section when reading an object file. This
2206 is called when elfcode.h finds a section with an unknown type. */
2209 ppc_elf_section_from_shdr (abfd, hdr, name)
2211 Elf_Internal_Shdr *hdr;
2217 if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name))
2220 newsect = hdr->bfd_section;
2221 flags = bfd_get_section_flags (abfd, newsect);
2222 if (hdr->sh_flags & SHF_EXCLUDE)
2223 flags |= SEC_EXCLUDE;
2225 if (hdr->sh_type == SHT_ORDERED)
2226 flags |= SEC_SORT_ENTRIES;
2228 bfd_set_section_flags (abfd, newsect, flags);
2232 /* Set up any other section flags and such that may be necessary. */
2235 ppc_elf_fake_sections (abfd, shdr, asect)
2236 bfd *abfd ATTRIBUTE_UNUSED;
2237 Elf_Internal_Shdr *shdr;
2240 if ((asect->flags & SEC_EXCLUDE) != 0)
2241 shdr->sh_flags |= SHF_EXCLUDE;
2243 if ((asect->flags & SEC_SORT_ENTRIES) != 0)
2244 shdr->sh_type = SHT_ORDERED;
2249 /* Create a special linker section */
2250 static elf_linker_section_t *
2251 ppc_elf_create_linker_section (abfd, info, which)
2253 struct bfd_link_info *info;
2254 enum elf_linker_section_enum which;
2256 bfd *dynobj = elf_hash_table (info)->dynobj;
2257 elf_linker_section_t *lsect;
2259 /* Record the first bfd section that needs the special section. */
2261 dynobj = elf_hash_table (info)->dynobj = abfd;
2263 /* If this is the first time, create the section. */
2264 lsect = elf_linker_section (dynobj, which);
2267 elf_linker_section_t defaults;
2268 static elf_linker_section_t zero_section;
2270 defaults = zero_section;
2271 defaults.which = which;
2272 defaults.hole_written_p = FALSE;
2273 defaults.alignment = 2;
2275 /* Both of these sections are (technically) created by the user
2276 putting data in them, so they shouldn't be marked
2279 The linker creates them so it has somewhere to attach their
2280 respective symbols. In fact, if they were empty it would
2281 be OK to leave the symbol set to 0 (or any random number), because
2282 the appropriate register should never be used. */
2283 defaults.flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS
2289 (*_bfd_error_handler) (_("%s: Unknown special linker type %d"),
2290 bfd_get_filename (abfd),
2293 bfd_set_error (bfd_error_bad_value);
2294 return (elf_linker_section_t *) 0;
2296 case LINKER_SECTION_SDATA: /* .sdata/.sbss section */
2297 defaults.name = ".sdata";
2298 defaults.rel_name = ".rela.sdata";
2299 defaults.bss_name = ".sbss";
2300 defaults.sym_name = "_SDA_BASE_";
2301 defaults.sym_offset = 32768;
2304 case LINKER_SECTION_SDATA2: /* .sdata2/.sbss2 section */
2305 defaults.name = ".sdata2";
2306 defaults.rel_name = ".rela.sdata2";
2307 defaults.bss_name = ".sbss2";
2308 defaults.sym_name = "_SDA2_BASE_";
2309 defaults.sym_offset = 32768;
2310 defaults.flags |= SEC_READONLY;
2314 lsect = _bfd_elf_create_linker_section (abfd, info, which, &defaults);
2320 /* If we have a non-zero sized .sbss2 or .PPC.EMB.sbss0 sections, we
2321 need to bump up the number of section headers. */
2324 ppc_elf_additional_program_headers (abfd)
2332 s = bfd_get_section_by_name (abfd, ".interp");
2336 s = bfd_get_section_by_name (abfd, ".sbss2");
2337 if (s != NULL && (s->flags & SEC_LOAD) != 0 && s->_raw_size > 0)
2340 s = bfd_get_section_by_name (abfd, ".PPC.EMB.sbss0");
2341 if (s != NULL && (s->flags & SEC_LOAD) != 0 && s->_raw_size > 0)
2347 /* Modify the segment map if needed. */
2350 ppc_elf_modify_segment_map (abfd)
2351 bfd *abfd ATTRIBUTE_UNUSED;
2356 /* The powerpc .got has a blrl instruction in it. Mark it executable. */
2359 ppc_elf_create_got (abfd, info)
2361 struct bfd_link_info *info;
2363 struct ppc_elf_link_hash_table *htab;
2367 if (!_bfd_elf_create_got_section (abfd, info))
2370 htab = ppc_elf_hash_table (info);
2371 htab->got = s = bfd_get_section_by_name (abfd, ".got");
2375 flags = (SEC_ALLOC | SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS | SEC_IN_MEMORY
2376 | SEC_LINKER_CREATED);
2377 if (!bfd_set_section_flags (abfd, s, flags))
2380 htab->relgot = bfd_make_section (abfd, ".rela.got");
2382 || ! bfd_set_section_flags (abfd, htab->relgot,
2383 (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS
2384 | SEC_IN_MEMORY | SEC_LINKER_CREATED
2386 || ! bfd_set_section_alignment (abfd, htab->relgot, 2))
2392 /* We have to create .dynsbss and .rela.sbss here so that they get mapped
2393 to output sections (just like _bfd_elf_create_dynamic_sections has
2394 to create .dynbss and .rela.bss). */
2397 ppc_elf_create_dynamic_sections (abfd, info)
2399 struct bfd_link_info *info;
2401 struct ppc_elf_link_hash_table *htab;
2405 if (!ppc_elf_create_got (abfd, info))
2408 if (!_bfd_elf_create_dynamic_sections (abfd, info))
2411 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
2412 | SEC_LINKER_CREATED);
2414 htab = ppc_elf_hash_table (info);
2415 htab->dynbss = bfd_get_section_by_name (abfd, ".dynbss");
2416 htab->dynsbss = s = bfd_make_section (abfd, ".dynsbss");
2418 || ! bfd_set_section_flags (abfd, s, SEC_ALLOC))
2423 htab->relbss = bfd_get_section_by_name (abfd, ".rela.bss");
2424 htab->relsbss = s = bfd_make_section (abfd, ".rela.sbss");
2426 || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
2427 || ! bfd_set_section_alignment (abfd, s, 2))
2431 htab->relplt = bfd_get_section_by_name (abfd, ".rela.plt");
2432 htab->plt = s = bfd_get_section_by_name (abfd, ".plt");
2436 flags = SEC_ALLOC | SEC_CODE | SEC_IN_MEMORY | SEC_LINKER_CREATED;
2437 return bfd_set_section_flags (abfd, s, flags);
2440 /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
2441 copying dynamic variables from a shared lib into an app's dynbss
2442 section, and instead use a dynamic relocation to point into the
2444 #define ELIMINATE_COPY_RELOCS 1
2446 /* Adjust a symbol defined by a dynamic object and referenced by a
2447 regular object. The current definition is in some section of the
2448 dynamic object, but we're not including those sections. We have to
2449 change the definition to something the rest of the link can
2453 ppc_elf_adjust_dynamic_symbol (info, h)
2454 struct bfd_link_info *info;
2455 struct elf_link_hash_entry *h;
2457 struct ppc_elf_link_hash_table *htab;
2459 unsigned int power_of_two;
2462 fprintf (stderr, "ppc_elf_adjust_dynamic_symbol called for %s\n", h->root.root.string);
2465 /* Make sure we know what is going on here. */
2466 htab = ppc_elf_hash_table (info);
2467 BFD_ASSERT (htab->elf.dynobj != NULL
2468 && ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT)
2469 || h->weakdef != NULL
2470 || ((h->elf_link_hash_flags
2471 & ELF_LINK_HASH_DEF_DYNAMIC) != 0
2472 && (h->elf_link_hash_flags
2473 & ELF_LINK_HASH_REF_REGULAR) != 0
2474 && (h->elf_link_hash_flags
2475 & ELF_LINK_HASH_DEF_REGULAR) == 0)));
2477 /* Deal with function syms. */
2478 if (h->type == STT_FUNC
2479 || (h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0)
2481 /* Clear procedure linkage table information for any symbol that
2482 won't need a .plt entry. */
2483 if (! htab->elf.dynamic_sections_created
2484 || SYMBOL_CALLS_LOCAL (info, h)
2485 || h->plt.refcount <= 0)
2487 /* A PLT entry is not required/allowed when:
2489 1. We are not using ld.so; because then the PLT entry
2490 can't be set up, so we can't use one.
2492 2. We know for certain that a call to this symbol
2493 will go to this object.
2495 3. GC has rendered the entry unused. */
2496 h->plt.offset = (bfd_vma) -1;
2497 h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
2502 h->plt.offset = (bfd_vma) -1;
2504 /* If this is a weak symbol, and there is a real definition, the
2505 processor independent code will have arranged for us to see the
2506 real definition first, and we can just use the same value. */
2507 if (h->weakdef != NULL)
2509 BFD_ASSERT (h->weakdef->root.type == bfd_link_hash_defined
2510 || h->weakdef->root.type == bfd_link_hash_defweak);
2511 h->root.u.def.section = h->weakdef->root.u.def.section;
2512 h->root.u.def.value = h->weakdef->root.u.def.value;
2516 /* This is a reference to a symbol defined by a dynamic object which
2517 is not a function. */
2519 /* If we are creating a shared library, we must presume that the
2520 only references to the symbol are via the global offset table.
2521 For such cases we need not do anything here; the relocations will
2522 be handled correctly by relocate_section. */
2526 /* If there are no references to this symbol that do not use the
2527 GOT, we don't need to generate a copy reloc. */
2528 if ((h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0)
2531 if (ELIMINATE_COPY_RELOCS)
2533 struct ppc_elf_dyn_relocs *p;
2534 for (p = ppc_elf_hash_entry (h)->dyn_relocs; p != NULL; p = p->next)
2536 s = p->sec->output_section;
2537 if (s != NULL && (s->flags & SEC_READONLY) != 0)
2541 /* If we didn't find any dynamic relocs in read-only sections, then
2542 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
2545 h->elf_link_hash_flags &= ~ELF_LINK_NON_GOT_REF;
2550 /* We must allocate the symbol in our .dynbss section, which will
2551 become part of the .bss section of the executable. There will be
2552 an entry for this symbol in the .dynsym section. The dynamic
2553 object will contain position independent code, so all references
2554 from the dynamic object to this symbol will go through the global
2555 offset table. The dynamic linker will use the .dynsym entry to
2556 determine the address it must put in the global offset table, so
2557 both the dynamic object and the regular object will refer to the
2558 same memory location for the variable.
2560 Of course, if the symbol is sufficiently small, we must instead
2561 allocate it in .sbss. FIXME: It would be better to do this if and
2562 only if there were actually SDAREL relocs for that symbol. */
2564 if (h->size <= elf_gp_size (htab->elf.dynobj))
2568 BFD_ASSERT (s != NULL);
2570 /* We must generate a R_PPC_COPY reloc to tell the dynamic linker to
2571 copy the initial value out of the dynamic object and into the
2572 runtime process image. We need to remember the offset into the
2573 .rela.bss section we are going to use. */
2574 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
2578 if (h->size <= elf_gp_size (htab->elf.dynobj))
2579 srel = htab->relsbss;
2581 srel = htab->relbss;
2582 BFD_ASSERT (srel != NULL);
2583 srel->_raw_size += sizeof (Elf32_External_Rela);
2584 h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_COPY;
2587 /* We need to figure out the alignment required for this symbol. I
2588 have no idea how ELF linkers handle this. */
2589 power_of_two = bfd_log2 (h->size);
2590 if (power_of_two > 4)
2593 /* Apply the required alignment. */
2594 s->_raw_size = BFD_ALIGN (s->_raw_size,
2595 (bfd_size_type) (1 << power_of_two));
2596 if (power_of_two > bfd_get_section_alignment (htab->elf.dynobj, s))
2598 if (! bfd_set_section_alignment (htab->elf.dynobj, s, power_of_two))
2602 /* Define the symbol as being at this point in the section. */
2603 h->root.u.def.section = s;
2604 h->root.u.def.value = s->_raw_size;
2606 /* Increment the section size to make room for the symbol. */
2607 s->_raw_size += h->size;
2612 /* This is the condition under which finish_dynamic_symbol will be
2613 called from elflink.h. If elflink.h doesn't call our
2614 finish_dynamic_symbol routine, we'll need to do something about
2615 initializing any .plt and .got entries in relocate_section. */
2616 #define WILL_CALL_FINISH_DYNAMIC_SYMBOL(DYN, SHARED, H) \
2619 || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) \
2620 && ((H)->dynindx != -1 \
2621 || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0))
2623 /* Of those relocs that might be copied as dynamic relocs, this macro
2624 selects those that must be copied when linking a shared library,
2625 even when the symbol is local. */
2627 #define MUST_BE_DYN_RELOC(RTYPE) \
2628 ((RTYPE) != R_PPC_REL24 \
2629 && (RTYPE) != R_PPC_REL14 \
2630 && (RTYPE) != R_PPC_REL14_BRTAKEN \
2631 && (RTYPE) != R_PPC_REL14_BRNTAKEN \
2632 && (RTYPE) != R_PPC_REL32)
2634 /* Allocate space in associated reloc sections for dynamic relocs. */
2637 allocate_dynrelocs (h, inf)
2638 struct elf_link_hash_entry *h;
2641 struct bfd_link_info *info = (struct bfd_link_info *) inf;
2642 struct ppc_elf_link_hash_entry *eh;
2643 struct ppc_elf_link_hash_table *htab;
2644 struct ppc_elf_dyn_relocs *p;
2646 if (h->root.type == bfd_link_hash_indirect)
2649 if (h->root.type == bfd_link_hash_warning)
2650 /* When warning symbols are created, they **replace** the "real"
2651 entry in the hash table, thus we never get to see the real
2652 symbol in a hash traversal. So look at it now. */
2653 h = (struct elf_link_hash_entry *) h->root.u.i.link;
2655 htab = ppc_elf_hash_table (info);
2656 if (htab->elf.dynamic_sections_created
2657 && h->plt.refcount > 0)
2659 /* Make sure this symbol is output as a dynamic symbol. */
2660 if (h->dynindx == -1
2661 && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0)
2663 if (! bfd_elf32_link_record_dynamic_symbol (info, h))
2668 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h))
2670 asection *s = htab->plt;
2672 /* If this is the first .plt entry, make room for the special
2674 if (s->_raw_size == 0)
2675 s->_raw_size += PLT_INITIAL_ENTRY_SIZE;
2677 /* The PowerPC PLT is actually composed of two parts, the
2678 first part is 2 words (for a load and a jump), and then
2679 there is a remaining word available at the end. */
2680 h->plt.offset = (PLT_INITIAL_ENTRY_SIZE
2682 * ((s->_raw_size - PLT_INITIAL_ENTRY_SIZE)
2683 / PLT_ENTRY_SIZE)));
2685 /* If this symbol is not defined in a regular file, and we
2686 are not generating a shared library, then set the symbol
2687 to this location in the .plt. This is required to make
2688 function pointers compare as equal between the normal
2689 executable and the shared library. */
2691 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
2693 h->root.u.def.section = s;
2694 h->root.u.def.value = h->plt.offset;
2697 /* Make room for this entry. After the 8192nd entry, room
2698 for two entries is allocated. */
2699 s->_raw_size += PLT_ENTRY_SIZE;
2700 if ((s->_raw_size - PLT_INITIAL_ENTRY_SIZE) / PLT_ENTRY_SIZE
2701 >= PLT_NUM_SINGLE_ENTRIES)
2702 s->_raw_size += PLT_ENTRY_SIZE;
2704 /* We also need to make an entry in the .rela.plt section. */
2705 htab->relplt->_raw_size += sizeof (Elf32_External_Rela);
2709 h->plt.offset = (bfd_vma) -1;
2710 h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
2715 h->plt.offset = (bfd_vma) -1;
2716 h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
2719 eh = (struct ppc_elf_link_hash_entry *) h;
2720 if (eh->elf.got.refcount > 0)
2722 /* Make sure this symbol is output as a dynamic symbol. */
2723 if (eh->elf.dynindx == -1
2724 && (eh->elf.elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0)
2726 if (!bfd_elf32_link_record_dynamic_symbol (info, &eh->elf))
2730 if (eh->tls_mask == (TLS_TLS | TLS_LD)
2731 && !(eh->elf.elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC))
2732 /* If just an LD reloc, we'll just use htab->tlsld_got.offset. */
2733 eh->elf.got.offset = (bfd_vma) -1;
2737 eh->elf.got.offset = htab->got->_raw_size;
2738 if ((eh->tls_mask & TLS_TLS) != 0)
2740 if ((eh->tls_mask & (TLS_GD | TLS_LD)) != 0)
2741 htab->got->_raw_size += 8;
2742 if ((eh->tls_mask & (TLS_TPREL | TLS_TPRELGD)) != 0)
2743 htab->got->_raw_size += 4;
2744 if ((eh->tls_mask & TLS_DTPREL) != 0)
2745 htab->got->_raw_size += 4;
2748 htab->got->_raw_size += 4;
2749 dyn = htab->elf.dynamic_sections_created;
2751 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, &eh->elf))
2753 /* All the entries we allocated need relocs. */
2754 htab->relgot->_raw_size
2755 += ((htab->got->_raw_size - eh->elf.got.offset) / 4
2756 * sizeof (Elf32_External_Rela));
2757 /* Except LD only needs one. */
2758 if ((eh->tls_mask & TLS_LD) != 0)
2759 htab->relgot->_raw_size -= sizeof (Elf32_External_Rela);
2764 eh->elf.got.offset = (bfd_vma) -1;
2766 if (eh->dyn_relocs == NULL)
2769 /* In the shared -Bsymbolic case, discard space allocated for
2770 dynamic pc-relative relocs against symbols which turn out to be
2771 defined in regular objects. For the normal shared case, discard
2772 space for relocs that have become local due to symbol visibility
2776 if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) != 0
2777 && ((h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0
2780 struct ppc_elf_dyn_relocs **pp;
2782 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; )
2784 p->count -= p->pc_count;
2793 else if (ELIMINATE_COPY_RELOCS)
2795 /* For the non-shared case, discard space for relocs against
2796 symbols which turn out to need copy relocs or are not
2799 if ((h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0
2800 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0
2801 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
2803 /* Make sure this symbol is output as a dynamic symbol.
2804 Undefined weak syms won't yet be marked as dynamic. */
2805 if (h->dynindx == -1
2806 && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0)
2808 if (! bfd_elf64_link_record_dynamic_symbol (info, h))
2812 /* If that succeeded, we know we'll be keeping all the
2814 if (h->dynindx != -1)
2818 eh->dyn_relocs = NULL;
2823 /* Finally, allocate space. */
2824 for (p = eh->dyn_relocs; p != NULL; p = p->next)
2826 asection *sreloc = elf_section_data (p->sec)->sreloc;
2827 sreloc->_raw_size += p->count * sizeof (Elf32_External_Rela);
2833 /* Find any dynamic relocs that apply to read-only sections. */
2836 readonly_dynrelocs (h, info)
2837 struct elf_link_hash_entry *h;
2840 struct ppc_elf_dyn_relocs *p;
2842 if (h->root.type == bfd_link_hash_indirect)
2845 if (h->root.type == bfd_link_hash_warning)
2846 h = (struct elf_link_hash_entry *) h->root.u.i.link;
2848 for (p = ppc_elf_hash_entry (h)->dyn_relocs; p != NULL; p = p->next)
2850 asection *s = p->sec->output_section;
2853 && ((s->flags & (SEC_READONLY | SEC_ALLOC))
2854 == (SEC_READONLY | SEC_ALLOC)))
2856 ((struct bfd_link_info *) info)->flags |= DF_TEXTREL;
2858 /* Not an error, just cut short the traversal. */
2865 /* Set the sizes of the dynamic sections. */
2868 ppc_elf_size_dynamic_sections (output_bfd, info)
2869 bfd *output_bfd ATTRIBUTE_UNUSED;
2870 struct bfd_link_info *info;
2872 struct ppc_elf_link_hash_table *htab;
2878 fprintf (stderr, "ppc_elf_size_dynamic_sections called\n");
2881 htab = ppc_elf_hash_table (info);
2882 BFD_ASSERT (htab->elf.dynobj != NULL);
2884 if (elf_hash_table (info)->dynamic_sections_created)
2886 /* Set the contents of the .interp section to the interpreter. */
2889 s = bfd_get_section_by_name (htab->elf.dynobj, ".interp");
2890 BFD_ASSERT (s != NULL);
2891 s->_raw_size = sizeof ELF_DYNAMIC_INTERPRETER;
2892 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
2896 if (htab->tlsld_got.refcount > 0)
2898 htab->tlsld_got.offset = htab->got->_raw_size;
2899 htab->got->_raw_size += 8;
2901 htab->relgot->_raw_size += sizeof (Elf32_External_Rela);
2904 htab->tlsld_got.offset = (bfd_vma) -1;
2906 /* Set up .got offsets for local syms, and space for local dynamic
2908 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
2910 bfd_signed_vma *local_got;
2911 bfd_signed_vma *end_local_got;
2913 bfd_size_type locsymcount;
2914 Elf_Internal_Shdr *symtab_hdr;
2917 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour)
2920 for (s = ibfd->sections; s != NULL; s = s->next)
2922 struct ppc_elf_dyn_relocs *p;
2924 for (p = ((struct ppc_elf_dyn_relocs *)
2925 elf_section_data (s)->local_dynrel);
2929 if (!bfd_is_abs_section (p->sec)
2930 && bfd_is_abs_section (p->sec->output_section))
2932 /* Input section has been discarded, either because
2933 it is a copy of a linkonce section or due to
2934 linker script /DISCARD/, so we'll be discarding
2937 else if (p->count != 0)
2939 elf_section_data (p->sec)->sreloc->_raw_size
2940 += p->count * sizeof (Elf32_External_Rela);
2941 if ((p->sec->output_section->flags
2942 & (SEC_READONLY | SEC_ALLOC))
2943 == (SEC_READONLY | SEC_ALLOC))
2944 info->flags |= DF_TEXTREL;
2949 local_got = elf_local_got_refcounts (ibfd);
2953 symtab_hdr = &elf_tdata (ibfd)->symtab_hdr;
2954 locsymcount = symtab_hdr->sh_info;
2955 end_local_got = local_got + locsymcount;
2956 lgot_masks = (char *) end_local_got;
2958 srel = htab->relgot;
2959 for (; local_got < end_local_got; ++local_got, ++lgot_masks)
2962 if (*lgot_masks == (TLS_TLS | TLS_LD))
2964 /* If just an LD reloc, we'll just use
2965 htab->tlsld_got.offset. */
2966 if (htab->tlsld_got.offset == (bfd_vma) -1)
2968 htab->tlsld_got.offset = s->_raw_size;
2971 srel->_raw_size += sizeof (Elf32_External_Rela);
2973 *local_got = (bfd_vma) -1;
2977 *local_got = s->_raw_size;
2978 if ((*lgot_masks & TLS_TLS) != 0)
2980 if ((*lgot_masks & TLS_GD) != 0)
2982 if ((*lgot_masks & (TLS_TPREL | TLS_TPRELGD)) != 0)
2984 if ((*lgot_masks & TLS_DTPREL) != 0)
2990 srel->_raw_size += ((s->_raw_size - *local_got) / 4
2991 * sizeof (Elf32_External_Rela));
2995 *local_got = (bfd_vma) -1;
2998 /* Allocate space for global sym dynamic relocs. */
2999 elf_link_hash_traverse (elf_hash_table (info), allocate_dynrelocs, info);
3001 /* We've now determined the sizes of the various dynamic sections.
3002 Allocate memory for them. */
3004 for (s = htab->elf.dynobj->sections; s != NULL; s = s->next)
3006 if ((s->flags & SEC_LINKER_CREATED) == 0)
3011 || (htab->sdata != NULL && s == htab->sdata->section)
3012 || (htab->sdata2 != NULL && s == htab->sdata2->section))
3014 /* Strip this section if we don't need it; see the
3017 else if (strncmp (bfd_get_section_name (dynobj, s), ".rela", 5) == 0)
3019 if (s->_raw_size == 0)
3021 /* If we don't need this section, strip it from the
3022 output file. This is mostly to handle .rela.bss and
3023 .rela.plt. We must create both sections in
3024 create_dynamic_sections, because they must be created
3025 before the linker maps input sections to output
3026 sections. The linker does that before
3027 adjust_dynamic_symbol is called, and it is that
3028 function which decides whether anything needs to go
3029 into these sections. */
3033 /* Remember whether there are any relocation sections. */
3036 /* We use the reloc_count field as a counter if we need
3037 to copy relocs into the output file. */
3043 /* It's not one of our sections, so don't allocate space. */
3047 if (s->_raw_size == 0)
3049 _bfd_strip_section_from_output (info, s);
3053 /* Allocate memory for the section contents. */
3054 s->contents = (bfd_byte *) bfd_zalloc (htab->elf.dynobj, s->_raw_size);
3055 if (s->contents == NULL)
3059 if (htab->elf.dynamic_sections_created)
3061 /* Add some entries to the .dynamic section. We fill in the
3062 values later, in ppc_elf_finish_dynamic_sections, but we
3063 must add the entries now so that we get the correct size for
3064 the .dynamic section. The DT_DEBUG entry is filled in by the
3065 dynamic linker and used by the debugger. */
3066 #define add_dynamic_entry(TAG, VAL) \
3067 bfd_elf32_add_dynamic_entry (info, (bfd_vma) (TAG), (bfd_vma) (VAL))
3071 if (!add_dynamic_entry (DT_DEBUG, 0))
3075 if (htab->plt != NULL && htab->plt->_raw_size != 0)
3077 if (!add_dynamic_entry (DT_PLTGOT, 0)
3078 || !add_dynamic_entry (DT_PLTRELSZ, 0)
3079 || !add_dynamic_entry (DT_PLTREL, DT_RELA)
3080 || !add_dynamic_entry (DT_JMPREL, 0))
3086 if (!add_dynamic_entry (DT_RELA, 0)
3087 || !add_dynamic_entry (DT_RELASZ, 0)
3088 || !add_dynamic_entry (DT_RELAENT, sizeof (Elf32_External_Rela)))
3092 /* If any dynamic relocs apply to a read-only section, then we
3093 need a DT_TEXTREL entry. */
3094 if ((info->flags & DF_TEXTREL) == 0)
3095 elf_link_hash_traverse (elf_hash_table (info), readonly_dynrelocs,
3098 if ((info->flags & DF_TEXTREL) != 0)
3100 if (!add_dynamic_entry (DT_TEXTREL, 0))
3104 #undef add_dynamic_entry
3110 update_local_sym_info (abfd, symtab_hdr, r_symndx, tls_type)
3112 Elf_Internal_Shdr *symtab_hdr;
3113 unsigned long r_symndx;
3116 bfd_signed_vma *local_got_refcounts = elf_local_got_refcounts (abfd);
3117 char *local_got_tls_masks;
3119 if (local_got_refcounts == NULL)
3121 bfd_size_type size = symtab_hdr->sh_info;
3123 size *= sizeof (*local_got_refcounts) + sizeof (*local_got_tls_masks);
3124 local_got_refcounts = (bfd_signed_vma *) bfd_zalloc (abfd, size);
3125 if (local_got_refcounts == NULL)
3127 elf_local_got_refcounts (abfd) = local_got_refcounts;
3130 local_got_refcounts[r_symndx] += 1;
3131 local_got_tls_masks = (char *) (local_got_refcounts + symtab_hdr->sh_info);
3132 local_got_tls_masks[r_symndx] |= tls_type;
3137 bad_shared_reloc (abfd, r_type)
3139 enum elf_ppc_reloc_type r_type;
3141 (*_bfd_error_handler)
3142 (_("%s: relocation %s cannot be used when making a shared object"),
3143 bfd_archive_filename (abfd),
3144 ppc_elf_howto_table[(int) r_type]->name);
3145 bfd_set_error (bfd_error_bad_value);
3148 /* Look through the relocs for a section during the first phase, and
3149 allocate space in the global offset table or procedure linkage
3153 ppc_elf_check_relocs (abfd, info, sec, relocs)
3155 struct bfd_link_info *info;
3157 const Elf_Internal_Rela *relocs;
3159 struct ppc_elf_link_hash_table *htab;
3160 Elf_Internal_Shdr *symtab_hdr;
3161 struct elf_link_hash_entry **sym_hashes;
3162 const Elf_Internal_Rela *rel;
3163 const Elf_Internal_Rela *rel_end;
3166 if (info->relocateable)
3170 fprintf (stderr, "ppc_elf_check_relocs called for section %s in %s\n",
3171 bfd_get_section_name (abfd, sec),
3172 bfd_archive_filename (abfd));
3175 /* Create the linker generated sections all the time so that the
3176 special symbols are created. */
3178 htab = ppc_elf_hash_table (info);
3179 if (htab->sdata == NULL)
3181 htab->sdata = elf_linker_section (abfd, LINKER_SECTION_SDATA);
3182 if (htab->sdata == NULL)
3183 htab->sdata = ppc_elf_create_linker_section (abfd, info,
3184 LINKER_SECTION_SDATA);
3185 if (htab->sdata == NULL)
3189 if (htab->sdata2 == NULL)
3191 htab->sdata2 = elf_linker_section (abfd, LINKER_SECTION_SDATA2);
3192 if (htab->sdata2 == NULL)
3193 htab->sdata2 = ppc_elf_create_linker_section (abfd, info,
3194 LINKER_SECTION_SDATA2);
3195 if (htab->sdata2 == NULL)
3199 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
3200 sym_hashes = elf_sym_hashes (abfd);
3203 rel_end = relocs + sec->reloc_count;
3204 for (rel = relocs; rel < rel_end; rel++)
3206 unsigned long r_symndx;
3207 enum elf_ppc_reloc_type r_type;
3208 struct elf_link_hash_entry *h;
3211 r_symndx = ELF32_R_SYM (rel->r_info);
3212 if (r_symndx < symtab_hdr->sh_info)
3215 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
3217 /* If a relocation refers to _GLOBAL_OFFSET_TABLE_, create the .got.
3218 This shows up in particular in an R_PPC_ADDR32 in the eabi
3220 if (h && strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
3222 if (htab->got == NULL)
3224 if (htab->elf.dynobj == NULL)
3225 htab->elf.dynobj = abfd;
3226 if (!ppc_elf_create_got (htab->elf.dynobj, info))
3231 r_type = (enum elf_ppc_reloc_type) ELF32_R_TYPE (rel->r_info);
3234 case R_PPC_GOT_TLSLD16:
3235 case R_PPC_GOT_TLSLD16_LO:
3236 case R_PPC_GOT_TLSLD16_HI:
3237 case R_PPC_GOT_TLSLD16_HA:
3238 htab->tlsld_got.refcount += 1;
3239 tls_type = TLS_TLS | TLS_LD;
3242 case R_PPC_GOT_TLSGD16:
3243 case R_PPC_GOT_TLSGD16_LO:
3244 case R_PPC_GOT_TLSGD16_HI:
3245 case R_PPC_GOT_TLSGD16_HA:
3246 tls_type = TLS_TLS | TLS_GD;
3249 case R_PPC_GOT_TPREL16:
3250 case R_PPC_GOT_TPREL16_LO:
3251 case R_PPC_GOT_TPREL16_HI:
3252 case R_PPC_GOT_TPREL16_HA:
3254 info->flags |= DF_STATIC_TLS;
3255 tls_type = TLS_TLS | TLS_TPREL;
3258 case R_PPC_GOT_DTPREL16:
3259 case R_PPC_GOT_DTPREL16_LO:
3260 case R_PPC_GOT_DTPREL16_HI:
3261 case R_PPC_GOT_DTPREL16_HA:
3262 tls_type = TLS_TLS | TLS_DTPREL;
3264 sec->has_tls_reloc = 1;
3267 /* GOT16 relocations */
3269 case R_PPC_GOT16_LO:
3270 case R_PPC_GOT16_HI:
3271 case R_PPC_GOT16_HA:
3272 /* This symbol requires a global offset table entry. */
3273 if (htab->got == NULL)
3275 if (htab->elf.dynobj == NULL)
3276 htab->elf.dynobj = abfd;
3277 if (!ppc_elf_create_got (htab->elf.dynobj, info))
3282 h->got.refcount += 1;
3283 ppc_elf_hash_entry (h)->tls_mask |= tls_type;
3286 /* This is a global offset table entry for a local symbol. */
3287 if (!update_local_sym_info (abfd, symtab_hdr, r_symndx, tls_type))
3291 /* Indirect .sdata relocation. */
3292 case R_PPC_EMB_SDAI16:
3295 bad_shared_reloc (abfd, r_type);
3298 if (!bfd_elf32_create_pointer_linker_section (abfd, info,
3299 htab->sdata, h, rel))
3303 /* Indirect .sdata2 relocation. */
3304 case R_PPC_EMB_SDA2I16:
3307 bad_shared_reloc (abfd, r_type);
3310 if (!bfd_elf32_create_pointer_linker_section (abfd, info,
3311 htab->sdata2, h, rel))
3315 case R_PPC_SDAREL16:
3316 case R_PPC_EMB_SDA2REL:
3317 case R_PPC_EMB_SDA21:
3318 case R_PPC_EMB_RELSDA:
3319 case R_PPC_EMB_NADDR32:
3320 case R_PPC_EMB_NADDR16:
3321 case R_PPC_EMB_NADDR16_LO:
3322 case R_PPC_EMB_NADDR16_HI:
3323 case R_PPC_EMB_NADDR16_HA:
3326 bad_shared_reloc (abfd, r_type);
3332 case R_PPC_PLTREL24:
3333 case R_PPC_PLTREL32:
3334 case R_PPC_PLT16_LO:
3335 case R_PPC_PLT16_HI:
3336 case R_PPC_PLT16_HA:
3338 fprintf (stderr, "Reloc requires a PLT entry\n");
3340 /* This symbol requires a procedure linkage table entry. We
3341 actually build the entry in finish_dynamic_symbol,
3342 because this might be a case of linking PIC code without
3343 linking in any dynamic objects, in which case we don't
3344 need to generate a procedure linkage table after all. */
3348 /* It does not make sense to have a procedure linkage
3349 table entry for a local symbol. */
3350 bfd_set_error (bfd_error_bad_value);
3354 h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
3358 /* The following relocations don't need to propagate the
3359 relocation if linking a shared object since they are
3360 section relative. */
3362 case R_PPC_SECTOFF_LO:
3363 case R_PPC_SECTOFF_HI:
3364 case R_PPC_SECTOFF_HA:
3365 case R_PPC_DTPREL16:
3366 case R_PPC_DTPREL16_LO:
3367 case R_PPC_DTPREL16_HI:
3368 case R_PPC_DTPREL16_HA:
3372 /* This are just markers. */
3374 case R_PPC_EMB_MRKREF:
3379 /* These should only appear in dynamic objects. */
3381 case R_PPC_GLOB_DAT:
3382 case R_PPC_JMP_SLOT:
3383 case R_PPC_RELATIVE:
3386 /* These aren't handled yet. We'll report an error later. */
3388 case R_PPC_EMB_RELSEC16:
3389 case R_PPC_EMB_RELST_LO:
3390 case R_PPC_EMB_RELST_HI:
3391 case R_PPC_EMB_RELST_HA:
3392 case R_PPC_EMB_BIT_FLD:
3395 /* This refers only to functions defined in the shared library. */
3396 case R_PPC_LOCAL24PC:
3399 /* This relocation describes the C++ object vtable hierarchy.
3400 Reconstruct it for later use during GC. */
3401 case R_PPC_GNU_VTINHERIT:
3402 if (!_bfd_elf32_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
3406 /* This relocation describes which C++ vtable entries are actually
3407 used. Record for later use during GC. */
3408 case R_PPC_GNU_VTENTRY:
3409 if (!_bfd_elf32_gc_record_vtentry (abfd, sec, h, rel->r_addend))
3413 /* We shouldn't really be seeing these. */
3416 info->flags |= DF_STATIC_TLS;
3420 case R_PPC_DTPMOD32:
3421 case R_PPC_DTPREL32:
3425 case R_PPC_TPREL16_LO:
3426 case R_PPC_TPREL16_HI:
3427 case R_PPC_TPREL16_HA:
3429 info->flags |= DF_STATIC_TLS;
3432 /* When creating a shared object, we must copy these
3433 relocs into the output file. We create a reloc
3434 section in dynobj and make room for the reloc. */
3437 case R_PPC_REL14_BRTAKEN:
3438 case R_PPC_REL14_BRNTAKEN:
3441 || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0
3442 || SYMBOL_REFERENCES_LOCAL (info, h))
3449 case R_PPC_ADDR16_LO:
3450 case R_PPC_ADDR16_HI:
3451 case R_PPC_ADDR16_HA:
3453 case R_PPC_ADDR14_BRTAKEN:
3454 case R_PPC_ADDR14_BRNTAKEN:
3457 if (h != NULL && !info->shared)
3459 /* We may need a plt entry if the symbol turns out to be
3460 a function defined in a dynamic object. */
3463 /* We may need a copy reloc too. */
3464 h->elf_link_hash_flags |= ELF_LINK_NON_GOT_REF;
3468 /* If we are creating a shared library, and this is a reloc
3469 against a global symbol, or a non PC relative reloc
3470 against a local symbol, then we need to copy the reloc
3471 into the shared library. However, if we are linking with
3472 -Bsymbolic, we do not need to copy a reloc against a
3473 global symbol which is defined in an object we are
3474 including in the link (i.e., DEF_REGULAR is set). At
3475 this point we have not seen all the input files, so it is
3476 possible that DEF_REGULAR is not set now but will be set
3477 later (it is never cleared). In case of a weak definition,
3478 DEF_REGULAR may be cleared later by a strong definition in
3479 a shared library. We account for that possibility below by
3480 storing information in the dyn_relocs field of the hash
3481 table entry. A similar situation occurs when creating
3482 shared libraries and symbol visibility changes render the
3485 If on the other hand, we are creating an executable, we
3486 may need to keep relocations for symbols satisfied by a
3487 dynamic library if we manage to avoid copy relocs for the
3490 && (MUST_BE_DYN_RELOC (r_type)
3492 && (! info->symbolic
3493 || h->root.type == bfd_link_hash_defweak
3494 || (h->elf_link_hash_flags
3495 & ELF_LINK_HASH_DEF_REGULAR) == 0))))
3496 || (ELIMINATE_COPY_RELOCS
3498 && (sec->flags & SEC_ALLOC) != 0
3500 && (h->root.type == bfd_link_hash_defweak
3501 || (h->elf_link_hash_flags
3502 & ELF_LINK_HASH_DEF_REGULAR) == 0)))
3504 struct ppc_elf_dyn_relocs *p;
3505 struct ppc_elf_dyn_relocs **head;
3508 fprintf (stderr, "ppc_elf_check_relocs need to create relocation for %s\n",
3509 (h && h->root.root.string) ? h->root.root.string : "<unknown>");
3515 name = (bfd_elf_string_from_elf_section
3517 elf_elfheader (abfd)->e_shstrndx,
3518 elf_section_data (sec)->rel_hdr.sh_name));
3522 BFD_ASSERT (strncmp (name, ".rela", 5) == 0
3523 && strcmp (bfd_get_section_name (abfd, sec),
3526 sreloc = bfd_get_section_by_name (htab->elf.dynobj, name);
3531 sreloc = bfd_make_section (htab->elf.dynobj, name);
3532 flags = (SEC_HAS_CONTENTS | SEC_READONLY
3533 | SEC_IN_MEMORY | SEC_LINKER_CREATED);
3534 if ((sec->flags & SEC_ALLOC) != 0)
3535 flags |= SEC_ALLOC | SEC_LOAD;
3537 || ! bfd_set_section_flags (htab->elf.dynobj,
3539 || ! bfd_set_section_alignment (htab->elf.dynobj,
3543 elf_section_data (sec)->sreloc = sreloc;
3546 /* If this is a global symbol, we count the number of
3547 relocations we need for this symbol. */
3550 head = &ppc_elf_hash_entry (h)->dyn_relocs;
3554 /* Track dynamic relocs needed for local syms too.
3555 We really need local syms available to do this
3559 s = bfd_section_from_r_symndx (abfd, &htab->sym_sec,
3564 head = ((struct ppc_elf_dyn_relocs **)
3565 &elf_section_data (s)->local_dynrel);
3569 if (p == NULL || p->sec != sec)
3571 p = ((struct ppc_elf_dyn_relocs *)
3572 bfd_alloc (htab->elf.dynobj, sizeof *p));
3583 if (!MUST_BE_DYN_RELOC (r_type))
3594 /* Return the section that should be marked against GC for a given
3598 ppc_elf_gc_mark_hook (sec, info, rel, h, sym)
3600 struct bfd_link_info *info ATTRIBUTE_UNUSED;
3601 Elf_Internal_Rela *rel;
3602 struct elf_link_hash_entry *h;
3603 Elf_Internal_Sym *sym;
3607 switch (ELF32_R_TYPE (rel->r_info))
3609 case R_PPC_GNU_VTINHERIT:
3610 case R_PPC_GNU_VTENTRY:
3614 switch (h->root.type)
3616 case bfd_link_hash_defined:
3617 case bfd_link_hash_defweak:
3618 return h->root.u.def.section;
3620 case bfd_link_hash_common:
3621 return h->root.u.c.p->section;
3629 return bfd_section_from_elf_index (sec->owner, sym->st_shndx);
3634 /* Update the got, plt and dynamic reloc reference counts for the
3635 section being removed. */
3638 ppc_elf_gc_sweep_hook (abfd, info, sec, relocs)
3640 struct bfd_link_info *info;
3642 const Elf_Internal_Rela *relocs;
3644 struct ppc_elf_link_hash_table *htab;
3645 Elf_Internal_Shdr *symtab_hdr;
3646 struct elf_link_hash_entry **sym_hashes;
3647 bfd_signed_vma *local_got_refcounts;
3648 const Elf_Internal_Rela *rel, *relend;
3650 elf_section_data (sec)->local_dynrel = NULL;
3652 htab = ppc_elf_hash_table (info);
3653 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
3654 sym_hashes = elf_sym_hashes (abfd);
3655 local_got_refcounts = elf_local_got_refcounts (abfd);
3657 relend = relocs + sec->reloc_count;
3658 for (rel = relocs; rel < relend; rel++)
3660 unsigned long r_symndx;
3661 enum elf_ppc_reloc_type r_type;
3662 struct elf_link_hash_entry *h = NULL;
3664 r_symndx = ELF32_R_SYM (rel->r_info);
3665 if (r_symndx >= symtab_hdr->sh_info)
3667 struct ppc_elf_dyn_relocs **pp, *p;
3668 struct ppc_elf_link_hash_entry *eh;
3670 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
3671 eh = (struct ppc_elf_link_hash_entry *) h;
3673 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next)
3676 /* Everything must go for SEC. */
3682 r_type = (enum elf_ppc_reloc_type) ELF32_R_TYPE (rel->r_info);
3685 case R_PPC_GOT_TLSLD16:
3686 case R_PPC_GOT_TLSLD16_LO:
3687 case R_PPC_GOT_TLSLD16_HI:
3688 case R_PPC_GOT_TLSLD16_HA:
3689 htab->tlsld_got.refcount -= 1;
3692 case R_PPC_GOT_TLSGD16:
3693 case R_PPC_GOT_TLSGD16_LO:
3694 case R_PPC_GOT_TLSGD16_HI:
3695 case R_PPC_GOT_TLSGD16_HA:
3696 case R_PPC_GOT_TPREL16:
3697 case R_PPC_GOT_TPREL16_LO:
3698 case R_PPC_GOT_TPREL16_HI:
3699 case R_PPC_GOT_TPREL16_HA:
3700 case R_PPC_GOT_DTPREL16:
3701 case R_PPC_GOT_DTPREL16_LO:
3702 case R_PPC_GOT_DTPREL16_HI:
3703 case R_PPC_GOT_DTPREL16_HA:
3705 case R_PPC_GOT16_LO:
3706 case R_PPC_GOT16_HI:
3707 case R_PPC_GOT16_HA:
3710 if (h->got.refcount > 0)
3713 else if (local_got_refcounts != NULL)
3715 if (local_got_refcounts[r_symndx] > 0)
3716 local_got_refcounts[r_symndx]--;
3722 case R_PPC_REL14_BRTAKEN:
3723 case R_PPC_REL14_BRNTAKEN:
3726 || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0
3727 || SYMBOL_REFERENCES_LOCAL (info, h))
3734 case R_PPC_ADDR16_LO:
3735 case R_PPC_ADDR16_HI:
3736 case R_PPC_ADDR16_HA:
3738 case R_PPC_ADDR14_BRTAKEN:
3739 case R_PPC_ADDR14_BRNTAKEN:
3743 case R_PPC_PLTREL24:
3744 case R_PPC_PLT16_LO:
3745 case R_PPC_PLT16_HI:
3746 case R_PPC_PLT16_HA:
3749 if (h->plt.refcount > 0)
3761 /* Set htab->tls_sec and htab->tls_get_addr. */
3764 ppc_elf_tls_setup (obfd, info)
3766 struct bfd_link_info *info;
3769 struct ppc_elf_link_hash_table *htab;
3771 htab = ppc_elf_hash_table (info);
3772 htab->tls_get_addr = elf_link_hash_lookup (&htab->elf, "__tls_get_addr",
3773 FALSE, FALSE, TRUE);
3775 for (tls = obfd->sections; tls != NULL; tls = tls->next)
3776 if ((tls->flags & (SEC_THREAD_LOCAL | SEC_LOAD))
3777 == (SEC_THREAD_LOCAL | SEC_LOAD))
3779 htab->tls_sec = tls;
3784 /* Run through all the TLS relocs looking for optimization
3788 ppc_elf_tls_optimize (obfd, info)
3789 bfd *obfd ATTRIBUTE_UNUSED;
3790 struct bfd_link_info *info;
3794 struct ppc_elf_link_hash_table *htab;
3796 if (info->relocateable || info->shared)
3799 htab = ppc_elf_hash_table (info);
3800 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
3802 Elf_Internal_Sym *locsyms = NULL;
3803 Elf_Internal_Shdr *symtab_hdr = &elf_tdata (ibfd)->symtab_hdr;
3805 for (sec = ibfd->sections; sec != NULL; sec = sec->next)
3806 if (sec->has_tls_reloc && !bfd_is_abs_section (sec->output_section))
3808 Elf_Internal_Rela *relstart, *rel, *relend;
3809 int expecting_tls_get_addr;
3811 /* Read the relocations. */
3812 relstart = _bfd_elf32_link_read_relocs (ibfd, sec, (PTR) NULL,
3813 (Elf_Internal_Rela *) NULL,
3815 if (relstart == NULL)
3818 expecting_tls_get_addr = 0;
3819 relend = relstart + sec->reloc_count;
3820 for (rel = relstart; rel < relend; rel++)
3822 enum elf_ppc_reloc_type r_type;
3823 unsigned long r_symndx;
3824 struct elf_link_hash_entry *h = NULL;
3826 char tls_set, tls_clear;
3827 bfd_boolean is_local;
3829 r_symndx = ELF32_R_SYM (rel->r_info);
3830 if (r_symndx >= symtab_hdr->sh_info)
3832 struct elf_link_hash_entry **sym_hashes;
3834 sym_hashes = elf_sym_hashes (ibfd);
3835 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
3836 while (h->root.type == bfd_link_hash_indirect
3837 || h->root.type == bfd_link_hash_warning)
3838 h = (struct elf_link_hash_entry *) h->root.u.i.link;
3843 || !(h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC))
3846 r_type = (enum elf_ppc_reloc_type) ELF32_R_TYPE (rel->r_info);
3849 case R_PPC_GOT_TLSLD16:
3850 case R_PPC_GOT_TLSLD16_LO:
3851 case R_PPC_GOT_TLSLD16_HI:
3852 case R_PPC_GOT_TLSLD16_HA:
3853 /* These relocs should never be against a symbol
3854 defined in a shared lib. Leave them alone if
3855 that turns out to be the case. */
3856 expecting_tls_get_addr = 0;
3857 htab->tlsld_got.refcount -= 1;
3864 expecting_tls_get_addr = 1;
3867 case R_PPC_GOT_TLSGD16:
3868 case R_PPC_GOT_TLSGD16_LO:
3869 case R_PPC_GOT_TLSGD16_HI:
3870 case R_PPC_GOT_TLSGD16_HA:
3876 tls_set = TLS_TLS | TLS_TPRELGD;
3878 expecting_tls_get_addr = 1;
3881 case R_PPC_GOT_TPREL16:
3882 case R_PPC_GOT_TPREL16_LO:
3883 case R_PPC_GOT_TPREL16_HI:
3884 case R_PPC_GOT_TPREL16_HA:
3885 expecting_tls_get_addr = 0;
3890 tls_clear = TLS_TPREL;
3897 case R_PPC_REL14_BRTAKEN:
3898 case R_PPC_REL14_BRNTAKEN:
3900 if (expecting_tls_get_addr
3902 && h == htab->tls_get_addr)
3904 if (h->plt.refcount > 0)
3905 h->plt.refcount -= 1;
3907 expecting_tls_get_addr = 0;
3911 expecting_tls_get_addr = 0;
3919 /* We managed to get rid of a got entry. */
3920 if (h->got.refcount > 0)
3921 h->got.refcount -= 1;
3923 tls_mask = &ppc_elf_hash_entry (h)->tls_mask;
3927 Elf_Internal_Sym *sym;
3928 bfd_signed_vma *lgot_refs;
3931 if (locsyms == NULL)
3933 locsyms = (Elf_Internal_Sym *) symtab_hdr->contents;
3934 if (locsyms == NULL)
3935 locsyms = bfd_elf_get_elf_syms (ibfd, symtab_hdr,
3936 symtab_hdr->sh_info,
3937 0, NULL, NULL, NULL);
3938 if (locsyms == NULL)
3940 if (elf_section_data (sec)->relocs != relstart)
3945 sym = locsyms + r_symndx;
3946 lgot_refs = elf_local_got_refcounts (ibfd);
3947 if (lgot_refs == NULL)
3951 /* We managed to get rid of a got entry. */
3952 if (lgot_refs[r_symndx] > 0)
3953 lgot_refs[r_symndx] -= 1;
3955 lgot_masks = (char *) (lgot_refs + symtab_hdr->sh_info);
3956 tls_mask = &lgot_masks[r_symndx];
3959 *tls_mask |= tls_set;
3960 *tls_mask &= ~tls_clear;
3963 if (elf_section_data (sec)->relocs != relstart)
3968 && (symtab_hdr->contents != (unsigned char *) locsyms))
3970 if (!info->keep_memory)
3973 symtab_hdr->contents = (unsigned char *) locsyms;
3979 /* Hook called by the linker routine which adds symbols from an object
3980 file. We use it to put .comm items in .sbss, and not .bss. */
3983 ppc_elf_add_symbol_hook (abfd, info, sym, namep, flagsp, secp, valp)
3985 struct bfd_link_info *info;
3986 const Elf_Internal_Sym *sym;
3987 const char **namep ATTRIBUTE_UNUSED;
3988 flagword *flagsp ATTRIBUTE_UNUSED;
3992 if (sym->st_shndx == SHN_COMMON
3993 && !info->relocateable
3994 && sym->st_size <= elf_gp_size (abfd)
3995 && info->hash->creator->flavour == bfd_target_elf_flavour)
3997 /* Common symbols less than or equal to -G nn bytes are automatically
3999 elf_linker_section_t *sdata
4000 = ppc_elf_create_linker_section (abfd, info, LINKER_SECTION_SDATA);
4002 if (!sdata->bss_section)
4006 /* We don't go through bfd_make_section, because we don't
4007 want to attach this common section to DYNOBJ. The linker
4008 will move the symbols to the appropriate output section
4009 when it defines common symbols. */
4010 amt = sizeof (asection);
4011 sdata->bss_section = (asection *) bfd_zalloc (abfd, amt);
4012 if (sdata->bss_section == NULL)
4014 sdata->bss_section->name = sdata->bss_name;
4015 sdata->bss_section->flags = SEC_IS_COMMON;
4016 sdata->bss_section->output_section = sdata->bss_section;
4017 amt = sizeof (asymbol);
4018 sdata->bss_section->symbol = (asymbol *) bfd_zalloc (abfd, amt);
4019 amt = sizeof (asymbol *);
4020 sdata->bss_section->symbol_ptr_ptr =
4021 (asymbol **) bfd_zalloc (abfd, amt);
4022 if (sdata->bss_section->symbol == NULL
4023 || sdata->bss_section->symbol_ptr_ptr == NULL)
4025 sdata->bss_section->symbol->name = sdata->bss_name;
4026 sdata->bss_section->symbol->flags = BSF_SECTION_SYM;
4027 sdata->bss_section->symbol->section = sdata->bss_section;
4028 *sdata->bss_section->symbol_ptr_ptr = sdata->bss_section->symbol;
4031 *secp = sdata->bss_section;
4032 *valp = sym->st_size;
4038 /* Finish up dynamic symbol handling. We set the contents of various
4039 dynamic sections here. */
4042 ppc_elf_finish_dynamic_symbol (output_bfd, info, h, sym)
4044 struct bfd_link_info *info;
4045 struct elf_link_hash_entry *h;
4046 Elf_Internal_Sym *sym;
4048 struct ppc_elf_link_hash_table *htab;
4051 fprintf (stderr, "ppc_elf_finish_dynamic_symbol called for %s",
4052 h->root.root.string);
4055 htab = ppc_elf_hash_table (info);
4056 BFD_ASSERT (htab->elf.dynobj != NULL);
4058 if (h->plt.offset != (bfd_vma) -1)
4060 Elf_Internal_Rela rela;
4062 bfd_vma reloc_index;
4065 fprintf (stderr, ", plt_offset = %d", h->plt.offset);
4068 /* This symbol has an entry in the procedure linkage table. Set
4071 BFD_ASSERT (h->dynindx != -1);
4072 BFD_ASSERT (htab->plt != NULL && htab->relplt != NULL);
4074 /* We don't need to fill in the .plt. The ppc dynamic linker
4077 /* Fill in the entry in the .rela.plt section. */
4078 rela.r_offset = (htab->plt->output_section->vma
4079 + htab->plt->output_offset
4081 rela.r_info = ELF32_R_INFO (h->dynindx, R_PPC_JMP_SLOT);
4084 reloc_index = (h->plt.offset - PLT_INITIAL_ENTRY_SIZE) / PLT_SLOT_SIZE;
4085 if (reloc_index > PLT_NUM_SINGLE_ENTRIES)
4086 reloc_index -= (reloc_index - PLT_NUM_SINGLE_ENTRIES) / 2;
4087 loc = (htab->relplt->contents
4088 + reloc_index * sizeof (Elf32_External_Rela));
4089 bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
4091 if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
4093 /* Mark the symbol as undefined, rather than as defined in
4094 the .plt section. Leave the value alone. */
4095 sym->st_shndx = SHN_UNDEF;
4096 /* If the symbol is weak, we do need to clear the value.
4097 Otherwise, the PLT entry would provide a definition for
4098 the symbol even if the symbol wasn't defined anywhere,
4099 and so the symbol would never be NULL. */
4100 if ((h->elf_link_hash_flags & ELF_LINK_HASH_REF_REGULAR_NONWEAK)
4106 if ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_COPY) != 0)
4109 Elf_Internal_Rela rela;
4112 /* This symbols needs a copy reloc. Set it up. */
4115 fprintf (stderr, ", copy");
4118 BFD_ASSERT (h->dynindx != -1);
4120 if (h->size <= elf_gp_size (htab->elf.dynobj))
4124 BFD_ASSERT (s != NULL);
4126 rela.r_offset = (h->root.u.def.value
4127 + h->root.u.def.section->output_section->vma
4128 + h->root.u.def.section->output_offset);
4129 rela.r_info = ELF32_R_INFO (h->dynindx, R_PPC_COPY);
4131 loc = s->contents + s->reloc_count++ * sizeof (Elf32_External_Rela);
4132 bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
4136 fprintf (stderr, "\n");
4139 /* Mark some specially defined symbols as absolute. */
4140 if (strcmp (h->root.root.string, "_DYNAMIC") == 0
4141 || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0
4142 || strcmp (h->root.root.string, "_PROCEDURE_LINKAGE_TABLE_") == 0)
4143 sym->st_shndx = SHN_ABS;
4148 /* Finish up the dynamic sections. */
4151 ppc_elf_finish_dynamic_sections (output_bfd, info)
4153 struct bfd_link_info *info;
4156 struct ppc_elf_link_hash_table *htab;
4159 fprintf (stderr, "ppc_elf_finish_dynamic_sections called\n");
4162 htab = ppc_elf_hash_table (info);
4163 sdyn = bfd_get_section_by_name (htab->elf.dynobj, ".dynamic");
4165 if (htab->elf.dynamic_sections_created)
4167 Elf32_External_Dyn *dyncon, *dynconend;
4169 BFD_ASSERT (htab->plt != NULL && sdyn != NULL);
4171 dyncon = (Elf32_External_Dyn *) sdyn->contents;
4172 dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->_raw_size);
4173 for (; dyncon < dynconend; dyncon++)
4175 Elf_Internal_Dyn dyn;
4178 bfd_elf32_swap_dyn_in (htab->elf.dynobj, dyncon, &dyn);
4184 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
4188 dyn.d_un.d_val = htab->relplt->_raw_size;
4193 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
4200 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
4204 /* Add a blrl instruction at _GLOBAL_OFFSET_TABLE_-4 so that a function can
4205 easily find the address of the _GLOBAL_OFFSET_TABLE_. */
4208 unsigned char *contents = htab->got->contents;
4209 bfd_put_32 (output_bfd, (bfd_vma) 0x4e800021 /* blrl */, contents);
4212 bfd_put_32 (output_bfd, (bfd_vma) 0, contents + 4);
4214 bfd_put_32 (output_bfd,
4215 sdyn->output_section->vma + sdyn->output_offset,
4218 elf_section_data (htab->got->output_section)->this_hdr.sh_entsize = 4;
4224 /* The RELOCATE_SECTION function is called by the ELF backend linker
4225 to handle the relocations for a section.
4227 The relocs are always passed as Rela structures; if the section
4228 actually uses Rel structures, the r_addend field will always be
4231 This function is responsible for adjust the section contents as
4232 necessary, and (if using Rela relocs and generating a
4233 relocateable output file) adjusting the reloc addend as
4236 This function does not have to worry about setting the reloc
4237 address or the reloc symbol index.
4239 LOCAL_SYMS is a pointer to the swapped in local symbols.
4241 LOCAL_SECTIONS is an array giving the section in the input file
4242 corresponding to the st_shndx field of each local symbol.
4244 The global hash table entry for the global symbols can be found
4245 via elf_sym_hashes (input_bfd).
4247 When generating relocateable output, this function must handle
4248 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
4249 going to be the section symbol corresponding to the output
4250 section, which means that the addend must be adjusted
4254 ppc_elf_relocate_section (output_bfd, info, input_bfd, input_section,
4255 contents, relocs, local_syms, local_sections)
4257 struct bfd_link_info *info;
4259 asection *input_section;
4261 Elf_Internal_Rela *relocs;
4262 Elf_Internal_Sym *local_syms;
4263 asection **local_sections;
4265 Elf_Internal_Shdr *symtab_hdr;
4266 struct elf_link_hash_entry **sym_hashes;
4267 struct ppc_elf_link_hash_table *htab;
4268 Elf_Internal_Rela *rel;
4269 Elf_Internal_Rela *relend;
4270 Elf_Internal_Rela outrel;
4272 asection *sreloc = NULL;
4273 bfd_vma *local_got_offsets;
4274 bfd_boolean ret = TRUE;
4277 fprintf (stderr, "ppc_elf_relocate_section called for %s section %s, %ld relocations%s\n",
4278 bfd_archive_filename (input_bfd),
4279 bfd_section_name(input_bfd, input_section),
4280 (long) input_section->reloc_count,
4281 (info->relocateable) ? " (relocatable)" : "");
4284 if (info->relocateable)
4287 if (!ppc_elf_howto_table[R_PPC_ADDR32])
4288 /* Initialize howto table if needed. */
4289 ppc_elf_howto_init ();
4291 htab = ppc_elf_hash_table (info);
4292 local_got_offsets = elf_local_got_offsets (input_bfd);
4293 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
4294 sym_hashes = elf_sym_hashes (input_bfd);
4296 relend = relocs + input_section->reloc_count;
4297 for (; rel < relend; rel++)
4299 enum elf_ppc_reloc_type r_type;
4301 bfd_reloc_status_type r;
4302 Elf_Internal_Sym *sym;
4304 struct elf_link_hash_entry *h;
4305 const char *sym_name;
4306 reloc_howto_type *howto;
4307 unsigned long r_symndx;
4309 bfd_vma branch_bit, insn, from;
4310 bfd_boolean unresolved_reloc;
4312 unsigned int tls_type, tls_mask, tls_gd;
4314 r_type = (enum elf_ppc_reloc_type)ELF32_R_TYPE (rel->r_info);
4315 sym = (Elf_Internal_Sym *) 0;
4316 sec = (asection *) 0;
4317 h = (struct elf_link_hash_entry *) 0;
4318 unresolved_reloc = FALSE;
4320 r_symndx = ELF32_R_SYM (rel->r_info);
4321 if (r_symndx < symtab_hdr->sh_info)
4323 sym = local_syms + r_symndx;
4324 sec = local_sections[r_symndx];
4325 sym_name = bfd_elf_local_sym_name (input_bfd, sym);
4327 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, sec, rel);
4331 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
4332 while (h->root.type == bfd_link_hash_indirect
4333 || h->root.type == bfd_link_hash_warning)
4334 h = (struct elf_link_hash_entry *) h->root.u.i.link;
4335 sym_name = h->root.root.string;
4338 if (h->root.type == bfd_link_hash_defined
4339 || h->root.type == bfd_link_hash_defweak)
4341 sec = h->root.u.def.section;
4342 /* Set a flag that will be cleared later if we find a
4343 relocation value for this symbol. output_section
4344 is typically NULL for symbols satisfied by a shared
4346 if (sec->output_section == NULL)
4347 unresolved_reloc = TRUE;
4349 relocation = (h->root.u.def.value
4350 + sec->output_section->vma
4351 + sec->output_offset);
4353 else if (h->root.type == bfd_link_hash_undefweak)
4355 else if (info->shared
4356 && !info->no_undefined
4357 && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
4361 if (! ((*info->callbacks->undefined_symbol)
4362 (info, h->root.root.string, input_bfd, input_section,
4363 rel->r_offset, (!info->shared
4364 || info->no_undefined
4365 || ELF_ST_VISIBILITY (h->other)))))
4371 /* TLS optimizations. Replace instruction sequences and relocs
4372 based on information we collected in tls_optimize. We edit
4373 RELOCS so that --emit-relocs will output something sensible
4374 for the final instruction stream. */
4377 if (IS_PPC_TLS_RELOC (r_type))
4380 tls_mask = ((struct ppc_elf_link_hash_entry *) h)->tls_mask;
4381 else if (local_got_offsets != NULL)
4384 lgot_masks = (char *) (local_got_offsets + symtab_hdr->sh_info);
4385 tls_mask = lgot_masks[r_symndx];
4389 /* Ensure reloc mapping code below stays sane. */
4390 if ((R_PPC_GOT_TLSLD16 & 3) != (R_PPC_GOT_TLSGD16 & 3)
4391 || (R_PPC_GOT_TLSLD16_LO & 3) != (R_PPC_GOT_TLSGD16_LO & 3)
4392 || (R_PPC_GOT_TLSLD16_HI & 3) != (R_PPC_GOT_TLSGD16_HI & 3)
4393 || (R_PPC_GOT_TLSLD16_HA & 3) != (R_PPC_GOT_TLSGD16_HA & 3)
4394 || (R_PPC_GOT_TLSLD16 & 3) != (R_PPC_GOT_TPREL16 & 3)
4395 || (R_PPC_GOT_TLSLD16_LO & 3) != (R_PPC_GOT_TPREL16_LO & 3)
4396 || (R_PPC_GOT_TLSLD16_HI & 3) != (R_PPC_GOT_TPREL16_HI & 3)
4397 || (R_PPC_GOT_TLSLD16_HA & 3) != (R_PPC_GOT_TPREL16_HA & 3))
4404 case R_PPC_GOT_TPREL16:
4405 case R_PPC_GOT_TPREL16_LO:
4407 && (tls_mask & TLS_TPREL) == 0)
4410 insn = bfd_get_32 (output_bfd, contents + rel->r_offset - 2);
4412 insn |= 0x3c020000; /* addis 0,2,0 */
4413 bfd_put_32 (output_bfd, insn, contents + rel->r_offset - 2);
4414 r_type = R_PPC_TPREL16_HA;
4415 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
4421 && (tls_mask & TLS_TPREL) == 0)
4424 insn = bfd_get_32 (output_bfd, contents + rel->r_offset);
4425 if ((insn & ((31 << 26) | (31 << 11)))
4426 == ((31 << 26) | (2 << 11)))
4427 rtra = insn & ((1 << 26) - (1 << 16));
4428 else if ((insn & ((31 << 26) | (31 << 16)))
4429 == ((31 << 26) | (2 << 16)))
4430 rtra = (insn & (31 << 21)) | ((insn & (31 << 11)) << 5);
4433 if ((insn & ((1 << 11) - (1 << 1))) == 266 << 1)
4436 else if ((insn & (31 << 1)) == 23 << 1
4437 && ((insn & (31 << 6)) < 14 << 6
4438 || ((insn & (31 << 6)) >= 16 << 6
4439 && (insn & (31 << 6)) < 24 << 6)))
4440 /* load and store indexed -> dform. */
4441 insn = (32 | ((insn >> 6) & 31)) << 26;
4442 else if ((insn & (31 << 1)) == 21 << 1
4443 && (insn & (0x1a << 6)) == 0)
4444 /* ldx, ldux, stdx, stdux -> ld, ldu, std, stdu. */
4445 insn = (((58 | ((insn >> 6) & 4)) << 26)
4446 | ((insn >> 6) & 1));
4447 else if ((insn & (31 << 1)) == 21 << 1
4448 && (insn & ((1 << 11) - (1 << 1))) == 341 << 1)
4450 insn = (58 << 26) | 2;
4454 bfd_put_32 (output_bfd, insn, contents + rel->r_offset);
4455 r_type = R_PPC_TPREL16_LO;
4456 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
4457 /* Was PPC_TLS which sits on insn boundary, now
4458 PPC_TPREL16_LO which is at insn+2. */
4463 case R_PPC_GOT_TLSGD16_HI:
4464 case R_PPC_GOT_TLSGD16_HA:
4465 tls_gd = TLS_TPRELGD;
4466 if (tls_mask != 0 && (tls_mask & TLS_GD) == 0)
4470 case R_PPC_GOT_TLSLD16_HI:
4471 case R_PPC_GOT_TLSLD16_HA:
4472 if (tls_mask != 0 && (tls_mask & TLS_LD) == 0)
4475 if ((tls_mask & tls_gd) != 0)
4476 r_type = (((r_type - (R_PPC_GOT_TLSGD16 & 3)) & 3)
4477 + R_PPC_GOT_TPREL16);
4480 bfd_put_32 (output_bfd, NOP, contents + rel->r_offset);
4482 r_type = R_PPC_NONE;
4484 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
4488 case R_PPC_GOT_TLSGD16:
4489 case R_PPC_GOT_TLSGD16_LO:
4490 tls_gd = TLS_TPRELGD;
4491 if (tls_mask != 0 && (tls_mask & TLS_GD) == 0)
4492 goto tls_get_addr_check;
4495 case R_PPC_GOT_TLSLD16:
4496 case R_PPC_GOT_TLSLD16_LO:
4497 if (tls_mask != 0 && (tls_mask & TLS_LD) == 0)
4500 if (rel + 1 < relend)
4502 enum elf_ppc_reloc_type r_type2;
4503 unsigned long r_symndx2;
4504 struct elf_link_hash_entry *h2;
4505 bfd_vma insn1, insn2, insn3;
4508 /* The next instruction should be a call to
4509 __tls_get_addr. Peek at the reloc to be sure. */
4511 = (enum elf_ppc_reloc_type) ELF32_R_TYPE (rel[1].r_info);
4512 r_symndx2 = ELF32_R_SYM (rel[1].r_info);
4513 if (r_symndx2 < symtab_hdr->sh_info
4514 || (r_type2 != R_PPC_REL14
4515 && r_type2 != R_PPC_REL14_BRTAKEN
4516 && r_type2 != R_PPC_REL14_BRNTAKEN
4517 && r_type2 != R_PPC_REL24
4518 && r_type2 != R_PPC_PLTREL24))
4521 h2 = sym_hashes[r_symndx2 - symtab_hdr->sh_info];
4522 while (h2->root.type == bfd_link_hash_indirect
4523 || h2->root.type == bfd_link_hash_warning)
4524 h2 = (struct elf_link_hash_entry *) h2->root.u.i.link;
4525 if (h2 == NULL || h2 != htab->tls_get_addr)
4528 /* OK, it checks out. Replace the call. */
4529 offset = rel[1].r_offset;
4530 insn1 = bfd_get_32 (output_bfd,
4531 contents + rel->r_offset - 2);
4532 insn3 = bfd_get_32 (output_bfd,
4533 contents + offset + 4);
4534 if ((tls_mask & tls_gd) != 0)
4537 insn1 &= (1 << 26) - 1;
4538 insn1 |= 32 << 26; /* lwz */
4539 insn2 = 0x7c631214; /* add 3,3,2 */
4540 rel[1].r_info = ELF32_R_INFO (r_symndx2, R_PPC_NONE);
4541 r_type = (((r_type - (R_PPC_GOT_TLSGD16 & 3)) & 3)
4542 + R_PPC_GOT_TPREL16);
4543 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
4548 insn1 = 0x3c620000; /* addis 3,2,0 */
4549 insn2 = 0x38630000; /* addi 3,3,0 */
4552 /* Was an LD reloc. */
4554 rel->r_addend = htab->tls_sec->vma + DTP_OFFSET;
4555 rel[1].r_addend = htab->tls_sec->vma + DTP_OFFSET;
4557 r_type = R_PPC_TPREL16_HA;
4558 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
4559 rel[1].r_info = ELF32_R_INFO (r_symndx,
4561 rel[1].r_offset += 2;
4564 || insn3 == CROR_151515 || insn3 == CROR_313131)
4568 rel[1].r_offset += 4;
4570 bfd_put_32 (output_bfd, insn1, contents + rel->r_offset - 2);
4571 bfd_put_32 (output_bfd, insn2, contents + offset);
4572 bfd_put_32 (output_bfd, insn3, contents + offset + 4);
4575 /* We changed the symbol on an LD reloc. Start over
4576 in order to get h, sym, sec etc. right. */
4585 /* Handle other relocations that tweak non-addend part of insn. */
4592 /* Branch taken prediction relocations. */
4593 case R_PPC_ADDR14_BRTAKEN:
4594 case R_PPC_REL14_BRTAKEN:
4595 branch_bit = BRANCH_PREDICT_BIT;
4598 /* Branch not taken predicition relocations. */
4599 case R_PPC_ADDR14_BRNTAKEN:
4600 case R_PPC_REL14_BRNTAKEN:
4601 insn = bfd_get_32 (output_bfd, contents + rel->r_offset);
4602 insn &= ~BRANCH_PREDICT_BIT;
4605 from = (rel->r_offset
4606 + input_section->output_offset
4607 + input_section->output_section->vma);
4609 /* Invert 'y' bit if not the default. */
4610 if ((bfd_signed_vma) (relocation + rel->r_addend - from) < 0)
4611 insn ^= BRANCH_PREDICT_BIT;
4613 bfd_put_32 (output_bfd, insn, contents + rel->r_offset);
4617 addend = rel->r_addend;
4620 if ((unsigned) r_type < (unsigned) R_PPC_max)
4621 howto = ppc_elf_howto_table[(int) r_type];
4625 (*_bfd_error_handler)
4626 (_("%s: unknown relocation type %d for symbol %s"),
4627 bfd_archive_filename (input_bfd), (int) r_type, sym_name);
4629 bfd_set_error (bfd_error_bad_value);
4635 case R_PPC_EMB_MRKREF:
4636 case R_PPC_GNU_VTINHERIT:
4637 case R_PPC_GNU_VTENTRY:
4640 /* GOT16 relocations. Like an ADDR16 using the symbol's
4641 address in the GOT as relocation value instead of the
4642 symbol's value itself. Also, create a GOT entry for the
4643 symbol and put the symbol value there. */
4644 case R_PPC_GOT_TLSGD16:
4645 case R_PPC_GOT_TLSGD16_LO:
4646 case R_PPC_GOT_TLSGD16_HI:
4647 case R_PPC_GOT_TLSGD16_HA:
4648 tls_type = TLS_TLS | TLS_GD;
4651 case R_PPC_GOT_TLSLD16:
4652 case R_PPC_GOT_TLSLD16_LO:
4653 case R_PPC_GOT_TLSLD16_HI:
4654 case R_PPC_GOT_TLSLD16_HA:
4655 tls_type = TLS_TLS | TLS_LD;
4658 case R_PPC_GOT_TPREL16:
4659 case R_PPC_GOT_TPREL16_LO:
4660 case R_PPC_GOT_TPREL16_HI:
4661 case R_PPC_GOT_TPREL16_HA:
4662 tls_type = TLS_TLS | TLS_TPREL;
4665 case R_PPC_GOT_DTPREL16:
4666 case R_PPC_GOT_DTPREL16_LO:
4667 case R_PPC_GOT_DTPREL16_HI:
4668 case R_PPC_GOT_DTPREL16_HA:
4669 tls_type = TLS_TLS | TLS_DTPREL;
4673 case R_PPC_GOT16_LO:
4674 case R_PPC_GOT16_HI:
4675 case R_PPC_GOT16_HA:
4678 /* Relocation is to the entry for this symbol in the global
4684 if (htab->got == NULL)
4688 if (tls_type == (TLS_TLS | TLS_LD)
4690 || !(h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC)))
4691 offp = &htab->tlsld_got.offset;
4695 dyn = htab->elf.dynamic_sections_created;
4696 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
4698 && SYMBOL_REFERENCES_LOCAL (info, h)))
4699 /* This is actually a static link, or it is a
4700 -Bsymbolic link and the symbol is defined
4701 locally, or the symbol was forced to be local
4702 because of a version file. */
4707 unresolved_reloc = FALSE;
4709 offp = &h->got.offset;
4713 if (local_got_offsets == NULL)
4715 offp = &local_got_offsets[r_symndx];
4718 /* The offset must always be a multiple of 4. We use the
4719 least significant bit to record whether we have already
4720 processed this entry. */
4728 /* Generate relocs for the dynamic linker, except in
4729 the case of TLSLD where we'll use one entry per
4731 if (info->shared || indx != 0)
4733 outrel.r_offset = (htab->got->output_section->vma
4734 + htab->got->output_offset
4736 if (tls_type & (TLS_LD | TLS_GD))
4738 outrel.r_info = ELF32_R_INFO (indx, R_PPC_DTPMOD32);
4739 outrel.r_addend = 0;
4740 if (tls_type == (TLS_TLS | TLS_GD))
4742 loc = htab->relgot->contents;
4743 loc += (htab->relgot->reloc_count++
4744 * sizeof (Elf32_External_Rela));
4745 bfd_elf32_swap_reloca_out (output_bfd,
4748 = ELF32_R_INFO (indx, R_PPC_DTPREL32);
4749 outrel.r_offset += 4;
4752 else if (tls_type == (TLS_TLS | TLS_DTPREL))
4753 outrel.r_info = ELF32_R_INFO (indx, R_PPC_DTPREL32);
4754 else if (tls_type == (TLS_TLS | TLS_TPREL))
4755 outrel.r_info = ELF32_R_INFO (indx, R_PPC_TPREL32);
4757 outrel.r_info = ELF32_R_INFO (indx, R_PPC_RELATIVE);
4759 outrel.r_info = ELF32_R_INFO (indx, R_PPC_GLOB_DAT);
4760 outrel.r_addend = 0;
4762 outrel.r_addend += relocation;
4763 loc = htab->relgot->contents;
4764 loc += (htab->relgot->reloc_count++
4765 * sizeof (Elf32_External_Rela));
4766 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
4769 /* Init the .got section contents if we're not
4770 emitting a reloc. */
4775 relocation -= htab->tls_sec->vma + DTP_OFFSET;
4776 if ((tls_type & TLS_TPREL) != 0)
4777 relocation += DTP_OFFSET - TP_OFFSET;
4780 if (tls_type == (TLS_TLS | TLS_GD))
4782 bfd_put_32 (output_bfd, relocation,
4783 htab->got->contents + off + 4);
4786 else if (tls_type == (TLS_TLS | TLS_LD))
4788 bfd_put_32 (output_bfd, relocation,
4789 htab->got->contents + off);
4793 if (off >= (bfd_vma) -2)
4796 relocation = htab->got->output_offset + off - 4;
4798 /* Addends on got relocations don't make much sense.
4799 x+off@got is actually x@got+off, and since the got is
4800 generated by a hash table traversal, the value in the
4801 got at entry m+n bears little relation to the entry m. */
4803 (*_bfd_error_handler)
4804 (_("%s(%s+0x%lx): non-zero addend on got reloc against `%s'"),
4805 bfd_archive_filename (input_bfd),
4806 bfd_get_section_name (input_bfd, input_section),
4807 (long) rel->r_offset,
4812 /* Relocations that need no special processing. */
4813 case R_PPC_LOCAL24PC:
4814 /* It makes no sense to point a local relocation
4815 at a symbol not in this object. */
4817 && (h->root.type == bfd_link_hash_defined
4818 || h->root.type == bfd_link_hash_defweak)
4819 && sec->output_section == NULL)
4821 if (! (*info->callbacks->undefined_symbol) (info,
4822 h->root.root.string,
4832 case R_PPC_DTPREL16:
4833 case R_PPC_DTPREL16_LO:
4834 case R_PPC_DTPREL16_HI:
4835 case R_PPC_DTPREL16_HA:
4836 addend -= htab->tls_sec->vma + DTP_OFFSET;
4839 /* Relocations that may need to be propagated if this is a shared
4842 case R_PPC_TPREL16_LO:
4843 case R_PPC_TPREL16_HI:
4844 case R_PPC_TPREL16_HA:
4845 addend -= htab->tls_sec->vma + TP_OFFSET;
4846 /* The TPREL16 relocs shouldn't really be used in shared
4847 libs as they will result in DT_TEXTREL being set, but
4848 support them anyway. */
4852 addend -= htab->tls_sec->vma + TP_OFFSET;
4855 case R_PPC_DTPREL32:
4856 addend -= htab->tls_sec->vma + DTP_OFFSET;
4862 case R_PPC_REL14_BRTAKEN:
4863 case R_PPC_REL14_BRNTAKEN:
4864 /* If these relocations are not to a named symbol, they can be
4865 handled right here, no need to bother the dynamic linker. */
4867 || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0
4868 || SYMBOL_REFERENCES_LOCAL (info, h))
4872 /* Relocations that always need to be propagated if this is a shared
4877 case R_PPC_ADDR16_LO:
4878 case R_PPC_ADDR16_HI:
4879 case R_PPC_ADDR16_HA:
4881 case R_PPC_ADDR14_BRTAKEN:
4882 case R_PPC_ADDR14_BRNTAKEN:
4885 case R_PPC_DTPMOD32:
4886 /* r_symndx will be zero only for relocs against symbols
4887 from removed linkonce sections, or sections discarded by
4895 && (MUST_BE_DYN_RELOC (r_type)
4899 || (h->elf_link_hash_flags
4900 & ELF_LINK_HASH_DEF_REGULAR) == 0))))
4901 || (ELIMINATE_COPY_RELOCS
4903 && (input_section->flags & SEC_ALLOC) != 0
4906 && (h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0
4907 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0
4908 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0))
4913 fprintf (stderr, "ppc_elf_relocate_section need to create relocation for %s\n",
4914 (h && h->root.root.string) ? h->root.root.string : "<unknown>");
4917 /* When generating a shared object, these relocations
4918 are copied into the output file to be resolved at run
4924 name = (bfd_elf_string_from_elf_section
4926 elf_elfheader (input_bfd)->e_shstrndx,
4927 elf_section_data (input_section)->rel_hdr.sh_name));
4931 BFD_ASSERT (strncmp (name, ".rela", 5) == 0
4932 && strcmp (bfd_get_section_name (input_bfd,
4936 sreloc = bfd_get_section_by_name (htab->elf.dynobj, name);
4937 BFD_ASSERT (sreloc != NULL);
4943 _bfd_elf_section_offset (output_bfd, info, input_section,
4945 if (outrel.r_offset == (bfd_vma) -1
4946 || outrel.r_offset == (bfd_vma) -2)
4947 skip = (int) outrel.r_offset;
4948 outrel.r_offset += (input_section->output_section->vma
4949 + input_section->output_offset);
4952 memset (&outrel, 0, sizeof outrel);
4953 /* h->dynindx may be -1 if this symbol was marked to
4956 && !SYMBOL_REFERENCES_LOCAL (info, h))
4958 unresolved_reloc = FALSE;
4959 outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
4960 outrel.r_addend = rel->r_addend;
4964 outrel.r_addend = relocation + rel->r_addend;
4966 if (r_type == R_PPC_ADDR32)
4967 outrel.r_info = ELF32_R_INFO (0, R_PPC_RELATIVE);
4972 if (bfd_is_abs_section (sec))
4974 else if (sec == NULL || sec->owner == NULL)
4976 bfd_set_error (bfd_error_bad_value);
4983 /* We are turning this relocation into one
4984 against a section symbol. It would be
4985 proper to subtract the symbol's value,
4986 osec->vma, from the emitted reloc addend,
4987 but ld.so expects buggy relocs. */
4988 osec = sec->output_section;
4989 indx = elf_section_data (osec)->dynindx;
4990 BFD_ASSERT (indx > 0);
4994 printf ("indx=%d section=%s flags=%08x name=%s\n",
4995 indx, osec->name, osec->flags,
4996 h->root.root.string);
5001 outrel.r_info = ELF32_R_INFO (indx, r_type);
5005 loc = sreloc->contents;
5006 loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rela);
5007 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
5012 /* This reloc will be computed at runtime. We clear the memory
5013 so that it contains predictable value. */
5015 && ((input_section->flags & SEC_ALLOC) != 0
5016 || ELF32_R_TYPE (outrel.r_info) != R_PPC_RELATIVE))
5018 relocation = howto->pc_relative ? outrel.r_offset : 0;
5025 /* Indirect .sdata relocation. */
5026 case R_PPC_EMB_SDAI16:
5027 BFD_ASSERT (htab->sdata != NULL);
5029 = bfd_elf32_finish_pointer_linker_section (output_bfd, input_bfd,
5030 info, htab->sdata, h,
5035 /* Indirect .sdata2 relocation. */
5036 case R_PPC_EMB_SDA2I16:
5037 BFD_ASSERT (htab->sdata2 != NULL);
5039 = bfd_elf32_finish_pointer_linker_section (output_bfd, input_bfd,
5040 info, htab->sdata2, h,
5045 /* Handle the TOC16 reloc. We want to use the offset within the .got
5046 section, not the actual VMA. This is appropriate when generating
5047 an embedded ELF object, for which the .got section acts like the
5048 AIX .toc section. */
5049 case R_PPC_TOC16: /* phony GOT16 relocations */
5050 BFD_ASSERT (sec != (asection *) 0);
5051 BFD_ASSERT (bfd_is_und_section (sec)
5052 || strcmp (bfd_get_section_name (abfd, sec), ".got") == 0
5053 || strcmp (bfd_get_section_name (abfd, sec), ".cgot") == 0)
5055 addend -= sec->output_section->vma + sec->output_offset + 0x8000;
5058 case R_PPC_PLTREL24:
5059 /* Relocation is to the entry for this symbol in the
5060 procedure linkage table. */
5061 BFD_ASSERT (h != NULL);
5063 if (h->plt.offset == (bfd_vma) -1
5064 || htab->plt == NULL)
5066 /* We didn't make a PLT entry for this symbol. This
5067 happens when statically linking PIC code, or when
5068 using -Bsymbolic. */
5072 unresolved_reloc = FALSE;
5073 relocation = (htab->plt->output_section->vma
5074 + htab->plt->output_offset
5078 /* Relocate against _SDA_BASE_. */
5079 case R_PPC_SDAREL16:
5082 const struct elf_link_hash_entry *sh;
5084 BFD_ASSERT (sec != (asection *) 0);
5085 name = bfd_get_section_name (abfd, sec->output_section);
5086 if (! ((strncmp (name, ".sdata", 6) == 0
5087 && (name[6] == 0 || name[6] == '.'))
5088 || (strncmp (name, ".sbss", 5) == 0
5089 && (name[5] == 0 || name[5] == '.'))))
5091 (*_bfd_error_handler) (_("%s: The target (%s) of a %s relocation is in the wrong output section (%s)"),
5092 bfd_archive_filename (input_bfd),
5097 sh = htab->sdata->sym_hash;
5098 addend -= (sh->root.u.def.value
5099 + sh->root.u.def.section->output_section->vma
5100 + sh->root.u.def.section->output_offset);
5104 /* Relocate against _SDA2_BASE_. */
5105 case R_PPC_EMB_SDA2REL:
5108 const struct elf_link_hash_entry *sh;
5110 BFD_ASSERT (sec != (asection *) 0);
5111 name = bfd_get_section_name (abfd, sec->output_section);
5112 if (! (strncmp (name, ".sdata2", 7) == 0
5113 || strncmp (name, ".sbss2", 6) == 0))
5115 (*_bfd_error_handler) (_("%s: The target (%s) of a %s relocation is in the wrong output section (%s)"),
5116 bfd_archive_filename (input_bfd),
5121 bfd_set_error (bfd_error_bad_value);
5125 sh = htab->sdata2->sym_hash;
5126 addend -= (sh->root.u.def.value
5127 + sh->root.u.def.section->output_section->vma
5128 + sh->root.u.def.section->output_offset);
5132 /* Relocate against either _SDA_BASE_, _SDA2_BASE_, or 0. */
5133 case R_PPC_EMB_SDA21:
5134 case R_PPC_EMB_RELSDA:
5137 const struct elf_link_hash_entry *sh;
5140 BFD_ASSERT (sec != (asection *) 0);
5141 name = bfd_get_section_name (abfd, sec->output_section);
5142 if (((strncmp (name, ".sdata", 6) == 0
5143 && (name[6] == 0 || name[6] == '.'))
5144 || (strncmp (name, ".sbss", 5) == 0
5145 && (name[5] == 0 || name[5] == '.'))))
5148 sh = htab->sdata->sym_hash;
5149 addend -= (sh->root.u.def.value
5150 + sh->root.u.def.section->output_section->vma
5151 + sh->root.u.def.section->output_offset);
5154 else if (strncmp (name, ".sdata2", 7) == 0
5155 || strncmp (name, ".sbss2", 6) == 0)
5158 sh = htab->sdata2->sym_hash;
5159 addend -= (sh->root.u.def.value
5160 + sh->root.u.def.section->output_section->vma
5161 + sh->root.u.def.section->output_offset);
5164 else if (strcmp (name, ".PPC.EMB.sdata0") == 0
5165 || strcmp (name, ".PPC.EMB.sbss0") == 0)
5172 (*_bfd_error_handler) (_("%s: The target (%s) of a %s relocation is in the wrong output section (%s)"),
5173 bfd_archive_filename (input_bfd),
5178 bfd_set_error (bfd_error_bad_value);
5183 if (r_type == R_PPC_EMB_SDA21)
5184 { /* fill in register field */
5185 insn = bfd_get_32 (output_bfd, contents + rel->r_offset);
5186 insn = (insn & ~RA_REGISTER_MASK) | (reg << RA_REGISTER_SHIFT);
5187 bfd_put_32 (output_bfd, insn, contents + rel->r_offset);
5192 /* Relocate against the beginning of the section. */
5194 case R_PPC_SECTOFF_LO:
5195 case R_PPC_SECTOFF_HI:
5196 case R_PPC_SECTOFF_HA:
5197 BFD_ASSERT (sec != (asection *) 0);
5198 addend -= sec->output_section->vma;
5201 /* Negative relocations. */
5202 case R_PPC_EMB_NADDR32:
5203 case R_PPC_EMB_NADDR16:
5204 case R_PPC_EMB_NADDR16_LO:
5205 case R_PPC_EMB_NADDR16_HI:
5206 case R_PPC_EMB_NADDR16_HA:
5207 addend -= 2 * relocation;
5211 case R_PPC_GLOB_DAT:
5212 case R_PPC_JMP_SLOT:
5213 case R_PPC_RELATIVE:
5215 case R_PPC_PLTREL32:
5216 case R_PPC_PLT16_LO:
5217 case R_PPC_PLT16_HI:
5218 case R_PPC_PLT16_HA:
5220 case R_PPC_EMB_RELSEC16:
5221 case R_PPC_EMB_RELST_LO:
5222 case R_PPC_EMB_RELST_HI:
5223 case R_PPC_EMB_RELST_HA:
5224 case R_PPC_EMB_BIT_FLD:
5225 (*_bfd_error_handler)
5226 (_("%s: Relocation %s is not yet supported for symbol %s."),
5227 bfd_archive_filename (input_bfd),
5231 bfd_set_error (bfd_error_invalid_operation);
5236 /* Do any further special processing. */
5242 case R_PPC_ADDR16_HA:
5243 case R_PPC_GOT16_HA:
5244 case R_PPC_PLT16_HA:
5245 case R_PPC_SECTOFF_HA:
5246 case R_PPC_TPREL16_HA:
5247 case R_PPC_DTPREL16_HA:
5248 case R_PPC_GOT_TLSGD16_HA:
5249 case R_PPC_GOT_TLSLD16_HA:
5250 case R_PPC_GOT_TPREL16_HA:
5251 case R_PPC_GOT_DTPREL16_HA:
5252 case R_PPC_EMB_NADDR16_HA:
5253 case R_PPC_EMB_RELST_HA:
5254 /* It's just possible that this symbol is a weak symbol
5255 that's not actually defined anywhere. In that case,
5256 'sec' would be NULL, and we should leave the symbol
5257 alone (it will be set to zero elsewhere in the link). */
5259 /* Add 0x10000 if sign bit in 0:15 is set. */
5260 addend += ((relocation + addend) & 0x8000) << 1;
5265 fprintf (stderr, "\ttype = %s (%d), name = %s, symbol index = %ld, offset = %ld, addend = %ld\n",
5270 (long) rel->r_offset,
5274 if (unresolved_reloc
5275 && !((input_section->flags & SEC_DEBUGGING) != 0
5276 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0))
5278 (*_bfd_error_handler)
5279 (_("%s(%s+0x%lx): unresolvable relocation against symbol `%s'"),
5280 bfd_archive_filename (input_bfd),
5281 bfd_get_section_name (input_bfd, input_section),
5282 (long) rel->r_offset,
5287 r = _bfd_final_link_relocate (howto,
5295 if (r != bfd_reloc_ok)
5297 if (sym_name == NULL)
5298 sym_name = "(null)";
5299 if (r == bfd_reloc_overflow)
5304 && h->root.type == bfd_link_hash_undefweak
5305 && howto->pc_relative)
5307 /* Assume this is a call protected by other code that
5308 detect the symbol is undefined. If this is the case,
5309 we can safely ignore the overflow. If not, the
5310 program is hosed anyway, and a little warning isn't
5316 if (! (*info->callbacks->reloc_overflow) (info,
5327 (*_bfd_error_handler)
5328 (_("%s(%s+0x%lx): reloc against `%s': error %d"),
5329 bfd_archive_filename (input_bfd),
5330 bfd_get_section_name (input_bfd, input_section),
5331 (long) rel->r_offset, sym_name, (int) r);
5338 fprintf (stderr, "\n");
5344 static enum elf_reloc_type_class
5345 ppc_elf_reloc_type_class (rela)
5346 const Elf_Internal_Rela *rela;
5348 switch ((int) ELF32_R_TYPE (rela->r_info))
5350 case R_PPC_RELATIVE:
5351 return reloc_class_relative;
5354 case R_PPC_JMP_SLOT:
5355 return reloc_class_plt;
5357 return reloc_class_copy;
5359 return reloc_class_normal;
5363 /* Support for core dump NOTE sections. */
5366 ppc_elf_grok_prstatus (abfd, note)
5368 Elf_Internal_Note *note;
5371 unsigned int raw_size;
5373 switch (note->descsz)
5378 case 268: /* Linux/PPC. */
5380 elf_tdata (abfd)->core_signal = bfd_get_16 (abfd, note->descdata + 12);
5383 elf_tdata (abfd)->core_pid = bfd_get_32 (abfd, note->descdata + 24);
5392 /* Make a ".reg/999" section. */
5393 return _bfd_elfcore_make_pseudosection (abfd, ".reg",
5394 raw_size, note->descpos + offset);
5398 ppc_elf_grok_psinfo (abfd, note)
5400 Elf_Internal_Note *note;
5402 switch (note->descsz)
5407 case 128: /* Linux/PPC elf_prpsinfo. */
5408 elf_tdata (abfd)->core_program
5409 = _bfd_elfcore_strndup (abfd, note->descdata + 32, 16);
5410 elf_tdata (abfd)->core_command
5411 = _bfd_elfcore_strndup (abfd, note->descdata + 48, 80);
5414 /* Note that for some reason, a spurious space is tacked
5415 onto the end of the args in some (at least one anyway)
5416 implementations, so strip it off if it exists. */
5419 char *command = elf_tdata (abfd)->core_command;
5420 int n = strlen (command);
5422 if (0 < n && command[n - 1] == ' ')
5423 command[n - 1] = '\0';
5429 /* Very simple linked list structure for recording apuinfo values. */
5430 typedef struct apuinfo_list
5432 struct apuinfo_list * next;
5433 unsigned long value;
5437 static apuinfo_list * head;
5439 static void apuinfo_list_init PARAMS ((void));
5440 static void apuinfo_list_add PARAMS ((unsigned long));
5441 static unsigned apuinfo_list_length PARAMS ((void));
5442 static unsigned long apuinfo_list_element PARAMS ((unsigned long));
5443 static void apuinfo_list_finish PARAMS ((void));
5445 extern void ppc_elf_begin_write_processing
5446 PARAMS ((bfd *, struct bfd_link_info *));
5447 extern void ppc_elf_final_write_processing
5448 PARAMS ((bfd *, bfd_boolean));
5449 extern bfd_boolean ppc_elf_write_section
5450 PARAMS ((bfd *, asection *, bfd_byte *));
5455 apuinfo_list_init PARAMS ((void))
5461 apuinfo_list_add (value)
5462 unsigned long value;
5464 apuinfo_list * entry = head;
5466 while (entry != NULL)
5468 if (entry->value == value)
5470 entry = entry->next;
5473 entry = bfd_malloc (sizeof (* entry));
5477 entry->value = value;
5483 apuinfo_list_length PARAMS ((void))
5485 apuinfo_list * entry;
5486 unsigned long count;
5488 for (entry = head, count = 0;
5490 entry = entry->next)
5496 static inline unsigned long
5497 apuinfo_list_element (number)
5498 unsigned long number;
5500 apuinfo_list * entry;
5504 entry = entry->next)
5507 return entry ? entry->value : 0;
5511 apuinfo_list_finish PARAMS ((void))
5513 apuinfo_list * entry;
5515 for (entry = head; entry;)
5517 apuinfo_list * next = entry->next;
5525 #define APUINFO_SECTION_NAME ".PPC.EMB.apuinfo"
5526 #define APUINFO_LABEL "APUinfo"
5528 /* Scan the input BFDs and create a linked list of
5529 the APUinfo values that will need to be emitted. */
5532 ppc_elf_begin_write_processing (abfd, link_info)
5534 struct bfd_link_info *link_info;
5539 unsigned num_input_sections;
5540 bfd_size_type output_section_size;
5542 unsigned num_entries;
5543 unsigned long offset;
5544 unsigned long length;
5545 const char * error_message = NULL;
5547 if (link_info == NULL)
5550 /* Scan the input bfds, looking for apuinfo sections. */
5551 num_input_sections = 0;
5552 output_section_size = 0;
5554 for (ibfd = link_info->input_bfds; ibfd; ibfd = ibfd->link_next)
5556 asec = bfd_get_section_by_name (ibfd, APUINFO_SECTION_NAME);
5559 ++ num_input_sections;
5560 output_section_size += asec->_raw_size;
5564 /* We need at least one input sections
5565 in order to make merging worthwhile. */
5566 if (num_input_sections < 1)
5569 /* Just make sure that the output section exists as well. */
5570 asec = bfd_get_section_by_name (abfd, APUINFO_SECTION_NAME);
5574 /* Allocate a buffer for the contents of the input sections. */
5575 buffer = bfd_malloc (output_section_size);
5580 apuinfo_list_init ();
5582 /* Read in the input sections contents. */
5583 for (ibfd = link_info->input_bfds; ibfd; ibfd = ibfd->link_next)
5585 unsigned long datum;
5589 asec = bfd_get_section_by_name (ibfd, APUINFO_SECTION_NAME);
5593 length = asec->_raw_size;
5596 error_message = _("corrupt or empty %s section in %s");
5600 if (bfd_seek (ibfd, asec->filepos, SEEK_SET) != 0
5601 || (bfd_bread (buffer + offset, length, ibfd) != length))
5603 error_message = _("unable to read in %s section from %s");
5607 /* Process the contents of the section. */
5608 ptr = buffer + offset;
5609 error_message = _("corrupt %s section in %s");
5611 /* Verify the contents of the header. Note - we have to
5612 extract the values this way in order to allow for a
5613 host whose endian-ness is different from the target. */
5614 datum = bfd_get_32 (ibfd, ptr);
5615 if (datum != sizeof APUINFO_LABEL)
5618 datum = bfd_get_32 (ibfd, ptr + 8);
5622 if (strcmp (ptr + 12, APUINFO_LABEL) != 0)
5625 /* Get the number of apuinfo entries. */
5626 datum = bfd_get_32 (ibfd, ptr + 4);
5627 if ((datum * 4 + 20) != length)
5630 /* Make sure that we do not run off the end of the section. */
5631 if (offset + length > output_section_size)
5634 /* Scan the apuinfo section, building a list of apuinfo numbers. */
5635 for (i = 0; i < datum; i++)
5636 apuinfo_list_add (bfd_get_32 (ibfd, ptr + 20 + (i * 4)));
5638 /* Update the offset. */
5642 error_message = NULL;
5644 /* Compute the size of the output section. */
5645 num_entries = apuinfo_list_length ();
5646 output_section_size = 20 + num_entries * 4;
5648 asec = bfd_get_section_by_name (abfd, APUINFO_SECTION_NAME);
5650 if (! bfd_set_section_size (abfd, asec, output_section_size))
5652 error_message = _("warning: unable to set size of %s section in %s");
5658 _bfd_error_handler (error_message, APUINFO_SECTION_NAME,
5659 bfd_archive_filename (ibfd));
5663 /* Prevent the output section from accumulating the input sections'
5664 contents. We have already stored this in our linked list structure. */
5667 ppc_elf_write_section (abfd, asec, contents)
5668 bfd * abfd ATTRIBUTE_UNUSED;
5670 bfd_byte * contents ATTRIBUTE_UNUSED;
5672 return apuinfo_list_length () && strcmp (asec->name, APUINFO_SECTION_NAME) == 0;
5676 /* Finally we can generate the output section. */
5679 ppc_elf_final_write_processing (abfd, linker)
5681 bfd_boolean linker ATTRIBUTE_UNUSED;
5686 unsigned num_entries;
5687 bfd_size_type length;
5689 asec = bfd_get_section_by_name (abfd, APUINFO_SECTION_NAME);
5693 if (apuinfo_list_length () == 0)
5696 length = asec->_raw_size;
5700 buffer = bfd_malloc (length);
5703 _bfd_error_handler (_("failed to allocate space for new APUinfo section."));
5707 /* Create the apuinfo header. */
5708 num_entries = apuinfo_list_length ();
5709 bfd_put_32 (abfd, sizeof APUINFO_LABEL, buffer);
5710 bfd_put_32 (abfd, num_entries, buffer + 4);
5711 bfd_put_32 (abfd, 0x2, buffer + 8);
5712 strcpy (buffer + 12, APUINFO_LABEL);
5715 for (i = 0; i < num_entries; i++)
5717 bfd_put_32 (abfd, apuinfo_list_element (i), buffer + length);
5721 if (length != asec->_raw_size)
5722 _bfd_error_handler (_("failed to compute new APUinfo section."));
5724 if (! bfd_set_section_contents (abfd, asec, buffer, (file_ptr) 0, length))
5725 _bfd_error_handler (_("failed to install new APUinfo section."));
5729 apuinfo_list_finish ();
5732 #define TARGET_LITTLE_SYM bfd_elf32_powerpcle_vec
5733 #define TARGET_LITTLE_NAME "elf32-powerpcle"
5734 #define TARGET_BIG_SYM bfd_elf32_powerpc_vec
5735 #define TARGET_BIG_NAME "elf32-powerpc"
5736 #define ELF_ARCH bfd_arch_powerpc
5737 #define ELF_MACHINE_CODE EM_PPC
5738 #define ELF_MAXPAGESIZE 0x10000
5739 #define elf_info_to_howto ppc_elf_info_to_howto
5741 #ifdef EM_CYGNUS_POWERPC
5742 #define ELF_MACHINE_ALT1 EM_CYGNUS_POWERPC
5746 #define ELF_MACHINE_ALT2 EM_PPC_OLD
5749 #define elf_backend_plt_not_loaded 1
5750 #define elf_backend_got_symbol_offset 4
5751 #define elf_backend_can_gc_sections 1
5752 #define elf_backend_can_refcount 1
5753 #define elf_backend_got_header_size 12
5754 #define elf_backend_plt_header_size PLT_INITIAL_ENTRY_SIZE
5755 #define elf_backend_rela_normal 1
5757 #define bfd_elf32_bfd_merge_private_bfd_data ppc_elf_merge_private_bfd_data
5758 #define bfd_elf32_bfd_relax_section ppc_elf_relax_section
5759 #define bfd_elf32_bfd_reloc_type_lookup ppc_elf_reloc_type_lookup
5760 #define bfd_elf32_bfd_set_private_flags ppc_elf_set_private_flags
5761 #define bfd_elf32_bfd_link_hash_table_create ppc_elf_link_hash_table_create
5763 #define elf_backend_object_p ppc_elf_object_p
5764 #define elf_backend_gc_mark_hook ppc_elf_gc_mark_hook
5765 #define elf_backend_gc_sweep_hook ppc_elf_gc_sweep_hook
5766 #define elf_backend_section_from_shdr ppc_elf_section_from_shdr
5767 #define elf_backend_relocate_section ppc_elf_relocate_section
5768 #define elf_backend_create_dynamic_sections ppc_elf_create_dynamic_sections
5769 #define elf_backend_check_relocs ppc_elf_check_relocs
5770 #define elf_backend_copy_indirect_symbol ppc_elf_copy_indirect_symbol
5771 #define elf_backend_adjust_dynamic_symbol ppc_elf_adjust_dynamic_symbol
5772 #define elf_backend_add_symbol_hook ppc_elf_add_symbol_hook
5773 #define elf_backend_size_dynamic_sections ppc_elf_size_dynamic_sections
5774 #define elf_backend_finish_dynamic_symbol ppc_elf_finish_dynamic_symbol
5775 #define elf_backend_finish_dynamic_sections ppc_elf_finish_dynamic_sections
5776 #define elf_backend_fake_sections ppc_elf_fake_sections
5777 #define elf_backend_additional_program_headers ppc_elf_additional_program_headers
5778 #define elf_backend_modify_segment_map ppc_elf_modify_segment_map
5779 #define elf_backend_grok_prstatus ppc_elf_grok_prstatus
5780 #define elf_backend_grok_psinfo ppc_elf_grok_psinfo
5781 #define elf_backend_reloc_type_class ppc_elf_reloc_type_class
5782 #define elf_backend_begin_write_processing ppc_elf_begin_write_processing
5783 #define elf_backend_final_write_processing ppc_elf_final_write_processing
5784 #define elf_backend_write_section ppc_elf_write_section
5786 #include "elf32-target.h"