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_add_symbol_hook PARAMS ((bfd *,
142 struct bfd_link_info *,
143 const Elf_Internal_Sym *,
149 static boolean ppc_elf_finish_dynamic_symbol PARAMS ((bfd *,
150 struct bfd_link_info *,
151 struct elf_link_hash_entry *,
152 Elf_Internal_Sym *));
154 static boolean ppc_elf_finish_dynamic_sections PARAMS ((bfd *, struct bfd_link_info *));
156 #define BRANCH_PREDICT_BIT 0x200000 /* branch prediction bit for branch taken relocs */
157 #define RA_REGISTER_MASK 0x001f0000 /* mask to set RA in memory instructions */
158 #define RA_REGISTER_SHIFT 16 /* value to shift register by to insert RA */
160 /* The name of the dynamic interpreter. This is put in the .interp
163 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
166 static reloc_howto_type *ppc_elf_howto_table[ (int)R_PPC_max ];
168 static reloc_howto_type ppc_elf_howto_raw[] =
170 /* This reloc does nothing. */
171 HOWTO (R_PPC_NONE, /* type */
173 2, /* size (0 = byte, 1 = short, 2 = long) */
175 false, /* pc_relative */
177 complain_overflow_bitfield, /* complain_on_overflow */
178 bfd_elf_generic_reloc, /* special_function */
179 "R_PPC_NONE", /* name */
180 false, /* partial_inplace */
183 false), /* pcrel_offset */
185 /* A standard 32 bit relocation. */
186 HOWTO (R_PPC_ADDR32, /* type */
188 2, /* size (0 = byte, 1 = short, 2 = long) */
190 false, /* pc_relative */
192 complain_overflow_bitfield, /* complain_on_overflow */
193 bfd_elf_generic_reloc, /* special_function */
194 "R_PPC_ADDR32", /* name */
195 false, /* partial_inplace */
197 0xffffffff, /* dst_mask */
198 false), /* pcrel_offset */
200 /* An absolute 26 bit branch; the lower two bits must be zero.
201 FIXME: we don't check that, we just clear them. */
202 HOWTO (R_PPC_ADDR24, /* type */
204 2, /* size (0 = byte, 1 = short, 2 = long) */
206 false, /* pc_relative */
208 complain_overflow_bitfield, /* complain_on_overflow */
209 bfd_elf_generic_reloc, /* special_function */
210 "R_PPC_ADDR24", /* name */
211 false, /* partial_inplace */
213 0x3fffffc, /* dst_mask */
214 false), /* pcrel_offset */
216 /* A standard 16 bit relocation. */
217 HOWTO (R_PPC_ADDR16, /* type */
219 1, /* size (0 = byte, 1 = short, 2 = long) */
221 false, /* pc_relative */
223 complain_overflow_bitfield, /* complain_on_overflow */
224 bfd_elf_generic_reloc, /* special_function */
225 "R_PPC_ADDR16", /* name */
226 false, /* partial_inplace */
228 0xffff, /* dst_mask */
229 false), /* pcrel_offset */
231 /* A 16 bit relocation without overflow. */
232 HOWTO (R_PPC_ADDR16_LO, /* type */
234 1, /* size (0 = byte, 1 = short, 2 = long) */
236 false, /* pc_relative */
238 complain_overflow_dont,/* complain_on_overflow */
239 bfd_elf_generic_reloc, /* special_function */
240 "R_PPC_ADDR16_LO", /* name */
241 false, /* partial_inplace */
243 0xffff, /* dst_mask */
244 false), /* pcrel_offset */
246 /* The high order 16 bits of an address. */
247 HOWTO (R_PPC_ADDR16_HI, /* type */
249 1, /* size (0 = byte, 1 = short, 2 = long) */
251 false, /* pc_relative */
253 complain_overflow_dont, /* complain_on_overflow */
254 bfd_elf_generic_reloc, /* special_function */
255 "R_PPC_ADDR16_HI", /* name */
256 false, /* partial_inplace */
258 0xffff, /* dst_mask */
259 false), /* pcrel_offset */
261 /* The high order 16 bits of an address, plus 1 if the contents of
262 the low 16 bits, treated as a signed number, is negative. */
263 HOWTO (R_PPC_ADDR16_HA, /* type */
265 1, /* size (0 = byte, 1 = short, 2 = long) */
267 false, /* pc_relative */
269 complain_overflow_dont, /* complain_on_overflow */
270 bfd_elf_generic_reloc, /* special_function */
271 "R_PPC_ADDR16_HA", /* name */
272 false, /* partial_inplace */
274 0xffff, /* dst_mask */
275 false), /* pcrel_offset */
277 /* An absolute 16 bit branch; the lower two bits must be zero.
278 FIXME: we don't check that, we just clear them. */
279 HOWTO (R_PPC_ADDR14, /* type */
281 2, /* size (0 = byte, 1 = short, 2 = long) */
283 false, /* pc_relative */
285 complain_overflow_bitfield, /* complain_on_overflow */
286 bfd_elf_generic_reloc, /* special_function */
287 "R_PPC_ADDR14", /* name */
288 false, /* partial_inplace */
290 0xfffc, /* dst_mask */
291 false), /* pcrel_offset */
293 /* An absolute 16 bit branch, for which bit 10 should be set to
294 indicate that the branch is expected to be taken. The lower two
295 bits must be zero. */
296 HOWTO (R_PPC_ADDR14_BRTAKEN, /* type */
298 2, /* size (0 = byte, 1 = short, 2 = long) */
300 false, /* pc_relative */
302 complain_overflow_bitfield, /* complain_on_overflow */
303 bfd_elf_generic_reloc, /* special_function */
304 "R_PPC_ADDR14_BRTAKEN",/* name */
305 false, /* partial_inplace */
307 0xfffc, /* dst_mask */
308 false), /* pcrel_offset */
310 /* An absolute 16 bit branch, for which bit 10 should be set to
311 indicate that the branch is not expected to be taken. The lower
312 two bits must be zero. */
313 HOWTO (R_PPC_ADDR14_BRNTAKEN, /* type */
315 2, /* size (0 = byte, 1 = short, 2 = long) */
317 false, /* pc_relative */
319 complain_overflow_bitfield, /* complain_on_overflow */
320 bfd_elf_generic_reloc, /* special_function */
321 "R_PPC_ADDR14_BRNTAKEN",/* name */
322 false, /* partial_inplace */
324 0xfffc, /* dst_mask */
325 false), /* pcrel_offset */
327 /* A relative 26 bit branch; the lower two bits must be zero. */
328 HOWTO (R_PPC_REL24, /* type */
330 2, /* size (0 = byte, 1 = short, 2 = long) */
332 true, /* pc_relative */
334 complain_overflow_signed, /* complain_on_overflow */
335 bfd_elf_generic_reloc, /* special_function */
336 "R_PPC_REL24", /* name */
337 false, /* partial_inplace */
339 0x3fffffc, /* dst_mask */
340 true), /* pcrel_offset */
342 /* A relative 16 bit branch; the lower two bits must be zero. */
343 HOWTO (R_PPC_REL14, /* type */
345 2, /* size (0 = byte, 1 = short, 2 = long) */
347 true, /* pc_relative */
349 complain_overflow_signed, /* complain_on_overflow */
350 bfd_elf_generic_reloc, /* special_function */
351 "R_PPC_REL14", /* name */
352 false, /* partial_inplace */
354 0xfffc, /* dst_mask */
355 true), /* pcrel_offset */
357 /* A relative 16 bit branch. Bit 10 should be set to indicate that
358 the branch is expected to be taken. The lower two bits must be
360 HOWTO (R_PPC_REL14_BRTAKEN, /* type */
362 2, /* size (0 = byte, 1 = short, 2 = long) */
364 true, /* pc_relative */
366 complain_overflow_signed, /* complain_on_overflow */
367 bfd_elf_generic_reloc, /* special_function */
368 "R_PPC_REL14_BRTAKEN", /* name */
369 false, /* partial_inplace */
371 0xfffc, /* dst_mask */
372 true), /* pcrel_offset */
374 /* A relative 16 bit branch. Bit 10 should be set to indicate that
375 the branch is not expected to be taken. The lower two bits must
377 HOWTO (R_PPC_REL14_BRNTAKEN, /* type */
379 2, /* size (0 = byte, 1 = short, 2 = long) */
381 true, /* pc_relative */
383 complain_overflow_signed, /* complain_on_overflow */
384 bfd_elf_generic_reloc, /* special_function */
385 "R_PPC_REL14_BRNTAKEN",/* name */
386 false, /* partial_inplace */
388 0xfffc, /* dst_mask */
389 true), /* pcrel_offset */
391 /* Like R_PPC_ADDR16, but referring to the GOT table entry for the
393 HOWTO (R_PPC_GOT16, /* type */
395 1, /* size (0 = byte, 1 = short, 2 = long) */
397 false, /* pc_relative */
399 complain_overflow_signed, /* complain_on_overflow */
400 bfd_elf_generic_reloc, /* special_function */
401 "R_PPC_GOT16", /* name */
402 false, /* partial_inplace */
404 0xffff, /* dst_mask */
405 false), /* pcrel_offset */
407 /* Like R_PPC_ADDR16_LO, but referring to the GOT table entry for
409 HOWTO (R_PPC_GOT16_LO, /* type */
411 1, /* size (0 = byte, 1 = short, 2 = long) */
413 false, /* pc_relative */
415 complain_overflow_bitfield, /* complain_on_overflow */
416 bfd_elf_generic_reloc, /* special_function */
417 "R_PPC_GOT16_LO", /* name */
418 false, /* partial_inplace */
420 0xffff, /* dst_mask */
421 false), /* pcrel_offset */
423 /* Like R_PPC_ADDR16_HI, but referring to the GOT table entry for
425 HOWTO (R_PPC_GOT16_HI, /* type */
427 1, /* size (0 = byte, 1 = short, 2 = long) */
429 false, /* pc_relative */
431 complain_overflow_bitfield, /* complain_on_overflow */
432 bfd_elf_generic_reloc, /* special_function */
433 "R_PPC_GOT16_HI", /* name */
434 false, /* partial_inplace */
436 0xffff, /* dst_mask */
437 false), /* pcrel_offset */
439 /* Like R_PPC_ADDR16_HA, but referring to the GOT table entry for
441 HOWTO (R_PPC_GOT16_HA, /* type */
443 1, /* size (0 = byte, 1 = short, 2 = long) */
445 false, /* pc_relative */
447 complain_overflow_bitfield, /* complain_on_overflow */
448 bfd_elf_generic_reloc, /* special_function */
449 "R_PPC_GOT16_HA", /* name */
450 false, /* partial_inplace */
452 0xffff, /* dst_mask */
453 false), /* pcrel_offset */
455 /* Like R_PPC_REL24, but referring to the procedure linkage table
456 entry for the symbol. FIXME: Not supported. */
457 HOWTO (R_PPC_PLTREL24, /* type */
459 2, /* size (0 = byte, 1 = short, 2 = long) */
461 true, /* pc_relative */
463 complain_overflow_signed, /* complain_on_overflow */
464 bfd_elf_generic_reloc, /* special_function */
465 "R_PPC_PLTREL24", /* name */
466 false, /* partial_inplace */
468 0x3fffffc, /* dst_mask */
469 true), /* pcrel_offset */
471 /* This is used only by the dynamic linker. The symbol should exist
472 both in the object being run and in some shared library. The
473 dynamic linker copies the data addressed by the symbol from the
474 shared library into the object. I have no idea what the purpose
476 HOWTO (R_PPC_COPY, /* type */
478 2, /* size (0 = byte, 1 = short, 2 = long) */
480 false, /* pc_relative */
482 complain_overflow_bitfield, /* complain_on_overflow */
483 bfd_elf_generic_reloc, /* special_function */
484 "R_PPC_COPY", /* name */
485 false, /* partial_inplace */
488 false), /* pcrel_offset */
490 /* Like R_PPC_ADDR32, but used when setting global offset table
492 HOWTO (R_PPC_GLOB_DAT, /* type */
494 2, /* size (0 = byte, 1 = short, 2 = long) */
496 false, /* pc_relative */
498 complain_overflow_bitfield, /* complain_on_overflow */
499 bfd_elf_generic_reloc, /* special_function */
500 "R_PPC_GLOB_DAT", /* name */
501 false, /* partial_inplace */
503 0xffffffff, /* dst_mask */
504 false), /* pcrel_offset */
506 /* Marks a procedure linkage table entry for a symbol. */
507 HOWTO (R_PPC_JMP_SLOT, /* type */
509 2, /* size (0 = byte, 1 = short, 2 = long) */
511 false, /* pc_relative */
513 complain_overflow_bitfield, /* complain_on_overflow */
514 bfd_elf_generic_reloc, /* special_function */
515 "R_PPC_JMP_SLOT", /* name */
516 false, /* partial_inplace */
519 false), /* pcrel_offset */
521 /* Used only by the dynamic linker. When the object is run, this
522 longword is set to the load address of the object, plus the
524 HOWTO (R_PPC_RELATIVE, /* type */
526 2, /* size (0 = byte, 1 = short, 2 = long) */
528 false, /* pc_relative */
530 complain_overflow_bitfield, /* complain_on_overflow */
531 bfd_elf_generic_reloc, /* special_function */
532 "R_PPC_RELATIVE", /* name */
533 false, /* partial_inplace */
535 0xffffffff, /* dst_mask */
536 false), /* pcrel_offset */
538 /* Like R_PPC_REL24, but uses the value of the symbol within the
539 object rather than the final value. Normally used for
540 _GLOBAL_OFFSET_TABLE_. FIXME: Not supported. */
541 HOWTO (R_PPC_LOCAL24PC, /* type */
543 2, /* size (0 = byte, 1 = short, 2 = long) */
545 true, /* pc_relative */
547 complain_overflow_signed, /* complain_on_overflow */
548 bfd_elf_generic_reloc, /* special_function */
549 "R_PPC_LOCAL24PC", /* name */
550 false, /* partial_inplace */
552 0x3fffffc, /* dst_mask */
553 true), /* pcrel_offset */
555 /* Like R_PPC_ADDR32, but may be unaligned. */
556 HOWTO (R_PPC_UADDR32, /* type */
558 2, /* size (0 = byte, 1 = short, 2 = long) */
560 false, /* pc_relative */
562 complain_overflow_bitfield, /* complain_on_overflow */
563 bfd_elf_generic_reloc, /* special_function */
564 "R_PPC_UADDR32", /* name */
565 false, /* partial_inplace */
567 0xffffffff, /* dst_mask */
568 false), /* pcrel_offset */
570 /* Like R_PPC_ADDR16, but may be unaligned. */
571 HOWTO (R_PPC_UADDR16, /* type */
573 1, /* size (0 = byte, 1 = short, 2 = long) */
575 false, /* pc_relative */
577 complain_overflow_bitfield, /* complain_on_overflow */
578 bfd_elf_generic_reloc, /* special_function */
579 "R_PPC_UADDR16", /* name */
580 false, /* partial_inplace */
582 0xffff, /* dst_mask */
583 false), /* pcrel_offset */
585 /* 32-bit PC relative */
586 HOWTO (R_PPC_REL32, /* type */
588 2, /* size (0 = byte, 1 = short, 2 = long) */
590 true, /* pc_relative */
592 complain_overflow_bitfield, /* complain_on_overflow */
593 bfd_elf_generic_reloc, /* special_function */
594 "R_PPC_REL32", /* name */
595 false, /* partial_inplace */
597 0xffffffff, /* dst_mask */
598 true), /* pcrel_offset */
600 /* 32-bit relocation to the symbol's procedure linkage table.
601 FIXEME: not supported. */
602 HOWTO (R_PPC_PLT32, /* type */
604 2, /* size (0 = byte, 1 = short, 2 = long) */
606 false, /* pc_relative */
608 complain_overflow_bitfield, /* complain_on_overflow */
609 bfd_elf_generic_reloc, /* special_function */
610 "R_PPC_PLT32", /* name */
611 false, /* partial_inplace */
614 false), /* pcrel_offset */
616 /* 32-bit PC relative relocation to the symbol's procedure linkage table.
617 FIXEME: not supported. */
618 HOWTO (R_PPC_PLTREL32, /* type */
620 2, /* size (0 = byte, 1 = short, 2 = long) */
622 true, /* pc_relative */
624 complain_overflow_bitfield, /* complain_on_overflow */
625 bfd_elf_generic_reloc, /* special_function */
626 "R_PPC_PLTREL32", /* name */
627 false, /* partial_inplace */
630 true), /* pcrel_offset */
632 /* Like R_PPC_ADDR16_LO, but referring to the PLT table entry for
634 HOWTO (R_PPC_PLT16_LO, /* type */
636 1, /* size (0 = byte, 1 = short, 2 = long) */
638 false, /* pc_relative */
640 complain_overflow_bitfield, /* complain_on_overflow */
641 bfd_elf_generic_reloc, /* special_function */
642 "R_PPC_PLT16_LO", /* name */
643 false, /* partial_inplace */
645 0xffff, /* dst_mask */
646 false), /* pcrel_offset */
648 /* Like R_PPC_ADDR16_HI, but referring to the PLT table entry for
650 HOWTO (R_PPC_PLT16_HI, /* type */
652 1, /* size (0 = byte, 1 = short, 2 = long) */
654 false, /* pc_relative */
656 complain_overflow_bitfield, /* complain_on_overflow */
657 bfd_elf_generic_reloc, /* special_function */
658 "R_PPC_PLT16_HI", /* name */
659 false, /* partial_inplace */
661 0xffff, /* dst_mask */
662 false), /* pcrel_offset */
664 /* Like R_PPC_ADDR16_HA, but referring to the PLT table entry for
665 the symbol. FIXME: Not supported. */
666 HOWTO (R_PPC_PLT16_HA, /* type */
668 1, /* size (0 = byte, 1 = short, 2 = long) */
670 false, /* pc_relative */
672 complain_overflow_bitfield, /* complain_on_overflow */
673 bfd_elf_generic_reloc, /* special_function */
674 "R_PPC_PLT16_HA", /* name */
675 false, /* partial_inplace */
677 0xffff, /* dst_mask */
678 false), /* pcrel_offset */
680 /* A sign-extended 16 bit value relative to _SDA_BASE_, for use with
682 HOWTO (R_PPC_SDAREL16, /* type */
684 1, /* size (0 = byte, 1 = short, 2 = long) */
686 false, /* pc_relative */
688 complain_overflow_signed, /* complain_on_overflow */
689 bfd_elf_generic_reloc, /* special_function */
690 "R_PPC_SDAREL16", /* name */
691 false, /* partial_inplace */
693 0xffff, /* dst_mask */
694 false), /* pcrel_offset */
696 /* 32-bit section relative relocation. */
697 HOWTO (R_PPC_SECTOFF, /* type */
699 2, /* size (0 = byte, 1 = short, 2 = long) */
701 true, /* pc_relative */
703 complain_overflow_bitfield, /* complain_on_overflow */
704 bfd_elf_generic_reloc, /* special_function */
705 "R_PPC_SECTOFF", /* name */
706 false, /* partial_inplace */
709 true), /* pcrel_offset */
711 /* 16-bit lower half section relative relocation. */
712 HOWTO (R_PPC_SECTOFF_LO, /* type */
714 1, /* size (0 = byte, 1 = short, 2 = long) */
716 false, /* pc_relative */
718 complain_overflow_bitfield, /* complain_on_overflow */
719 bfd_elf_generic_reloc, /* special_function */
720 "R_PPC_SECTOFF_LO", /* name */
721 false, /* partial_inplace */
723 0xffff, /* dst_mask */
724 false), /* pcrel_offset */
726 /* 16-bit upper half section relative relocation. */
727 HOWTO (R_PPC_SECTOFF_HI, /* type */
729 1, /* size (0 = byte, 1 = short, 2 = long) */
731 false, /* pc_relative */
733 complain_overflow_bitfield, /* complain_on_overflow */
734 bfd_elf_generic_reloc, /* special_function */
735 "R_PPC_SECTOFF_HI", /* name */
736 false, /* partial_inplace */
738 0xffff, /* dst_mask */
739 false), /* pcrel_offset */
741 /* 16-bit upper half adjusted section relative relocation. */
742 HOWTO (R_PPC_SECTOFF_HA, /* type */
744 1, /* size (0 = byte, 1 = short, 2 = long) */
746 false, /* pc_relative */
748 complain_overflow_bitfield, /* complain_on_overflow */
749 bfd_elf_generic_reloc, /* special_function */
750 "R_PPC_SECTOFF_HA", /* name */
751 false, /* partial_inplace */
753 0xffff, /* dst_mask */
754 false), /* pcrel_offset */
756 /* The remaining relocs are from the Embedded ELF ABI, and are not
757 in the SVR4 ELF ABI. */
759 /* 32 bit value resulting from the addend minus the symbol */
760 HOWTO (R_PPC_EMB_NADDR32, /* type */
762 2, /* size (0 = byte, 1 = short, 2 = long) */
764 false, /* pc_relative */
766 complain_overflow_bitfield, /* complain_on_overflow */
767 bfd_elf_generic_reloc, /* special_function */
768 "R_PPC_EMB_NADDR32", /* name */
769 false, /* partial_inplace */
771 0xffffffff, /* dst_mask */
772 false), /* pcrel_offset */
774 /* 16 bit value resulting from the addend minus the symbol */
775 HOWTO (R_PPC_EMB_NADDR16, /* type */
777 1, /* size (0 = byte, 1 = short, 2 = long) */
779 false, /* pc_relative */
781 complain_overflow_bitfield, /* complain_on_overflow */
782 bfd_elf_generic_reloc, /* special_function */
783 "R_PPC_EMB_NADDR16", /* name */
784 false, /* partial_inplace */
786 0xffff, /* dst_mask */
787 false), /* pcrel_offset */
789 /* 16 bit value resulting from the addend minus the symbol */
790 HOWTO (R_PPC_EMB_NADDR16_LO, /* type */
792 1, /* size (0 = byte, 1 = short, 2 = long) */
794 false, /* pc_relative */
796 complain_overflow_dont,/* complain_on_overflow */
797 bfd_elf_generic_reloc, /* special_function */
798 "R_PPC_EMB_ADDR16_LO", /* name */
799 false, /* partial_inplace */
801 0xffff, /* dst_mask */
802 false), /* pcrel_offset */
804 /* The high order 16 bits of the addend minus the symbol */
805 HOWTO (R_PPC_EMB_NADDR16_HI, /* type */
807 1, /* size (0 = byte, 1 = short, 2 = long) */
809 false, /* pc_relative */
811 complain_overflow_dont, /* complain_on_overflow */
812 bfd_elf_generic_reloc, /* special_function */
813 "R_PPC_EMB_NADDR16_HI", /* name */
814 false, /* partial_inplace */
816 0xffff, /* dst_mask */
817 false), /* pcrel_offset */
819 /* The high order 16 bits of the result of the addend minus the address,
820 plus 1 if the contents of the low 16 bits, treated as a signed number,
822 HOWTO (R_PPC_EMB_NADDR16_HA, /* type */
824 1, /* size (0 = byte, 1 = short, 2 = long) */
826 false, /* pc_relative */
828 complain_overflow_dont, /* complain_on_overflow */
829 bfd_elf_generic_reloc, /* special_function */
830 "R_PPC_EMB_NADDR16_HA", /* name */
831 false, /* partial_inplace */
833 0xffff, /* dst_mask */
834 false), /* pcrel_offset */
836 /* 16 bit value resulting from allocating a 4 byte word to hold an
837 address in the .sdata section, and returning the offset from
838 _SDA_BASE_ for that relocation */
839 HOWTO (R_PPC_EMB_SDAI16, /* type */
841 1, /* size (0 = byte, 1 = short, 2 = long) */
843 false, /* pc_relative */
845 complain_overflow_bitfield, /* complain_on_overflow */
846 bfd_elf_generic_reloc, /* special_function */
847 "R_PPC_EMB_SDAI16", /* name */
848 false, /* partial_inplace */
850 0xffff, /* dst_mask */
851 false), /* pcrel_offset */
853 /* 16 bit value resulting from allocating a 4 byte word to hold an
854 address in the .sdata2 section, and returning the offset from
855 _SDA2_BASE_ for that relocation */
856 HOWTO (R_PPC_EMB_SDA2I16, /* type */
858 1, /* size (0 = byte, 1 = short, 2 = long) */
860 false, /* pc_relative */
862 complain_overflow_bitfield, /* complain_on_overflow */
863 bfd_elf_generic_reloc, /* special_function */
864 "R_PPC_EMB_SDA2I16", /* name */
865 false, /* partial_inplace */
867 0xffff, /* dst_mask */
868 false), /* pcrel_offset */
870 /* A sign-extended 16 bit value relative to _SDA2_BASE_, for use with
872 HOWTO (R_PPC_EMB_SDA2REL, /* type */
874 1, /* size (0 = byte, 1 = short, 2 = long) */
876 false, /* pc_relative */
878 complain_overflow_signed, /* complain_on_overflow */
879 bfd_elf_generic_reloc, /* special_function */
880 "R_PPC_EMB_SDA2REL", /* name */
881 false, /* partial_inplace */
883 0xffff, /* dst_mask */
884 false), /* pcrel_offset */
886 /* Relocate against either _SDA_BASE_ or _SDA2_BASE_, filling in the 16 bit
887 signed offset from the appropriate base, and filling in the register
888 field with the appropriate register (0, 2, or 13). */
889 HOWTO (R_PPC_EMB_SDA21, /* type */
891 2, /* size (0 = byte, 1 = short, 2 = long) */
893 false, /* pc_relative */
895 complain_overflow_signed, /* complain_on_overflow */
896 bfd_elf_generic_reloc, /* special_function */
897 "R_PPC_EMB_SDA21", /* name */
898 false, /* partial_inplace */
900 0xffff, /* dst_mask */
901 false), /* pcrel_offset */
903 /* Relocation not handled: R_PPC_EMB_MRKREF */
904 /* Relocation not handled: R_PPC_EMB_RELSEC16 */
905 /* Relocation not handled: R_PPC_EMB_RELST_LO */
906 /* Relocation not handled: R_PPC_EMB_RELST_HI */
907 /* Relocation not handled: R_PPC_EMB_RELST_HA */
908 /* Relocation not handled: R_PPC_EMB_BIT_FLD */
910 /* PC relative relocation against either _SDA_BASE_ or _SDA2_BASE_, filling
911 in the 16 bit signed offset from the appropriate base, and filling in the
912 register field with the appropriate register (0, 2, or 13). */
913 HOWTO (R_PPC_EMB_RELSDA, /* type */
915 1, /* size (0 = byte, 1 = short, 2 = long) */
917 true, /* pc_relative */
919 complain_overflow_signed, /* complain_on_overflow */
920 bfd_elf_generic_reloc, /* special_function */
921 "R_PPC_EMB_RELSDA", /* name */
922 false, /* partial_inplace */
924 0xffff, /* dst_mask */
925 false), /* pcrel_offset */
927 /* Phony reloc to handle AIX style TOC entries */
928 HOWTO (R_PPC_TOC16, /* type */
930 1, /* size (0 = byte, 1 = short, 2 = long) */
932 false, /* pc_relative */
934 complain_overflow_signed, /* complain_on_overflow */
935 bfd_elf_generic_reloc, /* special_function */
936 "R_PPC_TOC16", /* name */
937 false, /* partial_inplace */
939 0xffff, /* dst_mask */
940 false), /* pcrel_offset */
944 /* Initialize the ppc_elf_howto_table, so that linear accesses can be done. */
947 ppc_elf_howto_init ()
949 unsigned int i, type;
951 for (i = 0; i < sizeof (ppc_elf_howto_raw) / sizeof (ppc_elf_howto_raw[0]); i++)
953 type = ppc_elf_howto_raw[i].type;
954 BFD_ASSERT (type < sizeof(ppc_elf_howto_table) / sizeof(ppc_elf_howto_table[0]));
955 ppc_elf_howto_table[type] = &ppc_elf_howto_raw[i];
960 static reloc_howto_type *
961 ppc_elf_reloc_type_lookup (abfd, code)
963 bfd_reloc_code_real_type code;
965 enum ppc_reloc_type ppc_reloc = R_PPC_NONE;
967 if (!ppc_elf_howto_table[ R_PPC_ADDR32 ]) /* Initialize howto table if needed */
968 ppc_elf_howto_init ();
973 return (reloc_howto_type *)NULL;
975 case BFD_RELOC_NONE: ppc_reloc = R_PPC_NONE; break;
976 case BFD_RELOC_32: ppc_reloc = R_PPC_ADDR32; break;
977 case BFD_RELOC_PPC_BA26: ppc_reloc = R_PPC_ADDR24; break;
978 case BFD_RELOC_16: ppc_reloc = R_PPC_ADDR16; break;
979 case BFD_RELOC_LO16: ppc_reloc = R_PPC_ADDR16_LO; break;
980 case BFD_RELOC_HI16: ppc_reloc = R_PPC_ADDR16_HI; break;
981 case BFD_RELOC_HI16_S: ppc_reloc = R_PPC_ADDR16_HA; break;
982 case BFD_RELOC_PPC_BA16: ppc_reloc = R_PPC_ADDR14; break;
983 case BFD_RELOC_PPC_BA16_BRTAKEN: ppc_reloc = R_PPC_ADDR14_BRTAKEN; break;
984 case BFD_RELOC_PPC_BA16_BRNTAKEN: ppc_reloc = R_PPC_ADDR14_BRNTAKEN; break;
985 case BFD_RELOC_PPC_B26: ppc_reloc = R_PPC_REL24; break;
986 case BFD_RELOC_PPC_B16: ppc_reloc = R_PPC_REL14; break;
987 case BFD_RELOC_PPC_B16_BRTAKEN: ppc_reloc = R_PPC_REL14_BRTAKEN; break;
988 case BFD_RELOC_PPC_B16_BRNTAKEN: ppc_reloc = R_PPC_REL14_BRNTAKEN; break;
989 case BFD_RELOC_16_GOTOFF: ppc_reloc = R_PPC_GOT16; break;
990 case BFD_RELOC_LO16_GOTOFF: ppc_reloc = R_PPC_GOT16_LO; break;
991 case BFD_RELOC_HI16_GOTOFF: ppc_reloc = R_PPC_GOT16_HI; break;
992 case BFD_RELOC_HI16_S_GOTOFF: ppc_reloc = R_PPC_GOT16_HA; break;
993 case BFD_RELOC_24_PLT_PCREL: ppc_reloc = R_PPC_PLTREL24; break;
994 case BFD_RELOC_PPC_COPY: ppc_reloc = R_PPC_COPY; break;
995 case BFD_RELOC_PPC_GLOB_DAT: ppc_reloc = R_PPC_GLOB_DAT; break;
996 case BFD_RELOC_PPC_LOCAL24PC: ppc_reloc = R_PPC_LOCAL24PC; break;
997 case BFD_RELOC_32_PCREL: ppc_reloc = R_PPC_REL32; break;
998 case BFD_RELOC_32_PLTOFF: ppc_reloc = R_PPC_PLT32; break;
999 case BFD_RELOC_32_PLT_PCREL: ppc_reloc = R_PPC_PLTREL32; break;
1000 case BFD_RELOC_LO16_PLTOFF: ppc_reloc = R_PPC_PLT16_LO; break;
1001 case BFD_RELOC_HI16_PLTOFF: ppc_reloc = R_PPC_PLT16_HI; break;
1002 case BFD_RELOC_HI16_S_PLTOFF: ppc_reloc = R_PPC_PLT16_HA; break;
1003 case BFD_RELOC_GPREL16: ppc_reloc = R_PPC_SDAREL16; break;
1004 case BFD_RELOC_32_BASEREL: ppc_reloc = R_PPC_SECTOFF; break;
1005 case BFD_RELOC_LO16_BASEREL: ppc_reloc = R_PPC_SECTOFF_LO; break;
1006 case BFD_RELOC_HI16_BASEREL: ppc_reloc = R_PPC_SECTOFF_HI; break;
1007 case BFD_RELOC_HI16_S_BASEREL: ppc_reloc = R_PPC_SECTOFF_HA; break;
1008 case BFD_RELOC_CTOR: ppc_reloc = R_PPC_ADDR32; break;
1009 case BFD_RELOC_PPC_TOC16: ppc_reloc = R_PPC_TOC16; break;
1010 case BFD_RELOC_PPC_EMB_NADDR32: ppc_reloc = R_PPC_EMB_NADDR32; break;
1011 case BFD_RELOC_PPC_EMB_NADDR16: ppc_reloc = R_PPC_EMB_NADDR16; break;
1012 case BFD_RELOC_PPC_EMB_NADDR16_LO: ppc_reloc = R_PPC_EMB_NADDR16_LO; break;
1013 case BFD_RELOC_PPC_EMB_NADDR16_HI: ppc_reloc = R_PPC_EMB_NADDR16_HI; break;
1014 case BFD_RELOC_PPC_EMB_NADDR16_HA: ppc_reloc = R_PPC_EMB_NADDR16_HA; break;
1015 case BFD_RELOC_PPC_EMB_SDAI16: ppc_reloc = R_PPC_EMB_SDAI16; break;
1016 case BFD_RELOC_PPC_EMB_SDA2I16: ppc_reloc = R_PPC_EMB_SDA2I16; break;
1017 case BFD_RELOC_PPC_EMB_SDA2REL: ppc_reloc = R_PPC_EMB_SDA2REL; break;
1018 case BFD_RELOC_PPC_EMB_SDA21: ppc_reloc = R_PPC_EMB_SDA21; break;
1019 case BFD_RELOC_PPC_EMB_MRKREF: ppc_reloc = R_PPC_EMB_MRKREF; break;
1020 case BFD_RELOC_PPC_EMB_RELSEC16: ppc_reloc = R_PPC_EMB_RELSEC16; break;
1021 case BFD_RELOC_PPC_EMB_RELST_LO: ppc_reloc = R_PPC_EMB_RELST_LO; break;
1022 case BFD_RELOC_PPC_EMB_RELST_HI: ppc_reloc = R_PPC_EMB_RELST_HI; break;
1023 case BFD_RELOC_PPC_EMB_RELST_HA: ppc_reloc = R_PPC_EMB_RELST_HA; break;
1024 case BFD_RELOC_PPC_EMB_BIT_FLD: ppc_reloc = R_PPC_EMB_BIT_FLD; break;
1025 case BFD_RELOC_PPC_EMB_RELSDA: ppc_reloc = R_PPC_EMB_RELSDA; break;
1028 return ppc_elf_howto_table[ (int)ppc_reloc ];
1031 /* Set the howto pointer for a PowerPC ELF reloc. */
1034 ppc_elf_info_to_howto (abfd, cache_ptr, dst)
1037 Elf32_Internal_Rela *dst;
1039 if (!ppc_elf_howto_table[ R_PPC_ADDR32 ]) /* Initialize howto table if needed */
1040 ppc_elf_howto_init ();
1042 BFD_ASSERT (ELF32_R_TYPE (dst->r_info) < (unsigned int) R_PPC_max);
1043 cache_ptr->howto = ppc_elf_howto_table[ELF32_R_TYPE (dst->r_info)];
1046 /* Function to set whether a module needs the -mrelocatable bit set. */
1049 ppc_elf_set_private_flags (abfd, flags)
1053 BFD_ASSERT (!elf_flags_init (abfd)
1054 || elf_elfheader (abfd)->e_flags == flags);
1056 elf_elfheader (abfd)->e_flags = flags;
1057 elf_flags_init (abfd) = true;
1061 /* Copy backend specific data from one object module to another */
1063 ppc_elf_copy_private_bfd_data (ibfd, obfd)
1067 /* This function is selected based on the input vector. We only
1068 want to copy information over if the output BFD also uses Elf
1070 if (bfd_get_flavour (obfd) != bfd_target_elf_flavour)
1073 BFD_ASSERT (!elf_flags_init (obfd)
1074 || elf_elfheader (obfd)->e_flags == elf_elfheader (ibfd)->e_flags);
1076 elf_elfheader (obfd)->e_flags = elf_elfheader (ibfd)->e_flags;
1077 elf_flags_init (obfd) = true;
1081 /* Merge backend specific data from an object file to the output
1082 object file when linking */
1084 ppc_elf_merge_private_bfd_data (ibfd, obfd)
1092 /* Check if we have the same endianess */
1093 if (ibfd->xvec->byteorder != obfd->xvec->byteorder
1094 && obfd->xvec->byteorder != BFD_ENDIAN_UNKNOWN)
1096 (*_bfd_error_handler)
1097 ("%s: compiled for a %s endian system and target is %s endian",
1098 bfd_get_filename (ibfd),
1099 bfd_big_endian (ibfd) ? "big" : "little",
1100 bfd_big_endian (obfd) ? "big" : "little");
1102 bfd_set_error (bfd_error_wrong_format);
1106 /* This function is selected based on the input vector. We only
1107 want to copy information over if the output BFD also uses Elf
1109 if (bfd_get_flavour (obfd) != bfd_target_elf_flavour)
1112 new_flags = elf_elfheader (ibfd)->e_flags;
1113 old_flags = elf_elfheader (obfd)->e_flags;
1114 if (!elf_flags_init (obfd)) /* First call, no flags set */
1116 elf_flags_init (obfd) = true;
1117 elf_elfheader (obfd)->e_flags = new_flags;
1120 else if (new_flags == old_flags) /* Compatible flags are ok */
1123 else /* Incompatible flags */
1125 /* Warn about -mrelocatable mismatch. Allow -mrelocatable-lib to be linked
1128 if ((new_flags & EF_PPC_RELOCATABLE) != 0
1129 && (old_flags & (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB)) == 0)
1132 (*_bfd_error_handler)
1133 ("%s: compiled with -mrelocatable and linked with modules compiled normally",
1134 bfd_get_filename (ibfd));
1136 else if ((new_flags & (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB)) == 0
1137 && (old_flags & EF_PPC_RELOCATABLE) != 0)
1140 (*_bfd_error_handler)
1141 ("%s: compiled normally and linked with modules compiled with -mrelocatable",
1142 bfd_get_filename (ibfd));
1144 else if ((new_flags & EF_PPC_RELOCATABLE_LIB) != 0)
1145 elf_elfheader (obfd)->e_flags |= EF_PPC_RELOCATABLE_LIB;
1148 /* Do not warn about eabi vs. V.4 mismatch, just or in the bit if any module uses it */
1149 elf_elfheader (obfd)->e_flags |= (new_flags & EF_PPC_EMB);
1151 new_flags &= ~ (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB | EF_PPC_EMB);
1152 old_flags &= ~ (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB | EF_PPC_EMB);
1154 /* Warn about any other mismatches */
1155 if (new_flags != old_flags)
1158 (*_bfd_error_handler)
1159 ("%s: uses different e_flags (0x%lx) fields than previous modules (0x%lx)",
1160 bfd_get_filename (ibfd), (long)new_flags, (long)old_flags);
1165 bfd_set_error (bfd_error_bad_value);
1174 /* Handle a PowerPC specific section when reading an object file. This
1175 is called when elfcode.h finds a section with an unknown type. */
1178 ppc_elf_section_from_shdr (abfd, hdr, name)
1180 Elf32_Internal_Shdr *hdr;
1186 if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name))
1189 newsect = hdr->bfd_section;
1190 flags = bfd_get_section_flags (abfd, newsect);
1191 if (hdr->sh_flags & SHF_EXCLUDE)
1192 flags |= SEC_EXCLUDE;
1194 if (hdr->sh_type == SHT_ORDERED)
1195 flags |= SEC_SORT_ENTRIES;
1197 bfd_set_section_flags (abfd, newsect, flags);
1202 /* Set up any other section flags and such that may be necessary. */
1205 ppc_elf_fake_sections (abfd, shdr, asect)
1207 Elf32_Internal_Shdr *shdr;
1210 if ((asect->flags & SEC_EXCLUDE) != 0)
1211 shdr->sh_flags |= SHF_EXCLUDE;
1213 if ((asect->flags & SEC_SORT_ENTRIES) != 0)
1214 shdr->sh_type = SHT_ORDERED;
1218 /* Create a special linker section */
1219 static elf_linker_section_t *
1220 ppc_elf_create_linker_section (abfd, info, which)
1222 struct bfd_link_info *info;
1223 enum elf_linker_section_enum which;
1225 bfd *dynobj = elf_hash_table (info)->dynobj;
1226 elf_linker_section_t *lsect;
1228 /* Record the first bfd section that needs the special section */
1230 dynobj = elf_hash_table (info)->dynobj = abfd;
1232 /* If this is the first time, create the section */
1233 lsect = elf_linker_section (dynobj, which);
1236 elf_linker_section_t defaults;
1237 static elf_linker_section_t zero_section;
1239 defaults = zero_section;
1240 defaults.which = which;
1241 defaults.hole_written_p = false;
1242 defaults.alignment = 2;
1243 defaults.flags = SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY;
1248 (*_bfd_error_handler) ("%s: Unknown special linker type %d",
1249 bfd_get_filename (abfd),
1252 bfd_set_error (bfd_error_bad_value);
1253 return (elf_linker_section_t *)0;
1255 case LINKER_SECTION_GOT: /* .got section */
1256 defaults.name = ".got";
1257 defaults.rel_name = ".rela.got";
1258 defaults.sym_name = "_GLOBAL_OFFSET_TABLE_";
1259 defaults.max_hole_offset = 32764;
1260 defaults.hole_size = 16;
1261 defaults.sym_offset = 4;
1264 case LINKER_SECTION_SDATA: /* .sdata/.sbss section */
1265 defaults.name = ".sdata";
1266 defaults.rel_name = ".rela.sdata";
1267 defaults.bss_name = ".sbss";
1268 defaults.sym_name = "_SDA_BASE_";
1269 defaults.sym_offset = 32768;
1272 case LINKER_SECTION_SDATA2: /* .sdata2/.sbss2 section */
1273 defaults.name = ".sdata2";
1274 defaults.rel_name = ".rela.sdata2";
1275 defaults.bss_name = ".sbss2";
1276 defaults.sym_name = "_SDA2_BASE_";
1277 defaults.sym_offset = 32768;
1281 lsect = _bfd_elf_create_linker_section (abfd, info, which, &defaults);
1288 /* Adjust a symbol defined by a dynamic object and referenced by a
1289 regular object. The current definition is in some section of the
1290 dynamic object, but we're not including those sections. We have to
1291 change the definition to something the rest of the link can
1295 ppc_elf_adjust_dynamic_symbol (info, h)
1296 struct bfd_link_info *info;
1297 struct elf_link_hash_entry *h;
1300 fprintf (stderr, "ppc_elf_adjust_dynamic_symbol called\n");
1306 /* Increment the index of a dynamic symbol by a given amount. Called
1307 via elf_link_hash_traverse. */
1310 ppc_elf_adjust_dynindx (h, cparg)
1311 struct elf_link_hash_entry *h;
1314 int *cp = (int *) cparg;
1317 fprintf (stderr, "ppc_elf_adjust_dynindx called, h->dynindx = %d, *cp = %d\n", h->dynindx, *cp);
1320 if (h->dynindx != -1)
1327 /* Set the sizes of the dynamic sections. */
1330 ppc_elf_size_dynamic_sections (output_bfd, info)
1332 struct bfd_link_info *info;
1340 fprintf (stderr, "ppc_elf_size_dynamic_sections called\n");
1343 dynobj = elf_hash_table (info)->dynobj;
1344 BFD_ASSERT (dynobj != NULL);
1346 if (elf_hash_table (info)->dynamic_sections_created)
1348 /* Set the contents of the .interp section to the interpreter. */
1351 s = bfd_get_section_by_name (dynobj, ".interp");
1352 BFD_ASSERT (s != NULL);
1353 s->_raw_size = sizeof ELF_DYNAMIC_INTERPRETER;
1354 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
1357 /* Make space for the trailing nop in .plt. */
1358 s = bfd_get_section_by_name (dynobj, ".plt");
1359 BFD_ASSERT (s != NULL);
1360 if (s->_raw_size > 0)
1365 /* We may have created entries in the .rela.got, .rela.sdata, and
1366 .rela.sdata2 section2. However, if we are not creating the
1367 dynamic sections, we will not actually use these entries. Reset
1368 the size of .rela.got, et al, which will cause it to get
1369 stripped from the output file below. */
1370 static char *rela_sections[] = { ".rela.got", ".rela.sdata", ".rela.sdata", (char *)0 };
1373 for (p = rela_sections; *p != (char *)0; p++)
1375 s = bfd_get_section_by_name (dynobj, *p);
1381 /* The check_relocs and adjust_dynamic_symbol entry points have
1382 determined the sizes of the various dynamic sections. Allocate
1386 for (s = dynobj->sections; s != NULL; s = s->next)
1391 if ((s->flags & SEC_IN_MEMORY) == 0)
1394 /* It's OK to base decisions on the section name, because none
1395 of the dynobj section names depend upon the input files. */
1396 name = bfd_get_section_name (dynobj, s);
1401 if (strncmp (name, ".rela", 5) == 0)
1403 if (s->_raw_size == 0)
1405 /* If we don't need this section, strip it from the
1406 output file. This is to handle .rela.bss and
1407 .rel.plt. We must create it in
1408 create_dynamic_sections, because it must be created
1409 before the linker maps input sections to output
1410 sections. The linker does that before
1411 adjust_dynamic_symbol is called, and it is that
1412 function which decides whether anything needs to go
1413 into these sections. */
1420 /* If this relocation section applies to a read only
1421 section, then we probably need a DT_TEXTREL entry. */
1422 target = bfd_get_section_by_name (output_bfd, name + 5);
1424 && (target->flags & SEC_READONLY) != 0)
1427 if (strcmp (name, ".rela.plt") == 0)
1430 /* We use the reloc_count field as a counter if we need
1431 to copy relocs into the output file. */
1437 if (strcmp (name, ".plt") != 0
1438 && strcmp (name, ".got") != 0
1439 && strcmp (name, ".sdata") != 0
1440 && strcmp (name, ".sdata2") != 0
1441 && strcmp (name, ".rela.sdata") != 0
1442 && strcmp (name, ".rela.sdata2") != 0)
1444 /* It's not one of our sections, so don't allocate space. */
1452 for (spp = &s->output_section->owner->sections;
1453 *spp != s->output_section;
1454 spp = &(*spp)->next)
1456 *spp = s->output_section->next;
1457 --s->output_section->owner->section_count;
1462 /* Allocate memory for the section contents. */
1463 s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->_raw_size);
1464 if (s->contents == NULL && s->_raw_size != 0)
1468 if (elf_hash_table (info)->dynamic_sections_created)
1470 /* Add some entries to the .dynamic section. We fill in the
1471 values later, in ppc_elf_finish_dynamic_sections, but we
1472 must add the entries now so that we get the correct size for
1473 the .dynamic section. The DT_DEBUG entry is filled in by the
1474 dynamic linker and used by the debugger. */
1477 if (! bfd_elf32_add_dynamic_entry (info, DT_DEBUG, 0))
1481 if (! bfd_elf32_add_dynamic_entry (info, DT_PLTGOT, 0))
1486 if (! bfd_elf32_add_dynamic_entry (info, DT_PLTRELSZ, 0)
1487 || ! bfd_elf32_add_dynamic_entry (info, DT_PLTREL, DT_RELA)
1488 || ! bfd_elf32_add_dynamic_entry (info, DT_JMPREL, 0))
1492 if (! bfd_elf32_add_dynamic_entry (info, DT_RELA, 0)
1493 || ! bfd_elf32_add_dynamic_entry (info, DT_RELASZ, 0)
1494 || ! bfd_elf32_add_dynamic_entry (info, DT_RELAENT,
1495 sizeof (Elf32_External_Rela)))
1500 if (! bfd_elf32_add_dynamic_entry (info, DT_TEXTREL, 0))
1505 /* If we are generating a shared library, we generate a section
1506 symbol for each output section. These are local symbols, which
1507 means that they must come first in the dynamic symbol table.
1508 That means we must increment the dynamic symbol index of every
1509 other dynamic symbol. */
1514 c = bfd_count_sections (output_bfd);
1515 elf_link_hash_traverse (elf_hash_table (info),
1516 ppc_elf_adjust_dynindx,
1518 elf_hash_table (info)->dynsymcount += c;
1520 for (i = 1, s = output_bfd->sections; s != NULL; s = s->next, i++)
1522 elf_section_data (s)->dynindx = i;
1523 /* These symbols will have no names, so we don't need to
1524 fiddle with dynstr_index. */
1532 /* Look through the relocs for a section during the first phase, and
1533 allocate space in the global offset table or procedure linkage
1537 ppc_elf_check_relocs (abfd, info, sec, relocs)
1539 struct bfd_link_info *info;
1541 const Elf_Internal_Rela *relocs;
1544 Elf_Internal_Shdr *symtab_hdr;
1545 struct elf_link_hash_entry **sym_hashes;
1546 const Elf_Internal_Rela *rel;
1547 const Elf_Internal_Rela *rel_end;
1548 elf_linker_section_t *got;
1549 elf_linker_section_t *sdata;
1550 elf_linker_section_t *sdata2;
1553 if (info->relocateable)
1557 fprintf (stderr, "ppc_elf_check_relocs called for section %s\n",
1558 bfd_get_section_name (abfd, sec));
1561 /* Create the linker generated sections all the time so that the special
1562 symbols are created. */
1563 if ((got = elf_linker_section (abfd, LINKER_SECTION_GOT)) == NULL)
1565 got = ppc_elf_create_linker_section (abfd, info, LINKER_SECTION_GOT);
1570 if ((sdata = elf_linker_section (abfd, LINKER_SECTION_SDATA)) == NULL)
1572 sdata = ppc_elf_create_linker_section (abfd, info, LINKER_SECTION_SDATA);
1578 if ((sdata2 = elf_linker_section (abfd, LINKER_SECTION_SDATA2)) == NULL)
1580 sdata2 = ppc_elf_create_linker_section (abfd, info, LINKER_SECTION_SDATA2);
1585 dynobj = elf_hash_table (info)->dynobj;
1586 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
1587 sym_hashes = elf_sym_hashes (abfd);
1591 rel_end = relocs + sec->reloc_count;
1592 for (rel = relocs; rel < rel_end; rel++)
1594 unsigned long r_symndx;
1595 struct elf_link_hash_entry *h;
1597 r_symndx = ELF32_R_SYM (rel->r_info);
1598 if (r_symndx < symtab_hdr->sh_info)
1601 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
1603 switch (ELF32_R_TYPE (rel->r_info))
1608 /* GOT16 relocations */
1610 case R_PPC_GOT16_LO:
1611 case R_PPC_GOT16_HI:
1612 case R_PPC_GOT16_HA:
1613 if (got->rel_section == NULL
1614 && (h != NULL || info->shared)
1615 && !_bfd_elf_make_linker_section_rela (dynobj, got, 2))
1618 if (!bfd_elf32_create_pointer_linker_section (abfd, info, got, h, rel))
1623 /* Indirect .sdata relocation */
1624 case R_PPC_EMB_SDAI16:
1625 if (got->rel_section == NULL
1626 && (h != NULL || info->shared)
1627 && !_bfd_elf_make_linker_section_rela (dynobj, got, 2))
1630 if (!bfd_elf32_create_pointer_linker_section (abfd, info, sdata, h, rel))
1635 /* Indirect .sdata2 relocation */
1636 case R_PPC_EMB_SDA2I16:
1637 if (got->rel_section == NULL
1638 && (h != NULL || info->shared)
1639 && !_bfd_elf_make_linker_section_rela (dynobj, got, 2))
1642 if (!bfd_elf32_create_pointer_linker_section (abfd, info, sdata2, h, rel))
1649 case R_PPC_PLTREL24:
1650 case R_PPC_PLT16_LO:
1651 case R_PPC_PLT16_HI:
1652 case R_PPC_PLT16_HA:
1654 fprintf (stderr, "Reloc requires a PLT entry\n");
1656 /* This symbol requires a procedure linkage table entry. We
1657 actually build the entry in adjust_dynamic_symbol,
1658 because this might be a case of linking PIC code without
1659 linking in any dynamic objects, in which case we don't
1660 need to generate a procedure linkage table after all. */
1664 /* It does not make sense to have a procedure linkage
1665 table entry for a local symbol. */
1666 bfd_set_error (bfd_error_bad_value);
1670 /* Make sure this symbol is output as a dynamic symbol. */
1671 if (h->dynindx == -1)
1673 if (! bfd_elf32_link_record_dynamic_symbol (info, h))
1677 h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
1683 && strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
1687 case R_SPARC_DISP16:
1688 case R_SPARC_DISP32:
1689 case R_SPARC_WDISP30:
1690 case R_SPARC_WDISP22:
1703 && (sec->flags & SEC_ALLOC) != 0)
1705 /* When creating a shared object, we must copy these
1706 relocs into the output file. We create a reloc
1707 section in dynobj and make room for the reloc. */
1712 name = (bfd_elf_string_from_elf_section
1714 elf_elfheader (abfd)->e_shstrndx,
1715 elf_section_data (sec)->rel_hdr.sh_name));
1719 BFD_ASSERT (strncmp (name, ".rela", 5) == 0
1720 && strcmp (bfd_get_section_name (abfd, sec),
1723 sreloc = bfd_get_section_by_name (dynobj, name);
1726 sreloc = bfd_make_section (dynobj, name);
1728 || ! bfd_set_section_flags (dynobj, sreloc,
1734 || ! bfd_set_section_alignment (dynobj, sreloc, 2))
1739 sreloc->_raw_size += sizeof (Elf32_External_Rela);
1751 /* Hook called by the linker routine which adds symbols from an object
1752 file. We use it to put .comm items in .sbss, and not .bss. */
1756 ppc_elf_add_symbol_hook (abfd, info, sym, namep, flagsp, secp, valp)
1758 struct bfd_link_info *info;
1759 const Elf_Internal_Sym *sym;
1765 if (sym->st_shndx == SHN_COMMON && sym->st_size <= bfd_get_gp_size (abfd))
1767 /* Common symbols less than or equal to -G nn bytes are automatically
1769 bfd *dynobj = elf_hash_table (info)->dynobj;
1770 elf_linker_section_t *sdata = elf_linker_section (dynobj, LINKER_SECTION_SDATA);
1771 if (!sdata->bss_section)
1772 sdata->bss_section = bfd_make_section (dynobj, sdata->bss_name);
1773 *secp = sdata->bss_section;
1774 (*secp)->flags |= SEC_IS_COMMON;
1775 *valp = sym->st_size;
1782 /* Finish up dynamic symbol handling. We set the contents of various
1783 dynamic sections here. */
1786 ppc_elf_finish_dynamic_symbol (output_bfd, info, h, sym)
1788 struct bfd_link_info *info;
1789 struct elf_link_hash_entry *h;
1790 Elf_Internal_Sym *sym;
1795 fprintf (stderr, "ppc_elf_finish_dynamic_symbol called for %s\n", h->root.root.string);
1798 dynobj = elf_hash_table (info)->dynobj;
1799 BFD_ASSERT (dynobj != NULL);
1801 if (h->plt_offset != (bfd_vma) -1)
1805 Elf_Internal_Rela rela;
1807 /* This symbol has an entry in the procedure linkage table. Set
1810 BFD_ASSERT (h->dynindx != -1);
1812 splt = bfd_get_section_by_name (dynobj, ".plt");
1813 srela = bfd_get_section_by_name (dynobj, ".rela.plt");
1814 BFD_ASSERT (splt != NULL && srela != NULL);
1816 /* Fill in the entry in the procedure linkage table. */
1818 bfd_put_32 (output_bfd,
1819 PLT_ENTRY_WORD0 + h->plt_offset,
1820 splt->contents + h->plt_offset);
1821 bfd_put_32 (output_bfd,
1823 + (((- (h->plt_offset + 4)) >> 2) & 0x3fffff)),
1824 splt->contents + h->plt_offset + 4);
1825 bfd_put_32 (output_bfd, PLT_ENTRY_WORD2,
1826 splt->contents + h->plt_offset + 8);
1828 /* Fill in the entry in the .rela.plt section. */
1829 rela.r_offset = (splt->output_section->vma
1830 + splt->output_offset
1832 rela.r_info = ELF32_R_INFO (h->dynindx, R_SPARC_JMP_SLOT);
1834 bfd_elf32_swap_reloca_out (output_bfd, &rela,
1835 ((Elf32_External_Rela *) srela->contents
1836 + h->plt_offset / PLT_ENTRY_SIZE - 4));
1839 if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
1841 /* Mark the symbol as undefined, rather than as defined in
1842 the .plt section. Leave the value alone. */
1843 sym->st_shndx = SHN_UNDEF;
1847 if ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_COPY) != 0)
1850 Elf_Internal_Rela rela;
1852 /* This symbols needs a copy reloc. Set it up. */
1854 BFD_ASSERT (h->dynindx != -1);
1856 s = bfd_get_section_by_name (h->root.u.def.section->owner,
1858 BFD_ASSERT (s != NULL);
1860 rela.r_offset = (h->root.u.def.value
1861 + h->root.u.def.section->output_section->vma
1862 + h->root.u.def.section->output_offset);
1863 rela.r_info = ELF32_R_INFO (h->dynindx, R_PPC_COPY);
1865 bfd_elf32_swap_reloca_out (output_bfd, &rela,
1866 ((Elf32_External_Rela *) s->contents
1871 /* Mark some specially defined symbols as absolute. */
1872 if (strcmp (h->root.root.string, "_DYNAMIC") == 0
1873 || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0
1874 || strcmp (h->root.root.string, "_PROCEDURE_LINKAGE_TABLE_") == 0)
1875 sym->st_shndx = SHN_ABS;
1881 /* Finish up the dynamic sections. */
1884 ppc_elf_finish_dynamic_sections (output_bfd, info)
1886 struct bfd_link_info *info;
1889 bfd *dynobj = elf_hash_table (info)->dynobj;
1890 elf_linker_section_t *got = elf_linker_section (dynobj, LINKER_SECTION_GOT);
1893 fprintf (stderr, "ppc_elf_finish_dynamic_sections called\n");
1896 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
1898 if (elf_hash_table (info)->dynamic_sections_created)
1901 Elf32_External_Dyn *dyncon, *dynconend;
1903 splt = bfd_get_section_by_name (dynobj, ".plt");
1904 BFD_ASSERT (splt != NULL && sdyn != NULL);
1906 dyncon = (Elf32_External_Dyn *) sdyn->contents;
1907 dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->_raw_size);
1908 for (; dyncon < dynconend; dyncon++)
1910 Elf_Internal_Dyn dyn;
1914 bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
1918 case DT_PLTGOT: name = ".plt"; size = false; break;
1919 case DT_PLTRELSZ: name = ".rela.plt"; size = true; break;
1920 case DT_JMPREL: name = ".rela.plt"; size = false; break;
1921 default: name = NULL; size = false; break;
1928 s = bfd_get_section_by_name (output_bfd, name);
1934 dyn.d_un.d_ptr = s->vma;
1937 if (s->_cooked_size != 0)
1938 dyn.d_un.d_val = s->_cooked_size;
1940 dyn.d_un.d_val = s->_raw_size;
1943 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
1948 /* Add a blrl instruction at _GLOBAL_OFFSET_TABLE_-4 so that a function can
1949 easily find the address of the _GLOBAL_OFFSET_TABLE_. */
1952 unsigned char *contents = got->section->contents + got->hole_offset;
1953 bfd_put_32 (output_bfd, 0x4e800021 /* blrl */, contents);
1956 bfd_put_32 (output_bfd, (bfd_vma) 0, contents+4);
1958 bfd_put_32 (output_bfd,
1959 sdyn->output_section->vma + sdyn->output_offset,
1962 elf_section_data (got->section->output_section)->this_hdr.sh_entsize = 4;
1969 Elf_Internal_Sym sym;
1971 /* Set up the section symbols for the output sections. */
1973 sdynsym = bfd_get_section_by_name (dynobj, ".dynsym");
1974 BFD_ASSERT (sdynsym != NULL);
1978 sym.st_info = ELF_ST_INFO (STB_LOCAL, STT_SECTION);
1981 for (s = output_bfd->sections; s != NULL; s = s->next)
1985 sym.st_value = s->vma;
1987 indx = elf_section_data (s)->this_idx;
1988 BFD_ASSERT (indx > 0);
1989 sym.st_shndx = indx;
1991 bfd_elf32_swap_symbol_out (output_bfd, &sym,
1992 (PTR) (((Elf32_External_Sym *)
1994 + elf_section_data (s)->dynindx));
1997 /* Set the sh_info field of the output .dynsym section to the
1998 index of the first global symbol. */
1999 elf_section_data (sdynsym->output_section)->this_hdr.sh_info =
2000 bfd_count_sections (output_bfd) + 1;
2007 /* The RELOCATE_SECTION function is called by the ELF backend linker
2008 to handle the relocations for a section.
2010 The relocs are always passed as Rela structures; if the section
2011 actually uses Rel structures, the r_addend field will always be
2014 This function is responsible for adjust the section contents as
2015 necessary, and (if using Rela relocs and generating a
2016 relocateable output file) adjusting the reloc addend as
2019 This function does not have to worry about setting the reloc
2020 address or the reloc symbol index.
2022 LOCAL_SYMS is a pointer to the swapped in local symbols.
2024 LOCAL_SECTIONS is an array giving the section in the input file
2025 corresponding to the st_shndx field of each local symbol.
2027 The global hash table entry for the global symbols can be found
2028 via elf_sym_hashes (input_bfd).
2030 When generating relocateable output, this function must handle
2031 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
2032 going to be the section symbol corresponding to the output
2033 section, which means that the addend must be adjusted
2037 ppc_elf_relocate_section (output_bfd, info, input_bfd, input_section,
2038 contents, relocs, local_syms, local_sections)
2040 struct bfd_link_info *info;
2042 asection *input_section;
2044 Elf_Internal_Rela *relocs;
2045 Elf_Internal_Sym *local_syms;
2046 asection **local_sections;
2048 Elf_Internal_Shdr *symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
2049 struct elf_link_hash_entry **sym_hashes = elf_sym_hashes (input_bfd);
2050 bfd *dynobj = elf_hash_table (info)->dynobj;
2051 elf_linker_section_t *got = elf_linker_section (dynobj, LINKER_SECTION_GOT);
2052 elf_linker_section_t *sdata = elf_linker_section (dynobj, LINKER_SECTION_SDATA);
2053 elf_linker_section_t *sdata2 = elf_linker_section (dynobj, LINKER_SECTION_SDATA2);
2054 Elf_Internal_Rela *rel = relocs;
2055 Elf_Internal_Rela *relend = relocs + input_section->reloc_count;
2060 fprintf (stderr, "ppc_elf_relocate_section called for %s section %s, %ld relocations%s\n",
2061 bfd_get_filename (input_bfd),
2062 bfd_section_name(input_bfd, input_section),
2063 (long)input_section->reloc_count,
2064 (info->relocateable) ? " (relocatable)" : "");
2067 if (!ppc_elf_howto_table[ R_PPC_ADDR32 ]) /* Initialize howto table if needed */
2068 ppc_elf_howto_init ();
2070 for (; rel < relend; rel++)
2072 enum ppc_reloc_type r_type = (enum ppc_reloc_type)ELF32_R_TYPE (rel->r_info);
2073 bfd_vma offset = rel->r_offset;
2074 bfd_vma addend = rel->r_addend;
2075 bfd_reloc_status_type r = bfd_reloc_other;
2076 Elf_Internal_Sym *sym = (Elf_Internal_Sym *)0;
2077 asection *sec = (asection *)0;
2078 struct elf_link_hash_entry *h = (struct elf_link_hash_entry *)0;
2079 const char *sym_name = (const char *)0;
2080 reloc_howto_type *howto;
2081 unsigned long r_symndx;
2084 /* Unknown relocation handling */
2085 if ((unsigned)r_type >= (unsigned)R_PPC_max || !ppc_elf_howto_table[(int)r_type])
2087 (*_bfd_error_handler) ("%s: unknown relocation type %d",
2088 bfd_get_filename (input_bfd),
2091 bfd_set_error (bfd_error_bad_value);
2096 howto = ppc_elf_howto_table[(int)r_type];
2097 r_symndx = ELF32_R_SYM (rel->r_info);
2099 if (info->relocateable)
2101 /* This is a relocateable link. We don't have to change
2102 anything, unless the reloc is against a section symbol,
2103 in which case we have to adjust according to where the
2104 section symbol winds up in the output section. */
2105 if (r_symndx < symtab_hdr->sh_info)
2107 sym = local_syms + r_symndx;
2108 if ((unsigned)ELF_ST_TYPE (sym->st_info) == STT_SECTION)
2110 sec = local_sections[r_symndx];
2111 addend = rel->r_addend += sec->output_offset + sym->st_value;
2116 fprintf (stderr, "\ttype = %s (%d), symbol index = %ld, offset = %ld, addend = %ld\n",
2126 /* This is a final link. */
2127 if (r_symndx < symtab_hdr->sh_info)
2129 sym = local_syms + r_symndx;
2130 sec = local_sections[r_symndx];
2131 sym_name = "<local symbol>";
2133 relocation = (sec->output_section->vma
2134 + sec->output_offset
2139 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
2140 while (h->root.type == bfd_link_hash_indirect
2141 || h->root.type == bfd_link_hash_warning)
2142 h = (struct elf_link_hash_entry *) h->root.u.i.link;
2143 sym_name = h->root.root.string;
2144 if (h->root.type == bfd_link_hash_defined
2145 || h->root.type == bfd_link_hash_defweak)
2147 sec = h->root.u.def.section;
2148 relocation = (h->root.u.def.value
2149 + sec->output_section->vma
2150 + sec->output_offset);
2152 else if (h->root.type == bfd_link_hash_undefweak)
2154 else if (info->shared)
2158 (*info->callbacks->undefined_symbol)(info,
2159 h->root.root.string,
2168 switch ((int)r_type)
2171 (*_bfd_error_handler) ("%s: unknown relocation type %d for symbol %s",
2172 bfd_get_filename (input_bfd),
2173 (int)r_type, sym_name);
2175 bfd_set_error (bfd_error_bad_value);
2179 /* relocations that need no special processing */
2180 case (int)R_PPC_NONE:
2181 case (int)R_PPC_ADDR32:
2182 case (int)R_PPC_ADDR24:
2183 case (int)R_PPC_ADDR16:
2184 case (int)R_PPC_ADDR16_LO:
2185 case (int)R_PPC_ADDR16_HI:
2186 case (int)R_PPC_ADDR14:
2187 case (int)R_PPC_REL24:
2188 case (int)R_PPC_REL14:
2189 case (int)R_PPC_UADDR32:
2190 case (int)R_PPC_UADDR16:
2191 case (int)R_PPC_REL32:
2194 /* branch taken prediction relocations */
2195 case (int)R_PPC_ADDR14_BRTAKEN:
2196 case (int)R_PPC_REL14_BRTAKEN:
2197 insn = bfd_get_32 (output_bfd, contents + offset);
2198 if ((relocation - offset) & 0x8000)
2199 insn &= ~BRANCH_PREDICT_BIT;
2201 insn |= BRANCH_PREDICT_BIT;
2202 bfd_put_32 (output_bfd, insn, contents + offset);
2205 /* branch not taken predicition relocations */
2206 case (int)R_PPC_ADDR14_BRNTAKEN:
2207 case (int)R_PPC_REL14_BRNTAKEN:
2208 insn = bfd_get_32 (output_bfd, contents + offset);
2209 if ((relocation - offset) & 0x8000)
2210 insn |= BRANCH_PREDICT_BIT;
2212 insn &= ~BRANCH_PREDICT_BIT;
2213 bfd_put_32 (output_bfd, insn, contents + offset);
2216 /* GOT16 relocations */
2217 case (int)R_PPC_GOT16:
2218 case (int)R_PPC_GOT16_LO:
2219 case (int)R_PPC_GOT16_HI:
2220 case (int)R_PPC_GOT16_HA:
2221 relocation = bfd_elf32_finish_pointer_linker_section (output_bfd, input_bfd, info,
2222 got, h, relocation, rel,
2226 /* Indirect .sdata relocation */
2227 case (int)R_PPC_EMB_SDAI16:
2228 BFD_ASSERT (sdata != NULL);
2229 relocation = bfd_elf32_finish_pointer_linker_section (output_bfd, input_bfd, info,
2230 sdata, h, relocation, rel,
2234 /* Indirect .sdata2 relocation */
2235 case (int)R_PPC_EMB_SDA2I16:
2236 BFD_ASSERT (sdata2 != NULL);
2237 relocation = bfd_elf32_finish_pointer_linker_section (output_bfd, input_bfd, info,
2238 sdata2, h, relocation, rel,
2242 /* Handle the TOC16 reloc. We want to use the offset within the .got
2243 section, not the actual VMA. This is appropriate when generating
2244 an embedded ELF object, for which the .got section acts like the
2245 AIX .toc section. */
2246 case (int)R_PPC_TOC16: /* phony GOT16 relocations */
2247 BFD_ASSERT (sec != (asection *)0);
2248 BFD_ASSERT (bfd_is_und_section (sec)
2249 || strcmp (bfd_get_section_name (abfd, sec), ".got") == 0
2250 || strcmp (bfd_get_section_name (abfd, sec), ".cgot") == 0)
2252 addend -= sec->output_section->vma + sec->output_offset + 0x8000;
2255 /* arithmetic adjust relocations */
2256 case (int)R_PPC_ADDR16_HA:
2257 BFD_ASSERT (sec != (asection *)0);
2258 addend += ((relocation + addend) & 0x8000) << 1;
2261 /* relocate against _SDA_BASE_ */
2262 case (int)R_PPC_SDAREL16:
2263 BFD_ASSERT (sec != (asection *)0);
2264 if (strcmp (bfd_get_section_name (abfd, sec), ".sdata") != 0
2265 && strcmp (bfd_get_section_name (abfd, sec), ".sbss") != 0)
2267 (*_bfd_error_handler) ("%s: The target (%s) of a %s relocation is in the wrong section (%s)",
2268 bfd_get_filename (input_bfd),
2270 ppc_elf_howto_table[ (int)r_type ]->name,
2271 bfd_get_section_name (abfd, sec));
2273 bfd_set_error (bfd_error_bad_value);
2277 addend -= (sdata->sym_hash->root.u.def.value
2278 + sdata->sym_hash->root.u.def.section->output_section->vma
2279 + sdata->sym_hash->root.u.def.section->output_offset);
2283 /* relocate against _SDA2_BASE_ */
2284 case (int)R_PPC_EMB_SDA2REL:
2285 BFD_ASSERT (sec != (asection *)0);
2286 if (strcmp (bfd_get_section_name (abfd, sec), ".sdata2") != 0
2287 && strcmp (bfd_get_section_name (abfd, sec), ".sbss2") != 0)
2289 (*_bfd_error_handler) ("%s: The target (%s) of a %s relocation is in the wrong section (%s)",
2290 bfd_get_filename (input_bfd),
2292 ppc_elf_howto_table[ (int)r_type ]->name,
2293 bfd_get_section_name (abfd, sec));
2295 bfd_set_error (bfd_error_bad_value);
2299 addend -= (sdata2->sym_hash->root.u.def.value
2300 + sdata2->sym_hash->root.u.def.section->output_section->vma
2301 + sdata2->sym_hash->root.u.def.section->output_offset);
2305 /* relocate against either _SDA_BASE_, _SDA2_BASE_, or 0 */
2306 case (int)R_PPC_EMB_SDA21:
2307 case (int)R_PPC_EMB_RELSDA:
2309 const char *name = bfd_get_section_name (abfd, sec);
2312 BFD_ASSERT (sec != (asection *)0);
2313 if (strcmp (name, ".sdata") == 0 || strcmp (name, ".sbss") == 0)
2316 addend -= (sdata->sym_hash->root.u.def.value
2317 + sdata->sym_hash->root.u.def.section->output_section->vma
2318 + sdata->sym_hash->root.u.def.section->output_offset);
2321 else if (strcmp (name, ".sdata2") == 0 || strcmp (name, ".sbss2") == 0)
2324 addend -= (sdata2->sym_hash->root.u.def.value
2325 + sdata2->sym_hash->root.u.def.section->output_section->vma
2326 + sdata2->sym_hash->root.u.def.section->output_offset);
2329 else if (strcmp (name, ".PPC.EMB.sdata0") == 0 || strcmp (name, ".PPC.EMB.sbss0") == 0)
2336 (*_bfd_error_handler) ("%s: The target (%s) of a %s relocation is in the wrong section (%s)",
2337 bfd_get_filename (input_bfd),
2339 ppc_elf_howto_table[ (int)r_type ]->name,
2340 bfd_get_section_name (abfd, sec));
2342 bfd_set_error (bfd_error_bad_value);
2347 if (r_type == R_PPC_EMB_SDA21)
2348 { /* fill in register field */
2349 insn = bfd_get_32 (output_bfd, contents + offset);
2350 insn = (insn & ~RA_REGISTER_MASK) | (reg << RA_REGISTER_SHIFT);
2351 bfd_put_32 (output_bfd, insn, contents + offset);
2356 /* Relocate against the beginning of the section */
2357 case (int)R_PPC_SECTOFF:
2358 case (int)R_PPC_SECTOFF_LO:
2359 case (int)R_PPC_SECTOFF_HI:
2360 BFD_ASSERT (sec != (asection *)0);
2361 addend -= sec->output_section->vma;
2364 case (int)R_PPC_SECTOFF_HA:
2365 BFD_ASSERT (sec != (asection *)0);
2366 addend -= sec->output_section->vma;
2367 addend += ((relocation + addend) & 0x8000) << 1;
2370 /* Negative relocations */
2371 case (int)R_PPC_EMB_NADDR32:
2372 case (int)R_PPC_EMB_NADDR16:
2373 case (int)R_PPC_EMB_NADDR16_LO:
2374 case (int)R_PPC_EMB_NADDR16_HI:
2375 addend -= 2*relocation;
2378 case (int)R_PPC_EMB_NADDR16_HA:
2379 addend -= 2*relocation;
2380 addend += ((relocation + addend) & 0x8000) << 1;
2383 /* NOP relocation that prevents garbage collecting linkers from omitting a
2385 case (int)R_PPC_EMB_MRKREF:
2388 case (int)R_PPC_PLTREL24:
2389 case (int)R_PPC_COPY:
2390 case (int)R_PPC_GLOB_DAT:
2391 case (int)R_PPC_JMP_SLOT:
2392 case (int)R_PPC_RELATIVE:
2393 case (int)R_PPC_LOCAL24PC:
2394 case (int)R_PPC_PLT32:
2395 case (int)R_PPC_PLTREL32:
2396 case (int)R_PPC_PLT16_LO:
2397 case (int)R_PPC_PLT16_HI:
2398 case (int)R_PPC_PLT16_HA:
2399 case (int)R_PPC_EMB_RELSEC16:
2400 case (int)R_PPC_EMB_RELST_LO:
2401 case (int)R_PPC_EMB_RELST_HI:
2402 case (int)R_PPC_EMB_RELST_HA:
2403 case (int)R_PPC_EMB_BIT_FLD:
2404 (*_bfd_error_handler) ("%s: Relocation %s is not yet supported for symbol %s.",
2405 bfd_get_filename (input_bfd),
2406 ppc_elf_howto_table[ (int)r_type ]->name,
2409 bfd_set_error (bfd_error_invalid_operation);
2416 fprintf (stderr, "\ttype = %s (%d), name = %s, symbol index = %ld, offset = %ld, addend = %ld\n",
2425 r = _bfd_final_link_relocate (howto,
2433 if (r != bfd_reloc_ok)
2441 case bfd_reloc_overflow:
2446 name = h->root.root.string;
2449 name = bfd_elf_string_from_elf_section (input_bfd,
2450 symtab_hdr->sh_link,
2456 name = bfd_section_name (input_bfd, sec);
2459 (*info->callbacks->reloc_overflow)(info,
2475 fprintf (stderr, "\n");
2482 #define TARGET_LITTLE_SYM bfd_elf32_powerpcle_vec
2483 #define TARGET_LITTLE_NAME "elf32-powerpcle"
2484 #define TARGET_BIG_SYM bfd_elf32_powerpc_vec
2485 #define TARGET_BIG_NAME "elf32-powerpc"
2486 #define ELF_ARCH bfd_arch_powerpc
2487 #define ELF_MACHINE_CODE EM_PPC
2488 #define ELF_MAXPAGESIZE 0x10000
2489 #define elf_info_to_howto ppc_elf_info_to_howto
2491 #ifdef EM_CYGNUS_POWERPC
2492 #define ELF_MACHINE_ALT1 EM_CYGNUS_POWERPC
2496 #define ELF_MACHINE_ALT2 EM_PPC_OLD
2499 #define bfd_elf32_bfd_copy_private_bfd_data ppc_elf_copy_private_bfd_data
2500 #define bfd_elf32_bfd_merge_private_bfd_data ppc_elf_merge_private_bfd_data
2501 #define bfd_elf32_bfd_set_private_flags ppc_elf_set_private_flags
2502 #define bfd_elf32_bfd_reloc_type_lookup ppc_elf_reloc_type_lookup
2503 #define elf_backend_section_from_shdr ppc_elf_section_from_shdr
2504 #define elf_backend_relocate_section ppc_elf_relocate_section
2505 #define elf_backend_create_dynamic_sections _bfd_elf_create_dynamic_sections
2506 #define elf_backend_check_relocs ppc_elf_check_relocs
2507 #define elf_backend_adjust_dynamic_symbol ppc_elf_adjust_dynamic_symbol
2508 #define elf_backend_add_symbol_hook ppc_elf_add_symbol_hook
2509 #define elf_backend_size_dynamic_sections ppc_elf_size_dynamic_sections
2510 #define elf_backend_finish_dynamic_symbol ppc_elf_finish_dynamic_symbol
2511 #define elf_backend_finish_dynamic_sections ppc_elf_finish_dynamic_sections
2512 #define elf_backend_fake_sections ppc_elf_fake_sections
2514 #include "elf32-target.h"