1 /* PowerPC-specific support for 32-bit ELF
2 Copyright 1994, 95, 96, 97, 98, 1999 Free Software Foundation, Inc.
3 Written by Ian Lance Taylor, Cygnus Support.
5 This file is part of BFD, the Binary File Descriptor library.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
21 /* This file is based on a preliminary PowerPC ELF ABI. The
22 information may not match the final PowerPC ELF ABI. It includes
23 suggestions from the in-progress Embedded PowerPC ABI, and that
24 information may also not match. */
33 #define USE_RELA /* we want RELA relocations, not REL */
36 static reloc_howto_type *ppc_elf_reloc_type_lookup
37 PARAMS ((bfd *abfd, bfd_reloc_code_real_type code));
38 static void ppc_elf_info_to_howto
39 PARAMS ((bfd *abfd, arelent *cache_ptr, Elf32_Internal_Rela *dst));
40 static void ppc_elf_howto_init PARAMS ((void));
41 static bfd_reloc_status_type ppc_elf_addr16_ha_reloc
42 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
43 static boolean ppc_elf_set_private_flags PARAMS ((bfd *, flagword));
44 static boolean ppc_elf_copy_private_bfd_data PARAMS ((bfd *, bfd *));
45 static boolean ppc_elf_merge_private_bfd_data PARAMS ((bfd *, bfd *));
47 static int ppc_elf_additional_program_headers PARAMS ((bfd *));
48 static boolean ppc_elf_modify_segment_map PARAMS ((bfd *));
50 static boolean ppc_elf_create_dynamic_sections
51 PARAMS ((bfd *, struct bfd_link_info *));
53 static boolean ppc_elf_section_from_shdr PARAMS ((bfd *,
54 Elf32_Internal_Shdr *,
56 static boolean ppc_elf_fake_sections
57 PARAMS ((bfd *, Elf32_Internal_Shdr *, asection *));
59 static elf_linker_section_t *ppc_elf_create_linker_section
61 struct bfd_link_info *info,
62 enum elf_linker_section_enum));
64 static boolean ppc_elf_check_relocs PARAMS ((bfd *,
65 struct bfd_link_info *,
67 const Elf_Internal_Rela *));
69 static asection * ppc_elf_gc_mark_hook PARAMS ((bfd *abfd,
70 struct bfd_link_info *info,
71 Elf_Internal_Rela *rel,
72 struct elf_link_hash_entry *h,
73 Elf_Internal_Sym *sym));
75 static boolean ppc_elf_gc_sweep_hook PARAMS ((bfd *abfd,
76 struct bfd_link_info *info,
78 const Elf_Internal_Rela *relocs));
80 static boolean ppc_elf_adjust_dynamic_symbol PARAMS ((struct bfd_link_info *,
81 struct elf_link_hash_entry *));
83 static boolean ppc_elf_size_dynamic_sections PARAMS ((bfd *, struct bfd_link_info *));
85 static boolean ppc_elf_relocate_section PARAMS ((bfd *,
86 struct bfd_link_info *info,
90 Elf_Internal_Rela *relocs,
91 Elf_Internal_Sym *local_syms,
94 static boolean ppc_elf_add_symbol_hook PARAMS ((bfd *,
95 struct bfd_link_info *,
96 const Elf_Internal_Sym *,
102 static boolean ppc_elf_finish_dynamic_symbol PARAMS ((bfd *,
103 struct bfd_link_info *,
104 struct elf_link_hash_entry *,
105 Elf_Internal_Sym *));
107 static boolean ppc_elf_finish_dynamic_sections PARAMS ((bfd *, struct bfd_link_info *));
109 #define BRANCH_PREDICT_BIT 0x200000 /* branch prediction bit for branch taken relocs */
110 #define RA_REGISTER_MASK 0x001f0000 /* mask to set RA in memory instructions */
111 #define RA_REGISTER_SHIFT 16 /* value to shift register by to insert RA */
113 /* The name of the dynamic interpreter. This is put in the .interp
116 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
118 /* The size in bytes of an entry in the procedure linkage table. */
119 #define PLT_ENTRY_SIZE 12
120 /* The initial size of the plt reserved for the dynamic linker. */
121 #define PLT_INITIAL_ENTRY_SIZE 72
122 /* The size of the gap between entries in the PLT. */
123 #define PLT_SLOT_SIZE 8
124 /* The number of single-slot PLT entries (the rest use two slots). */
125 #define PLT_NUM_SINGLE_ENTRIES 8192
128 static reloc_howto_type *ppc_elf_howto_table[ (int)R_PPC_max ];
130 static reloc_howto_type ppc_elf_howto_raw[] =
132 /* This reloc does nothing. */
133 HOWTO (R_PPC_NONE, /* type */
135 2, /* size (0 = byte, 1 = short, 2 = long) */
137 false, /* pc_relative */
139 complain_overflow_bitfield, /* complain_on_overflow */
140 bfd_elf_generic_reloc, /* special_function */
141 "R_PPC_NONE", /* name */
142 false, /* partial_inplace */
145 false), /* pcrel_offset */
147 /* A standard 32 bit relocation. */
148 HOWTO (R_PPC_ADDR32, /* type */
150 2, /* size (0 = byte, 1 = short, 2 = long) */
152 false, /* pc_relative */
154 complain_overflow_bitfield, /* complain_on_overflow */
155 bfd_elf_generic_reloc, /* special_function */
156 "R_PPC_ADDR32", /* name */
157 false, /* partial_inplace */
159 0xffffffff, /* dst_mask */
160 false), /* pcrel_offset */
162 /* An absolute 26 bit branch; the lower two bits must be zero.
163 FIXME: we don't check that, we just clear them. */
164 HOWTO (R_PPC_ADDR24, /* type */
166 2, /* size (0 = byte, 1 = short, 2 = long) */
168 false, /* pc_relative */
170 complain_overflow_bitfield, /* complain_on_overflow */
171 bfd_elf_generic_reloc, /* special_function */
172 "R_PPC_ADDR24", /* name */
173 false, /* partial_inplace */
175 0x3fffffc, /* dst_mask */
176 false), /* pcrel_offset */
178 /* A standard 16 bit relocation. */
179 HOWTO (R_PPC_ADDR16, /* type */
181 1, /* size (0 = byte, 1 = short, 2 = long) */
183 false, /* pc_relative */
185 complain_overflow_bitfield, /* complain_on_overflow */
186 bfd_elf_generic_reloc, /* special_function */
187 "R_PPC_ADDR16", /* name */
188 false, /* partial_inplace */
190 0xffff, /* dst_mask */
191 false), /* pcrel_offset */
193 /* A 16 bit relocation without overflow. */
194 HOWTO (R_PPC_ADDR16_LO, /* type */
196 1, /* size (0 = byte, 1 = short, 2 = long) */
198 false, /* pc_relative */
200 complain_overflow_dont,/* complain_on_overflow */
201 bfd_elf_generic_reloc, /* special_function */
202 "R_PPC_ADDR16_LO", /* name */
203 false, /* partial_inplace */
205 0xffff, /* dst_mask */
206 false), /* pcrel_offset */
208 /* The high order 16 bits of an address. */
209 HOWTO (R_PPC_ADDR16_HI, /* type */
211 1, /* size (0 = byte, 1 = short, 2 = long) */
213 false, /* pc_relative */
215 complain_overflow_dont, /* complain_on_overflow */
216 bfd_elf_generic_reloc, /* special_function */
217 "R_PPC_ADDR16_HI", /* name */
218 false, /* partial_inplace */
220 0xffff, /* dst_mask */
221 false), /* pcrel_offset */
223 /* The high order 16 bits of an address, plus 1 if the contents of
224 the low 16 bits, treated as a signed number, is negative. */
225 HOWTO (R_PPC_ADDR16_HA, /* type */
227 1, /* size (0 = byte, 1 = short, 2 = long) */
229 false, /* pc_relative */
231 complain_overflow_dont, /* complain_on_overflow */
232 ppc_elf_addr16_ha_reloc, /* special_function */
233 "R_PPC_ADDR16_HA", /* name */
234 false, /* partial_inplace */
236 0xffff, /* dst_mask */
237 false), /* pcrel_offset */
239 /* An absolute 16 bit branch; the lower two bits must be zero.
240 FIXME: we don't check that, we just clear them. */
241 HOWTO (R_PPC_ADDR14, /* type */
243 2, /* size (0 = byte, 1 = short, 2 = long) */
245 false, /* pc_relative */
247 complain_overflow_bitfield, /* complain_on_overflow */
248 bfd_elf_generic_reloc, /* special_function */
249 "R_PPC_ADDR14", /* name */
250 false, /* partial_inplace */
252 0xfffc, /* dst_mask */
253 false), /* pcrel_offset */
255 /* An absolute 16 bit branch, for which bit 10 should be set to
256 indicate that the branch is expected to be taken. The lower two
257 bits must be zero. */
258 HOWTO (R_PPC_ADDR14_BRTAKEN, /* type */
260 2, /* size (0 = byte, 1 = short, 2 = long) */
262 false, /* pc_relative */
264 complain_overflow_bitfield, /* complain_on_overflow */
265 bfd_elf_generic_reloc, /* special_function */
266 "R_PPC_ADDR14_BRTAKEN",/* name */
267 false, /* partial_inplace */
269 0xfffc, /* dst_mask */
270 false), /* pcrel_offset */
272 /* An absolute 16 bit branch, for which bit 10 should be set to
273 indicate that the branch is not expected to be taken. The lower
274 two bits must be zero. */
275 HOWTO (R_PPC_ADDR14_BRNTAKEN, /* type */
277 2, /* size (0 = byte, 1 = short, 2 = long) */
279 false, /* pc_relative */
281 complain_overflow_bitfield, /* complain_on_overflow */
282 bfd_elf_generic_reloc, /* special_function */
283 "R_PPC_ADDR14_BRNTAKEN",/* name */
284 false, /* partial_inplace */
286 0xfffc, /* dst_mask */
287 false), /* pcrel_offset */
289 /* A relative 26 bit branch; the lower two bits must be zero. */
290 HOWTO (R_PPC_REL24, /* type */
292 2, /* size (0 = byte, 1 = short, 2 = long) */
294 true, /* pc_relative */
296 complain_overflow_signed, /* complain_on_overflow */
297 bfd_elf_generic_reloc, /* special_function */
298 "R_PPC_REL24", /* name */
299 false, /* partial_inplace */
301 0x3fffffc, /* dst_mask */
302 true), /* pcrel_offset */
304 /* A relative 16 bit branch; the lower two bits must be zero. */
305 HOWTO (R_PPC_REL14, /* type */
307 2, /* size (0 = byte, 1 = short, 2 = long) */
309 true, /* pc_relative */
311 complain_overflow_signed, /* complain_on_overflow */
312 bfd_elf_generic_reloc, /* special_function */
313 "R_PPC_REL14", /* name */
314 false, /* partial_inplace */
316 0xfffc, /* dst_mask */
317 true), /* pcrel_offset */
319 /* A relative 16 bit branch. Bit 10 should be set to indicate that
320 the branch is expected to be taken. The lower two bits must be
322 HOWTO (R_PPC_REL14_BRTAKEN, /* type */
324 2, /* size (0 = byte, 1 = short, 2 = long) */
326 true, /* pc_relative */
328 complain_overflow_signed, /* complain_on_overflow */
329 bfd_elf_generic_reloc, /* special_function */
330 "R_PPC_REL14_BRTAKEN", /* name */
331 false, /* partial_inplace */
333 0xfffc, /* dst_mask */
334 true), /* pcrel_offset */
336 /* A relative 16 bit branch. Bit 10 should be set to indicate that
337 the branch is not expected to be taken. The lower two bits must
339 HOWTO (R_PPC_REL14_BRNTAKEN, /* type */
341 2, /* size (0 = byte, 1 = short, 2 = long) */
343 true, /* pc_relative */
345 complain_overflow_signed, /* complain_on_overflow */
346 bfd_elf_generic_reloc, /* special_function */
347 "R_PPC_REL14_BRNTAKEN",/* name */
348 false, /* partial_inplace */
350 0xfffc, /* dst_mask */
351 true), /* pcrel_offset */
353 /* Like R_PPC_ADDR16, but referring to the GOT table entry for the
355 HOWTO (R_PPC_GOT16, /* type */
357 1, /* size (0 = byte, 1 = short, 2 = long) */
359 false, /* pc_relative */
361 complain_overflow_signed, /* complain_on_overflow */
362 bfd_elf_generic_reloc, /* special_function */
363 "R_PPC_GOT16", /* name */
364 false, /* partial_inplace */
366 0xffff, /* dst_mask */
367 false), /* pcrel_offset */
369 /* Like R_PPC_ADDR16_LO, but referring to the GOT table entry for
371 HOWTO (R_PPC_GOT16_LO, /* type */
373 1, /* size (0 = byte, 1 = short, 2 = long) */
375 false, /* pc_relative */
377 complain_overflow_dont, /* complain_on_overflow */
378 bfd_elf_generic_reloc, /* special_function */
379 "R_PPC_GOT16_LO", /* name */
380 false, /* partial_inplace */
382 0xffff, /* dst_mask */
383 false), /* pcrel_offset */
385 /* Like R_PPC_ADDR16_HI, but referring to the GOT table entry for
387 HOWTO (R_PPC_GOT16_HI, /* type */
389 1, /* size (0 = byte, 1 = short, 2 = long) */
391 false, /* pc_relative */
393 complain_overflow_bitfield, /* complain_on_overflow */
394 bfd_elf_generic_reloc, /* special_function */
395 "R_PPC_GOT16_HI", /* name */
396 false, /* partial_inplace */
398 0xffff, /* dst_mask */
399 false), /* pcrel_offset */
401 /* Like R_PPC_ADDR16_HA, but referring to the GOT table entry for
403 HOWTO (R_PPC_GOT16_HA, /* type */
405 1, /* size (0 = byte, 1 = short, 2 = long) */
407 false, /* pc_relative */
409 complain_overflow_bitfield, /* complain_on_overflow */
410 ppc_elf_addr16_ha_reloc, /* special_function */
411 "R_PPC_GOT16_HA", /* name */
412 false, /* partial_inplace */
414 0xffff, /* dst_mask */
415 false), /* pcrel_offset */
417 /* Like R_PPC_REL24, but referring to the procedure linkage table
418 entry for the symbol. */
419 HOWTO (R_PPC_PLTREL24, /* type */
421 2, /* size (0 = byte, 1 = short, 2 = long) */
423 true, /* pc_relative */
425 complain_overflow_signed, /* complain_on_overflow */
426 bfd_elf_generic_reloc, /* special_function */
427 "R_PPC_PLTREL24", /* name */
428 false, /* partial_inplace */
430 0x3fffffc, /* dst_mask */
431 true), /* pcrel_offset */
433 /* This is used only by the dynamic linker. The symbol should exist
434 both in the object being run and in some shared library. The
435 dynamic linker copies the data addressed by the symbol from the
436 shared library into the object, because the object being
437 run has to have the data at some particular address. */
438 HOWTO (R_PPC_COPY, /* type */
440 2, /* size (0 = byte, 1 = short, 2 = long) */
442 false, /* pc_relative */
444 complain_overflow_bitfield, /* complain_on_overflow */
445 bfd_elf_generic_reloc, /* special_function */
446 "R_PPC_COPY", /* name */
447 false, /* partial_inplace */
450 false), /* pcrel_offset */
452 /* Like R_PPC_ADDR32, but used when setting global offset table
454 HOWTO (R_PPC_GLOB_DAT, /* type */
456 2, /* size (0 = byte, 1 = short, 2 = long) */
458 false, /* pc_relative */
460 complain_overflow_bitfield, /* complain_on_overflow */
461 bfd_elf_generic_reloc, /* special_function */
462 "R_PPC_GLOB_DAT", /* name */
463 false, /* partial_inplace */
465 0xffffffff, /* dst_mask */
466 false), /* pcrel_offset */
468 /* Marks a procedure linkage table entry for a symbol. */
469 HOWTO (R_PPC_JMP_SLOT, /* type */
471 2, /* size (0 = byte, 1 = short, 2 = long) */
473 false, /* pc_relative */
475 complain_overflow_bitfield, /* complain_on_overflow */
476 bfd_elf_generic_reloc, /* special_function */
477 "R_PPC_JMP_SLOT", /* name */
478 false, /* partial_inplace */
481 false), /* pcrel_offset */
483 /* Used only by the dynamic linker. When the object is run, this
484 longword is set to the load address of the object, plus the
486 HOWTO (R_PPC_RELATIVE, /* type */
488 2, /* size (0 = byte, 1 = short, 2 = long) */
490 false, /* pc_relative */
492 complain_overflow_bitfield, /* complain_on_overflow */
493 bfd_elf_generic_reloc, /* special_function */
494 "R_PPC_RELATIVE", /* name */
495 false, /* partial_inplace */
497 0xffffffff, /* dst_mask */
498 false), /* pcrel_offset */
500 /* Like R_PPC_REL24, but uses the value of the symbol within the
501 object rather than the final value. Normally used for
502 _GLOBAL_OFFSET_TABLE_. */
503 HOWTO (R_PPC_LOCAL24PC, /* type */
505 2, /* size (0 = byte, 1 = short, 2 = long) */
507 true, /* pc_relative */
509 complain_overflow_signed, /* complain_on_overflow */
510 bfd_elf_generic_reloc, /* special_function */
511 "R_PPC_LOCAL24PC", /* name */
512 false, /* partial_inplace */
514 0x3fffffc, /* dst_mask */
515 true), /* pcrel_offset */
517 /* Like R_PPC_ADDR32, but may be unaligned. */
518 HOWTO (R_PPC_UADDR32, /* type */
520 2, /* size (0 = byte, 1 = short, 2 = long) */
522 false, /* pc_relative */
524 complain_overflow_bitfield, /* complain_on_overflow */
525 bfd_elf_generic_reloc, /* special_function */
526 "R_PPC_UADDR32", /* name */
527 false, /* partial_inplace */
529 0xffffffff, /* dst_mask */
530 false), /* pcrel_offset */
532 /* Like R_PPC_ADDR16, but may be unaligned. */
533 HOWTO (R_PPC_UADDR16, /* type */
535 1, /* size (0 = byte, 1 = short, 2 = long) */
537 false, /* pc_relative */
539 complain_overflow_bitfield, /* complain_on_overflow */
540 bfd_elf_generic_reloc, /* special_function */
541 "R_PPC_UADDR16", /* name */
542 false, /* partial_inplace */
544 0xffff, /* dst_mask */
545 false), /* pcrel_offset */
547 /* 32-bit PC relative */
548 HOWTO (R_PPC_REL32, /* type */
550 2, /* size (0 = byte, 1 = short, 2 = long) */
552 true, /* pc_relative */
554 complain_overflow_bitfield, /* complain_on_overflow */
555 bfd_elf_generic_reloc, /* special_function */
556 "R_PPC_REL32", /* name */
557 false, /* partial_inplace */
559 0xffffffff, /* dst_mask */
560 true), /* pcrel_offset */
562 /* 32-bit relocation to the symbol's procedure linkage table.
563 FIXME: not supported. */
564 HOWTO (R_PPC_PLT32, /* type */
566 2, /* size (0 = byte, 1 = short, 2 = long) */
568 false, /* pc_relative */
570 complain_overflow_bitfield, /* complain_on_overflow */
571 bfd_elf_generic_reloc, /* special_function */
572 "R_PPC_PLT32", /* name */
573 false, /* partial_inplace */
576 false), /* pcrel_offset */
578 /* 32-bit PC relative relocation to the symbol's procedure linkage table.
579 FIXME: not supported. */
580 HOWTO (R_PPC_PLTREL32, /* type */
582 2, /* size (0 = byte, 1 = short, 2 = long) */
584 true, /* pc_relative */
586 complain_overflow_bitfield, /* complain_on_overflow */
587 bfd_elf_generic_reloc, /* special_function */
588 "R_PPC_PLTREL32", /* name */
589 false, /* partial_inplace */
592 true), /* pcrel_offset */
594 /* Like R_PPC_ADDR16_LO, but referring to the PLT table entry for
596 HOWTO (R_PPC_PLT16_LO, /* type */
598 1, /* size (0 = byte, 1 = short, 2 = long) */
600 false, /* pc_relative */
602 complain_overflow_dont, /* complain_on_overflow */
603 bfd_elf_generic_reloc, /* special_function */
604 "R_PPC_PLT16_LO", /* name */
605 false, /* partial_inplace */
607 0xffff, /* dst_mask */
608 false), /* pcrel_offset */
610 /* Like R_PPC_ADDR16_HI, but referring to the PLT table entry for
612 HOWTO (R_PPC_PLT16_HI, /* type */
614 1, /* size (0 = byte, 1 = short, 2 = long) */
616 false, /* pc_relative */
618 complain_overflow_bitfield, /* complain_on_overflow */
619 bfd_elf_generic_reloc, /* special_function */
620 "R_PPC_PLT16_HI", /* name */
621 false, /* partial_inplace */
623 0xffff, /* dst_mask */
624 false), /* pcrel_offset */
626 /* Like R_PPC_ADDR16_HA, but referring to the PLT table entry for
628 HOWTO (R_PPC_PLT16_HA, /* type */
630 1, /* size (0 = byte, 1 = short, 2 = long) */
632 false, /* pc_relative */
634 complain_overflow_bitfield, /* complain_on_overflow */
635 ppc_elf_addr16_ha_reloc, /* special_function */
636 "R_PPC_PLT16_HA", /* name */
637 false, /* partial_inplace */
639 0xffff, /* dst_mask */
640 false), /* pcrel_offset */
642 /* A sign-extended 16 bit value relative to _SDA_BASE_, for use with
644 HOWTO (R_PPC_SDAREL16, /* type */
646 1, /* size (0 = byte, 1 = short, 2 = long) */
648 false, /* pc_relative */
650 complain_overflow_signed, /* complain_on_overflow */
651 bfd_elf_generic_reloc, /* special_function */
652 "R_PPC_SDAREL16", /* name */
653 false, /* partial_inplace */
655 0xffff, /* dst_mask */
656 false), /* pcrel_offset */
658 /* 32-bit section relative relocation. */
659 HOWTO (R_PPC_SECTOFF, /* type */
661 2, /* size (0 = byte, 1 = short, 2 = long) */
663 true, /* pc_relative */
665 complain_overflow_bitfield, /* complain_on_overflow */
666 bfd_elf_generic_reloc, /* special_function */
667 "R_PPC_SECTOFF", /* name */
668 false, /* partial_inplace */
671 true), /* pcrel_offset */
673 /* 16-bit lower half section relative relocation. */
674 HOWTO (R_PPC_SECTOFF_LO, /* type */
676 1, /* size (0 = byte, 1 = short, 2 = long) */
678 false, /* pc_relative */
680 complain_overflow_dont, /* complain_on_overflow */
681 bfd_elf_generic_reloc, /* special_function */
682 "R_PPC_SECTOFF_LO", /* name */
683 false, /* partial_inplace */
685 0xffff, /* dst_mask */
686 false), /* pcrel_offset */
688 /* 16-bit upper half section relative relocation. */
689 HOWTO (R_PPC_SECTOFF_HI, /* type */
691 1, /* size (0 = byte, 1 = short, 2 = long) */
693 false, /* pc_relative */
695 complain_overflow_bitfield, /* complain_on_overflow */
696 bfd_elf_generic_reloc, /* special_function */
697 "R_PPC_SECTOFF_HI", /* name */
698 false, /* partial_inplace */
700 0xffff, /* dst_mask */
701 false), /* pcrel_offset */
703 /* 16-bit upper half adjusted section relative relocation. */
704 HOWTO (R_PPC_SECTOFF_HA, /* type */
706 1, /* size (0 = byte, 1 = short, 2 = long) */
708 false, /* pc_relative */
710 complain_overflow_bitfield, /* complain_on_overflow */
711 ppc_elf_addr16_ha_reloc, /* special_function */
712 "R_PPC_SECTOFF_HA", /* name */
713 false, /* partial_inplace */
715 0xffff, /* dst_mask */
716 false), /* pcrel_offset */
718 /* The remaining relocs are from the Embedded ELF ABI, and are not
719 in the SVR4 ELF ABI. */
721 /* 32 bit value resulting from the addend minus the symbol */
722 HOWTO (R_PPC_EMB_NADDR32, /* type */
724 2, /* size (0 = byte, 1 = short, 2 = long) */
726 false, /* pc_relative */
728 complain_overflow_bitfield, /* complain_on_overflow */
729 bfd_elf_generic_reloc, /* special_function */
730 "R_PPC_EMB_NADDR32", /* name */
731 false, /* partial_inplace */
733 0xffffffff, /* dst_mask */
734 false), /* pcrel_offset */
736 /* 16 bit value resulting from the addend minus the symbol */
737 HOWTO (R_PPC_EMB_NADDR16, /* type */
739 1, /* size (0 = byte, 1 = short, 2 = long) */
741 false, /* pc_relative */
743 complain_overflow_bitfield, /* complain_on_overflow */
744 bfd_elf_generic_reloc, /* special_function */
745 "R_PPC_EMB_NADDR16", /* name */
746 false, /* partial_inplace */
748 0xffff, /* dst_mask */
749 false), /* pcrel_offset */
751 /* 16 bit value resulting from the addend minus the symbol */
752 HOWTO (R_PPC_EMB_NADDR16_LO, /* type */
754 1, /* size (0 = byte, 1 = short, 2 = long) */
756 false, /* pc_relative */
758 complain_overflow_dont,/* complain_on_overflow */
759 bfd_elf_generic_reloc, /* special_function */
760 "R_PPC_EMB_ADDR16_LO", /* name */
761 false, /* partial_inplace */
763 0xffff, /* dst_mask */
764 false), /* pcrel_offset */
766 /* The high order 16 bits of the addend minus the symbol */
767 HOWTO (R_PPC_EMB_NADDR16_HI, /* type */
769 1, /* size (0 = byte, 1 = short, 2 = long) */
771 false, /* pc_relative */
773 complain_overflow_dont, /* complain_on_overflow */
774 bfd_elf_generic_reloc, /* special_function */
775 "R_PPC_EMB_NADDR16_HI", /* name */
776 false, /* partial_inplace */
778 0xffff, /* dst_mask */
779 false), /* pcrel_offset */
781 /* The high order 16 bits of the result of the addend minus the address,
782 plus 1 if the contents of the low 16 bits, treated as a signed number,
784 HOWTO (R_PPC_EMB_NADDR16_HA, /* type */
786 1, /* size (0 = byte, 1 = short, 2 = long) */
788 false, /* pc_relative */
790 complain_overflow_dont, /* complain_on_overflow */
791 ppc_elf_addr16_ha_reloc, /* special_function */
792 "R_PPC_EMB_NADDR16_HA", /* name */
793 false, /* partial_inplace */
795 0xffff, /* dst_mask */
796 false), /* pcrel_offset */
798 /* 16 bit value resulting from allocating a 4 byte word to hold an
799 address in the .sdata section, and returning the offset from
800 _SDA_BASE_ for that relocation */
801 HOWTO (R_PPC_EMB_SDAI16, /* type */
803 1, /* size (0 = byte, 1 = short, 2 = long) */
805 false, /* pc_relative */
807 complain_overflow_bitfield, /* complain_on_overflow */
808 bfd_elf_generic_reloc, /* special_function */
809 "R_PPC_EMB_SDAI16", /* name */
810 false, /* partial_inplace */
812 0xffff, /* dst_mask */
813 false), /* pcrel_offset */
815 /* 16 bit value resulting from allocating a 4 byte word to hold an
816 address in the .sdata2 section, and returning the offset from
817 _SDA2_BASE_ for that relocation */
818 HOWTO (R_PPC_EMB_SDA2I16, /* type */
820 1, /* size (0 = byte, 1 = short, 2 = long) */
822 false, /* pc_relative */
824 complain_overflow_bitfield, /* complain_on_overflow */
825 bfd_elf_generic_reloc, /* special_function */
826 "R_PPC_EMB_SDA2I16", /* name */
827 false, /* partial_inplace */
829 0xffff, /* dst_mask */
830 false), /* pcrel_offset */
832 /* A sign-extended 16 bit value relative to _SDA2_BASE_, for use with
834 HOWTO (R_PPC_EMB_SDA2REL, /* type */
836 1, /* size (0 = byte, 1 = short, 2 = long) */
838 false, /* pc_relative */
840 complain_overflow_signed, /* complain_on_overflow */
841 bfd_elf_generic_reloc, /* special_function */
842 "R_PPC_EMB_SDA2REL", /* name */
843 false, /* partial_inplace */
845 0xffff, /* dst_mask */
846 false), /* pcrel_offset */
848 /* Relocate against either _SDA_BASE_ or _SDA2_BASE_, filling in the 16 bit
849 signed offset from the appropriate base, and filling in the register
850 field with the appropriate register (0, 2, or 13). */
851 HOWTO (R_PPC_EMB_SDA21, /* type */
853 2, /* size (0 = byte, 1 = short, 2 = long) */
855 false, /* pc_relative */
857 complain_overflow_signed, /* complain_on_overflow */
858 bfd_elf_generic_reloc, /* special_function */
859 "R_PPC_EMB_SDA21", /* name */
860 false, /* partial_inplace */
862 0xffff, /* dst_mask */
863 false), /* pcrel_offset */
865 /* Relocation not handled: R_PPC_EMB_MRKREF */
866 /* Relocation not handled: R_PPC_EMB_RELSEC16 */
867 /* Relocation not handled: R_PPC_EMB_RELST_LO */
868 /* Relocation not handled: R_PPC_EMB_RELST_HI */
869 /* Relocation not handled: R_PPC_EMB_RELST_HA */
870 /* Relocation not handled: R_PPC_EMB_BIT_FLD */
872 /* PC relative relocation against either _SDA_BASE_ or _SDA2_BASE_, filling
873 in the 16 bit signed offset from the appropriate base, and filling in the
874 register field with the appropriate register (0, 2, or 13). */
875 HOWTO (R_PPC_EMB_RELSDA, /* type */
877 1, /* size (0 = byte, 1 = short, 2 = long) */
879 true, /* pc_relative */
881 complain_overflow_signed, /* complain_on_overflow */
882 bfd_elf_generic_reloc, /* special_function */
883 "R_PPC_EMB_RELSDA", /* name */
884 false, /* partial_inplace */
886 0xffff, /* dst_mask */
887 false), /* pcrel_offset */
889 /* GNU extension to record C++ vtable hierarchy */
890 HOWTO (R_PPC_GNU_VTINHERIT, /* type */
892 0, /* size (0 = byte, 1 = short, 2 = long) */
894 false, /* pc_relative */
896 complain_overflow_dont, /* complain_on_overflow */
897 NULL, /* special_function */
898 "R_PPC_GNU_VTINHERIT", /* name */
899 false, /* partial_inplace */
902 false), /* pcrel_offset */
904 /* GNU extension to record C++ vtable member usage */
905 HOWTO (R_PPC_GNU_VTENTRY, /* type */
907 0, /* size (0 = byte, 1 = short, 2 = long) */
909 false, /* pc_relative */
911 complain_overflow_dont, /* complain_on_overflow */
912 NULL, /* special_function */
913 "R_PPC_GNU_VTENTRY", /* name */
914 false, /* partial_inplace */
917 false), /* pcrel_offset */
919 /* Phony reloc to handle AIX style TOC entries */
920 HOWTO (R_PPC_TOC16, /* type */
922 1, /* size (0 = byte, 1 = short, 2 = long) */
924 false, /* pc_relative */
926 complain_overflow_signed, /* complain_on_overflow */
927 bfd_elf_generic_reloc, /* special_function */
928 "R_PPC_TOC16", /* name */
929 false, /* partial_inplace */
931 0xffff, /* dst_mask */
932 false), /* pcrel_offset */
936 /* Initialize the ppc_elf_howto_table, so that linear accesses can be done. */
939 ppc_elf_howto_init ()
941 unsigned int i, type;
943 for (i = 0; i < sizeof (ppc_elf_howto_raw) / sizeof (ppc_elf_howto_raw[0]); i++)
945 type = ppc_elf_howto_raw[i].type;
946 BFD_ASSERT (type < sizeof(ppc_elf_howto_table) / sizeof(ppc_elf_howto_table[0]));
947 ppc_elf_howto_table[type] = &ppc_elf_howto_raw[i];
952 /* This function handles relaxing for the PPC with option --mpc860c0[=<n>].
954 The MPC860, revision C0 or earlier contains a bug in the die.
955 If all of the following conditions are true, the next instruction
956 to be executed *may* be treated as a no-op.
957 1/ A forward branch is executed.
958 2/ The branch is predicted as not taken.
959 3/ The branch is taken.
960 4/ The branch is located in the last 5 words of a page.
961 (The EOP limit is 5 by default but may be specified as any value from 1-10.)
963 Our software solution is to detect these problematic branches in a
964 linker pass and modify them as follows:
965 1/ Unconditional branches - Since these are always predicted taken,
966 there is no problem and no action is required.
967 2/ Conditional backward branches - No problem, no action required.
968 3/ Conditional forward branches - Ensure that the "inverse prediction
969 bit" is set (ensure it is predicted taken).
970 4/ Conditional register branches - Ensure that the "y bit" is set
971 (ensure it is predicted taken).
974 /* Sort sections by address. */
977 ppc_elf_sort_rela (arg1, arg2)
981 const Elf_Internal_Rela **rela1 = (const Elf_Internal_Rela**) arg1;
982 const Elf_Internal_Rela **rela2 = (const Elf_Internal_Rela**) arg2;
984 /* Sort by offset. */
985 return ((*rela1)->r_offset - (*rela2)->r_offset);
989 ppc_elf_relax_section (abfd, isec, link_info, again)
992 struct bfd_link_info *link_info;
995 #define PAGESIZE 0x1000
997 bfd_byte *contents = NULL;
998 bfd_byte *free_contents = NULL;
999 Elf_Internal_Rela *internal_relocs = NULL;
1000 Elf_Internal_Rela *free_relocs = NULL;
1001 Elf_Internal_Rela **rela_comb = NULL;
1002 int comb_curr, comb_count;
1004 /* We never have to do this more than once per input section. */
1007 /* If needed, initialize this section's cooked size. */
1008 if (isec->_cooked_size == 0)
1009 isec->_cooked_size = isec->_raw_size;
1011 /* We're only interested in text sections which overlap the
1012 troublesome area at the end of a page. */
1013 if (link_info->mpc860c0 && (isec->flags & SEC_CODE) && isec->_cooked_size)
1015 bfd_vma dot, end_page, end_section;
1016 boolean section_modified;
1018 /* Get the section contents. */
1019 /* Get cached copy if it exists. */
1020 if (elf_section_data (isec)->this_hdr.contents != NULL)
1021 contents = elf_section_data (isec)->this_hdr.contents;
1024 /* Go get them off disk. */
1025 contents = (bfd_byte *) bfd_malloc (isec->_raw_size);
1026 if (contents == NULL)
1028 free_contents = contents;
1030 if (! bfd_get_section_contents (abfd, isec, contents,
1031 (file_ptr) 0, isec->_raw_size))
1037 if (isec->reloc_count)
1041 /* Get a copy of the native relocations. */
1042 internal_relocs = _bfd_elf32_link_read_relocs (
1043 abfd, isec, (PTR) NULL, (Elf_Internal_Rela *) NULL,
1044 link_info->keep_memory);
1045 if (internal_relocs == NULL)
1047 if (! link_info->keep_memory)
1048 free_relocs = internal_relocs;
1050 /* Setup a faster access method for the reloc info we need. */
1051 rela_comb = (Elf_Internal_Rela**)
1052 bfd_malloc (isec->reloc_count*sizeof(Elf_Internal_Rela*));
1053 if (rela_comb == NULL)
1055 for (n=0; n<isec->reloc_count; ++n)
1059 r_type = ELF32_R_TYPE (internal_relocs[n].r_info);
1060 if (r_type < 0 || r_type >= (int)R_PPC_max)
1063 /* Prologue constants are sometimes present in the ".text"
1064 sections and they can be identified by their associated relocation.
1065 We don't want to process those words and some others which
1066 can also be identified by their relocations. However, not all
1067 conditional branches will have a relocation so we will
1068 only ignore words that 1) have a reloc, and 2) the reloc
1069 is not applicable to a conditional branch.
1070 The array rela_comb is built here for use in the EOP scan loop. */
1073 case R_PPC_ADDR14_BRNTAKEN: /* absolute, predicted not taken */
1074 case R_PPC_REL14: /* relative cond. br. */
1075 case R_PPC_REL14_BRNTAKEN: /* rel. cond. br., predicted not taken */
1076 /* We should check the instruction. */
1079 /* The word is not a conditional branch - ignore it. */
1080 rela_comb[comb_count++] = &internal_relocs[n];
1085 qsort (rela_comb, (size_t) comb_count, sizeof (int), ppc_elf_sort_rela);
1088 /* Enumerate each EOP region that overlaps this section. */
1089 end_section = isec->vma + isec->_cooked_size;
1090 dot = end_page = (isec->vma | (PAGESIZE - 1)) + 1;
1091 dot -= link_info->mpc860c0;
1092 section_modified = false;
1093 if (dot < isec->vma) /* Increment the start position if this section */
1094 dot = isec->vma; /* begins in the middle of its first EOP region. */
1097 dot += PAGESIZE, end_page += PAGESIZE)
1100 /* Check each word in this EOP region. */
1101 for (; dot < end_page; dot += 4)
1103 bfd_vma isec_offset;
1105 boolean skip, modified;
1107 /* Don't process this word if there is a relocation for it and
1108 the relocation indicates the word is not a conditional branch. */
1110 isec_offset = dot - isec->vma;
1111 for (; comb_curr<comb_count; ++comb_curr)
1115 r_offset = rela_comb[comb_curr]->r_offset;
1116 if (r_offset >= isec_offset)
1118 if (r_offset == isec_offset) skip = true;
1124 /* Check the current word for a problematic conditional branch. */
1125 #define BO0(insn) ((insn) & 0x02000000)
1126 #define BO2(insn) ((insn) & 0x00800000)
1127 #define BO4(insn) ((insn) & 0x00200000)
1128 insn = (unsigned long) bfd_get_32 (abfd, contents + isec_offset);
1130 if ((insn & 0xFc000000) == 0x40000000)
1132 /* Instruction is BCx */
1133 if ((!BO0(insn) || !BO2(insn)) && !BO4(insn))
1136 /* This branch is predicted as "normal".
1137 If this is a forward branch, it is problematic. */
1139 target = insn & 0x0000Fffc; /*extract*/
1140 target = (target ^ 0x8000) - 0x8000; /*sign extend*/
1141 if ((insn & 0x00000002) == 0)
1142 target += dot; /*convert to abs*/
1145 insn |= 0x00200000; /* set the prediction bit */
1150 else if ((insn & 0xFc00Fffe) == 0x4c000420)
1152 /* Instruction is BCCTRx */
1153 if ((!BO0(insn) || !BO2(insn)) && !BO4(insn))
1155 /* This branch is predicted as not-taken.
1156 If this is a forward branch, it is problematic.
1157 Since we can't tell statically if it will branch forward,
1158 always set the prediction bit. */
1159 insn |= 0x00200000; /* set the prediction bit */
1163 else if ((insn & 0xFc00Fffe) == 0x4c000020)
1165 /* Instruction is BCLRx */
1166 if ((!BO0(insn) || !BO2(insn)) && !BO4(insn))
1168 /* This branch is predicted as not-taken.
1169 If this is a forward branch, it is problematic.
1170 Since we can't tell statically if it will branch forward,
1171 always set the prediction bit. */
1172 insn |= 0x00200000; /* set the prediction bit */
1181 bfd_put_32 (abfd, insn, contents + isec_offset);
1182 section_modified = true;
1186 if (section_modified)
1188 elf_section_data (isec)->this_hdr.contents = contents;
1189 free_contents = NULL;
1193 if (rela_comb != NULL)
1199 if (free_relocs != NULL)
1205 if (free_contents != NULL)
1207 if (! link_info->keep_memory)
1208 free (free_contents);
1211 /* Cache the section contents for elf_link_input_bfd. */
1212 elf_section_data (isec)->this_hdr.contents = contents;
1214 free_contents = NULL;
1220 if (rela_comb != NULL)
1222 if (free_relocs != NULL)
1224 if (free_contents != NULL)
1225 free (free_contents);
1230 static reloc_howto_type *
1231 ppc_elf_reloc_type_lookup (abfd, code)
1232 bfd *abfd ATTRIBUTE_UNUSED;
1233 bfd_reloc_code_real_type code;
1235 enum elf_ppc_reloc_type ppc_reloc = R_PPC_NONE;
1237 if (!ppc_elf_howto_table[R_PPC_ADDR32])
1238 /* Initialize howto table if needed */
1239 ppc_elf_howto_init ();
1244 return (reloc_howto_type *)NULL;
1246 case BFD_RELOC_NONE: ppc_reloc = R_PPC_NONE; break;
1247 case BFD_RELOC_32: ppc_reloc = R_PPC_ADDR32; break;
1248 case BFD_RELOC_PPC_BA26: ppc_reloc = R_PPC_ADDR24; break;
1249 case BFD_RELOC_16: ppc_reloc = R_PPC_ADDR16; break;
1250 case BFD_RELOC_LO16: ppc_reloc = R_PPC_ADDR16_LO; break;
1251 case BFD_RELOC_HI16: ppc_reloc = R_PPC_ADDR16_HI; break;
1252 case BFD_RELOC_HI16_S: ppc_reloc = R_PPC_ADDR16_HA; break;
1253 case BFD_RELOC_PPC_BA16: ppc_reloc = R_PPC_ADDR14; break;
1254 case BFD_RELOC_PPC_BA16_BRTAKEN: ppc_reloc = R_PPC_ADDR14_BRTAKEN; break;
1255 case BFD_RELOC_PPC_BA16_BRNTAKEN: ppc_reloc = R_PPC_ADDR14_BRNTAKEN; break;
1256 case BFD_RELOC_PPC_B26: ppc_reloc = R_PPC_REL24; break;
1257 case BFD_RELOC_PPC_B16: ppc_reloc = R_PPC_REL14; break;
1258 case BFD_RELOC_PPC_B16_BRTAKEN: ppc_reloc = R_PPC_REL14_BRTAKEN; break;
1259 case BFD_RELOC_PPC_B16_BRNTAKEN: ppc_reloc = R_PPC_REL14_BRNTAKEN; break;
1260 case BFD_RELOC_16_GOTOFF: ppc_reloc = R_PPC_GOT16; break;
1261 case BFD_RELOC_LO16_GOTOFF: ppc_reloc = R_PPC_GOT16_LO; break;
1262 case BFD_RELOC_HI16_GOTOFF: ppc_reloc = R_PPC_GOT16_HI; break;
1263 case BFD_RELOC_HI16_S_GOTOFF: ppc_reloc = R_PPC_GOT16_HA; break;
1264 case BFD_RELOC_24_PLT_PCREL: ppc_reloc = R_PPC_PLTREL24; break;
1265 case BFD_RELOC_PPC_COPY: ppc_reloc = R_PPC_COPY; break;
1266 case BFD_RELOC_PPC_GLOB_DAT: ppc_reloc = R_PPC_GLOB_DAT; break;
1267 case BFD_RELOC_PPC_LOCAL24PC: ppc_reloc = R_PPC_LOCAL24PC; break;
1268 case BFD_RELOC_32_PCREL: ppc_reloc = R_PPC_REL32; break;
1269 case BFD_RELOC_32_PLTOFF: ppc_reloc = R_PPC_PLT32; break;
1270 case BFD_RELOC_32_PLT_PCREL: ppc_reloc = R_PPC_PLTREL32; break;
1271 case BFD_RELOC_LO16_PLTOFF: ppc_reloc = R_PPC_PLT16_LO; break;
1272 case BFD_RELOC_HI16_PLTOFF: ppc_reloc = R_PPC_PLT16_HI; break;
1273 case BFD_RELOC_HI16_S_PLTOFF: ppc_reloc = R_PPC_PLT16_HA; break;
1274 case BFD_RELOC_GPREL16: ppc_reloc = R_PPC_SDAREL16; break;
1275 case BFD_RELOC_32_BASEREL: ppc_reloc = R_PPC_SECTOFF; break;
1276 case BFD_RELOC_LO16_BASEREL: ppc_reloc = R_PPC_SECTOFF_LO; break;
1277 case BFD_RELOC_HI16_BASEREL: ppc_reloc = R_PPC_SECTOFF_HI; break;
1278 case BFD_RELOC_HI16_S_BASEREL: ppc_reloc = R_PPC_SECTOFF_HA; break;
1279 case BFD_RELOC_CTOR: ppc_reloc = R_PPC_ADDR32; break;
1280 case BFD_RELOC_PPC_TOC16: ppc_reloc = R_PPC_TOC16; break;
1281 case BFD_RELOC_PPC_EMB_NADDR32: ppc_reloc = R_PPC_EMB_NADDR32; break;
1282 case BFD_RELOC_PPC_EMB_NADDR16: ppc_reloc = R_PPC_EMB_NADDR16; break;
1283 case BFD_RELOC_PPC_EMB_NADDR16_LO: ppc_reloc = R_PPC_EMB_NADDR16_LO; break;
1284 case BFD_RELOC_PPC_EMB_NADDR16_HI: ppc_reloc = R_PPC_EMB_NADDR16_HI; break;
1285 case BFD_RELOC_PPC_EMB_NADDR16_HA: ppc_reloc = R_PPC_EMB_NADDR16_HA; break;
1286 case BFD_RELOC_PPC_EMB_SDAI16: ppc_reloc = R_PPC_EMB_SDAI16; break;
1287 case BFD_RELOC_PPC_EMB_SDA2I16: ppc_reloc = R_PPC_EMB_SDA2I16; break;
1288 case BFD_RELOC_PPC_EMB_SDA2REL: ppc_reloc = R_PPC_EMB_SDA2REL; break;
1289 case BFD_RELOC_PPC_EMB_SDA21: ppc_reloc = R_PPC_EMB_SDA21; break;
1290 case BFD_RELOC_PPC_EMB_MRKREF: ppc_reloc = R_PPC_EMB_MRKREF; break;
1291 case BFD_RELOC_PPC_EMB_RELSEC16: ppc_reloc = R_PPC_EMB_RELSEC16; break;
1292 case BFD_RELOC_PPC_EMB_RELST_LO: ppc_reloc = R_PPC_EMB_RELST_LO; break;
1293 case BFD_RELOC_PPC_EMB_RELST_HI: ppc_reloc = R_PPC_EMB_RELST_HI; break;
1294 case BFD_RELOC_PPC_EMB_RELST_HA: ppc_reloc = R_PPC_EMB_RELST_HA; break;
1295 case BFD_RELOC_PPC_EMB_BIT_FLD: ppc_reloc = R_PPC_EMB_BIT_FLD; break;
1296 case BFD_RELOC_PPC_EMB_RELSDA: ppc_reloc = R_PPC_EMB_RELSDA; break;
1297 case BFD_RELOC_VTABLE_INHERIT: ppc_reloc = R_PPC_GNU_VTINHERIT; break;
1298 case BFD_RELOC_VTABLE_ENTRY: ppc_reloc = R_PPC_GNU_VTENTRY; break;
1301 return ppc_elf_howto_table[ (int)ppc_reloc ];
1304 /* Set the howto pointer for a PowerPC ELF reloc. */
1307 ppc_elf_info_to_howto (abfd, cache_ptr, dst)
1308 bfd *abfd ATTRIBUTE_UNUSED;
1310 Elf32_Internal_Rela *dst;
1312 if (!ppc_elf_howto_table[ R_PPC_ADDR32 ]) /* Initialize howto table if needed */
1313 ppc_elf_howto_init ();
1315 BFD_ASSERT (ELF32_R_TYPE (dst->r_info) < (unsigned int) R_PPC_max);
1316 cache_ptr->howto = ppc_elf_howto_table[ELF32_R_TYPE (dst->r_info)];
1319 /* Handle the R_PPC_ADDR16_HA reloc. */
1321 static bfd_reloc_status_type
1322 ppc_elf_addr16_ha_reloc (abfd, reloc_entry, symbol, data, input_section,
1323 output_bfd, error_message)
1324 bfd *abfd ATTRIBUTE_UNUSED;
1325 arelent *reloc_entry;
1327 PTR data ATTRIBUTE_UNUSED;
1328 asection *input_section;
1330 char **error_message ATTRIBUTE_UNUSED;
1334 if (output_bfd != NULL)
1336 reloc_entry->address += input_section->output_offset;
1337 return bfd_reloc_ok;
1340 if (reloc_entry->address > input_section->_cooked_size)
1341 return bfd_reloc_outofrange;
1343 if (bfd_is_com_section (symbol->section))
1346 relocation = symbol->value;
1348 relocation += symbol->section->output_section->vma;
1349 relocation += symbol->section->output_offset;
1350 relocation += reloc_entry->addend;
1352 reloc_entry->addend += (relocation & 0x8000) << 1;
1354 return bfd_reloc_continue;
1357 /* Function to set whether a module needs the -mrelocatable bit set. */
1360 ppc_elf_set_private_flags (abfd, flags)
1364 BFD_ASSERT (!elf_flags_init (abfd)
1365 || elf_elfheader (abfd)->e_flags == flags);
1367 elf_elfheader (abfd)->e_flags = flags;
1368 elf_flags_init (abfd) = true;
1372 /* Copy backend specific data from one object module to another */
1374 ppc_elf_copy_private_bfd_data (ibfd, obfd)
1378 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
1379 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
1382 BFD_ASSERT (!elf_flags_init (obfd)
1383 || elf_elfheader (obfd)->e_flags == elf_elfheader (ibfd)->e_flags);
1385 elf_elfheader (obfd)->e_flags = elf_elfheader (ibfd)->e_flags;
1386 elf_flags_init (obfd) = true;
1390 /* Merge backend specific data from an object file to the output
1391 object file when linking */
1393 ppc_elf_merge_private_bfd_data (ibfd, obfd)
1401 /* Check if we have the same endianess */
1402 if (ibfd->xvec->byteorder != obfd->xvec->byteorder
1403 && obfd->xvec->byteorder != BFD_ENDIAN_UNKNOWN)
1407 if (bfd_big_endian (ibfd))
1408 msg = _("%s: compiled for a big endian system and target is little endian");
1410 msg = _("%s: compiled for a little endian system and target is big endian");
1412 (*_bfd_error_handler) (msg, bfd_get_filename (ibfd));
1414 bfd_set_error (bfd_error_wrong_format);
1418 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
1419 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
1422 new_flags = elf_elfheader (ibfd)->e_flags;
1423 old_flags = elf_elfheader (obfd)->e_flags;
1424 if (!elf_flags_init (obfd)) /* First call, no flags set */
1426 elf_flags_init (obfd) = true;
1427 elf_elfheader (obfd)->e_flags = new_flags;
1430 else if (new_flags == old_flags) /* Compatible flags are ok */
1433 else /* Incompatible flags */
1435 /* Warn about -mrelocatable mismatch. Allow -mrelocatable-lib to be linked
1438 if ((new_flags & EF_PPC_RELOCATABLE) != 0
1439 && (old_flags & (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB)) == 0)
1442 (*_bfd_error_handler)
1443 (_("%s: compiled with -mrelocatable and linked with modules compiled normally"),
1444 bfd_get_filename (ibfd));
1446 else if ((new_flags & (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB)) == 0
1447 && (old_flags & EF_PPC_RELOCATABLE) != 0)
1450 (*_bfd_error_handler)
1451 (_("%s: compiled normally and linked with modules compiled with -mrelocatable"),
1452 bfd_get_filename (ibfd));
1455 /* The output is -mrelocatable-lib iff both the input files are. */
1456 if (! (new_flags & EF_PPC_RELOCATABLE_LIB))
1457 elf_elfheader (obfd)->e_flags &= ~EF_PPC_RELOCATABLE_LIB;
1459 /* The output is -mrelocatable iff it can't be -mrelocatable-lib,
1460 but each input file is either -mrelocatable or -mrelocatable-lib. */
1461 if (! (elf_elfheader (obfd)->e_flags & EF_PPC_RELOCATABLE_LIB)
1462 && (new_flags & (EF_PPC_RELOCATABLE_LIB | EF_PPC_RELOCATABLE))
1463 && (old_flags & (EF_PPC_RELOCATABLE_LIB | EF_PPC_RELOCATABLE)))
1464 elf_elfheader (obfd)->e_flags |= EF_PPC_RELOCATABLE;
1466 /* Do not warn about eabi vs. V.4 mismatch, just or in the bit if any module uses it */
1467 elf_elfheader (obfd)->e_flags |= (new_flags & EF_PPC_EMB);
1469 new_flags &= ~ (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB | EF_PPC_EMB);
1470 old_flags &= ~ (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB | EF_PPC_EMB);
1472 /* Warn about any other mismatches */
1473 if (new_flags != old_flags)
1476 (*_bfd_error_handler)
1477 (_("%s: uses different e_flags (0x%lx) fields than previous modules (0x%lx)"),
1478 bfd_get_filename (ibfd), (long)new_flags, (long)old_flags);
1483 bfd_set_error (bfd_error_bad_value);
1492 /* Handle a PowerPC specific section when reading an object file. This
1493 is called when elfcode.h finds a section with an unknown type. */
1496 ppc_elf_section_from_shdr (abfd, hdr, name)
1498 Elf32_Internal_Shdr *hdr;
1504 if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name))
1507 newsect = hdr->bfd_section;
1508 flags = bfd_get_section_flags (abfd, newsect);
1509 if (hdr->sh_flags & SHF_EXCLUDE)
1510 flags |= SEC_EXCLUDE;
1512 if (hdr->sh_type == SHT_ORDERED)
1513 flags |= SEC_SORT_ENTRIES;
1515 bfd_set_section_flags (abfd, newsect, flags);
1520 /* Set up any other section flags and such that may be necessary. */
1523 ppc_elf_fake_sections (abfd, shdr, asect)
1524 bfd *abfd ATTRIBUTE_UNUSED;
1525 Elf32_Internal_Shdr *shdr;
1528 if ((asect->flags & SEC_EXCLUDE) != 0)
1529 shdr->sh_flags |= SHF_EXCLUDE;
1531 if ((asect->flags & SEC_SORT_ENTRIES) != 0)
1532 shdr->sh_type = SHT_ORDERED;
1538 /* Create a special linker section */
1539 static elf_linker_section_t *
1540 ppc_elf_create_linker_section (abfd, info, which)
1542 struct bfd_link_info *info;
1543 enum elf_linker_section_enum which;
1545 bfd *dynobj = elf_hash_table (info)->dynobj;
1546 elf_linker_section_t *lsect;
1548 /* Record the first bfd section that needs the special section */
1550 dynobj = elf_hash_table (info)->dynobj = abfd;
1552 /* If this is the first time, create the section */
1553 lsect = elf_linker_section (dynobj, which);
1556 elf_linker_section_t defaults;
1557 static elf_linker_section_t zero_section;
1559 defaults = zero_section;
1560 defaults.which = which;
1561 defaults.hole_written_p = false;
1562 defaults.alignment = 2;
1564 /* Both of these sections are (technically) created by the user
1565 putting data in them, so they shouldn't be marked
1568 The linker creates them so it has somewhere to attach their
1569 respective symbols. In fact, if they were empty it would
1570 be OK to leave the symbol set to 0 (or any random number), because
1571 the appropriate register should never be used. */
1572 defaults.flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS
1578 (*_bfd_error_handler) (_("%s: Unknown special linker type %d"),
1579 bfd_get_filename (abfd),
1582 bfd_set_error (bfd_error_bad_value);
1583 return (elf_linker_section_t *)0;
1585 case LINKER_SECTION_SDATA: /* .sdata/.sbss section */
1586 defaults.name = ".sdata";
1587 defaults.rel_name = ".rela.sdata";
1588 defaults.bss_name = ".sbss";
1589 defaults.sym_name = "_SDA_BASE_";
1590 defaults.sym_offset = 32768;
1593 case LINKER_SECTION_SDATA2: /* .sdata2/.sbss2 section */
1594 defaults.name = ".sdata2";
1595 defaults.rel_name = ".rela.sdata2";
1596 defaults.bss_name = ".sbss2";
1597 defaults.sym_name = "_SDA2_BASE_";
1598 defaults.sym_offset = 32768;
1599 defaults.flags |= SEC_READONLY;
1603 lsect = _bfd_elf_create_linker_section (abfd, info, which, &defaults);
1610 /* If we have a non-zero sized .sbss2 or .PPC.EMB.sbss0 sections, we need to bump up
1611 the number of section headers. */
1614 ppc_elf_additional_program_headers (abfd)
1622 s = bfd_get_section_by_name (abfd, ".interp");
1626 s = bfd_get_section_by_name (abfd, ".sbss2");
1627 if (s != NULL && (s->flags & SEC_LOAD) != 0 && s->_raw_size > 0)
1630 s = bfd_get_section_by_name (abfd, ".PPC.EMB.sbss0");
1631 if (s != NULL && (s->flags & SEC_LOAD) != 0 && s->_raw_size > 0)
1637 /* Modify the segment map if needed */
1640 ppc_elf_modify_segment_map (abfd)
1641 bfd *abfd ATTRIBUTE_UNUSED;
1646 /* We have to create .dynsbss and .rela.sbss here so that they get mapped
1647 to output sections (just like _bfd_elf_create_dynamic_sections has
1648 to create .dynbss and .rela.bss). */
1651 ppc_elf_create_dynamic_sections (abfd, info)
1653 struct bfd_link_info *info;
1655 register asection *s;
1658 if (!_bfd_elf_create_dynamic_sections(abfd, info))
1661 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
1662 | SEC_LINKER_CREATED);
1664 s = bfd_make_section (abfd, ".dynsbss");
1666 || ! bfd_set_section_flags (abfd, s, SEC_ALLOC))
1671 s = bfd_make_section (abfd, ".rela.sbss");
1673 || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
1674 || ! bfd_set_section_alignment (abfd, s, 2))
1680 /* Adjust a symbol defined by a dynamic object and referenced by a
1681 regular object. The current definition is in some section of the
1682 dynamic object, but we're not including those sections. We have to
1683 change the definition to something the rest of the link can
1687 ppc_elf_adjust_dynamic_symbol (info, h)
1688 struct bfd_link_info *info;
1689 struct elf_link_hash_entry *h;
1691 bfd *dynobj = elf_hash_table (info)->dynobj;
1693 unsigned int power_of_two;
1697 fprintf (stderr, "ppc_elf_adjust_dynamic_symbol called for %s\n", h->root.root.string);
1700 /* Make sure we know what is going on here. */
1701 BFD_ASSERT (dynobj != NULL
1702 && ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT)
1703 || h->weakdef != NULL
1704 || ((h->elf_link_hash_flags
1705 & ELF_LINK_HASH_DEF_DYNAMIC) != 0
1706 && (h->elf_link_hash_flags
1707 & ELF_LINK_HASH_REF_REGULAR) != 0
1708 && (h->elf_link_hash_flags
1709 & ELF_LINK_HASH_DEF_REGULAR) == 0)));
1712 /* If this is a function, put it in the procedure linkage table. We
1713 will fill in the contents of the procedure linkage table later,
1714 when we know the address of the .got section. */
1715 if (h->type == STT_FUNC
1716 || (h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0)
1718 if (! elf_hash_table (info)->dynamic_sections_created
1719 || ((!info->shared || info->symbolic || h->dynindx == -1)
1720 && (h->elf_link_hash_flags
1721 & ELF_LINK_HASH_DEF_REGULAR) != 0)
1722 || (info->shared && h->plt.refcount <= 0))
1724 /* A PLT entry is not required/allowed when:
1726 1. We are not using ld.so; because then the PLT entry
1727 can't be set up, so we can't use one.
1729 2. We know for certain that a symbol is defined in
1730 this object, because this object is the application,
1731 is linked with -Bsymbolic, or because the symbol is local.
1733 3. GC has rendered the entry unused.
1734 Note, however, that in an executable all references to the
1735 symbol go to the PLT, so we can't turn it off in that case.
1736 ??? The correct thing to do here is to reference count
1737 all uses of the symbol, not just those to the GOT or PLT. */
1738 h->plt.offset = (bfd_vma) -1;
1739 h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
1743 /* Make sure this symbol is output as a dynamic symbol. */
1744 if (h->dynindx == -1)
1746 if (! bfd_elf32_link_record_dynamic_symbol (info, h))
1749 BFD_ASSERT (h->dynindx != -1);
1751 s = bfd_get_section_by_name (dynobj, ".plt");
1752 BFD_ASSERT (s != NULL);
1754 /* If this is the first .plt entry, make room for the special
1756 if (s->_raw_size == 0)
1757 s->_raw_size += PLT_INITIAL_ENTRY_SIZE;
1759 /* The PowerPC PLT is actually composed of two parts, the first part
1760 is 2 words (for a load and a jump), and then there is a remaining
1761 word available at the end. */
1762 plt_offset = (PLT_INITIAL_ENTRY_SIZE
1764 * ((s->_raw_size - PLT_INITIAL_ENTRY_SIZE)
1765 / PLT_ENTRY_SIZE)));
1767 /* If this symbol is not defined in a regular file, and we are
1768 not generating a shared library, then set the symbol to this
1769 location in the .plt. This is required to make function
1770 pointers compare as equal between the normal executable and
1771 the shared library. */
1773 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
1775 h->root.u.def.section = s;
1776 h->root.u.def.value = plt_offset;
1779 h->plt.offset = plt_offset;
1781 /* Make room for this entry. After the 8192nd entry, room
1782 for two entries is allocated. */
1783 if ((s->_raw_size - PLT_INITIAL_ENTRY_SIZE) / PLT_ENTRY_SIZE
1784 >= PLT_NUM_SINGLE_ENTRIES)
1785 s->_raw_size += 2 * PLT_ENTRY_SIZE;
1787 s->_raw_size += PLT_ENTRY_SIZE;
1789 /* We also need to make an entry in the .rela.plt section. */
1790 s = bfd_get_section_by_name (dynobj, ".rela.plt");
1791 BFD_ASSERT (s != NULL);
1792 s->_raw_size += sizeof (Elf32_External_Rela);
1797 /* If this is a weak symbol, and there is a real definition, the
1798 processor independent code will have arranged for us to see the
1799 real definition first, and we can just use the same value. */
1800 if (h->weakdef != NULL)
1802 BFD_ASSERT (h->weakdef->root.type == bfd_link_hash_defined
1803 || h->weakdef->root.type == bfd_link_hash_defweak);
1804 h->root.u.def.section = h->weakdef->root.u.def.section;
1805 h->root.u.def.value = h->weakdef->root.u.def.value;
1809 /* This is a reference to a symbol defined by a dynamic object which
1810 is not a function. */
1812 /* If we are creating a shared library, we must presume that the
1813 only references to the symbol are via the global offset table.
1814 For such cases we need not do anything here; the relocations will
1815 be handled correctly by relocate_section. */
1819 /* We must allocate the symbol in our .dynbss section, which will
1820 become part of the .bss section of the executable. There will be
1821 an entry for this symbol in the .dynsym section. The dynamic
1822 object will contain position independent code, so all references
1823 from the dynamic object to this symbol will go through the global
1824 offset table. The dynamic linker will use the .dynsym entry to
1825 determine the address it must put in the global offset table, so
1826 both the dynamic object and the regular object will refer to the
1827 same memory location for the variable.
1829 Of course, if the symbol is sufficiently small, we must instead
1830 allocate it in .sbss. FIXME: It would be better to do this if and
1831 only if there were actually SDAREL relocs for that symbol. */
1833 if (h->size <= elf_gp_size (dynobj))
1834 s = bfd_get_section_by_name (dynobj, ".dynsbss");
1836 s = bfd_get_section_by_name (dynobj, ".dynbss");
1837 BFD_ASSERT (s != NULL);
1839 /* We must generate a R_PPC_COPY reloc to tell the dynamic linker to
1840 copy the initial value out of the dynamic object and into the
1841 runtime process image. We need to remember the offset into the
1842 .rela.bss section we are going to use. */
1843 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
1847 if (h->size <= elf_gp_size (dynobj))
1848 srel = bfd_get_section_by_name (dynobj, ".rela.sbss");
1850 srel = bfd_get_section_by_name (dynobj, ".rela.bss");
1851 BFD_ASSERT (srel != NULL);
1852 srel->_raw_size += sizeof (Elf32_External_Rela);
1853 h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_COPY;
1856 /* We need to figure out the alignment required for this symbol. I
1857 have no idea how ELF linkers handle this. */
1858 power_of_two = bfd_log2 (h->size);
1859 if (power_of_two > 4)
1862 /* Apply the required alignment. */
1863 s->_raw_size = BFD_ALIGN (s->_raw_size,
1864 (bfd_size_type) (1 << power_of_two));
1865 if (power_of_two > bfd_get_section_alignment (dynobj, s))
1867 if (! bfd_set_section_alignment (dynobj, s, power_of_two))
1871 /* Define the symbol as being at this point in the section. */
1872 h->root.u.def.section = s;
1873 h->root.u.def.value = s->_raw_size;
1875 /* Increment the section size to make room for the symbol. */
1876 s->_raw_size += h->size;
1882 /* Set the sizes of the dynamic sections. */
1885 ppc_elf_size_dynamic_sections (output_bfd, info)
1887 struct bfd_link_info *info;
1896 fprintf (stderr, "ppc_elf_size_dynamic_sections called\n");
1899 dynobj = elf_hash_table (info)->dynobj;
1900 BFD_ASSERT (dynobj != NULL);
1902 if (elf_hash_table (info)->dynamic_sections_created)
1904 /* Set the contents of the .interp section to the interpreter. */
1907 s = bfd_get_section_by_name (dynobj, ".interp");
1908 BFD_ASSERT (s != NULL);
1909 s->_raw_size = sizeof ELF_DYNAMIC_INTERPRETER;
1910 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
1915 /* We may have created entries in the .rela.got, .rela.sdata, and
1916 .rela.sdata2 sections. However, if we are not creating the
1917 dynamic sections, we will not actually use these entries. Reset
1918 the size of .rela.got, et al, which will cause it to get
1919 stripped from the output file below. */
1920 static char *rela_sections[] = { ".rela.got", ".rela.sdata",
1921 ".rela.sdata2", ".rela.sbss",
1925 for (p = rela_sections; *p != (char *)0; p++)
1927 s = bfd_get_section_by_name (dynobj, *p);
1933 /* The check_relocs and adjust_dynamic_symbol entry points have
1934 determined the sizes of the various dynamic sections. Allocate
1939 for (s = dynobj->sections; s != NULL; s = s->next)
1944 if ((s->flags & SEC_LINKER_CREATED) == 0)
1947 /* It's OK to base decisions on the section name, because none
1948 of the dynobj section names depend upon the input files. */
1949 name = bfd_get_section_name (dynobj, s);
1953 if (strcmp (name, ".plt") == 0)
1955 if (s->_raw_size == 0)
1957 /* Strip this section if we don't need it; see the
1963 /* Remember whether there is a PLT. */
1967 else if (strncmp (name, ".rela", 5) == 0)
1969 if (s->_raw_size == 0)
1971 /* If we don't need this section, strip it from the
1972 output file. This is mostly to handle .rela.bss and
1973 .rela.plt. We must create both sections in
1974 create_dynamic_sections, because they must be created
1975 before the linker maps input sections to output
1976 sections. The linker does that before
1977 adjust_dynamic_symbol is called, and it is that
1978 function which decides whether anything needs to go
1979 into these sections. */
1985 const char *outname;
1987 /* Remember whether there are any relocation sections. */
1990 /* If this relocation section applies to a read only
1991 section, then we probably need a DT_TEXTREL entry. */
1992 outname = bfd_get_section_name (output_bfd,
1994 target = bfd_get_section_by_name (output_bfd, outname + 5);
1996 && (target->flags & SEC_READONLY) != 0
1997 && (target->flags & SEC_ALLOC) != 0)
2000 /* We use the reloc_count field as a counter if we need
2001 to copy relocs into the output file. */
2005 else if (strcmp (name, ".got") != 0
2006 && strcmp (name, ".sdata") != 0
2007 && strcmp (name, ".sdata2") != 0)
2009 /* It's not one of our sections, so don't allocate space. */
2015 _bfd_strip_section_from_output (info, s);
2019 /* Allocate memory for the section contents. */
2020 s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->_raw_size);
2021 if (s->contents == NULL && s->_raw_size != 0)
2025 if (elf_hash_table (info)->dynamic_sections_created)
2027 /* Add some entries to the .dynamic section. We fill in the
2028 values later, in ppc_elf_finish_dynamic_sections, but we
2029 must add the entries now so that we get the correct size for
2030 the .dynamic section. The DT_DEBUG entry is filled in by the
2031 dynamic linker and used by the debugger. */
2034 if (! bfd_elf32_add_dynamic_entry (info, DT_DEBUG, 0))
2040 if (! bfd_elf32_add_dynamic_entry (info, DT_PLTGOT, 0)
2041 || ! bfd_elf32_add_dynamic_entry (info, DT_PLTRELSZ, 0)
2042 || ! bfd_elf32_add_dynamic_entry (info, DT_PLTREL, DT_RELA)
2043 || ! bfd_elf32_add_dynamic_entry (info, DT_JMPREL, 0))
2049 if (! bfd_elf32_add_dynamic_entry (info, DT_RELA, 0)
2050 || ! bfd_elf32_add_dynamic_entry (info, DT_RELASZ, 0)
2051 || ! bfd_elf32_add_dynamic_entry (info, DT_RELAENT,
2052 sizeof (Elf32_External_Rela)))
2058 if (! bfd_elf32_add_dynamic_entry (info, DT_TEXTREL, 0))
2067 /* Look through the relocs for a section during the first phase, and
2068 allocate space in the global offset table or procedure linkage
2072 ppc_elf_check_relocs (abfd, info, sec, relocs)
2074 struct bfd_link_info *info;
2076 const Elf_Internal_Rela *relocs;
2079 Elf_Internal_Shdr *symtab_hdr;
2080 struct elf_link_hash_entry **sym_hashes, **sym_hashes_end;
2081 const Elf_Internal_Rela *rel;
2082 const Elf_Internal_Rela *rel_end;
2083 bfd_signed_vma *local_got_refcounts;
2084 elf_linker_section_t *sdata;
2085 elf_linker_section_t *sdata2;
2087 asection *sgot = NULL;
2088 asection *srelgot = NULL;
2090 if (info->relocateable)
2094 fprintf (stderr, "ppc_elf_check_relocs called for section %s in %s\n",
2095 bfd_get_section_name (abfd, sec),
2096 bfd_get_filename (abfd));
2099 /* Create the linker generated sections all the time so that the
2100 special symbols are created. */
2102 if ((sdata = elf_linker_section (abfd, LINKER_SECTION_SDATA)) == NULL)
2104 sdata = ppc_elf_create_linker_section (abfd, info, LINKER_SECTION_SDATA);
2110 if ((sdata2 = elf_linker_section (abfd, LINKER_SECTION_SDATA2)) == NULL)
2112 sdata2 = ppc_elf_create_linker_section (abfd, info, LINKER_SECTION_SDATA2);
2117 dynobj = elf_hash_table (info)->dynobj;
2118 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
2119 local_got_refcounts = elf_local_got_refcounts (abfd);
2121 sym_hashes = elf_sym_hashes (abfd);
2122 sym_hashes_end = sym_hashes + symtab_hdr->sh_size/sizeof(Elf32_External_Sym);
2123 if (!elf_bad_symtab (abfd))
2124 sym_hashes_end -= symtab_hdr->sh_info;
2128 rel_end = relocs + sec->reloc_count;
2129 for (rel = relocs; rel < rel_end; rel++)
2131 unsigned long r_symndx;
2132 struct elf_link_hash_entry *h;
2134 r_symndx = ELF32_R_SYM (rel->r_info);
2135 if (r_symndx < symtab_hdr->sh_info)
2138 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
2140 /* If a relocation refers to _GLOBAL_OFFSET_TABLE_, create the .got.
2141 This shows up in particular in an R_PPC_ADDR32 in the eabi
2143 if (h && strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
2148 elf_hash_table (info)->dynobj = dynobj = abfd;
2149 if (! _bfd_elf_create_got_section (dynobj, info))
2151 sgot = bfd_get_section_by_name (dynobj, ".got");
2152 BFD_ASSERT (sgot != NULL);
2156 switch (ELF32_R_TYPE (rel->r_info))
2158 /* GOT16 relocations */
2160 case R_PPC_GOT16_LO:
2161 case R_PPC_GOT16_HI:
2162 case R_PPC_GOT16_HA:
2163 /* This symbol requires a global offset table entry. */
2168 elf_hash_table (info)->dynobj = dynobj = abfd;
2169 if (! _bfd_elf_create_got_section (dynobj, info))
2171 sgot = bfd_get_section_by_name (dynobj, ".got");
2172 BFD_ASSERT (sgot != NULL);
2176 && (h != NULL || info->shared))
2178 srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
2179 if (srelgot == NULL)
2181 srelgot = bfd_make_section (dynobj, ".rela.got");
2183 || ! bfd_set_section_flags (dynobj, srelgot,
2188 | SEC_LINKER_CREATED
2190 || ! bfd_set_section_alignment (dynobj, srelgot, 2))
2197 if (h->got.refcount == -1)
2199 /* Make sure this symbol is output as a dynamic symbol. */
2200 if (h->dynindx == -1)
2201 if (!bfd_elf32_link_record_dynamic_symbol (info, h))
2204 /* Allocate space in the .got. */
2205 sgot->_raw_size += 4;
2206 /* Allocate relocation space. */
2207 srelgot->_raw_size += sizeof (Elf32_External_Rela);
2209 h->got.refcount = 1;
2216 /* This is a global offset table entry for a local symbol. */
2217 if (local_got_refcounts == NULL)
2221 size = symtab_hdr->sh_info * sizeof (bfd_signed_vma);
2222 local_got_refcounts = (bfd_signed_vma *)
2223 bfd_alloc (abfd, size);
2224 if (local_got_refcounts == NULL)
2226 elf_local_got_refcounts (abfd) = local_got_refcounts;
2227 memset (local_got_refcounts, -1, size);
2229 if (local_got_refcounts[r_symndx] == -1)
2231 sgot->_raw_size += 4;
2233 /* If we are generating a shared object, we need to
2234 output a R_PPC_RELATIVE reloc so that the
2235 dynamic linker can adjust this GOT entry. */
2237 srelgot->_raw_size += sizeof (Elf32_External_Rela);
2239 local_got_refcounts[r_symndx] = 1;
2242 local_got_refcounts[r_symndx]++;
2246 /* Indirect .sdata relocation */
2247 case R_PPC_EMB_SDAI16:
2250 ((*_bfd_error_handler)
2251 (_("%s: relocation %s cannot be used when making a shared object"),
2252 bfd_get_filename (abfd), "R_PPC_EMB_SDAI16"));
2256 if (srelgot == NULL && (h != NULL || info->shared))
2258 srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
2259 if (srelgot == NULL)
2261 srelgot = bfd_make_section (dynobj, ".rela.got");
2263 || ! bfd_set_section_flags (dynobj, srelgot,
2268 | SEC_LINKER_CREATED
2270 || ! bfd_set_section_alignment (dynobj, srelgot, 2))
2275 if (!bfd_elf32_create_pointer_linker_section (abfd, info, sdata, h, rel))
2280 /* Indirect .sdata2 relocation */
2281 case R_PPC_EMB_SDA2I16:
2284 ((*_bfd_error_handler)
2285 (_("%s: relocation %s cannot be used when making a shared object"),
2286 bfd_get_filename (abfd), "R_PPC_EMB_SDA2I16"));
2290 if (srelgot == NULL && (h != NULL || info->shared))
2292 srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
2293 if (srelgot == NULL)
2295 srelgot = bfd_make_section (dynobj, ".rela.got");
2297 || ! bfd_set_section_flags (dynobj, srelgot,
2302 | SEC_LINKER_CREATED
2304 || ! bfd_set_section_alignment (dynobj, srelgot, 2))
2309 if (!bfd_elf32_create_pointer_linker_section (abfd, info, sdata2, h, rel))
2314 case R_PPC_SDAREL16:
2315 case R_PPC_EMB_SDA2REL:
2316 case R_PPC_EMB_SDA21:
2319 ((*_bfd_error_handler)
2320 (_("%s: relocation %s cannot be used when making a shared object"),
2321 bfd_get_filename (abfd),
2322 ppc_elf_howto_table[(int)ELF32_R_TYPE (rel->r_info)]->name));
2328 case R_PPC_PLTREL24:
2329 case R_PPC_PLT16_LO:
2330 case R_PPC_PLT16_HI:
2331 case R_PPC_PLT16_HA:
2333 fprintf (stderr, "Reloc requires a PLT entry\n");
2335 /* This symbol requires a procedure linkage table entry. We
2336 actually build the entry in adjust_dynamic_symbol,
2337 because this might be a case of linking PIC code without
2338 linking in any dynamic objects, in which case we don't
2339 need to generate a procedure linkage table after all. */
2343 /* It does not make sense to have a procedure linkage
2344 table entry for a local symbol. */
2345 bfd_set_error (bfd_error_bad_value);
2349 /* Make sure this symbol is output as a dynamic symbol. */
2350 if (h->dynindx == -1)
2352 if (! bfd_elf32_link_record_dynamic_symbol (info, h))
2355 if (h->plt.refcount == -1)
2357 h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
2358 h->plt.refcount = 1;
2364 /* The following relocations don't need to propagate the
2365 relocation if linking a shared object since they are
2366 section relative. */
2368 case R_PPC_SECTOFF_LO:
2369 case R_PPC_SECTOFF_HI:
2370 case R_PPC_SECTOFF_HA:
2373 /* This refers only to functions defined in the shared library */
2374 case R_PPC_LOCAL24PC:
2377 /* This relocation describes the C++ object vtable hierarchy.
2378 Reconstruct it for later use during GC. */
2379 case R_PPC_GNU_VTINHERIT:
2380 if (!_bfd_elf32_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
2384 /* This relocation describes which C++ vtable entries are actually
2385 used. Record for later use during GC. */
2386 case R_PPC_GNU_VTENTRY:
2387 if (!_bfd_elf32_gc_record_vtentry (abfd, sec, h, rel->r_addend))
2391 /* When creating a shared object, we must copy these
2392 relocs into the output file. We create a reloc
2393 section in dynobj and make room for the reloc. */
2396 case R_PPC_REL14_BRTAKEN:
2397 case R_PPC_REL14_BRNTAKEN:
2400 || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
2408 fprintf (stderr, "ppc_elf_check_relocs need to create relocation for %s\n",
2409 (h && h->root.root.string) ? h->root.root.string : "<unknown>");
2415 name = (bfd_elf_string_from_elf_section
2417 elf_elfheader (abfd)->e_shstrndx,
2418 elf_section_data (sec)->rel_hdr.sh_name));
2422 BFD_ASSERT (strncmp (name, ".rela", 5) == 0
2423 && strcmp (bfd_get_section_name (abfd, sec),
2426 sreloc = bfd_get_section_by_name (dynobj, name);
2431 sreloc = bfd_make_section (dynobj, name);
2432 flags = (SEC_HAS_CONTENTS | SEC_READONLY
2433 | SEC_IN_MEMORY | SEC_LINKER_CREATED);
2434 if ((sec->flags & SEC_ALLOC) != 0)
2435 flags |= SEC_ALLOC | SEC_LOAD;
2437 || ! bfd_set_section_flags (dynobj, sreloc, flags)
2438 || ! bfd_set_section_alignment (dynobj, sreloc, 2))
2443 sreloc->_raw_size += sizeof (Elf32_External_Rela);
2445 /* FIXME: We should here do what the m68k and i386
2446 backends do: if the reloc is pc-relative, record it
2447 in case it turns out that the reloc is unnecessary
2448 because the symbol is forced local by versioning or
2449 we are linking with -Bdynamic. Fortunately this
2450 case is not frequent. */
2460 /* Return the section that should be marked against GC for a given
2464 ppc_elf_gc_mark_hook (abfd, info, rel, h, sym)
2466 struct bfd_link_info *info ATTRIBUTE_UNUSED;
2467 Elf_Internal_Rela *rel;
2468 struct elf_link_hash_entry *h;
2469 Elf_Internal_Sym *sym;
2473 switch (ELF32_R_TYPE (rel->r_info))
2475 case R_PPC_GNU_VTINHERIT:
2476 case R_PPC_GNU_VTENTRY:
2480 switch (h->root.type)
2482 case bfd_link_hash_defined:
2483 case bfd_link_hash_defweak:
2484 return h->root.u.def.section;
2486 case bfd_link_hash_common:
2487 return h->root.u.c.p->section;
2496 if (!(elf_bad_symtab (abfd)
2497 && ELF_ST_BIND (sym->st_info) != STB_LOCAL)
2498 && ! ((sym->st_shndx <= 0 || sym->st_shndx >= SHN_LORESERVE)
2499 && sym->st_shndx != SHN_COMMON))
2501 return bfd_section_from_elf_index (abfd, sym->st_shndx);
2508 /* Update the got entry reference counts for the section being removed. */
2511 ppc_elf_gc_sweep_hook (abfd, info, sec, relocs)
2513 struct bfd_link_info *info ATTRIBUTE_UNUSED;
2515 const Elf_Internal_Rela *relocs;
2517 Elf_Internal_Shdr *symtab_hdr;
2518 struct elf_link_hash_entry **sym_hashes;
2519 bfd_signed_vma *local_got_refcounts;
2520 const Elf_Internal_Rela *rel, *relend;
2521 unsigned long r_symndx;
2522 struct elf_link_hash_entry *h;
2524 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
2525 sym_hashes = elf_sym_hashes (abfd);
2526 local_got_refcounts = elf_local_got_refcounts (abfd);
2528 relend = relocs + sec->reloc_count;
2529 for (rel = relocs; rel < relend; rel++)
2530 switch (ELF32_R_TYPE (rel->r_info))
2533 case R_PPC_GOT16_LO:
2534 case R_PPC_GOT16_HI:
2535 case R_PPC_GOT16_HA:
2536 r_symndx = ELF32_R_SYM (rel->r_info);
2537 if (r_symndx >= symtab_hdr->sh_info)
2539 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
2540 if (h->got.refcount > 0)
2543 else if (local_got_refcounts != NULL)
2545 if (local_got_refcounts[r_symndx] > 0)
2546 local_got_refcounts[r_symndx]--;
2551 case R_PPC_PLTREL24:
2552 case R_PPC_PLT16_LO:
2553 case R_PPC_PLT16_HI:
2554 case R_PPC_PLT16_HA:
2555 r_symndx = ELF32_R_SYM (rel->r_info);
2556 if (r_symndx >= symtab_hdr->sh_info)
2558 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
2559 if (h->plt.refcount > 0)
2571 /* Hook called by the linker routine which adds symbols from an object
2572 file. We use it to put .comm items in .sbss, and not .bss. */
2576 ppc_elf_add_symbol_hook (abfd, info, sym, namep, flagsp, secp, valp)
2578 struct bfd_link_info *info;
2579 const Elf_Internal_Sym *sym;
2580 const char **namep ATTRIBUTE_UNUSED;
2581 flagword *flagsp ATTRIBUTE_UNUSED;
2585 if (sym->st_shndx == SHN_COMMON
2586 && !info->relocateable
2587 && sym->st_size <= (bfd_vma) bfd_get_gp_size (abfd))
2589 /* Common symbols less than or equal to -G nn bytes are automatically
2591 elf_linker_section_t *sdata
2592 = ppc_elf_create_linker_section (abfd, info, LINKER_SECTION_SDATA);
2594 if (!sdata->bss_section)
2596 /* We don't go through bfd_make_section, because we don't
2597 want to attach this common section to DYNOBJ. The linker
2598 will move the symbols to the appropriate output section
2599 when it defines common symbols. */
2600 sdata->bss_section = ((asection *)
2601 bfd_zalloc (abfd, sizeof (asection)));
2602 if (sdata->bss_section == NULL)
2604 sdata->bss_section->name = sdata->bss_name;
2605 sdata->bss_section->flags = SEC_IS_COMMON;
2606 sdata->bss_section->output_section = sdata->bss_section;
2607 sdata->bss_section->symbol =
2608 (asymbol *) bfd_zalloc (abfd, sizeof (asymbol));
2609 sdata->bss_section->symbol_ptr_ptr =
2610 (asymbol **) bfd_zalloc (abfd, sizeof (asymbol *));
2611 if (sdata->bss_section->symbol == NULL
2612 || sdata->bss_section->symbol_ptr_ptr == NULL)
2614 sdata->bss_section->symbol->name = sdata->bss_name;
2615 sdata->bss_section->symbol->flags = BSF_SECTION_SYM;
2616 sdata->bss_section->symbol->section = sdata->bss_section;
2617 *sdata->bss_section->symbol_ptr_ptr = sdata->bss_section->symbol;
2620 *secp = sdata->bss_section;
2621 *valp = sym->st_size;
2628 /* Finish up dynamic symbol handling. We set the contents of various
2629 dynamic sections here. */
2632 ppc_elf_finish_dynamic_symbol (output_bfd, info, h, sym)
2634 struct bfd_link_info *info;
2635 struct elf_link_hash_entry *h;
2636 Elf_Internal_Sym *sym;
2641 fprintf (stderr, "ppc_elf_finish_dynamic_symbol called for %s",
2642 h->root.root.string);
2645 dynobj = elf_hash_table (info)->dynobj;
2646 BFD_ASSERT (dynobj != NULL);
2648 if (h->plt.offset != (bfd_vma) -1)
2652 Elf_Internal_Rela rela;
2653 bfd_vma reloc_index;
2656 fprintf (stderr, ", plt_offset = %d", h->plt.offset);
2659 /* This symbol has an entry in the procedure linkage table. Set
2662 BFD_ASSERT (h->dynindx != -1);
2664 splt = bfd_get_section_by_name (dynobj, ".plt");
2665 srela = bfd_get_section_by_name (dynobj, ".rela.plt");
2666 BFD_ASSERT (splt != NULL && srela != NULL);
2668 /* We don't need to fill in the .plt. The ppc dynamic linker
2671 /* Fill in the entry in the .rela.plt section. */
2672 rela.r_offset = (splt->output_section->vma
2673 + splt->output_offset
2675 rela.r_info = ELF32_R_INFO (h->dynindx, R_PPC_JMP_SLOT);
2678 reloc_index = (h->plt.offset - PLT_INITIAL_ENTRY_SIZE) / PLT_SLOT_SIZE;
2679 if (reloc_index > PLT_NUM_SINGLE_ENTRIES)
2680 reloc_index -= (reloc_index - PLT_NUM_SINGLE_ENTRIES) / 2;
2681 bfd_elf32_swap_reloca_out (output_bfd, &rela,
2682 ((Elf32_External_Rela *) srela->contents
2685 if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
2687 /* Mark the symbol as undefined, rather than as defined in
2688 the .plt section. Leave the value alone. */
2689 sym->st_shndx = SHN_UNDEF;
2693 if (h->got.offset != (bfd_vma) -1)
2697 Elf_Internal_Rela rela;
2699 /* This symbol has an entry in the global offset table. Set it
2702 sgot = bfd_get_section_by_name (dynobj, ".got");
2703 srela = bfd_get_section_by_name (dynobj, ".rela.got");
2704 BFD_ASSERT (sgot != NULL && srela != NULL);
2706 rela.r_offset = (sgot->output_section->vma
2707 + sgot->output_offset
2708 + (h->got.offset &~ 1));
2710 /* If this is a -Bsymbolic link, and the symbol is defined
2711 locally, we just want to emit a RELATIVE reloc. The entry in
2712 the global offset table will already have been initialized in
2713 the relocate_section function. */
2715 && (info->symbolic || h->dynindx == -1)
2716 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR))
2718 rela.r_info = ELF32_R_INFO (0, R_PPC_RELATIVE);
2719 rela.r_addend = (h->root.u.def.value
2720 + h->root.u.def.section->output_section->vma
2721 + h->root.u.def.section->output_offset);
2725 BFD_ASSERT((h->got.offset & 1) == 0);
2726 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + h->got.offset);
2727 rela.r_info = ELF32_R_INFO (h->dynindx, R_PPC_GLOB_DAT);
2731 bfd_elf32_swap_reloca_out (output_bfd, &rela,
2732 ((Elf32_External_Rela *) srela->contents
2733 + srela->reloc_count));
2734 ++srela->reloc_count;
2737 if ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_COPY) != 0)
2740 Elf_Internal_Rela rela;
2742 /* This symbols needs a copy reloc. Set it up. */
2745 fprintf (stderr, ", copy");
2748 BFD_ASSERT (h->dynindx != -1);
2750 if (h->size <= elf_gp_size (dynobj))
2751 s = bfd_get_section_by_name (h->root.u.def.section->owner,
2754 s = bfd_get_section_by_name (h->root.u.def.section->owner,
2756 BFD_ASSERT (s != NULL);
2758 rela.r_offset = (h->root.u.def.value
2759 + h->root.u.def.section->output_section->vma
2760 + h->root.u.def.section->output_offset);
2761 rela.r_info = ELF32_R_INFO (h->dynindx, R_PPC_COPY);
2763 bfd_elf32_swap_reloca_out (output_bfd, &rela,
2764 ((Elf32_External_Rela *) s->contents
2770 fprintf (stderr, "\n");
2773 /* Mark some specially defined symbols as absolute. */
2774 if (strcmp (h->root.root.string, "_DYNAMIC") == 0
2775 || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0
2776 || strcmp (h->root.root.string, "_PROCEDURE_LINKAGE_TABLE_") == 0)
2777 sym->st_shndx = SHN_ABS;
2783 /* Finish up the dynamic sections. */
2786 ppc_elf_finish_dynamic_sections (output_bfd, info)
2788 struct bfd_link_info *info;
2791 bfd *dynobj = elf_hash_table (info)->dynobj;
2792 asection *sgot = bfd_get_section_by_name (dynobj, ".got");
2795 fprintf (stderr, "ppc_elf_finish_dynamic_sections called\n");
2798 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
2800 if (elf_hash_table (info)->dynamic_sections_created)
2803 Elf32_External_Dyn *dyncon, *dynconend;
2805 splt = bfd_get_section_by_name (dynobj, ".plt");
2806 BFD_ASSERT (splt != NULL && sdyn != NULL);
2808 dyncon = (Elf32_External_Dyn *) sdyn->contents;
2809 dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->_raw_size);
2810 for (; dyncon < dynconend; dyncon++)
2812 Elf_Internal_Dyn dyn;
2816 bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
2820 case DT_PLTGOT: name = ".plt"; size = false; break;
2821 case DT_PLTRELSZ: name = ".rela.plt"; size = true; break;
2822 case DT_JMPREL: name = ".rela.plt"; size = false; break;
2823 default: name = NULL; size = false; break;
2830 s = bfd_get_section_by_name (output_bfd, name);
2836 dyn.d_un.d_ptr = s->vma;
2839 if (s->_cooked_size != 0)
2840 dyn.d_un.d_val = s->_cooked_size;
2842 dyn.d_un.d_val = s->_raw_size;
2845 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
2850 /* Add a blrl instruction at _GLOBAL_OFFSET_TABLE_-4 so that a function can
2851 easily find the address of the _GLOBAL_OFFSET_TABLE_. */
2854 unsigned char *contents = sgot->contents;
2855 bfd_put_32 (output_bfd, 0x4e800021 /* blrl */, contents);
2858 bfd_put_32 (output_bfd, (bfd_vma) 0, contents+4);
2860 bfd_put_32 (output_bfd,
2861 sdyn->output_section->vma + sdyn->output_offset,
2864 elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4;
2871 /* The RELOCATE_SECTION function is called by the ELF backend linker
2872 to handle the relocations for a section.
2874 The relocs are always passed as Rela structures; if the section
2875 actually uses Rel structures, the r_addend field will always be
2878 This function is responsible for adjust the section contents as
2879 necessary, and (if using Rela relocs and generating a
2880 relocateable output file) adjusting the reloc addend as
2883 This function does not have to worry about setting the reloc
2884 address or the reloc symbol index.
2886 LOCAL_SYMS is a pointer to the swapped in local symbols.
2888 LOCAL_SECTIONS is an array giving the section in the input file
2889 corresponding to the st_shndx field of each local symbol.
2891 The global hash table entry for the global symbols can be found
2892 via elf_sym_hashes (input_bfd).
2894 When generating relocateable output, this function must handle
2895 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
2896 going to be the section symbol corresponding to the output
2897 section, which means that the addend must be adjusted
2901 ppc_elf_relocate_section (output_bfd, info, input_bfd, input_section,
2902 contents, relocs, local_syms, local_sections)
2904 struct bfd_link_info *info;
2906 asection *input_section;
2908 Elf_Internal_Rela *relocs;
2909 Elf_Internal_Sym *local_syms;
2910 asection **local_sections;
2912 Elf_Internal_Shdr *symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
2913 struct elf_link_hash_entry **sym_hashes = elf_sym_hashes (input_bfd);
2914 bfd *dynobj = elf_hash_table (info)->dynobj;
2915 elf_linker_section_t *sdata = (dynobj) ? elf_linker_section (dynobj, LINKER_SECTION_SDATA) : NULL;
2916 elf_linker_section_t *sdata2 = (dynobj) ? elf_linker_section (dynobj, LINKER_SECTION_SDATA2) : NULL;
2917 Elf_Internal_Rela *rel = relocs;
2918 Elf_Internal_Rela *relend = relocs + input_section->reloc_count;
2919 asection *sreloc = NULL;
2922 bfd_vma *local_got_offsets;
2927 fprintf (stderr, "ppc_elf_relocate_section called for %s section %s, %ld relocations%s\n",
2928 bfd_get_filename (input_bfd),
2929 bfd_section_name(input_bfd, input_section),
2930 (long)input_section->reloc_count,
2931 (info->relocateable) ? " (relocatable)" : "");
2934 if (!ppc_elf_howto_table[ R_PPC_ADDR32 ]) /* Initialize howto table if needed */
2935 ppc_elf_howto_init ();
2937 local_got_offsets = elf_local_got_offsets (input_bfd);
2942 splt = bfd_get_section_by_name (dynobj, ".plt");
2943 sgot = bfd_get_section_by_name (dynobj, ".got");
2946 for (; rel < relend; rel++)
2948 enum elf_ppc_reloc_type r_type = (enum elf_ppc_reloc_type)ELF32_R_TYPE (rel->r_info);
2949 bfd_vma offset = rel->r_offset;
2950 bfd_vma addend = rel->r_addend;
2951 bfd_reloc_status_type r = bfd_reloc_other;
2952 Elf_Internal_Sym *sym = (Elf_Internal_Sym *)0;
2953 asection *sec = (asection *)0;
2954 struct elf_link_hash_entry *h = (struct elf_link_hash_entry *)0;
2955 const char *sym_name = (const char *)0;
2956 reloc_howto_type *howto;
2957 unsigned long r_symndx;
2960 /* Unknown relocation handling */
2961 if ((unsigned)r_type >= (unsigned)R_PPC_max || !ppc_elf_howto_table[(int)r_type])
2963 (*_bfd_error_handler) (_("%s: unknown relocation type %d"),
2964 bfd_get_filename (input_bfd),
2967 bfd_set_error (bfd_error_bad_value);
2972 howto = ppc_elf_howto_table[(int)r_type];
2973 r_symndx = ELF32_R_SYM (rel->r_info);
2975 if (info->relocateable)
2977 /* This is a relocateable link. We don't have to change
2978 anything, unless the reloc is against a section symbol,
2979 in which case we have to adjust according to where the
2980 section symbol winds up in the output section. */
2981 if (r_symndx < symtab_hdr->sh_info)
2983 sym = local_syms + r_symndx;
2984 if ((unsigned)ELF_ST_TYPE (sym->st_info) == STT_SECTION)
2986 sec = local_sections[r_symndx];
2987 addend = rel->r_addend += sec->output_offset + sym->st_value;
2992 fprintf (stderr, "\ttype = %s (%d), symbol index = %ld, offset = %ld, addend = %ld\n",
3002 /* This is a final link. */
3003 if (r_symndx < symtab_hdr->sh_info)
3005 sym = local_syms + r_symndx;
3006 sec = local_sections[r_symndx];
3007 sym_name = "<local symbol>";
3009 relocation = (sec->output_section->vma
3010 + sec->output_offset
3015 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
3016 while (h->root.type == bfd_link_hash_indirect
3017 || h->root.type == bfd_link_hash_warning)
3018 h = (struct elf_link_hash_entry *) h->root.u.i.link;
3019 sym_name = h->root.root.string;
3020 if (h->root.type == bfd_link_hash_defined
3021 || h->root.type == bfd_link_hash_defweak)
3023 sec = h->root.u.def.section;
3024 if ((r_type == R_PPC_PLT32
3026 && h->plt.offset != (bfd_vma) -1)
3027 || (r_type == R_PPC_LOCAL24PC
3028 && sec->output_section == NULL)
3029 || ((r_type == R_PPC_GOT16
3030 || r_type == R_PPC_GOT16_LO
3031 || r_type == R_PPC_GOT16_HI
3032 || r_type == R_PPC_GOT16_HA)
3033 && elf_hash_table (info)->dynamic_sections_created
3035 || (! info->symbolic && h->dynindx != -1)
3036 || (h->elf_link_hash_flags
3037 & ELF_LINK_HASH_DEF_REGULAR) == 0))
3039 && ((! info->symbolic && h->dynindx != -1)
3040 || (h->elf_link_hash_flags
3041 & ELF_LINK_HASH_DEF_REGULAR) == 0)
3042 && ((input_section->flags & SEC_ALLOC) != 0
3043 /* Testing SEC_DEBUGGING here may be wrong.
3044 It's here to avoid a crash when
3045 generating a shared library with DWARF
3046 debugging information. */
3047 || ((input_section->flags & SEC_DEBUGGING) != 0
3048 && (h->elf_link_hash_flags
3049 & ELF_LINK_HASH_DEF_DYNAMIC) != 0))
3050 && (r_type == R_PPC_ADDR32
3051 || r_type == R_PPC_ADDR24
3052 || r_type == R_PPC_ADDR16
3053 || r_type == R_PPC_ADDR16_LO
3054 || r_type == R_PPC_ADDR16_HI
3055 || r_type == R_PPC_ADDR16_HA
3056 || r_type == R_PPC_ADDR14
3057 || r_type == R_PPC_ADDR14_BRTAKEN
3058 || r_type == R_PPC_ADDR14_BRNTAKEN
3059 || r_type == R_PPC_PLTREL24
3060 || r_type == R_PPC_COPY
3061 || r_type == R_PPC_GLOB_DAT
3062 || r_type == R_PPC_JMP_SLOT
3063 || r_type == R_PPC_UADDR32
3064 || r_type == R_PPC_UADDR16
3065 || r_type == R_PPC_SDAREL16
3066 || r_type == R_PPC_EMB_NADDR32
3067 || r_type == R_PPC_EMB_NADDR16
3068 || r_type == R_PPC_EMB_NADDR16_LO
3069 || r_type == R_PPC_EMB_NADDR16_HI
3070 || r_type == R_PPC_EMB_NADDR16_HA
3071 || r_type == R_PPC_EMB_SDAI16
3072 || r_type == R_PPC_EMB_SDA2I16
3073 || r_type == R_PPC_EMB_SDA2REL
3074 || r_type == R_PPC_EMB_SDA21
3075 || r_type == R_PPC_EMB_MRKREF
3076 || r_type == R_PPC_EMB_BIT_FLD
3077 || r_type == R_PPC_EMB_RELSDA
3078 || ((r_type == R_PPC_REL24
3079 || r_type == R_PPC_REL32
3080 || r_type == R_PPC_REL14
3081 || r_type == R_PPC_REL14_BRTAKEN
3082 || r_type == R_PPC_REL14_BRNTAKEN
3083 || r_type == R_PPC_RELATIVE)
3084 && strcmp (h->root.root.string,
3085 "_GLOBAL_OFFSET_TABLE_") != 0))))
3087 /* In these cases, we don't need the relocation
3088 value. We check specially because in some
3089 obscure cases sec->output_section will be NULL. */
3092 else if (sec->output_section == NULL)
3094 (*_bfd_error_handler)
3095 (_("%s: warning: unresolvable relocation against symbol `%s' from %s section"),
3096 bfd_get_filename (input_bfd), h->root.root.string,
3097 bfd_get_section_name (input_bfd, input_section));
3101 relocation = (h->root.u.def.value
3102 + sec->output_section->vma
3103 + sec->output_offset);
3105 else if (h->root.type == bfd_link_hash_undefweak)
3107 else if (info->shared && !info->symbolic && !info->no_undefined)
3111 if (! (*info->callbacks->undefined_symbol)(info,
3112 h->root.root.string,
3117 || info->no_undefined)))
3123 switch ((int)r_type)
3126 (*_bfd_error_handler) (_("%s: unknown relocation type %d for symbol %s"),
3127 bfd_get_filename (input_bfd),
3128 (int)r_type, sym_name);
3130 bfd_set_error (bfd_error_bad_value);
3134 /* Relocations that need no special processing. */
3135 case (int)R_PPC_LOCAL24PC:
3136 /* It makes no sense to point a local relocation
3137 at a symbol not in this object. */
3139 && (h->root.type == bfd_link_hash_defined
3140 || h->root.type == bfd_link_hash_defweak)
3141 && sec->output_section == NULL)
3143 if (! (*info->callbacks->undefined_symbol) (info,
3144 h->root.root.string,
3154 /* Relocations that may need to be propagated if this is a shared
3156 case (int)R_PPC_REL24:
3157 case (int)R_PPC_REL32:
3158 case (int)R_PPC_REL14:
3159 /* If these relocations are not to a named symbol, they can be
3160 handled right here, no need to bother the dynamic linker. */
3162 || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
3166 /* Relocations that always need to be propagated if this is a shared
3168 case (int)R_PPC_NONE:
3169 case (int)R_PPC_ADDR32:
3170 case (int)R_PPC_ADDR24:
3171 case (int)R_PPC_ADDR16:
3172 case (int)R_PPC_ADDR16_LO:
3173 case (int)R_PPC_ADDR16_HI:
3174 case (int)R_PPC_ADDR16_HA:
3175 case (int)R_PPC_ADDR14:
3176 case (int)R_PPC_UADDR32:
3177 case (int)R_PPC_UADDR16:
3180 Elf_Internal_Rela outrel;
3184 fprintf (stderr, "ppc_elf_relocate_section need to create relocation for %s\n",
3185 (h && h->root.root.string) ? h->root.root.string : "<unknown>");
3188 /* When generating a shared object, these relocations
3189 are copied into the output file to be resolved at run
3196 name = (bfd_elf_string_from_elf_section
3198 elf_elfheader (input_bfd)->e_shstrndx,
3199 elf_section_data (input_section)->rel_hdr.sh_name));
3203 BFD_ASSERT (strncmp (name, ".rela", 5) == 0
3204 && strcmp (bfd_get_section_name (input_bfd,
3208 sreloc = bfd_get_section_by_name (dynobj, name);
3209 BFD_ASSERT (sreloc != NULL);
3214 if (elf_section_data (input_section)->stab_info == NULL)
3215 outrel.r_offset = rel->r_offset;
3220 off = (_bfd_stab_section_offset
3221 (output_bfd, &elf_hash_table (info)->stab_info,
3223 &elf_section_data (input_section)->stab_info,
3225 if (off == (bfd_vma) -1)
3227 outrel.r_offset = off;
3230 outrel.r_offset += (input_section->output_section->vma
3231 + input_section->output_offset);
3234 memset (&outrel, 0, sizeof outrel);
3235 /* h->dynindx may be -1 if this symbol was marked to
3238 && ((! info->symbolic && h->dynindx != -1)
3239 || (h->elf_link_hash_flags
3240 & ELF_LINK_HASH_DEF_REGULAR) == 0))
3242 BFD_ASSERT (h->dynindx != -1);
3243 outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
3244 outrel.r_addend = rel->r_addend;
3248 if (r_type == R_PPC_ADDR32)
3250 outrel.r_info = ELF32_R_INFO (0, R_PPC_RELATIVE);
3251 outrel.r_addend = relocation + rel->r_addend;
3258 sec = local_sections[r_symndx];
3261 BFD_ASSERT (h->root.type == bfd_link_hash_defined
3263 == bfd_link_hash_defweak));
3264 sec = h->root.u.def.section;
3266 if (sec != NULL && bfd_is_abs_section (sec))
3268 else if (sec == NULL || sec->owner == NULL)
3270 bfd_set_error (bfd_error_bad_value);
3277 osec = sec->output_section;
3278 indx = elf_section_data (osec)->dynindx;
3279 BFD_ASSERT(indx > 0);
3283 printf("indx=%d section=%s flags=%08x name=%s\n",
3284 indx, osec->name, osec->flags,
3285 h->root.root.string);
3290 outrel.r_info = ELF32_R_INFO (indx, r_type);
3291 outrel.r_addend = relocation + rel->r_addend;
3295 bfd_elf32_swap_reloca_out (output_bfd, &outrel,
3296 (((Elf32_External_Rela *)
3298 + sreloc->reloc_count));
3299 ++sreloc->reloc_count;
3301 /* This reloc will be computed at runtime, so there's no
3302 need to do anything now, unless this is a RELATIVE
3303 reloc in an unallocated section. */
3305 || (input_section->flags & SEC_ALLOC) != 0
3306 || ELF32_R_TYPE (outrel.r_info) != R_PPC_RELATIVE)
3310 /* Arithmetic adjust relocations that aren't going into a
3312 if (r_type == R_PPC_ADDR16_HA
3313 /* It's just possible that this symbol is a weak symbol
3314 that's not actually defined anywhere. In that case,
3315 'sec' would be NULL, and we should leave the symbol
3316 alone (it will be set to zero elsewhere in the link). */
3319 addend += ((relocation + addend) & 0x8000) << 1;
3323 /* branch taken prediction relocations */
3324 case (int)R_PPC_ADDR14_BRTAKEN:
3325 case (int)R_PPC_REL14_BRTAKEN:
3326 insn = bfd_get_32 (output_bfd, contents + offset);
3327 if ((relocation - offset) & 0x8000)
3328 insn &= ~BRANCH_PREDICT_BIT;
3330 insn |= BRANCH_PREDICT_BIT;
3331 bfd_put_32 (output_bfd, insn, contents + offset);
3334 /* branch not taken predicition relocations */
3335 case (int)R_PPC_ADDR14_BRNTAKEN:
3336 case (int)R_PPC_REL14_BRNTAKEN:
3337 insn = bfd_get_32 (output_bfd, contents + offset);
3338 if ((relocation - offset) & 0x8000)
3339 insn |= BRANCH_PREDICT_BIT;
3341 insn &= ~BRANCH_PREDICT_BIT;
3342 bfd_put_32 (output_bfd, insn, contents + offset);
3345 /* GOT16 relocations */
3346 case (int)R_PPC_GOT16:
3347 case (int)R_PPC_GOT16_LO:
3348 case (int)R_PPC_GOT16_HI:
3349 case (int)R_PPC_GOT16_HA:
3350 /* Relocation is to the entry for this symbol in the global
3352 BFD_ASSERT (sgot != NULL);
3358 off = h->got.offset;
3359 BFD_ASSERT (off != (bfd_vma) -1);
3361 if (! elf_hash_table (info)->dynamic_sections_created
3363 && (info->symbolic || h->dynindx == -1)
3364 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR)))
3366 /* This is actually a static link, or it is a
3367 -Bsymbolic link and the symbol is defined
3368 locally. We must initialize this entry in the
3369 global offset table. Since the offset must
3370 always be a multiple of 4, we use the least
3371 significant bit to record whether we have
3372 initialized it already.
3374 When doing a dynamic link, we create a .rela.got
3375 relocation entry to initialize the value. This
3376 is done in the finish_dynamic_symbol routine. */
3381 bfd_put_32 (output_bfd, relocation,
3382 sgot->contents + off);
3387 relocation = sgot->output_offset + off - 4;
3393 BFD_ASSERT (local_got_offsets != NULL
3394 && local_got_offsets[r_symndx] != (bfd_vma) -1);
3396 off = local_got_offsets[r_symndx];
3398 /* The offset must always be a multiple of 4. We use
3399 the least significant bit to record whether we have
3400 already processed this entry. */
3405 bfd_put_32 (output_bfd, relocation, sgot->contents + off);
3410 Elf_Internal_Rela outrel;
3412 /* We need to generate a R_PPC_RELATIVE reloc
3413 for the dynamic linker. */
3414 srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
3415 BFD_ASSERT (srelgot != NULL);
3417 outrel.r_offset = (sgot->output_section->vma
3418 + sgot->output_offset
3420 outrel.r_info = ELF32_R_INFO (0, R_PPC_RELATIVE);
3421 outrel.r_addend = relocation;
3422 bfd_elf32_swap_reloca_out (output_bfd, &outrel,
3423 (((Elf32_External_Rela *)
3425 + srelgot->reloc_count));
3426 ++srelgot->reloc_count;
3429 local_got_offsets[r_symndx] |= 1;
3432 relocation = sgot->output_offset + off - 4;
3436 /* Indirect .sdata relocation */
3437 case (int)R_PPC_EMB_SDAI16:
3438 BFD_ASSERT (sdata != NULL);
3439 relocation = bfd_elf32_finish_pointer_linker_section (output_bfd, input_bfd, info,
3440 sdata, h, relocation, rel,
3444 /* Indirect .sdata2 relocation */
3445 case (int)R_PPC_EMB_SDA2I16:
3446 BFD_ASSERT (sdata2 != NULL);
3447 relocation = bfd_elf32_finish_pointer_linker_section (output_bfd, input_bfd, info,
3448 sdata2, h, relocation, rel,
3452 /* Handle the TOC16 reloc. We want to use the offset within the .got
3453 section, not the actual VMA. This is appropriate when generating
3454 an embedded ELF object, for which the .got section acts like the
3455 AIX .toc section. */
3456 case (int)R_PPC_TOC16: /* phony GOT16 relocations */
3457 BFD_ASSERT (sec != (asection *)0);
3458 BFD_ASSERT (bfd_is_und_section (sec)
3459 || strcmp (bfd_get_section_name (abfd, sec), ".got") == 0
3460 || strcmp (bfd_get_section_name (abfd, sec), ".cgot") == 0)
3462 addend -= sec->output_section->vma + sec->output_offset + 0x8000;
3465 case (int)R_PPC_PLTREL24:
3466 /* Relocation is to the entry for this symbol in the
3467 procedure linkage table. */
3468 BFD_ASSERT (h != NULL);
3470 if (h->plt.offset == (bfd_vma) -1
3473 /* We didn't make a PLT entry for this symbol. This
3474 happens when statically linking PIC code, or when
3475 using -Bsymbolic. */
3479 relocation = (splt->output_section->vma
3480 + splt->output_offset
3484 /* relocate against _SDA_BASE_ */
3485 case (int)R_PPC_SDAREL16:
3489 BFD_ASSERT (sec != (asection *)0);
3490 name = bfd_get_section_name (abfd, sec->output_section);
3491 if (strcmp (name, ".sdata") != 0
3492 && strcmp (name, ".sbss") != 0)
3494 (*_bfd_error_handler) (_("%s: The target (%s) of a %s relocation is in the wrong output section (%s)"),
3495 bfd_get_filename (input_bfd),
3497 ppc_elf_howto_table[ (int)r_type ]->name,
3500 addend -= (sdata->sym_hash->root.u.def.value
3501 + sdata->sym_hash->root.u.def.section->output_section->vma
3502 + sdata->sym_hash->root.u.def.section->output_offset);
3507 /* relocate against _SDA2_BASE_ */
3508 case (int)R_PPC_EMB_SDA2REL:
3512 BFD_ASSERT (sec != (asection *)0);
3513 name = bfd_get_section_name (abfd, sec->output_section);
3514 if (strcmp (name, ".sdata2") != 0 && strcmp (name, ".sbss2") != 0)
3516 (*_bfd_error_handler) (_("%s: The target (%s) of a %s relocation is in the wrong output section (%s)"),
3517 bfd_get_filename (input_bfd),
3519 ppc_elf_howto_table[ (int)r_type ]->name,
3522 bfd_set_error (bfd_error_bad_value);
3526 addend -= (sdata2->sym_hash->root.u.def.value
3527 + sdata2->sym_hash->root.u.def.section->output_section->vma
3528 + sdata2->sym_hash->root.u.def.section->output_offset);
3533 /* relocate against either _SDA_BASE_, _SDA2_BASE_, or 0 */
3534 case (int)R_PPC_EMB_SDA21:
3535 case (int)R_PPC_EMB_RELSDA:
3540 BFD_ASSERT (sec != (asection *)0);
3541 name = bfd_get_section_name (abfd, sec->output_section);
3542 if (strcmp (name, ".sdata") == 0 || strcmp (name, ".sbss") == 0)
3545 addend -= (sdata->sym_hash->root.u.def.value
3546 + sdata->sym_hash->root.u.def.section->output_section->vma
3547 + sdata->sym_hash->root.u.def.section->output_offset);
3550 else if (strcmp (name, ".sdata2") == 0 || strcmp (name, ".sbss2") == 0)
3553 addend -= (sdata2->sym_hash->root.u.def.value
3554 + sdata2->sym_hash->root.u.def.section->output_section->vma
3555 + sdata2->sym_hash->root.u.def.section->output_offset);
3558 else if (strcmp (name, ".PPC.EMB.sdata0") == 0 || strcmp (name, ".PPC.EMB.sbss0") == 0)
3565 (*_bfd_error_handler) (_("%s: The target (%s) of a %s relocation is in the wrong output section (%s)"),
3566 bfd_get_filename (input_bfd),
3568 ppc_elf_howto_table[ (int)r_type ]->name,
3571 bfd_set_error (bfd_error_bad_value);
3576 if (r_type == R_PPC_EMB_SDA21)
3577 { /* fill in register field */
3578 insn = bfd_get_32 (output_bfd, contents + offset);
3579 insn = (insn & ~RA_REGISTER_MASK) | (reg << RA_REGISTER_SHIFT);
3580 bfd_put_32 (output_bfd, insn, contents + offset);
3585 /* Relocate against the beginning of the section */
3586 case (int)R_PPC_SECTOFF:
3587 case (int)R_PPC_SECTOFF_LO:
3588 case (int)R_PPC_SECTOFF_HI:
3589 BFD_ASSERT (sec != (asection *)0);
3590 addend -= sec->output_section->vma;
3593 case (int)R_PPC_SECTOFF_HA:
3594 BFD_ASSERT (sec != (asection *)0);
3595 addend -= sec->output_section->vma;
3596 addend += ((relocation + addend) & 0x8000) << 1;
3599 /* Negative relocations */
3600 case (int)R_PPC_EMB_NADDR32:
3601 case (int)R_PPC_EMB_NADDR16:
3602 case (int)R_PPC_EMB_NADDR16_LO:
3603 case (int)R_PPC_EMB_NADDR16_HI:
3604 addend -= 2*relocation;
3607 case (int)R_PPC_EMB_NADDR16_HA:
3608 addend -= 2*relocation;
3609 addend += ((relocation + addend) & 0x8000) << 1;
3612 /* NOP relocation that prevents garbage collecting linkers from omitting a
3614 case (int)R_PPC_EMB_MRKREF:
3617 case (int)R_PPC_COPY:
3618 case (int)R_PPC_GLOB_DAT:
3619 case (int)R_PPC_JMP_SLOT:
3620 case (int)R_PPC_RELATIVE:
3621 case (int)R_PPC_PLT32:
3622 case (int)R_PPC_PLTREL32:
3623 case (int)R_PPC_PLT16_LO:
3624 case (int)R_PPC_PLT16_HI:
3625 case (int)R_PPC_PLT16_HA:
3626 case (int)R_PPC_EMB_RELSEC16:
3627 case (int)R_PPC_EMB_RELST_LO:
3628 case (int)R_PPC_EMB_RELST_HI:
3629 case (int)R_PPC_EMB_RELST_HA:
3630 case (int)R_PPC_EMB_BIT_FLD:
3631 (*_bfd_error_handler) (_("%s: Relocation %s is not yet supported for symbol %s."),
3632 bfd_get_filename (input_bfd),
3633 ppc_elf_howto_table[ (int)r_type ]->name,
3636 bfd_set_error (bfd_error_invalid_operation);
3640 case (int)R_PPC_GNU_VTINHERIT:
3641 case (int)R_PPC_GNU_VTENTRY:
3642 /* These are no-ops in the end. */
3648 fprintf (stderr, "\ttype = %s (%d), name = %s, symbol index = %ld, offset = %ld, addend = %ld\n",
3657 r = _bfd_final_link_relocate (howto,
3665 if (r == bfd_reloc_ok)
3667 else if (r == bfd_reloc_overflow)
3673 if (h->root.type == bfd_link_hash_undefweak
3674 && howto->pc_relative)
3676 /* Assume this is a call protected by other code that
3677 detect the symbol is undefined. If this is the case,
3678 we can safely ignore the overflow. If not, the
3679 program is hosed anyway, and a little warning isn't
3685 name = h->root.root.string;
3689 name = bfd_elf_string_from_elf_section (input_bfd,
3690 symtab_hdr->sh_link,
3695 name = bfd_section_name (input_bfd, sec);
3698 if (! (*info->callbacks->reloc_overflow)(info,
3712 fprintf (stderr, "\n");
3719 #define TARGET_LITTLE_SYM bfd_elf32_powerpcle_vec
3720 #define TARGET_LITTLE_NAME "elf32-powerpcle"
3721 #define TARGET_BIG_SYM bfd_elf32_powerpc_vec
3722 #define TARGET_BIG_NAME "elf32-powerpc"
3723 #define ELF_ARCH bfd_arch_powerpc
3724 #define ELF_MACHINE_CODE EM_PPC
3725 #define ELF_MAXPAGESIZE 0x10000
3726 #define elf_info_to_howto ppc_elf_info_to_howto
3728 #ifdef EM_CYGNUS_POWERPC
3729 #define ELF_MACHINE_ALT1 EM_CYGNUS_POWERPC
3733 #define ELF_MACHINE_ALT2 EM_PPC_OLD
3736 #define elf_backend_plt_not_loaded 1
3737 #define elf_backend_got_symbol_offset 4
3738 #define elf_backend_can_gc_sections 1
3739 #define elf_backend_got_header_size 12
3740 #define elf_backend_plt_header_size PLT_INITIAL_ENTRY_SIZE
3742 #define bfd_elf32_bfd_copy_private_bfd_data ppc_elf_copy_private_bfd_data
3743 #define bfd_elf32_bfd_merge_private_bfd_data ppc_elf_merge_private_bfd_data
3744 #define bfd_elf32_bfd_relax_section ppc_elf_relax_section
3745 #define bfd_elf32_bfd_reloc_type_lookup ppc_elf_reloc_type_lookup
3746 #define bfd_elf32_bfd_set_private_flags ppc_elf_set_private_flags
3747 #define bfd_elf32_bfd_final_link _bfd_elf32_gc_common_final_link
3749 #define elf_backend_gc_mark_hook ppc_elf_gc_mark_hook
3750 #define elf_backend_gc_sweep_hook ppc_elf_gc_sweep_hook
3751 #define elf_backend_section_from_shdr ppc_elf_section_from_shdr
3752 #define elf_backend_relocate_section ppc_elf_relocate_section
3753 #define elf_backend_create_dynamic_sections ppc_elf_create_dynamic_sections
3754 #define elf_backend_check_relocs ppc_elf_check_relocs
3755 #define elf_backend_adjust_dynamic_symbol ppc_elf_adjust_dynamic_symbol
3756 #define elf_backend_add_symbol_hook ppc_elf_add_symbol_hook
3757 #define elf_backend_size_dynamic_sections ppc_elf_size_dynamic_sections
3758 #define elf_backend_finish_dynamic_symbol ppc_elf_finish_dynamic_symbol
3759 #define elf_backend_finish_dynamic_sections ppc_elf_finish_dynamic_sections
3760 #define elf_backend_fake_sections ppc_elf_fake_sections
3761 #define elf_backend_additional_program_headers ppc_elf_additional_program_headers
3762 #define elf_backend_modify_segment_map ppc_elf_modify_segment_map
3764 #include "elf32-target.h"