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 bfd
*ppc_elf_create_dynamic_sections
PARAMS ((bfd
*abfd
,
116 struct bfd_link_info
*info
));
118 static boolean ppc_elf_check_relocs
PARAMS ((bfd
*,
119 struct bfd_link_info
*,
121 const Elf_Internal_Rela
*));
123 static boolean ppc_elf_adjust_dynamic_symbol
PARAMS ((struct bfd_link_info
*,
124 struct elf_link_hash_entry
*));
126 static boolean ppc_elf_adjust_dynindx
PARAMS ((struct elf_link_hash_entry
*, PTR
));
128 static boolean ppc_elf_size_dynamic_sections
PARAMS ((bfd
*, struct bfd_link_info
*));
130 static boolean ppc_elf_relocate_section
PARAMS ((bfd
*,
131 struct bfd_link_info
*info
,
135 Elf_Internal_Rela
*relocs
,
136 Elf_Internal_Sym
*local_syms
,
139 static boolean ppc_elf_finish_dynamic_symbol
PARAMS ((bfd
*,
140 struct bfd_link_info
*,
141 struct elf_link_hash_entry
*,
142 Elf_Internal_Sym
*));
144 static boolean ppc_elf_finish_dynamic_sections
PARAMS ((bfd
*, struct bfd_link_info
*));
146 #define BRANCH_PREDICT_BIT 0x200000
148 /* The name of the dynamic interpreter. This is put in the .interp
151 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
154 static reloc_howto_type
*ppc_elf_howto_table
[ (int)R_PPC_max
];
156 static reloc_howto_type ppc_elf_howto_raw
[] =
158 /* This reloc does nothing. */
159 HOWTO (R_PPC_NONE
, /* type */
161 2, /* size (0 = byte, 1 = short, 2 = long) */
163 false, /* pc_relative */
165 complain_overflow_bitfield
, /* complain_on_overflow */
166 bfd_elf_generic_reloc
, /* special_function */
167 "R_PPC_NONE", /* name */
168 false, /* partial_inplace */
171 false), /* pcrel_offset */
173 /* A standard 32 bit relocation. */
174 HOWTO (R_PPC_ADDR32
, /* type */
176 2, /* size (0 = byte, 1 = short, 2 = long) */
178 false, /* pc_relative */
180 complain_overflow_bitfield
, /* complain_on_overflow */
181 bfd_elf_generic_reloc
, /* special_function */
182 "R_PPC_ADDR32", /* name */
183 false, /* partial_inplace */
185 0xffffffff, /* dst_mask */
186 false), /* pcrel_offset */
188 /* An absolute 26 bit branch; the lower two bits must be zero.
189 FIXME: we don't check that, we just clear them. */
190 HOWTO (R_PPC_ADDR24
, /* type */
192 2, /* size (0 = byte, 1 = short, 2 = long) */
194 false, /* pc_relative */
196 complain_overflow_bitfield
, /* complain_on_overflow */
197 bfd_elf_generic_reloc
, /* special_function */
198 "R_PPC_ADDR24", /* name */
199 false, /* partial_inplace */
201 0x3fffffc, /* dst_mask */
202 false), /* pcrel_offset */
204 /* A standard 16 bit relocation. */
205 HOWTO (R_PPC_ADDR16
, /* type */
207 1, /* size (0 = byte, 1 = short, 2 = long) */
209 false, /* pc_relative */
211 complain_overflow_bitfield
, /* complain_on_overflow */
212 bfd_elf_generic_reloc
, /* special_function */
213 "R_PPC_ADDR16", /* name */
214 false, /* partial_inplace */
216 0xffff, /* dst_mask */
217 false), /* pcrel_offset */
219 /* A 16 bit relocation without overflow. */
220 HOWTO (R_PPC_ADDR16_LO
, /* type */
222 1, /* size (0 = byte, 1 = short, 2 = long) */
224 false, /* pc_relative */
226 complain_overflow_dont
,/* complain_on_overflow */
227 bfd_elf_generic_reloc
, /* special_function */
228 "R_PPC_ADDR16_LO", /* name */
229 false, /* partial_inplace */
231 0xffff, /* dst_mask */
232 false), /* pcrel_offset */
234 /* The high order 16 bits of an address. */
235 HOWTO (R_PPC_ADDR16_HI
, /* type */
237 1, /* size (0 = byte, 1 = short, 2 = long) */
239 false, /* pc_relative */
241 complain_overflow_dont
, /* complain_on_overflow */
242 bfd_elf_generic_reloc
, /* special_function */
243 "R_PPC_ADDR16_HI", /* name */
244 false, /* partial_inplace */
246 0xffff, /* dst_mask */
247 false), /* pcrel_offset */
249 /* The high order 16 bits of an address, plus 1 if the contents of
250 the low 16 bits, treated as a signed number, is negative. */
251 HOWTO (R_PPC_ADDR16_HA
, /* type */
253 1, /* size (0 = byte, 1 = short, 2 = long) */
255 false, /* pc_relative */
257 complain_overflow_dont
, /* complain_on_overflow */
258 bfd_elf_generic_reloc
, /* special_function */
259 "R_PPC_ADDR16_HA", /* name */
260 false, /* partial_inplace */
262 0xffff, /* dst_mask */
263 false), /* pcrel_offset */
265 /* An absolute 16 bit branch; the lower two bits must be zero.
266 FIXME: we don't check that, we just clear them. */
267 HOWTO (R_PPC_ADDR14
, /* type */
269 2, /* size (0 = byte, 1 = short, 2 = long) */
271 false, /* pc_relative */
273 complain_overflow_bitfield
, /* complain_on_overflow */
274 bfd_elf_generic_reloc
, /* special_function */
275 "R_PPC_ADDR14", /* name */
276 false, /* partial_inplace */
278 0xfffc, /* dst_mask */
279 false), /* pcrel_offset */
281 /* An absolute 16 bit branch, for which bit 10 should be set to
282 indicate that the branch is expected to be taken. The lower two
283 bits must be zero. */
284 HOWTO (R_PPC_ADDR14_BRTAKEN
, /* type */
286 2, /* size (0 = byte, 1 = short, 2 = long) */
288 false, /* pc_relative */
290 complain_overflow_bitfield
, /* complain_on_overflow */
291 bfd_elf_generic_reloc
, /* special_function */
292 "R_PPC_ADDR14_BRTAKEN",/* name */
293 false, /* partial_inplace */
295 0xfffc, /* dst_mask */
296 false), /* pcrel_offset */
298 /* An absolute 16 bit branch, for which bit 10 should be set to
299 indicate that the branch is not expected to be taken. The lower
300 two bits must be zero. */
301 HOWTO (R_PPC_ADDR14_BRNTAKEN
, /* type */
303 2, /* size (0 = byte, 1 = short, 2 = long) */
305 false, /* pc_relative */
307 complain_overflow_bitfield
, /* complain_on_overflow */
308 bfd_elf_generic_reloc
, /* special_function */
309 "R_PPC_ADDR14_BRNTAKEN",/* name */
310 false, /* partial_inplace */
312 0xfffc, /* dst_mask */
313 false), /* pcrel_offset */
315 /* A relative 26 bit branch; the lower two bits must be zero. */
316 HOWTO (R_PPC_REL24
, /* type */
318 2, /* size (0 = byte, 1 = short, 2 = long) */
320 true, /* pc_relative */
322 complain_overflow_signed
, /* complain_on_overflow */
323 bfd_elf_generic_reloc
, /* special_function */
324 "R_PPC_REL24", /* name */
325 false, /* partial_inplace */
327 0x3fffffc, /* dst_mask */
328 true), /* pcrel_offset */
330 /* A relative 16 bit branch; the lower two bits must be zero. */
331 HOWTO (R_PPC_REL14
, /* type */
333 2, /* size (0 = byte, 1 = short, 2 = long) */
335 true, /* pc_relative */
337 complain_overflow_signed
, /* complain_on_overflow */
338 bfd_elf_generic_reloc
, /* special_function */
339 "R_PPC_REL14", /* name */
340 false, /* partial_inplace */
342 0xfffc, /* dst_mask */
343 true), /* pcrel_offset */
345 /* A relative 16 bit branch. Bit 10 should be set to indicate that
346 the branch is expected to be taken. The lower two bits must be
348 HOWTO (R_PPC_REL14_BRTAKEN
, /* type */
350 2, /* size (0 = byte, 1 = short, 2 = long) */
352 true, /* pc_relative */
354 complain_overflow_signed
, /* complain_on_overflow */
355 bfd_elf_generic_reloc
, /* special_function */
356 "R_PPC_REL14_BRTAKEN", /* name */
357 false, /* partial_inplace */
359 0xfffc, /* dst_mask */
360 true), /* pcrel_offset */
362 /* A relative 16 bit branch. Bit 10 should be set to indicate that
363 the branch is not expected to be taken. The lower two bits must
365 HOWTO (R_PPC_REL14_BRNTAKEN
, /* type */
367 2, /* size (0 = byte, 1 = short, 2 = long) */
369 true, /* pc_relative */
371 complain_overflow_signed
, /* complain_on_overflow */
372 bfd_elf_generic_reloc
, /* special_function */
373 "R_PPC_REL14_BRNTAKEN",/* name */
374 false, /* partial_inplace */
376 0xfffc, /* dst_mask */
377 true), /* pcrel_offset */
379 /* Like R_PPC_ADDR16, but referring to the GOT table entry for the
381 HOWTO (R_PPC_GOT16
, /* type */
383 1, /* size (0 = byte, 1 = short, 2 = long) */
385 false, /* pc_relative */
387 complain_overflow_signed
, /* complain_on_overflow */
388 bfd_elf_generic_reloc
, /* special_function */
389 "R_PPC_GOT16", /* name */
390 false, /* partial_inplace */
392 0xffff, /* dst_mask */
393 false), /* pcrel_offset */
395 /* Like R_PPC_ADDR16_LO, but referring to the GOT table entry for
397 HOWTO (R_PPC_GOT16_LO
, /* type */
399 1, /* size (0 = byte, 1 = short, 2 = long) */
401 false, /* pc_relative */
403 complain_overflow_bitfield
, /* complain_on_overflow */
404 bfd_elf_generic_reloc
, /* special_function */
405 "R_PPC_GOT16_LO", /* name */
406 false, /* partial_inplace */
408 0xffff, /* dst_mask */
409 false), /* pcrel_offset */
411 /* Like R_PPC_ADDR16_HI, but referring to the GOT table entry for
413 HOWTO (R_PPC_GOT16_HI
, /* type */
415 1, /* size (0 = byte, 1 = short, 2 = long) */
417 false, /* pc_relative */
419 complain_overflow_bitfield
, /* complain_on_overflow */
420 bfd_elf_generic_reloc
, /* special_function */
421 "R_PPC_GOT16_HI", /* name */
422 false, /* partial_inplace */
424 0xffff, /* dst_mask */
425 false), /* pcrel_offset */
427 /* Like R_PPC_ADDR16_HA, but referring to the GOT table entry for
428 the symbol. FIXME: Not supported. */
429 HOWTO (R_PPC_GOT16_HA
, /* type */
431 1, /* size (0 = byte, 1 = short, 2 = long) */
433 false, /* pc_relative */
435 complain_overflow_bitfield
, /* complain_on_overflow */
436 bfd_elf_generic_reloc
, /* special_function */
437 "R_PPC_GOT16_HA", /* name */
438 false, /* partial_inplace */
440 0xffff, /* dst_mask */
441 false), /* pcrel_offset */
443 /* Like R_PPC_REL24, but referring to the procedure linkage table
444 entry for the symbol. FIXME: Not supported. */
445 HOWTO (R_PPC_PLTREL24
, /* type */
447 2, /* size (0 = byte, 1 = short, 2 = long) */
449 true, /* pc_relative */
451 complain_overflow_signed
, /* complain_on_overflow */
452 bfd_elf_generic_reloc
, /* special_function */
453 "R_PPC_PLTREL24", /* name */
454 false, /* partial_inplace */
456 0x3fffffc, /* dst_mask */
457 true), /* pcrel_offset */
459 /* This is used only by the dynamic linker. The symbol should exist
460 both in the object being run and in some shared library. The
461 dynamic linker copies the data addressed by the symbol from the
462 shared library into the object. I have no idea what the purpose
464 HOWTO (R_PPC_COPY
, /* type */
466 2, /* size (0 = byte, 1 = short, 2 = long) */
468 false, /* pc_relative */
470 complain_overflow_bitfield
, /* complain_on_overflow */
471 bfd_elf_generic_reloc
, /* special_function */
472 "R_PPC_COPY", /* name */
473 false, /* partial_inplace */
476 false), /* pcrel_offset */
478 /* Like R_PPC_ADDR32, but used when setting global offset table
480 HOWTO (R_PPC_GLOB_DAT
, /* type */
482 2, /* size (0 = byte, 1 = short, 2 = long) */
484 false, /* pc_relative */
486 complain_overflow_bitfield
, /* complain_on_overflow */
487 bfd_elf_generic_reloc
, /* special_function */
488 "R_PPC_GLOB_DAT", /* name */
489 false, /* partial_inplace */
491 0xffffffff, /* dst_mask */
492 false), /* pcrel_offset */
494 /* Marks a procedure linkage table entry for a symbol. */
495 HOWTO (R_PPC_JMP_SLOT
, /* type */
497 2, /* size (0 = byte, 1 = short, 2 = long) */
499 false, /* pc_relative */
501 complain_overflow_bitfield
, /* complain_on_overflow */
502 bfd_elf_generic_reloc
, /* special_function */
503 "R_PPC_JMP_SLOT", /* name */
504 false, /* partial_inplace */
507 false), /* pcrel_offset */
509 /* Used only by the dynamic linker. When the object is run, this
510 longword is set to the load address of the object, plus the
512 HOWTO (R_PPC_RELATIVE
, /* type */
514 2, /* size (0 = byte, 1 = short, 2 = long) */
516 false, /* pc_relative */
518 complain_overflow_bitfield
, /* complain_on_overflow */
519 bfd_elf_generic_reloc
, /* special_function */
520 "R_PPC_RELATIVE", /* name */
521 false, /* partial_inplace */
523 0xffffffff, /* dst_mask */
524 false), /* pcrel_offset */
526 /* Like R_PPC_REL24, but uses the value of the symbol within the
527 object rather than the final value. Normally used for
528 _GLOBAL_OFFSET_TABLE_. FIXME: Not supported. */
529 HOWTO (R_PPC_LOCAL24PC
, /* type */
531 2, /* size (0 = byte, 1 = short, 2 = long) */
533 true, /* pc_relative */
535 complain_overflow_signed
, /* complain_on_overflow */
536 bfd_elf_generic_reloc
, /* special_function */
537 "R_PPC_LOCAL24PC", /* name */
538 false, /* partial_inplace */
540 0x3fffffc, /* dst_mask */
541 true), /* pcrel_offset */
543 /* Like R_PPC_ADDR32, but may be unaligned. */
544 HOWTO (R_PPC_UADDR32
, /* type */
546 2, /* size (0 = byte, 1 = short, 2 = long) */
548 false, /* pc_relative */
550 complain_overflow_bitfield
, /* complain_on_overflow */
551 bfd_elf_generic_reloc
, /* special_function */
552 "R_PPC_UADDR32", /* name */
553 false, /* partial_inplace */
555 0xffffffff, /* dst_mask */
556 false), /* pcrel_offset */
558 /* Like R_PPC_ADDR16, but may be unaligned. */
559 HOWTO (R_PPC_UADDR16
, /* type */
561 1, /* size (0 = byte, 1 = short, 2 = long) */
563 false, /* pc_relative */
565 complain_overflow_bitfield
, /* complain_on_overflow */
566 bfd_elf_generic_reloc
, /* special_function */
567 "R_PPC_UADDR16", /* name */
568 false, /* partial_inplace */
570 0xffff, /* dst_mask */
571 false), /* pcrel_offset */
573 /* 32-bit PC relative */
574 HOWTO (R_PPC_REL32
, /* type */
576 2, /* size (0 = byte, 1 = short, 2 = long) */
578 true, /* pc_relative */
580 complain_overflow_bitfield
, /* complain_on_overflow */
581 bfd_elf_generic_reloc
, /* special_function */
582 "R_PPC_REL32", /* name */
583 false, /* partial_inplace */
585 0xffffffff, /* dst_mask */
586 true), /* pcrel_offset */
588 /* 32-bit relocation to the symbol's procedure linkage table.
589 FIXEME: not supported. */
590 HOWTO (R_PPC_PLT32
, /* type */
592 2, /* size (0 = byte, 1 = short, 2 = long) */
594 false, /* pc_relative */
596 complain_overflow_bitfield
, /* complain_on_overflow */
597 bfd_elf_generic_reloc
, /* special_function */
598 "R_PPC_PLT32", /* name */
599 false, /* partial_inplace */
602 false), /* pcrel_offset */
604 /* 32-bit PC relative relocation to the symbol's procedure linkage table.
605 FIXEME: not supported. */
606 HOWTO (R_PPC_PLTREL32
, /* type */
608 2, /* size (0 = byte, 1 = short, 2 = long) */
610 true, /* pc_relative */
612 complain_overflow_bitfield
, /* complain_on_overflow */
613 bfd_elf_generic_reloc
, /* special_function */
614 "R_PPC_PLTREL32", /* name */
615 false, /* partial_inplace */
618 true), /* pcrel_offset */
620 /* Like R_PPC_ADDR16_LO, but referring to the PLT table entry for
622 HOWTO (R_PPC_PLT16_LO
, /* type */
624 1, /* size (0 = byte, 1 = short, 2 = long) */
626 false, /* pc_relative */
628 complain_overflow_bitfield
, /* complain_on_overflow */
629 bfd_elf_generic_reloc
, /* special_function */
630 "R_PPC_PLT16_LO", /* name */
631 false, /* partial_inplace */
633 0xffff, /* dst_mask */
634 false), /* pcrel_offset */
636 /* Like R_PPC_ADDR16_HI, but referring to the PLT table entry for
638 HOWTO (R_PPC_PLT16_HI
, /* type */
640 1, /* size (0 = byte, 1 = short, 2 = long) */
642 false, /* pc_relative */
644 complain_overflow_bitfield
, /* complain_on_overflow */
645 bfd_elf_generic_reloc
, /* special_function */
646 "R_PPC_PLT16_HI", /* name */
647 false, /* partial_inplace */
649 0xffff, /* dst_mask */
650 false), /* pcrel_offset */
652 /* Like R_PPC_ADDR16_HA, but referring to the PLT table entry for
653 the symbol. FIXME: Not supported. */
654 HOWTO (R_PPC_PLT16_HA
, /* type */
656 1, /* size (0 = byte, 1 = short, 2 = long) */
658 false, /* pc_relative */
660 complain_overflow_bitfield
, /* complain_on_overflow */
661 bfd_elf_generic_reloc
, /* special_function */
662 "R_PPC_PLT16_HA", /* name */
663 false, /* partial_inplace */
665 0xffff, /* dst_mask */
666 false), /* pcrel_offset */
668 /* A sign-extended 16 bit value relative to _SDA_BASE, for use with
669 small data items. FIXME: Not supported. */
670 HOWTO (R_PPC_SDAREL16
, /* type */
672 1, /* size (0 = byte, 1 = short, 2 = long) */
674 false, /* pc_relative */
676 complain_overflow_signed
, /* complain_on_overflow */
677 bfd_elf_generic_reloc
, /* special_function */
678 "R_PPC_SDAREL16", /* name */
679 false, /* partial_inplace */
681 0xffff, /* dst_mask */
682 false), /* pcrel_offset */
684 /* These next 4 relocations were added by Sun. */
685 /* 32-bit section relative relocation. FIXME: not supported. */
686 HOWTO (R_PPC_SECTOFF
, /* type */
688 2, /* size (0 = byte, 1 = short, 2 = long) */
690 true, /* pc_relative */
692 complain_overflow_bitfield
, /* complain_on_overflow */
693 bfd_elf_generic_reloc
, /* special_function */
694 "R_PPC_SECTOFF", /* name */
695 false, /* partial_inplace */
698 true), /* pcrel_offset */
700 /* 16-bit lower half section relative relocation. FIXME: not supported. */
701 HOWTO (R_PPC_SECTOFF_LO
, /* type */
703 1, /* size (0 = byte, 1 = short, 2 = long) */
705 false, /* pc_relative */
707 complain_overflow_bitfield
, /* complain_on_overflow */
708 bfd_elf_generic_reloc
, /* special_function */
709 "R_PPC_SECTOFF_LO", /* name */
710 false, /* partial_inplace */
712 0xffff, /* dst_mask */
713 false), /* pcrel_offset */
715 /* 16-bit upper half section relative relocation. FIXME: not supported. */
716 HOWTO (R_PPC_SECTOFF_HI
, /* type */
718 1, /* size (0 = byte, 1 = short, 2 = long) */
720 false, /* pc_relative */
722 complain_overflow_bitfield
, /* complain_on_overflow */
723 bfd_elf_generic_reloc
, /* special_function */
724 "R_PPC_SECTOFF_HI", /* name */
725 false, /* partial_inplace */
727 0xffff, /* dst_mask */
728 false), /* pcrel_offset */
730 /* 16-bit upper half adjusted section relative relocation. FIXME: not supported. */
731 HOWTO (R_PPC_SECTOFF_HA
, /* type */
733 1, /* size (0 = byte, 1 = short, 2 = long) */
735 false, /* pc_relative */
737 complain_overflow_bitfield
, /* complain_on_overflow */
738 bfd_elf_generic_reloc
, /* special_function */
739 "R_PPC_SECTOFF_HA", /* name */
740 false, /* partial_inplace */
742 0xffff, /* dst_mask */
743 false), /* pcrel_offset */
745 /* The remaining relocs are from the Embedded ELF ABI, and are not
746 in the SVR4 ELF ABI. */
748 /* 32 bit value resulting from the addend minus the symbol */
749 HOWTO (R_PPC_EMB_NADDR32
, /* type */
751 2, /* size (0 = byte, 1 = short, 2 = long) */
753 false, /* pc_relative */
755 complain_overflow_bitfield
, /* complain_on_overflow */
756 bfd_elf_generic_reloc
, /* special_function */
757 "R_PPC_EMB_NADDR32", /* name */
758 false, /* partial_inplace */
760 0xffffffff, /* dst_mask */
761 false), /* pcrel_offset */
763 /* 16 bit value resulting from the addend minus the symbol */
764 HOWTO (R_PPC_EMB_NADDR16
, /* type */
766 1, /* size (0 = byte, 1 = short, 2 = long) */
768 false, /* pc_relative */
770 complain_overflow_bitfield
, /* complain_on_overflow */
771 bfd_elf_generic_reloc
, /* special_function */
772 "R_PPC_EMB_NADDR16", /* name */
773 false, /* partial_inplace */
775 0xffff, /* dst_mask */
776 false), /* pcrel_offset */
778 /* 16 bit value resulting from the addend minus the symbol */
779 HOWTO (R_PPC_EMB_NADDR16_LO
, /* type */
781 1, /* size (0 = byte, 1 = short, 2 = long) */
783 false, /* pc_relative */
785 complain_overflow_dont
,/* complain_on_overflow */
786 bfd_elf_generic_reloc
, /* special_function */
787 "R_PPC_EMB_ADDR16_LO", /* name */
788 false, /* partial_inplace */
790 0xffff, /* dst_mask */
791 false), /* pcrel_offset */
793 /* The high order 16 bits of the addend minus the symbol */
794 HOWTO (R_PPC_EMB_NADDR16_HI
, /* type */
796 1, /* size (0 = byte, 1 = short, 2 = long) */
798 false, /* pc_relative */
800 complain_overflow_dont
, /* complain_on_overflow */
801 bfd_elf_generic_reloc
, /* special_function */
802 "R_PPC_EMB_NADDR16_HI", /* name */
803 false, /* partial_inplace */
805 0xffff, /* dst_mask */
806 false), /* pcrel_offset */
808 /* The high order 16 bits of the result of the addend minus the address,
809 plus 1 if the contents of the low 16 bits, treated as a signed number,
811 HOWTO (R_PPC_EMB_NADDR16_HA
, /* type */
813 1, /* size (0 = byte, 1 = short, 2 = long) */
815 false, /* pc_relative */
817 complain_overflow_dont
, /* complain_on_overflow */
818 bfd_elf_generic_reloc
, /* special_function */
819 "R_PPC_EMB_NADDR16_HA", /* name */
820 false, /* partial_inplace */
822 0xffff, /* dst_mask */
823 false), /* pcrel_offset */
825 /* Phony reloc to handle AIX style TOC entries */
826 HOWTO (R_PPC_TOC16
, /* type */
828 1, /* size (0 = byte, 1 = short, 2 = long) */
830 false, /* pc_relative */
832 complain_overflow_signed
, /* complain_on_overflow */
833 bfd_elf_generic_reloc
, /* special_function */
834 "R_PPC_TOC16", /* name */
835 false, /* partial_inplace */
837 0xffff, /* dst_mask */
838 false), /* pcrel_offset */
842 /* Initialize the ppc_elf_howto_table, so that linear accesses can be done. */
845 ppc_elf_howto_init ()
847 unsigned int i
, type
;
849 for (i
= 0; i
< sizeof (ppc_elf_howto_raw
) / sizeof (ppc_elf_howto_raw
[0]); i
++)
851 type
= ppc_elf_howto_raw
[i
].type
;
852 BFD_ASSERT (type
< sizeof(ppc_elf_howto_table
) / sizeof(ppc_elf_howto_table
[0]));
853 ppc_elf_howto_table
[type
] = &ppc_elf_howto_raw
[i
];
858 static reloc_howto_type
*
859 ppc_elf_reloc_type_lookup (abfd
, code
)
861 bfd_reloc_code_real_type code
;
863 enum ppc_reloc_type ppc_reloc
= R_PPC_NONE
;
865 if (!ppc_elf_howto_table
[ R_PPC_ADDR32
]) /* Initialize howto table if needed */
866 ppc_elf_howto_init ();
871 return (reloc_howto_type
*)NULL
;
873 case BFD_RELOC_NONE
: ppc_reloc
= R_PPC_NONE
; break;
874 case BFD_RELOC_32
: ppc_reloc
= R_PPC_ADDR32
; break;
875 case BFD_RELOC_PPC_BA26
: ppc_reloc
= R_PPC_ADDR24
; break;
876 case BFD_RELOC_16
: ppc_reloc
= R_PPC_ADDR16
; break;
877 case BFD_RELOC_LO16
: ppc_reloc
= R_PPC_ADDR16_LO
; break;
878 case BFD_RELOC_HI16
: ppc_reloc
= R_PPC_ADDR16_HI
; break;
879 case BFD_RELOC_HI16_S
: ppc_reloc
= R_PPC_ADDR16_HA
; break;
880 case BFD_RELOC_PPC_BA16
: ppc_reloc
= R_PPC_ADDR14
; break;
881 case BFD_RELOC_PPC_BA16_BRTAKEN
: ppc_reloc
= R_PPC_ADDR14_BRTAKEN
; break;
882 case BFD_RELOC_PPC_BA16_BRNTAKEN
: ppc_reloc
= R_PPC_ADDR14_BRNTAKEN
; break;
883 case BFD_RELOC_PPC_B26
: ppc_reloc
= R_PPC_REL24
; break;
884 case BFD_RELOC_PPC_B16
: ppc_reloc
= R_PPC_REL14
; break;
885 case BFD_RELOC_PPC_B16_BRTAKEN
: ppc_reloc
= R_PPC_REL14_BRTAKEN
; break;
886 case BFD_RELOC_PPC_B16_BRNTAKEN
: ppc_reloc
= R_PPC_REL14_BRNTAKEN
; break;
887 case BFD_RELOC_16_GOTOFF
: ppc_reloc
= R_PPC_GOT16
; break;
888 case BFD_RELOC_LO16_GOTOFF
: ppc_reloc
= R_PPC_GOT16_LO
; break;
889 case BFD_RELOC_HI16_GOTOFF
: ppc_reloc
= R_PPC_GOT16_HI
; break;
890 case BFD_RELOC_HI16_S_GOTOFF
: ppc_reloc
= R_PPC_GOT16_HA
; break;
891 case BFD_RELOC_24_PLT_PCREL
: ppc_reloc
= R_PPC_PLTREL24
; break;
892 case BFD_RELOC_PPC_COPY
: ppc_reloc
= R_PPC_COPY
; break;
893 case BFD_RELOC_PPC_GLOB_DAT
: ppc_reloc
= R_PPC_GLOB_DAT
; break;
894 case BFD_RELOC_PPC_LOCAL24PC
: ppc_reloc
= R_PPC_LOCAL24PC
; break;
895 case BFD_RELOC_32_PCREL
: ppc_reloc
= R_PPC_REL32
; break;
896 case BFD_RELOC_32_PLTOFF
: ppc_reloc
= R_PPC_PLT32
; break;
897 case BFD_RELOC_32_PLT_PCREL
: ppc_reloc
= R_PPC_PLTREL32
; break;
898 case BFD_RELOC_LO16_PLTOFF
: ppc_reloc
= R_PPC_PLT16_LO
; break;
899 case BFD_RELOC_HI16_PLTOFF
: ppc_reloc
= R_PPC_PLT16_HI
; break;
900 case BFD_RELOC_HI16_S_PLTOFF
: ppc_reloc
= R_PPC_PLT16_HA
; break;
901 case BFD_RELOC_GPREL16
: ppc_reloc
= R_PPC_SDAREL16
; break;
902 case BFD_RELOC_32_BASEREL
: ppc_reloc
= R_PPC_SECTOFF
; break;
903 case BFD_RELOC_LO16_BASEREL
: ppc_reloc
= R_PPC_SECTOFF_LO
; break;
904 case BFD_RELOC_HI16_BASEREL
: ppc_reloc
= R_PPC_SECTOFF_HI
; break;
905 case BFD_RELOC_HI16_S_BASEREL
: ppc_reloc
= R_PPC_SECTOFF_HA
; break;
906 case BFD_RELOC_CTOR
: ppc_reloc
= R_PPC_ADDR32
; break;
907 case BFD_RELOC_PPC_TOC16
: ppc_reloc
= R_PPC_TOC16
; break;
910 return ppc_elf_howto_table
[ (int)ppc_reloc
];
913 /* Set the howto pointer for a PowerPC ELF reloc. */
916 ppc_elf_info_to_howto (abfd
, cache_ptr
, dst
)
919 Elf32_Internal_Rela
*dst
;
921 if (!ppc_elf_howto_table
[ R_PPC_ADDR32
]) /* Initialize howto table if needed */
922 ppc_elf_howto_init ();
924 BFD_ASSERT (ELF32_R_TYPE (dst
->r_info
) < (unsigned int) R_PPC_max
);
925 cache_ptr
->howto
= ppc_elf_howto_table
[ELF32_R_TYPE (dst
->r_info
)];
928 /* Function to set whether a module needs the -mrelocatable bit set. */
931 ppc_elf_set_private_flags (abfd
, flags
)
935 BFD_ASSERT (!elf_flags_init (abfd
)
936 || elf_elfheader (abfd
)->e_flags
== flags
);
938 elf_elfheader (abfd
)->e_flags
= flags
;
939 elf_flags_init (abfd
) = true;
943 /* Copy backend specific data from one object module to another */
945 ppc_elf_copy_private_bfd_data (ibfd
, obfd
)
949 /* This function is selected based on the input vector. We only
950 want to copy information over if the output BFD also uses Elf
952 if (bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
955 BFD_ASSERT (!elf_flags_init (obfd
)
956 || elf_elfheader (obfd
)->e_flags
== elf_elfheader (ibfd
)->e_flags
);
958 elf_elfheader (obfd
)->e_flags
= elf_elfheader (ibfd
)->e_flags
;
959 elf_flags_init (obfd
) = true;
963 /* Merge backend specific data from an object file to the output
964 object file when linking */
966 ppc_elf_merge_private_bfd_data (ibfd
, obfd
)
974 /* Check if we have the same endianess */
975 if (ibfd
->xvec
->byteorder
!= obfd
->xvec
->byteorder
976 && obfd
->xvec
->byteorder
!= BFD_ENDIAN_UNKNOWN
)
978 (*_bfd_error_handler
)
979 ("%s: compiled for a %s endian system and target is %s endian",
980 bfd_get_filename (ibfd
),
981 bfd_big_endian (ibfd
) ? "big" : "little",
982 bfd_big_endian (obfd
) ? "big" : "little");
984 bfd_set_error (bfd_error_wrong_format
);
988 /* This function is selected based on the input vector. We only
989 want to copy information over if the output BFD also uses Elf
991 if (bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
994 new_flags
= elf_elfheader (ibfd
)->e_flags
;
995 old_flags
= elf_elfheader (obfd
)->e_flags
;
996 if (!elf_flags_init (obfd
)) /* First call, no flags set */
998 elf_flags_init (obfd
) = true;
999 elf_elfheader (obfd
)->e_flags
= new_flags
;
1002 else if (new_flags
== old_flags
) /* Compatible flags are ok */
1005 else /* Incompatible flags */
1007 /* Warn about -mrelocatable mismatch. Allow -mrelocatable-lib to be linked
1010 if ((new_flags
& EF_PPC_RELOCATABLE
) != 0
1011 && (old_flags
& (EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
)) == 0)
1014 (*_bfd_error_handler
)
1015 ("%s: compiled with -mrelocatable and linked with modules compiled normally",
1016 bfd_get_filename (ibfd
));
1018 else if ((new_flags
& (EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
)) == 0
1019 && (old_flags
& EF_PPC_RELOCATABLE
) != 0)
1022 (*_bfd_error_handler
)
1023 ("%s: compiled normally and linked with modules compiled with -mrelocatable",
1024 bfd_get_filename (ibfd
));
1026 else if ((new_flags
& EF_PPC_RELOCATABLE_LIB
) != 0)
1027 elf_elfheader (obfd
)->e_flags
|= EF_PPC_RELOCATABLE_LIB
;
1029 new_flags
&= ~ (EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
);
1030 old_flags
&= ~ (EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
);
1032 /* Warn about eabi vs. V.4 mismatch */
1033 if ((new_flags
& EF_PPC_EMB
) != 0 && (old_flags
& EF_PPC_EMB
) == 0)
1035 new_flags
&= ~EF_PPC_EMB
;
1037 (*_bfd_error_handler
)
1038 ("%s: compiled for the eabi and linked with modules compiled for System V",
1039 bfd_get_filename (ibfd
));
1041 else if ((new_flags
& EF_PPC_EMB
) == 0 && (old_flags
& EF_PPC_EMB
) != 0)
1043 old_flags
&= ~EF_PPC_EMB
;
1045 (*_bfd_error_handler
)
1046 ("%s: compiled for System V and linked with modules compiled for eabi",
1047 bfd_get_filename (ibfd
));
1050 /* Warn about any other mismatches */
1051 if (new_flags
!= old_flags
)
1054 (*_bfd_error_handler
)
1055 ("%s: uses different e_flags (0x%lx) fields than previous modules (0x%lx)",
1056 bfd_get_filename (ibfd
), (long)new_flags
, (long)old_flags
);
1061 bfd_set_error (bfd_error_bad_value
);
1070 /* Handle a PowerPC specific section when reading an object file. This
1071 is called when elfcode.h finds a section with an unknown type. */
1074 ppc_elf_section_from_shdr (abfd
, hdr
, name
)
1076 Elf32_Internal_Shdr
*hdr
;
1082 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
))
1085 newsect
= hdr
->bfd_section
;
1086 flags
= bfd_get_section_flags (abfd
, newsect
);
1087 if (hdr
->sh_flags
& SHF_EXCLUDE
)
1088 flags
|= SEC_EXCLUDE
;
1090 if (hdr
->sh_type
== SHT_ORDERED
)
1091 flags
|= SEC_SORT_ENTRIES
;
1093 bfd_set_section_flags (abfd
, newsect
, flags
);
1098 /* Set up any other section flags and such that may be necessary. */
1101 ppc_elf_fake_sections (abfd
, shdr
, asect
)
1103 Elf32_Internal_Shdr
*shdr
;
1106 if ((asect
->flags
& SEC_EXCLUDE
) != 0)
1107 shdr
->sh_flags
|= SHF_EXCLUDE
;
1109 if ((asect
->flags
& SEC_SORT_ENTRIES
) != 0)
1110 shdr
->sh_type
= SHT_ORDERED
;
1114 /* Create the PowerPC dynamic sections */
1117 ppc_elf_create_dynamic_sections (abfd
, info
)
1119 struct bfd_link_info
*info
;
1121 struct elf_link_hash_entry
*h
;
1122 struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
1124 /* Create the .got section. */
1125 if (! _bfd_elf_create_got_section (abfd
, info
))
1128 /* Also create the .got.neg section where we put negative offsets */
1129 if (bfd_get_section_by_name (abfd
, ".got.neg") == NULL
)
1131 asection
*s
= bfd_make_section (abfd
, ".got.neg");
1133 || !bfd_set_section_flags (abfd
, s
,
1134 SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
)
1135 || !bfd_set_section_alignment (abfd
, s
, 2))
1139 elf_hash_table (info
)->dynobj
= abfd
;
1144 /* Adjust a symbol defined by a dynamic object and referenced by a
1145 regular object. The current definition is in some section of the
1146 dynamic object, but we're not including those sections. We have to
1147 change the definition to something the rest of the link can
1151 ppc_elf_adjust_dynamic_symbol (info
, h
)
1152 struct bfd_link_info
*info
;
1153 struct elf_link_hash_entry
*h
;
1156 fprintf (stderr
, "ppc_elf_adjust_dynamic_symbol called\n");
1162 /* Increment the index of a dynamic symbol by a given amount. Called
1163 via elf_link_hash_traverse. */
1166 ppc_elf_adjust_dynindx (h
, cparg
)
1167 struct elf_link_hash_entry
*h
;
1170 int *cp
= (int *) cparg
;
1173 fprintf (stderr
, "ppc_elf_adjust_dynindx called, h->dynindx = %d, *cp = %d\n", h
->dynindx
, *cp
);
1176 if (h
->dynindx
!= -1)
1183 /* Set the sizes of the dynamic sections. */
1186 ppc_elf_size_dynamic_sections (output_bfd
, info
)
1188 struct bfd_link_info
*info
;
1196 fprintf (stderr
, "ppc_elf_size_dynamic_sections called\n");
1199 dynobj
= elf_hash_table (info
)->dynobj
;
1200 BFD_ASSERT (dynobj
!= NULL
);
1202 if (elf_hash_table (info
)->dynamic_sections_created
)
1204 /* Set the contents of the .interp section to the interpreter. */
1207 s
= bfd_get_section_by_name (dynobj
, ".interp");
1208 BFD_ASSERT (s
!= NULL
);
1209 s
->_raw_size
= sizeof ELF_DYNAMIC_INTERPRETER
;
1210 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
1213 /* Make space for the trailing nop in .plt. */
1214 s
= bfd_get_section_by_name (dynobj
, ".plt");
1215 BFD_ASSERT (s
!= NULL
);
1216 if (s
->_raw_size
> 0)
1221 /* We may have created entries in the .rela.got section.
1222 However, if we are not creating the dynamic sections, we will
1223 not actually use these entries. Reset the size of .rela.got,
1224 which will cause it to get stripped from the output file
1226 s
= bfd_get_section_by_name (dynobj
, ".rela.got");
1230 /* Ditto for .rela.got.neg */
1231 s
= bfd_get_section_by_name (dynobj
, ".rela.got.neg");
1236 /* The check_relocs and adjust_dynamic_symbol entry points have
1237 determined the sizes of the various dynamic sections. Allocate
1241 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
1246 if ((s
->flags
& SEC_IN_MEMORY
) == 0)
1249 /* It's OK to base decisions on the section name, because none
1250 of the dynobj section names depend upon the input files. */
1251 name
= bfd_get_section_name (dynobj
, s
);
1255 if (strncmp (name
, ".rela", 5) == 0)
1257 if (s
->_raw_size
== 0)
1259 /* If we don't need this section, strip it from the
1260 output file. This is to handle .rela.bss and
1261 .rel.plt. We must create it in
1262 create_dynamic_sections, because it must be created
1263 before the linker maps input sections to output
1264 sections. The linker does that before
1265 adjust_dynamic_symbol is called, and it is that
1266 function which decides whether anything needs to go
1267 into these sections. */
1274 /* If this relocation section applies to a read only
1275 section, then we probably need a DT_TEXTREL entry. */
1276 target
= bfd_get_section_by_name (output_bfd
, name
+ 5);
1278 && (target
->flags
& SEC_READONLY
) != 0)
1281 if (strcmp (name
, ".rela.plt") == 0)
1284 /* We use the reloc_count field as a counter if we need
1285 to copy relocs into the output file. */
1289 else if (strcmp (name
, ".plt") != 0
1290 && strcmp (name
, ".got") != 0
1291 && strcmp (name
, ".got.neg") != 0)
1293 /* It's not one of our sections, so don't allocate space. */
1301 for (spp
= &s
->output_section
->owner
->sections
;
1302 *spp
!= s
->output_section
;
1303 spp
= &(*spp
)->next
)
1305 *spp
= s
->output_section
->next
;
1306 --s
->output_section
->owner
->section_count
;
1311 /* Allocate memory for the section contents. */
1312 s
->contents
= (bfd_byte
*) bfd_alloc (dynobj
, s
->_raw_size
);
1313 if (s
->contents
== NULL
&& s
->_raw_size
!= 0)
1317 if (elf_hash_table (info
)->dynamic_sections_created
)
1319 /* Add some entries to the .dynamic section. We fill in the
1320 values later, in ppc_elf_finish_dynamic_sections, but we
1321 must add the entries now so that we get the correct size for
1322 the .dynamic section. The DT_DEBUG entry is filled in by the
1323 dynamic linker and used by the debugger. */
1326 if (! bfd_elf32_add_dynamic_entry (info
, DT_DEBUG
, 0))
1330 if (! bfd_elf32_add_dynamic_entry (info
, DT_PLTGOT
, 0))
1335 if (! bfd_elf32_add_dynamic_entry (info
, DT_PLTRELSZ
, 0)
1336 || ! bfd_elf32_add_dynamic_entry (info
, DT_PLTREL
, DT_RELA
)
1337 || ! bfd_elf32_add_dynamic_entry (info
, DT_JMPREL
, 0))
1341 if (! bfd_elf32_add_dynamic_entry (info
, DT_RELA
, 0)
1342 || ! bfd_elf32_add_dynamic_entry (info
, DT_RELASZ
, 0)
1343 || ! bfd_elf32_add_dynamic_entry (info
, DT_RELAENT
,
1344 sizeof (Elf32_External_Rela
)))
1349 if (! bfd_elf32_add_dynamic_entry (info
, DT_TEXTREL
, 0))
1354 /* If we are generating a shared library, we generate a section
1355 symbol for each output section. These are local symbols, which
1356 means that they must come first in the dynamic symbol table.
1357 That means we must increment the dynamic symbol index of every
1358 other dynamic symbol. */
1363 c
= bfd_count_sections (output_bfd
);
1364 elf_link_hash_traverse (elf_hash_table (info
),
1365 ppc_elf_adjust_dynindx
,
1367 elf_hash_table (info
)->dynsymcount
+= c
;
1369 for (i
= 1, s
= output_bfd
->sections
; s
!= NULL
; s
= s
->next
, i
++)
1371 elf_section_data (s
)->dynindx
= i
;
1372 /* These symbols will have no names, so we don't need to
1373 fiddle with dynstr_index. */
1381 /* Look through the relocs for a section during the first phase, and
1382 allocate space in the global offset table or procedure linkage
1386 ppc_elf_check_relocs (abfd
, info
, sec
, relocs
)
1388 struct bfd_link_info
*info
;
1390 const Elf_Internal_Rela
*relocs
;
1393 Elf_Internal_Shdr
*symtab_hdr
;
1394 struct elf_link_hash_entry
**sym_hashes
;
1395 bfd_vma
*local_got_offsets
;
1396 const Elf_Internal_Rela
*rel
;
1397 const Elf_Internal_Rela
*rel_end
;
1401 asection
*srelgot_neg
;
1404 if (info
->relocateable
)
1408 fprintf (stderr
, "ppc_elf_check_relocs called for section %s\n", sec
->name
);
1411 dynobj
= elf_hash_table (info
)->dynobj
;
1412 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
1413 sym_hashes
= elf_sym_hashes (abfd
);
1414 local_got_offsets
= elf_local_got_offsets (abfd
);
1420 rel_end
= relocs
+ sec
->reloc_count
;
1421 for (rel
= relocs
; rel
< rel_end
; rel
++)
1423 unsigned long r_symndx
;
1424 struct elf_link_hash_entry
*h
;
1426 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1427 if (r_symndx
< symtab_hdr
->sh_info
)
1430 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1432 switch (ELF32_R_TYPE (rel
->r_info
))
1435 case R_PPC_GOT16_LO
:
1436 case R_PPC_GOT16_HI
:
1437 case R_PPC_GOT16_HA
:
1439 fprintf (stderr
, "Reloc requires a GOT entry\n");
1441 /* This symbol requires a global offset table entry. */
1445 dynobj
= ppc_elf_create_dynamic_sections (abfd
, info
);
1452 sgot
= bfd_get_section_by_name (dynobj
, ".got");
1453 sgot_neg
= bfd_get_section_by_name (dynobj
, ".got.neg");
1454 BFD_ASSERT (sgot
!= NULL
&& sgot_neg
!= NULL
);
1458 && (h
!= NULL
|| info
->shared
))
1460 srelgot
= bfd_get_section_by_name (dynobj
, ".rela.got");
1461 if (srelgot
== NULL
)
1463 srelgot
= bfd_make_section (dynobj
, ".rela.got");
1465 || ! bfd_set_section_flags (dynobj
, srelgot
,
1471 || ! bfd_set_section_alignment (dynobj
, srelgot
, 2))
1475 srelgot_neg
= bfd_get_section_by_name (dynobj
, ".rela.got.neg");
1476 if (srelgot_neg
== NULL
)
1478 srelgot_neg
= bfd_make_section (dynobj
, ".rela.got.neg");
1480 || ! bfd_set_section_flags (dynobj
, srelgot_neg
,
1486 || ! bfd_set_section_alignment (dynobj
, srelgot
, 2))
1493 if (h
->got_offset
!= (bfd_vma
) -1)
1495 /* We have already allocated space in the .got. */
1498 h
->got_offset
= sgot
->_raw_size
;
1500 /* Make sure this symbol is output as a dynamic symbol. */
1501 if (h
->dynindx
== -1)
1503 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
1507 srelgot
->_raw_size
+= sizeof (Elf32_External_Rela
);
1511 /* This is a global offset table entry for a local
1513 if (local_got_offsets
== NULL
)
1516 register unsigned int i
;
1518 size
= symtab_hdr
->sh_info
* sizeof (bfd_vma
);
1519 local_got_offsets
= (bfd_vma
*) bfd_alloc (abfd
, size
);
1520 if (local_got_offsets
== NULL
)
1522 elf_local_got_offsets (abfd
) = local_got_offsets
;
1523 for (i
= 0; i
< symtab_hdr
->sh_info
; i
++)
1524 local_got_offsets
[i
] = (bfd_vma
) -1;
1526 if (local_got_offsets
[r_symndx
] != (bfd_vma
) -1)
1528 /* We have already allocated space in the .got. */
1531 local_got_offsets
[r_symndx
] = sgot
->_raw_size
;
1535 /* If we are generating a shared object, we need to
1536 output a R_PPC_RELATIVE reloc so that the
1537 dynamic linker can adjust this GOT entry. */
1538 srelgot
->_raw_size
+= sizeof (Elf32_External_Rela
);
1542 sgot
->_raw_size
+= 4;
1547 case R_PPC_PLTREL24
:
1548 case R_PPC_PLT16_LO
:
1549 case R_PPC_PLT16_HI
:
1550 case R_PPC_PLT16_HA
:
1552 fprintf (stderr
, "Reloc requires a PLT entry\n");
1554 /* This symbol requires a procedure linkage table entry. We
1555 actually build the entry in adjust_dynamic_symbol,
1556 because this might be a case of linking PIC code without
1557 linking in any dynamic objects, in which case we don't
1558 need to generate a procedure linkage table after all. */
1562 /* It does not make sense to have a procedure linkage
1563 table entry for a local symbol. */
1564 bfd_set_error (bfd_error_bad_value
);
1568 /* Make sure this symbol is output as a dynamic symbol. */
1569 if (h
->dynindx
== -1)
1571 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
1575 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
1582 && strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
1586 case R_SPARC_DISP16
:
1587 case R_SPARC_DISP32
:
1588 case R_SPARC_WDISP30
:
1589 case R_SPARC_WDISP22
:
1602 && (sec
->flags
& SEC_ALLOC
) != 0)
1604 /* When creating a shared object, we must copy these
1605 relocs into the output file. We create a reloc
1606 section in dynobj and make room for the reloc. */
1611 name
= (bfd_elf_string_from_elf_section
1613 elf_elfheader (abfd
)->e_shstrndx
,
1614 elf_section_data (sec
)->rel_hdr
.sh_name
));
1618 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
1619 && strcmp (bfd_get_section_name (abfd
, sec
),
1622 sreloc
= bfd_get_section_by_name (dynobj
, name
);
1625 sreloc
= bfd_make_section (dynobj
, name
);
1627 || ! bfd_set_section_flags (dynobj
, sreloc
,
1633 || ! bfd_set_section_alignment (dynobj
, sreloc
, 2))
1638 sreloc
->_raw_size
+= sizeof (Elf32_External_Rela
);
1653 /* Finish up dynamic symbol handling. We set the contents of various
1654 dynamic sections here. */
1657 ppc_elf_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
1659 struct bfd_link_info
*info
;
1660 struct elf_link_hash_entry
*h
;
1661 Elf_Internal_Sym
*sym
;
1666 fprintf (stderr
, "ppc_elf_finish_dynamic_symbol called\n");
1669 dynobj
= elf_hash_table (info
)->dynobj
;
1671 if (h
->plt_offset
!= (bfd_vma
) -1)
1675 Elf_Internal_Rela rela
;
1677 /* This symbol has an entry in the procedure linkage table. Set
1680 BFD_ASSERT (h
->dynindx
!= -1);
1682 splt
= bfd_get_section_by_name (dynobj
, ".plt");
1683 srela
= bfd_get_section_by_name (dynobj
, ".rela.plt");
1684 BFD_ASSERT (splt
!= NULL
&& srela
!= NULL
);
1686 /* Fill in the entry in the procedure linkage table. */
1688 bfd_put_32 (output_bfd
,
1689 PLT_ENTRY_WORD0
+ h
->plt_offset
,
1690 splt
->contents
+ h
->plt_offset
);
1691 bfd_put_32 (output_bfd
,
1693 + (((- (h
->plt_offset
+ 4)) >> 2) & 0x3fffff)),
1694 splt
->contents
+ h
->plt_offset
+ 4);
1695 bfd_put_32 (output_bfd
, PLT_ENTRY_WORD2
,
1696 splt
->contents
+ h
->plt_offset
+ 8);
1698 /* Fill in the entry in the .rela.plt section. */
1699 rela
.r_offset
= (splt
->output_section
->vma
1700 + splt
->output_offset
1702 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_SPARC_JMP_SLOT
);
1704 bfd_elf32_swap_reloca_out (output_bfd
, &rela
,
1705 ((Elf32_External_Rela
*) srela
->contents
1706 + h
->plt_offset
/ PLT_ENTRY_SIZE
- 4));
1709 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
1711 /* Mark the symbol as undefined, rather than as defined in
1712 the .plt section. Leave the value alone. */
1713 sym
->st_shndx
= SHN_UNDEF
;
1717 if (h
->got_offset
!= (bfd_vma
) -1)
1721 Elf_Internal_Rela rela
;
1723 /* This symbol has an entry in the global offset table. Set it
1726 BFD_ASSERT (h
->dynindx
!= -1);
1728 sgot
= bfd_get_section_by_name (dynobj
, ".got");
1729 srela
= bfd_get_section_by_name (dynobj
, ".rela.got");
1730 BFD_ASSERT (sgot
!= NULL
&& srela
!= NULL
);
1732 rela
.r_offset
= (sgot
->output_section
->vma
1733 + sgot
->output_offset
1734 + (h
->got_offset
&~ 1));
1736 /* If this is a -Bsymbolic link, and the symbol is defined
1737 locally, we just want to emit a RELATIVE reloc. The entry in
1738 the global offset table will already have been initialized in
1739 the relocate_section function. */
1742 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
))
1743 rela
.r_info
= ELF32_R_INFO (0, R_PPC_RELATIVE
);
1746 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ h
->got_offset
);
1747 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_PPC_GLOB_DAT
);
1751 bfd_elf32_swap_reloca_out (output_bfd
, &rela
,
1752 ((Elf32_External_Rela
*) srela
->contents
1753 + srela
->reloc_count
));
1754 ++srela
->reloc_count
;
1757 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_COPY
) != 0)
1760 Elf_Internal_Rela rela
;
1762 /* This symbols needs a copy reloc. Set it up. */
1764 BFD_ASSERT (h
->dynindx
!= -1);
1766 s
= bfd_get_section_by_name (h
->root
.u
.def
.section
->owner
,
1768 BFD_ASSERT (s
!= NULL
);
1770 rela
.r_offset
= (h
->root
.u
.def
.value
1771 + h
->root
.u
.def
.section
->output_section
->vma
1772 + h
->root
.u
.def
.section
->output_offset
);
1773 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_PPC_COPY
);
1775 bfd_elf32_swap_reloca_out (output_bfd
, &rela
,
1776 ((Elf32_External_Rela
*) s
->contents
1781 /* Mark some specially defined symbols as absolute. */
1782 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
1783 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0
1784 || strcmp (h
->root
.root
.string
, "_PROCEDURE_LINKAGE_TABLE_") == 0)
1785 sym
->st_shndx
= SHN_ABS
;
1791 /* Finish up the dynamic sections. */
1794 ppc_elf_finish_dynamic_sections (output_bfd
, info
)
1796 struct bfd_link_info
*info
;
1803 fprintf (stderr
, "ppc_elf_finish_dynamic_sections called\n");
1806 dynobj
= elf_hash_table (info
)->dynobj
;
1808 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
1810 if (elf_hash_table (info
)->dynamic_sections_created
)
1813 Elf32_External_Dyn
*dyncon
, *dynconend
;
1815 splt
= bfd_get_section_by_name (dynobj
, ".plt");
1816 BFD_ASSERT (splt
!= NULL
&& sdyn
!= NULL
);
1818 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
1819 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
1820 for (; dyncon
< dynconend
; dyncon
++)
1822 Elf_Internal_Dyn dyn
;
1826 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
1830 case DT_PLTGOT
: name
= ".plt"; size
= false; break;
1831 case DT_PLTRELSZ
: name
= ".rela.plt"; size
= true; break;
1832 case DT_JMPREL
: name
= ".rela.plt"; size
= false; break;
1833 default: name
= NULL
; size
= false; break;
1840 s
= bfd_get_section_by_name (output_bfd
, name
);
1846 dyn
.d_un
.d_ptr
= s
->vma
;
1849 if (s
->_cooked_size
!= 0)
1850 dyn
.d_un
.d_val
= s
->_cooked_size
;
1852 dyn
.d_un
.d_val
= s
->_raw_size
;
1855 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
1859 /* Clear the first four entries in the procedure linkage table,
1860 and put a nop in the last four bytes. */
1862 if (splt
->_raw_size
> 0)
1864 memset (splt
->contents
, 0, 4 * PLT_ENTRY_SIZE
);
1865 bfd_put_32 (output_bfd
, SPARC_NOP
,
1866 splt
->contents
+ splt
->_raw_size
- 4);
1869 elf_section_data (splt
->output_section
)->this_hdr
.sh_entsize
=
1874 /* Set the first entry in the global offset table to the address of
1875 the dynamic section. */
1876 sgot
= bfd_get_section_by_name (dynobj
, ".got");
1877 BFD_ASSERT (sgot
!= NULL
);
1878 if (sgot
->_raw_size
> 0)
1881 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
);
1883 bfd_put_32 (output_bfd
,
1884 sdyn
->output_section
->vma
+ sdyn
->output_offset
,
1888 elf_section_data (sgot
->output_section
)->this_hdr
.sh_entsize
= 4;
1894 Elf_Internal_Sym sym
;
1896 /* Set up the section symbols for the output sections. */
1898 sdynsym
= bfd_get_section_by_name (dynobj
, ".dynsym");
1899 BFD_ASSERT (sdynsym
!= NULL
);
1903 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_SECTION
);
1906 for (s
= output_bfd
->sections
; s
!= NULL
; s
= s
->next
)
1910 sym
.st_value
= s
->vma
;
1912 indx
= elf_section_data (s
)->this_idx
;
1913 BFD_ASSERT (indx
> 0);
1914 sym
.st_shndx
= indx
;
1916 bfd_elf32_swap_symbol_out (output_bfd
, &sym
,
1917 (PTR
) (((Elf32_External_Sym
*)
1919 + elf_section_data (s
)->dynindx
));
1922 /* Set the sh_info field of the output .dynsym section to the
1923 index of the first global symbol. */
1924 elf_section_data (sdynsym
->output_section
)->this_hdr
.sh_info
=
1925 bfd_count_sections (output_bfd
) + 1;
1932 /* The RELOCATE_SECTION function is called by the ELF backend linker
1933 to handle the relocations for a section.
1935 The relocs are always passed as Rela structures; if the section
1936 actually uses Rel structures, the r_addend field will always be
1939 This function is responsible for adjust the section contents as
1940 necessary, and (if using Rela relocs and generating a
1941 relocateable output file) adjusting the reloc addend as
1944 This function does not have to worry about setting the reloc
1945 address or the reloc symbol index.
1947 LOCAL_SYMS is a pointer to the swapped in local symbols.
1949 LOCAL_SECTIONS is an array giving the section in the input file
1950 corresponding to the st_shndx field of each local symbol.
1952 The global hash table entry for the global symbols can be found
1953 via elf_sym_hashes (input_bfd).
1955 When generating relocateable output, this function must handle
1956 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
1957 going to be the section symbol corresponding to the output
1958 section, which means that the addend must be adjusted
1962 ppc_elf_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
1963 contents
, relocs
, local_syms
, local_sections
)
1965 struct bfd_link_info
*info
;
1967 asection
*input_section
;
1969 Elf_Internal_Rela
*relocs
;
1970 Elf_Internal_Sym
*local_syms
;
1971 asection
**local_sections
;
1973 Elf_Internal_Shdr
*symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
1974 struct elf_link_hash_entry
**sym_hashes
= elf_sym_hashes (input_bfd
);
1975 bfd
*dynobj
= elf_hash_table (info
)->dynobj
;
1976 bfd_vma
*local_got_offsets
= elf_local_got_offsets (input_bfd
);
1977 asection
*sgot
= (asection
*)0;
1978 Elf_Internal_Rela
*rel
= relocs
;
1979 Elf_Internal_Rela
*relend
= relocs
+ input_section
->reloc_count
;
1984 fprintf (stderr
, "ppc_elf_relocate_section called for %s section %s, %ld relocations%s\n",
1985 bfd_get_filename (input_bfd
),
1986 bfd_section_name(input_bfd
, input_section
),
1987 (long)input_section
->reloc_count
,
1988 (info
->relocateable
) ? " (relocatable)" : "");
1991 if (!ppc_elf_howto_table
[ R_PPC_ADDR32
]) /* Initialize howto table if needed */
1992 ppc_elf_howto_init ();
1994 for (; rel
< relend
; rel
++)
1996 enum ppc_reloc_type r_type
= (enum ppc_reloc_type
)ELF32_R_TYPE (rel
->r_info
);
1997 bfd_vma offset
= rel
->r_offset
;
1998 bfd_vma addend
= rel
->r_addend
;
1999 bfd_reloc_status_type r
= bfd_reloc_other
;
2000 Elf_Internal_Sym
*sym
= (Elf_Internal_Sym
*)0;
2001 asection
*sec
= (asection
*)0;
2002 struct elf_link_hash_entry
*h
= (struct elf_link_hash_entry
*)0;
2003 reloc_howto_type
*howto
;
2004 unsigned long r_symndx
;
2007 /* Unknown relocation handling */
2008 if ((unsigned)r_type
>= (unsigned)R_PPC_max
|| !ppc_elf_howto_table
[(int)r_type
])
2010 (*_bfd_error_handler
) ("%s: unknown relocation type %d",
2011 bfd_get_filename (input_bfd
),
2014 bfd_set_error (bfd_error_bad_value
);
2019 howto
= ppc_elf_howto_table
[(int)r_type
];
2020 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2022 if (info
->relocateable
)
2024 /* This is a relocateable link. We don't have to change
2025 anything, unless the reloc is against a section symbol,
2026 in which case we have to adjust according to where the
2027 section symbol winds up in the output section. */
2028 if (r_symndx
< symtab_hdr
->sh_info
)
2030 sym
= local_syms
+ r_symndx
;
2031 if ((unsigned)ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
2033 sec
= local_sections
[r_symndx
];
2034 addend
= rel
->r_addend
+= sec
->output_offset
+ sym
->st_value
;
2039 fprintf (stderr
, "\ttype = %s (%d), symbol index = %ld, offset = %ld, addend = %ld\n",
2049 /* This is a final link. */
2050 if (r_symndx
< symtab_hdr
->sh_info
)
2052 sym
= local_syms
+ r_symndx
;
2053 sec
= local_sections
[r_symndx
];
2054 relocation
= (sec
->output_section
->vma
2055 + sec
->output_offset
2060 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2061 if (h
->root
.type
== bfd_link_hash_defined
2062 || h
->root
.type
== bfd_link_hash_defweak
)
2064 sec
= h
->root
.u
.def
.section
;
2065 relocation
= (h
->root
.u
.def
.value
2066 + sec
->output_section
->vma
2067 + sec
->output_offset
);
2069 else if (h
->root
.type
== bfd_link_hash_undefweak
)
2071 else if (info
->shared
)
2075 (*info
->callbacks
->undefined_symbol
)(info
,
2076 h
->root
.root
.string
,
2085 switch ((int)r_type
)
2088 (*_bfd_error_handler
) ("%s: unknown relocation type %d",
2089 bfd_get_filename (input_bfd
),
2092 bfd_set_error (bfd_error_bad_value
);
2096 case R_PPC_NONE
: /* relocations that need no special processing */
2100 case R_PPC_ADDR16_LO
:
2101 case R_PPC_ADDR16_HI
:
2110 case (int)R_PPC_ADDR14_BRTAKEN
: /* branch taken prediction relocations */
2111 case (int)R_PPC_REL14_BRTAKEN
:
2112 insn
= bfd_get_32 (output_bfd
, contents
+ offset
);
2113 if ((relocation
- offset
) & 0x8000)
2114 insn
&= ~BRANCH_PREDICT_BIT
;
2116 insn
|= BRANCH_PREDICT_BIT
;
2117 bfd_put_32 (output_bfd
, insn
, contents
+ offset
);
2120 case (int)R_PPC_ADDR14_BRNTAKEN
: /* branch not taken predicition relocations */
2121 case (int)R_PPC_REL14_BRNTAKEN
:
2122 insn
= bfd_get_32 (output_bfd
, contents
+ offset
);
2123 if ((relocation
- offset
) & 0x8000)
2124 insn
|= BRANCH_PREDICT_BIT
;
2126 insn
&= ~BRANCH_PREDICT_BIT
;
2127 bfd_put_32 (output_bfd
, insn
, contents
+ offset
);
2130 case (int)R_PPC_GOT16
: /* GOT16 relocations */
2131 case (int)R_PPC_GOT16_LO
:
2132 case (int)R_PPC_GOT16_HI
:
2133 case (int)R_PPC_GOT16_HA
:
2135 fprintf (stderr
, "GOT relocations in section %s from section %s\n", input_section
->name
, sec
->name
);
2139 dynobj
= ppc_elf_create_dynamic_sections (output_bfd
, info
);
2147 BFD_ASSERT (sec
!= (asection
*)0);
2150 sgot
= bfd_get_section_by_name (dynobj
, ".got");
2151 BFD_ASSERT (sgot
!= NULL
);
2158 off
= h
->got_offset
;
2159 BFD_ASSERT (off
!= (bfd_vma
) -1);
2161 if (! elf_hash_table (info
)->dynamic_sections_created
2164 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
)))
2166 /* This is actually a static link, or it is a
2167 -Bsymbolic link and the symbol is defined
2168 locally. We must initialize this entry in the
2169 global offset table. Since the offset must
2170 always be a multiple of 4, we use the least
2171 significant bit to record whether we have
2172 initialized it already.
2174 When doing a dynamic link, we create a .rela.got
2175 relocation entry to initialize the value. This
2176 is done in the finish_dynamic_symbol routine. */
2181 bfd_put_32 (output_bfd
, relocation
,
2182 sgot
->contents
+ off
);
2187 relocation
= sgot
->output_offset
+ off
;
2193 BFD_ASSERT (local_got_offsets
!= NULL
2194 && local_got_offsets
[r_symndx
] != (bfd_vma
) -1);
2196 off
= local_got_offsets
[r_symndx
];
2198 /* The offset must always be a multiple of 4. We use
2199 the least significant bit to record whether we have
2200 already processed this entry. */
2205 bfd_put_32 (output_bfd
, relocation
, sgot
->contents
+ off
);
2210 Elf_Internal_Rela outrel
;
2212 /* We need to generate a R_PPC_RELATIVE reloc
2213 for the dynamic linker. */
2214 srelgot
= bfd_get_section_by_name (dynobj
, ".rela.got");
2215 BFD_ASSERT (srelgot
!= NULL
);
2217 outrel
.r_offset
= (sgot
->output_section
->vma
2218 + sgot
->output_offset
2220 outrel
.r_info
= ELF32_R_INFO (0, R_PPC_RELATIVE
);
2221 outrel
.r_addend
= 0;
2222 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
,
2223 (((Elf32_External_Rela
*)
2225 + srelgot
->reloc_count
));
2226 ++srelgot
->reloc_count
;
2229 local_got_offsets
[r_symndx
] |= 1;
2232 relocation
= sgot
->output_offset
+ off
;
2237 /* Handle the TOC16 reloc. We want to use the offset within the .got
2238 section, not the actual VMA. This is appropriate when generating
2239 an embedded ELF object, for which the .got section acts like the
2240 AIX .toc section. */
2241 case (int)R_PPC_TOC16
: /* phony GOT16 relocations */
2242 BFD_ASSERT (sec
!= (asection
*)0);
2243 BFD_ASSERT (bfd_is_und_section (sec
)
2244 || strcmp (bfd_get_section_name (abfd
, sec
), ".got") == 0
2245 || strcmp (bfd_get_section_name (abfd
, sec
), ".cgot") == 0)
2247 addend
-= sec
->output_section
->vma
+ 0x8000;
2250 case (int)R_PPC_ADDR16_HA
: /* arithmetic adjust relocations */
2251 BFD_ASSERT (sec
!= (asection
*)0);
2252 addend
+= ((relocation
+ addend
) & 0x8000) << 1;
2255 case R_PPC_SDAREL16
: /* relocate against _SDA_BASE_ */
2256 BFD_ASSERT (sec
!= (asection
*)0);
2257 if (strcmp (bfd_get_section_name (abfd
, sec
), ".sdata") != 0
2258 && strcmp (bfd_get_section_name (abfd
, sec
), ".sbss") != 0)
2260 (*_bfd_error_handler
) ("%s: The target of R_PPC_SDAREL16 relocations must be in section .sdata or .sbss not %s",
2261 bfd_get_filename (input_bfd
),
2262 bfd_get_section_name (abfd
, sec
));
2264 bfd_set_error (bfd_error_bad_value
);
2270 case R_PPC_EMB_SDA2REL
:
2271 BFD_ASSERT (sec
!= (asection
*)0);
2272 if (strcmp (bfd_get_section_name (abfd
, sec
), ".sdata2") != 0
2273 && strcmp (bfd_get_section_name (abfd
, sec
), ".sbss2") != 0)
2275 (*_bfd_error_handler
) ("%s: The target of R_PPC_SDA2REL16 relocations must be in section .sdata2 or .sbss2 not %s",
2276 bfd_get_filename (input_bfd
),
2277 bfd_get_section_name (abfd
, sec
));
2279 bfd_set_error (bfd_error_bad_value
);
2286 case R_PPC_PLTREL24
:
2288 case R_PPC_GLOB_DAT
:
2289 case R_PPC_JMP_SLOT
:
2290 case R_PPC_RELATIVE
:
2291 case R_PPC_LOCAL24PC
:
2293 case R_PPC_PLTREL32
:
2294 case R_PPC_PLT16_LO
:
2295 case R_PPC_PLT16_HI
:
2296 case R_PPC_PLT16_HA
:
2298 case R_PPC_SECTOFF_LO
:
2299 case R_PPC_SECTOFF_HI
:
2300 case R_PPC_SECTOFF_HA
:
2301 case R_PPC_EMB_NADDR32
:
2302 case R_PPC_EMB_NADDR16
:
2303 case R_PPC_EMB_NADDR16_LO
:
2304 case R_PPC_EMB_NADDR16_HI
:
2305 case R_PPC_EMB_NADDR16_HA
:
2306 case R_PPC_EMB_SDAI16
:
2307 case R_PPC_EMB_SDA2I16
:
2308 case R_PPC_EMB_SDA21
:
2309 case R_PPC_EMB_MRKREF
:
2310 case R_PPC_EMB_RELSEC16
:
2311 case R_PPC_EMB_RELST_LO
:
2312 case R_PPC_EMB_RELST_HI
:
2313 case R_PPC_EMB_RELST_HA
:
2314 case R_PPC_EMB_BIT_FLD
:
2315 case R_PPC_EMB_RELSDA
:
2317 (*_bfd_error_handler
) ("%s: Relocation %s is not yet supported.",
2318 bfd_get_filename (input_bfd
),
2319 ppc_elf_howto_table
[ (int)r_type
]->name
);
2321 bfd_set_error (bfd_error_bad_value
);
2328 fprintf (stderr
, "\ttype = %s (%d), symbol index = %ld, offset = %ld, addend = %ld\n",
2336 r
= _bfd_final_link_relocate (howto
,
2344 if (r
!= bfd_reloc_ok
)
2352 case bfd_reloc_overflow
:
2357 name
= h
->root
.root
.string
;
2360 name
= bfd_elf_string_from_elf_section (input_bfd
,
2361 symtab_hdr
->sh_link
,
2367 name
= bfd_section_name (input_bfd
, sec
);
2370 (*info
->callbacks
->reloc_overflow
)(info
,
2386 fprintf (stderr
, "\n");
2393 #define TARGET_LITTLE_SYM bfd_elf32_powerpcle_vec
2394 #define TARGET_LITTLE_NAME "elf32-powerpcle"
2395 #define TARGET_BIG_SYM bfd_elf32_powerpc_vec
2396 #define TARGET_BIG_NAME "elf32-powerpc"
2397 #define ELF_ARCH bfd_arch_powerpc
2398 #define ELF_MACHINE_CODE EM_PPC
2399 #define ELF_MAXPAGESIZE 0x10000
2400 #define elf_info_to_howto ppc_elf_info_to_howto
2402 #ifdef EM_CYGNUS_POWERPC
2403 #define ELF_MACHINE_ALT1 EM_CYGNUS_POWERPC
2407 #define ELF_MACHINE_ALT2 EM_PPC_OLD
2410 #define bfd_elf32_bfd_copy_private_bfd_data ppc_elf_copy_private_bfd_data
2411 #define bfd_elf32_bfd_merge_private_bfd_data ppc_elf_merge_private_bfd_data
2412 #define bfd_elf32_bfd_set_private_flags ppc_elf_set_private_flags
2413 #define bfd_elf32_bfd_reloc_type_lookup ppc_elf_reloc_type_lookup
2414 #define elf_backend_section_from_shdr ppc_elf_section_from_shdr
2415 #define elf_backend_relocate_section ppc_elf_relocate_section
2416 #define elf_backend_create_dynamic_sections _bfd_elf_create_dynamic_sections
2417 #define elf_backend_check_relocs ppc_elf_check_relocs
2418 #define elf_backend_adjust_dynamic_symbol ppc_elf_adjust_dynamic_symbol
2419 #define elf_backend_size_dynamic_sections ppc_elf_size_dynamic_sections
2420 #define elf_backend_finish_dynamic_symbol ppc_elf_finish_dynamic_symbol
2421 #define elf_backend_finish_dynamic_sections ppc_elf_finish_dynamic_sections
2422 #define elf_backend_fake_sections ppc_elf_fake_sections
2424 #include "elf32-target.h"