1 /* PowerPC-specific support for 32-bit ELF
2 Copyright 1994, 1995, 1996 Free Software Foundation, Inc.
3 Written by Ian Lance Taylor, Cygnus Support.
5 This file is part of BFD, the Binary File Descriptor library.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
21 /* This file is based on a preliminary PowerPC ELF ABI. The
22 information may not match the final PowerPC ELF ABI. It includes
23 suggestions from the in-progress Embedded PowerPC ABI, and that
24 information may also not match. */
33 #define USE_RELA /* we want RELA relocations, not REL */
35 /* PowerPC relocations defined by the ABIs */
46 R_PPC_ADDR14_BRTAKEN
= 8,
47 R_PPC_ADDR14_BRNTAKEN
= 9,
50 R_PPC_REL14_BRTAKEN
= 12,
51 R_PPC_REL14_BRNTAKEN
= 13,
72 R_PPC_SECTOFF_LO
= 34,
73 R_PPC_SECTOFF_HI
= 35,
74 R_PPC_SECTOFF_HA
= 36,
76 /* The remaining relocs are from the Embedded ELF ABI, and are not
77 in the SVR4 ELF ABI. */
78 R_PPC_EMB_NADDR32
= 101,
79 R_PPC_EMB_NADDR16
= 102,
80 R_PPC_EMB_NADDR16_LO
= 103,
81 R_PPC_EMB_NADDR16_HI
= 104,
82 R_PPC_EMB_NADDR16_HA
= 105,
83 R_PPC_EMB_SDAI16
= 106,
84 R_PPC_EMB_SDA2I16
= 107,
85 R_PPC_EMB_SDA2REL
= 108,
86 R_PPC_EMB_SDA21
= 109,
87 R_PPC_EMB_MRKREF
= 110,
88 R_PPC_EMB_RELSEC16
= 111,
89 R_PPC_EMB_RELST_LO
= 112,
90 R_PPC_EMB_RELST_HI
= 113,
91 R_PPC_EMB_RELST_HA
= 114,
92 R_PPC_EMB_BIT_FLD
= 115,
93 R_PPC_EMB_RELSDA
= 116,
95 /* This is a phony reloc to handle any old fashioned TOC16 references
96 that may still be in object files. */
102 static reloc_howto_type
*ppc_elf_reloc_type_lookup
103 PARAMS ((bfd
*abfd
, bfd_reloc_code_real_type code
));
104 static void ppc_elf_info_to_howto
105 PARAMS ((bfd
*abfd
, arelent
*cache_ptr
, Elf32_Internal_Rela
*dst
));
106 static void ppc_elf_howto_init
PARAMS ((void));
107 static boolean ppc_elf_set_private_flags
PARAMS ((bfd
*, flagword
));
108 static boolean ppc_elf_copy_private_bfd_data
PARAMS ((bfd
*, bfd
*));
109 static boolean ppc_elf_merge_private_bfd_data
PARAMS ((bfd
*, bfd
*));
111 static boolean ppc_elf_section_from_shdr
PARAMS ((bfd
*,
112 Elf32_Internal_Shdr
*,
115 static elf_linker_section_t
*ppc_elf_create_linker_section
117 struct bfd_link_info
*info
,
118 enum elf_linker_section_enum
));
120 static boolean ppc_elf_check_relocs
PARAMS ((bfd
*,
121 struct bfd_link_info
*,
123 const Elf_Internal_Rela
*));
125 static boolean ppc_elf_adjust_dynamic_symbol
PARAMS ((struct bfd_link_info
*,
126 struct elf_link_hash_entry
*));
128 static boolean ppc_elf_adjust_dynindx
PARAMS ((struct elf_link_hash_entry
*, PTR
));
130 static boolean ppc_elf_size_dynamic_sections
PARAMS ((bfd
*, struct bfd_link_info
*));
132 static boolean ppc_elf_relocate_section
PARAMS ((bfd
*,
133 struct bfd_link_info
*info
,
137 Elf_Internal_Rela
*relocs
,
138 Elf_Internal_Sym
*local_syms
,
141 static boolean ppc_elf_finish_dynamic_symbol
PARAMS ((bfd
*,
142 struct bfd_link_info
*,
143 struct elf_link_hash_entry
*,
144 Elf_Internal_Sym
*));
146 static boolean ppc_elf_finish_dynamic_sections
PARAMS ((bfd
*, struct bfd_link_info
*));
148 #define BRANCH_PREDICT_BIT 0x200000 /* branch prediction bit for branch taken relocs */
149 #define RA_REGISTER_MASK 0x001f0000 /* mask to set RA in memory instructions */
150 #define RA_REGISTER_SHIFT 16 /* value to shift register by to insert RA */
152 /* The name of the dynamic interpreter. This is put in the .interp
155 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
158 static reloc_howto_type
*ppc_elf_howto_table
[ (int)R_PPC_max
];
160 static reloc_howto_type ppc_elf_howto_raw
[] =
162 /* This reloc does nothing. */
163 HOWTO (R_PPC_NONE
, /* type */
165 2, /* size (0 = byte, 1 = short, 2 = long) */
167 false, /* pc_relative */
169 complain_overflow_bitfield
, /* complain_on_overflow */
170 bfd_elf_generic_reloc
, /* special_function */
171 "R_PPC_NONE", /* name */
172 false, /* partial_inplace */
175 false), /* pcrel_offset */
177 /* A standard 32 bit relocation. */
178 HOWTO (R_PPC_ADDR32
, /* type */
180 2, /* size (0 = byte, 1 = short, 2 = long) */
182 false, /* pc_relative */
184 complain_overflow_bitfield
, /* complain_on_overflow */
185 bfd_elf_generic_reloc
, /* special_function */
186 "R_PPC_ADDR32", /* name */
187 false, /* partial_inplace */
189 0xffffffff, /* dst_mask */
190 false), /* pcrel_offset */
192 /* An absolute 26 bit branch; the lower two bits must be zero.
193 FIXME: we don't check that, we just clear them. */
194 HOWTO (R_PPC_ADDR24
, /* type */
196 2, /* size (0 = byte, 1 = short, 2 = long) */
198 false, /* pc_relative */
200 complain_overflow_bitfield
, /* complain_on_overflow */
201 bfd_elf_generic_reloc
, /* special_function */
202 "R_PPC_ADDR24", /* name */
203 false, /* partial_inplace */
205 0x3fffffc, /* dst_mask */
206 false), /* pcrel_offset */
208 /* A standard 16 bit relocation. */
209 HOWTO (R_PPC_ADDR16
, /* type */
211 1, /* size (0 = byte, 1 = short, 2 = long) */
213 false, /* pc_relative */
215 complain_overflow_bitfield
, /* complain_on_overflow */
216 bfd_elf_generic_reloc
, /* special_function */
217 "R_PPC_ADDR16", /* name */
218 false, /* partial_inplace */
220 0xffff, /* dst_mask */
221 false), /* pcrel_offset */
223 /* A 16 bit relocation without overflow. */
224 HOWTO (R_PPC_ADDR16_LO
, /* type */
226 1, /* size (0 = byte, 1 = short, 2 = long) */
228 false, /* pc_relative */
230 complain_overflow_dont
,/* complain_on_overflow */
231 bfd_elf_generic_reloc
, /* special_function */
232 "R_PPC_ADDR16_LO", /* name */
233 false, /* partial_inplace */
235 0xffff, /* dst_mask */
236 false), /* pcrel_offset */
238 /* The high order 16 bits of an address. */
239 HOWTO (R_PPC_ADDR16_HI
, /* type */
241 1, /* size (0 = byte, 1 = short, 2 = long) */
243 false, /* pc_relative */
245 complain_overflow_dont
, /* complain_on_overflow */
246 bfd_elf_generic_reloc
, /* special_function */
247 "R_PPC_ADDR16_HI", /* name */
248 false, /* partial_inplace */
250 0xffff, /* dst_mask */
251 false), /* pcrel_offset */
253 /* The high order 16 bits of an address, plus 1 if the contents of
254 the low 16 bits, treated as a signed number, is negative. */
255 HOWTO (R_PPC_ADDR16_HA
, /* type */
257 1, /* size (0 = byte, 1 = short, 2 = long) */
259 false, /* pc_relative */
261 complain_overflow_dont
, /* complain_on_overflow */
262 bfd_elf_generic_reloc
, /* special_function */
263 "R_PPC_ADDR16_HA", /* name */
264 false, /* partial_inplace */
266 0xffff, /* dst_mask */
267 false), /* pcrel_offset */
269 /* An absolute 16 bit branch; the lower two bits must be zero.
270 FIXME: we don't check that, we just clear them. */
271 HOWTO (R_PPC_ADDR14
, /* type */
273 2, /* size (0 = byte, 1 = short, 2 = long) */
275 false, /* pc_relative */
277 complain_overflow_bitfield
, /* complain_on_overflow */
278 bfd_elf_generic_reloc
, /* special_function */
279 "R_PPC_ADDR14", /* name */
280 false, /* partial_inplace */
282 0xfffc, /* dst_mask */
283 false), /* pcrel_offset */
285 /* An absolute 16 bit branch, for which bit 10 should be set to
286 indicate that the branch is expected to be taken. The lower two
287 bits must be zero. */
288 HOWTO (R_PPC_ADDR14_BRTAKEN
, /* type */
290 2, /* size (0 = byte, 1 = short, 2 = long) */
292 false, /* pc_relative */
294 complain_overflow_bitfield
, /* complain_on_overflow */
295 bfd_elf_generic_reloc
, /* special_function */
296 "R_PPC_ADDR14_BRTAKEN",/* name */
297 false, /* partial_inplace */
299 0xfffc, /* dst_mask */
300 false), /* pcrel_offset */
302 /* An absolute 16 bit branch, for which bit 10 should be set to
303 indicate that the branch is not expected to be taken. The lower
304 two bits must be zero. */
305 HOWTO (R_PPC_ADDR14_BRNTAKEN
, /* type */
307 2, /* size (0 = byte, 1 = short, 2 = long) */
309 false, /* pc_relative */
311 complain_overflow_bitfield
, /* complain_on_overflow */
312 bfd_elf_generic_reloc
, /* special_function */
313 "R_PPC_ADDR14_BRNTAKEN",/* name */
314 false, /* partial_inplace */
316 0xfffc, /* dst_mask */
317 false), /* pcrel_offset */
319 /* A relative 26 bit branch; the lower two bits must be zero. */
320 HOWTO (R_PPC_REL24
, /* type */
322 2, /* size (0 = byte, 1 = short, 2 = long) */
324 true, /* pc_relative */
326 complain_overflow_signed
, /* complain_on_overflow */
327 bfd_elf_generic_reloc
, /* special_function */
328 "R_PPC_REL24", /* name */
329 false, /* partial_inplace */
331 0x3fffffc, /* dst_mask */
332 true), /* pcrel_offset */
334 /* A relative 16 bit branch; the lower two bits must be zero. */
335 HOWTO (R_PPC_REL14
, /* type */
337 2, /* size (0 = byte, 1 = short, 2 = long) */
339 true, /* pc_relative */
341 complain_overflow_signed
, /* complain_on_overflow */
342 bfd_elf_generic_reloc
, /* special_function */
343 "R_PPC_REL14", /* name */
344 false, /* partial_inplace */
346 0xfffc, /* dst_mask */
347 true), /* pcrel_offset */
349 /* A relative 16 bit branch. Bit 10 should be set to indicate that
350 the branch is expected to be taken. The lower two bits must be
352 HOWTO (R_PPC_REL14_BRTAKEN
, /* type */
354 2, /* size (0 = byte, 1 = short, 2 = long) */
356 true, /* pc_relative */
358 complain_overflow_signed
, /* complain_on_overflow */
359 bfd_elf_generic_reloc
, /* special_function */
360 "R_PPC_REL14_BRTAKEN", /* name */
361 false, /* partial_inplace */
363 0xfffc, /* dst_mask */
364 true), /* pcrel_offset */
366 /* A relative 16 bit branch. Bit 10 should be set to indicate that
367 the branch is not expected to be taken. The lower two bits must
369 HOWTO (R_PPC_REL14_BRNTAKEN
, /* type */
371 2, /* size (0 = byte, 1 = short, 2 = long) */
373 true, /* pc_relative */
375 complain_overflow_signed
, /* complain_on_overflow */
376 bfd_elf_generic_reloc
, /* special_function */
377 "R_PPC_REL14_BRNTAKEN",/* name */
378 false, /* partial_inplace */
380 0xfffc, /* dst_mask */
381 true), /* pcrel_offset */
383 /* Like R_PPC_ADDR16, but referring to the GOT table entry for the
385 HOWTO (R_PPC_GOT16
, /* type */
387 1, /* size (0 = byte, 1 = short, 2 = long) */
389 false, /* pc_relative */
391 complain_overflow_signed
, /* complain_on_overflow */
392 bfd_elf_generic_reloc
, /* special_function */
393 "R_PPC_GOT16", /* name */
394 false, /* partial_inplace */
396 0xffff, /* dst_mask */
397 false), /* pcrel_offset */
399 /* Like R_PPC_ADDR16_LO, but referring to the GOT table entry for
401 HOWTO (R_PPC_GOT16_LO
, /* type */
403 1, /* size (0 = byte, 1 = short, 2 = long) */
405 false, /* pc_relative */
407 complain_overflow_bitfield
, /* complain_on_overflow */
408 bfd_elf_generic_reloc
, /* special_function */
409 "R_PPC_GOT16_LO", /* name */
410 false, /* partial_inplace */
412 0xffff, /* dst_mask */
413 false), /* pcrel_offset */
415 /* Like R_PPC_ADDR16_HI, but referring to the GOT table entry for
417 HOWTO (R_PPC_GOT16_HI
, /* type */
419 1, /* size (0 = byte, 1 = short, 2 = long) */
421 false, /* pc_relative */
423 complain_overflow_bitfield
, /* complain_on_overflow */
424 bfd_elf_generic_reloc
, /* special_function */
425 "R_PPC_GOT16_HI", /* name */
426 false, /* partial_inplace */
428 0xffff, /* dst_mask */
429 false), /* pcrel_offset */
431 /* Like R_PPC_ADDR16_HA, but referring to the GOT table entry for
432 the symbol. FIXME: Not supported. */
433 HOWTO (R_PPC_GOT16_HA
, /* type */
435 1, /* size (0 = byte, 1 = short, 2 = long) */
437 false, /* pc_relative */
439 complain_overflow_bitfield
, /* complain_on_overflow */
440 bfd_elf_generic_reloc
, /* special_function */
441 "R_PPC_GOT16_HA", /* name */
442 false, /* partial_inplace */
444 0xffff, /* dst_mask */
445 false), /* pcrel_offset */
447 /* Like R_PPC_REL24, but referring to the procedure linkage table
448 entry for the symbol. FIXME: Not supported. */
449 HOWTO (R_PPC_PLTREL24
, /* type */
451 2, /* size (0 = byte, 1 = short, 2 = long) */
453 true, /* pc_relative */
455 complain_overflow_signed
, /* complain_on_overflow */
456 bfd_elf_generic_reloc
, /* special_function */
457 "R_PPC_PLTREL24", /* name */
458 false, /* partial_inplace */
460 0x3fffffc, /* dst_mask */
461 true), /* pcrel_offset */
463 /* This is used only by the dynamic linker. The symbol should exist
464 both in the object being run and in some shared library. The
465 dynamic linker copies the data addressed by the symbol from the
466 shared library into the object. I have no idea what the purpose
468 HOWTO (R_PPC_COPY
, /* type */
470 2, /* size (0 = byte, 1 = short, 2 = long) */
472 false, /* pc_relative */
474 complain_overflow_bitfield
, /* complain_on_overflow */
475 bfd_elf_generic_reloc
, /* special_function */
476 "R_PPC_COPY", /* name */
477 false, /* partial_inplace */
480 false), /* pcrel_offset */
482 /* Like R_PPC_ADDR32, but used when setting global offset table
484 HOWTO (R_PPC_GLOB_DAT
, /* type */
486 2, /* size (0 = byte, 1 = short, 2 = long) */
488 false, /* pc_relative */
490 complain_overflow_bitfield
, /* complain_on_overflow */
491 bfd_elf_generic_reloc
, /* special_function */
492 "R_PPC_GLOB_DAT", /* name */
493 false, /* partial_inplace */
495 0xffffffff, /* dst_mask */
496 false), /* pcrel_offset */
498 /* Marks a procedure linkage table entry for a symbol. */
499 HOWTO (R_PPC_JMP_SLOT
, /* type */
501 2, /* size (0 = byte, 1 = short, 2 = long) */
503 false, /* pc_relative */
505 complain_overflow_bitfield
, /* complain_on_overflow */
506 bfd_elf_generic_reloc
, /* special_function */
507 "R_PPC_JMP_SLOT", /* name */
508 false, /* partial_inplace */
511 false), /* pcrel_offset */
513 /* Used only by the dynamic linker. When the object is run, this
514 longword is set to the load address of the object, plus the
516 HOWTO (R_PPC_RELATIVE
, /* type */
518 2, /* size (0 = byte, 1 = short, 2 = long) */
520 false, /* pc_relative */
522 complain_overflow_bitfield
, /* complain_on_overflow */
523 bfd_elf_generic_reloc
, /* special_function */
524 "R_PPC_RELATIVE", /* name */
525 false, /* partial_inplace */
527 0xffffffff, /* dst_mask */
528 false), /* pcrel_offset */
530 /* Like R_PPC_REL24, but uses the value of the symbol within the
531 object rather than the final value. Normally used for
532 _GLOBAL_OFFSET_TABLE_. FIXME: Not supported. */
533 HOWTO (R_PPC_LOCAL24PC
, /* type */
535 2, /* size (0 = byte, 1 = short, 2 = long) */
537 true, /* pc_relative */
539 complain_overflow_signed
, /* complain_on_overflow */
540 bfd_elf_generic_reloc
, /* special_function */
541 "R_PPC_LOCAL24PC", /* name */
542 false, /* partial_inplace */
544 0x3fffffc, /* dst_mask */
545 true), /* pcrel_offset */
547 /* Like R_PPC_ADDR32, but may be unaligned. */
548 HOWTO (R_PPC_UADDR32
, /* type */
550 2, /* size (0 = byte, 1 = short, 2 = long) */
552 false, /* pc_relative */
554 complain_overflow_bitfield
, /* complain_on_overflow */
555 bfd_elf_generic_reloc
, /* special_function */
556 "R_PPC_UADDR32", /* name */
557 false, /* partial_inplace */
559 0xffffffff, /* dst_mask */
560 false), /* pcrel_offset */
562 /* Like R_PPC_ADDR16, but may be unaligned. */
563 HOWTO (R_PPC_UADDR16
, /* type */
565 1, /* size (0 = byte, 1 = short, 2 = long) */
567 false, /* pc_relative */
569 complain_overflow_bitfield
, /* complain_on_overflow */
570 bfd_elf_generic_reloc
, /* special_function */
571 "R_PPC_UADDR16", /* name */
572 false, /* partial_inplace */
574 0xffff, /* dst_mask */
575 false), /* pcrel_offset */
577 /* 32-bit PC relative */
578 HOWTO (R_PPC_REL32
, /* type */
580 2, /* size (0 = byte, 1 = short, 2 = long) */
582 true, /* pc_relative */
584 complain_overflow_bitfield
, /* complain_on_overflow */
585 bfd_elf_generic_reloc
, /* special_function */
586 "R_PPC_REL32", /* name */
587 false, /* partial_inplace */
589 0xffffffff, /* dst_mask */
590 true), /* pcrel_offset */
592 /* 32-bit relocation to the symbol's procedure linkage table.
593 FIXEME: not supported. */
594 HOWTO (R_PPC_PLT32
, /* type */
596 2, /* size (0 = byte, 1 = short, 2 = long) */
598 false, /* pc_relative */
600 complain_overflow_bitfield
, /* complain_on_overflow */
601 bfd_elf_generic_reloc
, /* special_function */
602 "R_PPC_PLT32", /* name */
603 false, /* partial_inplace */
606 false), /* pcrel_offset */
608 /* 32-bit PC relative relocation to the symbol's procedure linkage table.
609 FIXEME: not supported. */
610 HOWTO (R_PPC_PLTREL32
, /* type */
612 2, /* size (0 = byte, 1 = short, 2 = long) */
614 true, /* pc_relative */
616 complain_overflow_bitfield
, /* complain_on_overflow */
617 bfd_elf_generic_reloc
, /* special_function */
618 "R_PPC_PLTREL32", /* name */
619 false, /* partial_inplace */
622 true), /* pcrel_offset */
624 /* Like R_PPC_ADDR16_LO, but referring to the PLT table entry for
626 HOWTO (R_PPC_PLT16_LO
, /* type */
628 1, /* size (0 = byte, 1 = short, 2 = long) */
630 false, /* pc_relative */
632 complain_overflow_bitfield
, /* complain_on_overflow */
633 bfd_elf_generic_reloc
, /* special_function */
634 "R_PPC_PLT16_LO", /* name */
635 false, /* partial_inplace */
637 0xffff, /* dst_mask */
638 false), /* pcrel_offset */
640 /* Like R_PPC_ADDR16_HI, but referring to the PLT table entry for
642 HOWTO (R_PPC_PLT16_HI
, /* type */
644 1, /* size (0 = byte, 1 = short, 2 = long) */
646 false, /* pc_relative */
648 complain_overflow_bitfield
, /* complain_on_overflow */
649 bfd_elf_generic_reloc
, /* special_function */
650 "R_PPC_PLT16_HI", /* name */
651 false, /* partial_inplace */
653 0xffff, /* dst_mask */
654 false), /* pcrel_offset */
656 /* Like R_PPC_ADDR16_HA, but referring to the PLT table entry for
657 the symbol. FIXME: Not supported. */
658 HOWTO (R_PPC_PLT16_HA
, /* type */
660 1, /* size (0 = byte, 1 = short, 2 = long) */
662 false, /* pc_relative */
664 complain_overflow_bitfield
, /* complain_on_overflow */
665 bfd_elf_generic_reloc
, /* special_function */
666 "R_PPC_PLT16_HA", /* name */
667 false, /* partial_inplace */
669 0xffff, /* dst_mask */
670 false), /* pcrel_offset */
672 /* A sign-extended 16 bit value relative to _SDA_BASE_, for use with
673 small data items. FIXME: Not supported. */
674 HOWTO (R_PPC_SDAREL16
, /* type */
676 1, /* size (0 = byte, 1 = short, 2 = long) */
678 false, /* pc_relative */
680 complain_overflow_signed
, /* complain_on_overflow */
681 bfd_elf_generic_reloc
, /* special_function */
682 "R_PPC_SDAREL16", /* name */
683 false, /* partial_inplace */
685 0xffff, /* dst_mask */
686 false), /* pcrel_offset */
688 /* 32-bit section relative relocation. FIXME: not supported. */
689 HOWTO (R_PPC_SECTOFF
, /* type */
691 2, /* size (0 = byte, 1 = short, 2 = long) */
693 true, /* pc_relative */
695 complain_overflow_bitfield
, /* complain_on_overflow */
696 bfd_elf_generic_reloc
, /* special_function */
697 "R_PPC_SECTOFF", /* name */
698 false, /* partial_inplace */
701 true), /* pcrel_offset */
703 /* 16-bit lower half section relative relocation. FIXME: not supported. */
704 HOWTO (R_PPC_SECTOFF_LO
, /* type */
706 1, /* size (0 = byte, 1 = short, 2 = long) */
708 false, /* pc_relative */
710 complain_overflow_bitfield
, /* complain_on_overflow */
711 bfd_elf_generic_reloc
, /* special_function */
712 "R_PPC_SECTOFF_LO", /* name */
713 false, /* partial_inplace */
715 0xffff, /* dst_mask */
716 false), /* pcrel_offset */
718 /* 16-bit upper half section relative relocation. FIXME: not supported. */
719 HOWTO (R_PPC_SECTOFF_HI
, /* type */
721 1, /* size (0 = byte, 1 = short, 2 = long) */
723 false, /* pc_relative */
725 complain_overflow_bitfield
, /* complain_on_overflow */
726 bfd_elf_generic_reloc
, /* special_function */
727 "R_PPC_SECTOFF_HI", /* name */
728 false, /* partial_inplace */
730 0xffff, /* dst_mask */
731 false), /* pcrel_offset */
733 /* 16-bit upper half adjusted section relative relocation. FIXME: not supported. */
734 HOWTO (R_PPC_SECTOFF_HA
, /* type */
736 1, /* size (0 = byte, 1 = short, 2 = long) */
738 false, /* pc_relative */
740 complain_overflow_bitfield
, /* complain_on_overflow */
741 bfd_elf_generic_reloc
, /* special_function */
742 "R_PPC_SECTOFF_HA", /* name */
743 false, /* partial_inplace */
745 0xffff, /* dst_mask */
746 false), /* pcrel_offset */
748 /* The remaining relocs are from the Embedded ELF ABI, and are not
749 in the SVR4 ELF ABI. */
751 /* 32 bit value resulting from the addend minus the symbol */
752 HOWTO (R_PPC_EMB_NADDR32
, /* type */
754 2, /* size (0 = byte, 1 = short, 2 = long) */
756 false, /* pc_relative */
758 complain_overflow_bitfield
, /* complain_on_overflow */
759 bfd_elf_generic_reloc
, /* special_function */
760 "R_PPC_EMB_NADDR32", /* name */
761 false, /* partial_inplace */
763 0xffffffff, /* dst_mask */
764 false), /* pcrel_offset */
766 /* 16 bit value resulting from the addend minus the symbol */
767 HOWTO (R_PPC_EMB_NADDR16
, /* type */
769 1, /* size (0 = byte, 1 = short, 2 = long) */
771 false, /* pc_relative */
773 complain_overflow_bitfield
, /* complain_on_overflow */
774 bfd_elf_generic_reloc
, /* special_function */
775 "R_PPC_EMB_NADDR16", /* name */
776 false, /* partial_inplace */
778 0xffff, /* dst_mask */
779 false), /* pcrel_offset */
781 /* 16 bit value resulting from the addend minus the symbol */
782 HOWTO (R_PPC_EMB_NADDR16_LO
, /* type */
784 1, /* size (0 = byte, 1 = short, 2 = long) */
786 false, /* pc_relative */
788 complain_overflow_dont
,/* complain_on_overflow */
789 bfd_elf_generic_reloc
, /* special_function */
790 "R_PPC_EMB_ADDR16_LO", /* name */
791 false, /* partial_inplace */
793 0xffff, /* dst_mask */
794 false), /* pcrel_offset */
796 /* The high order 16 bits of the addend minus the symbol */
797 HOWTO (R_PPC_EMB_NADDR16_HI
, /* type */
799 1, /* size (0 = byte, 1 = short, 2 = long) */
801 false, /* pc_relative */
803 complain_overflow_dont
, /* complain_on_overflow */
804 bfd_elf_generic_reloc
, /* special_function */
805 "R_PPC_EMB_NADDR16_HI", /* name */
806 false, /* partial_inplace */
808 0xffff, /* dst_mask */
809 false), /* pcrel_offset */
811 /* The high order 16 bits of the result of the addend minus the address,
812 plus 1 if the contents of the low 16 bits, treated as a signed number,
814 HOWTO (R_PPC_EMB_NADDR16_HA
, /* type */
816 1, /* size (0 = byte, 1 = short, 2 = long) */
818 false, /* pc_relative */
820 complain_overflow_dont
, /* complain_on_overflow */
821 bfd_elf_generic_reloc
, /* special_function */
822 "R_PPC_EMB_NADDR16_HA", /* name */
823 false, /* partial_inplace */
825 0xffff, /* dst_mask */
826 false), /* pcrel_offset */
828 /* 16 bit value resulting from allocating a 4 byte word to hold an
829 address in the .sdata section, and returning the offset from
830 _SDA_BASE_ for that relocation */
831 HOWTO (R_PPC_EMB_SDAI16
, /* type */
833 1, /* size (0 = byte, 1 = short, 2 = long) */
835 false, /* pc_relative */
837 complain_overflow_bitfield
, /* complain_on_overflow */
838 bfd_elf_generic_reloc
, /* special_function */
839 "R_PPC_EMB_SDAI16", /* name */
840 false, /* partial_inplace */
842 0xffff, /* dst_mask */
843 false), /* pcrel_offset */
845 /* 16 bit value resulting from allocating a 4 byte word to hold an
846 address in the .sdata2 section, and returning the offset from
847 _SDA2_BASE_ for that relocation */
848 HOWTO (R_PPC_EMB_SDA2I16
, /* type */
850 1, /* size (0 = byte, 1 = short, 2 = long) */
852 false, /* pc_relative */
854 complain_overflow_bitfield
, /* complain_on_overflow */
855 bfd_elf_generic_reloc
, /* special_function */
856 "R_PPC_EMB_SDA2I16", /* name */
857 false, /* partial_inplace */
859 0xffff, /* dst_mask */
860 false), /* pcrel_offset */
862 /* A sign-extended 16 bit value relative to _SDA2_BASE_, for use with
863 small data items. FIXME: Not supported. */
864 HOWTO (R_PPC_EMB_SDA2REL
, /* type */
866 1, /* size (0 = byte, 1 = short, 2 = long) */
868 false, /* pc_relative */
870 complain_overflow_signed
, /* complain_on_overflow */
871 bfd_elf_generic_reloc
, /* special_function */
872 "R_PPC_EMB_SDA2REL", /* name */
873 false, /* partial_inplace */
875 0xffff, /* dst_mask */
876 false), /* pcrel_offset */
878 /* Relocate against either _SDA_BASE_ or _SDA2_BASE_, filling in the 16 bit
879 signed offset from the appropriate base, and filling in the register
880 field with the appropriate register (0, 2, or 13). */
881 HOWTO (R_PPC_EMB_SDA21
, /* type */
883 1, /* size (0 = byte, 1 = short, 2 = long) */
885 false, /* pc_relative */
887 complain_overflow_signed
, /* complain_on_overflow */
888 bfd_elf_generic_reloc
, /* special_function */
889 "R_PPC_EMB_SDA21", /* name */
890 false, /* partial_inplace */
892 0xffff, /* dst_mask */
893 false), /* pcrel_offset */
895 /* Relocation not handled: R_PPC_EMB_MRKREF */
896 /* Relocation not handled: R_PPC_EMB_RELSEC16 */
897 /* Relocation not handled: R_PPC_EMB_RELST_LO */
898 /* Relocation not handled: R_PPC_EMB_RELST_HI */
899 /* Relocation not handled: R_PPC_EMB_RELST_HA */
900 /* Relocation not handled: R_PPC_EMB_BIT_FLD */
902 /* PC relative relocation against either _SDA_BASE_ or _SDA2_BASE_, filling
903 in the 16 bit signed offset from the appropriate base, and filling in the
904 register field with the appropriate register (0, 2, or 13). */
905 HOWTO (R_PPC_EMB_RELSDA
, /* type */
907 1, /* size (0 = byte, 1 = short, 2 = long) */
909 true, /* pc_relative */
911 complain_overflow_signed
, /* complain_on_overflow */
912 bfd_elf_generic_reloc
, /* special_function */
913 "R_PPC_EMB_RELSDA", /* name */
914 false, /* partial_inplace */
916 0xffff, /* dst_mask */
917 false), /* pcrel_offset */
919 /* Phony reloc to handle AIX style TOC entries */
920 HOWTO (R_PPC_TOC16
, /* type */
922 1, /* size (0 = byte, 1 = short, 2 = long) */
924 false, /* pc_relative */
926 complain_overflow_signed
, /* complain_on_overflow */
927 bfd_elf_generic_reloc
, /* special_function */
928 "R_PPC_TOC16", /* name */
929 false, /* partial_inplace */
931 0xffff, /* dst_mask */
932 false), /* pcrel_offset */
936 /* Initialize the ppc_elf_howto_table, so that linear accesses can be done. */
939 ppc_elf_howto_init ()
941 unsigned int i
, type
;
943 for (i
= 0; i
< sizeof (ppc_elf_howto_raw
) / sizeof (ppc_elf_howto_raw
[0]); i
++)
945 type
= ppc_elf_howto_raw
[i
].type
;
946 BFD_ASSERT (type
< sizeof(ppc_elf_howto_table
) / sizeof(ppc_elf_howto_table
[0]));
947 ppc_elf_howto_table
[type
] = &ppc_elf_howto_raw
[i
];
952 static reloc_howto_type
*
953 ppc_elf_reloc_type_lookup (abfd
, code
)
955 bfd_reloc_code_real_type code
;
957 enum ppc_reloc_type ppc_reloc
= R_PPC_NONE
;
959 if (!ppc_elf_howto_table
[ R_PPC_ADDR32
]) /* Initialize howto table if needed */
960 ppc_elf_howto_init ();
965 return (reloc_howto_type
*)NULL
;
967 case BFD_RELOC_NONE
: ppc_reloc
= R_PPC_NONE
; break;
968 case BFD_RELOC_32
: ppc_reloc
= R_PPC_ADDR32
; break;
969 case BFD_RELOC_PPC_BA26
: ppc_reloc
= R_PPC_ADDR24
; break;
970 case BFD_RELOC_16
: ppc_reloc
= R_PPC_ADDR16
; break;
971 case BFD_RELOC_LO16
: ppc_reloc
= R_PPC_ADDR16_LO
; break;
972 case BFD_RELOC_HI16
: ppc_reloc
= R_PPC_ADDR16_HI
; break;
973 case BFD_RELOC_HI16_S
: ppc_reloc
= R_PPC_ADDR16_HA
; break;
974 case BFD_RELOC_PPC_BA16
: ppc_reloc
= R_PPC_ADDR14
; break;
975 case BFD_RELOC_PPC_BA16_BRTAKEN
: ppc_reloc
= R_PPC_ADDR14_BRTAKEN
; break;
976 case BFD_RELOC_PPC_BA16_BRNTAKEN
: ppc_reloc
= R_PPC_ADDR14_BRNTAKEN
; break;
977 case BFD_RELOC_PPC_B26
: ppc_reloc
= R_PPC_REL24
; break;
978 case BFD_RELOC_PPC_B16
: ppc_reloc
= R_PPC_REL14
; break;
979 case BFD_RELOC_PPC_B16_BRTAKEN
: ppc_reloc
= R_PPC_REL14_BRTAKEN
; break;
980 case BFD_RELOC_PPC_B16_BRNTAKEN
: ppc_reloc
= R_PPC_REL14_BRNTAKEN
; break;
981 case BFD_RELOC_16_GOTOFF
: ppc_reloc
= R_PPC_GOT16
; break;
982 case BFD_RELOC_LO16_GOTOFF
: ppc_reloc
= R_PPC_GOT16_LO
; break;
983 case BFD_RELOC_HI16_GOTOFF
: ppc_reloc
= R_PPC_GOT16_HI
; break;
984 case BFD_RELOC_HI16_S_GOTOFF
: ppc_reloc
= R_PPC_GOT16_HA
; break;
985 case BFD_RELOC_24_PLT_PCREL
: ppc_reloc
= R_PPC_PLTREL24
; break;
986 case BFD_RELOC_PPC_COPY
: ppc_reloc
= R_PPC_COPY
; break;
987 case BFD_RELOC_PPC_GLOB_DAT
: ppc_reloc
= R_PPC_GLOB_DAT
; break;
988 case BFD_RELOC_PPC_LOCAL24PC
: ppc_reloc
= R_PPC_LOCAL24PC
; break;
989 case BFD_RELOC_32_PCREL
: ppc_reloc
= R_PPC_REL32
; break;
990 case BFD_RELOC_32_PLTOFF
: ppc_reloc
= R_PPC_PLT32
; break;
991 case BFD_RELOC_32_PLT_PCREL
: ppc_reloc
= R_PPC_PLTREL32
; break;
992 case BFD_RELOC_LO16_PLTOFF
: ppc_reloc
= R_PPC_PLT16_LO
; break;
993 case BFD_RELOC_HI16_PLTOFF
: ppc_reloc
= R_PPC_PLT16_HI
; break;
994 case BFD_RELOC_HI16_S_PLTOFF
: ppc_reloc
= R_PPC_PLT16_HA
; break;
995 case BFD_RELOC_GPREL16
: ppc_reloc
= R_PPC_SDAREL16
; break;
996 case BFD_RELOC_32_BASEREL
: ppc_reloc
= R_PPC_SECTOFF
; break;
997 case BFD_RELOC_LO16_BASEREL
: ppc_reloc
= R_PPC_SECTOFF_LO
; break;
998 case BFD_RELOC_HI16_BASEREL
: ppc_reloc
= R_PPC_SECTOFF_HI
; break;
999 case BFD_RELOC_HI16_S_BASEREL
: ppc_reloc
= R_PPC_SECTOFF_HA
; break;
1000 case BFD_RELOC_CTOR
: ppc_reloc
= R_PPC_ADDR32
; break;
1001 case BFD_RELOC_PPC_TOC16
: ppc_reloc
= R_PPC_TOC16
; break;
1002 case BFD_RELOC_PPC_EMB_NADDR32
: ppc_reloc
= R_PPC_EMB_NADDR32
; break;
1003 case BFD_RELOC_PPC_EMB_NADDR16
: ppc_reloc
= R_PPC_EMB_NADDR16
; break;
1004 case BFD_RELOC_PPC_EMB_NADDR16_LO
: ppc_reloc
= R_PPC_EMB_NADDR16_LO
; break;
1005 case BFD_RELOC_PPC_EMB_NADDR16_HI
: ppc_reloc
= R_PPC_EMB_NADDR16_HI
; break;
1006 case BFD_RELOC_PPC_EMB_NADDR16_HA
: ppc_reloc
= R_PPC_EMB_NADDR16_HA
; break;
1007 case BFD_RELOC_PPC_EMB_SDAI16
: ppc_reloc
= R_PPC_EMB_SDAI16
; break;
1008 case BFD_RELOC_PPC_EMB_SDA2I16
: ppc_reloc
= R_PPC_EMB_SDA2I16
; break;
1009 case BFD_RELOC_PPC_EMB_SDA2REL
: ppc_reloc
= R_PPC_EMB_SDA2REL
; break;
1010 case BFD_RELOC_PPC_EMB_SDA21
: ppc_reloc
= R_PPC_EMB_SDA21
; break;
1011 case BFD_RELOC_PPC_EMB_MRKREF
: ppc_reloc
= R_PPC_EMB_MRKREF
; break;
1012 case BFD_RELOC_PPC_EMB_RELSEC16
: ppc_reloc
= R_PPC_EMB_RELSEC16
; break;
1013 case BFD_RELOC_PPC_EMB_RELST_LO
: ppc_reloc
= R_PPC_EMB_RELST_LO
; break;
1014 case BFD_RELOC_PPC_EMB_RELST_HI
: ppc_reloc
= R_PPC_EMB_RELST_HI
; break;
1015 case BFD_RELOC_PPC_EMB_RELST_HA
: ppc_reloc
= R_PPC_EMB_RELST_HA
; break;
1016 case BFD_RELOC_PPC_EMB_BIT_FLD
: ppc_reloc
= R_PPC_EMB_BIT_FLD
; break;
1017 case BFD_RELOC_PPC_EMB_RELSDA
: ppc_reloc
= R_PPC_EMB_RELSDA
; break;
1020 return ppc_elf_howto_table
[ (int)ppc_reloc
];
1023 /* Set the howto pointer for a PowerPC ELF reloc. */
1026 ppc_elf_info_to_howto (abfd
, cache_ptr
, dst
)
1029 Elf32_Internal_Rela
*dst
;
1031 if (!ppc_elf_howto_table
[ R_PPC_ADDR32
]) /* Initialize howto table if needed */
1032 ppc_elf_howto_init ();
1034 BFD_ASSERT (ELF32_R_TYPE (dst
->r_info
) < (unsigned int) R_PPC_max
);
1035 cache_ptr
->howto
= ppc_elf_howto_table
[ELF32_R_TYPE (dst
->r_info
)];
1038 /* Function to set whether a module needs the -mrelocatable bit set. */
1041 ppc_elf_set_private_flags (abfd
, flags
)
1045 BFD_ASSERT (!elf_flags_init (abfd
)
1046 || elf_elfheader (abfd
)->e_flags
== flags
);
1048 elf_elfheader (abfd
)->e_flags
= flags
;
1049 elf_flags_init (abfd
) = true;
1053 /* Copy backend specific data from one object module to another */
1055 ppc_elf_copy_private_bfd_data (ibfd
, obfd
)
1059 /* This function is selected based on the input vector. We only
1060 want to copy information over if the output BFD also uses Elf
1062 if (bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
1065 BFD_ASSERT (!elf_flags_init (obfd
)
1066 || elf_elfheader (obfd
)->e_flags
== elf_elfheader (ibfd
)->e_flags
);
1068 elf_elfheader (obfd
)->e_flags
= elf_elfheader (ibfd
)->e_flags
;
1069 elf_flags_init (obfd
) = true;
1073 /* Merge backend specific data from an object file to the output
1074 object file when linking */
1076 ppc_elf_merge_private_bfd_data (ibfd
, obfd
)
1084 /* Check if we have the same endianess */
1085 if (ibfd
->xvec
->byteorder
!= obfd
->xvec
->byteorder
1086 && obfd
->xvec
->byteorder
!= BFD_ENDIAN_UNKNOWN
)
1088 (*_bfd_error_handler
)
1089 ("%s: compiled for a %s endian system and target is %s endian",
1090 bfd_get_filename (ibfd
),
1091 bfd_big_endian (ibfd
) ? "big" : "little",
1092 bfd_big_endian (obfd
) ? "big" : "little");
1094 bfd_set_error (bfd_error_wrong_format
);
1098 /* This function is selected based on the input vector. We only
1099 want to copy information over if the output BFD also uses Elf
1101 if (bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
1104 new_flags
= elf_elfheader (ibfd
)->e_flags
;
1105 old_flags
= elf_elfheader (obfd
)->e_flags
;
1106 if (!elf_flags_init (obfd
)) /* First call, no flags set */
1108 elf_flags_init (obfd
) = true;
1109 elf_elfheader (obfd
)->e_flags
= new_flags
;
1112 else if (new_flags
== old_flags
) /* Compatible flags are ok */
1115 else /* Incompatible flags */
1117 /* Warn about -mrelocatable mismatch. Allow -mrelocatable-lib to be linked
1120 if ((new_flags
& EF_PPC_RELOCATABLE
) != 0
1121 && (old_flags
& (EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
)) == 0)
1124 (*_bfd_error_handler
)
1125 ("%s: compiled with -mrelocatable and linked with modules compiled normally",
1126 bfd_get_filename (ibfd
));
1128 else if ((new_flags
& (EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
)) == 0
1129 && (old_flags
& EF_PPC_RELOCATABLE
) != 0)
1132 (*_bfd_error_handler
)
1133 ("%s: compiled normally and linked with modules compiled with -mrelocatable",
1134 bfd_get_filename (ibfd
));
1136 else if ((new_flags
& EF_PPC_RELOCATABLE_LIB
) != 0)
1137 elf_elfheader (obfd
)->e_flags
|= EF_PPC_RELOCATABLE_LIB
;
1140 /* Do not warn about eabi vs. V.4 mismatch, just or in the bit if any module uses it */
1141 elf_elfheader (obfd
)->e_flags
|= (new_flags
& EF_PPC_EMB
);
1143 new_flags
&= ~ (EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
| EF_PPC_EMB
);
1144 old_flags
&= ~ (EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
| EF_PPC_EMB
);
1146 /* Warn about any other mismatches */
1147 if (new_flags
!= old_flags
)
1150 (*_bfd_error_handler
)
1151 ("%s: uses different e_flags (0x%lx) fields than previous modules (0x%lx)",
1152 bfd_get_filename (ibfd
), (long)new_flags
, (long)old_flags
);
1157 bfd_set_error (bfd_error_bad_value
);
1166 /* Handle a PowerPC specific section when reading an object file. This
1167 is called when elfcode.h finds a section with an unknown type. */
1170 ppc_elf_section_from_shdr (abfd
, hdr
, name
)
1172 Elf32_Internal_Shdr
*hdr
;
1178 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
))
1181 newsect
= hdr
->bfd_section
;
1182 flags
= bfd_get_section_flags (abfd
, newsect
);
1183 if (hdr
->sh_flags
& SHF_EXCLUDE
)
1184 flags
|= SEC_EXCLUDE
;
1186 if (hdr
->sh_type
== SHT_ORDERED
)
1187 flags
|= SEC_SORT_ENTRIES
;
1189 bfd_set_section_flags (abfd
, newsect
, flags
);
1194 /* Set up any other section flags and such that may be necessary. */
1197 ppc_elf_fake_sections (abfd
, shdr
, asect
)
1199 Elf32_Internal_Shdr
*shdr
;
1202 if ((asect
->flags
& SEC_EXCLUDE
) != 0)
1203 shdr
->sh_flags
|= SHF_EXCLUDE
;
1205 if ((asect
->flags
& SEC_SORT_ENTRIES
) != 0)
1206 shdr
->sh_type
= SHT_ORDERED
;
1210 /* Create a special linker section */
1211 static elf_linker_section_t
*
1212 ppc_elf_create_linker_section (abfd
, info
, which
)
1214 struct bfd_link_info
*info
;
1215 enum elf_linker_section_enum which
;
1217 bfd
*dynobj
= elf_hash_table (info
)->dynobj
;
1218 elf_linker_section_t
*lsect
;
1220 /* Record the first bfd section that needs the special section */
1222 dynobj
= elf_hash_table (info
)->dynobj
= abfd
;
1224 /* If this is the first time, create the section */
1225 lsect
= elf_linker_section (dynobj
, which
);
1228 elf_linker_section_t defaults
;
1229 static elf_linker_section_t zero_section
;
1231 defaults
= zero_section
;
1232 defaults
.which
= which
;
1233 defaults
.hole_written_p
= false;
1234 defaults
.alignment
= 2;
1235 defaults
.flags
= SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
;
1240 (*_bfd_error_handler
) ("%s: Unknown special linker type %d",
1241 bfd_get_filename (abfd
),
1244 bfd_set_error (bfd_error_bad_value
);
1245 return (elf_linker_section_t
*)0;
1247 case LINKER_SECTION_GOT
: /* .got section */
1248 defaults
.name
= ".got";
1249 defaults
.rel_name
= ".rela.got";
1250 defaults
.sym_name
= "_GLOBAL_OFFSET_TABLE_";
1251 defaults
.max_hole_offset
= 32764;
1252 defaults
.hole_size
= 16;
1253 defaults
.sym_offset
= 4;
1256 case LINKER_SECTION_SDATA
: /* .sdata/.sbss section */
1257 defaults
.name
= ".sdata";
1258 defaults
.rel_name
= ".rela.sdata";
1259 defaults
.bss_name
= ".sbss";
1260 defaults
.sym_name
= "_SDA_BASE_";
1261 defaults
.sym_offset
= 32768;
1264 case LINKER_SECTION_SDATA2
: /* .sdata2/.sbss2 section */
1265 defaults
.name
= ".sdata2";
1266 defaults
.rel_name
= ".rela.sdata2";
1267 defaults
.bss_name
= ".sbss2";
1268 defaults
.sym_name
= "_SDA2_BASE_";
1269 defaults
.sym_offset
= 32768;
1273 lsect
= _bfd_elf_create_linker_section (abfd
, info
, which
, &defaults
);
1280 /* Adjust a symbol defined by a dynamic object and referenced by a
1281 regular object. The current definition is in some section of the
1282 dynamic object, but we're not including those sections. We have to
1283 change the definition to something the rest of the link can
1287 ppc_elf_adjust_dynamic_symbol (info
, h
)
1288 struct bfd_link_info
*info
;
1289 struct elf_link_hash_entry
*h
;
1292 fprintf (stderr
, "ppc_elf_adjust_dynamic_symbol called\n");
1298 /* Increment the index of a dynamic symbol by a given amount. Called
1299 via elf_link_hash_traverse. */
1302 ppc_elf_adjust_dynindx (h
, cparg
)
1303 struct elf_link_hash_entry
*h
;
1306 int *cp
= (int *) cparg
;
1309 fprintf (stderr
, "ppc_elf_adjust_dynindx called, h->dynindx = %d, *cp = %d\n", h
->dynindx
, *cp
);
1312 if (h
->dynindx
!= -1)
1319 /* Set the sizes of the dynamic sections. */
1322 ppc_elf_size_dynamic_sections (output_bfd
, info
)
1324 struct bfd_link_info
*info
;
1332 fprintf (stderr
, "ppc_elf_size_dynamic_sections called\n");
1335 dynobj
= elf_hash_table (info
)->dynobj
;
1336 BFD_ASSERT (dynobj
!= NULL
);
1338 if (elf_hash_table (info
)->dynamic_sections_created
)
1340 /* Set the contents of the .interp section to the interpreter. */
1343 s
= bfd_get_section_by_name (dynobj
, ".interp");
1344 BFD_ASSERT (s
!= NULL
);
1345 s
->_raw_size
= sizeof ELF_DYNAMIC_INTERPRETER
;
1346 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
1349 /* Make space for the trailing nop in .plt. */
1350 s
= bfd_get_section_by_name (dynobj
, ".plt");
1351 BFD_ASSERT (s
!= NULL
);
1352 if (s
->_raw_size
> 0)
1357 /* We may have created entries in the .rela.got, .rela.sdata, and
1358 .rela.sdata2 section2. However, if we are not creating the
1359 dynamic sections, we will not actually use these entries. Reset
1360 the size of .rela.got, et al, which will cause it to get
1361 stripped from the output file below. */
1362 static char *rela_sections
[] = { ".rela.got", ".rela.sdata", ".rela.sdata", (char *)0 };
1365 for (p
= rela_sections
; *p
!= (char *)0; p
++)
1367 s
= bfd_get_section_by_name (dynobj
, *p
);
1373 /* The check_relocs and adjust_dynamic_symbol entry points have
1374 determined the sizes of the various dynamic sections. Allocate
1378 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
1383 if ((s
->flags
& SEC_IN_MEMORY
) == 0)
1386 /* It's OK to base decisions on the section name, because none
1387 of the dynobj section names depend upon the input files. */
1388 name
= bfd_get_section_name (dynobj
, s
);
1393 if (strncmp (name
, ".rela", 5) == 0)
1395 if (s
->_raw_size
== 0)
1397 /* If we don't need this section, strip it from the
1398 output file. This is to handle .rela.bss and
1399 .rel.plt. We must create it in
1400 create_dynamic_sections, because it must be created
1401 before the linker maps input sections to output
1402 sections. The linker does that before
1403 adjust_dynamic_symbol is called, and it is that
1404 function which decides whether anything needs to go
1405 into these sections. */
1412 /* If this relocation section applies to a read only
1413 section, then we probably need a DT_TEXTREL entry. */
1414 target
= bfd_get_section_by_name (output_bfd
, name
+ 5);
1416 && (target
->flags
& SEC_READONLY
) != 0)
1419 if (strcmp (name
, ".rela.plt") == 0)
1422 /* We use the reloc_count field as a counter if we need
1423 to copy relocs into the output file. */
1429 if (strcmp (name
, ".plt") != 0
1430 && strcmp (name
, ".got") != 0
1431 && strcmp (name
, ".sdata") != 0
1432 && strcmp (name
, ".sdata2") != 0)
1434 /* It's not one of our sections, so don't allocate space. */
1442 for (spp
= &s
->output_section
->owner
->sections
;
1443 *spp
!= s
->output_section
;
1444 spp
= &(*spp
)->next
)
1446 *spp
= s
->output_section
->next
;
1447 --s
->output_section
->owner
->section_count
;
1452 /* Allocate memory for the section contents. */
1453 s
->contents
= (bfd_byte
*) bfd_alloc (dynobj
, s
->_raw_size
);
1454 if (s
->contents
== NULL
&& s
->_raw_size
!= 0)
1458 if (elf_hash_table (info
)->dynamic_sections_created
)
1460 /* Add some entries to the .dynamic section. We fill in the
1461 values later, in ppc_elf_finish_dynamic_sections, but we
1462 must add the entries now so that we get the correct size for
1463 the .dynamic section. The DT_DEBUG entry is filled in by the
1464 dynamic linker and used by the debugger. */
1467 if (! bfd_elf32_add_dynamic_entry (info
, DT_DEBUG
, 0))
1471 if (! bfd_elf32_add_dynamic_entry (info
, DT_PLTGOT
, 0))
1476 if (! bfd_elf32_add_dynamic_entry (info
, DT_PLTRELSZ
, 0)
1477 || ! bfd_elf32_add_dynamic_entry (info
, DT_PLTREL
, DT_RELA
)
1478 || ! bfd_elf32_add_dynamic_entry (info
, DT_JMPREL
, 0))
1482 if (! bfd_elf32_add_dynamic_entry (info
, DT_RELA
, 0)
1483 || ! bfd_elf32_add_dynamic_entry (info
, DT_RELASZ
, 0)
1484 || ! bfd_elf32_add_dynamic_entry (info
, DT_RELAENT
,
1485 sizeof (Elf32_External_Rela
)))
1490 if (! bfd_elf32_add_dynamic_entry (info
, DT_TEXTREL
, 0))
1495 /* If we are generating a shared library, we generate a section
1496 symbol for each output section. These are local symbols, which
1497 means that they must come first in the dynamic symbol table.
1498 That means we must increment the dynamic symbol index of every
1499 other dynamic symbol. */
1504 c
= bfd_count_sections (output_bfd
);
1505 elf_link_hash_traverse (elf_hash_table (info
),
1506 ppc_elf_adjust_dynindx
,
1508 elf_hash_table (info
)->dynsymcount
+= c
;
1510 for (i
= 1, s
= output_bfd
->sections
; s
!= NULL
; s
= s
->next
, i
++)
1512 elf_section_data (s
)->dynindx
= i
;
1513 /* These symbols will have no names, so we don't need to
1514 fiddle with dynstr_index. */
1522 /* Look through the relocs for a section during the first phase, and
1523 allocate space in the global offset table or procedure linkage
1527 ppc_elf_check_relocs (abfd
, info
, sec
, relocs
)
1529 struct bfd_link_info
*info
;
1531 const Elf_Internal_Rela
*relocs
;
1534 Elf_Internal_Shdr
*symtab_hdr
;
1535 struct elf_link_hash_entry
**sym_hashes
;
1536 const Elf_Internal_Rela
*rel
;
1537 const Elf_Internal_Rela
*rel_end
;
1538 elf_linker_section_t
*got
;
1539 elf_linker_section_t
*sdata
;
1540 elf_linker_section_t
*sdata2
;
1543 if (info
->relocateable
)
1547 fprintf (stderr
, "ppc_elf_check_relocs called for section %s\n",
1548 bfd_get_section_name (abfd
, sec
));
1551 /* Create the linker generated sections all the time so that the special
1552 symbols are created. */
1553 if ((got
= elf_linker_section (abfd
, LINKER_SECTION_GOT
)) == NULL
)
1555 got
= ppc_elf_create_linker_section (abfd
, info
, LINKER_SECTION_GOT
);
1560 if ((sdata
= elf_linker_section (abfd
, LINKER_SECTION_SDATA
)) == NULL
)
1562 sdata
= ppc_elf_create_linker_section (abfd
, info
, LINKER_SECTION_SDATA
);
1568 if ((sdata2
= elf_linker_section (abfd
, LINKER_SECTION_SDATA2
)) == NULL
)
1570 sdata2
= ppc_elf_create_linker_section (abfd
, info
, LINKER_SECTION_SDATA2
);
1575 dynobj
= elf_hash_table (info
)->dynobj
;
1576 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
1577 sym_hashes
= elf_sym_hashes (abfd
);
1581 rel_end
= relocs
+ sec
->reloc_count
;
1582 for (rel
= relocs
; rel
< rel_end
; rel
++)
1584 unsigned long r_symndx
;
1585 struct elf_link_hash_entry
*h
;
1587 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1588 if (r_symndx
< symtab_hdr
->sh_info
)
1591 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1593 switch (ELF32_R_TYPE (rel
->r_info
))
1598 /* GOT16 relocations */
1600 case R_PPC_GOT16_LO
:
1601 case R_PPC_GOT16_HI
:
1602 case R_PPC_GOT16_HA
:
1603 if (got
->rel_section
== NULL
1604 && (h
!= NULL
|| info
->shared
)
1605 && !_bfd_elf_make_linker_section_rela (dynobj
, got
, 2))
1608 if (!bfd_elf32_create_pointer_linker_section (abfd
, info
, got
, h
, rel
))
1613 /* Indirect .sdata relocation */
1614 case R_PPC_EMB_SDAI16
:
1615 if (got
->rel_section
== NULL
1616 && (h
!= NULL
|| info
->shared
)
1617 && !_bfd_elf_make_linker_section_rela (dynobj
, got
, 2))
1620 BFD_ASSERT (!info
->shared
);
1621 if (!bfd_elf32_create_pointer_linker_section (abfd
, info
, sdata
, h
, rel
))
1626 /* Indirect .sdata2 relocation */
1627 case R_PPC_EMB_SDA2I16
:
1628 if (got
->rel_section
== NULL
1629 && (h
!= NULL
|| info
->shared
)
1630 && !_bfd_elf_make_linker_section_rela (dynobj
, got
, 2))
1633 BFD_ASSERT (!info
->shared
);
1634 if (!bfd_elf32_create_pointer_linker_section (abfd
, info
, sdata2
, h
, rel
))
1641 case R_PPC_PLTREL24
:
1642 case R_PPC_PLT16_LO
:
1643 case R_PPC_PLT16_HI
:
1644 case R_PPC_PLT16_HA
:
1646 fprintf (stderr
, "Reloc requires a PLT entry\n");
1648 /* This symbol requires a procedure linkage table entry. We
1649 actually build the entry in adjust_dynamic_symbol,
1650 because this might be a case of linking PIC code without
1651 linking in any dynamic objects, in which case we don't
1652 need to generate a procedure linkage table after all. */
1656 /* It does not make sense to have a procedure linkage
1657 table entry for a local symbol. */
1658 bfd_set_error (bfd_error_bad_value
);
1662 /* Make sure this symbol is output as a dynamic symbol. */
1663 if (h
->dynindx
== -1)
1665 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
1669 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
1675 && strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
1679 case R_SPARC_DISP16
:
1680 case R_SPARC_DISP32
:
1681 case R_SPARC_WDISP30
:
1682 case R_SPARC_WDISP22
:
1695 && (sec
->flags
& SEC_ALLOC
) != 0)
1697 /* When creating a shared object, we must copy these
1698 relocs into the output file. We create a reloc
1699 section in dynobj and make room for the reloc. */
1704 name
= (bfd_elf_string_from_elf_section
1706 elf_elfheader (abfd
)->e_shstrndx
,
1707 elf_section_data (sec
)->rel_hdr
.sh_name
));
1711 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
1712 && strcmp (bfd_get_section_name (abfd
, sec
),
1715 sreloc
= bfd_get_section_by_name (dynobj
, name
);
1718 sreloc
= bfd_make_section (dynobj
, name
);
1720 || ! bfd_set_section_flags (dynobj
, sreloc
,
1726 || ! bfd_set_section_alignment (dynobj
, sreloc
, 2))
1731 sreloc
->_raw_size
+= sizeof (Elf32_External_Rela
);
1743 /* Finish up dynamic symbol handling. We set the contents of various
1744 dynamic sections here. */
1747 ppc_elf_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
1749 struct bfd_link_info
*info
;
1750 struct elf_link_hash_entry
*h
;
1751 Elf_Internal_Sym
*sym
;
1756 fprintf (stderr
, "ppc_elf_finish_dynamic_symbol called for %s\n", h
->root
.root
.string
);
1759 dynobj
= elf_hash_table (info
)->dynobj
;
1760 BFD_ASSERT (dynobj
!= NULL
);
1762 if (h
->plt_offset
!= (bfd_vma
) -1)
1766 Elf_Internal_Rela rela
;
1768 /* This symbol has an entry in the procedure linkage table. Set
1771 BFD_ASSERT (h
->dynindx
!= -1);
1773 splt
= bfd_get_section_by_name (dynobj
, ".plt");
1774 srela
= bfd_get_section_by_name (dynobj
, ".rela.plt");
1775 BFD_ASSERT (splt
!= NULL
&& srela
!= NULL
);
1777 /* Fill in the entry in the procedure linkage table. */
1779 bfd_put_32 (output_bfd
,
1780 PLT_ENTRY_WORD0
+ h
->plt_offset
,
1781 splt
->contents
+ h
->plt_offset
);
1782 bfd_put_32 (output_bfd
,
1784 + (((- (h
->plt_offset
+ 4)) >> 2) & 0x3fffff)),
1785 splt
->contents
+ h
->plt_offset
+ 4);
1786 bfd_put_32 (output_bfd
, PLT_ENTRY_WORD2
,
1787 splt
->contents
+ h
->plt_offset
+ 8);
1789 /* Fill in the entry in the .rela.plt section. */
1790 rela
.r_offset
= (splt
->output_section
->vma
1791 + splt
->output_offset
1793 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_SPARC_JMP_SLOT
);
1795 bfd_elf32_swap_reloca_out (output_bfd
, &rela
,
1796 ((Elf32_External_Rela
*) srela
->contents
1797 + h
->plt_offset
/ PLT_ENTRY_SIZE
- 4));
1800 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
1802 /* Mark the symbol as undefined, rather than as defined in
1803 the .plt section. Leave the value alone. */
1804 sym
->st_shndx
= SHN_UNDEF
;
1808 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_COPY
) != 0)
1811 Elf_Internal_Rela rela
;
1813 /* This symbols needs a copy reloc. Set it up. */
1815 BFD_ASSERT (h
->dynindx
!= -1);
1817 s
= bfd_get_section_by_name (h
->root
.u
.def
.section
->owner
,
1819 BFD_ASSERT (s
!= NULL
);
1821 rela
.r_offset
= (h
->root
.u
.def
.value
1822 + h
->root
.u
.def
.section
->output_section
->vma
1823 + h
->root
.u
.def
.section
->output_offset
);
1824 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_PPC_COPY
);
1826 bfd_elf32_swap_reloca_out (output_bfd
, &rela
,
1827 ((Elf32_External_Rela
*) s
->contents
1832 /* Mark some specially defined symbols as absolute. */
1833 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
1834 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0
1835 || strcmp (h
->root
.root
.string
, "_PROCEDURE_LINKAGE_TABLE_") == 0)
1836 sym
->st_shndx
= SHN_ABS
;
1842 /* Finish up the dynamic sections. */
1845 ppc_elf_finish_dynamic_sections (output_bfd
, info
)
1847 struct bfd_link_info
*info
;
1850 bfd
*dynobj
= elf_hash_table (info
)->dynobj
;
1851 elf_linker_section_t
*got
= elf_linker_section (dynobj
, LINKER_SECTION_GOT
);
1854 fprintf (stderr
, "ppc_elf_finish_dynamic_sections called\n");
1857 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
1859 if (elf_hash_table (info
)->dynamic_sections_created
)
1862 Elf32_External_Dyn
*dyncon
, *dynconend
;
1864 splt
= bfd_get_section_by_name (dynobj
, ".plt");
1865 BFD_ASSERT (splt
!= NULL
&& sdyn
!= NULL
);
1867 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
1868 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
1869 for (; dyncon
< dynconend
; dyncon
++)
1871 Elf_Internal_Dyn dyn
;
1875 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
1879 case DT_PLTGOT
: name
= ".plt"; size
= false; break;
1880 case DT_PLTRELSZ
: name
= ".rela.plt"; size
= true; break;
1881 case DT_JMPREL
: name
= ".rela.plt"; size
= false; break;
1882 default: name
= NULL
; size
= false; break;
1889 s
= bfd_get_section_by_name (output_bfd
, name
);
1895 dyn
.d_un
.d_ptr
= s
->vma
;
1898 if (s
->_cooked_size
!= 0)
1899 dyn
.d_un
.d_val
= s
->_cooked_size
;
1901 dyn
.d_un
.d_val
= s
->_raw_size
;
1904 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
1909 /* Add a blrl instruction at _GLOBAL_OFFSET_TABLE_-4 so that a function can
1910 easily find the address of the _GLOBAL_OFFSET_TABLE_. */
1913 unsigned char *contents
= got
->section
->contents
+ got
->hole_offset
;
1914 bfd_put_32 (output_bfd
, 0x4e800021 /* blrl */, contents
);
1917 bfd_put_32 (output_bfd
, (bfd_vma
) 0, contents
+4);
1919 bfd_put_32 (output_bfd
,
1920 sdyn
->output_section
->vma
+ sdyn
->output_offset
,
1923 elf_section_data (got
->section
->output_section
)->this_hdr
.sh_entsize
= 4;
1930 Elf_Internal_Sym sym
;
1932 /* Set up the section symbols for the output sections. */
1934 sdynsym
= bfd_get_section_by_name (dynobj
, ".dynsym");
1935 BFD_ASSERT (sdynsym
!= NULL
);
1939 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_SECTION
);
1942 for (s
= output_bfd
->sections
; s
!= NULL
; s
= s
->next
)
1946 sym
.st_value
= s
->vma
;
1948 indx
= elf_section_data (s
)->this_idx
;
1949 BFD_ASSERT (indx
> 0);
1950 sym
.st_shndx
= indx
;
1952 bfd_elf32_swap_symbol_out (output_bfd
, &sym
,
1953 (PTR
) (((Elf32_External_Sym
*)
1955 + elf_section_data (s
)->dynindx
));
1958 /* Set the sh_info field of the output .dynsym section to the
1959 index of the first global symbol. */
1960 elf_section_data (sdynsym
->output_section
)->this_hdr
.sh_info
=
1961 bfd_count_sections (output_bfd
) + 1;
1968 /* The RELOCATE_SECTION function is called by the ELF backend linker
1969 to handle the relocations for a section.
1971 The relocs are always passed as Rela structures; if the section
1972 actually uses Rel structures, the r_addend field will always be
1975 This function is responsible for adjust the section contents as
1976 necessary, and (if using Rela relocs and generating a
1977 relocateable output file) adjusting the reloc addend as
1980 This function does not have to worry about setting the reloc
1981 address or the reloc symbol index.
1983 LOCAL_SYMS is a pointer to the swapped in local symbols.
1985 LOCAL_SECTIONS is an array giving the section in the input file
1986 corresponding to the st_shndx field of each local symbol.
1988 The global hash table entry for the global symbols can be found
1989 via elf_sym_hashes (input_bfd).
1991 When generating relocateable output, this function must handle
1992 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
1993 going to be the section symbol corresponding to the output
1994 section, which means that the addend must be adjusted
1998 ppc_elf_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
1999 contents
, relocs
, local_syms
, local_sections
)
2001 struct bfd_link_info
*info
;
2003 asection
*input_section
;
2005 Elf_Internal_Rela
*relocs
;
2006 Elf_Internal_Sym
*local_syms
;
2007 asection
**local_sections
;
2009 Elf_Internal_Shdr
*symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
2010 struct elf_link_hash_entry
**sym_hashes
= elf_sym_hashes (input_bfd
);
2011 bfd
*dynobj
= elf_hash_table (info
)->dynobj
;
2012 elf_linker_section_t
*got
= elf_linker_section (dynobj
, LINKER_SECTION_GOT
);
2013 elf_linker_section_t
*sdata
= elf_linker_section (dynobj
, LINKER_SECTION_SDATA
);
2014 elf_linker_section_t
*sdata2
= elf_linker_section (dynobj
, LINKER_SECTION_SDATA2
);
2015 Elf_Internal_Rela
*rel
= relocs
;
2016 Elf_Internal_Rela
*relend
= relocs
+ input_section
->reloc_count
;
2021 fprintf (stderr
, "ppc_elf_relocate_section called for %s section %s, %ld relocations%s\n",
2022 bfd_get_filename (input_bfd
),
2023 bfd_section_name(input_bfd
, input_section
),
2024 (long)input_section
->reloc_count
,
2025 (info
->relocateable
) ? " (relocatable)" : "");
2028 if (!ppc_elf_howto_table
[ R_PPC_ADDR32
]) /* Initialize howto table if needed */
2029 ppc_elf_howto_init ();
2031 for (; rel
< relend
; rel
++)
2033 enum ppc_reloc_type r_type
= (enum ppc_reloc_type
)ELF32_R_TYPE (rel
->r_info
);
2034 bfd_vma offset
= rel
->r_offset
;
2035 bfd_vma addend
= rel
->r_addend
;
2036 bfd_reloc_status_type r
= bfd_reloc_other
;
2037 Elf_Internal_Sym
*sym
= (Elf_Internal_Sym
*)0;
2038 asection
*sec
= (asection
*)0;
2039 struct elf_link_hash_entry
*h
= (struct elf_link_hash_entry
*)0;
2040 reloc_howto_type
*howto
;
2041 unsigned long r_symndx
;
2044 /* Unknown relocation handling */
2045 if ((unsigned)r_type
>= (unsigned)R_PPC_max
|| !ppc_elf_howto_table
[(int)r_type
])
2047 (*_bfd_error_handler
) ("%s: unknown relocation type %d",
2048 bfd_get_filename (input_bfd
),
2051 bfd_set_error (bfd_error_bad_value
);
2056 howto
= ppc_elf_howto_table
[(int)r_type
];
2057 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2059 if (info
->relocateable
)
2061 /* This is a relocateable link. We don't have to change
2062 anything, unless the reloc is against a section symbol,
2063 in which case we have to adjust according to where the
2064 section symbol winds up in the output section. */
2065 if (r_symndx
< symtab_hdr
->sh_info
)
2067 sym
= local_syms
+ r_symndx
;
2068 if ((unsigned)ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
2070 sec
= local_sections
[r_symndx
];
2071 addend
= rel
->r_addend
+= sec
->output_offset
+ sym
->st_value
;
2076 fprintf (stderr
, "\ttype = %s (%d), symbol index = %ld, offset = %ld, addend = %ld\n",
2086 /* This is a final link. */
2087 if (r_symndx
< symtab_hdr
->sh_info
)
2089 sym
= local_syms
+ r_symndx
;
2090 sec
= local_sections
[r_symndx
];
2091 relocation
= (sec
->output_section
->vma
2092 + sec
->output_offset
2097 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2098 if (h
->root
.type
== bfd_link_hash_defined
2099 || h
->root
.type
== bfd_link_hash_defweak
)
2101 sec
= h
->root
.u
.def
.section
;
2102 relocation
= (h
->root
.u
.def
.value
2103 + sec
->output_section
->vma
2104 + sec
->output_offset
);
2106 else if (h
->root
.type
== bfd_link_hash_undefweak
)
2108 else if (info
->shared
)
2112 (*info
->callbacks
->undefined_symbol
)(info
,
2113 h
->root
.root
.string
,
2122 switch ((int)r_type
)
2125 (*_bfd_error_handler
) ("%s: unknown relocation type %d",
2126 bfd_get_filename (input_bfd
),
2129 bfd_set_error (bfd_error_bad_value
);
2133 /* relocations that need no special processing */
2134 case (int)R_PPC_NONE
:
2135 case (int)R_PPC_ADDR32
:
2136 case (int)R_PPC_ADDR24
:
2137 case (int)R_PPC_ADDR16
:
2138 case (int)R_PPC_ADDR16_LO
:
2139 case (int)R_PPC_ADDR16_HI
:
2140 case (int)R_PPC_ADDR14
:
2141 case (int)R_PPC_REL24
:
2142 case (int)R_PPC_REL14
:
2143 case (int)R_PPC_UADDR32
:
2144 case (int)R_PPC_UADDR16
:
2145 case (int)R_PPC_REL32
:
2148 /* branch taken prediction relocations */
2149 case (int)R_PPC_ADDR14_BRTAKEN
:
2150 case (int)R_PPC_REL14_BRTAKEN
:
2151 insn
= bfd_get_32 (output_bfd
, contents
+ offset
);
2152 if ((relocation
- offset
) & 0x8000)
2153 insn
&= ~BRANCH_PREDICT_BIT
;
2155 insn
|= BRANCH_PREDICT_BIT
;
2156 bfd_put_32 (output_bfd
, insn
, contents
+ offset
);
2159 /* branch not taken predicition relocations */
2160 case (int)R_PPC_ADDR14_BRNTAKEN
:
2161 case (int)R_PPC_REL14_BRNTAKEN
:
2162 insn
= bfd_get_32 (output_bfd
, contents
+ offset
);
2163 if ((relocation
- offset
) & 0x8000)
2164 insn
|= BRANCH_PREDICT_BIT
;
2166 insn
&= ~BRANCH_PREDICT_BIT
;
2167 bfd_put_32 (output_bfd
, insn
, contents
+ offset
);
2170 /* GOT16 relocations */
2171 case (int)R_PPC_GOT16
:
2172 case (int)R_PPC_GOT16_LO
:
2173 case (int)R_PPC_GOT16_HI
:
2174 case (int)R_PPC_GOT16_HA
:
2175 relocation
= bfd_elf32_finish_pointer_linker_section (output_bfd
, input_bfd
, info
,
2176 got
, h
, relocation
, rel
,
2180 /* Indirect .sdata relocation */
2181 case (int)R_PPC_EMB_SDAI16
:
2182 BFD_ASSERT (sdata
!= NULL
);
2183 relocation
= bfd_elf32_finish_pointer_linker_section (output_bfd
, input_bfd
, info
,
2184 sdata
, h
, relocation
, rel
,
2188 /* Indirect .sdata2 relocation */
2189 case (int)R_PPC_EMB_SDA2I16
:
2190 BFD_ASSERT (sdata2
!= NULL
);
2191 relocation
= bfd_elf32_finish_pointer_linker_section (output_bfd
, input_bfd
, info
,
2192 sdata2
, h
, relocation
, rel
,
2196 /* Handle the TOC16 reloc. We want to use the offset within the .got
2197 section, not the actual VMA. This is appropriate when generating
2198 an embedded ELF object, for which the .got section acts like the
2199 AIX .toc section. */
2200 case (int)R_PPC_TOC16
: /* phony GOT16 relocations */
2201 BFD_ASSERT (sec
!= (asection
*)0);
2202 BFD_ASSERT (bfd_is_und_section (sec
)
2203 || strcmp (bfd_get_section_name (abfd
, sec
), ".got") == 0
2204 || strcmp (bfd_get_section_name (abfd
, sec
), ".cgot") == 0)
2206 addend
-= sec
->output_section
->vma
+ 0x8000;
2209 /* arithmetic adjust relocations */
2210 case (int)R_PPC_ADDR16_HA
:
2211 BFD_ASSERT (sec
!= (asection
*)0);
2212 addend
+= ((relocation
+ addend
) & 0x8000) << 1;
2215 /* relocate against _SDA_BASE_ */
2216 case (int)R_PPC_SDAREL16
:
2217 BFD_ASSERT (sec
!= (asection
*)0);
2218 if (strcmp (bfd_get_section_name (abfd
, sec
), ".sdata") != 0
2219 && strcmp (bfd_get_section_name (abfd
, sec
), ".sbss") != 0)
2221 (*_bfd_error_handler
) ("%s: The target of a %s relocation is in the wrong section (%s)",
2222 bfd_get_filename (input_bfd
),
2223 ppc_elf_howto_table
[ (int)r_type
]->name
,
2224 bfd_get_section_name (abfd
, sec
));
2226 bfd_set_error (bfd_error_bad_value
);
2230 addend
-= sdata
->sym_hash
->root
.u
.def
.value
;
2231 relocation
= sdata
->sym_hash
->root
.u
.def
.section
->output_section
->vma
- relocation
;
2235 /* relocate against _SDA2_BASE_ */
2236 case (int)R_PPC_EMB_SDA2REL
:
2237 BFD_ASSERT (sec
!= (asection
*)0);
2238 if (strcmp (bfd_get_section_name (abfd
, sec
), ".sdata2") != 0
2239 && strcmp (bfd_get_section_name (abfd
, sec
), ".sbss2") != 0)
2241 (*_bfd_error_handler
) ("%s: The target of a %s relocation is in the wrong section (%s)",
2242 bfd_get_filename (input_bfd
),
2243 ppc_elf_howto_table
[ (int)r_type
]->name
,
2244 bfd_get_section_name (abfd
, sec
));
2246 bfd_set_error (bfd_error_bad_value
);
2250 addend
-= sdata2
->sym_hash
->root
.u
.def
.value
;
2251 relocation
= sdata2
->sym_hash
->root
.u
.def
.section
->output_section
->vma
- relocation
;
2255 /* relocate against either _SDA_BASE_, _SDA2_BASE_, or 0 */
2256 case (int)R_PPC_EMB_SDA21
:
2257 case (int)R_PPC_EMB_RELSDA
:
2259 const char *name
= bfd_get_section_name (abfd
, sec
);
2262 BFD_ASSERT (sec
!= (asection
*)0);
2263 if (strcmp (name
, ".sdata") == 0 || strcmp (name
, ".sbss") == 0)
2266 addend
-= sdata
->sym_hash
->root
.u
.def
.value
;
2267 relocation
= sdata
->sym_hash
->root
.u
.def
.section
->output_section
->vma
- relocation
;
2270 else if (strcmp (name
, ".sdata2") == 0 || strcmp (name
, ".sbss2") == 0)
2273 addend
-= sdata2
->sym_hash
->root
.u
.def
.value
;
2274 relocation
= sdata2
->sym_hash
->root
.u
.def
.section
->output_section
->vma
- relocation
;
2277 else if (strcmp (name
, ".PPC.EMB.sdata0") == 0 || strcmp (name
, ".PPC.EMB.sbss0") == 0)
2284 (*_bfd_error_handler
) ("%s: The target of a %s relocation is in the wrong section (%s)",
2285 bfd_get_filename (input_bfd
),
2286 ppc_elf_howto_table
[ (int)r_type
]->name
,
2287 bfd_get_section_name (abfd
, sec
));
2289 bfd_set_error (bfd_error_bad_value
);
2294 if (r_type
== R_PPC_EMB_SDA21
)
2295 { /* fill in register field */
2296 insn
= bfd_get_32 (output_bfd
, contents
+ offset
- 2);
2297 insn
= (insn
& ~RA_REGISTER_MASK
) | (reg
<< RA_REGISTER_SHIFT
);
2298 bfd_put_32 (output_bfd
, insn
, contents
+ offset
- 2);
2303 case (int)R_PPC_PLTREL24
:
2304 case (int)R_PPC_COPY
:
2305 case (int)R_PPC_GLOB_DAT
:
2306 case (int)R_PPC_JMP_SLOT
:
2307 case (int)R_PPC_RELATIVE
:
2308 case (int)R_PPC_LOCAL24PC
:
2309 case (int)R_PPC_PLT32
:
2310 case (int)R_PPC_PLTREL32
:
2311 case (int)R_PPC_PLT16_LO
:
2312 case (int)R_PPC_PLT16_HI
:
2313 case (int)R_PPC_PLT16_HA
:
2314 case (int)R_PPC_SECTOFF
:
2315 case (int)R_PPC_SECTOFF_LO
:
2316 case (int)R_PPC_SECTOFF_HI
:
2317 case (int)R_PPC_SECTOFF_HA
:
2318 case (int)R_PPC_EMB_NADDR32
:
2319 case (int)R_PPC_EMB_NADDR16
:
2320 case (int)R_PPC_EMB_NADDR16_LO
:
2321 case (int)R_PPC_EMB_NADDR16_HI
:
2322 case (int)R_PPC_EMB_NADDR16_HA
:
2323 case (int)R_PPC_EMB_MRKREF
:
2324 case (int)R_PPC_EMB_RELSEC16
:
2325 case (int)R_PPC_EMB_RELST_LO
:
2326 case (int)R_PPC_EMB_RELST_HI
:
2327 case (int)R_PPC_EMB_RELST_HA
:
2328 case (int)R_PPC_EMB_BIT_FLD
:
2330 (*_bfd_error_handler
) ("%s: Relocation %s is not yet supported.",
2331 bfd_get_filename (input_bfd
),
2332 ppc_elf_howto_table
[ (int)r_type
]->name
);
2334 bfd_set_error (bfd_error_invalid_operation
);
2341 fprintf (stderr
, "\ttype = %s (%d), symbol index = %ld, offset = %ld, addend = %ld\n",
2349 r
= _bfd_final_link_relocate (howto
,
2357 if (r
!= bfd_reloc_ok
)
2365 case bfd_reloc_overflow
:
2370 name
= h
->root
.root
.string
;
2373 name
= bfd_elf_string_from_elf_section (input_bfd
,
2374 symtab_hdr
->sh_link
,
2380 name
= bfd_section_name (input_bfd
, sec
);
2383 (*info
->callbacks
->reloc_overflow
)(info
,
2399 fprintf (stderr
, "\n");
2406 #define TARGET_LITTLE_SYM bfd_elf32_powerpcle_vec
2407 #define TARGET_LITTLE_NAME "elf32-powerpcle"
2408 #define TARGET_BIG_SYM bfd_elf32_powerpc_vec
2409 #define TARGET_BIG_NAME "elf32-powerpc"
2410 #define ELF_ARCH bfd_arch_powerpc
2411 #define ELF_MACHINE_CODE EM_PPC
2412 #define ELF_MAXPAGESIZE 0x10000
2413 #define elf_info_to_howto ppc_elf_info_to_howto
2415 #ifdef EM_CYGNUS_POWERPC
2416 #define ELF_MACHINE_ALT1 EM_CYGNUS_POWERPC
2420 #define ELF_MACHINE_ALT2 EM_PPC_OLD
2423 #define bfd_elf32_bfd_copy_private_bfd_data ppc_elf_copy_private_bfd_data
2424 #define bfd_elf32_bfd_merge_private_bfd_data ppc_elf_merge_private_bfd_data
2425 #define bfd_elf32_bfd_set_private_flags ppc_elf_set_private_flags
2426 #define bfd_elf32_bfd_reloc_type_lookup ppc_elf_reloc_type_lookup
2427 #define elf_backend_section_from_shdr ppc_elf_section_from_shdr
2428 #define elf_backend_relocate_section ppc_elf_relocate_section
2429 #define elf_backend_create_dynamic_sections _bfd_elf_create_dynamic_sections
2430 #define elf_backend_check_relocs ppc_elf_check_relocs
2431 #define elf_backend_adjust_dynamic_symbol ppc_elf_adjust_dynamic_symbol
2432 #define elf_backend_size_dynamic_sections ppc_elf_size_dynamic_sections
2433 #define elf_backend_finish_dynamic_symbol ppc_elf_finish_dynamic_symbol
2434 #define elf_backend_finish_dynamic_sections ppc_elf_finish_dynamic_sections
2435 #define elf_backend_fake_sections ppc_elf_fake_sections
2437 #include "elf32-target.h"