1 /* PowerPC-specific support for 32-bit ELF
2 Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
3 2004, 2005 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 bfd_reloc_status_type ppc_elf_addr16_ha_reloc
39 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
40 static bfd_reloc_status_type ppc_elf_unhandled_reloc
41 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
43 /* Branch prediction bit for branch taken relocs. */
44 #define BRANCH_PREDICT_BIT 0x200000
45 /* Mask to set RA in memory instructions. */
46 #define RA_REGISTER_MASK 0x001f0000
47 /* Value to shift register by to insert RA. */
48 #define RA_REGISTER_SHIFT 16
50 /* The name of the dynamic interpreter. This is put in the .interp
52 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
54 /* The size in bytes of an entry in the procedure linkage table. */
55 #define PLT_ENTRY_SIZE 12
56 /* The initial size of the plt reserved for the dynamic linker. */
57 #define PLT_INITIAL_ENTRY_SIZE 72
58 /* The size of the gap between entries in the PLT. */
59 #define PLT_SLOT_SIZE 8
60 /* The number of single-slot PLT entries (the rest use two slots). */
61 #define PLT_NUM_SINGLE_ENTRIES 8192
63 /* Some nop instructions. */
64 #define NOP 0x60000000
65 #define CROR_151515 0x4def7b82
66 #define CROR_313131 0x4ffffb82
68 /* Offset of tp and dtp pointers from start of TLS block. */
69 #define TP_OFFSET 0x7000
70 #define DTP_OFFSET 0x8000
73 /* Enumeration to specify the special section. */
74 enum elf_linker_section_enum
80 /* Sections created by the linker. */
82 typedef struct elf_linker_section
84 /* pointer to the section */
86 /* pointer to the relocations needed for this section */
87 asection
*rel_section
;
88 /* pointer to the created symbol hash value */
89 struct elf_link_hash_entry
*sym_hash
;
90 /* offset of symbol from beginning of section */
92 } elf_linker_section_t
;
94 /* Linked list of allocated pointer entries. This hangs off of the
95 symbol lists, and provides allows us to return different pointers,
96 based on different addend's. */
98 typedef struct elf_linker_section_pointers
100 /* next allocated pointer for this symbol */
101 struct elf_linker_section_pointers
*next
;
102 /* offset of pointer from beginning of section */
106 /* which linker section this is */
107 elf_linker_section_t
*lsect
;
108 /* whether address was written yet */
109 bfd_boolean written_address_p
;
110 } elf_linker_section_pointers_t
;
112 struct ppc_elf_obj_tdata
114 struct elf_obj_tdata elf
;
116 /* A mapping from local symbols to offsets into the various linker
117 sections added. This is index by the symbol index. */
118 elf_linker_section_pointers_t
**linker_section_pointers
;
121 #define ppc_elf_tdata(bfd) \
122 ((struct ppc_elf_obj_tdata *) (bfd)->tdata.any)
124 #define elf_local_ptr_offsets(bfd) \
125 (ppc_elf_tdata (bfd)->linker_section_pointers)
127 /* Override the generic function because we store some extras. */
130 ppc_elf_mkobject (bfd
*abfd
)
132 bfd_size_type amt
= sizeof (struct ppc_elf_obj_tdata
);
133 abfd
->tdata
.any
= bfd_zalloc (abfd
, amt
);
134 if (abfd
->tdata
.any
== NULL
)
139 /* The PPC linker needs to keep track of the number of relocs that it
140 decides to copy as dynamic relocs in check_relocs for each symbol.
141 This is so that it can later discard them if they are found to be
142 unnecessary. We store the information in a field extending the
143 regular ELF linker hash table. */
145 struct ppc_elf_dyn_relocs
147 struct ppc_elf_dyn_relocs
*next
;
149 /* The input section of the reloc. */
152 /* Total number of relocs copied for the input section. */
155 /* Number of pc-relative relocs copied for the input section. */
156 bfd_size_type pc_count
;
159 /* PPC ELF linker hash entry. */
161 struct ppc_elf_link_hash_entry
163 struct elf_link_hash_entry elf
;
165 /* If this symbol is used in the linker created sections, the processor
166 specific backend uses this field to map the field into the offset
167 from the beginning of the section. */
168 elf_linker_section_pointers_t
*linker_section_pointer
;
170 /* Track dynamic relocs copied for this symbol. */
171 struct ppc_elf_dyn_relocs
*dyn_relocs
;
173 /* Contexts in which symbol is used in the GOT (or TOC).
174 TLS_GD .. TLS_TLS bits are or'd into the mask as the
175 corresponding relocs are encountered during check_relocs.
176 tls_optimize clears TLS_GD .. TLS_TPREL when optimizing to
177 indicate the corresponding GOT entry type is not needed. */
178 #define TLS_GD 1 /* GD reloc. */
179 #define TLS_LD 2 /* LD reloc. */
180 #define TLS_TPREL 4 /* TPREL reloc, => IE. */
181 #define TLS_DTPREL 8 /* DTPREL reloc, => LD. */
182 #define TLS_TLS 16 /* Any TLS reloc. */
183 #define TLS_TPRELGD 32 /* TPREL reloc resulting from GD->IE. */
187 #define ppc_elf_hash_entry(ent) ((struct ppc_elf_link_hash_entry *) (ent))
189 /* PPC ELF linker hash table. */
191 struct ppc_elf_link_hash_table
193 struct elf_link_hash_table elf
;
195 /* Short-cuts to get to dynamic linker sections. */
204 elf_linker_section_t
*sdata
;
205 elf_linker_section_t
*sdata2
;
208 /* Shortcut to .__tls_get_addr. */
209 struct elf_link_hash_entry
*tls_get_addr
;
211 /* TLS local dynamic got entry handling. */
213 bfd_signed_vma refcount
;
217 /* Small local sym to section mapping cache. */
218 struct sym_sec_cache sym_sec
;
221 /* Get the PPC ELF linker hash table from a link_info structure. */
223 #define ppc_elf_hash_table(p) \
224 ((struct ppc_elf_link_hash_table *) (p)->hash)
226 /* Create an entry in a PPC ELF linker hash table. */
228 static struct bfd_hash_entry
*
229 ppc_elf_link_hash_newfunc (struct bfd_hash_entry
*entry
,
230 struct bfd_hash_table
*table
,
233 /* Allocate the structure if it has not already been allocated by a
237 entry
= bfd_hash_allocate (table
,
238 sizeof (struct ppc_elf_link_hash_entry
));
243 /* Call the allocation method of the superclass. */
244 entry
= _bfd_elf_link_hash_newfunc (entry
, table
, string
);
247 ppc_elf_hash_entry (entry
)->linker_section_pointer
= NULL
;
248 ppc_elf_hash_entry (entry
)->dyn_relocs
= NULL
;
249 ppc_elf_hash_entry (entry
)->tls_mask
= 0;
255 /* Create a PPC ELF linker hash table. */
257 static struct bfd_link_hash_table
*
258 ppc_elf_link_hash_table_create (bfd
*abfd
)
260 struct ppc_elf_link_hash_table
*ret
;
262 ret
= bfd_zmalloc (sizeof (struct ppc_elf_link_hash_table
));
266 if (! _bfd_elf_link_hash_table_init (&ret
->elf
, abfd
,
267 ppc_elf_link_hash_newfunc
))
273 return &ret
->elf
.root
;
276 /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
277 copying dynamic variables from a shared lib into an app's dynbss
278 section, and instead use a dynamic relocation to point into the
280 #define ELIMINATE_COPY_RELOCS 1
282 /* Copy the extra info we tack onto an elf_link_hash_entry. */
285 ppc_elf_copy_indirect_symbol (const struct elf_backend_data
*bed
,
286 struct elf_link_hash_entry
*dir
,
287 struct elf_link_hash_entry
*ind
)
289 struct ppc_elf_link_hash_entry
*edir
, *eind
;
291 edir
= (struct ppc_elf_link_hash_entry
*) dir
;
292 eind
= (struct ppc_elf_link_hash_entry
*) ind
;
294 if (eind
->dyn_relocs
!= NULL
)
296 if (edir
->dyn_relocs
!= NULL
)
298 struct ppc_elf_dyn_relocs
**pp
;
299 struct ppc_elf_dyn_relocs
*p
;
301 if (ind
->root
.type
== bfd_link_hash_indirect
)
304 /* Add reloc counts against the weak sym to the strong sym
305 list. Merge any entries against the same section. */
306 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
; )
308 struct ppc_elf_dyn_relocs
*q
;
310 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
311 if (q
->sec
== p
->sec
)
313 q
->pc_count
+= p
->pc_count
;
314 q
->count
+= p
->count
;
321 *pp
= edir
->dyn_relocs
;
324 edir
->dyn_relocs
= eind
->dyn_relocs
;
325 eind
->dyn_relocs
= NULL
;
328 edir
->tls_mask
|= eind
->tls_mask
;
330 if (ELIMINATE_COPY_RELOCS
331 && ind
->root
.type
!= bfd_link_hash_indirect
332 && dir
->dynamic_adjusted
)
334 /* If called to transfer flags for a weakdef during processing
335 of elf_adjust_dynamic_symbol, don't copy non_got_ref.
336 We clear it ourselves for ELIMINATE_COPY_RELOCS. */
337 dir
->ref_dynamic
|= ind
->ref_dynamic
;
338 dir
->ref_regular
|= ind
->ref_regular
;
339 dir
->ref_regular_nonweak
|= ind
->ref_regular_nonweak
;
340 dir
->needs_plt
|= ind
->needs_plt
;
343 _bfd_elf_link_hash_copy_indirect (bed
, dir
, ind
);
346 static reloc_howto_type
*ppc_elf_howto_table
[R_PPC_max
];
348 static reloc_howto_type ppc_elf_howto_raw
[] = {
349 /* This reloc does nothing. */
350 HOWTO (R_PPC_NONE
, /* type */
352 2, /* size (0 = byte, 1 = short, 2 = long) */
354 FALSE
, /* pc_relative */
356 complain_overflow_bitfield
, /* complain_on_overflow */
357 bfd_elf_generic_reloc
, /* special_function */
358 "R_PPC_NONE", /* name */
359 FALSE
, /* partial_inplace */
362 FALSE
), /* pcrel_offset */
364 /* A standard 32 bit relocation. */
365 HOWTO (R_PPC_ADDR32
, /* type */
367 2, /* size (0 = byte, 1 = short, 2 = long) */
369 FALSE
, /* pc_relative */
371 complain_overflow_bitfield
, /* complain_on_overflow */
372 bfd_elf_generic_reloc
, /* special_function */
373 "R_PPC_ADDR32", /* name */
374 FALSE
, /* partial_inplace */
376 0xffffffff, /* dst_mask */
377 FALSE
), /* pcrel_offset */
379 /* An absolute 26 bit branch; the lower two bits must be zero.
380 FIXME: we don't check that, we just clear them. */
381 HOWTO (R_PPC_ADDR24
, /* type */
383 2, /* size (0 = byte, 1 = short, 2 = long) */
385 FALSE
, /* pc_relative */
387 complain_overflow_bitfield
, /* complain_on_overflow */
388 bfd_elf_generic_reloc
, /* special_function */
389 "R_PPC_ADDR24", /* name */
390 FALSE
, /* partial_inplace */
392 0x3fffffc, /* dst_mask */
393 FALSE
), /* pcrel_offset */
395 /* A standard 16 bit relocation. */
396 HOWTO (R_PPC_ADDR16
, /* type */
398 1, /* size (0 = byte, 1 = short, 2 = long) */
400 FALSE
, /* pc_relative */
402 complain_overflow_bitfield
, /* complain_on_overflow */
403 bfd_elf_generic_reloc
, /* special_function */
404 "R_PPC_ADDR16", /* name */
405 FALSE
, /* partial_inplace */
407 0xffff, /* dst_mask */
408 FALSE
), /* pcrel_offset */
410 /* A 16 bit relocation without overflow. */
411 HOWTO (R_PPC_ADDR16_LO
, /* type */
413 1, /* size (0 = byte, 1 = short, 2 = long) */
415 FALSE
, /* pc_relative */
417 complain_overflow_dont
,/* complain_on_overflow */
418 bfd_elf_generic_reloc
, /* special_function */
419 "R_PPC_ADDR16_LO", /* name */
420 FALSE
, /* partial_inplace */
422 0xffff, /* dst_mask */
423 FALSE
), /* pcrel_offset */
425 /* The high order 16 bits of an address. */
426 HOWTO (R_PPC_ADDR16_HI
, /* type */
428 1, /* size (0 = byte, 1 = short, 2 = long) */
430 FALSE
, /* pc_relative */
432 complain_overflow_dont
, /* complain_on_overflow */
433 bfd_elf_generic_reloc
, /* special_function */
434 "R_PPC_ADDR16_HI", /* name */
435 FALSE
, /* partial_inplace */
437 0xffff, /* dst_mask */
438 FALSE
), /* pcrel_offset */
440 /* The high order 16 bits of an address, plus 1 if the contents of
441 the low 16 bits, treated as a signed number, is negative. */
442 HOWTO (R_PPC_ADDR16_HA
, /* type */
444 1, /* size (0 = byte, 1 = short, 2 = long) */
446 FALSE
, /* pc_relative */
448 complain_overflow_dont
, /* complain_on_overflow */
449 ppc_elf_addr16_ha_reloc
, /* special_function */
450 "R_PPC_ADDR16_HA", /* name */
451 FALSE
, /* partial_inplace */
453 0xffff, /* dst_mask */
454 FALSE
), /* pcrel_offset */
456 /* An absolute 16 bit branch; the lower two bits must be zero.
457 FIXME: we don't check that, we just clear them. */
458 HOWTO (R_PPC_ADDR14
, /* type */
460 2, /* size (0 = byte, 1 = short, 2 = long) */
462 FALSE
, /* pc_relative */
464 complain_overflow_bitfield
, /* complain_on_overflow */
465 bfd_elf_generic_reloc
, /* special_function */
466 "R_PPC_ADDR14", /* name */
467 FALSE
, /* partial_inplace */
469 0xfffc, /* dst_mask */
470 FALSE
), /* pcrel_offset */
472 /* An absolute 16 bit branch, for which bit 10 should be set to
473 indicate that the branch is expected to be taken. The lower two
474 bits must be zero. */
475 HOWTO (R_PPC_ADDR14_BRTAKEN
, /* type */
477 2, /* size (0 = byte, 1 = short, 2 = long) */
479 FALSE
, /* pc_relative */
481 complain_overflow_bitfield
, /* complain_on_overflow */
482 bfd_elf_generic_reloc
, /* special_function */
483 "R_PPC_ADDR14_BRTAKEN",/* name */
484 FALSE
, /* partial_inplace */
486 0xfffc, /* dst_mask */
487 FALSE
), /* pcrel_offset */
489 /* An absolute 16 bit branch, for which bit 10 should be set to
490 indicate that the branch is not expected to be taken. The lower
491 two bits must be zero. */
492 HOWTO (R_PPC_ADDR14_BRNTAKEN
, /* type */
494 2, /* size (0 = byte, 1 = short, 2 = long) */
496 FALSE
, /* pc_relative */
498 complain_overflow_bitfield
, /* complain_on_overflow */
499 bfd_elf_generic_reloc
, /* special_function */
500 "R_PPC_ADDR14_BRNTAKEN",/* name */
501 FALSE
, /* partial_inplace */
503 0xfffc, /* dst_mask */
504 FALSE
), /* pcrel_offset */
506 /* A relative 26 bit branch; the lower two bits must be zero. */
507 HOWTO (R_PPC_REL24
, /* type */
509 2, /* size (0 = byte, 1 = short, 2 = long) */
511 TRUE
, /* pc_relative */
513 complain_overflow_signed
, /* complain_on_overflow */
514 bfd_elf_generic_reloc
, /* special_function */
515 "R_PPC_REL24", /* name */
516 FALSE
, /* partial_inplace */
518 0x3fffffc, /* dst_mask */
519 TRUE
), /* pcrel_offset */
521 /* A relative 16 bit branch; the lower two bits must be zero. */
522 HOWTO (R_PPC_REL14
, /* type */
524 2, /* size (0 = byte, 1 = short, 2 = long) */
526 TRUE
, /* pc_relative */
528 complain_overflow_signed
, /* complain_on_overflow */
529 bfd_elf_generic_reloc
, /* special_function */
530 "R_PPC_REL14", /* name */
531 FALSE
, /* partial_inplace */
533 0xfffc, /* dst_mask */
534 TRUE
), /* pcrel_offset */
536 /* A relative 16 bit branch. Bit 10 should be set to indicate that
537 the branch is expected to be taken. The lower two bits must be
539 HOWTO (R_PPC_REL14_BRTAKEN
, /* type */
541 2, /* size (0 = byte, 1 = short, 2 = long) */
543 TRUE
, /* pc_relative */
545 complain_overflow_signed
, /* complain_on_overflow */
546 bfd_elf_generic_reloc
, /* special_function */
547 "R_PPC_REL14_BRTAKEN", /* name */
548 FALSE
, /* partial_inplace */
550 0xfffc, /* dst_mask */
551 TRUE
), /* pcrel_offset */
553 /* A relative 16 bit branch. Bit 10 should be set to indicate that
554 the branch is not expected to be taken. The lower two bits must
556 HOWTO (R_PPC_REL14_BRNTAKEN
, /* type */
558 2, /* size (0 = byte, 1 = short, 2 = long) */
560 TRUE
, /* pc_relative */
562 complain_overflow_signed
, /* complain_on_overflow */
563 bfd_elf_generic_reloc
, /* special_function */
564 "R_PPC_REL14_BRNTAKEN",/* name */
565 FALSE
, /* partial_inplace */
567 0xfffc, /* dst_mask */
568 TRUE
), /* pcrel_offset */
570 /* Like R_PPC_ADDR16, but referring to the GOT table entry for the
572 HOWTO (R_PPC_GOT16
, /* type */
574 1, /* size (0 = byte, 1 = short, 2 = long) */
576 FALSE
, /* pc_relative */
578 complain_overflow_signed
, /* complain_on_overflow */
579 bfd_elf_generic_reloc
, /* special_function */
580 "R_PPC_GOT16", /* name */
581 FALSE
, /* partial_inplace */
583 0xffff, /* dst_mask */
584 FALSE
), /* pcrel_offset */
586 /* Like R_PPC_ADDR16_LO, but referring to the GOT table entry for
588 HOWTO (R_PPC_GOT16_LO
, /* type */
590 1, /* size (0 = byte, 1 = short, 2 = long) */
592 FALSE
, /* pc_relative */
594 complain_overflow_dont
, /* complain_on_overflow */
595 bfd_elf_generic_reloc
, /* special_function */
596 "R_PPC_GOT16_LO", /* name */
597 FALSE
, /* partial_inplace */
599 0xffff, /* dst_mask */
600 FALSE
), /* pcrel_offset */
602 /* Like R_PPC_ADDR16_HI, but referring to the GOT table entry for
604 HOWTO (R_PPC_GOT16_HI
, /* type */
606 1, /* size (0 = byte, 1 = short, 2 = long) */
608 FALSE
, /* pc_relative */
610 complain_overflow_bitfield
, /* complain_on_overflow */
611 bfd_elf_generic_reloc
, /* special_function */
612 "R_PPC_GOT16_HI", /* name */
613 FALSE
, /* partial_inplace */
615 0xffff, /* dst_mask */
616 FALSE
), /* pcrel_offset */
618 /* Like R_PPC_ADDR16_HA, but referring to the GOT table entry for
620 HOWTO (R_PPC_GOT16_HA
, /* type */
622 1, /* size (0 = byte, 1 = short, 2 = long) */
624 FALSE
, /* pc_relative */
626 complain_overflow_bitfield
, /* complain_on_overflow */
627 ppc_elf_addr16_ha_reloc
, /* special_function */
628 "R_PPC_GOT16_HA", /* name */
629 FALSE
, /* partial_inplace */
631 0xffff, /* dst_mask */
632 FALSE
), /* pcrel_offset */
634 /* Like R_PPC_REL24, but referring to the procedure linkage table
635 entry for the symbol. */
636 HOWTO (R_PPC_PLTREL24
, /* type */
638 2, /* size (0 = byte, 1 = short, 2 = long) */
640 TRUE
, /* pc_relative */
642 complain_overflow_signed
, /* complain_on_overflow */
643 bfd_elf_generic_reloc
, /* special_function */
644 "R_PPC_PLTREL24", /* name */
645 FALSE
, /* partial_inplace */
647 0x3fffffc, /* dst_mask */
648 TRUE
), /* pcrel_offset */
650 /* This is used only by the dynamic linker. The symbol should exist
651 both in the object being run and in some shared library. The
652 dynamic linker copies the data addressed by the symbol from the
653 shared library into the object, because the object being
654 run has to have the data at some particular address. */
655 HOWTO (R_PPC_COPY
, /* type */
657 2, /* size (0 = byte, 1 = short, 2 = long) */
659 FALSE
, /* pc_relative */
661 complain_overflow_bitfield
, /* complain_on_overflow */
662 bfd_elf_generic_reloc
, /* special_function */
663 "R_PPC_COPY", /* name */
664 FALSE
, /* partial_inplace */
667 FALSE
), /* pcrel_offset */
669 /* Like R_PPC_ADDR32, but used when setting global offset table
671 HOWTO (R_PPC_GLOB_DAT
, /* type */
673 2, /* size (0 = byte, 1 = short, 2 = long) */
675 FALSE
, /* pc_relative */
677 complain_overflow_bitfield
, /* complain_on_overflow */
678 bfd_elf_generic_reloc
, /* special_function */
679 "R_PPC_GLOB_DAT", /* name */
680 FALSE
, /* partial_inplace */
682 0xffffffff, /* dst_mask */
683 FALSE
), /* pcrel_offset */
685 /* Marks a procedure linkage table entry for a symbol. */
686 HOWTO (R_PPC_JMP_SLOT
, /* type */
688 2, /* size (0 = byte, 1 = short, 2 = long) */
690 FALSE
, /* pc_relative */
692 complain_overflow_bitfield
, /* complain_on_overflow */
693 bfd_elf_generic_reloc
, /* special_function */
694 "R_PPC_JMP_SLOT", /* name */
695 FALSE
, /* partial_inplace */
698 FALSE
), /* pcrel_offset */
700 /* Used only by the dynamic linker. When the object is run, this
701 longword is set to the load address of the object, plus the
703 HOWTO (R_PPC_RELATIVE
, /* type */
705 2, /* size (0 = byte, 1 = short, 2 = long) */
707 FALSE
, /* pc_relative */
709 complain_overflow_bitfield
, /* complain_on_overflow */
710 bfd_elf_generic_reloc
, /* special_function */
711 "R_PPC_RELATIVE", /* name */
712 FALSE
, /* partial_inplace */
714 0xffffffff, /* dst_mask */
715 FALSE
), /* pcrel_offset */
717 /* Like R_PPC_REL24, but uses the value of the symbol within the
718 object rather than the final value. Normally used for
719 _GLOBAL_OFFSET_TABLE_. */
720 HOWTO (R_PPC_LOCAL24PC
, /* type */
722 2, /* size (0 = byte, 1 = short, 2 = long) */
724 TRUE
, /* pc_relative */
726 complain_overflow_signed
, /* complain_on_overflow */
727 bfd_elf_generic_reloc
, /* special_function */
728 "R_PPC_LOCAL24PC", /* name */
729 FALSE
, /* partial_inplace */
731 0x3fffffc, /* dst_mask */
732 TRUE
), /* pcrel_offset */
734 /* Like R_PPC_ADDR32, but may be unaligned. */
735 HOWTO (R_PPC_UADDR32
, /* type */
737 2, /* size (0 = byte, 1 = short, 2 = long) */
739 FALSE
, /* pc_relative */
741 complain_overflow_bitfield
, /* complain_on_overflow */
742 bfd_elf_generic_reloc
, /* special_function */
743 "R_PPC_UADDR32", /* name */
744 FALSE
, /* partial_inplace */
746 0xffffffff, /* dst_mask */
747 FALSE
), /* pcrel_offset */
749 /* Like R_PPC_ADDR16, but may be unaligned. */
750 HOWTO (R_PPC_UADDR16
, /* type */
752 1, /* size (0 = byte, 1 = short, 2 = long) */
754 FALSE
, /* pc_relative */
756 complain_overflow_bitfield
, /* complain_on_overflow */
757 bfd_elf_generic_reloc
, /* special_function */
758 "R_PPC_UADDR16", /* name */
759 FALSE
, /* partial_inplace */
761 0xffff, /* dst_mask */
762 FALSE
), /* pcrel_offset */
764 /* 32-bit PC relative */
765 HOWTO (R_PPC_REL32
, /* type */
767 2, /* size (0 = byte, 1 = short, 2 = long) */
769 TRUE
, /* pc_relative */
771 complain_overflow_bitfield
, /* complain_on_overflow */
772 bfd_elf_generic_reloc
, /* special_function */
773 "R_PPC_REL32", /* name */
774 FALSE
, /* partial_inplace */
776 0xffffffff, /* dst_mask */
777 TRUE
), /* pcrel_offset */
779 /* 32-bit relocation to the symbol's procedure linkage table.
780 FIXME: not supported. */
781 HOWTO (R_PPC_PLT32
, /* type */
783 2, /* size (0 = byte, 1 = short, 2 = long) */
785 FALSE
, /* pc_relative */
787 complain_overflow_bitfield
, /* complain_on_overflow */
788 bfd_elf_generic_reloc
, /* special_function */
789 "R_PPC_PLT32", /* name */
790 FALSE
, /* partial_inplace */
793 FALSE
), /* pcrel_offset */
795 /* 32-bit PC relative relocation to the symbol's procedure linkage table.
796 FIXME: not supported. */
797 HOWTO (R_PPC_PLTREL32
, /* type */
799 2, /* size (0 = byte, 1 = short, 2 = long) */
801 TRUE
, /* pc_relative */
803 complain_overflow_bitfield
, /* complain_on_overflow */
804 bfd_elf_generic_reloc
, /* special_function */
805 "R_PPC_PLTREL32", /* name */
806 FALSE
, /* partial_inplace */
809 TRUE
), /* pcrel_offset */
811 /* Like R_PPC_ADDR16_LO, but referring to the PLT table entry for
813 HOWTO (R_PPC_PLT16_LO
, /* type */
815 1, /* size (0 = byte, 1 = short, 2 = long) */
817 FALSE
, /* pc_relative */
819 complain_overflow_dont
, /* complain_on_overflow */
820 bfd_elf_generic_reloc
, /* special_function */
821 "R_PPC_PLT16_LO", /* name */
822 FALSE
, /* partial_inplace */
824 0xffff, /* dst_mask */
825 FALSE
), /* pcrel_offset */
827 /* Like R_PPC_ADDR16_HI, but referring to the PLT table entry for
829 HOWTO (R_PPC_PLT16_HI
, /* type */
831 1, /* size (0 = byte, 1 = short, 2 = long) */
833 FALSE
, /* pc_relative */
835 complain_overflow_bitfield
, /* complain_on_overflow */
836 bfd_elf_generic_reloc
, /* special_function */
837 "R_PPC_PLT16_HI", /* name */
838 FALSE
, /* partial_inplace */
840 0xffff, /* dst_mask */
841 FALSE
), /* pcrel_offset */
843 /* Like R_PPC_ADDR16_HA, but referring to the PLT table entry for
845 HOWTO (R_PPC_PLT16_HA
, /* type */
847 1, /* size (0 = byte, 1 = short, 2 = long) */
849 FALSE
, /* pc_relative */
851 complain_overflow_bitfield
, /* complain_on_overflow */
852 ppc_elf_addr16_ha_reloc
, /* special_function */
853 "R_PPC_PLT16_HA", /* name */
854 FALSE
, /* partial_inplace */
856 0xffff, /* dst_mask */
857 FALSE
), /* pcrel_offset */
859 /* A sign-extended 16 bit value relative to _SDA_BASE_, for use with
861 HOWTO (R_PPC_SDAREL16
, /* type */
863 1, /* size (0 = byte, 1 = short, 2 = long) */
865 FALSE
, /* pc_relative */
867 complain_overflow_signed
, /* complain_on_overflow */
868 bfd_elf_generic_reloc
, /* special_function */
869 "R_PPC_SDAREL16", /* name */
870 FALSE
, /* partial_inplace */
872 0xffff, /* dst_mask */
873 FALSE
), /* pcrel_offset */
875 /* 16-bit section relative relocation. */
876 HOWTO (R_PPC_SECTOFF
, /* type */
878 1, /* size (0 = byte, 1 = short, 2 = long) */
880 FALSE
, /* pc_relative */
882 complain_overflow_bitfield
, /* complain_on_overflow */
883 bfd_elf_generic_reloc
, /* special_function */
884 "R_PPC_SECTOFF", /* name */
885 FALSE
, /* partial_inplace */
887 0xffff, /* dst_mask */
888 FALSE
), /* pcrel_offset */
890 /* 16-bit lower half section relative relocation. */
891 HOWTO (R_PPC_SECTOFF_LO
, /* type */
893 1, /* size (0 = byte, 1 = short, 2 = long) */
895 FALSE
, /* pc_relative */
897 complain_overflow_dont
, /* complain_on_overflow */
898 bfd_elf_generic_reloc
, /* special_function */
899 "R_PPC_SECTOFF_LO", /* name */
900 FALSE
, /* partial_inplace */
902 0xffff, /* dst_mask */
903 FALSE
), /* pcrel_offset */
905 /* 16-bit upper half section relative relocation. */
906 HOWTO (R_PPC_SECTOFF_HI
, /* type */
908 1, /* size (0 = byte, 1 = short, 2 = long) */
910 FALSE
, /* pc_relative */
912 complain_overflow_bitfield
, /* complain_on_overflow */
913 bfd_elf_generic_reloc
, /* special_function */
914 "R_PPC_SECTOFF_HI", /* name */
915 FALSE
, /* partial_inplace */
917 0xffff, /* dst_mask */
918 FALSE
), /* pcrel_offset */
920 /* 16-bit upper half adjusted section relative relocation. */
921 HOWTO (R_PPC_SECTOFF_HA
, /* type */
923 1, /* size (0 = byte, 1 = short, 2 = long) */
925 FALSE
, /* pc_relative */
927 complain_overflow_bitfield
, /* complain_on_overflow */
928 ppc_elf_addr16_ha_reloc
, /* special_function */
929 "R_PPC_SECTOFF_HA", /* name */
930 FALSE
, /* partial_inplace */
932 0xffff, /* dst_mask */
933 FALSE
), /* pcrel_offset */
935 /* Marker reloc for TLS. */
938 2, /* 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_TLS", /* name */
945 FALSE
, /* partial_inplace */
948 FALSE
), /* pcrel_offset */
950 /* Computes the load module index of the load module that contains the
951 definition of its TLS sym. */
952 HOWTO (R_PPC_DTPMOD32
,
954 2, /* size (0 = byte, 1 = short, 2 = long) */
956 FALSE
, /* pc_relative */
958 complain_overflow_dont
, /* complain_on_overflow */
959 ppc_elf_unhandled_reloc
, /* special_function */
960 "R_PPC_DTPMOD32", /* name */
961 FALSE
, /* partial_inplace */
963 0xffffffff, /* dst_mask */
964 FALSE
), /* pcrel_offset */
966 /* Computes a dtv-relative displacement, the difference between the value
967 of sym+add and the base address of the thread-local storage block that
968 contains the definition of sym, minus 0x8000. */
969 HOWTO (R_PPC_DTPREL32
,
971 2, /* size (0 = byte, 1 = short, 2 = long) */
973 FALSE
, /* pc_relative */
975 complain_overflow_dont
, /* complain_on_overflow */
976 ppc_elf_unhandled_reloc
, /* special_function */
977 "R_PPC_DTPREL32", /* name */
978 FALSE
, /* partial_inplace */
980 0xffffffff, /* dst_mask */
981 FALSE
), /* pcrel_offset */
983 /* A 16 bit dtprel reloc. */
984 HOWTO (R_PPC_DTPREL16
,
986 1, /* size (0 = byte, 1 = short, 2 = long) */
988 FALSE
, /* pc_relative */
990 complain_overflow_signed
, /* complain_on_overflow */
991 ppc_elf_unhandled_reloc
, /* special_function */
992 "R_PPC_DTPREL16", /* name */
993 FALSE
, /* partial_inplace */
995 0xffff, /* dst_mask */
996 FALSE
), /* pcrel_offset */
998 /* Like DTPREL16, but no overflow. */
999 HOWTO (R_PPC_DTPREL16_LO
,
1001 1, /* size (0 = byte, 1 = short, 2 = long) */
1003 FALSE
, /* pc_relative */
1005 complain_overflow_dont
, /* complain_on_overflow */
1006 ppc_elf_unhandled_reloc
, /* special_function */
1007 "R_PPC_DTPREL16_LO", /* name */
1008 FALSE
, /* partial_inplace */
1010 0xffff, /* dst_mask */
1011 FALSE
), /* pcrel_offset */
1013 /* Like DTPREL16_LO, but next higher group of 16 bits. */
1014 HOWTO (R_PPC_DTPREL16_HI
,
1015 16, /* rightshift */
1016 1, /* 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_DTPREL16_HI", /* name */
1023 FALSE
, /* partial_inplace */
1025 0xffff, /* dst_mask */
1026 FALSE
), /* pcrel_offset */
1028 /* Like DTPREL16_HI, but adjust for low 16 bits. */
1029 HOWTO (R_PPC_DTPREL16_HA
,
1030 16, /* rightshift */
1031 1, /* size (0 = byte, 1 = short, 2 = long) */
1033 FALSE
, /* pc_relative */
1035 complain_overflow_dont
, /* complain_on_overflow */
1036 ppc_elf_unhandled_reloc
, /* special_function */
1037 "R_PPC_DTPREL16_HA", /* name */
1038 FALSE
, /* partial_inplace */
1040 0xffff, /* dst_mask */
1041 FALSE
), /* pcrel_offset */
1043 /* Computes a tp-relative displacement, the difference between the value of
1044 sym+add and the value of the thread pointer (r13). */
1045 HOWTO (R_PPC_TPREL32
,
1047 2, /* size (0 = byte, 1 = short, 2 = long) */
1049 FALSE
, /* pc_relative */
1051 complain_overflow_dont
, /* complain_on_overflow */
1052 ppc_elf_unhandled_reloc
, /* special_function */
1053 "R_PPC_TPREL32", /* name */
1054 FALSE
, /* partial_inplace */
1056 0xffffffff, /* dst_mask */
1057 FALSE
), /* pcrel_offset */
1059 /* A 16 bit tprel reloc. */
1060 HOWTO (R_PPC_TPREL16
,
1062 1, /* size (0 = byte, 1 = short, 2 = long) */
1064 FALSE
, /* pc_relative */
1066 complain_overflow_signed
, /* complain_on_overflow */
1067 ppc_elf_unhandled_reloc
, /* special_function */
1068 "R_PPC_TPREL16", /* name */
1069 FALSE
, /* partial_inplace */
1071 0xffff, /* dst_mask */
1072 FALSE
), /* pcrel_offset */
1074 /* Like TPREL16, but no overflow. */
1075 HOWTO (R_PPC_TPREL16_LO
,
1077 1, /* size (0 = byte, 1 = short, 2 = long) */
1079 FALSE
, /* pc_relative */
1081 complain_overflow_dont
, /* complain_on_overflow */
1082 ppc_elf_unhandled_reloc
, /* special_function */
1083 "R_PPC_TPREL16_LO", /* name */
1084 FALSE
, /* partial_inplace */
1086 0xffff, /* dst_mask */
1087 FALSE
), /* pcrel_offset */
1089 /* Like TPREL16_LO, but next higher group of 16 bits. */
1090 HOWTO (R_PPC_TPREL16_HI
,
1091 16, /* rightshift */
1092 1, /* 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_TPREL16_HI", /* name */
1099 FALSE
, /* partial_inplace */
1101 0xffff, /* dst_mask */
1102 FALSE
), /* pcrel_offset */
1104 /* Like TPREL16_HI, but adjust for low 16 bits. */
1105 HOWTO (R_PPC_TPREL16_HA
,
1106 16, /* rightshift */
1107 1, /* size (0 = byte, 1 = short, 2 = long) */
1109 FALSE
, /* pc_relative */
1111 complain_overflow_dont
, /* complain_on_overflow */
1112 ppc_elf_unhandled_reloc
, /* special_function */
1113 "R_PPC_TPREL16_HA", /* name */
1114 FALSE
, /* partial_inplace */
1116 0xffff, /* dst_mask */
1117 FALSE
), /* pcrel_offset */
1119 /* Allocates two contiguous entries in the GOT to hold a tls_index structure,
1120 with values (sym+add)@dtpmod and (sym+add)@dtprel, and computes the offset
1121 to the first entry. */
1122 HOWTO (R_PPC_GOT_TLSGD16
,
1124 1, /* size (0 = byte, 1 = short, 2 = long) */
1126 FALSE
, /* pc_relative */
1128 complain_overflow_signed
, /* complain_on_overflow */
1129 ppc_elf_unhandled_reloc
, /* special_function */
1130 "R_PPC_GOT_TLSGD16", /* name */
1131 FALSE
, /* partial_inplace */
1133 0xffff, /* dst_mask */
1134 FALSE
), /* pcrel_offset */
1136 /* Like GOT_TLSGD16, but no overflow. */
1137 HOWTO (R_PPC_GOT_TLSGD16_LO
,
1139 1, /* size (0 = byte, 1 = short, 2 = long) */
1141 FALSE
, /* pc_relative */
1143 complain_overflow_dont
, /* complain_on_overflow */
1144 ppc_elf_unhandled_reloc
, /* special_function */
1145 "R_PPC_GOT_TLSGD16_LO", /* name */
1146 FALSE
, /* partial_inplace */
1148 0xffff, /* dst_mask */
1149 FALSE
), /* pcrel_offset */
1151 /* Like GOT_TLSGD16_LO, but next higher group of 16 bits. */
1152 HOWTO (R_PPC_GOT_TLSGD16_HI
,
1153 16, /* rightshift */
1154 1, /* size (0 = byte, 1 = short, 2 = long) */
1156 FALSE
, /* pc_relative */
1158 complain_overflow_dont
, /* complain_on_overflow */
1159 ppc_elf_unhandled_reloc
, /* special_function */
1160 "R_PPC_GOT_TLSGD16_HI", /* name */
1161 FALSE
, /* partial_inplace */
1163 0xffff, /* dst_mask */
1164 FALSE
), /* pcrel_offset */
1166 /* Like GOT_TLSGD16_HI, but adjust for low 16 bits. */
1167 HOWTO (R_PPC_GOT_TLSGD16_HA
,
1168 16, /* rightshift */
1169 1, /* size (0 = byte, 1 = short, 2 = long) */
1171 FALSE
, /* pc_relative */
1173 complain_overflow_dont
, /* complain_on_overflow */
1174 ppc_elf_unhandled_reloc
, /* special_function */
1175 "R_PPC_GOT_TLSGD16_HA", /* name */
1176 FALSE
, /* partial_inplace */
1178 0xffff, /* dst_mask */
1179 FALSE
), /* pcrel_offset */
1181 /* Allocates two contiguous entries in the GOT to hold a tls_index structure,
1182 with values (sym+add)@dtpmod and zero, and computes the offset to the
1184 HOWTO (R_PPC_GOT_TLSLD16
,
1186 1, /* size (0 = byte, 1 = short, 2 = long) */
1188 FALSE
, /* pc_relative */
1190 complain_overflow_signed
, /* complain_on_overflow */
1191 ppc_elf_unhandled_reloc
, /* special_function */
1192 "R_PPC_GOT_TLSLD16", /* name */
1193 FALSE
, /* partial_inplace */
1195 0xffff, /* dst_mask */
1196 FALSE
), /* pcrel_offset */
1198 /* Like GOT_TLSLD16, but no overflow. */
1199 HOWTO (R_PPC_GOT_TLSLD16_LO
,
1201 1, /* size (0 = byte, 1 = short, 2 = long) */
1203 FALSE
, /* pc_relative */
1205 complain_overflow_dont
, /* complain_on_overflow */
1206 ppc_elf_unhandled_reloc
, /* special_function */
1207 "R_PPC_GOT_TLSLD16_LO", /* name */
1208 FALSE
, /* partial_inplace */
1210 0xffff, /* dst_mask */
1211 FALSE
), /* pcrel_offset */
1213 /* Like GOT_TLSLD16_LO, but next higher group of 16 bits. */
1214 HOWTO (R_PPC_GOT_TLSLD16_HI
,
1215 16, /* rightshift */
1216 1, /* size (0 = byte, 1 = short, 2 = long) */
1218 FALSE
, /* pc_relative */
1220 complain_overflow_dont
, /* complain_on_overflow */
1221 ppc_elf_unhandled_reloc
, /* special_function */
1222 "R_PPC_GOT_TLSLD16_HI", /* name */
1223 FALSE
, /* partial_inplace */
1225 0xffff, /* dst_mask */
1226 FALSE
), /* pcrel_offset */
1228 /* Like GOT_TLSLD16_HI, but adjust for low 16 bits. */
1229 HOWTO (R_PPC_GOT_TLSLD16_HA
,
1230 16, /* rightshift */
1231 1, /* size (0 = byte, 1 = short, 2 = long) */
1233 FALSE
, /* pc_relative */
1235 complain_overflow_dont
, /* complain_on_overflow */
1236 ppc_elf_unhandled_reloc
, /* special_function */
1237 "R_PPC_GOT_TLSLD16_HA", /* name */
1238 FALSE
, /* partial_inplace */
1240 0xffff, /* dst_mask */
1241 FALSE
), /* pcrel_offset */
1243 /* Allocates an entry in the GOT with value (sym+add)@dtprel, and computes
1244 the offset to the entry. */
1245 HOWTO (R_PPC_GOT_DTPREL16
,
1247 1, /* size (0 = byte, 1 = short, 2 = long) */
1249 FALSE
, /* pc_relative */
1251 complain_overflow_signed
, /* complain_on_overflow */
1252 ppc_elf_unhandled_reloc
, /* special_function */
1253 "R_PPC_GOT_DTPREL16", /* name */
1254 FALSE
, /* partial_inplace */
1256 0xffff, /* dst_mask */
1257 FALSE
), /* pcrel_offset */
1259 /* Like GOT_DTPREL16, but no overflow. */
1260 HOWTO (R_PPC_GOT_DTPREL16_LO
,
1262 1, /* size (0 = byte, 1 = short, 2 = long) */
1264 FALSE
, /* pc_relative */
1266 complain_overflow_dont
, /* complain_on_overflow */
1267 ppc_elf_unhandled_reloc
, /* special_function */
1268 "R_PPC_GOT_DTPREL16_LO", /* name */
1269 FALSE
, /* partial_inplace */
1271 0xffff, /* dst_mask */
1272 FALSE
), /* pcrel_offset */
1274 /* Like GOT_DTPREL16_LO, but next higher group of 16 bits. */
1275 HOWTO (R_PPC_GOT_DTPREL16_HI
,
1276 16, /* rightshift */
1277 1, /* size (0 = byte, 1 = short, 2 = long) */
1279 FALSE
, /* pc_relative */
1281 complain_overflow_dont
, /* complain_on_overflow */
1282 ppc_elf_unhandled_reloc
, /* special_function */
1283 "R_PPC_GOT_DTPREL16_HI", /* name */
1284 FALSE
, /* partial_inplace */
1286 0xffff, /* dst_mask */
1287 FALSE
), /* pcrel_offset */
1289 /* Like GOT_DTPREL16_HI, but adjust for low 16 bits. */
1290 HOWTO (R_PPC_GOT_DTPREL16_HA
,
1291 16, /* rightshift */
1292 1, /* size (0 = byte, 1 = short, 2 = long) */
1294 FALSE
, /* pc_relative */
1296 complain_overflow_dont
, /* complain_on_overflow */
1297 ppc_elf_unhandled_reloc
, /* special_function */
1298 "R_PPC_GOT_DTPREL16_HA", /* name */
1299 FALSE
, /* partial_inplace */
1301 0xffff, /* dst_mask */
1302 FALSE
), /* pcrel_offset */
1304 /* Allocates an entry in the GOT with value (sym+add)@tprel, and computes the
1305 offset to the entry. */
1306 HOWTO (R_PPC_GOT_TPREL16
,
1308 1, /* size (0 = byte, 1 = short, 2 = long) */
1310 FALSE
, /* pc_relative */
1312 complain_overflow_signed
, /* complain_on_overflow */
1313 ppc_elf_unhandled_reloc
, /* special_function */
1314 "R_PPC_GOT_TPREL16", /* name */
1315 FALSE
, /* partial_inplace */
1317 0xffff, /* dst_mask */
1318 FALSE
), /* pcrel_offset */
1320 /* Like GOT_TPREL16, but no overflow. */
1321 HOWTO (R_PPC_GOT_TPREL16_LO
,
1323 1, /* size (0 = byte, 1 = short, 2 = long) */
1325 FALSE
, /* pc_relative */
1327 complain_overflow_dont
, /* complain_on_overflow */
1328 ppc_elf_unhandled_reloc
, /* special_function */
1329 "R_PPC_GOT_TPREL16_LO", /* name */
1330 FALSE
, /* partial_inplace */
1332 0xffff, /* dst_mask */
1333 FALSE
), /* pcrel_offset */
1335 /* Like GOT_TPREL16_LO, but next higher group of 16 bits. */
1336 HOWTO (R_PPC_GOT_TPREL16_HI
,
1337 16, /* rightshift */
1338 1, /* size (0 = byte, 1 = short, 2 = long) */
1340 FALSE
, /* pc_relative */
1342 complain_overflow_dont
, /* complain_on_overflow */
1343 ppc_elf_unhandled_reloc
, /* special_function */
1344 "R_PPC_GOT_TPREL16_HI", /* name */
1345 FALSE
, /* partial_inplace */
1347 0xffff, /* dst_mask */
1348 FALSE
), /* pcrel_offset */
1350 /* Like GOT_TPREL16_HI, but adjust for low 16 bits. */
1351 HOWTO (R_PPC_GOT_TPREL16_HA
,
1352 16, /* rightshift */
1353 1, /* size (0 = byte, 1 = short, 2 = long) */
1355 FALSE
, /* pc_relative */
1357 complain_overflow_dont
, /* complain_on_overflow */
1358 ppc_elf_unhandled_reloc
, /* special_function */
1359 "R_PPC_GOT_TPREL16_HA", /* name */
1360 FALSE
, /* partial_inplace */
1362 0xffff, /* dst_mask */
1363 FALSE
), /* pcrel_offset */
1365 /* The remaining relocs are from the Embedded ELF ABI, and are not
1366 in the SVR4 ELF ABI. */
1368 /* 32 bit value resulting from the addend minus the symbol. */
1369 HOWTO (R_PPC_EMB_NADDR32
, /* type */
1371 2, /* size (0 = byte, 1 = short, 2 = long) */
1373 FALSE
, /* pc_relative */
1375 complain_overflow_bitfield
, /* complain_on_overflow */
1376 bfd_elf_generic_reloc
, /* special_function */
1377 "R_PPC_EMB_NADDR32", /* name */
1378 FALSE
, /* partial_inplace */
1380 0xffffffff, /* dst_mask */
1381 FALSE
), /* pcrel_offset */
1383 /* 16 bit value resulting from the addend minus the symbol. */
1384 HOWTO (R_PPC_EMB_NADDR16
, /* type */
1386 1, /* size (0 = byte, 1 = short, 2 = long) */
1388 FALSE
, /* pc_relative */
1390 complain_overflow_bitfield
, /* complain_on_overflow */
1391 bfd_elf_generic_reloc
, /* special_function */
1392 "R_PPC_EMB_NADDR16", /* name */
1393 FALSE
, /* partial_inplace */
1395 0xffff, /* dst_mask */
1396 FALSE
), /* pcrel_offset */
1398 /* 16 bit value resulting from the addend minus the symbol. */
1399 HOWTO (R_PPC_EMB_NADDR16_LO
, /* type */
1401 1, /* size (0 = byte, 1 = short, 2 = long) */
1403 FALSE
, /* pc_relative */
1405 complain_overflow_dont
,/* complain_on_overflow */
1406 bfd_elf_generic_reloc
, /* special_function */
1407 "R_PPC_EMB_ADDR16_LO", /* name */
1408 FALSE
, /* partial_inplace */
1410 0xffff, /* dst_mask */
1411 FALSE
), /* pcrel_offset */
1413 /* The high order 16 bits of the addend minus the symbol. */
1414 HOWTO (R_PPC_EMB_NADDR16_HI
, /* type */
1415 16, /* rightshift */
1416 1, /* size (0 = byte, 1 = short, 2 = long) */
1418 FALSE
, /* pc_relative */
1420 complain_overflow_dont
, /* complain_on_overflow */
1421 bfd_elf_generic_reloc
, /* special_function */
1422 "R_PPC_EMB_NADDR16_HI", /* name */
1423 FALSE
, /* partial_inplace */
1425 0xffff, /* dst_mask */
1426 FALSE
), /* pcrel_offset */
1428 /* The high order 16 bits of the result of the addend minus the address,
1429 plus 1 if the contents of the low 16 bits, treated as a signed number,
1431 HOWTO (R_PPC_EMB_NADDR16_HA
, /* type */
1432 16, /* rightshift */
1433 1, /* size (0 = byte, 1 = short, 2 = long) */
1435 FALSE
, /* pc_relative */
1437 complain_overflow_dont
, /* complain_on_overflow */
1438 ppc_elf_addr16_ha_reloc
, /* special_function */
1439 "R_PPC_EMB_NADDR16_HA", /* name */
1440 FALSE
, /* partial_inplace */
1442 0xffff, /* dst_mask */
1443 FALSE
), /* pcrel_offset */
1445 /* 16 bit value resulting from allocating a 4 byte word to hold an
1446 address in the .sdata section, and returning the offset from
1447 _SDA_BASE_ for that relocation. */
1448 HOWTO (R_PPC_EMB_SDAI16
, /* type */
1450 1, /* size (0 = byte, 1 = short, 2 = long) */
1452 FALSE
, /* pc_relative */
1454 complain_overflow_bitfield
, /* complain_on_overflow */
1455 bfd_elf_generic_reloc
, /* special_function */
1456 "R_PPC_EMB_SDAI16", /* name */
1457 FALSE
, /* partial_inplace */
1459 0xffff, /* dst_mask */
1460 FALSE
), /* pcrel_offset */
1462 /* 16 bit value resulting from allocating a 4 byte word to hold an
1463 address in the .sdata2 section, and returning the offset from
1464 _SDA2_BASE_ for that relocation. */
1465 HOWTO (R_PPC_EMB_SDA2I16
, /* type */
1467 1, /* size (0 = byte, 1 = short, 2 = long) */
1469 FALSE
, /* pc_relative */
1471 complain_overflow_bitfield
, /* complain_on_overflow */
1472 bfd_elf_generic_reloc
, /* special_function */
1473 "R_PPC_EMB_SDA2I16", /* name */
1474 FALSE
, /* partial_inplace */
1476 0xffff, /* dst_mask */
1477 FALSE
), /* pcrel_offset */
1479 /* A sign-extended 16 bit value relative to _SDA2_BASE_, for use with
1480 small data items. */
1481 HOWTO (R_PPC_EMB_SDA2REL
, /* type */
1483 1, /* size (0 = byte, 1 = short, 2 = long) */
1485 FALSE
, /* pc_relative */
1487 complain_overflow_signed
, /* complain_on_overflow */
1488 bfd_elf_generic_reloc
, /* special_function */
1489 "R_PPC_EMB_SDA2REL", /* name */
1490 FALSE
, /* partial_inplace */
1492 0xffff, /* dst_mask */
1493 FALSE
), /* pcrel_offset */
1495 /* Relocate against either _SDA_BASE_ or _SDA2_BASE_, filling in the 16 bit
1496 signed offset from the appropriate base, and filling in the register
1497 field with the appropriate register (0, 2, or 13). */
1498 HOWTO (R_PPC_EMB_SDA21
, /* type */
1500 2, /* size (0 = byte, 1 = short, 2 = long) */
1502 FALSE
, /* pc_relative */
1504 complain_overflow_signed
, /* complain_on_overflow */
1505 bfd_elf_generic_reloc
, /* special_function */
1506 "R_PPC_EMB_SDA21", /* name */
1507 FALSE
, /* partial_inplace */
1509 0xffff, /* dst_mask */
1510 FALSE
), /* pcrel_offset */
1512 /* Relocation not handled: R_PPC_EMB_MRKREF */
1513 /* Relocation not handled: R_PPC_EMB_RELSEC16 */
1514 /* Relocation not handled: R_PPC_EMB_RELST_LO */
1515 /* Relocation not handled: R_PPC_EMB_RELST_HI */
1516 /* Relocation not handled: R_PPC_EMB_RELST_HA */
1517 /* Relocation not handled: R_PPC_EMB_BIT_FLD */
1519 /* PC relative relocation against either _SDA_BASE_ or _SDA2_BASE_, filling
1520 in the 16 bit signed offset from the appropriate base, and filling in the
1521 register field with the appropriate register (0, 2, or 13). */
1522 HOWTO (R_PPC_EMB_RELSDA
, /* type */
1524 1, /* size (0 = byte, 1 = short, 2 = long) */
1526 TRUE
, /* pc_relative */
1528 complain_overflow_signed
, /* complain_on_overflow */
1529 bfd_elf_generic_reloc
, /* special_function */
1530 "R_PPC_EMB_RELSDA", /* name */
1531 FALSE
, /* partial_inplace */
1533 0xffff, /* dst_mask */
1534 FALSE
), /* pcrel_offset */
1536 /* GNU extension to record C++ vtable hierarchy. */
1537 HOWTO (R_PPC_GNU_VTINHERIT
, /* type */
1539 0, /* size (0 = byte, 1 = short, 2 = long) */
1541 FALSE
, /* pc_relative */
1543 complain_overflow_dont
, /* complain_on_overflow */
1544 NULL
, /* special_function */
1545 "R_PPC_GNU_VTINHERIT", /* name */
1546 FALSE
, /* partial_inplace */
1549 FALSE
), /* pcrel_offset */
1551 /* GNU extension to record C++ vtable member usage. */
1552 HOWTO (R_PPC_GNU_VTENTRY
, /* type */
1554 0, /* size (0 = byte, 1 = short, 2 = long) */
1556 FALSE
, /* pc_relative */
1558 complain_overflow_dont
, /* complain_on_overflow */
1559 NULL
, /* special_function */
1560 "R_PPC_GNU_VTENTRY", /* name */
1561 FALSE
, /* partial_inplace */
1564 FALSE
), /* pcrel_offset */
1566 /* Phony reloc to handle AIX style TOC entries. */
1567 HOWTO (R_PPC_TOC16
, /* type */
1569 1, /* size (0 = byte, 1 = short, 2 = long) */
1571 FALSE
, /* pc_relative */
1573 complain_overflow_signed
, /* complain_on_overflow */
1574 bfd_elf_generic_reloc
, /* special_function */
1575 "R_PPC_TOC16", /* name */
1576 FALSE
, /* partial_inplace */
1578 0xffff, /* dst_mask */
1579 FALSE
), /* pcrel_offset */
1582 /* Initialize the ppc_elf_howto_table, so that linear accesses can be done. */
1585 ppc_elf_howto_init (void)
1587 unsigned int i
, type
;
1590 i
< sizeof (ppc_elf_howto_raw
) / sizeof (ppc_elf_howto_raw
[0]);
1593 type
= ppc_elf_howto_raw
[i
].type
;
1594 if (type
>= (sizeof (ppc_elf_howto_table
)
1595 / sizeof (ppc_elf_howto_table
[0])))
1597 ppc_elf_howto_table
[type
] = &ppc_elf_howto_raw
[i
];
1601 #define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
1603 static const int shared_stub_entry
[] =
1605 0x7c0802a6, /* mflr 0 */
1606 0x429f0005, /* bcl 20, 31, .Lxxx */
1607 0x7d6802a6, /* mflr 11 */
1608 0x3d6b0000, /* addis 11, 11, (xxx-.Lxxx)@ha */
1609 0x396b0018, /* addi 11, 11, (xxx-.Lxxx)@l */
1610 0x7c0803a6, /* mtlr 0 */
1611 0x7d6903a6, /* mtctr 11 */
1612 0x4e800420, /* bctr */
1615 static const int stub_entry
[] =
1617 0x3d600000, /* lis 11,xxx@ha */
1618 0x396b0000, /* addi 11,11,xxx@l */
1619 0x7d6903a6, /* mtctr 11 */
1620 0x4e800420, /* bctr */
1625 ppc_elf_relax_section (bfd
*abfd
,
1627 struct bfd_link_info
*link_info
,
1632 struct one_fixup
*next
;
1638 Elf_Internal_Shdr
*symtab_hdr
;
1639 bfd_byte
*contents
= NULL
;
1640 Elf_Internal_Sym
*isymbuf
= NULL
;
1641 Elf_Internal_Rela
*internal_relocs
= NULL
;
1642 Elf_Internal_Rela
*irel
, *irelend
;
1643 struct one_fixup
*fixups
= NULL
;
1644 bfd_boolean changed
;
1645 struct ppc_elf_link_hash_table
*ppc_info
;
1646 bfd_size_type trampoff
;
1650 /* Nothing to do if there are no relocations. */
1651 if ((isec
->flags
& SEC_RELOC
) == 0 || isec
->reloc_count
== 0)
1654 trampoff
= (isec
->size
+ 3) & (bfd_vma
) -4;
1655 /* Space for a branch around any trampolines. */
1658 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
1660 /* Get a copy of the native relocations. */
1661 internal_relocs
= _bfd_elf_link_read_relocs (abfd
, isec
, NULL
, NULL
,
1662 link_info
->keep_memory
);
1663 if (internal_relocs
== NULL
)
1666 ppc_info
= ppc_elf_hash_table (link_info
);
1667 irelend
= internal_relocs
+ isec
->reloc_count
;
1669 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
1671 unsigned long r_type
= ELF32_R_TYPE (irel
->r_info
);
1672 bfd_vma symaddr
, reladdr
, toff
, roff
;
1674 struct one_fixup
*f
;
1675 size_t insn_offset
= 0;
1676 bfd_vma max_branch_offset
, val
;
1679 unsigned char sym_type
;
1684 case R_PPC_LOCAL24PC
:
1685 case R_PPC_PLTREL24
:
1686 max_branch_offset
= 1 << 25;
1690 case R_PPC_REL14_BRTAKEN
:
1691 case R_PPC_REL14_BRNTAKEN
:
1692 max_branch_offset
= 1 << 15;
1699 /* Get the value of the symbol referred to by the reloc. */
1700 if (ELF32_R_SYM (irel
->r_info
) < symtab_hdr
->sh_info
)
1702 /* A local symbol. */
1703 Elf_Internal_Sym
*isym
;
1705 /* Read this BFD's local symbols. */
1706 if (isymbuf
== NULL
)
1708 isymbuf
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
1709 if (isymbuf
== NULL
)
1710 isymbuf
= bfd_elf_get_elf_syms (abfd
, symtab_hdr
,
1711 symtab_hdr
->sh_info
, 0,
1716 isym
= isymbuf
+ ELF32_R_SYM (irel
->r_info
);
1717 if (isym
->st_shndx
== SHN_UNDEF
)
1718 continue; /* We can't do anything with undefined symbols. */
1719 else if (isym
->st_shndx
== SHN_ABS
)
1720 tsec
= bfd_abs_section_ptr
;
1721 else if (isym
->st_shndx
== SHN_COMMON
)
1722 tsec
= bfd_com_section_ptr
;
1724 tsec
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
1726 toff
= isym
->st_value
;
1727 sym_type
= ELF_ST_TYPE (isym
->st_info
);
1731 /* Global symbol handling. */
1733 struct elf_link_hash_entry
*h
;
1735 indx
= ELF32_R_SYM (irel
->r_info
) - symtab_hdr
->sh_info
;
1736 h
= elf_sym_hashes (abfd
)[indx
];
1738 while (h
->root
.type
== bfd_link_hash_indirect
1739 || h
->root
.type
== bfd_link_hash_warning
)
1740 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1742 if (r_type
== R_PPC_PLTREL24
1743 && ppc_info
->plt
!= NULL
1744 && h
->plt
.offset
!= (bfd_vma
) -1)
1746 tsec
= ppc_info
->plt
;
1747 toff
= h
->plt
.offset
;
1749 else if (h
->root
.type
== bfd_link_hash_defined
1750 || h
->root
.type
== bfd_link_hash_defweak
)
1752 tsec
= h
->root
.u
.def
.section
;
1753 toff
= h
->root
.u
.def
.value
;
1761 /* If the branch and target are in the same section, you have
1762 no hope of adding stubs. We'll error out later should the
1767 /* There probably isn't any reason to handle symbols in
1768 SEC_MERGE sections; SEC_MERGE doesn't seem a likely
1769 attribute for a code section, and we are only looking at
1770 branches. However, implement it correctly here as a
1771 reference for other target relax_section functions. */
1772 if (0 && tsec
->sec_info_type
== ELF_INFO_TYPE_MERGE
)
1774 /* At this stage in linking, no SEC_MERGE symbol has been
1775 adjusted, so all references to such symbols need to be
1776 passed through _bfd_merged_section_offset. (Later, in
1777 relocate_section, all SEC_MERGE symbols *except* for
1778 section symbols have been adjusted.)
1780 gas may reduce relocations against symbols in SEC_MERGE
1781 sections to a relocation against the section symbol when
1782 the original addend was zero. When the reloc is against
1783 a section symbol we should include the addend in the
1784 offset passed to _bfd_merged_section_offset, since the
1785 location of interest is the original symbol. On the
1786 other hand, an access to "sym+addend" where "sym" is not
1787 a section symbol should not include the addend; Such an
1788 access is presumed to be an offset from "sym"; The
1789 location of interest is just "sym". */
1790 if (sym_type
== STT_SECTION
)
1791 toff
+= irel
->r_addend
;
1793 toff
= _bfd_merged_section_offset (abfd
, &tsec
,
1794 elf_section_data (tsec
)->sec_info
,
1797 if (sym_type
!= STT_SECTION
)
1798 toff
+= irel
->r_addend
;
1801 toff
+= irel
->r_addend
;
1803 symaddr
= tsec
->output_section
->vma
+ tsec
->output_offset
+ toff
;
1805 roff
= irel
->r_offset
;
1806 reladdr
= isec
->output_section
->vma
+ isec
->output_offset
+ roff
;
1808 /* If the branch is in range, no need to do anything. */
1809 if (symaddr
- reladdr
+ max_branch_offset
< 2 * max_branch_offset
)
1812 /* Look for an existing fixup to this address. */
1813 for (f
= fixups
; f
; f
= f
->next
)
1814 if (f
->tsec
== tsec
&& f
->toff
== toff
)
1820 unsigned long stub_rtype
;
1822 val
= trampoff
- roff
;
1823 if (val
>= max_branch_offset
)
1824 /* Oh dear, we can't reach a trampoline. Don't try to add
1825 one. We'll report an error later. */
1828 if (link_info
->shared
)
1830 size
= 4 * ARRAY_SIZE (shared_stub_entry
);
1832 stub_rtype
= R_PPC_RELAX32PC
;
1836 size
= 4 * ARRAY_SIZE (stub_entry
);
1838 stub_rtype
= R_PPC_RELAX32
;
1841 if (R_PPC_RELAX32_PLT
- R_PPC_RELAX32
1842 != R_PPC_RELAX32PC_PLT
- R_PPC_RELAX32PC
)
1844 if (tsec
== ppc_info
->plt
)
1845 stub_rtype
+= R_PPC_RELAX32_PLT
- R_PPC_RELAX32
;
1847 /* Hijack the old relocation. Since we need two
1848 relocations for this use a "composite" reloc. */
1849 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
),
1851 irel
->r_offset
= trampoff
+ insn_offset
;
1853 /* Record the fixup so we don't do it again this section. */
1854 f
= bfd_malloc (sizeof (*f
));
1858 f
->trampoff
= trampoff
;
1865 val
= f
->trampoff
- roff
;
1866 if (val
>= max_branch_offset
)
1869 /* Nop out the reloc, since we're finalizing things here. */
1870 irel
->r_info
= ELF32_R_INFO (0, R_PPC_NONE
);
1873 /* Get the section contents. */
1874 if (contents
== NULL
)
1876 /* Get cached copy if it exists. */
1877 if (elf_section_data (isec
)->this_hdr
.contents
!= NULL
)
1878 contents
= elf_section_data (isec
)->this_hdr
.contents
;
1881 /* Go get them off disk. */
1882 if (!bfd_malloc_and_get_section (abfd
, isec
, &contents
))
1887 /* Fix up the existing branch to hit the trampoline. */
1888 hit_addr
= contents
+ roff
;
1892 case R_PPC_LOCAL24PC
:
1893 case R_PPC_PLTREL24
:
1894 t0
= bfd_get_32 (abfd
, hit_addr
);
1896 t0
|= val
& 0x3fffffc;
1897 bfd_put_32 (abfd
, t0
, hit_addr
);
1901 case R_PPC_REL14_BRTAKEN
:
1902 case R_PPC_REL14_BRNTAKEN
:
1903 t0
= bfd_get_32 (abfd
, hit_addr
);
1906 bfd_put_32 (abfd
, t0
, hit_addr
);
1911 /* Write out the trampolines. */
1912 changed
= fixups
!= NULL
;
1922 struct one_fixup
*f
= fixups
;
1923 fixups
= fixups
->next
;
1928 contents
= bfd_realloc (contents
, trampoff
);
1929 if (contents
== NULL
)
1932 isec
->size
= (isec
->size
+ 3) & (bfd_vma
) -4;
1933 /* Branch around the trampolines. */
1934 val
= trampoff
- isec
->size
+ 0x48000000;
1935 dest
= contents
+ isec
->size
;
1936 isec
->size
= trampoff
;
1937 bfd_put_32 (abfd
, val
, dest
);
1940 if (link_info
->shared
)
1942 stub
= shared_stub_entry
;
1943 size
= ARRAY_SIZE (shared_stub_entry
);
1948 size
= ARRAY_SIZE (stub_entry
);
1952 while (dest
< contents
+ trampoff
)
1954 bfd_put_32 (abfd
, stub
[i
], dest
);
1960 BFD_ASSERT (i
== 0);
1964 && symtab_hdr
->contents
!= (unsigned char *) isymbuf
)
1966 if (! link_info
->keep_memory
)
1970 /* Cache the symbols for elf_link_input_bfd. */
1971 symtab_hdr
->contents
= (unsigned char *) isymbuf
;
1975 if (contents
!= NULL
1976 && elf_section_data (isec
)->this_hdr
.contents
!= contents
)
1978 if (!changed
&& !link_info
->keep_memory
)
1982 /* Cache the section contents for elf_link_input_bfd. */
1983 elf_section_data (isec
)->this_hdr
.contents
= contents
;
1987 if (elf_section_data (isec
)->relocs
!= internal_relocs
)
1990 free (internal_relocs
);
1992 elf_section_data (isec
)->relocs
= internal_relocs
;
1999 if (isymbuf
!= NULL
&& (unsigned char *) isymbuf
!= symtab_hdr
->contents
)
2001 if (contents
!= NULL
2002 && elf_section_data (isec
)->this_hdr
.contents
!= contents
)
2004 if (internal_relocs
!= NULL
2005 && elf_section_data (isec
)->relocs
!= internal_relocs
)
2006 free (internal_relocs
);
2010 static reloc_howto_type
*
2011 ppc_elf_reloc_type_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
2012 bfd_reloc_code_real_type code
)
2014 enum elf_ppc_reloc_type r
;
2016 /* Initialize howto table if not already done. */
2017 if (!ppc_elf_howto_table
[R_PPC_ADDR32
])
2018 ppc_elf_howto_init ();
2025 case BFD_RELOC_NONE
: r
= R_PPC_NONE
; break;
2026 case BFD_RELOC_32
: r
= R_PPC_ADDR32
; break;
2027 case BFD_RELOC_PPC_BA26
: r
= R_PPC_ADDR24
; break;
2028 case BFD_RELOC_16
: r
= R_PPC_ADDR16
; break;
2029 case BFD_RELOC_LO16
: r
= R_PPC_ADDR16_LO
; break;
2030 case BFD_RELOC_HI16
: r
= R_PPC_ADDR16_HI
; break;
2031 case BFD_RELOC_HI16_S
: r
= R_PPC_ADDR16_HA
; break;
2032 case BFD_RELOC_PPC_BA16
: r
= R_PPC_ADDR14
; break;
2033 case BFD_RELOC_PPC_BA16_BRTAKEN
: r
= R_PPC_ADDR14_BRTAKEN
; break;
2034 case BFD_RELOC_PPC_BA16_BRNTAKEN
: r
= R_PPC_ADDR14_BRNTAKEN
; break;
2035 case BFD_RELOC_PPC_B26
: r
= R_PPC_REL24
; break;
2036 case BFD_RELOC_PPC_B16
: r
= R_PPC_REL14
; break;
2037 case BFD_RELOC_PPC_B16_BRTAKEN
: r
= R_PPC_REL14_BRTAKEN
; break;
2038 case BFD_RELOC_PPC_B16_BRNTAKEN
: r
= R_PPC_REL14_BRNTAKEN
; break;
2039 case BFD_RELOC_16_GOTOFF
: r
= R_PPC_GOT16
; break;
2040 case BFD_RELOC_LO16_GOTOFF
: r
= R_PPC_GOT16_LO
; break;
2041 case BFD_RELOC_HI16_GOTOFF
: r
= R_PPC_GOT16_HI
; break;
2042 case BFD_RELOC_HI16_S_GOTOFF
: r
= R_PPC_GOT16_HA
; break;
2043 case BFD_RELOC_24_PLT_PCREL
: r
= R_PPC_PLTREL24
; break;
2044 case BFD_RELOC_PPC_COPY
: r
= R_PPC_COPY
; break;
2045 case BFD_RELOC_PPC_GLOB_DAT
: r
= R_PPC_GLOB_DAT
; break;
2046 case BFD_RELOC_PPC_LOCAL24PC
: r
= R_PPC_LOCAL24PC
; break;
2047 case BFD_RELOC_32_PCREL
: r
= R_PPC_REL32
; break;
2048 case BFD_RELOC_32_PLTOFF
: r
= R_PPC_PLT32
; break;
2049 case BFD_RELOC_32_PLT_PCREL
: r
= R_PPC_PLTREL32
; break;
2050 case BFD_RELOC_LO16_PLTOFF
: r
= R_PPC_PLT16_LO
; break;
2051 case BFD_RELOC_HI16_PLTOFF
: r
= R_PPC_PLT16_HI
; break;
2052 case BFD_RELOC_HI16_S_PLTOFF
: r
= R_PPC_PLT16_HA
; break;
2053 case BFD_RELOC_GPREL16
: r
= R_PPC_SDAREL16
; break;
2054 case BFD_RELOC_16_BASEREL
: r
= R_PPC_SECTOFF
; break;
2055 case BFD_RELOC_LO16_BASEREL
: r
= R_PPC_SECTOFF_LO
; break;
2056 case BFD_RELOC_HI16_BASEREL
: r
= R_PPC_SECTOFF_HI
; break;
2057 case BFD_RELOC_HI16_S_BASEREL
: r
= R_PPC_SECTOFF_HA
; break;
2058 case BFD_RELOC_CTOR
: r
= R_PPC_ADDR32
; break;
2059 case BFD_RELOC_PPC_TOC16
: r
= R_PPC_TOC16
; break;
2060 case BFD_RELOC_PPC_TLS
: r
= R_PPC_TLS
; break;
2061 case BFD_RELOC_PPC_DTPMOD
: r
= R_PPC_DTPMOD32
; break;
2062 case BFD_RELOC_PPC_TPREL16
: r
= R_PPC_TPREL16
; break;
2063 case BFD_RELOC_PPC_TPREL16_LO
: r
= R_PPC_TPREL16_LO
; break;
2064 case BFD_RELOC_PPC_TPREL16_HI
: r
= R_PPC_TPREL16_HI
; break;
2065 case BFD_RELOC_PPC_TPREL16_HA
: r
= R_PPC_TPREL16_HA
; break;
2066 case BFD_RELOC_PPC_TPREL
: r
= R_PPC_TPREL32
; break;
2067 case BFD_RELOC_PPC_DTPREL16
: r
= R_PPC_DTPREL16
; break;
2068 case BFD_RELOC_PPC_DTPREL16_LO
: r
= R_PPC_DTPREL16_LO
; break;
2069 case BFD_RELOC_PPC_DTPREL16_HI
: r
= R_PPC_DTPREL16_HI
; break;
2070 case BFD_RELOC_PPC_DTPREL16_HA
: r
= R_PPC_DTPREL16_HA
; break;
2071 case BFD_RELOC_PPC_DTPREL
: r
= R_PPC_DTPREL32
; break;
2072 case BFD_RELOC_PPC_GOT_TLSGD16
: r
= R_PPC_GOT_TLSGD16
; break;
2073 case BFD_RELOC_PPC_GOT_TLSGD16_LO
: r
= R_PPC_GOT_TLSGD16_LO
; break;
2074 case BFD_RELOC_PPC_GOT_TLSGD16_HI
: r
= R_PPC_GOT_TLSGD16_HI
; break;
2075 case BFD_RELOC_PPC_GOT_TLSGD16_HA
: r
= R_PPC_GOT_TLSGD16_HA
; break;
2076 case BFD_RELOC_PPC_GOT_TLSLD16
: r
= R_PPC_GOT_TLSLD16
; break;
2077 case BFD_RELOC_PPC_GOT_TLSLD16_LO
: r
= R_PPC_GOT_TLSLD16_LO
; break;
2078 case BFD_RELOC_PPC_GOT_TLSLD16_HI
: r
= R_PPC_GOT_TLSLD16_HI
; break;
2079 case BFD_RELOC_PPC_GOT_TLSLD16_HA
: r
= R_PPC_GOT_TLSLD16_HA
; break;
2080 case BFD_RELOC_PPC_GOT_TPREL16
: r
= R_PPC_GOT_TPREL16
; break;
2081 case BFD_RELOC_PPC_GOT_TPREL16_LO
: r
= R_PPC_GOT_TPREL16_LO
; break;
2082 case BFD_RELOC_PPC_GOT_TPREL16_HI
: r
= R_PPC_GOT_TPREL16_HI
; break;
2083 case BFD_RELOC_PPC_GOT_TPREL16_HA
: r
= R_PPC_GOT_TPREL16_HA
; break;
2084 case BFD_RELOC_PPC_GOT_DTPREL16
: r
= R_PPC_GOT_DTPREL16
; break;
2085 case BFD_RELOC_PPC_GOT_DTPREL16_LO
: r
= R_PPC_GOT_DTPREL16_LO
; break;
2086 case BFD_RELOC_PPC_GOT_DTPREL16_HI
: r
= R_PPC_GOT_DTPREL16_HI
; break;
2087 case BFD_RELOC_PPC_GOT_DTPREL16_HA
: r
= R_PPC_GOT_DTPREL16_HA
; break;
2088 case BFD_RELOC_PPC_EMB_NADDR32
: r
= R_PPC_EMB_NADDR32
; break;
2089 case BFD_RELOC_PPC_EMB_NADDR16
: r
= R_PPC_EMB_NADDR16
; break;
2090 case BFD_RELOC_PPC_EMB_NADDR16_LO
: r
= R_PPC_EMB_NADDR16_LO
; break;
2091 case BFD_RELOC_PPC_EMB_NADDR16_HI
: r
= R_PPC_EMB_NADDR16_HI
; break;
2092 case BFD_RELOC_PPC_EMB_NADDR16_HA
: r
= R_PPC_EMB_NADDR16_HA
; break;
2093 case BFD_RELOC_PPC_EMB_SDAI16
: r
= R_PPC_EMB_SDAI16
; break;
2094 case BFD_RELOC_PPC_EMB_SDA2I16
: r
= R_PPC_EMB_SDA2I16
; break;
2095 case BFD_RELOC_PPC_EMB_SDA2REL
: r
= R_PPC_EMB_SDA2REL
; break;
2096 case BFD_RELOC_PPC_EMB_SDA21
: r
= R_PPC_EMB_SDA21
; break;
2097 case BFD_RELOC_PPC_EMB_MRKREF
: r
= R_PPC_EMB_MRKREF
; break;
2098 case BFD_RELOC_PPC_EMB_RELSEC16
: r
= R_PPC_EMB_RELSEC16
; break;
2099 case BFD_RELOC_PPC_EMB_RELST_LO
: r
= R_PPC_EMB_RELST_LO
; break;
2100 case BFD_RELOC_PPC_EMB_RELST_HI
: r
= R_PPC_EMB_RELST_HI
; break;
2101 case BFD_RELOC_PPC_EMB_RELST_HA
: r
= R_PPC_EMB_RELST_HA
; break;
2102 case BFD_RELOC_PPC_EMB_BIT_FLD
: r
= R_PPC_EMB_BIT_FLD
; break;
2103 case BFD_RELOC_PPC_EMB_RELSDA
: r
= R_PPC_EMB_RELSDA
; break;
2104 case BFD_RELOC_VTABLE_INHERIT
: r
= R_PPC_GNU_VTINHERIT
; break;
2105 case BFD_RELOC_VTABLE_ENTRY
: r
= R_PPC_GNU_VTENTRY
; break;
2108 return ppc_elf_howto_table
[r
];
2111 /* Set the howto pointer for a PowerPC ELF reloc. */
2114 ppc_elf_info_to_howto (bfd
*abfd ATTRIBUTE_UNUSED
,
2116 Elf_Internal_Rela
*dst
)
2118 /* Initialize howto table if not already done. */
2119 if (!ppc_elf_howto_table
[R_PPC_ADDR32
])
2120 ppc_elf_howto_init ();
2122 BFD_ASSERT (ELF32_R_TYPE (dst
->r_info
) < (unsigned int) R_PPC_max
);
2123 cache_ptr
->howto
= ppc_elf_howto_table
[ELF32_R_TYPE (dst
->r_info
)];
2126 /* Handle the R_PPC_ADDR16_HA reloc. */
2128 static bfd_reloc_status_type
2129 ppc_elf_addr16_ha_reloc (bfd
*abfd ATTRIBUTE_UNUSED
,
2130 arelent
*reloc_entry
,
2132 void *data ATTRIBUTE_UNUSED
,
2133 asection
*input_section
,
2135 char **error_message ATTRIBUTE_UNUSED
)
2139 if (output_bfd
!= NULL
)
2141 reloc_entry
->address
+= input_section
->output_offset
;
2142 return bfd_reloc_ok
;
2145 if (reloc_entry
->address
> bfd_get_section_limit (abfd
, input_section
))
2146 return bfd_reloc_outofrange
;
2148 if (bfd_is_com_section (symbol
->section
))
2151 relocation
= symbol
->value
;
2153 relocation
+= symbol
->section
->output_section
->vma
;
2154 relocation
+= symbol
->section
->output_offset
;
2155 relocation
+= reloc_entry
->addend
;
2157 reloc_entry
->addend
+= (relocation
& 0x8000) << 1;
2159 return bfd_reloc_continue
;
2162 static bfd_reloc_status_type
2163 ppc_elf_unhandled_reloc (bfd
*abfd
,
2164 arelent
*reloc_entry
,
2167 asection
*input_section
,
2169 char **error_message
)
2171 /* If this is a relocatable link (output_bfd test tells us), just
2172 call the generic function. Any adjustment will be done at final
2174 if (output_bfd
!= NULL
)
2175 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2176 input_section
, output_bfd
, error_message
);
2178 if (error_message
!= NULL
)
2180 static char buf
[60];
2181 sprintf (buf
, _("generic linker can't handle %s"),
2182 reloc_entry
->howto
->name
);
2183 *error_message
= buf
;
2185 return bfd_reloc_dangerous
;
2188 /* Fix bad default arch selected for a 32 bit input bfd when the
2189 default is 64 bit. */
2192 ppc_elf_object_p (bfd
*abfd
)
2194 if (abfd
->arch_info
->the_default
&& abfd
->arch_info
->bits_per_word
== 64)
2196 Elf_Internal_Ehdr
*i_ehdr
= elf_elfheader (abfd
);
2198 if (i_ehdr
->e_ident
[EI_CLASS
] == ELFCLASS32
)
2200 /* Relies on arch after 64 bit default being 32 bit default. */
2201 abfd
->arch_info
= abfd
->arch_info
->next
;
2202 BFD_ASSERT (abfd
->arch_info
->bits_per_word
== 32);
2208 /* Function to set whether a module needs the -mrelocatable bit set. */
2211 ppc_elf_set_private_flags (bfd
*abfd
, flagword flags
)
2213 BFD_ASSERT (!elf_flags_init (abfd
)
2214 || elf_elfheader (abfd
)->e_flags
== flags
);
2216 elf_elfheader (abfd
)->e_flags
= flags
;
2217 elf_flags_init (abfd
) = TRUE
;
2221 /* Merge backend specific data from an object file to the output
2222 object file when linking. */
2225 ppc_elf_merge_private_bfd_data (bfd
*ibfd
, bfd
*obfd
)
2231 /* Check if we have the same endianess. */
2232 if (! _bfd_generic_verify_endian_match (ibfd
, obfd
))
2235 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
2236 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
2239 new_flags
= elf_elfheader (ibfd
)->e_flags
;
2240 old_flags
= elf_elfheader (obfd
)->e_flags
;
2241 if (!elf_flags_init (obfd
))
2243 /* First call, no flags set. */
2244 elf_flags_init (obfd
) = TRUE
;
2245 elf_elfheader (obfd
)->e_flags
= new_flags
;
2248 /* Compatible flags are ok. */
2249 else if (new_flags
== old_flags
)
2252 /* Incompatible flags. */
2255 /* Warn about -mrelocatable mismatch. Allow -mrelocatable-lib
2256 to be linked with either. */
2258 if ((new_flags
& EF_PPC_RELOCATABLE
) != 0
2259 && (old_flags
& (EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
)) == 0)
2262 (*_bfd_error_handler
)
2263 (_("%B: compiled with -mrelocatable and linked with "
2264 "modules compiled normally"), ibfd
);
2266 else if ((new_flags
& (EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
)) == 0
2267 && (old_flags
& EF_PPC_RELOCATABLE
) != 0)
2270 (*_bfd_error_handler
)
2271 (_("%B: compiled normally and linked with "
2272 "modules compiled with -mrelocatable"), ibfd
);
2275 /* The output is -mrelocatable-lib iff both the input files are. */
2276 if (! (new_flags
& EF_PPC_RELOCATABLE_LIB
))
2277 elf_elfheader (obfd
)->e_flags
&= ~EF_PPC_RELOCATABLE_LIB
;
2279 /* The output is -mrelocatable iff it can't be -mrelocatable-lib,
2280 but each input file is either -mrelocatable or -mrelocatable-lib. */
2281 if (! (elf_elfheader (obfd
)->e_flags
& EF_PPC_RELOCATABLE_LIB
)
2282 && (new_flags
& (EF_PPC_RELOCATABLE_LIB
| EF_PPC_RELOCATABLE
))
2283 && (old_flags
& (EF_PPC_RELOCATABLE_LIB
| EF_PPC_RELOCATABLE
)))
2284 elf_elfheader (obfd
)->e_flags
|= EF_PPC_RELOCATABLE
;
2286 /* Do not warn about eabi vs. V.4 mismatch, just or in the bit if
2287 any module uses it. */
2288 elf_elfheader (obfd
)->e_flags
|= (new_flags
& EF_PPC_EMB
);
2290 new_flags
&= ~(EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
| EF_PPC_EMB
);
2291 old_flags
&= ~(EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
| EF_PPC_EMB
);
2293 /* Warn about any other mismatches. */
2294 if (new_flags
!= old_flags
)
2297 (*_bfd_error_handler
)
2298 (_("%B: uses different e_flags (0x%lx) fields "
2299 "than previous modules (0x%lx)"),
2300 ibfd
, (long) new_flags
, (long) old_flags
);
2305 bfd_set_error (bfd_error_bad_value
);
2313 /* Handle a PowerPC specific section when reading an object file. This
2314 is called when elfcode.h finds a section with an unknown type. */
2317 ppc_elf_section_from_shdr (bfd
*abfd
, Elf_Internal_Shdr
*hdr
, const char *name
)
2322 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
))
2325 newsect
= hdr
->bfd_section
;
2326 flags
= bfd_get_section_flags (abfd
, newsect
);
2327 if (hdr
->sh_flags
& SHF_EXCLUDE
)
2328 flags
|= SEC_EXCLUDE
;
2330 if (hdr
->sh_type
== SHT_ORDERED
)
2331 flags
|= SEC_SORT_ENTRIES
;
2333 bfd_set_section_flags (abfd
, newsect
, flags
);
2337 /* Set up any other section flags and such that may be necessary. */
2340 ppc_elf_fake_sections (bfd
*abfd ATTRIBUTE_UNUSED
,
2341 Elf_Internal_Shdr
*shdr
,
2344 if ((asect
->flags
& SEC_EXCLUDE
) != 0)
2345 shdr
->sh_flags
|= SHF_EXCLUDE
;
2347 if ((asect
->flags
& SEC_SORT_ENTRIES
) != 0)
2348 shdr
->sh_type
= SHT_ORDERED
;
2353 /* Find a linker generated pointer with a given addend and type. */
2355 static elf_linker_section_pointers_t
*
2356 elf_find_pointer_linker_section
2357 (elf_linker_section_pointers_t
*linker_pointers
,
2359 elf_linker_section_t
*lsect
)
2361 for ( ; linker_pointers
!= NULL
; linker_pointers
= linker_pointers
->next
)
2362 if (lsect
== linker_pointers
->lsect
&& addend
== linker_pointers
->addend
)
2363 return linker_pointers
;
2368 /* Allocate a pointer to live in a linker created section. */
2371 elf_create_pointer_linker_section (bfd
*abfd
,
2372 struct bfd_link_info
*info
,
2373 elf_linker_section_t
*lsect
,
2374 struct elf_link_hash_entry
*h
,
2375 const Elf_Internal_Rela
*rel
)
2377 elf_linker_section_pointers_t
**ptr_linker_section_ptr
= NULL
;
2378 elf_linker_section_pointers_t
*linker_section_ptr
;
2379 unsigned long r_symndx
= ELF32_R_SYM (rel
->r_info
);
2382 BFD_ASSERT (lsect
!= NULL
);
2384 /* Is this a global symbol? */
2387 struct ppc_elf_link_hash_entry
*eh
;
2389 /* Has this symbol already been allocated? If so, our work is done. */
2390 eh
= (struct ppc_elf_link_hash_entry
*) h
;
2391 if (elf_find_pointer_linker_section (eh
->linker_section_pointer
,
2396 ptr_linker_section_ptr
= &eh
->linker_section_pointer
;
2397 /* Make sure this symbol is output as a dynamic symbol. */
2398 if (h
->dynindx
== -1)
2400 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
2404 if (lsect
->rel_section
)
2405 lsect
->rel_section
->size
+= sizeof (Elf32_External_Rela
);
2409 /* Allocation of a pointer to a local symbol. */
2410 elf_linker_section_pointers_t
**ptr
= elf_local_ptr_offsets (abfd
);
2412 /* Allocate a table to hold the local symbols if first time. */
2415 unsigned int num_symbols
= elf_tdata (abfd
)->symtab_hdr
.sh_info
;
2418 amt
*= sizeof (elf_linker_section_pointers_t
*);
2419 ptr
= bfd_zalloc (abfd
, amt
);
2424 elf_local_ptr_offsets (abfd
) = ptr
;
2427 /* Has this symbol already been allocated? If so, our work is done. */
2428 if (elf_find_pointer_linker_section (ptr
[r_symndx
],
2433 ptr_linker_section_ptr
= &ptr
[r_symndx
];
2437 /* If we are generating a shared object, we need to
2438 output a R_<xxx>_RELATIVE reloc so that the
2439 dynamic linker can adjust this GOT entry. */
2440 BFD_ASSERT (lsect
->rel_section
!= NULL
);
2441 lsect
->rel_section
->size
+= sizeof (Elf32_External_Rela
);
2445 /* Allocate space for a pointer in the linker section, and allocate
2446 a new pointer record from internal memory. */
2447 BFD_ASSERT (ptr_linker_section_ptr
!= NULL
);
2448 amt
= sizeof (elf_linker_section_pointers_t
);
2449 linker_section_ptr
= bfd_alloc (abfd
, amt
);
2451 if (!linker_section_ptr
)
2454 linker_section_ptr
->next
= *ptr_linker_section_ptr
;
2455 linker_section_ptr
->addend
= rel
->r_addend
;
2456 linker_section_ptr
->lsect
= lsect
;
2457 linker_section_ptr
->written_address_p
= FALSE
;
2458 *ptr_linker_section_ptr
= linker_section_ptr
;
2460 linker_section_ptr
->offset
= lsect
->section
->size
;
2461 lsect
->section
->size
+= 4;
2465 "Create pointer in linker section %s, offset = %ld, section size = %ld\n",
2466 lsect
->name
, (long) linker_section_ptr
->offset
,
2467 (long) lsect
->section
->size
);
2473 #define bfd_put_ptr(BFD, VAL, ADDR) bfd_put_32 (BFD, VAL, ADDR)
2475 /* Fill in the address for a pointer generated in a linker section. */
2478 elf_finish_pointer_linker_section (bfd
*output_bfd
,
2480 struct bfd_link_info
*info
,
2481 elf_linker_section_t
*lsect
,
2482 struct elf_link_hash_entry
*h
,
2484 const Elf_Internal_Rela
*rel
,
2487 elf_linker_section_pointers_t
*linker_section_ptr
;
2489 BFD_ASSERT (lsect
!= NULL
);
2493 /* Handle global symbol. */
2494 struct ppc_elf_link_hash_entry
*eh
;
2496 eh
= (struct ppc_elf_link_hash_entry
*) h
;
2498 = elf_find_pointer_linker_section (eh
->linker_section_pointer
,
2502 BFD_ASSERT (linker_section_ptr
!= NULL
);
2504 if (! elf_hash_table (info
)->dynamic_sections_created
2509 /* This is actually a static link, or it is a
2510 -Bsymbolic link and the symbol is defined
2511 locally. We must initialize this entry in the
2514 When doing a dynamic link, we create a .rela.<xxx>
2515 relocation entry to initialize the value. This
2516 is done in the finish_dynamic_symbol routine. */
2517 if (!linker_section_ptr
->written_address_p
)
2519 linker_section_ptr
->written_address_p
= TRUE
;
2520 bfd_put_ptr (output_bfd
,
2521 relocation
+ linker_section_ptr
->addend
,
2522 (lsect
->section
->contents
2523 + linker_section_ptr
->offset
));
2529 /* Handle local symbol. */
2530 unsigned long r_symndx
= ELF32_R_SYM (rel
->r_info
);
2531 BFD_ASSERT (elf_local_ptr_offsets (input_bfd
) != NULL
);
2532 BFD_ASSERT (elf_local_ptr_offsets (input_bfd
)[r_symndx
] != NULL
);
2533 linker_section_ptr
= (elf_find_pointer_linker_section
2534 (elf_local_ptr_offsets (input_bfd
)[r_symndx
],
2538 BFD_ASSERT (linker_section_ptr
!= NULL
);
2540 /* Write out pointer if it hasn't been rewritten out before. */
2541 if (!linker_section_ptr
->written_address_p
)
2543 linker_section_ptr
->written_address_p
= TRUE
;
2544 bfd_put_ptr (output_bfd
, relocation
+ linker_section_ptr
->addend
,
2545 lsect
->section
->contents
+ linker_section_ptr
->offset
);
2549 /* We need to generate a relative reloc for the dynamic
2552 asection
*srel
= lsect
->rel_section
;
2553 Elf_Internal_Rela outrel
[MAX_INT_RELS_PER_EXT_REL
];
2555 const struct elf_backend_data
*bed
;
2558 BFD_ASSERT (srel
!= NULL
);
2560 bed
= get_elf_backend_data (output_bfd
);
2561 for (i
= 0; i
< bed
->s
->int_rels_per_ext_rel
; i
++)
2563 outrel
[i
].r_offset
= (lsect
->section
->output_section
->vma
2564 + lsect
->section
->output_offset
2565 + linker_section_ptr
->offset
);
2566 outrel
[i
].r_info
= 0;
2567 outrel
[i
].r_addend
= 0;
2569 outrel
[0].r_info
= ELF32_R_INFO (0, relative_reloc
);
2570 erel
= lsect
->section
->contents
;
2571 erel
+= (elf_section_data (lsect
->section
)->rel_count
++
2572 * sizeof (Elf32_External_Rela
));
2573 bfd_elf32_swap_reloca_out (output_bfd
, outrel
, erel
);
2578 relocation
= (lsect
->section
->output_offset
2579 + linker_section_ptr
->offset
2580 - lsect
->sym_offset
);
2584 "Finish pointer in linker section %s, offset = %ld (0x%lx)\n",
2585 lsect
->name
, (long) relocation
, (long) relocation
);
2588 /* Subtract out the addend, because it will get added back in by the normal
2590 return relocation
- linker_section_ptr
->addend
;
2593 /* Create a special linker section */
2594 static elf_linker_section_t
*
2595 ppc_elf_create_linker_section (bfd
*abfd
,
2596 struct bfd_link_info
*info
,
2597 enum elf_linker_section_enum which
)
2599 elf_linker_section_t
*lsect
;
2600 struct ppc_elf_link_hash_table
*htab
= ppc_elf_hash_table (info
);
2601 asection
*s
, *sym_sec
;
2605 const char *rel_name
;
2606 const char *sym_name
;
2609 /* Both of these sections are (technically) created by the user
2610 putting data in them, so they shouldn't be marked
2613 The linker creates them so it has somewhere to attach their
2614 respective symbols. In fact, if they were empty it would
2615 be OK to leave the symbol set to 0 (or any random number), because
2616 the appropriate register should never be used. */
2617 flags
= SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
;
2626 case LINKER_SECTION_SDATA
: /* .sdata/.sbss section */
2628 rel_name
= ".rela.sdata";
2629 sym_name
= "_SDA_BASE_";
2632 case LINKER_SECTION_SDATA2
: /* .sdata2/.sbss2 section */
2634 rel_name
= ".rela.sdata2";
2635 sym_name
= "_SDA2_BASE_";
2636 flags
|= SEC_READONLY
;
2640 /* Record the first bfd that needs the special sections. */
2641 if (!htab
->elf
.dynobj
)
2642 htab
->elf
.dynobj
= abfd
;
2644 amt
= sizeof (elf_linker_section_t
);
2645 lsect
= bfd_zalloc (htab
->elf
.dynobj
, amt
);
2647 lsect
->sym_offset
= sym_offset
;
2649 /* See if the sections already exist. */
2650 sym_sec
= s
= bfd_get_section_by_name (htab
->elf
.dynobj
, name
);
2651 if (s
== NULL
|| (s
->flags
& flags
) != flags
)
2653 s
= bfd_make_section_anyway (htab
->elf
.dynobj
, name
);
2655 || !bfd_set_section_flags (htab
->elf
.dynobj
, s
, flags
))
2657 if (sym_sec
== NULL
)
2662 if (bfd_get_section_alignment (htab
->elf
.dynobj
, s
) < 2
2663 && !bfd_set_section_alignment (htab
->elf
.dynobj
, s
, 2))
2666 s
->size
= align_power (s
->size
, 2);
2669 fprintf (stderr
, "Creating section %s, current size = %ld\n",
2670 name
, (long) s
->size
);
2675 struct elf_link_hash_entry
*h
;
2676 struct bfd_link_hash_entry
*bh
;
2679 fprintf (stderr
, "Adding %s to section %s\n", sym_name
, name
);
2681 bh
= bfd_link_hash_lookup (info
->hash
, sym_name
,
2682 FALSE
, FALSE
, FALSE
);
2684 if ((bh
== NULL
|| bh
->type
== bfd_link_hash_undefined
)
2685 && !(_bfd_generic_link_add_one_symbol
2686 (info
, abfd
, sym_name
, BSF_GLOBAL
, sym_sec
, sym_offset
, NULL
,
2687 FALSE
, get_elf_backend_data (abfd
)->collect
, &bh
)))
2689 h
= (struct elf_link_hash_entry
*) bh
;
2691 h
->type
= STT_OBJECT
;
2692 lsect
->sym_hash
= h
;
2695 && ! bfd_elf_link_record_dynamic_symbol (info
, h
))
2701 s
= bfd_make_section_anyway (htab
->elf
.dynobj
, rel_name
);
2702 lsect
->rel_section
= s
;
2703 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
2704 | SEC_LINKER_CREATED
| SEC_READONLY
);
2706 || ! bfd_set_section_flags (htab
->elf
.dynobj
, s
, flags
)
2707 || ! bfd_set_section_alignment (htab
->elf
.dynobj
, s
, 2))
2714 /* If we have a non-zero sized .sbss2 or .PPC.EMB.sbss0 sections, we
2715 need to bump up the number of section headers. */
2718 ppc_elf_additional_program_headers (bfd
*abfd
)
2725 s
= bfd_get_section_by_name (abfd
, ".interp");
2729 s
= bfd_get_section_by_name (abfd
, ".sbss2");
2730 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0 && s
->size
> 0)
2733 s
= bfd_get_section_by_name (abfd
, ".PPC.EMB.sbss0");
2734 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0 && s
->size
> 0)
2740 /* The powerpc .got has a blrl instruction in it. Mark it executable. */
2743 ppc_elf_create_got (bfd
*abfd
, struct bfd_link_info
*info
)
2745 struct ppc_elf_link_hash_table
*htab
;
2749 if (!_bfd_elf_create_got_section (abfd
, info
))
2752 htab
= ppc_elf_hash_table (info
);
2753 htab
->got
= s
= bfd_get_section_by_name (abfd
, ".got");
2757 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_CODE
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
2758 | SEC_LINKER_CREATED
);
2759 if (!bfd_set_section_flags (abfd
, s
, flags
))
2762 htab
->relgot
= bfd_make_section (abfd
, ".rela.got");
2764 || ! bfd_set_section_flags (abfd
, htab
->relgot
,
2765 (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
2766 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
2768 || ! bfd_set_section_alignment (abfd
, htab
->relgot
, 2))
2774 /* We have to create .dynsbss and .rela.sbss here so that they get mapped
2775 to output sections (just like _bfd_elf_create_dynamic_sections has
2776 to create .dynbss and .rela.bss). */
2779 ppc_elf_create_dynamic_sections (bfd
*abfd
, struct bfd_link_info
*info
)
2781 struct ppc_elf_link_hash_table
*htab
;
2785 htab
= ppc_elf_hash_table (info
);
2787 if (htab
->got
== NULL
2788 && !ppc_elf_create_got (abfd
, info
))
2791 if (!_bfd_elf_create_dynamic_sections (abfd
, info
))
2794 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
2795 | SEC_LINKER_CREATED
);
2797 htab
->dynbss
= bfd_get_section_by_name (abfd
, ".dynbss");
2798 htab
->dynsbss
= s
= bfd_make_section (abfd
, ".dynsbss");
2800 || ! bfd_set_section_flags (abfd
, s
, SEC_ALLOC
| SEC_LINKER_CREATED
))
2805 htab
->relbss
= bfd_get_section_by_name (abfd
, ".rela.bss");
2806 htab
->relsbss
= s
= bfd_make_section (abfd
, ".rela.sbss");
2808 || ! bfd_set_section_flags (abfd
, s
, flags
| SEC_READONLY
)
2809 || ! bfd_set_section_alignment (abfd
, s
, 2))
2813 htab
->relplt
= bfd_get_section_by_name (abfd
, ".rela.plt");
2814 htab
->plt
= s
= bfd_get_section_by_name (abfd
, ".plt");
2818 flags
= SEC_ALLOC
| SEC_CODE
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
;
2819 return bfd_set_section_flags (abfd
, s
, flags
);
2822 /* Adjust a symbol defined by a dynamic object and referenced by a
2823 regular object. The current definition is in some section of the
2824 dynamic object, but we're not including those sections. We have to
2825 change the definition to something the rest of the link can
2829 ppc_elf_adjust_dynamic_symbol (struct bfd_link_info
*info
,
2830 struct elf_link_hash_entry
*h
)
2832 struct ppc_elf_link_hash_table
*htab
;
2834 unsigned int power_of_two
;
2837 fprintf (stderr
, "ppc_elf_adjust_dynamic_symbol called for %s\n",
2838 h
->root
.root
.string
);
2841 /* Make sure we know what is going on here. */
2842 htab
= ppc_elf_hash_table (info
);
2843 BFD_ASSERT (htab
->elf
.dynobj
!= NULL
2845 || h
->u
.weakdef
!= NULL
2848 && !h
->def_regular
)));
2850 /* Deal with function syms. */
2851 if (h
->type
== STT_FUNC
2854 /* Clear procedure linkage table information for any symbol that
2855 won't need a .plt entry. */
2856 if (h
->plt
.refcount
<= 0
2857 || SYMBOL_CALLS_LOCAL (info
, h
)
2858 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
2859 && h
->root
.type
== bfd_link_hash_undefweak
))
2861 /* A PLT entry is not required/allowed when:
2863 1. We are not using ld.so; because then the PLT entry
2864 can't be set up, so we can't use one. In this case,
2865 ppc_elf_adjust_dynamic_symbol won't even be called.
2867 2. GC has rendered the entry unused.
2869 3. We know for certain that a call to this symbol
2870 will go to this object, or will remain undefined. */
2871 h
->plt
.offset
= (bfd_vma
) -1;
2877 h
->plt
.offset
= (bfd_vma
) -1;
2879 /* If this is a weak symbol, and there is a real definition, the
2880 processor independent code will have arranged for us to see the
2881 real definition first, and we can just use the same value. */
2882 if (h
->u
.weakdef
!= NULL
)
2884 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
2885 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
2886 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
2887 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
2888 if (ELIMINATE_COPY_RELOCS
)
2889 h
->non_got_ref
= h
->u
.weakdef
->non_got_ref
;
2893 /* This is a reference to a symbol defined by a dynamic object which
2894 is not a function. */
2896 /* If we are creating a shared library, we must presume that the
2897 only references to the symbol are via the global offset table.
2898 For such cases we need not do anything here; the relocations will
2899 be handled correctly by relocate_section. */
2903 /* If there are no references to this symbol that do not use the
2904 GOT, we don't need to generate a copy reloc. */
2905 if (!h
->non_got_ref
)
2908 if (ELIMINATE_COPY_RELOCS
)
2910 struct ppc_elf_dyn_relocs
*p
;
2911 for (p
= ppc_elf_hash_entry (h
)->dyn_relocs
; p
!= NULL
; p
= p
->next
)
2913 s
= p
->sec
->output_section
;
2914 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
2918 /* If we didn't find any dynamic relocs in read-only sections, then
2919 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
2927 /* We must allocate the symbol in our .dynbss section, which will
2928 become part of the .bss section of the executable. There will be
2929 an entry for this symbol in the .dynsym section. The dynamic
2930 object will contain position independent code, so all references
2931 from the dynamic object to this symbol will go through the global
2932 offset table. The dynamic linker will use the .dynsym entry to
2933 determine the address it must put in the global offset table, so
2934 both the dynamic object and the regular object will refer to the
2935 same memory location for the variable.
2937 Of course, if the symbol is sufficiently small, we must instead
2938 allocate it in .sbss. FIXME: It would be better to do this if and
2939 only if there were actually SDAREL relocs for that symbol. */
2941 if (h
->size
<= elf_gp_size (htab
->elf
.dynobj
))
2945 BFD_ASSERT (s
!= NULL
);
2947 /* We must generate a R_PPC_COPY reloc to tell the dynamic linker to
2948 copy the initial value out of the dynamic object and into the
2949 runtime process image. We need to remember the offset into the
2950 .rela.bss section we are going to use. */
2951 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
2955 if (h
->size
<= elf_gp_size (htab
->elf
.dynobj
))
2956 srel
= htab
->relsbss
;
2958 srel
= htab
->relbss
;
2959 BFD_ASSERT (srel
!= NULL
);
2960 srel
->size
+= sizeof (Elf32_External_Rela
);
2964 /* We need to figure out the alignment required for this symbol. I
2965 have no idea how ELF linkers handle this. */
2966 power_of_two
= bfd_log2 (h
->size
);
2967 if (power_of_two
> 4)
2970 /* Apply the required alignment. */
2971 s
->size
= BFD_ALIGN (s
->size
, (bfd_size_type
) (1 << power_of_two
));
2972 if (power_of_two
> bfd_get_section_alignment (htab
->elf
.dynobj
, s
))
2974 if (! bfd_set_section_alignment (htab
->elf
.dynobj
, s
, power_of_two
))
2978 /* Define the symbol as being at this point in the section. */
2979 h
->root
.u
.def
.section
= s
;
2980 h
->root
.u
.def
.value
= s
->size
;
2982 /* Increment the section size to make room for the symbol. */
2988 /* Of those relocs that might be copied as dynamic relocs, this macro
2989 selects those that must be copied when linking a shared library,
2990 even when the symbol is local. */
2992 #define MUST_BE_DYN_RELOC(RTYPE) \
2993 ((RTYPE) != R_PPC_REL24 \
2994 && (RTYPE) != R_PPC_REL14 \
2995 && (RTYPE) != R_PPC_REL14_BRTAKEN \
2996 && (RTYPE) != R_PPC_REL14_BRNTAKEN \
2997 && (RTYPE) != R_PPC_REL32)
2999 /* Allocate space in associated reloc sections for dynamic relocs. */
3002 allocate_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
3004 struct bfd_link_info
*info
= inf
;
3005 struct ppc_elf_link_hash_entry
*eh
;
3006 struct ppc_elf_link_hash_table
*htab
;
3007 struct ppc_elf_dyn_relocs
*p
;
3009 if (h
->root
.type
== bfd_link_hash_indirect
)
3012 if (h
->root
.type
== bfd_link_hash_warning
)
3013 /* When warning symbols are created, they **replace** the "real"
3014 entry in the hash table, thus we never get to see the real
3015 symbol in a hash traversal. So look at it now. */
3016 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
3018 htab
= ppc_elf_hash_table (info
);
3019 if (htab
->elf
.dynamic_sections_created
3020 && h
->plt
.refcount
> 0)
3022 /* Make sure this symbol is output as a dynamic symbol. */
3023 if (h
->dynindx
== -1
3024 && !h
->forced_local
)
3026 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
3031 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h
))
3033 asection
*s
= htab
->plt
;
3035 /* If this is the first .plt entry, make room for the special
3038 s
->size
+= PLT_INITIAL_ENTRY_SIZE
;
3040 /* The PowerPC PLT is actually composed of two parts, the
3041 first part is 2 words (for a load and a jump), and then
3042 there is a remaining word available at the end. */
3043 h
->plt
.offset
= (PLT_INITIAL_ENTRY_SIZE
3045 * ((s
->size
- PLT_INITIAL_ENTRY_SIZE
)
3046 / PLT_ENTRY_SIZE
)));
3048 /* If this symbol is not defined in a regular file, and we
3049 are not generating a shared library, then set the symbol
3050 to this location in the .plt. This is required to make
3051 function pointers compare as equal between the normal
3052 executable and the shared library. */
3056 h
->root
.u
.def
.section
= s
;
3057 h
->root
.u
.def
.value
= h
->plt
.offset
;
3060 /* Make room for this entry. After the 8192nd entry, room
3061 for two entries is allocated. */
3062 s
->size
+= PLT_ENTRY_SIZE
;
3063 if ((s
->size
- PLT_INITIAL_ENTRY_SIZE
) / PLT_ENTRY_SIZE
3064 > PLT_NUM_SINGLE_ENTRIES
)
3065 s
->size
+= PLT_ENTRY_SIZE
;
3067 /* We also need to make an entry in the .rela.plt section. */
3068 htab
->relplt
->size
+= sizeof (Elf32_External_Rela
);
3072 h
->plt
.offset
= (bfd_vma
) -1;
3078 h
->plt
.offset
= (bfd_vma
) -1;
3082 eh
= (struct ppc_elf_link_hash_entry
*) h
;
3083 if (eh
->elf
.got
.refcount
> 0)
3085 /* Make sure this symbol is output as a dynamic symbol. */
3086 if (eh
->elf
.dynindx
== -1
3087 && !eh
->elf
.forced_local
)
3089 if (!bfd_elf_link_record_dynamic_symbol (info
, &eh
->elf
))
3093 if (eh
->tls_mask
== (TLS_TLS
| TLS_LD
)
3094 && !eh
->elf
.def_dynamic
)
3095 /* If just an LD reloc, we'll just use htab->tlsld_got.offset. */
3096 eh
->elf
.got
.offset
= (bfd_vma
) -1;
3100 eh
->elf
.got
.offset
= htab
->got
->size
;
3101 if ((eh
->tls_mask
& TLS_TLS
) != 0)
3103 if ((eh
->tls_mask
& TLS_LD
) != 0)
3104 htab
->got
->size
+= 8;
3105 if ((eh
->tls_mask
& TLS_GD
) != 0)
3106 htab
->got
->size
+= 8;
3107 if ((eh
->tls_mask
& (TLS_TPREL
| TLS_TPRELGD
)) != 0)
3108 htab
->got
->size
+= 4;
3109 if ((eh
->tls_mask
& TLS_DTPREL
) != 0)
3110 htab
->got
->size
+= 4;
3113 htab
->got
->size
+= 4;
3114 dyn
= htab
->elf
.dynamic_sections_created
;
3116 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, &eh
->elf
))
3117 && (ELF_ST_VISIBILITY (eh
->elf
.other
) == STV_DEFAULT
3118 || eh
->elf
.root
.type
!= bfd_link_hash_undefweak
))
3120 /* All the entries we allocated need relocs. */
3122 += ((htab
->got
->size
- eh
->elf
.got
.offset
) / 4
3123 * sizeof (Elf32_External_Rela
));
3124 /* Except LD only needs one. */
3125 if ((eh
->tls_mask
& TLS_LD
) != 0)
3126 htab
->relgot
->size
-= sizeof (Elf32_External_Rela
);
3131 eh
->elf
.got
.offset
= (bfd_vma
) -1;
3133 if (eh
->dyn_relocs
== NULL
)
3136 /* In the shared -Bsymbolic case, discard space allocated for
3137 dynamic pc-relative relocs against symbols which turn out to be
3138 defined in regular objects. For the normal shared case, discard
3139 space for relocs that have become local due to symbol visibility
3144 /* Relocs that use pc_count are those that appear on a call insn,
3145 or certain REL relocs (see MUST_BE_DYN_RELOC) that can be
3146 generated via assembly. We want calls to protected symbols to
3147 resolve directly to the function rather than going via the plt.
3148 If people want function pointer comparisons to work as expected
3149 then they should avoid writing weird assembly. */
3150 if (SYMBOL_CALLS_LOCAL (info
, h
))
3152 struct ppc_elf_dyn_relocs
**pp
;
3154 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
3156 p
->count
-= p
->pc_count
;
3165 /* Also discard relocs on undefined weak syms with non-default
3167 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
3168 && h
->root
.type
== bfd_link_hash_undefweak
)
3169 eh
->dyn_relocs
= NULL
;
3171 /* Make sure undefined weak symbols are output as a dynamic symbol
3174 && eh
->dyn_relocs
!= NULL
3176 && h
->root
.type
== bfd_link_hash_undefweak
3177 && !h
->forced_local
)
3179 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
3183 else if (ELIMINATE_COPY_RELOCS
)
3185 /* For the non-shared case, discard space for relocs against
3186 symbols which turn out to need copy relocs or are not
3193 /* Make sure this symbol is output as a dynamic symbol.
3194 Undefined weak syms won't yet be marked as dynamic. */
3195 if (h
->dynindx
== -1
3196 && !h
->forced_local
)
3198 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
3202 /* If that succeeded, we know we'll be keeping all the
3204 if (h
->dynindx
!= -1)
3208 eh
->dyn_relocs
= NULL
;
3213 /* Finally, allocate space. */
3214 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
3216 asection
*sreloc
= elf_section_data (p
->sec
)->sreloc
;
3217 sreloc
->size
+= p
->count
* sizeof (Elf32_External_Rela
);
3223 /* Find any dynamic relocs that apply to read-only sections. */
3226 readonly_dynrelocs (struct elf_link_hash_entry
*h
, void *info
)
3228 struct ppc_elf_dyn_relocs
*p
;
3230 if (h
->root
.type
== bfd_link_hash_indirect
)
3233 if (h
->root
.type
== bfd_link_hash_warning
)
3234 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
3236 for (p
= ppc_elf_hash_entry (h
)->dyn_relocs
; p
!= NULL
; p
= p
->next
)
3238 asection
*s
= p
->sec
->output_section
;
3241 && ((s
->flags
& (SEC_READONLY
| SEC_ALLOC
))
3242 == (SEC_READONLY
| SEC_ALLOC
)))
3244 ((struct bfd_link_info
*) info
)->flags
|= DF_TEXTREL
;
3246 /* Not an error, just cut short the traversal. */
3253 /* Set the sizes of the dynamic sections. */
3256 ppc_elf_size_dynamic_sections (bfd
*output_bfd ATTRIBUTE_UNUSED
,
3257 struct bfd_link_info
*info
)
3259 struct ppc_elf_link_hash_table
*htab
;
3265 fprintf (stderr
, "ppc_elf_size_dynamic_sections called\n");
3268 htab
= ppc_elf_hash_table (info
);
3269 BFD_ASSERT (htab
->elf
.dynobj
!= NULL
);
3271 if (elf_hash_table (info
)->dynamic_sections_created
)
3273 /* Set the contents of the .interp section to the interpreter. */
3274 if (info
->executable
)
3276 s
= bfd_get_section_by_name (htab
->elf
.dynobj
, ".interp");
3277 BFD_ASSERT (s
!= NULL
);
3278 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
3279 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
3283 if (htab
->tlsld_got
.refcount
> 0)
3285 htab
->tlsld_got
.offset
= htab
->got
->size
;
3286 htab
->got
->size
+= 8;
3288 htab
->relgot
->size
+= sizeof (Elf32_External_Rela
);
3291 htab
->tlsld_got
.offset
= (bfd_vma
) -1;
3293 /* Set up .got offsets for local syms, and space for local dynamic
3295 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
3297 bfd_signed_vma
*local_got
;
3298 bfd_signed_vma
*end_local_got
;
3300 bfd_size_type locsymcount
;
3301 Elf_Internal_Shdr
*symtab_hdr
;
3304 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
)
3307 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
3309 struct ppc_elf_dyn_relocs
*p
;
3311 for (p
= ((struct ppc_elf_dyn_relocs
*)
3312 elf_section_data (s
)->local_dynrel
);
3316 if (!bfd_is_abs_section (p
->sec
)
3317 && bfd_is_abs_section (p
->sec
->output_section
))
3319 /* Input section has been discarded, either because
3320 it is a copy of a linkonce section or due to
3321 linker script /DISCARD/, so we'll be discarding
3324 else if (p
->count
!= 0)
3326 elf_section_data (p
->sec
)->sreloc
->size
3327 += p
->count
* sizeof (Elf32_External_Rela
);
3328 if ((p
->sec
->output_section
->flags
3329 & (SEC_READONLY
| SEC_ALLOC
))
3330 == (SEC_READONLY
| SEC_ALLOC
))
3331 info
->flags
|= DF_TEXTREL
;
3336 local_got
= elf_local_got_refcounts (ibfd
);
3340 symtab_hdr
= &elf_tdata (ibfd
)->symtab_hdr
;
3341 locsymcount
= symtab_hdr
->sh_info
;
3342 end_local_got
= local_got
+ locsymcount
;
3343 lgot_masks
= (char *) end_local_got
;
3345 srel
= htab
->relgot
;
3346 for (; local_got
< end_local_got
; ++local_got
, ++lgot_masks
)
3349 if (*lgot_masks
== (TLS_TLS
| TLS_LD
))
3351 /* If just an LD reloc, we'll just use
3352 htab->tlsld_got.offset. */
3353 if (htab
->tlsld_got
.offset
== (bfd_vma
) -1)
3355 htab
->tlsld_got
.offset
= s
->size
;
3358 srel
->size
+= sizeof (Elf32_External_Rela
);
3360 *local_got
= (bfd_vma
) -1;
3364 *local_got
= s
->size
;
3365 if ((*lgot_masks
& TLS_TLS
) != 0)
3367 if ((*lgot_masks
& TLS_GD
) != 0)
3369 if ((*lgot_masks
& (TLS_TPREL
| TLS_TPRELGD
)) != 0)
3371 if ((*lgot_masks
& TLS_DTPREL
) != 0)
3377 srel
->size
+= ((s
->size
- *local_got
) / 4
3378 * sizeof (Elf32_External_Rela
));
3382 *local_got
= (bfd_vma
) -1;
3385 /* Allocate space for global sym dynamic relocs. */
3386 elf_link_hash_traverse (elf_hash_table (info
), allocate_dynrelocs
, info
);
3388 /* We've now determined the sizes of the various dynamic sections.
3389 Allocate memory for them. */
3391 for (s
= htab
->elf
.dynobj
->sections
; s
!= NULL
; s
= s
->next
)
3393 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
3398 || (htab
->sdata
!= NULL
&& s
== htab
->sdata
->section
)
3399 || (htab
->sdata2
!= NULL
&& s
== htab
->sdata2
->section
))
3401 /* Strip this section if we don't need it; see the
3404 else if (strncmp (bfd_get_section_name (dynobj
, s
), ".rela", 5) == 0)
3408 /* If we don't need this section, strip it from the
3409 output file. This is mostly to handle .rela.bss and
3410 .rela.plt. We must create both sections in
3411 create_dynamic_sections, because they must be created
3412 before the linker maps input sections to output
3413 sections. The linker does that before
3414 adjust_dynamic_symbol is called, and it is that
3415 function which decides whether anything needs to go
3416 into these sections. */
3420 /* Remember whether there are any relocation sections. */
3423 /* We use the reloc_count field as a counter if we need
3424 to copy relocs into the output file. */
3430 /* It's not one of our sections, so don't allocate space. */
3436 _bfd_strip_section_from_output (info
, s
);
3440 /* Allocate memory for the section contents. */
3441 s
->contents
= bfd_zalloc (htab
->elf
.dynobj
, s
->size
);
3442 if (s
->contents
== NULL
)
3446 if (htab
->elf
.dynamic_sections_created
)
3448 /* Add some entries to the .dynamic section. We fill in the
3449 values later, in ppc_elf_finish_dynamic_sections, but we
3450 must add the entries now so that we get the correct size for
3451 the .dynamic section. The DT_DEBUG entry is filled in by the
3452 dynamic linker and used by the debugger. */
3453 #define add_dynamic_entry(TAG, VAL) \
3454 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
3456 if (info
->executable
)
3458 if (!add_dynamic_entry (DT_DEBUG
, 0))
3462 if (htab
->plt
!= NULL
&& htab
->plt
->size
!= 0)
3464 if (!add_dynamic_entry (DT_PLTGOT
, 0)
3465 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
3466 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
3467 || !add_dynamic_entry (DT_JMPREL
, 0))
3473 if (!add_dynamic_entry (DT_RELA
, 0)
3474 || !add_dynamic_entry (DT_RELASZ
, 0)
3475 || !add_dynamic_entry (DT_RELAENT
, sizeof (Elf32_External_Rela
)))
3479 /* If any dynamic relocs apply to a read-only section, then we
3480 need a DT_TEXTREL entry. */
3481 if ((info
->flags
& DF_TEXTREL
) == 0)
3482 elf_link_hash_traverse (elf_hash_table (info
), readonly_dynrelocs
,
3485 if ((info
->flags
& DF_TEXTREL
) != 0)
3487 if (!add_dynamic_entry (DT_TEXTREL
, 0))
3491 #undef add_dynamic_entry
3497 update_local_sym_info (bfd
*abfd
,
3498 Elf_Internal_Shdr
*symtab_hdr
,
3499 unsigned long r_symndx
,
3502 bfd_signed_vma
*local_got_refcounts
= elf_local_got_refcounts (abfd
);
3503 char *local_got_tls_masks
;
3505 if (local_got_refcounts
== NULL
)
3507 bfd_size_type size
= symtab_hdr
->sh_info
;
3509 size
*= sizeof (*local_got_refcounts
) + sizeof (*local_got_tls_masks
);
3510 local_got_refcounts
= bfd_zalloc (abfd
, size
);
3511 if (local_got_refcounts
== NULL
)
3513 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
3516 local_got_refcounts
[r_symndx
] += 1;
3517 local_got_tls_masks
= (char *) (local_got_refcounts
+ symtab_hdr
->sh_info
);
3518 local_got_tls_masks
[r_symndx
] |= tls_type
;
3523 bad_shared_reloc (bfd
*abfd
, enum elf_ppc_reloc_type r_type
)
3525 (*_bfd_error_handler
)
3526 (_("%B: relocation %s cannot be used when making a shared object"),
3528 ppc_elf_howto_table
[r_type
]->name
);
3529 bfd_set_error (bfd_error_bad_value
);
3532 /* Look through the relocs for a section during the first phase, and
3533 allocate space in the global offset table or procedure linkage
3537 ppc_elf_check_relocs (bfd
*abfd
,
3538 struct bfd_link_info
*info
,
3540 const Elf_Internal_Rela
*relocs
)
3542 struct ppc_elf_link_hash_table
*htab
;
3543 Elf_Internal_Shdr
*symtab_hdr
;
3544 struct elf_link_hash_entry
**sym_hashes
;
3545 const Elf_Internal_Rela
*rel
;
3546 const Elf_Internal_Rela
*rel_end
;
3549 if (info
->relocatable
)
3553 _bfd_error_handler ("ppc_elf_check_relocs called for section %A in %B",
3557 /* Initialize howto table if not already done. */
3558 if (!ppc_elf_howto_table
[R_PPC_ADDR32
])
3559 ppc_elf_howto_init ();
3561 /* Create the linker generated sections all the time so that the
3562 special symbols are created. */
3563 htab
= ppc_elf_hash_table (info
);
3564 if (htab
->sdata
== NULL
)
3566 htab
->sdata
= ppc_elf_create_linker_section (abfd
, info
,
3567 LINKER_SECTION_SDATA
);
3568 if (htab
->sdata
== NULL
)
3572 if (htab
->sdata2
== NULL
)
3574 htab
->sdata2
= ppc_elf_create_linker_section (abfd
, info
,
3575 LINKER_SECTION_SDATA2
);
3576 if (htab
->sdata2
== NULL
)
3580 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
3581 sym_hashes
= elf_sym_hashes (abfd
);
3584 rel_end
= relocs
+ sec
->reloc_count
;
3585 for (rel
= relocs
; rel
< rel_end
; rel
++)
3587 unsigned long r_symndx
;
3588 enum elf_ppc_reloc_type r_type
;
3589 struct elf_link_hash_entry
*h
;
3592 r_symndx
= ELF32_R_SYM (rel
->r_info
);
3593 if (r_symndx
< symtab_hdr
->sh_info
)
3596 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
3598 /* If a relocation refers to _GLOBAL_OFFSET_TABLE_, create the .got.
3599 This shows up in particular in an R_PPC_ADDR32 in the eabi
3601 if (h
&& strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
3603 if (htab
->got
== NULL
)
3605 if (htab
->elf
.dynobj
== NULL
)
3606 htab
->elf
.dynobj
= abfd
;
3607 if (!ppc_elf_create_got (htab
->elf
.dynobj
, info
))
3612 r_type
= ELF32_R_TYPE (rel
->r_info
);
3615 case R_PPC_GOT_TLSLD16
:
3616 case R_PPC_GOT_TLSLD16_LO
:
3617 case R_PPC_GOT_TLSLD16_HI
:
3618 case R_PPC_GOT_TLSLD16_HA
:
3619 htab
->tlsld_got
.refcount
+= 1;
3620 tls_type
= TLS_TLS
| TLS_LD
;
3623 case R_PPC_GOT_TLSGD16
:
3624 case R_PPC_GOT_TLSGD16_LO
:
3625 case R_PPC_GOT_TLSGD16_HI
:
3626 case R_PPC_GOT_TLSGD16_HA
:
3627 tls_type
= TLS_TLS
| TLS_GD
;
3630 case R_PPC_GOT_TPREL16
:
3631 case R_PPC_GOT_TPREL16_LO
:
3632 case R_PPC_GOT_TPREL16_HI
:
3633 case R_PPC_GOT_TPREL16_HA
:
3635 info
->flags
|= DF_STATIC_TLS
;
3636 tls_type
= TLS_TLS
| TLS_TPREL
;
3639 case R_PPC_GOT_DTPREL16
:
3640 case R_PPC_GOT_DTPREL16_LO
:
3641 case R_PPC_GOT_DTPREL16_HI
:
3642 case R_PPC_GOT_DTPREL16_HA
:
3643 tls_type
= TLS_TLS
| TLS_DTPREL
;
3645 sec
->has_tls_reloc
= 1;
3648 /* GOT16 relocations */
3650 case R_PPC_GOT16_LO
:
3651 case R_PPC_GOT16_HI
:
3652 case R_PPC_GOT16_HA
:
3653 /* This symbol requires a global offset table entry. */
3654 if (htab
->got
== NULL
)
3656 if (htab
->elf
.dynobj
== NULL
)
3657 htab
->elf
.dynobj
= abfd
;
3658 if (!ppc_elf_create_got (htab
->elf
.dynobj
, info
))
3663 h
->got
.refcount
+= 1;
3664 ppc_elf_hash_entry (h
)->tls_mask
|= tls_type
;
3667 /* This is a global offset table entry for a local symbol. */
3668 if (!update_local_sym_info (abfd
, symtab_hdr
, r_symndx
, tls_type
))
3672 /* Indirect .sdata relocation. */
3673 case R_PPC_EMB_SDAI16
:
3676 bad_shared_reloc (abfd
, r_type
);
3679 if (!elf_create_pointer_linker_section (abfd
, info
,
3680 htab
->sdata
, h
, rel
))
3684 /* Indirect .sdata2 relocation. */
3685 case R_PPC_EMB_SDA2I16
:
3688 bad_shared_reloc (abfd
, r_type
);
3691 if (!elf_create_pointer_linker_section (abfd
, info
,
3692 htab
->sdata2
, h
, rel
))
3696 case R_PPC_SDAREL16
:
3697 case R_PPC_EMB_SDA2REL
:
3698 case R_PPC_EMB_SDA21
:
3699 case R_PPC_EMB_RELSDA
:
3700 case R_PPC_EMB_NADDR32
:
3701 case R_PPC_EMB_NADDR16
:
3702 case R_PPC_EMB_NADDR16_LO
:
3703 case R_PPC_EMB_NADDR16_HI
:
3704 case R_PPC_EMB_NADDR16_HA
:
3707 bad_shared_reloc (abfd
, r_type
);
3713 case R_PPC_PLTREL24
:
3714 case R_PPC_PLTREL32
:
3715 case R_PPC_PLT16_LO
:
3716 case R_PPC_PLT16_HI
:
3717 case R_PPC_PLT16_HA
:
3719 fprintf (stderr
, "Reloc requires a PLT entry\n");
3721 /* This symbol requires a procedure linkage table entry. We
3722 actually build the entry in finish_dynamic_symbol,
3723 because this might be a case of linking PIC code without
3724 linking in any dynamic objects, in which case we don't
3725 need to generate a procedure linkage table after all. */
3729 /* It does not make sense to have a procedure linkage
3730 table entry for a local symbol. */
3731 (*_bfd_error_handler
) (_("%B(%A+0x%lx): %s reloc against "
3735 (long) rel
->r_offset
,
3736 ppc_elf_howto_table
[r_type
]->name
);
3737 bfd_set_error (bfd_error_bad_value
);
3745 /* The following relocations don't need to propagate the
3746 relocation if linking a shared object since they are
3747 section relative. */
3749 case R_PPC_SECTOFF_LO
:
3750 case R_PPC_SECTOFF_HI
:
3751 case R_PPC_SECTOFF_HA
:
3752 case R_PPC_DTPREL16
:
3753 case R_PPC_DTPREL16_LO
:
3754 case R_PPC_DTPREL16_HI
:
3755 case R_PPC_DTPREL16_HA
:
3759 /* This are just markers. */
3761 case R_PPC_EMB_MRKREF
:
3766 /* These should only appear in dynamic objects. */
3768 case R_PPC_GLOB_DAT
:
3769 case R_PPC_JMP_SLOT
:
3770 case R_PPC_RELATIVE
:
3773 /* These aren't handled yet. We'll report an error later. */
3775 case R_PPC_EMB_RELSEC16
:
3776 case R_PPC_EMB_RELST_LO
:
3777 case R_PPC_EMB_RELST_HI
:
3778 case R_PPC_EMB_RELST_HA
:
3779 case R_PPC_EMB_BIT_FLD
:
3782 /* This refers only to functions defined in the shared library. */
3783 case R_PPC_LOCAL24PC
:
3786 /* This relocation describes the C++ object vtable hierarchy.
3787 Reconstruct it for later use during GC. */
3788 case R_PPC_GNU_VTINHERIT
:
3789 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
3793 /* This relocation describes which C++ vtable entries are actually
3794 used. Record for later use during GC. */
3795 case R_PPC_GNU_VTENTRY
:
3796 if (!bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
3800 /* We shouldn't really be seeing these. */
3803 info
->flags
|= DF_STATIC_TLS
;
3807 case R_PPC_DTPMOD32
:
3808 case R_PPC_DTPREL32
:
3812 case R_PPC_TPREL16_LO
:
3813 case R_PPC_TPREL16_HI
:
3814 case R_PPC_TPREL16_HA
:
3816 info
->flags
|= DF_STATIC_TLS
;
3819 /* When creating a shared object, we must copy these
3820 relocs into the output file. We create a reloc
3821 section in dynobj and make room for the reloc. */
3824 case R_PPC_REL14_BRTAKEN
:
3825 case R_PPC_REL14_BRNTAKEN
:
3828 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
3835 case R_PPC_ADDR16_LO
:
3836 case R_PPC_ADDR16_HI
:
3837 case R_PPC_ADDR16_HA
:
3839 case R_PPC_ADDR14_BRTAKEN
:
3840 case R_PPC_ADDR14_BRNTAKEN
:
3843 if (h
!= NULL
&& !info
->shared
)
3845 /* We may need a plt entry if the symbol turns out to be
3846 a function defined in a dynamic object. */
3849 /* We may need a copy reloc too. */
3854 /* If we are creating a shared library, and this is a reloc
3855 against a global symbol, or a non PC relative reloc
3856 against a local symbol, then we need to copy the reloc
3857 into the shared library. However, if we are linking with
3858 -Bsymbolic, we do not need to copy a reloc against a
3859 global symbol which is defined in an object we are
3860 including in the link (i.e., DEF_REGULAR is set). At
3861 this point we have not seen all the input files, so it is
3862 possible that DEF_REGULAR is not set now but will be set
3863 later (it is never cleared). In case of a weak definition,
3864 DEF_REGULAR may be cleared later by a strong definition in
3865 a shared library. We account for that possibility below by
3866 storing information in the dyn_relocs field of the hash
3867 table entry. A similar situation occurs when creating
3868 shared libraries and symbol visibility changes render the
3871 If on the other hand, we are creating an executable, we
3872 may need to keep relocations for symbols satisfied by a
3873 dynamic library if we manage to avoid copy relocs for the
3876 && (MUST_BE_DYN_RELOC (r_type
)
3878 && (! info
->symbolic
3879 || h
->root
.type
== bfd_link_hash_defweak
3880 || !h
->def_regular
))))
3881 || (ELIMINATE_COPY_RELOCS
3883 && (sec
->flags
& SEC_ALLOC
) != 0
3885 && (h
->root
.type
== bfd_link_hash_defweak
3886 || !h
->def_regular
)))
3888 struct ppc_elf_dyn_relocs
*p
;
3889 struct ppc_elf_dyn_relocs
**head
;
3893 "ppc_elf_check_relocs needs to "
3894 "create relocation for %s\n",
3895 (h
&& h
->root
.root
.string
3896 ? h
->root
.root
.string
: "<unknown>"));
3902 name
= (bfd_elf_string_from_elf_section
3904 elf_elfheader (abfd
)->e_shstrndx
,
3905 elf_section_data (sec
)->rel_hdr
.sh_name
));
3909 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
3910 && strcmp (bfd_get_section_name (abfd
, sec
),
3913 sreloc
= bfd_get_section_by_name (htab
->elf
.dynobj
, name
);
3918 sreloc
= bfd_make_section (htab
->elf
.dynobj
, name
);
3919 flags
= (SEC_HAS_CONTENTS
| SEC_READONLY
3920 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
3921 if ((sec
->flags
& SEC_ALLOC
) != 0)
3922 flags
|= SEC_ALLOC
| SEC_LOAD
;
3924 || ! bfd_set_section_flags (htab
->elf
.dynobj
,
3926 || ! bfd_set_section_alignment (htab
->elf
.dynobj
,
3930 elf_section_data (sec
)->sreloc
= sreloc
;
3933 /* If this is a global symbol, we count the number of
3934 relocations we need for this symbol. */
3937 head
= &ppc_elf_hash_entry (h
)->dyn_relocs
;
3941 /* Track dynamic relocs needed for local syms too.
3942 We really need local syms available to do this
3946 s
= bfd_section_from_r_symndx (abfd
, &htab
->sym_sec
,
3951 head
= ((struct ppc_elf_dyn_relocs
**)
3952 &elf_section_data (s
)->local_dynrel
);
3956 if (p
== NULL
|| p
->sec
!= sec
)
3958 p
= bfd_alloc (htab
->elf
.dynobj
, sizeof *p
);
3969 if (!MUST_BE_DYN_RELOC (r_type
))
3980 /* Return the section that should be marked against GC for a given
3984 ppc_elf_gc_mark_hook (asection
*sec
,
3985 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
3986 Elf_Internal_Rela
*rel
,
3987 struct elf_link_hash_entry
*h
,
3988 Elf_Internal_Sym
*sym
)
3992 switch (ELF32_R_TYPE (rel
->r_info
))
3994 case R_PPC_GNU_VTINHERIT
:
3995 case R_PPC_GNU_VTENTRY
:
3999 switch (h
->root
.type
)
4001 case bfd_link_hash_defined
:
4002 case bfd_link_hash_defweak
:
4003 return h
->root
.u
.def
.section
;
4005 case bfd_link_hash_common
:
4006 return h
->root
.u
.c
.p
->section
;
4014 return bfd_section_from_elf_index (sec
->owner
, sym
->st_shndx
);
4019 /* Update the got, plt and dynamic reloc reference counts for the
4020 section being removed. */
4023 ppc_elf_gc_sweep_hook (bfd
*abfd
,
4024 struct bfd_link_info
*info
,
4026 const Elf_Internal_Rela
*relocs
)
4028 struct ppc_elf_link_hash_table
*htab
;
4029 Elf_Internal_Shdr
*symtab_hdr
;
4030 struct elf_link_hash_entry
**sym_hashes
;
4031 bfd_signed_vma
*local_got_refcounts
;
4032 const Elf_Internal_Rela
*rel
, *relend
;
4034 elf_section_data (sec
)->local_dynrel
= NULL
;
4036 htab
= ppc_elf_hash_table (info
);
4037 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
4038 sym_hashes
= elf_sym_hashes (abfd
);
4039 local_got_refcounts
= elf_local_got_refcounts (abfd
);
4041 relend
= relocs
+ sec
->reloc_count
;
4042 for (rel
= relocs
; rel
< relend
; rel
++)
4044 unsigned long r_symndx
;
4045 enum elf_ppc_reloc_type r_type
;
4046 struct elf_link_hash_entry
*h
= NULL
;
4048 r_symndx
= ELF32_R_SYM (rel
->r_info
);
4049 if (r_symndx
>= symtab_hdr
->sh_info
)
4051 struct ppc_elf_dyn_relocs
**pp
, *p
;
4052 struct ppc_elf_link_hash_entry
*eh
;
4054 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
4055 while (h
->root
.type
== bfd_link_hash_indirect
4056 || h
->root
.type
== bfd_link_hash_warning
)
4057 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
4058 eh
= (struct ppc_elf_link_hash_entry
*) h
;
4060 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; pp
= &p
->next
)
4063 /* Everything must go for SEC. */
4069 r_type
= ELF32_R_TYPE (rel
->r_info
);
4072 case R_PPC_GOT_TLSLD16
:
4073 case R_PPC_GOT_TLSLD16_LO
:
4074 case R_PPC_GOT_TLSLD16_HI
:
4075 case R_PPC_GOT_TLSLD16_HA
:
4076 htab
->tlsld_got
.refcount
-= 1;
4079 case R_PPC_GOT_TLSGD16
:
4080 case R_PPC_GOT_TLSGD16_LO
:
4081 case R_PPC_GOT_TLSGD16_HI
:
4082 case R_PPC_GOT_TLSGD16_HA
:
4083 case R_PPC_GOT_TPREL16
:
4084 case R_PPC_GOT_TPREL16_LO
:
4085 case R_PPC_GOT_TPREL16_HI
:
4086 case R_PPC_GOT_TPREL16_HA
:
4087 case R_PPC_GOT_DTPREL16
:
4088 case R_PPC_GOT_DTPREL16_LO
:
4089 case R_PPC_GOT_DTPREL16_HI
:
4090 case R_PPC_GOT_DTPREL16_HA
:
4092 case R_PPC_GOT16_LO
:
4093 case R_PPC_GOT16_HI
:
4094 case R_PPC_GOT16_HA
:
4097 if (h
->got
.refcount
> 0)
4100 else if (local_got_refcounts
!= NULL
)
4102 if (local_got_refcounts
[r_symndx
] > 0)
4103 local_got_refcounts
[r_symndx
]--;
4109 case R_PPC_REL14_BRTAKEN
:
4110 case R_PPC_REL14_BRNTAKEN
:
4113 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
4120 case R_PPC_ADDR16_LO
:
4121 case R_PPC_ADDR16_HI
:
4122 case R_PPC_ADDR16_HA
:
4124 case R_PPC_ADDR14_BRTAKEN
:
4125 case R_PPC_ADDR14_BRNTAKEN
:
4129 case R_PPC_PLTREL24
:
4130 case R_PPC_PLT16_LO
:
4131 case R_PPC_PLT16_HI
:
4132 case R_PPC_PLT16_HA
:
4135 if (h
->plt
.refcount
> 0)
4147 /* Set htab->tls_get_addr and call the generic ELF tls_setup function. */
4150 ppc_elf_tls_setup (bfd
*obfd
, struct bfd_link_info
*info
)
4152 struct ppc_elf_link_hash_table
*htab
;
4154 htab
= ppc_elf_hash_table (info
);
4155 htab
->tls_get_addr
= elf_link_hash_lookup (&htab
->elf
, "__tls_get_addr",
4156 FALSE
, FALSE
, TRUE
);
4158 return _bfd_elf_tls_setup (obfd
, info
);
4161 /* Run through all the TLS relocs looking for optimization
4165 ppc_elf_tls_optimize (bfd
*obfd ATTRIBUTE_UNUSED
,
4166 struct bfd_link_info
*info
)
4170 struct ppc_elf_link_hash_table
*htab
;
4172 if (info
->relocatable
|| info
->shared
)
4175 htab
= ppc_elf_hash_table (info
);
4176 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
4178 Elf_Internal_Sym
*locsyms
= NULL
;
4179 Elf_Internal_Shdr
*symtab_hdr
= &elf_tdata (ibfd
)->symtab_hdr
;
4181 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
4182 if (sec
->has_tls_reloc
&& !bfd_is_abs_section (sec
->output_section
))
4184 Elf_Internal_Rela
*relstart
, *rel
, *relend
;
4185 int expecting_tls_get_addr
;
4187 /* Read the relocations. */
4188 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
4190 if (relstart
== NULL
)
4193 expecting_tls_get_addr
= 0;
4194 relend
= relstart
+ sec
->reloc_count
;
4195 for (rel
= relstart
; rel
< relend
; rel
++)
4197 enum elf_ppc_reloc_type r_type
;
4198 unsigned long r_symndx
;
4199 struct elf_link_hash_entry
*h
= NULL
;
4201 char tls_set
, tls_clear
;
4202 bfd_boolean is_local
;
4204 r_symndx
= ELF32_R_SYM (rel
->r_info
);
4205 if (r_symndx
>= symtab_hdr
->sh_info
)
4207 struct elf_link_hash_entry
**sym_hashes
;
4209 sym_hashes
= elf_sym_hashes (ibfd
);
4210 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
4211 while (h
->root
.type
== bfd_link_hash_indirect
4212 || h
->root
.type
== bfd_link_hash_warning
)
4213 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
4221 r_type
= ELF32_R_TYPE (rel
->r_info
);
4224 case R_PPC_GOT_TLSLD16
:
4225 case R_PPC_GOT_TLSLD16_LO
:
4226 case R_PPC_GOT_TLSLD16_HI
:
4227 case R_PPC_GOT_TLSLD16_HA
:
4228 /* These relocs should never be against a symbol
4229 defined in a shared lib. Leave them alone if
4230 that turns out to be the case. */
4231 expecting_tls_get_addr
= 0;
4232 htab
->tlsld_got
.refcount
-= 1;
4239 expecting_tls_get_addr
= 1;
4242 case R_PPC_GOT_TLSGD16
:
4243 case R_PPC_GOT_TLSGD16_LO
:
4244 case R_PPC_GOT_TLSGD16_HI
:
4245 case R_PPC_GOT_TLSGD16_HA
:
4251 tls_set
= TLS_TLS
| TLS_TPRELGD
;
4253 expecting_tls_get_addr
= 1;
4256 case R_PPC_GOT_TPREL16
:
4257 case R_PPC_GOT_TPREL16_LO
:
4258 case R_PPC_GOT_TPREL16_HI
:
4259 case R_PPC_GOT_TPREL16_HA
:
4260 expecting_tls_get_addr
= 0;
4265 tls_clear
= TLS_TPREL
;
4272 case R_PPC_REL14_BRTAKEN
:
4273 case R_PPC_REL14_BRNTAKEN
:
4275 if (expecting_tls_get_addr
4277 && h
== htab
->tls_get_addr
)
4279 if (h
->plt
.refcount
> 0)
4280 h
->plt
.refcount
-= 1;
4282 expecting_tls_get_addr
= 0;
4286 expecting_tls_get_addr
= 0;
4294 /* We managed to get rid of a got entry. */
4295 if (h
->got
.refcount
> 0)
4296 h
->got
.refcount
-= 1;
4298 tls_mask
= &ppc_elf_hash_entry (h
)->tls_mask
;
4302 Elf_Internal_Sym
*sym
;
4303 bfd_signed_vma
*lgot_refs
;
4306 if (locsyms
== NULL
)
4308 locsyms
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
4309 if (locsyms
== NULL
)
4310 locsyms
= bfd_elf_get_elf_syms (ibfd
, symtab_hdr
,
4311 symtab_hdr
->sh_info
,
4312 0, NULL
, NULL
, NULL
);
4313 if (locsyms
== NULL
)
4315 if (elf_section_data (sec
)->relocs
!= relstart
)
4320 sym
= locsyms
+ r_symndx
;
4321 lgot_refs
= elf_local_got_refcounts (ibfd
);
4322 if (lgot_refs
== NULL
)
4326 /* We managed to get rid of a got entry. */
4327 if (lgot_refs
[r_symndx
] > 0)
4328 lgot_refs
[r_symndx
] -= 1;
4330 lgot_masks
= (char *) (lgot_refs
+ symtab_hdr
->sh_info
);
4331 tls_mask
= &lgot_masks
[r_symndx
];
4334 *tls_mask
|= tls_set
;
4335 *tls_mask
&= ~tls_clear
;
4338 if (elf_section_data (sec
)->relocs
!= relstart
)
4343 && (symtab_hdr
->contents
!= (unsigned char *) locsyms
))
4345 if (!info
->keep_memory
)
4348 symtab_hdr
->contents
= (unsigned char *) locsyms
;
4354 /* Hook called by the linker routine which adds symbols from an object
4355 file. We use it to put .comm items in .sbss, and not .bss. */
4358 ppc_elf_add_symbol_hook (bfd
*abfd
,
4359 struct bfd_link_info
*info
,
4360 Elf_Internal_Sym
*sym
,
4361 const char **namep ATTRIBUTE_UNUSED
,
4362 flagword
*flagsp ATTRIBUTE_UNUSED
,
4366 if (sym
->st_shndx
== SHN_COMMON
4367 && !info
->relocatable
4368 && sym
->st_size
<= elf_gp_size (abfd
)
4369 && (info
->hash
->creator
== abfd
->xvec
4370 || info
->hash
->creator
== abfd
->xvec
->alternative_target
))
4372 /* Common symbols less than or equal to -G nn bytes are automatically
4374 struct ppc_elf_link_hash_table
*htab
;
4376 htab
= ppc_elf_hash_table (info
);
4377 if (htab
->sbss
== NULL
)
4379 flagword flags
= SEC_IS_COMMON
;
4381 htab
->sbss
= bfd_make_section_anyway (abfd
, ".sbss");
4382 if (htab
->sbss
== NULL
4383 || ! bfd_set_section_flags (abfd
, htab
->sbss
, flags
))
4388 *valp
= sym
->st_size
;
4394 /* Finish up dynamic symbol handling. We set the contents of various
4395 dynamic sections here. */
4398 ppc_elf_finish_dynamic_symbol (bfd
*output_bfd
,
4399 struct bfd_link_info
*info
,
4400 struct elf_link_hash_entry
*h
,
4401 Elf_Internal_Sym
*sym
)
4403 struct ppc_elf_link_hash_table
*htab
;
4406 fprintf (stderr
, "ppc_elf_finish_dynamic_symbol called for %s",
4407 h
->root
.root
.string
);
4410 htab
= ppc_elf_hash_table (info
);
4411 BFD_ASSERT (htab
->elf
.dynobj
!= NULL
);
4413 if (h
->plt
.offset
!= (bfd_vma
) -1)
4415 Elf_Internal_Rela rela
;
4417 bfd_vma reloc_index
;
4420 fprintf (stderr
, ", plt_offset = %d", h
->plt
.offset
);
4423 /* This symbol has an entry in the procedure linkage table. Set
4426 BFD_ASSERT (h
->dynindx
!= -1);
4427 BFD_ASSERT (htab
->plt
!= NULL
&& htab
->relplt
!= NULL
);
4429 /* We don't need to fill in the .plt. The ppc dynamic linker
4432 /* Fill in the entry in the .rela.plt section. */
4433 rela
.r_offset
= (htab
->plt
->output_section
->vma
4434 + htab
->plt
->output_offset
4436 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_PPC_JMP_SLOT
);
4439 reloc_index
= (h
->plt
.offset
- PLT_INITIAL_ENTRY_SIZE
) / PLT_SLOT_SIZE
;
4440 if (reloc_index
> PLT_NUM_SINGLE_ENTRIES
)
4441 reloc_index
-= (reloc_index
- PLT_NUM_SINGLE_ENTRIES
) / 2;
4442 loc
= (htab
->relplt
->contents
4443 + reloc_index
* sizeof (Elf32_External_Rela
));
4444 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
4446 if (!h
->def_regular
)
4448 /* Mark the symbol as undefined, rather than as defined in
4449 the .plt section. Leave the value alone. */
4450 sym
->st_shndx
= SHN_UNDEF
;
4451 /* If the symbol is weak, we do need to clear the value.
4452 Otherwise, the PLT entry would provide a definition for
4453 the symbol even if the symbol wasn't defined anywhere,
4454 and so the symbol would never be NULL. */
4455 if (!h
->ref_regular_nonweak
)
4463 Elf_Internal_Rela rela
;
4466 /* This symbols needs a copy reloc. Set it up. */
4469 fprintf (stderr
, ", copy");
4472 BFD_ASSERT (h
->dynindx
!= -1);
4474 if (h
->size
<= elf_gp_size (htab
->elf
.dynobj
))
4478 BFD_ASSERT (s
!= NULL
);
4480 rela
.r_offset
= (h
->root
.u
.def
.value
4481 + h
->root
.u
.def
.section
->output_section
->vma
4482 + h
->root
.u
.def
.section
->output_offset
);
4483 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_PPC_COPY
);
4485 loc
= s
->contents
+ s
->reloc_count
++ * sizeof (Elf32_External_Rela
);
4486 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
4490 fprintf (stderr
, "\n");
4493 /* Mark some specially defined symbols as absolute. */
4494 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
4495 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0
4496 || strcmp (h
->root
.root
.string
, "_PROCEDURE_LINKAGE_TABLE_") == 0)
4497 sym
->st_shndx
= SHN_ABS
;
4502 /* Finish up the dynamic sections. */
4505 ppc_elf_finish_dynamic_sections (bfd
*output_bfd
,
4506 struct bfd_link_info
*info
)
4509 struct ppc_elf_link_hash_table
*htab
;
4512 fprintf (stderr
, "ppc_elf_finish_dynamic_sections called\n");
4515 htab
= ppc_elf_hash_table (info
);
4516 sdyn
= bfd_get_section_by_name (htab
->elf
.dynobj
, ".dynamic");
4518 if (htab
->elf
.dynamic_sections_created
)
4520 Elf32_External_Dyn
*dyncon
, *dynconend
;
4522 BFD_ASSERT (htab
->plt
!= NULL
&& sdyn
!= NULL
);
4524 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
4525 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
4526 for (; dyncon
< dynconend
; dyncon
++)
4528 Elf_Internal_Dyn dyn
;
4531 bfd_elf32_swap_dyn_in (htab
->elf
.dynobj
, dyncon
, &dyn
);
4537 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
4541 dyn
.d_un
.d_val
= htab
->relplt
->size
;
4546 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
4553 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
4557 /* Add a blrl instruction at _GLOBAL_OFFSET_TABLE_-4 so that a function can
4558 easily find the address of the _GLOBAL_OFFSET_TABLE_. */
4561 unsigned char *contents
= htab
->got
->contents
;
4562 bfd_put_32 (output_bfd
, 0x4e800021 /* blrl */, contents
);
4565 bfd_put_32 (output_bfd
, 0, contents
+ 4);
4567 bfd_put_32 (output_bfd
,
4568 sdyn
->output_section
->vma
+ sdyn
->output_offset
,
4571 elf_section_data (htab
->got
->output_section
)->this_hdr
.sh_entsize
= 4;
4577 /* The RELOCATE_SECTION function is called by the ELF backend linker
4578 to handle the relocations for a section.
4580 The relocs are always passed as Rela structures; if the section
4581 actually uses Rel structures, the r_addend field will always be
4584 This function is responsible for adjust the section contents as
4585 necessary, and (if using Rela relocs and generating a
4586 relocatable output file) adjusting the reloc addend as
4589 This function does not have to worry about setting the reloc
4590 address or the reloc symbol index.
4592 LOCAL_SYMS is a pointer to the swapped in local symbols.
4594 LOCAL_SECTIONS is an array giving the section in the input file
4595 corresponding to the st_shndx field of each local symbol.
4597 The global hash table entry for the global symbols can be found
4598 via elf_sym_hashes (input_bfd).
4600 When generating relocatable output, this function must handle
4601 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
4602 going to be the section symbol corresponding to the output
4603 section, which means that the addend must be adjusted
4607 ppc_elf_relocate_section (bfd
*output_bfd
,
4608 struct bfd_link_info
*info
,
4610 asection
*input_section
,
4612 Elf_Internal_Rela
*relocs
,
4613 Elf_Internal_Sym
*local_syms
,
4614 asection
**local_sections
)
4616 Elf_Internal_Shdr
*symtab_hdr
;
4617 struct elf_link_hash_entry
**sym_hashes
;
4618 struct ppc_elf_link_hash_table
*htab
;
4619 Elf_Internal_Rela
*rel
;
4620 Elf_Internal_Rela
*relend
;
4621 Elf_Internal_Rela outrel
;
4623 asection
*sreloc
= NULL
;
4624 bfd_vma
*local_got_offsets
;
4625 bfd_boolean ret
= TRUE
;
4628 _bfd_error_handler ("ppc_elf_relocate_section called for %B section %A, "
4629 "%ld relocations%s",
4630 input_bfd
, input_section
,
4631 (long) input_section
->reloc_count
,
4632 (info
->relocatable
) ? " (relocatable)" : "");
4635 if (info
->relocatable
)
4638 /* Initialize howto table if not already done. */
4639 if (!ppc_elf_howto_table
[R_PPC_ADDR32
])
4640 ppc_elf_howto_init ();
4642 htab
= ppc_elf_hash_table (info
);
4643 local_got_offsets
= elf_local_got_offsets (input_bfd
);
4644 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
4645 sym_hashes
= elf_sym_hashes (input_bfd
);
4647 relend
= relocs
+ input_section
->reloc_count
;
4648 for (; rel
< relend
; rel
++)
4650 enum elf_ppc_reloc_type r_type
;
4652 bfd_reloc_status_type r
;
4653 Elf_Internal_Sym
*sym
;
4655 struct elf_link_hash_entry
*h
;
4656 const char *sym_name
;
4657 reloc_howto_type
*howto
;
4658 unsigned long r_symndx
;
4660 bfd_vma branch_bit
, insn
, from
;
4661 bfd_boolean unresolved_reloc
;
4663 unsigned int tls_type
, tls_mask
, tls_gd
;
4665 r_type
= ELF32_R_TYPE (rel
->r_info
);
4669 unresolved_reloc
= FALSE
;
4671 r_symndx
= ELF32_R_SYM (rel
->r_info
);
4673 if (r_symndx
< symtab_hdr
->sh_info
)
4675 sym
= local_syms
+ r_symndx
;
4676 sec
= local_sections
[r_symndx
];
4677 sym_name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, sym
);
4679 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
4683 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
4684 r_symndx
, symtab_hdr
, sym_hashes
,
4686 unresolved_reloc
, warned
);
4688 sym_name
= h
->root
.root
.string
;
4691 /* TLS optimizations. Replace instruction sequences and relocs
4692 based on information we collected in tls_optimize. We edit
4693 RELOCS so that --emit-relocs will output something sensible
4694 for the final instruction stream. */
4697 if (IS_PPC_TLS_RELOC (r_type
))
4700 tls_mask
= ((struct ppc_elf_link_hash_entry
*) h
)->tls_mask
;
4701 else if (local_got_offsets
!= NULL
)
4704 lgot_masks
= (char *) (local_got_offsets
+ symtab_hdr
->sh_info
);
4705 tls_mask
= lgot_masks
[r_symndx
];
4709 /* Ensure reloc mapping code below stays sane. */
4710 if ((R_PPC_GOT_TLSLD16
& 3) != (R_PPC_GOT_TLSGD16
& 3)
4711 || (R_PPC_GOT_TLSLD16_LO
& 3) != (R_PPC_GOT_TLSGD16_LO
& 3)
4712 || (R_PPC_GOT_TLSLD16_HI
& 3) != (R_PPC_GOT_TLSGD16_HI
& 3)
4713 || (R_PPC_GOT_TLSLD16_HA
& 3) != (R_PPC_GOT_TLSGD16_HA
& 3)
4714 || (R_PPC_GOT_TLSLD16
& 3) != (R_PPC_GOT_TPREL16
& 3)
4715 || (R_PPC_GOT_TLSLD16_LO
& 3) != (R_PPC_GOT_TPREL16_LO
& 3)
4716 || (R_PPC_GOT_TLSLD16_HI
& 3) != (R_PPC_GOT_TPREL16_HI
& 3)
4717 || (R_PPC_GOT_TLSLD16_HA
& 3) != (R_PPC_GOT_TPREL16_HA
& 3))
4724 case R_PPC_GOT_TPREL16
:
4725 case R_PPC_GOT_TPREL16_LO
:
4727 && (tls_mask
& TLS_TPREL
) == 0)
4730 insn
= bfd_get_32 (output_bfd
, contents
+ rel
->r_offset
- 2);
4732 insn
|= 0x3c020000; /* addis 0,2,0 */
4733 bfd_put_32 (output_bfd
, insn
, contents
+ rel
->r_offset
- 2);
4734 r_type
= R_PPC_TPREL16_HA
;
4735 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
4741 && (tls_mask
& TLS_TPREL
) == 0)
4744 insn
= bfd_get_32 (output_bfd
, contents
+ rel
->r_offset
);
4745 if ((insn
& ((31 << 26) | (31 << 11)))
4746 == ((31 << 26) | (2 << 11)))
4747 rtra
= insn
& ((1 << 26) - (1 << 16));
4748 else if ((insn
& ((31 << 26) | (31 << 16)))
4749 == ((31 << 26) | (2 << 16)))
4750 rtra
= (insn
& (31 << 21)) | ((insn
& (31 << 11)) << 5);
4753 if ((insn
& ((1 << 11) - (1 << 1))) == 266 << 1)
4756 else if ((insn
& (31 << 1)) == 23 << 1
4757 && ((insn
& (31 << 6)) < 14 << 6
4758 || ((insn
& (31 << 6)) >= 16 << 6
4759 && (insn
& (31 << 6)) < 24 << 6)))
4760 /* load and store indexed -> dform. */
4761 insn
= (32 | ((insn
>> 6) & 31)) << 26;
4762 else if ((insn
& (31 << 1)) == 21 << 1
4763 && (insn
& (0x1a << 6)) == 0)
4764 /* ldx, ldux, stdx, stdux -> ld, ldu, std, stdu. */
4765 insn
= (((58 | ((insn
>> 6) & 4)) << 26)
4766 | ((insn
>> 6) & 1));
4767 else if ((insn
& (31 << 1)) == 21 << 1
4768 && (insn
& ((1 << 11) - (1 << 1))) == 341 << 1)
4770 insn
= (58 << 26) | 2;
4774 bfd_put_32 (output_bfd
, insn
, contents
+ rel
->r_offset
);
4775 r_type
= R_PPC_TPREL16_LO
;
4776 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
4777 /* Was PPC_TLS which sits on insn boundary, now
4778 PPC_TPREL16_LO which is at insn+2. */
4783 case R_PPC_GOT_TLSGD16_HI
:
4784 case R_PPC_GOT_TLSGD16_HA
:
4785 tls_gd
= TLS_TPRELGD
;
4786 if (tls_mask
!= 0 && (tls_mask
& TLS_GD
) == 0)
4790 case R_PPC_GOT_TLSLD16_HI
:
4791 case R_PPC_GOT_TLSLD16_HA
:
4792 if (tls_mask
!= 0 && (tls_mask
& TLS_LD
) == 0)
4795 if ((tls_mask
& tls_gd
) != 0)
4796 r_type
= (((r_type
- (R_PPC_GOT_TLSGD16
& 3)) & 3)
4797 + R_PPC_GOT_TPREL16
);
4800 bfd_put_32 (output_bfd
, NOP
, contents
+ rel
->r_offset
);
4802 r_type
= R_PPC_NONE
;
4804 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
4808 case R_PPC_GOT_TLSGD16
:
4809 case R_PPC_GOT_TLSGD16_LO
:
4810 tls_gd
= TLS_TPRELGD
;
4811 if (tls_mask
!= 0 && (tls_mask
& TLS_GD
) == 0)
4812 goto tls_get_addr_check
;
4815 case R_PPC_GOT_TLSLD16
:
4816 case R_PPC_GOT_TLSLD16_LO
:
4817 if (tls_mask
!= 0 && (tls_mask
& TLS_LD
) == 0)
4820 if (rel
+ 1 < relend
)
4822 enum elf_ppc_reloc_type r_type2
;
4823 unsigned long r_symndx2
;
4824 struct elf_link_hash_entry
*h2
;
4825 bfd_vma insn1
, insn2
;
4828 /* The next instruction should be a call to
4829 __tls_get_addr. Peek at the reloc to be sure. */
4830 r_type2
= ELF32_R_TYPE (rel
[1].r_info
);
4831 r_symndx2
= ELF32_R_SYM (rel
[1].r_info
);
4832 if (r_symndx2
< symtab_hdr
->sh_info
4833 || (r_type2
!= R_PPC_REL14
4834 && r_type2
!= R_PPC_REL14_BRTAKEN
4835 && r_type2
!= R_PPC_REL14_BRNTAKEN
4836 && r_type2
!= R_PPC_REL24
4837 && r_type2
!= R_PPC_PLTREL24
))
4840 h2
= sym_hashes
[r_symndx2
- symtab_hdr
->sh_info
];
4841 while (h2
->root
.type
== bfd_link_hash_indirect
4842 || h2
->root
.type
== bfd_link_hash_warning
)
4843 h2
= (struct elf_link_hash_entry
*) h2
->root
.u
.i
.link
;
4844 if (h2
== NULL
|| h2
!= htab
->tls_get_addr
)
4847 /* OK, it checks out. Replace the call. */
4848 offset
= rel
[1].r_offset
;
4849 insn1
= bfd_get_32 (output_bfd
,
4850 contents
+ rel
->r_offset
- 2);
4851 if ((tls_mask
& tls_gd
) != 0)
4854 insn1
&= (1 << 26) - 1;
4855 insn1
|= 32 << 26; /* lwz */
4856 insn2
= 0x7c631214; /* add 3,3,2 */
4857 rel
[1].r_info
= ELF32_R_INFO (r_symndx2
, R_PPC_NONE
);
4858 r_type
= (((r_type
- (R_PPC_GOT_TLSGD16
& 3)) & 3)
4859 + R_PPC_GOT_TPREL16
);
4860 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
4865 insn1
= 0x3c620000; /* addis 3,2,0 */
4866 insn2
= 0x38630000; /* addi 3,3,0 */
4869 /* Was an LD reloc. */
4871 rel
->r_addend
= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
4872 rel
[1].r_addend
= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
4874 r_type
= R_PPC_TPREL16_HA
;
4875 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
4876 rel
[1].r_info
= ELF32_R_INFO (r_symndx
,
4878 rel
[1].r_offset
+= 2;
4880 bfd_put_32 (output_bfd
, insn1
, contents
+ rel
->r_offset
- 2);
4881 bfd_put_32 (output_bfd
, insn2
, contents
+ offset
);
4884 /* We changed the symbol on an LD reloc. Start over
4885 in order to get h, sym, sec etc. right. */
4894 /* Handle other relocations that tweak non-addend part of insn. */
4901 /* Branch taken prediction relocations. */
4902 case R_PPC_ADDR14_BRTAKEN
:
4903 case R_PPC_REL14_BRTAKEN
:
4904 branch_bit
= BRANCH_PREDICT_BIT
;
4907 /* Branch not taken prediction relocations. */
4908 case R_PPC_ADDR14_BRNTAKEN
:
4909 case R_PPC_REL14_BRNTAKEN
:
4910 insn
= bfd_get_32 (output_bfd
, contents
+ rel
->r_offset
);
4911 insn
&= ~BRANCH_PREDICT_BIT
;
4914 from
= (rel
->r_offset
4915 + input_section
->output_offset
4916 + input_section
->output_section
->vma
);
4918 /* Invert 'y' bit if not the default. */
4919 if ((bfd_signed_vma
) (relocation
+ rel
->r_addend
- from
) < 0)
4920 insn
^= BRANCH_PREDICT_BIT
;
4922 bfd_put_32 (output_bfd
, insn
, contents
+ rel
->r_offset
);
4926 addend
= rel
->r_addend
;
4929 if (r_type
< R_PPC_max
)
4930 howto
= ppc_elf_howto_table
[r_type
];
4934 (*_bfd_error_handler
)
4935 (_("%B: unknown relocation type %d for symbol %s"),
4936 input_bfd
, (int) r_type
, sym_name
);
4938 bfd_set_error (bfd_error_bad_value
);
4944 case R_PPC_EMB_MRKREF
:
4945 case R_PPC_GNU_VTINHERIT
:
4946 case R_PPC_GNU_VTENTRY
:
4949 /* GOT16 relocations. Like an ADDR16 using the symbol's
4950 address in the GOT as relocation value instead of the
4951 symbol's value itself. Also, create a GOT entry for the
4952 symbol and put the symbol value there. */
4953 case R_PPC_GOT_TLSGD16
:
4954 case R_PPC_GOT_TLSGD16_LO
:
4955 case R_PPC_GOT_TLSGD16_HI
:
4956 case R_PPC_GOT_TLSGD16_HA
:
4957 tls_type
= TLS_TLS
| TLS_GD
;
4960 case R_PPC_GOT_TLSLD16
:
4961 case R_PPC_GOT_TLSLD16_LO
:
4962 case R_PPC_GOT_TLSLD16_HI
:
4963 case R_PPC_GOT_TLSLD16_HA
:
4964 tls_type
= TLS_TLS
| TLS_LD
;
4967 case R_PPC_GOT_TPREL16
:
4968 case R_PPC_GOT_TPREL16_LO
:
4969 case R_PPC_GOT_TPREL16_HI
:
4970 case R_PPC_GOT_TPREL16_HA
:
4971 tls_type
= TLS_TLS
| TLS_TPREL
;
4974 case R_PPC_GOT_DTPREL16
:
4975 case R_PPC_GOT_DTPREL16_LO
:
4976 case R_PPC_GOT_DTPREL16_HI
:
4977 case R_PPC_GOT_DTPREL16_HA
:
4978 tls_type
= TLS_TLS
| TLS_DTPREL
;
4982 case R_PPC_GOT16_LO
:
4983 case R_PPC_GOT16_HI
:
4984 case R_PPC_GOT16_HA
:
4987 /* Relocation is to the entry for this symbol in the global
4993 if (htab
->got
== NULL
)
4997 if (tls_type
== (TLS_TLS
| TLS_LD
)
4999 || !h
->def_dynamic
))
5000 offp
= &htab
->tlsld_got
.offset
;
5004 dyn
= htab
->elf
.dynamic_sections_created
;
5005 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
5007 && SYMBOL_REFERENCES_LOCAL (info
, h
)))
5008 /* This is actually a static link, or it is a
5009 -Bsymbolic link and the symbol is defined
5010 locally, or the symbol was forced to be local
5011 because of a version file. */
5016 unresolved_reloc
= FALSE
;
5018 offp
= &h
->got
.offset
;
5022 if (local_got_offsets
== NULL
)
5024 offp
= &local_got_offsets
[r_symndx
];
5027 /* The offset must always be a multiple of 4. We use the
5028 least significant bit to record whether we have already
5029 processed this entry. */
5035 unsigned int tls_m
= (tls_mask
5036 & (TLS_LD
| TLS_GD
| TLS_DTPREL
5037 | TLS_TPREL
| TLS_TPRELGD
));
5039 if (offp
== &htab
->tlsld_got
.offset
)
5045 /* We might have multiple got entries for this sym.
5046 Initialize them all. */
5051 if ((tls_m
& TLS_LD
) != 0)
5053 tls_ty
= TLS_TLS
| TLS_LD
;
5056 else if ((tls_m
& TLS_GD
) != 0)
5058 tls_ty
= TLS_TLS
| TLS_GD
;
5061 else if ((tls_m
& TLS_DTPREL
) != 0)
5063 tls_ty
= TLS_TLS
| TLS_DTPREL
;
5064 tls_m
&= ~TLS_DTPREL
;
5066 else if ((tls_m
& (TLS_TPREL
| TLS_TPRELGD
)) != 0)
5068 tls_ty
= TLS_TLS
| TLS_TPREL
;
5072 /* Generate relocs for the dynamic linker. */
5073 if ((info
->shared
|| indx
!= 0)
5075 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
5076 || h
->root
.type
!= bfd_link_hash_undefweak
))
5078 outrel
.r_offset
= (htab
->got
->output_section
->vma
5079 + htab
->got
->output_offset
5081 outrel
.r_addend
= 0;
5082 if (tls_ty
& (TLS_LD
| TLS_GD
))
5084 outrel
.r_info
= ELF32_R_INFO (indx
, R_PPC_DTPMOD32
);
5085 if (tls_ty
== (TLS_TLS
| TLS_GD
))
5087 loc
= htab
->relgot
->contents
;
5088 loc
+= (htab
->relgot
->reloc_count
++
5089 * sizeof (Elf32_External_Rela
));
5090 bfd_elf32_swap_reloca_out (output_bfd
,
5092 outrel
.r_offset
+= 4;
5094 = ELF32_R_INFO (indx
, R_PPC_DTPREL32
);
5097 else if (tls_ty
== (TLS_TLS
| TLS_DTPREL
))
5098 outrel
.r_info
= ELF32_R_INFO (indx
, R_PPC_DTPREL32
);
5099 else if (tls_ty
== (TLS_TLS
| TLS_TPREL
))
5100 outrel
.r_info
= ELF32_R_INFO (indx
, R_PPC_TPREL32
);
5102 outrel
.r_info
= ELF32_R_INFO (indx
, R_PPC_RELATIVE
);
5104 outrel
.r_info
= ELF32_R_INFO (indx
, R_PPC_GLOB_DAT
);
5107 outrel
.r_addend
+= relocation
;
5108 if (tls_ty
& (TLS_GD
| TLS_DTPREL
| TLS_TPREL
))
5109 outrel
.r_addend
-= htab
->elf
.tls_sec
->vma
;
5111 loc
= htab
->relgot
->contents
;
5112 loc
+= (htab
->relgot
->reloc_count
++
5113 * sizeof (Elf32_External_Rela
));
5114 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
5117 /* Init the .got section contents if we're not
5118 emitting a reloc. */
5121 bfd_vma value
= relocation
;
5123 if (tls_ty
== (TLS_TLS
| TLS_LD
))
5125 else if (tls_ty
!= 0)
5127 value
-= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
5128 if (tls_ty
== (TLS_TLS
| TLS_TPREL
))
5129 value
+= DTP_OFFSET
- TP_OFFSET
;
5131 if (tls_ty
== (TLS_TLS
| TLS_GD
))
5133 bfd_put_32 (output_bfd
, value
,
5134 htab
->got
->contents
+ off
+ 4);
5138 bfd_put_32 (output_bfd
, value
,
5139 htab
->got
->contents
+ off
);
5143 if (tls_ty
& (TLS_LD
| TLS_GD
))
5152 if (off
>= (bfd_vma
) -2)
5155 if ((tls_type
& TLS_TLS
) != 0)
5157 if (tls_type
!= (TLS_TLS
| TLS_LD
))
5159 if ((tls_mask
& TLS_LD
) != 0
5161 || !h
->def_dynamic
))
5163 if (tls_type
!= (TLS_TLS
| TLS_GD
))
5165 if ((tls_mask
& TLS_GD
) != 0)
5167 if (tls_type
!= (TLS_TLS
| TLS_DTPREL
))
5169 if ((tls_mask
& TLS_DTPREL
) != 0)
5176 relocation
= htab
->got
->output_offset
+ off
- 4;
5178 /* Addends on got relocations don't make much sense.
5179 x+off@got is actually x@got+off, and since the got is
5180 generated by a hash table traversal, the value in the
5181 got at entry m+n bears little relation to the entry m. */
5183 (*_bfd_error_handler
)
5184 (_("%B(%A+0x%lx): non-zero addend on %s reloc against `%s'"),
5187 (long) rel
->r_offset
,
5193 /* Relocations that need no special processing. */
5194 case R_PPC_LOCAL24PC
:
5195 /* It makes no sense to point a local relocation
5196 at a symbol not in this object. */
5197 if (unresolved_reloc
)
5199 if (! (*info
->callbacks
->undefined_symbol
) (info
,
5200 h
->root
.root
.string
,
5210 case R_PPC_DTPREL16
:
5211 case R_PPC_DTPREL16_LO
:
5212 case R_PPC_DTPREL16_HI
:
5213 case R_PPC_DTPREL16_HA
:
5214 addend
-= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
5217 /* Relocations that may need to be propagated if this is a shared
5220 case R_PPC_TPREL16_LO
:
5221 case R_PPC_TPREL16_HI
:
5222 case R_PPC_TPREL16_HA
:
5223 addend
-= htab
->elf
.tls_sec
->vma
+ TP_OFFSET
;
5224 /* The TPREL16 relocs shouldn't really be used in shared
5225 libs as they will result in DT_TEXTREL being set, but
5226 support them anyway. */
5230 addend
-= htab
->elf
.tls_sec
->vma
+ TP_OFFSET
;
5233 case R_PPC_DTPREL32
:
5234 addend
-= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
5237 case R_PPC_DTPMOD32
:
5245 case R_PPC_REL14_BRTAKEN
:
5246 case R_PPC_REL14_BRNTAKEN
:
5247 /* If these relocations are not to a named symbol, they can be
5248 handled right here, no need to bother the dynamic linker. */
5249 if (SYMBOL_REFERENCES_LOCAL (info
, h
)
5250 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
5254 /* Relocations that always need to be propagated if this is a shared
5259 case R_PPC_ADDR16_LO
:
5260 case R_PPC_ADDR16_HI
:
5261 case R_PPC_ADDR16_HA
:
5263 case R_PPC_ADDR14_BRTAKEN
:
5264 case R_PPC_ADDR14_BRNTAKEN
:
5267 /* r_symndx will be zero only for relocs against symbols
5268 from removed linkonce sections, or sections discarded by
5277 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
5278 || h
->root
.type
!= bfd_link_hash_undefweak
)
5279 && (MUST_BE_DYN_RELOC (r_type
)
5280 || !SYMBOL_CALLS_LOCAL (info
, h
)))
5281 || (ELIMINATE_COPY_RELOCS
5283 && (input_section
->flags
& SEC_ALLOC
) != 0
5288 && !h
->def_regular
))
5293 fprintf (stderr
, "ppc_elf_relocate_section needs to "
5294 "create relocation for %s\n",
5295 (h
&& h
->root
.root
.string
5296 ? h
->root
.root
.string
: "<unknown>"));
5299 /* When generating a shared object, these relocations
5300 are copied into the output file to be resolved at run
5306 name
= (bfd_elf_string_from_elf_section
5308 elf_elfheader (input_bfd
)->e_shstrndx
,
5309 elf_section_data (input_section
)->rel_hdr
.sh_name
));
5313 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
5314 && strcmp (bfd_get_section_name (input_bfd
,
5318 sreloc
= bfd_get_section_by_name (htab
->elf
.dynobj
, name
);
5319 BFD_ASSERT (sreloc
!= NULL
);
5325 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
5327 if (outrel
.r_offset
== (bfd_vma
) -1
5328 || outrel
.r_offset
== (bfd_vma
) -2)
5329 skip
= (int) outrel
.r_offset
;
5330 outrel
.r_offset
+= (input_section
->output_section
->vma
5331 + input_section
->output_offset
);
5334 memset (&outrel
, 0, sizeof outrel
);
5335 else if (!SYMBOL_REFERENCES_LOCAL (info
, h
))
5337 unresolved_reloc
= FALSE
;
5338 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
5339 outrel
.r_addend
= rel
->r_addend
;
5343 outrel
.r_addend
= relocation
+ rel
->r_addend
;
5345 if (r_type
== R_PPC_ADDR32
)
5346 outrel
.r_info
= ELF32_R_INFO (0, R_PPC_RELATIVE
);
5351 if (bfd_is_abs_section (sec
))
5353 else if (sec
== NULL
|| sec
->owner
== NULL
)
5355 bfd_set_error (bfd_error_bad_value
);
5362 /* We are turning this relocation into one
5363 against a section symbol. It would be
5364 proper to subtract the symbol's value,
5365 osec->vma, from the emitted reloc addend,
5366 but ld.so expects buggy relocs. */
5367 osec
= sec
->output_section
;
5368 indx
= elf_section_data (osec
)->dynindx
;
5369 BFD_ASSERT (indx
> 0);
5372 printf ("indx=%d section=%s flags=%08x name=%s\n",
5373 indx
, osec
->name
, osec
->flags
,
5374 h
->root
.root
.string
);
5378 outrel
.r_info
= ELF32_R_INFO (indx
, r_type
);
5382 loc
= sreloc
->contents
;
5383 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rela
);
5384 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
5389 /* This reloc will be computed at runtime. We clear the memory
5390 so that it contains predictable value. */
5392 && ((input_section
->flags
& SEC_ALLOC
) != 0
5393 || ELF32_R_TYPE (outrel
.r_info
) != R_PPC_RELATIVE
))
5395 relocation
= howto
->pc_relative
? outrel
.r_offset
: 0;
5402 case R_PPC_RELAX32PC_PLT
:
5403 case R_PPC_RELAX32_PLT
:
5404 BFD_ASSERT (h
!= NULL
5405 && h
->plt
.offset
!= (bfd_vma
) -1
5406 && htab
->plt
!= NULL
);
5408 relocation
= (htab
->plt
->output_section
->vma
5409 + htab
->plt
->output_offset
5411 if (r_type
== R_PPC_RELAX32_PLT
)
5415 case R_PPC_RELAX32PC
:
5416 relocation
-= (input_section
->output_section
->vma
5417 + input_section
->output_offset
5418 + rel
->r_offset
- 4);
5427 t0
= bfd_get_32 (output_bfd
, contents
+ rel
->r_offset
);
5428 t1
= bfd_get_32 (output_bfd
, contents
+ rel
->r_offset
+ 4);
5430 /* We're clearing the bits for R_PPC_ADDR16_HA
5431 and R_PPC_ADDR16_LO here. */
5435 /* t0 is HA, t1 is LO */
5436 relocation
+= addend
;
5437 t0
|= ((relocation
+ 0x8000) >> 16) & 0xffff;
5438 t1
|= relocation
& 0xffff;
5440 bfd_put_32 (output_bfd
, t0
, contents
+ rel
->r_offset
);
5441 bfd_put_32 (output_bfd
, t1
, contents
+ rel
->r_offset
+ 4);
5445 /* Indirect .sdata relocation. */
5446 case R_PPC_EMB_SDAI16
:
5447 BFD_ASSERT (htab
->sdata
!= NULL
);
5449 = elf_finish_pointer_linker_section (output_bfd
, input_bfd
, info
,
5450 htab
->sdata
, h
, relocation
,
5451 rel
, R_PPC_RELATIVE
);
5454 /* Indirect .sdata2 relocation. */
5455 case R_PPC_EMB_SDA2I16
:
5456 BFD_ASSERT (htab
->sdata2
!= NULL
);
5458 = elf_finish_pointer_linker_section (output_bfd
, input_bfd
, info
,
5459 htab
->sdata2
, h
, relocation
,
5460 rel
, R_PPC_RELATIVE
);
5463 /* Handle the TOC16 reloc. We want to use the offset within the .got
5464 section, not the actual VMA. This is appropriate when generating
5465 an embedded ELF object, for which the .got section acts like the
5466 AIX .toc section. */
5467 case R_PPC_TOC16
: /* phony GOT16 relocations */
5468 BFD_ASSERT (sec
!= NULL
);
5469 BFD_ASSERT (bfd_is_und_section (sec
)
5470 || strcmp (bfd_get_section_name (abfd
, sec
), ".got") == 0
5471 || strcmp (bfd_get_section_name (abfd
, sec
), ".cgot") == 0);
5473 addend
-= sec
->output_section
->vma
+ sec
->output_offset
+ 0x8000;
5476 case R_PPC_PLTREL24
:
5477 /* Relocation is to the entry for this symbol in the
5478 procedure linkage table. */
5479 BFD_ASSERT (h
!= NULL
);
5481 if (h
->plt
.offset
== (bfd_vma
) -1
5482 || htab
->plt
== NULL
)
5484 /* We didn't make a PLT entry for this symbol. This
5485 happens when statically linking PIC code, or when
5486 using -Bsymbolic. */
5490 unresolved_reloc
= FALSE
;
5491 relocation
= (htab
->plt
->output_section
->vma
5492 + htab
->plt
->output_offset
5496 /* Relocate against _SDA_BASE_. */
5497 case R_PPC_SDAREL16
:
5500 const struct elf_link_hash_entry
*sh
;
5502 BFD_ASSERT (sec
!= NULL
);
5503 name
= bfd_get_section_name (abfd
, sec
->output_section
);
5504 if (! ((strncmp (name
, ".sdata", 6) == 0
5505 && (name
[6] == 0 || name
[6] == '.'))
5506 || (strncmp (name
, ".sbss", 5) == 0
5507 && (name
[5] == 0 || name
[5] == '.'))))
5509 (*_bfd_error_handler
)
5510 (_("%B: the target (%s) of a %s relocation is "
5511 "in the wrong output section (%s)"),
5517 sh
= htab
->sdata
->sym_hash
;
5518 addend
-= (sh
->root
.u
.def
.value
5519 + sh
->root
.u
.def
.section
->output_section
->vma
5520 + sh
->root
.u
.def
.section
->output_offset
);
5524 /* Relocate against _SDA2_BASE_. */
5525 case R_PPC_EMB_SDA2REL
:
5528 const struct elf_link_hash_entry
*sh
;
5530 BFD_ASSERT (sec
!= NULL
);
5531 name
= bfd_get_section_name (abfd
, sec
->output_section
);
5532 if (! (strncmp (name
, ".sdata2", 7) == 0
5533 || strncmp (name
, ".sbss2", 6) == 0))
5535 (*_bfd_error_handler
)
5536 (_("%B: the target (%s) of a %s relocation is "
5537 "in the wrong output section (%s)"),
5543 bfd_set_error (bfd_error_bad_value
);
5547 sh
= htab
->sdata2
->sym_hash
;
5548 addend
-= (sh
->root
.u
.def
.value
5549 + sh
->root
.u
.def
.section
->output_section
->vma
5550 + sh
->root
.u
.def
.section
->output_offset
);
5554 /* Relocate against either _SDA_BASE_, _SDA2_BASE_, or 0. */
5555 case R_PPC_EMB_SDA21
:
5556 case R_PPC_EMB_RELSDA
:
5559 const struct elf_link_hash_entry
*sh
;
5562 BFD_ASSERT (sec
!= NULL
);
5563 name
= bfd_get_section_name (abfd
, sec
->output_section
);
5564 if (((strncmp (name
, ".sdata", 6) == 0
5565 && (name
[6] == 0 || name
[6] == '.'))
5566 || (strncmp (name
, ".sbss", 5) == 0
5567 && (name
[5] == 0 || name
[5] == '.'))))
5570 sh
= htab
->sdata
->sym_hash
;
5571 addend
-= (sh
->root
.u
.def
.value
5572 + sh
->root
.u
.def
.section
->output_section
->vma
5573 + sh
->root
.u
.def
.section
->output_offset
);
5576 else if (strncmp (name
, ".sdata2", 7) == 0
5577 || strncmp (name
, ".sbss2", 6) == 0)
5580 sh
= htab
->sdata2
->sym_hash
;
5581 addend
-= (sh
->root
.u
.def
.value
5582 + sh
->root
.u
.def
.section
->output_section
->vma
5583 + sh
->root
.u
.def
.section
->output_offset
);
5586 else if (strcmp (name
, ".PPC.EMB.sdata0") == 0
5587 || strcmp (name
, ".PPC.EMB.sbss0") == 0)
5594 (*_bfd_error_handler
)
5595 (_("%B: the target (%s) of a %s relocation is "
5596 "in the wrong output section (%s)"),
5602 bfd_set_error (bfd_error_bad_value
);
5607 if (r_type
== R_PPC_EMB_SDA21
)
5608 { /* fill in register field */
5609 insn
= bfd_get_32 (output_bfd
, contents
+ rel
->r_offset
);
5610 insn
= (insn
& ~RA_REGISTER_MASK
) | (reg
<< RA_REGISTER_SHIFT
);
5611 bfd_put_32 (output_bfd
, insn
, contents
+ rel
->r_offset
);
5616 /* Relocate against the beginning of the section. */
5618 case R_PPC_SECTOFF_LO
:
5619 case R_PPC_SECTOFF_HI
:
5620 case R_PPC_SECTOFF_HA
:
5621 BFD_ASSERT (sec
!= NULL
);
5622 addend
-= sec
->output_section
->vma
;
5625 /* Negative relocations. */
5626 case R_PPC_EMB_NADDR32
:
5627 case R_PPC_EMB_NADDR16
:
5628 case R_PPC_EMB_NADDR16_LO
:
5629 case R_PPC_EMB_NADDR16_HI
:
5630 case R_PPC_EMB_NADDR16_HA
:
5631 addend
-= 2 * relocation
;
5635 case R_PPC_GLOB_DAT
:
5636 case R_PPC_JMP_SLOT
:
5637 case R_PPC_RELATIVE
:
5639 case R_PPC_PLTREL32
:
5640 case R_PPC_PLT16_LO
:
5641 case R_PPC_PLT16_HI
:
5642 case R_PPC_PLT16_HA
:
5644 case R_PPC_EMB_RELSEC16
:
5645 case R_PPC_EMB_RELST_LO
:
5646 case R_PPC_EMB_RELST_HI
:
5647 case R_PPC_EMB_RELST_HA
:
5648 case R_PPC_EMB_BIT_FLD
:
5649 (*_bfd_error_handler
)
5650 (_("%B: relocation %s is not yet supported for symbol %s."),
5655 bfd_set_error (bfd_error_invalid_operation
);
5660 /* Do any further special processing. */
5666 case R_PPC_ADDR16_HA
:
5667 case R_PPC_GOT16_HA
:
5668 case R_PPC_PLT16_HA
:
5669 case R_PPC_SECTOFF_HA
:
5670 case R_PPC_TPREL16_HA
:
5671 case R_PPC_DTPREL16_HA
:
5672 case R_PPC_GOT_TLSGD16_HA
:
5673 case R_PPC_GOT_TLSLD16_HA
:
5674 case R_PPC_GOT_TPREL16_HA
:
5675 case R_PPC_GOT_DTPREL16_HA
:
5676 case R_PPC_EMB_NADDR16_HA
:
5677 case R_PPC_EMB_RELST_HA
:
5678 /* It's just possible that this symbol is a weak symbol
5679 that's not actually defined anywhere. In that case,
5680 'sec' would be NULL, and we should leave the symbol
5681 alone (it will be set to zero elsewhere in the link). */
5683 /* Add 0x10000 if sign bit in 0:15 is set.
5684 Bits 0:15 are not used. */
5690 fprintf (stderr
, "\ttype = %s (%d), name = %s, symbol index = %ld, "
5691 "offset = %ld, addend = %ld\n",
5696 (long) rel
->r_offset
,
5700 if (unresolved_reloc
5701 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
5704 (*_bfd_error_handler
)
5705 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
5708 (long) rel
->r_offset
,
5714 r
= _bfd_final_link_relocate (howto
,
5722 if (r
!= bfd_reloc_ok
)
5724 if (sym_name
== NULL
)
5725 sym_name
= "(null)";
5726 if (r
== bfd_reloc_overflow
)
5731 && h
->root
.type
== bfd_link_hash_undefweak
5732 && howto
->pc_relative
)
5734 /* Assume this is a call protected by other code that
5735 detect the symbol is undefined. If this is the case,
5736 we can safely ignore the overflow. If not, the
5737 program is hosed anyway, and a little warning isn't
5743 if (! (*info
->callbacks
->reloc_overflow
) (info
,
5744 (h
? &h
->root
: NULL
),
5755 (*_bfd_error_handler
)
5756 (_("%B(%A+0x%lx): %s reloc against `%s': error %d"),
5757 input_bfd
, input_section
,
5758 (long) rel
->r_offset
, howto
->name
, sym_name
, (int) r
);
5765 fprintf (stderr
, "\n");
5771 static enum elf_reloc_type_class
5772 ppc_elf_reloc_type_class (const Elf_Internal_Rela
*rela
)
5774 switch (ELF32_R_TYPE (rela
->r_info
))
5776 case R_PPC_RELATIVE
:
5777 return reloc_class_relative
;
5780 case R_PPC_JMP_SLOT
:
5781 return reloc_class_plt
;
5783 return reloc_class_copy
;
5785 return reloc_class_normal
;
5789 /* Support for core dump NOTE sections. */
5792 ppc_elf_grok_prstatus (bfd
*abfd
, Elf_Internal_Note
*note
)
5797 switch (note
->descsz
)
5802 case 268: /* Linux/PPC. */
5804 elf_tdata (abfd
)->core_signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
5807 elf_tdata (abfd
)->core_pid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
5816 /* Make a ".reg/999" section. */
5817 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
5818 size
, note
->descpos
+ offset
);
5822 ppc_elf_grok_psinfo (bfd
*abfd
, Elf_Internal_Note
*note
)
5824 switch (note
->descsz
)
5829 case 128: /* Linux/PPC elf_prpsinfo. */
5830 elf_tdata (abfd
)->core_program
5831 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 32, 16);
5832 elf_tdata (abfd
)->core_command
5833 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 48, 80);
5836 /* Note that for some reason, a spurious space is tacked
5837 onto the end of the args in some (at least one anyway)
5838 implementations, so strip it off if it exists. */
5841 char *command
= elf_tdata (abfd
)->core_command
;
5842 int n
= strlen (command
);
5844 if (0 < n
&& command
[n
- 1] == ' ')
5845 command
[n
- 1] = '\0';
5851 /* Very simple linked list structure for recording apuinfo values. */
5852 typedef struct apuinfo_list
5854 struct apuinfo_list
*next
;
5855 unsigned long value
;
5859 static apuinfo_list
*head
;
5863 apuinfo_list_init (void)
5869 apuinfo_list_add (unsigned long value
)
5871 apuinfo_list
*entry
= head
;
5873 while (entry
!= NULL
)
5875 if (entry
->value
== value
)
5877 entry
= entry
->next
;
5880 entry
= bfd_malloc (sizeof (* entry
));
5884 entry
->value
= value
;
5890 apuinfo_list_length (void)
5892 apuinfo_list
*entry
;
5893 unsigned long count
;
5895 for (entry
= head
, count
= 0;
5897 entry
= entry
->next
)
5903 static inline unsigned long
5904 apuinfo_list_element (unsigned long number
)
5906 apuinfo_list
* entry
;
5910 entry
= entry
->next
)
5913 return entry
? entry
->value
: 0;
5917 apuinfo_list_finish (void)
5919 apuinfo_list
*entry
;
5921 for (entry
= head
; entry
;)
5923 apuinfo_list
*next
= entry
->next
;
5931 #define APUINFO_SECTION_NAME ".PPC.EMB.apuinfo"
5932 #define APUINFO_LABEL "APUinfo"
5934 /* Scan the input BFDs and create a linked list of
5935 the APUinfo values that will need to be emitted. */
5938 ppc_elf_begin_write_processing (bfd
*abfd
, struct bfd_link_info
*link_info
)
5943 unsigned num_input_sections
;
5944 bfd_size_type output_section_size
;
5946 unsigned num_entries
;
5947 unsigned long offset
;
5948 unsigned long length
;
5949 const char *error_message
= NULL
;
5951 if (link_info
== NULL
)
5954 /* Scan the input bfds, looking for apuinfo sections. */
5955 num_input_sections
= 0;
5956 output_section_size
= 0;
5958 for (ibfd
= link_info
->input_bfds
; ibfd
; ibfd
= ibfd
->link_next
)
5960 asec
= bfd_get_section_by_name (ibfd
, APUINFO_SECTION_NAME
);
5963 ++ num_input_sections
;
5964 output_section_size
+= asec
->size
;
5968 /* We need at least one input sections
5969 in order to make merging worthwhile. */
5970 if (num_input_sections
< 1)
5973 /* Just make sure that the output section exists as well. */
5974 asec
= bfd_get_section_by_name (abfd
, APUINFO_SECTION_NAME
);
5978 /* Allocate a buffer for the contents of the input sections. */
5979 buffer
= bfd_malloc (output_section_size
);
5984 apuinfo_list_init ();
5986 /* Read in the input sections contents. */
5987 for (ibfd
= link_info
->input_bfds
; ibfd
; ibfd
= ibfd
->link_next
)
5989 unsigned long datum
;
5992 asec
= bfd_get_section_by_name (ibfd
, APUINFO_SECTION_NAME
);
5996 length
= asec
->size
;
5999 error_message
= _("corrupt or empty %s section in %B");
6003 if (bfd_seek (ibfd
, asec
->filepos
, SEEK_SET
) != 0
6004 || (bfd_bread (buffer
+ offset
, length
, ibfd
) != length
))
6006 error_message
= _("unable to read in %s section from %B");
6010 /* Process the contents of the section. */
6011 ptr
= buffer
+ offset
;
6012 error_message
= _("corrupt %s section in %B");
6014 /* Verify the contents of the header. Note - we have to
6015 extract the values this way in order to allow for a
6016 host whose endian-ness is different from the target. */
6017 datum
= bfd_get_32 (ibfd
, ptr
);
6018 if (datum
!= sizeof APUINFO_LABEL
)
6021 datum
= bfd_get_32 (ibfd
, ptr
+ 8);
6025 if (strcmp (ptr
+ 12, APUINFO_LABEL
) != 0)
6028 /* Get the number of bytes used for apuinfo entries. */
6029 datum
= bfd_get_32 (ibfd
, ptr
+ 4);
6030 if (datum
+ 20 != length
)
6033 /* Make sure that we do not run off the end of the section. */
6034 if (offset
+ length
> output_section_size
)
6037 /* Scan the apuinfo section, building a list of apuinfo numbers. */
6038 for (i
= 0; i
< datum
; i
+= 4)
6039 apuinfo_list_add (bfd_get_32 (ibfd
, ptr
+ 20 + i
));
6041 /* Update the offset. */
6045 error_message
= NULL
;
6047 /* Compute the size of the output section. */
6048 num_entries
= apuinfo_list_length ();
6049 output_section_size
= 20 + num_entries
* 4;
6051 asec
= bfd_get_section_by_name (abfd
, APUINFO_SECTION_NAME
);
6053 if (! bfd_set_section_size (abfd
, asec
, output_section_size
))
6055 error_message
= _("warning: unable to set size of %s section in %B");
6061 (*_bfd_error_handler
) (error_message
, ibfd
, APUINFO_SECTION_NAME
);
6065 /* Prevent the output section from accumulating the input sections'
6066 contents. We have already stored this in our linked list structure. */
6069 ppc_elf_write_section (bfd
*abfd ATTRIBUTE_UNUSED
,
6071 bfd_byte
*contents ATTRIBUTE_UNUSED
)
6073 return (apuinfo_list_length ()
6074 && strcmp (asec
->name
, APUINFO_SECTION_NAME
) == 0);
6078 /* Finally we can generate the output section. */
6081 ppc_elf_final_write_processing (bfd
*abfd
, bfd_boolean linker ATTRIBUTE_UNUSED
)
6086 unsigned num_entries
;
6087 bfd_size_type length
;
6089 asec
= bfd_get_section_by_name (abfd
, APUINFO_SECTION_NAME
);
6093 if (apuinfo_list_length () == 0)
6096 length
= asec
->size
;
6100 buffer
= bfd_malloc (length
);
6103 (*_bfd_error_handler
)
6104 (_("failed to allocate space for new APUinfo section."));
6108 /* Create the apuinfo header. */
6109 num_entries
= apuinfo_list_length ();
6110 bfd_put_32 (abfd
, sizeof APUINFO_LABEL
, buffer
);
6111 bfd_put_32 (abfd
, num_entries
* 4, buffer
+ 4);
6112 bfd_put_32 (abfd
, 0x2, buffer
+ 8);
6113 strcpy (buffer
+ 12, APUINFO_LABEL
);
6116 for (i
= 0; i
< num_entries
; i
++)
6118 bfd_put_32 (abfd
, apuinfo_list_element (i
), buffer
+ length
);
6122 if (length
!= asec
->size
)
6123 (*_bfd_error_handler
) (_("failed to compute new APUinfo section."));
6125 if (! bfd_set_section_contents (abfd
, asec
, buffer
, (file_ptr
) 0, length
))
6126 (*_bfd_error_handler
) (_("failed to install new APUinfo section."));
6130 apuinfo_list_finish ();
6133 /* Return address for Ith PLT stub in section PLT, for relocation REL
6134 or (bfd_vma) -1 if it should not be included. */
6137 ppc_elf_plt_sym_val (bfd_vma i ATTRIBUTE_UNUSED
,
6138 const asection
*plt ATTRIBUTE_UNUSED
,
6141 return rel
->address
;
6144 /* Add extra PPC sections -- Note, for now, make .sbss2 and
6145 .PPC.EMB.sbss0 a normal section, and not a bss section so
6146 that the linker doesn't crater when trying to make more than
6149 static struct bfd_elf_special_section
const ppc_elf_special_sections
[]=
6151 { ".tags", 5, 0, SHT_ORDERED
, SHF_ALLOC
},
6152 { ".sdata", 6, -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
6153 { ".sbss", 5, -2, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
},
6154 { ".sdata2", 7, -2, SHT_PROGBITS
, SHF_ALLOC
},
6155 { ".sbss2", 6, -2, SHT_PROGBITS
, SHF_ALLOC
},
6156 { ".PPC.EMB.apuinfo", 16, 0, SHT_NOTE
, 0 },
6157 { ".PPC.EMB.sdata0", 15, 0, SHT_PROGBITS
, SHF_ALLOC
},
6158 { ".PPC.EMB.sbss0", 14, 0, SHT_PROGBITS
, SHF_ALLOC
},
6159 { ".plt", 4, 0, SHT_NOBITS
, SHF_ALLOC
+ SHF_EXECINSTR
},
6160 { NULL
, 0, 0, 0, 0 }
6163 #define TARGET_LITTLE_SYM bfd_elf32_powerpcle_vec
6164 #define TARGET_LITTLE_NAME "elf32-powerpcle"
6165 #define TARGET_BIG_SYM bfd_elf32_powerpc_vec
6166 #define TARGET_BIG_NAME "elf32-powerpc"
6167 #define ELF_ARCH bfd_arch_powerpc
6168 #define ELF_MACHINE_CODE EM_PPC
6169 #ifdef __QNXTARGET__
6170 #define ELF_MAXPAGESIZE 0x1000
6172 #define ELF_MAXPAGESIZE 0x10000
6174 #define ELF_MINPAGESIZE 0x1000
6175 #define elf_info_to_howto ppc_elf_info_to_howto
6177 #ifdef EM_CYGNUS_POWERPC
6178 #define ELF_MACHINE_ALT1 EM_CYGNUS_POWERPC
6182 #define ELF_MACHINE_ALT2 EM_PPC_OLD
6185 #define elf_backend_plt_not_loaded 1
6186 #define elf_backend_got_symbol_offset 4
6187 #define elf_backend_can_gc_sections 1
6188 #define elf_backend_can_refcount 1
6189 #define elf_backend_got_header_size 12
6190 #define elf_backend_rela_normal 1
6192 #define bfd_elf32_mkobject ppc_elf_mkobject
6193 #define bfd_elf32_bfd_merge_private_bfd_data ppc_elf_merge_private_bfd_data
6194 #define bfd_elf32_bfd_relax_section ppc_elf_relax_section
6195 #define bfd_elf32_bfd_reloc_type_lookup ppc_elf_reloc_type_lookup
6196 #define bfd_elf32_bfd_set_private_flags ppc_elf_set_private_flags
6197 #define bfd_elf32_bfd_link_hash_table_create ppc_elf_link_hash_table_create
6199 #define elf_backend_object_p ppc_elf_object_p
6200 #define elf_backend_gc_mark_hook ppc_elf_gc_mark_hook
6201 #define elf_backend_gc_sweep_hook ppc_elf_gc_sweep_hook
6202 #define elf_backend_section_from_shdr ppc_elf_section_from_shdr
6203 #define elf_backend_relocate_section ppc_elf_relocate_section
6204 #define elf_backend_create_dynamic_sections ppc_elf_create_dynamic_sections
6205 #define elf_backend_check_relocs ppc_elf_check_relocs
6206 #define elf_backend_copy_indirect_symbol ppc_elf_copy_indirect_symbol
6207 #define elf_backend_adjust_dynamic_symbol ppc_elf_adjust_dynamic_symbol
6208 #define elf_backend_add_symbol_hook ppc_elf_add_symbol_hook
6209 #define elf_backend_size_dynamic_sections ppc_elf_size_dynamic_sections
6210 #define elf_backend_finish_dynamic_symbol ppc_elf_finish_dynamic_symbol
6211 #define elf_backend_finish_dynamic_sections ppc_elf_finish_dynamic_sections
6212 #define elf_backend_fake_sections ppc_elf_fake_sections
6213 #define elf_backend_additional_program_headers ppc_elf_additional_program_headers
6214 #define elf_backend_grok_prstatus ppc_elf_grok_prstatus
6215 #define elf_backend_grok_psinfo ppc_elf_grok_psinfo
6216 #define elf_backend_reloc_type_class ppc_elf_reloc_type_class
6217 #define elf_backend_begin_write_processing ppc_elf_begin_write_processing
6218 #define elf_backend_final_write_processing ppc_elf_final_write_processing
6219 #define elf_backend_write_section ppc_elf_write_section
6220 #define elf_backend_special_sections ppc_elf_special_sections
6221 #define elf_backend_plt_sym_val ppc_elf_plt_sym_val
6223 #include "elf32-target.h"