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 /* 32-bit section relative relocation. FIXME: not supported. */
685 HOWTO (R_PPC_SECTOFF
, /* type */
687 2, /* size (0 = byte, 1 = short, 2 = long) */
689 true, /* pc_relative */
691 complain_overflow_bitfield
, /* complain_on_overflow */
692 bfd_elf_generic_reloc
, /* special_function */
693 "R_PPC_SECTOFF", /* name */
694 false, /* partial_inplace */
697 true), /* pcrel_offset */
699 /* 16-bit lower half section relative relocation. FIXME: not supported. */
700 HOWTO (R_PPC_SECTOFF_LO
, /* type */
702 1, /* size (0 = byte, 1 = short, 2 = long) */
704 false, /* pc_relative */
706 complain_overflow_bitfield
, /* complain_on_overflow */
707 bfd_elf_generic_reloc
, /* special_function */
708 "R_PPC_SECTOFF_LO", /* name */
709 false, /* partial_inplace */
711 0xffff, /* dst_mask */
712 false), /* pcrel_offset */
714 /* 16-bit upper half section relative relocation. FIXME: not supported. */
715 HOWTO (R_PPC_SECTOFF_HI
, /* type */
717 1, /* size (0 = byte, 1 = short, 2 = long) */
719 false, /* pc_relative */
721 complain_overflow_bitfield
, /* complain_on_overflow */
722 bfd_elf_generic_reloc
, /* special_function */
723 "R_PPC_SECTOFF_HI", /* name */
724 false, /* partial_inplace */
726 0xffff, /* dst_mask */
727 false), /* pcrel_offset */
729 /* 16-bit upper half adjusted section relative relocation. FIXME: not supported. */
730 HOWTO (R_PPC_SECTOFF_HA
, /* type */
732 1, /* size (0 = byte, 1 = short, 2 = long) */
734 false, /* pc_relative */
736 complain_overflow_bitfield
, /* complain_on_overflow */
737 bfd_elf_generic_reloc
, /* special_function */
738 "R_PPC_SECTOFF_HA", /* name */
739 false, /* partial_inplace */
741 0xffff, /* dst_mask */
742 false), /* pcrel_offset */
744 /* The remaining relocs are from the Embedded ELF ABI, and are not
745 in the SVR4 ELF ABI. */
747 /* 32 bit value resulting from the addend minus the symbol */
748 HOWTO (R_PPC_EMB_NADDR32
, /* type */
750 2, /* size (0 = byte, 1 = short, 2 = long) */
752 false, /* pc_relative */
754 complain_overflow_bitfield
, /* complain_on_overflow */
755 bfd_elf_generic_reloc
, /* special_function */
756 "R_PPC_EMB_NADDR32", /* name */
757 false, /* partial_inplace */
759 0xffffffff, /* dst_mask */
760 false), /* pcrel_offset */
762 /* 16 bit value resulting from the addend minus the symbol */
763 HOWTO (R_PPC_EMB_NADDR16
, /* type */
765 1, /* size (0 = byte, 1 = short, 2 = long) */
767 false, /* pc_relative */
769 complain_overflow_bitfield
, /* complain_on_overflow */
770 bfd_elf_generic_reloc
, /* special_function */
771 "R_PPC_EMB_NADDR16", /* name */
772 false, /* partial_inplace */
774 0xffff, /* dst_mask */
775 false), /* pcrel_offset */
777 /* 16 bit value resulting from the addend minus the symbol */
778 HOWTO (R_PPC_EMB_NADDR16_LO
, /* type */
780 1, /* size (0 = byte, 1 = short, 2 = long) */
782 false, /* pc_relative */
784 complain_overflow_dont
,/* complain_on_overflow */
785 bfd_elf_generic_reloc
, /* special_function */
786 "R_PPC_EMB_ADDR16_LO", /* name */
787 false, /* partial_inplace */
789 0xffff, /* dst_mask */
790 false), /* pcrel_offset */
792 /* The high order 16 bits of the addend minus the symbol */
793 HOWTO (R_PPC_EMB_NADDR16_HI
, /* type */
795 1, /* size (0 = byte, 1 = short, 2 = long) */
797 false, /* pc_relative */
799 complain_overflow_dont
, /* complain_on_overflow */
800 bfd_elf_generic_reloc
, /* special_function */
801 "R_PPC_EMB_NADDR16_HI", /* name */
802 false, /* partial_inplace */
804 0xffff, /* dst_mask */
805 false), /* pcrel_offset */
807 /* The high order 16 bits of the result of the addend minus the address,
808 plus 1 if the contents of the low 16 bits, treated as a signed number,
810 HOWTO (R_PPC_EMB_NADDR16_HA
, /* type */
812 1, /* size (0 = byte, 1 = short, 2 = long) */
814 false, /* pc_relative */
816 complain_overflow_dont
, /* complain_on_overflow */
817 bfd_elf_generic_reloc
, /* special_function */
818 "R_PPC_EMB_NADDR16_HA", /* name */
819 false, /* partial_inplace */
821 0xffff, /* dst_mask */
822 false), /* pcrel_offset */
824 /* 16 bit value resulting from allocating a 4 byte word to hold an
825 address in the .sdata section, and returning the offset from
826 _SDA_BASE_ for that relocation */
827 HOWTO (R_PPC_EMB_SDAI16
, /* type */
829 1, /* size (0 = byte, 1 = short, 2 = long) */
831 false, /* pc_relative */
833 complain_overflow_bitfield
, /* complain_on_overflow */
834 bfd_elf_generic_reloc
, /* special_function */
835 "R_PPC_EMB_SDAI16", /* name */
836 false, /* partial_inplace */
838 0xffff, /* dst_mask */
839 false), /* pcrel_offset */
841 /* 16 bit value resulting from allocating a 4 byte word to hold an
842 address in the .sdata2 section, and returning the offset from
843 _SDA2_BASE_ for that relocation */
844 HOWTO (R_PPC_EMB_SDA2I16
, /* type */
846 1, /* size (0 = byte, 1 = short, 2 = long) */
848 false, /* pc_relative */
850 complain_overflow_bitfield
, /* complain_on_overflow */
851 bfd_elf_generic_reloc
, /* special_function */
852 "R_PPC_EMB_SDA2I16", /* name */
853 false, /* partial_inplace */
855 0xffff, /* dst_mask */
856 false), /* pcrel_offset */
858 /* A sign-extended 16 bit value relative to _SDA2_BASE_, for use with
859 small data items. FIXME: Not supported. */
860 HOWTO (R_PPC_EMB_SDA2REL
, /* type */
862 1, /* size (0 = byte, 1 = short, 2 = long) */
864 false, /* pc_relative */
866 complain_overflow_signed
, /* complain_on_overflow */
867 bfd_elf_generic_reloc
, /* special_function */
868 "R_PPC_EMB_SDA2REL", /* name */
869 false, /* partial_inplace */
871 0xffff, /* dst_mask */
872 false), /* pcrel_offset */
874 /* Relocate against either _SDA_BASE_ or _SDA2_BASE_, filling in the 16 bit
875 signed offset from the appropriate base, and filling in the register
876 field with the appropriate register (0, 2, or 13). */
877 HOWTO (R_PPC_EMB_SDA21
, /* type */
879 1, /* size (0 = byte, 1 = short, 2 = long) */
881 false, /* pc_relative */
883 complain_overflow_signed
, /* complain_on_overflow */
884 bfd_elf_generic_reloc
, /* special_function */
885 "R_PPC_EMB_SDA21", /* name */
886 false, /* partial_inplace */
888 0xffff, /* dst_mask */
889 false), /* pcrel_offset */
891 /* Relocation not handled: R_PPC_EMB_MRKREF */
892 /* Relocation not handled: R_PPC_EMB_RELSEC16 */
893 /* Relocation not handled: R_PPC_EMB_RELST_LO */
894 /* Relocation not handled: R_PPC_EMB_RELST_HI */
895 /* Relocation not handled: R_PPC_EMB_RELST_HA */
896 /* Relocation not handled: R_PPC_EMB_BIT_FLD */
898 /* PC relative relocation against either _SDA_BASE_ or _SDA2_BASE_, filling
899 in the 16 bit signed offset from the appropriate base, and filling in the
900 register field with the appropriate register (0, 2, or 13). */
901 HOWTO (R_PPC_EMB_RELSDA
, /* type */
903 1, /* size (0 = byte, 1 = short, 2 = long) */
905 true, /* pc_relative */
907 complain_overflow_signed
, /* complain_on_overflow */
908 bfd_elf_generic_reloc
, /* special_function */
909 "R_PPC_EMB_RELSDA", /* name */
910 false, /* partial_inplace */
912 0xffff, /* dst_mask */
913 false), /* pcrel_offset */
915 /* Phony reloc to handle AIX style TOC entries */
916 HOWTO (R_PPC_TOC16
, /* type */
918 1, /* size (0 = byte, 1 = short, 2 = long) */
920 false, /* pc_relative */
922 complain_overflow_signed
, /* complain_on_overflow */
923 bfd_elf_generic_reloc
, /* special_function */
924 "R_PPC_TOC16", /* name */
925 false, /* partial_inplace */
927 0xffff, /* dst_mask */
928 false), /* pcrel_offset */
932 /* Initialize the ppc_elf_howto_table, so that linear accesses can be done. */
935 ppc_elf_howto_init ()
937 unsigned int i
, type
;
939 for (i
= 0; i
< sizeof (ppc_elf_howto_raw
) / sizeof (ppc_elf_howto_raw
[0]); i
++)
941 type
= ppc_elf_howto_raw
[i
].type
;
942 BFD_ASSERT (type
< sizeof(ppc_elf_howto_table
) / sizeof(ppc_elf_howto_table
[0]));
943 ppc_elf_howto_table
[type
] = &ppc_elf_howto_raw
[i
];
948 static reloc_howto_type
*
949 ppc_elf_reloc_type_lookup (abfd
, code
)
951 bfd_reloc_code_real_type code
;
953 enum ppc_reloc_type ppc_reloc
= R_PPC_NONE
;
955 if (!ppc_elf_howto_table
[ R_PPC_ADDR32
]) /* Initialize howto table if needed */
956 ppc_elf_howto_init ();
961 return (reloc_howto_type
*)NULL
;
963 case BFD_RELOC_NONE
: ppc_reloc
= R_PPC_NONE
; break;
964 case BFD_RELOC_32
: ppc_reloc
= R_PPC_ADDR32
; break;
965 case BFD_RELOC_PPC_BA26
: ppc_reloc
= R_PPC_ADDR24
; break;
966 case BFD_RELOC_16
: ppc_reloc
= R_PPC_ADDR16
; break;
967 case BFD_RELOC_LO16
: ppc_reloc
= R_PPC_ADDR16_LO
; break;
968 case BFD_RELOC_HI16
: ppc_reloc
= R_PPC_ADDR16_HI
; break;
969 case BFD_RELOC_HI16_S
: ppc_reloc
= R_PPC_ADDR16_HA
; break;
970 case BFD_RELOC_PPC_BA16
: ppc_reloc
= R_PPC_ADDR14
; break;
971 case BFD_RELOC_PPC_BA16_BRTAKEN
: ppc_reloc
= R_PPC_ADDR14_BRTAKEN
; break;
972 case BFD_RELOC_PPC_BA16_BRNTAKEN
: ppc_reloc
= R_PPC_ADDR14_BRNTAKEN
; break;
973 case BFD_RELOC_PPC_B26
: ppc_reloc
= R_PPC_REL24
; break;
974 case BFD_RELOC_PPC_B16
: ppc_reloc
= R_PPC_REL14
; break;
975 case BFD_RELOC_PPC_B16_BRTAKEN
: ppc_reloc
= R_PPC_REL14_BRTAKEN
; break;
976 case BFD_RELOC_PPC_B16_BRNTAKEN
: ppc_reloc
= R_PPC_REL14_BRNTAKEN
; break;
977 case BFD_RELOC_16_GOTOFF
: ppc_reloc
= R_PPC_GOT16
; break;
978 case BFD_RELOC_LO16_GOTOFF
: ppc_reloc
= R_PPC_GOT16_LO
; break;
979 case BFD_RELOC_HI16_GOTOFF
: ppc_reloc
= R_PPC_GOT16_HI
; break;
980 case BFD_RELOC_HI16_S_GOTOFF
: ppc_reloc
= R_PPC_GOT16_HA
; break;
981 case BFD_RELOC_24_PLT_PCREL
: ppc_reloc
= R_PPC_PLTREL24
; break;
982 case BFD_RELOC_PPC_COPY
: ppc_reloc
= R_PPC_COPY
; break;
983 case BFD_RELOC_PPC_GLOB_DAT
: ppc_reloc
= R_PPC_GLOB_DAT
; break;
984 case BFD_RELOC_PPC_LOCAL24PC
: ppc_reloc
= R_PPC_LOCAL24PC
; break;
985 case BFD_RELOC_32_PCREL
: ppc_reloc
= R_PPC_REL32
; break;
986 case BFD_RELOC_32_PLTOFF
: ppc_reloc
= R_PPC_PLT32
; break;
987 case BFD_RELOC_32_PLT_PCREL
: ppc_reloc
= R_PPC_PLTREL32
; break;
988 case BFD_RELOC_LO16_PLTOFF
: ppc_reloc
= R_PPC_PLT16_LO
; break;
989 case BFD_RELOC_HI16_PLTOFF
: ppc_reloc
= R_PPC_PLT16_HI
; break;
990 case BFD_RELOC_HI16_S_PLTOFF
: ppc_reloc
= R_PPC_PLT16_HA
; break;
991 case BFD_RELOC_GPREL16
: ppc_reloc
= R_PPC_SDAREL16
; break;
992 case BFD_RELOC_32_BASEREL
: ppc_reloc
= R_PPC_SECTOFF
; break;
993 case BFD_RELOC_LO16_BASEREL
: ppc_reloc
= R_PPC_SECTOFF_LO
; break;
994 case BFD_RELOC_HI16_BASEREL
: ppc_reloc
= R_PPC_SECTOFF_HI
; break;
995 case BFD_RELOC_HI16_S_BASEREL
: ppc_reloc
= R_PPC_SECTOFF_HA
; break;
996 case BFD_RELOC_CTOR
: ppc_reloc
= R_PPC_ADDR32
; break;
997 case BFD_RELOC_PPC_TOC16
: ppc_reloc
= R_PPC_TOC16
; break;
998 case BFD_RELOC_PPC_EMB_NADDR32
: ppc_reloc
= R_PPC_EMB_NADDR32
; break;
999 case BFD_RELOC_PPC_EMB_NADDR16
: ppc_reloc
= R_PPC_EMB_NADDR16
; break;
1000 case BFD_RELOC_PPC_EMB_NADDR16_LO
: ppc_reloc
= R_PPC_EMB_NADDR16_LO
; break;
1001 case BFD_RELOC_PPC_EMB_NADDR16_HI
: ppc_reloc
= R_PPC_EMB_NADDR16_HI
; break;
1002 case BFD_RELOC_PPC_EMB_NADDR16_HA
: ppc_reloc
= R_PPC_EMB_NADDR16_HA
; break;
1003 case BFD_RELOC_PPC_EMB_SDAI16
: ppc_reloc
= R_PPC_EMB_SDAI16
; break;
1004 case BFD_RELOC_PPC_EMB_SDA2I16
: ppc_reloc
= R_PPC_EMB_SDA2I16
; break;
1005 case BFD_RELOC_PPC_EMB_SDA2REL
: ppc_reloc
= R_PPC_EMB_SDA2REL
; break;
1006 case BFD_RELOC_PPC_EMB_SDA21
: ppc_reloc
= R_PPC_EMB_SDA21
; break;
1007 case BFD_RELOC_PPC_EMB_MRKREF
: ppc_reloc
= R_PPC_EMB_MRKREF
; break;
1008 case BFD_RELOC_PPC_EMB_RELSEC16
: ppc_reloc
= R_PPC_EMB_RELSEC16
; break;
1009 case BFD_RELOC_PPC_EMB_RELST_LO
: ppc_reloc
= R_PPC_EMB_RELST_LO
; break;
1010 case BFD_RELOC_PPC_EMB_RELST_HI
: ppc_reloc
= R_PPC_EMB_RELST_HI
; break;
1011 case BFD_RELOC_PPC_EMB_RELST_HA
: ppc_reloc
= R_PPC_EMB_RELST_HA
; break;
1012 case BFD_RELOC_PPC_EMB_BIT_FLD
: ppc_reloc
= R_PPC_EMB_BIT_FLD
; break;
1013 case BFD_RELOC_PPC_EMB_RELSDA
: ppc_reloc
= R_PPC_EMB_RELSDA
; break;
1016 return ppc_elf_howto_table
[ (int)ppc_reloc
];
1019 /* Set the howto pointer for a PowerPC ELF reloc. */
1022 ppc_elf_info_to_howto (abfd
, cache_ptr
, dst
)
1025 Elf32_Internal_Rela
*dst
;
1027 if (!ppc_elf_howto_table
[ R_PPC_ADDR32
]) /* Initialize howto table if needed */
1028 ppc_elf_howto_init ();
1030 BFD_ASSERT (ELF32_R_TYPE (dst
->r_info
) < (unsigned int) R_PPC_max
);
1031 cache_ptr
->howto
= ppc_elf_howto_table
[ELF32_R_TYPE (dst
->r_info
)];
1034 /* Function to set whether a module needs the -mrelocatable bit set. */
1037 ppc_elf_set_private_flags (abfd
, flags
)
1041 BFD_ASSERT (!elf_flags_init (abfd
)
1042 || elf_elfheader (abfd
)->e_flags
== flags
);
1044 elf_elfheader (abfd
)->e_flags
= flags
;
1045 elf_flags_init (abfd
) = true;
1049 /* Copy backend specific data from one object module to another */
1051 ppc_elf_copy_private_bfd_data (ibfd
, obfd
)
1055 /* This function is selected based on the input vector. We only
1056 want to copy information over if the output BFD also uses Elf
1058 if (bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
1061 BFD_ASSERT (!elf_flags_init (obfd
)
1062 || elf_elfheader (obfd
)->e_flags
== elf_elfheader (ibfd
)->e_flags
);
1064 elf_elfheader (obfd
)->e_flags
= elf_elfheader (ibfd
)->e_flags
;
1065 elf_flags_init (obfd
) = true;
1069 /* Merge backend specific data from an object file to the output
1070 object file when linking */
1072 ppc_elf_merge_private_bfd_data (ibfd
, obfd
)
1080 /* Check if we have the same endianess */
1081 if (ibfd
->xvec
->byteorder
!= obfd
->xvec
->byteorder
1082 && obfd
->xvec
->byteorder
!= BFD_ENDIAN_UNKNOWN
)
1084 (*_bfd_error_handler
)
1085 ("%s: compiled for a %s endian system and target is %s endian",
1086 bfd_get_filename (ibfd
),
1087 bfd_big_endian (ibfd
) ? "big" : "little",
1088 bfd_big_endian (obfd
) ? "big" : "little");
1090 bfd_set_error (bfd_error_wrong_format
);
1094 /* This function is selected based on the input vector. We only
1095 want to copy information over if the output BFD also uses Elf
1097 if (bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
1100 new_flags
= elf_elfheader (ibfd
)->e_flags
;
1101 old_flags
= elf_elfheader (obfd
)->e_flags
;
1102 if (!elf_flags_init (obfd
)) /* First call, no flags set */
1104 elf_flags_init (obfd
) = true;
1105 elf_elfheader (obfd
)->e_flags
= new_flags
;
1108 else if (new_flags
== old_flags
) /* Compatible flags are ok */
1111 else /* Incompatible flags */
1113 /* Warn about -mrelocatable mismatch. Allow -mrelocatable-lib to be linked
1116 if ((new_flags
& EF_PPC_RELOCATABLE
) != 0
1117 && (old_flags
& (EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
)) == 0)
1120 (*_bfd_error_handler
)
1121 ("%s: compiled with -mrelocatable and linked with modules compiled normally",
1122 bfd_get_filename (ibfd
));
1124 else if ((new_flags
& (EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
)) == 0
1125 && (old_flags
& EF_PPC_RELOCATABLE
) != 0)
1128 (*_bfd_error_handler
)
1129 ("%s: compiled normally and linked with modules compiled with -mrelocatable",
1130 bfd_get_filename (ibfd
));
1132 else if ((new_flags
& EF_PPC_RELOCATABLE_LIB
) != 0)
1133 elf_elfheader (obfd
)->e_flags
|= EF_PPC_RELOCATABLE_LIB
;
1135 new_flags
&= ~ (EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
);
1136 old_flags
&= ~ (EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
);
1138 /* Warn about eabi vs. V.4 mismatch */
1139 if ((new_flags
& EF_PPC_EMB
) != 0 && (old_flags
& EF_PPC_EMB
) == 0)
1141 new_flags
&= ~EF_PPC_EMB
;
1143 (*_bfd_error_handler
)
1144 ("%s: compiled for the eabi and linked with modules compiled for System V",
1145 bfd_get_filename (ibfd
));
1147 else if ((new_flags
& EF_PPC_EMB
) == 0 && (old_flags
& EF_PPC_EMB
) != 0)
1149 old_flags
&= ~EF_PPC_EMB
;
1151 (*_bfd_error_handler
)
1152 ("%s: compiled for System V and linked with modules compiled for eabi",
1153 bfd_get_filename (ibfd
));
1156 /* Warn about any other mismatches */
1157 if (new_flags
!= old_flags
)
1160 (*_bfd_error_handler
)
1161 ("%s: uses different e_flags (0x%lx) fields than previous modules (0x%lx)",
1162 bfd_get_filename (ibfd
), (long)new_flags
, (long)old_flags
);
1167 bfd_set_error (bfd_error_bad_value
);
1176 /* Handle a PowerPC specific section when reading an object file. This
1177 is called when elfcode.h finds a section with an unknown type. */
1180 ppc_elf_section_from_shdr (abfd
, hdr
, name
)
1182 Elf32_Internal_Shdr
*hdr
;
1188 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
))
1191 newsect
= hdr
->bfd_section
;
1192 flags
= bfd_get_section_flags (abfd
, newsect
);
1193 if (hdr
->sh_flags
& SHF_EXCLUDE
)
1194 flags
|= SEC_EXCLUDE
;
1196 if (hdr
->sh_type
== SHT_ORDERED
)
1197 flags
|= SEC_SORT_ENTRIES
;
1199 bfd_set_section_flags (abfd
, newsect
, flags
);
1204 /* Set up any other section flags and such that may be necessary. */
1207 ppc_elf_fake_sections (abfd
, shdr
, asect
)
1209 Elf32_Internal_Shdr
*shdr
;
1212 if ((asect
->flags
& SEC_EXCLUDE
) != 0)
1213 shdr
->sh_flags
|= SHF_EXCLUDE
;
1215 if ((asect
->flags
& SEC_SORT_ENTRIES
) != 0)
1216 shdr
->sh_type
= SHT_ORDERED
;
1220 /* Create the PowerPC dynamic sections */
1223 ppc_elf_create_dynamic_sections (abfd
, info
)
1225 struct bfd_link_info
*info
;
1227 struct elf_link_hash_entry
*h
;
1228 struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
1230 /* Create the .got section. */
1231 if (! _bfd_elf_create_got_section (abfd
, info
))
1234 /* Also create the .got.neg section where we put negative offsets */
1235 if (bfd_get_section_by_name (abfd
, ".got.neg") == NULL
)
1237 asection
*s
= bfd_make_section (abfd
, ".got.neg");
1239 || !bfd_set_section_flags (abfd
, s
,
1240 SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
)
1241 || !bfd_set_section_alignment (abfd
, s
, 2))
1245 elf_hash_table (info
)->dynobj
= abfd
;
1250 /* Adjust a symbol defined by a dynamic object and referenced by a
1251 regular object. The current definition is in some section of the
1252 dynamic object, but we're not including those sections. We have to
1253 change the definition to something the rest of the link can
1257 ppc_elf_adjust_dynamic_symbol (info
, h
)
1258 struct bfd_link_info
*info
;
1259 struct elf_link_hash_entry
*h
;
1262 fprintf (stderr
, "ppc_elf_adjust_dynamic_symbol called\n");
1268 /* Increment the index of a dynamic symbol by a given amount. Called
1269 via elf_link_hash_traverse. */
1272 ppc_elf_adjust_dynindx (h
, cparg
)
1273 struct elf_link_hash_entry
*h
;
1276 int *cp
= (int *) cparg
;
1279 fprintf (stderr
, "ppc_elf_adjust_dynindx called, h->dynindx = %d, *cp = %d\n", h
->dynindx
, *cp
);
1282 if (h
->dynindx
!= -1)
1289 /* Set the sizes of the dynamic sections. */
1292 ppc_elf_size_dynamic_sections (output_bfd
, info
)
1294 struct bfd_link_info
*info
;
1302 fprintf (stderr
, "ppc_elf_size_dynamic_sections called\n");
1305 dynobj
= elf_hash_table (info
)->dynobj
;
1306 BFD_ASSERT (dynobj
!= NULL
);
1308 if (elf_hash_table (info
)->dynamic_sections_created
)
1310 /* Set the contents of the .interp section to the interpreter. */
1313 s
= bfd_get_section_by_name (dynobj
, ".interp");
1314 BFD_ASSERT (s
!= NULL
);
1315 s
->_raw_size
= sizeof ELF_DYNAMIC_INTERPRETER
;
1316 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
1319 /* Make space for the trailing nop in .plt. */
1320 s
= bfd_get_section_by_name (dynobj
, ".plt");
1321 BFD_ASSERT (s
!= NULL
);
1322 if (s
->_raw_size
> 0)
1327 /* We may have created entries in the .rela.got section.
1328 However, if we are not creating the dynamic sections, we will
1329 not actually use these entries. Reset the size of .rela.got,
1330 which will cause it to get stripped from the output file
1332 s
= bfd_get_section_by_name (dynobj
, ".rela.got");
1336 /* Ditto for .rela.got.neg */
1337 s
= bfd_get_section_by_name (dynobj
, ".rela.got.neg");
1342 /* The check_relocs and adjust_dynamic_symbol entry points have
1343 determined the sizes of the various dynamic sections. Allocate
1347 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
1352 if ((s
->flags
& SEC_IN_MEMORY
) == 0)
1355 /* It's OK to base decisions on the section name, because none
1356 of the dynobj section names depend upon the input files. */
1357 name
= bfd_get_section_name (dynobj
, s
);
1361 if (strncmp (name
, ".rela", 5) == 0)
1363 if (s
->_raw_size
== 0)
1365 /* If we don't need this section, strip it from the
1366 output file. This is to handle .rela.bss and
1367 .rel.plt. We must create it in
1368 create_dynamic_sections, because it must be created
1369 before the linker maps input sections to output
1370 sections. The linker does that before
1371 adjust_dynamic_symbol is called, and it is that
1372 function which decides whether anything needs to go
1373 into these sections. */
1380 /* If this relocation section applies to a read only
1381 section, then we probably need a DT_TEXTREL entry. */
1382 target
= bfd_get_section_by_name (output_bfd
, name
+ 5);
1384 && (target
->flags
& SEC_READONLY
) != 0)
1387 if (strcmp (name
, ".rela.plt") == 0)
1390 /* We use the reloc_count field as a counter if we need
1391 to copy relocs into the output file. */
1395 else if (strcmp (name
, ".plt") != 0
1396 && strcmp (name
, ".got") != 0
1397 && strcmp (name
, ".got.neg") != 0)
1399 /* It's not one of our sections, so don't allocate space. */
1407 for (spp
= &s
->output_section
->owner
->sections
;
1408 *spp
!= s
->output_section
;
1409 spp
= &(*spp
)->next
)
1411 *spp
= s
->output_section
->next
;
1412 --s
->output_section
->owner
->section_count
;
1417 /* Allocate memory for the section contents. */
1418 s
->contents
= (bfd_byte
*) bfd_alloc (dynobj
, s
->_raw_size
);
1419 if (s
->contents
== NULL
&& s
->_raw_size
!= 0)
1423 if (elf_hash_table (info
)->dynamic_sections_created
)
1425 /* Add some entries to the .dynamic section. We fill in the
1426 values later, in ppc_elf_finish_dynamic_sections, but we
1427 must add the entries now so that we get the correct size for
1428 the .dynamic section. The DT_DEBUG entry is filled in by the
1429 dynamic linker and used by the debugger. */
1432 if (! bfd_elf32_add_dynamic_entry (info
, DT_DEBUG
, 0))
1436 if (! bfd_elf32_add_dynamic_entry (info
, DT_PLTGOT
, 0))
1441 if (! bfd_elf32_add_dynamic_entry (info
, DT_PLTRELSZ
, 0)
1442 || ! bfd_elf32_add_dynamic_entry (info
, DT_PLTREL
, DT_RELA
)
1443 || ! bfd_elf32_add_dynamic_entry (info
, DT_JMPREL
, 0))
1447 if (! bfd_elf32_add_dynamic_entry (info
, DT_RELA
, 0)
1448 || ! bfd_elf32_add_dynamic_entry (info
, DT_RELASZ
, 0)
1449 || ! bfd_elf32_add_dynamic_entry (info
, DT_RELAENT
,
1450 sizeof (Elf32_External_Rela
)))
1455 if (! bfd_elf32_add_dynamic_entry (info
, DT_TEXTREL
, 0))
1460 /* If we are generating a shared library, we generate a section
1461 symbol for each output section. These are local symbols, which
1462 means that they must come first in the dynamic symbol table.
1463 That means we must increment the dynamic symbol index of every
1464 other dynamic symbol. */
1469 c
= bfd_count_sections (output_bfd
);
1470 elf_link_hash_traverse (elf_hash_table (info
),
1471 ppc_elf_adjust_dynindx
,
1473 elf_hash_table (info
)->dynsymcount
+= c
;
1475 for (i
= 1, s
= output_bfd
->sections
; s
!= NULL
; s
= s
->next
, i
++)
1477 elf_section_data (s
)->dynindx
= i
;
1478 /* These symbols will have no names, so we don't need to
1479 fiddle with dynstr_index. */
1487 /* Look through the relocs for a section during the first phase, and
1488 allocate space in the global offset table or procedure linkage
1492 ppc_elf_check_relocs (abfd
, info
, sec
, relocs
)
1494 struct bfd_link_info
*info
;
1496 const Elf_Internal_Rela
*relocs
;
1499 Elf_Internal_Shdr
*symtab_hdr
;
1500 struct elf_link_hash_entry
**sym_hashes
;
1501 bfd_vma
*local_got_offsets
;
1502 const Elf_Internal_Rela
*rel
;
1503 const Elf_Internal_Rela
*rel_end
;
1507 asection
*srelgot_neg
;
1510 if (info
->relocateable
)
1514 fprintf (stderr
, "ppc_elf_check_relocs called for section %s\n", sec
->name
);
1517 dynobj
= elf_hash_table (info
)->dynobj
;
1518 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
1519 sym_hashes
= elf_sym_hashes (abfd
);
1520 local_got_offsets
= elf_local_got_offsets (abfd
);
1526 rel_end
= relocs
+ sec
->reloc_count
;
1527 for (rel
= relocs
; rel
< rel_end
; rel
++)
1529 unsigned long r_symndx
;
1530 struct elf_link_hash_entry
*h
;
1532 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1533 if (r_symndx
< symtab_hdr
->sh_info
)
1536 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1538 switch (ELF32_R_TYPE (rel
->r_info
))
1541 case R_PPC_GOT16_LO
:
1542 case R_PPC_GOT16_HI
:
1543 case R_PPC_GOT16_HA
:
1545 fprintf (stderr
, "Reloc requires a GOT entry\n");
1547 /* This symbol requires a global offset table entry. */
1551 dynobj
= ppc_elf_create_dynamic_sections (abfd
, info
);
1558 sgot
= bfd_get_section_by_name (dynobj
, ".got");
1559 sgot_neg
= bfd_get_section_by_name (dynobj
, ".got.neg");
1560 BFD_ASSERT (sgot
!= NULL
&& sgot_neg
!= NULL
);
1564 && (h
!= NULL
|| info
->shared
))
1566 srelgot
= bfd_get_section_by_name (dynobj
, ".rela.got");
1567 if (srelgot
== NULL
)
1569 srelgot
= bfd_make_section (dynobj
, ".rela.got");
1571 || ! bfd_set_section_flags (dynobj
, srelgot
,
1577 || ! bfd_set_section_alignment (dynobj
, srelgot
, 2))
1581 srelgot_neg
= bfd_get_section_by_name (dynobj
, ".rela.got.neg");
1582 if (srelgot_neg
== NULL
)
1584 srelgot_neg
= bfd_make_section (dynobj
, ".rela.got.neg");
1586 || ! bfd_set_section_flags (dynobj
, srelgot_neg
,
1592 || ! bfd_set_section_alignment (dynobj
, srelgot
, 2))
1599 if (h
->got_offset
!= (bfd_vma
) -1)
1601 /* We have already allocated space in the .got. */
1604 h
->got_offset
= sgot
->_raw_size
;
1606 /* Make sure this symbol is output as a dynamic symbol. */
1607 if (h
->dynindx
== -1)
1609 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
1613 srelgot
->_raw_size
+= sizeof (Elf32_External_Rela
);
1617 /* This is a global offset table entry for a local
1619 if (local_got_offsets
== NULL
)
1622 register unsigned int i
;
1624 size
= symtab_hdr
->sh_info
* sizeof (bfd_vma
);
1625 local_got_offsets
= (bfd_vma
*) bfd_alloc (abfd
, size
);
1626 if (local_got_offsets
== NULL
)
1628 elf_local_got_offsets (abfd
) = local_got_offsets
;
1629 for (i
= 0; i
< symtab_hdr
->sh_info
; i
++)
1630 local_got_offsets
[i
] = (bfd_vma
) -1;
1632 if (local_got_offsets
[r_symndx
] != (bfd_vma
) -1)
1634 /* We have already allocated space in the .got. */
1637 local_got_offsets
[r_symndx
] = sgot
->_raw_size
;
1641 /* If we are generating a shared object, we need to
1642 output a R_PPC_RELATIVE reloc so that the
1643 dynamic linker can adjust this GOT entry. */
1644 srelgot
->_raw_size
+= sizeof (Elf32_External_Rela
);
1648 sgot
->_raw_size
+= 4;
1653 case R_PPC_PLTREL24
:
1654 case R_PPC_PLT16_LO
:
1655 case R_PPC_PLT16_HI
:
1656 case R_PPC_PLT16_HA
:
1658 fprintf (stderr
, "Reloc requires a PLT entry\n");
1660 /* This symbol requires a procedure linkage table entry. We
1661 actually build the entry in adjust_dynamic_symbol,
1662 because this might be a case of linking PIC code without
1663 linking in any dynamic objects, in which case we don't
1664 need to generate a procedure linkage table after all. */
1668 /* It does not make sense to have a procedure linkage
1669 table entry for a local symbol. */
1670 bfd_set_error (bfd_error_bad_value
);
1674 /* Make sure this symbol is output as a dynamic symbol. */
1675 if (h
->dynindx
== -1)
1677 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
1681 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
1688 && strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
1692 case R_SPARC_DISP16
:
1693 case R_SPARC_DISP32
:
1694 case R_SPARC_WDISP30
:
1695 case R_SPARC_WDISP22
:
1708 && (sec
->flags
& SEC_ALLOC
) != 0)
1710 /* When creating a shared object, we must copy these
1711 relocs into the output file. We create a reloc
1712 section in dynobj and make room for the reloc. */
1717 name
= (bfd_elf_string_from_elf_section
1719 elf_elfheader (abfd
)->e_shstrndx
,
1720 elf_section_data (sec
)->rel_hdr
.sh_name
));
1724 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
1725 && strcmp (bfd_get_section_name (abfd
, sec
),
1728 sreloc
= bfd_get_section_by_name (dynobj
, name
);
1731 sreloc
= bfd_make_section (dynobj
, name
);
1733 || ! bfd_set_section_flags (dynobj
, sreloc
,
1739 || ! bfd_set_section_alignment (dynobj
, sreloc
, 2))
1744 sreloc
->_raw_size
+= sizeof (Elf32_External_Rela
);
1759 /* Finish up dynamic symbol handling. We set the contents of various
1760 dynamic sections here. */
1763 ppc_elf_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
1765 struct bfd_link_info
*info
;
1766 struct elf_link_hash_entry
*h
;
1767 Elf_Internal_Sym
*sym
;
1772 fprintf (stderr
, "ppc_elf_finish_dynamic_symbol called\n");
1775 dynobj
= elf_hash_table (info
)->dynobj
;
1777 if (h
->plt_offset
!= (bfd_vma
) -1)
1781 Elf_Internal_Rela rela
;
1783 /* This symbol has an entry in the procedure linkage table. Set
1786 BFD_ASSERT (h
->dynindx
!= -1);
1788 splt
= bfd_get_section_by_name (dynobj
, ".plt");
1789 srela
= bfd_get_section_by_name (dynobj
, ".rela.plt");
1790 BFD_ASSERT (splt
!= NULL
&& srela
!= NULL
);
1792 /* Fill in the entry in the procedure linkage table. */
1794 bfd_put_32 (output_bfd
,
1795 PLT_ENTRY_WORD0
+ h
->plt_offset
,
1796 splt
->contents
+ h
->plt_offset
);
1797 bfd_put_32 (output_bfd
,
1799 + (((- (h
->plt_offset
+ 4)) >> 2) & 0x3fffff)),
1800 splt
->contents
+ h
->plt_offset
+ 4);
1801 bfd_put_32 (output_bfd
, PLT_ENTRY_WORD2
,
1802 splt
->contents
+ h
->plt_offset
+ 8);
1804 /* Fill in the entry in the .rela.plt section. */
1805 rela
.r_offset
= (splt
->output_section
->vma
1806 + splt
->output_offset
1808 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_SPARC_JMP_SLOT
);
1810 bfd_elf32_swap_reloca_out (output_bfd
, &rela
,
1811 ((Elf32_External_Rela
*) srela
->contents
1812 + h
->plt_offset
/ PLT_ENTRY_SIZE
- 4));
1815 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
1817 /* Mark the symbol as undefined, rather than as defined in
1818 the .plt section. Leave the value alone. */
1819 sym
->st_shndx
= SHN_UNDEF
;
1823 if (h
->got_offset
!= (bfd_vma
) -1)
1827 Elf_Internal_Rela rela
;
1829 /* This symbol has an entry in the global offset table. Set it
1832 BFD_ASSERT (h
->dynindx
!= -1);
1834 sgot
= bfd_get_section_by_name (dynobj
, ".got");
1835 srela
= bfd_get_section_by_name (dynobj
, ".rela.got");
1836 BFD_ASSERT (sgot
!= NULL
&& srela
!= NULL
);
1838 rela
.r_offset
= (sgot
->output_section
->vma
1839 + sgot
->output_offset
1840 + (h
->got_offset
&~ 1));
1842 /* If this is a -Bsymbolic link, and the symbol is defined
1843 locally, we just want to emit a RELATIVE reloc. The entry in
1844 the global offset table will already have been initialized in
1845 the relocate_section function. */
1848 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
))
1849 rela
.r_info
= ELF32_R_INFO (0, R_PPC_RELATIVE
);
1852 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ h
->got_offset
);
1853 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_PPC_GLOB_DAT
);
1857 bfd_elf32_swap_reloca_out (output_bfd
, &rela
,
1858 ((Elf32_External_Rela
*) srela
->contents
1859 + srela
->reloc_count
));
1860 ++srela
->reloc_count
;
1863 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_COPY
) != 0)
1866 Elf_Internal_Rela rela
;
1868 /* This symbols needs a copy reloc. Set it up. */
1870 BFD_ASSERT (h
->dynindx
!= -1);
1872 s
= bfd_get_section_by_name (h
->root
.u
.def
.section
->owner
,
1874 BFD_ASSERT (s
!= NULL
);
1876 rela
.r_offset
= (h
->root
.u
.def
.value
1877 + h
->root
.u
.def
.section
->output_section
->vma
1878 + h
->root
.u
.def
.section
->output_offset
);
1879 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_PPC_COPY
);
1881 bfd_elf32_swap_reloca_out (output_bfd
, &rela
,
1882 ((Elf32_External_Rela
*) s
->contents
1887 /* Mark some specially defined symbols as absolute. */
1888 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
1889 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0
1890 || strcmp (h
->root
.root
.string
, "_PROCEDURE_LINKAGE_TABLE_") == 0)
1891 sym
->st_shndx
= SHN_ABS
;
1897 /* Finish up the dynamic sections. */
1900 ppc_elf_finish_dynamic_sections (output_bfd
, info
)
1902 struct bfd_link_info
*info
;
1909 fprintf (stderr
, "ppc_elf_finish_dynamic_sections called\n");
1912 dynobj
= elf_hash_table (info
)->dynobj
;
1914 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
1916 if (elf_hash_table (info
)->dynamic_sections_created
)
1919 Elf32_External_Dyn
*dyncon
, *dynconend
;
1921 splt
= bfd_get_section_by_name (dynobj
, ".plt");
1922 BFD_ASSERT (splt
!= NULL
&& sdyn
!= NULL
);
1924 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
1925 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
1926 for (; dyncon
< dynconend
; dyncon
++)
1928 Elf_Internal_Dyn dyn
;
1932 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
1936 case DT_PLTGOT
: name
= ".plt"; size
= false; break;
1937 case DT_PLTRELSZ
: name
= ".rela.plt"; size
= true; break;
1938 case DT_JMPREL
: name
= ".rela.plt"; size
= false; break;
1939 default: name
= NULL
; size
= false; break;
1946 s
= bfd_get_section_by_name (output_bfd
, name
);
1952 dyn
.d_un
.d_ptr
= s
->vma
;
1955 if (s
->_cooked_size
!= 0)
1956 dyn
.d_un
.d_val
= s
->_cooked_size
;
1958 dyn
.d_un
.d_val
= s
->_raw_size
;
1961 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
1965 /* Clear the first four entries in the procedure linkage table,
1966 and put a nop in the last four bytes. */
1968 if (splt
->_raw_size
> 0)
1970 memset (splt
->contents
, 0, 4 * PLT_ENTRY_SIZE
);
1971 bfd_put_32 (output_bfd
, SPARC_NOP
,
1972 splt
->contents
+ splt
->_raw_size
- 4);
1975 elf_section_data (splt
->output_section
)->this_hdr
.sh_entsize
=
1980 /* Set the first entry in the global offset table to the address of
1981 the dynamic section. */
1982 sgot
= bfd_get_section_by_name (dynobj
, ".got");
1983 BFD_ASSERT (sgot
!= NULL
);
1984 if (sgot
->_raw_size
> 0)
1987 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
);
1989 bfd_put_32 (output_bfd
,
1990 sdyn
->output_section
->vma
+ sdyn
->output_offset
,
1994 elf_section_data (sgot
->output_section
)->this_hdr
.sh_entsize
= 4;
2000 Elf_Internal_Sym sym
;
2002 /* Set up the section symbols for the output sections. */
2004 sdynsym
= bfd_get_section_by_name (dynobj
, ".dynsym");
2005 BFD_ASSERT (sdynsym
!= NULL
);
2009 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_SECTION
);
2012 for (s
= output_bfd
->sections
; s
!= NULL
; s
= s
->next
)
2016 sym
.st_value
= s
->vma
;
2018 indx
= elf_section_data (s
)->this_idx
;
2019 BFD_ASSERT (indx
> 0);
2020 sym
.st_shndx
= indx
;
2022 bfd_elf32_swap_symbol_out (output_bfd
, &sym
,
2023 (PTR
) (((Elf32_External_Sym
*)
2025 + elf_section_data (s
)->dynindx
));
2028 /* Set the sh_info field of the output .dynsym section to the
2029 index of the first global symbol. */
2030 elf_section_data (sdynsym
->output_section
)->this_hdr
.sh_info
=
2031 bfd_count_sections (output_bfd
) + 1;
2038 /* The RELOCATE_SECTION function is called by the ELF backend linker
2039 to handle the relocations for a section.
2041 The relocs are always passed as Rela structures; if the section
2042 actually uses Rel structures, the r_addend field will always be
2045 This function is responsible for adjust the section contents as
2046 necessary, and (if using Rela relocs and generating a
2047 relocateable output file) adjusting the reloc addend as
2050 This function does not have to worry about setting the reloc
2051 address or the reloc symbol index.
2053 LOCAL_SYMS is a pointer to the swapped in local symbols.
2055 LOCAL_SECTIONS is an array giving the section in the input file
2056 corresponding to the st_shndx field of each local symbol.
2058 The global hash table entry for the global symbols can be found
2059 via elf_sym_hashes (input_bfd).
2061 When generating relocateable output, this function must handle
2062 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
2063 going to be the section symbol corresponding to the output
2064 section, which means that the addend must be adjusted
2068 ppc_elf_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
2069 contents
, relocs
, local_syms
, local_sections
)
2071 struct bfd_link_info
*info
;
2073 asection
*input_section
;
2075 Elf_Internal_Rela
*relocs
;
2076 Elf_Internal_Sym
*local_syms
;
2077 asection
**local_sections
;
2079 Elf_Internal_Shdr
*symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
2080 struct elf_link_hash_entry
**sym_hashes
= elf_sym_hashes (input_bfd
);
2081 bfd
*dynobj
= elf_hash_table (info
)->dynobj
;
2082 bfd_vma
*local_got_offsets
= elf_local_got_offsets (input_bfd
);
2083 asection
*sgot
= (asection
*)0;
2084 Elf_Internal_Rela
*rel
= relocs
;
2085 Elf_Internal_Rela
*relend
= relocs
+ input_section
->reloc_count
;
2090 fprintf (stderr
, "ppc_elf_relocate_section called for %s section %s, %ld relocations%s\n",
2091 bfd_get_filename (input_bfd
),
2092 bfd_section_name(input_bfd
, input_section
),
2093 (long)input_section
->reloc_count
,
2094 (info
->relocateable
) ? " (relocatable)" : "");
2097 if (!ppc_elf_howto_table
[ R_PPC_ADDR32
]) /* Initialize howto table if needed */
2098 ppc_elf_howto_init ();
2100 for (; rel
< relend
; rel
++)
2102 enum ppc_reloc_type r_type
= (enum ppc_reloc_type
)ELF32_R_TYPE (rel
->r_info
);
2103 bfd_vma offset
= rel
->r_offset
;
2104 bfd_vma addend
= rel
->r_addend
;
2105 bfd_reloc_status_type r
= bfd_reloc_other
;
2106 Elf_Internal_Sym
*sym
= (Elf_Internal_Sym
*)0;
2107 asection
*sec
= (asection
*)0;
2108 struct elf_link_hash_entry
*h
= (struct elf_link_hash_entry
*)0;
2109 reloc_howto_type
*howto
;
2110 unsigned long r_symndx
;
2113 /* Unknown relocation handling */
2114 if ((unsigned)r_type
>= (unsigned)R_PPC_max
|| !ppc_elf_howto_table
[(int)r_type
])
2116 (*_bfd_error_handler
) ("%s: unknown relocation type %d",
2117 bfd_get_filename (input_bfd
),
2120 bfd_set_error (bfd_error_bad_value
);
2125 howto
= ppc_elf_howto_table
[(int)r_type
];
2126 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2128 if (info
->relocateable
)
2130 /* This is a relocateable link. We don't have to change
2131 anything, unless the reloc is against a section symbol,
2132 in which case we have to adjust according to where the
2133 section symbol winds up in the output section. */
2134 if (r_symndx
< symtab_hdr
->sh_info
)
2136 sym
= local_syms
+ r_symndx
;
2137 if ((unsigned)ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
2139 sec
= local_sections
[r_symndx
];
2140 addend
= rel
->r_addend
+= sec
->output_offset
+ sym
->st_value
;
2145 fprintf (stderr
, "\ttype = %s (%d), symbol index = %ld, offset = %ld, addend = %ld\n",
2155 /* This is a final link. */
2156 if (r_symndx
< symtab_hdr
->sh_info
)
2158 sym
= local_syms
+ r_symndx
;
2159 sec
= local_sections
[r_symndx
];
2160 relocation
= (sec
->output_section
->vma
2161 + sec
->output_offset
2166 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2167 if (h
->root
.type
== bfd_link_hash_defined
2168 || h
->root
.type
== bfd_link_hash_defweak
)
2170 sec
= h
->root
.u
.def
.section
;
2171 relocation
= (h
->root
.u
.def
.value
2172 + sec
->output_section
->vma
2173 + sec
->output_offset
);
2175 else if (h
->root
.type
== bfd_link_hash_undefweak
)
2177 else if (info
->shared
)
2181 (*info
->callbacks
->undefined_symbol
)(info
,
2182 h
->root
.root
.string
,
2191 switch ((int)r_type
)
2194 (*_bfd_error_handler
) ("%s: unknown relocation type %d",
2195 bfd_get_filename (input_bfd
),
2198 bfd_set_error (bfd_error_bad_value
);
2202 case R_PPC_NONE
: /* relocations that need no special processing */
2206 case R_PPC_ADDR16_LO
:
2207 case R_PPC_ADDR16_HI
:
2216 case (int)R_PPC_ADDR14_BRTAKEN
: /* branch taken prediction relocations */
2217 case (int)R_PPC_REL14_BRTAKEN
:
2218 insn
= bfd_get_32 (output_bfd
, contents
+ offset
);
2219 if ((relocation
- offset
) & 0x8000)
2220 insn
&= ~BRANCH_PREDICT_BIT
;
2222 insn
|= BRANCH_PREDICT_BIT
;
2223 bfd_put_32 (output_bfd
, insn
, contents
+ offset
);
2226 case (int)R_PPC_ADDR14_BRNTAKEN
: /* branch not taken predicition relocations */
2227 case (int)R_PPC_REL14_BRNTAKEN
:
2228 insn
= bfd_get_32 (output_bfd
, contents
+ offset
);
2229 if ((relocation
- offset
) & 0x8000)
2230 insn
|= BRANCH_PREDICT_BIT
;
2232 insn
&= ~BRANCH_PREDICT_BIT
;
2233 bfd_put_32 (output_bfd
, insn
, contents
+ offset
);
2236 case (int)R_PPC_GOT16
: /* GOT16 relocations */
2237 case (int)R_PPC_GOT16_LO
:
2238 case (int)R_PPC_GOT16_HI
:
2239 case (int)R_PPC_GOT16_HA
:
2241 fprintf (stderr
, "GOT relocations in section %s from section %s\n", input_section
->name
, sec
->name
);
2245 dynobj
= ppc_elf_create_dynamic_sections (output_bfd
, info
);
2253 BFD_ASSERT (sec
!= (asection
*)0);
2256 sgot
= bfd_get_section_by_name (dynobj
, ".got");
2257 BFD_ASSERT (sgot
!= NULL
);
2264 off
= h
->got_offset
;
2265 BFD_ASSERT (off
!= (bfd_vma
) -1);
2267 if (! elf_hash_table (info
)->dynamic_sections_created
2270 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
)))
2272 /* This is actually a static link, or it is a
2273 -Bsymbolic link and the symbol is defined
2274 locally. We must initialize this entry in the
2275 global offset table. Since the offset must
2276 always be a multiple of 4, we use the least
2277 significant bit to record whether we have
2278 initialized it already.
2280 When doing a dynamic link, we create a .rela.got
2281 relocation entry to initialize the value. This
2282 is done in the finish_dynamic_symbol routine. */
2287 bfd_put_32 (output_bfd
, relocation
,
2288 sgot
->contents
+ off
);
2293 relocation
= sgot
->output_offset
+ off
;
2299 BFD_ASSERT (local_got_offsets
!= NULL
2300 && local_got_offsets
[r_symndx
] != (bfd_vma
) -1);
2302 off
= local_got_offsets
[r_symndx
];
2304 /* The offset must always be a multiple of 4. We use
2305 the least significant bit to record whether we have
2306 already processed this entry. */
2311 bfd_put_32 (output_bfd
, relocation
, sgot
->contents
+ off
);
2316 Elf_Internal_Rela outrel
;
2318 /* We need to generate a R_PPC_RELATIVE reloc
2319 for the dynamic linker. */
2320 srelgot
= bfd_get_section_by_name (dynobj
, ".rela.got");
2321 BFD_ASSERT (srelgot
!= NULL
);
2323 outrel
.r_offset
= (sgot
->output_section
->vma
2324 + sgot
->output_offset
2326 outrel
.r_info
= ELF32_R_INFO (0, R_PPC_RELATIVE
);
2327 outrel
.r_addend
= 0;
2328 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
,
2329 (((Elf32_External_Rela
*)
2331 + srelgot
->reloc_count
));
2332 ++srelgot
->reloc_count
;
2335 local_got_offsets
[r_symndx
] |= 1;
2338 relocation
= sgot
->output_offset
+ off
;
2343 /* Handle the TOC16 reloc. We want to use the offset within the .got
2344 section, not the actual VMA. This is appropriate when generating
2345 an embedded ELF object, for which the .got section acts like the
2346 AIX .toc section. */
2347 case (int)R_PPC_TOC16
: /* phony GOT16 relocations */
2348 BFD_ASSERT (sec
!= (asection
*)0);
2349 BFD_ASSERT (bfd_is_und_section (sec
)
2350 || strcmp (bfd_get_section_name (abfd
, sec
), ".got") == 0
2351 || strcmp (bfd_get_section_name (abfd
, sec
), ".cgot") == 0)
2353 addend
-= sec
->output_section
->vma
+ 0x8000;
2356 case (int)R_PPC_ADDR16_HA
: /* arithmetic adjust relocations */
2357 BFD_ASSERT (sec
!= (asection
*)0);
2358 addend
+= ((relocation
+ addend
) & 0x8000) << 1;
2361 case R_PPC_SDAREL16
: /* relocate against _SDA_BASE_ */
2362 BFD_ASSERT (sec
!= (asection
*)0);
2363 if (strcmp (bfd_get_section_name (abfd
, sec
), ".sdata") != 0
2364 && strcmp (bfd_get_section_name (abfd
, sec
), ".sbss") != 0)
2366 (*_bfd_error_handler
) ("%s: The target of R_PPC_SDAREL16 relocations must be in section .sdata or .sbss not %s",
2367 bfd_get_filename (input_bfd
),
2368 bfd_get_section_name (abfd
, sec
));
2370 bfd_set_error (bfd_error_bad_value
);
2376 case R_PPC_EMB_SDA2REL
:
2377 BFD_ASSERT (sec
!= (asection
*)0);
2378 if (strcmp (bfd_get_section_name (abfd
, sec
), ".sdata2") != 0
2379 && strcmp (bfd_get_section_name (abfd
, sec
), ".sbss2") != 0)
2381 (*_bfd_error_handler
) ("%s: The target of R_PPC_SDA2REL16 relocations must be in section .sdata2 or .sbss2 not %s",
2382 bfd_get_filename (input_bfd
),
2383 bfd_get_section_name (abfd
, sec
));
2385 bfd_set_error (bfd_error_bad_value
);
2392 case R_PPC_PLTREL24
:
2394 case R_PPC_GLOB_DAT
:
2395 case R_PPC_JMP_SLOT
:
2396 case R_PPC_RELATIVE
:
2397 case R_PPC_LOCAL24PC
:
2399 case R_PPC_PLTREL32
:
2400 case R_PPC_PLT16_LO
:
2401 case R_PPC_PLT16_HI
:
2402 case R_PPC_PLT16_HA
:
2404 case R_PPC_SECTOFF_LO
:
2405 case R_PPC_SECTOFF_HI
:
2406 case R_PPC_SECTOFF_HA
:
2407 case R_PPC_EMB_NADDR32
:
2408 case R_PPC_EMB_NADDR16
:
2409 case R_PPC_EMB_NADDR16_LO
:
2410 case R_PPC_EMB_NADDR16_HI
:
2411 case R_PPC_EMB_NADDR16_HA
:
2412 case R_PPC_EMB_SDAI16
:
2413 case R_PPC_EMB_SDA2I16
:
2414 case R_PPC_EMB_SDA21
:
2415 case R_PPC_EMB_MRKREF
:
2416 case R_PPC_EMB_RELSEC16
:
2417 case R_PPC_EMB_RELST_LO
:
2418 case R_PPC_EMB_RELST_HI
:
2419 case R_PPC_EMB_RELST_HA
:
2420 case R_PPC_EMB_BIT_FLD
:
2421 case R_PPC_EMB_RELSDA
:
2423 (*_bfd_error_handler
) ("%s: Relocation %s is not yet supported.",
2424 bfd_get_filename (input_bfd
),
2425 ppc_elf_howto_table
[ (int)r_type
]->name
);
2427 bfd_set_error (bfd_error_bad_value
);
2434 fprintf (stderr
, "\ttype = %s (%d), symbol index = %ld, offset = %ld, addend = %ld\n",
2442 r
= _bfd_final_link_relocate (howto
,
2450 if (r
!= bfd_reloc_ok
)
2458 case bfd_reloc_overflow
:
2463 name
= h
->root
.root
.string
;
2466 name
= bfd_elf_string_from_elf_section (input_bfd
,
2467 symtab_hdr
->sh_link
,
2473 name
= bfd_section_name (input_bfd
, sec
);
2476 (*info
->callbacks
->reloc_overflow
)(info
,
2492 fprintf (stderr
, "\n");
2499 #define TARGET_LITTLE_SYM bfd_elf32_powerpcle_vec
2500 #define TARGET_LITTLE_NAME "elf32-powerpcle"
2501 #define TARGET_BIG_SYM bfd_elf32_powerpc_vec
2502 #define TARGET_BIG_NAME "elf32-powerpc"
2503 #define ELF_ARCH bfd_arch_powerpc
2504 #define ELF_MACHINE_CODE EM_PPC
2505 #define ELF_MAXPAGESIZE 0x10000
2506 #define elf_info_to_howto ppc_elf_info_to_howto
2508 #ifdef EM_CYGNUS_POWERPC
2509 #define ELF_MACHINE_ALT1 EM_CYGNUS_POWERPC
2513 #define ELF_MACHINE_ALT2 EM_PPC_OLD
2516 #define bfd_elf32_bfd_copy_private_bfd_data ppc_elf_copy_private_bfd_data
2517 #define bfd_elf32_bfd_merge_private_bfd_data ppc_elf_merge_private_bfd_data
2518 #define bfd_elf32_bfd_set_private_flags ppc_elf_set_private_flags
2519 #define bfd_elf32_bfd_reloc_type_lookup ppc_elf_reloc_type_lookup
2520 #define elf_backend_section_from_shdr ppc_elf_section_from_shdr
2521 #define elf_backend_relocate_section ppc_elf_relocate_section
2522 #define elf_backend_create_dynamic_sections _bfd_elf_create_dynamic_sections
2523 #define elf_backend_check_relocs ppc_elf_check_relocs
2524 #define elf_backend_adjust_dynamic_symbol ppc_elf_adjust_dynamic_symbol
2525 #define elf_backend_size_dynamic_sections ppc_elf_size_dynamic_sections
2526 #define elf_backend_finish_dynamic_symbol ppc_elf_finish_dynamic_symbol
2527 #define elf_backend_finish_dynamic_sections ppc_elf_finish_dynamic_sections
2528 #define elf_backend_fake_sections ppc_elf_fake_sections
2530 #include "elf32-target.h"