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
378 && ind
->root
.type
!= bfd_link_hash_indirect
379 && (dir
->elf_link_hash_flags
& ELF_LINK_HASH_DYNAMIC_ADJUSTED
) != 0)
380 /* If called to transfer flags for a weakdef during processing
381 of elf_adjust_dynamic_symbol, don't copy ELF_LINK_NON_GOT_REF.
382 We clear it ourselves for ELIMINATE_COPY_RELOCS. */
383 dir
->elf_link_hash_flags
|=
384 (ind
->elf_link_hash_flags
& (ELF_LINK_HASH_REF_DYNAMIC
385 | ELF_LINK_HASH_REF_REGULAR
386 | ELF_LINK_HASH_REF_REGULAR_NONWEAK
));
388 _bfd_elf_link_hash_copy_indirect (bed
, dir
, ind
);
391 static reloc_howto_type
*ppc_elf_howto_table
[(int) R_PPC_max
];
393 static reloc_howto_type ppc_elf_howto_raw
[] = {
394 /* This reloc does nothing. */
395 HOWTO (R_PPC_NONE
, /* type */
397 2, /* size (0 = byte, 1 = short, 2 = long) */
399 FALSE
, /* pc_relative */
401 complain_overflow_bitfield
, /* complain_on_overflow */
402 bfd_elf_generic_reloc
, /* special_function */
403 "R_PPC_NONE", /* name */
404 FALSE
, /* partial_inplace */
407 FALSE
), /* pcrel_offset */
409 /* A standard 32 bit relocation. */
410 HOWTO (R_PPC_ADDR32
, /* type */
412 2, /* size (0 = byte, 1 = short, 2 = long) */
414 FALSE
, /* pc_relative */
416 complain_overflow_bitfield
, /* complain_on_overflow */
417 bfd_elf_generic_reloc
, /* special_function */
418 "R_PPC_ADDR32", /* name */
419 FALSE
, /* partial_inplace */
421 0xffffffff, /* dst_mask */
422 FALSE
), /* pcrel_offset */
424 /* An absolute 26 bit branch; the lower two bits must be zero.
425 FIXME: we don't check that, we just clear them. */
426 HOWTO (R_PPC_ADDR24
, /* type */
428 2, /* size (0 = byte, 1 = short, 2 = long) */
430 FALSE
, /* pc_relative */
432 complain_overflow_bitfield
, /* complain_on_overflow */
433 bfd_elf_generic_reloc
, /* special_function */
434 "R_PPC_ADDR24", /* name */
435 FALSE
, /* partial_inplace */
437 0x3fffffc, /* dst_mask */
438 FALSE
), /* pcrel_offset */
440 /* A standard 16 bit relocation. */
441 HOWTO (R_PPC_ADDR16
, /* type */
443 1, /* size (0 = byte, 1 = short, 2 = long) */
445 FALSE
, /* pc_relative */
447 complain_overflow_bitfield
, /* complain_on_overflow */
448 bfd_elf_generic_reloc
, /* special_function */
449 "R_PPC_ADDR16", /* name */
450 FALSE
, /* partial_inplace */
452 0xffff, /* dst_mask */
453 FALSE
), /* pcrel_offset */
455 /* A 16 bit relocation without overflow. */
456 HOWTO (R_PPC_ADDR16_LO
, /* type */
458 1, /* size (0 = byte, 1 = short, 2 = long) */
460 FALSE
, /* pc_relative */
462 complain_overflow_dont
,/* complain_on_overflow */
463 bfd_elf_generic_reloc
, /* special_function */
464 "R_PPC_ADDR16_LO", /* name */
465 FALSE
, /* partial_inplace */
467 0xffff, /* dst_mask */
468 FALSE
), /* pcrel_offset */
470 /* The high order 16 bits of an address. */
471 HOWTO (R_PPC_ADDR16_HI
, /* type */
473 1, /* size (0 = byte, 1 = short, 2 = long) */
475 FALSE
, /* pc_relative */
477 complain_overflow_dont
, /* complain_on_overflow */
478 bfd_elf_generic_reloc
, /* special_function */
479 "R_PPC_ADDR16_HI", /* name */
480 FALSE
, /* partial_inplace */
482 0xffff, /* dst_mask */
483 FALSE
), /* pcrel_offset */
485 /* The high order 16 bits of an address, plus 1 if the contents of
486 the low 16 bits, treated as a signed number, is negative. */
487 HOWTO (R_PPC_ADDR16_HA
, /* type */
489 1, /* size (0 = byte, 1 = short, 2 = long) */
491 FALSE
, /* pc_relative */
493 complain_overflow_dont
, /* complain_on_overflow */
494 ppc_elf_addr16_ha_reloc
, /* special_function */
495 "R_PPC_ADDR16_HA", /* name */
496 FALSE
, /* partial_inplace */
498 0xffff, /* dst_mask */
499 FALSE
), /* pcrel_offset */
501 /* An absolute 16 bit branch; the lower two bits must be zero.
502 FIXME: we don't check that, we just clear them. */
503 HOWTO (R_PPC_ADDR14
, /* type */
505 2, /* size (0 = byte, 1 = short, 2 = long) */
507 FALSE
, /* pc_relative */
509 complain_overflow_bitfield
, /* complain_on_overflow */
510 bfd_elf_generic_reloc
, /* special_function */
511 "R_PPC_ADDR14", /* name */
512 FALSE
, /* partial_inplace */
514 0xfffc, /* dst_mask */
515 FALSE
), /* pcrel_offset */
517 /* An absolute 16 bit branch, for which bit 10 should be set to
518 indicate that the branch is expected to be taken. The lower two
519 bits must be zero. */
520 HOWTO (R_PPC_ADDR14_BRTAKEN
, /* type */
522 2, /* size (0 = byte, 1 = short, 2 = long) */
524 FALSE
, /* pc_relative */
526 complain_overflow_bitfield
, /* complain_on_overflow */
527 bfd_elf_generic_reloc
, /* special_function */
528 "R_PPC_ADDR14_BRTAKEN",/* name */
529 FALSE
, /* partial_inplace */
531 0xfffc, /* dst_mask */
532 FALSE
), /* pcrel_offset */
534 /* An absolute 16 bit branch, for which bit 10 should be set to
535 indicate that the branch is not expected to be taken. The lower
536 two bits must be zero. */
537 HOWTO (R_PPC_ADDR14_BRNTAKEN
, /* type */
539 2, /* size (0 = byte, 1 = short, 2 = long) */
541 FALSE
, /* pc_relative */
543 complain_overflow_bitfield
, /* complain_on_overflow */
544 bfd_elf_generic_reloc
, /* special_function */
545 "R_PPC_ADDR14_BRNTAKEN",/* name */
546 FALSE
, /* partial_inplace */
548 0xfffc, /* dst_mask */
549 FALSE
), /* pcrel_offset */
551 /* A relative 26 bit branch; the lower two bits must be zero. */
552 HOWTO (R_PPC_REL24
, /* type */
554 2, /* size (0 = byte, 1 = short, 2 = long) */
556 TRUE
, /* pc_relative */
558 complain_overflow_signed
, /* complain_on_overflow */
559 bfd_elf_generic_reloc
, /* special_function */
560 "R_PPC_REL24", /* name */
561 FALSE
, /* partial_inplace */
563 0x3fffffc, /* dst_mask */
564 TRUE
), /* pcrel_offset */
566 /* A relative 16 bit branch; the lower two bits must be zero. */
567 HOWTO (R_PPC_REL14
, /* type */
569 2, /* size (0 = byte, 1 = short, 2 = long) */
571 TRUE
, /* pc_relative */
573 complain_overflow_signed
, /* complain_on_overflow */
574 bfd_elf_generic_reloc
, /* special_function */
575 "R_PPC_REL14", /* name */
576 FALSE
, /* partial_inplace */
578 0xfffc, /* dst_mask */
579 TRUE
), /* pcrel_offset */
581 /* A relative 16 bit branch. Bit 10 should be set to indicate that
582 the branch is expected to be taken. The lower two bits must be
584 HOWTO (R_PPC_REL14_BRTAKEN
, /* type */
586 2, /* size (0 = byte, 1 = short, 2 = long) */
588 TRUE
, /* pc_relative */
590 complain_overflow_signed
, /* complain_on_overflow */
591 bfd_elf_generic_reloc
, /* special_function */
592 "R_PPC_REL14_BRTAKEN", /* name */
593 FALSE
, /* partial_inplace */
595 0xfffc, /* dst_mask */
596 TRUE
), /* pcrel_offset */
598 /* A relative 16 bit branch. Bit 10 should be set to indicate that
599 the branch is not expected to be taken. The lower two bits must
601 HOWTO (R_PPC_REL14_BRNTAKEN
, /* type */
603 2, /* size (0 = byte, 1 = short, 2 = long) */
605 TRUE
, /* pc_relative */
607 complain_overflow_signed
, /* complain_on_overflow */
608 bfd_elf_generic_reloc
, /* special_function */
609 "R_PPC_REL14_BRNTAKEN",/* name */
610 FALSE
, /* partial_inplace */
612 0xfffc, /* dst_mask */
613 TRUE
), /* pcrel_offset */
615 /* Like R_PPC_ADDR16, but referring to the GOT table entry for the
617 HOWTO (R_PPC_GOT16
, /* type */
619 1, /* size (0 = byte, 1 = short, 2 = long) */
621 FALSE
, /* pc_relative */
623 complain_overflow_signed
, /* complain_on_overflow */
624 bfd_elf_generic_reloc
, /* special_function */
625 "R_PPC_GOT16", /* name */
626 FALSE
, /* partial_inplace */
628 0xffff, /* dst_mask */
629 FALSE
), /* pcrel_offset */
631 /* Like R_PPC_ADDR16_LO, but referring to the GOT table entry for
633 HOWTO (R_PPC_GOT16_LO
, /* type */
635 1, /* size (0 = byte, 1 = short, 2 = long) */
637 FALSE
, /* pc_relative */
639 complain_overflow_dont
, /* complain_on_overflow */
640 bfd_elf_generic_reloc
, /* special_function */
641 "R_PPC_GOT16_LO", /* name */
642 FALSE
, /* partial_inplace */
644 0xffff, /* dst_mask */
645 FALSE
), /* pcrel_offset */
647 /* Like R_PPC_ADDR16_HI, but referring to the GOT table entry for
649 HOWTO (R_PPC_GOT16_HI
, /* type */
651 1, /* size (0 = byte, 1 = short, 2 = long) */
653 FALSE
, /* pc_relative */
655 complain_overflow_bitfield
, /* complain_on_overflow */
656 bfd_elf_generic_reloc
, /* special_function */
657 "R_PPC_GOT16_HI", /* name */
658 FALSE
, /* partial_inplace */
660 0xffff, /* dst_mask */
661 FALSE
), /* pcrel_offset */
663 /* Like R_PPC_ADDR16_HA, but referring to the GOT table entry for
665 HOWTO (R_PPC_GOT16_HA
, /* type */
667 1, /* size (0 = byte, 1 = short, 2 = long) */
669 FALSE
, /* pc_relative */
671 complain_overflow_bitfield
, /* complain_on_overflow */
672 ppc_elf_addr16_ha_reloc
, /* special_function */
673 "R_PPC_GOT16_HA", /* name */
674 FALSE
, /* partial_inplace */
676 0xffff, /* dst_mask */
677 FALSE
), /* pcrel_offset */
679 /* Like R_PPC_REL24, but referring to the procedure linkage table
680 entry for the symbol. */
681 HOWTO (R_PPC_PLTREL24
, /* type */
683 2, /* size (0 = byte, 1 = short, 2 = long) */
685 TRUE
, /* pc_relative */
687 complain_overflow_signed
, /* complain_on_overflow */
688 bfd_elf_generic_reloc
, /* special_function */
689 "R_PPC_PLTREL24", /* name */
690 FALSE
, /* partial_inplace */
692 0x3fffffc, /* dst_mask */
693 TRUE
), /* pcrel_offset */
695 /* This is used only by the dynamic linker. The symbol should exist
696 both in the object being run and in some shared library. The
697 dynamic linker copies the data addressed by the symbol from the
698 shared library into the object, because the object being
699 run has to have the data at some particular address. */
700 HOWTO (R_PPC_COPY
, /* type */
702 2, /* size (0 = byte, 1 = short, 2 = long) */
704 FALSE
, /* pc_relative */
706 complain_overflow_bitfield
, /* complain_on_overflow */
707 bfd_elf_generic_reloc
, /* special_function */
708 "R_PPC_COPY", /* name */
709 FALSE
, /* partial_inplace */
712 FALSE
), /* pcrel_offset */
714 /* Like R_PPC_ADDR32, but used when setting global offset table
716 HOWTO (R_PPC_GLOB_DAT
, /* type */
718 2, /* size (0 = byte, 1 = short, 2 = long) */
720 FALSE
, /* pc_relative */
722 complain_overflow_bitfield
, /* complain_on_overflow */
723 bfd_elf_generic_reloc
, /* special_function */
724 "R_PPC_GLOB_DAT", /* name */
725 FALSE
, /* partial_inplace */
727 0xffffffff, /* dst_mask */
728 FALSE
), /* pcrel_offset */
730 /* Marks a procedure linkage table entry for a symbol. */
731 HOWTO (R_PPC_JMP_SLOT
, /* type */
733 2, /* size (0 = byte, 1 = short, 2 = long) */
735 FALSE
, /* pc_relative */
737 complain_overflow_bitfield
, /* complain_on_overflow */
738 bfd_elf_generic_reloc
, /* special_function */
739 "R_PPC_JMP_SLOT", /* name */
740 FALSE
, /* partial_inplace */
743 FALSE
), /* pcrel_offset */
745 /* Used only by the dynamic linker. When the object is run, this
746 longword is set to the load address of the object, plus the
748 HOWTO (R_PPC_RELATIVE
, /* type */
750 2, /* size (0 = byte, 1 = short, 2 = long) */
752 FALSE
, /* pc_relative */
754 complain_overflow_bitfield
, /* complain_on_overflow */
755 bfd_elf_generic_reloc
, /* special_function */
756 "R_PPC_RELATIVE", /* name */
757 FALSE
, /* partial_inplace */
759 0xffffffff, /* dst_mask */
760 FALSE
), /* pcrel_offset */
762 /* Like R_PPC_REL24, but uses the value of the symbol within the
763 object rather than the final value. Normally used for
764 _GLOBAL_OFFSET_TABLE_. */
765 HOWTO (R_PPC_LOCAL24PC
, /* type */
767 2, /* size (0 = byte, 1 = short, 2 = long) */
769 TRUE
, /* pc_relative */
771 complain_overflow_signed
, /* complain_on_overflow */
772 bfd_elf_generic_reloc
, /* special_function */
773 "R_PPC_LOCAL24PC", /* name */
774 FALSE
, /* partial_inplace */
776 0x3fffffc, /* dst_mask */
777 TRUE
), /* pcrel_offset */
779 /* Like R_PPC_ADDR32, but may be unaligned. */
780 HOWTO (R_PPC_UADDR32
, /* type */
782 2, /* size (0 = byte, 1 = short, 2 = long) */
784 FALSE
, /* pc_relative */
786 complain_overflow_bitfield
, /* complain_on_overflow */
787 bfd_elf_generic_reloc
, /* special_function */
788 "R_PPC_UADDR32", /* name */
789 FALSE
, /* partial_inplace */
791 0xffffffff, /* dst_mask */
792 FALSE
), /* pcrel_offset */
794 /* Like R_PPC_ADDR16, but may be unaligned. */
795 HOWTO (R_PPC_UADDR16
, /* type */
797 1, /* size (0 = byte, 1 = short, 2 = long) */
799 FALSE
, /* pc_relative */
801 complain_overflow_bitfield
, /* complain_on_overflow */
802 bfd_elf_generic_reloc
, /* special_function */
803 "R_PPC_UADDR16", /* name */
804 FALSE
, /* partial_inplace */
806 0xffff, /* dst_mask */
807 FALSE
), /* pcrel_offset */
809 /* 32-bit PC relative */
810 HOWTO (R_PPC_REL32
, /* type */
812 2, /* size (0 = byte, 1 = short, 2 = long) */
814 TRUE
, /* pc_relative */
816 complain_overflow_bitfield
, /* complain_on_overflow */
817 bfd_elf_generic_reloc
, /* special_function */
818 "R_PPC_REL32", /* name */
819 FALSE
, /* partial_inplace */
821 0xffffffff, /* dst_mask */
822 TRUE
), /* pcrel_offset */
824 /* 32-bit relocation to the symbol's procedure linkage table.
825 FIXME: not supported. */
826 HOWTO (R_PPC_PLT32
, /* type */
828 2, /* size (0 = byte, 1 = short, 2 = long) */
830 FALSE
, /* pc_relative */
832 complain_overflow_bitfield
, /* complain_on_overflow */
833 bfd_elf_generic_reloc
, /* special_function */
834 "R_PPC_PLT32", /* name */
835 FALSE
, /* partial_inplace */
838 FALSE
), /* pcrel_offset */
840 /* 32-bit PC relative relocation to the symbol's procedure linkage table.
841 FIXME: not supported. */
842 HOWTO (R_PPC_PLTREL32
, /* type */
844 2, /* size (0 = byte, 1 = short, 2 = long) */
846 TRUE
, /* pc_relative */
848 complain_overflow_bitfield
, /* complain_on_overflow */
849 bfd_elf_generic_reloc
, /* special_function */
850 "R_PPC_PLTREL32", /* name */
851 FALSE
, /* partial_inplace */
854 TRUE
), /* pcrel_offset */
856 /* Like R_PPC_ADDR16_LO, but referring to the PLT table entry for
858 HOWTO (R_PPC_PLT16_LO
, /* type */
860 1, /* size (0 = byte, 1 = short, 2 = long) */
862 FALSE
, /* pc_relative */
864 complain_overflow_dont
, /* complain_on_overflow */
865 bfd_elf_generic_reloc
, /* special_function */
866 "R_PPC_PLT16_LO", /* name */
867 FALSE
, /* partial_inplace */
869 0xffff, /* dst_mask */
870 FALSE
), /* pcrel_offset */
872 /* Like R_PPC_ADDR16_HI, but referring to the PLT table entry for
874 HOWTO (R_PPC_PLT16_HI
, /* type */
876 1, /* size (0 = byte, 1 = short, 2 = long) */
878 FALSE
, /* pc_relative */
880 complain_overflow_bitfield
, /* complain_on_overflow */
881 bfd_elf_generic_reloc
, /* special_function */
882 "R_PPC_PLT16_HI", /* name */
883 FALSE
, /* partial_inplace */
885 0xffff, /* dst_mask */
886 FALSE
), /* pcrel_offset */
888 /* Like R_PPC_ADDR16_HA, but referring to the PLT table entry for
890 HOWTO (R_PPC_PLT16_HA
, /* type */
892 1, /* size (0 = byte, 1 = short, 2 = long) */
894 FALSE
, /* pc_relative */
896 complain_overflow_bitfield
, /* complain_on_overflow */
897 ppc_elf_addr16_ha_reloc
, /* special_function */
898 "R_PPC_PLT16_HA", /* name */
899 FALSE
, /* partial_inplace */
901 0xffff, /* dst_mask */
902 FALSE
), /* pcrel_offset */
904 /* A sign-extended 16 bit value relative to _SDA_BASE_, for use with
906 HOWTO (R_PPC_SDAREL16
, /* type */
908 1, /* size (0 = byte, 1 = short, 2 = long) */
910 FALSE
, /* pc_relative */
912 complain_overflow_signed
, /* complain_on_overflow */
913 bfd_elf_generic_reloc
, /* special_function */
914 "R_PPC_SDAREL16", /* name */
915 FALSE
, /* partial_inplace */
917 0xffff, /* dst_mask */
918 FALSE
), /* pcrel_offset */
920 /* 16-bit section relative relocation. */
921 HOWTO (R_PPC_SECTOFF
, /* type */
923 1, /* size (0 = byte, 1 = short, 2 = long) */
925 FALSE
, /* pc_relative */
927 complain_overflow_bitfield
, /* complain_on_overflow */
928 bfd_elf_generic_reloc
, /* special_function */
929 "R_PPC_SECTOFF", /* name */
930 FALSE
, /* partial_inplace */
932 0xffff, /* dst_mask */
933 FALSE
), /* pcrel_offset */
935 /* 16-bit lower half section relative relocation. */
936 HOWTO (R_PPC_SECTOFF_LO
, /* type */
938 1, /* size (0 = byte, 1 = short, 2 = long) */
940 FALSE
, /* pc_relative */
942 complain_overflow_dont
, /* complain_on_overflow */
943 bfd_elf_generic_reloc
, /* special_function */
944 "R_PPC_SECTOFF_LO", /* name */
945 FALSE
, /* partial_inplace */
947 0xffff, /* dst_mask */
948 FALSE
), /* pcrel_offset */
950 /* 16-bit upper half section relative relocation. */
951 HOWTO (R_PPC_SECTOFF_HI
, /* type */
953 1, /* size (0 = byte, 1 = short, 2 = long) */
955 FALSE
, /* pc_relative */
957 complain_overflow_bitfield
, /* complain_on_overflow */
958 bfd_elf_generic_reloc
, /* special_function */
959 "R_PPC_SECTOFF_HI", /* name */
960 FALSE
, /* partial_inplace */
962 0xffff, /* dst_mask */
963 FALSE
), /* pcrel_offset */
965 /* 16-bit upper half adjusted section relative relocation. */
966 HOWTO (R_PPC_SECTOFF_HA
, /* type */
968 1, /* size (0 = byte, 1 = short, 2 = long) */
970 FALSE
, /* pc_relative */
972 complain_overflow_bitfield
, /* complain_on_overflow */
973 ppc_elf_addr16_ha_reloc
, /* special_function */
974 "R_PPC_SECTOFF_HA", /* name */
975 FALSE
, /* partial_inplace */
977 0xffff, /* dst_mask */
978 FALSE
), /* pcrel_offset */
980 /* Marker reloc for TLS. */
983 2, /* size (0 = byte, 1 = short, 2 = long) */
985 FALSE
, /* pc_relative */
987 complain_overflow_dont
, /* complain_on_overflow */
988 bfd_elf_generic_reloc
, /* special_function */
989 "R_PPC_TLS", /* name */
990 FALSE
, /* partial_inplace */
993 FALSE
), /* pcrel_offset */
995 /* Computes the load module index of the load module that contains the
996 definition of its TLS sym. */
997 HOWTO (R_PPC_DTPMOD32
,
999 2, /* size (0 = byte, 1 = short, 2 = long) */
1001 FALSE
, /* pc_relative */
1003 complain_overflow_dont
, /* complain_on_overflow */
1004 ppc_elf_unhandled_reloc
, /* special_function */
1005 "R_PPC_DTPMOD32", /* name */
1006 FALSE
, /* partial_inplace */
1008 0xffffffff, /* dst_mask */
1009 FALSE
), /* pcrel_offset */
1011 /* Computes a dtv-relative displacement, the difference between the value
1012 of sym+add and the base address of the thread-local storage block that
1013 contains the definition of sym, minus 0x8000. */
1014 HOWTO (R_PPC_DTPREL32
,
1016 2, /* size (0 = byte, 1 = short, 2 = long) */
1018 FALSE
, /* pc_relative */
1020 complain_overflow_dont
, /* complain_on_overflow */
1021 ppc_elf_unhandled_reloc
, /* special_function */
1022 "R_PPC_DTPREL32", /* name */
1023 FALSE
, /* partial_inplace */
1025 0xffffffff, /* dst_mask */
1026 FALSE
), /* pcrel_offset */
1028 /* A 16 bit dtprel reloc. */
1029 HOWTO (R_PPC_DTPREL16
,
1031 1, /* size (0 = byte, 1 = short, 2 = long) */
1033 FALSE
, /* pc_relative */
1035 complain_overflow_signed
, /* complain_on_overflow */
1036 ppc_elf_unhandled_reloc
, /* special_function */
1037 "R_PPC_DTPREL16", /* name */
1038 FALSE
, /* partial_inplace */
1040 0xffff, /* dst_mask */
1041 FALSE
), /* pcrel_offset */
1043 /* Like DTPREL16, but no overflow. */
1044 HOWTO (R_PPC_DTPREL16_LO
,
1046 1, /* size (0 = byte, 1 = short, 2 = long) */
1048 FALSE
, /* pc_relative */
1050 complain_overflow_dont
, /* complain_on_overflow */
1051 ppc_elf_unhandled_reloc
, /* special_function */
1052 "R_PPC_DTPREL16_LO", /* name */
1053 FALSE
, /* partial_inplace */
1055 0xffff, /* dst_mask */
1056 FALSE
), /* pcrel_offset */
1058 /* Like DTPREL16_LO, but next higher group of 16 bits. */
1059 HOWTO (R_PPC_DTPREL16_HI
,
1060 16, /* rightshift */
1061 1, /* size (0 = byte, 1 = short, 2 = long) */
1063 FALSE
, /* pc_relative */
1065 complain_overflow_dont
, /* complain_on_overflow */
1066 ppc_elf_unhandled_reloc
, /* special_function */
1067 "R_PPC_DTPREL16_HI", /* name */
1068 FALSE
, /* partial_inplace */
1070 0xffff, /* dst_mask */
1071 FALSE
), /* pcrel_offset */
1073 /* Like DTPREL16_HI, but adjust for low 16 bits. */
1074 HOWTO (R_PPC_DTPREL16_HA
,
1075 16, /* rightshift */
1076 1, /* size (0 = byte, 1 = short, 2 = long) */
1078 FALSE
, /* pc_relative */
1080 complain_overflow_dont
, /* complain_on_overflow */
1081 ppc_elf_unhandled_reloc
, /* special_function */
1082 "R_PPC_DTPREL16_HA", /* name */
1083 FALSE
, /* partial_inplace */
1085 0xffff, /* dst_mask */
1086 FALSE
), /* pcrel_offset */
1088 /* Computes a tp-relative displacement, the difference between the value of
1089 sym+add and the value of the thread pointer (r13). */
1090 HOWTO (R_PPC_TPREL32
,
1092 2, /* size (0 = byte, 1 = short, 2 = long) */
1094 FALSE
, /* pc_relative */
1096 complain_overflow_dont
, /* complain_on_overflow */
1097 ppc_elf_unhandled_reloc
, /* special_function */
1098 "R_PPC_TPREL32", /* name */
1099 FALSE
, /* partial_inplace */
1101 0xffffffff, /* dst_mask */
1102 FALSE
), /* pcrel_offset */
1104 /* A 16 bit tprel reloc. */
1105 HOWTO (R_PPC_TPREL16
,
1107 1, /* size (0 = byte, 1 = short, 2 = long) */
1109 FALSE
, /* pc_relative */
1111 complain_overflow_signed
, /* complain_on_overflow */
1112 ppc_elf_unhandled_reloc
, /* special_function */
1113 "R_PPC_TPREL16", /* name */
1114 FALSE
, /* partial_inplace */
1116 0xffff, /* dst_mask */
1117 FALSE
), /* pcrel_offset */
1119 /* Like TPREL16, but no overflow. */
1120 HOWTO (R_PPC_TPREL16_LO
,
1122 1, /* size (0 = byte, 1 = short, 2 = long) */
1124 FALSE
, /* pc_relative */
1126 complain_overflow_dont
, /* complain_on_overflow */
1127 ppc_elf_unhandled_reloc
, /* special_function */
1128 "R_PPC_TPREL16_LO", /* name */
1129 FALSE
, /* partial_inplace */
1131 0xffff, /* dst_mask */
1132 FALSE
), /* pcrel_offset */
1134 /* Like TPREL16_LO, but next higher group of 16 bits. */
1135 HOWTO (R_PPC_TPREL16_HI
,
1136 16, /* rightshift */
1137 1, /* size (0 = byte, 1 = short, 2 = long) */
1139 FALSE
, /* pc_relative */
1141 complain_overflow_dont
, /* complain_on_overflow */
1142 ppc_elf_unhandled_reloc
, /* special_function */
1143 "R_PPC_TPREL16_HI", /* name */
1144 FALSE
, /* partial_inplace */
1146 0xffff, /* dst_mask */
1147 FALSE
), /* pcrel_offset */
1149 /* Like TPREL16_HI, but adjust for low 16 bits. */
1150 HOWTO (R_PPC_TPREL16_HA
,
1151 16, /* rightshift */
1152 1, /* size (0 = byte, 1 = short, 2 = long) */
1154 FALSE
, /* pc_relative */
1156 complain_overflow_dont
, /* complain_on_overflow */
1157 ppc_elf_unhandled_reloc
, /* special_function */
1158 "R_PPC_TPREL16_HA", /* name */
1159 FALSE
, /* partial_inplace */
1161 0xffff, /* dst_mask */
1162 FALSE
), /* pcrel_offset */
1164 /* Allocates two contiguous entries in the GOT to hold a tls_index structure,
1165 with values (sym+add)@dtpmod and (sym+add)@dtprel, and computes the offset
1166 to the first entry. */
1167 HOWTO (R_PPC_GOT_TLSGD16
,
1169 1, /* size (0 = byte, 1 = short, 2 = long) */
1171 FALSE
, /* pc_relative */
1173 complain_overflow_signed
, /* complain_on_overflow */
1174 ppc_elf_unhandled_reloc
, /* special_function */
1175 "R_PPC_GOT_TLSGD16", /* name */
1176 FALSE
, /* partial_inplace */
1178 0xffff, /* dst_mask */
1179 FALSE
), /* pcrel_offset */
1181 /* Like GOT_TLSGD16, but no overflow. */
1182 HOWTO (R_PPC_GOT_TLSGD16_LO
,
1184 1, /* size (0 = byte, 1 = short, 2 = long) */
1186 FALSE
, /* pc_relative */
1188 complain_overflow_dont
, /* complain_on_overflow */
1189 ppc_elf_unhandled_reloc
, /* special_function */
1190 "R_PPC_GOT_TLSGD16_LO", /* name */
1191 FALSE
, /* partial_inplace */
1193 0xffff, /* dst_mask */
1194 FALSE
), /* pcrel_offset */
1196 /* Like GOT_TLSGD16_LO, but next higher group of 16 bits. */
1197 HOWTO (R_PPC_GOT_TLSGD16_HI
,
1198 16, /* rightshift */
1199 1, /* size (0 = byte, 1 = short, 2 = long) */
1201 FALSE
, /* pc_relative */
1203 complain_overflow_dont
, /* complain_on_overflow */
1204 ppc_elf_unhandled_reloc
, /* special_function */
1205 "R_PPC_GOT_TLSGD16_HI", /* name */
1206 FALSE
, /* partial_inplace */
1208 0xffff, /* dst_mask */
1209 FALSE
), /* pcrel_offset */
1211 /* Like GOT_TLSGD16_HI, but adjust for low 16 bits. */
1212 HOWTO (R_PPC_GOT_TLSGD16_HA
,
1213 16, /* rightshift */
1214 1, /* size (0 = byte, 1 = short, 2 = long) */
1216 FALSE
, /* pc_relative */
1218 complain_overflow_dont
, /* complain_on_overflow */
1219 ppc_elf_unhandled_reloc
, /* special_function */
1220 "R_PPC_GOT_TLSGD16_HA", /* name */
1221 FALSE
, /* partial_inplace */
1223 0xffff, /* dst_mask */
1224 FALSE
), /* pcrel_offset */
1226 /* Allocates two contiguous entries in the GOT to hold a tls_index structure,
1227 with values (sym+add)@dtpmod and zero, and computes the offset to the
1229 HOWTO (R_PPC_GOT_TLSLD16
,
1231 1, /* size (0 = byte, 1 = short, 2 = long) */
1233 FALSE
, /* pc_relative */
1235 complain_overflow_signed
, /* complain_on_overflow */
1236 ppc_elf_unhandled_reloc
, /* special_function */
1237 "R_PPC_GOT_TLSLD16", /* name */
1238 FALSE
, /* partial_inplace */
1240 0xffff, /* dst_mask */
1241 FALSE
), /* pcrel_offset */
1243 /* Like GOT_TLSLD16, but no overflow. */
1244 HOWTO (R_PPC_GOT_TLSLD16_LO
,
1246 1, /* size (0 = byte, 1 = short, 2 = long) */
1248 FALSE
, /* pc_relative */
1250 complain_overflow_dont
, /* complain_on_overflow */
1251 ppc_elf_unhandled_reloc
, /* special_function */
1252 "R_PPC_GOT_TLSLD16_LO", /* name */
1253 FALSE
, /* partial_inplace */
1255 0xffff, /* dst_mask */
1256 FALSE
), /* pcrel_offset */
1258 /* Like GOT_TLSLD16_LO, but next higher group of 16 bits. */
1259 HOWTO (R_PPC_GOT_TLSLD16_HI
,
1260 16, /* rightshift */
1261 1, /* size (0 = byte, 1 = short, 2 = long) */
1263 FALSE
, /* pc_relative */
1265 complain_overflow_dont
, /* complain_on_overflow */
1266 ppc_elf_unhandled_reloc
, /* special_function */
1267 "R_PPC_GOT_TLSLD16_HI", /* name */
1268 FALSE
, /* partial_inplace */
1270 0xffff, /* dst_mask */
1271 FALSE
), /* pcrel_offset */
1273 /* Like GOT_TLSLD16_HI, but adjust for low 16 bits. */
1274 HOWTO (R_PPC_GOT_TLSLD16_HA
,
1275 16, /* rightshift */
1276 1, /* size (0 = byte, 1 = short, 2 = long) */
1278 FALSE
, /* pc_relative */
1280 complain_overflow_dont
, /* complain_on_overflow */
1281 ppc_elf_unhandled_reloc
, /* special_function */
1282 "R_PPC_GOT_TLSLD16_HA", /* name */
1283 FALSE
, /* partial_inplace */
1285 0xffff, /* dst_mask */
1286 FALSE
), /* pcrel_offset */
1288 /* Allocates an entry in the GOT with value (sym+add)@dtprel, and computes
1289 the offset to the entry. */
1290 HOWTO (R_PPC_GOT_DTPREL16
,
1292 1, /* size (0 = byte, 1 = short, 2 = long) */
1294 FALSE
, /* pc_relative */
1296 complain_overflow_signed
, /* complain_on_overflow */
1297 ppc_elf_unhandled_reloc
, /* special_function */
1298 "R_PPC_GOT_DTPREL16", /* name */
1299 FALSE
, /* partial_inplace */
1301 0xffff, /* dst_mask */
1302 FALSE
), /* pcrel_offset */
1304 /* Like GOT_DTPREL16, but no overflow. */
1305 HOWTO (R_PPC_GOT_DTPREL16_LO
,
1307 1, /* size (0 = byte, 1 = short, 2 = long) */
1309 FALSE
, /* pc_relative */
1311 complain_overflow_dont
, /* complain_on_overflow */
1312 ppc_elf_unhandled_reloc
, /* special_function */
1313 "R_PPC_GOT_DTPREL16_LO", /* name */
1314 FALSE
, /* partial_inplace */
1316 0xffff, /* dst_mask */
1317 FALSE
), /* pcrel_offset */
1319 /* Like GOT_DTPREL16_LO, but next higher group of 16 bits. */
1320 HOWTO (R_PPC_GOT_DTPREL16_HI
,
1321 16, /* rightshift */
1322 1, /* size (0 = byte, 1 = short, 2 = long) */
1324 FALSE
, /* pc_relative */
1326 complain_overflow_dont
, /* complain_on_overflow */
1327 ppc_elf_unhandled_reloc
, /* special_function */
1328 "R_PPC_GOT_DTPREL16_HI", /* name */
1329 FALSE
, /* partial_inplace */
1331 0xffff, /* dst_mask */
1332 FALSE
), /* pcrel_offset */
1334 /* Like GOT_DTPREL16_HI, but adjust for low 16 bits. */
1335 HOWTO (R_PPC_GOT_DTPREL16_HA
,
1336 16, /* rightshift */
1337 1, /* size (0 = byte, 1 = short, 2 = long) */
1339 FALSE
, /* pc_relative */
1341 complain_overflow_dont
, /* complain_on_overflow */
1342 ppc_elf_unhandled_reloc
, /* special_function */
1343 "R_PPC_GOT_DTPREL16_HA", /* name */
1344 FALSE
, /* partial_inplace */
1346 0xffff, /* dst_mask */
1347 FALSE
), /* pcrel_offset */
1349 /* Allocates an entry in the GOT with value (sym+add)@tprel, and computes the
1350 offset to the entry. */
1351 HOWTO (R_PPC_GOT_TPREL16
,
1353 1, /* size (0 = byte, 1 = short, 2 = long) */
1355 FALSE
, /* pc_relative */
1357 complain_overflow_signed
, /* complain_on_overflow */
1358 ppc_elf_unhandled_reloc
, /* special_function */
1359 "R_PPC_GOT_TPREL16", /* name */
1360 FALSE
, /* partial_inplace */
1362 0xffff, /* dst_mask */
1363 FALSE
), /* pcrel_offset */
1365 /* Like GOT_TPREL16, but no overflow. */
1366 HOWTO (R_PPC_GOT_TPREL16_LO
,
1368 1, /* size (0 = byte, 1 = short, 2 = long) */
1370 FALSE
, /* pc_relative */
1372 complain_overflow_dont
, /* complain_on_overflow */
1373 ppc_elf_unhandled_reloc
, /* special_function */
1374 "R_PPC_GOT_TPREL16_LO", /* name */
1375 FALSE
, /* partial_inplace */
1377 0xffff, /* dst_mask */
1378 FALSE
), /* pcrel_offset */
1380 /* Like GOT_TPREL16_LO, but next higher group of 16 bits. */
1381 HOWTO (R_PPC_GOT_TPREL16_HI
,
1382 16, /* rightshift */
1383 1, /* size (0 = byte, 1 = short, 2 = long) */
1385 FALSE
, /* pc_relative */
1387 complain_overflow_dont
, /* complain_on_overflow */
1388 ppc_elf_unhandled_reloc
, /* special_function */
1389 "R_PPC_GOT_TPREL16_HI", /* name */
1390 FALSE
, /* partial_inplace */
1392 0xffff, /* dst_mask */
1393 FALSE
), /* pcrel_offset */
1395 /* Like GOT_TPREL16_HI, but adjust for low 16 bits. */
1396 HOWTO (R_PPC_GOT_TPREL16_HA
,
1397 16, /* rightshift */
1398 1, /* size (0 = byte, 1 = short, 2 = long) */
1400 FALSE
, /* pc_relative */
1402 complain_overflow_dont
, /* complain_on_overflow */
1403 ppc_elf_unhandled_reloc
, /* special_function */
1404 "R_PPC_GOT_TPREL16_HA", /* name */
1405 FALSE
, /* partial_inplace */
1407 0xffff, /* dst_mask */
1408 FALSE
), /* pcrel_offset */
1410 /* The remaining relocs are from the Embedded ELF ABI, and are not
1411 in the SVR4 ELF ABI. */
1413 /* 32 bit value resulting from the addend minus the symbol. */
1414 HOWTO (R_PPC_EMB_NADDR32
, /* type */
1416 2, /* size (0 = byte, 1 = short, 2 = long) */
1418 FALSE
, /* pc_relative */
1420 complain_overflow_bitfield
, /* complain_on_overflow */
1421 bfd_elf_generic_reloc
, /* special_function */
1422 "R_PPC_EMB_NADDR32", /* name */
1423 FALSE
, /* partial_inplace */
1425 0xffffffff, /* dst_mask */
1426 FALSE
), /* pcrel_offset */
1428 /* 16 bit value resulting from the addend minus the symbol. */
1429 HOWTO (R_PPC_EMB_NADDR16
, /* type */
1431 1, /* size (0 = byte, 1 = short, 2 = long) */
1433 FALSE
, /* pc_relative */
1435 complain_overflow_bitfield
, /* complain_on_overflow */
1436 bfd_elf_generic_reloc
, /* special_function */
1437 "R_PPC_EMB_NADDR16", /* name */
1438 FALSE
, /* partial_inplace */
1440 0xffff, /* dst_mask */
1441 FALSE
), /* pcrel_offset */
1443 /* 16 bit value resulting from the addend minus the symbol. */
1444 HOWTO (R_PPC_EMB_NADDR16_LO
, /* type */
1446 1, /* size (0 = byte, 1 = short, 2 = long) */
1448 FALSE
, /* pc_relative */
1450 complain_overflow_dont
,/* complain_on_overflow */
1451 bfd_elf_generic_reloc
, /* special_function */
1452 "R_PPC_EMB_ADDR16_LO", /* name */
1453 FALSE
, /* partial_inplace */
1455 0xffff, /* dst_mask */
1456 FALSE
), /* pcrel_offset */
1458 /* The high order 16 bits of the addend minus the symbol. */
1459 HOWTO (R_PPC_EMB_NADDR16_HI
, /* type */
1460 16, /* rightshift */
1461 1, /* size (0 = byte, 1 = short, 2 = long) */
1463 FALSE
, /* pc_relative */
1465 complain_overflow_dont
, /* complain_on_overflow */
1466 bfd_elf_generic_reloc
, /* special_function */
1467 "R_PPC_EMB_NADDR16_HI", /* name */
1468 FALSE
, /* partial_inplace */
1470 0xffff, /* dst_mask */
1471 FALSE
), /* pcrel_offset */
1473 /* The high order 16 bits of the result of the addend minus the address,
1474 plus 1 if the contents of the low 16 bits, treated as a signed number,
1476 HOWTO (R_PPC_EMB_NADDR16_HA
, /* type */
1477 16, /* rightshift */
1478 1, /* size (0 = byte, 1 = short, 2 = long) */
1480 FALSE
, /* pc_relative */
1482 complain_overflow_dont
, /* complain_on_overflow */
1483 ppc_elf_addr16_ha_reloc
, /* special_function */
1484 "R_PPC_EMB_NADDR16_HA", /* name */
1485 FALSE
, /* partial_inplace */
1487 0xffff, /* dst_mask */
1488 FALSE
), /* pcrel_offset */
1490 /* 16 bit value resulting from allocating a 4 byte word to hold an
1491 address in the .sdata section, and returning the offset from
1492 _SDA_BASE_ for that relocation. */
1493 HOWTO (R_PPC_EMB_SDAI16
, /* type */
1495 1, /* size (0 = byte, 1 = short, 2 = long) */
1497 FALSE
, /* pc_relative */
1499 complain_overflow_bitfield
, /* complain_on_overflow */
1500 bfd_elf_generic_reloc
, /* special_function */
1501 "R_PPC_EMB_SDAI16", /* name */
1502 FALSE
, /* partial_inplace */
1504 0xffff, /* dst_mask */
1505 FALSE
), /* pcrel_offset */
1507 /* 16 bit value resulting from allocating a 4 byte word to hold an
1508 address in the .sdata2 section, and returning the offset from
1509 _SDA2_BASE_ for that relocation. */
1510 HOWTO (R_PPC_EMB_SDA2I16
, /* type */
1512 1, /* size (0 = byte, 1 = short, 2 = long) */
1514 FALSE
, /* pc_relative */
1516 complain_overflow_bitfield
, /* complain_on_overflow */
1517 bfd_elf_generic_reloc
, /* special_function */
1518 "R_PPC_EMB_SDA2I16", /* name */
1519 FALSE
, /* partial_inplace */
1521 0xffff, /* dst_mask */
1522 FALSE
), /* pcrel_offset */
1524 /* A sign-extended 16 bit value relative to _SDA2_BASE_, for use with
1525 small data items. */
1526 HOWTO (R_PPC_EMB_SDA2REL
, /* type */
1528 1, /* size (0 = byte, 1 = short, 2 = long) */
1530 FALSE
, /* pc_relative */
1532 complain_overflow_signed
, /* complain_on_overflow */
1533 bfd_elf_generic_reloc
, /* special_function */
1534 "R_PPC_EMB_SDA2REL", /* name */
1535 FALSE
, /* partial_inplace */
1537 0xffff, /* dst_mask */
1538 FALSE
), /* pcrel_offset */
1540 /* Relocate against either _SDA_BASE_ or _SDA2_BASE_, filling in the 16 bit
1541 signed offset from the appropriate base, and filling in the register
1542 field with the appropriate register (0, 2, or 13). */
1543 HOWTO (R_PPC_EMB_SDA21
, /* type */
1545 2, /* size (0 = byte, 1 = short, 2 = long) */
1547 FALSE
, /* pc_relative */
1549 complain_overflow_signed
, /* complain_on_overflow */
1550 bfd_elf_generic_reloc
, /* special_function */
1551 "R_PPC_EMB_SDA21", /* name */
1552 FALSE
, /* partial_inplace */
1554 0xffff, /* dst_mask */
1555 FALSE
), /* pcrel_offset */
1557 /* Relocation not handled: R_PPC_EMB_MRKREF */
1558 /* Relocation not handled: R_PPC_EMB_RELSEC16 */
1559 /* Relocation not handled: R_PPC_EMB_RELST_LO */
1560 /* Relocation not handled: R_PPC_EMB_RELST_HI */
1561 /* Relocation not handled: R_PPC_EMB_RELST_HA */
1562 /* Relocation not handled: R_PPC_EMB_BIT_FLD */
1564 /* PC relative relocation against either _SDA_BASE_ or _SDA2_BASE_, filling
1565 in the 16 bit signed offset from the appropriate base, and filling in the
1566 register field with the appropriate register (0, 2, or 13). */
1567 HOWTO (R_PPC_EMB_RELSDA
, /* type */
1569 1, /* size (0 = byte, 1 = short, 2 = long) */
1571 TRUE
, /* pc_relative */
1573 complain_overflow_signed
, /* complain_on_overflow */
1574 bfd_elf_generic_reloc
, /* special_function */
1575 "R_PPC_EMB_RELSDA", /* name */
1576 FALSE
, /* partial_inplace */
1578 0xffff, /* dst_mask */
1579 FALSE
), /* pcrel_offset */
1581 /* GNU extension to record C++ vtable hierarchy. */
1582 HOWTO (R_PPC_GNU_VTINHERIT
, /* type */
1584 0, /* size (0 = byte, 1 = short, 2 = long) */
1586 FALSE
, /* pc_relative */
1588 complain_overflow_dont
, /* complain_on_overflow */
1589 NULL
, /* special_function */
1590 "R_PPC_GNU_VTINHERIT", /* name */
1591 FALSE
, /* partial_inplace */
1594 FALSE
), /* pcrel_offset */
1596 /* GNU extension to record C++ vtable member usage. */
1597 HOWTO (R_PPC_GNU_VTENTRY
, /* type */
1599 0, /* size (0 = byte, 1 = short, 2 = long) */
1601 FALSE
, /* pc_relative */
1603 complain_overflow_dont
, /* complain_on_overflow */
1604 NULL
, /* special_function */
1605 "R_PPC_GNU_VTENTRY", /* name */
1606 FALSE
, /* partial_inplace */
1609 FALSE
), /* pcrel_offset */
1611 /* Phony reloc to handle AIX style TOC entries. */
1612 HOWTO (R_PPC_TOC16
, /* type */
1614 1, /* size (0 = byte, 1 = short, 2 = long) */
1616 FALSE
, /* pc_relative */
1618 complain_overflow_signed
, /* complain_on_overflow */
1619 bfd_elf_generic_reloc
, /* special_function */
1620 "R_PPC_TOC16", /* name */
1621 FALSE
, /* partial_inplace */
1623 0xffff, /* dst_mask */
1624 FALSE
), /* pcrel_offset */
1627 /* Initialize the ppc_elf_howto_table, so that linear accesses can be done. */
1630 ppc_elf_howto_init ()
1632 unsigned int i
, type
;
1635 i
< sizeof (ppc_elf_howto_raw
) / sizeof (ppc_elf_howto_raw
[0]);
1638 type
= ppc_elf_howto_raw
[i
].type
;
1639 if (type
>= (sizeof (ppc_elf_howto_table
)
1640 / sizeof (ppc_elf_howto_table
[0])))
1642 ppc_elf_howto_table
[type
] = &ppc_elf_howto_raw
[i
];
1646 /* This function handles relaxing for the PPC with option --mpc860c0[=<n>].
1648 The MPC860, revision C0 or earlier contains a bug in the die.
1649 If all of the following conditions are true, the next instruction
1650 to be executed *may* be treated as a no-op.
1651 1/ A forward branch is executed.
1652 2/ The branch is predicted as not taken.
1653 3/ The branch is taken.
1654 4/ The branch is located in the last 5 words of a page.
1655 (The EOP limit is 5 by default but may be specified as any value
1658 Our software solution is to detect these problematic branches in a
1659 linker pass and modify them as follows:
1660 1/ Unconditional branches - Since these are always predicted taken,
1661 there is no problem and no action is required.
1662 2/ Conditional backward branches - No problem, no action required.
1663 3/ Conditional forward branches - Ensure that the "inverse prediction
1664 bit" is set (ensure it is predicted taken).
1665 4/ Conditional register branches - Ensure that the "y bit" is set
1666 (ensure it is predicted taken). */
1668 /* Sort sections by address. */
1671 ppc_elf_sort_rela (arg1
, arg2
)
1675 const Elf_Internal_Rela
**rela1
= (const Elf_Internal_Rela
**) arg1
;
1676 const Elf_Internal_Rela
**rela2
= (const Elf_Internal_Rela
**) arg2
;
1678 /* Sort by offset. */
1679 return ((*rela1
)->r_offset
- (*rela2
)->r_offset
);
1683 ppc_elf_relax_section (abfd
, isec
, link_info
, again
)
1686 struct bfd_link_info
*link_info
;
1689 #define PAGESIZE 0x1000
1691 bfd_byte
*contents
= NULL
;
1692 bfd_byte
*free_contents
= NULL
;
1693 Elf_Internal_Rela
*internal_relocs
= NULL
;
1694 Elf_Internal_Rela
*free_relocs
= NULL
;
1695 Elf_Internal_Rela
**rela_comb
= NULL
;
1696 int comb_curr
, comb_count
;
1698 /* We never have to do this more than once per input section. */
1701 /* If needed, initialize this section's cooked size. */
1702 if (isec
->_cooked_size
== 0)
1703 isec
->_cooked_size
= isec
->_raw_size
;
1705 /* We're only interested in text sections which overlap the
1706 troublesome area at the end of a page. */
1707 if (link_info
->mpc860c0
&& (isec
->flags
& SEC_CODE
) && isec
->_cooked_size
)
1709 bfd_vma dot
, end_page
, end_section
;
1710 bfd_boolean section_modified
;
1712 /* Get the section contents. */
1713 /* Get cached copy if it exists. */
1714 if (elf_section_data (isec
)->this_hdr
.contents
!= NULL
)
1715 contents
= elf_section_data (isec
)->this_hdr
.contents
;
1718 /* Go get them off disk. */
1719 contents
= (bfd_byte
*) bfd_malloc (isec
->_raw_size
);
1720 if (contents
== NULL
)
1722 free_contents
= contents
;
1724 if (! bfd_get_section_contents (abfd
, isec
, contents
,
1725 (file_ptr
) 0, isec
->_raw_size
))
1731 if (isec
->reloc_count
)
1736 /* Get a copy of the native relocations. */
1738 = _bfd_elf32_link_read_relocs (abfd
, isec
, (PTR
) NULL
,
1739 (Elf_Internal_Rela
*) NULL
,
1740 link_info
->keep_memory
);
1741 if (internal_relocs
== NULL
)
1743 if (! link_info
->keep_memory
)
1744 free_relocs
= internal_relocs
;
1746 /* Setup a faster access method for the reloc info we need. */
1747 amt
= isec
->reloc_count
;
1748 amt
*= sizeof (Elf_Internal_Rela
*);
1749 rela_comb
= (Elf_Internal_Rela
**) bfd_malloc (amt
);
1750 if (rela_comb
== NULL
)
1752 for (n
= 0; n
< isec
->reloc_count
; ++n
)
1756 r_type
= ELF32_R_TYPE (internal_relocs
[n
].r_info
);
1757 if (r_type
< 0 || r_type
>= (int) R_PPC_max
)
1760 /* Prologue constants are sometimes present in the ".text"
1761 sections and they can be identified by their associated
1762 relocation. We don't want to process those words and
1763 some others which can also be identified by their
1764 relocations. However, not all conditional branches will
1765 have a relocation so we will only ignore words that
1766 1) have a reloc, and 2) the reloc is not applicable to a
1767 conditional branch. The array rela_comb is built here
1768 for use in the EOP scan loop. */
1771 case R_PPC_ADDR14_BRNTAKEN
:
1773 case R_PPC_REL14_BRNTAKEN
:
1774 /* We should check the instruction. */
1777 /* The word is not a conditional branch - ignore it. */
1778 rela_comb
[comb_count
++] = &internal_relocs
[n
];
1783 qsort (rela_comb
, (size_t) comb_count
, sizeof (int),
1787 /* Enumerate each EOP region that overlaps this section. */
1788 end_section
= isec
->vma
+ isec
->_cooked_size
;
1789 dot
= end_page
= (isec
->vma
| (PAGESIZE
- 1)) + 1;
1790 dot
-= link_info
->mpc860c0
;
1791 section_modified
= FALSE
;
1792 /* Increment the start position if this section begins in the
1793 middle of its first EOP region. */
1794 if (dot
< isec
->vma
)
1798 dot
+= PAGESIZE
, end_page
+= PAGESIZE
)
1800 /* Check each word in this EOP region. */
1801 for (; dot
< end_page
; dot
+= 4)
1803 bfd_vma isec_offset
;
1805 bfd_boolean skip
, modified
;
1807 /* Don't process this word if there is a relocation for it
1808 and the relocation indicates the word is not a
1809 conditional branch. */
1811 isec_offset
= dot
- isec
->vma
;
1812 for (; comb_curr
<comb_count
; ++comb_curr
)
1816 r_offset
= rela_comb
[comb_curr
]->r_offset
;
1817 if (r_offset
>= isec_offset
)
1819 if (r_offset
== isec_offset
) skip
= TRUE
;
1825 /* Check the current word for a problematic conditional
1827 #define BO0(insn) ((insn) & 0x02000000)
1828 #define BO2(insn) ((insn) & 0x00800000)
1829 #define BO4(insn) ((insn) & 0x00200000)
1830 insn
= (unsigned long) bfd_get_32 (abfd
, contents
+ isec_offset
);
1832 if ((insn
& 0xFc000000) == 0x40000000)
1834 /* Instruction is BCx */
1835 if ((!BO0(insn
) || !BO2(insn
)) && !BO4(insn
))
1839 /* This branch is predicted as "normal".
1840 If this is a forward branch, it is problematic. */
1841 target
= insn
& 0x0000Fffc;
1842 target
= (target
^ 0x8000) - 0x8000;
1843 if ((insn
& 0x00000002) == 0)
1844 /* Convert to abs. */
1848 /* Set the prediction bit. */
1854 else if ((insn
& 0xFc00Fffe) == 0x4c000420)
1856 /* Instruction is BCCTRx. */
1857 if ((!BO0(insn
) || !BO2(insn
)) && !BO4(insn
))
1859 /* This branch is predicted as not-taken.
1860 If this is a forward branch, it is problematic.
1861 Since we can't tell statically if it will branch
1862 forward, always set the prediction bit. */
1867 else if ((insn
& 0xFc00Fffe) == 0x4c000020)
1869 /* Instruction is BCLRx */
1870 if ((!BO0(insn
) || !BO2(insn
)) && !BO4(insn
))
1872 /* This branch is predicted as not-taken.
1873 If this is a forward branch, it is problematic.
1874 Since we can't tell statically if it will branch
1875 forward, always set the prediction bit. */
1885 bfd_put_32 (abfd
, (bfd_vma
) insn
, contents
+ isec_offset
);
1886 section_modified
= TRUE
;
1890 if (section_modified
)
1892 elf_section_data (isec
)->this_hdr
.contents
= contents
;
1893 free_contents
= NULL
;
1897 if (rela_comb
!= NULL
)
1903 if (free_relocs
!= NULL
)
1909 if (free_contents
!= NULL
)
1911 if (! link_info
->keep_memory
)
1912 free (free_contents
);
1915 /* Cache the section contents for elf_link_input_bfd. */
1916 elf_section_data (isec
)->this_hdr
.contents
= contents
;
1918 free_contents
= NULL
;
1924 if (rela_comb
!= NULL
)
1926 if (free_relocs
!= NULL
)
1928 if (free_contents
!= NULL
)
1929 free (free_contents
);
1933 static reloc_howto_type
*
1934 ppc_elf_reloc_type_lookup (abfd
, code
)
1935 bfd
*abfd ATTRIBUTE_UNUSED
;
1936 bfd_reloc_code_real_type code
;
1938 enum elf_ppc_reloc_type r
;
1940 if (!ppc_elf_howto_table
[R_PPC_ADDR32
])
1941 /* Initialize howto table if needed. */
1942 ppc_elf_howto_init ();
1947 return (reloc_howto_type
*) NULL
;
1949 case BFD_RELOC_NONE
: r
= R_PPC_NONE
; break;
1950 case BFD_RELOC_32
: r
= R_PPC_ADDR32
; break;
1951 case BFD_RELOC_PPC_BA26
: r
= R_PPC_ADDR24
; break;
1952 case BFD_RELOC_16
: r
= R_PPC_ADDR16
; break;
1953 case BFD_RELOC_LO16
: r
= R_PPC_ADDR16_LO
; break;
1954 case BFD_RELOC_HI16
: r
= R_PPC_ADDR16_HI
; break;
1955 case BFD_RELOC_HI16_S
: r
= R_PPC_ADDR16_HA
; break;
1956 case BFD_RELOC_PPC_BA16
: r
= R_PPC_ADDR14
; break;
1957 case BFD_RELOC_PPC_BA16_BRTAKEN
: r
= R_PPC_ADDR14_BRTAKEN
; break;
1958 case BFD_RELOC_PPC_BA16_BRNTAKEN
: r
= R_PPC_ADDR14_BRNTAKEN
; break;
1959 case BFD_RELOC_PPC_B26
: r
= R_PPC_REL24
; break;
1960 case BFD_RELOC_PPC_B16
: r
= R_PPC_REL14
; break;
1961 case BFD_RELOC_PPC_B16_BRTAKEN
: r
= R_PPC_REL14_BRTAKEN
; break;
1962 case BFD_RELOC_PPC_B16_BRNTAKEN
: r
= R_PPC_REL14_BRNTAKEN
; break;
1963 case BFD_RELOC_16_GOTOFF
: r
= R_PPC_GOT16
; break;
1964 case BFD_RELOC_LO16_GOTOFF
: r
= R_PPC_GOT16_LO
; break;
1965 case BFD_RELOC_HI16_GOTOFF
: r
= R_PPC_GOT16_HI
; break;
1966 case BFD_RELOC_HI16_S_GOTOFF
: r
= R_PPC_GOT16_HA
; break;
1967 case BFD_RELOC_24_PLT_PCREL
: r
= R_PPC_PLTREL24
; break;
1968 case BFD_RELOC_PPC_COPY
: r
= R_PPC_COPY
; break;
1969 case BFD_RELOC_PPC_GLOB_DAT
: r
= R_PPC_GLOB_DAT
; break;
1970 case BFD_RELOC_PPC_LOCAL24PC
: r
= R_PPC_LOCAL24PC
; break;
1971 case BFD_RELOC_32_PCREL
: r
= R_PPC_REL32
; break;
1972 case BFD_RELOC_32_PLTOFF
: r
= R_PPC_PLT32
; break;
1973 case BFD_RELOC_32_PLT_PCREL
: r
= R_PPC_PLTREL32
; break;
1974 case BFD_RELOC_LO16_PLTOFF
: r
= R_PPC_PLT16_LO
; break;
1975 case BFD_RELOC_HI16_PLTOFF
: r
= R_PPC_PLT16_HI
; break;
1976 case BFD_RELOC_HI16_S_PLTOFF
: r
= R_PPC_PLT16_HA
; break;
1977 case BFD_RELOC_GPREL16
: r
= R_PPC_SDAREL16
; break;
1978 case BFD_RELOC_16_BASEREL
: r
= R_PPC_SECTOFF
; break;
1979 case BFD_RELOC_LO16_BASEREL
: r
= R_PPC_SECTOFF_LO
; break;
1980 case BFD_RELOC_HI16_BASEREL
: r
= R_PPC_SECTOFF_HI
; break;
1981 case BFD_RELOC_HI16_S_BASEREL
: r
= R_PPC_SECTOFF_HA
; break;
1982 case BFD_RELOC_CTOR
: r
= R_PPC_ADDR32
; break;
1983 case BFD_RELOC_PPC_TOC16
: r
= R_PPC_TOC16
; break;
1984 case BFD_RELOC_PPC_TLS
: r
= R_PPC_TLS
; break;
1985 case BFD_RELOC_PPC_DTPMOD
: r
= R_PPC_DTPMOD32
; break;
1986 case BFD_RELOC_PPC_TPREL16
: r
= R_PPC_TPREL16
; break;
1987 case BFD_RELOC_PPC_TPREL16_LO
: r
= R_PPC_TPREL16_LO
; break;
1988 case BFD_RELOC_PPC_TPREL16_HI
: r
= R_PPC_TPREL16_HI
; break;
1989 case BFD_RELOC_PPC_TPREL16_HA
: r
= R_PPC_TPREL16_HA
; break;
1990 case BFD_RELOC_PPC_TPREL
: r
= R_PPC_TPREL32
; break;
1991 case BFD_RELOC_PPC_DTPREL16
: r
= R_PPC_DTPREL16
; break;
1992 case BFD_RELOC_PPC_DTPREL16_LO
: r
= R_PPC_DTPREL16_LO
; break;
1993 case BFD_RELOC_PPC_DTPREL16_HI
: r
= R_PPC_DTPREL16_HI
; break;
1994 case BFD_RELOC_PPC_DTPREL16_HA
: r
= R_PPC_DTPREL16_HA
; break;
1995 case BFD_RELOC_PPC_DTPREL
: r
= R_PPC_DTPREL32
; break;
1996 case BFD_RELOC_PPC_GOT_TLSGD16
: r
= R_PPC_GOT_TLSGD16
; break;
1997 case BFD_RELOC_PPC_GOT_TLSGD16_LO
: r
= R_PPC_GOT_TLSGD16_LO
; break;
1998 case BFD_RELOC_PPC_GOT_TLSGD16_HI
: r
= R_PPC_GOT_TLSGD16_HI
; break;
1999 case BFD_RELOC_PPC_GOT_TLSGD16_HA
: r
= R_PPC_GOT_TLSGD16_HA
; break;
2000 case BFD_RELOC_PPC_GOT_TLSLD16
: r
= R_PPC_GOT_TLSLD16
; break;
2001 case BFD_RELOC_PPC_GOT_TLSLD16_LO
: r
= R_PPC_GOT_TLSLD16_LO
; break;
2002 case BFD_RELOC_PPC_GOT_TLSLD16_HI
: r
= R_PPC_GOT_TLSLD16_HI
; break;
2003 case BFD_RELOC_PPC_GOT_TLSLD16_HA
: r
= R_PPC_GOT_TLSLD16_HA
; break;
2004 case BFD_RELOC_PPC_GOT_TPREL16
: r
= R_PPC_GOT_TPREL16
; break;
2005 case BFD_RELOC_PPC_GOT_TPREL16_LO
: r
= R_PPC_GOT_TPREL16_LO
; break;
2006 case BFD_RELOC_PPC_GOT_TPREL16_HI
: r
= R_PPC_GOT_TPREL16_HI
; break;
2007 case BFD_RELOC_PPC_GOT_TPREL16_HA
: r
= R_PPC_GOT_TPREL16_HA
; break;
2008 case BFD_RELOC_PPC_GOT_DTPREL16
: r
= R_PPC_GOT_DTPREL16
; break;
2009 case BFD_RELOC_PPC_GOT_DTPREL16_LO
: r
= R_PPC_GOT_DTPREL16_LO
; break;
2010 case BFD_RELOC_PPC_GOT_DTPREL16_HI
: r
= R_PPC_GOT_DTPREL16_HI
; break;
2011 case BFD_RELOC_PPC_GOT_DTPREL16_HA
: r
= R_PPC_GOT_DTPREL16_HA
; break;
2012 case BFD_RELOC_PPC_EMB_NADDR32
: r
= R_PPC_EMB_NADDR32
; break;
2013 case BFD_RELOC_PPC_EMB_NADDR16
: r
= R_PPC_EMB_NADDR16
; break;
2014 case BFD_RELOC_PPC_EMB_NADDR16_LO
: r
= R_PPC_EMB_NADDR16_LO
; break;
2015 case BFD_RELOC_PPC_EMB_NADDR16_HI
: r
= R_PPC_EMB_NADDR16_HI
; break;
2016 case BFD_RELOC_PPC_EMB_NADDR16_HA
: r
= R_PPC_EMB_NADDR16_HA
; break;
2017 case BFD_RELOC_PPC_EMB_SDAI16
: r
= R_PPC_EMB_SDAI16
; break;
2018 case BFD_RELOC_PPC_EMB_SDA2I16
: r
= R_PPC_EMB_SDA2I16
; break;
2019 case BFD_RELOC_PPC_EMB_SDA2REL
: r
= R_PPC_EMB_SDA2REL
; break;
2020 case BFD_RELOC_PPC_EMB_SDA21
: r
= R_PPC_EMB_SDA21
; break;
2021 case BFD_RELOC_PPC_EMB_MRKREF
: r
= R_PPC_EMB_MRKREF
; break;
2022 case BFD_RELOC_PPC_EMB_RELSEC16
: r
= R_PPC_EMB_RELSEC16
; break;
2023 case BFD_RELOC_PPC_EMB_RELST_LO
: r
= R_PPC_EMB_RELST_LO
; break;
2024 case BFD_RELOC_PPC_EMB_RELST_HI
: r
= R_PPC_EMB_RELST_HI
; break;
2025 case BFD_RELOC_PPC_EMB_RELST_HA
: r
= R_PPC_EMB_RELST_HA
; break;
2026 case BFD_RELOC_PPC_EMB_BIT_FLD
: r
= R_PPC_EMB_BIT_FLD
; break;
2027 case BFD_RELOC_PPC_EMB_RELSDA
: r
= R_PPC_EMB_RELSDA
; break;
2028 case BFD_RELOC_VTABLE_INHERIT
: r
= R_PPC_GNU_VTINHERIT
; break;
2029 case BFD_RELOC_VTABLE_ENTRY
: r
= R_PPC_GNU_VTENTRY
; break;
2032 return ppc_elf_howto_table
[(int) r
];
2035 /* Set the howto pointer for a PowerPC ELF reloc. */
2038 ppc_elf_info_to_howto (abfd
, cache_ptr
, dst
)
2039 bfd
*abfd ATTRIBUTE_UNUSED
;
2041 Elf_Internal_Rela
*dst
;
2043 if (!ppc_elf_howto_table
[R_PPC_ADDR32
])
2044 /* Initialize howto table if needed. */
2045 ppc_elf_howto_init ();
2047 BFD_ASSERT (ELF32_R_TYPE (dst
->r_info
) < (unsigned int) R_PPC_max
);
2048 cache_ptr
->howto
= ppc_elf_howto_table
[ELF32_R_TYPE (dst
->r_info
)];
2051 /* Handle the R_PPC_ADDR16_HA reloc. */
2053 static bfd_reloc_status_type
2054 ppc_elf_addr16_ha_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
2055 output_bfd
, error_message
)
2056 bfd
*abfd ATTRIBUTE_UNUSED
;
2057 arelent
*reloc_entry
;
2059 PTR data ATTRIBUTE_UNUSED
;
2060 asection
*input_section
;
2062 char **error_message ATTRIBUTE_UNUSED
;
2066 if (output_bfd
!= NULL
)
2068 reloc_entry
->address
+= input_section
->output_offset
;
2069 return bfd_reloc_ok
;
2072 if (reloc_entry
->address
> input_section
->_cooked_size
)
2073 return bfd_reloc_outofrange
;
2075 if (bfd_is_com_section (symbol
->section
))
2078 relocation
= symbol
->value
;
2080 relocation
+= symbol
->section
->output_section
->vma
;
2081 relocation
+= symbol
->section
->output_offset
;
2082 relocation
+= reloc_entry
->addend
;
2084 reloc_entry
->addend
+= (relocation
& 0x8000) << 1;
2086 return bfd_reloc_continue
;
2089 static bfd_reloc_status_type
2090 ppc_elf_unhandled_reloc (abfd
, reloc_entry
, symbol
, data
,
2091 input_section
, output_bfd
, error_message
)
2093 arelent
*reloc_entry
;
2096 asection
*input_section
;
2098 char **error_message
;
2100 /* If this is a relocatable link (output_bfd test tells us), just
2101 call the generic function. Any adjustment will be done at final
2103 if (output_bfd
!= NULL
)
2104 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2105 input_section
, output_bfd
, error_message
);
2107 if (error_message
!= NULL
)
2109 static char buf
[60];
2110 sprintf (buf
, "generic linker can't handle %s",
2111 reloc_entry
->howto
->name
);
2112 *error_message
= buf
;
2114 return bfd_reloc_dangerous
;
2117 /* Fix bad default arch selected for a 32 bit input bfd when the
2118 default is 64 bit. */
2121 ppc_elf_object_p (abfd
)
2124 if (abfd
->arch_info
->the_default
&& abfd
->arch_info
->bits_per_word
== 64)
2126 Elf_Internal_Ehdr
*i_ehdr
= elf_elfheader (abfd
);
2128 if (i_ehdr
->e_ident
[EI_CLASS
] == ELFCLASS32
)
2130 /* Relies on arch after 64 bit default being 32 bit default. */
2131 abfd
->arch_info
= abfd
->arch_info
->next
;
2132 BFD_ASSERT (abfd
->arch_info
->bits_per_word
== 32);
2138 /* Function to set whether a module needs the -mrelocatable bit set. */
2141 ppc_elf_set_private_flags (abfd
, flags
)
2145 BFD_ASSERT (!elf_flags_init (abfd
)
2146 || elf_elfheader (abfd
)->e_flags
== flags
);
2148 elf_elfheader (abfd
)->e_flags
= flags
;
2149 elf_flags_init (abfd
) = TRUE
;
2153 /* Merge backend specific data from an object file to the output
2154 object file when linking. */
2157 ppc_elf_merge_private_bfd_data (ibfd
, obfd
)
2165 /* Check if we have the same endianess. */
2166 if (! _bfd_generic_verify_endian_match (ibfd
, obfd
))
2169 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
2170 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
2173 new_flags
= elf_elfheader (ibfd
)->e_flags
;
2174 old_flags
= elf_elfheader (obfd
)->e_flags
;
2175 if (!elf_flags_init (obfd
))
2177 /* First call, no flags set. */
2178 elf_flags_init (obfd
) = TRUE
;
2179 elf_elfheader (obfd
)->e_flags
= new_flags
;
2182 /* Compatible flags are ok. */
2183 else if (new_flags
== old_flags
)
2186 /* Incompatible flags. */
2189 /* Warn about -mrelocatable mismatch. Allow -mrelocatable-lib
2190 to be linked with either. */
2192 if ((new_flags
& EF_PPC_RELOCATABLE
) != 0
2193 && (old_flags
& (EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
)) == 0)
2196 (*_bfd_error_handler
)
2197 (_("%s: compiled with -mrelocatable and linked with modules compiled normally"),
2198 bfd_archive_filename (ibfd
));
2200 else if ((new_flags
& (EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
)) == 0
2201 && (old_flags
& EF_PPC_RELOCATABLE
) != 0)
2204 (*_bfd_error_handler
)
2205 (_("%s: compiled normally and linked with modules compiled with -mrelocatable"),
2206 bfd_archive_filename (ibfd
));
2209 /* The output is -mrelocatable-lib iff both the input files are. */
2210 if (! (new_flags
& EF_PPC_RELOCATABLE_LIB
))
2211 elf_elfheader (obfd
)->e_flags
&= ~EF_PPC_RELOCATABLE_LIB
;
2213 /* The output is -mrelocatable iff it can't be -mrelocatable-lib,
2214 but each input file is either -mrelocatable or -mrelocatable-lib. */
2215 if (! (elf_elfheader (obfd
)->e_flags
& EF_PPC_RELOCATABLE_LIB
)
2216 && (new_flags
& (EF_PPC_RELOCATABLE_LIB
| EF_PPC_RELOCATABLE
))
2217 && (old_flags
& (EF_PPC_RELOCATABLE_LIB
| EF_PPC_RELOCATABLE
)))
2218 elf_elfheader (obfd
)->e_flags
|= EF_PPC_RELOCATABLE
;
2220 /* Do not warn about eabi vs. V.4 mismatch, just or in the bit if
2221 any module uses it. */
2222 elf_elfheader (obfd
)->e_flags
|= (new_flags
& EF_PPC_EMB
);
2224 new_flags
&= ~(EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
| EF_PPC_EMB
);
2225 old_flags
&= ~(EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
| EF_PPC_EMB
);
2227 /* Warn about any other mismatches. */
2228 if (new_flags
!= old_flags
)
2231 (*_bfd_error_handler
)
2232 (_("%s: uses different e_flags (0x%lx) fields than previous modules (0x%lx)"),
2233 bfd_archive_filename (ibfd
), (long) new_flags
, (long) old_flags
);
2238 bfd_set_error (bfd_error_bad_value
);
2246 /* Handle a PowerPC specific section when reading an object file. This
2247 is called when elfcode.h finds a section with an unknown type. */
2250 ppc_elf_section_from_shdr (abfd
, hdr
, name
)
2252 Elf_Internal_Shdr
*hdr
;
2258 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
))
2261 newsect
= hdr
->bfd_section
;
2262 flags
= bfd_get_section_flags (abfd
, newsect
);
2263 if (hdr
->sh_flags
& SHF_EXCLUDE
)
2264 flags
|= SEC_EXCLUDE
;
2266 if (hdr
->sh_type
== SHT_ORDERED
)
2267 flags
|= SEC_SORT_ENTRIES
;
2269 bfd_set_section_flags (abfd
, newsect
, flags
);
2273 /* Set up any other section flags and such that may be necessary. */
2276 ppc_elf_fake_sections (abfd
, shdr
, asect
)
2277 bfd
*abfd ATTRIBUTE_UNUSED
;
2278 Elf_Internal_Shdr
*shdr
;
2281 if ((asect
->flags
& SEC_EXCLUDE
) != 0)
2282 shdr
->sh_flags
|= SHF_EXCLUDE
;
2284 if ((asect
->flags
& SEC_SORT_ENTRIES
) != 0)
2285 shdr
->sh_type
= SHT_ORDERED
;
2290 /* Create a special linker section */
2291 static elf_linker_section_t
*
2292 ppc_elf_create_linker_section (abfd
, info
, which
)
2294 struct bfd_link_info
*info
;
2295 enum elf_linker_section_enum which
;
2297 bfd
*dynobj
= elf_hash_table (info
)->dynobj
;
2298 elf_linker_section_t
*lsect
;
2300 /* Record the first bfd section that needs the special section. */
2302 dynobj
= elf_hash_table (info
)->dynobj
= abfd
;
2304 /* If this is the first time, create the section. */
2305 lsect
= elf_linker_section (dynobj
, which
);
2308 elf_linker_section_t defaults
;
2309 static elf_linker_section_t zero_section
;
2311 defaults
= zero_section
;
2312 defaults
.which
= which
;
2313 defaults
.hole_written_p
= FALSE
;
2314 defaults
.alignment
= 2;
2316 /* Both of these sections are (technically) created by the user
2317 putting data in them, so they shouldn't be marked
2320 The linker creates them so it has somewhere to attach their
2321 respective symbols. In fact, if they were empty it would
2322 be OK to leave the symbol set to 0 (or any random number), because
2323 the appropriate register should never be used. */
2324 defaults
.flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
2330 (*_bfd_error_handler
) (_("%s: unknown special linker type %d"),
2331 bfd_get_filename (abfd
),
2334 bfd_set_error (bfd_error_bad_value
);
2335 return (elf_linker_section_t
*) 0;
2337 case LINKER_SECTION_SDATA
: /* .sdata/.sbss section */
2338 defaults
.name
= ".sdata";
2339 defaults
.rel_name
= ".rela.sdata";
2340 defaults
.bss_name
= ".sbss";
2341 defaults
.sym_name
= "_SDA_BASE_";
2342 defaults
.sym_offset
= 32768;
2345 case LINKER_SECTION_SDATA2
: /* .sdata2/.sbss2 section */
2346 defaults
.name
= ".sdata2";
2347 defaults
.rel_name
= ".rela.sdata2";
2348 defaults
.bss_name
= ".sbss2";
2349 defaults
.sym_name
= "_SDA2_BASE_";
2350 defaults
.sym_offset
= 32768;
2351 defaults
.flags
|= SEC_READONLY
;
2355 lsect
= _bfd_elf_create_linker_section (abfd
, info
, which
, &defaults
);
2361 /* If we have a non-zero sized .sbss2 or .PPC.EMB.sbss0 sections, we
2362 need to bump up the number of section headers. */
2365 ppc_elf_additional_program_headers (abfd
)
2373 s
= bfd_get_section_by_name (abfd
, ".interp");
2377 s
= bfd_get_section_by_name (abfd
, ".sbss2");
2378 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0 && s
->_raw_size
> 0)
2381 s
= bfd_get_section_by_name (abfd
, ".PPC.EMB.sbss0");
2382 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0 && s
->_raw_size
> 0)
2388 /* Modify the segment map if needed. */
2391 ppc_elf_modify_segment_map (abfd
)
2392 bfd
*abfd ATTRIBUTE_UNUSED
;
2397 /* The powerpc .got has a blrl instruction in it. Mark it executable. */
2400 ppc_elf_create_got (abfd
, info
)
2402 struct bfd_link_info
*info
;
2404 struct ppc_elf_link_hash_table
*htab
;
2408 if (!_bfd_elf_create_got_section (abfd
, info
))
2411 htab
= ppc_elf_hash_table (info
);
2412 htab
->got
= s
= bfd_get_section_by_name (abfd
, ".got");
2416 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_CODE
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
2417 | SEC_LINKER_CREATED
);
2418 if (!bfd_set_section_flags (abfd
, s
, flags
))
2421 htab
->relgot
= bfd_make_section (abfd
, ".rela.got");
2423 || ! bfd_set_section_flags (abfd
, htab
->relgot
,
2424 (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
2425 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
2427 || ! bfd_set_section_alignment (abfd
, htab
->relgot
, 2))
2433 /* We have to create .dynsbss and .rela.sbss here so that they get mapped
2434 to output sections (just like _bfd_elf_create_dynamic_sections has
2435 to create .dynbss and .rela.bss). */
2438 ppc_elf_create_dynamic_sections (abfd
, info
)
2440 struct bfd_link_info
*info
;
2442 struct ppc_elf_link_hash_table
*htab
;
2446 if (!ppc_elf_create_got (abfd
, info
))
2449 if (!_bfd_elf_create_dynamic_sections (abfd
, info
))
2452 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
2453 | SEC_LINKER_CREATED
);
2455 htab
= ppc_elf_hash_table (info
);
2456 htab
->dynbss
= bfd_get_section_by_name (abfd
, ".dynbss");
2457 htab
->dynsbss
= s
= bfd_make_section (abfd
, ".dynsbss");
2459 || ! bfd_set_section_flags (abfd
, s
, SEC_ALLOC
))
2464 htab
->relbss
= bfd_get_section_by_name (abfd
, ".rela.bss");
2465 htab
->relsbss
= s
= bfd_make_section (abfd
, ".rela.sbss");
2467 || ! bfd_set_section_flags (abfd
, s
, flags
| SEC_READONLY
)
2468 || ! bfd_set_section_alignment (abfd
, s
, 2))
2472 htab
->relplt
= bfd_get_section_by_name (abfd
, ".rela.plt");
2473 htab
->plt
= s
= bfd_get_section_by_name (abfd
, ".plt");
2477 flags
= SEC_ALLOC
| SEC_CODE
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
;
2478 return bfd_set_section_flags (abfd
, s
, flags
);
2481 /* Adjust a symbol defined by a dynamic object and referenced by a
2482 regular object. The current definition is in some section of the
2483 dynamic object, but we're not including those sections. We have to
2484 change the definition to something the rest of the link can
2488 ppc_elf_adjust_dynamic_symbol (info
, h
)
2489 struct bfd_link_info
*info
;
2490 struct elf_link_hash_entry
*h
;
2492 struct ppc_elf_link_hash_table
*htab
;
2494 unsigned int power_of_two
;
2497 fprintf (stderr
, "ppc_elf_adjust_dynamic_symbol called for %s\n",
2498 h
->root
.root
.string
);
2501 /* Make sure we know what is going on here. */
2502 htab
= ppc_elf_hash_table (info
);
2503 BFD_ASSERT (htab
->elf
.dynobj
!= NULL
2504 && ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
)
2505 || h
->weakdef
!= NULL
2506 || ((h
->elf_link_hash_flags
2507 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0
2508 && (h
->elf_link_hash_flags
2509 & ELF_LINK_HASH_REF_REGULAR
) != 0
2510 && (h
->elf_link_hash_flags
2511 & ELF_LINK_HASH_DEF_REGULAR
) == 0)));
2513 /* Deal with function syms. */
2514 if (h
->type
== STT_FUNC
2515 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
2517 /* Clear procedure linkage table information for any symbol that
2518 won't need a .plt entry. */
2519 if (! htab
->elf
.dynamic_sections_created
2520 || SYMBOL_CALLS_LOCAL (info
, h
)
2521 || h
->plt
.refcount
<= 0)
2523 /* A PLT entry is not required/allowed when:
2525 1. We are not using ld.so; because then the PLT entry
2526 can't be set up, so we can't use one.
2528 2. We know for certain that a call to this symbol
2529 will go to this object.
2531 3. GC has rendered the entry unused. */
2532 h
->plt
.offset
= (bfd_vma
) -1;
2533 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
2538 h
->plt
.offset
= (bfd_vma
) -1;
2540 /* If this is a weak symbol, and there is a real definition, the
2541 processor independent code will have arranged for us to see the
2542 real definition first, and we can just use the same value. */
2543 if (h
->weakdef
!= NULL
)
2545 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
2546 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
2547 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
2548 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
2549 if (ELIMINATE_COPY_RELOCS
)
2550 h
->elf_link_hash_flags
2551 = ((h
->elf_link_hash_flags
& ~ELF_LINK_NON_GOT_REF
)
2552 | (h
->weakdef
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
));
2556 /* This is a reference to a symbol defined by a dynamic object which
2557 is not a function. */
2559 /* If we are creating a shared library, we must presume that the
2560 only references to the symbol are via the global offset table.
2561 For such cases we need not do anything here; the relocations will
2562 be handled correctly by relocate_section. */
2566 /* If there are no references to this symbol that do not use the
2567 GOT, we don't need to generate a copy reloc. */
2568 if ((h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0)
2571 if (ELIMINATE_COPY_RELOCS
)
2573 struct ppc_elf_dyn_relocs
*p
;
2574 for (p
= ppc_elf_hash_entry (h
)->dyn_relocs
; p
!= NULL
; p
= p
->next
)
2576 s
= p
->sec
->output_section
;
2577 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
2581 /* If we didn't find any dynamic relocs in read-only sections, then
2582 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
2585 h
->elf_link_hash_flags
&= ~ELF_LINK_NON_GOT_REF
;
2590 /* We must allocate the symbol in our .dynbss section, which will
2591 become part of the .bss section of the executable. There will be
2592 an entry for this symbol in the .dynsym section. The dynamic
2593 object will contain position independent code, so all references
2594 from the dynamic object to this symbol will go through the global
2595 offset table. The dynamic linker will use the .dynsym entry to
2596 determine the address it must put in the global offset table, so
2597 both the dynamic object and the regular object will refer to the
2598 same memory location for the variable.
2600 Of course, if the symbol is sufficiently small, we must instead
2601 allocate it in .sbss. FIXME: It would be better to do this if and
2602 only if there were actually SDAREL relocs for that symbol. */
2604 if (h
->size
<= elf_gp_size (htab
->elf
.dynobj
))
2608 BFD_ASSERT (s
!= NULL
);
2610 /* We must generate a R_PPC_COPY reloc to tell the dynamic linker to
2611 copy the initial value out of the dynamic object and into the
2612 runtime process image. We need to remember the offset into the
2613 .rela.bss section we are going to use. */
2614 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
2618 if (h
->size
<= elf_gp_size (htab
->elf
.dynobj
))
2619 srel
= htab
->relsbss
;
2621 srel
= htab
->relbss
;
2622 BFD_ASSERT (srel
!= NULL
);
2623 srel
->_raw_size
+= sizeof (Elf32_External_Rela
);
2624 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_COPY
;
2627 /* We need to figure out the alignment required for this symbol. I
2628 have no idea how ELF linkers handle this. */
2629 power_of_two
= bfd_log2 (h
->size
);
2630 if (power_of_two
> 4)
2633 /* Apply the required alignment. */
2634 s
->_raw_size
= BFD_ALIGN (s
->_raw_size
,
2635 (bfd_size_type
) (1 << power_of_two
));
2636 if (power_of_two
> bfd_get_section_alignment (htab
->elf
.dynobj
, s
))
2638 if (! bfd_set_section_alignment (htab
->elf
.dynobj
, s
, power_of_two
))
2642 /* Define the symbol as being at this point in the section. */
2643 h
->root
.u
.def
.section
= s
;
2644 h
->root
.u
.def
.value
= s
->_raw_size
;
2646 /* Increment the section size to make room for the symbol. */
2647 s
->_raw_size
+= h
->size
;
2652 /* This is the condition under which finish_dynamic_symbol will be
2653 called from elflink.h. If elflink.h doesn't call our
2654 finish_dynamic_symbol routine, we'll need to do something about
2655 initializing any .plt and .got entries in relocate_section. */
2656 #define WILL_CALL_FINISH_DYNAMIC_SYMBOL(DYN, SHARED, H) \
2659 || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) \
2660 && ((H)->dynindx != -1 \
2661 || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0))
2663 /* Of those relocs that might be copied as dynamic relocs, this macro
2664 selects those that must be copied when linking a shared library,
2665 even when the symbol is local. */
2667 #define MUST_BE_DYN_RELOC(RTYPE) \
2668 ((RTYPE) != R_PPC_REL24 \
2669 && (RTYPE) != R_PPC_REL14 \
2670 && (RTYPE) != R_PPC_REL14_BRTAKEN \
2671 && (RTYPE) != R_PPC_REL14_BRNTAKEN \
2672 && (RTYPE) != R_PPC_REL32)
2674 /* Allocate space in associated reloc sections for dynamic relocs. */
2677 allocate_dynrelocs (h
, inf
)
2678 struct elf_link_hash_entry
*h
;
2681 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
2682 struct ppc_elf_link_hash_entry
*eh
;
2683 struct ppc_elf_link_hash_table
*htab
;
2684 struct ppc_elf_dyn_relocs
*p
;
2686 if (h
->root
.type
== bfd_link_hash_indirect
)
2689 if (h
->root
.type
== bfd_link_hash_warning
)
2690 /* When warning symbols are created, they **replace** the "real"
2691 entry in the hash table, thus we never get to see the real
2692 symbol in a hash traversal. So look at it now. */
2693 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2695 htab
= ppc_elf_hash_table (info
);
2696 if (htab
->elf
.dynamic_sections_created
2697 && h
->plt
.refcount
> 0)
2699 /* Make sure this symbol is output as a dynamic symbol. */
2700 if (h
->dynindx
== -1
2701 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
2703 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
2708 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h
))
2710 asection
*s
= htab
->plt
;
2712 /* If this is the first .plt entry, make room for the special
2714 if (s
->_raw_size
== 0)
2715 s
->_raw_size
+= PLT_INITIAL_ENTRY_SIZE
;
2717 /* The PowerPC PLT is actually composed of two parts, the
2718 first part is 2 words (for a load and a jump), and then
2719 there is a remaining word available at the end. */
2720 h
->plt
.offset
= (PLT_INITIAL_ENTRY_SIZE
2722 * ((s
->_raw_size
- PLT_INITIAL_ENTRY_SIZE
)
2723 / PLT_ENTRY_SIZE
)));
2725 /* If this symbol is not defined in a regular file, and we
2726 are not generating a shared library, then set the symbol
2727 to this location in the .plt. This is required to make
2728 function pointers compare as equal between the normal
2729 executable and the shared library. */
2731 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
2733 h
->root
.u
.def
.section
= s
;
2734 h
->root
.u
.def
.value
= h
->plt
.offset
;
2737 /* Make room for this entry. After the 8192nd entry, room
2738 for two entries is allocated. */
2739 s
->_raw_size
+= PLT_ENTRY_SIZE
;
2740 if ((s
->_raw_size
- PLT_INITIAL_ENTRY_SIZE
) / PLT_ENTRY_SIZE
2741 >= PLT_NUM_SINGLE_ENTRIES
)
2742 s
->_raw_size
+= PLT_ENTRY_SIZE
;
2744 /* We also need to make an entry in the .rela.plt section. */
2745 htab
->relplt
->_raw_size
+= sizeof (Elf32_External_Rela
);
2749 h
->plt
.offset
= (bfd_vma
) -1;
2750 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
2755 h
->plt
.offset
= (bfd_vma
) -1;
2756 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
2759 eh
= (struct ppc_elf_link_hash_entry
*) h
;
2760 if (eh
->elf
.got
.refcount
> 0)
2762 /* Make sure this symbol is output as a dynamic symbol. */
2763 if (eh
->elf
.dynindx
== -1
2764 && (eh
->elf
.elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
2766 if (!bfd_elf32_link_record_dynamic_symbol (info
, &eh
->elf
))
2770 if (eh
->tls_mask
== (TLS_TLS
| TLS_LD
)
2771 && !(eh
->elf
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
))
2772 /* If just an LD reloc, we'll just use htab->tlsld_got.offset. */
2773 eh
->elf
.got
.offset
= (bfd_vma
) -1;
2777 eh
->elf
.got
.offset
= htab
->got
->_raw_size
;
2778 if ((eh
->tls_mask
& TLS_TLS
) != 0)
2780 if ((eh
->tls_mask
& TLS_LD
) != 0)
2781 htab
->got
->_raw_size
+= 8;
2782 if ((eh
->tls_mask
& TLS_GD
) != 0)
2783 htab
->got
->_raw_size
+= 8;
2784 if ((eh
->tls_mask
& (TLS_TPREL
| TLS_TPRELGD
)) != 0)
2785 htab
->got
->_raw_size
+= 4;
2786 if ((eh
->tls_mask
& TLS_DTPREL
) != 0)
2787 htab
->got
->_raw_size
+= 4;
2790 htab
->got
->_raw_size
+= 4;
2791 dyn
= htab
->elf
.dynamic_sections_created
;
2793 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, &eh
->elf
))
2795 /* All the entries we allocated need relocs. */
2796 htab
->relgot
->_raw_size
2797 += ((htab
->got
->_raw_size
- eh
->elf
.got
.offset
) / 4
2798 * sizeof (Elf32_External_Rela
));
2799 /* Except LD only needs one. */
2800 if ((eh
->tls_mask
& TLS_LD
) != 0)
2801 htab
->relgot
->_raw_size
-= sizeof (Elf32_External_Rela
);
2806 eh
->elf
.got
.offset
= (bfd_vma
) -1;
2808 if (eh
->dyn_relocs
== NULL
)
2811 /* In the shared -Bsymbolic case, discard space allocated for
2812 dynamic pc-relative relocs against symbols which turn out to be
2813 defined in regular objects. For the normal shared case, discard
2814 space for relocs that have become local due to symbol visibility
2818 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) != 0
2819 && ((h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) != 0
2822 struct ppc_elf_dyn_relocs
**pp
;
2824 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
2826 p
->count
-= p
->pc_count
;
2835 else if (ELIMINATE_COPY_RELOCS
)
2837 /* For the non-shared case, discard space for relocs against
2838 symbols which turn out to need copy relocs or are not
2841 if ((h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0
2842 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
2843 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
2845 /* Make sure this symbol is output as a dynamic symbol.
2846 Undefined weak syms won't yet be marked as dynamic. */
2847 if (h
->dynindx
== -1
2848 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
2850 if (! bfd_elf64_link_record_dynamic_symbol (info
, h
))
2854 /* If that succeeded, we know we'll be keeping all the
2856 if (h
->dynindx
!= -1)
2860 eh
->dyn_relocs
= NULL
;
2865 /* Finally, allocate space. */
2866 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
2868 asection
*sreloc
= elf_section_data (p
->sec
)->sreloc
;
2869 sreloc
->_raw_size
+= p
->count
* sizeof (Elf32_External_Rela
);
2875 /* Find any dynamic relocs that apply to read-only sections. */
2878 readonly_dynrelocs (h
, info
)
2879 struct elf_link_hash_entry
*h
;
2882 struct ppc_elf_dyn_relocs
*p
;
2884 if (h
->root
.type
== bfd_link_hash_indirect
)
2887 if (h
->root
.type
== bfd_link_hash_warning
)
2888 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2890 for (p
= ppc_elf_hash_entry (h
)->dyn_relocs
; p
!= NULL
; p
= p
->next
)
2892 asection
*s
= p
->sec
->output_section
;
2895 && ((s
->flags
& (SEC_READONLY
| SEC_ALLOC
))
2896 == (SEC_READONLY
| SEC_ALLOC
)))
2898 ((struct bfd_link_info
*) info
)->flags
|= DF_TEXTREL
;
2900 /* Not an error, just cut short the traversal. */
2907 /* Set the sizes of the dynamic sections. */
2910 ppc_elf_size_dynamic_sections (output_bfd
, info
)
2911 bfd
*output_bfd ATTRIBUTE_UNUSED
;
2912 struct bfd_link_info
*info
;
2914 struct ppc_elf_link_hash_table
*htab
;
2920 fprintf (stderr
, "ppc_elf_size_dynamic_sections called\n");
2923 htab
= ppc_elf_hash_table (info
);
2924 BFD_ASSERT (htab
->elf
.dynobj
!= NULL
);
2926 if (elf_hash_table (info
)->dynamic_sections_created
)
2928 /* Set the contents of the .interp section to the interpreter. */
2931 s
= bfd_get_section_by_name (htab
->elf
.dynobj
, ".interp");
2932 BFD_ASSERT (s
!= NULL
);
2933 s
->_raw_size
= sizeof ELF_DYNAMIC_INTERPRETER
;
2934 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
2938 if (htab
->tlsld_got
.refcount
> 0)
2940 htab
->tlsld_got
.offset
= htab
->got
->_raw_size
;
2941 htab
->got
->_raw_size
+= 8;
2943 htab
->relgot
->_raw_size
+= sizeof (Elf32_External_Rela
);
2946 htab
->tlsld_got
.offset
= (bfd_vma
) -1;
2948 /* Set up .got offsets for local syms, and space for local dynamic
2950 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
2952 bfd_signed_vma
*local_got
;
2953 bfd_signed_vma
*end_local_got
;
2955 bfd_size_type locsymcount
;
2956 Elf_Internal_Shdr
*symtab_hdr
;
2959 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
)
2962 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
2964 struct ppc_elf_dyn_relocs
*p
;
2966 for (p
= ((struct ppc_elf_dyn_relocs
*)
2967 elf_section_data (s
)->local_dynrel
);
2971 if (!bfd_is_abs_section (p
->sec
)
2972 && bfd_is_abs_section (p
->sec
->output_section
))
2974 /* Input section has been discarded, either because
2975 it is a copy of a linkonce section or due to
2976 linker script /DISCARD/, so we'll be discarding
2979 else if (p
->count
!= 0)
2981 elf_section_data (p
->sec
)->sreloc
->_raw_size
2982 += p
->count
* sizeof (Elf32_External_Rela
);
2983 if ((p
->sec
->output_section
->flags
2984 & (SEC_READONLY
| SEC_ALLOC
))
2985 == (SEC_READONLY
| SEC_ALLOC
))
2986 info
->flags
|= DF_TEXTREL
;
2991 local_got
= elf_local_got_refcounts (ibfd
);
2995 symtab_hdr
= &elf_tdata (ibfd
)->symtab_hdr
;
2996 locsymcount
= symtab_hdr
->sh_info
;
2997 end_local_got
= local_got
+ locsymcount
;
2998 lgot_masks
= (char *) end_local_got
;
3000 srel
= htab
->relgot
;
3001 for (; local_got
< end_local_got
; ++local_got
, ++lgot_masks
)
3004 if (*lgot_masks
== (TLS_TLS
| TLS_LD
))
3006 /* If just an LD reloc, we'll just use
3007 htab->tlsld_got.offset. */
3008 if (htab
->tlsld_got
.offset
== (bfd_vma
) -1)
3010 htab
->tlsld_got
.offset
= s
->_raw_size
;
3013 srel
->_raw_size
+= sizeof (Elf32_External_Rela
);
3015 *local_got
= (bfd_vma
) -1;
3019 *local_got
= s
->_raw_size
;
3020 if ((*lgot_masks
& TLS_TLS
) != 0)
3022 if ((*lgot_masks
& TLS_GD
) != 0)
3024 if ((*lgot_masks
& (TLS_TPREL
| TLS_TPRELGD
)) != 0)
3026 if ((*lgot_masks
& TLS_DTPREL
) != 0)
3032 srel
->_raw_size
+= ((s
->_raw_size
- *local_got
) / 4
3033 * sizeof (Elf32_External_Rela
));
3037 *local_got
= (bfd_vma
) -1;
3040 /* Allocate space for global sym dynamic relocs. */
3041 elf_link_hash_traverse (elf_hash_table (info
), allocate_dynrelocs
, info
);
3043 /* We've now determined the sizes of the various dynamic sections.
3044 Allocate memory for them. */
3046 for (s
= htab
->elf
.dynobj
->sections
; s
!= NULL
; s
= s
->next
)
3048 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
3053 || (htab
->sdata
!= NULL
&& s
== htab
->sdata
->section
)
3054 || (htab
->sdata2
!= NULL
&& s
== htab
->sdata2
->section
))
3056 /* Strip this section if we don't need it; see the
3059 else if (strncmp (bfd_get_section_name (dynobj
, s
), ".rela", 5) == 0)
3061 if (s
->_raw_size
== 0)
3063 /* If we don't need this section, strip it from the
3064 output file. This is mostly to handle .rela.bss and
3065 .rela.plt. We must create both sections in
3066 create_dynamic_sections, because they must be created
3067 before the linker maps input sections to output
3068 sections. The linker does that before
3069 adjust_dynamic_symbol is called, and it is that
3070 function which decides whether anything needs to go
3071 into these sections. */
3075 /* Remember whether there are any relocation sections. */
3078 /* We use the reloc_count field as a counter if we need
3079 to copy relocs into the output file. */
3085 /* It's not one of our sections, so don't allocate space. */
3089 if (s
->_raw_size
== 0)
3091 _bfd_strip_section_from_output (info
, s
);
3095 /* Allocate memory for the section contents. */
3096 s
->contents
= (bfd_byte
*) bfd_zalloc (htab
->elf
.dynobj
, s
->_raw_size
);
3097 if (s
->contents
== NULL
)
3101 if (htab
->elf
.dynamic_sections_created
)
3103 /* Add some entries to the .dynamic section. We fill in the
3104 values later, in ppc_elf_finish_dynamic_sections, but we
3105 must add the entries now so that we get the correct size for
3106 the .dynamic section. The DT_DEBUG entry is filled in by the
3107 dynamic linker and used by the debugger. */
3108 #define add_dynamic_entry(TAG, VAL) \
3109 bfd_elf32_add_dynamic_entry (info, (bfd_vma) (TAG), (bfd_vma) (VAL))
3113 if (!add_dynamic_entry (DT_DEBUG
, 0))
3117 if (htab
->plt
!= NULL
&& htab
->plt
->_raw_size
!= 0)
3119 if (!add_dynamic_entry (DT_PLTGOT
, 0)
3120 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
3121 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
3122 || !add_dynamic_entry (DT_JMPREL
, 0))
3128 if (!add_dynamic_entry (DT_RELA
, 0)
3129 || !add_dynamic_entry (DT_RELASZ
, 0)
3130 || !add_dynamic_entry (DT_RELAENT
, sizeof (Elf32_External_Rela
)))
3134 /* If any dynamic relocs apply to a read-only section, then we
3135 need a DT_TEXTREL entry. */
3136 if ((info
->flags
& DF_TEXTREL
) == 0)
3137 elf_link_hash_traverse (elf_hash_table (info
), readonly_dynrelocs
,
3140 if ((info
->flags
& DF_TEXTREL
) != 0)
3142 if (!add_dynamic_entry (DT_TEXTREL
, 0))
3146 #undef add_dynamic_entry
3152 update_local_sym_info (abfd
, symtab_hdr
, r_symndx
, tls_type
)
3154 Elf_Internal_Shdr
*symtab_hdr
;
3155 unsigned long r_symndx
;
3158 bfd_signed_vma
*local_got_refcounts
= elf_local_got_refcounts (abfd
);
3159 char *local_got_tls_masks
;
3161 if (local_got_refcounts
== NULL
)
3163 bfd_size_type size
= symtab_hdr
->sh_info
;
3165 size
*= sizeof (*local_got_refcounts
) + sizeof (*local_got_tls_masks
);
3166 local_got_refcounts
= (bfd_signed_vma
*) bfd_zalloc (abfd
, size
);
3167 if (local_got_refcounts
== NULL
)
3169 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
3172 local_got_refcounts
[r_symndx
] += 1;
3173 local_got_tls_masks
= (char *) (local_got_refcounts
+ symtab_hdr
->sh_info
);
3174 local_got_tls_masks
[r_symndx
] |= tls_type
;
3179 bad_shared_reloc (abfd
, r_type
)
3181 enum elf_ppc_reloc_type r_type
;
3183 (*_bfd_error_handler
)
3184 (_("%s: relocation %s cannot be used when making a shared object"),
3185 bfd_archive_filename (abfd
),
3186 ppc_elf_howto_table
[(int) r_type
]->name
);
3187 bfd_set_error (bfd_error_bad_value
);
3190 /* Look through the relocs for a section during the first phase, and
3191 allocate space in the global offset table or procedure linkage
3195 ppc_elf_check_relocs (abfd
, info
, sec
, relocs
)
3197 struct bfd_link_info
*info
;
3199 const Elf_Internal_Rela
*relocs
;
3201 struct ppc_elf_link_hash_table
*htab
;
3202 Elf_Internal_Shdr
*symtab_hdr
;
3203 struct elf_link_hash_entry
**sym_hashes
;
3204 const Elf_Internal_Rela
*rel
;
3205 const Elf_Internal_Rela
*rel_end
;
3208 if (info
->relocateable
)
3212 fprintf (stderr
, "ppc_elf_check_relocs called for section %s in %s\n",
3213 bfd_get_section_name (abfd
, sec
),
3214 bfd_archive_filename (abfd
));
3217 /* Create the linker generated sections all the time so that the
3218 special symbols are created. */
3220 htab
= ppc_elf_hash_table (info
);
3221 if (htab
->sdata
== NULL
)
3223 htab
->sdata
= elf_linker_section (abfd
, LINKER_SECTION_SDATA
);
3224 if (htab
->sdata
== NULL
)
3225 htab
->sdata
= ppc_elf_create_linker_section (abfd
, info
,
3226 LINKER_SECTION_SDATA
);
3227 if (htab
->sdata
== NULL
)
3231 if (htab
->sdata2
== NULL
)
3233 htab
->sdata2
= elf_linker_section (abfd
, LINKER_SECTION_SDATA2
);
3234 if (htab
->sdata2
== NULL
)
3235 htab
->sdata2
= ppc_elf_create_linker_section (abfd
, info
,
3236 LINKER_SECTION_SDATA2
);
3237 if (htab
->sdata2
== NULL
)
3241 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
3242 sym_hashes
= elf_sym_hashes (abfd
);
3245 rel_end
= relocs
+ sec
->reloc_count
;
3246 for (rel
= relocs
; rel
< rel_end
; rel
++)
3248 unsigned long r_symndx
;
3249 enum elf_ppc_reloc_type r_type
;
3250 struct elf_link_hash_entry
*h
;
3253 r_symndx
= ELF32_R_SYM (rel
->r_info
);
3254 if (r_symndx
< symtab_hdr
->sh_info
)
3257 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
3259 /* If a relocation refers to _GLOBAL_OFFSET_TABLE_, create the .got.
3260 This shows up in particular in an R_PPC_ADDR32 in the eabi
3262 if (h
&& strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
3264 if (htab
->got
== NULL
)
3266 if (htab
->elf
.dynobj
== NULL
)
3267 htab
->elf
.dynobj
= abfd
;
3268 if (!ppc_elf_create_got (htab
->elf
.dynobj
, info
))
3273 r_type
= (enum elf_ppc_reloc_type
) ELF32_R_TYPE (rel
->r_info
);
3276 case R_PPC_GOT_TLSLD16
:
3277 case R_PPC_GOT_TLSLD16_LO
:
3278 case R_PPC_GOT_TLSLD16_HI
:
3279 case R_PPC_GOT_TLSLD16_HA
:
3280 htab
->tlsld_got
.refcount
+= 1;
3281 tls_type
= TLS_TLS
| TLS_LD
;
3284 case R_PPC_GOT_TLSGD16
:
3285 case R_PPC_GOT_TLSGD16_LO
:
3286 case R_PPC_GOT_TLSGD16_HI
:
3287 case R_PPC_GOT_TLSGD16_HA
:
3288 tls_type
= TLS_TLS
| TLS_GD
;
3291 case R_PPC_GOT_TPREL16
:
3292 case R_PPC_GOT_TPREL16_LO
:
3293 case R_PPC_GOT_TPREL16_HI
:
3294 case R_PPC_GOT_TPREL16_HA
:
3296 info
->flags
|= DF_STATIC_TLS
;
3297 tls_type
= TLS_TLS
| TLS_TPREL
;
3300 case R_PPC_GOT_DTPREL16
:
3301 case R_PPC_GOT_DTPREL16_LO
:
3302 case R_PPC_GOT_DTPREL16_HI
:
3303 case R_PPC_GOT_DTPREL16_HA
:
3304 tls_type
= TLS_TLS
| TLS_DTPREL
;
3306 sec
->has_tls_reloc
= 1;
3309 /* GOT16 relocations */
3311 case R_PPC_GOT16_LO
:
3312 case R_PPC_GOT16_HI
:
3313 case R_PPC_GOT16_HA
:
3314 /* This symbol requires a global offset table entry. */
3315 if (htab
->got
== NULL
)
3317 if (htab
->elf
.dynobj
== NULL
)
3318 htab
->elf
.dynobj
= abfd
;
3319 if (!ppc_elf_create_got (htab
->elf
.dynobj
, info
))
3324 h
->got
.refcount
+= 1;
3325 ppc_elf_hash_entry (h
)->tls_mask
|= tls_type
;
3328 /* This is a global offset table entry for a local symbol. */
3329 if (!update_local_sym_info (abfd
, symtab_hdr
, r_symndx
, tls_type
))
3333 /* Indirect .sdata relocation. */
3334 case R_PPC_EMB_SDAI16
:
3337 bad_shared_reloc (abfd
, r_type
);
3340 if (!bfd_elf32_create_pointer_linker_section (abfd
, info
,
3341 htab
->sdata
, h
, rel
))
3345 /* Indirect .sdata2 relocation. */
3346 case R_PPC_EMB_SDA2I16
:
3349 bad_shared_reloc (abfd
, r_type
);
3352 if (!bfd_elf32_create_pointer_linker_section (abfd
, info
,
3353 htab
->sdata2
, h
, rel
))
3357 case R_PPC_SDAREL16
:
3358 case R_PPC_EMB_SDA2REL
:
3359 case R_PPC_EMB_SDA21
:
3360 case R_PPC_EMB_RELSDA
:
3361 case R_PPC_EMB_NADDR32
:
3362 case R_PPC_EMB_NADDR16
:
3363 case R_PPC_EMB_NADDR16_LO
:
3364 case R_PPC_EMB_NADDR16_HI
:
3365 case R_PPC_EMB_NADDR16_HA
:
3368 bad_shared_reloc (abfd
, r_type
);
3374 case R_PPC_PLTREL24
:
3375 case R_PPC_PLTREL32
:
3376 case R_PPC_PLT16_LO
:
3377 case R_PPC_PLT16_HI
:
3378 case R_PPC_PLT16_HA
:
3380 fprintf (stderr
, "Reloc requires a PLT entry\n");
3382 /* This symbol requires a procedure linkage table entry. We
3383 actually build the entry in finish_dynamic_symbol,
3384 because this might be a case of linking PIC code without
3385 linking in any dynamic objects, in which case we don't
3386 need to generate a procedure linkage table after all. */
3390 /* It does not make sense to have a procedure linkage
3391 table entry for a local symbol. */
3392 bfd_set_error (bfd_error_bad_value
);
3396 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
3400 /* The following relocations don't need to propagate the
3401 relocation if linking a shared object since they are
3402 section relative. */
3404 case R_PPC_SECTOFF_LO
:
3405 case R_PPC_SECTOFF_HI
:
3406 case R_PPC_SECTOFF_HA
:
3407 case R_PPC_DTPREL16
:
3408 case R_PPC_DTPREL16_LO
:
3409 case R_PPC_DTPREL16_HI
:
3410 case R_PPC_DTPREL16_HA
:
3414 /* This are just markers. */
3416 case R_PPC_EMB_MRKREF
:
3421 /* These should only appear in dynamic objects. */
3423 case R_PPC_GLOB_DAT
:
3424 case R_PPC_JMP_SLOT
:
3425 case R_PPC_RELATIVE
:
3428 /* These aren't handled yet. We'll report an error later. */
3430 case R_PPC_EMB_RELSEC16
:
3431 case R_PPC_EMB_RELST_LO
:
3432 case R_PPC_EMB_RELST_HI
:
3433 case R_PPC_EMB_RELST_HA
:
3434 case R_PPC_EMB_BIT_FLD
:
3437 /* This refers only to functions defined in the shared library. */
3438 case R_PPC_LOCAL24PC
:
3441 /* This relocation describes the C++ object vtable hierarchy.
3442 Reconstruct it for later use during GC. */
3443 case R_PPC_GNU_VTINHERIT
:
3444 if (!_bfd_elf32_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
3448 /* This relocation describes which C++ vtable entries are actually
3449 used. Record for later use during GC. */
3450 case R_PPC_GNU_VTENTRY
:
3451 if (!_bfd_elf32_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
3455 /* We shouldn't really be seeing these. */
3458 info
->flags
|= DF_STATIC_TLS
;
3462 case R_PPC_DTPMOD32
:
3463 case R_PPC_DTPREL32
:
3467 case R_PPC_TPREL16_LO
:
3468 case R_PPC_TPREL16_HI
:
3469 case R_PPC_TPREL16_HA
:
3471 info
->flags
|= DF_STATIC_TLS
;
3474 /* When creating a shared object, we must copy these
3475 relocs into the output file. We create a reloc
3476 section in dynobj and make room for the reloc. */
3479 case R_PPC_REL14_BRTAKEN
:
3480 case R_PPC_REL14_BRNTAKEN
:
3483 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
3490 case R_PPC_ADDR16_LO
:
3491 case R_PPC_ADDR16_HI
:
3492 case R_PPC_ADDR16_HA
:
3494 case R_PPC_ADDR14_BRTAKEN
:
3495 case R_PPC_ADDR14_BRNTAKEN
:
3498 if (h
!= NULL
&& !info
->shared
)
3500 /* We may need a plt entry if the symbol turns out to be
3501 a function defined in a dynamic object. */
3504 /* We may need a copy reloc too. */
3505 h
->elf_link_hash_flags
|= ELF_LINK_NON_GOT_REF
;
3509 /* If we are creating a shared library, and this is a reloc
3510 against a global symbol, or a non PC relative reloc
3511 against a local symbol, then we need to copy the reloc
3512 into the shared library. However, if we are linking with
3513 -Bsymbolic, we do not need to copy a reloc against a
3514 global symbol which is defined in an object we are
3515 including in the link (i.e., DEF_REGULAR is set). At
3516 this point we have not seen all the input files, so it is
3517 possible that DEF_REGULAR is not set now but will be set
3518 later (it is never cleared). In case of a weak definition,
3519 DEF_REGULAR may be cleared later by a strong definition in
3520 a shared library. We account for that possibility below by
3521 storing information in the dyn_relocs field of the hash
3522 table entry. A similar situation occurs when creating
3523 shared libraries and symbol visibility changes render the
3526 If on the other hand, we are creating an executable, we
3527 may need to keep relocations for symbols satisfied by a
3528 dynamic library if we manage to avoid copy relocs for the
3531 && (MUST_BE_DYN_RELOC (r_type
)
3533 && (! info
->symbolic
3534 || h
->root
.type
== bfd_link_hash_defweak
3535 || (h
->elf_link_hash_flags
3536 & ELF_LINK_HASH_DEF_REGULAR
) == 0))))
3537 || (ELIMINATE_COPY_RELOCS
3539 && (sec
->flags
& SEC_ALLOC
) != 0
3541 && (h
->root
.type
== bfd_link_hash_defweak
3542 || (h
->elf_link_hash_flags
3543 & ELF_LINK_HASH_DEF_REGULAR
) == 0)))
3545 struct ppc_elf_dyn_relocs
*p
;
3546 struct ppc_elf_dyn_relocs
**head
;
3549 fprintf (stderr
, "ppc_elf_check_relocs need to create relocation for %s\n",
3550 (h
&& h
->root
.root
.string
3551 ? h
->root
.root
.string
: "<unknown>"));
3557 name
= (bfd_elf_string_from_elf_section
3559 elf_elfheader (abfd
)->e_shstrndx
,
3560 elf_section_data (sec
)->rel_hdr
.sh_name
));
3564 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
3565 && strcmp (bfd_get_section_name (abfd
, sec
),
3568 sreloc
= bfd_get_section_by_name (htab
->elf
.dynobj
, name
);
3573 sreloc
= bfd_make_section (htab
->elf
.dynobj
, name
);
3574 flags
= (SEC_HAS_CONTENTS
| SEC_READONLY
3575 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
3576 if ((sec
->flags
& SEC_ALLOC
) != 0)
3577 flags
|= SEC_ALLOC
| SEC_LOAD
;
3579 || ! bfd_set_section_flags (htab
->elf
.dynobj
,
3581 || ! bfd_set_section_alignment (htab
->elf
.dynobj
,
3585 elf_section_data (sec
)->sreloc
= sreloc
;
3588 /* If this is a global symbol, we count the number of
3589 relocations we need for this symbol. */
3592 head
= &ppc_elf_hash_entry (h
)->dyn_relocs
;
3596 /* Track dynamic relocs needed for local syms too.
3597 We really need local syms available to do this
3601 s
= bfd_section_from_r_symndx (abfd
, &htab
->sym_sec
,
3606 head
= ((struct ppc_elf_dyn_relocs
**)
3607 &elf_section_data (s
)->local_dynrel
);
3611 if (p
== NULL
|| p
->sec
!= sec
)
3613 p
= ((struct ppc_elf_dyn_relocs
*)
3614 bfd_alloc (htab
->elf
.dynobj
, sizeof *p
));
3625 if (!MUST_BE_DYN_RELOC (r_type
))
3636 /* Return the section that should be marked against GC for a given
3640 ppc_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
)
3642 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
3643 Elf_Internal_Rela
*rel
;
3644 struct elf_link_hash_entry
*h
;
3645 Elf_Internal_Sym
*sym
;
3649 switch (ELF32_R_TYPE (rel
->r_info
))
3651 case R_PPC_GNU_VTINHERIT
:
3652 case R_PPC_GNU_VTENTRY
:
3656 switch (h
->root
.type
)
3658 case bfd_link_hash_defined
:
3659 case bfd_link_hash_defweak
:
3660 return h
->root
.u
.def
.section
;
3662 case bfd_link_hash_common
:
3663 return h
->root
.u
.c
.p
->section
;
3671 return bfd_section_from_elf_index (sec
->owner
, sym
->st_shndx
);
3676 /* Update the got, plt and dynamic reloc reference counts for the
3677 section being removed. */
3680 ppc_elf_gc_sweep_hook (abfd
, info
, sec
, relocs
)
3682 struct bfd_link_info
*info
;
3684 const Elf_Internal_Rela
*relocs
;
3686 struct ppc_elf_link_hash_table
*htab
;
3687 Elf_Internal_Shdr
*symtab_hdr
;
3688 struct elf_link_hash_entry
**sym_hashes
;
3689 bfd_signed_vma
*local_got_refcounts
;
3690 const Elf_Internal_Rela
*rel
, *relend
;
3692 elf_section_data (sec
)->local_dynrel
= NULL
;
3694 htab
= ppc_elf_hash_table (info
);
3695 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
3696 sym_hashes
= elf_sym_hashes (abfd
);
3697 local_got_refcounts
= elf_local_got_refcounts (abfd
);
3699 relend
= relocs
+ sec
->reloc_count
;
3700 for (rel
= relocs
; rel
< relend
; rel
++)
3702 unsigned long r_symndx
;
3703 enum elf_ppc_reloc_type r_type
;
3704 struct elf_link_hash_entry
*h
= NULL
;
3706 r_symndx
= ELF32_R_SYM (rel
->r_info
);
3707 if (r_symndx
>= symtab_hdr
->sh_info
)
3709 struct ppc_elf_dyn_relocs
**pp
, *p
;
3710 struct ppc_elf_link_hash_entry
*eh
;
3712 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
3713 eh
= (struct ppc_elf_link_hash_entry
*) h
;
3715 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; pp
= &p
->next
)
3718 /* Everything must go for SEC. */
3724 r_type
= (enum elf_ppc_reloc_type
) ELF32_R_TYPE (rel
->r_info
);
3727 case R_PPC_GOT_TLSLD16
:
3728 case R_PPC_GOT_TLSLD16_LO
:
3729 case R_PPC_GOT_TLSLD16_HI
:
3730 case R_PPC_GOT_TLSLD16_HA
:
3731 htab
->tlsld_got
.refcount
-= 1;
3734 case R_PPC_GOT_TLSGD16
:
3735 case R_PPC_GOT_TLSGD16_LO
:
3736 case R_PPC_GOT_TLSGD16_HI
:
3737 case R_PPC_GOT_TLSGD16_HA
:
3738 case R_PPC_GOT_TPREL16
:
3739 case R_PPC_GOT_TPREL16_LO
:
3740 case R_PPC_GOT_TPREL16_HI
:
3741 case R_PPC_GOT_TPREL16_HA
:
3742 case R_PPC_GOT_DTPREL16
:
3743 case R_PPC_GOT_DTPREL16_LO
:
3744 case R_PPC_GOT_DTPREL16_HI
:
3745 case R_PPC_GOT_DTPREL16_HA
:
3747 case R_PPC_GOT16_LO
:
3748 case R_PPC_GOT16_HI
:
3749 case R_PPC_GOT16_HA
:
3752 if (h
->got
.refcount
> 0)
3755 else if (local_got_refcounts
!= NULL
)
3757 if (local_got_refcounts
[r_symndx
] > 0)
3758 local_got_refcounts
[r_symndx
]--;
3764 case R_PPC_REL14_BRTAKEN
:
3765 case R_PPC_REL14_BRNTAKEN
:
3768 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
3775 case R_PPC_ADDR16_LO
:
3776 case R_PPC_ADDR16_HI
:
3777 case R_PPC_ADDR16_HA
:
3779 case R_PPC_ADDR14_BRTAKEN
:
3780 case R_PPC_ADDR14_BRNTAKEN
:
3784 case R_PPC_PLTREL24
:
3785 case R_PPC_PLT16_LO
:
3786 case R_PPC_PLT16_HI
:
3787 case R_PPC_PLT16_HA
:
3790 if (h
->plt
.refcount
> 0)
3802 /* Set htab->tls_sec and htab->tls_get_addr. */
3805 ppc_elf_tls_setup (obfd
, info
)
3807 struct bfd_link_info
*info
;
3810 struct ppc_elf_link_hash_table
*htab
;
3812 htab
= ppc_elf_hash_table (info
);
3813 htab
->tls_get_addr
= elf_link_hash_lookup (&htab
->elf
, "__tls_get_addr",
3814 FALSE
, FALSE
, TRUE
);
3816 for (tls
= obfd
->sections
; tls
!= NULL
; tls
= tls
->next
)
3817 if ((tls
->flags
& (SEC_THREAD_LOCAL
| SEC_LOAD
))
3818 == (SEC_THREAD_LOCAL
| SEC_LOAD
))
3820 htab
->tls_sec
= tls
;
3825 /* Run through all the TLS relocs looking for optimization
3829 ppc_elf_tls_optimize (obfd
, info
)
3830 bfd
*obfd ATTRIBUTE_UNUSED
;
3831 struct bfd_link_info
*info
;
3835 struct ppc_elf_link_hash_table
*htab
;
3837 if (info
->relocateable
|| info
->shared
)
3840 htab
= ppc_elf_hash_table (info
);
3841 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
3843 Elf_Internal_Sym
*locsyms
= NULL
;
3844 Elf_Internal_Shdr
*symtab_hdr
= &elf_tdata (ibfd
)->symtab_hdr
;
3846 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
3847 if (sec
->has_tls_reloc
&& !bfd_is_abs_section (sec
->output_section
))
3849 Elf_Internal_Rela
*relstart
, *rel
, *relend
;
3850 int expecting_tls_get_addr
;
3852 /* Read the relocations. */
3853 relstart
= _bfd_elf32_link_read_relocs (ibfd
, sec
, (PTR
) NULL
,
3854 (Elf_Internal_Rela
*) NULL
,
3856 if (relstart
== NULL
)
3859 expecting_tls_get_addr
= 0;
3860 relend
= relstart
+ sec
->reloc_count
;
3861 for (rel
= relstart
; rel
< relend
; rel
++)
3863 enum elf_ppc_reloc_type r_type
;
3864 unsigned long r_symndx
;
3865 struct elf_link_hash_entry
*h
= NULL
;
3867 char tls_set
, tls_clear
;
3868 bfd_boolean is_local
;
3870 r_symndx
= ELF32_R_SYM (rel
->r_info
);
3871 if (r_symndx
>= symtab_hdr
->sh_info
)
3873 struct elf_link_hash_entry
**sym_hashes
;
3875 sym_hashes
= elf_sym_hashes (ibfd
);
3876 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
3877 while (h
->root
.type
== bfd_link_hash_indirect
3878 || h
->root
.type
== bfd_link_hash_warning
)
3879 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
3884 || !(h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
))
3887 r_type
= (enum elf_ppc_reloc_type
) ELF32_R_TYPE (rel
->r_info
);
3890 case R_PPC_GOT_TLSLD16
:
3891 case R_PPC_GOT_TLSLD16_LO
:
3892 case R_PPC_GOT_TLSLD16_HI
:
3893 case R_PPC_GOT_TLSLD16_HA
:
3894 /* These relocs should never be against a symbol
3895 defined in a shared lib. Leave them alone if
3896 that turns out to be the case. */
3897 expecting_tls_get_addr
= 0;
3898 htab
->tlsld_got
.refcount
-= 1;
3905 expecting_tls_get_addr
= 1;
3908 case R_PPC_GOT_TLSGD16
:
3909 case R_PPC_GOT_TLSGD16_LO
:
3910 case R_PPC_GOT_TLSGD16_HI
:
3911 case R_PPC_GOT_TLSGD16_HA
:
3917 tls_set
= TLS_TLS
| TLS_TPRELGD
;
3919 expecting_tls_get_addr
= 1;
3922 case R_PPC_GOT_TPREL16
:
3923 case R_PPC_GOT_TPREL16_LO
:
3924 case R_PPC_GOT_TPREL16_HI
:
3925 case R_PPC_GOT_TPREL16_HA
:
3926 expecting_tls_get_addr
= 0;
3931 tls_clear
= TLS_TPREL
;
3938 case R_PPC_REL14_BRTAKEN
:
3939 case R_PPC_REL14_BRNTAKEN
:
3941 if (expecting_tls_get_addr
3943 && h
== htab
->tls_get_addr
)
3945 if (h
->plt
.refcount
> 0)
3946 h
->plt
.refcount
-= 1;
3948 expecting_tls_get_addr
= 0;
3952 expecting_tls_get_addr
= 0;
3960 /* We managed to get rid of a got entry. */
3961 if (h
->got
.refcount
> 0)
3962 h
->got
.refcount
-= 1;
3964 tls_mask
= &ppc_elf_hash_entry (h
)->tls_mask
;
3968 Elf_Internal_Sym
*sym
;
3969 bfd_signed_vma
*lgot_refs
;
3972 if (locsyms
== NULL
)
3974 locsyms
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
3975 if (locsyms
== NULL
)
3976 locsyms
= bfd_elf_get_elf_syms (ibfd
, symtab_hdr
,
3977 symtab_hdr
->sh_info
,
3978 0, NULL
, NULL
, NULL
);
3979 if (locsyms
== NULL
)
3981 if (elf_section_data (sec
)->relocs
!= relstart
)
3986 sym
= locsyms
+ r_symndx
;
3987 lgot_refs
= elf_local_got_refcounts (ibfd
);
3988 if (lgot_refs
== NULL
)
3992 /* We managed to get rid of a got entry. */
3993 if (lgot_refs
[r_symndx
] > 0)
3994 lgot_refs
[r_symndx
] -= 1;
3996 lgot_masks
= (char *) (lgot_refs
+ symtab_hdr
->sh_info
);
3997 tls_mask
= &lgot_masks
[r_symndx
];
4000 *tls_mask
|= tls_set
;
4001 *tls_mask
&= ~tls_clear
;
4004 if (elf_section_data (sec
)->relocs
!= relstart
)
4009 && (symtab_hdr
->contents
!= (unsigned char *) locsyms
))
4011 if (!info
->keep_memory
)
4014 symtab_hdr
->contents
= (unsigned char *) locsyms
;
4020 /* Hook called by the linker routine which adds symbols from an object
4021 file. We use it to put .comm items in .sbss, and not .bss. */
4024 ppc_elf_add_symbol_hook (abfd
, info
, sym
, namep
, flagsp
, secp
, valp
)
4026 struct bfd_link_info
*info
;
4027 const Elf_Internal_Sym
*sym
;
4028 const char **namep ATTRIBUTE_UNUSED
;
4029 flagword
*flagsp ATTRIBUTE_UNUSED
;
4033 if (sym
->st_shndx
== SHN_COMMON
4034 && !info
->relocateable
4035 && sym
->st_size
<= elf_gp_size (abfd
)
4036 && info
->hash
->creator
->flavour
== bfd_target_elf_flavour
)
4038 /* Common symbols less than or equal to -G nn bytes are automatically
4040 elf_linker_section_t
*sdata
4041 = ppc_elf_create_linker_section (abfd
, info
, LINKER_SECTION_SDATA
);
4043 if (!sdata
->bss_section
)
4047 /* We don't go through bfd_make_section, because we don't
4048 want to attach this common section to DYNOBJ. The linker
4049 will move the symbols to the appropriate output section
4050 when it defines common symbols. */
4051 amt
= sizeof (asection
);
4052 sdata
->bss_section
= (asection
*) bfd_zalloc (abfd
, amt
);
4053 if (sdata
->bss_section
== NULL
)
4055 sdata
->bss_section
->name
= sdata
->bss_name
;
4056 sdata
->bss_section
->flags
= SEC_IS_COMMON
;
4057 sdata
->bss_section
->output_section
= sdata
->bss_section
;
4058 amt
= sizeof (asymbol
);
4059 sdata
->bss_section
->symbol
= (asymbol
*) bfd_zalloc (abfd
, amt
);
4060 amt
= sizeof (asymbol
*);
4061 sdata
->bss_section
->symbol_ptr_ptr
=
4062 (asymbol
**) bfd_zalloc (abfd
, amt
);
4063 if (sdata
->bss_section
->symbol
== NULL
4064 || sdata
->bss_section
->symbol_ptr_ptr
== NULL
)
4066 sdata
->bss_section
->symbol
->name
= sdata
->bss_name
;
4067 sdata
->bss_section
->symbol
->flags
= BSF_SECTION_SYM
;
4068 sdata
->bss_section
->symbol
->section
= sdata
->bss_section
;
4069 *sdata
->bss_section
->symbol_ptr_ptr
= sdata
->bss_section
->symbol
;
4072 *secp
= sdata
->bss_section
;
4073 *valp
= sym
->st_size
;
4079 /* Finish up dynamic symbol handling. We set the contents of various
4080 dynamic sections here. */
4083 ppc_elf_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
4085 struct bfd_link_info
*info
;
4086 struct elf_link_hash_entry
*h
;
4087 Elf_Internal_Sym
*sym
;
4089 struct ppc_elf_link_hash_table
*htab
;
4092 fprintf (stderr
, "ppc_elf_finish_dynamic_symbol called for %s",
4093 h
->root
.root
.string
);
4096 htab
= ppc_elf_hash_table (info
);
4097 BFD_ASSERT (htab
->elf
.dynobj
!= NULL
);
4099 if (h
->plt
.offset
!= (bfd_vma
) -1)
4101 Elf_Internal_Rela rela
;
4103 bfd_vma reloc_index
;
4106 fprintf (stderr
, ", plt_offset = %d", h
->plt
.offset
);
4109 /* This symbol has an entry in the procedure linkage table. Set
4112 BFD_ASSERT (h
->dynindx
!= -1);
4113 BFD_ASSERT (htab
->plt
!= NULL
&& htab
->relplt
!= NULL
);
4115 /* We don't need to fill in the .plt. The ppc dynamic linker
4118 /* Fill in the entry in the .rela.plt section. */
4119 rela
.r_offset
= (htab
->plt
->output_section
->vma
4120 + htab
->plt
->output_offset
4122 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_PPC_JMP_SLOT
);
4125 reloc_index
= (h
->plt
.offset
- PLT_INITIAL_ENTRY_SIZE
) / PLT_SLOT_SIZE
;
4126 if (reloc_index
> PLT_NUM_SINGLE_ENTRIES
)
4127 reloc_index
-= (reloc_index
- PLT_NUM_SINGLE_ENTRIES
) / 2;
4128 loc
= (htab
->relplt
->contents
4129 + reloc_index
* sizeof (Elf32_External_Rela
));
4130 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
4132 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
4134 /* Mark the symbol as undefined, rather than as defined in
4135 the .plt section. Leave the value alone. */
4136 sym
->st_shndx
= SHN_UNDEF
;
4137 /* If the symbol is weak, we do need to clear the value.
4138 Otherwise, the PLT entry would provide a definition for
4139 the symbol even if the symbol wasn't defined anywhere,
4140 and so the symbol would never be NULL. */
4141 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_REF_REGULAR_NONWEAK
)
4147 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_COPY
) != 0)
4150 Elf_Internal_Rela rela
;
4153 /* This symbols needs a copy reloc. Set it up. */
4156 fprintf (stderr
, ", copy");
4159 BFD_ASSERT (h
->dynindx
!= -1);
4161 if (h
->size
<= elf_gp_size (htab
->elf
.dynobj
))
4165 BFD_ASSERT (s
!= NULL
);
4167 rela
.r_offset
= (h
->root
.u
.def
.value
4168 + h
->root
.u
.def
.section
->output_section
->vma
4169 + h
->root
.u
.def
.section
->output_offset
);
4170 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_PPC_COPY
);
4172 loc
= s
->contents
+ s
->reloc_count
++ * sizeof (Elf32_External_Rela
);
4173 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
4177 fprintf (stderr
, "\n");
4180 /* Mark some specially defined symbols as absolute. */
4181 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
4182 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0
4183 || strcmp (h
->root
.root
.string
, "_PROCEDURE_LINKAGE_TABLE_") == 0)
4184 sym
->st_shndx
= SHN_ABS
;
4189 /* Finish up the dynamic sections. */
4192 ppc_elf_finish_dynamic_sections (output_bfd
, info
)
4194 struct bfd_link_info
*info
;
4197 struct ppc_elf_link_hash_table
*htab
;
4200 fprintf (stderr
, "ppc_elf_finish_dynamic_sections called\n");
4203 htab
= ppc_elf_hash_table (info
);
4204 sdyn
= bfd_get_section_by_name (htab
->elf
.dynobj
, ".dynamic");
4206 if (htab
->elf
.dynamic_sections_created
)
4208 Elf32_External_Dyn
*dyncon
, *dynconend
;
4210 BFD_ASSERT (htab
->plt
!= NULL
&& sdyn
!= NULL
);
4212 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
4213 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
4214 for (; dyncon
< dynconend
; dyncon
++)
4216 Elf_Internal_Dyn dyn
;
4219 bfd_elf32_swap_dyn_in (htab
->elf
.dynobj
, dyncon
, &dyn
);
4225 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
4229 dyn
.d_un
.d_val
= htab
->relplt
->_raw_size
;
4234 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
4241 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
4245 /* Add a blrl instruction at _GLOBAL_OFFSET_TABLE_-4 so that a function can
4246 easily find the address of the _GLOBAL_OFFSET_TABLE_. */
4249 unsigned char *contents
= htab
->got
->contents
;
4250 bfd_put_32 (output_bfd
, (bfd_vma
) 0x4e800021 /* blrl */, contents
);
4253 bfd_put_32 (output_bfd
, (bfd_vma
) 0, contents
+ 4);
4255 bfd_put_32 (output_bfd
,
4256 sdyn
->output_section
->vma
+ sdyn
->output_offset
,
4259 elf_section_data (htab
->got
->output_section
)->this_hdr
.sh_entsize
= 4;
4265 /* The RELOCATE_SECTION function is called by the ELF backend linker
4266 to handle the relocations for a section.
4268 The relocs are always passed as Rela structures; if the section
4269 actually uses Rel structures, the r_addend field will always be
4272 This function is responsible for adjust the section contents as
4273 necessary, and (if using Rela relocs and generating a
4274 relocateable output file) adjusting the reloc addend as
4277 This function does not have to worry about setting the reloc
4278 address or the reloc symbol index.
4280 LOCAL_SYMS is a pointer to the swapped in local symbols.
4282 LOCAL_SECTIONS is an array giving the section in the input file
4283 corresponding to the st_shndx field of each local symbol.
4285 The global hash table entry for the global symbols can be found
4286 via elf_sym_hashes (input_bfd).
4288 When generating relocateable output, this function must handle
4289 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
4290 going to be the section symbol corresponding to the output
4291 section, which means that the addend must be adjusted
4295 ppc_elf_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
4296 contents
, relocs
, local_syms
, local_sections
)
4298 struct bfd_link_info
*info
;
4300 asection
*input_section
;
4302 Elf_Internal_Rela
*relocs
;
4303 Elf_Internal_Sym
*local_syms
;
4304 asection
**local_sections
;
4306 Elf_Internal_Shdr
*symtab_hdr
;
4307 struct elf_link_hash_entry
**sym_hashes
;
4308 struct ppc_elf_link_hash_table
*htab
;
4309 Elf_Internal_Rela
*rel
;
4310 Elf_Internal_Rela
*relend
;
4311 Elf_Internal_Rela outrel
;
4313 asection
*sreloc
= NULL
;
4314 bfd_vma
*local_got_offsets
;
4315 bfd_boolean ret
= TRUE
;
4318 fprintf (stderr
, "ppc_elf_relocate_section called for %s section %s, %ld relocations%s\n",
4319 bfd_archive_filename (input_bfd
),
4320 bfd_section_name(input_bfd
, input_section
),
4321 (long) input_section
->reloc_count
,
4322 (info
->relocateable
) ? " (relocatable)" : "");
4325 if (info
->relocateable
)
4328 if (!ppc_elf_howto_table
[R_PPC_ADDR32
])
4329 /* Initialize howto table if needed. */
4330 ppc_elf_howto_init ();
4332 htab
= ppc_elf_hash_table (info
);
4333 local_got_offsets
= elf_local_got_offsets (input_bfd
);
4334 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
4335 sym_hashes
= elf_sym_hashes (input_bfd
);
4337 relend
= relocs
+ input_section
->reloc_count
;
4338 for (; rel
< relend
; rel
++)
4340 enum elf_ppc_reloc_type r_type
;
4342 bfd_reloc_status_type r
;
4343 Elf_Internal_Sym
*sym
;
4345 struct elf_link_hash_entry
*h
;
4346 const char *sym_name
;
4347 reloc_howto_type
*howto
;
4348 unsigned long r_symndx
;
4350 bfd_vma branch_bit
, insn
, from
;
4351 bfd_boolean unresolved_reloc
;
4353 unsigned int tls_type
, tls_mask
, tls_gd
;
4355 r_type
= (enum elf_ppc_reloc_type
)ELF32_R_TYPE (rel
->r_info
);
4356 sym
= (Elf_Internal_Sym
*) 0;
4357 sec
= (asection
*) 0;
4358 h
= (struct elf_link_hash_entry
*) 0;
4359 unresolved_reloc
= FALSE
;
4361 r_symndx
= ELF32_R_SYM (rel
->r_info
);
4362 if (r_symndx
< symtab_hdr
->sh_info
)
4364 sym
= local_syms
+ r_symndx
;
4365 sec
= local_sections
[r_symndx
];
4366 sym_name
= bfd_elf_local_sym_name (input_bfd
, sym
);
4368 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, sec
, rel
);
4372 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
4373 while (h
->root
.type
== bfd_link_hash_indirect
4374 || h
->root
.type
== bfd_link_hash_warning
)
4375 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
4376 sym_name
= h
->root
.root
.string
;
4379 if (h
->root
.type
== bfd_link_hash_defined
4380 || h
->root
.type
== bfd_link_hash_defweak
)
4382 sec
= h
->root
.u
.def
.section
;
4383 /* Set a flag that will be cleared later if we find a
4384 relocation value for this symbol. output_section
4385 is typically NULL for symbols satisfied by a shared
4387 if (sec
->output_section
== NULL
)
4388 unresolved_reloc
= TRUE
;
4390 relocation
= (h
->root
.u
.def
.value
4391 + sec
->output_section
->vma
4392 + sec
->output_offset
);
4394 else if (h
->root
.type
== bfd_link_hash_undefweak
)
4396 else if (info
->shared
4397 && !info
->no_undefined
4398 && ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
)
4402 if (! ((*info
->callbacks
->undefined_symbol
)
4403 (info
, h
->root
.root
.string
, input_bfd
, input_section
,
4404 rel
->r_offset
, (!info
->shared
4405 || info
->no_undefined
4406 || ELF_ST_VISIBILITY (h
->other
)))))
4412 /* TLS optimizations. Replace instruction sequences and relocs
4413 based on information we collected in tls_optimize. We edit
4414 RELOCS so that --emit-relocs will output something sensible
4415 for the final instruction stream. */
4418 if (IS_PPC_TLS_RELOC (r_type
))
4421 tls_mask
= ((struct ppc_elf_link_hash_entry
*) h
)->tls_mask
;
4422 else if (local_got_offsets
!= NULL
)
4425 lgot_masks
= (char *) (local_got_offsets
+ symtab_hdr
->sh_info
);
4426 tls_mask
= lgot_masks
[r_symndx
];
4430 /* Ensure reloc mapping code below stays sane. */
4431 if ((R_PPC_GOT_TLSLD16
& 3) != (R_PPC_GOT_TLSGD16
& 3)
4432 || (R_PPC_GOT_TLSLD16_LO
& 3) != (R_PPC_GOT_TLSGD16_LO
& 3)
4433 || (R_PPC_GOT_TLSLD16_HI
& 3) != (R_PPC_GOT_TLSGD16_HI
& 3)
4434 || (R_PPC_GOT_TLSLD16_HA
& 3) != (R_PPC_GOT_TLSGD16_HA
& 3)
4435 || (R_PPC_GOT_TLSLD16
& 3) != (R_PPC_GOT_TPREL16
& 3)
4436 || (R_PPC_GOT_TLSLD16_LO
& 3) != (R_PPC_GOT_TPREL16_LO
& 3)
4437 || (R_PPC_GOT_TLSLD16_HI
& 3) != (R_PPC_GOT_TPREL16_HI
& 3)
4438 || (R_PPC_GOT_TLSLD16_HA
& 3) != (R_PPC_GOT_TPREL16_HA
& 3))
4445 case R_PPC_GOT_TPREL16
:
4446 case R_PPC_GOT_TPREL16_LO
:
4448 && (tls_mask
& TLS_TPREL
) == 0)
4451 insn
= bfd_get_32 (output_bfd
, contents
+ rel
->r_offset
- 2);
4453 insn
|= 0x3c020000; /* addis 0,2,0 */
4454 bfd_put_32 (output_bfd
, insn
, contents
+ rel
->r_offset
- 2);
4455 r_type
= R_PPC_TPREL16_HA
;
4456 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
4462 && (tls_mask
& TLS_TPREL
) == 0)
4465 insn
= bfd_get_32 (output_bfd
, contents
+ rel
->r_offset
);
4466 if ((insn
& ((31 << 26) | (31 << 11)))
4467 == ((31 << 26) | (2 << 11)))
4468 rtra
= insn
& ((1 << 26) - (1 << 16));
4469 else if ((insn
& ((31 << 26) | (31 << 16)))
4470 == ((31 << 26) | (2 << 16)))
4471 rtra
= (insn
& (31 << 21)) | ((insn
& (31 << 11)) << 5);
4474 if ((insn
& ((1 << 11) - (1 << 1))) == 266 << 1)
4477 else if ((insn
& (31 << 1)) == 23 << 1
4478 && ((insn
& (31 << 6)) < 14 << 6
4479 || ((insn
& (31 << 6)) >= 16 << 6
4480 && (insn
& (31 << 6)) < 24 << 6)))
4481 /* load and store indexed -> dform. */
4482 insn
= (32 | ((insn
>> 6) & 31)) << 26;
4483 else if ((insn
& (31 << 1)) == 21 << 1
4484 && (insn
& (0x1a << 6)) == 0)
4485 /* ldx, ldux, stdx, stdux -> ld, ldu, std, stdu. */
4486 insn
= (((58 | ((insn
>> 6) & 4)) << 26)
4487 | ((insn
>> 6) & 1));
4488 else if ((insn
& (31 << 1)) == 21 << 1
4489 && (insn
& ((1 << 11) - (1 << 1))) == 341 << 1)
4491 insn
= (58 << 26) | 2;
4495 bfd_put_32 (output_bfd
, insn
, contents
+ rel
->r_offset
);
4496 r_type
= R_PPC_TPREL16_LO
;
4497 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
4498 /* Was PPC_TLS which sits on insn boundary, now
4499 PPC_TPREL16_LO which is at insn+2. */
4504 case R_PPC_GOT_TLSGD16_HI
:
4505 case R_PPC_GOT_TLSGD16_HA
:
4506 tls_gd
= TLS_TPRELGD
;
4507 if (tls_mask
!= 0 && (tls_mask
& TLS_GD
) == 0)
4511 case R_PPC_GOT_TLSLD16_HI
:
4512 case R_PPC_GOT_TLSLD16_HA
:
4513 if (tls_mask
!= 0 && (tls_mask
& TLS_LD
) == 0)
4516 if ((tls_mask
& tls_gd
) != 0)
4517 r_type
= (((r_type
- (R_PPC_GOT_TLSGD16
& 3)) & 3)
4518 + R_PPC_GOT_TPREL16
);
4521 bfd_put_32 (output_bfd
, NOP
, contents
+ rel
->r_offset
);
4523 r_type
= R_PPC_NONE
;
4525 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
4529 case R_PPC_GOT_TLSGD16
:
4530 case R_PPC_GOT_TLSGD16_LO
:
4531 tls_gd
= TLS_TPRELGD
;
4532 if (tls_mask
!= 0 && (tls_mask
& TLS_GD
) == 0)
4533 goto tls_get_addr_check
;
4536 case R_PPC_GOT_TLSLD16
:
4537 case R_PPC_GOT_TLSLD16_LO
:
4538 if (tls_mask
!= 0 && (tls_mask
& TLS_LD
) == 0)
4541 if (rel
+ 1 < relend
)
4543 enum elf_ppc_reloc_type r_type2
;
4544 unsigned long r_symndx2
;
4545 struct elf_link_hash_entry
*h2
;
4546 bfd_vma insn1
, insn2
;
4549 /* The next instruction should be a call to
4550 __tls_get_addr. Peek at the reloc to be sure. */
4552 = (enum elf_ppc_reloc_type
) ELF32_R_TYPE (rel
[1].r_info
);
4553 r_symndx2
= ELF32_R_SYM (rel
[1].r_info
);
4554 if (r_symndx2
< symtab_hdr
->sh_info
4555 || (r_type2
!= R_PPC_REL14
4556 && r_type2
!= R_PPC_REL14_BRTAKEN
4557 && r_type2
!= R_PPC_REL14_BRNTAKEN
4558 && r_type2
!= R_PPC_REL24
4559 && r_type2
!= R_PPC_PLTREL24
))
4562 h2
= sym_hashes
[r_symndx2
- symtab_hdr
->sh_info
];
4563 while (h2
->root
.type
== bfd_link_hash_indirect
4564 || h2
->root
.type
== bfd_link_hash_warning
)
4565 h2
= (struct elf_link_hash_entry
*) h2
->root
.u
.i
.link
;
4566 if (h2
== NULL
|| h2
!= htab
->tls_get_addr
)
4569 /* OK, it checks out. Replace the call. */
4570 offset
= rel
[1].r_offset
;
4571 insn1
= bfd_get_32 (output_bfd
,
4572 contents
+ rel
->r_offset
- 2);
4573 if ((tls_mask
& tls_gd
) != 0)
4576 insn1
&= (1 << 26) - 1;
4577 insn1
|= 32 << 26; /* lwz */
4578 insn2
= 0x7c631214; /* add 3,3,2 */
4579 rel
[1].r_info
= ELF32_R_INFO (r_symndx2
, R_PPC_NONE
);
4580 r_type
= (((r_type
- (R_PPC_GOT_TLSGD16
& 3)) & 3)
4581 + R_PPC_GOT_TPREL16
);
4582 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
4587 insn1
= 0x3c620000; /* addis 3,2,0 */
4588 insn2
= 0x38630000; /* addi 3,3,0 */
4591 /* Was an LD reloc. */
4593 rel
->r_addend
= htab
->tls_sec
->vma
+ DTP_OFFSET
;
4594 rel
[1].r_addend
= htab
->tls_sec
->vma
+ DTP_OFFSET
;
4596 r_type
= R_PPC_TPREL16_HA
;
4597 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
4598 rel
[1].r_info
= ELF32_R_INFO (r_symndx
,
4600 rel
[1].r_offset
+= 2;
4602 bfd_put_32 (output_bfd
, insn1
, contents
+ rel
->r_offset
- 2);
4603 bfd_put_32 (output_bfd
, insn2
, contents
+ offset
);
4606 /* We changed the symbol on an LD reloc. Start over
4607 in order to get h, sym, sec etc. right. */
4616 /* Handle other relocations that tweak non-addend part of insn. */
4623 /* Branch taken prediction relocations. */
4624 case R_PPC_ADDR14_BRTAKEN
:
4625 case R_PPC_REL14_BRTAKEN
:
4626 branch_bit
= BRANCH_PREDICT_BIT
;
4629 /* Branch not taken predicition relocations. */
4630 case R_PPC_ADDR14_BRNTAKEN
:
4631 case R_PPC_REL14_BRNTAKEN
:
4632 insn
= bfd_get_32 (output_bfd
, contents
+ rel
->r_offset
);
4633 insn
&= ~BRANCH_PREDICT_BIT
;
4636 from
= (rel
->r_offset
4637 + input_section
->output_offset
4638 + input_section
->output_section
->vma
);
4640 /* Invert 'y' bit if not the default. */
4641 if ((bfd_signed_vma
) (relocation
+ rel
->r_addend
- from
) < 0)
4642 insn
^= BRANCH_PREDICT_BIT
;
4644 bfd_put_32 (output_bfd
, insn
, contents
+ rel
->r_offset
);
4648 addend
= rel
->r_addend
;
4651 if ((unsigned) r_type
< (unsigned) R_PPC_max
)
4652 howto
= ppc_elf_howto_table
[(int) r_type
];
4656 (*_bfd_error_handler
)
4657 (_("%s: unknown relocation type %d for symbol %s"),
4658 bfd_archive_filename (input_bfd
), (int) r_type
, sym_name
);
4660 bfd_set_error (bfd_error_bad_value
);
4666 case R_PPC_EMB_MRKREF
:
4667 case R_PPC_GNU_VTINHERIT
:
4668 case R_PPC_GNU_VTENTRY
:
4671 /* GOT16 relocations. Like an ADDR16 using the symbol's
4672 address in the GOT as relocation value instead of the
4673 symbol's value itself. Also, create a GOT entry for the
4674 symbol and put the symbol value there. */
4675 case R_PPC_GOT_TLSGD16
:
4676 case R_PPC_GOT_TLSGD16_LO
:
4677 case R_PPC_GOT_TLSGD16_HI
:
4678 case R_PPC_GOT_TLSGD16_HA
:
4679 tls_type
= TLS_TLS
| TLS_GD
;
4682 case R_PPC_GOT_TLSLD16
:
4683 case R_PPC_GOT_TLSLD16_LO
:
4684 case R_PPC_GOT_TLSLD16_HI
:
4685 case R_PPC_GOT_TLSLD16_HA
:
4686 tls_type
= TLS_TLS
| TLS_LD
;
4689 case R_PPC_GOT_TPREL16
:
4690 case R_PPC_GOT_TPREL16_LO
:
4691 case R_PPC_GOT_TPREL16_HI
:
4692 case R_PPC_GOT_TPREL16_HA
:
4693 tls_type
= TLS_TLS
| TLS_TPREL
;
4696 case R_PPC_GOT_DTPREL16
:
4697 case R_PPC_GOT_DTPREL16_LO
:
4698 case R_PPC_GOT_DTPREL16_HI
:
4699 case R_PPC_GOT_DTPREL16_HA
:
4700 tls_type
= TLS_TLS
| TLS_DTPREL
;
4704 case R_PPC_GOT16_LO
:
4705 case R_PPC_GOT16_HI
:
4706 case R_PPC_GOT16_HA
:
4709 /* Relocation is to the entry for this symbol in the global
4715 if (htab
->got
== NULL
)
4719 if (tls_type
== (TLS_TLS
| TLS_LD
)
4721 || !(h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
)))
4722 offp
= &htab
->tlsld_got
.offset
;
4726 dyn
= htab
->elf
.dynamic_sections_created
;
4727 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
4729 && SYMBOL_REFERENCES_LOCAL (info
, h
)))
4730 /* This is actually a static link, or it is a
4731 -Bsymbolic link and the symbol is defined
4732 locally, or the symbol was forced to be local
4733 because of a version file. */
4738 unresolved_reloc
= FALSE
;
4740 offp
= &h
->got
.offset
;
4744 if (local_got_offsets
== NULL
)
4746 offp
= &local_got_offsets
[r_symndx
];
4749 /* The offset must always be a multiple of 4. We use the
4750 least significant bit to record whether we have already
4751 processed this entry. */
4757 unsigned int tls_m
= (tls_mask
4758 & (TLS_LD
| TLS_GD
| TLS_DTPREL
4759 | TLS_TPREL
| TLS_TPRELGD
));
4761 if (offp
== &htab
->tlsld_got
.offset
)
4764 || !(h
->elf_link_hash_flags
4765 & ELF_LINK_HASH_DEF_DYNAMIC
))
4768 /* We might have multiple got entries for this sym.
4769 Initialize them all. */
4774 if ((tls_m
& TLS_LD
) != 0)
4776 tls_ty
= TLS_TLS
| TLS_LD
;
4779 else if ((tls_m
& TLS_GD
) != 0)
4781 tls_ty
= TLS_TLS
| TLS_GD
;
4784 else if ((tls_m
& TLS_DTPREL
) != 0)
4786 tls_ty
= TLS_TLS
| TLS_DTPREL
;
4787 tls_m
&= ~TLS_DTPREL
;
4789 else if ((tls_m
& (TLS_TPREL
| TLS_TPRELGD
)) != 0)
4791 tls_ty
= TLS_TLS
| TLS_TPREL
;
4795 /* Generate relocs for the dynamic linker. */
4796 if (info
->shared
|| indx
!= 0)
4798 outrel
.r_offset
= (htab
->got
->output_section
->vma
4799 + htab
->got
->output_offset
4801 outrel
.r_addend
= 0;
4802 if (tls_ty
& (TLS_LD
| TLS_GD
))
4804 outrel
.r_info
= ELF32_R_INFO (indx
, R_PPC_DTPMOD32
);
4805 if (tls_ty
== (TLS_TLS
| TLS_GD
))
4807 loc
= htab
->relgot
->contents
;
4808 loc
+= (htab
->relgot
->reloc_count
++
4809 * sizeof (Elf32_External_Rela
));
4810 bfd_elf32_swap_reloca_out (output_bfd
,
4812 outrel
.r_offset
+= 4;
4814 = ELF32_R_INFO (indx
, R_PPC_DTPREL32
);
4817 else if (tls_ty
== (TLS_TLS
| TLS_DTPREL
))
4818 outrel
.r_info
= ELF32_R_INFO (indx
, R_PPC_DTPREL32
);
4819 else if (tls_ty
== (TLS_TLS
| TLS_TPREL
))
4820 outrel
.r_info
= ELF32_R_INFO (indx
, R_PPC_TPREL32
);
4822 outrel
.r_info
= ELF32_R_INFO (indx
, R_PPC_RELATIVE
);
4824 outrel
.r_info
= ELF32_R_INFO (indx
, R_PPC_GLOB_DAT
);
4827 outrel
.r_addend
+= relocation
;
4828 if (tls_ty
& (TLS_GD
| TLS_DTPREL
| TLS_TPREL
))
4829 outrel
.r_addend
-= htab
->tls_sec
->vma
;
4831 loc
= htab
->relgot
->contents
;
4832 loc
+= (htab
->relgot
->reloc_count
++
4833 * sizeof (Elf32_External_Rela
));
4834 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
4837 /* Init the .got section contents if we're not
4838 emitting a reloc. */
4841 bfd_vma value
= relocation
;
4843 if (tls_ty
== (TLS_TLS
| TLS_LD
))
4845 else if (tls_ty
!= 0)
4847 value
-= htab
->tls_sec
->vma
+ DTP_OFFSET
;
4848 if (tls_ty
== (TLS_TLS
| TLS_TPREL
))
4849 value
+= DTP_OFFSET
- TP_OFFSET
;
4851 if (tls_ty
== (TLS_TLS
| TLS_GD
))
4853 bfd_put_32 (output_bfd
, value
,
4854 htab
->got
->contents
+ off
+ 4);
4858 bfd_put_32 (output_bfd
, value
,
4859 htab
->got
->contents
+ off
);
4863 if (tls_ty
& (TLS_LD
| TLS_GD
))
4872 if (off
>= (bfd_vma
) -2)
4875 if ((tls_type
& TLS_TLS
) != 0)
4877 if (tls_type
!= (TLS_TLS
| TLS_LD
))
4879 if ((tls_mask
& TLS_LD
) != 0
4881 || !(h
->elf_link_hash_flags
4882 & ELF_LINK_HASH_DEF_DYNAMIC
)))
4884 if (tls_type
!= (TLS_TLS
| TLS_GD
))
4886 if ((tls_mask
& TLS_GD
) != 0)
4888 if (tls_type
!= (TLS_TLS
| TLS_DTPREL
))
4890 if ((tls_mask
& TLS_DTPREL
) != 0)
4897 relocation
= htab
->got
->output_offset
+ off
- 4;
4899 /* Addends on got relocations don't make much sense.
4900 x+off@got is actually x@got+off, and since the got is
4901 generated by a hash table traversal, the value in the
4902 got at entry m+n bears little relation to the entry m. */
4904 (*_bfd_error_handler
)
4905 (_("%s(%s+0x%lx): non-zero addend on %s reloc against `%s'"),
4906 bfd_archive_filename (input_bfd
),
4907 bfd_get_section_name (input_bfd
, input_section
),
4908 (long) rel
->r_offset
,
4914 /* Relocations that need no special processing. */
4915 case R_PPC_LOCAL24PC
:
4916 /* It makes no sense to point a local relocation
4917 at a symbol not in this object. */
4918 if (unresolved_reloc
)
4920 if (! (*info
->callbacks
->undefined_symbol
) (info
,
4921 h
->root
.root
.string
,
4931 case R_PPC_DTPREL16
:
4932 case R_PPC_DTPREL16_LO
:
4933 case R_PPC_DTPREL16_HI
:
4934 case R_PPC_DTPREL16_HA
:
4935 addend
-= htab
->tls_sec
->vma
+ DTP_OFFSET
;
4938 /* Relocations that may need to be propagated if this is a shared
4941 case R_PPC_TPREL16_LO
:
4942 case R_PPC_TPREL16_HI
:
4943 case R_PPC_TPREL16_HA
:
4944 addend
-= htab
->tls_sec
->vma
+ TP_OFFSET
;
4945 /* The TPREL16 relocs shouldn't really be used in shared
4946 libs as they will result in DT_TEXTREL being set, but
4947 support them anyway. */
4951 addend
-= htab
->tls_sec
->vma
+ TP_OFFSET
;
4954 case R_PPC_DTPREL32
:
4955 addend
-= htab
->tls_sec
->vma
+ DTP_OFFSET
;
4958 case R_PPC_DTPMOD32
:
4966 case R_PPC_REL14_BRTAKEN
:
4967 case R_PPC_REL14_BRNTAKEN
:
4968 /* If these relocations are not to a named symbol, they can be
4969 handled right here, no need to bother the dynamic linker. */
4971 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0
4972 || SYMBOL_REFERENCES_LOCAL (info
, h
))
4976 /* Relocations that always need to be propagated if this is a shared
4981 case R_PPC_ADDR16_LO
:
4982 case R_PPC_ADDR16_HI
:
4983 case R_PPC_ADDR16_HA
:
4985 case R_PPC_ADDR14_BRTAKEN
:
4986 case R_PPC_ADDR14_BRNTAKEN
:
4989 /* r_symndx will be zero only for relocs against symbols
4990 from removed linkonce sections, or sections discarded by
4998 && (MUST_BE_DYN_RELOC (r_type
)
5002 || (h
->elf_link_hash_flags
5003 & ELF_LINK_HASH_DEF_REGULAR
) == 0))))
5004 || (ELIMINATE_COPY_RELOCS
5006 && (input_section
->flags
& SEC_ALLOC
) != 0
5009 && (h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0
5010 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
5011 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0))
5016 fprintf (stderr
, "ppc_elf_relocate_section need to create relocation for %s\n",
5017 (h
&& h
->root
.root
.string
5018 ? h
->root
.root
.string
: "<unknown>"));
5021 /* When generating a shared object, these relocations
5022 are copied into the output file to be resolved at run
5028 name
= (bfd_elf_string_from_elf_section
5030 elf_elfheader (input_bfd
)->e_shstrndx
,
5031 elf_section_data (input_section
)->rel_hdr
.sh_name
));
5035 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
5036 && strcmp (bfd_get_section_name (input_bfd
,
5040 sreloc
= bfd_get_section_by_name (htab
->elf
.dynobj
, name
);
5041 BFD_ASSERT (sreloc
!= NULL
);
5047 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
5049 if (outrel
.r_offset
== (bfd_vma
) -1
5050 || outrel
.r_offset
== (bfd_vma
) -2)
5051 skip
= (int) outrel
.r_offset
;
5052 outrel
.r_offset
+= (input_section
->output_section
->vma
5053 + input_section
->output_offset
);
5056 memset (&outrel
, 0, sizeof outrel
);
5058 && !SYMBOL_REFERENCES_LOCAL (info
, h
))
5060 unresolved_reloc
= FALSE
;
5061 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
5062 outrel
.r_addend
= rel
->r_addend
;
5066 outrel
.r_addend
= relocation
+ rel
->r_addend
;
5068 if (r_type
== R_PPC_ADDR32
)
5069 outrel
.r_info
= ELF32_R_INFO (0, R_PPC_RELATIVE
);
5074 if (bfd_is_abs_section (sec
))
5076 else if (sec
== NULL
|| sec
->owner
== NULL
)
5078 bfd_set_error (bfd_error_bad_value
);
5085 /* We are turning this relocation into one
5086 against a section symbol. It would be
5087 proper to subtract the symbol's value,
5088 osec->vma, from the emitted reloc addend,
5089 but ld.so expects buggy relocs. */
5090 osec
= sec
->output_section
;
5091 indx
= elf_section_data (osec
)->dynindx
;
5092 BFD_ASSERT (indx
> 0);
5096 printf ("indx=%d section=%s flags=%08x name=%s\n",
5097 indx
, osec
->name
, osec
->flags
,
5098 h
->root
.root
.string
);
5103 outrel
.r_info
= ELF32_R_INFO (indx
, r_type
);
5107 loc
= sreloc
->contents
;
5108 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rela
);
5109 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
5114 /* This reloc will be computed at runtime. We clear the memory
5115 so that it contains predictable value. */
5117 && ((input_section
->flags
& SEC_ALLOC
) != 0
5118 || ELF32_R_TYPE (outrel
.r_info
) != R_PPC_RELATIVE
))
5120 relocation
= howto
->pc_relative
? outrel
.r_offset
: 0;
5127 /* Indirect .sdata relocation. */
5128 case R_PPC_EMB_SDAI16
:
5129 BFD_ASSERT (htab
->sdata
!= NULL
);
5131 = bfd_elf32_finish_pointer_linker_section (output_bfd
, input_bfd
,
5132 info
, htab
->sdata
, h
,
5137 /* Indirect .sdata2 relocation. */
5138 case R_PPC_EMB_SDA2I16
:
5139 BFD_ASSERT (htab
->sdata2
!= NULL
);
5141 = bfd_elf32_finish_pointer_linker_section (output_bfd
, input_bfd
,
5142 info
, htab
->sdata2
, h
,
5147 /* Handle the TOC16 reloc. We want to use the offset within the .got
5148 section, not the actual VMA. This is appropriate when generating
5149 an embedded ELF object, for which the .got section acts like the
5150 AIX .toc section. */
5151 case R_PPC_TOC16
: /* phony GOT16 relocations */
5152 BFD_ASSERT (sec
!= (asection
*) 0);
5153 BFD_ASSERT (bfd_is_und_section (sec
)
5154 || strcmp (bfd_get_section_name (abfd
, sec
), ".got") == 0
5155 || strcmp (bfd_get_section_name (abfd
, sec
), ".cgot") == 0)
5157 addend
-= sec
->output_section
->vma
+ sec
->output_offset
+ 0x8000;
5160 case R_PPC_PLTREL24
:
5161 /* Relocation is to the entry for this symbol in the
5162 procedure linkage table. */
5163 BFD_ASSERT (h
!= NULL
);
5165 if (h
->plt
.offset
== (bfd_vma
) -1
5166 || htab
->plt
== NULL
)
5168 /* We didn't make a PLT entry for this symbol. This
5169 happens when statically linking PIC code, or when
5170 using -Bsymbolic. */
5174 unresolved_reloc
= FALSE
;
5175 relocation
= (htab
->plt
->output_section
->vma
5176 + htab
->plt
->output_offset
5180 /* Relocate against _SDA_BASE_. */
5181 case R_PPC_SDAREL16
:
5184 const struct elf_link_hash_entry
*sh
;
5186 BFD_ASSERT (sec
!= (asection
*) 0);
5187 name
= bfd_get_section_name (abfd
, sec
->output_section
);
5188 if (! ((strncmp (name
, ".sdata", 6) == 0
5189 && (name
[6] == 0 || name
[6] == '.'))
5190 || (strncmp (name
, ".sbss", 5) == 0
5191 && (name
[5] == 0 || name
[5] == '.'))))
5193 (*_bfd_error_handler
) (_("%s: the target (%s) of a %s relocation is in the wrong output section (%s)"),
5194 bfd_archive_filename (input_bfd
),
5199 sh
= htab
->sdata
->sym_hash
;
5200 addend
-= (sh
->root
.u
.def
.value
5201 + sh
->root
.u
.def
.section
->output_section
->vma
5202 + sh
->root
.u
.def
.section
->output_offset
);
5206 /* Relocate against _SDA2_BASE_. */
5207 case R_PPC_EMB_SDA2REL
:
5210 const struct elf_link_hash_entry
*sh
;
5212 BFD_ASSERT (sec
!= (asection
*) 0);
5213 name
= bfd_get_section_name (abfd
, sec
->output_section
);
5214 if (! (strncmp (name
, ".sdata2", 7) == 0
5215 || strncmp (name
, ".sbss2", 6) == 0))
5217 (*_bfd_error_handler
) (_("%s: the target (%s) of a %s relocation is in the wrong output section (%s)"),
5218 bfd_archive_filename (input_bfd
),
5223 bfd_set_error (bfd_error_bad_value
);
5227 sh
= htab
->sdata2
->sym_hash
;
5228 addend
-= (sh
->root
.u
.def
.value
5229 + sh
->root
.u
.def
.section
->output_section
->vma
5230 + sh
->root
.u
.def
.section
->output_offset
);
5234 /* Relocate against either _SDA_BASE_, _SDA2_BASE_, or 0. */
5235 case R_PPC_EMB_SDA21
:
5236 case R_PPC_EMB_RELSDA
:
5239 const struct elf_link_hash_entry
*sh
;
5242 BFD_ASSERT (sec
!= (asection
*) 0);
5243 name
= bfd_get_section_name (abfd
, sec
->output_section
);
5244 if (((strncmp (name
, ".sdata", 6) == 0
5245 && (name
[6] == 0 || name
[6] == '.'))
5246 || (strncmp (name
, ".sbss", 5) == 0
5247 && (name
[5] == 0 || name
[5] == '.'))))
5250 sh
= htab
->sdata
->sym_hash
;
5251 addend
-= (sh
->root
.u
.def
.value
5252 + sh
->root
.u
.def
.section
->output_section
->vma
5253 + sh
->root
.u
.def
.section
->output_offset
);
5256 else if (strncmp (name
, ".sdata2", 7) == 0
5257 || strncmp (name
, ".sbss2", 6) == 0)
5260 sh
= htab
->sdata2
->sym_hash
;
5261 addend
-= (sh
->root
.u
.def
.value
5262 + sh
->root
.u
.def
.section
->output_section
->vma
5263 + sh
->root
.u
.def
.section
->output_offset
);
5266 else if (strcmp (name
, ".PPC.EMB.sdata0") == 0
5267 || strcmp (name
, ".PPC.EMB.sbss0") == 0)
5274 (*_bfd_error_handler
) (_("%s: the target (%s) of a %s relocation is in the wrong output section (%s)"),
5275 bfd_archive_filename (input_bfd
),
5280 bfd_set_error (bfd_error_bad_value
);
5285 if (r_type
== R_PPC_EMB_SDA21
)
5286 { /* fill in register field */
5287 insn
= bfd_get_32 (output_bfd
, contents
+ rel
->r_offset
);
5288 insn
= (insn
& ~RA_REGISTER_MASK
) | (reg
<< RA_REGISTER_SHIFT
);
5289 bfd_put_32 (output_bfd
, insn
, contents
+ rel
->r_offset
);
5294 /* Relocate against the beginning of the section. */
5296 case R_PPC_SECTOFF_LO
:
5297 case R_PPC_SECTOFF_HI
:
5298 case R_PPC_SECTOFF_HA
:
5299 BFD_ASSERT (sec
!= (asection
*) 0);
5300 addend
-= sec
->output_section
->vma
;
5303 /* Negative relocations. */
5304 case R_PPC_EMB_NADDR32
:
5305 case R_PPC_EMB_NADDR16
:
5306 case R_PPC_EMB_NADDR16_LO
:
5307 case R_PPC_EMB_NADDR16_HI
:
5308 case R_PPC_EMB_NADDR16_HA
:
5309 addend
-= 2 * relocation
;
5313 case R_PPC_GLOB_DAT
:
5314 case R_PPC_JMP_SLOT
:
5315 case R_PPC_RELATIVE
:
5317 case R_PPC_PLTREL32
:
5318 case R_PPC_PLT16_LO
:
5319 case R_PPC_PLT16_HI
:
5320 case R_PPC_PLT16_HA
:
5322 case R_PPC_EMB_RELSEC16
:
5323 case R_PPC_EMB_RELST_LO
:
5324 case R_PPC_EMB_RELST_HI
:
5325 case R_PPC_EMB_RELST_HA
:
5326 case R_PPC_EMB_BIT_FLD
:
5327 (*_bfd_error_handler
)
5328 (_("%s: relocation %s is not yet supported for symbol %s."),
5329 bfd_archive_filename (input_bfd
),
5333 bfd_set_error (bfd_error_invalid_operation
);
5338 /* Do any further special processing. */
5344 case R_PPC_ADDR16_HA
:
5345 case R_PPC_GOT16_HA
:
5346 case R_PPC_PLT16_HA
:
5347 case R_PPC_SECTOFF_HA
:
5348 case R_PPC_TPREL16_HA
:
5349 case R_PPC_DTPREL16_HA
:
5350 case R_PPC_GOT_TLSGD16_HA
:
5351 case R_PPC_GOT_TLSLD16_HA
:
5352 case R_PPC_GOT_TPREL16_HA
:
5353 case R_PPC_GOT_DTPREL16_HA
:
5354 case R_PPC_EMB_NADDR16_HA
:
5355 case R_PPC_EMB_RELST_HA
:
5356 /* It's just possible that this symbol is a weak symbol
5357 that's not actually defined anywhere. In that case,
5358 'sec' would be NULL, and we should leave the symbol
5359 alone (it will be set to zero elsewhere in the link). */
5361 /* Add 0x10000 if sign bit in 0:15 is set.
5362 Bits 0:15 are not used. */
5368 fprintf (stderr
, "\ttype = %s (%d), name = %s, symbol index = %ld, offset = %ld, addend = %ld\n",
5373 (long) rel
->r_offset
,
5377 if (unresolved_reloc
5378 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
5379 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0))
5381 (*_bfd_error_handler
)
5382 (_("%s(%s+0x%lx): unresolvable %s relocation against symbol `%s'"),
5383 bfd_archive_filename (input_bfd
),
5384 bfd_get_section_name (input_bfd
, input_section
),
5385 (long) rel
->r_offset
,
5391 r
= _bfd_final_link_relocate (howto
,
5399 if (r
!= bfd_reloc_ok
)
5401 if (sym_name
== NULL
)
5402 sym_name
= "(null)";
5403 if (r
== bfd_reloc_overflow
)
5408 && h
->root
.type
== bfd_link_hash_undefweak
5409 && howto
->pc_relative
)
5411 /* Assume this is a call protected by other code that
5412 detect the symbol is undefined. If this is the case,
5413 we can safely ignore the overflow. If not, the
5414 program is hosed anyway, and a little warning isn't
5420 if (! (*info
->callbacks
->reloc_overflow
) (info
,
5431 (*_bfd_error_handler
)
5432 (_("%s(%s+0x%lx): %s reloc against `%s': error %d"),
5433 bfd_archive_filename (input_bfd
),
5434 bfd_get_section_name (input_bfd
, input_section
),
5435 (long) rel
->r_offset
, howto
->name
, sym_name
, (int) r
);
5442 fprintf (stderr
, "\n");
5448 static enum elf_reloc_type_class
5449 ppc_elf_reloc_type_class (rela
)
5450 const Elf_Internal_Rela
*rela
;
5452 switch ((int) ELF32_R_TYPE (rela
->r_info
))
5454 case R_PPC_RELATIVE
:
5455 return reloc_class_relative
;
5458 case R_PPC_JMP_SLOT
:
5459 return reloc_class_plt
;
5461 return reloc_class_copy
;
5463 return reloc_class_normal
;
5467 /* Support for core dump NOTE sections. */
5470 ppc_elf_grok_prstatus (abfd
, note
)
5472 Elf_Internal_Note
*note
;
5475 unsigned int raw_size
;
5477 switch (note
->descsz
)
5482 case 268: /* Linux/PPC. */
5484 elf_tdata (abfd
)->core_signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
5487 elf_tdata (abfd
)->core_pid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
5496 /* Make a ".reg/999" section. */
5497 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
5498 raw_size
, note
->descpos
+ offset
);
5502 ppc_elf_grok_psinfo (abfd
, note
)
5504 Elf_Internal_Note
*note
;
5506 switch (note
->descsz
)
5511 case 128: /* Linux/PPC elf_prpsinfo. */
5512 elf_tdata (abfd
)->core_program
5513 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 32, 16);
5514 elf_tdata (abfd
)->core_command
5515 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 48, 80);
5518 /* Note that for some reason, a spurious space is tacked
5519 onto the end of the args in some (at least one anyway)
5520 implementations, so strip it off if it exists. */
5523 char *command
= elf_tdata (abfd
)->core_command
;
5524 int n
= strlen (command
);
5526 if (0 < n
&& command
[n
- 1] == ' ')
5527 command
[n
- 1] = '\0';
5533 /* Very simple linked list structure for recording apuinfo values. */
5534 typedef struct apuinfo_list
5536 struct apuinfo_list
*next
;
5537 unsigned long value
;
5541 static apuinfo_list
* head
;
5543 static void apuinfo_list_init
PARAMS ((void));
5544 static void apuinfo_list_add
PARAMS ((unsigned long));
5545 static unsigned apuinfo_list_length
PARAMS ((void));
5546 static unsigned long apuinfo_list_element
PARAMS ((unsigned long));
5547 static void apuinfo_list_finish
PARAMS ((void));
5549 extern void ppc_elf_begin_write_processing
5550 PARAMS ((bfd
*, struct bfd_link_info
*));
5551 extern void ppc_elf_final_write_processing
5552 PARAMS ((bfd
*, bfd_boolean
));
5553 extern bfd_boolean ppc_elf_write_section
5554 PARAMS ((bfd
*, asection
*, bfd_byte
*));
5558 apuinfo_list_init
PARAMS ((void))
5564 apuinfo_list_add (value
)
5565 unsigned long value
;
5567 apuinfo_list
*entry
= head
;
5569 while (entry
!= NULL
)
5571 if (entry
->value
== value
)
5573 entry
= entry
->next
;
5576 entry
= bfd_malloc (sizeof (* entry
));
5580 entry
->value
= value
;
5586 apuinfo_list_length
PARAMS ((void))
5588 apuinfo_list
*entry
;
5589 unsigned long count
;
5591 for (entry
= head
, count
= 0;
5593 entry
= entry
->next
)
5599 static inline unsigned long
5600 apuinfo_list_element (number
)
5601 unsigned long number
;
5603 apuinfo_list
* entry
;
5607 entry
= entry
->next
)
5610 return entry
? entry
->value
: 0;
5614 apuinfo_list_finish
PARAMS ((void))
5616 apuinfo_list
*entry
;
5618 for (entry
= head
; entry
;)
5620 apuinfo_list
*next
= entry
->next
;
5628 #define APUINFO_SECTION_NAME ".PPC.EMB.apuinfo"
5629 #define APUINFO_LABEL "APUinfo"
5631 /* Scan the input BFDs and create a linked list of
5632 the APUinfo values that will need to be emitted. */
5635 ppc_elf_begin_write_processing (abfd
, link_info
)
5637 struct bfd_link_info
*link_info
;
5642 unsigned num_input_sections
;
5643 bfd_size_type output_section_size
;
5645 unsigned num_entries
;
5646 unsigned long offset
;
5647 unsigned long length
;
5648 const char *error_message
= NULL
;
5650 if (link_info
== NULL
)
5653 /* Scan the input bfds, looking for apuinfo sections. */
5654 num_input_sections
= 0;
5655 output_section_size
= 0;
5657 for (ibfd
= link_info
->input_bfds
; ibfd
; ibfd
= ibfd
->link_next
)
5659 asec
= bfd_get_section_by_name (ibfd
, APUINFO_SECTION_NAME
);
5662 ++ num_input_sections
;
5663 output_section_size
+= asec
->_raw_size
;
5667 /* We need at least one input sections
5668 in order to make merging worthwhile. */
5669 if (num_input_sections
< 1)
5672 /* Just make sure that the output section exists as well. */
5673 asec
= bfd_get_section_by_name (abfd
, APUINFO_SECTION_NAME
);
5677 /* Allocate a buffer for the contents of the input sections. */
5678 buffer
= bfd_malloc (output_section_size
);
5683 apuinfo_list_init ();
5685 /* Read in the input sections contents. */
5686 for (ibfd
= link_info
->input_bfds
; ibfd
; ibfd
= ibfd
->link_next
)
5688 unsigned long datum
;
5691 asec
= bfd_get_section_by_name (ibfd
, APUINFO_SECTION_NAME
);
5695 length
= asec
->_raw_size
;
5698 error_message
= _("corrupt or empty %s section in %s");
5702 if (bfd_seek (ibfd
, asec
->filepos
, SEEK_SET
) != 0
5703 || (bfd_bread (buffer
+ offset
, length
, ibfd
) != length
))
5705 error_message
= _("unable to read in %s section from %s");
5709 /* Process the contents of the section. */
5710 ptr
= buffer
+ offset
;
5711 error_message
= _("corrupt %s section in %s");
5713 /* Verify the contents of the header. Note - we have to
5714 extract the values this way in order to allow for a
5715 host whose endian-ness is different from the target. */
5716 datum
= bfd_get_32 (ibfd
, ptr
);
5717 if (datum
!= sizeof APUINFO_LABEL
)
5720 datum
= bfd_get_32 (ibfd
, ptr
+ 8);
5724 if (strcmp (ptr
+ 12, APUINFO_LABEL
) != 0)
5727 /* Get the number of apuinfo entries. */
5728 datum
= bfd_get_32 (ibfd
, ptr
+ 4);
5729 if ((datum
* 4 + 20) != length
)
5732 /* Make sure that we do not run off the end of the section. */
5733 if (offset
+ length
> output_section_size
)
5736 /* Scan the apuinfo section, building a list of apuinfo numbers. */
5737 for (i
= 0; i
< datum
; i
++)
5738 apuinfo_list_add (bfd_get_32 (ibfd
, ptr
+ 20 + (i
* 4)));
5740 /* Update the offset. */
5744 error_message
= NULL
;
5746 /* Compute the size of the output section. */
5747 num_entries
= apuinfo_list_length ();
5748 output_section_size
= 20 + num_entries
* 4;
5750 asec
= bfd_get_section_by_name (abfd
, APUINFO_SECTION_NAME
);
5752 if (! bfd_set_section_size (abfd
, asec
, output_section_size
))
5754 error_message
= _("warning: unable to set size of %s section in %s");
5760 (*_bfd_error_handler
) (error_message
, APUINFO_SECTION_NAME
,
5761 bfd_archive_filename (ibfd
));
5765 /* Prevent the output section from accumulating the input sections'
5766 contents. We have already stored this in our linked list structure. */
5769 ppc_elf_write_section (abfd
, asec
, contents
)
5770 bfd
*abfd ATTRIBUTE_UNUSED
;
5772 bfd_byte
*contents ATTRIBUTE_UNUSED
;
5774 return (apuinfo_list_length ()
5775 && strcmp (asec
->name
, APUINFO_SECTION_NAME
) == 0);
5779 /* Finally we can generate the output section. */
5782 ppc_elf_final_write_processing (abfd
, linker
)
5784 bfd_boolean linker ATTRIBUTE_UNUSED
;
5789 unsigned num_entries
;
5790 bfd_size_type length
;
5792 asec
= bfd_get_section_by_name (abfd
, APUINFO_SECTION_NAME
);
5796 if (apuinfo_list_length () == 0)
5799 length
= asec
->_raw_size
;
5803 buffer
= bfd_malloc (length
);
5806 (*_bfd_error_handler
)
5807 (_("failed to allocate space for new APUinfo section."));
5811 /* Create the apuinfo header. */
5812 num_entries
= apuinfo_list_length ();
5813 bfd_put_32 (abfd
, sizeof APUINFO_LABEL
, buffer
);
5814 bfd_put_32 (abfd
, num_entries
, buffer
+ 4);
5815 bfd_put_32 (abfd
, 0x2, buffer
+ 8);
5816 strcpy (buffer
+ 12, APUINFO_LABEL
);
5819 for (i
= 0; i
< num_entries
; i
++)
5821 bfd_put_32 (abfd
, apuinfo_list_element (i
), buffer
+ length
);
5825 if (length
!= asec
->_raw_size
)
5826 (*_bfd_error_handler
) (_("failed to compute new APUinfo section."));
5828 if (! bfd_set_section_contents (abfd
, asec
, buffer
, (file_ptr
) 0, length
))
5829 (*_bfd_error_handler
) (_("failed to install new APUinfo section."));
5833 apuinfo_list_finish ();
5836 #define TARGET_LITTLE_SYM bfd_elf32_powerpcle_vec
5837 #define TARGET_LITTLE_NAME "elf32-powerpcle"
5838 #define TARGET_BIG_SYM bfd_elf32_powerpc_vec
5839 #define TARGET_BIG_NAME "elf32-powerpc"
5840 #define ELF_ARCH bfd_arch_powerpc
5841 #define ELF_MACHINE_CODE EM_PPC
5842 #define ELF_MAXPAGESIZE 0x10000
5843 #define elf_info_to_howto ppc_elf_info_to_howto
5845 #ifdef EM_CYGNUS_POWERPC
5846 #define ELF_MACHINE_ALT1 EM_CYGNUS_POWERPC
5850 #define ELF_MACHINE_ALT2 EM_PPC_OLD
5853 #define elf_backend_plt_not_loaded 1
5854 #define elf_backend_got_symbol_offset 4
5855 #define elf_backend_can_gc_sections 1
5856 #define elf_backend_can_refcount 1
5857 #define elf_backend_got_header_size 12
5858 #define elf_backend_plt_header_size PLT_INITIAL_ENTRY_SIZE
5859 #define elf_backend_rela_normal 1
5861 #define bfd_elf32_bfd_merge_private_bfd_data ppc_elf_merge_private_bfd_data
5862 #define bfd_elf32_bfd_relax_section ppc_elf_relax_section
5863 #define bfd_elf32_bfd_reloc_type_lookup ppc_elf_reloc_type_lookup
5864 #define bfd_elf32_bfd_set_private_flags ppc_elf_set_private_flags
5865 #define bfd_elf32_bfd_link_hash_table_create ppc_elf_link_hash_table_create
5867 #define elf_backend_object_p ppc_elf_object_p
5868 #define elf_backend_gc_mark_hook ppc_elf_gc_mark_hook
5869 #define elf_backend_gc_sweep_hook ppc_elf_gc_sweep_hook
5870 #define elf_backend_section_from_shdr ppc_elf_section_from_shdr
5871 #define elf_backend_relocate_section ppc_elf_relocate_section
5872 #define elf_backend_create_dynamic_sections ppc_elf_create_dynamic_sections
5873 #define elf_backend_check_relocs ppc_elf_check_relocs
5874 #define elf_backend_copy_indirect_symbol ppc_elf_copy_indirect_symbol
5875 #define elf_backend_adjust_dynamic_symbol ppc_elf_adjust_dynamic_symbol
5876 #define elf_backend_add_symbol_hook ppc_elf_add_symbol_hook
5877 #define elf_backend_size_dynamic_sections ppc_elf_size_dynamic_sections
5878 #define elf_backend_finish_dynamic_symbol ppc_elf_finish_dynamic_symbol
5879 #define elf_backend_finish_dynamic_sections ppc_elf_finish_dynamic_sections
5880 #define elf_backend_fake_sections ppc_elf_fake_sections
5881 #define elf_backend_additional_program_headers ppc_elf_additional_program_headers
5882 #define elf_backend_modify_segment_map ppc_elf_modify_segment_map
5883 #define elf_backend_grok_prstatus ppc_elf_grok_prstatus
5884 #define elf_backend_grok_psinfo ppc_elf_grok_psinfo
5885 #define elf_backend_reloc_type_class ppc_elf_reloc_type_class
5886 #define elf_backend_begin_write_processing ppc_elf_begin_write_processing
5887 #define elf_backend_final_write_processing ppc_elf_final_write_processing
5888 #define elf_backend_write_section ppc_elf_write_section
5890 #include "elf32-target.h"