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
340 | ELF_LINK_HASH_NEEDS_PLT
));
342 _bfd_elf_link_hash_copy_indirect (bed
, dir
, ind
);
345 static reloc_howto_type
*ppc_elf_howto_table
[R_PPC_max
];
347 static reloc_howto_type ppc_elf_howto_raw
[] = {
348 /* This reloc does nothing. */
349 HOWTO (R_PPC_NONE
, /* type */
351 2, /* size (0 = byte, 1 = short, 2 = long) */
353 FALSE
, /* pc_relative */
355 complain_overflow_bitfield
, /* complain_on_overflow */
356 bfd_elf_generic_reloc
, /* special_function */
357 "R_PPC_NONE", /* name */
358 FALSE
, /* partial_inplace */
361 FALSE
), /* pcrel_offset */
363 /* A standard 32 bit relocation. */
364 HOWTO (R_PPC_ADDR32
, /* type */
366 2, /* size (0 = byte, 1 = short, 2 = long) */
368 FALSE
, /* pc_relative */
370 complain_overflow_bitfield
, /* complain_on_overflow */
371 bfd_elf_generic_reloc
, /* special_function */
372 "R_PPC_ADDR32", /* name */
373 FALSE
, /* partial_inplace */
375 0xffffffff, /* dst_mask */
376 FALSE
), /* pcrel_offset */
378 /* An absolute 26 bit branch; the lower two bits must be zero.
379 FIXME: we don't check that, we just clear them. */
380 HOWTO (R_PPC_ADDR24
, /* type */
382 2, /* size (0 = byte, 1 = short, 2 = long) */
384 FALSE
, /* pc_relative */
386 complain_overflow_bitfield
, /* complain_on_overflow */
387 bfd_elf_generic_reloc
, /* special_function */
388 "R_PPC_ADDR24", /* name */
389 FALSE
, /* partial_inplace */
391 0x3fffffc, /* dst_mask */
392 FALSE
), /* pcrel_offset */
394 /* A standard 16 bit relocation. */
395 HOWTO (R_PPC_ADDR16
, /* type */
397 1, /* size (0 = byte, 1 = short, 2 = long) */
399 FALSE
, /* pc_relative */
401 complain_overflow_bitfield
, /* complain_on_overflow */
402 bfd_elf_generic_reloc
, /* special_function */
403 "R_PPC_ADDR16", /* name */
404 FALSE
, /* partial_inplace */
406 0xffff, /* dst_mask */
407 FALSE
), /* pcrel_offset */
409 /* A 16 bit relocation without overflow. */
410 HOWTO (R_PPC_ADDR16_LO
, /* type */
412 1, /* size (0 = byte, 1 = short, 2 = long) */
414 FALSE
, /* pc_relative */
416 complain_overflow_dont
,/* complain_on_overflow */
417 bfd_elf_generic_reloc
, /* special_function */
418 "R_PPC_ADDR16_LO", /* name */
419 FALSE
, /* partial_inplace */
421 0xffff, /* dst_mask */
422 FALSE
), /* pcrel_offset */
424 /* The high order 16 bits of an address. */
425 HOWTO (R_PPC_ADDR16_HI
, /* type */
427 1, /* size (0 = byte, 1 = short, 2 = long) */
429 FALSE
, /* pc_relative */
431 complain_overflow_dont
, /* complain_on_overflow */
432 bfd_elf_generic_reloc
, /* special_function */
433 "R_PPC_ADDR16_HI", /* name */
434 FALSE
, /* partial_inplace */
436 0xffff, /* dst_mask */
437 FALSE
), /* pcrel_offset */
439 /* The high order 16 bits of an address, plus 1 if the contents of
440 the low 16 bits, treated as a signed number, is negative. */
441 HOWTO (R_PPC_ADDR16_HA
, /* type */
443 1, /* size (0 = byte, 1 = short, 2 = long) */
445 FALSE
, /* pc_relative */
447 complain_overflow_dont
, /* complain_on_overflow */
448 ppc_elf_addr16_ha_reloc
, /* special_function */
449 "R_PPC_ADDR16_HA", /* name */
450 FALSE
, /* partial_inplace */
452 0xffff, /* dst_mask */
453 FALSE
), /* pcrel_offset */
455 /* An absolute 16 bit branch; the lower two bits must be zero.
456 FIXME: we don't check that, we just clear them. */
457 HOWTO (R_PPC_ADDR14
, /* type */
459 2, /* size (0 = byte, 1 = short, 2 = long) */
461 FALSE
, /* pc_relative */
463 complain_overflow_bitfield
, /* complain_on_overflow */
464 bfd_elf_generic_reloc
, /* special_function */
465 "R_PPC_ADDR14", /* name */
466 FALSE
, /* partial_inplace */
468 0xfffc, /* dst_mask */
469 FALSE
), /* pcrel_offset */
471 /* An absolute 16 bit branch, for which bit 10 should be set to
472 indicate that the branch is expected to be taken. The lower two
473 bits must be zero. */
474 HOWTO (R_PPC_ADDR14_BRTAKEN
, /* type */
476 2, /* size (0 = byte, 1 = short, 2 = long) */
478 FALSE
, /* pc_relative */
480 complain_overflow_bitfield
, /* complain_on_overflow */
481 bfd_elf_generic_reloc
, /* special_function */
482 "R_PPC_ADDR14_BRTAKEN",/* name */
483 FALSE
, /* partial_inplace */
485 0xfffc, /* dst_mask */
486 FALSE
), /* pcrel_offset */
488 /* An absolute 16 bit branch, for which bit 10 should be set to
489 indicate that the branch is not expected to be taken. The lower
490 two bits must be zero. */
491 HOWTO (R_PPC_ADDR14_BRNTAKEN
, /* type */
493 2, /* size (0 = byte, 1 = short, 2 = long) */
495 FALSE
, /* pc_relative */
497 complain_overflow_bitfield
, /* complain_on_overflow */
498 bfd_elf_generic_reloc
, /* special_function */
499 "R_PPC_ADDR14_BRNTAKEN",/* name */
500 FALSE
, /* partial_inplace */
502 0xfffc, /* dst_mask */
503 FALSE
), /* pcrel_offset */
505 /* A relative 26 bit branch; the lower two bits must be zero. */
506 HOWTO (R_PPC_REL24
, /* type */
508 2, /* size (0 = byte, 1 = short, 2 = long) */
510 TRUE
, /* pc_relative */
512 complain_overflow_signed
, /* complain_on_overflow */
513 bfd_elf_generic_reloc
, /* special_function */
514 "R_PPC_REL24", /* name */
515 FALSE
, /* partial_inplace */
517 0x3fffffc, /* dst_mask */
518 TRUE
), /* pcrel_offset */
520 /* A relative 16 bit branch; the lower two bits must be zero. */
521 HOWTO (R_PPC_REL14
, /* type */
523 2, /* size (0 = byte, 1 = short, 2 = long) */
525 TRUE
, /* pc_relative */
527 complain_overflow_signed
, /* complain_on_overflow */
528 bfd_elf_generic_reloc
, /* special_function */
529 "R_PPC_REL14", /* name */
530 FALSE
, /* partial_inplace */
532 0xfffc, /* dst_mask */
533 TRUE
), /* pcrel_offset */
535 /* A relative 16 bit branch. Bit 10 should be set to indicate that
536 the branch is expected to be taken. The lower two bits must be
538 HOWTO (R_PPC_REL14_BRTAKEN
, /* type */
540 2, /* size (0 = byte, 1 = short, 2 = long) */
542 TRUE
, /* pc_relative */
544 complain_overflow_signed
, /* complain_on_overflow */
545 bfd_elf_generic_reloc
, /* special_function */
546 "R_PPC_REL14_BRTAKEN", /* name */
547 FALSE
, /* partial_inplace */
549 0xfffc, /* dst_mask */
550 TRUE
), /* pcrel_offset */
552 /* A relative 16 bit branch. Bit 10 should be set to indicate that
553 the branch is not expected to be taken. The lower two bits must
555 HOWTO (R_PPC_REL14_BRNTAKEN
, /* type */
557 2, /* size (0 = byte, 1 = short, 2 = long) */
559 TRUE
, /* pc_relative */
561 complain_overflow_signed
, /* complain_on_overflow */
562 bfd_elf_generic_reloc
, /* special_function */
563 "R_PPC_REL14_BRNTAKEN",/* name */
564 FALSE
, /* partial_inplace */
566 0xfffc, /* dst_mask */
567 TRUE
), /* pcrel_offset */
569 /* Like R_PPC_ADDR16, but referring to the GOT table entry for the
571 HOWTO (R_PPC_GOT16
, /* type */
573 1, /* size (0 = byte, 1 = short, 2 = long) */
575 FALSE
, /* pc_relative */
577 complain_overflow_signed
, /* complain_on_overflow */
578 bfd_elf_generic_reloc
, /* special_function */
579 "R_PPC_GOT16", /* name */
580 FALSE
, /* partial_inplace */
582 0xffff, /* dst_mask */
583 FALSE
), /* pcrel_offset */
585 /* Like R_PPC_ADDR16_LO, but referring to the GOT table entry for
587 HOWTO (R_PPC_GOT16_LO
, /* type */
589 1, /* size (0 = byte, 1 = short, 2 = long) */
591 FALSE
, /* pc_relative */
593 complain_overflow_dont
, /* complain_on_overflow */
594 bfd_elf_generic_reloc
, /* special_function */
595 "R_PPC_GOT16_LO", /* name */
596 FALSE
, /* partial_inplace */
598 0xffff, /* dst_mask */
599 FALSE
), /* pcrel_offset */
601 /* Like R_PPC_ADDR16_HI, but referring to the GOT table entry for
603 HOWTO (R_PPC_GOT16_HI
, /* type */
605 1, /* size (0 = byte, 1 = short, 2 = long) */
607 FALSE
, /* pc_relative */
609 complain_overflow_bitfield
, /* complain_on_overflow */
610 bfd_elf_generic_reloc
, /* special_function */
611 "R_PPC_GOT16_HI", /* name */
612 FALSE
, /* partial_inplace */
614 0xffff, /* dst_mask */
615 FALSE
), /* pcrel_offset */
617 /* Like R_PPC_ADDR16_HA, but referring to the GOT table entry for
619 HOWTO (R_PPC_GOT16_HA
, /* type */
621 1, /* size (0 = byte, 1 = short, 2 = long) */
623 FALSE
, /* pc_relative */
625 complain_overflow_bitfield
, /* complain_on_overflow */
626 ppc_elf_addr16_ha_reloc
, /* special_function */
627 "R_PPC_GOT16_HA", /* name */
628 FALSE
, /* partial_inplace */
630 0xffff, /* dst_mask */
631 FALSE
), /* pcrel_offset */
633 /* Like R_PPC_REL24, but referring to the procedure linkage table
634 entry for the symbol. */
635 HOWTO (R_PPC_PLTREL24
, /* type */
637 2, /* size (0 = byte, 1 = short, 2 = long) */
639 TRUE
, /* pc_relative */
641 complain_overflow_signed
, /* complain_on_overflow */
642 bfd_elf_generic_reloc
, /* special_function */
643 "R_PPC_PLTREL24", /* name */
644 FALSE
, /* partial_inplace */
646 0x3fffffc, /* dst_mask */
647 TRUE
), /* pcrel_offset */
649 /* This is used only by the dynamic linker. The symbol should exist
650 both in the object being run and in some shared library. The
651 dynamic linker copies the data addressed by the symbol from the
652 shared library into the object, because the object being
653 run has to have the data at some particular address. */
654 HOWTO (R_PPC_COPY
, /* type */
656 2, /* size (0 = byte, 1 = short, 2 = long) */
658 FALSE
, /* pc_relative */
660 complain_overflow_bitfield
, /* complain_on_overflow */
661 bfd_elf_generic_reloc
, /* special_function */
662 "R_PPC_COPY", /* name */
663 FALSE
, /* partial_inplace */
666 FALSE
), /* pcrel_offset */
668 /* Like R_PPC_ADDR32, but used when setting global offset table
670 HOWTO (R_PPC_GLOB_DAT
, /* type */
672 2, /* size (0 = byte, 1 = short, 2 = long) */
674 FALSE
, /* pc_relative */
676 complain_overflow_bitfield
, /* complain_on_overflow */
677 bfd_elf_generic_reloc
, /* special_function */
678 "R_PPC_GLOB_DAT", /* name */
679 FALSE
, /* partial_inplace */
681 0xffffffff, /* dst_mask */
682 FALSE
), /* pcrel_offset */
684 /* Marks a procedure linkage table entry for a symbol. */
685 HOWTO (R_PPC_JMP_SLOT
, /* type */
687 2, /* size (0 = byte, 1 = short, 2 = long) */
689 FALSE
, /* pc_relative */
691 complain_overflow_bitfield
, /* complain_on_overflow */
692 bfd_elf_generic_reloc
, /* special_function */
693 "R_PPC_JMP_SLOT", /* name */
694 FALSE
, /* partial_inplace */
697 FALSE
), /* pcrel_offset */
699 /* Used only by the dynamic linker. When the object is run, this
700 longword is set to the load address of the object, plus the
702 HOWTO (R_PPC_RELATIVE
, /* type */
704 2, /* size (0 = byte, 1 = short, 2 = long) */
706 FALSE
, /* pc_relative */
708 complain_overflow_bitfield
, /* complain_on_overflow */
709 bfd_elf_generic_reloc
, /* special_function */
710 "R_PPC_RELATIVE", /* name */
711 FALSE
, /* partial_inplace */
713 0xffffffff, /* dst_mask */
714 FALSE
), /* pcrel_offset */
716 /* Like R_PPC_REL24, but uses the value of the symbol within the
717 object rather than the final value. Normally used for
718 _GLOBAL_OFFSET_TABLE_. */
719 HOWTO (R_PPC_LOCAL24PC
, /* type */
721 2, /* size (0 = byte, 1 = short, 2 = long) */
723 TRUE
, /* pc_relative */
725 complain_overflow_signed
, /* complain_on_overflow */
726 bfd_elf_generic_reloc
, /* special_function */
727 "R_PPC_LOCAL24PC", /* name */
728 FALSE
, /* partial_inplace */
730 0x3fffffc, /* dst_mask */
731 TRUE
), /* pcrel_offset */
733 /* Like R_PPC_ADDR32, but may be unaligned. */
734 HOWTO (R_PPC_UADDR32
, /* type */
736 2, /* size (0 = byte, 1 = short, 2 = long) */
738 FALSE
, /* pc_relative */
740 complain_overflow_bitfield
, /* complain_on_overflow */
741 bfd_elf_generic_reloc
, /* special_function */
742 "R_PPC_UADDR32", /* name */
743 FALSE
, /* partial_inplace */
745 0xffffffff, /* dst_mask */
746 FALSE
), /* pcrel_offset */
748 /* Like R_PPC_ADDR16, but may be unaligned. */
749 HOWTO (R_PPC_UADDR16
, /* type */
751 1, /* size (0 = byte, 1 = short, 2 = long) */
753 FALSE
, /* pc_relative */
755 complain_overflow_bitfield
, /* complain_on_overflow */
756 bfd_elf_generic_reloc
, /* special_function */
757 "R_PPC_UADDR16", /* name */
758 FALSE
, /* partial_inplace */
760 0xffff, /* dst_mask */
761 FALSE
), /* pcrel_offset */
763 /* 32-bit PC relative */
764 HOWTO (R_PPC_REL32
, /* type */
766 2, /* size (0 = byte, 1 = short, 2 = long) */
768 TRUE
, /* pc_relative */
770 complain_overflow_bitfield
, /* complain_on_overflow */
771 bfd_elf_generic_reloc
, /* special_function */
772 "R_PPC_REL32", /* name */
773 FALSE
, /* partial_inplace */
775 0xffffffff, /* dst_mask */
776 TRUE
), /* pcrel_offset */
778 /* 32-bit relocation to the symbol's procedure linkage table.
779 FIXME: not supported. */
780 HOWTO (R_PPC_PLT32
, /* type */
782 2, /* size (0 = byte, 1 = short, 2 = long) */
784 FALSE
, /* pc_relative */
786 complain_overflow_bitfield
, /* complain_on_overflow */
787 bfd_elf_generic_reloc
, /* special_function */
788 "R_PPC_PLT32", /* name */
789 FALSE
, /* partial_inplace */
792 FALSE
), /* pcrel_offset */
794 /* 32-bit PC relative relocation to the symbol's procedure linkage table.
795 FIXME: not supported. */
796 HOWTO (R_PPC_PLTREL32
, /* type */
798 2, /* size (0 = byte, 1 = short, 2 = long) */
800 TRUE
, /* pc_relative */
802 complain_overflow_bitfield
, /* complain_on_overflow */
803 bfd_elf_generic_reloc
, /* special_function */
804 "R_PPC_PLTREL32", /* name */
805 FALSE
, /* partial_inplace */
808 TRUE
), /* pcrel_offset */
810 /* Like R_PPC_ADDR16_LO, but referring to the PLT table entry for
812 HOWTO (R_PPC_PLT16_LO
, /* type */
814 1, /* size (0 = byte, 1 = short, 2 = long) */
816 FALSE
, /* pc_relative */
818 complain_overflow_dont
, /* complain_on_overflow */
819 bfd_elf_generic_reloc
, /* special_function */
820 "R_PPC_PLT16_LO", /* name */
821 FALSE
, /* partial_inplace */
823 0xffff, /* dst_mask */
824 FALSE
), /* pcrel_offset */
826 /* Like R_PPC_ADDR16_HI, but referring to the PLT table entry for
828 HOWTO (R_PPC_PLT16_HI
, /* type */
830 1, /* size (0 = byte, 1 = short, 2 = long) */
832 FALSE
, /* pc_relative */
834 complain_overflow_bitfield
, /* complain_on_overflow */
835 bfd_elf_generic_reloc
, /* special_function */
836 "R_PPC_PLT16_HI", /* name */
837 FALSE
, /* partial_inplace */
839 0xffff, /* dst_mask */
840 FALSE
), /* pcrel_offset */
842 /* Like R_PPC_ADDR16_HA, but referring to the PLT table entry for
844 HOWTO (R_PPC_PLT16_HA
, /* type */
846 1, /* size (0 = byte, 1 = short, 2 = long) */
848 FALSE
, /* pc_relative */
850 complain_overflow_bitfield
, /* complain_on_overflow */
851 ppc_elf_addr16_ha_reloc
, /* special_function */
852 "R_PPC_PLT16_HA", /* name */
853 FALSE
, /* partial_inplace */
855 0xffff, /* dst_mask */
856 FALSE
), /* pcrel_offset */
858 /* A sign-extended 16 bit value relative to _SDA_BASE_, for use with
860 HOWTO (R_PPC_SDAREL16
, /* type */
862 1, /* size (0 = byte, 1 = short, 2 = long) */
864 FALSE
, /* pc_relative */
866 complain_overflow_signed
, /* complain_on_overflow */
867 bfd_elf_generic_reloc
, /* special_function */
868 "R_PPC_SDAREL16", /* name */
869 FALSE
, /* partial_inplace */
871 0xffff, /* dst_mask */
872 FALSE
), /* pcrel_offset */
874 /* 16-bit section relative relocation. */
875 HOWTO (R_PPC_SECTOFF
, /* type */
877 1, /* size (0 = byte, 1 = short, 2 = long) */
879 FALSE
, /* pc_relative */
881 complain_overflow_bitfield
, /* complain_on_overflow */
882 bfd_elf_generic_reloc
, /* special_function */
883 "R_PPC_SECTOFF", /* name */
884 FALSE
, /* partial_inplace */
886 0xffff, /* dst_mask */
887 FALSE
), /* pcrel_offset */
889 /* 16-bit lower half section relative relocation. */
890 HOWTO (R_PPC_SECTOFF_LO
, /* type */
892 1, /* size (0 = byte, 1 = short, 2 = long) */
894 FALSE
, /* pc_relative */
896 complain_overflow_dont
, /* complain_on_overflow */
897 bfd_elf_generic_reloc
, /* special_function */
898 "R_PPC_SECTOFF_LO", /* name */
899 FALSE
, /* partial_inplace */
901 0xffff, /* dst_mask */
902 FALSE
), /* pcrel_offset */
904 /* 16-bit upper half section relative relocation. */
905 HOWTO (R_PPC_SECTOFF_HI
, /* type */
907 1, /* size (0 = byte, 1 = short, 2 = long) */
909 FALSE
, /* pc_relative */
911 complain_overflow_bitfield
, /* complain_on_overflow */
912 bfd_elf_generic_reloc
, /* special_function */
913 "R_PPC_SECTOFF_HI", /* name */
914 FALSE
, /* partial_inplace */
916 0xffff, /* dst_mask */
917 FALSE
), /* pcrel_offset */
919 /* 16-bit upper half adjusted section relative relocation. */
920 HOWTO (R_PPC_SECTOFF_HA
, /* type */
922 1, /* size (0 = byte, 1 = short, 2 = long) */
924 FALSE
, /* pc_relative */
926 complain_overflow_bitfield
, /* complain_on_overflow */
927 ppc_elf_addr16_ha_reloc
, /* special_function */
928 "R_PPC_SECTOFF_HA", /* name */
929 FALSE
, /* partial_inplace */
931 0xffff, /* dst_mask */
932 FALSE
), /* pcrel_offset */
934 /* Marker reloc for TLS. */
937 2, /* size (0 = byte, 1 = short, 2 = long) */
939 FALSE
, /* pc_relative */
941 complain_overflow_dont
, /* complain_on_overflow */
942 bfd_elf_generic_reloc
, /* special_function */
943 "R_PPC_TLS", /* name */
944 FALSE
, /* partial_inplace */
947 FALSE
), /* pcrel_offset */
949 /* Computes the load module index of the load module that contains the
950 definition of its TLS sym. */
951 HOWTO (R_PPC_DTPMOD32
,
953 2, /* size (0 = byte, 1 = short, 2 = long) */
955 FALSE
, /* pc_relative */
957 complain_overflow_dont
, /* complain_on_overflow */
958 ppc_elf_unhandled_reloc
, /* special_function */
959 "R_PPC_DTPMOD32", /* name */
960 FALSE
, /* partial_inplace */
962 0xffffffff, /* dst_mask */
963 FALSE
), /* pcrel_offset */
965 /* Computes a dtv-relative displacement, the difference between the value
966 of sym+add and the base address of the thread-local storage block that
967 contains the definition of sym, minus 0x8000. */
968 HOWTO (R_PPC_DTPREL32
,
970 2, /* size (0 = byte, 1 = short, 2 = long) */
972 FALSE
, /* pc_relative */
974 complain_overflow_dont
, /* complain_on_overflow */
975 ppc_elf_unhandled_reloc
, /* special_function */
976 "R_PPC_DTPREL32", /* name */
977 FALSE
, /* partial_inplace */
979 0xffffffff, /* dst_mask */
980 FALSE
), /* pcrel_offset */
982 /* A 16 bit dtprel reloc. */
983 HOWTO (R_PPC_DTPREL16
,
985 1, /* size (0 = byte, 1 = short, 2 = long) */
987 FALSE
, /* pc_relative */
989 complain_overflow_signed
, /* complain_on_overflow */
990 ppc_elf_unhandled_reloc
, /* special_function */
991 "R_PPC_DTPREL16", /* name */
992 FALSE
, /* partial_inplace */
994 0xffff, /* dst_mask */
995 FALSE
), /* pcrel_offset */
997 /* Like DTPREL16, but no overflow. */
998 HOWTO (R_PPC_DTPREL16_LO
,
1000 1, /* size (0 = byte, 1 = short, 2 = long) */
1002 FALSE
, /* pc_relative */
1004 complain_overflow_dont
, /* complain_on_overflow */
1005 ppc_elf_unhandled_reloc
, /* special_function */
1006 "R_PPC_DTPREL16_LO", /* name */
1007 FALSE
, /* partial_inplace */
1009 0xffff, /* dst_mask */
1010 FALSE
), /* pcrel_offset */
1012 /* Like DTPREL16_LO, but next higher group of 16 bits. */
1013 HOWTO (R_PPC_DTPREL16_HI
,
1014 16, /* rightshift */
1015 1, /* size (0 = byte, 1 = short, 2 = long) */
1017 FALSE
, /* pc_relative */
1019 complain_overflow_dont
, /* complain_on_overflow */
1020 ppc_elf_unhandled_reloc
, /* special_function */
1021 "R_PPC_DTPREL16_HI", /* name */
1022 FALSE
, /* partial_inplace */
1024 0xffff, /* dst_mask */
1025 FALSE
), /* pcrel_offset */
1027 /* Like DTPREL16_HI, but adjust for low 16 bits. */
1028 HOWTO (R_PPC_DTPREL16_HA
,
1029 16, /* rightshift */
1030 1, /* size (0 = byte, 1 = short, 2 = long) */
1032 FALSE
, /* pc_relative */
1034 complain_overflow_dont
, /* complain_on_overflow */
1035 ppc_elf_unhandled_reloc
, /* special_function */
1036 "R_PPC_DTPREL16_HA", /* name */
1037 FALSE
, /* partial_inplace */
1039 0xffff, /* dst_mask */
1040 FALSE
), /* pcrel_offset */
1042 /* Computes a tp-relative displacement, the difference between the value of
1043 sym+add and the value of the thread pointer (r13). */
1044 HOWTO (R_PPC_TPREL32
,
1046 2, /* size (0 = byte, 1 = short, 2 = long) */
1048 FALSE
, /* pc_relative */
1050 complain_overflow_dont
, /* complain_on_overflow */
1051 ppc_elf_unhandled_reloc
, /* special_function */
1052 "R_PPC_TPREL32", /* name */
1053 FALSE
, /* partial_inplace */
1055 0xffffffff, /* dst_mask */
1056 FALSE
), /* pcrel_offset */
1058 /* A 16 bit tprel reloc. */
1059 HOWTO (R_PPC_TPREL16
,
1061 1, /* size (0 = byte, 1 = short, 2 = long) */
1063 FALSE
, /* pc_relative */
1065 complain_overflow_signed
, /* complain_on_overflow */
1066 ppc_elf_unhandled_reloc
, /* special_function */
1067 "R_PPC_TPREL16", /* name */
1068 FALSE
, /* partial_inplace */
1070 0xffff, /* dst_mask */
1071 FALSE
), /* pcrel_offset */
1073 /* Like TPREL16, but no overflow. */
1074 HOWTO (R_PPC_TPREL16_LO
,
1076 1, /* size (0 = byte, 1 = short, 2 = long) */
1078 FALSE
, /* pc_relative */
1080 complain_overflow_dont
, /* complain_on_overflow */
1081 ppc_elf_unhandled_reloc
, /* special_function */
1082 "R_PPC_TPREL16_LO", /* name */
1083 FALSE
, /* partial_inplace */
1085 0xffff, /* dst_mask */
1086 FALSE
), /* pcrel_offset */
1088 /* Like TPREL16_LO, but next higher group of 16 bits. */
1089 HOWTO (R_PPC_TPREL16_HI
,
1090 16, /* rightshift */
1091 1, /* size (0 = byte, 1 = short, 2 = long) */
1093 FALSE
, /* pc_relative */
1095 complain_overflow_dont
, /* complain_on_overflow */
1096 ppc_elf_unhandled_reloc
, /* special_function */
1097 "R_PPC_TPREL16_HI", /* name */
1098 FALSE
, /* partial_inplace */
1100 0xffff, /* dst_mask */
1101 FALSE
), /* pcrel_offset */
1103 /* Like TPREL16_HI, but adjust for low 16 bits. */
1104 HOWTO (R_PPC_TPREL16_HA
,
1105 16, /* rightshift */
1106 1, /* size (0 = byte, 1 = short, 2 = long) */
1108 FALSE
, /* pc_relative */
1110 complain_overflow_dont
, /* complain_on_overflow */
1111 ppc_elf_unhandled_reloc
, /* special_function */
1112 "R_PPC_TPREL16_HA", /* name */
1113 FALSE
, /* partial_inplace */
1115 0xffff, /* dst_mask */
1116 FALSE
), /* pcrel_offset */
1118 /* Allocates two contiguous entries in the GOT to hold a tls_index structure,
1119 with values (sym+add)@dtpmod and (sym+add)@dtprel, and computes the offset
1120 to the first entry. */
1121 HOWTO (R_PPC_GOT_TLSGD16
,
1123 1, /* size (0 = byte, 1 = short, 2 = long) */
1125 FALSE
, /* pc_relative */
1127 complain_overflow_signed
, /* complain_on_overflow */
1128 ppc_elf_unhandled_reloc
, /* special_function */
1129 "R_PPC_GOT_TLSGD16", /* name */
1130 FALSE
, /* partial_inplace */
1132 0xffff, /* dst_mask */
1133 FALSE
), /* pcrel_offset */
1135 /* Like GOT_TLSGD16, but no overflow. */
1136 HOWTO (R_PPC_GOT_TLSGD16_LO
,
1138 1, /* size (0 = byte, 1 = short, 2 = long) */
1140 FALSE
, /* pc_relative */
1142 complain_overflow_dont
, /* complain_on_overflow */
1143 ppc_elf_unhandled_reloc
, /* special_function */
1144 "R_PPC_GOT_TLSGD16_LO", /* name */
1145 FALSE
, /* partial_inplace */
1147 0xffff, /* dst_mask */
1148 FALSE
), /* pcrel_offset */
1150 /* Like GOT_TLSGD16_LO, but next higher group of 16 bits. */
1151 HOWTO (R_PPC_GOT_TLSGD16_HI
,
1152 16, /* rightshift */
1153 1, /* size (0 = byte, 1 = short, 2 = long) */
1155 FALSE
, /* pc_relative */
1157 complain_overflow_dont
, /* complain_on_overflow */
1158 ppc_elf_unhandled_reloc
, /* special_function */
1159 "R_PPC_GOT_TLSGD16_HI", /* name */
1160 FALSE
, /* partial_inplace */
1162 0xffff, /* dst_mask */
1163 FALSE
), /* pcrel_offset */
1165 /* Like GOT_TLSGD16_HI, but adjust for low 16 bits. */
1166 HOWTO (R_PPC_GOT_TLSGD16_HA
,
1167 16, /* rightshift */
1168 1, /* size (0 = byte, 1 = short, 2 = long) */
1170 FALSE
, /* pc_relative */
1172 complain_overflow_dont
, /* complain_on_overflow */
1173 ppc_elf_unhandled_reloc
, /* special_function */
1174 "R_PPC_GOT_TLSGD16_HA", /* name */
1175 FALSE
, /* partial_inplace */
1177 0xffff, /* dst_mask */
1178 FALSE
), /* pcrel_offset */
1180 /* Allocates two contiguous entries in the GOT to hold a tls_index structure,
1181 with values (sym+add)@dtpmod and zero, and computes the offset to the
1183 HOWTO (R_PPC_GOT_TLSLD16
,
1185 1, /* size (0 = byte, 1 = short, 2 = long) */
1187 FALSE
, /* pc_relative */
1189 complain_overflow_signed
, /* complain_on_overflow */
1190 ppc_elf_unhandled_reloc
, /* special_function */
1191 "R_PPC_GOT_TLSLD16", /* name */
1192 FALSE
, /* partial_inplace */
1194 0xffff, /* dst_mask */
1195 FALSE
), /* pcrel_offset */
1197 /* Like GOT_TLSLD16, but no overflow. */
1198 HOWTO (R_PPC_GOT_TLSLD16_LO
,
1200 1, /* size (0 = byte, 1 = short, 2 = long) */
1202 FALSE
, /* pc_relative */
1204 complain_overflow_dont
, /* complain_on_overflow */
1205 ppc_elf_unhandled_reloc
, /* special_function */
1206 "R_PPC_GOT_TLSLD16_LO", /* name */
1207 FALSE
, /* partial_inplace */
1209 0xffff, /* dst_mask */
1210 FALSE
), /* pcrel_offset */
1212 /* Like GOT_TLSLD16_LO, but next higher group of 16 bits. */
1213 HOWTO (R_PPC_GOT_TLSLD16_HI
,
1214 16, /* rightshift */
1215 1, /* size (0 = byte, 1 = short, 2 = long) */
1217 FALSE
, /* pc_relative */
1219 complain_overflow_dont
, /* complain_on_overflow */
1220 ppc_elf_unhandled_reloc
, /* special_function */
1221 "R_PPC_GOT_TLSLD16_HI", /* name */
1222 FALSE
, /* partial_inplace */
1224 0xffff, /* dst_mask */
1225 FALSE
), /* pcrel_offset */
1227 /* Like GOT_TLSLD16_HI, but adjust for low 16 bits. */
1228 HOWTO (R_PPC_GOT_TLSLD16_HA
,
1229 16, /* rightshift */
1230 1, /* size (0 = byte, 1 = short, 2 = long) */
1232 FALSE
, /* pc_relative */
1234 complain_overflow_dont
, /* complain_on_overflow */
1235 ppc_elf_unhandled_reloc
, /* special_function */
1236 "R_PPC_GOT_TLSLD16_HA", /* name */
1237 FALSE
, /* partial_inplace */
1239 0xffff, /* dst_mask */
1240 FALSE
), /* pcrel_offset */
1242 /* Allocates an entry in the GOT with value (sym+add)@dtprel, and computes
1243 the offset to the entry. */
1244 HOWTO (R_PPC_GOT_DTPREL16
,
1246 1, /* size (0 = byte, 1 = short, 2 = long) */
1248 FALSE
, /* pc_relative */
1250 complain_overflow_signed
, /* complain_on_overflow */
1251 ppc_elf_unhandled_reloc
, /* special_function */
1252 "R_PPC_GOT_DTPREL16", /* name */
1253 FALSE
, /* partial_inplace */
1255 0xffff, /* dst_mask */
1256 FALSE
), /* pcrel_offset */
1258 /* Like GOT_DTPREL16, but no overflow. */
1259 HOWTO (R_PPC_GOT_DTPREL16_LO
,
1261 1, /* size (0 = byte, 1 = short, 2 = long) */
1263 FALSE
, /* pc_relative */
1265 complain_overflow_dont
, /* complain_on_overflow */
1266 ppc_elf_unhandled_reloc
, /* special_function */
1267 "R_PPC_GOT_DTPREL16_LO", /* name */
1268 FALSE
, /* partial_inplace */
1270 0xffff, /* dst_mask */
1271 FALSE
), /* pcrel_offset */
1273 /* Like GOT_DTPREL16_LO, but next higher group of 16 bits. */
1274 HOWTO (R_PPC_GOT_DTPREL16_HI
,
1275 16, /* rightshift */
1276 1, /* size (0 = byte, 1 = short, 2 = long) */
1278 FALSE
, /* pc_relative */
1280 complain_overflow_dont
, /* complain_on_overflow */
1281 ppc_elf_unhandled_reloc
, /* special_function */
1282 "R_PPC_GOT_DTPREL16_HI", /* name */
1283 FALSE
, /* partial_inplace */
1285 0xffff, /* dst_mask */
1286 FALSE
), /* pcrel_offset */
1288 /* Like GOT_DTPREL16_HI, but adjust for low 16 bits. */
1289 HOWTO (R_PPC_GOT_DTPREL16_HA
,
1290 16, /* rightshift */
1291 1, /* size (0 = byte, 1 = short, 2 = long) */
1293 FALSE
, /* pc_relative */
1295 complain_overflow_dont
, /* complain_on_overflow */
1296 ppc_elf_unhandled_reloc
, /* special_function */
1297 "R_PPC_GOT_DTPREL16_HA", /* name */
1298 FALSE
, /* partial_inplace */
1300 0xffff, /* dst_mask */
1301 FALSE
), /* pcrel_offset */
1303 /* Allocates an entry in the GOT with value (sym+add)@tprel, and computes the
1304 offset to the entry. */
1305 HOWTO (R_PPC_GOT_TPREL16
,
1307 1, /* size (0 = byte, 1 = short, 2 = long) */
1309 FALSE
, /* pc_relative */
1311 complain_overflow_signed
, /* complain_on_overflow */
1312 ppc_elf_unhandled_reloc
, /* special_function */
1313 "R_PPC_GOT_TPREL16", /* name */
1314 FALSE
, /* partial_inplace */
1316 0xffff, /* dst_mask */
1317 FALSE
), /* pcrel_offset */
1319 /* Like GOT_TPREL16, but no overflow. */
1320 HOWTO (R_PPC_GOT_TPREL16_LO
,
1322 1, /* size (0 = byte, 1 = short, 2 = long) */
1324 FALSE
, /* pc_relative */
1326 complain_overflow_dont
, /* complain_on_overflow */
1327 ppc_elf_unhandled_reloc
, /* special_function */
1328 "R_PPC_GOT_TPREL16_LO", /* name */
1329 FALSE
, /* partial_inplace */
1331 0xffff, /* dst_mask */
1332 FALSE
), /* pcrel_offset */
1334 /* Like GOT_TPREL16_LO, but next higher group of 16 bits. */
1335 HOWTO (R_PPC_GOT_TPREL16_HI
,
1336 16, /* rightshift */
1337 1, /* size (0 = byte, 1 = short, 2 = long) */
1339 FALSE
, /* pc_relative */
1341 complain_overflow_dont
, /* complain_on_overflow */
1342 ppc_elf_unhandled_reloc
, /* special_function */
1343 "R_PPC_GOT_TPREL16_HI", /* name */
1344 FALSE
, /* partial_inplace */
1346 0xffff, /* dst_mask */
1347 FALSE
), /* pcrel_offset */
1349 /* Like GOT_TPREL16_HI, but adjust for low 16 bits. */
1350 HOWTO (R_PPC_GOT_TPREL16_HA
,
1351 16, /* rightshift */
1352 1, /* size (0 = byte, 1 = short, 2 = long) */
1354 FALSE
, /* pc_relative */
1356 complain_overflow_dont
, /* complain_on_overflow */
1357 ppc_elf_unhandled_reloc
, /* special_function */
1358 "R_PPC_GOT_TPREL16_HA", /* name */
1359 FALSE
, /* partial_inplace */
1361 0xffff, /* dst_mask */
1362 FALSE
), /* pcrel_offset */
1364 /* The remaining relocs are from the Embedded ELF ABI, and are not
1365 in the SVR4 ELF ABI. */
1367 /* 32 bit value resulting from the addend minus the symbol. */
1368 HOWTO (R_PPC_EMB_NADDR32
, /* type */
1370 2, /* size (0 = byte, 1 = short, 2 = long) */
1372 FALSE
, /* pc_relative */
1374 complain_overflow_bitfield
, /* complain_on_overflow */
1375 bfd_elf_generic_reloc
, /* special_function */
1376 "R_PPC_EMB_NADDR32", /* name */
1377 FALSE
, /* partial_inplace */
1379 0xffffffff, /* dst_mask */
1380 FALSE
), /* pcrel_offset */
1382 /* 16 bit value resulting from the addend minus the symbol. */
1383 HOWTO (R_PPC_EMB_NADDR16
, /* type */
1385 1, /* size (0 = byte, 1 = short, 2 = long) */
1387 FALSE
, /* pc_relative */
1389 complain_overflow_bitfield
, /* complain_on_overflow */
1390 bfd_elf_generic_reloc
, /* special_function */
1391 "R_PPC_EMB_NADDR16", /* name */
1392 FALSE
, /* partial_inplace */
1394 0xffff, /* dst_mask */
1395 FALSE
), /* pcrel_offset */
1397 /* 16 bit value resulting from the addend minus the symbol. */
1398 HOWTO (R_PPC_EMB_NADDR16_LO
, /* type */
1400 1, /* size (0 = byte, 1 = short, 2 = long) */
1402 FALSE
, /* pc_relative */
1404 complain_overflow_dont
,/* complain_on_overflow */
1405 bfd_elf_generic_reloc
, /* special_function */
1406 "R_PPC_EMB_ADDR16_LO", /* name */
1407 FALSE
, /* partial_inplace */
1409 0xffff, /* dst_mask */
1410 FALSE
), /* pcrel_offset */
1412 /* The high order 16 bits of the addend minus the symbol. */
1413 HOWTO (R_PPC_EMB_NADDR16_HI
, /* type */
1414 16, /* rightshift */
1415 1, /* size (0 = byte, 1 = short, 2 = long) */
1417 FALSE
, /* pc_relative */
1419 complain_overflow_dont
, /* complain_on_overflow */
1420 bfd_elf_generic_reloc
, /* special_function */
1421 "R_PPC_EMB_NADDR16_HI", /* name */
1422 FALSE
, /* partial_inplace */
1424 0xffff, /* dst_mask */
1425 FALSE
), /* pcrel_offset */
1427 /* The high order 16 bits of the result of the addend minus the address,
1428 plus 1 if the contents of the low 16 bits, treated as a signed number,
1430 HOWTO (R_PPC_EMB_NADDR16_HA
, /* type */
1431 16, /* rightshift */
1432 1, /* size (0 = byte, 1 = short, 2 = long) */
1434 FALSE
, /* pc_relative */
1436 complain_overflow_dont
, /* complain_on_overflow */
1437 ppc_elf_addr16_ha_reloc
, /* special_function */
1438 "R_PPC_EMB_NADDR16_HA", /* name */
1439 FALSE
, /* partial_inplace */
1441 0xffff, /* dst_mask */
1442 FALSE
), /* pcrel_offset */
1444 /* 16 bit value resulting from allocating a 4 byte word to hold an
1445 address in the .sdata section, and returning the offset from
1446 _SDA_BASE_ for that relocation. */
1447 HOWTO (R_PPC_EMB_SDAI16
, /* type */
1449 1, /* size (0 = byte, 1 = short, 2 = long) */
1451 FALSE
, /* pc_relative */
1453 complain_overflow_bitfield
, /* complain_on_overflow */
1454 bfd_elf_generic_reloc
, /* special_function */
1455 "R_PPC_EMB_SDAI16", /* name */
1456 FALSE
, /* partial_inplace */
1458 0xffff, /* dst_mask */
1459 FALSE
), /* pcrel_offset */
1461 /* 16 bit value resulting from allocating a 4 byte word to hold an
1462 address in the .sdata2 section, and returning the offset from
1463 _SDA2_BASE_ for that relocation. */
1464 HOWTO (R_PPC_EMB_SDA2I16
, /* type */
1466 1, /* size (0 = byte, 1 = short, 2 = long) */
1468 FALSE
, /* pc_relative */
1470 complain_overflow_bitfield
, /* complain_on_overflow */
1471 bfd_elf_generic_reloc
, /* special_function */
1472 "R_PPC_EMB_SDA2I16", /* name */
1473 FALSE
, /* partial_inplace */
1475 0xffff, /* dst_mask */
1476 FALSE
), /* pcrel_offset */
1478 /* A sign-extended 16 bit value relative to _SDA2_BASE_, for use with
1479 small data items. */
1480 HOWTO (R_PPC_EMB_SDA2REL
, /* type */
1482 1, /* size (0 = byte, 1 = short, 2 = long) */
1484 FALSE
, /* pc_relative */
1486 complain_overflow_signed
, /* complain_on_overflow */
1487 bfd_elf_generic_reloc
, /* special_function */
1488 "R_PPC_EMB_SDA2REL", /* name */
1489 FALSE
, /* partial_inplace */
1491 0xffff, /* dst_mask */
1492 FALSE
), /* pcrel_offset */
1494 /* Relocate against either _SDA_BASE_ or _SDA2_BASE_, filling in the 16 bit
1495 signed offset from the appropriate base, and filling in the register
1496 field with the appropriate register (0, 2, or 13). */
1497 HOWTO (R_PPC_EMB_SDA21
, /* type */
1499 2, /* size (0 = byte, 1 = short, 2 = long) */
1501 FALSE
, /* pc_relative */
1503 complain_overflow_signed
, /* complain_on_overflow */
1504 bfd_elf_generic_reloc
, /* special_function */
1505 "R_PPC_EMB_SDA21", /* name */
1506 FALSE
, /* partial_inplace */
1508 0xffff, /* dst_mask */
1509 FALSE
), /* pcrel_offset */
1511 /* Relocation not handled: R_PPC_EMB_MRKREF */
1512 /* Relocation not handled: R_PPC_EMB_RELSEC16 */
1513 /* Relocation not handled: R_PPC_EMB_RELST_LO */
1514 /* Relocation not handled: R_PPC_EMB_RELST_HI */
1515 /* Relocation not handled: R_PPC_EMB_RELST_HA */
1516 /* Relocation not handled: R_PPC_EMB_BIT_FLD */
1518 /* PC relative relocation against either _SDA_BASE_ or _SDA2_BASE_, filling
1519 in the 16 bit signed offset from the appropriate base, and filling in the
1520 register field with the appropriate register (0, 2, or 13). */
1521 HOWTO (R_PPC_EMB_RELSDA
, /* type */
1523 1, /* size (0 = byte, 1 = short, 2 = long) */
1525 TRUE
, /* pc_relative */
1527 complain_overflow_signed
, /* complain_on_overflow */
1528 bfd_elf_generic_reloc
, /* special_function */
1529 "R_PPC_EMB_RELSDA", /* name */
1530 FALSE
, /* partial_inplace */
1532 0xffff, /* dst_mask */
1533 FALSE
), /* pcrel_offset */
1535 /* Phony relocs to handle branch stubs. */
1536 HOWTO (R_PPC_RELAX32
, /* type */
1540 FALSE
, /* pc_relative */
1542 complain_overflow_dont
, /* complain_on_overflow */
1543 bfd_elf_generic_reloc
, /* special_function */
1544 "R_PPC_RELAX32", /* name */
1545 FALSE
, /* partial_inplace */
1548 FALSE
), /* pcrel_offset */
1550 HOWTO (R_PPC_RELAX32PC
, /* type */
1554 FALSE
, /* pc_relative */
1556 complain_overflow_dont
, /* complain_on_overflow */
1557 bfd_elf_generic_reloc
, /* special_function */
1558 "R_PPC_RELAX32PC", /* name */
1559 FALSE
, /* partial_inplace */
1562 FALSE
), /* pcrel_offset */
1564 /* GNU extension to record C++ vtable hierarchy. */
1565 HOWTO (R_PPC_GNU_VTINHERIT
, /* type */
1567 0, /* size (0 = byte, 1 = short, 2 = long) */
1569 FALSE
, /* pc_relative */
1571 complain_overflow_dont
, /* complain_on_overflow */
1572 NULL
, /* special_function */
1573 "R_PPC_GNU_VTINHERIT", /* name */
1574 FALSE
, /* partial_inplace */
1577 FALSE
), /* pcrel_offset */
1579 /* GNU extension to record C++ vtable member usage. */
1580 HOWTO (R_PPC_GNU_VTENTRY
, /* type */
1582 0, /* size (0 = byte, 1 = short, 2 = long) */
1584 FALSE
, /* pc_relative */
1586 complain_overflow_dont
, /* complain_on_overflow */
1587 NULL
, /* special_function */
1588 "R_PPC_GNU_VTENTRY", /* name */
1589 FALSE
, /* partial_inplace */
1592 FALSE
), /* pcrel_offset */
1594 /* Phony reloc to handle AIX style TOC entries. */
1595 HOWTO (R_PPC_TOC16
, /* type */
1597 1, /* size (0 = byte, 1 = short, 2 = long) */
1599 FALSE
, /* pc_relative */
1601 complain_overflow_signed
, /* complain_on_overflow */
1602 bfd_elf_generic_reloc
, /* special_function */
1603 "R_PPC_TOC16", /* name */
1604 FALSE
, /* partial_inplace */
1606 0xffff, /* dst_mask */
1607 FALSE
), /* pcrel_offset */
1610 /* Initialize the ppc_elf_howto_table, so that linear accesses can be done. */
1613 ppc_elf_howto_init (void)
1615 unsigned int i
, type
;
1618 i
< sizeof (ppc_elf_howto_raw
) / sizeof (ppc_elf_howto_raw
[0]);
1621 type
= ppc_elf_howto_raw
[i
].type
;
1622 if (type
>= (sizeof (ppc_elf_howto_table
)
1623 / sizeof (ppc_elf_howto_table
[0])))
1625 ppc_elf_howto_table
[type
] = &ppc_elf_howto_raw
[i
];
1629 #define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
1631 static const int shared_stub_entry
[] =
1633 0x7c0802a6, /* mflr 0 */
1634 0x429f0005, /* bcl 20, 31, .Lxxx */
1635 0x7d6802a6, /* mflr 11 */
1636 0x3d6b0000, /* addis 11, 11, (xxx-.Lxxx)@ha */
1637 0x396b0018, /* addi 11, 11, (xxx-.Lxxx)@l */
1638 0x7c0803a6, /* mtlr 0 */
1639 0x7d6903a6, /* mtctr 11 */
1640 0x4e800420, /* bctr */
1643 static const int stub_entry
[] =
1645 0x3d600000, /* lis 11,xxx@ha */
1646 0x396b0000, /* addi 11,11,xxx@l */
1647 0x7d6903a6, /* mtctr 11 */
1648 0x4e800420, /* bctr */
1653 ppc_elf_relax_section (bfd
*abfd
,
1655 struct bfd_link_info
*link_info
,
1660 struct one_fixup
*next
;
1666 Elf_Internal_Shdr
*symtab_hdr
;
1667 bfd_byte
*contents
= NULL
;
1668 Elf_Internal_Sym
*isymbuf
= NULL
;
1669 Elf_Internal_Rela
*internal_relocs
= NULL
;
1670 Elf_Internal_Rela
*irel
, *irelend
;
1671 struct one_fixup
*fixups
= NULL
;
1672 bfd_boolean changed
;
1673 struct ppc_elf_link_hash_table
*ppc_info
;
1674 bfd_size_type trampoff
;
1678 /* Nothing to do if there are no relocations and no need for
1679 the relax finalize pass. */
1680 if ((isec
->flags
& SEC_RELOC
) == 0
1681 || isec
->reloc_count
== 0
1682 || link_info
->relax_finalizing
)
1685 /* If needed, initialize this section's cooked size. */
1686 if (isec
->_cooked_size
== 0)
1687 isec
->_cooked_size
= isec
->_raw_size
;
1689 trampoff
= (isec
->_cooked_size
+ 3) & (bfd_vma
) -4;
1690 /* Space for a branch around any trampolines. */
1693 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
1695 /* Get a copy of the native relocations. */
1696 internal_relocs
= _bfd_elf_link_read_relocs (abfd
, isec
, NULL
, NULL
,
1697 link_info
->keep_memory
);
1698 if (internal_relocs
== NULL
)
1701 ppc_info
= ppc_elf_hash_table (link_info
);
1702 irelend
= internal_relocs
+ isec
->reloc_count
;
1704 /* Get the section contents. */
1705 /* Get cached copy if it exists. */
1706 if (elf_section_data (isec
)->this_hdr
.contents
!= NULL
)
1707 contents
= elf_section_data (isec
)->this_hdr
.contents
;
1710 /* Go get them off disk. */
1711 contents
= bfd_malloc (isec
->_raw_size
);
1712 if (contents
== NULL
)
1715 if (!bfd_get_section_contents (abfd
, isec
, contents
, 0, isec
->_raw_size
))
1719 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
1721 unsigned long r_type
= ELF32_R_TYPE (irel
->r_info
);
1722 bfd_vma symaddr
, reladdr
, toff
, roff
;
1724 struct one_fixup
*f
;
1725 size_t insn_offset
= 0;
1726 bfd_vma max_branch_offset
, val
;
1733 case R_PPC_LOCAL24PC
:
1734 case R_PPC_PLTREL24
:
1735 max_branch_offset
= 1 << 25;
1739 case R_PPC_REL14_BRTAKEN
:
1740 case R_PPC_REL14_BRNTAKEN
:
1741 max_branch_offset
= 1 << 15;
1748 /* Get the value of the symbol referred to by the reloc. */
1749 if (ELF32_R_SYM (irel
->r_info
) < symtab_hdr
->sh_info
)
1751 /* A local symbol. */
1752 Elf_Internal_Sym
*isym
;
1754 /* Read this BFD's local symbols. */
1755 if (isymbuf
== NULL
)
1757 isymbuf
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
1758 if (isymbuf
== NULL
)
1759 isymbuf
= bfd_elf_get_elf_syms (abfd
, symtab_hdr
,
1760 symtab_hdr
->sh_info
, 0,
1765 isym
= isymbuf
+ ELF32_R_SYM (irel
->r_info
);
1766 if (isym
->st_shndx
== SHN_UNDEF
)
1767 continue; /* We can't do anthing with undefined symbols. */
1768 else if (isym
->st_shndx
== SHN_ABS
)
1769 tsec
= bfd_abs_section_ptr
;
1770 else if (isym
->st_shndx
== SHN_COMMON
)
1771 tsec
= bfd_com_section_ptr
;
1773 tsec
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
1775 toff
= isym
->st_value
;
1779 /* Global symbol handling. */
1781 struct elf_link_hash_entry
*h
;
1783 indx
= ELF32_R_SYM (irel
->r_info
) - symtab_hdr
->sh_info
;
1784 h
= elf_sym_hashes (abfd
)[indx
];
1786 while (h
->root
.type
== bfd_link_hash_indirect
1787 || h
->root
.type
== bfd_link_hash_warning
)
1788 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1790 if (r_type
== R_PPC_PLTREL24
1791 && ppc_info
->plt
!= NULL
1792 && h
->plt
.offset
!= (bfd_vma
) -1)
1794 tsec
= ppc_info
->plt
;
1795 toff
= h
->plt
.offset
;
1797 else if (h
->root
.type
== bfd_link_hash_defined
1798 || h
->root
.type
== bfd_link_hash_defweak
)
1800 tsec
= h
->root
.u
.def
.section
;
1801 toff
= h
->root
.u
.def
.value
;
1807 /* If the branch and target are in the same section, you have
1808 no hope of adding stubs. We'll error out later should the
1813 toff
+= irel
->r_addend
;
1814 if (tsec
->sec_info_type
== ELF_INFO_TYPE_MERGE
)
1815 toff
= _bfd_merged_section_offset (abfd
, &tsec
,
1816 elf_section_data (tsec
)->sec_info
,
1819 symaddr
= tsec
->output_section
->vma
+ tsec
->output_offset
+ toff
;
1821 roff
= irel
->r_offset
;
1823 reladdr
= (isec
->output_section
->vma
1824 + isec
->output_offset
1827 /* If the branch is in range, no need to do anything. */
1828 if (symaddr
- reladdr
+ max_branch_offset
< 2 * max_branch_offset
)
1831 /* Look for an existing fixup to this address. */
1832 for (f
= fixups
; f
; f
= f
->next
)
1833 if (f
->tsec
== tsec
&& f
->toff
== toff
)
1839 unsigned long stub_rtype
;
1841 val
= trampoff
- roff
;
1842 if (val
>= max_branch_offset
)
1843 /* Oh dear, we can't reach a trampoline. Don't try to add
1844 one. We'll report an error later. */
1847 if (link_info
->shared
)
1849 size
= 4 * ARRAY_SIZE (shared_stub_entry
);
1851 stub_rtype
= R_PPC_RELAX32PC
;
1855 size
= 4 * ARRAY_SIZE (stub_entry
);
1857 stub_rtype
= R_PPC_RELAX32
;
1860 /* Hijack the old relocation. Since we need two
1861 relocations for this use a "composite" reloc. */
1862 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
),
1864 irel
->r_offset
= trampoff
+ insn_offset
;
1866 /* Record the fixup so we don't do it again this section. */
1867 f
= bfd_malloc (sizeof (*f
));
1871 f
->trampoff
= trampoff
;
1878 val
= f
->trampoff
- roff
;
1879 if (val
>= max_branch_offset
)
1882 /* Nop out the reloc, since we're finalizing things here. */
1883 irel
->r_info
= ELF32_R_INFO (0, R_PPC_NONE
);
1886 /* Fix up the existing branch to hit the trampoline. */
1887 hit_addr
= contents
+ roff
;
1891 case R_PPC_LOCAL24PC
:
1892 case R_PPC_PLTREL24
:
1893 t0
= bfd_get_32 (abfd
, hit_addr
);
1895 t0
|= val
& 0x3fffffc;
1896 bfd_put_32 (abfd
, t0
, hit_addr
);
1900 case R_PPC_REL14_BRTAKEN
:
1901 case R_PPC_REL14_BRNTAKEN
:
1902 t0
= bfd_get_32 (abfd
, hit_addr
);
1905 bfd_put_32 (abfd
, t0
, hit_addr
);
1910 /* Write out the trampolines. */
1911 changed
= fixups
!= NULL
;
1921 struct one_fixup
*f
= fixups
;
1922 fixups
= fixups
->next
;
1927 contents
= bfd_realloc (contents
, trampoff
);
1928 if (contents
== NULL
)
1931 isec
->_cooked_size
= (isec
->_cooked_size
+ 3) & (bfd_vma
) -4;
1932 /* Branch around the trampolines. */
1933 val
= trampoff
- isec
->_cooked_size
+ 0x48000000;
1934 dest
= contents
+ isec
->_cooked_size
;
1935 isec
->_cooked_size
= trampoff
;
1936 bfd_put_32 (abfd
, val
, dest
);
1939 if (link_info
->shared
)
1941 stub
= shared_stub_entry
;
1942 size
= ARRAY_SIZE (shared_stub_entry
);
1947 size
= ARRAY_SIZE (stub_entry
);
1951 while (dest
< contents
+ trampoff
)
1953 bfd_put_32 (abfd
, stub
[i
], dest
);
1959 BFD_ASSERT (i
== 0);
1963 && symtab_hdr
->contents
!= (unsigned char *) isymbuf
)
1965 if (! link_info
->keep_memory
)
1969 /* Cache the symbols for elf_link_input_bfd. */
1970 symtab_hdr
->contents
= (unsigned char *) isymbuf
;
1974 if (contents
!= NULL
1975 && elf_section_data (isec
)->this_hdr
.contents
!= contents
)
1977 if (!changed
&& !link_info
->keep_memory
)
1981 /* Cache the section contents for elf_link_input_bfd. */
1982 elf_section_data (isec
)->this_hdr
.contents
= contents
;
1986 if (elf_section_data (isec
)->relocs
!= internal_relocs
)
1989 free (internal_relocs
);
1991 elf_section_data (isec
)->relocs
= internal_relocs
;
1998 if (isymbuf
!= NULL
&& (unsigned char *) isymbuf
!= symtab_hdr
->contents
)
2000 if (contents
!= NULL
2001 && elf_section_data (isec
)->this_hdr
.contents
!= contents
)
2003 if (internal_relocs
!= NULL
2004 && elf_section_data (isec
)->relocs
!= internal_relocs
)
2005 free (internal_relocs
);
2009 static reloc_howto_type
*
2010 ppc_elf_reloc_type_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
2011 bfd_reloc_code_real_type code
)
2013 enum elf_ppc_reloc_type r
;
2015 /* Initialize howto table if not already done. */
2016 if (!ppc_elf_howto_table
[R_PPC_ADDR32
])
2017 ppc_elf_howto_init ();
2024 case BFD_RELOC_NONE
: r
= R_PPC_NONE
; break;
2025 case BFD_RELOC_32
: r
= R_PPC_ADDR32
; break;
2026 case BFD_RELOC_PPC_BA26
: r
= R_PPC_ADDR24
; break;
2027 case BFD_RELOC_16
: r
= R_PPC_ADDR16
; break;
2028 case BFD_RELOC_LO16
: r
= R_PPC_ADDR16_LO
; break;
2029 case BFD_RELOC_HI16
: r
= R_PPC_ADDR16_HI
; break;
2030 case BFD_RELOC_HI16_S
: r
= R_PPC_ADDR16_HA
; break;
2031 case BFD_RELOC_PPC_BA16
: r
= R_PPC_ADDR14
; break;
2032 case BFD_RELOC_PPC_BA16_BRTAKEN
: r
= R_PPC_ADDR14_BRTAKEN
; break;
2033 case BFD_RELOC_PPC_BA16_BRNTAKEN
: r
= R_PPC_ADDR14_BRNTAKEN
; break;
2034 case BFD_RELOC_PPC_B26
: r
= R_PPC_REL24
; break;
2035 case BFD_RELOC_PPC_B16
: r
= R_PPC_REL14
; break;
2036 case BFD_RELOC_PPC_B16_BRTAKEN
: r
= R_PPC_REL14_BRTAKEN
; break;
2037 case BFD_RELOC_PPC_B16_BRNTAKEN
: r
= R_PPC_REL14_BRNTAKEN
; break;
2038 case BFD_RELOC_16_GOTOFF
: r
= R_PPC_GOT16
; break;
2039 case BFD_RELOC_LO16_GOTOFF
: r
= R_PPC_GOT16_LO
; break;
2040 case BFD_RELOC_HI16_GOTOFF
: r
= R_PPC_GOT16_HI
; break;
2041 case BFD_RELOC_HI16_S_GOTOFF
: r
= R_PPC_GOT16_HA
; break;
2042 case BFD_RELOC_24_PLT_PCREL
: r
= R_PPC_PLTREL24
; break;
2043 case BFD_RELOC_PPC_COPY
: r
= R_PPC_COPY
; break;
2044 case BFD_RELOC_PPC_GLOB_DAT
: r
= R_PPC_GLOB_DAT
; break;
2045 case BFD_RELOC_PPC_LOCAL24PC
: r
= R_PPC_LOCAL24PC
; break;
2046 case BFD_RELOC_32_PCREL
: r
= R_PPC_REL32
; break;
2047 case BFD_RELOC_32_PLTOFF
: r
= R_PPC_PLT32
; break;
2048 case BFD_RELOC_32_PLT_PCREL
: r
= R_PPC_PLTREL32
; break;
2049 case BFD_RELOC_LO16_PLTOFF
: r
= R_PPC_PLT16_LO
; break;
2050 case BFD_RELOC_HI16_PLTOFF
: r
= R_PPC_PLT16_HI
; break;
2051 case BFD_RELOC_HI16_S_PLTOFF
: r
= R_PPC_PLT16_HA
; break;
2052 case BFD_RELOC_GPREL16
: r
= R_PPC_SDAREL16
; break;
2053 case BFD_RELOC_16_BASEREL
: r
= R_PPC_SECTOFF
; break;
2054 case BFD_RELOC_LO16_BASEREL
: r
= R_PPC_SECTOFF_LO
; break;
2055 case BFD_RELOC_HI16_BASEREL
: r
= R_PPC_SECTOFF_HI
; break;
2056 case BFD_RELOC_HI16_S_BASEREL
: r
= R_PPC_SECTOFF_HA
; break;
2057 case BFD_RELOC_CTOR
: r
= R_PPC_ADDR32
; break;
2058 case BFD_RELOC_PPC_TOC16
: r
= R_PPC_TOC16
; break;
2059 case BFD_RELOC_PPC_TLS
: r
= R_PPC_TLS
; break;
2060 case BFD_RELOC_PPC_DTPMOD
: r
= R_PPC_DTPMOD32
; break;
2061 case BFD_RELOC_PPC_TPREL16
: r
= R_PPC_TPREL16
; break;
2062 case BFD_RELOC_PPC_TPREL16_LO
: r
= R_PPC_TPREL16_LO
; break;
2063 case BFD_RELOC_PPC_TPREL16_HI
: r
= R_PPC_TPREL16_HI
; break;
2064 case BFD_RELOC_PPC_TPREL16_HA
: r
= R_PPC_TPREL16_HA
; break;
2065 case BFD_RELOC_PPC_TPREL
: r
= R_PPC_TPREL32
; break;
2066 case BFD_RELOC_PPC_DTPREL16
: r
= R_PPC_DTPREL16
; break;
2067 case BFD_RELOC_PPC_DTPREL16_LO
: r
= R_PPC_DTPREL16_LO
; break;
2068 case BFD_RELOC_PPC_DTPREL16_HI
: r
= R_PPC_DTPREL16_HI
; break;
2069 case BFD_RELOC_PPC_DTPREL16_HA
: r
= R_PPC_DTPREL16_HA
; break;
2070 case BFD_RELOC_PPC_DTPREL
: r
= R_PPC_DTPREL32
; break;
2071 case BFD_RELOC_PPC_GOT_TLSGD16
: r
= R_PPC_GOT_TLSGD16
; break;
2072 case BFD_RELOC_PPC_GOT_TLSGD16_LO
: r
= R_PPC_GOT_TLSGD16_LO
; break;
2073 case BFD_RELOC_PPC_GOT_TLSGD16_HI
: r
= R_PPC_GOT_TLSGD16_HI
; break;
2074 case BFD_RELOC_PPC_GOT_TLSGD16_HA
: r
= R_PPC_GOT_TLSGD16_HA
; break;
2075 case BFD_RELOC_PPC_GOT_TLSLD16
: r
= R_PPC_GOT_TLSLD16
; break;
2076 case BFD_RELOC_PPC_GOT_TLSLD16_LO
: r
= R_PPC_GOT_TLSLD16_LO
; break;
2077 case BFD_RELOC_PPC_GOT_TLSLD16_HI
: r
= R_PPC_GOT_TLSLD16_HI
; break;
2078 case BFD_RELOC_PPC_GOT_TLSLD16_HA
: r
= R_PPC_GOT_TLSLD16_HA
; break;
2079 case BFD_RELOC_PPC_GOT_TPREL16
: r
= R_PPC_GOT_TPREL16
; break;
2080 case BFD_RELOC_PPC_GOT_TPREL16_LO
: r
= R_PPC_GOT_TPREL16_LO
; break;
2081 case BFD_RELOC_PPC_GOT_TPREL16_HI
: r
= R_PPC_GOT_TPREL16_HI
; break;
2082 case BFD_RELOC_PPC_GOT_TPREL16_HA
: r
= R_PPC_GOT_TPREL16_HA
; break;
2083 case BFD_RELOC_PPC_GOT_DTPREL16
: r
= R_PPC_GOT_DTPREL16
; break;
2084 case BFD_RELOC_PPC_GOT_DTPREL16_LO
: r
= R_PPC_GOT_DTPREL16_LO
; break;
2085 case BFD_RELOC_PPC_GOT_DTPREL16_HI
: r
= R_PPC_GOT_DTPREL16_HI
; break;
2086 case BFD_RELOC_PPC_GOT_DTPREL16_HA
: r
= R_PPC_GOT_DTPREL16_HA
; break;
2087 case BFD_RELOC_PPC_EMB_NADDR32
: r
= R_PPC_EMB_NADDR32
; break;
2088 case BFD_RELOC_PPC_EMB_NADDR16
: r
= R_PPC_EMB_NADDR16
; break;
2089 case BFD_RELOC_PPC_EMB_NADDR16_LO
: r
= R_PPC_EMB_NADDR16_LO
; break;
2090 case BFD_RELOC_PPC_EMB_NADDR16_HI
: r
= R_PPC_EMB_NADDR16_HI
; break;
2091 case BFD_RELOC_PPC_EMB_NADDR16_HA
: r
= R_PPC_EMB_NADDR16_HA
; break;
2092 case BFD_RELOC_PPC_EMB_SDAI16
: r
= R_PPC_EMB_SDAI16
; break;
2093 case BFD_RELOC_PPC_EMB_SDA2I16
: r
= R_PPC_EMB_SDA2I16
; break;
2094 case BFD_RELOC_PPC_EMB_SDA2REL
: r
= R_PPC_EMB_SDA2REL
; break;
2095 case BFD_RELOC_PPC_EMB_SDA21
: r
= R_PPC_EMB_SDA21
; break;
2096 case BFD_RELOC_PPC_EMB_MRKREF
: r
= R_PPC_EMB_MRKREF
; break;
2097 case BFD_RELOC_PPC_EMB_RELSEC16
: r
= R_PPC_EMB_RELSEC16
; break;
2098 case BFD_RELOC_PPC_EMB_RELST_LO
: r
= R_PPC_EMB_RELST_LO
; break;
2099 case BFD_RELOC_PPC_EMB_RELST_HI
: r
= R_PPC_EMB_RELST_HI
; break;
2100 case BFD_RELOC_PPC_EMB_RELST_HA
: r
= R_PPC_EMB_RELST_HA
; break;
2101 case BFD_RELOC_PPC_EMB_BIT_FLD
: r
= R_PPC_EMB_BIT_FLD
; break;
2102 case BFD_RELOC_PPC_EMB_RELSDA
: r
= R_PPC_EMB_RELSDA
; break;
2103 case BFD_RELOC_VTABLE_INHERIT
: r
= R_PPC_GNU_VTINHERIT
; break;
2104 case BFD_RELOC_VTABLE_ENTRY
: r
= R_PPC_GNU_VTENTRY
; break;
2107 return ppc_elf_howto_table
[r
];
2110 /* Set the howto pointer for a PowerPC ELF reloc. */
2113 ppc_elf_info_to_howto (bfd
*abfd ATTRIBUTE_UNUSED
,
2115 Elf_Internal_Rela
*dst
)
2117 /* Initialize howto table if not already done. */
2118 if (!ppc_elf_howto_table
[R_PPC_ADDR32
])
2119 ppc_elf_howto_init ();
2121 BFD_ASSERT (ELF32_R_TYPE (dst
->r_info
) < (unsigned int) R_PPC_max
);
2122 cache_ptr
->howto
= ppc_elf_howto_table
[ELF32_R_TYPE (dst
->r_info
)];
2125 /* Handle the R_PPC_ADDR16_HA reloc. */
2127 static bfd_reloc_status_type
2128 ppc_elf_addr16_ha_reloc (bfd
*abfd ATTRIBUTE_UNUSED
,
2129 arelent
*reloc_entry
,
2131 void *data ATTRIBUTE_UNUSED
,
2132 asection
*input_section
,
2134 char **error_message ATTRIBUTE_UNUSED
)
2138 if (output_bfd
!= NULL
)
2140 reloc_entry
->address
+= input_section
->output_offset
;
2141 return bfd_reloc_ok
;
2144 if (reloc_entry
->address
> input_section
->_cooked_size
)
2145 return bfd_reloc_outofrange
;
2147 if (bfd_is_com_section (symbol
->section
))
2150 relocation
= symbol
->value
;
2152 relocation
+= symbol
->section
->output_section
->vma
;
2153 relocation
+= symbol
->section
->output_offset
;
2154 relocation
+= reloc_entry
->addend
;
2156 reloc_entry
->addend
+= (relocation
& 0x8000) << 1;
2158 return bfd_reloc_continue
;
2161 static bfd_reloc_status_type
2162 ppc_elf_unhandled_reloc (bfd
*abfd
,
2163 arelent
*reloc_entry
,
2166 asection
*input_section
,
2168 char **error_message
)
2170 /* If this is a relocatable link (output_bfd test tells us), just
2171 call the generic function. Any adjustment will be done at final
2173 if (output_bfd
!= NULL
)
2174 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2175 input_section
, output_bfd
, error_message
);
2177 if (error_message
!= NULL
)
2179 static char buf
[60];
2180 sprintf (buf
, _("generic linker can't handle %s"),
2181 reloc_entry
->howto
->name
);
2182 *error_message
= buf
;
2184 return bfd_reloc_dangerous
;
2187 /* Fix bad default arch selected for a 32 bit input bfd when the
2188 default is 64 bit. */
2191 ppc_elf_object_p (bfd
*abfd
)
2193 if (abfd
->arch_info
->the_default
&& abfd
->arch_info
->bits_per_word
== 64)
2195 Elf_Internal_Ehdr
*i_ehdr
= elf_elfheader (abfd
);
2197 if (i_ehdr
->e_ident
[EI_CLASS
] == ELFCLASS32
)
2199 /* Relies on arch after 64 bit default being 32 bit default. */
2200 abfd
->arch_info
= abfd
->arch_info
->next
;
2201 BFD_ASSERT (abfd
->arch_info
->bits_per_word
== 32);
2207 /* Function to set whether a module needs the -mrelocatable bit set. */
2210 ppc_elf_set_private_flags (bfd
*abfd
, flagword flags
)
2212 BFD_ASSERT (!elf_flags_init (abfd
)
2213 || elf_elfheader (abfd
)->e_flags
== flags
);
2215 elf_elfheader (abfd
)->e_flags
= flags
;
2216 elf_flags_init (abfd
) = TRUE
;
2220 /* Merge backend specific data from an object file to the output
2221 object file when linking. */
2224 ppc_elf_merge_private_bfd_data (bfd
*ibfd
, bfd
*obfd
)
2230 /* Check if we have the same endianess. */
2231 if (! _bfd_generic_verify_endian_match (ibfd
, obfd
))
2234 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
2235 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
2238 new_flags
= elf_elfheader (ibfd
)->e_flags
;
2239 old_flags
= elf_elfheader (obfd
)->e_flags
;
2240 if (!elf_flags_init (obfd
))
2242 /* First call, no flags set. */
2243 elf_flags_init (obfd
) = TRUE
;
2244 elf_elfheader (obfd
)->e_flags
= new_flags
;
2247 /* Compatible flags are ok. */
2248 else if (new_flags
== old_flags
)
2251 /* Incompatible flags. */
2254 /* Warn about -mrelocatable mismatch. Allow -mrelocatable-lib
2255 to be linked with either. */
2257 if ((new_flags
& EF_PPC_RELOCATABLE
) != 0
2258 && (old_flags
& (EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
)) == 0)
2261 (*_bfd_error_handler
)
2262 (_("%s: compiled with -mrelocatable and linked with "
2263 "modules compiled normally"),
2264 bfd_archive_filename (ibfd
));
2266 else if ((new_flags
& (EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
)) == 0
2267 && (old_flags
& EF_PPC_RELOCATABLE
) != 0)
2270 (*_bfd_error_handler
)
2271 (_("%s: compiled normally and linked with "
2272 "modules compiled with -mrelocatable"),
2273 bfd_archive_filename (ibfd
));
2276 /* The output is -mrelocatable-lib iff both the input files are. */
2277 if (! (new_flags
& EF_PPC_RELOCATABLE_LIB
))
2278 elf_elfheader (obfd
)->e_flags
&= ~EF_PPC_RELOCATABLE_LIB
;
2280 /* The output is -mrelocatable iff it can't be -mrelocatable-lib,
2281 but each input file is either -mrelocatable or -mrelocatable-lib. */
2282 if (! (elf_elfheader (obfd
)->e_flags
& EF_PPC_RELOCATABLE_LIB
)
2283 && (new_flags
& (EF_PPC_RELOCATABLE_LIB
| EF_PPC_RELOCATABLE
))
2284 && (old_flags
& (EF_PPC_RELOCATABLE_LIB
| EF_PPC_RELOCATABLE
)))
2285 elf_elfheader (obfd
)->e_flags
|= EF_PPC_RELOCATABLE
;
2287 /* Do not warn about eabi vs. V.4 mismatch, just or in the bit if
2288 any module uses it. */
2289 elf_elfheader (obfd
)->e_flags
|= (new_flags
& EF_PPC_EMB
);
2291 new_flags
&= ~(EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
| EF_PPC_EMB
);
2292 old_flags
&= ~(EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
| EF_PPC_EMB
);
2294 /* Warn about any other mismatches. */
2295 if (new_flags
!= old_flags
)
2298 (*_bfd_error_handler
)
2299 (_("%s: uses different e_flags (0x%lx) fields "
2300 "than previous modules (0x%lx)"),
2301 bfd_archive_filename (ibfd
), (long) new_flags
, (long) old_flags
);
2306 bfd_set_error (bfd_error_bad_value
);
2314 /* Handle a PowerPC specific section when reading an object file. This
2315 is called when elfcode.h finds a section with an unknown type. */
2318 ppc_elf_section_from_shdr (bfd
*abfd
, Elf_Internal_Shdr
*hdr
, const char *name
)
2323 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
))
2326 newsect
= hdr
->bfd_section
;
2327 flags
= bfd_get_section_flags (abfd
, newsect
);
2328 if (hdr
->sh_flags
& SHF_EXCLUDE
)
2329 flags
|= SEC_EXCLUDE
;
2331 if (hdr
->sh_type
== SHT_ORDERED
)
2332 flags
|= SEC_SORT_ENTRIES
;
2334 bfd_set_section_flags (abfd
, newsect
, flags
);
2338 /* Set up any other section flags and such that may be necessary. */
2341 ppc_elf_fake_sections (bfd
*abfd ATTRIBUTE_UNUSED
,
2342 Elf_Internal_Shdr
*shdr
,
2345 if ((asect
->flags
& SEC_EXCLUDE
) != 0)
2346 shdr
->sh_flags
|= SHF_EXCLUDE
;
2348 if ((asect
->flags
& SEC_SORT_ENTRIES
) != 0)
2349 shdr
->sh_type
= SHT_ORDERED
;
2354 /* Find a linker generated pointer with a given addend and type. */
2356 static elf_linker_section_pointers_t
*
2357 elf_find_pointer_linker_section
2358 (elf_linker_section_pointers_t
*linker_pointers
,
2360 elf_linker_section_t
*lsect
)
2362 for ( ; linker_pointers
!= NULL
; linker_pointers
= linker_pointers
->next
)
2363 if (lsect
== linker_pointers
->lsect
&& addend
== linker_pointers
->addend
)
2364 return linker_pointers
;
2369 /* Allocate a pointer to live in a linker created section. */
2372 elf_create_pointer_linker_section (bfd
*abfd
,
2373 struct bfd_link_info
*info
,
2374 elf_linker_section_t
*lsect
,
2375 struct elf_link_hash_entry
*h
,
2376 const Elf_Internal_Rela
*rel
)
2378 elf_linker_section_pointers_t
**ptr_linker_section_ptr
= NULL
;
2379 elf_linker_section_pointers_t
*linker_section_ptr
;
2380 unsigned long r_symndx
= ELF32_R_SYM (rel
->r_info
);
2383 BFD_ASSERT (lsect
!= NULL
);
2385 /* Is this a global symbol? */
2388 struct ppc_elf_link_hash_entry
*eh
;
2390 /* Has this symbol already been allocated? If so, our work is done. */
2391 eh
= (struct ppc_elf_link_hash_entry
*) h
;
2392 if (elf_find_pointer_linker_section (eh
->linker_section_pointer
,
2397 ptr_linker_section_ptr
= &eh
->linker_section_pointer
;
2398 /* Make sure this symbol is output as a dynamic symbol. */
2399 if (h
->dynindx
== -1)
2401 if (! _bfd_elf_link_record_dynamic_symbol (info
, h
))
2405 if (lsect
->rel_section
)
2406 lsect
->rel_section
->_raw_size
+= sizeof (Elf32_External_Rela
);
2410 /* Allocation of a pointer to a local symbol. */
2411 elf_linker_section_pointers_t
**ptr
= elf_local_ptr_offsets (abfd
);
2413 /* Allocate a table to hold the local symbols if first time. */
2416 unsigned int num_symbols
= elf_tdata (abfd
)->symtab_hdr
.sh_info
;
2419 amt
*= sizeof (elf_linker_section_pointers_t
*);
2420 ptr
= bfd_zalloc (abfd
, amt
);
2425 elf_local_ptr_offsets (abfd
) = ptr
;
2428 /* Has this symbol already been allocated? If so, our work is done. */
2429 if (elf_find_pointer_linker_section (ptr
[r_symndx
],
2434 ptr_linker_section_ptr
= &ptr
[r_symndx
];
2438 /* If we are generating a shared object, we need to
2439 output a R_<xxx>_RELATIVE reloc so that the
2440 dynamic linker can adjust this GOT entry. */
2441 BFD_ASSERT (lsect
->rel_section
!= NULL
);
2442 lsect
->rel_section
->_raw_size
+= sizeof (Elf32_External_Rela
);
2446 /* Allocate space for a pointer in the linker section, and allocate
2447 a new pointer record from internal memory. */
2448 BFD_ASSERT (ptr_linker_section_ptr
!= NULL
);
2449 amt
= sizeof (elf_linker_section_pointers_t
);
2450 linker_section_ptr
= bfd_alloc (abfd
, amt
);
2452 if (!linker_section_ptr
)
2455 linker_section_ptr
->next
= *ptr_linker_section_ptr
;
2456 linker_section_ptr
->addend
= rel
->r_addend
;
2457 linker_section_ptr
->lsect
= lsect
;
2458 linker_section_ptr
->written_address_p
= FALSE
;
2459 *ptr_linker_section_ptr
= linker_section_ptr
;
2461 linker_section_ptr
->offset
= lsect
->section
->_raw_size
;
2462 lsect
->section
->_raw_size
+= 4;
2466 "Create pointer in linker section %s, offset = %ld, section size = %ld\n",
2467 lsect
->name
, (long) linker_section_ptr
->offset
,
2468 (long) lsect
->section
->_raw_size
);
2474 #define bfd_put_ptr(BFD, VAL, ADDR) bfd_put_32 (BFD, VAL, ADDR)
2476 /* Fill in the address for a pointer generated in a linker section. */
2479 elf_finish_pointer_linker_section (bfd
*output_bfd
,
2481 struct bfd_link_info
*info
,
2482 elf_linker_section_t
*lsect
,
2483 struct elf_link_hash_entry
*h
,
2485 const Elf_Internal_Rela
*rel
,
2488 elf_linker_section_pointers_t
*linker_section_ptr
;
2490 BFD_ASSERT (lsect
!= NULL
);
2494 /* Handle global symbol. */
2495 struct ppc_elf_link_hash_entry
*eh
;
2497 eh
= (struct ppc_elf_link_hash_entry
*) h
;
2499 = elf_find_pointer_linker_section (eh
->linker_section_pointer
,
2503 BFD_ASSERT (linker_section_ptr
!= NULL
);
2505 if (! elf_hash_table (info
)->dynamic_sections_created
2508 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
)))
2510 /* This is actually a static link, or it is a
2511 -Bsymbolic link and the symbol is defined
2512 locally. We must initialize this entry in the
2515 When doing a dynamic link, we create a .rela.<xxx>
2516 relocation entry to initialize the value. This
2517 is done in the finish_dynamic_symbol routine. */
2518 if (!linker_section_ptr
->written_address_p
)
2520 linker_section_ptr
->written_address_p
= TRUE
;
2521 bfd_put_ptr (output_bfd
,
2522 relocation
+ linker_section_ptr
->addend
,
2523 (lsect
->section
->contents
2524 + linker_section_ptr
->offset
));
2530 /* Handle local symbol. */
2531 unsigned long r_symndx
= ELF32_R_SYM (rel
->r_info
);
2532 BFD_ASSERT (elf_local_ptr_offsets (input_bfd
) != NULL
);
2533 BFD_ASSERT (elf_local_ptr_offsets (input_bfd
)[r_symndx
] != NULL
);
2534 linker_section_ptr
= (elf_find_pointer_linker_section
2535 (elf_local_ptr_offsets (input_bfd
)[r_symndx
],
2539 BFD_ASSERT (linker_section_ptr
!= NULL
);
2541 /* Write out pointer if it hasn't been rewritten out before. */
2542 if (!linker_section_ptr
->written_address_p
)
2544 linker_section_ptr
->written_address_p
= TRUE
;
2545 bfd_put_ptr (output_bfd
, relocation
+ linker_section_ptr
->addend
,
2546 lsect
->section
->contents
+ linker_section_ptr
->offset
);
2550 /* We need to generate a relative reloc for the dynamic
2553 asection
*srel
= lsect
->rel_section
;
2554 Elf_Internal_Rela outrel
[MAX_INT_RELS_PER_EXT_REL
];
2556 const struct elf_backend_data
*bed
;
2559 BFD_ASSERT (srel
!= NULL
);
2561 bed
= get_elf_backend_data (output_bfd
);
2562 for (i
= 0; i
< bed
->s
->int_rels_per_ext_rel
; i
++)
2564 outrel
[i
].r_offset
= (lsect
->section
->output_section
->vma
2565 + lsect
->section
->output_offset
2566 + linker_section_ptr
->offset
);
2567 outrel
[i
].r_info
= 0;
2568 outrel
[i
].r_addend
= 0;
2570 outrel
[0].r_info
= ELF32_R_INFO (0, relative_reloc
);
2571 erel
= lsect
->section
->contents
;
2572 erel
+= (elf_section_data (lsect
->section
)->rel_count
++
2573 * sizeof (Elf32_External_Rela
));
2574 bfd_elf32_swap_reloca_out (output_bfd
, outrel
, erel
);
2579 relocation
= (lsect
->section
->output_offset
2580 + linker_section_ptr
->offset
2581 - lsect
->sym_offset
);
2585 "Finish pointer in linker section %s, offset = %ld (0x%lx)\n",
2586 lsect
->name
, (long) relocation
, (long) relocation
);
2589 /* Subtract out the addend, because it will get added back in by the normal
2591 return relocation
- linker_section_ptr
->addend
;
2594 /* Create a special linker section */
2595 static elf_linker_section_t
*
2596 ppc_elf_create_linker_section (bfd
*abfd
,
2597 struct bfd_link_info
*info
,
2598 enum elf_linker_section_enum which
)
2600 elf_linker_section_t
*lsect
;
2601 struct ppc_elf_link_hash_table
*htab
= ppc_elf_hash_table (info
);
2606 const char *rel_name
;
2607 const char *sym_name
;
2610 /* Both of these sections are (technically) created by the user
2611 putting data in them, so they shouldn't be marked
2614 The linker creates them so it has somewhere to attach their
2615 respective symbols. In fact, if they were empty it would
2616 be OK to leave the symbol set to 0 (or any random number), because
2617 the appropriate register should never be used. */
2618 flags
= SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
;
2627 case LINKER_SECTION_SDATA
: /* .sdata/.sbss section */
2629 rel_name
= ".rela.sdata";
2630 sym_name
= "_SDA_BASE_";
2633 case LINKER_SECTION_SDATA2
: /* .sdata2/.sbss2 section */
2635 rel_name
= ".rela.sdata2";
2636 sym_name
= "_SDA2_BASE_";
2637 flags
|= SEC_READONLY
;
2641 /* Record the first bfd that needs the special sections. */
2642 if (!htab
->elf
.dynobj
)
2643 htab
->elf
.dynobj
= abfd
;
2645 amt
= sizeof (elf_linker_section_t
);
2646 lsect
= bfd_zalloc (htab
->elf
.dynobj
, amt
);
2648 lsect
->sym_offset
= sym_offset
;
2650 /* See if the sections already exist. */
2651 s
= bfd_get_section_by_name (htab
->elf
.dynobj
, name
);
2652 if (s
== NULL
|| (s
->flags
& flags
) != flags
)
2654 s
= bfd_make_section_anyway (htab
->elf
.dynobj
, name
);
2656 || !bfd_set_section_flags (htab
->elf
.dynobj
, s
, flags
))
2661 if (bfd_get_section_alignment (htab
->elf
.dynobj
, s
) < 2
2662 && !bfd_set_section_alignment (htab
->elf
.dynobj
, s
, 2))
2665 s
->_raw_size
= align_power (s
->_raw_size
, 2);
2668 fprintf (stderr
, "Creating section %s, current size = %ld\n",
2669 name
, (long) s
->_raw_size
);
2674 struct elf_link_hash_entry
*h
;
2675 struct bfd_link_hash_entry
*bh
;
2678 fprintf (stderr
, "Adding %s to section %s\n", sym_name
, name
);
2680 bh
= bfd_link_hash_lookup (info
->hash
, sym_name
,
2681 FALSE
, FALSE
, FALSE
);
2683 if ((bh
== NULL
|| bh
->type
== bfd_link_hash_undefined
)
2684 && !(_bfd_generic_link_add_one_symbol
2685 (info
, abfd
, sym_name
, BSF_GLOBAL
, s
, sym_offset
, NULL
,
2686 FALSE
, get_elf_backend_data (abfd
)->collect
, &bh
)))
2688 h
= (struct elf_link_hash_entry
*) bh
;
2690 h
->type
= STT_OBJECT
;
2691 lsect
->sym_hash
= h
;
2694 && ! _bfd_elf_link_record_dynamic_symbol (info
, h
))
2700 s
= bfd_make_section_anyway (htab
->elf
.dynobj
, rel_name
);
2701 lsect
->rel_section
= s
;
2702 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
2703 | SEC_LINKER_CREATED
| SEC_READONLY
);
2705 || ! bfd_set_section_flags (htab
->elf
.dynobj
, s
, flags
)
2706 || ! bfd_set_section_alignment (htab
->elf
.dynobj
, s
, 2))
2713 /* If we have a non-zero sized .sbss2 or .PPC.EMB.sbss0 sections, we
2714 need to bump up the number of section headers. */
2717 ppc_elf_additional_program_headers (bfd
*abfd
)
2724 s
= bfd_get_section_by_name (abfd
, ".interp");
2728 s
= bfd_get_section_by_name (abfd
, ".sbss2");
2729 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0 && s
->_raw_size
> 0)
2732 s
= bfd_get_section_by_name (abfd
, ".PPC.EMB.sbss0");
2733 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0 && s
->_raw_size
> 0)
2739 /* Modify the segment map if needed. */
2742 ppc_elf_modify_segment_map (bfd
*abfd ATTRIBUTE_UNUSED
,
2743 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
2748 /* The powerpc .got has a blrl instruction in it. Mark it executable. */
2751 ppc_elf_create_got (bfd
*abfd
, struct bfd_link_info
*info
)
2753 struct ppc_elf_link_hash_table
*htab
;
2757 if (!_bfd_elf_create_got_section (abfd
, info
))
2760 htab
= ppc_elf_hash_table (info
);
2761 htab
->got
= s
= bfd_get_section_by_name (abfd
, ".got");
2765 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_CODE
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
2766 | SEC_LINKER_CREATED
);
2767 if (!bfd_set_section_flags (abfd
, s
, flags
))
2770 htab
->relgot
= bfd_make_section (abfd
, ".rela.got");
2772 || ! bfd_set_section_flags (abfd
, htab
->relgot
,
2773 (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
2774 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
2776 || ! bfd_set_section_alignment (abfd
, htab
->relgot
, 2))
2782 /* We have to create .dynsbss and .rela.sbss here so that they get mapped
2783 to output sections (just like _bfd_elf_create_dynamic_sections has
2784 to create .dynbss and .rela.bss). */
2787 ppc_elf_create_dynamic_sections (bfd
*abfd
, struct bfd_link_info
*info
)
2789 struct ppc_elf_link_hash_table
*htab
;
2793 htab
= ppc_elf_hash_table (info
);
2795 if (htab
->got
== NULL
2796 && !ppc_elf_create_got (abfd
, info
))
2799 if (!_bfd_elf_create_dynamic_sections (abfd
, info
))
2802 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
2803 | SEC_LINKER_CREATED
);
2805 htab
->dynbss
= bfd_get_section_by_name (abfd
, ".dynbss");
2806 htab
->dynsbss
= s
= bfd_make_section (abfd
, ".dynsbss");
2808 || ! bfd_set_section_flags (abfd
, s
, SEC_ALLOC
))
2813 htab
->relbss
= bfd_get_section_by_name (abfd
, ".rela.bss");
2814 htab
->relsbss
= s
= bfd_make_section (abfd
, ".rela.sbss");
2816 || ! bfd_set_section_flags (abfd
, s
, flags
| SEC_READONLY
)
2817 || ! bfd_set_section_alignment (abfd
, s
, 2))
2821 htab
->relplt
= bfd_get_section_by_name (abfd
, ".rela.plt");
2822 htab
->plt
= s
= bfd_get_section_by_name (abfd
, ".plt");
2826 flags
= SEC_ALLOC
| SEC_CODE
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
;
2827 return bfd_set_section_flags (abfd
, s
, flags
);
2830 /* Adjust a symbol defined by a dynamic object and referenced by a
2831 regular object. The current definition is in some section of the
2832 dynamic object, but we're not including those sections. We have to
2833 change the definition to something the rest of the link can
2837 ppc_elf_adjust_dynamic_symbol (struct bfd_link_info
*info
,
2838 struct elf_link_hash_entry
*h
)
2840 struct ppc_elf_link_hash_table
*htab
;
2842 unsigned int power_of_two
;
2845 fprintf (stderr
, "ppc_elf_adjust_dynamic_symbol called for %s\n",
2846 h
->root
.root
.string
);
2849 /* Make sure we know what is going on here. */
2850 htab
= ppc_elf_hash_table (info
);
2851 BFD_ASSERT (htab
->elf
.dynobj
!= NULL
2852 && ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
)
2853 || h
->weakdef
!= NULL
2854 || ((h
->elf_link_hash_flags
2855 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0
2856 && (h
->elf_link_hash_flags
2857 & ELF_LINK_HASH_REF_REGULAR
) != 0
2858 && (h
->elf_link_hash_flags
2859 & ELF_LINK_HASH_DEF_REGULAR
) == 0)));
2861 /* Deal with function syms. */
2862 if (h
->type
== STT_FUNC
2863 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
2865 /* Clear procedure linkage table information for any symbol that
2866 won't need a .plt entry. */
2867 if (h
->plt
.refcount
<= 0
2868 || SYMBOL_CALLS_LOCAL (info
, h
)
2869 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
2870 && h
->root
.type
== bfd_link_hash_undefweak
))
2872 /* A PLT entry is not required/allowed when:
2874 1. We are not using ld.so; because then the PLT entry
2875 can't be set up, so we can't use one. In this case,
2876 ppc_elf_adjust_dynamic_symbol won't even be called.
2878 2. GC has rendered the entry unused.
2880 3. We know for certain that a call to this symbol
2881 will go to this object, or will remain undefined. */
2882 h
->plt
.offset
= (bfd_vma
) -1;
2883 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
2888 h
->plt
.offset
= (bfd_vma
) -1;
2890 /* If this is a weak symbol, and there is a real definition, the
2891 processor independent code will have arranged for us to see the
2892 real definition first, and we can just use the same value. */
2893 if (h
->weakdef
!= NULL
)
2895 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
2896 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
2897 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
2898 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
2899 if (ELIMINATE_COPY_RELOCS
)
2900 h
->elf_link_hash_flags
2901 = ((h
->elf_link_hash_flags
& ~ELF_LINK_NON_GOT_REF
)
2902 | (h
->weakdef
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
));
2906 /* This is a reference to a symbol defined by a dynamic object which
2907 is not a function. */
2909 /* If we are creating a shared library, we must presume that the
2910 only references to the symbol are via the global offset table.
2911 For such cases we need not do anything here; the relocations will
2912 be handled correctly by relocate_section. */
2916 /* If there are no references to this symbol that do not use the
2917 GOT, we don't need to generate a copy reloc. */
2918 if ((h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0)
2921 if (ELIMINATE_COPY_RELOCS
)
2923 struct ppc_elf_dyn_relocs
*p
;
2924 for (p
= ppc_elf_hash_entry (h
)->dyn_relocs
; p
!= NULL
; p
= p
->next
)
2926 s
= p
->sec
->output_section
;
2927 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
2931 /* If we didn't find any dynamic relocs in read-only sections, then
2932 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
2935 h
->elf_link_hash_flags
&= ~ELF_LINK_NON_GOT_REF
;
2940 /* We must allocate the symbol in our .dynbss section, which will
2941 become part of the .bss section of the executable. There will be
2942 an entry for this symbol in the .dynsym section. The dynamic
2943 object will contain position independent code, so all references
2944 from the dynamic object to this symbol will go through the global
2945 offset table. The dynamic linker will use the .dynsym entry to
2946 determine the address it must put in the global offset table, so
2947 both the dynamic object and the regular object will refer to the
2948 same memory location for the variable.
2950 Of course, if the symbol is sufficiently small, we must instead
2951 allocate it in .sbss. FIXME: It would be better to do this if and
2952 only if there were actually SDAREL relocs for that symbol. */
2954 if (h
->size
<= elf_gp_size (htab
->elf
.dynobj
))
2958 BFD_ASSERT (s
!= NULL
);
2960 /* We must generate a R_PPC_COPY reloc to tell the dynamic linker to
2961 copy the initial value out of the dynamic object and into the
2962 runtime process image. We need to remember the offset into the
2963 .rela.bss section we are going to use. */
2964 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
2968 if (h
->size
<= elf_gp_size (htab
->elf
.dynobj
))
2969 srel
= htab
->relsbss
;
2971 srel
= htab
->relbss
;
2972 BFD_ASSERT (srel
!= NULL
);
2973 srel
->_raw_size
+= sizeof (Elf32_External_Rela
);
2974 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_COPY
;
2977 /* We need to figure out the alignment required for this symbol. I
2978 have no idea how ELF linkers handle this. */
2979 power_of_two
= bfd_log2 (h
->size
);
2980 if (power_of_two
> 4)
2983 /* Apply the required alignment. */
2984 s
->_raw_size
= BFD_ALIGN (s
->_raw_size
,
2985 (bfd_size_type
) (1 << power_of_two
));
2986 if (power_of_two
> bfd_get_section_alignment (htab
->elf
.dynobj
, s
))
2988 if (! bfd_set_section_alignment (htab
->elf
.dynobj
, s
, power_of_two
))
2992 /* Define the symbol as being at this point in the section. */
2993 h
->root
.u
.def
.section
= s
;
2994 h
->root
.u
.def
.value
= s
->_raw_size
;
2996 /* Increment the section size to make room for the symbol. */
2997 s
->_raw_size
+= h
->size
;
3002 /* This is the condition under which finish_dynamic_symbol will be
3003 called from elflink.h. If elflink.h doesn't call our
3004 finish_dynamic_symbol routine, we'll need to do something about
3005 initializing any .plt and .got entries in relocate_section. */
3006 #define WILL_CALL_FINISH_DYNAMIC_SYMBOL(DYN, SHARED, H) \
3009 || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) \
3010 && ((H)->dynindx != -1 \
3011 || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0))
3013 /* Of those relocs that might be copied as dynamic relocs, this macro
3014 selects those that must be copied when linking a shared library,
3015 even when the symbol is local. */
3017 #define MUST_BE_DYN_RELOC(RTYPE) \
3018 ((RTYPE) != R_PPC_REL24 \
3019 && (RTYPE) != R_PPC_REL14 \
3020 && (RTYPE) != R_PPC_REL14_BRTAKEN \
3021 && (RTYPE) != R_PPC_REL14_BRNTAKEN \
3022 && (RTYPE) != R_PPC_REL32)
3024 /* Allocate space in associated reloc sections for dynamic relocs. */
3027 allocate_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
3029 struct bfd_link_info
*info
= inf
;
3030 struct ppc_elf_link_hash_entry
*eh
;
3031 struct ppc_elf_link_hash_table
*htab
;
3032 struct ppc_elf_dyn_relocs
*p
;
3034 if (h
->root
.type
== bfd_link_hash_indirect
)
3037 if (h
->root
.type
== bfd_link_hash_warning
)
3038 /* When warning symbols are created, they **replace** the "real"
3039 entry in the hash table, thus we never get to see the real
3040 symbol in a hash traversal. So look at it now. */
3041 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
3043 htab
= ppc_elf_hash_table (info
);
3044 if (htab
->elf
.dynamic_sections_created
3045 && h
->plt
.refcount
> 0)
3047 /* Make sure this symbol is output as a dynamic symbol. */
3048 if (h
->dynindx
== -1
3049 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
3051 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
3056 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h
))
3058 asection
*s
= htab
->plt
;
3060 /* If this is the first .plt entry, make room for the special
3062 if (s
->_raw_size
== 0)
3063 s
->_raw_size
+= PLT_INITIAL_ENTRY_SIZE
;
3065 /* The PowerPC PLT is actually composed of two parts, the
3066 first part is 2 words (for a load and a jump), and then
3067 there is a remaining word available at the end. */
3068 h
->plt
.offset
= (PLT_INITIAL_ENTRY_SIZE
3070 * ((s
->_raw_size
- PLT_INITIAL_ENTRY_SIZE
)
3071 / PLT_ENTRY_SIZE
)));
3073 /* If this symbol is not defined in a regular file, and we
3074 are not generating a shared library, then set the symbol
3075 to this location in the .plt. This is required to make
3076 function pointers compare as equal between the normal
3077 executable and the shared library. */
3079 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
3081 h
->root
.u
.def
.section
= s
;
3082 h
->root
.u
.def
.value
= h
->plt
.offset
;
3085 /* Make room for this entry. After the 8192nd entry, room
3086 for two entries is allocated. */
3087 s
->_raw_size
+= PLT_ENTRY_SIZE
;
3088 if ((s
->_raw_size
- PLT_INITIAL_ENTRY_SIZE
) / PLT_ENTRY_SIZE
3089 > PLT_NUM_SINGLE_ENTRIES
)
3090 s
->_raw_size
+= PLT_ENTRY_SIZE
;
3092 /* We also need to make an entry in the .rela.plt section. */
3093 htab
->relplt
->_raw_size
+= sizeof (Elf32_External_Rela
);
3097 h
->plt
.offset
= (bfd_vma
) -1;
3098 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
3103 h
->plt
.offset
= (bfd_vma
) -1;
3104 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
3107 eh
= (struct ppc_elf_link_hash_entry
*) h
;
3108 if (eh
->elf
.got
.refcount
> 0)
3110 /* Make sure this symbol is output as a dynamic symbol. */
3111 if (eh
->elf
.dynindx
== -1
3112 && (eh
->elf
.elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
3114 if (!bfd_elf32_link_record_dynamic_symbol (info
, &eh
->elf
))
3118 if (eh
->tls_mask
== (TLS_TLS
| TLS_LD
)
3119 && !(eh
->elf
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
))
3120 /* If just an LD reloc, we'll just use htab->tlsld_got.offset. */
3121 eh
->elf
.got
.offset
= (bfd_vma
) -1;
3125 eh
->elf
.got
.offset
= htab
->got
->_raw_size
;
3126 if ((eh
->tls_mask
& TLS_TLS
) != 0)
3128 if ((eh
->tls_mask
& TLS_LD
) != 0)
3129 htab
->got
->_raw_size
+= 8;
3130 if ((eh
->tls_mask
& TLS_GD
) != 0)
3131 htab
->got
->_raw_size
+= 8;
3132 if ((eh
->tls_mask
& (TLS_TPREL
| TLS_TPRELGD
)) != 0)
3133 htab
->got
->_raw_size
+= 4;
3134 if ((eh
->tls_mask
& TLS_DTPREL
) != 0)
3135 htab
->got
->_raw_size
+= 4;
3138 htab
->got
->_raw_size
+= 4;
3139 dyn
= htab
->elf
.dynamic_sections_created
;
3141 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, &eh
->elf
))
3142 && (ELF_ST_VISIBILITY (eh
->elf
.other
) == STV_DEFAULT
3143 || eh
->elf
.root
.type
!= bfd_link_hash_undefweak
))
3145 /* All the entries we allocated need relocs. */
3146 htab
->relgot
->_raw_size
3147 += ((htab
->got
->_raw_size
- eh
->elf
.got
.offset
) / 4
3148 * sizeof (Elf32_External_Rela
));
3149 /* Except LD only needs one. */
3150 if ((eh
->tls_mask
& TLS_LD
) != 0)
3151 htab
->relgot
->_raw_size
-= sizeof (Elf32_External_Rela
);
3156 eh
->elf
.got
.offset
= (bfd_vma
) -1;
3158 if (eh
->dyn_relocs
== NULL
)
3161 /* In the shared -Bsymbolic case, discard space allocated for
3162 dynamic pc-relative relocs against symbols which turn out to be
3163 defined in regular objects. For the normal shared case, discard
3164 space for relocs that have become local due to symbol visibility
3169 /* Relocs that use pc_count are those that appear on a call insn,
3170 or certain REL relocs (see MUST_BE_DYN_RELOC) that can be
3171 generated via assembly. We want calls to protected symbols to
3172 resolve directly to the function rather than going via the plt.
3173 If people want function pointer comparisons to work as expected
3174 then they should avoid writing weird assembly. */
3175 if (SYMBOL_CALLS_LOCAL (info
, h
))
3177 struct ppc_elf_dyn_relocs
**pp
;
3179 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
3181 p
->count
-= p
->pc_count
;
3190 /* Also discard relocs on undefined weak syms with non-default
3192 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
3193 && h
->root
.type
== bfd_link_hash_undefweak
)
3194 eh
->dyn_relocs
= NULL
;
3196 else if (ELIMINATE_COPY_RELOCS
)
3198 /* For the non-shared case, discard space for relocs against
3199 symbols which turn out to need copy relocs or are not
3202 if ((h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0
3203 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
3204 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
3206 /* Make sure this symbol is output as a dynamic symbol.
3207 Undefined weak syms won't yet be marked as dynamic. */
3208 if (h
->dynindx
== -1
3209 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
3211 if (! bfd_elf64_link_record_dynamic_symbol (info
, h
))
3215 /* If that succeeded, we know we'll be keeping all the
3217 if (h
->dynindx
!= -1)
3221 eh
->dyn_relocs
= NULL
;
3226 /* Finally, allocate space. */
3227 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
3229 asection
*sreloc
= elf_section_data (p
->sec
)->sreloc
;
3230 sreloc
->_raw_size
+= p
->count
* sizeof (Elf32_External_Rela
);
3236 /* Find any dynamic relocs that apply to read-only sections. */
3239 readonly_dynrelocs (struct elf_link_hash_entry
*h
, void *info
)
3241 struct ppc_elf_dyn_relocs
*p
;
3243 if (h
->root
.type
== bfd_link_hash_indirect
)
3246 if (h
->root
.type
== bfd_link_hash_warning
)
3247 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
3249 for (p
= ppc_elf_hash_entry (h
)->dyn_relocs
; p
!= NULL
; p
= p
->next
)
3251 asection
*s
= p
->sec
->output_section
;
3254 && ((s
->flags
& (SEC_READONLY
| SEC_ALLOC
))
3255 == (SEC_READONLY
| SEC_ALLOC
)))
3257 ((struct bfd_link_info
*) info
)->flags
|= DF_TEXTREL
;
3259 /* Not an error, just cut short the traversal. */
3266 /* Set the sizes of the dynamic sections. */
3269 ppc_elf_size_dynamic_sections (bfd
*output_bfd ATTRIBUTE_UNUSED
,
3270 struct bfd_link_info
*info
)
3272 struct ppc_elf_link_hash_table
*htab
;
3278 fprintf (stderr
, "ppc_elf_size_dynamic_sections called\n");
3281 htab
= ppc_elf_hash_table (info
);
3282 BFD_ASSERT (htab
->elf
.dynobj
!= NULL
);
3284 if (elf_hash_table (info
)->dynamic_sections_created
)
3286 /* Set the contents of the .interp section to the interpreter. */
3287 if (info
->executable
)
3289 s
= bfd_get_section_by_name (htab
->elf
.dynobj
, ".interp");
3290 BFD_ASSERT (s
!= NULL
);
3291 s
->_raw_size
= sizeof ELF_DYNAMIC_INTERPRETER
;
3292 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
3296 if (htab
->tlsld_got
.refcount
> 0)
3298 htab
->tlsld_got
.offset
= htab
->got
->_raw_size
;
3299 htab
->got
->_raw_size
+= 8;
3301 htab
->relgot
->_raw_size
+= sizeof (Elf32_External_Rela
);
3304 htab
->tlsld_got
.offset
= (bfd_vma
) -1;
3306 /* Set up .got offsets for local syms, and space for local dynamic
3308 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
3310 bfd_signed_vma
*local_got
;
3311 bfd_signed_vma
*end_local_got
;
3313 bfd_size_type locsymcount
;
3314 Elf_Internal_Shdr
*symtab_hdr
;
3317 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
)
3320 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
3322 struct ppc_elf_dyn_relocs
*p
;
3324 for (p
= ((struct ppc_elf_dyn_relocs
*)
3325 elf_section_data (s
)->local_dynrel
);
3329 if (!bfd_is_abs_section (p
->sec
)
3330 && bfd_is_abs_section (p
->sec
->output_section
))
3332 /* Input section has been discarded, either because
3333 it is a copy of a linkonce section or due to
3334 linker script /DISCARD/, so we'll be discarding
3337 else if (p
->count
!= 0)
3339 elf_section_data (p
->sec
)->sreloc
->_raw_size
3340 += p
->count
* sizeof (Elf32_External_Rela
);
3341 if ((p
->sec
->output_section
->flags
3342 & (SEC_READONLY
| SEC_ALLOC
))
3343 == (SEC_READONLY
| SEC_ALLOC
))
3344 info
->flags
|= DF_TEXTREL
;
3349 local_got
= elf_local_got_refcounts (ibfd
);
3353 symtab_hdr
= &elf_tdata (ibfd
)->symtab_hdr
;
3354 locsymcount
= symtab_hdr
->sh_info
;
3355 end_local_got
= local_got
+ locsymcount
;
3356 lgot_masks
= (char *) end_local_got
;
3358 srel
= htab
->relgot
;
3359 for (; local_got
< end_local_got
; ++local_got
, ++lgot_masks
)
3362 if (*lgot_masks
== (TLS_TLS
| TLS_LD
))
3364 /* If just an LD reloc, we'll just use
3365 htab->tlsld_got.offset. */
3366 if (htab
->tlsld_got
.offset
== (bfd_vma
) -1)
3368 htab
->tlsld_got
.offset
= s
->_raw_size
;
3371 srel
->_raw_size
+= sizeof (Elf32_External_Rela
);
3373 *local_got
= (bfd_vma
) -1;
3377 *local_got
= s
->_raw_size
;
3378 if ((*lgot_masks
& TLS_TLS
) != 0)
3380 if ((*lgot_masks
& TLS_GD
) != 0)
3382 if ((*lgot_masks
& (TLS_TPREL
| TLS_TPRELGD
)) != 0)
3384 if ((*lgot_masks
& TLS_DTPREL
) != 0)
3390 srel
->_raw_size
+= ((s
->_raw_size
- *local_got
) / 4
3391 * sizeof (Elf32_External_Rela
));
3395 *local_got
= (bfd_vma
) -1;
3398 /* Allocate space for global sym dynamic relocs. */
3399 elf_link_hash_traverse (elf_hash_table (info
), allocate_dynrelocs
, info
);
3401 /* We've now determined the sizes of the various dynamic sections.
3402 Allocate memory for them. */
3404 for (s
= htab
->elf
.dynobj
->sections
; s
!= NULL
; s
= s
->next
)
3406 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
3411 || (htab
->sdata
!= NULL
&& s
== htab
->sdata
->section
)
3412 || (htab
->sdata2
!= NULL
&& s
== htab
->sdata2
->section
))
3414 /* Strip this section if we don't need it; see the
3417 else if (strncmp (bfd_get_section_name (dynobj
, s
), ".rela", 5) == 0)
3419 if (s
->_raw_size
== 0)
3421 /* If we don't need this section, strip it from the
3422 output file. This is mostly to handle .rela.bss and
3423 .rela.plt. We must create both sections in
3424 create_dynamic_sections, because they must be created
3425 before the linker maps input sections to output
3426 sections. The linker does that before
3427 adjust_dynamic_symbol is called, and it is that
3428 function which decides whether anything needs to go
3429 into these sections. */
3433 /* Remember whether there are any relocation sections. */
3436 /* We use the reloc_count field as a counter if we need
3437 to copy relocs into the output file. */
3443 /* It's not one of our sections, so don't allocate space. */
3447 if (s
->_raw_size
== 0)
3449 _bfd_strip_section_from_output (info
, s
);
3453 /* Allocate memory for the section contents. */
3454 s
->contents
= bfd_zalloc (htab
->elf
.dynobj
, s
->_raw_size
);
3455 if (s
->contents
== NULL
)
3459 if (htab
->elf
.dynamic_sections_created
)
3461 /* Add some entries to the .dynamic section. We fill in the
3462 values later, in ppc_elf_finish_dynamic_sections, but we
3463 must add the entries now so that we get the correct size for
3464 the .dynamic section. The DT_DEBUG entry is filled in by the
3465 dynamic linker and used by the debugger. */
3466 #define add_dynamic_entry(TAG, VAL) \
3467 bfd_elf32_add_dynamic_entry (info, (TAG), (VAL))
3469 if (info
->executable
)
3471 if (!add_dynamic_entry (DT_DEBUG
, 0))
3475 if (htab
->plt
!= NULL
&& htab
->plt
->_raw_size
!= 0)
3477 if (!add_dynamic_entry (DT_PLTGOT
, 0)
3478 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
3479 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
3480 || !add_dynamic_entry (DT_JMPREL
, 0))
3486 if (!add_dynamic_entry (DT_RELA
, 0)
3487 || !add_dynamic_entry (DT_RELASZ
, 0)
3488 || !add_dynamic_entry (DT_RELAENT
, sizeof (Elf32_External_Rela
)))
3492 /* If any dynamic relocs apply to a read-only section, then we
3493 need a DT_TEXTREL entry. */
3494 if ((info
->flags
& DF_TEXTREL
) == 0)
3495 elf_link_hash_traverse (elf_hash_table (info
), readonly_dynrelocs
,
3498 if ((info
->flags
& DF_TEXTREL
) != 0)
3500 if (!add_dynamic_entry (DT_TEXTREL
, 0))
3504 #undef add_dynamic_entry
3510 update_local_sym_info (bfd
*abfd
,
3511 Elf_Internal_Shdr
*symtab_hdr
,
3512 unsigned long r_symndx
,
3515 bfd_signed_vma
*local_got_refcounts
= elf_local_got_refcounts (abfd
);
3516 char *local_got_tls_masks
;
3518 if (local_got_refcounts
== NULL
)
3520 bfd_size_type size
= symtab_hdr
->sh_info
;
3522 size
*= sizeof (*local_got_refcounts
) + sizeof (*local_got_tls_masks
);
3523 local_got_refcounts
= bfd_zalloc (abfd
, size
);
3524 if (local_got_refcounts
== NULL
)
3526 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
3529 local_got_refcounts
[r_symndx
] += 1;
3530 local_got_tls_masks
= (char *) (local_got_refcounts
+ symtab_hdr
->sh_info
);
3531 local_got_tls_masks
[r_symndx
] |= tls_type
;
3536 bad_shared_reloc (bfd
*abfd
, enum elf_ppc_reloc_type r_type
)
3538 (*_bfd_error_handler
)
3539 (_("%s: relocation %s cannot be used when making a shared object"),
3540 bfd_archive_filename (abfd
),
3541 ppc_elf_howto_table
[r_type
]->name
);
3542 bfd_set_error (bfd_error_bad_value
);
3545 /* Look through the relocs for a section during the first phase, and
3546 allocate space in the global offset table or procedure linkage
3550 ppc_elf_check_relocs (bfd
*abfd
,
3551 struct bfd_link_info
*info
,
3553 const Elf_Internal_Rela
*relocs
)
3555 struct ppc_elf_link_hash_table
*htab
;
3556 Elf_Internal_Shdr
*symtab_hdr
;
3557 struct elf_link_hash_entry
**sym_hashes
;
3558 const Elf_Internal_Rela
*rel
;
3559 const Elf_Internal_Rela
*rel_end
;
3562 if (info
->relocatable
)
3566 fprintf (stderr
, "ppc_elf_check_relocs called for section %s in %s\n",
3567 bfd_get_section_name (abfd
, sec
),
3568 bfd_archive_filename (abfd
));
3571 /* Initialize howto table if not already done. */
3572 if (!ppc_elf_howto_table
[R_PPC_ADDR32
])
3573 ppc_elf_howto_init ();
3575 /* Create the linker generated sections all the time so that the
3576 special symbols are created. */
3577 htab
= ppc_elf_hash_table (info
);
3578 if (htab
->sdata
== NULL
)
3580 htab
->sdata
= ppc_elf_create_linker_section (abfd
, info
,
3581 LINKER_SECTION_SDATA
);
3582 if (htab
->sdata
== NULL
)
3586 if (htab
->sdata2
== NULL
)
3588 htab
->sdata2
= ppc_elf_create_linker_section (abfd
, info
,
3589 LINKER_SECTION_SDATA2
);
3590 if (htab
->sdata2
== NULL
)
3594 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
3595 sym_hashes
= elf_sym_hashes (abfd
);
3598 rel_end
= relocs
+ sec
->reloc_count
;
3599 for (rel
= relocs
; rel
< rel_end
; rel
++)
3601 unsigned long r_symndx
;
3602 enum elf_ppc_reloc_type r_type
;
3603 struct elf_link_hash_entry
*h
;
3606 r_symndx
= ELF32_R_SYM (rel
->r_info
);
3607 if (r_symndx
< symtab_hdr
->sh_info
)
3610 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
3612 /* If a relocation refers to _GLOBAL_OFFSET_TABLE_, create the .got.
3613 This shows up in particular in an R_PPC_ADDR32 in the eabi
3615 if (h
&& strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
3617 if (htab
->got
== NULL
)
3619 if (htab
->elf
.dynobj
== NULL
)
3620 htab
->elf
.dynobj
= abfd
;
3621 if (!ppc_elf_create_got (htab
->elf
.dynobj
, info
))
3626 r_type
= ELF32_R_TYPE (rel
->r_info
);
3629 case R_PPC_GOT_TLSLD16
:
3630 case R_PPC_GOT_TLSLD16_LO
:
3631 case R_PPC_GOT_TLSLD16_HI
:
3632 case R_PPC_GOT_TLSLD16_HA
:
3633 htab
->tlsld_got
.refcount
+= 1;
3634 tls_type
= TLS_TLS
| TLS_LD
;
3637 case R_PPC_GOT_TLSGD16
:
3638 case R_PPC_GOT_TLSGD16_LO
:
3639 case R_PPC_GOT_TLSGD16_HI
:
3640 case R_PPC_GOT_TLSGD16_HA
:
3641 tls_type
= TLS_TLS
| TLS_GD
;
3644 case R_PPC_GOT_TPREL16
:
3645 case R_PPC_GOT_TPREL16_LO
:
3646 case R_PPC_GOT_TPREL16_HI
:
3647 case R_PPC_GOT_TPREL16_HA
:
3649 info
->flags
|= DF_STATIC_TLS
;
3650 tls_type
= TLS_TLS
| TLS_TPREL
;
3653 case R_PPC_GOT_DTPREL16
:
3654 case R_PPC_GOT_DTPREL16_LO
:
3655 case R_PPC_GOT_DTPREL16_HI
:
3656 case R_PPC_GOT_DTPREL16_HA
:
3657 tls_type
= TLS_TLS
| TLS_DTPREL
;
3659 sec
->has_tls_reloc
= 1;
3662 /* GOT16 relocations */
3664 case R_PPC_GOT16_LO
:
3665 case R_PPC_GOT16_HI
:
3666 case R_PPC_GOT16_HA
:
3667 /* This symbol requires a global offset table entry. */
3668 if (htab
->got
== NULL
)
3670 if (htab
->elf
.dynobj
== NULL
)
3671 htab
->elf
.dynobj
= abfd
;
3672 if (!ppc_elf_create_got (htab
->elf
.dynobj
, info
))
3677 h
->got
.refcount
+= 1;
3678 ppc_elf_hash_entry (h
)->tls_mask
|= tls_type
;
3681 /* This is a global offset table entry for a local symbol. */
3682 if (!update_local_sym_info (abfd
, symtab_hdr
, r_symndx
, tls_type
))
3686 /* Indirect .sdata relocation. */
3687 case R_PPC_EMB_SDAI16
:
3690 bad_shared_reloc (abfd
, r_type
);
3693 if (!elf_create_pointer_linker_section (abfd
, info
,
3694 htab
->sdata
, h
, rel
))
3698 /* Indirect .sdata2 relocation. */
3699 case R_PPC_EMB_SDA2I16
:
3702 bad_shared_reloc (abfd
, r_type
);
3705 if (!elf_create_pointer_linker_section (abfd
, info
,
3706 htab
->sdata2
, h
, rel
))
3710 case R_PPC_SDAREL16
:
3711 case R_PPC_EMB_SDA2REL
:
3712 case R_PPC_EMB_SDA21
:
3713 case R_PPC_EMB_RELSDA
:
3714 case R_PPC_EMB_NADDR32
:
3715 case R_PPC_EMB_NADDR16
:
3716 case R_PPC_EMB_NADDR16_LO
:
3717 case R_PPC_EMB_NADDR16_HI
:
3718 case R_PPC_EMB_NADDR16_HA
:
3721 bad_shared_reloc (abfd
, r_type
);
3727 case R_PPC_PLTREL24
:
3728 case R_PPC_PLTREL32
:
3729 case R_PPC_PLT16_LO
:
3730 case R_PPC_PLT16_HI
:
3731 case R_PPC_PLT16_HA
:
3733 fprintf (stderr
, "Reloc requires a PLT entry\n");
3735 /* This symbol requires a procedure linkage table entry. We
3736 actually build the entry in finish_dynamic_symbol,
3737 because this might be a case of linking PIC code without
3738 linking in any dynamic objects, in which case we don't
3739 need to generate a procedure linkage table after all. */
3743 /* It does not make sense to have a procedure linkage
3744 table entry for a local symbol. */
3745 (*_bfd_error_handler
) (_("%s(%s+0x%lx): %s reloc against "
3747 bfd_archive_filename (abfd
),
3749 (long) rel
->r_offset
,
3750 ppc_elf_howto_table
[r_type
]->name
);
3751 bfd_set_error (bfd_error_bad_value
);
3755 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
3759 /* The following relocations don't need to propagate the
3760 relocation if linking a shared object since they are
3761 section relative. */
3763 case R_PPC_SECTOFF_LO
:
3764 case R_PPC_SECTOFF_HI
:
3765 case R_PPC_SECTOFF_HA
:
3766 case R_PPC_DTPREL16
:
3767 case R_PPC_DTPREL16_LO
:
3768 case R_PPC_DTPREL16_HI
:
3769 case R_PPC_DTPREL16_HA
:
3773 /* This are just markers. */
3775 case R_PPC_EMB_MRKREF
:
3780 /* These should only appear in dynamic objects. */
3782 case R_PPC_GLOB_DAT
:
3783 case R_PPC_JMP_SLOT
:
3784 case R_PPC_RELATIVE
:
3787 /* These aren't handled yet. We'll report an error later. */
3789 case R_PPC_EMB_RELSEC16
:
3790 case R_PPC_EMB_RELST_LO
:
3791 case R_PPC_EMB_RELST_HI
:
3792 case R_PPC_EMB_RELST_HA
:
3793 case R_PPC_EMB_BIT_FLD
:
3796 /* This refers only to functions defined in the shared library. */
3797 case R_PPC_LOCAL24PC
:
3800 /* This relocation describes the C++ object vtable hierarchy.
3801 Reconstruct it for later use during GC. */
3802 case R_PPC_GNU_VTINHERIT
:
3803 if (!_bfd_elf32_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
3807 /* This relocation describes which C++ vtable entries are actually
3808 used. Record for later use during GC. */
3809 case R_PPC_GNU_VTENTRY
:
3810 if (!_bfd_elf32_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
3814 /* We shouldn't really be seeing these. */
3817 info
->flags
|= DF_STATIC_TLS
;
3821 case R_PPC_DTPMOD32
:
3822 case R_PPC_DTPREL32
:
3826 case R_PPC_TPREL16_LO
:
3827 case R_PPC_TPREL16_HI
:
3828 case R_PPC_TPREL16_HA
:
3830 info
->flags
|= DF_STATIC_TLS
;
3833 /* When creating a shared object, we must copy these
3834 relocs into the output file. We create a reloc
3835 section in dynobj and make room for the reloc. */
3838 case R_PPC_REL14_BRTAKEN
:
3839 case R_PPC_REL14_BRNTAKEN
:
3842 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
3849 case R_PPC_ADDR16_LO
:
3850 case R_PPC_ADDR16_HI
:
3851 case R_PPC_ADDR16_HA
:
3853 case R_PPC_ADDR14_BRTAKEN
:
3854 case R_PPC_ADDR14_BRNTAKEN
:
3857 if (h
!= NULL
&& !info
->shared
)
3859 /* We may need a plt entry if the symbol turns out to be
3860 a function defined in a dynamic object. */
3863 /* We may need a copy reloc too. */
3864 h
->elf_link_hash_flags
|= ELF_LINK_NON_GOT_REF
;
3868 /* If we are creating a shared library, and this is a reloc
3869 against a global symbol, or a non PC relative reloc
3870 against a local symbol, then we need to copy the reloc
3871 into the shared library. However, if we are linking with
3872 -Bsymbolic, we do not need to copy a reloc against a
3873 global symbol which is defined in an object we are
3874 including in the link (i.e., DEF_REGULAR is set). At
3875 this point we have not seen all the input files, so it is
3876 possible that DEF_REGULAR is not set now but will be set
3877 later (it is never cleared). In case of a weak definition,
3878 DEF_REGULAR may be cleared later by a strong definition in
3879 a shared library. We account for that possibility below by
3880 storing information in the dyn_relocs field of the hash
3881 table entry. A similar situation occurs when creating
3882 shared libraries and symbol visibility changes render the
3885 If on the other hand, we are creating an executable, we
3886 may need to keep relocations for symbols satisfied by a
3887 dynamic library if we manage to avoid copy relocs for the
3890 && (MUST_BE_DYN_RELOC (r_type
)
3892 && (! info
->symbolic
3893 || h
->root
.type
== bfd_link_hash_defweak
3894 || (h
->elf_link_hash_flags
3895 & ELF_LINK_HASH_DEF_REGULAR
) == 0))))
3896 || (ELIMINATE_COPY_RELOCS
3898 && (sec
->flags
& SEC_ALLOC
) != 0
3900 && (h
->root
.type
== bfd_link_hash_defweak
3901 || (h
->elf_link_hash_flags
3902 & ELF_LINK_HASH_DEF_REGULAR
) == 0)))
3904 struct ppc_elf_dyn_relocs
*p
;
3905 struct ppc_elf_dyn_relocs
**head
;
3909 "ppc_elf_check_relocs needs to "
3910 "create relocation for %s\n",
3911 (h
&& h
->root
.root
.string
3912 ? h
->root
.root
.string
: "<unknown>"));
3918 name
= (bfd_elf_string_from_elf_section
3920 elf_elfheader (abfd
)->e_shstrndx
,
3921 elf_section_data (sec
)->rel_hdr
.sh_name
));
3925 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
3926 && strcmp (bfd_get_section_name (abfd
, sec
),
3929 sreloc
= bfd_get_section_by_name (htab
->elf
.dynobj
, name
);
3934 sreloc
= bfd_make_section (htab
->elf
.dynobj
, name
);
3935 flags
= (SEC_HAS_CONTENTS
| SEC_READONLY
3936 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
3937 if ((sec
->flags
& SEC_ALLOC
) != 0)
3938 flags
|= SEC_ALLOC
| SEC_LOAD
;
3940 || ! bfd_set_section_flags (htab
->elf
.dynobj
,
3942 || ! bfd_set_section_alignment (htab
->elf
.dynobj
,
3946 elf_section_data (sec
)->sreloc
= sreloc
;
3949 /* If this is a global symbol, we count the number of
3950 relocations we need for this symbol. */
3953 head
= &ppc_elf_hash_entry (h
)->dyn_relocs
;
3957 /* Track dynamic relocs needed for local syms too.
3958 We really need local syms available to do this
3962 s
= bfd_section_from_r_symndx (abfd
, &htab
->sym_sec
,
3967 head
= ((struct ppc_elf_dyn_relocs
**)
3968 &elf_section_data (s
)->local_dynrel
);
3972 if (p
== NULL
|| p
->sec
!= sec
)
3974 p
= bfd_alloc (htab
->elf
.dynobj
, sizeof *p
);
3985 if (!MUST_BE_DYN_RELOC (r_type
))
3996 /* Return the section that should be marked against GC for a given
4000 ppc_elf_gc_mark_hook (asection
*sec
,
4001 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
4002 Elf_Internal_Rela
*rel
,
4003 struct elf_link_hash_entry
*h
,
4004 Elf_Internal_Sym
*sym
)
4008 switch (ELF32_R_TYPE (rel
->r_info
))
4010 case R_PPC_GNU_VTINHERIT
:
4011 case R_PPC_GNU_VTENTRY
:
4015 switch (h
->root
.type
)
4017 case bfd_link_hash_defined
:
4018 case bfd_link_hash_defweak
:
4019 return h
->root
.u
.def
.section
;
4021 case bfd_link_hash_common
:
4022 return h
->root
.u
.c
.p
->section
;
4030 return bfd_section_from_elf_index (sec
->owner
, sym
->st_shndx
);
4035 /* Update the got, plt and dynamic reloc reference counts for the
4036 section being removed. */
4039 ppc_elf_gc_sweep_hook (bfd
*abfd
,
4040 struct bfd_link_info
*info
,
4042 const Elf_Internal_Rela
*relocs
)
4044 struct ppc_elf_link_hash_table
*htab
;
4045 Elf_Internal_Shdr
*symtab_hdr
;
4046 struct elf_link_hash_entry
**sym_hashes
;
4047 bfd_signed_vma
*local_got_refcounts
;
4048 const Elf_Internal_Rela
*rel
, *relend
;
4050 elf_section_data (sec
)->local_dynrel
= NULL
;
4052 htab
= ppc_elf_hash_table (info
);
4053 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
4054 sym_hashes
= elf_sym_hashes (abfd
);
4055 local_got_refcounts
= elf_local_got_refcounts (abfd
);
4057 relend
= relocs
+ sec
->reloc_count
;
4058 for (rel
= relocs
; rel
< relend
; rel
++)
4060 unsigned long r_symndx
;
4061 enum elf_ppc_reloc_type r_type
;
4062 struct elf_link_hash_entry
*h
= NULL
;
4064 r_symndx
= ELF32_R_SYM (rel
->r_info
);
4065 if (r_symndx
>= symtab_hdr
->sh_info
)
4067 struct ppc_elf_dyn_relocs
**pp
, *p
;
4068 struct ppc_elf_link_hash_entry
*eh
;
4070 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
4071 eh
= (struct ppc_elf_link_hash_entry
*) h
;
4073 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; pp
= &p
->next
)
4076 /* Everything must go for SEC. */
4082 r_type
= ELF32_R_TYPE (rel
->r_info
);
4085 case R_PPC_GOT_TLSLD16
:
4086 case R_PPC_GOT_TLSLD16_LO
:
4087 case R_PPC_GOT_TLSLD16_HI
:
4088 case R_PPC_GOT_TLSLD16_HA
:
4089 htab
->tlsld_got
.refcount
-= 1;
4092 case R_PPC_GOT_TLSGD16
:
4093 case R_PPC_GOT_TLSGD16_LO
:
4094 case R_PPC_GOT_TLSGD16_HI
:
4095 case R_PPC_GOT_TLSGD16_HA
:
4096 case R_PPC_GOT_TPREL16
:
4097 case R_PPC_GOT_TPREL16_LO
:
4098 case R_PPC_GOT_TPREL16_HI
:
4099 case R_PPC_GOT_TPREL16_HA
:
4100 case R_PPC_GOT_DTPREL16
:
4101 case R_PPC_GOT_DTPREL16_LO
:
4102 case R_PPC_GOT_DTPREL16_HI
:
4103 case R_PPC_GOT_DTPREL16_HA
:
4105 case R_PPC_GOT16_LO
:
4106 case R_PPC_GOT16_HI
:
4107 case R_PPC_GOT16_HA
:
4110 if (h
->got
.refcount
> 0)
4113 else if (local_got_refcounts
!= NULL
)
4115 if (local_got_refcounts
[r_symndx
] > 0)
4116 local_got_refcounts
[r_symndx
]--;
4122 case R_PPC_REL14_BRTAKEN
:
4123 case R_PPC_REL14_BRNTAKEN
:
4126 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
4133 case R_PPC_ADDR16_LO
:
4134 case R_PPC_ADDR16_HI
:
4135 case R_PPC_ADDR16_HA
:
4137 case R_PPC_ADDR14_BRTAKEN
:
4138 case R_PPC_ADDR14_BRNTAKEN
:
4142 case R_PPC_PLTREL24
:
4143 case R_PPC_PLT16_LO
:
4144 case R_PPC_PLT16_HI
:
4145 case R_PPC_PLT16_HA
:
4148 if (h
->plt
.refcount
> 0)
4160 /* Set htab->tls_get_addr and call the generic ELF tls_setup function. */
4163 ppc_elf_tls_setup (bfd
*obfd
, struct bfd_link_info
*info
)
4165 struct ppc_elf_link_hash_table
*htab
;
4167 htab
= ppc_elf_hash_table (info
);
4168 htab
->tls_get_addr
= elf_link_hash_lookup (&htab
->elf
, "__tls_get_addr",
4169 FALSE
, FALSE
, TRUE
);
4171 return _bfd_elf_tls_setup (obfd
, info
);
4174 /* Run through all the TLS relocs looking for optimization
4178 ppc_elf_tls_optimize (bfd
*obfd ATTRIBUTE_UNUSED
,
4179 struct bfd_link_info
*info
)
4183 struct ppc_elf_link_hash_table
*htab
;
4185 if (info
->relocatable
|| info
->shared
)
4188 htab
= ppc_elf_hash_table (info
);
4189 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
4191 Elf_Internal_Sym
*locsyms
= NULL
;
4192 Elf_Internal_Shdr
*symtab_hdr
= &elf_tdata (ibfd
)->symtab_hdr
;
4194 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
4195 if (sec
->has_tls_reloc
&& !bfd_is_abs_section (sec
->output_section
))
4197 Elf_Internal_Rela
*relstart
, *rel
, *relend
;
4198 int expecting_tls_get_addr
;
4200 /* Read the relocations. */
4201 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
4203 if (relstart
== NULL
)
4206 expecting_tls_get_addr
= 0;
4207 relend
= relstart
+ sec
->reloc_count
;
4208 for (rel
= relstart
; rel
< relend
; rel
++)
4210 enum elf_ppc_reloc_type r_type
;
4211 unsigned long r_symndx
;
4212 struct elf_link_hash_entry
*h
= NULL
;
4214 char tls_set
, tls_clear
;
4215 bfd_boolean is_local
;
4217 r_symndx
= ELF32_R_SYM (rel
->r_info
);
4218 if (r_symndx
>= symtab_hdr
->sh_info
)
4220 struct elf_link_hash_entry
**sym_hashes
;
4222 sym_hashes
= elf_sym_hashes (ibfd
);
4223 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
4224 while (h
->root
.type
== bfd_link_hash_indirect
4225 || h
->root
.type
== bfd_link_hash_warning
)
4226 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
4231 || !(h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
))
4234 r_type
= ELF32_R_TYPE (rel
->r_info
);
4237 case R_PPC_GOT_TLSLD16
:
4238 case R_PPC_GOT_TLSLD16_LO
:
4239 case R_PPC_GOT_TLSLD16_HI
:
4240 case R_PPC_GOT_TLSLD16_HA
:
4241 /* These relocs should never be against a symbol
4242 defined in a shared lib. Leave them alone if
4243 that turns out to be the case. */
4244 expecting_tls_get_addr
= 0;
4245 htab
->tlsld_got
.refcount
-= 1;
4252 expecting_tls_get_addr
= 1;
4255 case R_PPC_GOT_TLSGD16
:
4256 case R_PPC_GOT_TLSGD16_LO
:
4257 case R_PPC_GOT_TLSGD16_HI
:
4258 case R_PPC_GOT_TLSGD16_HA
:
4264 tls_set
= TLS_TLS
| TLS_TPRELGD
;
4266 expecting_tls_get_addr
= 1;
4269 case R_PPC_GOT_TPREL16
:
4270 case R_PPC_GOT_TPREL16_LO
:
4271 case R_PPC_GOT_TPREL16_HI
:
4272 case R_PPC_GOT_TPREL16_HA
:
4273 expecting_tls_get_addr
= 0;
4278 tls_clear
= TLS_TPREL
;
4285 case R_PPC_REL14_BRTAKEN
:
4286 case R_PPC_REL14_BRNTAKEN
:
4288 if (expecting_tls_get_addr
4290 && h
== htab
->tls_get_addr
)
4292 if (h
->plt
.refcount
> 0)
4293 h
->plt
.refcount
-= 1;
4295 expecting_tls_get_addr
= 0;
4299 expecting_tls_get_addr
= 0;
4307 /* We managed to get rid of a got entry. */
4308 if (h
->got
.refcount
> 0)
4309 h
->got
.refcount
-= 1;
4311 tls_mask
= &ppc_elf_hash_entry (h
)->tls_mask
;
4315 Elf_Internal_Sym
*sym
;
4316 bfd_signed_vma
*lgot_refs
;
4319 if (locsyms
== NULL
)
4321 locsyms
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
4322 if (locsyms
== NULL
)
4323 locsyms
= bfd_elf_get_elf_syms (ibfd
, symtab_hdr
,
4324 symtab_hdr
->sh_info
,
4325 0, NULL
, NULL
, NULL
);
4326 if (locsyms
== NULL
)
4328 if (elf_section_data (sec
)->relocs
!= relstart
)
4333 sym
= locsyms
+ r_symndx
;
4334 lgot_refs
= elf_local_got_refcounts (ibfd
);
4335 if (lgot_refs
== NULL
)
4339 /* We managed to get rid of a got entry. */
4340 if (lgot_refs
[r_symndx
] > 0)
4341 lgot_refs
[r_symndx
] -= 1;
4343 lgot_masks
= (char *) (lgot_refs
+ symtab_hdr
->sh_info
);
4344 tls_mask
= &lgot_masks
[r_symndx
];
4347 *tls_mask
|= tls_set
;
4348 *tls_mask
&= ~tls_clear
;
4351 if (elf_section_data (sec
)->relocs
!= relstart
)
4356 && (symtab_hdr
->contents
!= (unsigned char *) locsyms
))
4358 if (!info
->keep_memory
)
4361 symtab_hdr
->contents
= (unsigned char *) locsyms
;
4367 /* Hook called by the linker routine which adds symbols from an object
4368 file. We use it to put .comm items in .sbss, and not .bss. */
4371 ppc_elf_add_symbol_hook (bfd
*abfd
,
4372 struct bfd_link_info
*info
,
4373 const Elf_Internal_Sym
*sym
,
4374 const char **namep ATTRIBUTE_UNUSED
,
4375 flagword
*flagsp ATTRIBUTE_UNUSED
,
4379 if (sym
->st_shndx
== SHN_COMMON
4380 && !info
->relocatable
4381 && sym
->st_size
<= elf_gp_size (abfd
)
4382 && (info
->hash
->creator
== abfd
->xvec
4383 || info
->hash
->creator
== abfd
->xvec
->alternative_target
))
4385 /* Common symbols less than or equal to -G nn bytes are automatically
4387 struct ppc_elf_link_hash_table
*htab
;
4389 htab
= ppc_elf_hash_table (info
);
4390 if (htab
->sbss
== NULL
)
4392 flagword flags
= SEC_IS_COMMON
;
4394 htab
->sbss
= bfd_make_section_anyway (abfd
, ".sbss");
4395 if (htab
->sbss
== NULL
4396 || ! bfd_set_section_flags (abfd
, htab
->sbss
, flags
))
4401 *valp
= sym
->st_size
;
4407 /* Finish up dynamic symbol handling. We set the contents of various
4408 dynamic sections here. */
4411 ppc_elf_finish_dynamic_symbol (bfd
*output_bfd
,
4412 struct bfd_link_info
*info
,
4413 struct elf_link_hash_entry
*h
,
4414 Elf_Internal_Sym
*sym
)
4416 struct ppc_elf_link_hash_table
*htab
;
4419 fprintf (stderr
, "ppc_elf_finish_dynamic_symbol called for %s",
4420 h
->root
.root
.string
);
4423 htab
= ppc_elf_hash_table (info
);
4424 BFD_ASSERT (htab
->elf
.dynobj
!= NULL
);
4426 if (h
->plt
.offset
!= (bfd_vma
) -1)
4428 Elf_Internal_Rela rela
;
4430 bfd_vma reloc_index
;
4433 fprintf (stderr
, ", plt_offset = %d", h
->plt
.offset
);
4436 /* This symbol has an entry in the procedure linkage table. Set
4439 BFD_ASSERT (h
->dynindx
!= -1);
4440 BFD_ASSERT (htab
->plt
!= NULL
&& htab
->relplt
!= NULL
);
4442 /* We don't need to fill in the .plt. The ppc dynamic linker
4445 /* Fill in the entry in the .rela.plt section. */
4446 rela
.r_offset
= (htab
->plt
->output_section
->vma
4447 + htab
->plt
->output_offset
4449 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_PPC_JMP_SLOT
);
4452 reloc_index
= (h
->plt
.offset
- PLT_INITIAL_ENTRY_SIZE
) / PLT_SLOT_SIZE
;
4453 if (reloc_index
> PLT_NUM_SINGLE_ENTRIES
)
4454 reloc_index
-= (reloc_index
- PLT_NUM_SINGLE_ENTRIES
) / 2;
4455 loc
= (htab
->relplt
->contents
4456 + reloc_index
* sizeof (Elf32_External_Rela
));
4457 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
4459 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
4461 /* Mark the symbol as undefined, rather than as defined in
4462 the .plt section. Leave the value alone. */
4463 sym
->st_shndx
= SHN_UNDEF
;
4464 /* If the symbol is weak, we do need to clear the value.
4465 Otherwise, the PLT entry would provide a definition for
4466 the symbol even if the symbol wasn't defined anywhere,
4467 and so the symbol would never be NULL. */
4468 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_REF_REGULAR_NONWEAK
)
4474 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_COPY
) != 0)
4477 Elf_Internal_Rela rela
;
4480 /* This symbols needs a copy reloc. Set it up. */
4483 fprintf (stderr
, ", copy");
4486 BFD_ASSERT (h
->dynindx
!= -1);
4488 if (h
->size
<= elf_gp_size (htab
->elf
.dynobj
))
4492 BFD_ASSERT (s
!= NULL
);
4494 rela
.r_offset
= (h
->root
.u
.def
.value
4495 + h
->root
.u
.def
.section
->output_section
->vma
4496 + h
->root
.u
.def
.section
->output_offset
);
4497 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_PPC_COPY
);
4499 loc
= s
->contents
+ s
->reloc_count
++ * sizeof (Elf32_External_Rela
);
4500 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
4504 fprintf (stderr
, "\n");
4507 /* Mark some specially defined symbols as absolute. */
4508 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
4509 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0
4510 || strcmp (h
->root
.root
.string
, "_PROCEDURE_LINKAGE_TABLE_") == 0)
4511 sym
->st_shndx
= SHN_ABS
;
4516 /* Finish up the dynamic sections. */
4519 ppc_elf_finish_dynamic_sections (bfd
*output_bfd
,
4520 struct bfd_link_info
*info
)
4523 struct ppc_elf_link_hash_table
*htab
;
4526 fprintf (stderr
, "ppc_elf_finish_dynamic_sections called\n");
4529 htab
= ppc_elf_hash_table (info
);
4530 sdyn
= bfd_get_section_by_name (htab
->elf
.dynobj
, ".dynamic");
4532 if (htab
->elf
.dynamic_sections_created
)
4534 Elf32_External_Dyn
*dyncon
, *dynconend
;
4536 BFD_ASSERT (htab
->plt
!= NULL
&& sdyn
!= NULL
);
4538 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
4539 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
4540 for (; dyncon
< dynconend
; dyncon
++)
4542 Elf_Internal_Dyn dyn
;
4545 bfd_elf32_swap_dyn_in (htab
->elf
.dynobj
, dyncon
, &dyn
);
4551 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
4555 dyn
.d_un
.d_val
= htab
->relplt
->_raw_size
;
4560 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
4567 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
4571 /* Add a blrl instruction at _GLOBAL_OFFSET_TABLE_-4 so that a function can
4572 easily find the address of the _GLOBAL_OFFSET_TABLE_. */
4575 unsigned char *contents
= htab
->got
->contents
;
4576 bfd_put_32 (output_bfd
, 0x4e800021 /* blrl */, contents
);
4579 bfd_put_32 (output_bfd
, 0, contents
+ 4);
4581 bfd_put_32 (output_bfd
,
4582 sdyn
->output_section
->vma
+ sdyn
->output_offset
,
4585 elf_section_data (htab
->got
->output_section
)->this_hdr
.sh_entsize
= 4;
4591 /* The RELOCATE_SECTION function is called by the ELF backend linker
4592 to handle the relocations for a section.
4594 The relocs are always passed as Rela structures; if the section
4595 actually uses Rel structures, the r_addend field will always be
4598 This function is responsible for adjust the section contents as
4599 necessary, and (if using Rela relocs and generating a
4600 relocatable output file) adjusting the reloc addend as
4603 This function does not have to worry about setting the reloc
4604 address or the reloc symbol index.
4606 LOCAL_SYMS is a pointer to the swapped in local symbols.
4608 LOCAL_SECTIONS is an array giving the section in the input file
4609 corresponding to the st_shndx field of each local symbol.
4611 The global hash table entry for the global symbols can be found
4612 via elf_sym_hashes (input_bfd).
4614 When generating relocatable output, this function must handle
4615 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
4616 going to be the section symbol corresponding to the output
4617 section, which means that the addend must be adjusted
4621 ppc_elf_relocate_section (bfd
*output_bfd
,
4622 struct bfd_link_info
*info
,
4624 asection
*input_section
,
4626 Elf_Internal_Rela
*relocs
,
4627 Elf_Internal_Sym
*local_syms
,
4628 asection
**local_sections
)
4630 Elf_Internal_Shdr
*symtab_hdr
;
4631 struct elf_link_hash_entry
**sym_hashes
;
4632 struct ppc_elf_link_hash_table
*htab
;
4633 Elf_Internal_Rela
*rel
;
4634 Elf_Internal_Rela
*relend
;
4635 Elf_Internal_Rela outrel
;
4637 asection
*sreloc
= NULL
;
4638 bfd_vma
*local_got_offsets
;
4639 bfd_boolean ret
= TRUE
;
4642 fprintf (stderr
, "ppc_elf_relocate_section called for %s section %s, "
4643 "%ld relocations%s\n",
4644 bfd_archive_filename (input_bfd
),
4645 bfd_section_name(input_bfd
, input_section
),
4646 (long) input_section
->reloc_count
,
4647 (info
->relocatable
) ? " (relocatable)" : "");
4650 if (info
->relocatable
)
4653 /* Initialize howto table if not already done. */
4654 if (!ppc_elf_howto_table
[R_PPC_ADDR32
])
4655 ppc_elf_howto_init ();
4657 htab
= ppc_elf_hash_table (info
);
4658 local_got_offsets
= elf_local_got_offsets (input_bfd
);
4659 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
4660 sym_hashes
= elf_sym_hashes (input_bfd
);
4662 relend
= relocs
+ input_section
->reloc_count
;
4663 for (; rel
< relend
; rel
++)
4665 enum elf_ppc_reloc_type r_type
;
4667 bfd_reloc_status_type r
;
4668 Elf_Internal_Sym
*sym
;
4670 struct elf_link_hash_entry
*h
;
4671 const char *sym_name
;
4672 reloc_howto_type
*howto
;
4673 unsigned long r_symndx
;
4675 bfd_vma branch_bit
, insn
, from
;
4676 bfd_boolean unresolved_reloc
;
4678 unsigned int tls_type
, tls_mask
, tls_gd
;
4680 r_type
= ELF32_R_TYPE (rel
->r_info
);
4684 unresolved_reloc
= FALSE
;
4686 r_symndx
= ELF32_R_SYM (rel
->r_info
);
4688 if (r_symndx
< symtab_hdr
->sh_info
)
4690 sym
= local_syms
+ r_symndx
;
4691 sec
= local_sections
[r_symndx
];
4692 sym_name
= bfd_elf_local_sym_name (input_bfd
, sym
);
4694 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
4698 RELOC_FOR_GLOBAL_SYMBOL (h
, sym_hashes
, r_symndx
,
4699 symtab_hdr
, relocation
, sec
,
4700 unresolved_reloc
, info
,
4703 sym_name
= h
->root
.root
.string
;
4706 /* TLS optimizations. Replace instruction sequences and relocs
4707 based on information we collected in tls_optimize. We edit
4708 RELOCS so that --emit-relocs will output something sensible
4709 for the final instruction stream. */
4712 if (IS_PPC_TLS_RELOC (r_type
))
4715 tls_mask
= ((struct ppc_elf_link_hash_entry
*) h
)->tls_mask
;
4716 else if (local_got_offsets
!= NULL
)
4719 lgot_masks
= (char *) (local_got_offsets
+ symtab_hdr
->sh_info
);
4720 tls_mask
= lgot_masks
[r_symndx
];
4724 /* Ensure reloc mapping code below stays sane. */
4725 if ((R_PPC_GOT_TLSLD16
& 3) != (R_PPC_GOT_TLSGD16
& 3)
4726 || (R_PPC_GOT_TLSLD16_LO
& 3) != (R_PPC_GOT_TLSGD16_LO
& 3)
4727 || (R_PPC_GOT_TLSLD16_HI
& 3) != (R_PPC_GOT_TLSGD16_HI
& 3)
4728 || (R_PPC_GOT_TLSLD16_HA
& 3) != (R_PPC_GOT_TLSGD16_HA
& 3)
4729 || (R_PPC_GOT_TLSLD16
& 3) != (R_PPC_GOT_TPREL16
& 3)
4730 || (R_PPC_GOT_TLSLD16_LO
& 3) != (R_PPC_GOT_TPREL16_LO
& 3)
4731 || (R_PPC_GOT_TLSLD16_HI
& 3) != (R_PPC_GOT_TPREL16_HI
& 3)
4732 || (R_PPC_GOT_TLSLD16_HA
& 3) != (R_PPC_GOT_TPREL16_HA
& 3))
4739 case R_PPC_GOT_TPREL16
:
4740 case R_PPC_GOT_TPREL16_LO
:
4742 && (tls_mask
& TLS_TPREL
) == 0)
4745 insn
= bfd_get_32 (output_bfd
, contents
+ rel
->r_offset
- 2);
4747 insn
|= 0x3c020000; /* addis 0,2,0 */
4748 bfd_put_32 (output_bfd
, insn
, contents
+ rel
->r_offset
- 2);
4749 r_type
= R_PPC_TPREL16_HA
;
4750 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
4756 && (tls_mask
& TLS_TPREL
) == 0)
4759 insn
= bfd_get_32 (output_bfd
, contents
+ rel
->r_offset
);
4760 if ((insn
& ((31 << 26) | (31 << 11)))
4761 == ((31 << 26) | (2 << 11)))
4762 rtra
= insn
& ((1 << 26) - (1 << 16));
4763 else if ((insn
& ((31 << 26) | (31 << 16)))
4764 == ((31 << 26) | (2 << 16)))
4765 rtra
= (insn
& (31 << 21)) | ((insn
& (31 << 11)) << 5);
4768 if ((insn
& ((1 << 11) - (1 << 1))) == 266 << 1)
4771 else if ((insn
& (31 << 1)) == 23 << 1
4772 && ((insn
& (31 << 6)) < 14 << 6
4773 || ((insn
& (31 << 6)) >= 16 << 6
4774 && (insn
& (31 << 6)) < 24 << 6)))
4775 /* load and store indexed -> dform. */
4776 insn
= (32 | ((insn
>> 6) & 31)) << 26;
4777 else if ((insn
& (31 << 1)) == 21 << 1
4778 && (insn
& (0x1a << 6)) == 0)
4779 /* ldx, ldux, stdx, stdux -> ld, ldu, std, stdu. */
4780 insn
= (((58 | ((insn
>> 6) & 4)) << 26)
4781 | ((insn
>> 6) & 1));
4782 else if ((insn
& (31 << 1)) == 21 << 1
4783 && (insn
& ((1 << 11) - (1 << 1))) == 341 << 1)
4785 insn
= (58 << 26) | 2;
4789 bfd_put_32 (output_bfd
, insn
, contents
+ rel
->r_offset
);
4790 r_type
= R_PPC_TPREL16_LO
;
4791 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
4792 /* Was PPC_TLS which sits on insn boundary, now
4793 PPC_TPREL16_LO which is at insn+2. */
4798 case R_PPC_GOT_TLSGD16_HI
:
4799 case R_PPC_GOT_TLSGD16_HA
:
4800 tls_gd
= TLS_TPRELGD
;
4801 if (tls_mask
!= 0 && (tls_mask
& TLS_GD
) == 0)
4805 case R_PPC_GOT_TLSLD16_HI
:
4806 case R_PPC_GOT_TLSLD16_HA
:
4807 if (tls_mask
!= 0 && (tls_mask
& TLS_LD
) == 0)
4810 if ((tls_mask
& tls_gd
) != 0)
4811 r_type
= (((r_type
- (R_PPC_GOT_TLSGD16
& 3)) & 3)
4812 + R_PPC_GOT_TPREL16
);
4815 bfd_put_32 (output_bfd
, NOP
, contents
+ rel
->r_offset
);
4817 r_type
= R_PPC_NONE
;
4819 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
4823 case R_PPC_GOT_TLSGD16
:
4824 case R_PPC_GOT_TLSGD16_LO
:
4825 tls_gd
= TLS_TPRELGD
;
4826 if (tls_mask
!= 0 && (tls_mask
& TLS_GD
) == 0)
4827 goto tls_get_addr_check
;
4830 case R_PPC_GOT_TLSLD16
:
4831 case R_PPC_GOT_TLSLD16_LO
:
4832 if (tls_mask
!= 0 && (tls_mask
& TLS_LD
) == 0)
4835 if (rel
+ 1 < relend
)
4837 enum elf_ppc_reloc_type r_type2
;
4838 unsigned long r_symndx2
;
4839 struct elf_link_hash_entry
*h2
;
4840 bfd_vma insn1
, insn2
;
4843 /* The next instruction should be a call to
4844 __tls_get_addr. Peek at the reloc to be sure. */
4845 r_type2
= ELF32_R_TYPE (rel
[1].r_info
);
4846 r_symndx2
= ELF32_R_SYM (rel
[1].r_info
);
4847 if (r_symndx2
< symtab_hdr
->sh_info
4848 || (r_type2
!= R_PPC_REL14
4849 && r_type2
!= R_PPC_REL14_BRTAKEN
4850 && r_type2
!= R_PPC_REL14_BRNTAKEN
4851 && r_type2
!= R_PPC_REL24
4852 && r_type2
!= R_PPC_PLTREL24
))
4855 h2
= sym_hashes
[r_symndx2
- symtab_hdr
->sh_info
];
4856 while (h2
->root
.type
== bfd_link_hash_indirect
4857 || h2
->root
.type
== bfd_link_hash_warning
)
4858 h2
= (struct elf_link_hash_entry
*) h2
->root
.u
.i
.link
;
4859 if (h2
== NULL
|| h2
!= htab
->tls_get_addr
)
4862 /* OK, it checks out. Replace the call. */
4863 offset
= rel
[1].r_offset
;
4864 insn1
= bfd_get_32 (output_bfd
,
4865 contents
+ rel
->r_offset
- 2);
4866 if ((tls_mask
& tls_gd
) != 0)
4869 insn1
&= (1 << 26) - 1;
4870 insn1
|= 32 << 26; /* lwz */
4871 insn2
= 0x7c631214; /* add 3,3,2 */
4872 rel
[1].r_info
= ELF32_R_INFO (r_symndx2
, R_PPC_NONE
);
4873 r_type
= (((r_type
- (R_PPC_GOT_TLSGD16
& 3)) & 3)
4874 + R_PPC_GOT_TPREL16
);
4875 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
4880 insn1
= 0x3c620000; /* addis 3,2,0 */
4881 insn2
= 0x38630000; /* addi 3,3,0 */
4884 /* Was an LD reloc. */
4886 rel
->r_addend
= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
4887 rel
[1].r_addend
= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
4889 r_type
= R_PPC_TPREL16_HA
;
4890 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
4891 rel
[1].r_info
= ELF32_R_INFO (r_symndx
,
4893 rel
[1].r_offset
+= 2;
4895 bfd_put_32 (output_bfd
, insn1
, contents
+ rel
->r_offset
- 2);
4896 bfd_put_32 (output_bfd
, insn2
, contents
+ offset
);
4899 /* We changed the symbol on an LD reloc. Start over
4900 in order to get h, sym, sec etc. right. */
4909 /* Handle other relocations that tweak non-addend part of insn. */
4916 /* Branch taken prediction relocations. */
4917 case R_PPC_ADDR14_BRTAKEN
:
4918 case R_PPC_REL14_BRTAKEN
:
4919 branch_bit
= BRANCH_PREDICT_BIT
;
4922 /* Branch not taken predicition relocations. */
4923 case R_PPC_ADDR14_BRNTAKEN
:
4924 case R_PPC_REL14_BRNTAKEN
:
4925 insn
= bfd_get_32 (output_bfd
, contents
+ rel
->r_offset
);
4926 insn
&= ~BRANCH_PREDICT_BIT
;
4929 from
= (rel
->r_offset
4930 + input_section
->output_offset
4931 + input_section
->output_section
->vma
);
4933 /* Invert 'y' bit if not the default. */
4934 if ((bfd_signed_vma
) (relocation
+ rel
->r_addend
- from
) < 0)
4935 insn
^= BRANCH_PREDICT_BIT
;
4937 bfd_put_32 (output_bfd
, insn
, contents
+ rel
->r_offset
);
4941 addend
= rel
->r_addend
;
4944 if (r_type
< R_PPC_max
)
4945 howto
= ppc_elf_howto_table
[r_type
];
4949 (*_bfd_error_handler
)
4950 (_("%s: unknown relocation type %d for symbol %s"),
4951 bfd_archive_filename (input_bfd
), (int) r_type
, sym_name
);
4953 bfd_set_error (bfd_error_bad_value
);
4959 case R_PPC_EMB_MRKREF
:
4960 case R_PPC_GNU_VTINHERIT
:
4961 case R_PPC_GNU_VTENTRY
:
4964 /* GOT16 relocations. Like an ADDR16 using the symbol's
4965 address in the GOT as relocation value instead of the
4966 symbol's value itself. Also, create a GOT entry for the
4967 symbol and put the symbol value there. */
4968 case R_PPC_GOT_TLSGD16
:
4969 case R_PPC_GOT_TLSGD16_LO
:
4970 case R_PPC_GOT_TLSGD16_HI
:
4971 case R_PPC_GOT_TLSGD16_HA
:
4972 tls_type
= TLS_TLS
| TLS_GD
;
4975 case R_PPC_GOT_TLSLD16
:
4976 case R_PPC_GOT_TLSLD16_LO
:
4977 case R_PPC_GOT_TLSLD16_HI
:
4978 case R_PPC_GOT_TLSLD16_HA
:
4979 tls_type
= TLS_TLS
| TLS_LD
;
4982 case R_PPC_GOT_TPREL16
:
4983 case R_PPC_GOT_TPREL16_LO
:
4984 case R_PPC_GOT_TPREL16_HI
:
4985 case R_PPC_GOT_TPREL16_HA
:
4986 tls_type
= TLS_TLS
| TLS_TPREL
;
4989 case R_PPC_GOT_DTPREL16
:
4990 case R_PPC_GOT_DTPREL16_LO
:
4991 case R_PPC_GOT_DTPREL16_HI
:
4992 case R_PPC_GOT_DTPREL16_HA
:
4993 tls_type
= TLS_TLS
| TLS_DTPREL
;
4997 case R_PPC_GOT16_LO
:
4998 case R_PPC_GOT16_HI
:
4999 case R_PPC_GOT16_HA
:
5002 /* Relocation is to the entry for this symbol in the global
5008 if (htab
->got
== NULL
)
5012 if (tls_type
== (TLS_TLS
| TLS_LD
)
5014 || !(h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
)))
5015 offp
= &htab
->tlsld_got
.offset
;
5019 dyn
= htab
->elf
.dynamic_sections_created
;
5020 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
5022 && SYMBOL_REFERENCES_LOCAL (info
, h
)))
5023 /* This is actually a static link, or it is a
5024 -Bsymbolic link and the symbol is defined
5025 locally, or the symbol was forced to be local
5026 because of a version file. */
5031 unresolved_reloc
= FALSE
;
5033 offp
= &h
->got
.offset
;
5037 if (local_got_offsets
== NULL
)
5039 offp
= &local_got_offsets
[r_symndx
];
5042 /* The offset must always be a multiple of 4. We use the
5043 least significant bit to record whether we have already
5044 processed this entry. */
5050 unsigned int tls_m
= (tls_mask
5051 & (TLS_LD
| TLS_GD
| TLS_DTPREL
5052 | TLS_TPREL
| TLS_TPRELGD
));
5054 if (offp
== &htab
->tlsld_got
.offset
)
5057 || !(h
->elf_link_hash_flags
5058 & ELF_LINK_HASH_DEF_DYNAMIC
))
5061 /* We might have multiple got entries for this sym.
5062 Initialize them all. */
5067 if ((tls_m
& TLS_LD
) != 0)
5069 tls_ty
= TLS_TLS
| TLS_LD
;
5072 else if ((tls_m
& TLS_GD
) != 0)
5074 tls_ty
= TLS_TLS
| TLS_GD
;
5077 else if ((tls_m
& TLS_DTPREL
) != 0)
5079 tls_ty
= TLS_TLS
| TLS_DTPREL
;
5080 tls_m
&= ~TLS_DTPREL
;
5082 else if ((tls_m
& (TLS_TPREL
| TLS_TPRELGD
)) != 0)
5084 tls_ty
= TLS_TLS
| TLS_TPREL
;
5088 /* Generate relocs for the dynamic linker. */
5089 if ((info
->shared
|| indx
!= 0)
5091 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
5092 || h
->root
.type
!= bfd_link_hash_undefweak
))
5094 outrel
.r_offset
= (htab
->got
->output_section
->vma
5095 + htab
->got
->output_offset
5097 outrel
.r_addend
= 0;
5098 if (tls_ty
& (TLS_LD
| TLS_GD
))
5100 outrel
.r_info
= ELF32_R_INFO (indx
, R_PPC_DTPMOD32
);
5101 if (tls_ty
== (TLS_TLS
| TLS_GD
))
5103 loc
= htab
->relgot
->contents
;
5104 loc
+= (htab
->relgot
->reloc_count
++
5105 * sizeof (Elf32_External_Rela
));
5106 bfd_elf32_swap_reloca_out (output_bfd
,
5108 outrel
.r_offset
+= 4;
5110 = ELF32_R_INFO (indx
, R_PPC_DTPREL32
);
5113 else if (tls_ty
== (TLS_TLS
| TLS_DTPREL
))
5114 outrel
.r_info
= ELF32_R_INFO (indx
, R_PPC_DTPREL32
);
5115 else if (tls_ty
== (TLS_TLS
| TLS_TPREL
))
5116 outrel
.r_info
= ELF32_R_INFO (indx
, R_PPC_TPREL32
);
5118 outrel
.r_info
= ELF32_R_INFO (indx
, R_PPC_RELATIVE
);
5120 outrel
.r_info
= ELF32_R_INFO (indx
, R_PPC_GLOB_DAT
);
5123 outrel
.r_addend
+= relocation
;
5124 if (tls_ty
& (TLS_GD
| TLS_DTPREL
| TLS_TPREL
))
5125 outrel
.r_addend
-= htab
->elf
.tls_sec
->vma
;
5127 loc
= htab
->relgot
->contents
;
5128 loc
+= (htab
->relgot
->reloc_count
++
5129 * sizeof (Elf32_External_Rela
));
5130 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
5133 /* Init the .got section contents if we're not
5134 emitting a reloc. */
5137 bfd_vma value
= relocation
;
5139 if (tls_ty
== (TLS_TLS
| TLS_LD
))
5141 else if (tls_ty
!= 0)
5143 value
-= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
5144 if (tls_ty
== (TLS_TLS
| TLS_TPREL
))
5145 value
+= DTP_OFFSET
- TP_OFFSET
;
5147 if (tls_ty
== (TLS_TLS
| TLS_GD
))
5149 bfd_put_32 (output_bfd
, value
,
5150 htab
->got
->contents
+ off
+ 4);
5154 bfd_put_32 (output_bfd
, value
,
5155 htab
->got
->contents
+ off
);
5159 if (tls_ty
& (TLS_LD
| TLS_GD
))
5168 if (off
>= (bfd_vma
) -2)
5171 if ((tls_type
& TLS_TLS
) != 0)
5173 if (tls_type
!= (TLS_TLS
| TLS_LD
))
5175 if ((tls_mask
& TLS_LD
) != 0
5177 || !(h
->elf_link_hash_flags
5178 & ELF_LINK_HASH_DEF_DYNAMIC
)))
5180 if (tls_type
!= (TLS_TLS
| TLS_GD
))
5182 if ((tls_mask
& TLS_GD
) != 0)
5184 if (tls_type
!= (TLS_TLS
| TLS_DTPREL
))
5186 if ((tls_mask
& TLS_DTPREL
) != 0)
5193 relocation
= htab
->got
->output_offset
+ off
- 4;
5195 /* Addends on got relocations don't make much sense.
5196 x+off@got is actually x@got+off, and since the got is
5197 generated by a hash table traversal, the value in the
5198 got at entry m+n bears little relation to the entry m. */
5200 (*_bfd_error_handler
)
5201 (_("%s(%s+0x%lx): non-zero addend on %s reloc against `%s'"),
5202 bfd_archive_filename (input_bfd
),
5203 bfd_get_section_name (input_bfd
, input_section
),
5204 (long) rel
->r_offset
,
5210 /* Relocations that need no special processing. */
5211 case R_PPC_LOCAL24PC
:
5212 /* It makes no sense to point a local relocation
5213 at a symbol not in this object. */
5214 if (unresolved_reloc
)
5216 if (! (*info
->callbacks
->undefined_symbol
) (info
,
5217 h
->root
.root
.string
,
5227 case R_PPC_DTPREL16
:
5228 case R_PPC_DTPREL16_LO
:
5229 case R_PPC_DTPREL16_HI
:
5230 case R_PPC_DTPREL16_HA
:
5231 addend
-= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
5234 /* Relocations that may need to be propagated if this is a shared
5237 case R_PPC_TPREL16_LO
:
5238 case R_PPC_TPREL16_HI
:
5239 case R_PPC_TPREL16_HA
:
5240 addend
-= htab
->elf
.tls_sec
->vma
+ TP_OFFSET
;
5241 /* The TPREL16 relocs shouldn't really be used in shared
5242 libs as they will result in DT_TEXTREL being set, but
5243 support them anyway. */
5247 addend
-= htab
->elf
.tls_sec
->vma
+ TP_OFFSET
;
5250 case R_PPC_DTPREL32
:
5251 addend
-= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
5254 case R_PPC_DTPMOD32
:
5262 case R_PPC_REL14_BRTAKEN
:
5263 case R_PPC_REL14_BRNTAKEN
:
5264 /* If these relocations are not to a named symbol, they can be
5265 handled right here, no need to bother the dynamic linker. */
5266 if (SYMBOL_REFERENCES_LOCAL (info
, h
)
5267 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
5271 /* Relocations that always need to be propagated if this is a shared
5276 case R_PPC_ADDR16_LO
:
5277 case R_PPC_ADDR16_HI
:
5278 case R_PPC_ADDR16_HA
:
5280 case R_PPC_ADDR14_BRTAKEN
:
5281 case R_PPC_ADDR14_BRNTAKEN
:
5284 /* r_symndx will be zero only for relocs against symbols
5285 from removed linkonce sections, or sections discarded by
5294 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
5295 || h
->root
.type
!= bfd_link_hash_undefweak
)
5296 && (MUST_BE_DYN_RELOC (r_type
)
5297 || !SYMBOL_CALLS_LOCAL (info
, h
)))
5298 || (ELIMINATE_COPY_RELOCS
5300 && (input_section
->flags
& SEC_ALLOC
) != 0
5303 && (h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0
5304 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
5305 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0))
5310 fprintf (stderr
, "ppc_elf_relocate_section needs to "
5311 "create relocation for %s\n",
5312 (h
&& h
->root
.root
.string
5313 ? h
->root
.root
.string
: "<unknown>"));
5316 /* When generating a shared object, these relocations
5317 are copied into the output file to be resolved at run
5323 name
= (bfd_elf_string_from_elf_section
5325 elf_elfheader (input_bfd
)->e_shstrndx
,
5326 elf_section_data (input_section
)->rel_hdr
.sh_name
));
5330 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
5331 && strcmp (bfd_get_section_name (input_bfd
,
5335 sreloc
= bfd_get_section_by_name (htab
->elf
.dynobj
, name
);
5336 BFD_ASSERT (sreloc
!= NULL
);
5342 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
5344 if (outrel
.r_offset
== (bfd_vma
) -1
5345 || outrel
.r_offset
== (bfd_vma
) -2)
5346 skip
= (int) outrel
.r_offset
;
5347 outrel
.r_offset
+= (input_section
->output_section
->vma
5348 + input_section
->output_offset
);
5351 memset (&outrel
, 0, sizeof outrel
);
5352 else if (!SYMBOL_REFERENCES_LOCAL (info
, h
))
5354 unresolved_reloc
= FALSE
;
5355 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
5356 outrel
.r_addend
= rel
->r_addend
;
5360 outrel
.r_addend
= relocation
+ rel
->r_addend
;
5362 if (r_type
== R_PPC_ADDR32
)
5363 outrel
.r_info
= ELF32_R_INFO (0, R_PPC_RELATIVE
);
5368 if (bfd_is_abs_section (sec
))
5370 else if (sec
== NULL
|| sec
->owner
== NULL
)
5372 bfd_set_error (bfd_error_bad_value
);
5379 /* We are turning this relocation into one
5380 against a section symbol. It would be
5381 proper to subtract the symbol's value,
5382 osec->vma, from the emitted reloc addend,
5383 but ld.so expects buggy relocs. */
5384 osec
= sec
->output_section
;
5385 indx
= elf_section_data (osec
)->dynindx
;
5386 BFD_ASSERT (indx
> 0);
5389 printf ("indx=%d section=%s flags=%08x name=%s\n",
5390 indx
, osec
->name
, osec
->flags
,
5391 h
->root
.root
.string
);
5395 outrel
.r_info
= ELF32_R_INFO (indx
, r_type
);
5399 loc
= sreloc
->contents
;
5400 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rela
);
5401 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
5406 /* This reloc will be computed at runtime. We clear the memory
5407 so that it contains predictable value. */
5409 && ((input_section
->flags
& SEC_ALLOC
) != 0
5410 || ELF32_R_TYPE (outrel
.r_info
) != R_PPC_RELATIVE
))
5412 relocation
= howto
->pc_relative
? outrel
.r_offset
: 0;
5419 case R_PPC_RELAX32PC
:
5420 relocation
-= (input_section
->output_section
->vma
5421 + input_section
->output_offset
5422 + rel
->r_offset
- 4);
5429 t0
= bfd_get_32 (output_bfd
, contents
+ rel
->r_offset
);
5430 t1
= bfd_get_32 (output_bfd
, contents
+ rel
->r_offset
+ 4);
5432 /* We're clearing the bits for R_PPC_ADDR16_HA
5433 and R_PPC_ADDR16_LO here. */
5437 /* t0 is HA, t1 is LO */
5438 relocation
+= addend
;
5439 t0
|= ((relocation
+ 0x8000) >> 16) & 0xffff;
5440 t1
|= relocation
& 0xffff;
5442 bfd_put_32 (output_bfd
, t0
, contents
+ rel
->r_offset
);
5443 bfd_put_32 (output_bfd
, t1
, contents
+ rel
->r_offset
+ 4);
5447 /* Indirect .sdata relocation. */
5448 case R_PPC_EMB_SDAI16
:
5449 BFD_ASSERT (htab
->sdata
!= NULL
);
5451 = elf_finish_pointer_linker_section (output_bfd
, input_bfd
, info
,
5452 htab
->sdata
, h
, relocation
,
5453 rel
, R_PPC_RELATIVE
);
5456 /* Indirect .sdata2 relocation. */
5457 case R_PPC_EMB_SDA2I16
:
5458 BFD_ASSERT (htab
->sdata2
!= NULL
);
5460 = elf_finish_pointer_linker_section (output_bfd
, input_bfd
, info
,
5461 htab
->sdata2
, h
, relocation
,
5462 rel
, R_PPC_RELATIVE
);
5465 /* Handle the TOC16 reloc. We want to use the offset within the .got
5466 section, not the actual VMA. This is appropriate when generating
5467 an embedded ELF object, for which the .got section acts like the
5468 AIX .toc section. */
5469 case R_PPC_TOC16
: /* phony GOT16 relocations */
5470 BFD_ASSERT (sec
!= NULL
);
5471 BFD_ASSERT (bfd_is_und_section (sec
)
5472 || strcmp (bfd_get_section_name (abfd
, sec
), ".got") == 0
5473 || strcmp (bfd_get_section_name (abfd
, sec
), ".cgot") == 0)
5475 addend
-= sec
->output_section
->vma
+ sec
->output_offset
+ 0x8000;
5478 case R_PPC_PLTREL24
:
5479 /* Relocation is to the entry for this symbol in the
5480 procedure linkage table. */
5481 BFD_ASSERT (h
!= NULL
);
5483 if (h
->plt
.offset
== (bfd_vma
) -1
5484 || htab
->plt
== NULL
)
5486 /* We didn't make a PLT entry for this symbol. This
5487 happens when statically linking PIC code, or when
5488 using -Bsymbolic. */
5492 unresolved_reloc
= FALSE
;
5493 relocation
= (htab
->plt
->output_section
->vma
5494 + htab
->plt
->output_offset
5498 /* Relocate against _SDA_BASE_. */
5499 case R_PPC_SDAREL16
:
5502 const struct elf_link_hash_entry
*sh
;
5504 BFD_ASSERT (sec
!= NULL
);
5505 name
= bfd_get_section_name (abfd
, sec
->output_section
);
5506 if (! ((strncmp (name
, ".sdata", 6) == 0
5507 && (name
[6] == 0 || name
[6] == '.'))
5508 || (strncmp (name
, ".sbss", 5) == 0
5509 && (name
[5] == 0 || name
[5] == '.'))))
5511 (*_bfd_error_handler
)
5512 (_("%s: the target (%s) of a %s relocation is "
5513 "in the wrong output section (%s)"),
5514 bfd_archive_filename (input_bfd
),
5519 sh
= htab
->sdata
->sym_hash
;
5520 addend
-= (sh
->root
.u
.def
.value
5521 + sh
->root
.u
.def
.section
->output_section
->vma
5522 + sh
->root
.u
.def
.section
->output_offset
);
5526 /* Relocate against _SDA2_BASE_. */
5527 case R_PPC_EMB_SDA2REL
:
5530 const struct elf_link_hash_entry
*sh
;
5532 BFD_ASSERT (sec
!= NULL
);
5533 name
= bfd_get_section_name (abfd
, sec
->output_section
);
5534 if (! (strncmp (name
, ".sdata2", 7) == 0
5535 || strncmp (name
, ".sbss2", 6) == 0))
5537 (*_bfd_error_handler
)
5538 (_("%s: the target (%s) of a %s relocation is "
5539 "in the wrong output section (%s)"),
5540 bfd_archive_filename (input_bfd
),
5545 bfd_set_error (bfd_error_bad_value
);
5549 sh
= htab
->sdata2
->sym_hash
;
5550 addend
-= (sh
->root
.u
.def
.value
5551 + sh
->root
.u
.def
.section
->output_section
->vma
5552 + sh
->root
.u
.def
.section
->output_offset
);
5556 /* Relocate against either _SDA_BASE_, _SDA2_BASE_, or 0. */
5557 case R_PPC_EMB_SDA21
:
5558 case R_PPC_EMB_RELSDA
:
5561 const struct elf_link_hash_entry
*sh
;
5564 BFD_ASSERT (sec
!= NULL
);
5565 name
= bfd_get_section_name (abfd
, sec
->output_section
);
5566 if (((strncmp (name
, ".sdata", 6) == 0
5567 && (name
[6] == 0 || name
[6] == '.'))
5568 || (strncmp (name
, ".sbss", 5) == 0
5569 && (name
[5] == 0 || name
[5] == '.'))))
5572 sh
= htab
->sdata
->sym_hash
;
5573 addend
-= (sh
->root
.u
.def
.value
5574 + sh
->root
.u
.def
.section
->output_section
->vma
5575 + sh
->root
.u
.def
.section
->output_offset
);
5578 else if (strncmp (name
, ".sdata2", 7) == 0
5579 || strncmp (name
, ".sbss2", 6) == 0)
5582 sh
= htab
->sdata2
->sym_hash
;
5583 addend
-= (sh
->root
.u
.def
.value
5584 + sh
->root
.u
.def
.section
->output_section
->vma
5585 + sh
->root
.u
.def
.section
->output_offset
);
5588 else if (strcmp (name
, ".PPC.EMB.sdata0") == 0
5589 || strcmp (name
, ".PPC.EMB.sbss0") == 0)
5596 (*_bfd_error_handler
)
5597 (_("%s: the target (%s) of a %s relocation is "
5598 "in the wrong output section (%s)"),
5599 bfd_archive_filename (input_bfd
),
5604 bfd_set_error (bfd_error_bad_value
);
5609 if (r_type
== R_PPC_EMB_SDA21
)
5610 { /* fill in register field */
5611 insn
= bfd_get_32 (output_bfd
, contents
+ rel
->r_offset
);
5612 insn
= (insn
& ~RA_REGISTER_MASK
) | (reg
<< RA_REGISTER_SHIFT
);
5613 bfd_put_32 (output_bfd
, insn
, contents
+ rel
->r_offset
);
5618 /* Relocate against the beginning of the section. */
5620 case R_PPC_SECTOFF_LO
:
5621 case R_PPC_SECTOFF_HI
:
5622 case R_PPC_SECTOFF_HA
:
5623 BFD_ASSERT (sec
!= NULL
);
5624 addend
-= sec
->output_section
->vma
;
5627 /* Negative relocations. */
5628 case R_PPC_EMB_NADDR32
:
5629 case R_PPC_EMB_NADDR16
:
5630 case R_PPC_EMB_NADDR16_LO
:
5631 case R_PPC_EMB_NADDR16_HI
:
5632 case R_PPC_EMB_NADDR16_HA
:
5633 addend
-= 2 * relocation
;
5637 case R_PPC_GLOB_DAT
:
5638 case R_PPC_JMP_SLOT
:
5639 case R_PPC_RELATIVE
:
5641 case R_PPC_PLTREL32
:
5642 case R_PPC_PLT16_LO
:
5643 case R_PPC_PLT16_HI
:
5644 case R_PPC_PLT16_HA
:
5646 case R_PPC_EMB_RELSEC16
:
5647 case R_PPC_EMB_RELST_LO
:
5648 case R_PPC_EMB_RELST_HI
:
5649 case R_PPC_EMB_RELST_HA
:
5650 case R_PPC_EMB_BIT_FLD
:
5651 (*_bfd_error_handler
)
5652 (_("%s: relocation %s is not yet supported for symbol %s."),
5653 bfd_archive_filename (input_bfd
),
5657 bfd_set_error (bfd_error_invalid_operation
);
5662 /* Do any further special processing. */
5668 case R_PPC_ADDR16_HA
:
5669 case R_PPC_GOT16_HA
:
5670 case R_PPC_PLT16_HA
:
5671 case R_PPC_SECTOFF_HA
:
5672 case R_PPC_TPREL16_HA
:
5673 case R_PPC_DTPREL16_HA
:
5674 case R_PPC_GOT_TLSGD16_HA
:
5675 case R_PPC_GOT_TLSLD16_HA
:
5676 case R_PPC_GOT_TPREL16_HA
:
5677 case R_PPC_GOT_DTPREL16_HA
:
5678 case R_PPC_EMB_NADDR16_HA
:
5679 case R_PPC_EMB_RELST_HA
:
5680 /* It's just possible that this symbol is a weak symbol
5681 that's not actually defined anywhere. In that case,
5682 'sec' would be NULL, and we should leave the symbol
5683 alone (it will be set to zero elsewhere in the link). */
5685 /* Add 0x10000 if sign bit in 0:15 is set.
5686 Bits 0:15 are not used. */
5692 fprintf (stderr
, "\ttype = %s (%d), name = %s, symbol index = %ld, "
5693 "offset = %ld, addend = %ld\n",
5698 (long) rel
->r_offset
,
5702 if (unresolved_reloc
5703 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
5704 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0))
5706 (*_bfd_error_handler
)
5707 (_("%s(%s+0x%lx): unresolvable %s relocation against symbol `%s'"),
5708 bfd_archive_filename (input_bfd
),
5709 bfd_get_section_name (input_bfd
, input_section
),
5710 (long) rel
->r_offset
,
5716 r
= _bfd_final_link_relocate (howto
,
5724 if (r
!= bfd_reloc_ok
)
5726 if (sym_name
== NULL
)
5727 sym_name
= "(null)";
5728 if (r
== bfd_reloc_overflow
)
5733 && h
->root
.type
== bfd_link_hash_undefweak
5734 && howto
->pc_relative
)
5736 /* Assume this is a call protected by other code that
5737 detect the symbol is undefined. If this is the case,
5738 we can safely ignore the overflow. If not, the
5739 program is hosed anyway, and a little warning isn't
5745 if (! (*info
->callbacks
->reloc_overflow
) (info
,
5756 (*_bfd_error_handler
)
5757 (_("%s(%s+0x%lx): %s reloc against `%s': error %d"),
5758 bfd_archive_filename (input_bfd
),
5759 bfd_get_section_name (input_bfd
, input_section
),
5760 (long) rel
->r_offset
, howto
->name
, sym_name
, (int) r
);
5767 fprintf (stderr
, "\n");
5773 static enum elf_reloc_type_class
5774 ppc_elf_reloc_type_class (const Elf_Internal_Rela
*rela
)
5776 switch (ELF32_R_TYPE (rela
->r_info
))
5778 case R_PPC_RELATIVE
:
5779 return reloc_class_relative
;
5782 case R_PPC_JMP_SLOT
:
5783 return reloc_class_plt
;
5785 return reloc_class_copy
;
5787 return reloc_class_normal
;
5791 /* Support for core dump NOTE sections. */
5794 ppc_elf_grok_prstatus (bfd
*abfd
, Elf_Internal_Note
*note
)
5797 unsigned int raw_size
;
5799 switch (note
->descsz
)
5804 case 268: /* Linux/PPC. */
5806 elf_tdata (abfd
)->core_signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
5809 elf_tdata (abfd
)->core_pid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
5818 /* Make a ".reg/999" section. */
5819 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
5820 raw_size
, note
->descpos
+ offset
);
5824 ppc_elf_grok_psinfo (bfd
*abfd
, Elf_Internal_Note
*note
)
5826 switch (note
->descsz
)
5831 case 128: /* Linux/PPC elf_prpsinfo. */
5832 elf_tdata (abfd
)->core_program
5833 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 32, 16);
5834 elf_tdata (abfd
)->core_command
5835 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 48, 80);
5838 /* Note that for some reason, a spurious space is tacked
5839 onto the end of the args in some (at least one anyway)
5840 implementations, so strip it off if it exists. */
5843 char *command
= elf_tdata (abfd
)->core_command
;
5844 int n
= strlen (command
);
5846 if (0 < n
&& command
[n
- 1] == ' ')
5847 command
[n
- 1] = '\0';
5853 /* Very simple linked list structure for recording apuinfo values. */
5854 typedef struct apuinfo_list
5856 struct apuinfo_list
*next
;
5857 unsigned long value
;
5861 static apuinfo_list
*head
;
5865 apuinfo_list_init (void)
5871 apuinfo_list_add (unsigned long value
)
5873 apuinfo_list
*entry
= head
;
5875 while (entry
!= NULL
)
5877 if (entry
->value
== value
)
5879 entry
= entry
->next
;
5882 entry
= bfd_malloc (sizeof (* entry
));
5886 entry
->value
= value
;
5892 apuinfo_list_length (void)
5894 apuinfo_list
*entry
;
5895 unsigned long count
;
5897 for (entry
= head
, count
= 0;
5899 entry
= entry
->next
)
5905 static inline unsigned long
5906 apuinfo_list_element (unsigned long number
)
5908 apuinfo_list
* entry
;
5912 entry
= entry
->next
)
5915 return entry
? entry
->value
: 0;
5919 apuinfo_list_finish (void)
5921 apuinfo_list
*entry
;
5923 for (entry
= head
; entry
;)
5925 apuinfo_list
*next
= entry
->next
;
5933 #define APUINFO_SECTION_NAME ".PPC.EMB.apuinfo"
5934 #define APUINFO_LABEL "APUinfo"
5936 /* Scan the input BFDs and create a linked list of
5937 the APUinfo values that will need to be emitted. */
5940 ppc_elf_begin_write_processing (bfd
*abfd
, struct bfd_link_info
*link_info
)
5945 unsigned num_input_sections
;
5946 bfd_size_type output_section_size
;
5948 unsigned num_entries
;
5949 unsigned long offset
;
5950 unsigned long length
;
5951 const char *error_message
= NULL
;
5953 if (link_info
== NULL
)
5956 /* Scan the input bfds, looking for apuinfo sections. */
5957 num_input_sections
= 0;
5958 output_section_size
= 0;
5960 for (ibfd
= link_info
->input_bfds
; ibfd
; ibfd
= ibfd
->link_next
)
5962 asec
= bfd_get_section_by_name (ibfd
, APUINFO_SECTION_NAME
);
5965 ++ num_input_sections
;
5966 output_section_size
+= asec
->_raw_size
;
5970 /* We need at least one input sections
5971 in order to make merging worthwhile. */
5972 if (num_input_sections
< 1)
5975 /* Just make sure that the output section exists as well. */
5976 asec
= bfd_get_section_by_name (abfd
, APUINFO_SECTION_NAME
);
5980 /* Allocate a buffer for the contents of the input sections. */
5981 buffer
= bfd_malloc (output_section_size
);
5986 apuinfo_list_init ();
5988 /* Read in the input sections contents. */
5989 for (ibfd
= link_info
->input_bfds
; ibfd
; ibfd
= ibfd
->link_next
)
5991 unsigned long datum
;
5994 asec
= bfd_get_section_by_name (ibfd
, APUINFO_SECTION_NAME
);
5998 length
= asec
->_raw_size
;
6001 error_message
= _("corrupt or empty %s section in %s");
6005 if (bfd_seek (ibfd
, asec
->filepos
, SEEK_SET
) != 0
6006 || (bfd_bread (buffer
+ offset
, length
, ibfd
) != length
))
6008 error_message
= _("unable to read in %s section from %s");
6012 /* Process the contents of the section. */
6013 ptr
= buffer
+ offset
;
6014 error_message
= _("corrupt %s section in %s");
6016 /* Verify the contents of the header. Note - we have to
6017 extract the values this way in order to allow for a
6018 host whose endian-ness is different from the target. */
6019 datum
= bfd_get_32 (ibfd
, ptr
);
6020 if (datum
!= sizeof APUINFO_LABEL
)
6023 datum
= bfd_get_32 (ibfd
, ptr
+ 8);
6027 if (strcmp (ptr
+ 12, APUINFO_LABEL
) != 0)
6030 /* Get the number of bytes used for apuinfo entries. */
6031 datum
= bfd_get_32 (ibfd
, ptr
+ 4);
6032 if (datum
+ 20 != length
)
6035 /* Make sure that we do not run off the end of the section. */
6036 if (offset
+ length
> output_section_size
)
6039 /* Scan the apuinfo section, building a list of apuinfo numbers. */
6040 for (i
= 0; i
< datum
; i
+= 4)
6041 apuinfo_list_add (bfd_get_32 (ibfd
, ptr
+ 20 + i
));
6043 /* Update the offset. */
6047 error_message
= NULL
;
6049 /* Compute the size of the output section. */
6050 num_entries
= apuinfo_list_length ();
6051 output_section_size
= 20 + num_entries
* 4;
6053 asec
= bfd_get_section_by_name (abfd
, APUINFO_SECTION_NAME
);
6055 if (! bfd_set_section_size (abfd
, asec
, output_section_size
))
6057 error_message
= _("warning: unable to set size of %s section in %s");
6063 (*_bfd_error_handler
) (error_message
, APUINFO_SECTION_NAME
,
6064 bfd_archive_filename (ibfd
));
6068 /* Prevent the output section from accumulating the input sections'
6069 contents. We have already stored this in our linked list structure. */
6072 ppc_elf_write_section (bfd
*abfd ATTRIBUTE_UNUSED
,
6074 bfd_byte
*contents ATTRIBUTE_UNUSED
)
6076 return (apuinfo_list_length ()
6077 && strcmp (asec
->name
, APUINFO_SECTION_NAME
) == 0);
6081 /* Finally we can generate the output section. */
6084 ppc_elf_final_write_processing (bfd
*abfd
, bfd_boolean linker ATTRIBUTE_UNUSED
)
6089 unsigned num_entries
;
6090 bfd_size_type length
;
6092 asec
= bfd_get_section_by_name (abfd
, APUINFO_SECTION_NAME
);
6096 if (apuinfo_list_length () == 0)
6099 length
= asec
->_raw_size
;
6103 buffer
= bfd_malloc (length
);
6106 (*_bfd_error_handler
)
6107 (_("failed to allocate space for new APUinfo section."));
6111 /* Create the apuinfo header. */
6112 num_entries
= apuinfo_list_length ();
6113 bfd_put_32 (abfd
, sizeof APUINFO_LABEL
, buffer
);
6114 bfd_put_32 (abfd
, num_entries
* 4, buffer
+ 4);
6115 bfd_put_32 (abfd
, 0x2, buffer
+ 8);
6116 strcpy (buffer
+ 12, APUINFO_LABEL
);
6119 for (i
= 0; i
< num_entries
; i
++)
6121 bfd_put_32 (abfd
, apuinfo_list_element (i
), buffer
+ length
);
6125 if (length
!= asec
->_raw_size
)
6126 (*_bfd_error_handler
) (_("failed to compute new APUinfo section."));
6128 if (! bfd_set_section_contents (abfd
, asec
, buffer
, (file_ptr
) 0, length
))
6129 (*_bfd_error_handler
) (_("failed to install new APUinfo section."));
6133 apuinfo_list_finish ();
6136 /* Add extra PPC sections -- Note, for now, make .sbss2 and
6137 .PPC.EMB.sbss0 a normal section, and not a bss section so
6138 that the linker doesn't crater when trying to make more than
6141 static struct bfd_elf_special_section
const ppc_elf_special_sections
[]=
6143 { ".tags", 5, 0, SHT_ORDERED
, SHF_ALLOC
},
6144 { ".sdata", 6, -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
6145 { ".sbss", 5, -2, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
},
6146 { ".sdata2", 7, -2, SHT_PROGBITS
, SHF_ALLOC
},
6147 { ".sbss2", 6, -2, SHT_PROGBITS
, SHF_ALLOC
},
6148 { ".PPC.EMB.apuinfo", 16, 0, SHT_NOTE
, 0 },
6149 { ".PPC.EMB.sdata0", 15, 0, SHT_PROGBITS
, SHF_ALLOC
},
6150 { ".PPC.EMB.sbss0", 14, 0, SHT_PROGBITS
, SHF_ALLOC
},
6151 { ".plt", 4, 0, SHT_NOBITS
, SHF_ALLOC
+ SHF_EXECINSTR
},
6152 { NULL
, 0, 0, 0, 0 }
6155 #define TARGET_LITTLE_SYM bfd_elf32_powerpcle_vec
6156 #define TARGET_LITTLE_NAME "elf32-powerpcle"
6157 #define TARGET_BIG_SYM bfd_elf32_powerpc_vec
6158 #define TARGET_BIG_NAME "elf32-powerpc"
6159 #define ELF_ARCH bfd_arch_powerpc
6160 #define ELF_MACHINE_CODE EM_PPC
6161 #ifdef __QNXTARGET__
6162 #define ELF_MAXPAGESIZE 0x1000
6164 #define ELF_MAXPAGESIZE 0x10000
6166 #define elf_info_to_howto ppc_elf_info_to_howto
6168 #ifdef EM_CYGNUS_POWERPC
6169 #define ELF_MACHINE_ALT1 EM_CYGNUS_POWERPC
6173 #define ELF_MACHINE_ALT2 EM_PPC_OLD
6176 #define elf_backend_plt_not_loaded 1
6177 #define elf_backend_got_symbol_offset 4
6178 #define elf_backend_can_gc_sections 1
6179 #define elf_backend_can_refcount 1
6180 #define elf_backend_got_header_size 12
6181 #define elf_backend_rela_normal 1
6183 #define bfd_elf32_mkobject ppc_elf_mkobject
6184 #define bfd_elf32_bfd_merge_private_bfd_data ppc_elf_merge_private_bfd_data
6185 #define bfd_elf32_bfd_relax_section ppc_elf_relax_section
6186 #define bfd_elf32_bfd_reloc_type_lookup ppc_elf_reloc_type_lookup
6187 #define bfd_elf32_bfd_set_private_flags ppc_elf_set_private_flags
6188 #define bfd_elf32_bfd_link_hash_table_create ppc_elf_link_hash_table_create
6190 #define elf_backend_object_p ppc_elf_object_p
6191 #define elf_backend_gc_mark_hook ppc_elf_gc_mark_hook
6192 #define elf_backend_gc_sweep_hook ppc_elf_gc_sweep_hook
6193 #define elf_backend_section_from_shdr ppc_elf_section_from_shdr
6194 #define elf_backend_relocate_section ppc_elf_relocate_section
6195 #define elf_backend_create_dynamic_sections ppc_elf_create_dynamic_sections
6196 #define elf_backend_check_relocs ppc_elf_check_relocs
6197 #define elf_backend_copy_indirect_symbol ppc_elf_copy_indirect_symbol
6198 #define elf_backend_adjust_dynamic_symbol ppc_elf_adjust_dynamic_symbol
6199 #define elf_backend_add_symbol_hook ppc_elf_add_symbol_hook
6200 #define elf_backend_size_dynamic_sections ppc_elf_size_dynamic_sections
6201 #define elf_backend_finish_dynamic_symbol ppc_elf_finish_dynamic_symbol
6202 #define elf_backend_finish_dynamic_sections ppc_elf_finish_dynamic_sections
6203 #define elf_backend_fake_sections ppc_elf_fake_sections
6204 #define elf_backend_additional_program_headers ppc_elf_additional_program_headers
6205 #define elf_backend_modify_segment_map ppc_elf_modify_segment_map
6206 #define elf_backend_grok_prstatus ppc_elf_grok_prstatus
6207 #define elf_backend_grok_psinfo ppc_elf_grok_psinfo
6208 #define elf_backend_reloc_type_class ppc_elf_reloc_type_class
6209 #define elf_backend_begin_write_processing ppc_elf_begin_write_processing
6210 #define elf_backend_final_write_processing ppc_elf_final_write_processing
6211 #define elf_backend_write_section ppc_elf_write_section
6212 #define elf_backend_special_sections ppc_elf_special_sections
6214 #include "elf32-target.h"