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 /* Short-cut to first output tls section. */
211 /* Shortcut to .__tls_get_addr. */
212 struct elf_link_hash_entry
*tls_get_addr
;
214 /* TLS local dynamic got entry handling. */
216 bfd_signed_vma refcount
;
220 /* Small local sym to section mapping cache. */
221 struct sym_sec_cache sym_sec
;
224 /* Get the PPC ELF linker hash table from a link_info structure. */
226 #define ppc_elf_hash_table(p) \
227 ((struct ppc_elf_link_hash_table *) (p)->hash)
229 /* Create an entry in a PPC ELF linker hash table. */
231 static struct bfd_hash_entry
*
232 ppc_elf_link_hash_newfunc (struct bfd_hash_entry
*entry
,
233 struct bfd_hash_table
*table
,
236 /* Allocate the structure if it has not already been allocated by a
240 entry
= bfd_hash_allocate (table
,
241 sizeof (struct ppc_elf_link_hash_entry
));
246 /* Call the allocation method of the superclass. */
247 entry
= _bfd_elf_link_hash_newfunc (entry
, table
, string
);
250 ppc_elf_hash_entry (entry
)->linker_section_pointer
= NULL
;
251 ppc_elf_hash_entry (entry
)->dyn_relocs
= NULL
;
252 ppc_elf_hash_entry (entry
)->tls_mask
= 0;
258 /* Create a PPC ELF linker hash table. */
260 static struct bfd_link_hash_table
*
261 ppc_elf_link_hash_table_create (bfd
*abfd
)
263 struct ppc_elf_link_hash_table
*ret
;
265 ret
= bfd_zmalloc (sizeof (struct ppc_elf_link_hash_table
));
269 if (! _bfd_elf_link_hash_table_init (&ret
->elf
, abfd
,
270 ppc_elf_link_hash_newfunc
))
276 return &ret
->elf
.root
;
279 /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
280 copying dynamic variables from a shared lib into an app's dynbss
281 section, and instead use a dynamic relocation to point into the
283 #define ELIMINATE_COPY_RELOCS 1
285 /* Copy the extra info we tack onto an elf_link_hash_entry. */
288 ppc_elf_copy_indirect_symbol (const struct elf_backend_data
*bed
,
289 struct elf_link_hash_entry
*dir
,
290 struct elf_link_hash_entry
*ind
)
292 struct ppc_elf_link_hash_entry
*edir
, *eind
;
294 edir
= (struct ppc_elf_link_hash_entry
*) dir
;
295 eind
= (struct ppc_elf_link_hash_entry
*) ind
;
297 if (eind
->dyn_relocs
!= NULL
)
299 if (edir
->dyn_relocs
!= NULL
)
301 struct ppc_elf_dyn_relocs
**pp
;
302 struct ppc_elf_dyn_relocs
*p
;
304 if (ind
->root
.type
== bfd_link_hash_indirect
)
307 /* Add reloc counts against the weak sym to the strong sym
308 list. Merge any entries against the same section. */
309 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
; )
311 struct ppc_elf_dyn_relocs
*q
;
313 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
314 if (q
->sec
== p
->sec
)
316 q
->pc_count
+= p
->pc_count
;
317 q
->count
+= p
->count
;
324 *pp
= edir
->dyn_relocs
;
327 edir
->dyn_relocs
= eind
->dyn_relocs
;
328 eind
->dyn_relocs
= NULL
;
331 edir
->tls_mask
|= eind
->tls_mask
;
333 if (ELIMINATE_COPY_RELOCS
334 && ind
->root
.type
!= bfd_link_hash_indirect
335 && (dir
->elf_link_hash_flags
& ELF_LINK_HASH_DYNAMIC_ADJUSTED
) != 0)
336 /* If called to transfer flags for a weakdef during processing
337 of elf_adjust_dynamic_symbol, don't copy ELF_LINK_NON_GOT_REF.
338 We clear it ourselves for ELIMINATE_COPY_RELOCS. */
339 dir
->elf_link_hash_flags
|=
340 (ind
->elf_link_hash_flags
& (ELF_LINK_HASH_REF_DYNAMIC
341 | ELF_LINK_HASH_REF_REGULAR
342 | ELF_LINK_HASH_REF_REGULAR_NONWEAK
));
344 _bfd_elf_link_hash_copy_indirect (bed
, dir
, ind
);
347 static reloc_howto_type
*ppc_elf_howto_table
[R_PPC_max
];
349 static reloc_howto_type ppc_elf_howto_raw
[] = {
350 /* This reloc does nothing. */
351 HOWTO (R_PPC_NONE
, /* type */
353 2, /* size (0 = byte, 1 = short, 2 = long) */
355 FALSE
, /* pc_relative */
357 complain_overflow_bitfield
, /* complain_on_overflow */
358 bfd_elf_generic_reloc
, /* special_function */
359 "R_PPC_NONE", /* name */
360 FALSE
, /* partial_inplace */
363 FALSE
), /* pcrel_offset */
365 /* A standard 32 bit relocation. */
366 HOWTO (R_PPC_ADDR32
, /* type */
368 2, /* size (0 = byte, 1 = short, 2 = long) */
370 FALSE
, /* pc_relative */
372 complain_overflow_bitfield
, /* complain_on_overflow */
373 bfd_elf_generic_reloc
, /* special_function */
374 "R_PPC_ADDR32", /* name */
375 FALSE
, /* partial_inplace */
377 0xffffffff, /* dst_mask */
378 FALSE
), /* pcrel_offset */
380 /* An absolute 26 bit branch; the lower two bits must be zero.
381 FIXME: we don't check that, we just clear them. */
382 HOWTO (R_PPC_ADDR24
, /* type */
384 2, /* size (0 = byte, 1 = short, 2 = long) */
386 FALSE
, /* pc_relative */
388 complain_overflow_bitfield
, /* complain_on_overflow */
389 bfd_elf_generic_reloc
, /* special_function */
390 "R_PPC_ADDR24", /* name */
391 FALSE
, /* partial_inplace */
393 0x3fffffc, /* dst_mask */
394 FALSE
), /* pcrel_offset */
396 /* A standard 16 bit relocation. */
397 HOWTO (R_PPC_ADDR16
, /* type */
399 1, /* size (0 = byte, 1 = short, 2 = long) */
401 FALSE
, /* pc_relative */
403 complain_overflow_bitfield
, /* complain_on_overflow */
404 bfd_elf_generic_reloc
, /* special_function */
405 "R_PPC_ADDR16", /* name */
406 FALSE
, /* partial_inplace */
408 0xffff, /* dst_mask */
409 FALSE
), /* pcrel_offset */
411 /* A 16 bit relocation without overflow. */
412 HOWTO (R_PPC_ADDR16_LO
, /* type */
414 1, /* size (0 = byte, 1 = short, 2 = long) */
416 FALSE
, /* pc_relative */
418 complain_overflow_dont
,/* complain_on_overflow */
419 bfd_elf_generic_reloc
, /* special_function */
420 "R_PPC_ADDR16_LO", /* name */
421 FALSE
, /* partial_inplace */
423 0xffff, /* dst_mask */
424 FALSE
), /* pcrel_offset */
426 /* The high order 16 bits of an address. */
427 HOWTO (R_PPC_ADDR16_HI
, /* type */
429 1, /* size (0 = byte, 1 = short, 2 = long) */
431 FALSE
, /* pc_relative */
433 complain_overflow_dont
, /* complain_on_overflow */
434 bfd_elf_generic_reloc
, /* special_function */
435 "R_PPC_ADDR16_HI", /* name */
436 FALSE
, /* partial_inplace */
438 0xffff, /* dst_mask */
439 FALSE
), /* pcrel_offset */
441 /* The high order 16 bits of an address, plus 1 if the contents of
442 the low 16 bits, treated as a signed number, is negative. */
443 HOWTO (R_PPC_ADDR16_HA
, /* type */
445 1, /* size (0 = byte, 1 = short, 2 = long) */
447 FALSE
, /* pc_relative */
449 complain_overflow_dont
, /* complain_on_overflow */
450 ppc_elf_addr16_ha_reloc
, /* special_function */
451 "R_PPC_ADDR16_HA", /* name */
452 FALSE
, /* partial_inplace */
454 0xffff, /* dst_mask */
455 FALSE
), /* pcrel_offset */
457 /* An absolute 16 bit branch; the lower two bits must be zero.
458 FIXME: we don't check that, we just clear them. */
459 HOWTO (R_PPC_ADDR14
, /* type */
461 2, /* size (0 = byte, 1 = short, 2 = long) */
463 FALSE
, /* pc_relative */
465 complain_overflow_bitfield
, /* complain_on_overflow */
466 bfd_elf_generic_reloc
, /* special_function */
467 "R_PPC_ADDR14", /* name */
468 FALSE
, /* partial_inplace */
470 0xfffc, /* dst_mask */
471 FALSE
), /* pcrel_offset */
473 /* An absolute 16 bit branch, for which bit 10 should be set to
474 indicate that the branch is expected to be taken. The lower two
475 bits must be zero. */
476 HOWTO (R_PPC_ADDR14_BRTAKEN
, /* type */
478 2, /* size (0 = byte, 1 = short, 2 = long) */
480 FALSE
, /* pc_relative */
482 complain_overflow_bitfield
, /* complain_on_overflow */
483 bfd_elf_generic_reloc
, /* special_function */
484 "R_PPC_ADDR14_BRTAKEN",/* name */
485 FALSE
, /* partial_inplace */
487 0xfffc, /* dst_mask */
488 FALSE
), /* pcrel_offset */
490 /* An absolute 16 bit branch, for which bit 10 should be set to
491 indicate that the branch is not expected to be taken. The lower
492 two bits must be zero. */
493 HOWTO (R_PPC_ADDR14_BRNTAKEN
, /* type */
495 2, /* size (0 = byte, 1 = short, 2 = long) */
497 FALSE
, /* pc_relative */
499 complain_overflow_bitfield
, /* complain_on_overflow */
500 bfd_elf_generic_reloc
, /* special_function */
501 "R_PPC_ADDR14_BRNTAKEN",/* name */
502 FALSE
, /* partial_inplace */
504 0xfffc, /* dst_mask */
505 FALSE
), /* pcrel_offset */
507 /* A relative 26 bit branch; the lower two bits must be zero. */
508 HOWTO (R_PPC_REL24
, /* type */
510 2, /* size (0 = byte, 1 = short, 2 = long) */
512 TRUE
, /* pc_relative */
514 complain_overflow_signed
, /* complain_on_overflow */
515 bfd_elf_generic_reloc
, /* special_function */
516 "R_PPC_REL24", /* name */
517 FALSE
, /* partial_inplace */
519 0x3fffffc, /* dst_mask */
520 TRUE
), /* pcrel_offset */
522 /* A relative 16 bit branch; the lower two bits must be zero. */
523 HOWTO (R_PPC_REL14
, /* type */
525 2, /* size (0 = byte, 1 = short, 2 = long) */
527 TRUE
, /* pc_relative */
529 complain_overflow_signed
, /* complain_on_overflow */
530 bfd_elf_generic_reloc
, /* special_function */
531 "R_PPC_REL14", /* name */
532 FALSE
, /* partial_inplace */
534 0xfffc, /* dst_mask */
535 TRUE
), /* pcrel_offset */
537 /* A relative 16 bit branch. Bit 10 should be set to indicate that
538 the branch is expected to be taken. The lower two bits must be
540 HOWTO (R_PPC_REL14_BRTAKEN
, /* type */
542 2, /* size (0 = byte, 1 = short, 2 = long) */
544 TRUE
, /* pc_relative */
546 complain_overflow_signed
, /* complain_on_overflow */
547 bfd_elf_generic_reloc
, /* special_function */
548 "R_PPC_REL14_BRTAKEN", /* name */
549 FALSE
, /* partial_inplace */
551 0xfffc, /* dst_mask */
552 TRUE
), /* pcrel_offset */
554 /* A relative 16 bit branch. Bit 10 should be set to indicate that
555 the branch is not expected to be taken. The lower two bits must
557 HOWTO (R_PPC_REL14_BRNTAKEN
, /* type */
559 2, /* size (0 = byte, 1 = short, 2 = long) */
561 TRUE
, /* pc_relative */
563 complain_overflow_signed
, /* complain_on_overflow */
564 bfd_elf_generic_reloc
, /* special_function */
565 "R_PPC_REL14_BRNTAKEN",/* name */
566 FALSE
, /* partial_inplace */
568 0xfffc, /* dst_mask */
569 TRUE
), /* pcrel_offset */
571 /* Like R_PPC_ADDR16, but referring to the GOT table entry for the
573 HOWTO (R_PPC_GOT16
, /* type */
575 1, /* size (0 = byte, 1 = short, 2 = long) */
577 FALSE
, /* pc_relative */
579 complain_overflow_signed
, /* complain_on_overflow */
580 bfd_elf_generic_reloc
, /* special_function */
581 "R_PPC_GOT16", /* name */
582 FALSE
, /* partial_inplace */
584 0xffff, /* dst_mask */
585 FALSE
), /* pcrel_offset */
587 /* Like R_PPC_ADDR16_LO, but referring to the GOT table entry for
589 HOWTO (R_PPC_GOT16_LO
, /* type */
591 1, /* size (0 = byte, 1 = short, 2 = long) */
593 FALSE
, /* pc_relative */
595 complain_overflow_dont
, /* complain_on_overflow */
596 bfd_elf_generic_reloc
, /* special_function */
597 "R_PPC_GOT16_LO", /* name */
598 FALSE
, /* partial_inplace */
600 0xffff, /* dst_mask */
601 FALSE
), /* pcrel_offset */
603 /* Like R_PPC_ADDR16_HI, but referring to the GOT table entry for
605 HOWTO (R_PPC_GOT16_HI
, /* type */
607 1, /* size (0 = byte, 1 = short, 2 = long) */
609 FALSE
, /* pc_relative */
611 complain_overflow_bitfield
, /* complain_on_overflow */
612 bfd_elf_generic_reloc
, /* special_function */
613 "R_PPC_GOT16_HI", /* name */
614 FALSE
, /* partial_inplace */
616 0xffff, /* dst_mask */
617 FALSE
), /* pcrel_offset */
619 /* Like R_PPC_ADDR16_HA, but referring to the GOT table entry for
621 HOWTO (R_PPC_GOT16_HA
, /* type */
623 1, /* size (0 = byte, 1 = short, 2 = long) */
625 FALSE
, /* pc_relative */
627 complain_overflow_bitfield
, /* complain_on_overflow */
628 ppc_elf_addr16_ha_reloc
, /* special_function */
629 "R_PPC_GOT16_HA", /* name */
630 FALSE
, /* partial_inplace */
632 0xffff, /* dst_mask */
633 FALSE
), /* pcrel_offset */
635 /* Like R_PPC_REL24, but referring to the procedure linkage table
636 entry for the symbol. */
637 HOWTO (R_PPC_PLTREL24
, /* type */
639 2, /* size (0 = byte, 1 = short, 2 = long) */
641 TRUE
, /* pc_relative */
643 complain_overflow_signed
, /* complain_on_overflow */
644 bfd_elf_generic_reloc
, /* special_function */
645 "R_PPC_PLTREL24", /* name */
646 FALSE
, /* partial_inplace */
648 0x3fffffc, /* dst_mask */
649 TRUE
), /* pcrel_offset */
651 /* This is used only by the dynamic linker. The symbol should exist
652 both in the object being run and in some shared library. The
653 dynamic linker copies the data addressed by the symbol from the
654 shared library into the object, because the object being
655 run has to have the data at some particular address. */
656 HOWTO (R_PPC_COPY
, /* type */
658 2, /* size (0 = byte, 1 = short, 2 = long) */
660 FALSE
, /* pc_relative */
662 complain_overflow_bitfield
, /* complain_on_overflow */
663 bfd_elf_generic_reloc
, /* special_function */
664 "R_PPC_COPY", /* name */
665 FALSE
, /* partial_inplace */
668 FALSE
), /* pcrel_offset */
670 /* Like R_PPC_ADDR32, but used when setting global offset table
672 HOWTO (R_PPC_GLOB_DAT
, /* type */
674 2, /* size (0 = byte, 1 = short, 2 = long) */
676 FALSE
, /* pc_relative */
678 complain_overflow_bitfield
, /* complain_on_overflow */
679 bfd_elf_generic_reloc
, /* special_function */
680 "R_PPC_GLOB_DAT", /* name */
681 FALSE
, /* partial_inplace */
683 0xffffffff, /* dst_mask */
684 FALSE
), /* pcrel_offset */
686 /* Marks a procedure linkage table entry for a symbol. */
687 HOWTO (R_PPC_JMP_SLOT
, /* type */
689 2, /* size (0 = byte, 1 = short, 2 = long) */
691 FALSE
, /* pc_relative */
693 complain_overflow_bitfield
, /* complain_on_overflow */
694 bfd_elf_generic_reloc
, /* special_function */
695 "R_PPC_JMP_SLOT", /* name */
696 FALSE
, /* partial_inplace */
699 FALSE
), /* pcrel_offset */
701 /* Used only by the dynamic linker. When the object is run, this
702 longword is set to the load address of the object, plus the
704 HOWTO (R_PPC_RELATIVE
, /* type */
706 2, /* size (0 = byte, 1 = short, 2 = long) */
708 FALSE
, /* pc_relative */
710 complain_overflow_bitfield
, /* complain_on_overflow */
711 bfd_elf_generic_reloc
, /* special_function */
712 "R_PPC_RELATIVE", /* name */
713 FALSE
, /* partial_inplace */
715 0xffffffff, /* dst_mask */
716 FALSE
), /* pcrel_offset */
718 /* Like R_PPC_REL24, but uses the value of the symbol within the
719 object rather than the final value. Normally used for
720 _GLOBAL_OFFSET_TABLE_. */
721 HOWTO (R_PPC_LOCAL24PC
, /* type */
723 2, /* size (0 = byte, 1 = short, 2 = long) */
725 TRUE
, /* pc_relative */
727 complain_overflow_signed
, /* complain_on_overflow */
728 bfd_elf_generic_reloc
, /* special_function */
729 "R_PPC_LOCAL24PC", /* name */
730 FALSE
, /* partial_inplace */
732 0x3fffffc, /* dst_mask */
733 TRUE
), /* pcrel_offset */
735 /* Like R_PPC_ADDR32, but may be unaligned. */
736 HOWTO (R_PPC_UADDR32
, /* type */
738 2, /* size (0 = byte, 1 = short, 2 = long) */
740 FALSE
, /* pc_relative */
742 complain_overflow_bitfield
, /* complain_on_overflow */
743 bfd_elf_generic_reloc
, /* special_function */
744 "R_PPC_UADDR32", /* name */
745 FALSE
, /* partial_inplace */
747 0xffffffff, /* dst_mask */
748 FALSE
), /* pcrel_offset */
750 /* Like R_PPC_ADDR16, but may be unaligned. */
751 HOWTO (R_PPC_UADDR16
, /* type */
753 1, /* size (0 = byte, 1 = short, 2 = long) */
755 FALSE
, /* pc_relative */
757 complain_overflow_bitfield
, /* complain_on_overflow */
758 bfd_elf_generic_reloc
, /* special_function */
759 "R_PPC_UADDR16", /* name */
760 FALSE
, /* partial_inplace */
762 0xffff, /* dst_mask */
763 FALSE
), /* pcrel_offset */
765 /* 32-bit PC relative */
766 HOWTO (R_PPC_REL32
, /* type */
768 2, /* size (0 = byte, 1 = short, 2 = long) */
770 TRUE
, /* pc_relative */
772 complain_overflow_bitfield
, /* complain_on_overflow */
773 bfd_elf_generic_reloc
, /* special_function */
774 "R_PPC_REL32", /* name */
775 FALSE
, /* partial_inplace */
777 0xffffffff, /* dst_mask */
778 TRUE
), /* pcrel_offset */
780 /* 32-bit relocation to the symbol's procedure linkage table.
781 FIXME: not supported. */
782 HOWTO (R_PPC_PLT32
, /* type */
784 2, /* size (0 = byte, 1 = short, 2 = long) */
786 FALSE
, /* pc_relative */
788 complain_overflow_bitfield
, /* complain_on_overflow */
789 bfd_elf_generic_reloc
, /* special_function */
790 "R_PPC_PLT32", /* name */
791 FALSE
, /* partial_inplace */
794 FALSE
), /* pcrel_offset */
796 /* 32-bit PC relative relocation to the symbol's procedure linkage table.
797 FIXME: not supported. */
798 HOWTO (R_PPC_PLTREL32
, /* type */
800 2, /* size (0 = byte, 1 = short, 2 = long) */
802 TRUE
, /* pc_relative */
804 complain_overflow_bitfield
, /* complain_on_overflow */
805 bfd_elf_generic_reloc
, /* special_function */
806 "R_PPC_PLTREL32", /* name */
807 FALSE
, /* partial_inplace */
810 TRUE
), /* pcrel_offset */
812 /* Like R_PPC_ADDR16_LO, but referring to the PLT table entry for
814 HOWTO (R_PPC_PLT16_LO
, /* type */
816 1, /* size (0 = byte, 1 = short, 2 = long) */
818 FALSE
, /* pc_relative */
820 complain_overflow_dont
, /* complain_on_overflow */
821 bfd_elf_generic_reloc
, /* special_function */
822 "R_PPC_PLT16_LO", /* name */
823 FALSE
, /* partial_inplace */
825 0xffff, /* dst_mask */
826 FALSE
), /* pcrel_offset */
828 /* Like R_PPC_ADDR16_HI, but referring to the PLT table entry for
830 HOWTO (R_PPC_PLT16_HI
, /* type */
832 1, /* size (0 = byte, 1 = short, 2 = long) */
834 FALSE
, /* pc_relative */
836 complain_overflow_bitfield
, /* complain_on_overflow */
837 bfd_elf_generic_reloc
, /* special_function */
838 "R_PPC_PLT16_HI", /* name */
839 FALSE
, /* partial_inplace */
841 0xffff, /* dst_mask */
842 FALSE
), /* pcrel_offset */
844 /* Like R_PPC_ADDR16_HA, but referring to the PLT table entry for
846 HOWTO (R_PPC_PLT16_HA
, /* type */
848 1, /* size (0 = byte, 1 = short, 2 = long) */
850 FALSE
, /* pc_relative */
852 complain_overflow_bitfield
, /* complain_on_overflow */
853 ppc_elf_addr16_ha_reloc
, /* special_function */
854 "R_PPC_PLT16_HA", /* name */
855 FALSE
, /* partial_inplace */
857 0xffff, /* dst_mask */
858 FALSE
), /* pcrel_offset */
860 /* A sign-extended 16 bit value relative to _SDA_BASE_, for use with
862 HOWTO (R_PPC_SDAREL16
, /* type */
864 1, /* size (0 = byte, 1 = short, 2 = long) */
866 FALSE
, /* pc_relative */
868 complain_overflow_signed
, /* complain_on_overflow */
869 bfd_elf_generic_reloc
, /* special_function */
870 "R_PPC_SDAREL16", /* name */
871 FALSE
, /* partial_inplace */
873 0xffff, /* dst_mask */
874 FALSE
), /* pcrel_offset */
876 /* 16-bit section relative relocation. */
877 HOWTO (R_PPC_SECTOFF
, /* type */
879 1, /* size (0 = byte, 1 = short, 2 = long) */
881 FALSE
, /* pc_relative */
883 complain_overflow_bitfield
, /* complain_on_overflow */
884 bfd_elf_generic_reloc
, /* special_function */
885 "R_PPC_SECTOFF", /* name */
886 FALSE
, /* partial_inplace */
888 0xffff, /* dst_mask */
889 FALSE
), /* pcrel_offset */
891 /* 16-bit lower half section relative relocation. */
892 HOWTO (R_PPC_SECTOFF_LO
, /* type */
894 1, /* size (0 = byte, 1 = short, 2 = long) */
896 FALSE
, /* pc_relative */
898 complain_overflow_dont
, /* complain_on_overflow */
899 bfd_elf_generic_reloc
, /* special_function */
900 "R_PPC_SECTOFF_LO", /* name */
901 FALSE
, /* partial_inplace */
903 0xffff, /* dst_mask */
904 FALSE
), /* pcrel_offset */
906 /* 16-bit upper half section relative relocation. */
907 HOWTO (R_PPC_SECTOFF_HI
, /* type */
909 1, /* size (0 = byte, 1 = short, 2 = long) */
911 FALSE
, /* pc_relative */
913 complain_overflow_bitfield
, /* complain_on_overflow */
914 bfd_elf_generic_reloc
, /* special_function */
915 "R_PPC_SECTOFF_HI", /* name */
916 FALSE
, /* partial_inplace */
918 0xffff, /* dst_mask */
919 FALSE
), /* pcrel_offset */
921 /* 16-bit upper half adjusted section relative relocation. */
922 HOWTO (R_PPC_SECTOFF_HA
, /* type */
924 1, /* size (0 = byte, 1 = short, 2 = long) */
926 FALSE
, /* pc_relative */
928 complain_overflow_bitfield
, /* complain_on_overflow */
929 ppc_elf_addr16_ha_reloc
, /* special_function */
930 "R_PPC_SECTOFF_HA", /* name */
931 FALSE
, /* partial_inplace */
933 0xffff, /* dst_mask */
934 FALSE
), /* pcrel_offset */
936 /* Marker reloc for TLS. */
939 2, /* size (0 = byte, 1 = short, 2 = long) */
941 FALSE
, /* pc_relative */
943 complain_overflow_dont
, /* complain_on_overflow */
944 bfd_elf_generic_reloc
, /* special_function */
945 "R_PPC_TLS", /* name */
946 FALSE
, /* partial_inplace */
949 FALSE
), /* pcrel_offset */
951 /* Computes the load module index of the load module that contains the
952 definition of its TLS sym. */
953 HOWTO (R_PPC_DTPMOD32
,
955 2, /* size (0 = byte, 1 = short, 2 = long) */
957 FALSE
, /* pc_relative */
959 complain_overflow_dont
, /* complain_on_overflow */
960 ppc_elf_unhandled_reloc
, /* special_function */
961 "R_PPC_DTPMOD32", /* name */
962 FALSE
, /* partial_inplace */
964 0xffffffff, /* dst_mask */
965 FALSE
), /* pcrel_offset */
967 /* Computes a dtv-relative displacement, the difference between the value
968 of sym+add and the base address of the thread-local storage block that
969 contains the definition of sym, minus 0x8000. */
970 HOWTO (R_PPC_DTPREL32
,
972 2, /* size (0 = byte, 1 = short, 2 = long) */
974 FALSE
, /* pc_relative */
976 complain_overflow_dont
, /* complain_on_overflow */
977 ppc_elf_unhandled_reloc
, /* special_function */
978 "R_PPC_DTPREL32", /* name */
979 FALSE
, /* partial_inplace */
981 0xffffffff, /* dst_mask */
982 FALSE
), /* pcrel_offset */
984 /* A 16 bit dtprel reloc. */
985 HOWTO (R_PPC_DTPREL16
,
987 1, /* size (0 = byte, 1 = short, 2 = long) */
989 FALSE
, /* pc_relative */
991 complain_overflow_signed
, /* complain_on_overflow */
992 ppc_elf_unhandled_reloc
, /* special_function */
993 "R_PPC_DTPREL16", /* name */
994 FALSE
, /* partial_inplace */
996 0xffff, /* dst_mask */
997 FALSE
), /* pcrel_offset */
999 /* Like DTPREL16, but no overflow. */
1000 HOWTO (R_PPC_DTPREL16_LO
,
1002 1, /* size (0 = byte, 1 = short, 2 = long) */
1004 FALSE
, /* pc_relative */
1006 complain_overflow_dont
, /* complain_on_overflow */
1007 ppc_elf_unhandled_reloc
, /* special_function */
1008 "R_PPC_DTPREL16_LO", /* name */
1009 FALSE
, /* partial_inplace */
1011 0xffff, /* dst_mask */
1012 FALSE
), /* pcrel_offset */
1014 /* Like DTPREL16_LO, but next higher group of 16 bits. */
1015 HOWTO (R_PPC_DTPREL16_HI
,
1016 16, /* rightshift */
1017 1, /* size (0 = byte, 1 = short, 2 = long) */
1019 FALSE
, /* pc_relative */
1021 complain_overflow_dont
, /* complain_on_overflow */
1022 ppc_elf_unhandled_reloc
, /* special_function */
1023 "R_PPC_DTPREL16_HI", /* name */
1024 FALSE
, /* partial_inplace */
1026 0xffff, /* dst_mask */
1027 FALSE
), /* pcrel_offset */
1029 /* Like DTPREL16_HI, but adjust for low 16 bits. */
1030 HOWTO (R_PPC_DTPREL16_HA
,
1031 16, /* rightshift */
1032 1, /* size (0 = byte, 1 = short, 2 = long) */
1034 FALSE
, /* pc_relative */
1036 complain_overflow_dont
, /* complain_on_overflow */
1037 ppc_elf_unhandled_reloc
, /* special_function */
1038 "R_PPC_DTPREL16_HA", /* name */
1039 FALSE
, /* partial_inplace */
1041 0xffff, /* dst_mask */
1042 FALSE
), /* pcrel_offset */
1044 /* Computes a tp-relative displacement, the difference between the value of
1045 sym+add and the value of the thread pointer (r13). */
1046 HOWTO (R_PPC_TPREL32
,
1048 2, /* size (0 = byte, 1 = short, 2 = long) */
1050 FALSE
, /* pc_relative */
1052 complain_overflow_dont
, /* complain_on_overflow */
1053 ppc_elf_unhandled_reloc
, /* special_function */
1054 "R_PPC_TPREL32", /* name */
1055 FALSE
, /* partial_inplace */
1057 0xffffffff, /* dst_mask */
1058 FALSE
), /* pcrel_offset */
1060 /* A 16 bit tprel reloc. */
1061 HOWTO (R_PPC_TPREL16
,
1063 1, /* size (0 = byte, 1 = short, 2 = long) */
1065 FALSE
, /* pc_relative */
1067 complain_overflow_signed
, /* complain_on_overflow */
1068 ppc_elf_unhandled_reloc
, /* special_function */
1069 "R_PPC_TPREL16", /* name */
1070 FALSE
, /* partial_inplace */
1072 0xffff, /* dst_mask */
1073 FALSE
), /* pcrel_offset */
1075 /* Like TPREL16, but no overflow. */
1076 HOWTO (R_PPC_TPREL16_LO
,
1078 1, /* size (0 = byte, 1 = short, 2 = long) */
1080 FALSE
, /* pc_relative */
1082 complain_overflow_dont
, /* complain_on_overflow */
1083 ppc_elf_unhandled_reloc
, /* special_function */
1084 "R_PPC_TPREL16_LO", /* name */
1085 FALSE
, /* partial_inplace */
1087 0xffff, /* dst_mask */
1088 FALSE
), /* pcrel_offset */
1090 /* Like TPREL16_LO, but next higher group of 16 bits. */
1091 HOWTO (R_PPC_TPREL16_HI
,
1092 16, /* rightshift */
1093 1, /* size (0 = byte, 1 = short, 2 = long) */
1095 FALSE
, /* pc_relative */
1097 complain_overflow_dont
, /* complain_on_overflow */
1098 ppc_elf_unhandled_reloc
, /* special_function */
1099 "R_PPC_TPREL16_HI", /* name */
1100 FALSE
, /* partial_inplace */
1102 0xffff, /* dst_mask */
1103 FALSE
), /* pcrel_offset */
1105 /* Like TPREL16_HI, but adjust for low 16 bits. */
1106 HOWTO (R_PPC_TPREL16_HA
,
1107 16, /* rightshift */
1108 1, /* size (0 = byte, 1 = short, 2 = long) */
1110 FALSE
, /* pc_relative */
1112 complain_overflow_dont
, /* complain_on_overflow */
1113 ppc_elf_unhandled_reloc
, /* special_function */
1114 "R_PPC_TPREL16_HA", /* name */
1115 FALSE
, /* partial_inplace */
1117 0xffff, /* dst_mask */
1118 FALSE
), /* pcrel_offset */
1120 /* Allocates two contiguous entries in the GOT to hold a tls_index structure,
1121 with values (sym+add)@dtpmod and (sym+add)@dtprel, and computes the offset
1122 to the first entry. */
1123 HOWTO (R_PPC_GOT_TLSGD16
,
1125 1, /* size (0 = byte, 1 = short, 2 = long) */
1127 FALSE
, /* pc_relative */
1129 complain_overflow_signed
, /* complain_on_overflow */
1130 ppc_elf_unhandled_reloc
, /* special_function */
1131 "R_PPC_GOT_TLSGD16", /* name */
1132 FALSE
, /* partial_inplace */
1134 0xffff, /* dst_mask */
1135 FALSE
), /* pcrel_offset */
1137 /* Like GOT_TLSGD16, but no overflow. */
1138 HOWTO (R_PPC_GOT_TLSGD16_LO
,
1140 1, /* size (0 = byte, 1 = short, 2 = long) */
1142 FALSE
, /* pc_relative */
1144 complain_overflow_dont
, /* complain_on_overflow */
1145 ppc_elf_unhandled_reloc
, /* special_function */
1146 "R_PPC_GOT_TLSGD16_LO", /* name */
1147 FALSE
, /* partial_inplace */
1149 0xffff, /* dst_mask */
1150 FALSE
), /* pcrel_offset */
1152 /* Like GOT_TLSGD16_LO, but next higher group of 16 bits. */
1153 HOWTO (R_PPC_GOT_TLSGD16_HI
,
1154 16, /* rightshift */
1155 1, /* size (0 = byte, 1 = short, 2 = long) */
1157 FALSE
, /* pc_relative */
1159 complain_overflow_dont
, /* complain_on_overflow */
1160 ppc_elf_unhandled_reloc
, /* special_function */
1161 "R_PPC_GOT_TLSGD16_HI", /* name */
1162 FALSE
, /* partial_inplace */
1164 0xffff, /* dst_mask */
1165 FALSE
), /* pcrel_offset */
1167 /* Like GOT_TLSGD16_HI, but adjust for low 16 bits. */
1168 HOWTO (R_PPC_GOT_TLSGD16_HA
,
1169 16, /* rightshift */
1170 1, /* size (0 = byte, 1 = short, 2 = long) */
1172 FALSE
, /* pc_relative */
1174 complain_overflow_dont
, /* complain_on_overflow */
1175 ppc_elf_unhandled_reloc
, /* special_function */
1176 "R_PPC_GOT_TLSGD16_HA", /* name */
1177 FALSE
, /* partial_inplace */
1179 0xffff, /* dst_mask */
1180 FALSE
), /* pcrel_offset */
1182 /* Allocates two contiguous entries in the GOT to hold a tls_index structure,
1183 with values (sym+add)@dtpmod and zero, and computes the offset to the
1185 HOWTO (R_PPC_GOT_TLSLD16
,
1187 1, /* size (0 = byte, 1 = short, 2 = long) */
1189 FALSE
, /* pc_relative */
1191 complain_overflow_signed
, /* complain_on_overflow */
1192 ppc_elf_unhandled_reloc
, /* special_function */
1193 "R_PPC_GOT_TLSLD16", /* name */
1194 FALSE
, /* partial_inplace */
1196 0xffff, /* dst_mask */
1197 FALSE
), /* pcrel_offset */
1199 /* Like GOT_TLSLD16, but no overflow. */
1200 HOWTO (R_PPC_GOT_TLSLD16_LO
,
1202 1, /* size (0 = byte, 1 = short, 2 = long) */
1204 FALSE
, /* pc_relative */
1206 complain_overflow_dont
, /* complain_on_overflow */
1207 ppc_elf_unhandled_reloc
, /* special_function */
1208 "R_PPC_GOT_TLSLD16_LO", /* name */
1209 FALSE
, /* partial_inplace */
1211 0xffff, /* dst_mask */
1212 FALSE
), /* pcrel_offset */
1214 /* Like GOT_TLSLD16_LO, but next higher group of 16 bits. */
1215 HOWTO (R_PPC_GOT_TLSLD16_HI
,
1216 16, /* rightshift */
1217 1, /* size (0 = byte, 1 = short, 2 = long) */
1219 FALSE
, /* pc_relative */
1221 complain_overflow_dont
, /* complain_on_overflow */
1222 ppc_elf_unhandled_reloc
, /* special_function */
1223 "R_PPC_GOT_TLSLD16_HI", /* name */
1224 FALSE
, /* partial_inplace */
1226 0xffff, /* dst_mask */
1227 FALSE
), /* pcrel_offset */
1229 /* Like GOT_TLSLD16_HI, but adjust for low 16 bits. */
1230 HOWTO (R_PPC_GOT_TLSLD16_HA
,
1231 16, /* rightshift */
1232 1, /* size (0 = byte, 1 = short, 2 = long) */
1234 FALSE
, /* pc_relative */
1236 complain_overflow_dont
, /* complain_on_overflow */
1237 ppc_elf_unhandled_reloc
, /* special_function */
1238 "R_PPC_GOT_TLSLD16_HA", /* name */
1239 FALSE
, /* partial_inplace */
1241 0xffff, /* dst_mask */
1242 FALSE
), /* pcrel_offset */
1244 /* Allocates an entry in the GOT with value (sym+add)@dtprel, and computes
1245 the offset to the entry. */
1246 HOWTO (R_PPC_GOT_DTPREL16
,
1248 1, /* size (0 = byte, 1 = short, 2 = long) */
1250 FALSE
, /* pc_relative */
1252 complain_overflow_signed
, /* complain_on_overflow */
1253 ppc_elf_unhandled_reloc
, /* special_function */
1254 "R_PPC_GOT_DTPREL16", /* name */
1255 FALSE
, /* partial_inplace */
1257 0xffff, /* dst_mask */
1258 FALSE
), /* pcrel_offset */
1260 /* Like GOT_DTPREL16, but no overflow. */
1261 HOWTO (R_PPC_GOT_DTPREL16_LO
,
1263 1, /* size (0 = byte, 1 = short, 2 = long) */
1265 FALSE
, /* pc_relative */
1267 complain_overflow_dont
, /* complain_on_overflow */
1268 ppc_elf_unhandled_reloc
, /* special_function */
1269 "R_PPC_GOT_DTPREL16_LO", /* name */
1270 FALSE
, /* partial_inplace */
1272 0xffff, /* dst_mask */
1273 FALSE
), /* pcrel_offset */
1275 /* Like GOT_DTPREL16_LO, but next higher group of 16 bits. */
1276 HOWTO (R_PPC_GOT_DTPREL16_HI
,
1277 16, /* rightshift */
1278 1, /* size (0 = byte, 1 = short, 2 = long) */
1280 FALSE
, /* pc_relative */
1282 complain_overflow_dont
, /* complain_on_overflow */
1283 ppc_elf_unhandled_reloc
, /* special_function */
1284 "R_PPC_GOT_DTPREL16_HI", /* name */
1285 FALSE
, /* partial_inplace */
1287 0xffff, /* dst_mask */
1288 FALSE
), /* pcrel_offset */
1290 /* Like GOT_DTPREL16_HI, but adjust for low 16 bits. */
1291 HOWTO (R_PPC_GOT_DTPREL16_HA
,
1292 16, /* rightshift */
1293 1, /* size (0 = byte, 1 = short, 2 = long) */
1295 FALSE
, /* pc_relative */
1297 complain_overflow_dont
, /* complain_on_overflow */
1298 ppc_elf_unhandled_reloc
, /* special_function */
1299 "R_PPC_GOT_DTPREL16_HA", /* name */
1300 FALSE
, /* partial_inplace */
1302 0xffff, /* dst_mask */
1303 FALSE
), /* pcrel_offset */
1305 /* Allocates an entry in the GOT with value (sym+add)@tprel, and computes the
1306 offset to the entry. */
1307 HOWTO (R_PPC_GOT_TPREL16
,
1309 1, /* size (0 = byte, 1 = short, 2 = long) */
1311 FALSE
, /* pc_relative */
1313 complain_overflow_signed
, /* complain_on_overflow */
1314 ppc_elf_unhandled_reloc
, /* special_function */
1315 "R_PPC_GOT_TPREL16", /* name */
1316 FALSE
, /* partial_inplace */
1318 0xffff, /* dst_mask */
1319 FALSE
), /* pcrel_offset */
1321 /* Like GOT_TPREL16, but no overflow. */
1322 HOWTO (R_PPC_GOT_TPREL16_LO
,
1324 1, /* size (0 = byte, 1 = short, 2 = long) */
1326 FALSE
, /* pc_relative */
1328 complain_overflow_dont
, /* complain_on_overflow */
1329 ppc_elf_unhandled_reloc
, /* special_function */
1330 "R_PPC_GOT_TPREL16_LO", /* name */
1331 FALSE
, /* partial_inplace */
1333 0xffff, /* dst_mask */
1334 FALSE
), /* pcrel_offset */
1336 /* Like GOT_TPREL16_LO, but next higher group of 16 bits. */
1337 HOWTO (R_PPC_GOT_TPREL16_HI
,
1338 16, /* rightshift */
1339 1, /* size (0 = byte, 1 = short, 2 = long) */
1341 FALSE
, /* pc_relative */
1343 complain_overflow_dont
, /* complain_on_overflow */
1344 ppc_elf_unhandled_reloc
, /* special_function */
1345 "R_PPC_GOT_TPREL16_HI", /* name */
1346 FALSE
, /* partial_inplace */
1348 0xffff, /* dst_mask */
1349 FALSE
), /* pcrel_offset */
1351 /* Like GOT_TPREL16_HI, but adjust for low 16 bits. */
1352 HOWTO (R_PPC_GOT_TPREL16_HA
,
1353 16, /* rightshift */
1354 1, /* size (0 = byte, 1 = short, 2 = long) */
1356 FALSE
, /* pc_relative */
1358 complain_overflow_dont
, /* complain_on_overflow */
1359 ppc_elf_unhandled_reloc
, /* special_function */
1360 "R_PPC_GOT_TPREL16_HA", /* name */
1361 FALSE
, /* partial_inplace */
1363 0xffff, /* dst_mask */
1364 FALSE
), /* pcrel_offset */
1366 /* The remaining relocs are from the Embedded ELF ABI, and are not
1367 in the SVR4 ELF ABI. */
1369 /* 32 bit value resulting from the addend minus the symbol. */
1370 HOWTO (R_PPC_EMB_NADDR32
, /* type */
1372 2, /* size (0 = byte, 1 = short, 2 = long) */
1374 FALSE
, /* pc_relative */
1376 complain_overflow_bitfield
, /* complain_on_overflow */
1377 bfd_elf_generic_reloc
, /* special_function */
1378 "R_PPC_EMB_NADDR32", /* name */
1379 FALSE
, /* partial_inplace */
1381 0xffffffff, /* dst_mask */
1382 FALSE
), /* pcrel_offset */
1384 /* 16 bit value resulting from the addend minus the symbol. */
1385 HOWTO (R_PPC_EMB_NADDR16
, /* type */
1387 1, /* size (0 = byte, 1 = short, 2 = long) */
1389 FALSE
, /* pc_relative */
1391 complain_overflow_bitfield
, /* complain_on_overflow */
1392 bfd_elf_generic_reloc
, /* special_function */
1393 "R_PPC_EMB_NADDR16", /* name */
1394 FALSE
, /* partial_inplace */
1396 0xffff, /* dst_mask */
1397 FALSE
), /* pcrel_offset */
1399 /* 16 bit value resulting from the addend minus the symbol. */
1400 HOWTO (R_PPC_EMB_NADDR16_LO
, /* type */
1402 1, /* size (0 = byte, 1 = short, 2 = long) */
1404 FALSE
, /* pc_relative */
1406 complain_overflow_dont
,/* complain_on_overflow */
1407 bfd_elf_generic_reloc
, /* special_function */
1408 "R_PPC_EMB_ADDR16_LO", /* name */
1409 FALSE
, /* partial_inplace */
1411 0xffff, /* dst_mask */
1412 FALSE
), /* pcrel_offset */
1414 /* The high order 16 bits of the addend minus the symbol. */
1415 HOWTO (R_PPC_EMB_NADDR16_HI
, /* type */
1416 16, /* rightshift */
1417 1, /* size (0 = byte, 1 = short, 2 = long) */
1419 FALSE
, /* pc_relative */
1421 complain_overflow_dont
, /* complain_on_overflow */
1422 bfd_elf_generic_reloc
, /* special_function */
1423 "R_PPC_EMB_NADDR16_HI", /* name */
1424 FALSE
, /* partial_inplace */
1426 0xffff, /* dst_mask */
1427 FALSE
), /* pcrel_offset */
1429 /* The high order 16 bits of the result of the addend minus the address,
1430 plus 1 if the contents of the low 16 bits, treated as a signed number,
1432 HOWTO (R_PPC_EMB_NADDR16_HA
, /* type */
1433 16, /* rightshift */
1434 1, /* size (0 = byte, 1 = short, 2 = long) */
1436 FALSE
, /* pc_relative */
1438 complain_overflow_dont
, /* complain_on_overflow */
1439 ppc_elf_addr16_ha_reloc
, /* special_function */
1440 "R_PPC_EMB_NADDR16_HA", /* name */
1441 FALSE
, /* partial_inplace */
1443 0xffff, /* dst_mask */
1444 FALSE
), /* pcrel_offset */
1446 /* 16 bit value resulting from allocating a 4 byte word to hold an
1447 address in the .sdata section, and returning the offset from
1448 _SDA_BASE_ for that relocation. */
1449 HOWTO (R_PPC_EMB_SDAI16
, /* type */
1451 1, /* size (0 = byte, 1 = short, 2 = long) */
1453 FALSE
, /* pc_relative */
1455 complain_overflow_bitfield
, /* complain_on_overflow */
1456 bfd_elf_generic_reloc
, /* special_function */
1457 "R_PPC_EMB_SDAI16", /* name */
1458 FALSE
, /* partial_inplace */
1460 0xffff, /* dst_mask */
1461 FALSE
), /* pcrel_offset */
1463 /* 16 bit value resulting from allocating a 4 byte word to hold an
1464 address in the .sdata2 section, and returning the offset from
1465 _SDA2_BASE_ for that relocation. */
1466 HOWTO (R_PPC_EMB_SDA2I16
, /* type */
1468 1, /* size (0 = byte, 1 = short, 2 = long) */
1470 FALSE
, /* pc_relative */
1472 complain_overflow_bitfield
, /* complain_on_overflow */
1473 bfd_elf_generic_reloc
, /* special_function */
1474 "R_PPC_EMB_SDA2I16", /* name */
1475 FALSE
, /* partial_inplace */
1477 0xffff, /* dst_mask */
1478 FALSE
), /* pcrel_offset */
1480 /* A sign-extended 16 bit value relative to _SDA2_BASE_, for use with
1481 small data items. */
1482 HOWTO (R_PPC_EMB_SDA2REL
, /* type */
1484 1, /* size (0 = byte, 1 = short, 2 = long) */
1486 FALSE
, /* pc_relative */
1488 complain_overflow_signed
, /* complain_on_overflow */
1489 bfd_elf_generic_reloc
, /* special_function */
1490 "R_PPC_EMB_SDA2REL", /* name */
1491 FALSE
, /* partial_inplace */
1493 0xffff, /* dst_mask */
1494 FALSE
), /* pcrel_offset */
1496 /* Relocate against either _SDA_BASE_ or _SDA2_BASE_, filling in the 16 bit
1497 signed offset from the appropriate base, and filling in the register
1498 field with the appropriate register (0, 2, or 13). */
1499 HOWTO (R_PPC_EMB_SDA21
, /* type */
1501 2, /* size (0 = byte, 1 = short, 2 = long) */
1503 FALSE
, /* pc_relative */
1505 complain_overflow_signed
, /* complain_on_overflow */
1506 bfd_elf_generic_reloc
, /* special_function */
1507 "R_PPC_EMB_SDA21", /* name */
1508 FALSE
, /* partial_inplace */
1510 0xffff, /* dst_mask */
1511 FALSE
), /* pcrel_offset */
1513 /* Relocation not handled: R_PPC_EMB_MRKREF */
1514 /* Relocation not handled: R_PPC_EMB_RELSEC16 */
1515 /* Relocation not handled: R_PPC_EMB_RELST_LO */
1516 /* Relocation not handled: R_PPC_EMB_RELST_HI */
1517 /* Relocation not handled: R_PPC_EMB_RELST_HA */
1518 /* Relocation not handled: R_PPC_EMB_BIT_FLD */
1520 /* PC relative relocation against either _SDA_BASE_ or _SDA2_BASE_, filling
1521 in the 16 bit signed offset from the appropriate base, and filling in the
1522 register field with the appropriate register (0, 2, or 13). */
1523 HOWTO (R_PPC_EMB_RELSDA
, /* type */
1525 1, /* size (0 = byte, 1 = short, 2 = long) */
1527 TRUE
, /* pc_relative */
1529 complain_overflow_signed
, /* complain_on_overflow */
1530 bfd_elf_generic_reloc
, /* special_function */
1531 "R_PPC_EMB_RELSDA", /* name */
1532 FALSE
, /* partial_inplace */
1534 0xffff, /* dst_mask */
1535 FALSE
), /* pcrel_offset */
1537 /* Phony reloc to handle branch stubs. */
1538 HOWTO (R_PPC_RELAX32
, /* type */
1542 FALSE
, /* pc_relative */
1544 complain_overflow_dont
, /* complain_on_overflow */
1545 bfd_elf_generic_reloc
, /* special_function */
1546 "R_PPC_RELAX32", /* name */
1547 FALSE
, /* partial_inplace */
1550 FALSE
), /* pcrel_offset */
1552 /* GNU extension to record C++ vtable hierarchy. */
1553 HOWTO (R_PPC_GNU_VTINHERIT
, /* type */
1555 0, /* size (0 = byte, 1 = short, 2 = long) */
1557 FALSE
, /* pc_relative */
1559 complain_overflow_dont
, /* complain_on_overflow */
1560 NULL
, /* special_function */
1561 "R_PPC_GNU_VTINHERIT", /* name */
1562 FALSE
, /* partial_inplace */
1565 FALSE
), /* pcrel_offset */
1567 /* GNU extension to record C++ vtable member usage. */
1568 HOWTO (R_PPC_GNU_VTENTRY
, /* type */
1570 0, /* size (0 = byte, 1 = short, 2 = long) */
1572 FALSE
, /* pc_relative */
1574 complain_overflow_dont
, /* complain_on_overflow */
1575 NULL
, /* special_function */
1576 "R_PPC_GNU_VTENTRY", /* name */
1577 FALSE
, /* partial_inplace */
1580 FALSE
), /* pcrel_offset */
1582 /* Phony reloc to handle AIX style TOC entries. */
1583 HOWTO (R_PPC_TOC16
, /* type */
1585 1, /* size (0 = byte, 1 = short, 2 = long) */
1587 FALSE
, /* pc_relative */
1589 complain_overflow_signed
, /* complain_on_overflow */
1590 bfd_elf_generic_reloc
, /* special_function */
1591 "R_PPC_TOC16", /* name */
1592 FALSE
, /* partial_inplace */
1594 0xffff, /* dst_mask */
1595 FALSE
), /* pcrel_offset */
1598 /* Initialize the ppc_elf_howto_table, so that linear accesses can be done. */
1601 ppc_elf_howto_init (void)
1603 unsigned int i
, type
;
1606 i
< sizeof (ppc_elf_howto_raw
) / sizeof (ppc_elf_howto_raw
[0]);
1609 type
= ppc_elf_howto_raw
[i
].type
;
1610 if (type
>= (sizeof (ppc_elf_howto_table
)
1611 / sizeof (ppc_elf_howto_table
[0])))
1613 ppc_elf_howto_table
[type
] = &ppc_elf_howto_raw
[i
];
1617 static bfd_reloc_status_type
1618 ppc_elf_install_value (bfd
*abfd
,
1621 unsigned int r_type
)
1624 #ifdef BFD_HOST_U_64_BIT
1625 BFD_HOST_U_64_BIT val
= (BFD_HOST_U_64_BIT
) v
;
1633 /* Do stuff here. */
1634 t0
= bfd_get_32 (abfd
, hit_addr
);
1635 t1
= bfd_get_32 (abfd
, hit_addr
+ 4);
1637 /* We're clearing the bits for R_PPC_ADDR16_HA
1638 and R_PPC_ADDR16_LO here. */
1642 /* t0 is HA, t1 is lo */
1643 t0
|= ((val
+ 0x8000) >> 16) & 0xffff;
1646 bfd_put_32 (abfd
, t0
, hit_addr
);
1647 bfd_put_32 (abfd
, t1
, hit_addr
+ 4);
1651 t0
= bfd_get_32 (abfd
, hit_addr
);
1653 t0
|= val
& 0x3fffffc;
1654 bfd_put_32 (abfd
, t0
, hit_addr
);
1658 case R_PPC_REL14_BRTAKEN
:
1659 case R_PPC_REL14_BRNTAKEN
:
1660 t0
= bfd_get_32 (abfd
, hit_addr
);
1663 bfd_put_32 (abfd
, t0
, hit_addr
);
1666 case R_PPC_LOCAL24PC
:
1667 case R_PPC_PLTREL24
:
1668 t0
= bfd_get_32 (abfd
, hit_addr
);
1670 t0
|= val
& 0x3fffffc;
1671 bfd_put_32 (abfd
, t0
, hit_addr
);
1675 return bfd_reloc_notsupported
;
1678 return bfd_reloc_ok
;
1681 static const bfd_byte shared_stub_entry
[] =
1683 0x48, 0x00, 0x00, 0x24, /* b .+36 */
1684 0x7c, 0x08, 0x02, 0xa6, /* mflr 0 */
1685 0x42, 0x9f, 0x00, 0x05, /* bcl 20, 31, .Lxxx */
1686 0x7d, 0x68, 0x02, 0xa6, /* mflr 11 */
1687 0x3d, 0x60, 0x00, 0x00, /* addis 11, 11, (xxx-.Lxxx)@ha */
1688 0x39, 0x6b, 0x00, 0x18, /* addi 11, 11, (xxx-.Lxxx)@l */
1689 0x7c, 0x08, 0x03, 0xa6, /* mtlr 0 */
1690 0x7d, 0x69, 0x03, 0xa6, /* mtctr 11 */
1691 0x4e, 0x80, 0x04, 0x20, /* bctr */
1694 static const bfd_byte stub_entry
[] =
1696 0x48, 0x00, 0x00, 0x14, /* b .+20 */
1697 0x3d, 0x60, 0x00, 0x00, /* lis 11,xxx@ha */
1698 0x39, 0x6b, 0x00, 0x00, /* addi 11,11,xxx@l */
1699 0x7d, 0x69, 0x03, 0xa6, /* mtctr 11 */
1700 0x4e, 0x80, 0x04, 0x20, /* bctr */
1705 ppc_elf_relax_section (bfd
*abfd
,
1707 struct bfd_link_info
*link_info
,
1712 struct one_fixup
*next
;
1718 Elf_Internal_Shdr
*symtab_hdr
;
1719 bfd_byte
*contents
= NULL
;
1720 Elf_Internal_Sym
*isymbuf
= NULL
;
1721 Elf_Internal_Rela
*internal_relocs
= NULL
;
1722 Elf_Internal_Rela
*irel
, *irelend
;
1723 struct one_fixup
*fixups
= NULL
;
1724 bfd_boolean changed_contents
= FALSE
;
1725 bfd_boolean changed_relocs
= FALSE
;
1726 struct ppc_elf_link_hash_table
*ppc_info
;
1730 /* Nothing to do if there are no relocations and no need for
1731 the relax finalize pass. */
1732 if ((isec
->flags
& SEC_RELOC
) == 0
1733 || isec
->reloc_count
== 0
1734 || link_info
->relax_finalizing
)
1737 /* If needed, initialize this section's cooked size. */
1738 if (isec
->_cooked_size
== 0)
1739 isec
->_cooked_size
= isec
->_raw_size
;
1741 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
1743 /* Get a copy of the native relocations. */
1744 internal_relocs
= _bfd_elf_link_read_relocs (abfd
, isec
, NULL
, NULL
,
1745 link_info
->keep_memory
);
1746 if (internal_relocs
== NULL
)
1749 ppc_info
= ppc_elf_hash_table (link_info
);
1750 irelend
= internal_relocs
+ isec
->reloc_count
;
1752 /* Get the section contents. */
1753 /* Get cached copy if it exists. */
1754 if (elf_section_data (isec
)->this_hdr
.contents
!= NULL
)
1755 contents
= elf_section_data (isec
)->this_hdr
.contents
;
1758 /* Go get them off disk. */
1759 contents
= bfd_malloc (isec
->_raw_size
);
1760 if (contents
== NULL
)
1763 if (!bfd_get_section_contents (abfd
, isec
, contents
, 0, isec
->_raw_size
))
1767 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
1769 unsigned long r_type
= ELF32_R_TYPE (irel
->r_info
);
1770 bfd_vma symaddr
, reladdr
, trampoff
, toff
, roff
;
1773 struct one_fixup
*f
;
1774 size_t insn_offset
= 0;
1775 bfd_vma max_branch_offset
;
1780 case R_PPC_LOCAL24PC
:
1782 case R_PPC_REL14_BRTAKEN
:
1783 case R_PPC_REL14_BRNTAKEN
:
1784 case R_PPC_PLTREL24
:
1791 /* Get the value of the symbol referred to by the reloc. */
1792 if (ELF32_R_SYM (irel
->r_info
) < symtab_hdr
->sh_info
)
1794 /* A local symbol. */
1795 Elf_Internal_Sym
*isym
;
1797 /* Read this BFD's local symbols. */
1798 if (isymbuf
== NULL
)
1800 isymbuf
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
1801 if (isymbuf
== NULL
)
1802 isymbuf
= bfd_elf_get_elf_syms (abfd
, symtab_hdr
,
1803 symtab_hdr
->sh_info
, 0,
1808 isym
= isymbuf
+ ELF32_R_SYM (irel
->r_info
);
1809 if (isym
->st_shndx
== SHN_UNDEF
)
1810 continue; /* We can't do anthing with undefined symbols. */
1811 else if (isym
->st_shndx
== SHN_ABS
)
1812 tsec
= bfd_abs_section_ptr
;
1813 else if (isym
->st_shndx
== SHN_COMMON
)
1814 tsec
= bfd_com_section_ptr
;
1816 tsec
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
1818 toff
= isym
->st_value
;
1822 /* Need dynamic symbol handling. */
1824 struct elf_link_hash_entry
*h
;
1826 indx
= ELF32_R_SYM (irel
->r_info
) - symtab_hdr
->sh_info
;
1827 h
= elf_sym_hashes (abfd
)[indx
];
1829 while (h
->root
.type
== bfd_link_hash_indirect
1830 || h
->root
.type
== bfd_link_hash_warning
)
1831 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1833 if (r_type
== R_PPC_PLTREL24
)
1835 Elf_Internal_Sym
*isym
;
1837 if (h
->plt
.offset
== (bfd_vma
) -1
1838 || ppc_info
->plt
== NULL
)
1841 /* Read this BFD's local symbols. */
1842 if (isymbuf
== NULL
)
1844 isymbuf
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
1845 if (isymbuf
== NULL
)
1846 isymbuf
= bfd_elf_get_elf_syms (abfd
, symtab_hdr
,
1847 symtab_hdr
->sh_info
, 0,
1852 isym
= isymbuf
+ ELF32_R_SYM (irel
->r_info
);
1854 if (isym
->st_shndx
== SHN_UNDEF
)
1855 /* We can't do anthing with undefined symbols. */
1857 else if (isym
->st_shndx
== SHN_ABS
)
1858 tsec
= bfd_abs_section_ptr
;
1859 else if (isym
->st_shndx
== SHN_COMMON
)
1860 tsec
= bfd_com_section_ptr
;
1862 tsec
= h
->root
.u
.def
.section
;
1864 toff
= h
->root
.u
.def
.value
;
1868 tsec
= ppc_info
->plt
;
1869 toff
= h
->plt
.offset
;
1872 else if (h
->root
.type
== bfd_link_hash_undefined
1873 || h
->root
.type
== bfd_link_hash_undefweak
)
1878 tsec
= h
->root
.u
.def
.section
;
1879 toff
= h
->root
.u
.def
.value
;
1883 if (tsec
->sec_info_type
== ELF_INFO_TYPE_MERGE
)
1884 toff
= _bfd_merged_section_offset (abfd
, &tsec
,
1885 elf_section_data (tsec
)->sec_info
,
1886 toff
+ irel
->r_addend
, 0);
1888 toff
+= irel
->r_addend
;
1890 symaddr
= tsec
->output_section
->vma
+ tsec
->output_offset
+ toff
;
1892 roff
= irel
->r_offset
;
1894 reladdr
= (isec
->output_section
->vma
1895 + isec
->output_offset
1896 + roff
) & (bfd_vma
) -4;
1898 /* If the branch is in range, no need to do anything. */
1899 max_branch_offset
= 1 << 25;
1900 if (r_type
!= R_PPC_REL24
1901 && r_type
!= R_PPC_LOCAL24PC
1902 && r_type
!= R_PPC_PLTREL24
)
1903 max_branch_offset
= 1 << 15;
1905 if ((bfd_vma
) (symaddr
- reladdr
) + max_branch_offset
1906 <= 2 * max_branch_offset
)
1909 /* If the branch and target are in the same section, you have
1910 no hope. We'll error out later. */
1914 /* Look for an existing fixup to this address. */
1915 for (f
= fixups
; f
; f
= f
->next
)
1916 if (f
->tsec
== tsec
&& f
->toff
== toff
)
1923 if (link_info
->shared
1924 || tsec
== ppc_info
->plt
1925 || r_type
== R_PPC_LOCAL24PC
)
1927 size
= sizeof (shared_stub_entry
);
1932 size
= sizeof (stub_entry
);
1936 /* Resize the current section to make room for the new branch. */
1937 trampoff
= (isec
->_cooked_size
+ 3) & (bfd_vma
) - 4;
1938 amt
= trampoff
+ size
;
1939 contents
= bfd_realloc (contents
, amt
);
1940 if (contents
== NULL
)
1943 isec
->_cooked_size
= amt
;
1945 if (link_info
->shared
1946 || tsec
== ppc_info
->plt
1947 || r_type
== R_PPC_LOCAL24PC
)
1948 memcpy (contents
+ trampoff
, shared_stub_entry
, size
);
1950 memcpy (contents
+ trampoff
, stub_entry
, size
);
1952 /* Hijack the old relocation. Since we need two
1953 relocations for this use a "composite" reloc. */
1954 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
),
1956 irel
->r_offset
= trampoff
+ insn_offset
;
1958 /* Record the fixup so we don't do it again this section. */
1959 f
= bfd_malloc (sizeof (*f
));
1963 f
->trampoff
= trampoff
;
1968 /* Nop out the reloc, since we're finalizing things here. */
1969 irel
->r_info
= ELF32_R_INFO (0, R_PPC_NONE
);
1972 /* Fix up the existing branch to hit the trampoline. Hope like
1973 hell this doesn't overflow too. */
1974 if (ppc_elf_install_value (abfd
, contents
+ roff
,
1975 f
->trampoff
- (roff
& (bfd_vma
) -3) + 4,
1976 r_type
) != bfd_reloc_ok
)
1979 changed_contents
= TRUE
;
1980 changed_relocs
= TRUE
;
1986 struct one_fixup
*f
= fixups
;
1987 fixups
= fixups
->next
;
1991 && symtab_hdr
->contents
!= (unsigned char *) isymbuf
)
1993 if (! link_info
->keep_memory
)
1997 /* Cache the symbols for elf_link_input_bfd. */
1998 symtab_hdr
->contents
= (unsigned char *) isymbuf
;
2002 if (contents
!= NULL
2003 && elf_section_data (isec
)->this_hdr
.contents
!= contents
)
2005 if (!changed_contents
&& !link_info
->keep_memory
)
2009 /* Cache the section contents for elf_link_input_bfd. */
2010 elf_section_data (isec
)->this_hdr
.contents
= contents
;
2014 if (elf_section_data (isec
)->relocs
!= internal_relocs
)
2016 if (!changed_relocs
)
2017 free (internal_relocs
);
2019 elf_section_data (isec
)->relocs
= internal_relocs
;
2022 *again
= changed_contents
|| changed_relocs
;
2026 if (isymbuf
!= NULL
&& (unsigned char *) isymbuf
!= symtab_hdr
->contents
)
2028 if (contents
!= NULL
2029 && elf_section_data (isec
)->this_hdr
.contents
!= contents
)
2031 if (internal_relocs
!= NULL
2032 && elf_section_data (isec
)->relocs
!= internal_relocs
)
2033 free (internal_relocs
);
2037 static reloc_howto_type
*
2038 ppc_elf_reloc_type_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
2039 bfd_reloc_code_real_type code
)
2041 enum elf_ppc_reloc_type r
;
2043 /* Initialize howto table if not already done. */
2044 if (!ppc_elf_howto_table
[R_PPC_ADDR32
])
2045 ppc_elf_howto_init ();
2052 case BFD_RELOC_NONE
: r
= R_PPC_NONE
; break;
2053 case BFD_RELOC_32
: r
= R_PPC_ADDR32
; break;
2054 case BFD_RELOC_PPC_BA26
: r
= R_PPC_ADDR24
; break;
2055 case BFD_RELOC_16
: r
= R_PPC_ADDR16
; break;
2056 case BFD_RELOC_LO16
: r
= R_PPC_ADDR16_LO
; break;
2057 case BFD_RELOC_HI16
: r
= R_PPC_ADDR16_HI
; break;
2058 case BFD_RELOC_HI16_S
: r
= R_PPC_ADDR16_HA
; break;
2059 case BFD_RELOC_PPC_BA16
: r
= R_PPC_ADDR14
; break;
2060 case BFD_RELOC_PPC_BA16_BRTAKEN
: r
= R_PPC_ADDR14_BRTAKEN
; break;
2061 case BFD_RELOC_PPC_BA16_BRNTAKEN
: r
= R_PPC_ADDR14_BRNTAKEN
; break;
2062 case BFD_RELOC_PPC_B26
: r
= R_PPC_REL24
; break;
2063 case BFD_RELOC_PPC_B16
: r
= R_PPC_REL14
; break;
2064 case BFD_RELOC_PPC_B16_BRTAKEN
: r
= R_PPC_REL14_BRTAKEN
; break;
2065 case BFD_RELOC_PPC_B16_BRNTAKEN
: r
= R_PPC_REL14_BRNTAKEN
; break;
2066 case BFD_RELOC_16_GOTOFF
: r
= R_PPC_GOT16
; break;
2067 case BFD_RELOC_LO16_GOTOFF
: r
= R_PPC_GOT16_LO
; break;
2068 case BFD_RELOC_HI16_GOTOFF
: r
= R_PPC_GOT16_HI
; break;
2069 case BFD_RELOC_HI16_S_GOTOFF
: r
= R_PPC_GOT16_HA
; break;
2070 case BFD_RELOC_24_PLT_PCREL
: r
= R_PPC_PLTREL24
; break;
2071 case BFD_RELOC_PPC_COPY
: r
= R_PPC_COPY
; break;
2072 case BFD_RELOC_PPC_GLOB_DAT
: r
= R_PPC_GLOB_DAT
; break;
2073 case BFD_RELOC_PPC_LOCAL24PC
: r
= R_PPC_LOCAL24PC
; break;
2074 case BFD_RELOC_32_PCREL
: r
= R_PPC_REL32
; break;
2075 case BFD_RELOC_32_PLTOFF
: r
= R_PPC_PLT32
; break;
2076 case BFD_RELOC_32_PLT_PCREL
: r
= R_PPC_PLTREL32
; break;
2077 case BFD_RELOC_LO16_PLTOFF
: r
= R_PPC_PLT16_LO
; break;
2078 case BFD_RELOC_HI16_PLTOFF
: r
= R_PPC_PLT16_HI
; break;
2079 case BFD_RELOC_HI16_S_PLTOFF
: r
= R_PPC_PLT16_HA
; break;
2080 case BFD_RELOC_GPREL16
: r
= R_PPC_SDAREL16
; break;
2081 case BFD_RELOC_16_BASEREL
: r
= R_PPC_SECTOFF
; break;
2082 case BFD_RELOC_LO16_BASEREL
: r
= R_PPC_SECTOFF_LO
; break;
2083 case BFD_RELOC_HI16_BASEREL
: r
= R_PPC_SECTOFF_HI
; break;
2084 case BFD_RELOC_HI16_S_BASEREL
: r
= R_PPC_SECTOFF_HA
; break;
2085 case BFD_RELOC_CTOR
: r
= R_PPC_ADDR32
; break;
2086 case BFD_RELOC_PPC_TOC16
: r
= R_PPC_TOC16
; break;
2087 case BFD_RELOC_PPC_TLS
: r
= R_PPC_TLS
; break;
2088 case BFD_RELOC_PPC_DTPMOD
: r
= R_PPC_DTPMOD32
; break;
2089 case BFD_RELOC_PPC_TPREL16
: r
= R_PPC_TPREL16
; break;
2090 case BFD_RELOC_PPC_TPREL16_LO
: r
= R_PPC_TPREL16_LO
; break;
2091 case BFD_RELOC_PPC_TPREL16_HI
: r
= R_PPC_TPREL16_HI
; break;
2092 case BFD_RELOC_PPC_TPREL16_HA
: r
= R_PPC_TPREL16_HA
; break;
2093 case BFD_RELOC_PPC_TPREL
: r
= R_PPC_TPREL32
; break;
2094 case BFD_RELOC_PPC_DTPREL16
: r
= R_PPC_DTPREL16
; break;
2095 case BFD_RELOC_PPC_DTPREL16_LO
: r
= R_PPC_DTPREL16_LO
; break;
2096 case BFD_RELOC_PPC_DTPREL16_HI
: r
= R_PPC_DTPREL16_HI
; break;
2097 case BFD_RELOC_PPC_DTPREL16_HA
: r
= R_PPC_DTPREL16_HA
; break;
2098 case BFD_RELOC_PPC_DTPREL
: r
= R_PPC_DTPREL32
; break;
2099 case BFD_RELOC_PPC_GOT_TLSGD16
: r
= R_PPC_GOT_TLSGD16
; break;
2100 case BFD_RELOC_PPC_GOT_TLSGD16_LO
: r
= R_PPC_GOT_TLSGD16_LO
; break;
2101 case BFD_RELOC_PPC_GOT_TLSGD16_HI
: r
= R_PPC_GOT_TLSGD16_HI
; break;
2102 case BFD_RELOC_PPC_GOT_TLSGD16_HA
: r
= R_PPC_GOT_TLSGD16_HA
; break;
2103 case BFD_RELOC_PPC_GOT_TLSLD16
: r
= R_PPC_GOT_TLSLD16
; break;
2104 case BFD_RELOC_PPC_GOT_TLSLD16_LO
: r
= R_PPC_GOT_TLSLD16_LO
; break;
2105 case BFD_RELOC_PPC_GOT_TLSLD16_HI
: r
= R_PPC_GOT_TLSLD16_HI
; break;
2106 case BFD_RELOC_PPC_GOT_TLSLD16_HA
: r
= R_PPC_GOT_TLSLD16_HA
; break;
2107 case BFD_RELOC_PPC_GOT_TPREL16
: r
= R_PPC_GOT_TPREL16
; break;
2108 case BFD_RELOC_PPC_GOT_TPREL16_LO
: r
= R_PPC_GOT_TPREL16_LO
; break;
2109 case BFD_RELOC_PPC_GOT_TPREL16_HI
: r
= R_PPC_GOT_TPREL16_HI
; break;
2110 case BFD_RELOC_PPC_GOT_TPREL16_HA
: r
= R_PPC_GOT_TPREL16_HA
; break;
2111 case BFD_RELOC_PPC_GOT_DTPREL16
: r
= R_PPC_GOT_DTPREL16
; break;
2112 case BFD_RELOC_PPC_GOT_DTPREL16_LO
: r
= R_PPC_GOT_DTPREL16_LO
; break;
2113 case BFD_RELOC_PPC_GOT_DTPREL16_HI
: r
= R_PPC_GOT_DTPREL16_HI
; break;
2114 case BFD_RELOC_PPC_GOT_DTPREL16_HA
: r
= R_PPC_GOT_DTPREL16_HA
; break;
2115 case BFD_RELOC_PPC_EMB_NADDR32
: r
= R_PPC_EMB_NADDR32
; break;
2116 case BFD_RELOC_PPC_EMB_NADDR16
: r
= R_PPC_EMB_NADDR16
; break;
2117 case BFD_RELOC_PPC_EMB_NADDR16_LO
: r
= R_PPC_EMB_NADDR16_LO
; break;
2118 case BFD_RELOC_PPC_EMB_NADDR16_HI
: r
= R_PPC_EMB_NADDR16_HI
; break;
2119 case BFD_RELOC_PPC_EMB_NADDR16_HA
: r
= R_PPC_EMB_NADDR16_HA
; break;
2120 case BFD_RELOC_PPC_EMB_SDAI16
: r
= R_PPC_EMB_SDAI16
; break;
2121 case BFD_RELOC_PPC_EMB_SDA2I16
: r
= R_PPC_EMB_SDA2I16
; break;
2122 case BFD_RELOC_PPC_EMB_SDA2REL
: r
= R_PPC_EMB_SDA2REL
; break;
2123 case BFD_RELOC_PPC_EMB_SDA21
: r
= R_PPC_EMB_SDA21
; break;
2124 case BFD_RELOC_PPC_EMB_MRKREF
: r
= R_PPC_EMB_MRKREF
; break;
2125 case BFD_RELOC_PPC_EMB_RELSEC16
: r
= R_PPC_EMB_RELSEC16
; break;
2126 case BFD_RELOC_PPC_EMB_RELST_LO
: r
= R_PPC_EMB_RELST_LO
; break;
2127 case BFD_RELOC_PPC_EMB_RELST_HI
: r
= R_PPC_EMB_RELST_HI
; break;
2128 case BFD_RELOC_PPC_EMB_RELST_HA
: r
= R_PPC_EMB_RELST_HA
; break;
2129 case BFD_RELOC_PPC_EMB_BIT_FLD
: r
= R_PPC_EMB_BIT_FLD
; break;
2130 case BFD_RELOC_PPC_EMB_RELSDA
: r
= R_PPC_EMB_RELSDA
; break;
2131 case BFD_RELOC_VTABLE_INHERIT
: r
= R_PPC_GNU_VTINHERIT
; break;
2132 case BFD_RELOC_VTABLE_ENTRY
: r
= R_PPC_GNU_VTENTRY
; break;
2135 return ppc_elf_howto_table
[r
];
2138 /* Set the howto pointer for a PowerPC ELF reloc. */
2141 ppc_elf_info_to_howto (bfd
*abfd ATTRIBUTE_UNUSED
,
2143 Elf_Internal_Rela
*dst
)
2145 /* Initialize howto table if not already done. */
2146 if (!ppc_elf_howto_table
[R_PPC_ADDR32
])
2147 ppc_elf_howto_init ();
2149 BFD_ASSERT (ELF32_R_TYPE (dst
->r_info
) < (unsigned int) R_PPC_max
);
2150 cache_ptr
->howto
= ppc_elf_howto_table
[ELF32_R_TYPE (dst
->r_info
)];
2153 /* Handle the R_PPC_ADDR16_HA reloc. */
2155 static bfd_reloc_status_type
2156 ppc_elf_addr16_ha_reloc (bfd
*abfd ATTRIBUTE_UNUSED
,
2157 arelent
*reloc_entry
,
2159 void *data ATTRIBUTE_UNUSED
,
2160 asection
*input_section
,
2162 char **error_message ATTRIBUTE_UNUSED
)
2166 if (output_bfd
!= NULL
)
2168 reloc_entry
->address
+= input_section
->output_offset
;
2169 return bfd_reloc_ok
;
2172 if (reloc_entry
->address
> input_section
->_cooked_size
)
2173 return bfd_reloc_outofrange
;
2175 if (bfd_is_com_section (symbol
->section
))
2178 relocation
= symbol
->value
;
2180 relocation
+= symbol
->section
->output_section
->vma
;
2181 relocation
+= symbol
->section
->output_offset
;
2182 relocation
+= reloc_entry
->addend
;
2184 reloc_entry
->addend
+= (relocation
& 0x8000) << 1;
2186 return bfd_reloc_continue
;
2189 static bfd_reloc_status_type
2190 ppc_elf_unhandled_reloc (bfd
*abfd
,
2191 arelent
*reloc_entry
,
2194 asection
*input_section
,
2196 char **error_message
)
2198 /* If this is a relocatable link (output_bfd test tells us), just
2199 call the generic function. Any adjustment will be done at final
2201 if (output_bfd
!= NULL
)
2202 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2203 input_section
, output_bfd
, error_message
);
2205 if (error_message
!= NULL
)
2207 static char buf
[60];
2208 sprintf (buf
, _("generic linker can't handle %s"),
2209 reloc_entry
->howto
->name
);
2210 *error_message
= buf
;
2212 return bfd_reloc_dangerous
;
2215 /* Fix bad default arch selected for a 32 bit input bfd when the
2216 default is 64 bit. */
2219 ppc_elf_object_p (bfd
*abfd
)
2221 if (abfd
->arch_info
->the_default
&& abfd
->arch_info
->bits_per_word
== 64)
2223 Elf_Internal_Ehdr
*i_ehdr
= elf_elfheader (abfd
);
2225 if (i_ehdr
->e_ident
[EI_CLASS
] == ELFCLASS32
)
2227 /* Relies on arch after 64 bit default being 32 bit default. */
2228 abfd
->arch_info
= abfd
->arch_info
->next
;
2229 BFD_ASSERT (abfd
->arch_info
->bits_per_word
== 32);
2235 /* Function to set whether a module needs the -mrelocatable bit set. */
2238 ppc_elf_set_private_flags (bfd
*abfd
, flagword flags
)
2240 BFD_ASSERT (!elf_flags_init (abfd
)
2241 || elf_elfheader (abfd
)->e_flags
== flags
);
2243 elf_elfheader (abfd
)->e_flags
= flags
;
2244 elf_flags_init (abfd
) = TRUE
;
2248 /* Merge backend specific data from an object file to the output
2249 object file when linking. */
2252 ppc_elf_merge_private_bfd_data (bfd
*ibfd
, bfd
*obfd
)
2258 /* Check if we have the same endianess. */
2259 if (! _bfd_generic_verify_endian_match (ibfd
, obfd
))
2262 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
2263 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
2266 new_flags
= elf_elfheader (ibfd
)->e_flags
;
2267 old_flags
= elf_elfheader (obfd
)->e_flags
;
2268 if (!elf_flags_init (obfd
))
2270 /* First call, no flags set. */
2271 elf_flags_init (obfd
) = TRUE
;
2272 elf_elfheader (obfd
)->e_flags
= new_flags
;
2275 /* Compatible flags are ok. */
2276 else if (new_flags
== old_flags
)
2279 /* Incompatible flags. */
2282 /* Warn about -mrelocatable mismatch. Allow -mrelocatable-lib
2283 to be linked with either. */
2285 if ((new_flags
& EF_PPC_RELOCATABLE
) != 0
2286 && (old_flags
& (EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
)) == 0)
2289 (*_bfd_error_handler
)
2290 (_("%s: compiled with -mrelocatable and linked with "
2291 "modules compiled normally"),
2292 bfd_archive_filename (ibfd
));
2294 else if ((new_flags
& (EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
)) == 0
2295 && (old_flags
& EF_PPC_RELOCATABLE
) != 0)
2298 (*_bfd_error_handler
)
2299 (_("%s: compiled normally and linked with "
2300 "modules compiled with -mrelocatable"),
2301 bfd_archive_filename (ibfd
));
2304 /* The output is -mrelocatable-lib iff both the input files are. */
2305 if (! (new_flags
& EF_PPC_RELOCATABLE_LIB
))
2306 elf_elfheader (obfd
)->e_flags
&= ~EF_PPC_RELOCATABLE_LIB
;
2308 /* The output is -mrelocatable iff it can't be -mrelocatable-lib,
2309 but each input file is either -mrelocatable or -mrelocatable-lib. */
2310 if (! (elf_elfheader (obfd
)->e_flags
& EF_PPC_RELOCATABLE_LIB
)
2311 && (new_flags
& (EF_PPC_RELOCATABLE_LIB
| EF_PPC_RELOCATABLE
))
2312 && (old_flags
& (EF_PPC_RELOCATABLE_LIB
| EF_PPC_RELOCATABLE
)))
2313 elf_elfheader (obfd
)->e_flags
|= EF_PPC_RELOCATABLE
;
2315 /* Do not warn about eabi vs. V.4 mismatch, just or in the bit if
2316 any module uses it. */
2317 elf_elfheader (obfd
)->e_flags
|= (new_flags
& EF_PPC_EMB
);
2319 new_flags
&= ~(EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
| EF_PPC_EMB
);
2320 old_flags
&= ~(EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
| EF_PPC_EMB
);
2322 /* Warn about any other mismatches. */
2323 if (new_flags
!= old_flags
)
2326 (*_bfd_error_handler
)
2327 (_("%s: uses different e_flags (0x%lx) fields "
2328 "than previous modules (0x%lx)"),
2329 bfd_archive_filename (ibfd
), (long) new_flags
, (long) old_flags
);
2334 bfd_set_error (bfd_error_bad_value
);
2342 /* Handle a PowerPC specific section when reading an object file. This
2343 is called when elfcode.h finds a section with an unknown type. */
2346 ppc_elf_section_from_shdr (bfd
*abfd
, Elf_Internal_Shdr
*hdr
, const char *name
)
2351 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
))
2354 newsect
= hdr
->bfd_section
;
2355 flags
= bfd_get_section_flags (abfd
, newsect
);
2356 if (hdr
->sh_flags
& SHF_EXCLUDE
)
2357 flags
|= SEC_EXCLUDE
;
2359 if (hdr
->sh_type
== SHT_ORDERED
)
2360 flags
|= SEC_SORT_ENTRIES
;
2362 bfd_set_section_flags (abfd
, newsect
, flags
);
2366 /* Set up any other section flags and such that may be necessary. */
2369 ppc_elf_fake_sections (bfd
*abfd ATTRIBUTE_UNUSED
,
2370 Elf_Internal_Shdr
*shdr
,
2373 if ((asect
->flags
& SEC_EXCLUDE
) != 0)
2374 shdr
->sh_flags
|= SHF_EXCLUDE
;
2376 if ((asect
->flags
& SEC_SORT_ENTRIES
) != 0)
2377 shdr
->sh_type
= SHT_ORDERED
;
2382 /* Find a linker generated pointer with a given addend and type. */
2384 static elf_linker_section_pointers_t
*
2385 elf_find_pointer_linker_section
2386 (elf_linker_section_pointers_t
*linker_pointers
,
2388 elf_linker_section_t
*lsect
)
2390 for ( ; linker_pointers
!= NULL
; linker_pointers
= linker_pointers
->next
)
2391 if (lsect
== linker_pointers
->lsect
&& addend
== linker_pointers
->addend
)
2392 return linker_pointers
;
2397 /* Allocate a pointer to live in a linker created section. */
2400 elf_create_pointer_linker_section (bfd
*abfd
,
2401 struct bfd_link_info
*info
,
2402 elf_linker_section_t
*lsect
,
2403 struct elf_link_hash_entry
*h
,
2404 const Elf_Internal_Rela
*rel
)
2406 elf_linker_section_pointers_t
**ptr_linker_section_ptr
= NULL
;
2407 elf_linker_section_pointers_t
*linker_section_ptr
;
2408 unsigned long r_symndx
= ELF32_R_SYM (rel
->r_info
);
2411 BFD_ASSERT (lsect
!= NULL
);
2413 /* Is this a global symbol? */
2416 struct ppc_elf_link_hash_entry
*eh
;
2418 /* Has this symbol already been allocated? If so, our work is done. */
2419 eh
= (struct ppc_elf_link_hash_entry
*) h
;
2420 if (elf_find_pointer_linker_section (eh
->linker_section_pointer
,
2425 ptr_linker_section_ptr
= &eh
->linker_section_pointer
;
2426 /* Make sure this symbol is output as a dynamic symbol. */
2427 if (h
->dynindx
== -1)
2429 if (! _bfd_elf_link_record_dynamic_symbol (info
, h
))
2433 if (lsect
->rel_section
)
2434 lsect
->rel_section
->_raw_size
+= sizeof (Elf32_External_Rela
);
2438 /* Allocation of a pointer to a local symbol. */
2439 elf_linker_section_pointers_t
**ptr
= elf_local_ptr_offsets (abfd
);
2441 /* Allocate a table to hold the local symbols if first time. */
2444 unsigned int num_symbols
= elf_tdata (abfd
)->symtab_hdr
.sh_info
;
2447 amt
*= sizeof (elf_linker_section_pointers_t
*);
2448 ptr
= bfd_zalloc (abfd
, amt
);
2453 elf_local_ptr_offsets (abfd
) = ptr
;
2456 /* Has this symbol already been allocated? If so, our work is done. */
2457 if (elf_find_pointer_linker_section (ptr
[r_symndx
],
2462 ptr_linker_section_ptr
= &ptr
[r_symndx
];
2466 /* If we are generating a shared object, we need to
2467 output a R_<xxx>_RELATIVE reloc so that the
2468 dynamic linker can adjust this GOT entry. */
2469 BFD_ASSERT (lsect
->rel_section
!= NULL
);
2470 lsect
->rel_section
->_raw_size
+= sizeof (Elf32_External_Rela
);
2474 /* Allocate space for a pointer in the linker section, and allocate
2475 a new pointer record from internal memory. */
2476 BFD_ASSERT (ptr_linker_section_ptr
!= NULL
);
2477 amt
= sizeof (elf_linker_section_pointers_t
);
2478 linker_section_ptr
= bfd_alloc (abfd
, amt
);
2480 if (!linker_section_ptr
)
2483 linker_section_ptr
->next
= *ptr_linker_section_ptr
;
2484 linker_section_ptr
->addend
= rel
->r_addend
;
2485 linker_section_ptr
->lsect
= lsect
;
2486 linker_section_ptr
->written_address_p
= FALSE
;
2487 *ptr_linker_section_ptr
= linker_section_ptr
;
2489 linker_section_ptr
->offset
= lsect
->section
->_raw_size
;
2490 lsect
->section
->_raw_size
+= 4;
2494 "Create pointer in linker section %s, offset = %ld, section size = %ld\n",
2495 lsect
->name
, (long) linker_section_ptr
->offset
,
2496 (long) lsect
->section
->_raw_size
);
2502 #define bfd_put_ptr(BFD, VAL, ADDR) bfd_put_32 (BFD, VAL, ADDR)
2504 /* Fill in the address for a pointer generated in a linker section. */
2507 elf_finish_pointer_linker_section (bfd
*output_bfd
,
2509 struct bfd_link_info
*info
,
2510 elf_linker_section_t
*lsect
,
2511 struct elf_link_hash_entry
*h
,
2513 const Elf_Internal_Rela
*rel
,
2516 elf_linker_section_pointers_t
*linker_section_ptr
;
2518 BFD_ASSERT (lsect
!= NULL
);
2522 /* Handle global symbol. */
2523 struct ppc_elf_link_hash_entry
*eh
;
2525 eh
= (struct ppc_elf_link_hash_entry
*) h
;
2527 = elf_find_pointer_linker_section (eh
->linker_section_pointer
,
2531 BFD_ASSERT (linker_section_ptr
!= NULL
);
2533 if (! elf_hash_table (info
)->dynamic_sections_created
2536 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
)))
2538 /* This is actually a static link, or it is a
2539 -Bsymbolic link and the symbol is defined
2540 locally. We must initialize this entry in the
2543 When doing a dynamic link, we create a .rela.<xxx>
2544 relocation entry to initialize the value. This
2545 is done in the finish_dynamic_symbol routine. */
2546 if (!linker_section_ptr
->written_address_p
)
2548 linker_section_ptr
->written_address_p
= TRUE
;
2549 bfd_put_ptr (output_bfd
,
2550 relocation
+ linker_section_ptr
->addend
,
2551 (lsect
->section
->contents
2552 + linker_section_ptr
->offset
));
2558 /* Handle local symbol. */
2559 unsigned long r_symndx
= ELF32_R_SYM (rel
->r_info
);
2560 BFD_ASSERT (elf_local_ptr_offsets (input_bfd
) != NULL
);
2561 BFD_ASSERT (elf_local_ptr_offsets (input_bfd
)[r_symndx
] != NULL
);
2562 linker_section_ptr
= (elf_find_pointer_linker_section
2563 (elf_local_ptr_offsets (input_bfd
)[r_symndx
],
2567 BFD_ASSERT (linker_section_ptr
!= NULL
);
2569 /* Write out pointer if it hasn't been rewritten out before. */
2570 if (!linker_section_ptr
->written_address_p
)
2572 linker_section_ptr
->written_address_p
= TRUE
;
2573 bfd_put_ptr (output_bfd
, relocation
+ linker_section_ptr
->addend
,
2574 lsect
->section
->contents
+ linker_section_ptr
->offset
);
2578 /* We need to generate a relative reloc for the dynamic
2581 asection
*srel
= lsect
->rel_section
;
2582 Elf_Internal_Rela outrel
[MAX_INT_RELS_PER_EXT_REL
];
2584 const struct elf_backend_data
*bed
;
2587 BFD_ASSERT (srel
!= NULL
);
2589 bed
= get_elf_backend_data (output_bfd
);
2590 for (i
= 0; i
< bed
->s
->int_rels_per_ext_rel
; i
++)
2592 outrel
[i
].r_offset
= (lsect
->section
->output_section
->vma
2593 + lsect
->section
->output_offset
2594 + linker_section_ptr
->offset
);
2595 outrel
[i
].r_info
= 0;
2596 outrel
[i
].r_addend
= 0;
2598 outrel
[0].r_info
= ELF32_R_INFO (0, relative_reloc
);
2599 erel
= lsect
->section
->contents
;
2600 erel
+= (elf_section_data (lsect
->section
)->rel_count
++
2601 * sizeof (Elf32_External_Rela
));
2602 bfd_elf32_swap_reloca_out (output_bfd
, outrel
, erel
);
2607 relocation
= (lsect
->section
->output_offset
2608 + linker_section_ptr
->offset
2609 - lsect
->sym_offset
);
2613 "Finish pointer in linker section %s, offset = %ld (0x%lx)\n",
2614 lsect
->name
, (long) relocation
, (long) relocation
);
2617 /* Subtract out the addend, because it will get added back in by the normal
2619 return relocation
- linker_section_ptr
->addend
;
2622 /* Create a special linker section */
2623 static elf_linker_section_t
*
2624 ppc_elf_create_linker_section (bfd
*abfd
,
2625 struct bfd_link_info
*info
,
2626 enum elf_linker_section_enum which
)
2628 elf_linker_section_t
*lsect
;
2629 struct ppc_elf_link_hash_table
*htab
= ppc_elf_hash_table (info
);
2634 const char *rel_name
;
2635 const char *sym_name
;
2638 /* Both of these sections are (technically) created by the user
2639 putting data in them, so they shouldn't be marked
2642 The linker creates them so it has somewhere to attach their
2643 respective symbols. In fact, if they were empty it would
2644 be OK to leave the symbol set to 0 (or any random number), because
2645 the appropriate register should never be used. */
2646 flags
= SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
;
2655 case LINKER_SECTION_SDATA
: /* .sdata/.sbss section */
2657 rel_name
= ".rela.sdata";
2658 sym_name
= "_SDA_BASE_";
2661 case LINKER_SECTION_SDATA2
: /* .sdata2/.sbss2 section */
2663 rel_name
= ".rela.sdata2";
2664 sym_name
= "_SDA2_BASE_";
2665 flags
|= SEC_READONLY
;
2669 /* Record the first bfd that needs the special sections. */
2670 if (!htab
->elf
.dynobj
)
2671 htab
->elf
.dynobj
= abfd
;
2673 amt
= sizeof (elf_linker_section_t
);
2674 lsect
= bfd_zalloc (htab
->elf
.dynobj
, amt
);
2676 lsect
->sym_offset
= sym_offset
;
2678 /* See if the sections already exist. */
2679 s
= bfd_get_section_by_name (htab
->elf
.dynobj
, name
);
2680 if (s
== NULL
|| (s
->flags
& flags
) != flags
)
2682 s
= bfd_make_section_anyway (htab
->elf
.dynobj
, name
);
2684 || !bfd_set_section_flags (htab
->elf
.dynobj
, s
, flags
))
2689 if (bfd_get_section_alignment (htab
->elf
.dynobj
, s
) < 2
2690 && !bfd_set_section_alignment (htab
->elf
.dynobj
, s
, 2))
2693 s
->_raw_size
= align_power (s
->_raw_size
, 2);
2696 fprintf (stderr
, "Creating section %s, current size = %ld\n",
2697 name
, (long) s
->_raw_size
);
2702 struct elf_link_hash_entry
*h
;
2703 struct bfd_link_hash_entry
*bh
;
2706 fprintf (stderr
, "Adding %s to section %s\n", sym_name
, name
);
2708 bh
= bfd_link_hash_lookup (info
->hash
, sym_name
,
2709 FALSE
, FALSE
, FALSE
);
2711 if ((bh
== NULL
|| bh
->type
== bfd_link_hash_undefined
)
2712 && !(_bfd_generic_link_add_one_symbol
2713 (info
, abfd
, sym_name
, BSF_GLOBAL
, s
, sym_offset
, NULL
,
2714 FALSE
, get_elf_backend_data (abfd
)->collect
, &bh
)))
2716 h
= (struct elf_link_hash_entry
*) bh
;
2718 h
->type
= STT_OBJECT
;
2719 lsect
->sym_hash
= h
;
2722 && ! _bfd_elf_link_record_dynamic_symbol (info
, h
))
2728 s
= bfd_make_section_anyway (htab
->elf
.dynobj
, rel_name
);
2729 lsect
->rel_section
= s
;
2730 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
2731 | SEC_LINKER_CREATED
| SEC_READONLY
);
2733 || ! bfd_set_section_flags (htab
->elf
.dynobj
, s
, flags
)
2734 || ! bfd_set_section_alignment (htab
->elf
.dynobj
, s
, 2))
2741 /* If we have a non-zero sized .sbss2 or .PPC.EMB.sbss0 sections, we
2742 need to bump up the number of section headers. */
2745 ppc_elf_additional_program_headers (bfd
*abfd
)
2752 s
= bfd_get_section_by_name (abfd
, ".interp");
2756 s
= bfd_get_section_by_name (abfd
, ".sbss2");
2757 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0 && s
->_raw_size
> 0)
2760 s
= bfd_get_section_by_name (abfd
, ".PPC.EMB.sbss0");
2761 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0 && s
->_raw_size
> 0)
2767 /* Modify the segment map if needed. */
2770 ppc_elf_modify_segment_map (bfd
*abfd ATTRIBUTE_UNUSED
)
2775 /* The powerpc .got has a blrl instruction in it. Mark it executable. */
2778 ppc_elf_create_got (bfd
*abfd
, struct bfd_link_info
*info
)
2780 struct ppc_elf_link_hash_table
*htab
;
2784 if (!_bfd_elf_create_got_section (abfd
, info
))
2787 htab
= ppc_elf_hash_table (info
);
2788 htab
->got
= s
= bfd_get_section_by_name (abfd
, ".got");
2792 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_CODE
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
2793 | SEC_LINKER_CREATED
);
2794 if (!bfd_set_section_flags (abfd
, s
, flags
))
2797 htab
->relgot
= bfd_make_section (abfd
, ".rela.got");
2799 || ! bfd_set_section_flags (abfd
, htab
->relgot
,
2800 (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
2801 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
2803 || ! bfd_set_section_alignment (abfd
, htab
->relgot
, 2))
2809 /* We have to create .dynsbss and .rela.sbss here so that they get mapped
2810 to output sections (just like _bfd_elf_create_dynamic_sections has
2811 to create .dynbss and .rela.bss). */
2814 ppc_elf_create_dynamic_sections (bfd
*abfd
, struct bfd_link_info
*info
)
2816 struct ppc_elf_link_hash_table
*htab
;
2820 htab
= ppc_elf_hash_table (info
);
2822 if (htab
->got
== NULL
2823 && !ppc_elf_create_got (abfd
, info
))
2826 if (!_bfd_elf_create_dynamic_sections (abfd
, info
))
2829 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
2830 | SEC_LINKER_CREATED
);
2832 htab
->dynbss
= bfd_get_section_by_name (abfd
, ".dynbss");
2833 htab
->dynsbss
= s
= bfd_make_section (abfd
, ".dynsbss");
2835 || ! bfd_set_section_flags (abfd
, s
, SEC_ALLOC
))
2840 htab
->relbss
= bfd_get_section_by_name (abfd
, ".rela.bss");
2841 htab
->relsbss
= s
= bfd_make_section (abfd
, ".rela.sbss");
2843 || ! bfd_set_section_flags (abfd
, s
, flags
| SEC_READONLY
)
2844 || ! bfd_set_section_alignment (abfd
, s
, 2))
2848 htab
->relplt
= bfd_get_section_by_name (abfd
, ".rela.plt");
2849 htab
->plt
= s
= bfd_get_section_by_name (abfd
, ".plt");
2853 flags
= SEC_ALLOC
| SEC_CODE
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
;
2854 return bfd_set_section_flags (abfd
, s
, flags
);
2857 /* Adjust a symbol defined by a dynamic object and referenced by a
2858 regular object. The current definition is in some section of the
2859 dynamic object, but we're not including those sections. We have to
2860 change the definition to something the rest of the link can
2864 ppc_elf_adjust_dynamic_symbol (struct bfd_link_info
*info
,
2865 struct elf_link_hash_entry
*h
)
2867 struct ppc_elf_link_hash_table
*htab
;
2869 unsigned int power_of_two
;
2872 fprintf (stderr
, "ppc_elf_adjust_dynamic_symbol called for %s\n",
2873 h
->root
.root
.string
);
2876 /* Make sure we know what is going on here. */
2877 htab
= ppc_elf_hash_table (info
);
2878 BFD_ASSERT (htab
->elf
.dynobj
!= NULL
2879 && ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
)
2880 || h
->weakdef
!= NULL
2881 || ((h
->elf_link_hash_flags
2882 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0
2883 && (h
->elf_link_hash_flags
2884 & ELF_LINK_HASH_REF_REGULAR
) != 0
2885 && (h
->elf_link_hash_flags
2886 & ELF_LINK_HASH_DEF_REGULAR
) == 0)));
2888 /* Deal with function syms. */
2889 if (h
->type
== STT_FUNC
2890 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
2892 /* Clear procedure linkage table information for any symbol that
2893 won't need a .plt entry. */
2894 if (h
->plt
.refcount
<= 0
2895 || SYMBOL_CALLS_LOCAL (info
, h
)
2896 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
2897 && h
->root
.type
== bfd_link_hash_undefweak
))
2899 /* A PLT entry is not required/allowed when:
2901 1. We are not using ld.so; because then the PLT entry
2902 can't be set up, so we can't use one. In this case,
2903 ppc_elf_adjust_dynamic_symbol won't even be called.
2905 2. GC has rendered the entry unused.
2907 3. We know for certain that a call to this symbol
2908 will go to this object, or will remain undefined. */
2909 h
->plt
.offset
= (bfd_vma
) -1;
2910 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
2915 h
->plt
.offset
= (bfd_vma
) -1;
2917 /* If this is a weak symbol, and there is a real definition, the
2918 processor independent code will have arranged for us to see the
2919 real definition first, and we can just use the same value. */
2920 if (h
->weakdef
!= NULL
)
2922 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
2923 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
2924 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
2925 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
2926 if (ELIMINATE_COPY_RELOCS
)
2927 h
->elf_link_hash_flags
2928 = ((h
->elf_link_hash_flags
& ~ELF_LINK_NON_GOT_REF
)
2929 | (h
->weakdef
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
));
2933 /* This is a reference to a symbol defined by a dynamic object which
2934 is not a function. */
2936 /* If we are creating a shared library, we must presume that the
2937 only references to the symbol are via the global offset table.
2938 For such cases we need not do anything here; the relocations will
2939 be handled correctly by relocate_section. */
2943 /* If there are no references to this symbol that do not use the
2944 GOT, we don't need to generate a copy reloc. */
2945 if ((h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0)
2948 if (ELIMINATE_COPY_RELOCS
)
2950 struct ppc_elf_dyn_relocs
*p
;
2951 for (p
= ppc_elf_hash_entry (h
)->dyn_relocs
; p
!= NULL
; p
= p
->next
)
2953 s
= p
->sec
->output_section
;
2954 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
2958 /* If we didn't find any dynamic relocs in read-only sections, then
2959 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
2962 h
->elf_link_hash_flags
&= ~ELF_LINK_NON_GOT_REF
;
2967 /* We must allocate the symbol in our .dynbss section, which will
2968 become part of the .bss section of the executable. There will be
2969 an entry for this symbol in the .dynsym section. The dynamic
2970 object will contain position independent code, so all references
2971 from the dynamic object to this symbol will go through the global
2972 offset table. The dynamic linker will use the .dynsym entry to
2973 determine the address it must put in the global offset table, so
2974 both the dynamic object and the regular object will refer to the
2975 same memory location for the variable.
2977 Of course, if the symbol is sufficiently small, we must instead
2978 allocate it in .sbss. FIXME: It would be better to do this if and
2979 only if there were actually SDAREL relocs for that symbol. */
2981 if (h
->size
<= elf_gp_size (htab
->elf
.dynobj
))
2985 BFD_ASSERT (s
!= NULL
);
2987 /* We must generate a R_PPC_COPY reloc to tell the dynamic linker to
2988 copy the initial value out of the dynamic object and into the
2989 runtime process image. We need to remember the offset into the
2990 .rela.bss section we are going to use. */
2991 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
2995 if (h
->size
<= elf_gp_size (htab
->elf
.dynobj
))
2996 srel
= htab
->relsbss
;
2998 srel
= htab
->relbss
;
2999 BFD_ASSERT (srel
!= NULL
);
3000 srel
->_raw_size
+= sizeof (Elf32_External_Rela
);
3001 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_COPY
;
3004 /* We need to figure out the alignment required for this symbol. I
3005 have no idea how ELF linkers handle this. */
3006 power_of_two
= bfd_log2 (h
->size
);
3007 if (power_of_two
> 4)
3010 /* Apply the required alignment. */
3011 s
->_raw_size
= BFD_ALIGN (s
->_raw_size
,
3012 (bfd_size_type
) (1 << power_of_two
));
3013 if (power_of_two
> bfd_get_section_alignment (htab
->elf
.dynobj
, s
))
3015 if (! bfd_set_section_alignment (htab
->elf
.dynobj
, s
, power_of_two
))
3019 /* Define the symbol as being at this point in the section. */
3020 h
->root
.u
.def
.section
= s
;
3021 h
->root
.u
.def
.value
= s
->_raw_size
;
3023 /* Increment the section size to make room for the symbol. */
3024 s
->_raw_size
+= h
->size
;
3029 /* This is the condition under which finish_dynamic_symbol will be
3030 called from elflink.h. If elflink.h doesn't call our
3031 finish_dynamic_symbol routine, we'll need to do something about
3032 initializing any .plt and .got entries in relocate_section. */
3033 #define WILL_CALL_FINISH_DYNAMIC_SYMBOL(DYN, SHARED, H) \
3036 || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) \
3037 && ((H)->dynindx != -1 \
3038 || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0))
3040 /* Of those relocs that might be copied as dynamic relocs, this macro
3041 selects those that must be copied when linking a shared library,
3042 even when the symbol is local. */
3044 #define MUST_BE_DYN_RELOC(RTYPE) \
3045 ((RTYPE) != R_PPC_REL24 \
3046 && (RTYPE) != R_PPC_REL14 \
3047 && (RTYPE) != R_PPC_REL14_BRTAKEN \
3048 && (RTYPE) != R_PPC_REL14_BRNTAKEN \
3049 && (RTYPE) != R_PPC_REL32)
3051 /* Allocate space in associated reloc sections for dynamic relocs. */
3054 allocate_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
3056 struct bfd_link_info
*info
= inf
;
3057 struct ppc_elf_link_hash_entry
*eh
;
3058 struct ppc_elf_link_hash_table
*htab
;
3059 struct ppc_elf_dyn_relocs
*p
;
3061 if (h
->root
.type
== bfd_link_hash_indirect
)
3064 if (h
->root
.type
== bfd_link_hash_warning
)
3065 /* When warning symbols are created, they **replace** the "real"
3066 entry in the hash table, thus we never get to see the real
3067 symbol in a hash traversal. So look at it now. */
3068 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
3070 htab
= ppc_elf_hash_table (info
);
3071 if (htab
->elf
.dynamic_sections_created
3072 && h
->plt
.refcount
> 0)
3074 /* Make sure this symbol is output as a dynamic symbol. */
3075 if (h
->dynindx
== -1
3076 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
3078 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
3083 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h
))
3085 asection
*s
= htab
->plt
;
3087 /* If this is the first .plt entry, make room for the special
3089 if (s
->_raw_size
== 0)
3090 s
->_raw_size
+= PLT_INITIAL_ENTRY_SIZE
;
3092 /* The PowerPC PLT is actually composed of two parts, the
3093 first part is 2 words (for a load and a jump), and then
3094 there is a remaining word available at the end. */
3095 h
->plt
.offset
= (PLT_INITIAL_ENTRY_SIZE
3097 * ((s
->_raw_size
- PLT_INITIAL_ENTRY_SIZE
)
3098 / PLT_ENTRY_SIZE
)));
3100 /* If this symbol is not defined in a regular file, and we
3101 are not generating a shared library, then set the symbol
3102 to this location in the .plt. This is required to make
3103 function pointers compare as equal between the normal
3104 executable and the shared library. */
3106 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
3108 h
->root
.u
.def
.section
= s
;
3109 h
->root
.u
.def
.value
= h
->plt
.offset
;
3112 /* Make room for this entry. After the 8192nd entry, room
3113 for two entries is allocated. */
3114 s
->_raw_size
+= PLT_ENTRY_SIZE
;
3115 if ((s
->_raw_size
- PLT_INITIAL_ENTRY_SIZE
) / PLT_ENTRY_SIZE
3116 > PLT_NUM_SINGLE_ENTRIES
)
3117 s
->_raw_size
+= PLT_ENTRY_SIZE
;
3119 /* We also need to make an entry in the .rela.plt section. */
3120 htab
->relplt
->_raw_size
+= sizeof (Elf32_External_Rela
);
3124 h
->plt
.offset
= (bfd_vma
) -1;
3125 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
3130 h
->plt
.offset
= (bfd_vma
) -1;
3131 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
3134 eh
= (struct ppc_elf_link_hash_entry
*) h
;
3135 if (eh
->elf
.got
.refcount
> 0)
3137 /* Make sure this symbol is output as a dynamic symbol. */
3138 if (eh
->elf
.dynindx
== -1
3139 && (eh
->elf
.elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
3141 if (!bfd_elf32_link_record_dynamic_symbol (info
, &eh
->elf
))
3145 if (eh
->tls_mask
== (TLS_TLS
| TLS_LD
)
3146 && !(eh
->elf
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
))
3147 /* If just an LD reloc, we'll just use htab->tlsld_got.offset. */
3148 eh
->elf
.got
.offset
= (bfd_vma
) -1;
3152 eh
->elf
.got
.offset
= htab
->got
->_raw_size
;
3153 if ((eh
->tls_mask
& TLS_TLS
) != 0)
3155 if ((eh
->tls_mask
& TLS_LD
) != 0)
3156 htab
->got
->_raw_size
+= 8;
3157 if ((eh
->tls_mask
& TLS_GD
) != 0)
3158 htab
->got
->_raw_size
+= 8;
3159 if ((eh
->tls_mask
& (TLS_TPREL
| TLS_TPRELGD
)) != 0)
3160 htab
->got
->_raw_size
+= 4;
3161 if ((eh
->tls_mask
& TLS_DTPREL
) != 0)
3162 htab
->got
->_raw_size
+= 4;
3165 htab
->got
->_raw_size
+= 4;
3166 dyn
= htab
->elf
.dynamic_sections_created
;
3168 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, &eh
->elf
))
3169 && (ELF_ST_VISIBILITY (eh
->elf
.other
) == STV_DEFAULT
3170 || eh
->elf
.root
.type
!= bfd_link_hash_undefweak
))
3172 /* All the entries we allocated need relocs. */
3173 htab
->relgot
->_raw_size
3174 += ((htab
->got
->_raw_size
- eh
->elf
.got
.offset
) / 4
3175 * sizeof (Elf32_External_Rela
));
3176 /* Except LD only needs one. */
3177 if ((eh
->tls_mask
& TLS_LD
) != 0)
3178 htab
->relgot
->_raw_size
-= sizeof (Elf32_External_Rela
);
3183 eh
->elf
.got
.offset
= (bfd_vma
) -1;
3185 if (eh
->dyn_relocs
== NULL
)
3188 /* In the shared -Bsymbolic case, discard space allocated for
3189 dynamic pc-relative relocs against symbols which turn out to be
3190 defined in regular objects. For the normal shared case, discard
3191 space for relocs that have become local due to symbol visibility
3196 /* Relocs that use pc_count are those that appear on a call insn,
3197 or certain REL relocs (see MUST_BE_DYN_RELOC) that can be
3198 generated via assembly. We want calls to protected symbols to
3199 resolve directly to the function rather than going via the plt.
3200 If people want function pointer comparisons to work as expected
3201 then they should avoid writing weird assembly. */
3202 if (SYMBOL_CALLS_LOCAL (info
, h
))
3204 struct ppc_elf_dyn_relocs
**pp
;
3206 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
3208 p
->count
-= p
->pc_count
;
3217 /* Also discard relocs on undefined weak syms with non-default
3219 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
3220 && h
->root
.type
== bfd_link_hash_undefweak
)
3221 eh
->dyn_relocs
= NULL
;
3223 else if (ELIMINATE_COPY_RELOCS
)
3225 /* For the non-shared case, discard space for relocs against
3226 symbols which turn out to need copy relocs or are not
3229 if ((h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0
3230 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
3231 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
3233 /* Make sure this symbol is output as a dynamic symbol.
3234 Undefined weak syms won't yet be marked as dynamic. */
3235 if (h
->dynindx
== -1
3236 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
3238 if (! bfd_elf64_link_record_dynamic_symbol (info
, h
))
3242 /* If that succeeded, we know we'll be keeping all the
3244 if (h
->dynindx
!= -1)
3248 eh
->dyn_relocs
= NULL
;
3253 /* Finally, allocate space. */
3254 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
3256 asection
*sreloc
= elf_section_data (p
->sec
)->sreloc
;
3257 sreloc
->_raw_size
+= p
->count
* sizeof (Elf32_External_Rela
);
3263 /* Find any dynamic relocs that apply to read-only sections. */
3266 readonly_dynrelocs (struct elf_link_hash_entry
*h
, void *info
)
3268 struct ppc_elf_dyn_relocs
*p
;
3270 if (h
->root
.type
== bfd_link_hash_indirect
)
3273 if (h
->root
.type
== bfd_link_hash_warning
)
3274 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
3276 for (p
= ppc_elf_hash_entry (h
)->dyn_relocs
; p
!= NULL
; p
= p
->next
)
3278 asection
*s
= p
->sec
->output_section
;
3281 && ((s
->flags
& (SEC_READONLY
| SEC_ALLOC
))
3282 == (SEC_READONLY
| SEC_ALLOC
)))
3284 ((struct bfd_link_info
*) info
)->flags
|= DF_TEXTREL
;
3286 /* Not an error, just cut short the traversal. */
3293 /* Set the sizes of the dynamic sections. */
3296 ppc_elf_size_dynamic_sections (bfd
*output_bfd ATTRIBUTE_UNUSED
,
3297 struct bfd_link_info
*info
)
3299 struct ppc_elf_link_hash_table
*htab
;
3305 fprintf (stderr
, "ppc_elf_size_dynamic_sections called\n");
3308 htab
= ppc_elf_hash_table (info
);
3309 BFD_ASSERT (htab
->elf
.dynobj
!= NULL
);
3311 if (elf_hash_table (info
)->dynamic_sections_created
)
3313 /* Set the contents of the .interp section to the interpreter. */
3314 if (info
->executable
)
3316 s
= bfd_get_section_by_name (htab
->elf
.dynobj
, ".interp");
3317 BFD_ASSERT (s
!= NULL
);
3318 s
->_raw_size
= sizeof ELF_DYNAMIC_INTERPRETER
;
3319 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
3323 if (htab
->tlsld_got
.refcount
> 0)
3325 htab
->tlsld_got
.offset
= htab
->got
->_raw_size
;
3326 htab
->got
->_raw_size
+= 8;
3328 htab
->relgot
->_raw_size
+= sizeof (Elf32_External_Rela
);
3331 htab
->tlsld_got
.offset
= (bfd_vma
) -1;
3333 /* Set up .got offsets for local syms, and space for local dynamic
3335 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
3337 bfd_signed_vma
*local_got
;
3338 bfd_signed_vma
*end_local_got
;
3340 bfd_size_type locsymcount
;
3341 Elf_Internal_Shdr
*symtab_hdr
;
3344 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
)
3347 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
3349 struct ppc_elf_dyn_relocs
*p
;
3351 for (p
= ((struct ppc_elf_dyn_relocs
*)
3352 elf_section_data (s
)->local_dynrel
);
3356 if (!bfd_is_abs_section (p
->sec
)
3357 && bfd_is_abs_section (p
->sec
->output_section
))
3359 /* Input section has been discarded, either because
3360 it is a copy of a linkonce section or due to
3361 linker script /DISCARD/, so we'll be discarding
3364 else if (p
->count
!= 0)
3366 elf_section_data (p
->sec
)->sreloc
->_raw_size
3367 += p
->count
* sizeof (Elf32_External_Rela
);
3368 if ((p
->sec
->output_section
->flags
3369 & (SEC_READONLY
| SEC_ALLOC
))
3370 == (SEC_READONLY
| SEC_ALLOC
))
3371 info
->flags
|= DF_TEXTREL
;
3376 local_got
= elf_local_got_refcounts (ibfd
);
3380 symtab_hdr
= &elf_tdata (ibfd
)->symtab_hdr
;
3381 locsymcount
= symtab_hdr
->sh_info
;
3382 end_local_got
= local_got
+ locsymcount
;
3383 lgot_masks
= (char *) end_local_got
;
3385 srel
= htab
->relgot
;
3386 for (; local_got
< end_local_got
; ++local_got
, ++lgot_masks
)
3389 if (*lgot_masks
== (TLS_TLS
| TLS_LD
))
3391 /* If just an LD reloc, we'll just use
3392 htab->tlsld_got.offset. */
3393 if (htab
->tlsld_got
.offset
== (bfd_vma
) -1)
3395 htab
->tlsld_got
.offset
= s
->_raw_size
;
3398 srel
->_raw_size
+= sizeof (Elf32_External_Rela
);
3400 *local_got
= (bfd_vma
) -1;
3404 *local_got
= s
->_raw_size
;
3405 if ((*lgot_masks
& TLS_TLS
) != 0)
3407 if ((*lgot_masks
& TLS_GD
) != 0)
3409 if ((*lgot_masks
& (TLS_TPREL
| TLS_TPRELGD
)) != 0)
3411 if ((*lgot_masks
& TLS_DTPREL
) != 0)
3417 srel
->_raw_size
+= ((s
->_raw_size
- *local_got
) / 4
3418 * sizeof (Elf32_External_Rela
));
3422 *local_got
= (bfd_vma
) -1;
3425 /* Allocate space for global sym dynamic relocs. */
3426 elf_link_hash_traverse (elf_hash_table (info
), allocate_dynrelocs
, info
);
3428 /* We've now determined the sizes of the various dynamic sections.
3429 Allocate memory for them. */
3431 for (s
= htab
->elf
.dynobj
->sections
; s
!= NULL
; s
= s
->next
)
3433 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
3438 || (htab
->sdata
!= NULL
&& s
== htab
->sdata
->section
)
3439 || (htab
->sdata2
!= NULL
&& s
== htab
->sdata2
->section
))
3441 /* Strip this section if we don't need it; see the
3444 else if (strncmp (bfd_get_section_name (dynobj
, s
), ".rela", 5) == 0)
3446 if (s
->_raw_size
== 0)
3448 /* If we don't need this section, strip it from the
3449 output file. This is mostly to handle .rela.bss and
3450 .rela.plt. We must create both sections in
3451 create_dynamic_sections, because they must be created
3452 before the linker maps input sections to output
3453 sections. The linker does that before
3454 adjust_dynamic_symbol is called, and it is that
3455 function which decides whether anything needs to go
3456 into these sections. */
3460 /* Remember whether there are any relocation sections. */
3463 /* We use the reloc_count field as a counter if we need
3464 to copy relocs into the output file. */
3470 /* It's not one of our sections, so don't allocate space. */
3474 if (s
->_raw_size
== 0)
3476 _bfd_strip_section_from_output (info
, s
);
3480 /* Allocate memory for the section contents. */
3481 s
->contents
= bfd_zalloc (htab
->elf
.dynobj
, s
->_raw_size
);
3482 if (s
->contents
== NULL
)
3486 if (htab
->elf
.dynamic_sections_created
)
3488 /* Add some entries to the .dynamic section. We fill in the
3489 values later, in ppc_elf_finish_dynamic_sections, but we
3490 must add the entries now so that we get the correct size for
3491 the .dynamic section. The DT_DEBUG entry is filled in by the
3492 dynamic linker and used by the debugger. */
3493 #define add_dynamic_entry(TAG, VAL) \
3494 bfd_elf32_add_dynamic_entry (info, (TAG), (VAL))
3496 if (info
->executable
)
3498 if (!add_dynamic_entry (DT_DEBUG
, 0))
3502 if (htab
->plt
!= NULL
&& htab
->plt
->_raw_size
!= 0)
3504 if (!add_dynamic_entry (DT_PLTGOT
, 0)
3505 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
3506 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
3507 || !add_dynamic_entry (DT_JMPREL
, 0))
3513 if (!add_dynamic_entry (DT_RELA
, 0)
3514 || !add_dynamic_entry (DT_RELASZ
, 0)
3515 || !add_dynamic_entry (DT_RELAENT
, sizeof (Elf32_External_Rela
)))
3519 /* If any dynamic relocs apply to a read-only section, then we
3520 need a DT_TEXTREL entry. */
3521 if ((info
->flags
& DF_TEXTREL
) == 0)
3522 elf_link_hash_traverse (elf_hash_table (info
), readonly_dynrelocs
,
3525 if ((info
->flags
& DF_TEXTREL
) != 0)
3527 if (!add_dynamic_entry (DT_TEXTREL
, 0))
3531 #undef add_dynamic_entry
3537 update_local_sym_info (bfd
*abfd
,
3538 Elf_Internal_Shdr
*symtab_hdr
,
3539 unsigned long r_symndx
,
3542 bfd_signed_vma
*local_got_refcounts
= elf_local_got_refcounts (abfd
);
3543 char *local_got_tls_masks
;
3545 if (local_got_refcounts
== NULL
)
3547 bfd_size_type size
= symtab_hdr
->sh_info
;
3549 size
*= sizeof (*local_got_refcounts
) + sizeof (*local_got_tls_masks
);
3550 local_got_refcounts
= bfd_zalloc (abfd
, size
);
3551 if (local_got_refcounts
== NULL
)
3553 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
3556 local_got_refcounts
[r_symndx
] += 1;
3557 local_got_tls_masks
= (char *) (local_got_refcounts
+ symtab_hdr
->sh_info
);
3558 local_got_tls_masks
[r_symndx
] |= tls_type
;
3563 bad_shared_reloc (bfd
*abfd
, enum elf_ppc_reloc_type r_type
)
3565 (*_bfd_error_handler
)
3566 (_("%s: relocation %s cannot be used when making a shared object"),
3567 bfd_archive_filename (abfd
),
3568 ppc_elf_howto_table
[r_type
]->name
);
3569 bfd_set_error (bfd_error_bad_value
);
3572 /* Look through the relocs for a section during the first phase, and
3573 allocate space in the global offset table or procedure linkage
3577 ppc_elf_check_relocs (bfd
*abfd
,
3578 struct bfd_link_info
*info
,
3580 const Elf_Internal_Rela
*relocs
)
3582 struct ppc_elf_link_hash_table
*htab
;
3583 Elf_Internal_Shdr
*symtab_hdr
;
3584 struct elf_link_hash_entry
**sym_hashes
;
3585 const Elf_Internal_Rela
*rel
;
3586 const Elf_Internal_Rela
*rel_end
;
3589 if (info
->relocatable
)
3593 fprintf (stderr
, "ppc_elf_check_relocs called for section %s in %s\n",
3594 bfd_get_section_name (abfd
, sec
),
3595 bfd_archive_filename (abfd
));
3598 /* Initialize howto table if not already done. */
3599 if (!ppc_elf_howto_table
[R_PPC_ADDR32
])
3600 ppc_elf_howto_init ();
3602 /* Create the linker generated sections all the time so that the
3603 special symbols are created. */
3604 htab
= ppc_elf_hash_table (info
);
3605 if (htab
->sdata
== NULL
)
3607 htab
->sdata
= ppc_elf_create_linker_section (abfd
, info
,
3608 LINKER_SECTION_SDATA
);
3609 if (htab
->sdata
== NULL
)
3613 if (htab
->sdata2
== NULL
)
3615 htab
->sdata2
= ppc_elf_create_linker_section (abfd
, info
,
3616 LINKER_SECTION_SDATA2
);
3617 if (htab
->sdata2
== NULL
)
3621 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
3622 sym_hashes
= elf_sym_hashes (abfd
);
3625 rel_end
= relocs
+ sec
->reloc_count
;
3626 for (rel
= relocs
; rel
< rel_end
; rel
++)
3628 unsigned long r_symndx
;
3629 enum elf_ppc_reloc_type r_type
;
3630 struct elf_link_hash_entry
*h
;
3633 r_symndx
= ELF32_R_SYM (rel
->r_info
);
3634 if (r_symndx
< symtab_hdr
->sh_info
)
3637 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
3639 /* If a relocation refers to _GLOBAL_OFFSET_TABLE_, create the .got.
3640 This shows up in particular in an R_PPC_ADDR32 in the eabi
3642 if (h
&& strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
3644 if (htab
->got
== NULL
)
3646 if (htab
->elf
.dynobj
== NULL
)
3647 htab
->elf
.dynobj
= abfd
;
3648 if (!ppc_elf_create_got (htab
->elf
.dynobj
, info
))
3653 r_type
= ELF32_R_TYPE (rel
->r_info
);
3656 case R_PPC_GOT_TLSLD16
:
3657 case R_PPC_GOT_TLSLD16_LO
:
3658 case R_PPC_GOT_TLSLD16_HI
:
3659 case R_PPC_GOT_TLSLD16_HA
:
3660 htab
->tlsld_got
.refcount
+= 1;
3661 tls_type
= TLS_TLS
| TLS_LD
;
3664 case R_PPC_GOT_TLSGD16
:
3665 case R_PPC_GOT_TLSGD16_LO
:
3666 case R_PPC_GOT_TLSGD16_HI
:
3667 case R_PPC_GOT_TLSGD16_HA
:
3668 tls_type
= TLS_TLS
| TLS_GD
;
3671 case R_PPC_GOT_TPREL16
:
3672 case R_PPC_GOT_TPREL16_LO
:
3673 case R_PPC_GOT_TPREL16_HI
:
3674 case R_PPC_GOT_TPREL16_HA
:
3676 info
->flags
|= DF_STATIC_TLS
;
3677 tls_type
= TLS_TLS
| TLS_TPREL
;
3680 case R_PPC_GOT_DTPREL16
:
3681 case R_PPC_GOT_DTPREL16_LO
:
3682 case R_PPC_GOT_DTPREL16_HI
:
3683 case R_PPC_GOT_DTPREL16_HA
:
3684 tls_type
= TLS_TLS
| TLS_DTPREL
;
3686 sec
->has_tls_reloc
= 1;
3689 /* GOT16 relocations */
3691 case R_PPC_GOT16_LO
:
3692 case R_PPC_GOT16_HI
:
3693 case R_PPC_GOT16_HA
:
3694 /* This symbol requires a global offset table entry. */
3695 if (htab
->got
== NULL
)
3697 if (htab
->elf
.dynobj
== NULL
)
3698 htab
->elf
.dynobj
= abfd
;
3699 if (!ppc_elf_create_got (htab
->elf
.dynobj
, info
))
3704 h
->got
.refcount
+= 1;
3705 ppc_elf_hash_entry (h
)->tls_mask
|= tls_type
;
3708 /* This is a global offset table entry for a local symbol. */
3709 if (!update_local_sym_info (abfd
, symtab_hdr
, r_symndx
, tls_type
))
3713 /* Indirect .sdata relocation. */
3714 case R_PPC_EMB_SDAI16
:
3717 bad_shared_reloc (abfd
, r_type
);
3720 if (!elf_create_pointer_linker_section (abfd
, info
,
3721 htab
->sdata
, h
, rel
))
3725 /* Indirect .sdata2 relocation. */
3726 case R_PPC_EMB_SDA2I16
:
3729 bad_shared_reloc (abfd
, r_type
);
3732 if (!elf_create_pointer_linker_section (abfd
, info
,
3733 htab
->sdata2
, h
, rel
))
3737 case R_PPC_SDAREL16
:
3738 case R_PPC_EMB_SDA2REL
:
3739 case R_PPC_EMB_SDA21
:
3740 case R_PPC_EMB_RELSDA
:
3741 case R_PPC_EMB_NADDR32
:
3742 case R_PPC_EMB_NADDR16
:
3743 case R_PPC_EMB_NADDR16_LO
:
3744 case R_PPC_EMB_NADDR16_HI
:
3745 case R_PPC_EMB_NADDR16_HA
:
3748 bad_shared_reloc (abfd
, r_type
);
3754 case R_PPC_PLTREL24
:
3755 case R_PPC_PLTREL32
:
3756 case R_PPC_PLT16_LO
:
3757 case R_PPC_PLT16_HI
:
3758 case R_PPC_PLT16_HA
:
3760 fprintf (stderr
, "Reloc requires a PLT entry\n");
3762 /* This symbol requires a procedure linkage table entry. We
3763 actually build the entry in finish_dynamic_symbol,
3764 because this might be a case of linking PIC code without
3765 linking in any dynamic objects, in which case we don't
3766 need to generate a procedure linkage table after all. */
3770 /* It does not make sense to have a procedure linkage
3771 table entry for a local symbol. */
3772 (*_bfd_error_handler
) (_("%s(%s+0x%lx): %s reloc against "
3774 bfd_archive_filename (abfd
),
3776 (long) rel
->r_offset
,
3777 ppc_elf_howto_table
[r_type
]->name
);
3778 bfd_set_error (bfd_error_bad_value
);
3782 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
3786 /* The following relocations don't need to propagate the
3787 relocation if linking a shared object since they are
3788 section relative. */
3790 case R_PPC_SECTOFF_LO
:
3791 case R_PPC_SECTOFF_HI
:
3792 case R_PPC_SECTOFF_HA
:
3793 case R_PPC_DTPREL16
:
3794 case R_PPC_DTPREL16_LO
:
3795 case R_PPC_DTPREL16_HI
:
3796 case R_PPC_DTPREL16_HA
:
3800 /* This are just markers. */
3802 case R_PPC_EMB_MRKREF
:
3807 /* These should only appear in dynamic objects. */
3809 case R_PPC_GLOB_DAT
:
3810 case R_PPC_JMP_SLOT
:
3811 case R_PPC_RELATIVE
:
3814 /* These aren't handled yet. We'll report an error later. */
3816 case R_PPC_EMB_RELSEC16
:
3817 case R_PPC_EMB_RELST_LO
:
3818 case R_PPC_EMB_RELST_HI
:
3819 case R_PPC_EMB_RELST_HA
:
3820 case R_PPC_EMB_BIT_FLD
:
3823 /* This refers only to functions defined in the shared library. */
3824 case R_PPC_LOCAL24PC
:
3827 /* This relocation describes the C++ object vtable hierarchy.
3828 Reconstruct it for later use during GC. */
3829 case R_PPC_GNU_VTINHERIT
:
3830 if (!_bfd_elf32_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
3834 /* This relocation describes which C++ vtable entries are actually
3835 used. Record for later use during GC. */
3836 case R_PPC_GNU_VTENTRY
:
3837 if (!_bfd_elf32_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
3841 /* We shouldn't really be seeing these. */
3844 info
->flags
|= DF_STATIC_TLS
;
3848 case R_PPC_DTPMOD32
:
3849 case R_PPC_DTPREL32
:
3853 case R_PPC_TPREL16_LO
:
3854 case R_PPC_TPREL16_HI
:
3855 case R_PPC_TPREL16_HA
:
3857 info
->flags
|= DF_STATIC_TLS
;
3860 /* When creating a shared object, we must copy these
3861 relocs into the output file. We create a reloc
3862 section in dynobj and make room for the reloc. */
3865 case R_PPC_REL14_BRTAKEN
:
3866 case R_PPC_REL14_BRNTAKEN
:
3869 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
3876 case R_PPC_ADDR16_LO
:
3877 case R_PPC_ADDR16_HI
:
3878 case R_PPC_ADDR16_HA
:
3880 case R_PPC_ADDR14_BRTAKEN
:
3881 case R_PPC_ADDR14_BRNTAKEN
:
3884 if (h
!= NULL
&& !info
->shared
)
3886 /* We may need a plt entry if the symbol turns out to be
3887 a function defined in a dynamic object. */
3890 /* We may need a copy reloc too. */
3891 h
->elf_link_hash_flags
|= ELF_LINK_NON_GOT_REF
;
3895 /* If we are creating a shared library, and this is a reloc
3896 against a global symbol, or a non PC relative reloc
3897 against a local symbol, then we need to copy the reloc
3898 into the shared library. However, if we are linking with
3899 -Bsymbolic, we do not need to copy a reloc against a
3900 global symbol which is defined in an object we are
3901 including in the link (i.e., DEF_REGULAR is set). At
3902 this point we have not seen all the input files, so it is
3903 possible that DEF_REGULAR is not set now but will be set
3904 later (it is never cleared). In case of a weak definition,
3905 DEF_REGULAR may be cleared later by a strong definition in
3906 a shared library. We account for that possibility below by
3907 storing information in the dyn_relocs field of the hash
3908 table entry. A similar situation occurs when creating
3909 shared libraries and symbol visibility changes render the
3912 If on the other hand, we are creating an executable, we
3913 may need to keep relocations for symbols satisfied by a
3914 dynamic library if we manage to avoid copy relocs for the
3917 && (MUST_BE_DYN_RELOC (r_type
)
3919 && (! info
->symbolic
3920 || h
->root
.type
== bfd_link_hash_defweak
3921 || (h
->elf_link_hash_flags
3922 & ELF_LINK_HASH_DEF_REGULAR
) == 0))))
3923 || (ELIMINATE_COPY_RELOCS
3925 && (sec
->flags
& SEC_ALLOC
) != 0
3927 && (h
->root
.type
== bfd_link_hash_defweak
3928 || (h
->elf_link_hash_flags
3929 & ELF_LINK_HASH_DEF_REGULAR
) == 0)))
3931 struct ppc_elf_dyn_relocs
*p
;
3932 struct ppc_elf_dyn_relocs
**head
;
3936 "ppc_elf_check_relocs needs to "
3937 "create relocation for %s\n",
3938 (h
&& h
->root
.root
.string
3939 ? h
->root
.root
.string
: "<unknown>"));
3945 name
= (bfd_elf_string_from_elf_section
3947 elf_elfheader (abfd
)->e_shstrndx
,
3948 elf_section_data (sec
)->rel_hdr
.sh_name
));
3952 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
3953 && strcmp (bfd_get_section_name (abfd
, sec
),
3956 sreloc
= bfd_get_section_by_name (htab
->elf
.dynobj
, name
);
3961 sreloc
= bfd_make_section (htab
->elf
.dynobj
, name
);
3962 flags
= (SEC_HAS_CONTENTS
| SEC_READONLY
3963 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
3964 if ((sec
->flags
& SEC_ALLOC
) != 0)
3965 flags
|= SEC_ALLOC
| SEC_LOAD
;
3967 || ! bfd_set_section_flags (htab
->elf
.dynobj
,
3969 || ! bfd_set_section_alignment (htab
->elf
.dynobj
,
3973 elf_section_data (sec
)->sreloc
= sreloc
;
3976 /* If this is a global symbol, we count the number of
3977 relocations we need for this symbol. */
3980 head
= &ppc_elf_hash_entry (h
)->dyn_relocs
;
3984 /* Track dynamic relocs needed for local syms too.
3985 We really need local syms available to do this
3989 s
= bfd_section_from_r_symndx (abfd
, &htab
->sym_sec
,
3994 head
= ((struct ppc_elf_dyn_relocs
**)
3995 &elf_section_data (s
)->local_dynrel
);
3999 if (p
== NULL
|| p
->sec
!= sec
)
4001 p
= bfd_alloc (htab
->elf
.dynobj
, sizeof *p
);
4012 if (!MUST_BE_DYN_RELOC (r_type
))
4023 /* Return the section that should be marked against GC for a given
4027 ppc_elf_gc_mark_hook (asection
*sec
,
4028 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
4029 Elf_Internal_Rela
*rel
,
4030 struct elf_link_hash_entry
*h
,
4031 Elf_Internal_Sym
*sym
)
4035 switch (ELF32_R_TYPE (rel
->r_info
))
4037 case R_PPC_GNU_VTINHERIT
:
4038 case R_PPC_GNU_VTENTRY
:
4042 switch (h
->root
.type
)
4044 case bfd_link_hash_defined
:
4045 case bfd_link_hash_defweak
:
4046 return h
->root
.u
.def
.section
;
4048 case bfd_link_hash_common
:
4049 return h
->root
.u
.c
.p
->section
;
4057 return bfd_section_from_elf_index (sec
->owner
, sym
->st_shndx
);
4062 /* Update the got, plt and dynamic reloc reference counts for the
4063 section being removed. */
4066 ppc_elf_gc_sweep_hook (bfd
*abfd
,
4067 struct bfd_link_info
*info
,
4069 const Elf_Internal_Rela
*relocs
)
4071 struct ppc_elf_link_hash_table
*htab
;
4072 Elf_Internal_Shdr
*symtab_hdr
;
4073 struct elf_link_hash_entry
**sym_hashes
;
4074 bfd_signed_vma
*local_got_refcounts
;
4075 const Elf_Internal_Rela
*rel
, *relend
;
4077 elf_section_data (sec
)->local_dynrel
= NULL
;
4079 htab
= ppc_elf_hash_table (info
);
4080 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
4081 sym_hashes
= elf_sym_hashes (abfd
);
4082 local_got_refcounts
= elf_local_got_refcounts (abfd
);
4084 relend
= relocs
+ sec
->reloc_count
;
4085 for (rel
= relocs
; rel
< relend
; rel
++)
4087 unsigned long r_symndx
;
4088 enum elf_ppc_reloc_type r_type
;
4089 struct elf_link_hash_entry
*h
= NULL
;
4091 r_symndx
= ELF32_R_SYM (rel
->r_info
);
4092 if (r_symndx
>= symtab_hdr
->sh_info
)
4094 struct ppc_elf_dyn_relocs
**pp
, *p
;
4095 struct ppc_elf_link_hash_entry
*eh
;
4097 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
4098 eh
= (struct ppc_elf_link_hash_entry
*) h
;
4100 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; pp
= &p
->next
)
4103 /* Everything must go for SEC. */
4109 r_type
= ELF32_R_TYPE (rel
->r_info
);
4112 case R_PPC_GOT_TLSLD16
:
4113 case R_PPC_GOT_TLSLD16_LO
:
4114 case R_PPC_GOT_TLSLD16_HI
:
4115 case R_PPC_GOT_TLSLD16_HA
:
4116 htab
->tlsld_got
.refcount
-= 1;
4119 case R_PPC_GOT_TLSGD16
:
4120 case R_PPC_GOT_TLSGD16_LO
:
4121 case R_PPC_GOT_TLSGD16_HI
:
4122 case R_PPC_GOT_TLSGD16_HA
:
4123 case R_PPC_GOT_TPREL16
:
4124 case R_PPC_GOT_TPREL16_LO
:
4125 case R_PPC_GOT_TPREL16_HI
:
4126 case R_PPC_GOT_TPREL16_HA
:
4127 case R_PPC_GOT_DTPREL16
:
4128 case R_PPC_GOT_DTPREL16_LO
:
4129 case R_PPC_GOT_DTPREL16_HI
:
4130 case R_PPC_GOT_DTPREL16_HA
:
4132 case R_PPC_GOT16_LO
:
4133 case R_PPC_GOT16_HI
:
4134 case R_PPC_GOT16_HA
:
4137 if (h
->got
.refcount
> 0)
4140 else if (local_got_refcounts
!= NULL
)
4142 if (local_got_refcounts
[r_symndx
] > 0)
4143 local_got_refcounts
[r_symndx
]--;
4149 case R_PPC_REL14_BRTAKEN
:
4150 case R_PPC_REL14_BRNTAKEN
:
4153 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
4160 case R_PPC_ADDR16_LO
:
4161 case R_PPC_ADDR16_HI
:
4162 case R_PPC_ADDR16_HA
:
4164 case R_PPC_ADDR14_BRTAKEN
:
4165 case R_PPC_ADDR14_BRNTAKEN
:
4169 case R_PPC_PLTREL24
:
4170 case R_PPC_PLT16_LO
:
4171 case R_PPC_PLT16_HI
:
4172 case R_PPC_PLT16_HA
:
4175 if (h
->plt
.refcount
> 0)
4187 /* Set htab->tls_sec and htab->tls_get_addr. */
4190 ppc_elf_tls_setup (bfd
*obfd
, struct bfd_link_info
*info
)
4193 struct ppc_elf_link_hash_table
*htab
;
4195 htab
= ppc_elf_hash_table (info
);
4196 htab
->tls_get_addr
= elf_link_hash_lookup (&htab
->elf
, "__tls_get_addr",
4197 FALSE
, FALSE
, TRUE
);
4199 for (tls
= obfd
->sections
; tls
!= NULL
; tls
= tls
->next
)
4200 if ((tls
->flags
& (SEC_THREAD_LOCAL
| SEC_LOAD
))
4201 == (SEC_THREAD_LOCAL
| SEC_LOAD
))
4203 htab
->tls_sec
= tls
;
4208 /* Run through all the TLS relocs looking for optimization
4212 ppc_elf_tls_optimize (bfd
*obfd ATTRIBUTE_UNUSED
,
4213 struct bfd_link_info
*info
)
4217 struct ppc_elf_link_hash_table
*htab
;
4219 if (info
->relocatable
|| info
->shared
)
4222 htab
= ppc_elf_hash_table (info
);
4223 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
4225 Elf_Internal_Sym
*locsyms
= NULL
;
4226 Elf_Internal_Shdr
*symtab_hdr
= &elf_tdata (ibfd
)->symtab_hdr
;
4228 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
4229 if (sec
->has_tls_reloc
&& !bfd_is_abs_section (sec
->output_section
))
4231 Elf_Internal_Rela
*relstart
, *rel
, *relend
;
4232 int expecting_tls_get_addr
;
4234 /* Read the relocations. */
4235 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
4237 if (relstart
== NULL
)
4240 expecting_tls_get_addr
= 0;
4241 relend
= relstart
+ sec
->reloc_count
;
4242 for (rel
= relstart
; rel
< relend
; rel
++)
4244 enum elf_ppc_reloc_type r_type
;
4245 unsigned long r_symndx
;
4246 struct elf_link_hash_entry
*h
= NULL
;
4248 char tls_set
, tls_clear
;
4249 bfd_boolean is_local
;
4251 r_symndx
= ELF32_R_SYM (rel
->r_info
);
4252 if (r_symndx
>= symtab_hdr
->sh_info
)
4254 struct elf_link_hash_entry
**sym_hashes
;
4256 sym_hashes
= elf_sym_hashes (ibfd
);
4257 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
4258 while (h
->root
.type
== bfd_link_hash_indirect
4259 || h
->root
.type
== bfd_link_hash_warning
)
4260 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
4265 || !(h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
))
4268 r_type
= ELF32_R_TYPE (rel
->r_info
);
4271 case R_PPC_GOT_TLSLD16
:
4272 case R_PPC_GOT_TLSLD16_LO
:
4273 case R_PPC_GOT_TLSLD16_HI
:
4274 case R_PPC_GOT_TLSLD16_HA
:
4275 /* These relocs should never be against a symbol
4276 defined in a shared lib. Leave them alone if
4277 that turns out to be the case. */
4278 expecting_tls_get_addr
= 0;
4279 htab
->tlsld_got
.refcount
-= 1;
4286 expecting_tls_get_addr
= 1;
4289 case R_PPC_GOT_TLSGD16
:
4290 case R_PPC_GOT_TLSGD16_LO
:
4291 case R_PPC_GOT_TLSGD16_HI
:
4292 case R_PPC_GOT_TLSGD16_HA
:
4298 tls_set
= TLS_TLS
| TLS_TPRELGD
;
4300 expecting_tls_get_addr
= 1;
4303 case R_PPC_GOT_TPREL16
:
4304 case R_PPC_GOT_TPREL16_LO
:
4305 case R_PPC_GOT_TPREL16_HI
:
4306 case R_PPC_GOT_TPREL16_HA
:
4307 expecting_tls_get_addr
= 0;
4312 tls_clear
= TLS_TPREL
;
4319 case R_PPC_REL14_BRTAKEN
:
4320 case R_PPC_REL14_BRNTAKEN
:
4322 if (expecting_tls_get_addr
4324 && h
== htab
->tls_get_addr
)
4326 if (h
->plt
.refcount
> 0)
4327 h
->plt
.refcount
-= 1;
4329 expecting_tls_get_addr
= 0;
4333 expecting_tls_get_addr
= 0;
4341 /* We managed to get rid of a got entry. */
4342 if (h
->got
.refcount
> 0)
4343 h
->got
.refcount
-= 1;
4345 tls_mask
= &ppc_elf_hash_entry (h
)->tls_mask
;
4349 Elf_Internal_Sym
*sym
;
4350 bfd_signed_vma
*lgot_refs
;
4353 if (locsyms
== NULL
)
4355 locsyms
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
4356 if (locsyms
== NULL
)
4357 locsyms
= bfd_elf_get_elf_syms (ibfd
, symtab_hdr
,
4358 symtab_hdr
->sh_info
,
4359 0, NULL
, NULL
, NULL
);
4360 if (locsyms
== NULL
)
4362 if (elf_section_data (sec
)->relocs
!= relstart
)
4367 sym
= locsyms
+ r_symndx
;
4368 lgot_refs
= elf_local_got_refcounts (ibfd
);
4369 if (lgot_refs
== NULL
)
4373 /* We managed to get rid of a got entry. */
4374 if (lgot_refs
[r_symndx
] > 0)
4375 lgot_refs
[r_symndx
] -= 1;
4377 lgot_masks
= (char *) (lgot_refs
+ symtab_hdr
->sh_info
);
4378 tls_mask
= &lgot_masks
[r_symndx
];
4381 *tls_mask
|= tls_set
;
4382 *tls_mask
&= ~tls_clear
;
4385 if (elf_section_data (sec
)->relocs
!= relstart
)
4390 && (symtab_hdr
->contents
!= (unsigned char *) locsyms
))
4392 if (!info
->keep_memory
)
4395 symtab_hdr
->contents
= (unsigned char *) locsyms
;
4401 /* Hook called by the linker routine which adds symbols from an object
4402 file. We use it to put .comm items in .sbss, and not .bss. */
4405 ppc_elf_add_symbol_hook (bfd
*abfd
,
4406 struct bfd_link_info
*info
,
4407 const Elf_Internal_Sym
*sym
,
4408 const char **namep ATTRIBUTE_UNUSED
,
4409 flagword
*flagsp ATTRIBUTE_UNUSED
,
4413 if (sym
->st_shndx
== SHN_COMMON
4414 && !info
->relocatable
4415 && sym
->st_size
<= elf_gp_size (abfd
)
4416 && (info
->hash
->creator
== abfd
->xvec
4417 || info
->hash
->creator
== abfd
->xvec
->alternative_target
))
4419 /* Common symbols less than or equal to -G nn bytes are automatically
4421 struct ppc_elf_link_hash_table
*htab
;
4423 htab
= ppc_elf_hash_table (info
);
4424 if (htab
->sbss
== NULL
)
4426 flagword flags
= SEC_IS_COMMON
;
4428 htab
->sbss
= bfd_make_section_anyway (abfd
, ".sbss");
4429 if (htab
->sbss
== NULL
4430 || ! bfd_set_section_flags (abfd
, htab
->sbss
, flags
))
4435 *valp
= sym
->st_size
;
4441 /* Finish up dynamic symbol handling. We set the contents of various
4442 dynamic sections here. */
4445 ppc_elf_finish_dynamic_symbol (bfd
*output_bfd
,
4446 struct bfd_link_info
*info
,
4447 struct elf_link_hash_entry
*h
,
4448 Elf_Internal_Sym
*sym
)
4450 struct ppc_elf_link_hash_table
*htab
;
4453 fprintf (stderr
, "ppc_elf_finish_dynamic_symbol called for %s",
4454 h
->root
.root
.string
);
4457 htab
= ppc_elf_hash_table (info
);
4458 BFD_ASSERT (htab
->elf
.dynobj
!= NULL
);
4460 if (h
->plt
.offset
!= (bfd_vma
) -1)
4462 Elf_Internal_Rela rela
;
4464 bfd_vma reloc_index
;
4467 fprintf (stderr
, ", plt_offset = %d", h
->plt
.offset
);
4470 /* This symbol has an entry in the procedure linkage table. Set
4473 BFD_ASSERT (h
->dynindx
!= -1);
4474 BFD_ASSERT (htab
->plt
!= NULL
&& htab
->relplt
!= NULL
);
4476 /* We don't need to fill in the .plt. The ppc dynamic linker
4479 /* Fill in the entry in the .rela.plt section. */
4480 rela
.r_offset
= (htab
->plt
->output_section
->vma
4481 + htab
->plt
->output_offset
4483 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_PPC_JMP_SLOT
);
4486 reloc_index
= (h
->plt
.offset
- PLT_INITIAL_ENTRY_SIZE
) / PLT_SLOT_SIZE
;
4487 if (reloc_index
> PLT_NUM_SINGLE_ENTRIES
)
4488 reloc_index
-= (reloc_index
- PLT_NUM_SINGLE_ENTRIES
) / 2;
4489 loc
= (htab
->relplt
->contents
4490 + reloc_index
* sizeof (Elf32_External_Rela
));
4491 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
4493 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
4495 /* Mark the symbol as undefined, rather than as defined in
4496 the .plt section. Leave the value alone. */
4497 sym
->st_shndx
= SHN_UNDEF
;
4498 /* If the symbol is weak, we do need to clear the value.
4499 Otherwise, the PLT entry would provide a definition for
4500 the symbol even if the symbol wasn't defined anywhere,
4501 and so the symbol would never be NULL. */
4502 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_REF_REGULAR_NONWEAK
)
4508 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_COPY
) != 0)
4511 Elf_Internal_Rela rela
;
4514 /* This symbols needs a copy reloc. Set it up. */
4517 fprintf (stderr
, ", copy");
4520 BFD_ASSERT (h
->dynindx
!= -1);
4522 if (h
->size
<= elf_gp_size (htab
->elf
.dynobj
))
4526 BFD_ASSERT (s
!= NULL
);
4528 rela
.r_offset
= (h
->root
.u
.def
.value
4529 + h
->root
.u
.def
.section
->output_section
->vma
4530 + h
->root
.u
.def
.section
->output_offset
);
4531 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_PPC_COPY
);
4533 loc
= s
->contents
+ s
->reloc_count
++ * sizeof (Elf32_External_Rela
);
4534 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
4538 fprintf (stderr
, "\n");
4541 /* Mark some specially defined symbols as absolute. */
4542 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
4543 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0
4544 || strcmp (h
->root
.root
.string
, "_PROCEDURE_LINKAGE_TABLE_") == 0)
4545 sym
->st_shndx
= SHN_ABS
;
4550 /* Finish up the dynamic sections. */
4553 ppc_elf_finish_dynamic_sections (bfd
*output_bfd
,
4554 struct bfd_link_info
*info
)
4557 struct ppc_elf_link_hash_table
*htab
;
4560 fprintf (stderr
, "ppc_elf_finish_dynamic_sections called\n");
4563 htab
= ppc_elf_hash_table (info
);
4564 sdyn
= bfd_get_section_by_name (htab
->elf
.dynobj
, ".dynamic");
4566 if (htab
->elf
.dynamic_sections_created
)
4568 Elf32_External_Dyn
*dyncon
, *dynconend
;
4570 BFD_ASSERT (htab
->plt
!= NULL
&& sdyn
!= NULL
);
4572 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
4573 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
4574 for (; dyncon
< dynconend
; dyncon
++)
4576 Elf_Internal_Dyn dyn
;
4579 bfd_elf32_swap_dyn_in (htab
->elf
.dynobj
, dyncon
, &dyn
);
4585 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
4589 dyn
.d_un
.d_val
= htab
->relplt
->_raw_size
;
4594 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
4601 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
4605 /* Add a blrl instruction at _GLOBAL_OFFSET_TABLE_-4 so that a function can
4606 easily find the address of the _GLOBAL_OFFSET_TABLE_. */
4609 unsigned char *contents
= htab
->got
->contents
;
4610 bfd_put_32 (output_bfd
, 0x4e800021 /* blrl */, contents
);
4613 bfd_put_32 (output_bfd
, 0, contents
+ 4);
4615 bfd_put_32 (output_bfd
,
4616 sdyn
->output_section
->vma
+ sdyn
->output_offset
,
4619 elf_section_data (htab
->got
->output_section
)->this_hdr
.sh_entsize
= 4;
4625 /* The RELOCATE_SECTION function is called by the ELF backend linker
4626 to handle the relocations for a section.
4628 The relocs are always passed as Rela structures; if the section
4629 actually uses Rel structures, the r_addend field will always be
4632 This function is responsible for adjust the section contents as
4633 necessary, and (if using Rela relocs and generating a
4634 relocatable output file) adjusting the reloc addend as
4637 This function does not have to worry about setting the reloc
4638 address or the reloc symbol index.
4640 LOCAL_SYMS is a pointer to the swapped in local symbols.
4642 LOCAL_SECTIONS is an array giving the section in the input file
4643 corresponding to the st_shndx field of each local symbol.
4645 The global hash table entry for the global symbols can be found
4646 via elf_sym_hashes (input_bfd).
4648 When generating relocatable output, this function must handle
4649 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
4650 going to be the section symbol corresponding to the output
4651 section, which means that the addend must be adjusted
4655 ppc_elf_relocate_section (bfd
*output_bfd
,
4656 struct bfd_link_info
*info
,
4658 asection
*input_section
,
4660 Elf_Internal_Rela
*relocs
,
4661 Elf_Internal_Sym
*local_syms
,
4662 asection
**local_sections
)
4664 Elf_Internal_Shdr
*symtab_hdr
;
4665 struct elf_link_hash_entry
**sym_hashes
;
4666 struct ppc_elf_link_hash_table
*htab
;
4667 Elf_Internal_Rela
*rel
;
4668 Elf_Internal_Rela
*relend
;
4669 Elf_Internal_Rela outrel
;
4671 asection
*sreloc
= NULL
;
4672 bfd_vma
*local_got_offsets
;
4673 bfd_boolean ret
= TRUE
;
4676 fprintf (stderr
, "ppc_elf_relocate_section called for %s section %s, "
4677 "%ld relocations%s\n",
4678 bfd_archive_filename (input_bfd
),
4679 bfd_section_name(input_bfd
, input_section
),
4680 (long) input_section
->reloc_count
,
4681 (info
->relocatable
) ? " (relocatable)" : "");
4684 if (info
->relocatable
)
4687 /* Initialize howto table if not already done. */
4688 if (!ppc_elf_howto_table
[R_PPC_ADDR32
])
4689 ppc_elf_howto_init ();
4691 htab
= ppc_elf_hash_table (info
);
4692 local_got_offsets
= elf_local_got_offsets (input_bfd
);
4693 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
4694 sym_hashes
= elf_sym_hashes (input_bfd
);
4696 relend
= relocs
+ input_section
->reloc_count
;
4697 for (; rel
< relend
; rel
++)
4699 enum elf_ppc_reloc_type r_type
;
4701 bfd_reloc_status_type r
;
4702 Elf_Internal_Sym
*sym
;
4704 struct elf_link_hash_entry
*h
;
4705 const char *sym_name
;
4706 reloc_howto_type
*howto
;
4707 unsigned long r_symndx
;
4709 bfd_vma branch_bit
, insn
, from
;
4710 bfd_boolean unresolved_reloc
;
4712 unsigned int tls_type
, tls_mask
, tls_gd
;
4714 r_type
= ELF32_R_TYPE (rel
->r_info
);
4718 unresolved_reloc
= FALSE
;
4720 r_symndx
= ELF32_R_SYM (rel
->r_info
);
4721 if (r_symndx
< symtab_hdr
->sh_info
)
4723 sym
= local_syms
+ r_symndx
;
4724 sec
= local_sections
[r_symndx
];
4725 sym_name
= bfd_elf_local_sym_name (input_bfd
, sym
);
4727 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, sec
, rel
);
4731 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
4732 while (h
->root
.type
== bfd_link_hash_indirect
4733 || h
->root
.type
== bfd_link_hash_warning
)
4734 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
4735 sym_name
= h
->root
.root
.string
;
4738 if (h
->root
.type
== bfd_link_hash_defined
4739 || h
->root
.type
== bfd_link_hash_defweak
)
4741 sec
= h
->root
.u
.def
.section
;
4742 /* Set a flag that will be cleared later if we find a
4743 relocation value for this symbol. output_section
4744 is typically NULL for symbols satisfied by a shared
4746 if (sec
->output_section
== NULL
)
4747 unresolved_reloc
= TRUE
;
4749 relocation
= (h
->root
.u
.def
.value
4750 + sec
->output_section
->vma
4751 + sec
->output_offset
);
4753 else if (h
->root
.type
== bfd_link_hash_undefweak
)
4755 else if (!info
->executable
4756 && !info
->no_undefined
4757 && ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
)
4761 if (! ((*info
->callbacks
->undefined_symbol
)
4762 (info
, h
->root
.root
.string
, input_bfd
, input_section
,
4763 rel
->r_offset
, (info
->executable
4764 || info
->no_undefined
4765 || ELF_ST_VISIBILITY (h
->other
)))))
4771 /* TLS optimizations. Replace instruction sequences and relocs
4772 based on information we collected in tls_optimize. We edit
4773 RELOCS so that --emit-relocs will output something sensible
4774 for the final instruction stream. */
4777 if (IS_PPC_TLS_RELOC (r_type
))
4780 tls_mask
= ((struct ppc_elf_link_hash_entry
*) h
)->tls_mask
;
4781 else if (local_got_offsets
!= NULL
)
4784 lgot_masks
= (char *) (local_got_offsets
+ symtab_hdr
->sh_info
);
4785 tls_mask
= lgot_masks
[r_symndx
];
4789 /* Ensure reloc mapping code below stays sane. */
4790 if ((R_PPC_GOT_TLSLD16
& 3) != (R_PPC_GOT_TLSGD16
& 3)
4791 || (R_PPC_GOT_TLSLD16_LO
& 3) != (R_PPC_GOT_TLSGD16_LO
& 3)
4792 || (R_PPC_GOT_TLSLD16_HI
& 3) != (R_PPC_GOT_TLSGD16_HI
& 3)
4793 || (R_PPC_GOT_TLSLD16_HA
& 3) != (R_PPC_GOT_TLSGD16_HA
& 3)
4794 || (R_PPC_GOT_TLSLD16
& 3) != (R_PPC_GOT_TPREL16
& 3)
4795 || (R_PPC_GOT_TLSLD16_LO
& 3) != (R_PPC_GOT_TPREL16_LO
& 3)
4796 || (R_PPC_GOT_TLSLD16_HI
& 3) != (R_PPC_GOT_TPREL16_HI
& 3)
4797 || (R_PPC_GOT_TLSLD16_HA
& 3) != (R_PPC_GOT_TPREL16_HA
& 3))
4804 case R_PPC_GOT_TPREL16
:
4805 case R_PPC_GOT_TPREL16_LO
:
4807 && (tls_mask
& TLS_TPREL
) == 0)
4810 insn
= bfd_get_32 (output_bfd
, contents
+ rel
->r_offset
- 2);
4812 insn
|= 0x3c020000; /* addis 0,2,0 */
4813 bfd_put_32 (output_bfd
, insn
, contents
+ rel
->r_offset
- 2);
4814 r_type
= R_PPC_TPREL16_HA
;
4815 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
4821 && (tls_mask
& TLS_TPREL
) == 0)
4824 insn
= bfd_get_32 (output_bfd
, contents
+ rel
->r_offset
);
4825 if ((insn
& ((31 << 26) | (31 << 11)))
4826 == ((31 << 26) | (2 << 11)))
4827 rtra
= insn
& ((1 << 26) - (1 << 16));
4828 else if ((insn
& ((31 << 26) | (31 << 16)))
4829 == ((31 << 26) | (2 << 16)))
4830 rtra
= (insn
& (31 << 21)) | ((insn
& (31 << 11)) << 5);
4833 if ((insn
& ((1 << 11) - (1 << 1))) == 266 << 1)
4836 else if ((insn
& (31 << 1)) == 23 << 1
4837 && ((insn
& (31 << 6)) < 14 << 6
4838 || ((insn
& (31 << 6)) >= 16 << 6
4839 && (insn
& (31 << 6)) < 24 << 6)))
4840 /* load and store indexed -> dform. */
4841 insn
= (32 | ((insn
>> 6) & 31)) << 26;
4842 else if ((insn
& (31 << 1)) == 21 << 1
4843 && (insn
& (0x1a << 6)) == 0)
4844 /* ldx, ldux, stdx, stdux -> ld, ldu, std, stdu. */
4845 insn
= (((58 | ((insn
>> 6) & 4)) << 26)
4846 | ((insn
>> 6) & 1));
4847 else if ((insn
& (31 << 1)) == 21 << 1
4848 && (insn
& ((1 << 11) - (1 << 1))) == 341 << 1)
4850 insn
= (58 << 26) | 2;
4854 bfd_put_32 (output_bfd
, insn
, contents
+ rel
->r_offset
);
4855 r_type
= R_PPC_TPREL16_LO
;
4856 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
4857 /* Was PPC_TLS which sits on insn boundary, now
4858 PPC_TPREL16_LO which is at insn+2. */
4863 case R_PPC_GOT_TLSGD16_HI
:
4864 case R_PPC_GOT_TLSGD16_HA
:
4865 tls_gd
= TLS_TPRELGD
;
4866 if (tls_mask
!= 0 && (tls_mask
& TLS_GD
) == 0)
4870 case R_PPC_GOT_TLSLD16_HI
:
4871 case R_PPC_GOT_TLSLD16_HA
:
4872 if (tls_mask
!= 0 && (tls_mask
& TLS_LD
) == 0)
4875 if ((tls_mask
& tls_gd
) != 0)
4876 r_type
= (((r_type
- (R_PPC_GOT_TLSGD16
& 3)) & 3)
4877 + R_PPC_GOT_TPREL16
);
4880 bfd_put_32 (output_bfd
, NOP
, contents
+ rel
->r_offset
);
4882 r_type
= R_PPC_NONE
;
4884 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
4888 case R_PPC_GOT_TLSGD16
:
4889 case R_PPC_GOT_TLSGD16_LO
:
4890 tls_gd
= TLS_TPRELGD
;
4891 if (tls_mask
!= 0 && (tls_mask
& TLS_GD
) == 0)
4892 goto tls_get_addr_check
;
4895 case R_PPC_GOT_TLSLD16
:
4896 case R_PPC_GOT_TLSLD16_LO
:
4897 if (tls_mask
!= 0 && (tls_mask
& TLS_LD
) == 0)
4900 if (rel
+ 1 < relend
)
4902 enum elf_ppc_reloc_type r_type2
;
4903 unsigned long r_symndx2
;
4904 struct elf_link_hash_entry
*h2
;
4905 bfd_vma insn1
, insn2
;
4908 /* The next instruction should be a call to
4909 __tls_get_addr. Peek at the reloc to be sure. */
4910 r_type2
= ELF32_R_TYPE (rel
[1].r_info
);
4911 r_symndx2
= ELF32_R_SYM (rel
[1].r_info
);
4912 if (r_symndx2
< symtab_hdr
->sh_info
4913 || (r_type2
!= R_PPC_REL14
4914 && r_type2
!= R_PPC_REL14_BRTAKEN
4915 && r_type2
!= R_PPC_REL14_BRNTAKEN
4916 && r_type2
!= R_PPC_REL24
4917 && r_type2
!= R_PPC_PLTREL24
))
4920 h2
= sym_hashes
[r_symndx2
- symtab_hdr
->sh_info
];
4921 while (h2
->root
.type
== bfd_link_hash_indirect
4922 || h2
->root
.type
== bfd_link_hash_warning
)
4923 h2
= (struct elf_link_hash_entry
*) h2
->root
.u
.i
.link
;
4924 if (h2
== NULL
|| h2
!= htab
->tls_get_addr
)
4927 /* OK, it checks out. Replace the call. */
4928 offset
= rel
[1].r_offset
;
4929 insn1
= bfd_get_32 (output_bfd
,
4930 contents
+ rel
->r_offset
- 2);
4931 if ((tls_mask
& tls_gd
) != 0)
4934 insn1
&= (1 << 26) - 1;
4935 insn1
|= 32 << 26; /* lwz */
4936 insn2
= 0x7c631214; /* add 3,3,2 */
4937 rel
[1].r_info
= ELF32_R_INFO (r_symndx2
, R_PPC_NONE
);
4938 r_type
= (((r_type
- (R_PPC_GOT_TLSGD16
& 3)) & 3)
4939 + R_PPC_GOT_TPREL16
);
4940 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
4945 insn1
= 0x3c620000; /* addis 3,2,0 */
4946 insn2
= 0x38630000; /* addi 3,3,0 */
4949 /* Was an LD reloc. */
4951 rel
->r_addend
= htab
->tls_sec
->vma
+ DTP_OFFSET
;
4952 rel
[1].r_addend
= htab
->tls_sec
->vma
+ DTP_OFFSET
;
4954 r_type
= R_PPC_TPREL16_HA
;
4955 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
4956 rel
[1].r_info
= ELF32_R_INFO (r_symndx
,
4958 rel
[1].r_offset
+= 2;
4960 bfd_put_32 (output_bfd
, insn1
, contents
+ rel
->r_offset
- 2);
4961 bfd_put_32 (output_bfd
, insn2
, contents
+ offset
);
4964 /* We changed the symbol on an LD reloc. Start over
4965 in order to get h, sym, sec etc. right. */
4974 /* Handle other relocations that tweak non-addend part of insn. */
4981 /* Branch taken prediction relocations. */
4982 case R_PPC_ADDR14_BRTAKEN
:
4983 case R_PPC_REL14_BRTAKEN
:
4984 branch_bit
= BRANCH_PREDICT_BIT
;
4987 /* Branch not taken predicition relocations. */
4988 case R_PPC_ADDR14_BRNTAKEN
:
4989 case R_PPC_REL14_BRNTAKEN
:
4990 insn
= bfd_get_32 (output_bfd
, contents
+ rel
->r_offset
);
4991 insn
&= ~BRANCH_PREDICT_BIT
;
4994 from
= (rel
->r_offset
4995 + input_section
->output_offset
4996 + input_section
->output_section
->vma
);
4998 /* Invert 'y' bit if not the default. */
4999 if ((bfd_signed_vma
) (relocation
+ rel
->r_addend
- from
) < 0)
5000 insn
^= BRANCH_PREDICT_BIT
;
5002 bfd_put_32 (output_bfd
, insn
, contents
+ rel
->r_offset
);
5006 addend
= rel
->r_addend
;
5009 if (r_type
< R_PPC_max
)
5010 howto
= ppc_elf_howto_table
[r_type
];
5014 (*_bfd_error_handler
)
5015 (_("%s: unknown relocation type %d for symbol %s"),
5016 bfd_archive_filename (input_bfd
), (int) r_type
, sym_name
);
5018 bfd_set_error (bfd_error_bad_value
);
5024 case R_PPC_EMB_MRKREF
:
5025 case R_PPC_GNU_VTINHERIT
:
5026 case R_PPC_GNU_VTENTRY
:
5029 /* GOT16 relocations. Like an ADDR16 using the symbol's
5030 address in the GOT as relocation value instead of the
5031 symbol's value itself. Also, create a GOT entry for the
5032 symbol and put the symbol value there. */
5033 case R_PPC_GOT_TLSGD16
:
5034 case R_PPC_GOT_TLSGD16_LO
:
5035 case R_PPC_GOT_TLSGD16_HI
:
5036 case R_PPC_GOT_TLSGD16_HA
:
5037 tls_type
= TLS_TLS
| TLS_GD
;
5040 case R_PPC_GOT_TLSLD16
:
5041 case R_PPC_GOT_TLSLD16_LO
:
5042 case R_PPC_GOT_TLSLD16_HI
:
5043 case R_PPC_GOT_TLSLD16_HA
:
5044 tls_type
= TLS_TLS
| TLS_LD
;
5047 case R_PPC_GOT_TPREL16
:
5048 case R_PPC_GOT_TPREL16_LO
:
5049 case R_PPC_GOT_TPREL16_HI
:
5050 case R_PPC_GOT_TPREL16_HA
:
5051 tls_type
= TLS_TLS
| TLS_TPREL
;
5054 case R_PPC_GOT_DTPREL16
:
5055 case R_PPC_GOT_DTPREL16_LO
:
5056 case R_PPC_GOT_DTPREL16_HI
:
5057 case R_PPC_GOT_DTPREL16_HA
:
5058 tls_type
= TLS_TLS
| TLS_DTPREL
;
5062 case R_PPC_GOT16_LO
:
5063 case R_PPC_GOT16_HI
:
5064 case R_PPC_GOT16_HA
:
5067 /* Relocation is to the entry for this symbol in the global
5073 if (htab
->got
== NULL
)
5077 if (tls_type
== (TLS_TLS
| TLS_LD
)
5079 || !(h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
)))
5080 offp
= &htab
->tlsld_got
.offset
;
5084 dyn
= htab
->elf
.dynamic_sections_created
;
5085 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
5087 && SYMBOL_REFERENCES_LOCAL (info
, h
)))
5088 /* This is actually a static link, or it is a
5089 -Bsymbolic link and the symbol is defined
5090 locally, or the symbol was forced to be local
5091 because of a version file. */
5096 unresolved_reloc
= FALSE
;
5098 offp
= &h
->got
.offset
;
5102 if (local_got_offsets
== NULL
)
5104 offp
= &local_got_offsets
[r_symndx
];
5107 /* The offset must always be a multiple of 4. We use the
5108 least significant bit to record whether we have already
5109 processed this entry. */
5115 unsigned int tls_m
= (tls_mask
5116 & (TLS_LD
| TLS_GD
| TLS_DTPREL
5117 | TLS_TPREL
| TLS_TPRELGD
));
5119 if (offp
== &htab
->tlsld_got
.offset
)
5122 || !(h
->elf_link_hash_flags
5123 & ELF_LINK_HASH_DEF_DYNAMIC
))
5126 /* We might have multiple got entries for this sym.
5127 Initialize them all. */
5132 if ((tls_m
& TLS_LD
) != 0)
5134 tls_ty
= TLS_TLS
| TLS_LD
;
5137 else if ((tls_m
& TLS_GD
) != 0)
5139 tls_ty
= TLS_TLS
| TLS_GD
;
5142 else if ((tls_m
& TLS_DTPREL
) != 0)
5144 tls_ty
= TLS_TLS
| TLS_DTPREL
;
5145 tls_m
&= ~TLS_DTPREL
;
5147 else if ((tls_m
& (TLS_TPREL
| TLS_TPRELGD
)) != 0)
5149 tls_ty
= TLS_TLS
| TLS_TPREL
;
5153 /* Generate relocs for the dynamic linker. */
5154 if ((info
->shared
|| indx
!= 0)
5156 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
5157 || h
->root
.type
!= bfd_link_hash_undefweak
))
5159 outrel
.r_offset
= (htab
->got
->output_section
->vma
5160 + htab
->got
->output_offset
5162 outrel
.r_addend
= 0;
5163 if (tls_ty
& (TLS_LD
| TLS_GD
))
5165 outrel
.r_info
= ELF32_R_INFO (indx
, R_PPC_DTPMOD32
);
5166 if (tls_ty
== (TLS_TLS
| TLS_GD
))
5168 loc
= htab
->relgot
->contents
;
5169 loc
+= (htab
->relgot
->reloc_count
++
5170 * sizeof (Elf32_External_Rela
));
5171 bfd_elf32_swap_reloca_out (output_bfd
,
5173 outrel
.r_offset
+= 4;
5175 = ELF32_R_INFO (indx
, R_PPC_DTPREL32
);
5178 else if (tls_ty
== (TLS_TLS
| TLS_DTPREL
))
5179 outrel
.r_info
= ELF32_R_INFO (indx
, R_PPC_DTPREL32
);
5180 else if (tls_ty
== (TLS_TLS
| TLS_TPREL
))
5181 outrel
.r_info
= ELF32_R_INFO (indx
, R_PPC_TPREL32
);
5183 outrel
.r_info
= ELF32_R_INFO (indx
, R_PPC_RELATIVE
);
5185 outrel
.r_info
= ELF32_R_INFO (indx
, R_PPC_GLOB_DAT
);
5188 outrel
.r_addend
+= relocation
;
5189 if (tls_ty
& (TLS_GD
| TLS_DTPREL
| TLS_TPREL
))
5190 outrel
.r_addend
-= htab
->tls_sec
->vma
;
5192 loc
= htab
->relgot
->contents
;
5193 loc
+= (htab
->relgot
->reloc_count
++
5194 * sizeof (Elf32_External_Rela
));
5195 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
5198 /* Init the .got section contents if we're not
5199 emitting a reloc. */
5202 bfd_vma value
= relocation
;
5204 if (tls_ty
== (TLS_TLS
| TLS_LD
))
5206 else if (tls_ty
!= 0)
5208 value
-= htab
->tls_sec
->vma
+ DTP_OFFSET
;
5209 if (tls_ty
== (TLS_TLS
| TLS_TPREL
))
5210 value
+= DTP_OFFSET
- TP_OFFSET
;
5212 if (tls_ty
== (TLS_TLS
| TLS_GD
))
5214 bfd_put_32 (output_bfd
, value
,
5215 htab
->got
->contents
+ off
+ 4);
5219 bfd_put_32 (output_bfd
, value
,
5220 htab
->got
->contents
+ off
);
5224 if (tls_ty
& (TLS_LD
| TLS_GD
))
5233 if (off
>= (bfd_vma
) -2)
5236 if ((tls_type
& TLS_TLS
) != 0)
5238 if (tls_type
!= (TLS_TLS
| TLS_LD
))
5240 if ((tls_mask
& TLS_LD
) != 0
5242 || !(h
->elf_link_hash_flags
5243 & ELF_LINK_HASH_DEF_DYNAMIC
)))
5245 if (tls_type
!= (TLS_TLS
| TLS_GD
))
5247 if ((tls_mask
& TLS_GD
) != 0)
5249 if (tls_type
!= (TLS_TLS
| TLS_DTPREL
))
5251 if ((tls_mask
& TLS_DTPREL
) != 0)
5258 relocation
= htab
->got
->output_offset
+ off
- 4;
5260 /* Addends on got relocations don't make much sense.
5261 x+off@got is actually x@got+off, and since the got is
5262 generated by a hash table traversal, the value in the
5263 got at entry m+n bears little relation to the entry m. */
5265 (*_bfd_error_handler
)
5266 (_("%s(%s+0x%lx): non-zero addend on %s reloc against `%s'"),
5267 bfd_archive_filename (input_bfd
),
5268 bfd_get_section_name (input_bfd
, input_section
),
5269 (long) rel
->r_offset
,
5275 /* Relocations that need no special processing. */
5276 case R_PPC_LOCAL24PC
:
5277 /* It makes no sense to point a local relocation
5278 at a symbol not in this object. */
5279 if (unresolved_reloc
)
5281 if (! (*info
->callbacks
->undefined_symbol
) (info
,
5282 h
->root
.root
.string
,
5292 case R_PPC_DTPREL16
:
5293 case R_PPC_DTPREL16_LO
:
5294 case R_PPC_DTPREL16_HI
:
5295 case R_PPC_DTPREL16_HA
:
5296 addend
-= htab
->tls_sec
->vma
+ DTP_OFFSET
;
5299 /* Relocations that may need to be propagated if this is a shared
5302 case R_PPC_TPREL16_LO
:
5303 case R_PPC_TPREL16_HI
:
5304 case R_PPC_TPREL16_HA
:
5305 addend
-= htab
->tls_sec
->vma
+ TP_OFFSET
;
5306 /* The TPREL16 relocs shouldn't really be used in shared
5307 libs as they will result in DT_TEXTREL being set, but
5308 support them anyway. */
5312 addend
-= htab
->tls_sec
->vma
+ TP_OFFSET
;
5315 case R_PPC_DTPREL32
:
5316 addend
-= htab
->tls_sec
->vma
+ DTP_OFFSET
;
5319 case R_PPC_DTPMOD32
:
5327 case R_PPC_REL14_BRTAKEN
:
5328 case R_PPC_REL14_BRNTAKEN
:
5329 /* If these relocations are not to a named symbol, they can be
5330 handled right here, no need to bother the dynamic linker. */
5331 if (SYMBOL_REFERENCES_LOCAL (info
, h
)
5332 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
5336 /* Relocations that always need to be propagated if this is a shared
5341 case R_PPC_ADDR16_LO
:
5342 case R_PPC_ADDR16_HI
:
5343 case R_PPC_ADDR16_HA
:
5345 case R_PPC_ADDR14_BRTAKEN
:
5346 case R_PPC_ADDR14_BRNTAKEN
:
5349 /* r_symndx will be zero only for relocs against symbols
5350 from removed linkonce sections, or sections discarded by
5359 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
5360 || h
->root
.type
!= bfd_link_hash_undefweak
)
5361 && (MUST_BE_DYN_RELOC (r_type
)
5362 || !SYMBOL_CALLS_LOCAL (info
, h
)))
5363 || (ELIMINATE_COPY_RELOCS
5365 && (input_section
->flags
& SEC_ALLOC
) != 0
5368 && (h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0
5369 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
5370 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0))
5375 fprintf (stderr
, "ppc_elf_relocate_section needs to "
5376 "create relocation for %s\n",
5377 (h
&& h
->root
.root
.string
5378 ? h
->root
.root
.string
: "<unknown>"));
5381 /* When generating a shared object, these relocations
5382 are copied into the output file to be resolved at run
5388 name
= (bfd_elf_string_from_elf_section
5390 elf_elfheader (input_bfd
)->e_shstrndx
,
5391 elf_section_data (input_section
)->rel_hdr
.sh_name
));
5395 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
5396 && strcmp (bfd_get_section_name (input_bfd
,
5400 sreloc
= bfd_get_section_by_name (htab
->elf
.dynobj
, name
);
5401 BFD_ASSERT (sreloc
!= NULL
);
5407 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
5409 if (outrel
.r_offset
== (bfd_vma
) -1
5410 || outrel
.r_offset
== (bfd_vma
) -2)
5411 skip
= (int) outrel
.r_offset
;
5412 outrel
.r_offset
+= (input_section
->output_section
->vma
5413 + input_section
->output_offset
);
5416 memset (&outrel
, 0, sizeof outrel
);
5417 else if (!SYMBOL_REFERENCES_LOCAL (info
, h
))
5419 unresolved_reloc
= FALSE
;
5420 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
5421 outrel
.r_addend
= rel
->r_addend
;
5425 outrel
.r_addend
= relocation
+ rel
->r_addend
;
5427 if (r_type
== R_PPC_ADDR32
)
5428 outrel
.r_info
= ELF32_R_INFO (0, R_PPC_RELATIVE
);
5433 if (bfd_is_abs_section (sec
))
5435 else if (sec
== NULL
|| sec
->owner
== NULL
)
5437 bfd_set_error (bfd_error_bad_value
);
5444 /* We are turning this relocation into one
5445 against a section symbol. It would be
5446 proper to subtract the symbol's value,
5447 osec->vma, from the emitted reloc addend,
5448 but ld.so expects buggy relocs. */
5449 osec
= sec
->output_section
;
5450 indx
= elf_section_data (osec
)->dynindx
;
5451 BFD_ASSERT (indx
> 0);
5454 printf ("indx=%d section=%s flags=%08x name=%s\n",
5455 indx
, osec
->name
, osec
->flags
,
5456 h
->root
.root
.string
);
5460 outrel
.r_info
= ELF32_R_INFO (indx
, r_type
);
5464 loc
= sreloc
->contents
;
5465 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rela
);
5466 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
5471 /* This reloc will be computed at runtime. We clear the memory
5472 so that it contains predictable value. */
5474 && ((input_section
->flags
& SEC_ALLOC
) != 0
5475 || ELF32_R_TYPE (outrel
.r_info
) != R_PPC_RELATIVE
))
5477 relocation
= howto
->pc_relative
? outrel
.r_offset
: 0;
5486 unsigned long r_symndx
;
5487 Elf_Internal_Sym
*sym
;
5489 bfd_byte
*hit_addr
= 0;
5492 r_symndx
= ELF32_R_SYM (rel
->r_info
);
5494 if (r_symndx
< symtab_hdr
->sh_info
)
5496 sym
= local_syms
+ r_symndx
;
5497 sym_sec
= local_sections
[r_symndx
];
5499 value
= _bfd_elf_rela_local_sym (output_bfd
, sym
, sym_sec
, rel
);
5505 indx
= r_symndx
- symtab_hdr
->sh_info
;
5506 h
= elf_sym_hashes (input_bfd
)[indx
];
5507 while (h
->root
.type
== bfd_link_hash_indirect
5508 || h
->root
.type
== bfd_link_hash_warning
)
5509 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
5512 if (h
->root
.type
== bfd_link_hash_defined
5513 || h
->root
.type
== bfd_link_hash_defweak
)
5515 sym_sec
= h
->root
.u
.def
.section
;
5517 /* Detect the cases that sym_sec->output_section is
5518 expected to be NULL -- all cases in which the symbol
5519 is defined in another shared module. This includes
5520 PLT relocs for which we've created a PLT entry and
5521 other relocs for which we're prepared to create
5522 dynamic relocations. */
5523 /* ??? Just accept it NULL and continue. */
5525 if (sym_sec
->output_section
!= NULL
)
5527 value
= (h
->root
.u
.def
.value
5528 + sym_sec
->output_section
->vma
5529 + sym_sec
->output_offset
);
5532 else if (!info
->executable
5533 && !info
->no_undefined
5534 && ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
)
5538 if (! ((*info
->callbacks
->undefined_symbol
)
5539 (info
, h
->root
.root
.string
, input_bfd
,
5540 input_section
, rel
->r_offset
,
5541 (info
->executable
|| info
->no_undefined
5542 || ELF_ST_VISIBILITY (h
->other
)))))
5547 hit_addr
= contents
+ rel
->r_offset
;
5548 value
+= rel
->r_addend
;
5550 r
= ppc_elf_install_value (output_bfd
, hit_addr
, value
, r_type
);
5551 if (r
!= bfd_reloc_ok
)
5557 /* Indirect .sdata relocation. */
5558 case R_PPC_EMB_SDAI16
:
5559 BFD_ASSERT (htab
->sdata
!= NULL
);
5561 = elf_finish_pointer_linker_section (output_bfd
, input_bfd
, info
,
5562 htab
->sdata
, h
, relocation
,
5563 rel
, R_PPC_RELATIVE
);
5566 /* Indirect .sdata2 relocation. */
5567 case R_PPC_EMB_SDA2I16
:
5568 BFD_ASSERT (htab
->sdata2
!= NULL
);
5570 = elf_finish_pointer_linker_section (output_bfd
, input_bfd
, info
,
5571 htab
->sdata2
, h
, relocation
,
5572 rel
, R_PPC_RELATIVE
);
5575 /* Handle the TOC16 reloc. We want to use the offset within the .got
5576 section, not the actual VMA. This is appropriate when generating
5577 an embedded ELF object, for which the .got section acts like the
5578 AIX .toc section. */
5579 case R_PPC_TOC16
: /* phony GOT16 relocations */
5580 BFD_ASSERT (sec
!= NULL
);
5581 BFD_ASSERT (bfd_is_und_section (sec
)
5582 || strcmp (bfd_get_section_name (abfd
, sec
), ".got") == 0
5583 || strcmp (bfd_get_section_name (abfd
, sec
), ".cgot") == 0)
5585 addend
-= sec
->output_section
->vma
+ sec
->output_offset
+ 0x8000;
5588 case R_PPC_PLTREL24
:
5589 /* Relocation is to the entry for this symbol in the
5590 procedure linkage table. */
5591 BFD_ASSERT (h
!= NULL
);
5593 if (h
->plt
.offset
== (bfd_vma
) -1
5594 || htab
->plt
== NULL
)
5596 /* We didn't make a PLT entry for this symbol. This
5597 happens when statically linking PIC code, or when
5598 using -Bsymbolic. */
5602 unresolved_reloc
= FALSE
;
5603 relocation
= (htab
->plt
->output_section
->vma
5604 + htab
->plt
->output_offset
5608 /* Relocate against _SDA_BASE_. */
5609 case R_PPC_SDAREL16
:
5612 const struct elf_link_hash_entry
*sh
;
5614 BFD_ASSERT (sec
!= NULL
);
5615 name
= bfd_get_section_name (abfd
, sec
->output_section
);
5616 if (! ((strncmp (name
, ".sdata", 6) == 0
5617 && (name
[6] == 0 || name
[6] == '.'))
5618 || (strncmp (name
, ".sbss", 5) == 0
5619 && (name
[5] == 0 || name
[5] == '.'))))
5621 (*_bfd_error_handler
)
5622 (_("%s: the target (%s) of a %s relocation is "
5623 "in the wrong output section (%s)"),
5624 bfd_archive_filename (input_bfd
),
5629 sh
= htab
->sdata
->sym_hash
;
5630 addend
-= (sh
->root
.u
.def
.value
5631 + sh
->root
.u
.def
.section
->output_section
->vma
5632 + sh
->root
.u
.def
.section
->output_offset
);
5636 /* Relocate against _SDA2_BASE_. */
5637 case R_PPC_EMB_SDA2REL
:
5640 const struct elf_link_hash_entry
*sh
;
5642 BFD_ASSERT (sec
!= NULL
);
5643 name
= bfd_get_section_name (abfd
, sec
->output_section
);
5644 if (! (strncmp (name
, ".sdata2", 7) == 0
5645 || strncmp (name
, ".sbss2", 6) == 0))
5647 (*_bfd_error_handler
)
5648 (_("%s: the target (%s) of a %s relocation is "
5649 "in the wrong output section (%s)"),
5650 bfd_archive_filename (input_bfd
),
5655 bfd_set_error (bfd_error_bad_value
);
5659 sh
= htab
->sdata2
->sym_hash
;
5660 addend
-= (sh
->root
.u
.def
.value
5661 + sh
->root
.u
.def
.section
->output_section
->vma
5662 + sh
->root
.u
.def
.section
->output_offset
);
5666 /* Relocate against either _SDA_BASE_, _SDA2_BASE_, or 0. */
5667 case R_PPC_EMB_SDA21
:
5668 case R_PPC_EMB_RELSDA
:
5671 const struct elf_link_hash_entry
*sh
;
5674 BFD_ASSERT (sec
!= NULL
);
5675 name
= bfd_get_section_name (abfd
, sec
->output_section
);
5676 if (((strncmp (name
, ".sdata", 6) == 0
5677 && (name
[6] == 0 || name
[6] == '.'))
5678 || (strncmp (name
, ".sbss", 5) == 0
5679 && (name
[5] == 0 || name
[5] == '.'))))
5682 sh
= htab
->sdata
->sym_hash
;
5683 addend
-= (sh
->root
.u
.def
.value
5684 + sh
->root
.u
.def
.section
->output_section
->vma
5685 + sh
->root
.u
.def
.section
->output_offset
);
5688 else if (strncmp (name
, ".sdata2", 7) == 0
5689 || strncmp (name
, ".sbss2", 6) == 0)
5692 sh
= htab
->sdata2
->sym_hash
;
5693 addend
-= (sh
->root
.u
.def
.value
5694 + sh
->root
.u
.def
.section
->output_section
->vma
5695 + sh
->root
.u
.def
.section
->output_offset
);
5698 else if (strcmp (name
, ".PPC.EMB.sdata0") == 0
5699 || strcmp (name
, ".PPC.EMB.sbss0") == 0)
5706 (*_bfd_error_handler
)
5707 (_("%s: the target (%s) of a %s relocation is "
5708 "in the wrong output section (%s)"),
5709 bfd_archive_filename (input_bfd
),
5714 bfd_set_error (bfd_error_bad_value
);
5719 if (r_type
== R_PPC_EMB_SDA21
)
5720 { /* fill in register field */
5721 insn
= bfd_get_32 (output_bfd
, contents
+ rel
->r_offset
);
5722 insn
= (insn
& ~RA_REGISTER_MASK
) | (reg
<< RA_REGISTER_SHIFT
);
5723 bfd_put_32 (output_bfd
, insn
, contents
+ rel
->r_offset
);
5728 /* Relocate against the beginning of the section. */
5730 case R_PPC_SECTOFF_LO
:
5731 case R_PPC_SECTOFF_HI
:
5732 case R_PPC_SECTOFF_HA
:
5733 BFD_ASSERT (sec
!= NULL
);
5734 addend
-= sec
->output_section
->vma
;
5737 /* Negative relocations. */
5738 case R_PPC_EMB_NADDR32
:
5739 case R_PPC_EMB_NADDR16
:
5740 case R_PPC_EMB_NADDR16_LO
:
5741 case R_PPC_EMB_NADDR16_HI
:
5742 case R_PPC_EMB_NADDR16_HA
:
5743 addend
-= 2 * relocation
;
5747 case R_PPC_GLOB_DAT
:
5748 case R_PPC_JMP_SLOT
:
5749 case R_PPC_RELATIVE
:
5751 case R_PPC_PLTREL32
:
5752 case R_PPC_PLT16_LO
:
5753 case R_PPC_PLT16_HI
:
5754 case R_PPC_PLT16_HA
:
5756 case R_PPC_EMB_RELSEC16
:
5757 case R_PPC_EMB_RELST_LO
:
5758 case R_PPC_EMB_RELST_HI
:
5759 case R_PPC_EMB_RELST_HA
:
5760 case R_PPC_EMB_BIT_FLD
:
5761 (*_bfd_error_handler
)
5762 (_("%s: relocation %s is not yet supported for symbol %s."),
5763 bfd_archive_filename (input_bfd
),
5767 bfd_set_error (bfd_error_invalid_operation
);
5772 /* Do any further special processing. */
5778 case R_PPC_ADDR16_HA
:
5779 case R_PPC_GOT16_HA
:
5780 case R_PPC_PLT16_HA
:
5781 case R_PPC_SECTOFF_HA
:
5782 case R_PPC_TPREL16_HA
:
5783 case R_PPC_DTPREL16_HA
:
5784 case R_PPC_GOT_TLSGD16_HA
:
5785 case R_PPC_GOT_TLSLD16_HA
:
5786 case R_PPC_GOT_TPREL16_HA
:
5787 case R_PPC_GOT_DTPREL16_HA
:
5788 case R_PPC_EMB_NADDR16_HA
:
5789 case R_PPC_EMB_RELST_HA
:
5790 /* It's just possible that this symbol is a weak symbol
5791 that's not actually defined anywhere. In that case,
5792 'sec' would be NULL, and we should leave the symbol
5793 alone (it will be set to zero elsewhere in the link). */
5795 /* Add 0x10000 if sign bit in 0:15 is set.
5796 Bits 0:15 are not used. */
5802 fprintf (stderr
, "\ttype = %s (%d), name = %s, symbol index = %ld, "
5803 "offset = %ld, addend = %ld\n",
5808 (long) rel
->r_offset
,
5812 if (unresolved_reloc
5813 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
5814 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0))
5816 (*_bfd_error_handler
)
5817 (_("%s(%s+0x%lx): unresolvable %s relocation against symbol `%s'"),
5818 bfd_archive_filename (input_bfd
),
5819 bfd_get_section_name (input_bfd
, input_section
),
5820 (long) rel
->r_offset
,
5826 r
= _bfd_final_link_relocate (howto
,
5834 if (r
!= bfd_reloc_ok
)
5836 if (sym_name
== NULL
)
5837 sym_name
= "(null)";
5838 if (r
== bfd_reloc_overflow
)
5843 && h
->root
.type
== bfd_link_hash_undefweak
5844 && howto
->pc_relative
)
5846 /* Assume this is a call protected by other code that
5847 detect the symbol is undefined. If this is the case,
5848 we can safely ignore the overflow. If not, the
5849 program is hosed anyway, and a little warning isn't
5855 if (! (*info
->callbacks
->reloc_overflow
) (info
,
5866 (*_bfd_error_handler
)
5867 (_("%s(%s+0x%lx): %s reloc against `%s': error %d"),
5868 bfd_archive_filename (input_bfd
),
5869 bfd_get_section_name (input_bfd
, input_section
),
5870 (long) rel
->r_offset
, howto
->name
, sym_name
, (int) r
);
5877 fprintf (stderr
, "\n");
5883 static enum elf_reloc_type_class
5884 ppc_elf_reloc_type_class (const Elf_Internal_Rela
*rela
)
5886 switch (ELF32_R_TYPE (rela
->r_info
))
5888 case R_PPC_RELATIVE
:
5889 return reloc_class_relative
;
5892 case R_PPC_JMP_SLOT
:
5893 return reloc_class_plt
;
5895 return reloc_class_copy
;
5897 return reloc_class_normal
;
5901 /* Support for core dump NOTE sections. */
5904 ppc_elf_grok_prstatus (bfd
*abfd
, Elf_Internal_Note
*note
)
5907 unsigned int raw_size
;
5909 switch (note
->descsz
)
5914 case 268: /* Linux/PPC. */
5916 elf_tdata (abfd
)->core_signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
5919 elf_tdata (abfd
)->core_pid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
5928 /* Make a ".reg/999" section. */
5929 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
5930 raw_size
, note
->descpos
+ offset
);
5934 ppc_elf_grok_psinfo (bfd
*abfd
, Elf_Internal_Note
*note
)
5936 switch (note
->descsz
)
5941 case 128: /* Linux/PPC elf_prpsinfo. */
5942 elf_tdata (abfd
)->core_program
5943 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 32, 16);
5944 elf_tdata (abfd
)->core_command
5945 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 48, 80);
5948 /* Note that for some reason, a spurious space is tacked
5949 onto the end of the args in some (at least one anyway)
5950 implementations, so strip it off if it exists. */
5953 char *command
= elf_tdata (abfd
)->core_command
;
5954 int n
= strlen (command
);
5956 if (0 < n
&& command
[n
- 1] == ' ')
5957 command
[n
- 1] = '\0';
5963 /* Very simple linked list structure for recording apuinfo values. */
5964 typedef struct apuinfo_list
5966 struct apuinfo_list
*next
;
5967 unsigned long value
;
5971 static apuinfo_list
*head
;
5975 apuinfo_list_init (void)
5981 apuinfo_list_add (unsigned long value
)
5983 apuinfo_list
*entry
= head
;
5985 while (entry
!= NULL
)
5987 if (entry
->value
== value
)
5989 entry
= entry
->next
;
5992 entry
= bfd_malloc (sizeof (* entry
));
5996 entry
->value
= value
;
6002 apuinfo_list_length (void)
6004 apuinfo_list
*entry
;
6005 unsigned long count
;
6007 for (entry
= head
, count
= 0;
6009 entry
= entry
->next
)
6015 static inline unsigned long
6016 apuinfo_list_element (unsigned long number
)
6018 apuinfo_list
* entry
;
6022 entry
= entry
->next
)
6025 return entry
? entry
->value
: 0;
6029 apuinfo_list_finish (void)
6031 apuinfo_list
*entry
;
6033 for (entry
= head
; entry
;)
6035 apuinfo_list
*next
= entry
->next
;
6043 #define APUINFO_SECTION_NAME ".PPC.EMB.apuinfo"
6044 #define APUINFO_LABEL "APUinfo"
6046 /* Scan the input BFDs and create a linked list of
6047 the APUinfo values that will need to be emitted. */
6050 ppc_elf_begin_write_processing (bfd
*abfd
, struct bfd_link_info
*link_info
)
6055 unsigned num_input_sections
;
6056 bfd_size_type output_section_size
;
6058 unsigned num_entries
;
6059 unsigned long offset
;
6060 unsigned long length
;
6061 const char *error_message
= NULL
;
6063 if (link_info
== NULL
)
6066 /* Scan the input bfds, looking for apuinfo sections. */
6067 num_input_sections
= 0;
6068 output_section_size
= 0;
6070 for (ibfd
= link_info
->input_bfds
; ibfd
; ibfd
= ibfd
->link_next
)
6072 asec
= bfd_get_section_by_name (ibfd
, APUINFO_SECTION_NAME
);
6075 ++ num_input_sections
;
6076 output_section_size
+= asec
->_raw_size
;
6080 /* We need at least one input sections
6081 in order to make merging worthwhile. */
6082 if (num_input_sections
< 1)
6085 /* Just make sure that the output section exists as well. */
6086 asec
= bfd_get_section_by_name (abfd
, APUINFO_SECTION_NAME
);
6090 /* Allocate a buffer for the contents of the input sections. */
6091 buffer
= bfd_malloc (output_section_size
);
6096 apuinfo_list_init ();
6098 /* Read in the input sections contents. */
6099 for (ibfd
= link_info
->input_bfds
; ibfd
; ibfd
= ibfd
->link_next
)
6101 unsigned long datum
;
6104 asec
= bfd_get_section_by_name (ibfd
, APUINFO_SECTION_NAME
);
6108 length
= asec
->_raw_size
;
6111 error_message
= _("corrupt or empty %s section in %s");
6115 if (bfd_seek (ibfd
, asec
->filepos
, SEEK_SET
) != 0
6116 || (bfd_bread (buffer
+ offset
, length
, ibfd
) != length
))
6118 error_message
= _("unable to read in %s section from %s");
6122 /* Process the contents of the section. */
6123 ptr
= buffer
+ offset
;
6124 error_message
= _("corrupt %s section in %s");
6126 /* Verify the contents of the header. Note - we have to
6127 extract the values this way in order to allow for a
6128 host whose endian-ness is different from the target. */
6129 datum
= bfd_get_32 (ibfd
, ptr
);
6130 if (datum
!= sizeof APUINFO_LABEL
)
6133 datum
= bfd_get_32 (ibfd
, ptr
+ 8);
6137 if (strcmp (ptr
+ 12, APUINFO_LABEL
) != 0)
6140 /* Get the number of bytes used for apuinfo entries. */
6141 datum
= bfd_get_32 (ibfd
, ptr
+ 4);
6142 if (datum
+ 20 != length
)
6145 /* Make sure that we do not run off the end of the section. */
6146 if (offset
+ length
> output_section_size
)
6149 /* Scan the apuinfo section, building a list of apuinfo numbers. */
6150 for (i
= 0; i
< datum
; i
+= 4)
6151 apuinfo_list_add (bfd_get_32 (ibfd
, ptr
+ 20 + i
));
6153 /* Update the offset. */
6157 error_message
= NULL
;
6159 /* Compute the size of the output section. */
6160 num_entries
= apuinfo_list_length ();
6161 output_section_size
= 20 + num_entries
* 4;
6163 asec
= bfd_get_section_by_name (abfd
, APUINFO_SECTION_NAME
);
6165 if (! bfd_set_section_size (abfd
, asec
, output_section_size
))
6167 error_message
= _("warning: unable to set size of %s section in %s");
6173 (*_bfd_error_handler
) (error_message
, APUINFO_SECTION_NAME
,
6174 bfd_archive_filename (ibfd
));
6178 /* Prevent the output section from accumulating the input sections'
6179 contents. We have already stored this in our linked list structure. */
6182 ppc_elf_write_section (bfd
*abfd ATTRIBUTE_UNUSED
,
6184 bfd_byte
*contents ATTRIBUTE_UNUSED
)
6186 return (apuinfo_list_length ()
6187 && strcmp (asec
->name
, APUINFO_SECTION_NAME
) == 0);
6191 /* Finally we can generate the output section. */
6194 ppc_elf_final_write_processing (bfd
*abfd
, bfd_boolean linker ATTRIBUTE_UNUSED
)
6199 unsigned num_entries
;
6200 bfd_size_type length
;
6202 asec
= bfd_get_section_by_name (abfd
, APUINFO_SECTION_NAME
);
6206 if (apuinfo_list_length () == 0)
6209 length
= asec
->_raw_size
;
6213 buffer
= bfd_malloc (length
);
6216 (*_bfd_error_handler
)
6217 (_("failed to allocate space for new APUinfo section."));
6221 /* Create the apuinfo header. */
6222 num_entries
= apuinfo_list_length ();
6223 bfd_put_32 (abfd
, sizeof APUINFO_LABEL
, buffer
);
6224 bfd_put_32 (abfd
, num_entries
* 4, buffer
+ 4);
6225 bfd_put_32 (abfd
, 0x2, buffer
+ 8);
6226 strcpy (buffer
+ 12, APUINFO_LABEL
);
6229 for (i
= 0; i
< num_entries
; i
++)
6231 bfd_put_32 (abfd
, apuinfo_list_element (i
), buffer
+ length
);
6235 if (length
!= asec
->_raw_size
)
6236 (*_bfd_error_handler
) (_("failed to compute new APUinfo section."));
6238 if (! bfd_set_section_contents (abfd
, asec
, buffer
, (file_ptr
) 0, length
))
6239 (*_bfd_error_handler
) (_("failed to install new APUinfo section."));
6243 apuinfo_list_finish ();
6246 /* Add extra PPC sections -- Note, for now, make .sbss2 and
6247 .PPC.EMB.sbss0 a normal section, and not a bss section so
6248 that the linker doesn't crater when trying to make more than
6251 static struct bfd_elf_special_section
const ppc_elf_special_sections
[]=
6253 { ".tags", 0, NULL
, 0,
6254 SHT_ORDERED
, SHF_ALLOC
},
6255 { ".sdata", 0, NULL
, 0,
6256 SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
6257 { ".sbss", 0, NULL
, 0,
6258 SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
},
6259 { ".sdata2", 0, NULL
, 0,
6260 SHT_PROGBITS
, SHF_ALLOC
},
6261 { ".sbss2", 0, NULL
, 0,
6262 SHT_PROGBITS
, SHF_ALLOC
},
6263 { ".PPC.EMB.apuinfo", 0, NULL
, 0,
6265 { ".PPC.EMB.sdata0", 0, NULL
, 0,
6266 SHT_PROGBITS
, SHF_ALLOC
},
6267 { ".PPC.EMB.sbss0", 0, NULL
, 0,
6268 SHT_PROGBITS
, SHF_ALLOC
},
6269 { ".plt", 0, NULL
, 0,
6275 #define TARGET_LITTLE_SYM bfd_elf32_powerpcle_vec
6276 #define TARGET_LITTLE_NAME "elf32-powerpcle"
6277 #define TARGET_BIG_SYM bfd_elf32_powerpc_vec
6278 #define TARGET_BIG_NAME "elf32-powerpc"
6279 #define ELF_ARCH bfd_arch_powerpc
6280 #define ELF_MACHINE_CODE EM_PPC
6281 #ifdef __QNXTARGET__
6282 #define ELF_MAXPAGESIZE 0x1000
6284 #define ELF_MAXPAGESIZE 0x10000
6286 #define elf_info_to_howto ppc_elf_info_to_howto
6288 #ifdef EM_CYGNUS_POWERPC
6289 #define ELF_MACHINE_ALT1 EM_CYGNUS_POWERPC
6293 #define ELF_MACHINE_ALT2 EM_PPC_OLD
6296 #define elf_backend_plt_not_loaded 1
6297 #define elf_backend_got_symbol_offset 4
6298 #define elf_backend_can_gc_sections 1
6299 #define elf_backend_can_refcount 1
6300 #define elf_backend_got_header_size 12
6301 #define elf_backend_plt_header_size PLT_INITIAL_ENTRY_SIZE
6302 #define elf_backend_rela_normal 1
6304 #define bfd_elf32_mkobject ppc_elf_mkobject
6305 #define bfd_elf32_bfd_merge_private_bfd_data ppc_elf_merge_private_bfd_data
6306 #define bfd_elf32_bfd_relax_section ppc_elf_relax_section
6307 #define bfd_elf32_bfd_reloc_type_lookup ppc_elf_reloc_type_lookup
6308 #define bfd_elf32_bfd_set_private_flags ppc_elf_set_private_flags
6309 #define bfd_elf32_bfd_link_hash_table_create ppc_elf_link_hash_table_create
6311 #define elf_backend_object_p ppc_elf_object_p
6312 #define elf_backend_gc_mark_hook ppc_elf_gc_mark_hook
6313 #define elf_backend_gc_sweep_hook ppc_elf_gc_sweep_hook
6314 #define elf_backend_section_from_shdr ppc_elf_section_from_shdr
6315 #define elf_backend_relocate_section ppc_elf_relocate_section
6316 #define elf_backend_create_dynamic_sections ppc_elf_create_dynamic_sections
6317 #define elf_backend_check_relocs ppc_elf_check_relocs
6318 #define elf_backend_copy_indirect_symbol ppc_elf_copy_indirect_symbol
6319 #define elf_backend_adjust_dynamic_symbol ppc_elf_adjust_dynamic_symbol
6320 #define elf_backend_add_symbol_hook ppc_elf_add_symbol_hook
6321 #define elf_backend_size_dynamic_sections ppc_elf_size_dynamic_sections
6322 #define elf_backend_finish_dynamic_symbol ppc_elf_finish_dynamic_symbol
6323 #define elf_backend_finish_dynamic_sections ppc_elf_finish_dynamic_sections
6324 #define elf_backend_fake_sections ppc_elf_fake_sections
6325 #define elf_backend_additional_program_headers ppc_elf_additional_program_headers
6326 #define elf_backend_modify_segment_map ppc_elf_modify_segment_map
6327 #define elf_backend_grok_prstatus ppc_elf_grok_prstatus
6328 #define elf_backend_grok_psinfo ppc_elf_grok_psinfo
6329 #define elf_backend_reloc_type_class ppc_elf_reloc_type_class
6330 #define elf_backend_begin_write_processing ppc_elf_begin_write_processing
6331 #define elf_backend_final_write_processing ppc_elf_final_write_processing
6332 #define elf_backend_write_section ppc_elf_write_section
6333 #define elf_backend_special_sections ppc_elf_special_sections
6335 #include "elf32-target.h"