1 /* PowerPC-specific support for 32-bit ELF
2 Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
3 Free Software Foundation, Inc.
4 Written by Ian Lance Taylor, Cygnus Support.
6 This file is part of BFD, the Binary File Descriptor library.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the
20 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
23 /* This file is based on a preliminary PowerPC ELF ABI. The
24 information may not match the final PowerPC ELF ABI. It includes
25 suggestions from the in-progress Embedded PowerPC ABI, and that
26 information may also not match. */
34 #include "elf32-ppc.h"
36 /* RELA relocations are used here. */
38 static 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
->elf_link_hash_flags
& ELF_LINK_HASH_DYNAMIC_ADJUSTED
) != 0)
333 /* If called to transfer flags for a weakdef during processing
334 of elf_adjust_dynamic_symbol, don't copy ELF_LINK_NON_GOT_REF.
335 We clear it ourselves for ELIMINATE_COPY_RELOCS. */
336 dir
->elf_link_hash_flags
|=
337 (ind
->elf_link_hash_flags
& (ELF_LINK_HASH_REF_DYNAMIC
338 | ELF_LINK_HASH_REF_REGULAR
339 | ELF_LINK_HASH_REF_REGULAR_NONWEAK
));
341 _bfd_elf_link_hash_copy_indirect (bed
, dir
, ind
);
344 static reloc_howto_type
*ppc_elf_howto_table
[R_PPC_max
];
346 static reloc_howto_type ppc_elf_howto_raw
[] = {
347 /* This reloc does nothing. */
348 HOWTO (R_PPC_NONE
, /* type */
350 2, /* size (0 = byte, 1 = short, 2 = long) */
352 FALSE
, /* pc_relative */
354 complain_overflow_bitfield
, /* complain_on_overflow */
355 bfd_elf_generic_reloc
, /* special_function */
356 "R_PPC_NONE", /* name */
357 FALSE
, /* partial_inplace */
360 FALSE
), /* pcrel_offset */
362 /* A standard 32 bit relocation. */
363 HOWTO (R_PPC_ADDR32
, /* type */
365 2, /* size (0 = byte, 1 = short, 2 = long) */
367 FALSE
, /* pc_relative */
369 complain_overflow_bitfield
, /* complain_on_overflow */
370 bfd_elf_generic_reloc
, /* special_function */
371 "R_PPC_ADDR32", /* name */
372 FALSE
, /* partial_inplace */
374 0xffffffff, /* dst_mask */
375 FALSE
), /* pcrel_offset */
377 /* An absolute 26 bit branch; the lower two bits must be zero.
378 FIXME: we don't check that, we just clear them. */
379 HOWTO (R_PPC_ADDR24
, /* type */
381 2, /* size (0 = byte, 1 = short, 2 = long) */
383 FALSE
, /* pc_relative */
385 complain_overflow_bitfield
, /* complain_on_overflow */
386 bfd_elf_generic_reloc
, /* special_function */
387 "R_PPC_ADDR24", /* name */
388 FALSE
, /* partial_inplace */
390 0x3fffffc, /* dst_mask */
391 FALSE
), /* pcrel_offset */
393 /* A standard 16 bit relocation. */
394 HOWTO (R_PPC_ADDR16
, /* type */
396 1, /* size (0 = byte, 1 = short, 2 = long) */
398 FALSE
, /* pc_relative */
400 complain_overflow_bitfield
, /* complain_on_overflow */
401 bfd_elf_generic_reloc
, /* special_function */
402 "R_PPC_ADDR16", /* name */
403 FALSE
, /* partial_inplace */
405 0xffff, /* dst_mask */
406 FALSE
), /* pcrel_offset */
408 /* A 16 bit relocation without overflow. */
409 HOWTO (R_PPC_ADDR16_LO
, /* type */
411 1, /* size (0 = byte, 1 = short, 2 = long) */
413 FALSE
, /* pc_relative */
415 complain_overflow_dont
,/* complain_on_overflow */
416 bfd_elf_generic_reloc
, /* special_function */
417 "R_PPC_ADDR16_LO", /* name */
418 FALSE
, /* partial_inplace */
420 0xffff, /* dst_mask */
421 FALSE
), /* pcrel_offset */
423 /* The high order 16 bits of an address. */
424 HOWTO (R_PPC_ADDR16_HI
, /* type */
426 1, /* size (0 = byte, 1 = short, 2 = long) */
428 FALSE
, /* pc_relative */
430 complain_overflow_dont
, /* complain_on_overflow */
431 bfd_elf_generic_reloc
, /* special_function */
432 "R_PPC_ADDR16_HI", /* name */
433 FALSE
, /* partial_inplace */
435 0xffff, /* dst_mask */
436 FALSE
), /* pcrel_offset */
438 /* The high order 16 bits of an address, plus 1 if the contents of
439 the low 16 bits, treated as a signed number, is negative. */
440 HOWTO (R_PPC_ADDR16_HA
, /* type */
442 1, /* size (0 = byte, 1 = short, 2 = long) */
444 FALSE
, /* pc_relative */
446 complain_overflow_dont
, /* complain_on_overflow */
447 ppc_elf_addr16_ha_reloc
, /* special_function */
448 "R_PPC_ADDR16_HA", /* name */
449 FALSE
, /* partial_inplace */
451 0xffff, /* dst_mask */
452 FALSE
), /* pcrel_offset */
454 /* An absolute 16 bit branch; the lower two bits must be zero.
455 FIXME: we don't check that, we just clear them. */
456 HOWTO (R_PPC_ADDR14
, /* type */
458 2, /* size (0 = byte, 1 = short, 2 = long) */
460 FALSE
, /* pc_relative */
462 complain_overflow_bitfield
, /* complain_on_overflow */
463 bfd_elf_generic_reloc
, /* special_function */
464 "R_PPC_ADDR14", /* name */
465 FALSE
, /* partial_inplace */
467 0xfffc, /* dst_mask */
468 FALSE
), /* pcrel_offset */
470 /* An absolute 16 bit branch, for which bit 10 should be set to
471 indicate that the branch is expected to be taken. The lower two
472 bits must be zero. */
473 HOWTO (R_PPC_ADDR14_BRTAKEN
, /* type */
475 2, /* size (0 = byte, 1 = short, 2 = long) */
477 FALSE
, /* pc_relative */
479 complain_overflow_bitfield
, /* complain_on_overflow */
480 bfd_elf_generic_reloc
, /* special_function */
481 "R_PPC_ADDR14_BRTAKEN",/* name */
482 FALSE
, /* partial_inplace */
484 0xfffc, /* dst_mask */
485 FALSE
), /* pcrel_offset */
487 /* An absolute 16 bit branch, for which bit 10 should be set to
488 indicate that the branch is not expected to be taken. The lower
489 two bits must be zero. */
490 HOWTO (R_PPC_ADDR14_BRNTAKEN
, /* type */
492 2, /* size (0 = byte, 1 = short, 2 = long) */
494 FALSE
, /* pc_relative */
496 complain_overflow_bitfield
, /* complain_on_overflow */
497 bfd_elf_generic_reloc
, /* special_function */
498 "R_PPC_ADDR14_BRNTAKEN",/* name */
499 FALSE
, /* partial_inplace */
501 0xfffc, /* dst_mask */
502 FALSE
), /* pcrel_offset */
504 /* A relative 26 bit branch; the lower two bits must be zero. */
505 HOWTO (R_PPC_REL24
, /* type */
507 2, /* size (0 = byte, 1 = short, 2 = long) */
509 TRUE
, /* pc_relative */
511 complain_overflow_signed
, /* complain_on_overflow */
512 bfd_elf_generic_reloc
, /* special_function */
513 "R_PPC_REL24", /* name */
514 FALSE
, /* partial_inplace */
516 0x3fffffc, /* dst_mask */
517 TRUE
), /* pcrel_offset */
519 /* A relative 16 bit branch; the lower two bits must be zero. */
520 HOWTO (R_PPC_REL14
, /* type */
522 2, /* size (0 = byte, 1 = short, 2 = long) */
524 TRUE
, /* pc_relative */
526 complain_overflow_signed
, /* complain_on_overflow */
527 bfd_elf_generic_reloc
, /* special_function */
528 "R_PPC_REL14", /* name */
529 FALSE
, /* partial_inplace */
531 0xfffc, /* dst_mask */
532 TRUE
), /* pcrel_offset */
534 /* A relative 16 bit branch. Bit 10 should be set to indicate that
535 the branch is expected to be taken. The lower two bits must be
537 HOWTO (R_PPC_REL14_BRTAKEN
, /* type */
539 2, /* size (0 = byte, 1 = short, 2 = long) */
541 TRUE
, /* pc_relative */
543 complain_overflow_signed
, /* complain_on_overflow */
544 bfd_elf_generic_reloc
, /* special_function */
545 "R_PPC_REL14_BRTAKEN", /* name */
546 FALSE
, /* partial_inplace */
548 0xfffc, /* dst_mask */
549 TRUE
), /* pcrel_offset */
551 /* A relative 16 bit branch. Bit 10 should be set to indicate that
552 the branch is not expected to be taken. The lower two bits must
554 HOWTO (R_PPC_REL14_BRNTAKEN
, /* type */
556 2, /* size (0 = byte, 1 = short, 2 = long) */
558 TRUE
, /* pc_relative */
560 complain_overflow_signed
, /* complain_on_overflow */
561 bfd_elf_generic_reloc
, /* special_function */
562 "R_PPC_REL14_BRNTAKEN",/* name */
563 FALSE
, /* partial_inplace */
565 0xfffc, /* dst_mask */
566 TRUE
), /* pcrel_offset */
568 /* Like R_PPC_ADDR16, but referring to the GOT table entry for the
570 HOWTO (R_PPC_GOT16
, /* type */
572 1, /* size (0 = byte, 1 = short, 2 = long) */
574 FALSE
, /* pc_relative */
576 complain_overflow_signed
, /* complain_on_overflow */
577 bfd_elf_generic_reloc
, /* special_function */
578 "R_PPC_GOT16", /* name */
579 FALSE
, /* partial_inplace */
581 0xffff, /* dst_mask */
582 FALSE
), /* pcrel_offset */
584 /* Like R_PPC_ADDR16_LO, but referring to the GOT table entry for
586 HOWTO (R_PPC_GOT16_LO
, /* type */
588 1, /* size (0 = byte, 1 = short, 2 = long) */
590 FALSE
, /* pc_relative */
592 complain_overflow_dont
, /* complain_on_overflow */
593 bfd_elf_generic_reloc
, /* special_function */
594 "R_PPC_GOT16_LO", /* name */
595 FALSE
, /* partial_inplace */
597 0xffff, /* dst_mask */
598 FALSE
), /* pcrel_offset */
600 /* Like R_PPC_ADDR16_HI, but referring to the GOT table entry for
602 HOWTO (R_PPC_GOT16_HI
, /* type */
604 1, /* size (0 = byte, 1 = short, 2 = long) */
606 FALSE
, /* pc_relative */
608 complain_overflow_bitfield
, /* complain_on_overflow */
609 bfd_elf_generic_reloc
, /* special_function */
610 "R_PPC_GOT16_HI", /* name */
611 FALSE
, /* partial_inplace */
613 0xffff, /* dst_mask */
614 FALSE
), /* pcrel_offset */
616 /* Like R_PPC_ADDR16_HA, but referring to the GOT table entry for
618 HOWTO (R_PPC_GOT16_HA
, /* type */
620 1, /* size (0 = byte, 1 = short, 2 = long) */
622 FALSE
, /* pc_relative */
624 complain_overflow_bitfield
, /* complain_on_overflow */
625 ppc_elf_addr16_ha_reloc
, /* special_function */
626 "R_PPC_GOT16_HA", /* name */
627 FALSE
, /* partial_inplace */
629 0xffff, /* dst_mask */
630 FALSE
), /* pcrel_offset */
632 /* Like R_PPC_REL24, but referring to the procedure linkage table
633 entry for the symbol. */
634 HOWTO (R_PPC_PLTREL24
, /* type */
636 2, /* size (0 = byte, 1 = short, 2 = long) */
638 TRUE
, /* pc_relative */
640 complain_overflow_signed
, /* complain_on_overflow */
641 bfd_elf_generic_reloc
, /* special_function */
642 "R_PPC_PLTREL24", /* name */
643 FALSE
, /* partial_inplace */
645 0x3fffffc, /* dst_mask */
646 TRUE
), /* pcrel_offset */
648 /* This is used only by the dynamic linker. The symbol should exist
649 both in the object being run and in some shared library. The
650 dynamic linker copies the data addressed by the symbol from the
651 shared library into the object, because the object being
652 run has to have the data at some particular address. */
653 HOWTO (R_PPC_COPY
, /* type */
655 2, /* size (0 = byte, 1 = short, 2 = long) */
657 FALSE
, /* pc_relative */
659 complain_overflow_bitfield
, /* complain_on_overflow */
660 bfd_elf_generic_reloc
, /* special_function */
661 "R_PPC_COPY", /* name */
662 FALSE
, /* partial_inplace */
665 FALSE
), /* pcrel_offset */
667 /* Like R_PPC_ADDR32, but used when setting global offset table
669 HOWTO (R_PPC_GLOB_DAT
, /* type */
671 2, /* size (0 = byte, 1 = short, 2 = long) */
673 FALSE
, /* pc_relative */
675 complain_overflow_bitfield
, /* complain_on_overflow */
676 bfd_elf_generic_reloc
, /* special_function */
677 "R_PPC_GLOB_DAT", /* name */
678 FALSE
, /* partial_inplace */
680 0xffffffff, /* dst_mask */
681 FALSE
), /* pcrel_offset */
683 /* Marks a procedure linkage table entry for a symbol. */
684 HOWTO (R_PPC_JMP_SLOT
, /* type */
686 2, /* size (0 = byte, 1 = short, 2 = long) */
688 FALSE
, /* pc_relative */
690 complain_overflow_bitfield
, /* complain_on_overflow */
691 bfd_elf_generic_reloc
, /* special_function */
692 "R_PPC_JMP_SLOT", /* name */
693 FALSE
, /* partial_inplace */
696 FALSE
), /* pcrel_offset */
698 /* Used only by the dynamic linker. When the object is run, this
699 longword is set to the load address of the object, plus the
701 HOWTO (R_PPC_RELATIVE
, /* type */
703 2, /* size (0 = byte, 1 = short, 2 = long) */
705 FALSE
, /* pc_relative */
707 complain_overflow_bitfield
, /* complain_on_overflow */
708 bfd_elf_generic_reloc
, /* special_function */
709 "R_PPC_RELATIVE", /* name */
710 FALSE
, /* partial_inplace */
712 0xffffffff, /* dst_mask */
713 FALSE
), /* pcrel_offset */
715 /* Like R_PPC_REL24, but uses the value of the symbol within the
716 object rather than the final value. Normally used for
717 _GLOBAL_OFFSET_TABLE_. */
718 HOWTO (R_PPC_LOCAL24PC
, /* type */
720 2, /* size (0 = byte, 1 = short, 2 = long) */
722 TRUE
, /* pc_relative */
724 complain_overflow_signed
, /* complain_on_overflow */
725 bfd_elf_generic_reloc
, /* special_function */
726 "R_PPC_LOCAL24PC", /* name */
727 FALSE
, /* partial_inplace */
729 0x3fffffc, /* dst_mask */
730 TRUE
), /* pcrel_offset */
732 /* Like R_PPC_ADDR32, but may be unaligned. */
733 HOWTO (R_PPC_UADDR32
, /* type */
735 2, /* size (0 = byte, 1 = short, 2 = long) */
737 FALSE
, /* pc_relative */
739 complain_overflow_bitfield
, /* complain_on_overflow */
740 bfd_elf_generic_reloc
, /* special_function */
741 "R_PPC_UADDR32", /* name */
742 FALSE
, /* partial_inplace */
744 0xffffffff, /* dst_mask */
745 FALSE
), /* pcrel_offset */
747 /* Like R_PPC_ADDR16, but may be unaligned. */
748 HOWTO (R_PPC_UADDR16
, /* type */
750 1, /* size (0 = byte, 1 = short, 2 = long) */
752 FALSE
, /* pc_relative */
754 complain_overflow_bitfield
, /* complain_on_overflow */
755 bfd_elf_generic_reloc
, /* special_function */
756 "R_PPC_UADDR16", /* name */
757 FALSE
, /* partial_inplace */
759 0xffff, /* dst_mask */
760 FALSE
), /* pcrel_offset */
762 /* 32-bit PC relative */
763 HOWTO (R_PPC_REL32
, /* type */
765 2, /* size (0 = byte, 1 = short, 2 = long) */
767 TRUE
, /* pc_relative */
769 complain_overflow_bitfield
, /* complain_on_overflow */
770 bfd_elf_generic_reloc
, /* special_function */
771 "R_PPC_REL32", /* name */
772 FALSE
, /* partial_inplace */
774 0xffffffff, /* dst_mask */
775 TRUE
), /* pcrel_offset */
777 /* 32-bit relocation to the symbol's procedure linkage table.
778 FIXME: not supported. */
779 HOWTO (R_PPC_PLT32
, /* type */
781 2, /* size (0 = byte, 1 = short, 2 = long) */
783 FALSE
, /* pc_relative */
785 complain_overflow_bitfield
, /* complain_on_overflow */
786 bfd_elf_generic_reloc
, /* special_function */
787 "R_PPC_PLT32", /* name */
788 FALSE
, /* partial_inplace */
791 FALSE
), /* pcrel_offset */
793 /* 32-bit PC relative relocation to the symbol's procedure linkage table.
794 FIXME: not supported. */
795 HOWTO (R_PPC_PLTREL32
, /* type */
797 2, /* size (0 = byte, 1 = short, 2 = long) */
799 TRUE
, /* pc_relative */
801 complain_overflow_bitfield
, /* complain_on_overflow */
802 bfd_elf_generic_reloc
, /* special_function */
803 "R_PPC_PLTREL32", /* name */
804 FALSE
, /* partial_inplace */
807 TRUE
), /* pcrel_offset */
809 /* Like R_PPC_ADDR16_LO, but referring to the PLT table entry for
811 HOWTO (R_PPC_PLT16_LO
, /* type */
813 1, /* size (0 = byte, 1 = short, 2 = long) */
815 FALSE
, /* pc_relative */
817 complain_overflow_dont
, /* complain_on_overflow */
818 bfd_elf_generic_reloc
, /* special_function */
819 "R_PPC_PLT16_LO", /* name */
820 FALSE
, /* partial_inplace */
822 0xffff, /* dst_mask */
823 FALSE
), /* pcrel_offset */
825 /* Like R_PPC_ADDR16_HI, but referring to the PLT table entry for
827 HOWTO (R_PPC_PLT16_HI
, /* type */
829 1, /* size (0 = byte, 1 = short, 2 = long) */
831 FALSE
, /* pc_relative */
833 complain_overflow_bitfield
, /* complain_on_overflow */
834 bfd_elf_generic_reloc
, /* special_function */
835 "R_PPC_PLT16_HI", /* name */
836 FALSE
, /* partial_inplace */
838 0xffff, /* dst_mask */
839 FALSE
), /* pcrel_offset */
841 /* Like R_PPC_ADDR16_HA, but referring to the PLT table entry for
843 HOWTO (R_PPC_PLT16_HA
, /* type */
845 1, /* size (0 = byte, 1 = short, 2 = long) */
847 FALSE
, /* pc_relative */
849 complain_overflow_bitfield
, /* complain_on_overflow */
850 ppc_elf_addr16_ha_reloc
, /* special_function */
851 "R_PPC_PLT16_HA", /* name */
852 FALSE
, /* partial_inplace */
854 0xffff, /* dst_mask */
855 FALSE
), /* pcrel_offset */
857 /* A sign-extended 16 bit value relative to _SDA_BASE_, for use with
859 HOWTO (R_PPC_SDAREL16
, /* type */
861 1, /* size (0 = byte, 1 = short, 2 = long) */
863 FALSE
, /* pc_relative */
865 complain_overflow_signed
, /* complain_on_overflow */
866 bfd_elf_generic_reloc
, /* special_function */
867 "R_PPC_SDAREL16", /* name */
868 FALSE
, /* partial_inplace */
870 0xffff, /* dst_mask */
871 FALSE
), /* pcrel_offset */
873 /* 16-bit section relative relocation. */
874 HOWTO (R_PPC_SECTOFF
, /* type */
876 1, /* size (0 = byte, 1 = short, 2 = long) */
878 FALSE
, /* pc_relative */
880 complain_overflow_bitfield
, /* complain_on_overflow */
881 bfd_elf_generic_reloc
, /* special_function */
882 "R_PPC_SECTOFF", /* name */
883 FALSE
, /* partial_inplace */
885 0xffff, /* dst_mask */
886 FALSE
), /* pcrel_offset */
888 /* 16-bit lower half section relative relocation. */
889 HOWTO (R_PPC_SECTOFF_LO
, /* type */
891 1, /* size (0 = byte, 1 = short, 2 = long) */
893 FALSE
, /* pc_relative */
895 complain_overflow_dont
, /* complain_on_overflow */
896 bfd_elf_generic_reloc
, /* special_function */
897 "R_PPC_SECTOFF_LO", /* name */
898 FALSE
, /* partial_inplace */
900 0xffff, /* dst_mask */
901 FALSE
), /* pcrel_offset */
903 /* 16-bit upper half section relative relocation. */
904 HOWTO (R_PPC_SECTOFF_HI
, /* type */
906 1, /* size (0 = byte, 1 = short, 2 = long) */
908 FALSE
, /* pc_relative */
910 complain_overflow_bitfield
, /* complain_on_overflow */
911 bfd_elf_generic_reloc
, /* special_function */
912 "R_PPC_SECTOFF_HI", /* name */
913 FALSE
, /* partial_inplace */
915 0xffff, /* dst_mask */
916 FALSE
), /* pcrel_offset */
918 /* 16-bit upper half adjusted section relative relocation. */
919 HOWTO (R_PPC_SECTOFF_HA
, /* type */
921 1, /* size (0 = byte, 1 = short, 2 = long) */
923 FALSE
, /* pc_relative */
925 complain_overflow_bitfield
, /* complain_on_overflow */
926 ppc_elf_addr16_ha_reloc
, /* special_function */
927 "R_PPC_SECTOFF_HA", /* name */
928 FALSE
, /* partial_inplace */
930 0xffff, /* dst_mask */
931 FALSE
), /* pcrel_offset */
933 /* Marker reloc for TLS. */
936 2, /* size (0 = byte, 1 = short, 2 = long) */
938 FALSE
, /* pc_relative */
940 complain_overflow_dont
, /* complain_on_overflow */
941 bfd_elf_generic_reloc
, /* special_function */
942 "R_PPC_TLS", /* name */
943 FALSE
, /* partial_inplace */
946 FALSE
), /* pcrel_offset */
948 /* Computes the load module index of the load module that contains the
949 definition of its TLS sym. */
950 HOWTO (R_PPC_DTPMOD32
,
952 2, /* size (0 = byte, 1 = short, 2 = long) */
954 FALSE
, /* pc_relative */
956 complain_overflow_dont
, /* complain_on_overflow */
957 ppc_elf_unhandled_reloc
, /* special_function */
958 "R_PPC_DTPMOD32", /* name */
959 FALSE
, /* partial_inplace */
961 0xffffffff, /* dst_mask */
962 FALSE
), /* pcrel_offset */
964 /* Computes a dtv-relative displacement, the difference between the value
965 of sym+add and the base address of the thread-local storage block that
966 contains the definition of sym, minus 0x8000. */
967 HOWTO (R_PPC_DTPREL32
,
969 2, /* size (0 = byte, 1 = short, 2 = long) */
971 FALSE
, /* pc_relative */
973 complain_overflow_dont
, /* complain_on_overflow */
974 ppc_elf_unhandled_reloc
, /* special_function */
975 "R_PPC_DTPREL32", /* name */
976 FALSE
, /* partial_inplace */
978 0xffffffff, /* dst_mask */
979 FALSE
), /* pcrel_offset */
981 /* A 16 bit dtprel reloc. */
982 HOWTO (R_PPC_DTPREL16
,
984 1, /* size (0 = byte, 1 = short, 2 = long) */
986 FALSE
, /* pc_relative */
988 complain_overflow_signed
, /* complain_on_overflow */
989 ppc_elf_unhandled_reloc
, /* special_function */
990 "R_PPC_DTPREL16", /* name */
991 FALSE
, /* partial_inplace */
993 0xffff, /* dst_mask */
994 FALSE
), /* pcrel_offset */
996 /* Like DTPREL16, but no overflow. */
997 HOWTO (R_PPC_DTPREL16_LO
,
999 1, /* size (0 = byte, 1 = short, 2 = long) */
1001 FALSE
, /* pc_relative */
1003 complain_overflow_dont
, /* complain_on_overflow */
1004 ppc_elf_unhandled_reloc
, /* special_function */
1005 "R_PPC_DTPREL16_LO", /* name */
1006 FALSE
, /* partial_inplace */
1008 0xffff, /* dst_mask */
1009 FALSE
), /* pcrel_offset */
1011 /* Like DTPREL16_LO, but next higher group of 16 bits. */
1012 HOWTO (R_PPC_DTPREL16_HI
,
1013 16, /* rightshift */
1014 1, /* size (0 = byte, 1 = short, 2 = long) */
1016 FALSE
, /* pc_relative */
1018 complain_overflow_dont
, /* complain_on_overflow */
1019 ppc_elf_unhandled_reloc
, /* special_function */
1020 "R_PPC_DTPREL16_HI", /* name */
1021 FALSE
, /* partial_inplace */
1023 0xffff, /* dst_mask */
1024 FALSE
), /* pcrel_offset */
1026 /* Like DTPREL16_HI, but adjust for low 16 bits. */
1027 HOWTO (R_PPC_DTPREL16_HA
,
1028 16, /* rightshift */
1029 1, /* size (0 = byte, 1 = short, 2 = long) */
1031 FALSE
, /* pc_relative */
1033 complain_overflow_dont
, /* complain_on_overflow */
1034 ppc_elf_unhandled_reloc
, /* special_function */
1035 "R_PPC_DTPREL16_HA", /* name */
1036 FALSE
, /* partial_inplace */
1038 0xffff, /* dst_mask */
1039 FALSE
), /* pcrel_offset */
1041 /* Computes a tp-relative displacement, the difference between the value of
1042 sym+add and the value of the thread pointer (r13). */
1043 HOWTO (R_PPC_TPREL32
,
1045 2, /* size (0 = byte, 1 = short, 2 = long) */
1047 FALSE
, /* pc_relative */
1049 complain_overflow_dont
, /* complain_on_overflow */
1050 ppc_elf_unhandled_reloc
, /* special_function */
1051 "R_PPC_TPREL32", /* name */
1052 FALSE
, /* partial_inplace */
1054 0xffffffff, /* dst_mask */
1055 FALSE
), /* pcrel_offset */
1057 /* A 16 bit tprel reloc. */
1058 HOWTO (R_PPC_TPREL16
,
1060 1, /* size (0 = byte, 1 = short, 2 = long) */
1062 FALSE
, /* pc_relative */
1064 complain_overflow_signed
, /* complain_on_overflow */
1065 ppc_elf_unhandled_reloc
, /* special_function */
1066 "R_PPC_TPREL16", /* name */
1067 FALSE
, /* partial_inplace */
1069 0xffff, /* dst_mask */
1070 FALSE
), /* pcrel_offset */
1072 /* Like TPREL16, but no overflow. */
1073 HOWTO (R_PPC_TPREL16_LO
,
1075 1, /* size (0 = byte, 1 = short, 2 = long) */
1077 FALSE
, /* pc_relative */
1079 complain_overflow_dont
, /* complain_on_overflow */
1080 ppc_elf_unhandled_reloc
, /* special_function */
1081 "R_PPC_TPREL16_LO", /* name */
1082 FALSE
, /* partial_inplace */
1084 0xffff, /* dst_mask */
1085 FALSE
), /* pcrel_offset */
1087 /* Like TPREL16_LO, but next higher group of 16 bits. */
1088 HOWTO (R_PPC_TPREL16_HI
,
1089 16, /* rightshift */
1090 1, /* size (0 = byte, 1 = short, 2 = long) */
1092 FALSE
, /* pc_relative */
1094 complain_overflow_dont
, /* complain_on_overflow */
1095 ppc_elf_unhandled_reloc
, /* special_function */
1096 "R_PPC_TPREL16_HI", /* name */
1097 FALSE
, /* partial_inplace */
1099 0xffff, /* dst_mask */
1100 FALSE
), /* pcrel_offset */
1102 /* Like TPREL16_HI, but adjust for low 16 bits. */
1103 HOWTO (R_PPC_TPREL16_HA
,
1104 16, /* rightshift */
1105 1, /* size (0 = byte, 1 = short, 2 = long) */
1107 FALSE
, /* pc_relative */
1109 complain_overflow_dont
, /* complain_on_overflow */
1110 ppc_elf_unhandled_reloc
, /* special_function */
1111 "R_PPC_TPREL16_HA", /* name */
1112 FALSE
, /* partial_inplace */
1114 0xffff, /* dst_mask */
1115 FALSE
), /* pcrel_offset */
1117 /* Allocates two contiguous entries in the GOT to hold a tls_index structure,
1118 with values (sym+add)@dtpmod and (sym+add)@dtprel, and computes the offset
1119 to the first entry. */
1120 HOWTO (R_PPC_GOT_TLSGD16
,
1122 1, /* size (0 = byte, 1 = short, 2 = long) */
1124 FALSE
, /* pc_relative */
1126 complain_overflow_signed
, /* complain_on_overflow */
1127 ppc_elf_unhandled_reloc
, /* special_function */
1128 "R_PPC_GOT_TLSGD16", /* name */
1129 FALSE
, /* partial_inplace */
1131 0xffff, /* dst_mask */
1132 FALSE
), /* pcrel_offset */
1134 /* Like GOT_TLSGD16, but no overflow. */
1135 HOWTO (R_PPC_GOT_TLSGD16_LO
,
1137 1, /* size (0 = byte, 1 = short, 2 = long) */
1139 FALSE
, /* pc_relative */
1141 complain_overflow_dont
, /* complain_on_overflow */
1142 ppc_elf_unhandled_reloc
, /* special_function */
1143 "R_PPC_GOT_TLSGD16_LO", /* name */
1144 FALSE
, /* partial_inplace */
1146 0xffff, /* dst_mask */
1147 FALSE
), /* pcrel_offset */
1149 /* Like GOT_TLSGD16_LO, but next higher group of 16 bits. */
1150 HOWTO (R_PPC_GOT_TLSGD16_HI
,
1151 16, /* rightshift */
1152 1, /* size (0 = byte, 1 = short, 2 = long) */
1154 FALSE
, /* pc_relative */
1156 complain_overflow_dont
, /* complain_on_overflow */
1157 ppc_elf_unhandled_reloc
, /* special_function */
1158 "R_PPC_GOT_TLSGD16_HI", /* name */
1159 FALSE
, /* partial_inplace */
1161 0xffff, /* dst_mask */
1162 FALSE
), /* pcrel_offset */
1164 /* Like GOT_TLSGD16_HI, but adjust for low 16 bits. */
1165 HOWTO (R_PPC_GOT_TLSGD16_HA
,
1166 16, /* rightshift */
1167 1, /* size (0 = byte, 1 = short, 2 = long) */
1169 FALSE
, /* pc_relative */
1171 complain_overflow_dont
, /* complain_on_overflow */
1172 ppc_elf_unhandled_reloc
, /* special_function */
1173 "R_PPC_GOT_TLSGD16_HA", /* name */
1174 FALSE
, /* partial_inplace */
1176 0xffff, /* dst_mask */
1177 FALSE
), /* pcrel_offset */
1179 /* Allocates two contiguous entries in the GOT to hold a tls_index structure,
1180 with values (sym+add)@dtpmod and zero, and computes the offset to the
1182 HOWTO (R_PPC_GOT_TLSLD16
,
1184 1, /* size (0 = byte, 1 = short, 2 = long) */
1186 FALSE
, /* pc_relative */
1188 complain_overflow_signed
, /* complain_on_overflow */
1189 ppc_elf_unhandled_reloc
, /* special_function */
1190 "R_PPC_GOT_TLSLD16", /* name */
1191 FALSE
, /* partial_inplace */
1193 0xffff, /* dst_mask */
1194 FALSE
), /* pcrel_offset */
1196 /* Like GOT_TLSLD16, but no overflow. */
1197 HOWTO (R_PPC_GOT_TLSLD16_LO
,
1199 1, /* size (0 = byte, 1 = short, 2 = long) */
1201 FALSE
, /* pc_relative */
1203 complain_overflow_dont
, /* complain_on_overflow */
1204 ppc_elf_unhandled_reloc
, /* special_function */
1205 "R_PPC_GOT_TLSLD16_LO", /* name */
1206 FALSE
, /* partial_inplace */
1208 0xffff, /* dst_mask */
1209 FALSE
), /* pcrel_offset */
1211 /* Like GOT_TLSLD16_LO, but next higher group of 16 bits. */
1212 HOWTO (R_PPC_GOT_TLSLD16_HI
,
1213 16, /* rightshift */
1214 1, /* size (0 = byte, 1 = short, 2 = long) */
1216 FALSE
, /* pc_relative */
1218 complain_overflow_dont
, /* complain_on_overflow */
1219 ppc_elf_unhandled_reloc
, /* special_function */
1220 "R_PPC_GOT_TLSLD16_HI", /* name */
1221 FALSE
, /* partial_inplace */
1223 0xffff, /* dst_mask */
1224 FALSE
), /* pcrel_offset */
1226 /* Like GOT_TLSLD16_HI, but adjust for low 16 bits. */
1227 HOWTO (R_PPC_GOT_TLSLD16_HA
,
1228 16, /* rightshift */
1229 1, /* size (0 = byte, 1 = short, 2 = long) */
1231 FALSE
, /* pc_relative */
1233 complain_overflow_dont
, /* complain_on_overflow */
1234 ppc_elf_unhandled_reloc
, /* special_function */
1235 "R_PPC_GOT_TLSLD16_HA", /* name */
1236 FALSE
, /* partial_inplace */
1238 0xffff, /* dst_mask */
1239 FALSE
), /* pcrel_offset */
1241 /* Allocates an entry in the GOT with value (sym+add)@dtprel, and computes
1242 the offset to the entry. */
1243 HOWTO (R_PPC_GOT_DTPREL16
,
1245 1, /* size (0 = byte, 1 = short, 2 = long) */
1247 FALSE
, /* pc_relative */
1249 complain_overflow_signed
, /* complain_on_overflow */
1250 ppc_elf_unhandled_reloc
, /* special_function */
1251 "R_PPC_GOT_DTPREL16", /* name */
1252 FALSE
, /* partial_inplace */
1254 0xffff, /* dst_mask */
1255 FALSE
), /* pcrel_offset */
1257 /* Like GOT_DTPREL16, but no overflow. */
1258 HOWTO (R_PPC_GOT_DTPREL16_LO
,
1260 1, /* size (0 = byte, 1 = short, 2 = long) */
1262 FALSE
, /* pc_relative */
1264 complain_overflow_dont
, /* complain_on_overflow */
1265 ppc_elf_unhandled_reloc
, /* special_function */
1266 "R_PPC_GOT_DTPREL16_LO", /* name */
1267 FALSE
, /* partial_inplace */
1269 0xffff, /* dst_mask */
1270 FALSE
), /* pcrel_offset */
1272 /* Like GOT_DTPREL16_LO, but next higher group of 16 bits. */
1273 HOWTO (R_PPC_GOT_DTPREL16_HI
,
1274 16, /* rightshift */
1275 1, /* size (0 = byte, 1 = short, 2 = long) */
1277 FALSE
, /* pc_relative */
1279 complain_overflow_dont
, /* complain_on_overflow */
1280 ppc_elf_unhandled_reloc
, /* special_function */
1281 "R_PPC_GOT_DTPREL16_HI", /* name */
1282 FALSE
, /* partial_inplace */
1284 0xffff, /* dst_mask */
1285 FALSE
), /* pcrel_offset */
1287 /* Like GOT_DTPREL16_HI, but adjust for low 16 bits. */
1288 HOWTO (R_PPC_GOT_DTPREL16_HA
,
1289 16, /* rightshift */
1290 1, /* size (0 = byte, 1 = short, 2 = long) */
1292 FALSE
, /* pc_relative */
1294 complain_overflow_dont
, /* complain_on_overflow */
1295 ppc_elf_unhandled_reloc
, /* special_function */
1296 "R_PPC_GOT_DTPREL16_HA", /* name */
1297 FALSE
, /* partial_inplace */
1299 0xffff, /* dst_mask */
1300 FALSE
), /* pcrel_offset */
1302 /* Allocates an entry in the GOT with value (sym+add)@tprel, and computes the
1303 offset to the entry. */
1304 HOWTO (R_PPC_GOT_TPREL16
,
1306 1, /* size (0 = byte, 1 = short, 2 = long) */
1308 FALSE
, /* pc_relative */
1310 complain_overflow_signed
, /* complain_on_overflow */
1311 ppc_elf_unhandled_reloc
, /* special_function */
1312 "R_PPC_GOT_TPREL16", /* name */
1313 FALSE
, /* partial_inplace */
1315 0xffff, /* dst_mask */
1316 FALSE
), /* pcrel_offset */
1318 /* Like GOT_TPREL16, but no overflow. */
1319 HOWTO (R_PPC_GOT_TPREL16_LO
,
1321 1, /* size (0 = byte, 1 = short, 2 = long) */
1323 FALSE
, /* pc_relative */
1325 complain_overflow_dont
, /* complain_on_overflow */
1326 ppc_elf_unhandled_reloc
, /* special_function */
1327 "R_PPC_GOT_TPREL16_LO", /* name */
1328 FALSE
, /* partial_inplace */
1330 0xffff, /* dst_mask */
1331 FALSE
), /* pcrel_offset */
1333 /* Like GOT_TPREL16_LO, but next higher group of 16 bits. */
1334 HOWTO (R_PPC_GOT_TPREL16_HI
,
1335 16, /* rightshift */
1336 1, /* size (0 = byte, 1 = short, 2 = long) */
1338 FALSE
, /* pc_relative */
1340 complain_overflow_dont
, /* complain_on_overflow */
1341 ppc_elf_unhandled_reloc
, /* special_function */
1342 "R_PPC_GOT_TPREL16_HI", /* name */
1343 FALSE
, /* partial_inplace */
1345 0xffff, /* dst_mask */
1346 FALSE
), /* pcrel_offset */
1348 /* Like GOT_TPREL16_HI, but adjust for low 16 bits. */
1349 HOWTO (R_PPC_GOT_TPREL16_HA
,
1350 16, /* rightshift */
1351 1, /* size (0 = byte, 1 = short, 2 = long) */
1353 FALSE
, /* pc_relative */
1355 complain_overflow_dont
, /* complain_on_overflow */
1356 ppc_elf_unhandled_reloc
, /* special_function */
1357 "R_PPC_GOT_TPREL16_HA", /* name */
1358 FALSE
, /* partial_inplace */
1360 0xffff, /* dst_mask */
1361 FALSE
), /* pcrel_offset */
1363 /* The remaining relocs are from the Embedded ELF ABI, and are not
1364 in the SVR4 ELF ABI. */
1366 /* 32 bit value resulting from the addend minus the symbol. */
1367 HOWTO (R_PPC_EMB_NADDR32
, /* type */
1369 2, /* size (0 = byte, 1 = short, 2 = long) */
1371 FALSE
, /* pc_relative */
1373 complain_overflow_bitfield
, /* complain_on_overflow */
1374 bfd_elf_generic_reloc
, /* special_function */
1375 "R_PPC_EMB_NADDR32", /* name */
1376 FALSE
, /* partial_inplace */
1378 0xffffffff, /* dst_mask */
1379 FALSE
), /* pcrel_offset */
1381 /* 16 bit value resulting from the addend minus the symbol. */
1382 HOWTO (R_PPC_EMB_NADDR16
, /* type */
1384 1, /* size (0 = byte, 1 = short, 2 = long) */
1386 FALSE
, /* pc_relative */
1388 complain_overflow_bitfield
, /* complain_on_overflow */
1389 bfd_elf_generic_reloc
, /* special_function */
1390 "R_PPC_EMB_NADDR16", /* name */
1391 FALSE
, /* partial_inplace */
1393 0xffff, /* dst_mask */
1394 FALSE
), /* pcrel_offset */
1396 /* 16 bit value resulting from the addend minus the symbol. */
1397 HOWTO (R_PPC_EMB_NADDR16_LO
, /* type */
1399 1, /* size (0 = byte, 1 = short, 2 = long) */
1401 FALSE
, /* pc_relative */
1403 complain_overflow_dont
,/* complain_on_overflow */
1404 bfd_elf_generic_reloc
, /* special_function */
1405 "R_PPC_EMB_ADDR16_LO", /* name */
1406 FALSE
, /* partial_inplace */
1408 0xffff, /* dst_mask */
1409 FALSE
), /* pcrel_offset */
1411 /* The high order 16 bits of the addend minus the symbol. */
1412 HOWTO (R_PPC_EMB_NADDR16_HI
, /* type */
1413 16, /* rightshift */
1414 1, /* size (0 = byte, 1 = short, 2 = long) */
1416 FALSE
, /* pc_relative */
1418 complain_overflow_dont
, /* complain_on_overflow */
1419 bfd_elf_generic_reloc
, /* special_function */
1420 "R_PPC_EMB_NADDR16_HI", /* name */
1421 FALSE
, /* partial_inplace */
1423 0xffff, /* dst_mask */
1424 FALSE
), /* pcrel_offset */
1426 /* The high order 16 bits of the result of the addend minus the address,
1427 plus 1 if the contents of the low 16 bits, treated as a signed number,
1429 HOWTO (R_PPC_EMB_NADDR16_HA
, /* type */
1430 16, /* rightshift */
1431 1, /* size (0 = byte, 1 = short, 2 = long) */
1433 FALSE
, /* pc_relative */
1435 complain_overflow_dont
, /* complain_on_overflow */
1436 ppc_elf_addr16_ha_reloc
, /* special_function */
1437 "R_PPC_EMB_NADDR16_HA", /* name */
1438 FALSE
, /* partial_inplace */
1440 0xffff, /* dst_mask */
1441 FALSE
), /* pcrel_offset */
1443 /* 16 bit value resulting from allocating a 4 byte word to hold an
1444 address in the .sdata section, and returning the offset from
1445 _SDA_BASE_ for that relocation. */
1446 HOWTO (R_PPC_EMB_SDAI16
, /* type */
1448 1, /* size (0 = byte, 1 = short, 2 = long) */
1450 FALSE
, /* pc_relative */
1452 complain_overflow_bitfield
, /* complain_on_overflow */
1453 bfd_elf_generic_reloc
, /* special_function */
1454 "R_PPC_EMB_SDAI16", /* name */
1455 FALSE
, /* partial_inplace */
1457 0xffff, /* dst_mask */
1458 FALSE
), /* pcrel_offset */
1460 /* 16 bit value resulting from allocating a 4 byte word to hold an
1461 address in the .sdata2 section, and returning the offset from
1462 _SDA2_BASE_ for that relocation. */
1463 HOWTO (R_PPC_EMB_SDA2I16
, /* type */
1465 1, /* size (0 = byte, 1 = short, 2 = long) */
1467 FALSE
, /* pc_relative */
1469 complain_overflow_bitfield
, /* complain_on_overflow */
1470 bfd_elf_generic_reloc
, /* special_function */
1471 "R_PPC_EMB_SDA2I16", /* name */
1472 FALSE
, /* partial_inplace */
1474 0xffff, /* dst_mask */
1475 FALSE
), /* pcrel_offset */
1477 /* A sign-extended 16 bit value relative to _SDA2_BASE_, for use with
1478 small data items. */
1479 HOWTO (R_PPC_EMB_SDA2REL
, /* type */
1481 1, /* size (0 = byte, 1 = short, 2 = long) */
1483 FALSE
, /* pc_relative */
1485 complain_overflow_signed
, /* complain_on_overflow */
1486 bfd_elf_generic_reloc
, /* special_function */
1487 "R_PPC_EMB_SDA2REL", /* name */
1488 FALSE
, /* partial_inplace */
1490 0xffff, /* dst_mask */
1491 FALSE
), /* pcrel_offset */
1493 /* Relocate against either _SDA_BASE_ or _SDA2_BASE_, filling in the 16 bit
1494 signed offset from the appropriate base, and filling in the register
1495 field with the appropriate register (0, 2, or 13). */
1496 HOWTO (R_PPC_EMB_SDA21
, /* type */
1498 2, /* size (0 = byte, 1 = short, 2 = long) */
1500 FALSE
, /* pc_relative */
1502 complain_overflow_signed
, /* complain_on_overflow */
1503 bfd_elf_generic_reloc
, /* special_function */
1504 "R_PPC_EMB_SDA21", /* name */
1505 FALSE
, /* partial_inplace */
1507 0xffff, /* dst_mask */
1508 FALSE
), /* pcrel_offset */
1510 /* Relocation not handled: R_PPC_EMB_MRKREF */
1511 /* Relocation not handled: R_PPC_EMB_RELSEC16 */
1512 /* Relocation not handled: R_PPC_EMB_RELST_LO */
1513 /* Relocation not handled: R_PPC_EMB_RELST_HI */
1514 /* Relocation not handled: R_PPC_EMB_RELST_HA */
1515 /* Relocation not handled: R_PPC_EMB_BIT_FLD */
1517 /* PC relative relocation against either _SDA_BASE_ or _SDA2_BASE_, filling
1518 in the 16 bit signed offset from the appropriate base, and filling in the
1519 register field with the appropriate register (0, 2, or 13). */
1520 HOWTO (R_PPC_EMB_RELSDA
, /* type */
1522 1, /* size (0 = byte, 1 = short, 2 = long) */
1524 TRUE
, /* pc_relative */
1526 complain_overflow_signed
, /* complain_on_overflow */
1527 bfd_elf_generic_reloc
, /* special_function */
1528 "R_PPC_EMB_RELSDA", /* name */
1529 FALSE
, /* partial_inplace */
1531 0xffff, /* dst_mask */
1532 FALSE
), /* pcrel_offset */
1534 /* Phony relocs to handle branch stubs. */
1535 HOWTO (R_PPC_RELAX32
, /* type */
1539 FALSE
, /* pc_relative */
1541 complain_overflow_dont
, /* complain_on_overflow */
1542 bfd_elf_generic_reloc
, /* special_function */
1543 "R_PPC_RELAX32", /* name */
1544 FALSE
, /* partial_inplace */
1547 FALSE
), /* pcrel_offset */
1549 HOWTO (R_PPC_RELAX32PC
, /* type */
1553 FALSE
, /* pc_relative */
1555 complain_overflow_dont
, /* complain_on_overflow */
1556 bfd_elf_generic_reloc
, /* special_function */
1557 "R_PPC_RELAX32PC", /* name */
1558 FALSE
, /* partial_inplace */
1561 FALSE
), /* pcrel_offset */
1563 /* GNU extension to record C++ vtable hierarchy. */
1564 HOWTO (R_PPC_GNU_VTINHERIT
, /* type */
1566 0, /* size (0 = byte, 1 = short, 2 = long) */
1568 FALSE
, /* pc_relative */
1570 complain_overflow_dont
, /* complain_on_overflow */
1571 NULL
, /* special_function */
1572 "R_PPC_GNU_VTINHERIT", /* name */
1573 FALSE
, /* partial_inplace */
1576 FALSE
), /* pcrel_offset */
1578 /* GNU extension to record C++ vtable member usage. */
1579 HOWTO (R_PPC_GNU_VTENTRY
, /* type */
1581 0, /* size (0 = byte, 1 = short, 2 = long) */
1583 FALSE
, /* pc_relative */
1585 complain_overflow_dont
, /* complain_on_overflow */
1586 NULL
, /* special_function */
1587 "R_PPC_GNU_VTENTRY", /* name */
1588 FALSE
, /* partial_inplace */
1591 FALSE
), /* pcrel_offset */
1593 /* Phony reloc to handle AIX style TOC entries. */
1594 HOWTO (R_PPC_TOC16
, /* type */
1596 1, /* size (0 = byte, 1 = short, 2 = long) */
1598 FALSE
, /* pc_relative */
1600 complain_overflow_signed
, /* complain_on_overflow */
1601 bfd_elf_generic_reloc
, /* special_function */
1602 "R_PPC_TOC16", /* name */
1603 FALSE
, /* partial_inplace */
1605 0xffff, /* dst_mask */
1606 FALSE
), /* pcrel_offset */
1609 /* Initialize the ppc_elf_howto_table, so that linear accesses can be done. */
1612 ppc_elf_howto_init (void)
1614 unsigned int i
, type
;
1617 i
< sizeof (ppc_elf_howto_raw
) / sizeof (ppc_elf_howto_raw
[0]);
1620 type
= ppc_elf_howto_raw
[i
].type
;
1621 if (type
>= (sizeof (ppc_elf_howto_table
)
1622 / sizeof (ppc_elf_howto_table
[0])))
1624 ppc_elf_howto_table
[type
] = &ppc_elf_howto_raw
[i
];
1628 static bfd_reloc_status_type
1629 ppc_elf_install_value (bfd
*abfd
,
1632 unsigned int r_type
)
1635 #ifdef BFD_HOST_U_64_BIT
1636 BFD_HOST_U_64_BIT val
= (BFD_HOST_U_64_BIT
) v
;
1644 case R_PPC_RELAX32PC
:
1645 t0
= bfd_get_32 (abfd
, hit_addr
);
1646 t1
= bfd_get_32 (abfd
, hit_addr
+ 4);
1648 /* We're clearing the bits for R_PPC_ADDR16_HA
1649 and R_PPC_ADDR16_LO here. */
1653 /* t0 is HA, t1 is lo */
1654 t0
|= ((val
+ 0x8000) >> 16) & 0xffff;
1657 bfd_put_32 (abfd
, t0
, hit_addr
);
1658 bfd_put_32 (abfd
, t1
, hit_addr
+ 4);
1662 case R_PPC_LOCAL24PC
:
1663 case R_PPC_PLTREL24
:
1664 t0
= bfd_get_32 (abfd
, hit_addr
);
1666 t0
|= val
& 0x3fffffc;
1667 bfd_put_32 (abfd
, t0
, hit_addr
);
1671 case R_PPC_REL14_BRTAKEN
:
1672 case R_PPC_REL14_BRNTAKEN
:
1673 t0
= bfd_get_32 (abfd
, hit_addr
);
1676 bfd_put_32 (abfd
, t0
, hit_addr
);
1680 return bfd_reloc_notsupported
;
1683 return bfd_reloc_ok
;
1686 static const bfd_byte shared_stub_entry
[] =
1688 0x48, 0x00, 0x00, 0x24, /* b .+36 */
1689 0x7c, 0x08, 0x02, 0xa6, /* mflr 0 */
1690 0x42, 0x9f, 0x00, 0x05, /* bcl 20, 31, .Lxxx */
1691 0x7d, 0x68, 0x02, 0xa6, /* mflr 11 */
1692 0x3d, 0x6b, 0x00, 0x00, /* addis 11, 11, (xxx-.Lxxx)@ha */
1693 0x39, 0x6b, 0x00, 0x18, /* addi 11, 11, (xxx-.Lxxx)@l */
1694 0x7c, 0x08, 0x03, 0xa6, /* mtlr 0 */
1695 0x7d, 0x69, 0x03, 0xa6, /* mtctr 11 */
1696 0x4e, 0x80, 0x04, 0x20, /* bctr */
1699 static const bfd_byte stub_entry
[] =
1701 0x48, 0x00, 0x00, 0x14, /* b .+20 */
1702 0x3d, 0x60, 0x00, 0x00, /* lis 11,xxx@ha */
1703 0x39, 0x6b, 0x00, 0x00, /* addi 11,11,xxx@l */
1704 0x7d, 0x69, 0x03, 0xa6, /* mtctr 11 */
1705 0x4e, 0x80, 0x04, 0x20, /* bctr */
1710 ppc_elf_relax_section (bfd
*abfd
,
1712 struct bfd_link_info
*link_info
,
1717 struct one_fixup
*next
;
1723 Elf_Internal_Shdr
*symtab_hdr
;
1724 bfd_byte
*contents
= NULL
;
1725 Elf_Internal_Sym
*isymbuf
= NULL
;
1726 Elf_Internal_Rela
*internal_relocs
= NULL
;
1727 Elf_Internal_Rela
*irel
, *irelend
;
1728 struct one_fixup
*fixups
= NULL
;
1729 bfd_boolean changed_contents
= FALSE
;
1730 bfd_boolean changed_relocs
= FALSE
;
1731 struct ppc_elf_link_hash_table
*ppc_info
;
1735 /* Nothing to do if there are no relocations and no need for
1736 the relax finalize pass. */
1737 if ((isec
->flags
& SEC_RELOC
) == 0
1738 || isec
->reloc_count
== 0
1739 || link_info
->relax_finalizing
)
1742 /* If needed, initialize this section's cooked size. */
1743 if (isec
->_cooked_size
== 0)
1744 isec
->_cooked_size
= isec
->_raw_size
;
1746 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
1748 /* Get a copy of the native relocations. */
1749 internal_relocs
= _bfd_elf_link_read_relocs (abfd
, isec
, NULL
, NULL
,
1750 link_info
->keep_memory
);
1751 if (internal_relocs
== NULL
)
1754 ppc_info
= ppc_elf_hash_table (link_info
);
1755 irelend
= internal_relocs
+ isec
->reloc_count
;
1757 /* Get the section contents. */
1758 /* Get cached copy if it exists. */
1759 if (elf_section_data (isec
)->this_hdr
.contents
!= NULL
)
1760 contents
= elf_section_data (isec
)->this_hdr
.contents
;
1763 /* Go get them off disk. */
1764 contents
= bfd_malloc (isec
->_raw_size
);
1765 if (contents
== NULL
)
1768 if (!bfd_get_section_contents (abfd
, isec
, contents
, 0, isec
->_raw_size
))
1772 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
1774 unsigned long r_type
= ELF32_R_TYPE (irel
->r_info
);
1775 bfd_vma symaddr
, reladdr
, trampoff
, toff
, roff
;
1778 struct one_fixup
*f
;
1779 size_t insn_offset
= 0;
1780 bfd_vma max_branch_offset
;
1785 case R_PPC_LOCAL24PC
:
1787 case R_PPC_REL14_BRTAKEN
:
1788 case R_PPC_REL14_BRNTAKEN
:
1789 case R_PPC_PLTREL24
:
1796 /* Get the value of the symbol referred to by the reloc. */
1797 if (ELF32_R_SYM (irel
->r_info
) < symtab_hdr
->sh_info
)
1799 /* A local symbol. */
1800 Elf_Internal_Sym
*isym
;
1802 /* Read this BFD's local symbols. */
1803 if (isymbuf
== NULL
)
1805 isymbuf
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
1806 if (isymbuf
== NULL
)
1807 isymbuf
= bfd_elf_get_elf_syms (abfd
, symtab_hdr
,
1808 symtab_hdr
->sh_info
, 0,
1813 isym
= isymbuf
+ ELF32_R_SYM (irel
->r_info
);
1814 if (isym
->st_shndx
== SHN_UNDEF
)
1815 continue; /* We can't do anthing with undefined symbols. */
1816 else if (isym
->st_shndx
== SHN_ABS
)
1817 tsec
= bfd_abs_section_ptr
;
1818 else if (isym
->st_shndx
== SHN_COMMON
)
1819 tsec
= bfd_com_section_ptr
;
1821 tsec
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
1823 toff
= isym
->st_value
;
1827 /* Need dynamic symbol handling. */
1829 struct elf_link_hash_entry
*h
;
1831 indx
= ELF32_R_SYM (irel
->r_info
) - symtab_hdr
->sh_info
;
1832 h
= elf_sym_hashes (abfd
)[indx
];
1834 while (h
->root
.type
== bfd_link_hash_indirect
1835 || h
->root
.type
== bfd_link_hash_warning
)
1836 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1838 if (r_type
== R_PPC_PLTREL24
)
1840 Elf_Internal_Sym
*isym
;
1842 if (h
->plt
.offset
== (bfd_vma
) -1
1843 || ppc_info
->plt
== NULL
)
1846 /* Read this BFD's local symbols. */
1847 if (isymbuf
== NULL
)
1849 isymbuf
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
1850 if (isymbuf
== NULL
)
1851 isymbuf
= bfd_elf_get_elf_syms (abfd
, symtab_hdr
,
1852 symtab_hdr
->sh_info
, 0,
1857 isym
= isymbuf
+ ELF32_R_SYM (irel
->r_info
);
1859 if (isym
->st_shndx
== SHN_UNDEF
)
1860 /* We can't do anthing with undefined symbols. */
1862 else if (isym
->st_shndx
== SHN_ABS
)
1863 tsec
= bfd_abs_section_ptr
;
1864 else if (isym
->st_shndx
== SHN_COMMON
)
1865 tsec
= bfd_com_section_ptr
;
1867 tsec
= h
->root
.u
.def
.section
;
1869 toff
= h
->root
.u
.def
.value
;
1873 tsec
= ppc_info
->plt
;
1874 toff
= h
->plt
.offset
;
1877 else if (h
->root
.type
== bfd_link_hash_undefined
1878 || h
->root
.type
== bfd_link_hash_undefweak
)
1883 tsec
= h
->root
.u
.def
.section
;
1884 toff
= h
->root
.u
.def
.value
;
1888 if (tsec
->sec_info_type
== ELF_INFO_TYPE_MERGE
)
1889 toff
= _bfd_merged_section_offset (abfd
, &tsec
,
1890 elf_section_data (tsec
)->sec_info
,
1891 toff
+ irel
->r_addend
, 0);
1893 toff
+= irel
->r_addend
;
1895 symaddr
= tsec
->output_section
->vma
+ tsec
->output_offset
+ toff
;
1897 roff
= irel
->r_offset
;
1899 reladdr
= (isec
->output_section
->vma
1900 + isec
->output_offset
1901 + roff
) & (bfd_vma
) -4;
1903 /* If the branch is in range, no need to do anything. */
1904 max_branch_offset
= 1 << 25;
1905 if (r_type
!= R_PPC_REL24
1906 && r_type
!= R_PPC_LOCAL24PC
1907 && r_type
!= R_PPC_PLTREL24
)
1908 max_branch_offset
= 1 << 15;
1910 if ((bfd_vma
) (symaddr
- reladdr
) + max_branch_offset
1911 <= 2 * max_branch_offset
)
1914 /* If the branch and target are in the same section, you have
1915 no hope. We'll error out later. */
1919 /* Look for an existing fixup to this address.
1920 ??? What if the existing fixup is for a non-pic stub, and the
1921 new one requires a pic stub? This presumably could happen with
1922 a static link and a mix of R_PPC_LOCAL24PC and R_PPC_REL24
1923 relocs to a symbol needing long branch stubs.
1924 ??? Why do we require R_PPC_LOCAL24PC and branches to the plt
1925 to have a shared branch stub? Shared branch stubs should only
1926 be needed when info->shared. */
1927 for (f
= fixups
; f
; f
= f
->next
)
1928 if (f
->tsec
== tsec
&& f
->toff
== toff
)
1933 const bfd_byte
*stub
;
1935 unsigned long stub_rtype
;
1937 if (link_info
->shared
1938 || tsec
== ppc_info
->plt
1939 || r_type
== R_PPC_LOCAL24PC
)
1941 stub
= shared_stub_entry
;
1942 size
= sizeof (shared_stub_entry
);
1944 stub_rtype
= R_PPC_RELAX32PC
;
1949 size
= sizeof (stub_entry
);
1951 stub_rtype
= R_PPC_RELAX32
;
1954 /* Resize the current section to make room for the new branch. */
1955 trampoff
= (isec
->_cooked_size
+ 3) & (bfd_vma
) - 4;
1956 amt
= trampoff
+ size
;
1957 contents
= bfd_realloc (contents
, amt
);
1958 if (contents
== NULL
)
1961 isec
->_cooked_size
= amt
;
1963 memcpy (contents
+ trampoff
, stub
, size
);
1965 /* Hijack the old relocation. Since we need two
1966 relocations for this use a "composite" reloc. */
1967 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
),
1969 irel
->r_offset
= trampoff
+ insn_offset
;
1971 /* Record the fixup so we don't do it again this section. */
1972 f
= bfd_malloc (sizeof (*f
));
1976 f
->trampoff
= trampoff
;
1981 /* Nop out the reloc, since we're finalizing things here. */
1982 irel
->r_info
= ELF32_R_INFO (0, R_PPC_NONE
);
1985 /* Fix up the existing branch to hit the trampoline. Hope like
1986 hell this doesn't overflow too. */
1987 if (ppc_elf_install_value (abfd
, contents
+ roff
,
1988 f
->trampoff
- (roff
& (bfd_vma
) -3) + 4,
1989 r_type
) != bfd_reloc_ok
)
1992 changed_contents
= TRUE
;
1993 changed_relocs
= TRUE
;
1999 struct one_fixup
*f
= fixups
;
2000 fixups
= fixups
->next
;
2004 && symtab_hdr
->contents
!= (unsigned char *) isymbuf
)
2006 if (! link_info
->keep_memory
)
2010 /* Cache the symbols for elf_link_input_bfd. */
2011 symtab_hdr
->contents
= (unsigned char *) isymbuf
;
2015 if (contents
!= NULL
2016 && elf_section_data (isec
)->this_hdr
.contents
!= contents
)
2018 if (!changed_contents
&& !link_info
->keep_memory
)
2022 /* Cache the section contents for elf_link_input_bfd. */
2023 elf_section_data (isec
)->this_hdr
.contents
= contents
;
2027 if (elf_section_data (isec
)->relocs
!= internal_relocs
)
2029 if (!changed_relocs
)
2030 free (internal_relocs
);
2032 elf_section_data (isec
)->relocs
= internal_relocs
;
2035 *again
= changed_contents
|| changed_relocs
;
2039 if (isymbuf
!= NULL
&& (unsigned char *) isymbuf
!= symtab_hdr
->contents
)
2041 if (contents
!= NULL
2042 && elf_section_data (isec
)->this_hdr
.contents
!= contents
)
2044 if (internal_relocs
!= NULL
2045 && elf_section_data (isec
)->relocs
!= internal_relocs
)
2046 free (internal_relocs
);
2050 static reloc_howto_type
*
2051 ppc_elf_reloc_type_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
2052 bfd_reloc_code_real_type code
)
2054 enum elf_ppc_reloc_type r
;
2056 /* Initialize howto table if not already done. */
2057 if (!ppc_elf_howto_table
[R_PPC_ADDR32
])
2058 ppc_elf_howto_init ();
2065 case BFD_RELOC_NONE
: r
= R_PPC_NONE
; break;
2066 case BFD_RELOC_32
: r
= R_PPC_ADDR32
; break;
2067 case BFD_RELOC_PPC_BA26
: r
= R_PPC_ADDR24
; break;
2068 case BFD_RELOC_16
: r
= R_PPC_ADDR16
; break;
2069 case BFD_RELOC_LO16
: r
= R_PPC_ADDR16_LO
; break;
2070 case BFD_RELOC_HI16
: r
= R_PPC_ADDR16_HI
; break;
2071 case BFD_RELOC_HI16_S
: r
= R_PPC_ADDR16_HA
; break;
2072 case BFD_RELOC_PPC_BA16
: r
= R_PPC_ADDR14
; break;
2073 case BFD_RELOC_PPC_BA16_BRTAKEN
: r
= R_PPC_ADDR14_BRTAKEN
; break;
2074 case BFD_RELOC_PPC_BA16_BRNTAKEN
: r
= R_PPC_ADDR14_BRNTAKEN
; break;
2075 case BFD_RELOC_PPC_B26
: r
= R_PPC_REL24
; break;
2076 case BFD_RELOC_PPC_B16
: r
= R_PPC_REL14
; break;
2077 case BFD_RELOC_PPC_B16_BRTAKEN
: r
= R_PPC_REL14_BRTAKEN
; break;
2078 case BFD_RELOC_PPC_B16_BRNTAKEN
: r
= R_PPC_REL14_BRNTAKEN
; break;
2079 case BFD_RELOC_16_GOTOFF
: r
= R_PPC_GOT16
; break;
2080 case BFD_RELOC_LO16_GOTOFF
: r
= R_PPC_GOT16_LO
; break;
2081 case BFD_RELOC_HI16_GOTOFF
: r
= R_PPC_GOT16_HI
; break;
2082 case BFD_RELOC_HI16_S_GOTOFF
: r
= R_PPC_GOT16_HA
; break;
2083 case BFD_RELOC_24_PLT_PCREL
: r
= R_PPC_PLTREL24
; break;
2084 case BFD_RELOC_PPC_COPY
: r
= R_PPC_COPY
; break;
2085 case BFD_RELOC_PPC_GLOB_DAT
: r
= R_PPC_GLOB_DAT
; break;
2086 case BFD_RELOC_PPC_LOCAL24PC
: r
= R_PPC_LOCAL24PC
; break;
2087 case BFD_RELOC_32_PCREL
: r
= R_PPC_REL32
; break;
2088 case BFD_RELOC_32_PLTOFF
: r
= R_PPC_PLT32
; break;
2089 case BFD_RELOC_32_PLT_PCREL
: r
= R_PPC_PLTREL32
; break;
2090 case BFD_RELOC_LO16_PLTOFF
: r
= R_PPC_PLT16_LO
; break;
2091 case BFD_RELOC_HI16_PLTOFF
: r
= R_PPC_PLT16_HI
; break;
2092 case BFD_RELOC_HI16_S_PLTOFF
: r
= R_PPC_PLT16_HA
; break;
2093 case BFD_RELOC_GPREL16
: r
= R_PPC_SDAREL16
; break;
2094 case BFD_RELOC_16_BASEREL
: r
= R_PPC_SECTOFF
; break;
2095 case BFD_RELOC_LO16_BASEREL
: r
= R_PPC_SECTOFF_LO
; break;
2096 case BFD_RELOC_HI16_BASEREL
: r
= R_PPC_SECTOFF_HI
; break;
2097 case BFD_RELOC_HI16_S_BASEREL
: r
= R_PPC_SECTOFF_HA
; break;
2098 case BFD_RELOC_CTOR
: r
= R_PPC_ADDR32
; break;
2099 case BFD_RELOC_PPC_TOC16
: r
= R_PPC_TOC16
; break;
2100 case BFD_RELOC_PPC_TLS
: r
= R_PPC_TLS
; break;
2101 case BFD_RELOC_PPC_DTPMOD
: r
= R_PPC_DTPMOD32
; break;
2102 case BFD_RELOC_PPC_TPREL16
: r
= R_PPC_TPREL16
; break;
2103 case BFD_RELOC_PPC_TPREL16_LO
: r
= R_PPC_TPREL16_LO
; break;
2104 case BFD_RELOC_PPC_TPREL16_HI
: r
= R_PPC_TPREL16_HI
; break;
2105 case BFD_RELOC_PPC_TPREL16_HA
: r
= R_PPC_TPREL16_HA
; break;
2106 case BFD_RELOC_PPC_TPREL
: r
= R_PPC_TPREL32
; break;
2107 case BFD_RELOC_PPC_DTPREL16
: r
= R_PPC_DTPREL16
; break;
2108 case BFD_RELOC_PPC_DTPREL16_LO
: r
= R_PPC_DTPREL16_LO
; break;
2109 case BFD_RELOC_PPC_DTPREL16_HI
: r
= R_PPC_DTPREL16_HI
; break;
2110 case BFD_RELOC_PPC_DTPREL16_HA
: r
= R_PPC_DTPREL16_HA
; break;
2111 case BFD_RELOC_PPC_DTPREL
: r
= R_PPC_DTPREL32
; break;
2112 case BFD_RELOC_PPC_GOT_TLSGD16
: r
= R_PPC_GOT_TLSGD16
; break;
2113 case BFD_RELOC_PPC_GOT_TLSGD16_LO
: r
= R_PPC_GOT_TLSGD16_LO
; break;
2114 case BFD_RELOC_PPC_GOT_TLSGD16_HI
: r
= R_PPC_GOT_TLSGD16_HI
; break;
2115 case BFD_RELOC_PPC_GOT_TLSGD16_HA
: r
= R_PPC_GOT_TLSGD16_HA
; break;
2116 case BFD_RELOC_PPC_GOT_TLSLD16
: r
= R_PPC_GOT_TLSLD16
; break;
2117 case BFD_RELOC_PPC_GOT_TLSLD16_LO
: r
= R_PPC_GOT_TLSLD16_LO
; break;
2118 case BFD_RELOC_PPC_GOT_TLSLD16_HI
: r
= R_PPC_GOT_TLSLD16_HI
; break;
2119 case BFD_RELOC_PPC_GOT_TLSLD16_HA
: r
= R_PPC_GOT_TLSLD16_HA
; break;
2120 case BFD_RELOC_PPC_GOT_TPREL16
: r
= R_PPC_GOT_TPREL16
; break;
2121 case BFD_RELOC_PPC_GOT_TPREL16_LO
: r
= R_PPC_GOT_TPREL16_LO
; break;
2122 case BFD_RELOC_PPC_GOT_TPREL16_HI
: r
= R_PPC_GOT_TPREL16_HI
; break;
2123 case BFD_RELOC_PPC_GOT_TPREL16_HA
: r
= R_PPC_GOT_TPREL16_HA
; break;
2124 case BFD_RELOC_PPC_GOT_DTPREL16
: r
= R_PPC_GOT_DTPREL16
; break;
2125 case BFD_RELOC_PPC_GOT_DTPREL16_LO
: r
= R_PPC_GOT_DTPREL16_LO
; break;
2126 case BFD_RELOC_PPC_GOT_DTPREL16_HI
: r
= R_PPC_GOT_DTPREL16_HI
; break;
2127 case BFD_RELOC_PPC_GOT_DTPREL16_HA
: r
= R_PPC_GOT_DTPREL16_HA
; break;
2128 case BFD_RELOC_PPC_EMB_NADDR32
: r
= R_PPC_EMB_NADDR32
; break;
2129 case BFD_RELOC_PPC_EMB_NADDR16
: r
= R_PPC_EMB_NADDR16
; break;
2130 case BFD_RELOC_PPC_EMB_NADDR16_LO
: r
= R_PPC_EMB_NADDR16_LO
; break;
2131 case BFD_RELOC_PPC_EMB_NADDR16_HI
: r
= R_PPC_EMB_NADDR16_HI
; break;
2132 case BFD_RELOC_PPC_EMB_NADDR16_HA
: r
= R_PPC_EMB_NADDR16_HA
; break;
2133 case BFD_RELOC_PPC_EMB_SDAI16
: r
= R_PPC_EMB_SDAI16
; break;
2134 case BFD_RELOC_PPC_EMB_SDA2I16
: r
= R_PPC_EMB_SDA2I16
; break;
2135 case BFD_RELOC_PPC_EMB_SDA2REL
: r
= R_PPC_EMB_SDA2REL
; break;
2136 case BFD_RELOC_PPC_EMB_SDA21
: r
= R_PPC_EMB_SDA21
; break;
2137 case BFD_RELOC_PPC_EMB_MRKREF
: r
= R_PPC_EMB_MRKREF
; break;
2138 case BFD_RELOC_PPC_EMB_RELSEC16
: r
= R_PPC_EMB_RELSEC16
; break;
2139 case BFD_RELOC_PPC_EMB_RELST_LO
: r
= R_PPC_EMB_RELST_LO
; break;
2140 case BFD_RELOC_PPC_EMB_RELST_HI
: r
= R_PPC_EMB_RELST_HI
; break;
2141 case BFD_RELOC_PPC_EMB_RELST_HA
: r
= R_PPC_EMB_RELST_HA
; break;
2142 case BFD_RELOC_PPC_EMB_BIT_FLD
: r
= R_PPC_EMB_BIT_FLD
; break;
2143 case BFD_RELOC_PPC_EMB_RELSDA
: r
= R_PPC_EMB_RELSDA
; break;
2144 case BFD_RELOC_VTABLE_INHERIT
: r
= R_PPC_GNU_VTINHERIT
; break;
2145 case BFD_RELOC_VTABLE_ENTRY
: r
= R_PPC_GNU_VTENTRY
; break;
2148 return ppc_elf_howto_table
[r
];
2151 /* Set the howto pointer for a PowerPC ELF reloc. */
2154 ppc_elf_info_to_howto (bfd
*abfd ATTRIBUTE_UNUSED
,
2156 Elf_Internal_Rela
*dst
)
2158 /* Initialize howto table if not already done. */
2159 if (!ppc_elf_howto_table
[R_PPC_ADDR32
])
2160 ppc_elf_howto_init ();
2162 BFD_ASSERT (ELF32_R_TYPE (dst
->r_info
) < (unsigned int) R_PPC_max
);
2163 cache_ptr
->howto
= ppc_elf_howto_table
[ELF32_R_TYPE (dst
->r_info
)];
2166 /* Handle the R_PPC_ADDR16_HA reloc. */
2168 static bfd_reloc_status_type
2169 ppc_elf_addr16_ha_reloc (bfd
*abfd ATTRIBUTE_UNUSED
,
2170 arelent
*reloc_entry
,
2172 void *data ATTRIBUTE_UNUSED
,
2173 asection
*input_section
,
2175 char **error_message ATTRIBUTE_UNUSED
)
2179 if (output_bfd
!= NULL
)
2181 reloc_entry
->address
+= input_section
->output_offset
;
2182 return bfd_reloc_ok
;
2185 if (reloc_entry
->address
> input_section
->_cooked_size
)
2186 return bfd_reloc_outofrange
;
2188 if (bfd_is_com_section (symbol
->section
))
2191 relocation
= symbol
->value
;
2193 relocation
+= symbol
->section
->output_section
->vma
;
2194 relocation
+= symbol
->section
->output_offset
;
2195 relocation
+= reloc_entry
->addend
;
2197 reloc_entry
->addend
+= (relocation
& 0x8000) << 1;
2199 return bfd_reloc_continue
;
2202 static bfd_reloc_status_type
2203 ppc_elf_unhandled_reloc (bfd
*abfd
,
2204 arelent
*reloc_entry
,
2207 asection
*input_section
,
2209 char **error_message
)
2211 /* If this is a relocatable link (output_bfd test tells us), just
2212 call the generic function. Any adjustment will be done at final
2214 if (output_bfd
!= NULL
)
2215 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2216 input_section
, output_bfd
, error_message
);
2218 if (error_message
!= NULL
)
2220 static char buf
[60];
2221 sprintf (buf
, _("generic linker can't handle %s"),
2222 reloc_entry
->howto
->name
);
2223 *error_message
= buf
;
2225 return bfd_reloc_dangerous
;
2228 /* Fix bad default arch selected for a 32 bit input bfd when the
2229 default is 64 bit. */
2232 ppc_elf_object_p (bfd
*abfd
)
2234 if (abfd
->arch_info
->the_default
&& abfd
->arch_info
->bits_per_word
== 64)
2236 Elf_Internal_Ehdr
*i_ehdr
= elf_elfheader (abfd
);
2238 if (i_ehdr
->e_ident
[EI_CLASS
] == ELFCLASS32
)
2240 /* Relies on arch after 64 bit default being 32 bit default. */
2241 abfd
->arch_info
= abfd
->arch_info
->next
;
2242 BFD_ASSERT (abfd
->arch_info
->bits_per_word
== 32);
2248 /* Function to set whether a module needs the -mrelocatable bit set. */
2251 ppc_elf_set_private_flags (bfd
*abfd
, flagword flags
)
2253 BFD_ASSERT (!elf_flags_init (abfd
)
2254 || elf_elfheader (abfd
)->e_flags
== flags
);
2256 elf_elfheader (abfd
)->e_flags
= flags
;
2257 elf_flags_init (abfd
) = TRUE
;
2261 /* Merge backend specific data from an object file to the output
2262 object file when linking. */
2265 ppc_elf_merge_private_bfd_data (bfd
*ibfd
, bfd
*obfd
)
2271 /* Check if we have the same endianess. */
2272 if (! _bfd_generic_verify_endian_match (ibfd
, obfd
))
2275 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
2276 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
2279 new_flags
= elf_elfheader (ibfd
)->e_flags
;
2280 old_flags
= elf_elfheader (obfd
)->e_flags
;
2281 if (!elf_flags_init (obfd
))
2283 /* First call, no flags set. */
2284 elf_flags_init (obfd
) = TRUE
;
2285 elf_elfheader (obfd
)->e_flags
= new_flags
;
2288 /* Compatible flags are ok. */
2289 else if (new_flags
== old_flags
)
2292 /* Incompatible flags. */
2295 /* Warn about -mrelocatable mismatch. Allow -mrelocatable-lib
2296 to be linked with either. */
2298 if ((new_flags
& EF_PPC_RELOCATABLE
) != 0
2299 && (old_flags
& (EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
)) == 0)
2302 (*_bfd_error_handler
)
2303 (_("%s: compiled with -mrelocatable and linked with "
2304 "modules compiled normally"),
2305 bfd_archive_filename (ibfd
));
2307 else if ((new_flags
& (EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
)) == 0
2308 && (old_flags
& EF_PPC_RELOCATABLE
) != 0)
2311 (*_bfd_error_handler
)
2312 (_("%s: compiled normally and linked with "
2313 "modules compiled with -mrelocatable"),
2314 bfd_archive_filename (ibfd
));
2317 /* The output is -mrelocatable-lib iff both the input files are. */
2318 if (! (new_flags
& EF_PPC_RELOCATABLE_LIB
))
2319 elf_elfheader (obfd
)->e_flags
&= ~EF_PPC_RELOCATABLE_LIB
;
2321 /* The output is -mrelocatable iff it can't be -mrelocatable-lib,
2322 but each input file is either -mrelocatable or -mrelocatable-lib. */
2323 if (! (elf_elfheader (obfd
)->e_flags
& EF_PPC_RELOCATABLE_LIB
)
2324 && (new_flags
& (EF_PPC_RELOCATABLE_LIB
| EF_PPC_RELOCATABLE
))
2325 && (old_flags
& (EF_PPC_RELOCATABLE_LIB
| EF_PPC_RELOCATABLE
)))
2326 elf_elfheader (obfd
)->e_flags
|= EF_PPC_RELOCATABLE
;
2328 /* Do not warn about eabi vs. V.4 mismatch, just or in the bit if
2329 any module uses it. */
2330 elf_elfheader (obfd
)->e_flags
|= (new_flags
& EF_PPC_EMB
);
2332 new_flags
&= ~(EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
| EF_PPC_EMB
);
2333 old_flags
&= ~(EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
| EF_PPC_EMB
);
2335 /* Warn about any other mismatches. */
2336 if (new_flags
!= old_flags
)
2339 (*_bfd_error_handler
)
2340 (_("%s: uses different e_flags (0x%lx) fields "
2341 "than previous modules (0x%lx)"),
2342 bfd_archive_filename (ibfd
), (long) new_flags
, (long) old_flags
);
2347 bfd_set_error (bfd_error_bad_value
);
2355 /* Handle a PowerPC specific section when reading an object file. This
2356 is called when elfcode.h finds a section with an unknown type. */
2359 ppc_elf_section_from_shdr (bfd
*abfd
, Elf_Internal_Shdr
*hdr
, const char *name
)
2364 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
))
2367 newsect
= hdr
->bfd_section
;
2368 flags
= bfd_get_section_flags (abfd
, newsect
);
2369 if (hdr
->sh_flags
& SHF_EXCLUDE
)
2370 flags
|= SEC_EXCLUDE
;
2372 if (hdr
->sh_type
== SHT_ORDERED
)
2373 flags
|= SEC_SORT_ENTRIES
;
2375 bfd_set_section_flags (abfd
, newsect
, flags
);
2379 /* Set up any other section flags and such that may be necessary. */
2382 ppc_elf_fake_sections (bfd
*abfd ATTRIBUTE_UNUSED
,
2383 Elf_Internal_Shdr
*shdr
,
2386 if ((asect
->flags
& SEC_EXCLUDE
) != 0)
2387 shdr
->sh_flags
|= SHF_EXCLUDE
;
2389 if ((asect
->flags
& SEC_SORT_ENTRIES
) != 0)
2390 shdr
->sh_type
= SHT_ORDERED
;
2395 /* Find a linker generated pointer with a given addend and type. */
2397 static elf_linker_section_pointers_t
*
2398 elf_find_pointer_linker_section
2399 (elf_linker_section_pointers_t
*linker_pointers
,
2401 elf_linker_section_t
*lsect
)
2403 for ( ; linker_pointers
!= NULL
; linker_pointers
= linker_pointers
->next
)
2404 if (lsect
== linker_pointers
->lsect
&& addend
== linker_pointers
->addend
)
2405 return linker_pointers
;
2410 /* Allocate a pointer to live in a linker created section. */
2413 elf_create_pointer_linker_section (bfd
*abfd
,
2414 struct bfd_link_info
*info
,
2415 elf_linker_section_t
*lsect
,
2416 struct elf_link_hash_entry
*h
,
2417 const Elf_Internal_Rela
*rel
)
2419 elf_linker_section_pointers_t
**ptr_linker_section_ptr
= NULL
;
2420 elf_linker_section_pointers_t
*linker_section_ptr
;
2421 unsigned long r_symndx
= ELF32_R_SYM (rel
->r_info
);
2424 BFD_ASSERT (lsect
!= NULL
);
2426 /* Is this a global symbol? */
2429 struct ppc_elf_link_hash_entry
*eh
;
2431 /* Has this symbol already been allocated? If so, our work is done. */
2432 eh
= (struct ppc_elf_link_hash_entry
*) h
;
2433 if (elf_find_pointer_linker_section (eh
->linker_section_pointer
,
2438 ptr_linker_section_ptr
= &eh
->linker_section_pointer
;
2439 /* Make sure this symbol is output as a dynamic symbol. */
2440 if (h
->dynindx
== -1)
2442 if (! _bfd_elf_link_record_dynamic_symbol (info
, h
))
2446 if (lsect
->rel_section
)
2447 lsect
->rel_section
->_raw_size
+= sizeof (Elf32_External_Rela
);
2451 /* Allocation of a pointer to a local symbol. */
2452 elf_linker_section_pointers_t
**ptr
= elf_local_ptr_offsets (abfd
);
2454 /* Allocate a table to hold the local symbols if first time. */
2457 unsigned int num_symbols
= elf_tdata (abfd
)->symtab_hdr
.sh_info
;
2460 amt
*= sizeof (elf_linker_section_pointers_t
*);
2461 ptr
= bfd_zalloc (abfd
, amt
);
2466 elf_local_ptr_offsets (abfd
) = ptr
;
2469 /* Has this symbol already been allocated? If so, our work is done. */
2470 if (elf_find_pointer_linker_section (ptr
[r_symndx
],
2475 ptr_linker_section_ptr
= &ptr
[r_symndx
];
2479 /* If we are generating a shared object, we need to
2480 output a R_<xxx>_RELATIVE reloc so that the
2481 dynamic linker can adjust this GOT entry. */
2482 BFD_ASSERT (lsect
->rel_section
!= NULL
);
2483 lsect
->rel_section
->_raw_size
+= sizeof (Elf32_External_Rela
);
2487 /* Allocate space for a pointer in the linker section, and allocate
2488 a new pointer record from internal memory. */
2489 BFD_ASSERT (ptr_linker_section_ptr
!= NULL
);
2490 amt
= sizeof (elf_linker_section_pointers_t
);
2491 linker_section_ptr
= bfd_alloc (abfd
, amt
);
2493 if (!linker_section_ptr
)
2496 linker_section_ptr
->next
= *ptr_linker_section_ptr
;
2497 linker_section_ptr
->addend
= rel
->r_addend
;
2498 linker_section_ptr
->lsect
= lsect
;
2499 linker_section_ptr
->written_address_p
= FALSE
;
2500 *ptr_linker_section_ptr
= linker_section_ptr
;
2502 linker_section_ptr
->offset
= lsect
->section
->_raw_size
;
2503 lsect
->section
->_raw_size
+= 4;
2507 "Create pointer in linker section %s, offset = %ld, section size = %ld\n",
2508 lsect
->name
, (long) linker_section_ptr
->offset
,
2509 (long) lsect
->section
->_raw_size
);
2515 #define bfd_put_ptr(BFD, VAL, ADDR) bfd_put_32 (BFD, VAL, ADDR)
2517 /* Fill in the address for a pointer generated in a linker section. */
2520 elf_finish_pointer_linker_section (bfd
*output_bfd
,
2522 struct bfd_link_info
*info
,
2523 elf_linker_section_t
*lsect
,
2524 struct elf_link_hash_entry
*h
,
2526 const Elf_Internal_Rela
*rel
,
2529 elf_linker_section_pointers_t
*linker_section_ptr
;
2531 BFD_ASSERT (lsect
!= NULL
);
2535 /* Handle global symbol. */
2536 struct ppc_elf_link_hash_entry
*eh
;
2538 eh
= (struct ppc_elf_link_hash_entry
*) h
;
2540 = elf_find_pointer_linker_section (eh
->linker_section_pointer
,
2544 BFD_ASSERT (linker_section_ptr
!= NULL
);
2546 if (! elf_hash_table (info
)->dynamic_sections_created
2549 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
)))
2551 /* This is actually a static link, or it is a
2552 -Bsymbolic link and the symbol is defined
2553 locally. We must initialize this entry in the
2556 When doing a dynamic link, we create a .rela.<xxx>
2557 relocation entry to initialize the value. This
2558 is done in the finish_dynamic_symbol routine. */
2559 if (!linker_section_ptr
->written_address_p
)
2561 linker_section_ptr
->written_address_p
= TRUE
;
2562 bfd_put_ptr (output_bfd
,
2563 relocation
+ linker_section_ptr
->addend
,
2564 (lsect
->section
->contents
2565 + linker_section_ptr
->offset
));
2571 /* Handle local symbol. */
2572 unsigned long r_symndx
= ELF32_R_SYM (rel
->r_info
);
2573 BFD_ASSERT (elf_local_ptr_offsets (input_bfd
) != NULL
);
2574 BFD_ASSERT (elf_local_ptr_offsets (input_bfd
)[r_symndx
] != NULL
);
2575 linker_section_ptr
= (elf_find_pointer_linker_section
2576 (elf_local_ptr_offsets (input_bfd
)[r_symndx
],
2580 BFD_ASSERT (linker_section_ptr
!= NULL
);
2582 /* Write out pointer if it hasn't been rewritten out before. */
2583 if (!linker_section_ptr
->written_address_p
)
2585 linker_section_ptr
->written_address_p
= TRUE
;
2586 bfd_put_ptr (output_bfd
, relocation
+ linker_section_ptr
->addend
,
2587 lsect
->section
->contents
+ linker_section_ptr
->offset
);
2591 /* We need to generate a relative reloc for the dynamic
2594 asection
*srel
= lsect
->rel_section
;
2595 Elf_Internal_Rela outrel
[MAX_INT_RELS_PER_EXT_REL
];
2597 const struct elf_backend_data
*bed
;
2600 BFD_ASSERT (srel
!= NULL
);
2602 bed
= get_elf_backend_data (output_bfd
);
2603 for (i
= 0; i
< bed
->s
->int_rels_per_ext_rel
; i
++)
2605 outrel
[i
].r_offset
= (lsect
->section
->output_section
->vma
2606 + lsect
->section
->output_offset
2607 + linker_section_ptr
->offset
);
2608 outrel
[i
].r_info
= 0;
2609 outrel
[i
].r_addend
= 0;
2611 outrel
[0].r_info
= ELF32_R_INFO (0, relative_reloc
);
2612 erel
= lsect
->section
->contents
;
2613 erel
+= (elf_section_data (lsect
->section
)->rel_count
++
2614 * sizeof (Elf32_External_Rela
));
2615 bfd_elf32_swap_reloca_out (output_bfd
, outrel
, erel
);
2620 relocation
= (lsect
->section
->output_offset
2621 + linker_section_ptr
->offset
2622 - lsect
->sym_offset
);
2626 "Finish pointer in linker section %s, offset = %ld (0x%lx)\n",
2627 lsect
->name
, (long) relocation
, (long) relocation
);
2630 /* Subtract out the addend, because it will get added back in by the normal
2632 return relocation
- linker_section_ptr
->addend
;
2635 /* Create a special linker section */
2636 static elf_linker_section_t
*
2637 ppc_elf_create_linker_section (bfd
*abfd
,
2638 struct bfd_link_info
*info
,
2639 enum elf_linker_section_enum which
)
2641 elf_linker_section_t
*lsect
;
2642 struct ppc_elf_link_hash_table
*htab
= ppc_elf_hash_table (info
);
2647 const char *rel_name
;
2648 const char *sym_name
;
2651 /* Both of these sections are (technically) created by the user
2652 putting data in them, so they shouldn't be marked
2655 The linker creates them so it has somewhere to attach their
2656 respective symbols. In fact, if they were empty it would
2657 be OK to leave the symbol set to 0 (or any random number), because
2658 the appropriate register should never be used. */
2659 flags
= SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
;
2668 case LINKER_SECTION_SDATA
: /* .sdata/.sbss section */
2670 rel_name
= ".rela.sdata";
2671 sym_name
= "_SDA_BASE_";
2674 case LINKER_SECTION_SDATA2
: /* .sdata2/.sbss2 section */
2676 rel_name
= ".rela.sdata2";
2677 sym_name
= "_SDA2_BASE_";
2678 flags
|= SEC_READONLY
;
2682 /* Record the first bfd that needs the special sections. */
2683 if (!htab
->elf
.dynobj
)
2684 htab
->elf
.dynobj
= abfd
;
2686 amt
= sizeof (elf_linker_section_t
);
2687 lsect
= bfd_zalloc (htab
->elf
.dynobj
, amt
);
2689 lsect
->sym_offset
= sym_offset
;
2691 /* See if the sections already exist. */
2692 s
= bfd_get_section_by_name (htab
->elf
.dynobj
, name
);
2693 if (s
== NULL
|| (s
->flags
& flags
) != flags
)
2695 s
= bfd_make_section_anyway (htab
->elf
.dynobj
, name
);
2697 || !bfd_set_section_flags (htab
->elf
.dynobj
, s
, flags
))
2702 if (bfd_get_section_alignment (htab
->elf
.dynobj
, s
) < 2
2703 && !bfd_set_section_alignment (htab
->elf
.dynobj
, s
, 2))
2706 s
->_raw_size
= align_power (s
->_raw_size
, 2);
2709 fprintf (stderr
, "Creating section %s, current size = %ld\n",
2710 name
, (long) s
->_raw_size
);
2715 struct elf_link_hash_entry
*h
;
2716 struct bfd_link_hash_entry
*bh
;
2719 fprintf (stderr
, "Adding %s to section %s\n", sym_name
, name
);
2721 bh
= bfd_link_hash_lookup (info
->hash
, sym_name
,
2722 FALSE
, FALSE
, FALSE
);
2724 if ((bh
== NULL
|| bh
->type
== bfd_link_hash_undefined
)
2725 && !(_bfd_generic_link_add_one_symbol
2726 (info
, abfd
, sym_name
, BSF_GLOBAL
, s
, sym_offset
, NULL
,
2727 FALSE
, get_elf_backend_data (abfd
)->collect
, &bh
)))
2729 h
= (struct elf_link_hash_entry
*) bh
;
2731 h
->type
= STT_OBJECT
;
2732 lsect
->sym_hash
= h
;
2735 && ! _bfd_elf_link_record_dynamic_symbol (info
, h
))
2741 s
= bfd_make_section_anyway (htab
->elf
.dynobj
, rel_name
);
2742 lsect
->rel_section
= s
;
2743 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
2744 | SEC_LINKER_CREATED
| SEC_READONLY
);
2746 || ! bfd_set_section_flags (htab
->elf
.dynobj
, s
, flags
)
2747 || ! bfd_set_section_alignment (htab
->elf
.dynobj
, s
, 2))
2754 /* If we have a non-zero sized .sbss2 or .PPC.EMB.sbss0 sections, we
2755 need to bump up the number of section headers. */
2758 ppc_elf_additional_program_headers (bfd
*abfd
)
2765 s
= bfd_get_section_by_name (abfd
, ".interp");
2769 s
= bfd_get_section_by_name (abfd
, ".sbss2");
2770 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0 && s
->_raw_size
> 0)
2773 s
= bfd_get_section_by_name (abfd
, ".PPC.EMB.sbss0");
2774 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0 && s
->_raw_size
> 0)
2780 /* Modify the segment map if needed. */
2783 ppc_elf_modify_segment_map (bfd
*abfd ATTRIBUTE_UNUSED
)
2788 /* The powerpc .got has a blrl instruction in it. Mark it executable. */
2791 ppc_elf_create_got (bfd
*abfd
, struct bfd_link_info
*info
)
2793 struct ppc_elf_link_hash_table
*htab
;
2797 if (!_bfd_elf_create_got_section (abfd
, info
))
2800 htab
= ppc_elf_hash_table (info
);
2801 htab
->got
= s
= bfd_get_section_by_name (abfd
, ".got");
2805 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_CODE
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
2806 | SEC_LINKER_CREATED
);
2807 if (!bfd_set_section_flags (abfd
, s
, flags
))
2810 htab
->relgot
= bfd_make_section (abfd
, ".rela.got");
2812 || ! bfd_set_section_flags (abfd
, htab
->relgot
,
2813 (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
2814 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
2816 || ! bfd_set_section_alignment (abfd
, htab
->relgot
, 2))
2822 /* We have to create .dynsbss and .rela.sbss here so that they get mapped
2823 to output sections (just like _bfd_elf_create_dynamic_sections has
2824 to create .dynbss and .rela.bss). */
2827 ppc_elf_create_dynamic_sections (bfd
*abfd
, struct bfd_link_info
*info
)
2829 struct ppc_elf_link_hash_table
*htab
;
2833 htab
= ppc_elf_hash_table (info
);
2835 if (htab
->got
== NULL
2836 && !ppc_elf_create_got (abfd
, info
))
2839 if (!_bfd_elf_create_dynamic_sections (abfd
, info
))
2842 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
2843 | SEC_LINKER_CREATED
);
2845 htab
->dynbss
= bfd_get_section_by_name (abfd
, ".dynbss");
2846 htab
->dynsbss
= s
= bfd_make_section (abfd
, ".dynsbss");
2848 || ! bfd_set_section_flags (abfd
, s
, SEC_ALLOC
))
2853 htab
->relbss
= bfd_get_section_by_name (abfd
, ".rela.bss");
2854 htab
->relsbss
= s
= bfd_make_section (abfd
, ".rela.sbss");
2856 || ! bfd_set_section_flags (abfd
, s
, flags
| SEC_READONLY
)
2857 || ! bfd_set_section_alignment (abfd
, s
, 2))
2861 htab
->relplt
= bfd_get_section_by_name (abfd
, ".rela.plt");
2862 htab
->plt
= s
= bfd_get_section_by_name (abfd
, ".plt");
2866 flags
= SEC_ALLOC
| SEC_CODE
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
;
2867 return bfd_set_section_flags (abfd
, s
, flags
);
2870 /* Adjust a symbol defined by a dynamic object and referenced by a
2871 regular object. The current definition is in some section of the
2872 dynamic object, but we're not including those sections. We have to
2873 change the definition to something the rest of the link can
2877 ppc_elf_adjust_dynamic_symbol (struct bfd_link_info
*info
,
2878 struct elf_link_hash_entry
*h
)
2880 struct ppc_elf_link_hash_table
*htab
;
2882 unsigned int power_of_two
;
2885 fprintf (stderr
, "ppc_elf_adjust_dynamic_symbol called for %s\n",
2886 h
->root
.root
.string
);
2889 /* Make sure we know what is going on here. */
2890 htab
= ppc_elf_hash_table (info
);
2891 BFD_ASSERT (htab
->elf
.dynobj
!= NULL
2892 && ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
)
2893 || h
->weakdef
!= NULL
2894 || ((h
->elf_link_hash_flags
2895 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0
2896 && (h
->elf_link_hash_flags
2897 & ELF_LINK_HASH_REF_REGULAR
) != 0
2898 && (h
->elf_link_hash_flags
2899 & ELF_LINK_HASH_DEF_REGULAR
) == 0)));
2901 /* Deal with function syms. */
2902 if (h
->type
== STT_FUNC
2903 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
2905 /* Clear procedure linkage table information for any symbol that
2906 won't need a .plt entry. */
2907 if (h
->plt
.refcount
<= 0
2908 || SYMBOL_CALLS_LOCAL (info
, h
)
2909 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
2910 && h
->root
.type
== bfd_link_hash_undefweak
))
2912 /* A PLT entry is not required/allowed when:
2914 1. We are not using ld.so; because then the PLT entry
2915 can't be set up, so we can't use one. In this case,
2916 ppc_elf_adjust_dynamic_symbol won't even be called.
2918 2. GC has rendered the entry unused.
2920 3. We know for certain that a call to this symbol
2921 will go to this object, or will remain undefined. */
2922 h
->plt
.offset
= (bfd_vma
) -1;
2923 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
2928 h
->plt
.offset
= (bfd_vma
) -1;
2930 /* If this is a weak symbol, and there is a real definition, the
2931 processor independent code will have arranged for us to see the
2932 real definition first, and we can just use the same value. */
2933 if (h
->weakdef
!= NULL
)
2935 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
2936 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
2937 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
2938 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
2939 if (ELIMINATE_COPY_RELOCS
)
2940 h
->elf_link_hash_flags
2941 = ((h
->elf_link_hash_flags
& ~ELF_LINK_NON_GOT_REF
)
2942 | (h
->weakdef
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
));
2946 /* This is a reference to a symbol defined by a dynamic object which
2947 is not a function. */
2949 /* If we are creating a shared library, we must presume that the
2950 only references to the symbol are via the global offset table.
2951 For such cases we need not do anything here; the relocations will
2952 be handled correctly by relocate_section. */
2956 /* If there are no references to this symbol that do not use the
2957 GOT, we don't need to generate a copy reloc. */
2958 if ((h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0)
2961 if (ELIMINATE_COPY_RELOCS
)
2963 struct ppc_elf_dyn_relocs
*p
;
2964 for (p
= ppc_elf_hash_entry (h
)->dyn_relocs
; p
!= NULL
; p
= p
->next
)
2966 s
= p
->sec
->output_section
;
2967 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
2971 /* If we didn't find any dynamic relocs in read-only sections, then
2972 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
2975 h
->elf_link_hash_flags
&= ~ELF_LINK_NON_GOT_REF
;
2980 /* We must allocate the symbol in our .dynbss section, which will
2981 become part of the .bss section of the executable. There will be
2982 an entry for this symbol in the .dynsym section. The dynamic
2983 object will contain position independent code, so all references
2984 from the dynamic object to this symbol will go through the global
2985 offset table. The dynamic linker will use the .dynsym entry to
2986 determine the address it must put in the global offset table, so
2987 both the dynamic object and the regular object will refer to the
2988 same memory location for the variable.
2990 Of course, if the symbol is sufficiently small, we must instead
2991 allocate it in .sbss. FIXME: It would be better to do this if and
2992 only if there were actually SDAREL relocs for that symbol. */
2994 if (h
->size
<= elf_gp_size (htab
->elf
.dynobj
))
2998 BFD_ASSERT (s
!= NULL
);
3000 /* We must generate a R_PPC_COPY reloc to tell the dynamic linker to
3001 copy the initial value out of the dynamic object and into the
3002 runtime process image. We need to remember the offset into the
3003 .rela.bss section we are going to use. */
3004 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
3008 if (h
->size
<= elf_gp_size (htab
->elf
.dynobj
))
3009 srel
= htab
->relsbss
;
3011 srel
= htab
->relbss
;
3012 BFD_ASSERT (srel
!= NULL
);
3013 srel
->_raw_size
+= sizeof (Elf32_External_Rela
);
3014 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_COPY
;
3017 /* We need to figure out the alignment required for this symbol. I
3018 have no idea how ELF linkers handle this. */
3019 power_of_two
= bfd_log2 (h
->size
);
3020 if (power_of_two
> 4)
3023 /* Apply the required alignment. */
3024 s
->_raw_size
= BFD_ALIGN (s
->_raw_size
,
3025 (bfd_size_type
) (1 << power_of_two
));
3026 if (power_of_two
> bfd_get_section_alignment (htab
->elf
.dynobj
, s
))
3028 if (! bfd_set_section_alignment (htab
->elf
.dynobj
, s
, power_of_two
))
3032 /* Define the symbol as being at this point in the section. */
3033 h
->root
.u
.def
.section
= s
;
3034 h
->root
.u
.def
.value
= s
->_raw_size
;
3036 /* Increment the section size to make room for the symbol. */
3037 s
->_raw_size
+= h
->size
;
3042 /* This is the condition under which finish_dynamic_symbol will be
3043 called from elflink.h. If elflink.h doesn't call our
3044 finish_dynamic_symbol routine, we'll need to do something about
3045 initializing any .plt and .got entries in relocate_section. */
3046 #define WILL_CALL_FINISH_DYNAMIC_SYMBOL(DYN, SHARED, H) \
3049 || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) \
3050 && ((H)->dynindx != -1 \
3051 || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0))
3053 /* Of those relocs that might be copied as dynamic relocs, this macro
3054 selects those that must be copied when linking a shared library,
3055 even when the symbol is local. */
3057 #define MUST_BE_DYN_RELOC(RTYPE) \
3058 ((RTYPE) != R_PPC_REL24 \
3059 && (RTYPE) != R_PPC_REL14 \
3060 && (RTYPE) != R_PPC_REL14_BRTAKEN \
3061 && (RTYPE) != R_PPC_REL14_BRNTAKEN \
3062 && (RTYPE) != R_PPC_REL32)
3064 /* Allocate space in associated reloc sections for dynamic relocs. */
3067 allocate_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
3069 struct bfd_link_info
*info
= inf
;
3070 struct ppc_elf_link_hash_entry
*eh
;
3071 struct ppc_elf_link_hash_table
*htab
;
3072 struct ppc_elf_dyn_relocs
*p
;
3074 if (h
->root
.type
== bfd_link_hash_indirect
)
3077 if (h
->root
.type
== bfd_link_hash_warning
)
3078 /* When warning symbols are created, they **replace** the "real"
3079 entry in the hash table, thus we never get to see the real
3080 symbol in a hash traversal. So look at it now. */
3081 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
3083 htab
= ppc_elf_hash_table (info
);
3084 if (htab
->elf
.dynamic_sections_created
3085 && h
->plt
.refcount
> 0)
3087 /* Make sure this symbol is output as a dynamic symbol. */
3088 if (h
->dynindx
== -1
3089 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
3091 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
3096 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h
))
3098 asection
*s
= htab
->plt
;
3100 /* If this is the first .plt entry, make room for the special
3102 if (s
->_raw_size
== 0)
3103 s
->_raw_size
+= PLT_INITIAL_ENTRY_SIZE
;
3105 /* The PowerPC PLT is actually composed of two parts, the
3106 first part is 2 words (for a load and a jump), and then
3107 there is a remaining word available at the end. */
3108 h
->plt
.offset
= (PLT_INITIAL_ENTRY_SIZE
3110 * ((s
->_raw_size
- PLT_INITIAL_ENTRY_SIZE
)
3111 / PLT_ENTRY_SIZE
)));
3113 /* If this symbol is not defined in a regular file, and we
3114 are not generating a shared library, then set the symbol
3115 to this location in the .plt. This is required to make
3116 function pointers compare as equal between the normal
3117 executable and the shared library. */
3119 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
3121 h
->root
.u
.def
.section
= s
;
3122 h
->root
.u
.def
.value
= h
->plt
.offset
;
3125 /* Make room for this entry. After the 8192nd entry, room
3126 for two entries is allocated. */
3127 s
->_raw_size
+= PLT_ENTRY_SIZE
;
3128 if ((s
->_raw_size
- PLT_INITIAL_ENTRY_SIZE
) / PLT_ENTRY_SIZE
3129 > PLT_NUM_SINGLE_ENTRIES
)
3130 s
->_raw_size
+= PLT_ENTRY_SIZE
;
3132 /* We also need to make an entry in the .rela.plt section. */
3133 htab
->relplt
->_raw_size
+= sizeof (Elf32_External_Rela
);
3137 h
->plt
.offset
= (bfd_vma
) -1;
3138 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
3143 h
->plt
.offset
= (bfd_vma
) -1;
3144 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
3147 eh
= (struct ppc_elf_link_hash_entry
*) h
;
3148 if (eh
->elf
.got
.refcount
> 0)
3150 /* Make sure this symbol is output as a dynamic symbol. */
3151 if (eh
->elf
.dynindx
== -1
3152 && (eh
->elf
.elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
3154 if (!bfd_elf32_link_record_dynamic_symbol (info
, &eh
->elf
))
3158 if (eh
->tls_mask
== (TLS_TLS
| TLS_LD
)
3159 && !(eh
->elf
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
))
3160 /* If just an LD reloc, we'll just use htab->tlsld_got.offset. */
3161 eh
->elf
.got
.offset
= (bfd_vma
) -1;
3165 eh
->elf
.got
.offset
= htab
->got
->_raw_size
;
3166 if ((eh
->tls_mask
& TLS_TLS
) != 0)
3168 if ((eh
->tls_mask
& TLS_LD
) != 0)
3169 htab
->got
->_raw_size
+= 8;
3170 if ((eh
->tls_mask
& TLS_GD
) != 0)
3171 htab
->got
->_raw_size
+= 8;
3172 if ((eh
->tls_mask
& (TLS_TPREL
| TLS_TPRELGD
)) != 0)
3173 htab
->got
->_raw_size
+= 4;
3174 if ((eh
->tls_mask
& TLS_DTPREL
) != 0)
3175 htab
->got
->_raw_size
+= 4;
3178 htab
->got
->_raw_size
+= 4;
3179 dyn
= htab
->elf
.dynamic_sections_created
;
3181 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, &eh
->elf
))
3182 && (ELF_ST_VISIBILITY (eh
->elf
.other
) == STV_DEFAULT
3183 || eh
->elf
.root
.type
!= bfd_link_hash_undefweak
))
3185 /* All the entries we allocated need relocs. */
3186 htab
->relgot
->_raw_size
3187 += ((htab
->got
->_raw_size
- eh
->elf
.got
.offset
) / 4
3188 * sizeof (Elf32_External_Rela
));
3189 /* Except LD only needs one. */
3190 if ((eh
->tls_mask
& TLS_LD
) != 0)
3191 htab
->relgot
->_raw_size
-= sizeof (Elf32_External_Rela
);
3196 eh
->elf
.got
.offset
= (bfd_vma
) -1;
3198 if (eh
->dyn_relocs
== NULL
)
3201 /* In the shared -Bsymbolic case, discard space allocated for
3202 dynamic pc-relative relocs against symbols which turn out to be
3203 defined in regular objects. For the normal shared case, discard
3204 space for relocs that have become local due to symbol visibility
3209 /* Relocs that use pc_count are those that appear on a call insn,
3210 or certain REL relocs (see MUST_BE_DYN_RELOC) that can be
3211 generated via assembly. We want calls to protected symbols to
3212 resolve directly to the function rather than going via the plt.
3213 If people want function pointer comparisons to work as expected
3214 then they should avoid writing weird assembly. */
3215 if (SYMBOL_CALLS_LOCAL (info
, h
))
3217 struct ppc_elf_dyn_relocs
**pp
;
3219 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
3221 p
->count
-= p
->pc_count
;
3230 /* Also discard relocs on undefined weak syms with non-default
3232 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
3233 && h
->root
.type
== bfd_link_hash_undefweak
)
3234 eh
->dyn_relocs
= NULL
;
3236 else if (ELIMINATE_COPY_RELOCS
)
3238 /* For the non-shared case, discard space for relocs against
3239 symbols which turn out to need copy relocs or are not
3242 if ((h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0
3243 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
3244 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
3246 /* Make sure this symbol is output as a dynamic symbol.
3247 Undefined weak syms won't yet be marked as dynamic. */
3248 if (h
->dynindx
== -1
3249 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
3251 if (! bfd_elf64_link_record_dynamic_symbol (info
, h
))
3255 /* If that succeeded, we know we'll be keeping all the
3257 if (h
->dynindx
!= -1)
3261 eh
->dyn_relocs
= NULL
;
3266 /* Finally, allocate space. */
3267 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
3269 asection
*sreloc
= elf_section_data (p
->sec
)->sreloc
;
3270 sreloc
->_raw_size
+= p
->count
* sizeof (Elf32_External_Rela
);
3276 /* Find any dynamic relocs that apply to read-only sections. */
3279 readonly_dynrelocs (struct elf_link_hash_entry
*h
, void *info
)
3281 struct ppc_elf_dyn_relocs
*p
;
3283 if (h
->root
.type
== bfd_link_hash_indirect
)
3286 if (h
->root
.type
== bfd_link_hash_warning
)
3287 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
3289 for (p
= ppc_elf_hash_entry (h
)->dyn_relocs
; p
!= NULL
; p
= p
->next
)
3291 asection
*s
= p
->sec
->output_section
;
3294 && ((s
->flags
& (SEC_READONLY
| SEC_ALLOC
))
3295 == (SEC_READONLY
| SEC_ALLOC
)))
3297 ((struct bfd_link_info
*) info
)->flags
|= DF_TEXTREL
;
3299 /* Not an error, just cut short the traversal. */
3306 /* Set the sizes of the dynamic sections. */
3309 ppc_elf_size_dynamic_sections (bfd
*output_bfd ATTRIBUTE_UNUSED
,
3310 struct bfd_link_info
*info
)
3312 struct ppc_elf_link_hash_table
*htab
;
3318 fprintf (stderr
, "ppc_elf_size_dynamic_sections called\n");
3321 htab
= ppc_elf_hash_table (info
);
3322 BFD_ASSERT (htab
->elf
.dynobj
!= NULL
);
3324 if (elf_hash_table (info
)->dynamic_sections_created
)
3326 /* Set the contents of the .interp section to the interpreter. */
3327 if (info
->executable
)
3329 s
= bfd_get_section_by_name (htab
->elf
.dynobj
, ".interp");
3330 BFD_ASSERT (s
!= NULL
);
3331 s
->_raw_size
= sizeof ELF_DYNAMIC_INTERPRETER
;
3332 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
3336 if (htab
->tlsld_got
.refcount
> 0)
3338 htab
->tlsld_got
.offset
= htab
->got
->_raw_size
;
3339 htab
->got
->_raw_size
+= 8;
3341 htab
->relgot
->_raw_size
+= sizeof (Elf32_External_Rela
);
3344 htab
->tlsld_got
.offset
= (bfd_vma
) -1;
3346 /* Set up .got offsets for local syms, and space for local dynamic
3348 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
3350 bfd_signed_vma
*local_got
;
3351 bfd_signed_vma
*end_local_got
;
3353 bfd_size_type locsymcount
;
3354 Elf_Internal_Shdr
*symtab_hdr
;
3357 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
)
3360 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
3362 struct ppc_elf_dyn_relocs
*p
;
3364 for (p
= ((struct ppc_elf_dyn_relocs
*)
3365 elf_section_data (s
)->local_dynrel
);
3369 if (!bfd_is_abs_section (p
->sec
)
3370 && bfd_is_abs_section (p
->sec
->output_section
))
3372 /* Input section has been discarded, either because
3373 it is a copy of a linkonce section or due to
3374 linker script /DISCARD/, so we'll be discarding
3377 else if (p
->count
!= 0)
3379 elf_section_data (p
->sec
)->sreloc
->_raw_size
3380 += p
->count
* sizeof (Elf32_External_Rela
);
3381 if ((p
->sec
->output_section
->flags
3382 & (SEC_READONLY
| SEC_ALLOC
))
3383 == (SEC_READONLY
| SEC_ALLOC
))
3384 info
->flags
|= DF_TEXTREL
;
3389 local_got
= elf_local_got_refcounts (ibfd
);
3393 symtab_hdr
= &elf_tdata (ibfd
)->symtab_hdr
;
3394 locsymcount
= symtab_hdr
->sh_info
;
3395 end_local_got
= local_got
+ locsymcount
;
3396 lgot_masks
= (char *) end_local_got
;
3398 srel
= htab
->relgot
;
3399 for (; local_got
< end_local_got
; ++local_got
, ++lgot_masks
)
3402 if (*lgot_masks
== (TLS_TLS
| TLS_LD
))
3404 /* If just an LD reloc, we'll just use
3405 htab->tlsld_got.offset. */
3406 if (htab
->tlsld_got
.offset
== (bfd_vma
) -1)
3408 htab
->tlsld_got
.offset
= s
->_raw_size
;
3411 srel
->_raw_size
+= sizeof (Elf32_External_Rela
);
3413 *local_got
= (bfd_vma
) -1;
3417 *local_got
= s
->_raw_size
;
3418 if ((*lgot_masks
& TLS_TLS
) != 0)
3420 if ((*lgot_masks
& TLS_GD
) != 0)
3422 if ((*lgot_masks
& (TLS_TPREL
| TLS_TPRELGD
)) != 0)
3424 if ((*lgot_masks
& TLS_DTPREL
) != 0)
3430 srel
->_raw_size
+= ((s
->_raw_size
- *local_got
) / 4
3431 * sizeof (Elf32_External_Rela
));
3435 *local_got
= (bfd_vma
) -1;
3438 /* Allocate space for global sym dynamic relocs. */
3439 elf_link_hash_traverse (elf_hash_table (info
), allocate_dynrelocs
, info
);
3441 /* We've now determined the sizes of the various dynamic sections.
3442 Allocate memory for them. */
3444 for (s
= htab
->elf
.dynobj
->sections
; s
!= NULL
; s
= s
->next
)
3446 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
3451 || (htab
->sdata
!= NULL
&& s
== htab
->sdata
->section
)
3452 || (htab
->sdata2
!= NULL
&& s
== htab
->sdata2
->section
))
3454 /* Strip this section if we don't need it; see the
3457 else if (strncmp (bfd_get_section_name (dynobj
, s
), ".rela", 5) == 0)
3459 if (s
->_raw_size
== 0)
3461 /* If we don't need this section, strip it from the
3462 output file. This is mostly to handle .rela.bss and
3463 .rela.plt. We must create both sections in
3464 create_dynamic_sections, because they must be created
3465 before the linker maps input sections to output
3466 sections. The linker does that before
3467 adjust_dynamic_symbol is called, and it is that
3468 function which decides whether anything needs to go
3469 into these sections. */
3473 /* Remember whether there are any relocation sections. */
3476 /* We use the reloc_count field as a counter if we need
3477 to copy relocs into the output file. */
3483 /* It's not one of our sections, so don't allocate space. */
3487 if (s
->_raw_size
== 0)
3489 _bfd_strip_section_from_output (info
, s
);
3493 /* Allocate memory for the section contents. */
3494 s
->contents
= bfd_zalloc (htab
->elf
.dynobj
, s
->_raw_size
);
3495 if (s
->contents
== NULL
)
3499 if (htab
->elf
.dynamic_sections_created
)
3501 /* Add some entries to the .dynamic section. We fill in the
3502 values later, in ppc_elf_finish_dynamic_sections, but we
3503 must add the entries now so that we get the correct size for
3504 the .dynamic section. The DT_DEBUG entry is filled in by the
3505 dynamic linker and used by the debugger. */
3506 #define add_dynamic_entry(TAG, VAL) \
3507 bfd_elf32_add_dynamic_entry (info, (TAG), (VAL))
3509 if (info
->executable
)
3511 if (!add_dynamic_entry (DT_DEBUG
, 0))
3515 if (htab
->plt
!= NULL
&& htab
->plt
->_raw_size
!= 0)
3517 if (!add_dynamic_entry (DT_PLTGOT
, 0)
3518 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
3519 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
3520 || !add_dynamic_entry (DT_JMPREL
, 0))
3526 if (!add_dynamic_entry (DT_RELA
, 0)
3527 || !add_dynamic_entry (DT_RELASZ
, 0)
3528 || !add_dynamic_entry (DT_RELAENT
, sizeof (Elf32_External_Rela
)))
3532 /* If any dynamic relocs apply to a read-only section, then we
3533 need a DT_TEXTREL entry. */
3534 if ((info
->flags
& DF_TEXTREL
) == 0)
3535 elf_link_hash_traverse (elf_hash_table (info
), readonly_dynrelocs
,
3538 if ((info
->flags
& DF_TEXTREL
) != 0)
3540 if (!add_dynamic_entry (DT_TEXTREL
, 0))
3544 #undef add_dynamic_entry
3550 update_local_sym_info (bfd
*abfd
,
3551 Elf_Internal_Shdr
*symtab_hdr
,
3552 unsigned long r_symndx
,
3555 bfd_signed_vma
*local_got_refcounts
= elf_local_got_refcounts (abfd
);
3556 char *local_got_tls_masks
;
3558 if (local_got_refcounts
== NULL
)
3560 bfd_size_type size
= symtab_hdr
->sh_info
;
3562 size
*= sizeof (*local_got_refcounts
) + sizeof (*local_got_tls_masks
);
3563 local_got_refcounts
= bfd_zalloc (abfd
, size
);
3564 if (local_got_refcounts
== NULL
)
3566 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
3569 local_got_refcounts
[r_symndx
] += 1;
3570 local_got_tls_masks
= (char *) (local_got_refcounts
+ symtab_hdr
->sh_info
);
3571 local_got_tls_masks
[r_symndx
] |= tls_type
;
3576 bad_shared_reloc (bfd
*abfd
, enum elf_ppc_reloc_type r_type
)
3578 (*_bfd_error_handler
)
3579 (_("%s: relocation %s cannot be used when making a shared object"),
3580 bfd_archive_filename (abfd
),
3581 ppc_elf_howto_table
[r_type
]->name
);
3582 bfd_set_error (bfd_error_bad_value
);
3585 /* Look through the relocs for a section during the first phase, and
3586 allocate space in the global offset table or procedure linkage
3590 ppc_elf_check_relocs (bfd
*abfd
,
3591 struct bfd_link_info
*info
,
3593 const Elf_Internal_Rela
*relocs
)
3595 struct ppc_elf_link_hash_table
*htab
;
3596 Elf_Internal_Shdr
*symtab_hdr
;
3597 struct elf_link_hash_entry
**sym_hashes
;
3598 const Elf_Internal_Rela
*rel
;
3599 const Elf_Internal_Rela
*rel_end
;
3602 if (info
->relocatable
)
3606 fprintf (stderr
, "ppc_elf_check_relocs called for section %s in %s\n",
3607 bfd_get_section_name (abfd
, sec
),
3608 bfd_archive_filename (abfd
));
3611 /* Initialize howto table if not already done. */
3612 if (!ppc_elf_howto_table
[R_PPC_ADDR32
])
3613 ppc_elf_howto_init ();
3615 /* Create the linker generated sections all the time so that the
3616 special symbols are created. */
3617 htab
= ppc_elf_hash_table (info
);
3618 if (htab
->sdata
== NULL
)
3620 htab
->sdata
= ppc_elf_create_linker_section (abfd
, info
,
3621 LINKER_SECTION_SDATA
);
3622 if (htab
->sdata
== NULL
)
3626 if (htab
->sdata2
== NULL
)
3628 htab
->sdata2
= ppc_elf_create_linker_section (abfd
, info
,
3629 LINKER_SECTION_SDATA2
);
3630 if (htab
->sdata2
== NULL
)
3634 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
3635 sym_hashes
= elf_sym_hashes (abfd
);
3638 rel_end
= relocs
+ sec
->reloc_count
;
3639 for (rel
= relocs
; rel
< rel_end
; rel
++)
3641 unsigned long r_symndx
;
3642 enum elf_ppc_reloc_type r_type
;
3643 struct elf_link_hash_entry
*h
;
3646 r_symndx
= ELF32_R_SYM (rel
->r_info
);
3647 if (r_symndx
< symtab_hdr
->sh_info
)
3650 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
3652 /* If a relocation refers to _GLOBAL_OFFSET_TABLE_, create the .got.
3653 This shows up in particular in an R_PPC_ADDR32 in the eabi
3655 if (h
&& strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
3657 if (htab
->got
== NULL
)
3659 if (htab
->elf
.dynobj
== NULL
)
3660 htab
->elf
.dynobj
= abfd
;
3661 if (!ppc_elf_create_got (htab
->elf
.dynobj
, info
))
3666 r_type
= ELF32_R_TYPE (rel
->r_info
);
3669 case R_PPC_GOT_TLSLD16
:
3670 case R_PPC_GOT_TLSLD16_LO
:
3671 case R_PPC_GOT_TLSLD16_HI
:
3672 case R_PPC_GOT_TLSLD16_HA
:
3673 htab
->tlsld_got
.refcount
+= 1;
3674 tls_type
= TLS_TLS
| TLS_LD
;
3677 case R_PPC_GOT_TLSGD16
:
3678 case R_PPC_GOT_TLSGD16_LO
:
3679 case R_PPC_GOT_TLSGD16_HI
:
3680 case R_PPC_GOT_TLSGD16_HA
:
3681 tls_type
= TLS_TLS
| TLS_GD
;
3684 case R_PPC_GOT_TPREL16
:
3685 case R_PPC_GOT_TPREL16_LO
:
3686 case R_PPC_GOT_TPREL16_HI
:
3687 case R_PPC_GOT_TPREL16_HA
:
3689 info
->flags
|= DF_STATIC_TLS
;
3690 tls_type
= TLS_TLS
| TLS_TPREL
;
3693 case R_PPC_GOT_DTPREL16
:
3694 case R_PPC_GOT_DTPREL16_LO
:
3695 case R_PPC_GOT_DTPREL16_HI
:
3696 case R_PPC_GOT_DTPREL16_HA
:
3697 tls_type
= TLS_TLS
| TLS_DTPREL
;
3699 sec
->has_tls_reloc
= 1;
3702 /* GOT16 relocations */
3704 case R_PPC_GOT16_LO
:
3705 case R_PPC_GOT16_HI
:
3706 case R_PPC_GOT16_HA
:
3707 /* This symbol requires a global offset table entry. */
3708 if (htab
->got
== NULL
)
3710 if (htab
->elf
.dynobj
== NULL
)
3711 htab
->elf
.dynobj
= abfd
;
3712 if (!ppc_elf_create_got (htab
->elf
.dynobj
, info
))
3717 h
->got
.refcount
+= 1;
3718 ppc_elf_hash_entry (h
)->tls_mask
|= tls_type
;
3721 /* This is a global offset table entry for a local symbol. */
3722 if (!update_local_sym_info (abfd
, symtab_hdr
, r_symndx
, tls_type
))
3726 /* Indirect .sdata relocation. */
3727 case R_PPC_EMB_SDAI16
:
3730 bad_shared_reloc (abfd
, r_type
);
3733 if (!elf_create_pointer_linker_section (abfd
, info
,
3734 htab
->sdata
, h
, rel
))
3738 /* Indirect .sdata2 relocation. */
3739 case R_PPC_EMB_SDA2I16
:
3742 bad_shared_reloc (abfd
, r_type
);
3745 if (!elf_create_pointer_linker_section (abfd
, info
,
3746 htab
->sdata2
, h
, rel
))
3750 case R_PPC_SDAREL16
:
3751 case R_PPC_EMB_SDA2REL
:
3752 case R_PPC_EMB_SDA21
:
3753 case R_PPC_EMB_RELSDA
:
3754 case R_PPC_EMB_NADDR32
:
3755 case R_PPC_EMB_NADDR16
:
3756 case R_PPC_EMB_NADDR16_LO
:
3757 case R_PPC_EMB_NADDR16_HI
:
3758 case R_PPC_EMB_NADDR16_HA
:
3761 bad_shared_reloc (abfd
, r_type
);
3767 case R_PPC_PLTREL24
:
3768 case R_PPC_PLTREL32
:
3769 case R_PPC_PLT16_LO
:
3770 case R_PPC_PLT16_HI
:
3771 case R_PPC_PLT16_HA
:
3773 fprintf (stderr
, "Reloc requires a PLT entry\n");
3775 /* This symbol requires a procedure linkage table entry. We
3776 actually build the entry in finish_dynamic_symbol,
3777 because this might be a case of linking PIC code without
3778 linking in any dynamic objects, in which case we don't
3779 need to generate a procedure linkage table after all. */
3783 /* It does not make sense to have a procedure linkage
3784 table entry for a local symbol. */
3785 (*_bfd_error_handler
) (_("%s(%s+0x%lx): %s reloc against "
3787 bfd_archive_filename (abfd
),
3789 (long) rel
->r_offset
,
3790 ppc_elf_howto_table
[r_type
]->name
);
3791 bfd_set_error (bfd_error_bad_value
);
3795 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
3799 /* The following relocations don't need to propagate the
3800 relocation if linking a shared object since they are
3801 section relative. */
3803 case R_PPC_SECTOFF_LO
:
3804 case R_PPC_SECTOFF_HI
:
3805 case R_PPC_SECTOFF_HA
:
3806 case R_PPC_DTPREL16
:
3807 case R_PPC_DTPREL16_LO
:
3808 case R_PPC_DTPREL16_HI
:
3809 case R_PPC_DTPREL16_HA
:
3813 /* This are just markers. */
3815 case R_PPC_EMB_MRKREF
:
3820 /* These should only appear in dynamic objects. */
3822 case R_PPC_GLOB_DAT
:
3823 case R_PPC_JMP_SLOT
:
3824 case R_PPC_RELATIVE
:
3827 /* These aren't handled yet. We'll report an error later. */
3829 case R_PPC_EMB_RELSEC16
:
3830 case R_PPC_EMB_RELST_LO
:
3831 case R_PPC_EMB_RELST_HI
:
3832 case R_PPC_EMB_RELST_HA
:
3833 case R_PPC_EMB_BIT_FLD
:
3836 /* This refers only to functions defined in the shared library. */
3837 case R_PPC_LOCAL24PC
:
3840 /* This relocation describes the C++ object vtable hierarchy.
3841 Reconstruct it for later use during GC. */
3842 case R_PPC_GNU_VTINHERIT
:
3843 if (!_bfd_elf32_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
3847 /* This relocation describes which C++ vtable entries are actually
3848 used. Record for later use during GC. */
3849 case R_PPC_GNU_VTENTRY
:
3850 if (!_bfd_elf32_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
3854 /* We shouldn't really be seeing these. */
3857 info
->flags
|= DF_STATIC_TLS
;
3861 case R_PPC_DTPMOD32
:
3862 case R_PPC_DTPREL32
:
3866 case R_PPC_TPREL16_LO
:
3867 case R_PPC_TPREL16_HI
:
3868 case R_PPC_TPREL16_HA
:
3870 info
->flags
|= DF_STATIC_TLS
;
3873 /* When creating a shared object, we must copy these
3874 relocs into the output file. We create a reloc
3875 section in dynobj and make room for the reloc. */
3878 case R_PPC_REL14_BRTAKEN
:
3879 case R_PPC_REL14_BRNTAKEN
:
3882 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
3889 case R_PPC_ADDR16_LO
:
3890 case R_PPC_ADDR16_HI
:
3891 case R_PPC_ADDR16_HA
:
3893 case R_PPC_ADDR14_BRTAKEN
:
3894 case R_PPC_ADDR14_BRNTAKEN
:
3897 if (h
!= NULL
&& !info
->shared
)
3899 /* We may need a plt entry if the symbol turns out to be
3900 a function defined in a dynamic object. */
3903 /* We may need a copy reloc too. */
3904 h
->elf_link_hash_flags
|= ELF_LINK_NON_GOT_REF
;
3908 /* If we are creating a shared library, and this is a reloc
3909 against a global symbol, or a non PC relative reloc
3910 against a local symbol, then we need to copy the reloc
3911 into the shared library. However, if we are linking with
3912 -Bsymbolic, we do not need to copy a reloc against a
3913 global symbol which is defined in an object we are
3914 including in the link (i.e., DEF_REGULAR is set). At
3915 this point we have not seen all the input files, so it is
3916 possible that DEF_REGULAR is not set now but will be set
3917 later (it is never cleared). In case of a weak definition,
3918 DEF_REGULAR may be cleared later by a strong definition in
3919 a shared library. We account for that possibility below by
3920 storing information in the dyn_relocs field of the hash
3921 table entry. A similar situation occurs when creating
3922 shared libraries and symbol visibility changes render the
3925 If on the other hand, we are creating an executable, we
3926 may need to keep relocations for symbols satisfied by a
3927 dynamic library if we manage to avoid copy relocs for the
3930 && (MUST_BE_DYN_RELOC (r_type
)
3932 && (! info
->symbolic
3933 || h
->root
.type
== bfd_link_hash_defweak
3934 || (h
->elf_link_hash_flags
3935 & ELF_LINK_HASH_DEF_REGULAR
) == 0))))
3936 || (ELIMINATE_COPY_RELOCS
3938 && (sec
->flags
& SEC_ALLOC
) != 0
3940 && (h
->root
.type
== bfd_link_hash_defweak
3941 || (h
->elf_link_hash_flags
3942 & ELF_LINK_HASH_DEF_REGULAR
) == 0)))
3944 struct ppc_elf_dyn_relocs
*p
;
3945 struct ppc_elf_dyn_relocs
**head
;
3949 "ppc_elf_check_relocs needs to "
3950 "create relocation for %s\n",
3951 (h
&& h
->root
.root
.string
3952 ? h
->root
.root
.string
: "<unknown>"));
3958 name
= (bfd_elf_string_from_elf_section
3960 elf_elfheader (abfd
)->e_shstrndx
,
3961 elf_section_data (sec
)->rel_hdr
.sh_name
));
3965 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
3966 && strcmp (bfd_get_section_name (abfd
, sec
),
3969 sreloc
= bfd_get_section_by_name (htab
->elf
.dynobj
, name
);
3974 sreloc
= bfd_make_section (htab
->elf
.dynobj
, name
);
3975 flags
= (SEC_HAS_CONTENTS
| SEC_READONLY
3976 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
3977 if ((sec
->flags
& SEC_ALLOC
) != 0)
3978 flags
|= SEC_ALLOC
| SEC_LOAD
;
3980 || ! bfd_set_section_flags (htab
->elf
.dynobj
,
3982 || ! bfd_set_section_alignment (htab
->elf
.dynobj
,
3986 elf_section_data (sec
)->sreloc
= sreloc
;
3989 /* If this is a global symbol, we count the number of
3990 relocations we need for this symbol. */
3993 head
= &ppc_elf_hash_entry (h
)->dyn_relocs
;
3997 /* Track dynamic relocs needed for local syms too.
3998 We really need local syms available to do this
4002 s
= bfd_section_from_r_symndx (abfd
, &htab
->sym_sec
,
4007 head
= ((struct ppc_elf_dyn_relocs
**)
4008 &elf_section_data (s
)->local_dynrel
);
4012 if (p
== NULL
|| p
->sec
!= sec
)
4014 p
= bfd_alloc (htab
->elf
.dynobj
, sizeof *p
);
4025 if (!MUST_BE_DYN_RELOC (r_type
))
4036 /* Return the section that should be marked against GC for a given
4040 ppc_elf_gc_mark_hook (asection
*sec
,
4041 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
4042 Elf_Internal_Rela
*rel
,
4043 struct elf_link_hash_entry
*h
,
4044 Elf_Internal_Sym
*sym
)
4048 switch (ELF32_R_TYPE (rel
->r_info
))
4050 case R_PPC_GNU_VTINHERIT
:
4051 case R_PPC_GNU_VTENTRY
:
4055 switch (h
->root
.type
)
4057 case bfd_link_hash_defined
:
4058 case bfd_link_hash_defweak
:
4059 return h
->root
.u
.def
.section
;
4061 case bfd_link_hash_common
:
4062 return h
->root
.u
.c
.p
->section
;
4070 return bfd_section_from_elf_index (sec
->owner
, sym
->st_shndx
);
4075 /* Update the got, plt and dynamic reloc reference counts for the
4076 section being removed. */
4079 ppc_elf_gc_sweep_hook (bfd
*abfd
,
4080 struct bfd_link_info
*info
,
4082 const Elf_Internal_Rela
*relocs
)
4084 struct ppc_elf_link_hash_table
*htab
;
4085 Elf_Internal_Shdr
*symtab_hdr
;
4086 struct elf_link_hash_entry
**sym_hashes
;
4087 bfd_signed_vma
*local_got_refcounts
;
4088 const Elf_Internal_Rela
*rel
, *relend
;
4090 elf_section_data (sec
)->local_dynrel
= NULL
;
4092 htab
= ppc_elf_hash_table (info
);
4093 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
4094 sym_hashes
= elf_sym_hashes (abfd
);
4095 local_got_refcounts
= elf_local_got_refcounts (abfd
);
4097 relend
= relocs
+ sec
->reloc_count
;
4098 for (rel
= relocs
; rel
< relend
; rel
++)
4100 unsigned long r_symndx
;
4101 enum elf_ppc_reloc_type r_type
;
4102 struct elf_link_hash_entry
*h
= NULL
;
4104 r_symndx
= ELF32_R_SYM (rel
->r_info
);
4105 if (r_symndx
>= symtab_hdr
->sh_info
)
4107 struct ppc_elf_dyn_relocs
**pp
, *p
;
4108 struct ppc_elf_link_hash_entry
*eh
;
4110 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
4111 eh
= (struct ppc_elf_link_hash_entry
*) h
;
4113 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; pp
= &p
->next
)
4116 /* Everything must go for SEC. */
4122 r_type
= ELF32_R_TYPE (rel
->r_info
);
4125 case R_PPC_GOT_TLSLD16
:
4126 case R_PPC_GOT_TLSLD16_LO
:
4127 case R_PPC_GOT_TLSLD16_HI
:
4128 case R_PPC_GOT_TLSLD16_HA
:
4129 htab
->tlsld_got
.refcount
-= 1;
4132 case R_PPC_GOT_TLSGD16
:
4133 case R_PPC_GOT_TLSGD16_LO
:
4134 case R_PPC_GOT_TLSGD16_HI
:
4135 case R_PPC_GOT_TLSGD16_HA
:
4136 case R_PPC_GOT_TPREL16
:
4137 case R_PPC_GOT_TPREL16_LO
:
4138 case R_PPC_GOT_TPREL16_HI
:
4139 case R_PPC_GOT_TPREL16_HA
:
4140 case R_PPC_GOT_DTPREL16
:
4141 case R_PPC_GOT_DTPREL16_LO
:
4142 case R_PPC_GOT_DTPREL16_HI
:
4143 case R_PPC_GOT_DTPREL16_HA
:
4145 case R_PPC_GOT16_LO
:
4146 case R_PPC_GOT16_HI
:
4147 case R_PPC_GOT16_HA
:
4150 if (h
->got
.refcount
> 0)
4153 else if (local_got_refcounts
!= NULL
)
4155 if (local_got_refcounts
[r_symndx
] > 0)
4156 local_got_refcounts
[r_symndx
]--;
4162 case R_PPC_REL14_BRTAKEN
:
4163 case R_PPC_REL14_BRNTAKEN
:
4166 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
4173 case R_PPC_ADDR16_LO
:
4174 case R_PPC_ADDR16_HI
:
4175 case R_PPC_ADDR16_HA
:
4177 case R_PPC_ADDR14_BRTAKEN
:
4178 case R_PPC_ADDR14_BRNTAKEN
:
4182 case R_PPC_PLTREL24
:
4183 case R_PPC_PLT16_LO
:
4184 case R_PPC_PLT16_HI
:
4185 case R_PPC_PLT16_HA
:
4188 if (h
->plt
.refcount
> 0)
4200 /* Set htab->tls_get_addr and call the generic ELF tls_setup function. */
4203 ppc_elf_tls_setup (bfd
*obfd
, struct bfd_link_info
*info
)
4205 struct ppc_elf_link_hash_table
*htab
;
4207 htab
= ppc_elf_hash_table (info
);
4208 htab
->tls_get_addr
= elf_link_hash_lookup (&htab
->elf
, "__tls_get_addr",
4209 FALSE
, FALSE
, TRUE
);
4211 return _bfd_elf_tls_setup (obfd
, info
);
4214 /* Run through all the TLS relocs looking for optimization
4218 ppc_elf_tls_optimize (bfd
*obfd ATTRIBUTE_UNUSED
,
4219 struct bfd_link_info
*info
)
4223 struct ppc_elf_link_hash_table
*htab
;
4225 if (info
->relocatable
|| info
->shared
)
4228 htab
= ppc_elf_hash_table (info
);
4229 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
4231 Elf_Internal_Sym
*locsyms
= NULL
;
4232 Elf_Internal_Shdr
*symtab_hdr
= &elf_tdata (ibfd
)->symtab_hdr
;
4234 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
4235 if (sec
->has_tls_reloc
&& !bfd_is_abs_section (sec
->output_section
))
4237 Elf_Internal_Rela
*relstart
, *rel
, *relend
;
4238 int expecting_tls_get_addr
;
4240 /* Read the relocations. */
4241 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
4243 if (relstart
== NULL
)
4246 expecting_tls_get_addr
= 0;
4247 relend
= relstart
+ sec
->reloc_count
;
4248 for (rel
= relstart
; rel
< relend
; rel
++)
4250 enum elf_ppc_reloc_type r_type
;
4251 unsigned long r_symndx
;
4252 struct elf_link_hash_entry
*h
= NULL
;
4254 char tls_set
, tls_clear
;
4255 bfd_boolean is_local
;
4257 r_symndx
= ELF32_R_SYM (rel
->r_info
);
4258 if (r_symndx
>= symtab_hdr
->sh_info
)
4260 struct elf_link_hash_entry
**sym_hashes
;
4262 sym_hashes
= elf_sym_hashes (ibfd
);
4263 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
4264 while (h
->root
.type
== bfd_link_hash_indirect
4265 || h
->root
.type
== bfd_link_hash_warning
)
4266 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
4271 || !(h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
))
4274 r_type
= ELF32_R_TYPE (rel
->r_info
);
4277 case R_PPC_GOT_TLSLD16
:
4278 case R_PPC_GOT_TLSLD16_LO
:
4279 case R_PPC_GOT_TLSLD16_HI
:
4280 case R_PPC_GOT_TLSLD16_HA
:
4281 /* These relocs should never be against a symbol
4282 defined in a shared lib. Leave them alone if
4283 that turns out to be the case. */
4284 expecting_tls_get_addr
= 0;
4285 htab
->tlsld_got
.refcount
-= 1;
4292 expecting_tls_get_addr
= 1;
4295 case R_PPC_GOT_TLSGD16
:
4296 case R_PPC_GOT_TLSGD16_LO
:
4297 case R_PPC_GOT_TLSGD16_HI
:
4298 case R_PPC_GOT_TLSGD16_HA
:
4304 tls_set
= TLS_TLS
| TLS_TPRELGD
;
4306 expecting_tls_get_addr
= 1;
4309 case R_PPC_GOT_TPREL16
:
4310 case R_PPC_GOT_TPREL16_LO
:
4311 case R_PPC_GOT_TPREL16_HI
:
4312 case R_PPC_GOT_TPREL16_HA
:
4313 expecting_tls_get_addr
= 0;
4318 tls_clear
= TLS_TPREL
;
4325 case R_PPC_REL14_BRTAKEN
:
4326 case R_PPC_REL14_BRNTAKEN
:
4328 if (expecting_tls_get_addr
4330 && h
== htab
->tls_get_addr
)
4332 if (h
->plt
.refcount
> 0)
4333 h
->plt
.refcount
-= 1;
4335 expecting_tls_get_addr
= 0;
4339 expecting_tls_get_addr
= 0;
4347 /* We managed to get rid of a got entry. */
4348 if (h
->got
.refcount
> 0)
4349 h
->got
.refcount
-= 1;
4351 tls_mask
= &ppc_elf_hash_entry (h
)->tls_mask
;
4355 Elf_Internal_Sym
*sym
;
4356 bfd_signed_vma
*lgot_refs
;
4359 if (locsyms
== NULL
)
4361 locsyms
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
4362 if (locsyms
== NULL
)
4363 locsyms
= bfd_elf_get_elf_syms (ibfd
, symtab_hdr
,
4364 symtab_hdr
->sh_info
,
4365 0, NULL
, NULL
, NULL
);
4366 if (locsyms
== NULL
)
4368 if (elf_section_data (sec
)->relocs
!= relstart
)
4373 sym
= locsyms
+ r_symndx
;
4374 lgot_refs
= elf_local_got_refcounts (ibfd
);
4375 if (lgot_refs
== NULL
)
4379 /* We managed to get rid of a got entry. */
4380 if (lgot_refs
[r_symndx
] > 0)
4381 lgot_refs
[r_symndx
] -= 1;
4383 lgot_masks
= (char *) (lgot_refs
+ symtab_hdr
->sh_info
);
4384 tls_mask
= &lgot_masks
[r_symndx
];
4387 *tls_mask
|= tls_set
;
4388 *tls_mask
&= ~tls_clear
;
4391 if (elf_section_data (sec
)->relocs
!= relstart
)
4396 && (symtab_hdr
->contents
!= (unsigned char *) locsyms
))
4398 if (!info
->keep_memory
)
4401 symtab_hdr
->contents
= (unsigned char *) locsyms
;
4407 /* Hook called by the linker routine which adds symbols from an object
4408 file. We use it to put .comm items in .sbss, and not .bss. */
4411 ppc_elf_add_symbol_hook (bfd
*abfd
,
4412 struct bfd_link_info
*info
,
4413 const Elf_Internal_Sym
*sym
,
4414 const char **namep ATTRIBUTE_UNUSED
,
4415 flagword
*flagsp ATTRIBUTE_UNUSED
,
4419 if (sym
->st_shndx
== SHN_COMMON
4420 && !info
->relocatable
4421 && sym
->st_size
<= elf_gp_size (abfd
)
4422 && (info
->hash
->creator
== abfd
->xvec
4423 || info
->hash
->creator
== abfd
->xvec
->alternative_target
))
4425 /* Common symbols less than or equal to -G nn bytes are automatically
4427 struct ppc_elf_link_hash_table
*htab
;
4429 htab
= ppc_elf_hash_table (info
);
4430 if (htab
->sbss
== NULL
)
4432 flagword flags
= SEC_IS_COMMON
;
4434 htab
->sbss
= bfd_make_section_anyway (abfd
, ".sbss");
4435 if (htab
->sbss
== NULL
4436 || ! bfd_set_section_flags (abfd
, htab
->sbss
, flags
))
4441 *valp
= sym
->st_size
;
4447 /* Finish up dynamic symbol handling. We set the contents of various
4448 dynamic sections here. */
4451 ppc_elf_finish_dynamic_symbol (bfd
*output_bfd
,
4452 struct bfd_link_info
*info
,
4453 struct elf_link_hash_entry
*h
,
4454 Elf_Internal_Sym
*sym
)
4456 struct ppc_elf_link_hash_table
*htab
;
4459 fprintf (stderr
, "ppc_elf_finish_dynamic_symbol called for %s",
4460 h
->root
.root
.string
);
4463 htab
= ppc_elf_hash_table (info
);
4464 BFD_ASSERT (htab
->elf
.dynobj
!= NULL
);
4466 if (h
->plt
.offset
!= (bfd_vma
) -1)
4468 Elf_Internal_Rela rela
;
4470 bfd_vma reloc_index
;
4473 fprintf (stderr
, ", plt_offset = %d", h
->plt
.offset
);
4476 /* This symbol has an entry in the procedure linkage table. Set
4479 BFD_ASSERT (h
->dynindx
!= -1);
4480 BFD_ASSERT (htab
->plt
!= NULL
&& htab
->relplt
!= NULL
);
4482 /* We don't need to fill in the .plt. The ppc dynamic linker
4485 /* Fill in the entry in the .rela.plt section. */
4486 rela
.r_offset
= (htab
->plt
->output_section
->vma
4487 + htab
->plt
->output_offset
4489 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_PPC_JMP_SLOT
);
4492 reloc_index
= (h
->plt
.offset
- PLT_INITIAL_ENTRY_SIZE
) / PLT_SLOT_SIZE
;
4493 if (reloc_index
> PLT_NUM_SINGLE_ENTRIES
)
4494 reloc_index
-= (reloc_index
- PLT_NUM_SINGLE_ENTRIES
) / 2;
4495 loc
= (htab
->relplt
->contents
4496 + reloc_index
* sizeof (Elf32_External_Rela
));
4497 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
4499 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
4501 /* Mark the symbol as undefined, rather than as defined in
4502 the .plt section. Leave the value alone. */
4503 sym
->st_shndx
= SHN_UNDEF
;
4504 /* If the symbol is weak, we do need to clear the value.
4505 Otherwise, the PLT entry would provide a definition for
4506 the symbol even if the symbol wasn't defined anywhere,
4507 and so the symbol would never be NULL. */
4508 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_REF_REGULAR_NONWEAK
)
4514 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_COPY
) != 0)
4517 Elf_Internal_Rela rela
;
4520 /* This symbols needs a copy reloc. Set it up. */
4523 fprintf (stderr
, ", copy");
4526 BFD_ASSERT (h
->dynindx
!= -1);
4528 if (h
->size
<= elf_gp_size (htab
->elf
.dynobj
))
4532 BFD_ASSERT (s
!= NULL
);
4534 rela
.r_offset
= (h
->root
.u
.def
.value
4535 + h
->root
.u
.def
.section
->output_section
->vma
4536 + h
->root
.u
.def
.section
->output_offset
);
4537 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_PPC_COPY
);
4539 loc
= s
->contents
+ s
->reloc_count
++ * sizeof (Elf32_External_Rela
);
4540 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
4544 fprintf (stderr
, "\n");
4547 /* Mark some specially defined symbols as absolute. */
4548 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
4549 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0
4550 || strcmp (h
->root
.root
.string
, "_PROCEDURE_LINKAGE_TABLE_") == 0)
4551 sym
->st_shndx
= SHN_ABS
;
4556 /* Finish up the dynamic sections. */
4559 ppc_elf_finish_dynamic_sections (bfd
*output_bfd
,
4560 struct bfd_link_info
*info
)
4563 struct ppc_elf_link_hash_table
*htab
;
4566 fprintf (stderr
, "ppc_elf_finish_dynamic_sections called\n");
4569 htab
= ppc_elf_hash_table (info
);
4570 sdyn
= bfd_get_section_by_name (htab
->elf
.dynobj
, ".dynamic");
4572 if (htab
->elf
.dynamic_sections_created
)
4574 Elf32_External_Dyn
*dyncon
, *dynconend
;
4576 BFD_ASSERT (htab
->plt
!= NULL
&& sdyn
!= NULL
);
4578 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
4579 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
4580 for (; dyncon
< dynconend
; dyncon
++)
4582 Elf_Internal_Dyn dyn
;
4585 bfd_elf32_swap_dyn_in (htab
->elf
.dynobj
, dyncon
, &dyn
);
4591 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
4595 dyn
.d_un
.d_val
= htab
->relplt
->_raw_size
;
4600 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
4607 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
4611 /* Add a blrl instruction at _GLOBAL_OFFSET_TABLE_-4 so that a function can
4612 easily find the address of the _GLOBAL_OFFSET_TABLE_. */
4615 unsigned char *contents
= htab
->got
->contents
;
4616 bfd_put_32 (output_bfd
, 0x4e800021 /* blrl */, contents
);
4619 bfd_put_32 (output_bfd
, 0, contents
+ 4);
4621 bfd_put_32 (output_bfd
,
4622 sdyn
->output_section
->vma
+ sdyn
->output_offset
,
4625 elf_section_data (htab
->got
->output_section
)->this_hdr
.sh_entsize
= 4;
4631 /* The RELOCATE_SECTION function is called by the ELF backend linker
4632 to handle the relocations for a section.
4634 The relocs are always passed as Rela structures; if the section
4635 actually uses Rel structures, the r_addend field will always be
4638 This function is responsible for adjust the section contents as
4639 necessary, and (if using Rela relocs and generating a
4640 relocatable output file) adjusting the reloc addend as
4643 This function does not have to worry about setting the reloc
4644 address or the reloc symbol index.
4646 LOCAL_SYMS is a pointer to the swapped in local symbols.
4648 LOCAL_SECTIONS is an array giving the section in the input file
4649 corresponding to the st_shndx field of each local symbol.
4651 The global hash table entry for the global symbols can be found
4652 via elf_sym_hashes (input_bfd).
4654 When generating relocatable output, this function must handle
4655 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
4656 going to be the section symbol corresponding to the output
4657 section, which means that the addend must be adjusted
4661 ppc_elf_relocate_section (bfd
*output_bfd
,
4662 struct bfd_link_info
*info
,
4664 asection
*input_section
,
4666 Elf_Internal_Rela
*relocs
,
4667 Elf_Internal_Sym
*local_syms
,
4668 asection
**local_sections
)
4670 Elf_Internal_Shdr
*symtab_hdr
;
4671 struct elf_link_hash_entry
**sym_hashes
;
4672 struct ppc_elf_link_hash_table
*htab
;
4673 Elf_Internal_Rela
*rel
;
4674 Elf_Internal_Rela
*relend
;
4675 Elf_Internal_Rela outrel
;
4677 asection
*sreloc
= NULL
;
4678 bfd_vma
*local_got_offsets
;
4679 bfd_boolean ret
= TRUE
;
4682 fprintf (stderr
, "ppc_elf_relocate_section called for %s section %s, "
4683 "%ld relocations%s\n",
4684 bfd_archive_filename (input_bfd
),
4685 bfd_section_name(input_bfd
, input_section
),
4686 (long) input_section
->reloc_count
,
4687 (info
->relocatable
) ? " (relocatable)" : "");
4690 if (info
->relocatable
)
4693 /* Initialize howto table if not already done. */
4694 if (!ppc_elf_howto_table
[R_PPC_ADDR32
])
4695 ppc_elf_howto_init ();
4697 htab
= ppc_elf_hash_table (info
);
4698 local_got_offsets
= elf_local_got_offsets (input_bfd
);
4699 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
4700 sym_hashes
= elf_sym_hashes (input_bfd
);
4702 relend
= relocs
+ input_section
->reloc_count
;
4703 for (; rel
< relend
; rel
++)
4705 enum elf_ppc_reloc_type r_type
;
4707 bfd_reloc_status_type r
;
4708 Elf_Internal_Sym
*sym
;
4710 struct elf_link_hash_entry
*h
;
4711 const char *sym_name
;
4712 reloc_howto_type
*howto
;
4713 unsigned long r_symndx
;
4715 bfd_vma branch_bit
, insn
, from
;
4716 bfd_boolean unresolved_reloc
;
4718 unsigned int tls_type
, tls_mask
, tls_gd
;
4720 r_type
= ELF32_R_TYPE (rel
->r_info
);
4724 unresolved_reloc
= FALSE
;
4726 r_symndx
= ELF32_R_SYM (rel
->r_info
);
4728 if (r_symndx
< symtab_hdr
->sh_info
)
4730 sym
= local_syms
+ r_symndx
;
4731 sec
= local_sections
[r_symndx
];
4732 sym_name
= bfd_elf_local_sym_name (input_bfd
, sym
);
4734 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
4738 RELOC_FOR_GLOBAL_SYMBOL (h
, sym_hashes
, r_symndx
,
4739 symtab_hdr
, relocation
, sec
,
4740 unresolved_reloc
, info
,
4743 sym_name
= h
->root
.root
.string
;
4746 /* TLS optimizations. Replace instruction sequences and relocs
4747 based on information we collected in tls_optimize. We edit
4748 RELOCS so that --emit-relocs will output something sensible
4749 for the final instruction stream. */
4752 if (IS_PPC_TLS_RELOC (r_type
))
4755 tls_mask
= ((struct ppc_elf_link_hash_entry
*) h
)->tls_mask
;
4756 else if (local_got_offsets
!= NULL
)
4759 lgot_masks
= (char *) (local_got_offsets
+ symtab_hdr
->sh_info
);
4760 tls_mask
= lgot_masks
[r_symndx
];
4764 /* Ensure reloc mapping code below stays sane. */
4765 if ((R_PPC_GOT_TLSLD16
& 3) != (R_PPC_GOT_TLSGD16
& 3)
4766 || (R_PPC_GOT_TLSLD16_LO
& 3) != (R_PPC_GOT_TLSGD16_LO
& 3)
4767 || (R_PPC_GOT_TLSLD16_HI
& 3) != (R_PPC_GOT_TLSGD16_HI
& 3)
4768 || (R_PPC_GOT_TLSLD16_HA
& 3) != (R_PPC_GOT_TLSGD16_HA
& 3)
4769 || (R_PPC_GOT_TLSLD16
& 3) != (R_PPC_GOT_TPREL16
& 3)
4770 || (R_PPC_GOT_TLSLD16_LO
& 3) != (R_PPC_GOT_TPREL16_LO
& 3)
4771 || (R_PPC_GOT_TLSLD16_HI
& 3) != (R_PPC_GOT_TPREL16_HI
& 3)
4772 || (R_PPC_GOT_TLSLD16_HA
& 3) != (R_PPC_GOT_TPREL16_HA
& 3))
4779 case R_PPC_GOT_TPREL16
:
4780 case R_PPC_GOT_TPREL16_LO
:
4782 && (tls_mask
& TLS_TPREL
) == 0)
4785 insn
= bfd_get_32 (output_bfd
, contents
+ rel
->r_offset
- 2);
4787 insn
|= 0x3c020000; /* addis 0,2,0 */
4788 bfd_put_32 (output_bfd
, insn
, contents
+ rel
->r_offset
- 2);
4789 r_type
= R_PPC_TPREL16_HA
;
4790 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
4796 && (tls_mask
& TLS_TPREL
) == 0)
4799 insn
= bfd_get_32 (output_bfd
, contents
+ rel
->r_offset
);
4800 if ((insn
& ((31 << 26) | (31 << 11)))
4801 == ((31 << 26) | (2 << 11)))
4802 rtra
= insn
& ((1 << 26) - (1 << 16));
4803 else if ((insn
& ((31 << 26) | (31 << 16)))
4804 == ((31 << 26) | (2 << 16)))
4805 rtra
= (insn
& (31 << 21)) | ((insn
& (31 << 11)) << 5);
4808 if ((insn
& ((1 << 11) - (1 << 1))) == 266 << 1)
4811 else if ((insn
& (31 << 1)) == 23 << 1
4812 && ((insn
& (31 << 6)) < 14 << 6
4813 || ((insn
& (31 << 6)) >= 16 << 6
4814 && (insn
& (31 << 6)) < 24 << 6)))
4815 /* load and store indexed -> dform. */
4816 insn
= (32 | ((insn
>> 6) & 31)) << 26;
4817 else if ((insn
& (31 << 1)) == 21 << 1
4818 && (insn
& (0x1a << 6)) == 0)
4819 /* ldx, ldux, stdx, stdux -> ld, ldu, std, stdu. */
4820 insn
= (((58 | ((insn
>> 6) & 4)) << 26)
4821 | ((insn
>> 6) & 1));
4822 else if ((insn
& (31 << 1)) == 21 << 1
4823 && (insn
& ((1 << 11) - (1 << 1))) == 341 << 1)
4825 insn
= (58 << 26) | 2;
4829 bfd_put_32 (output_bfd
, insn
, contents
+ rel
->r_offset
);
4830 r_type
= R_PPC_TPREL16_LO
;
4831 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
4832 /* Was PPC_TLS which sits on insn boundary, now
4833 PPC_TPREL16_LO which is at insn+2. */
4838 case R_PPC_GOT_TLSGD16_HI
:
4839 case R_PPC_GOT_TLSGD16_HA
:
4840 tls_gd
= TLS_TPRELGD
;
4841 if (tls_mask
!= 0 && (tls_mask
& TLS_GD
) == 0)
4845 case R_PPC_GOT_TLSLD16_HI
:
4846 case R_PPC_GOT_TLSLD16_HA
:
4847 if (tls_mask
!= 0 && (tls_mask
& TLS_LD
) == 0)
4850 if ((tls_mask
& tls_gd
) != 0)
4851 r_type
= (((r_type
- (R_PPC_GOT_TLSGD16
& 3)) & 3)
4852 + R_PPC_GOT_TPREL16
);
4855 bfd_put_32 (output_bfd
, NOP
, contents
+ rel
->r_offset
);
4857 r_type
= R_PPC_NONE
;
4859 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
4863 case R_PPC_GOT_TLSGD16
:
4864 case R_PPC_GOT_TLSGD16_LO
:
4865 tls_gd
= TLS_TPRELGD
;
4866 if (tls_mask
!= 0 && (tls_mask
& TLS_GD
) == 0)
4867 goto tls_get_addr_check
;
4870 case R_PPC_GOT_TLSLD16
:
4871 case R_PPC_GOT_TLSLD16_LO
:
4872 if (tls_mask
!= 0 && (tls_mask
& TLS_LD
) == 0)
4875 if (rel
+ 1 < relend
)
4877 enum elf_ppc_reloc_type r_type2
;
4878 unsigned long r_symndx2
;
4879 struct elf_link_hash_entry
*h2
;
4880 bfd_vma insn1
, insn2
;
4883 /* The next instruction should be a call to
4884 __tls_get_addr. Peek at the reloc to be sure. */
4885 r_type2
= ELF32_R_TYPE (rel
[1].r_info
);
4886 r_symndx2
= ELF32_R_SYM (rel
[1].r_info
);
4887 if (r_symndx2
< symtab_hdr
->sh_info
4888 || (r_type2
!= R_PPC_REL14
4889 && r_type2
!= R_PPC_REL14_BRTAKEN
4890 && r_type2
!= R_PPC_REL14_BRNTAKEN
4891 && r_type2
!= R_PPC_REL24
4892 && r_type2
!= R_PPC_PLTREL24
))
4895 h2
= sym_hashes
[r_symndx2
- symtab_hdr
->sh_info
];
4896 while (h2
->root
.type
== bfd_link_hash_indirect
4897 || h2
->root
.type
== bfd_link_hash_warning
)
4898 h2
= (struct elf_link_hash_entry
*) h2
->root
.u
.i
.link
;
4899 if (h2
== NULL
|| h2
!= htab
->tls_get_addr
)
4902 /* OK, it checks out. Replace the call. */
4903 offset
= rel
[1].r_offset
;
4904 insn1
= bfd_get_32 (output_bfd
,
4905 contents
+ rel
->r_offset
- 2);
4906 if ((tls_mask
& tls_gd
) != 0)
4909 insn1
&= (1 << 26) - 1;
4910 insn1
|= 32 << 26; /* lwz */
4911 insn2
= 0x7c631214; /* add 3,3,2 */
4912 rel
[1].r_info
= ELF32_R_INFO (r_symndx2
, R_PPC_NONE
);
4913 r_type
= (((r_type
- (R_PPC_GOT_TLSGD16
& 3)) & 3)
4914 + R_PPC_GOT_TPREL16
);
4915 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
4920 insn1
= 0x3c620000; /* addis 3,2,0 */
4921 insn2
= 0x38630000; /* addi 3,3,0 */
4924 /* Was an LD reloc. */
4926 rel
->r_addend
= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
4927 rel
[1].r_addend
= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
4929 r_type
= R_PPC_TPREL16_HA
;
4930 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
4931 rel
[1].r_info
= ELF32_R_INFO (r_symndx
,
4933 rel
[1].r_offset
+= 2;
4935 bfd_put_32 (output_bfd
, insn1
, contents
+ rel
->r_offset
- 2);
4936 bfd_put_32 (output_bfd
, insn2
, contents
+ offset
);
4939 /* We changed the symbol on an LD reloc. Start over
4940 in order to get h, sym, sec etc. right. */
4949 /* Handle other relocations that tweak non-addend part of insn. */
4956 /* Branch taken prediction relocations. */
4957 case R_PPC_ADDR14_BRTAKEN
:
4958 case R_PPC_REL14_BRTAKEN
:
4959 branch_bit
= BRANCH_PREDICT_BIT
;
4962 /* Branch not taken predicition relocations. */
4963 case R_PPC_ADDR14_BRNTAKEN
:
4964 case R_PPC_REL14_BRNTAKEN
:
4965 insn
= bfd_get_32 (output_bfd
, contents
+ rel
->r_offset
);
4966 insn
&= ~BRANCH_PREDICT_BIT
;
4969 from
= (rel
->r_offset
4970 + input_section
->output_offset
4971 + input_section
->output_section
->vma
);
4973 /* Invert 'y' bit if not the default. */
4974 if ((bfd_signed_vma
) (relocation
+ rel
->r_addend
- from
) < 0)
4975 insn
^= BRANCH_PREDICT_BIT
;
4977 bfd_put_32 (output_bfd
, insn
, contents
+ rel
->r_offset
);
4981 addend
= rel
->r_addend
;
4984 if (r_type
< R_PPC_max
)
4985 howto
= ppc_elf_howto_table
[r_type
];
4989 (*_bfd_error_handler
)
4990 (_("%s: unknown relocation type %d for symbol %s"),
4991 bfd_archive_filename (input_bfd
), (int) r_type
, sym_name
);
4993 bfd_set_error (bfd_error_bad_value
);
4999 case R_PPC_EMB_MRKREF
:
5000 case R_PPC_GNU_VTINHERIT
:
5001 case R_PPC_GNU_VTENTRY
:
5004 /* GOT16 relocations. Like an ADDR16 using the symbol's
5005 address in the GOT as relocation value instead of the
5006 symbol's value itself. Also, create a GOT entry for the
5007 symbol and put the symbol value there. */
5008 case R_PPC_GOT_TLSGD16
:
5009 case R_PPC_GOT_TLSGD16_LO
:
5010 case R_PPC_GOT_TLSGD16_HI
:
5011 case R_PPC_GOT_TLSGD16_HA
:
5012 tls_type
= TLS_TLS
| TLS_GD
;
5015 case R_PPC_GOT_TLSLD16
:
5016 case R_PPC_GOT_TLSLD16_LO
:
5017 case R_PPC_GOT_TLSLD16_HI
:
5018 case R_PPC_GOT_TLSLD16_HA
:
5019 tls_type
= TLS_TLS
| TLS_LD
;
5022 case R_PPC_GOT_TPREL16
:
5023 case R_PPC_GOT_TPREL16_LO
:
5024 case R_PPC_GOT_TPREL16_HI
:
5025 case R_PPC_GOT_TPREL16_HA
:
5026 tls_type
= TLS_TLS
| TLS_TPREL
;
5029 case R_PPC_GOT_DTPREL16
:
5030 case R_PPC_GOT_DTPREL16_LO
:
5031 case R_PPC_GOT_DTPREL16_HI
:
5032 case R_PPC_GOT_DTPREL16_HA
:
5033 tls_type
= TLS_TLS
| TLS_DTPREL
;
5037 case R_PPC_GOT16_LO
:
5038 case R_PPC_GOT16_HI
:
5039 case R_PPC_GOT16_HA
:
5042 /* Relocation is to the entry for this symbol in the global
5048 if (htab
->got
== NULL
)
5052 if (tls_type
== (TLS_TLS
| TLS_LD
)
5054 || !(h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
)))
5055 offp
= &htab
->tlsld_got
.offset
;
5059 dyn
= htab
->elf
.dynamic_sections_created
;
5060 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
5062 && SYMBOL_REFERENCES_LOCAL (info
, h
)))
5063 /* This is actually a static link, or it is a
5064 -Bsymbolic link and the symbol is defined
5065 locally, or the symbol was forced to be local
5066 because of a version file. */
5071 unresolved_reloc
= FALSE
;
5073 offp
= &h
->got
.offset
;
5077 if (local_got_offsets
== NULL
)
5079 offp
= &local_got_offsets
[r_symndx
];
5082 /* The offset must always be a multiple of 4. We use the
5083 least significant bit to record whether we have already
5084 processed this entry. */
5090 unsigned int tls_m
= (tls_mask
5091 & (TLS_LD
| TLS_GD
| TLS_DTPREL
5092 | TLS_TPREL
| TLS_TPRELGD
));
5094 if (offp
== &htab
->tlsld_got
.offset
)
5097 || !(h
->elf_link_hash_flags
5098 & ELF_LINK_HASH_DEF_DYNAMIC
))
5101 /* We might have multiple got entries for this sym.
5102 Initialize them all. */
5107 if ((tls_m
& TLS_LD
) != 0)
5109 tls_ty
= TLS_TLS
| TLS_LD
;
5112 else if ((tls_m
& TLS_GD
) != 0)
5114 tls_ty
= TLS_TLS
| TLS_GD
;
5117 else if ((tls_m
& TLS_DTPREL
) != 0)
5119 tls_ty
= TLS_TLS
| TLS_DTPREL
;
5120 tls_m
&= ~TLS_DTPREL
;
5122 else if ((tls_m
& (TLS_TPREL
| TLS_TPRELGD
)) != 0)
5124 tls_ty
= TLS_TLS
| TLS_TPREL
;
5128 /* Generate relocs for the dynamic linker. */
5129 if ((info
->shared
|| indx
!= 0)
5131 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
5132 || h
->root
.type
!= bfd_link_hash_undefweak
))
5134 outrel
.r_offset
= (htab
->got
->output_section
->vma
5135 + htab
->got
->output_offset
5137 outrel
.r_addend
= 0;
5138 if (tls_ty
& (TLS_LD
| TLS_GD
))
5140 outrel
.r_info
= ELF32_R_INFO (indx
, R_PPC_DTPMOD32
);
5141 if (tls_ty
== (TLS_TLS
| TLS_GD
))
5143 loc
= htab
->relgot
->contents
;
5144 loc
+= (htab
->relgot
->reloc_count
++
5145 * sizeof (Elf32_External_Rela
));
5146 bfd_elf32_swap_reloca_out (output_bfd
,
5148 outrel
.r_offset
+= 4;
5150 = ELF32_R_INFO (indx
, R_PPC_DTPREL32
);
5153 else if (tls_ty
== (TLS_TLS
| TLS_DTPREL
))
5154 outrel
.r_info
= ELF32_R_INFO (indx
, R_PPC_DTPREL32
);
5155 else if (tls_ty
== (TLS_TLS
| TLS_TPREL
))
5156 outrel
.r_info
= ELF32_R_INFO (indx
, R_PPC_TPREL32
);
5158 outrel
.r_info
= ELF32_R_INFO (indx
, R_PPC_RELATIVE
);
5160 outrel
.r_info
= ELF32_R_INFO (indx
, R_PPC_GLOB_DAT
);
5163 outrel
.r_addend
+= relocation
;
5164 if (tls_ty
& (TLS_GD
| TLS_DTPREL
| TLS_TPREL
))
5165 outrel
.r_addend
-= htab
->elf
.tls_sec
->vma
;
5167 loc
= htab
->relgot
->contents
;
5168 loc
+= (htab
->relgot
->reloc_count
++
5169 * sizeof (Elf32_External_Rela
));
5170 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
5173 /* Init the .got section contents if we're not
5174 emitting a reloc. */
5177 bfd_vma value
= relocation
;
5179 if (tls_ty
== (TLS_TLS
| TLS_LD
))
5181 else if (tls_ty
!= 0)
5183 value
-= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
5184 if (tls_ty
== (TLS_TLS
| TLS_TPREL
))
5185 value
+= DTP_OFFSET
- TP_OFFSET
;
5187 if (tls_ty
== (TLS_TLS
| TLS_GD
))
5189 bfd_put_32 (output_bfd
, value
,
5190 htab
->got
->contents
+ off
+ 4);
5194 bfd_put_32 (output_bfd
, value
,
5195 htab
->got
->contents
+ off
);
5199 if (tls_ty
& (TLS_LD
| TLS_GD
))
5208 if (off
>= (bfd_vma
) -2)
5211 if ((tls_type
& TLS_TLS
) != 0)
5213 if (tls_type
!= (TLS_TLS
| TLS_LD
))
5215 if ((tls_mask
& TLS_LD
) != 0
5217 || !(h
->elf_link_hash_flags
5218 & ELF_LINK_HASH_DEF_DYNAMIC
)))
5220 if (tls_type
!= (TLS_TLS
| TLS_GD
))
5222 if ((tls_mask
& TLS_GD
) != 0)
5224 if (tls_type
!= (TLS_TLS
| TLS_DTPREL
))
5226 if ((tls_mask
& TLS_DTPREL
) != 0)
5233 relocation
= htab
->got
->output_offset
+ off
- 4;
5235 /* Addends on got relocations don't make much sense.
5236 x+off@got is actually x@got+off, and since the got is
5237 generated by a hash table traversal, the value in the
5238 got at entry m+n bears little relation to the entry m. */
5240 (*_bfd_error_handler
)
5241 (_("%s(%s+0x%lx): non-zero addend on %s reloc against `%s'"),
5242 bfd_archive_filename (input_bfd
),
5243 bfd_get_section_name (input_bfd
, input_section
),
5244 (long) rel
->r_offset
,
5250 /* Relocations that need no special processing. */
5251 case R_PPC_LOCAL24PC
:
5252 /* It makes no sense to point a local relocation
5253 at a symbol not in this object. */
5254 if (unresolved_reloc
)
5256 if (! (*info
->callbacks
->undefined_symbol
) (info
,
5257 h
->root
.root
.string
,
5267 case R_PPC_DTPREL16
:
5268 case R_PPC_DTPREL16_LO
:
5269 case R_PPC_DTPREL16_HI
:
5270 case R_PPC_DTPREL16_HA
:
5271 addend
-= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
5274 /* Relocations that may need to be propagated if this is a shared
5277 case R_PPC_TPREL16_LO
:
5278 case R_PPC_TPREL16_HI
:
5279 case R_PPC_TPREL16_HA
:
5280 addend
-= htab
->elf
.tls_sec
->vma
+ TP_OFFSET
;
5281 /* The TPREL16 relocs shouldn't really be used in shared
5282 libs as they will result in DT_TEXTREL being set, but
5283 support them anyway. */
5287 addend
-= htab
->elf
.tls_sec
->vma
+ TP_OFFSET
;
5290 case R_PPC_DTPREL32
:
5291 addend
-= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
5294 case R_PPC_DTPMOD32
:
5302 case R_PPC_REL14_BRTAKEN
:
5303 case R_PPC_REL14_BRNTAKEN
:
5304 /* If these relocations are not to a named symbol, they can be
5305 handled right here, no need to bother the dynamic linker. */
5306 if (SYMBOL_REFERENCES_LOCAL (info
, h
)
5307 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
5311 /* Relocations that always need to be propagated if this is a shared
5316 case R_PPC_ADDR16_LO
:
5317 case R_PPC_ADDR16_HI
:
5318 case R_PPC_ADDR16_HA
:
5320 case R_PPC_ADDR14_BRTAKEN
:
5321 case R_PPC_ADDR14_BRNTAKEN
:
5324 /* r_symndx will be zero only for relocs against symbols
5325 from removed linkonce sections, or sections discarded by
5334 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
5335 || h
->root
.type
!= bfd_link_hash_undefweak
)
5336 && (MUST_BE_DYN_RELOC (r_type
)
5337 || !SYMBOL_CALLS_LOCAL (info
, h
)))
5338 || (ELIMINATE_COPY_RELOCS
5340 && (input_section
->flags
& SEC_ALLOC
) != 0
5343 && (h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0
5344 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
5345 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0))
5350 fprintf (stderr
, "ppc_elf_relocate_section needs to "
5351 "create relocation for %s\n",
5352 (h
&& h
->root
.root
.string
5353 ? h
->root
.root
.string
: "<unknown>"));
5356 /* When generating a shared object, these relocations
5357 are copied into the output file to be resolved at run
5363 name
= (bfd_elf_string_from_elf_section
5365 elf_elfheader (input_bfd
)->e_shstrndx
,
5366 elf_section_data (input_section
)->rel_hdr
.sh_name
));
5370 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
5371 && strcmp (bfd_get_section_name (input_bfd
,
5375 sreloc
= bfd_get_section_by_name (htab
->elf
.dynobj
, name
);
5376 BFD_ASSERT (sreloc
!= NULL
);
5382 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
5384 if (outrel
.r_offset
== (bfd_vma
) -1
5385 || outrel
.r_offset
== (bfd_vma
) -2)
5386 skip
= (int) outrel
.r_offset
;
5387 outrel
.r_offset
+= (input_section
->output_section
->vma
5388 + input_section
->output_offset
);
5391 memset (&outrel
, 0, sizeof outrel
);
5392 else if (!SYMBOL_REFERENCES_LOCAL (info
, h
))
5394 unresolved_reloc
= FALSE
;
5395 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
5396 outrel
.r_addend
= rel
->r_addend
;
5400 outrel
.r_addend
= relocation
+ rel
->r_addend
;
5402 if (r_type
== R_PPC_ADDR32
)
5403 outrel
.r_info
= ELF32_R_INFO (0, R_PPC_RELATIVE
);
5408 if (bfd_is_abs_section (sec
))
5410 else if (sec
== NULL
|| sec
->owner
== NULL
)
5412 bfd_set_error (bfd_error_bad_value
);
5419 /* We are turning this relocation into one
5420 against a section symbol. It would be
5421 proper to subtract the symbol's value,
5422 osec->vma, from the emitted reloc addend,
5423 but ld.so expects buggy relocs. */
5424 osec
= sec
->output_section
;
5425 indx
= elf_section_data (osec
)->dynindx
;
5426 BFD_ASSERT (indx
> 0);
5429 printf ("indx=%d section=%s flags=%08x name=%s\n",
5430 indx
, osec
->name
, osec
->flags
,
5431 h
->root
.root
.string
);
5435 outrel
.r_info
= ELF32_R_INFO (indx
, r_type
);
5439 loc
= sreloc
->contents
;
5440 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rela
);
5441 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
5446 /* This reloc will be computed at runtime. We clear the memory
5447 so that it contains predictable value. */
5449 && ((input_section
->flags
& SEC_ALLOC
) != 0
5450 || ELF32_R_TYPE (outrel
.r_info
) != R_PPC_RELATIVE
))
5452 relocation
= howto
->pc_relative
? outrel
.r_offset
: 0;
5459 case R_PPC_RELAX32PC
:
5460 relocation
-= (input_section
->output_section
->vma
5461 + input_section
->output_offset
5462 + rel
->r_offset
- 4);
5465 ppc_elf_install_value (output_bfd
, contents
+ rel
->r_offset
,
5466 relocation
+ addend
, r_type
);
5469 /* Indirect .sdata relocation. */
5470 case R_PPC_EMB_SDAI16
:
5471 BFD_ASSERT (htab
->sdata
!= NULL
);
5473 = elf_finish_pointer_linker_section (output_bfd
, input_bfd
, info
,
5474 htab
->sdata
, h
, relocation
,
5475 rel
, R_PPC_RELATIVE
);
5478 /* Indirect .sdata2 relocation. */
5479 case R_PPC_EMB_SDA2I16
:
5480 BFD_ASSERT (htab
->sdata2
!= NULL
);
5482 = elf_finish_pointer_linker_section (output_bfd
, input_bfd
, info
,
5483 htab
->sdata2
, h
, relocation
,
5484 rel
, R_PPC_RELATIVE
);
5487 /* Handle the TOC16 reloc. We want to use the offset within the .got
5488 section, not the actual VMA. This is appropriate when generating
5489 an embedded ELF object, for which the .got section acts like the
5490 AIX .toc section. */
5491 case R_PPC_TOC16
: /* phony GOT16 relocations */
5492 BFD_ASSERT (sec
!= NULL
);
5493 BFD_ASSERT (bfd_is_und_section (sec
)
5494 || strcmp (bfd_get_section_name (abfd
, sec
), ".got") == 0
5495 || strcmp (bfd_get_section_name (abfd
, sec
), ".cgot") == 0)
5497 addend
-= sec
->output_section
->vma
+ sec
->output_offset
+ 0x8000;
5500 case R_PPC_PLTREL24
:
5501 /* Relocation is to the entry for this symbol in the
5502 procedure linkage table. */
5503 BFD_ASSERT (h
!= NULL
);
5505 if (h
->plt
.offset
== (bfd_vma
) -1
5506 || htab
->plt
== NULL
)
5508 /* We didn't make a PLT entry for this symbol. This
5509 happens when statically linking PIC code, or when
5510 using -Bsymbolic. */
5514 unresolved_reloc
= FALSE
;
5515 relocation
= (htab
->plt
->output_section
->vma
5516 + htab
->plt
->output_offset
5520 /* Relocate against _SDA_BASE_. */
5521 case R_PPC_SDAREL16
:
5524 const struct elf_link_hash_entry
*sh
;
5526 BFD_ASSERT (sec
!= NULL
);
5527 name
= bfd_get_section_name (abfd
, sec
->output_section
);
5528 if (! ((strncmp (name
, ".sdata", 6) == 0
5529 && (name
[6] == 0 || name
[6] == '.'))
5530 || (strncmp (name
, ".sbss", 5) == 0
5531 && (name
[5] == 0 || name
[5] == '.'))))
5533 (*_bfd_error_handler
)
5534 (_("%s: the target (%s) of a %s relocation is "
5535 "in the wrong output section (%s)"),
5536 bfd_archive_filename (input_bfd
),
5541 sh
= htab
->sdata
->sym_hash
;
5542 addend
-= (sh
->root
.u
.def
.value
5543 + sh
->root
.u
.def
.section
->output_section
->vma
5544 + sh
->root
.u
.def
.section
->output_offset
);
5548 /* Relocate against _SDA2_BASE_. */
5549 case R_PPC_EMB_SDA2REL
:
5552 const struct elf_link_hash_entry
*sh
;
5554 BFD_ASSERT (sec
!= NULL
);
5555 name
= bfd_get_section_name (abfd
, sec
->output_section
);
5556 if (! (strncmp (name
, ".sdata2", 7) == 0
5557 || strncmp (name
, ".sbss2", 6) == 0))
5559 (*_bfd_error_handler
)
5560 (_("%s: the target (%s) of a %s relocation is "
5561 "in the wrong output section (%s)"),
5562 bfd_archive_filename (input_bfd
),
5567 bfd_set_error (bfd_error_bad_value
);
5571 sh
= htab
->sdata2
->sym_hash
;
5572 addend
-= (sh
->root
.u
.def
.value
5573 + sh
->root
.u
.def
.section
->output_section
->vma
5574 + sh
->root
.u
.def
.section
->output_offset
);
5578 /* Relocate against either _SDA_BASE_, _SDA2_BASE_, or 0. */
5579 case R_PPC_EMB_SDA21
:
5580 case R_PPC_EMB_RELSDA
:
5583 const struct elf_link_hash_entry
*sh
;
5586 BFD_ASSERT (sec
!= NULL
);
5587 name
= bfd_get_section_name (abfd
, sec
->output_section
);
5588 if (((strncmp (name
, ".sdata", 6) == 0
5589 && (name
[6] == 0 || name
[6] == '.'))
5590 || (strncmp (name
, ".sbss", 5) == 0
5591 && (name
[5] == 0 || name
[5] == '.'))))
5594 sh
= htab
->sdata
->sym_hash
;
5595 addend
-= (sh
->root
.u
.def
.value
5596 + sh
->root
.u
.def
.section
->output_section
->vma
5597 + sh
->root
.u
.def
.section
->output_offset
);
5600 else if (strncmp (name
, ".sdata2", 7) == 0
5601 || strncmp (name
, ".sbss2", 6) == 0)
5604 sh
= htab
->sdata2
->sym_hash
;
5605 addend
-= (sh
->root
.u
.def
.value
5606 + sh
->root
.u
.def
.section
->output_section
->vma
5607 + sh
->root
.u
.def
.section
->output_offset
);
5610 else if (strcmp (name
, ".PPC.EMB.sdata0") == 0
5611 || strcmp (name
, ".PPC.EMB.sbss0") == 0)
5618 (*_bfd_error_handler
)
5619 (_("%s: the target (%s) of a %s relocation is "
5620 "in the wrong output section (%s)"),
5621 bfd_archive_filename (input_bfd
),
5626 bfd_set_error (bfd_error_bad_value
);
5631 if (r_type
== R_PPC_EMB_SDA21
)
5632 { /* fill in register field */
5633 insn
= bfd_get_32 (output_bfd
, contents
+ rel
->r_offset
);
5634 insn
= (insn
& ~RA_REGISTER_MASK
) | (reg
<< RA_REGISTER_SHIFT
);
5635 bfd_put_32 (output_bfd
, insn
, contents
+ rel
->r_offset
);
5640 /* Relocate against the beginning of the section. */
5642 case R_PPC_SECTOFF_LO
:
5643 case R_PPC_SECTOFF_HI
:
5644 case R_PPC_SECTOFF_HA
:
5645 BFD_ASSERT (sec
!= NULL
);
5646 addend
-= sec
->output_section
->vma
;
5649 /* Negative relocations. */
5650 case R_PPC_EMB_NADDR32
:
5651 case R_PPC_EMB_NADDR16
:
5652 case R_PPC_EMB_NADDR16_LO
:
5653 case R_PPC_EMB_NADDR16_HI
:
5654 case R_PPC_EMB_NADDR16_HA
:
5655 addend
-= 2 * relocation
;
5659 case R_PPC_GLOB_DAT
:
5660 case R_PPC_JMP_SLOT
:
5661 case R_PPC_RELATIVE
:
5663 case R_PPC_PLTREL32
:
5664 case R_PPC_PLT16_LO
:
5665 case R_PPC_PLT16_HI
:
5666 case R_PPC_PLT16_HA
:
5668 case R_PPC_EMB_RELSEC16
:
5669 case R_PPC_EMB_RELST_LO
:
5670 case R_PPC_EMB_RELST_HI
:
5671 case R_PPC_EMB_RELST_HA
:
5672 case R_PPC_EMB_BIT_FLD
:
5673 (*_bfd_error_handler
)
5674 (_("%s: relocation %s is not yet supported for symbol %s."),
5675 bfd_archive_filename (input_bfd
),
5679 bfd_set_error (bfd_error_invalid_operation
);
5684 /* Do any further special processing. */
5690 case R_PPC_ADDR16_HA
:
5691 case R_PPC_GOT16_HA
:
5692 case R_PPC_PLT16_HA
:
5693 case R_PPC_SECTOFF_HA
:
5694 case R_PPC_TPREL16_HA
:
5695 case R_PPC_DTPREL16_HA
:
5696 case R_PPC_GOT_TLSGD16_HA
:
5697 case R_PPC_GOT_TLSLD16_HA
:
5698 case R_PPC_GOT_TPREL16_HA
:
5699 case R_PPC_GOT_DTPREL16_HA
:
5700 case R_PPC_EMB_NADDR16_HA
:
5701 case R_PPC_EMB_RELST_HA
:
5702 /* It's just possible that this symbol is a weak symbol
5703 that's not actually defined anywhere. In that case,
5704 'sec' would be NULL, and we should leave the symbol
5705 alone (it will be set to zero elsewhere in the link). */
5707 /* Add 0x10000 if sign bit in 0:15 is set.
5708 Bits 0:15 are not used. */
5714 fprintf (stderr
, "\ttype = %s (%d), name = %s, symbol index = %ld, "
5715 "offset = %ld, addend = %ld\n",
5720 (long) rel
->r_offset
,
5724 if (unresolved_reloc
5725 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
5726 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0))
5728 (*_bfd_error_handler
)
5729 (_("%s(%s+0x%lx): unresolvable %s relocation against symbol `%s'"),
5730 bfd_archive_filename (input_bfd
),
5731 bfd_get_section_name (input_bfd
, input_section
),
5732 (long) rel
->r_offset
,
5738 r
= _bfd_final_link_relocate (howto
,
5746 if (r
!= bfd_reloc_ok
)
5748 if (sym_name
== NULL
)
5749 sym_name
= "(null)";
5750 if (r
== bfd_reloc_overflow
)
5755 && h
->root
.type
== bfd_link_hash_undefweak
5756 && howto
->pc_relative
)
5758 /* Assume this is a call protected by other code that
5759 detect the symbol is undefined. If this is the case,
5760 we can safely ignore the overflow. If not, the
5761 program is hosed anyway, and a little warning isn't
5767 if (! (*info
->callbacks
->reloc_overflow
) (info
,
5778 (*_bfd_error_handler
)
5779 (_("%s(%s+0x%lx): %s reloc against `%s': error %d"),
5780 bfd_archive_filename (input_bfd
),
5781 bfd_get_section_name (input_bfd
, input_section
),
5782 (long) rel
->r_offset
, howto
->name
, sym_name
, (int) r
);
5789 fprintf (stderr
, "\n");
5795 static enum elf_reloc_type_class
5796 ppc_elf_reloc_type_class (const Elf_Internal_Rela
*rela
)
5798 switch (ELF32_R_TYPE (rela
->r_info
))
5800 case R_PPC_RELATIVE
:
5801 return reloc_class_relative
;
5804 case R_PPC_JMP_SLOT
:
5805 return reloc_class_plt
;
5807 return reloc_class_copy
;
5809 return reloc_class_normal
;
5813 /* Support for core dump NOTE sections. */
5816 ppc_elf_grok_prstatus (bfd
*abfd
, Elf_Internal_Note
*note
)
5819 unsigned int raw_size
;
5821 switch (note
->descsz
)
5826 case 268: /* Linux/PPC. */
5828 elf_tdata (abfd
)->core_signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
5831 elf_tdata (abfd
)->core_pid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
5840 /* Make a ".reg/999" section. */
5841 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
5842 raw_size
, note
->descpos
+ offset
);
5846 ppc_elf_grok_psinfo (bfd
*abfd
, Elf_Internal_Note
*note
)
5848 switch (note
->descsz
)
5853 case 128: /* Linux/PPC elf_prpsinfo. */
5854 elf_tdata (abfd
)->core_program
5855 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 32, 16);
5856 elf_tdata (abfd
)->core_command
5857 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 48, 80);
5860 /* Note that for some reason, a spurious space is tacked
5861 onto the end of the args in some (at least one anyway)
5862 implementations, so strip it off if it exists. */
5865 char *command
= elf_tdata (abfd
)->core_command
;
5866 int n
= strlen (command
);
5868 if (0 < n
&& command
[n
- 1] == ' ')
5869 command
[n
- 1] = '\0';
5875 /* Very simple linked list structure for recording apuinfo values. */
5876 typedef struct apuinfo_list
5878 struct apuinfo_list
*next
;
5879 unsigned long value
;
5883 static apuinfo_list
*head
;
5887 apuinfo_list_init (void)
5893 apuinfo_list_add (unsigned long value
)
5895 apuinfo_list
*entry
= head
;
5897 while (entry
!= NULL
)
5899 if (entry
->value
== value
)
5901 entry
= entry
->next
;
5904 entry
= bfd_malloc (sizeof (* entry
));
5908 entry
->value
= value
;
5914 apuinfo_list_length (void)
5916 apuinfo_list
*entry
;
5917 unsigned long count
;
5919 for (entry
= head
, count
= 0;
5921 entry
= entry
->next
)
5927 static inline unsigned long
5928 apuinfo_list_element (unsigned long number
)
5930 apuinfo_list
* entry
;
5934 entry
= entry
->next
)
5937 return entry
? entry
->value
: 0;
5941 apuinfo_list_finish (void)
5943 apuinfo_list
*entry
;
5945 for (entry
= head
; entry
;)
5947 apuinfo_list
*next
= entry
->next
;
5955 #define APUINFO_SECTION_NAME ".PPC.EMB.apuinfo"
5956 #define APUINFO_LABEL "APUinfo"
5958 /* Scan the input BFDs and create a linked list of
5959 the APUinfo values that will need to be emitted. */
5962 ppc_elf_begin_write_processing (bfd
*abfd
, struct bfd_link_info
*link_info
)
5967 unsigned num_input_sections
;
5968 bfd_size_type output_section_size
;
5970 unsigned num_entries
;
5971 unsigned long offset
;
5972 unsigned long length
;
5973 const char *error_message
= NULL
;
5975 if (link_info
== NULL
)
5978 /* Scan the input bfds, looking for apuinfo sections. */
5979 num_input_sections
= 0;
5980 output_section_size
= 0;
5982 for (ibfd
= link_info
->input_bfds
; ibfd
; ibfd
= ibfd
->link_next
)
5984 asec
= bfd_get_section_by_name (ibfd
, APUINFO_SECTION_NAME
);
5987 ++ num_input_sections
;
5988 output_section_size
+= asec
->_raw_size
;
5992 /* We need at least one input sections
5993 in order to make merging worthwhile. */
5994 if (num_input_sections
< 1)
5997 /* Just make sure that the output section exists as well. */
5998 asec
= bfd_get_section_by_name (abfd
, APUINFO_SECTION_NAME
);
6002 /* Allocate a buffer for the contents of the input sections. */
6003 buffer
= bfd_malloc (output_section_size
);
6008 apuinfo_list_init ();
6010 /* Read in the input sections contents. */
6011 for (ibfd
= link_info
->input_bfds
; ibfd
; ibfd
= ibfd
->link_next
)
6013 unsigned long datum
;
6016 asec
= bfd_get_section_by_name (ibfd
, APUINFO_SECTION_NAME
);
6020 length
= asec
->_raw_size
;
6023 error_message
= _("corrupt or empty %s section in %s");
6027 if (bfd_seek (ibfd
, asec
->filepos
, SEEK_SET
) != 0
6028 || (bfd_bread (buffer
+ offset
, length
, ibfd
) != length
))
6030 error_message
= _("unable to read in %s section from %s");
6034 /* Process the contents of the section. */
6035 ptr
= buffer
+ offset
;
6036 error_message
= _("corrupt %s section in %s");
6038 /* Verify the contents of the header. Note - we have to
6039 extract the values this way in order to allow for a
6040 host whose endian-ness is different from the target. */
6041 datum
= bfd_get_32 (ibfd
, ptr
);
6042 if (datum
!= sizeof APUINFO_LABEL
)
6045 datum
= bfd_get_32 (ibfd
, ptr
+ 8);
6049 if (strcmp (ptr
+ 12, APUINFO_LABEL
) != 0)
6052 /* Get the number of bytes used for apuinfo entries. */
6053 datum
= bfd_get_32 (ibfd
, ptr
+ 4);
6054 if (datum
+ 20 != length
)
6057 /* Make sure that we do not run off the end of the section. */
6058 if (offset
+ length
> output_section_size
)
6061 /* Scan the apuinfo section, building a list of apuinfo numbers. */
6062 for (i
= 0; i
< datum
; i
+= 4)
6063 apuinfo_list_add (bfd_get_32 (ibfd
, ptr
+ 20 + i
));
6065 /* Update the offset. */
6069 error_message
= NULL
;
6071 /* Compute the size of the output section. */
6072 num_entries
= apuinfo_list_length ();
6073 output_section_size
= 20 + num_entries
* 4;
6075 asec
= bfd_get_section_by_name (abfd
, APUINFO_SECTION_NAME
);
6077 if (! bfd_set_section_size (abfd
, asec
, output_section_size
))
6079 error_message
= _("warning: unable to set size of %s section in %s");
6085 (*_bfd_error_handler
) (error_message
, APUINFO_SECTION_NAME
,
6086 bfd_archive_filename (ibfd
));
6090 /* Prevent the output section from accumulating the input sections'
6091 contents. We have already stored this in our linked list structure. */
6094 ppc_elf_write_section (bfd
*abfd ATTRIBUTE_UNUSED
,
6096 bfd_byte
*contents ATTRIBUTE_UNUSED
)
6098 return (apuinfo_list_length ()
6099 && strcmp (asec
->name
, APUINFO_SECTION_NAME
) == 0);
6103 /* Finally we can generate the output section. */
6106 ppc_elf_final_write_processing (bfd
*abfd
, bfd_boolean linker ATTRIBUTE_UNUSED
)
6111 unsigned num_entries
;
6112 bfd_size_type length
;
6114 asec
= bfd_get_section_by_name (abfd
, APUINFO_SECTION_NAME
);
6118 if (apuinfo_list_length () == 0)
6121 length
= asec
->_raw_size
;
6125 buffer
= bfd_malloc (length
);
6128 (*_bfd_error_handler
)
6129 (_("failed to allocate space for new APUinfo section."));
6133 /* Create the apuinfo header. */
6134 num_entries
= apuinfo_list_length ();
6135 bfd_put_32 (abfd
, sizeof APUINFO_LABEL
, buffer
);
6136 bfd_put_32 (abfd
, num_entries
* 4, buffer
+ 4);
6137 bfd_put_32 (abfd
, 0x2, buffer
+ 8);
6138 strcpy (buffer
+ 12, APUINFO_LABEL
);
6141 for (i
= 0; i
< num_entries
; i
++)
6143 bfd_put_32 (abfd
, apuinfo_list_element (i
), buffer
+ length
);
6147 if (length
!= asec
->_raw_size
)
6148 (*_bfd_error_handler
) (_("failed to compute new APUinfo section."));
6150 if (! bfd_set_section_contents (abfd
, asec
, buffer
, (file_ptr
) 0, length
))
6151 (*_bfd_error_handler
) (_("failed to install new APUinfo section."));
6155 apuinfo_list_finish ();
6158 /* Add extra PPC sections -- Note, for now, make .sbss2 and
6159 .PPC.EMB.sbss0 a normal section, and not a bss section so
6160 that the linker doesn't crater when trying to make more than
6163 static struct bfd_elf_special_section
const ppc_elf_special_sections
[]=
6165 { ".tags", 5, 0, SHT_ORDERED
, SHF_ALLOC
},
6166 { ".sdata", 6, -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
6167 { ".sbss", 5, -2, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
},
6168 { ".sdata2", 7, -2, SHT_PROGBITS
, SHF_ALLOC
},
6169 { ".sbss2", 6, -2, SHT_PROGBITS
, SHF_ALLOC
},
6170 { ".PPC.EMB.apuinfo", 16, 0, SHT_NOTE
, 0 },
6171 { ".PPC.EMB.sdata0", 15, 0, SHT_PROGBITS
, SHF_ALLOC
},
6172 { ".PPC.EMB.sbss0", 14, 0, SHT_PROGBITS
, SHF_ALLOC
},
6173 { ".plt", 4, 0, SHT_NOBITS
, SHF_ALLOC
+ SHF_EXECINSTR
},
6174 { NULL
, 0, 0, 0, 0 }
6177 #define TARGET_LITTLE_SYM bfd_elf32_powerpcle_vec
6178 #define TARGET_LITTLE_NAME "elf32-powerpcle"
6179 #define TARGET_BIG_SYM bfd_elf32_powerpc_vec
6180 #define TARGET_BIG_NAME "elf32-powerpc"
6181 #define ELF_ARCH bfd_arch_powerpc
6182 #define ELF_MACHINE_CODE EM_PPC
6183 #ifdef __QNXTARGET__
6184 #define ELF_MAXPAGESIZE 0x1000
6186 #define ELF_MAXPAGESIZE 0x10000
6188 #define elf_info_to_howto ppc_elf_info_to_howto
6190 #ifdef EM_CYGNUS_POWERPC
6191 #define ELF_MACHINE_ALT1 EM_CYGNUS_POWERPC
6195 #define ELF_MACHINE_ALT2 EM_PPC_OLD
6198 #define elf_backend_plt_not_loaded 1
6199 #define elf_backend_got_symbol_offset 4
6200 #define elf_backend_can_gc_sections 1
6201 #define elf_backend_can_refcount 1
6202 #define elf_backend_got_header_size 12
6203 #define elf_backend_rela_normal 1
6205 #define bfd_elf32_mkobject ppc_elf_mkobject
6206 #define bfd_elf32_bfd_merge_private_bfd_data ppc_elf_merge_private_bfd_data
6207 #define bfd_elf32_bfd_relax_section ppc_elf_relax_section
6208 #define bfd_elf32_bfd_reloc_type_lookup ppc_elf_reloc_type_lookup
6209 #define bfd_elf32_bfd_set_private_flags ppc_elf_set_private_flags
6210 #define bfd_elf32_bfd_link_hash_table_create ppc_elf_link_hash_table_create
6212 #define elf_backend_object_p ppc_elf_object_p
6213 #define elf_backend_gc_mark_hook ppc_elf_gc_mark_hook
6214 #define elf_backend_gc_sweep_hook ppc_elf_gc_sweep_hook
6215 #define elf_backend_section_from_shdr ppc_elf_section_from_shdr
6216 #define elf_backend_relocate_section ppc_elf_relocate_section
6217 #define elf_backend_create_dynamic_sections ppc_elf_create_dynamic_sections
6218 #define elf_backend_check_relocs ppc_elf_check_relocs
6219 #define elf_backend_copy_indirect_symbol ppc_elf_copy_indirect_symbol
6220 #define elf_backend_adjust_dynamic_symbol ppc_elf_adjust_dynamic_symbol
6221 #define elf_backend_add_symbol_hook ppc_elf_add_symbol_hook
6222 #define elf_backend_size_dynamic_sections ppc_elf_size_dynamic_sections
6223 #define elf_backend_finish_dynamic_symbol ppc_elf_finish_dynamic_symbol
6224 #define elf_backend_finish_dynamic_sections ppc_elf_finish_dynamic_sections
6225 #define elf_backend_fake_sections ppc_elf_fake_sections
6226 #define elf_backend_additional_program_headers ppc_elf_additional_program_headers
6227 #define elf_backend_modify_segment_map ppc_elf_modify_segment_map
6228 #define elf_backend_grok_prstatus ppc_elf_grok_prstatus
6229 #define elf_backend_grok_psinfo ppc_elf_grok_psinfo
6230 #define elf_backend_reloc_type_class ppc_elf_reloc_type_class
6231 #define elf_backend_begin_write_processing ppc_elf_begin_write_processing
6232 #define elf_backend_final_write_processing ppc_elf_final_write_processing
6233 #define elf_backend_write_section ppc_elf_write_section
6234 #define elf_backend_special_sections ppc_elf_special_sections
6236 #include "elf32-target.h"