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 struct bfd_hash_entry
*ppc_elf_link_hash_newfunc
39 PARAMS ((struct bfd_hash_entry
*entry
, struct bfd_hash_table
*table
,
41 static struct bfd_link_hash_table
*ppc_elf_link_hash_table_create
43 static void ppc_elf_copy_indirect_symbol
44 PARAMS ((struct elf_backend_data
*bed
, struct elf_link_hash_entry
*dir
,
45 struct elf_link_hash_entry
*ind
));
46 static reloc_howto_type
*ppc_elf_reloc_type_lookup
47 PARAMS ((bfd
*abfd
, bfd_reloc_code_real_type code
));
48 static void ppc_elf_info_to_howto
49 PARAMS ((bfd
*abfd
, arelent
*cache_ptr
, Elf_Internal_Rela
*dst
));
50 static void ppc_elf_howto_init
52 static int ppc_elf_sort_rela
53 PARAMS ((const PTR
, const PTR
));
54 static bfd_boolean ppc_elf_relax_section
55 PARAMS ((bfd
*, asection
*, struct bfd_link_info
*, bfd_boolean
*));
56 static bfd_reloc_status_type ppc_elf_addr16_ha_reloc
57 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
58 static bfd_reloc_status_type ppc_elf_unhandled_reloc
59 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
60 static bfd_boolean ppc_elf_object_p
62 static bfd_boolean ppc_elf_set_private_flags
63 PARAMS ((bfd
*, flagword
));
64 static bfd_boolean ppc_elf_merge_private_bfd_data
65 PARAMS ((bfd
*, bfd
*));
66 static int ppc_elf_additional_program_headers
68 static bfd_boolean ppc_elf_modify_segment_map
70 static bfd_boolean ppc_elf_create_got
71 PARAMS ((bfd
*, struct bfd_link_info
*));
72 static bfd_boolean ppc_elf_create_dynamic_sections
73 PARAMS ((bfd
*, struct bfd_link_info
*));
74 static bfd_boolean ppc_elf_section_from_shdr
75 PARAMS ((bfd
*, Elf_Internal_Shdr
*, const char *));
76 static bfd_boolean ppc_elf_fake_sections
77 PARAMS ((bfd
*, Elf_Internal_Shdr
*, asection
*));
78 static elf_linker_section_t
*ppc_elf_create_linker_section
79 PARAMS ((bfd
*abfd
, struct bfd_link_info
*info
,
80 enum elf_linker_section_enum
));
81 static bfd_boolean update_local_sym_info
82 PARAMS ((bfd
*, Elf_Internal_Shdr
*, unsigned long, int));
83 static void bad_shared_reloc
84 PARAMS ((bfd
*, enum elf_ppc_reloc_type
));
85 static bfd_boolean ppc_elf_check_relocs
86 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
87 const Elf_Internal_Rela
*));
88 static asection
*ppc_elf_gc_mark_hook
89 PARAMS ((asection
*sec
, struct bfd_link_info
*info
, Elf_Internal_Rela
*rel
,
90 struct elf_link_hash_entry
*h
, Elf_Internal_Sym
*sym
));
91 static bfd_boolean ppc_elf_gc_sweep_hook
92 PARAMS ((bfd
*abfd
, struct bfd_link_info
*info
, asection
*sec
,
93 const Elf_Internal_Rela
*relocs
));
94 static bfd_boolean ppc_elf_adjust_dynamic_symbol
95 PARAMS ((struct bfd_link_info
*, struct elf_link_hash_entry
*));
96 static bfd_boolean allocate_dynrelocs
97 PARAMS ((struct elf_link_hash_entry
*, PTR
));
98 static bfd_boolean readonly_dynrelocs
99 PARAMS ((struct elf_link_hash_entry
*, PTR
));
100 static bfd_boolean ppc_elf_size_dynamic_sections
101 PARAMS ((bfd
*, struct bfd_link_info
*));
102 static bfd_boolean ppc_elf_relocate_section
103 PARAMS ((bfd
*, struct bfd_link_info
*info
, bfd
*, asection
*, bfd_byte
*,
104 Elf_Internal_Rela
*relocs
, Elf_Internal_Sym
*local_syms
,
106 static bfd_boolean ppc_elf_add_symbol_hook
107 PARAMS ((bfd
*, struct bfd_link_info
*, const Elf_Internal_Sym
*,
108 const char **, flagword
*, asection
**, bfd_vma
*));
109 static bfd_boolean ppc_elf_finish_dynamic_symbol
110 PARAMS ((bfd
*, struct bfd_link_info
*, struct elf_link_hash_entry
*,
111 Elf_Internal_Sym
*));
112 static bfd_boolean ppc_elf_finish_dynamic_sections
113 PARAMS ((bfd
*, struct bfd_link_info
*));
114 static enum elf_reloc_type_class ppc_elf_reloc_type_class
115 PARAMS ((const Elf_Internal_Rela
*));
116 static bfd_boolean ppc_elf_grok_prstatus
117 PARAMS ((bfd
*abfd
, Elf_Internal_Note
*note
));
118 static bfd_boolean ppc_elf_grok_psinfo
119 PARAMS ((bfd
*abfd
, Elf_Internal_Note
*note
));
121 /* Branch prediction bit for branch taken relocs. */
122 #define BRANCH_PREDICT_BIT 0x200000
123 /* Mask to set RA in memory instructions. */
124 #define RA_REGISTER_MASK 0x001f0000
125 /* Value to shift register by to insert RA. */
126 #define RA_REGISTER_SHIFT 16
128 /* The name of the dynamic interpreter. This is put in the .interp
130 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
132 /* The size in bytes of an entry in the procedure linkage table. */
133 #define PLT_ENTRY_SIZE 12
134 /* The initial size of the plt reserved for the dynamic linker. */
135 #define PLT_INITIAL_ENTRY_SIZE 72
136 /* The size of the gap between entries in the PLT. */
137 #define PLT_SLOT_SIZE 8
138 /* The number of single-slot PLT entries (the rest use two slots). */
139 #define PLT_NUM_SINGLE_ENTRIES 8192
141 /* Some nop instructions. */
142 #define NOP 0x60000000
143 #define CROR_151515 0x4def7b82
144 #define CROR_313131 0x4ffffb82
146 /* Offset of tp and dtp pointers from start of TLS block. */
147 #define TP_OFFSET 0x7000
148 #define DTP_OFFSET 0x8000
151 /* The PPC linker needs to keep track of the number of relocs that it
152 decides to copy as dynamic relocs in check_relocs for each symbol.
153 This is so that it can later discard them if they are found to be
154 unnecessary. We store the information in a field extending the
155 regular ELF linker hash table. */
157 struct ppc_elf_dyn_relocs
159 struct ppc_elf_dyn_relocs
*next
;
161 /* The input section of the reloc. */
164 /* Total number of relocs copied for the input section. */
167 /* Number of pc-relative relocs copied for the input section. */
168 bfd_size_type pc_count
;
171 /* PPC ELF linker hash entry. */
173 struct ppc_elf_link_hash_entry
175 struct elf_link_hash_entry elf
;
177 /* Track dynamic relocs copied for this symbol. */
178 struct ppc_elf_dyn_relocs
*dyn_relocs
;
180 /* Contexts in which symbol is used in the GOT (or TOC).
181 TLS_GD .. TLS_TLS bits are or'd into the mask as the
182 corresponding relocs are encountered during check_relocs.
183 tls_optimize clears TLS_GD .. TLS_TPREL when optimizing to
184 indicate the corresponding GOT entry type is not needed. */
185 #define TLS_GD 1 /* GD reloc. */
186 #define TLS_LD 2 /* LD reloc. */
187 #define TLS_TPREL 4 /* TPREL reloc, => IE. */
188 #define TLS_DTPREL 8 /* DTPREL reloc, => LD. */
189 #define TLS_TLS 16 /* Any TLS reloc. */
190 #define TLS_TPRELGD 32 /* TPREL reloc resulting from GD->IE. */
194 #define ppc_elf_hash_entry(ent) ((struct ppc_elf_link_hash_entry *) (ent))
196 /* PPC ELF linker hash table. */
198 struct ppc_elf_link_hash_table
200 struct elf_link_hash_table elf
;
202 /* Short-cuts to get to dynamic linker sections. */
211 elf_linker_section_t
*sdata
;
212 elf_linker_section_t
*sdata2
;
214 /* Short-cut to first output tls section. */
217 /* Shortcut to .__tls_get_addr. */
218 struct elf_link_hash_entry
*tls_get_addr
;
220 /* TLS local dynamic got entry handling. */
222 bfd_signed_vma refcount
;
226 /* Small local sym to section mapping cache. */
227 struct sym_sec_cache sym_sec
;
230 /* Get the PPC ELF linker hash table from a link_info structure. */
232 #define ppc_elf_hash_table(p) \
233 ((struct ppc_elf_link_hash_table *) (p)->hash)
235 /* Create an entry in a PPC ELF linker hash table. */
237 static struct bfd_hash_entry
*
238 ppc_elf_link_hash_newfunc (entry
, table
, string
)
239 struct bfd_hash_entry
*entry
;
240 struct bfd_hash_table
*table
;
243 /* Allocate the structure if it has not already been allocated by a
247 entry
= bfd_hash_allocate (table
,
248 sizeof (struct ppc_elf_link_hash_entry
));
253 /* Call the allocation method of the superclass. */
254 entry
= _bfd_elf_link_hash_newfunc (entry
, table
, string
);
257 ppc_elf_hash_entry (entry
)->dyn_relocs
= NULL
;
258 ppc_elf_hash_entry (entry
)->tls_mask
= 0;
264 /* Create a PPC ELF linker hash table. */
266 static struct bfd_link_hash_table
*
267 ppc_elf_link_hash_table_create (abfd
)
270 struct ppc_elf_link_hash_table
*ret
;
272 ret
= ((struct ppc_elf_link_hash_table
*)
273 bfd_malloc (sizeof (struct ppc_elf_link_hash_table
)));
277 if (! _bfd_elf_link_hash_table_init (&ret
->elf
, abfd
,
278 ppc_elf_link_hash_newfunc
))
295 ret
->tls_get_addr
= NULL
;
296 ret
->tlsld_got
.refcount
= 0;
297 ret
->sym_sec
.abfd
= NULL
;
299 return &ret
->elf
.root
;
302 /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
303 copying dynamic variables from a shared lib into an app's dynbss
304 section, and instead use a dynamic relocation to point into the
306 #define ELIMINATE_COPY_RELOCS 1
308 /* Copy the extra info we tack onto an elf_link_hash_entry. */
311 ppc_elf_copy_indirect_symbol (bed
, dir
, ind
)
312 struct elf_backend_data
*bed
;
313 struct elf_link_hash_entry
*dir
, *ind
;
315 struct ppc_elf_link_hash_entry
*edir
, *eind
;
317 edir
= (struct ppc_elf_link_hash_entry
*) dir
;
318 eind
= (struct ppc_elf_link_hash_entry
*) ind
;
320 if (eind
->dyn_relocs
!= NULL
)
322 if (edir
->dyn_relocs
!= NULL
)
324 struct ppc_elf_dyn_relocs
**pp
;
325 struct ppc_elf_dyn_relocs
*p
;
327 if (ind
->root
.type
== bfd_link_hash_indirect
)
330 /* Add reloc counts against the weak sym to the strong sym
331 list. Merge any entries against the same section. */
332 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
; )
334 struct ppc_elf_dyn_relocs
*q
;
336 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
337 if (q
->sec
== p
->sec
)
339 q
->pc_count
+= p
->pc_count
;
340 q
->count
+= p
->count
;
347 *pp
= edir
->dyn_relocs
;
350 edir
->dyn_relocs
= eind
->dyn_relocs
;
351 eind
->dyn_relocs
= NULL
;
354 edir
->tls_mask
|= eind
->tls_mask
;
356 if (ELIMINATE_COPY_RELOCS
357 && ind
->root
.type
!= bfd_link_hash_indirect
358 && (dir
->elf_link_hash_flags
& ELF_LINK_HASH_DYNAMIC_ADJUSTED
) != 0)
359 /* If called to transfer flags for a weakdef during processing
360 of elf_adjust_dynamic_symbol, don't copy ELF_LINK_NON_GOT_REF.
361 We clear it ourselves for ELIMINATE_COPY_RELOCS. */
362 dir
->elf_link_hash_flags
|=
363 (ind
->elf_link_hash_flags
& (ELF_LINK_HASH_REF_DYNAMIC
364 | ELF_LINK_HASH_REF_REGULAR
365 | ELF_LINK_HASH_REF_REGULAR_NONWEAK
));
367 _bfd_elf_link_hash_copy_indirect (bed
, dir
, ind
);
370 static reloc_howto_type
*ppc_elf_howto_table
[(int) R_PPC_max
];
372 static reloc_howto_type ppc_elf_howto_raw
[] = {
373 /* This reloc does nothing. */
374 HOWTO (R_PPC_NONE
, /* type */
376 2, /* size (0 = byte, 1 = short, 2 = long) */
378 FALSE
, /* pc_relative */
380 complain_overflow_bitfield
, /* complain_on_overflow */
381 bfd_elf_generic_reloc
, /* special_function */
382 "R_PPC_NONE", /* name */
383 FALSE
, /* partial_inplace */
386 FALSE
), /* pcrel_offset */
388 /* A standard 32 bit relocation. */
389 HOWTO (R_PPC_ADDR32
, /* type */
391 2, /* size (0 = byte, 1 = short, 2 = long) */
393 FALSE
, /* pc_relative */
395 complain_overflow_bitfield
, /* complain_on_overflow */
396 bfd_elf_generic_reloc
, /* special_function */
397 "R_PPC_ADDR32", /* name */
398 FALSE
, /* partial_inplace */
400 0xffffffff, /* dst_mask */
401 FALSE
), /* pcrel_offset */
403 /* An absolute 26 bit branch; the lower two bits must be zero.
404 FIXME: we don't check that, we just clear them. */
405 HOWTO (R_PPC_ADDR24
, /* type */
407 2, /* size (0 = byte, 1 = short, 2 = long) */
409 FALSE
, /* pc_relative */
411 complain_overflow_bitfield
, /* complain_on_overflow */
412 bfd_elf_generic_reloc
, /* special_function */
413 "R_PPC_ADDR24", /* name */
414 FALSE
, /* partial_inplace */
416 0x3fffffc, /* dst_mask */
417 FALSE
), /* pcrel_offset */
419 /* A standard 16 bit relocation. */
420 HOWTO (R_PPC_ADDR16
, /* type */
422 1, /* size (0 = byte, 1 = short, 2 = long) */
424 FALSE
, /* pc_relative */
426 complain_overflow_bitfield
, /* complain_on_overflow */
427 bfd_elf_generic_reloc
, /* special_function */
428 "R_PPC_ADDR16", /* name */
429 FALSE
, /* partial_inplace */
431 0xffff, /* dst_mask */
432 FALSE
), /* pcrel_offset */
434 /* A 16 bit relocation without overflow. */
435 HOWTO (R_PPC_ADDR16_LO
, /* type */
437 1, /* size (0 = byte, 1 = short, 2 = long) */
439 FALSE
, /* pc_relative */
441 complain_overflow_dont
,/* complain_on_overflow */
442 bfd_elf_generic_reloc
, /* special_function */
443 "R_PPC_ADDR16_LO", /* name */
444 FALSE
, /* partial_inplace */
446 0xffff, /* dst_mask */
447 FALSE
), /* pcrel_offset */
449 /* The high order 16 bits of an address. */
450 HOWTO (R_PPC_ADDR16_HI
, /* type */
452 1, /* size (0 = byte, 1 = short, 2 = long) */
454 FALSE
, /* pc_relative */
456 complain_overflow_dont
, /* complain_on_overflow */
457 bfd_elf_generic_reloc
, /* special_function */
458 "R_PPC_ADDR16_HI", /* name */
459 FALSE
, /* partial_inplace */
461 0xffff, /* dst_mask */
462 FALSE
), /* pcrel_offset */
464 /* The high order 16 bits of an address, plus 1 if the contents of
465 the low 16 bits, treated as a signed number, is negative. */
466 HOWTO (R_PPC_ADDR16_HA
, /* type */
468 1, /* size (0 = byte, 1 = short, 2 = long) */
470 FALSE
, /* pc_relative */
472 complain_overflow_dont
, /* complain_on_overflow */
473 ppc_elf_addr16_ha_reloc
, /* special_function */
474 "R_PPC_ADDR16_HA", /* name */
475 FALSE
, /* partial_inplace */
477 0xffff, /* dst_mask */
478 FALSE
), /* pcrel_offset */
480 /* An absolute 16 bit branch; the lower two bits must be zero.
481 FIXME: we don't check that, we just clear them. */
482 HOWTO (R_PPC_ADDR14
, /* type */
484 2, /* size (0 = byte, 1 = short, 2 = long) */
486 FALSE
, /* pc_relative */
488 complain_overflow_bitfield
, /* complain_on_overflow */
489 bfd_elf_generic_reloc
, /* special_function */
490 "R_PPC_ADDR14", /* name */
491 FALSE
, /* partial_inplace */
493 0xfffc, /* dst_mask */
494 FALSE
), /* pcrel_offset */
496 /* An absolute 16 bit branch, for which bit 10 should be set to
497 indicate that the branch is expected to be taken. The lower two
498 bits must be zero. */
499 HOWTO (R_PPC_ADDR14_BRTAKEN
, /* type */
501 2, /* size (0 = byte, 1 = short, 2 = long) */
503 FALSE
, /* pc_relative */
505 complain_overflow_bitfield
, /* complain_on_overflow */
506 bfd_elf_generic_reloc
, /* special_function */
507 "R_PPC_ADDR14_BRTAKEN",/* name */
508 FALSE
, /* partial_inplace */
510 0xfffc, /* dst_mask */
511 FALSE
), /* pcrel_offset */
513 /* An absolute 16 bit branch, for which bit 10 should be set to
514 indicate that the branch is not expected to be taken. The lower
515 two bits must be zero. */
516 HOWTO (R_PPC_ADDR14_BRNTAKEN
, /* type */
518 2, /* size (0 = byte, 1 = short, 2 = long) */
520 FALSE
, /* pc_relative */
522 complain_overflow_bitfield
, /* complain_on_overflow */
523 bfd_elf_generic_reloc
, /* special_function */
524 "R_PPC_ADDR14_BRNTAKEN",/* name */
525 FALSE
, /* partial_inplace */
527 0xfffc, /* dst_mask */
528 FALSE
), /* pcrel_offset */
530 /* A relative 26 bit branch; the lower two bits must be zero. */
531 HOWTO (R_PPC_REL24
, /* type */
533 2, /* size (0 = byte, 1 = short, 2 = long) */
535 TRUE
, /* pc_relative */
537 complain_overflow_signed
, /* complain_on_overflow */
538 bfd_elf_generic_reloc
, /* special_function */
539 "R_PPC_REL24", /* name */
540 FALSE
, /* partial_inplace */
542 0x3fffffc, /* dst_mask */
543 TRUE
), /* pcrel_offset */
545 /* A relative 16 bit branch; the lower two bits must be zero. */
546 HOWTO (R_PPC_REL14
, /* type */
548 2, /* size (0 = byte, 1 = short, 2 = long) */
550 TRUE
, /* pc_relative */
552 complain_overflow_signed
, /* complain_on_overflow */
553 bfd_elf_generic_reloc
, /* special_function */
554 "R_PPC_REL14", /* name */
555 FALSE
, /* partial_inplace */
557 0xfffc, /* dst_mask */
558 TRUE
), /* pcrel_offset */
560 /* A relative 16 bit branch. Bit 10 should be set to indicate that
561 the branch is expected to be taken. The lower two bits must be
563 HOWTO (R_PPC_REL14_BRTAKEN
, /* type */
565 2, /* size (0 = byte, 1 = short, 2 = long) */
567 TRUE
, /* pc_relative */
569 complain_overflow_signed
, /* complain_on_overflow */
570 bfd_elf_generic_reloc
, /* special_function */
571 "R_PPC_REL14_BRTAKEN", /* name */
572 FALSE
, /* partial_inplace */
574 0xfffc, /* dst_mask */
575 TRUE
), /* pcrel_offset */
577 /* A relative 16 bit branch. Bit 10 should be set to indicate that
578 the branch is not expected to be taken. The lower two bits must
580 HOWTO (R_PPC_REL14_BRNTAKEN
, /* type */
582 2, /* size (0 = byte, 1 = short, 2 = long) */
584 TRUE
, /* pc_relative */
586 complain_overflow_signed
, /* complain_on_overflow */
587 bfd_elf_generic_reloc
, /* special_function */
588 "R_PPC_REL14_BRNTAKEN",/* name */
589 FALSE
, /* partial_inplace */
591 0xfffc, /* dst_mask */
592 TRUE
), /* pcrel_offset */
594 /* Like R_PPC_ADDR16, but referring to the GOT table entry for the
596 HOWTO (R_PPC_GOT16
, /* type */
598 1, /* size (0 = byte, 1 = short, 2 = long) */
600 FALSE
, /* pc_relative */
602 complain_overflow_signed
, /* complain_on_overflow */
603 bfd_elf_generic_reloc
, /* special_function */
604 "R_PPC_GOT16", /* name */
605 FALSE
, /* partial_inplace */
607 0xffff, /* dst_mask */
608 FALSE
), /* pcrel_offset */
610 /* Like R_PPC_ADDR16_LO, but referring to the GOT table entry for
612 HOWTO (R_PPC_GOT16_LO
, /* type */
614 1, /* size (0 = byte, 1 = short, 2 = long) */
616 FALSE
, /* pc_relative */
618 complain_overflow_dont
, /* complain_on_overflow */
619 bfd_elf_generic_reloc
, /* special_function */
620 "R_PPC_GOT16_LO", /* name */
621 FALSE
, /* partial_inplace */
623 0xffff, /* dst_mask */
624 FALSE
), /* pcrel_offset */
626 /* Like R_PPC_ADDR16_HI, but referring to the GOT table entry for
628 HOWTO (R_PPC_GOT16_HI
, /* type */
630 1, /* size (0 = byte, 1 = short, 2 = long) */
632 FALSE
, /* pc_relative */
634 complain_overflow_bitfield
, /* complain_on_overflow */
635 bfd_elf_generic_reloc
, /* special_function */
636 "R_PPC_GOT16_HI", /* name */
637 FALSE
, /* partial_inplace */
639 0xffff, /* dst_mask */
640 FALSE
), /* pcrel_offset */
642 /* Like R_PPC_ADDR16_HA, but referring to the GOT table entry for
644 HOWTO (R_PPC_GOT16_HA
, /* type */
646 1, /* size (0 = byte, 1 = short, 2 = long) */
648 FALSE
, /* pc_relative */
650 complain_overflow_bitfield
, /* complain_on_overflow */
651 ppc_elf_addr16_ha_reloc
, /* special_function */
652 "R_PPC_GOT16_HA", /* name */
653 FALSE
, /* partial_inplace */
655 0xffff, /* dst_mask */
656 FALSE
), /* pcrel_offset */
658 /* Like R_PPC_REL24, but referring to the procedure linkage table
659 entry for the symbol. */
660 HOWTO (R_PPC_PLTREL24
, /* type */
662 2, /* size (0 = byte, 1 = short, 2 = long) */
664 TRUE
, /* pc_relative */
666 complain_overflow_signed
, /* complain_on_overflow */
667 bfd_elf_generic_reloc
, /* special_function */
668 "R_PPC_PLTREL24", /* name */
669 FALSE
, /* partial_inplace */
671 0x3fffffc, /* dst_mask */
672 TRUE
), /* pcrel_offset */
674 /* This is used only by the dynamic linker. The symbol should exist
675 both in the object being run and in some shared library. The
676 dynamic linker copies the data addressed by the symbol from the
677 shared library into the object, because the object being
678 run has to have the data at some particular address. */
679 HOWTO (R_PPC_COPY
, /* type */
681 2, /* size (0 = byte, 1 = short, 2 = long) */
683 FALSE
, /* pc_relative */
685 complain_overflow_bitfield
, /* complain_on_overflow */
686 bfd_elf_generic_reloc
, /* special_function */
687 "R_PPC_COPY", /* name */
688 FALSE
, /* partial_inplace */
691 FALSE
), /* pcrel_offset */
693 /* Like R_PPC_ADDR32, but used when setting global offset table
695 HOWTO (R_PPC_GLOB_DAT
, /* type */
697 2, /* size (0 = byte, 1 = short, 2 = long) */
699 FALSE
, /* pc_relative */
701 complain_overflow_bitfield
, /* complain_on_overflow */
702 bfd_elf_generic_reloc
, /* special_function */
703 "R_PPC_GLOB_DAT", /* name */
704 FALSE
, /* partial_inplace */
706 0xffffffff, /* dst_mask */
707 FALSE
), /* pcrel_offset */
709 /* Marks a procedure linkage table entry for a symbol. */
710 HOWTO (R_PPC_JMP_SLOT
, /* type */
712 2, /* size (0 = byte, 1 = short, 2 = long) */
714 FALSE
, /* pc_relative */
716 complain_overflow_bitfield
, /* complain_on_overflow */
717 bfd_elf_generic_reloc
, /* special_function */
718 "R_PPC_JMP_SLOT", /* name */
719 FALSE
, /* partial_inplace */
722 FALSE
), /* pcrel_offset */
724 /* Used only by the dynamic linker. When the object is run, this
725 longword is set to the load address of the object, plus the
727 HOWTO (R_PPC_RELATIVE
, /* type */
729 2, /* size (0 = byte, 1 = short, 2 = long) */
731 FALSE
, /* pc_relative */
733 complain_overflow_bitfield
, /* complain_on_overflow */
734 bfd_elf_generic_reloc
, /* special_function */
735 "R_PPC_RELATIVE", /* name */
736 FALSE
, /* partial_inplace */
738 0xffffffff, /* dst_mask */
739 FALSE
), /* pcrel_offset */
741 /* Like R_PPC_REL24, but uses the value of the symbol within the
742 object rather than the final value. Normally used for
743 _GLOBAL_OFFSET_TABLE_. */
744 HOWTO (R_PPC_LOCAL24PC
, /* type */
746 2, /* size (0 = byte, 1 = short, 2 = long) */
748 TRUE
, /* pc_relative */
750 complain_overflow_signed
, /* complain_on_overflow */
751 bfd_elf_generic_reloc
, /* special_function */
752 "R_PPC_LOCAL24PC", /* name */
753 FALSE
, /* partial_inplace */
755 0x3fffffc, /* dst_mask */
756 TRUE
), /* pcrel_offset */
758 /* Like R_PPC_ADDR32, but may be unaligned. */
759 HOWTO (R_PPC_UADDR32
, /* type */
761 2, /* size (0 = byte, 1 = short, 2 = long) */
763 FALSE
, /* pc_relative */
765 complain_overflow_bitfield
, /* complain_on_overflow */
766 bfd_elf_generic_reloc
, /* special_function */
767 "R_PPC_UADDR32", /* name */
768 FALSE
, /* partial_inplace */
770 0xffffffff, /* dst_mask */
771 FALSE
), /* pcrel_offset */
773 /* Like R_PPC_ADDR16, but may be unaligned. */
774 HOWTO (R_PPC_UADDR16
, /* type */
776 1, /* size (0 = byte, 1 = short, 2 = long) */
778 FALSE
, /* pc_relative */
780 complain_overflow_bitfield
, /* complain_on_overflow */
781 bfd_elf_generic_reloc
, /* special_function */
782 "R_PPC_UADDR16", /* name */
783 FALSE
, /* partial_inplace */
785 0xffff, /* dst_mask */
786 FALSE
), /* pcrel_offset */
788 /* 32-bit PC relative */
789 HOWTO (R_PPC_REL32
, /* type */
791 2, /* size (0 = byte, 1 = short, 2 = long) */
793 TRUE
, /* pc_relative */
795 complain_overflow_bitfield
, /* complain_on_overflow */
796 bfd_elf_generic_reloc
, /* special_function */
797 "R_PPC_REL32", /* name */
798 FALSE
, /* partial_inplace */
800 0xffffffff, /* dst_mask */
801 TRUE
), /* pcrel_offset */
803 /* 32-bit relocation to the symbol's procedure linkage table.
804 FIXME: not supported. */
805 HOWTO (R_PPC_PLT32
, /* type */
807 2, /* size (0 = byte, 1 = short, 2 = long) */
809 FALSE
, /* pc_relative */
811 complain_overflow_bitfield
, /* complain_on_overflow */
812 bfd_elf_generic_reloc
, /* special_function */
813 "R_PPC_PLT32", /* name */
814 FALSE
, /* partial_inplace */
817 FALSE
), /* pcrel_offset */
819 /* 32-bit PC relative relocation to the symbol's procedure linkage table.
820 FIXME: not supported. */
821 HOWTO (R_PPC_PLTREL32
, /* type */
823 2, /* size (0 = byte, 1 = short, 2 = long) */
825 TRUE
, /* pc_relative */
827 complain_overflow_bitfield
, /* complain_on_overflow */
828 bfd_elf_generic_reloc
, /* special_function */
829 "R_PPC_PLTREL32", /* name */
830 FALSE
, /* partial_inplace */
833 TRUE
), /* pcrel_offset */
835 /* Like R_PPC_ADDR16_LO, but referring to the PLT table entry for
837 HOWTO (R_PPC_PLT16_LO
, /* type */
839 1, /* size (0 = byte, 1 = short, 2 = long) */
841 FALSE
, /* pc_relative */
843 complain_overflow_dont
, /* complain_on_overflow */
844 bfd_elf_generic_reloc
, /* special_function */
845 "R_PPC_PLT16_LO", /* name */
846 FALSE
, /* partial_inplace */
848 0xffff, /* dst_mask */
849 FALSE
), /* pcrel_offset */
851 /* Like R_PPC_ADDR16_HI, but referring to the PLT table entry for
853 HOWTO (R_PPC_PLT16_HI
, /* type */
855 1, /* size (0 = byte, 1 = short, 2 = long) */
857 FALSE
, /* pc_relative */
859 complain_overflow_bitfield
, /* complain_on_overflow */
860 bfd_elf_generic_reloc
, /* special_function */
861 "R_PPC_PLT16_HI", /* name */
862 FALSE
, /* partial_inplace */
864 0xffff, /* dst_mask */
865 FALSE
), /* pcrel_offset */
867 /* Like R_PPC_ADDR16_HA, but referring to the PLT table entry for
869 HOWTO (R_PPC_PLT16_HA
, /* type */
871 1, /* size (0 = byte, 1 = short, 2 = long) */
873 FALSE
, /* pc_relative */
875 complain_overflow_bitfield
, /* complain_on_overflow */
876 ppc_elf_addr16_ha_reloc
, /* special_function */
877 "R_PPC_PLT16_HA", /* name */
878 FALSE
, /* partial_inplace */
880 0xffff, /* dst_mask */
881 FALSE
), /* pcrel_offset */
883 /* A sign-extended 16 bit value relative to _SDA_BASE_, for use with
885 HOWTO (R_PPC_SDAREL16
, /* type */
887 1, /* size (0 = byte, 1 = short, 2 = long) */
889 FALSE
, /* pc_relative */
891 complain_overflow_signed
, /* complain_on_overflow */
892 bfd_elf_generic_reloc
, /* special_function */
893 "R_PPC_SDAREL16", /* name */
894 FALSE
, /* partial_inplace */
896 0xffff, /* dst_mask */
897 FALSE
), /* pcrel_offset */
899 /* 16-bit section relative relocation. */
900 HOWTO (R_PPC_SECTOFF
, /* type */
902 1, /* size (0 = byte, 1 = short, 2 = long) */
904 FALSE
, /* pc_relative */
906 complain_overflow_bitfield
, /* complain_on_overflow */
907 bfd_elf_generic_reloc
, /* special_function */
908 "R_PPC_SECTOFF", /* name */
909 FALSE
, /* partial_inplace */
911 0xffff, /* dst_mask */
912 FALSE
), /* pcrel_offset */
914 /* 16-bit lower half section relative relocation. */
915 HOWTO (R_PPC_SECTOFF_LO
, /* type */
917 1, /* size (0 = byte, 1 = short, 2 = long) */
919 FALSE
, /* pc_relative */
921 complain_overflow_dont
, /* complain_on_overflow */
922 bfd_elf_generic_reloc
, /* special_function */
923 "R_PPC_SECTOFF_LO", /* name */
924 FALSE
, /* partial_inplace */
926 0xffff, /* dst_mask */
927 FALSE
), /* pcrel_offset */
929 /* 16-bit upper half section relative relocation. */
930 HOWTO (R_PPC_SECTOFF_HI
, /* type */
932 1, /* size (0 = byte, 1 = short, 2 = long) */
934 FALSE
, /* pc_relative */
936 complain_overflow_bitfield
, /* complain_on_overflow */
937 bfd_elf_generic_reloc
, /* special_function */
938 "R_PPC_SECTOFF_HI", /* name */
939 FALSE
, /* partial_inplace */
941 0xffff, /* dst_mask */
942 FALSE
), /* pcrel_offset */
944 /* 16-bit upper half adjusted section relative relocation. */
945 HOWTO (R_PPC_SECTOFF_HA
, /* type */
947 1, /* size (0 = byte, 1 = short, 2 = long) */
949 FALSE
, /* pc_relative */
951 complain_overflow_bitfield
, /* complain_on_overflow */
952 ppc_elf_addr16_ha_reloc
, /* special_function */
953 "R_PPC_SECTOFF_HA", /* name */
954 FALSE
, /* partial_inplace */
956 0xffff, /* dst_mask */
957 FALSE
), /* pcrel_offset */
959 /* Marker reloc for TLS. */
962 2, /* size (0 = byte, 1 = short, 2 = long) */
964 FALSE
, /* pc_relative */
966 complain_overflow_dont
, /* complain_on_overflow */
967 bfd_elf_generic_reloc
, /* special_function */
968 "R_PPC_TLS", /* name */
969 FALSE
, /* partial_inplace */
972 FALSE
), /* pcrel_offset */
974 /* Computes the load module index of the load module that contains the
975 definition of its TLS sym. */
976 HOWTO (R_PPC_DTPMOD32
,
978 2, /* size (0 = byte, 1 = short, 2 = long) */
980 FALSE
, /* pc_relative */
982 complain_overflow_dont
, /* complain_on_overflow */
983 ppc_elf_unhandled_reloc
, /* special_function */
984 "R_PPC_DTPMOD32", /* name */
985 FALSE
, /* partial_inplace */
987 0xffffffff, /* dst_mask */
988 FALSE
), /* pcrel_offset */
990 /* Computes a dtv-relative displacement, the difference between the value
991 of sym+add and the base address of the thread-local storage block that
992 contains the definition of sym, minus 0x8000. */
993 HOWTO (R_PPC_DTPREL32
,
995 2, /* size (0 = byte, 1 = short, 2 = long) */
997 FALSE
, /* pc_relative */
999 complain_overflow_dont
, /* complain_on_overflow */
1000 ppc_elf_unhandled_reloc
, /* special_function */
1001 "R_PPC_DTPREL32", /* name */
1002 FALSE
, /* partial_inplace */
1004 0xffffffff, /* dst_mask */
1005 FALSE
), /* pcrel_offset */
1007 /* A 16 bit dtprel reloc. */
1008 HOWTO (R_PPC_DTPREL16
,
1010 1, /* size (0 = byte, 1 = short, 2 = long) */
1012 FALSE
, /* pc_relative */
1014 complain_overflow_signed
, /* complain_on_overflow */
1015 ppc_elf_unhandled_reloc
, /* special_function */
1016 "R_PPC_DTPREL16", /* name */
1017 FALSE
, /* partial_inplace */
1019 0xffff, /* dst_mask */
1020 FALSE
), /* pcrel_offset */
1022 /* Like DTPREL16, but no overflow. */
1023 HOWTO (R_PPC_DTPREL16_LO
,
1025 1, /* size (0 = byte, 1 = short, 2 = long) */
1027 FALSE
, /* pc_relative */
1029 complain_overflow_dont
, /* complain_on_overflow */
1030 ppc_elf_unhandled_reloc
, /* special_function */
1031 "R_PPC_DTPREL16_LO", /* name */
1032 FALSE
, /* partial_inplace */
1034 0xffff, /* dst_mask */
1035 FALSE
), /* pcrel_offset */
1037 /* Like DTPREL16_LO, but next higher group of 16 bits. */
1038 HOWTO (R_PPC_DTPREL16_HI
,
1039 16, /* rightshift */
1040 1, /* size (0 = byte, 1 = short, 2 = long) */
1042 FALSE
, /* pc_relative */
1044 complain_overflow_dont
, /* complain_on_overflow */
1045 ppc_elf_unhandled_reloc
, /* special_function */
1046 "R_PPC_DTPREL16_HI", /* name */
1047 FALSE
, /* partial_inplace */
1049 0xffff, /* dst_mask */
1050 FALSE
), /* pcrel_offset */
1052 /* Like DTPREL16_HI, but adjust for low 16 bits. */
1053 HOWTO (R_PPC_DTPREL16_HA
,
1054 16, /* rightshift */
1055 1, /* size (0 = byte, 1 = short, 2 = long) */
1057 FALSE
, /* pc_relative */
1059 complain_overflow_dont
, /* complain_on_overflow */
1060 ppc_elf_unhandled_reloc
, /* special_function */
1061 "R_PPC_DTPREL16_HA", /* name */
1062 FALSE
, /* partial_inplace */
1064 0xffff, /* dst_mask */
1065 FALSE
), /* pcrel_offset */
1067 /* Computes a tp-relative displacement, the difference between the value of
1068 sym+add and the value of the thread pointer (r13). */
1069 HOWTO (R_PPC_TPREL32
,
1071 2, /* size (0 = byte, 1 = short, 2 = long) */
1073 FALSE
, /* pc_relative */
1075 complain_overflow_dont
, /* complain_on_overflow */
1076 ppc_elf_unhandled_reloc
, /* special_function */
1077 "R_PPC_TPREL32", /* name */
1078 FALSE
, /* partial_inplace */
1080 0xffffffff, /* dst_mask */
1081 FALSE
), /* pcrel_offset */
1083 /* A 16 bit tprel reloc. */
1084 HOWTO (R_PPC_TPREL16
,
1086 1, /* size (0 = byte, 1 = short, 2 = long) */
1088 FALSE
, /* pc_relative */
1090 complain_overflow_signed
, /* complain_on_overflow */
1091 ppc_elf_unhandled_reloc
, /* special_function */
1092 "R_PPC_TPREL16", /* name */
1093 FALSE
, /* partial_inplace */
1095 0xffff, /* dst_mask */
1096 FALSE
), /* pcrel_offset */
1098 /* Like TPREL16, but no overflow. */
1099 HOWTO (R_PPC_TPREL16_LO
,
1101 1, /* size (0 = byte, 1 = short, 2 = long) */
1103 FALSE
, /* pc_relative */
1105 complain_overflow_dont
, /* complain_on_overflow */
1106 ppc_elf_unhandled_reloc
, /* special_function */
1107 "R_PPC_TPREL16_LO", /* name */
1108 FALSE
, /* partial_inplace */
1110 0xffff, /* dst_mask */
1111 FALSE
), /* pcrel_offset */
1113 /* Like TPREL16_LO, but next higher group of 16 bits. */
1114 HOWTO (R_PPC_TPREL16_HI
,
1115 16, /* rightshift */
1116 1, /* size (0 = byte, 1 = short, 2 = long) */
1118 FALSE
, /* pc_relative */
1120 complain_overflow_dont
, /* complain_on_overflow */
1121 ppc_elf_unhandled_reloc
, /* special_function */
1122 "R_PPC_TPREL16_HI", /* name */
1123 FALSE
, /* partial_inplace */
1125 0xffff, /* dst_mask */
1126 FALSE
), /* pcrel_offset */
1128 /* Like TPREL16_HI, but adjust for low 16 bits. */
1129 HOWTO (R_PPC_TPREL16_HA
,
1130 16, /* rightshift */
1131 1, /* size (0 = byte, 1 = short, 2 = long) */
1133 FALSE
, /* pc_relative */
1135 complain_overflow_dont
, /* complain_on_overflow */
1136 ppc_elf_unhandled_reloc
, /* special_function */
1137 "R_PPC_TPREL16_HA", /* name */
1138 FALSE
, /* partial_inplace */
1140 0xffff, /* dst_mask */
1141 FALSE
), /* pcrel_offset */
1143 /* Allocates two contiguous entries in the GOT to hold a tls_index structure,
1144 with values (sym+add)@dtpmod and (sym+add)@dtprel, and computes the offset
1145 to the first entry. */
1146 HOWTO (R_PPC_GOT_TLSGD16
,
1148 1, /* size (0 = byte, 1 = short, 2 = long) */
1150 FALSE
, /* pc_relative */
1152 complain_overflow_signed
, /* complain_on_overflow */
1153 ppc_elf_unhandled_reloc
, /* special_function */
1154 "R_PPC_GOT_TLSGD16", /* name */
1155 FALSE
, /* partial_inplace */
1157 0xffff, /* dst_mask */
1158 FALSE
), /* pcrel_offset */
1160 /* Like GOT_TLSGD16, but no overflow. */
1161 HOWTO (R_PPC_GOT_TLSGD16_LO
,
1163 1, /* size (0 = byte, 1 = short, 2 = long) */
1165 FALSE
, /* pc_relative */
1167 complain_overflow_dont
, /* complain_on_overflow */
1168 ppc_elf_unhandled_reloc
, /* special_function */
1169 "R_PPC_GOT_TLSGD16_LO", /* name */
1170 FALSE
, /* partial_inplace */
1172 0xffff, /* dst_mask */
1173 FALSE
), /* pcrel_offset */
1175 /* Like GOT_TLSGD16_LO, but next higher group of 16 bits. */
1176 HOWTO (R_PPC_GOT_TLSGD16_HI
,
1177 16, /* rightshift */
1178 1, /* size (0 = byte, 1 = short, 2 = long) */
1180 FALSE
, /* pc_relative */
1182 complain_overflow_dont
, /* complain_on_overflow */
1183 ppc_elf_unhandled_reloc
, /* special_function */
1184 "R_PPC_GOT_TLSGD16_HI", /* name */
1185 FALSE
, /* partial_inplace */
1187 0xffff, /* dst_mask */
1188 FALSE
), /* pcrel_offset */
1190 /* Like GOT_TLSGD16_HI, but adjust for low 16 bits. */
1191 HOWTO (R_PPC_GOT_TLSGD16_HA
,
1192 16, /* rightshift */
1193 1, /* size (0 = byte, 1 = short, 2 = long) */
1195 FALSE
, /* pc_relative */
1197 complain_overflow_dont
, /* complain_on_overflow */
1198 ppc_elf_unhandled_reloc
, /* special_function */
1199 "R_PPC_GOT_TLSGD16_HA", /* name */
1200 FALSE
, /* partial_inplace */
1202 0xffff, /* dst_mask */
1203 FALSE
), /* pcrel_offset */
1205 /* Allocates two contiguous entries in the GOT to hold a tls_index structure,
1206 with values (sym+add)@dtpmod and zero, and computes the offset to the
1208 HOWTO (R_PPC_GOT_TLSLD16
,
1210 1, /* size (0 = byte, 1 = short, 2 = long) */
1212 FALSE
, /* pc_relative */
1214 complain_overflow_signed
, /* complain_on_overflow */
1215 ppc_elf_unhandled_reloc
, /* special_function */
1216 "R_PPC_GOT_TLSLD16", /* name */
1217 FALSE
, /* partial_inplace */
1219 0xffff, /* dst_mask */
1220 FALSE
), /* pcrel_offset */
1222 /* Like GOT_TLSLD16, but no overflow. */
1223 HOWTO (R_PPC_GOT_TLSLD16_LO
,
1225 1, /* size (0 = byte, 1 = short, 2 = long) */
1227 FALSE
, /* pc_relative */
1229 complain_overflow_dont
, /* complain_on_overflow */
1230 ppc_elf_unhandled_reloc
, /* special_function */
1231 "R_PPC_GOT_TLSLD16_LO", /* name */
1232 FALSE
, /* partial_inplace */
1234 0xffff, /* dst_mask */
1235 FALSE
), /* pcrel_offset */
1237 /* Like GOT_TLSLD16_LO, but next higher group of 16 bits. */
1238 HOWTO (R_PPC_GOT_TLSLD16_HI
,
1239 16, /* rightshift */
1240 1, /* size (0 = byte, 1 = short, 2 = long) */
1242 FALSE
, /* pc_relative */
1244 complain_overflow_dont
, /* complain_on_overflow */
1245 ppc_elf_unhandled_reloc
, /* special_function */
1246 "R_PPC_GOT_TLSLD16_HI", /* name */
1247 FALSE
, /* partial_inplace */
1249 0xffff, /* dst_mask */
1250 FALSE
), /* pcrel_offset */
1252 /* Like GOT_TLSLD16_HI, but adjust for low 16 bits. */
1253 HOWTO (R_PPC_GOT_TLSLD16_HA
,
1254 16, /* rightshift */
1255 1, /* size (0 = byte, 1 = short, 2 = long) */
1257 FALSE
, /* pc_relative */
1259 complain_overflow_dont
, /* complain_on_overflow */
1260 ppc_elf_unhandled_reloc
, /* special_function */
1261 "R_PPC_GOT_TLSLD16_HA", /* name */
1262 FALSE
, /* partial_inplace */
1264 0xffff, /* dst_mask */
1265 FALSE
), /* pcrel_offset */
1267 /* Allocates an entry in the GOT with value (sym+add)@dtprel, and computes
1268 the offset to the entry. */
1269 HOWTO (R_PPC_GOT_DTPREL16
,
1271 1, /* size (0 = byte, 1 = short, 2 = long) */
1273 FALSE
, /* pc_relative */
1275 complain_overflow_signed
, /* complain_on_overflow */
1276 ppc_elf_unhandled_reloc
, /* special_function */
1277 "R_PPC_GOT_DTPREL16", /* name */
1278 FALSE
, /* partial_inplace */
1280 0xffff, /* dst_mask */
1281 FALSE
), /* pcrel_offset */
1283 /* Like GOT_DTPREL16, but no overflow. */
1284 HOWTO (R_PPC_GOT_DTPREL16_LO
,
1286 1, /* size (0 = byte, 1 = short, 2 = long) */
1288 FALSE
, /* pc_relative */
1290 complain_overflow_dont
, /* complain_on_overflow */
1291 ppc_elf_unhandled_reloc
, /* special_function */
1292 "R_PPC_GOT_DTPREL16_LO", /* name */
1293 FALSE
, /* partial_inplace */
1295 0xffff, /* dst_mask */
1296 FALSE
), /* pcrel_offset */
1298 /* Like GOT_DTPREL16_LO, but next higher group of 16 bits. */
1299 HOWTO (R_PPC_GOT_DTPREL16_HI
,
1300 16, /* rightshift */
1301 1, /* size (0 = byte, 1 = short, 2 = long) */
1303 FALSE
, /* pc_relative */
1305 complain_overflow_dont
, /* complain_on_overflow */
1306 ppc_elf_unhandled_reloc
, /* special_function */
1307 "R_PPC_GOT_DTPREL16_HI", /* name */
1308 FALSE
, /* partial_inplace */
1310 0xffff, /* dst_mask */
1311 FALSE
), /* pcrel_offset */
1313 /* Like GOT_DTPREL16_HI, but adjust for low 16 bits. */
1314 HOWTO (R_PPC_GOT_DTPREL16_HA
,
1315 16, /* rightshift */
1316 1, /* size (0 = byte, 1 = short, 2 = long) */
1318 FALSE
, /* pc_relative */
1320 complain_overflow_dont
, /* complain_on_overflow */
1321 ppc_elf_unhandled_reloc
, /* special_function */
1322 "R_PPC_GOT_DTPREL16_HA", /* name */
1323 FALSE
, /* partial_inplace */
1325 0xffff, /* dst_mask */
1326 FALSE
), /* pcrel_offset */
1328 /* Allocates an entry in the GOT with value (sym+add)@tprel, and computes the
1329 offset to the entry. */
1330 HOWTO (R_PPC_GOT_TPREL16
,
1332 1, /* size (0 = byte, 1 = short, 2 = long) */
1334 FALSE
, /* pc_relative */
1336 complain_overflow_signed
, /* complain_on_overflow */
1337 ppc_elf_unhandled_reloc
, /* special_function */
1338 "R_PPC_GOT_TPREL16", /* name */
1339 FALSE
, /* partial_inplace */
1341 0xffff, /* dst_mask */
1342 FALSE
), /* pcrel_offset */
1344 /* Like GOT_TPREL16, but no overflow. */
1345 HOWTO (R_PPC_GOT_TPREL16_LO
,
1347 1, /* size (0 = byte, 1 = short, 2 = long) */
1349 FALSE
, /* pc_relative */
1351 complain_overflow_dont
, /* complain_on_overflow */
1352 ppc_elf_unhandled_reloc
, /* special_function */
1353 "R_PPC_GOT_TPREL16_LO", /* name */
1354 FALSE
, /* partial_inplace */
1356 0xffff, /* dst_mask */
1357 FALSE
), /* pcrel_offset */
1359 /* Like GOT_TPREL16_LO, but next higher group of 16 bits. */
1360 HOWTO (R_PPC_GOT_TPREL16_HI
,
1361 16, /* rightshift */
1362 1, /* size (0 = byte, 1 = short, 2 = long) */
1364 FALSE
, /* pc_relative */
1366 complain_overflow_dont
, /* complain_on_overflow */
1367 ppc_elf_unhandled_reloc
, /* special_function */
1368 "R_PPC_GOT_TPREL16_HI", /* name */
1369 FALSE
, /* partial_inplace */
1371 0xffff, /* dst_mask */
1372 FALSE
), /* pcrel_offset */
1374 /* Like GOT_TPREL16_HI, but adjust for low 16 bits. */
1375 HOWTO (R_PPC_GOT_TPREL16_HA
,
1376 16, /* rightshift */
1377 1, /* size (0 = byte, 1 = short, 2 = long) */
1379 FALSE
, /* pc_relative */
1381 complain_overflow_dont
, /* complain_on_overflow */
1382 ppc_elf_unhandled_reloc
, /* special_function */
1383 "R_PPC_GOT_TPREL16_HA", /* name */
1384 FALSE
, /* partial_inplace */
1386 0xffff, /* dst_mask */
1387 FALSE
), /* pcrel_offset */
1389 /* The remaining relocs are from the Embedded ELF ABI, and are not
1390 in the SVR4 ELF ABI. */
1392 /* 32 bit value resulting from the addend minus the symbol. */
1393 HOWTO (R_PPC_EMB_NADDR32
, /* type */
1395 2, /* size (0 = byte, 1 = short, 2 = long) */
1397 FALSE
, /* pc_relative */
1399 complain_overflow_bitfield
, /* complain_on_overflow */
1400 bfd_elf_generic_reloc
, /* special_function */
1401 "R_PPC_EMB_NADDR32", /* name */
1402 FALSE
, /* partial_inplace */
1404 0xffffffff, /* dst_mask */
1405 FALSE
), /* pcrel_offset */
1407 /* 16 bit value resulting from the addend minus the symbol. */
1408 HOWTO (R_PPC_EMB_NADDR16
, /* 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_NADDR16", /* name */
1417 FALSE
, /* partial_inplace */
1419 0xffff, /* dst_mask */
1420 FALSE
), /* pcrel_offset */
1422 /* 16 bit value resulting from the addend minus the symbol. */
1423 HOWTO (R_PPC_EMB_NADDR16_LO
, /* type */
1425 1, /* size (0 = byte, 1 = short, 2 = long) */
1427 FALSE
, /* pc_relative */
1429 complain_overflow_dont
,/* complain_on_overflow */
1430 bfd_elf_generic_reloc
, /* special_function */
1431 "R_PPC_EMB_ADDR16_LO", /* name */
1432 FALSE
, /* partial_inplace */
1434 0xffff, /* dst_mask */
1435 FALSE
), /* pcrel_offset */
1437 /* The high order 16 bits of the addend minus the symbol. */
1438 HOWTO (R_PPC_EMB_NADDR16_HI
, /* type */
1439 16, /* rightshift */
1440 1, /* size (0 = byte, 1 = short, 2 = long) */
1442 FALSE
, /* pc_relative */
1444 complain_overflow_dont
, /* complain_on_overflow */
1445 bfd_elf_generic_reloc
, /* special_function */
1446 "R_PPC_EMB_NADDR16_HI", /* name */
1447 FALSE
, /* partial_inplace */
1449 0xffff, /* dst_mask */
1450 FALSE
), /* pcrel_offset */
1452 /* The high order 16 bits of the result of the addend minus the address,
1453 plus 1 if the contents of the low 16 bits, treated as a signed number,
1455 HOWTO (R_PPC_EMB_NADDR16_HA
, /* type */
1456 16, /* rightshift */
1457 1, /* size (0 = byte, 1 = short, 2 = long) */
1459 FALSE
, /* pc_relative */
1461 complain_overflow_dont
, /* complain_on_overflow */
1462 ppc_elf_addr16_ha_reloc
, /* special_function */
1463 "R_PPC_EMB_NADDR16_HA", /* name */
1464 FALSE
, /* partial_inplace */
1466 0xffff, /* dst_mask */
1467 FALSE
), /* pcrel_offset */
1469 /* 16 bit value resulting from allocating a 4 byte word to hold an
1470 address in the .sdata section, and returning the offset from
1471 _SDA_BASE_ for that relocation. */
1472 HOWTO (R_PPC_EMB_SDAI16
, /* type */
1474 1, /* size (0 = byte, 1 = short, 2 = long) */
1476 FALSE
, /* pc_relative */
1478 complain_overflow_bitfield
, /* complain_on_overflow */
1479 bfd_elf_generic_reloc
, /* special_function */
1480 "R_PPC_EMB_SDAI16", /* name */
1481 FALSE
, /* partial_inplace */
1483 0xffff, /* dst_mask */
1484 FALSE
), /* pcrel_offset */
1486 /* 16 bit value resulting from allocating a 4 byte word to hold an
1487 address in the .sdata2 section, and returning the offset from
1488 _SDA2_BASE_ for that relocation. */
1489 HOWTO (R_PPC_EMB_SDA2I16
, /* type */
1491 1, /* size (0 = byte, 1 = short, 2 = long) */
1493 FALSE
, /* pc_relative */
1495 complain_overflow_bitfield
, /* complain_on_overflow */
1496 bfd_elf_generic_reloc
, /* special_function */
1497 "R_PPC_EMB_SDA2I16", /* name */
1498 FALSE
, /* partial_inplace */
1500 0xffff, /* dst_mask */
1501 FALSE
), /* pcrel_offset */
1503 /* A sign-extended 16 bit value relative to _SDA2_BASE_, for use with
1504 small data items. */
1505 HOWTO (R_PPC_EMB_SDA2REL
, /* type */
1507 1, /* size (0 = byte, 1 = short, 2 = long) */
1509 FALSE
, /* pc_relative */
1511 complain_overflow_signed
, /* complain_on_overflow */
1512 bfd_elf_generic_reloc
, /* special_function */
1513 "R_PPC_EMB_SDA2REL", /* name */
1514 FALSE
, /* partial_inplace */
1516 0xffff, /* dst_mask */
1517 FALSE
), /* pcrel_offset */
1519 /* Relocate against either _SDA_BASE_ or _SDA2_BASE_, filling in the 16 bit
1520 signed offset from the appropriate base, and filling in the register
1521 field with the appropriate register (0, 2, or 13). */
1522 HOWTO (R_PPC_EMB_SDA21
, /* type */
1524 2, /* size (0 = byte, 1 = short, 2 = long) */
1526 FALSE
, /* pc_relative */
1528 complain_overflow_signed
, /* complain_on_overflow */
1529 bfd_elf_generic_reloc
, /* special_function */
1530 "R_PPC_EMB_SDA21", /* name */
1531 FALSE
, /* partial_inplace */
1533 0xffff, /* dst_mask */
1534 FALSE
), /* pcrel_offset */
1536 /* Relocation not handled: R_PPC_EMB_MRKREF */
1537 /* Relocation not handled: R_PPC_EMB_RELSEC16 */
1538 /* Relocation not handled: R_PPC_EMB_RELST_LO */
1539 /* Relocation not handled: R_PPC_EMB_RELST_HI */
1540 /* Relocation not handled: R_PPC_EMB_RELST_HA */
1541 /* Relocation not handled: R_PPC_EMB_BIT_FLD */
1543 /* PC relative relocation against either _SDA_BASE_ or _SDA2_BASE_, filling
1544 in the 16 bit signed offset from the appropriate base, and filling in the
1545 register field with the appropriate register (0, 2, or 13). */
1546 HOWTO (R_PPC_EMB_RELSDA
, /* type */
1548 1, /* size (0 = byte, 1 = short, 2 = long) */
1550 TRUE
, /* pc_relative */
1552 complain_overflow_signed
, /* complain_on_overflow */
1553 bfd_elf_generic_reloc
, /* special_function */
1554 "R_PPC_EMB_RELSDA", /* name */
1555 FALSE
, /* partial_inplace */
1557 0xffff, /* dst_mask */
1558 FALSE
), /* pcrel_offset */
1560 /* GNU extension to record C++ vtable hierarchy. */
1561 HOWTO (R_PPC_GNU_VTINHERIT
, /* type */
1563 0, /* size (0 = byte, 1 = short, 2 = long) */
1565 FALSE
, /* pc_relative */
1567 complain_overflow_dont
, /* complain_on_overflow */
1568 NULL
, /* special_function */
1569 "R_PPC_GNU_VTINHERIT", /* name */
1570 FALSE
, /* partial_inplace */
1573 FALSE
), /* pcrel_offset */
1575 /* GNU extension to record C++ vtable member usage. */
1576 HOWTO (R_PPC_GNU_VTENTRY
, /* type */
1578 0, /* size (0 = byte, 1 = short, 2 = long) */
1580 FALSE
, /* pc_relative */
1582 complain_overflow_dont
, /* complain_on_overflow */
1583 NULL
, /* special_function */
1584 "R_PPC_GNU_VTENTRY", /* name */
1585 FALSE
, /* partial_inplace */
1588 FALSE
), /* pcrel_offset */
1590 /* Phony reloc to handle AIX style TOC entries. */
1591 HOWTO (R_PPC_TOC16
, /* type */
1593 1, /* size (0 = byte, 1 = short, 2 = long) */
1595 FALSE
, /* pc_relative */
1597 complain_overflow_signed
, /* complain_on_overflow */
1598 bfd_elf_generic_reloc
, /* special_function */
1599 "R_PPC_TOC16", /* name */
1600 FALSE
, /* partial_inplace */
1602 0xffff, /* dst_mask */
1603 FALSE
), /* pcrel_offset */
1606 /* Initialize the ppc_elf_howto_table, so that linear accesses can be done. */
1609 ppc_elf_howto_init ()
1611 unsigned int i
, type
;
1614 i
< sizeof (ppc_elf_howto_raw
) / sizeof (ppc_elf_howto_raw
[0]);
1617 type
= ppc_elf_howto_raw
[i
].type
;
1618 if (type
>= (sizeof (ppc_elf_howto_table
)
1619 / sizeof (ppc_elf_howto_table
[0])))
1621 ppc_elf_howto_table
[type
] = &ppc_elf_howto_raw
[i
];
1625 /* This function handles relaxing for the PPC with option --mpc860c0[=<n>].
1627 The MPC860, revision C0 or earlier contains a bug in the die.
1628 If all of the following conditions are true, the next instruction
1629 to be executed *may* be treated as a no-op.
1630 1/ A forward branch is executed.
1631 2/ The branch is predicted as not taken.
1632 3/ The branch is taken.
1633 4/ The branch is located in the last 5 words of a page.
1634 (The EOP limit is 5 by default but may be specified as any value
1637 Our software solution is to detect these problematic branches in a
1638 linker pass and modify them as follows:
1639 1/ Unconditional branches - Since these are always predicted taken,
1640 there is no problem and no action is required.
1641 2/ Conditional backward branches - No problem, no action required.
1642 3/ Conditional forward branches - Ensure that the "inverse prediction
1643 bit" is set (ensure it is predicted taken).
1644 4/ Conditional register branches - Ensure that the "y bit" is set
1645 (ensure it is predicted taken). */
1647 /* Sort sections by address. */
1650 ppc_elf_sort_rela (arg1
, arg2
)
1654 const Elf_Internal_Rela
**rela1
= (const Elf_Internal_Rela
**) arg1
;
1655 const Elf_Internal_Rela
**rela2
= (const Elf_Internal_Rela
**) arg2
;
1657 /* Sort by offset. */
1658 return ((*rela1
)->r_offset
- (*rela2
)->r_offset
);
1662 ppc_elf_relax_section (abfd
, isec
, link_info
, again
)
1665 struct bfd_link_info
*link_info
;
1668 #define PAGESIZE 0x1000
1670 bfd_byte
*contents
= NULL
;
1671 bfd_byte
*free_contents
= NULL
;
1672 Elf_Internal_Rela
*internal_relocs
= NULL
;
1673 Elf_Internal_Rela
*free_relocs
= NULL
;
1674 Elf_Internal_Rela
**rela_comb
= NULL
;
1675 int comb_curr
, comb_count
;
1677 /* We never have to do this more than once per input section. */
1680 /* If needed, initialize this section's cooked size. */
1681 if (isec
->_cooked_size
== 0)
1682 isec
->_cooked_size
= isec
->_raw_size
;
1684 /* We're only interested in text sections which overlap the
1685 troublesome area at the end of a page. */
1686 if (link_info
->mpc860c0
&& (isec
->flags
& SEC_CODE
) && isec
->_cooked_size
)
1688 bfd_vma dot
, end_page
, end_section
;
1689 bfd_boolean section_modified
;
1691 /* Get the section contents. */
1692 /* Get cached copy if it exists. */
1693 if (elf_section_data (isec
)->this_hdr
.contents
!= NULL
)
1694 contents
= elf_section_data (isec
)->this_hdr
.contents
;
1697 /* Go get them off disk. */
1698 contents
= (bfd_byte
*) bfd_malloc (isec
->_raw_size
);
1699 if (contents
== NULL
)
1701 free_contents
= contents
;
1703 if (! bfd_get_section_contents (abfd
, isec
, contents
,
1704 (file_ptr
) 0, isec
->_raw_size
))
1710 if (isec
->reloc_count
)
1715 /* Get a copy of the native relocations. */
1717 = _bfd_elf_link_read_relocs (abfd
, isec
, (PTR
) NULL
,
1718 (Elf_Internal_Rela
*) NULL
,
1719 link_info
->keep_memory
);
1720 if (internal_relocs
== NULL
)
1722 if (! link_info
->keep_memory
)
1723 free_relocs
= internal_relocs
;
1725 /* Setup a faster access method for the reloc info we need. */
1726 amt
= isec
->reloc_count
;
1727 amt
*= sizeof (Elf_Internal_Rela
*);
1728 rela_comb
= (Elf_Internal_Rela
**) bfd_malloc (amt
);
1729 if (rela_comb
== NULL
)
1731 for (n
= 0; n
< isec
->reloc_count
; ++n
)
1735 r_type
= ELF32_R_TYPE (internal_relocs
[n
].r_info
);
1736 if (r_type
< 0 || r_type
>= (int) R_PPC_max
)
1739 /* Prologue constants are sometimes present in the ".text"
1740 sections and they can be identified by their associated
1741 relocation. We don't want to process those words and
1742 some others which can also be identified by their
1743 relocations. However, not all conditional branches will
1744 have a relocation so we will only ignore words that
1745 1) have a reloc, and 2) the reloc is not applicable to a
1746 conditional branch. The array rela_comb is built here
1747 for use in the EOP scan loop. */
1750 case R_PPC_ADDR14_BRNTAKEN
:
1752 case R_PPC_REL14_BRNTAKEN
:
1753 /* We should check the instruction. */
1756 /* The word is not a conditional branch - ignore it. */
1757 rela_comb
[comb_count
++] = &internal_relocs
[n
];
1762 qsort (rela_comb
, (size_t) comb_count
, sizeof (int),
1766 /* Enumerate each EOP region that overlaps this section. */
1767 end_section
= isec
->vma
+ isec
->_cooked_size
;
1768 dot
= end_page
= (isec
->vma
| (PAGESIZE
- 1)) + 1;
1769 dot
-= link_info
->mpc860c0
;
1770 section_modified
= FALSE
;
1771 /* Increment the start position if this section begins in the
1772 middle of its first EOP region. */
1773 if (dot
< isec
->vma
)
1777 dot
+= PAGESIZE
, end_page
+= PAGESIZE
)
1779 /* Check each word in this EOP region. */
1780 for (; dot
< end_page
; dot
+= 4)
1782 bfd_vma isec_offset
;
1784 bfd_boolean skip
, modified
;
1786 /* Don't process this word if there is a relocation for it
1787 and the relocation indicates the word is not a
1788 conditional branch. */
1790 isec_offset
= dot
- isec
->vma
;
1791 for (; comb_curr
<comb_count
; ++comb_curr
)
1795 r_offset
= rela_comb
[comb_curr
]->r_offset
;
1796 if (r_offset
>= isec_offset
)
1798 if (r_offset
== isec_offset
) skip
= TRUE
;
1804 /* Check the current word for a problematic conditional
1806 #define BO0(insn) ((insn) & 0x02000000)
1807 #define BO2(insn) ((insn) & 0x00800000)
1808 #define BO4(insn) ((insn) & 0x00200000)
1809 insn
= (unsigned long) bfd_get_32 (abfd
, contents
+ isec_offset
);
1811 if ((insn
& 0xFc000000) == 0x40000000)
1813 /* Instruction is BCx */
1814 if ((!BO0(insn
) || !BO2(insn
)) && !BO4(insn
))
1818 /* This branch is predicted as "normal".
1819 If this is a forward branch, it is problematic. */
1820 target
= insn
& 0x0000Fffc;
1821 target
= (target
^ 0x8000) - 0x8000;
1822 if ((insn
& 0x00000002) == 0)
1823 /* Convert to abs. */
1827 /* Set the prediction bit. */
1833 else if ((insn
& 0xFc00Fffe) == 0x4c000420)
1835 /* Instruction is BCCTRx. */
1836 if ((!BO0(insn
) || !BO2(insn
)) && !BO4(insn
))
1838 /* This branch is predicted as not-taken.
1839 If this is a forward branch, it is problematic.
1840 Since we can't tell statically if it will branch
1841 forward, always set the prediction bit. */
1846 else if ((insn
& 0xFc00Fffe) == 0x4c000020)
1848 /* Instruction is BCLRx */
1849 if ((!BO0(insn
) || !BO2(insn
)) && !BO4(insn
))
1851 /* This branch is predicted as not-taken.
1852 If this is a forward branch, it is problematic.
1853 Since we can't tell statically if it will branch
1854 forward, always set the prediction bit. */
1864 bfd_put_32 (abfd
, (bfd_vma
) insn
, contents
+ isec_offset
);
1865 section_modified
= TRUE
;
1869 if (section_modified
)
1871 elf_section_data (isec
)->this_hdr
.contents
= contents
;
1872 free_contents
= NULL
;
1876 if (rela_comb
!= NULL
)
1882 if (free_relocs
!= NULL
)
1888 if (free_contents
!= NULL
)
1890 if (! link_info
->keep_memory
)
1891 free (free_contents
);
1894 /* Cache the section contents for elf_link_input_bfd. */
1895 elf_section_data (isec
)->this_hdr
.contents
= contents
;
1897 free_contents
= NULL
;
1903 if (rela_comb
!= NULL
)
1905 if (free_relocs
!= NULL
)
1907 if (free_contents
!= NULL
)
1908 free (free_contents
);
1912 static reloc_howto_type
*
1913 ppc_elf_reloc_type_lookup (abfd
, code
)
1914 bfd
*abfd ATTRIBUTE_UNUSED
;
1915 bfd_reloc_code_real_type code
;
1917 enum elf_ppc_reloc_type r
;
1919 if (!ppc_elf_howto_table
[R_PPC_ADDR32
])
1920 /* Initialize howto table if needed. */
1921 ppc_elf_howto_init ();
1926 return (reloc_howto_type
*) NULL
;
1928 case BFD_RELOC_NONE
: r
= R_PPC_NONE
; break;
1929 case BFD_RELOC_32
: r
= R_PPC_ADDR32
; break;
1930 case BFD_RELOC_PPC_BA26
: r
= R_PPC_ADDR24
; break;
1931 case BFD_RELOC_16
: r
= R_PPC_ADDR16
; break;
1932 case BFD_RELOC_LO16
: r
= R_PPC_ADDR16_LO
; break;
1933 case BFD_RELOC_HI16
: r
= R_PPC_ADDR16_HI
; break;
1934 case BFD_RELOC_HI16_S
: r
= R_PPC_ADDR16_HA
; break;
1935 case BFD_RELOC_PPC_BA16
: r
= R_PPC_ADDR14
; break;
1936 case BFD_RELOC_PPC_BA16_BRTAKEN
: r
= R_PPC_ADDR14_BRTAKEN
; break;
1937 case BFD_RELOC_PPC_BA16_BRNTAKEN
: r
= R_PPC_ADDR14_BRNTAKEN
; break;
1938 case BFD_RELOC_PPC_B26
: r
= R_PPC_REL24
; break;
1939 case BFD_RELOC_PPC_B16
: r
= R_PPC_REL14
; break;
1940 case BFD_RELOC_PPC_B16_BRTAKEN
: r
= R_PPC_REL14_BRTAKEN
; break;
1941 case BFD_RELOC_PPC_B16_BRNTAKEN
: r
= R_PPC_REL14_BRNTAKEN
; break;
1942 case BFD_RELOC_16_GOTOFF
: r
= R_PPC_GOT16
; break;
1943 case BFD_RELOC_LO16_GOTOFF
: r
= R_PPC_GOT16_LO
; break;
1944 case BFD_RELOC_HI16_GOTOFF
: r
= R_PPC_GOT16_HI
; break;
1945 case BFD_RELOC_HI16_S_GOTOFF
: r
= R_PPC_GOT16_HA
; break;
1946 case BFD_RELOC_24_PLT_PCREL
: r
= R_PPC_PLTREL24
; break;
1947 case BFD_RELOC_PPC_COPY
: r
= R_PPC_COPY
; break;
1948 case BFD_RELOC_PPC_GLOB_DAT
: r
= R_PPC_GLOB_DAT
; break;
1949 case BFD_RELOC_PPC_LOCAL24PC
: r
= R_PPC_LOCAL24PC
; break;
1950 case BFD_RELOC_32_PCREL
: r
= R_PPC_REL32
; break;
1951 case BFD_RELOC_32_PLTOFF
: r
= R_PPC_PLT32
; break;
1952 case BFD_RELOC_32_PLT_PCREL
: r
= R_PPC_PLTREL32
; break;
1953 case BFD_RELOC_LO16_PLTOFF
: r
= R_PPC_PLT16_LO
; break;
1954 case BFD_RELOC_HI16_PLTOFF
: r
= R_PPC_PLT16_HI
; break;
1955 case BFD_RELOC_HI16_S_PLTOFF
: r
= R_PPC_PLT16_HA
; break;
1956 case BFD_RELOC_GPREL16
: r
= R_PPC_SDAREL16
; break;
1957 case BFD_RELOC_16_BASEREL
: r
= R_PPC_SECTOFF
; break;
1958 case BFD_RELOC_LO16_BASEREL
: r
= R_PPC_SECTOFF_LO
; break;
1959 case BFD_RELOC_HI16_BASEREL
: r
= R_PPC_SECTOFF_HI
; break;
1960 case BFD_RELOC_HI16_S_BASEREL
: r
= R_PPC_SECTOFF_HA
; break;
1961 case BFD_RELOC_CTOR
: r
= R_PPC_ADDR32
; break;
1962 case BFD_RELOC_PPC_TOC16
: r
= R_PPC_TOC16
; break;
1963 case BFD_RELOC_PPC_TLS
: r
= R_PPC_TLS
; break;
1964 case BFD_RELOC_PPC_DTPMOD
: r
= R_PPC_DTPMOD32
; break;
1965 case BFD_RELOC_PPC_TPREL16
: r
= R_PPC_TPREL16
; break;
1966 case BFD_RELOC_PPC_TPREL16_LO
: r
= R_PPC_TPREL16_LO
; break;
1967 case BFD_RELOC_PPC_TPREL16_HI
: r
= R_PPC_TPREL16_HI
; break;
1968 case BFD_RELOC_PPC_TPREL16_HA
: r
= R_PPC_TPREL16_HA
; break;
1969 case BFD_RELOC_PPC_TPREL
: r
= R_PPC_TPREL32
; break;
1970 case BFD_RELOC_PPC_DTPREL16
: r
= R_PPC_DTPREL16
; break;
1971 case BFD_RELOC_PPC_DTPREL16_LO
: r
= R_PPC_DTPREL16_LO
; break;
1972 case BFD_RELOC_PPC_DTPREL16_HI
: r
= R_PPC_DTPREL16_HI
; break;
1973 case BFD_RELOC_PPC_DTPREL16_HA
: r
= R_PPC_DTPREL16_HA
; break;
1974 case BFD_RELOC_PPC_DTPREL
: r
= R_PPC_DTPREL32
; break;
1975 case BFD_RELOC_PPC_GOT_TLSGD16
: r
= R_PPC_GOT_TLSGD16
; break;
1976 case BFD_RELOC_PPC_GOT_TLSGD16_LO
: r
= R_PPC_GOT_TLSGD16_LO
; break;
1977 case BFD_RELOC_PPC_GOT_TLSGD16_HI
: r
= R_PPC_GOT_TLSGD16_HI
; break;
1978 case BFD_RELOC_PPC_GOT_TLSGD16_HA
: r
= R_PPC_GOT_TLSGD16_HA
; break;
1979 case BFD_RELOC_PPC_GOT_TLSLD16
: r
= R_PPC_GOT_TLSLD16
; break;
1980 case BFD_RELOC_PPC_GOT_TLSLD16_LO
: r
= R_PPC_GOT_TLSLD16_LO
; break;
1981 case BFD_RELOC_PPC_GOT_TLSLD16_HI
: r
= R_PPC_GOT_TLSLD16_HI
; break;
1982 case BFD_RELOC_PPC_GOT_TLSLD16_HA
: r
= R_PPC_GOT_TLSLD16_HA
; break;
1983 case BFD_RELOC_PPC_GOT_TPREL16
: r
= R_PPC_GOT_TPREL16
; break;
1984 case BFD_RELOC_PPC_GOT_TPREL16_LO
: r
= R_PPC_GOT_TPREL16_LO
; break;
1985 case BFD_RELOC_PPC_GOT_TPREL16_HI
: r
= R_PPC_GOT_TPREL16_HI
; break;
1986 case BFD_RELOC_PPC_GOT_TPREL16_HA
: r
= R_PPC_GOT_TPREL16_HA
; break;
1987 case BFD_RELOC_PPC_GOT_DTPREL16
: r
= R_PPC_GOT_DTPREL16
; break;
1988 case BFD_RELOC_PPC_GOT_DTPREL16_LO
: r
= R_PPC_GOT_DTPREL16_LO
; break;
1989 case BFD_RELOC_PPC_GOT_DTPREL16_HI
: r
= R_PPC_GOT_DTPREL16_HI
; break;
1990 case BFD_RELOC_PPC_GOT_DTPREL16_HA
: r
= R_PPC_GOT_DTPREL16_HA
; break;
1991 case BFD_RELOC_PPC_EMB_NADDR32
: r
= R_PPC_EMB_NADDR32
; break;
1992 case BFD_RELOC_PPC_EMB_NADDR16
: r
= R_PPC_EMB_NADDR16
; break;
1993 case BFD_RELOC_PPC_EMB_NADDR16_LO
: r
= R_PPC_EMB_NADDR16_LO
; break;
1994 case BFD_RELOC_PPC_EMB_NADDR16_HI
: r
= R_PPC_EMB_NADDR16_HI
; break;
1995 case BFD_RELOC_PPC_EMB_NADDR16_HA
: r
= R_PPC_EMB_NADDR16_HA
; break;
1996 case BFD_RELOC_PPC_EMB_SDAI16
: r
= R_PPC_EMB_SDAI16
; break;
1997 case BFD_RELOC_PPC_EMB_SDA2I16
: r
= R_PPC_EMB_SDA2I16
; break;
1998 case BFD_RELOC_PPC_EMB_SDA2REL
: r
= R_PPC_EMB_SDA2REL
; break;
1999 case BFD_RELOC_PPC_EMB_SDA21
: r
= R_PPC_EMB_SDA21
; break;
2000 case BFD_RELOC_PPC_EMB_MRKREF
: r
= R_PPC_EMB_MRKREF
; break;
2001 case BFD_RELOC_PPC_EMB_RELSEC16
: r
= R_PPC_EMB_RELSEC16
; break;
2002 case BFD_RELOC_PPC_EMB_RELST_LO
: r
= R_PPC_EMB_RELST_LO
; break;
2003 case BFD_RELOC_PPC_EMB_RELST_HI
: r
= R_PPC_EMB_RELST_HI
; break;
2004 case BFD_RELOC_PPC_EMB_RELST_HA
: r
= R_PPC_EMB_RELST_HA
; break;
2005 case BFD_RELOC_PPC_EMB_BIT_FLD
: r
= R_PPC_EMB_BIT_FLD
; break;
2006 case BFD_RELOC_PPC_EMB_RELSDA
: r
= R_PPC_EMB_RELSDA
; break;
2007 case BFD_RELOC_VTABLE_INHERIT
: r
= R_PPC_GNU_VTINHERIT
; break;
2008 case BFD_RELOC_VTABLE_ENTRY
: r
= R_PPC_GNU_VTENTRY
; break;
2011 return ppc_elf_howto_table
[(int) r
];
2014 /* Set the howto pointer for a PowerPC ELF reloc. */
2017 ppc_elf_info_to_howto (abfd
, cache_ptr
, dst
)
2018 bfd
*abfd ATTRIBUTE_UNUSED
;
2020 Elf_Internal_Rela
*dst
;
2022 if (!ppc_elf_howto_table
[R_PPC_ADDR32
])
2023 /* Initialize howto table if needed. */
2024 ppc_elf_howto_init ();
2026 BFD_ASSERT (ELF32_R_TYPE (dst
->r_info
) < (unsigned int) R_PPC_max
);
2027 cache_ptr
->howto
= ppc_elf_howto_table
[ELF32_R_TYPE (dst
->r_info
)];
2030 /* Handle the R_PPC_ADDR16_HA reloc. */
2032 static bfd_reloc_status_type
2033 ppc_elf_addr16_ha_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
2034 output_bfd
, error_message
)
2035 bfd
*abfd ATTRIBUTE_UNUSED
;
2036 arelent
*reloc_entry
;
2038 PTR data ATTRIBUTE_UNUSED
;
2039 asection
*input_section
;
2041 char **error_message ATTRIBUTE_UNUSED
;
2045 if (output_bfd
!= NULL
)
2047 reloc_entry
->address
+= input_section
->output_offset
;
2048 return bfd_reloc_ok
;
2051 if (reloc_entry
->address
> input_section
->_cooked_size
)
2052 return bfd_reloc_outofrange
;
2054 if (bfd_is_com_section (symbol
->section
))
2057 relocation
= symbol
->value
;
2059 relocation
+= symbol
->section
->output_section
->vma
;
2060 relocation
+= symbol
->section
->output_offset
;
2061 relocation
+= reloc_entry
->addend
;
2063 reloc_entry
->addend
+= (relocation
& 0x8000) << 1;
2065 return bfd_reloc_continue
;
2068 static bfd_reloc_status_type
2069 ppc_elf_unhandled_reloc (abfd
, reloc_entry
, symbol
, data
,
2070 input_section
, output_bfd
, error_message
)
2072 arelent
*reloc_entry
;
2075 asection
*input_section
;
2077 char **error_message
;
2079 /* If this is a relocatable link (output_bfd test tells us), just
2080 call the generic function. Any adjustment will be done at final
2082 if (output_bfd
!= NULL
)
2083 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2084 input_section
, output_bfd
, error_message
);
2086 if (error_message
!= NULL
)
2088 static char buf
[60];
2089 sprintf (buf
, "generic linker can't handle %s",
2090 reloc_entry
->howto
->name
);
2091 *error_message
= buf
;
2093 return bfd_reloc_dangerous
;
2096 /* Fix bad default arch selected for a 32 bit input bfd when the
2097 default is 64 bit. */
2100 ppc_elf_object_p (abfd
)
2103 if (abfd
->arch_info
->the_default
&& abfd
->arch_info
->bits_per_word
== 64)
2105 Elf_Internal_Ehdr
*i_ehdr
= elf_elfheader (abfd
);
2107 if (i_ehdr
->e_ident
[EI_CLASS
] == ELFCLASS32
)
2109 /* Relies on arch after 64 bit default being 32 bit default. */
2110 abfd
->arch_info
= abfd
->arch_info
->next
;
2111 BFD_ASSERT (abfd
->arch_info
->bits_per_word
== 32);
2117 /* Function to set whether a module needs the -mrelocatable bit set. */
2120 ppc_elf_set_private_flags (abfd
, flags
)
2124 BFD_ASSERT (!elf_flags_init (abfd
)
2125 || elf_elfheader (abfd
)->e_flags
== flags
);
2127 elf_elfheader (abfd
)->e_flags
= flags
;
2128 elf_flags_init (abfd
) = TRUE
;
2132 /* Merge backend specific data from an object file to the output
2133 object file when linking. */
2136 ppc_elf_merge_private_bfd_data (ibfd
, obfd
)
2144 /* Check if we have the same endianess. */
2145 if (! _bfd_generic_verify_endian_match (ibfd
, obfd
))
2148 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
2149 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
2152 new_flags
= elf_elfheader (ibfd
)->e_flags
;
2153 old_flags
= elf_elfheader (obfd
)->e_flags
;
2154 if (!elf_flags_init (obfd
))
2156 /* First call, no flags set. */
2157 elf_flags_init (obfd
) = TRUE
;
2158 elf_elfheader (obfd
)->e_flags
= new_flags
;
2161 /* Compatible flags are ok. */
2162 else if (new_flags
== old_flags
)
2165 /* Incompatible flags. */
2168 /* Warn about -mrelocatable mismatch. Allow -mrelocatable-lib
2169 to be linked with either. */
2171 if ((new_flags
& EF_PPC_RELOCATABLE
) != 0
2172 && (old_flags
& (EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
)) == 0)
2175 (*_bfd_error_handler
)
2176 (_("%s: compiled with -mrelocatable and linked with modules compiled normally"),
2177 bfd_archive_filename (ibfd
));
2179 else if ((new_flags
& (EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
)) == 0
2180 && (old_flags
& EF_PPC_RELOCATABLE
) != 0)
2183 (*_bfd_error_handler
)
2184 (_("%s: compiled normally and linked with modules compiled with -mrelocatable"),
2185 bfd_archive_filename (ibfd
));
2188 /* The output is -mrelocatable-lib iff both the input files are. */
2189 if (! (new_flags
& EF_PPC_RELOCATABLE_LIB
))
2190 elf_elfheader (obfd
)->e_flags
&= ~EF_PPC_RELOCATABLE_LIB
;
2192 /* The output is -mrelocatable iff it can't be -mrelocatable-lib,
2193 but each input file is either -mrelocatable or -mrelocatable-lib. */
2194 if (! (elf_elfheader (obfd
)->e_flags
& EF_PPC_RELOCATABLE_LIB
)
2195 && (new_flags
& (EF_PPC_RELOCATABLE_LIB
| EF_PPC_RELOCATABLE
))
2196 && (old_flags
& (EF_PPC_RELOCATABLE_LIB
| EF_PPC_RELOCATABLE
)))
2197 elf_elfheader (obfd
)->e_flags
|= EF_PPC_RELOCATABLE
;
2199 /* Do not warn about eabi vs. V.4 mismatch, just or in the bit if
2200 any module uses it. */
2201 elf_elfheader (obfd
)->e_flags
|= (new_flags
& EF_PPC_EMB
);
2203 new_flags
&= ~(EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
| EF_PPC_EMB
);
2204 old_flags
&= ~(EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
| EF_PPC_EMB
);
2206 /* Warn about any other mismatches. */
2207 if (new_flags
!= old_flags
)
2210 (*_bfd_error_handler
)
2211 (_("%s: uses different e_flags (0x%lx) fields than previous modules (0x%lx)"),
2212 bfd_archive_filename (ibfd
), (long) new_flags
, (long) old_flags
);
2217 bfd_set_error (bfd_error_bad_value
);
2225 /* Handle a PowerPC specific section when reading an object file. This
2226 is called when elfcode.h finds a section with an unknown type. */
2229 ppc_elf_section_from_shdr (abfd
, hdr
, name
)
2231 Elf_Internal_Shdr
*hdr
;
2237 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
))
2240 newsect
= hdr
->bfd_section
;
2241 flags
= bfd_get_section_flags (abfd
, newsect
);
2242 if (hdr
->sh_flags
& SHF_EXCLUDE
)
2243 flags
|= SEC_EXCLUDE
;
2245 if (hdr
->sh_type
== SHT_ORDERED
)
2246 flags
|= SEC_SORT_ENTRIES
;
2248 bfd_set_section_flags (abfd
, newsect
, flags
);
2252 /* Set up any other section flags and such that may be necessary. */
2255 ppc_elf_fake_sections (abfd
, shdr
, asect
)
2256 bfd
*abfd ATTRIBUTE_UNUSED
;
2257 Elf_Internal_Shdr
*shdr
;
2260 if ((asect
->flags
& SEC_EXCLUDE
) != 0)
2261 shdr
->sh_flags
|= SHF_EXCLUDE
;
2263 if ((asect
->flags
& SEC_SORT_ENTRIES
) != 0)
2264 shdr
->sh_type
= SHT_ORDERED
;
2269 /* Create a special linker section */
2270 static elf_linker_section_t
*
2271 ppc_elf_create_linker_section (abfd
, info
, which
)
2273 struct bfd_link_info
*info
;
2274 enum elf_linker_section_enum which
;
2276 bfd
*dynobj
= elf_hash_table (info
)->dynobj
;
2277 elf_linker_section_t
*lsect
;
2279 /* Record the first bfd section that needs the special section. */
2281 dynobj
= elf_hash_table (info
)->dynobj
= abfd
;
2283 /* If this is the first time, create the section. */
2284 lsect
= elf_linker_section (dynobj
, which
);
2287 elf_linker_section_t defaults
;
2288 static elf_linker_section_t zero_section
;
2290 defaults
= zero_section
;
2291 defaults
.which
= which
;
2292 defaults
.hole_written_p
= FALSE
;
2293 defaults
.alignment
= 2;
2295 /* Both of these sections are (technically) created by the user
2296 putting data in them, so they shouldn't be marked
2299 The linker creates them so it has somewhere to attach their
2300 respective symbols. In fact, if they were empty it would
2301 be OK to leave the symbol set to 0 (or any random number), because
2302 the appropriate register should never be used. */
2303 defaults
.flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
2309 (*_bfd_error_handler
) (_("%s: unknown special linker type %d"),
2310 bfd_get_filename (abfd
),
2313 bfd_set_error (bfd_error_bad_value
);
2314 return (elf_linker_section_t
*) 0;
2316 case LINKER_SECTION_SDATA
: /* .sdata/.sbss section */
2317 defaults
.name
= ".sdata";
2318 defaults
.rel_name
= ".rela.sdata";
2319 defaults
.bss_name
= ".sbss";
2320 defaults
.sym_name
= "_SDA_BASE_";
2321 defaults
.sym_offset
= 32768;
2324 case LINKER_SECTION_SDATA2
: /* .sdata2/.sbss2 section */
2325 defaults
.name
= ".sdata2";
2326 defaults
.rel_name
= ".rela.sdata2";
2327 defaults
.bss_name
= ".sbss2";
2328 defaults
.sym_name
= "_SDA2_BASE_";
2329 defaults
.sym_offset
= 32768;
2330 defaults
.flags
|= SEC_READONLY
;
2334 lsect
= _bfd_elf_create_linker_section (abfd
, info
, which
, &defaults
);
2340 /* If we have a non-zero sized .sbss2 or .PPC.EMB.sbss0 sections, we
2341 need to bump up the number of section headers. */
2344 ppc_elf_additional_program_headers (abfd
)
2352 s
= bfd_get_section_by_name (abfd
, ".interp");
2356 s
= bfd_get_section_by_name (abfd
, ".sbss2");
2357 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0 && s
->_raw_size
> 0)
2360 s
= bfd_get_section_by_name (abfd
, ".PPC.EMB.sbss0");
2361 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0 && s
->_raw_size
> 0)
2367 /* Modify the segment map if needed. */
2370 ppc_elf_modify_segment_map (abfd
)
2371 bfd
*abfd ATTRIBUTE_UNUSED
;
2376 /* The powerpc .got has a blrl instruction in it. Mark it executable. */
2379 ppc_elf_create_got (abfd
, info
)
2381 struct bfd_link_info
*info
;
2383 struct ppc_elf_link_hash_table
*htab
;
2387 if (!_bfd_elf_create_got_section (abfd
, info
))
2390 htab
= ppc_elf_hash_table (info
);
2391 htab
->got
= s
= bfd_get_section_by_name (abfd
, ".got");
2395 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_CODE
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
2396 | SEC_LINKER_CREATED
);
2397 if (!bfd_set_section_flags (abfd
, s
, flags
))
2400 htab
->relgot
= bfd_make_section (abfd
, ".rela.got");
2402 || ! bfd_set_section_flags (abfd
, htab
->relgot
,
2403 (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
2404 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
2406 || ! bfd_set_section_alignment (abfd
, htab
->relgot
, 2))
2412 /* We have to create .dynsbss and .rela.sbss here so that they get mapped
2413 to output sections (just like _bfd_elf_create_dynamic_sections has
2414 to create .dynbss and .rela.bss). */
2417 ppc_elf_create_dynamic_sections (abfd
, info
)
2419 struct bfd_link_info
*info
;
2421 struct ppc_elf_link_hash_table
*htab
;
2425 if (!ppc_elf_create_got (abfd
, info
))
2428 if (!_bfd_elf_create_dynamic_sections (abfd
, info
))
2431 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
2432 | SEC_LINKER_CREATED
);
2434 htab
= ppc_elf_hash_table (info
);
2435 htab
->dynbss
= bfd_get_section_by_name (abfd
, ".dynbss");
2436 htab
->dynsbss
= s
= bfd_make_section (abfd
, ".dynsbss");
2438 || ! bfd_set_section_flags (abfd
, s
, SEC_ALLOC
))
2443 htab
->relbss
= bfd_get_section_by_name (abfd
, ".rela.bss");
2444 htab
->relsbss
= s
= bfd_make_section (abfd
, ".rela.sbss");
2446 || ! bfd_set_section_flags (abfd
, s
, flags
| SEC_READONLY
)
2447 || ! bfd_set_section_alignment (abfd
, s
, 2))
2451 htab
->relplt
= bfd_get_section_by_name (abfd
, ".rela.plt");
2452 htab
->plt
= s
= bfd_get_section_by_name (abfd
, ".plt");
2456 flags
= SEC_ALLOC
| SEC_CODE
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
;
2457 return bfd_set_section_flags (abfd
, s
, flags
);
2460 /* Adjust a symbol defined by a dynamic object and referenced by a
2461 regular object. The current definition is in some section of the
2462 dynamic object, but we're not including those sections. We have to
2463 change the definition to something the rest of the link can
2467 ppc_elf_adjust_dynamic_symbol (info
, h
)
2468 struct bfd_link_info
*info
;
2469 struct elf_link_hash_entry
*h
;
2471 struct ppc_elf_link_hash_table
*htab
;
2473 unsigned int power_of_two
;
2476 fprintf (stderr
, "ppc_elf_adjust_dynamic_symbol called for %s\n",
2477 h
->root
.root
.string
);
2480 /* Make sure we know what is going on here. */
2481 htab
= ppc_elf_hash_table (info
);
2482 BFD_ASSERT (htab
->elf
.dynobj
!= NULL
2483 && ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
)
2484 || h
->weakdef
!= NULL
2485 || ((h
->elf_link_hash_flags
2486 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0
2487 && (h
->elf_link_hash_flags
2488 & ELF_LINK_HASH_REF_REGULAR
) != 0
2489 && (h
->elf_link_hash_flags
2490 & ELF_LINK_HASH_DEF_REGULAR
) == 0)));
2492 /* Deal with function syms. */
2493 if (h
->type
== STT_FUNC
2494 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
2496 /* Clear procedure linkage table information for any symbol that
2497 won't need a .plt entry. */
2498 if (h
->plt
.refcount
<= 0
2499 || SYMBOL_CALLS_LOCAL (info
, h
)
2500 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
2501 && h
->root
.type
== bfd_link_hash_undefweak
))
2503 /* A PLT entry is not required/allowed when:
2505 1. We are not using ld.so; because then the PLT entry
2506 can't be set up, so we can't use one. In this case,
2507 ppc_elf_adjust_dynamic_symbol won't even be called.
2509 2. GC has rendered the entry unused.
2511 3. We know for certain that a call to this symbol
2512 will go to this object, or will remain undefined. */
2513 h
->plt
.offset
= (bfd_vma
) -1;
2514 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
2519 h
->plt
.offset
= (bfd_vma
) -1;
2521 /* If this is a weak symbol, and there is a real definition, the
2522 processor independent code will have arranged for us to see the
2523 real definition first, and we can just use the same value. */
2524 if (h
->weakdef
!= NULL
)
2526 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
2527 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
2528 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
2529 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
2530 if (ELIMINATE_COPY_RELOCS
)
2531 h
->elf_link_hash_flags
2532 = ((h
->elf_link_hash_flags
& ~ELF_LINK_NON_GOT_REF
)
2533 | (h
->weakdef
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
));
2537 /* This is a reference to a symbol defined by a dynamic object which
2538 is not a function. */
2540 /* If we are creating a shared library, we must presume that the
2541 only references to the symbol are via the global offset table.
2542 For such cases we need not do anything here; the relocations will
2543 be handled correctly by relocate_section. */
2547 /* If there are no references to this symbol that do not use the
2548 GOT, we don't need to generate a copy reloc. */
2549 if ((h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0)
2552 if (ELIMINATE_COPY_RELOCS
)
2554 struct ppc_elf_dyn_relocs
*p
;
2555 for (p
= ppc_elf_hash_entry (h
)->dyn_relocs
; p
!= NULL
; p
= p
->next
)
2557 s
= p
->sec
->output_section
;
2558 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
2562 /* If we didn't find any dynamic relocs in read-only sections, then
2563 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
2566 h
->elf_link_hash_flags
&= ~ELF_LINK_NON_GOT_REF
;
2571 /* We must allocate the symbol in our .dynbss section, which will
2572 become part of the .bss section of the executable. There will be
2573 an entry for this symbol in the .dynsym section. The dynamic
2574 object will contain position independent code, so all references
2575 from the dynamic object to this symbol will go through the global
2576 offset table. The dynamic linker will use the .dynsym entry to
2577 determine the address it must put in the global offset table, so
2578 both the dynamic object and the regular object will refer to the
2579 same memory location for the variable.
2581 Of course, if the symbol is sufficiently small, we must instead
2582 allocate it in .sbss. FIXME: It would be better to do this if and
2583 only if there were actually SDAREL relocs for that symbol. */
2585 if (h
->size
<= elf_gp_size (htab
->elf
.dynobj
))
2589 BFD_ASSERT (s
!= NULL
);
2591 /* We must generate a R_PPC_COPY reloc to tell the dynamic linker to
2592 copy the initial value out of the dynamic object and into the
2593 runtime process image. We need to remember the offset into the
2594 .rela.bss section we are going to use. */
2595 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
2599 if (h
->size
<= elf_gp_size (htab
->elf
.dynobj
))
2600 srel
= htab
->relsbss
;
2602 srel
= htab
->relbss
;
2603 BFD_ASSERT (srel
!= NULL
);
2604 srel
->_raw_size
+= sizeof (Elf32_External_Rela
);
2605 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_COPY
;
2608 /* We need to figure out the alignment required for this symbol. I
2609 have no idea how ELF linkers handle this. */
2610 power_of_two
= bfd_log2 (h
->size
);
2611 if (power_of_two
> 4)
2614 /* Apply the required alignment. */
2615 s
->_raw_size
= BFD_ALIGN (s
->_raw_size
,
2616 (bfd_size_type
) (1 << power_of_two
));
2617 if (power_of_two
> bfd_get_section_alignment (htab
->elf
.dynobj
, s
))
2619 if (! bfd_set_section_alignment (htab
->elf
.dynobj
, s
, power_of_two
))
2623 /* Define the symbol as being at this point in the section. */
2624 h
->root
.u
.def
.section
= s
;
2625 h
->root
.u
.def
.value
= s
->_raw_size
;
2627 /* Increment the section size to make room for the symbol. */
2628 s
->_raw_size
+= h
->size
;
2633 /* This is the condition under which finish_dynamic_symbol will be
2634 called from elflink.h. If elflink.h doesn't call our
2635 finish_dynamic_symbol routine, we'll need to do something about
2636 initializing any .plt and .got entries in relocate_section. */
2637 #define WILL_CALL_FINISH_DYNAMIC_SYMBOL(DYN, SHARED, H) \
2640 || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) \
2641 && ((H)->dynindx != -1 \
2642 || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0))
2644 /* Of those relocs that might be copied as dynamic relocs, this macro
2645 selects those that must be copied when linking a shared library,
2646 even when the symbol is local. */
2648 #define MUST_BE_DYN_RELOC(RTYPE) \
2649 ((RTYPE) != R_PPC_REL24 \
2650 && (RTYPE) != R_PPC_REL14 \
2651 && (RTYPE) != R_PPC_REL14_BRTAKEN \
2652 && (RTYPE) != R_PPC_REL14_BRNTAKEN \
2653 && (RTYPE) != R_PPC_REL32)
2655 /* Allocate space in associated reloc sections for dynamic relocs. */
2658 allocate_dynrelocs (h
, inf
)
2659 struct elf_link_hash_entry
*h
;
2662 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
2663 struct ppc_elf_link_hash_entry
*eh
;
2664 struct ppc_elf_link_hash_table
*htab
;
2665 struct ppc_elf_dyn_relocs
*p
;
2667 if (h
->root
.type
== bfd_link_hash_indirect
)
2670 if (h
->root
.type
== bfd_link_hash_warning
)
2671 /* When warning symbols are created, they **replace** the "real"
2672 entry in the hash table, thus we never get to see the real
2673 symbol in a hash traversal. So look at it now. */
2674 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2676 htab
= ppc_elf_hash_table (info
);
2677 if (htab
->elf
.dynamic_sections_created
2678 && h
->plt
.refcount
> 0)
2680 /* Make sure this symbol is output as a dynamic symbol. */
2681 if (h
->dynindx
== -1
2682 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
2684 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
2689 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h
))
2691 asection
*s
= htab
->plt
;
2693 /* If this is the first .plt entry, make room for the special
2695 if (s
->_raw_size
== 0)
2696 s
->_raw_size
+= PLT_INITIAL_ENTRY_SIZE
;
2698 /* The PowerPC PLT is actually composed of two parts, the
2699 first part is 2 words (for a load and a jump), and then
2700 there is a remaining word available at the end. */
2701 h
->plt
.offset
= (PLT_INITIAL_ENTRY_SIZE
2703 * ((s
->_raw_size
- PLT_INITIAL_ENTRY_SIZE
)
2704 / PLT_ENTRY_SIZE
)));
2706 /* If this symbol is not defined in a regular file, and we
2707 are not generating a shared library, then set the symbol
2708 to this location in the .plt. This is required to make
2709 function pointers compare as equal between the normal
2710 executable and the shared library. */
2712 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
2714 h
->root
.u
.def
.section
= s
;
2715 h
->root
.u
.def
.value
= h
->plt
.offset
;
2718 /* Make room for this entry. After the 8192nd entry, room
2719 for two entries is allocated. */
2720 s
->_raw_size
+= PLT_ENTRY_SIZE
;
2721 if ((s
->_raw_size
- PLT_INITIAL_ENTRY_SIZE
) / PLT_ENTRY_SIZE
2722 >= PLT_NUM_SINGLE_ENTRIES
)
2723 s
->_raw_size
+= PLT_ENTRY_SIZE
;
2725 /* We also need to make an entry in the .rela.plt section. */
2726 htab
->relplt
->_raw_size
+= sizeof (Elf32_External_Rela
);
2730 h
->plt
.offset
= (bfd_vma
) -1;
2731 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
2736 h
->plt
.offset
= (bfd_vma
) -1;
2737 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
2740 eh
= (struct ppc_elf_link_hash_entry
*) h
;
2741 if (eh
->elf
.got
.refcount
> 0)
2743 /* Make sure this symbol is output as a dynamic symbol. */
2744 if (eh
->elf
.dynindx
== -1
2745 && (eh
->elf
.elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
2747 if (!bfd_elf32_link_record_dynamic_symbol (info
, &eh
->elf
))
2751 if (eh
->tls_mask
== (TLS_TLS
| TLS_LD
)
2752 && !(eh
->elf
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
))
2753 /* If just an LD reloc, we'll just use htab->tlsld_got.offset. */
2754 eh
->elf
.got
.offset
= (bfd_vma
) -1;
2758 eh
->elf
.got
.offset
= htab
->got
->_raw_size
;
2759 if ((eh
->tls_mask
& TLS_TLS
) != 0)
2761 if ((eh
->tls_mask
& TLS_LD
) != 0)
2762 htab
->got
->_raw_size
+= 8;
2763 if ((eh
->tls_mask
& TLS_GD
) != 0)
2764 htab
->got
->_raw_size
+= 8;
2765 if ((eh
->tls_mask
& (TLS_TPREL
| TLS_TPRELGD
)) != 0)
2766 htab
->got
->_raw_size
+= 4;
2767 if ((eh
->tls_mask
& TLS_DTPREL
) != 0)
2768 htab
->got
->_raw_size
+= 4;
2771 htab
->got
->_raw_size
+= 4;
2772 dyn
= htab
->elf
.dynamic_sections_created
;
2774 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, &eh
->elf
))
2775 && (ELF_ST_VISIBILITY (eh
->elf
.other
) == STV_DEFAULT
2776 || eh
->elf
.root
.type
!= bfd_link_hash_undefweak
))
2778 /* All the entries we allocated need relocs. */
2779 htab
->relgot
->_raw_size
2780 += ((htab
->got
->_raw_size
- eh
->elf
.got
.offset
) / 4
2781 * sizeof (Elf32_External_Rela
));
2782 /* Except LD only needs one. */
2783 if ((eh
->tls_mask
& TLS_LD
) != 0)
2784 htab
->relgot
->_raw_size
-= sizeof (Elf32_External_Rela
);
2789 eh
->elf
.got
.offset
= (bfd_vma
) -1;
2791 if (eh
->dyn_relocs
== NULL
)
2794 /* In the shared -Bsymbolic case, discard space allocated for
2795 dynamic pc-relative relocs against symbols which turn out to be
2796 defined in regular objects. For the normal shared case, discard
2797 space for relocs that have become local due to symbol visibility
2802 /* Relocs that use pc_count are those that appear on a call insn,
2803 or certain REL relocs (see MUST_BE_DYN_RELOC) that can be
2804 generated via assembly. We want calls to protected symbols to
2805 resolve directly to the function rather than going via the plt.
2806 If people want function pointer comparisons to work as expected
2807 then they should avoid writing weird assembly. */
2808 if (SYMBOL_CALLS_LOCAL (info
, h
))
2810 struct ppc_elf_dyn_relocs
**pp
;
2812 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
2814 p
->count
-= p
->pc_count
;
2823 /* Also discard relocs on undefined weak syms with non-default
2825 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
2826 && h
->root
.type
== bfd_link_hash_undefweak
)
2827 eh
->dyn_relocs
= NULL
;
2829 else if (ELIMINATE_COPY_RELOCS
)
2831 /* For the non-shared case, discard space for relocs against
2832 symbols which turn out to need copy relocs or are not
2835 if ((h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0
2836 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
2837 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
2839 /* Make sure this symbol is output as a dynamic symbol.
2840 Undefined weak syms won't yet be marked as dynamic. */
2841 if (h
->dynindx
== -1
2842 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
2844 if (! bfd_elf64_link_record_dynamic_symbol (info
, h
))
2848 /* If that succeeded, we know we'll be keeping all the
2850 if (h
->dynindx
!= -1)
2854 eh
->dyn_relocs
= NULL
;
2859 /* Finally, allocate space. */
2860 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
2862 asection
*sreloc
= elf_section_data (p
->sec
)->sreloc
;
2863 sreloc
->_raw_size
+= p
->count
* sizeof (Elf32_External_Rela
);
2869 /* Find any dynamic relocs that apply to read-only sections. */
2872 readonly_dynrelocs (h
, info
)
2873 struct elf_link_hash_entry
*h
;
2876 struct ppc_elf_dyn_relocs
*p
;
2878 if (h
->root
.type
== bfd_link_hash_indirect
)
2881 if (h
->root
.type
== bfd_link_hash_warning
)
2882 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2884 for (p
= ppc_elf_hash_entry (h
)->dyn_relocs
; p
!= NULL
; p
= p
->next
)
2886 asection
*s
= p
->sec
->output_section
;
2889 && ((s
->flags
& (SEC_READONLY
| SEC_ALLOC
))
2890 == (SEC_READONLY
| SEC_ALLOC
)))
2892 ((struct bfd_link_info
*) info
)->flags
|= DF_TEXTREL
;
2894 /* Not an error, just cut short the traversal. */
2901 /* Set the sizes of the dynamic sections. */
2904 ppc_elf_size_dynamic_sections (output_bfd
, info
)
2905 bfd
*output_bfd ATTRIBUTE_UNUSED
;
2906 struct bfd_link_info
*info
;
2908 struct ppc_elf_link_hash_table
*htab
;
2914 fprintf (stderr
, "ppc_elf_size_dynamic_sections called\n");
2917 htab
= ppc_elf_hash_table (info
);
2918 BFD_ASSERT (htab
->elf
.dynobj
!= NULL
);
2920 if (elf_hash_table (info
)->dynamic_sections_created
)
2922 /* Set the contents of the .interp section to the interpreter. */
2923 if (info
->executable
)
2925 s
= bfd_get_section_by_name (htab
->elf
.dynobj
, ".interp");
2926 BFD_ASSERT (s
!= NULL
);
2927 s
->_raw_size
= sizeof ELF_DYNAMIC_INTERPRETER
;
2928 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
2932 if (htab
->tlsld_got
.refcount
> 0)
2934 htab
->tlsld_got
.offset
= htab
->got
->_raw_size
;
2935 htab
->got
->_raw_size
+= 8;
2937 htab
->relgot
->_raw_size
+= sizeof (Elf32_External_Rela
);
2940 htab
->tlsld_got
.offset
= (bfd_vma
) -1;
2942 /* Set up .got offsets for local syms, and space for local dynamic
2944 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
2946 bfd_signed_vma
*local_got
;
2947 bfd_signed_vma
*end_local_got
;
2949 bfd_size_type locsymcount
;
2950 Elf_Internal_Shdr
*symtab_hdr
;
2953 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
)
2956 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
2958 struct ppc_elf_dyn_relocs
*p
;
2960 for (p
= ((struct ppc_elf_dyn_relocs
*)
2961 elf_section_data (s
)->local_dynrel
);
2965 if (!bfd_is_abs_section (p
->sec
)
2966 && bfd_is_abs_section (p
->sec
->output_section
))
2968 /* Input section has been discarded, either because
2969 it is a copy of a linkonce section or due to
2970 linker script /DISCARD/, so we'll be discarding
2973 else if (p
->count
!= 0)
2975 elf_section_data (p
->sec
)->sreloc
->_raw_size
2976 += p
->count
* sizeof (Elf32_External_Rela
);
2977 if ((p
->sec
->output_section
->flags
2978 & (SEC_READONLY
| SEC_ALLOC
))
2979 == (SEC_READONLY
| SEC_ALLOC
))
2980 info
->flags
|= DF_TEXTREL
;
2985 local_got
= elf_local_got_refcounts (ibfd
);
2989 symtab_hdr
= &elf_tdata (ibfd
)->symtab_hdr
;
2990 locsymcount
= symtab_hdr
->sh_info
;
2991 end_local_got
= local_got
+ locsymcount
;
2992 lgot_masks
= (char *) end_local_got
;
2994 srel
= htab
->relgot
;
2995 for (; local_got
< end_local_got
; ++local_got
, ++lgot_masks
)
2998 if (*lgot_masks
== (TLS_TLS
| TLS_LD
))
3000 /* If just an LD reloc, we'll just use
3001 htab->tlsld_got.offset. */
3002 if (htab
->tlsld_got
.offset
== (bfd_vma
) -1)
3004 htab
->tlsld_got
.offset
= s
->_raw_size
;
3007 srel
->_raw_size
+= sizeof (Elf32_External_Rela
);
3009 *local_got
= (bfd_vma
) -1;
3013 *local_got
= s
->_raw_size
;
3014 if ((*lgot_masks
& TLS_TLS
) != 0)
3016 if ((*lgot_masks
& TLS_GD
) != 0)
3018 if ((*lgot_masks
& (TLS_TPREL
| TLS_TPRELGD
)) != 0)
3020 if ((*lgot_masks
& TLS_DTPREL
) != 0)
3026 srel
->_raw_size
+= ((s
->_raw_size
- *local_got
) / 4
3027 * sizeof (Elf32_External_Rela
));
3031 *local_got
= (bfd_vma
) -1;
3034 /* Allocate space for global sym dynamic relocs. */
3035 elf_link_hash_traverse (elf_hash_table (info
), allocate_dynrelocs
, info
);
3037 /* We've now determined the sizes of the various dynamic sections.
3038 Allocate memory for them. */
3040 for (s
= htab
->elf
.dynobj
->sections
; s
!= NULL
; s
= s
->next
)
3042 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
3047 || (htab
->sdata
!= NULL
&& s
== htab
->sdata
->section
)
3048 || (htab
->sdata2
!= NULL
&& s
== htab
->sdata2
->section
))
3050 /* Strip this section if we don't need it; see the
3053 else if (strncmp (bfd_get_section_name (dynobj
, s
), ".rela", 5) == 0)
3055 if (s
->_raw_size
== 0)
3057 /* If we don't need this section, strip it from the
3058 output file. This is mostly to handle .rela.bss and
3059 .rela.plt. We must create both sections in
3060 create_dynamic_sections, because they must be created
3061 before the linker maps input sections to output
3062 sections. The linker does that before
3063 adjust_dynamic_symbol is called, and it is that
3064 function which decides whether anything needs to go
3065 into these sections. */
3069 /* Remember whether there are any relocation sections. */
3072 /* We use the reloc_count field as a counter if we need
3073 to copy relocs into the output file. */
3079 /* It's not one of our sections, so don't allocate space. */
3083 if (s
->_raw_size
== 0)
3085 _bfd_strip_section_from_output (info
, s
);
3089 /* Allocate memory for the section contents. */
3090 s
->contents
= (bfd_byte
*) bfd_zalloc (htab
->elf
.dynobj
, s
->_raw_size
);
3091 if (s
->contents
== NULL
)
3095 if (htab
->elf
.dynamic_sections_created
)
3097 /* Add some entries to the .dynamic section. We fill in the
3098 values later, in ppc_elf_finish_dynamic_sections, but we
3099 must add the entries now so that we get the correct size for
3100 the .dynamic section. The DT_DEBUG entry is filled in by the
3101 dynamic linker and used by the debugger. */
3102 #define add_dynamic_entry(TAG, VAL) \
3103 bfd_elf32_add_dynamic_entry (info, (bfd_vma) (TAG), (bfd_vma) (VAL))
3105 if (info
->executable
)
3107 if (!add_dynamic_entry (DT_DEBUG
, 0))
3111 if (htab
->plt
!= NULL
&& htab
->plt
->_raw_size
!= 0)
3113 if (!add_dynamic_entry (DT_PLTGOT
, 0)
3114 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
3115 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
3116 || !add_dynamic_entry (DT_JMPREL
, 0))
3122 if (!add_dynamic_entry (DT_RELA
, 0)
3123 || !add_dynamic_entry (DT_RELASZ
, 0)
3124 || !add_dynamic_entry (DT_RELAENT
, sizeof (Elf32_External_Rela
)))
3128 /* If any dynamic relocs apply to a read-only section, then we
3129 need a DT_TEXTREL entry. */
3130 if ((info
->flags
& DF_TEXTREL
) == 0)
3131 elf_link_hash_traverse (elf_hash_table (info
), readonly_dynrelocs
,
3134 if ((info
->flags
& DF_TEXTREL
) != 0)
3136 if (!add_dynamic_entry (DT_TEXTREL
, 0))
3140 #undef add_dynamic_entry
3146 update_local_sym_info (abfd
, symtab_hdr
, r_symndx
, tls_type
)
3148 Elf_Internal_Shdr
*symtab_hdr
;
3149 unsigned long r_symndx
;
3152 bfd_signed_vma
*local_got_refcounts
= elf_local_got_refcounts (abfd
);
3153 char *local_got_tls_masks
;
3155 if (local_got_refcounts
== NULL
)
3157 bfd_size_type size
= symtab_hdr
->sh_info
;
3159 size
*= sizeof (*local_got_refcounts
) + sizeof (*local_got_tls_masks
);
3160 local_got_refcounts
= (bfd_signed_vma
*) bfd_zalloc (abfd
, size
);
3161 if (local_got_refcounts
== NULL
)
3163 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
3166 local_got_refcounts
[r_symndx
] += 1;
3167 local_got_tls_masks
= (char *) (local_got_refcounts
+ symtab_hdr
->sh_info
);
3168 local_got_tls_masks
[r_symndx
] |= tls_type
;
3173 bad_shared_reloc (abfd
, r_type
)
3175 enum elf_ppc_reloc_type r_type
;
3177 (*_bfd_error_handler
)
3178 (_("%s: relocation %s cannot be used when making a shared object"),
3179 bfd_archive_filename (abfd
),
3180 ppc_elf_howto_table
[(int) r_type
]->name
);
3181 bfd_set_error (bfd_error_bad_value
);
3184 /* Look through the relocs for a section during the first phase, and
3185 allocate space in the global offset table or procedure linkage
3189 ppc_elf_check_relocs (abfd
, info
, sec
, relocs
)
3191 struct bfd_link_info
*info
;
3193 const Elf_Internal_Rela
*relocs
;
3195 struct ppc_elf_link_hash_table
*htab
;
3196 Elf_Internal_Shdr
*symtab_hdr
;
3197 struct elf_link_hash_entry
**sym_hashes
;
3198 const Elf_Internal_Rela
*rel
;
3199 const Elf_Internal_Rela
*rel_end
;
3202 if (info
->relocateable
)
3206 fprintf (stderr
, "ppc_elf_check_relocs called for section %s in %s\n",
3207 bfd_get_section_name (abfd
, sec
),
3208 bfd_archive_filename (abfd
));
3211 /* Create the linker generated sections all the time so that the
3212 special symbols are created. */
3214 htab
= ppc_elf_hash_table (info
);
3215 if (htab
->sdata
== NULL
)
3217 htab
->sdata
= elf_linker_section (abfd
, LINKER_SECTION_SDATA
);
3218 if (htab
->sdata
== NULL
)
3219 htab
->sdata
= ppc_elf_create_linker_section (abfd
, info
,
3220 LINKER_SECTION_SDATA
);
3221 if (htab
->sdata
== NULL
)
3225 if (htab
->sdata2
== NULL
)
3227 htab
->sdata2
= elf_linker_section (abfd
, LINKER_SECTION_SDATA2
);
3228 if (htab
->sdata2
== NULL
)
3229 htab
->sdata2
= ppc_elf_create_linker_section (abfd
, info
,
3230 LINKER_SECTION_SDATA2
);
3231 if (htab
->sdata2
== NULL
)
3235 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
3236 sym_hashes
= elf_sym_hashes (abfd
);
3239 rel_end
= relocs
+ sec
->reloc_count
;
3240 for (rel
= relocs
; rel
< rel_end
; rel
++)
3242 unsigned long r_symndx
;
3243 enum elf_ppc_reloc_type r_type
;
3244 struct elf_link_hash_entry
*h
;
3247 r_symndx
= ELF32_R_SYM (rel
->r_info
);
3248 if (r_symndx
< symtab_hdr
->sh_info
)
3251 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
3253 /* If a relocation refers to _GLOBAL_OFFSET_TABLE_, create the .got.
3254 This shows up in particular in an R_PPC_ADDR32 in the eabi
3256 if (h
&& strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
3258 if (htab
->got
== NULL
)
3260 if (htab
->elf
.dynobj
== NULL
)
3261 htab
->elf
.dynobj
= abfd
;
3262 if (!ppc_elf_create_got (htab
->elf
.dynobj
, info
))
3267 r_type
= (enum elf_ppc_reloc_type
) ELF32_R_TYPE (rel
->r_info
);
3270 case R_PPC_GOT_TLSLD16
:
3271 case R_PPC_GOT_TLSLD16_LO
:
3272 case R_PPC_GOT_TLSLD16_HI
:
3273 case R_PPC_GOT_TLSLD16_HA
:
3274 htab
->tlsld_got
.refcount
+= 1;
3275 tls_type
= TLS_TLS
| TLS_LD
;
3278 case R_PPC_GOT_TLSGD16
:
3279 case R_PPC_GOT_TLSGD16_LO
:
3280 case R_PPC_GOT_TLSGD16_HI
:
3281 case R_PPC_GOT_TLSGD16_HA
:
3282 tls_type
= TLS_TLS
| TLS_GD
;
3285 case R_PPC_GOT_TPREL16
:
3286 case R_PPC_GOT_TPREL16_LO
:
3287 case R_PPC_GOT_TPREL16_HI
:
3288 case R_PPC_GOT_TPREL16_HA
:
3290 info
->flags
|= DF_STATIC_TLS
;
3291 tls_type
= TLS_TLS
| TLS_TPREL
;
3294 case R_PPC_GOT_DTPREL16
:
3295 case R_PPC_GOT_DTPREL16_LO
:
3296 case R_PPC_GOT_DTPREL16_HI
:
3297 case R_PPC_GOT_DTPREL16_HA
:
3298 tls_type
= TLS_TLS
| TLS_DTPREL
;
3300 sec
->has_tls_reloc
= 1;
3303 /* GOT16 relocations */
3305 case R_PPC_GOT16_LO
:
3306 case R_PPC_GOT16_HI
:
3307 case R_PPC_GOT16_HA
:
3308 /* This symbol requires a global offset table entry. */
3309 if (htab
->got
== NULL
)
3311 if (htab
->elf
.dynobj
== NULL
)
3312 htab
->elf
.dynobj
= abfd
;
3313 if (!ppc_elf_create_got (htab
->elf
.dynobj
, info
))
3318 h
->got
.refcount
+= 1;
3319 ppc_elf_hash_entry (h
)->tls_mask
|= tls_type
;
3322 /* This is a global offset table entry for a local symbol. */
3323 if (!update_local_sym_info (abfd
, symtab_hdr
, r_symndx
, tls_type
))
3327 /* Indirect .sdata relocation. */
3328 case R_PPC_EMB_SDAI16
:
3331 bad_shared_reloc (abfd
, r_type
);
3334 if (!bfd_elf32_create_pointer_linker_section (abfd
, info
,
3335 htab
->sdata
, h
, rel
))
3339 /* Indirect .sdata2 relocation. */
3340 case R_PPC_EMB_SDA2I16
:
3343 bad_shared_reloc (abfd
, r_type
);
3346 if (!bfd_elf32_create_pointer_linker_section (abfd
, info
,
3347 htab
->sdata2
, h
, rel
))
3351 case R_PPC_SDAREL16
:
3352 case R_PPC_EMB_SDA2REL
:
3353 case R_PPC_EMB_SDA21
:
3354 case R_PPC_EMB_RELSDA
:
3355 case R_PPC_EMB_NADDR32
:
3356 case R_PPC_EMB_NADDR16
:
3357 case R_PPC_EMB_NADDR16_LO
:
3358 case R_PPC_EMB_NADDR16_HI
:
3359 case R_PPC_EMB_NADDR16_HA
:
3362 bad_shared_reloc (abfd
, r_type
);
3368 case R_PPC_PLTREL24
:
3369 case R_PPC_PLTREL32
:
3370 case R_PPC_PLT16_LO
:
3371 case R_PPC_PLT16_HI
:
3372 case R_PPC_PLT16_HA
:
3374 fprintf (stderr
, "Reloc requires a PLT entry\n");
3376 /* This symbol requires a procedure linkage table entry. We
3377 actually build the entry in finish_dynamic_symbol,
3378 because this might be a case of linking PIC code without
3379 linking in any dynamic objects, in which case we don't
3380 need to generate a procedure linkage table after all. */
3384 /* It does not make sense to have a procedure linkage
3385 table entry for a local symbol. */
3386 bfd_set_error (bfd_error_bad_value
);
3390 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
3394 /* The following relocations don't need to propagate the
3395 relocation if linking a shared object since they are
3396 section relative. */
3398 case R_PPC_SECTOFF_LO
:
3399 case R_PPC_SECTOFF_HI
:
3400 case R_PPC_SECTOFF_HA
:
3401 case R_PPC_DTPREL16
:
3402 case R_PPC_DTPREL16_LO
:
3403 case R_PPC_DTPREL16_HI
:
3404 case R_PPC_DTPREL16_HA
:
3408 /* This are just markers. */
3410 case R_PPC_EMB_MRKREF
:
3415 /* These should only appear in dynamic objects. */
3417 case R_PPC_GLOB_DAT
:
3418 case R_PPC_JMP_SLOT
:
3419 case R_PPC_RELATIVE
:
3422 /* These aren't handled yet. We'll report an error later. */
3424 case R_PPC_EMB_RELSEC16
:
3425 case R_PPC_EMB_RELST_LO
:
3426 case R_PPC_EMB_RELST_HI
:
3427 case R_PPC_EMB_RELST_HA
:
3428 case R_PPC_EMB_BIT_FLD
:
3431 /* This refers only to functions defined in the shared library. */
3432 case R_PPC_LOCAL24PC
:
3435 /* This relocation describes the C++ object vtable hierarchy.
3436 Reconstruct it for later use during GC. */
3437 case R_PPC_GNU_VTINHERIT
:
3438 if (!_bfd_elf32_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
3442 /* This relocation describes which C++ vtable entries are actually
3443 used. Record for later use during GC. */
3444 case R_PPC_GNU_VTENTRY
:
3445 if (!_bfd_elf32_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
3449 /* We shouldn't really be seeing these. */
3452 info
->flags
|= DF_STATIC_TLS
;
3456 case R_PPC_DTPMOD32
:
3457 case R_PPC_DTPREL32
:
3461 case R_PPC_TPREL16_LO
:
3462 case R_PPC_TPREL16_HI
:
3463 case R_PPC_TPREL16_HA
:
3465 info
->flags
|= DF_STATIC_TLS
;
3468 /* When creating a shared object, we must copy these
3469 relocs into the output file. We create a reloc
3470 section in dynobj and make room for the reloc. */
3473 case R_PPC_REL14_BRTAKEN
:
3474 case R_PPC_REL14_BRNTAKEN
:
3477 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
3484 case R_PPC_ADDR16_LO
:
3485 case R_PPC_ADDR16_HI
:
3486 case R_PPC_ADDR16_HA
:
3488 case R_PPC_ADDR14_BRTAKEN
:
3489 case R_PPC_ADDR14_BRNTAKEN
:
3492 if (h
!= NULL
&& !info
->shared
)
3494 /* We may need a plt entry if the symbol turns out to be
3495 a function defined in a dynamic object. */
3498 /* We may need a copy reloc too. */
3499 h
->elf_link_hash_flags
|= ELF_LINK_NON_GOT_REF
;
3503 /* If we are creating a shared library, and this is a reloc
3504 against a global symbol, or a non PC relative reloc
3505 against a local symbol, then we need to copy the reloc
3506 into the shared library. However, if we are linking with
3507 -Bsymbolic, we do not need to copy a reloc against a
3508 global symbol which is defined in an object we are
3509 including in the link (i.e., DEF_REGULAR is set). At
3510 this point we have not seen all the input files, so it is
3511 possible that DEF_REGULAR is not set now but will be set
3512 later (it is never cleared). In case of a weak definition,
3513 DEF_REGULAR may be cleared later by a strong definition in
3514 a shared library. We account for that possibility below by
3515 storing information in the dyn_relocs field of the hash
3516 table entry. A similar situation occurs when creating
3517 shared libraries and symbol visibility changes render the
3520 If on the other hand, we are creating an executable, we
3521 may need to keep relocations for symbols satisfied by a
3522 dynamic library if we manage to avoid copy relocs for the
3525 && (MUST_BE_DYN_RELOC (r_type
)
3527 && (! info
->symbolic
3528 || h
->root
.type
== bfd_link_hash_defweak
3529 || (h
->elf_link_hash_flags
3530 & ELF_LINK_HASH_DEF_REGULAR
) == 0))))
3531 || (ELIMINATE_COPY_RELOCS
3533 && (sec
->flags
& SEC_ALLOC
) != 0
3535 && (h
->root
.type
== bfd_link_hash_defweak
3536 || (h
->elf_link_hash_flags
3537 & ELF_LINK_HASH_DEF_REGULAR
) == 0)))
3539 struct ppc_elf_dyn_relocs
*p
;
3540 struct ppc_elf_dyn_relocs
**head
;
3543 fprintf (stderr
, "ppc_elf_check_relocs need to create relocation for %s\n",
3544 (h
&& h
->root
.root
.string
3545 ? h
->root
.root
.string
: "<unknown>"));
3551 name
= (bfd_elf_string_from_elf_section
3553 elf_elfheader (abfd
)->e_shstrndx
,
3554 elf_section_data (sec
)->rel_hdr
.sh_name
));
3558 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
3559 && strcmp (bfd_get_section_name (abfd
, sec
),
3562 sreloc
= bfd_get_section_by_name (htab
->elf
.dynobj
, name
);
3567 sreloc
= bfd_make_section (htab
->elf
.dynobj
, name
);
3568 flags
= (SEC_HAS_CONTENTS
| SEC_READONLY
3569 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
3570 if ((sec
->flags
& SEC_ALLOC
) != 0)
3571 flags
|= SEC_ALLOC
| SEC_LOAD
;
3573 || ! bfd_set_section_flags (htab
->elf
.dynobj
,
3575 || ! bfd_set_section_alignment (htab
->elf
.dynobj
,
3579 elf_section_data (sec
)->sreloc
= sreloc
;
3582 /* If this is a global symbol, we count the number of
3583 relocations we need for this symbol. */
3586 head
= &ppc_elf_hash_entry (h
)->dyn_relocs
;
3590 /* Track dynamic relocs needed for local syms too.
3591 We really need local syms available to do this
3595 s
= bfd_section_from_r_symndx (abfd
, &htab
->sym_sec
,
3600 head
= ((struct ppc_elf_dyn_relocs
**)
3601 &elf_section_data (s
)->local_dynrel
);
3605 if (p
== NULL
|| p
->sec
!= sec
)
3607 p
= ((struct ppc_elf_dyn_relocs
*)
3608 bfd_alloc (htab
->elf
.dynobj
, sizeof *p
));
3619 if (!MUST_BE_DYN_RELOC (r_type
))
3630 /* Return the section that should be marked against GC for a given
3634 ppc_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
)
3636 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
3637 Elf_Internal_Rela
*rel
;
3638 struct elf_link_hash_entry
*h
;
3639 Elf_Internal_Sym
*sym
;
3643 switch (ELF32_R_TYPE (rel
->r_info
))
3645 case R_PPC_GNU_VTINHERIT
:
3646 case R_PPC_GNU_VTENTRY
:
3650 switch (h
->root
.type
)
3652 case bfd_link_hash_defined
:
3653 case bfd_link_hash_defweak
:
3654 return h
->root
.u
.def
.section
;
3656 case bfd_link_hash_common
:
3657 return h
->root
.u
.c
.p
->section
;
3665 return bfd_section_from_elf_index (sec
->owner
, sym
->st_shndx
);
3670 /* Update the got, plt and dynamic reloc reference counts for the
3671 section being removed. */
3674 ppc_elf_gc_sweep_hook (abfd
, info
, sec
, relocs
)
3676 struct bfd_link_info
*info
;
3678 const Elf_Internal_Rela
*relocs
;
3680 struct ppc_elf_link_hash_table
*htab
;
3681 Elf_Internal_Shdr
*symtab_hdr
;
3682 struct elf_link_hash_entry
**sym_hashes
;
3683 bfd_signed_vma
*local_got_refcounts
;
3684 const Elf_Internal_Rela
*rel
, *relend
;
3686 elf_section_data (sec
)->local_dynrel
= NULL
;
3688 htab
= ppc_elf_hash_table (info
);
3689 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
3690 sym_hashes
= elf_sym_hashes (abfd
);
3691 local_got_refcounts
= elf_local_got_refcounts (abfd
);
3693 relend
= relocs
+ sec
->reloc_count
;
3694 for (rel
= relocs
; rel
< relend
; rel
++)
3696 unsigned long r_symndx
;
3697 enum elf_ppc_reloc_type r_type
;
3698 struct elf_link_hash_entry
*h
= NULL
;
3700 r_symndx
= ELF32_R_SYM (rel
->r_info
);
3701 if (r_symndx
>= symtab_hdr
->sh_info
)
3703 struct ppc_elf_dyn_relocs
**pp
, *p
;
3704 struct ppc_elf_link_hash_entry
*eh
;
3706 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
3707 eh
= (struct ppc_elf_link_hash_entry
*) h
;
3709 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; pp
= &p
->next
)
3712 /* Everything must go for SEC. */
3718 r_type
= (enum elf_ppc_reloc_type
) ELF32_R_TYPE (rel
->r_info
);
3721 case R_PPC_GOT_TLSLD16
:
3722 case R_PPC_GOT_TLSLD16_LO
:
3723 case R_PPC_GOT_TLSLD16_HI
:
3724 case R_PPC_GOT_TLSLD16_HA
:
3725 htab
->tlsld_got
.refcount
-= 1;
3728 case R_PPC_GOT_TLSGD16
:
3729 case R_PPC_GOT_TLSGD16_LO
:
3730 case R_PPC_GOT_TLSGD16_HI
:
3731 case R_PPC_GOT_TLSGD16_HA
:
3732 case R_PPC_GOT_TPREL16
:
3733 case R_PPC_GOT_TPREL16_LO
:
3734 case R_PPC_GOT_TPREL16_HI
:
3735 case R_PPC_GOT_TPREL16_HA
:
3736 case R_PPC_GOT_DTPREL16
:
3737 case R_PPC_GOT_DTPREL16_LO
:
3738 case R_PPC_GOT_DTPREL16_HI
:
3739 case R_PPC_GOT_DTPREL16_HA
:
3741 case R_PPC_GOT16_LO
:
3742 case R_PPC_GOT16_HI
:
3743 case R_PPC_GOT16_HA
:
3746 if (h
->got
.refcount
> 0)
3749 else if (local_got_refcounts
!= NULL
)
3751 if (local_got_refcounts
[r_symndx
] > 0)
3752 local_got_refcounts
[r_symndx
]--;
3758 case R_PPC_REL14_BRTAKEN
:
3759 case R_PPC_REL14_BRNTAKEN
:
3762 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
3769 case R_PPC_ADDR16_LO
:
3770 case R_PPC_ADDR16_HI
:
3771 case R_PPC_ADDR16_HA
:
3773 case R_PPC_ADDR14_BRTAKEN
:
3774 case R_PPC_ADDR14_BRNTAKEN
:
3778 case R_PPC_PLTREL24
:
3779 case R_PPC_PLT16_LO
:
3780 case R_PPC_PLT16_HI
:
3781 case R_PPC_PLT16_HA
:
3784 if (h
->plt
.refcount
> 0)
3796 /* Set htab->tls_sec and htab->tls_get_addr. */
3799 ppc_elf_tls_setup (obfd
, info
)
3801 struct bfd_link_info
*info
;
3804 struct ppc_elf_link_hash_table
*htab
;
3806 htab
= ppc_elf_hash_table (info
);
3807 htab
->tls_get_addr
= elf_link_hash_lookup (&htab
->elf
, "__tls_get_addr",
3808 FALSE
, FALSE
, TRUE
);
3810 for (tls
= obfd
->sections
; tls
!= NULL
; tls
= tls
->next
)
3811 if ((tls
->flags
& (SEC_THREAD_LOCAL
| SEC_LOAD
))
3812 == (SEC_THREAD_LOCAL
| SEC_LOAD
))
3814 htab
->tls_sec
= tls
;
3819 /* Run through all the TLS relocs looking for optimization
3823 ppc_elf_tls_optimize (obfd
, info
)
3824 bfd
*obfd ATTRIBUTE_UNUSED
;
3825 struct bfd_link_info
*info
;
3829 struct ppc_elf_link_hash_table
*htab
;
3831 if (info
->relocateable
|| info
->shared
)
3834 htab
= ppc_elf_hash_table (info
);
3835 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
3837 Elf_Internal_Sym
*locsyms
= NULL
;
3838 Elf_Internal_Shdr
*symtab_hdr
= &elf_tdata (ibfd
)->symtab_hdr
;
3840 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
3841 if (sec
->has_tls_reloc
&& !bfd_is_abs_section (sec
->output_section
))
3843 Elf_Internal_Rela
*relstart
, *rel
, *relend
;
3844 int expecting_tls_get_addr
;
3846 /* Read the relocations. */
3847 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, (PTR
) NULL
,
3848 (Elf_Internal_Rela
*) NULL
,
3850 if (relstart
== NULL
)
3853 expecting_tls_get_addr
= 0;
3854 relend
= relstart
+ sec
->reloc_count
;
3855 for (rel
= relstart
; rel
< relend
; rel
++)
3857 enum elf_ppc_reloc_type r_type
;
3858 unsigned long r_symndx
;
3859 struct elf_link_hash_entry
*h
= NULL
;
3861 char tls_set
, tls_clear
;
3862 bfd_boolean is_local
;
3864 r_symndx
= ELF32_R_SYM (rel
->r_info
);
3865 if (r_symndx
>= symtab_hdr
->sh_info
)
3867 struct elf_link_hash_entry
**sym_hashes
;
3869 sym_hashes
= elf_sym_hashes (ibfd
);
3870 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
3871 while (h
->root
.type
== bfd_link_hash_indirect
3872 || h
->root
.type
== bfd_link_hash_warning
)
3873 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
3878 || !(h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
))
3881 r_type
= (enum elf_ppc_reloc_type
) ELF32_R_TYPE (rel
->r_info
);
3884 case R_PPC_GOT_TLSLD16
:
3885 case R_PPC_GOT_TLSLD16_LO
:
3886 case R_PPC_GOT_TLSLD16_HI
:
3887 case R_PPC_GOT_TLSLD16_HA
:
3888 /* These relocs should never be against a symbol
3889 defined in a shared lib. Leave them alone if
3890 that turns out to be the case. */
3891 expecting_tls_get_addr
= 0;
3892 htab
->tlsld_got
.refcount
-= 1;
3899 expecting_tls_get_addr
= 1;
3902 case R_PPC_GOT_TLSGD16
:
3903 case R_PPC_GOT_TLSGD16_LO
:
3904 case R_PPC_GOT_TLSGD16_HI
:
3905 case R_PPC_GOT_TLSGD16_HA
:
3911 tls_set
= TLS_TLS
| TLS_TPRELGD
;
3913 expecting_tls_get_addr
= 1;
3916 case R_PPC_GOT_TPREL16
:
3917 case R_PPC_GOT_TPREL16_LO
:
3918 case R_PPC_GOT_TPREL16_HI
:
3919 case R_PPC_GOT_TPREL16_HA
:
3920 expecting_tls_get_addr
= 0;
3925 tls_clear
= TLS_TPREL
;
3932 case R_PPC_REL14_BRTAKEN
:
3933 case R_PPC_REL14_BRNTAKEN
:
3935 if (expecting_tls_get_addr
3937 && h
== htab
->tls_get_addr
)
3939 if (h
->plt
.refcount
> 0)
3940 h
->plt
.refcount
-= 1;
3942 expecting_tls_get_addr
= 0;
3946 expecting_tls_get_addr
= 0;
3954 /* We managed to get rid of a got entry. */
3955 if (h
->got
.refcount
> 0)
3956 h
->got
.refcount
-= 1;
3958 tls_mask
= &ppc_elf_hash_entry (h
)->tls_mask
;
3962 Elf_Internal_Sym
*sym
;
3963 bfd_signed_vma
*lgot_refs
;
3966 if (locsyms
== NULL
)
3968 locsyms
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
3969 if (locsyms
== NULL
)
3970 locsyms
= bfd_elf_get_elf_syms (ibfd
, symtab_hdr
,
3971 symtab_hdr
->sh_info
,
3972 0, NULL
, NULL
, NULL
);
3973 if (locsyms
== NULL
)
3975 if (elf_section_data (sec
)->relocs
!= relstart
)
3980 sym
= locsyms
+ r_symndx
;
3981 lgot_refs
= elf_local_got_refcounts (ibfd
);
3982 if (lgot_refs
== NULL
)
3986 /* We managed to get rid of a got entry. */
3987 if (lgot_refs
[r_symndx
] > 0)
3988 lgot_refs
[r_symndx
] -= 1;
3990 lgot_masks
= (char *) (lgot_refs
+ symtab_hdr
->sh_info
);
3991 tls_mask
= &lgot_masks
[r_symndx
];
3994 *tls_mask
|= tls_set
;
3995 *tls_mask
&= ~tls_clear
;
3998 if (elf_section_data (sec
)->relocs
!= relstart
)
4003 && (symtab_hdr
->contents
!= (unsigned char *) locsyms
))
4005 if (!info
->keep_memory
)
4008 symtab_hdr
->contents
= (unsigned char *) locsyms
;
4014 /* Hook called by the linker routine which adds symbols from an object
4015 file. We use it to put .comm items in .sbss, and not .bss. */
4018 ppc_elf_add_symbol_hook (abfd
, info
, sym
, namep
, flagsp
, secp
, valp
)
4020 struct bfd_link_info
*info
;
4021 const Elf_Internal_Sym
*sym
;
4022 const char **namep ATTRIBUTE_UNUSED
;
4023 flagword
*flagsp ATTRIBUTE_UNUSED
;
4027 if (sym
->st_shndx
== SHN_COMMON
4028 && !info
->relocateable
4029 && sym
->st_size
<= elf_gp_size (abfd
)
4030 && info
->hash
->creator
->flavour
== bfd_target_elf_flavour
)
4032 /* Common symbols less than or equal to -G nn bytes are automatically
4034 elf_linker_section_t
*sdata
4035 = ppc_elf_create_linker_section (abfd
, info
, LINKER_SECTION_SDATA
);
4037 if (!sdata
->bss_section
)
4041 /* We don't go through bfd_make_section, because we don't
4042 want to attach this common section to DYNOBJ. The linker
4043 will move the symbols to the appropriate output section
4044 when it defines common symbols. */
4045 amt
= sizeof (asection
);
4046 sdata
->bss_section
= (asection
*) bfd_zalloc (abfd
, amt
);
4047 if (sdata
->bss_section
== NULL
)
4049 sdata
->bss_section
->name
= sdata
->bss_name
;
4050 sdata
->bss_section
->flags
= SEC_IS_COMMON
;
4051 sdata
->bss_section
->output_section
= sdata
->bss_section
;
4052 amt
= sizeof (asymbol
);
4053 sdata
->bss_section
->symbol
= (asymbol
*) bfd_zalloc (abfd
, amt
);
4054 amt
= sizeof (asymbol
*);
4055 sdata
->bss_section
->symbol_ptr_ptr
=
4056 (asymbol
**) bfd_zalloc (abfd
, amt
);
4057 if (sdata
->bss_section
->symbol
== NULL
4058 || sdata
->bss_section
->symbol_ptr_ptr
== NULL
)
4060 sdata
->bss_section
->symbol
->name
= sdata
->bss_name
;
4061 sdata
->bss_section
->symbol
->flags
= BSF_SECTION_SYM
;
4062 sdata
->bss_section
->symbol
->section
= sdata
->bss_section
;
4063 *sdata
->bss_section
->symbol_ptr_ptr
= sdata
->bss_section
->symbol
;
4066 *secp
= sdata
->bss_section
;
4067 *valp
= sym
->st_size
;
4073 /* Finish up dynamic symbol handling. We set the contents of various
4074 dynamic sections here. */
4077 ppc_elf_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
4079 struct bfd_link_info
*info
;
4080 struct elf_link_hash_entry
*h
;
4081 Elf_Internal_Sym
*sym
;
4083 struct ppc_elf_link_hash_table
*htab
;
4086 fprintf (stderr
, "ppc_elf_finish_dynamic_symbol called for %s",
4087 h
->root
.root
.string
);
4090 htab
= ppc_elf_hash_table (info
);
4091 BFD_ASSERT (htab
->elf
.dynobj
!= NULL
);
4093 if (h
->plt
.offset
!= (bfd_vma
) -1)
4095 Elf_Internal_Rela rela
;
4097 bfd_vma reloc_index
;
4100 fprintf (stderr
, ", plt_offset = %d", h
->plt
.offset
);
4103 /* This symbol has an entry in the procedure linkage table. Set
4106 BFD_ASSERT (h
->dynindx
!= -1);
4107 BFD_ASSERT (htab
->plt
!= NULL
&& htab
->relplt
!= NULL
);
4109 /* We don't need to fill in the .plt. The ppc dynamic linker
4112 /* Fill in the entry in the .rela.plt section. */
4113 rela
.r_offset
= (htab
->plt
->output_section
->vma
4114 + htab
->plt
->output_offset
4116 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_PPC_JMP_SLOT
);
4119 reloc_index
= (h
->plt
.offset
- PLT_INITIAL_ENTRY_SIZE
) / PLT_SLOT_SIZE
;
4120 if (reloc_index
> PLT_NUM_SINGLE_ENTRIES
)
4121 reloc_index
-= (reloc_index
- PLT_NUM_SINGLE_ENTRIES
) / 2;
4122 loc
= (htab
->relplt
->contents
4123 + reloc_index
* sizeof (Elf32_External_Rela
));
4124 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
4126 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
4128 /* Mark the symbol as undefined, rather than as defined in
4129 the .plt section. Leave the value alone. */
4130 sym
->st_shndx
= SHN_UNDEF
;
4131 /* If the symbol is weak, we do need to clear the value.
4132 Otherwise, the PLT entry would provide a definition for
4133 the symbol even if the symbol wasn't defined anywhere,
4134 and so the symbol would never be NULL. */
4135 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_REF_REGULAR_NONWEAK
)
4141 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_COPY
) != 0)
4144 Elf_Internal_Rela rela
;
4147 /* This symbols needs a copy reloc. Set it up. */
4150 fprintf (stderr
, ", copy");
4153 BFD_ASSERT (h
->dynindx
!= -1);
4155 if (h
->size
<= elf_gp_size (htab
->elf
.dynobj
))
4159 BFD_ASSERT (s
!= NULL
);
4161 rela
.r_offset
= (h
->root
.u
.def
.value
4162 + h
->root
.u
.def
.section
->output_section
->vma
4163 + h
->root
.u
.def
.section
->output_offset
);
4164 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_PPC_COPY
);
4166 loc
= s
->contents
+ s
->reloc_count
++ * sizeof (Elf32_External_Rela
);
4167 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
4171 fprintf (stderr
, "\n");
4174 /* Mark some specially defined symbols as absolute. */
4175 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
4176 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0
4177 || strcmp (h
->root
.root
.string
, "_PROCEDURE_LINKAGE_TABLE_") == 0)
4178 sym
->st_shndx
= SHN_ABS
;
4183 /* Finish up the dynamic sections. */
4186 ppc_elf_finish_dynamic_sections (output_bfd
, info
)
4188 struct bfd_link_info
*info
;
4191 struct ppc_elf_link_hash_table
*htab
;
4194 fprintf (stderr
, "ppc_elf_finish_dynamic_sections called\n");
4197 htab
= ppc_elf_hash_table (info
);
4198 sdyn
= bfd_get_section_by_name (htab
->elf
.dynobj
, ".dynamic");
4200 if (htab
->elf
.dynamic_sections_created
)
4202 Elf32_External_Dyn
*dyncon
, *dynconend
;
4204 BFD_ASSERT (htab
->plt
!= NULL
&& sdyn
!= NULL
);
4206 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
4207 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
4208 for (; dyncon
< dynconend
; dyncon
++)
4210 Elf_Internal_Dyn dyn
;
4213 bfd_elf32_swap_dyn_in (htab
->elf
.dynobj
, dyncon
, &dyn
);
4219 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
4223 dyn
.d_un
.d_val
= htab
->relplt
->_raw_size
;
4228 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
4235 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
4239 /* Add a blrl instruction at _GLOBAL_OFFSET_TABLE_-4 so that a function can
4240 easily find the address of the _GLOBAL_OFFSET_TABLE_. */
4243 unsigned char *contents
= htab
->got
->contents
;
4244 bfd_put_32 (output_bfd
, (bfd_vma
) 0x4e800021 /* blrl */, contents
);
4247 bfd_put_32 (output_bfd
, (bfd_vma
) 0, contents
+ 4);
4249 bfd_put_32 (output_bfd
,
4250 sdyn
->output_section
->vma
+ sdyn
->output_offset
,
4253 elf_section_data (htab
->got
->output_section
)->this_hdr
.sh_entsize
= 4;
4259 /* The RELOCATE_SECTION function is called by the ELF backend linker
4260 to handle the relocations for a section.
4262 The relocs are always passed as Rela structures; if the section
4263 actually uses Rel structures, the r_addend field will always be
4266 This function is responsible for adjust the section contents as
4267 necessary, and (if using Rela relocs and generating a
4268 relocateable output file) adjusting the reloc addend as
4271 This function does not have to worry about setting the reloc
4272 address or the reloc symbol index.
4274 LOCAL_SYMS is a pointer to the swapped in local symbols.
4276 LOCAL_SECTIONS is an array giving the section in the input file
4277 corresponding to the st_shndx field of each local symbol.
4279 The global hash table entry for the global symbols can be found
4280 via elf_sym_hashes (input_bfd).
4282 When generating relocateable output, this function must handle
4283 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
4284 going to be the section symbol corresponding to the output
4285 section, which means that the addend must be adjusted
4289 ppc_elf_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
4290 contents
, relocs
, local_syms
, local_sections
)
4292 struct bfd_link_info
*info
;
4294 asection
*input_section
;
4296 Elf_Internal_Rela
*relocs
;
4297 Elf_Internal_Sym
*local_syms
;
4298 asection
**local_sections
;
4300 Elf_Internal_Shdr
*symtab_hdr
;
4301 struct elf_link_hash_entry
**sym_hashes
;
4302 struct ppc_elf_link_hash_table
*htab
;
4303 Elf_Internal_Rela
*rel
;
4304 Elf_Internal_Rela
*relend
;
4305 Elf_Internal_Rela outrel
;
4307 asection
*sreloc
= NULL
;
4308 bfd_vma
*local_got_offsets
;
4309 bfd_boolean ret
= TRUE
;
4312 fprintf (stderr
, "ppc_elf_relocate_section called for %s section %s, %ld relocations%s\n",
4313 bfd_archive_filename (input_bfd
),
4314 bfd_section_name(input_bfd
, input_section
),
4315 (long) input_section
->reloc_count
,
4316 (info
->relocateable
) ? " (relocatable)" : "");
4319 if (info
->relocateable
)
4322 if (!ppc_elf_howto_table
[R_PPC_ADDR32
])
4323 /* Initialize howto table if needed. */
4324 ppc_elf_howto_init ();
4326 htab
= ppc_elf_hash_table (info
);
4327 local_got_offsets
= elf_local_got_offsets (input_bfd
);
4328 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
4329 sym_hashes
= elf_sym_hashes (input_bfd
);
4331 relend
= relocs
+ input_section
->reloc_count
;
4332 for (; rel
< relend
; rel
++)
4334 enum elf_ppc_reloc_type r_type
;
4336 bfd_reloc_status_type r
;
4337 Elf_Internal_Sym
*sym
;
4339 struct elf_link_hash_entry
*h
;
4340 const char *sym_name
;
4341 reloc_howto_type
*howto
;
4342 unsigned long r_symndx
;
4344 bfd_vma branch_bit
, insn
, from
;
4345 bfd_boolean unresolved_reloc
;
4347 unsigned int tls_type
, tls_mask
, tls_gd
;
4349 r_type
= (enum elf_ppc_reloc_type
)ELF32_R_TYPE (rel
->r_info
);
4350 sym
= (Elf_Internal_Sym
*) 0;
4351 sec
= (asection
*) 0;
4352 h
= (struct elf_link_hash_entry
*) 0;
4353 unresolved_reloc
= FALSE
;
4355 r_symndx
= ELF32_R_SYM (rel
->r_info
);
4356 if (r_symndx
< symtab_hdr
->sh_info
)
4358 sym
= local_syms
+ r_symndx
;
4359 sec
= local_sections
[r_symndx
];
4360 sym_name
= bfd_elf_local_sym_name (input_bfd
, sym
);
4362 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, sec
, rel
);
4366 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
4367 while (h
->root
.type
== bfd_link_hash_indirect
4368 || h
->root
.type
== bfd_link_hash_warning
)
4369 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
4370 sym_name
= h
->root
.root
.string
;
4373 if (h
->root
.type
== bfd_link_hash_defined
4374 || h
->root
.type
== bfd_link_hash_defweak
)
4376 sec
= h
->root
.u
.def
.section
;
4377 /* Set a flag that will be cleared later if we find a
4378 relocation value for this symbol. output_section
4379 is typically NULL for symbols satisfied by a shared
4381 if (sec
->output_section
== NULL
)
4382 unresolved_reloc
= TRUE
;
4384 relocation
= (h
->root
.u
.def
.value
4385 + sec
->output_section
->vma
4386 + sec
->output_offset
);
4388 else if (h
->root
.type
== bfd_link_hash_undefweak
)
4390 else if (info
->shared
4391 && !info
->no_undefined
4392 && ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
)
4396 if (! ((*info
->callbacks
->undefined_symbol
)
4397 (info
, h
->root
.root
.string
, input_bfd
, input_section
,
4398 rel
->r_offset
, (!info
->shared
4399 || info
->no_undefined
4400 || ELF_ST_VISIBILITY (h
->other
)))))
4406 /* TLS optimizations. Replace instruction sequences and relocs
4407 based on information we collected in tls_optimize. We edit
4408 RELOCS so that --emit-relocs will output something sensible
4409 for the final instruction stream. */
4412 if (IS_PPC_TLS_RELOC (r_type
))
4415 tls_mask
= ((struct ppc_elf_link_hash_entry
*) h
)->tls_mask
;
4416 else if (local_got_offsets
!= NULL
)
4419 lgot_masks
= (char *) (local_got_offsets
+ symtab_hdr
->sh_info
);
4420 tls_mask
= lgot_masks
[r_symndx
];
4424 /* Ensure reloc mapping code below stays sane. */
4425 if ((R_PPC_GOT_TLSLD16
& 3) != (R_PPC_GOT_TLSGD16
& 3)
4426 || (R_PPC_GOT_TLSLD16_LO
& 3) != (R_PPC_GOT_TLSGD16_LO
& 3)
4427 || (R_PPC_GOT_TLSLD16_HI
& 3) != (R_PPC_GOT_TLSGD16_HI
& 3)
4428 || (R_PPC_GOT_TLSLD16_HA
& 3) != (R_PPC_GOT_TLSGD16_HA
& 3)
4429 || (R_PPC_GOT_TLSLD16
& 3) != (R_PPC_GOT_TPREL16
& 3)
4430 || (R_PPC_GOT_TLSLD16_LO
& 3) != (R_PPC_GOT_TPREL16_LO
& 3)
4431 || (R_PPC_GOT_TLSLD16_HI
& 3) != (R_PPC_GOT_TPREL16_HI
& 3)
4432 || (R_PPC_GOT_TLSLD16_HA
& 3) != (R_PPC_GOT_TPREL16_HA
& 3))
4439 case R_PPC_GOT_TPREL16
:
4440 case R_PPC_GOT_TPREL16_LO
:
4442 && (tls_mask
& TLS_TPREL
) == 0)
4445 insn
= bfd_get_32 (output_bfd
, contents
+ rel
->r_offset
- 2);
4447 insn
|= 0x3c020000; /* addis 0,2,0 */
4448 bfd_put_32 (output_bfd
, insn
, contents
+ rel
->r_offset
- 2);
4449 r_type
= R_PPC_TPREL16_HA
;
4450 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
4456 && (tls_mask
& TLS_TPREL
) == 0)
4459 insn
= bfd_get_32 (output_bfd
, contents
+ rel
->r_offset
);
4460 if ((insn
& ((31 << 26) | (31 << 11)))
4461 == ((31 << 26) | (2 << 11)))
4462 rtra
= insn
& ((1 << 26) - (1 << 16));
4463 else if ((insn
& ((31 << 26) | (31 << 16)))
4464 == ((31 << 26) | (2 << 16)))
4465 rtra
= (insn
& (31 << 21)) | ((insn
& (31 << 11)) << 5);
4468 if ((insn
& ((1 << 11) - (1 << 1))) == 266 << 1)
4471 else if ((insn
& (31 << 1)) == 23 << 1
4472 && ((insn
& (31 << 6)) < 14 << 6
4473 || ((insn
& (31 << 6)) >= 16 << 6
4474 && (insn
& (31 << 6)) < 24 << 6)))
4475 /* load and store indexed -> dform. */
4476 insn
= (32 | ((insn
>> 6) & 31)) << 26;
4477 else if ((insn
& (31 << 1)) == 21 << 1
4478 && (insn
& (0x1a << 6)) == 0)
4479 /* ldx, ldux, stdx, stdux -> ld, ldu, std, stdu. */
4480 insn
= (((58 | ((insn
>> 6) & 4)) << 26)
4481 | ((insn
>> 6) & 1));
4482 else if ((insn
& (31 << 1)) == 21 << 1
4483 && (insn
& ((1 << 11) - (1 << 1))) == 341 << 1)
4485 insn
= (58 << 26) | 2;
4489 bfd_put_32 (output_bfd
, insn
, contents
+ rel
->r_offset
);
4490 r_type
= R_PPC_TPREL16_LO
;
4491 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
4492 /* Was PPC_TLS which sits on insn boundary, now
4493 PPC_TPREL16_LO which is at insn+2. */
4498 case R_PPC_GOT_TLSGD16_HI
:
4499 case R_PPC_GOT_TLSGD16_HA
:
4500 tls_gd
= TLS_TPRELGD
;
4501 if (tls_mask
!= 0 && (tls_mask
& TLS_GD
) == 0)
4505 case R_PPC_GOT_TLSLD16_HI
:
4506 case R_PPC_GOT_TLSLD16_HA
:
4507 if (tls_mask
!= 0 && (tls_mask
& TLS_LD
) == 0)
4510 if ((tls_mask
& tls_gd
) != 0)
4511 r_type
= (((r_type
- (R_PPC_GOT_TLSGD16
& 3)) & 3)
4512 + R_PPC_GOT_TPREL16
);
4515 bfd_put_32 (output_bfd
, NOP
, contents
+ rel
->r_offset
);
4517 r_type
= R_PPC_NONE
;
4519 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
4523 case R_PPC_GOT_TLSGD16
:
4524 case R_PPC_GOT_TLSGD16_LO
:
4525 tls_gd
= TLS_TPRELGD
;
4526 if (tls_mask
!= 0 && (tls_mask
& TLS_GD
) == 0)
4527 goto tls_get_addr_check
;
4530 case R_PPC_GOT_TLSLD16
:
4531 case R_PPC_GOT_TLSLD16_LO
:
4532 if (tls_mask
!= 0 && (tls_mask
& TLS_LD
) == 0)
4535 if (rel
+ 1 < relend
)
4537 enum elf_ppc_reloc_type r_type2
;
4538 unsigned long r_symndx2
;
4539 struct elf_link_hash_entry
*h2
;
4540 bfd_vma insn1
, insn2
;
4543 /* The next instruction should be a call to
4544 __tls_get_addr. Peek at the reloc to be sure. */
4546 = (enum elf_ppc_reloc_type
) ELF32_R_TYPE (rel
[1].r_info
);
4547 r_symndx2
= ELF32_R_SYM (rel
[1].r_info
);
4548 if (r_symndx2
< symtab_hdr
->sh_info
4549 || (r_type2
!= R_PPC_REL14
4550 && r_type2
!= R_PPC_REL14_BRTAKEN
4551 && r_type2
!= R_PPC_REL14_BRNTAKEN
4552 && r_type2
!= R_PPC_REL24
4553 && r_type2
!= R_PPC_PLTREL24
))
4556 h2
= sym_hashes
[r_symndx2
- symtab_hdr
->sh_info
];
4557 while (h2
->root
.type
== bfd_link_hash_indirect
4558 || h2
->root
.type
== bfd_link_hash_warning
)
4559 h2
= (struct elf_link_hash_entry
*) h2
->root
.u
.i
.link
;
4560 if (h2
== NULL
|| h2
!= htab
->tls_get_addr
)
4563 /* OK, it checks out. Replace the call. */
4564 offset
= rel
[1].r_offset
;
4565 insn1
= bfd_get_32 (output_bfd
,
4566 contents
+ rel
->r_offset
- 2);
4567 if ((tls_mask
& tls_gd
) != 0)
4570 insn1
&= (1 << 26) - 1;
4571 insn1
|= 32 << 26; /* lwz */
4572 insn2
= 0x7c631214; /* add 3,3,2 */
4573 rel
[1].r_info
= ELF32_R_INFO (r_symndx2
, R_PPC_NONE
);
4574 r_type
= (((r_type
- (R_PPC_GOT_TLSGD16
& 3)) & 3)
4575 + R_PPC_GOT_TPREL16
);
4576 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
4581 insn1
= 0x3c620000; /* addis 3,2,0 */
4582 insn2
= 0x38630000; /* addi 3,3,0 */
4585 /* Was an LD reloc. */
4587 rel
->r_addend
= htab
->tls_sec
->vma
+ DTP_OFFSET
;
4588 rel
[1].r_addend
= htab
->tls_sec
->vma
+ DTP_OFFSET
;
4590 r_type
= R_PPC_TPREL16_HA
;
4591 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
4592 rel
[1].r_info
= ELF32_R_INFO (r_symndx
,
4594 rel
[1].r_offset
+= 2;
4596 bfd_put_32 (output_bfd
, insn1
, contents
+ rel
->r_offset
- 2);
4597 bfd_put_32 (output_bfd
, insn2
, contents
+ offset
);
4600 /* We changed the symbol on an LD reloc. Start over
4601 in order to get h, sym, sec etc. right. */
4610 /* Handle other relocations that tweak non-addend part of insn. */
4617 /* Branch taken prediction relocations. */
4618 case R_PPC_ADDR14_BRTAKEN
:
4619 case R_PPC_REL14_BRTAKEN
:
4620 branch_bit
= BRANCH_PREDICT_BIT
;
4623 /* Branch not taken predicition relocations. */
4624 case R_PPC_ADDR14_BRNTAKEN
:
4625 case R_PPC_REL14_BRNTAKEN
:
4626 insn
= bfd_get_32 (output_bfd
, contents
+ rel
->r_offset
);
4627 insn
&= ~BRANCH_PREDICT_BIT
;
4630 from
= (rel
->r_offset
4631 + input_section
->output_offset
4632 + input_section
->output_section
->vma
);
4634 /* Invert 'y' bit if not the default. */
4635 if ((bfd_signed_vma
) (relocation
+ rel
->r_addend
- from
) < 0)
4636 insn
^= BRANCH_PREDICT_BIT
;
4638 bfd_put_32 (output_bfd
, insn
, contents
+ rel
->r_offset
);
4642 addend
= rel
->r_addend
;
4645 if ((unsigned) r_type
< (unsigned) R_PPC_max
)
4646 howto
= ppc_elf_howto_table
[(int) r_type
];
4650 (*_bfd_error_handler
)
4651 (_("%s: unknown relocation type %d for symbol %s"),
4652 bfd_archive_filename (input_bfd
), (int) r_type
, sym_name
);
4654 bfd_set_error (bfd_error_bad_value
);
4660 case R_PPC_EMB_MRKREF
:
4661 case R_PPC_GNU_VTINHERIT
:
4662 case R_PPC_GNU_VTENTRY
:
4665 /* GOT16 relocations. Like an ADDR16 using the symbol's
4666 address in the GOT as relocation value instead of the
4667 symbol's value itself. Also, create a GOT entry for the
4668 symbol and put the symbol value there. */
4669 case R_PPC_GOT_TLSGD16
:
4670 case R_PPC_GOT_TLSGD16_LO
:
4671 case R_PPC_GOT_TLSGD16_HI
:
4672 case R_PPC_GOT_TLSGD16_HA
:
4673 tls_type
= TLS_TLS
| TLS_GD
;
4676 case R_PPC_GOT_TLSLD16
:
4677 case R_PPC_GOT_TLSLD16_LO
:
4678 case R_PPC_GOT_TLSLD16_HI
:
4679 case R_PPC_GOT_TLSLD16_HA
:
4680 tls_type
= TLS_TLS
| TLS_LD
;
4683 case R_PPC_GOT_TPREL16
:
4684 case R_PPC_GOT_TPREL16_LO
:
4685 case R_PPC_GOT_TPREL16_HI
:
4686 case R_PPC_GOT_TPREL16_HA
:
4687 tls_type
= TLS_TLS
| TLS_TPREL
;
4690 case R_PPC_GOT_DTPREL16
:
4691 case R_PPC_GOT_DTPREL16_LO
:
4692 case R_PPC_GOT_DTPREL16_HI
:
4693 case R_PPC_GOT_DTPREL16_HA
:
4694 tls_type
= TLS_TLS
| TLS_DTPREL
;
4698 case R_PPC_GOT16_LO
:
4699 case R_PPC_GOT16_HI
:
4700 case R_PPC_GOT16_HA
:
4703 /* Relocation is to the entry for this symbol in the global
4709 if (htab
->got
== NULL
)
4713 if (tls_type
== (TLS_TLS
| TLS_LD
)
4715 || !(h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
)))
4716 offp
= &htab
->tlsld_got
.offset
;
4720 dyn
= htab
->elf
.dynamic_sections_created
;
4721 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
4723 && SYMBOL_REFERENCES_LOCAL (info
, h
)))
4724 /* This is actually a static link, or it is a
4725 -Bsymbolic link and the symbol is defined
4726 locally, or the symbol was forced to be local
4727 because of a version file. */
4732 unresolved_reloc
= FALSE
;
4734 offp
= &h
->got
.offset
;
4738 if (local_got_offsets
== NULL
)
4740 offp
= &local_got_offsets
[r_symndx
];
4743 /* The offset must always be a multiple of 4. We use the
4744 least significant bit to record whether we have already
4745 processed this entry. */
4751 unsigned int tls_m
= (tls_mask
4752 & (TLS_LD
| TLS_GD
| TLS_DTPREL
4753 | TLS_TPREL
| TLS_TPRELGD
));
4755 if (offp
== &htab
->tlsld_got
.offset
)
4758 || !(h
->elf_link_hash_flags
4759 & ELF_LINK_HASH_DEF_DYNAMIC
))
4762 /* We might have multiple got entries for this sym.
4763 Initialize them all. */
4768 if ((tls_m
& TLS_LD
) != 0)
4770 tls_ty
= TLS_TLS
| TLS_LD
;
4773 else if ((tls_m
& TLS_GD
) != 0)
4775 tls_ty
= TLS_TLS
| TLS_GD
;
4778 else if ((tls_m
& TLS_DTPREL
) != 0)
4780 tls_ty
= TLS_TLS
| TLS_DTPREL
;
4781 tls_m
&= ~TLS_DTPREL
;
4783 else if ((tls_m
& (TLS_TPREL
| TLS_TPRELGD
)) != 0)
4785 tls_ty
= TLS_TLS
| TLS_TPREL
;
4789 /* Generate relocs for the dynamic linker. */
4790 if ((info
->shared
|| indx
!= 0)
4792 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
4793 || h
->root
.type
!= bfd_link_hash_undefweak
))
4795 outrel
.r_offset
= (htab
->got
->output_section
->vma
4796 + htab
->got
->output_offset
4798 outrel
.r_addend
= 0;
4799 if (tls_ty
& (TLS_LD
| TLS_GD
))
4801 outrel
.r_info
= ELF32_R_INFO (indx
, R_PPC_DTPMOD32
);
4802 if (tls_ty
== (TLS_TLS
| TLS_GD
))
4804 loc
= htab
->relgot
->contents
;
4805 loc
+= (htab
->relgot
->reloc_count
++
4806 * sizeof (Elf32_External_Rela
));
4807 bfd_elf32_swap_reloca_out (output_bfd
,
4809 outrel
.r_offset
+= 4;
4811 = ELF32_R_INFO (indx
, R_PPC_DTPREL32
);
4814 else if (tls_ty
== (TLS_TLS
| TLS_DTPREL
))
4815 outrel
.r_info
= ELF32_R_INFO (indx
, R_PPC_DTPREL32
);
4816 else if (tls_ty
== (TLS_TLS
| TLS_TPREL
))
4817 outrel
.r_info
= ELF32_R_INFO (indx
, R_PPC_TPREL32
);
4819 outrel
.r_info
= ELF32_R_INFO (indx
, R_PPC_RELATIVE
);
4821 outrel
.r_info
= ELF32_R_INFO (indx
, R_PPC_GLOB_DAT
);
4824 outrel
.r_addend
+= relocation
;
4825 if (tls_ty
& (TLS_GD
| TLS_DTPREL
| TLS_TPREL
))
4826 outrel
.r_addend
-= htab
->tls_sec
->vma
;
4828 loc
= htab
->relgot
->contents
;
4829 loc
+= (htab
->relgot
->reloc_count
++
4830 * sizeof (Elf32_External_Rela
));
4831 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
4834 /* Init the .got section contents if we're not
4835 emitting a reloc. */
4838 bfd_vma value
= relocation
;
4840 if (tls_ty
== (TLS_TLS
| TLS_LD
))
4842 else if (tls_ty
!= 0)
4844 value
-= htab
->tls_sec
->vma
+ DTP_OFFSET
;
4845 if (tls_ty
== (TLS_TLS
| TLS_TPREL
))
4846 value
+= DTP_OFFSET
- TP_OFFSET
;
4848 if (tls_ty
== (TLS_TLS
| TLS_GD
))
4850 bfd_put_32 (output_bfd
, value
,
4851 htab
->got
->contents
+ off
+ 4);
4855 bfd_put_32 (output_bfd
, value
,
4856 htab
->got
->contents
+ off
);
4860 if (tls_ty
& (TLS_LD
| TLS_GD
))
4869 if (off
>= (bfd_vma
) -2)
4872 if ((tls_type
& TLS_TLS
) != 0)
4874 if (tls_type
!= (TLS_TLS
| TLS_LD
))
4876 if ((tls_mask
& TLS_LD
) != 0
4878 || !(h
->elf_link_hash_flags
4879 & ELF_LINK_HASH_DEF_DYNAMIC
)))
4881 if (tls_type
!= (TLS_TLS
| TLS_GD
))
4883 if ((tls_mask
& TLS_GD
) != 0)
4885 if (tls_type
!= (TLS_TLS
| TLS_DTPREL
))
4887 if ((tls_mask
& TLS_DTPREL
) != 0)
4894 relocation
= htab
->got
->output_offset
+ off
- 4;
4896 /* Addends on got relocations don't make much sense.
4897 x+off@got is actually x@got+off, and since the got is
4898 generated by a hash table traversal, the value in the
4899 got at entry m+n bears little relation to the entry m. */
4901 (*_bfd_error_handler
)
4902 (_("%s(%s+0x%lx): non-zero addend on %s reloc against `%s'"),
4903 bfd_archive_filename (input_bfd
),
4904 bfd_get_section_name (input_bfd
, input_section
),
4905 (long) rel
->r_offset
,
4911 /* Relocations that need no special processing. */
4912 case R_PPC_LOCAL24PC
:
4913 /* It makes no sense to point a local relocation
4914 at a symbol not in this object. */
4915 if (unresolved_reloc
)
4917 if (! (*info
->callbacks
->undefined_symbol
) (info
,
4918 h
->root
.root
.string
,
4928 case R_PPC_DTPREL16
:
4929 case R_PPC_DTPREL16_LO
:
4930 case R_PPC_DTPREL16_HI
:
4931 case R_PPC_DTPREL16_HA
:
4932 addend
-= htab
->tls_sec
->vma
+ DTP_OFFSET
;
4935 /* Relocations that may need to be propagated if this is a shared
4938 case R_PPC_TPREL16_LO
:
4939 case R_PPC_TPREL16_HI
:
4940 case R_PPC_TPREL16_HA
:
4941 addend
-= htab
->tls_sec
->vma
+ TP_OFFSET
;
4942 /* The TPREL16 relocs shouldn't really be used in shared
4943 libs as they will result in DT_TEXTREL being set, but
4944 support them anyway. */
4948 addend
-= htab
->tls_sec
->vma
+ TP_OFFSET
;
4951 case R_PPC_DTPREL32
:
4952 addend
-= htab
->tls_sec
->vma
+ DTP_OFFSET
;
4955 case R_PPC_DTPMOD32
:
4963 case R_PPC_REL14_BRTAKEN
:
4964 case R_PPC_REL14_BRNTAKEN
:
4965 /* If these relocations are not to a named symbol, they can be
4966 handled right here, no need to bother the dynamic linker. */
4968 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0
4969 || SYMBOL_REFERENCES_LOCAL (info
, h
))
4973 /* Relocations that always need to be propagated if this is a shared
4978 case R_PPC_ADDR16_LO
:
4979 case R_PPC_ADDR16_HI
:
4980 case R_PPC_ADDR16_HA
:
4982 case R_PPC_ADDR14_BRTAKEN
:
4983 case R_PPC_ADDR14_BRNTAKEN
:
4986 /* r_symndx will be zero only for relocs against symbols
4987 from removed linkonce sections, or sections discarded by
4996 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
4997 || h
->root
.type
!= bfd_link_hash_undefweak
)
4998 && (MUST_BE_DYN_RELOC (r_type
)
5000 && !SYMBOL_CALLS_LOCAL (info
, h
))))
5001 || (ELIMINATE_COPY_RELOCS
5003 && (input_section
->flags
& SEC_ALLOC
) != 0
5006 && (h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0
5007 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
5008 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0))
5013 fprintf (stderr
, "ppc_elf_relocate_section need to create relocation for %s\n",
5014 (h
&& h
->root
.root
.string
5015 ? h
->root
.root
.string
: "<unknown>"));
5018 /* When generating a shared object, these relocations
5019 are copied into the output file to be resolved at run
5025 name
= (bfd_elf_string_from_elf_section
5027 elf_elfheader (input_bfd
)->e_shstrndx
,
5028 elf_section_data (input_section
)->rel_hdr
.sh_name
));
5032 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
5033 && strcmp (bfd_get_section_name (input_bfd
,
5037 sreloc
= bfd_get_section_by_name (htab
->elf
.dynobj
, name
);
5038 BFD_ASSERT (sreloc
!= NULL
);
5044 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
5046 if (outrel
.r_offset
== (bfd_vma
) -1
5047 || outrel
.r_offset
== (bfd_vma
) -2)
5048 skip
= (int) outrel
.r_offset
;
5049 outrel
.r_offset
+= (input_section
->output_section
->vma
5050 + input_section
->output_offset
);
5053 memset (&outrel
, 0, sizeof outrel
);
5055 && !SYMBOL_REFERENCES_LOCAL (info
, h
))
5057 unresolved_reloc
= FALSE
;
5058 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
5059 outrel
.r_addend
= rel
->r_addend
;
5063 outrel
.r_addend
= relocation
+ rel
->r_addend
;
5065 if (r_type
== R_PPC_ADDR32
)
5066 outrel
.r_info
= ELF32_R_INFO (0, R_PPC_RELATIVE
);
5071 if (bfd_is_abs_section (sec
))
5073 else if (sec
== NULL
|| sec
->owner
== NULL
)
5075 bfd_set_error (bfd_error_bad_value
);
5082 /* We are turning this relocation into one
5083 against a section symbol. It would be
5084 proper to subtract the symbol's value,
5085 osec->vma, from the emitted reloc addend,
5086 but ld.so expects buggy relocs. */
5087 osec
= sec
->output_section
;
5088 indx
= elf_section_data (osec
)->dynindx
;
5089 BFD_ASSERT (indx
> 0);
5093 printf ("indx=%d section=%s flags=%08x name=%s\n",
5094 indx
, osec
->name
, osec
->flags
,
5095 h
->root
.root
.string
);
5100 outrel
.r_info
= ELF32_R_INFO (indx
, r_type
);
5104 loc
= sreloc
->contents
;
5105 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rela
);
5106 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
5111 /* This reloc will be computed at runtime. We clear the memory
5112 so that it contains predictable value. */
5114 && ((input_section
->flags
& SEC_ALLOC
) != 0
5115 || ELF32_R_TYPE (outrel
.r_info
) != R_PPC_RELATIVE
))
5117 relocation
= howto
->pc_relative
? outrel
.r_offset
: 0;
5124 /* Indirect .sdata relocation. */
5125 case R_PPC_EMB_SDAI16
:
5126 BFD_ASSERT (htab
->sdata
!= NULL
);
5128 = bfd_elf32_finish_pointer_linker_section (output_bfd
, input_bfd
,
5129 info
, htab
->sdata
, h
,
5134 /* Indirect .sdata2 relocation. */
5135 case R_PPC_EMB_SDA2I16
:
5136 BFD_ASSERT (htab
->sdata2
!= NULL
);
5138 = bfd_elf32_finish_pointer_linker_section (output_bfd
, input_bfd
,
5139 info
, htab
->sdata2
, h
,
5144 /* Handle the TOC16 reloc. We want to use the offset within the .got
5145 section, not the actual VMA. This is appropriate when generating
5146 an embedded ELF object, for which the .got section acts like the
5147 AIX .toc section. */
5148 case R_PPC_TOC16
: /* phony GOT16 relocations */
5149 BFD_ASSERT (sec
!= (asection
*) 0);
5150 BFD_ASSERT (bfd_is_und_section (sec
)
5151 || strcmp (bfd_get_section_name (abfd
, sec
), ".got") == 0
5152 || strcmp (bfd_get_section_name (abfd
, sec
), ".cgot") == 0)
5154 addend
-= sec
->output_section
->vma
+ sec
->output_offset
+ 0x8000;
5157 case R_PPC_PLTREL24
:
5158 /* Relocation is to the entry for this symbol in the
5159 procedure linkage table. */
5160 BFD_ASSERT (h
!= NULL
);
5162 if (h
->plt
.offset
== (bfd_vma
) -1
5163 || htab
->plt
== NULL
)
5165 /* We didn't make a PLT entry for this symbol. This
5166 happens when statically linking PIC code, or when
5167 using -Bsymbolic. */
5171 unresolved_reloc
= FALSE
;
5172 relocation
= (htab
->plt
->output_section
->vma
5173 + htab
->plt
->output_offset
5177 /* Relocate against _SDA_BASE_. */
5178 case R_PPC_SDAREL16
:
5181 const struct elf_link_hash_entry
*sh
;
5183 BFD_ASSERT (sec
!= (asection
*) 0);
5184 name
= bfd_get_section_name (abfd
, sec
->output_section
);
5185 if (! ((strncmp (name
, ".sdata", 6) == 0
5186 && (name
[6] == 0 || name
[6] == '.'))
5187 || (strncmp (name
, ".sbss", 5) == 0
5188 && (name
[5] == 0 || name
[5] == '.'))))
5190 (*_bfd_error_handler
) (_("%s: the target (%s) of a %s relocation is in the wrong output section (%s)"),
5191 bfd_archive_filename (input_bfd
),
5196 sh
= htab
->sdata
->sym_hash
;
5197 addend
-= (sh
->root
.u
.def
.value
5198 + sh
->root
.u
.def
.section
->output_section
->vma
5199 + sh
->root
.u
.def
.section
->output_offset
);
5203 /* Relocate against _SDA2_BASE_. */
5204 case R_PPC_EMB_SDA2REL
:
5207 const struct elf_link_hash_entry
*sh
;
5209 BFD_ASSERT (sec
!= (asection
*) 0);
5210 name
= bfd_get_section_name (abfd
, sec
->output_section
);
5211 if (! (strncmp (name
, ".sdata2", 7) == 0
5212 || strncmp (name
, ".sbss2", 6) == 0))
5214 (*_bfd_error_handler
) (_("%s: the target (%s) of a %s relocation is in the wrong output section (%s)"),
5215 bfd_archive_filename (input_bfd
),
5220 bfd_set_error (bfd_error_bad_value
);
5224 sh
= htab
->sdata2
->sym_hash
;
5225 addend
-= (sh
->root
.u
.def
.value
5226 + sh
->root
.u
.def
.section
->output_section
->vma
5227 + sh
->root
.u
.def
.section
->output_offset
);
5231 /* Relocate against either _SDA_BASE_, _SDA2_BASE_, or 0. */
5232 case R_PPC_EMB_SDA21
:
5233 case R_PPC_EMB_RELSDA
:
5236 const struct elf_link_hash_entry
*sh
;
5239 BFD_ASSERT (sec
!= (asection
*) 0);
5240 name
= bfd_get_section_name (abfd
, sec
->output_section
);
5241 if (((strncmp (name
, ".sdata", 6) == 0
5242 && (name
[6] == 0 || name
[6] == '.'))
5243 || (strncmp (name
, ".sbss", 5) == 0
5244 && (name
[5] == 0 || name
[5] == '.'))))
5247 sh
= htab
->sdata
->sym_hash
;
5248 addend
-= (sh
->root
.u
.def
.value
5249 + sh
->root
.u
.def
.section
->output_section
->vma
5250 + sh
->root
.u
.def
.section
->output_offset
);
5253 else if (strncmp (name
, ".sdata2", 7) == 0
5254 || strncmp (name
, ".sbss2", 6) == 0)
5257 sh
= htab
->sdata2
->sym_hash
;
5258 addend
-= (sh
->root
.u
.def
.value
5259 + sh
->root
.u
.def
.section
->output_section
->vma
5260 + sh
->root
.u
.def
.section
->output_offset
);
5263 else if (strcmp (name
, ".PPC.EMB.sdata0") == 0
5264 || strcmp (name
, ".PPC.EMB.sbss0") == 0)
5271 (*_bfd_error_handler
) (_("%s: the target (%s) of a %s relocation is in the wrong output section (%s)"),
5272 bfd_archive_filename (input_bfd
),
5277 bfd_set_error (bfd_error_bad_value
);
5282 if (r_type
== R_PPC_EMB_SDA21
)
5283 { /* fill in register field */
5284 insn
= bfd_get_32 (output_bfd
, contents
+ rel
->r_offset
);
5285 insn
= (insn
& ~RA_REGISTER_MASK
) | (reg
<< RA_REGISTER_SHIFT
);
5286 bfd_put_32 (output_bfd
, insn
, contents
+ rel
->r_offset
);
5291 /* Relocate against the beginning of the section. */
5293 case R_PPC_SECTOFF_LO
:
5294 case R_PPC_SECTOFF_HI
:
5295 case R_PPC_SECTOFF_HA
:
5296 BFD_ASSERT (sec
!= (asection
*) 0);
5297 addend
-= sec
->output_section
->vma
;
5300 /* Negative relocations. */
5301 case R_PPC_EMB_NADDR32
:
5302 case R_PPC_EMB_NADDR16
:
5303 case R_PPC_EMB_NADDR16_LO
:
5304 case R_PPC_EMB_NADDR16_HI
:
5305 case R_PPC_EMB_NADDR16_HA
:
5306 addend
-= 2 * relocation
;
5310 case R_PPC_GLOB_DAT
:
5311 case R_PPC_JMP_SLOT
:
5312 case R_PPC_RELATIVE
:
5314 case R_PPC_PLTREL32
:
5315 case R_PPC_PLT16_LO
:
5316 case R_PPC_PLT16_HI
:
5317 case R_PPC_PLT16_HA
:
5319 case R_PPC_EMB_RELSEC16
:
5320 case R_PPC_EMB_RELST_LO
:
5321 case R_PPC_EMB_RELST_HI
:
5322 case R_PPC_EMB_RELST_HA
:
5323 case R_PPC_EMB_BIT_FLD
:
5324 (*_bfd_error_handler
)
5325 (_("%s: relocation %s is not yet supported for symbol %s."),
5326 bfd_archive_filename (input_bfd
),
5330 bfd_set_error (bfd_error_invalid_operation
);
5335 /* Do any further special processing. */
5341 case R_PPC_ADDR16_HA
:
5342 case R_PPC_GOT16_HA
:
5343 case R_PPC_PLT16_HA
:
5344 case R_PPC_SECTOFF_HA
:
5345 case R_PPC_TPREL16_HA
:
5346 case R_PPC_DTPREL16_HA
:
5347 case R_PPC_GOT_TLSGD16_HA
:
5348 case R_PPC_GOT_TLSLD16_HA
:
5349 case R_PPC_GOT_TPREL16_HA
:
5350 case R_PPC_GOT_DTPREL16_HA
:
5351 case R_PPC_EMB_NADDR16_HA
:
5352 case R_PPC_EMB_RELST_HA
:
5353 /* It's just possible that this symbol is a weak symbol
5354 that's not actually defined anywhere. In that case,
5355 'sec' would be NULL, and we should leave the symbol
5356 alone (it will be set to zero elsewhere in the link). */
5358 /* Add 0x10000 if sign bit in 0:15 is set.
5359 Bits 0:15 are not used. */
5365 fprintf (stderr
, "\ttype = %s (%d), name = %s, symbol index = %ld, offset = %ld, addend = %ld\n",
5370 (long) rel
->r_offset
,
5374 if (unresolved_reloc
5375 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
5376 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0))
5378 (*_bfd_error_handler
)
5379 (_("%s(%s+0x%lx): unresolvable %s relocation against symbol `%s'"),
5380 bfd_archive_filename (input_bfd
),
5381 bfd_get_section_name (input_bfd
, input_section
),
5382 (long) rel
->r_offset
,
5388 r
= _bfd_final_link_relocate (howto
,
5396 if (r
!= bfd_reloc_ok
)
5398 if (sym_name
== NULL
)
5399 sym_name
= "(null)";
5400 if (r
== bfd_reloc_overflow
)
5405 && h
->root
.type
== bfd_link_hash_undefweak
5406 && howto
->pc_relative
)
5408 /* Assume this is a call protected by other code that
5409 detect the symbol is undefined. If this is the case,
5410 we can safely ignore the overflow. If not, the
5411 program is hosed anyway, and a little warning isn't
5417 if (! (*info
->callbacks
->reloc_overflow
) (info
,
5428 (*_bfd_error_handler
)
5429 (_("%s(%s+0x%lx): %s reloc against `%s': error %d"),
5430 bfd_archive_filename (input_bfd
),
5431 bfd_get_section_name (input_bfd
, input_section
),
5432 (long) rel
->r_offset
, howto
->name
, sym_name
, (int) r
);
5439 fprintf (stderr
, "\n");
5445 static enum elf_reloc_type_class
5446 ppc_elf_reloc_type_class (rela
)
5447 const Elf_Internal_Rela
*rela
;
5449 switch ((int) ELF32_R_TYPE (rela
->r_info
))
5451 case R_PPC_RELATIVE
:
5452 return reloc_class_relative
;
5455 case R_PPC_JMP_SLOT
:
5456 return reloc_class_plt
;
5458 return reloc_class_copy
;
5460 return reloc_class_normal
;
5464 /* Support for core dump NOTE sections. */
5467 ppc_elf_grok_prstatus (abfd
, note
)
5469 Elf_Internal_Note
*note
;
5472 unsigned int raw_size
;
5474 switch (note
->descsz
)
5479 case 268: /* Linux/PPC. */
5481 elf_tdata (abfd
)->core_signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
5484 elf_tdata (abfd
)->core_pid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
5493 /* Make a ".reg/999" section. */
5494 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
5495 raw_size
, note
->descpos
+ offset
);
5499 ppc_elf_grok_psinfo (abfd
, note
)
5501 Elf_Internal_Note
*note
;
5503 switch (note
->descsz
)
5508 case 128: /* Linux/PPC elf_prpsinfo. */
5509 elf_tdata (abfd
)->core_program
5510 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 32, 16);
5511 elf_tdata (abfd
)->core_command
5512 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 48, 80);
5515 /* Note that for some reason, a spurious space is tacked
5516 onto the end of the args in some (at least one anyway)
5517 implementations, so strip it off if it exists. */
5520 char *command
= elf_tdata (abfd
)->core_command
;
5521 int n
= strlen (command
);
5523 if (0 < n
&& command
[n
- 1] == ' ')
5524 command
[n
- 1] = '\0';
5530 /* Very simple linked list structure for recording apuinfo values. */
5531 typedef struct apuinfo_list
5533 struct apuinfo_list
*next
;
5534 unsigned long value
;
5538 static apuinfo_list
* head
;
5540 static void apuinfo_list_init
PARAMS ((void));
5541 static void apuinfo_list_add
PARAMS ((unsigned long));
5542 static unsigned apuinfo_list_length
PARAMS ((void));
5543 static unsigned long apuinfo_list_element
PARAMS ((unsigned long));
5544 static void apuinfo_list_finish
PARAMS ((void));
5546 extern void ppc_elf_begin_write_processing
5547 PARAMS ((bfd
*, struct bfd_link_info
*));
5548 extern void ppc_elf_final_write_processing
5549 PARAMS ((bfd
*, bfd_boolean
));
5550 extern bfd_boolean ppc_elf_write_section
5551 PARAMS ((bfd
*, asection
*, bfd_byte
*));
5555 apuinfo_list_init
PARAMS ((void))
5561 apuinfo_list_add (value
)
5562 unsigned long value
;
5564 apuinfo_list
*entry
= head
;
5566 while (entry
!= NULL
)
5568 if (entry
->value
== value
)
5570 entry
= entry
->next
;
5573 entry
= bfd_malloc (sizeof (* entry
));
5577 entry
->value
= value
;
5583 apuinfo_list_length
PARAMS ((void))
5585 apuinfo_list
*entry
;
5586 unsigned long count
;
5588 for (entry
= head
, count
= 0;
5590 entry
= entry
->next
)
5596 static inline unsigned long
5597 apuinfo_list_element (number
)
5598 unsigned long number
;
5600 apuinfo_list
* entry
;
5604 entry
= entry
->next
)
5607 return entry
? entry
->value
: 0;
5611 apuinfo_list_finish
PARAMS ((void))
5613 apuinfo_list
*entry
;
5615 for (entry
= head
; entry
;)
5617 apuinfo_list
*next
= entry
->next
;
5625 #define APUINFO_SECTION_NAME ".PPC.EMB.apuinfo"
5626 #define APUINFO_LABEL "APUinfo"
5628 /* Scan the input BFDs and create a linked list of
5629 the APUinfo values that will need to be emitted. */
5632 ppc_elf_begin_write_processing (abfd
, link_info
)
5634 struct bfd_link_info
*link_info
;
5639 unsigned num_input_sections
;
5640 bfd_size_type output_section_size
;
5642 unsigned num_entries
;
5643 unsigned long offset
;
5644 unsigned long length
;
5645 const char *error_message
= NULL
;
5647 if (link_info
== NULL
)
5650 /* Scan the input bfds, looking for apuinfo sections. */
5651 num_input_sections
= 0;
5652 output_section_size
= 0;
5654 for (ibfd
= link_info
->input_bfds
; ibfd
; ibfd
= ibfd
->link_next
)
5656 asec
= bfd_get_section_by_name (ibfd
, APUINFO_SECTION_NAME
);
5659 ++ num_input_sections
;
5660 output_section_size
+= asec
->_raw_size
;
5664 /* We need at least one input sections
5665 in order to make merging worthwhile. */
5666 if (num_input_sections
< 1)
5669 /* Just make sure that the output section exists as well. */
5670 asec
= bfd_get_section_by_name (abfd
, APUINFO_SECTION_NAME
);
5674 /* Allocate a buffer for the contents of the input sections. */
5675 buffer
= bfd_malloc (output_section_size
);
5680 apuinfo_list_init ();
5682 /* Read in the input sections contents. */
5683 for (ibfd
= link_info
->input_bfds
; ibfd
; ibfd
= ibfd
->link_next
)
5685 unsigned long datum
;
5688 asec
= bfd_get_section_by_name (ibfd
, APUINFO_SECTION_NAME
);
5692 length
= asec
->_raw_size
;
5695 error_message
= _("corrupt or empty %s section in %s");
5699 if (bfd_seek (ibfd
, asec
->filepos
, SEEK_SET
) != 0
5700 || (bfd_bread (buffer
+ offset
, length
, ibfd
) != length
))
5702 error_message
= _("unable to read in %s section from %s");
5706 /* Process the contents of the section. */
5707 ptr
= buffer
+ offset
;
5708 error_message
= _("corrupt %s section in %s");
5710 /* Verify the contents of the header. Note - we have to
5711 extract the values this way in order to allow for a
5712 host whose endian-ness is different from the target. */
5713 datum
= bfd_get_32 (ibfd
, ptr
);
5714 if (datum
!= sizeof APUINFO_LABEL
)
5717 datum
= bfd_get_32 (ibfd
, ptr
+ 8);
5721 if (strcmp (ptr
+ 12, APUINFO_LABEL
) != 0)
5724 /* Get the number of apuinfo entries. */
5725 datum
= bfd_get_32 (ibfd
, ptr
+ 4);
5726 if ((datum
* 4 + 20) != length
)
5729 /* Make sure that we do not run off the end of the section. */
5730 if (offset
+ length
> output_section_size
)
5733 /* Scan the apuinfo section, building a list of apuinfo numbers. */
5734 for (i
= 0; i
< datum
; i
++)
5735 apuinfo_list_add (bfd_get_32 (ibfd
, ptr
+ 20 + (i
* 4)));
5737 /* Update the offset. */
5741 error_message
= NULL
;
5743 /* Compute the size of the output section. */
5744 num_entries
= apuinfo_list_length ();
5745 output_section_size
= 20 + num_entries
* 4;
5747 asec
= bfd_get_section_by_name (abfd
, APUINFO_SECTION_NAME
);
5749 if (! bfd_set_section_size (abfd
, asec
, output_section_size
))
5751 error_message
= _("warning: unable to set size of %s section in %s");
5757 (*_bfd_error_handler
) (error_message
, APUINFO_SECTION_NAME
,
5758 bfd_archive_filename (ibfd
));
5762 /* Prevent the output section from accumulating the input sections'
5763 contents. We have already stored this in our linked list structure. */
5766 ppc_elf_write_section (abfd
, asec
, contents
)
5767 bfd
*abfd ATTRIBUTE_UNUSED
;
5769 bfd_byte
*contents ATTRIBUTE_UNUSED
;
5771 return (apuinfo_list_length ()
5772 && strcmp (asec
->name
, APUINFO_SECTION_NAME
) == 0);
5776 /* Finally we can generate the output section. */
5779 ppc_elf_final_write_processing (abfd
, linker
)
5781 bfd_boolean linker ATTRIBUTE_UNUSED
;
5786 unsigned num_entries
;
5787 bfd_size_type length
;
5789 asec
= bfd_get_section_by_name (abfd
, APUINFO_SECTION_NAME
);
5793 if (apuinfo_list_length () == 0)
5796 length
= asec
->_raw_size
;
5800 buffer
= bfd_malloc (length
);
5803 (*_bfd_error_handler
)
5804 (_("failed to allocate space for new APUinfo section."));
5808 /* Create the apuinfo header. */
5809 num_entries
= apuinfo_list_length ();
5810 bfd_put_32 (abfd
, sizeof APUINFO_LABEL
, buffer
);
5811 bfd_put_32 (abfd
, num_entries
, buffer
+ 4);
5812 bfd_put_32 (abfd
, 0x2, buffer
+ 8);
5813 strcpy (buffer
+ 12, APUINFO_LABEL
);
5816 for (i
= 0; i
< num_entries
; i
++)
5818 bfd_put_32 (abfd
, apuinfo_list_element (i
), buffer
+ length
);
5822 if (length
!= asec
->_raw_size
)
5823 (*_bfd_error_handler
) (_("failed to compute new APUinfo section."));
5825 if (! bfd_set_section_contents (abfd
, asec
, buffer
, (file_ptr
) 0, length
))
5826 (*_bfd_error_handler
) (_("failed to install new APUinfo section."));
5830 apuinfo_list_finish ();
5833 #define TARGET_LITTLE_SYM bfd_elf32_powerpcle_vec
5834 #define TARGET_LITTLE_NAME "elf32-powerpcle"
5835 #define TARGET_BIG_SYM bfd_elf32_powerpc_vec
5836 #define TARGET_BIG_NAME "elf32-powerpc"
5837 #define ELF_ARCH bfd_arch_powerpc
5838 #define ELF_MACHINE_CODE EM_PPC
5839 #define ELF_MAXPAGESIZE 0x10000
5840 #define elf_info_to_howto ppc_elf_info_to_howto
5842 #ifdef EM_CYGNUS_POWERPC
5843 #define ELF_MACHINE_ALT1 EM_CYGNUS_POWERPC
5847 #define ELF_MACHINE_ALT2 EM_PPC_OLD
5850 #define elf_backend_plt_not_loaded 1
5851 #define elf_backend_got_symbol_offset 4
5852 #define elf_backend_can_gc_sections 1
5853 #define elf_backend_can_refcount 1
5854 #define elf_backend_got_header_size 12
5855 #define elf_backend_plt_header_size PLT_INITIAL_ENTRY_SIZE
5856 #define elf_backend_rela_normal 1
5858 #define bfd_elf32_bfd_merge_private_bfd_data ppc_elf_merge_private_bfd_data
5859 #define bfd_elf32_bfd_relax_section ppc_elf_relax_section
5860 #define bfd_elf32_bfd_reloc_type_lookup ppc_elf_reloc_type_lookup
5861 #define bfd_elf32_bfd_set_private_flags ppc_elf_set_private_flags
5862 #define bfd_elf32_bfd_link_hash_table_create ppc_elf_link_hash_table_create
5864 #define elf_backend_object_p ppc_elf_object_p
5865 #define elf_backend_gc_mark_hook ppc_elf_gc_mark_hook
5866 #define elf_backend_gc_sweep_hook ppc_elf_gc_sweep_hook
5867 #define elf_backend_section_from_shdr ppc_elf_section_from_shdr
5868 #define elf_backend_relocate_section ppc_elf_relocate_section
5869 #define elf_backend_create_dynamic_sections ppc_elf_create_dynamic_sections
5870 #define elf_backend_check_relocs ppc_elf_check_relocs
5871 #define elf_backend_copy_indirect_symbol ppc_elf_copy_indirect_symbol
5872 #define elf_backend_adjust_dynamic_symbol ppc_elf_adjust_dynamic_symbol
5873 #define elf_backend_add_symbol_hook ppc_elf_add_symbol_hook
5874 #define elf_backend_size_dynamic_sections ppc_elf_size_dynamic_sections
5875 #define elf_backend_finish_dynamic_symbol ppc_elf_finish_dynamic_symbol
5876 #define elf_backend_finish_dynamic_sections ppc_elf_finish_dynamic_sections
5877 #define elf_backend_fake_sections ppc_elf_fake_sections
5878 #define elf_backend_additional_program_headers ppc_elf_additional_program_headers
5879 #define elf_backend_modify_segment_map ppc_elf_modify_segment_map
5880 #define elf_backend_grok_prstatus ppc_elf_grok_prstatus
5881 #define elf_backend_grok_psinfo ppc_elf_grok_psinfo
5882 #define elf_backend_reloc_type_class ppc_elf_reloc_type_class
5883 #define elf_backend_begin_write_processing ppc_elf_begin_write_processing
5884 #define elf_backend_final_write_processing ppc_elf_final_write_processing
5885 #define elf_backend_write_section ppc_elf_write_section
5887 #include "elf32-target.h"