1 /* PowerPC-specific support for 32-bit ELF
2 Copyright 1994, 1995 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 bfd_reloc_status_type ppc_elf_unsupported_reloc
103 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
104 static bfd_reloc_status_type ppc_elf_std_reloc
105 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
107 static reloc_howto_type *ppc_elf_reloc_type_lookup
108 PARAMS ((bfd *abfd, bfd_reloc_code_real_type code));
109 static void ppc_elf_info_to_howto
110 PARAMS ((bfd *abfd, arelent *cache_ptr, Elf32_Internal_Rela *dst));
111 static void ppc_elf_howto_init PARAMS ((void));
112 static boolean ppc_elf_set_private_flags PARAMS ((bfd *, flagword));
113 static boolean ppc_elf_copy_private_bfd_data PARAMS ((bfd *, bfd *));
114 static boolean ppc_elf_merge_private_bfd_data PARAMS ((bfd *, bfd *));
116 static boolean ppc_elf_check_relocs PARAMS ((bfd *,
117 struct bfd_link_info *,
119 const Elf_Internal_Rela *));
121 static boolean ppc_elf_adjust_dynamic_symbol PARAMS ((struct bfd_link_info *,
122 struct elf_link_hash_entry *));
124 static boolean ppc_elf_adjust_dynindx PARAMS ((struct elf_link_hash_entry *, PTR));
126 static boolean ppc_elf_size_dynamic_sections PARAMS ((bfd *, struct bfd_link_info *));
128 static boolean ppc_elf_relocate_section PARAMS ((bfd *,
129 struct bfd_link_info *info,
133 Elf_Internal_Rela *relocs,
134 Elf_Internal_Sym *local_syms,
137 static boolean ppc_elf_finish_dynamic_symbol PARAMS ((bfd *,
138 struct bfd_link_info *,
139 struct elf_link_hash_entry *,
140 Elf_Internal_Sym *));
142 static boolean ppc_elf_finish_dynamic_sections PARAMS ((bfd *, struct bfd_link_info *));
144 #define BRANCH_PREDICT_BIT 0x200000
146 /* The name of the dynamic interpreter. This is put in the .interp
149 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
152 static reloc_howto_type *ppc_elf_howto_table[ (int)R_PPC_max ];
154 static reloc_howto_type ppc_elf_howto_raw[] =
156 /* This reloc does nothing. */
157 HOWTO (R_PPC_NONE, /* type */
159 2, /* size (0 = byte, 1 = short, 2 = long) */
161 false, /* pc_relative */
163 complain_overflow_bitfield, /* complain_on_overflow */
164 ppc_elf_std_reloc, /* special_function */
165 "R_PPC_NONE", /* name */
166 false, /* partial_inplace */
169 false), /* pcrel_offset */
171 /* A standard 32 bit relocation. */
172 HOWTO (R_PPC_ADDR32, /* type */
174 2, /* size (0 = byte, 1 = short, 2 = long) */
176 false, /* pc_relative */
178 complain_overflow_bitfield, /* complain_on_overflow */
179 ppc_elf_std_reloc, /* special_function */
180 "R_PPC_ADDR32", /* name */
181 false, /* partial_inplace */
183 0xffffffff, /* dst_mask */
184 false), /* pcrel_offset */
186 /* An absolute 26 bit branch; the lower two bits must be zero.
187 FIXME: we don't check that, we just clear them. */
188 HOWTO (R_PPC_ADDR24, /* type */
190 2, /* size (0 = byte, 1 = short, 2 = long) */
192 false, /* pc_relative */
194 complain_overflow_bitfield, /* complain_on_overflow */
195 ppc_elf_std_reloc, /* special_function */
196 "R_PPC_ADDR24", /* name */
197 false, /* partial_inplace */
199 0x3fffffc, /* dst_mask */
200 false), /* pcrel_offset */
202 /* A standard 16 bit relocation. */
203 HOWTO (R_PPC_ADDR16, /* type */
205 1, /* size (0 = byte, 1 = short, 2 = long) */
207 false, /* pc_relative */
209 complain_overflow_bitfield, /* complain_on_overflow */
210 ppc_elf_std_reloc, /* special_function */
211 "R_PPC_ADDR16", /* name */
212 false, /* partial_inplace */
214 0xffff, /* dst_mask */
215 false), /* pcrel_offset */
217 /* A 16 bit relocation without overflow. */
218 HOWTO (R_PPC_ADDR16_LO, /* type */
220 1, /* size (0 = byte, 1 = short, 2 = long) */
222 false, /* pc_relative */
224 complain_overflow_dont,/* complain_on_overflow */
225 ppc_elf_std_reloc, /* special_function */
226 "R_PPC_ADDR16_LO", /* name */
227 false, /* partial_inplace */
229 0xffff, /* dst_mask */
230 false), /* pcrel_offset */
232 /* The high order 16 bits of an address. */
233 HOWTO (R_PPC_ADDR16_HI, /* type */
235 1, /* size (0 = byte, 1 = short, 2 = long) */
237 false, /* pc_relative */
239 complain_overflow_dont, /* complain_on_overflow */
240 ppc_elf_std_reloc, /* special_function */
241 "R_PPC_ADDR16_HI", /* name */
242 false, /* partial_inplace */
244 0xffff, /* dst_mask */
245 false), /* pcrel_offset */
247 /* The high order 16 bits of an address, plus 1 if the contents of
248 the low 16 bits, treated as a signed number, is negative. */
249 HOWTO (R_PPC_ADDR16_HA, /* type */
251 1, /* size (0 = byte, 1 = short, 2 = long) */
253 false, /* pc_relative */
255 complain_overflow_dont, /* complain_on_overflow */
256 bfd_elf_generic_reloc, /* special_function */
257 "R_PPC_ADDR16_HA", /* name */
258 false, /* partial_inplace */
260 0xffff, /* dst_mask */
261 false), /* pcrel_offset */
263 /* An absolute 16 bit branch; the lower two bits must be zero.
264 FIXME: we don't check that, we just clear them. */
265 HOWTO (R_PPC_ADDR14, /* type */
267 2, /* size (0 = byte, 1 = short, 2 = long) */
269 false, /* pc_relative */
271 complain_overflow_bitfield, /* complain_on_overflow */
272 ppc_elf_std_reloc, /* special_function */
273 "R_PPC_ADDR14", /* name */
274 false, /* partial_inplace */
276 0xfffc, /* dst_mask */
277 false), /* pcrel_offset */
279 /* An absolute 16 bit branch, for which bit 10 should be set to
280 indicate that the branch is expected to be taken. The lower two
281 bits must be zero. */
282 HOWTO (R_PPC_ADDR14_BRTAKEN, /* type */
284 2, /* size (0 = byte, 1 = short, 2 = long) */
286 false, /* pc_relative */
288 complain_overflow_bitfield, /* complain_on_overflow */
289 bfd_elf_generic_reloc, /* special_function */
290 "R_PPC_ADDR14_BRTAKEN",/* name */
291 false, /* partial_inplace */
293 0xfffc, /* dst_mask */
294 false), /* pcrel_offset */
296 /* An absolute 16 bit branch, for which bit 10 should be set to
297 indicate that the branch is not expected to be taken. The lower
298 two bits must be zero. */
299 HOWTO (R_PPC_ADDR14_BRNTAKEN, /* type */
301 2, /* size (0 = byte, 1 = short, 2 = long) */
303 false, /* pc_relative */
305 complain_overflow_bitfield, /* complain_on_overflow */
306 bfd_elf_generic_reloc, /* special_function */
307 "R_PPC_ADDR14_BRNTAKEN",/* name */
308 false, /* partial_inplace */
310 0xfffc, /* dst_mask */
311 false), /* pcrel_offset */
313 /* A relative 26 bit branch; the lower two bits must be zero. */
314 HOWTO (R_PPC_REL24, /* type */
316 2, /* size (0 = byte, 1 = short, 2 = long) */
318 true, /* pc_relative */
320 complain_overflow_signed, /* complain_on_overflow */
321 ppc_elf_std_reloc, /* special_function */
322 "R_PPC_REL24", /* name */
323 false, /* partial_inplace */
325 0x3fffffc, /* dst_mask */
326 true), /* pcrel_offset */
328 /* A relative 16 bit branch; the lower two bits must be zero. */
329 HOWTO (R_PPC_REL14, /* type */
331 2, /* size (0 = byte, 1 = short, 2 = long) */
333 true, /* pc_relative */
335 complain_overflow_signed, /* complain_on_overflow */
336 ppc_elf_std_reloc, /* special_function */
337 "R_PPC_REL14", /* name */
338 false, /* partial_inplace */
340 0xfffc, /* dst_mask */
341 true), /* pcrel_offset */
343 /* A relative 16 bit branch. Bit 10 should be set to indicate that
344 the branch is expected to be taken. The lower two bits must be
346 HOWTO (R_PPC_REL14_BRTAKEN, /* type */
348 2, /* size (0 = byte, 1 = short, 2 = long) */
350 true, /* pc_relative */
352 complain_overflow_signed, /* complain_on_overflow */
353 bfd_elf_generic_reloc, /* special_function */
354 "R_PPC_REL14_BRTAKEN", /* name */
355 false, /* partial_inplace */
357 0xfffc, /* dst_mask */
358 true), /* pcrel_offset */
360 /* A relative 16 bit branch. Bit 10 should be set to indicate that
361 the branch is not expected to be taken. The lower two bits must
363 HOWTO (R_PPC_REL14_BRNTAKEN, /* type */
365 2, /* size (0 = byte, 1 = short, 2 = long) */
367 true, /* pc_relative */
369 complain_overflow_signed, /* complain_on_overflow */
370 bfd_elf_generic_reloc, /* special_function */
371 "R_PPC_REL14_BRNTAKEN",/* name */
372 false, /* partial_inplace */
374 0xfffc, /* dst_mask */
375 true), /* pcrel_offset */
377 /* Like R_PPC_ADDR16, but referring to the GOT table entry for the
379 HOWTO (R_PPC_GOT16, /* type */
381 1, /* size (0 = byte, 1 = short, 2 = long) */
383 false, /* pc_relative */
385 complain_overflow_signed, /* complain_on_overflow */
386 bfd_elf_generic_reloc, /* special_function */
387 "R_PPC_GOT16", /* name */
388 false, /* partial_inplace */
390 0xffff, /* dst_mask */
391 false), /* pcrel_offset */
393 /* Like R_PPC_ADDR16_LO, but referring to the GOT table entry for
395 HOWTO (R_PPC_GOT16_LO, /* type */
397 1, /* size (0 = byte, 1 = short, 2 = long) */
399 false, /* pc_relative */
401 complain_overflow_bitfield, /* complain_on_overflow */
402 bfd_elf_generic_reloc, /* special_function */
403 "R_PPC_GOT16_LO", /* name */
404 false, /* partial_inplace */
406 0xffff, /* dst_mask */
407 false), /* pcrel_offset */
409 /* Like R_PPC_ADDR16_HI, but referring to the GOT table entry for
411 HOWTO (R_PPC_GOT16_HI, /* type */
413 1, /* size (0 = byte, 1 = short, 2 = long) */
415 false, /* pc_relative */
417 complain_overflow_bitfield, /* complain_on_overflow */
418 bfd_elf_generic_reloc, /* special_function */
419 "R_PPC_GOT16_HI", /* name */
420 false, /* partial_inplace */
422 0xffff, /* dst_mask */
423 false), /* pcrel_offset */
425 /* Like R_PPC_ADDR16_HA, but referring to the GOT table entry for
426 the symbol. FIXME: Not supported. */
427 HOWTO (R_PPC_GOT16_HA, /* type */
429 1, /* size (0 = byte, 1 = short, 2 = long) */
431 false, /* pc_relative */
433 complain_overflow_bitfield, /* complain_on_overflow */
434 ppc_elf_unsupported_reloc, /* special_function */
435 "R_PPC_GOT16_HA", /* name */
436 false, /* partial_inplace */
438 0xffff, /* dst_mask */
439 false), /* pcrel_offset */
441 /* Like R_PPC_REL24, but referring to the procedure linkage table
442 entry for the symbol. FIXME: Not supported. */
443 HOWTO (R_PPC_PLTREL24, /* type */
445 2, /* size (0 = byte, 1 = short, 2 = long) */
447 true, /* pc_relative */
449 complain_overflow_signed, /* complain_on_overflow */
450 ppc_elf_unsupported_reloc, /* special_function */
451 "R_PPC_PLTREL24", /* name */
452 false, /* partial_inplace */
454 0x3fffffc, /* dst_mask */
455 true), /* pcrel_offset */
457 /* This is used only by the dynamic linker. The symbol should exist
458 both in the object being run and in some shared library. The
459 dynamic linker copies the data addressed by the symbol from the
460 shared library into the object. I have no idea what the purpose
462 HOWTO (R_PPC_COPY, /* type */
464 2, /* size (0 = byte, 1 = short, 2 = long) */
466 false, /* pc_relative */
468 complain_overflow_bitfield, /* complain_on_overflow */
469 ppc_elf_unsupported_reloc, /* special_function */
470 "R_PPC_COPY", /* name */
471 false, /* partial_inplace */
474 false), /* pcrel_offset */
476 /* Like R_PPC_ADDR32, but used when setting global offset table
478 HOWTO (R_PPC_GLOB_DAT, /* type */
480 2, /* size (0 = byte, 1 = short, 2 = long) */
482 false, /* pc_relative */
484 complain_overflow_bitfield, /* complain_on_overflow */
485 ppc_elf_unsupported_reloc, /* special_function */
486 "R_PPC_GLOB_DAT", /* name */
487 false, /* partial_inplace */
489 0xffffffff, /* dst_mask */
490 false), /* pcrel_offset */
492 /* Marks a procedure linkage table entry for a symbol. */
493 HOWTO (R_PPC_JMP_SLOT, /* type */
495 2, /* size (0 = byte, 1 = short, 2 = long) */
497 false, /* pc_relative */
499 complain_overflow_bitfield, /* complain_on_overflow */
500 ppc_elf_unsupported_reloc, /* special_function */
501 "R_PPC_JMP_SLOT", /* name */
502 false, /* partial_inplace */
505 false), /* pcrel_offset */
507 /* Used only by the dynamic linker. When the object is run, this
508 longword is set to the load address of the object, plus the
510 HOWTO (R_PPC_RELATIVE, /* type */
512 2, /* size (0 = byte, 1 = short, 2 = long) */
514 false, /* pc_relative */
516 complain_overflow_bitfield, /* complain_on_overflow */
517 ppc_elf_unsupported_reloc, /* special_function */
518 "R_PPC_RELATIVE", /* name */
519 false, /* partial_inplace */
521 0xffffffff, /* dst_mask */
522 false), /* pcrel_offset */
524 /* Like R_PPC_REL24, but uses the value of the symbol within the
525 object rather than the final value. Normally used for
526 _GLOBAL_OFFSET_TABLE_. FIXME: Not supported. */
527 HOWTO (R_PPC_LOCAL24PC, /* type */
529 2, /* size (0 = byte, 1 = short, 2 = long) */
531 true, /* pc_relative */
533 complain_overflow_signed, /* complain_on_overflow */
534 ppc_elf_unsupported_reloc, /* special_function */
535 "R_PPC_LOCAL24PC", /* name */
536 false, /* partial_inplace */
538 0x3fffffc, /* dst_mask */
539 true), /* pcrel_offset */
541 /* Like R_PPC_ADDR32, but may be unaligned. */
542 HOWTO (R_PPC_UADDR32, /* type */
544 2, /* size (0 = byte, 1 = short, 2 = long) */
546 false, /* pc_relative */
548 complain_overflow_bitfield, /* complain_on_overflow */
549 ppc_elf_std_reloc, /* special_function */
550 "R_PPC_UADDR32", /* name */
551 false, /* partial_inplace */
553 0xffffffff, /* dst_mask */
554 false), /* pcrel_offset */
556 /* Like R_PPC_ADDR16, but may be unaligned. */
557 HOWTO (R_PPC_UADDR16, /* type */
559 1, /* size (0 = byte, 1 = short, 2 = long) */
561 false, /* pc_relative */
563 complain_overflow_bitfield, /* complain_on_overflow */
564 ppc_elf_std_reloc, /* special_function */
565 "R_PPC_UADDR16", /* name */
566 false, /* partial_inplace */
568 0xffff, /* dst_mask */
569 false), /* pcrel_offset */
571 /* 32-bit PC relative */
572 HOWTO (R_PPC_REL32, /* type */
574 2, /* size (0 = byte, 1 = short, 2 = long) */
576 true, /* pc_relative */
578 complain_overflow_bitfield, /* complain_on_overflow */
579 ppc_elf_std_reloc, /* special_function */
580 "R_PPC_REL32", /* name */
581 false, /* partial_inplace */
583 0xffffffff, /* dst_mask */
584 true), /* pcrel_offset */
586 /* 32-bit relocation to the symbol's procedure linkage table.
587 FIXEME: not supported. */
588 HOWTO (R_PPC_PLT32, /* type */
590 2, /* size (0 = byte, 1 = short, 2 = long) */
592 false, /* pc_relative */
594 complain_overflow_bitfield, /* complain_on_overflow */
595 ppc_elf_unsupported_reloc, /* special_function */
596 "R_PPC_PLT32", /* name */
597 false, /* partial_inplace */
600 false), /* pcrel_offset */
602 /* 32-bit PC relative relocation to the symbol's procedure linkage table.
603 FIXEME: not supported. */
604 HOWTO (R_PPC_PLTREL32, /* type */
606 2, /* size (0 = byte, 1 = short, 2 = long) */
608 true, /* pc_relative */
610 complain_overflow_bitfield, /* complain_on_overflow */
611 ppc_elf_unsupported_reloc, /* special_function */
612 "R_PPC_PLTREL32", /* name */
613 false, /* partial_inplace */
616 true), /* pcrel_offset */
618 /* Like R_PPC_ADDR16_LO, but referring to the PLT table entry for
620 HOWTO (R_PPC_PLT16_LO, /* type */
622 1, /* size (0 = byte, 1 = short, 2 = long) */
624 false, /* pc_relative */
626 complain_overflow_bitfield, /* complain_on_overflow */
627 ppc_elf_unsupported_reloc, /* special_function */
628 "R_PPC_PLT16_LO", /* name */
629 false, /* partial_inplace */
631 0xffff, /* dst_mask */
632 false), /* pcrel_offset */
634 /* Like R_PPC_ADDR16_HI, but referring to the PLT table entry for
636 HOWTO (R_PPC_PLT16_HI, /* type */
638 1, /* size (0 = byte, 1 = short, 2 = long) */
640 false, /* pc_relative */
642 complain_overflow_bitfield, /* complain_on_overflow */
643 ppc_elf_unsupported_reloc, /* special_function */
644 "R_PPC_PLT16_HI", /* name */
645 false, /* partial_inplace */
647 0xffff, /* dst_mask */
648 false), /* pcrel_offset */
650 /* Like R_PPC_ADDR16_HA, but referring to the PLT table entry for
651 the symbol. FIXME: Not supported. */
652 HOWTO (R_PPC_PLT16_HA, /* type */
654 1, /* size (0 = byte, 1 = short, 2 = long) */
656 false, /* pc_relative */
658 complain_overflow_bitfield, /* complain_on_overflow */
659 ppc_elf_unsupported_reloc, /* special_function */
660 "R_PPC_PLT16_HA", /* name */
661 false, /* partial_inplace */
663 0xffff, /* dst_mask */
664 false), /* pcrel_offset */
666 /* A sign-extended 16 bit value relative to _SDA_BASE, for use with
668 HOWTO (R_PPC_SDAREL16, /* type */
670 1, /* size (0 = byte, 1 = short, 2 = long) */
672 false, /* pc_relative */
674 complain_overflow_signed, /* complain_on_overflow */
675 bfd_elf_generic_reloc, /* special_function */
676 "R_PPC_SDAREL16", /* name */
677 false, /* partial_inplace */
679 0xffff, /* dst_mask */
680 false), /* pcrel_offset */
682 /* These next 4 relocations were added by Sun. */
683 /* 32-bit section relative relocation. FIXME: not supported. */
684 HOWTO (R_PPC_SECTOFF, /* type */
686 2, /* size (0 = byte, 1 = short, 2 = long) */
688 true, /* pc_relative */
690 complain_overflow_bitfield, /* complain_on_overflow */
691 ppc_elf_unsupported_reloc, /* special_function */
692 "R_PPC_SECTOFF", /* name */
693 false, /* partial_inplace */
696 true), /* pcrel_offset */
698 /* 16-bit lower half section relative relocation. FIXME: not supported. */
699 HOWTO (R_PPC_SECTOFF_LO, /* type */
701 1, /* size (0 = byte, 1 = short, 2 = long) */
703 false, /* pc_relative */
705 complain_overflow_bitfield, /* complain_on_overflow */
706 ppc_elf_unsupported_reloc, /* special_function */
707 "R_PPC_SECTOFF_LO", /* name */
708 false, /* partial_inplace */
710 0xffff, /* dst_mask */
711 false), /* pcrel_offset */
713 /* 16-bit upper half section relative relocation. FIXME: not supported. */
714 HOWTO (R_PPC_SECTOFF_HI, /* type */
716 1, /* size (0 = byte, 1 = short, 2 = long) */
718 false, /* pc_relative */
720 complain_overflow_bitfield, /* complain_on_overflow */
721 ppc_elf_unsupported_reloc, /* special_function */
722 "R_PPC_SECTOFF_HI", /* name */
723 false, /* partial_inplace */
725 0xffff, /* dst_mask */
726 false), /* pcrel_offset */
728 /* 16-bit upper half adjusted section relative relocation. FIXME: not supported. */
729 HOWTO (R_PPC_SECTOFF_HA, /* type */
731 1, /* size (0 = byte, 1 = short, 2 = long) */
733 false, /* pc_relative */
735 complain_overflow_bitfield, /* complain_on_overflow */
736 ppc_elf_unsupported_reloc, /* special_function */
737 "R_PPC_SECTOFF_HA", /* name */
738 false, /* partial_inplace */
740 0xffff, /* dst_mask */
741 false), /* pcrel_offset */
743 /* The remaining relocs are from the Embedded ELF ABI, and are not
744 in the SVR4 ELF ABI. */
746 /* 32 bit value resulting from the addend minus the symbol */
747 HOWTO (R_PPC_EMB_NADDR32, /* type */
749 2, /* size (0 = byte, 1 = short, 2 = long) */
751 false, /* pc_relative */
753 complain_overflow_bitfield, /* complain_on_overflow */
754 ppc_elf_unsupported_reloc, /* special_function */
755 "R_PPC_EMB_NADDR32", /* name */
756 false, /* partial_inplace */
758 0xffffffff, /* dst_mask */
759 false), /* pcrel_offset */
761 /* 16 bit value resulting from the addend minus the symbol */
762 HOWTO (R_PPC_EMB_NADDR16, /* type */
764 1, /* size (0 = byte, 1 = short, 2 = long) */
766 false, /* pc_relative */
768 complain_overflow_bitfield, /* complain_on_overflow */
769 ppc_elf_unsupported_reloc, /* special_function */
770 "R_PPC_EMB_NADDR16", /* name */
771 false, /* partial_inplace */
773 0xffff, /* dst_mask */
774 false), /* pcrel_offset */
776 /* 16 bit value resulting from the addend minus the symbol */
777 HOWTO (R_PPC_EMB_NADDR16_LO, /* type */
779 1, /* size (0 = byte, 1 = short, 2 = long) */
781 false, /* pc_relative */
783 complain_overflow_dont,/* complain_on_overflow */
784 ppc_elf_unsupported_reloc, /* special_function */
785 "R_PPC_EMB_ADDR16_LO", /* name */
786 false, /* partial_inplace */
788 0xffff, /* dst_mask */
789 false), /* pcrel_offset */
791 /* The high order 16 bits of the addend minus the symbol */
792 HOWTO (R_PPC_EMB_NADDR16_HI, /* type */
794 1, /* size (0 = byte, 1 = short, 2 = long) */
796 false, /* pc_relative */
798 complain_overflow_dont, /* complain_on_overflow */
799 ppc_elf_unsupported_reloc, /* special_function */
800 "R_PPC_EMB_NADDR16_HI", /* name */
801 false, /* partial_inplace */
803 0xffff, /* dst_mask */
804 false), /* pcrel_offset */
806 /* The high order 16 bits of the result of the addend minus the address,
807 plus 1 if the contents of the low 16 bits, treated as a signed number,
809 HOWTO (R_PPC_EMB_NADDR16_HA, /* type */
811 1, /* size (0 = byte, 1 = short, 2 = long) */
813 false, /* pc_relative */
815 complain_overflow_dont, /* complain_on_overflow */
816 ppc_elf_unsupported_reloc, /* special_function */
817 "R_PPC_EMB_NADDR16_HA", /* name */
818 false, /* partial_inplace */
820 0xffff, /* dst_mask */
821 false), /* pcrel_offset */
823 /* Phony reloc to handle AIX style TOC entries */
824 HOWTO (R_PPC_TOC16, /* type */
826 1, /* size (0 = byte, 1 = short, 2 = long) */
828 false, /* pc_relative */
830 complain_overflow_signed, /* complain_on_overflow */
831 bfd_elf_generic_reloc, /* special_function */
832 "R_PPC_TOC16", /* name */
833 false, /* partial_inplace */
835 0xffff, /* dst_mask */
836 false), /* pcrel_offset */
840 /* Initialize the ppc_elf_howto_table, so that linear accesses can be done. */
843 ppc_elf_howto_init ()
845 unsigned int i, type;
847 for (i = 0; i < sizeof (ppc_elf_howto_raw) / sizeof (ppc_elf_howto_raw[0]); i++)
849 type = ppc_elf_howto_raw[i].type;
850 BFD_ASSERT (type < sizeof(ppc_elf_howto_table) / sizeof(ppc_elf_howto_table[0]));
851 ppc_elf_howto_table[type] = &ppc_elf_howto_raw[i];
856 static reloc_howto_type *
857 ppc_elf_reloc_type_lookup (abfd, code)
859 bfd_reloc_code_real_type code;
861 enum ppc_reloc_type ppc_reloc = R_PPC_NONE;
863 if (!ppc_elf_howto_table[ R_PPC_ADDR32 ]) /* Initialize howto table if needed */
864 ppc_elf_howto_init ();
869 return (reloc_howto_type *)NULL;
871 case BFD_RELOC_NONE: ppc_reloc = R_PPC_NONE; break;
872 case BFD_RELOC_32: ppc_reloc = R_PPC_ADDR32; break;
873 case BFD_RELOC_PPC_BA26: ppc_reloc = R_PPC_ADDR24; break;
874 case BFD_RELOC_16: ppc_reloc = R_PPC_ADDR16; break;
875 case BFD_RELOC_LO16: ppc_reloc = R_PPC_ADDR16_LO; break;
876 case BFD_RELOC_HI16: ppc_reloc = R_PPC_ADDR16_HI; break;
877 case BFD_RELOC_HI16_S: ppc_reloc = R_PPC_ADDR16_HA; break;
878 case BFD_RELOC_PPC_BA16: ppc_reloc = R_PPC_ADDR14; break;
879 case BFD_RELOC_PPC_BA16_BRTAKEN: ppc_reloc = R_PPC_ADDR14_BRTAKEN; break;
880 case BFD_RELOC_PPC_BA16_BRNTAKEN: ppc_reloc = R_PPC_ADDR14_BRNTAKEN; break;
881 case BFD_RELOC_PPC_B26: ppc_reloc = R_PPC_REL24; break;
882 case BFD_RELOC_PPC_B16: ppc_reloc = R_PPC_REL14; break;
883 case BFD_RELOC_PPC_B16_BRTAKEN: ppc_reloc = R_PPC_REL14_BRTAKEN; break;
884 case BFD_RELOC_PPC_B16_BRNTAKEN: ppc_reloc = R_PPC_REL14_BRNTAKEN; break;
885 case BFD_RELOC_16_GOTOFF: ppc_reloc = R_PPC_GOT16; break;
886 case BFD_RELOC_LO16_GOTOFF: ppc_reloc = R_PPC_GOT16_LO; break;
887 case BFD_RELOC_HI16_GOTOFF: ppc_reloc = R_PPC_GOT16_HI; break;
888 case BFD_RELOC_HI16_S_GOTOFF: ppc_reloc = R_PPC_GOT16_HA; break;
889 case BFD_RELOC_24_PLT_PCREL: ppc_reloc = R_PPC_PLTREL24; break;
890 case BFD_RELOC_PPC_COPY: ppc_reloc = R_PPC_COPY; break;
891 case BFD_RELOC_PPC_GLOB_DAT: ppc_reloc = R_PPC_GLOB_DAT; break;
892 case BFD_RELOC_PPC_LOCAL24PC: ppc_reloc = R_PPC_LOCAL24PC; break;
893 case BFD_RELOC_32_PCREL: ppc_reloc = R_PPC_REL32; break;
894 case BFD_RELOC_32_PLTOFF: ppc_reloc = R_PPC_PLT32; break;
895 case BFD_RELOC_32_PLT_PCREL: ppc_reloc = R_PPC_PLTREL32; break;
896 case BFD_RELOC_LO16_PLTOFF: ppc_reloc = R_PPC_PLT16_LO; break;
897 case BFD_RELOC_HI16_PLTOFF: ppc_reloc = R_PPC_PLT16_HI; break;
898 case BFD_RELOC_HI16_S_PLTOFF: ppc_reloc = R_PPC_PLT16_HA; break;
899 case BFD_RELOC_GPREL16: ppc_reloc = R_PPC_SDAREL16; break;
900 case BFD_RELOC_32_BASEREL: ppc_reloc = R_PPC_SECTOFF; break;
901 case BFD_RELOC_LO16_BASEREL: ppc_reloc = R_PPC_SECTOFF_LO; break;
902 case BFD_RELOC_HI16_BASEREL: ppc_reloc = R_PPC_SECTOFF_HI; break;
903 case BFD_RELOC_HI16_S_BASEREL: ppc_reloc = R_PPC_SECTOFF_HA; break;
904 case BFD_RELOC_CTOR: ppc_reloc = R_PPC_ADDR32; break;
905 case BFD_RELOC_PPC_TOC16: ppc_reloc = R_PPC_TOC16; break;
908 return ppc_elf_howto_table[ (int)ppc_reloc ];
911 /* Set the howto pointer for a PowerPC ELF reloc. */
914 ppc_elf_info_to_howto (abfd, cache_ptr, dst)
917 Elf32_Internal_Rela *dst;
919 if (!ppc_elf_howto_table[ R_PPC_ADDR32 ]) /* Initialize howto table if needed */
920 ppc_elf_howto_init ();
922 BFD_ASSERT (ELF32_R_TYPE (dst->r_info) < (unsigned int) R_PPC_max);
923 cache_ptr->howto = ppc_elf_howto_table[ELF32_R_TYPE (dst->r_info)];
926 /* Function to set whether a module needs the -mrelocatable bit set. */
929 ppc_elf_set_private_flags (abfd, flags)
933 BFD_ASSERT (!elf_flags_init (abfd)
934 || elf_elfheader (abfd)->e_flags == flags);
936 elf_elfheader (abfd)->e_flags = flags;
937 elf_flags_init (abfd) = true;
941 /* Copy backend specific data from one object module to another */
943 ppc_elf_copy_private_bfd_data (ibfd, obfd)
947 /* This function is selected based on the input vector. We only
948 want to copy information over if the output BFD also uses Elf
950 if (bfd_get_flavour (obfd) != bfd_target_elf_flavour)
953 BFD_ASSERT (!elf_flags_init (obfd)
954 || elf_elfheader (obfd)->e_flags == elf_elfheader (ibfd)->e_flags);
956 elf_elfheader (obfd)->e_flags = elf_elfheader (ibfd)->e_flags;
957 elf_flags_init (obfd) = true;
961 /* Merge backend specific data from an object file to the output
962 object file when linking */
964 ppc_elf_merge_private_bfd_data (ibfd, obfd)
972 /* Check if we have the same endianess */
973 if (ibfd->xvec->byteorder != obfd->xvec->byteorder
974 && obfd->xvec->byteorder != BFD_ENDIAN_UNKNOWN)
976 (*_bfd_error_handler)
977 ("%s: compiled for a %s endian system and target is %s endian",
978 bfd_get_filename (ibfd),
979 bfd_big_endian (ibfd) ? "big" : "little",
980 bfd_big_endian (obfd) ? "big" : "little");
982 bfd_set_error (bfd_error_wrong_format);
986 /* This function is selected based on the input vector. We only
987 want to copy information over if the output BFD also uses Elf
989 if (bfd_get_flavour (obfd) != bfd_target_elf_flavour)
992 new_flags = elf_elfheader (ibfd)->e_flags;
993 old_flags = elf_elfheader (obfd)->e_flags;
994 if (!elf_flags_init (obfd)) /* First call, no flags set */
996 elf_flags_init (obfd) = true;
997 elf_elfheader (obfd)->e_flags = new_flags;
1000 else if (new_flags == old_flags) /* Compatible flags are ok */
1003 else /* Incompatible flags */
1005 /* Warn about -mrelocatable mismatch. Allow -mrelocatable-lib to be linked
1008 if ((new_flags & EF_PPC_RELOCATABLE) != 0
1009 && (old_flags & (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB)) == 0)
1012 (*_bfd_error_handler)
1013 ("%s: compiled with -mrelocatable and linked with modules compiled normally",
1014 bfd_get_filename (ibfd));
1016 else if ((new_flags & (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB)) == 0
1017 && (old_flags & EF_PPC_RELOCATABLE) != 0)
1020 (*_bfd_error_handler)
1021 ("%s: compiled normally and linked with modules compiled with -mrelocatable",
1022 bfd_get_filename (ibfd));
1024 else if ((new_flags & EF_PPC_RELOCATABLE_LIB) != 0)
1025 elf_elfheader (obfd)->e_flags |= EF_PPC_RELOCATABLE_LIB;
1027 new_flags &= ~ (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB);
1028 old_flags &= ~ (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB);
1030 /* Warn about eabi vs. V.4 mismatch */
1031 if ((new_flags & EF_PPC_EMB) != 0 && (old_flags & EF_PPC_EMB) == 0)
1033 new_flags &= ~EF_PPC_EMB;
1035 (*_bfd_error_handler)
1036 ("%s: compiled for the eabi and linked with modules compiled for System V",
1037 bfd_get_filename (ibfd));
1039 else if ((new_flags & EF_PPC_EMB) == 0 && (old_flags & EF_PPC_EMB) != 0)
1041 old_flags &= ~EF_PPC_EMB;
1043 (*_bfd_error_handler)
1044 ("%s: compiled for System V and linked with modules compiled for eabi",
1045 bfd_get_filename (ibfd));
1048 /* Warn about any other mismatches */
1049 if (new_flags != old_flags)
1052 (*_bfd_error_handler)
1053 ("%s: uses different e_flags (0x%lx) fields than previous modules (0x%lx)",
1054 bfd_get_filename (ibfd), (long)new_flags, (long)old_flags);
1059 bfd_set_error (bfd_error_bad_value);
1068 /* ELF relocs are against symbols. If we are producing relocateable
1069 output, and the reloc is against an external symbol, and nothing
1070 has given us any additional addend, the resulting reloc will also
1071 be against the same symbol. In such a case, we don't want to
1072 change anything about the way the reloc is handled, since it will
1073 all be done at final link time. Rather than put special case code
1074 into bfd_perform_relocation, all the reloc types use this howto
1075 function. It just short circuits the reloc if producing
1076 relocateable output against an external symbol. */
1079 static bfd_reloc_status_type
1080 ppc_elf_std_reloc (abfd,
1088 arelent *reloc_entry;
1091 asection *input_section;
1093 char **error_message;
1095 if (output_bfd != (bfd *) NULL
1096 && (symbol->flags & BSF_SECTION_SYM) == 0
1097 && (! reloc_entry->howto->partial_inplace || reloc_entry->addend == 0))
1099 reloc_entry->address += input_section->output_offset;
1100 return bfd_reloc_ok;
1103 return bfd_reloc_continue;
1106 /* Don't pretend we can deal with unsupported relocs. */
1109 static bfd_reloc_status_type
1110 ppc_elf_unsupported_reloc (abfd, reloc_entry, symbol, data, input_section,
1111 output_bfd, error_message)
1113 arelent *reloc_entry;
1116 asection *input_section;
1118 char **error_message;
1120 BFD_ASSERT (reloc_entry->howto != (reloc_howto_type *)0);
1121 (*_bfd_error_handler)
1122 ("%s: relocation %s (%d) is not currently supported",
1123 bfd_get_filename (abfd),
1124 reloc_entry->howto->name,
1125 reloc_entry->howto->type);
1127 return bfd_reloc_notsupported;
1131 /* Adjust a symbol defined by a dynamic object and referenced by a
1132 regular object. The current definition is in some section of the
1133 dynamic object, but we're not including those sections. We have to
1134 change the definition to something the rest of the link can
1138 ppc_elf_adjust_dynamic_symbol (info, h)
1139 struct bfd_link_info *info;
1140 struct elf_link_hash_entry *h;
1143 fprintf (stderr, "ppc_elf_adjust_dynamic_symbol called\n");
1149 /* Increment the index of a dynamic symbol by a given amount. Called
1150 via elf_link_hash_traverse. */
1153 ppc_elf_adjust_dynindx (h, cparg)
1154 struct elf_link_hash_entry *h;
1157 int *cp = (int *) cparg;
1160 fprintf (stderr, "ppc_elf_adjust_dynindx called, h->dynindx = %d, *cp = %d\n", h->dynindx, *cp);
1163 if (h->dynindx != -1)
1170 /* Set the sizes of the dynamic sections. */
1173 ppc_elf_size_dynamic_sections (output_bfd, info)
1175 struct bfd_link_info *info;
1183 fprintf (stderr, "ppc_elf_size_dynamic_sections called\n");
1186 dynobj = elf_hash_table (info)->dynobj;
1187 BFD_ASSERT (dynobj != NULL);
1189 if (elf_hash_table (info)->dynamic_sections_created)
1191 /* Set the contents of the .interp section to the interpreter. */
1194 s = bfd_get_section_by_name (dynobj, ".interp");
1195 BFD_ASSERT (s != NULL);
1196 s->_raw_size = sizeof ELF_DYNAMIC_INTERPRETER;
1197 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
1200 /* Make space for the trailing nop in .plt. */
1201 s = bfd_get_section_by_name (dynobj, ".plt");
1202 BFD_ASSERT (s != NULL);
1203 if (s->_raw_size > 0)
1208 /* We may have created entries in the .rela.got section.
1209 However, if we are not creating the dynamic sections, we will
1210 not actually use these entries. Reset the size of .rela.got,
1211 which will cause it to get stripped from the output file
1213 s = bfd_get_section_by_name (dynobj, ".rela.got");
1218 /* The check_relocs and adjust_dynamic_symbol entry points have
1219 determined the sizes of the various dynamic sections. Allocate
1223 for (s = dynobj->sections; s != NULL; s = s->next)
1228 if ((s->flags & SEC_IN_MEMORY) == 0)
1231 /* It's OK to base decisions on the section name, because none
1232 of the dynobj section names depend upon the input files. */
1233 name = bfd_get_section_name (dynobj, s);
1237 if (strncmp (name, ".rela", 5) == 0)
1239 if (s->_raw_size == 0)
1241 /* If we don't need this section, strip it from the
1242 output file. This is to handle .rela.bss and
1243 .rel.plt. We must create it in
1244 create_dynamic_sections, because it must be created
1245 before the linker maps input sections to output
1246 sections. The linker does that before
1247 adjust_dynamic_symbol is called, and it is that
1248 function which decides whether anything needs to go
1249 into these sections. */
1256 /* If this relocation section applies to a read only
1257 section, then we probably need a DT_TEXTREL entry. */
1258 target = bfd_get_section_by_name (output_bfd, name + 5);
1260 && (target->flags & SEC_READONLY) != 0)
1263 if (strcmp (name, ".rela.plt") == 0)
1266 /* We use the reloc_count field as a counter if we need
1267 to copy relocs into the output file. */
1271 else if (strcmp (name, ".plt") != 0
1272 && strcmp (name, ".got") != 0)
1274 /* It's not one of our sections, so don't allocate space. */
1282 for (spp = &s->output_section->owner->sections;
1283 *spp != s->output_section;
1284 spp = &(*spp)->next)
1286 *spp = s->output_section->next;
1287 --s->output_section->owner->section_count;
1292 /* Allocate memory for the section contents. */
1293 s->contents = (bfd_byte *) bfd_alloc (dynobj, s->_raw_size);
1294 if (s->contents == NULL && s->_raw_size != 0)
1298 if (elf_hash_table (info)->dynamic_sections_created)
1300 /* Add some entries to the .dynamic section. We fill in the
1301 values later, in ppc_elf_finish_dynamic_sections, but we
1302 must add the entries now so that we get the correct size for
1303 the .dynamic section. The DT_DEBUG entry is filled in by the
1304 dynamic linker and used by the debugger. */
1307 if (! bfd_elf32_add_dynamic_entry (info, DT_DEBUG, 0))
1311 if (! bfd_elf32_add_dynamic_entry (info, DT_PLTGOT, 0))
1316 if (! bfd_elf32_add_dynamic_entry (info, DT_PLTRELSZ, 0)
1317 || ! bfd_elf32_add_dynamic_entry (info, DT_PLTREL, DT_RELA)
1318 || ! bfd_elf32_add_dynamic_entry (info, DT_JMPREL, 0))
1322 if (! bfd_elf32_add_dynamic_entry (info, DT_RELA, 0)
1323 || ! bfd_elf32_add_dynamic_entry (info, DT_RELASZ, 0)
1324 || ! bfd_elf32_add_dynamic_entry (info, DT_RELAENT,
1325 sizeof (Elf32_External_Rela)))
1330 if (! bfd_elf32_add_dynamic_entry (info, DT_TEXTREL, 0))
1335 /* If we are generating a shared library, we generate a section
1336 symbol for each output section. These are local symbols, which
1337 means that they must come first in the dynamic symbol table.
1338 That means we must increment the dynamic symbol index of every
1339 other dynamic symbol. */
1344 c = bfd_count_sections (output_bfd);
1345 elf_link_hash_traverse (elf_hash_table (info),
1346 ppc_elf_adjust_dynindx,
1348 elf_hash_table (info)->dynsymcount += c;
1350 for (i = 1, s = output_bfd->sections; s != NULL; s = s->next, i++)
1352 elf_section_data (s)->dynindx = i;
1353 /* These symbols will have no names, so we don't need to
1354 fiddle with dynstr_index. */
1362 /* Look through the relocs for a section during the first phase, and
1363 allocate space in the global offset table or procedure linkage
1367 ppc_elf_check_relocs (abfd, info, sec, relocs)
1369 struct bfd_link_info *info;
1371 const Elf_Internal_Rela *relocs;
1374 Elf_Internal_Shdr *symtab_hdr;
1375 struct elf_link_hash_entry **sym_hashes;
1376 bfd_vma *local_got_offsets;
1377 const Elf_Internal_Rela *rel;
1378 const Elf_Internal_Rela *rel_end;
1383 if (info->relocateable)
1387 fprintf (stderr, "ppc_elf_check_relocs called for section %s\n", sec->name);
1390 dynobj = elf_hash_table (info)->dynobj;
1391 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
1392 sym_hashes = elf_sym_hashes (abfd);
1393 local_got_offsets = elf_local_got_offsets (abfd);
1399 rel_end = relocs + sec->reloc_count;
1400 for (rel = relocs; rel < rel_end; rel++)
1402 unsigned long r_symndx;
1403 struct elf_link_hash_entry *h;
1405 r_symndx = ELF32_R_SYM (rel->r_info);
1406 if (r_symndx < symtab_hdr->sh_info)
1409 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
1411 switch (ELF32_R_TYPE (rel->r_info))
1414 case R_PPC_GOT16_LO:
1415 case R_PPC_GOT16_HI:
1416 case R_PPC_GOT16_HA:
1418 fprintf (stderr, "Reloc requires a GOT entry\n");
1420 /* This symbol requires a global offset table entry. */
1424 /* Create the .got section. */
1425 elf_hash_table (info)->dynobj = dynobj = abfd;
1426 if (! _bfd_elf_create_got_section (dynobj, info))
1432 sgot = bfd_get_section_by_name (dynobj, ".got");
1433 BFD_ASSERT (sgot != NULL);
1437 && (h != NULL || info->shared))
1439 srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
1440 if (srelgot == NULL)
1442 srelgot = bfd_make_section (dynobj, ".rela.got");
1444 || ! bfd_set_section_flags (dynobj, srelgot,
1450 || ! bfd_set_section_alignment (dynobj, srelgot, 2))
1457 if (h->got_offset != (bfd_vma) -1)
1459 /* We have already allocated space in the .got. */
1462 h->got_offset = sgot->_raw_size;
1464 /* Make sure this symbol is output as a dynamic symbol. */
1465 if (h->dynindx == -1)
1467 if (! bfd_elf32_link_record_dynamic_symbol (info, h))
1471 srelgot->_raw_size += sizeof (Elf32_External_Rela);
1475 /* This is a global offset table entry for a local
1477 if (local_got_offsets == NULL)
1480 register unsigned int i;
1482 size = symtab_hdr->sh_info * sizeof (bfd_vma);
1483 local_got_offsets = (bfd_vma *) bfd_alloc (abfd, size);
1484 if (local_got_offsets == NULL)
1486 elf_local_got_offsets (abfd) = local_got_offsets;
1487 for (i = 0; i < symtab_hdr->sh_info; i++)
1488 local_got_offsets[i] = (bfd_vma) -1;
1490 if (local_got_offsets[r_symndx] != (bfd_vma) -1)
1492 /* We have already allocated space in the .got. */
1495 local_got_offsets[r_symndx] = sgot->_raw_size;
1499 /* If we are generating a shared object, we need to
1500 output a R_PPC_RELATIVE reloc so that the
1501 dynamic linker can adjust this GOT entry. */
1502 srelgot->_raw_size += sizeof (Elf32_External_Rela);
1506 sgot->_raw_size += 4;
1511 case R_PPC_PLTREL24:
1512 case R_PPC_PLT16_LO:
1513 case R_PPC_PLT16_HI:
1514 case R_PPC_PLT16_HA:
1516 fprintf (stderr, "Reloc requires a PLT entry\n");
1518 /* This symbol requires a procedure linkage table entry. We
1519 actually build the entry in adjust_dynamic_symbol,
1520 because this might be a case of linking PIC code without
1521 linking in any dynamic objects, in which case we don't
1522 need to generate a procedure linkage table after all. */
1526 /* It does not make sense to have a procedure linkage
1527 table entry for a local symbol. */
1528 bfd_set_error (bfd_error_bad_value);
1532 /* Make sure this symbol is output as a dynamic symbol. */
1533 if (h->dynindx == -1)
1535 if (! bfd_elf32_link_record_dynamic_symbol (info, h))
1539 h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
1546 && strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
1550 case R_SPARC_DISP16:
1551 case R_SPARC_DISP32:
1552 case R_SPARC_WDISP30:
1553 case R_SPARC_WDISP22:
1566 && (sec->flags & SEC_ALLOC) != 0)
1568 /* When creating a shared object, we must copy these
1569 relocs into the output file. We create a reloc
1570 section in dynobj and make room for the reloc. */
1575 name = (bfd_elf_string_from_elf_section
1577 elf_elfheader (abfd)->e_shstrndx,
1578 elf_section_data (sec)->rel_hdr.sh_name));
1582 BFD_ASSERT (strncmp (name, ".rela", 5) == 0
1583 && strcmp (bfd_get_section_name (abfd, sec),
1586 sreloc = bfd_get_section_by_name (dynobj, name);
1589 sreloc = bfd_make_section (dynobj, name);
1591 || ! bfd_set_section_flags (dynobj, sreloc,
1597 || ! bfd_set_section_alignment (dynobj, sreloc, 2))
1602 sreloc->_raw_size += sizeof (Elf32_External_Rela);
1617 /* Finish up dynamic symbol handling. We set the contents of various
1618 dynamic sections here. */
1621 ppc_elf_finish_dynamic_symbol (output_bfd, info, h, sym)
1623 struct bfd_link_info *info;
1624 struct elf_link_hash_entry *h;
1625 Elf_Internal_Sym *sym;
1630 fprintf (stderr, "ppc_elf_finish_dynamic_symbol called\n");
1633 dynobj = elf_hash_table (info)->dynobj;
1635 if (h->plt_offset != (bfd_vma) -1)
1639 Elf_Internal_Rela rela;
1641 /* This symbol has an entry in the procedure linkage table. Set
1644 BFD_ASSERT (h->dynindx != -1);
1646 splt = bfd_get_section_by_name (dynobj, ".plt");
1647 srela = bfd_get_section_by_name (dynobj, ".rela.plt");
1648 BFD_ASSERT (splt != NULL && srela != NULL);
1650 /* Fill in the entry in the procedure linkage table. */
1652 bfd_put_32 (output_bfd,
1653 PLT_ENTRY_WORD0 + h->plt_offset,
1654 splt->contents + h->plt_offset);
1655 bfd_put_32 (output_bfd,
1657 + (((- (h->plt_offset + 4)) >> 2) & 0x3fffff)),
1658 splt->contents + h->plt_offset + 4);
1659 bfd_put_32 (output_bfd, PLT_ENTRY_WORD2,
1660 splt->contents + h->plt_offset + 8);
1662 /* Fill in the entry in the .rela.plt section. */
1663 rela.r_offset = (splt->output_section->vma
1664 + splt->output_offset
1666 rela.r_info = ELF32_R_INFO (h->dynindx, R_SPARC_JMP_SLOT);
1668 bfd_elf32_swap_reloca_out (output_bfd, &rela,
1669 ((Elf32_External_Rela *) srela->contents
1670 + h->plt_offset / PLT_ENTRY_SIZE - 4));
1673 if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
1675 /* Mark the symbol as undefined, rather than as defined in
1676 the .plt section. Leave the value alone. */
1677 sym->st_shndx = SHN_UNDEF;
1681 if (h->got_offset != (bfd_vma) -1)
1685 Elf_Internal_Rela rela;
1687 /* This symbol has an entry in the global offset table. Set it
1690 BFD_ASSERT (h->dynindx != -1);
1692 sgot = bfd_get_section_by_name (dynobj, ".got");
1693 srela = bfd_get_section_by_name (dynobj, ".rela.got");
1694 BFD_ASSERT (sgot != NULL && srela != NULL);
1696 rela.r_offset = (sgot->output_section->vma
1697 + sgot->output_offset
1698 + (h->got_offset &~ 1));
1700 /* If this is a -Bsymbolic link, and the symbol is defined
1701 locally, we just want to emit a RELATIVE reloc. The entry in
1702 the global offset table will already have been initialized in
1703 the relocate_section function. */
1706 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR))
1707 rela.r_info = ELF32_R_INFO (0, R_PPC_RELATIVE);
1710 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + h->got_offset);
1711 rela.r_info = ELF32_R_INFO (h->dynindx, R_PPC_GLOB_DAT);
1715 bfd_elf32_swap_reloca_out (output_bfd, &rela,
1716 ((Elf32_External_Rela *) srela->contents
1717 + srela->reloc_count));
1718 ++srela->reloc_count;
1721 if ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_COPY) != 0)
1724 Elf_Internal_Rela rela;
1726 /* This symbols needs a copy reloc. Set it up. */
1728 BFD_ASSERT (h->dynindx != -1);
1730 s = bfd_get_section_by_name (h->root.u.def.section->owner,
1732 BFD_ASSERT (s != NULL);
1734 rela.r_offset = (h->root.u.def.value
1735 + h->root.u.def.section->output_section->vma
1736 + h->root.u.def.section->output_offset);
1737 rela.r_info = ELF32_R_INFO (h->dynindx, R_PPC_COPY);
1739 bfd_elf32_swap_reloca_out (output_bfd, &rela,
1740 ((Elf32_External_Rela *) s->contents
1745 /* Mark some specially defined symbols as absolute. */
1746 if (strcmp (h->root.root.string, "_DYNAMIC") == 0
1747 || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0
1748 || strcmp (h->root.root.string, "_PROCEDURE_LINKAGE_TABLE_") == 0)
1749 sym->st_shndx = SHN_ABS;
1755 /* Finish up the dynamic sections. */
1758 ppc_elf_finish_dynamic_sections (output_bfd, info)
1760 struct bfd_link_info *info;
1767 fprintf (stderr, "ppc_elf_finish_dynamic_sections called\n");
1770 dynobj = elf_hash_table (info)->dynobj;
1772 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
1774 if (elf_hash_table (info)->dynamic_sections_created)
1777 Elf32_External_Dyn *dyncon, *dynconend;
1779 splt = bfd_get_section_by_name (dynobj, ".plt");
1780 BFD_ASSERT (splt != NULL && sdyn != NULL);
1782 dyncon = (Elf32_External_Dyn *) sdyn->contents;
1783 dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->_raw_size);
1784 for (; dyncon < dynconend; dyncon++)
1786 Elf_Internal_Dyn dyn;
1790 bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
1794 case DT_PLTGOT: name = ".plt"; size = false; break;
1795 case DT_PLTRELSZ: name = ".rela.plt"; size = true; break;
1796 case DT_JMPREL: name = ".rela.plt"; size = false; break;
1797 default: name = NULL; size = false; break;
1804 s = bfd_get_section_by_name (output_bfd, name);
1810 dyn.d_un.d_ptr = s->vma;
1813 if (s->_cooked_size != 0)
1814 dyn.d_un.d_val = s->_cooked_size;
1816 dyn.d_un.d_val = s->_raw_size;
1819 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
1823 /* Clear the first four entries in the procedure linkage table,
1824 and put a nop in the last four bytes. */
1826 if (splt->_raw_size > 0)
1828 memset (splt->contents, 0, 4 * PLT_ENTRY_SIZE);
1829 bfd_put_32 (output_bfd, SPARC_NOP,
1830 splt->contents + splt->_raw_size - 4);
1833 elf_section_data (splt->output_section)->this_hdr.sh_entsize =
1838 /* Set the first entry in the global offset table to the address of
1839 the dynamic section. */
1840 sgot = bfd_get_section_by_name (dynobj, ".got");
1841 BFD_ASSERT (sgot != NULL);
1842 if (sgot->_raw_size > 0)
1845 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents);
1847 bfd_put_32 (output_bfd,
1848 sdyn->output_section->vma + sdyn->output_offset,
1852 elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4;
1858 Elf_Internal_Sym sym;
1860 /* Set up the section symbols for the output sections. */
1862 sdynsym = bfd_get_section_by_name (dynobj, ".dynsym");
1863 BFD_ASSERT (sdynsym != NULL);
1867 sym.st_info = ELF_ST_INFO (STB_LOCAL, STT_SECTION);
1870 for (s = output_bfd->sections; s != NULL; s = s->next)
1874 sym.st_value = s->vma;
1876 indx = elf_section_data (s)->this_idx;
1877 BFD_ASSERT (indx > 0);
1878 sym.st_shndx = indx;
1880 bfd_elf32_swap_symbol_out (output_bfd, &sym,
1881 (PTR) (((Elf32_External_Sym *)
1883 + elf_section_data (s)->dynindx));
1886 /* Set the sh_info field of the output .dynsym section to the
1887 index of the first global symbol. */
1888 elf_section_data (sdynsym->output_section)->this_hdr.sh_info =
1889 bfd_count_sections (output_bfd) + 1;
1896 /* The RELOCATE_SECTION function is called by the ELF backend linker
1897 to handle the relocations for a section.
1899 The relocs are always passed as Rela structures; if the section
1900 actually uses Rel structures, the r_addend field will always be
1903 This function is responsible for adjust the section contents as
1904 necessary, and (if using Rela relocs and generating a
1905 relocateable output file) adjusting the reloc addend as
1908 This function does not have to worry about setting the reloc
1909 address or the reloc symbol index.
1911 LOCAL_SYMS is a pointer to the swapped in local symbols.
1913 LOCAL_SECTIONS is an array giving the section in the input file
1914 corresponding to the st_shndx field of each local symbol.
1916 The global hash table entry for the global symbols can be found
1917 via elf_sym_hashes (input_bfd).
1919 When generating relocateable output, this function must handle
1920 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
1921 going to be the section symbol corresponding to the output
1922 section, which means that the addend must be adjusted
1926 ppc_elf_relocate_section (output_bfd, info, input_bfd, input_section,
1927 contents, relocs, local_syms, local_sections)
1929 struct bfd_link_info *info;
1931 asection *input_section;
1933 Elf_Internal_Rela *relocs;
1934 Elf_Internal_Sym *local_syms;
1935 asection **local_sections;
1937 Elf_Internal_Shdr *symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
1938 struct elf_link_hash_entry **sym_hashes = elf_sym_hashes (input_bfd);
1939 bfd *dynobj = elf_hash_table (info)->dynobj;
1940 bfd_vma *local_got_offsets = elf_local_got_offsets (input_bfd);
1941 asection *sgot = (asection *)0;
1942 Elf_Internal_Rela *rel = relocs;
1943 Elf_Internal_Rela *relend = relocs + input_section->reloc_count;
1948 fprintf (stderr, "ppc_elf_relocate_section called for %s section %s, %ld relocations%s\n",
1949 bfd_get_filename (input_bfd),
1950 bfd_section_name(input_bfd, input_section),
1951 (long)input_section->reloc_count,
1952 (info->relocateable) ? " (relocatable)" : "");
1955 if (!ppc_elf_howto_table[ R_PPC_ADDR32 ]) /* Initialize howto table if needed */
1956 ppc_elf_howto_init ();
1958 for (; rel < relend; rel++)
1960 enum ppc_reloc_type r_type = (enum ppc_reloc_type)ELF32_R_TYPE (rel->r_info);
1961 bfd_vma offset = rel->r_offset;
1962 bfd_vma addend = rel->r_addend;
1963 bfd_reloc_status_type r = bfd_reloc_other;
1964 Elf_Internal_Sym *sym = (Elf_Internal_Sym *)0;
1965 asection *sec = (asection *)0;
1966 struct elf_link_hash_entry *h = (struct elf_link_hash_entry *)0;
1967 reloc_howto_type *howto;
1968 unsigned long r_symndx;
1971 /* Unknown relocation handling */
1972 if ((unsigned)r_type >= (unsigned)R_PPC_max || !ppc_elf_howto_table[(int)r_type])
1974 (*_bfd_error_handler)
1975 ("%s: unknown relocation type %d",
1976 bfd_get_filename (input_bfd),
1979 bfd_set_error (bfd_error_bad_value);
1984 howto = ppc_elf_howto_table[(int)r_type];
1985 r_symndx = ELF32_R_SYM (rel->r_info);
1987 if (info->relocateable)
1989 /* This is a relocateable link. We don't have to change
1990 anything, unless the reloc is against a section symbol,
1991 in which case we have to adjust according to where the
1992 section symbol winds up in the output section. */
1993 if (r_symndx < symtab_hdr->sh_info)
1995 sym = local_syms + r_symndx;
1996 if ((unsigned)ELF_ST_TYPE (sym->st_info) == STT_SECTION)
1998 sec = local_sections[r_symndx];
1999 addend = rel->r_addend += sec->output_offset + sym->st_value;
2004 fprintf (stderr, "\ttype = %s (%d), symbol index = %ld, offset = %ld, addend = %ld\n",
2014 /* This is a final link. */
2016 /* Complain about known relocation that are not yet supported */
2017 if (howto->special_function == ppc_elf_unsupported_reloc)
2019 (*_bfd_error_handler)
2020 ("%s: relocation %s (%d) is not currently supported",
2021 bfd_get_filename (input_bfd),
2025 bfd_set_error (bfd_error_bad_value);
2030 if (r_symndx < symtab_hdr->sh_info)
2032 sym = local_syms + r_symndx;
2033 sec = local_sections[r_symndx];
2034 relocation = (sec->output_section->vma
2035 + sec->output_offset
2040 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
2041 if (h->root.type == bfd_link_hash_defined
2042 || h->root.type == bfd_link_hash_defweak)
2044 sec = h->root.u.def.section;
2045 relocation = (h->root.u.def.value
2046 + sec->output_section->vma
2047 + sec->output_offset);
2049 else if (h->root.type == bfd_link_hash_undefweak)
2051 else if (info->shared)
2055 (*info->callbacks->undefined_symbol)(info,
2056 h->root.root.string,
2065 switch ((int)r_type)
2070 case (int)R_PPC_ADDR14_BRTAKEN: /* branch taken prediction relocations */
2071 case (int)R_PPC_REL14_BRTAKEN:
2072 insn = bfd_get_32 (output_bfd, contents + offset);
2073 if ((relocation - offset) & 0x8000)
2074 insn &= ~BRANCH_PREDICT_BIT;
2076 insn |= BRANCH_PREDICT_BIT;
2077 bfd_put_32 (output_bfd, insn, contents + offset);
2080 case (int)R_PPC_ADDR14_BRNTAKEN: /* branch not taken predicition relocations */
2081 case (int)R_PPC_REL14_BRNTAKEN:
2082 insn = bfd_get_32 (output_bfd, contents + offset);
2083 if ((relocation - offset) & 0x8000)
2084 insn |= BRANCH_PREDICT_BIT;
2086 insn &= ~BRANCH_PREDICT_BIT;
2087 bfd_put_32 (output_bfd, insn, contents + offset);
2090 case (int)R_PPC_GOT16: /* GOT16 relocations */
2091 case (int)R_PPC_GOT16_LO:
2092 case (int)R_PPC_GOT16_HI:
2093 case (int)R_PPC_SDAREL16:
2094 fprintf (stderr, "GOT relocations in section %s from section %s\n", input_section->name, sec->name);
2095 BFD_ASSERT (sec != (asection *)0);
2098 sgot = bfd_get_section_by_name (dynobj, ".got");
2099 BFD_ASSERT (sgot != NULL);
2106 off = h->got_offset;
2107 BFD_ASSERT (off != (bfd_vma) -1);
2109 if (! elf_hash_table (info)->dynamic_sections_created
2112 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR)))
2114 /* This is actually a static link, or it is a
2115 -Bsymbolic link and the symbol is defined
2116 locally. We must initialize this entry in the
2117 global offset table. Since the offset must
2118 always be a multiple of 4, we use the least
2119 significant bit to record whether we have
2120 initialized it already.
2122 When doing a dynamic link, we create a .rela.got
2123 relocation entry to initialize the value. This
2124 is done in the finish_dynamic_symbol routine. */
2129 bfd_put_32 (output_bfd, relocation,
2130 sgot->contents + off);
2135 relocation = sgot->output_offset + off;
2141 BFD_ASSERT (local_got_offsets != NULL
2142 && local_got_offsets[r_symndx] != (bfd_vma) -1);
2144 off = local_got_offsets[r_symndx];
2146 /* The offset must always be a multiple of 4. We use
2147 the least significant bit to record whether we have
2148 already processed this entry. */
2153 bfd_put_32 (output_bfd, relocation, sgot->contents + off);
2158 Elf_Internal_Rela outrel;
2160 /* We need to generate a R_SPARC_RELATIVE reloc
2161 for the dynamic linker. */
2162 srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
2163 BFD_ASSERT (srelgot != NULL);
2165 outrel.r_offset = (sgot->output_section->vma
2166 + sgot->output_offset
2168 outrel.r_info = ELF32_R_INFO (0, R_PPC_RELATIVE);
2169 outrel.r_addend = 0;
2170 bfd_elf32_swap_reloca_out (output_bfd, &outrel,
2171 (((Elf32_External_Rela *)
2173 + srelgot->reloc_count));
2174 ++srelgot->reloc_count;
2177 local_got_offsets[r_symndx] |= 1;
2180 relocation = sgot->output_offset + off;
2185 /* Handle the TOC16 reloc. We want to use the offset within the .got
2186 section, not the actual VMA. This is appropriate when generating
2187 an embedded ELF object, for which the .got section acts like the
2188 AIX .toc section. */
2189 case (int)R_PPC_TOC16: /* phony GOT16 relocations */
2190 BFD_ASSERT (sec != (asection *)0);
2191 BFD_ASSERT (bfd_is_und_section (sec)
2192 || strcmp (bfd_get_section_name (abfd, sec), ".got") == 0
2193 || strcmp (bfd_get_section_name (abfd, sec), ".cgot") == 0
2194 || strcmp (bfd_get_section_name (abfd, sec), ".sdata") == 0
2195 || strcmp (bfd_get_section_name (abfd, sec), ".sbss") == 0)
2197 addend -= sec->output_section->vma + 0x8000;
2200 case (int)R_PPC_ADDR16_HA: /* arithmetic adjust relocations */
2201 BFD_ASSERT (sec != (asection *)0);
2202 addend += ((relocation + addend) & 0x8000) << 1;
2208 fprintf (stderr, "\ttype = %s (%d), symbol index = %ld, offset = %ld, addend = %ld\n",
2216 r = _bfd_final_link_relocate (howto,
2224 if (r != bfd_reloc_ok)
2232 case bfd_reloc_overflow:
2237 name = h->root.root.string;
2240 name = bfd_elf_string_from_elf_section (input_bfd,
2241 symtab_hdr->sh_link,
2247 name = bfd_section_name (input_bfd, sec);
2250 (*info->callbacks->reloc_overflow)(info,
2266 fprintf (stderr, "\n");
2272 #define TARGET_LITTLE_SYM bfd_elf32_powerpcle_vec
2273 #define TARGET_LITTLE_NAME "elf32-powerpcle"
2274 #define TARGET_BIG_SYM bfd_elf32_powerpc_vec
2275 #define TARGET_BIG_NAME "elf32-powerpc"
2276 #define ELF_ARCH bfd_arch_powerpc
2277 #define ELF_MACHINE_CODE EM_PPC
2278 #define ELF_MAXPAGESIZE 0x10000
2279 #define elf_info_to_howto ppc_elf_info_to_howto
2281 #ifdef EM_CYGNUS_POWERPC
2282 #define ELF_MACHINE_ALT1 EM_CYGNUS_POWERPC
2286 #define ELF_MACHINE_ALT2 EM_PPC_OLD
2289 #define bfd_elf32_bfd_copy_private_bfd_data ppc_elf_copy_private_bfd_data
2290 #define bfd_elf32_bfd_merge_private_bfd_data ppc_elf_merge_private_bfd_data
2291 #define bfd_elf32_bfd_set_private_flags ppc_elf_set_private_flags
2292 #define bfd_elf32_bfd_reloc_type_lookup ppc_elf_reloc_type_lookup
2293 #define elf_backend_relocate_section ppc_elf_relocate_section
2294 #define elf_backend_create_dynamic_sections _bfd_elf_create_dynamic_sections
2295 #define elf_backend_check_relocs ppc_elf_check_relocs
2296 #define elf_backend_adjust_dynamic_symbol ppc_elf_adjust_dynamic_symbol
2297 #define elf_backend_size_dynamic_sections ppc_elf_size_dynamic_sections
2298 #define elf_backend_finish_dynamic_symbol ppc_elf_finish_dynamic_symbol
2299 #define elf_backend_finish_dynamic_sections ppc_elf_finish_dynamic_sections
2301 #include "elf32-target.h"