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
20 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
23 /* This file is based on a preliminary PowerPC ELF ABI. The
24 information may not match the final PowerPC ELF ABI. It includes
25 suggestions from the in-progress Embedded PowerPC ABI, and that
26 information may also not match. */
34 #include "elf32-ppc.h"
36 /* RELA relocations are used here. */
38 static struct bfd_hash_entry
*ppc_elf_link_hash_newfunc
39 PARAMS ((struct bfd_hash_entry
*entry
, struct bfd_hash_table
*table
,
41 static struct bfd_link_hash_table
*ppc_elf_link_hash_table_create
43 static void ppc_elf_copy_indirect_symbol
44 PARAMS ((struct elf_backend_data
*bed
, struct elf_link_hash_entry
*dir
,
45 struct elf_link_hash_entry
*ind
));
46 static reloc_howto_type
*ppc_elf_reloc_type_lookup
47 PARAMS ((bfd
*abfd
, bfd_reloc_code_real_type code
));
48 static void ppc_elf_info_to_howto
49 PARAMS ((bfd
*abfd
, arelent
*cache_ptr
, Elf_Internal_Rela
*dst
));
50 static void ppc_elf_howto_init
52 static int ppc_elf_sort_rela
53 PARAMS ((const PTR
, const PTR
));
54 static bfd_boolean ppc_elf_relax_section
55 PARAMS ((bfd
*, asection
*, struct bfd_link_info
*, bfd_boolean
*));
56 static bfd_reloc_status_type ppc_elf_addr16_ha_reloc
57 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
58 static bfd_reloc_status_type ppc_elf_unhandled_reloc
59 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
60 static bfd_boolean ppc_elf_object_p
62 static bfd_boolean ppc_elf_set_private_flags
63 PARAMS ((bfd
*, flagword
));
64 static bfd_boolean ppc_elf_merge_private_bfd_data
65 PARAMS ((bfd
*, bfd
*));
66 static int ppc_elf_additional_program_headers
68 static bfd_boolean ppc_elf_modify_segment_map
70 static bfd_boolean ppc_elf_create_got
71 PARAMS ((bfd
*, struct bfd_link_info
*));
72 static bfd_boolean ppc_elf_create_dynamic_sections
73 PARAMS ((bfd
*, struct bfd_link_info
*));
74 static bfd_boolean ppc_elf_section_from_shdr
75 PARAMS ((bfd
*, Elf_Internal_Shdr
*, const char *));
76 static bfd_boolean ppc_elf_fake_sections
77 PARAMS ((bfd
*, Elf_Internal_Shdr
*, asection
*));
78 static elf_linker_section_t
*ppc_elf_create_linker_section
79 PARAMS ((bfd
*abfd
, struct bfd_link_info
*info
,
80 enum elf_linker_section_enum
));
81 static bfd_boolean update_local_sym_info
82 PARAMS ((bfd
*, Elf_Internal_Shdr
*, unsigned long, int));
83 static void bad_shared_reloc
84 PARAMS ((bfd
*, enum elf_ppc_reloc_type
));
85 static bfd_boolean ppc_elf_check_relocs
86 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
87 const Elf_Internal_Rela
*));
88 static asection
*ppc_elf_gc_mark_hook
89 PARAMS ((asection
*sec
, struct bfd_link_info
*info
, Elf_Internal_Rela
*rel
,
90 struct elf_link_hash_entry
*h
, Elf_Internal_Sym
*sym
));
91 static bfd_boolean ppc_elf_gc_sweep_hook
92 PARAMS ((bfd
*abfd
, struct bfd_link_info
*info
, asection
*sec
,
93 const Elf_Internal_Rela
*relocs
));
94 static bfd_boolean ppc_elf_adjust_dynamic_symbol
95 PARAMS ((struct bfd_link_info
*, struct elf_link_hash_entry
*));
96 static bfd_boolean allocate_dynrelocs
97 PARAMS ((struct elf_link_hash_entry
*, PTR
));
98 static bfd_boolean readonly_dynrelocs
99 PARAMS ((struct elf_link_hash_entry
*, PTR
));
100 static bfd_boolean ppc_elf_size_dynamic_sections
101 PARAMS ((bfd
*, struct bfd_link_info
*));
102 static bfd_boolean ppc_elf_relocate_section
103 PARAMS ((bfd
*, struct bfd_link_info
*info
, bfd
*, asection
*, bfd_byte
*,
104 Elf_Internal_Rela
*relocs
, Elf_Internal_Sym
*local_syms
,
106 static bfd_boolean ppc_elf_add_symbol_hook
107 PARAMS ((bfd
*, struct bfd_link_info
*, const Elf_Internal_Sym
*,
108 const char **, flagword
*, asection
**, bfd_vma
*));
109 static bfd_boolean ppc_elf_finish_dynamic_symbol
110 PARAMS ((bfd
*, struct bfd_link_info
*, struct elf_link_hash_entry
*,
111 Elf_Internal_Sym
*));
112 static bfd_boolean ppc_elf_finish_dynamic_sections
113 PARAMS ((bfd
*, struct bfd_link_info
*));
114 static enum elf_reloc_type_class ppc_elf_reloc_type_class
115 PARAMS ((const Elf_Internal_Rela
*));
116 static bfd_boolean ppc_elf_grok_prstatus
117 PARAMS ((bfd
*abfd
, Elf_Internal_Note
*note
));
118 static bfd_boolean ppc_elf_grok_psinfo
119 PARAMS ((bfd
*abfd
, Elf_Internal_Note
*note
));
121 /* Branch prediction bit for branch taken relocs. */
122 #define BRANCH_PREDICT_BIT 0x200000
123 /* Mask to set RA in memory instructions. */
124 #define RA_REGISTER_MASK 0x001f0000
125 /* Value to shift register by to insert RA. */
126 #define RA_REGISTER_SHIFT 16
128 /* The name of the dynamic interpreter. This is put in the .interp
130 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
132 /* The size in bytes of an entry in the procedure linkage table. */
133 #define PLT_ENTRY_SIZE 12
134 /* The initial size of the plt reserved for the dynamic linker. */
135 #define PLT_INITIAL_ENTRY_SIZE 72
136 /* The size of the gap between entries in the PLT. */
137 #define PLT_SLOT_SIZE 8
138 /* The number of single-slot PLT entries (the rest use two slots). */
139 #define PLT_NUM_SINGLE_ENTRIES 8192
141 /* Some nop instructions. */
142 #define NOP 0x60000000
143 #define CROR_151515 0x4def7b82
144 #define CROR_313131 0x4ffffb82
146 /* Offset of tp and dtp pointers from start of TLS block. */
147 #define TP_OFFSET 0x7000
148 #define DTP_OFFSET 0x8000
150 /* Will references to this symbol always reference the symbol
151 in this object? STV_PROTECTED is excluded from the visibility test
152 here so that function pointer comparisons work properly. Since
153 function symbols not defined in an app are set to their .plt entry,
154 it's necessary for shared libs to also reference the .plt even
155 though the symbol is really local to the shared lib. */
156 #define SYMBOL_REFERENCES_LOCAL(INFO, H) \
159 || H->dynindx == -1 \
160 || ELF_ST_VISIBILITY (H->other) == STV_INTERNAL \
161 || ELF_ST_VISIBILITY (H->other) == STV_HIDDEN) \
162 && (H->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) != 0)
164 /* Will _calls_ to this symbol always call the version in this object? */
165 #define SYMBOL_CALLS_LOCAL(INFO, H) \
168 || H->dynindx == -1 \
169 || ELF_ST_VISIBILITY (H->other) != STV_DEFAULT) \
170 && (H->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) != 0)
172 /* The PPC linker needs to keep track of the number of relocs that it
173 decides to copy as dynamic relocs in check_relocs for each symbol.
174 This is so that it can later discard them if they are found to be
175 unnecessary. We store the information in a field extending the
176 regular ELF linker hash table. */
178 struct ppc_elf_dyn_relocs
180 struct ppc_elf_dyn_relocs
*next
;
182 /* The input section of the reloc. */
185 /* Total number of relocs copied for the input section. */
188 /* Number of pc-relative relocs copied for the input section. */
189 bfd_size_type pc_count
;
192 /* PPC ELF linker hash entry. */
194 struct ppc_elf_link_hash_entry
196 struct elf_link_hash_entry elf
;
198 /* Track dynamic relocs copied for this symbol. */
199 struct ppc_elf_dyn_relocs
*dyn_relocs
;
201 /* Contexts in which symbol is used in the GOT (or TOC).
202 TLS_GD .. TLS_TLS bits are or'd into the mask as the
203 corresponding relocs are encountered during check_relocs.
204 tls_optimize clears TLS_GD .. TLS_TPREL when optimizing to
205 indicate the corresponding GOT entry type is not needed. */
206 #define TLS_GD 1 /* GD reloc. */
207 #define TLS_LD 2 /* LD reloc. */
208 #define TLS_TPREL 4 /* TPREL reloc, => IE. */
209 #define TLS_DTPREL 8 /* DTPREL reloc, => LD. */
210 #define TLS_TLS 16 /* Any TLS reloc. */
211 #define TLS_TPRELGD 32 /* TPREL reloc resulting from GD->IE. */
215 #define ppc_elf_hash_entry(ent) ((struct ppc_elf_link_hash_entry *) (ent))
217 /* PPC ELF linker hash table. */
219 struct ppc_elf_link_hash_table
221 struct elf_link_hash_table elf
;
223 /* Short-cuts to get to dynamic linker sections. */
232 elf_linker_section_t
*sdata
;
233 elf_linker_section_t
*sdata2
;
235 /* Short-cut to first output tls section. */
238 /* Shortcut to .__tls_get_addr. */
239 struct elf_link_hash_entry
*tls_get_addr
;
241 /* TLS local dynamic got entry handling. */
243 bfd_signed_vma refcount
;
247 /* Small local sym to section mapping cache. */
248 struct sym_sec_cache sym_sec
;
251 /* Get the PPC ELF linker hash table from a link_info structure. */
253 #define ppc_elf_hash_table(p) \
254 ((struct ppc_elf_link_hash_table *) (p)->hash)
256 /* Create an entry in a PPC ELF linker hash table. */
258 static struct bfd_hash_entry
*
259 ppc_elf_link_hash_newfunc (entry
, table
, string
)
260 struct bfd_hash_entry
*entry
;
261 struct bfd_hash_table
*table
;
264 /* Allocate the structure if it has not already been allocated by a
268 entry
= bfd_hash_allocate (table
,
269 sizeof (struct ppc_elf_link_hash_entry
));
274 /* Call the allocation method of the superclass. */
275 entry
= _bfd_elf_link_hash_newfunc (entry
, table
, string
);
278 ppc_elf_hash_entry (entry
)->dyn_relocs
= NULL
;
279 ppc_elf_hash_entry (entry
)->tls_mask
= 0;
285 /* Create a PPC ELF linker hash table. */
287 static struct bfd_link_hash_table
*
288 ppc_elf_link_hash_table_create (abfd
)
291 struct ppc_elf_link_hash_table
*ret
;
293 ret
= ((struct ppc_elf_link_hash_table
*)
294 bfd_malloc (sizeof (struct ppc_elf_link_hash_table
)));
298 if (! _bfd_elf_link_hash_table_init (&ret
->elf
, abfd
,
299 ppc_elf_link_hash_newfunc
))
316 ret
->tls_get_addr
= NULL
;
317 ret
->tlsld_got
.refcount
= 0;
318 ret
->sym_sec
.abfd
= NULL
;
320 return &ret
->elf
.root
;
323 /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
324 copying dynamic variables from a shared lib into an app's dynbss
325 section, and instead use a dynamic relocation to point into the
327 #define ELIMINATE_COPY_RELOCS 1
329 /* Copy the extra info we tack onto an elf_link_hash_entry. */
332 ppc_elf_copy_indirect_symbol (bed
, dir
, ind
)
333 struct elf_backend_data
*bed
;
334 struct elf_link_hash_entry
*dir
, *ind
;
336 struct ppc_elf_link_hash_entry
*edir
, *eind
;
338 edir
= (struct ppc_elf_link_hash_entry
*) dir
;
339 eind
= (struct ppc_elf_link_hash_entry
*) ind
;
341 if (eind
->dyn_relocs
!= NULL
)
343 if (edir
->dyn_relocs
!= NULL
)
345 struct ppc_elf_dyn_relocs
**pp
;
346 struct ppc_elf_dyn_relocs
*p
;
348 if (ind
->root
.type
== bfd_link_hash_indirect
)
351 /* Add reloc counts against the weak sym to the strong sym
352 list. Merge any entries against the same section. */
353 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
; )
355 struct ppc_elf_dyn_relocs
*q
;
357 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
358 if (q
->sec
== p
->sec
)
360 q
->pc_count
+= p
->pc_count
;
361 q
->count
+= p
->count
;
368 *pp
= edir
->dyn_relocs
;
371 edir
->dyn_relocs
= eind
->dyn_relocs
;
372 eind
->dyn_relocs
= NULL
;
375 edir
->tls_mask
|= eind
->tls_mask
;
377 if (ELIMINATE_COPY_RELOCS
&& ind
->root
.type
!= bfd_link_hash_indirect
)
378 /* If called to transfer flags for a weakdef during processing
379 of elf_adjust_dynamic_symbol, don't copy ELF_LINK_NON_GOT_REF.
380 We clear it ourselves for ELIMINATE_COPY_RELOCS. */
381 dir
->elf_link_hash_flags
|=
382 (ind
->elf_link_hash_flags
& (ELF_LINK_HASH_REF_DYNAMIC
383 | ELF_LINK_HASH_REF_REGULAR
384 | ELF_LINK_HASH_REF_REGULAR_NONWEAK
));
386 _bfd_elf_link_hash_copy_indirect (bed
, dir
, ind
);
389 static reloc_howto_type
*ppc_elf_howto_table
[(int) R_PPC_max
];
391 static reloc_howto_type ppc_elf_howto_raw
[] = {
392 /* This reloc does nothing. */
393 HOWTO (R_PPC_NONE
, /* type */
395 2, /* size (0 = byte, 1 = short, 2 = long) */
397 FALSE
, /* pc_relative */
399 complain_overflow_bitfield
, /* complain_on_overflow */
400 bfd_elf_generic_reloc
, /* special_function */
401 "R_PPC_NONE", /* name */
402 FALSE
, /* partial_inplace */
405 FALSE
), /* pcrel_offset */
407 /* A standard 32 bit relocation. */
408 HOWTO (R_PPC_ADDR32
, /* type */
410 2, /* size (0 = byte, 1 = short, 2 = long) */
412 FALSE
, /* pc_relative */
414 complain_overflow_bitfield
, /* complain_on_overflow */
415 bfd_elf_generic_reloc
, /* special_function */
416 "R_PPC_ADDR32", /* name */
417 FALSE
, /* partial_inplace */
419 0xffffffff, /* dst_mask */
420 FALSE
), /* pcrel_offset */
422 /* An absolute 26 bit branch; the lower two bits must be zero.
423 FIXME: we don't check that, we just clear them. */
424 HOWTO (R_PPC_ADDR24
, /* type */
426 2, /* size (0 = byte, 1 = short, 2 = long) */
428 FALSE
, /* pc_relative */
430 complain_overflow_bitfield
, /* complain_on_overflow */
431 bfd_elf_generic_reloc
, /* special_function */
432 "R_PPC_ADDR24", /* name */
433 FALSE
, /* partial_inplace */
435 0x3fffffc, /* dst_mask */
436 FALSE
), /* pcrel_offset */
438 /* A standard 16 bit relocation. */
439 HOWTO (R_PPC_ADDR16
, /* type */
441 1, /* size (0 = byte, 1 = short, 2 = long) */
443 FALSE
, /* pc_relative */
445 complain_overflow_bitfield
, /* complain_on_overflow */
446 bfd_elf_generic_reloc
, /* special_function */
447 "R_PPC_ADDR16", /* name */
448 FALSE
, /* partial_inplace */
450 0xffff, /* dst_mask */
451 FALSE
), /* pcrel_offset */
453 /* A 16 bit relocation without overflow. */
454 HOWTO (R_PPC_ADDR16_LO
, /* type */
456 1, /* size (0 = byte, 1 = short, 2 = long) */
458 FALSE
, /* pc_relative */
460 complain_overflow_dont
,/* complain_on_overflow */
461 bfd_elf_generic_reloc
, /* special_function */
462 "R_PPC_ADDR16_LO", /* name */
463 FALSE
, /* partial_inplace */
465 0xffff, /* dst_mask */
466 FALSE
), /* pcrel_offset */
468 /* The high order 16 bits of an address. */
469 HOWTO (R_PPC_ADDR16_HI
, /* type */
471 1, /* size (0 = byte, 1 = short, 2 = long) */
473 FALSE
, /* pc_relative */
475 complain_overflow_dont
, /* complain_on_overflow */
476 bfd_elf_generic_reloc
, /* special_function */
477 "R_PPC_ADDR16_HI", /* name */
478 FALSE
, /* partial_inplace */
480 0xffff, /* dst_mask */
481 FALSE
), /* pcrel_offset */
483 /* The high order 16 bits of an address, plus 1 if the contents of
484 the low 16 bits, treated as a signed number, is negative. */
485 HOWTO (R_PPC_ADDR16_HA
, /* type */
487 1, /* size (0 = byte, 1 = short, 2 = long) */
489 FALSE
, /* pc_relative */
491 complain_overflow_dont
, /* complain_on_overflow */
492 ppc_elf_addr16_ha_reloc
, /* special_function */
493 "R_PPC_ADDR16_HA", /* name */
494 FALSE
, /* partial_inplace */
496 0xffff, /* dst_mask */
497 FALSE
), /* pcrel_offset */
499 /* An absolute 16 bit branch; the lower two bits must be zero.
500 FIXME: we don't check that, we just clear them. */
501 HOWTO (R_PPC_ADDR14
, /* type */
503 2, /* size (0 = byte, 1 = short, 2 = long) */
505 FALSE
, /* pc_relative */
507 complain_overflow_bitfield
, /* complain_on_overflow */
508 bfd_elf_generic_reloc
, /* special_function */
509 "R_PPC_ADDR14", /* name */
510 FALSE
, /* partial_inplace */
512 0xfffc, /* dst_mask */
513 FALSE
), /* pcrel_offset */
515 /* An absolute 16 bit branch, for which bit 10 should be set to
516 indicate that the branch is expected to be taken. The lower two
517 bits must be zero. */
518 HOWTO (R_PPC_ADDR14_BRTAKEN
, /* type */
520 2, /* size (0 = byte, 1 = short, 2 = long) */
522 FALSE
, /* pc_relative */
524 complain_overflow_bitfield
, /* complain_on_overflow */
525 bfd_elf_generic_reloc
, /* special_function */
526 "R_PPC_ADDR14_BRTAKEN",/* name */
527 FALSE
, /* partial_inplace */
529 0xfffc, /* dst_mask */
530 FALSE
), /* pcrel_offset */
532 /* An absolute 16 bit branch, for which bit 10 should be set to
533 indicate that the branch is not expected to be taken. The lower
534 two bits must be zero. */
535 HOWTO (R_PPC_ADDR14_BRNTAKEN
, /* type */
537 2, /* size (0 = byte, 1 = short, 2 = long) */
539 FALSE
, /* pc_relative */
541 complain_overflow_bitfield
, /* complain_on_overflow */
542 bfd_elf_generic_reloc
, /* special_function */
543 "R_PPC_ADDR14_BRNTAKEN",/* name */
544 FALSE
, /* partial_inplace */
546 0xfffc, /* dst_mask */
547 FALSE
), /* pcrel_offset */
549 /* A relative 26 bit branch; the lower two bits must be zero. */
550 HOWTO (R_PPC_REL24
, /* type */
552 2, /* size (0 = byte, 1 = short, 2 = long) */
554 TRUE
, /* pc_relative */
556 complain_overflow_signed
, /* complain_on_overflow */
557 bfd_elf_generic_reloc
, /* special_function */
558 "R_PPC_REL24", /* name */
559 FALSE
, /* partial_inplace */
561 0x3fffffc, /* dst_mask */
562 TRUE
), /* pcrel_offset */
564 /* A relative 16 bit branch; the lower two bits must be zero. */
565 HOWTO (R_PPC_REL14
, /* type */
567 2, /* size (0 = byte, 1 = short, 2 = long) */
569 TRUE
, /* pc_relative */
571 complain_overflow_signed
, /* complain_on_overflow */
572 bfd_elf_generic_reloc
, /* special_function */
573 "R_PPC_REL14", /* name */
574 FALSE
, /* partial_inplace */
576 0xfffc, /* dst_mask */
577 TRUE
), /* pcrel_offset */
579 /* A relative 16 bit branch. Bit 10 should be set to indicate that
580 the branch is expected to be taken. The lower two bits must be
582 HOWTO (R_PPC_REL14_BRTAKEN
, /* type */
584 2, /* size (0 = byte, 1 = short, 2 = long) */
586 TRUE
, /* pc_relative */
588 complain_overflow_signed
, /* complain_on_overflow */
589 bfd_elf_generic_reloc
, /* special_function */
590 "R_PPC_REL14_BRTAKEN", /* name */
591 FALSE
, /* partial_inplace */
593 0xfffc, /* dst_mask */
594 TRUE
), /* pcrel_offset */
596 /* A relative 16 bit branch. Bit 10 should be set to indicate that
597 the branch is not expected to be taken. The lower two bits must
599 HOWTO (R_PPC_REL14_BRNTAKEN
, /* type */
601 2, /* size (0 = byte, 1 = short, 2 = long) */
603 TRUE
, /* pc_relative */
605 complain_overflow_signed
, /* complain_on_overflow */
606 bfd_elf_generic_reloc
, /* special_function */
607 "R_PPC_REL14_BRNTAKEN",/* name */
608 FALSE
, /* partial_inplace */
610 0xfffc, /* dst_mask */
611 TRUE
), /* pcrel_offset */
613 /* Like R_PPC_ADDR16, but referring to the GOT table entry for the
615 HOWTO (R_PPC_GOT16
, /* type */
617 1, /* size (0 = byte, 1 = short, 2 = long) */
619 FALSE
, /* pc_relative */
621 complain_overflow_signed
, /* complain_on_overflow */
622 bfd_elf_generic_reloc
, /* special_function */
623 "R_PPC_GOT16", /* name */
624 FALSE
, /* partial_inplace */
626 0xffff, /* dst_mask */
627 FALSE
), /* pcrel_offset */
629 /* Like R_PPC_ADDR16_LO, but referring to the GOT table entry for
631 HOWTO (R_PPC_GOT16_LO
, /* type */
633 1, /* size (0 = byte, 1 = short, 2 = long) */
635 FALSE
, /* pc_relative */
637 complain_overflow_dont
, /* complain_on_overflow */
638 bfd_elf_generic_reloc
, /* special_function */
639 "R_PPC_GOT16_LO", /* name */
640 FALSE
, /* partial_inplace */
642 0xffff, /* dst_mask */
643 FALSE
), /* pcrel_offset */
645 /* Like R_PPC_ADDR16_HI, but referring to the GOT table entry for
647 HOWTO (R_PPC_GOT16_HI
, /* type */
649 1, /* size (0 = byte, 1 = short, 2 = long) */
651 FALSE
, /* pc_relative */
653 complain_overflow_bitfield
, /* complain_on_overflow */
654 bfd_elf_generic_reloc
, /* special_function */
655 "R_PPC_GOT16_HI", /* name */
656 FALSE
, /* partial_inplace */
658 0xffff, /* dst_mask */
659 FALSE
), /* pcrel_offset */
661 /* Like R_PPC_ADDR16_HA, but referring to the GOT table entry for
663 HOWTO (R_PPC_GOT16_HA
, /* type */
665 1, /* size (0 = byte, 1 = short, 2 = long) */
667 FALSE
, /* pc_relative */
669 complain_overflow_bitfield
, /* complain_on_overflow */
670 ppc_elf_addr16_ha_reloc
, /* special_function */
671 "R_PPC_GOT16_HA", /* name */
672 FALSE
, /* partial_inplace */
674 0xffff, /* dst_mask */
675 FALSE
), /* pcrel_offset */
677 /* Like R_PPC_REL24, but referring to the procedure linkage table
678 entry for the symbol. */
679 HOWTO (R_PPC_PLTREL24
, /* type */
681 2, /* size (0 = byte, 1 = short, 2 = long) */
683 TRUE
, /* pc_relative */
685 complain_overflow_signed
, /* complain_on_overflow */
686 bfd_elf_generic_reloc
, /* special_function */
687 "R_PPC_PLTREL24", /* name */
688 FALSE
, /* partial_inplace */
690 0x3fffffc, /* dst_mask */
691 TRUE
), /* pcrel_offset */
693 /* This is used only by the dynamic linker. The symbol should exist
694 both in the object being run and in some shared library. The
695 dynamic linker copies the data addressed by the symbol from the
696 shared library into the object, because the object being
697 run has to have the data at some particular address. */
698 HOWTO (R_PPC_COPY
, /* type */
700 2, /* size (0 = byte, 1 = short, 2 = long) */
702 FALSE
, /* pc_relative */
704 complain_overflow_bitfield
, /* complain_on_overflow */
705 bfd_elf_generic_reloc
, /* special_function */
706 "R_PPC_COPY", /* name */
707 FALSE
, /* partial_inplace */
710 FALSE
), /* pcrel_offset */
712 /* Like R_PPC_ADDR32, but used when setting global offset table
714 HOWTO (R_PPC_GLOB_DAT
, /* type */
716 2, /* size (0 = byte, 1 = short, 2 = long) */
718 FALSE
, /* pc_relative */
720 complain_overflow_bitfield
, /* complain_on_overflow */
721 bfd_elf_generic_reloc
, /* special_function */
722 "R_PPC_GLOB_DAT", /* name */
723 FALSE
, /* partial_inplace */
725 0xffffffff, /* dst_mask */
726 FALSE
), /* pcrel_offset */
728 /* Marks a procedure linkage table entry for a symbol. */
729 HOWTO (R_PPC_JMP_SLOT
, /* type */
731 2, /* size (0 = byte, 1 = short, 2 = long) */
733 FALSE
, /* pc_relative */
735 complain_overflow_bitfield
, /* complain_on_overflow */
736 bfd_elf_generic_reloc
, /* special_function */
737 "R_PPC_JMP_SLOT", /* name */
738 FALSE
, /* partial_inplace */
741 FALSE
), /* pcrel_offset */
743 /* Used only by the dynamic linker. When the object is run, this
744 longword is set to the load address of the object, plus the
746 HOWTO (R_PPC_RELATIVE
, /* type */
748 2, /* size (0 = byte, 1 = short, 2 = long) */
750 FALSE
, /* pc_relative */
752 complain_overflow_bitfield
, /* complain_on_overflow */
753 bfd_elf_generic_reloc
, /* special_function */
754 "R_PPC_RELATIVE", /* name */
755 FALSE
, /* partial_inplace */
757 0xffffffff, /* dst_mask */
758 FALSE
), /* pcrel_offset */
760 /* Like R_PPC_REL24, but uses the value of the symbol within the
761 object rather than the final value. Normally used for
762 _GLOBAL_OFFSET_TABLE_. */
763 HOWTO (R_PPC_LOCAL24PC
, /* type */
765 2, /* size (0 = byte, 1 = short, 2 = long) */
767 TRUE
, /* pc_relative */
769 complain_overflow_signed
, /* complain_on_overflow */
770 bfd_elf_generic_reloc
, /* special_function */
771 "R_PPC_LOCAL24PC", /* name */
772 FALSE
, /* partial_inplace */
774 0x3fffffc, /* dst_mask */
775 TRUE
), /* pcrel_offset */
777 /* Like R_PPC_ADDR32, but may be unaligned. */
778 HOWTO (R_PPC_UADDR32
, /* type */
780 2, /* size (0 = byte, 1 = short, 2 = long) */
782 FALSE
, /* pc_relative */
784 complain_overflow_bitfield
, /* complain_on_overflow */
785 bfd_elf_generic_reloc
, /* special_function */
786 "R_PPC_UADDR32", /* name */
787 FALSE
, /* partial_inplace */
789 0xffffffff, /* dst_mask */
790 FALSE
), /* pcrel_offset */
792 /* Like R_PPC_ADDR16, but may be unaligned. */
793 HOWTO (R_PPC_UADDR16
, /* type */
795 1, /* size (0 = byte, 1 = short, 2 = long) */
797 FALSE
, /* pc_relative */
799 complain_overflow_bitfield
, /* complain_on_overflow */
800 bfd_elf_generic_reloc
, /* special_function */
801 "R_PPC_UADDR16", /* name */
802 FALSE
, /* partial_inplace */
804 0xffff, /* dst_mask */
805 FALSE
), /* pcrel_offset */
807 /* 32-bit PC relative */
808 HOWTO (R_PPC_REL32
, /* type */
810 2, /* size (0 = byte, 1 = short, 2 = long) */
812 TRUE
, /* pc_relative */
814 complain_overflow_bitfield
, /* complain_on_overflow */
815 bfd_elf_generic_reloc
, /* special_function */
816 "R_PPC_REL32", /* name */
817 FALSE
, /* partial_inplace */
819 0xffffffff, /* dst_mask */
820 TRUE
), /* pcrel_offset */
822 /* 32-bit relocation to the symbol's procedure linkage table.
823 FIXME: not supported. */
824 HOWTO (R_PPC_PLT32
, /* type */
826 2, /* size (0 = byte, 1 = short, 2 = long) */
828 FALSE
, /* pc_relative */
830 complain_overflow_bitfield
, /* complain_on_overflow */
831 bfd_elf_generic_reloc
, /* special_function */
832 "R_PPC_PLT32", /* name */
833 FALSE
, /* partial_inplace */
836 FALSE
), /* pcrel_offset */
838 /* 32-bit PC relative relocation to the symbol's procedure linkage table.
839 FIXME: not supported. */
840 HOWTO (R_PPC_PLTREL32
, /* type */
842 2, /* size (0 = byte, 1 = short, 2 = long) */
844 TRUE
, /* pc_relative */
846 complain_overflow_bitfield
, /* complain_on_overflow */
847 bfd_elf_generic_reloc
, /* special_function */
848 "R_PPC_PLTREL32", /* name */
849 FALSE
, /* partial_inplace */
852 TRUE
), /* pcrel_offset */
854 /* Like R_PPC_ADDR16_LO, but referring to the PLT table entry for
856 HOWTO (R_PPC_PLT16_LO
, /* type */
858 1, /* size (0 = byte, 1 = short, 2 = long) */
860 FALSE
, /* pc_relative */
862 complain_overflow_dont
, /* complain_on_overflow */
863 bfd_elf_generic_reloc
, /* special_function */
864 "R_PPC_PLT16_LO", /* name */
865 FALSE
, /* partial_inplace */
867 0xffff, /* dst_mask */
868 FALSE
), /* pcrel_offset */
870 /* Like R_PPC_ADDR16_HI, but referring to the PLT table entry for
872 HOWTO (R_PPC_PLT16_HI
, /* type */
874 1, /* size (0 = byte, 1 = short, 2 = long) */
876 FALSE
, /* pc_relative */
878 complain_overflow_bitfield
, /* complain_on_overflow */
879 bfd_elf_generic_reloc
, /* special_function */
880 "R_PPC_PLT16_HI", /* name */
881 FALSE
, /* partial_inplace */
883 0xffff, /* dst_mask */
884 FALSE
), /* pcrel_offset */
886 /* Like R_PPC_ADDR16_HA, but referring to the PLT table entry for
888 HOWTO (R_PPC_PLT16_HA
, /* type */
890 1, /* size (0 = byte, 1 = short, 2 = long) */
892 FALSE
, /* pc_relative */
894 complain_overflow_bitfield
, /* complain_on_overflow */
895 ppc_elf_addr16_ha_reloc
, /* special_function */
896 "R_PPC_PLT16_HA", /* name */
897 FALSE
, /* partial_inplace */
899 0xffff, /* dst_mask */
900 FALSE
), /* pcrel_offset */
902 /* A sign-extended 16 bit value relative to _SDA_BASE_, for use with
904 HOWTO (R_PPC_SDAREL16
, /* type */
906 1, /* size (0 = byte, 1 = short, 2 = long) */
908 FALSE
, /* pc_relative */
910 complain_overflow_signed
, /* complain_on_overflow */
911 bfd_elf_generic_reloc
, /* special_function */
912 "R_PPC_SDAREL16", /* name */
913 FALSE
, /* partial_inplace */
915 0xffff, /* dst_mask */
916 FALSE
), /* pcrel_offset */
918 /* 16-bit section relative relocation. */
919 HOWTO (R_PPC_SECTOFF
, /* type */
921 1, /* size (0 = byte, 1 = short, 2 = long) */
923 FALSE
, /* pc_relative */
925 complain_overflow_bitfield
, /* complain_on_overflow */
926 bfd_elf_generic_reloc
, /* special_function */
927 "R_PPC_SECTOFF", /* name */
928 FALSE
, /* partial_inplace */
930 0xffff, /* dst_mask */
931 FALSE
), /* pcrel_offset */
933 /* 16-bit lower half section relative relocation. */
934 HOWTO (R_PPC_SECTOFF_LO
, /* type */
936 1, /* size (0 = byte, 1 = short, 2 = long) */
938 FALSE
, /* pc_relative */
940 complain_overflow_dont
, /* complain_on_overflow */
941 bfd_elf_generic_reloc
, /* special_function */
942 "R_PPC_SECTOFF_LO", /* name */
943 FALSE
, /* partial_inplace */
945 0xffff, /* dst_mask */
946 FALSE
), /* pcrel_offset */
948 /* 16-bit upper half section relative relocation. */
949 HOWTO (R_PPC_SECTOFF_HI
, /* type */
951 1, /* size (0 = byte, 1 = short, 2 = long) */
953 FALSE
, /* pc_relative */
955 complain_overflow_bitfield
, /* complain_on_overflow */
956 bfd_elf_generic_reloc
, /* special_function */
957 "R_PPC_SECTOFF_HI", /* name */
958 FALSE
, /* partial_inplace */
960 0xffff, /* dst_mask */
961 FALSE
), /* pcrel_offset */
963 /* 16-bit upper half adjusted section relative relocation. */
964 HOWTO (R_PPC_SECTOFF_HA
, /* type */
966 1, /* size (0 = byte, 1 = short, 2 = long) */
968 FALSE
, /* pc_relative */
970 complain_overflow_bitfield
, /* complain_on_overflow */
971 ppc_elf_addr16_ha_reloc
, /* special_function */
972 "R_PPC_SECTOFF_HA", /* name */
973 FALSE
, /* partial_inplace */
975 0xffff, /* dst_mask */
976 FALSE
), /* pcrel_offset */
978 /* Marker reloc for TLS. */
981 2, /* size (0 = byte, 1 = short, 2 = long) */
983 FALSE
, /* pc_relative */
985 complain_overflow_dont
, /* complain_on_overflow */
986 bfd_elf_generic_reloc
, /* special_function */
987 "R_PPC_TLS", /* name */
988 FALSE
, /* partial_inplace */
991 FALSE
), /* pcrel_offset */
993 /* Computes the load module index of the load module that contains the
994 definition of its TLS sym. */
995 HOWTO (R_PPC_DTPMOD32
,
997 2, /* size (0 = byte, 1 = short, 2 = long) */
999 FALSE
, /* pc_relative */
1001 complain_overflow_dont
, /* complain_on_overflow */
1002 ppc_elf_unhandled_reloc
, /* special_function */
1003 "R_PPC_DTPMOD32", /* name */
1004 FALSE
, /* partial_inplace */
1006 0xffffffff, /* dst_mask */
1007 FALSE
), /* pcrel_offset */
1009 /* Computes a dtv-relative displacement, the difference between the value
1010 of sym+add and the base address of the thread-local storage block that
1011 contains the definition of sym, minus 0x8000. */
1012 HOWTO (R_PPC_DTPREL32
,
1014 2, /* size (0 = byte, 1 = short, 2 = long) */
1016 FALSE
, /* pc_relative */
1018 complain_overflow_dont
, /* complain_on_overflow */
1019 ppc_elf_unhandled_reloc
, /* special_function */
1020 "R_PPC_DTPREL32", /* name */
1021 FALSE
, /* partial_inplace */
1023 0xffffffff, /* dst_mask */
1024 FALSE
), /* pcrel_offset */
1026 /* A 16 bit dtprel reloc. */
1027 HOWTO (R_PPC_DTPREL16
,
1029 1, /* size (0 = byte, 1 = short, 2 = long) */
1031 FALSE
, /* pc_relative */
1033 complain_overflow_signed
, /* complain_on_overflow */
1034 ppc_elf_unhandled_reloc
, /* special_function */
1035 "R_PPC_DTPREL16", /* name */
1036 FALSE
, /* partial_inplace */
1038 0xffff, /* dst_mask */
1039 FALSE
), /* pcrel_offset */
1041 /* Like DTPREL16, but no overflow. */
1042 HOWTO (R_PPC_DTPREL16_LO
,
1044 1, /* size (0 = byte, 1 = short, 2 = long) */
1046 FALSE
, /* pc_relative */
1048 complain_overflow_dont
, /* complain_on_overflow */
1049 ppc_elf_unhandled_reloc
, /* special_function */
1050 "R_PPC_DTPREL16_LO", /* name */
1051 FALSE
, /* partial_inplace */
1053 0xffff, /* dst_mask */
1054 FALSE
), /* pcrel_offset */
1056 /* Like DTPREL16_LO, but next higher group of 16 bits. */
1057 HOWTO (R_PPC_DTPREL16_HI
,
1058 16, /* rightshift */
1059 1, /* size (0 = byte, 1 = short, 2 = long) */
1061 FALSE
, /* pc_relative */
1063 complain_overflow_dont
, /* complain_on_overflow */
1064 ppc_elf_unhandled_reloc
, /* special_function */
1065 "R_PPC_DTPREL16_HI", /* name */
1066 FALSE
, /* partial_inplace */
1068 0xffff, /* dst_mask */
1069 FALSE
), /* pcrel_offset */
1071 /* Like DTPREL16_HI, but adjust for low 16 bits. */
1072 HOWTO (R_PPC_DTPREL16_HA
,
1073 16, /* rightshift */
1074 1, /* size (0 = byte, 1 = short, 2 = long) */
1076 FALSE
, /* pc_relative */
1078 complain_overflow_dont
, /* complain_on_overflow */
1079 ppc_elf_unhandled_reloc
, /* special_function */
1080 "R_PPC_DTPREL16_HA", /* name */
1081 FALSE
, /* partial_inplace */
1083 0xffff, /* dst_mask */
1084 FALSE
), /* pcrel_offset */
1086 /* Computes a tp-relative displacement, the difference between the value of
1087 sym+add and the value of the thread pointer (r13). */
1088 HOWTO (R_PPC_TPREL32
,
1090 2, /* size (0 = byte, 1 = short, 2 = long) */
1092 FALSE
, /* pc_relative */
1094 complain_overflow_dont
, /* complain_on_overflow */
1095 ppc_elf_unhandled_reloc
, /* special_function */
1096 "R_PPC_TPREL32", /* name */
1097 FALSE
, /* partial_inplace */
1099 0xffffffff, /* dst_mask */
1100 FALSE
), /* pcrel_offset */
1102 /* A 16 bit tprel reloc. */
1103 HOWTO (R_PPC_TPREL16
,
1105 1, /* size (0 = byte, 1 = short, 2 = long) */
1107 FALSE
, /* pc_relative */
1109 complain_overflow_signed
, /* complain_on_overflow */
1110 ppc_elf_unhandled_reloc
, /* special_function */
1111 "R_PPC_TPREL16", /* name */
1112 FALSE
, /* partial_inplace */
1114 0xffff, /* dst_mask */
1115 FALSE
), /* pcrel_offset */
1117 /* Like TPREL16, but no overflow. */
1118 HOWTO (R_PPC_TPREL16_LO
,
1120 1, /* size (0 = byte, 1 = short, 2 = long) */
1122 FALSE
, /* pc_relative */
1124 complain_overflow_dont
, /* complain_on_overflow */
1125 ppc_elf_unhandled_reloc
, /* special_function */
1126 "R_PPC_TPREL16_LO", /* name */
1127 FALSE
, /* partial_inplace */
1129 0xffff, /* dst_mask */
1130 FALSE
), /* pcrel_offset */
1132 /* Like TPREL16_LO, but next higher group of 16 bits. */
1133 HOWTO (R_PPC_TPREL16_HI
,
1134 16, /* rightshift */
1135 1, /* size (0 = byte, 1 = short, 2 = long) */
1137 FALSE
, /* pc_relative */
1139 complain_overflow_dont
, /* complain_on_overflow */
1140 ppc_elf_unhandled_reloc
, /* special_function */
1141 "R_PPC_TPREL16_HI", /* name */
1142 FALSE
, /* partial_inplace */
1144 0xffff, /* dst_mask */
1145 FALSE
), /* pcrel_offset */
1147 /* Like TPREL16_HI, but adjust for low 16 bits. */
1148 HOWTO (R_PPC_TPREL16_HA
,
1149 16, /* rightshift */
1150 1, /* size (0 = byte, 1 = short, 2 = long) */
1152 FALSE
, /* pc_relative */
1154 complain_overflow_dont
, /* complain_on_overflow */
1155 ppc_elf_unhandled_reloc
, /* special_function */
1156 "R_PPC_TPREL16_HA", /* name */
1157 FALSE
, /* partial_inplace */
1159 0xffff, /* dst_mask */
1160 FALSE
), /* pcrel_offset */
1162 /* Allocates two contiguous entries in the GOT to hold a tls_index structure,
1163 with values (sym+add)@dtpmod and (sym+add)@dtprel, and computes the offset
1164 to the first entry. */
1165 HOWTO (R_PPC_GOT_TLSGD16
,
1167 1, /* size (0 = byte, 1 = short, 2 = long) */
1169 FALSE
, /* pc_relative */
1171 complain_overflow_signed
, /* complain_on_overflow */
1172 ppc_elf_unhandled_reloc
, /* special_function */
1173 "R_PPC_GOT_TLSGD16", /* name */
1174 FALSE
, /* partial_inplace */
1176 0xffff, /* dst_mask */
1177 FALSE
), /* pcrel_offset */
1179 /* Like GOT_TLSGD16, but no overflow. */
1180 HOWTO (R_PPC_GOT_TLSGD16_LO
,
1182 1, /* size (0 = byte, 1 = short, 2 = long) */
1184 FALSE
, /* pc_relative */
1186 complain_overflow_dont
, /* complain_on_overflow */
1187 ppc_elf_unhandled_reloc
, /* special_function */
1188 "R_PPC_GOT_TLSGD16_LO", /* name */
1189 FALSE
, /* partial_inplace */
1191 0xffff, /* dst_mask */
1192 FALSE
), /* pcrel_offset */
1194 /* Like GOT_TLSGD16_LO, but next higher group of 16 bits. */
1195 HOWTO (R_PPC_GOT_TLSGD16_HI
,
1196 16, /* rightshift */
1197 1, /* size (0 = byte, 1 = short, 2 = long) */
1199 FALSE
, /* pc_relative */
1201 complain_overflow_dont
, /* complain_on_overflow */
1202 ppc_elf_unhandled_reloc
, /* special_function */
1203 "R_PPC_GOT_TLSGD16_HI", /* name */
1204 FALSE
, /* partial_inplace */
1206 0xffff, /* dst_mask */
1207 FALSE
), /* pcrel_offset */
1209 /* Like GOT_TLSGD16_HI, but adjust for low 16 bits. */
1210 HOWTO (R_PPC_GOT_TLSGD16_HA
,
1211 16, /* rightshift */
1212 1, /* size (0 = byte, 1 = short, 2 = long) */
1214 FALSE
, /* pc_relative */
1216 complain_overflow_dont
, /* complain_on_overflow */
1217 ppc_elf_unhandled_reloc
, /* special_function */
1218 "R_PPC_GOT_TLSGD16_HA", /* name */
1219 FALSE
, /* partial_inplace */
1221 0xffff, /* dst_mask */
1222 FALSE
), /* pcrel_offset */
1224 /* Allocates two contiguous entries in the GOT to hold a tls_index structure,
1225 with values (sym+add)@dtpmod and zero, and computes the offset to the
1227 HOWTO (R_PPC_GOT_TLSLD16
,
1229 1, /* size (0 = byte, 1 = short, 2 = long) */
1231 FALSE
, /* pc_relative */
1233 complain_overflow_signed
, /* complain_on_overflow */
1234 ppc_elf_unhandled_reloc
, /* special_function */
1235 "R_PPC_GOT_TLSLD16", /* name */
1236 FALSE
, /* partial_inplace */
1238 0xffff, /* dst_mask */
1239 FALSE
), /* pcrel_offset */
1241 /* Like GOT_TLSLD16, but no overflow. */
1242 HOWTO (R_PPC_GOT_TLSLD16_LO
,
1244 1, /* size (0 = byte, 1 = short, 2 = long) */
1246 FALSE
, /* pc_relative */
1248 complain_overflow_dont
, /* complain_on_overflow */
1249 ppc_elf_unhandled_reloc
, /* special_function */
1250 "R_PPC_GOT_TLSLD16_LO", /* name */
1251 FALSE
, /* partial_inplace */
1253 0xffff, /* dst_mask */
1254 FALSE
), /* pcrel_offset */
1256 /* Like GOT_TLSLD16_LO, but next higher group of 16 bits. */
1257 HOWTO (R_PPC_GOT_TLSLD16_HI
,
1258 16, /* rightshift */
1259 1, /* size (0 = byte, 1 = short, 2 = long) */
1261 FALSE
, /* pc_relative */
1263 complain_overflow_dont
, /* complain_on_overflow */
1264 ppc_elf_unhandled_reloc
, /* special_function */
1265 "R_PPC_GOT_TLSLD16_HI", /* name */
1266 FALSE
, /* partial_inplace */
1268 0xffff, /* dst_mask */
1269 FALSE
), /* pcrel_offset */
1271 /* Like GOT_TLSLD16_HI, but adjust for low 16 bits. */
1272 HOWTO (R_PPC_GOT_TLSLD16_HA
,
1273 16, /* rightshift */
1274 1, /* size (0 = byte, 1 = short, 2 = long) */
1276 FALSE
, /* pc_relative */
1278 complain_overflow_dont
, /* complain_on_overflow */
1279 ppc_elf_unhandled_reloc
, /* special_function */
1280 "R_PPC_GOT_TLSLD16_HA", /* name */
1281 FALSE
, /* partial_inplace */
1283 0xffff, /* dst_mask */
1284 FALSE
), /* pcrel_offset */
1286 /* Allocates an entry in the GOT with value (sym+add)@dtprel, and computes
1287 the offset to the entry. */
1288 HOWTO (R_PPC_GOT_DTPREL16
,
1290 1, /* size (0 = byte, 1 = short, 2 = long) */
1292 FALSE
, /* pc_relative */
1294 complain_overflow_signed
, /* complain_on_overflow */
1295 ppc_elf_unhandled_reloc
, /* special_function */
1296 "R_PPC_GOT_DTPREL16", /* name */
1297 FALSE
, /* partial_inplace */
1299 0xffff, /* dst_mask */
1300 FALSE
), /* pcrel_offset */
1302 /* Like GOT_DTPREL16, but no overflow. */
1303 HOWTO (R_PPC_GOT_DTPREL16_LO
,
1305 1, /* size (0 = byte, 1 = short, 2 = long) */
1307 FALSE
, /* pc_relative */
1309 complain_overflow_dont
, /* complain_on_overflow */
1310 ppc_elf_unhandled_reloc
, /* special_function */
1311 "R_PPC_GOT_DTPREL16_LO", /* name */
1312 FALSE
, /* partial_inplace */
1314 0xffff, /* dst_mask */
1315 FALSE
), /* pcrel_offset */
1317 /* Like GOT_DTPREL16_LO, but next higher group of 16 bits. */
1318 HOWTO (R_PPC_GOT_DTPREL16_HI
,
1319 16, /* rightshift */
1320 1, /* size (0 = byte, 1 = short, 2 = long) */
1322 FALSE
, /* pc_relative */
1324 complain_overflow_dont
, /* complain_on_overflow */
1325 ppc_elf_unhandled_reloc
, /* special_function */
1326 "R_PPC_GOT_DTPREL16_HI", /* name */
1327 FALSE
, /* partial_inplace */
1329 0xffff, /* dst_mask */
1330 FALSE
), /* pcrel_offset */
1332 /* Like GOT_DTPREL16_HI, but adjust for low 16 bits. */
1333 HOWTO (R_PPC_GOT_DTPREL16_HA
,
1334 16, /* rightshift */
1335 1, /* size (0 = byte, 1 = short, 2 = long) */
1337 FALSE
, /* pc_relative */
1339 complain_overflow_dont
, /* complain_on_overflow */
1340 ppc_elf_unhandled_reloc
, /* special_function */
1341 "R_PPC_GOT_DTPREL16_HA", /* name */
1342 FALSE
, /* partial_inplace */
1344 0xffff, /* dst_mask */
1345 FALSE
), /* pcrel_offset */
1347 /* Allocates an entry in the GOT with value (sym+add)@tprel, and computes the
1348 offset to the entry. */
1349 HOWTO (R_PPC_GOT_TPREL16
,
1351 1, /* size (0 = byte, 1 = short, 2 = long) */
1353 FALSE
, /* pc_relative */
1355 complain_overflow_signed
, /* complain_on_overflow */
1356 ppc_elf_unhandled_reloc
, /* special_function */
1357 "R_PPC_GOT_TPREL16", /* name */
1358 FALSE
, /* partial_inplace */
1360 0xffff, /* dst_mask */
1361 FALSE
), /* pcrel_offset */
1363 /* Like GOT_TPREL16, but no overflow. */
1364 HOWTO (R_PPC_GOT_TPREL16_LO
,
1366 1, /* size (0 = byte, 1 = short, 2 = long) */
1368 FALSE
, /* pc_relative */
1370 complain_overflow_dont
, /* complain_on_overflow */
1371 ppc_elf_unhandled_reloc
, /* special_function */
1372 "R_PPC_GOT_TPREL16_LO", /* name */
1373 FALSE
, /* partial_inplace */
1375 0xffff, /* dst_mask */
1376 FALSE
), /* pcrel_offset */
1378 /* Like GOT_TPREL16_LO, but next higher group of 16 bits. */
1379 HOWTO (R_PPC_GOT_TPREL16_HI
,
1380 16, /* rightshift */
1381 1, /* size (0 = byte, 1 = short, 2 = long) */
1383 FALSE
, /* pc_relative */
1385 complain_overflow_dont
, /* complain_on_overflow */
1386 ppc_elf_unhandled_reloc
, /* special_function */
1387 "R_PPC_GOT_TPREL16_HI", /* name */
1388 FALSE
, /* partial_inplace */
1390 0xffff, /* dst_mask */
1391 FALSE
), /* pcrel_offset */
1393 /* Like GOT_TPREL16_HI, but adjust for low 16 bits. */
1394 HOWTO (R_PPC_GOT_TPREL16_HA
,
1395 16, /* rightshift */
1396 1, /* size (0 = byte, 1 = short, 2 = long) */
1398 FALSE
, /* pc_relative */
1400 complain_overflow_dont
, /* complain_on_overflow */
1401 ppc_elf_unhandled_reloc
, /* special_function */
1402 "R_PPC_GOT_TPREL16_HA", /* name */
1403 FALSE
, /* partial_inplace */
1405 0xffff, /* dst_mask */
1406 FALSE
), /* pcrel_offset */
1408 /* The remaining relocs are from the Embedded ELF ABI, and are not
1409 in the SVR4 ELF ABI. */
1411 /* 32 bit value resulting from the addend minus the symbol. */
1412 HOWTO (R_PPC_EMB_NADDR32
, /* type */
1414 2, /* size (0 = byte, 1 = short, 2 = long) */
1416 FALSE
, /* pc_relative */
1418 complain_overflow_bitfield
, /* complain_on_overflow */
1419 bfd_elf_generic_reloc
, /* special_function */
1420 "R_PPC_EMB_NADDR32", /* name */
1421 FALSE
, /* partial_inplace */
1423 0xffffffff, /* dst_mask */
1424 FALSE
), /* pcrel_offset */
1426 /* 16 bit value resulting from the addend minus the symbol. */
1427 HOWTO (R_PPC_EMB_NADDR16
, /* type */
1429 1, /* size (0 = byte, 1 = short, 2 = long) */
1431 FALSE
, /* pc_relative */
1433 complain_overflow_bitfield
, /* complain_on_overflow */
1434 bfd_elf_generic_reloc
, /* special_function */
1435 "R_PPC_EMB_NADDR16", /* name */
1436 FALSE
, /* partial_inplace */
1438 0xffff, /* dst_mask */
1439 FALSE
), /* pcrel_offset */
1441 /* 16 bit value resulting from the addend minus the symbol. */
1442 HOWTO (R_PPC_EMB_NADDR16_LO
, /* type */
1444 1, /* size (0 = byte, 1 = short, 2 = long) */
1446 FALSE
, /* pc_relative */
1448 complain_overflow_dont
,/* complain_on_overflow */
1449 bfd_elf_generic_reloc
, /* special_function */
1450 "R_PPC_EMB_ADDR16_LO", /* name */
1451 FALSE
, /* partial_inplace */
1453 0xffff, /* dst_mask */
1454 FALSE
), /* pcrel_offset */
1456 /* The high order 16 bits of the addend minus the symbol. */
1457 HOWTO (R_PPC_EMB_NADDR16_HI
, /* type */
1458 16, /* rightshift */
1459 1, /* size (0 = byte, 1 = short, 2 = long) */
1461 FALSE
, /* pc_relative */
1463 complain_overflow_dont
, /* complain_on_overflow */
1464 bfd_elf_generic_reloc
, /* special_function */
1465 "R_PPC_EMB_NADDR16_HI", /* name */
1466 FALSE
, /* partial_inplace */
1468 0xffff, /* dst_mask */
1469 FALSE
), /* pcrel_offset */
1471 /* The high order 16 bits of the result of the addend minus the address,
1472 plus 1 if the contents of the low 16 bits, treated as a signed number,
1474 HOWTO (R_PPC_EMB_NADDR16_HA
, /* type */
1475 16, /* rightshift */
1476 1, /* size (0 = byte, 1 = short, 2 = long) */
1478 FALSE
, /* pc_relative */
1480 complain_overflow_dont
, /* complain_on_overflow */
1481 ppc_elf_addr16_ha_reloc
, /* special_function */
1482 "R_PPC_EMB_NADDR16_HA", /* name */
1483 FALSE
, /* partial_inplace */
1485 0xffff, /* dst_mask */
1486 FALSE
), /* pcrel_offset */
1488 /* 16 bit value resulting from allocating a 4 byte word to hold an
1489 address in the .sdata section, and returning the offset from
1490 _SDA_BASE_ for that relocation. */
1491 HOWTO (R_PPC_EMB_SDAI16
, /* type */
1493 1, /* size (0 = byte, 1 = short, 2 = long) */
1495 FALSE
, /* pc_relative */
1497 complain_overflow_bitfield
, /* complain_on_overflow */
1498 bfd_elf_generic_reloc
, /* special_function */
1499 "R_PPC_EMB_SDAI16", /* name */
1500 FALSE
, /* partial_inplace */
1502 0xffff, /* dst_mask */
1503 FALSE
), /* pcrel_offset */
1505 /* 16 bit value resulting from allocating a 4 byte word to hold an
1506 address in the .sdata2 section, and returning the offset from
1507 _SDA2_BASE_ for that relocation. */
1508 HOWTO (R_PPC_EMB_SDA2I16
, /* type */
1510 1, /* size (0 = byte, 1 = short, 2 = long) */
1512 FALSE
, /* pc_relative */
1514 complain_overflow_bitfield
, /* complain_on_overflow */
1515 bfd_elf_generic_reloc
, /* special_function */
1516 "R_PPC_EMB_SDA2I16", /* name */
1517 FALSE
, /* partial_inplace */
1519 0xffff, /* dst_mask */
1520 FALSE
), /* pcrel_offset */
1522 /* A sign-extended 16 bit value relative to _SDA2_BASE_, for use with
1523 small data items. */
1524 HOWTO (R_PPC_EMB_SDA2REL
, /* type */
1526 1, /* size (0 = byte, 1 = short, 2 = long) */
1528 FALSE
, /* pc_relative */
1530 complain_overflow_signed
, /* complain_on_overflow */
1531 bfd_elf_generic_reloc
, /* special_function */
1532 "R_PPC_EMB_SDA2REL", /* name */
1533 FALSE
, /* partial_inplace */
1535 0xffff, /* dst_mask */
1536 FALSE
), /* pcrel_offset */
1538 /* Relocate against either _SDA_BASE_ or _SDA2_BASE_, filling in the 16 bit
1539 signed offset from the appropriate base, and filling in the register
1540 field with the appropriate register (0, 2, or 13). */
1541 HOWTO (R_PPC_EMB_SDA21
, /* type */
1543 2, /* size (0 = byte, 1 = short, 2 = long) */
1545 FALSE
, /* pc_relative */
1547 complain_overflow_signed
, /* complain_on_overflow */
1548 bfd_elf_generic_reloc
, /* special_function */
1549 "R_PPC_EMB_SDA21", /* name */
1550 FALSE
, /* partial_inplace */
1552 0xffff, /* dst_mask */
1553 FALSE
), /* pcrel_offset */
1555 /* Relocation not handled: R_PPC_EMB_MRKREF */
1556 /* Relocation not handled: R_PPC_EMB_RELSEC16 */
1557 /* Relocation not handled: R_PPC_EMB_RELST_LO */
1558 /* Relocation not handled: R_PPC_EMB_RELST_HI */
1559 /* Relocation not handled: R_PPC_EMB_RELST_HA */
1560 /* Relocation not handled: R_PPC_EMB_BIT_FLD */
1562 /* PC relative relocation against either _SDA_BASE_ or _SDA2_BASE_, filling
1563 in the 16 bit signed offset from the appropriate base, and filling in the
1564 register field with the appropriate register (0, 2, or 13). */
1565 HOWTO (R_PPC_EMB_RELSDA
, /* type */
1567 1, /* size (0 = byte, 1 = short, 2 = long) */
1569 TRUE
, /* pc_relative */
1571 complain_overflow_signed
, /* complain_on_overflow */
1572 bfd_elf_generic_reloc
, /* special_function */
1573 "R_PPC_EMB_RELSDA", /* name */
1574 FALSE
, /* partial_inplace */
1576 0xffff, /* dst_mask */
1577 FALSE
), /* pcrel_offset */
1579 /* GNU extension to record C++ vtable hierarchy. */
1580 HOWTO (R_PPC_GNU_VTINHERIT
, /* type */
1582 0, /* size (0 = byte, 1 = short, 2 = long) */
1584 FALSE
, /* pc_relative */
1586 complain_overflow_dont
, /* complain_on_overflow */
1587 NULL
, /* special_function */
1588 "R_PPC_GNU_VTINHERIT", /* name */
1589 FALSE
, /* partial_inplace */
1592 FALSE
), /* pcrel_offset */
1594 /* GNU extension to record C++ vtable member usage. */
1595 HOWTO (R_PPC_GNU_VTENTRY
, /* type */
1597 0, /* size (0 = byte, 1 = short, 2 = long) */
1599 FALSE
, /* pc_relative */
1601 complain_overflow_dont
, /* complain_on_overflow */
1602 NULL
, /* special_function */
1603 "R_PPC_GNU_VTENTRY", /* name */
1604 FALSE
, /* partial_inplace */
1607 FALSE
), /* pcrel_offset */
1609 /* Phony reloc to handle AIX style TOC entries. */
1610 HOWTO (R_PPC_TOC16
, /* type */
1612 1, /* size (0 = byte, 1 = short, 2 = long) */
1614 FALSE
, /* pc_relative */
1616 complain_overflow_signed
, /* complain_on_overflow */
1617 bfd_elf_generic_reloc
, /* special_function */
1618 "R_PPC_TOC16", /* name */
1619 FALSE
, /* partial_inplace */
1621 0xffff, /* dst_mask */
1622 FALSE
), /* pcrel_offset */
1625 /* Initialize the ppc_elf_howto_table, so that linear accesses can be done. */
1628 ppc_elf_howto_init ()
1630 unsigned int i
, type
;
1633 i
< sizeof (ppc_elf_howto_raw
) / sizeof (ppc_elf_howto_raw
[0]);
1636 type
= ppc_elf_howto_raw
[i
].type
;
1637 if (type
>= (sizeof (ppc_elf_howto_table
)
1638 / sizeof (ppc_elf_howto_table
[0])))
1640 ppc_elf_howto_table
[type
] = &ppc_elf_howto_raw
[i
];
1644 /* This function handles relaxing for the PPC with option --mpc860c0[=<n>].
1646 The MPC860, revision C0 or earlier contains a bug in the die.
1647 If all of the following conditions are true, the next instruction
1648 to be executed *may* be treated as a no-op.
1649 1/ A forward branch is executed.
1650 2/ The branch is predicted as not taken.
1651 3/ The branch is taken.
1652 4/ The branch is located in the last 5 words of a page.
1653 (The EOP limit is 5 by default but may be specified as any value
1656 Our software solution is to detect these problematic branches in a
1657 linker pass and modify them as follows:
1658 1/ Unconditional branches - Since these are always predicted taken,
1659 there is no problem and no action is required.
1660 2/ Conditional backward branches - No problem, no action required.
1661 3/ Conditional forward branches - Ensure that the "inverse prediction
1662 bit" is set (ensure it is predicted taken).
1663 4/ Conditional register branches - Ensure that the "y bit" is set
1664 (ensure it is predicted taken). */
1666 /* Sort sections by address. */
1669 ppc_elf_sort_rela (arg1
, arg2
)
1673 const Elf_Internal_Rela
**rela1
= (const Elf_Internal_Rela
**) arg1
;
1674 const Elf_Internal_Rela
**rela2
= (const Elf_Internal_Rela
**) arg2
;
1676 /* Sort by offset. */
1677 return ((*rela1
)->r_offset
- (*rela2
)->r_offset
);
1681 ppc_elf_relax_section (abfd
, isec
, link_info
, again
)
1684 struct bfd_link_info
*link_info
;
1687 #define PAGESIZE 0x1000
1689 bfd_byte
*contents
= NULL
;
1690 bfd_byte
*free_contents
= NULL
;
1691 Elf_Internal_Rela
*internal_relocs
= NULL
;
1692 Elf_Internal_Rela
*free_relocs
= NULL
;
1693 Elf_Internal_Rela
**rela_comb
= NULL
;
1694 int comb_curr
, comb_count
;
1696 /* We never have to do this more than once per input section. */
1699 /* If needed, initialize this section's cooked size. */
1700 if (isec
->_cooked_size
== 0)
1701 isec
->_cooked_size
= isec
->_raw_size
;
1703 /* We're only interested in text sections which overlap the
1704 troublesome area at the end of a page. */
1705 if (link_info
->mpc860c0
&& (isec
->flags
& SEC_CODE
) && isec
->_cooked_size
)
1707 bfd_vma dot
, end_page
, end_section
;
1708 bfd_boolean section_modified
;
1710 /* Get the section contents. */
1711 /* Get cached copy if it exists. */
1712 if (elf_section_data (isec
)->this_hdr
.contents
!= NULL
)
1713 contents
= elf_section_data (isec
)->this_hdr
.contents
;
1716 /* Go get them off disk. */
1717 contents
= (bfd_byte
*) bfd_malloc (isec
->_raw_size
);
1718 if (contents
== NULL
)
1720 free_contents
= contents
;
1722 if (! bfd_get_section_contents (abfd
, isec
, contents
,
1723 (file_ptr
) 0, isec
->_raw_size
))
1729 if (isec
->reloc_count
)
1734 /* Get a copy of the native relocations. */
1736 = _bfd_elf32_link_read_relocs (abfd
, isec
, (PTR
) NULL
,
1737 (Elf_Internal_Rela
*) NULL
,
1738 link_info
->keep_memory
);
1739 if (internal_relocs
== NULL
)
1741 if (! link_info
->keep_memory
)
1742 free_relocs
= internal_relocs
;
1744 /* Setup a faster access method for the reloc info we need. */
1745 amt
= isec
->reloc_count
;
1746 amt
*= sizeof (Elf_Internal_Rela
*);
1747 rela_comb
= (Elf_Internal_Rela
**) bfd_malloc (amt
);
1748 if (rela_comb
== NULL
)
1750 for (n
= 0; n
< isec
->reloc_count
; ++n
)
1754 r_type
= ELF32_R_TYPE (internal_relocs
[n
].r_info
);
1755 if (r_type
< 0 || r_type
>= (int) R_PPC_max
)
1758 /* Prologue constants are sometimes present in the ".text"
1759 sections and they can be identified by their associated
1760 relocation. We don't want to process those words and
1761 some others which can also be identified by their
1762 relocations. However, not all conditional branches will
1763 have a relocation so we will only ignore words that
1764 1) have a reloc, and 2) the reloc is not applicable to a
1765 conditional branch. The array rela_comb is built here
1766 for use in the EOP scan loop. */
1769 case R_PPC_ADDR14_BRNTAKEN
:
1771 case R_PPC_REL14_BRNTAKEN
:
1772 /* We should check the instruction. */
1775 /* The word is not a conditional branch - ignore it. */
1776 rela_comb
[comb_count
++] = &internal_relocs
[n
];
1781 qsort (rela_comb
, (size_t) comb_count
, sizeof (int),
1785 /* Enumerate each EOP region that overlaps this section. */
1786 end_section
= isec
->vma
+ isec
->_cooked_size
;
1787 dot
= end_page
= (isec
->vma
| (PAGESIZE
- 1)) + 1;
1788 dot
-= link_info
->mpc860c0
;
1789 section_modified
= FALSE
;
1790 /* Increment the start position if this section begins in the
1791 middle of its first EOP region. */
1792 if (dot
< isec
->vma
)
1796 dot
+= PAGESIZE
, end_page
+= PAGESIZE
)
1798 /* Check each word in this EOP region. */
1799 for (; dot
< end_page
; dot
+= 4)
1801 bfd_vma isec_offset
;
1803 bfd_boolean skip
, modified
;
1805 /* Don't process this word if there is a relocation for it
1806 and the relocation indicates the word is not a
1807 conditional branch. */
1809 isec_offset
= dot
- isec
->vma
;
1810 for (; comb_curr
<comb_count
; ++comb_curr
)
1814 r_offset
= rela_comb
[comb_curr
]->r_offset
;
1815 if (r_offset
>= isec_offset
)
1817 if (r_offset
== isec_offset
) skip
= TRUE
;
1823 /* Check the current word for a problematic conditional
1825 #define BO0(insn) ((insn) & 0x02000000)
1826 #define BO2(insn) ((insn) & 0x00800000)
1827 #define BO4(insn) ((insn) & 0x00200000)
1828 insn
= (unsigned long) bfd_get_32 (abfd
, contents
+ isec_offset
);
1830 if ((insn
& 0xFc000000) == 0x40000000)
1832 /* Instruction is BCx */
1833 if ((!BO0(insn
) || !BO2(insn
)) && !BO4(insn
))
1837 /* This branch is predicted as "normal".
1838 If this is a forward branch, it is problematic. */
1839 target
= insn
& 0x0000Fffc;
1840 target
= (target
^ 0x8000) - 0x8000;
1841 if ((insn
& 0x00000002) == 0)
1842 /* Convert to abs. */
1846 /* Set the prediction bit. */
1852 else if ((insn
& 0xFc00Fffe) == 0x4c000420)
1854 /* Instruction is BCCTRx. */
1855 if ((!BO0(insn
) || !BO2(insn
)) && !BO4(insn
))
1857 /* This branch is predicted as not-taken.
1858 If this is a forward branch, it is problematic.
1859 Since we can't tell statically if it will branch
1860 forward, always set the prediction bit. */
1865 else if ((insn
& 0xFc00Fffe) == 0x4c000020)
1867 /* Instruction is BCLRx */
1868 if ((!BO0(insn
) || !BO2(insn
)) && !BO4(insn
))
1870 /* This branch is predicted as not-taken.
1871 If this is a forward branch, it is problematic.
1872 Since we can't tell statically if it will branch
1873 forward, always set the prediction bit. */
1883 bfd_put_32 (abfd
, (bfd_vma
) insn
, contents
+ isec_offset
);
1884 section_modified
= TRUE
;
1888 if (section_modified
)
1890 elf_section_data (isec
)->this_hdr
.contents
= contents
;
1891 free_contents
= NULL
;
1895 if (rela_comb
!= NULL
)
1901 if (free_relocs
!= NULL
)
1907 if (free_contents
!= NULL
)
1909 if (! link_info
->keep_memory
)
1910 free (free_contents
);
1913 /* Cache the section contents for elf_link_input_bfd. */
1914 elf_section_data (isec
)->this_hdr
.contents
= contents
;
1916 free_contents
= NULL
;
1922 if (rela_comb
!= NULL
)
1924 if (free_relocs
!= NULL
)
1926 if (free_contents
!= NULL
)
1927 free (free_contents
);
1931 static reloc_howto_type
*
1932 ppc_elf_reloc_type_lookup (abfd
, code
)
1933 bfd
*abfd ATTRIBUTE_UNUSED
;
1934 bfd_reloc_code_real_type code
;
1936 enum elf_ppc_reloc_type r
;
1938 if (!ppc_elf_howto_table
[R_PPC_ADDR32
])
1939 /* Initialize howto table if needed. */
1940 ppc_elf_howto_init ();
1945 return (reloc_howto_type
*) NULL
;
1947 case BFD_RELOC_NONE
: r
= R_PPC_NONE
; break;
1948 case BFD_RELOC_32
: r
= R_PPC_ADDR32
; break;
1949 case BFD_RELOC_PPC_BA26
: r
= R_PPC_ADDR24
; break;
1950 case BFD_RELOC_16
: r
= R_PPC_ADDR16
; break;
1951 case BFD_RELOC_LO16
: r
= R_PPC_ADDR16_LO
; break;
1952 case BFD_RELOC_HI16
: r
= R_PPC_ADDR16_HI
; break;
1953 case BFD_RELOC_HI16_S
: r
= R_PPC_ADDR16_HA
; break;
1954 case BFD_RELOC_PPC_BA16
: r
= R_PPC_ADDR14
; break;
1955 case BFD_RELOC_PPC_BA16_BRTAKEN
: r
= R_PPC_ADDR14_BRTAKEN
; break;
1956 case BFD_RELOC_PPC_BA16_BRNTAKEN
: r
= R_PPC_ADDR14_BRNTAKEN
; break;
1957 case BFD_RELOC_PPC_B26
: r
= R_PPC_REL24
; break;
1958 case BFD_RELOC_PPC_B16
: r
= R_PPC_REL14
; break;
1959 case BFD_RELOC_PPC_B16_BRTAKEN
: r
= R_PPC_REL14_BRTAKEN
; break;
1960 case BFD_RELOC_PPC_B16_BRNTAKEN
: r
= R_PPC_REL14_BRNTAKEN
; break;
1961 case BFD_RELOC_16_GOTOFF
: r
= R_PPC_GOT16
; break;
1962 case BFD_RELOC_LO16_GOTOFF
: r
= R_PPC_GOT16_LO
; break;
1963 case BFD_RELOC_HI16_GOTOFF
: r
= R_PPC_GOT16_HI
; break;
1964 case BFD_RELOC_HI16_S_GOTOFF
: r
= R_PPC_GOT16_HA
; break;
1965 case BFD_RELOC_24_PLT_PCREL
: r
= R_PPC_PLTREL24
; break;
1966 case BFD_RELOC_PPC_COPY
: r
= R_PPC_COPY
; break;
1967 case BFD_RELOC_PPC_GLOB_DAT
: r
= R_PPC_GLOB_DAT
; break;
1968 case BFD_RELOC_PPC_LOCAL24PC
: r
= R_PPC_LOCAL24PC
; break;
1969 case BFD_RELOC_32_PCREL
: r
= R_PPC_REL32
; break;
1970 case BFD_RELOC_32_PLTOFF
: r
= R_PPC_PLT32
; break;
1971 case BFD_RELOC_32_PLT_PCREL
: r
= R_PPC_PLTREL32
; break;
1972 case BFD_RELOC_LO16_PLTOFF
: r
= R_PPC_PLT16_LO
; break;
1973 case BFD_RELOC_HI16_PLTOFF
: r
= R_PPC_PLT16_HI
; break;
1974 case BFD_RELOC_HI16_S_PLTOFF
: r
= R_PPC_PLT16_HA
; break;
1975 case BFD_RELOC_GPREL16
: r
= R_PPC_SDAREL16
; break;
1976 case BFD_RELOC_16_BASEREL
: r
= R_PPC_SECTOFF
; break;
1977 case BFD_RELOC_LO16_BASEREL
: r
= R_PPC_SECTOFF_LO
; break;
1978 case BFD_RELOC_HI16_BASEREL
: r
= R_PPC_SECTOFF_HI
; break;
1979 case BFD_RELOC_HI16_S_BASEREL
: r
= R_PPC_SECTOFF_HA
; break;
1980 case BFD_RELOC_CTOR
: r
= R_PPC_ADDR32
; break;
1981 case BFD_RELOC_PPC_TOC16
: r
= R_PPC_TOC16
; break;
1982 case BFD_RELOC_PPC_TLS
: r
= R_PPC_TLS
; break;
1983 case BFD_RELOC_PPC_DTPMOD
: r
= R_PPC_DTPMOD32
; break;
1984 case BFD_RELOC_PPC_TPREL16
: r
= R_PPC_TPREL16
; break;
1985 case BFD_RELOC_PPC_TPREL16_LO
: r
= R_PPC_TPREL16_LO
; break;
1986 case BFD_RELOC_PPC_TPREL16_HI
: r
= R_PPC_TPREL16_HI
; break;
1987 case BFD_RELOC_PPC_TPREL16_HA
: r
= R_PPC_TPREL16_HA
; break;
1988 case BFD_RELOC_PPC_TPREL
: r
= R_PPC_TPREL32
; break;
1989 case BFD_RELOC_PPC_DTPREL16
: r
= R_PPC_DTPREL16
; break;
1990 case BFD_RELOC_PPC_DTPREL16_LO
: r
= R_PPC_DTPREL16_LO
; break;
1991 case BFD_RELOC_PPC_DTPREL16_HI
: r
= R_PPC_DTPREL16_HI
; break;
1992 case BFD_RELOC_PPC_DTPREL16_HA
: r
= R_PPC_DTPREL16_HA
; break;
1993 case BFD_RELOC_PPC_DTPREL
: r
= R_PPC_DTPREL32
; break;
1994 case BFD_RELOC_PPC_GOT_TLSGD16
: r
= R_PPC_GOT_TLSGD16
; break;
1995 case BFD_RELOC_PPC_GOT_TLSGD16_LO
: r
= R_PPC_GOT_TLSGD16_LO
; break;
1996 case BFD_RELOC_PPC_GOT_TLSGD16_HI
: r
= R_PPC_GOT_TLSGD16_HI
; break;
1997 case BFD_RELOC_PPC_GOT_TLSGD16_HA
: r
= R_PPC_GOT_TLSGD16_HA
; break;
1998 case BFD_RELOC_PPC_GOT_TLSLD16
: r
= R_PPC_GOT_TLSLD16
; break;
1999 case BFD_RELOC_PPC_GOT_TLSLD16_LO
: r
= R_PPC_GOT_TLSLD16_LO
; break;
2000 case BFD_RELOC_PPC_GOT_TLSLD16_HI
: r
= R_PPC_GOT_TLSLD16_HI
; break;
2001 case BFD_RELOC_PPC_GOT_TLSLD16_HA
: r
= R_PPC_GOT_TLSLD16_HA
; break;
2002 case BFD_RELOC_PPC_GOT_TPREL16
: r
= R_PPC_GOT_TPREL16
; break;
2003 case BFD_RELOC_PPC_GOT_TPREL16_LO
: r
= R_PPC_GOT_TPREL16_LO
; break;
2004 case BFD_RELOC_PPC_GOT_TPREL16_HI
: r
= R_PPC_GOT_TPREL16_HI
; break;
2005 case BFD_RELOC_PPC_GOT_TPREL16_HA
: r
= R_PPC_GOT_TPREL16_HA
; break;
2006 case BFD_RELOC_PPC_GOT_DTPREL16
: r
= R_PPC_GOT_DTPREL16
; break;
2007 case BFD_RELOC_PPC_GOT_DTPREL16_LO
: r
= R_PPC_GOT_DTPREL16_LO
; break;
2008 case BFD_RELOC_PPC_GOT_DTPREL16_HI
: r
= R_PPC_GOT_DTPREL16_HI
; break;
2009 case BFD_RELOC_PPC_GOT_DTPREL16_HA
: r
= R_PPC_GOT_DTPREL16_HA
; break;
2010 case BFD_RELOC_PPC_EMB_NADDR32
: r
= R_PPC_EMB_NADDR32
; break;
2011 case BFD_RELOC_PPC_EMB_NADDR16
: r
= R_PPC_EMB_NADDR16
; break;
2012 case BFD_RELOC_PPC_EMB_NADDR16_LO
: r
= R_PPC_EMB_NADDR16_LO
; break;
2013 case BFD_RELOC_PPC_EMB_NADDR16_HI
: r
= R_PPC_EMB_NADDR16_HI
; break;
2014 case BFD_RELOC_PPC_EMB_NADDR16_HA
: r
= R_PPC_EMB_NADDR16_HA
; break;
2015 case BFD_RELOC_PPC_EMB_SDAI16
: r
= R_PPC_EMB_SDAI16
; break;
2016 case BFD_RELOC_PPC_EMB_SDA2I16
: r
= R_PPC_EMB_SDA2I16
; break;
2017 case BFD_RELOC_PPC_EMB_SDA2REL
: r
= R_PPC_EMB_SDA2REL
; break;
2018 case BFD_RELOC_PPC_EMB_SDA21
: r
= R_PPC_EMB_SDA21
; break;
2019 case BFD_RELOC_PPC_EMB_MRKREF
: r
= R_PPC_EMB_MRKREF
; break;
2020 case BFD_RELOC_PPC_EMB_RELSEC16
: r
= R_PPC_EMB_RELSEC16
; break;
2021 case BFD_RELOC_PPC_EMB_RELST_LO
: r
= R_PPC_EMB_RELST_LO
; break;
2022 case BFD_RELOC_PPC_EMB_RELST_HI
: r
= R_PPC_EMB_RELST_HI
; break;
2023 case BFD_RELOC_PPC_EMB_RELST_HA
: r
= R_PPC_EMB_RELST_HA
; break;
2024 case BFD_RELOC_PPC_EMB_BIT_FLD
: r
= R_PPC_EMB_BIT_FLD
; break;
2025 case BFD_RELOC_PPC_EMB_RELSDA
: r
= R_PPC_EMB_RELSDA
; break;
2026 case BFD_RELOC_VTABLE_INHERIT
: r
= R_PPC_GNU_VTINHERIT
; break;
2027 case BFD_RELOC_VTABLE_ENTRY
: r
= R_PPC_GNU_VTENTRY
; break;
2030 return ppc_elf_howto_table
[(int) r
];
2033 /* Set the howto pointer for a PowerPC ELF reloc. */
2036 ppc_elf_info_to_howto (abfd
, cache_ptr
, dst
)
2037 bfd
*abfd ATTRIBUTE_UNUSED
;
2039 Elf_Internal_Rela
*dst
;
2041 if (!ppc_elf_howto_table
[R_PPC_ADDR32
])
2042 /* Initialize howto table if needed. */
2043 ppc_elf_howto_init ();
2045 BFD_ASSERT (ELF32_R_TYPE (dst
->r_info
) < (unsigned int) R_PPC_max
);
2046 cache_ptr
->howto
= ppc_elf_howto_table
[ELF32_R_TYPE (dst
->r_info
)];
2049 /* Handle the R_PPC_ADDR16_HA reloc. */
2051 static bfd_reloc_status_type
2052 ppc_elf_addr16_ha_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
2053 output_bfd
, error_message
)
2054 bfd
*abfd ATTRIBUTE_UNUSED
;
2055 arelent
*reloc_entry
;
2057 PTR data ATTRIBUTE_UNUSED
;
2058 asection
*input_section
;
2060 char **error_message ATTRIBUTE_UNUSED
;
2064 if (output_bfd
!= NULL
)
2066 reloc_entry
->address
+= input_section
->output_offset
;
2067 return bfd_reloc_ok
;
2070 if (reloc_entry
->address
> input_section
->_cooked_size
)
2071 return bfd_reloc_outofrange
;
2073 if (bfd_is_com_section (symbol
->section
))
2076 relocation
= symbol
->value
;
2078 relocation
+= symbol
->section
->output_section
->vma
;
2079 relocation
+= symbol
->section
->output_offset
;
2080 relocation
+= reloc_entry
->addend
;
2082 reloc_entry
->addend
+= (relocation
& 0x8000) << 1;
2084 return bfd_reloc_continue
;
2087 static bfd_reloc_status_type
2088 ppc_elf_unhandled_reloc (abfd
, reloc_entry
, symbol
, data
,
2089 input_section
, output_bfd
, error_message
)
2091 arelent
*reloc_entry
;
2094 asection
*input_section
;
2096 char **error_message
;
2098 /* If this is a relocatable link (output_bfd test tells us), just
2099 call the generic function. Any adjustment will be done at final
2101 if (output_bfd
!= NULL
)
2102 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2103 input_section
, output_bfd
, error_message
);
2105 if (error_message
!= NULL
)
2107 static char buf
[60];
2108 sprintf (buf
, "generic linker can't handle %s",
2109 reloc_entry
->howto
->name
);
2110 *error_message
= buf
;
2112 return bfd_reloc_dangerous
;
2115 /* Fix bad default arch selected for a 32 bit input bfd when the
2116 default is 64 bit. */
2119 ppc_elf_object_p (abfd
)
2122 if (abfd
->arch_info
->the_default
&& abfd
->arch_info
->bits_per_word
== 64)
2124 Elf_Internal_Ehdr
*i_ehdr
= elf_elfheader (abfd
);
2126 if (i_ehdr
->e_ident
[EI_CLASS
] == ELFCLASS32
)
2128 /* Relies on arch after 64 bit default being 32 bit default. */
2129 abfd
->arch_info
= abfd
->arch_info
->next
;
2130 BFD_ASSERT (abfd
->arch_info
->bits_per_word
== 32);
2136 /* Function to set whether a module needs the -mrelocatable bit set. */
2139 ppc_elf_set_private_flags (abfd
, flags
)
2143 BFD_ASSERT (!elf_flags_init (abfd
)
2144 || elf_elfheader (abfd
)->e_flags
== flags
);
2146 elf_elfheader (abfd
)->e_flags
= flags
;
2147 elf_flags_init (abfd
) = TRUE
;
2151 /* Merge backend specific data from an object file to the output
2152 object file when linking. */
2155 ppc_elf_merge_private_bfd_data (ibfd
, obfd
)
2163 /* Check if we have the same endianess. */
2164 if (! _bfd_generic_verify_endian_match (ibfd
, obfd
))
2167 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
2168 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
2171 new_flags
= elf_elfheader (ibfd
)->e_flags
;
2172 old_flags
= elf_elfheader (obfd
)->e_flags
;
2173 if (!elf_flags_init (obfd
))
2175 /* First call, no flags set. */
2176 elf_flags_init (obfd
) = TRUE
;
2177 elf_elfheader (obfd
)->e_flags
= new_flags
;
2180 /* Compatible flags are ok. */
2181 else if (new_flags
== old_flags
)
2184 /* Incompatible flags. */
2187 /* Warn about -mrelocatable mismatch. Allow -mrelocatable-lib
2188 to be linked with either. */
2190 if ((new_flags
& EF_PPC_RELOCATABLE
) != 0
2191 && (old_flags
& (EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
)) == 0)
2194 (*_bfd_error_handler
)
2195 (_("%s: compiled with -mrelocatable and linked with modules compiled normally"),
2196 bfd_archive_filename (ibfd
));
2198 else if ((new_flags
& (EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
)) == 0
2199 && (old_flags
& EF_PPC_RELOCATABLE
) != 0)
2202 (*_bfd_error_handler
)
2203 (_("%s: compiled normally and linked with modules compiled with -mrelocatable"),
2204 bfd_archive_filename (ibfd
));
2207 /* The output is -mrelocatable-lib iff both the input files are. */
2208 if (! (new_flags
& EF_PPC_RELOCATABLE_LIB
))
2209 elf_elfheader (obfd
)->e_flags
&= ~EF_PPC_RELOCATABLE_LIB
;
2211 /* The output is -mrelocatable iff it can't be -mrelocatable-lib,
2212 but each input file is either -mrelocatable or -mrelocatable-lib. */
2213 if (! (elf_elfheader (obfd
)->e_flags
& EF_PPC_RELOCATABLE_LIB
)
2214 && (new_flags
& (EF_PPC_RELOCATABLE_LIB
| EF_PPC_RELOCATABLE
))
2215 && (old_flags
& (EF_PPC_RELOCATABLE_LIB
| EF_PPC_RELOCATABLE
)))
2216 elf_elfheader (obfd
)->e_flags
|= EF_PPC_RELOCATABLE
;
2218 /* Do not warn about eabi vs. V.4 mismatch, just or in the bit if
2219 any module uses it. */
2220 elf_elfheader (obfd
)->e_flags
|= (new_flags
& EF_PPC_EMB
);
2222 new_flags
&= ~(EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
| EF_PPC_EMB
);
2223 old_flags
&= ~(EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
| EF_PPC_EMB
);
2225 /* Warn about any other mismatches. */
2226 if (new_flags
!= old_flags
)
2229 (*_bfd_error_handler
)
2230 (_("%s: uses different e_flags (0x%lx) fields than previous modules (0x%lx)"),
2231 bfd_archive_filename (ibfd
), (long) new_flags
, (long) old_flags
);
2236 bfd_set_error (bfd_error_bad_value
);
2244 /* Handle a PowerPC specific section when reading an object file. This
2245 is called when elfcode.h finds a section with an unknown type. */
2248 ppc_elf_section_from_shdr (abfd
, hdr
, name
)
2250 Elf_Internal_Shdr
*hdr
;
2256 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
))
2259 newsect
= hdr
->bfd_section
;
2260 flags
= bfd_get_section_flags (abfd
, newsect
);
2261 if (hdr
->sh_flags
& SHF_EXCLUDE
)
2262 flags
|= SEC_EXCLUDE
;
2264 if (hdr
->sh_type
== SHT_ORDERED
)
2265 flags
|= SEC_SORT_ENTRIES
;
2267 bfd_set_section_flags (abfd
, newsect
, flags
);
2271 /* Set up any other section flags and such that may be necessary. */
2274 ppc_elf_fake_sections (abfd
, shdr
, asect
)
2275 bfd
*abfd ATTRIBUTE_UNUSED
;
2276 Elf_Internal_Shdr
*shdr
;
2279 if ((asect
->flags
& SEC_EXCLUDE
) != 0)
2280 shdr
->sh_flags
|= SHF_EXCLUDE
;
2282 if ((asect
->flags
& SEC_SORT_ENTRIES
) != 0)
2283 shdr
->sh_type
= SHT_ORDERED
;
2288 /* Create a special linker section */
2289 static elf_linker_section_t
*
2290 ppc_elf_create_linker_section (abfd
, info
, which
)
2292 struct bfd_link_info
*info
;
2293 enum elf_linker_section_enum which
;
2295 bfd
*dynobj
= elf_hash_table (info
)->dynobj
;
2296 elf_linker_section_t
*lsect
;
2298 /* Record the first bfd section that needs the special section. */
2300 dynobj
= elf_hash_table (info
)->dynobj
= abfd
;
2302 /* If this is the first time, create the section. */
2303 lsect
= elf_linker_section (dynobj
, which
);
2306 elf_linker_section_t defaults
;
2307 static elf_linker_section_t zero_section
;
2309 defaults
= zero_section
;
2310 defaults
.which
= which
;
2311 defaults
.hole_written_p
= FALSE
;
2312 defaults
.alignment
= 2;
2314 /* Both of these sections are (technically) created by the user
2315 putting data in them, so they shouldn't be marked
2318 The linker creates them so it has somewhere to attach their
2319 respective symbols. In fact, if they were empty it would
2320 be OK to leave the symbol set to 0 (or any random number), because
2321 the appropriate register should never be used. */
2322 defaults
.flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
2328 (*_bfd_error_handler
) (_("%s: unknown special linker type %d"),
2329 bfd_get_filename (abfd
),
2332 bfd_set_error (bfd_error_bad_value
);
2333 return (elf_linker_section_t
*) 0;
2335 case LINKER_SECTION_SDATA
: /* .sdata/.sbss section */
2336 defaults
.name
= ".sdata";
2337 defaults
.rel_name
= ".rela.sdata";
2338 defaults
.bss_name
= ".sbss";
2339 defaults
.sym_name
= "_SDA_BASE_";
2340 defaults
.sym_offset
= 32768;
2343 case LINKER_SECTION_SDATA2
: /* .sdata2/.sbss2 section */
2344 defaults
.name
= ".sdata2";
2345 defaults
.rel_name
= ".rela.sdata2";
2346 defaults
.bss_name
= ".sbss2";
2347 defaults
.sym_name
= "_SDA2_BASE_";
2348 defaults
.sym_offset
= 32768;
2349 defaults
.flags
|= SEC_READONLY
;
2353 lsect
= _bfd_elf_create_linker_section (abfd
, info
, which
, &defaults
);
2359 /* If we have a non-zero sized .sbss2 or .PPC.EMB.sbss0 sections, we
2360 need to bump up the number of section headers. */
2363 ppc_elf_additional_program_headers (abfd
)
2371 s
= bfd_get_section_by_name (abfd
, ".interp");
2375 s
= bfd_get_section_by_name (abfd
, ".sbss2");
2376 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0 && s
->_raw_size
> 0)
2379 s
= bfd_get_section_by_name (abfd
, ".PPC.EMB.sbss0");
2380 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0 && s
->_raw_size
> 0)
2386 /* Modify the segment map if needed. */
2389 ppc_elf_modify_segment_map (abfd
)
2390 bfd
*abfd ATTRIBUTE_UNUSED
;
2395 /* The powerpc .got has a blrl instruction in it. Mark it executable. */
2398 ppc_elf_create_got (abfd
, info
)
2400 struct bfd_link_info
*info
;
2402 struct ppc_elf_link_hash_table
*htab
;
2406 if (!_bfd_elf_create_got_section (abfd
, info
))
2409 htab
= ppc_elf_hash_table (info
);
2410 htab
->got
= s
= bfd_get_section_by_name (abfd
, ".got");
2414 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_CODE
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
2415 | SEC_LINKER_CREATED
);
2416 if (!bfd_set_section_flags (abfd
, s
, flags
))
2419 htab
->relgot
= bfd_make_section (abfd
, ".rela.got");
2421 || ! bfd_set_section_flags (abfd
, htab
->relgot
,
2422 (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
2423 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
2425 || ! bfd_set_section_alignment (abfd
, htab
->relgot
, 2))
2431 /* We have to create .dynsbss and .rela.sbss here so that they get mapped
2432 to output sections (just like _bfd_elf_create_dynamic_sections has
2433 to create .dynbss and .rela.bss). */
2436 ppc_elf_create_dynamic_sections (abfd
, info
)
2438 struct bfd_link_info
*info
;
2440 struct ppc_elf_link_hash_table
*htab
;
2444 if (!ppc_elf_create_got (abfd
, info
))
2447 if (!_bfd_elf_create_dynamic_sections (abfd
, info
))
2450 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
2451 | SEC_LINKER_CREATED
);
2453 htab
= ppc_elf_hash_table (info
);
2454 htab
->dynbss
= bfd_get_section_by_name (abfd
, ".dynbss");
2455 htab
->dynsbss
= s
= bfd_make_section (abfd
, ".dynsbss");
2457 || ! bfd_set_section_flags (abfd
, s
, SEC_ALLOC
))
2462 htab
->relbss
= bfd_get_section_by_name (abfd
, ".rela.bss");
2463 htab
->relsbss
= s
= bfd_make_section (abfd
, ".rela.sbss");
2465 || ! bfd_set_section_flags (abfd
, s
, flags
| SEC_READONLY
)
2466 || ! bfd_set_section_alignment (abfd
, s
, 2))
2470 htab
->relplt
= bfd_get_section_by_name (abfd
, ".rela.plt");
2471 htab
->plt
= s
= bfd_get_section_by_name (abfd
, ".plt");
2475 flags
= SEC_ALLOC
| SEC_CODE
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
;
2476 return bfd_set_section_flags (abfd
, s
, flags
);
2479 /* Adjust a symbol defined by a dynamic object and referenced by a
2480 regular object. The current definition is in some section of the
2481 dynamic object, but we're not including those sections. We have to
2482 change the definition to something the rest of the link can
2486 ppc_elf_adjust_dynamic_symbol (info
, h
)
2487 struct bfd_link_info
*info
;
2488 struct elf_link_hash_entry
*h
;
2490 struct ppc_elf_link_hash_table
*htab
;
2492 unsigned int power_of_two
;
2495 fprintf (stderr
, "ppc_elf_adjust_dynamic_symbol called for %s\n",
2496 h
->root
.root
.string
);
2499 /* Make sure we know what is going on here. */
2500 htab
= ppc_elf_hash_table (info
);
2501 BFD_ASSERT (htab
->elf
.dynobj
!= NULL
2502 && ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
)
2503 || h
->weakdef
!= NULL
2504 || ((h
->elf_link_hash_flags
2505 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0
2506 && (h
->elf_link_hash_flags
2507 & ELF_LINK_HASH_REF_REGULAR
) != 0
2508 && (h
->elf_link_hash_flags
2509 & ELF_LINK_HASH_DEF_REGULAR
) == 0)));
2511 /* Deal with function syms. */
2512 if (h
->type
== STT_FUNC
2513 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
2515 /* Clear procedure linkage table information for any symbol that
2516 won't need a .plt entry. */
2517 if (! htab
->elf
.dynamic_sections_created
2518 || SYMBOL_CALLS_LOCAL (info
, h
)
2519 || h
->plt
.refcount
<= 0)
2521 /* A PLT entry is not required/allowed when:
2523 1. We are not using ld.so; because then the PLT entry
2524 can't be set up, so we can't use one.
2526 2. We know for certain that a call to this symbol
2527 will go to this object.
2529 3. GC has rendered the entry unused. */
2530 h
->plt
.offset
= (bfd_vma
) -1;
2531 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
2536 h
->plt
.offset
= (bfd_vma
) -1;
2538 /* If this is a weak symbol, and there is a real definition, the
2539 processor independent code will have arranged for us to see the
2540 real definition first, and we can just use the same value. */
2541 if (h
->weakdef
!= NULL
)
2543 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
2544 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
2545 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
2546 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
2547 if (ELIMINATE_COPY_RELOCS
)
2548 h
->elf_link_hash_flags
2549 = ((h
->elf_link_hash_flags
& ~ELF_LINK_NON_GOT_REF
)
2550 | (h
->weakdef
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
));
2554 /* This is a reference to a symbol defined by a dynamic object which
2555 is not a function. */
2557 /* If we are creating a shared library, we must presume that the
2558 only references to the symbol are via the global offset table.
2559 For such cases we need not do anything here; the relocations will
2560 be handled correctly by relocate_section. */
2564 /* If there are no references to this symbol that do not use the
2565 GOT, we don't need to generate a copy reloc. */
2566 if ((h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0)
2569 if (ELIMINATE_COPY_RELOCS
)
2571 struct ppc_elf_dyn_relocs
*p
;
2572 for (p
= ppc_elf_hash_entry (h
)->dyn_relocs
; p
!= NULL
; p
= p
->next
)
2574 s
= p
->sec
->output_section
;
2575 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
2579 /* If we didn't find any dynamic relocs in read-only sections, then
2580 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
2583 h
->elf_link_hash_flags
&= ~ELF_LINK_NON_GOT_REF
;
2588 /* We must allocate the symbol in our .dynbss section, which will
2589 become part of the .bss section of the executable. There will be
2590 an entry for this symbol in the .dynsym section. The dynamic
2591 object will contain position independent code, so all references
2592 from the dynamic object to this symbol will go through the global
2593 offset table. The dynamic linker will use the .dynsym entry to
2594 determine the address it must put in the global offset table, so
2595 both the dynamic object and the regular object will refer to the
2596 same memory location for the variable.
2598 Of course, if the symbol is sufficiently small, we must instead
2599 allocate it in .sbss. FIXME: It would be better to do this if and
2600 only if there were actually SDAREL relocs for that symbol. */
2602 if (h
->size
<= elf_gp_size (htab
->elf
.dynobj
))
2606 BFD_ASSERT (s
!= NULL
);
2608 /* We must generate a R_PPC_COPY reloc to tell the dynamic linker to
2609 copy the initial value out of the dynamic object and into the
2610 runtime process image. We need to remember the offset into the
2611 .rela.bss section we are going to use. */
2612 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
2616 if (h
->size
<= elf_gp_size (htab
->elf
.dynobj
))
2617 srel
= htab
->relsbss
;
2619 srel
= htab
->relbss
;
2620 BFD_ASSERT (srel
!= NULL
);
2621 srel
->_raw_size
+= sizeof (Elf32_External_Rela
);
2622 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_COPY
;
2625 /* We need to figure out the alignment required for this symbol. I
2626 have no idea how ELF linkers handle this. */
2627 power_of_two
= bfd_log2 (h
->size
);
2628 if (power_of_two
> 4)
2631 /* Apply the required alignment. */
2632 s
->_raw_size
= BFD_ALIGN (s
->_raw_size
,
2633 (bfd_size_type
) (1 << power_of_two
));
2634 if (power_of_two
> bfd_get_section_alignment (htab
->elf
.dynobj
, s
))
2636 if (! bfd_set_section_alignment (htab
->elf
.dynobj
, s
, power_of_two
))
2640 /* Define the symbol as being at this point in the section. */
2641 h
->root
.u
.def
.section
= s
;
2642 h
->root
.u
.def
.value
= s
->_raw_size
;
2644 /* Increment the section size to make room for the symbol. */
2645 s
->_raw_size
+= h
->size
;
2650 /* This is the condition under which finish_dynamic_symbol will be
2651 called from elflink.h. If elflink.h doesn't call our
2652 finish_dynamic_symbol routine, we'll need to do something about
2653 initializing any .plt and .got entries in relocate_section. */
2654 #define WILL_CALL_FINISH_DYNAMIC_SYMBOL(DYN, SHARED, H) \
2657 || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) \
2658 && ((H)->dynindx != -1 \
2659 || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0))
2661 /* Of those relocs that might be copied as dynamic relocs, this macro
2662 selects those that must be copied when linking a shared library,
2663 even when the symbol is local. */
2665 #define MUST_BE_DYN_RELOC(RTYPE) \
2666 ((RTYPE) != R_PPC_REL24 \
2667 && (RTYPE) != R_PPC_REL14 \
2668 && (RTYPE) != R_PPC_REL14_BRTAKEN \
2669 && (RTYPE) != R_PPC_REL14_BRNTAKEN \
2670 && (RTYPE) != R_PPC_REL32)
2672 /* Allocate space in associated reloc sections for dynamic relocs. */
2675 allocate_dynrelocs (h
, inf
)
2676 struct elf_link_hash_entry
*h
;
2679 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
2680 struct ppc_elf_link_hash_entry
*eh
;
2681 struct ppc_elf_link_hash_table
*htab
;
2682 struct ppc_elf_dyn_relocs
*p
;
2684 if (h
->root
.type
== bfd_link_hash_indirect
)
2687 if (h
->root
.type
== bfd_link_hash_warning
)
2688 /* When warning symbols are created, they **replace** the "real"
2689 entry in the hash table, thus we never get to see the real
2690 symbol in a hash traversal. So look at it now. */
2691 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2693 htab
= ppc_elf_hash_table (info
);
2694 if (htab
->elf
.dynamic_sections_created
2695 && h
->plt
.refcount
> 0)
2697 /* Make sure this symbol is output as a dynamic symbol. */
2698 if (h
->dynindx
== -1
2699 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
2701 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
2706 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h
))
2708 asection
*s
= htab
->plt
;
2710 /* If this is the first .plt entry, make room for the special
2712 if (s
->_raw_size
== 0)
2713 s
->_raw_size
+= PLT_INITIAL_ENTRY_SIZE
;
2715 /* The PowerPC PLT is actually composed of two parts, the
2716 first part is 2 words (for a load and a jump), and then
2717 there is a remaining word available at the end. */
2718 h
->plt
.offset
= (PLT_INITIAL_ENTRY_SIZE
2720 * ((s
->_raw_size
- PLT_INITIAL_ENTRY_SIZE
)
2721 / PLT_ENTRY_SIZE
)));
2723 /* If this symbol is not defined in a regular file, and we
2724 are not generating a shared library, then set the symbol
2725 to this location in the .plt. This is required to make
2726 function pointers compare as equal between the normal
2727 executable and the shared library. */
2729 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
2731 h
->root
.u
.def
.section
= s
;
2732 h
->root
.u
.def
.value
= h
->plt
.offset
;
2735 /* Make room for this entry. After the 8192nd entry, room
2736 for two entries is allocated. */
2737 s
->_raw_size
+= PLT_ENTRY_SIZE
;
2738 if ((s
->_raw_size
- PLT_INITIAL_ENTRY_SIZE
) / PLT_ENTRY_SIZE
2739 >= PLT_NUM_SINGLE_ENTRIES
)
2740 s
->_raw_size
+= PLT_ENTRY_SIZE
;
2742 /* We also need to make an entry in the .rela.plt section. */
2743 htab
->relplt
->_raw_size
+= sizeof (Elf32_External_Rela
);
2747 h
->plt
.offset
= (bfd_vma
) -1;
2748 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
2753 h
->plt
.offset
= (bfd_vma
) -1;
2754 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
2757 eh
= (struct ppc_elf_link_hash_entry
*) h
;
2758 if (eh
->elf
.got
.refcount
> 0)
2760 /* Make sure this symbol is output as a dynamic symbol. */
2761 if (eh
->elf
.dynindx
== -1
2762 && (eh
->elf
.elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
2764 if (!bfd_elf32_link_record_dynamic_symbol (info
, &eh
->elf
))
2768 if (eh
->tls_mask
== (TLS_TLS
| TLS_LD
)
2769 && !(eh
->elf
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
))
2770 /* If just an LD reloc, we'll just use htab->tlsld_got.offset. */
2771 eh
->elf
.got
.offset
= (bfd_vma
) -1;
2775 eh
->elf
.got
.offset
= htab
->got
->_raw_size
;
2776 if ((eh
->tls_mask
& TLS_TLS
) != 0)
2778 if ((eh
->tls_mask
& TLS_LD
) != 0)
2779 htab
->got
->_raw_size
+= 8;
2780 if ((eh
->tls_mask
& TLS_GD
) != 0)
2781 htab
->got
->_raw_size
+= 8;
2782 if ((eh
->tls_mask
& (TLS_TPREL
| TLS_TPRELGD
)) != 0)
2783 htab
->got
->_raw_size
+= 4;
2784 if ((eh
->tls_mask
& TLS_DTPREL
) != 0)
2785 htab
->got
->_raw_size
+= 4;
2788 htab
->got
->_raw_size
+= 4;
2789 dyn
= htab
->elf
.dynamic_sections_created
;
2791 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, &eh
->elf
))
2793 /* All the entries we allocated need relocs. */
2794 htab
->relgot
->_raw_size
2795 += ((htab
->got
->_raw_size
- eh
->elf
.got
.offset
) / 4
2796 * sizeof (Elf32_External_Rela
));
2797 /* Except LD only needs one. */
2798 if ((eh
->tls_mask
& TLS_LD
) != 0)
2799 htab
->relgot
->_raw_size
-= sizeof (Elf32_External_Rela
);
2804 eh
->elf
.got
.offset
= (bfd_vma
) -1;
2806 if (eh
->dyn_relocs
== NULL
)
2809 /* In the shared -Bsymbolic case, discard space allocated for
2810 dynamic pc-relative relocs against symbols which turn out to be
2811 defined in regular objects. For the normal shared case, discard
2812 space for relocs that have become local due to symbol visibility
2816 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) != 0
2817 && ((h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) != 0
2820 struct ppc_elf_dyn_relocs
**pp
;
2822 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
2824 p
->count
-= p
->pc_count
;
2833 else if (ELIMINATE_COPY_RELOCS
)
2835 /* For the non-shared case, discard space for relocs against
2836 symbols which turn out to need copy relocs or are not
2839 if ((h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0
2840 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
2841 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
2843 /* Make sure this symbol is output as a dynamic symbol.
2844 Undefined weak syms won't yet be marked as dynamic. */
2845 if (h
->dynindx
== -1
2846 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
2848 if (! bfd_elf64_link_record_dynamic_symbol (info
, h
))
2852 /* If that succeeded, we know we'll be keeping all the
2854 if (h
->dynindx
!= -1)
2858 eh
->dyn_relocs
= NULL
;
2863 /* Finally, allocate space. */
2864 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
2866 asection
*sreloc
= elf_section_data (p
->sec
)->sreloc
;
2867 sreloc
->_raw_size
+= p
->count
* sizeof (Elf32_External_Rela
);
2873 /* Find any dynamic relocs that apply to read-only sections. */
2876 readonly_dynrelocs (h
, info
)
2877 struct elf_link_hash_entry
*h
;
2880 struct ppc_elf_dyn_relocs
*p
;
2882 if (h
->root
.type
== bfd_link_hash_indirect
)
2885 if (h
->root
.type
== bfd_link_hash_warning
)
2886 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2888 for (p
= ppc_elf_hash_entry (h
)->dyn_relocs
; p
!= NULL
; p
= p
->next
)
2890 asection
*s
= p
->sec
->output_section
;
2893 && ((s
->flags
& (SEC_READONLY
| SEC_ALLOC
))
2894 == (SEC_READONLY
| SEC_ALLOC
)))
2896 ((struct bfd_link_info
*) info
)->flags
|= DF_TEXTREL
;
2898 /* Not an error, just cut short the traversal. */
2905 /* Set the sizes of the dynamic sections. */
2908 ppc_elf_size_dynamic_sections (output_bfd
, info
)
2909 bfd
*output_bfd ATTRIBUTE_UNUSED
;
2910 struct bfd_link_info
*info
;
2912 struct ppc_elf_link_hash_table
*htab
;
2918 fprintf (stderr
, "ppc_elf_size_dynamic_sections called\n");
2921 htab
= ppc_elf_hash_table (info
);
2922 BFD_ASSERT (htab
->elf
.dynobj
!= NULL
);
2924 if (elf_hash_table (info
)->dynamic_sections_created
)
2926 /* Set the contents of the .interp section to the interpreter. */
2929 s
= bfd_get_section_by_name (htab
->elf
.dynobj
, ".interp");
2930 BFD_ASSERT (s
!= NULL
);
2931 s
->_raw_size
= sizeof ELF_DYNAMIC_INTERPRETER
;
2932 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
2936 if (htab
->tlsld_got
.refcount
> 0)
2938 htab
->tlsld_got
.offset
= htab
->got
->_raw_size
;
2939 htab
->got
->_raw_size
+= 8;
2941 htab
->relgot
->_raw_size
+= sizeof (Elf32_External_Rela
);
2944 htab
->tlsld_got
.offset
= (bfd_vma
) -1;
2946 /* Set up .got offsets for local syms, and space for local dynamic
2948 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
2950 bfd_signed_vma
*local_got
;
2951 bfd_signed_vma
*end_local_got
;
2953 bfd_size_type locsymcount
;
2954 Elf_Internal_Shdr
*symtab_hdr
;
2957 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
)
2960 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
2962 struct ppc_elf_dyn_relocs
*p
;
2964 for (p
= ((struct ppc_elf_dyn_relocs
*)
2965 elf_section_data (s
)->local_dynrel
);
2969 if (!bfd_is_abs_section (p
->sec
)
2970 && bfd_is_abs_section (p
->sec
->output_section
))
2972 /* Input section has been discarded, either because
2973 it is a copy of a linkonce section or due to
2974 linker script /DISCARD/, so we'll be discarding
2977 else if (p
->count
!= 0)
2979 elf_section_data (p
->sec
)->sreloc
->_raw_size
2980 += p
->count
* sizeof (Elf32_External_Rela
);
2981 if ((p
->sec
->output_section
->flags
2982 & (SEC_READONLY
| SEC_ALLOC
))
2983 == (SEC_READONLY
| SEC_ALLOC
))
2984 info
->flags
|= DF_TEXTREL
;
2989 local_got
= elf_local_got_refcounts (ibfd
);
2993 symtab_hdr
= &elf_tdata (ibfd
)->symtab_hdr
;
2994 locsymcount
= symtab_hdr
->sh_info
;
2995 end_local_got
= local_got
+ locsymcount
;
2996 lgot_masks
= (char *) end_local_got
;
2998 srel
= htab
->relgot
;
2999 for (; local_got
< end_local_got
; ++local_got
, ++lgot_masks
)
3002 if (*lgot_masks
== (TLS_TLS
| TLS_LD
))
3004 /* If just an LD reloc, we'll just use
3005 htab->tlsld_got.offset. */
3006 if (htab
->tlsld_got
.offset
== (bfd_vma
) -1)
3008 htab
->tlsld_got
.offset
= s
->_raw_size
;
3011 srel
->_raw_size
+= sizeof (Elf32_External_Rela
);
3013 *local_got
= (bfd_vma
) -1;
3017 *local_got
= s
->_raw_size
;
3018 if ((*lgot_masks
& TLS_TLS
) != 0)
3020 if ((*lgot_masks
& TLS_GD
) != 0)
3022 if ((*lgot_masks
& (TLS_TPREL
| TLS_TPRELGD
)) != 0)
3024 if ((*lgot_masks
& TLS_DTPREL
) != 0)
3030 srel
->_raw_size
+= ((s
->_raw_size
- *local_got
) / 4
3031 * sizeof (Elf32_External_Rela
));
3035 *local_got
= (bfd_vma
) -1;
3038 /* Allocate space for global sym dynamic relocs. */
3039 elf_link_hash_traverse (elf_hash_table (info
), allocate_dynrelocs
, info
);
3041 /* We've now determined the sizes of the various dynamic sections.
3042 Allocate memory for them. */
3044 for (s
= htab
->elf
.dynobj
->sections
; s
!= NULL
; s
= s
->next
)
3046 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
3051 || (htab
->sdata
!= NULL
&& s
== htab
->sdata
->section
)
3052 || (htab
->sdata2
!= NULL
&& s
== htab
->sdata2
->section
))
3054 /* Strip this section if we don't need it; see the
3057 else if (strncmp (bfd_get_section_name (dynobj
, s
), ".rela", 5) == 0)
3059 if (s
->_raw_size
== 0)
3061 /* If we don't need this section, strip it from the
3062 output file. This is mostly to handle .rela.bss and
3063 .rela.plt. We must create both sections in
3064 create_dynamic_sections, because they must be created
3065 before the linker maps input sections to output
3066 sections. The linker does that before
3067 adjust_dynamic_symbol is called, and it is that
3068 function which decides whether anything needs to go
3069 into these sections. */
3073 /* Remember whether there are any relocation sections. */
3076 /* We use the reloc_count field as a counter if we need
3077 to copy relocs into the output file. */
3083 /* It's not one of our sections, so don't allocate space. */
3087 if (s
->_raw_size
== 0)
3089 _bfd_strip_section_from_output (info
, s
);
3093 /* Allocate memory for the section contents. */
3094 s
->contents
= (bfd_byte
*) bfd_zalloc (htab
->elf
.dynobj
, s
->_raw_size
);
3095 if (s
->contents
== NULL
)
3099 if (htab
->elf
.dynamic_sections_created
)
3101 /* Add some entries to the .dynamic section. We fill in the
3102 values later, in ppc_elf_finish_dynamic_sections, but we
3103 must add the entries now so that we get the correct size for
3104 the .dynamic section. The DT_DEBUG entry is filled in by the
3105 dynamic linker and used by the debugger. */
3106 #define add_dynamic_entry(TAG, VAL) \
3107 bfd_elf32_add_dynamic_entry (info, (bfd_vma) (TAG), (bfd_vma) (VAL))
3111 if (!add_dynamic_entry (DT_DEBUG
, 0))
3115 if (htab
->plt
!= NULL
&& htab
->plt
->_raw_size
!= 0)
3117 if (!add_dynamic_entry (DT_PLTGOT
, 0)
3118 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
3119 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
3120 || !add_dynamic_entry (DT_JMPREL
, 0))
3126 if (!add_dynamic_entry (DT_RELA
, 0)
3127 || !add_dynamic_entry (DT_RELASZ
, 0)
3128 || !add_dynamic_entry (DT_RELAENT
, sizeof (Elf32_External_Rela
)))
3132 /* If any dynamic relocs apply to a read-only section, then we
3133 need a DT_TEXTREL entry. */
3134 if ((info
->flags
& DF_TEXTREL
) == 0)
3135 elf_link_hash_traverse (elf_hash_table (info
), readonly_dynrelocs
,
3138 if ((info
->flags
& DF_TEXTREL
) != 0)
3140 if (!add_dynamic_entry (DT_TEXTREL
, 0))
3144 #undef add_dynamic_entry
3150 update_local_sym_info (abfd
, symtab_hdr
, r_symndx
, tls_type
)
3152 Elf_Internal_Shdr
*symtab_hdr
;
3153 unsigned long r_symndx
;
3156 bfd_signed_vma
*local_got_refcounts
= elf_local_got_refcounts (abfd
);
3157 char *local_got_tls_masks
;
3159 if (local_got_refcounts
== NULL
)
3161 bfd_size_type size
= symtab_hdr
->sh_info
;
3163 size
*= sizeof (*local_got_refcounts
) + sizeof (*local_got_tls_masks
);
3164 local_got_refcounts
= (bfd_signed_vma
*) bfd_zalloc (abfd
, size
);
3165 if (local_got_refcounts
== NULL
)
3167 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
3170 local_got_refcounts
[r_symndx
] += 1;
3171 local_got_tls_masks
= (char *) (local_got_refcounts
+ symtab_hdr
->sh_info
);
3172 local_got_tls_masks
[r_symndx
] |= tls_type
;
3177 bad_shared_reloc (abfd
, r_type
)
3179 enum elf_ppc_reloc_type r_type
;
3181 (*_bfd_error_handler
)
3182 (_("%s: relocation %s cannot be used when making a shared object"),
3183 bfd_archive_filename (abfd
),
3184 ppc_elf_howto_table
[(int) r_type
]->name
);
3185 bfd_set_error (bfd_error_bad_value
);
3188 /* Look through the relocs for a section during the first phase, and
3189 allocate space in the global offset table or procedure linkage
3193 ppc_elf_check_relocs (abfd
, info
, sec
, relocs
)
3195 struct bfd_link_info
*info
;
3197 const Elf_Internal_Rela
*relocs
;
3199 struct ppc_elf_link_hash_table
*htab
;
3200 Elf_Internal_Shdr
*symtab_hdr
;
3201 struct elf_link_hash_entry
**sym_hashes
;
3202 const Elf_Internal_Rela
*rel
;
3203 const Elf_Internal_Rela
*rel_end
;
3206 if (info
->relocateable
)
3210 fprintf (stderr
, "ppc_elf_check_relocs called for section %s in %s\n",
3211 bfd_get_section_name (abfd
, sec
),
3212 bfd_archive_filename (abfd
));
3215 /* Create the linker generated sections all the time so that the
3216 special symbols are created. */
3218 htab
= ppc_elf_hash_table (info
);
3219 if (htab
->sdata
== NULL
)
3221 htab
->sdata
= elf_linker_section (abfd
, LINKER_SECTION_SDATA
);
3222 if (htab
->sdata
== NULL
)
3223 htab
->sdata
= ppc_elf_create_linker_section (abfd
, info
,
3224 LINKER_SECTION_SDATA
);
3225 if (htab
->sdata
== NULL
)
3229 if (htab
->sdata2
== NULL
)
3231 htab
->sdata2
= elf_linker_section (abfd
, LINKER_SECTION_SDATA2
);
3232 if (htab
->sdata2
== NULL
)
3233 htab
->sdata2
= ppc_elf_create_linker_section (abfd
, info
,
3234 LINKER_SECTION_SDATA2
);
3235 if (htab
->sdata2
== NULL
)
3239 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
3240 sym_hashes
= elf_sym_hashes (abfd
);
3243 rel_end
= relocs
+ sec
->reloc_count
;
3244 for (rel
= relocs
; rel
< rel_end
; rel
++)
3246 unsigned long r_symndx
;
3247 enum elf_ppc_reloc_type r_type
;
3248 struct elf_link_hash_entry
*h
;
3251 r_symndx
= ELF32_R_SYM (rel
->r_info
);
3252 if (r_symndx
< symtab_hdr
->sh_info
)
3255 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
3257 /* If a relocation refers to _GLOBAL_OFFSET_TABLE_, create the .got.
3258 This shows up in particular in an R_PPC_ADDR32 in the eabi
3260 if (h
&& strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
3262 if (htab
->got
== NULL
)
3264 if (htab
->elf
.dynobj
== NULL
)
3265 htab
->elf
.dynobj
= abfd
;
3266 if (!ppc_elf_create_got (htab
->elf
.dynobj
, info
))
3271 r_type
= (enum elf_ppc_reloc_type
) ELF32_R_TYPE (rel
->r_info
);
3274 case R_PPC_GOT_TLSLD16
:
3275 case R_PPC_GOT_TLSLD16_LO
:
3276 case R_PPC_GOT_TLSLD16_HI
:
3277 case R_PPC_GOT_TLSLD16_HA
:
3278 htab
->tlsld_got
.refcount
+= 1;
3279 tls_type
= TLS_TLS
| TLS_LD
;
3282 case R_PPC_GOT_TLSGD16
:
3283 case R_PPC_GOT_TLSGD16_LO
:
3284 case R_PPC_GOT_TLSGD16_HI
:
3285 case R_PPC_GOT_TLSGD16_HA
:
3286 tls_type
= TLS_TLS
| TLS_GD
;
3289 case R_PPC_GOT_TPREL16
:
3290 case R_PPC_GOT_TPREL16_LO
:
3291 case R_PPC_GOT_TPREL16_HI
:
3292 case R_PPC_GOT_TPREL16_HA
:
3294 info
->flags
|= DF_STATIC_TLS
;
3295 tls_type
= TLS_TLS
| TLS_TPREL
;
3298 case R_PPC_GOT_DTPREL16
:
3299 case R_PPC_GOT_DTPREL16_LO
:
3300 case R_PPC_GOT_DTPREL16_HI
:
3301 case R_PPC_GOT_DTPREL16_HA
:
3302 tls_type
= TLS_TLS
| TLS_DTPREL
;
3304 sec
->has_tls_reloc
= 1;
3307 /* GOT16 relocations */
3309 case R_PPC_GOT16_LO
:
3310 case R_PPC_GOT16_HI
:
3311 case R_PPC_GOT16_HA
:
3312 /* This symbol requires a global offset table entry. */
3313 if (htab
->got
== NULL
)
3315 if (htab
->elf
.dynobj
== NULL
)
3316 htab
->elf
.dynobj
= abfd
;
3317 if (!ppc_elf_create_got (htab
->elf
.dynobj
, info
))
3322 h
->got
.refcount
+= 1;
3323 ppc_elf_hash_entry (h
)->tls_mask
|= tls_type
;
3326 /* This is a global offset table entry for a local symbol. */
3327 if (!update_local_sym_info (abfd
, symtab_hdr
, r_symndx
, tls_type
))
3331 /* Indirect .sdata relocation. */
3332 case R_PPC_EMB_SDAI16
:
3335 bad_shared_reloc (abfd
, r_type
);
3338 if (!bfd_elf32_create_pointer_linker_section (abfd
, info
,
3339 htab
->sdata
, h
, rel
))
3343 /* Indirect .sdata2 relocation. */
3344 case R_PPC_EMB_SDA2I16
:
3347 bad_shared_reloc (abfd
, r_type
);
3350 if (!bfd_elf32_create_pointer_linker_section (abfd
, info
,
3351 htab
->sdata2
, h
, rel
))
3355 case R_PPC_SDAREL16
:
3356 case R_PPC_EMB_SDA2REL
:
3357 case R_PPC_EMB_SDA21
:
3358 case R_PPC_EMB_RELSDA
:
3359 case R_PPC_EMB_NADDR32
:
3360 case R_PPC_EMB_NADDR16
:
3361 case R_PPC_EMB_NADDR16_LO
:
3362 case R_PPC_EMB_NADDR16_HI
:
3363 case R_PPC_EMB_NADDR16_HA
:
3366 bad_shared_reloc (abfd
, r_type
);
3372 case R_PPC_PLTREL24
:
3373 case R_PPC_PLTREL32
:
3374 case R_PPC_PLT16_LO
:
3375 case R_PPC_PLT16_HI
:
3376 case R_PPC_PLT16_HA
:
3378 fprintf (stderr
, "Reloc requires a PLT entry\n");
3380 /* This symbol requires a procedure linkage table entry. We
3381 actually build the entry in finish_dynamic_symbol,
3382 because this might be a case of linking PIC code without
3383 linking in any dynamic objects, in which case we don't
3384 need to generate a procedure linkage table after all. */
3388 /* It does not make sense to have a procedure linkage
3389 table entry for a local symbol. */
3390 bfd_set_error (bfd_error_bad_value
);
3394 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
3398 /* The following relocations don't need to propagate the
3399 relocation if linking a shared object since they are
3400 section relative. */
3402 case R_PPC_SECTOFF_LO
:
3403 case R_PPC_SECTOFF_HI
:
3404 case R_PPC_SECTOFF_HA
:
3405 case R_PPC_DTPREL16
:
3406 case R_PPC_DTPREL16_LO
:
3407 case R_PPC_DTPREL16_HI
:
3408 case R_PPC_DTPREL16_HA
:
3412 /* This are just markers. */
3414 case R_PPC_EMB_MRKREF
:
3419 /* These should only appear in dynamic objects. */
3421 case R_PPC_GLOB_DAT
:
3422 case R_PPC_JMP_SLOT
:
3423 case R_PPC_RELATIVE
:
3426 /* These aren't handled yet. We'll report an error later. */
3428 case R_PPC_EMB_RELSEC16
:
3429 case R_PPC_EMB_RELST_LO
:
3430 case R_PPC_EMB_RELST_HI
:
3431 case R_PPC_EMB_RELST_HA
:
3432 case R_PPC_EMB_BIT_FLD
:
3435 /* This refers only to functions defined in the shared library. */
3436 case R_PPC_LOCAL24PC
:
3439 /* This relocation describes the C++ object vtable hierarchy.
3440 Reconstruct it for later use during GC. */
3441 case R_PPC_GNU_VTINHERIT
:
3442 if (!_bfd_elf32_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
3446 /* This relocation describes which C++ vtable entries are actually
3447 used. Record for later use during GC. */
3448 case R_PPC_GNU_VTENTRY
:
3449 if (!_bfd_elf32_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
3453 /* We shouldn't really be seeing these. */
3456 info
->flags
|= DF_STATIC_TLS
;
3460 case R_PPC_DTPMOD32
:
3461 case R_PPC_DTPREL32
:
3465 case R_PPC_TPREL16_LO
:
3466 case R_PPC_TPREL16_HI
:
3467 case R_PPC_TPREL16_HA
:
3469 info
->flags
|= DF_STATIC_TLS
;
3472 /* When creating a shared object, we must copy these
3473 relocs into the output file. We create a reloc
3474 section in dynobj and make room for the reloc. */
3477 case R_PPC_REL14_BRTAKEN
:
3478 case R_PPC_REL14_BRNTAKEN
:
3481 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
3488 case R_PPC_ADDR16_LO
:
3489 case R_PPC_ADDR16_HI
:
3490 case R_PPC_ADDR16_HA
:
3492 case R_PPC_ADDR14_BRTAKEN
:
3493 case R_PPC_ADDR14_BRNTAKEN
:
3496 if (h
!= NULL
&& !info
->shared
)
3498 /* We may need a plt entry if the symbol turns out to be
3499 a function defined in a dynamic object. */
3502 /* We may need a copy reloc too. */
3503 h
->elf_link_hash_flags
|= ELF_LINK_NON_GOT_REF
;
3507 /* If we are creating a shared library, and this is a reloc
3508 against a global symbol, or a non PC relative reloc
3509 against a local symbol, then we need to copy the reloc
3510 into the shared library. However, if we are linking with
3511 -Bsymbolic, we do not need to copy a reloc against a
3512 global symbol which is defined in an object we are
3513 including in the link (i.e., DEF_REGULAR is set). At
3514 this point we have not seen all the input files, so it is
3515 possible that DEF_REGULAR is not set now but will be set
3516 later (it is never cleared). In case of a weak definition,
3517 DEF_REGULAR may be cleared later by a strong definition in
3518 a shared library. We account for that possibility below by
3519 storing information in the dyn_relocs field of the hash
3520 table entry. A similar situation occurs when creating
3521 shared libraries and symbol visibility changes render the
3524 If on the other hand, we are creating an executable, we
3525 may need to keep relocations for symbols satisfied by a
3526 dynamic library if we manage to avoid copy relocs for the
3529 && (MUST_BE_DYN_RELOC (r_type
)
3531 && (! info
->symbolic
3532 || h
->root
.type
== bfd_link_hash_defweak
3533 || (h
->elf_link_hash_flags
3534 & ELF_LINK_HASH_DEF_REGULAR
) == 0))))
3535 || (ELIMINATE_COPY_RELOCS
3537 && (sec
->flags
& SEC_ALLOC
) != 0
3539 && (h
->root
.type
== bfd_link_hash_defweak
3540 || (h
->elf_link_hash_flags
3541 & ELF_LINK_HASH_DEF_REGULAR
) == 0)))
3543 struct ppc_elf_dyn_relocs
*p
;
3544 struct ppc_elf_dyn_relocs
**head
;
3547 fprintf (stderr
, "ppc_elf_check_relocs need to create relocation for %s\n",
3548 (h
&& h
->root
.root
.string
3549 ? h
->root
.root
.string
: "<unknown>"));
3555 name
= (bfd_elf_string_from_elf_section
3557 elf_elfheader (abfd
)->e_shstrndx
,
3558 elf_section_data (sec
)->rel_hdr
.sh_name
));
3562 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
3563 && strcmp (bfd_get_section_name (abfd
, sec
),
3566 sreloc
= bfd_get_section_by_name (htab
->elf
.dynobj
, name
);
3571 sreloc
= bfd_make_section (htab
->elf
.dynobj
, name
);
3572 flags
= (SEC_HAS_CONTENTS
| SEC_READONLY
3573 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
3574 if ((sec
->flags
& SEC_ALLOC
) != 0)
3575 flags
|= SEC_ALLOC
| SEC_LOAD
;
3577 || ! bfd_set_section_flags (htab
->elf
.dynobj
,
3579 || ! bfd_set_section_alignment (htab
->elf
.dynobj
,
3583 elf_section_data (sec
)->sreloc
= sreloc
;
3586 /* If this is a global symbol, we count the number of
3587 relocations we need for this symbol. */
3590 head
= &ppc_elf_hash_entry (h
)->dyn_relocs
;
3594 /* Track dynamic relocs needed for local syms too.
3595 We really need local syms available to do this
3599 s
= bfd_section_from_r_symndx (abfd
, &htab
->sym_sec
,
3604 head
= ((struct ppc_elf_dyn_relocs
**)
3605 &elf_section_data (s
)->local_dynrel
);
3609 if (p
== NULL
|| p
->sec
!= sec
)
3611 p
= ((struct ppc_elf_dyn_relocs
*)
3612 bfd_alloc (htab
->elf
.dynobj
, sizeof *p
));
3623 if (!MUST_BE_DYN_RELOC (r_type
))
3634 /* Return the section that should be marked against GC for a given
3638 ppc_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
)
3640 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
3641 Elf_Internal_Rela
*rel
;
3642 struct elf_link_hash_entry
*h
;
3643 Elf_Internal_Sym
*sym
;
3647 switch (ELF32_R_TYPE (rel
->r_info
))
3649 case R_PPC_GNU_VTINHERIT
:
3650 case R_PPC_GNU_VTENTRY
:
3654 switch (h
->root
.type
)
3656 case bfd_link_hash_defined
:
3657 case bfd_link_hash_defweak
:
3658 return h
->root
.u
.def
.section
;
3660 case bfd_link_hash_common
:
3661 return h
->root
.u
.c
.p
->section
;
3669 return bfd_section_from_elf_index (sec
->owner
, sym
->st_shndx
);
3674 /* Update the got, plt and dynamic reloc reference counts for the
3675 section being removed. */
3678 ppc_elf_gc_sweep_hook (abfd
, info
, sec
, relocs
)
3680 struct bfd_link_info
*info
;
3682 const Elf_Internal_Rela
*relocs
;
3684 struct ppc_elf_link_hash_table
*htab
;
3685 Elf_Internal_Shdr
*symtab_hdr
;
3686 struct elf_link_hash_entry
**sym_hashes
;
3687 bfd_signed_vma
*local_got_refcounts
;
3688 const Elf_Internal_Rela
*rel
, *relend
;
3690 elf_section_data (sec
)->local_dynrel
= NULL
;
3692 htab
= ppc_elf_hash_table (info
);
3693 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
3694 sym_hashes
= elf_sym_hashes (abfd
);
3695 local_got_refcounts
= elf_local_got_refcounts (abfd
);
3697 relend
= relocs
+ sec
->reloc_count
;
3698 for (rel
= relocs
; rel
< relend
; rel
++)
3700 unsigned long r_symndx
;
3701 enum elf_ppc_reloc_type r_type
;
3702 struct elf_link_hash_entry
*h
= NULL
;
3704 r_symndx
= ELF32_R_SYM (rel
->r_info
);
3705 if (r_symndx
>= symtab_hdr
->sh_info
)
3707 struct ppc_elf_dyn_relocs
**pp
, *p
;
3708 struct ppc_elf_link_hash_entry
*eh
;
3710 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
3711 eh
= (struct ppc_elf_link_hash_entry
*) h
;
3713 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; pp
= &p
->next
)
3716 /* Everything must go for SEC. */
3722 r_type
= (enum elf_ppc_reloc_type
) ELF32_R_TYPE (rel
->r_info
);
3725 case R_PPC_GOT_TLSLD16
:
3726 case R_PPC_GOT_TLSLD16_LO
:
3727 case R_PPC_GOT_TLSLD16_HI
:
3728 case R_PPC_GOT_TLSLD16_HA
:
3729 htab
->tlsld_got
.refcount
-= 1;
3732 case R_PPC_GOT_TLSGD16
:
3733 case R_PPC_GOT_TLSGD16_LO
:
3734 case R_PPC_GOT_TLSGD16_HI
:
3735 case R_PPC_GOT_TLSGD16_HA
:
3736 case R_PPC_GOT_TPREL16
:
3737 case R_PPC_GOT_TPREL16_LO
:
3738 case R_PPC_GOT_TPREL16_HI
:
3739 case R_PPC_GOT_TPREL16_HA
:
3740 case R_PPC_GOT_DTPREL16
:
3741 case R_PPC_GOT_DTPREL16_LO
:
3742 case R_PPC_GOT_DTPREL16_HI
:
3743 case R_PPC_GOT_DTPREL16_HA
:
3745 case R_PPC_GOT16_LO
:
3746 case R_PPC_GOT16_HI
:
3747 case R_PPC_GOT16_HA
:
3750 if (h
->got
.refcount
> 0)
3753 else if (local_got_refcounts
!= NULL
)
3755 if (local_got_refcounts
[r_symndx
] > 0)
3756 local_got_refcounts
[r_symndx
]--;
3762 case R_PPC_REL14_BRTAKEN
:
3763 case R_PPC_REL14_BRNTAKEN
:
3766 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
3773 case R_PPC_ADDR16_LO
:
3774 case R_PPC_ADDR16_HI
:
3775 case R_PPC_ADDR16_HA
:
3777 case R_PPC_ADDR14_BRTAKEN
:
3778 case R_PPC_ADDR14_BRNTAKEN
:
3782 case R_PPC_PLTREL24
:
3783 case R_PPC_PLT16_LO
:
3784 case R_PPC_PLT16_HI
:
3785 case R_PPC_PLT16_HA
:
3788 if (h
->plt
.refcount
> 0)
3800 /* Set htab->tls_sec and htab->tls_get_addr. */
3803 ppc_elf_tls_setup (obfd
, info
)
3805 struct bfd_link_info
*info
;
3808 struct ppc_elf_link_hash_table
*htab
;
3810 htab
= ppc_elf_hash_table (info
);
3811 htab
->tls_get_addr
= elf_link_hash_lookup (&htab
->elf
, "__tls_get_addr",
3812 FALSE
, FALSE
, TRUE
);
3814 for (tls
= obfd
->sections
; tls
!= NULL
; tls
= tls
->next
)
3815 if ((tls
->flags
& (SEC_THREAD_LOCAL
| SEC_LOAD
))
3816 == (SEC_THREAD_LOCAL
| SEC_LOAD
))
3818 htab
->tls_sec
= tls
;
3823 /* Run through all the TLS relocs looking for optimization
3827 ppc_elf_tls_optimize (obfd
, info
)
3828 bfd
*obfd ATTRIBUTE_UNUSED
;
3829 struct bfd_link_info
*info
;
3833 struct ppc_elf_link_hash_table
*htab
;
3835 if (info
->relocateable
|| info
->shared
)
3838 htab
= ppc_elf_hash_table (info
);
3839 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
3841 Elf_Internal_Sym
*locsyms
= NULL
;
3842 Elf_Internal_Shdr
*symtab_hdr
= &elf_tdata (ibfd
)->symtab_hdr
;
3844 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
3845 if (sec
->has_tls_reloc
&& !bfd_is_abs_section (sec
->output_section
))
3847 Elf_Internal_Rela
*relstart
, *rel
, *relend
;
3848 int expecting_tls_get_addr
;
3850 /* Read the relocations. */
3851 relstart
= _bfd_elf32_link_read_relocs (ibfd
, sec
, (PTR
) NULL
,
3852 (Elf_Internal_Rela
*) NULL
,
3854 if (relstart
== NULL
)
3857 expecting_tls_get_addr
= 0;
3858 relend
= relstart
+ sec
->reloc_count
;
3859 for (rel
= relstart
; rel
< relend
; rel
++)
3861 enum elf_ppc_reloc_type r_type
;
3862 unsigned long r_symndx
;
3863 struct elf_link_hash_entry
*h
= NULL
;
3865 char tls_set
, tls_clear
;
3866 bfd_boolean is_local
;
3868 r_symndx
= ELF32_R_SYM (rel
->r_info
);
3869 if (r_symndx
>= symtab_hdr
->sh_info
)
3871 struct elf_link_hash_entry
**sym_hashes
;
3873 sym_hashes
= elf_sym_hashes (ibfd
);
3874 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
3875 while (h
->root
.type
== bfd_link_hash_indirect
3876 || h
->root
.type
== bfd_link_hash_warning
)
3877 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
3882 || !(h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
))
3885 r_type
= (enum elf_ppc_reloc_type
) ELF32_R_TYPE (rel
->r_info
);
3888 case R_PPC_GOT_TLSLD16
:
3889 case R_PPC_GOT_TLSLD16_LO
:
3890 case R_PPC_GOT_TLSLD16_HI
:
3891 case R_PPC_GOT_TLSLD16_HA
:
3892 /* These relocs should never be against a symbol
3893 defined in a shared lib. Leave them alone if
3894 that turns out to be the case. */
3895 expecting_tls_get_addr
= 0;
3896 htab
->tlsld_got
.refcount
-= 1;
3903 expecting_tls_get_addr
= 1;
3906 case R_PPC_GOT_TLSGD16
:
3907 case R_PPC_GOT_TLSGD16_LO
:
3908 case R_PPC_GOT_TLSGD16_HI
:
3909 case R_PPC_GOT_TLSGD16_HA
:
3915 tls_set
= TLS_TLS
| TLS_TPRELGD
;
3917 expecting_tls_get_addr
= 1;
3920 case R_PPC_GOT_TPREL16
:
3921 case R_PPC_GOT_TPREL16_LO
:
3922 case R_PPC_GOT_TPREL16_HI
:
3923 case R_PPC_GOT_TPREL16_HA
:
3924 expecting_tls_get_addr
= 0;
3929 tls_clear
= TLS_TPREL
;
3936 case R_PPC_REL14_BRTAKEN
:
3937 case R_PPC_REL14_BRNTAKEN
:
3939 if (expecting_tls_get_addr
3941 && h
== htab
->tls_get_addr
)
3943 if (h
->plt
.refcount
> 0)
3944 h
->plt
.refcount
-= 1;
3946 expecting_tls_get_addr
= 0;
3950 expecting_tls_get_addr
= 0;
3958 /* We managed to get rid of a got entry. */
3959 if (h
->got
.refcount
> 0)
3960 h
->got
.refcount
-= 1;
3962 tls_mask
= &ppc_elf_hash_entry (h
)->tls_mask
;
3966 Elf_Internal_Sym
*sym
;
3967 bfd_signed_vma
*lgot_refs
;
3970 if (locsyms
== NULL
)
3972 locsyms
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
3973 if (locsyms
== NULL
)
3974 locsyms
= bfd_elf_get_elf_syms (ibfd
, symtab_hdr
,
3975 symtab_hdr
->sh_info
,
3976 0, NULL
, NULL
, NULL
);
3977 if (locsyms
== NULL
)
3979 if (elf_section_data (sec
)->relocs
!= relstart
)
3984 sym
= locsyms
+ r_symndx
;
3985 lgot_refs
= elf_local_got_refcounts (ibfd
);
3986 if (lgot_refs
== NULL
)
3990 /* We managed to get rid of a got entry. */
3991 if (lgot_refs
[r_symndx
] > 0)
3992 lgot_refs
[r_symndx
] -= 1;
3994 lgot_masks
= (char *) (lgot_refs
+ symtab_hdr
->sh_info
);
3995 tls_mask
= &lgot_masks
[r_symndx
];
3998 *tls_mask
|= tls_set
;
3999 *tls_mask
&= ~tls_clear
;
4002 if (elf_section_data (sec
)->relocs
!= relstart
)
4007 && (symtab_hdr
->contents
!= (unsigned char *) locsyms
))
4009 if (!info
->keep_memory
)
4012 symtab_hdr
->contents
= (unsigned char *) locsyms
;
4018 /* Hook called by the linker routine which adds symbols from an object
4019 file. We use it to put .comm items in .sbss, and not .bss. */
4022 ppc_elf_add_symbol_hook (abfd
, info
, sym
, namep
, flagsp
, secp
, valp
)
4024 struct bfd_link_info
*info
;
4025 const Elf_Internal_Sym
*sym
;
4026 const char **namep ATTRIBUTE_UNUSED
;
4027 flagword
*flagsp ATTRIBUTE_UNUSED
;
4031 if (sym
->st_shndx
== SHN_COMMON
4032 && !info
->relocateable
4033 && sym
->st_size
<= elf_gp_size (abfd
)
4034 && info
->hash
->creator
->flavour
== bfd_target_elf_flavour
)
4036 /* Common symbols less than or equal to -G nn bytes are automatically
4038 elf_linker_section_t
*sdata
4039 = ppc_elf_create_linker_section (abfd
, info
, LINKER_SECTION_SDATA
);
4041 if (!sdata
->bss_section
)
4045 /* We don't go through bfd_make_section, because we don't
4046 want to attach this common section to DYNOBJ. The linker
4047 will move the symbols to the appropriate output section
4048 when it defines common symbols. */
4049 amt
= sizeof (asection
);
4050 sdata
->bss_section
= (asection
*) bfd_zalloc (abfd
, amt
);
4051 if (sdata
->bss_section
== NULL
)
4053 sdata
->bss_section
->name
= sdata
->bss_name
;
4054 sdata
->bss_section
->flags
= SEC_IS_COMMON
;
4055 sdata
->bss_section
->output_section
= sdata
->bss_section
;
4056 amt
= sizeof (asymbol
);
4057 sdata
->bss_section
->symbol
= (asymbol
*) bfd_zalloc (abfd
, amt
);
4058 amt
= sizeof (asymbol
*);
4059 sdata
->bss_section
->symbol_ptr_ptr
=
4060 (asymbol
**) bfd_zalloc (abfd
, amt
);
4061 if (sdata
->bss_section
->symbol
== NULL
4062 || sdata
->bss_section
->symbol_ptr_ptr
== NULL
)
4064 sdata
->bss_section
->symbol
->name
= sdata
->bss_name
;
4065 sdata
->bss_section
->symbol
->flags
= BSF_SECTION_SYM
;
4066 sdata
->bss_section
->symbol
->section
= sdata
->bss_section
;
4067 *sdata
->bss_section
->symbol_ptr_ptr
= sdata
->bss_section
->symbol
;
4070 *secp
= sdata
->bss_section
;
4071 *valp
= sym
->st_size
;
4077 /* Finish up dynamic symbol handling. We set the contents of various
4078 dynamic sections here. */
4081 ppc_elf_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
4083 struct bfd_link_info
*info
;
4084 struct elf_link_hash_entry
*h
;
4085 Elf_Internal_Sym
*sym
;
4087 struct ppc_elf_link_hash_table
*htab
;
4090 fprintf (stderr
, "ppc_elf_finish_dynamic_symbol called for %s",
4091 h
->root
.root
.string
);
4094 htab
= ppc_elf_hash_table (info
);
4095 BFD_ASSERT (htab
->elf
.dynobj
!= NULL
);
4097 if (h
->plt
.offset
!= (bfd_vma
) -1)
4099 Elf_Internal_Rela rela
;
4101 bfd_vma reloc_index
;
4104 fprintf (stderr
, ", plt_offset = %d", h
->plt
.offset
);
4107 /* This symbol has an entry in the procedure linkage table. Set
4110 BFD_ASSERT (h
->dynindx
!= -1);
4111 BFD_ASSERT (htab
->plt
!= NULL
&& htab
->relplt
!= NULL
);
4113 /* We don't need to fill in the .plt. The ppc dynamic linker
4116 /* Fill in the entry in the .rela.plt section. */
4117 rela
.r_offset
= (htab
->plt
->output_section
->vma
4118 + htab
->plt
->output_offset
4120 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_PPC_JMP_SLOT
);
4123 reloc_index
= (h
->plt
.offset
- PLT_INITIAL_ENTRY_SIZE
) / PLT_SLOT_SIZE
;
4124 if (reloc_index
> PLT_NUM_SINGLE_ENTRIES
)
4125 reloc_index
-= (reloc_index
- PLT_NUM_SINGLE_ENTRIES
) / 2;
4126 loc
= (htab
->relplt
->contents
4127 + reloc_index
* sizeof (Elf32_External_Rela
));
4128 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
4130 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
4132 /* Mark the symbol as undefined, rather than as defined in
4133 the .plt section. Leave the value alone. */
4134 sym
->st_shndx
= SHN_UNDEF
;
4135 /* If the symbol is weak, we do need to clear the value.
4136 Otherwise, the PLT entry would provide a definition for
4137 the symbol even if the symbol wasn't defined anywhere,
4138 and so the symbol would never be NULL. */
4139 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_REF_REGULAR_NONWEAK
)
4145 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_COPY
) != 0)
4148 Elf_Internal_Rela rela
;
4151 /* This symbols needs a copy reloc. Set it up. */
4154 fprintf (stderr
, ", copy");
4157 BFD_ASSERT (h
->dynindx
!= -1);
4159 if (h
->size
<= elf_gp_size (htab
->elf
.dynobj
))
4163 BFD_ASSERT (s
!= NULL
);
4165 rela
.r_offset
= (h
->root
.u
.def
.value
4166 + h
->root
.u
.def
.section
->output_section
->vma
4167 + h
->root
.u
.def
.section
->output_offset
);
4168 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_PPC_COPY
);
4170 loc
= s
->contents
+ s
->reloc_count
++ * sizeof (Elf32_External_Rela
);
4171 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
4175 fprintf (stderr
, "\n");
4178 /* Mark some specially defined symbols as absolute. */
4179 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
4180 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0
4181 || strcmp (h
->root
.root
.string
, "_PROCEDURE_LINKAGE_TABLE_") == 0)
4182 sym
->st_shndx
= SHN_ABS
;
4187 /* Finish up the dynamic sections. */
4190 ppc_elf_finish_dynamic_sections (output_bfd
, info
)
4192 struct bfd_link_info
*info
;
4195 struct ppc_elf_link_hash_table
*htab
;
4198 fprintf (stderr
, "ppc_elf_finish_dynamic_sections called\n");
4201 htab
= ppc_elf_hash_table (info
);
4202 sdyn
= bfd_get_section_by_name (htab
->elf
.dynobj
, ".dynamic");
4204 if (htab
->elf
.dynamic_sections_created
)
4206 Elf32_External_Dyn
*dyncon
, *dynconend
;
4208 BFD_ASSERT (htab
->plt
!= NULL
&& sdyn
!= NULL
);
4210 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
4211 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
4212 for (; dyncon
< dynconend
; dyncon
++)
4214 Elf_Internal_Dyn dyn
;
4217 bfd_elf32_swap_dyn_in (htab
->elf
.dynobj
, dyncon
, &dyn
);
4223 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
4227 dyn
.d_un
.d_val
= htab
->relplt
->_raw_size
;
4232 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
4239 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
4243 /* Add a blrl instruction at _GLOBAL_OFFSET_TABLE_-4 so that a function can
4244 easily find the address of the _GLOBAL_OFFSET_TABLE_. */
4247 unsigned char *contents
= htab
->got
->contents
;
4248 bfd_put_32 (output_bfd
, (bfd_vma
) 0x4e800021 /* blrl */, contents
);
4251 bfd_put_32 (output_bfd
, (bfd_vma
) 0, contents
+ 4);
4253 bfd_put_32 (output_bfd
,
4254 sdyn
->output_section
->vma
+ sdyn
->output_offset
,
4257 elf_section_data (htab
->got
->output_section
)->this_hdr
.sh_entsize
= 4;
4263 /* The RELOCATE_SECTION function is called by the ELF backend linker
4264 to handle the relocations for a section.
4266 The relocs are always passed as Rela structures; if the section
4267 actually uses Rel structures, the r_addend field will always be
4270 This function is responsible for adjust the section contents as
4271 necessary, and (if using Rela relocs and generating a
4272 relocateable output file) adjusting the reloc addend as
4275 This function does not have to worry about setting the reloc
4276 address or the reloc symbol index.
4278 LOCAL_SYMS is a pointer to the swapped in local symbols.
4280 LOCAL_SECTIONS is an array giving the section in the input file
4281 corresponding to the st_shndx field of each local symbol.
4283 The global hash table entry for the global symbols can be found
4284 via elf_sym_hashes (input_bfd).
4286 When generating relocateable output, this function must handle
4287 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
4288 going to be the section symbol corresponding to the output
4289 section, which means that the addend must be adjusted
4293 ppc_elf_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
4294 contents
, relocs
, local_syms
, local_sections
)
4296 struct bfd_link_info
*info
;
4298 asection
*input_section
;
4300 Elf_Internal_Rela
*relocs
;
4301 Elf_Internal_Sym
*local_syms
;
4302 asection
**local_sections
;
4304 Elf_Internal_Shdr
*symtab_hdr
;
4305 struct elf_link_hash_entry
**sym_hashes
;
4306 struct ppc_elf_link_hash_table
*htab
;
4307 Elf_Internal_Rela
*rel
;
4308 Elf_Internal_Rela
*relend
;
4309 Elf_Internal_Rela outrel
;
4311 asection
*sreloc
= NULL
;
4312 bfd_vma
*local_got_offsets
;
4313 bfd_boolean ret
= TRUE
;
4316 fprintf (stderr
, "ppc_elf_relocate_section called for %s section %s, %ld relocations%s\n",
4317 bfd_archive_filename (input_bfd
),
4318 bfd_section_name(input_bfd
, input_section
),
4319 (long) input_section
->reloc_count
,
4320 (info
->relocateable
) ? " (relocatable)" : "");
4323 if (info
->relocateable
)
4326 if (!ppc_elf_howto_table
[R_PPC_ADDR32
])
4327 /* Initialize howto table if needed. */
4328 ppc_elf_howto_init ();
4330 htab
= ppc_elf_hash_table (info
);
4331 local_got_offsets
= elf_local_got_offsets (input_bfd
);
4332 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
4333 sym_hashes
= elf_sym_hashes (input_bfd
);
4335 relend
= relocs
+ input_section
->reloc_count
;
4336 for (; rel
< relend
; rel
++)
4338 enum elf_ppc_reloc_type r_type
;
4340 bfd_reloc_status_type r
;
4341 Elf_Internal_Sym
*sym
;
4343 struct elf_link_hash_entry
*h
;
4344 const char *sym_name
;
4345 reloc_howto_type
*howto
;
4346 unsigned long r_symndx
;
4348 bfd_vma branch_bit
, insn
, from
;
4349 bfd_boolean unresolved_reloc
;
4351 unsigned int tls_type
, tls_mask
, tls_gd
;
4353 r_type
= (enum elf_ppc_reloc_type
)ELF32_R_TYPE (rel
->r_info
);
4354 sym
= (Elf_Internal_Sym
*) 0;
4355 sec
= (asection
*) 0;
4356 h
= (struct elf_link_hash_entry
*) 0;
4357 unresolved_reloc
= FALSE
;
4359 r_symndx
= ELF32_R_SYM (rel
->r_info
);
4360 if (r_symndx
< symtab_hdr
->sh_info
)
4362 sym
= local_syms
+ r_symndx
;
4363 sec
= local_sections
[r_symndx
];
4364 sym_name
= bfd_elf_local_sym_name (input_bfd
, sym
);
4366 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, sec
, rel
);
4370 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
4371 while (h
->root
.type
== bfd_link_hash_indirect
4372 || h
->root
.type
== bfd_link_hash_warning
)
4373 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
4374 sym_name
= h
->root
.root
.string
;
4377 if (h
->root
.type
== bfd_link_hash_defined
4378 || h
->root
.type
== bfd_link_hash_defweak
)
4380 sec
= h
->root
.u
.def
.section
;
4381 /* Set a flag that will be cleared later if we find a
4382 relocation value for this symbol. output_section
4383 is typically NULL for symbols satisfied by a shared
4385 if (sec
->output_section
== NULL
)
4386 unresolved_reloc
= TRUE
;
4388 relocation
= (h
->root
.u
.def
.value
4389 + sec
->output_section
->vma
4390 + sec
->output_offset
);
4392 else if (h
->root
.type
== bfd_link_hash_undefweak
)
4394 else if (info
->shared
4395 && !info
->no_undefined
4396 && ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
)
4400 if (! ((*info
->callbacks
->undefined_symbol
)
4401 (info
, h
->root
.root
.string
, input_bfd
, input_section
,
4402 rel
->r_offset
, (!info
->shared
4403 || info
->no_undefined
4404 || ELF_ST_VISIBILITY (h
->other
)))))
4410 /* TLS optimizations. Replace instruction sequences and relocs
4411 based on information we collected in tls_optimize. We edit
4412 RELOCS so that --emit-relocs will output something sensible
4413 for the final instruction stream. */
4416 if (IS_PPC_TLS_RELOC (r_type
))
4419 tls_mask
= ((struct ppc_elf_link_hash_entry
*) h
)->tls_mask
;
4420 else if (local_got_offsets
!= NULL
)
4423 lgot_masks
= (char *) (local_got_offsets
+ symtab_hdr
->sh_info
);
4424 tls_mask
= lgot_masks
[r_symndx
];
4428 /* Ensure reloc mapping code below stays sane. */
4429 if ((R_PPC_GOT_TLSLD16
& 3) != (R_PPC_GOT_TLSGD16
& 3)
4430 || (R_PPC_GOT_TLSLD16_LO
& 3) != (R_PPC_GOT_TLSGD16_LO
& 3)
4431 || (R_PPC_GOT_TLSLD16_HI
& 3) != (R_PPC_GOT_TLSGD16_HI
& 3)
4432 || (R_PPC_GOT_TLSLD16_HA
& 3) != (R_PPC_GOT_TLSGD16_HA
& 3)
4433 || (R_PPC_GOT_TLSLD16
& 3) != (R_PPC_GOT_TPREL16
& 3)
4434 || (R_PPC_GOT_TLSLD16_LO
& 3) != (R_PPC_GOT_TPREL16_LO
& 3)
4435 || (R_PPC_GOT_TLSLD16_HI
& 3) != (R_PPC_GOT_TPREL16_HI
& 3)
4436 || (R_PPC_GOT_TLSLD16_HA
& 3) != (R_PPC_GOT_TPREL16_HA
& 3))
4443 case R_PPC_GOT_TPREL16
:
4444 case R_PPC_GOT_TPREL16_LO
:
4446 && (tls_mask
& TLS_TPREL
) == 0)
4449 insn
= bfd_get_32 (output_bfd
, contents
+ rel
->r_offset
- 2);
4451 insn
|= 0x3c020000; /* addis 0,2,0 */
4452 bfd_put_32 (output_bfd
, insn
, contents
+ rel
->r_offset
- 2);
4453 r_type
= R_PPC_TPREL16_HA
;
4454 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
4460 && (tls_mask
& TLS_TPREL
) == 0)
4463 insn
= bfd_get_32 (output_bfd
, contents
+ rel
->r_offset
);
4464 if ((insn
& ((31 << 26) | (31 << 11)))
4465 == ((31 << 26) | (2 << 11)))
4466 rtra
= insn
& ((1 << 26) - (1 << 16));
4467 else if ((insn
& ((31 << 26) | (31 << 16)))
4468 == ((31 << 26) | (2 << 16)))
4469 rtra
= (insn
& (31 << 21)) | ((insn
& (31 << 11)) << 5);
4472 if ((insn
& ((1 << 11) - (1 << 1))) == 266 << 1)
4475 else if ((insn
& (31 << 1)) == 23 << 1
4476 && ((insn
& (31 << 6)) < 14 << 6
4477 || ((insn
& (31 << 6)) >= 16 << 6
4478 && (insn
& (31 << 6)) < 24 << 6)))
4479 /* load and store indexed -> dform. */
4480 insn
= (32 | ((insn
>> 6) & 31)) << 26;
4481 else if ((insn
& (31 << 1)) == 21 << 1
4482 && (insn
& (0x1a << 6)) == 0)
4483 /* ldx, ldux, stdx, stdux -> ld, ldu, std, stdu. */
4484 insn
= (((58 | ((insn
>> 6) & 4)) << 26)
4485 | ((insn
>> 6) & 1));
4486 else if ((insn
& (31 << 1)) == 21 << 1
4487 && (insn
& ((1 << 11) - (1 << 1))) == 341 << 1)
4489 insn
= (58 << 26) | 2;
4493 bfd_put_32 (output_bfd
, insn
, contents
+ rel
->r_offset
);
4494 r_type
= R_PPC_TPREL16_LO
;
4495 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
4496 /* Was PPC_TLS which sits on insn boundary, now
4497 PPC_TPREL16_LO which is at insn+2. */
4502 case R_PPC_GOT_TLSGD16_HI
:
4503 case R_PPC_GOT_TLSGD16_HA
:
4504 tls_gd
= TLS_TPRELGD
;
4505 if (tls_mask
!= 0 && (tls_mask
& TLS_GD
) == 0)
4509 case R_PPC_GOT_TLSLD16_HI
:
4510 case R_PPC_GOT_TLSLD16_HA
:
4511 if (tls_mask
!= 0 && (tls_mask
& TLS_LD
) == 0)
4514 if ((tls_mask
& tls_gd
) != 0)
4515 r_type
= (((r_type
- (R_PPC_GOT_TLSGD16
& 3)) & 3)
4516 + R_PPC_GOT_TPREL16
);
4519 bfd_put_32 (output_bfd
, NOP
, contents
+ rel
->r_offset
);
4521 r_type
= R_PPC_NONE
;
4523 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
4527 case R_PPC_GOT_TLSGD16
:
4528 case R_PPC_GOT_TLSGD16_LO
:
4529 tls_gd
= TLS_TPRELGD
;
4530 if (tls_mask
!= 0 && (tls_mask
& TLS_GD
) == 0)
4531 goto tls_get_addr_check
;
4534 case R_PPC_GOT_TLSLD16
:
4535 case R_PPC_GOT_TLSLD16_LO
:
4536 if (tls_mask
!= 0 && (tls_mask
& TLS_LD
) == 0)
4539 if (rel
+ 1 < relend
)
4541 enum elf_ppc_reloc_type r_type2
;
4542 unsigned long r_symndx2
;
4543 struct elf_link_hash_entry
*h2
;
4544 bfd_vma insn1
, insn2
;
4547 /* The next instruction should be a call to
4548 __tls_get_addr. Peek at the reloc to be sure. */
4550 = (enum elf_ppc_reloc_type
) ELF32_R_TYPE (rel
[1].r_info
);
4551 r_symndx2
= ELF32_R_SYM (rel
[1].r_info
);
4552 if (r_symndx2
< symtab_hdr
->sh_info
4553 || (r_type2
!= R_PPC_REL14
4554 && r_type2
!= R_PPC_REL14_BRTAKEN
4555 && r_type2
!= R_PPC_REL14_BRNTAKEN
4556 && r_type2
!= R_PPC_REL24
4557 && r_type2
!= R_PPC_PLTREL24
))
4560 h2
= sym_hashes
[r_symndx2
- symtab_hdr
->sh_info
];
4561 while (h2
->root
.type
== bfd_link_hash_indirect
4562 || h2
->root
.type
== bfd_link_hash_warning
)
4563 h2
= (struct elf_link_hash_entry
*) h2
->root
.u
.i
.link
;
4564 if (h2
== NULL
|| h2
!= htab
->tls_get_addr
)
4567 /* OK, it checks out. Replace the call. */
4568 offset
= rel
[1].r_offset
;
4569 insn1
= bfd_get_32 (output_bfd
,
4570 contents
+ rel
->r_offset
- 2);
4571 if ((tls_mask
& tls_gd
) != 0)
4574 insn1
&= (1 << 26) - 1;
4575 insn1
|= 32 << 26; /* lwz */
4576 insn2
= 0x7c631214; /* add 3,3,2 */
4577 rel
[1].r_info
= ELF32_R_INFO (r_symndx2
, R_PPC_NONE
);
4578 r_type
= (((r_type
- (R_PPC_GOT_TLSGD16
& 3)) & 3)
4579 + R_PPC_GOT_TPREL16
);
4580 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
4585 insn1
= 0x3c620000; /* addis 3,2,0 */
4586 insn2
= 0x38630000; /* addi 3,3,0 */
4589 /* Was an LD reloc. */
4591 rel
->r_addend
= htab
->tls_sec
->vma
+ DTP_OFFSET
;
4592 rel
[1].r_addend
= htab
->tls_sec
->vma
+ DTP_OFFSET
;
4594 r_type
= R_PPC_TPREL16_HA
;
4595 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
4596 rel
[1].r_info
= ELF32_R_INFO (r_symndx
,
4598 rel
[1].r_offset
+= 2;
4600 bfd_put_32 (output_bfd
, insn1
, contents
+ rel
->r_offset
- 2);
4601 bfd_put_32 (output_bfd
, insn2
, contents
+ offset
);
4604 /* We changed the symbol on an LD reloc. Start over
4605 in order to get h, sym, sec etc. right. */
4614 /* Handle other relocations that tweak non-addend part of insn. */
4621 /* Branch taken prediction relocations. */
4622 case R_PPC_ADDR14_BRTAKEN
:
4623 case R_PPC_REL14_BRTAKEN
:
4624 branch_bit
= BRANCH_PREDICT_BIT
;
4627 /* Branch not taken predicition relocations. */
4628 case R_PPC_ADDR14_BRNTAKEN
:
4629 case R_PPC_REL14_BRNTAKEN
:
4630 insn
= bfd_get_32 (output_bfd
, contents
+ rel
->r_offset
);
4631 insn
&= ~BRANCH_PREDICT_BIT
;
4634 from
= (rel
->r_offset
4635 + input_section
->output_offset
4636 + input_section
->output_section
->vma
);
4638 /* Invert 'y' bit if not the default. */
4639 if ((bfd_signed_vma
) (relocation
+ rel
->r_addend
- from
) < 0)
4640 insn
^= BRANCH_PREDICT_BIT
;
4642 bfd_put_32 (output_bfd
, insn
, contents
+ rel
->r_offset
);
4646 addend
= rel
->r_addend
;
4649 if ((unsigned) r_type
< (unsigned) R_PPC_max
)
4650 howto
= ppc_elf_howto_table
[(int) r_type
];
4654 (*_bfd_error_handler
)
4655 (_("%s: unknown relocation type %d for symbol %s"),
4656 bfd_archive_filename (input_bfd
), (int) r_type
, sym_name
);
4658 bfd_set_error (bfd_error_bad_value
);
4664 case R_PPC_EMB_MRKREF
:
4665 case R_PPC_GNU_VTINHERIT
:
4666 case R_PPC_GNU_VTENTRY
:
4669 /* GOT16 relocations. Like an ADDR16 using the symbol's
4670 address in the GOT as relocation value instead of the
4671 symbol's value itself. Also, create a GOT entry for the
4672 symbol and put the symbol value there. */
4673 case R_PPC_GOT_TLSGD16
:
4674 case R_PPC_GOT_TLSGD16_LO
:
4675 case R_PPC_GOT_TLSGD16_HI
:
4676 case R_PPC_GOT_TLSGD16_HA
:
4677 tls_type
= TLS_TLS
| TLS_GD
;
4680 case R_PPC_GOT_TLSLD16
:
4681 case R_PPC_GOT_TLSLD16_LO
:
4682 case R_PPC_GOT_TLSLD16_HI
:
4683 case R_PPC_GOT_TLSLD16_HA
:
4684 tls_type
= TLS_TLS
| TLS_LD
;
4687 case R_PPC_GOT_TPREL16
:
4688 case R_PPC_GOT_TPREL16_LO
:
4689 case R_PPC_GOT_TPREL16_HI
:
4690 case R_PPC_GOT_TPREL16_HA
:
4691 tls_type
= TLS_TLS
| TLS_TPREL
;
4694 case R_PPC_GOT_DTPREL16
:
4695 case R_PPC_GOT_DTPREL16_LO
:
4696 case R_PPC_GOT_DTPREL16_HI
:
4697 case R_PPC_GOT_DTPREL16_HA
:
4698 tls_type
= TLS_TLS
| TLS_DTPREL
;
4702 case R_PPC_GOT16_LO
:
4703 case R_PPC_GOT16_HI
:
4704 case R_PPC_GOT16_HA
:
4707 /* Relocation is to the entry for this symbol in the global
4713 if (htab
->got
== NULL
)
4717 if (tls_type
== (TLS_TLS
| TLS_LD
)
4719 || !(h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
)))
4720 offp
= &htab
->tlsld_got
.offset
;
4724 dyn
= htab
->elf
.dynamic_sections_created
;
4725 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
4727 && SYMBOL_REFERENCES_LOCAL (info
, h
)))
4728 /* This is actually a static link, or it is a
4729 -Bsymbolic link and the symbol is defined
4730 locally, or the symbol was forced to be local
4731 because of a version file. */
4736 unresolved_reloc
= FALSE
;
4738 offp
= &h
->got
.offset
;
4742 if (local_got_offsets
== NULL
)
4744 offp
= &local_got_offsets
[r_symndx
];
4747 /* The offset must always be a multiple of 4. We use the
4748 least significant bit to record whether we have already
4749 processed this entry. */
4755 unsigned int tls_m
= (tls_mask
4756 & (TLS_LD
| TLS_GD
| TLS_DTPREL
4757 | TLS_TPREL
| TLS_TPRELGD
));
4759 if (offp
== &htab
->tlsld_got
.offset
)
4762 || !(h
->elf_link_hash_flags
4763 & ELF_LINK_HASH_DEF_DYNAMIC
))
4766 /* We might have multiple got entries for this sym.
4767 Initialize them all. */
4772 if ((tls_m
& TLS_LD
) != 0)
4774 tls_ty
= TLS_TLS
| TLS_LD
;
4777 else if ((tls_m
& TLS_GD
) != 0)
4779 tls_ty
= TLS_TLS
| TLS_GD
;
4782 else if ((tls_m
& TLS_DTPREL
) != 0)
4784 tls_ty
= TLS_TLS
| TLS_DTPREL
;
4785 tls_m
&= ~TLS_DTPREL
;
4787 else if ((tls_m
& (TLS_TPREL
| TLS_TPRELGD
)) != 0)
4789 tls_ty
= TLS_TLS
| TLS_TPREL
;
4793 /* Generate relocs for the dynamic linker. */
4794 if (info
->shared
|| indx
!= 0)
4796 outrel
.r_offset
= (htab
->got
->output_section
->vma
4797 + htab
->got
->output_offset
4799 outrel
.r_addend
= 0;
4800 if (tls_ty
& (TLS_LD
| TLS_GD
))
4802 outrel
.r_info
= ELF32_R_INFO (indx
, R_PPC_DTPMOD32
);
4803 if (tls_ty
== (TLS_TLS
| TLS_GD
))
4805 loc
= htab
->relgot
->contents
;
4806 loc
+= (htab
->relgot
->reloc_count
++
4807 * sizeof (Elf32_External_Rela
));
4808 bfd_elf32_swap_reloca_out (output_bfd
,
4810 outrel
.r_offset
+= 4;
4812 = ELF32_R_INFO (indx
, R_PPC_DTPREL32
);
4815 else if (tls_ty
== (TLS_TLS
| TLS_DTPREL
))
4816 outrel
.r_info
= ELF32_R_INFO (indx
, R_PPC_DTPREL32
);
4817 else if (tls_ty
== (TLS_TLS
| TLS_TPREL
))
4818 outrel
.r_info
= ELF32_R_INFO (indx
, R_PPC_TPREL32
);
4820 outrel
.r_info
= ELF32_R_INFO (indx
, R_PPC_RELATIVE
);
4822 outrel
.r_info
= ELF32_R_INFO (indx
, R_PPC_GLOB_DAT
);
4825 outrel
.r_addend
+= relocation
;
4826 if (tls_ty
& (TLS_GD
| TLS_DTPREL
| TLS_TPREL
))
4827 outrel
.r_addend
-= htab
->tls_sec
->vma
;
4829 loc
= htab
->relgot
->contents
;
4830 loc
+= (htab
->relgot
->reloc_count
++
4831 * sizeof (Elf32_External_Rela
));
4832 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
4835 /* Init the .got section contents if we're not
4836 emitting a reloc. */
4839 bfd_vma value
= relocation
;
4841 if (tls_ty
== (TLS_TLS
| TLS_LD
))
4843 else if (tls_ty
!= 0)
4845 value
-= htab
->tls_sec
->vma
+ DTP_OFFSET
;
4846 if (tls_ty
== (TLS_TLS
| TLS_TPREL
))
4847 value
+= DTP_OFFSET
- TP_OFFSET
;
4849 if (tls_ty
== (TLS_TLS
| TLS_GD
))
4851 bfd_put_32 (output_bfd
, value
,
4852 htab
->got
->contents
+ off
+ 4);
4856 bfd_put_32 (output_bfd
, value
,
4857 htab
->got
->contents
+ off
);
4861 if (tls_ty
& (TLS_LD
| TLS_GD
))
4870 if (off
>= (bfd_vma
) -2)
4873 if ((tls_type
& TLS_TLS
) != 0)
4875 if (tls_type
!= (TLS_TLS
| TLS_LD
))
4877 if ((tls_mask
& TLS_LD
) != 0
4879 || !(h
->elf_link_hash_flags
4880 & ELF_LINK_HASH_DEF_DYNAMIC
)))
4882 if (tls_type
!= (TLS_TLS
| TLS_GD
))
4884 if ((tls_mask
& TLS_GD
) != 0)
4886 if (tls_type
!= (TLS_TLS
| TLS_DTPREL
))
4888 if ((tls_mask
& TLS_DTPREL
) != 0)
4895 relocation
= htab
->got
->output_offset
+ off
- 4;
4897 /* Addends on got relocations don't make much sense.
4898 x+off@got is actually x@got+off, and since the got is
4899 generated by a hash table traversal, the value in the
4900 got at entry m+n bears little relation to the entry m. */
4902 (*_bfd_error_handler
)
4903 (_("%s(%s+0x%lx): non-zero addend on %s reloc against `%s'"),
4904 bfd_archive_filename (input_bfd
),
4905 bfd_get_section_name (input_bfd
, input_section
),
4906 (long) rel
->r_offset
,
4912 /* Relocations that need no special processing. */
4913 case R_PPC_LOCAL24PC
:
4914 /* It makes no sense to point a local relocation
4915 at a symbol not in this object. */
4916 if (unresolved_reloc
)
4918 if (! (*info
->callbacks
->undefined_symbol
) (info
,
4919 h
->root
.root
.string
,
4929 case R_PPC_DTPREL16
:
4930 case R_PPC_DTPREL16_LO
:
4931 case R_PPC_DTPREL16_HI
:
4932 case R_PPC_DTPREL16_HA
:
4933 addend
-= htab
->tls_sec
->vma
+ DTP_OFFSET
;
4936 /* Relocations that may need to be propagated if this is a shared
4939 case R_PPC_TPREL16_LO
:
4940 case R_PPC_TPREL16_HI
:
4941 case R_PPC_TPREL16_HA
:
4942 addend
-= htab
->tls_sec
->vma
+ TP_OFFSET
;
4943 /* The TPREL16 relocs shouldn't really be used in shared
4944 libs as they will result in DT_TEXTREL being set, but
4945 support them anyway. */
4949 addend
-= htab
->tls_sec
->vma
+ TP_OFFSET
;
4952 case R_PPC_DTPREL32
:
4953 addend
-= htab
->tls_sec
->vma
+ DTP_OFFSET
;
4956 case R_PPC_DTPMOD32
:
4964 case R_PPC_REL14_BRTAKEN
:
4965 case R_PPC_REL14_BRNTAKEN
:
4966 /* If these relocations are not to a named symbol, they can be
4967 handled right here, no need to bother the dynamic linker. */
4969 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0
4970 || SYMBOL_REFERENCES_LOCAL (info
, h
))
4974 /* Relocations that always need to be propagated if this is a shared
4979 case R_PPC_ADDR16_LO
:
4980 case R_PPC_ADDR16_HI
:
4981 case R_PPC_ADDR16_HA
:
4983 case R_PPC_ADDR14_BRTAKEN
:
4984 case R_PPC_ADDR14_BRNTAKEN
:
4987 /* r_symndx will be zero only for relocs against symbols
4988 from removed linkonce sections, or sections discarded by
4996 && (MUST_BE_DYN_RELOC (r_type
)
5000 || (h
->elf_link_hash_flags
5001 & ELF_LINK_HASH_DEF_REGULAR
) == 0))))
5002 || (ELIMINATE_COPY_RELOCS
5004 && (input_section
->flags
& SEC_ALLOC
) != 0
5007 && (h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0
5008 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
5009 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0))
5014 fprintf (stderr
, "ppc_elf_relocate_section need to create relocation for %s\n",
5015 (h
&& h
->root
.root
.string
5016 ? h
->root
.root
.string
: "<unknown>"));
5019 /* When generating a shared object, these relocations
5020 are copied into the output file to be resolved at run
5026 name
= (bfd_elf_string_from_elf_section
5028 elf_elfheader (input_bfd
)->e_shstrndx
,
5029 elf_section_data (input_section
)->rel_hdr
.sh_name
));
5033 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
5034 && strcmp (bfd_get_section_name (input_bfd
,
5038 sreloc
= bfd_get_section_by_name (htab
->elf
.dynobj
, name
);
5039 BFD_ASSERT (sreloc
!= NULL
);
5045 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
5047 if (outrel
.r_offset
== (bfd_vma
) -1
5048 || outrel
.r_offset
== (bfd_vma
) -2)
5049 skip
= (int) outrel
.r_offset
;
5050 outrel
.r_offset
+= (input_section
->output_section
->vma
5051 + input_section
->output_offset
);
5054 memset (&outrel
, 0, sizeof outrel
);
5056 && !SYMBOL_REFERENCES_LOCAL (info
, h
))
5058 unresolved_reloc
= FALSE
;
5059 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
5060 outrel
.r_addend
= rel
->r_addend
;
5064 outrel
.r_addend
= relocation
+ rel
->r_addend
;
5066 if (r_type
== R_PPC_ADDR32
)
5067 outrel
.r_info
= ELF32_R_INFO (0, R_PPC_RELATIVE
);
5072 if (bfd_is_abs_section (sec
))
5074 else if (sec
== NULL
|| sec
->owner
== NULL
)
5076 bfd_set_error (bfd_error_bad_value
);
5083 /* We are turning this relocation into one
5084 against a section symbol. It would be
5085 proper to subtract the symbol's value,
5086 osec->vma, from the emitted reloc addend,
5087 but ld.so expects buggy relocs. */
5088 osec
= sec
->output_section
;
5089 indx
= elf_section_data (osec
)->dynindx
;
5090 BFD_ASSERT (indx
> 0);
5094 printf ("indx=%d section=%s flags=%08x name=%s\n",
5095 indx
, osec
->name
, osec
->flags
,
5096 h
->root
.root
.string
);
5101 outrel
.r_info
= ELF32_R_INFO (indx
, r_type
);
5105 loc
= sreloc
->contents
;
5106 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rela
);
5107 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
5112 /* This reloc will be computed at runtime. We clear the memory
5113 so that it contains predictable value. */
5115 && ((input_section
->flags
& SEC_ALLOC
) != 0
5116 || ELF32_R_TYPE (outrel
.r_info
) != R_PPC_RELATIVE
))
5118 relocation
= howto
->pc_relative
? outrel
.r_offset
: 0;
5125 /* Indirect .sdata relocation. */
5126 case R_PPC_EMB_SDAI16
:
5127 BFD_ASSERT (htab
->sdata
!= NULL
);
5129 = bfd_elf32_finish_pointer_linker_section (output_bfd
, input_bfd
,
5130 info
, htab
->sdata
, h
,
5135 /* Indirect .sdata2 relocation. */
5136 case R_PPC_EMB_SDA2I16
:
5137 BFD_ASSERT (htab
->sdata2
!= NULL
);
5139 = bfd_elf32_finish_pointer_linker_section (output_bfd
, input_bfd
,
5140 info
, htab
->sdata2
, h
,
5145 /* Handle the TOC16 reloc. We want to use the offset within the .got
5146 section, not the actual VMA. This is appropriate when generating
5147 an embedded ELF object, for which the .got section acts like the
5148 AIX .toc section. */
5149 case R_PPC_TOC16
: /* phony GOT16 relocations */
5150 BFD_ASSERT (sec
!= (asection
*) 0);
5151 BFD_ASSERT (bfd_is_und_section (sec
)
5152 || strcmp (bfd_get_section_name (abfd
, sec
), ".got") == 0
5153 || strcmp (bfd_get_section_name (abfd
, sec
), ".cgot") == 0)
5155 addend
-= sec
->output_section
->vma
+ sec
->output_offset
+ 0x8000;
5158 case R_PPC_PLTREL24
:
5159 /* Relocation is to the entry for this symbol in the
5160 procedure linkage table. */
5161 BFD_ASSERT (h
!= NULL
);
5163 if (h
->plt
.offset
== (bfd_vma
) -1
5164 || htab
->plt
== NULL
)
5166 /* We didn't make a PLT entry for this symbol. This
5167 happens when statically linking PIC code, or when
5168 using -Bsymbolic. */
5172 unresolved_reloc
= FALSE
;
5173 relocation
= (htab
->plt
->output_section
->vma
5174 + htab
->plt
->output_offset
5178 /* Relocate against _SDA_BASE_. */
5179 case R_PPC_SDAREL16
:
5182 const struct elf_link_hash_entry
*sh
;
5184 BFD_ASSERT (sec
!= (asection
*) 0);
5185 name
= bfd_get_section_name (abfd
, sec
->output_section
);
5186 if (! ((strncmp (name
, ".sdata", 6) == 0
5187 && (name
[6] == 0 || name
[6] == '.'))
5188 || (strncmp (name
, ".sbss", 5) == 0
5189 && (name
[5] == 0 || name
[5] == '.'))))
5191 (*_bfd_error_handler
) (_("%s: the target (%s) of a %s relocation is in the wrong output section (%s)"),
5192 bfd_archive_filename (input_bfd
),
5197 sh
= htab
->sdata
->sym_hash
;
5198 addend
-= (sh
->root
.u
.def
.value
5199 + sh
->root
.u
.def
.section
->output_section
->vma
5200 + sh
->root
.u
.def
.section
->output_offset
);
5204 /* Relocate against _SDA2_BASE_. */
5205 case R_PPC_EMB_SDA2REL
:
5208 const struct elf_link_hash_entry
*sh
;
5210 BFD_ASSERT (sec
!= (asection
*) 0);
5211 name
= bfd_get_section_name (abfd
, sec
->output_section
);
5212 if (! (strncmp (name
, ".sdata2", 7) == 0
5213 || strncmp (name
, ".sbss2", 6) == 0))
5215 (*_bfd_error_handler
) (_("%s: the target (%s) of a %s relocation is in the wrong output section (%s)"),
5216 bfd_archive_filename (input_bfd
),
5221 bfd_set_error (bfd_error_bad_value
);
5225 sh
= htab
->sdata2
->sym_hash
;
5226 addend
-= (sh
->root
.u
.def
.value
5227 + sh
->root
.u
.def
.section
->output_section
->vma
5228 + sh
->root
.u
.def
.section
->output_offset
);
5232 /* Relocate against either _SDA_BASE_, _SDA2_BASE_, or 0. */
5233 case R_PPC_EMB_SDA21
:
5234 case R_PPC_EMB_RELSDA
:
5237 const struct elf_link_hash_entry
*sh
;
5240 BFD_ASSERT (sec
!= (asection
*) 0);
5241 name
= bfd_get_section_name (abfd
, sec
->output_section
);
5242 if (((strncmp (name
, ".sdata", 6) == 0
5243 && (name
[6] == 0 || name
[6] == '.'))
5244 || (strncmp (name
, ".sbss", 5) == 0
5245 && (name
[5] == 0 || name
[5] == '.'))))
5248 sh
= htab
->sdata
->sym_hash
;
5249 addend
-= (sh
->root
.u
.def
.value
5250 + sh
->root
.u
.def
.section
->output_section
->vma
5251 + sh
->root
.u
.def
.section
->output_offset
);
5254 else if (strncmp (name
, ".sdata2", 7) == 0
5255 || strncmp (name
, ".sbss2", 6) == 0)
5258 sh
= htab
->sdata2
->sym_hash
;
5259 addend
-= (sh
->root
.u
.def
.value
5260 + sh
->root
.u
.def
.section
->output_section
->vma
5261 + sh
->root
.u
.def
.section
->output_offset
);
5264 else if (strcmp (name
, ".PPC.EMB.sdata0") == 0
5265 || strcmp (name
, ".PPC.EMB.sbss0") == 0)
5272 (*_bfd_error_handler
) (_("%s: the target (%s) of a %s relocation is in the wrong output section (%s)"),
5273 bfd_archive_filename (input_bfd
),
5278 bfd_set_error (bfd_error_bad_value
);
5283 if (r_type
== R_PPC_EMB_SDA21
)
5284 { /* fill in register field */
5285 insn
= bfd_get_32 (output_bfd
, contents
+ rel
->r_offset
);
5286 insn
= (insn
& ~RA_REGISTER_MASK
) | (reg
<< RA_REGISTER_SHIFT
);
5287 bfd_put_32 (output_bfd
, insn
, contents
+ rel
->r_offset
);
5292 /* Relocate against the beginning of the section. */
5294 case R_PPC_SECTOFF_LO
:
5295 case R_PPC_SECTOFF_HI
:
5296 case R_PPC_SECTOFF_HA
:
5297 BFD_ASSERT (sec
!= (asection
*) 0);
5298 addend
-= sec
->output_section
->vma
;
5301 /* Negative relocations. */
5302 case R_PPC_EMB_NADDR32
:
5303 case R_PPC_EMB_NADDR16
:
5304 case R_PPC_EMB_NADDR16_LO
:
5305 case R_PPC_EMB_NADDR16_HI
:
5306 case R_PPC_EMB_NADDR16_HA
:
5307 addend
-= 2 * relocation
;
5311 case R_PPC_GLOB_DAT
:
5312 case R_PPC_JMP_SLOT
:
5313 case R_PPC_RELATIVE
:
5315 case R_PPC_PLTREL32
:
5316 case R_PPC_PLT16_LO
:
5317 case R_PPC_PLT16_HI
:
5318 case R_PPC_PLT16_HA
:
5320 case R_PPC_EMB_RELSEC16
:
5321 case R_PPC_EMB_RELST_LO
:
5322 case R_PPC_EMB_RELST_HI
:
5323 case R_PPC_EMB_RELST_HA
:
5324 case R_PPC_EMB_BIT_FLD
:
5325 (*_bfd_error_handler
)
5326 (_("%s: relocation %s is not yet supported for symbol %s."),
5327 bfd_archive_filename (input_bfd
),
5331 bfd_set_error (bfd_error_invalid_operation
);
5336 /* Do any further special processing. */
5342 case R_PPC_ADDR16_HA
:
5343 case R_PPC_GOT16_HA
:
5344 case R_PPC_PLT16_HA
:
5345 case R_PPC_SECTOFF_HA
:
5346 case R_PPC_TPREL16_HA
:
5347 case R_PPC_DTPREL16_HA
:
5348 case R_PPC_GOT_TLSGD16_HA
:
5349 case R_PPC_GOT_TLSLD16_HA
:
5350 case R_PPC_GOT_TPREL16_HA
:
5351 case R_PPC_GOT_DTPREL16_HA
:
5352 case R_PPC_EMB_NADDR16_HA
:
5353 case R_PPC_EMB_RELST_HA
:
5354 /* It's just possible that this symbol is a weak symbol
5355 that's not actually defined anywhere. In that case,
5356 'sec' would be NULL, and we should leave the symbol
5357 alone (it will be set to zero elsewhere in the link). */
5359 /* Add 0x10000 if sign bit in 0:15 is set.
5360 Bits 0:15 are not used. */
5366 fprintf (stderr
, "\ttype = %s (%d), name = %s, symbol index = %ld, offset = %ld, addend = %ld\n",
5371 (long) rel
->r_offset
,
5375 if (unresolved_reloc
5376 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
5377 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0))
5379 (*_bfd_error_handler
)
5380 (_("%s(%s+0x%lx): unresolvable %s relocation against symbol `%s'"),
5381 bfd_archive_filename (input_bfd
),
5382 bfd_get_section_name (input_bfd
, input_section
),
5383 (long) rel
->r_offset
,
5389 r
= _bfd_final_link_relocate (howto
,
5397 if (r
!= bfd_reloc_ok
)
5399 if (sym_name
== NULL
)
5400 sym_name
= "(null)";
5401 if (r
== bfd_reloc_overflow
)
5406 && h
->root
.type
== bfd_link_hash_undefweak
5407 && howto
->pc_relative
)
5409 /* Assume this is a call protected by other code that
5410 detect the symbol is undefined. If this is the case,
5411 we can safely ignore the overflow. If not, the
5412 program is hosed anyway, and a little warning isn't
5418 if (! (*info
->callbacks
->reloc_overflow
) (info
,
5429 (*_bfd_error_handler
)
5430 (_("%s(%s+0x%lx): %s reloc against `%s': error %d"),
5431 bfd_archive_filename (input_bfd
),
5432 bfd_get_section_name (input_bfd
, input_section
),
5433 (long) rel
->r_offset
, howto
->name
, sym_name
, (int) r
);
5440 fprintf (stderr
, "\n");
5446 static enum elf_reloc_type_class
5447 ppc_elf_reloc_type_class (rela
)
5448 const Elf_Internal_Rela
*rela
;
5450 switch ((int) ELF32_R_TYPE (rela
->r_info
))
5452 case R_PPC_RELATIVE
:
5453 return reloc_class_relative
;
5456 case R_PPC_JMP_SLOT
:
5457 return reloc_class_plt
;
5459 return reloc_class_copy
;
5461 return reloc_class_normal
;
5465 /* Support for core dump NOTE sections. */
5468 ppc_elf_grok_prstatus (abfd
, note
)
5470 Elf_Internal_Note
*note
;
5473 unsigned int raw_size
;
5475 switch (note
->descsz
)
5480 case 268: /* Linux/PPC. */
5482 elf_tdata (abfd
)->core_signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
5485 elf_tdata (abfd
)->core_pid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
5494 /* Make a ".reg/999" section. */
5495 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
5496 raw_size
, note
->descpos
+ offset
);
5500 ppc_elf_grok_psinfo (abfd
, note
)
5502 Elf_Internal_Note
*note
;
5504 switch (note
->descsz
)
5509 case 128: /* Linux/PPC elf_prpsinfo. */
5510 elf_tdata (abfd
)->core_program
5511 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 32, 16);
5512 elf_tdata (abfd
)->core_command
5513 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 48, 80);
5516 /* Note that for some reason, a spurious space is tacked
5517 onto the end of the args in some (at least one anyway)
5518 implementations, so strip it off if it exists. */
5521 char *command
= elf_tdata (abfd
)->core_command
;
5522 int n
= strlen (command
);
5524 if (0 < n
&& command
[n
- 1] == ' ')
5525 command
[n
- 1] = '\0';
5531 /* Very simple linked list structure for recording apuinfo values. */
5532 typedef struct apuinfo_list
5534 struct apuinfo_list
*next
;
5535 unsigned long value
;
5539 static apuinfo_list
* head
;
5541 static void apuinfo_list_init
PARAMS ((void));
5542 static void apuinfo_list_add
PARAMS ((unsigned long));
5543 static unsigned apuinfo_list_length
PARAMS ((void));
5544 static unsigned long apuinfo_list_element
PARAMS ((unsigned long));
5545 static void apuinfo_list_finish
PARAMS ((void));
5547 extern void ppc_elf_begin_write_processing
5548 PARAMS ((bfd
*, struct bfd_link_info
*));
5549 extern void ppc_elf_final_write_processing
5550 PARAMS ((bfd
*, bfd_boolean
));
5551 extern bfd_boolean ppc_elf_write_section
5552 PARAMS ((bfd
*, asection
*, bfd_byte
*));
5556 apuinfo_list_init
PARAMS ((void))
5562 apuinfo_list_add (value
)
5563 unsigned long value
;
5565 apuinfo_list
*entry
= head
;
5567 while (entry
!= NULL
)
5569 if (entry
->value
== value
)
5571 entry
= entry
->next
;
5574 entry
= bfd_malloc (sizeof (* entry
));
5578 entry
->value
= value
;
5584 apuinfo_list_length
PARAMS ((void))
5586 apuinfo_list
*entry
;
5587 unsigned long count
;
5589 for (entry
= head
, count
= 0;
5591 entry
= entry
->next
)
5597 static inline unsigned long
5598 apuinfo_list_element (number
)
5599 unsigned long number
;
5601 apuinfo_list
* entry
;
5605 entry
= entry
->next
)
5608 return entry
? entry
->value
: 0;
5612 apuinfo_list_finish
PARAMS ((void))
5614 apuinfo_list
*entry
;
5616 for (entry
= head
; entry
;)
5618 apuinfo_list
*next
= entry
->next
;
5626 #define APUINFO_SECTION_NAME ".PPC.EMB.apuinfo"
5627 #define APUINFO_LABEL "APUinfo"
5629 /* Scan the input BFDs and create a linked list of
5630 the APUinfo values that will need to be emitted. */
5633 ppc_elf_begin_write_processing (abfd
, link_info
)
5635 struct bfd_link_info
*link_info
;
5640 unsigned num_input_sections
;
5641 bfd_size_type output_section_size
;
5643 unsigned num_entries
;
5644 unsigned long offset
;
5645 unsigned long length
;
5646 const char *error_message
= NULL
;
5648 if (link_info
== NULL
)
5651 /* Scan the input bfds, looking for apuinfo sections. */
5652 num_input_sections
= 0;
5653 output_section_size
= 0;
5655 for (ibfd
= link_info
->input_bfds
; ibfd
; ibfd
= ibfd
->link_next
)
5657 asec
= bfd_get_section_by_name (ibfd
, APUINFO_SECTION_NAME
);
5660 ++ num_input_sections
;
5661 output_section_size
+= asec
->_raw_size
;
5665 /* We need at least one input sections
5666 in order to make merging worthwhile. */
5667 if (num_input_sections
< 1)
5670 /* Just make sure that the output section exists as well. */
5671 asec
= bfd_get_section_by_name (abfd
, APUINFO_SECTION_NAME
);
5675 /* Allocate a buffer for the contents of the input sections. */
5676 buffer
= bfd_malloc (output_section_size
);
5681 apuinfo_list_init ();
5683 /* Read in the input sections contents. */
5684 for (ibfd
= link_info
->input_bfds
; ibfd
; ibfd
= ibfd
->link_next
)
5686 unsigned long datum
;
5689 asec
= bfd_get_section_by_name (ibfd
, APUINFO_SECTION_NAME
);
5693 length
= asec
->_raw_size
;
5696 error_message
= _("corrupt or empty %s section in %s");
5700 if (bfd_seek (ibfd
, asec
->filepos
, SEEK_SET
) != 0
5701 || (bfd_bread (buffer
+ offset
, length
, ibfd
) != length
))
5703 error_message
= _("unable to read in %s section from %s");
5707 /* Process the contents of the section. */
5708 ptr
= buffer
+ offset
;
5709 error_message
= _("corrupt %s section in %s");
5711 /* Verify the contents of the header. Note - we have to
5712 extract the values this way in order to allow for a
5713 host whose endian-ness is different from the target. */
5714 datum
= bfd_get_32 (ibfd
, ptr
);
5715 if (datum
!= sizeof APUINFO_LABEL
)
5718 datum
= bfd_get_32 (ibfd
, ptr
+ 8);
5722 if (strcmp (ptr
+ 12, APUINFO_LABEL
) != 0)
5725 /* Get the number of apuinfo entries. */
5726 datum
= bfd_get_32 (ibfd
, ptr
+ 4);
5727 if ((datum
* 4 + 20) != length
)
5730 /* Make sure that we do not run off the end of the section. */
5731 if (offset
+ length
> output_section_size
)
5734 /* Scan the apuinfo section, building a list of apuinfo numbers. */
5735 for (i
= 0; i
< datum
; i
++)
5736 apuinfo_list_add (bfd_get_32 (ibfd
, ptr
+ 20 + (i
* 4)));
5738 /* Update the offset. */
5742 error_message
= NULL
;
5744 /* Compute the size of the output section. */
5745 num_entries
= apuinfo_list_length ();
5746 output_section_size
= 20 + num_entries
* 4;
5748 asec
= bfd_get_section_by_name (abfd
, APUINFO_SECTION_NAME
);
5750 if (! bfd_set_section_size (abfd
, asec
, output_section_size
))
5752 error_message
= _("warning: unable to set size of %s section in %s");
5758 (*_bfd_error_handler
) (error_message
, APUINFO_SECTION_NAME
,
5759 bfd_archive_filename (ibfd
));
5763 /* Prevent the output section from accumulating the input sections'
5764 contents. We have already stored this in our linked list structure. */
5767 ppc_elf_write_section (abfd
, asec
, contents
)
5768 bfd
*abfd ATTRIBUTE_UNUSED
;
5770 bfd_byte
*contents ATTRIBUTE_UNUSED
;
5772 return (apuinfo_list_length ()
5773 && strcmp (asec
->name
, APUINFO_SECTION_NAME
) == 0);
5777 /* Finally we can generate the output section. */
5780 ppc_elf_final_write_processing (abfd
, linker
)
5782 bfd_boolean linker ATTRIBUTE_UNUSED
;
5787 unsigned num_entries
;
5788 bfd_size_type length
;
5790 asec
= bfd_get_section_by_name (abfd
, APUINFO_SECTION_NAME
);
5794 if (apuinfo_list_length () == 0)
5797 length
= asec
->_raw_size
;
5801 buffer
= bfd_malloc (length
);
5804 (*_bfd_error_handler
)
5805 (_("failed to allocate space for new APUinfo section."));
5809 /* Create the apuinfo header. */
5810 num_entries
= apuinfo_list_length ();
5811 bfd_put_32 (abfd
, sizeof APUINFO_LABEL
, buffer
);
5812 bfd_put_32 (abfd
, num_entries
, buffer
+ 4);
5813 bfd_put_32 (abfd
, 0x2, buffer
+ 8);
5814 strcpy (buffer
+ 12, APUINFO_LABEL
);
5817 for (i
= 0; i
< num_entries
; i
++)
5819 bfd_put_32 (abfd
, apuinfo_list_element (i
), buffer
+ length
);
5823 if (length
!= asec
->_raw_size
)
5824 (*_bfd_error_handler
) (_("failed to compute new APUinfo section."));
5826 if (! bfd_set_section_contents (abfd
, asec
, buffer
, (file_ptr
) 0, length
))
5827 (*_bfd_error_handler
) (_("failed to install new APUinfo section."));
5831 apuinfo_list_finish ();
5834 #define TARGET_LITTLE_SYM bfd_elf32_powerpcle_vec
5835 #define TARGET_LITTLE_NAME "elf32-powerpcle"
5836 #define TARGET_BIG_SYM bfd_elf32_powerpc_vec
5837 #define TARGET_BIG_NAME "elf32-powerpc"
5838 #define ELF_ARCH bfd_arch_powerpc
5839 #define ELF_MACHINE_CODE EM_PPC
5840 #define ELF_MAXPAGESIZE 0x10000
5841 #define elf_info_to_howto ppc_elf_info_to_howto
5843 #ifdef EM_CYGNUS_POWERPC
5844 #define ELF_MACHINE_ALT1 EM_CYGNUS_POWERPC
5848 #define ELF_MACHINE_ALT2 EM_PPC_OLD
5851 #define elf_backend_plt_not_loaded 1
5852 #define elf_backend_got_symbol_offset 4
5853 #define elf_backend_can_gc_sections 1
5854 #define elf_backend_can_refcount 1
5855 #define elf_backend_got_header_size 12
5856 #define elf_backend_plt_header_size PLT_INITIAL_ENTRY_SIZE
5857 #define elf_backend_rela_normal 1
5859 #define bfd_elf32_bfd_merge_private_bfd_data ppc_elf_merge_private_bfd_data
5860 #define bfd_elf32_bfd_relax_section ppc_elf_relax_section
5861 #define bfd_elf32_bfd_reloc_type_lookup ppc_elf_reloc_type_lookup
5862 #define bfd_elf32_bfd_set_private_flags ppc_elf_set_private_flags
5863 #define bfd_elf32_bfd_link_hash_table_create ppc_elf_link_hash_table_create
5865 #define elf_backend_object_p ppc_elf_object_p
5866 #define elf_backend_gc_mark_hook ppc_elf_gc_mark_hook
5867 #define elf_backend_gc_sweep_hook ppc_elf_gc_sweep_hook
5868 #define elf_backend_section_from_shdr ppc_elf_section_from_shdr
5869 #define elf_backend_relocate_section ppc_elf_relocate_section
5870 #define elf_backend_create_dynamic_sections ppc_elf_create_dynamic_sections
5871 #define elf_backend_check_relocs ppc_elf_check_relocs
5872 #define elf_backend_copy_indirect_symbol ppc_elf_copy_indirect_symbol
5873 #define elf_backend_adjust_dynamic_symbol ppc_elf_adjust_dynamic_symbol
5874 #define elf_backend_add_symbol_hook ppc_elf_add_symbol_hook
5875 #define elf_backend_size_dynamic_sections ppc_elf_size_dynamic_sections
5876 #define elf_backend_finish_dynamic_symbol ppc_elf_finish_dynamic_symbol
5877 #define elf_backend_finish_dynamic_sections ppc_elf_finish_dynamic_sections
5878 #define elf_backend_fake_sections ppc_elf_fake_sections
5879 #define elf_backend_additional_program_headers ppc_elf_additional_program_headers
5880 #define elf_backend_modify_segment_map ppc_elf_modify_segment_map
5881 #define elf_backend_grok_prstatus ppc_elf_grok_prstatus
5882 #define elf_backend_grok_psinfo ppc_elf_grok_psinfo
5883 #define elf_backend_reloc_type_class ppc_elf_reloc_type_class
5884 #define elf_backend_begin_write_processing ppc_elf_begin_write_processing
5885 #define elf_backend_final_write_processing ppc_elf_final_write_processing
5886 #define elf_backend_write_section ppc_elf_write_section
5888 #include "elf32-target.h"