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 #define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
1630 static const int shared_stub_entry
[] =
1632 0x7c0802a6, /* mflr 0 */
1633 0x429f0005, /* bcl 20, 31, .Lxxx */
1634 0x7d6802a6, /* mflr 11 */
1635 0x3d6b0000, /* addis 11, 11, (xxx-.Lxxx)@ha */
1636 0x396b0018, /* addi 11, 11, (xxx-.Lxxx)@l */
1637 0x7c0803a6, /* mtlr 0 */
1638 0x7d6903a6, /* mtctr 11 */
1639 0x4e800420, /* bctr */
1642 static const int stub_entry
[] =
1644 0x3d600000, /* lis 11,xxx@ha */
1645 0x396b0000, /* addi 11,11,xxx@l */
1646 0x7d6903a6, /* mtctr 11 */
1647 0x4e800420, /* bctr */
1652 ppc_elf_relax_section (bfd
*abfd
,
1654 struct bfd_link_info
*link_info
,
1659 struct one_fixup
*next
;
1665 Elf_Internal_Shdr
*symtab_hdr
;
1666 bfd_byte
*contents
= NULL
;
1667 Elf_Internal_Sym
*isymbuf
= NULL
;
1668 Elf_Internal_Rela
*internal_relocs
= NULL
;
1669 Elf_Internal_Rela
*irel
, *irelend
;
1670 struct one_fixup
*fixups
= NULL
;
1671 bfd_boolean changed
;
1672 struct ppc_elf_link_hash_table
*ppc_info
;
1673 bfd_size_type trampoff
;
1677 /* Nothing to do if there are no relocations and no need for
1678 the relax finalize pass. */
1679 if ((isec
->flags
& SEC_RELOC
) == 0
1680 || isec
->reloc_count
== 0
1681 || link_info
->relax_finalizing
)
1684 /* If needed, initialize this section's cooked size. */
1685 if (isec
->_cooked_size
== 0)
1686 isec
->_cooked_size
= isec
->_raw_size
;
1688 trampoff
= (isec
->_cooked_size
+ 3) & (bfd_vma
) -4;
1689 /* Space for a branch around any trampolines. */
1692 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
1694 /* Get a copy of the native relocations. */
1695 internal_relocs
= _bfd_elf_link_read_relocs (abfd
, isec
, NULL
, NULL
,
1696 link_info
->keep_memory
);
1697 if (internal_relocs
== NULL
)
1700 ppc_info
= ppc_elf_hash_table (link_info
);
1701 irelend
= internal_relocs
+ isec
->reloc_count
;
1703 /* Get the section contents. */
1704 /* Get cached copy if it exists. */
1705 if (elf_section_data (isec
)->this_hdr
.contents
!= NULL
)
1706 contents
= elf_section_data (isec
)->this_hdr
.contents
;
1709 /* Go get them off disk. */
1710 contents
= bfd_malloc (isec
->_raw_size
);
1711 if (contents
== NULL
)
1714 if (!bfd_get_section_contents (abfd
, isec
, contents
, 0, isec
->_raw_size
))
1718 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
1720 unsigned long r_type
= ELF32_R_TYPE (irel
->r_info
);
1721 bfd_vma symaddr
, reladdr
, toff
, roff
;
1723 struct one_fixup
*f
;
1724 size_t insn_offset
= 0;
1725 bfd_vma max_branch_offset
, val
;
1732 case R_PPC_LOCAL24PC
:
1733 case R_PPC_PLTREL24
:
1734 max_branch_offset
= 1 << 25;
1738 case R_PPC_REL14_BRTAKEN
:
1739 case R_PPC_REL14_BRNTAKEN
:
1740 max_branch_offset
= 1 << 15;
1747 /* Get the value of the symbol referred to by the reloc. */
1748 if (ELF32_R_SYM (irel
->r_info
) < symtab_hdr
->sh_info
)
1750 /* A local symbol. */
1751 Elf_Internal_Sym
*isym
;
1753 /* Read this BFD's local symbols. */
1754 if (isymbuf
== NULL
)
1756 isymbuf
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
1757 if (isymbuf
== NULL
)
1758 isymbuf
= bfd_elf_get_elf_syms (abfd
, symtab_hdr
,
1759 symtab_hdr
->sh_info
, 0,
1764 isym
= isymbuf
+ ELF32_R_SYM (irel
->r_info
);
1765 if (isym
->st_shndx
== SHN_UNDEF
)
1766 continue; /* We can't do anthing with undefined symbols. */
1767 else if (isym
->st_shndx
== SHN_ABS
)
1768 tsec
= bfd_abs_section_ptr
;
1769 else if (isym
->st_shndx
== SHN_COMMON
)
1770 tsec
= bfd_com_section_ptr
;
1772 tsec
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
1774 toff
= isym
->st_value
;
1778 /* Global symbol handling. */
1780 struct elf_link_hash_entry
*h
;
1782 indx
= ELF32_R_SYM (irel
->r_info
) - symtab_hdr
->sh_info
;
1783 h
= elf_sym_hashes (abfd
)[indx
];
1785 while (h
->root
.type
== bfd_link_hash_indirect
1786 || h
->root
.type
== bfd_link_hash_warning
)
1787 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1789 if (r_type
== R_PPC_PLTREL24
1790 && ppc_info
->plt
!= NULL
1791 && h
->plt
.offset
!= (bfd_vma
) -1)
1793 tsec
= ppc_info
->plt
;
1794 toff
= h
->plt
.offset
;
1796 else if (h
->root
.type
== bfd_link_hash_defined
1797 || h
->root
.type
== bfd_link_hash_defweak
)
1799 tsec
= h
->root
.u
.def
.section
;
1800 toff
= h
->root
.u
.def
.value
;
1806 /* If the branch and target are in the same section, you have
1807 no hope of adding stubs. We'll error out later should the
1812 toff
+= irel
->r_addend
;
1813 if (tsec
->sec_info_type
== ELF_INFO_TYPE_MERGE
)
1814 toff
= _bfd_merged_section_offset (abfd
, &tsec
,
1815 elf_section_data (tsec
)->sec_info
,
1818 symaddr
= tsec
->output_section
->vma
+ tsec
->output_offset
+ toff
;
1820 roff
= irel
->r_offset
;
1822 reladdr
= (isec
->output_section
->vma
1823 + isec
->output_offset
1826 /* If the branch is in range, no need to do anything. */
1827 if (symaddr
- reladdr
+ max_branch_offset
< 2 * max_branch_offset
)
1830 /* Look for an existing fixup to this address. */
1831 for (f
= fixups
; f
; f
= f
->next
)
1832 if (f
->tsec
== tsec
&& f
->toff
== toff
)
1838 unsigned long stub_rtype
;
1840 val
= trampoff
- roff
;
1841 if (val
>= max_branch_offset
)
1842 /* Oh dear, we can't reach a trampoline. Don't try to add
1843 one. We'll report an error later. */
1846 if (link_info
->shared
)
1848 size
= 4 * ARRAY_SIZE (shared_stub_entry
);
1850 stub_rtype
= R_PPC_RELAX32PC
;
1854 size
= 4 * ARRAY_SIZE (stub_entry
);
1856 stub_rtype
= R_PPC_RELAX32
;
1859 /* Hijack the old relocation. Since we need two
1860 relocations for this use a "composite" reloc. */
1861 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
),
1863 irel
->r_offset
= trampoff
+ insn_offset
;
1865 /* Record the fixup so we don't do it again this section. */
1866 f
= bfd_malloc (sizeof (*f
));
1870 f
->trampoff
= trampoff
;
1877 val
= f
->trampoff
- roff
;
1878 if (val
>= max_branch_offset
)
1881 /* Nop out the reloc, since we're finalizing things here. */
1882 irel
->r_info
= ELF32_R_INFO (0, R_PPC_NONE
);
1885 /* Fix up the existing branch to hit the trampoline. */
1886 hit_addr
= contents
+ roff
;
1890 case R_PPC_LOCAL24PC
:
1891 case R_PPC_PLTREL24
:
1892 t0
= bfd_get_32 (abfd
, hit_addr
);
1894 t0
|= val
& 0x3fffffc;
1895 bfd_put_32 (abfd
, t0
, hit_addr
);
1899 case R_PPC_REL14_BRTAKEN
:
1900 case R_PPC_REL14_BRNTAKEN
:
1901 t0
= bfd_get_32 (abfd
, hit_addr
);
1904 bfd_put_32 (abfd
, t0
, hit_addr
);
1909 /* Write out the trampolines. */
1910 changed
= fixups
!= NULL
;
1920 struct one_fixup
*f
= fixups
;
1921 fixups
= fixups
->next
;
1926 contents
= bfd_realloc (contents
, trampoff
);
1927 if (contents
== NULL
)
1930 isec
->_cooked_size
= (isec
->_cooked_size
+ 3) & (bfd_vma
) -4;
1931 /* Branch around the trampolines. */
1932 val
= trampoff
- isec
->_cooked_size
+ 0x48000000;
1933 dest
= contents
+ isec
->_cooked_size
;
1934 isec
->_cooked_size
= trampoff
;
1935 bfd_put_32 (abfd
, val
, dest
);
1938 if (link_info
->shared
)
1940 stub
= shared_stub_entry
;
1941 size
= ARRAY_SIZE (shared_stub_entry
);
1946 size
= ARRAY_SIZE (stub_entry
);
1950 while (dest
< contents
+ trampoff
)
1952 bfd_put_32 (abfd
, stub
[i
], dest
);
1958 BFD_ASSERT (i
== 0);
1962 && symtab_hdr
->contents
!= (unsigned char *) isymbuf
)
1964 if (! link_info
->keep_memory
)
1968 /* Cache the symbols for elf_link_input_bfd. */
1969 symtab_hdr
->contents
= (unsigned char *) isymbuf
;
1973 if (contents
!= NULL
1974 && elf_section_data (isec
)->this_hdr
.contents
!= contents
)
1976 if (!changed
&& !link_info
->keep_memory
)
1980 /* Cache the section contents for elf_link_input_bfd. */
1981 elf_section_data (isec
)->this_hdr
.contents
= contents
;
1985 if (elf_section_data (isec
)->relocs
!= internal_relocs
)
1988 free (internal_relocs
);
1990 elf_section_data (isec
)->relocs
= internal_relocs
;
1997 if (isymbuf
!= NULL
&& (unsigned char *) isymbuf
!= symtab_hdr
->contents
)
1999 if (contents
!= NULL
2000 && elf_section_data (isec
)->this_hdr
.contents
!= contents
)
2002 if (internal_relocs
!= NULL
2003 && elf_section_data (isec
)->relocs
!= internal_relocs
)
2004 free (internal_relocs
);
2008 static reloc_howto_type
*
2009 ppc_elf_reloc_type_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
2010 bfd_reloc_code_real_type code
)
2012 enum elf_ppc_reloc_type r
;
2014 /* Initialize howto table if not already done. */
2015 if (!ppc_elf_howto_table
[R_PPC_ADDR32
])
2016 ppc_elf_howto_init ();
2023 case BFD_RELOC_NONE
: r
= R_PPC_NONE
; break;
2024 case BFD_RELOC_32
: r
= R_PPC_ADDR32
; break;
2025 case BFD_RELOC_PPC_BA26
: r
= R_PPC_ADDR24
; break;
2026 case BFD_RELOC_16
: r
= R_PPC_ADDR16
; break;
2027 case BFD_RELOC_LO16
: r
= R_PPC_ADDR16_LO
; break;
2028 case BFD_RELOC_HI16
: r
= R_PPC_ADDR16_HI
; break;
2029 case BFD_RELOC_HI16_S
: r
= R_PPC_ADDR16_HA
; break;
2030 case BFD_RELOC_PPC_BA16
: r
= R_PPC_ADDR14
; break;
2031 case BFD_RELOC_PPC_BA16_BRTAKEN
: r
= R_PPC_ADDR14_BRTAKEN
; break;
2032 case BFD_RELOC_PPC_BA16_BRNTAKEN
: r
= R_PPC_ADDR14_BRNTAKEN
; break;
2033 case BFD_RELOC_PPC_B26
: r
= R_PPC_REL24
; break;
2034 case BFD_RELOC_PPC_B16
: r
= R_PPC_REL14
; break;
2035 case BFD_RELOC_PPC_B16_BRTAKEN
: r
= R_PPC_REL14_BRTAKEN
; break;
2036 case BFD_RELOC_PPC_B16_BRNTAKEN
: r
= R_PPC_REL14_BRNTAKEN
; break;
2037 case BFD_RELOC_16_GOTOFF
: r
= R_PPC_GOT16
; break;
2038 case BFD_RELOC_LO16_GOTOFF
: r
= R_PPC_GOT16_LO
; break;
2039 case BFD_RELOC_HI16_GOTOFF
: r
= R_PPC_GOT16_HI
; break;
2040 case BFD_RELOC_HI16_S_GOTOFF
: r
= R_PPC_GOT16_HA
; break;
2041 case BFD_RELOC_24_PLT_PCREL
: r
= R_PPC_PLTREL24
; break;
2042 case BFD_RELOC_PPC_COPY
: r
= R_PPC_COPY
; break;
2043 case BFD_RELOC_PPC_GLOB_DAT
: r
= R_PPC_GLOB_DAT
; break;
2044 case BFD_RELOC_PPC_LOCAL24PC
: r
= R_PPC_LOCAL24PC
; break;
2045 case BFD_RELOC_32_PCREL
: r
= R_PPC_REL32
; break;
2046 case BFD_RELOC_32_PLTOFF
: r
= R_PPC_PLT32
; break;
2047 case BFD_RELOC_32_PLT_PCREL
: r
= R_PPC_PLTREL32
; break;
2048 case BFD_RELOC_LO16_PLTOFF
: r
= R_PPC_PLT16_LO
; break;
2049 case BFD_RELOC_HI16_PLTOFF
: r
= R_PPC_PLT16_HI
; break;
2050 case BFD_RELOC_HI16_S_PLTOFF
: r
= R_PPC_PLT16_HA
; break;
2051 case BFD_RELOC_GPREL16
: r
= R_PPC_SDAREL16
; break;
2052 case BFD_RELOC_16_BASEREL
: r
= R_PPC_SECTOFF
; break;
2053 case BFD_RELOC_LO16_BASEREL
: r
= R_PPC_SECTOFF_LO
; break;
2054 case BFD_RELOC_HI16_BASEREL
: r
= R_PPC_SECTOFF_HI
; break;
2055 case BFD_RELOC_HI16_S_BASEREL
: r
= R_PPC_SECTOFF_HA
; break;
2056 case BFD_RELOC_CTOR
: r
= R_PPC_ADDR32
; break;
2057 case BFD_RELOC_PPC_TOC16
: r
= R_PPC_TOC16
; break;
2058 case BFD_RELOC_PPC_TLS
: r
= R_PPC_TLS
; break;
2059 case BFD_RELOC_PPC_DTPMOD
: r
= R_PPC_DTPMOD32
; break;
2060 case BFD_RELOC_PPC_TPREL16
: r
= R_PPC_TPREL16
; break;
2061 case BFD_RELOC_PPC_TPREL16_LO
: r
= R_PPC_TPREL16_LO
; break;
2062 case BFD_RELOC_PPC_TPREL16_HI
: r
= R_PPC_TPREL16_HI
; break;
2063 case BFD_RELOC_PPC_TPREL16_HA
: r
= R_PPC_TPREL16_HA
; break;
2064 case BFD_RELOC_PPC_TPREL
: r
= R_PPC_TPREL32
; break;
2065 case BFD_RELOC_PPC_DTPREL16
: r
= R_PPC_DTPREL16
; break;
2066 case BFD_RELOC_PPC_DTPREL16_LO
: r
= R_PPC_DTPREL16_LO
; break;
2067 case BFD_RELOC_PPC_DTPREL16_HI
: r
= R_PPC_DTPREL16_HI
; break;
2068 case BFD_RELOC_PPC_DTPREL16_HA
: r
= R_PPC_DTPREL16_HA
; break;
2069 case BFD_RELOC_PPC_DTPREL
: r
= R_PPC_DTPREL32
; break;
2070 case BFD_RELOC_PPC_GOT_TLSGD16
: r
= R_PPC_GOT_TLSGD16
; break;
2071 case BFD_RELOC_PPC_GOT_TLSGD16_LO
: r
= R_PPC_GOT_TLSGD16_LO
; break;
2072 case BFD_RELOC_PPC_GOT_TLSGD16_HI
: r
= R_PPC_GOT_TLSGD16_HI
; break;
2073 case BFD_RELOC_PPC_GOT_TLSGD16_HA
: r
= R_PPC_GOT_TLSGD16_HA
; break;
2074 case BFD_RELOC_PPC_GOT_TLSLD16
: r
= R_PPC_GOT_TLSLD16
; break;
2075 case BFD_RELOC_PPC_GOT_TLSLD16_LO
: r
= R_PPC_GOT_TLSLD16_LO
; break;
2076 case BFD_RELOC_PPC_GOT_TLSLD16_HI
: r
= R_PPC_GOT_TLSLD16_HI
; break;
2077 case BFD_RELOC_PPC_GOT_TLSLD16_HA
: r
= R_PPC_GOT_TLSLD16_HA
; break;
2078 case BFD_RELOC_PPC_GOT_TPREL16
: r
= R_PPC_GOT_TPREL16
; break;
2079 case BFD_RELOC_PPC_GOT_TPREL16_LO
: r
= R_PPC_GOT_TPREL16_LO
; break;
2080 case BFD_RELOC_PPC_GOT_TPREL16_HI
: r
= R_PPC_GOT_TPREL16_HI
; break;
2081 case BFD_RELOC_PPC_GOT_TPREL16_HA
: r
= R_PPC_GOT_TPREL16_HA
; break;
2082 case BFD_RELOC_PPC_GOT_DTPREL16
: r
= R_PPC_GOT_DTPREL16
; break;
2083 case BFD_RELOC_PPC_GOT_DTPREL16_LO
: r
= R_PPC_GOT_DTPREL16_LO
; break;
2084 case BFD_RELOC_PPC_GOT_DTPREL16_HI
: r
= R_PPC_GOT_DTPREL16_HI
; break;
2085 case BFD_RELOC_PPC_GOT_DTPREL16_HA
: r
= R_PPC_GOT_DTPREL16_HA
; break;
2086 case BFD_RELOC_PPC_EMB_NADDR32
: r
= R_PPC_EMB_NADDR32
; break;
2087 case BFD_RELOC_PPC_EMB_NADDR16
: r
= R_PPC_EMB_NADDR16
; break;
2088 case BFD_RELOC_PPC_EMB_NADDR16_LO
: r
= R_PPC_EMB_NADDR16_LO
; break;
2089 case BFD_RELOC_PPC_EMB_NADDR16_HI
: r
= R_PPC_EMB_NADDR16_HI
; break;
2090 case BFD_RELOC_PPC_EMB_NADDR16_HA
: r
= R_PPC_EMB_NADDR16_HA
; break;
2091 case BFD_RELOC_PPC_EMB_SDAI16
: r
= R_PPC_EMB_SDAI16
; break;
2092 case BFD_RELOC_PPC_EMB_SDA2I16
: r
= R_PPC_EMB_SDA2I16
; break;
2093 case BFD_RELOC_PPC_EMB_SDA2REL
: r
= R_PPC_EMB_SDA2REL
; break;
2094 case BFD_RELOC_PPC_EMB_SDA21
: r
= R_PPC_EMB_SDA21
; break;
2095 case BFD_RELOC_PPC_EMB_MRKREF
: r
= R_PPC_EMB_MRKREF
; break;
2096 case BFD_RELOC_PPC_EMB_RELSEC16
: r
= R_PPC_EMB_RELSEC16
; break;
2097 case BFD_RELOC_PPC_EMB_RELST_LO
: r
= R_PPC_EMB_RELST_LO
; break;
2098 case BFD_RELOC_PPC_EMB_RELST_HI
: r
= R_PPC_EMB_RELST_HI
; break;
2099 case BFD_RELOC_PPC_EMB_RELST_HA
: r
= R_PPC_EMB_RELST_HA
; break;
2100 case BFD_RELOC_PPC_EMB_BIT_FLD
: r
= R_PPC_EMB_BIT_FLD
; break;
2101 case BFD_RELOC_PPC_EMB_RELSDA
: r
= R_PPC_EMB_RELSDA
; break;
2102 case BFD_RELOC_VTABLE_INHERIT
: r
= R_PPC_GNU_VTINHERIT
; break;
2103 case BFD_RELOC_VTABLE_ENTRY
: r
= R_PPC_GNU_VTENTRY
; break;
2106 return ppc_elf_howto_table
[r
];
2109 /* Set the howto pointer for a PowerPC ELF reloc. */
2112 ppc_elf_info_to_howto (bfd
*abfd ATTRIBUTE_UNUSED
,
2114 Elf_Internal_Rela
*dst
)
2116 /* Initialize howto table if not already done. */
2117 if (!ppc_elf_howto_table
[R_PPC_ADDR32
])
2118 ppc_elf_howto_init ();
2120 BFD_ASSERT (ELF32_R_TYPE (dst
->r_info
) < (unsigned int) R_PPC_max
);
2121 cache_ptr
->howto
= ppc_elf_howto_table
[ELF32_R_TYPE (dst
->r_info
)];
2124 /* Handle the R_PPC_ADDR16_HA reloc. */
2126 static bfd_reloc_status_type
2127 ppc_elf_addr16_ha_reloc (bfd
*abfd ATTRIBUTE_UNUSED
,
2128 arelent
*reloc_entry
,
2130 void *data ATTRIBUTE_UNUSED
,
2131 asection
*input_section
,
2133 char **error_message ATTRIBUTE_UNUSED
)
2137 if (output_bfd
!= NULL
)
2139 reloc_entry
->address
+= input_section
->output_offset
;
2140 return bfd_reloc_ok
;
2143 if (reloc_entry
->address
> input_section
->_cooked_size
)
2144 return bfd_reloc_outofrange
;
2146 if (bfd_is_com_section (symbol
->section
))
2149 relocation
= symbol
->value
;
2151 relocation
+= symbol
->section
->output_section
->vma
;
2152 relocation
+= symbol
->section
->output_offset
;
2153 relocation
+= reloc_entry
->addend
;
2155 reloc_entry
->addend
+= (relocation
& 0x8000) << 1;
2157 return bfd_reloc_continue
;
2160 static bfd_reloc_status_type
2161 ppc_elf_unhandled_reloc (bfd
*abfd
,
2162 arelent
*reloc_entry
,
2165 asection
*input_section
,
2167 char **error_message
)
2169 /* If this is a relocatable link (output_bfd test tells us), just
2170 call the generic function. Any adjustment will be done at final
2172 if (output_bfd
!= NULL
)
2173 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2174 input_section
, output_bfd
, error_message
);
2176 if (error_message
!= NULL
)
2178 static char buf
[60];
2179 sprintf (buf
, _("generic linker can't handle %s"),
2180 reloc_entry
->howto
->name
);
2181 *error_message
= buf
;
2183 return bfd_reloc_dangerous
;
2186 /* Fix bad default arch selected for a 32 bit input bfd when the
2187 default is 64 bit. */
2190 ppc_elf_object_p (bfd
*abfd
)
2192 if (abfd
->arch_info
->the_default
&& abfd
->arch_info
->bits_per_word
== 64)
2194 Elf_Internal_Ehdr
*i_ehdr
= elf_elfheader (abfd
);
2196 if (i_ehdr
->e_ident
[EI_CLASS
] == ELFCLASS32
)
2198 /* Relies on arch after 64 bit default being 32 bit default. */
2199 abfd
->arch_info
= abfd
->arch_info
->next
;
2200 BFD_ASSERT (abfd
->arch_info
->bits_per_word
== 32);
2206 /* Function to set whether a module needs the -mrelocatable bit set. */
2209 ppc_elf_set_private_flags (bfd
*abfd
, flagword flags
)
2211 BFD_ASSERT (!elf_flags_init (abfd
)
2212 || elf_elfheader (abfd
)->e_flags
== flags
);
2214 elf_elfheader (abfd
)->e_flags
= flags
;
2215 elf_flags_init (abfd
) = TRUE
;
2219 /* Merge backend specific data from an object file to the output
2220 object file when linking. */
2223 ppc_elf_merge_private_bfd_data (bfd
*ibfd
, bfd
*obfd
)
2229 /* Check if we have the same endianess. */
2230 if (! _bfd_generic_verify_endian_match (ibfd
, obfd
))
2233 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
2234 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
2237 new_flags
= elf_elfheader (ibfd
)->e_flags
;
2238 old_flags
= elf_elfheader (obfd
)->e_flags
;
2239 if (!elf_flags_init (obfd
))
2241 /* First call, no flags set. */
2242 elf_flags_init (obfd
) = TRUE
;
2243 elf_elfheader (obfd
)->e_flags
= new_flags
;
2246 /* Compatible flags are ok. */
2247 else if (new_flags
== old_flags
)
2250 /* Incompatible flags. */
2253 /* Warn about -mrelocatable mismatch. Allow -mrelocatable-lib
2254 to be linked with either. */
2256 if ((new_flags
& EF_PPC_RELOCATABLE
) != 0
2257 && (old_flags
& (EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
)) == 0)
2260 (*_bfd_error_handler
)
2261 (_("%s: compiled with -mrelocatable and linked with "
2262 "modules compiled normally"),
2263 bfd_archive_filename (ibfd
));
2265 else if ((new_flags
& (EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
)) == 0
2266 && (old_flags
& EF_PPC_RELOCATABLE
) != 0)
2269 (*_bfd_error_handler
)
2270 (_("%s: compiled normally and linked with "
2271 "modules compiled with -mrelocatable"),
2272 bfd_archive_filename (ibfd
));
2275 /* The output is -mrelocatable-lib iff both the input files are. */
2276 if (! (new_flags
& EF_PPC_RELOCATABLE_LIB
))
2277 elf_elfheader (obfd
)->e_flags
&= ~EF_PPC_RELOCATABLE_LIB
;
2279 /* The output is -mrelocatable iff it can't be -mrelocatable-lib,
2280 but each input file is either -mrelocatable or -mrelocatable-lib. */
2281 if (! (elf_elfheader (obfd
)->e_flags
& EF_PPC_RELOCATABLE_LIB
)
2282 && (new_flags
& (EF_PPC_RELOCATABLE_LIB
| EF_PPC_RELOCATABLE
))
2283 && (old_flags
& (EF_PPC_RELOCATABLE_LIB
| EF_PPC_RELOCATABLE
)))
2284 elf_elfheader (obfd
)->e_flags
|= EF_PPC_RELOCATABLE
;
2286 /* Do not warn about eabi vs. V.4 mismatch, just or in the bit if
2287 any module uses it. */
2288 elf_elfheader (obfd
)->e_flags
|= (new_flags
& EF_PPC_EMB
);
2290 new_flags
&= ~(EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
| EF_PPC_EMB
);
2291 old_flags
&= ~(EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
| EF_PPC_EMB
);
2293 /* Warn about any other mismatches. */
2294 if (new_flags
!= old_flags
)
2297 (*_bfd_error_handler
)
2298 (_("%s: uses different e_flags (0x%lx) fields "
2299 "than previous modules (0x%lx)"),
2300 bfd_archive_filename (ibfd
), (long) new_flags
, (long) old_flags
);
2305 bfd_set_error (bfd_error_bad_value
);
2313 /* Handle a PowerPC specific section when reading an object file. This
2314 is called when elfcode.h finds a section with an unknown type. */
2317 ppc_elf_section_from_shdr (bfd
*abfd
, Elf_Internal_Shdr
*hdr
, const char *name
)
2322 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
))
2325 newsect
= hdr
->bfd_section
;
2326 flags
= bfd_get_section_flags (abfd
, newsect
);
2327 if (hdr
->sh_flags
& SHF_EXCLUDE
)
2328 flags
|= SEC_EXCLUDE
;
2330 if (hdr
->sh_type
== SHT_ORDERED
)
2331 flags
|= SEC_SORT_ENTRIES
;
2333 bfd_set_section_flags (abfd
, newsect
, flags
);
2337 /* Set up any other section flags and such that may be necessary. */
2340 ppc_elf_fake_sections (bfd
*abfd ATTRIBUTE_UNUSED
,
2341 Elf_Internal_Shdr
*shdr
,
2344 if ((asect
->flags
& SEC_EXCLUDE
) != 0)
2345 shdr
->sh_flags
|= SHF_EXCLUDE
;
2347 if ((asect
->flags
& SEC_SORT_ENTRIES
) != 0)
2348 shdr
->sh_type
= SHT_ORDERED
;
2353 /* Find a linker generated pointer with a given addend and type. */
2355 static elf_linker_section_pointers_t
*
2356 elf_find_pointer_linker_section
2357 (elf_linker_section_pointers_t
*linker_pointers
,
2359 elf_linker_section_t
*lsect
)
2361 for ( ; linker_pointers
!= NULL
; linker_pointers
= linker_pointers
->next
)
2362 if (lsect
== linker_pointers
->lsect
&& addend
== linker_pointers
->addend
)
2363 return linker_pointers
;
2368 /* Allocate a pointer to live in a linker created section. */
2371 elf_create_pointer_linker_section (bfd
*abfd
,
2372 struct bfd_link_info
*info
,
2373 elf_linker_section_t
*lsect
,
2374 struct elf_link_hash_entry
*h
,
2375 const Elf_Internal_Rela
*rel
)
2377 elf_linker_section_pointers_t
**ptr_linker_section_ptr
= NULL
;
2378 elf_linker_section_pointers_t
*linker_section_ptr
;
2379 unsigned long r_symndx
= ELF32_R_SYM (rel
->r_info
);
2382 BFD_ASSERT (lsect
!= NULL
);
2384 /* Is this a global symbol? */
2387 struct ppc_elf_link_hash_entry
*eh
;
2389 /* Has this symbol already been allocated? If so, our work is done. */
2390 eh
= (struct ppc_elf_link_hash_entry
*) h
;
2391 if (elf_find_pointer_linker_section (eh
->linker_section_pointer
,
2396 ptr_linker_section_ptr
= &eh
->linker_section_pointer
;
2397 /* Make sure this symbol is output as a dynamic symbol. */
2398 if (h
->dynindx
== -1)
2400 if (! _bfd_elf_link_record_dynamic_symbol (info
, h
))
2404 if (lsect
->rel_section
)
2405 lsect
->rel_section
->_raw_size
+= sizeof (Elf32_External_Rela
);
2409 /* Allocation of a pointer to a local symbol. */
2410 elf_linker_section_pointers_t
**ptr
= elf_local_ptr_offsets (abfd
);
2412 /* Allocate a table to hold the local symbols if first time. */
2415 unsigned int num_symbols
= elf_tdata (abfd
)->symtab_hdr
.sh_info
;
2418 amt
*= sizeof (elf_linker_section_pointers_t
*);
2419 ptr
= bfd_zalloc (abfd
, amt
);
2424 elf_local_ptr_offsets (abfd
) = ptr
;
2427 /* Has this symbol already been allocated? If so, our work is done. */
2428 if (elf_find_pointer_linker_section (ptr
[r_symndx
],
2433 ptr_linker_section_ptr
= &ptr
[r_symndx
];
2437 /* If we are generating a shared object, we need to
2438 output a R_<xxx>_RELATIVE reloc so that the
2439 dynamic linker can adjust this GOT entry. */
2440 BFD_ASSERT (lsect
->rel_section
!= NULL
);
2441 lsect
->rel_section
->_raw_size
+= sizeof (Elf32_External_Rela
);
2445 /* Allocate space for a pointer in the linker section, and allocate
2446 a new pointer record from internal memory. */
2447 BFD_ASSERT (ptr_linker_section_ptr
!= NULL
);
2448 amt
= sizeof (elf_linker_section_pointers_t
);
2449 linker_section_ptr
= bfd_alloc (abfd
, amt
);
2451 if (!linker_section_ptr
)
2454 linker_section_ptr
->next
= *ptr_linker_section_ptr
;
2455 linker_section_ptr
->addend
= rel
->r_addend
;
2456 linker_section_ptr
->lsect
= lsect
;
2457 linker_section_ptr
->written_address_p
= FALSE
;
2458 *ptr_linker_section_ptr
= linker_section_ptr
;
2460 linker_section_ptr
->offset
= lsect
->section
->_raw_size
;
2461 lsect
->section
->_raw_size
+= 4;
2465 "Create pointer in linker section %s, offset = %ld, section size = %ld\n",
2466 lsect
->name
, (long) linker_section_ptr
->offset
,
2467 (long) lsect
->section
->_raw_size
);
2473 #define bfd_put_ptr(BFD, VAL, ADDR) bfd_put_32 (BFD, VAL, ADDR)
2475 /* Fill in the address for a pointer generated in a linker section. */
2478 elf_finish_pointer_linker_section (bfd
*output_bfd
,
2480 struct bfd_link_info
*info
,
2481 elf_linker_section_t
*lsect
,
2482 struct elf_link_hash_entry
*h
,
2484 const Elf_Internal_Rela
*rel
,
2487 elf_linker_section_pointers_t
*linker_section_ptr
;
2489 BFD_ASSERT (lsect
!= NULL
);
2493 /* Handle global symbol. */
2494 struct ppc_elf_link_hash_entry
*eh
;
2496 eh
= (struct ppc_elf_link_hash_entry
*) h
;
2498 = elf_find_pointer_linker_section (eh
->linker_section_pointer
,
2502 BFD_ASSERT (linker_section_ptr
!= NULL
);
2504 if (! elf_hash_table (info
)->dynamic_sections_created
2507 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
)))
2509 /* This is actually a static link, or it is a
2510 -Bsymbolic link and the symbol is defined
2511 locally. We must initialize this entry in the
2514 When doing a dynamic link, we create a .rela.<xxx>
2515 relocation entry to initialize the value. This
2516 is done in the finish_dynamic_symbol routine. */
2517 if (!linker_section_ptr
->written_address_p
)
2519 linker_section_ptr
->written_address_p
= TRUE
;
2520 bfd_put_ptr (output_bfd
,
2521 relocation
+ linker_section_ptr
->addend
,
2522 (lsect
->section
->contents
2523 + linker_section_ptr
->offset
));
2529 /* Handle local symbol. */
2530 unsigned long r_symndx
= ELF32_R_SYM (rel
->r_info
);
2531 BFD_ASSERT (elf_local_ptr_offsets (input_bfd
) != NULL
);
2532 BFD_ASSERT (elf_local_ptr_offsets (input_bfd
)[r_symndx
] != NULL
);
2533 linker_section_ptr
= (elf_find_pointer_linker_section
2534 (elf_local_ptr_offsets (input_bfd
)[r_symndx
],
2538 BFD_ASSERT (linker_section_ptr
!= NULL
);
2540 /* Write out pointer if it hasn't been rewritten out before. */
2541 if (!linker_section_ptr
->written_address_p
)
2543 linker_section_ptr
->written_address_p
= TRUE
;
2544 bfd_put_ptr (output_bfd
, relocation
+ linker_section_ptr
->addend
,
2545 lsect
->section
->contents
+ linker_section_ptr
->offset
);
2549 /* We need to generate a relative reloc for the dynamic
2552 asection
*srel
= lsect
->rel_section
;
2553 Elf_Internal_Rela outrel
[MAX_INT_RELS_PER_EXT_REL
];
2555 const struct elf_backend_data
*bed
;
2558 BFD_ASSERT (srel
!= NULL
);
2560 bed
= get_elf_backend_data (output_bfd
);
2561 for (i
= 0; i
< bed
->s
->int_rels_per_ext_rel
; i
++)
2563 outrel
[i
].r_offset
= (lsect
->section
->output_section
->vma
2564 + lsect
->section
->output_offset
2565 + linker_section_ptr
->offset
);
2566 outrel
[i
].r_info
= 0;
2567 outrel
[i
].r_addend
= 0;
2569 outrel
[0].r_info
= ELF32_R_INFO (0, relative_reloc
);
2570 erel
= lsect
->section
->contents
;
2571 erel
+= (elf_section_data (lsect
->section
)->rel_count
++
2572 * sizeof (Elf32_External_Rela
));
2573 bfd_elf32_swap_reloca_out (output_bfd
, outrel
, erel
);
2578 relocation
= (lsect
->section
->output_offset
2579 + linker_section_ptr
->offset
2580 - lsect
->sym_offset
);
2584 "Finish pointer in linker section %s, offset = %ld (0x%lx)\n",
2585 lsect
->name
, (long) relocation
, (long) relocation
);
2588 /* Subtract out the addend, because it will get added back in by the normal
2590 return relocation
- linker_section_ptr
->addend
;
2593 /* Create a special linker section */
2594 static elf_linker_section_t
*
2595 ppc_elf_create_linker_section (bfd
*abfd
,
2596 struct bfd_link_info
*info
,
2597 enum elf_linker_section_enum which
)
2599 elf_linker_section_t
*lsect
;
2600 struct ppc_elf_link_hash_table
*htab
= ppc_elf_hash_table (info
);
2605 const char *rel_name
;
2606 const char *sym_name
;
2609 /* Both of these sections are (technically) created by the user
2610 putting data in them, so they shouldn't be marked
2613 The linker creates them so it has somewhere to attach their
2614 respective symbols. In fact, if they were empty it would
2615 be OK to leave the symbol set to 0 (or any random number), because
2616 the appropriate register should never be used. */
2617 flags
= SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
;
2626 case LINKER_SECTION_SDATA
: /* .sdata/.sbss section */
2628 rel_name
= ".rela.sdata";
2629 sym_name
= "_SDA_BASE_";
2632 case LINKER_SECTION_SDATA2
: /* .sdata2/.sbss2 section */
2634 rel_name
= ".rela.sdata2";
2635 sym_name
= "_SDA2_BASE_";
2636 flags
|= SEC_READONLY
;
2640 /* Record the first bfd that needs the special sections. */
2641 if (!htab
->elf
.dynobj
)
2642 htab
->elf
.dynobj
= abfd
;
2644 amt
= sizeof (elf_linker_section_t
);
2645 lsect
= bfd_zalloc (htab
->elf
.dynobj
, amt
);
2647 lsect
->sym_offset
= sym_offset
;
2649 /* See if the sections already exist. */
2650 s
= bfd_get_section_by_name (htab
->elf
.dynobj
, name
);
2651 if (s
== NULL
|| (s
->flags
& flags
) != flags
)
2653 s
= bfd_make_section_anyway (htab
->elf
.dynobj
, name
);
2655 || !bfd_set_section_flags (htab
->elf
.dynobj
, s
, flags
))
2660 if (bfd_get_section_alignment (htab
->elf
.dynobj
, s
) < 2
2661 && !bfd_set_section_alignment (htab
->elf
.dynobj
, s
, 2))
2664 s
->_raw_size
= align_power (s
->_raw_size
, 2);
2667 fprintf (stderr
, "Creating section %s, current size = %ld\n",
2668 name
, (long) s
->_raw_size
);
2673 struct elf_link_hash_entry
*h
;
2674 struct bfd_link_hash_entry
*bh
;
2677 fprintf (stderr
, "Adding %s to section %s\n", sym_name
, name
);
2679 bh
= bfd_link_hash_lookup (info
->hash
, sym_name
,
2680 FALSE
, FALSE
, FALSE
);
2682 if ((bh
== NULL
|| bh
->type
== bfd_link_hash_undefined
)
2683 && !(_bfd_generic_link_add_one_symbol
2684 (info
, abfd
, sym_name
, BSF_GLOBAL
, s
, sym_offset
, NULL
,
2685 FALSE
, get_elf_backend_data (abfd
)->collect
, &bh
)))
2687 h
= (struct elf_link_hash_entry
*) bh
;
2689 h
->type
= STT_OBJECT
;
2690 lsect
->sym_hash
= h
;
2693 && ! _bfd_elf_link_record_dynamic_symbol (info
, h
))
2699 s
= bfd_make_section_anyway (htab
->elf
.dynobj
, rel_name
);
2700 lsect
->rel_section
= s
;
2701 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
2702 | SEC_LINKER_CREATED
| SEC_READONLY
);
2704 || ! bfd_set_section_flags (htab
->elf
.dynobj
, s
, flags
)
2705 || ! bfd_set_section_alignment (htab
->elf
.dynobj
, s
, 2))
2712 /* If we have a non-zero sized .sbss2 or .PPC.EMB.sbss0 sections, we
2713 need to bump up the number of section headers. */
2716 ppc_elf_additional_program_headers (bfd
*abfd
)
2723 s
= bfd_get_section_by_name (abfd
, ".interp");
2727 s
= bfd_get_section_by_name (abfd
, ".sbss2");
2728 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0 && s
->_raw_size
> 0)
2731 s
= bfd_get_section_by_name (abfd
, ".PPC.EMB.sbss0");
2732 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0 && s
->_raw_size
> 0)
2738 /* Modify the segment map if needed. */
2741 ppc_elf_modify_segment_map (bfd
*abfd ATTRIBUTE_UNUSED
)
2746 /* The powerpc .got has a blrl instruction in it. Mark it executable. */
2749 ppc_elf_create_got (bfd
*abfd
, struct bfd_link_info
*info
)
2751 struct ppc_elf_link_hash_table
*htab
;
2755 if (!_bfd_elf_create_got_section (abfd
, info
))
2758 htab
= ppc_elf_hash_table (info
);
2759 htab
->got
= s
= bfd_get_section_by_name (abfd
, ".got");
2763 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_CODE
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
2764 | SEC_LINKER_CREATED
);
2765 if (!bfd_set_section_flags (abfd
, s
, flags
))
2768 htab
->relgot
= bfd_make_section (abfd
, ".rela.got");
2770 || ! bfd_set_section_flags (abfd
, htab
->relgot
,
2771 (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
2772 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
2774 || ! bfd_set_section_alignment (abfd
, htab
->relgot
, 2))
2780 /* We have to create .dynsbss and .rela.sbss here so that they get mapped
2781 to output sections (just like _bfd_elf_create_dynamic_sections has
2782 to create .dynbss and .rela.bss). */
2785 ppc_elf_create_dynamic_sections (bfd
*abfd
, struct bfd_link_info
*info
)
2787 struct ppc_elf_link_hash_table
*htab
;
2791 htab
= ppc_elf_hash_table (info
);
2793 if (htab
->got
== NULL
2794 && !ppc_elf_create_got (abfd
, info
))
2797 if (!_bfd_elf_create_dynamic_sections (abfd
, info
))
2800 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
2801 | SEC_LINKER_CREATED
);
2803 htab
->dynbss
= bfd_get_section_by_name (abfd
, ".dynbss");
2804 htab
->dynsbss
= s
= bfd_make_section (abfd
, ".dynsbss");
2806 || ! bfd_set_section_flags (abfd
, s
, SEC_ALLOC
))
2811 htab
->relbss
= bfd_get_section_by_name (abfd
, ".rela.bss");
2812 htab
->relsbss
= s
= bfd_make_section (abfd
, ".rela.sbss");
2814 || ! bfd_set_section_flags (abfd
, s
, flags
| SEC_READONLY
)
2815 || ! bfd_set_section_alignment (abfd
, s
, 2))
2819 htab
->relplt
= bfd_get_section_by_name (abfd
, ".rela.plt");
2820 htab
->plt
= s
= bfd_get_section_by_name (abfd
, ".plt");
2824 flags
= SEC_ALLOC
| SEC_CODE
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
;
2825 return bfd_set_section_flags (abfd
, s
, flags
);
2828 /* Adjust a symbol defined by a dynamic object and referenced by a
2829 regular object. The current definition is in some section of the
2830 dynamic object, but we're not including those sections. We have to
2831 change the definition to something the rest of the link can
2835 ppc_elf_adjust_dynamic_symbol (struct bfd_link_info
*info
,
2836 struct elf_link_hash_entry
*h
)
2838 struct ppc_elf_link_hash_table
*htab
;
2840 unsigned int power_of_two
;
2843 fprintf (stderr
, "ppc_elf_adjust_dynamic_symbol called for %s\n",
2844 h
->root
.root
.string
);
2847 /* Make sure we know what is going on here. */
2848 htab
= ppc_elf_hash_table (info
);
2849 BFD_ASSERT (htab
->elf
.dynobj
!= NULL
2850 && ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
)
2851 || h
->weakdef
!= NULL
2852 || ((h
->elf_link_hash_flags
2853 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0
2854 && (h
->elf_link_hash_flags
2855 & ELF_LINK_HASH_REF_REGULAR
) != 0
2856 && (h
->elf_link_hash_flags
2857 & ELF_LINK_HASH_DEF_REGULAR
) == 0)));
2859 /* Deal with function syms. */
2860 if (h
->type
== STT_FUNC
2861 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
2863 /* Clear procedure linkage table information for any symbol that
2864 won't need a .plt entry. */
2865 if (h
->plt
.refcount
<= 0
2866 || SYMBOL_CALLS_LOCAL (info
, h
)
2867 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
2868 && h
->root
.type
== bfd_link_hash_undefweak
))
2870 /* A PLT entry is not required/allowed when:
2872 1. We are not using ld.so; because then the PLT entry
2873 can't be set up, so we can't use one. In this case,
2874 ppc_elf_adjust_dynamic_symbol won't even be called.
2876 2. GC has rendered the entry unused.
2878 3. We know for certain that a call to this symbol
2879 will go to this object, or will remain undefined. */
2880 h
->plt
.offset
= (bfd_vma
) -1;
2881 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
2886 h
->plt
.offset
= (bfd_vma
) -1;
2888 /* If this is a weak symbol, and there is a real definition, the
2889 processor independent code will have arranged for us to see the
2890 real definition first, and we can just use the same value. */
2891 if (h
->weakdef
!= NULL
)
2893 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
2894 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
2895 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
2896 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
2897 if (ELIMINATE_COPY_RELOCS
)
2898 h
->elf_link_hash_flags
2899 = ((h
->elf_link_hash_flags
& ~ELF_LINK_NON_GOT_REF
)
2900 | (h
->weakdef
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
));
2904 /* This is a reference to a symbol defined by a dynamic object which
2905 is not a function. */
2907 /* If we are creating a shared library, we must presume that the
2908 only references to the symbol are via the global offset table.
2909 For such cases we need not do anything here; the relocations will
2910 be handled correctly by relocate_section. */
2914 /* If there are no references to this symbol that do not use the
2915 GOT, we don't need to generate a copy reloc. */
2916 if ((h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0)
2919 if (ELIMINATE_COPY_RELOCS
)
2921 struct ppc_elf_dyn_relocs
*p
;
2922 for (p
= ppc_elf_hash_entry (h
)->dyn_relocs
; p
!= NULL
; p
= p
->next
)
2924 s
= p
->sec
->output_section
;
2925 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
2929 /* If we didn't find any dynamic relocs in read-only sections, then
2930 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
2933 h
->elf_link_hash_flags
&= ~ELF_LINK_NON_GOT_REF
;
2938 /* We must allocate the symbol in our .dynbss section, which will
2939 become part of the .bss section of the executable. There will be
2940 an entry for this symbol in the .dynsym section. The dynamic
2941 object will contain position independent code, so all references
2942 from the dynamic object to this symbol will go through the global
2943 offset table. The dynamic linker will use the .dynsym entry to
2944 determine the address it must put in the global offset table, so
2945 both the dynamic object and the regular object will refer to the
2946 same memory location for the variable.
2948 Of course, if the symbol is sufficiently small, we must instead
2949 allocate it in .sbss. FIXME: It would be better to do this if and
2950 only if there were actually SDAREL relocs for that symbol. */
2952 if (h
->size
<= elf_gp_size (htab
->elf
.dynobj
))
2956 BFD_ASSERT (s
!= NULL
);
2958 /* We must generate a R_PPC_COPY reloc to tell the dynamic linker to
2959 copy the initial value out of the dynamic object and into the
2960 runtime process image. We need to remember the offset into the
2961 .rela.bss section we are going to use. */
2962 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
2966 if (h
->size
<= elf_gp_size (htab
->elf
.dynobj
))
2967 srel
= htab
->relsbss
;
2969 srel
= htab
->relbss
;
2970 BFD_ASSERT (srel
!= NULL
);
2971 srel
->_raw_size
+= sizeof (Elf32_External_Rela
);
2972 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_COPY
;
2975 /* We need to figure out the alignment required for this symbol. I
2976 have no idea how ELF linkers handle this. */
2977 power_of_two
= bfd_log2 (h
->size
);
2978 if (power_of_two
> 4)
2981 /* Apply the required alignment. */
2982 s
->_raw_size
= BFD_ALIGN (s
->_raw_size
,
2983 (bfd_size_type
) (1 << power_of_two
));
2984 if (power_of_two
> bfd_get_section_alignment (htab
->elf
.dynobj
, s
))
2986 if (! bfd_set_section_alignment (htab
->elf
.dynobj
, s
, power_of_two
))
2990 /* Define the symbol as being at this point in the section. */
2991 h
->root
.u
.def
.section
= s
;
2992 h
->root
.u
.def
.value
= s
->_raw_size
;
2994 /* Increment the section size to make room for the symbol. */
2995 s
->_raw_size
+= h
->size
;
3000 /* This is the condition under which finish_dynamic_symbol will be
3001 called from elflink.h. If elflink.h doesn't call our
3002 finish_dynamic_symbol routine, we'll need to do something about
3003 initializing any .plt and .got entries in relocate_section. */
3004 #define WILL_CALL_FINISH_DYNAMIC_SYMBOL(DYN, SHARED, H) \
3007 || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) \
3008 && ((H)->dynindx != -1 \
3009 || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0))
3011 /* Of those relocs that might be copied as dynamic relocs, this macro
3012 selects those that must be copied when linking a shared library,
3013 even when the symbol is local. */
3015 #define MUST_BE_DYN_RELOC(RTYPE) \
3016 ((RTYPE) != R_PPC_REL24 \
3017 && (RTYPE) != R_PPC_REL14 \
3018 && (RTYPE) != R_PPC_REL14_BRTAKEN \
3019 && (RTYPE) != R_PPC_REL14_BRNTAKEN \
3020 && (RTYPE) != R_PPC_REL32)
3022 /* Allocate space in associated reloc sections for dynamic relocs. */
3025 allocate_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
3027 struct bfd_link_info
*info
= inf
;
3028 struct ppc_elf_link_hash_entry
*eh
;
3029 struct ppc_elf_link_hash_table
*htab
;
3030 struct ppc_elf_dyn_relocs
*p
;
3032 if (h
->root
.type
== bfd_link_hash_indirect
)
3035 if (h
->root
.type
== bfd_link_hash_warning
)
3036 /* When warning symbols are created, they **replace** the "real"
3037 entry in the hash table, thus we never get to see the real
3038 symbol in a hash traversal. So look at it now. */
3039 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
3041 htab
= ppc_elf_hash_table (info
);
3042 if (htab
->elf
.dynamic_sections_created
3043 && h
->plt
.refcount
> 0)
3045 /* Make sure this symbol is output as a dynamic symbol. */
3046 if (h
->dynindx
== -1
3047 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
3049 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
3054 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h
))
3056 asection
*s
= htab
->plt
;
3058 /* If this is the first .plt entry, make room for the special
3060 if (s
->_raw_size
== 0)
3061 s
->_raw_size
+= PLT_INITIAL_ENTRY_SIZE
;
3063 /* The PowerPC PLT is actually composed of two parts, the
3064 first part is 2 words (for a load and a jump), and then
3065 there is a remaining word available at the end. */
3066 h
->plt
.offset
= (PLT_INITIAL_ENTRY_SIZE
3068 * ((s
->_raw_size
- PLT_INITIAL_ENTRY_SIZE
)
3069 / PLT_ENTRY_SIZE
)));
3071 /* If this symbol is not defined in a regular file, and we
3072 are not generating a shared library, then set the symbol
3073 to this location in the .plt. This is required to make
3074 function pointers compare as equal between the normal
3075 executable and the shared library. */
3077 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
3079 h
->root
.u
.def
.section
= s
;
3080 h
->root
.u
.def
.value
= h
->plt
.offset
;
3083 /* Make room for this entry. After the 8192nd entry, room
3084 for two entries is allocated. */
3085 s
->_raw_size
+= PLT_ENTRY_SIZE
;
3086 if ((s
->_raw_size
- PLT_INITIAL_ENTRY_SIZE
) / PLT_ENTRY_SIZE
3087 > PLT_NUM_SINGLE_ENTRIES
)
3088 s
->_raw_size
+= PLT_ENTRY_SIZE
;
3090 /* We also need to make an entry in the .rela.plt section. */
3091 htab
->relplt
->_raw_size
+= sizeof (Elf32_External_Rela
);
3095 h
->plt
.offset
= (bfd_vma
) -1;
3096 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
3101 h
->plt
.offset
= (bfd_vma
) -1;
3102 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
3105 eh
= (struct ppc_elf_link_hash_entry
*) h
;
3106 if (eh
->elf
.got
.refcount
> 0)
3108 /* Make sure this symbol is output as a dynamic symbol. */
3109 if (eh
->elf
.dynindx
== -1
3110 && (eh
->elf
.elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
3112 if (!bfd_elf32_link_record_dynamic_symbol (info
, &eh
->elf
))
3116 if (eh
->tls_mask
== (TLS_TLS
| TLS_LD
)
3117 && !(eh
->elf
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
))
3118 /* If just an LD reloc, we'll just use htab->tlsld_got.offset. */
3119 eh
->elf
.got
.offset
= (bfd_vma
) -1;
3123 eh
->elf
.got
.offset
= htab
->got
->_raw_size
;
3124 if ((eh
->tls_mask
& TLS_TLS
) != 0)
3126 if ((eh
->tls_mask
& TLS_LD
) != 0)
3127 htab
->got
->_raw_size
+= 8;
3128 if ((eh
->tls_mask
& TLS_GD
) != 0)
3129 htab
->got
->_raw_size
+= 8;
3130 if ((eh
->tls_mask
& (TLS_TPREL
| TLS_TPRELGD
)) != 0)
3131 htab
->got
->_raw_size
+= 4;
3132 if ((eh
->tls_mask
& TLS_DTPREL
) != 0)
3133 htab
->got
->_raw_size
+= 4;
3136 htab
->got
->_raw_size
+= 4;
3137 dyn
= htab
->elf
.dynamic_sections_created
;
3139 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, &eh
->elf
))
3140 && (ELF_ST_VISIBILITY (eh
->elf
.other
) == STV_DEFAULT
3141 || eh
->elf
.root
.type
!= bfd_link_hash_undefweak
))
3143 /* All the entries we allocated need relocs. */
3144 htab
->relgot
->_raw_size
3145 += ((htab
->got
->_raw_size
- eh
->elf
.got
.offset
) / 4
3146 * sizeof (Elf32_External_Rela
));
3147 /* Except LD only needs one. */
3148 if ((eh
->tls_mask
& TLS_LD
) != 0)
3149 htab
->relgot
->_raw_size
-= sizeof (Elf32_External_Rela
);
3154 eh
->elf
.got
.offset
= (bfd_vma
) -1;
3156 if (eh
->dyn_relocs
== NULL
)
3159 /* In the shared -Bsymbolic case, discard space allocated for
3160 dynamic pc-relative relocs against symbols which turn out to be
3161 defined in regular objects. For the normal shared case, discard
3162 space for relocs that have become local due to symbol visibility
3167 /* Relocs that use pc_count are those that appear on a call insn,
3168 or certain REL relocs (see MUST_BE_DYN_RELOC) that can be
3169 generated via assembly. We want calls to protected symbols to
3170 resolve directly to the function rather than going via the plt.
3171 If people want function pointer comparisons to work as expected
3172 then they should avoid writing weird assembly. */
3173 if (SYMBOL_CALLS_LOCAL (info
, h
))
3175 struct ppc_elf_dyn_relocs
**pp
;
3177 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
3179 p
->count
-= p
->pc_count
;
3188 /* Also discard relocs on undefined weak syms with non-default
3190 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
3191 && h
->root
.type
== bfd_link_hash_undefweak
)
3192 eh
->dyn_relocs
= NULL
;
3194 else if (ELIMINATE_COPY_RELOCS
)
3196 /* For the non-shared case, discard space for relocs against
3197 symbols which turn out to need copy relocs or are not
3200 if ((h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0
3201 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
3202 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
3204 /* Make sure this symbol is output as a dynamic symbol.
3205 Undefined weak syms won't yet be marked as dynamic. */
3206 if (h
->dynindx
== -1
3207 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
3209 if (! bfd_elf64_link_record_dynamic_symbol (info
, h
))
3213 /* If that succeeded, we know we'll be keeping all the
3215 if (h
->dynindx
!= -1)
3219 eh
->dyn_relocs
= NULL
;
3224 /* Finally, allocate space. */
3225 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
3227 asection
*sreloc
= elf_section_data (p
->sec
)->sreloc
;
3228 sreloc
->_raw_size
+= p
->count
* sizeof (Elf32_External_Rela
);
3234 /* Find any dynamic relocs that apply to read-only sections. */
3237 readonly_dynrelocs (struct elf_link_hash_entry
*h
, void *info
)
3239 struct ppc_elf_dyn_relocs
*p
;
3241 if (h
->root
.type
== bfd_link_hash_indirect
)
3244 if (h
->root
.type
== bfd_link_hash_warning
)
3245 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
3247 for (p
= ppc_elf_hash_entry (h
)->dyn_relocs
; p
!= NULL
; p
= p
->next
)
3249 asection
*s
= p
->sec
->output_section
;
3252 && ((s
->flags
& (SEC_READONLY
| SEC_ALLOC
))
3253 == (SEC_READONLY
| SEC_ALLOC
)))
3255 ((struct bfd_link_info
*) info
)->flags
|= DF_TEXTREL
;
3257 /* Not an error, just cut short the traversal. */
3264 /* Set the sizes of the dynamic sections. */
3267 ppc_elf_size_dynamic_sections (bfd
*output_bfd ATTRIBUTE_UNUSED
,
3268 struct bfd_link_info
*info
)
3270 struct ppc_elf_link_hash_table
*htab
;
3276 fprintf (stderr
, "ppc_elf_size_dynamic_sections called\n");
3279 htab
= ppc_elf_hash_table (info
);
3280 BFD_ASSERT (htab
->elf
.dynobj
!= NULL
);
3282 if (elf_hash_table (info
)->dynamic_sections_created
)
3284 /* Set the contents of the .interp section to the interpreter. */
3285 if (info
->executable
)
3287 s
= bfd_get_section_by_name (htab
->elf
.dynobj
, ".interp");
3288 BFD_ASSERT (s
!= NULL
);
3289 s
->_raw_size
= sizeof ELF_DYNAMIC_INTERPRETER
;
3290 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
3294 if (htab
->tlsld_got
.refcount
> 0)
3296 htab
->tlsld_got
.offset
= htab
->got
->_raw_size
;
3297 htab
->got
->_raw_size
+= 8;
3299 htab
->relgot
->_raw_size
+= sizeof (Elf32_External_Rela
);
3302 htab
->tlsld_got
.offset
= (bfd_vma
) -1;
3304 /* Set up .got offsets for local syms, and space for local dynamic
3306 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
3308 bfd_signed_vma
*local_got
;
3309 bfd_signed_vma
*end_local_got
;
3311 bfd_size_type locsymcount
;
3312 Elf_Internal_Shdr
*symtab_hdr
;
3315 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
)
3318 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
3320 struct ppc_elf_dyn_relocs
*p
;
3322 for (p
= ((struct ppc_elf_dyn_relocs
*)
3323 elf_section_data (s
)->local_dynrel
);
3327 if (!bfd_is_abs_section (p
->sec
)
3328 && bfd_is_abs_section (p
->sec
->output_section
))
3330 /* Input section has been discarded, either because
3331 it is a copy of a linkonce section or due to
3332 linker script /DISCARD/, so we'll be discarding
3335 else if (p
->count
!= 0)
3337 elf_section_data (p
->sec
)->sreloc
->_raw_size
3338 += p
->count
* sizeof (Elf32_External_Rela
);
3339 if ((p
->sec
->output_section
->flags
3340 & (SEC_READONLY
| SEC_ALLOC
))
3341 == (SEC_READONLY
| SEC_ALLOC
))
3342 info
->flags
|= DF_TEXTREL
;
3347 local_got
= elf_local_got_refcounts (ibfd
);
3351 symtab_hdr
= &elf_tdata (ibfd
)->symtab_hdr
;
3352 locsymcount
= symtab_hdr
->sh_info
;
3353 end_local_got
= local_got
+ locsymcount
;
3354 lgot_masks
= (char *) end_local_got
;
3356 srel
= htab
->relgot
;
3357 for (; local_got
< end_local_got
; ++local_got
, ++lgot_masks
)
3360 if (*lgot_masks
== (TLS_TLS
| TLS_LD
))
3362 /* If just an LD reloc, we'll just use
3363 htab->tlsld_got.offset. */
3364 if (htab
->tlsld_got
.offset
== (bfd_vma
) -1)
3366 htab
->tlsld_got
.offset
= s
->_raw_size
;
3369 srel
->_raw_size
+= sizeof (Elf32_External_Rela
);
3371 *local_got
= (bfd_vma
) -1;
3375 *local_got
= s
->_raw_size
;
3376 if ((*lgot_masks
& TLS_TLS
) != 0)
3378 if ((*lgot_masks
& TLS_GD
) != 0)
3380 if ((*lgot_masks
& (TLS_TPREL
| TLS_TPRELGD
)) != 0)
3382 if ((*lgot_masks
& TLS_DTPREL
) != 0)
3388 srel
->_raw_size
+= ((s
->_raw_size
- *local_got
) / 4
3389 * sizeof (Elf32_External_Rela
));
3393 *local_got
= (bfd_vma
) -1;
3396 /* Allocate space for global sym dynamic relocs. */
3397 elf_link_hash_traverse (elf_hash_table (info
), allocate_dynrelocs
, info
);
3399 /* We've now determined the sizes of the various dynamic sections.
3400 Allocate memory for them. */
3402 for (s
= htab
->elf
.dynobj
->sections
; s
!= NULL
; s
= s
->next
)
3404 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
3409 || (htab
->sdata
!= NULL
&& s
== htab
->sdata
->section
)
3410 || (htab
->sdata2
!= NULL
&& s
== htab
->sdata2
->section
))
3412 /* Strip this section if we don't need it; see the
3415 else if (strncmp (bfd_get_section_name (dynobj
, s
), ".rela", 5) == 0)
3417 if (s
->_raw_size
== 0)
3419 /* If we don't need this section, strip it from the
3420 output file. This is mostly to handle .rela.bss and
3421 .rela.plt. We must create both sections in
3422 create_dynamic_sections, because they must be created
3423 before the linker maps input sections to output
3424 sections. The linker does that before
3425 adjust_dynamic_symbol is called, and it is that
3426 function which decides whether anything needs to go
3427 into these sections. */
3431 /* Remember whether there are any relocation sections. */
3434 /* We use the reloc_count field as a counter if we need
3435 to copy relocs into the output file. */
3441 /* It's not one of our sections, so don't allocate space. */
3445 if (s
->_raw_size
== 0)
3447 _bfd_strip_section_from_output (info
, s
);
3451 /* Allocate memory for the section contents. */
3452 s
->contents
= bfd_zalloc (htab
->elf
.dynobj
, s
->_raw_size
);
3453 if (s
->contents
== NULL
)
3457 if (htab
->elf
.dynamic_sections_created
)
3459 /* Add some entries to the .dynamic section. We fill in the
3460 values later, in ppc_elf_finish_dynamic_sections, but we
3461 must add the entries now so that we get the correct size for
3462 the .dynamic section. The DT_DEBUG entry is filled in by the
3463 dynamic linker and used by the debugger. */
3464 #define add_dynamic_entry(TAG, VAL) \
3465 bfd_elf32_add_dynamic_entry (info, (TAG), (VAL))
3467 if (info
->executable
)
3469 if (!add_dynamic_entry (DT_DEBUG
, 0))
3473 if (htab
->plt
!= NULL
&& htab
->plt
->_raw_size
!= 0)
3475 if (!add_dynamic_entry (DT_PLTGOT
, 0)
3476 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
3477 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
3478 || !add_dynamic_entry (DT_JMPREL
, 0))
3484 if (!add_dynamic_entry (DT_RELA
, 0)
3485 || !add_dynamic_entry (DT_RELASZ
, 0)
3486 || !add_dynamic_entry (DT_RELAENT
, sizeof (Elf32_External_Rela
)))
3490 /* If any dynamic relocs apply to a read-only section, then we
3491 need a DT_TEXTREL entry. */
3492 if ((info
->flags
& DF_TEXTREL
) == 0)
3493 elf_link_hash_traverse (elf_hash_table (info
), readonly_dynrelocs
,
3496 if ((info
->flags
& DF_TEXTREL
) != 0)
3498 if (!add_dynamic_entry (DT_TEXTREL
, 0))
3502 #undef add_dynamic_entry
3508 update_local_sym_info (bfd
*abfd
,
3509 Elf_Internal_Shdr
*symtab_hdr
,
3510 unsigned long r_symndx
,
3513 bfd_signed_vma
*local_got_refcounts
= elf_local_got_refcounts (abfd
);
3514 char *local_got_tls_masks
;
3516 if (local_got_refcounts
== NULL
)
3518 bfd_size_type size
= symtab_hdr
->sh_info
;
3520 size
*= sizeof (*local_got_refcounts
) + sizeof (*local_got_tls_masks
);
3521 local_got_refcounts
= bfd_zalloc (abfd
, size
);
3522 if (local_got_refcounts
== NULL
)
3524 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
3527 local_got_refcounts
[r_symndx
] += 1;
3528 local_got_tls_masks
= (char *) (local_got_refcounts
+ symtab_hdr
->sh_info
);
3529 local_got_tls_masks
[r_symndx
] |= tls_type
;
3534 bad_shared_reloc (bfd
*abfd
, enum elf_ppc_reloc_type r_type
)
3536 (*_bfd_error_handler
)
3537 (_("%s: relocation %s cannot be used when making a shared object"),
3538 bfd_archive_filename (abfd
),
3539 ppc_elf_howto_table
[r_type
]->name
);
3540 bfd_set_error (bfd_error_bad_value
);
3543 /* Look through the relocs for a section during the first phase, and
3544 allocate space in the global offset table or procedure linkage
3548 ppc_elf_check_relocs (bfd
*abfd
,
3549 struct bfd_link_info
*info
,
3551 const Elf_Internal_Rela
*relocs
)
3553 struct ppc_elf_link_hash_table
*htab
;
3554 Elf_Internal_Shdr
*symtab_hdr
;
3555 struct elf_link_hash_entry
**sym_hashes
;
3556 const Elf_Internal_Rela
*rel
;
3557 const Elf_Internal_Rela
*rel_end
;
3560 if (info
->relocatable
)
3564 fprintf (stderr
, "ppc_elf_check_relocs called for section %s in %s\n",
3565 bfd_get_section_name (abfd
, sec
),
3566 bfd_archive_filename (abfd
));
3569 /* Initialize howto table if not already done. */
3570 if (!ppc_elf_howto_table
[R_PPC_ADDR32
])
3571 ppc_elf_howto_init ();
3573 /* Create the linker generated sections all the time so that the
3574 special symbols are created. */
3575 htab
= ppc_elf_hash_table (info
);
3576 if (htab
->sdata
== NULL
)
3578 htab
->sdata
= ppc_elf_create_linker_section (abfd
, info
,
3579 LINKER_SECTION_SDATA
);
3580 if (htab
->sdata
== NULL
)
3584 if (htab
->sdata2
== NULL
)
3586 htab
->sdata2
= ppc_elf_create_linker_section (abfd
, info
,
3587 LINKER_SECTION_SDATA2
);
3588 if (htab
->sdata2
== NULL
)
3592 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
3593 sym_hashes
= elf_sym_hashes (abfd
);
3596 rel_end
= relocs
+ sec
->reloc_count
;
3597 for (rel
= relocs
; rel
< rel_end
; rel
++)
3599 unsigned long r_symndx
;
3600 enum elf_ppc_reloc_type r_type
;
3601 struct elf_link_hash_entry
*h
;
3604 r_symndx
= ELF32_R_SYM (rel
->r_info
);
3605 if (r_symndx
< symtab_hdr
->sh_info
)
3608 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
3610 /* If a relocation refers to _GLOBAL_OFFSET_TABLE_, create the .got.
3611 This shows up in particular in an R_PPC_ADDR32 in the eabi
3613 if (h
&& strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
3615 if (htab
->got
== NULL
)
3617 if (htab
->elf
.dynobj
== NULL
)
3618 htab
->elf
.dynobj
= abfd
;
3619 if (!ppc_elf_create_got (htab
->elf
.dynobj
, info
))
3624 r_type
= ELF32_R_TYPE (rel
->r_info
);
3627 case R_PPC_GOT_TLSLD16
:
3628 case R_PPC_GOT_TLSLD16_LO
:
3629 case R_PPC_GOT_TLSLD16_HI
:
3630 case R_PPC_GOT_TLSLD16_HA
:
3631 htab
->tlsld_got
.refcount
+= 1;
3632 tls_type
= TLS_TLS
| TLS_LD
;
3635 case R_PPC_GOT_TLSGD16
:
3636 case R_PPC_GOT_TLSGD16_LO
:
3637 case R_PPC_GOT_TLSGD16_HI
:
3638 case R_PPC_GOT_TLSGD16_HA
:
3639 tls_type
= TLS_TLS
| TLS_GD
;
3642 case R_PPC_GOT_TPREL16
:
3643 case R_PPC_GOT_TPREL16_LO
:
3644 case R_PPC_GOT_TPREL16_HI
:
3645 case R_PPC_GOT_TPREL16_HA
:
3647 info
->flags
|= DF_STATIC_TLS
;
3648 tls_type
= TLS_TLS
| TLS_TPREL
;
3651 case R_PPC_GOT_DTPREL16
:
3652 case R_PPC_GOT_DTPREL16_LO
:
3653 case R_PPC_GOT_DTPREL16_HI
:
3654 case R_PPC_GOT_DTPREL16_HA
:
3655 tls_type
= TLS_TLS
| TLS_DTPREL
;
3657 sec
->has_tls_reloc
= 1;
3660 /* GOT16 relocations */
3662 case R_PPC_GOT16_LO
:
3663 case R_PPC_GOT16_HI
:
3664 case R_PPC_GOT16_HA
:
3665 /* This symbol requires a global offset table entry. */
3666 if (htab
->got
== NULL
)
3668 if (htab
->elf
.dynobj
== NULL
)
3669 htab
->elf
.dynobj
= abfd
;
3670 if (!ppc_elf_create_got (htab
->elf
.dynobj
, info
))
3675 h
->got
.refcount
+= 1;
3676 ppc_elf_hash_entry (h
)->tls_mask
|= tls_type
;
3679 /* This is a global offset table entry for a local symbol. */
3680 if (!update_local_sym_info (abfd
, symtab_hdr
, r_symndx
, tls_type
))
3684 /* Indirect .sdata relocation. */
3685 case R_PPC_EMB_SDAI16
:
3688 bad_shared_reloc (abfd
, r_type
);
3691 if (!elf_create_pointer_linker_section (abfd
, info
,
3692 htab
->sdata
, h
, rel
))
3696 /* Indirect .sdata2 relocation. */
3697 case R_PPC_EMB_SDA2I16
:
3700 bad_shared_reloc (abfd
, r_type
);
3703 if (!elf_create_pointer_linker_section (abfd
, info
,
3704 htab
->sdata2
, h
, rel
))
3708 case R_PPC_SDAREL16
:
3709 case R_PPC_EMB_SDA2REL
:
3710 case R_PPC_EMB_SDA21
:
3711 case R_PPC_EMB_RELSDA
:
3712 case R_PPC_EMB_NADDR32
:
3713 case R_PPC_EMB_NADDR16
:
3714 case R_PPC_EMB_NADDR16_LO
:
3715 case R_PPC_EMB_NADDR16_HI
:
3716 case R_PPC_EMB_NADDR16_HA
:
3719 bad_shared_reloc (abfd
, r_type
);
3725 case R_PPC_PLTREL24
:
3726 case R_PPC_PLTREL32
:
3727 case R_PPC_PLT16_LO
:
3728 case R_PPC_PLT16_HI
:
3729 case R_PPC_PLT16_HA
:
3731 fprintf (stderr
, "Reloc requires a PLT entry\n");
3733 /* This symbol requires a procedure linkage table entry. We
3734 actually build the entry in finish_dynamic_symbol,
3735 because this might be a case of linking PIC code without
3736 linking in any dynamic objects, in which case we don't
3737 need to generate a procedure linkage table after all. */
3741 /* It does not make sense to have a procedure linkage
3742 table entry for a local symbol. */
3743 (*_bfd_error_handler
) (_("%s(%s+0x%lx): %s reloc against "
3745 bfd_archive_filename (abfd
),
3747 (long) rel
->r_offset
,
3748 ppc_elf_howto_table
[r_type
]->name
);
3749 bfd_set_error (bfd_error_bad_value
);
3753 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
3757 /* The following relocations don't need to propagate the
3758 relocation if linking a shared object since they are
3759 section relative. */
3761 case R_PPC_SECTOFF_LO
:
3762 case R_PPC_SECTOFF_HI
:
3763 case R_PPC_SECTOFF_HA
:
3764 case R_PPC_DTPREL16
:
3765 case R_PPC_DTPREL16_LO
:
3766 case R_PPC_DTPREL16_HI
:
3767 case R_PPC_DTPREL16_HA
:
3771 /* This are just markers. */
3773 case R_PPC_EMB_MRKREF
:
3778 /* These should only appear in dynamic objects. */
3780 case R_PPC_GLOB_DAT
:
3781 case R_PPC_JMP_SLOT
:
3782 case R_PPC_RELATIVE
:
3785 /* These aren't handled yet. We'll report an error later. */
3787 case R_PPC_EMB_RELSEC16
:
3788 case R_PPC_EMB_RELST_LO
:
3789 case R_PPC_EMB_RELST_HI
:
3790 case R_PPC_EMB_RELST_HA
:
3791 case R_PPC_EMB_BIT_FLD
:
3794 /* This refers only to functions defined in the shared library. */
3795 case R_PPC_LOCAL24PC
:
3798 /* This relocation describes the C++ object vtable hierarchy.
3799 Reconstruct it for later use during GC. */
3800 case R_PPC_GNU_VTINHERIT
:
3801 if (!_bfd_elf32_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
3805 /* This relocation describes which C++ vtable entries are actually
3806 used. Record for later use during GC. */
3807 case R_PPC_GNU_VTENTRY
:
3808 if (!_bfd_elf32_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
3812 /* We shouldn't really be seeing these. */
3815 info
->flags
|= DF_STATIC_TLS
;
3819 case R_PPC_DTPMOD32
:
3820 case R_PPC_DTPREL32
:
3824 case R_PPC_TPREL16_LO
:
3825 case R_PPC_TPREL16_HI
:
3826 case R_PPC_TPREL16_HA
:
3828 info
->flags
|= DF_STATIC_TLS
;
3831 /* When creating a shared object, we must copy these
3832 relocs into the output file. We create a reloc
3833 section in dynobj and make room for the reloc. */
3836 case R_PPC_REL14_BRTAKEN
:
3837 case R_PPC_REL14_BRNTAKEN
:
3840 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
3847 case R_PPC_ADDR16_LO
:
3848 case R_PPC_ADDR16_HI
:
3849 case R_PPC_ADDR16_HA
:
3851 case R_PPC_ADDR14_BRTAKEN
:
3852 case R_PPC_ADDR14_BRNTAKEN
:
3855 if (h
!= NULL
&& !info
->shared
)
3857 /* We may need a plt entry if the symbol turns out to be
3858 a function defined in a dynamic object. */
3861 /* We may need a copy reloc too. */
3862 h
->elf_link_hash_flags
|= ELF_LINK_NON_GOT_REF
;
3866 /* If we are creating a shared library, and this is a reloc
3867 against a global symbol, or a non PC relative reloc
3868 against a local symbol, then we need to copy the reloc
3869 into the shared library. However, if we are linking with
3870 -Bsymbolic, we do not need to copy a reloc against a
3871 global symbol which is defined in an object we are
3872 including in the link (i.e., DEF_REGULAR is set). At
3873 this point we have not seen all the input files, so it is
3874 possible that DEF_REGULAR is not set now but will be set
3875 later (it is never cleared). In case of a weak definition,
3876 DEF_REGULAR may be cleared later by a strong definition in
3877 a shared library. We account for that possibility below by
3878 storing information in the dyn_relocs field of the hash
3879 table entry. A similar situation occurs when creating
3880 shared libraries and symbol visibility changes render the
3883 If on the other hand, we are creating an executable, we
3884 may need to keep relocations for symbols satisfied by a
3885 dynamic library if we manage to avoid copy relocs for the
3888 && (MUST_BE_DYN_RELOC (r_type
)
3890 && (! info
->symbolic
3891 || h
->root
.type
== bfd_link_hash_defweak
3892 || (h
->elf_link_hash_flags
3893 & ELF_LINK_HASH_DEF_REGULAR
) == 0))))
3894 || (ELIMINATE_COPY_RELOCS
3896 && (sec
->flags
& SEC_ALLOC
) != 0
3898 && (h
->root
.type
== bfd_link_hash_defweak
3899 || (h
->elf_link_hash_flags
3900 & ELF_LINK_HASH_DEF_REGULAR
) == 0)))
3902 struct ppc_elf_dyn_relocs
*p
;
3903 struct ppc_elf_dyn_relocs
**head
;
3907 "ppc_elf_check_relocs needs to "
3908 "create relocation for %s\n",
3909 (h
&& h
->root
.root
.string
3910 ? h
->root
.root
.string
: "<unknown>"));
3916 name
= (bfd_elf_string_from_elf_section
3918 elf_elfheader (abfd
)->e_shstrndx
,
3919 elf_section_data (sec
)->rel_hdr
.sh_name
));
3923 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
3924 && strcmp (bfd_get_section_name (abfd
, sec
),
3927 sreloc
= bfd_get_section_by_name (htab
->elf
.dynobj
, name
);
3932 sreloc
= bfd_make_section (htab
->elf
.dynobj
, name
);
3933 flags
= (SEC_HAS_CONTENTS
| SEC_READONLY
3934 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
3935 if ((sec
->flags
& SEC_ALLOC
) != 0)
3936 flags
|= SEC_ALLOC
| SEC_LOAD
;
3938 || ! bfd_set_section_flags (htab
->elf
.dynobj
,
3940 || ! bfd_set_section_alignment (htab
->elf
.dynobj
,
3944 elf_section_data (sec
)->sreloc
= sreloc
;
3947 /* If this is a global symbol, we count the number of
3948 relocations we need for this symbol. */
3951 head
= &ppc_elf_hash_entry (h
)->dyn_relocs
;
3955 /* Track dynamic relocs needed for local syms too.
3956 We really need local syms available to do this
3960 s
= bfd_section_from_r_symndx (abfd
, &htab
->sym_sec
,
3965 head
= ((struct ppc_elf_dyn_relocs
**)
3966 &elf_section_data (s
)->local_dynrel
);
3970 if (p
== NULL
|| p
->sec
!= sec
)
3972 p
= bfd_alloc (htab
->elf
.dynobj
, sizeof *p
);
3983 if (!MUST_BE_DYN_RELOC (r_type
))
3994 /* Return the section that should be marked against GC for a given
3998 ppc_elf_gc_mark_hook (asection
*sec
,
3999 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
4000 Elf_Internal_Rela
*rel
,
4001 struct elf_link_hash_entry
*h
,
4002 Elf_Internal_Sym
*sym
)
4006 switch (ELF32_R_TYPE (rel
->r_info
))
4008 case R_PPC_GNU_VTINHERIT
:
4009 case R_PPC_GNU_VTENTRY
:
4013 switch (h
->root
.type
)
4015 case bfd_link_hash_defined
:
4016 case bfd_link_hash_defweak
:
4017 return h
->root
.u
.def
.section
;
4019 case bfd_link_hash_common
:
4020 return h
->root
.u
.c
.p
->section
;
4028 return bfd_section_from_elf_index (sec
->owner
, sym
->st_shndx
);
4033 /* Update the got, plt and dynamic reloc reference counts for the
4034 section being removed. */
4037 ppc_elf_gc_sweep_hook (bfd
*abfd
,
4038 struct bfd_link_info
*info
,
4040 const Elf_Internal_Rela
*relocs
)
4042 struct ppc_elf_link_hash_table
*htab
;
4043 Elf_Internal_Shdr
*symtab_hdr
;
4044 struct elf_link_hash_entry
**sym_hashes
;
4045 bfd_signed_vma
*local_got_refcounts
;
4046 const Elf_Internal_Rela
*rel
, *relend
;
4048 elf_section_data (sec
)->local_dynrel
= NULL
;
4050 htab
= ppc_elf_hash_table (info
);
4051 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
4052 sym_hashes
= elf_sym_hashes (abfd
);
4053 local_got_refcounts
= elf_local_got_refcounts (abfd
);
4055 relend
= relocs
+ sec
->reloc_count
;
4056 for (rel
= relocs
; rel
< relend
; rel
++)
4058 unsigned long r_symndx
;
4059 enum elf_ppc_reloc_type r_type
;
4060 struct elf_link_hash_entry
*h
= NULL
;
4062 r_symndx
= ELF32_R_SYM (rel
->r_info
);
4063 if (r_symndx
>= symtab_hdr
->sh_info
)
4065 struct ppc_elf_dyn_relocs
**pp
, *p
;
4066 struct ppc_elf_link_hash_entry
*eh
;
4068 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
4069 eh
= (struct ppc_elf_link_hash_entry
*) h
;
4071 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; pp
= &p
->next
)
4074 /* Everything must go for SEC. */
4080 r_type
= ELF32_R_TYPE (rel
->r_info
);
4083 case R_PPC_GOT_TLSLD16
:
4084 case R_PPC_GOT_TLSLD16_LO
:
4085 case R_PPC_GOT_TLSLD16_HI
:
4086 case R_PPC_GOT_TLSLD16_HA
:
4087 htab
->tlsld_got
.refcount
-= 1;
4090 case R_PPC_GOT_TLSGD16
:
4091 case R_PPC_GOT_TLSGD16_LO
:
4092 case R_PPC_GOT_TLSGD16_HI
:
4093 case R_PPC_GOT_TLSGD16_HA
:
4094 case R_PPC_GOT_TPREL16
:
4095 case R_PPC_GOT_TPREL16_LO
:
4096 case R_PPC_GOT_TPREL16_HI
:
4097 case R_PPC_GOT_TPREL16_HA
:
4098 case R_PPC_GOT_DTPREL16
:
4099 case R_PPC_GOT_DTPREL16_LO
:
4100 case R_PPC_GOT_DTPREL16_HI
:
4101 case R_PPC_GOT_DTPREL16_HA
:
4103 case R_PPC_GOT16_LO
:
4104 case R_PPC_GOT16_HI
:
4105 case R_PPC_GOT16_HA
:
4108 if (h
->got
.refcount
> 0)
4111 else if (local_got_refcounts
!= NULL
)
4113 if (local_got_refcounts
[r_symndx
] > 0)
4114 local_got_refcounts
[r_symndx
]--;
4120 case R_PPC_REL14_BRTAKEN
:
4121 case R_PPC_REL14_BRNTAKEN
:
4124 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
4131 case R_PPC_ADDR16_LO
:
4132 case R_PPC_ADDR16_HI
:
4133 case R_PPC_ADDR16_HA
:
4135 case R_PPC_ADDR14_BRTAKEN
:
4136 case R_PPC_ADDR14_BRNTAKEN
:
4140 case R_PPC_PLTREL24
:
4141 case R_PPC_PLT16_LO
:
4142 case R_PPC_PLT16_HI
:
4143 case R_PPC_PLT16_HA
:
4146 if (h
->plt
.refcount
> 0)
4158 /* Set htab->tls_get_addr and call the generic ELF tls_setup function. */
4161 ppc_elf_tls_setup (bfd
*obfd
, struct bfd_link_info
*info
)
4163 struct ppc_elf_link_hash_table
*htab
;
4165 htab
= ppc_elf_hash_table (info
);
4166 htab
->tls_get_addr
= elf_link_hash_lookup (&htab
->elf
, "__tls_get_addr",
4167 FALSE
, FALSE
, TRUE
);
4169 return _bfd_elf_tls_setup (obfd
, info
);
4172 /* Run through all the TLS relocs looking for optimization
4176 ppc_elf_tls_optimize (bfd
*obfd ATTRIBUTE_UNUSED
,
4177 struct bfd_link_info
*info
)
4181 struct ppc_elf_link_hash_table
*htab
;
4183 if (info
->relocatable
|| info
->shared
)
4186 htab
= ppc_elf_hash_table (info
);
4187 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
4189 Elf_Internal_Sym
*locsyms
= NULL
;
4190 Elf_Internal_Shdr
*symtab_hdr
= &elf_tdata (ibfd
)->symtab_hdr
;
4192 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
4193 if (sec
->has_tls_reloc
&& !bfd_is_abs_section (sec
->output_section
))
4195 Elf_Internal_Rela
*relstart
, *rel
, *relend
;
4196 int expecting_tls_get_addr
;
4198 /* Read the relocations. */
4199 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
4201 if (relstart
== NULL
)
4204 expecting_tls_get_addr
= 0;
4205 relend
= relstart
+ sec
->reloc_count
;
4206 for (rel
= relstart
; rel
< relend
; rel
++)
4208 enum elf_ppc_reloc_type r_type
;
4209 unsigned long r_symndx
;
4210 struct elf_link_hash_entry
*h
= NULL
;
4212 char tls_set
, tls_clear
;
4213 bfd_boolean is_local
;
4215 r_symndx
= ELF32_R_SYM (rel
->r_info
);
4216 if (r_symndx
>= symtab_hdr
->sh_info
)
4218 struct elf_link_hash_entry
**sym_hashes
;
4220 sym_hashes
= elf_sym_hashes (ibfd
);
4221 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
4222 while (h
->root
.type
== bfd_link_hash_indirect
4223 || h
->root
.type
== bfd_link_hash_warning
)
4224 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
4229 || !(h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
))
4232 r_type
= ELF32_R_TYPE (rel
->r_info
);
4235 case R_PPC_GOT_TLSLD16
:
4236 case R_PPC_GOT_TLSLD16_LO
:
4237 case R_PPC_GOT_TLSLD16_HI
:
4238 case R_PPC_GOT_TLSLD16_HA
:
4239 /* These relocs should never be against a symbol
4240 defined in a shared lib. Leave them alone if
4241 that turns out to be the case. */
4242 expecting_tls_get_addr
= 0;
4243 htab
->tlsld_got
.refcount
-= 1;
4250 expecting_tls_get_addr
= 1;
4253 case R_PPC_GOT_TLSGD16
:
4254 case R_PPC_GOT_TLSGD16_LO
:
4255 case R_PPC_GOT_TLSGD16_HI
:
4256 case R_PPC_GOT_TLSGD16_HA
:
4262 tls_set
= TLS_TLS
| TLS_TPRELGD
;
4264 expecting_tls_get_addr
= 1;
4267 case R_PPC_GOT_TPREL16
:
4268 case R_PPC_GOT_TPREL16_LO
:
4269 case R_PPC_GOT_TPREL16_HI
:
4270 case R_PPC_GOT_TPREL16_HA
:
4271 expecting_tls_get_addr
= 0;
4276 tls_clear
= TLS_TPREL
;
4283 case R_PPC_REL14_BRTAKEN
:
4284 case R_PPC_REL14_BRNTAKEN
:
4286 if (expecting_tls_get_addr
4288 && h
== htab
->tls_get_addr
)
4290 if (h
->plt
.refcount
> 0)
4291 h
->plt
.refcount
-= 1;
4293 expecting_tls_get_addr
= 0;
4297 expecting_tls_get_addr
= 0;
4305 /* We managed to get rid of a got entry. */
4306 if (h
->got
.refcount
> 0)
4307 h
->got
.refcount
-= 1;
4309 tls_mask
= &ppc_elf_hash_entry (h
)->tls_mask
;
4313 Elf_Internal_Sym
*sym
;
4314 bfd_signed_vma
*lgot_refs
;
4317 if (locsyms
== NULL
)
4319 locsyms
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
4320 if (locsyms
== NULL
)
4321 locsyms
= bfd_elf_get_elf_syms (ibfd
, symtab_hdr
,
4322 symtab_hdr
->sh_info
,
4323 0, NULL
, NULL
, NULL
);
4324 if (locsyms
== NULL
)
4326 if (elf_section_data (sec
)->relocs
!= relstart
)
4331 sym
= locsyms
+ r_symndx
;
4332 lgot_refs
= elf_local_got_refcounts (ibfd
);
4333 if (lgot_refs
== NULL
)
4337 /* We managed to get rid of a got entry. */
4338 if (lgot_refs
[r_symndx
] > 0)
4339 lgot_refs
[r_symndx
] -= 1;
4341 lgot_masks
= (char *) (lgot_refs
+ symtab_hdr
->sh_info
);
4342 tls_mask
= &lgot_masks
[r_symndx
];
4345 *tls_mask
|= tls_set
;
4346 *tls_mask
&= ~tls_clear
;
4349 if (elf_section_data (sec
)->relocs
!= relstart
)
4354 && (symtab_hdr
->contents
!= (unsigned char *) locsyms
))
4356 if (!info
->keep_memory
)
4359 symtab_hdr
->contents
= (unsigned char *) locsyms
;
4365 /* Hook called by the linker routine which adds symbols from an object
4366 file. We use it to put .comm items in .sbss, and not .bss. */
4369 ppc_elf_add_symbol_hook (bfd
*abfd
,
4370 struct bfd_link_info
*info
,
4371 const Elf_Internal_Sym
*sym
,
4372 const char **namep ATTRIBUTE_UNUSED
,
4373 flagword
*flagsp ATTRIBUTE_UNUSED
,
4377 if (sym
->st_shndx
== SHN_COMMON
4378 && !info
->relocatable
4379 && sym
->st_size
<= elf_gp_size (abfd
)
4380 && (info
->hash
->creator
== abfd
->xvec
4381 || info
->hash
->creator
== abfd
->xvec
->alternative_target
))
4383 /* Common symbols less than or equal to -G nn bytes are automatically
4385 struct ppc_elf_link_hash_table
*htab
;
4387 htab
= ppc_elf_hash_table (info
);
4388 if (htab
->sbss
== NULL
)
4390 flagword flags
= SEC_IS_COMMON
;
4392 htab
->sbss
= bfd_make_section_anyway (abfd
, ".sbss");
4393 if (htab
->sbss
== NULL
4394 || ! bfd_set_section_flags (abfd
, htab
->sbss
, flags
))
4399 *valp
= sym
->st_size
;
4405 /* Finish up dynamic symbol handling. We set the contents of various
4406 dynamic sections here. */
4409 ppc_elf_finish_dynamic_symbol (bfd
*output_bfd
,
4410 struct bfd_link_info
*info
,
4411 struct elf_link_hash_entry
*h
,
4412 Elf_Internal_Sym
*sym
)
4414 struct ppc_elf_link_hash_table
*htab
;
4417 fprintf (stderr
, "ppc_elf_finish_dynamic_symbol called for %s",
4418 h
->root
.root
.string
);
4421 htab
= ppc_elf_hash_table (info
);
4422 BFD_ASSERT (htab
->elf
.dynobj
!= NULL
);
4424 if (h
->plt
.offset
!= (bfd_vma
) -1)
4426 Elf_Internal_Rela rela
;
4428 bfd_vma reloc_index
;
4431 fprintf (stderr
, ", plt_offset = %d", h
->plt
.offset
);
4434 /* This symbol has an entry in the procedure linkage table. Set
4437 BFD_ASSERT (h
->dynindx
!= -1);
4438 BFD_ASSERT (htab
->plt
!= NULL
&& htab
->relplt
!= NULL
);
4440 /* We don't need to fill in the .plt. The ppc dynamic linker
4443 /* Fill in the entry in the .rela.plt section. */
4444 rela
.r_offset
= (htab
->plt
->output_section
->vma
4445 + htab
->plt
->output_offset
4447 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_PPC_JMP_SLOT
);
4450 reloc_index
= (h
->plt
.offset
- PLT_INITIAL_ENTRY_SIZE
) / PLT_SLOT_SIZE
;
4451 if (reloc_index
> PLT_NUM_SINGLE_ENTRIES
)
4452 reloc_index
-= (reloc_index
- PLT_NUM_SINGLE_ENTRIES
) / 2;
4453 loc
= (htab
->relplt
->contents
4454 + reloc_index
* sizeof (Elf32_External_Rela
));
4455 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
4457 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
4459 /* Mark the symbol as undefined, rather than as defined in
4460 the .plt section. Leave the value alone. */
4461 sym
->st_shndx
= SHN_UNDEF
;
4462 /* If the symbol is weak, we do need to clear the value.
4463 Otherwise, the PLT entry would provide a definition for
4464 the symbol even if the symbol wasn't defined anywhere,
4465 and so the symbol would never be NULL. */
4466 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_REF_REGULAR_NONWEAK
)
4472 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_COPY
) != 0)
4475 Elf_Internal_Rela rela
;
4478 /* This symbols needs a copy reloc. Set it up. */
4481 fprintf (stderr
, ", copy");
4484 BFD_ASSERT (h
->dynindx
!= -1);
4486 if (h
->size
<= elf_gp_size (htab
->elf
.dynobj
))
4490 BFD_ASSERT (s
!= NULL
);
4492 rela
.r_offset
= (h
->root
.u
.def
.value
4493 + h
->root
.u
.def
.section
->output_section
->vma
4494 + h
->root
.u
.def
.section
->output_offset
);
4495 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_PPC_COPY
);
4497 loc
= s
->contents
+ s
->reloc_count
++ * sizeof (Elf32_External_Rela
);
4498 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
4502 fprintf (stderr
, "\n");
4505 /* Mark some specially defined symbols as absolute. */
4506 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
4507 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0
4508 || strcmp (h
->root
.root
.string
, "_PROCEDURE_LINKAGE_TABLE_") == 0)
4509 sym
->st_shndx
= SHN_ABS
;
4514 /* Finish up the dynamic sections. */
4517 ppc_elf_finish_dynamic_sections (bfd
*output_bfd
,
4518 struct bfd_link_info
*info
)
4521 struct ppc_elf_link_hash_table
*htab
;
4524 fprintf (stderr
, "ppc_elf_finish_dynamic_sections called\n");
4527 htab
= ppc_elf_hash_table (info
);
4528 sdyn
= bfd_get_section_by_name (htab
->elf
.dynobj
, ".dynamic");
4530 if (htab
->elf
.dynamic_sections_created
)
4532 Elf32_External_Dyn
*dyncon
, *dynconend
;
4534 BFD_ASSERT (htab
->plt
!= NULL
&& sdyn
!= NULL
);
4536 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
4537 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
4538 for (; dyncon
< dynconend
; dyncon
++)
4540 Elf_Internal_Dyn dyn
;
4543 bfd_elf32_swap_dyn_in (htab
->elf
.dynobj
, dyncon
, &dyn
);
4549 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
4553 dyn
.d_un
.d_val
= htab
->relplt
->_raw_size
;
4558 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
4565 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
4569 /* Add a blrl instruction at _GLOBAL_OFFSET_TABLE_-4 so that a function can
4570 easily find the address of the _GLOBAL_OFFSET_TABLE_. */
4573 unsigned char *contents
= htab
->got
->contents
;
4574 bfd_put_32 (output_bfd
, 0x4e800021 /* blrl */, contents
);
4577 bfd_put_32 (output_bfd
, 0, contents
+ 4);
4579 bfd_put_32 (output_bfd
,
4580 sdyn
->output_section
->vma
+ sdyn
->output_offset
,
4583 elf_section_data (htab
->got
->output_section
)->this_hdr
.sh_entsize
= 4;
4589 /* The RELOCATE_SECTION function is called by the ELF backend linker
4590 to handle the relocations for a section.
4592 The relocs are always passed as Rela structures; if the section
4593 actually uses Rel structures, the r_addend field will always be
4596 This function is responsible for adjust the section contents as
4597 necessary, and (if using Rela relocs and generating a
4598 relocatable output file) adjusting the reloc addend as
4601 This function does not have to worry about setting the reloc
4602 address or the reloc symbol index.
4604 LOCAL_SYMS is a pointer to the swapped in local symbols.
4606 LOCAL_SECTIONS is an array giving the section in the input file
4607 corresponding to the st_shndx field of each local symbol.
4609 The global hash table entry for the global symbols can be found
4610 via elf_sym_hashes (input_bfd).
4612 When generating relocatable output, this function must handle
4613 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
4614 going to be the section symbol corresponding to the output
4615 section, which means that the addend must be adjusted
4619 ppc_elf_relocate_section (bfd
*output_bfd
,
4620 struct bfd_link_info
*info
,
4622 asection
*input_section
,
4624 Elf_Internal_Rela
*relocs
,
4625 Elf_Internal_Sym
*local_syms
,
4626 asection
**local_sections
)
4628 Elf_Internal_Shdr
*symtab_hdr
;
4629 struct elf_link_hash_entry
**sym_hashes
;
4630 struct ppc_elf_link_hash_table
*htab
;
4631 Elf_Internal_Rela
*rel
;
4632 Elf_Internal_Rela
*relend
;
4633 Elf_Internal_Rela outrel
;
4635 asection
*sreloc
= NULL
;
4636 bfd_vma
*local_got_offsets
;
4637 bfd_boolean ret
= TRUE
;
4640 fprintf (stderr
, "ppc_elf_relocate_section called for %s section %s, "
4641 "%ld relocations%s\n",
4642 bfd_archive_filename (input_bfd
),
4643 bfd_section_name(input_bfd
, input_section
),
4644 (long) input_section
->reloc_count
,
4645 (info
->relocatable
) ? " (relocatable)" : "");
4648 if (info
->relocatable
)
4651 /* Initialize howto table if not already done. */
4652 if (!ppc_elf_howto_table
[R_PPC_ADDR32
])
4653 ppc_elf_howto_init ();
4655 htab
= ppc_elf_hash_table (info
);
4656 local_got_offsets
= elf_local_got_offsets (input_bfd
);
4657 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
4658 sym_hashes
= elf_sym_hashes (input_bfd
);
4660 relend
= relocs
+ input_section
->reloc_count
;
4661 for (; rel
< relend
; rel
++)
4663 enum elf_ppc_reloc_type r_type
;
4665 bfd_reloc_status_type r
;
4666 Elf_Internal_Sym
*sym
;
4668 struct elf_link_hash_entry
*h
;
4669 const char *sym_name
;
4670 reloc_howto_type
*howto
;
4671 unsigned long r_symndx
;
4673 bfd_vma branch_bit
, insn
, from
;
4674 bfd_boolean unresolved_reloc
;
4676 unsigned int tls_type
, tls_mask
, tls_gd
;
4678 r_type
= ELF32_R_TYPE (rel
->r_info
);
4682 unresolved_reloc
= FALSE
;
4684 r_symndx
= ELF32_R_SYM (rel
->r_info
);
4686 if (r_symndx
< symtab_hdr
->sh_info
)
4688 sym
= local_syms
+ r_symndx
;
4689 sec
= local_sections
[r_symndx
];
4690 sym_name
= bfd_elf_local_sym_name (input_bfd
, sym
);
4692 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
4696 RELOC_FOR_GLOBAL_SYMBOL (h
, sym_hashes
, r_symndx
,
4697 symtab_hdr
, relocation
, sec
,
4698 unresolved_reloc
, info
,
4701 sym_name
= h
->root
.root
.string
;
4704 /* TLS optimizations. Replace instruction sequences and relocs
4705 based on information we collected in tls_optimize. We edit
4706 RELOCS so that --emit-relocs will output something sensible
4707 for the final instruction stream. */
4710 if (IS_PPC_TLS_RELOC (r_type
))
4713 tls_mask
= ((struct ppc_elf_link_hash_entry
*) h
)->tls_mask
;
4714 else if (local_got_offsets
!= NULL
)
4717 lgot_masks
= (char *) (local_got_offsets
+ symtab_hdr
->sh_info
);
4718 tls_mask
= lgot_masks
[r_symndx
];
4722 /* Ensure reloc mapping code below stays sane. */
4723 if ((R_PPC_GOT_TLSLD16
& 3) != (R_PPC_GOT_TLSGD16
& 3)
4724 || (R_PPC_GOT_TLSLD16_LO
& 3) != (R_PPC_GOT_TLSGD16_LO
& 3)
4725 || (R_PPC_GOT_TLSLD16_HI
& 3) != (R_PPC_GOT_TLSGD16_HI
& 3)
4726 || (R_PPC_GOT_TLSLD16_HA
& 3) != (R_PPC_GOT_TLSGD16_HA
& 3)
4727 || (R_PPC_GOT_TLSLD16
& 3) != (R_PPC_GOT_TPREL16
& 3)
4728 || (R_PPC_GOT_TLSLD16_LO
& 3) != (R_PPC_GOT_TPREL16_LO
& 3)
4729 || (R_PPC_GOT_TLSLD16_HI
& 3) != (R_PPC_GOT_TPREL16_HI
& 3)
4730 || (R_PPC_GOT_TLSLD16_HA
& 3) != (R_PPC_GOT_TPREL16_HA
& 3))
4737 case R_PPC_GOT_TPREL16
:
4738 case R_PPC_GOT_TPREL16_LO
:
4740 && (tls_mask
& TLS_TPREL
) == 0)
4743 insn
= bfd_get_32 (output_bfd
, contents
+ rel
->r_offset
- 2);
4745 insn
|= 0x3c020000; /* addis 0,2,0 */
4746 bfd_put_32 (output_bfd
, insn
, contents
+ rel
->r_offset
- 2);
4747 r_type
= R_PPC_TPREL16_HA
;
4748 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
4754 && (tls_mask
& TLS_TPREL
) == 0)
4757 insn
= bfd_get_32 (output_bfd
, contents
+ rel
->r_offset
);
4758 if ((insn
& ((31 << 26) | (31 << 11)))
4759 == ((31 << 26) | (2 << 11)))
4760 rtra
= insn
& ((1 << 26) - (1 << 16));
4761 else if ((insn
& ((31 << 26) | (31 << 16)))
4762 == ((31 << 26) | (2 << 16)))
4763 rtra
= (insn
& (31 << 21)) | ((insn
& (31 << 11)) << 5);
4766 if ((insn
& ((1 << 11) - (1 << 1))) == 266 << 1)
4769 else if ((insn
& (31 << 1)) == 23 << 1
4770 && ((insn
& (31 << 6)) < 14 << 6
4771 || ((insn
& (31 << 6)) >= 16 << 6
4772 && (insn
& (31 << 6)) < 24 << 6)))
4773 /* load and store indexed -> dform. */
4774 insn
= (32 | ((insn
>> 6) & 31)) << 26;
4775 else if ((insn
& (31 << 1)) == 21 << 1
4776 && (insn
& (0x1a << 6)) == 0)
4777 /* ldx, ldux, stdx, stdux -> ld, ldu, std, stdu. */
4778 insn
= (((58 | ((insn
>> 6) & 4)) << 26)
4779 | ((insn
>> 6) & 1));
4780 else if ((insn
& (31 << 1)) == 21 << 1
4781 && (insn
& ((1 << 11) - (1 << 1))) == 341 << 1)
4783 insn
= (58 << 26) | 2;
4787 bfd_put_32 (output_bfd
, insn
, contents
+ rel
->r_offset
);
4788 r_type
= R_PPC_TPREL16_LO
;
4789 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
4790 /* Was PPC_TLS which sits on insn boundary, now
4791 PPC_TPREL16_LO which is at insn+2. */
4796 case R_PPC_GOT_TLSGD16_HI
:
4797 case R_PPC_GOT_TLSGD16_HA
:
4798 tls_gd
= TLS_TPRELGD
;
4799 if (tls_mask
!= 0 && (tls_mask
& TLS_GD
) == 0)
4803 case R_PPC_GOT_TLSLD16_HI
:
4804 case R_PPC_GOT_TLSLD16_HA
:
4805 if (tls_mask
!= 0 && (tls_mask
& TLS_LD
) == 0)
4808 if ((tls_mask
& tls_gd
) != 0)
4809 r_type
= (((r_type
- (R_PPC_GOT_TLSGD16
& 3)) & 3)
4810 + R_PPC_GOT_TPREL16
);
4813 bfd_put_32 (output_bfd
, NOP
, contents
+ rel
->r_offset
);
4815 r_type
= R_PPC_NONE
;
4817 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
4821 case R_PPC_GOT_TLSGD16
:
4822 case R_PPC_GOT_TLSGD16_LO
:
4823 tls_gd
= TLS_TPRELGD
;
4824 if (tls_mask
!= 0 && (tls_mask
& TLS_GD
) == 0)
4825 goto tls_get_addr_check
;
4828 case R_PPC_GOT_TLSLD16
:
4829 case R_PPC_GOT_TLSLD16_LO
:
4830 if (tls_mask
!= 0 && (tls_mask
& TLS_LD
) == 0)
4833 if (rel
+ 1 < relend
)
4835 enum elf_ppc_reloc_type r_type2
;
4836 unsigned long r_symndx2
;
4837 struct elf_link_hash_entry
*h2
;
4838 bfd_vma insn1
, insn2
;
4841 /* The next instruction should be a call to
4842 __tls_get_addr. Peek at the reloc to be sure. */
4843 r_type2
= ELF32_R_TYPE (rel
[1].r_info
);
4844 r_symndx2
= ELF32_R_SYM (rel
[1].r_info
);
4845 if (r_symndx2
< symtab_hdr
->sh_info
4846 || (r_type2
!= R_PPC_REL14
4847 && r_type2
!= R_PPC_REL14_BRTAKEN
4848 && r_type2
!= R_PPC_REL14_BRNTAKEN
4849 && r_type2
!= R_PPC_REL24
4850 && r_type2
!= R_PPC_PLTREL24
))
4853 h2
= sym_hashes
[r_symndx2
- symtab_hdr
->sh_info
];
4854 while (h2
->root
.type
== bfd_link_hash_indirect
4855 || h2
->root
.type
== bfd_link_hash_warning
)
4856 h2
= (struct elf_link_hash_entry
*) h2
->root
.u
.i
.link
;
4857 if (h2
== NULL
|| h2
!= htab
->tls_get_addr
)
4860 /* OK, it checks out. Replace the call. */
4861 offset
= rel
[1].r_offset
;
4862 insn1
= bfd_get_32 (output_bfd
,
4863 contents
+ rel
->r_offset
- 2);
4864 if ((tls_mask
& tls_gd
) != 0)
4867 insn1
&= (1 << 26) - 1;
4868 insn1
|= 32 << 26; /* lwz */
4869 insn2
= 0x7c631214; /* add 3,3,2 */
4870 rel
[1].r_info
= ELF32_R_INFO (r_symndx2
, R_PPC_NONE
);
4871 r_type
= (((r_type
- (R_PPC_GOT_TLSGD16
& 3)) & 3)
4872 + R_PPC_GOT_TPREL16
);
4873 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
4878 insn1
= 0x3c620000; /* addis 3,2,0 */
4879 insn2
= 0x38630000; /* addi 3,3,0 */
4882 /* Was an LD reloc. */
4884 rel
->r_addend
= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
4885 rel
[1].r_addend
= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
4887 r_type
= R_PPC_TPREL16_HA
;
4888 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
4889 rel
[1].r_info
= ELF32_R_INFO (r_symndx
,
4891 rel
[1].r_offset
+= 2;
4893 bfd_put_32 (output_bfd
, insn1
, contents
+ rel
->r_offset
- 2);
4894 bfd_put_32 (output_bfd
, insn2
, contents
+ offset
);
4897 /* We changed the symbol on an LD reloc. Start over
4898 in order to get h, sym, sec etc. right. */
4907 /* Handle other relocations that tweak non-addend part of insn. */
4914 /* Branch taken prediction relocations. */
4915 case R_PPC_ADDR14_BRTAKEN
:
4916 case R_PPC_REL14_BRTAKEN
:
4917 branch_bit
= BRANCH_PREDICT_BIT
;
4920 /* Branch not taken predicition relocations. */
4921 case R_PPC_ADDR14_BRNTAKEN
:
4922 case R_PPC_REL14_BRNTAKEN
:
4923 insn
= bfd_get_32 (output_bfd
, contents
+ rel
->r_offset
);
4924 insn
&= ~BRANCH_PREDICT_BIT
;
4927 from
= (rel
->r_offset
4928 + input_section
->output_offset
4929 + input_section
->output_section
->vma
);
4931 /* Invert 'y' bit if not the default. */
4932 if ((bfd_signed_vma
) (relocation
+ rel
->r_addend
- from
) < 0)
4933 insn
^= BRANCH_PREDICT_BIT
;
4935 bfd_put_32 (output_bfd
, insn
, contents
+ rel
->r_offset
);
4939 addend
= rel
->r_addend
;
4942 if (r_type
< R_PPC_max
)
4943 howto
= ppc_elf_howto_table
[r_type
];
4947 (*_bfd_error_handler
)
4948 (_("%s: unknown relocation type %d for symbol %s"),
4949 bfd_archive_filename (input_bfd
), (int) r_type
, sym_name
);
4951 bfd_set_error (bfd_error_bad_value
);
4957 case R_PPC_EMB_MRKREF
:
4958 case R_PPC_GNU_VTINHERIT
:
4959 case R_PPC_GNU_VTENTRY
:
4962 /* GOT16 relocations. Like an ADDR16 using the symbol's
4963 address in the GOT as relocation value instead of the
4964 symbol's value itself. Also, create a GOT entry for the
4965 symbol and put the symbol value there. */
4966 case R_PPC_GOT_TLSGD16
:
4967 case R_PPC_GOT_TLSGD16_LO
:
4968 case R_PPC_GOT_TLSGD16_HI
:
4969 case R_PPC_GOT_TLSGD16_HA
:
4970 tls_type
= TLS_TLS
| TLS_GD
;
4973 case R_PPC_GOT_TLSLD16
:
4974 case R_PPC_GOT_TLSLD16_LO
:
4975 case R_PPC_GOT_TLSLD16_HI
:
4976 case R_PPC_GOT_TLSLD16_HA
:
4977 tls_type
= TLS_TLS
| TLS_LD
;
4980 case R_PPC_GOT_TPREL16
:
4981 case R_PPC_GOT_TPREL16_LO
:
4982 case R_PPC_GOT_TPREL16_HI
:
4983 case R_PPC_GOT_TPREL16_HA
:
4984 tls_type
= TLS_TLS
| TLS_TPREL
;
4987 case R_PPC_GOT_DTPREL16
:
4988 case R_PPC_GOT_DTPREL16_LO
:
4989 case R_PPC_GOT_DTPREL16_HI
:
4990 case R_PPC_GOT_DTPREL16_HA
:
4991 tls_type
= TLS_TLS
| TLS_DTPREL
;
4995 case R_PPC_GOT16_LO
:
4996 case R_PPC_GOT16_HI
:
4997 case R_PPC_GOT16_HA
:
5000 /* Relocation is to the entry for this symbol in the global
5006 if (htab
->got
== NULL
)
5010 if (tls_type
== (TLS_TLS
| TLS_LD
)
5012 || !(h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
)))
5013 offp
= &htab
->tlsld_got
.offset
;
5017 dyn
= htab
->elf
.dynamic_sections_created
;
5018 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
5020 && SYMBOL_REFERENCES_LOCAL (info
, h
)))
5021 /* This is actually a static link, or it is a
5022 -Bsymbolic link and the symbol is defined
5023 locally, or the symbol was forced to be local
5024 because of a version file. */
5029 unresolved_reloc
= FALSE
;
5031 offp
= &h
->got
.offset
;
5035 if (local_got_offsets
== NULL
)
5037 offp
= &local_got_offsets
[r_symndx
];
5040 /* The offset must always be a multiple of 4. We use the
5041 least significant bit to record whether we have already
5042 processed this entry. */
5048 unsigned int tls_m
= (tls_mask
5049 & (TLS_LD
| TLS_GD
| TLS_DTPREL
5050 | TLS_TPREL
| TLS_TPRELGD
));
5052 if (offp
== &htab
->tlsld_got
.offset
)
5055 || !(h
->elf_link_hash_flags
5056 & ELF_LINK_HASH_DEF_DYNAMIC
))
5059 /* We might have multiple got entries for this sym.
5060 Initialize them all. */
5065 if ((tls_m
& TLS_LD
) != 0)
5067 tls_ty
= TLS_TLS
| TLS_LD
;
5070 else if ((tls_m
& TLS_GD
) != 0)
5072 tls_ty
= TLS_TLS
| TLS_GD
;
5075 else if ((tls_m
& TLS_DTPREL
) != 0)
5077 tls_ty
= TLS_TLS
| TLS_DTPREL
;
5078 tls_m
&= ~TLS_DTPREL
;
5080 else if ((tls_m
& (TLS_TPREL
| TLS_TPRELGD
)) != 0)
5082 tls_ty
= TLS_TLS
| TLS_TPREL
;
5086 /* Generate relocs for the dynamic linker. */
5087 if ((info
->shared
|| indx
!= 0)
5089 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
5090 || h
->root
.type
!= bfd_link_hash_undefweak
))
5092 outrel
.r_offset
= (htab
->got
->output_section
->vma
5093 + htab
->got
->output_offset
5095 outrel
.r_addend
= 0;
5096 if (tls_ty
& (TLS_LD
| TLS_GD
))
5098 outrel
.r_info
= ELF32_R_INFO (indx
, R_PPC_DTPMOD32
);
5099 if (tls_ty
== (TLS_TLS
| TLS_GD
))
5101 loc
= htab
->relgot
->contents
;
5102 loc
+= (htab
->relgot
->reloc_count
++
5103 * sizeof (Elf32_External_Rela
));
5104 bfd_elf32_swap_reloca_out (output_bfd
,
5106 outrel
.r_offset
+= 4;
5108 = ELF32_R_INFO (indx
, R_PPC_DTPREL32
);
5111 else if (tls_ty
== (TLS_TLS
| TLS_DTPREL
))
5112 outrel
.r_info
= ELF32_R_INFO (indx
, R_PPC_DTPREL32
);
5113 else if (tls_ty
== (TLS_TLS
| TLS_TPREL
))
5114 outrel
.r_info
= ELF32_R_INFO (indx
, R_PPC_TPREL32
);
5116 outrel
.r_info
= ELF32_R_INFO (indx
, R_PPC_RELATIVE
);
5118 outrel
.r_info
= ELF32_R_INFO (indx
, R_PPC_GLOB_DAT
);
5121 outrel
.r_addend
+= relocation
;
5122 if (tls_ty
& (TLS_GD
| TLS_DTPREL
| TLS_TPREL
))
5123 outrel
.r_addend
-= htab
->elf
.tls_sec
->vma
;
5125 loc
= htab
->relgot
->contents
;
5126 loc
+= (htab
->relgot
->reloc_count
++
5127 * sizeof (Elf32_External_Rela
));
5128 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
5131 /* Init the .got section contents if we're not
5132 emitting a reloc. */
5135 bfd_vma value
= relocation
;
5137 if (tls_ty
== (TLS_TLS
| TLS_LD
))
5139 else if (tls_ty
!= 0)
5141 value
-= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
5142 if (tls_ty
== (TLS_TLS
| TLS_TPREL
))
5143 value
+= DTP_OFFSET
- TP_OFFSET
;
5145 if (tls_ty
== (TLS_TLS
| TLS_GD
))
5147 bfd_put_32 (output_bfd
, value
,
5148 htab
->got
->contents
+ off
+ 4);
5152 bfd_put_32 (output_bfd
, value
,
5153 htab
->got
->contents
+ off
);
5157 if (tls_ty
& (TLS_LD
| TLS_GD
))
5166 if (off
>= (bfd_vma
) -2)
5169 if ((tls_type
& TLS_TLS
) != 0)
5171 if (tls_type
!= (TLS_TLS
| TLS_LD
))
5173 if ((tls_mask
& TLS_LD
) != 0
5175 || !(h
->elf_link_hash_flags
5176 & ELF_LINK_HASH_DEF_DYNAMIC
)))
5178 if (tls_type
!= (TLS_TLS
| TLS_GD
))
5180 if ((tls_mask
& TLS_GD
) != 0)
5182 if (tls_type
!= (TLS_TLS
| TLS_DTPREL
))
5184 if ((tls_mask
& TLS_DTPREL
) != 0)
5191 relocation
= htab
->got
->output_offset
+ off
- 4;
5193 /* Addends on got relocations don't make much sense.
5194 x+off@got is actually x@got+off, and since the got is
5195 generated by a hash table traversal, the value in the
5196 got at entry m+n bears little relation to the entry m. */
5198 (*_bfd_error_handler
)
5199 (_("%s(%s+0x%lx): non-zero addend on %s reloc against `%s'"),
5200 bfd_archive_filename (input_bfd
),
5201 bfd_get_section_name (input_bfd
, input_section
),
5202 (long) rel
->r_offset
,
5208 /* Relocations that need no special processing. */
5209 case R_PPC_LOCAL24PC
:
5210 /* It makes no sense to point a local relocation
5211 at a symbol not in this object. */
5212 if (unresolved_reloc
)
5214 if (! (*info
->callbacks
->undefined_symbol
) (info
,
5215 h
->root
.root
.string
,
5225 case R_PPC_DTPREL16
:
5226 case R_PPC_DTPREL16_LO
:
5227 case R_PPC_DTPREL16_HI
:
5228 case R_PPC_DTPREL16_HA
:
5229 addend
-= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
5232 /* Relocations that may need to be propagated if this is a shared
5235 case R_PPC_TPREL16_LO
:
5236 case R_PPC_TPREL16_HI
:
5237 case R_PPC_TPREL16_HA
:
5238 addend
-= htab
->elf
.tls_sec
->vma
+ TP_OFFSET
;
5239 /* The TPREL16 relocs shouldn't really be used in shared
5240 libs as they will result in DT_TEXTREL being set, but
5241 support them anyway. */
5245 addend
-= htab
->elf
.tls_sec
->vma
+ TP_OFFSET
;
5248 case R_PPC_DTPREL32
:
5249 addend
-= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
5252 case R_PPC_DTPMOD32
:
5260 case R_PPC_REL14_BRTAKEN
:
5261 case R_PPC_REL14_BRNTAKEN
:
5262 /* If these relocations are not to a named symbol, they can be
5263 handled right here, no need to bother the dynamic linker. */
5264 if (SYMBOL_REFERENCES_LOCAL (info
, h
)
5265 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
5269 /* Relocations that always need to be propagated if this is a shared
5274 case R_PPC_ADDR16_LO
:
5275 case R_PPC_ADDR16_HI
:
5276 case R_PPC_ADDR16_HA
:
5278 case R_PPC_ADDR14_BRTAKEN
:
5279 case R_PPC_ADDR14_BRNTAKEN
:
5282 /* r_symndx will be zero only for relocs against symbols
5283 from removed linkonce sections, or sections discarded by
5292 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
5293 || h
->root
.type
!= bfd_link_hash_undefweak
)
5294 && (MUST_BE_DYN_RELOC (r_type
)
5295 || !SYMBOL_CALLS_LOCAL (info
, h
)))
5296 || (ELIMINATE_COPY_RELOCS
5298 && (input_section
->flags
& SEC_ALLOC
) != 0
5301 && (h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0
5302 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
5303 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0))
5308 fprintf (stderr
, "ppc_elf_relocate_section needs to "
5309 "create relocation for %s\n",
5310 (h
&& h
->root
.root
.string
5311 ? h
->root
.root
.string
: "<unknown>"));
5314 /* When generating a shared object, these relocations
5315 are copied into the output file to be resolved at run
5321 name
= (bfd_elf_string_from_elf_section
5323 elf_elfheader (input_bfd
)->e_shstrndx
,
5324 elf_section_data (input_section
)->rel_hdr
.sh_name
));
5328 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
5329 && strcmp (bfd_get_section_name (input_bfd
,
5333 sreloc
= bfd_get_section_by_name (htab
->elf
.dynobj
, name
);
5334 BFD_ASSERT (sreloc
!= NULL
);
5340 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
5342 if (outrel
.r_offset
== (bfd_vma
) -1
5343 || outrel
.r_offset
== (bfd_vma
) -2)
5344 skip
= (int) outrel
.r_offset
;
5345 outrel
.r_offset
+= (input_section
->output_section
->vma
5346 + input_section
->output_offset
);
5349 memset (&outrel
, 0, sizeof outrel
);
5350 else if (!SYMBOL_REFERENCES_LOCAL (info
, h
))
5352 unresolved_reloc
= FALSE
;
5353 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
5354 outrel
.r_addend
= rel
->r_addend
;
5358 outrel
.r_addend
= relocation
+ rel
->r_addend
;
5360 if (r_type
== R_PPC_ADDR32
)
5361 outrel
.r_info
= ELF32_R_INFO (0, R_PPC_RELATIVE
);
5366 if (bfd_is_abs_section (sec
))
5368 else if (sec
== NULL
|| sec
->owner
== NULL
)
5370 bfd_set_error (bfd_error_bad_value
);
5377 /* We are turning this relocation into one
5378 against a section symbol. It would be
5379 proper to subtract the symbol's value,
5380 osec->vma, from the emitted reloc addend,
5381 but ld.so expects buggy relocs. */
5382 osec
= sec
->output_section
;
5383 indx
= elf_section_data (osec
)->dynindx
;
5384 BFD_ASSERT (indx
> 0);
5387 printf ("indx=%d section=%s flags=%08x name=%s\n",
5388 indx
, osec
->name
, osec
->flags
,
5389 h
->root
.root
.string
);
5393 outrel
.r_info
= ELF32_R_INFO (indx
, r_type
);
5397 loc
= sreloc
->contents
;
5398 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rela
);
5399 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
5404 /* This reloc will be computed at runtime. We clear the memory
5405 so that it contains predictable value. */
5407 && ((input_section
->flags
& SEC_ALLOC
) != 0
5408 || ELF32_R_TYPE (outrel
.r_info
) != R_PPC_RELATIVE
))
5410 relocation
= howto
->pc_relative
? outrel
.r_offset
: 0;
5417 case R_PPC_RELAX32PC
:
5418 relocation
-= (input_section
->output_section
->vma
5419 + input_section
->output_offset
5420 + rel
->r_offset
- 4);
5427 t0
= bfd_get_32 (output_bfd
, contents
+ rel
->r_offset
);
5428 t1
= bfd_get_32 (output_bfd
, contents
+ rel
->r_offset
+ 4);
5430 /* We're clearing the bits for R_PPC_ADDR16_HA
5431 and R_PPC_ADDR16_LO here. */
5435 /* t0 is HA, t1 is LO */
5436 relocation
+= addend
;
5437 t0
|= ((relocation
+ 0x8000) >> 16) & 0xffff;
5438 t1
|= relocation
& 0xffff;
5440 bfd_put_32 (output_bfd
, t0
, contents
+ rel
->r_offset
);
5441 bfd_put_32 (output_bfd
, t1
, contents
+ rel
->r_offset
+ 4);
5445 /* Indirect .sdata relocation. */
5446 case R_PPC_EMB_SDAI16
:
5447 BFD_ASSERT (htab
->sdata
!= NULL
);
5449 = elf_finish_pointer_linker_section (output_bfd
, input_bfd
, info
,
5450 htab
->sdata
, h
, relocation
,
5451 rel
, R_PPC_RELATIVE
);
5454 /* Indirect .sdata2 relocation. */
5455 case R_PPC_EMB_SDA2I16
:
5456 BFD_ASSERT (htab
->sdata2
!= NULL
);
5458 = elf_finish_pointer_linker_section (output_bfd
, input_bfd
, info
,
5459 htab
->sdata2
, h
, relocation
,
5460 rel
, R_PPC_RELATIVE
);
5463 /* Handle the TOC16 reloc. We want to use the offset within the .got
5464 section, not the actual VMA. This is appropriate when generating
5465 an embedded ELF object, for which the .got section acts like the
5466 AIX .toc section. */
5467 case R_PPC_TOC16
: /* phony GOT16 relocations */
5468 BFD_ASSERT (sec
!= NULL
);
5469 BFD_ASSERT (bfd_is_und_section (sec
)
5470 || strcmp (bfd_get_section_name (abfd
, sec
), ".got") == 0
5471 || strcmp (bfd_get_section_name (abfd
, sec
), ".cgot") == 0)
5473 addend
-= sec
->output_section
->vma
+ sec
->output_offset
+ 0x8000;
5476 case R_PPC_PLTREL24
:
5477 /* Relocation is to the entry for this symbol in the
5478 procedure linkage table. */
5479 BFD_ASSERT (h
!= NULL
);
5481 if (h
->plt
.offset
== (bfd_vma
) -1
5482 || htab
->plt
== NULL
)
5484 /* We didn't make a PLT entry for this symbol. This
5485 happens when statically linking PIC code, or when
5486 using -Bsymbolic. */
5490 unresolved_reloc
= FALSE
;
5491 relocation
= (htab
->plt
->output_section
->vma
5492 + htab
->plt
->output_offset
5496 /* Relocate against _SDA_BASE_. */
5497 case R_PPC_SDAREL16
:
5500 const struct elf_link_hash_entry
*sh
;
5502 BFD_ASSERT (sec
!= NULL
);
5503 name
= bfd_get_section_name (abfd
, sec
->output_section
);
5504 if (! ((strncmp (name
, ".sdata", 6) == 0
5505 && (name
[6] == 0 || name
[6] == '.'))
5506 || (strncmp (name
, ".sbss", 5) == 0
5507 && (name
[5] == 0 || name
[5] == '.'))))
5509 (*_bfd_error_handler
)
5510 (_("%s: the target (%s) of a %s relocation is "
5511 "in the wrong output section (%s)"),
5512 bfd_archive_filename (input_bfd
),
5517 sh
= htab
->sdata
->sym_hash
;
5518 addend
-= (sh
->root
.u
.def
.value
5519 + sh
->root
.u
.def
.section
->output_section
->vma
5520 + sh
->root
.u
.def
.section
->output_offset
);
5524 /* Relocate against _SDA2_BASE_. */
5525 case R_PPC_EMB_SDA2REL
:
5528 const struct elf_link_hash_entry
*sh
;
5530 BFD_ASSERT (sec
!= NULL
);
5531 name
= bfd_get_section_name (abfd
, sec
->output_section
);
5532 if (! (strncmp (name
, ".sdata2", 7) == 0
5533 || strncmp (name
, ".sbss2", 6) == 0))
5535 (*_bfd_error_handler
)
5536 (_("%s: the target (%s) of a %s relocation is "
5537 "in the wrong output section (%s)"),
5538 bfd_archive_filename (input_bfd
),
5543 bfd_set_error (bfd_error_bad_value
);
5547 sh
= htab
->sdata2
->sym_hash
;
5548 addend
-= (sh
->root
.u
.def
.value
5549 + sh
->root
.u
.def
.section
->output_section
->vma
5550 + sh
->root
.u
.def
.section
->output_offset
);
5554 /* Relocate against either _SDA_BASE_, _SDA2_BASE_, or 0. */
5555 case R_PPC_EMB_SDA21
:
5556 case R_PPC_EMB_RELSDA
:
5559 const struct elf_link_hash_entry
*sh
;
5562 BFD_ASSERT (sec
!= NULL
);
5563 name
= bfd_get_section_name (abfd
, sec
->output_section
);
5564 if (((strncmp (name
, ".sdata", 6) == 0
5565 && (name
[6] == 0 || name
[6] == '.'))
5566 || (strncmp (name
, ".sbss", 5) == 0
5567 && (name
[5] == 0 || name
[5] == '.'))))
5570 sh
= htab
->sdata
->sym_hash
;
5571 addend
-= (sh
->root
.u
.def
.value
5572 + sh
->root
.u
.def
.section
->output_section
->vma
5573 + sh
->root
.u
.def
.section
->output_offset
);
5576 else if (strncmp (name
, ".sdata2", 7) == 0
5577 || strncmp (name
, ".sbss2", 6) == 0)
5580 sh
= htab
->sdata2
->sym_hash
;
5581 addend
-= (sh
->root
.u
.def
.value
5582 + sh
->root
.u
.def
.section
->output_section
->vma
5583 + sh
->root
.u
.def
.section
->output_offset
);
5586 else if (strcmp (name
, ".PPC.EMB.sdata0") == 0
5587 || strcmp (name
, ".PPC.EMB.sbss0") == 0)
5594 (*_bfd_error_handler
)
5595 (_("%s: the target (%s) of a %s relocation is "
5596 "in the wrong output section (%s)"),
5597 bfd_archive_filename (input_bfd
),
5602 bfd_set_error (bfd_error_bad_value
);
5607 if (r_type
== R_PPC_EMB_SDA21
)
5608 { /* fill in register field */
5609 insn
= bfd_get_32 (output_bfd
, contents
+ rel
->r_offset
);
5610 insn
= (insn
& ~RA_REGISTER_MASK
) | (reg
<< RA_REGISTER_SHIFT
);
5611 bfd_put_32 (output_bfd
, insn
, contents
+ rel
->r_offset
);
5616 /* Relocate against the beginning of the section. */
5618 case R_PPC_SECTOFF_LO
:
5619 case R_PPC_SECTOFF_HI
:
5620 case R_PPC_SECTOFF_HA
:
5621 BFD_ASSERT (sec
!= NULL
);
5622 addend
-= sec
->output_section
->vma
;
5625 /* Negative relocations. */
5626 case R_PPC_EMB_NADDR32
:
5627 case R_PPC_EMB_NADDR16
:
5628 case R_PPC_EMB_NADDR16_LO
:
5629 case R_PPC_EMB_NADDR16_HI
:
5630 case R_PPC_EMB_NADDR16_HA
:
5631 addend
-= 2 * relocation
;
5635 case R_PPC_GLOB_DAT
:
5636 case R_PPC_JMP_SLOT
:
5637 case R_PPC_RELATIVE
:
5639 case R_PPC_PLTREL32
:
5640 case R_PPC_PLT16_LO
:
5641 case R_PPC_PLT16_HI
:
5642 case R_PPC_PLT16_HA
:
5644 case R_PPC_EMB_RELSEC16
:
5645 case R_PPC_EMB_RELST_LO
:
5646 case R_PPC_EMB_RELST_HI
:
5647 case R_PPC_EMB_RELST_HA
:
5648 case R_PPC_EMB_BIT_FLD
:
5649 (*_bfd_error_handler
)
5650 (_("%s: relocation %s is not yet supported for symbol %s."),
5651 bfd_archive_filename (input_bfd
),
5655 bfd_set_error (bfd_error_invalid_operation
);
5660 /* Do any further special processing. */
5666 case R_PPC_ADDR16_HA
:
5667 case R_PPC_GOT16_HA
:
5668 case R_PPC_PLT16_HA
:
5669 case R_PPC_SECTOFF_HA
:
5670 case R_PPC_TPREL16_HA
:
5671 case R_PPC_DTPREL16_HA
:
5672 case R_PPC_GOT_TLSGD16_HA
:
5673 case R_PPC_GOT_TLSLD16_HA
:
5674 case R_PPC_GOT_TPREL16_HA
:
5675 case R_PPC_GOT_DTPREL16_HA
:
5676 case R_PPC_EMB_NADDR16_HA
:
5677 case R_PPC_EMB_RELST_HA
:
5678 /* It's just possible that this symbol is a weak symbol
5679 that's not actually defined anywhere. In that case,
5680 'sec' would be NULL, and we should leave the symbol
5681 alone (it will be set to zero elsewhere in the link). */
5683 /* Add 0x10000 if sign bit in 0:15 is set.
5684 Bits 0:15 are not used. */
5690 fprintf (stderr
, "\ttype = %s (%d), name = %s, symbol index = %ld, "
5691 "offset = %ld, addend = %ld\n",
5696 (long) rel
->r_offset
,
5700 if (unresolved_reloc
5701 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
5702 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0))
5704 (*_bfd_error_handler
)
5705 (_("%s(%s+0x%lx): unresolvable %s relocation against symbol `%s'"),
5706 bfd_archive_filename (input_bfd
),
5707 bfd_get_section_name (input_bfd
, input_section
),
5708 (long) rel
->r_offset
,
5714 r
= _bfd_final_link_relocate (howto
,
5722 if (r
!= bfd_reloc_ok
)
5724 if (sym_name
== NULL
)
5725 sym_name
= "(null)";
5726 if (r
== bfd_reloc_overflow
)
5731 && h
->root
.type
== bfd_link_hash_undefweak
5732 && howto
->pc_relative
)
5734 /* Assume this is a call protected by other code that
5735 detect the symbol is undefined. If this is the case,
5736 we can safely ignore the overflow. If not, the
5737 program is hosed anyway, and a little warning isn't
5743 if (! (*info
->callbacks
->reloc_overflow
) (info
,
5754 (*_bfd_error_handler
)
5755 (_("%s(%s+0x%lx): %s reloc against `%s': error %d"),
5756 bfd_archive_filename (input_bfd
),
5757 bfd_get_section_name (input_bfd
, input_section
),
5758 (long) rel
->r_offset
, howto
->name
, sym_name
, (int) r
);
5765 fprintf (stderr
, "\n");
5771 static enum elf_reloc_type_class
5772 ppc_elf_reloc_type_class (const Elf_Internal_Rela
*rela
)
5774 switch (ELF32_R_TYPE (rela
->r_info
))
5776 case R_PPC_RELATIVE
:
5777 return reloc_class_relative
;
5780 case R_PPC_JMP_SLOT
:
5781 return reloc_class_plt
;
5783 return reloc_class_copy
;
5785 return reloc_class_normal
;
5789 /* Support for core dump NOTE sections. */
5792 ppc_elf_grok_prstatus (bfd
*abfd
, Elf_Internal_Note
*note
)
5795 unsigned int raw_size
;
5797 switch (note
->descsz
)
5802 case 268: /* Linux/PPC. */
5804 elf_tdata (abfd
)->core_signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
5807 elf_tdata (abfd
)->core_pid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
5816 /* Make a ".reg/999" section. */
5817 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
5818 raw_size
, note
->descpos
+ offset
);
5822 ppc_elf_grok_psinfo (bfd
*abfd
, Elf_Internal_Note
*note
)
5824 switch (note
->descsz
)
5829 case 128: /* Linux/PPC elf_prpsinfo. */
5830 elf_tdata (abfd
)->core_program
5831 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 32, 16);
5832 elf_tdata (abfd
)->core_command
5833 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 48, 80);
5836 /* Note that for some reason, a spurious space is tacked
5837 onto the end of the args in some (at least one anyway)
5838 implementations, so strip it off if it exists. */
5841 char *command
= elf_tdata (abfd
)->core_command
;
5842 int n
= strlen (command
);
5844 if (0 < n
&& command
[n
- 1] == ' ')
5845 command
[n
- 1] = '\0';
5851 /* Very simple linked list structure for recording apuinfo values. */
5852 typedef struct apuinfo_list
5854 struct apuinfo_list
*next
;
5855 unsigned long value
;
5859 static apuinfo_list
*head
;
5863 apuinfo_list_init (void)
5869 apuinfo_list_add (unsigned long value
)
5871 apuinfo_list
*entry
= head
;
5873 while (entry
!= NULL
)
5875 if (entry
->value
== value
)
5877 entry
= entry
->next
;
5880 entry
= bfd_malloc (sizeof (* entry
));
5884 entry
->value
= value
;
5890 apuinfo_list_length (void)
5892 apuinfo_list
*entry
;
5893 unsigned long count
;
5895 for (entry
= head
, count
= 0;
5897 entry
= entry
->next
)
5903 static inline unsigned long
5904 apuinfo_list_element (unsigned long number
)
5906 apuinfo_list
* entry
;
5910 entry
= entry
->next
)
5913 return entry
? entry
->value
: 0;
5917 apuinfo_list_finish (void)
5919 apuinfo_list
*entry
;
5921 for (entry
= head
; entry
;)
5923 apuinfo_list
*next
= entry
->next
;
5931 #define APUINFO_SECTION_NAME ".PPC.EMB.apuinfo"
5932 #define APUINFO_LABEL "APUinfo"
5934 /* Scan the input BFDs and create a linked list of
5935 the APUinfo values that will need to be emitted. */
5938 ppc_elf_begin_write_processing (bfd
*abfd
, struct bfd_link_info
*link_info
)
5943 unsigned num_input_sections
;
5944 bfd_size_type output_section_size
;
5946 unsigned num_entries
;
5947 unsigned long offset
;
5948 unsigned long length
;
5949 const char *error_message
= NULL
;
5951 if (link_info
== NULL
)
5954 /* Scan the input bfds, looking for apuinfo sections. */
5955 num_input_sections
= 0;
5956 output_section_size
= 0;
5958 for (ibfd
= link_info
->input_bfds
; ibfd
; ibfd
= ibfd
->link_next
)
5960 asec
= bfd_get_section_by_name (ibfd
, APUINFO_SECTION_NAME
);
5963 ++ num_input_sections
;
5964 output_section_size
+= asec
->_raw_size
;
5968 /* We need at least one input sections
5969 in order to make merging worthwhile. */
5970 if (num_input_sections
< 1)
5973 /* Just make sure that the output section exists as well. */
5974 asec
= bfd_get_section_by_name (abfd
, APUINFO_SECTION_NAME
);
5978 /* Allocate a buffer for the contents of the input sections. */
5979 buffer
= bfd_malloc (output_section_size
);
5984 apuinfo_list_init ();
5986 /* Read in the input sections contents. */
5987 for (ibfd
= link_info
->input_bfds
; ibfd
; ibfd
= ibfd
->link_next
)
5989 unsigned long datum
;
5992 asec
= bfd_get_section_by_name (ibfd
, APUINFO_SECTION_NAME
);
5996 length
= asec
->_raw_size
;
5999 error_message
= _("corrupt or empty %s section in %s");
6003 if (bfd_seek (ibfd
, asec
->filepos
, SEEK_SET
) != 0
6004 || (bfd_bread (buffer
+ offset
, length
, ibfd
) != length
))
6006 error_message
= _("unable to read in %s section from %s");
6010 /* Process the contents of the section. */
6011 ptr
= buffer
+ offset
;
6012 error_message
= _("corrupt %s section in %s");
6014 /* Verify the contents of the header. Note - we have to
6015 extract the values this way in order to allow for a
6016 host whose endian-ness is different from the target. */
6017 datum
= bfd_get_32 (ibfd
, ptr
);
6018 if (datum
!= sizeof APUINFO_LABEL
)
6021 datum
= bfd_get_32 (ibfd
, ptr
+ 8);
6025 if (strcmp (ptr
+ 12, APUINFO_LABEL
) != 0)
6028 /* Get the number of bytes used for apuinfo entries. */
6029 datum
= bfd_get_32 (ibfd
, ptr
+ 4);
6030 if (datum
+ 20 != length
)
6033 /* Make sure that we do not run off the end of the section. */
6034 if (offset
+ length
> output_section_size
)
6037 /* Scan the apuinfo section, building a list of apuinfo numbers. */
6038 for (i
= 0; i
< datum
; i
+= 4)
6039 apuinfo_list_add (bfd_get_32 (ibfd
, ptr
+ 20 + i
));
6041 /* Update the offset. */
6045 error_message
= NULL
;
6047 /* Compute the size of the output section. */
6048 num_entries
= apuinfo_list_length ();
6049 output_section_size
= 20 + num_entries
* 4;
6051 asec
= bfd_get_section_by_name (abfd
, APUINFO_SECTION_NAME
);
6053 if (! bfd_set_section_size (abfd
, asec
, output_section_size
))
6055 error_message
= _("warning: unable to set size of %s section in %s");
6061 (*_bfd_error_handler
) (error_message
, APUINFO_SECTION_NAME
,
6062 bfd_archive_filename (ibfd
));
6066 /* Prevent the output section from accumulating the input sections'
6067 contents. We have already stored this in our linked list structure. */
6070 ppc_elf_write_section (bfd
*abfd ATTRIBUTE_UNUSED
,
6072 bfd_byte
*contents ATTRIBUTE_UNUSED
)
6074 return (apuinfo_list_length ()
6075 && strcmp (asec
->name
, APUINFO_SECTION_NAME
) == 0);
6079 /* Finally we can generate the output section. */
6082 ppc_elf_final_write_processing (bfd
*abfd
, bfd_boolean linker ATTRIBUTE_UNUSED
)
6087 unsigned num_entries
;
6088 bfd_size_type length
;
6090 asec
= bfd_get_section_by_name (abfd
, APUINFO_SECTION_NAME
);
6094 if (apuinfo_list_length () == 0)
6097 length
= asec
->_raw_size
;
6101 buffer
= bfd_malloc (length
);
6104 (*_bfd_error_handler
)
6105 (_("failed to allocate space for new APUinfo section."));
6109 /* Create the apuinfo header. */
6110 num_entries
= apuinfo_list_length ();
6111 bfd_put_32 (abfd
, sizeof APUINFO_LABEL
, buffer
);
6112 bfd_put_32 (abfd
, num_entries
* 4, buffer
+ 4);
6113 bfd_put_32 (abfd
, 0x2, buffer
+ 8);
6114 strcpy (buffer
+ 12, APUINFO_LABEL
);
6117 for (i
= 0; i
< num_entries
; i
++)
6119 bfd_put_32 (abfd
, apuinfo_list_element (i
), buffer
+ length
);
6123 if (length
!= asec
->_raw_size
)
6124 (*_bfd_error_handler
) (_("failed to compute new APUinfo section."));
6126 if (! bfd_set_section_contents (abfd
, asec
, buffer
, (file_ptr
) 0, length
))
6127 (*_bfd_error_handler
) (_("failed to install new APUinfo section."));
6131 apuinfo_list_finish ();
6134 /* Add extra PPC sections -- Note, for now, make .sbss2 and
6135 .PPC.EMB.sbss0 a normal section, and not a bss section so
6136 that the linker doesn't crater when trying to make more than
6139 static struct bfd_elf_special_section
const ppc_elf_special_sections
[]=
6141 { ".tags", 5, 0, SHT_ORDERED
, SHF_ALLOC
},
6142 { ".sdata", 6, -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
6143 { ".sbss", 5, -2, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
},
6144 { ".sdata2", 7, -2, SHT_PROGBITS
, SHF_ALLOC
},
6145 { ".sbss2", 6, -2, SHT_PROGBITS
, SHF_ALLOC
},
6146 { ".PPC.EMB.apuinfo", 16, 0, SHT_NOTE
, 0 },
6147 { ".PPC.EMB.sdata0", 15, 0, SHT_PROGBITS
, SHF_ALLOC
},
6148 { ".PPC.EMB.sbss0", 14, 0, SHT_PROGBITS
, SHF_ALLOC
},
6149 { ".plt", 4, 0, SHT_NOBITS
, SHF_ALLOC
+ SHF_EXECINSTR
},
6150 { NULL
, 0, 0, 0, 0 }
6153 #define TARGET_LITTLE_SYM bfd_elf32_powerpcle_vec
6154 #define TARGET_LITTLE_NAME "elf32-powerpcle"
6155 #define TARGET_BIG_SYM bfd_elf32_powerpc_vec
6156 #define TARGET_BIG_NAME "elf32-powerpc"
6157 #define ELF_ARCH bfd_arch_powerpc
6158 #define ELF_MACHINE_CODE EM_PPC
6159 #ifdef __QNXTARGET__
6160 #define ELF_MAXPAGESIZE 0x1000
6162 #define ELF_MAXPAGESIZE 0x10000
6164 #define elf_info_to_howto ppc_elf_info_to_howto
6166 #ifdef EM_CYGNUS_POWERPC
6167 #define ELF_MACHINE_ALT1 EM_CYGNUS_POWERPC
6171 #define ELF_MACHINE_ALT2 EM_PPC_OLD
6174 #define elf_backend_plt_not_loaded 1
6175 #define elf_backend_got_symbol_offset 4
6176 #define elf_backend_can_gc_sections 1
6177 #define elf_backend_can_refcount 1
6178 #define elf_backend_got_header_size 12
6179 #define elf_backend_rela_normal 1
6181 #define bfd_elf32_mkobject ppc_elf_mkobject
6182 #define bfd_elf32_bfd_merge_private_bfd_data ppc_elf_merge_private_bfd_data
6183 #define bfd_elf32_bfd_relax_section ppc_elf_relax_section
6184 #define bfd_elf32_bfd_reloc_type_lookup ppc_elf_reloc_type_lookup
6185 #define bfd_elf32_bfd_set_private_flags ppc_elf_set_private_flags
6186 #define bfd_elf32_bfd_link_hash_table_create ppc_elf_link_hash_table_create
6188 #define elf_backend_object_p ppc_elf_object_p
6189 #define elf_backend_gc_mark_hook ppc_elf_gc_mark_hook
6190 #define elf_backend_gc_sweep_hook ppc_elf_gc_sweep_hook
6191 #define elf_backend_section_from_shdr ppc_elf_section_from_shdr
6192 #define elf_backend_relocate_section ppc_elf_relocate_section
6193 #define elf_backend_create_dynamic_sections ppc_elf_create_dynamic_sections
6194 #define elf_backend_check_relocs ppc_elf_check_relocs
6195 #define elf_backend_copy_indirect_symbol ppc_elf_copy_indirect_symbol
6196 #define elf_backend_adjust_dynamic_symbol ppc_elf_adjust_dynamic_symbol
6197 #define elf_backend_add_symbol_hook ppc_elf_add_symbol_hook
6198 #define elf_backend_size_dynamic_sections ppc_elf_size_dynamic_sections
6199 #define elf_backend_finish_dynamic_symbol ppc_elf_finish_dynamic_symbol
6200 #define elf_backend_finish_dynamic_sections ppc_elf_finish_dynamic_sections
6201 #define elf_backend_fake_sections ppc_elf_fake_sections
6202 #define elf_backend_additional_program_headers ppc_elf_additional_program_headers
6203 #define elf_backend_modify_segment_map ppc_elf_modify_segment_map
6204 #define elf_backend_grok_prstatus ppc_elf_grok_prstatus
6205 #define elf_backend_grok_psinfo ppc_elf_grok_psinfo
6206 #define elf_backend_reloc_type_class ppc_elf_reloc_type_class
6207 #define elf_backend_begin_write_processing ppc_elf_begin_write_processing
6208 #define elf_backend_final_write_processing ppc_elf_final_write_processing
6209 #define elf_backend_write_section ppc_elf_write_section
6210 #define elf_backend_special_sections ppc_elf_special_sections
6212 #include "elf32-target.h"