1 /* PowerPC-specific support for 32-bit ELF
2 Copyright 1994, 1995, 1996, 1997 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 */
35 /* PowerPC relocations defined by the ABIs */
46 R_PPC_ADDR14_BRTAKEN = 8,
47 R_PPC_ADDR14_BRNTAKEN = 9,
50 R_PPC_REL14_BRTAKEN = 12,
51 R_PPC_REL14_BRNTAKEN = 13,
72 R_PPC_SECTOFF_LO = 34,
73 R_PPC_SECTOFF_HI = 35,
74 R_PPC_SECTOFF_HA = 36,
76 /* The remaining relocs are from the Embedded ELF ABI, and are not
77 in the SVR4 ELF ABI. */
78 R_PPC_EMB_NADDR32 = 101,
79 R_PPC_EMB_NADDR16 = 102,
80 R_PPC_EMB_NADDR16_LO = 103,
81 R_PPC_EMB_NADDR16_HI = 104,
82 R_PPC_EMB_NADDR16_HA = 105,
83 R_PPC_EMB_SDAI16 = 106,
84 R_PPC_EMB_SDA2I16 = 107,
85 R_PPC_EMB_SDA2REL = 108,
86 R_PPC_EMB_SDA21 = 109,
87 R_PPC_EMB_MRKREF = 110,
88 R_PPC_EMB_RELSEC16 = 111,
89 R_PPC_EMB_RELST_LO = 112,
90 R_PPC_EMB_RELST_HI = 113,
91 R_PPC_EMB_RELST_HA = 114,
92 R_PPC_EMB_BIT_FLD = 115,
93 R_PPC_EMB_RELSDA = 116,
95 /* This is a phony reloc to handle any old fashioned TOC16 references
96 that may still be in object files. */
102 static reloc_howto_type *ppc_elf_reloc_type_lookup
103 PARAMS ((bfd *abfd, bfd_reloc_code_real_type code));
104 static void ppc_elf_info_to_howto
105 PARAMS ((bfd *abfd, arelent *cache_ptr, Elf32_Internal_Rela *dst));
106 static void ppc_elf_howto_init PARAMS ((void));
107 static bfd_reloc_status_type ppc_elf_addr16_ha_reloc
108 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
109 static boolean ppc_elf_set_private_flags PARAMS ((bfd *, flagword));
110 static boolean ppc_elf_copy_private_bfd_data PARAMS ((bfd *, bfd *));
111 static boolean ppc_elf_merge_private_bfd_data PARAMS ((bfd *, bfd *));
113 static int ppc_elf_additional_program_headers PARAMS ((bfd *));
114 static boolean ppc_elf_modify_segment_map PARAMS ((bfd *));
116 static boolean ppc_elf_section_from_shdr PARAMS ((bfd *,
117 Elf32_Internal_Shdr *,
119 static boolean ppc_elf_fake_sections
120 PARAMS ((bfd *, Elf32_Internal_Shdr *, asection *));
122 static elf_linker_section_t *ppc_elf_create_linker_section
124 struct bfd_link_info *info,
125 enum elf_linker_section_enum));
127 static boolean ppc_elf_check_relocs PARAMS ((bfd *,
128 struct bfd_link_info *,
130 const Elf_Internal_Rela *));
132 static boolean ppc_elf_adjust_dynamic_symbol PARAMS ((struct bfd_link_info *,
133 struct elf_link_hash_entry *));
135 static boolean ppc_elf_adjust_dynindx PARAMS ((struct elf_link_hash_entry *, PTR));
137 static boolean ppc_elf_size_dynamic_sections PARAMS ((bfd *, struct bfd_link_info *));
139 static boolean ppc_elf_relocate_section PARAMS ((bfd *,
140 struct bfd_link_info *info,
144 Elf_Internal_Rela *relocs,
145 Elf_Internal_Sym *local_syms,
148 static boolean ppc_elf_add_symbol_hook PARAMS ((bfd *,
149 struct bfd_link_info *,
150 const Elf_Internal_Sym *,
156 static boolean ppc_elf_finish_dynamic_symbol PARAMS ((bfd *,
157 struct bfd_link_info *,
158 struct elf_link_hash_entry *,
159 Elf_Internal_Sym *));
161 static boolean ppc_elf_finish_dynamic_sections PARAMS ((bfd *, struct bfd_link_info *));
163 #define BRANCH_PREDICT_BIT 0x200000 /* branch prediction bit for branch taken relocs */
164 #define RA_REGISTER_MASK 0x001f0000 /* mask to set RA in memory instructions */
165 #define RA_REGISTER_SHIFT 16 /* value to shift register by to insert RA */
167 /* The name of the dynamic interpreter. This is put in the .interp
170 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
172 /* The size in bytes of an entry in the procedure linkage table, and of the initial size
173 of the plt reserved for the dynamic linker. */
175 #define PLT_ENTRY_SIZE 12
176 #define PLT_INITIAL_ENTRY_SIZE 72
179 static reloc_howto_type *ppc_elf_howto_table[ (int)R_PPC_max ];
181 static reloc_howto_type ppc_elf_howto_raw[] =
183 /* This reloc does nothing. */
184 HOWTO (R_PPC_NONE, /* type */
186 2, /* size (0 = byte, 1 = short, 2 = long) */
188 false, /* pc_relative */
190 complain_overflow_bitfield, /* complain_on_overflow */
191 bfd_elf_generic_reloc, /* special_function */
192 "R_PPC_NONE", /* name */
193 false, /* partial_inplace */
196 false), /* pcrel_offset */
198 /* A standard 32 bit relocation. */
199 HOWTO (R_PPC_ADDR32, /* type */
201 2, /* size (0 = byte, 1 = short, 2 = long) */
203 false, /* pc_relative */
205 complain_overflow_bitfield, /* complain_on_overflow */
206 bfd_elf_generic_reloc, /* special_function */
207 "R_PPC_ADDR32", /* name */
208 false, /* partial_inplace */
210 0xffffffff, /* dst_mask */
211 false), /* pcrel_offset */
213 /* An absolute 26 bit branch; the lower two bits must be zero.
214 FIXME: we don't check that, we just clear them. */
215 HOWTO (R_PPC_ADDR24, /* type */
217 2, /* size (0 = byte, 1 = short, 2 = long) */
219 false, /* pc_relative */
221 complain_overflow_bitfield, /* complain_on_overflow */
222 bfd_elf_generic_reloc, /* special_function */
223 "R_PPC_ADDR24", /* name */
224 false, /* partial_inplace */
226 0x3fffffc, /* dst_mask */
227 false), /* pcrel_offset */
229 /* A standard 16 bit relocation. */
230 HOWTO (R_PPC_ADDR16, /* type */
232 1, /* size (0 = byte, 1 = short, 2 = long) */
234 false, /* pc_relative */
236 complain_overflow_bitfield, /* complain_on_overflow */
237 bfd_elf_generic_reloc, /* special_function */
238 "R_PPC_ADDR16", /* name */
239 false, /* partial_inplace */
241 0xffff, /* dst_mask */
242 false), /* pcrel_offset */
244 /* A 16 bit relocation without overflow. */
245 HOWTO (R_PPC_ADDR16_LO, /* type */
247 1, /* size (0 = byte, 1 = short, 2 = long) */
249 false, /* pc_relative */
251 complain_overflow_dont,/* complain_on_overflow */
252 bfd_elf_generic_reloc, /* special_function */
253 "R_PPC_ADDR16_LO", /* name */
254 false, /* partial_inplace */
256 0xffff, /* dst_mask */
257 false), /* pcrel_offset */
259 /* The high order 16 bits of an address. */
260 HOWTO (R_PPC_ADDR16_HI, /* type */
262 1, /* size (0 = byte, 1 = short, 2 = long) */
264 false, /* pc_relative */
266 complain_overflow_dont, /* complain_on_overflow */
267 bfd_elf_generic_reloc, /* special_function */
268 "R_PPC_ADDR16_HI", /* name */
269 false, /* partial_inplace */
271 0xffff, /* dst_mask */
272 false), /* pcrel_offset */
274 /* The high order 16 bits of an address, plus 1 if the contents of
275 the low 16 bits, treated as a signed number, is negative. */
276 HOWTO (R_PPC_ADDR16_HA, /* type */
278 1, /* size (0 = byte, 1 = short, 2 = long) */
280 false, /* pc_relative */
282 complain_overflow_dont, /* complain_on_overflow */
283 ppc_elf_addr16_ha_reloc, /* special_function */
284 "R_PPC_ADDR16_HA", /* name */
285 false, /* partial_inplace */
287 0xffff, /* dst_mask */
288 false), /* pcrel_offset */
290 /* An absolute 16 bit branch; the lower two bits must be zero.
291 FIXME: we don't check that, we just clear them. */
292 HOWTO (R_PPC_ADDR14, /* type */
294 2, /* size (0 = byte, 1 = short, 2 = long) */
296 false, /* pc_relative */
298 complain_overflow_bitfield, /* complain_on_overflow */
299 bfd_elf_generic_reloc, /* special_function */
300 "R_PPC_ADDR14", /* name */
301 false, /* partial_inplace */
303 0xfffc, /* dst_mask */
304 false), /* pcrel_offset */
306 /* An absolute 16 bit branch, for which bit 10 should be set to
307 indicate that the branch is expected to be taken. The lower two
308 bits must be zero. */
309 HOWTO (R_PPC_ADDR14_BRTAKEN, /* type */
311 2, /* size (0 = byte, 1 = short, 2 = long) */
313 false, /* pc_relative */
315 complain_overflow_bitfield, /* complain_on_overflow */
316 bfd_elf_generic_reloc, /* special_function */
317 "R_PPC_ADDR14_BRTAKEN",/* name */
318 false, /* partial_inplace */
320 0xfffc, /* dst_mask */
321 false), /* pcrel_offset */
323 /* An absolute 16 bit branch, for which bit 10 should be set to
324 indicate that the branch is not expected to be taken. The lower
325 two bits must be zero. */
326 HOWTO (R_PPC_ADDR14_BRNTAKEN, /* type */
328 2, /* size (0 = byte, 1 = short, 2 = long) */
330 false, /* pc_relative */
332 complain_overflow_bitfield, /* complain_on_overflow */
333 bfd_elf_generic_reloc, /* special_function */
334 "R_PPC_ADDR14_BRNTAKEN",/* name */
335 false, /* partial_inplace */
337 0xfffc, /* dst_mask */
338 false), /* pcrel_offset */
340 /* A relative 26 bit branch; the lower two bits must be zero. */
341 HOWTO (R_PPC_REL24, /* type */
343 2, /* size (0 = byte, 1 = short, 2 = long) */
345 true, /* pc_relative */
347 complain_overflow_signed, /* complain_on_overflow */
348 bfd_elf_generic_reloc, /* special_function */
349 "R_PPC_REL24", /* name */
350 false, /* partial_inplace */
352 0x3fffffc, /* dst_mask */
353 true), /* pcrel_offset */
355 /* A relative 16 bit branch; the lower two bits must be zero. */
356 HOWTO (R_PPC_REL14, /* type */
358 2, /* size (0 = byte, 1 = short, 2 = long) */
360 true, /* pc_relative */
362 complain_overflow_signed, /* complain_on_overflow */
363 bfd_elf_generic_reloc, /* special_function */
364 "R_PPC_REL14", /* name */
365 false, /* partial_inplace */
367 0xfffc, /* dst_mask */
368 true), /* pcrel_offset */
370 /* A relative 16 bit branch. Bit 10 should be set to indicate that
371 the branch is expected to be taken. The lower two bits must be
373 HOWTO (R_PPC_REL14_BRTAKEN, /* type */
375 2, /* size (0 = byte, 1 = short, 2 = long) */
377 true, /* pc_relative */
379 complain_overflow_signed, /* complain_on_overflow */
380 bfd_elf_generic_reloc, /* special_function */
381 "R_PPC_REL14_BRTAKEN", /* name */
382 false, /* partial_inplace */
384 0xfffc, /* dst_mask */
385 true), /* pcrel_offset */
387 /* A relative 16 bit branch. Bit 10 should be set to indicate that
388 the branch is not expected to be taken. The lower two bits must
390 HOWTO (R_PPC_REL14_BRNTAKEN, /* type */
392 2, /* size (0 = byte, 1 = short, 2 = long) */
394 true, /* pc_relative */
396 complain_overflow_signed, /* complain_on_overflow */
397 bfd_elf_generic_reloc, /* special_function */
398 "R_PPC_REL14_BRNTAKEN",/* name */
399 false, /* partial_inplace */
401 0xfffc, /* dst_mask */
402 true), /* pcrel_offset */
404 /* Like R_PPC_ADDR16, but referring to the GOT table entry for the
406 HOWTO (R_PPC_GOT16, /* type */
408 1, /* size (0 = byte, 1 = short, 2 = long) */
410 false, /* pc_relative */
412 complain_overflow_signed, /* complain_on_overflow */
413 bfd_elf_generic_reloc, /* special_function */
414 "R_PPC_GOT16", /* name */
415 false, /* partial_inplace */
417 0xffff, /* dst_mask */
418 false), /* pcrel_offset */
420 /* Like R_PPC_ADDR16_LO, but referring to the GOT table entry for
422 HOWTO (R_PPC_GOT16_LO, /* type */
424 1, /* size (0 = byte, 1 = short, 2 = long) */
426 false, /* pc_relative */
428 complain_overflow_bitfield, /* complain_on_overflow */
429 bfd_elf_generic_reloc, /* special_function */
430 "R_PPC_GOT16_LO", /* name */
431 false, /* partial_inplace */
433 0xffff, /* dst_mask */
434 false), /* pcrel_offset */
436 /* Like R_PPC_ADDR16_HI, but referring to the GOT table entry for
438 HOWTO (R_PPC_GOT16_HI, /* type */
440 1, /* 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_GOT16_HI", /* name */
447 false, /* partial_inplace */
449 0xffff, /* dst_mask */
450 false), /* pcrel_offset */
452 /* Like R_PPC_ADDR16_HA, but referring to the GOT table entry for
454 HOWTO (R_PPC_GOT16_HA, /* type */
456 1, /* size (0 = byte, 1 = short, 2 = long) */
458 false, /* pc_relative */
460 complain_overflow_bitfield, /* complain_on_overflow */
461 ppc_elf_addr16_ha_reloc, /* special_function */
462 "R_PPC_GOT16_HA", /* name */
463 false, /* partial_inplace */
465 0xffff, /* dst_mask */
466 false), /* pcrel_offset */
468 /* Like R_PPC_REL24, but referring to the procedure linkage table
469 entry for the symbol. FIXME: Not supported. */
470 HOWTO (R_PPC_PLTREL24, /* type */
472 2, /* size (0 = byte, 1 = short, 2 = long) */
474 true, /* pc_relative */
476 complain_overflow_signed, /* complain_on_overflow */
477 bfd_elf_generic_reloc, /* special_function */
478 "R_PPC_PLTREL24", /* name */
479 false, /* partial_inplace */
481 0x3fffffc, /* dst_mask */
482 true), /* pcrel_offset */
484 /* This is used only by the dynamic linker. The symbol should exist
485 both in the object being run and in some shared library. The
486 dynamic linker copies the data addressed by the symbol from the
487 shared library into the object. I have no idea what the purpose
489 HOWTO (R_PPC_COPY, /* type */
491 2, /* size (0 = byte, 1 = short, 2 = long) */
493 false, /* pc_relative */
495 complain_overflow_bitfield, /* complain_on_overflow */
496 bfd_elf_generic_reloc, /* special_function */
497 "R_PPC_COPY", /* name */
498 false, /* partial_inplace */
501 false), /* pcrel_offset */
503 /* Like R_PPC_ADDR32, but used when setting global offset table
505 HOWTO (R_PPC_GLOB_DAT, /* type */
507 2, /* size (0 = byte, 1 = short, 2 = long) */
509 false, /* pc_relative */
511 complain_overflow_bitfield, /* complain_on_overflow */
512 bfd_elf_generic_reloc, /* special_function */
513 "R_PPC_GLOB_DAT", /* name */
514 false, /* partial_inplace */
516 0xffffffff, /* dst_mask */
517 false), /* pcrel_offset */
519 /* Marks a procedure linkage table entry for a symbol. */
520 HOWTO (R_PPC_JMP_SLOT, /* type */
522 2, /* size (0 = byte, 1 = short, 2 = long) */
524 false, /* pc_relative */
526 complain_overflow_bitfield, /* complain_on_overflow */
527 bfd_elf_generic_reloc, /* special_function */
528 "R_PPC_JMP_SLOT", /* name */
529 false, /* partial_inplace */
532 false), /* pcrel_offset */
534 /* Used only by the dynamic linker. When the object is run, this
535 longword is set to the load address of the object, plus the
537 HOWTO (R_PPC_RELATIVE, /* type */
539 2, /* size (0 = byte, 1 = short, 2 = long) */
541 false, /* pc_relative */
543 complain_overflow_bitfield, /* complain_on_overflow */
544 bfd_elf_generic_reloc, /* special_function */
545 "R_PPC_RELATIVE", /* name */
546 false, /* partial_inplace */
548 0xffffffff, /* dst_mask */
549 false), /* pcrel_offset */
551 /* Like R_PPC_REL24, but uses the value of the symbol within the
552 object rather than the final value. Normally used for
553 _GLOBAL_OFFSET_TABLE_. FIXME: Not supported. */
554 HOWTO (R_PPC_LOCAL24PC, /* type */
556 2, /* size (0 = byte, 1 = short, 2 = long) */
558 true, /* pc_relative */
560 complain_overflow_signed, /* complain_on_overflow */
561 bfd_elf_generic_reloc, /* special_function */
562 "R_PPC_LOCAL24PC", /* name */
563 false, /* partial_inplace */
565 0x3fffffc, /* dst_mask */
566 true), /* pcrel_offset */
568 /* Like R_PPC_ADDR32, but may be unaligned. */
569 HOWTO (R_PPC_UADDR32, /* type */
571 2, /* size (0 = byte, 1 = short, 2 = long) */
573 false, /* pc_relative */
575 complain_overflow_bitfield, /* complain_on_overflow */
576 bfd_elf_generic_reloc, /* special_function */
577 "R_PPC_UADDR32", /* name */
578 false, /* partial_inplace */
580 0xffffffff, /* dst_mask */
581 false), /* pcrel_offset */
583 /* Like R_PPC_ADDR16, but may be unaligned. */
584 HOWTO (R_PPC_UADDR16, /* type */
586 1, /* size (0 = byte, 1 = short, 2 = long) */
588 false, /* pc_relative */
590 complain_overflow_bitfield, /* complain_on_overflow */
591 bfd_elf_generic_reloc, /* special_function */
592 "R_PPC_UADDR16", /* name */
593 false, /* partial_inplace */
595 0xffff, /* dst_mask */
596 false), /* pcrel_offset */
598 /* 32-bit PC relative */
599 HOWTO (R_PPC_REL32, /* type */
601 2, /* size (0 = byte, 1 = short, 2 = long) */
603 true, /* pc_relative */
605 complain_overflow_bitfield, /* complain_on_overflow */
606 bfd_elf_generic_reloc, /* special_function */
607 "R_PPC_REL32", /* name */
608 false, /* partial_inplace */
610 0xffffffff, /* dst_mask */
611 true), /* pcrel_offset */
613 /* 32-bit relocation to the symbol's procedure linkage table.
614 FIXEME: not supported. */
615 HOWTO (R_PPC_PLT32, /* type */
617 2, /* size (0 = byte, 1 = short, 2 = long) */
619 false, /* pc_relative */
621 complain_overflow_bitfield, /* complain_on_overflow */
622 bfd_elf_generic_reloc, /* special_function */
623 "R_PPC_PLT32", /* name */
624 false, /* partial_inplace */
627 false), /* pcrel_offset */
629 /* 32-bit PC relative relocation to the symbol's procedure linkage table.
630 FIXEME: not supported. */
631 HOWTO (R_PPC_PLTREL32, /* type */
633 2, /* size (0 = byte, 1 = short, 2 = long) */
635 true, /* pc_relative */
637 complain_overflow_bitfield, /* complain_on_overflow */
638 bfd_elf_generic_reloc, /* special_function */
639 "R_PPC_PLTREL32", /* name */
640 false, /* partial_inplace */
643 true), /* pcrel_offset */
645 /* Like R_PPC_ADDR16_LO, but referring to the PLT table entry for
647 HOWTO (R_PPC_PLT16_LO, /* type */
649 1, /* size (0 = byte, 1 = short, 2 = long) */
651 false, /* pc_relative */
653 complain_overflow_bitfield, /* complain_on_overflow */
654 bfd_elf_generic_reloc, /* special_function */
655 "R_PPC_PLT16_LO", /* name */
656 false, /* partial_inplace */
658 0xffff, /* dst_mask */
659 false), /* pcrel_offset */
661 /* Like R_PPC_ADDR16_HI, but referring to the PLT table entry for
663 HOWTO (R_PPC_PLT16_HI, /* type */
665 1, /* size (0 = byte, 1 = short, 2 = long) */
667 false, /* pc_relative */
669 complain_overflow_bitfield, /* complain_on_overflow */
670 bfd_elf_generic_reloc, /* special_function */
671 "R_PPC_PLT16_HI", /* name */
672 false, /* partial_inplace */
674 0xffff, /* dst_mask */
675 false), /* pcrel_offset */
677 /* Like R_PPC_ADDR16_HA, but referring to the PLT table entry for
678 the symbol. FIXME: Not supported. */
679 HOWTO (R_PPC_PLT16_HA, /* type */
681 1, /* size (0 = byte, 1 = short, 2 = long) */
683 false, /* pc_relative */
685 complain_overflow_bitfield, /* complain_on_overflow */
686 bfd_elf_generic_reloc, /* special_function */
687 "R_PPC_PLT16_HA", /* name */
688 false, /* partial_inplace */
690 0xffff, /* dst_mask */
691 false), /* pcrel_offset */
693 /* A sign-extended 16 bit value relative to _SDA_BASE_, for use with
695 HOWTO (R_PPC_SDAREL16, /* type */
697 1, /* size (0 = byte, 1 = short, 2 = long) */
699 false, /* pc_relative */
701 complain_overflow_signed, /* complain_on_overflow */
702 bfd_elf_generic_reloc, /* special_function */
703 "R_PPC_SDAREL16", /* name */
704 false, /* partial_inplace */
706 0xffff, /* dst_mask */
707 false), /* pcrel_offset */
709 /* 32-bit section relative relocation. */
710 HOWTO (R_PPC_SECTOFF, /* type */
712 2, /* size (0 = byte, 1 = short, 2 = long) */
714 true, /* pc_relative */
716 complain_overflow_bitfield, /* complain_on_overflow */
717 bfd_elf_generic_reloc, /* special_function */
718 "R_PPC_SECTOFF", /* name */
719 false, /* partial_inplace */
722 true), /* pcrel_offset */
724 /* 16-bit lower half section relative relocation. */
725 HOWTO (R_PPC_SECTOFF_LO, /* type */
727 1, /* size (0 = byte, 1 = short, 2 = long) */
729 false, /* pc_relative */
731 complain_overflow_bitfield, /* complain_on_overflow */
732 bfd_elf_generic_reloc, /* special_function */
733 "R_PPC_SECTOFF_LO", /* name */
734 false, /* partial_inplace */
736 0xffff, /* dst_mask */
737 false), /* pcrel_offset */
739 /* 16-bit upper half section relative relocation. */
740 HOWTO (R_PPC_SECTOFF_HI, /* type */
742 1, /* size (0 = byte, 1 = short, 2 = long) */
744 false, /* pc_relative */
746 complain_overflow_bitfield, /* complain_on_overflow */
747 bfd_elf_generic_reloc, /* special_function */
748 "R_PPC_SECTOFF_HI", /* name */
749 false, /* partial_inplace */
751 0xffff, /* dst_mask */
752 false), /* pcrel_offset */
754 /* 16-bit upper half adjusted section relative relocation. */
755 HOWTO (R_PPC_SECTOFF_HA, /* type */
757 1, /* size (0 = byte, 1 = short, 2 = long) */
759 false, /* pc_relative */
761 complain_overflow_bitfield, /* complain_on_overflow */
762 bfd_elf_generic_reloc, /* special_function */
763 "R_PPC_SECTOFF_HA", /* name */
764 false, /* partial_inplace */
766 0xffff, /* dst_mask */
767 false), /* pcrel_offset */
769 /* The remaining relocs are from the Embedded ELF ABI, and are not
770 in the SVR4 ELF ABI. */
772 /* 32 bit value resulting from the addend minus the symbol */
773 HOWTO (R_PPC_EMB_NADDR32, /* type */
775 2, /* size (0 = byte, 1 = short, 2 = long) */
777 false, /* pc_relative */
779 complain_overflow_bitfield, /* complain_on_overflow */
780 bfd_elf_generic_reloc, /* special_function */
781 "R_PPC_EMB_NADDR32", /* name */
782 false, /* partial_inplace */
784 0xffffffff, /* dst_mask */
785 false), /* pcrel_offset */
787 /* 16 bit value resulting from the addend minus the symbol */
788 HOWTO (R_PPC_EMB_NADDR16, /* type */
790 1, /* size (0 = byte, 1 = short, 2 = long) */
792 false, /* pc_relative */
794 complain_overflow_bitfield, /* complain_on_overflow */
795 bfd_elf_generic_reloc, /* special_function */
796 "R_PPC_EMB_NADDR16", /* name */
797 false, /* partial_inplace */
799 0xffff, /* dst_mask */
800 false), /* pcrel_offset */
802 /* 16 bit value resulting from the addend minus the symbol */
803 HOWTO (R_PPC_EMB_NADDR16_LO, /* type */
805 1, /* size (0 = byte, 1 = short, 2 = long) */
807 false, /* pc_relative */
809 complain_overflow_dont,/* complain_on_overflow */
810 bfd_elf_generic_reloc, /* special_function */
811 "R_PPC_EMB_ADDR16_LO", /* name */
812 false, /* partial_inplace */
814 0xffff, /* dst_mask */
815 false), /* pcrel_offset */
817 /* The high order 16 bits of the addend minus the symbol */
818 HOWTO (R_PPC_EMB_NADDR16_HI, /* type */
820 1, /* size (0 = byte, 1 = short, 2 = long) */
822 false, /* pc_relative */
824 complain_overflow_dont, /* complain_on_overflow */
825 bfd_elf_generic_reloc, /* special_function */
826 "R_PPC_EMB_NADDR16_HI", /* name */
827 false, /* partial_inplace */
829 0xffff, /* dst_mask */
830 false), /* pcrel_offset */
832 /* The high order 16 bits of the result of the addend minus the address,
833 plus 1 if the contents of the low 16 bits, treated as a signed number,
835 HOWTO (R_PPC_EMB_NADDR16_HA, /* type */
837 1, /* size (0 = byte, 1 = short, 2 = long) */
839 false, /* pc_relative */
841 complain_overflow_dont, /* complain_on_overflow */
842 bfd_elf_generic_reloc, /* special_function */
843 "R_PPC_EMB_NADDR16_HA", /* name */
844 false, /* partial_inplace */
846 0xffff, /* dst_mask */
847 false), /* pcrel_offset */
849 /* 16 bit value resulting from allocating a 4 byte word to hold an
850 address in the .sdata section, and returning the offset from
851 _SDA_BASE_ for that relocation */
852 HOWTO (R_PPC_EMB_SDAI16, /* type */
854 1, /* size (0 = byte, 1 = short, 2 = long) */
856 false, /* pc_relative */
858 complain_overflow_bitfield, /* complain_on_overflow */
859 bfd_elf_generic_reloc, /* special_function */
860 "R_PPC_EMB_SDAI16", /* name */
861 false, /* partial_inplace */
863 0xffff, /* dst_mask */
864 false), /* pcrel_offset */
866 /* 16 bit value resulting from allocating a 4 byte word to hold an
867 address in the .sdata2 section, and returning the offset from
868 _SDA2_BASE_ for that relocation */
869 HOWTO (R_PPC_EMB_SDA2I16, /* type */
871 1, /* size (0 = byte, 1 = short, 2 = long) */
873 false, /* pc_relative */
875 complain_overflow_bitfield, /* complain_on_overflow */
876 bfd_elf_generic_reloc, /* special_function */
877 "R_PPC_EMB_SDA2I16", /* name */
878 false, /* partial_inplace */
880 0xffff, /* dst_mask */
881 false), /* pcrel_offset */
883 /* A sign-extended 16 bit value relative to _SDA2_BASE_, for use with
885 HOWTO (R_PPC_EMB_SDA2REL, /* type */
887 1, /* size (0 = byte, 1 = short, 2 = long) */
889 false, /* pc_relative */
891 complain_overflow_signed, /* complain_on_overflow */
892 bfd_elf_generic_reloc, /* special_function */
893 "R_PPC_EMB_SDA2REL", /* name */
894 false, /* partial_inplace */
896 0xffff, /* dst_mask */
897 false), /* pcrel_offset */
899 /* Relocate against either _SDA_BASE_ or _SDA2_BASE_, filling in the 16 bit
900 signed offset from the appropriate base, and filling in the register
901 field with the appropriate register (0, 2, or 13). */
902 HOWTO (R_PPC_EMB_SDA21, /* type */
904 2, /* size (0 = byte, 1 = short, 2 = long) */
906 false, /* pc_relative */
908 complain_overflow_signed, /* complain_on_overflow */
909 bfd_elf_generic_reloc, /* special_function */
910 "R_PPC_EMB_SDA21", /* name */
911 false, /* partial_inplace */
913 0xffff, /* dst_mask */
914 false), /* pcrel_offset */
916 /* Relocation not handled: R_PPC_EMB_MRKREF */
917 /* Relocation not handled: R_PPC_EMB_RELSEC16 */
918 /* Relocation not handled: R_PPC_EMB_RELST_LO */
919 /* Relocation not handled: R_PPC_EMB_RELST_HI */
920 /* Relocation not handled: R_PPC_EMB_RELST_HA */
921 /* Relocation not handled: R_PPC_EMB_BIT_FLD */
923 /* PC relative relocation against either _SDA_BASE_ or _SDA2_BASE_, filling
924 in the 16 bit signed offset from the appropriate base, and filling in the
925 register field with the appropriate register (0, 2, or 13). */
926 HOWTO (R_PPC_EMB_RELSDA, /* type */
928 1, /* size (0 = byte, 1 = short, 2 = long) */
930 true, /* pc_relative */
932 complain_overflow_signed, /* complain_on_overflow */
933 bfd_elf_generic_reloc, /* special_function */
934 "R_PPC_EMB_RELSDA", /* name */
935 false, /* partial_inplace */
937 0xffff, /* dst_mask */
938 false), /* pcrel_offset */
940 /* Phony reloc to handle AIX style TOC entries */
941 HOWTO (R_PPC_TOC16, /* type */
943 1, /* size (0 = byte, 1 = short, 2 = long) */
945 false, /* pc_relative */
947 complain_overflow_signed, /* complain_on_overflow */
948 bfd_elf_generic_reloc, /* special_function */
949 "R_PPC_TOC16", /* name */
950 false, /* partial_inplace */
952 0xffff, /* dst_mask */
953 false), /* pcrel_offset */
957 /* Initialize the ppc_elf_howto_table, so that linear accesses can be done. */
960 ppc_elf_howto_init ()
962 unsigned int i, type;
964 for (i = 0; i < sizeof (ppc_elf_howto_raw) / sizeof (ppc_elf_howto_raw[0]); i++)
966 type = ppc_elf_howto_raw[i].type;
967 BFD_ASSERT (type < sizeof(ppc_elf_howto_table) / sizeof(ppc_elf_howto_table[0]));
968 ppc_elf_howto_table[type] = &ppc_elf_howto_raw[i];
973 static reloc_howto_type *
974 ppc_elf_reloc_type_lookup (abfd, code)
976 bfd_reloc_code_real_type code;
978 enum ppc_reloc_type ppc_reloc = R_PPC_NONE;
980 if (!ppc_elf_howto_table[ R_PPC_ADDR32 ]) /* Initialize howto table if needed */
981 ppc_elf_howto_init ();
986 return (reloc_howto_type *)NULL;
988 case BFD_RELOC_NONE: ppc_reloc = R_PPC_NONE; break;
989 case BFD_RELOC_32: ppc_reloc = R_PPC_ADDR32; break;
990 case BFD_RELOC_PPC_BA26: ppc_reloc = R_PPC_ADDR24; break;
991 case BFD_RELOC_16: ppc_reloc = R_PPC_ADDR16; break;
992 case BFD_RELOC_LO16: ppc_reloc = R_PPC_ADDR16_LO; break;
993 case BFD_RELOC_HI16: ppc_reloc = R_PPC_ADDR16_HI; break;
994 case BFD_RELOC_HI16_S: ppc_reloc = R_PPC_ADDR16_HA; break;
995 case BFD_RELOC_PPC_BA16: ppc_reloc = R_PPC_ADDR14; break;
996 case BFD_RELOC_PPC_BA16_BRTAKEN: ppc_reloc = R_PPC_ADDR14_BRTAKEN; break;
997 case BFD_RELOC_PPC_BA16_BRNTAKEN: ppc_reloc = R_PPC_ADDR14_BRNTAKEN; break;
998 case BFD_RELOC_PPC_B26: ppc_reloc = R_PPC_REL24; break;
999 case BFD_RELOC_PPC_B16: ppc_reloc = R_PPC_REL14; break;
1000 case BFD_RELOC_PPC_B16_BRTAKEN: ppc_reloc = R_PPC_REL14_BRTAKEN; break;
1001 case BFD_RELOC_PPC_B16_BRNTAKEN: ppc_reloc = R_PPC_REL14_BRNTAKEN; break;
1002 case BFD_RELOC_16_GOTOFF: ppc_reloc = R_PPC_GOT16; break;
1003 case BFD_RELOC_LO16_GOTOFF: ppc_reloc = R_PPC_GOT16_LO; break;
1004 case BFD_RELOC_HI16_GOTOFF: ppc_reloc = R_PPC_GOT16_HI; break;
1005 case BFD_RELOC_HI16_S_GOTOFF: ppc_reloc = R_PPC_GOT16_HA; break;
1006 case BFD_RELOC_24_PLT_PCREL: ppc_reloc = R_PPC_PLTREL24; break;
1007 case BFD_RELOC_PPC_COPY: ppc_reloc = R_PPC_COPY; break;
1008 case BFD_RELOC_PPC_GLOB_DAT: ppc_reloc = R_PPC_GLOB_DAT; break;
1009 case BFD_RELOC_PPC_LOCAL24PC: ppc_reloc = R_PPC_LOCAL24PC; break;
1010 case BFD_RELOC_32_PCREL: ppc_reloc = R_PPC_REL32; break;
1011 case BFD_RELOC_32_PLTOFF: ppc_reloc = R_PPC_PLT32; break;
1012 case BFD_RELOC_32_PLT_PCREL: ppc_reloc = R_PPC_PLTREL32; break;
1013 case BFD_RELOC_LO16_PLTOFF: ppc_reloc = R_PPC_PLT16_LO; break;
1014 case BFD_RELOC_HI16_PLTOFF: ppc_reloc = R_PPC_PLT16_HI; break;
1015 case BFD_RELOC_HI16_S_PLTOFF: ppc_reloc = R_PPC_PLT16_HA; break;
1016 case BFD_RELOC_GPREL16: ppc_reloc = R_PPC_SDAREL16; break;
1017 case BFD_RELOC_32_BASEREL: ppc_reloc = R_PPC_SECTOFF; break;
1018 case BFD_RELOC_LO16_BASEREL: ppc_reloc = R_PPC_SECTOFF_LO; break;
1019 case BFD_RELOC_HI16_BASEREL: ppc_reloc = R_PPC_SECTOFF_HI; break;
1020 case BFD_RELOC_HI16_S_BASEREL: ppc_reloc = R_PPC_SECTOFF_HA; break;
1021 case BFD_RELOC_CTOR: ppc_reloc = R_PPC_ADDR32; break;
1022 case BFD_RELOC_PPC_TOC16: ppc_reloc = R_PPC_TOC16; break;
1023 case BFD_RELOC_PPC_EMB_NADDR32: ppc_reloc = R_PPC_EMB_NADDR32; break;
1024 case BFD_RELOC_PPC_EMB_NADDR16: ppc_reloc = R_PPC_EMB_NADDR16; break;
1025 case BFD_RELOC_PPC_EMB_NADDR16_LO: ppc_reloc = R_PPC_EMB_NADDR16_LO; break;
1026 case BFD_RELOC_PPC_EMB_NADDR16_HI: ppc_reloc = R_PPC_EMB_NADDR16_HI; break;
1027 case BFD_RELOC_PPC_EMB_NADDR16_HA: ppc_reloc = R_PPC_EMB_NADDR16_HA; break;
1028 case BFD_RELOC_PPC_EMB_SDAI16: ppc_reloc = R_PPC_EMB_SDAI16; break;
1029 case BFD_RELOC_PPC_EMB_SDA2I16: ppc_reloc = R_PPC_EMB_SDA2I16; break;
1030 case BFD_RELOC_PPC_EMB_SDA2REL: ppc_reloc = R_PPC_EMB_SDA2REL; break;
1031 case BFD_RELOC_PPC_EMB_SDA21: ppc_reloc = R_PPC_EMB_SDA21; break;
1032 case BFD_RELOC_PPC_EMB_MRKREF: ppc_reloc = R_PPC_EMB_MRKREF; break;
1033 case BFD_RELOC_PPC_EMB_RELSEC16: ppc_reloc = R_PPC_EMB_RELSEC16; break;
1034 case BFD_RELOC_PPC_EMB_RELST_LO: ppc_reloc = R_PPC_EMB_RELST_LO; break;
1035 case BFD_RELOC_PPC_EMB_RELST_HI: ppc_reloc = R_PPC_EMB_RELST_HI; break;
1036 case BFD_RELOC_PPC_EMB_RELST_HA: ppc_reloc = R_PPC_EMB_RELST_HA; break;
1037 case BFD_RELOC_PPC_EMB_BIT_FLD: ppc_reloc = R_PPC_EMB_BIT_FLD; break;
1038 case BFD_RELOC_PPC_EMB_RELSDA: ppc_reloc = R_PPC_EMB_RELSDA; break;
1041 return ppc_elf_howto_table[ (int)ppc_reloc ];
1044 /* Set the howto pointer for a PowerPC ELF reloc. */
1047 ppc_elf_info_to_howto (abfd, cache_ptr, dst)
1050 Elf32_Internal_Rela *dst;
1052 if (!ppc_elf_howto_table[ R_PPC_ADDR32 ]) /* Initialize howto table if needed */
1053 ppc_elf_howto_init ();
1055 BFD_ASSERT (ELF32_R_TYPE (dst->r_info) < (unsigned int) R_PPC_max);
1056 cache_ptr->howto = ppc_elf_howto_table[ELF32_R_TYPE (dst->r_info)];
1059 /* Handle the R_PPC_ADDR16_HA reloc. */
1061 static bfd_reloc_status_type
1062 ppc_elf_addr16_ha_reloc (abfd, reloc_entry, symbol, data, input_section,
1063 output_bfd, error_message)
1065 arelent *reloc_entry;
1068 asection *input_section;
1070 char **error_message;
1074 if (output_bfd != NULL)
1076 reloc_entry->address += input_section->output_offset;
1077 return bfd_reloc_ok;
1080 if (reloc_entry->address > input_section->_cooked_size)
1081 return bfd_reloc_outofrange;
1083 if (bfd_is_com_section (symbol->section))
1086 relocation = symbol->value;
1088 relocation += symbol->section->output_section->vma;
1089 relocation += symbol->section->output_offset;
1090 relocation += reloc_entry->addend;
1092 reloc_entry->addend += (relocation & 0x8000) << 1;
1094 return bfd_reloc_continue;
1097 /* Function to set whether a module needs the -mrelocatable bit set. */
1100 ppc_elf_set_private_flags (abfd, flags)
1104 BFD_ASSERT (!elf_flags_init (abfd)
1105 || elf_elfheader (abfd)->e_flags == flags);
1107 elf_elfheader (abfd)->e_flags = flags;
1108 elf_flags_init (abfd) = true;
1112 /* Copy backend specific data from one object module to another */
1114 ppc_elf_copy_private_bfd_data (ibfd, obfd)
1118 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
1119 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
1122 BFD_ASSERT (!elf_flags_init (obfd)
1123 || elf_elfheader (obfd)->e_flags == elf_elfheader (ibfd)->e_flags);
1125 elf_elfheader (obfd)->e_flags = elf_elfheader (ibfd)->e_flags;
1126 elf_flags_init (obfd) = true;
1130 /* Merge backend specific data from an object file to the output
1131 object file when linking */
1133 ppc_elf_merge_private_bfd_data (ibfd, obfd)
1141 /* Check if we have the same endianess */
1142 if (ibfd->xvec->byteorder != obfd->xvec->byteorder
1143 && obfd->xvec->byteorder != BFD_ENDIAN_UNKNOWN)
1145 (*_bfd_error_handler)
1146 ("%s: compiled for a %s endian system and target is %s endian",
1147 bfd_get_filename (ibfd),
1148 bfd_big_endian (ibfd) ? "big" : "little",
1149 bfd_big_endian (obfd) ? "big" : "little");
1151 bfd_set_error (bfd_error_wrong_format);
1155 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
1156 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
1159 new_flags = elf_elfheader (ibfd)->e_flags;
1160 old_flags = elf_elfheader (obfd)->e_flags;
1161 if (!elf_flags_init (obfd)) /* First call, no flags set */
1163 elf_flags_init (obfd) = true;
1164 elf_elfheader (obfd)->e_flags = new_flags;
1167 else if (new_flags == old_flags) /* Compatible flags are ok */
1170 else /* Incompatible flags */
1172 /* Warn about -mrelocatable mismatch. Allow -mrelocatable-lib to be linked
1175 if ((new_flags & EF_PPC_RELOCATABLE) != 0
1176 && (old_flags & (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB)) == 0)
1179 (*_bfd_error_handler)
1180 ("%s: compiled with -mrelocatable and linked with modules compiled normally",
1181 bfd_get_filename (ibfd));
1183 else if ((new_flags & (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB)) == 0
1184 && (old_flags & EF_PPC_RELOCATABLE) != 0)
1187 (*_bfd_error_handler)
1188 ("%s: compiled normally and linked with modules compiled with -mrelocatable",
1189 bfd_get_filename (ibfd));
1191 /* If -mrelocatable-lib is linked with an object without -mrelocatable-lib, turn off
1192 the -mrelocatable-lib, since at least one module isn't relocatable. */
1193 else if ((old_flags & EF_PPC_RELOCATABLE_LIB) != 0
1194 && (new_flags & EF_PPC_RELOCATABLE_LIB) == 0)
1195 elf_elfheader (obfd)->e_flags &= ~EF_PPC_RELOCATABLE_LIB;
1198 /* Do not warn about eabi vs. V.4 mismatch, just or in the bit if any module uses it */
1199 elf_elfheader (obfd)->e_flags |= (new_flags & EF_PPC_EMB);
1201 new_flags &= ~ (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB | EF_PPC_EMB);
1202 old_flags &= ~ (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB | EF_PPC_EMB);
1204 /* Warn about any other mismatches */
1205 if (new_flags != old_flags)
1208 (*_bfd_error_handler)
1209 ("%s: uses different e_flags (0x%lx) fields than previous modules (0x%lx)",
1210 bfd_get_filename (ibfd), (long)new_flags, (long)old_flags);
1215 bfd_set_error (bfd_error_bad_value);
1224 /* Handle a PowerPC specific section when reading an object file. This
1225 is called when elfcode.h finds a section with an unknown type. */
1228 ppc_elf_section_from_shdr (abfd, hdr, name)
1230 Elf32_Internal_Shdr *hdr;
1236 if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name))
1239 newsect = hdr->bfd_section;
1240 flags = bfd_get_section_flags (abfd, newsect);
1241 if (hdr->sh_flags & SHF_EXCLUDE)
1242 flags |= SEC_EXCLUDE;
1244 if (hdr->sh_type == SHT_ORDERED)
1245 flags |= SEC_SORT_ENTRIES;
1247 bfd_set_section_flags (abfd, newsect, flags);
1252 /* Set up any other section flags and such that may be necessary. */
1255 ppc_elf_fake_sections (abfd, shdr, asect)
1257 Elf32_Internal_Shdr *shdr;
1260 if ((asect->flags & SEC_EXCLUDE) != 0)
1261 shdr->sh_flags |= SHF_EXCLUDE;
1263 if ((asect->flags & SEC_SORT_ENTRIES) != 0)
1264 shdr->sh_type = SHT_ORDERED;
1270 /* Create a special linker section */
1271 static elf_linker_section_t *
1272 ppc_elf_create_linker_section (abfd, info, which)
1274 struct bfd_link_info *info;
1275 enum elf_linker_section_enum which;
1277 bfd *dynobj = elf_hash_table (info)->dynobj;
1278 elf_linker_section_t *lsect;
1280 /* Record the first bfd section that needs the special section */
1282 dynobj = elf_hash_table (info)->dynobj = abfd;
1284 /* If this is the first time, create the section */
1285 lsect = elf_linker_section (dynobj, which);
1288 elf_linker_section_t defaults;
1289 static elf_linker_section_t zero_section;
1291 defaults = zero_section;
1292 defaults.which = which;
1293 defaults.hole_written_p = false;
1294 defaults.alignment = 2;
1295 defaults.flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS
1296 | SEC_IN_MEMORY | SEC_LINKER_CREATED);
1301 (*_bfd_error_handler) ("%s: Unknown special linker type %d",
1302 bfd_get_filename (abfd),
1305 bfd_set_error (bfd_error_bad_value);
1306 return (elf_linker_section_t *)0;
1308 case LINKER_SECTION_SDATA: /* .sdata/.sbss section */
1309 defaults.name = ".sdata";
1310 defaults.rel_name = ".rela.sdata";
1311 defaults.bss_name = ".sbss";
1312 defaults.sym_name = "_SDA_BASE_";
1313 defaults.sym_offset = 32768;
1316 case LINKER_SECTION_SDATA2: /* .sdata2/.sbss2 section */
1317 defaults.name = ".sdata2";
1318 defaults.rel_name = ".rela.sdata2";
1319 defaults.bss_name = ".sbss2";
1320 defaults.sym_name = "_SDA2_BASE_";
1321 defaults.sym_offset = 32768;
1322 defaults.flags |= SEC_READONLY;
1326 lsect = _bfd_elf_create_linker_section (abfd, info, which, &defaults);
1333 /* If we have a non-zero sized .sbss2 or .PPC.EMB.sbss0 sections, we need to bump up
1334 the number of section headers. */
1337 ppc_elf_additional_program_headers (abfd)
1345 s = bfd_get_section_by_name (abfd, ".interp");
1349 s = bfd_get_section_by_name (abfd, ".sbss2");
1350 if (s != NULL && (s->flags & SEC_LOAD) != 0 && s->_raw_size > 0)
1353 s = bfd_get_section_by_name (abfd, ".PPC.EMB.sbss0");
1354 if (s != NULL && (s->flags & SEC_LOAD) != 0 && s->_raw_size > 0)
1360 /* Modify the segment map if needed */
1363 ppc_elf_modify_segment_map (abfd)
1369 /* Adjust a symbol defined by a dynamic object and referenced by a
1370 regular object. The current definition is in some section of the
1371 dynamic object, but we're not including those sections. We have to
1372 change the definition to something the rest of the link can
1376 ppc_elf_adjust_dynamic_symbol (info, h)
1377 struct bfd_link_info *info;
1378 struct elf_link_hash_entry *h;
1380 bfd *dynobj = elf_hash_table (info)->dynobj;
1382 unsigned int power_of_two;
1386 fprintf (stderr, "ppc_elf_adjust_dynamic_symbol called for %s\n", h->root.root.string);
1389 /* Make sure we know what is going on here. */
1390 BFD_ASSERT (dynobj != NULL
1391 && ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT)
1392 || h->weakdef != NULL
1393 || ((h->elf_link_hash_flags
1394 & ELF_LINK_HASH_DEF_DYNAMIC) != 0
1395 && (h->elf_link_hash_flags
1396 & ELF_LINK_HASH_REF_REGULAR) != 0
1397 && (h->elf_link_hash_flags
1398 & ELF_LINK_HASH_DEF_REGULAR) == 0)));
1401 /* If this is a function, put it in the procedure linkage table. We
1402 will fill in the contents of the procedure linkage table later,
1403 when we know the address of the .got section. */
1404 if (h->type == STT_FUNC
1405 || (h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0)
1408 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) == 0
1409 && (h->elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) == 0)
1411 /* This case can occur if we saw a PLT32 reloc in an input
1412 file, but the symbol was never referred to by a dynamic
1413 object. In such a case, we don't actually need to build
1414 a procedure linkage table, and we can just do a PC32
1416 BFD_ASSERT ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0);
1420 /* Make sure this symbol is output as a dynamic symbol. */
1421 if (h->dynindx == -1)
1423 if (! bfd_elf32_link_record_dynamic_symbol (info, h))
1427 s = bfd_get_section_by_name (dynobj, ".plt");
1428 BFD_ASSERT (s != NULL);
1430 /* If this is the first .plt entry, make room for the special
1432 if (s->_raw_size == 0)
1433 s->_raw_size += PLT_INITIAL_ENTRY_SIZE;
1435 /* The PowerPC PLT is actually composed of two parts, the first part
1436 is 2 words (for a load and a jump), and then there is a remaining
1437 word available at the end. */
1438 plt_offset = (PLT_INITIAL_ENTRY_SIZE
1439 + 8 * ((s->_raw_size - PLT_INITIAL_ENTRY_SIZE) / PLT_ENTRY_SIZE));
1441 /* If this symbol is not defined in a regular file, and we are
1442 not generating a shared library, then set the symbol to this
1443 location in the .plt. This is required to make function
1444 pointers compare as equal between the normal executable and
1445 the shared library. */
1447 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
1449 h->root.u.def.section = s;
1450 h->root.u.def.value = plt_offset;
1453 h->plt_offset = plt_offset;
1455 /* Make room for this entry. */
1456 s->_raw_size += PLT_ENTRY_SIZE;
1458 /* We also need to make an entry in the .rela.plt section. */
1459 s = bfd_get_section_by_name (dynobj, ".rela.plt");
1460 BFD_ASSERT (s != NULL);
1461 s->_raw_size += sizeof (Elf32_External_Rela);
1466 /* If this is a weak symbol, and there is a real definition, the
1467 processor independent code will have arranged for us to see the
1468 real definition first, and we can just use the same value. */
1469 if (h->weakdef != NULL)
1471 BFD_ASSERT (h->weakdef->root.type == bfd_link_hash_defined
1472 || h->weakdef->root.type == bfd_link_hash_defweak);
1473 h->root.u.def.section = h->weakdef->root.u.def.section;
1474 h->root.u.def.value = h->weakdef->root.u.def.value;
1478 /* This is a reference to a symbol defined by a dynamic object which
1479 is not a function. */
1481 /* If we are creating a shared library, we must presume that the
1482 only references to the symbol are via the global offset table.
1483 For such cases we need not do anything here; the relocations will
1484 be handled correctly by relocate_section. */
1488 /* We must allocate the symbol in our .dynbss section, which will
1489 become part of the .bss section of the executable. There will be
1490 an entry for this symbol in the .dynsym section. The dynamic
1491 object will contain position independent code, so all references
1492 from the dynamic object to this symbol will go through the global
1493 offset table. The dynamic linker will use the .dynsym entry to
1494 determine the address it must put in the global offset table, so
1495 both the dynamic object and the regular object will refer to the
1496 same memory location for the variable. */
1498 s = bfd_get_section_by_name (dynobj, ".dynbss");
1499 BFD_ASSERT (s != NULL);
1501 /* We must generate a R_PPC_COPY reloc to tell the dynamic linker to
1502 copy the initial value out of the dynamic object and into the
1503 runtime process image. We need to remember the offset into the
1504 .rela.bss section we are going to use. */
1505 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
1509 srel = bfd_get_section_by_name (dynobj, ".rela.bss");
1510 BFD_ASSERT (srel != NULL);
1511 srel->_raw_size += sizeof (Elf32_External_Rela);
1512 h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_COPY;
1515 /* We need to figure out the alignment required for this symbol. I
1516 have no idea how ELF linkers handle this. */
1517 power_of_two = bfd_log2 (h->size);
1518 if (power_of_two > 3)
1521 /* Apply the required alignment. */
1522 s->_raw_size = BFD_ALIGN (s->_raw_size,
1523 (bfd_size_type) (1 << power_of_two));
1524 if (power_of_two > bfd_get_section_alignment (dynobj, s))
1526 if (! bfd_set_section_alignment (dynobj, s, power_of_two))
1530 /* Define the symbol as being at this point in the section. */
1531 h->root.u.def.section = s;
1532 h->root.u.def.value = s->_raw_size;
1534 /* Increment the section size to make room for the symbol. */
1535 s->_raw_size += h->size;
1541 /* Increment the index of a dynamic symbol by a given amount. Called
1542 via elf_link_hash_traverse. */
1545 ppc_elf_adjust_dynindx (h, cparg)
1546 struct elf_link_hash_entry *h;
1549 int *cp = (int *) cparg;
1552 fprintf (stderr, "ppc_elf_adjust_dynindx called, h->dynindx = %d, *cp = %d\n", h->dynindx, *cp);
1555 if (h->dynindx != -1)
1562 /* Set the sizes of the dynamic sections. */
1565 ppc_elf_size_dynamic_sections (output_bfd, info)
1567 struct bfd_link_info *info;
1576 fprintf (stderr, "ppc_elf_size_dynamic_sections called\n");
1579 dynobj = elf_hash_table (info)->dynobj;
1580 BFD_ASSERT (dynobj != NULL);
1582 if (elf_hash_table (info)->dynamic_sections_created)
1584 /* Set the contents of the .interp section to the interpreter. */
1587 s = bfd_get_section_by_name (dynobj, ".interp");
1588 BFD_ASSERT (s != NULL);
1589 s->_raw_size = sizeof ELF_DYNAMIC_INTERPRETER;
1590 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
1595 /* We may have created entries in the .rela.got, .rela.sdata, and
1596 .rela.sdata2 sections. However, if we are not creating the
1597 dynamic sections, we will not actually use these entries. Reset
1598 the size of .rela.got, et al, which will cause it to get
1599 stripped from the output file below. */
1600 static char *rela_sections[] = { ".rela.got", ".rela.sdata", ".rela.sdata", (char *)0 };
1603 for (p = rela_sections; *p != (char *)0; p++)
1605 s = bfd_get_section_by_name (dynobj, *p);
1611 /* The check_relocs and adjust_dynamic_symbol entry points have
1612 determined the sizes of the various dynamic sections. Allocate
1617 for (s = dynobj->sections; s != NULL; s = s->next)
1622 if ((s->flags & SEC_LINKER_CREATED) == 0)
1625 /* It's OK to base decisions on the section name, because none
1626 of the dynobj section names depend upon the input files. */
1627 name = bfd_get_section_name (dynobj, s);
1631 if (strcmp (name, ".plt") == 0)
1633 if (s->_raw_size == 0)
1635 /* Strip this section if we don't need it; see the
1641 /* Remember whether there is a PLT. */
1645 else if (strncmp (name, ".rela", 5) == 0)
1647 if (s->_raw_size == 0)
1649 /* If we don't need this section, strip it from the
1650 output file. This is mostly to handle .rela.bss and
1651 .rela.plt. We must create both sections in
1652 create_dynamic_sections, because they must be created
1653 before the linker maps input sections to output
1654 sections. The linker does that before
1655 adjust_dynamic_symbol is called, and it is that
1656 function which decides whether anything needs to go
1657 into these sections. */
1663 const char *outname;
1665 /* Remember whether there are any relocation sections. */
1668 /* If this relocation section applies to a read only
1669 section, then we probably need a DT_TEXTREL entry. */
1670 outname = bfd_get_section_name (output_bfd,
1672 target = bfd_get_section_by_name (output_bfd, outname + 5);
1674 && (target->flags & SEC_READONLY) != 0)
1677 /* We use the reloc_count field as a counter if we need
1678 to copy relocs into the output file. */
1682 else if (strcmp (name, ".got") != 0
1683 && strcmp (name, ".sdata") != 0
1684 && strcmp (name, ".sdata2") != 0)
1686 /* It's not one of our sections, so don't allocate space. */
1694 for (spp = &s->output_section->owner->sections;
1695 *spp != s->output_section;
1696 spp = &(*spp)->next)
1698 *spp = s->output_section->next;
1699 --s->output_section->owner->section_count;
1704 /* Allocate memory for the section contents. */
1705 s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->_raw_size);
1706 if (s->contents == NULL && s->_raw_size != 0)
1710 if (elf_hash_table (info)->dynamic_sections_created)
1712 /* Add some entries to the .dynamic section. We fill in the
1713 values later, in ppc_elf_finish_dynamic_sections, but we
1714 must add the entries now so that we get the correct size for
1715 the .dynamic section. The DT_DEBUG entry is filled in by the
1716 dynamic linker and used by the debugger. */
1719 if (! bfd_elf32_add_dynamic_entry (info, DT_DEBUG, 0))
1725 if (! bfd_elf32_add_dynamic_entry (info, DT_PLTGOT, 0)
1726 || ! bfd_elf32_add_dynamic_entry (info, DT_PLTRELSZ, 0)
1727 || ! bfd_elf32_add_dynamic_entry (info, DT_PLTREL, DT_RELA)
1728 || ! bfd_elf32_add_dynamic_entry (info, DT_JMPREL, 0))
1734 if (! bfd_elf32_add_dynamic_entry (info, DT_RELA, 0)
1735 || ! bfd_elf32_add_dynamic_entry (info, DT_RELASZ, 0)
1736 || ! bfd_elf32_add_dynamic_entry (info, DT_RELAENT,
1737 sizeof (Elf32_External_Rela)))
1743 if (! bfd_elf32_add_dynamic_entry (info, DT_TEXTREL, 0))
1748 /* If we are generating a shared library, we generate a section
1749 symbol for each output section. These are local symbols, which
1750 means that they must come first in the dynamic symbol table.
1751 That means we must increment the dynamic symbol index of every
1752 other dynamic symbol.
1754 FIXME: We assume that there will never be relocations to
1755 locations in linker-created sections that do not have
1756 externally-visible names. Instead, we should work out precisely
1757 which sections relocations are targetted at. */
1762 for (c = 0, s = output_bfd->sections; s != NULL; s = s->next)
1764 if ((s->flags & SEC_LINKER_CREATED) != 0)
1769 elf_link_hash_traverse (elf_hash_table (info),
1770 ppc_elf_adjust_dynindx,
1772 elf_hash_table (info)->dynsymcount += c;
1774 for (i = 1, s = output_bfd->sections; s != NULL; s = s->next)
1776 if ((s->flags & SEC_LINKER_CREATED) != 0)
1777 elf_section_data (s)->dynindx = -1;
1780 elf_section_data (s)->dynindx = i;
1781 /* These symbols will have no names, so we don't need to
1782 fiddle with dynstr_index. */
1787 BFD_ASSERT(i == c + 1);
1794 /* Look through the relocs for a section during the first phase, and
1795 allocate space in the global offset table or procedure linkage
1799 ppc_elf_check_relocs (abfd, info, sec, relocs)
1801 struct bfd_link_info *info;
1803 const Elf_Internal_Rela *relocs;
1807 Elf_Internal_Shdr *symtab_hdr;
1808 struct elf_link_hash_entry **sym_hashes;
1809 const Elf_Internal_Rela *rel;
1810 const Elf_Internal_Rela *rel_end;
1811 bfd_vma *local_got_offsets;
1812 elf_linker_section_t *sdata;
1813 elf_linker_section_t *sdata2;
1816 asection *srelgot = NULL;
1818 if (info->relocateable)
1822 fprintf (stderr, "ppc_elf_check_relocs called for section %s in %s\n",
1823 bfd_get_section_name (abfd, sec),
1824 bfd_get_filename (abfd));
1827 /* Create the linker generated sections all the time so that the
1828 special symbols are created. */
1830 if ((sdata = elf_linker_section (abfd, LINKER_SECTION_SDATA)) == NULL)
1832 sdata = ppc_elf_create_linker_section (abfd, info, LINKER_SECTION_SDATA);
1838 if ((sdata2 = elf_linker_section (abfd, LINKER_SECTION_SDATA2)) == NULL)
1840 sdata2 = ppc_elf_create_linker_section (abfd, info, LINKER_SECTION_SDATA2);
1845 dynobj = elf_hash_table (info)->dynobj;
1846 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
1847 sym_hashes = elf_sym_hashes (abfd);
1848 local_got_offsets = elf_local_got_offsets (abfd);
1850 /* FIXME: We should only create the .got section if we need it.
1851 Otherwise we waste space in a statically linked executable. */
1853 if (! _bfd_elf_create_got_section (dynobj, info))
1855 sgot = bfd_get_section_by_name (dynobj, ".got");
1856 BFD_ASSERT (sgot != NULL);
1860 rel_end = relocs + sec->reloc_count;
1861 for (rel = relocs; rel < rel_end; rel++)
1863 unsigned long r_symndx;
1864 struct elf_link_hash_entry *h;
1866 r_symndx = ELF32_R_SYM (rel->r_info);
1867 if (r_symndx < symtab_hdr->sh_info)
1870 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
1872 switch (ELF32_R_TYPE (rel->r_info))
1874 /* GOT16 relocations */
1876 case R_PPC_GOT16_LO:
1877 case R_PPC_GOT16_HI:
1878 case R_PPC_GOT16_HA:
1880 && (h != NULL || info->shared))
1882 srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
1883 if (srelgot == NULL)
1885 srelgot = bfd_make_section (dynobj, ".rela.got");
1887 || ! bfd_set_section_flags (dynobj, srelgot,
1892 | SEC_LINKER_CREATED
1894 || ! bfd_set_section_alignment (dynobj, srelgot, 2))
1901 if (h->got_offset != (bfd_vma) -1)
1903 /* We have already allocated space in the .got. */
1906 h->got_offset = sgot->_raw_size;
1908 /* Make sure this symbol is output as a dynamic symbol. */
1909 if (h->dynindx == -1)
1911 if (! bfd_elf32_link_record_dynamic_symbol (info, h))
1915 srelgot->_raw_size += sizeof (Elf32_External_Rela);
1919 /* This is a global offset table entry for a local
1921 if (local_got_offsets == NULL)
1924 register unsigned int i;
1926 size = symtab_hdr->sh_info * sizeof (bfd_vma);
1927 local_got_offsets = (bfd_vma *) bfd_alloc (abfd, size);
1928 if (local_got_offsets == NULL)
1930 elf_local_got_offsets (abfd) = local_got_offsets;
1931 for (i = 0; i < symtab_hdr->sh_info; i++)
1932 local_got_offsets[i] = (bfd_vma) -1;
1934 if (local_got_offsets[r_symndx] != (bfd_vma) -1)
1936 /* We have already allocated space in the .got. */
1939 local_got_offsets[r_symndx] = sgot->_raw_size;
1943 /* If we are generating a shared object, we need to
1944 output a R_PPC_RELATIVE reloc so that the
1945 dynamic linker can adjust this GOT entry. */
1946 srelgot->_raw_size += sizeof (Elf32_External_Rela);
1950 sgot->_raw_size += 4;
1954 /* Indirect .sdata relocation */
1955 case R_PPC_EMB_SDAI16:
1958 (*_bfd_error_handler) ("%s: relocation %s cannot be used when making a shared object",
1959 bfd_get_filename (abfd),
1960 "R_PPC_EMB_SDAI16");
1966 && (h != NULL || info->shared))
1968 srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
1969 if (srelgot == NULL)
1971 srelgot = bfd_make_section (dynobj, ".rela.got");
1973 || ! bfd_set_section_flags (dynobj, srelgot,
1978 | SEC_LINKER_CREATED
1980 || ! bfd_set_section_alignment (dynobj, srelgot, 2))
1985 if (!bfd_elf32_create_pointer_linker_section (abfd, info, sdata, h, rel))
1990 /* Indirect .sdata2 relocation */
1991 case R_PPC_EMB_SDA2I16:
1994 (*_bfd_error_handler) ("%s: relocation %s cannot be used when making a shared object",
1995 bfd_get_filename (abfd),
1996 "R_PPC_EMB_SDA2I16");
2002 && (h != NULL || info->shared))
2004 srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
2005 if (srelgot == NULL)
2007 srelgot = bfd_make_section (dynobj, ".rela.got");
2009 || ! bfd_set_section_flags (dynobj, srelgot,
2014 | SEC_LINKER_CREATED
2016 || ! bfd_set_section_alignment (dynobj, srelgot, 2))
2021 if (!bfd_elf32_create_pointer_linker_section (abfd, info, sdata2, h, rel))
2026 case R_PPC_SDAREL16:
2027 case R_PPC_EMB_SDA2REL:
2028 case R_PPC_EMB_SDA21:
2031 (*_bfd_error_handler) ("%s: relocation %s cannot be used when making a shared object",
2032 bfd_get_filename (abfd),
2033 ppc_elf_howto_table[(int)ELF32_R_TYPE (rel->r_info)]->name);
2039 case R_PPC_PLTREL24:
2040 case R_PPC_PLT16_LO:
2041 case R_PPC_PLT16_HI:
2042 case R_PPC_PLT16_HA:
2044 fprintf (stderr, "Reloc requires a PLT entry\n");
2046 /* This symbol requires a procedure linkage table entry. We
2047 actually build the entry in adjust_dynamic_symbol,
2048 because this might be a case of linking PIC code without
2049 linking in any dynamic objects, in which case we don't
2050 need to generate a procedure linkage table after all. */
2054 /* It does not make sense to have a procedure linkage
2055 table entry for a local symbol. */
2056 bfd_set_error (bfd_error_bad_value);
2061 /* Make sure this symbol is output as a dynamic symbol. */
2062 if (h->dynindx == -1)
2064 if (! bfd_elf32_link_record_dynamic_symbol (info, h))
2071 h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
2074 /* The following relocations don't need to propagate the
2075 relocation if linking a shared object since they are
2076 section relative. */
2078 case R_PPC_SECTOFF_LO:
2079 case R_PPC_SECTOFF_HI:
2080 case R_PPC_SECTOFF_HA:
2083 /* This refers only to functions defined in the shared library */
2084 case R_PPC_LOCAL24PC:
2087 /* When creating a shared object, we must copy these
2088 relocs into the output file. We create a reloc
2089 section in dynobj and make room for the reloc. */
2092 && strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
2097 case R_PPC_REL14_BRTAKEN:
2098 case R_PPC_REL14_BRNTAKEN:
2107 fprintf (stderr, "ppc_elf_check_relocs need to create relocation for %s\n",
2108 (h && h->root.root.string) ? h->root.root.string : "<unknown>");
2114 name = (bfd_elf_string_from_elf_section
2116 elf_elfheader (abfd)->e_shstrndx,
2117 elf_section_data (sec)->rel_hdr.sh_name));
2124 BFD_ASSERT (strncmp (name, ".rela", 5) == 0
2125 && strcmp (bfd_get_section_name (abfd, sec),
2128 sreloc = bfd_get_section_by_name (dynobj, name);
2131 sreloc = bfd_make_section (dynobj, name);
2133 || ! bfd_set_section_flags (dynobj, sreloc,
2138 | SEC_LINKER_CREATED
2140 || ! bfd_set_section_alignment (dynobj, sreloc, 2))
2148 sreloc->_raw_size += sizeof (Elf32_External_Rela);
2159 /* Hook called by the linker routine which adds symbols from an object
2160 file. We use it to put .comm items in .sbss, and not .bss. */
2164 ppc_elf_add_symbol_hook (abfd, info, sym, namep, flagsp, secp, valp)
2166 struct bfd_link_info *info;
2167 const Elf_Internal_Sym *sym;
2173 if (sym->st_shndx == SHN_COMMON && !info->relocateable && sym->st_size <= bfd_get_gp_size (abfd))
2175 /* Common symbols less than or equal to -G nn bytes are automatically
2177 elf_linker_section_t *sdata = ppc_elf_create_linker_section (abfd, info, LINKER_SECTION_SDATA);
2178 if (!sdata->bss_section)
2180 /* We don't go through bfd_make_section, because we don't
2181 want to attach this common section to DYNOBJ. The linker
2182 will move the symbols to the appropriate output section
2183 when it defines common symbols. */
2184 sdata->bss_section = ((asection *)
2185 bfd_zalloc (abfd, sizeof (asection)));
2186 if (sdata->bss_section == NULL)
2188 sdata->bss_section->name = sdata->bss_name;
2189 sdata->bss_section->flags = SEC_IS_COMMON;
2190 sdata->bss_section->output_section = sdata->bss_section;
2191 sdata->bss_section->symbol =
2192 (asymbol *) bfd_zalloc (abfd, sizeof (asymbol));
2193 sdata->bss_section->symbol_ptr_ptr =
2194 (asymbol **) bfd_zalloc (abfd, sizeof (asymbol *));
2195 if (sdata->bss_section->symbol == NULL
2196 || sdata->bss_section->symbol_ptr_ptr == NULL)
2198 sdata->bss_section->symbol->name = sdata->bss_name;
2199 sdata->bss_section->symbol->flags = BSF_SECTION_SYM;
2200 sdata->bss_section->symbol->section = sdata->bss_section;
2201 *sdata->bss_section->symbol_ptr_ptr = sdata->bss_section->symbol;
2204 *secp = sdata->bss_section;
2205 *valp = sym->st_size;
2212 /* Finish up dynamic symbol handling. We set the contents of various
2213 dynamic sections here. */
2216 ppc_elf_finish_dynamic_symbol (output_bfd, info, h, sym)
2218 struct bfd_link_info *info;
2219 struct elf_link_hash_entry *h;
2220 Elf_Internal_Sym *sym;
2225 fprintf (stderr, "ppc_elf_finish_dynamic_symbol called for %s", h->root.root.string);
2228 dynobj = elf_hash_table (info)->dynobj;
2229 BFD_ASSERT (dynobj != NULL);
2231 if (h->plt_offset != (bfd_vma) -1)
2235 Elf_Internal_Rela rela;
2238 fprintf (stderr, ", plt_offset = %d", h->plt_offset);
2241 /* This symbol has an entry in the procedure linkage table. Set
2244 BFD_ASSERT (h->dynindx != -1);
2246 splt = bfd_get_section_by_name (dynobj, ".plt");
2247 srela = bfd_get_section_by_name (dynobj, ".rela.plt");
2248 BFD_ASSERT (splt != NULL && srela != NULL);
2250 /* We don't need to fill in the .plt. The ppc dynamic linker
2253 /* Fill in the entry in the .rela.plt section. */
2254 rela.r_offset = (splt->output_section->vma
2255 + splt->output_offset
2257 rela.r_info = ELF32_R_INFO (h->dynindx, R_PPC_JMP_SLOT);
2259 bfd_elf32_swap_reloca_out (output_bfd, &rela,
2260 ((Elf32_External_Rela *) srela->contents
2261 + ((h->plt_offset - PLT_INITIAL_ENTRY_SIZE) / 8)));
2263 if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
2265 /* Mark the symbol as undefined, rather than as defined in
2266 the .plt section. Leave the value alone. */
2267 sym->st_shndx = SHN_UNDEF;
2271 if (h->got_offset != (bfd_vma) -1)
2275 Elf_Internal_Rela rela;
2277 /* This symbol has an entry in the global offset table. Set it
2280 BFD_ASSERT (h->dynindx != -1);
2282 sgot = bfd_get_section_by_name (dynobj, ".got");
2283 srela = bfd_get_section_by_name (dynobj, ".rela.got");
2284 BFD_ASSERT (sgot != NULL && srela != NULL);
2286 rela.r_offset = (sgot->output_section->vma
2287 + sgot->output_offset
2288 + (h->got_offset &~ 1));
2290 /* If this is a -Bsymbolic link, and the symbol is defined
2291 locally, we just want to emit a RELATIVE reloc. The entry in
2292 the global offset table will already have been initialized in
2293 the relocate_section function. */
2296 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR))
2297 rela.r_info = ELF32_R_INFO (0, R_PPC_RELATIVE);
2300 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + h->got_offset);
2301 rela.r_info = ELF32_R_INFO (h->dynindx, R_PPC_GLOB_DAT);
2305 bfd_elf32_swap_reloca_out (output_bfd, &rela,
2306 ((Elf32_External_Rela *) srela->contents
2307 + srela->reloc_count));
2308 ++srela->reloc_count;
2311 if ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_COPY) != 0)
2314 Elf_Internal_Rela rela;
2316 /* This symbols needs a copy reloc. Set it up. */
2319 fprintf (stderr, ", copy");
2322 BFD_ASSERT (h->dynindx != -1);
2324 s = bfd_get_section_by_name (h->root.u.def.section->owner,
2326 BFD_ASSERT (s != NULL);
2328 rela.r_offset = (h->root.u.def.value
2329 + h->root.u.def.section->output_section->vma
2330 + h->root.u.def.section->output_offset);
2331 rela.r_info = ELF32_R_INFO (h->dynindx, R_PPC_COPY);
2333 bfd_elf32_swap_reloca_out (output_bfd, &rela,
2334 ((Elf32_External_Rela *) s->contents
2340 fprintf (stderr, "\n");
2343 /* Mark some specially defined symbols as absolute. */
2344 if (strcmp (h->root.root.string, "_DYNAMIC") == 0
2345 || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0
2346 || strcmp (h->root.root.string, "_PROCEDURE_LINKAGE_TABLE_") == 0)
2347 sym->st_shndx = SHN_ABS;
2353 /* Finish up the dynamic sections. */
2356 ppc_elf_finish_dynamic_sections (output_bfd, info)
2358 struct bfd_link_info *info;
2361 bfd *dynobj = elf_hash_table (info)->dynobj;
2362 asection *sgot = bfd_get_section_by_name (dynobj, ".got");
2365 fprintf (stderr, "ppc_elf_finish_dynamic_sections called\n");
2368 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
2370 if (elf_hash_table (info)->dynamic_sections_created)
2373 Elf32_External_Dyn *dyncon, *dynconend;
2375 splt = bfd_get_section_by_name (dynobj, ".plt");
2376 BFD_ASSERT (splt != NULL && sdyn != NULL);
2378 dyncon = (Elf32_External_Dyn *) sdyn->contents;
2379 dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->_raw_size);
2380 for (; dyncon < dynconend; dyncon++)
2382 Elf_Internal_Dyn dyn;
2386 bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
2390 case DT_PLTGOT: name = ".plt"; size = false; break;
2391 case DT_PLTRELSZ: name = ".rela.plt"; size = true; break;
2392 case DT_JMPREL: name = ".rela.plt"; size = false; break;
2393 default: name = NULL; size = false; break;
2400 s = bfd_get_section_by_name (output_bfd, name);
2406 dyn.d_un.d_ptr = s->vma;
2409 if (s->_cooked_size != 0)
2410 dyn.d_un.d_val = s->_cooked_size;
2412 dyn.d_un.d_val = s->_raw_size;
2415 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
2420 /* Add a blrl instruction at _GLOBAL_OFFSET_TABLE_-4 so that a function can
2421 easily find the address of the _GLOBAL_OFFSET_TABLE_. */
2424 unsigned char *contents = sgot->contents;
2425 bfd_put_32 (output_bfd, 0x4e800021 /* blrl */, contents);
2428 bfd_put_32 (output_bfd, (bfd_vma) 0, contents+4);
2430 bfd_put_32 (output_bfd,
2431 sdyn->output_section->vma + sdyn->output_offset,
2434 elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4;
2441 Elf_Internal_Sym sym;
2444 /* Set up the section symbols for the output sections. */
2446 sdynsym = bfd_get_section_by_name (dynobj, ".dynsym");
2447 BFD_ASSERT (sdynsym != NULL);
2451 sym.st_info = ELF_ST_INFO (STB_LOCAL, STT_SECTION);
2454 for (s = output_bfd->sections; s != NULL; s = s->next)
2458 sym.st_value = s->vma;
2460 indx = elf_section_data (s)->this_idx;
2461 dindx = elf_section_data (s)->dynindx;
2464 BFD_ASSERT(indx > 0);
2465 BFD_ASSERT(dindx > 0);
2467 if (dindx > maxdindx)
2470 sym.st_shndx = indx;
2472 bfd_elf32_swap_symbol_out (output_bfd, &sym,
2473 (PTR) (((Elf32_External_Sym *)
2479 /* Set the sh_info field of the output .dynsym section to the
2480 index of the first global symbol. */
2481 elf_section_data (sdynsym->output_section)->this_hdr.sh_info =
2489 /* The RELOCATE_SECTION function is called by the ELF backend linker
2490 to handle the relocations for a section.
2492 The relocs are always passed as Rela structures; if the section
2493 actually uses Rel structures, the r_addend field will always be
2496 This function is responsible for adjust the section contents as
2497 necessary, and (if using Rela relocs and generating a
2498 relocateable output file) adjusting the reloc addend as
2501 This function does not have to worry about setting the reloc
2502 address or the reloc symbol index.
2504 LOCAL_SYMS is a pointer to the swapped in local symbols.
2506 LOCAL_SECTIONS is an array giving the section in the input file
2507 corresponding to the st_shndx field of each local symbol.
2509 The global hash table entry for the global symbols can be found
2510 via elf_sym_hashes (input_bfd).
2512 When generating relocateable output, this function must handle
2513 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
2514 going to be the section symbol corresponding to the output
2515 section, which means that the addend must be adjusted
2519 ppc_elf_relocate_section (output_bfd, info, input_bfd, input_section,
2520 contents, relocs, local_syms, local_sections)
2522 struct bfd_link_info *info;
2524 asection *input_section;
2526 Elf_Internal_Rela *relocs;
2527 Elf_Internal_Sym *local_syms;
2528 asection **local_sections;
2530 Elf_Internal_Shdr *symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
2531 struct elf_link_hash_entry **sym_hashes = elf_sym_hashes (input_bfd);
2532 bfd *dynobj = elf_hash_table (info)->dynobj;
2533 elf_linker_section_t *sdata = (dynobj) ? elf_linker_section (dynobj, LINKER_SECTION_SDATA) : NULL;
2534 elf_linker_section_t *sdata2 = (dynobj) ? elf_linker_section (dynobj, LINKER_SECTION_SDATA2) : NULL;
2535 Elf_Internal_Rela *rel = relocs;
2536 Elf_Internal_Rela *relend = relocs + input_section->reloc_count;
2537 asection *sreloc = NULL;
2538 asection *splt = NULL;
2539 asection *sgot = NULL;
2540 bfd_vma *local_got_offsets;
2545 fprintf (stderr, "ppc_elf_relocate_section called for %s section %s, %ld relocations%s\n",
2546 bfd_get_filename (input_bfd),
2547 bfd_section_name(input_bfd, input_section),
2548 (long)input_section->reloc_count,
2549 (info->relocateable) ? " (relocatable)" : "");
2552 if (!ppc_elf_howto_table[ R_PPC_ADDR32 ]) /* Initialize howto table if needed */
2553 ppc_elf_howto_init ();
2555 local_got_offsets = elf_local_got_offsets (input_bfd);
2557 for (; rel < relend; rel++)
2559 enum ppc_reloc_type r_type = (enum ppc_reloc_type)ELF32_R_TYPE (rel->r_info);
2560 bfd_vma offset = rel->r_offset;
2561 bfd_vma addend = rel->r_addend;
2562 bfd_reloc_status_type r = bfd_reloc_other;
2563 Elf_Internal_Sym *sym = (Elf_Internal_Sym *)0;
2564 asection *sec = (asection *)0;
2565 struct elf_link_hash_entry *h = (struct elf_link_hash_entry *)0;
2566 const char *sym_name = (const char *)0;
2567 reloc_howto_type *howto;
2568 unsigned long r_symndx;
2571 /* Unknown relocation handling */
2572 if ((unsigned)r_type >= (unsigned)R_PPC_max || !ppc_elf_howto_table[(int)r_type])
2574 (*_bfd_error_handler) ("%s: unknown relocation type %d",
2575 bfd_get_filename (input_bfd),
2578 bfd_set_error (bfd_error_bad_value);
2583 howto = ppc_elf_howto_table[(int)r_type];
2584 r_symndx = ELF32_R_SYM (rel->r_info);
2586 if (info->relocateable)
2588 /* This is a relocateable link. We don't have to change
2589 anything, unless the reloc is against a section symbol,
2590 in which case we have to adjust according to where the
2591 section symbol winds up in the output section. */
2592 if (r_symndx < symtab_hdr->sh_info)
2594 sym = local_syms + r_symndx;
2595 if ((unsigned)ELF_ST_TYPE (sym->st_info) == STT_SECTION)
2597 sec = local_sections[r_symndx];
2598 addend = rel->r_addend += sec->output_offset + sym->st_value;
2603 fprintf (stderr, "\ttype = %s (%d), symbol index = %ld, offset = %ld, addend = %ld\n",
2613 /* This is a final link. */
2614 if (r_symndx < symtab_hdr->sh_info)
2616 sym = local_syms + r_symndx;
2617 sec = local_sections[r_symndx];
2618 sym_name = "<local symbol>";
2620 relocation = (sec->output_section->vma
2621 + sec->output_offset
2626 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
2627 while (h->root.type == bfd_link_hash_indirect
2628 || h->root.type == bfd_link_hash_warning)
2629 h = (struct elf_link_hash_entry *) h->root.u.i.link;
2630 sym_name = h->root.root.string;
2631 if (h->root.type == bfd_link_hash_defined
2632 || h->root.type == bfd_link_hash_defweak)
2634 sec = h->root.u.def.section;
2635 if ((r_type == R_PPC_PLT32
2636 && h->plt_offset != (bfd_vma) -1)
2637 || ((r_type == R_PPC_GOT16
2638 || r_type == R_PPC_GOT16_LO
2639 || r_type == R_PPC_GOT16_HI
2640 || r_type == R_PPC_GOT16_HA)
2641 && elf_hash_table (info)->dynamic_sections_created
2644 || (h->elf_link_hash_flags
2645 & ELF_LINK_HASH_DEF_REGULAR) == 0))
2647 && (! info->symbolic
2648 || (h->elf_link_hash_flags
2649 & ELF_LINK_HASH_DEF_REGULAR) == 0)
2650 && (input_section->flags & SEC_ALLOC) != 0
2651 && (r_type == R_PPC_ADDR32
2652 || r_type == R_PPC_ADDR24
2653 || r_type == R_PPC_ADDR16
2654 || r_type == R_PPC_ADDR16_LO
2655 || r_type == R_PPC_ADDR16_HI
2656 || r_type == R_PPC_ADDR16_HA
2657 || r_type == R_PPC_ADDR14
2658 || r_type == R_PPC_ADDR14_BRTAKEN
2659 || r_type == R_PPC_ADDR14_BRNTAKEN
2660 || r_type == R_PPC_PLTREL24
2661 || r_type == R_PPC_COPY
2662 || r_type == R_PPC_GLOB_DAT
2663 || r_type == R_PPC_JMP_SLOT
2664 || r_type == R_PPC_UADDR32
2665 || r_type == R_PPC_UADDR16
2666 || r_type == R_PPC_REL32
2667 || r_type == R_PPC_SDAREL16
2668 || r_type == R_PPC_EMB_NADDR32
2669 || r_type == R_PPC_EMB_NADDR16
2670 || r_type == R_PPC_EMB_NADDR16_LO
2671 || r_type == R_PPC_EMB_NADDR16_HI
2672 || r_type == R_PPC_EMB_NADDR16_HA
2673 || r_type == R_PPC_EMB_SDAI16
2674 || r_type == R_PPC_EMB_SDA2I16
2675 || r_type == R_PPC_EMB_SDA2REL
2676 || r_type == R_PPC_EMB_SDA21
2677 || r_type == R_PPC_EMB_MRKREF
2678 || r_type == R_PPC_EMB_BIT_FLD
2679 || r_type == R_PPC_EMB_RELSDA
2680 || ((r_type == R_PPC_REL24
2681 || r_type == R_PPC_REL14
2682 || r_type == R_PPC_REL14_BRTAKEN
2683 || r_type == R_PPC_REL14_BRNTAKEN
2684 || r_type == R_PPC_RELATIVE)
2685 && strcmp (h->root.root.string,
2686 "_GLOBAL_OFFSET_TABLE_") != 0))))
2688 /* In these cases, we don't need the relocation
2689 value. We check specially because in some
2690 obscure cases sec->output_section will be NULL. */
2694 relocation = (h->root.u.def.value
2695 + sec->output_section->vma
2696 + sec->output_offset);
2698 else if (h->root.type == bfd_link_hash_undefweak)
2700 else if (info->shared)
2704 (*info->callbacks->undefined_symbol)(info,
2705 h->root.root.string,
2714 switch ((int)r_type)
2717 (*_bfd_error_handler) ("%s: unknown relocation type %d for symbol %s",
2718 bfd_get_filename (input_bfd),
2719 (int)r_type, sym_name);
2721 bfd_set_error (bfd_error_bad_value);
2725 /* relocations that need no special processing */
2726 case (int)R_PPC_LOCAL24PC:
2729 case (int)R_PPC_REL24:
2730 case (int)R_PPC_REL14:
2732 || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
2736 /* Relocations that need to be propagated if this is a shared
2738 case (int)R_PPC_NONE:
2739 case (int)R_PPC_ADDR32:
2740 case (int)R_PPC_ADDR24:
2741 case (int)R_PPC_ADDR16:
2742 case (int)R_PPC_ADDR16_LO:
2743 case (int)R_PPC_ADDR16_HI:
2744 case (int)R_PPC_ADDR16_HA:
2745 case (int)R_PPC_ADDR14:
2746 case (int)R_PPC_UADDR32:
2747 case (int)R_PPC_UADDR16:
2748 case (int)R_PPC_REL32:
2751 Elf_Internal_Rela outrel;
2755 fprintf (stderr, "ppc_elf_relocate_section need to create relocation for %s\n",
2756 (h && h->root.root.string) ? h->root.root.string : "<unknown>");
2759 /* When generating a shared object, these relocations
2760 are copied into the output file to be resolved at run
2767 name = (bfd_elf_string_from_elf_section
2769 elf_elfheader (input_bfd)->e_shstrndx,
2770 elf_section_data (input_section)->rel_hdr.sh_name));
2774 BFD_ASSERT (strncmp (name, ".rela", 5) == 0
2775 && strcmp (bfd_get_section_name (input_bfd,
2779 sreloc = bfd_get_section_by_name (dynobj, name);
2780 BFD_ASSERT (sreloc != NULL);
2785 if (elf_section_data (input_section)->stab_info == NULL)
2786 outrel.r_offset = rel->r_offset;
2791 off = (_bfd_stab_section_offset
2792 (output_bfd, &elf_hash_table (info)->stab_info,
2794 &elf_section_data (input_section)->stab_info,
2796 if (off == (bfd_vma) -1)
2798 outrel.r_offset = off;
2801 outrel.r_offset += (input_section->output_section->vma
2802 + input_section->output_offset);
2805 memset (&outrel, 0, sizeof outrel);
2806 /* h->dynindx may be -1 if this symbol was marked to
2809 && ((! info->symbolic && h->dynindx != -1)
2810 || (h->elf_link_hash_flags
2811 & ELF_LINK_HASH_DEF_REGULAR) == 0))
2813 BFD_ASSERT (h->dynindx != -1);
2814 outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
2815 outrel.r_addend = rel->r_addend;
2819 if (r_type == R_PPC_ADDR32)
2821 outrel.r_info = ELF32_R_INFO (0, R_PPC_RELATIVE);
2822 outrel.r_addend = relocation + rel->r_addend;
2829 sec = local_sections[r_symndx];
2832 BFD_ASSERT (h->root.type == bfd_link_hash_defined
2834 == bfd_link_hash_defweak));
2835 sec = h->root.u.def.section;
2837 if (sec != NULL && bfd_is_abs_section (sec))
2839 else if (sec == NULL || sec->owner == NULL)
2841 bfd_set_error (bfd_error_bad_value);
2848 osec = sec->output_section;
2849 indx = elf_section_data (osec)->dynindx;
2850 BFD_ASSERT(indx > 0);
2853 outrel.r_info = ELF32_R_INFO (indx, r_type);
2854 outrel.r_addend = relocation + rel->r_addend;
2858 bfd_elf32_swap_reloca_out (output_bfd, &outrel,
2859 (((Elf32_External_Rela *)
2861 + sreloc->reloc_count));
2862 ++sreloc->reloc_count;
2864 /* This reloc will be computed at runtime, so there's no
2865 need to do anything now, unless this is a RELATIVE
2866 reloc in an unallocated section. */
2868 || (input_section->flags & SEC_ALLOC) != 0
2869 || ELF32_R_TYPE (outrel.r_info) != R_PPC_RELATIVE)
2873 /* Arithmetic adjust relocations that aren't going into a
2875 if (r_type == R_PPC_ADDR16_HA
2876 /* It's just possible that this symbol is a weak symbol
2877 that's not actually defined anywhere. In that case,
2878 'sec' would be NULL, and we should leave the symbol
2879 alone (it will be set to zero elsewhere in the link). */
2882 addend += ((relocation + addend) & 0x8000) << 1;
2886 /* branch taken prediction relocations */
2887 case (int)R_PPC_ADDR14_BRTAKEN:
2888 case (int)R_PPC_REL14_BRTAKEN:
2889 insn = bfd_get_32 (output_bfd, contents + offset);
2890 if ((relocation - offset) & 0x8000)
2891 insn &= ~BRANCH_PREDICT_BIT;
2893 insn |= BRANCH_PREDICT_BIT;
2894 bfd_put_32 (output_bfd, insn, contents + offset);
2897 /* branch not taken predicition relocations */
2898 case (int)R_PPC_ADDR14_BRNTAKEN:
2899 case (int)R_PPC_REL14_BRNTAKEN:
2900 insn = bfd_get_32 (output_bfd, contents + offset);
2901 if ((relocation - offset) & 0x8000)
2902 insn |= BRANCH_PREDICT_BIT;
2904 insn &= ~BRANCH_PREDICT_BIT;
2905 bfd_put_32 (output_bfd, insn, contents + offset);
2908 /* GOT16 relocations */
2909 case (int)R_PPC_GOT16:
2910 case (int)R_PPC_GOT16_LO:
2911 case (int)R_PPC_GOT16_HI:
2912 case (int)R_PPC_GOT16_HA:
2913 /* Relocation is to the entry for this symbol in the global
2917 sgot = bfd_get_section_by_name (dynobj, ".got");
2918 BFD_ASSERT (sgot != NULL);
2925 off = h->got_offset;
2926 BFD_ASSERT (off != (bfd_vma) -1);
2928 if (! elf_hash_table (info)->dynamic_sections_created
2931 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR)))
2933 /* This is actually a static link, or it is a
2934 -Bsymbolic link and the symbol is defined
2935 locally. We must initialize this entry in the
2936 global offset table. Since the offset must
2937 always be a multiple of 4, we use the least
2938 significant bit to record whether we have
2939 initialized it already.
2941 When doing a dynamic link, we create a .rela.got
2942 relocation entry to initialize the value. This
2943 is done in the finish_dynamic_symbol routine. */
2948 bfd_put_32 (output_bfd, relocation + addend,
2949 sgot->contents + off);
2954 relocation = sgot->output_offset + off - 4;
2961 BFD_ASSERT (local_got_offsets != NULL
2962 && local_got_offsets[r_symndx] != (bfd_vma) -1);
2964 off = local_got_offsets[r_symndx];
2966 /* The offset must always be a multiple of 4. We use
2967 the least significant bit to record whether we have
2968 already processed this entry. */
2973 bfd_put_32 (output_bfd, relocation, sgot->contents + off);
2978 Elf_Internal_Rela outrel;
2980 /* We need to generate a R_PPC_RELATIVE reloc
2981 for the dynamic linker. */
2982 srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
2983 BFD_ASSERT (srelgot != NULL);
2985 outrel.r_offset = (sgot->output_section->vma
2986 + sgot->output_offset
2988 outrel.r_info = ELF32_R_INFO (0, R_PPC_RELATIVE);
2989 outrel.r_addend = relocation + addend;
2990 bfd_elf32_swap_reloca_out (output_bfd, &outrel,
2991 (((Elf32_External_Rela *)
2993 + srelgot->reloc_count));
2994 ++srelgot->reloc_count;
2997 local_got_offsets[r_symndx] |= 1;
3000 relocation = sgot->output_offset + off - 4;
3006 /* Indirect .sdata relocation */
3007 case (int)R_PPC_EMB_SDAI16:
3008 BFD_ASSERT (sdata != NULL);
3009 relocation = bfd_elf32_finish_pointer_linker_section (output_bfd, input_bfd, info,
3010 sdata, h, relocation, rel,
3014 /* Indirect .sdata2 relocation */
3015 case (int)R_PPC_EMB_SDA2I16:
3016 BFD_ASSERT (sdata2 != NULL);
3017 relocation = bfd_elf32_finish_pointer_linker_section (output_bfd, input_bfd, info,
3018 sdata2, h, relocation, rel,
3022 /* Handle the TOC16 reloc. We want to use the offset within the .got
3023 section, not the actual VMA. This is appropriate when generating
3024 an embedded ELF object, for which the .got section acts like the
3025 AIX .toc section. */
3026 case (int)R_PPC_TOC16: /* phony GOT16 relocations */
3027 BFD_ASSERT (sec != (asection *)0);
3028 BFD_ASSERT (bfd_is_und_section (sec)
3029 || strcmp (bfd_get_section_name (abfd, sec), ".got") == 0
3030 || strcmp (bfd_get_section_name (abfd, sec), ".cgot") == 0)
3032 addend -= sec->output_section->vma + sec->output_offset + 0x8000;
3035 case (int)R_PPC_PLTREL24:
3036 /* Relocation is to the entry for this symbol in the
3037 procedure linkage table. */
3038 BFD_ASSERT (h != NULL);
3040 if (h->plt_offset == (bfd_vma) -1)
3042 /* We didn't make a PLT entry for this symbol. This
3043 happens when statically linking PIC code, or when
3044 using -Bsymbolic. */
3050 splt = bfd_get_section_by_name (dynobj, ".plt");
3051 BFD_ASSERT (splt != NULL);
3054 relocation = (splt->output_section->vma
3055 + splt->output_offset
3059 /* relocate against _SDA_BASE_ */
3060 case (int)R_PPC_SDAREL16:
3061 BFD_ASSERT (sec != (asection *)0);
3062 if (strcmp (bfd_get_section_name (abfd, sec), ".sdata") != 0
3063 && strcmp (bfd_get_section_name (abfd, sec), ".sbss") != 0)
3065 (*_bfd_error_handler) ("%s: The target (%s) of a %s relocation is in the wrong section (%s)",
3066 bfd_get_filename (input_bfd),
3068 ppc_elf_howto_table[ (int)r_type ]->name,
3069 bfd_get_section_name (abfd, sec));
3071 bfd_set_error (bfd_error_bad_value);
3075 addend -= (sdata->sym_hash->root.u.def.value
3076 + sdata->sym_hash->root.u.def.section->output_section->vma
3077 + sdata->sym_hash->root.u.def.section->output_offset);
3081 /* relocate against _SDA2_BASE_ */
3082 case (int)R_PPC_EMB_SDA2REL:
3083 BFD_ASSERT (sec != (asection *)0);
3084 if (strcmp (bfd_get_section_name (abfd, sec), ".sdata2") != 0
3085 && strcmp (bfd_get_section_name (abfd, sec), ".sbss2") != 0)
3087 (*_bfd_error_handler) ("%s: The target (%s) of a %s relocation is in the wrong section (%s)",
3088 bfd_get_filename (input_bfd),
3090 ppc_elf_howto_table[ (int)r_type ]->name,
3091 bfd_get_section_name (abfd, sec));
3093 bfd_set_error (bfd_error_bad_value);
3097 addend -= (sdata2->sym_hash->root.u.def.value
3098 + sdata2->sym_hash->root.u.def.section->output_section->vma
3099 + sdata2->sym_hash->root.u.def.section->output_offset);
3103 /* relocate against either _SDA_BASE_, _SDA2_BASE_, or 0 */
3104 case (int)R_PPC_EMB_SDA21:
3105 case (int)R_PPC_EMB_RELSDA:
3107 const char *name = bfd_get_section_name (abfd, sec);
3110 BFD_ASSERT (sec != (asection *)0);
3111 if (strcmp (name, ".sdata") == 0 || strcmp (name, ".sbss") == 0)
3114 addend -= (sdata->sym_hash->root.u.def.value
3115 + sdata->sym_hash->root.u.def.section->output_section->vma
3116 + sdata->sym_hash->root.u.def.section->output_offset);
3119 else if (strcmp (name, ".sdata2") == 0 || strcmp (name, ".sbss2") == 0)
3122 addend -= (sdata2->sym_hash->root.u.def.value
3123 + sdata2->sym_hash->root.u.def.section->output_section->vma
3124 + sdata2->sym_hash->root.u.def.section->output_offset);
3127 else if (strcmp (name, ".PPC.EMB.sdata0") == 0 || strcmp (name, ".PPC.EMB.sbss0") == 0)
3134 (*_bfd_error_handler) ("%s: The target (%s) of a %s relocation is in the wrong section (%s)",
3135 bfd_get_filename (input_bfd),
3137 ppc_elf_howto_table[ (int)r_type ]->name,
3138 bfd_get_section_name (abfd, sec));
3140 bfd_set_error (bfd_error_bad_value);
3145 if (r_type == R_PPC_EMB_SDA21)
3146 { /* fill in register field */
3147 insn = bfd_get_32 (output_bfd, contents + offset);
3148 insn = (insn & ~RA_REGISTER_MASK) | (reg << RA_REGISTER_SHIFT);
3149 bfd_put_32 (output_bfd, insn, contents + offset);
3154 /* Relocate against the beginning of the section */
3155 case (int)R_PPC_SECTOFF:
3156 case (int)R_PPC_SECTOFF_LO:
3157 case (int)R_PPC_SECTOFF_HI:
3158 BFD_ASSERT (sec != (asection *)0);
3159 addend -= sec->output_section->vma;
3162 case (int)R_PPC_SECTOFF_HA:
3163 BFD_ASSERT (sec != (asection *)0);
3164 addend -= sec->output_section->vma;
3165 addend += ((relocation + addend) & 0x8000) << 1;
3168 /* Negative relocations */
3169 case (int)R_PPC_EMB_NADDR32:
3170 case (int)R_PPC_EMB_NADDR16:
3171 case (int)R_PPC_EMB_NADDR16_LO:
3172 case (int)R_PPC_EMB_NADDR16_HI:
3173 addend -= 2*relocation;
3176 case (int)R_PPC_EMB_NADDR16_HA:
3177 addend -= 2*relocation;
3178 addend += ((relocation + addend) & 0x8000) << 1;
3181 /* NOP relocation that prevents garbage collecting linkers from omitting a
3183 case (int)R_PPC_EMB_MRKREF:
3186 case (int)R_PPC_COPY:
3187 case (int)R_PPC_GLOB_DAT:
3188 case (int)R_PPC_JMP_SLOT:
3189 case (int)R_PPC_RELATIVE:
3190 case (int)R_PPC_PLT32:
3191 case (int)R_PPC_PLTREL32:
3192 case (int)R_PPC_PLT16_LO:
3193 case (int)R_PPC_PLT16_HI:
3194 case (int)R_PPC_PLT16_HA:
3195 case (int)R_PPC_EMB_RELSEC16:
3196 case (int)R_PPC_EMB_RELST_LO:
3197 case (int)R_PPC_EMB_RELST_HI:
3198 case (int)R_PPC_EMB_RELST_HA:
3199 case (int)R_PPC_EMB_BIT_FLD:
3200 (*_bfd_error_handler) ("%s: Relocation %s is not yet supported for symbol %s.",
3201 bfd_get_filename (input_bfd),
3202 ppc_elf_howto_table[ (int)r_type ]->name,
3205 bfd_set_error (bfd_error_invalid_operation);
3212 fprintf (stderr, "\ttype = %s (%d), name = %s, symbol index = %ld, offset = %ld, addend = %ld\n",
3221 r = _bfd_final_link_relocate (howto,
3229 if (r != bfd_reloc_ok)
3237 case bfd_reloc_overflow:
3242 name = h->root.root.string;
3245 name = bfd_elf_string_from_elf_section (input_bfd,
3246 symtab_hdr->sh_link,
3252 name = bfd_section_name (input_bfd, sec);
3255 (*info->callbacks->reloc_overflow)(info,
3271 fprintf (stderr, "\n");
3278 #define TARGET_LITTLE_SYM bfd_elf32_powerpcle_vec
3279 #define TARGET_LITTLE_NAME "elf32-powerpcle"
3280 #define TARGET_BIG_SYM bfd_elf32_powerpc_vec
3281 #define TARGET_BIG_NAME "elf32-powerpc"
3282 #define ELF_ARCH bfd_arch_powerpc
3283 #define ELF_MACHINE_CODE EM_PPC
3284 #define ELF_MAXPAGESIZE 0x10000
3285 #define elf_info_to_howto ppc_elf_info_to_howto
3287 #ifdef EM_CYGNUS_POWERPC
3288 #define ELF_MACHINE_ALT1 EM_CYGNUS_POWERPC
3292 #define ELF_MACHINE_ALT2 EM_PPC_OLD
3295 #define elf_backend_plt_not_loaded 1
3296 #define elf_backend_got_symbol_offset 4
3298 #define bfd_elf32_bfd_copy_private_bfd_data ppc_elf_copy_private_bfd_data
3299 #define bfd_elf32_bfd_merge_private_bfd_data ppc_elf_merge_private_bfd_data
3300 #define bfd_elf32_bfd_set_private_flags ppc_elf_set_private_flags
3301 #define bfd_elf32_bfd_reloc_type_lookup ppc_elf_reloc_type_lookup
3302 #define elf_backend_section_from_shdr ppc_elf_section_from_shdr
3303 #define elf_backend_relocate_section ppc_elf_relocate_section
3304 #define elf_backend_create_dynamic_sections _bfd_elf_create_dynamic_sections
3305 #define elf_backend_check_relocs ppc_elf_check_relocs
3306 #define elf_backend_adjust_dynamic_symbol ppc_elf_adjust_dynamic_symbol
3307 #define elf_backend_add_symbol_hook ppc_elf_add_symbol_hook
3308 #define elf_backend_size_dynamic_sections ppc_elf_size_dynamic_sections
3309 #define elf_backend_finish_dynamic_symbol ppc_elf_finish_dynamic_symbol
3310 #define elf_backend_finish_dynamic_sections ppc_elf_finish_dynamic_sections
3311 #define elf_backend_fake_sections ppc_elf_fake_sections
3312 #define elf_backend_additional_program_headers ppc_elf_additional_program_headers
3313 #define elf_backend_modify_segment_map ppc_elf_modify_segment_map
3315 #include "elf32-target.h"