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 /* The PPC linker needs to keep track of the number of relocs that it
74 decides to copy as dynamic relocs in check_relocs for each symbol.
75 This is so that it can later discard them if they are found to be
76 unnecessary. We store the information in a field extending the
77 regular ELF linker hash table. */
79 struct ppc_elf_dyn_relocs
81 struct ppc_elf_dyn_relocs
*next
;
83 /* The input section of the reloc. */
86 /* Total number of relocs copied for the input section. */
89 /* Number of pc-relative relocs copied for the input section. */
90 bfd_size_type pc_count
;
93 /* PPC ELF linker hash entry. */
95 struct ppc_elf_link_hash_entry
97 struct elf_link_hash_entry elf
;
99 /* Track dynamic relocs copied for this symbol. */
100 struct ppc_elf_dyn_relocs
*dyn_relocs
;
102 /* Contexts in which symbol is used in the GOT (or TOC).
103 TLS_GD .. TLS_TLS bits are or'd into the mask as the
104 corresponding relocs are encountered during check_relocs.
105 tls_optimize clears TLS_GD .. TLS_TPREL when optimizing to
106 indicate the corresponding GOT entry type is not needed. */
107 #define TLS_GD 1 /* GD reloc. */
108 #define TLS_LD 2 /* LD reloc. */
109 #define TLS_TPREL 4 /* TPREL reloc, => IE. */
110 #define TLS_DTPREL 8 /* DTPREL reloc, => LD. */
111 #define TLS_TLS 16 /* Any TLS reloc. */
112 #define TLS_TPRELGD 32 /* TPREL reloc resulting from GD->IE. */
116 #define ppc_elf_hash_entry(ent) ((struct ppc_elf_link_hash_entry *) (ent))
118 /* PPC ELF linker hash table. */
120 struct ppc_elf_link_hash_table
122 struct elf_link_hash_table elf
;
124 /* Short-cuts to get to dynamic linker sections. */
133 elf_linker_section_t
*sdata
;
134 elf_linker_section_t
*sdata2
;
136 /* Short-cut to first output tls section. */
139 /* Shortcut to .__tls_get_addr. */
140 struct elf_link_hash_entry
*tls_get_addr
;
142 /* TLS local dynamic got entry handling. */
144 bfd_signed_vma refcount
;
148 /* Small local sym to section mapping cache. */
149 struct sym_sec_cache sym_sec
;
152 /* Get the PPC ELF linker hash table from a link_info structure. */
154 #define ppc_elf_hash_table(p) \
155 ((struct ppc_elf_link_hash_table *) (p)->hash)
157 /* Create an entry in a PPC ELF linker hash table. */
159 static struct bfd_hash_entry
*
160 ppc_elf_link_hash_newfunc (struct bfd_hash_entry
*entry
,
161 struct bfd_hash_table
*table
,
164 /* Allocate the structure if it has not already been allocated by a
168 entry
= bfd_hash_allocate (table
,
169 sizeof (struct ppc_elf_link_hash_entry
));
174 /* Call the allocation method of the superclass. */
175 entry
= _bfd_elf_link_hash_newfunc (entry
, table
, string
);
178 ppc_elf_hash_entry (entry
)->dyn_relocs
= NULL
;
179 ppc_elf_hash_entry (entry
)->tls_mask
= 0;
185 /* Create a PPC ELF linker hash table. */
187 static struct bfd_link_hash_table
*
188 ppc_elf_link_hash_table_create (bfd
*abfd
)
190 struct ppc_elf_link_hash_table
*ret
;
192 ret
= bfd_malloc (sizeof (struct ppc_elf_link_hash_table
));
196 if (! _bfd_elf_link_hash_table_init (&ret
->elf
, abfd
,
197 ppc_elf_link_hash_newfunc
))
214 ret
->tls_get_addr
= NULL
;
215 ret
->tlsld_got
.refcount
= 0;
216 ret
->sym_sec
.abfd
= NULL
;
218 return &ret
->elf
.root
;
221 /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
222 copying dynamic variables from a shared lib into an app's dynbss
223 section, and instead use a dynamic relocation to point into the
225 #define ELIMINATE_COPY_RELOCS 1
227 /* Copy the extra info we tack onto an elf_link_hash_entry. */
230 ppc_elf_copy_indirect_symbol (struct elf_backend_data
*bed
,
231 struct elf_link_hash_entry
*dir
,
232 struct elf_link_hash_entry
*ind
)
234 struct ppc_elf_link_hash_entry
*edir
, *eind
;
236 edir
= (struct ppc_elf_link_hash_entry
*) dir
;
237 eind
= (struct ppc_elf_link_hash_entry
*) ind
;
239 if (eind
->dyn_relocs
!= NULL
)
241 if (edir
->dyn_relocs
!= NULL
)
243 struct ppc_elf_dyn_relocs
**pp
;
244 struct ppc_elf_dyn_relocs
*p
;
246 if (ind
->root
.type
== bfd_link_hash_indirect
)
249 /* Add reloc counts against the weak sym to the strong sym
250 list. Merge any entries against the same section. */
251 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
; )
253 struct ppc_elf_dyn_relocs
*q
;
255 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
256 if (q
->sec
== p
->sec
)
258 q
->pc_count
+= p
->pc_count
;
259 q
->count
+= p
->count
;
266 *pp
= edir
->dyn_relocs
;
269 edir
->dyn_relocs
= eind
->dyn_relocs
;
270 eind
->dyn_relocs
= NULL
;
273 edir
->tls_mask
|= eind
->tls_mask
;
275 if (ELIMINATE_COPY_RELOCS
276 && ind
->root
.type
!= bfd_link_hash_indirect
277 && (dir
->elf_link_hash_flags
& ELF_LINK_HASH_DYNAMIC_ADJUSTED
) != 0)
278 /* If called to transfer flags for a weakdef during processing
279 of elf_adjust_dynamic_symbol, don't copy ELF_LINK_NON_GOT_REF.
280 We clear it ourselves for ELIMINATE_COPY_RELOCS. */
281 dir
->elf_link_hash_flags
|=
282 (ind
->elf_link_hash_flags
& (ELF_LINK_HASH_REF_DYNAMIC
283 | ELF_LINK_HASH_REF_REGULAR
284 | ELF_LINK_HASH_REF_REGULAR_NONWEAK
));
286 _bfd_elf_link_hash_copy_indirect (bed
, dir
, ind
);
289 static reloc_howto_type
*ppc_elf_howto_table
[R_PPC_max
];
291 static reloc_howto_type ppc_elf_howto_raw
[] = {
292 /* This reloc does nothing. */
293 HOWTO (R_PPC_NONE
, /* type */
295 2, /* size (0 = byte, 1 = short, 2 = long) */
297 FALSE
, /* pc_relative */
299 complain_overflow_bitfield
, /* complain_on_overflow */
300 bfd_elf_generic_reloc
, /* special_function */
301 "R_PPC_NONE", /* name */
302 FALSE
, /* partial_inplace */
305 FALSE
), /* pcrel_offset */
307 /* A standard 32 bit relocation. */
308 HOWTO (R_PPC_ADDR32
, /* type */
310 2, /* size (0 = byte, 1 = short, 2 = long) */
312 FALSE
, /* pc_relative */
314 complain_overflow_bitfield
, /* complain_on_overflow */
315 bfd_elf_generic_reloc
, /* special_function */
316 "R_PPC_ADDR32", /* name */
317 FALSE
, /* partial_inplace */
319 0xffffffff, /* dst_mask */
320 FALSE
), /* pcrel_offset */
322 /* An absolute 26 bit branch; the lower two bits must be zero.
323 FIXME: we don't check that, we just clear them. */
324 HOWTO (R_PPC_ADDR24
, /* type */
326 2, /* size (0 = byte, 1 = short, 2 = long) */
328 FALSE
, /* pc_relative */
330 complain_overflow_bitfield
, /* complain_on_overflow */
331 bfd_elf_generic_reloc
, /* special_function */
332 "R_PPC_ADDR24", /* name */
333 FALSE
, /* partial_inplace */
335 0x3fffffc, /* dst_mask */
336 FALSE
), /* pcrel_offset */
338 /* A standard 16 bit relocation. */
339 HOWTO (R_PPC_ADDR16
, /* type */
341 1, /* size (0 = byte, 1 = short, 2 = long) */
343 FALSE
, /* pc_relative */
345 complain_overflow_bitfield
, /* complain_on_overflow */
346 bfd_elf_generic_reloc
, /* special_function */
347 "R_PPC_ADDR16", /* name */
348 FALSE
, /* partial_inplace */
350 0xffff, /* dst_mask */
351 FALSE
), /* pcrel_offset */
353 /* A 16 bit relocation without overflow. */
354 HOWTO (R_PPC_ADDR16_LO
, /* type */
356 1, /* size (0 = byte, 1 = short, 2 = long) */
358 FALSE
, /* pc_relative */
360 complain_overflow_dont
,/* complain_on_overflow */
361 bfd_elf_generic_reloc
, /* special_function */
362 "R_PPC_ADDR16_LO", /* name */
363 FALSE
, /* partial_inplace */
365 0xffff, /* dst_mask */
366 FALSE
), /* pcrel_offset */
368 /* The high order 16 bits of an address. */
369 HOWTO (R_PPC_ADDR16_HI
, /* type */
371 1, /* size (0 = byte, 1 = short, 2 = long) */
373 FALSE
, /* pc_relative */
375 complain_overflow_dont
, /* complain_on_overflow */
376 bfd_elf_generic_reloc
, /* special_function */
377 "R_PPC_ADDR16_HI", /* name */
378 FALSE
, /* partial_inplace */
380 0xffff, /* dst_mask */
381 FALSE
), /* pcrel_offset */
383 /* The high order 16 bits of an address, plus 1 if the contents of
384 the low 16 bits, treated as a signed number, is negative. */
385 HOWTO (R_PPC_ADDR16_HA
, /* type */
387 1, /* size (0 = byte, 1 = short, 2 = long) */
389 FALSE
, /* pc_relative */
391 complain_overflow_dont
, /* complain_on_overflow */
392 ppc_elf_addr16_ha_reloc
, /* special_function */
393 "R_PPC_ADDR16_HA", /* name */
394 FALSE
, /* partial_inplace */
396 0xffff, /* dst_mask */
397 FALSE
), /* pcrel_offset */
399 /* An absolute 16 bit branch; the lower two bits must be zero.
400 FIXME: we don't check that, we just clear them. */
401 HOWTO (R_PPC_ADDR14
, /* type */
403 2, /* size (0 = byte, 1 = short, 2 = long) */
405 FALSE
, /* pc_relative */
407 complain_overflow_bitfield
, /* complain_on_overflow */
408 bfd_elf_generic_reloc
, /* special_function */
409 "R_PPC_ADDR14", /* name */
410 FALSE
, /* partial_inplace */
412 0xfffc, /* dst_mask */
413 FALSE
), /* pcrel_offset */
415 /* An absolute 16 bit branch, for which bit 10 should be set to
416 indicate that the branch is expected to be taken. The lower two
417 bits must be zero. */
418 HOWTO (R_PPC_ADDR14_BRTAKEN
, /* type */
420 2, /* size (0 = byte, 1 = short, 2 = long) */
422 FALSE
, /* pc_relative */
424 complain_overflow_bitfield
, /* complain_on_overflow */
425 bfd_elf_generic_reloc
, /* special_function */
426 "R_PPC_ADDR14_BRTAKEN",/* name */
427 FALSE
, /* partial_inplace */
429 0xfffc, /* dst_mask */
430 FALSE
), /* pcrel_offset */
432 /* An absolute 16 bit branch, for which bit 10 should be set to
433 indicate that the branch is not expected to be taken. The lower
434 two bits must be zero. */
435 HOWTO (R_PPC_ADDR14_BRNTAKEN
, /* type */
437 2, /* size (0 = byte, 1 = short, 2 = long) */
439 FALSE
, /* pc_relative */
441 complain_overflow_bitfield
, /* complain_on_overflow */
442 bfd_elf_generic_reloc
, /* special_function */
443 "R_PPC_ADDR14_BRNTAKEN",/* name */
444 FALSE
, /* partial_inplace */
446 0xfffc, /* dst_mask */
447 FALSE
), /* pcrel_offset */
449 /* A relative 26 bit branch; the lower two bits must be zero. */
450 HOWTO (R_PPC_REL24
, /* type */
452 2, /* size (0 = byte, 1 = short, 2 = long) */
454 TRUE
, /* pc_relative */
456 complain_overflow_signed
, /* complain_on_overflow */
457 bfd_elf_generic_reloc
, /* special_function */
458 "R_PPC_REL24", /* name */
459 FALSE
, /* partial_inplace */
461 0x3fffffc, /* dst_mask */
462 TRUE
), /* pcrel_offset */
464 /* A relative 16 bit branch; the lower two bits must be zero. */
465 HOWTO (R_PPC_REL14
, /* type */
467 2, /* size (0 = byte, 1 = short, 2 = long) */
469 TRUE
, /* pc_relative */
471 complain_overflow_signed
, /* complain_on_overflow */
472 bfd_elf_generic_reloc
, /* special_function */
473 "R_PPC_REL14", /* name */
474 FALSE
, /* partial_inplace */
476 0xfffc, /* dst_mask */
477 TRUE
), /* pcrel_offset */
479 /* A relative 16 bit branch. Bit 10 should be set to indicate that
480 the branch is expected to be taken. The lower two bits must be
482 HOWTO (R_PPC_REL14_BRTAKEN
, /* type */
484 2, /* size (0 = byte, 1 = short, 2 = long) */
486 TRUE
, /* pc_relative */
488 complain_overflow_signed
, /* complain_on_overflow */
489 bfd_elf_generic_reloc
, /* special_function */
490 "R_PPC_REL14_BRTAKEN", /* name */
491 FALSE
, /* partial_inplace */
493 0xfffc, /* dst_mask */
494 TRUE
), /* pcrel_offset */
496 /* A relative 16 bit branch. Bit 10 should be set to indicate that
497 the branch is not expected to be taken. The lower two bits must
499 HOWTO (R_PPC_REL14_BRNTAKEN
, /* type */
501 2, /* size (0 = byte, 1 = short, 2 = long) */
503 TRUE
, /* pc_relative */
505 complain_overflow_signed
, /* complain_on_overflow */
506 bfd_elf_generic_reloc
, /* special_function */
507 "R_PPC_REL14_BRNTAKEN",/* name */
508 FALSE
, /* partial_inplace */
510 0xfffc, /* dst_mask */
511 TRUE
), /* pcrel_offset */
513 /* Like R_PPC_ADDR16, but referring to the GOT table entry for the
515 HOWTO (R_PPC_GOT16
, /* type */
517 1, /* size (0 = byte, 1 = short, 2 = long) */
519 FALSE
, /* pc_relative */
521 complain_overflow_signed
, /* complain_on_overflow */
522 bfd_elf_generic_reloc
, /* special_function */
523 "R_PPC_GOT16", /* name */
524 FALSE
, /* partial_inplace */
526 0xffff, /* dst_mask */
527 FALSE
), /* pcrel_offset */
529 /* Like R_PPC_ADDR16_LO, but referring to the GOT table entry for
531 HOWTO (R_PPC_GOT16_LO
, /* type */
533 1, /* size (0 = byte, 1 = short, 2 = long) */
535 FALSE
, /* pc_relative */
537 complain_overflow_dont
, /* complain_on_overflow */
538 bfd_elf_generic_reloc
, /* special_function */
539 "R_PPC_GOT16_LO", /* name */
540 FALSE
, /* partial_inplace */
542 0xffff, /* dst_mask */
543 FALSE
), /* pcrel_offset */
545 /* Like R_PPC_ADDR16_HI, but referring to the GOT table entry for
547 HOWTO (R_PPC_GOT16_HI
, /* type */
549 1, /* size (0 = byte, 1 = short, 2 = long) */
551 FALSE
, /* pc_relative */
553 complain_overflow_bitfield
, /* complain_on_overflow */
554 bfd_elf_generic_reloc
, /* special_function */
555 "R_PPC_GOT16_HI", /* name */
556 FALSE
, /* partial_inplace */
558 0xffff, /* dst_mask */
559 FALSE
), /* pcrel_offset */
561 /* Like R_PPC_ADDR16_HA, but referring to the GOT table entry for
563 HOWTO (R_PPC_GOT16_HA
, /* type */
565 1, /* size (0 = byte, 1 = short, 2 = long) */
567 FALSE
, /* pc_relative */
569 complain_overflow_bitfield
, /* complain_on_overflow */
570 ppc_elf_addr16_ha_reloc
, /* special_function */
571 "R_PPC_GOT16_HA", /* name */
572 FALSE
, /* partial_inplace */
574 0xffff, /* dst_mask */
575 FALSE
), /* pcrel_offset */
577 /* Like R_PPC_REL24, but referring to the procedure linkage table
578 entry for the symbol. */
579 HOWTO (R_PPC_PLTREL24
, /* type */
581 2, /* size (0 = byte, 1 = short, 2 = long) */
583 TRUE
, /* pc_relative */
585 complain_overflow_signed
, /* complain_on_overflow */
586 bfd_elf_generic_reloc
, /* special_function */
587 "R_PPC_PLTREL24", /* name */
588 FALSE
, /* partial_inplace */
590 0x3fffffc, /* dst_mask */
591 TRUE
), /* pcrel_offset */
593 /* This is used only by the dynamic linker. The symbol should exist
594 both in the object being run and in some shared library. The
595 dynamic linker copies the data addressed by the symbol from the
596 shared library into the object, because the object being
597 run has to have the data at some particular address. */
598 HOWTO (R_PPC_COPY
, /* type */
600 2, /* size (0 = byte, 1 = short, 2 = long) */
602 FALSE
, /* pc_relative */
604 complain_overflow_bitfield
, /* complain_on_overflow */
605 bfd_elf_generic_reloc
, /* special_function */
606 "R_PPC_COPY", /* name */
607 FALSE
, /* partial_inplace */
610 FALSE
), /* pcrel_offset */
612 /* Like R_PPC_ADDR32, but used when setting global offset table
614 HOWTO (R_PPC_GLOB_DAT
, /* type */
616 2, /* size (0 = byte, 1 = short, 2 = long) */
618 FALSE
, /* pc_relative */
620 complain_overflow_bitfield
, /* complain_on_overflow */
621 bfd_elf_generic_reloc
, /* special_function */
622 "R_PPC_GLOB_DAT", /* name */
623 FALSE
, /* partial_inplace */
625 0xffffffff, /* dst_mask */
626 FALSE
), /* pcrel_offset */
628 /* Marks a procedure linkage table entry for a symbol. */
629 HOWTO (R_PPC_JMP_SLOT
, /* type */
631 2, /* size (0 = byte, 1 = short, 2 = long) */
633 FALSE
, /* pc_relative */
635 complain_overflow_bitfield
, /* complain_on_overflow */
636 bfd_elf_generic_reloc
, /* special_function */
637 "R_PPC_JMP_SLOT", /* name */
638 FALSE
, /* partial_inplace */
641 FALSE
), /* pcrel_offset */
643 /* Used only by the dynamic linker. When the object is run, this
644 longword is set to the load address of the object, plus the
646 HOWTO (R_PPC_RELATIVE
, /* type */
648 2, /* size (0 = byte, 1 = short, 2 = long) */
650 FALSE
, /* pc_relative */
652 complain_overflow_bitfield
, /* complain_on_overflow */
653 bfd_elf_generic_reloc
, /* special_function */
654 "R_PPC_RELATIVE", /* name */
655 FALSE
, /* partial_inplace */
657 0xffffffff, /* dst_mask */
658 FALSE
), /* pcrel_offset */
660 /* Like R_PPC_REL24, but uses the value of the symbol within the
661 object rather than the final value. Normally used for
662 _GLOBAL_OFFSET_TABLE_. */
663 HOWTO (R_PPC_LOCAL24PC
, /* type */
665 2, /* size (0 = byte, 1 = short, 2 = long) */
667 TRUE
, /* pc_relative */
669 complain_overflow_signed
, /* complain_on_overflow */
670 bfd_elf_generic_reloc
, /* special_function */
671 "R_PPC_LOCAL24PC", /* name */
672 FALSE
, /* partial_inplace */
674 0x3fffffc, /* dst_mask */
675 TRUE
), /* pcrel_offset */
677 /* Like R_PPC_ADDR32, but may be unaligned. */
678 HOWTO (R_PPC_UADDR32
, /* type */
680 2, /* size (0 = byte, 1 = short, 2 = long) */
682 FALSE
, /* pc_relative */
684 complain_overflow_bitfield
, /* complain_on_overflow */
685 bfd_elf_generic_reloc
, /* special_function */
686 "R_PPC_UADDR32", /* name */
687 FALSE
, /* partial_inplace */
689 0xffffffff, /* dst_mask */
690 FALSE
), /* pcrel_offset */
692 /* Like R_PPC_ADDR16, but may be unaligned. */
693 HOWTO (R_PPC_UADDR16
, /* type */
695 1, /* size (0 = byte, 1 = short, 2 = long) */
697 FALSE
, /* pc_relative */
699 complain_overflow_bitfield
, /* complain_on_overflow */
700 bfd_elf_generic_reloc
, /* special_function */
701 "R_PPC_UADDR16", /* name */
702 FALSE
, /* partial_inplace */
704 0xffff, /* dst_mask */
705 FALSE
), /* pcrel_offset */
707 /* 32-bit PC relative */
708 HOWTO (R_PPC_REL32
, /* type */
710 2, /* size (0 = byte, 1 = short, 2 = long) */
712 TRUE
, /* pc_relative */
714 complain_overflow_bitfield
, /* complain_on_overflow */
715 bfd_elf_generic_reloc
, /* special_function */
716 "R_PPC_REL32", /* name */
717 FALSE
, /* partial_inplace */
719 0xffffffff, /* dst_mask */
720 TRUE
), /* pcrel_offset */
722 /* 32-bit relocation to the symbol's procedure linkage table.
723 FIXME: not supported. */
724 HOWTO (R_PPC_PLT32
, /* type */
726 2, /* size (0 = byte, 1 = short, 2 = long) */
728 FALSE
, /* pc_relative */
730 complain_overflow_bitfield
, /* complain_on_overflow */
731 bfd_elf_generic_reloc
, /* special_function */
732 "R_PPC_PLT32", /* name */
733 FALSE
, /* partial_inplace */
736 FALSE
), /* pcrel_offset */
738 /* 32-bit PC relative relocation to the symbol's procedure linkage table.
739 FIXME: not supported. */
740 HOWTO (R_PPC_PLTREL32
, /* type */
742 2, /* size (0 = byte, 1 = short, 2 = long) */
744 TRUE
, /* pc_relative */
746 complain_overflow_bitfield
, /* complain_on_overflow */
747 bfd_elf_generic_reloc
, /* special_function */
748 "R_PPC_PLTREL32", /* name */
749 FALSE
, /* partial_inplace */
752 TRUE
), /* pcrel_offset */
754 /* Like R_PPC_ADDR16_LO, but referring to the PLT table entry for
756 HOWTO (R_PPC_PLT16_LO
, /* type */
758 1, /* size (0 = byte, 1 = short, 2 = long) */
760 FALSE
, /* pc_relative */
762 complain_overflow_dont
, /* complain_on_overflow */
763 bfd_elf_generic_reloc
, /* special_function */
764 "R_PPC_PLT16_LO", /* name */
765 FALSE
, /* partial_inplace */
767 0xffff, /* dst_mask */
768 FALSE
), /* pcrel_offset */
770 /* Like R_PPC_ADDR16_HI, but referring to the PLT table entry for
772 HOWTO (R_PPC_PLT16_HI
, /* type */
774 1, /* size (0 = byte, 1 = short, 2 = long) */
776 FALSE
, /* pc_relative */
778 complain_overflow_bitfield
, /* complain_on_overflow */
779 bfd_elf_generic_reloc
, /* special_function */
780 "R_PPC_PLT16_HI", /* name */
781 FALSE
, /* partial_inplace */
783 0xffff, /* dst_mask */
784 FALSE
), /* pcrel_offset */
786 /* Like R_PPC_ADDR16_HA, but referring to the PLT table entry for
788 HOWTO (R_PPC_PLT16_HA
, /* type */
790 1, /* size (0 = byte, 1 = short, 2 = long) */
792 FALSE
, /* pc_relative */
794 complain_overflow_bitfield
, /* complain_on_overflow */
795 ppc_elf_addr16_ha_reloc
, /* special_function */
796 "R_PPC_PLT16_HA", /* name */
797 FALSE
, /* partial_inplace */
799 0xffff, /* dst_mask */
800 FALSE
), /* pcrel_offset */
802 /* A sign-extended 16 bit value relative to _SDA_BASE_, for use with
804 HOWTO (R_PPC_SDAREL16
, /* type */
806 1, /* size (0 = byte, 1 = short, 2 = long) */
808 FALSE
, /* pc_relative */
810 complain_overflow_signed
, /* complain_on_overflow */
811 bfd_elf_generic_reloc
, /* special_function */
812 "R_PPC_SDAREL16", /* name */
813 FALSE
, /* partial_inplace */
815 0xffff, /* dst_mask */
816 FALSE
), /* pcrel_offset */
818 /* 16-bit section relative relocation. */
819 HOWTO (R_PPC_SECTOFF
, /* type */
821 1, /* size (0 = byte, 1 = short, 2 = long) */
823 FALSE
, /* pc_relative */
825 complain_overflow_bitfield
, /* complain_on_overflow */
826 bfd_elf_generic_reloc
, /* special_function */
827 "R_PPC_SECTOFF", /* name */
828 FALSE
, /* partial_inplace */
830 0xffff, /* dst_mask */
831 FALSE
), /* pcrel_offset */
833 /* 16-bit lower half section relative relocation. */
834 HOWTO (R_PPC_SECTOFF_LO
, /* type */
836 1, /* size (0 = byte, 1 = short, 2 = long) */
838 FALSE
, /* pc_relative */
840 complain_overflow_dont
, /* complain_on_overflow */
841 bfd_elf_generic_reloc
, /* special_function */
842 "R_PPC_SECTOFF_LO", /* name */
843 FALSE
, /* partial_inplace */
845 0xffff, /* dst_mask */
846 FALSE
), /* pcrel_offset */
848 /* 16-bit upper half section relative relocation. */
849 HOWTO (R_PPC_SECTOFF_HI
, /* type */
851 1, /* size (0 = byte, 1 = short, 2 = long) */
853 FALSE
, /* pc_relative */
855 complain_overflow_bitfield
, /* complain_on_overflow */
856 bfd_elf_generic_reloc
, /* special_function */
857 "R_PPC_SECTOFF_HI", /* name */
858 FALSE
, /* partial_inplace */
860 0xffff, /* dst_mask */
861 FALSE
), /* pcrel_offset */
863 /* 16-bit upper half adjusted section relative relocation. */
864 HOWTO (R_PPC_SECTOFF_HA
, /* type */
866 1, /* size (0 = byte, 1 = short, 2 = long) */
868 FALSE
, /* pc_relative */
870 complain_overflow_bitfield
, /* complain_on_overflow */
871 ppc_elf_addr16_ha_reloc
, /* special_function */
872 "R_PPC_SECTOFF_HA", /* name */
873 FALSE
, /* partial_inplace */
875 0xffff, /* dst_mask */
876 FALSE
), /* pcrel_offset */
878 /* Marker reloc for TLS. */
881 2, /* size (0 = byte, 1 = short, 2 = long) */
883 FALSE
, /* pc_relative */
885 complain_overflow_dont
, /* complain_on_overflow */
886 bfd_elf_generic_reloc
, /* special_function */
887 "R_PPC_TLS", /* name */
888 FALSE
, /* partial_inplace */
891 FALSE
), /* pcrel_offset */
893 /* Computes the load module index of the load module that contains the
894 definition of its TLS sym. */
895 HOWTO (R_PPC_DTPMOD32
,
897 2, /* size (0 = byte, 1 = short, 2 = long) */
899 FALSE
, /* pc_relative */
901 complain_overflow_dont
, /* complain_on_overflow */
902 ppc_elf_unhandled_reloc
, /* special_function */
903 "R_PPC_DTPMOD32", /* name */
904 FALSE
, /* partial_inplace */
906 0xffffffff, /* dst_mask */
907 FALSE
), /* pcrel_offset */
909 /* Computes a dtv-relative displacement, the difference between the value
910 of sym+add and the base address of the thread-local storage block that
911 contains the definition of sym, minus 0x8000. */
912 HOWTO (R_PPC_DTPREL32
,
914 2, /* size (0 = byte, 1 = short, 2 = long) */
916 FALSE
, /* pc_relative */
918 complain_overflow_dont
, /* complain_on_overflow */
919 ppc_elf_unhandled_reloc
, /* special_function */
920 "R_PPC_DTPREL32", /* name */
921 FALSE
, /* partial_inplace */
923 0xffffffff, /* dst_mask */
924 FALSE
), /* pcrel_offset */
926 /* A 16 bit dtprel reloc. */
927 HOWTO (R_PPC_DTPREL16
,
929 1, /* size (0 = byte, 1 = short, 2 = long) */
931 FALSE
, /* pc_relative */
933 complain_overflow_signed
, /* complain_on_overflow */
934 ppc_elf_unhandled_reloc
, /* special_function */
935 "R_PPC_DTPREL16", /* name */
936 FALSE
, /* partial_inplace */
938 0xffff, /* dst_mask */
939 FALSE
), /* pcrel_offset */
941 /* Like DTPREL16, but no overflow. */
942 HOWTO (R_PPC_DTPREL16_LO
,
944 1, /* size (0 = byte, 1 = short, 2 = long) */
946 FALSE
, /* pc_relative */
948 complain_overflow_dont
, /* complain_on_overflow */
949 ppc_elf_unhandled_reloc
, /* special_function */
950 "R_PPC_DTPREL16_LO", /* name */
951 FALSE
, /* partial_inplace */
953 0xffff, /* dst_mask */
954 FALSE
), /* pcrel_offset */
956 /* Like DTPREL16_LO, but next higher group of 16 bits. */
957 HOWTO (R_PPC_DTPREL16_HI
,
959 1, /* size (0 = byte, 1 = short, 2 = long) */
961 FALSE
, /* pc_relative */
963 complain_overflow_dont
, /* complain_on_overflow */
964 ppc_elf_unhandled_reloc
, /* special_function */
965 "R_PPC_DTPREL16_HI", /* name */
966 FALSE
, /* partial_inplace */
968 0xffff, /* dst_mask */
969 FALSE
), /* pcrel_offset */
971 /* Like DTPREL16_HI, but adjust for low 16 bits. */
972 HOWTO (R_PPC_DTPREL16_HA
,
974 1, /* size (0 = byte, 1 = short, 2 = long) */
976 FALSE
, /* pc_relative */
978 complain_overflow_dont
, /* complain_on_overflow */
979 ppc_elf_unhandled_reloc
, /* special_function */
980 "R_PPC_DTPREL16_HA", /* name */
981 FALSE
, /* partial_inplace */
983 0xffff, /* dst_mask */
984 FALSE
), /* pcrel_offset */
986 /* Computes a tp-relative displacement, the difference between the value of
987 sym+add and the value of the thread pointer (r13). */
988 HOWTO (R_PPC_TPREL32
,
990 2, /* size (0 = byte, 1 = short, 2 = long) */
992 FALSE
, /* pc_relative */
994 complain_overflow_dont
, /* complain_on_overflow */
995 ppc_elf_unhandled_reloc
, /* special_function */
996 "R_PPC_TPREL32", /* name */
997 FALSE
, /* partial_inplace */
999 0xffffffff, /* dst_mask */
1000 FALSE
), /* pcrel_offset */
1002 /* A 16 bit tprel reloc. */
1003 HOWTO (R_PPC_TPREL16
,
1005 1, /* size (0 = byte, 1 = short, 2 = long) */
1007 FALSE
, /* pc_relative */
1009 complain_overflow_signed
, /* complain_on_overflow */
1010 ppc_elf_unhandled_reloc
, /* special_function */
1011 "R_PPC_TPREL16", /* name */
1012 FALSE
, /* partial_inplace */
1014 0xffff, /* dst_mask */
1015 FALSE
), /* pcrel_offset */
1017 /* Like TPREL16, but no overflow. */
1018 HOWTO (R_PPC_TPREL16_LO
,
1020 1, /* size (0 = byte, 1 = short, 2 = long) */
1022 FALSE
, /* pc_relative */
1024 complain_overflow_dont
, /* complain_on_overflow */
1025 ppc_elf_unhandled_reloc
, /* special_function */
1026 "R_PPC_TPREL16_LO", /* name */
1027 FALSE
, /* partial_inplace */
1029 0xffff, /* dst_mask */
1030 FALSE
), /* pcrel_offset */
1032 /* Like TPREL16_LO, but next higher group of 16 bits. */
1033 HOWTO (R_PPC_TPREL16_HI
,
1034 16, /* rightshift */
1035 1, /* size (0 = byte, 1 = short, 2 = long) */
1037 FALSE
, /* pc_relative */
1039 complain_overflow_dont
, /* complain_on_overflow */
1040 ppc_elf_unhandled_reloc
, /* special_function */
1041 "R_PPC_TPREL16_HI", /* name */
1042 FALSE
, /* partial_inplace */
1044 0xffff, /* dst_mask */
1045 FALSE
), /* pcrel_offset */
1047 /* Like TPREL16_HI, but adjust for low 16 bits. */
1048 HOWTO (R_PPC_TPREL16_HA
,
1049 16, /* rightshift */
1050 1, /* size (0 = byte, 1 = short, 2 = long) */
1052 FALSE
, /* pc_relative */
1054 complain_overflow_dont
, /* complain_on_overflow */
1055 ppc_elf_unhandled_reloc
, /* special_function */
1056 "R_PPC_TPREL16_HA", /* name */
1057 FALSE
, /* partial_inplace */
1059 0xffff, /* dst_mask */
1060 FALSE
), /* pcrel_offset */
1062 /* Allocates two contiguous entries in the GOT to hold a tls_index structure,
1063 with values (sym+add)@dtpmod and (sym+add)@dtprel, and computes the offset
1064 to the first entry. */
1065 HOWTO (R_PPC_GOT_TLSGD16
,
1067 1, /* size (0 = byte, 1 = short, 2 = long) */
1069 FALSE
, /* pc_relative */
1071 complain_overflow_signed
, /* complain_on_overflow */
1072 ppc_elf_unhandled_reloc
, /* special_function */
1073 "R_PPC_GOT_TLSGD16", /* name */
1074 FALSE
, /* partial_inplace */
1076 0xffff, /* dst_mask */
1077 FALSE
), /* pcrel_offset */
1079 /* Like GOT_TLSGD16, but no overflow. */
1080 HOWTO (R_PPC_GOT_TLSGD16_LO
,
1082 1, /* size (0 = byte, 1 = short, 2 = long) */
1084 FALSE
, /* pc_relative */
1086 complain_overflow_dont
, /* complain_on_overflow */
1087 ppc_elf_unhandled_reloc
, /* special_function */
1088 "R_PPC_GOT_TLSGD16_LO", /* name */
1089 FALSE
, /* partial_inplace */
1091 0xffff, /* dst_mask */
1092 FALSE
), /* pcrel_offset */
1094 /* Like GOT_TLSGD16_LO, but next higher group of 16 bits. */
1095 HOWTO (R_PPC_GOT_TLSGD16_HI
,
1096 16, /* rightshift */
1097 1, /* size (0 = byte, 1 = short, 2 = long) */
1099 FALSE
, /* pc_relative */
1101 complain_overflow_dont
, /* complain_on_overflow */
1102 ppc_elf_unhandled_reloc
, /* special_function */
1103 "R_PPC_GOT_TLSGD16_HI", /* name */
1104 FALSE
, /* partial_inplace */
1106 0xffff, /* dst_mask */
1107 FALSE
), /* pcrel_offset */
1109 /* Like GOT_TLSGD16_HI, but adjust for low 16 bits. */
1110 HOWTO (R_PPC_GOT_TLSGD16_HA
,
1111 16, /* rightshift */
1112 1, /* size (0 = byte, 1 = short, 2 = long) */
1114 FALSE
, /* pc_relative */
1116 complain_overflow_dont
, /* complain_on_overflow */
1117 ppc_elf_unhandled_reloc
, /* special_function */
1118 "R_PPC_GOT_TLSGD16_HA", /* name */
1119 FALSE
, /* partial_inplace */
1121 0xffff, /* dst_mask */
1122 FALSE
), /* pcrel_offset */
1124 /* Allocates two contiguous entries in the GOT to hold a tls_index structure,
1125 with values (sym+add)@dtpmod and zero, and computes the offset to the
1127 HOWTO (R_PPC_GOT_TLSLD16
,
1129 1, /* size (0 = byte, 1 = short, 2 = long) */
1131 FALSE
, /* pc_relative */
1133 complain_overflow_signed
, /* complain_on_overflow */
1134 ppc_elf_unhandled_reloc
, /* special_function */
1135 "R_PPC_GOT_TLSLD16", /* name */
1136 FALSE
, /* partial_inplace */
1138 0xffff, /* dst_mask */
1139 FALSE
), /* pcrel_offset */
1141 /* Like GOT_TLSLD16, but no overflow. */
1142 HOWTO (R_PPC_GOT_TLSLD16_LO
,
1144 1, /* size (0 = byte, 1 = short, 2 = long) */
1146 FALSE
, /* pc_relative */
1148 complain_overflow_dont
, /* complain_on_overflow */
1149 ppc_elf_unhandled_reloc
, /* special_function */
1150 "R_PPC_GOT_TLSLD16_LO", /* name */
1151 FALSE
, /* partial_inplace */
1153 0xffff, /* dst_mask */
1154 FALSE
), /* pcrel_offset */
1156 /* Like GOT_TLSLD16_LO, but next higher group of 16 bits. */
1157 HOWTO (R_PPC_GOT_TLSLD16_HI
,
1158 16, /* rightshift */
1159 1, /* size (0 = byte, 1 = short, 2 = long) */
1161 FALSE
, /* pc_relative */
1163 complain_overflow_dont
, /* complain_on_overflow */
1164 ppc_elf_unhandled_reloc
, /* special_function */
1165 "R_PPC_GOT_TLSLD16_HI", /* name */
1166 FALSE
, /* partial_inplace */
1168 0xffff, /* dst_mask */
1169 FALSE
), /* pcrel_offset */
1171 /* Like GOT_TLSLD16_HI, but adjust for low 16 bits. */
1172 HOWTO (R_PPC_GOT_TLSLD16_HA
,
1173 16, /* rightshift */
1174 1, /* size (0 = byte, 1 = short, 2 = long) */
1176 FALSE
, /* pc_relative */
1178 complain_overflow_dont
, /* complain_on_overflow */
1179 ppc_elf_unhandled_reloc
, /* special_function */
1180 "R_PPC_GOT_TLSLD16_HA", /* name */
1181 FALSE
, /* partial_inplace */
1183 0xffff, /* dst_mask */
1184 FALSE
), /* pcrel_offset */
1186 /* Allocates an entry in the GOT with value (sym+add)@dtprel, and computes
1187 the offset to the entry. */
1188 HOWTO (R_PPC_GOT_DTPREL16
,
1190 1, /* size (0 = byte, 1 = short, 2 = long) */
1192 FALSE
, /* pc_relative */
1194 complain_overflow_signed
, /* complain_on_overflow */
1195 ppc_elf_unhandled_reloc
, /* special_function */
1196 "R_PPC_GOT_DTPREL16", /* name */
1197 FALSE
, /* partial_inplace */
1199 0xffff, /* dst_mask */
1200 FALSE
), /* pcrel_offset */
1202 /* Like GOT_DTPREL16, but no overflow. */
1203 HOWTO (R_PPC_GOT_DTPREL16_LO
,
1205 1, /* size (0 = byte, 1 = short, 2 = long) */
1207 FALSE
, /* pc_relative */
1209 complain_overflow_dont
, /* complain_on_overflow */
1210 ppc_elf_unhandled_reloc
, /* special_function */
1211 "R_PPC_GOT_DTPREL16_LO", /* name */
1212 FALSE
, /* partial_inplace */
1214 0xffff, /* dst_mask */
1215 FALSE
), /* pcrel_offset */
1217 /* Like GOT_DTPREL16_LO, but next higher group of 16 bits. */
1218 HOWTO (R_PPC_GOT_DTPREL16_HI
,
1219 16, /* rightshift */
1220 1, /* size (0 = byte, 1 = short, 2 = long) */
1222 FALSE
, /* pc_relative */
1224 complain_overflow_dont
, /* complain_on_overflow */
1225 ppc_elf_unhandled_reloc
, /* special_function */
1226 "R_PPC_GOT_DTPREL16_HI", /* name */
1227 FALSE
, /* partial_inplace */
1229 0xffff, /* dst_mask */
1230 FALSE
), /* pcrel_offset */
1232 /* Like GOT_DTPREL16_HI, but adjust for low 16 bits. */
1233 HOWTO (R_PPC_GOT_DTPREL16_HA
,
1234 16, /* rightshift */
1235 1, /* size (0 = byte, 1 = short, 2 = long) */
1237 FALSE
, /* pc_relative */
1239 complain_overflow_dont
, /* complain_on_overflow */
1240 ppc_elf_unhandled_reloc
, /* special_function */
1241 "R_PPC_GOT_DTPREL16_HA", /* name */
1242 FALSE
, /* partial_inplace */
1244 0xffff, /* dst_mask */
1245 FALSE
), /* pcrel_offset */
1247 /* Allocates an entry in the GOT with value (sym+add)@tprel, and computes the
1248 offset to the entry. */
1249 HOWTO (R_PPC_GOT_TPREL16
,
1251 1, /* size (0 = byte, 1 = short, 2 = long) */
1253 FALSE
, /* pc_relative */
1255 complain_overflow_signed
, /* complain_on_overflow */
1256 ppc_elf_unhandled_reloc
, /* special_function */
1257 "R_PPC_GOT_TPREL16", /* name */
1258 FALSE
, /* partial_inplace */
1260 0xffff, /* dst_mask */
1261 FALSE
), /* pcrel_offset */
1263 /* Like GOT_TPREL16, but no overflow. */
1264 HOWTO (R_PPC_GOT_TPREL16_LO
,
1266 1, /* size (0 = byte, 1 = short, 2 = long) */
1268 FALSE
, /* pc_relative */
1270 complain_overflow_dont
, /* complain_on_overflow */
1271 ppc_elf_unhandled_reloc
, /* special_function */
1272 "R_PPC_GOT_TPREL16_LO", /* name */
1273 FALSE
, /* partial_inplace */
1275 0xffff, /* dst_mask */
1276 FALSE
), /* pcrel_offset */
1278 /* Like GOT_TPREL16_LO, but next higher group of 16 bits. */
1279 HOWTO (R_PPC_GOT_TPREL16_HI
,
1280 16, /* rightshift */
1281 1, /* size (0 = byte, 1 = short, 2 = long) */
1283 FALSE
, /* pc_relative */
1285 complain_overflow_dont
, /* complain_on_overflow */
1286 ppc_elf_unhandled_reloc
, /* special_function */
1287 "R_PPC_GOT_TPREL16_HI", /* name */
1288 FALSE
, /* partial_inplace */
1290 0xffff, /* dst_mask */
1291 FALSE
), /* pcrel_offset */
1293 /* Like GOT_TPREL16_HI, but adjust for low 16 bits. */
1294 HOWTO (R_PPC_GOT_TPREL16_HA
,
1295 16, /* rightshift */
1296 1, /* size (0 = byte, 1 = short, 2 = long) */
1298 FALSE
, /* pc_relative */
1300 complain_overflow_dont
, /* complain_on_overflow */
1301 ppc_elf_unhandled_reloc
, /* special_function */
1302 "R_PPC_GOT_TPREL16_HA", /* name */
1303 FALSE
, /* partial_inplace */
1305 0xffff, /* dst_mask */
1306 FALSE
), /* pcrel_offset */
1308 /* The remaining relocs are from the Embedded ELF ABI, and are not
1309 in the SVR4 ELF ABI. */
1311 /* 32 bit value resulting from the addend minus the symbol. */
1312 HOWTO (R_PPC_EMB_NADDR32
, /* type */
1314 2, /* size (0 = byte, 1 = short, 2 = long) */
1316 FALSE
, /* pc_relative */
1318 complain_overflow_bitfield
, /* complain_on_overflow */
1319 bfd_elf_generic_reloc
, /* special_function */
1320 "R_PPC_EMB_NADDR32", /* name */
1321 FALSE
, /* partial_inplace */
1323 0xffffffff, /* dst_mask */
1324 FALSE
), /* pcrel_offset */
1326 /* 16 bit value resulting from the addend minus the symbol. */
1327 HOWTO (R_PPC_EMB_NADDR16
, /* type */
1329 1, /* size (0 = byte, 1 = short, 2 = long) */
1331 FALSE
, /* pc_relative */
1333 complain_overflow_bitfield
, /* complain_on_overflow */
1334 bfd_elf_generic_reloc
, /* special_function */
1335 "R_PPC_EMB_NADDR16", /* name */
1336 FALSE
, /* partial_inplace */
1338 0xffff, /* dst_mask */
1339 FALSE
), /* pcrel_offset */
1341 /* 16 bit value resulting from the addend minus the symbol. */
1342 HOWTO (R_PPC_EMB_NADDR16_LO
, /* type */
1344 1, /* size (0 = byte, 1 = short, 2 = long) */
1346 FALSE
, /* pc_relative */
1348 complain_overflow_dont
,/* complain_on_overflow */
1349 bfd_elf_generic_reloc
, /* special_function */
1350 "R_PPC_EMB_ADDR16_LO", /* name */
1351 FALSE
, /* partial_inplace */
1353 0xffff, /* dst_mask */
1354 FALSE
), /* pcrel_offset */
1356 /* The high order 16 bits of the addend minus the symbol. */
1357 HOWTO (R_PPC_EMB_NADDR16_HI
, /* type */
1358 16, /* rightshift */
1359 1, /* size (0 = byte, 1 = short, 2 = long) */
1361 FALSE
, /* pc_relative */
1363 complain_overflow_dont
, /* complain_on_overflow */
1364 bfd_elf_generic_reloc
, /* special_function */
1365 "R_PPC_EMB_NADDR16_HI", /* name */
1366 FALSE
, /* partial_inplace */
1368 0xffff, /* dst_mask */
1369 FALSE
), /* pcrel_offset */
1371 /* The high order 16 bits of the result of the addend minus the address,
1372 plus 1 if the contents of the low 16 bits, treated as a signed number,
1374 HOWTO (R_PPC_EMB_NADDR16_HA
, /* type */
1375 16, /* rightshift */
1376 1, /* size (0 = byte, 1 = short, 2 = long) */
1378 FALSE
, /* pc_relative */
1380 complain_overflow_dont
, /* complain_on_overflow */
1381 ppc_elf_addr16_ha_reloc
, /* special_function */
1382 "R_PPC_EMB_NADDR16_HA", /* name */
1383 FALSE
, /* partial_inplace */
1385 0xffff, /* dst_mask */
1386 FALSE
), /* pcrel_offset */
1388 /* 16 bit value resulting from allocating a 4 byte word to hold an
1389 address in the .sdata section, and returning the offset from
1390 _SDA_BASE_ for that relocation. */
1391 HOWTO (R_PPC_EMB_SDAI16
, /* type */
1393 1, /* size (0 = byte, 1 = short, 2 = long) */
1395 FALSE
, /* pc_relative */
1397 complain_overflow_bitfield
, /* complain_on_overflow */
1398 bfd_elf_generic_reloc
, /* special_function */
1399 "R_PPC_EMB_SDAI16", /* name */
1400 FALSE
, /* partial_inplace */
1402 0xffff, /* dst_mask */
1403 FALSE
), /* pcrel_offset */
1405 /* 16 bit value resulting from allocating a 4 byte word to hold an
1406 address in the .sdata2 section, and returning the offset from
1407 _SDA2_BASE_ for that relocation. */
1408 HOWTO (R_PPC_EMB_SDA2I16
, /* type */
1410 1, /* size (0 = byte, 1 = short, 2 = long) */
1412 FALSE
, /* pc_relative */
1414 complain_overflow_bitfield
, /* complain_on_overflow */
1415 bfd_elf_generic_reloc
, /* special_function */
1416 "R_PPC_EMB_SDA2I16", /* name */
1417 FALSE
, /* partial_inplace */
1419 0xffff, /* dst_mask */
1420 FALSE
), /* pcrel_offset */
1422 /* A sign-extended 16 bit value relative to _SDA2_BASE_, for use with
1423 small data items. */
1424 HOWTO (R_PPC_EMB_SDA2REL
, /* type */
1426 1, /* size (0 = byte, 1 = short, 2 = long) */
1428 FALSE
, /* pc_relative */
1430 complain_overflow_signed
, /* complain_on_overflow */
1431 bfd_elf_generic_reloc
, /* special_function */
1432 "R_PPC_EMB_SDA2REL", /* name */
1433 FALSE
, /* partial_inplace */
1435 0xffff, /* dst_mask */
1436 FALSE
), /* pcrel_offset */
1438 /* Relocate against either _SDA_BASE_ or _SDA2_BASE_, filling in the 16 bit
1439 signed offset from the appropriate base, and filling in the register
1440 field with the appropriate register (0, 2, or 13). */
1441 HOWTO (R_PPC_EMB_SDA21
, /* type */
1443 2, /* size (0 = byte, 1 = short, 2 = long) */
1445 FALSE
, /* pc_relative */
1447 complain_overflow_signed
, /* complain_on_overflow */
1448 bfd_elf_generic_reloc
, /* special_function */
1449 "R_PPC_EMB_SDA21", /* name */
1450 FALSE
, /* partial_inplace */
1452 0xffff, /* dst_mask */
1453 FALSE
), /* pcrel_offset */
1455 /* Relocation not handled: R_PPC_EMB_MRKREF */
1456 /* Relocation not handled: R_PPC_EMB_RELSEC16 */
1457 /* Relocation not handled: R_PPC_EMB_RELST_LO */
1458 /* Relocation not handled: R_PPC_EMB_RELST_HI */
1459 /* Relocation not handled: R_PPC_EMB_RELST_HA */
1460 /* Relocation not handled: R_PPC_EMB_BIT_FLD */
1462 /* PC relative relocation against either _SDA_BASE_ or _SDA2_BASE_, filling
1463 in the 16 bit signed offset from the appropriate base, and filling in the
1464 register field with the appropriate register (0, 2, or 13). */
1465 HOWTO (R_PPC_EMB_RELSDA
, /* type */
1467 1, /* size (0 = byte, 1 = short, 2 = long) */
1469 TRUE
, /* pc_relative */
1471 complain_overflow_signed
, /* complain_on_overflow */
1472 bfd_elf_generic_reloc
, /* special_function */
1473 "R_PPC_EMB_RELSDA", /* name */
1474 FALSE
, /* partial_inplace */
1476 0xffff, /* dst_mask */
1477 FALSE
), /* pcrel_offset */
1479 /* GNU extension to record C++ vtable hierarchy. */
1480 HOWTO (R_PPC_GNU_VTINHERIT
, /* type */
1482 0, /* size (0 = byte, 1 = short, 2 = long) */
1484 FALSE
, /* pc_relative */
1486 complain_overflow_dont
, /* complain_on_overflow */
1487 NULL
, /* special_function */
1488 "R_PPC_GNU_VTINHERIT", /* name */
1489 FALSE
, /* partial_inplace */
1492 FALSE
), /* pcrel_offset */
1494 /* GNU extension to record C++ vtable member usage. */
1495 HOWTO (R_PPC_GNU_VTENTRY
, /* type */
1497 0, /* size (0 = byte, 1 = short, 2 = long) */
1499 FALSE
, /* pc_relative */
1501 complain_overflow_dont
, /* complain_on_overflow */
1502 NULL
, /* special_function */
1503 "R_PPC_GNU_VTENTRY", /* name */
1504 FALSE
, /* partial_inplace */
1507 FALSE
), /* pcrel_offset */
1509 /* Phony reloc to handle AIX style TOC entries. */
1510 HOWTO (R_PPC_TOC16
, /* type */
1512 1, /* size (0 = byte, 1 = short, 2 = long) */
1514 FALSE
, /* pc_relative */
1516 complain_overflow_signed
, /* complain_on_overflow */
1517 bfd_elf_generic_reloc
, /* special_function */
1518 "R_PPC_TOC16", /* name */
1519 FALSE
, /* partial_inplace */
1521 0xffff, /* dst_mask */
1522 FALSE
), /* pcrel_offset */
1525 /* Initialize the ppc_elf_howto_table, so that linear accesses can be done. */
1528 ppc_elf_howto_init (void)
1530 unsigned int i
, type
;
1533 i
< sizeof (ppc_elf_howto_raw
) / sizeof (ppc_elf_howto_raw
[0]);
1536 type
= ppc_elf_howto_raw
[i
].type
;
1537 if (type
>= (sizeof (ppc_elf_howto_table
)
1538 / sizeof (ppc_elf_howto_table
[0])))
1540 ppc_elf_howto_table
[type
] = &ppc_elf_howto_raw
[i
];
1544 /* This function handles relaxing for the PPC with option --mpc860c0[=<n>].
1546 The MPC860, revision C0 or earlier contains a bug in the die.
1547 If all of the following conditions are true, the next instruction
1548 to be executed *may* be treated as a no-op.
1549 1/ A forward branch is executed.
1550 2/ The branch is predicted as not taken.
1551 3/ The branch is taken.
1552 4/ The branch is located in the last 5 words of a page.
1553 (The EOP limit is 5 by default but may be specified as any value
1556 Our software solution is to detect these problematic branches in a
1557 linker pass and modify them as follows:
1558 1/ Unconditional branches - Since these are always predicted taken,
1559 there is no problem and no action is required.
1560 2/ Conditional backward branches - No problem, no action required.
1561 3/ Conditional forward branches - Ensure that the "inverse prediction
1562 bit" is set (ensure it is predicted taken).
1563 4/ Conditional register branches - Ensure that the "y bit" is set
1564 (ensure it is predicted taken). */
1566 /* Sort sections by address. */
1569 ppc_elf_sort_rela (const void *arg1
, const void *arg2
)
1571 const Elf_Internal_Rela
* const *rela1
= arg1
;
1572 const Elf_Internal_Rela
* const *rela2
= arg2
;
1574 /* Sort by offset. */
1575 return ((*rela1
)->r_offset
- (*rela2
)->r_offset
);
1579 ppc_elf_relax_section (bfd
*abfd
,
1581 struct bfd_link_info
*link_info
,
1584 #define PAGESIZE 0x1000
1586 bfd_byte
*contents
= NULL
;
1587 bfd_byte
*free_contents
= NULL
;
1588 Elf_Internal_Rela
*internal_relocs
= NULL
;
1589 Elf_Internal_Rela
*free_relocs
= NULL
;
1590 Elf_Internal_Rela
**rela_comb
= NULL
;
1591 int comb_curr
, comb_count
;
1593 /* We never have to do this more than once per input section. */
1596 /* If needed, initialize this section's cooked size. */
1597 if (isec
->_cooked_size
== 0)
1598 isec
->_cooked_size
= isec
->_raw_size
;
1600 /* We're only interested in text sections which overlap the
1601 troublesome area at the end of a page. */
1602 if (link_info
->mpc860c0
&& (isec
->flags
& SEC_CODE
) && isec
->_cooked_size
)
1604 bfd_vma dot
, end_page
, end_section
;
1605 bfd_boolean section_modified
;
1607 /* Get the section contents. */
1608 /* Get cached copy if it exists. */
1609 if (elf_section_data (isec
)->this_hdr
.contents
!= NULL
)
1610 contents
= elf_section_data (isec
)->this_hdr
.contents
;
1613 /* Go get them off disk. */
1614 contents
= bfd_malloc (isec
->_raw_size
);
1615 if (contents
== NULL
)
1617 free_contents
= contents
;
1619 if (! bfd_get_section_contents (abfd
, isec
, contents
,
1620 (file_ptr
) 0, isec
->_raw_size
))
1626 if (isec
->reloc_count
)
1631 /* Get a copy of the native relocations. */
1633 = _bfd_elf_link_read_relocs (abfd
, isec
, NULL
, NULL
,
1634 link_info
->keep_memory
);
1635 if (internal_relocs
== NULL
)
1637 if (! link_info
->keep_memory
)
1638 free_relocs
= internal_relocs
;
1640 /* Setup a faster access method for the reloc info we need. */
1641 amt
= isec
->reloc_count
;
1642 amt
*= sizeof (Elf_Internal_Rela
*);
1643 rela_comb
= bfd_malloc (amt
);
1644 if (rela_comb
== NULL
)
1646 for (n
= 0; n
< isec
->reloc_count
; ++n
)
1648 enum elf_ppc_reloc_type r_type
;
1650 r_type
= ELF32_R_TYPE (internal_relocs
[n
].r_info
);
1651 if (r_type
>= R_PPC_max
)
1654 /* Prologue constants are sometimes present in the ".text"
1655 sections and they can be identified by their associated
1656 relocation. We don't want to process those words and
1657 some others which can also be identified by their
1658 relocations. However, not all conditional branches will
1659 have a relocation so we will only ignore words that
1660 1) have a reloc, and 2) the reloc is not applicable to a
1661 conditional branch. The array rela_comb is built here
1662 for use in the EOP scan loop. */
1665 case R_PPC_ADDR14_BRNTAKEN
:
1667 case R_PPC_REL14_BRNTAKEN
:
1668 /* We should check the instruction. */
1671 /* The word is not a conditional branch - ignore it. */
1672 rela_comb
[comb_count
++] = &internal_relocs
[n
];
1677 qsort (rela_comb
, (size_t) comb_count
, sizeof (int),
1681 /* Enumerate each EOP region that overlaps this section. */
1682 end_section
= isec
->vma
+ isec
->_cooked_size
;
1683 dot
= end_page
= (isec
->vma
| (PAGESIZE
- 1)) + 1;
1684 dot
-= link_info
->mpc860c0
;
1685 section_modified
= FALSE
;
1686 /* Increment the start position if this section begins in the
1687 middle of its first EOP region. */
1688 if (dot
< isec
->vma
)
1692 dot
+= PAGESIZE
, end_page
+= PAGESIZE
)
1694 /* Check each word in this EOP region. */
1695 for (; dot
< end_page
; dot
+= 4)
1697 bfd_vma isec_offset
;
1699 bfd_boolean skip
, modified
;
1701 /* Don't process this word if there is a relocation for it
1702 and the relocation indicates the word is not a
1703 conditional branch. */
1705 isec_offset
= dot
- isec
->vma
;
1706 for (; comb_curr
<comb_count
; ++comb_curr
)
1710 r_offset
= rela_comb
[comb_curr
]->r_offset
;
1711 if (r_offset
>= isec_offset
)
1713 if (r_offset
== isec_offset
) skip
= TRUE
;
1719 /* Check the current word for a problematic conditional
1721 #define BO0(insn) ((insn) & 0x02000000)
1722 #define BO2(insn) ((insn) & 0x00800000)
1723 #define BO4(insn) ((insn) & 0x00200000)
1724 insn
= (unsigned long) bfd_get_32 (abfd
, contents
+ isec_offset
);
1726 if ((insn
& 0xFc000000) == 0x40000000)
1728 /* Instruction is BCx */
1729 if ((!BO0(insn
) || !BO2(insn
)) && !BO4(insn
))
1733 /* This branch is predicted as "normal".
1734 If this is a forward branch, it is problematic. */
1735 target
= insn
& 0x0000Fffc;
1736 target
= (target
^ 0x8000) - 0x8000;
1737 if ((insn
& 0x00000002) == 0)
1738 /* Convert to abs. */
1742 /* Set the prediction bit. */
1748 else if ((insn
& 0xFc00Fffe) == 0x4c000420)
1750 /* Instruction is BCCTRx. */
1751 if ((!BO0(insn
) || !BO2(insn
)) && !BO4(insn
))
1753 /* This branch is predicted as not-taken.
1754 If this is a forward branch, it is problematic.
1755 Since we can't tell statically if it will branch
1756 forward, always set the prediction bit. */
1761 else if ((insn
& 0xFc00Fffe) == 0x4c000020)
1763 /* Instruction is BCLRx */
1764 if ((!BO0(insn
) || !BO2(insn
)) && !BO4(insn
))
1766 /* This branch is predicted as not-taken.
1767 If this is a forward branch, it is problematic.
1768 Since we can't tell statically if it will branch
1769 forward, always set the prediction bit. */
1779 bfd_put_32 (abfd
, insn
, contents
+ isec_offset
);
1780 section_modified
= TRUE
;
1784 if (section_modified
)
1786 elf_section_data (isec
)->this_hdr
.contents
= contents
;
1787 free_contents
= NULL
;
1791 if (rela_comb
!= NULL
)
1797 if (free_relocs
!= NULL
)
1803 if (free_contents
!= NULL
)
1805 if (! link_info
->keep_memory
)
1806 free (free_contents
);
1809 /* Cache the section contents for elf_link_input_bfd. */
1810 elf_section_data (isec
)->this_hdr
.contents
= contents
;
1812 free_contents
= NULL
;
1818 if (rela_comb
!= NULL
)
1820 if (free_relocs
!= NULL
)
1822 if (free_contents
!= NULL
)
1823 free (free_contents
);
1827 static reloc_howto_type
*
1828 ppc_elf_reloc_type_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
1829 bfd_reloc_code_real_type code
)
1831 enum elf_ppc_reloc_type r
;
1833 /* Initialize howto table if not already done. */
1834 if (!ppc_elf_howto_table
[R_PPC_ADDR32
])
1835 ppc_elf_howto_init ();
1842 case BFD_RELOC_NONE
: r
= R_PPC_NONE
; break;
1843 case BFD_RELOC_32
: r
= R_PPC_ADDR32
; break;
1844 case BFD_RELOC_PPC_BA26
: r
= R_PPC_ADDR24
; break;
1845 case BFD_RELOC_16
: r
= R_PPC_ADDR16
; break;
1846 case BFD_RELOC_LO16
: r
= R_PPC_ADDR16_LO
; break;
1847 case BFD_RELOC_HI16
: r
= R_PPC_ADDR16_HI
; break;
1848 case BFD_RELOC_HI16_S
: r
= R_PPC_ADDR16_HA
; break;
1849 case BFD_RELOC_PPC_BA16
: r
= R_PPC_ADDR14
; break;
1850 case BFD_RELOC_PPC_BA16_BRTAKEN
: r
= R_PPC_ADDR14_BRTAKEN
; break;
1851 case BFD_RELOC_PPC_BA16_BRNTAKEN
: r
= R_PPC_ADDR14_BRNTAKEN
; break;
1852 case BFD_RELOC_PPC_B26
: r
= R_PPC_REL24
; break;
1853 case BFD_RELOC_PPC_B16
: r
= R_PPC_REL14
; break;
1854 case BFD_RELOC_PPC_B16_BRTAKEN
: r
= R_PPC_REL14_BRTAKEN
; break;
1855 case BFD_RELOC_PPC_B16_BRNTAKEN
: r
= R_PPC_REL14_BRNTAKEN
; break;
1856 case BFD_RELOC_16_GOTOFF
: r
= R_PPC_GOT16
; break;
1857 case BFD_RELOC_LO16_GOTOFF
: r
= R_PPC_GOT16_LO
; break;
1858 case BFD_RELOC_HI16_GOTOFF
: r
= R_PPC_GOT16_HI
; break;
1859 case BFD_RELOC_HI16_S_GOTOFF
: r
= R_PPC_GOT16_HA
; break;
1860 case BFD_RELOC_24_PLT_PCREL
: r
= R_PPC_PLTREL24
; break;
1861 case BFD_RELOC_PPC_COPY
: r
= R_PPC_COPY
; break;
1862 case BFD_RELOC_PPC_GLOB_DAT
: r
= R_PPC_GLOB_DAT
; break;
1863 case BFD_RELOC_PPC_LOCAL24PC
: r
= R_PPC_LOCAL24PC
; break;
1864 case BFD_RELOC_32_PCREL
: r
= R_PPC_REL32
; break;
1865 case BFD_RELOC_32_PLTOFF
: r
= R_PPC_PLT32
; break;
1866 case BFD_RELOC_32_PLT_PCREL
: r
= R_PPC_PLTREL32
; break;
1867 case BFD_RELOC_LO16_PLTOFF
: r
= R_PPC_PLT16_LO
; break;
1868 case BFD_RELOC_HI16_PLTOFF
: r
= R_PPC_PLT16_HI
; break;
1869 case BFD_RELOC_HI16_S_PLTOFF
: r
= R_PPC_PLT16_HA
; break;
1870 case BFD_RELOC_GPREL16
: r
= R_PPC_SDAREL16
; break;
1871 case BFD_RELOC_16_BASEREL
: r
= R_PPC_SECTOFF
; break;
1872 case BFD_RELOC_LO16_BASEREL
: r
= R_PPC_SECTOFF_LO
; break;
1873 case BFD_RELOC_HI16_BASEREL
: r
= R_PPC_SECTOFF_HI
; break;
1874 case BFD_RELOC_HI16_S_BASEREL
: r
= R_PPC_SECTOFF_HA
; break;
1875 case BFD_RELOC_CTOR
: r
= R_PPC_ADDR32
; break;
1876 case BFD_RELOC_PPC_TOC16
: r
= R_PPC_TOC16
; break;
1877 case BFD_RELOC_PPC_TLS
: r
= R_PPC_TLS
; break;
1878 case BFD_RELOC_PPC_DTPMOD
: r
= R_PPC_DTPMOD32
; break;
1879 case BFD_RELOC_PPC_TPREL16
: r
= R_PPC_TPREL16
; break;
1880 case BFD_RELOC_PPC_TPREL16_LO
: r
= R_PPC_TPREL16_LO
; break;
1881 case BFD_RELOC_PPC_TPREL16_HI
: r
= R_PPC_TPREL16_HI
; break;
1882 case BFD_RELOC_PPC_TPREL16_HA
: r
= R_PPC_TPREL16_HA
; break;
1883 case BFD_RELOC_PPC_TPREL
: r
= R_PPC_TPREL32
; break;
1884 case BFD_RELOC_PPC_DTPREL16
: r
= R_PPC_DTPREL16
; break;
1885 case BFD_RELOC_PPC_DTPREL16_LO
: r
= R_PPC_DTPREL16_LO
; break;
1886 case BFD_RELOC_PPC_DTPREL16_HI
: r
= R_PPC_DTPREL16_HI
; break;
1887 case BFD_RELOC_PPC_DTPREL16_HA
: r
= R_PPC_DTPREL16_HA
; break;
1888 case BFD_RELOC_PPC_DTPREL
: r
= R_PPC_DTPREL32
; break;
1889 case BFD_RELOC_PPC_GOT_TLSGD16
: r
= R_PPC_GOT_TLSGD16
; break;
1890 case BFD_RELOC_PPC_GOT_TLSGD16_LO
: r
= R_PPC_GOT_TLSGD16_LO
; break;
1891 case BFD_RELOC_PPC_GOT_TLSGD16_HI
: r
= R_PPC_GOT_TLSGD16_HI
; break;
1892 case BFD_RELOC_PPC_GOT_TLSGD16_HA
: r
= R_PPC_GOT_TLSGD16_HA
; break;
1893 case BFD_RELOC_PPC_GOT_TLSLD16
: r
= R_PPC_GOT_TLSLD16
; break;
1894 case BFD_RELOC_PPC_GOT_TLSLD16_LO
: r
= R_PPC_GOT_TLSLD16_LO
; break;
1895 case BFD_RELOC_PPC_GOT_TLSLD16_HI
: r
= R_PPC_GOT_TLSLD16_HI
; break;
1896 case BFD_RELOC_PPC_GOT_TLSLD16_HA
: r
= R_PPC_GOT_TLSLD16_HA
; break;
1897 case BFD_RELOC_PPC_GOT_TPREL16
: r
= R_PPC_GOT_TPREL16
; break;
1898 case BFD_RELOC_PPC_GOT_TPREL16_LO
: r
= R_PPC_GOT_TPREL16_LO
; break;
1899 case BFD_RELOC_PPC_GOT_TPREL16_HI
: r
= R_PPC_GOT_TPREL16_HI
; break;
1900 case BFD_RELOC_PPC_GOT_TPREL16_HA
: r
= R_PPC_GOT_TPREL16_HA
; break;
1901 case BFD_RELOC_PPC_GOT_DTPREL16
: r
= R_PPC_GOT_DTPREL16
; break;
1902 case BFD_RELOC_PPC_GOT_DTPREL16_LO
: r
= R_PPC_GOT_DTPREL16_LO
; break;
1903 case BFD_RELOC_PPC_GOT_DTPREL16_HI
: r
= R_PPC_GOT_DTPREL16_HI
; break;
1904 case BFD_RELOC_PPC_GOT_DTPREL16_HA
: r
= R_PPC_GOT_DTPREL16_HA
; break;
1905 case BFD_RELOC_PPC_EMB_NADDR32
: r
= R_PPC_EMB_NADDR32
; break;
1906 case BFD_RELOC_PPC_EMB_NADDR16
: r
= R_PPC_EMB_NADDR16
; break;
1907 case BFD_RELOC_PPC_EMB_NADDR16_LO
: r
= R_PPC_EMB_NADDR16_LO
; break;
1908 case BFD_RELOC_PPC_EMB_NADDR16_HI
: r
= R_PPC_EMB_NADDR16_HI
; break;
1909 case BFD_RELOC_PPC_EMB_NADDR16_HA
: r
= R_PPC_EMB_NADDR16_HA
; break;
1910 case BFD_RELOC_PPC_EMB_SDAI16
: r
= R_PPC_EMB_SDAI16
; break;
1911 case BFD_RELOC_PPC_EMB_SDA2I16
: r
= R_PPC_EMB_SDA2I16
; break;
1912 case BFD_RELOC_PPC_EMB_SDA2REL
: r
= R_PPC_EMB_SDA2REL
; break;
1913 case BFD_RELOC_PPC_EMB_SDA21
: r
= R_PPC_EMB_SDA21
; break;
1914 case BFD_RELOC_PPC_EMB_MRKREF
: r
= R_PPC_EMB_MRKREF
; break;
1915 case BFD_RELOC_PPC_EMB_RELSEC16
: r
= R_PPC_EMB_RELSEC16
; break;
1916 case BFD_RELOC_PPC_EMB_RELST_LO
: r
= R_PPC_EMB_RELST_LO
; break;
1917 case BFD_RELOC_PPC_EMB_RELST_HI
: r
= R_PPC_EMB_RELST_HI
; break;
1918 case BFD_RELOC_PPC_EMB_RELST_HA
: r
= R_PPC_EMB_RELST_HA
; break;
1919 case BFD_RELOC_PPC_EMB_BIT_FLD
: r
= R_PPC_EMB_BIT_FLD
; break;
1920 case BFD_RELOC_PPC_EMB_RELSDA
: r
= R_PPC_EMB_RELSDA
; break;
1921 case BFD_RELOC_VTABLE_INHERIT
: r
= R_PPC_GNU_VTINHERIT
; break;
1922 case BFD_RELOC_VTABLE_ENTRY
: r
= R_PPC_GNU_VTENTRY
; break;
1925 return ppc_elf_howto_table
[r
];
1928 /* Set the howto pointer for a PowerPC ELF reloc. */
1931 ppc_elf_info_to_howto (bfd
*abfd ATTRIBUTE_UNUSED
,
1933 Elf_Internal_Rela
*dst
)
1935 /* Initialize howto table if not already done. */
1936 if (!ppc_elf_howto_table
[R_PPC_ADDR32
])
1937 ppc_elf_howto_init ();
1939 BFD_ASSERT (ELF32_R_TYPE (dst
->r_info
) < (unsigned int) R_PPC_max
);
1940 cache_ptr
->howto
= ppc_elf_howto_table
[ELF32_R_TYPE (dst
->r_info
)];
1943 /* Handle the R_PPC_ADDR16_HA reloc. */
1945 static bfd_reloc_status_type
1946 ppc_elf_addr16_ha_reloc (bfd
*abfd ATTRIBUTE_UNUSED
,
1947 arelent
*reloc_entry
,
1949 void *data ATTRIBUTE_UNUSED
,
1950 asection
*input_section
,
1952 char **error_message ATTRIBUTE_UNUSED
)
1956 if (output_bfd
!= NULL
)
1958 reloc_entry
->address
+= input_section
->output_offset
;
1959 return bfd_reloc_ok
;
1962 if (reloc_entry
->address
> input_section
->_cooked_size
)
1963 return bfd_reloc_outofrange
;
1965 if (bfd_is_com_section (symbol
->section
))
1968 relocation
= symbol
->value
;
1970 relocation
+= symbol
->section
->output_section
->vma
;
1971 relocation
+= symbol
->section
->output_offset
;
1972 relocation
+= reloc_entry
->addend
;
1974 reloc_entry
->addend
+= (relocation
& 0x8000) << 1;
1976 return bfd_reloc_continue
;
1979 static bfd_reloc_status_type
1980 ppc_elf_unhandled_reloc (bfd
*abfd
,
1981 arelent
*reloc_entry
,
1984 asection
*input_section
,
1986 char **error_message
)
1988 /* If this is a relocatable link (output_bfd test tells us), just
1989 call the generic function. Any adjustment will be done at final
1991 if (output_bfd
!= NULL
)
1992 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
1993 input_section
, output_bfd
, error_message
);
1995 if (error_message
!= NULL
)
1997 static char buf
[60];
1998 sprintf (buf
, _("generic linker can't handle %s"),
1999 reloc_entry
->howto
->name
);
2000 *error_message
= buf
;
2002 return bfd_reloc_dangerous
;
2005 /* Fix bad default arch selected for a 32 bit input bfd when the
2006 default is 64 bit. */
2009 ppc_elf_object_p (bfd
*abfd
)
2011 if (abfd
->arch_info
->the_default
&& abfd
->arch_info
->bits_per_word
== 64)
2013 Elf_Internal_Ehdr
*i_ehdr
= elf_elfheader (abfd
);
2015 if (i_ehdr
->e_ident
[EI_CLASS
] == ELFCLASS32
)
2017 /* Relies on arch after 64 bit default being 32 bit default. */
2018 abfd
->arch_info
= abfd
->arch_info
->next
;
2019 BFD_ASSERT (abfd
->arch_info
->bits_per_word
== 32);
2025 /* Function to set whether a module needs the -mrelocatable bit set. */
2028 ppc_elf_set_private_flags (bfd
*abfd
, flagword flags
)
2030 BFD_ASSERT (!elf_flags_init (abfd
)
2031 || elf_elfheader (abfd
)->e_flags
== flags
);
2033 elf_elfheader (abfd
)->e_flags
= flags
;
2034 elf_flags_init (abfd
) = TRUE
;
2038 /* Merge backend specific data from an object file to the output
2039 object file when linking. */
2042 ppc_elf_merge_private_bfd_data (bfd
*ibfd
, bfd
*obfd
)
2048 /* Check if we have the same endianess. */
2049 if (! _bfd_generic_verify_endian_match (ibfd
, obfd
))
2052 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
2053 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
2056 new_flags
= elf_elfheader (ibfd
)->e_flags
;
2057 old_flags
= elf_elfheader (obfd
)->e_flags
;
2058 if (!elf_flags_init (obfd
))
2060 /* First call, no flags set. */
2061 elf_flags_init (obfd
) = TRUE
;
2062 elf_elfheader (obfd
)->e_flags
= new_flags
;
2065 /* Compatible flags are ok. */
2066 else if (new_flags
== old_flags
)
2069 /* Incompatible flags. */
2072 /* Warn about -mrelocatable mismatch. Allow -mrelocatable-lib
2073 to be linked with either. */
2075 if ((new_flags
& EF_PPC_RELOCATABLE
) != 0
2076 && (old_flags
& (EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
)) == 0)
2079 (*_bfd_error_handler
)
2080 (_("%s: compiled with -mrelocatable and linked with "
2081 "modules compiled normally"),
2082 bfd_archive_filename (ibfd
));
2084 else if ((new_flags
& (EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
)) == 0
2085 && (old_flags
& EF_PPC_RELOCATABLE
) != 0)
2088 (*_bfd_error_handler
)
2089 (_("%s: compiled normally and linked with "
2090 "modules compiled with -mrelocatable"),
2091 bfd_archive_filename (ibfd
));
2094 /* The output is -mrelocatable-lib iff both the input files are. */
2095 if (! (new_flags
& EF_PPC_RELOCATABLE_LIB
))
2096 elf_elfheader (obfd
)->e_flags
&= ~EF_PPC_RELOCATABLE_LIB
;
2098 /* The output is -mrelocatable iff it can't be -mrelocatable-lib,
2099 but each input file is either -mrelocatable or -mrelocatable-lib. */
2100 if (! (elf_elfheader (obfd
)->e_flags
& EF_PPC_RELOCATABLE_LIB
)
2101 && (new_flags
& (EF_PPC_RELOCATABLE_LIB
| EF_PPC_RELOCATABLE
))
2102 && (old_flags
& (EF_PPC_RELOCATABLE_LIB
| EF_PPC_RELOCATABLE
)))
2103 elf_elfheader (obfd
)->e_flags
|= EF_PPC_RELOCATABLE
;
2105 /* Do not warn about eabi vs. V.4 mismatch, just or in the bit if
2106 any module uses it. */
2107 elf_elfheader (obfd
)->e_flags
|= (new_flags
& EF_PPC_EMB
);
2109 new_flags
&= ~(EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
| EF_PPC_EMB
);
2110 old_flags
&= ~(EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
| EF_PPC_EMB
);
2112 /* Warn about any other mismatches. */
2113 if (new_flags
!= old_flags
)
2116 (*_bfd_error_handler
)
2117 (_("%s: uses different e_flags (0x%lx) fields "
2118 "than previous modules (0x%lx)"),
2119 bfd_archive_filename (ibfd
), (long) new_flags
, (long) old_flags
);
2124 bfd_set_error (bfd_error_bad_value
);
2132 /* Handle a PowerPC specific section when reading an object file. This
2133 is called when elfcode.h finds a section with an unknown type. */
2136 ppc_elf_section_from_shdr (bfd
*abfd
, Elf_Internal_Shdr
*hdr
, const char *name
)
2141 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
))
2144 newsect
= hdr
->bfd_section
;
2145 flags
= bfd_get_section_flags (abfd
, newsect
);
2146 if (hdr
->sh_flags
& SHF_EXCLUDE
)
2147 flags
|= SEC_EXCLUDE
;
2149 if (hdr
->sh_type
== SHT_ORDERED
)
2150 flags
|= SEC_SORT_ENTRIES
;
2152 bfd_set_section_flags (abfd
, newsect
, flags
);
2156 /* Set up any other section flags and such that may be necessary. */
2159 ppc_elf_fake_sections (bfd
*abfd ATTRIBUTE_UNUSED
,
2160 Elf_Internal_Shdr
*shdr
,
2163 if ((asect
->flags
& SEC_EXCLUDE
) != 0)
2164 shdr
->sh_flags
|= SHF_EXCLUDE
;
2166 if ((asect
->flags
& SEC_SORT_ENTRIES
) != 0)
2167 shdr
->sh_type
= SHT_ORDERED
;
2172 /* Create a special linker section, or return a pointer to a linker
2173 section already created */
2175 static elf_linker_section_t
*
2176 elf_create_linker_section (bfd
*abfd
,
2177 struct bfd_link_info
*info
,
2178 enum elf_linker_section_enum which
,
2179 elf_linker_section_t
*defaults
)
2181 bfd
*dynobj
= elf_hash_table (info
)->dynobj
;
2182 elf_linker_section_t
*lsect
;
2184 /* Record the first bfd section that needs the special section */
2186 dynobj
= elf_hash_table (info
)->dynobj
= abfd
;
2188 /* If this is the first time, create the section */
2189 lsect
= elf_linker_section (dynobj
, which
);
2193 bfd_size_type amt
= sizeof (elf_linker_section_t
);
2195 lsect
= bfd_alloc (dynobj
, amt
);
2198 elf_linker_section (dynobj
, which
) = lsect
;
2199 lsect
->which
= which
;
2200 lsect
->hole_written_p
= FALSE
;
2202 /* See if the sections already exist */
2203 lsect
->section
= s
= bfd_get_section_by_name (dynobj
, lsect
->name
);
2204 if (!s
|| (s
->flags
& defaults
->flags
) != defaults
->flags
)
2206 lsect
->section
= s
= bfd_make_section_anyway (dynobj
, lsect
->name
);
2211 bfd_set_section_flags (dynobj
, s
, defaults
->flags
);
2212 bfd_set_section_alignment (dynobj
, s
, lsect
->alignment
);
2214 else if (bfd_get_section_alignment (dynobj
, s
) < lsect
->alignment
)
2215 bfd_set_section_alignment (dynobj
, s
, lsect
->alignment
);
2217 s
->_raw_size
= align_power (s
->_raw_size
, lsect
->alignment
);
2219 /* Is there a hole we have to provide? If so check whether the
2220 segment is too big already */
2221 if (lsect
->hole_size
)
2223 lsect
->hole_offset
= s
->_raw_size
;
2224 s
->_raw_size
+= lsect
->hole_size
;
2225 if (lsect
->hole_offset
> lsect
->max_hole_offset
)
2227 (*_bfd_error_handler
)
2228 (_("%s: Section %s is too large to add hole of %ld bytes"),
2229 bfd_get_filename (abfd
),
2231 (long) lsect
->hole_size
);
2233 bfd_set_error (bfd_error_bad_value
);
2239 fprintf (stderr
, "Creating section %s, current size = %ld\n",
2240 lsect
->name
, (long) s
->_raw_size
);
2243 if (lsect
->sym_name
)
2245 struct elf_link_hash_entry
*h
;
2246 struct bfd_link_hash_entry
*bh
;
2249 fprintf (stderr
, "Adding %s to section %s\n",
2253 bh
= bfd_link_hash_lookup (info
->hash
, lsect
->sym_name
,
2254 FALSE
, FALSE
, FALSE
);
2256 if ((bh
== NULL
|| bh
->type
== bfd_link_hash_undefined
)
2257 && !(_bfd_generic_link_add_one_symbol
2258 (info
, abfd
, lsect
->sym_name
, BSF_GLOBAL
, s
,
2260 ? s
->_raw_size
- lsect
->hole_size
+ lsect
->sym_offset
2261 : lsect
->sym_offset
),
2263 get_elf_backend_data (abfd
)->collect
, &bh
)))
2265 h
= (struct elf_link_hash_entry
*) bh
;
2267 if ((defaults
->which
!= LINKER_SECTION_SDATA
)
2268 && (defaults
->which
!= LINKER_SECTION_SDATA2
))
2269 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_DYNAMIC
;
2271 h
->type
= STT_OBJECT
;
2272 lsect
->sym_hash
= h
;
2275 && ! _bfd_elf_link_record_dynamic_symbol (info
, h
))
2283 /* Find a linker generated pointer with a given addend and type. */
2285 static elf_linker_section_pointers_t
*
2286 elf_find_pointer_linker_section
2287 (elf_linker_section_pointers_t
*linker_pointers
,
2289 elf_linker_section_enum_t which
)
2291 for ( ; linker_pointers
!= NULL
; linker_pointers
= linker_pointers
->next
)
2292 if (which
== linker_pointers
->which
&& addend
== linker_pointers
->addend
)
2293 return linker_pointers
;
2298 /* Allocate a pointer to live in a linker created section. */
2301 elf_create_pointer_linker_section (bfd
*abfd
,
2302 struct bfd_link_info
*info
,
2303 elf_linker_section_t
*lsect
,
2304 struct elf_link_hash_entry
*h
,
2305 const Elf_Internal_Rela
*rel
)
2307 elf_linker_section_pointers_t
**ptr_linker_section_ptr
= NULL
;
2308 elf_linker_section_pointers_t
*linker_section_ptr
;
2309 unsigned long r_symndx
= ELF32_R_SYM (rel
->r_info
);
2312 BFD_ASSERT (lsect
!= NULL
);
2314 /* Is this a global symbol? */
2317 /* Has this symbol already been allocated? If so, our work is done. */
2318 if (elf_find_pointer_linker_section (h
->linker_section_pointer
,
2323 ptr_linker_section_ptr
= &h
->linker_section_pointer
;
2324 /* Make sure this symbol is output as a dynamic symbol. */
2325 if (h
->dynindx
== -1)
2327 if (! _bfd_elf_link_record_dynamic_symbol (info
, h
))
2331 if (lsect
->rel_section
)
2332 lsect
->rel_section
->_raw_size
+= sizeof (Elf32_External_Rela
);
2336 /* Allocation of a pointer to a local symbol. */
2337 elf_linker_section_pointers_t
**ptr
= elf_local_ptr_offsets (abfd
);
2339 /* Allocate a table to hold the local symbols if first time. */
2342 unsigned int num_symbols
= elf_tdata (abfd
)->symtab_hdr
.sh_info
;
2343 register unsigned int i
;
2346 amt
*= sizeof (elf_linker_section_pointers_t
*);
2347 ptr
= bfd_alloc (abfd
, amt
);
2352 elf_local_ptr_offsets (abfd
) = ptr
;
2353 for (i
= 0; i
< num_symbols
; i
++)
2357 /* Has this symbol already been allocated? If so, our work is done. */
2358 if (elf_find_pointer_linker_section (ptr
[r_symndx
],
2363 ptr_linker_section_ptr
= &ptr
[r_symndx
];
2367 /* If we are generating a shared object, we need to
2368 output a R_<xxx>_RELATIVE reloc so that the
2369 dynamic linker can adjust this GOT entry. */
2370 BFD_ASSERT (lsect
->rel_section
!= NULL
);
2371 lsect
->rel_section
->_raw_size
+= sizeof (Elf32_External_Rela
);
2375 /* Allocate space for a pointer in the linker section, and allocate
2376 a new pointer record from internal memory. */
2377 BFD_ASSERT (ptr_linker_section_ptr
!= NULL
);
2378 amt
= sizeof (elf_linker_section_pointers_t
);
2379 linker_section_ptr
= bfd_alloc (abfd
, amt
);
2381 if (!linker_section_ptr
)
2384 linker_section_ptr
->next
= *ptr_linker_section_ptr
;
2385 linker_section_ptr
->addend
= rel
->r_addend
;
2386 linker_section_ptr
->which
= lsect
->which
;
2387 linker_section_ptr
->written_address_p
= FALSE
;
2388 *ptr_linker_section_ptr
= linker_section_ptr
;
2390 linker_section_ptr
->offset
= lsect
->section
->_raw_size
;
2391 lsect
->section
->_raw_size
+= 4;
2395 "Create pointer in linker section %s, offset = %ld, section size = %ld\n",
2396 lsect
->name
, (long) linker_section_ptr
->offset
,
2397 (long) lsect
->section
->_raw_size
);
2403 #define bfd_put_ptr(BFD, VAL, ADDR) bfd_put_32 (BFD, VAL, ADDR)
2405 /* Fill in the address for a pointer generated in a linker section. */
2408 elf_finish_pointer_linker_section (bfd
*output_bfd
,
2410 struct bfd_link_info
*info
,
2411 elf_linker_section_t
*lsect
,
2412 struct elf_link_hash_entry
*h
,
2414 const Elf_Internal_Rela
*rel
,
2417 elf_linker_section_pointers_t
*linker_section_ptr
;
2419 BFD_ASSERT (lsect
!= NULL
);
2423 /* Handle global symbol. */
2425 = elf_find_pointer_linker_section (h
->linker_section_pointer
,
2429 BFD_ASSERT (linker_section_ptr
!= NULL
);
2431 if (! elf_hash_table (info
)->dynamic_sections_created
2434 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
)))
2436 /* This is actually a static link, or it is a
2437 -Bsymbolic link and the symbol is defined
2438 locally. We must initialize this entry in the
2441 When doing a dynamic link, we create a .rela.<xxx>
2442 relocation entry to initialize the value. This
2443 is done in the finish_dynamic_symbol routine. */
2444 if (!linker_section_ptr
->written_address_p
)
2446 linker_section_ptr
->written_address_p
= TRUE
;
2447 bfd_put_ptr (output_bfd
,
2448 relocation
+ linker_section_ptr
->addend
,
2449 (lsect
->section
->contents
2450 + linker_section_ptr
->offset
));
2456 /* Handle local symbol. */
2457 unsigned long r_symndx
= ELF32_R_SYM (rel
->r_info
);
2458 BFD_ASSERT (elf_local_ptr_offsets (input_bfd
) != NULL
);
2459 BFD_ASSERT (elf_local_ptr_offsets (input_bfd
)[r_symndx
] != NULL
);
2460 linker_section_ptr
= (elf_find_pointer_linker_section
2461 (elf_local_ptr_offsets (input_bfd
)[r_symndx
],
2465 BFD_ASSERT (linker_section_ptr
!= NULL
);
2467 /* Write out pointer if it hasn't been rewritten out before. */
2468 if (!linker_section_ptr
->written_address_p
)
2470 linker_section_ptr
->written_address_p
= TRUE
;
2471 bfd_put_ptr (output_bfd
, relocation
+ linker_section_ptr
->addend
,
2472 lsect
->section
->contents
+ linker_section_ptr
->offset
);
2476 asection
*srel
= lsect
->rel_section
;
2477 Elf_Internal_Rela outrel
[MAX_INT_RELS_PER_EXT_REL
];
2479 struct elf_backend_data
*bed
= get_elf_backend_data (output_bfd
);
2482 /* We need to generate a relative reloc for the dynamic
2486 srel
= bfd_get_section_by_name (elf_hash_table (info
)->dynobj
,
2488 lsect
->rel_section
= srel
;
2491 BFD_ASSERT (srel
!= NULL
);
2493 for (i
= 0; i
< bed
->s
->int_rels_per_ext_rel
; i
++)
2495 outrel
[i
].r_offset
= (lsect
->section
->output_section
->vma
2496 + lsect
->section
->output_offset
2497 + linker_section_ptr
->offset
);
2498 outrel
[i
].r_info
= 0;
2499 outrel
[i
].r_addend
= 0;
2501 outrel
[0].r_info
= ELF32_R_INFO (0, relative_reloc
);
2502 erel
= lsect
->section
->contents
;
2503 erel
+= (elf_section_data (lsect
->section
)->rel_count
++
2504 * sizeof (Elf32_External_Rela
));
2505 bfd_elf32_swap_reloca_out (output_bfd
, outrel
, erel
);
2510 relocation
= (lsect
->section
->output_offset
2511 + linker_section_ptr
->offset
2512 - lsect
->hole_offset
2513 - lsect
->sym_offset
);
2517 "Finish pointer in linker section %s, offset = %ld (0x%lx)\n",
2518 lsect
->name
, (long) relocation
, (long) relocation
);
2521 /* Subtract out the addend, because it will get added back in by the normal
2523 return relocation
- linker_section_ptr
->addend
;
2526 /* Create a special linker section */
2527 static elf_linker_section_t
*
2528 ppc_elf_create_linker_section (bfd
*abfd
,
2529 struct bfd_link_info
*info
,
2530 enum elf_linker_section_enum which
)
2532 bfd
*dynobj
= elf_hash_table (info
)->dynobj
;
2533 elf_linker_section_t
*lsect
;
2535 /* Record the first bfd section that needs the special section. */
2537 dynobj
= elf_hash_table (info
)->dynobj
= abfd
;
2539 /* If this is the first time, create the section. */
2540 lsect
= elf_linker_section (dynobj
, which
);
2543 elf_linker_section_t defaults
;
2544 static elf_linker_section_t zero_section
;
2546 defaults
= zero_section
;
2547 defaults
.which
= which
;
2548 defaults
.hole_written_p
= FALSE
;
2549 defaults
.alignment
= 2;
2551 /* Both of these sections are (technically) created by the user
2552 putting data in them, so they shouldn't be marked
2555 The linker creates them so it has somewhere to attach their
2556 respective symbols. In fact, if they were empty it would
2557 be OK to leave the symbol set to 0 (or any random number), because
2558 the appropriate register should never be used. */
2559 defaults
.flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
2565 (*_bfd_error_handler
) (_("%s: unknown special linker type %d"),
2566 bfd_get_filename (abfd
),
2569 bfd_set_error (bfd_error_bad_value
);
2572 case LINKER_SECTION_SDATA
: /* .sdata/.sbss section */
2573 defaults
.name
= ".sdata";
2574 defaults
.rel_name
= ".rela.sdata";
2575 defaults
.bss_name
= ".sbss";
2576 defaults
.sym_name
= "_SDA_BASE_";
2577 defaults
.sym_offset
= 32768;
2580 case LINKER_SECTION_SDATA2
: /* .sdata2/.sbss2 section */
2581 defaults
.name
= ".sdata2";
2582 defaults
.rel_name
= ".rela.sdata2";
2583 defaults
.bss_name
= ".sbss2";
2584 defaults
.sym_name
= "_SDA2_BASE_";
2585 defaults
.sym_offset
= 32768;
2586 defaults
.flags
|= SEC_READONLY
;
2590 lsect
= elf_create_linker_section (abfd
, info
, which
, &defaults
);
2596 /* If we have a non-zero sized .sbss2 or .PPC.EMB.sbss0 sections, we
2597 need to bump up the number of section headers. */
2600 ppc_elf_additional_program_headers (bfd
*abfd
)
2607 s
= bfd_get_section_by_name (abfd
, ".interp");
2611 s
= bfd_get_section_by_name (abfd
, ".sbss2");
2612 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0 && s
->_raw_size
> 0)
2615 s
= bfd_get_section_by_name (abfd
, ".PPC.EMB.sbss0");
2616 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0 && s
->_raw_size
> 0)
2622 /* Modify the segment map if needed. */
2625 ppc_elf_modify_segment_map (bfd
*abfd ATTRIBUTE_UNUSED
)
2630 /* The powerpc .got has a blrl instruction in it. Mark it executable. */
2633 ppc_elf_create_got (bfd
*abfd
, struct bfd_link_info
*info
)
2635 struct ppc_elf_link_hash_table
*htab
;
2639 if (!_bfd_elf_create_got_section (abfd
, info
))
2642 htab
= ppc_elf_hash_table (info
);
2643 htab
->got
= s
= bfd_get_section_by_name (abfd
, ".got");
2647 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_CODE
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
2648 | SEC_LINKER_CREATED
);
2649 if (!bfd_set_section_flags (abfd
, s
, flags
))
2652 htab
->relgot
= bfd_make_section (abfd
, ".rela.got");
2654 || ! bfd_set_section_flags (abfd
, htab
->relgot
,
2655 (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
2656 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
2658 || ! bfd_set_section_alignment (abfd
, htab
->relgot
, 2))
2664 /* We have to create .dynsbss and .rela.sbss here so that they get mapped
2665 to output sections (just like _bfd_elf_create_dynamic_sections has
2666 to create .dynbss and .rela.bss). */
2669 ppc_elf_create_dynamic_sections (bfd
*abfd
, struct bfd_link_info
*info
)
2671 struct ppc_elf_link_hash_table
*htab
;
2675 htab
= ppc_elf_hash_table (info
);
2677 if (htab
->got
== NULL
2678 && !ppc_elf_create_got (abfd
, info
))
2681 if (!_bfd_elf_create_dynamic_sections (abfd
, info
))
2684 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
2685 | SEC_LINKER_CREATED
);
2687 htab
->dynbss
= bfd_get_section_by_name (abfd
, ".dynbss");
2688 htab
->dynsbss
= s
= bfd_make_section (abfd
, ".dynsbss");
2690 || ! bfd_set_section_flags (abfd
, s
, SEC_ALLOC
))
2695 htab
->relbss
= bfd_get_section_by_name (abfd
, ".rela.bss");
2696 htab
->relsbss
= s
= bfd_make_section (abfd
, ".rela.sbss");
2698 || ! bfd_set_section_flags (abfd
, s
, flags
| SEC_READONLY
)
2699 || ! bfd_set_section_alignment (abfd
, s
, 2))
2703 htab
->relplt
= bfd_get_section_by_name (abfd
, ".rela.plt");
2704 htab
->plt
= s
= bfd_get_section_by_name (abfd
, ".plt");
2708 flags
= SEC_ALLOC
| SEC_CODE
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
;
2709 return bfd_set_section_flags (abfd
, s
, flags
);
2712 /* Adjust a symbol defined by a dynamic object and referenced by a
2713 regular object. The current definition is in some section of the
2714 dynamic object, but we're not including those sections. We have to
2715 change the definition to something the rest of the link can
2719 ppc_elf_adjust_dynamic_symbol (struct bfd_link_info
*info
,
2720 struct elf_link_hash_entry
*h
)
2722 struct ppc_elf_link_hash_table
*htab
;
2724 unsigned int power_of_two
;
2727 fprintf (stderr
, "ppc_elf_adjust_dynamic_symbol called for %s\n",
2728 h
->root
.root
.string
);
2731 /* Make sure we know what is going on here. */
2732 htab
= ppc_elf_hash_table (info
);
2733 BFD_ASSERT (htab
->elf
.dynobj
!= NULL
2734 && ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
)
2735 || h
->weakdef
!= NULL
2736 || ((h
->elf_link_hash_flags
2737 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0
2738 && (h
->elf_link_hash_flags
2739 & ELF_LINK_HASH_REF_REGULAR
) != 0
2740 && (h
->elf_link_hash_flags
2741 & ELF_LINK_HASH_DEF_REGULAR
) == 0)));
2743 /* Deal with function syms. */
2744 if (h
->type
== STT_FUNC
2745 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
2747 /* Clear procedure linkage table information for any symbol that
2748 won't need a .plt entry. */
2749 if (h
->plt
.refcount
<= 0
2750 || SYMBOL_CALLS_LOCAL (info
, h
)
2751 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
2752 && h
->root
.type
== bfd_link_hash_undefweak
))
2754 /* A PLT entry is not required/allowed when:
2756 1. We are not using ld.so; because then the PLT entry
2757 can't be set up, so we can't use one. In this case,
2758 ppc_elf_adjust_dynamic_symbol won't even be called.
2760 2. GC has rendered the entry unused.
2762 3. We know for certain that a call to this symbol
2763 will go to this object, or will remain undefined. */
2764 h
->plt
.offset
= (bfd_vma
) -1;
2765 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
2770 h
->plt
.offset
= (bfd_vma
) -1;
2772 /* If this is a weak symbol, and there is a real definition, the
2773 processor independent code will have arranged for us to see the
2774 real definition first, and we can just use the same value. */
2775 if (h
->weakdef
!= NULL
)
2777 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
2778 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
2779 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
2780 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
2781 if (ELIMINATE_COPY_RELOCS
)
2782 h
->elf_link_hash_flags
2783 = ((h
->elf_link_hash_flags
& ~ELF_LINK_NON_GOT_REF
)
2784 | (h
->weakdef
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
));
2788 /* This is a reference to a symbol defined by a dynamic object which
2789 is not a function. */
2791 /* If we are creating a shared library, we must presume that the
2792 only references to the symbol are via the global offset table.
2793 For such cases we need not do anything here; the relocations will
2794 be handled correctly by relocate_section. */
2798 /* If there are no references to this symbol that do not use the
2799 GOT, we don't need to generate a copy reloc. */
2800 if ((h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0)
2803 if (ELIMINATE_COPY_RELOCS
)
2805 struct ppc_elf_dyn_relocs
*p
;
2806 for (p
= ppc_elf_hash_entry (h
)->dyn_relocs
; p
!= NULL
; p
= p
->next
)
2808 s
= p
->sec
->output_section
;
2809 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
2813 /* If we didn't find any dynamic relocs in read-only sections, then
2814 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
2817 h
->elf_link_hash_flags
&= ~ELF_LINK_NON_GOT_REF
;
2822 /* We must allocate the symbol in our .dynbss section, which will
2823 become part of the .bss section of the executable. There will be
2824 an entry for this symbol in the .dynsym section. The dynamic
2825 object will contain position independent code, so all references
2826 from the dynamic object to this symbol will go through the global
2827 offset table. The dynamic linker will use the .dynsym entry to
2828 determine the address it must put in the global offset table, so
2829 both the dynamic object and the regular object will refer to the
2830 same memory location for the variable.
2832 Of course, if the symbol is sufficiently small, we must instead
2833 allocate it in .sbss. FIXME: It would be better to do this if and
2834 only if there were actually SDAREL relocs for that symbol. */
2836 if (h
->size
<= elf_gp_size (htab
->elf
.dynobj
))
2840 BFD_ASSERT (s
!= NULL
);
2842 /* We must generate a R_PPC_COPY reloc to tell the dynamic linker to
2843 copy the initial value out of the dynamic object and into the
2844 runtime process image. We need to remember the offset into the
2845 .rela.bss section we are going to use. */
2846 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
2850 if (h
->size
<= elf_gp_size (htab
->elf
.dynobj
))
2851 srel
= htab
->relsbss
;
2853 srel
= htab
->relbss
;
2854 BFD_ASSERT (srel
!= NULL
);
2855 srel
->_raw_size
+= sizeof (Elf32_External_Rela
);
2856 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_COPY
;
2859 /* We need to figure out the alignment required for this symbol. I
2860 have no idea how ELF linkers handle this. */
2861 power_of_two
= bfd_log2 (h
->size
);
2862 if (power_of_two
> 4)
2865 /* Apply the required alignment. */
2866 s
->_raw_size
= BFD_ALIGN (s
->_raw_size
,
2867 (bfd_size_type
) (1 << power_of_two
));
2868 if (power_of_two
> bfd_get_section_alignment (htab
->elf
.dynobj
, s
))
2870 if (! bfd_set_section_alignment (htab
->elf
.dynobj
, s
, power_of_two
))
2874 /* Define the symbol as being at this point in the section. */
2875 h
->root
.u
.def
.section
= s
;
2876 h
->root
.u
.def
.value
= s
->_raw_size
;
2878 /* Increment the section size to make room for the symbol. */
2879 s
->_raw_size
+= h
->size
;
2884 /* This is the condition under which finish_dynamic_symbol will be
2885 called from elflink.h. If elflink.h doesn't call our
2886 finish_dynamic_symbol routine, we'll need to do something about
2887 initializing any .plt and .got entries in relocate_section. */
2888 #define WILL_CALL_FINISH_DYNAMIC_SYMBOL(DYN, SHARED, H) \
2891 || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) \
2892 && ((H)->dynindx != -1 \
2893 || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0))
2895 /* Of those relocs that might be copied as dynamic relocs, this macro
2896 selects those that must be copied when linking a shared library,
2897 even when the symbol is local. */
2899 #define MUST_BE_DYN_RELOC(RTYPE) \
2900 ((RTYPE) != R_PPC_REL24 \
2901 && (RTYPE) != R_PPC_REL14 \
2902 && (RTYPE) != R_PPC_REL14_BRTAKEN \
2903 && (RTYPE) != R_PPC_REL14_BRNTAKEN \
2904 && (RTYPE) != R_PPC_REL32)
2906 /* Allocate space in associated reloc sections for dynamic relocs. */
2909 allocate_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
2911 struct bfd_link_info
*info
= inf
;
2912 struct ppc_elf_link_hash_entry
*eh
;
2913 struct ppc_elf_link_hash_table
*htab
;
2914 struct ppc_elf_dyn_relocs
*p
;
2916 if (h
->root
.type
== bfd_link_hash_indirect
)
2919 if (h
->root
.type
== bfd_link_hash_warning
)
2920 /* When warning symbols are created, they **replace** the "real"
2921 entry in the hash table, thus we never get to see the real
2922 symbol in a hash traversal. So look at it now. */
2923 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2925 htab
= ppc_elf_hash_table (info
);
2926 if (htab
->elf
.dynamic_sections_created
2927 && h
->plt
.refcount
> 0)
2929 /* Make sure this symbol is output as a dynamic symbol. */
2930 if (h
->dynindx
== -1
2931 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
2933 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
2938 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h
))
2940 asection
*s
= htab
->plt
;
2942 /* If this is the first .plt entry, make room for the special
2944 if (s
->_raw_size
== 0)
2945 s
->_raw_size
+= PLT_INITIAL_ENTRY_SIZE
;
2947 /* The PowerPC PLT is actually composed of two parts, the
2948 first part is 2 words (for a load and a jump), and then
2949 there is a remaining word available at the end. */
2950 h
->plt
.offset
= (PLT_INITIAL_ENTRY_SIZE
2952 * ((s
->_raw_size
- PLT_INITIAL_ENTRY_SIZE
)
2953 / PLT_ENTRY_SIZE
)));
2955 /* If this symbol is not defined in a regular file, and we
2956 are not generating a shared library, then set the symbol
2957 to this location in the .plt. This is required to make
2958 function pointers compare as equal between the normal
2959 executable and the shared library. */
2961 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
2963 h
->root
.u
.def
.section
= s
;
2964 h
->root
.u
.def
.value
= h
->plt
.offset
;
2967 /* Make room for this entry. After the 8192nd entry, room
2968 for two entries is allocated. */
2969 s
->_raw_size
+= PLT_ENTRY_SIZE
;
2970 if ((s
->_raw_size
- PLT_INITIAL_ENTRY_SIZE
) / PLT_ENTRY_SIZE
2971 > PLT_NUM_SINGLE_ENTRIES
)
2972 s
->_raw_size
+= PLT_ENTRY_SIZE
;
2974 /* We also need to make an entry in the .rela.plt section. */
2975 htab
->relplt
->_raw_size
+= sizeof (Elf32_External_Rela
);
2979 h
->plt
.offset
= (bfd_vma
) -1;
2980 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
2985 h
->plt
.offset
= (bfd_vma
) -1;
2986 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
2989 eh
= (struct ppc_elf_link_hash_entry
*) h
;
2990 if (eh
->elf
.got
.refcount
> 0)
2992 /* Make sure this symbol is output as a dynamic symbol. */
2993 if (eh
->elf
.dynindx
== -1
2994 && (eh
->elf
.elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
2996 if (!bfd_elf32_link_record_dynamic_symbol (info
, &eh
->elf
))
3000 if (eh
->tls_mask
== (TLS_TLS
| TLS_LD
)
3001 && !(eh
->elf
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
))
3002 /* If just an LD reloc, we'll just use htab->tlsld_got.offset. */
3003 eh
->elf
.got
.offset
= (bfd_vma
) -1;
3007 eh
->elf
.got
.offset
= htab
->got
->_raw_size
;
3008 if ((eh
->tls_mask
& TLS_TLS
) != 0)
3010 if ((eh
->tls_mask
& TLS_LD
) != 0)
3011 htab
->got
->_raw_size
+= 8;
3012 if ((eh
->tls_mask
& TLS_GD
) != 0)
3013 htab
->got
->_raw_size
+= 8;
3014 if ((eh
->tls_mask
& (TLS_TPREL
| TLS_TPRELGD
)) != 0)
3015 htab
->got
->_raw_size
+= 4;
3016 if ((eh
->tls_mask
& TLS_DTPREL
) != 0)
3017 htab
->got
->_raw_size
+= 4;
3020 htab
->got
->_raw_size
+= 4;
3021 dyn
= htab
->elf
.dynamic_sections_created
;
3023 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, &eh
->elf
))
3024 && (ELF_ST_VISIBILITY (eh
->elf
.other
) == STV_DEFAULT
3025 || eh
->elf
.root
.type
!= bfd_link_hash_undefweak
))
3027 /* All the entries we allocated need relocs. */
3028 htab
->relgot
->_raw_size
3029 += ((htab
->got
->_raw_size
- eh
->elf
.got
.offset
) / 4
3030 * sizeof (Elf32_External_Rela
));
3031 /* Except LD only needs one. */
3032 if ((eh
->tls_mask
& TLS_LD
) != 0)
3033 htab
->relgot
->_raw_size
-= sizeof (Elf32_External_Rela
);
3038 eh
->elf
.got
.offset
= (bfd_vma
) -1;
3040 if (eh
->dyn_relocs
== NULL
)
3043 /* In the shared -Bsymbolic case, discard space allocated for
3044 dynamic pc-relative relocs against symbols which turn out to be
3045 defined in regular objects. For the normal shared case, discard
3046 space for relocs that have become local due to symbol visibility
3051 /* Relocs that use pc_count are those that appear on a call insn,
3052 or certain REL relocs (see MUST_BE_DYN_RELOC) that can be
3053 generated via assembly. We want calls to protected symbols to
3054 resolve directly to the function rather than going via the plt.
3055 If people want function pointer comparisons to work as expected
3056 then they should avoid writing weird assembly. */
3057 if (SYMBOL_CALLS_LOCAL (info
, h
))
3059 struct ppc_elf_dyn_relocs
**pp
;
3061 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
3063 p
->count
-= p
->pc_count
;
3072 /* Also discard relocs on undefined weak syms with non-default
3074 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
3075 && h
->root
.type
== bfd_link_hash_undefweak
)
3076 eh
->dyn_relocs
= NULL
;
3078 else if (ELIMINATE_COPY_RELOCS
)
3080 /* For the non-shared case, discard space for relocs against
3081 symbols which turn out to need copy relocs or are not
3084 if ((h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0
3085 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
3086 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
3088 /* Make sure this symbol is output as a dynamic symbol.
3089 Undefined weak syms won't yet be marked as dynamic. */
3090 if (h
->dynindx
== -1
3091 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
3093 if (! bfd_elf64_link_record_dynamic_symbol (info
, h
))
3097 /* If that succeeded, we know we'll be keeping all the
3099 if (h
->dynindx
!= -1)
3103 eh
->dyn_relocs
= NULL
;
3108 /* Finally, allocate space. */
3109 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
3111 asection
*sreloc
= elf_section_data (p
->sec
)->sreloc
;
3112 sreloc
->_raw_size
+= p
->count
* sizeof (Elf32_External_Rela
);
3118 /* Find any dynamic relocs that apply to read-only sections. */
3121 readonly_dynrelocs (struct elf_link_hash_entry
*h
, void *info
)
3123 struct ppc_elf_dyn_relocs
*p
;
3125 if (h
->root
.type
== bfd_link_hash_indirect
)
3128 if (h
->root
.type
== bfd_link_hash_warning
)
3129 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
3131 for (p
= ppc_elf_hash_entry (h
)->dyn_relocs
; p
!= NULL
; p
= p
->next
)
3133 asection
*s
= p
->sec
->output_section
;
3136 && ((s
->flags
& (SEC_READONLY
| SEC_ALLOC
))
3137 == (SEC_READONLY
| SEC_ALLOC
)))
3139 ((struct bfd_link_info
*) info
)->flags
|= DF_TEXTREL
;
3141 /* Not an error, just cut short the traversal. */
3148 /* Set the sizes of the dynamic sections. */
3151 ppc_elf_size_dynamic_sections (bfd
*output_bfd ATTRIBUTE_UNUSED
,
3152 struct bfd_link_info
*info
)
3154 struct ppc_elf_link_hash_table
*htab
;
3160 fprintf (stderr
, "ppc_elf_size_dynamic_sections called\n");
3163 htab
= ppc_elf_hash_table (info
);
3164 BFD_ASSERT (htab
->elf
.dynobj
!= NULL
);
3166 if (elf_hash_table (info
)->dynamic_sections_created
)
3168 /* Set the contents of the .interp section to the interpreter. */
3169 if (info
->executable
)
3171 s
= bfd_get_section_by_name (htab
->elf
.dynobj
, ".interp");
3172 BFD_ASSERT (s
!= NULL
);
3173 s
->_raw_size
= sizeof ELF_DYNAMIC_INTERPRETER
;
3174 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
3178 if (htab
->tlsld_got
.refcount
> 0)
3180 htab
->tlsld_got
.offset
= htab
->got
->_raw_size
;
3181 htab
->got
->_raw_size
+= 8;
3183 htab
->relgot
->_raw_size
+= sizeof (Elf32_External_Rela
);
3186 htab
->tlsld_got
.offset
= (bfd_vma
) -1;
3188 /* Set up .got offsets for local syms, and space for local dynamic
3190 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
3192 bfd_signed_vma
*local_got
;
3193 bfd_signed_vma
*end_local_got
;
3195 bfd_size_type locsymcount
;
3196 Elf_Internal_Shdr
*symtab_hdr
;
3199 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
)
3202 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
3204 struct ppc_elf_dyn_relocs
*p
;
3206 for (p
= ((struct ppc_elf_dyn_relocs
*)
3207 elf_section_data (s
)->local_dynrel
);
3211 if (!bfd_is_abs_section (p
->sec
)
3212 && bfd_is_abs_section (p
->sec
->output_section
))
3214 /* Input section has been discarded, either because
3215 it is a copy of a linkonce section or due to
3216 linker script /DISCARD/, so we'll be discarding
3219 else if (p
->count
!= 0)
3221 elf_section_data (p
->sec
)->sreloc
->_raw_size
3222 += p
->count
* sizeof (Elf32_External_Rela
);
3223 if ((p
->sec
->output_section
->flags
3224 & (SEC_READONLY
| SEC_ALLOC
))
3225 == (SEC_READONLY
| SEC_ALLOC
))
3226 info
->flags
|= DF_TEXTREL
;
3231 local_got
= elf_local_got_refcounts (ibfd
);
3235 symtab_hdr
= &elf_tdata (ibfd
)->symtab_hdr
;
3236 locsymcount
= symtab_hdr
->sh_info
;
3237 end_local_got
= local_got
+ locsymcount
;
3238 lgot_masks
= (char *) end_local_got
;
3240 srel
= htab
->relgot
;
3241 for (; local_got
< end_local_got
; ++local_got
, ++lgot_masks
)
3244 if (*lgot_masks
== (TLS_TLS
| TLS_LD
))
3246 /* If just an LD reloc, we'll just use
3247 htab->tlsld_got.offset. */
3248 if (htab
->tlsld_got
.offset
== (bfd_vma
) -1)
3250 htab
->tlsld_got
.offset
= s
->_raw_size
;
3253 srel
->_raw_size
+= sizeof (Elf32_External_Rela
);
3255 *local_got
= (bfd_vma
) -1;
3259 *local_got
= s
->_raw_size
;
3260 if ((*lgot_masks
& TLS_TLS
) != 0)
3262 if ((*lgot_masks
& TLS_GD
) != 0)
3264 if ((*lgot_masks
& (TLS_TPREL
| TLS_TPRELGD
)) != 0)
3266 if ((*lgot_masks
& TLS_DTPREL
) != 0)
3272 srel
->_raw_size
+= ((s
->_raw_size
- *local_got
) / 4
3273 * sizeof (Elf32_External_Rela
));
3277 *local_got
= (bfd_vma
) -1;
3280 /* Allocate space for global sym dynamic relocs. */
3281 elf_link_hash_traverse (elf_hash_table (info
), allocate_dynrelocs
, info
);
3283 /* We've now determined the sizes of the various dynamic sections.
3284 Allocate memory for them. */
3286 for (s
= htab
->elf
.dynobj
->sections
; s
!= NULL
; s
= s
->next
)
3288 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
3293 || (htab
->sdata
!= NULL
&& s
== htab
->sdata
->section
)
3294 || (htab
->sdata2
!= NULL
&& s
== htab
->sdata2
->section
))
3296 /* Strip this section if we don't need it; see the
3299 else if (strncmp (bfd_get_section_name (dynobj
, s
), ".rela", 5) == 0)
3301 if (s
->_raw_size
== 0)
3303 /* If we don't need this section, strip it from the
3304 output file. This is mostly to handle .rela.bss and
3305 .rela.plt. We must create both sections in
3306 create_dynamic_sections, because they must be created
3307 before the linker maps input sections to output
3308 sections. The linker does that before
3309 adjust_dynamic_symbol is called, and it is that
3310 function which decides whether anything needs to go
3311 into these sections. */
3315 /* Remember whether there are any relocation sections. */
3318 /* We use the reloc_count field as a counter if we need
3319 to copy relocs into the output file. */
3325 /* It's not one of our sections, so don't allocate space. */
3329 if (s
->_raw_size
== 0)
3331 _bfd_strip_section_from_output (info
, s
);
3335 /* Allocate memory for the section contents. */
3336 s
->contents
= bfd_zalloc (htab
->elf
.dynobj
, s
->_raw_size
);
3337 if (s
->contents
== NULL
)
3341 if (htab
->elf
.dynamic_sections_created
)
3343 /* Add some entries to the .dynamic section. We fill in the
3344 values later, in ppc_elf_finish_dynamic_sections, but we
3345 must add the entries now so that we get the correct size for
3346 the .dynamic section. The DT_DEBUG entry is filled in by the
3347 dynamic linker and used by the debugger. */
3348 #define add_dynamic_entry(TAG, VAL) \
3349 bfd_elf32_add_dynamic_entry (info, (TAG), (VAL))
3351 if (info
->executable
)
3353 if (!add_dynamic_entry (DT_DEBUG
, 0))
3357 if (htab
->plt
!= NULL
&& htab
->plt
->_raw_size
!= 0)
3359 if (!add_dynamic_entry (DT_PLTGOT
, 0)
3360 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
3361 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
3362 || !add_dynamic_entry (DT_JMPREL
, 0))
3368 if (!add_dynamic_entry (DT_RELA
, 0)
3369 || !add_dynamic_entry (DT_RELASZ
, 0)
3370 || !add_dynamic_entry (DT_RELAENT
, sizeof (Elf32_External_Rela
)))
3374 /* If any dynamic relocs apply to a read-only section, then we
3375 need a DT_TEXTREL entry. */
3376 if ((info
->flags
& DF_TEXTREL
) == 0)
3377 elf_link_hash_traverse (elf_hash_table (info
), readonly_dynrelocs
,
3380 if ((info
->flags
& DF_TEXTREL
) != 0)
3382 if (!add_dynamic_entry (DT_TEXTREL
, 0))
3386 #undef add_dynamic_entry
3392 update_local_sym_info (bfd
*abfd
,
3393 Elf_Internal_Shdr
*symtab_hdr
,
3394 unsigned long r_symndx
,
3397 bfd_signed_vma
*local_got_refcounts
= elf_local_got_refcounts (abfd
);
3398 char *local_got_tls_masks
;
3400 if (local_got_refcounts
== NULL
)
3402 bfd_size_type size
= symtab_hdr
->sh_info
;
3404 size
*= sizeof (*local_got_refcounts
) + sizeof (*local_got_tls_masks
);
3405 local_got_refcounts
= bfd_zalloc (abfd
, size
);
3406 if (local_got_refcounts
== NULL
)
3408 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
3411 local_got_refcounts
[r_symndx
] += 1;
3412 local_got_tls_masks
= (char *) (local_got_refcounts
+ symtab_hdr
->sh_info
);
3413 local_got_tls_masks
[r_symndx
] |= tls_type
;
3418 bad_shared_reloc (bfd
*abfd
, enum elf_ppc_reloc_type r_type
)
3420 (*_bfd_error_handler
)
3421 (_("%s: relocation %s cannot be used when making a shared object"),
3422 bfd_archive_filename (abfd
),
3423 ppc_elf_howto_table
[r_type
]->name
);
3424 bfd_set_error (bfd_error_bad_value
);
3427 /* Look through the relocs for a section during the first phase, and
3428 allocate space in the global offset table or procedure linkage
3432 ppc_elf_check_relocs (bfd
*abfd
,
3433 struct bfd_link_info
*info
,
3435 const Elf_Internal_Rela
*relocs
)
3437 struct ppc_elf_link_hash_table
*htab
;
3438 Elf_Internal_Shdr
*symtab_hdr
;
3439 struct elf_link_hash_entry
**sym_hashes
;
3440 const Elf_Internal_Rela
*rel
;
3441 const Elf_Internal_Rela
*rel_end
;
3444 if (info
->relocatable
)
3448 fprintf (stderr
, "ppc_elf_check_relocs called for section %s in %s\n",
3449 bfd_get_section_name (abfd
, sec
),
3450 bfd_archive_filename (abfd
));
3453 /* Initialize howto table if not already done. */
3454 if (!ppc_elf_howto_table
[R_PPC_ADDR32
])
3455 ppc_elf_howto_init ();
3457 /* Create the linker generated sections all the time so that the
3458 special symbols are created. */
3459 htab
= ppc_elf_hash_table (info
);
3460 if (htab
->sdata
== NULL
)
3462 htab
->sdata
= elf_linker_section (abfd
, LINKER_SECTION_SDATA
);
3463 if (htab
->sdata
== NULL
)
3464 htab
->sdata
= ppc_elf_create_linker_section (abfd
, info
,
3465 LINKER_SECTION_SDATA
);
3466 if (htab
->sdata
== NULL
)
3470 if (htab
->sdata2
== NULL
)
3472 htab
->sdata2
= elf_linker_section (abfd
, LINKER_SECTION_SDATA2
);
3473 if (htab
->sdata2
== NULL
)
3474 htab
->sdata2
= ppc_elf_create_linker_section (abfd
, info
,
3475 LINKER_SECTION_SDATA2
);
3476 if (htab
->sdata2
== NULL
)
3480 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
3481 sym_hashes
= elf_sym_hashes (abfd
);
3484 rel_end
= relocs
+ sec
->reloc_count
;
3485 for (rel
= relocs
; rel
< rel_end
; rel
++)
3487 unsigned long r_symndx
;
3488 enum elf_ppc_reloc_type r_type
;
3489 struct elf_link_hash_entry
*h
;
3492 r_symndx
= ELF32_R_SYM (rel
->r_info
);
3493 if (r_symndx
< symtab_hdr
->sh_info
)
3496 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
3498 /* If a relocation refers to _GLOBAL_OFFSET_TABLE_, create the .got.
3499 This shows up in particular in an R_PPC_ADDR32 in the eabi
3501 if (h
&& strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
3503 if (htab
->got
== NULL
)
3505 if (htab
->elf
.dynobj
== NULL
)
3506 htab
->elf
.dynobj
= abfd
;
3507 if (!ppc_elf_create_got (htab
->elf
.dynobj
, info
))
3512 r_type
= ELF32_R_TYPE (rel
->r_info
);
3515 case R_PPC_GOT_TLSLD16
:
3516 case R_PPC_GOT_TLSLD16_LO
:
3517 case R_PPC_GOT_TLSLD16_HI
:
3518 case R_PPC_GOT_TLSLD16_HA
:
3519 htab
->tlsld_got
.refcount
+= 1;
3520 tls_type
= TLS_TLS
| TLS_LD
;
3523 case R_PPC_GOT_TLSGD16
:
3524 case R_PPC_GOT_TLSGD16_LO
:
3525 case R_PPC_GOT_TLSGD16_HI
:
3526 case R_PPC_GOT_TLSGD16_HA
:
3527 tls_type
= TLS_TLS
| TLS_GD
;
3530 case R_PPC_GOT_TPREL16
:
3531 case R_PPC_GOT_TPREL16_LO
:
3532 case R_PPC_GOT_TPREL16_HI
:
3533 case R_PPC_GOT_TPREL16_HA
:
3535 info
->flags
|= DF_STATIC_TLS
;
3536 tls_type
= TLS_TLS
| TLS_TPREL
;
3539 case R_PPC_GOT_DTPREL16
:
3540 case R_PPC_GOT_DTPREL16_LO
:
3541 case R_PPC_GOT_DTPREL16_HI
:
3542 case R_PPC_GOT_DTPREL16_HA
:
3543 tls_type
= TLS_TLS
| TLS_DTPREL
;
3545 sec
->has_tls_reloc
= 1;
3548 /* GOT16 relocations */
3550 case R_PPC_GOT16_LO
:
3551 case R_PPC_GOT16_HI
:
3552 case R_PPC_GOT16_HA
:
3553 /* This symbol requires a global offset table entry. */
3554 if (htab
->got
== NULL
)
3556 if (htab
->elf
.dynobj
== NULL
)
3557 htab
->elf
.dynobj
= abfd
;
3558 if (!ppc_elf_create_got (htab
->elf
.dynobj
, info
))
3563 h
->got
.refcount
+= 1;
3564 ppc_elf_hash_entry (h
)->tls_mask
|= tls_type
;
3567 /* This is a global offset table entry for a local symbol. */
3568 if (!update_local_sym_info (abfd
, symtab_hdr
, r_symndx
, tls_type
))
3572 /* Indirect .sdata relocation. */
3573 case R_PPC_EMB_SDAI16
:
3576 bad_shared_reloc (abfd
, r_type
);
3579 if (!elf_create_pointer_linker_section (abfd
, info
,
3580 htab
->sdata
, h
, rel
))
3584 /* Indirect .sdata2 relocation. */
3585 case R_PPC_EMB_SDA2I16
:
3588 bad_shared_reloc (abfd
, r_type
);
3591 if (!elf_create_pointer_linker_section (abfd
, info
,
3592 htab
->sdata2
, h
, rel
))
3596 case R_PPC_SDAREL16
:
3597 case R_PPC_EMB_SDA2REL
:
3598 case R_PPC_EMB_SDA21
:
3599 case R_PPC_EMB_RELSDA
:
3600 case R_PPC_EMB_NADDR32
:
3601 case R_PPC_EMB_NADDR16
:
3602 case R_PPC_EMB_NADDR16_LO
:
3603 case R_PPC_EMB_NADDR16_HI
:
3604 case R_PPC_EMB_NADDR16_HA
:
3607 bad_shared_reloc (abfd
, r_type
);
3613 case R_PPC_PLTREL24
:
3614 case R_PPC_PLTREL32
:
3615 case R_PPC_PLT16_LO
:
3616 case R_PPC_PLT16_HI
:
3617 case R_PPC_PLT16_HA
:
3619 fprintf (stderr
, "Reloc requires a PLT entry\n");
3621 /* This symbol requires a procedure linkage table entry. We
3622 actually build the entry in finish_dynamic_symbol,
3623 because this might be a case of linking PIC code without
3624 linking in any dynamic objects, in which case we don't
3625 need to generate a procedure linkage table after all. */
3629 /* It does not make sense to have a procedure linkage
3630 table entry for a local symbol. */
3631 (*_bfd_error_handler
) (_("%s(%s+0x%lx): %s reloc against "
3633 bfd_archive_filename (abfd
),
3635 (long) rel
->r_offset
,
3636 ppc_elf_howto_table
[r_type
]->name
);
3637 bfd_set_error (bfd_error_bad_value
);
3641 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
3645 /* The following relocations don't need to propagate the
3646 relocation if linking a shared object since they are
3647 section relative. */
3649 case R_PPC_SECTOFF_LO
:
3650 case R_PPC_SECTOFF_HI
:
3651 case R_PPC_SECTOFF_HA
:
3652 case R_PPC_DTPREL16
:
3653 case R_PPC_DTPREL16_LO
:
3654 case R_PPC_DTPREL16_HI
:
3655 case R_PPC_DTPREL16_HA
:
3659 /* This are just markers. */
3661 case R_PPC_EMB_MRKREF
:
3666 /* These should only appear in dynamic objects. */
3668 case R_PPC_GLOB_DAT
:
3669 case R_PPC_JMP_SLOT
:
3670 case R_PPC_RELATIVE
:
3673 /* These aren't handled yet. We'll report an error later. */
3675 case R_PPC_EMB_RELSEC16
:
3676 case R_PPC_EMB_RELST_LO
:
3677 case R_PPC_EMB_RELST_HI
:
3678 case R_PPC_EMB_RELST_HA
:
3679 case R_PPC_EMB_BIT_FLD
:
3682 /* This refers only to functions defined in the shared library. */
3683 case R_PPC_LOCAL24PC
:
3686 /* This relocation describes the C++ object vtable hierarchy.
3687 Reconstruct it for later use during GC. */
3688 case R_PPC_GNU_VTINHERIT
:
3689 if (!_bfd_elf32_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
3693 /* This relocation describes which C++ vtable entries are actually
3694 used. Record for later use during GC. */
3695 case R_PPC_GNU_VTENTRY
:
3696 if (!_bfd_elf32_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
3700 /* We shouldn't really be seeing these. */
3703 info
->flags
|= DF_STATIC_TLS
;
3707 case R_PPC_DTPMOD32
:
3708 case R_PPC_DTPREL32
:
3712 case R_PPC_TPREL16_LO
:
3713 case R_PPC_TPREL16_HI
:
3714 case R_PPC_TPREL16_HA
:
3716 info
->flags
|= DF_STATIC_TLS
;
3719 /* When creating a shared object, we must copy these
3720 relocs into the output file. We create a reloc
3721 section in dynobj and make room for the reloc. */
3724 case R_PPC_REL14_BRTAKEN
:
3725 case R_PPC_REL14_BRNTAKEN
:
3728 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
3735 case R_PPC_ADDR16_LO
:
3736 case R_PPC_ADDR16_HI
:
3737 case R_PPC_ADDR16_HA
:
3739 case R_PPC_ADDR14_BRTAKEN
:
3740 case R_PPC_ADDR14_BRNTAKEN
:
3743 if (h
!= NULL
&& !info
->shared
)
3745 /* We may need a plt entry if the symbol turns out to be
3746 a function defined in a dynamic object. */
3749 /* We may need a copy reloc too. */
3750 h
->elf_link_hash_flags
|= ELF_LINK_NON_GOT_REF
;
3754 /* If we are creating a shared library, and this is a reloc
3755 against a global symbol, or a non PC relative reloc
3756 against a local symbol, then we need to copy the reloc
3757 into the shared library. However, if we are linking with
3758 -Bsymbolic, we do not need to copy a reloc against a
3759 global symbol which is defined in an object we are
3760 including in the link (i.e., DEF_REGULAR is set). At
3761 this point we have not seen all the input files, so it is
3762 possible that DEF_REGULAR is not set now but will be set
3763 later (it is never cleared). In case of a weak definition,
3764 DEF_REGULAR may be cleared later by a strong definition in
3765 a shared library. We account for that possibility below by
3766 storing information in the dyn_relocs field of the hash
3767 table entry. A similar situation occurs when creating
3768 shared libraries and symbol visibility changes render the
3771 If on the other hand, we are creating an executable, we
3772 may need to keep relocations for symbols satisfied by a
3773 dynamic library if we manage to avoid copy relocs for the
3776 && (MUST_BE_DYN_RELOC (r_type
)
3778 && (! info
->symbolic
3779 || h
->root
.type
== bfd_link_hash_defweak
3780 || (h
->elf_link_hash_flags
3781 & ELF_LINK_HASH_DEF_REGULAR
) == 0))))
3782 || (ELIMINATE_COPY_RELOCS
3784 && (sec
->flags
& SEC_ALLOC
) != 0
3786 && (h
->root
.type
== bfd_link_hash_defweak
3787 || (h
->elf_link_hash_flags
3788 & ELF_LINK_HASH_DEF_REGULAR
) == 0)))
3790 struct ppc_elf_dyn_relocs
*p
;
3791 struct ppc_elf_dyn_relocs
**head
;
3795 "ppc_elf_check_relocs needs to "
3796 "create relocation for %s\n",
3797 (h
&& h
->root
.root
.string
3798 ? h
->root
.root
.string
: "<unknown>"));
3804 name
= (bfd_elf_string_from_elf_section
3806 elf_elfheader (abfd
)->e_shstrndx
,
3807 elf_section_data (sec
)->rel_hdr
.sh_name
));
3811 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
3812 && strcmp (bfd_get_section_name (abfd
, sec
),
3815 sreloc
= bfd_get_section_by_name (htab
->elf
.dynobj
, name
);
3820 sreloc
= bfd_make_section (htab
->elf
.dynobj
, name
);
3821 flags
= (SEC_HAS_CONTENTS
| SEC_READONLY
3822 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
3823 if ((sec
->flags
& SEC_ALLOC
) != 0)
3824 flags
|= SEC_ALLOC
| SEC_LOAD
;
3826 || ! bfd_set_section_flags (htab
->elf
.dynobj
,
3828 || ! bfd_set_section_alignment (htab
->elf
.dynobj
,
3832 elf_section_data (sec
)->sreloc
= sreloc
;
3835 /* If this is a global symbol, we count the number of
3836 relocations we need for this symbol. */
3839 head
= &ppc_elf_hash_entry (h
)->dyn_relocs
;
3843 /* Track dynamic relocs needed for local syms too.
3844 We really need local syms available to do this
3848 s
= bfd_section_from_r_symndx (abfd
, &htab
->sym_sec
,
3853 head
= ((struct ppc_elf_dyn_relocs
**)
3854 &elf_section_data (s
)->local_dynrel
);
3858 if (p
== NULL
|| p
->sec
!= sec
)
3860 p
= bfd_alloc (htab
->elf
.dynobj
, sizeof *p
);
3871 if (!MUST_BE_DYN_RELOC (r_type
))
3882 /* Return the section that should be marked against GC for a given
3886 ppc_elf_gc_mark_hook (asection
*sec
,
3887 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
3888 Elf_Internal_Rela
*rel
,
3889 struct elf_link_hash_entry
*h
,
3890 Elf_Internal_Sym
*sym
)
3894 switch (ELF32_R_TYPE (rel
->r_info
))
3896 case R_PPC_GNU_VTINHERIT
:
3897 case R_PPC_GNU_VTENTRY
:
3901 switch (h
->root
.type
)
3903 case bfd_link_hash_defined
:
3904 case bfd_link_hash_defweak
:
3905 return h
->root
.u
.def
.section
;
3907 case bfd_link_hash_common
:
3908 return h
->root
.u
.c
.p
->section
;
3916 return bfd_section_from_elf_index (sec
->owner
, sym
->st_shndx
);
3921 /* Update the got, plt and dynamic reloc reference counts for the
3922 section being removed. */
3925 ppc_elf_gc_sweep_hook (bfd
*abfd
,
3926 struct bfd_link_info
*info
,
3928 const Elf_Internal_Rela
*relocs
)
3930 struct ppc_elf_link_hash_table
*htab
;
3931 Elf_Internal_Shdr
*symtab_hdr
;
3932 struct elf_link_hash_entry
**sym_hashes
;
3933 bfd_signed_vma
*local_got_refcounts
;
3934 const Elf_Internal_Rela
*rel
, *relend
;
3936 elf_section_data (sec
)->local_dynrel
= NULL
;
3938 htab
= ppc_elf_hash_table (info
);
3939 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
3940 sym_hashes
= elf_sym_hashes (abfd
);
3941 local_got_refcounts
= elf_local_got_refcounts (abfd
);
3943 relend
= relocs
+ sec
->reloc_count
;
3944 for (rel
= relocs
; rel
< relend
; rel
++)
3946 unsigned long r_symndx
;
3947 enum elf_ppc_reloc_type r_type
;
3948 struct elf_link_hash_entry
*h
= NULL
;
3950 r_symndx
= ELF32_R_SYM (rel
->r_info
);
3951 if (r_symndx
>= symtab_hdr
->sh_info
)
3953 struct ppc_elf_dyn_relocs
**pp
, *p
;
3954 struct ppc_elf_link_hash_entry
*eh
;
3956 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
3957 eh
= (struct ppc_elf_link_hash_entry
*) h
;
3959 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; pp
= &p
->next
)
3962 /* Everything must go for SEC. */
3968 r_type
= ELF32_R_TYPE (rel
->r_info
);
3971 case R_PPC_GOT_TLSLD16
:
3972 case R_PPC_GOT_TLSLD16_LO
:
3973 case R_PPC_GOT_TLSLD16_HI
:
3974 case R_PPC_GOT_TLSLD16_HA
:
3975 htab
->tlsld_got
.refcount
-= 1;
3978 case R_PPC_GOT_TLSGD16
:
3979 case R_PPC_GOT_TLSGD16_LO
:
3980 case R_PPC_GOT_TLSGD16_HI
:
3981 case R_PPC_GOT_TLSGD16_HA
:
3982 case R_PPC_GOT_TPREL16
:
3983 case R_PPC_GOT_TPREL16_LO
:
3984 case R_PPC_GOT_TPREL16_HI
:
3985 case R_PPC_GOT_TPREL16_HA
:
3986 case R_PPC_GOT_DTPREL16
:
3987 case R_PPC_GOT_DTPREL16_LO
:
3988 case R_PPC_GOT_DTPREL16_HI
:
3989 case R_PPC_GOT_DTPREL16_HA
:
3991 case R_PPC_GOT16_LO
:
3992 case R_PPC_GOT16_HI
:
3993 case R_PPC_GOT16_HA
:
3996 if (h
->got
.refcount
> 0)
3999 else if (local_got_refcounts
!= NULL
)
4001 if (local_got_refcounts
[r_symndx
] > 0)
4002 local_got_refcounts
[r_symndx
]--;
4008 case R_PPC_REL14_BRTAKEN
:
4009 case R_PPC_REL14_BRNTAKEN
:
4012 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
4019 case R_PPC_ADDR16_LO
:
4020 case R_PPC_ADDR16_HI
:
4021 case R_PPC_ADDR16_HA
:
4023 case R_PPC_ADDR14_BRTAKEN
:
4024 case R_PPC_ADDR14_BRNTAKEN
:
4028 case R_PPC_PLTREL24
:
4029 case R_PPC_PLT16_LO
:
4030 case R_PPC_PLT16_HI
:
4031 case R_PPC_PLT16_HA
:
4034 if (h
->plt
.refcount
> 0)
4046 /* Set htab->tls_sec and htab->tls_get_addr. */
4049 ppc_elf_tls_setup (bfd
*obfd
, struct bfd_link_info
*info
)
4052 struct ppc_elf_link_hash_table
*htab
;
4054 htab
= ppc_elf_hash_table (info
);
4055 htab
->tls_get_addr
= elf_link_hash_lookup (&htab
->elf
, "__tls_get_addr",
4056 FALSE
, FALSE
, TRUE
);
4058 for (tls
= obfd
->sections
; tls
!= NULL
; tls
= tls
->next
)
4059 if ((tls
->flags
& (SEC_THREAD_LOCAL
| SEC_LOAD
))
4060 == (SEC_THREAD_LOCAL
| SEC_LOAD
))
4062 htab
->tls_sec
= tls
;
4067 /* Run through all the TLS relocs looking for optimization
4071 ppc_elf_tls_optimize (bfd
*obfd ATTRIBUTE_UNUSED
,
4072 struct bfd_link_info
*info
)
4076 struct ppc_elf_link_hash_table
*htab
;
4078 if (info
->relocatable
|| info
->shared
)
4081 htab
= ppc_elf_hash_table (info
);
4082 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
4084 Elf_Internal_Sym
*locsyms
= NULL
;
4085 Elf_Internal_Shdr
*symtab_hdr
= &elf_tdata (ibfd
)->symtab_hdr
;
4087 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
4088 if (sec
->has_tls_reloc
&& !bfd_is_abs_section (sec
->output_section
))
4090 Elf_Internal_Rela
*relstart
, *rel
, *relend
;
4091 int expecting_tls_get_addr
;
4093 /* Read the relocations. */
4094 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
4096 if (relstart
== NULL
)
4099 expecting_tls_get_addr
= 0;
4100 relend
= relstart
+ sec
->reloc_count
;
4101 for (rel
= relstart
; rel
< relend
; rel
++)
4103 enum elf_ppc_reloc_type r_type
;
4104 unsigned long r_symndx
;
4105 struct elf_link_hash_entry
*h
= NULL
;
4107 char tls_set
, tls_clear
;
4108 bfd_boolean is_local
;
4110 r_symndx
= ELF32_R_SYM (rel
->r_info
);
4111 if (r_symndx
>= symtab_hdr
->sh_info
)
4113 struct elf_link_hash_entry
**sym_hashes
;
4115 sym_hashes
= elf_sym_hashes (ibfd
);
4116 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
4117 while (h
->root
.type
== bfd_link_hash_indirect
4118 || h
->root
.type
== bfd_link_hash_warning
)
4119 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
4124 || !(h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
))
4127 r_type
= ELF32_R_TYPE (rel
->r_info
);
4130 case R_PPC_GOT_TLSLD16
:
4131 case R_PPC_GOT_TLSLD16_LO
:
4132 case R_PPC_GOT_TLSLD16_HI
:
4133 case R_PPC_GOT_TLSLD16_HA
:
4134 /* These relocs should never be against a symbol
4135 defined in a shared lib. Leave them alone if
4136 that turns out to be the case. */
4137 expecting_tls_get_addr
= 0;
4138 htab
->tlsld_got
.refcount
-= 1;
4145 expecting_tls_get_addr
= 1;
4148 case R_PPC_GOT_TLSGD16
:
4149 case R_PPC_GOT_TLSGD16_LO
:
4150 case R_PPC_GOT_TLSGD16_HI
:
4151 case R_PPC_GOT_TLSGD16_HA
:
4157 tls_set
= TLS_TLS
| TLS_TPRELGD
;
4159 expecting_tls_get_addr
= 1;
4162 case R_PPC_GOT_TPREL16
:
4163 case R_PPC_GOT_TPREL16_LO
:
4164 case R_PPC_GOT_TPREL16_HI
:
4165 case R_PPC_GOT_TPREL16_HA
:
4166 expecting_tls_get_addr
= 0;
4171 tls_clear
= TLS_TPREL
;
4178 case R_PPC_REL14_BRTAKEN
:
4179 case R_PPC_REL14_BRNTAKEN
:
4181 if (expecting_tls_get_addr
4183 && h
== htab
->tls_get_addr
)
4185 if (h
->plt
.refcount
> 0)
4186 h
->plt
.refcount
-= 1;
4188 expecting_tls_get_addr
= 0;
4192 expecting_tls_get_addr
= 0;
4200 /* We managed to get rid of a got entry. */
4201 if (h
->got
.refcount
> 0)
4202 h
->got
.refcount
-= 1;
4204 tls_mask
= &ppc_elf_hash_entry (h
)->tls_mask
;
4208 Elf_Internal_Sym
*sym
;
4209 bfd_signed_vma
*lgot_refs
;
4212 if (locsyms
== NULL
)
4214 locsyms
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
4215 if (locsyms
== NULL
)
4216 locsyms
= bfd_elf_get_elf_syms (ibfd
, symtab_hdr
,
4217 symtab_hdr
->sh_info
,
4218 0, NULL
, NULL
, NULL
);
4219 if (locsyms
== NULL
)
4221 if (elf_section_data (sec
)->relocs
!= relstart
)
4226 sym
= locsyms
+ r_symndx
;
4227 lgot_refs
= elf_local_got_refcounts (ibfd
);
4228 if (lgot_refs
== NULL
)
4232 /* We managed to get rid of a got entry. */
4233 if (lgot_refs
[r_symndx
] > 0)
4234 lgot_refs
[r_symndx
] -= 1;
4236 lgot_masks
= (char *) (lgot_refs
+ symtab_hdr
->sh_info
);
4237 tls_mask
= &lgot_masks
[r_symndx
];
4240 *tls_mask
|= tls_set
;
4241 *tls_mask
&= ~tls_clear
;
4244 if (elf_section_data (sec
)->relocs
!= relstart
)
4249 && (symtab_hdr
->contents
!= (unsigned char *) locsyms
))
4251 if (!info
->keep_memory
)
4254 symtab_hdr
->contents
= (unsigned char *) locsyms
;
4260 /* Hook called by the linker routine which adds symbols from an object
4261 file. We use it to put .comm items in .sbss, and not .bss. */
4264 ppc_elf_add_symbol_hook (bfd
*abfd
,
4265 struct bfd_link_info
*info
,
4266 const Elf_Internal_Sym
*sym
,
4267 const char **namep ATTRIBUTE_UNUSED
,
4268 flagword
*flagsp ATTRIBUTE_UNUSED
,
4272 if (sym
->st_shndx
== SHN_COMMON
4273 && !info
->relocatable
4274 && sym
->st_size
<= elf_gp_size (abfd
)
4275 && info
->hash
->creator
->flavour
== bfd_target_elf_flavour
)
4277 /* Common symbols less than or equal to -G nn bytes are automatically
4279 elf_linker_section_t
*sdata
4280 = ppc_elf_create_linker_section (abfd
, info
, LINKER_SECTION_SDATA
);
4282 if (!sdata
->bss_section
)
4286 /* We don't go through bfd_make_section, because we don't
4287 want to attach this common section to DYNOBJ. The linker
4288 will move the symbols to the appropriate output section
4289 when it defines common symbols. */
4290 amt
= sizeof (asection
);
4291 sdata
->bss_section
= bfd_zalloc (abfd
, amt
);
4292 if (sdata
->bss_section
== NULL
)
4294 sdata
->bss_section
->name
= sdata
->bss_name
;
4295 sdata
->bss_section
->flags
= SEC_IS_COMMON
;
4296 sdata
->bss_section
->output_section
= sdata
->bss_section
;
4297 amt
= sizeof (asymbol
);
4298 sdata
->bss_section
->symbol
= bfd_zalloc (abfd
, amt
);
4299 amt
= sizeof (asymbol
*);
4300 sdata
->bss_section
->symbol_ptr_ptr
= bfd_zalloc (abfd
, amt
);
4301 if (sdata
->bss_section
->symbol
== NULL
4302 || sdata
->bss_section
->symbol_ptr_ptr
== NULL
)
4304 sdata
->bss_section
->symbol
->name
= sdata
->bss_name
;
4305 sdata
->bss_section
->symbol
->flags
= BSF_SECTION_SYM
;
4306 sdata
->bss_section
->symbol
->section
= sdata
->bss_section
;
4307 *sdata
->bss_section
->symbol_ptr_ptr
= sdata
->bss_section
->symbol
;
4310 *secp
= sdata
->bss_section
;
4311 *valp
= sym
->st_size
;
4317 /* Finish up dynamic symbol handling. We set the contents of various
4318 dynamic sections here. */
4321 ppc_elf_finish_dynamic_symbol (bfd
*output_bfd
,
4322 struct bfd_link_info
*info
,
4323 struct elf_link_hash_entry
*h
,
4324 Elf_Internal_Sym
*sym
)
4326 struct ppc_elf_link_hash_table
*htab
;
4329 fprintf (stderr
, "ppc_elf_finish_dynamic_symbol called for %s",
4330 h
->root
.root
.string
);
4333 htab
= ppc_elf_hash_table (info
);
4334 BFD_ASSERT (htab
->elf
.dynobj
!= NULL
);
4336 if (h
->plt
.offset
!= (bfd_vma
) -1)
4338 Elf_Internal_Rela rela
;
4340 bfd_vma reloc_index
;
4343 fprintf (stderr
, ", plt_offset = %d", h
->plt
.offset
);
4346 /* This symbol has an entry in the procedure linkage table. Set
4349 BFD_ASSERT (h
->dynindx
!= -1);
4350 BFD_ASSERT (htab
->plt
!= NULL
&& htab
->relplt
!= NULL
);
4352 /* We don't need to fill in the .plt. The ppc dynamic linker
4355 /* Fill in the entry in the .rela.plt section. */
4356 rela
.r_offset
= (htab
->plt
->output_section
->vma
4357 + htab
->plt
->output_offset
4359 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_PPC_JMP_SLOT
);
4362 reloc_index
= (h
->plt
.offset
- PLT_INITIAL_ENTRY_SIZE
) / PLT_SLOT_SIZE
;
4363 if (reloc_index
> PLT_NUM_SINGLE_ENTRIES
)
4364 reloc_index
-= (reloc_index
- PLT_NUM_SINGLE_ENTRIES
) / 2;
4365 loc
= (htab
->relplt
->contents
4366 + reloc_index
* sizeof (Elf32_External_Rela
));
4367 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
4369 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
4371 /* Mark the symbol as undefined, rather than as defined in
4372 the .plt section. Leave the value alone. */
4373 sym
->st_shndx
= SHN_UNDEF
;
4374 /* If the symbol is weak, we do need to clear the value.
4375 Otherwise, the PLT entry would provide a definition for
4376 the symbol even if the symbol wasn't defined anywhere,
4377 and so the symbol would never be NULL. */
4378 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_REF_REGULAR_NONWEAK
)
4384 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_COPY
) != 0)
4387 Elf_Internal_Rela rela
;
4390 /* This symbols needs a copy reloc. Set it up. */
4393 fprintf (stderr
, ", copy");
4396 BFD_ASSERT (h
->dynindx
!= -1);
4398 if (h
->size
<= elf_gp_size (htab
->elf
.dynobj
))
4402 BFD_ASSERT (s
!= NULL
);
4404 rela
.r_offset
= (h
->root
.u
.def
.value
4405 + h
->root
.u
.def
.section
->output_section
->vma
4406 + h
->root
.u
.def
.section
->output_offset
);
4407 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_PPC_COPY
);
4409 loc
= s
->contents
+ s
->reloc_count
++ * sizeof (Elf32_External_Rela
);
4410 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
4414 fprintf (stderr
, "\n");
4417 /* Mark some specially defined symbols as absolute. */
4418 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
4419 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0
4420 || strcmp (h
->root
.root
.string
, "_PROCEDURE_LINKAGE_TABLE_") == 0)
4421 sym
->st_shndx
= SHN_ABS
;
4426 /* Finish up the dynamic sections. */
4429 ppc_elf_finish_dynamic_sections (bfd
*output_bfd
,
4430 struct bfd_link_info
*info
)
4433 struct ppc_elf_link_hash_table
*htab
;
4436 fprintf (stderr
, "ppc_elf_finish_dynamic_sections called\n");
4439 htab
= ppc_elf_hash_table (info
);
4440 sdyn
= bfd_get_section_by_name (htab
->elf
.dynobj
, ".dynamic");
4442 if (htab
->elf
.dynamic_sections_created
)
4444 Elf32_External_Dyn
*dyncon
, *dynconend
;
4446 BFD_ASSERT (htab
->plt
!= NULL
&& sdyn
!= NULL
);
4448 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
4449 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
4450 for (; dyncon
< dynconend
; dyncon
++)
4452 Elf_Internal_Dyn dyn
;
4455 bfd_elf32_swap_dyn_in (htab
->elf
.dynobj
, dyncon
, &dyn
);
4461 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
4465 dyn
.d_un
.d_val
= htab
->relplt
->_raw_size
;
4470 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
4477 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
4481 /* Add a blrl instruction at _GLOBAL_OFFSET_TABLE_-4 so that a function can
4482 easily find the address of the _GLOBAL_OFFSET_TABLE_. */
4485 unsigned char *contents
= htab
->got
->contents
;
4486 bfd_put_32 (output_bfd
, 0x4e800021 /* blrl */, contents
);
4489 bfd_put_32 (output_bfd
, 0, contents
+ 4);
4491 bfd_put_32 (output_bfd
,
4492 sdyn
->output_section
->vma
+ sdyn
->output_offset
,
4495 elf_section_data (htab
->got
->output_section
)->this_hdr
.sh_entsize
= 4;
4501 /* The RELOCATE_SECTION function is called by the ELF backend linker
4502 to handle the relocations for a section.
4504 The relocs are always passed as Rela structures; if the section
4505 actually uses Rel structures, the r_addend field will always be
4508 This function is responsible for adjust the section contents as
4509 necessary, and (if using Rela relocs and generating a
4510 relocatable output file) adjusting the reloc addend as
4513 This function does not have to worry about setting the reloc
4514 address or the reloc symbol index.
4516 LOCAL_SYMS is a pointer to the swapped in local symbols.
4518 LOCAL_SECTIONS is an array giving the section in the input file
4519 corresponding to the st_shndx field of each local symbol.
4521 The global hash table entry for the global symbols can be found
4522 via elf_sym_hashes (input_bfd).
4524 When generating relocatable output, this function must handle
4525 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
4526 going to be the section symbol corresponding to the output
4527 section, which means that the addend must be adjusted
4531 ppc_elf_relocate_section (bfd
*output_bfd
,
4532 struct bfd_link_info
*info
,
4534 asection
*input_section
,
4536 Elf_Internal_Rela
*relocs
,
4537 Elf_Internal_Sym
*local_syms
,
4538 asection
**local_sections
)
4540 Elf_Internal_Shdr
*symtab_hdr
;
4541 struct elf_link_hash_entry
**sym_hashes
;
4542 struct ppc_elf_link_hash_table
*htab
;
4543 Elf_Internal_Rela
*rel
;
4544 Elf_Internal_Rela
*relend
;
4545 Elf_Internal_Rela outrel
;
4547 asection
*sreloc
= NULL
;
4548 bfd_vma
*local_got_offsets
;
4549 bfd_boolean ret
= TRUE
;
4552 fprintf (stderr
, "ppc_elf_relocate_section called for %s section %s, "
4553 "%ld relocations%s\n",
4554 bfd_archive_filename (input_bfd
),
4555 bfd_section_name(input_bfd
, input_section
),
4556 (long) input_section
->reloc_count
,
4557 (info
->relocatable
) ? " (relocatable)" : "");
4560 if (info
->relocatable
)
4563 /* Initialize howto table if not already done. */
4564 if (!ppc_elf_howto_table
[R_PPC_ADDR32
])
4565 ppc_elf_howto_init ();
4567 htab
= ppc_elf_hash_table (info
);
4568 local_got_offsets
= elf_local_got_offsets (input_bfd
);
4569 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
4570 sym_hashes
= elf_sym_hashes (input_bfd
);
4572 relend
= relocs
+ input_section
->reloc_count
;
4573 for (; rel
< relend
; rel
++)
4575 enum elf_ppc_reloc_type r_type
;
4577 bfd_reloc_status_type r
;
4578 Elf_Internal_Sym
*sym
;
4580 struct elf_link_hash_entry
*h
;
4581 const char *sym_name
;
4582 reloc_howto_type
*howto
;
4583 unsigned long r_symndx
;
4585 bfd_vma branch_bit
, insn
, from
;
4586 bfd_boolean unresolved_reloc
;
4588 unsigned int tls_type
, tls_mask
, tls_gd
;
4590 r_type
= ELF32_R_TYPE (rel
->r_info
);
4594 unresolved_reloc
= FALSE
;
4596 r_symndx
= ELF32_R_SYM (rel
->r_info
);
4597 if (r_symndx
< symtab_hdr
->sh_info
)
4599 sym
= local_syms
+ r_symndx
;
4600 sec
= local_sections
[r_symndx
];
4601 sym_name
= bfd_elf_local_sym_name (input_bfd
, sym
);
4603 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, sec
, rel
);
4607 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
4608 while (h
->root
.type
== bfd_link_hash_indirect
4609 || h
->root
.type
== bfd_link_hash_warning
)
4610 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
4611 sym_name
= h
->root
.root
.string
;
4614 if (h
->root
.type
== bfd_link_hash_defined
4615 || h
->root
.type
== bfd_link_hash_defweak
)
4617 sec
= h
->root
.u
.def
.section
;
4618 /* Set a flag that will be cleared later if we find a
4619 relocation value for this symbol. output_section
4620 is typically NULL for symbols satisfied by a shared
4622 if (sec
->output_section
== NULL
)
4623 unresolved_reloc
= TRUE
;
4625 relocation
= (h
->root
.u
.def
.value
4626 + sec
->output_section
->vma
4627 + sec
->output_offset
);
4629 else if (h
->root
.type
== bfd_link_hash_undefweak
)
4631 else if (!info
->executable
4632 && !info
->no_undefined
4633 && ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
)
4637 if (! ((*info
->callbacks
->undefined_symbol
)
4638 (info
, h
->root
.root
.string
, input_bfd
, input_section
,
4639 rel
->r_offset
, (!info
->shared
4640 || info
->no_undefined
4641 || ELF_ST_VISIBILITY (h
->other
)))))
4647 /* TLS optimizations. Replace instruction sequences and relocs
4648 based on information we collected in tls_optimize. We edit
4649 RELOCS so that --emit-relocs will output something sensible
4650 for the final instruction stream. */
4653 if (IS_PPC_TLS_RELOC (r_type
))
4656 tls_mask
= ((struct ppc_elf_link_hash_entry
*) h
)->tls_mask
;
4657 else if (local_got_offsets
!= NULL
)
4660 lgot_masks
= (char *) (local_got_offsets
+ symtab_hdr
->sh_info
);
4661 tls_mask
= lgot_masks
[r_symndx
];
4665 /* Ensure reloc mapping code below stays sane. */
4666 if ((R_PPC_GOT_TLSLD16
& 3) != (R_PPC_GOT_TLSGD16
& 3)
4667 || (R_PPC_GOT_TLSLD16_LO
& 3) != (R_PPC_GOT_TLSGD16_LO
& 3)
4668 || (R_PPC_GOT_TLSLD16_HI
& 3) != (R_PPC_GOT_TLSGD16_HI
& 3)
4669 || (R_PPC_GOT_TLSLD16_HA
& 3) != (R_PPC_GOT_TLSGD16_HA
& 3)
4670 || (R_PPC_GOT_TLSLD16
& 3) != (R_PPC_GOT_TPREL16
& 3)
4671 || (R_PPC_GOT_TLSLD16_LO
& 3) != (R_PPC_GOT_TPREL16_LO
& 3)
4672 || (R_PPC_GOT_TLSLD16_HI
& 3) != (R_PPC_GOT_TPREL16_HI
& 3)
4673 || (R_PPC_GOT_TLSLD16_HA
& 3) != (R_PPC_GOT_TPREL16_HA
& 3))
4680 case R_PPC_GOT_TPREL16
:
4681 case R_PPC_GOT_TPREL16_LO
:
4683 && (tls_mask
& TLS_TPREL
) == 0)
4686 insn
= bfd_get_32 (output_bfd
, contents
+ rel
->r_offset
- 2);
4688 insn
|= 0x3c020000; /* addis 0,2,0 */
4689 bfd_put_32 (output_bfd
, insn
, contents
+ rel
->r_offset
- 2);
4690 r_type
= R_PPC_TPREL16_HA
;
4691 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
4697 && (tls_mask
& TLS_TPREL
) == 0)
4700 insn
= bfd_get_32 (output_bfd
, contents
+ rel
->r_offset
);
4701 if ((insn
& ((31 << 26) | (31 << 11)))
4702 == ((31 << 26) | (2 << 11)))
4703 rtra
= insn
& ((1 << 26) - (1 << 16));
4704 else if ((insn
& ((31 << 26) | (31 << 16)))
4705 == ((31 << 26) | (2 << 16)))
4706 rtra
= (insn
& (31 << 21)) | ((insn
& (31 << 11)) << 5);
4709 if ((insn
& ((1 << 11) - (1 << 1))) == 266 << 1)
4712 else if ((insn
& (31 << 1)) == 23 << 1
4713 && ((insn
& (31 << 6)) < 14 << 6
4714 || ((insn
& (31 << 6)) >= 16 << 6
4715 && (insn
& (31 << 6)) < 24 << 6)))
4716 /* load and store indexed -> dform. */
4717 insn
= (32 | ((insn
>> 6) & 31)) << 26;
4718 else if ((insn
& (31 << 1)) == 21 << 1
4719 && (insn
& (0x1a << 6)) == 0)
4720 /* ldx, ldux, stdx, stdux -> ld, ldu, std, stdu. */
4721 insn
= (((58 | ((insn
>> 6) & 4)) << 26)
4722 | ((insn
>> 6) & 1));
4723 else if ((insn
& (31 << 1)) == 21 << 1
4724 && (insn
& ((1 << 11) - (1 << 1))) == 341 << 1)
4726 insn
= (58 << 26) | 2;
4730 bfd_put_32 (output_bfd
, insn
, contents
+ rel
->r_offset
);
4731 r_type
= R_PPC_TPREL16_LO
;
4732 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
4733 /* Was PPC_TLS which sits on insn boundary, now
4734 PPC_TPREL16_LO which is at insn+2. */
4739 case R_PPC_GOT_TLSGD16_HI
:
4740 case R_PPC_GOT_TLSGD16_HA
:
4741 tls_gd
= TLS_TPRELGD
;
4742 if (tls_mask
!= 0 && (tls_mask
& TLS_GD
) == 0)
4746 case R_PPC_GOT_TLSLD16_HI
:
4747 case R_PPC_GOT_TLSLD16_HA
:
4748 if (tls_mask
!= 0 && (tls_mask
& TLS_LD
) == 0)
4751 if ((tls_mask
& tls_gd
) != 0)
4752 r_type
= (((r_type
- (R_PPC_GOT_TLSGD16
& 3)) & 3)
4753 + R_PPC_GOT_TPREL16
);
4756 bfd_put_32 (output_bfd
, NOP
, contents
+ rel
->r_offset
);
4758 r_type
= R_PPC_NONE
;
4760 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
4764 case R_PPC_GOT_TLSGD16
:
4765 case R_PPC_GOT_TLSGD16_LO
:
4766 tls_gd
= TLS_TPRELGD
;
4767 if (tls_mask
!= 0 && (tls_mask
& TLS_GD
) == 0)
4768 goto tls_get_addr_check
;
4771 case R_PPC_GOT_TLSLD16
:
4772 case R_PPC_GOT_TLSLD16_LO
:
4773 if (tls_mask
!= 0 && (tls_mask
& TLS_LD
) == 0)
4776 if (rel
+ 1 < relend
)
4778 enum elf_ppc_reloc_type r_type2
;
4779 unsigned long r_symndx2
;
4780 struct elf_link_hash_entry
*h2
;
4781 bfd_vma insn1
, insn2
;
4784 /* The next instruction should be a call to
4785 __tls_get_addr. Peek at the reloc to be sure. */
4786 r_type2
= ELF32_R_TYPE (rel
[1].r_info
);
4787 r_symndx2
= ELF32_R_SYM (rel
[1].r_info
);
4788 if (r_symndx2
< symtab_hdr
->sh_info
4789 || (r_type2
!= R_PPC_REL14
4790 && r_type2
!= R_PPC_REL14_BRTAKEN
4791 && r_type2
!= R_PPC_REL14_BRNTAKEN
4792 && r_type2
!= R_PPC_REL24
4793 && r_type2
!= R_PPC_PLTREL24
))
4796 h2
= sym_hashes
[r_symndx2
- symtab_hdr
->sh_info
];
4797 while (h2
->root
.type
== bfd_link_hash_indirect
4798 || h2
->root
.type
== bfd_link_hash_warning
)
4799 h2
= (struct elf_link_hash_entry
*) h2
->root
.u
.i
.link
;
4800 if (h2
== NULL
|| h2
!= htab
->tls_get_addr
)
4803 /* OK, it checks out. Replace the call. */
4804 offset
= rel
[1].r_offset
;
4805 insn1
= bfd_get_32 (output_bfd
,
4806 contents
+ rel
->r_offset
- 2);
4807 if ((tls_mask
& tls_gd
) != 0)
4810 insn1
&= (1 << 26) - 1;
4811 insn1
|= 32 << 26; /* lwz */
4812 insn2
= 0x7c631214; /* add 3,3,2 */
4813 rel
[1].r_info
= ELF32_R_INFO (r_symndx2
, R_PPC_NONE
);
4814 r_type
= (((r_type
- (R_PPC_GOT_TLSGD16
& 3)) & 3)
4815 + R_PPC_GOT_TPREL16
);
4816 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
4821 insn1
= 0x3c620000; /* addis 3,2,0 */
4822 insn2
= 0x38630000; /* addi 3,3,0 */
4825 /* Was an LD reloc. */
4827 rel
->r_addend
= htab
->tls_sec
->vma
+ DTP_OFFSET
;
4828 rel
[1].r_addend
= htab
->tls_sec
->vma
+ DTP_OFFSET
;
4830 r_type
= R_PPC_TPREL16_HA
;
4831 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
4832 rel
[1].r_info
= ELF32_R_INFO (r_symndx
,
4834 rel
[1].r_offset
+= 2;
4836 bfd_put_32 (output_bfd
, insn1
, contents
+ rel
->r_offset
- 2);
4837 bfd_put_32 (output_bfd
, insn2
, contents
+ offset
);
4840 /* We changed the symbol on an LD reloc. Start over
4841 in order to get h, sym, sec etc. right. */
4850 /* Handle other relocations that tweak non-addend part of insn. */
4857 /* Branch taken prediction relocations. */
4858 case R_PPC_ADDR14_BRTAKEN
:
4859 case R_PPC_REL14_BRTAKEN
:
4860 branch_bit
= BRANCH_PREDICT_BIT
;
4863 /* Branch not taken predicition relocations. */
4864 case R_PPC_ADDR14_BRNTAKEN
:
4865 case R_PPC_REL14_BRNTAKEN
:
4866 insn
= bfd_get_32 (output_bfd
, contents
+ rel
->r_offset
);
4867 insn
&= ~BRANCH_PREDICT_BIT
;
4870 from
= (rel
->r_offset
4871 + input_section
->output_offset
4872 + input_section
->output_section
->vma
);
4874 /* Invert 'y' bit if not the default. */
4875 if ((bfd_signed_vma
) (relocation
+ rel
->r_addend
- from
) < 0)
4876 insn
^= BRANCH_PREDICT_BIT
;
4878 bfd_put_32 (output_bfd
, insn
, contents
+ rel
->r_offset
);
4882 addend
= rel
->r_addend
;
4885 if (r_type
< R_PPC_max
)
4886 howto
= ppc_elf_howto_table
[r_type
];
4890 (*_bfd_error_handler
)
4891 (_("%s: unknown relocation type %d for symbol %s"),
4892 bfd_archive_filename (input_bfd
), (int) r_type
, sym_name
);
4894 bfd_set_error (bfd_error_bad_value
);
4900 case R_PPC_EMB_MRKREF
:
4901 case R_PPC_GNU_VTINHERIT
:
4902 case R_PPC_GNU_VTENTRY
:
4905 /* GOT16 relocations. Like an ADDR16 using the symbol's
4906 address in the GOT as relocation value instead of the
4907 symbol's value itself. Also, create a GOT entry for the
4908 symbol and put the symbol value there. */
4909 case R_PPC_GOT_TLSGD16
:
4910 case R_PPC_GOT_TLSGD16_LO
:
4911 case R_PPC_GOT_TLSGD16_HI
:
4912 case R_PPC_GOT_TLSGD16_HA
:
4913 tls_type
= TLS_TLS
| TLS_GD
;
4916 case R_PPC_GOT_TLSLD16
:
4917 case R_PPC_GOT_TLSLD16_LO
:
4918 case R_PPC_GOT_TLSLD16_HI
:
4919 case R_PPC_GOT_TLSLD16_HA
:
4920 tls_type
= TLS_TLS
| TLS_LD
;
4923 case R_PPC_GOT_TPREL16
:
4924 case R_PPC_GOT_TPREL16_LO
:
4925 case R_PPC_GOT_TPREL16_HI
:
4926 case R_PPC_GOT_TPREL16_HA
:
4927 tls_type
= TLS_TLS
| TLS_TPREL
;
4930 case R_PPC_GOT_DTPREL16
:
4931 case R_PPC_GOT_DTPREL16_LO
:
4932 case R_PPC_GOT_DTPREL16_HI
:
4933 case R_PPC_GOT_DTPREL16_HA
:
4934 tls_type
= TLS_TLS
| TLS_DTPREL
;
4938 case R_PPC_GOT16_LO
:
4939 case R_PPC_GOT16_HI
:
4940 case R_PPC_GOT16_HA
:
4943 /* Relocation is to the entry for this symbol in the global
4949 if (htab
->got
== NULL
)
4953 if (tls_type
== (TLS_TLS
| TLS_LD
)
4955 || !(h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
)))
4956 offp
= &htab
->tlsld_got
.offset
;
4960 dyn
= htab
->elf
.dynamic_sections_created
;
4961 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
4963 && SYMBOL_REFERENCES_LOCAL (info
, h
)))
4964 /* This is actually a static link, or it is a
4965 -Bsymbolic link and the symbol is defined
4966 locally, or the symbol was forced to be local
4967 because of a version file. */
4972 unresolved_reloc
= FALSE
;
4974 offp
= &h
->got
.offset
;
4978 if (local_got_offsets
== NULL
)
4980 offp
= &local_got_offsets
[r_symndx
];
4983 /* The offset must always be a multiple of 4. We use the
4984 least significant bit to record whether we have already
4985 processed this entry. */
4991 unsigned int tls_m
= (tls_mask
4992 & (TLS_LD
| TLS_GD
| TLS_DTPREL
4993 | TLS_TPREL
| TLS_TPRELGD
));
4995 if (offp
== &htab
->tlsld_got
.offset
)
4998 || !(h
->elf_link_hash_flags
4999 & ELF_LINK_HASH_DEF_DYNAMIC
))
5002 /* We might have multiple got entries for this sym.
5003 Initialize them all. */
5008 if ((tls_m
& TLS_LD
) != 0)
5010 tls_ty
= TLS_TLS
| TLS_LD
;
5013 else if ((tls_m
& TLS_GD
) != 0)
5015 tls_ty
= TLS_TLS
| TLS_GD
;
5018 else if ((tls_m
& TLS_DTPREL
) != 0)
5020 tls_ty
= TLS_TLS
| TLS_DTPREL
;
5021 tls_m
&= ~TLS_DTPREL
;
5023 else if ((tls_m
& (TLS_TPREL
| TLS_TPRELGD
)) != 0)
5025 tls_ty
= TLS_TLS
| TLS_TPREL
;
5029 /* Generate relocs for the dynamic linker. */
5030 if ((info
->shared
|| indx
!= 0)
5032 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
5033 || h
->root
.type
!= bfd_link_hash_undefweak
))
5035 outrel
.r_offset
= (htab
->got
->output_section
->vma
5036 + htab
->got
->output_offset
5038 outrel
.r_addend
= 0;
5039 if (tls_ty
& (TLS_LD
| TLS_GD
))
5041 outrel
.r_info
= ELF32_R_INFO (indx
, R_PPC_DTPMOD32
);
5042 if (tls_ty
== (TLS_TLS
| TLS_GD
))
5044 loc
= htab
->relgot
->contents
;
5045 loc
+= (htab
->relgot
->reloc_count
++
5046 * sizeof (Elf32_External_Rela
));
5047 bfd_elf32_swap_reloca_out (output_bfd
,
5049 outrel
.r_offset
+= 4;
5051 = ELF32_R_INFO (indx
, R_PPC_DTPREL32
);
5054 else if (tls_ty
== (TLS_TLS
| TLS_DTPREL
))
5055 outrel
.r_info
= ELF32_R_INFO (indx
, R_PPC_DTPREL32
);
5056 else if (tls_ty
== (TLS_TLS
| TLS_TPREL
))
5057 outrel
.r_info
= ELF32_R_INFO (indx
, R_PPC_TPREL32
);
5059 outrel
.r_info
= ELF32_R_INFO (indx
, R_PPC_RELATIVE
);
5061 outrel
.r_info
= ELF32_R_INFO (indx
, R_PPC_GLOB_DAT
);
5064 outrel
.r_addend
+= relocation
;
5065 if (tls_ty
& (TLS_GD
| TLS_DTPREL
| TLS_TPREL
))
5066 outrel
.r_addend
-= htab
->tls_sec
->vma
;
5068 loc
= htab
->relgot
->contents
;
5069 loc
+= (htab
->relgot
->reloc_count
++
5070 * sizeof (Elf32_External_Rela
));
5071 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
5074 /* Init the .got section contents if we're not
5075 emitting a reloc. */
5078 bfd_vma value
= relocation
;
5080 if (tls_ty
== (TLS_TLS
| TLS_LD
))
5082 else if (tls_ty
!= 0)
5084 value
-= htab
->tls_sec
->vma
+ DTP_OFFSET
;
5085 if (tls_ty
== (TLS_TLS
| TLS_TPREL
))
5086 value
+= DTP_OFFSET
- TP_OFFSET
;
5088 if (tls_ty
== (TLS_TLS
| TLS_GD
))
5090 bfd_put_32 (output_bfd
, value
,
5091 htab
->got
->contents
+ off
+ 4);
5095 bfd_put_32 (output_bfd
, value
,
5096 htab
->got
->contents
+ off
);
5100 if (tls_ty
& (TLS_LD
| TLS_GD
))
5109 if (off
>= (bfd_vma
) -2)
5112 if ((tls_type
& TLS_TLS
) != 0)
5114 if (tls_type
!= (TLS_TLS
| TLS_LD
))
5116 if ((tls_mask
& TLS_LD
) != 0
5118 || !(h
->elf_link_hash_flags
5119 & ELF_LINK_HASH_DEF_DYNAMIC
)))
5121 if (tls_type
!= (TLS_TLS
| TLS_GD
))
5123 if ((tls_mask
& TLS_GD
) != 0)
5125 if (tls_type
!= (TLS_TLS
| TLS_DTPREL
))
5127 if ((tls_mask
& TLS_DTPREL
) != 0)
5134 relocation
= htab
->got
->output_offset
+ off
- 4;
5136 /* Addends on got relocations don't make much sense.
5137 x+off@got is actually x@got+off, and since the got is
5138 generated by a hash table traversal, the value in the
5139 got at entry m+n bears little relation to the entry m. */
5141 (*_bfd_error_handler
)
5142 (_("%s(%s+0x%lx): non-zero addend on %s reloc against `%s'"),
5143 bfd_archive_filename (input_bfd
),
5144 bfd_get_section_name (input_bfd
, input_section
),
5145 (long) rel
->r_offset
,
5151 /* Relocations that need no special processing. */
5152 case R_PPC_LOCAL24PC
:
5153 /* It makes no sense to point a local relocation
5154 at a symbol not in this object. */
5155 if (unresolved_reloc
)
5157 if (! (*info
->callbacks
->undefined_symbol
) (info
,
5158 h
->root
.root
.string
,
5168 case R_PPC_DTPREL16
:
5169 case R_PPC_DTPREL16_LO
:
5170 case R_PPC_DTPREL16_HI
:
5171 case R_PPC_DTPREL16_HA
:
5172 addend
-= htab
->tls_sec
->vma
+ DTP_OFFSET
;
5175 /* Relocations that may need to be propagated if this is a shared
5178 case R_PPC_TPREL16_LO
:
5179 case R_PPC_TPREL16_HI
:
5180 case R_PPC_TPREL16_HA
:
5181 addend
-= htab
->tls_sec
->vma
+ TP_OFFSET
;
5182 /* The TPREL16 relocs shouldn't really be used in shared
5183 libs as they will result in DT_TEXTREL being set, but
5184 support them anyway. */
5188 addend
-= htab
->tls_sec
->vma
+ TP_OFFSET
;
5191 case R_PPC_DTPREL32
:
5192 addend
-= htab
->tls_sec
->vma
+ DTP_OFFSET
;
5195 case R_PPC_DTPMOD32
:
5203 case R_PPC_REL14_BRTAKEN
:
5204 case R_PPC_REL14_BRNTAKEN
:
5205 /* If these relocations are not to a named symbol, they can be
5206 handled right here, no need to bother the dynamic linker. */
5208 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0
5209 || SYMBOL_REFERENCES_LOCAL (info
, h
))
5213 /* Relocations that always need to be propagated if this is a shared
5218 case R_PPC_ADDR16_LO
:
5219 case R_PPC_ADDR16_HI
:
5220 case R_PPC_ADDR16_HA
:
5222 case R_PPC_ADDR14_BRTAKEN
:
5223 case R_PPC_ADDR14_BRNTAKEN
:
5226 /* r_symndx will be zero only for relocs against symbols
5227 from removed linkonce sections, or sections discarded by
5236 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
5237 || h
->root
.type
!= bfd_link_hash_undefweak
)
5238 && (MUST_BE_DYN_RELOC (r_type
)
5240 && !SYMBOL_CALLS_LOCAL (info
, h
))))
5241 || (ELIMINATE_COPY_RELOCS
5243 && (input_section
->flags
& SEC_ALLOC
) != 0
5246 && (h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0
5247 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
5248 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0))
5253 fprintf (stderr
, "ppc_elf_relocate_section needs to "
5254 "create relocation for %s\n",
5255 (h
&& h
->root
.root
.string
5256 ? h
->root
.root
.string
: "<unknown>"));
5259 /* When generating a shared object, these relocations
5260 are copied into the output file to be resolved at run
5266 name
= (bfd_elf_string_from_elf_section
5268 elf_elfheader (input_bfd
)->e_shstrndx
,
5269 elf_section_data (input_section
)->rel_hdr
.sh_name
));
5273 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
5274 && strcmp (bfd_get_section_name (input_bfd
,
5278 sreloc
= bfd_get_section_by_name (htab
->elf
.dynobj
, name
);
5279 BFD_ASSERT (sreloc
!= NULL
);
5285 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
5287 if (outrel
.r_offset
== (bfd_vma
) -1
5288 || outrel
.r_offset
== (bfd_vma
) -2)
5289 skip
= (int) outrel
.r_offset
;
5290 outrel
.r_offset
+= (input_section
->output_section
->vma
5291 + input_section
->output_offset
);
5294 memset (&outrel
, 0, sizeof outrel
);
5296 && !SYMBOL_REFERENCES_LOCAL (info
, h
))
5298 unresolved_reloc
= FALSE
;
5299 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
5300 outrel
.r_addend
= rel
->r_addend
;
5304 outrel
.r_addend
= relocation
+ rel
->r_addend
;
5306 if (r_type
== R_PPC_ADDR32
)
5307 outrel
.r_info
= ELF32_R_INFO (0, R_PPC_RELATIVE
);
5312 if (bfd_is_abs_section (sec
))
5314 else if (sec
== NULL
|| sec
->owner
== NULL
)
5316 bfd_set_error (bfd_error_bad_value
);
5323 /* We are turning this relocation into one
5324 against a section symbol. It would be
5325 proper to subtract the symbol's value,
5326 osec->vma, from the emitted reloc addend,
5327 but ld.so expects buggy relocs. */
5328 osec
= sec
->output_section
;
5329 indx
= elf_section_data (osec
)->dynindx
;
5330 BFD_ASSERT (indx
> 0);
5333 printf ("indx=%d section=%s flags=%08x name=%s\n",
5334 indx
, osec
->name
, osec
->flags
,
5335 h
->root
.root
.string
);
5339 outrel
.r_info
= ELF32_R_INFO (indx
, r_type
);
5343 loc
= sreloc
->contents
;
5344 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rela
);
5345 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
5350 /* This reloc will be computed at runtime. We clear the memory
5351 so that it contains predictable value. */
5353 && ((input_section
->flags
& SEC_ALLOC
) != 0
5354 || ELF32_R_TYPE (outrel
.r_info
) != R_PPC_RELATIVE
))
5356 relocation
= howto
->pc_relative
? outrel
.r_offset
: 0;
5363 /* Indirect .sdata relocation. */
5364 case R_PPC_EMB_SDAI16
:
5365 BFD_ASSERT (htab
->sdata
!= NULL
);
5367 = elf_finish_pointer_linker_section (output_bfd
, input_bfd
, info
,
5368 htab
->sdata
, h
, relocation
,
5369 rel
, R_PPC_RELATIVE
);
5372 /* Indirect .sdata2 relocation. */
5373 case R_PPC_EMB_SDA2I16
:
5374 BFD_ASSERT (htab
->sdata2
!= NULL
);
5376 = elf_finish_pointer_linker_section (output_bfd
, input_bfd
, info
,
5377 htab
->sdata2
, h
, relocation
,
5378 rel
, R_PPC_RELATIVE
);
5381 /* Handle the TOC16 reloc. We want to use the offset within the .got
5382 section, not the actual VMA. This is appropriate when generating
5383 an embedded ELF object, for which the .got section acts like the
5384 AIX .toc section. */
5385 case R_PPC_TOC16
: /* phony GOT16 relocations */
5386 BFD_ASSERT (sec
!= NULL
);
5387 BFD_ASSERT (bfd_is_und_section (sec
)
5388 || strcmp (bfd_get_section_name (abfd
, sec
), ".got") == 0
5389 || strcmp (bfd_get_section_name (abfd
, sec
), ".cgot") == 0)
5391 addend
-= sec
->output_section
->vma
+ sec
->output_offset
+ 0x8000;
5394 case R_PPC_PLTREL24
:
5395 /* Relocation is to the entry for this symbol in the
5396 procedure linkage table. */
5397 BFD_ASSERT (h
!= NULL
);
5399 if (h
->plt
.offset
== (bfd_vma
) -1
5400 || htab
->plt
== NULL
)
5402 /* We didn't make a PLT entry for this symbol. This
5403 happens when statically linking PIC code, or when
5404 using -Bsymbolic. */
5408 unresolved_reloc
= FALSE
;
5409 relocation
= (htab
->plt
->output_section
->vma
5410 + htab
->plt
->output_offset
5414 /* Relocate against _SDA_BASE_. */
5415 case R_PPC_SDAREL16
:
5418 const struct elf_link_hash_entry
*sh
;
5420 BFD_ASSERT (sec
!= NULL
);
5421 name
= bfd_get_section_name (abfd
, sec
->output_section
);
5422 if (! ((strncmp (name
, ".sdata", 6) == 0
5423 && (name
[6] == 0 || name
[6] == '.'))
5424 || (strncmp (name
, ".sbss", 5) == 0
5425 && (name
[5] == 0 || name
[5] == '.'))))
5427 (*_bfd_error_handler
)
5428 (_("%s: the target (%s) of a %s relocation is "
5429 "in the wrong output section (%s)"),
5430 bfd_archive_filename (input_bfd
),
5435 sh
= htab
->sdata
->sym_hash
;
5436 addend
-= (sh
->root
.u
.def
.value
5437 + sh
->root
.u
.def
.section
->output_section
->vma
5438 + sh
->root
.u
.def
.section
->output_offset
);
5442 /* Relocate against _SDA2_BASE_. */
5443 case R_PPC_EMB_SDA2REL
:
5446 const struct elf_link_hash_entry
*sh
;
5448 BFD_ASSERT (sec
!= NULL
);
5449 name
= bfd_get_section_name (abfd
, sec
->output_section
);
5450 if (! (strncmp (name
, ".sdata2", 7) == 0
5451 || strncmp (name
, ".sbss2", 6) == 0))
5453 (*_bfd_error_handler
)
5454 (_("%s: the target (%s) of a %s relocation is "
5455 "in the wrong output section (%s)"),
5456 bfd_archive_filename (input_bfd
),
5461 bfd_set_error (bfd_error_bad_value
);
5465 sh
= htab
->sdata2
->sym_hash
;
5466 addend
-= (sh
->root
.u
.def
.value
5467 + sh
->root
.u
.def
.section
->output_section
->vma
5468 + sh
->root
.u
.def
.section
->output_offset
);
5472 /* Relocate against either _SDA_BASE_, _SDA2_BASE_, or 0. */
5473 case R_PPC_EMB_SDA21
:
5474 case R_PPC_EMB_RELSDA
:
5477 const struct elf_link_hash_entry
*sh
;
5480 BFD_ASSERT (sec
!= NULL
);
5481 name
= bfd_get_section_name (abfd
, sec
->output_section
);
5482 if (((strncmp (name
, ".sdata", 6) == 0
5483 && (name
[6] == 0 || name
[6] == '.'))
5484 || (strncmp (name
, ".sbss", 5) == 0
5485 && (name
[5] == 0 || name
[5] == '.'))))
5488 sh
= htab
->sdata
->sym_hash
;
5489 addend
-= (sh
->root
.u
.def
.value
5490 + sh
->root
.u
.def
.section
->output_section
->vma
5491 + sh
->root
.u
.def
.section
->output_offset
);
5494 else if (strncmp (name
, ".sdata2", 7) == 0
5495 || strncmp (name
, ".sbss2", 6) == 0)
5498 sh
= htab
->sdata2
->sym_hash
;
5499 addend
-= (sh
->root
.u
.def
.value
5500 + sh
->root
.u
.def
.section
->output_section
->vma
5501 + sh
->root
.u
.def
.section
->output_offset
);
5504 else if (strcmp (name
, ".PPC.EMB.sdata0") == 0
5505 || strcmp (name
, ".PPC.EMB.sbss0") == 0)
5512 (*_bfd_error_handler
)
5513 (_("%s: the target (%s) of a %s relocation is "
5514 "in the wrong output section (%s)"),
5515 bfd_archive_filename (input_bfd
),
5520 bfd_set_error (bfd_error_bad_value
);
5525 if (r_type
== R_PPC_EMB_SDA21
)
5526 { /* fill in register field */
5527 insn
= bfd_get_32 (output_bfd
, contents
+ rel
->r_offset
);
5528 insn
= (insn
& ~RA_REGISTER_MASK
) | (reg
<< RA_REGISTER_SHIFT
);
5529 bfd_put_32 (output_bfd
, insn
, contents
+ rel
->r_offset
);
5534 /* Relocate against the beginning of the section. */
5536 case R_PPC_SECTOFF_LO
:
5537 case R_PPC_SECTOFF_HI
:
5538 case R_PPC_SECTOFF_HA
:
5539 BFD_ASSERT (sec
!= NULL
);
5540 addend
-= sec
->output_section
->vma
;
5543 /* Negative relocations. */
5544 case R_PPC_EMB_NADDR32
:
5545 case R_PPC_EMB_NADDR16
:
5546 case R_PPC_EMB_NADDR16_LO
:
5547 case R_PPC_EMB_NADDR16_HI
:
5548 case R_PPC_EMB_NADDR16_HA
:
5549 addend
-= 2 * relocation
;
5553 case R_PPC_GLOB_DAT
:
5554 case R_PPC_JMP_SLOT
:
5555 case R_PPC_RELATIVE
:
5557 case R_PPC_PLTREL32
:
5558 case R_PPC_PLT16_LO
:
5559 case R_PPC_PLT16_HI
:
5560 case R_PPC_PLT16_HA
:
5562 case R_PPC_EMB_RELSEC16
:
5563 case R_PPC_EMB_RELST_LO
:
5564 case R_PPC_EMB_RELST_HI
:
5565 case R_PPC_EMB_RELST_HA
:
5566 case R_PPC_EMB_BIT_FLD
:
5567 (*_bfd_error_handler
)
5568 (_("%s: relocation %s is not yet supported for symbol %s."),
5569 bfd_archive_filename (input_bfd
),
5573 bfd_set_error (bfd_error_invalid_operation
);
5578 /* Do any further special processing. */
5584 case R_PPC_ADDR16_HA
:
5585 case R_PPC_GOT16_HA
:
5586 case R_PPC_PLT16_HA
:
5587 case R_PPC_SECTOFF_HA
:
5588 case R_PPC_TPREL16_HA
:
5589 case R_PPC_DTPREL16_HA
:
5590 case R_PPC_GOT_TLSGD16_HA
:
5591 case R_PPC_GOT_TLSLD16_HA
:
5592 case R_PPC_GOT_TPREL16_HA
:
5593 case R_PPC_GOT_DTPREL16_HA
:
5594 case R_PPC_EMB_NADDR16_HA
:
5595 case R_PPC_EMB_RELST_HA
:
5596 /* It's just possible that this symbol is a weak symbol
5597 that's not actually defined anywhere. In that case,
5598 'sec' would be NULL, and we should leave the symbol
5599 alone (it will be set to zero elsewhere in the link). */
5601 /* Add 0x10000 if sign bit in 0:15 is set.
5602 Bits 0:15 are not used. */
5608 fprintf (stderr
, "\ttype = %s (%d), name = %s, symbol index = %ld, "
5609 "offset = %ld, addend = %ld\n",
5614 (long) rel
->r_offset
,
5618 if (unresolved_reloc
5619 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
5620 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0))
5622 (*_bfd_error_handler
)
5623 (_("%s(%s+0x%lx): unresolvable %s relocation against symbol `%s'"),
5624 bfd_archive_filename (input_bfd
),
5625 bfd_get_section_name (input_bfd
, input_section
),
5626 (long) rel
->r_offset
,
5632 r
= _bfd_final_link_relocate (howto
,
5640 if (r
!= bfd_reloc_ok
)
5642 if (sym_name
== NULL
)
5643 sym_name
= "(null)";
5644 if (r
== bfd_reloc_overflow
)
5649 && h
->root
.type
== bfd_link_hash_undefweak
5650 && howto
->pc_relative
)
5652 /* Assume this is a call protected by other code that
5653 detect the symbol is undefined. If this is the case,
5654 we can safely ignore the overflow. If not, the
5655 program is hosed anyway, and a little warning isn't
5661 if (! (*info
->callbacks
->reloc_overflow
) (info
,
5672 (*_bfd_error_handler
)
5673 (_("%s(%s+0x%lx): %s reloc against `%s': error %d"),
5674 bfd_archive_filename (input_bfd
),
5675 bfd_get_section_name (input_bfd
, input_section
),
5676 (long) rel
->r_offset
, howto
->name
, sym_name
, (int) r
);
5683 fprintf (stderr
, "\n");
5689 static enum elf_reloc_type_class
5690 ppc_elf_reloc_type_class (const Elf_Internal_Rela
*rela
)
5692 switch (ELF32_R_TYPE (rela
->r_info
))
5694 case R_PPC_RELATIVE
:
5695 return reloc_class_relative
;
5698 case R_PPC_JMP_SLOT
:
5699 return reloc_class_plt
;
5701 return reloc_class_copy
;
5703 return reloc_class_normal
;
5707 /* Support for core dump NOTE sections. */
5710 ppc_elf_grok_prstatus (bfd
*abfd
, Elf_Internal_Note
*note
)
5713 unsigned int raw_size
;
5715 switch (note
->descsz
)
5720 case 268: /* Linux/PPC. */
5722 elf_tdata (abfd
)->core_signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
5725 elf_tdata (abfd
)->core_pid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
5734 /* Make a ".reg/999" section. */
5735 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
5736 raw_size
, note
->descpos
+ offset
);
5740 ppc_elf_grok_psinfo (bfd
*abfd
, Elf_Internal_Note
*note
)
5742 switch (note
->descsz
)
5747 case 128: /* Linux/PPC elf_prpsinfo. */
5748 elf_tdata (abfd
)->core_program
5749 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 32, 16);
5750 elf_tdata (abfd
)->core_command
5751 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 48, 80);
5754 /* Note that for some reason, a spurious space is tacked
5755 onto the end of the args in some (at least one anyway)
5756 implementations, so strip it off if it exists. */
5759 char *command
= elf_tdata (abfd
)->core_command
;
5760 int n
= strlen (command
);
5762 if (0 < n
&& command
[n
- 1] == ' ')
5763 command
[n
- 1] = '\0';
5769 /* Very simple linked list structure for recording apuinfo values. */
5770 typedef struct apuinfo_list
5772 struct apuinfo_list
*next
;
5773 unsigned long value
;
5777 static apuinfo_list
*head
;
5781 apuinfo_list_init (void)
5787 apuinfo_list_add (unsigned long value
)
5789 apuinfo_list
*entry
= head
;
5791 while (entry
!= NULL
)
5793 if (entry
->value
== value
)
5795 entry
= entry
->next
;
5798 entry
= bfd_malloc (sizeof (* entry
));
5802 entry
->value
= value
;
5808 apuinfo_list_length (void)
5810 apuinfo_list
*entry
;
5811 unsigned long count
;
5813 for (entry
= head
, count
= 0;
5815 entry
= entry
->next
)
5821 static inline unsigned long
5822 apuinfo_list_element (unsigned long number
)
5824 apuinfo_list
* entry
;
5828 entry
= entry
->next
)
5831 return entry
? entry
->value
: 0;
5835 apuinfo_list_finish (void)
5837 apuinfo_list
*entry
;
5839 for (entry
= head
; entry
;)
5841 apuinfo_list
*next
= entry
->next
;
5849 #define APUINFO_SECTION_NAME ".PPC.EMB.apuinfo"
5850 #define APUINFO_LABEL "APUinfo"
5852 /* Scan the input BFDs and create a linked list of
5853 the APUinfo values that will need to be emitted. */
5856 ppc_elf_begin_write_processing (bfd
*abfd
, struct bfd_link_info
*link_info
)
5861 unsigned num_input_sections
;
5862 bfd_size_type output_section_size
;
5864 unsigned num_entries
;
5865 unsigned long offset
;
5866 unsigned long length
;
5867 const char *error_message
= NULL
;
5869 if (link_info
== NULL
)
5872 /* Scan the input bfds, looking for apuinfo sections. */
5873 num_input_sections
= 0;
5874 output_section_size
= 0;
5876 for (ibfd
= link_info
->input_bfds
; ibfd
; ibfd
= ibfd
->link_next
)
5878 asec
= bfd_get_section_by_name (ibfd
, APUINFO_SECTION_NAME
);
5881 ++ num_input_sections
;
5882 output_section_size
+= asec
->_raw_size
;
5886 /* We need at least one input sections
5887 in order to make merging worthwhile. */
5888 if (num_input_sections
< 1)
5891 /* Just make sure that the output section exists as well. */
5892 asec
= bfd_get_section_by_name (abfd
, APUINFO_SECTION_NAME
);
5896 /* Allocate a buffer for the contents of the input sections. */
5897 buffer
= bfd_malloc (output_section_size
);
5902 apuinfo_list_init ();
5904 /* Read in the input sections contents. */
5905 for (ibfd
= link_info
->input_bfds
; ibfd
; ibfd
= ibfd
->link_next
)
5907 unsigned long datum
;
5910 asec
= bfd_get_section_by_name (ibfd
, APUINFO_SECTION_NAME
);
5914 length
= asec
->_raw_size
;
5917 error_message
= _("corrupt or empty %s section in %s");
5921 if (bfd_seek (ibfd
, asec
->filepos
, SEEK_SET
) != 0
5922 || (bfd_bread (buffer
+ offset
, length
, ibfd
) != length
))
5924 error_message
= _("unable to read in %s section from %s");
5928 /* Process the contents of the section. */
5929 ptr
= buffer
+ offset
;
5930 error_message
= _("corrupt %s section in %s");
5932 /* Verify the contents of the header. Note - we have to
5933 extract the values this way in order to allow for a
5934 host whose endian-ness is different from the target. */
5935 datum
= bfd_get_32 (ibfd
, ptr
);
5936 if (datum
!= sizeof APUINFO_LABEL
)
5939 datum
= bfd_get_32 (ibfd
, ptr
+ 8);
5943 if (strcmp (ptr
+ 12, APUINFO_LABEL
) != 0)
5946 /* Get the number of bytes used for apuinfo entries. */
5947 datum
= bfd_get_32 (ibfd
, ptr
+ 4);
5948 if (datum
+ 20 != length
)
5951 /* Make sure that we do not run off the end of the section. */
5952 if (offset
+ length
> output_section_size
)
5955 /* Scan the apuinfo section, building a list of apuinfo numbers. */
5956 for (i
= 0; i
< datum
; i
+= 4)
5957 apuinfo_list_add (bfd_get_32 (ibfd
, ptr
+ 20 + i
));
5959 /* Update the offset. */
5963 error_message
= NULL
;
5965 /* Compute the size of the output section. */
5966 num_entries
= apuinfo_list_length ();
5967 output_section_size
= 20 + num_entries
* 4;
5969 asec
= bfd_get_section_by_name (abfd
, APUINFO_SECTION_NAME
);
5971 if (! bfd_set_section_size (abfd
, asec
, output_section_size
))
5973 error_message
= _("warning: unable to set size of %s section in %s");
5979 (*_bfd_error_handler
) (error_message
, APUINFO_SECTION_NAME
,
5980 bfd_archive_filename (ibfd
));
5984 /* Prevent the output section from accumulating the input sections'
5985 contents. We have already stored this in our linked list structure. */
5988 ppc_elf_write_section (bfd
*abfd ATTRIBUTE_UNUSED
,
5990 bfd_byte
*contents ATTRIBUTE_UNUSED
)
5992 return (apuinfo_list_length ()
5993 && strcmp (asec
->name
, APUINFO_SECTION_NAME
) == 0);
5997 /* Finally we can generate the output section. */
6000 ppc_elf_final_write_processing (bfd
*abfd
, bfd_boolean linker ATTRIBUTE_UNUSED
)
6005 unsigned num_entries
;
6006 bfd_size_type length
;
6008 asec
= bfd_get_section_by_name (abfd
, APUINFO_SECTION_NAME
);
6012 if (apuinfo_list_length () == 0)
6015 length
= asec
->_raw_size
;
6019 buffer
= bfd_malloc (length
);
6022 (*_bfd_error_handler
)
6023 (_("failed to allocate space for new APUinfo section."));
6027 /* Create the apuinfo header. */
6028 num_entries
= apuinfo_list_length ();
6029 bfd_put_32 (abfd
, sizeof APUINFO_LABEL
, buffer
);
6030 bfd_put_32 (abfd
, num_entries
* 4, buffer
+ 4);
6031 bfd_put_32 (abfd
, 0x2, buffer
+ 8);
6032 strcpy (buffer
+ 12, APUINFO_LABEL
);
6035 for (i
= 0; i
< num_entries
; i
++)
6037 bfd_put_32 (abfd
, apuinfo_list_element (i
), buffer
+ length
);
6041 if (length
!= asec
->_raw_size
)
6042 (*_bfd_error_handler
) (_("failed to compute new APUinfo section."));
6044 if (! bfd_set_section_contents (abfd
, asec
, buffer
, (file_ptr
) 0, length
))
6045 (*_bfd_error_handler
) (_("failed to install new APUinfo section."));
6049 apuinfo_list_finish ();
6052 #define TARGET_LITTLE_SYM bfd_elf32_powerpcle_vec
6053 #define TARGET_LITTLE_NAME "elf32-powerpcle"
6054 #define TARGET_BIG_SYM bfd_elf32_powerpc_vec
6055 #define TARGET_BIG_NAME "elf32-powerpc"
6056 #define ELF_ARCH bfd_arch_powerpc
6057 #define ELF_MACHINE_CODE EM_PPC
6058 #define ELF_MAXPAGESIZE 0x10000
6059 #define elf_info_to_howto ppc_elf_info_to_howto
6061 #ifdef EM_CYGNUS_POWERPC
6062 #define ELF_MACHINE_ALT1 EM_CYGNUS_POWERPC
6066 #define ELF_MACHINE_ALT2 EM_PPC_OLD
6069 #define elf_backend_plt_not_loaded 1
6070 #define elf_backend_got_symbol_offset 4
6071 #define elf_backend_can_gc_sections 1
6072 #define elf_backend_can_refcount 1
6073 #define elf_backend_got_header_size 12
6074 #define elf_backend_plt_header_size PLT_INITIAL_ENTRY_SIZE
6075 #define elf_backend_rela_normal 1
6077 #define bfd_elf32_bfd_merge_private_bfd_data ppc_elf_merge_private_bfd_data
6078 #define bfd_elf32_bfd_relax_section ppc_elf_relax_section
6079 #define bfd_elf32_bfd_reloc_type_lookup ppc_elf_reloc_type_lookup
6080 #define bfd_elf32_bfd_set_private_flags ppc_elf_set_private_flags
6081 #define bfd_elf32_bfd_link_hash_table_create ppc_elf_link_hash_table_create
6083 #define elf_backend_object_p ppc_elf_object_p
6084 #define elf_backend_gc_mark_hook ppc_elf_gc_mark_hook
6085 #define elf_backend_gc_sweep_hook ppc_elf_gc_sweep_hook
6086 #define elf_backend_section_from_shdr ppc_elf_section_from_shdr
6087 #define elf_backend_relocate_section ppc_elf_relocate_section
6088 #define elf_backend_create_dynamic_sections ppc_elf_create_dynamic_sections
6089 #define elf_backend_check_relocs ppc_elf_check_relocs
6090 #define elf_backend_copy_indirect_symbol ppc_elf_copy_indirect_symbol
6091 #define elf_backend_adjust_dynamic_symbol ppc_elf_adjust_dynamic_symbol
6092 #define elf_backend_add_symbol_hook ppc_elf_add_symbol_hook
6093 #define elf_backend_size_dynamic_sections ppc_elf_size_dynamic_sections
6094 #define elf_backend_finish_dynamic_symbol ppc_elf_finish_dynamic_symbol
6095 #define elf_backend_finish_dynamic_sections ppc_elf_finish_dynamic_sections
6096 #define elf_backend_fake_sections ppc_elf_fake_sections
6097 #define elf_backend_additional_program_headers ppc_elf_additional_program_headers
6098 #define elf_backend_modify_segment_map ppc_elf_modify_segment_map
6099 #define elf_backend_grok_prstatus ppc_elf_grok_prstatus
6100 #define elf_backend_grok_psinfo ppc_elf_grok_psinfo
6101 #define elf_backend_reloc_type_class ppc_elf_reloc_type_class
6102 #define elf_backend_begin_write_processing ppc_elf_begin_write_processing
6103 #define elf_backend_final_write_processing ppc_elf_final_write_processing
6104 #define elf_backend_write_section ppc_elf_write_section
6106 #include "elf32-target.h"