1 /* PowerPC-specific support for 32-bit ELF
2 Copyright 1994, 1995, 1996 Free Software Foundation, Inc.
3 Written by Ian Lance Taylor, Cygnus Support.
5 This file is part of BFD, the Binary File Descriptor library.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
21 /* This file is based on a preliminary PowerPC ELF ABI. The
22 information may not match the final PowerPC ELF ABI. It includes
23 suggestions from the in-progress Embedded PowerPC ABI, and that
24 information may also not match. */
33 #define USE_RELA /* we want RELA relocations, not REL */
35 /* PowerPC relocations defined by the ABIs */
46 R_PPC_ADDR14_BRTAKEN
= 8,
47 R_PPC_ADDR14_BRNTAKEN
= 9,
50 R_PPC_REL14_BRTAKEN
= 12,
51 R_PPC_REL14_BRNTAKEN
= 13,
72 R_PPC_SECTOFF_LO
= 34,
73 R_PPC_SECTOFF_HI
= 35,
74 R_PPC_SECTOFF_HA
= 36,
76 /* The remaining relocs are from the Embedded ELF ABI, and are not
77 in the SVR4 ELF ABI. */
78 R_PPC_EMB_NADDR32
= 101,
79 R_PPC_EMB_NADDR16
= 102,
80 R_PPC_EMB_NADDR16_LO
= 103,
81 R_PPC_EMB_NADDR16_HI
= 104,
82 R_PPC_EMB_NADDR16_HA
= 105,
83 R_PPC_EMB_SDAI16
= 106,
84 R_PPC_EMB_SDA2I16
= 107,
85 R_PPC_EMB_SDA2REL
= 108,
86 R_PPC_EMB_SDA21
= 109,
87 R_PPC_EMB_MRKREF
= 110,
88 R_PPC_EMB_RELSEC16
= 111,
89 R_PPC_EMB_RELST_LO
= 112,
90 R_PPC_EMB_RELST_HI
= 113,
91 R_PPC_EMB_RELST_HA
= 114,
92 R_PPC_EMB_BIT_FLD
= 115,
93 R_PPC_EMB_RELSDA
= 116,
95 /* This is a phony reloc to handle any old fashioned TOC16 references
96 that may still be in object files. */
102 static reloc_howto_type
*ppc_elf_reloc_type_lookup
103 PARAMS ((bfd
*abfd
, bfd_reloc_code_real_type code
));
104 static void ppc_elf_info_to_howto
105 PARAMS ((bfd
*abfd
, arelent
*cache_ptr
, Elf32_Internal_Rela
*dst
));
106 static void ppc_elf_howto_init
PARAMS ((void));
107 static boolean ppc_elf_set_private_flags
PARAMS ((bfd
*, flagword
));
108 static boolean ppc_elf_copy_private_bfd_data
PARAMS ((bfd
*, bfd
*));
109 static boolean ppc_elf_merge_private_bfd_data
PARAMS ((bfd
*, bfd
*));
111 static boolean ppc_elf_section_from_shdr
PARAMS ((bfd
*,
112 Elf32_Internal_Shdr
*,
115 static elf_linker_section_t
*ppc_elf_create_linker_section
117 struct bfd_link_info
*info
,
118 enum elf_linker_section_enum
));
120 static boolean ppc_elf_check_relocs
PARAMS ((bfd
*,
121 struct bfd_link_info
*,
123 const Elf_Internal_Rela
*));
125 static boolean ppc_elf_adjust_dynamic_symbol
PARAMS ((struct bfd_link_info
*,
126 struct elf_link_hash_entry
*));
128 static boolean ppc_elf_adjust_dynindx
PARAMS ((struct elf_link_hash_entry
*, PTR
));
130 static boolean ppc_elf_size_dynamic_sections
PARAMS ((bfd
*, struct bfd_link_info
*));
132 static boolean ppc_elf_relocate_section
PARAMS ((bfd
*,
133 struct bfd_link_info
*info
,
137 Elf_Internal_Rela
*relocs
,
138 Elf_Internal_Sym
*local_syms
,
141 static boolean ppc_elf_finish_dynamic_symbol
PARAMS ((bfd
*,
142 struct bfd_link_info
*,
143 struct elf_link_hash_entry
*,
144 Elf_Internal_Sym
*));
146 static boolean ppc_elf_finish_dynamic_sections
PARAMS ((bfd
*, struct bfd_link_info
*));
148 #define BRANCH_PREDICT_BIT 0x200000
150 /* The name of the dynamic interpreter. This is put in the .interp
153 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
156 static reloc_howto_type
*ppc_elf_howto_table
[ (int)R_PPC_max
];
158 static reloc_howto_type ppc_elf_howto_raw
[] =
160 /* This reloc does nothing. */
161 HOWTO (R_PPC_NONE
, /* type */
163 2, /* size (0 = byte, 1 = short, 2 = long) */
165 false, /* pc_relative */
167 complain_overflow_bitfield
, /* complain_on_overflow */
168 bfd_elf_generic_reloc
, /* special_function */
169 "R_PPC_NONE", /* name */
170 false, /* partial_inplace */
173 false), /* pcrel_offset */
175 /* A standard 32 bit relocation. */
176 HOWTO (R_PPC_ADDR32
, /* type */
178 2, /* size (0 = byte, 1 = short, 2 = long) */
180 false, /* pc_relative */
182 complain_overflow_bitfield
, /* complain_on_overflow */
183 bfd_elf_generic_reloc
, /* special_function */
184 "R_PPC_ADDR32", /* name */
185 false, /* partial_inplace */
187 0xffffffff, /* dst_mask */
188 false), /* pcrel_offset */
190 /* An absolute 26 bit branch; the lower two bits must be zero.
191 FIXME: we don't check that, we just clear them. */
192 HOWTO (R_PPC_ADDR24
, /* type */
194 2, /* size (0 = byte, 1 = short, 2 = long) */
196 false, /* pc_relative */
198 complain_overflow_bitfield
, /* complain_on_overflow */
199 bfd_elf_generic_reloc
, /* special_function */
200 "R_PPC_ADDR24", /* name */
201 false, /* partial_inplace */
203 0x3fffffc, /* dst_mask */
204 false), /* pcrel_offset */
206 /* A standard 16 bit relocation. */
207 HOWTO (R_PPC_ADDR16
, /* type */
209 1, /* size (0 = byte, 1 = short, 2 = long) */
211 false, /* pc_relative */
213 complain_overflow_bitfield
, /* complain_on_overflow */
214 bfd_elf_generic_reloc
, /* special_function */
215 "R_PPC_ADDR16", /* name */
216 false, /* partial_inplace */
218 0xffff, /* dst_mask */
219 false), /* pcrel_offset */
221 /* A 16 bit relocation without overflow. */
222 HOWTO (R_PPC_ADDR16_LO
, /* type */
224 1, /* size (0 = byte, 1 = short, 2 = long) */
226 false, /* pc_relative */
228 complain_overflow_dont
,/* complain_on_overflow */
229 bfd_elf_generic_reloc
, /* special_function */
230 "R_PPC_ADDR16_LO", /* name */
231 false, /* partial_inplace */
233 0xffff, /* dst_mask */
234 false), /* pcrel_offset */
236 /* The high order 16 bits of an address. */
237 HOWTO (R_PPC_ADDR16_HI
, /* type */
239 1, /* size (0 = byte, 1 = short, 2 = long) */
241 false, /* pc_relative */
243 complain_overflow_dont
, /* complain_on_overflow */
244 bfd_elf_generic_reloc
, /* special_function */
245 "R_PPC_ADDR16_HI", /* name */
246 false, /* partial_inplace */
248 0xffff, /* dst_mask */
249 false), /* pcrel_offset */
251 /* The high order 16 bits of an address, plus 1 if the contents of
252 the low 16 bits, treated as a signed number, is negative. */
253 HOWTO (R_PPC_ADDR16_HA
, /* type */
255 1, /* size (0 = byte, 1 = short, 2 = long) */
257 false, /* pc_relative */
259 complain_overflow_dont
, /* complain_on_overflow */
260 bfd_elf_generic_reloc
, /* special_function */
261 "R_PPC_ADDR16_HA", /* name */
262 false, /* partial_inplace */
264 0xffff, /* dst_mask */
265 false), /* pcrel_offset */
267 /* An absolute 16 bit branch; the lower two bits must be zero.
268 FIXME: we don't check that, we just clear them. */
269 HOWTO (R_PPC_ADDR14
, /* type */
271 2, /* size (0 = byte, 1 = short, 2 = long) */
273 false, /* pc_relative */
275 complain_overflow_bitfield
, /* complain_on_overflow */
276 bfd_elf_generic_reloc
, /* special_function */
277 "R_PPC_ADDR14", /* name */
278 false, /* partial_inplace */
280 0xfffc, /* dst_mask */
281 false), /* pcrel_offset */
283 /* An absolute 16 bit branch, for which bit 10 should be set to
284 indicate that the branch is expected to be taken. The lower two
285 bits must be zero. */
286 HOWTO (R_PPC_ADDR14_BRTAKEN
, /* type */
288 2, /* size (0 = byte, 1 = short, 2 = long) */
290 false, /* pc_relative */
292 complain_overflow_bitfield
, /* complain_on_overflow */
293 bfd_elf_generic_reloc
, /* special_function */
294 "R_PPC_ADDR14_BRTAKEN",/* name */
295 false, /* partial_inplace */
297 0xfffc, /* dst_mask */
298 false), /* pcrel_offset */
300 /* An absolute 16 bit branch, for which bit 10 should be set to
301 indicate that the branch is not expected to be taken. The lower
302 two bits must be zero. */
303 HOWTO (R_PPC_ADDR14_BRNTAKEN
, /* type */
305 2, /* size (0 = byte, 1 = short, 2 = long) */
307 false, /* pc_relative */
309 complain_overflow_bitfield
, /* complain_on_overflow */
310 bfd_elf_generic_reloc
, /* special_function */
311 "R_PPC_ADDR14_BRNTAKEN",/* name */
312 false, /* partial_inplace */
314 0xfffc, /* dst_mask */
315 false), /* pcrel_offset */
317 /* A relative 26 bit branch; the lower two bits must be zero. */
318 HOWTO (R_PPC_REL24
, /* type */
320 2, /* size (0 = byte, 1 = short, 2 = long) */
322 true, /* pc_relative */
324 complain_overflow_signed
, /* complain_on_overflow */
325 bfd_elf_generic_reloc
, /* special_function */
326 "R_PPC_REL24", /* name */
327 false, /* partial_inplace */
329 0x3fffffc, /* dst_mask */
330 true), /* pcrel_offset */
332 /* A relative 16 bit branch; the lower two bits must be zero. */
333 HOWTO (R_PPC_REL14
, /* type */
335 2, /* size (0 = byte, 1 = short, 2 = long) */
337 true, /* pc_relative */
339 complain_overflow_signed
, /* complain_on_overflow */
340 bfd_elf_generic_reloc
, /* special_function */
341 "R_PPC_REL14", /* name */
342 false, /* partial_inplace */
344 0xfffc, /* dst_mask */
345 true), /* pcrel_offset */
347 /* A relative 16 bit branch. Bit 10 should be set to indicate that
348 the branch is expected to be taken. The lower two bits must be
350 HOWTO (R_PPC_REL14_BRTAKEN
, /* type */
352 2, /* size (0 = byte, 1 = short, 2 = long) */
354 true, /* pc_relative */
356 complain_overflow_signed
, /* complain_on_overflow */
357 bfd_elf_generic_reloc
, /* special_function */
358 "R_PPC_REL14_BRTAKEN", /* name */
359 false, /* partial_inplace */
361 0xfffc, /* dst_mask */
362 true), /* pcrel_offset */
364 /* A relative 16 bit branch. Bit 10 should be set to indicate that
365 the branch is not expected to be taken. The lower two bits must
367 HOWTO (R_PPC_REL14_BRNTAKEN
, /* type */
369 2, /* size (0 = byte, 1 = short, 2 = long) */
371 true, /* pc_relative */
373 complain_overflow_signed
, /* complain_on_overflow */
374 bfd_elf_generic_reloc
, /* special_function */
375 "R_PPC_REL14_BRNTAKEN",/* name */
376 false, /* partial_inplace */
378 0xfffc, /* dst_mask */
379 true), /* pcrel_offset */
381 /* Like R_PPC_ADDR16, but referring to the GOT table entry for the
383 HOWTO (R_PPC_GOT16
, /* type */
385 1, /* size (0 = byte, 1 = short, 2 = long) */
387 false, /* pc_relative */
389 complain_overflow_signed
, /* complain_on_overflow */
390 bfd_elf_generic_reloc
, /* special_function */
391 "R_PPC_GOT16", /* name */
392 false, /* partial_inplace */
394 0xffff, /* dst_mask */
395 false), /* pcrel_offset */
397 /* Like R_PPC_ADDR16_LO, but referring to the GOT table entry for
399 HOWTO (R_PPC_GOT16_LO
, /* type */
401 1, /* size (0 = byte, 1 = short, 2 = long) */
403 false, /* pc_relative */
405 complain_overflow_bitfield
, /* complain_on_overflow */
406 bfd_elf_generic_reloc
, /* special_function */
407 "R_PPC_GOT16_LO", /* name */
408 false, /* partial_inplace */
410 0xffff, /* dst_mask */
411 false), /* pcrel_offset */
413 /* Like R_PPC_ADDR16_HI, but referring to the GOT table entry for
415 HOWTO (R_PPC_GOT16_HI
, /* type */
417 1, /* size (0 = byte, 1 = short, 2 = long) */
419 false, /* pc_relative */
421 complain_overflow_bitfield
, /* complain_on_overflow */
422 bfd_elf_generic_reloc
, /* special_function */
423 "R_PPC_GOT16_HI", /* name */
424 false, /* partial_inplace */
426 0xffff, /* dst_mask */
427 false), /* pcrel_offset */
429 /* Like R_PPC_ADDR16_HA, but referring to the GOT table entry for
430 the symbol. FIXME: Not supported. */
431 HOWTO (R_PPC_GOT16_HA
, /* type */
433 1, /* size (0 = byte, 1 = short, 2 = long) */
435 false, /* pc_relative */
437 complain_overflow_bitfield
, /* complain_on_overflow */
438 bfd_elf_generic_reloc
, /* special_function */
439 "R_PPC_GOT16_HA", /* name */
440 false, /* partial_inplace */
442 0xffff, /* dst_mask */
443 false), /* pcrel_offset */
445 /* Like R_PPC_REL24, but referring to the procedure linkage table
446 entry for the symbol. FIXME: Not supported. */
447 HOWTO (R_PPC_PLTREL24
, /* type */
449 2, /* size (0 = byte, 1 = short, 2 = long) */
451 true, /* pc_relative */
453 complain_overflow_signed
, /* complain_on_overflow */
454 bfd_elf_generic_reloc
, /* special_function */
455 "R_PPC_PLTREL24", /* name */
456 false, /* partial_inplace */
458 0x3fffffc, /* dst_mask */
459 true), /* pcrel_offset */
461 /* This is used only by the dynamic linker. The symbol should exist
462 both in the object being run and in some shared library. The
463 dynamic linker copies the data addressed by the symbol from the
464 shared library into the object. I have no idea what the purpose
466 HOWTO (R_PPC_COPY
, /* type */
468 2, /* size (0 = byte, 1 = short, 2 = long) */
470 false, /* pc_relative */
472 complain_overflow_bitfield
, /* complain_on_overflow */
473 bfd_elf_generic_reloc
, /* special_function */
474 "R_PPC_COPY", /* name */
475 false, /* partial_inplace */
478 false), /* pcrel_offset */
480 /* Like R_PPC_ADDR32, but used when setting global offset table
482 HOWTO (R_PPC_GLOB_DAT
, /* type */
484 2, /* size (0 = byte, 1 = short, 2 = long) */
486 false, /* pc_relative */
488 complain_overflow_bitfield
, /* complain_on_overflow */
489 bfd_elf_generic_reloc
, /* special_function */
490 "R_PPC_GLOB_DAT", /* name */
491 false, /* partial_inplace */
493 0xffffffff, /* dst_mask */
494 false), /* pcrel_offset */
496 /* Marks a procedure linkage table entry for a symbol. */
497 HOWTO (R_PPC_JMP_SLOT
, /* type */
499 2, /* size (0 = byte, 1 = short, 2 = long) */
501 false, /* pc_relative */
503 complain_overflow_bitfield
, /* complain_on_overflow */
504 bfd_elf_generic_reloc
, /* special_function */
505 "R_PPC_JMP_SLOT", /* name */
506 false, /* partial_inplace */
509 false), /* pcrel_offset */
511 /* Used only by the dynamic linker. When the object is run, this
512 longword is set to the load address of the object, plus the
514 HOWTO (R_PPC_RELATIVE
, /* type */
516 2, /* size (0 = byte, 1 = short, 2 = long) */
518 false, /* pc_relative */
520 complain_overflow_bitfield
, /* complain_on_overflow */
521 bfd_elf_generic_reloc
, /* special_function */
522 "R_PPC_RELATIVE", /* name */
523 false, /* partial_inplace */
525 0xffffffff, /* dst_mask */
526 false), /* pcrel_offset */
528 /* Like R_PPC_REL24, but uses the value of the symbol within the
529 object rather than the final value. Normally used for
530 _GLOBAL_OFFSET_TABLE_. FIXME: Not supported. */
531 HOWTO (R_PPC_LOCAL24PC
, /* type */
533 2, /* size (0 = byte, 1 = short, 2 = long) */
535 true, /* pc_relative */
537 complain_overflow_signed
, /* complain_on_overflow */
538 bfd_elf_generic_reloc
, /* special_function */
539 "R_PPC_LOCAL24PC", /* name */
540 false, /* partial_inplace */
542 0x3fffffc, /* dst_mask */
543 true), /* pcrel_offset */
545 /* Like R_PPC_ADDR32, but may be unaligned. */
546 HOWTO (R_PPC_UADDR32
, /* type */
548 2, /* size (0 = byte, 1 = short, 2 = long) */
550 false, /* pc_relative */
552 complain_overflow_bitfield
, /* complain_on_overflow */
553 bfd_elf_generic_reloc
, /* special_function */
554 "R_PPC_UADDR32", /* name */
555 false, /* partial_inplace */
557 0xffffffff, /* dst_mask */
558 false), /* pcrel_offset */
560 /* Like R_PPC_ADDR16, but may be unaligned. */
561 HOWTO (R_PPC_UADDR16
, /* type */
563 1, /* size (0 = byte, 1 = short, 2 = long) */
565 false, /* pc_relative */
567 complain_overflow_bitfield
, /* complain_on_overflow */
568 bfd_elf_generic_reloc
, /* special_function */
569 "R_PPC_UADDR16", /* name */
570 false, /* partial_inplace */
572 0xffff, /* dst_mask */
573 false), /* pcrel_offset */
575 /* 32-bit PC relative */
576 HOWTO (R_PPC_REL32
, /* type */
578 2, /* size (0 = byte, 1 = short, 2 = long) */
580 true, /* pc_relative */
582 complain_overflow_bitfield
, /* complain_on_overflow */
583 bfd_elf_generic_reloc
, /* special_function */
584 "R_PPC_REL32", /* name */
585 false, /* partial_inplace */
587 0xffffffff, /* dst_mask */
588 true), /* pcrel_offset */
590 /* 32-bit relocation to the symbol's procedure linkage table.
591 FIXEME: not supported. */
592 HOWTO (R_PPC_PLT32
, /* type */
594 2, /* size (0 = byte, 1 = short, 2 = long) */
596 false, /* pc_relative */
598 complain_overflow_bitfield
, /* complain_on_overflow */
599 bfd_elf_generic_reloc
, /* special_function */
600 "R_PPC_PLT32", /* name */
601 false, /* partial_inplace */
604 false), /* pcrel_offset */
606 /* 32-bit PC relative relocation to the symbol's procedure linkage table.
607 FIXEME: not supported. */
608 HOWTO (R_PPC_PLTREL32
, /* type */
610 2, /* size (0 = byte, 1 = short, 2 = long) */
612 true, /* pc_relative */
614 complain_overflow_bitfield
, /* complain_on_overflow */
615 bfd_elf_generic_reloc
, /* special_function */
616 "R_PPC_PLTREL32", /* name */
617 false, /* partial_inplace */
620 true), /* pcrel_offset */
622 /* Like R_PPC_ADDR16_LO, but referring to the PLT table entry for
624 HOWTO (R_PPC_PLT16_LO
, /* type */
626 1, /* size (0 = byte, 1 = short, 2 = long) */
628 false, /* pc_relative */
630 complain_overflow_bitfield
, /* complain_on_overflow */
631 bfd_elf_generic_reloc
, /* special_function */
632 "R_PPC_PLT16_LO", /* name */
633 false, /* partial_inplace */
635 0xffff, /* dst_mask */
636 false), /* pcrel_offset */
638 /* Like R_PPC_ADDR16_HI, but referring to the PLT table entry for
640 HOWTO (R_PPC_PLT16_HI
, /* type */
642 1, /* size (0 = byte, 1 = short, 2 = long) */
644 false, /* pc_relative */
646 complain_overflow_bitfield
, /* complain_on_overflow */
647 bfd_elf_generic_reloc
, /* special_function */
648 "R_PPC_PLT16_HI", /* name */
649 false, /* partial_inplace */
651 0xffff, /* dst_mask */
652 false), /* pcrel_offset */
654 /* Like R_PPC_ADDR16_HA, but referring to the PLT table entry for
655 the symbol. FIXME: Not supported. */
656 HOWTO (R_PPC_PLT16_HA
, /* type */
658 1, /* size (0 = byte, 1 = short, 2 = long) */
660 false, /* pc_relative */
662 complain_overflow_bitfield
, /* complain_on_overflow */
663 bfd_elf_generic_reloc
, /* special_function */
664 "R_PPC_PLT16_HA", /* name */
665 false, /* partial_inplace */
667 0xffff, /* dst_mask */
668 false), /* pcrel_offset */
670 /* A sign-extended 16 bit value relative to _SDA_BASE_, for use with
671 small data items. FIXME: Not supported. */
672 HOWTO (R_PPC_SDAREL16
, /* type */
674 1, /* size (0 = byte, 1 = short, 2 = long) */
676 false, /* pc_relative */
678 complain_overflow_signed
, /* complain_on_overflow */
679 bfd_elf_generic_reloc
, /* special_function */
680 "R_PPC_SDAREL16", /* name */
681 false, /* partial_inplace */
683 0xffff, /* dst_mask */
684 false), /* pcrel_offset */
686 /* 32-bit section relative relocation. FIXME: not supported. */
687 HOWTO (R_PPC_SECTOFF
, /* type */
689 2, /* size (0 = byte, 1 = short, 2 = long) */
691 true, /* pc_relative */
693 complain_overflow_bitfield
, /* complain_on_overflow */
694 bfd_elf_generic_reloc
, /* special_function */
695 "R_PPC_SECTOFF", /* name */
696 false, /* partial_inplace */
699 true), /* pcrel_offset */
701 /* 16-bit lower half section relative relocation. FIXME: not supported. */
702 HOWTO (R_PPC_SECTOFF_LO
, /* type */
704 1, /* size (0 = byte, 1 = short, 2 = long) */
706 false, /* pc_relative */
708 complain_overflow_bitfield
, /* complain_on_overflow */
709 bfd_elf_generic_reloc
, /* special_function */
710 "R_PPC_SECTOFF_LO", /* name */
711 false, /* partial_inplace */
713 0xffff, /* dst_mask */
714 false), /* pcrel_offset */
716 /* 16-bit upper half section relative relocation. FIXME: not supported. */
717 HOWTO (R_PPC_SECTOFF_HI
, /* type */
719 1, /* size (0 = byte, 1 = short, 2 = long) */
721 false, /* pc_relative */
723 complain_overflow_bitfield
, /* complain_on_overflow */
724 bfd_elf_generic_reloc
, /* special_function */
725 "R_PPC_SECTOFF_HI", /* name */
726 false, /* partial_inplace */
728 0xffff, /* dst_mask */
729 false), /* pcrel_offset */
731 /* 16-bit upper half adjusted section relative relocation. FIXME: not supported. */
732 HOWTO (R_PPC_SECTOFF_HA
, /* type */
734 1, /* size (0 = byte, 1 = short, 2 = long) */
736 false, /* pc_relative */
738 complain_overflow_bitfield
, /* complain_on_overflow */
739 bfd_elf_generic_reloc
, /* special_function */
740 "R_PPC_SECTOFF_HA", /* name */
741 false, /* partial_inplace */
743 0xffff, /* dst_mask */
744 false), /* pcrel_offset */
746 /* The remaining relocs are from the Embedded ELF ABI, and are not
747 in the SVR4 ELF ABI. */
749 /* 32 bit value resulting from the addend minus the symbol */
750 HOWTO (R_PPC_EMB_NADDR32
, /* type */
752 2, /* size (0 = byte, 1 = short, 2 = long) */
754 false, /* pc_relative */
756 complain_overflow_bitfield
, /* complain_on_overflow */
757 bfd_elf_generic_reloc
, /* special_function */
758 "R_PPC_EMB_NADDR32", /* name */
759 false, /* partial_inplace */
761 0xffffffff, /* dst_mask */
762 false), /* pcrel_offset */
764 /* 16 bit value resulting from the addend minus the symbol */
765 HOWTO (R_PPC_EMB_NADDR16
, /* type */
767 1, /* size (0 = byte, 1 = short, 2 = long) */
769 false, /* pc_relative */
771 complain_overflow_bitfield
, /* complain_on_overflow */
772 bfd_elf_generic_reloc
, /* special_function */
773 "R_PPC_EMB_NADDR16", /* name */
774 false, /* partial_inplace */
776 0xffff, /* dst_mask */
777 false), /* pcrel_offset */
779 /* 16 bit value resulting from the addend minus the symbol */
780 HOWTO (R_PPC_EMB_NADDR16_LO
, /* type */
782 1, /* size (0 = byte, 1 = short, 2 = long) */
784 false, /* pc_relative */
786 complain_overflow_dont
,/* complain_on_overflow */
787 bfd_elf_generic_reloc
, /* special_function */
788 "R_PPC_EMB_ADDR16_LO", /* name */
789 false, /* partial_inplace */
791 0xffff, /* dst_mask */
792 false), /* pcrel_offset */
794 /* The high order 16 bits of the addend minus the symbol */
795 HOWTO (R_PPC_EMB_NADDR16_HI
, /* type */
797 1, /* size (0 = byte, 1 = short, 2 = long) */
799 false, /* pc_relative */
801 complain_overflow_dont
, /* complain_on_overflow */
802 bfd_elf_generic_reloc
, /* special_function */
803 "R_PPC_EMB_NADDR16_HI", /* name */
804 false, /* partial_inplace */
806 0xffff, /* dst_mask */
807 false), /* pcrel_offset */
809 /* The high order 16 bits of the result of the addend minus the address,
810 plus 1 if the contents of the low 16 bits, treated as a signed number,
812 HOWTO (R_PPC_EMB_NADDR16_HA
, /* type */
814 1, /* size (0 = byte, 1 = short, 2 = long) */
816 false, /* pc_relative */
818 complain_overflow_dont
, /* complain_on_overflow */
819 bfd_elf_generic_reloc
, /* special_function */
820 "R_PPC_EMB_NADDR16_HA", /* name */
821 false, /* partial_inplace */
823 0xffff, /* dst_mask */
824 false), /* pcrel_offset */
826 /* 16 bit value resulting from allocating a 4 byte word to hold an
827 address in the .sdata section, and returning the offset from
828 _SDA_BASE_ for that relocation */
829 HOWTO (R_PPC_EMB_SDAI16
, /* type */
831 1, /* size (0 = byte, 1 = short, 2 = long) */
833 false, /* pc_relative */
835 complain_overflow_bitfield
, /* complain_on_overflow */
836 bfd_elf_generic_reloc
, /* special_function */
837 "R_PPC_EMB_SDAI16", /* name */
838 false, /* partial_inplace */
840 0xffff, /* dst_mask */
841 false), /* pcrel_offset */
843 /* 16 bit value resulting from allocating a 4 byte word to hold an
844 address in the .sdata2 section, and returning the offset from
845 _SDA2_BASE_ for that relocation */
846 HOWTO (R_PPC_EMB_SDA2I16
, /* type */
848 1, /* size (0 = byte, 1 = short, 2 = long) */
850 false, /* pc_relative */
852 complain_overflow_bitfield
, /* complain_on_overflow */
853 bfd_elf_generic_reloc
, /* special_function */
854 "R_PPC_EMB_SDA2I16", /* name */
855 false, /* partial_inplace */
857 0xffff, /* dst_mask */
858 false), /* pcrel_offset */
860 /* A sign-extended 16 bit value relative to _SDA2_BASE_, for use with
861 small data items. FIXME: Not supported. */
862 HOWTO (R_PPC_EMB_SDA2REL
, /* type */
864 1, /* size (0 = byte, 1 = short, 2 = long) */
866 false, /* pc_relative */
868 complain_overflow_signed
, /* complain_on_overflow */
869 bfd_elf_generic_reloc
, /* special_function */
870 "R_PPC_EMB_SDA2REL", /* name */
871 false, /* partial_inplace */
873 0xffff, /* dst_mask */
874 false), /* pcrel_offset */
876 /* Relocate against either _SDA_BASE_ or _SDA2_BASE_, filling in the 16 bit
877 signed offset from the appropriate base, and filling in the register
878 field with the appropriate register (0, 2, or 13). */
879 HOWTO (R_PPC_EMB_SDA21
, /* type */
881 1, /* size (0 = byte, 1 = short, 2 = long) */
883 false, /* pc_relative */
885 complain_overflow_signed
, /* complain_on_overflow */
886 bfd_elf_generic_reloc
, /* special_function */
887 "R_PPC_EMB_SDA21", /* name */
888 false, /* partial_inplace */
890 0xffff, /* dst_mask */
891 false), /* pcrel_offset */
893 /* Relocation not handled: R_PPC_EMB_MRKREF */
894 /* Relocation not handled: R_PPC_EMB_RELSEC16 */
895 /* Relocation not handled: R_PPC_EMB_RELST_LO */
896 /* Relocation not handled: R_PPC_EMB_RELST_HI */
897 /* Relocation not handled: R_PPC_EMB_RELST_HA */
898 /* Relocation not handled: R_PPC_EMB_BIT_FLD */
900 /* PC relative relocation against either _SDA_BASE_ or _SDA2_BASE_, filling
901 in the 16 bit signed offset from the appropriate base, and filling in the
902 register field with the appropriate register (0, 2, or 13). */
903 HOWTO (R_PPC_EMB_RELSDA
, /* type */
905 1, /* size (0 = byte, 1 = short, 2 = long) */
907 true, /* pc_relative */
909 complain_overflow_signed
, /* complain_on_overflow */
910 bfd_elf_generic_reloc
, /* special_function */
911 "R_PPC_EMB_RELSDA", /* name */
912 false, /* partial_inplace */
914 0xffff, /* dst_mask */
915 false), /* pcrel_offset */
917 /* Phony reloc to handle AIX style TOC entries */
918 HOWTO (R_PPC_TOC16
, /* type */
920 1, /* size (0 = byte, 1 = short, 2 = long) */
922 false, /* pc_relative */
924 complain_overflow_signed
, /* complain_on_overflow */
925 bfd_elf_generic_reloc
, /* special_function */
926 "R_PPC_TOC16", /* name */
927 false, /* partial_inplace */
929 0xffff, /* dst_mask */
930 false), /* pcrel_offset */
934 /* Initialize the ppc_elf_howto_table, so that linear accesses can be done. */
937 ppc_elf_howto_init ()
939 unsigned int i
, type
;
941 for (i
= 0; i
< sizeof (ppc_elf_howto_raw
) / sizeof (ppc_elf_howto_raw
[0]); i
++)
943 type
= ppc_elf_howto_raw
[i
].type
;
944 BFD_ASSERT (type
< sizeof(ppc_elf_howto_table
) / sizeof(ppc_elf_howto_table
[0]));
945 ppc_elf_howto_table
[type
] = &ppc_elf_howto_raw
[i
];
950 static reloc_howto_type
*
951 ppc_elf_reloc_type_lookup (abfd
, code
)
953 bfd_reloc_code_real_type code
;
955 enum ppc_reloc_type ppc_reloc
= R_PPC_NONE
;
957 if (!ppc_elf_howto_table
[ R_PPC_ADDR32
]) /* Initialize howto table if needed */
958 ppc_elf_howto_init ();
963 return (reloc_howto_type
*)NULL
;
965 case BFD_RELOC_NONE
: ppc_reloc
= R_PPC_NONE
; break;
966 case BFD_RELOC_32
: ppc_reloc
= R_PPC_ADDR32
; break;
967 case BFD_RELOC_PPC_BA26
: ppc_reloc
= R_PPC_ADDR24
; break;
968 case BFD_RELOC_16
: ppc_reloc
= R_PPC_ADDR16
; break;
969 case BFD_RELOC_LO16
: ppc_reloc
= R_PPC_ADDR16_LO
; break;
970 case BFD_RELOC_HI16
: ppc_reloc
= R_PPC_ADDR16_HI
; break;
971 case BFD_RELOC_HI16_S
: ppc_reloc
= R_PPC_ADDR16_HA
; break;
972 case BFD_RELOC_PPC_BA16
: ppc_reloc
= R_PPC_ADDR14
; break;
973 case BFD_RELOC_PPC_BA16_BRTAKEN
: ppc_reloc
= R_PPC_ADDR14_BRTAKEN
; break;
974 case BFD_RELOC_PPC_BA16_BRNTAKEN
: ppc_reloc
= R_PPC_ADDR14_BRNTAKEN
; break;
975 case BFD_RELOC_PPC_B26
: ppc_reloc
= R_PPC_REL24
; break;
976 case BFD_RELOC_PPC_B16
: ppc_reloc
= R_PPC_REL14
; break;
977 case BFD_RELOC_PPC_B16_BRTAKEN
: ppc_reloc
= R_PPC_REL14_BRTAKEN
; break;
978 case BFD_RELOC_PPC_B16_BRNTAKEN
: ppc_reloc
= R_PPC_REL14_BRNTAKEN
; break;
979 case BFD_RELOC_16_GOTOFF
: ppc_reloc
= R_PPC_GOT16
; break;
980 case BFD_RELOC_LO16_GOTOFF
: ppc_reloc
= R_PPC_GOT16_LO
; break;
981 case BFD_RELOC_HI16_GOTOFF
: ppc_reloc
= R_PPC_GOT16_HI
; break;
982 case BFD_RELOC_HI16_S_GOTOFF
: ppc_reloc
= R_PPC_GOT16_HA
; break;
983 case BFD_RELOC_24_PLT_PCREL
: ppc_reloc
= R_PPC_PLTREL24
; break;
984 case BFD_RELOC_PPC_COPY
: ppc_reloc
= R_PPC_COPY
; break;
985 case BFD_RELOC_PPC_GLOB_DAT
: ppc_reloc
= R_PPC_GLOB_DAT
; break;
986 case BFD_RELOC_PPC_LOCAL24PC
: ppc_reloc
= R_PPC_LOCAL24PC
; break;
987 case BFD_RELOC_32_PCREL
: ppc_reloc
= R_PPC_REL32
; break;
988 case BFD_RELOC_32_PLTOFF
: ppc_reloc
= R_PPC_PLT32
; break;
989 case BFD_RELOC_32_PLT_PCREL
: ppc_reloc
= R_PPC_PLTREL32
; break;
990 case BFD_RELOC_LO16_PLTOFF
: ppc_reloc
= R_PPC_PLT16_LO
; break;
991 case BFD_RELOC_HI16_PLTOFF
: ppc_reloc
= R_PPC_PLT16_HI
; break;
992 case BFD_RELOC_HI16_S_PLTOFF
: ppc_reloc
= R_PPC_PLT16_HA
; break;
993 case BFD_RELOC_GPREL16
: ppc_reloc
= R_PPC_SDAREL16
; break;
994 case BFD_RELOC_32_BASEREL
: ppc_reloc
= R_PPC_SECTOFF
; break;
995 case BFD_RELOC_LO16_BASEREL
: ppc_reloc
= R_PPC_SECTOFF_LO
; break;
996 case BFD_RELOC_HI16_BASEREL
: ppc_reloc
= R_PPC_SECTOFF_HI
; break;
997 case BFD_RELOC_HI16_S_BASEREL
: ppc_reloc
= R_PPC_SECTOFF_HA
; break;
998 case BFD_RELOC_CTOR
: ppc_reloc
= R_PPC_ADDR32
; break;
999 case BFD_RELOC_PPC_TOC16
: ppc_reloc
= R_PPC_TOC16
; break;
1000 case BFD_RELOC_PPC_EMB_NADDR32
: ppc_reloc
= R_PPC_EMB_NADDR32
; break;
1001 case BFD_RELOC_PPC_EMB_NADDR16
: ppc_reloc
= R_PPC_EMB_NADDR16
; break;
1002 case BFD_RELOC_PPC_EMB_NADDR16_LO
: ppc_reloc
= R_PPC_EMB_NADDR16_LO
; break;
1003 case BFD_RELOC_PPC_EMB_NADDR16_HI
: ppc_reloc
= R_PPC_EMB_NADDR16_HI
; break;
1004 case BFD_RELOC_PPC_EMB_NADDR16_HA
: ppc_reloc
= R_PPC_EMB_NADDR16_HA
; break;
1005 case BFD_RELOC_PPC_EMB_SDAI16
: ppc_reloc
= R_PPC_EMB_SDAI16
; break;
1006 case BFD_RELOC_PPC_EMB_SDA2I16
: ppc_reloc
= R_PPC_EMB_SDA2I16
; break;
1007 case BFD_RELOC_PPC_EMB_SDA2REL
: ppc_reloc
= R_PPC_EMB_SDA2REL
; break;
1008 case BFD_RELOC_PPC_EMB_SDA21
: ppc_reloc
= R_PPC_EMB_SDA21
; break;
1009 case BFD_RELOC_PPC_EMB_MRKREF
: ppc_reloc
= R_PPC_EMB_MRKREF
; break;
1010 case BFD_RELOC_PPC_EMB_RELSEC16
: ppc_reloc
= R_PPC_EMB_RELSEC16
; break;
1011 case BFD_RELOC_PPC_EMB_RELST_LO
: ppc_reloc
= R_PPC_EMB_RELST_LO
; break;
1012 case BFD_RELOC_PPC_EMB_RELST_HI
: ppc_reloc
= R_PPC_EMB_RELST_HI
; break;
1013 case BFD_RELOC_PPC_EMB_RELST_HA
: ppc_reloc
= R_PPC_EMB_RELST_HA
; break;
1014 case BFD_RELOC_PPC_EMB_BIT_FLD
: ppc_reloc
= R_PPC_EMB_BIT_FLD
; break;
1015 case BFD_RELOC_PPC_EMB_RELSDA
: ppc_reloc
= R_PPC_EMB_RELSDA
; break;
1018 return ppc_elf_howto_table
[ (int)ppc_reloc
];
1021 /* Set the howto pointer for a PowerPC ELF reloc. */
1024 ppc_elf_info_to_howto (abfd
, cache_ptr
, dst
)
1027 Elf32_Internal_Rela
*dst
;
1029 if (!ppc_elf_howto_table
[ R_PPC_ADDR32
]) /* Initialize howto table if needed */
1030 ppc_elf_howto_init ();
1032 BFD_ASSERT (ELF32_R_TYPE (dst
->r_info
) < (unsigned int) R_PPC_max
);
1033 cache_ptr
->howto
= ppc_elf_howto_table
[ELF32_R_TYPE (dst
->r_info
)];
1036 /* Function to set whether a module needs the -mrelocatable bit set. */
1039 ppc_elf_set_private_flags (abfd
, flags
)
1043 BFD_ASSERT (!elf_flags_init (abfd
)
1044 || elf_elfheader (abfd
)->e_flags
== flags
);
1046 elf_elfheader (abfd
)->e_flags
= flags
;
1047 elf_flags_init (abfd
) = true;
1051 /* Copy backend specific data from one object module to another */
1053 ppc_elf_copy_private_bfd_data (ibfd
, obfd
)
1057 /* This function is selected based on the input vector. We only
1058 want to copy information over if the output BFD also uses Elf
1060 if (bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
1063 BFD_ASSERT (!elf_flags_init (obfd
)
1064 || elf_elfheader (obfd
)->e_flags
== elf_elfheader (ibfd
)->e_flags
);
1066 elf_elfheader (obfd
)->e_flags
= elf_elfheader (ibfd
)->e_flags
;
1067 elf_flags_init (obfd
) = true;
1071 /* Merge backend specific data from an object file to the output
1072 object file when linking */
1074 ppc_elf_merge_private_bfd_data (ibfd
, obfd
)
1082 /* Check if we have the same endianess */
1083 if (ibfd
->xvec
->byteorder
!= obfd
->xvec
->byteorder
1084 && obfd
->xvec
->byteorder
!= BFD_ENDIAN_UNKNOWN
)
1086 (*_bfd_error_handler
)
1087 ("%s: compiled for a %s endian system and target is %s endian",
1088 bfd_get_filename (ibfd
),
1089 bfd_big_endian (ibfd
) ? "big" : "little",
1090 bfd_big_endian (obfd
) ? "big" : "little");
1092 bfd_set_error (bfd_error_wrong_format
);
1096 /* This function is selected based on the input vector. We only
1097 want to copy information over if the output BFD also uses Elf
1099 if (bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
1102 new_flags
= elf_elfheader (ibfd
)->e_flags
;
1103 old_flags
= elf_elfheader (obfd
)->e_flags
;
1104 if (!elf_flags_init (obfd
)) /* First call, no flags set */
1106 elf_flags_init (obfd
) = true;
1107 elf_elfheader (obfd
)->e_flags
= new_flags
;
1110 else if (new_flags
== old_flags
) /* Compatible flags are ok */
1113 else /* Incompatible flags */
1115 /* Warn about -mrelocatable mismatch. Allow -mrelocatable-lib to be linked
1118 if ((new_flags
& EF_PPC_RELOCATABLE
) != 0
1119 && (old_flags
& (EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
)) == 0)
1122 (*_bfd_error_handler
)
1123 ("%s: compiled with -mrelocatable and linked with modules compiled normally",
1124 bfd_get_filename (ibfd
));
1126 else if ((new_flags
& (EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
)) == 0
1127 && (old_flags
& EF_PPC_RELOCATABLE
) != 0)
1130 (*_bfd_error_handler
)
1131 ("%s: compiled normally and linked with modules compiled with -mrelocatable",
1132 bfd_get_filename (ibfd
));
1134 else if ((new_flags
& EF_PPC_RELOCATABLE_LIB
) != 0)
1135 elf_elfheader (obfd
)->e_flags
|= EF_PPC_RELOCATABLE_LIB
;
1137 new_flags
&= ~ (EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
);
1138 old_flags
&= ~ (EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
);
1140 /* Warn about eabi vs. V.4 mismatch */
1141 if ((new_flags
& EF_PPC_EMB
) != 0 && (old_flags
& EF_PPC_EMB
) == 0)
1143 new_flags
&= ~EF_PPC_EMB
;
1145 (*_bfd_error_handler
)
1146 ("%s: compiled for the eabi and linked with modules compiled for System V",
1147 bfd_get_filename (ibfd
));
1149 else if ((new_flags
& EF_PPC_EMB
) == 0 && (old_flags
& EF_PPC_EMB
) != 0)
1151 old_flags
&= ~EF_PPC_EMB
;
1153 (*_bfd_error_handler
)
1154 ("%s: compiled for System V and linked with modules compiled for eabi",
1155 bfd_get_filename (ibfd
));
1158 /* Warn about any other mismatches */
1159 if (new_flags
!= old_flags
)
1162 (*_bfd_error_handler
)
1163 ("%s: uses different e_flags (0x%lx) fields than previous modules (0x%lx)",
1164 bfd_get_filename (ibfd
), (long)new_flags
, (long)old_flags
);
1169 bfd_set_error (bfd_error_bad_value
);
1178 /* Handle a PowerPC specific section when reading an object file. This
1179 is called when elfcode.h finds a section with an unknown type. */
1182 ppc_elf_section_from_shdr (abfd
, hdr
, name
)
1184 Elf32_Internal_Shdr
*hdr
;
1190 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
))
1193 newsect
= hdr
->bfd_section
;
1194 flags
= bfd_get_section_flags (abfd
, newsect
);
1195 if (hdr
->sh_flags
& SHF_EXCLUDE
)
1196 flags
|= SEC_EXCLUDE
;
1198 if (hdr
->sh_type
== SHT_ORDERED
)
1199 flags
|= SEC_SORT_ENTRIES
;
1201 bfd_set_section_flags (abfd
, newsect
, flags
);
1206 /* Set up any other section flags and such that may be necessary. */
1209 ppc_elf_fake_sections (abfd
, shdr
, asect
)
1211 Elf32_Internal_Shdr
*shdr
;
1214 if ((asect
->flags
& SEC_EXCLUDE
) != 0)
1215 shdr
->sh_flags
|= SHF_EXCLUDE
;
1217 if ((asect
->flags
& SEC_SORT_ENTRIES
) != 0)
1218 shdr
->sh_type
= SHT_ORDERED
;
1222 /* Create a special linker section */
1223 static elf_linker_section_t
*
1224 ppc_elf_create_linker_section (abfd
, info
, which
)
1226 struct bfd_link_info
*info
;
1227 enum elf_linker_section_enum which
;
1229 bfd
*dynobj
= elf_hash_table (info
)->dynobj
;
1230 elf_linker_section_t
*lsect
;
1232 /* Record the first bfd section that needs the special section */
1234 dynobj
= elf_hash_table (info
)->dynobj
= abfd
;
1236 /* If this is the first time, create the section */
1237 lsect
= elf_linker_section (dynobj
, which
);
1240 elf_linker_section_t defaults
;
1241 static elf_linker_section_t zero_section
;
1243 defaults
= zero_section
;
1244 defaults
.which
= which
;
1245 defaults
.hole_written_p
= false;
1246 defaults
.alignment
= 2;
1247 defaults
.flags
= SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
;
1252 (*_bfd_error_handler
) ("%s: Unknown special linker type %d",
1253 bfd_get_filename (abfd
),
1256 bfd_set_error (bfd_error_bad_value
);
1257 return (elf_linker_section_t
*)0;
1259 case LINKER_SECTION_GOT
: /* .got section */
1260 defaults
.name
= ".got";
1261 defaults
.rel_name
= ".rela.got";
1262 defaults
.sym_name
= "_GLOBAL_OFFSET_TABLE_";
1263 defaults
.max_hole_offset
= 32764;
1264 defaults
.hole_size
= 16;
1265 defaults
.sym_offset
= 4;
1268 case LINKER_SECTION_SDATA
: /* .sdata/.sbss section */
1269 defaults
.name
= ".sdata";
1270 defaults
.rel_name
= ".rela.sdata";
1271 defaults
.bss_name
= ".sbss";
1272 defaults
.sym_name
= "_SDA_BASE_";
1275 case LINKER_SECTION_SDATA2
: /* .sdata2/.sbss2 section */
1276 defaults
.name
= ".sdata2";
1277 defaults
.rel_name
= ".rela.sdata2";
1278 defaults
.bss_name
= ".sbss2";
1279 defaults
.sym_name
= "_SDA2_BASE_";
1283 lsect
= _bfd_elf_create_linker_section (abfd
, info
, which
, &defaults
);
1290 /* Adjust a symbol defined by a dynamic object and referenced by a
1291 regular object. The current definition is in some section of the
1292 dynamic object, but we're not including those sections. We have to
1293 change the definition to something the rest of the link can
1297 ppc_elf_adjust_dynamic_symbol (info
, h
)
1298 struct bfd_link_info
*info
;
1299 struct elf_link_hash_entry
*h
;
1302 fprintf (stderr
, "ppc_elf_adjust_dynamic_symbol called\n");
1308 /* Increment the index of a dynamic symbol by a given amount. Called
1309 via elf_link_hash_traverse. */
1312 ppc_elf_adjust_dynindx (h
, cparg
)
1313 struct elf_link_hash_entry
*h
;
1316 int *cp
= (int *) cparg
;
1319 fprintf (stderr
, "ppc_elf_adjust_dynindx called, h->dynindx = %d, *cp = %d\n", h
->dynindx
, *cp
);
1322 if (h
->dynindx
!= -1)
1329 /* Set the sizes of the dynamic sections. */
1332 ppc_elf_size_dynamic_sections (output_bfd
, info
)
1334 struct bfd_link_info
*info
;
1342 fprintf (stderr
, "ppc_elf_size_dynamic_sections called\n");
1345 dynobj
= elf_hash_table (info
)->dynobj
;
1346 BFD_ASSERT (dynobj
!= NULL
);
1348 if (elf_hash_table (info
)->dynamic_sections_created
)
1350 /* Set the contents of the .interp section to the interpreter. */
1353 s
= bfd_get_section_by_name (dynobj
, ".interp");
1354 BFD_ASSERT (s
!= NULL
);
1355 s
->_raw_size
= sizeof ELF_DYNAMIC_INTERPRETER
;
1356 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
1359 /* Make space for the trailing nop in .plt. */
1360 s
= bfd_get_section_by_name (dynobj
, ".plt");
1361 BFD_ASSERT (s
!= NULL
);
1362 if (s
->_raw_size
> 0)
1367 /* We may have created entries in the .rela.got, .rela.sdata, and
1368 .rela.sdata2 section2. However, if we are not creating the
1369 dynamic sections, we will not actually use these entries. Reset
1370 the size of .rela.got, et al, which will cause it to get
1371 stripped from the output file below. */
1372 static char *rela_sections
[] = { ".rela.got", ".rela.sdata", ".rela.sdata", (char *)0 };
1375 for (p
= rela_sections
; *p
!= (char *)0; p
++)
1377 s
= bfd_get_section_by_name (dynobj
, *p
);
1383 /* The check_relocs and adjust_dynamic_symbol entry points have
1384 determined the sizes of the various dynamic sections. Allocate
1388 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
1393 if ((s
->flags
& SEC_IN_MEMORY
) == 0)
1396 /* It's OK to base decisions on the section name, because none
1397 of the dynobj section names depend upon the input files. */
1398 name
= bfd_get_section_name (dynobj
, s
);
1402 if (strncmp (name
, ".rela", 5) == 0)
1404 if (s
->_raw_size
== 0)
1406 /* If we don't need this section, strip it from the
1407 output file. This is to handle .rela.bss and
1408 .rel.plt. We must create it in
1409 create_dynamic_sections, because it must be created
1410 before the linker maps input sections to output
1411 sections. The linker does that before
1412 adjust_dynamic_symbol is called, and it is that
1413 function which decides whether anything needs to go
1414 into these sections. */
1421 /* If this relocation section applies to a read only
1422 section, then we probably need a DT_TEXTREL entry. */
1423 target
= bfd_get_section_by_name (output_bfd
, name
+ 5);
1425 && (target
->flags
& SEC_READONLY
) != 0)
1428 if (strcmp (name
, ".rela.plt") == 0)
1431 /* We use the reloc_count field as a counter if we need
1432 to copy relocs into the output file. */
1436 else if (strcmp (name
, ".plt") != 0
1437 && strcmp (name
, ".got") != 0)
1439 /* It's not one of our sections, so don't allocate space. */
1447 for (spp
= &s
->output_section
->owner
->sections
;
1448 *spp
!= s
->output_section
;
1449 spp
= &(*spp
)->next
)
1451 *spp
= s
->output_section
->next
;
1452 --s
->output_section
->owner
->section_count
;
1457 /* Allocate memory for the section contents. */
1458 s
->contents
= (bfd_byte
*) bfd_alloc (dynobj
, s
->_raw_size
);
1459 if (s
->contents
== NULL
&& s
->_raw_size
!= 0)
1463 if (elf_hash_table (info
)->dynamic_sections_created
)
1465 /* Add some entries to the .dynamic section. We fill in the
1466 values later, in ppc_elf_finish_dynamic_sections, but we
1467 must add the entries now so that we get the correct size for
1468 the .dynamic section. The DT_DEBUG entry is filled in by the
1469 dynamic linker and used by the debugger. */
1472 if (! bfd_elf32_add_dynamic_entry (info
, DT_DEBUG
, 0))
1476 if (! bfd_elf32_add_dynamic_entry (info
, DT_PLTGOT
, 0))
1481 if (! bfd_elf32_add_dynamic_entry (info
, DT_PLTRELSZ
, 0)
1482 || ! bfd_elf32_add_dynamic_entry (info
, DT_PLTREL
, DT_RELA
)
1483 || ! bfd_elf32_add_dynamic_entry (info
, DT_JMPREL
, 0))
1487 if (! bfd_elf32_add_dynamic_entry (info
, DT_RELA
, 0)
1488 || ! bfd_elf32_add_dynamic_entry (info
, DT_RELASZ
, 0)
1489 || ! bfd_elf32_add_dynamic_entry (info
, DT_RELAENT
,
1490 sizeof (Elf32_External_Rela
)))
1495 if (! bfd_elf32_add_dynamic_entry (info
, DT_TEXTREL
, 0))
1500 /* If we are generating a shared library, we generate a section
1501 symbol for each output section. These are local symbols, which
1502 means that they must come first in the dynamic symbol table.
1503 That means we must increment the dynamic symbol index of every
1504 other dynamic symbol. */
1509 c
= bfd_count_sections (output_bfd
);
1510 elf_link_hash_traverse (elf_hash_table (info
),
1511 ppc_elf_adjust_dynindx
,
1513 elf_hash_table (info
)->dynsymcount
+= c
;
1515 for (i
= 1, s
= output_bfd
->sections
; s
!= NULL
; s
= s
->next
, i
++)
1517 elf_section_data (s
)->dynindx
= i
;
1518 /* These symbols will have no names, so we don't need to
1519 fiddle with dynstr_index. */
1527 /* Look through the relocs for a section during the first phase, and
1528 allocate space in the global offset table or procedure linkage
1532 ppc_elf_check_relocs (abfd
, info
, sec
, relocs
)
1534 struct bfd_link_info
*info
;
1536 const Elf_Internal_Rela
*relocs
;
1539 Elf_Internal_Shdr
*symtab_hdr
;
1540 struct elf_link_hash_entry
**sym_hashes
;
1541 const Elf_Internal_Rela
*rel
;
1542 const Elf_Internal_Rela
*rel_end
;
1543 elf_linker_section_t
*got
;
1544 elf_linker_section_t
*sdata
;
1545 elf_linker_section_t
*sdata2
;
1548 if (info
->relocateable
)
1552 fprintf (stderr
, "ppc_elf_check_relocs called for section %s\n", sec
->name
);
1555 /* Create the linker generated sections all the time so that the special
1556 symbols are created. */
1557 if ((got
= elf_linker_section (abfd
, LINKER_SECTION_GOT
)) == NULL
)
1559 got
= ppc_elf_create_linker_section (abfd
, info
, LINKER_SECTION_GOT
);
1564 if ((sdata
= elf_linker_section (abfd
, LINKER_SECTION_SDATA
)) == NULL
)
1566 sdata
= ppc_elf_create_linker_section (abfd
, info
, LINKER_SECTION_SDATA
);
1572 if ((sdata2
= elf_linker_section (abfd
, LINKER_SECTION_SDATA2
)) == NULL
)
1574 sdata2
= ppc_elf_create_linker_section (abfd
, info
, LINKER_SECTION_SDATA2
);
1579 dynobj
= elf_hash_table (info
)->dynobj
;
1580 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
1581 sym_hashes
= elf_sym_hashes (abfd
);
1585 rel_end
= relocs
+ sec
->reloc_count
;
1586 for (rel
= relocs
; rel
< rel_end
; rel
++)
1588 unsigned long r_symndx
;
1589 struct elf_link_hash_entry
*h
;
1591 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1592 if (r_symndx
< symtab_hdr
->sh_info
)
1595 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1597 switch (ELF32_R_TYPE (rel
->r_info
))
1602 /* GOT16 relocations */
1604 case R_PPC_GOT16_LO
:
1605 case R_PPC_GOT16_HI
:
1606 case R_PPC_GOT16_HA
:
1607 if (got
->rel_section
== NULL
1608 && (h
!= NULL
|| info
->shared
)
1609 && !_bfd_elf_make_linker_section_rela (dynobj
, got
, 2))
1612 if (!bfd_elf32_create_pointer_linker_section (abfd
, info
, got
, h
, rel
))
1617 /* Indirect .sdata relocation */
1618 case R_PPC_EMB_SDAI16
:
1619 if (got
->rel_section
== NULL
1620 && (h
!= NULL
|| info
->shared
)
1621 && !_bfd_elf_make_linker_section_rela (dynobj
, got
, 2))
1624 BFD_ASSERT (!info
->shared
);
1625 if (!bfd_elf32_create_pointer_linker_section (abfd
, info
, sdata
, h
, rel
))
1630 /* Indirect .sdata2 relocation */
1631 case R_PPC_EMB_SDA2I16
:
1632 if (got
->rel_section
== NULL
1633 && (h
!= NULL
|| info
->shared
)
1634 && !_bfd_elf_make_linker_section_rela (dynobj
, got
, 2))
1637 BFD_ASSERT (!info
->shared
);
1638 if (!bfd_elf32_create_pointer_linker_section (abfd
, info
, sdata2
, h
, rel
))
1645 case R_PPC_PLTREL24
:
1646 case R_PPC_PLT16_LO
:
1647 case R_PPC_PLT16_HI
:
1648 case R_PPC_PLT16_HA
:
1650 fprintf (stderr
, "Reloc requires a PLT entry\n");
1652 /* This symbol requires a procedure linkage table entry. We
1653 actually build the entry in adjust_dynamic_symbol,
1654 because this might be a case of linking PIC code without
1655 linking in any dynamic objects, in which case we don't
1656 need to generate a procedure linkage table after all. */
1660 /* It does not make sense to have a procedure linkage
1661 table entry for a local symbol. */
1662 bfd_set_error (bfd_error_bad_value
);
1666 /* Make sure this symbol is output as a dynamic symbol. */
1667 if (h
->dynindx
== -1)
1669 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
1673 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
1679 && strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
1683 case R_SPARC_DISP16
:
1684 case R_SPARC_DISP32
:
1685 case R_SPARC_WDISP30
:
1686 case R_SPARC_WDISP22
:
1699 && (sec
->flags
& SEC_ALLOC
) != 0)
1701 /* When creating a shared object, we must copy these
1702 relocs into the output file. We create a reloc
1703 section in dynobj and make room for the reloc. */
1708 name
= (bfd_elf_string_from_elf_section
1710 elf_elfheader (abfd
)->e_shstrndx
,
1711 elf_section_data (sec
)->rel_hdr
.sh_name
));
1715 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
1716 && strcmp (bfd_get_section_name (abfd
, sec
),
1719 sreloc
= bfd_get_section_by_name (dynobj
, name
);
1722 sreloc
= bfd_make_section (dynobj
, name
);
1724 || ! bfd_set_section_flags (dynobj
, sreloc
,
1730 || ! bfd_set_section_alignment (dynobj
, sreloc
, 2))
1735 sreloc
->_raw_size
+= sizeof (Elf32_External_Rela
);
1747 /* Finish up dynamic symbol handling. We set the contents of various
1748 dynamic sections here. */
1751 ppc_elf_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
1753 struct bfd_link_info
*info
;
1754 struct elf_link_hash_entry
*h
;
1755 Elf_Internal_Sym
*sym
;
1758 elf_linker_section_t
*sdata
;
1759 elf_linker_section_t
*sdata2
;
1762 fprintf (stderr
, "ppc_elf_finish_dynamic_symbol called for %s\n", h
->root
.root
.string
);
1765 dynobj
= elf_hash_table (info
)->dynobj
;
1766 BFD_ASSERT (dynobj
!= NULL
);
1767 sdata
= elf_linker_section (dynobj
, LINKER_SECTION_SDATA
);
1768 sdata2
= elf_linker_section (dynobj
, LINKER_SECTION_SDATA2
);
1770 if (h
->plt_offset
!= (bfd_vma
) -1)
1774 Elf_Internal_Rela rela
;
1776 /* This symbol has an entry in the procedure linkage table. Set
1779 BFD_ASSERT (h
->dynindx
!= -1);
1781 splt
= bfd_get_section_by_name (dynobj
, ".plt");
1782 srela
= bfd_get_section_by_name (dynobj
, ".rela.plt");
1783 BFD_ASSERT (splt
!= NULL
&& srela
!= NULL
);
1785 /* Fill in the entry in the procedure linkage table. */
1787 bfd_put_32 (output_bfd
,
1788 PLT_ENTRY_WORD0
+ h
->plt_offset
,
1789 splt
->contents
+ h
->plt_offset
);
1790 bfd_put_32 (output_bfd
,
1792 + (((- (h
->plt_offset
+ 4)) >> 2) & 0x3fffff)),
1793 splt
->contents
+ h
->plt_offset
+ 4);
1794 bfd_put_32 (output_bfd
, PLT_ENTRY_WORD2
,
1795 splt
->contents
+ h
->plt_offset
+ 8);
1797 /* Fill in the entry in the .rela.plt section. */
1798 rela
.r_offset
= (splt
->output_section
->vma
1799 + splt
->output_offset
1801 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_SPARC_JMP_SLOT
);
1803 bfd_elf32_swap_reloca_out (output_bfd
, &rela
,
1804 ((Elf32_External_Rela
*) srela
->contents
1805 + h
->plt_offset
/ PLT_ENTRY_SIZE
- 4));
1808 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
1810 /* Mark the symbol as undefined, rather than as defined in
1811 the .plt section. Leave the value alone. */
1812 sym
->st_shndx
= SHN_UNDEF
;
1816 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_COPY
) != 0)
1819 Elf_Internal_Rela rela
;
1821 /* This symbols needs a copy reloc. Set it up. */
1823 BFD_ASSERT (h
->dynindx
!= -1);
1825 s
= bfd_get_section_by_name (h
->root
.u
.def
.section
->owner
,
1827 BFD_ASSERT (s
!= NULL
);
1829 rela
.r_offset
= (h
->root
.u
.def
.value
1830 + h
->root
.u
.def
.section
->output_section
->vma
1831 + h
->root
.u
.def
.section
->output_offset
);
1832 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_PPC_COPY
);
1834 bfd_elf32_swap_reloca_out (output_bfd
, &rela
,
1835 ((Elf32_External_Rela
*) s
->contents
1840 /* Mark some specially defined symbols as absolute. */
1841 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
1842 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0
1843 || strcmp (h
->root
.root
.string
, "_PROCEDURE_LINKAGE_TABLE_") == 0)
1844 sym
->st_shndx
= SHN_ABS
;
1846 /* If .sdata is larger than 32767, bump up _SDA_BASE_ by 32768 so that
1847 we put off getting relocation overflows until it is > 65k. Do the
1848 same for .sdata2 and _SDA2_BASE_. */
1849 if (sdata
&& sdata
->sym_hash
== h
1850 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DYNAMIC_ADJUSTED
) == 0)
1853 asection
*s
= bfd_get_section_by_name (output_bfd
, ".sdata");
1855 size
= s
->_raw_size
;
1857 s
= bfd_get_section_by_name (output_bfd
, ".sbss");
1859 size
+= s
->_raw_size
;
1862 h
->root
.u
.def
.value
+= 32768;
1864 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DYNAMIC_ADJUSTED
;
1867 if (sdata2
&& sdata2
->sym_hash
== h
1868 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DYNAMIC_ADJUSTED
) == 0)
1871 asection
*s
= bfd_get_section_by_name (output_bfd
, ".sdata2");
1873 size
= s
->_raw_size
;
1875 s
= bfd_get_section_by_name (output_bfd
, ".sbss2");
1877 size
+= s
->_raw_size
;
1880 h
->root
.u
.def
.value
+= 32768;
1882 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DYNAMIC_ADJUSTED
;
1889 /* Finish up the dynamic sections. */
1892 ppc_elf_finish_dynamic_sections (output_bfd
, info
)
1894 struct bfd_link_info
*info
;
1897 bfd
*dynobj
= elf_hash_table (info
)->dynobj
;
1898 elf_linker_section_t
*got
= elf_linker_section (dynobj
, LINKER_SECTION_GOT
);
1901 fprintf (stderr
, "ppc_elf_finish_dynamic_sections called\n");
1904 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
1906 if (elf_hash_table (info
)->dynamic_sections_created
)
1909 Elf32_External_Dyn
*dyncon
, *dynconend
;
1911 splt
= bfd_get_section_by_name (dynobj
, ".plt");
1912 BFD_ASSERT (splt
!= NULL
&& sdyn
!= NULL
);
1914 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
1915 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
1916 for (; dyncon
< dynconend
; dyncon
++)
1918 Elf_Internal_Dyn dyn
;
1922 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
1926 case DT_PLTGOT
: name
= ".plt"; size
= false; break;
1927 case DT_PLTRELSZ
: name
= ".rela.plt"; size
= true; break;
1928 case DT_JMPREL
: name
= ".rela.plt"; size
= false; break;
1929 default: name
= NULL
; size
= false; break;
1936 s
= bfd_get_section_by_name (output_bfd
, name
);
1942 dyn
.d_un
.d_ptr
= s
->vma
;
1945 if (s
->_cooked_size
!= 0)
1946 dyn
.d_un
.d_val
= s
->_cooked_size
;
1948 dyn
.d_un
.d_val
= s
->_raw_size
;
1951 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
1956 /* Add a blrl instruction at _GLOBAL_OFFSET_TABLE_-4 so that a function can
1957 easily find the address of the _GLOBAL_OFFSET_TABLE_. */
1960 unsigned char *contents
= got
->section
->contents
+ got
->hole_offset
;
1961 bfd_put_32 (output_bfd
, 0x4e800021 /* blrl */, contents
);
1964 bfd_put_32 (output_bfd
, (bfd_vma
) 0, contents
+4);
1966 bfd_put_32 (output_bfd
,
1967 sdyn
->output_section
->vma
+ sdyn
->output_offset
,
1970 elf_section_data (got
->section
->output_section
)->this_hdr
.sh_entsize
= 4;
1977 Elf_Internal_Sym sym
;
1979 /* Set up the section symbols for the output sections. */
1981 sdynsym
= bfd_get_section_by_name (dynobj
, ".dynsym");
1982 BFD_ASSERT (sdynsym
!= NULL
);
1986 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_SECTION
);
1989 for (s
= output_bfd
->sections
; s
!= NULL
; s
= s
->next
)
1993 sym
.st_value
= s
->vma
;
1995 indx
= elf_section_data (s
)->this_idx
;
1996 BFD_ASSERT (indx
> 0);
1997 sym
.st_shndx
= indx
;
1999 bfd_elf32_swap_symbol_out (output_bfd
, &sym
,
2000 (PTR
) (((Elf32_External_Sym
*)
2002 + elf_section_data (s
)->dynindx
));
2005 /* Set the sh_info field of the output .dynsym section to the
2006 index of the first global symbol. */
2007 elf_section_data (sdynsym
->output_section
)->this_hdr
.sh_info
=
2008 bfd_count_sections (output_bfd
) + 1;
2015 /* The RELOCATE_SECTION function is called by the ELF backend linker
2016 to handle the relocations for a section.
2018 The relocs are always passed as Rela structures; if the section
2019 actually uses Rel structures, the r_addend field will always be
2022 This function is responsible for adjust the section contents as
2023 necessary, and (if using Rela relocs and generating a
2024 relocateable output file) adjusting the reloc addend as
2027 This function does not have to worry about setting the reloc
2028 address or the reloc symbol index.
2030 LOCAL_SYMS is a pointer to the swapped in local symbols.
2032 LOCAL_SECTIONS is an array giving the section in the input file
2033 corresponding to the st_shndx field of each local symbol.
2035 The global hash table entry for the global symbols can be found
2036 via elf_sym_hashes (input_bfd).
2038 When generating relocateable output, this function must handle
2039 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
2040 going to be the section symbol corresponding to the output
2041 section, which means that the addend must be adjusted
2045 ppc_elf_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
2046 contents
, relocs
, local_syms
, local_sections
)
2048 struct bfd_link_info
*info
;
2050 asection
*input_section
;
2052 Elf_Internal_Rela
*relocs
;
2053 Elf_Internal_Sym
*local_syms
;
2054 asection
**local_sections
;
2056 Elf_Internal_Shdr
*symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
2057 struct elf_link_hash_entry
**sym_hashes
= elf_sym_hashes (input_bfd
);
2058 bfd
*dynobj
= elf_hash_table (info
)->dynobj
;
2059 elf_linker_section_t
*got
= elf_linker_section (dynobj
, LINKER_SECTION_GOT
);
2060 elf_linker_section_t
*sdata
= elf_linker_section (dynobj
, LINKER_SECTION_SDATA
);
2061 elf_linker_section_t
*sdata2
= elf_linker_section (dynobj
, LINKER_SECTION_SDATA2
);
2062 Elf_Internal_Rela
*rel
= relocs
;
2063 Elf_Internal_Rela
*relend
= relocs
+ input_section
->reloc_count
;
2068 fprintf (stderr
, "ppc_elf_relocate_section called for %s section %s, %ld relocations%s\n",
2069 bfd_get_filename (input_bfd
),
2070 bfd_section_name(input_bfd
, input_section
),
2071 (long)input_section
->reloc_count
,
2072 (info
->relocateable
) ? " (relocatable)" : "");
2075 if (!ppc_elf_howto_table
[ R_PPC_ADDR32
]) /* Initialize howto table if needed */
2076 ppc_elf_howto_init ();
2078 for (; rel
< relend
; rel
++)
2080 enum ppc_reloc_type r_type
= (enum ppc_reloc_type
)ELF32_R_TYPE (rel
->r_info
);
2081 bfd_vma offset
= rel
->r_offset
;
2082 bfd_vma addend
= rel
->r_addend
;
2083 bfd_reloc_status_type r
= bfd_reloc_other
;
2084 Elf_Internal_Sym
*sym
= (Elf_Internal_Sym
*)0;
2085 asection
*sec
= (asection
*)0;
2086 struct elf_link_hash_entry
*h
= (struct elf_link_hash_entry
*)0;
2087 reloc_howto_type
*howto
;
2088 unsigned long r_symndx
;
2091 /* Unknown relocation handling */
2092 if ((unsigned)r_type
>= (unsigned)R_PPC_max
|| !ppc_elf_howto_table
[(int)r_type
])
2094 (*_bfd_error_handler
) ("%s: unknown relocation type %d",
2095 bfd_get_filename (input_bfd
),
2098 bfd_set_error (bfd_error_bad_value
);
2103 howto
= ppc_elf_howto_table
[(int)r_type
];
2104 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2106 if (info
->relocateable
)
2108 /* This is a relocateable link. We don't have to change
2109 anything, unless the reloc is against a section symbol,
2110 in which case we have to adjust according to where the
2111 section symbol winds up in the output section. */
2112 if (r_symndx
< symtab_hdr
->sh_info
)
2114 sym
= local_syms
+ r_symndx
;
2115 if ((unsigned)ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
2117 sec
= local_sections
[r_symndx
];
2118 addend
= rel
->r_addend
+= sec
->output_offset
+ sym
->st_value
;
2123 fprintf (stderr
, "\ttype = %s (%d), symbol index = %ld, offset = %ld, addend = %ld\n",
2133 /* This is a final link. */
2134 if (r_symndx
< symtab_hdr
->sh_info
)
2136 sym
= local_syms
+ r_symndx
;
2137 sec
= local_sections
[r_symndx
];
2138 relocation
= (sec
->output_section
->vma
2139 + sec
->output_offset
2144 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2145 if (h
->root
.type
== bfd_link_hash_defined
2146 || h
->root
.type
== bfd_link_hash_defweak
)
2148 sec
= h
->root
.u
.def
.section
;
2149 relocation
= (h
->root
.u
.def
.value
2150 + sec
->output_section
->vma
2151 + sec
->output_offset
);
2153 else if (h
->root
.type
== bfd_link_hash_undefweak
)
2155 else if (info
->shared
)
2159 (*info
->callbacks
->undefined_symbol
)(info
,
2160 h
->root
.root
.string
,
2169 switch ((int)r_type
)
2172 (*_bfd_error_handler
) ("%s: unknown relocation type %d",
2173 bfd_get_filename (input_bfd
),
2176 bfd_set_error (bfd_error_bad_value
);
2180 /* relocations that need no special processing */
2181 case (int)R_PPC_NONE
:
2182 case (int)R_PPC_ADDR32
:
2183 case (int)R_PPC_ADDR24
:
2184 case (int)R_PPC_ADDR16
:
2185 case (int)R_PPC_ADDR16_LO
:
2186 case (int)R_PPC_ADDR16_HI
:
2187 case (int)R_PPC_ADDR14
:
2188 case (int)R_PPC_REL24
:
2189 case (int)R_PPC_REL14
:
2190 case (int)R_PPC_UADDR32
:
2191 case (int)R_PPC_UADDR16
:
2192 case (int)R_PPC_REL32
:
2195 /* branch taken prediction relocations */
2196 case (int)R_PPC_ADDR14_BRTAKEN
:
2197 case (int)R_PPC_REL14_BRTAKEN
:
2198 insn
= bfd_get_32 (output_bfd
, contents
+ offset
);
2199 if ((relocation
- offset
) & 0x8000)
2200 insn
&= ~BRANCH_PREDICT_BIT
;
2202 insn
|= BRANCH_PREDICT_BIT
;
2203 bfd_put_32 (output_bfd
, insn
, contents
+ offset
);
2206 /* branch not taken predicition relocations */
2207 case (int)R_PPC_ADDR14_BRNTAKEN
:
2208 case (int)R_PPC_REL14_BRNTAKEN
:
2209 insn
= bfd_get_32 (output_bfd
, contents
+ offset
);
2210 if ((relocation
- offset
) & 0x8000)
2211 insn
|= BRANCH_PREDICT_BIT
;
2213 insn
&= ~BRANCH_PREDICT_BIT
;
2214 bfd_put_32 (output_bfd
, insn
, contents
+ offset
);
2217 /* GOT16 relocations */
2218 case (int)R_PPC_GOT16
:
2219 case (int)R_PPC_GOT16_LO
:
2220 case (int)R_PPC_GOT16_HI
:
2221 case (int)R_PPC_GOT16_HA
:
2222 relocation
= bfd_elf32_finish_pointer_linker_section (output_bfd
, input_bfd
, info
,
2223 got
, h
, relocation
, rel
,
2227 /* Indirect .sdata relocation */
2228 case (int)R_PPC_EMB_SDAI16
:
2229 BFD_ASSERT (sdata
!= NULL
);
2230 relocation
= bfd_elf32_finish_pointer_linker_section (output_bfd
, input_bfd
, info
,
2231 sdata
, h
, relocation
, rel
,
2235 /* Indirect .sdata2 relocation */
2236 case (int)R_PPC_EMB_SDA2I16
:
2237 BFD_ASSERT (sdata2
!= NULL
);
2238 relocation
= bfd_elf32_finish_pointer_linker_section (output_bfd
, input_bfd
, info
,
2239 sdata2
, h
, relocation
, rel
,
2243 /* Handle the TOC16 reloc. We want to use the offset within the .got
2244 section, not the actual VMA. This is appropriate when generating
2245 an embedded ELF object, for which the .got section acts like the
2246 AIX .toc section. */
2247 case (int)R_PPC_TOC16
: /* phony GOT16 relocations */
2248 BFD_ASSERT (sec
!= (asection
*)0);
2249 BFD_ASSERT (bfd_is_und_section (sec
)
2250 || strcmp (bfd_get_section_name (abfd
, sec
), ".got") == 0
2251 || strcmp (bfd_get_section_name (abfd
, sec
), ".cgot") == 0)
2253 addend
-= sec
->output_section
->vma
+ 0x8000;
2256 /* arithmetic adjust relocations */
2257 case (int)R_PPC_ADDR16_HA
:
2258 BFD_ASSERT (sec
!= (asection
*)0);
2259 addend
+= ((relocation
+ addend
) & 0x8000) << 1;
2262 /* relocate against _SDA_BASE_ */
2263 case (int)R_PPC_SDAREL16
:
2264 BFD_ASSERT (sec
!= (asection
*)0);
2265 if (strcmp (bfd_get_section_name (abfd
, sec
), ".sdata") != 0
2266 && strcmp (bfd_get_section_name (abfd
, sec
), ".sbss") != 0)
2268 (*_bfd_error_handler
) ("%s: The target of a %s relocation is in the wrong section (%s)",
2269 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 relocation
= (sdata
->sym_hash
->root
.u
.def
.value
2278 + sdata
->sym_hash
->root
.u
.def
.section
->output_section
->vma
2282 /* relocate against _SDA2_BASE_ */
2283 case (int)R_PPC_EMB_SDA2REL
:
2284 BFD_ASSERT (sec
!= (asection
*)0);
2285 if (strcmp (bfd_get_section_name (abfd
, sec
), ".sdata2") != 0
2286 && strcmp (bfd_get_section_name (abfd
, sec
), ".sbss2") != 0)
2288 (*_bfd_error_handler
) ("%s: The target of a %s relocation is in the wrong section (%s)",
2289 bfd_get_filename (input_bfd
),
2290 ppc_elf_howto_table
[ (int)r_type
]->name
,
2291 bfd_get_section_name (abfd
, sec
));
2293 bfd_set_error (bfd_error_bad_value
);
2297 relocation
= (sdata
->sym_hash
->root
.u
.def
.value
2298 + sdata
->sym_hash
->root
.u
.def
.section
->output_section
->vma
2303 /* relocate against either _SDA_BASE_, _SDA2_BASE_, or 0 */
2304 case (int)R_PPC_EMB_SDA21
:
2305 case (int)R_PPC_EMB_RELSDA
:
2307 const char *name
= bfd_get_section_name (abfd
, sec
);
2310 BFD_ASSERT (sec
!= (asection
*)0);
2311 if (strcmp (name
, ".sdata") == 0 || strcmp (name
, ".sbss") == 0)
2314 relocation
= (sdata2
->sym_hash
->root
.u
.def
.value
2315 + sdata2
->sym_hash
->root
.u
.def
.section
->output_section
->vma
2319 else if (strcmp (name
, ".sdata2") == 0 || strcmp (name
, ".sbss2") == 0)
2322 relocation
= (sdata2
->sym_hash
->root
.u
.def
.value
2323 + sdata2
->sym_hash
->root
.u
.def
.section
->output_section
->vma
2327 else if (strcmp (name
, ".PPC.EMB.sdata0") == 0 || strcmp (name
, ".PPC.EMB.sbss0") == 0)
2334 (*_bfd_error_handler
) ("%s: The target of a %s relocation is in the wrong section (%s)",
2335 bfd_get_filename (input_bfd
),
2336 ppc_elf_howto_table
[ (int)r_type
]->name
,
2337 bfd_get_section_name (abfd
, sec
));
2339 bfd_set_error (bfd_error_bad_value
);
2346 case (int)R_PPC_PLTREL24
:
2347 case (int)R_PPC_COPY
:
2348 case (int)R_PPC_GLOB_DAT
:
2349 case (int)R_PPC_JMP_SLOT
:
2350 case (int)R_PPC_RELATIVE
:
2351 case (int)R_PPC_LOCAL24PC
:
2352 case (int)R_PPC_PLT32
:
2353 case (int)R_PPC_PLTREL32
:
2354 case (int)R_PPC_PLT16_LO
:
2355 case (int)R_PPC_PLT16_HI
:
2356 case (int)R_PPC_PLT16_HA
:
2357 case (int)R_PPC_SECTOFF
:
2358 case (int)R_PPC_SECTOFF_LO
:
2359 case (int)R_PPC_SECTOFF_HI
:
2360 case (int)R_PPC_SECTOFF_HA
:
2361 case (int)R_PPC_EMB_NADDR32
:
2362 case (int)R_PPC_EMB_NADDR16
:
2363 case (int)R_PPC_EMB_NADDR16_LO
:
2364 case (int)R_PPC_EMB_NADDR16_HI
:
2365 case (int)R_PPC_EMB_NADDR16_HA
:
2366 case (int)R_PPC_EMB_MRKREF
:
2367 case (int)R_PPC_EMB_RELSEC16
:
2368 case (int)R_PPC_EMB_RELST_LO
:
2369 case (int)R_PPC_EMB_RELST_HI
:
2370 case (int)R_PPC_EMB_RELST_HA
:
2371 case (int)R_PPC_EMB_BIT_FLD
:
2373 (*_bfd_error_handler
) ("%s: Relocation %s is not yet supported.",
2374 bfd_get_filename (input_bfd
),
2375 ppc_elf_howto_table
[ (int)r_type
]->name
);
2377 bfd_set_error (bfd_error_invalid_operation
);
2384 fprintf (stderr
, "\ttype = %s (%d), symbol index = %ld, offset = %ld, addend = %ld\n",
2392 r
= _bfd_final_link_relocate (howto
,
2400 if (r
!= bfd_reloc_ok
)
2408 case bfd_reloc_overflow
:
2413 name
= h
->root
.root
.string
;
2416 name
= bfd_elf_string_from_elf_section (input_bfd
,
2417 symtab_hdr
->sh_link
,
2423 name
= bfd_section_name (input_bfd
, sec
);
2426 (*info
->callbacks
->reloc_overflow
)(info
,
2442 fprintf (stderr
, "\n");
2449 #define TARGET_LITTLE_SYM bfd_elf32_powerpcle_vec
2450 #define TARGET_LITTLE_NAME "elf32-powerpcle"
2451 #define TARGET_BIG_SYM bfd_elf32_powerpc_vec
2452 #define TARGET_BIG_NAME "elf32-powerpc"
2453 #define ELF_ARCH bfd_arch_powerpc
2454 #define ELF_MACHINE_CODE EM_PPC
2455 #define ELF_MAXPAGESIZE 0x10000
2456 #define elf_info_to_howto ppc_elf_info_to_howto
2458 #ifdef EM_CYGNUS_POWERPC
2459 #define ELF_MACHINE_ALT1 EM_CYGNUS_POWERPC
2463 #define ELF_MACHINE_ALT2 EM_PPC_OLD
2466 #define bfd_elf32_bfd_copy_private_bfd_data ppc_elf_copy_private_bfd_data
2467 #define bfd_elf32_bfd_merge_private_bfd_data ppc_elf_merge_private_bfd_data
2468 #define bfd_elf32_bfd_set_private_flags ppc_elf_set_private_flags
2469 #define bfd_elf32_bfd_reloc_type_lookup ppc_elf_reloc_type_lookup
2470 #define elf_backend_section_from_shdr ppc_elf_section_from_shdr
2471 #define elf_backend_relocate_section ppc_elf_relocate_section
2472 #define elf_backend_create_dynamic_sections _bfd_elf_create_dynamic_sections
2473 #define elf_backend_check_relocs ppc_elf_check_relocs
2474 #define elf_backend_adjust_dynamic_symbol ppc_elf_adjust_dynamic_symbol
2475 #define elf_backend_size_dynamic_sections ppc_elf_size_dynamic_sections
2476 #define elf_backend_finish_dynamic_symbol ppc_elf_finish_dynamic_symbol
2477 #define elf_backend_finish_dynamic_sections ppc_elf_finish_dynamic_sections
2478 #define elf_backend_fake_sections ppc_elf_fake_sections
2480 #include "elf32-target.h"