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. */
182 /* PPC ELF linker hash entry. */
184 struct ppc_elf_link_hash_entry
186 struct elf_link_hash_entry elf;
188 /* Track dynamic relocs copied for this symbol. */
189 struct ppc_elf_dyn_relocs *dyn_relocs;
191 /* Contexts in which symbol is used in the GOT (or TOC).
192 TLS_GD .. TLS_EXPLICIT bits are or'd into the mask as the
193 corresponding relocs are encountered during check_relocs.
194 tls_optimize clears TLS_GD .. TLS_TPREL when optimizing to
195 indicate the corresponding GOT entry type is not needed. */
196 #define TLS_GD 1 /* GD reloc. */
197 #define TLS_LD 2 /* LD reloc. */
198 #define TLS_TPREL 4 /* TPREL reloc, => IE. */
199 #define TLS_DTPREL 8 /* DTPREL reloc, => LD. */
200 #define TLS_TLS 16 /* Any TLS reloc. */
201 #define TLS_TPRELGD 32 /* TPREL reloc resulting from GD->IE. */
205 #define ppc_elf_hash_entry(ent) ((struct ppc_elf_link_hash_entry *) (ent))
207 /* PPC ELF linker hash table. */
209 struct ppc_elf_link_hash_table
211 struct elf_link_hash_table elf;
213 /* Short-cuts to get to dynamic linker sections. */
222 elf_linker_section_t *sdata;
223 elf_linker_section_t *sdata2;
225 /* Short-cut to first output tls section. */
228 /* Shortcut to .__tls_get_addr. */
229 struct elf_link_hash_entry *tls_get_addr;
231 /* TLS local dynamic got entry handling. */
233 bfd_signed_vma refcount;
237 /* Small local sym to section mapping cache. */
238 struct sym_sec_cache sym_sec;
241 /* Get the PPC ELF linker hash table from a link_info structure. */
243 #define ppc_elf_hash_table(p) \
244 ((struct ppc_elf_link_hash_table *) (p)->hash)
246 /* Create an entry in a PPC ELF linker hash table. */
248 static struct bfd_hash_entry *
249 ppc_elf_link_hash_newfunc (entry, table, string)
250 struct bfd_hash_entry *entry;
251 struct bfd_hash_table *table;
254 /* Allocate the structure if it has not already been allocated by a
258 entry = bfd_hash_allocate (table,
259 sizeof (struct ppc_elf_link_hash_entry));
264 /* Call the allocation method of the superclass. */
265 entry = _bfd_elf_link_hash_newfunc (entry, table, string);
268 ppc_elf_hash_entry (entry)->dyn_relocs = NULL;
269 ppc_elf_hash_entry (entry)->tls_mask = 0;
275 /* Create a PPC ELF linker hash table. */
277 static struct bfd_link_hash_table *
278 ppc_elf_link_hash_table_create (abfd)
281 struct ppc_elf_link_hash_table *ret;
283 ret = ((struct ppc_elf_link_hash_table *)
284 bfd_malloc (sizeof (struct ppc_elf_link_hash_table)));
288 if (! _bfd_elf_link_hash_table_init (&ret->elf, abfd,
289 ppc_elf_link_hash_newfunc))
306 ret->tls_get_addr = NULL;
307 ret->tlsld_got.refcount = 0;
308 ret->sym_sec.abfd = NULL;
310 return &ret->elf.root;
313 /* Copy the extra info we tack onto an elf_link_hash_entry. */
316 ppc_elf_copy_indirect_symbol (bed, dir, ind)
317 struct elf_backend_data *bed;
318 struct elf_link_hash_entry *dir, *ind;
320 struct ppc_elf_link_hash_entry *edir, *eind;
322 edir = (struct ppc_elf_link_hash_entry *) dir;
323 eind = (struct ppc_elf_link_hash_entry *) ind;
325 if (eind->dyn_relocs != NULL)
327 if (edir->dyn_relocs != NULL)
329 struct ppc_elf_dyn_relocs **pp;
330 struct ppc_elf_dyn_relocs *p;
332 if (ind->root.type == bfd_link_hash_indirect)
335 /* Add reloc counts against the weak sym to the strong sym
336 list. Merge any entries against the same section. */
337 for (pp = &eind->dyn_relocs; (p = *pp) != NULL; )
339 struct ppc_elf_dyn_relocs *q;
341 for (q = edir->dyn_relocs; q != NULL; q = q->next)
342 if (q->sec == p->sec)
344 q->count += p->count;
351 *pp = edir->dyn_relocs;
354 edir->dyn_relocs = eind->dyn_relocs;
355 eind->dyn_relocs = NULL;
358 edir->tls_mask |= eind->tls_mask;
360 _bfd_elf_link_hash_copy_indirect (bed, dir, ind);
363 static reloc_howto_type *ppc_elf_howto_table[(int) R_PPC_max];
365 static reloc_howto_type ppc_elf_howto_raw[] = {
366 /* This reloc does nothing. */
367 HOWTO (R_PPC_NONE, /* type */
369 2, /* size (0 = byte, 1 = short, 2 = long) */
371 FALSE, /* pc_relative */
373 complain_overflow_bitfield, /* complain_on_overflow */
374 bfd_elf_generic_reloc, /* special_function */
375 "R_PPC_NONE", /* name */
376 FALSE, /* partial_inplace */
379 FALSE), /* pcrel_offset */
381 /* A standard 32 bit relocation. */
382 HOWTO (R_PPC_ADDR32, /* type */
384 2, /* size (0 = byte, 1 = short, 2 = long) */
386 FALSE, /* pc_relative */
388 complain_overflow_bitfield, /* complain_on_overflow */
389 bfd_elf_generic_reloc, /* special_function */
390 "R_PPC_ADDR32", /* name */
391 FALSE, /* partial_inplace */
393 0xffffffff, /* dst_mask */
394 FALSE), /* pcrel_offset */
396 /* An absolute 26 bit branch; the lower two bits must be zero.
397 FIXME: we don't check that, we just clear them. */
398 HOWTO (R_PPC_ADDR24, /* type */
400 2, /* size (0 = byte, 1 = short, 2 = long) */
402 FALSE, /* pc_relative */
404 complain_overflow_bitfield, /* complain_on_overflow */
405 bfd_elf_generic_reloc, /* special_function */
406 "R_PPC_ADDR24", /* name */
407 FALSE, /* partial_inplace */
409 0x3fffffc, /* dst_mask */
410 FALSE), /* pcrel_offset */
412 /* A standard 16 bit relocation. */
413 HOWTO (R_PPC_ADDR16, /* type */
415 1, /* size (0 = byte, 1 = short, 2 = long) */
417 FALSE, /* pc_relative */
419 complain_overflow_bitfield, /* complain_on_overflow */
420 bfd_elf_generic_reloc, /* special_function */
421 "R_PPC_ADDR16", /* name */
422 FALSE, /* partial_inplace */
424 0xffff, /* dst_mask */
425 FALSE), /* pcrel_offset */
427 /* A 16 bit relocation without overflow. */
428 HOWTO (R_PPC_ADDR16_LO, /* type */
430 1, /* size (0 = byte, 1 = short, 2 = long) */
432 FALSE, /* pc_relative */
434 complain_overflow_dont,/* complain_on_overflow */
435 bfd_elf_generic_reloc, /* special_function */
436 "R_PPC_ADDR16_LO", /* name */
437 FALSE, /* partial_inplace */
439 0xffff, /* dst_mask */
440 FALSE), /* pcrel_offset */
442 /* The high order 16 bits of an address. */
443 HOWTO (R_PPC_ADDR16_HI, /* type */
445 1, /* size (0 = byte, 1 = short, 2 = long) */
447 FALSE, /* pc_relative */
449 complain_overflow_dont, /* complain_on_overflow */
450 bfd_elf_generic_reloc, /* special_function */
451 "R_PPC_ADDR16_HI", /* name */
452 FALSE, /* partial_inplace */
454 0xffff, /* dst_mask */
455 FALSE), /* pcrel_offset */
457 /* The high order 16 bits of an address, plus 1 if the contents of
458 the low 16 bits, treated as a signed number, is negative. */
459 HOWTO (R_PPC_ADDR16_HA, /* type */
461 1, /* size (0 = byte, 1 = short, 2 = long) */
463 FALSE, /* pc_relative */
465 complain_overflow_dont, /* complain_on_overflow */
466 ppc_elf_addr16_ha_reloc, /* special_function */
467 "R_PPC_ADDR16_HA", /* name */
468 FALSE, /* partial_inplace */
470 0xffff, /* dst_mask */
471 FALSE), /* pcrel_offset */
473 /* An absolute 16 bit branch; the lower two bits must be zero.
474 FIXME: we don't check that, we just clear them. */
475 HOWTO (R_PPC_ADDR14, /* type */
477 2, /* size (0 = byte, 1 = short, 2 = long) */
479 FALSE, /* pc_relative */
481 complain_overflow_bitfield, /* complain_on_overflow */
482 bfd_elf_generic_reloc, /* special_function */
483 "R_PPC_ADDR14", /* name */
484 FALSE, /* partial_inplace */
486 0xfffc, /* dst_mask */
487 FALSE), /* pcrel_offset */
489 /* An absolute 16 bit branch, for which bit 10 should be set to
490 indicate that the branch is expected to be taken. The lower two
491 bits must be zero. */
492 HOWTO (R_PPC_ADDR14_BRTAKEN, /* type */
494 2, /* size (0 = byte, 1 = short, 2 = long) */
496 FALSE, /* pc_relative */
498 complain_overflow_bitfield, /* complain_on_overflow */
499 bfd_elf_generic_reloc, /* special_function */
500 "R_PPC_ADDR14_BRTAKEN",/* name */
501 FALSE, /* partial_inplace */
503 0xfffc, /* dst_mask */
504 FALSE), /* pcrel_offset */
506 /* An absolute 16 bit branch, for which bit 10 should be set to
507 indicate that the branch is not expected to be taken. The lower
508 two bits must be zero. */
509 HOWTO (R_PPC_ADDR14_BRNTAKEN, /* type */
511 2, /* size (0 = byte, 1 = short, 2 = long) */
513 FALSE, /* pc_relative */
515 complain_overflow_bitfield, /* complain_on_overflow */
516 bfd_elf_generic_reloc, /* special_function */
517 "R_PPC_ADDR14_BRNTAKEN",/* name */
518 FALSE, /* partial_inplace */
520 0xfffc, /* dst_mask */
521 FALSE), /* pcrel_offset */
523 /* A relative 26 bit branch; the lower two bits must be zero. */
524 HOWTO (R_PPC_REL24, /* type */
526 2, /* size (0 = byte, 1 = short, 2 = long) */
528 TRUE, /* pc_relative */
530 complain_overflow_signed, /* complain_on_overflow */
531 bfd_elf_generic_reloc, /* special_function */
532 "R_PPC_REL24", /* name */
533 FALSE, /* partial_inplace */
535 0x3fffffc, /* dst_mask */
536 TRUE), /* pcrel_offset */
538 /* A relative 16 bit branch; the lower two bits must be zero. */
539 HOWTO (R_PPC_REL14, /* type */
541 2, /* size (0 = byte, 1 = short, 2 = long) */
543 TRUE, /* pc_relative */
545 complain_overflow_signed, /* complain_on_overflow */
546 bfd_elf_generic_reloc, /* special_function */
547 "R_PPC_REL14", /* name */
548 FALSE, /* partial_inplace */
550 0xfffc, /* dst_mask */
551 TRUE), /* pcrel_offset */
553 /* A relative 16 bit branch. Bit 10 should be set to indicate that
554 the branch is expected to be taken. The lower two bits must be
556 HOWTO (R_PPC_REL14_BRTAKEN, /* type */
558 2, /* size (0 = byte, 1 = short, 2 = long) */
560 TRUE, /* pc_relative */
562 complain_overflow_signed, /* complain_on_overflow */
563 bfd_elf_generic_reloc, /* special_function */
564 "R_PPC_REL14_BRTAKEN", /* name */
565 FALSE, /* partial_inplace */
567 0xfffc, /* dst_mask */
568 TRUE), /* pcrel_offset */
570 /* A relative 16 bit branch. Bit 10 should be set to indicate that
571 the branch is not expected to be taken. The lower two bits must
573 HOWTO (R_PPC_REL14_BRNTAKEN, /* type */
575 2, /* size (0 = byte, 1 = short, 2 = long) */
577 TRUE, /* pc_relative */
579 complain_overflow_signed, /* complain_on_overflow */
580 bfd_elf_generic_reloc, /* special_function */
581 "R_PPC_REL14_BRNTAKEN",/* name */
582 FALSE, /* partial_inplace */
584 0xfffc, /* dst_mask */
585 TRUE), /* pcrel_offset */
587 /* Like R_PPC_ADDR16, but referring to the GOT table entry for the
589 HOWTO (R_PPC_GOT16, /* type */
591 1, /* size (0 = byte, 1 = short, 2 = long) */
593 FALSE, /* pc_relative */
595 complain_overflow_signed, /* complain_on_overflow */
596 bfd_elf_generic_reloc, /* special_function */
597 "R_PPC_GOT16", /* name */
598 FALSE, /* partial_inplace */
600 0xffff, /* dst_mask */
601 FALSE), /* pcrel_offset */
603 /* Like R_PPC_ADDR16_LO, but referring to the GOT table entry for
605 HOWTO (R_PPC_GOT16_LO, /* type */
607 1, /* size (0 = byte, 1 = short, 2 = long) */
609 FALSE, /* pc_relative */
611 complain_overflow_dont, /* complain_on_overflow */
612 bfd_elf_generic_reloc, /* special_function */
613 "R_PPC_GOT16_LO", /* name */
614 FALSE, /* partial_inplace */
616 0xffff, /* dst_mask */
617 FALSE), /* pcrel_offset */
619 /* Like R_PPC_ADDR16_HI, but referring to the GOT table entry for
621 HOWTO (R_PPC_GOT16_HI, /* type */
623 1, /* size (0 = byte, 1 = short, 2 = long) */
625 FALSE, /* pc_relative */
627 complain_overflow_bitfield, /* complain_on_overflow */
628 bfd_elf_generic_reloc, /* special_function */
629 "R_PPC_GOT16_HI", /* name */
630 FALSE, /* partial_inplace */
632 0xffff, /* dst_mask */
633 FALSE), /* pcrel_offset */
635 /* Like R_PPC_ADDR16_HA, but referring to the GOT table entry for
637 HOWTO (R_PPC_GOT16_HA, /* type */
639 1, /* size (0 = byte, 1 = short, 2 = long) */
641 FALSE, /* pc_relative */
643 complain_overflow_bitfield, /* complain_on_overflow */
644 ppc_elf_addr16_ha_reloc, /* special_function */
645 "R_PPC_GOT16_HA", /* name */
646 FALSE, /* partial_inplace */
648 0xffff, /* dst_mask */
649 FALSE), /* pcrel_offset */
651 /* Like R_PPC_REL24, but referring to the procedure linkage table
652 entry for the symbol. */
653 HOWTO (R_PPC_PLTREL24, /* type */
655 2, /* size (0 = byte, 1 = short, 2 = long) */
657 TRUE, /* pc_relative */
659 complain_overflow_signed, /* complain_on_overflow */
660 bfd_elf_generic_reloc, /* special_function */
661 "R_PPC_PLTREL24", /* name */
662 FALSE, /* partial_inplace */
664 0x3fffffc, /* dst_mask */
665 TRUE), /* pcrel_offset */
667 /* This is used only by the dynamic linker. The symbol should exist
668 both in the object being run and in some shared library. The
669 dynamic linker copies the data addressed by the symbol from the
670 shared library into the object, because the object being
671 run has to have the data at some particular address. */
672 HOWTO (R_PPC_COPY, /* type */
674 2, /* size (0 = byte, 1 = short, 2 = long) */
676 FALSE, /* pc_relative */
678 complain_overflow_bitfield, /* complain_on_overflow */
679 bfd_elf_generic_reloc, /* special_function */
680 "R_PPC_COPY", /* name */
681 FALSE, /* partial_inplace */
684 FALSE), /* pcrel_offset */
686 /* Like R_PPC_ADDR32, but used when setting global offset table
688 HOWTO (R_PPC_GLOB_DAT, /* type */
690 2, /* size (0 = byte, 1 = short, 2 = long) */
692 FALSE, /* pc_relative */
694 complain_overflow_bitfield, /* complain_on_overflow */
695 bfd_elf_generic_reloc, /* special_function */
696 "R_PPC_GLOB_DAT", /* name */
697 FALSE, /* partial_inplace */
699 0xffffffff, /* dst_mask */
700 FALSE), /* pcrel_offset */
702 /* Marks a procedure linkage table entry for a symbol. */
703 HOWTO (R_PPC_JMP_SLOT, /* type */
705 2, /* size (0 = byte, 1 = short, 2 = long) */
707 FALSE, /* pc_relative */
709 complain_overflow_bitfield, /* complain_on_overflow */
710 bfd_elf_generic_reloc, /* special_function */
711 "R_PPC_JMP_SLOT", /* name */
712 FALSE, /* partial_inplace */
715 FALSE), /* pcrel_offset */
717 /* Used only by the dynamic linker. When the object is run, this
718 longword is set to the load address of the object, plus the
720 HOWTO (R_PPC_RELATIVE, /* type */
722 2, /* size (0 = byte, 1 = short, 2 = long) */
724 FALSE, /* pc_relative */
726 complain_overflow_bitfield, /* complain_on_overflow */
727 bfd_elf_generic_reloc, /* special_function */
728 "R_PPC_RELATIVE", /* name */
729 FALSE, /* partial_inplace */
731 0xffffffff, /* dst_mask */
732 FALSE), /* pcrel_offset */
734 /* Like R_PPC_REL24, but uses the value of the symbol within the
735 object rather than the final value. Normally used for
736 _GLOBAL_OFFSET_TABLE_. */
737 HOWTO (R_PPC_LOCAL24PC, /* type */
739 2, /* size (0 = byte, 1 = short, 2 = long) */
741 TRUE, /* pc_relative */
743 complain_overflow_signed, /* complain_on_overflow */
744 bfd_elf_generic_reloc, /* special_function */
745 "R_PPC_LOCAL24PC", /* name */
746 FALSE, /* partial_inplace */
748 0x3fffffc, /* dst_mask */
749 TRUE), /* pcrel_offset */
751 /* Like R_PPC_ADDR32, but may be unaligned. */
752 HOWTO (R_PPC_UADDR32, /* type */
754 2, /* size (0 = byte, 1 = short, 2 = long) */
756 FALSE, /* pc_relative */
758 complain_overflow_bitfield, /* complain_on_overflow */
759 bfd_elf_generic_reloc, /* special_function */
760 "R_PPC_UADDR32", /* name */
761 FALSE, /* partial_inplace */
763 0xffffffff, /* dst_mask */
764 FALSE), /* pcrel_offset */
766 /* Like R_PPC_ADDR16, but may be unaligned. */
767 HOWTO (R_PPC_UADDR16, /* type */
769 1, /* size (0 = byte, 1 = short, 2 = long) */
771 FALSE, /* pc_relative */
773 complain_overflow_bitfield, /* complain_on_overflow */
774 bfd_elf_generic_reloc, /* special_function */
775 "R_PPC_UADDR16", /* name */
776 FALSE, /* partial_inplace */
778 0xffff, /* dst_mask */
779 FALSE), /* pcrel_offset */
781 /* 32-bit PC relative */
782 HOWTO (R_PPC_REL32, /* type */
784 2, /* size (0 = byte, 1 = short, 2 = long) */
786 TRUE, /* pc_relative */
788 complain_overflow_bitfield, /* complain_on_overflow */
789 bfd_elf_generic_reloc, /* special_function */
790 "R_PPC_REL32", /* name */
791 FALSE, /* partial_inplace */
793 0xffffffff, /* dst_mask */
794 TRUE), /* pcrel_offset */
796 /* 32-bit relocation to the symbol's procedure linkage table.
797 FIXME: not supported. */
798 HOWTO (R_PPC_PLT32, /* type */
800 2, /* size (0 = byte, 1 = short, 2 = long) */
802 FALSE, /* pc_relative */
804 complain_overflow_bitfield, /* complain_on_overflow */
805 bfd_elf_generic_reloc, /* special_function */
806 "R_PPC_PLT32", /* name */
807 FALSE, /* partial_inplace */
810 FALSE), /* pcrel_offset */
812 /* 32-bit PC relative relocation to the symbol's procedure linkage table.
813 FIXME: not supported. */
814 HOWTO (R_PPC_PLTREL32, /* type */
816 2, /* size (0 = byte, 1 = short, 2 = long) */
818 TRUE, /* pc_relative */
820 complain_overflow_bitfield, /* complain_on_overflow */
821 bfd_elf_generic_reloc, /* special_function */
822 "R_PPC_PLTREL32", /* name */
823 FALSE, /* partial_inplace */
826 TRUE), /* pcrel_offset */
828 /* Like R_PPC_ADDR16_LO, but referring to the PLT table entry for
830 HOWTO (R_PPC_PLT16_LO, /* type */
832 1, /* size (0 = byte, 1 = short, 2 = long) */
834 FALSE, /* pc_relative */
836 complain_overflow_dont, /* complain_on_overflow */
837 bfd_elf_generic_reloc, /* special_function */
838 "R_PPC_PLT16_LO", /* name */
839 FALSE, /* partial_inplace */
841 0xffff, /* dst_mask */
842 FALSE), /* pcrel_offset */
844 /* Like R_PPC_ADDR16_HI, but referring to the PLT table entry for
846 HOWTO (R_PPC_PLT16_HI, /* type */
848 1, /* size (0 = byte, 1 = short, 2 = long) */
850 FALSE, /* pc_relative */
852 complain_overflow_bitfield, /* complain_on_overflow */
853 bfd_elf_generic_reloc, /* special_function */
854 "R_PPC_PLT16_HI", /* name */
855 FALSE, /* partial_inplace */
857 0xffff, /* dst_mask */
858 FALSE), /* pcrel_offset */
860 /* Like R_PPC_ADDR16_HA, but referring to the PLT table entry for
862 HOWTO (R_PPC_PLT16_HA, /* type */
864 1, /* size (0 = byte, 1 = short, 2 = long) */
866 FALSE, /* pc_relative */
868 complain_overflow_bitfield, /* complain_on_overflow */
869 ppc_elf_addr16_ha_reloc, /* special_function */
870 "R_PPC_PLT16_HA", /* name */
871 FALSE, /* partial_inplace */
873 0xffff, /* dst_mask */
874 FALSE), /* pcrel_offset */
876 /* A sign-extended 16 bit value relative to _SDA_BASE_, for use with
878 HOWTO (R_PPC_SDAREL16, /* type */
880 1, /* size (0 = byte, 1 = short, 2 = long) */
882 FALSE, /* pc_relative */
884 complain_overflow_signed, /* complain_on_overflow */
885 bfd_elf_generic_reloc, /* special_function */
886 "R_PPC_SDAREL16", /* name */
887 FALSE, /* partial_inplace */
889 0xffff, /* dst_mask */
890 FALSE), /* pcrel_offset */
892 /* 16-bit section relative relocation. */
893 HOWTO (R_PPC_SECTOFF, /* type */
895 1, /* size (0 = byte, 1 = short, 2 = long) */
897 FALSE, /* pc_relative */
899 complain_overflow_bitfield, /* complain_on_overflow */
900 bfd_elf_generic_reloc, /* special_function */
901 "R_PPC_SECTOFF", /* name */
902 FALSE, /* partial_inplace */
904 0xffff, /* dst_mask */
905 FALSE), /* pcrel_offset */
907 /* 16-bit lower half section relative relocation. */
908 HOWTO (R_PPC_SECTOFF_LO, /* type */
910 1, /* size (0 = byte, 1 = short, 2 = long) */
912 FALSE, /* pc_relative */
914 complain_overflow_dont, /* complain_on_overflow */
915 bfd_elf_generic_reloc, /* special_function */
916 "R_PPC_SECTOFF_LO", /* name */
917 FALSE, /* partial_inplace */
919 0xffff, /* dst_mask */
920 FALSE), /* pcrel_offset */
922 /* 16-bit upper half section relative relocation. */
923 HOWTO (R_PPC_SECTOFF_HI, /* type */
925 1, /* size (0 = byte, 1 = short, 2 = long) */
927 FALSE, /* pc_relative */
929 complain_overflow_bitfield, /* complain_on_overflow */
930 bfd_elf_generic_reloc, /* special_function */
931 "R_PPC_SECTOFF_HI", /* name */
932 FALSE, /* partial_inplace */
934 0xffff, /* dst_mask */
935 FALSE), /* pcrel_offset */
937 /* 16-bit upper half adjusted section relative relocation. */
938 HOWTO (R_PPC_SECTOFF_HA, /* type */
940 1, /* size (0 = byte, 1 = short, 2 = long) */
942 FALSE, /* pc_relative */
944 complain_overflow_bitfield, /* complain_on_overflow */
945 ppc_elf_addr16_ha_reloc, /* special_function */
946 "R_PPC_SECTOFF_HA", /* name */
947 FALSE, /* partial_inplace */
949 0xffff, /* dst_mask */
950 FALSE), /* pcrel_offset */
952 /* Marker reloc for TLS. */
955 2, /* size (0 = byte, 1 = short, 2 = long) */
957 FALSE, /* pc_relative */
959 complain_overflow_dont, /* complain_on_overflow */
960 bfd_elf_generic_reloc, /* special_function */
961 "R_PPC_TLS", /* name */
962 FALSE, /* partial_inplace */
965 FALSE), /* pcrel_offset */
967 /* Computes the load module index of the load module that contains the
968 definition of its TLS sym. */
969 HOWTO (R_PPC_DTPMOD32,
971 2, /* size (0 = byte, 1 = short, 2 = long) */
973 FALSE, /* pc_relative */
975 complain_overflow_dont, /* complain_on_overflow */
976 ppc_elf_unhandled_reloc, /* special_function */
977 "R_PPC_DTPMOD32", /* name */
978 FALSE, /* partial_inplace */
980 0xffffffff, /* dst_mask */
981 FALSE), /* pcrel_offset */
983 /* Computes a dtv-relative displacement, the difference between the value
984 of sym+add and the base address of the thread-local storage block that
985 contains the definition of sym, minus 0x8000. */
986 HOWTO (R_PPC_DTPREL32,
988 2, /* size (0 = byte, 1 = short, 2 = long) */
990 FALSE, /* pc_relative */
992 complain_overflow_dont, /* complain_on_overflow */
993 ppc_elf_unhandled_reloc, /* special_function */
994 "R_PPC_DTPREL32", /* name */
995 FALSE, /* partial_inplace */
997 0xffffffff, /* dst_mask */
998 FALSE), /* pcrel_offset */
1000 /* A 16 bit dtprel reloc. */
1001 HOWTO (R_PPC_DTPREL16,
1003 1, /* size (0 = byte, 1 = short, 2 = long) */
1005 FALSE, /* pc_relative */
1007 complain_overflow_signed, /* complain_on_overflow */
1008 ppc_elf_unhandled_reloc, /* special_function */
1009 "R_PPC_DTPREL16", /* name */
1010 FALSE, /* partial_inplace */
1012 0xffff, /* dst_mask */
1013 FALSE), /* pcrel_offset */
1015 /* Like DTPREL16, but no overflow. */
1016 HOWTO (R_PPC_DTPREL16_LO,
1018 1, /* size (0 = byte, 1 = short, 2 = long) */
1020 FALSE, /* pc_relative */
1022 complain_overflow_dont, /* complain_on_overflow */
1023 ppc_elf_unhandled_reloc, /* special_function */
1024 "R_PPC_DTPREL16_LO", /* name */
1025 FALSE, /* partial_inplace */
1027 0xffff, /* dst_mask */
1028 FALSE), /* pcrel_offset */
1030 /* Like DTPREL16_LO, but next higher group of 16 bits. */
1031 HOWTO (R_PPC_DTPREL16_HI,
1032 16, /* rightshift */
1033 1, /* size (0 = byte, 1 = short, 2 = long) */
1035 FALSE, /* pc_relative */
1037 complain_overflow_dont, /* complain_on_overflow */
1038 ppc_elf_unhandled_reloc, /* special_function */
1039 "R_PPC_DTPREL16_HI", /* name */
1040 FALSE, /* partial_inplace */
1042 0xffff, /* dst_mask */
1043 FALSE), /* pcrel_offset */
1045 /* Like DTPREL16_HI, but adjust for low 16 bits. */
1046 HOWTO (R_PPC_DTPREL16_HA,
1047 16, /* rightshift */
1048 1, /* size (0 = byte, 1 = short, 2 = long) */
1050 FALSE, /* pc_relative */
1052 complain_overflow_dont, /* complain_on_overflow */
1053 ppc_elf_unhandled_reloc, /* special_function */
1054 "R_PPC_DTPREL16_HA", /* name */
1055 FALSE, /* partial_inplace */
1057 0xffff, /* dst_mask */
1058 FALSE), /* pcrel_offset */
1060 /* Computes a tp-relative displacement, the difference between the value of
1061 sym+add and the value of the thread pointer (r13). */
1062 HOWTO (R_PPC_TPREL32,
1064 2, /* size (0 = byte, 1 = short, 2 = long) */
1066 FALSE, /* pc_relative */
1068 complain_overflow_dont, /* complain_on_overflow */
1069 ppc_elf_unhandled_reloc, /* special_function */
1070 "R_PPC_TPREL32", /* name */
1071 FALSE, /* partial_inplace */
1073 0xffffffff, /* dst_mask */
1074 FALSE), /* pcrel_offset */
1076 /* A 16 bit tprel reloc. */
1077 HOWTO (R_PPC_TPREL16,
1079 1, /* size (0 = byte, 1 = short, 2 = long) */
1081 FALSE, /* pc_relative */
1083 complain_overflow_signed, /* complain_on_overflow */
1084 ppc_elf_unhandled_reloc, /* special_function */
1085 "R_PPC_TPREL16", /* name */
1086 FALSE, /* partial_inplace */
1088 0xffff, /* dst_mask */
1089 FALSE), /* pcrel_offset */
1091 /* Like TPREL16, but no overflow. */
1092 HOWTO (R_PPC_TPREL16_LO,
1094 1, /* size (0 = byte, 1 = short, 2 = long) */
1096 FALSE, /* pc_relative */
1098 complain_overflow_dont, /* complain_on_overflow */
1099 ppc_elf_unhandled_reloc, /* special_function */
1100 "R_PPC_TPREL16_LO", /* name */
1101 FALSE, /* partial_inplace */
1103 0xffff, /* dst_mask */
1104 FALSE), /* pcrel_offset */
1106 /* Like TPREL16_LO, but next higher group of 16 bits. */
1107 HOWTO (R_PPC_TPREL16_HI,
1108 16, /* rightshift */
1109 1, /* size (0 = byte, 1 = short, 2 = long) */
1111 FALSE, /* pc_relative */
1113 complain_overflow_dont, /* complain_on_overflow */
1114 ppc_elf_unhandled_reloc, /* special_function */
1115 "R_PPC_TPREL16_HI", /* name */
1116 FALSE, /* partial_inplace */
1118 0xffff, /* dst_mask */
1119 FALSE), /* pcrel_offset */
1121 /* Like TPREL16_HI, but adjust for low 16 bits. */
1122 HOWTO (R_PPC_TPREL16_HA,
1123 16, /* rightshift */
1124 1, /* size (0 = byte, 1 = short, 2 = long) */
1126 FALSE, /* pc_relative */
1128 complain_overflow_dont, /* complain_on_overflow */
1129 ppc_elf_unhandled_reloc, /* special_function */
1130 "R_PPC_TPREL16_HA", /* name */
1131 FALSE, /* partial_inplace */
1133 0xffff, /* dst_mask */
1134 FALSE), /* pcrel_offset */
1136 /* Allocates two contiguous entries in the GOT to hold a tls_index structure,
1137 with values (sym+add)@dtpmod and (sym+add)@dtprel, and computes the offset
1138 to the first entry. */
1139 HOWTO (R_PPC_GOT_TLSGD16,
1141 1, /* size (0 = byte, 1 = short, 2 = long) */
1143 FALSE, /* pc_relative */
1145 complain_overflow_signed, /* complain_on_overflow */
1146 ppc_elf_unhandled_reloc, /* special_function */
1147 "R_PPC_GOT_TLSGD16", /* name */
1148 FALSE, /* partial_inplace */
1150 0xffff, /* dst_mask */
1151 FALSE), /* pcrel_offset */
1153 /* Like GOT_TLSGD16, but no overflow. */
1154 HOWTO (R_PPC_GOT_TLSGD16_LO,
1156 1, /* size (0 = byte, 1 = short, 2 = long) */
1158 FALSE, /* pc_relative */
1160 complain_overflow_dont, /* complain_on_overflow */
1161 ppc_elf_unhandled_reloc, /* special_function */
1162 "R_PPC_GOT_TLSGD16_LO", /* name */
1163 FALSE, /* partial_inplace */
1165 0xffff, /* dst_mask */
1166 FALSE), /* pcrel_offset */
1168 /* Like GOT_TLSGD16_LO, but next higher group of 16 bits. */
1169 HOWTO (R_PPC_GOT_TLSGD16_HI,
1170 16, /* rightshift */
1171 1, /* size (0 = byte, 1 = short, 2 = long) */
1173 FALSE, /* pc_relative */
1175 complain_overflow_dont, /* complain_on_overflow */
1176 ppc_elf_unhandled_reloc, /* special_function */
1177 "R_PPC_GOT_TLSGD16_HI", /* name */
1178 FALSE, /* partial_inplace */
1180 0xffff, /* dst_mask */
1181 FALSE), /* pcrel_offset */
1183 /* Like GOT_TLSGD16_HI, but adjust for low 16 bits. */
1184 HOWTO (R_PPC_GOT_TLSGD16_HA,
1185 16, /* rightshift */
1186 1, /* size (0 = byte, 1 = short, 2 = long) */
1188 FALSE, /* pc_relative */
1190 complain_overflow_dont, /* complain_on_overflow */
1191 ppc_elf_unhandled_reloc, /* special_function */
1192 "R_PPC_GOT_TLSGD16_HA", /* name */
1193 FALSE, /* partial_inplace */
1195 0xffff, /* dst_mask */
1196 FALSE), /* pcrel_offset */
1198 /* Allocates two contiguous entries in the GOT to hold a tls_index structure,
1199 with values (sym+add)@dtpmod and zero, and computes the offset to the
1201 HOWTO (R_PPC_GOT_TLSLD16,
1203 1, /* size (0 = byte, 1 = short, 2 = long) */
1205 FALSE, /* pc_relative */
1207 complain_overflow_signed, /* complain_on_overflow */
1208 ppc_elf_unhandled_reloc, /* special_function */
1209 "R_PPC_GOT_TLSLD16", /* name */
1210 FALSE, /* partial_inplace */
1212 0xffff, /* dst_mask */
1213 FALSE), /* pcrel_offset */
1215 /* Like GOT_TLSLD16, but no overflow. */
1216 HOWTO (R_PPC_GOT_TLSLD16_LO,
1218 1, /* size (0 = byte, 1 = short, 2 = long) */
1220 FALSE, /* pc_relative */
1222 complain_overflow_dont, /* complain_on_overflow */
1223 ppc_elf_unhandled_reloc, /* special_function */
1224 "R_PPC_GOT_TLSLD16_LO", /* name */
1225 FALSE, /* partial_inplace */
1227 0xffff, /* dst_mask */
1228 FALSE), /* pcrel_offset */
1230 /* Like GOT_TLSLD16_LO, but next higher group of 16 bits. */
1231 HOWTO (R_PPC_GOT_TLSLD16_HI,
1232 16, /* rightshift */
1233 1, /* size (0 = byte, 1 = short, 2 = long) */
1235 FALSE, /* pc_relative */
1237 complain_overflow_dont, /* complain_on_overflow */
1238 ppc_elf_unhandled_reloc, /* special_function */
1239 "R_PPC_GOT_TLSLD16_HI", /* name */
1240 FALSE, /* partial_inplace */
1242 0xffff, /* dst_mask */
1243 FALSE), /* pcrel_offset */
1245 /* Like GOT_TLSLD16_HI, but adjust for low 16 bits. */
1246 HOWTO (R_PPC_GOT_TLSLD16_HA,
1247 16, /* rightshift */
1248 1, /* size (0 = byte, 1 = short, 2 = long) */
1250 FALSE, /* pc_relative */
1252 complain_overflow_dont, /* complain_on_overflow */
1253 ppc_elf_unhandled_reloc, /* special_function */
1254 "R_PPC_GOT_TLSLD16_HA", /* name */
1255 FALSE, /* partial_inplace */
1257 0xffff, /* dst_mask */
1258 FALSE), /* pcrel_offset */
1260 /* Allocates an entry in the GOT with value (sym+add)@dtprel, and computes
1261 the offset to the entry. */
1262 HOWTO (R_PPC_GOT_DTPREL16,
1264 1, /* size (0 = byte, 1 = short, 2 = long) */
1266 FALSE, /* pc_relative */
1268 complain_overflow_signed, /* complain_on_overflow */
1269 ppc_elf_unhandled_reloc, /* special_function */
1270 "R_PPC_GOT_DTPREL16", /* name */
1271 FALSE, /* partial_inplace */
1273 0xffff, /* dst_mask */
1274 FALSE), /* pcrel_offset */
1276 /* Like GOT_DTPREL16, but no overflow. */
1277 HOWTO (R_PPC_GOT_DTPREL16_LO,
1279 1, /* size (0 = byte, 1 = short, 2 = long) */
1281 FALSE, /* pc_relative */
1283 complain_overflow_dont, /* complain_on_overflow */
1284 ppc_elf_unhandled_reloc, /* special_function */
1285 "R_PPC_GOT_DTPREL16_LO", /* name */
1286 FALSE, /* partial_inplace */
1288 0xffff, /* dst_mask */
1289 FALSE), /* pcrel_offset */
1291 /* Like GOT_DTPREL16_LO, but next higher group of 16 bits. */
1292 HOWTO (R_PPC_GOT_DTPREL16_HI,
1293 16, /* rightshift */
1294 1, /* size (0 = byte, 1 = short, 2 = long) */
1296 FALSE, /* pc_relative */
1298 complain_overflow_dont, /* complain_on_overflow */
1299 ppc_elf_unhandled_reloc, /* special_function */
1300 "R_PPC_GOT_DTPREL16_HI", /* name */
1301 FALSE, /* partial_inplace */
1303 0xffff, /* dst_mask */
1304 FALSE), /* pcrel_offset */
1306 /* Like GOT_DTPREL16_HI, but adjust for low 16 bits. */
1307 HOWTO (R_PPC_GOT_DTPREL16_HA,
1308 16, /* rightshift */
1309 1, /* size (0 = byte, 1 = short, 2 = long) */
1311 FALSE, /* pc_relative */
1313 complain_overflow_dont, /* complain_on_overflow */
1314 ppc_elf_unhandled_reloc, /* special_function */
1315 "R_PPC_GOT_DTPREL16_HA", /* name */
1316 FALSE, /* partial_inplace */
1318 0xffff, /* dst_mask */
1319 FALSE), /* pcrel_offset */
1321 /* Allocates an entry in the GOT with value (sym+add)@tprel, and computes the
1322 offset to the entry. */
1323 HOWTO (R_PPC_GOT_TPREL16,
1325 1, /* size (0 = byte, 1 = short, 2 = long) */
1327 FALSE, /* pc_relative */
1329 complain_overflow_signed, /* complain_on_overflow */
1330 ppc_elf_unhandled_reloc, /* special_function */
1331 "R_PPC_GOT_TPREL16", /* name */
1332 FALSE, /* partial_inplace */
1334 0xffff, /* dst_mask */
1335 FALSE), /* pcrel_offset */
1337 /* Like GOT_TPREL16, but no overflow. */
1338 HOWTO (R_PPC_GOT_TPREL16_LO,
1340 1, /* size (0 = byte, 1 = short, 2 = long) */
1342 FALSE, /* pc_relative */
1344 complain_overflow_dont, /* complain_on_overflow */
1345 ppc_elf_unhandled_reloc, /* special_function */
1346 "R_PPC_GOT_TPREL16_LO", /* name */
1347 FALSE, /* partial_inplace */
1349 0xffff, /* dst_mask */
1350 FALSE), /* pcrel_offset */
1352 /* Like GOT_TPREL16_LO, but next higher group of 16 bits. */
1353 HOWTO (R_PPC_GOT_TPREL16_HI,
1354 16, /* rightshift */
1355 1, /* size (0 = byte, 1 = short, 2 = long) */
1357 FALSE, /* pc_relative */
1359 complain_overflow_dont, /* complain_on_overflow */
1360 ppc_elf_unhandled_reloc, /* special_function */
1361 "R_PPC_GOT_TPREL16_HI", /* name */
1362 FALSE, /* partial_inplace */
1364 0xffff, /* dst_mask */
1365 FALSE), /* pcrel_offset */
1367 /* Like GOT_TPREL16_HI, but adjust for low 16 bits. */
1368 HOWTO (R_PPC_GOT_TPREL16_HA,
1369 16, /* rightshift */
1370 1, /* size (0 = byte, 1 = short, 2 = long) */
1372 FALSE, /* pc_relative */
1374 complain_overflow_dont, /* complain_on_overflow */
1375 ppc_elf_unhandled_reloc, /* special_function */
1376 "R_PPC_GOT_TPREL16_HA", /* name */
1377 FALSE, /* partial_inplace */
1379 0xffff, /* dst_mask */
1380 FALSE), /* pcrel_offset */
1382 /* The remaining relocs are from the Embedded ELF ABI, and are not
1383 in the SVR4 ELF ABI. */
1385 /* 32 bit value resulting from the addend minus the symbol. */
1386 HOWTO (R_PPC_EMB_NADDR32, /* type */
1388 2, /* size (0 = byte, 1 = short, 2 = long) */
1390 FALSE, /* pc_relative */
1392 complain_overflow_bitfield, /* complain_on_overflow */
1393 bfd_elf_generic_reloc, /* special_function */
1394 "R_PPC_EMB_NADDR32", /* name */
1395 FALSE, /* partial_inplace */
1397 0xffffffff, /* dst_mask */
1398 FALSE), /* pcrel_offset */
1400 /* 16 bit value resulting from the addend minus the symbol. */
1401 HOWTO (R_PPC_EMB_NADDR16, /* type */
1403 1, /* size (0 = byte, 1 = short, 2 = long) */
1405 FALSE, /* pc_relative */
1407 complain_overflow_bitfield, /* complain_on_overflow */
1408 bfd_elf_generic_reloc, /* special_function */
1409 "R_PPC_EMB_NADDR16", /* name */
1410 FALSE, /* partial_inplace */
1412 0xffff, /* dst_mask */
1413 FALSE), /* pcrel_offset */
1415 /* 16 bit value resulting from the addend minus the symbol. */
1416 HOWTO (R_PPC_EMB_NADDR16_LO, /* type */
1418 1, /* size (0 = byte, 1 = short, 2 = long) */
1420 FALSE, /* pc_relative */
1422 complain_overflow_dont,/* complain_on_overflow */
1423 bfd_elf_generic_reloc, /* special_function */
1424 "R_PPC_EMB_ADDR16_LO", /* name */
1425 FALSE, /* partial_inplace */
1427 0xffff, /* dst_mask */
1428 FALSE), /* pcrel_offset */
1430 /* The high order 16 bits of the addend minus the symbol. */
1431 HOWTO (R_PPC_EMB_NADDR16_HI, /* type */
1432 16, /* rightshift */
1433 1, /* size (0 = byte, 1 = short, 2 = long) */
1435 FALSE, /* pc_relative */
1437 complain_overflow_dont, /* complain_on_overflow */
1438 bfd_elf_generic_reloc, /* special_function */
1439 "R_PPC_EMB_NADDR16_HI", /* name */
1440 FALSE, /* partial_inplace */
1442 0xffff, /* dst_mask */
1443 FALSE), /* pcrel_offset */
1445 /* The high order 16 bits of the result of the addend minus the address,
1446 plus 1 if the contents of the low 16 bits, treated as a signed number,
1448 HOWTO (R_PPC_EMB_NADDR16_HA, /* type */
1449 16, /* rightshift */
1450 1, /* size (0 = byte, 1 = short, 2 = long) */
1452 FALSE, /* pc_relative */
1454 complain_overflow_dont, /* complain_on_overflow */
1455 ppc_elf_addr16_ha_reloc, /* special_function */
1456 "R_PPC_EMB_NADDR16_HA", /* name */
1457 FALSE, /* partial_inplace */
1459 0xffff, /* dst_mask */
1460 FALSE), /* pcrel_offset */
1462 /* 16 bit value resulting from allocating a 4 byte word to hold an
1463 address in the .sdata section, and returning the offset from
1464 _SDA_BASE_ for that relocation. */
1465 HOWTO (R_PPC_EMB_SDAI16, /* type */
1467 1, /* size (0 = byte, 1 = short, 2 = long) */
1469 FALSE, /* pc_relative */
1471 complain_overflow_bitfield, /* complain_on_overflow */
1472 bfd_elf_generic_reloc, /* special_function */
1473 "R_PPC_EMB_SDAI16", /* name */
1474 FALSE, /* partial_inplace */
1476 0xffff, /* dst_mask */
1477 FALSE), /* pcrel_offset */
1479 /* 16 bit value resulting from allocating a 4 byte word to hold an
1480 address in the .sdata2 section, and returning the offset from
1481 _SDA2_BASE_ for that relocation. */
1482 HOWTO (R_PPC_EMB_SDA2I16, /* type */
1484 1, /* size (0 = byte, 1 = short, 2 = long) */
1486 FALSE, /* pc_relative */
1488 complain_overflow_bitfield, /* complain_on_overflow */
1489 bfd_elf_generic_reloc, /* special_function */
1490 "R_PPC_EMB_SDA2I16", /* name */
1491 FALSE, /* partial_inplace */
1493 0xffff, /* dst_mask */
1494 FALSE), /* pcrel_offset */
1496 /* A sign-extended 16 bit value relative to _SDA2_BASE_, for use with
1497 small data items. */
1498 HOWTO (R_PPC_EMB_SDA2REL, /* type */
1500 1, /* size (0 = byte, 1 = short, 2 = long) */
1502 FALSE, /* pc_relative */
1504 complain_overflow_signed, /* complain_on_overflow */
1505 bfd_elf_generic_reloc, /* special_function */
1506 "R_PPC_EMB_SDA2REL", /* name */
1507 FALSE, /* partial_inplace */
1509 0xffff, /* dst_mask */
1510 FALSE), /* pcrel_offset */
1512 /* Relocate against either _SDA_BASE_ or _SDA2_BASE_, filling in the 16 bit
1513 signed offset from the appropriate base, and filling in the register
1514 field with the appropriate register (0, 2, or 13). */
1515 HOWTO (R_PPC_EMB_SDA21, /* type */
1517 2, /* size (0 = byte, 1 = short, 2 = long) */
1519 FALSE, /* pc_relative */
1521 complain_overflow_signed, /* complain_on_overflow */
1522 bfd_elf_generic_reloc, /* special_function */
1523 "R_PPC_EMB_SDA21", /* name */
1524 FALSE, /* partial_inplace */
1526 0xffff, /* dst_mask */
1527 FALSE), /* pcrel_offset */
1529 /* Relocation not handled: R_PPC_EMB_MRKREF */
1530 /* Relocation not handled: R_PPC_EMB_RELSEC16 */
1531 /* Relocation not handled: R_PPC_EMB_RELST_LO */
1532 /* Relocation not handled: R_PPC_EMB_RELST_HI */
1533 /* Relocation not handled: R_PPC_EMB_RELST_HA */
1534 /* Relocation not handled: R_PPC_EMB_BIT_FLD */
1536 /* PC relative relocation against either _SDA_BASE_ or _SDA2_BASE_, filling
1537 in the 16 bit signed offset from the appropriate base, and filling in the
1538 register field with the appropriate register (0, 2, or 13). */
1539 HOWTO (R_PPC_EMB_RELSDA, /* type */
1541 1, /* size (0 = byte, 1 = short, 2 = long) */
1543 TRUE, /* pc_relative */
1545 complain_overflow_signed, /* complain_on_overflow */
1546 bfd_elf_generic_reloc, /* special_function */
1547 "R_PPC_EMB_RELSDA", /* name */
1548 FALSE, /* partial_inplace */
1550 0xffff, /* dst_mask */
1551 FALSE), /* pcrel_offset */
1553 /* GNU extension to record C++ vtable hierarchy. */
1554 HOWTO (R_PPC_GNU_VTINHERIT, /* type */
1556 0, /* size (0 = byte, 1 = short, 2 = long) */
1558 FALSE, /* pc_relative */
1560 complain_overflow_dont, /* complain_on_overflow */
1561 NULL, /* special_function */
1562 "R_PPC_GNU_VTINHERIT", /* name */
1563 FALSE, /* partial_inplace */
1566 FALSE), /* pcrel_offset */
1568 /* GNU extension to record C++ vtable member usage. */
1569 HOWTO (R_PPC_GNU_VTENTRY, /* type */
1571 0, /* size (0 = byte, 1 = short, 2 = long) */
1573 FALSE, /* pc_relative */
1575 complain_overflow_dont, /* complain_on_overflow */
1576 NULL, /* special_function */
1577 "R_PPC_GNU_VTENTRY", /* name */
1578 FALSE, /* partial_inplace */
1581 FALSE), /* pcrel_offset */
1583 /* Phony reloc to handle AIX style TOC entries. */
1584 HOWTO (R_PPC_TOC16, /* type */
1586 1, /* size (0 = byte, 1 = short, 2 = long) */
1588 FALSE, /* pc_relative */
1590 complain_overflow_signed, /* complain_on_overflow */
1591 bfd_elf_generic_reloc, /* special_function */
1592 "R_PPC_TOC16", /* name */
1593 FALSE, /* partial_inplace */
1595 0xffff, /* dst_mask */
1596 FALSE), /* pcrel_offset */
1599 /* Initialize the ppc_elf_howto_table, so that linear accesses can be done. */
1602 ppc_elf_howto_init ()
1604 unsigned int i, type;
1606 for (i = 0; i < sizeof (ppc_elf_howto_raw) / sizeof (ppc_elf_howto_raw[0]); i++)
1608 type = ppc_elf_howto_raw[i].type;
1609 BFD_ASSERT (type < sizeof (ppc_elf_howto_table) / sizeof (ppc_elf_howto_table[0]));
1610 ppc_elf_howto_table[type] = &ppc_elf_howto_raw[i];
1614 /* This function handles relaxing for the PPC with option --mpc860c0[=<n>].
1616 The MPC860, revision C0 or earlier contains a bug in the die.
1617 If all of the following conditions are true, the next instruction
1618 to be executed *may* be treated as a no-op.
1619 1/ A forward branch is executed.
1620 2/ The branch is predicted as not taken.
1621 3/ The branch is taken.
1622 4/ The branch is located in the last 5 words of a page.
1623 (The EOP limit is 5 by default but may be specified as any value from 1-10.)
1625 Our software solution is to detect these problematic branches in a
1626 linker pass and modify them as follows:
1627 1/ Unconditional branches - Since these are always predicted taken,
1628 there is no problem and no action is required.
1629 2/ Conditional backward branches - No problem, no action required.
1630 3/ Conditional forward branches - Ensure that the "inverse prediction
1631 bit" is set (ensure it is predicted taken).
1632 4/ Conditional register branches - Ensure that the "y bit" is set
1633 (ensure it is predicted taken). */
1635 /* Sort sections by address. */
1638 ppc_elf_sort_rela (arg1, arg2)
1642 const Elf_Internal_Rela **rela1 = (const Elf_Internal_Rela**) arg1;
1643 const Elf_Internal_Rela **rela2 = (const Elf_Internal_Rela**) arg2;
1645 /* Sort by offset. */
1646 return ((*rela1)->r_offset - (*rela2)->r_offset);
1650 ppc_elf_relax_section (abfd, isec, link_info, again)
1653 struct bfd_link_info *link_info;
1656 #define PAGESIZE 0x1000
1658 bfd_byte *contents = NULL;
1659 bfd_byte *free_contents = NULL;
1660 Elf_Internal_Rela *internal_relocs = NULL;
1661 Elf_Internal_Rela *free_relocs = NULL;
1662 Elf_Internal_Rela **rela_comb = NULL;
1663 int comb_curr, comb_count;
1665 /* We never have to do this more than once per input section. */
1668 /* If needed, initialize this section's cooked size. */
1669 if (isec->_cooked_size == 0)
1670 isec->_cooked_size = isec->_raw_size;
1672 /* We're only interested in text sections which overlap the
1673 troublesome area at the end of a page. */
1674 if (link_info->mpc860c0 && (isec->flags & SEC_CODE) && isec->_cooked_size)
1676 bfd_vma dot, end_page, end_section;
1677 bfd_boolean section_modified;
1679 /* Get the section contents. */
1680 /* Get cached copy if it exists. */
1681 if (elf_section_data (isec)->this_hdr.contents != NULL)
1682 contents = elf_section_data (isec)->this_hdr.contents;
1685 /* Go get them off disk. */
1686 contents = (bfd_byte *) bfd_malloc (isec->_raw_size);
1687 if (contents == NULL)
1689 free_contents = contents;
1691 if (! bfd_get_section_contents (abfd, isec, contents,
1692 (file_ptr) 0, isec->_raw_size))
1698 if (isec->reloc_count)
1703 /* Get a copy of the native relocations. */
1704 internal_relocs = _bfd_elf32_link_read_relocs (
1705 abfd, isec, (PTR) NULL, (Elf_Internal_Rela *) NULL,
1706 link_info->keep_memory);
1707 if (internal_relocs == NULL)
1709 if (! link_info->keep_memory)
1710 free_relocs = internal_relocs;
1712 /* Setup a faster access method for the reloc info we need. */
1713 amt = isec->reloc_count;
1714 amt *= sizeof (Elf_Internal_Rela*);
1715 rela_comb = (Elf_Internal_Rela**) bfd_malloc (amt);
1716 if (rela_comb == NULL)
1718 for (n = 0; n < isec->reloc_count; ++n)
1722 r_type = ELF32_R_TYPE (internal_relocs[n].r_info);
1723 if (r_type < 0 || r_type >= (int) R_PPC_max)
1726 /* Prologue constants are sometimes present in the ".text"
1727 sections and they can be identified by their associated relocation.
1728 We don't want to process those words and some others which
1729 can also be identified by their relocations. However, not all
1730 conditional branches will have a relocation so we will
1731 only ignore words that 1) have a reloc, and 2) the reloc
1732 is not applicable to a conditional branch.
1733 The array rela_comb is built here for use in the EOP scan loop. */
1736 case R_PPC_ADDR14_BRNTAKEN: /* Absolute, predicted not taken */
1737 case R_PPC_REL14: /* Relative cond. br. */
1738 case R_PPC_REL14_BRNTAKEN: /* Rel. cond. br., predicted not taken */
1739 /* We should check the instruction. */
1742 /* The word is not a conditional branch - ignore it. */
1743 rela_comb[comb_count++] = &internal_relocs[n];
1748 qsort (rela_comb, (size_t) comb_count, sizeof (int), ppc_elf_sort_rela);
1751 /* Enumerate each EOP region that overlaps this section. */
1752 end_section = isec->vma + isec->_cooked_size;
1753 dot = end_page = (isec->vma | (PAGESIZE - 1)) + 1;
1754 dot -= link_info->mpc860c0;
1755 section_modified = FALSE;
1756 if (dot < isec->vma) /* Increment the start position if this section */
1757 dot = isec->vma; /* begins in the middle of its first EOP region. */
1760 dot += PAGESIZE, end_page += PAGESIZE)
1763 /* Check each word in this EOP region. */
1764 for (; dot < end_page; dot += 4)
1766 bfd_vma isec_offset;
1768 bfd_boolean skip, modified;
1770 /* Don't process this word if there is a relocation for it and
1771 the relocation indicates the word is not a conditional branch. */
1773 isec_offset = dot - isec->vma;
1774 for (; comb_curr<comb_count; ++comb_curr)
1778 r_offset = rela_comb[comb_curr]->r_offset;
1779 if (r_offset >= isec_offset)
1781 if (r_offset == isec_offset) skip = TRUE;
1787 /* Check the current word for a problematic conditional branch. */
1788 #define BO0(insn) ((insn) & 0x02000000)
1789 #define BO2(insn) ((insn) & 0x00800000)
1790 #define BO4(insn) ((insn) & 0x00200000)
1791 insn = (unsigned long) bfd_get_32 (abfd, contents + isec_offset);
1793 if ((insn & 0xFc000000) == 0x40000000)
1795 /* Instruction is BCx */
1796 if ((!BO0(insn) || !BO2(insn)) && !BO4(insn))
1799 /* This branch is predicted as "normal".
1800 If this is a forward branch, it is problematic. */
1802 target = insn & 0x0000Fffc; /*extract*/
1803 target = (target ^ 0x8000) - 0x8000; /*sign extend*/
1804 if ((insn & 0x00000002) == 0)
1805 target += dot; /*convert to abs*/
1808 insn |= 0x00200000; /* Set the prediction bit. */
1813 else if ((insn & 0xFc00Fffe) == 0x4c000420)
1815 /* Instruction is BCCTRx. */
1816 if ((!BO0(insn) || !BO2(insn)) && !BO4(insn))
1818 /* This branch is predicted as not-taken.
1819 If this is a forward branch, it is problematic.
1820 Since we can't tell statically if it will branch forward,
1821 always set the prediction bit. */
1822 insn |= 0x00200000; /* Set the prediction bit. */
1826 else if ((insn & 0xFc00Fffe) == 0x4c000020)
1828 /* Instruction is BCLRx */
1829 if ((!BO0(insn) || !BO2(insn)) && !BO4(insn))
1831 /* This branch is predicted as not-taken.
1832 If this is a forward branch, it is problematic.
1833 Since we can't tell statically if it will branch forward,
1834 always set the prediction bit. */
1835 insn |= 0x00200000; /* Set the prediction bit. */
1844 bfd_put_32 (abfd, (bfd_vma) insn, contents + isec_offset);
1845 section_modified = TRUE;
1849 if (section_modified)
1851 elf_section_data (isec)->this_hdr.contents = contents;
1852 free_contents = NULL;
1856 if (rela_comb != NULL)
1862 if (free_relocs != NULL)
1868 if (free_contents != NULL)
1870 if (! link_info->keep_memory)
1871 free (free_contents);
1874 /* Cache the section contents for elf_link_input_bfd. */
1875 elf_section_data (isec)->this_hdr.contents = contents;
1877 free_contents = NULL;
1883 if (rela_comb != NULL)
1885 if (free_relocs != NULL)
1887 if (free_contents != NULL)
1888 free (free_contents);
1892 static reloc_howto_type *
1893 ppc_elf_reloc_type_lookup (abfd, code)
1894 bfd *abfd ATTRIBUTE_UNUSED;
1895 bfd_reloc_code_real_type code;
1897 enum elf_ppc_reloc_type r;
1899 if (!ppc_elf_howto_table[R_PPC_ADDR32])
1900 /* Initialize howto table if needed. */
1901 ppc_elf_howto_init ();
1906 return (reloc_howto_type *) NULL;
1908 case BFD_RELOC_NONE: r = R_PPC_NONE; break;
1909 case BFD_RELOC_32: r = R_PPC_ADDR32; break;
1910 case BFD_RELOC_PPC_BA26: r = R_PPC_ADDR24; break;
1911 case BFD_RELOC_16: r = R_PPC_ADDR16; break;
1912 case BFD_RELOC_LO16: r = R_PPC_ADDR16_LO; break;
1913 case BFD_RELOC_HI16: r = R_PPC_ADDR16_HI; break;
1914 case BFD_RELOC_HI16_S: r = R_PPC_ADDR16_HA; break;
1915 case BFD_RELOC_PPC_BA16: r = R_PPC_ADDR14; break;
1916 case BFD_RELOC_PPC_BA16_BRTAKEN: r = R_PPC_ADDR14_BRTAKEN; break;
1917 case BFD_RELOC_PPC_BA16_BRNTAKEN: r = R_PPC_ADDR14_BRNTAKEN; break;
1918 case BFD_RELOC_PPC_B26: r = R_PPC_REL24; break;
1919 case BFD_RELOC_PPC_B16: r = R_PPC_REL14; break;
1920 case BFD_RELOC_PPC_B16_BRTAKEN: r = R_PPC_REL14_BRTAKEN; break;
1921 case BFD_RELOC_PPC_B16_BRNTAKEN: r = R_PPC_REL14_BRNTAKEN; break;
1922 case BFD_RELOC_16_GOTOFF: r = R_PPC_GOT16; break;
1923 case BFD_RELOC_LO16_GOTOFF: r = R_PPC_GOT16_LO; break;
1924 case BFD_RELOC_HI16_GOTOFF: r = R_PPC_GOT16_HI; break;
1925 case BFD_RELOC_HI16_S_GOTOFF: r = R_PPC_GOT16_HA; break;
1926 case BFD_RELOC_24_PLT_PCREL: r = R_PPC_PLTREL24; break;
1927 case BFD_RELOC_PPC_COPY: r = R_PPC_COPY; break;
1928 case BFD_RELOC_PPC_GLOB_DAT: r = R_PPC_GLOB_DAT; break;
1929 case BFD_RELOC_PPC_LOCAL24PC: r = R_PPC_LOCAL24PC; break;
1930 case BFD_RELOC_32_PCREL: r = R_PPC_REL32; break;
1931 case BFD_RELOC_32_PLTOFF: r = R_PPC_PLT32; break;
1932 case BFD_RELOC_32_PLT_PCREL: r = R_PPC_PLTREL32; break;
1933 case BFD_RELOC_LO16_PLTOFF: r = R_PPC_PLT16_LO; break;
1934 case BFD_RELOC_HI16_PLTOFF: r = R_PPC_PLT16_HI; break;
1935 case BFD_RELOC_HI16_S_PLTOFF: r = R_PPC_PLT16_HA; break;
1936 case BFD_RELOC_GPREL16: r = R_PPC_SDAREL16; break;
1937 case BFD_RELOC_16_BASEREL: r = R_PPC_SECTOFF; break;
1938 case BFD_RELOC_LO16_BASEREL: r = R_PPC_SECTOFF_LO; break;
1939 case BFD_RELOC_HI16_BASEREL: r = R_PPC_SECTOFF_HI; break;
1940 case BFD_RELOC_HI16_S_BASEREL: r = R_PPC_SECTOFF_HA; break;
1941 case BFD_RELOC_CTOR: r = R_PPC_ADDR32; break;
1942 case BFD_RELOC_PPC_TOC16: r = R_PPC_TOC16; break;
1943 case BFD_RELOC_PPC_TLS: r = R_PPC_TLS; break;
1944 case BFD_RELOC_PPC_DTPMOD: r = R_PPC_DTPMOD32; break;
1945 case BFD_RELOC_PPC_TPREL16: r = R_PPC_TPREL16; break;
1946 case BFD_RELOC_PPC_TPREL16_LO: r = R_PPC_TPREL16_LO; break;
1947 case BFD_RELOC_PPC_TPREL16_HI: r = R_PPC_TPREL16_HI; break;
1948 case BFD_RELOC_PPC_TPREL16_HA: r = R_PPC_TPREL16_HA; break;
1949 case BFD_RELOC_PPC_TPREL: r = R_PPC_TPREL32; break;
1950 case BFD_RELOC_PPC_DTPREL16: r = R_PPC_DTPREL16; break;
1951 case BFD_RELOC_PPC_DTPREL16_LO: r = R_PPC_DTPREL16_LO; break;
1952 case BFD_RELOC_PPC_DTPREL16_HI: r = R_PPC_DTPREL16_HI; break;
1953 case BFD_RELOC_PPC_DTPREL16_HA: r = R_PPC_DTPREL16_HA; break;
1954 case BFD_RELOC_PPC_DTPREL: r = R_PPC_DTPREL32; break;
1955 case BFD_RELOC_PPC_GOT_TLSGD16: r = R_PPC_GOT_TLSGD16; break;
1956 case BFD_RELOC_PPC_GOT_TLSGD16_LO: r = R_PPC_GOT_TLSGD16_LO; break;
1957 case BFD_RELOC_PPC_GOT_TLSGD16_HI: r = R_PPC_GOT_TLSGD16_HI; break;
1958 case BFD_RELOC_PPC_GOT_TLSGD16_HA: r = R_PPC_GOT_TLSGD16_HA; break;
1959 case BFD_RELOC_PPC_GOT_TLSLD16: r = R_PPC_GOT_TLSLD16; break;
1960 case BFD_RELOC_PPC_GOT_TLSLD16_LO: r = R_PPC_GOT_TLSLD16_LO; break;
1961 case BFD_RELOC_PPC_GOT_TLSLD16_HI: r = R_PPC_GOT_TLSLD16_HI; break;
1962 case BFD_RELOC_PPC_GOT_TLSLD16_HA: r = R_PPC_GOT_TLSLD16_HA; break;
1963 case BFD_RELOC_PPC_GOT_TPREL16: r = R_PPC_GOT_TPREL16; break;
1964 case BFD_RELOC_PPC_GOT_TPREL16_LO: r = R_PPC_GOT_TPREL16_LO; break;
1965 case BFD_RELOC_PPC_GOT_TPREL16_HI: r = R_PPC_GOT_TPREL16_HI; break;
1966 case BFD_RELOC_PPC_GOT_TPREL16_HA: r = R_PPC_GOT_TPREL16_HA; break;
1967 case BFD_RELOC_PPC_GOT_DTPREL16: r = R_PPC_GOT_DTPREL16; break;
1968 case BFD_RELOC_PPC_GOT_DTPREL16_LO: r = R_PPC_GOT_DTPREL16_LO; break;
1969 case BFD_RELOC_PPC_GOT_DTPREL16_HI: r = R_PPC_GOT_DTPREL16_HI; break;
1970 case BFD_RELOC_PPC_GOT_DTPREL16_HA: r = R_PPC_GOT_DTPREL16_HA; break;
1971 case BFD_RELOC_PPC_EMB_NADDR32: r = R_PPC_EMB_NADDR32; break;
1972 case BFD_RELOC_PPC_EMB_NADDR16: r = R_PPC_EMB_NADDR16; break;
1973 case BFD_RELOC_PPC_EMB_NADDR16_LO: r = R_PPC_EMB_NADDR16_LO; break;
1974 case BFD_RELOC_PPC_EMB_NADDR16_HI: r = R_PPC_EMB_NADDR16_HI; break;
1975 case BFD_RELOC_PPC_EMB_NADDR16_HA: r = R_PPC_EMB_NADDR16_HA; break;
1976 case BFD_RELOC_PPC_EMB_SDAI16: r = R_PPC_EMB_SDAI16; break;
1977 case BFD_RELOC_PPC_EMB_SDA2I16: r = R_PPC_EMB_SDA2I16; break;
1978 case BFD_RELOC_PPC_EMB_SDA2REL: r = R_PPC_EMB_SDA2REL; break;
1979 case BFD_RELOC_PPC_EMB_SDA21: r = R_PPC_EMB_SDA21; break;
1980 case BFD_RELOC_PPC_EMB_MRKREF: r = R_PPC_EMB_MRKREF; break;
1981 case BFD_RELOC_PPC_EMB_RELSEC16: r = R_PPC_EMB_RELSEC16; break;
1982 case BFD_RELOC_PPC_EMB_RELST_LO: r = R_PPC_EMB_RELST_LO; break;
1983 case BFD_RELOC_PPC_EMB_RELST_HI: r = R_PPC_EMB_RELST_HI; break;
1984 case BFD_RELOC_PPC_EMB_RELST_HA: r = R_PPC_EMB_RELST_HA; break;
1985 case BFD_RELOC_PPC_EMB_BIT_FLD: r = R_PPC_EMB_BIT_FLD; break;
1986 case BFD_RELOC_PPC_EMB_RELSDA: r = R_PPC_EMB_RELSDA; break;
1987 case BFD_RELOC_VTABLE_INHERIT: r = R_PPC_GNU_VTINHERIT; break;
1988 case BFD_RELOC_VTABLE_ENTRY: r = R_PPC_GNU_VTENTRY; break;
1991 return ppc_elf_howto_table[(int) r];
1994 /* Set the howto pointer for a PowerPC ELF reloc. */
1997 ppc_elf_info_to_howto (abfd, cache_ptr, dst)
1998 bfd *abfd ATTRIBUTE_UNUSED;
2000 Elf_Internal_Rela *dst;
2002 if (!ppc_elf_howto_table[R_PPC_ADDR32])
2003 /* Initialize howto table if needed. */
2004 ppc_elf_howto_init ();
2006 BFD_ASSERT (ELF32_R_TYPE (dst->r_info) < (unsigned int) R_PPC_max);
2007 cache_ptr->howto = ppc_elf_howto_table[ELF32_R_TYPE (dst->r_info)];
2010 /* Handle the R_PPC_ADDR16_HA reloc. */
2012 static bfd_reloc_status_type
2013 ppc_elf_addr16_ha_reloc (abfd, reloc_entry, symbol, data, input_section,
2014 output_bfd, error_message)
2015 bfd *abfd ATTRIBUTE_UNUSED;
2016 arelent *reloc_entry;
2018 PTR data ATTRIBUTE_UNUSED;
2019 asection *input_section;
2021 char **error_message ATTRIBUTE_UNUSED;
2025 if (output_bfd != NULL)
2027 reloc_entry->address += input_section->output_offset;
2028 return bfd_reloc_ok;
2031 if (reloc_entry->address > input_section->_cooked_size)
2032 return bfd_reloc_outofrange;
2034 if (bfd_is_com_section (symbol->section))
2037 relocation = symbol->value;
2039 relocation += symbol->section->output_section->vma;
2040 relocation += symbol->section->output_offset;
2041 relocation += reloc_entry->addend;
2043 reloc_entry->addend += (relocation & 0x8000) << 1;
2045 return bfd_reloc_continue;
2048 static bfd_reloc_status_type
2049 ppc_elf_unhandled_reloc (abfd, reloc_entry, symbol, data,
2050 input_section, output_bfd, error_message)
2052 arelent *reloc_entry;
2055 asection *input_section;
2057 char **error_message;
2059 /* If this is a relocatable link (output_bfd test tells us), just
2060 call the generic function. Any adjustment will be done at final
2062 if (output_bfd != NULL)
2063 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
2064 input_section, output_bfd, error_message);
2066 if (error_message != NULL)
2068 static char buf[60];
2069 sprintf (buf, "generic linker can't handle %s",
2070 reloc_entry->howto->name);
2071 *error_message = buf;
2073 return bfd_reloc_dangerous;
2076 /* Fix bad default arch selected for a 32 bit input bfd when the
2077 default is 64 bit. */
2080 ppc_elf_object_p (abfd)
2083 if (abfd->arch_info->the_default && abfd->arch_info->bits_per_word == 64)
2085 Elf_Internal_Ehdr *i_ehdr = elf_elfheader (abfd);
2087 if (i_ehdr->e_ident[EI_CLASS] == ELFCLASS32)
2089 /* Relies on arch after 64 bit default being 32 bit default. */
2090 abfd->arch_info = abfd->arch_info->next;
2091 BFD_ASSERT (abfd->arch_info->bits_per_word == 32);
2097 /* Function to set whether a module needs the -mrelocatable bit set. */
2100 ppc_elf_set_private_flags (abfd, flags)
2104 BFD_ASSERT (!elf_flags_init (abfd)
2105 || elf_elfheader (abfd)->e_flags == flags);
2107 elf_elfheader (abfd)->e_flags = flags;
2108 elf_flags_init (abfd) = TRUE;
2112 /* Merge backend specific data from an object file to the output
2113 object file when linking. */
2116 ppc_elf_merge_private_bfd_data (ibfd, obfd)
2124 /* Check if we have the same endianess. */
2125 if (! _bfd_generic_verify_endian_match (ibfd, obfd))
2128 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
2129 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
2132 new_flags = elf_elfheader (ibfd)->e_flags;
2133 old_flags = elf_elfheader (obfd)->e_flags;
2134 if (!elf_flags_init (obfd)) /* First call, no flags set. */
2136 elf_flags_init (obfd) = TRUE;
2137 elf_elfheader (obfd)->e_flags = new_flags;
2140 else if (new_flags == old_flags) /* Compatible flags are ok. */
2143 else /* Incompatible flags. */
2145 /* Warn about -mrelocatable mismatch. Allow -mrelocatable-lib to be linked
2148 if ((new_flags & EF_PPC_RELOCATABLE) != 0
2149 && (old_flags & (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB)) == 0)
2152 (*_bfd_error_handler)
2153 (_("%s: compiled with -mrelocatable and linked with modules compiled normally"),
2154 bfd_archive_filename (ibfd));
2156 else if ((new_flags & (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB)) == 0
2157 && (old_flags & EF_PPC_RELOCATABLE) != 0)
2160 (*_bfd_error_handler)
2161 (_("%s: compiled normally and linked with modules compiled with -mrelocatable"),
2162 bfd_archive_filename (ibfd));
2165 /* The output is -mrelocatable-lib iff both the input files are. */
2166 if (! (new_flags & EF_PPC_RELOCATABLE_LIB))
2167 elf_elfheader (obfd)->e_flags &= ~EF_PPC_RELOCATABLE_LIB;
2169 /* The output is -mrelocatable iff it can't be -mrelocatable-lib,
2170 but each input file is either -mrelocatable or -mrelocatable-lib. */
2171 if (! (elf_elfheader (obfd)->e_flags & EF_PPC_RELOCATABLE_LIB)
2172 && (new_flags & (EF_PPC_RELOCATABLE_LIB | EF_PPC_RELOCATABLE))
2173 && (old_flags & (EF_PPC_RELOCATABLE_LIB | EF_PPC_RELOCATABLE)))
2174 elf_elfheader (obfd)->e_flags |= EF_PPC_RELOCATABLE;
2176 /* Do not warn about eabi vs. V.4 mismatch, just or in the bit if any module uses it. */
2177 elf_elfheader (obfd)->e_flags |= (new_flags & EF_PPC_EMB);
2179 new_flags &= ~ (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB | EF_PPC_EMB);
2180 old_flags &= ~ (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB | EF_PPC_EMB);
2182 /* Warn about any other mismatches. */
2183 if (new_flags != old_flags)
2186 (*_bfd_error_handler)
2187 (_("%s: uses different e_flags (0x%lx) fields than previous modules (0x%lx)"),
2188 bfd_archive_filename (ibfd), (long) new_flags, (long) old_flags);
2193 bfd_set_error (bfd_error_bad_value);
2201 /* Handle a PowerPC specific section when reading an object file. This
2202 is called when elfcode.h finds a section with an unknown type. */
2205 ppc_elf_section_from_shdr (abfd, hdr, name)
2207 Elf_Internal_Shdr *hdr;
2213 if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name))
2216 newsect = hdr->bfd_section;
2217 flags = bfd_get_section_flags (abfd, newsect);
2218 if (hdr->sh_flags & SHF_EXCLUDE)
2219 flags |= SEC_EXCLUDE;
2221 if (hdr->sh_type == SHT_ORDERED)
2222 flags |= SEC_SORT_ENTRIES;
2224 bfd_set_section_flags (abfd, newsect, flags);
2228 /* Set up any other section flags and such that may be necessary. */
2231 ppc_elf_fake_sections (abfd, shdr, asect)
2232 bfd *abfd ATTRIBUTE_UNUSED;
2233 Elf_Internal_Shdr *shdr;
2236 if ((asect->flags & SEC_EXCLUDE) != 0)
2237 shdr->sh_flags |= SHF_EXCLUDE;
2239 if ((asect->flags & SEC_SORT_ENTRIES) != 0)
2240 shdr->sh_type = SHT_ORDERED;
2245 /* Create a special linker section */
2246 static elf_linker_section_t *
2247 ppc_elf_create_linker_section (abfd, info, which)
2249 struct bfd_link_info *info;
2250 enum elf_linker_section_enum which;
2252 bfd *dynobj = elf_hash_table (info)->dynobj;
2253 elf_linker_section_t *lsect;
2255 /* Record the first bfd section that needs the special section. */
2257 dynobj = elf_hash_table (info)->dynobj = abfd;
2259 /* If this is the first time, create the section. */
2260 lsect = elf_linker_section (dynobj, which);
2263 elf_linker_section_t defaults;
2264 static elf_linker_section_t zero_section;
2266 defaults = zero_section;
2267 defaults.which = which;
2268 defaults.hole_written_p = FALSE;
2269 defaults.alignment = 2;
2271 /* Both of these sections are (technically) created by the user
2272 putting data in them, so they shouldn't be marked
2275 The linker creates them so it has somewhere to attach their
2276 respective symbols. In fact, if they were empty it would
2277 be OK to leave the symbol set to 0 (or any random number), because
2278 the appropriate register should never be used. */
2279 defaults.flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS
2285 (*_bfd_error_handler) (_("%s: Unknown special linker type %d"),
2286 bfd_get_filename (abfd),
2289 bfd_set_error (bfd_error_bad_value);
2290 return (elf_linker_section_t *) 0;
2292 case LINKER_SECTION_SDATA: /* .sdata/.sbss section */
2293 defaults.name = ".sdata";
2294 defaults.rel_name = ".rela.sdata";
2295 defaults.bss_name = ".sbss";
2296 defaults.sym_name = "_SDA_BASE_";
2297 defaults.sym_offset = 32768;
2300 case LINKER_SECTION_SDATA2: /* .sdata2/.sbss2 section */
2301 defaults.name = ".sdata2";
2302 defaults.rel_name = ".rela.sdata2";
2303 defaults.bss_name = ".sbss2";
2304 defaults.sym_name = "_SDA2_BASE_";
2305 defaults.sym_offset = 32768;
2306 defaults.flags |= SEC_READONLY;
2310 lsect = _bfd_elf_create_linker_section (abfd, info, which, &defaults);
2316 /* If we have a non-zero sized .sbss2 or .PPC.EMB.sbss0 sections, we
2317 need to bump up the number of section headers. */
2320 ppc_elf_additional_program_headers (abfd)
2328 s = bfd_get_section_by_name (abfd, ".interp");
2332 s = bfd_get_section_by_name (abfd, ".sbss2");
2333 if (s != NULL && (s->flags & SEC_LOAD) != 0 && s->_raw_size > 0)
2336 s = bfd_get_section_by_name (abfd, ".PPC.EMB.sbss0");
2337 if (s != NULL && (s->flags & SEC_LOAD) != 0 && s->_raw_size > 0)
2343 /* Modify the segment map if needed. */
2346 ppc_elf_modify_segment_map (abfd)
2347 bfd *abfd ATTRIBUTE_UNUSED;
2352 /* The powerpc .got has a blrl instruction in it. Mark it executable. */
2355 ppc_elf_create_got (abfd, info)
2357 struct bfd_link_info *info;
2359 struct ppc_elf_link_hash_table *htab;
2363 if (!_bfd_elf_create_got_section (abfd, info))
2366 htab = ppc_elf_hash_table (info);
2367 htab->got = s = bfd_get_section_by_name (abfd, ".got");
2371 flags = (SEC_ALLOC | SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS | SEC_IN_MEMORY
2372 | SEC_LINKER_CREATED);
2373 if (!bfd_set_section_flags (abfd, s, flags))
2376 htab->relgot = bfd_make_section (abfd, ".rela.got");
2378 || ! bfd_set_section_flags (abfd, htab->relgot,
2379 (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS
2380 | SEC_IN_MEMORY | SEC_LINKER_CREATED
2382 || ! bfd_set_section_alignment (abfd, htab->relgot, 2))
2388 /* We have to create .dynsbss and .rela.sbss here so that they get mapped
2389 to output sections (just like _bfd_elf_create_dynamic_sections has
2390 to create .dynbss and .rela.bss). */
2393 ppc_elf_create_dynamic_sections (abfd, info)
2395 struct bfd_link_info *info;
2397 struct ppc_elf_link_hash_table *htab;
2401 if (!ppc_elf_create_got (abfd, info))
2404 if (!_bfd_elf_create_dynamic_sections (abfd, info))
2407 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
2408 | SEC_LINKER_CREATED);
2410 htab = ppc_elf_hash_table (info);
2411 htab->dynbss = bfd_get_section_by_name (abfd, ".dynbss");
2412 htab->dynsbss = s = bfd_make_section (abfd, ".dynsbss");
2414 || ! bfd_set_section_flags (abfd, s, SEC_ALLOC))
2419 htab->relbss = bfd_get_section_by_name (abfd, ".rela.bss");
2420 htab->relsbss = s = bfd_make_section (abfd, ".rela.sbss");
2422 || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
2423 || ! bfd_set_section_alignment (abfd, s, 2))
2427 htab->relplt = bfd_get_section_by_name (abfd, ".rela.plt");
2428 htab->plt = s = bfd_get_section_by_name (abfd, ".plt");
2432 flags = SEC_ALLOC | SEC_CODE | SEC_IN_MEMORY | SEC_LINKER_CREATED;
2433 return bfd_set_section_flags (abfd, s, flags);
2436 /* Adjust a symbol defined by a dynamic object and referenced by a
2437 regular object. The current definition is in some section of the
2438 dynamic object, but we're not including those sections. We have to
2439 change the definition to something the rest of the link can
2443 ppc_elf_adjust_dynamic_symbol (info, h)
2444 struct bfd_link_info *info;
2445 struct elf_link_hash_entry *h;
2447 struct ppc_elf_link_hash_table *htab;
2449 unsigned int power_of_two;
2452 fprintf (stderr, "ppc_elf_adjust_dynamic_symbol called for %s\n", h->root.root.string);
2455 /* Make sure we know what is going on here. */
2456 htab = ppc_elf_hash_table (info);
2457 BFD_ASSERT (htab->elf.dynobj != NULL
2458 && ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT)
2459 || h->weakdef != NULL
2460 || ((h->elf_link_hash_flags
2461 & ELF_LINK_HASH_DEF_DYNAMIC) != 0
2462 && (h->elf_link_hash_flags
2463 & ELF_LINK_HASH_REF_REGULAR) != 0
2464 && (h->elf_link_hash_flags
2465 & ELF_LINK_HASH_DEF_REGULAR) == 0)));
2467 /* Deal with function syms. */
2468 if (h->type == STT_FUNC
2469 || (h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0)
2471 /* Clear procedure linkage table information for any symbol that
2472 won't need a .plt entry. */
2473 if (! htab->elf.dynamic_sections_created
2474 || SYMBOL_CALLS_LOCAL (info, h)
2475 || h->plt.refcount <= 0)
2477 /* A PLT entry is not required/allowed when:
2479 1. We are not using ld.so; because then the PLT entry
2480 can't be set up, so we can't use one.
2482 2. We know for certain that a call to this symbol
2483 will go to this object.
2485 3. GC has rendered the entry unused. */
2486 h->plt.offset = (bfd_vma) -1;
2487 h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
2492 h->plt.offset = (bfd_vma) -1;
2494 /* If this is a weak symbol, and there is a real definition, the
2495 processor independent code will have arranged for us to see the
2496 real definition first, and we can just use the same value. */
2497 if (h->weakdef != NULL)
2499 BFD_ASSERT (h->weakdef->root.type == bfd_link_hash_defined
2500 || h->weakdef->root.type == bfd_link_hash_defweak);
2501 h->root.u.def.section = h->weakdef->root.u.def.section;
2502 h->root.u.def.value = h->weakdef->root.u.def.value;
2506 /* This is a reference to a symbol defined by a dynamic object which
2507 is not a function. */
2509 /* If we are creating a shared library, we must presume that the
2510 only references to the symbol are via the global offset table.
2511 For such cases we need not do anything here; the relocations will
2512 be handled correctly by relocate_section. */
2516 /* If there are no references to this symbol that do not use the
2517 GOT, we don't need to generate a copy reloc. */
2518 if ((h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0)
2521 /* We must allocate the symbol in our .dynbss section, which will
2522 become part of the .bss section of the executable. There will be
2523 an entry for this symbol in the .dynsym section. The dynamic
2524 object will contain position independent code, so all references
2525 from the dynamic object to this symbol will go through the global
2526 offset table. The dynamic linker will use the .dynsym entry to
2527 determine the address it must put in the global offset table, so
2528 both the dynamic object and the regular object will refer to the
2529 same memory location for the variable.
2531 Of course, if the symbol is sufficiently small, we must instead
2532 allocate it in .sbss. FIXME: It would be better to do this if and
2533 only if there were actually SDAREL relocs for that symbol. */
2535 if (h->size <= elf_gp_size (htab->elf.dynobj))
2539 BFD_ASSERT (s != NULL);
2541 /* We must generate a R_PPC_COPY reloc to tell the dynamic linker to
2542 copy the initial value out of the dynamic object and into the
2543 runtime process image. We need to remember the offset into the
2544 .rela.bss section we are going to use. */
2545 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
2549 if (h->size <= elf_gp_size (htab->elf.dynobj))
2550 srel = htab->relsbss;
2552 srel = htab->relbss;
2553 BFD_ASSERT (srel != NULL);
2554 srel->_raw_size += sizeof (Elf32_External_Rela);
2555 h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_COPY;
2558 /* We need to figure out the alignment required for this symbol. I
2559 have no idea how ELF linkers handle this. */
2560 power_of_two = bfd_log2 (h->size);
2561 if (power_of_two > 4)
2564 /* Apply the required alignment. */
2565 s->_raw_size = BFD_ALIGN (s->_raw_size,
2566 (bfd_size_type) (1 << power_of_two));
2567 if (power_of_two > bfd_get_section_alignment (htab->elf.dynobj, s))
2569 if (! bfd_set_section_alignment (htab->elf.dynobj, s, power_of_two))
2573 /* Define the symbol as being at this point in the section. */
2574 h->root.u.def.section = s;
2575 h->root.u.def.value = s->_raw_size;
2577 /* Increment the section size to make room for the symbol. */
2578 s->_raw_size += h->size;
2583 /* This is the condition under which finish_dynamic_symbol will be
2584 called from elflink.h. If elflink.h doesn't call our
2585 finish_dynamic_symbol routine, we'll need to do something about
2586 initializing any .plt and .got entries in relocate_section. */
2587 #define WILL_CALL_FINISH_DYNAMIC_SYMBOL(DYN, INFO, H) \
2589 && ((INFO)->shared \
2590 || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) \
2591 && ((H)->dynindx != -1 \
2592 || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0))
2594 /* Allocate space in associated reloc sections for dynamic relocs. */
2597 allocate_dynrelocs (h, inf)
2598 struct elf_link_hash_entry *h;
2601 struct bfd_link_info *info = (struct bfd_link_info *) inf;
2602 struct ppc_elf_link_hash_entry *eh;
2603 struct ppc_elf_link_hash_table *htab;
2604 struct ppc_elf_dyn_relocs *p;
2606 if (h->root.type == bfd_link_hash_indirect)
2609 if (h->root.type == bfd_link_hash_warning)
2610 /* When warning symbols are created, they **replace** the "real"
2611 entry in the hash table, thus we never get to see the real
2612 symbol in a hash traversal. So look at it now. */
2613 h = (struct elf_link_hash_entry *) h->root.u.i.link;
2615 htab = ppc_elf_hash_table (info);
2616 if (htab->elf.dynamic_sections_created
2617 && h->plt.refcount > 0)
2619 /* Make sure this symbol is output as a dynamic symbol. */
2620 if (h->dynindx == -1
2621 && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0)
2623 if (! bfd_elf32_link_record_dynamic_symbol (info, h))
2627 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, info, h))
2629 asection *s = htab->plt;
2631 /* If this is the first .plt entry, make room for the special
2633 if (s->_raw_size == 0)
2634 s->_raw_size += PLT_INITIAL_ENTRY_SIZE;
2636 /* The PowerPC PLT is actually composed of two parts, the
2637 first part is 2 words (for a load and a jump), and then
2638 there is a remaining word available at the end. */
2639 h->plt.offset = (PLT_INITIAL_ENTRY_SIZE
2641 * ((s->_raw_size - PLT_INITIAL_ENTRY_SIZE)
2642 / PLT_ENTRY_SIZE)));
2644 /* If this symbol is not defined in a regular file, and we
2645 are not generating a shared library, then set the symbol
2646 to this location in the .plt. This is required to make
2647 function pointers compare as equal between the normal
2648 executable and the shared library. */
2650 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
2652 h->root.u.def.section = s;
2653 h->root.u.def.value = h->plt.offset;
2656 /* Make room for this entry. After the 8192nd entry, room
2657 for two entries is allocated. */
2658 s->_raw_size += PLT_ENTRY_SIZE;
2659 if ((s->_raw_size - PLT_INITIAL_ENTRY_SIZE) / PLT_ENTRY_SIZE
2660 >= PLT_NUM_SINGLE_ENTRIES)
2661 s->_raw_size += PLT_ENTRY_SIZE;
2663 /* We also need to make an entry in the .rela.plt section. */
2664 htab->relplt->_raw_size += sizeof (Elf32_External_Rela);
2668 h->plt.offset = (bfd_vma) -1;
2669 h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
2674 h->plt.offset = (bfd_vma) -1;
2675 h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
2678 eh = (struct ppc_elf_link_hash_entry *) h;
2679 if (eh->elf.got.refcount > 0)
2681 /* Make sure this symbol is output as a dynamic symbol. */
2682 if (eh->elf.dynindx == -1
2683 && (eh->elf.elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0)
2685 if (!bfd_elf32_link_record_dynamic_symbol (info, &eh->elf))
2689 if (eh->tls_mask == (TLS_TLS | TLS_LD)
2690 && !(eh->elf.elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC))
2691 /* If just an LD reloc, we'll just use htab->tlsld_got.offset. */
2692 eh->elf.got.offset = (bfd_vma) -1;
2696 eh->elf.got.offset = htab->got->_raw_size;
2697 if ((eh->tls_mask & TLS_TLS) != 0)
2699 if ((eh->tls_mask & (TLS_GD | TLS_LD)) != 0)
2700 htab->got->_raw_size += 8;
2701 if ((eh->tls_mask & (TLS_TPREL | TLS_TPRELGD)) != 0)
2702 htab->got->_raw_size += 4;
2703 if ((eh->tls_mask & TLS_DTPREL) != 0)
2704 htab->got->_raw_size += 4;
2707 htab->got->_raw_size += 4;
2708 dyn = htab->elf.dynamic_sections_created;
2709 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info, &eh->elf))
2711 /* All the entries we allocated need relocs. */
2712 htab->relgot->_raw_size
2713 += ((htab->got->_raw_size - eh->elf.got.offset) / 4
2714 * sizeof (Elf32_External_Rela));
2715 /* Except LD only needs one. */
2716 if ((eh->tls_mask & TLS_LD) != 0)
2717 htab->relgot->_raw_size -= sizeof (Elf32_External_Rela);
2722 eh->elf.got.offset = (bfd_vma) -1;
2724 for (p = eh->dyn_relocs; p != NULL; p = p->next)
2726 asection *sreloc = elf_section_data (p->sec)->sreloc;
2727 sreloc->_raw_size += p->count * sizeof (Elf32_External_Rela);
2733 /* Find any dynamic relocs that apply to read-only sections. */
2736 readonly_dynrelocs (h, info)
2737 struct elf_link_hash_entry *h;
2740 struct ppc_elf_dyn_relocs *p;
2742 if (h->root.type == bfd_link_hash_indirect)
2745 if (h->root.type == bfd_link_hash_warning)
2746 h = (struct elf_link_hash_entry *) h->root.u.i.link;
2748 for (p = ppc_elf_hash_entry (h)->dyn_relocs; p != NULL; p = p->next)
2750 asection *s = p->sec->output_section;
2753 && ((s->flags & (SEC_READONLY | SEC_ALLOC))
2754 == (SEC_READONLY | SEC_ALLOC)))
2756 ((struct bfd_link_info *) info)->flags |= DF_TEXTREL;
2758 /* Not an error, just cut short the traversal. */
2765 /* Set the sizes of the dynamic sections. */
2768 ppc_elf_size_dynamic_sections (output_bfd, info)
2769 bfd *output_bfd ATTRIBUTE_UNUSED;
2770 struct bfd_link_info *info;
2772 struct ppc_elf_link_hash_table *htab;
2778 fprintf (stderr, "ppc_elf_size_dynamic_sections called\n");
2781 htab = ppc_elf_hash_table (info);
2782 BFD_ASSERT (htab->elf.dynobj != NULL);
2784 if (elf_hash_table (info)->dynamic_sections_created)
2786 /* Set the contents of the .interp section to the interpreter. */
2789 s = bfd_get_section_by_name (htab->elf.dynobj, ".interp");
2790 BFD_ASSERT (s != NULL);
2791 s->_raw_size = sizeof ELF_DYNAMIC_INTERPRETER;
2792 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
2796 if (htab->tlsld_got.refcount > 0)
2798 htab->tlsld_got.offset = htab->got->_raw_size;
2799 htab->got->_raw_size += 8;
2801 htab->relgot->_raw_size += sizeof (Elf32_External_Rela);
2804 htab->tlsld_got.offset = (bfd_vma) -1;
2806 /* Set up .got offsets for local syms, and space for local dynamic
2808 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
2810 bfd_signed_vma *local_got;
2811 bfd_signed_vma *end_local_got;
2813 bfd_size_type locsymcount;
2814 Elf_Internal_Shdr *symtab_hdr;
2817 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour)
2820 for (s = ibfd->sections; s != NULL; s = s->next)
2822 struct ppc_elf_dyn_relocs *p;
2824 for (p = ((struct ppc_elf_dyn_relocs *)
2825 elf_section_data (s)->local_dynrel);
2829 if (!bfd_is_abs_section (p->sec)
2830 && bfd_is_abs_section (p->sec->output_section))
2832 /* Input section has been discarded, either because
2833 it is a copy of a linkonce section or due to
2834 linker script /DISCARD/, so we'll be discarding
2837 else if (p->count != 0)
2839 elf_section_data (p->sec)->sreloc->_raw_size
2840 += p->count * sizeof (Elf32_External_Rela);
2841 if ((p->sec->output_section->flags
2842 & (SEC_READONLY | SEC_ALLOC))
2843 == (SEC_READONLY | SEC_ALLOC))
2844 info->flags |= DF_TEXTREL;
2849 local_got = elf_local_got_refcounts (ibfd);
2853 symtab_hdr = &elf_tdata (ibfd)->symtab_hdr;
2854 locsymcount = symtab_hdr->sh_info;
2855 end_local_got = local_got + locsymcount;
2856 lgot_masks = (char *) end_local_got;
2858 srel = htab->relgot;
2859 for (; local_got < end_local_got; ++local_got, ++lgot_masks)
2862 if (*lgot_masks == (TLS_TLS | TLS_LD))
2864 /* If just an LD reloc, we'll just use
2865 htab->tlsld_got.offset. */
2866 if (htab->tlsld_got.offset == (bfd_vma) -1)
2868 htab->tlsld_got.offset = s->_raw_size;
2871 srel->_raw_size += sizeof (Elf32_External_Rela);
2873 *local_got = (bfd_vma) -1;
2877 *local_got = s->_raw_size;
2878 if ((*lgot_masks & TLS_TLS) != 0)
2880 if ((*lgot_masks & TLS_GD) != 0)
2882 if ((*lgot_masks & (TLS_TPREL | TLS_TPRELGD)) != 0)
2884 if ((*lgot_masks & TLS_DTPREL) != 0)
2890 srel->_raw_size += ((s->_raw_size - *local_got) / 4
2891 * sizeof (Elf32_External_Rela));
2895 *local_got = (bfd_vma) -1;
2898 /* Allocate space for global sym dynamic relocs. */
2899 elf_link_hash_traverse (elf_hash_table (info), allocate_dynrelocs, info);
2901 /* We've now determined the sizes of the various dynamic sections.
2902 Allocate memory for them. */
2904 for (s = htab->elf.dynobj->sections; s != NULL; s = s->next)
2906 if ((s->flags & SEC_LINKER_CREATED) == 0)
2911 || (htab->sdata != NULL && s == htab->sdata->section)
2912 || (htab->sdata2 != NULL && s == htab->sdata2->section))
2914 /* Strip this section if we don't need it; see the
2917 else if (strncmp (bfd_get_section_name (dynobj, s), ".rela", 5) == 0)
2919 if (s->_raw_size == 0)
2921 /* If we don't need this section, strip it from the
2922 output file. This is mostly to handle .rela.bss and
2923 .rela.plt. We must create both sections in
2924 create_dynamic_sections, because they must be created
2925 before the linker maps input sections to output
2926 sections. The linker does that before
2927 adjust_dynamic_symbol is called, and it is that
2928 function which decides whether anything needs to go
2929 into these sections. */
2933 /* Remember whether there are any relocation sections. */
2936 /* We use the reloc_count field as a counter if we need
2937 to copy relocs into the output file. */
2943 /* It's not one of our sections, so don't allocate space. */
2947 if (s->_raw_size == 0)
2949 _bfd_strip_section_from_output (info, s);
2953 /* Allocate memory for the section contents. */
2954 s->contents = (bfd_byte *) bfd_zalloc (htab->elf.dynobj, s->_raw_size);
2955 if (s->contents == NULL)
2959 if (htab->elf.dynamic_sections_created)
2961 /* Add some entries to the .dynamic section. We fill in the
2962 values later, in ppc_elf_finish_dynamic_sections, but we
2963 must add the entries now so that we get the correct size for
2964 the .dynamic section. The DT_DEBUG entry is filled in by the
2965 dynamic linker and used by the debugger. */
2966 #define add_dynamic_entry(TAG, VAL) \
2967 bfd_elf32_add_dynamic_entry (info, (bfd_vma) (TAG), (bfd_vma) (VAL))
2971 if (!add_dynamic_entry (DT_DEBUG, 0))
2975 if (htab->plt != NULL && htab->plt->_raw_size != 0)
2977 if (!add_dynamic_entry (DT_PLTGOT, 0)
2978 || !add_dynamic_entry (DT_PLTRELSZ, 0)
2979 || !add_dynamic_entry (DT_PLTREL, DT_RELA)
2980 || !add_dynamic_entry (DT_JMPREL, 0))
2986 if (!add_dynamic_entry (DT_RELA, 0)
2987 || !add_dynamic_entry (DT_RELASZ, 0)
2988 || !add_dynamic_entry (DT_RELAENT, sizeof (Elf32_External_Rela)))
2992 /* If any dynamic relocs apply to a read-only section, then we
2993 need a DT_TEXTREL entry. */
2994 if ((info->flags & DF_TEXTREL) == 0)
2995 elf_link_hash_traverse (elf_hash_table (info), readonly_dynrelocs,
2998 if ((info->flags & DF_TEXTREL) != 0)
3000 if (!add_dynamic_entry (DT_TEXTREL, 0))
3004 #undef add_dynamic_entry
3010 update_local_sym_info (abfd, symtab_hdr, r_symndx, tls_type)
3012 Elf_Internal_Shdr *symtab_hdr;
3013 unsigned long r_symndx;
3016 bfd_signed_vma *local_got_refcounts = elf_local_got_refcounts (abfd);
3017 char *local_got_tls_masks;
3019 if (local_got_refcounts == NULL)
3021 bfd_size_type size = symtab_hdr->sh_info;
3023 size *= sizeof (*local_got_refcounts) + sizeof (*local_got_tls_masks);
3024 local_got_refcounts = (bfd_signed_vma *) bfd_zalloc (abfd, size);
3025 if (local_got_refcounts == NULL)
3027 elf_local_got_refcounts (abfd) = local_got_refcounts;
3030 local_got_refcounts[r_symndx] += 1;
3031 local_got_tls_masks = (char *) (local_got_refcounts + symtab_hdr->sh_info);
3032 local_got_tls_masks[r_symndx] |= tls_type;
3037 bad_shared_reloc (abfd, r_type)
3039 enum elf_ppc_reloc_type r_type;
3041 (*_bfd_error_handler)
3042 (_("%s: relocation %s cannot be used when making a shared object"),
3043 bfd_archive_filename (abfd),
3044 ppc_elf_howto_table[(int) r_type]->name);
3045 bfd_set_error (bfd_error_bad_value);
3048 /* Look through the relocs for a section during the first phase, and
3049 allocate space in the global offset table or procedure linkage
3053 ppc_elf_check_relocs (abfd, info, sec, relocs)
3055 struct bfd_link_info *info;
3057 const Elf_Internal_Rela *relocs;
3059 struct ppc_elf_link_hash_table *htab;
3060 Elf_Internal_Shdr *symtab_hdr;
3061 struct elf_link_hash_entry **sym_hashes;
3062 const Elf_Internal_Rela *rel;
3063 const Elf_Internal_Rela *rel_end;
3066 if (info->relocateable)
3070 fprintf (stderr, "ppc_elf_check_relocs called for section %s in %s\n",
3071 bfd_get_section_name (abfd, sec),
3072 bfd_archive_filename (abfd));
3075 /* Create the linker generated sections all the time so that the
3076 special symbols are created. */
3078 htab = ppc_elf_hash_table (info);
3079 if (htab->sdata == NULL)
3081 htab->sdata = elf_linker_section (abfd, LINKER_SECTION_SDATA);
3082 if (htab->sdata == NULL)
3083 htab->sdata = ppc_elf_create_linker_section (abfd, info,
3084 LINKER_SECTION_SDATA);
3085 if (htab->sdata == NULL)
3089 if (htab->sdata2 == NULL)
3091 htab->sdata2 = elf_linker_section (abfd, LINKER_SECTION_SDATA2);
3092 if (htab->sdata2 == NULL)
3093 htab->sdata2 = ppc_elf_create_linker_section (abfd, info,
3094 LINKER_SECTION_SDATA2);
3095 if (htab->sdata2 == NULL)
3099 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
3100 sym_hashes = elf_sym_hashes (abfd);
3103 rel_end = relocs + sec->reloc_count;
3104 for (rel = relocs; rel < rel_end; rel++)
3106 unsigned long r_symndx;
3107 enum elf_ppc_reloc_type r_type;
3108 struct elf_link_hash_entry *h;
3111 r_symndx = ELF32_R_SYM (rel->r_info);
3112 if (r_symndx < symtab_hdr->sh_info)
3115 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
3117 /* If a relocation refers to _GLOBAL_OFFSET_TABLE_, create the .got.
3118 This shows up in particular in an R_PPC_ADDR32 in the eabi
3120 if (h && strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
3122 if (htab->got == NULL)
3124 if (htab->elf.dynobj == NULL)
3125 htab->elf.dynobj = abfd;
3126 if (!ppc_elf_create_got (htab->elf.dynobj, info))
3131 r_type = (enum elf_ppc_reloc_type) ELF32_R_TYPE (rel->r_info);
3134 case R_PPC_GOT_TLSLD16:
3135 case R_PPC_GOT_TLSLD16_LO:
3136 case R_PPC_GOT_TLSLD16_HI:
3137 case R_PPC_GOT_TLSLD16_HA:
3138 htab->tlsld_got.refcount += 1;
3139 tls_type = TLS_TLS | TLS_LD;
3142 case R_PPC_GOT_TLSGD16:
3143 case R_PPC_GOT_TLSGD16_LO:
3144 case R_PPC_GOT_TLSGD16_HI:
3145 case R_PPC_GOT_TLSGD16_HA:
3146 tls_type = TLS_TLS | TLS_GD;
3149 case R_PPC_GOT_TPREL16:
3150 case R_PPC_GOT_TPREL16_LO:
3151 case R_PPC_GOT_TPREL16_HI:
3152 case R_PPC_GOT_TPREL16_HA:
3154 info->flags |= DF_STATIC_TLS;
3155 tls_type = TLS_TLS | TLS_TPREL;
3158 case R_PPC_GOT_DTPREL16:
3159 case R_PPC_GOT_DTPREL16_LO:
3160 case R_PPC_GOT_DTPREL16_HI:
3161 case R_PPC_GOT_DTPREL16_HA:
3162 tls_type = TLS_TLS | TLS_DTPREL;
3164 sec->has_tls_reloc = 1;
3167 /* GOT16 relocations */
3169 case R_PPC_GOT16_LO:
3170 case R_PPC_GOT16_HI:
3171 case R_PPC_GOT16_HA:
3172 /* This symbol requires a global offset table entry. */
3173 if (htab->got == NULL)
3175 if (htab->elf.dynobj == NULL)
3176 htab->elf.dynobj = abfd;
3177 if (!ppc_elf_create_got (htab->elf.dynobj, info))
3182 h->got.refcount += 1;
3183 ppc_elf_hash_entry (h)->tls_mask |= tls_type;
3186 /* This is a global offset table entry for a local symbol. */
3187 if (!update_local_sym_info (abfd, symtab_hdr, r_symndx, tls_type))
3191 /* Indirect .sdata relocation. */
3192 case R_PPC_EMB_SDAI16:
3195 bad_shared_reloc (abfd, r_type);
3198 if (!bfd_elf32_create_pointer_linker_section (abfd, info,
3199 htab->sdata, h, rel))
3203 /* Indirect .sdata2 relocation. */
3204 case R_PPC_EMB_SDA2I16:
3207 bad_shared_reloc (abfd, r_type);
3210 if (!bfd_elf32_create_pointer_linker_section (abfd, info,
3211 htab->sdata2, h, rel))
3215 case R_PPC_SDAREL16:
3216 case R_PPC_EMB_SDA2REL:
3217 case R_PPC_EMB_SDA21:
3218 case R_PPC_EMB_RELSDA:
3219 case R_PPC_EMB_NADDR32:
3220 case R_PPC_EMB_NADDR16:
3221 case R_PPC_EMB_NADDR16_LO:
3222 case R_PPC_EMB_NADDR16_HI:
3223 case R_PPC_EMB_NADDR16_HA:
3226 bad_shared_reloc (abfd, r_type);
3232 case R_PPC_PLTREL24:
3233 case R_PPC_PLTREL32:
3234 case R_PPC_PLT16_LO:
3235 case R_PPC_PLT16_HI:
3236 case R_PPC_PLT16_HA:
3238 fprintf (stderr, "Reloc requires a PLT entry\n");
3240 /* This symbol requires a procedure linkage table entry. We
3241 actually build the entry in finish_dynamic_symbol,
3242 because this might be a case of linking PIC code without
3243 linking in any dynamic objects, in which case we don't
3244 need to generate a procedure linkage table after all. */
3248 /* It does not make sense to have a procedure linkage
3249 table entry for a local symbol. */
3250 bfd_set_error (bfd_error_bad_value);
3254 h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
3258 /* The following relocations don't need to propagate the
3259 relocation if linking a shared object since they are
3260 section relative. */
3262 case R_PPC_SECTOFF_LO:
3263 case R_PPC_SECTOFF_HI:
3264 case R_PPC_SECTOFF_HA:
3265 case R_PPC_DTPREL16:
3266 case R_PPC_DTPREL16_LO:
3267 case R_PPC_DTPREL16_HI:
3268 case R_PPC_DTPREL16_HA:
3272 /* This are just markers. */
3274 case R_PPC_EMB_MRKREF:
3279 /* These should only appear in dynamic objects. */
3281 case R_PPC_GLOB_DAT:
3282 case R_PPC_JMP_SLOT:
3283 case R_PPC_RELATIVE:
3286 /* These aren't handled yet. We'll report an error later. */
3288 case R_PPC_EMB_RELSEC16:
3289 case R_PPC_EMB_RELST_LO:
3290 case R_PPC_EMB_RELST_HI:
3291 case R_PPC_EMB_RELST_HA:
3292 case R_PPC_EMB_BIT_FLD:
3295 /* This refers only to functions defined in the shared library. */
3296 case R_PPC_LOCAL24PC:
3299 /* This relocation describes the C++ object vtable hierarchy.
3300 Reconstruct it for later use during GC. */
3301 case R_PPC_GNU_VTINHERIT:
3302 if (!_bfd_elf32_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
3306 /* This relocation describes which C++ vtable entries are actually
3307 used. Record for later use during GC. */
3308 case R_PPC_GNU_VTENTRY:
3309 if (!_bfd_elf32_gc_record_vtentry (abfd, sec, h, rel->r_addend))
3313 /* We shouldn't really be seeing these. */
3316 info->flags |= DF_STATIC_TLS;
3320 case R_PPC_DTPMOD32:
3321 case R_PPC_DTPREL32:
3325 case R_PPC_TPREL16_LO:
3326 case R_PPC_TPREL16_HI:
3327 case R_PPC_TPREL16_HA:
3329 info->flags |= DF_STATIC_TLS;
3332 /* When creating a shared object, we must copy these
3333 relocs into the output file. We create a reloc
3334 section in dynobj and make room for the reloc. */
3337 case R_PPC_REL14_BRTAKEN:
3338 case R_PPC_REL14_BRNTAKEN:
3341 || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0
3342 || SYMBOL_REFERENCES_LOCAL (info, h))
3349 case R_PPC_ADDR16_LO:
3350 case R_PPC_ADDR16_HI:
3351 case R_PPC_ADDR16_HA:
3353 case R_PPC_ADDR14_BRTAKEN:
3354 case R_PPC_ADDR14_BRNTAKEN:
3357 if (h != NULL && !info->shared)
3359 /* We may need a plt entry if the symbol turns out to be
3360 a function defined in a dynamic object. */
3363 /* We may need a copy reloc too. */
3364 h->elf_link_hash_flags |= ELF_LINK_NON_GOT_REF;
3369 struct ppc_elf_dyn_relocs *p;
3370 struct ppc_elf_dyn_relocs **head;
3373 fprintf (stderr, "ppc_elf_check_relocs need to create relocation for %s\n",
3374 (h && h->root.root.string) ? h->root.root.string : "<unknown>");
3380 name = (bfd_elf_string_from_elf_section
3382 elf_elfheader (abfd)->e_shstrndx,
3383 elf_section_data (sec)->rel_hdr.sh_name));
3387 BFD_ASSERT (strncmp (name, ".rela", 5) == 0
3388 && strcmp (bfd_get_section_name (abfd, sec),
3391 sreloc = bfd_get_section_by_name (htab->elf.dynobj, name);
3396 sreloc = bfd_make_section (htab->elf.dynobj, name);
3397 flags = (SEC_HAS_CONTENTS | SEC_READONLY
3398 | SEC_IN_MEMORY | SEC_LINKER_CREATED);
3399 if ((sec->flags & SEC_ALLOC) != 0)
3400 flags |= SEC_ALLOC | SEC_LOAD;
3402 || ! bfd_set_section_flags (htab->elf.dynobj,
3404 || ! bfd_set_section_alignment (htab->elf.dynobj,
3408 elf_section_data (sec)->sreloc = sreloc;
3411 /* If this is a global symbol, we count the number of
3412 relocations we need for this symbol. */
3415 head = &ppc_elf_hash_entry (h)->dyn_relocs;
3419 /* Track dynamic relocs needed for local syms too.
3420 We really need local syms available to do this
3424 s = (bfd_section_from_r_symndx
3425 (abfd, &ppc_elf_hash_table (info)->sym_sec,
3430 head = ((struct ppc_elf_dyn_relocs **)
3431 &elf_section_data (s)->local_dynrel);
3435 if (p == NULL || p->sec != sec)
3437 p = ((struct ppc_elf_dyn_relocs *)
3438 bfd_alloc (htab->elf.dynobj, sizeof *p));
3457 /* Return the section that should be marked against GC for a given
3461 ppc_elf_gc_mark_hook (sec, info, rel, h, sym)
3463 struct bfd_link_info *info ATTRIBUTE_UNUSED;
3464 Elf_Internal_Rela *rel;
3465 struct elf_link_hash_entry *h;
3466 Elf_Internal_Sym *sym;
3470 switch (ELF32_R_TYPE (rel->r_info))
3472 case R_PPC_GNU_VTINHERIT:
3473 case R_PPC_GNU_VTENTRY:
3477 switch (h->root.type)
3479 case bfd_link_hash_defined:
3480 case bfd_link_hash_defweak:
3481 return h->root.u.def.section;
3483 case bfd_link_hash_common:
3484 return h->root.u.c.p->section;
3492 return bfd_section_from_elf_index (sec->owner, sym->st_shndx);
3497 /* Update the got, plt and dynamic reloc reference counts for the
3498 section being removed. */
3501 ppc_elf_gc_sweep_hook (abfd, info, sec, relocs)
3503 struct bfd_link_info *info;
3505 const Elf_Internal_Rela *relocs;
3507 struct ppc_elf_link_hash_table *htab;
3508 Elf_Internal_Shdr *symtab_hdr;
3509 struct elf_link_hash_entry **sym_hashes;
3510 bfd_signed_vma *local_got_refcounts;
3511 const Elf_Internal_Rela *rel, *relend;
3513 elf_section_data (sec)->local_dynrel = NULL;
3515 htab = ppc_elf_hash_table (info);
3516 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
3517 sym_hashes = elf_sym_hashes (abfd);
3518 local_got_refcounts = elf_local_got_refcounts (abfd);
3520 relend = relocs + sec->reloc_count;
3521 for (rel = relocs; rel < relend; rel++)
3523 unsigned long r_symndx;
3524 enum elf_ppc_reloc_type r_type;
3525 struct elf_link_hash_entry *h = NULL;
3527 r_symndx = ELF32_R_SYM (rel->r_info);
3528 if (r_symndx >= symtab_hdr->sh_info)
3530 struct ppc_elf_dyn_relocs **pp, *p;
3531 struct ppc_elf_link_hash_entry *eh;
3533 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
3534 eh = (struct ppc_elf_link_hash_entry *) h;
3536 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next)
3539 /* Everything must go for SEC. */
3545 r_type = (enum elf_ppc_reloc_type) ELF32_R_TYPE (rel->r_info);
3548 case R_PPC_GOT_TLSLD16:
3549 case R_PPC_GOT_TLSLD16_LO:
3550 case R_PPC_GOT_TLSLD16_HI:
3551 case R_PPC_GOT_TLSLD16_HA:
3552 htab->tlsld_got.refcount -= 1;
3555 case R_PPC_GOT_TLSGD16:
3556 case R_PPC_GOT_TLSGD16_LO:
3557 case R_PPC_GOT_TLSGD16_HI:
3558 case R_PPC_GOT_TLSGD16_HA:
3559 case R_PPC_GOT_TPREL16:
3560 case R_PPC_GOT_TPREL16_LO:
3561 case R_PPC_GOT_TPREL16_HI:
3562 case R_PPC_GOT_TPREL16_HA:
3563 case R_PPC_GOT_DTPREL16:
3564 case R_PPC_GOT_DTPREL16_LO:
3565 case R_PPC_GOT_DTPREL16_HI:
3566 case R_PPC_GOT_DTPREL16_HA:
3568 case R_PPC_GOT16_LO:
3569 case R_PPC_GOT16_HI:
3570 case R_PPC_GOT16_HA:
3573 if (h->got.refcount > 0)
3576 else if (local_got_refcounts != NULL)
3578 if (local_got_refcounts[r_symndx] > 0)
3579 local_got_refcounts[r_symndx]--;
3585 case R_PPC_REL14_BRTAKEN:
3586 case R_PPC_REL14_BRNTAKEN:
3589 || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0
3590 || SYMBOL_REFERENCES_LOCAL (info, h))
3597 case R_PPC_ADDR16_LO:
3598 case R_PPC_ADDR16_HI:
3599 case R_PPC_ADDR16_HA:
3601 case R_PPC_ADDR14_BRTAKEN:
3602 case R_PPC_ADDR14_BRNTAKEN:
3606 case R_PPC_PLTREL24:
3607 case R_PPC_PLT16_LO:
3608 case R_PPC_PLT16_HI:
3609 case R_PPC_PLT16_HA:
3612 if (h->plt.refcount > 0)
3624 /* Set htab->tls_sec and htab->tls_get_addr. */
3627 ppc_elf_tls_setup (obfd, info)
3629 struct bfd_link_info *info;
3632 struct ppc_elf_link_hash_table *htab;
3634 htab = ppc_elf_hash_table (info);
3635 htab->tls_get_addr = elf_link_hash_lookup (&htab->elf, "__tls_get_addr",
3636 FALSE, FALSE, TRUE);
3638 for (tls = obfd->sections; tls != NULL; tls = tls->next)
3639 if ((tls->flags & (SEC_THREAD_LOCAL | SEC_LOAD))
3640 == (SEC_THREAD_LOCAL | SEC_LOAD))
3642 htab->tls_sec = tls;
3647 /* Run through all the TLS relocs looking for optimization
3651 ppc_elf_tls_optimize (obfd, info)
3652 bfd *obfd ATTRIBUTE_UNUSED;
3653 struct bfd_link_info *info;
3657 struct ppc_elf_link_hash_table *htab;
3659 if (info->relocateable || info->shared)
3662 htab = ppc_elf_hash_table (info);
3663 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
3665 Elf_Internal_Sym *locsyms = NULL;
3666 Elf_Internal_Shdr *symtab_hdr = &elf_tdata (ibfd)->symtab_hdr;
3668 for (sec = ibfd->sections; sec != NULL; sec = sec->next)
3669 if (sec->has_tls_reloc && !bfd_is_abs_section (sec->output_section))
3671 Elf_Internal_Rela *relstart, *rel, *relend;
3672 int expecting_tls_get_addr;
3674 /* Read the relocations. */
3675 relstart = _bfd_elf32_link_read_relocs (ibfd, sec, (PTR) NULL,
3676 (Elf_Internal_Rela *) NULL,
3678 if (relstart == NULL)
3681 expecting_tls_get_addr = 0;
3682 relend = relstart + sec->reloc_count;
3683 for (rel = relstart; rel < relend; rel++)
3685 enum elf_ppc_reloc_type r_type;
3686 unsigned long r_symndx;
3687 struct elf_link_hash_entry *h = NULL;
3689 char tls_set, tls_clear;
3690 bfd_boolean is_local;
3692 r_symndx = ELF32_R_SYM (rel->r_info);
3693 if (r_symndx >= symtab_hdr->sh_info)
3695 struct elf_link_hash_entry **sym_hashes;
3697 sym_hashes = elf_sym_hashes (ibfd);
3698 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
3699 while (h->root.type == bfd_link_hash_indirect
3700 || h->root.type == bfd_link_hash_warning)
3701 h = (struct elf_link_hash_entry *) h->root.u.i.link;
3706 || !(h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC))
3709 r_type = (enum elf_ppc_reloc_type) ELF32_R_TYPE (rel->r_info);
3712 case R_PPC_GOT_TLSLD16:
3713 case R_PPC_GOT_TLSLD16_LO:
3714 case R_PPC_GOT_TLSLD16_HI:
3715 case R_PPC_GOT_TLSLD16_HA:
3716 /* These relocs should never be against a symbol
3717 defined in a shared lib. Leave them alone if
3718 that turns out to be the case. */
3719 expecting_tls_get_addr = 0;
3720 htab->tlsld_got.refcount -= 1;
3727 expecting_tls_get_addr = 1;
3730 case R_PPC_GOT_TLSGD16:
3731 case R_PPC_GOT_TLSGD16_LO:
3732 case R_PPC_GOT_TLSGD16_HI:
3733 case R_PPC_GOT_TLSGD16_HA:
3739 tls_set = TLS_TLS | TLS_TPRELGD;
3741 expecting_tls_get_addr = 1;
3744 case R_PPC_GOT_TPREL16:
3745 case R_PPC_GOT_TPREL16_LO:
3746 case R_PPC_GOT_TPREL16_HI:
3747 case R_PPC_GOT_TPREL16_HA:
3748 expecting_tls_get_addr = 0;
3753 tls_clear = TLS_TPREL;
3760 case R_PPC_REL14_BRTAKEN:
3761 case R_PPC_REL14_BRNTAKEN:
3763 if (expecting_tls_get_addr
3765 && h == htab->tls_get_addr)
3767 if (h->plt.refcount > 0)
3768 h->plt.refcount -= 1;
3770 expecting_tls_get_addr = 0;
3774 expecting_tls_get_addr = 0;
3782 /* We managed to get rid of a got entry. */
3783 if (h->got.refcount > 0)
3784 h->got.refcount -= 1;
3786 tls_mask = &ppc_elf_hash_entry (h)->tls_mask;
3790 Elf_Internal_Sym *sym;
3791 bfd_signed_vma *lgot_refs;
3794 if (locsyms == NULL)
3796 locsyms = (Elf_Internal_Sym *) symtab_hdr->contents;
3797 if (locsyms == NULL)
3798 locsyms = bfd_elf_get_elf_syms (ibfd, symtab_hdr,
3799 symtab_hdr->sh_info,
3800 0, NULL, NULL, NULL);
3801 if (locsyms == NULL)
3803 if (elf_section_data (sec)->relocs != relstart)
3808 sym = locsyms + r_symndx;
3809 lgot_refs = elf_local_got_refcounts (ibfd);
3810 if (lgot_refs == NULL)
3814 /* We managed to get rid of a got entry. */
3815 if (lgot_refs[r_symndx] > 0)
3816 lgot_refs[r_symndx] -= 1;
3818 lgot_masks = (char *) (lgot_refs + symtab_hdr->sh_info);
3819 tls_mask = &lgot_masks[r_symndx];
3822 *tls_mask |= tls_set;
3823 *tls_mask &= ~tls_clear;
3826 if (elf_section_data (sec)->relocs != relstart)
3831 && (symtab_hdr->contents != (unsigned char *) locsyms))
3833 if (!info->keep_memory)
3836 symtab_hdr->contents = (unsigned char *) locsyms;
3842 /* Hook called by the linker routine which adds symbols from an object
3843 file. We use it to put .comm items in .sbss, and not .bss. */
3846 ppc_elf_add_symbol_hook (abfd, info, sym, namep, flagsp, secp, valp)
3848 struct bfd_link_info *info;
3849 const Elf_Internal_Sym *sym;
3850 const char **namep ATTRIBUTE_UNUSED;
3851 flagword *flagsp ATTRIBUTE_UNUSED;
3855 if (sym->st_shndx == SHN_COMMON
3856 && !info->relocateable
3857 && sym->st_size <= elf_gp_size (abfd)
3858 && info->hash->creator->flavour == bfd_target_elf_flavour)
3860 /* Common symbols less than or equal to -G nn bytes are automatically
3862 elf_linker_section_t *sdata
3863 = ppc_elf_create_linker_section (abfd, info, LINKER_SECTION_SDATA);
3865 if (!sdata->bss_section)
3869 /* We don't go through bfd_make_section, because we don't
3870 want to attach this common section to DYNOBJ. The linker
3871 will move the symbols to the appropriate output section
3872 when it defines common symbols. */
3873 amt = sizeof (asection);
3874 sdata->bss_section = (asection *) bfd_zalloc (abfd, amt);
3875 if (sdata->bss_section == NULL)
3877 sdata->bss_section->name = sdata->bss_name;
3878 sdata->bss_section->flags = SEC_IS_COMMON;
3879 sdata->bss_section->output_section = sdata->bss_section;
3880 amt = sizeof (asymbol);
3881 sdata->bss_section->symbol = (asymbol *) bfd_zalloc (abfd, amt);
3882 amt = sizeof (asymbol *);
3883 sdata->bss_section->symbol_ptr_ptr =
3884 (asymbol **) bfd_zalloc (abfd, amt);
3885 if (sdata->bss_section->symbol == NULL
3886 || sdata->bss_section->symbol_ptr_ptr == NULL)
3888 sdata->bss_section->symbol->name = sdata->bss_name;
3889 sdata->bss_section->symbol->flags = BSF_SECTION_SYM;
3890 sdata->bss_section->symbol->section = sdata->bss_section;
3891 *sdata->bss_section->symbol_ptr_ptr = sdata->bss_section->symbol;
3894 *secp = sdata->bss_section;
3895 *valp = sym->st_size;
3901 /* Finish up dynamic symbol handling. We set the contents of various
3902 dynamic sections here. */
3905 ppc_elf_finish_dynamic_symbol (output_bfd, info, h, sym)
3907 struct bfd_link_info *info;
3908 struct elf_link_hash_entry *h;
3909 Elf_Internal_Sym *sym;
3911 struct ppc_elf_link_hash_table *htab;
3914 fprintf (stderr, "ppc_elf_finish_dynamic_symbol called for %s",
3915 h->root.root.string);
3918 htab = ppc_elf_hash_table (info);
3919 BFD_ASSERT (htab->elf.dynobj != NULL);
3921 if (h->plt.offset != (bfd_vma) -1)
3923 Elf_Internal_Rela rela;
3925 bfd_vma reloc_index;
3928 fprintf (stderr, ", plt_offset = %d", h->plt.offset);
3931 /* This symbol has an entry in the procedure linkage table. Set
3934 BFD_ASSERT (h->dynindx != -1);
3935 BFD_ASSERT (htab->plt != NULL && htab->relplt != NULL);
3937 /* We don't need to fill in the .plt. The ppc dynamic linker
3940 /* Fill in the entry in the .rela.plt section. */
3941 rela.r_offset = (htab->plt->output_section->vma
3942 + htab->plt->output_offset
3944 rela.r_info = ELF32_R_INFO (h->dynindx, R_PPC_JMP_SLOT);
3947 reloc_index = (h->plt.offset - PLT_INITIAL_ENTRY_SIZE) / PLT_SLOT_SIZE;
3948 if (reloc_index > PLT_NUM_SINGLE_ENTRIES)
3949 reloc_index -= (reloc_index - PLT_NUM_SINGLE_ENTRIES) / 2;
3950 loc = (htab->relplt->contents
3951 + reloc_index * sizeof (Elf32_External_Rela));
3952 bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
3954 if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
3956 /* Mark the symbol as undefined, rather than as defined in
3957 the .plt section. Leave the value alone. */
3958 sym->st_shndx = SHN_UNDEF;
3959 /* If the symbol is weak, we do need to clear the value.
3960 Otherwise, the PLT entry would provide a definition for
3961 the symbol even if the symbol wasn't defined anywhere,
3962 and so the symbol would never be NULL. */
3963 if ((h->elf_link_hash_flags & ELF_LINK_HASH_REF_REGULAR_NONWEAK)
3969 if ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_COPY) != 0)
3972 Elf_Internal_Rela rela;
3975 /* This symbols needs a copy reloc. Set it up. */
3978 fprintf (stderr, ", copy");
3981 BFD_ASSERT (h->dynindx != -1);
3983 if (h->size <= elf_gp_size (htab->elf.dynobj))
3987 BFD_ASSERT (s != NULL);
3989 rela.r_offset = (h->root.u.def.value
3990 + h->root.u.def.section->output_section->vma
3991 + h->root.u.def.section->output_offset);
3992 rela.r_info = ELF32_R_INFO (h->dynindx, R_PPC_COPY);
3994 loc = s->contents + s->reloc_count++ * sizeof (Elf32_External_Rela);
3995 bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
3999 fprintf (stderr, "\n");
4002 /* Mark some specially defined symbols as absolute. */
4003 if (strcmp (h->root.root.string, "_DYNAMIC") == 0
4004 || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0
4005 || strcmp (h->root.root.string, "_PROCEDURE_LINKAGE_TABLE_") == 0)
4006 sym->st_shndx = SHN_ABS;
4011 /* Finish up the dynamic sections. */
4014 ppc_elf_finish_dynamic_sections (output_bfd, info)
4016 struct bfd_link_info *info;
4019 struct ppc_elf_link_hash_table *htab;
4022 fprintf (stderr, "ppc_elf_finish_dynamic_sections called\n");
4025 htab = ppc_elf_hash_table (info);
4026 sdyn = bfd_get_section_by_name (htab->elf.dynobj, ".dynamic");
4028 if (htab->elf.dynamic_sections_created)
4030 Elf32_External_Dyn *dyncon, *dynconend;
4032 BFD_ASSERT (htab->plt != NULL && sdyn != NULL);
4034 dyncon = (Elf32_External_Dyn *) sdyn->contents;
4035 dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->_raw_size);
4036 for (; dyncon < dynconend; dyncon++)
4038 Elf_Internal_Dyn dyn;
4041 bfd_elf32_swap_dyn_in (htab->elf.dynobj, dyncon, &dyn);
4047 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
4051 dyn.d_un.d_val = htab->relplt->_raw_size;
4056 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
4063 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
4067 /* Add a blrl instruction at _GLOBAL_OFFSET_TABLE_-4 so that a function can
4068 easily find the address of the _GLOBAL_OFFSET_TABLE_. */
4071 unsigned char *contents = htab->got->contents;
4072 bfd_put_32 (output_bfd, (bfd_vma) 0x4e800021 /* blrl */, contents);
4075 bfd_put_32 (output_bfd, (bfd_vma) 0, contents + 4);
4077 bfd_put_32 (output_bfd,
4078 sdyn->output_section->vma + sdyn->output_offset,
4081 elf_section_data (htab->got->output_section)->this_hdr.sh_entsize = 4;
4087 /* The RELOCATE_SECTION function is called by the ELF backend linker
4088 to handle the relocations for a section.
4090 The relocs are always passed as Rela structures; if the section
4091 actually uses Rel structures, the r_addend field will always be
4094 This function is responsible for adjust the section contents as
4095 necessary, and (if using Rela relocs and generating a
4096 relocateable output file) adjusting the reloc addend as
4099 This function does not have to worry about setting the reloc
4100 address or the reloc symbol index.
4102 LOCAL_SYMS is a pointer to the swapped in local symbols.
4104 LOCAL_SECTIONS is an array giving the section in the input file
4105 corresponding to the st_shndx field of each local symbol.
4107 The global hash table entry for the global symbols can be found
4108 via elf_sym_hashes (input_bfd).
4110 When generating relocateable output, this function must handle
4111 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
4112 going to be the section symbol corresponding to the output
4113 section, which means that the addend must be adjusted
4117 ppc_elf_relocate_section (output_bfd, info, input_bfd, input_section,
4118 contents, relocs, local_syms, local_sections)
4120 struct bfd_link_info *info;
4122 asection *input_section;
4124 Elf_Internal_Rela *relocs;
4125 Elf_Internal_Sym *local_syms;
4126 asection **local_sections;
4128 Elf_Internal_Shdr *symtab_hdr;
4129 struct elf_link_hash_entry **sym_hashes;
4130 struct ppc_elf_link_hash_table *htab;
4131 Elf_Internal_Rela *rel;
4132 Elf_Internal_Rela *relend;
4133 Elf_Internal_Rela outrel;
4135 asection *sreloc = NULL;
4136 bfd_vma *local_got_offsets;
4137 bfd_boolean ret = TRUE;
4140 fprintf (stderr, "ppc_elf_relocate_section called for %s section %s, %ld relocations%s\n",
4141 bfd_archive_filename (input_bfd),
4142 bfd_section_name(input_bfd, input_section),
4143 (long) input_section->reloc_count,
4144 (info->relocateable) ? " (relocatable)" : "");
4147 if (info->relocateable)
4150 if (!ppc_elf_howto_table[R_PPC_ADDR32])
4151 /* Initialize howto table if needed. */
4152 ppc_elf_howto_init ();
4154 htab = ppc_elf_hash_table (info);
4155 local_got_offsets = elf_local_got_offsets (input_bfd);
4156 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
4157 sym_hashes = elf_sym_hashes (input_bfd);
4159 relend = relocs + input_section->reloc_count;
4160 for (; rel < relend; rel++)
4162 enum elf_ppc_reloc_type r_type;
4164 bfd_reloc_status_type r;
4165 Elf_Internal_Sym *sym;
4167 struct elf_link_hash_entry *h;
4168 const char *sym_name;
4169 reloc_howto_type *howto;
4170 unsigned long r_symndx;
4172 bfd_vma branch_bit, insn, from;
4173 bfd_boolean will_become_local;
4174 bfd_boolean unresolved_reloc;
4176 unsigned int tls_type, tls_mask, tls_gd;
4178 r_type = (enum elf_ppc_reloc_type)ELF32_R_TYPE (rel->r_info);
4179 sym = (Elf_Internal_Sym *) 0;
4180 sec = (asection *) 0;
4181 h = (struct elf_link_hash_entry *) 0;
4182 unresolved_reloc = FALSE;
4184 r_symndx = ELF32_R_SYM (rel->r_info);
4185 if (r_symndx < symtab_hdr->sh_info)
4187 sym = local_syms + r_symndx;
4188 sec = local_sections[r_symndx];
4189 sym_name = bfd_elf_local_sym_name (input_bfd, sym);
4191 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, sec, rel);
4192 /* Relocs to local symbols are always resolved. */
4193 will_become_local = TRUE;
4197 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
4198 while (h->root.type == bfd_link_hash_indirect
4199 || h->root.type == bfd_link_hash_warning)
4200 h = (struct elf_link_hash_entry *) h->root.u.i.link;
4201 sym_name = h->root.root.string;
4203 /* Can this relocation be resolved immediately? */
4204 will_become_local = SYMBOL_REFERENCES_LOCAL (info, h);
4206 if (h->root.type == bfd_link_hash_defined
4207 || h->root.type == bfd_link_hash_defweak)
4209 sec = h->root.u.def.section;
4210 /* Set a flag that will be cleared later if we find a
4211 relocation value for this symbol. output_section
4212 is typically NULL for symbols satisfied by a shared
4214 if (sec->output_section == NULL)
4215 unresolved_reloc = TRUE;
4217 relocation = (h->root.u.def.value
4218 + sec->output_section->vma
4219 + sec->output_offset);
4221 else if (h->root.type == bfd_link_hash_undefweak)
4223 else if (info->shared
4224 && !info->no_undefined
4225 && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
4229 if (! ((*info->callbacks->undefined_symbol)
4230 (info, h->root.root.string, input_bfd, input_section,
4231 rel->r_offset, (!info->shared
4232 || info->no_undefined
4233 || ELF_ST_VISIBILITY (h->other)))))
4239 /* TLS optimizations. Replace instruction sequences and relocs
4240 based on information we collected in tls_optimize. We edit
4241 RELOCS so that --emit-relocs will output something sensible
4242 for the final instruction stream. */
4245 if (IS_PPC_TLS_RELOC (r_type))
4248 tls_mask = ((struct ppc_elf_link_hash_entry *) h)->tls_mask;
4249 else if (local_got_offsets != NULL)
4252 lgot_masks = (char *) (local_got_offsets + symtab_hdr->sh_info);
4253 tls_mask = lgot_masks[r_symndx];
4257 /* Ensure reloc mapping code below stays sane. */
4258 if ((R_PPC_GOT_TLSLD16 & 3) != (R_PPC_GOT_TLSGD16 & 3)
4259 || (R_PPC_GOT_TLSLD16_LO & 3) != (R_PPC_GOT_TLSGD16_LO & 3)
4260 || (R_PPC_GOT_TLSLD16_HI & 3) != (R_PPC_GOT_TLSGD16_HI & 3)
4261 || (R_PPC_GOT_TLSLD16_HA & 3) != (R_PPC_GOT_TLSGD16_HA & 3)
4262 || (R_PPC_GOT_TLSLD16 & 3) != (R_PPC_GOT_TPREL16 & 3)
4263 || (R_PPC_GOT_TLSLD16_LO & 3) != (R_PPC_GOT_TPREL16_LO & 3)
4264 || (R_PPC_GOT_TLSLD16_HI & 3) != (R_PPC_GOT_TPREL16_HI & 3)
4265 || (R_PPC_GOT_TLSLD16_HA & 3) != (R_PPC_GOT_TPREL16_HA & 3))
4272 case R_PPC_GOT_TPREL16:
4273 case R_PPC_GOT_TPREL16_LO:
4275 && (tls_mask & TLS_TPREL) == 0)
4278 insn = bfd_get_32 (output_bfd, contents + rel->r_offset - 2);
4280 insn |= 0x3c020000; /* addis 0,2,0 */
4281 bfd_put_32 (output_bfd, insn, contents + rel->r_offset - 2);
4282 r_type = R_PPC_TPREL16_HA;
4283 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
4289 && (tls_mask & TLS_TPREL) == 0)
4292 insn = bfd_get_32 (output_bfd, contents + rel->r_offset);
4293 if ((insn & ((31 << 26) | (31 << 11)))
4294 == ((31 << 26) | (2 << 11)))
4295 rtra = insn & ((1 << 26) - (1 << 16));
4296 else if ((insn & ((31 << 26) | (31 << 16)))
4297 == ((31 << 26) | (2 << 16)))
4298 rtra = (insn & (31 << 21)) | ((insn & (31 << 11)) << 5);
4301 if ((insn & ((1 << 11) - (1 << 1))) == 266 << 1)
4304 else if ((insn & (31 << 1)) == 23 << 1
4305 && ((insn & (31 << 6)) < 14 << 6
4306 || ((insn & (31 << 6)) >= 16 << 6
4307 && (insn & (31 << 6)) < 24 << 6)))
4308 /* load and store indexed -> dform. */
4309 insn = (32 | ((insn >> 6) & 31)) << 26;
4310 else if ((insn & (31 << 1)) == 21 << 1
4311 && (insn & (0x1a << 6)) == 0)
4312 /* ldx, ldux, stdx, stdux -> ld, ldu, std, stdu. */
4313 insn = (((58 | ((insn >> 6) & 4)) << 26)
4314 | ((insn >> 6) & 1));
4315 else if ((insn & (31 << 1)) == 21 << 1
4316 && (insn & ((1 << 11) - (1 << 1))) == 341 << 1)
4318 insn = (58 << 26) | 2;
4322 bfd_put_32 (output_bfd, insn, contents + rel->r_offset);
4323 r_type = R_PPC_TPREL16_LO;
4324 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
4325 /* Was PPC_TLS which sits on insn boundary, now
4326 PPC_TPREL16_LO which is at insn+2. */
4331 case R_PPC_GOT_TLSGD16_HI:
4332 case R_PPC_GOT_TLSGD16_HA:
4333 tls_gd = TLS_TPRELGD;
4334 if (tls_mask != 0 && (tls_mask & TLS_GD) == 0)
4338 case R_PPC_GOT_TLSLD16_HI:
4339 case R_PPC_GOT_TLSLD16_HA:
4340 if (tls_mask != 0 && (tls_mask & TLS_LD) == 0)
4343 if ((tls_mask & tls_gd) != 0)
4344 r_type = (((r_type - (R_PPC_GOT_TLSGD16 & 3)) & 3)
4345 + R_PPC_GOT_TPREL16);
4348 bfd_put_32 (output_bfd, NOP, contents + rel->r_offset);
4350 r_type = R_PPC_NONE;
4352 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
4356 case R_PPC_GOT_TLSGD16:
4357 case R_PPC_GOT_TLSGD16_LO:
4358 tls_gd = TLS_TPRELGD;
4359 if (tls_mask != 0 && (tls_mask & TLS_GD) == 0)
4360 goto tls_get_addr_check;
4363 case R_PPC_GOT_TLSLD16:
4364 case R_PPC_GOT_TLSLD16_LO:
4365 if (tls_mask != 0 && (tls_mask & TLS_LD) == 0)
4368 if (rel + 1 < relend)
4370 enum elf_ppc_reloc_type r_type2;
4371 unsigned long r_symndx2;
4372 struct elf_link_hash_entry *h2;
4373 bfd_vma insn1, insn2, insn3;
4376 /* The next instruction should be a call to
4377 __tls_get_addr. Peek at the reloc to be sure. */
4379 = (enum elf_ppc_reloc_type) ELF32_R_TYPE (rel[1].r_info);
4380 r_symndx2 = ELF32_R_SYM (rel[1].r_info);
4381 if (r_symndx2 < symtab_hdr->sh_info
4382 || (r_type2 != R_PPC_REL14
4383 && r_type2 != R_PPC_REL14_BRTAKEN
4384 && r_type2 != R_PPC_REL14_BRNTAKEN
4385 && r_type2 != R_PPC_REL24
4386 && r_type2 != R_PPC_PLTREL24))
4389 h2 = sym_hashes[r_symndx2 - symtab_hdr->sh_info];
4390 while (h2->root.type == bfd_link_hash_indirect
4391 || h2->root.type == bfd_link_hash_warning)
4392 h2 = (struct elf_link_hash_entry *) h2->root.u.i.link;
4393 if (h2 == NULL || h2 != htab->tls_get_addr)
4396 /* OK, it checks out. Replace the call. */
4397 offset = rel[1].r_offset;
4398 insn1 = bfd_get_32 (output_bfd,
4399 contents + rel->r_offset - 2);
4400 insn3 = bfd_get_32 (output_bfd,
4401 contents + offset + 4);
4402 if ((tls_mask & tls_gd) != 0)
4405 insn1 &= (1 << 26) - 1;
4406 insn1 |= 32 << 26; /* lwz */
4407 insn2 = 0x7c631214; /* add 3,3,2 */
4408 rel[1].r_info = ELF32_R_INFO (r_symndx2, R_PPC_NONE);
4409 r_type = (((r_type - (R_PPC_GOT_TLSGD16 & 3)) & 3)
4410 + R_PPC_GOT_TPREL16);
4411 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
4416 insn1 = 0x3c620000; /* addis 3,2,0 */
4417 insn2 = 0x38630000; /* addi 3,3,0 */
4420 /* Was an LD reloc. */
4422 rel->r_addend = htab->tls_sec->vma + DTP_OFFSET;
4423 rel[1].r_addend = htab->tls_sec->vma + DTP_OFFSET;
4425 r_type = R_PPC_TPREL16_HA;
4426 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
4427 rel[1].r_info = ELF32_R_INFO (r_symndx,
4429 rel[1].r_offset += 2;
4432 || insn3 == CROR_151515 || insn3 == CROR_313131)
4436 rel[1].r_offset += 4;
4438 bfd_put_32 (output_bfd, insn1, contents + rel->r_offset - 2);
4439 bfd_put_32 (output_bfd, insn2, contents + offset);
4440 bfd_put_32 (output_bfd, insn3, contents + offset + 4);
4443 /* We changed the symbol on an LD reloc. Start over
4444 in order to get h, sym, sec etc. right. */
4453 /* Handle other relocations that tweak non-addend part of insn. */
4460 /* Branch taken prediction relocations. */
4461 case R_PPC_ADDR14_BRTAKEN:
4462 case R_PPC_REL14_BRTAKEN:
4463 branch_bit = BRANCH_PREDICT_BIT;
4466 /* Branch not taken predicition relocations. */
4467 case R_PPC_ADDR14_BRNTAKEN:
4468 case R_PPC_REL14_BRNTAKEN:
4469 insn = bfd_get_32 (output_bfd, contents + rel->r_offset);
4470 insn &= ~BRANCH_PREDICT_BIT;
4473 from = (rel->r_offset
4474 + input_section->output_offset
4475 + input_section->output_section->vma);
4477 /* Invert 'y' bit if not the default. */
4478 if ((bfd_signed_vma) (relocation + rel->r_addend - from) < 0)
4479 insn ^= BRANCH_PREDICT_BIT;
4481 bfd_put_32 (output_bfd, insn, contents + rel->r_offset);
4485 addend = rel->r_addend;
4488 if ((unsigned) r_type < (unsigned) R_PPC_max)
4489 howto = ppc_elf_howto_table[(int) r_type];
4493 (*_bfd_error_handler)
4494 (_("%s: unknown relocation type %d for symbol %s"),
4495 bfd_archive_filename (input_bfd), (int) r_type, sym_name);
4497 bfd_set_error (bfd_error_bad_value);
4503 case R_PPC_EMB_MRKREF:
4504 case R_PPC_GNU_VTINHERIT:
4505 case R_PPC_GNU_VTENTRY:
4508 /* GOT16 relocations. Like an ADDR16 using the symbol's
4509 address in the GOT as relocation value instead of the
4510 symbol's value itself. Also, create a GOT entry for the
4511 symbol and put the symbol value there. */
4512 case R_PPC_GOT_TLSGD16:
4513 case R_PPC_GOT_TLSGD16_LO:
4514 case R_PPC_GOT_TLSGD16_HI:
4515 case R_PPC_GOT_TLSGD16_HA:
4516 tls_type = TLS_TLS | TLS_GD;
4519 case R_PPC_GOT_TLSLD16:
4520 case R_PPC_GOT_TLSLD16_LO:
4521 case R_PPC_GOT_TLSLD16_HI:
4522 case R_PPC_GOT_TLSLD16_HA:
4523 tls_type = TLS_TLS | TLS_LD;
4526 case R_PPC_GOT_TPREL16:
4527 case R_PPC_GOT_TPREL16_LO:
4528 case R_PPC_GOT_TPREL16_HI:
4529 case R_PPC_GOT_TPREL16_HA:
4530 tls_type = TLS_TLS | TLS_TPREL;
4533 case R_PPC_GOT_DTPREL16:
4534 case R_PPC_GOT_DTPREL16_LO:
4535 case R_PPC_GOT_DTPREL16_HI:
4536 case R_PPC_GOT_DTPREL16_HA:
4537 tls_type = TLS_TLS | TLS_DTPREL;
4541 case R_PPC_GOT16_LO:
4542 case R_PPC_GOT16_HI:
4543 case R_PPC_GOT16_HA:
4546 /* Relocation is to the entry for this symbol in the global
4552 if (htab->got == NULL)
4556 if (tls_type == (TLS_TLS | TLS_LD)
4557 && ((tls_mask & TLS_LD) == 0
4559 || !(h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC)))
4560 offp = &htab->tlsld_got.offset;
4564 dyn = htab->elf.dynamic_sections_created;
4565 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info, h)
4567 && SYMBOL_REFERENCES_LOCAL (info, h)))
4568 /* This is actually a static link, or it is a
4569 -Bsymbolic link and the symbol is defined
4570 locally, or the symbol was forced to be local
4571 because of a version file. */
4576 unresolved_reloc = FALSE;
4578 offp = &h->got.offset;
4582 if (local_got_offsets == NULL)
4584 offp = &local_got_offsets[r_symndx];
4587 /* The offset must always be a multiple of 4. We use the
4588 least significant bit to record whether we have already
4589 processed this entry. */
4597 /* Generate relocs for the dynamic linker, except in
4598 the case of TLSLD where we'll use one entry per
4600 if (info->shared || indx != 0)
4602 outrel.r_offset = (htab->got->output_section->vma
4603 + htab->got->output_offset
4605 if (tls_type & (TLS_LD | TLS_GD))
4607 outrel.r_info = ELF32_R_INFO (indx, R_PPC_DTPMOD32);
4608 outrel.r_addend = 0;
4609 if (tls_type == (TLS_TLS | TLS_GD))
4611 loc = htab->relgot->contents;
4612 loc += (htab->relgot->reloc_count++
4613 * sizeof (Elf32_External_Rela));
4614 bfd_elf32_swap_reloca_out (output_bfd,
4617 = ELF32_R_INFO (indx, R_PPC_DTPREL32);
4618 outrel.r_offset += 4;
4621 else if (tls_type == (TLS_TLS | TLS_DTPREL))
4622 outrel.r_info = ELF32_R_INFO (indx, R_PPC_DTPREL32);
4623 else if (tls_type == (TLS_TLS | TLS_TPREL))
4624 outrel.r_info = ELF32_R_INFO (indx, R_PPC_TPREL32);
4626 outrel.r_info = ELF32_R_INFO (indx, R_PPC_RELATIVE);
4628 outrel.r_info = ELF32_R_INFO (indx, R_PPC_GLOB_DAT);
4629 outrel.r_addend = 0;
4631 outrel.r_addend += relocation;
4632 loc = htab->relgot->contents;
4633 loc += (htab->relgot->reloc_count++
4634 * sizeof (Elf32_External_Rela));
4635 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
4638 /* Init the .got section contents if we're not
4639 emitting a reloc. */
4644 relocation -= htab->tls_sec->vma + DTP_OFFSET;
4645 if ((tls_type & TLS_TPREL) != 0)
4646 relocation += DTP_OFFSET - TP_OFFSET;
4649 if (tls_type == (TLS_TLS | TLS_GD))
4651 bfd_put_32 (output_bfd, relocation,
4652 htab->got->contents + off + 4);
4655 else if (tls_type == (TLS_TLS | TLS_LD))
4657 bfd_put_32 (output_bfd, relocation,
4658 htab->got->contents + off);
4662 if (off >= (bfd_vma) -2)
4665 relocation = htab->got->output_offset + off - 4;
4667 /* Addends on got relocations don't make much sense.
4668 x+off@got is actually x@got+off, and since the got is
4669 generated by a hash table traversal, the value in the
4670 got at entry m+n bears little relation to the entry m. */
4672 (*_bfd_error_handler)
4673 (_("%s(%s+0x%lx): non-zero addend on got reloc against `%s'"),
4674 bfd_archive_filename (input_bfd),
4675 bfd_get_section_name (input_bfd, input_section),
4676 (long) rel->r_offset,
4681 /* Relocations that need no special processing. */
4682 case R_PPC_LOCAL24PC:
4683 /* It makes no sense to point a local relocation
4684 at a symbol not in this object. */
4686 && (h->root.type == bfd_link_hash_defined
4687 || h->root.type == bfd_link_hash_defweak)
4688 && sec->output_section == NULL)
4690 if (! (*info->callbacks->undefined_symbol) (info,
4691 h->root.root.string,
4701 case R_PPC_DTPREL16:
4702 case R_PPC_DTPREL16_LO:
4703 case R_PPC_DTPREL16_HI:
4704 case R_PPC_DTPREL16_HA:
4705 addend -= htab->tls_sec->vma + DTP_OFFSET;
4708 /* Relocations that may need to be propagated if this is a shared
4711 case R_PPC_TPREL16_LO:
4712 case R_PPC_TPREL16_HI:
4713 case R_PPC_TPREL16_HA:
4714 addend -= htab->tls_sec->vma + TP_OFFSET;
4715 /* The TPREL16 relocs shouldn't really be used in shared
4716 libs as they will result in DT_TEXTREL being set, but
4717 support them anyway. */
4721 addend -= htab->tls_sec->vma + TP_OFFSET;
4724 case R_PPC_DTPREL32:
4725 addend -= htab->tls_sec->vma + DTP_OFFSET;
4731 case R_PPC_REL14_BRTAKEN:
4732 case R_PPC_REL14_BRNTAKEN:
4733 /* If these relocations are not to a named symbol, they can be
4734 handled right here, no need to bother the dynamic linker. */
4736 || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0
4737 || SYMBOL_REFERENCES_LOCAL (info, h))
4741 /* Relocations that always need to be propagated if this is a shared
4746 case R_PPC_ADDR16_LO:
4747 case R_PPC_ADDR16_HI:
4748 case R_PPC_ADDR16_HA:
4750 case R_PPC_ADDR14_BRTAKEN:
4751 case R_PPC_ADDR14_BRNTAKEN:
4754 case R_PPC_DTPMOD32:
4756 if (info->shared && r_symndx != 0)
4761 fprintf (stderr, "ppc_elf_relocate_section need to create relocation for %s\n",
4762 (h && h->root.root.string) ? h->root.root.string : "<unknown>");
4765 /* When generating a shared object, these relocations
4766 are copied into the output file to be resolved at run
4772 name = (bfd_elf_string_from_elf_section
4774 elf_elfheader (input_bfd)->e_shstrndx,
4775 elf_section_data (input_section)->rel_hdr.sh_name));
4779 BFD_ASSERT (strncmp (name, ".rela", 5) == 0
4780 && strcmp (bfd_get_section_name (input_bfd,
4784 sreloc = bfd_get_section_by_name (htab->elf.dynobj, name);
4785 BFD_ASSERT (sreloc != NULL);
4791 _bfd_elf_section_offset (output_bfd, info, input_section,
4793 if (outrel.r_offset == (bfd_vma) -1
4794 || outrel.r_offset == (bfd_vma) -2)
4795 skip = (int) outrel.r_offset;
4796 outrel.r_offset += (input_section->output_section->vma
4797 + input_section->output_offset);
4800 memset (&outrel, 0, sizeof outrel);
4801 /* h->dynindx may be -1 if this symbol was marked to
4803 else if (! will_become_local)
4805 unresolved_reloc = FALSE;
4806 outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
4807 outrel.r_addend = rel->r_addend;
4811 outrel.r_addend = relocation + rel->r_addend;
4813 if (r_type == R_PPC_ADDR32)
4814 outrel.r_info = ELF32_R_INFO (0, R_PPC_RELATIVE);
4820 sec = local_sections[r_symndx];
4823 BFD_ASSERT (h->root.type == bfd_link_hash_defined
4825 == bfd_link_hash_defweak));
4826 sec = h->root.u.def.section;
4829 if (bfd_is_abs_section (sec))
4831 else if (sec == NULL || sec->owner == NULL)
4833 bfd_set_error (bfd_error_bad_value);
4840 /* We are turning this relocation into one
4841 against a section symbol. It would be
4842 proper to subtract the symbol's value,
4843 osec->vma, from the emitted reloc addend,
4844 but ld.so expects buggy relocs. */
4845 osec = sec->output_section;
4846 indx = elf_section_data (osec)->dynindx;
4847 BFD_ASSERT (indx > 0);
4851 printf ("indx=%d section=%s flags=%08x name=%s\n",
4852 indx, osec->name, osec->flags,
4853 h->root.root.string);
4858 outrel.r_info = ELF32_R_INFO (indx, r_type);
4862 loc = sreloc->contents;
4863 loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rela);
4864 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
4869 /* This reloc will be computed at runtime. We clear the memory
4870 so that it contains predictable value. */
4872 && ((input_section->flags & SEC_ALLOC) != 0
4873 || ELF32_R_TYPE (outrel.r_info) != R_PPC_RELATIVE))
4875 relocation = howto->pc_relative ? outrel.r_offset : 0;
4882 /* Indirect .sdata relocation. */
4883 case R_PPC_EMB_SDAI16:
4884 BFD_ASSERT (htab->sdata != NULL);
4886 = bfd_elf32_finish_pointer_linker_section (output_bfd, input_bfd,
4887 info, htab->sdata, h,
4892 /* Indirect .sdata2 relocation. */
4893 case R_PPC_EMB_SDA2I16:
4894 BFD_ASSERT (htab->sdata2 != NULL);
4896 = bfd_elf32_finish_pointer_linker_section (output_bfd, input_bfd,
4897 info, htab->sdata2, h,
4902 /* Handle the TOC16 reloc. We want to use the offset within the .got
4903 section, not the actual VMA. This is appropriate when generating
4904 an embedded ELF object, for which the .got section acts like the
4905 AIX .toc section. */
4906 case R_PPC_TOC16: /* phony GOT16 relocations */
4907 BFD_ASSERT (sec != (asection *) 0);
4908 BFD_ASSERT (bfd_is_und_section (sec)
4909 || strcmp (bfd_get_section_name (abfd, sec), ".got") == 0
4910 || strcmp (bfd_get_section_name (abfd, sec), ".cgot") == 0)
4912 addend -= sec->output_section->vma + sec->output_offset + 0x8000;
4915 case R_PPC_PLTREL24:
4916 /* Relocation is to the entry for this symbol in the
4917 procedure linkage table. */
4918 BFD_ASSERT (h != NULL);
4920 if (h->plt.offset == (bfd_vma) -1
4921 || htab->plt == NULL)
4923 /* We didn't make a PLT entry for this symbol. This
4924 happens when statically linking PIC code, or when
4925 using -Bsymbolic. */
4929 unresolved_reloc = FALSE;
4930 relocation = (htab->plt->output_section->vma
4931 + htab->plt->output_offset
4935 /* Relocate against _SDA_BASE_. */
4936 case R_PPC_SDAREL16:
4939 const struct elf_link_hash_entry *sh;
4941 BFD_ASSERT (sec != (asection *) 0);
4942 name = bfd_get_section_name (abfd, sec->output_section);
4943 if (! ((strncmp (name, ".sdata", 6) == 0
4944 && (name[6] == 0 || name[6] == '.'))
4945 || (strncmp (name, ".sbss", 5) == 0
4946 && (name[5] == 0 || name[5] == '.'))))
4948 (*_bfd_error_handler) (_("%s: The target (%s) of a %s relocation is in the wrong output section (%s)"),
4949 bfd_archive_filename (input_bfd),
4954 sh = htab->sdata->sym_hash;
4955 addend -= (sh->root.u.def.value
4956 + sh->root.u.def.section->output_section->vma
4957 + sh->root.u.def.section->output_offset);
4961 /* Relocate against _SDA2_BASE_. */
4962 case R_PPC_EMB_SDA2REL:
4965 const struct elf_link_hash_entry *sh;
4967 BFD_ASSERT (sec != (asection *) 0);
4968 name = bfd_get_section_name (abfd, sec->output_section);
4969 if (! (strncmp (name, ".sdata2", 7) == 0
4970 || strncmp (name, ".sbss2", 6) == 0))
4972 (*_bfd_error_handler) (_("%s: The target (%s) of a %s relocation is in the wrong output section (%s)"),
4973 bfd_archive_filename (input_bfd),
4978 bfd_set_error (bfd_error_bad_value);
4982 sh = htab->sdata2->sym_hash;
4983 addend -= (sh->root.u.def.value
4984 + sh->root.u.def.section->output_section->vma
4985 + sh->root.u.def.section->output_offset);
4989 /* Relocate against either _SDA_BASE_, _SDA2_BASE_, or 0. */
4990 case R_PPC_EMB_SDA21:
4991 case R_PPC_EMB_RELSDA:
4994 const struct elf_link_hash_entry *sh;
4997 BFD_ASSERT (sec != (asection *) 0);
4998 name = bfd_get_section_name (abfd, sec->output_section);
4999 if (((strncmp (name, ".sdata", 6) == 0
5000 && (name[6] == 0 || name[6] == '.'))
5001 || (strncmp (name, ".sbss", 5) == 0
5002 && (name[5] == 0 || name[5] == '.'))))
5005 sh = htab->sdata->sym_hash;
5006 addend -= (sh->root.u.def.value
5007 + sh->root.u.def.section->output_section->vma
5008 + sh->root.u.def.section->output_offset);
5011 else if (strncmp (name, ".sdata2", 7) == 0
5012 || strncmp (name, ".sbss2", 6) == 0)
5015 sh = htab->sdata2->sym_hash;
5016 addend -= (sh->root.u.def.value
5017 + sh->root.u.def.section->output_section->vma
5018 + sh->root.u.def.section->output_offset);
5021 else if (strcmp (name, ".PPC.EMB.sdata0") == 0
5022 || strcmp (name, ".PPC.EMB.sbss0") == 0)
5029 (*_bfd_error_handler) (_("%s: The target (%s) of a %s relocation is in the wrong output section (%s)"),
5030 bfd_archive_filename (input_bfd),
5035 bfd_set_error (bfd_error_bad_value);
5040 if (r_type == R_PPC_EMB_SDA21)
5041 { /* fill in register field */
5042 insn = bfd_get_32 (output_bfd, contents + rel->r_offset);
5043 insn = (insn & ~RA_REGISTER_MASK) | (reg << RA_REGISTER_SHIFT);
5044 bfd_put_32 (output_bfd, insn, contents + rel->r_offset);
5049 /* Relocate against the beginning of the section. */
5051 case R_PPC_SECTOFF_LO:
5052 case R_PPC_SECTOFF_HI:
5053 case R_PPC_SECTOFF_HA:
5054 BFD_ASSERT (sec != (asection *) 0);
5055 addend -= sec->output_section->vma;
5058 /* Negative relocations. */
5059 case R_PPC_EMB_NADDR32:
5060 case R_PPC_EMB_NADDR16:
5061 case R_PPC_EMB_NADDR16_LO:
5062 case R_PPC_EMB_NADDR16_HI:
5063 case R_PPC_EMB_NADDR16_HA:
5064 addend -= 2 * relocation;
5068 case R_PPC_GLOB_DAT:
5069 case R_PPC_JMP_SLOT:
5070 case R_PPC_RELATIVE:
5072 case R_PPC_PLTREL32:
5073 case R_PPC_PLT16_LO:
5074 case R_PPC_PLT16_HI:
5075 case R_PPC_PLT16_HA:
5077 case R_PPC_EMB_RELSEC16:
5078 case R_PPC_EMB_RELST_LO:
5079 case R_PPC_EMB_RELST_HI:
5080 case R_PPC_EMB_RELST_HA:
5081 case R_PPC_EMB_BIT_FLD:
5082 (*_bfd_error_handler)
5083 (_("%s: Relocation %s is not yet supported for symbol %s."),
5084 bfd_archive_filename (input_bfd),
5088 bfd_set_error (bfd_error_invalid_operation);
5093 /* Do any further special processing. */
5099 case R_PPC_ADDR16_HA:
5100 case R_PPC_GOT16_HA:
5101 case R_PPC_PLT16_HA:
5102 case R_PPC_SECTOFF_HA:
5103 case R_PPC_TPREL16_HA:
5104 case R_PPC_DTPREL16_HA:
5105 case R_PPC_GOT_TLSGD16_HA:
5106 case R_PPC_GOT_TLSLD16_HA:
5107 case R_PPC_GOT_TPREL16_HA:
5108 case R_PPC_GOT_DTPREL16_HA:
5109 case R_PPC_EMB_NADDR16_HA:
5110 case R_PPC_EMB_RELST_HA:
5111 /* It's just possible that this symbol is a weak symbol
5112 that's not actually defined anywhere. In that case,
5113 'sec' would be NULL, and we should leave the symbol
5114 alone (it will be set to zero elsewhere in the link). */
5116 /* Add 0x10000 if sign bit in 0:15 is set. */
5117 addend += ((relocation + addend) & 0x8000) << 1;
5122 fprintf (stderr, "\ttype = %s (%d), name = %s, symbol index = %ld, offset = %ld, addend = %ld\n",
5127 (long) rel->r_offset,
5131 if (unresolved_reloc
5132 && !((input_section->flags & SEC_DEBUGGING) != 0
5133 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0))
5135 (*_bfd_error_handler)
5136 (_("%s(%s+0x%lx): unresolvable relocation against symbol `%s'"),
5137 bfd_archive_filename (input_bfd),
5138 bfd_get_section_name (input_bfd, input_section),
5139 (long) rel->r_offset,
5144 r = _bfd_final_link_relocate (howto,
5152 if (r != bfd_reloc_ok)
5154 if (sym_name == NULL)
5155 sym_name = "(null)";
5156 if (r == bfd_reloc_overflow)
5161 && h->root.type == bfd_link_hash_undefweak
5162 && howto->pc_relative)
5164 /* Assume this is a call protected by other code that
5165 detect the symbol is undefined. If this is the case,
5166 we can safely ignore the overflow. If not, the
5167 program is hosed anyway, and a little warning isn't
5173 if (! (*info->callbacks->reloc_overflow) (info,
5184 (*_bfd_error_handler)
5185 (_("%s(%s+0x%lx): reloc against `%s': error %d"),
5186 bfd_archive_filename (input_bfd),
5187 bfd_get_section_name (input_bfd, input_section),
5188 (long) rel->r_offset, sym_name, (int) r);
5195 fprintf (stderr, "\n");
5201 static enum elf_reloc_type_class
5202 ppc_elf_reloc_type_class (rela)
5203 const Elf_Internal_Rela *rela;
5205 switch ((int) ELF32_R_TYPE (rela->r_info))
5207 case R_PPC_RELATIVE:
5208 return reloc_class_relative;
5211 case R_PPC_JMP_SLOT:
5212 return reloc_class_plt;
5214 return reloc_class_copy;
5216 return reloc_class_normal;
5220 /* Support for core dump NOTE sections. */
5223 ppc_elf_grok_prstatus (abfd, note)
5225 Elf_Internal_Note *note;
5228 unsigned int raw_size;
5230 switch (note->descsz)
5235 case 268: /* Linux/PPC. */
5237 elf_tdata (abfd)->core_signal = bfd_get_16 (abfd, note->descdata + 12);
5240 elf_tdata (abfd)->core_pid = bfd_get_32 (abfd, note->descdata + 24);
5249 /* Make a ".reg/999" section. */
5250 return _bfd_elfcore_make_pseudosection (abfd, ".reg",
5251 raw_size, note->descpos + offset);
5255 ppc_elf_grok_psinfo (abfd, note)
5257 Elf_Internal_Note *note;
5259 switch (note->descsz)
5264 case 128: /* Linux/PPC elf_prpsinfo. */
5265 elf_tdata (abfd)->core_program
5266 = _bfd_elfcore_strndup (abfd, note->descdata + 32, 16);
5267 elf_tdata (abfd)->core_command
5268 = _bfd_elfcore_strndup (abfd, note->descdata + 48, 80);
5271 /* Note that for some reason, a spurious space is tacked
5272 onto the end of the args in some (at least one anyway)
5273 implementations, so strip it off if it exists. */
5276 char *command = elf_tdata (abfd)->core_command;
5277 int n = strlen (command);
5279 if (0 < n && command[n - 1] == ' ')
5280 command[n - 1] = '\0';
5286 /* Very simple linked list structure for recording apuinfo values. */
5287 typedef struct apuinfo_list
5289 struct apuinfo_list * next;
5290 unsigned long value;
5294 static apuinfo_list * head;
5296 static void apuinfo_list_init PARAMS ((void));
5297 static void apuinfo_list_add PARAMS ((unsigned long));
5298 static unsigned apuinfo_list_length PARAMS ((void));
5299 static unsigned long apuinfo_list_element PARAMS ((unsigned long));
5300 static void apuinfo_list_finish PARAMS ((void));
5302 extern void ppc_elf_begin_write_processing
5303 PARAMS ((bfd *, struct bfd_link_info *));
5304 extern void ppc_elf_final_write_processing
5305 PARAMS ((bfd *, bfd_boolean));
5306 extern bfd_boolean ppc_elf_write_section
5307 PARAMS ((bfd *, asection *, bfd_byte *));
5312 apuinfo_list_init PARAMS ((void))
5318 apuinfo_list_add (value)
5319 unsigned long value;
5321 apuinfo_list * entry = head;
5323 while (entry != NULL)
5325 if (entry->value == value)
5327 entry = entry->next;
5330 entry = bfd_malloc (sizeof (* entry));
5334 entry->value = value;
5340 apuinfo_list_length PARAMS ((void))
5342 apuinfo_list * entry;
5343 unsigned long count;
5345 for (entry = head, count = 0;
5347 entry = entry->next)
5353 static inline unsigned long
5354 apuinfo_list_element (number)
5355 unsigned long number;
5357 apuinfo_list * entry;
5361 entry = entry->next)
5364 return entry ? entry->value : 0;
5368 apuinfo_list_finish PARAMS ((void))
5370 apuinfo_list * entry;
5372 for (entry = head; entry;)
5374 apuinfo_list * next = entry->next;
5382 #define APUINFO_SECTION_NAME ".PPC.EMB.apuinfo"
5383 #define APUINFO_LABEL "APUinfo"
5385 /* Scan the input BFDs and create a linked list of
5386 the APUinfo values that will need to be emitted. */
5389 ppc_elf_begin_write_processing (abfd, link_info)
5391 struct bfd_link_info *link_info;
5396 unsigned num_input_sections;
5397 bfd_size_type output_section_size;
5399 unsigned num_entries;
5400 unsigned long offset;
5401 unsigned long length;
5402 const char * error_message = NULL;
5404 if (link_info == NULL)
5407 /* Scan the input bfds, looking for apuinfo sections. */
5408 num_input_sections = 0;
5409 output_section_size = 0;
5411 for (ibfd = link_info->input_bfds; ibfd; ibfd = ibfd->link_next)
5413 asec = bfd_get_section_by_name (ibfd, APUINFO_SECTION_NAME);
5416 ++ num_input_sections;
5417 output_section_size += asec->_raw_size;
5421 /* We need at least one input sections
5422 in order to make merging worthwhile. */
5423 if (num_input_sections < 1)
5426 /* Just make sure that the output section exists as well. */
5427 asec = bfd_get_section_by_name (abfd, APUINFO_SECTION_NAME);
5431 /* Allocate a buffer for the contents of the input sections. */
5432 buffer = bfd_malloc (output_section_size);
5437 apuinfo_list_init ();
5439 /* Read in the input sections contents. */
5440 for (ibfd = link_info->input_bfds; ibfd; ibfd = ibfd->link_next)
5442 unsigned long datum;
5446 asec = bfd_get_section_by_name (ibfd, APUINFO_SECTION_NAME);
5450 length = asec->_raw_size;
5453 error_message = _("corrupt or empty %s section in %s");
5457 if (bfd_seek (ibfd, asec->filepos, SEEK_SET) != 0
5458 || (bfd_bread (buffer + offset, length, ibfd) != length))
5460 error_message = _("unable to read in %s section from %s");
5464 /* Process the contents of the section. */
5465 ptr = buffer + offset;
5466 error_message = _("corrupt %s section in %s");
5468 /* Verify the contents of the header. Note - we have to
5469 extract the values this way in order to allow for a
5470 host whose endian-ness is different from the target. */
5471 datum = bfd_get_32 (ibfd, ptr);
5472 if (datum != sizeof APUINFO_LABEL)
5475 datum = bfd_get_32 (ibfd, ptr + 8);
5479 if (strcmp (ptr + 12, APUINFO_LABEL) != 0)
5482 /* Get the number of apuinfo entries. */
5483 datum = bfd_get_32 (ibfd, ptr + 4);
5484 if ((datum * 4 + 20) != length)
5487 /* Make sure that we do not run off the end of the section. */
5488 if (offset + length > output_section_size)
5491 /* Scan the apuinfo section, building a list of apuinfo numbers. */
5492 for (i = 0; i < datum; i++)
5493 apuinfo_list_add (bfd_get_32 (ibfd, ptr + 20 + (i * 4)));
5495 /* Update the offset. */
5499 error_message = NULL;
5501 /* Compute the size of the output section. */
5502 num_entries = apuinfo_list_length ();
5503 output_section_size = 20 + num_entries * 4;
5505 asec = bfd_get_section_by_name (abfd, APUINFO_SECTION_NAME);
5507 if (! bfd_set_section_size (abfd, asec, output_section_size))
5509 error_message = _("warning: unable to set size of %s section in %s");
5515 _bfd_error_handler (error_message, APUINFO_SECTION_NAME,
5516 bfd_archive_filename (ibfd));
5520 /* Prevent the output section from accumulating the input sections'
5521 contents. We have already stored this in our linked list structure. */
5524 ppc_elf_write_section (abfd, asec, contents)
5525 bfd * abfd ATTRIBUTE_UNUSED;
5527 bfd_byte * contents ATTRIBUTE_UNUSED;
5529 return apuinfo_list_length () && strcmp (asec->name, APUINFO_SECTION_NAME) == 0;
5533 /* Finally we can generate the output section. */
5536 ppc_elf_final_write_processing (abfd, linker)
5538 bfd_boolean linker ATTRIBUTE_UNUSED;
5543 unsigned num_entries;
5544 bfd_size_type length;
5546 asec = bfd_get_section_by_name (abfd, APUINFO_SECTION_NAME);
5550 if (apuinfo_list_length () == 0)
5553 length = asec->_raw_size;
5557 buffer = bfd_malloc (length);
5560 _bfd_error_handler (_("failed to allocate space for new APUinfo section."));
5564 /* Create the apuinfo header. */
5565 num_entries = apuinfo_list_length ();
5566 bfd_put_32 (abfd, sizeof APUINFO_LABEL, buffer);
5567 bfd_put_32 (abfd, num_entries, buffer + 4);
5568 bfd_put_32 (abfd, 0x2, buffer + 8);
5569 strcpy (buffer + 12, APUINFO_LABEL);
5572 for (i = 0; i < num_entries; i++)
5574 bfd_put_32 (abfd, apuinfo_list_element (i), buffer + length);
5578 if (length != asec->_raw_size)
5579 _bfd_error_handler (_("failed to compute new APUinfo section."));
5581 if (! bfd_set_section_contents (abfd, asec, buffer, (file_ptr) 0, length))
5582 _bfd_error_handler (_("failed to install new APUinfo section."));
5586 apuinfo_list_finish ();
5589 #define TARGET_LITTLE_SYM bfd_elf32_powerpcle_vec
5590 #define TARGET_LITTLE_NAME "elf32-powerpcle"
5591 #define TARGET_BIG_SYM bfd_elf32_powerpc_vec
5592 #define TARGET_BIG_NAME "elf32-powerpc"
5593 #define ELF_ARCH bfd_arch_powerpc
5594 #define ELF_MACHINE_CODE EM_PPC
5595 #define ELF_MAXPAGESIZE 0x10000
5596 #define elf_info_to_howto ppc_elf_info_to_howto
5598 #ifdef EM_CYGNUS_POWERPC
5599 #define ELF_MACHINE_ALT1 EM_CYGNUS_POWERPC
5603 #define ELF_MACHINE_ALT2 EM_PPC_OLD
5606 #define elf_backend_plt_not_loaded 1
5607 #define elf_backend_got_symbol_offset 4
5608 #define elf_backend_can_gc_sections 1
5609 #define elf_backend_can_refcount 1
5610 #define elf_backend_got_header_size 12
5611 #define elf_backend_plt_header_size PLT_INITIAL_ENTRY_SIZE
5612 #define elf_backend_rela_normal 1
5614 #define bfd_elf32_bfd_merge_private_bfd_data ppc_elf_merge_private_bfd_data
5615 #define bfd_elf32_bfd_relax_section ppc_elf_relax_section
5616 #define bfd_elf32_bfd_reloc_type_lookup ppc_elf_reloc_type_lookup
5617 #define bfd_elf32_bfd_set_private_flags ppc_elf_set_private_flags
5618 #define bfd_elf32_bfd_link_hash_table_create ppc_elf_link_hash_table_create
5620 #define elf_backend_object_p ppc_elf_object_p
5621 #define elf_backend_gc_mark_hook ppc_elf_gc_mark_hook
5622 #define elf_backend_gc_sweep_hook ppc_elf_gc_sweep_hook
5623 #define elf_backend_section_from_shdr ppc_elf_section_from_shdr
5624 #define elf_backend_relocate_section ppc_elf_relocate_section
5625 #define elf_backend_create_dynamic_sections ppc_elf_create_dynamic_sections
5626 #define elf_backend_check_relocs ppc_elf_check_relocs
5627 #define elf_backend_copy_indirect_symbol ppc_elf_copy_indirect_symbol
5628 #define elf_backend_adjust_dynamic_symbol ppc_elf_adjust_dynamic_symbol
5629 #define elf_backend_add_symbol_hook ppc_elf_add_symbol_hook
5630 #define elf_backend_size_dynamic_sections ppc_elf_size_dynamic_sections
5631 #define elf_backend_finish_dynamic_symbol ppc_elf_finish_dynamic_symbol
5632 #define elf_backend_finish_dynamic_sections ppc_elf_finish_dynamic_sections
5633 #define elf_backend_fake_sections ppc_elf_fake_sections
5634 #define elf_backend_additional_program_headers ppc_elf_additional_program_headers
5635 #define elf_backend_modify_segment_map ppc_elf_modify_segment_map
5636 #define elf_backend_grok_prstatus ppc_elf_grok_prstatus
5637 #define elf_backend_grok_psinfo ppc_elf_grok_psinfo
5638 #define elf_backend_reloc_type_class ppc_elf_reloc_type_class
5639 #define elf_backend_begin_write_processing ppc_elf_begin_write_processing
5640 #define elf_backend_final_write_processing ppc_elf_final_write_processing
5641 #define elf_backend_write_section ppc_elf_write_section
5643 #include "elf32-target.h"