1 /* PowerPC-specific support for 32-bit ELF
2 Copyright 1994, 1995, 1996 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 boolean ppc_elf_set_private_flags PARAMS ((bfd *, flagword));
108 static boolean ppc_elf_copy_private_bfd_data PARAMS ((bfd *, bfd *));
109 static boolean ppc_elf_merge_private_bfd_data PARAMS ((bfd *, bfd *));
111 static boolean ppc_elf_section_from_shdr PARAMS ((bfd *,
112 Elf32_Internal_Shdr *,
115 static elf_linker_section_t *ppc_elf_create_linker_section
117 struct bfd_link_info *info,
118 enum elf_linker_section_enum));
120 static boolean ppc_elf_check_relocs PARAMS ((bfd *,
121 struct bfd_link_info *,
123 const Elf_Internal_Rela *));
125 static boolean ppc_elf_adjust_dynamic_symbol PARAMS ((struct bfd_link_info *,
126 struct elf_link_hash_entry *));
128 static boolean ppc_elf_adjust_dynindx PARAMS ((struct elf_link_hash_entry *, PTR));
130 static boolean ppc_elf_size_dynamic_sections PARAMS ((bfd *, struct bfd_link_info *));
132 static boolean ppc_elf_relocate_section PARAMS ((bfd *,
133 struct bfd_link_info *info,
137 Elf_Internal_Rela *relocs,
138 Elf_Internal_Sym *local_syms,
141 static boolean ppc_elf_finish_dynamic_symbol PARAMS ((bfd *,
142 struct bfd_link_info *,
143 struct elf_link_hash_entry *,
144 Elf_Internal_Sym *));
146 static boolean ppc_elf_finish_dynamic_sections PARAMS ((bfd *, struct bfd_link_info *));
148 #define BRANCH_PREDICT_BIT 0x200000
150 /* The name of the dynamic interpreter. This is put in the .interp
153 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
156 static reloc_howto_type *ppc_elf_howto_table[ (int)R_PPC_max ];
158 static reloc_howto_type ppc_elf_howto_raw[] =
160 /* This reloc does nothing. */
161 HOWTO (R_PPC_NONE, /* type */
163 2, /* size (0 = byte, 1 = short, 2 = long) */
165 false, /* pc_relative */
167 complain_overflow_bitfield, /* complain_on_overflow */
168 bfd_elf_generic_reloc, /* special_function */
169 "R_PPC_NONE", /* name */
170 false, /* partial_inplace */
173 false), /* pcrel_offset */
175 /* A standard 32 bit relocation. */
176 HOWTO (R_PPC_ADDR32, /* type */
178 2, /* size (0 = byte, 1 = short, 2 = long) */
180 false, /* pc_relative */
182 complain_overflow_bitfield, /* complain_on_overflow */
183 bfd_elf_generic_reloc, /* special_function */
184 "R_PPC_ADDR32", /* name */
185 false, /* partial_inplace */
187 0xffffffff, /* dst_mask */
188 false), /* pcrel_offset */
190 /* An absolute 26 bit branch; the lower two bits must be zero.
191 FIXME: we don't check that, we just clear them. */
192 HOWTO (R_PPC_ADDR24, /* type */
194 2, /* size (0 = byte, 1 = short, 2 = long) */
196 false, /* pc_relative */
198 complain_overflow_bitfield, /* complain_on_overflow */
199 bfd_elf_generic_reloc, /* special_function */
200 "R_PPC_ADDR24", /* name */
201 false, /* partial_inplace */
203 0x3fffffc, /* dst_mask */
204 false), /* pcrel_offset */
206 /* A standard 16 bit relocation. */
207 HOWTO (R_PPC_ADDR16, /* type */
209 1, /* size (0 = byte, 1 = short, 2 = long) */
211 false, /* pc_relative */
213 complain_overflow_bitfield, /* complain_on_overflow */
214 bfd_elf_generic_reloc, /* special_function */
215 "R_PPC_ADDR16", /* name */
216 false, /* partial_inplace */
218 0xffff, /* dst_mask */
219 false), /* pcrel_offset */
221 /* A 16 bit relocation without overflow. */
222 HOWTO (R_PPC_ADDR16_LO, /* type */
224 1, /* size (0 = byte, 1 = short, 2 = long) */
226 false, /* pc_relative */
228 complain_overflow_dont,/* complain_on_overflow */
229 bfd_elf_generic_reloc, /* special_function */
230 "R_PPC_ADDR16_LO", /* name */
231 false, /* partial_inplace */
233 0xffff, /* dst_mask */
234 false), /* pcrel_offset */
236 /* The high order 16 bits of an address. */
237 HOWTO (R_PPC_ADDR16_HI, /* type */
239 1, /* size (0 = byte, 1 = short, 2 = long) */
241 false, /* pc_relative */
243 complain_overflow_dont, /* complain_on_overflow */
244 bfd_elf_generic_reloc, /* special_function */
245 "R_PPC_ADDR16_HI", /* name */
246 false, /* partial_inplace */
248 0xffff, /* dst_mask */
249 false), /* pcrel_offset */
251 /* The high order 16 bits of an address, plus 1 if the contents of
252 the low 16 bits, treated as a signed number, is negative. */
253 HOWTO (R_PPC_ADDR16_HA, /* type */
255 1, /* size (0 = byte, 1 = short, 2 = long) */
257 false, /* pc_relative */
259 complain_overflow_dont, /* complain_on_overflow */
260 bfd_elf_generic_reloc, /* special_function */
261 "R_PPC_ADDR16_HA", /* name */
262 false, /* partial_inplace */
264 0xffff, /* dst_mask */
265 false), /* pcrel_offset */
267 /* An absolute 16 bit branch; the lower two bits must be zero.
268 FIXME: we don't check that, we just clear them. */
269 HOWTO (R_PPC_ADDR14, /* type */
271 2, /* size (0 = byte, 1 = short, 2 = long) */
273 false, /* pc_relative */
275 complain_overflow_bitfield, /* complain_on_overflow */
276 bfd_elf_generic_reloc, /* special_function */
277 "R_PPC_ADDR14", /* name */
278 false, /* partial_inplace */
280 0xfffc, /* dst_mask */
281 false), /* pcrel_offset */
283 /* An absolute 16 bit branch, for which bit 10 should be set to
284 indicate that the branch is expected to be taken. The lower two
285 bits must be zero. */
286 HOWTO (R_PPC_ADDR14_BRTAKEN, /* type */
288 2, /* size (0 = byte, 1 = short, 2 = long) */
290 false, /* pc_relative */
292 complain_overflow_bitfield, /* complain_on_overflow */
293 bfd_elf_generic_reloc, /* special_function */
294 "R_PPC_ADDR14_BRTAKEN",/* name */
295 false, /* partial_inplace */
297 0xfffc, /* dst_mask */
298 false), /* pcrel_offset */
300 /* An absolute 16 bit branch, for which bit 10 should be set to
301 indicate that the branch is not expected to be taken. The lower
302 two bits must be zero. */
303 HOWTO (R_PPC_ADDR14_BRNTAKEN, /* type */
305 2, /* size (0 = byte, 1 = short, 2 = long) */
307 false, /* pc_relative */
309 complain_overflow_bitfield, /* complain_on_overflow */
310 bfd_elf_generic_reloc, /* special_function */
311 "R_PPC_ADDR14_BRNTAKEN",/* name */
312 false, /* partial_inplace */
314 0xfffc, /* dst_mask */
315 false), /* pcrel_offset */
317 /* A relative 26 bit branch; the lower two bits must be zero. */
318 HOWTO (R_PPC_REL24, /* type */
320 2, /* size (0 = byte, 1 = short, 2 = long) */
322 true, /* pc_relative */
324 complain_overflow_signed, /* complain_on_overflow */
325 bfd_elf_generic_reloc, /* special_function */
326 "R_PPC_REL24", /* name */
327 false, /* partial_inplace */
329 0x3fffffc, /* dst_mask */
330 true), /* pcrel_offset */
332 /* A relative 16 bit branch; the lower two bits must be zero. */
333 HOWTO (R_PPC_REL14, /* type */
335 2, /* size (0 = byte, 1 = short, 2 = long) */
337 true, /* pc_relative */
339 complain_overflow_signed, /* complain_on_overflow */
340 bfd_elf_generic_reloc, /* special_function */
341 "R_PPC_REL14", /* name */
342 false, /* partial_inplace */
344 0xfffc, /* dst_mask */
345 true), /* pcrel_offset */
347 /* A relative 16 bit branch. Bit 10 should be set to indicate that
348 the branch is expected to be taken. The lower two bits must be
350 HOWTO (R_PPC_REL14_BRTAKEN, /* type */
352 2, /* size (0 = byte, 1 = short, 2 = long) */
354 true, /* pc_relative */
356 complain_overflow_signed, /* complain_on_overflow */
357 bfd_elf_generic_reloc, /* special_function */
358 "R_PPC_REL14_BRTAKEN", /* name */
359 false, /* partial_inplace */
361 0xfffc, /* dst_mask */
362 true), /* pcrel_offset */
364 /* A relative 16 bit branch. Bit 10 should be set to indicate that
365 the branch is not expected to be taken. The lower two bits must
367 HOWTO (R_PPC_REL14_BRNTAKEN, /* type */
369 2, /* size (0 = byte, 1 = short, 2 = long) */
371 true, /* pc_relative */
373 complain_overflow_signed, /* complain_on_overflow */
374 bfd_elf_generic_reloc, /* special_function */
375 "R_PPC_REL14_BRNTAKEN",/* name */
376 false, /* partial_inplace */
378 0xfffc, /* dst_mask */
379 true), /* pcrel_offset */
381 /* Like R_PPC_ADDR16, but referring to the GOT table entry for the
383 HOWTO (R_PPC_GOT16, /* type */
385 1, /* size (0 = byte, 1 = short, 2 = long) */
387 false, /* pc_relative */
389 complain_overflow_signed, /* complain_on_overflow */
390 bfd_elf_generic_reloc, /* special_function */
391 "R_PPC_GOT16", /* name */
392 false, /* partial_inplace */
394 0xffff, /* dst_mask */
395 false), /* pcrel_offset */
397 /* Like R_PPC_ADDR16_LO, but referring to the GOT table entry for
399 HOWTO (R_PPC_GOT16_LO, /* type */
401 1, /* size (0 = byte, 1 = short, 2 = long) */
403 false, /* pc_relative */
405 complain_overflow_bitfield, /* complain_on_overflow */
406 bfd_elf_generic_reloc, /* special_function */
407 "R_PPC_GOT16_LO", /* name */
408 false, /* partial_inplace */
410 0xffff, /* dst_mask */
411 false), /* pcrel_offset */
413 /* Like R_PPC_ADDR16_HI, but referring to the GOT table entry for
415 HOWTO (R_PPC_GOT16_HI, /* type */
417 1, /* size (0 = byte, 1 = short, 2 = long) */
419 false, /* pc_relative */
421 complain_overflow_bitfield, /* complain_on_overflow */
422 bfd_elf_generic_reloc, /* special_function */
423 "R_PPC_GOT16_HI", /* name */
424 false, /* partial_inplace */
426 0xffff, /* dst_mask */
427 false), /* pcrel_offset */
429 /* Like R_PPC_ADDR16_HA, but referring to the GOT table entry for
430 the symbol. FIXME: Not supported. */
431 HOWTO (R_PPC_GOT16_HA, /* type */
433 1, /* size (0 = byte, 1 = short, 2 = long) */
435 false, /* pc_relative */
437 complain_overflow_bitfield, /* complain_on_overflow */
438 bfd_elf_generic_reloc, /* special_function */
439 "R_PPC_GOT16_HA", /* name */
440 false, /* partial_inplace */
442 0xffff, /* dst_mask */
443 false), /* pcrel_offset */
445 /* Like R_PPC_REL24, but referring to the procedure linkage table
446 entry for the symbol. FIXME: Not supported. */
447 HOWTO (R_PPC_PLTREL24, /* type */
449 2, /* size (0 = byte, 1 = short, 2 = long) */
451 true, /* pc_relative */
453 complain_overflow_signed, /* complain_on_overflow */
454 bfd_elf_generic_reloc, /* special_function */
455 "R_PPC_PLTREL24", /* name */
456 false, /* partial_inplace */
458 0x3fffffc, /* dst_mask */
459 true), /* pcrel_offset */
461 /* This is used only by the dynamic linker. The symbol should exist
462 both in the object being run and in some shared library. The
463 dynamic linker copies the data addressed by the symbol from the
464 shared library into the object. I have no idea what the purpose
466 HOWTO (R_PPC_COPY, /* type */
468 2, /* size (0 = byte, 1 = short, 2 = long) */
470 false, /* pc_relative */
472 complain_overflow_bitfield, /* complain_on_overflow */
473 bfd_elf_generic_reloc, /* special_function */
474 "R_PPC_COPY", /* name */
475 false, /* partial_inplace */
478 false), /* pcrel_offset */
480 /* Like R_PPC_ADDR32, but used when setting global offset table
482 HOWTO (R_PPC_GLOB_DAT, /* type */
484 2, /* size (0 = byte, 1 = short, 2 = long) */
486 false, /* pc_relative */
488 complain_overflow_bitfield, /* complain_on_overflow */
489 bfd_elf_generic_reloc, /* special_function */
490 "R_PPC_GLOB_DAT", /* name */
491 false, /* partial_inplace */
493 0xffffffff, /* dst_mask */
494 false), /* pcrel_offset */
496 /* Marks a procedure linkage table entry for a symbol. */
497 HOWTO (R_PPC_JMP_SLOT, /* type */
499 2, /* size (0 = byte, 1 = short, 2 = long) */
501 false, /* pc_relative */
503 complain_overflow_bitfield, /* complain_on_overflow */
504 bfd_elf_generic_reloc, /* special_function */
505 "R_PPC_JMP_SLOT", /* name */
506 false, /* partial_inplace */
509 false), /* pcrel_offset */
511 /* Used only by the dynamic linker. When the object is run, this
512 longword is set to the load address of the object, plus the
514 HOWTO (R_PPC_RELATIVE, /* type */
516 2, /* size (0 = byte, 1 = short, 2 = long) */
518 false, /* pc_relative */
520 complain_overflow_bitfield, /* complain_on_overflow */
521 bfd_elf_generic_reloc, /* special_function */
522 "R_PPC_RELATIVE", /* name */
523 false, /* partial_inplace */
525 0xffffffff, /* dst_mask */
526 false), /* pcrel_offset */
528 /* Like R_PPC_REL24, but uses the value of the symbol within the
529 object rather than the final value. Normally used for
530 _GLOBAL_OFFSET_TABLE_. FIXME: Not supported. */
531 HOWTO (R_PPC_LOCAL24PC, /* type */
533 2, /* size (0 = byte, 1 = short, 2 = long) */
535 true, /* pc_relative */
537 complain_overflow_signed, /* complain_on_overflow */
538 bfd_elf_generic_reloc, /* special_function */
539 "R_PPC_LOCAL24PC", /* name */
540 false, /* partial_inplace */
542 0x3fffffc, /* dst_mask */
543 true), /* pcrel_offset */
545 /* Like R_PPC_ADDR32, but may be unaligned. */
546 HOWTO (R_PPC_UADDR32, /* type */
548 2, /* size (0 = byte, 1 = short, 2 = long) */
550 false, /* pc_relative */
552 complain_overflow_bitfield, /* complain_on_overflow */
553 bfd_elf_generic_reloc, /* special_function */
554 "R_PPC_UADDR32", /* name */
555 false, /* partial_inplace */
557 0xffffffff, /* dst_mask */
558 false), /* pcrel_offset */
560 /* Like R_PPC_ADDR16, but may be unaligned. */
561 HOWTO (R_PPC_UADDR16, /* type */
563 1, /* size (0 = byte, 1 = short, 2 = long) */
565 false, /* pc_relative */
567 complain_overflow_bitfield, /* complain_on_overflow */
568 bfd_elf_generic_reloc, /* special_function */
569 "R_PPC_UADDR16", /* name */
570 false, /* partial_inplace */
572 0xffff, /* dst_mask */
573 false), /* pcrel_offset */
575 /* 32-bit PC relative */
576 HOWTO (R_PPC_REL32, /* type */
578 2, /* size (0 = byte, 1 = short, 2 = long) */
580 true, /* pc_relative */
582 complain_overflow_bitfield, /* complain_on_overflow */
583 bfd_elf_generic_reloc, /* special_function */
584 "R_PPC_REL32", /* name */
585 false, /* partial_inplace */
587 0xffffffff, /* dst_mask */
588 true), /* pcrel_offset */
590 /* 32-bit relocation to the symbol's procedure linkage table.
591 FIXEME: not supported. */
592 HOWTO (R_PPC_PLT32, /* type */
594 2, /* size (0 = byte, 1 = short, 2 = long) */
596 false, /* pc_relative */
598 complain_overflow_bitfield, /* complain_on_overflow */
599 bfd_elf_generic_reloc, /* special_function */
600 "R_PPC_PLT32", /* name */
601 false, /* partial_inplace */
604 false), /* pcrel_offset */
606 /* 32-bit PC relative relocation to the symbol's procedure linkage table.
607 FIXEME: not supported. */
608 HOWTO (R_PPC_PLTREL32, /* type */
610 2, /* size (0 = byte, 1 = short, 2 = long) */
612 true, /* pc_relative */
614 complain_overflow_bitfield, /* complain_on_overflow */
615 bfd_elf_generic_reloc, /* special_function */
616 "R_PPC_PLTREL32", /* name */
617 false, /* partial_inplace */
620 true), /* pcrel_offset */
622 /* Like R_PPC_ADDR16_LO, but referring to the PLT table entry for
624 HOWTO (R_PPC_PLT16_LO, /* type */
626 1, /* size (0 = byte, 1 = short, 2 = long) */
628 false, /* pc_relative */
630 complain_overflow_bitfield, /* complain_on_overflow */
631 bfd_elf_generic_reloc, /* special_function */
632 "R_PPC_PLT16_LO", /* name */
633 false, /* partial_inplace */
635 0xffff, /* dst_mask */
636 false), /* pcrel_offset */
638 /* Like R_PPC_ADDR16_HI, but referring to the PLT table entry for
640 HOWTO (R_PPC_PLT16_HI, /* type */
642 1, /* size (0 = byte, 1 = short, 2 = long) */
644 false, /* pc_relative */
646 complain_overflow_bitfield, /* complain_on_overflow */
647 bfd_elf_generic_reloc, /* special_function */
648 "R_PPC_PLT16_HI", /* name */
649 false, /* partial_inplace */
651 0xffff, /* dst_mask */
652 false), /* pcrel_offset */
654 /* Like R_PPC_ADDR16_HA, but referring to the PLT table entry for
655 the symbol. FIXME: Not supported. */
656 HOWTO (R_PPC_PLT16_HA, /* type */
658 1, /* size (0 = byte, 1 = short, 2 = long) */
660 false, /* pc_relative */
662 complain_overflow_bitfield, /* complain_on_overflow */
663 bfd_elf_generic_reloc, /* special_function */
664 "R_PPC_PLT16_HA", /* name */
665 false, /* partial_inplace */
667 0xffff, /* dst_mask */
668 false), /* pcrel_offset */
670 /* A sign-extended 16 bit value relative to _SDA_BASE_, for use with
671 small data items. FIXME: Not supported. */
672 HOWTO (R_PPC_SDAREL16, /* type */
674 1, /* size (0 = byte, 1 = short, 2 = long) */
676 false, /* pc_relative */
678 complain_overflow_signed, /* complain_on_overflow */
679 bfd_elf_generic_reloc, /* special_function */
680 "R_PPC_SDAREL16", /* name */
681 false, /* partial_inplace */
683 0xffff, /* dst_mask */
684 false), /* pcrel_offset */
686 /* 32-bit section relative relocation. FIXME: not supported. */
687 HOWTO (R_PPC_SECTOFF, /* type */
689 2, /* size (0 = byte, 1 = short, 2 = long) */
691 true, /* pc_relative */
693 complain_overflow_bitfield, /* complain_on_overflow */
694 bfd_elf_generic_reloc, /* special_function */
695 "R_PPC_SECTOFF", /* name */
696 false, /* partial_inplace */
699 true), /* pcrel_offset */
701 /* 16-bit lower half section relative relocation. FIXME: not supported. */
702 HOWTO (R_PPC_SECTOFF_LO, /* type */
704 1, /* size (0 = byte, 1 = short, 2 = long) */
706 false, /* pc_relative */
708 complain_overflow_bitfield, /* complain_on_overflow */
709 bfd_elf_generic_reloc, /* special_function */
710 "R_PPC_SECTOFF_LO", /* name */
711 false, /* partial_inplace */
713 0xffff, /* dst_mask */
714 false), /* pcrel_offset */
716 /* 16-bit upper half section relative relocation. FIXME: not supported. */
717 HOWTO (R_PPC_SECTOFF_HI, /* type */
719 1, /* size (0 = byte, 1 = short, 2 = long) */
721 false, /* pc_relative */
723 complain_overflow_bitfield, /* complain_on_overflow */
724 bfd_elf_generic_reloc, /* special_function */
725 "R_PPC_SECTOFF_HI", /* name */
726 false, /* partial_inplace */
728 0xffff, /* dst_mask */
729 false), /* pcrel_offset */
731 /* 16-bit upper half adjusted section relative relocation. FIXME: not supported. */
732 HOWTO (R_PPC_SECTOFF_HA, /* type */
734 1, /* size (0 = byte, 1 = short, 2 = long) */
736 false, /* pc_relative */
738 complain_overflow_bitfield, /* complain_on_overflow */
739 bfd_elf_generic_reloc, /* special_function */
740 "R_PPC_SECTOFF_HA", /* name */
741 false, /* partial_inplace */
743 0xffff, /* dst_mask */
744 false), /* pcrel_offset */
746 /* The remaining relocs are from the Embedded ELF ABI, and are not
747 in the SVR4 ELF ABI. */
749 /* 32 bit value resulting from the addend minus the symbol */
750 HOWTO (R_PPC_EMB_NADDR32, /* type */
752 2, /* size (0 = byte, 1 = short, 2 = long) */
754 false, /* pc_relative */
756 complain_overflow_bitfield, /* complain_on_overflow */
757 bfd_elf_generic_reloc, /* special_function */
758 "R_PPC_EMB_NADDR32", /* name */
759 false, /* partial_inplace */
761 0xffffffff, /* dst_mask */
762 false), /* pcrel_offset */
764 /* 16 bit value resulting from the addend minus the symbol */
765 HOWTO (R_PPC_EMB_NADDR16, /* type */
767 1, /* size (0 = byte, 1 = short, 2 = long) */
769 false, /* pc_relative */
771 complain_overflow_bitfield, /* complain_on_overflow */
772 bfd_elf_generic_reloc, /* special_function */
773 "R_PPC_EMB_NADDR16", /* name */
774 false, /* partial_inplace */
776 0xffff, /* dst_mask */
777 false), /* pcrel_offset */
779 /* 16 bit value resulting from the addend minus the symbol */
780 HOWTO (R_PPC_EMB_NADDR16_LO, /* type */
782 1, /* size (0 = byte, 1 = short, 2 = long) */
784 false, /* pc_relative */
786 complain_overflow_dont,/* complain_on_overflow */
787 bfd_elf_generic_reloc, /* special_function */
788 "R_PPC_EMB_ADDR16_LO", /* name */
789 false, /* partial_inplace */
791 0xffff, /* dst_mask */
792 false), /* pcrel_offset */
794 /* The high order 16 bits of the addend minus the symbol */
795 HOWTO (R_PPC_EMB_NADDR16_HI, /* type */
797 1, /* size (0 = byte, 1 = short, 2 = long) */
799 false, /* pc_relative */
801 complain_overflow_dont, /* complain_on_overflow */
802 bfd_elf_generic_reloc, /* special_function */
803 "R_PPC_EMB_NADDR16_HI", /* name */
804 false, /* partial_inplace */
806 0xffff, /* dst_mask */
807 false), /* pcrel_offset */
809 /* The high order 16 bits of the result of the addend minus the address,
810 plus 1 if the contents of the low 16 bits, treated as a signed number,
812 HOWTO (R_PPC_EMB_NADDR16_HA, /* type */
814 1, /* size (0 = byte, 1 = short, 2 = long) */
816 false, /* pc_relative */
818 complain_overflow_dont, /* complain_on_overflow */
819 bfd_elf_generic_reloc, /* special_function */
820 "R_PPC_EMB_NADDR16_HA", /* name */
821 false, /* partial_inplace */
823 0xffff, /* dst_mask */
824 false), /* pcrel_offset */
826 /* 16 bit value resulting from allocating a 4 byte word to hold an
827 address in the .sdata section, and returning the offset from
828 _SDA_BASE_ for that relocation */
829 HOWTO (R_PPC_EMB_SDAI16, /* type */
831 1, /* size (0 = byte, 1 = short, 2 = long) */
833 false, /* pc_relative */
835 complain_overflow_bitfield, /* complain_on_overflow */
836 bfd_elf_generic_reloc, /* special_function */
837 "R_PPC_EMB_SDAI16", /* name */
838 false, /* partial_inplace */
840 0xffff, /* dst_mask */
841 false), /* pcrel_offset */
843 /* 16 bit value resulting from allocating a 4 byte word to hold an
844 address in the .sdata2 section, and returning the offset from
845 _SDA2_BASE_ for that relocation */
846 HOWTO (R_PPC_EMB_SDA2I16, /* type */
848 1, /* size (0 = byte, 1 = short, 2 = long) */
850 false, /* pc_relative */
852 complain_overflow_bitfield, /* complain_on_overflow */
853 bfd_elf_generic_reloc, /* special_function */
854 "R_PPC_EMB_SDA2I16", /* name */
855 false, /* partial_inplace */
857 0xffff, /* dst_mask */
858 false), /* pcrel_offset */
860 /* A sign-extended 16 bit value relative to _SDA2_BASE_, for use with
861 small data items. FIXME: Not supported. */
862 HOWTO (R_PPC_EMB_SDA2REL, /* type */
864 1, /* size (0 = byte, 1 = short, 2 = long) */
866 false, /* pc_relative */
868 complain_overflow_signed, /* complain_on_overflow */
869 bfd_elf_generic_reloc, /* special_function */
870 "R_PPC_EMB_SDA2REL", /* name */
871 false, /* partial_inplace */
873 0xffff, /* dst_mask */
874 false), /* pcrel_offset */
876 /* Relocate against either _SDA_BASE_ or _SDA2_BASE_, filling in the 16 bit
877 signed offset from the appropriate base, and filling in the register
878 field with the appropriate register (0, 2, or 13). */
879 HOWTO (R_PPC_EMB_SDA21, /* type */
881 1, /* size (0 = byte, 1 = short, 2 = long) */
883 false, /* pc_relative */
885 complain_overflow_signed, /* complain_on_overflow */
886 bfd_elf_generic_reloc, /* special_function */
887 "R_PPC_EMB_SDA21", /* name */
888 false, /* partial_inplace */
890 0xffff, /* dst_mask */
891 false), /* pcrel_offset */
893 /* Relocation not handled: R_PPC_EMB_MRKREF */
894 /* Relocation not handled: R_PPC_EMB_RELSEC16 */
895 /* Relocation not handled: R_PPC_EMB_RELST_LO */
896 /* Relocation not handled: R_PPC_EMB_RELST_HI */
897 /* Relocation not handled: R_PPC_EMB_RELST_HA */
898 /* Relocation not handled: R_PPC_EMB_BIT_FLD */
900 /* PC relative relocation against either _SDA_BASE_ or _SDA2_BASE_, filling
901 in the 16 bit signed offset from the appropriate base, and filling in the
902 register field with the appropriate register (0, 2, or 13). */
903 HOWTO (R_PPC_EMB_RELSDA, /* type */
905 1, /* size (0 = byte, 1 = short, 2 = long) */
907 true, /* pc_relative */
909 complain_overflow_signed, /* complain_on_overflow */
910 bfd_elf_generic_reloc, /* special_function */
911 "R_PPC_EMB_RELSDA", /* name */
912 false, /* partial_inplace */
914 0xffff, /* dst_mask */
915 false), /* pcrel_offset */
917 /* Phony reloc to handle AIX style TOC entries */
918 HOWTO (R_PPC_TOC16, /* type */
920 1, /* size (0 = byte, 1 = short, 2 = long) */
922 false, /* pc_relative */
924 complain_overflow_signed, /* complain_on_overflow */
925 bfd_elf_generic_reloc, /* special_function */
926 "R_PPC_TOC16", /* name */
927 false, /* partial_inplace */
929 0xffff, /* dst_mask */
930 false), /* pcrel_offset */
934 /* Initialize the ppc_elf_howto_table, so that linear accesses can be done. */
937 ppc_elf_howto_init ()
939 unsigned int i, type;
941 for (i = 0; i < sizeof (ppc_elf_howto_raw) / sizeof (ppc_elf_howto_raw[0]); i++)
943 type = ppc_elf_howto_raw[i].type;
944 BFD_ASSERT (type < sizeof(ppc_elf_howto_table) / sizeof(ppc_elf_howto_table[0]));
945 ppc_elf_howto_table[type] = &ppc_elf_howto_raw[i];
950 static reloc_howto_type *
951 ppc_elf_reloc_type_lookup (abfd, code)
953 bfd_reloc_code_real_type code;
955 enum ppc_reloc_type ppc_reloc = R_PPC_NONE;
957 if (!ppc_elf_howto_table[ R_PPC_ADDR32 ]) /* Initialize howto table if needed */
958 ppc_elf_howto_init ();
963 return (reloc_howto_type *)NULL;
965 case BFD_RELOC_NONE: ppc_reloc = R_PPC_NONE; break;
966 case BFD_RELOC_32: ppc_reloc = R_PPC_ADDR32; break;
967 case BFD_RELOC_PPC_BA26: ppc_reloc = R_PPC_ADDR24; break;
968 case BFD_RELOC_16: ppc_reloc = R_PPC_ADDR16; break;
969 case BFD_RELOC_LO16: ppc_reloc = R_PPC_ADDR16_LO; break;
970 case BFD_RELOC_HI16: ppc_reloc = R_PPC_ADDR16_HI; break;
971 case BFD_RELOC_HI16_S: ppc_reloc = R_PPC_ADDR16_HA; break;
972 case BFD_RELOC_PPC_BA16: ppc_reloc = R_PPC_ADDR14; break;
973 case BFD_RELOC_PPC_BA16_BRTAKEN: ppc_reloc = R_PPC_ADDR14_BRTAKEN; break;
974 case BFD_RELOC_PPC_BA16_BRNTAKEN: ppc_reloc = R_PPC_ADDR14_BRNTAKEN; break;
975 case BFD_RELOC_PPC_B26: ppc_reloc = R_PPC_REL24; break;
976 case BFD_RELOC_PPC_B16: ppc_reloc = R_PPC_REL14; break;
977 case BFD_RELOC_PPC_B16_BRTAKEN: ppc_reloc = R_PPC_REL14_BRTAKEN; break;
978 case BFD_RELOC_PPC_B16_BRNTAKEN: ppc_reloc = R_PPC_REL14_BRNTAKEN; break;
979 case BFD_RELOC_16_GOTOFF: ppc_reloc = R_PPC_GOT16; break;
980 case BFD_RELOC_LO16_GOTOFF: ppc_reloc = R_PPC_GOT16_LO; break;
981 case BFD_RELOC_HI16_GOTOFF: ppc_reloc = R_PPC_GOT16_HI; break;
982 case BFD_RELOC_HI16_S_GOTOFF: ppc_reloc = R_PPC_GOT16_HA; break;
983 case BFD_RELOC_24_PLT_PCREL: ppc_reloc = R_PPC_PLTREL24; break;
984 case BFD_RELOC_PPC_COPY: ppc_reloc = R_PPC_COPY; break;
985 case BFD_RELOC_PPC_GLOB_DAT: ppc_reloc = R_PPC_GLOB_DAT; break;
986 case BFD_RELOC_PPC_LOCAL24PC: ppc_reloc = R_PPC_LOCAL24PC; break;
987 case BFD_RELOC_32_PCREL: ppc_reloc = R_PPC_REL32; break;
988 case BFD_RELOC_32_PLTOFF: ppc_reloc = R_PPC_PLT32; break;
989 case BFD_RELOC_32_PLT_PCREL: ppc_reloc = R_PPC_PLTREL32; break;
990 case BFD_RELOC_LO16_PLTOFF: ppc_reloc = R_PPC_PLT16_LO; break;
991 case BFD_RELOC_HI16_PLTOFF: ppc_reloc = R_PPC_PLT16_HI; break;
992 case BFD_RELOC_HI16_S_PLTOFF: ppc_reloc = R_PPC_PLT16_HA; break;
993 case BFD_RELOC_GPREL16: ppc_reloc = R_PPC_SDAREL16; break;
994 case BFD_RELOC_32_BASEREL: ppc_reloc = R_PPC_SECTOFF; break;
995 case BFD_RELOC_LO16_BASEREL: ppc_reloc = R_PPC_SECTOFF_LO; break;
996 case BFD_RELOC_HI16_BASEREL: ppc_reloc = R_PPC_SECTOFF_HI; break;
997 case BFD_RELOC_HI16_S_BASEREL: ppc_reloc = R_PPC_SECTOFF_HA; break;
998 case BFD_RELOC_CTOR: ppc_reloc = R_PPC_ADDR32; break;
999 case BFD_RELOC_PPC_TOC16: ppc_reloc = R_PPC_TOC16; break;
1000 case BFD_RELOC_PPC_EMB_NADDR32: ppc_reloc = R_PPC_EMB_NADDR32; break;
1001 case BFD_RELOC_PPC_EMB_NADDR16: ppc_reloc = R_PPC_EMB_NADDR16; break;
1002 case BFD_RELOC_PPC_EMB_NADDR16_LO: ppc_reloc = R_PPC_EMB_NADDR16_LO; break;
1003 case BFD_RELOC_PPC_EMB_NADDR16_HI: ppc_reloc = R_PPC_EMB_NADDR16_HI; break;
1004 case BFD_RELOC_PPC_EMB_NADDR16_HA: ppc_reloc = R_PPC_EMB_NADDR16_HA; break;
1005 case BFD_RELOC_PPC_EMB_SDAI16: ppc_reloc = R_PPC_EMB_SDAI16; break;
1006 case BFD_RELOC_PPC_EMB_SDA2I16: ppc_reloc = R_PPC_EMB_SDA2I16; break;
1007 case BFD_RELOC_PPC_EMB_SDA2REL: ppc_reloc = R_PPC_EMB_SDA2REL; break;
1008 case BFD_RELOC_PPC_EMB_SDA21: ppc_reloc = R_PPC_EMB_SDA21; break;
1009 case BFD_RELOC_PPC_EMB_MRKREF: ppc_reloc = R_PPC_EMB_MRKREF; break;
1010 case BFD_RELOC_PPC_EMB_RELSEC16: ppc_reloc = R_PPC_EMB_RELSEC16; break;
1011 case BFD_RELOC_PPC_EMB_RELST_LO: ppc_reloc = R_PPC_EMB_RELST_LO; break;
1012 case BFD_RELOC_PPC_EMB_RELST_HI: ppc_reloc = R_PPC_EMB_RELST_HI; break;
1013 case BFD_RELOC_PPC_EMB_RELST_HA: ppc_reloc = R_PPC_EMB_RELST_HA; break;
1014 case BFD_RELOC_PPC_EMB_BIT_FLD: ppc_reloc = R_PPC_EMB_BIT_FLD; break;
1015 case BFD_RELOC_PPC_EMB_RELSDA: ppc_reloc = R_PPC_EMB_RELSDA; break;
1018 return ppc_elf_howto_table[ (int)ppc_reloc ];
1021 /* Set the howto pointer for a PowerPC ELF reloc. */
1024 ppc_elf_info_to_howto (abfd, cache_ptr, dst)
1027 Elf32_Internal_Rela *dst;
1029 if (!ppc_elf_howto_table[ R_PPC_ADDR32 ]) /* Initialize howto table if needed */
1030 ppc_elf_howto_init ();
1032 BFD_ASSERT (ELF32_R_TYPE (dst->r_info) < (unsigned int) R_PPC_max);
1033 cache_ptr->howto = ppc_elf_howto_table[ELF32_R_TYPE (dst->r_info)];
1036 /* Function to set whether a module needs the -mrelocatable bit set. */
1039 ppc_elf_set_private_flags (abfd, flags)
1043 BFD_ASSERT (!elf_flags_init (abfd)
1044 || elf_elfheader (abfd)->e_flags == flags);
1046 elf_elfheader (abfd)->e_flags = flags;
1047 elf_flags_init (abfd) = true;
1051 /* Copy backend specific data from one object module to another */
1053 ppc_elf_copy_private_bfd_data (ibfd, obfd)
1057 /* This function is selected based on the input vector. We only
1058 want to copy information over if the output BFD also uses Elf
1060 if (bfd_get_flavour (obfd) != bfd_target_elf_flavour)
1063 BFD_ASSERT (!elf_flags_init (obfd)
1064 || elf_elfheader (obfd)->e_flags == elf_elfheader (ibfd)->e_flags);
1066 elf_elfheader (obfd)->e_flags = elf_elfheader (ibfd)->e_flags;
1067 elf_flags_init (obfd) = true;
1071 /* Merge backend specific data from an object file to the output
1072 object file when linking */
1074 ppc_elf_merge_private_bfd_data (ibfd, obfd)
1082 /* Check if we have the same endianess */
1083 if (ibfd->xvec->byteorder != obfd->xvec->byteorder
1084 && obfd->xvec->byteorder != BFD_ENDIAN_UNKNOWN)
1086 (*_bfd_error_handler)
1087 ("%s: compiled for a %s endian system and target is %s endian",
1088 bfd_get_filename (ibfd),
1089 bfd_big_endian (ibfd) ? "big" : "little",
1090 bfd_big_endian (obfd) ? "big" : "little");
1092 bfd_set_error (bfd_error_wrong_format);
1096 /* This function is selected based on the input vector. We only
1097 want to copy information over if the output BFD also uses Elf
1099 if (bfd_get_flavour (obfd) != bfd_target_elf_flavour)
1102 new_flags = elf_elfheader (ibfd)->e_flags;
1103 old_flags = elf_elfheader (obfd)->e_flags;
1104 if (!elf_flags_init (obfd)) /* First call, no flags set */
1106 elf_flags_init (obfd) = true;
1107 elf_elfheader (obfd)->e_flags = new_flags;
1110 else if (new_flags == old_flags) /* Compatible flags are ok */
1113 else /* Incompatible flags */
1115 /* Warn about -mrelocatable mismatch. Allow -mrelocatable-lib to be linked
1118 if ((new_flags & EF_PPC_RELOCATABLE) != 0
1119 && (old_flags & (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB)) == 0)
1122 (*_bfd_error_handler)
1123 ("%s: compiled with -mrelocatable and linked with modules compiled normally",
1124 bfd_get_filename (ibfd));
1126 else if ((new_flags & (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB)) == 0
1127 && (old_flags & EF_PPC_RELOCATABLE) != 0)
1130 (*_bfd_error_handler)
1131 ("%s: compiled normally and linked with modules compiled with -mrelocatable",
1132 bfd_get_filename (ibfd));
1134 else if ((new_flags & EF_PPC_RELOCATABLE_LIB) != 0)
1135 elf_elfheader (obfd)->e_flags |= EF_PPC_RELOCATABLE_LIB;
1138 /* Do not warn about eabi vs. V.4 mismatch, just or in the bit if any module uses it */
1139 elf_elfheader (obfd)->e_flags |= (new_flags & EF_PPC_EMB);
1141 new_flags &= ~ (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB | EF_PPC_EMB);
1142 old_flags &= ~ (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB | EF_PPC_EMB);
1144 /* Warn about any other mismatches */
1145 if (new_flags != old_flags)
1148 (*_bfd_error_handler)
1149 ("%s: uses different e_flags (0x%lx) fields than previous modules (0x%lx)",
1150 bfd_get_filename (ibfd), (long)new_flags, (long)old_flags);
1155 bfd_set_error (bfd_error_bad_value);
1164 /* Handle a PowerPC specific section when reading an object file. This
1165 is called when elfcode.h finds a section with an unknown type. */
1168 ppc_elf_section_from_shdr (abfd, hdr, name)
1170 Elf32_Internal_Shdr *hdr;
1176 if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name))
1179 newsect = hdr->bfd_section;
1180 flags = bfd_get_section_flags (abfd, newsect);
1181 if (hdr->sh_flags & SHF_EXCLUDE)
1182 flags |= SEC_EXCLUDE;
1184 if (hdr->sh_type == SHT_ORDERED)
1185 flags |= SEC_SORT_ENTRIES;
1187 bfd_set_section_flags (abfd, newsect, flags);
1192 /* Set up any other section flags and such that may be necessary. */
1195 ppc_elf_fake_sections (abfd, shdr, asect)
1197 Elf32_Internal_Shdr *shdr;
1200 if ((asect->flags & SEC_EXCLUDE) != 0)
1201 shdr->sh_flags |= SHF_EXCLUDE;
1203 if ((asect->flags & SEC_SORT_ENTRIES) != 0)
1204 shdr->sh_type = SHT_ORDERED;
1208 /* Create a special linker section */
1209 static elf_linker_section_t *
1210 ppc_elf_create_linker_section (abfd, info, which)
1212 struct bfd_link_info *info;
1213 enum elf_linker_section_enum which;
1215 bfd *dynobj = elf_hash_table (info)->dynobj;
1216 elf_linker_section_t *lsect;
1218 /* Record the first bfd section that needs the special section */
1220 dynobj = elf_hash_table (info)->dynobj = abfd;
1222 /* If this is the first time, create the section */
1223 lsect = elf_linker_section (dynobj, which);
1226 elf_linker_section_t defaults;
1227 static elf_linker_section_t zero_section;
1229 defaults = zero_section;
1230 defaults.which = which;
1231 defaults.hole_written_p = false;
1232 defaults.alignment = 2;
1233 defaults.flags = SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY;
1238 (*_bfd_error_handler) ("%s: Unknown special linker type %d",
1239 bfd_get_filename (abfd),
1242 bfd_set_error (bfd_error_bad_value);
1243 return (elf_linker_section_t *)0;
1245 case LINKER_SECTION_GOT: /* .got section */
1246 defaults.name = ".got";
1247 defaults.rel_name = ".rela.got";
1248 defaults.sym_name = "_GLOBAL_OFFSET_TABLE_";
1249 defaults.max_hole_offset = 32764;
1250 defaults.hole_size = 16;
1251 defaults.sym_offset = 4;
1254 case LINKER_SECTION_SDATA: /* .sdata/.sbss section */
1255 defaults.name = ".sdata";
1256 defaults.rel_name = ".rela.sdata";
1257 defaults.bss_name = ".sbss";
1258 defaults.sym_name = "_SDA_BASE_";
1259 defaults.sym_offset = 32768;
1262 case LINKER_SECTION_SDATA2: /* .sdata2/.sbss2 section */
1263 defaults.name = ".sdata2";
1264 defaults.rel_name = ".rela.sdata2";
1265 defaults.bss_name = ".sbss2";
1266 defaults.sym_name = "_SDA2_BASE_";
1267 defaults.sym_offset = 32768;
1271 lsect = _bfd_elf_create_linker_section (abfd, info, which, &defaults);
1278 /* Adjust a symbol defined by a dynamic object and referenced by a
1279 regular object. The current definition is in some section of the
1280 dynamic object, but we're not including those sections. We have to
1281 change the definition to something the rest of the link can
1285 ppc_elf_adjust_dynamic_symbol (info, h)
1286 struct bfd_link_info *info;
1287 struct elf_link_hash_entry *h;
1290 fprintf (stderr, "ppc_elf_adjust_dynamic_symbol called\n");
1296 /* Increment the index of a dynamic symbol by a given amount. Called
1297 via elf_link_hash_traverse. */
1300 ppc_elf_adjust_dynindx (h, cparg)
1301 struct elf_link_hash_entry *h;
1304 int *cp = (int *) cparg;
1307 fprintf (stderr, "ppc_elf_adjust_dynindx called, h->dynindx = %d, *cp = %d\n", h->dynindx, *cp);
1310 if (h->dynindx != -1)
1317 /* Set the sizes of the dynamic sections. */
1320 ppc_elf_size_dynamic_sections (output_bfd, info)
1322 struct bfd_link_info *info;
1330 fprintf (stderr, "ppc_elf_size_dynamic_sections called\n");
1333 dynobj = elf_hash_table (info)->dynobj;
1334 BFD_ASSERT (dynobj != NULL);
1336 if (elf_hash_table (info)->dynamic_sections_created)
1338 /* Set the contents of the .interp section to the interpreter. */
1341 s = bfd_get_section_by_name (dynobj, ".interp");
1342 BFD_ASSERT (s != NULL);
1343 s->_raw_size = sizeof ELF_DYNAMIC_INTERPRETER;
1344 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
1347 /* Make space for the trailing nop in .plt. */
1348 s = bfd_get_section_by_name (dynobj, ".plt");
1349 BFD_ASSERT (s != NULL);
1350 if (s->_raw_size > 0)
1355 /* We may have created entries in the .rela.got, .rela.sdata, and
1356 .rela.sdata2 section2. However, if we are not creating the
1357 dynamic sections, we will not actually use these entries. Reset
1358 the size of .rela.got, et al, which will cause it to get
1359 stripped from the output file below. */
1360 static char *rela_sections[] = { ".rela.got", ".rela.sdata", ".rela.sdata", (char *)0 };
1363 for (p = rela_sections; *p != (char *)0; p++)
1365 s = bfd_get_section_by_name (dynobj, *p);
1371 /* The check_relocs and adjust_dynamic_symbol entry points have
1372 determined the sizes of the various dynamic sections. Allocate
1376 for (s = dynobj->sections; s != NULL; s = s->next)
1381 if ((s->flags & SEC_IN_MEMORY) == 0)
1384 /* It's OK to base decisions on the section name, because none
1385 of the dynobj section names depend upon the input files. */
1386 name = bfd_get_section_name (dynobj, s);
1391 if (strncmp (name, ".rela", 5) == 0)
1393 if (s->_raw_size == 0)
1395 /* If we don't need this section, strip it from the
1396 output file. This is to handle .rela.bss and
1397 .rel.plt. We must create it in
1398 create_dynamic_sections, because it must be created
1399 before the linker maps input sections to output
1400 sections. The linker does that before
1401 adjust_dynamic_symbol is called, and it is that
1402 function which decides whether anything needs to go
1403 into these sections. */
1410 /* If this relocation section applies to a read only
1411 section, then we probably need a DT_TEXTREL entry. */
1412 target = bfd_get_section_by_name (output_bfd, name + 5);
1414 && (target->flags & SEC_READONLY) != 0)
1417 if (strcmp (name, ".rela.plt") == 0)
1420 /* We use the reloc_count field as a counter if we need
1421 to copy relocs into the output file. */
1427 if (strcmp (name, ".plt") != 0
1428 && strcmp (name, ".got") != 0
1429 && strcmp (name, ".sdata") != 0
1430 && strcmp (name, ".sdata2") != 0)
1432 /* It's not one of our sections, so don't allocate space. */
1440 for (spp = &s->output_section->owner->sections;
1441 *spp != s->output_section;
1442 spp = &(*spp)->next)
1444 *spp = s->output_section->next;
1445 --s->output_section->owner->section_count;
1450 /* Allocate memory for the section contents. */
1451 s->contents = (bfd_byte *) bfd_alloc (dynobj, s->_raw_size);
1452 if (s->contents == NULL && s->_raw_size != 0)
1456 if (elf_hash_table (info)->dynamic_sections_created)
1458 /* Add some entries to the .dynamic section. We fill in the
1459 values later, in ppc_elf_finish_dynamic_sections, but we
1460 must add the entries now so that we get the correct size for
1461 the .dynamic section. The DT_DEBUG entry is filled in by the
1462 dynamic linker and used by the debugger. */
1465 if (! bfd_elf32_add_dynamic_entry (info, DT_DEBUG, 0))
1469 if (! bfd_elf32_add_dynamic_entry (info, DT_PLTGOT, 0))
1474 if (! bfd_elf32_add_dynamic_entry (info, DT_PLTRELSZ, 0)
1475 || ! bfd_elf32_add_dynamic_entry (info, DT_PLTREL, DT_RELA)
1476 || ! bfd_elf32_add_dynamic_entry (info, DT_JMPREL, 0))
1480 if (! bfd_elf32_add_dynamic_entry (info, DT_RELA, 0)
1481 || ! bfd_elf32_add_dynamic_entry (info, DT_RELASZ, 0)
1482 || ! bfd_elf32_add_dynamic_entry (info, DT_RELAENT,
1483 sizeof (Elf32_External_Rela)))
1488 if (! bfd_elf32_add_dynamic_entry (info, DT_TEXTREL, 0))
1493 /* If we are generating a shared library, we generate a section
1494 symbol for each output section. These are local symbols, which
1495 means that they must come first in the dynamic symbol table.
1496 That means we must increment the dynamic symbol index of every
1497 other dynamic symbol. */
1502 c = bfd_count_sections (output_bfd);
1503 elf_link_hash_traverse (elf_hash_table (info),
1504 ppc_elf_adjust_dynindx,
1506 elf_hash_table (info)->dynsymcount += c;
1508 for (i = 1, s = output_bfd->sections; s != NULL; s = s->next, i++)
1510 elf_section_data (s)->dynindx = i;
1511 /* These symbols will have no names, so we don't need to
1512 fiddle with dynstr_index. */
1520 /* Look through the relocs for a section during the first phase, and
1521 allocate space in the global offset table or procedure linkage
1525 ppc_elf_check_relocs (abfd, info, sec, relocs)
1527 struct bfd_link_info *info;
1529 const Elf_Internal_Rela *relocs;
1532 Elf_Internal_Shdr *symtab_hdr;
1533 struct elf_link_hash_entry **sym_hashes;
1534 const Elf_Internal_Rela *rel;
1535 const Elf_Internal_Rela *rel_end;
1536 elf_linker_section_t *got;
1537 elf_linker_section_t *sdata;
1538 elf_linker_section_t *sdata2;
1541 if (info->relocateable)
1545 fprintf (stderr, "ppc_elf_check_relocs called for section %s\n",
1546 bfd_get_section_name (abfd, sec));
1549 /* Create the linker generated sections all the time so that the special
1550 symbols are created. */
1551 if ((got = elf_linker_section (abfd, LINKER_SECTION_GOT)) == NULL)
1553 got = ppc_elf_create_linker_section (abfd, info, LINKER_SECTION_GOT);
1558 if ((sdata = elf_linker_section (abfd, LINKER_SECTION_SDATA)) == NULL)
1560 sdata = ppc_elf_create_linker_section (abfd, info, LINKER_SECTION_SDATA);
1566 if ((sdata2 = elf_linker_section (abfd, LINKER_SECTION_SDATA2)) == NULL)
1568 sdata2 = ppc_elf_create_linker_section (abfd, info, LINKER_SECTION_SDATA2);
1573 dynobj = elf_hash_table (info)->dynobj;
1574 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
1575 sym_hashes = elf_sym_hashes (abfd);
1579 rel_end = relocs + sec->reloc_count;
1580 for (rel = relocs; rel < rel_end; rel++)
1582 unsigned long r_symndx;
1583 struct elf_link_hash_entry *h;
1585 r_symndx = ELF32_R_SYM (rel->r_info);
1586 if (r_symndx < symtab_hdr->sh_info)
1589 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
1591 switch (ELF32_R_TYPE (rel->r_info))
1596 /* GOT16 relocations */
1598 case R_PPC_GOT16_LO:
1599 case R_PPC_GOT16_HI:
1600 case R_PPC_GOT16_HA:
1601 if (got->rel_section == NULL
1602 && (h != NULL || info->shared)
1603 && !_bfd_elf_make_linker_section_rela (dynobj, got, 2))
1606 if (!bfd_elf32_create_pointer_linker_section (abfd, info, got, h, rel))
1611 /* Indirect .sdata relocation */
1612 case R_PPC_EMB_SDAI16:
1613 if (got->rel_section == NULL
1614 && (h != NULL || info->shared)
1615 && !_bfd_elf_make_linker_section_rela (dynobj, got, 2))
1618 BFD_ASSERT (!info->shared);
1619 if (!bfd_elf32_create_pointer_linker_section (abfd, info, sdata, h, rel))
1624 /* Indirect .sdata2 relocation */
1625 case R_PPC_EMB_SDA2I16:
1626 if (got->rel_section == NULL
1627 && (h != NULL || info->shared)
1628 && !_bfd_elf_make_linker_section_rela (dynobj, got, 2))
1631 BFD_ASSERT (!info->shared);
1632 if (!bfd_elf32_create_pointer_linker_section (abfd, info, sdata2, h, rel))
1639 case R_PPC_PLTREL24:
1640 case R_PPC_PLT16_LO:
1641 case R_PPC_PLT16_HI:
1642 case R_PPC_PLT16_HA:
1644 fprintf (stderr, "Reloc requires a PLT entry\n");
1646 /* This symbol requires a procedure linkage table entry. We
1647 actually build the entry in adjust_dynamic_symbol,
1648 because this might be a case of linking PIC code without
1649 linking in any dynamic objects, in which case we don't
1650 need to generate a procedure linkage table after all. */
1654 /* It does not make sense to have a procedure linkage
1655 table entry for a local symbol. */
1656 bfd_set_error (bfd_error_bad_value);
1660 /* Make sure this symbol is output as a dynamic symbol. */
1661 if (h->dynindx == -1)
1663 if (! bfd_elf32_link_record_dynamic_symbol (info, h))
1667 h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
1673 && strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
1677 case R_SPARC_DISP16:
1678 case R_SPARC_DISP32:
1679 case R_SPARC_WDISP30:
1680 case R_SPARC_WDISP22:
1693 && (sec->flags & SEC_ALLOC) != 0)
1695 /* When creating a shared object, we must copy these
1696 relocs into the output file. We create a reloc
1697 section in dynobj and make room for the reloc. */
1702 name = (bfd_elf_string_from_elf_section
1704 elf_elfheader (abfd)->e_shstrndx,
1705 elf_section_data (sec)->rel_hdr.sh_name));
1709 BFD_ASSERT (strncmp (name, ".rela", 5) == 0
1710 && strcmp (bfd_get_section_name (abfd, sec),
1713 sreloc = bfd_get_section_by_name (dynobj, name);
1716 sreloc = bfd_make_section (dynobj, name);
1718 || ! bfd_set_section_flags (dynobj, sreloc,
1724 || ! bfd_set_section_alignment (dynobj, sreloc, 2))
1729 sreloc->_raw_size += sizeof (Elf32_External_Rela);
1741 /* Finish up dynamic symbol handling. We set the contents of various
1742 dynamic sections here. */
1745 ppc_elf_finish_dynamic_symbol (output_bfd, info, h, sym)
1747 struct bfd_link_info *info;
1748 struct elf_link_hash_entry *h;
1749 Elf_Internal_Sym *sym;
1754 fprintf (stderr, "ppc_elf_finish_dynamic_symbol called for %s\n", h->root.root.string);
1757 dynobj = elf_hash_table (info)->dynobj;
1758 BFD_ASSERT (dynobj != NULL);
1760 if (h->plt_offset != (bfd_vma) -1)
1764 Elf_Internal_Rela rela;
1766 /* This symbol has an entry in the procedure linkage table. Set
1769 BFD_ASSERT (h->dynindx != -1);
1771 splt = bfd_get_section_by_name (dynobj, ".plt");
1772 srela = bfd_get_section_by_name (dynobj, ".rela.plt");
1773 BFD_ASSERT (splt != NULL && srela != NULL);
1775 /* Fill in the entry in the procedure linkage table. */
1777 bfd_put_32 (output_bfd,
1778 PLT_ENTRY_WORD0 + h->plt_offset,
1779 splt->contents + h->plt_offset);
1780 bfd_put_32 (output_bfd,
1782 + (((- (h->plt_offset + 4)) >> 2) & 0x3fffff)),
1783 splt->contents + h->plt_offset + 4);
1784 bfd_put_32 (output_bfd, PLT_ENTRY_WORD2,
1785 splt->contents + h->plt_offset + 8);
1787 /* Fill in the entry in the .rela.plt section. */
1788 rela.r_offset = (splt->output_section->vma
1789 + splt->output_offset
1791 rela.r_info = ELF32_R_INFO (h->dynindx, R_SPARC_JMP_SLOT);
1793 bfd_elf32_swap_reloca_out (output_bfd, &rela,
1794 ((Elf32_External_Rela *) srela->contents
1795 + h->plt_offset / PLT_ENTRY_SIZE - 4));
1798 if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
1800 /* Mark the symbol as undefined, rather than as defined in
1801 the .plt section. Leave the value alone. */
1802 sym->st_shndx = SHN_UNDEF;
1806 if ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_COPY) != 0)
1809 Elf_Internal_Rela rela;
1811 /* This symbols needs a copy reloc. Set it up. */
1813 BFD_ASSERT (h->dynindx != -1);
1815 s = bfd_get_section_by_name (h->root.u.def.section->owner,
1817 BFD_ASSERT (s != NULL);
1819 rela.r_offset = (h->root.u.def.value
1820 + h->root.u.def.section->output_section->vma
1821 + h->root.u.def.section->output_offset);
1822 rela.r_info = ELF32_R_INFO (h->dynindx, R_PPC_COPY);
1824 bfd_elf32_swap_reloca_out (output_bfd, &rela,
1825 ((Elf32_External_Rela *) s->contents
1830 /* Mark some specially defined symbols as absolute. */
1831 if (strcmp (h->root.root.string, "_DYNAMIC") == 0
1832 || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0
1833 || strcmp (h->root.root.string, "_PROCEDURE_LINKAGE_TABLE_") == 0)
1834 sym->st_shndx = SHN_ABS;
1840 /* Finish up the dynamic sections. */
1843 ppc_elf_finish_dynamic_sections (output_bfd, info)
1845 struct bfd_link_info *info;
1848 bfd *dynobj = elf_hash_table (info)->dynobj;
1849 elf_linker_section_t *got = elf_linker_section (dynobj, LINKER_SECTION_GOT);
1852 fprintf (stderr, "ppc_elf_finish_dynamic_sections called\n");
1855 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
1857 if (elf_hash_table (info)->dynamic_sections_created)
1860 Elf32_External_Dyn *dyncon, *dynconend;
1862 splt = bfd_get_section_by_name (dynobj, ".plt");
1863 BFD_ASSERT (splt != NULL && sdyn != NULL);
1865 dyncon = (Elf32_External_Dyn *) sdyn->contents;
1866 dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->_raw_size);
1867 for (; dyncon < dynconend; dyncon++)
1869 Elf_Internal_Dyn dyn;
1873 bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
1877 case DT_PLTGOT: name = ".plt"; size = false; break;
1878 case DT_PLTRELSZ: name = ".rela.plt"; size = true; break;
1879 case DT_JMPREL: name = ".rela.plt"; size = false; break;
1880 default: name = NULL; size = false; break;
1887 s = bfd_get_section_by_name (output_bfd, name);
1893 dyn.d_un.d_ptr = s->vma;
1896 if (s->_cooked_size != 0)
1897 dyn.d_un.d_val = s->_cooked_size;
1899 dyn.d_un.d_val = s->_raw_size;
1902 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
1907 /* Add a blrl instruction at _GLOBAL_OFFSET_TABLE_-4 so that a function can
1908 easily find the address of the _GLOBAL_OFFSET_TABLE_. */
1911 unsigned char *contents = got->section->contents + got->hole_offset;
1912 bfd_put_32 (output_bfd, 0x4e800021 /* blrl */, contents);
1915 bfd_put_32 (output_bfd, (bfd_vma) 0, contents+4);
1917 bfd_put_32 (output_bfd,
1918 sdyn->output_section->vma + sdyn->output_offset,
1921 elf_section_data (got->section->output_section)->this_hdr.sh_entsize = 4;
1928 Elf_Internal_Sym sym;
1930 /* Set up the section symbols for the output sections. */
1932 sdynsym = bfd_get_section_by_name (dynobj, ".dynsym");
1933 BFD_ASSERT (sdynsym != NULL);
1937 sym.st_info = ELF_ST_INFO (STB_LOCAL, STT_SECTION);
1940 for (s = output_bfd->sections; s != NULL; s = s->next)
1944 sym.st_value = s->vma;
1946 indx = elf_section_data (s)->this_idx;
1947 BFD_ASSERT (indx > 0);
1948 sym.st_shndx = indx;
1950 bfd_elf32_swap_symbol_out (output_bfd, &sym,
1951 (PTR) (((Elf32_External_Sym *)
1953 + elf_section_data (s)->dynindx));
1956 /* Set the sh_info field of the output .dynsym section to the
1957 index of the first global symbol. */
1958 elf_section_data (sdynsym->output_section)->this_hdr.sh_info =
1959 bfd_count_sections (output_bfd) + 1;
1966 /* The RELOCATE_SECTION function is called by the ELF backend linker
1967 to handle the relocations for a section.
1969 The relocs are always passed as Rela structures; if the section
1970 actually uses Rel structures, the r_addend field will always be
1973 This function is responsible for adjust the section contents as
1974 necessary, and (if using Rela relocs and generating a
1975 relocateable output file) adjusting the reloc addend as
1978 This function does not have to worry about setting the reloc
1979 address or the reloc symbol index.
1981 LOCAL_SYMS is a pointer to the swapped in local symbols.
1983 LOCAL_SECTIONS is an array giving the section in the input file
1984 corresponding to the st_shndx field of each local symbol.
1986 The global hash table entry for the global symbols can be found
1987 via elf_sym_hashes (input_bfd).
1989 When generating relocateable output, this function must handle
1990 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
1991 going to be the section symbol corresponding to the output
1992 section, which means that the addend must be adjusted
1996 ppc_elf_relocate_section (output_bfd, info, input_bfd, input_section,
1997 contents, relocs, local_syms, local_sections)
1999 struct bfd_link_info *info;
2001 asection *input_section;
2003 Elf_Internal_Rela *relocs;
2004 Elf_Internal_Sym *local_syms;
2005 asection **local_sections;
2007 Elf_Internal_Shdr *symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
2008 struct elf_link_hash_entry **sym_hashes = elf_sym_hashes (input_bfd);
2009 bfd *dynobj = elf_hash_table (info)->dynobj;
2010 elf_linker_section_t *got = elf_linker_section (dynobj, LINKER_SECTION_GOT);
2011 elf_linker_section_t *sdata = elf_linker_section (dynobj, LINKER_SECTION_SDATA);
2012 elf_linker_section_t *sdata2 = elf_linker_section (dynobj, LINKER_SECTION_SDATA2);
2013 Elf_Internal_Rela *rel = relocs;
2014 Elf_Internal_Rela *relend = relocs + input_section->reloc_count;
2019 fprintf (stderr, "ppc_elf_relocate_section called for %s section %s, %ld relocations%s\n",
2020 bfd_get_filename (input_bfd),
2021 bfd_section_name(input_bfd, input_section),
2022 (long)input_section->reloc_count,
2023 (info->relocateable) ? " (relocatable)" : "");
2026 if (!ppc_elf_howto_table[ R_PPC_ADDR32 ]) /* Initialize howto table if needed */
2027 ppc_elf_howto_init ();
2029 for (; rel < relend; rel++)
2031 enum ppc_reloc_type r_type = (enum ppc_reloc_type)ELF32_R_TYPE (rel->r_info);
2032 bfd_vma offset = rel->r_offset;
2033 bfd_vma addend = rel->r_addend;
2034 bfd_reloc_status_type r = bfd_reloc_other;
2035 Elf_Internal_Sym *sym = (Elf_Internal_Sym *)0;
2036 asection *sec = (asection *)0;
2037 struct elf_link_hash_entry *h = (struct elf_link_hash_entry *)0;
2038 reloc_howto_type *howto;
2039 unsigned long r_symndx;
2042 /* Unknown relocation handling */
2043 if ((unsigned)r_type >= (unsigned)R_PPC_max || !ppc_elf_howto_table[(int)r_type])
2045 (*_bfd_error_handler) ("%s: unknown relocation type %d",
2046 bfd_get_filename (input_bfd),
2049 bfd_set_error (bfd_error_bad_value);
2054 howto = ppc_elf_howto_table[(int)r_type];
2055 r_symndx = ELF32_R_SYM (rel->r_info);
2057 if (info->relocateable)
2059 /* This is a relocateable link. We don't have to change
2060 anything, unless the reloc is against a section symbol,
2061 in which case we have to adjust according to where the
2062 section symbol winds up in the output section. */
2063 if (r_symndx < symtab_hdr->sh_info)
2065 sym = local_syms + r_symndx;
2066 if ((unsigned)ELF_ST_TYPE (sym->st_info) == STT_SECTION)
2068 sec = local_sections[r_symndx];
2069 addend = rel->r_addend += sec->output_offset + sym->st_value;
2074 fprintf (stderr, "\ttype = %s (%d), symbol index = %ld, offset = %ld, addend = %ld\n",
2084 /* This is a final link. */
2085 if (r_symndx < symtab_hdr->sh_info)
2087 sym = local_syms + r_symndx;
2088 sec = local_sections[r_symndx];
2089 relocation = (sec->output_section->vma
2090 + sec->output_offset
2095 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
2096 if (h->root.type == bfd_link_hash_defined
2097 || h->root.type == bfd_link_hash_defweak)
2099 sec = h->root.u.def.section;
2100 relocation = (h->root.u.def.value
2101 + sec->output_section->vma
2102 + sec->output_offset);
2104 else if (h->root.type == bfd_link_hash_undefweak)
2106 else if (info->shared)
2110 (*info->callbacks->undefined_symbol)(info,
2111 h->root.root.string,
2120 switch ((int)r_type)
2123 (*_bfd_error_handler) ("%s: unknown relocation type %d",
2124 bfd_get_filename (input_bfd),
2127 bfd_set_error (bfd_error_bad_value);
2131 /* relocations that need no special processing */
2132 case (int)R_PPC_NONE:
2133 case (int)R_PPC_ADDR32:
2134 case (int)R_PPC_ADDR24:
2135 case (int)R_PPC_ADDR16:
2136 case (int)R_PPC_ADDR16_LO:
2137 case (int)R_PPC_ADDR16_HI:
2138 case (int)R_PPC_ADDR14:
2139 case (int)R_PPC_REL24:
2140 case (int)R_PPC_REL14:
2141 case (int)R_PPC_UADDR32:
2142 case (int)R_PPC_UADDR16:
2143 case (int)R_PPC_REL32:
2146 /* branch taken prediction relocations */
2147 case (int)R_PPC_ADDR14_BRTAKEN:
2148 case (int)R_PPC_REL14_BRTAKEN:
2149 insn = bfd_get_32 (output_bfd, contents + offset);
2150 if ((relocation - offset) & 0x8000)
2151 insn &= ~BRANCH_PREDICT_BIT;
2153 insn |= BRANCH_PREDICT_BIT;
2154 bfd_put_32 (output_bfd, insn, contents + offset);
2157 /* branch not taken predicition relocations */
2158 case (int)R_PPC_ADDR14_BRNTAKEN:
2159 case (int)R_PPC_REL14_BRNTAKEN:
2160 insn = bfd_get_32 (output_bfd, contents + offset);
2161 if ((relocation - offset) & 0x8000)
2162 insn |= BRANCH_PREDICT_BIT;
2164 insn &= ~BRANCH_PREDICT_BIT;
2165 bfd_put_32 (output_bfd, insn, contents + offset);
2168 /* GOT16 relocations */
2169 case (int)R_PPC_GOT16:
2170 case (int)R_PPC_GOT16_LO:
2171 case (int)R_PPC_GOT16_HI:
2172 case (int)R_PPC_GOT16_HA:
2173 relocation = bfd_elf32_finish_pointer_linker_section (output_bfd, input_bfd, info,
2174 got, h, relocation, rel,
2178 /* Indirect .sdata relocation */
2179 case (int)R_PPC_EMB_SDAI16:
2180 BFD_ASSERT (sdata != NULL);
2181 relocation = bfd_elf32_finish_pointer_linker_section (output_bfd, input_bfd, info,
2182 sdata, h, relocation, rel,
2186 /* Indirect .sdata2 relocation */
2187 case (int)R_PPC_EMB_SDA2I16:
2188 BFD_ASSERT (sdata2 != NULL);
2189 relocation = bfd_elf32_finish_pointer_linker_section (output_bfd, input_bfd, info,
2190 sdata2, h, relocation, rel,
2194 /* Handle the TOC16 reloc. We want to use the offset within the .got
2195 section, not the actual VMA. This is appropriate when generating
2196 an embedded ELF object, for which the .got section acts like the
2197 AIX .toc section. */
2198 case (int)R_PPC_TOC16: /* phony GOT16 relocations */
2199 BFD_ASSERT (sec != (asection *)0);
2200 BFD_ASSERT (bfd_is_und_section (sec)
2201 || strcmp (bfd_get_section_name (abfd, sec), ".got") == 0
2202 || strcmp (bfd_get_section_name (abfd, sec), ".cgot") == 0)
2204 addend -= sec->output_section->vma + 0x8000;
2207 /* arithmetic adjust relocations */
2208 case (int)R_PPC_ADDR16_HA:
2209 BFD_ASSERT (sec != (asection *)0);
2210 addend += ((relocation + addend) & 0x8000) << 1;
2213 /* relocate against _SDA_BASE_ */
2214 case (int)R_PPC_SDAREL16:
2215 BFD_ASSERT (sec != (asection *)0);
2216 if (strcmp (bfd_get_section_name (abfd, sec), ".sdata") != 0
2217 && strcmp (bfd_get_section_name (abfd, sec), ".sbss") != 0)
2219 (*_bfd_error_handler) ("%s: The target of a %s relocation is in the wrong section (%s)",
2220 bfd_get_filename (input_bfd),
2221 ppc_elf_howto_table[ (int)r_type ]->name,
2222 bfd_get_section_name (abfd, sec));
2224 bfd_set_error (bfd_error_bad_value);
2228 addend -= sdata->sym_hash->root.u.def.value;
2229 relocation = sdata->sym_hash->root.u.def.section->output_section->vma - relocation;
2233 /* relocate against _SDA2_BASE_ */
2234 case (int)R_PPC_EMB_SDA2REL:
2235 BFD_ASSERT (sec != (asection *)0);
2236 if (strcmp (bfd_get_section_name (abfd, sec), ".sdata2") != 0
2237 && strcmp (bfd_get_section_name (abfd, sec), ".sbss2") != 0)
2239 (*_bfd_error_handler) ("%s: The target of a %s relocation is in the wrong section (%s)",
2240 bfd_get_filename (input_bfd),
2241 ppc_elf_howto_table[ (int)r_type ]->name,
2242 bfd_get_section_name (abfd, sec));
2244 bfd_set_error (bfd_error_bad_value);
2248 addend -= sdata2->sym_hash->root.u.def.value;
2249 relocation = sdata2->sym_hash->root.u.def.section->output_section->vma - relocation;
2253 /* relocate against either _SDA_BASE_, _SDA2_BASE_, or 0 */
2254 case (int)R_PPC_EMB_SDA21:
2255 case (int)R_PPC_EMB_RELSDA:
2257 const char *name = bfd_get_section_name (abfd, sec);
2260 BFD_ASSERT (sec != (asection *)0);
2261 if (strcmp (name, ".sdata") == 0 || strcmp (name, ".sbss") == 0)
2264 addend -= sdata->sym_hash->root.u.def.value;
2265 relocation = sdata->sym_hash->root.u.def.section->output_section->vma - relocation;
2268 else if (strcmp (name, ".sdata2") == 0 || strcmp (name, ".sbss2") == 0)
2271 addend -= sdata2->sym_hash->root.u.def.value;
2272 relocation = sdata2->sym_hash->root.u.def.section->output_section->vma - relocation;
2275 else if (strcmp (name, ".PPC.EMB.sdata0") == 0 || strcmp (name, ".PPC.EMB.sbss0") == 0)
2282 (*_bfd_error_handler) ("%s: The target of a %s relocation is in the wrong section (%s)",
2283 bfd_get_filename (input_bfd),
2284 ppc_elf_howto_table[ (int)r_type ]->name,
2285 bfd_get_section_name (abfd, sec));
2287 bfd_set_error (bfd_error_bad_value);
2294 case (int)R_PPC_PLTREL24:
2295 case (int)R_PPC_COPY:
2296 case (int)R_PPC_GLOB_DAT:
2297 case (int)R_PPC_JMP_SLOT:
2298 case (int)R_PPC_RELATIVE:
2299 case (int)R_PPC_LOCAL24PC:
2300 case (int)R_PPC_PLT32:
2301 case (int)R_PPC_PLTREL32:
2302 case (int)R_PPC_PLT16_LO:
2303 case (int)R_PPC_PLT16_HI:
2304 case (int)R_PPC_PLT16_HA:
2305 case (int)R_PPC_SECTOFF:
2306 case (int)R_PPC_SECTOFF_LO:
2307 case (int)R_PPC_SECTOFF_HI:
2308 case (int)R_PPC_SECTOFF_HA:
2309 case (int)R_PPC_EMB_NADDR32:
2310 case (int)R_PPC_EMB_NADDR16:
2311 case (int)R_PPC_EMB_NADDR16_LO:
2312 case (int)R_PPC_EMB_NADDR16_HI:
2313 case (int)R_PPC_EMB_NADDR16_HA:
2314 case (int)R_PPC_EMB_MRKREF:
2315 case (int)R_PPC_EMB_RELSEC16:
2316 case (int)R_PPC_EMB_RELST_LO:
2317 case (int)R_PPC_EMB_RELST_HI:
2318 case (int)R_PPC_EMB_RELST_HA:
2319 case (int)R_PPC_EMB_BIT_FLD:
2321 (*_bfd_error_handler) ("%s: Relocation %s is not yet supported.",
2322 bfd_get_filename (input_bfd),
2323 ppc_elf_howto_table[ (int)r_type ]->name);
2325 bfd_set_error (bfd_error_invalid_operation);
2332 fprintf (stderr, "\ttype = %s (%d), symbol index = %ld, offset = %ld, addend = %ld\n",
2340 r = _bfd_final_link_relocate (howto,
2348 if (r != bfd_reloc_ok)
2356 case bfd_reloc_overflow:
2361 name = h->root.root.string;
2364 name = bfd_elf_string_from_elf_section (input_bfd,
2365 symtab_hdr->sh_link,
2371 name = bfd_section_name (input_bfd, sec);
2374 (*info->callbacks->reloc_overflow)(info,
2390 fprintf (stderr, "\n");
2397 #define TARGET_LITTLE_SYM bfd_elf32_powerpcle_vec
2398 #define TARGET_LITTLE_NAME "elf32-powerpcle"
2399 #define TARGET_BIG_SYM bfd_elf32_powerpc_vec
2400 #define TARGET_BIG_NAME "elf32-powerpc"
2401 #define ELF_ARCH bfd_arch_powerpc
2402 #define ELF_MACHINE_CODE EM_PPC
2403 #define ELF_MAXPAGESIZE 0x10000
2404 #define elf_info_to_howto ppc_elf_info_to_howto
2406 #ifdef EM_CYGNUS_POWERPC
2407 #define ELF_MACHINE_ALT1 EM_CYGNUS_POWERPC
2411 #define ELF_MACHINE_ALT2 EM_PPC_OLD
2414 #define bfd_elf32_bfd_copy_private_bfd_data ppc_elf_copy_private_bfd_data
2415 #define bfd_elf32_bfd_merge_private_bfd_data ppc_elf_merge_private_bfd_data
2416 #define bfd_elf32_bfd_set_private_flags ppc_elf_set_private_flags
2417 #define bfd_elf32_bfd_reloc_type_lookup ppc_elf_reloc_type_lookup
2418 #define elf_backend_section_from_shdr ppc_elf_section_from_shdr
2419 #define elf_backend_relocate_section ppc_elf_relocate_section
2420 #define elf_backend_create_dynamic_sections _bfd_elf_create_dynamic_sections
2421 #define elf_backend_check_relocs ppc_elf_check_relocs
2422 #define elf_backend_adjust_dynamic_symbol ppc_elf_adjust_dynamic_symbol
2423 #define elf_backend_size_dynamic_sections ppc_elf_size_dynamic_sections
2424 #define elf_backend_finish_dynamic_symbol ppc_elf_finish_dynamic_symbol
2425 #define elf_backend_finish_dynamic_sections ppc_elf_finish_dynamic_sections
2426 #define elf_backend_fake_sections ppc_elf_fake_sections
2428 #include "elf32-target.h"