1 /* PowerPC-specific support for 32-bit ELF
2 Copyright 1994, 1995, 1996, 1997 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 bfd_reloc_status_type ppc_elf_addr16_ha_reloc
108 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
109 static boolean ppc_elf_set_private_flags
PARAMS ((bfd
*, flagword
));
110 static boolean ppc_elf_copy_private_bfd_data
PARAMS ((bfd
*, bfd
*));
111 static boolean ppc_elf_merge_private_bfd_data
PARAMS ((bfd
*, bfd
*));
113 static int ppc_elf_additional_program_headers
PARAMS ((bfd
*));
114 static boolean ppc_elf_modify_segment_map
PARAMS ((bfd
*));
116 static boolean ppc_elf_section_from_shdr
PARAMS ((bfd
*,
117 Elf32_Internal_Shdr
*,
119 static boolean ppc_elf_fake_sections
120 PARAMS ((bfd
*, Elf32_Internal_Shdr
*, asection
*));
122 static elf_linker_section_t
*ppc_elf_create_linker_section
124 struct bfd_link_info
*info
,
125 enum elf_linker_section_enum
));
127 static boolean ppc_elf_check_relocs
PARAMS ((bfd
*,
128 struct bfd_link_info
*,
130 const Elf_Internal_Rela
*));
132 static boolean ppc_elf_adjust_dynamic_symbol
PARAMS ((struct bfd_link_info
*,
133 struct elf_link_hash_entry
*));
135 static boolean ppc_elf_adjust_dynindx
PARAMS ((struct elf_link_hash_entry
*, PTR
));
137 static boolean ppc_elf_size_dynamic_sections
PARAMS ((bfd
*, struct bfd_link_info
*));
139 static boolean ppc_elf_relocate_section
PARAMS ((bfd
*,
140 struct bfd_link_info
*info
,
144 Elf_Internal_Rela
*relocs
,
145 Elf_Internal_Sym
*local_syms
,
148 static boolean ppc_elf_add_symbol_hook
PARAMS ((bfd
*,
149 struct bfd_link_info
*,
150 const Elf_Internal_Sym
*,
156 static boolean ppc_elf_finish_dynamic_symbol
PARAMS ((bfd
*,
157 struct bfd_link_info
*,
158 struct elf_link_hash_entry
*,
159 Elf_Internal_Sym
*));
161 static boolean ppc_elf_finish_dynamic_sections
PARAMS ((bfd
*, struct bfd_link_info
*));
163 #define BRANCH_PREDICT_BIT 0x200000 /* branch prediction bit for branch taken relocs */
164 #define RA_REGISTER_MASK 0x001f0000 /* mask to set RA in memory instructions */
165 #define RA_REGISTER_SHIFT 16 /* value to shift register by to insert RA */
167 /* The name of the dynamic interpreter. This is put in the .interp
170 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
172 /* The size in bytes of an entry in the procedure linkage table, and of the initial size
173 of the plt reserved for the dynamic linker. */
175 #define PLT_ENTRY_SIZE 12
176 #define PLT_INITIAL_ENTRY_SIZE 72
179 static reloc_howto_type
*ppc_elf_howto_table
[ (int)R_PPC_max
];
181 static reloc_howto_type ppc_elf_howto_raw
[] =
183 /* This reloc does nothing. */
184 HOWTO (R_PPC_NONE
, /* type */
186 2, /* size (0 = byte, 1 = short, 2 = long) */
188 false, /* pc_relative */
190 complain_overflow_bitfield
, /* complain_on_overflow */
191 bfd_elf_generic_reloc
, /* special_function */
192 "R_PPC_NONE", /* name */
193 false, /* partial_inplace */
196 false), /* pcrel_offset */
198 /* A standard 32 bit relocation. */
199 HOWTO (R_PPC_ADDR32
, /* type */
201 2, /* size (0 = byte, 1 = short, 2 = long) */
203 false, /* pc_relative */
205 complain_overflow_bitfield
, /* complain_on_overflow */
206 bfd_elf_generic_reloc
, /* special_function */
207 "R_PPC_ADDR32", /* name */
208 false, /* partial_inplace */
210 0xffffffff, /* dst_mask */
211 false), /* pcrel_offset */
213 /* An absolute 26 bit branch; the lower two bits must be zero.
214 FIXME: we don't check that, we just clear them. */
215 HOWTO (R_PPC_ADDR24
, /* type */
217 2, /* size (0 = byte, 1 = short, 2 = long) */
219 false, /* pc_relative */
221 complain_overflow_bitfield
, /* complain_on_overflow */
222 bfd_elf_generic_reloc
, /* special_function */
223 "R_PPC_ADDR24", /* name */
224 false, /* partial_inplace */
226 0x3fffffc, /* dst_mask */
227 false), /* pcrel_offset */
229 /* A standard 16 bit relocation. */
230 HOWTO (R_PPC_ADDR16
, /* type */
232 1, /* size (0 = byte, 1 = short, 2 = long) */
234 false, /* pc_relative */
236 complain_overflow_bitfield
, /* complain_on_overflow */
237 bfd_elf_generic_reloc
, /* special_function */
238 "R_PPC_ADDR16", /* name */
239 false, /* partial_inplace */
241 0xffff, /* dst_mask */
242 false), /* pcrel_offset */
244 /* A 16 bit relocation without overflow. */
245 HOWTO (R_PPC_ADDR16_LO
, /* type */
247 1, /* size (0 = byte, 1 = short, 2 = long) */
249 false, /* pc_relative */
251 complain_overflow_dont
,/* complain_on_overflow */
252 bfd_elf_generic_reloc
, /* special_function */
253 "R_PPC_ADDR16_LO", /* name */
254 false, /* partial_inplace */
256 0xffff, /* dst_mask */
257 false), /* pcrel_offset */
259 /* The high order 16 bits of an address. */
260 HOWTO (R_PPC_ADDR16_HI
, /* type */
262 1, /* size (0 = byte, 1 = short, 2 = long) */
264 false, /* pc_relative */
266 complain_overflow_dont
, /* complain_on_overflow */
267 bfd_elf_generic_reloc
, /* special_function */
268 "R_PPC_ADDR16_HI", /* name */
269 false, /* partial_inplace */
271 0xffff, /* dst_mask */
272 false), /* pcrel_offset */
274 /* The high order 16 bits of an address, plus 1 if the contents of
275 the low 16 bits, treated as a signed number, is negative. */
276 HOWTO (R_PPC_ADDR16_HA
, /* type */
278 1, /* size (0 = byte, 1 = short, 2 = long) */
280 false, /* pc_relative */
282 complain_overflow_dont
, /* complain_on_overflow */
283 ppc_elf_addr16_ha_reloc
, /* special_function */
284 "R_PPC_ADDR16_HA", /* name */
285 false, /* partial_inplace */
287 0xffff, /* dst_mask */
288 false), /* pcrel_offset */
290 /* An absolute 16 bit branch; the lower two bits must be zero.
291 FIXME: we don't check that, we just clear them. */
292 HOWTO (R_PPC_ADDR14
, /* type */
294 2, /* size (0 = byte, 1 = short, 2 = long) */
296 false, /* pc_relative */
298 complain_overflow_bitfield
, /* complain_on_overflow */
299 bfd_elf_generic_reloc
, /* special_function */
300 "R_PPC_ADDR14", /* name */
301 false, /* partial_inplace */
303 0xfffc, /* dst_mask */
304 false), /* pcrel_offset */
306 /* An absolute 16 bit branch, for which bit 10 should be set to
307 indicate that the branch is expected to be taken. The lower two
308 bits must be zero. */
309 HOWTO (R_PPC_ADDR14_BRTAKEN
, /* type */
311 2, /* size (0 = byte, 1 = short, 2 = long) */
313 false, /* pc_relative */
315 complain_overflow_bitfield
, /* complain_on_overflow */
316 bfd_elf_generic_reloc
, /* special_function */
317 "R_PPC_ADDR14_BRTAKEN",/* name */
318 false, /* partial_inplace */
320 0xfffc, /* dst_mask */
321 false), /* pcrel_offset */
323 /* An absolute 16 bit branch, for which bit 10 should be set to
324 indicate that the branch is not expected to be taken. The lower
325 two bits must be zero. */
326 HOWTO (R_PPC_ADDR14_BRNTAKEN
, /* type */
328 2, /* size (0 = byte, 1 = short, 2 = long) */
330 false, /* pc_relative */
332 complain_overflow_bitfield
, /* complain_on_overflow */
333 bfd_elf_generic_reloc
, /* special_function */
334 "R_PPC_ADDR14_BRNTAKEN",/* name */
335 false, /* partial_inplace */
337 0xfffc, /* dst_mask */
338 false), /* pcrel_offset */
340 /* A relative 26 bit branch; the lower two bits must be zero. */
341 HOWTO (R_PPC_REL24
, /* type */
343 2, /* size (0 = byte, 1 = short, 2 = long) */
345 true, /* pc_relative */
347 complain_overflow_signed
, /* complain_on_overflow */
348 bfd_elf_generic_reloc
, /* special_function */
349 "R_PPC_REL24", /* name */
350 false, /* partial_inplace */
352 0x3fffffc, /* dst_mask */
353 true), /* pcrel_offset */
355 /* A relative 16 bit branch; the lower two bits must be zero. */
356 HOWTO (R_PPC_REL14
, /* type */
358 2, /* size (0 = byte, 1 = short, 2 = long) */
360 true, /* pc_relative */
362 complain_overflow_signed
, /* complain_on_overflow */
363 bfd_elf_generic_reloc
, /* special_function */
364 "R_PPC_REL14", /* name */
365 false, /* partial_inplace */
367 0xfffc, /* dst_mask */
368 true), /* pcrel_offset */
370 /* A relative 16 bit branch. Bit 10 should be set to indicate that
371 the branch is expected to be taken. The lower two bits must be
373 HOWTO (R_PPC_REL14_BRTAKEN
, /* type */
375 2, /* size (0 = byte, 1 = short, 2 = long) */
377 true, /* pc_relative */
379 complain_overflow_signed
, /* complain_on_overflow */
380 bfd_elf_generic_reloc
, /* special_function */
381 "R_PPC_REL14_BRTAKEN", /* name */
382 false, /* partial_inplace */
384 0xfffc, /* dst_mask */
385 true), /* pcrel_offset */
387 /* A relative 16 bit branch. Bit 10 should be set to indicate that
388 the branch is not expected to be taken. The lower two bits must
390 HOWTO (R_PPC_REL14_BRNTAKEN
, /* type */
392 2, /* size (0 = byte, 1 = short, 2 = long) */
394 true, /* pc_relative */
396 complain_overflow_signed
, /* complain_on_overflow */
397 bfd_elf_generic_reloc
, /* special_function */
398 "R_PPC_REL14_BRNTAKEN",/* name */
399 false, /* partial_inplace */
401 0xfffc, /* dst_mask */
402 true), /* pcrel_offset */
404 /* Like R_PPC_ADDR16, but referring to the GOT table entry for the
406 HOWTO (R_PPC_GOT16
, /* type */
408 1, /* size (0 = byte, 1 = short, 2 = long) */
410 false, /* pc_relative */
412 complain_overflow_signed
, /* complain_on_overflow */
413 bfd_elf_generic_reloc
, /* special_function */
414 "R_PPC_GOT16", /* name */
415 false, /* partial_inplace */
417 0xffff, /* dst_mask */
418 false), /* pcrel_offset */
420 /* Like R_PPC_ADDR16_LO, but referring to the GOT table entry for
422 HOWTO (R_PPC_GOT16_LO
, /* type */
424 1, /* size (0 = byte, 1 = short, 2 = long) */
426 false, /* pc_relative */
428 complain_overflow_bitfield
, /* complain_on_overflow */
429 bfd_elf_generic_reloc
, /* special_function */
430 "R_PPC_GOT16_LO", /* name */
431 false, /* partial_inplace */
433 0xffff, /* dst_mask */
434 false), /* pcrel_offset */
436 /* Like R_PPC_ADDR16_HI, but referring to the GOT table entry for
438 HOWTO (R_PPC_GOT16_HI
, /* type */
440 1, /* size (0 = byte, 1 = short, 2 = long) */
442 false, /* pc_relative */
444 complain_overflow_bitfield
, /* complain_on_overflow */
445 bfd_elf_generic_reloc
, /* special_function */
446 "R_PPC_GOT16_HI", /* name */
447 false, /* partial_inplace */
449 0xffff, /* dst_mask */
450 false), /* pcrel_offset */
452 /* Like R_PPC_ADDR16_HA, but referring to the GOT table entry for
454 HOWTO (R_PPC_GOT16_HA
, /* type */
456 1, /* size (0 = byte, 1 = short, 2 = long) */
458 false, /* pc_relative */
460 complain_overflow_bitfield
, /* complain_on_overflow */
461 bfd_elf_generic_reloc
, /* special_function */
462 "R_PPC_GOT16_HA", /* name */
463 false, /* partial_inplace */
465 0xffff, /* dst_mask */
466 false), /* pcrel_offset */
468 /* Like R_PPC_REL24, but referring to the procedure linkage table
469 entry for the symbol. FIXME: Not supported. */
470 HOWTO (R_PPC_PLTREL24
, /* type */
472 2, /* size (0 = byte, 1 = short, 2 = long) */
474 true, /* pc_relative */
476 complain_overflow_signed
, /* complain_on_overflow */
477 bfd_elf_generic_reloc
, /* special_function */
478 "R_PPC_PLTREL24", /* name */
479 false, /* partial_inplace */
481 0x3fffffc, /* dst_mask */
482 true), /* pcrel_offset */
484 /* This is used only by the dynamic linker. The symbol should exist
485 both in the object being run and in some shared library. The
486 dynamic linker copies the data addressed by the symbol from the
487 shared library into the object. I have no idea what the purpose
489 HOWTO (R_PPC_COPY
, /* type */
491 2, /* size (0 = byte, 1 = short, 2 = long) */
493 false, /* pc_relative */
495 complain_overflow_bitfield
, /* complain_on_overflow */
496 bfd_elf_generic_reloc
, /* special_function */
497 "R_PPC_COPY", /* name */
498 false, /* partial_inplace */
501 false), /* pcrel_offset */
503 /* Like R_PPC_ADDR32, but used when setting global offset table
505 HOWTO (R_PPC_GLOB_DAT
, /* type */
507 2, /* size (0 = byte, 1 = short, 2 = long) */
509 false, /* pc_relative */
511 complain_overflow_bitfield
, /* complain_on_overflow */
512 bfd_elf_generic_reloc
, /* special_function */
513 "R_PPC_GLOB_DAT", /* name */
514 false, /* partial_inplace */
516 0xffffffff, /* dst_mask */
517 false), /* pcrel_offset */
519 /* Marks a procedure linkage table entry for a symbol. */
520 HOWTO (R_PPC_JMP_SLOT
, /* type */
522 2, /* size (0 = byte, 1 = short, 2 = long) */
524 false, /* pc_relative */
526 complain_overflow_bitfield
, /* complain_on_overflow */
527 bfd_elf_generic_reloc
, /* special_function */
528 "R_PPC_JMP_SLOT", /* name */
529 false, /* partial_inplace */
532 false), /* pcrel_offset */
534 /* Used only by the dynamic linker. When the object is run, this
535 longword is set to the load address of the object, plus the
537 HOWTO (R_PPC_RELATIVE
, /* type */
539 2, /* size (0 = byte, 1 = short, 2 = long) */
541 false, /* pc_relative */
543 complain_overflow_bitfield
, /* complain_on_overflow */
544 bfd_elf_generic_reloc
, /* special_function */
545 "R_PPC_RELATIVE", /* name */
546 false, /* partial_inplace */
548 0xffffffff, /* dst_mask */
549 false), /* pcrel_offset */
551 /* Like R_PPC_REL24, but uses the value of the symbol within the
552 object rather than the final value. Normally used for
553 _GLOBAL_OFFSET_TABLE_. FIXME: Not supported. */
554 HOWTO (R_PPC_LOCAL24PC
, /* type */
556 2, /* size (0 = byte, 1 = short, 2 = long) */
558 true, /* pc_relative */
560 complain_overflow_signed
, /* complain_on_overflow */
561 bfd_elf_generic_reloc
, /* special_function */
562 "R_PPC_LOCAL24PC", /* name */
563 false, /* partial_inplace */
565 0x3fffffc, /* dst_mask */
566 true), /* pcrel_offset */
568 /* Like R_PPC_ADDR32, but may be unaligned. */
569 HOWTO (R_PPC_UADDR32
, /* type */
571 2, /* size (0 = byte, 1 = short, 2 = long) */
573 false, /* pc_relative */
575 complain_overflow_bitfield
, /* complain_on_overflow */
576 bfd_elf_generic_reloc
, /* special_function */
577 "R_PPC_UADDR32", /* name */
578 false, /* partial_inplace */
580 0xffffffff, /* dst_mask */
581 false), /* pcrel_offset */
583 /* Like R_PPC_ADDR16, but may be unaligned. */
584 HOWTO (R_PPC_UADDR16
, /* type */
586 1, /* size (0 = byte, 1 = short, 2 = long) */
588 false, /* pc_relative */
590 complain_overflow_bitfield
, /* complain_on_overflow */
591 bfd_elf_generic_reloc
, /* special_function */
592 "R_PPC_UADDR16", /* name */
593 false, /* partial_inplace */
595 0xffff, /* dst_mask */
596 false), /* pcrel_offset */
598 /* 32-bit PC relative */
599 HOWTO (R_PPC_REL32
, /* type */
601 2, /* size (0 = byte, 1 = short, 2 = long) */
603 true, /* pc_relative */
605 complain_overflow_bitfield
, /* complain_on_overflow */
606 bfd_elf_generic_reloc
, /* special_function */
607 "R_PPC_REL32", /* name */
608 false, /* partial_inplace */
610 0xffffffff, /* dst_mask */
611 true), /* pcrel_offset */
613 /* 32-bit relocation to the symbol's procedure linkage table.
614 FIXEME: not supported. */
615 HOWTO (R_PPC_PLT32
, /* type */
617 2, /* size (0 = byte, 1 = short, 2 = long) */
619 false, /* pc_relative */
621 complain_overflow_bitfield
, /* complain_on_overflow */
622 bfd_elf_generic_reloc
, /* special_function */
623 "R_PPC_PLT32", /* name */
624 false, /* partial_inplace */
627 false), /* pcrel_offset */
629 /* 32-bit PC relative relocation to the symbol's procedure linkage table.
630 FIXEME: not supported. */
631 HOWTO (R_PPC_PLTREL32
, /* type */
633 2, /* size (0 = byte, 1 = short, 2 = long) */
635 true, /* pc_relative */
637 complain_overflow_bitfield
, /* complain_on_overflow */
638 bfd_elf_generic_reloc
, /* special_function */
639 "R_PPC_PLTREL32", /* name */
640 false, /* partial_inplace */
643 true), /* pcrel_offset */
645 /* Like R_PPC_ADDR16_LO, but referring to the PLT table entry for
647 HOWTO (R_PPC_PLT16_LO
, /* type */
649 1, /* size (0 = byte, 1 = short, 2 = long) */
651 false, /* pc_relative */
653 complain_overflow_bitfield
, /* complain_on_overflow */
654 bfd_elf_generic_reloc
, /* special_function */
655 "R_PPC_PLT16_LO", /* name */
656 false, /* partial_inplace */
658 0xffff, /* dst_mask */
659 false), /* pcrel_offset */
661 /* Like R_PPC_ADDR16_HI, but referring to the PLT table entry for
663 HOWTO (R_PPC_PLT16_HI
, /* type */
665 1, /* size (0 = byte, 1 = short, 2 = long) */
667 false, /* pc_relative */
669 complain_overflow_bitfield
, /* complain_on_overflow */
670 bfd_elf_generic_reloc
, /* special_function */
671 "R_PPC_PLT16_HI", /* name */
672 false, /* partial_inplace */
674 0xffff, /* dst_mask */
675 false), /* pcrel_offset */
677 /* Like R_PPC_ADDR16_HA, but referring to the PLT table entry for
678 the symbol. FIXME: Not supported. */
679 HOWTO (R_PPC_PLT16_HA
, /* type */
681 1, /* size (0 = byte, 1 = short, 2 = long) */
683 false, /* pc_relative */
685 complain_overflow_bitfield
, /* complain_on_overflow */
686 bfd_elf_generic_reloc
, /* special_function */
687 "R_PPC_PLT16_HA", /* name */
688 false, /* partial_inplace */
690 0xffff, /* dst_mask */
691 false), /* pcrel_offset */
693 /* A sign-extended 16 bit value relative to _SDA_BASE_, for use with
695 HOWTO (R_PPC_SDAREL16
, /* type */
697 1, /* size (0 = byte, 1 = short, 2 = long) */
699 false, /* pc_relative */
701 complain_overflow_signed
, /* complain_on_overflow */
702 bfd_elf_generic_reloc
, /* special_function */
703 "R_PPC_SDAREL16", /* name */
704 false, /* partial_inplace */
706 0xffff, /* dst_mask */
707 false), /* pcrel_offset */
709 /* 32-bit section relative relocation. */
710 HOWTO (R_PPC_SECTOFF
, /* type */
712 2, /* size (0 = byte, 1 = short, 2 = long) */
714 true, /* pc_relative */
716 complain_overflow_bitfield
, /* complain_on_overflow */
717 bfd_elf_generic_reloc
, /* special_function */
718 "R_PPC_SECTOFF", /* name */
719 false, /* partial_inplace */
722 true), /* pcrel_offset */
724 /* 16-bit lower half section relative relocation. */
725 HOWTO (R_PPC_SECTOFF_LO
, /* type */
727 1, /* size (0 = byte, 1 = short, 2 = long) */
729 false, /* pc_relative */
731 complain_overflow_bitfield
, /* complain_on_overflow */
732 bfd_elf_generic_reloc
, /* special_function */
733 "R_PPC_SECTOFF_LO", /* name */
734 false, /* partial_inplace */
736 0xffff, /* dst_mask */
737 false), /* pcrel_offset */
739 /* 16-bit upper half section relative relocation. */
740 HOWTO (R_PPC_SECTOFF_HI
, /* type */
742 1, /* size (0 = byte, 1 = short, 2 = long) */
744 false, /* pc_relative */
746 complain_overflow_bitfield
, /* complain_on_overflow */
747 bfd_elf_generic_reloc
, /* special_function */
748 "R_PPC_SECTOFF_HI", /* name */
749 false, /* partial_inplace */
751 0xffff, /* dst_mask */
752 false), /* pcrel_offset */
754 /* 16-bit upper half adjusted section relative relocation. */
755 HOWTO (R_PPC_SECTOFF_HA
, /* type */
757 1, /* size (0 = byte, 1 = short, 2 = long) */
759 false, /* pc_relative */
761 complain_overflow_bitfield
, /* complain_on_overflow */
762 bfd_elf_generic_reloc
, /* special_function */
763 "R_PPC_SECTOFF_HA", /* name */
764 false, /* partial_inplace */
766 0xffff, /* dst_mask */
767 false), /* pcrel_offset */
769 /* The remaining relocs are from the Embedded ELF ABI, and are not
770 in the SVR4 ELF ABI. */
772 /* 32 bit value resulting from the addend minus the symbol */
773 HOWTO (R_PPC_EMB_NADDR32
, /* type */
775 2, /* size (0 = byte, 1 = short, 2 = long) */
777 false, /* pc_relative */
779 complain_overflow_bitfield
, /* complain_on_overflow */
780 bfd_elf_generic_reloc
, /* special_function */
781 "R_PPC_EMB_NADDR32", /* name */
782 false, /* partial_inplace */
784 0xffffffff, /* dst_mask */
785 false), /* pcrel_offset */
787 /* 16 bit value resulting from the addend minus the symbol */
788 HOWTO (R_PPC_EMB_NADDR16
, /* type */
790 1, /* size (0 = byte, 1 = short, 2 = long) */
792 false, /* pc_relative */
794 complain_overflow_bitfield
, /* complain_on_overflow */
795 bfd_elf_generic_reloc
, /* special_function */
796 "R_PPC_EMB_NADDR16", /* name */
797 false, /* partial_inplace */
799 0xffff, /* dst_mask */
800 false), /* pcrel_offset */
802 /* 16 bit value resulting from the addend minus the symbol */
803 HOWTO (R_PPC_EMB_NADDR16_LO
, /* type */
805 1, /* size (0 = byte, 1 = short, 2 = long) */
807 false, /* pc_relative */
809 complain_overflow_dont
,/* complain_on_overflow */
810 bfd_elf_generic_reloc
, /* special_function */
811 "R_PPC_EMB_ADDR16_LO", /* name */
812 false, /* partial_inplace */
814 0xffff, /* dst_mask */
815 false), /* pcrel_offset */
817 /* The high order 16 bits of the addend minus the symbol */
818 HOWTO (R_PPC_EMB_NADDR16_HI
, /* type */
820 1, /* size (0 = byte, 1 = short, 2 = long) */
822 false, /* pc_relative */
824 complain_overflow_dont
, /* complain_on_overflow */
825 bfd_elf_generic_reloc
, /* special_function */
826 "R_PPC_EMB_NADDR16_HI", /* name */
827 false, /* partial_inplace */
829 0xffff, /* dst_mask */
830 false), /* pcrel_offset */
832 /* The high order 16 bits of the result of the addend minus the address,
833 plus 1 if the contents of the low 16 bits, treated as a signed number,
835 HOWTO (R_PPC_EMB_NADDR16_HA
, /* type */
837 1, /* size (0 = byte, 1 = short, 2 = long) */
839 false, /* pc_relative */
841 complain_overflow_dont
, /* complain_on_overflow */
842 bfd_elf_generic_reloc
, /* special_function */
843 "R_PPC_EMB_NADDR16_HA", /* name */
844 false, /* partial_inplace */
846 0xffff, /* dst_mask */
847 false), /* pcrel_offset */
849 /* 16 bit value resulting from allocating a 4 byte word to hold an
850 address in the .sdata section, and returning the offset from
851 _SDA_BASE_ for that relocation */
852 HOWTO (R_PPC_EMB_SDAI16
, /* type */
854 1, /* size (0 = byte, 1 = short, 2 = long) */
856 false, /* pc_relative */
858 complain_overflow_bitfield
, /* complain_on_overflow */
859 bfd_elf_generic_reloc
, /* special_function */
860 "R_PPC_EMB_SDAI16", /* name */
861 false, /* partial_inplace */
863 0xffff, /* dst_mask */
864 false), /* pcrel_offset */
866 /* 16 bit value resulting from allocating a 4 byte word to hold an
867 address in the .sdata2 section, and returning the offset from
868 _SDA2_BASE_ for that relocation */
869 HOWTO (R_PPC_EMB_SDA2I16
, /* type */
871 1, /* size (0 = byte, 1 = short, 2 = long) */
873 false, /* pc_relative */
875 complain_overflow_bitfield
, /* complain_on_overflow */
876 bfd_elf_generic_reloc
, /* special_function */
877 "R_PPC_EMB_SDA2I16", /* name */
878 false, /* partial_inplace */
880 0xffff, /* dst_mask */
881 false), /* pcrel_offset */
883 /* A sign-extended 16 bit value relative to _SDA2_BASE_, for use with
885 HOWTO (R_PPC_EMB_SDA2REL
, /* type */
887 1, /* size (0 = byte, 1 = short, 2 = long) */
889 false, /* pc_relative */
891 complain_overflow_signed
, /* complain_on_overflow */
892 bfd_elf_generic_reloc
, /* special_function */
893 "R_PPC_EMB_SDA2REL", /* name */
894 false, /* partial_inplace */
896 0xffff, /* dst_mask */
897 false), /* pcrel_offset */
899 /* Relocate against either _SDA_BASE_ or _SDA2_BASE_, filling in the 16 bit
900 signed offset from the appropriate base, and filling in the register
901 field with the appropriate register (0, 2, or 13). */
902 HOWTO (R_PPC_EMB_SDA21
, /* type */
904 2, /* size (0 = byte, 1 = short, 2 = long) */
906 false, /* pc_relative */
908 complain_overflow_signed
, /* complain_on_overflow */
909 bfd_elf_generic_reloc
, /* special_function */
910 "R_PPC_EMB_SDA21", /* name */
911 false, /* partial_inplace */
913 0xffff, /* dst_mask */
914 false), /* pcrel_offset */
916 /* Relocation not handled: R_PPC_EMB_MRKREF */
917 /* Relocation not handled: R_PPC_EMB_RELSEC16 */
918 /* Relocation not handled: R_PPC_EMB_RELST_LO */
919 /* Relocation not handled: R_PPC_EMB_RELST_HI */
920 /* Relocation not handled: R_PPC_EMB_RELST_HA */
921 /* Relocation not handled: R_PPC_EMB_BIT_FLD */
923 /* PC relative relocation against either _SDA_BASE_ or _SDA2_BASE_, filling
924 in the 16 bit signed offset from the appropriate base, and filling in the
925 register field with the appropriate register (0, 2, or 13). */
926 HOWTO (R_PPC_EMB_RELSDA
, /* type */
928 1, /* size (0 = byte, 1 = short, 2 = long) */
930 true, /* pc_relative */
932 complain_overflow_signed
, /* complain_on_overflow */
933 bfd_elf_generic_reloc
, /* special_function */
934 "R_PPC_EMB_RELSDA", /* name */
935 false, /* partial_inplace */
937 0xffff, /* dst_mask */
938 false), /* pcrel_offset */
940 /* Phony reloc to handle AIX style TOC entries */
941 HOWTO (R_PPC_TOC16
, /* type */
943 1, /* size (0 = byte, 1 = short, 2 = long) */
945 false, /* pc_relative */
947 complain_overflow_signed
, /* complain_on_overflow */
948 bfd_elf_generic_reloc
, /* special_function */
949 "R_PPC_TOC16", /* name */
950 false, /* partial_inplace */
952 0xffff, /* dst_mask */
953 false), /* pcrel_offset */
957 /* Initialize the ppc_elf_howto_table, so that linear accesses can be done. */
960 ppc_elf_howto_init ()
962 unsigned int i
, type
;
964 for (i
= 0; i
< sizeof (ppc_elf_howto_raw
) / sizeof (ppc_elf_howto_raw
[0]); i
++)
966 type
= ppc_elf_howto_raw
[i
].type
;
967 BFD_ASSERT (type
< sizeof(ppc_elf_howto_table
) / sizeof(ppc_elf_howto_table
[0]));
968 ppc_elf_howto_table
[type
] = &ppc_elf_howto_raw
[i
];
973 static reloc_howto_type
*
974 ppc_elf_reloc_type_lookup (abfd
, code
)
976 bfd_reloc_code_real_type code
;
978 enum ppc_reloc_type ppc_reloc
= R_PPC_NONE
;
980 if (!ppc_elf_howto_table
[ R_PPC_ADDR32
]) /* Initialize howto table if needed */
981 ppc_elf_howto_init ();
986 return (reloc_howto_type
*)NULL
;
988 case BFD_RELOC_NONE
: ppc_reloc
= R_PPC_NONE
; break;
989 case BFD_RELOC_32
: ppc_reloc
= R_PPC_ADDR32
; break;
990 case BFD_RELOC_PPC_BA26
: ppc_reloc
= R_PPC_ADDR24
; break;
991 case BFD_RELOC_16
: ppc_reloc
= R_PPC_ADDR16
; break;
992 case BFD_RELOC_LO16
: ppc_reloc
= R_PPC_ADDR16_LO
; break;
993 case BFD_RELOC_HI16
: ppc_reloc
= R_PPC_ADDR16_HI
; break;
994 case BFD_RELOC_HI16_S
: ppc_reloc
= R_PPC_ADDR16_HA
; break;
995 case BFD_RELOC_PPC_BA16
: ppc_reloc
= R_PPC_ADDR14
; break;
996 case BFD_RELOC_PPC_BA16_BRTAKEN
: ppc_reloc
= R_PPC_ADDR14_BRTAKEN
; break;
997 case BFD_RELOC_PPC_BA16_BRNTAKEN
: ppc_reloc
= R_PPC_ADDR14_BRNTAKEN
; break;
998 case BFD_RELOC_PPC_B26
: ppc_reloc
= R_PPC_REL24
; break;
999 case BFD_RELOC_PPC_B16
: ppc_reloc
= R_PPC_REL14
; break;
1000 case BFD_RELOC_PPC_B16_BRTAKEN
: ppc_reloc
= R_PPC_REL14_BRTAKEN
; break;
1001 case BFD_RELOC_PPC_B16_BRNTAKEN
: ppc_reloc
= R_PPC_REL14_BRNTAKEN
; break;
1002 case BFD_RELOC_16_GOTOFF
: ppc_reloc
= R_PPC_GOT16
; break;
1003 case BFD_RELOC_LO16_GOTOFF
: ppc_reloc
= R_PPC_GOT16_LO
; break;
1004 case BFD_RELOC_HI16_GOTOFF
: ppc_reloc
= R_PPC_GOT16_HI
; break;
1005 case BFD_RELOC_HI16_S_GOTOFF
: ppc_reloc
= R_PPC_GOT16_HA
; break;
1006 case BFD_RELOC_24_PLT_PCREL
: ppc_reloc
= R_PPC_PLTREL24
; break;
1007 case BFD_RELOC_PPC_COPY
: ppc_reloc
= R_PPC_COPY
; break;
1008 case BFD_RELOC_PPC_GLOB_DAT
: ppc_reloc
= R_PPC_GLOB_DAT
; break;
1009 case BFD_RELOC_PPC_LOCAL24PC
: ppc_reloc
= R_PPC_LOCAL24PC
; break;
1010 case BFD_RELOC_32_PCREL
: ppc_reloc
= R_PPC_REL32
; break;
1011 case BFD_RELOC_32_PLTOFF
: ppc_reloc
= R_PPC_PLT32
; break;
1012 case BFD_RELOC_32_PLT_PCREL
: ppc_reloc
= R_PPC_PLTREL32
; break;
1013 case BFD_RELOC_LO16_PLTOFF
: ppc_reloc
= R_PPC_PLT16_LO
; break;
1014 case BFD_RELOC_HI16_PLTOFF
: ppc_reloc
= R_PPC_PLT16_HI
; break;
1015 case BFD_RELOC_HI16_S_PLTOFF
: ppc_reloc
= R_PPC_PLT16_HA
; break;
1016 case BFD_RELOC_GPREL16
: ppc_reloc
= R_PPC_SDAREL16
; break;
1017 case BFD_RELOC_32_BASEREL
: ppc_reloc
= R_PPC_SECTOFF
; break;
1018 case BFD_RELOC_LO16_BASEREL
: ppc_reloc
= R_PPC_SECTOFF_LO
; break;
1019 case BFD_RELOC_HI16_BASEREL
: ppc_reloc
= R_PPC_SECTOFF_HI
; break;
1020 case BFD_RELOC_HI16_S_BASEREL
: ppc_reloc
= R_PPC_SECTOFF_HA
; break;
1021 case BFD_RELOC_CTOR
: ppc_reloc
= R_PPC_ADDR32
; break;
1022 case BFD_RELOC_PPC_TOC16
: ppc_reloc
= R_PPC_TOC16
; break;
1023 case BFD_RELOC_PPC_EMB_NADDR32
: ppc_reloc
= R_PPC_EMB_NADDR32
; break;
1024 case BFD_RELOC_PPC_EMB_NADDR16
: ppc_reloc
= R_PPC_EMB_NADDR16
; break;
1025 case BFD_RELOC_PPC_EMB_NADDR16_LO
: ppc_reloc
= R_PPC_EMB_NADDR16_LO
; break;
1026 case BFD_RELOC_PPC_EMB_NADDR16_HI
: ppc_reloc
= R_PPC_EMB_NADDR16_HI
; break;
1027 case BFD_RELOC_PPC_EMB_NADDR16_HA
: ppc_reloc
= R_PPC_EMB_NADDR16_HA
; break;
1028 case BFD_RELOC_PPC_EMB_SDAI16
: ppc_reloc
= R_PPC_EMB_SDAI16
; break;
1029 case BFD_RELOC_PPC_EMB_SDA2I16
: ppc_reloc
= R_PPC_EMB_SDA2I16
; break;
1030 case BFD_RELOC_PPC_EMB_SDA2REL
: ppc_reloc
= R_PPC_EMB_SDA2REL
; break;
1031 case BFD_RELOC_PPC_EMB_SDA21
: ppc_reloc
= R_PPC_EMB_SDA21
; break;
1032 case BFD_RELOC_PPC_EMB_MRKREF
: ppc_reloc
= R_PPC_EMB_MRKREF
; break;
1033 case BFD_RELOC_PPC_EMB_RELSEC16
: ppc_reloc
= R_PPC_EMB_RELSEC16
; break;
1034 case BFD_RELOC_PPC_EMB_RELST_LO
: ppc_reloc
= R_PPC_EMB_RELST_LO
; break;
1035 case BFD_RELOC_PPC_EMB_RELST_HI
: ppc_reloc
= R_PPC_EMB_RELST_HI
; break;
1036 case BFD_RELOC_PPC_EMB_RELST_HA
: ppc_reloc
= R_PPC_EMB_RELST_HA
; break;
1037 case BFD_RELOC_PPC_EMB_BIT_FLD
: ppc_reloc
= R_PPC_EMB_BIT_FLD
; break;
1038 case BFD_RELOC_PPC_EMB_RELSDA
: ppc_reloc
= R_PPC_EMB_RELSDA
; break;
1041 return ppc_elf_howto_table
[ (int)ppc_reloc
];
1044 /* Set the howto pointer for a PowerPC ELF reloc. */
1047 ppc_elf_info_to_howto (abfd
, cache_ptr
, dst
)
1050 Elf32_Internal_Rela
*dst
;
1052 if (!ppc_elf_howto_table
[ R_PPC_ADDR32
]) /* Initialize howto table if needed */
1053 ppc_elf_howto_init ();
1055 BFD_ASSERT (ELF32_R_TYPE (dst
->r_info
) < (unsigned int) R_PPC_max
);
1056 cache_ptr
->howto
= ppc_elf_howto_table
[ELF32_R_TYPE (dst
->r_info
)];
1059 /* Handle the R_PPC_ADDR16_HA reloc. */
1061 static bfd_reloc_status_type
1062 ppc_elf_addr16_ha_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1063 output_bfd
, error_message
)
1065 arelent
*reloc_entry
;
1068 asection
*input_section
;
1070 char **error_message
;
1074 if (output_bfd
!= NULL
)
1076 reloc_entry
->address
+= input_section
->output_offset
;
1077 return bfd_reloc_ok
;
1080 if (reloc_entry
->address
> input_section
->_cooked_size
)
1081 return bfd_reloc_outofrange
;
1083 if (bfd_is_com_section (symbol
->section
))
1086 relocation
= symbol
->value
;
1088 relocation
+= symbol
->section
->output_section
->vma
;
1089 relocation
+= symbol
->section
->output_offset
;
1090 relocation
+= reloc_entry
->addend
;
1092 reloc_entry
->addend
+= (relocation
& 0x8000) << 1;
1094 return bfd_reloc_continue
;
1097 /* Function to set whether a module needs the -mrelocatable bit set. */
1100 ppc_elf_set_private_flags (abfd
, flags
)
1104 BFD_ASSERT (!elf_flags_init (abfd
)
1105 || elf_elfheader (abfd
)->e_flags
== flags
);
1107 elf_elfheader (abfd
)->e_flags
= flags
;
1108 elf_flags_init (abfd
) = true;
1112 /* Copy backend specific data from one object module to another */
1114 ppc_elf_copy_private_bfd_data (ibfd
, obfd
)
1118 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
1119 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
1122 BFD_ASSERT (!elf_flags_init (obfd
)
1123 || elf_elfheader (obfd
)->e_flags
== elf_elfheader (ibfd
)->e_flags
);
1125 elf_elfheader (obfd
)->e_flags
= elf_elfheader (ibfd
)->e_flags
;
1126 elf_flags_init (obfd
) = true;
1130 /* Merge backend specific data from an object file to the output
1131 object file when linking */
1133 ppc_elf_merge_private_bfd_data (ibfd
, obfd
)
1141 /* Check if we have the same endianess */
1142 if (ibfd
->xvec
->byteorder
!= obfd
->xvec
->byteorder
1143 && obfd
->xvec
->byteorder
!= BFD_ENDIAN_UNKNOWN
)
1145 (*_bfd_error_handler
)
1146 ("%s: compiled for a %s endian system and target is %s endian",
1147 bfd_get_filename (ibfd
),
1148 bfd_big_endian (ibfd
) ? "big" : "little",
1149 bfd_big_endian (obfd
) ? "big" : "little");
1151 bfd_set_error (bfd_error_wrong_format
);
1155 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
1156 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
1159 new_flags
= elf_elfheader (ibfd
)->e_flags
;
1160 old_flags
= elf_elfheader (obfd
)->e_flags
;
1161 if (!elf_flags_init (obfd
)) /* First call, no flags set */
1163 elf_flags_init (obfd
) = true;
1164 elf_elfheader (obfd
)->e_flags
= new_flags
;
1167 else if (new_flags
== old_flags
) /* Compatible flags are ok */
1170 else /* Incompatible flags */
1172 /* Warn about -mrelocatable mismatch. Allow -mrelocatable-lib to be linked
1175 if ((new_flags
& EF_PPC_RELOCATABLE
) != 0
1176 && (old_flags
& (EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
)) == 0)
1179 (*_bfd_error_handler
)
1180 ("%s: compiled with -mrelocatable and linked with modules compiled normally",
1181 bfd_get_filename (ibfd
));
1183 else if ((new_flags
& (EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
)) == 0
1184 && (old_flags
& EF_PPC_RELOCATABLE
) != 0)
1187 (*_bfd_error_handler
)
1188 ("%s: compiled normally and linked with modules compiled with -mrelocatable",
1189 bfd_get_filename (ibfd
));
1191 /* If -mrelocatable-lib is linked with an object without -mrelocatable-lib, turn off
1192 the -mrelocatable-lib, since at least one module isn't relocatable. */
1193 else if ((old_flags
& EF_PPC_RELOCATABLE_LIB
) != 0
1194 && (new_flags
& EF_PPC_RELOCATABLE_LIB
) == 0)
1195 elf_elfheader (obfd
)->e_flags
&= ~EF_PPC_RELOCATABLE_LIB
;
1198 /* Do not warn about eabi vs. V.4 mismatch, just or in the bit if any module uses it */
1199 elf_elfheader (obfd
)->e_flags
|= (new_flags
& EF_PPC_EMB
);
1201 new_flags
&= ~ (EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
| EF_PPC_EMB
);
1202 old_flags
&= ~ (EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
| EF_PPC_EMB
);
1204 /* Warn about any other mismatches */
1205 if (new_flags
!= old_flags
)
1208 (*_bfd_error_handler
)
1209 ("%s: uses different e_flags (0x%lx) fields than previous modules (0x%lx)",
1210 bfd_get_filename (ibfd
), (long)new_flags
, (long)old_flags
);
1215 bfd_set_error (bfd_error_bad_value
);
1224 /* Handle a PowerPC specific section when reading an object file. This
1225 is called when elfcode.h finds a section with an unknown type. */
1228 ppc_elf_section_from_shdr (abfd
, hdr
, name
)
1230 Elf32_Internal_Shdr
*hdr
;
1236 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
))
1239 newsect
= hdr
->bfd_section
;
1240 flags
= bfd_get_section_flags (abfd
, newsect
);
1241 if (hdr
->sh_flags
& SHF_EXCLUDE
)
1242 flags
|= SEC_EXCLUDE
;
1244 if (hdr
->sh_type
== SHT_ORDERED
)
1245 flags
|= SEC_SORT_ENTRIES
;
1247 bfd_set_section_flags (abfd
, newsect
, flags
);
1252 /* Set up any other section flags and such that may be necessary. */
1255 ppc_elf_fake_sections (abfd
, shdr
, asect
)
1257 Elf32_Internal_Shdr
*shdr
;
1260 if ((asect
->flags
& SEC_EXCLUDE
) != 0)
1261 shdr
->sh_flags
|= SHF_EXCLUDE
;
1263 if ((asect
->flags
& SEC_SORT_ENTRIES
) != 0)
1264 shdr
->sh_type
= SHT_ORDERED
;
1270 /* Create a special linker section */
1271 static elf_linker_section_t
*
1272 ppc_elf_create_linker_section (abfd
, info
, which
)
1274 struct bfd_link_info
*info
;
1275 enum elf_linker_section_enum which
;
1277 bfd
*dynobj
= elf_hash_table (info
)->dynobj
;
1278 elf_linker_section_t
*lsect
;
1280 /* Record the first bfd section that needs the special section */
1282 dynobj
= elf_hash_table (info
)->dynobj
= abfd
;
1284 /* If this is the first time, create the section */
1285 lsect
= elf_linker_section (dynobj
, which
);
1288 elf_linker_section_t defaults
;
1289 static elf_linker_section_t zero_section
;
1291 defaults
= zero_section
;
1292 defaults
.which
= which
;
1293 defaults
.hole_written_p
= false;
1294 defaults
.alignment
= 2;
1295 defaults
.flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
1296 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
1301 (*_bfd_error_handler
) ("%s: Unknown special linker type %d",
1302 bfd_get_filename (abfd
),
1305 bfd_set_error (bfd_error_bad_value
);
1306 return (elf_linker_section_t
*)0;
1308 case LINKER_SECTION_GOT
: /* .got section */
1309 defaults
.name
= ".got";
1310 defaults
.rel_name
= ".rela.got";
1311 defaults
.sym_name
= "_GLOBAL_OFFSET_TABLE_";
1312 defaults
.max_hole_offset
= 32764;
1313 defaults
.hole_size
= 16;
1314 defaults
.sym_offset
= 4;
1317 case LINKER_SECTION_PLT
: /* .plt section */
1318 defaults
.name
= ".plt";
1319 defaults
.rel_name
= ".rela.plt";
1320 defaults
.sym_name
= (char *)0;
1321 defaults
.max_hole_offset
= 0;
1322 defaults
.hole_size
= 0;
1323 defaults
.sym_offset
= 0;
1324 defaults
.flags
&= ~SEC_LOAD
;
1327 case LINKER_SECTION_SDATA
: /* .sdata/.sbss section */
1328 defaults
.name
= ".sdata";
1329 defaults
.rel_name
= ".rela.sdata";
1330 defaults
.bss_name
= ".sbss";
1331 defaults
.sym_name
= "_SDA_BASE_";
1332 defaults
.sym_offset
= 32768;
1335 case LINKER_SECTION_SDATA2
: /* .sdata2/.sbss2 section */
1336 defaults
.name
= ".sdata2";
1337 defaults
.rel_name
= ".rela.sdata2";
1338 defaults
.bss_name
= ".sbss2";
1339 defaults
.sym_name
= "_SDA2_BASE_";
1340 defaults
.sym_offset
= 32768;
1341 defaults
.flags
|= SEC_READONLY
;
1345 lsect
= _bfd_elf_create_linker_section (abfd
, info
, which
, &defaults
);
1352 /* If we have a non-zero sized .sbss2 or .PPC.EMB.sbss0 sections, we need to bump up
1353 the number of section headers. */
1356 ppc_elf_additional_program_headers (abfd
)
1364 s
= bfd_get_section_by_name (abfd
, ".interp");
1368 s
= bfd_get_section_by_name (abfd
, ".sbss2");
1369 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0 && s
->_raw_size
> 0)
1372 s
= bfd_get_section_by_name (abfd
, ".PPC.EMB.sbss0");
1373 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0 && s
->_raw_size
> 0)
1379 /* Modify the segment map if needed */
1382 ppc_elf_modify_segment_map (abfd
)
1388 /* Adjust a symbol defined by a dynamic object and referenced by a
1389 regular object. The current definition is in some section of the
1390 dynamic object, but we're not including those sections. We have to
1391 change the definition to something the rest of the link can
1395 ppc_elf_adjust_dynamic_symbol (info
, h
)
1396 struct bfd_link_info
*info
;
1397 struct elf_link_hash_entry
*h
;
1399 bfd
*dynobj
= elf_hash_table (info
)->dynobj
;
1401 unsigned int power_of_two
;
1405 fprintf (stderr
, "ppc_elf_adjust_dynamic_symbol called for %s\n", h
->root
.root
.string
);
1408 /* Make sure we know what is going on here. */
1409 BFD_ASSERT (dynobj
!= NULL
1410 && ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
)
1411 || h
->weakdef
!= NULL
1412 || ((h
->elf_link_hash_flags
1413 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0
1414 && (h
->elf_link_hash_flags
1415 & ELF_LINK_HASH_REF_REGULAR
) != 0
1416 && (h
->elf_link_hash_flags
1417 & ELF_LINK_HASH_DEF_REGULAR
) == 0)));
1420 /* If this is a function, put it in the procedure linkage table. We
1421 will fill in the contents of the procedure linkage table later,
1422 when we know the address of the .got section. */
1423 if (h
->type
== STT_FUNC
1424 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
1427 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) == 0
1428 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_REF_DYNAMIC
) == 0)
1430 /* This case can occur if we saw a PLT32 reloc in an input
1431 file, but the symbol was never referred to by a dynamic
1432 object. In such a case, we don't actually need to build
1433 a procedure linkage table, and we can just do a PC32
1435 BFD_ASSERT ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0);
1439 /* Make sure this symbol is output as a dynamic symbol. */
1440 if (h
->dynindx
== -1)
1442 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
1446 s
= bfd_get_section_by_name (dynobj
, ".plt");
1447 BFD_ASSERT (s
!= NULL
);
1449 /* If this is the first .plt entry, make room for the special
1451 if (s
->_raw_size
== 0)
1452 s
->_raw_size
+= PLT_INITIAL_ENTRY_SIZE
;
1454 /* The PowerPC PLT is actually composed of two parts, the first part
1455 is 2 words (for a load and a jump), and then there is a remaining
1456 word available at the end. */
1457 plt_offset
= (PLT_INITIAL_ENTRY_SIZE
1458 + 8 * ((s
->_raw_size
- PLT_INITIAL_ENTRY_SIZE
) / PLT_ENTRY_SIZE
));
1460 /* If this symbol is not defined in a regular file, and we are
1461 not generating a shared library, then set the symbol to this
1462 location in the .plt. This is required to make function
1463 pointers compare as equal between the normal executable and
1464 the shared library. */
1466 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
1468 h
->root
.u
.def
.section
= s
;
1469 h
->root
.u
.def
.value
= plt_offset
;
1472 h
->plt_offset
= plt_offset
;
1474 /* Make room for this entry. */
1475 s
->_raw_size
+= PLT_ENTRY_SIZE
;
1478 /* We also need to make an entry in the .got.plt section, which
1479 will be placed in the .got section by the linker script. */
1481 s
= bfd_get_section_by_name (dynobj
, ".got.plt");
1482 BFD_ASSERT (s
!= NULL
);
1486 /* We also need to make an entry in the .rela.plt section. */
1488 s
= bfd_get_section_by_name (dynobj
, ".rela.plt");
1489 BFD_ASSERT (s
!= NULL
);
1490 s
->_raw_size
+= sizeof (Elf32_External_Rela
);
1495 /* If this is a weak symbol, and there is a real definition, the
1496 processor independent code will have arranged for us to see the
1497 real definition first, and we can just use the same value. */
1498 if (h
->weakdef
!= NULL
)
1500 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
1501 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
1502 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
1503 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
1507 /* This is a reference to a symbol defined by a dynamic object which
1508 is not a function. */
1510 /* If we are creating a shared library, we must presume that the
1511 only references to the symbol are via the global offset table.
1512 For such cases we need not do anything here; the relocations will
1513 be handled correctly by relocate_section. */
1517 /* We must allocate the symbol in our .dynbss section, which will
1518 become part of the .bss section of the executable. There will be
1519 an entry for this symbol in the .dynsym section. The dynamic
1520 object will contain position independent code, so all references
1521 from the dynamic object to this symbol will go through the global
1522 offset table. The dynamic linker will use the .dynsym entry to
1523 determine the address it must put in the global offset table, so
1524 both the dynamic object and the regular object will refer to the
1525 same memory location for the variable. */
1527 s
= bfd_get_section_by_name (dynobj
, ".dynbss");
1528 BFD_ASSERT (s
!= NULL
);
1530 /* We must generate a R_PPC_COPY reloc to tell the dynamic linker to
1531 copy the initial value out of the dynamic object and into the
1532 runtime process image. We need to remember the offset into the
1533 .rela.bss section we are going to use. */
1534 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
1538 srel
= bfd_get_section_by_name (dynobj
, ".rela.bss");
1539 BFD_ASSERT (srel
!= NULL
);
1540 srel
->_raw_size
+= sizeof (Elf32_External_Rel
);
1541 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_COPY
;
1544 /* We need to figure out the alignment required for this symbol. I
1545 have no idea how ELF linkers handle this. */
1546 power_of_two
= bfd_log2 (h
->size
);
1547 if (power_of_two
> 3)
1550 /* Apply the required alignment. */
1551 s
->_raw_size
= BFD_ALIGN (s
->_raw_size
,
1552 (bfd_size_type
) (1 << power_of_two
));
1553 if (power_of_two
> bfd_get_section_alignment (dynobj
, s
))
1555 if (! bfd_set_section_alignment (dynobj
, s
, power_of_two
))
1559 /* Define the symbol as being at this point in the section. */
1560 h
->root
.u
.def
.section
= s
;
1561 h
->root
.u
.def
.value
= s
->_raw_size
;
1563 /* Increment the section size to make room for the symbol. */
1564 s
->_raw_size
+= h
->size
;
1570 /* Increment the index of a dynamic symbol by a given amount. Called
1571 via elf_link_hash_traverse. */
1574 ppc_elf_adjust_dynindx (h
, cparg
)
1575 struct elf_link_hash_entry
*h
;
1578 int *cp
= (int *) cparg
;
1581 fprintf (stderr
, "ppc_elf_adjust_dynindx called, h->dynindx = %d, *cp = %d\n", h
->dynindx
, *cp
);
1584 if (h
->dynindx
!= -1)
1591 /* Set the sizes of the dynamic sections. */
1594 ppc_elf_size_dynamic_sections (output_bfd
, info
)
1596 struct bfd_link_info
*info
;
1605 fprintf (stderr
, "ppc_elf_size_dynamic_sections called\n");
1608 dynobj
= elf_hash_table (info
)->dynobj
;
1609 BFD_ASSERT (dynobj
!= NULL
);
1611 if (elf_hash_table (info
)->dynamic_sections_created
)
1613 /* Set the contents of the .interp section to the interpreter. */
1616 s
= bfd_get_section_by_name (dynobj
, ".interp");
1617 BFD_ASSERT (s
!= NULL
);
1618 s
->_raw_size
= sizeof ELF_DYNAMIC_INTERPRETER
;
1619 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
1624 /* We may have created entries in the .rela.got, .rela.sdata, and
1625 .rela.sdata2 sections. However, if we are not creating the
1626 dynamic sections, we will not actually use these entries. Reset
1627 the size of .rela.got, et al, which will cause it to get
1628 stripped from the output file below. */
1629 static char *rela_sections
[] = { ".rela.got", ".rela.sdata", ".rela.sdata", (char *)0 };
1632 for (p
= rela_sections
; *p
!= (char *)0; p
++)
1634 s
= bfd_get_section_by_name (dynobj
, *p
);
1640 /* The check_relocs and adjust_dynamic_symbol entry points have
1641 determined the sizes of the various dynamic sections. Allocate
1646 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
1651 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
1654 /* It's OK to base decisions on the section name, because none
1655 of the dynobj section names depend upon the input files. */
1656 name
= bfd_get_section_name (dynobj
, s
);
1660 if (strcmp (name
, ".plt") == 0)
1662 if (s
->_raw_size
== 0)
1664 /* Strip this section if we don't need it; see the
1670 /* Remember whether there is a PLT. */
1674 else if (strncmp (name
, ".rela", 5) == 0)
1676 if (s
->_raw_size
== 0)
1678 /* If we don't need this section, strip it from the
1679 output file. This is mostly to handle .rela.bss and
1680 .rela.plt. We must create both sections in
1681 create_dynamic_sections, because they must be created
1682 before the linker maps input sections to output
1683 sections. The linker does that before
1684 adjust_dynamic_symbol is called, and it is that
1685 function which decides whether anything needs to go
1686 into these sections. */
1693 /* Remember whether there are any reloc sections other
1695 if (strcmp (name
, ".rela.plt") != 0)
1697 const char *outname
;
1701 /* If this relocation section applies to a read only
1702 section, then we probably need a DT_TEXTREL
1703 entry. The entries in the .rel.plt section
1704 really apply to the .got section, which we
1705 created ourselves and so know is not readonly. */
1706 outname
= bfd_get_section_name (output_bfd
,
1708 target
= bfd_get_section_by_name (output_bfd
, outname
+ 4);
1710 && (target
->flags
& SEC_READONLY
) != 0)
1714 /* We use the reloc_count field as a counter if we need
1715 to copy relocs into the output file. */
1719 else if (strcmp (name
, ".got") != 0
1720 && strcmp (name
, ".sdata") != 0
1721 && strcmp (name
, ".sdata2") != 0)
1723 /* It's not one of our sections, so don't allocate space. */
1731 for (spp
= &s
->output_section
->owner
->sections
;
1732 *spp
!= s
->output_section
;
1733 spp
= &(*spp
)->next
)
1735 *spp
= s
->output_section
->next
;
1736 --s
->output_section
->owner
->section_count
;
1741 /* Allocate memory for the section contents. */
1742 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->_raw_size
);
1743 if (s
->contents
== NULL
&& s
->_raw_size
!= 0)
1747 if (elf_hash_table (info
)->dynamic_sections_created
)
1749 /* Add some entries to the .dynamic section. We fill in the
1750 values later, in ppc_elf_finish_dynamic_sections, but we
1751 must add the entries now so that we get the correct size for
1752 the .dynamic section. The DT_DEBUG entry is filled in by the
1753 dynamic linker and used by the debugger. */
1756 if (! bfd_elf32_add_dynamic_entry (info
, DT_DEBUG
, 0))
1762 if (! bfd_elf32_add_dynamic_entry (info
, DT_PLTGOT
, 0)
1763 || ! bfd_elf32_add_dynamic_entry (info
, DT_PLTRELSZ
, 0)
1764 || ! bfd_elf32_add_dynamic_entry (info
, DT_PLTREL
, DT_REL
)
1765 || ! bfd_elf32_add_dynamic_entry (info
, DT_JMPREL
, 0))
1771 if (! bfd_elf32_add_dynamic_entry (info
, DT_RELA
, 0)
1772 || ! bfd_elf32_add_dynamic_entry (info
, DT_RELASZ
, DT_RELA
)
1773 || ! bfd_elf32_add_dynamic_entry (info
, DT_RELENT
,
1774 sizeof (Elf32_External_Rela
)))
1780 if (! bfd_elf32_add_dynamic_entry (info
, DT_TEXTREL
, 0))
1785 /* If we are generating a shared library, we generate a section
1786 symbol for each output section. These are local symbols, which
1787 means that they must come first in the dynamic symbol table.
1788 That means we must increment the dynamic symbol index of every
1789 other dynamic symbol. */
1794 c
= bfd_count_sections (output_bfd
);
1795 elf_link_hash_traverse (elf_hash_table (info
),
1796 ppc_elf_adjust_dynindx
,
1798 elf_hash_table (info
)->dynsymcount
+= c
;
1800 for (i
= 1, s
= output_bfd
->sections
; s
!= NULL
; s
= s
->next
, i
++)
1802 elf_section_data (s
)->dynindx
= i
;
1803 /* These symbols will have no names, so we don't need to
1804 fiddle with dynstr_index. */
1812 /* Look through the relocs for a section during the first phase, and
1813 allocate space in the global offset table or procedure linkage
1817 ppc_elf_check_relocs (abfd
, info
, sec
, relocs
)
1819 struct bfd_link_info
*info
;
1821 const Elf_Internal_Rela
*relocs
;
1825 Elf_Internal_Shdr
*symtab_hdr
;
1826 struct elf_link_hash_entry
**sym_hashes
;
1827 const Elf_Internal_Rela
*rel
;
1828 const Elf_Internal_Rela
*rel_end
;
1829 bfd_vma
*local_got_offsets
;
1830 elf_linker_section_t
*got
;
1831 elf_linker_section_t
*sdata
;
1832 elf_linker_section_t
*sdata2
;
1835 if (info
->relocateable
)
1839 fprintf (stderr
, "ppc_elf_check_relocs called for section %s in %s\n",
1840 bfd_get_section_name (abfd
, sec
),
1841 bfd_get_filename (abfd
));
1844 /* Create the linker generated sections all the time so that the
1845 special symbols are created. The .got section is an exception,
1846 so that we don't waste space allocating it when it is not needed. */
1849 if ((plt
= elf_linker_section (abfd
, LINKER_SECTION_PLT
)) == NULL
)
1851 plt
= ppc_elf_create_linker_section (abfd
, info
, LINKER_SECTION_PLT
);
1857 if ((sdata
= elf_linker_section (abfd
, LINKER_SECTION_SDATA
)) == NULL
)
1859 sdata
= ppc_elf_create_linker_section (abfd
, info
, LINKER_SECTION_SDATA
);
1865 if ((sdata2
= elf_linker_section (abfd
, LINKER_SECTION_SDATA2
)) == NULL
)
1867 sdata2
= ppc_elf_create_linker_section (abfd
, info
, LINKER_SECTION_SDATA2
);
1872 if ((got
= elf_linker_section (abfd
, LINKER_SECTION_GOT
)) == NULL
)
1874 got
= ppc_elf_create_linker_section (abfd
, info
, LINKER_SECTION_GOT
);
1879 dynobj
= elf_hash_table (info
)->dynobj
;
1880 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
1881 sym_hashes
= elf_sym_hashes (abfd
);
1882 local_got_offsets
= elf_local_got_offsets (abfd
);
1886 rel_end
= relocs
+ sec
->reloc_count
;
1887 for (rel
= relocs
; rel
< rel_end
; rel
++)
1889 unsigned long r_symndx
;
1890 struct elf_link_hash_entry
*h
;
1892 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1893 if (r_symndx
< symtab_hdr
->sh_info
)
1896 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1898 switch (ELF32_R_TYPE (rel
->r_info
))
1900 /* GOT16 relocations */
1902 case R_PPC_GOT16_LO
:
1903 case R_PPC_GOT16_HI
:
1904 case R_PPC_GOT16_HA
:
1905 if (got
->rel_section
== NULL
1906 && (h
!= NULL
|| info
->shared
)
1907 && !_bfd_elf_make_linker_section_rela (dynobj
, got
, 2))
1913 if (!bfd_elf32_create_pointer_linker_section (abfd
, info
, got
, h
, rel
))
1918 /* Indirect .sdata relocation */
1919 case R_PPC_EMB_SDAI16
:
1922 (*_bfd_error_handler
) ("%s: relocation %s cannot be used when making a shared object",
1923 bfd_get_filename (abfd
),
1924 "R_PPC_EMB_SDAI16");
1930 && (got
= elf_linker_section (abfd
, LINKER_SECTION_GOT
)) == NULL
)
1932 got
= ppc_elf_create_linker_section (abfd
, info
,
1933 LINKER_SECTION_GOT
);
1941 if (got
->rel_section
== NULL
1942 && (h
!= NULL
|| info
->shared
)
1943 && !_bfd_elf_make_linker_section_rela (dynobj
, got
, 2))
1949 if (!bfd_elf32_create_pointer_linker_section (abfd
, info
, sdata
, h
, rel
))
1954 /* Indirect .sdata2 relocation */
1955 case R_PPC_EMB_SDA2I16
:
1958 (*_bfd_error_handler
) ("%s: relocation %s cannot be used when making a shared object",
1959 bfd_get_filename (abfd
),
1960 "R_PPC_EMB_SDA2I16");
1966 && (got
= elf_linker_section (abfd
, LINKER_SECTION_GOT
)) == NULL
)
1968 got
= ppc_elf_create_linker_section (abfd
, info
,
1969 LINKER_SECTION_GOT
);
1977 if (got
->rel_section
== NULL
1978 && (h
!= NULL
|| info
->shared
)
1979 && !_bfd_elf_make_linker_section_rela (dynobj
, got
, 2))
1982 if (!bfd_elf32_create_pointer_linker_section (abfd
, info
, sdata2
, h
, rel
))
1987 case R_PPC_SDAREL16
:
1988 case R_PPC_EMB_SDA2REL
:
1989 case R_PPC_EMB_SDA21
:
1992 (*_bfd_error_handler
) ("%s: relocation %s cannot be used when making a shared object",
1993 bfd_get_filename (abfd
),
1994 ppc_elf_howto_table
[(int)ELF32_R_TYPE (rel
->r_info
)]->name
);
2000 case R_PPC_PLTREL24
:
2001 case R_PPC_PLT16_LO
:
2002 case R_PPC_PLT16_HI
:
2003 case R_PPC_PLT16_HA
:
2005 fprintf (stderr
, "Reloc requires a PLT entry\n");
2007 /* This symbol requires a procedure linkage table entry. We
2008 actually build the entry in adjust_dynamic_symbol,
2009 because this might be a case of linking PIC code without
2010 linking in any dynamic objects, in which case we don't
2011 need to generate a procedure linkage table after all. */
2015 /* It does not make sense to have a procedure linkage
2016 table entry for a local symbol. */
2017 bfd_set_error (bfd_error_bad_value
);
2022 /* Make sure this symbol is output as a dynamic symbol. */
2023 if (h
->dynindx
== -1)
2025 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
2032 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
2035 /* the following relocations don't need to propigate the relocation if
2036 linking a shared object since they are section relative. */
2038 case R_PPC_SECTOFF_LO
:
2039 case R_PPC_SECTOFF_HI
:
2040 case R_PPC_SECTOFF_HA
:
2043 /* This refers only to functions defined in the shared library */
2044 case R_PPC_LOCAL24PC
:
2047 /* When creating a shared object, we must copy these
2048 relocs into the output file. We create a reloc
2049 section in dynobj and make room for the reloc. */
2052 && strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
2057 case R_PPC_REL14_BRTAKEN
:
2058 case R_PPC_REL14_BRNTAKEN
:
2065 && (sec
->flags
& SEC_ALLOC
) != 0)
2068 fprintf (stderr
, "ppc_elf_check_relocs need to create relocation for %s\n",
2069 (h
&& h
->root
.root
.string
) ? h
->root
.root
.string
: "<unknown>");
2075 name
= (bfd_elf_string_from_elf_section
2077 elf_elfheader (abfd
)->e_shstrndx
,
2078 elf_section_data (sec
)->rel_hdr
.sh_name
));
2085 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
2086 && strcmp (bfd_get_section_name (abfd
, sec
),
2089 sreloc
= bfd_get_section_by_name (dynobj
, name
);
2092 sreloc
= bfd_make_section (dynobj
, name
);
2094 || ! bfd_set_section_flags (dynobj
, sreloc
,
2099 | SEC_LINKER_CREATED
2101 || ! bfd_set_section_alignment (dynobj
, sreloc
, 2))
2109 sreloc
->_raw_size
+= sizeof (Elf32_External_Rela
);
2120 /* Hook called by the linker routine which adds symbols from an object
2121 file. We use it to put .comm items in .sbss, and not .bss. */
2125 ppc_elf_add_symbol_hook (abfd
, info
, sym
, namep
, flagsp
, secp
, valp
)
2127 struct bfd_link_info
*info
;
2128 const Elf_Internal_Sym
*sym
;
2134 if (sym
->st_shndx
== SHN_COMMON
&& !info
->relocateable
&& sym
->st_size
<= bfd_get_gp_size (abfd
))
2136 /* Common symbols less than or equal to -G nn bytes are automatically
2138 elf_linker_section_t
*sdata
= ppc_elf_create_linker_section (abfd
, info
, LINKER_SECTION_SDATA
);
2139 if (!sdata
->bss_section
)
2141 /* We don't go through bfd_make_section, because we don't
2142 want to attach this common section to DYNOBJ. The linker
2143 will move the symbols to the appropriate output section
2144 when it defines common symbols. */
2145 sdata
->bss_section
= ((asection
*)
2146 bfd_zalloc (abfd
, sizeof (asection
)));
2147 if (sdata
->bss_section
== NULL
)
2149 sdata
->bss_section
->name
= sdata
->bss_name
;
2150 sdata
->bss_section
->flags
= SEC_IS_COMMON
;
2151 sdata
->bss_section
->output_section
= sdata
->bss_section
;
2152 sdata
->bss_section
->symbol
=
2153 (asymbol
*) bfd_zalloc (abfd
, sizeof (asymbol
));
2154 sdata
->bss_section
->symbol_ptr_ptr
=
2155 (asymbol
**) bfd_zalloc (abfd
, sizeof (asymbol
*));
2156 if (sdata
->bss_section
->symbol
== NULL
2157 || sdata
->bss_section
->symbol_ptr_ptr
== NULL
)
2159 sdata
->bss_section
->symbol
->name
= sdata
->bss_name
;
2160 sdata
->bss_section
->symbol
->flags
= BSF_SECTION_SYM
;
2161 sdata
->bss_section
->symbol
->section
= sdata
->bss_section
;
2162 *sdata
->bss_section
->symbol_ptr_ptr
= sdata
->bss_section
->symbol
;
2165 *secp
= sdata
->bss_section
;
2166 *valp
= sym
->st_size
;
2173 /* Finish up dynamic symbol handling. We set the contents of various
2174 dynamic sections here. */
2177 ppc_elf_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
2179 struct bfd_link_info
*info
;
2180 struct elf_link_hash_entry
*h
;
2181 Elf_Internal_Sym
*sym
;
2186 fprintf (stderr
, "ppc_elf_finish_dynamic_symbol called for %s", h
->root
.root
.string
);
2189 dynobj
= elf_hash_table (info
)->dynobj
;
2190 BFD_ASSERT (dynobj
!= NULL
);
2192 if (h
->plt_offset
!= (bfd_vma
) -1)
2196 Elf_Internal_Rela rela
;
2199 fprintf (stderr
, ", plt_offset = %d", h
->plt_offset
);
2202 /* This symbol has an entry in the procedure linkage table. Set
2205 BFD_ASSERT (h
->dynindx
!= -1);
2207 splt
= bfd_get_section_by_name (dynobj
, ".plt");
2208 srela
= bfd_get_section_by_name (dynobj
, ".rela.plt");
2209 BFD_ASSERT (splt
!= NULL
&& srela
!= NULL
);
2211 /* We don't need to fill in the .plt. The solaris dynamic linker will
2214 /* Fill in the entry in the .rela.plt section. */
2215 rela
.r_offset
= (splt
->output_section
->vma
2216 + splt
->output_offset
2218 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_PPC_JMP_SLOT
);
2220 bfd_elf32_swap_reloca_out (output_bfd
, &rela
,
2221 ((Elf32_External_Rela
*) srela
->contents
2222 + ((h
->plt_offset
- PLT_INITIAL_ENTRY_SIZE
) / 8)));
2224 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
2226 /* Mark the symbol as undefined, rather than as defined in
2227 the .plt section. Leave the value alone. */
2228 sym
->st_shndx
= SHN_UNDEF
;
2232 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_COPY
) != 0)
2235 Elf_Internal_Rela rela
;
2237 /* This symbols needs a copy reloc. Set it up. */
2240 fprintf (stderr
, ", copy");
2243 BFD_ASSERT (h
->dynindx
!= -1);
2245 s
= bfd_get_section_by_name (h
->root
.u
.def
.section
->owner
,
2247 BFD_ASSERT (s
!= NULL
);
2249 rela
.r_offset
= (h
->root
.u
.def
.value
2250 + h
->root
.u
.def
.section
->output_section
->vma
2251 + h
->root
.u
.def
.section
->output_offset
);
2252 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_PPC_COPY
);
2254 bfd_elf32_swap_reloca_out (output_bfd
, &rela
,
2255 ((Elf32_External_Rela
*) s
->contents
2261 fprintf (stderr
, "\n");
2264 /* Mark some specially defined symbols as absolute. */
2265 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
2266 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0
2267 || strcmp (h
->root
.root
.string
, "_PROCEDURE_LINKAGE_TABLE_") == 0)
2268 sym
->st_shndx
= SHN_ABS
;
2274 /* Finish up the dynamic sections. */
2277 ppc_elf_finish_dynamic_sections (output_bfd
, info
)
2279 struct bfd_link_info
*info
;
2282 bfd
*dynobj
= elf_hash_table (info
)->dynobj
;
2283 elf_linker_section_t
*got
= elf_linker_section (dynobj
, LINKER_SECTION_GOT
);
2286 fprintf (stderr
, "ppc_elf_finish_dynamic_sections called\n");
2289 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
2291 if (elf_hash_table (info
)->dynamic_sections_created
)
2294 Elf32_External_Dyn
*dyncon
, *dynconend
;
2296 splt
= bfd_get_section_by_name (dynobj
, ".plt");
2297 BFD_ASSERT (splt
!= NULL
&& sdyn
!= NULL
);
2299 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
2300 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
2301 for (; dyncon
< dynconend
; dyncon
++)
2303 Elf_Internal_Dyn dyn
;
2307 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
2311 case DT_PLTGOT
: name
= ".plt"; size
= false; break;
2312 case DT_PLTRELSZ
: name
= ".rela.plt"; size
= true; break;
2313 case DT_JMPREL
: name
= ".rela.plt"; size
= false; break;
2314 default: name
= NULL
; size
= false; break;
2321 s
= bfd_get_section_by_name (output_bfd
, name
);
2327 dyn
.d_un
.d_ptr
= s
->vma
;
2330 if (s
->_cooked_size
!= 0)
2331 dyn
.d_un
.d_val
= s
->_cooked_size
;
2333 dyn
.d_un
.d_val
= s
->_raw_size
;
2336 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
2341 /* Add a blrl instruction at _GLOBAL_OFFSET_TABLE_-4 so that a function can
2342 easily find the address of the _GLOBAL_OFFSET_TABLE_. */
2345 unsigned char *contents
= got
->section
->contents
+ got
->hole_offset
;
2346 bfd_put_32 (output_bfd
, 0x4e800021 /* blrl */, contents
);
2349 bfd_put_32 (output_bfd
, (bfd_vma
) 0, contents
+4);
2351 bfd_put_32 (output_bfd
,
2352 sdyn
->output_section
->vma
+ sdyn
->output_offset
,
2355 elf_section_data (got
->section
->output_section
)->this_hdr
.sh_entsize
= 4;
2362 Elf_Internal_Sym sym
;
2364 /* Set up the section symbols for the output sections. */
2366 sdynsym
= bfd_get_section_by_name (dynobj
, ".dynsym");
2367 BFD_ASSERT (sdynsym
!= NULL
);
2371 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_SECTION
);
2374 for (s
= output_bfd
->sections
; s
!= NULL
; s
= s
->next
)
2378 sym
.st_value
= s
->vma
;
2380 indx
= elf_section_data (s
)->this_idx
;
2381 BFD_ASSERT (indx
> 0);
2382 sym
.st_shndx
= indx
;
2384 bfd_elf32_swap_symbol_out (output_bfd
, &sym
,
2385 (PTR
) (((Elf32_External_Sym
*)
2387 + elf_section_data (s
)->dynindx
));
2390 /* Set the sh_info field of the output .dynsym section to the
2391 index of the first global symbol. */
2392 elf_section_data (sdynsym
->output_section
)->this_hdr
.sh_info
=
2393 bfd_count_sections (output_bfd
) + 1;
2400 /* The RELOCATE_SECTION function is called by the ELF backend linker
2401 to handle the relocations for a section.
2403 The relocs are always passed as Rela structures; if the section
2404 actually uses Rel structures, the r_addend field will always be
2407 This function is responsible for adjust the section contents as
2408 necessary, and (if using Rela relocs and generating a
2409 relocateable output file) adjusting the reloc addend as
2412 This function does not have to worry about setting the reloc
2413 address or the reloc symbol index.
2415 LOCAL_SYMS is a pointer to the swapped in local symbols.
2417 LOCAL_SECTIONS is an array giving the section in the input file
2418 corresponding to the st_shndx field of each local symbol.
2420 The global hash table entry for the global symbols can be found
2421 via elf_sym_hashes (input_bfd).
2423 When generating relocateable output, this function must handle
2424 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
2425 going to be the section symbol corresponding to the output
2426 section, which means that the addend must be adjusted
2430 ppc_elf_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
2431 contents
, relocs
, local_syms
, local_sections
)
2433 struct bfd_link_info
*info
;
2435 asection
*input_section
;
2437 Elf_Internal_Rela
*relocs
;
2438 Elf_Internal_Sym
*local_syms
;
2439 asection
**local_sections
;
2441 Elf_Internal_Shdr
*symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
2442 struct elf_link_hash_entry
**sym_hashes
= elf_sym_hashes (input_bfd
);
2443 bfd
*dynobj
= elf_hash_table (info
)->dynobj
;
2444 elf_linker_section_t
*got
= (dynobj
) ? elf_linker_section (dynobj
, LINKER_SECTION_GOT
) : NULL
;
2445 elf_linker_section_t
*sdata
= (dynobj
) ? elf_linker_section (dynobj
, LINKER_SECTION_SDATA
) : NULL
;
2446 elf_linker_section_t
*sdata2
= (dynobj
) ? elf_linker_section (dynobj
, LINKER_SECTION_SDATA2
) : NULL
;
2447 Elf_Internal_Rela
*rel
= relocs
;
2448 Elf_Internal_Rela
*relend
= relocs
+ input_section
->reloc_count
;
2449 asection
*sreloc
= NULL
;
2454 fprintf (stderr
, "ppc_elf_relocate_section called for %s section %s, %ld relocations%s\n",
2455 bfd_get_filename (input_bfd
),
2456 bfd_section_name(input_bfd
, input_section
),
2457 (long)input_section
->reloc_count
,
2458 (info
->relocateable
) ? " (relocatable)" : "");
2461 if (!ppc_elf_howto_table
[ R_PPC_ADDR32
]) /* Initialize howto table if needed */
2462 ppc_elf_howto_init ();
2464 for (; rel
< relend
; rel
++)
2466 enum ppc_reloc_type r_type
= (enum ppc_reloc_type
)ELF32_R_TYPE (rel
->r_info
);
2467 bfd_vma offset
= rel
->r_offset
;
2468 bfd_vma addend
= rel
->r_addend
;
2469 bfd_reloc_status_type r
= bfd_reloc_other
;
2470 Elf_Internal_Sym
*sym
= (Elf_Internal_Sym
*)0;
2471 asection
*sec
= (asection
*)0;
2472 struct elf_link_hash_entry
*h
= (struct elf_link_hash_entry
*)0;
2473 const char *sym_name
= (const char *)0;
2474 reloc_howto_type
*howto
;
2475 unsigned long r_symndx
;
2478 /* Unknown relocation handling */
2479 if ((unsigned)r_type
>= (unsigned)R_PPC_max
|| !ppc_elf_howto_table
[(int)r_type
])
2481 (*_bfd_error_handler
) ("%s: unknown relocation type %d",
2482 bfd_get_filename (input_bfd
),
2485 bfd_set_error (bfd_error_bad_value
);
2490 howto
= ppc_elf_howto_table
[(int)r_type
];
2491 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2493 if (info
->relocateable
)
2495 /* This is a relocateable link. We don't have to change
2496 anything, unless the reloc is against a section symbol,
2497 in which case we have to adjust according to where the
2498 section symbol winds up in the output section. */
2499 if (r_symndx
< symtab_hdr
->sh_info
)
2501 sym
= local_syms
+ r_symndx
;
2502 if ((unsigned)ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
2504 sec
= local_sections
[r_symndx
];
2505 addend
= rel
->r_addend
+= sec
->output_offset
+ sym
->st_value
;
2510 fprintf (stderr
, "\ttype = %s (%d), symbol index = %ld, offset = %ld, addend = %ld\n",
2520 /* This is a final link. */
2521 if (r_symndx
< symtab_hdr
->sh_info
)
2523 sym
= local_syms
+ r_symndx
;
2524 sec
= local_sections
[r_symndx
];
2525 sym_name
= "<local symbol>";
2527 relocation
= (sec
->output_section
->vma
2528 + sec
->output_offset
2533 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2534 while (h
->root
.type
== bfd_link_hash_indirect
2535 || h
->root
.type
== bfd_link_hash_warning
)
2536 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2537 sym_name
= h
->root
.root
.string
;
2538 if (h
->root
.type
== bfd_link_hash_defined
2539 || h
->root
.type
== bfd_link_hash_defweak
)
2541 sec
= h
->root
.u
.def
.section
;
2542 if ((r_type
== R_PPC_PLT32
2543 && h
->plt_offset
!= (bfd_vma
) -1)
2544 || ((r_type
== R_PPC_GOT16
2545 || r_type
== R_PPC_GOT16_LO
2546 || r_type
== R_PPC_GOT16_HI
2547 || r_type
== R_PPC_GOT16_HA
)
2548 && elf_hash_table (info
)->dynamic_sections_created
2551 || (h
->elf_link_hash_flags
2552 & ELF_LINK_HASH_DEF_REGULAR
) == 0))
2554 && (! info
->symbolic
2555 || (h
->elf_link_hash_flags
2556 & ELF_LINK_HASH_DEF_REGULAR
) == 0)
2557 && (input_section
->flags
& SEC_ALLOC
) != 0
2558 && (r_type
== R_PPC_ADDR32
2559 || r_type
== R_PPC_ADDR24
2560 || r_type
== R_PPC_ADDR16
2561 || r_type
== R_PPC_ADDR16_LO
2562 || r_type
== R_PPC_ADDR16_HI
2563 || r_type
== R_PPC_ADDR16_HA
2564 || r_type
== R_PPC_ADDR14
2565 || r_type
== R_PPC_ADDR14_BRTAKEN
2566 || r_type
== R_PPC_ADDR14_BRNTAKEN
2567 || r_type
== R_PPC_PLTREL24
2568 || r_type
== R_PPC_COPY
2569 || r_type
== R_PPC_GLOB_DAT
2570 || r_type
== R_PPC_JMP_SLOT
2571 || r_type
== R_PPC_UADDR32
2572 || r_type
== R_PPC_UADDR16
2573 || r_type
== R_PPC_REL32
2574 || r_type
== R_PPC_SDAREL16
2575 || r_type
== R_PPC_EMB_NADDR32
2576 || r_type
== R_PPC_EMB_NADDR16
2577 || r_type
== R_PPC_EMB_NADDR16_LO
2578 || r_type
== R_PPC_EMB_NADDR16_HI
2579 || r_type
== R_PPC_EMB_NADDR16_HA
2580 || r_type
== R_PPC_EMB_SDAI16
2581 || r_type
== R_PPC_EMB_SDA2I16
2582 || r_type
== R_PPC_EMB_SDA2REL
2583 || r_type
== R_PPC_EMB_SDA21
2584 || r_type
== R_PPC_EMB_MRKREF
2585 || r_type
== R_PPC_EMB_BIT_FLD
2586 || r_type
== R_PPC_EMB_RELSDA
2587 || ((r_type
== R_PPC_REL24
2588 || r_type
== R_PPC_REL14
2589 || r_type
== R_PPC_REL14_BRTAKEN
2590 || r_type
== R_PPC_REL14_BRNTAKEN
2591 || r_type
== R_PPC_RELATIVE
)
2592 && strcmp (h
->root
.root
.string
,
2593 "_GLOBAL_OFFSET_TABLE_") != 0))))
2595 /* In these cases, we don't need the relocation
2596 value. We check specially because in some
2597 obscure cases sec->output_section will be NULL. */
2601 relocation
= (h
->root
.u
.def
.value
2602 + sec
->output_section
->vma
2603 + sec
->output_offset
);
2605 else if (h
->root
.type
== bfd_link_hash_undefweak
)
2607 else if (info
->shared
)
2611 (*info
->callbacks
->undefined_symbol
)(info
,
2612 h
->root
.root
.string
,
2621 switch ((int)r_type
)
2624 (*_bfd_error_handler
) ("%s: unknown relocation type %d for symbol %s",
2625 bfd_get_filename (input_bfd
),
2626 (int)r_type
, sym_name
);
2628 bfd_set_error (bfd_error_bad_value
);
2632 /* relocations that need no special processing */
2633 case (int)R_PPC_LOCAL24PC
:
2636 case (int)R_PPC_REL24
:
2637 case (int)R_PPC_REL14
:
2639 && strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
2643 /* Relocations that need to be propigated if this is a shared object */
2644 case (int)R_PPC_NONE
:
2645 case (int)R_PPC_ADDR32
:
2646 case (int)R_PPC_ADDR24
:
2647 case (int)R_PPC_ADDR16
:
2648 case (int)R_PPC_ADDR16_LO
:
2649 case (int)R_PPC_ADDR16_HI
:
2650 case (int)R_PPC_ADDR14
:
2651 case (int)R_PPC_UADDR32
:
2652 case (int)R_PPC_UADDR16
:
2653 case (int)R_PPC_REL32
:
2654 case (int)R_PPC_PLTREL24
:
2656 && (input_section
->flags
& SEC_ALLOC
) != 0)
2658 Elf_Internal_Rela outrel
;
2662 fprintf (stderr
, "ppc_elf_relocate_section need to create relocation for %s\n",
2663 (h
&& h
->root
.root
.string
) ? h
->root
.root
.string
: "<unknown>");
2666 /* When generating a shared object, these relocations
2667 are copied into the output file to be resolved at run
2674 name
= (bfd_elf_string_from_elf_section
2676 elf_elfheader (input_bfd
)->e_shstrndx
,
2677 elf_section_data (input_section
)->rel_hdr
.sh_name
));
2681 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
2682 && strcmp (bfd_get_section_name (input_bfd
,
2686 sreloc
= bfd_get_section_by_name (dynobj
, name
);
2687 BFD_ASSERT (sreloc
!= NULL
);
2692 if (elf_section_data (input_section
)->stab_info
== NULL
)
2693 outrel
.r_offset
= rel
->r_offset
;
2698 off
= (_bfd_stab_section_offset
2699 (output_bfd
, &elf_hash_table (info
)->stab_info
,
2701 &elf_section_data (input_section
)->stab_info
,
2703 if (off
== (bfd_vma
) -1)
2705 outrel
.r_offset
= off
;
2708 outrel
.r_offset
+= (input_section
->output_section
->vma
2709 + input_section
->output_offset
);
2712 memset (&outrel
, 0, sizeof outrel
);
2713 /* h->dynindx may be -1 if this symbol was marked to
2716 && ((! info
->symbolic
&& h
->dynindx
!= -1)
2717 || (h
->elf_link_hash_flags
2718 & ELF_LINK_HASH_DEF_REGULAR
) == 0))
2720 BFD_ASSERT (h
->dynindx
!= -1);
2721 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
2722 outrel
.r_addend
= rel
->r_addend
;
2726 if (r_type
== R_PPC_ADDR32
)
2728 outrel
.r_info
= ELF32_R_INFO (0, R_PPC_RELATIVE
);
2729 outrel
.r_addend
= relocation
+ rel
->r_addend
;
2736 sec
= local_sections
[r_symndx
];
2739 BFD_ASSERT (h
->root
.type
== bfd_link_hash_defined
2741 == bfd_link_hash_defweak
));
2742 sec
= h
->root
.u
.def
.section
;
2744 if (sec
!= NULL
&& bfd_is_abs_section (sec
))
2746 else if (sec
== NULL
|| sec
->owner
== NULL
)
2748 bfd_set_error (bfd_error_bad_value
);
2755 osec
= sec
->output_section
;
2756 indx
= elf_section_data (osec
)->dynindx
;
2761 outrel
.r_info
= ELF32_R_INFO (indx
, r_type
);
2762 outrel
.r_addend
= relocation
+ rel
->r_addend
;
2766 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
,
2767 (((Elf32_External_Rela
*)
2769 + sreloc
->reloc_count
));
2770 ++sreloc
->reloc_count
;
2772 /* This reloc will be computed at runtime, so there's no
2773 need to do anything now. */
2778 /* branch taken prediction relocations */
2779 case (int)R_PPC_ADDR14_BRTAKEN
:
2780 case (int)R_PPC_REL14_BRTAKEN
:
2781 insn
= bfd_get_32 (output_bfd
, contents
+ offset
);
2782 if ((relocation
- offset
) & 0x8000)
2783 insn
&= ~BRANCH_PREDICT_BIT
;
2785 insn
|= BRANCH_PREDICT_BIT
;
2786 bfd_put_32 (output_bfd
, insn
, contents
+ offset
);
2789 /* branch not taken predicition relocations */
2790 case (int)R_PPC_ADDR14_BRNTAKEN
:
2791 case (int)R_PPC_REL14_BRNTAKEN
:
2792 insn
= bfd_get_32 (output_bfd
, contents
+ offset
);
2793 if ((relocation
- offset
) & 0x8000)
2794 insn
|= BRANCH_PREDICT_BIT
;
2796 insn
&= ~BRANCH_PREDICT_BIT
;
2797 bfd_put_32 (output_bfd
, insn
, contents
+ offset
);
2800 /* GOT16 relocations */
2801 case (int)R_PPC_GOT16
:
2802 case (int)R_PPC_GOT16_LO
:
2803 case (int)R_PPC_GOT16_HI
:
2804 case (int)R_PPC_GOT16_HA
:
2805 relocation
= bfd_elf32_finish_pointer_linker_section (output_bfd
, input_bfd
, info
,
2806 got
, h
, relocation
, rel
,
2810 /* Indirect .sdata relocation */
2811 case (int)R_PPC_EMB_SDAI16
:
2812 BFD_ASSERT (sdata
!= NULL
);
2813 relocation
= bfd_elf32_finish_pointer_linker_section (output_bfd
, input_bfd
, info
,
2814 sdata
, h
, relocation
, rel
,
2818 /* Indirect .sdata2 relocation */
2819 case (int)R_PPC_EMB_SDA2I16
:
2820 BFD_ASSERT (sdata2
!= NULL
);
2821 relocation
= bfd_elf32_finish_pointer_linker_section (output_bfd
, input_bfd
, info
,
2822 sdata2
, h
, relocation
, rel
,
2826 /* Handle the TOC16 reloc. We want to use the offset within the .got
2827 section, not the actual VMA. This is appropriate when generating
2828 an embedded ELF object, for which the .got section acts like the
2829 AIX .toc section. */
2830 case (int)R_PPC_TOC16
: /* phony GOT16 relocations */
2831 BFD_ASSERT (sec
!= (asection
*)0);
2832 BFD_ASSERT (bfd_is_und_section (sec
)
2833 || strcmp (bfd_get_section_name (abfd
, sec
), ".got") == 0
2834 || strcmp (bfd_get_section_name (abfd
, sec
), ".cgot") == 0)
2836 addend
-= sec
->output_section
->vma
+ sec
->output_offset
+ 0x8000;
2839 /* arithmetic adjust relocations */
2840 case (int)R_PPC_ADDR16_HA
:
2841 BFD_ASSERT (sec
!= (asection
*)0);
2842 addend
+= ((relocation
+ addend
) & 0x8000) << 1;
2845 /* relocate against _SDA_BASE_ */
2846 case (int)R_PPC_SDAREL16
:
2847 BFD_ASSERT (sec
!= (asection
*)0);
2848 if (strcmp (bfd_get_section_name (abfd
, sec
), ".sdata") != 0
2849 && strcmp (bfd_get_section_name (abfd
, sec
), ".sbss") != 0)
2851 (*_bfd_error_handler
) ("%s: The target (%s) of a %s relocation is in the wrong section (%s)",
2852 bfd_get_filename (input_bfd
),
2854 ppc_elf_howto_table
[ (int)r_type
]->name
,
2855 bfd_get_section_name (abfd
, sec
));
2857 bfd_set_error (bfd_error_bad_value
);
2861 addend
-= (sdata
->sym_hash
->root
.u
.def
.value
2862 + sdata
->sym_hash
->root
.u
.def
.section
->output_section
->vma
2863 + sdata
->sym_hash
->root
.u
.def
.section
->output_offset
);
2867 /* relocate against _SDA2_BASE_ */
2868 case (int)R_PPC_EMB_SDA2REL
:
2869 BFD_ASSERT (sec
!= (asection
*)0);
2870 if (strcmp (bfd_get_section_name (abfd
, sec
), ".sdata2") != 0
2871 && strcmp (bfd_get_section_name (abfd
, sec
), ".sbss2") != 0)
2873 (*_bfd_error_handler
) ("%s: The target (%s) of a %s relocation is in the wrong section (%s)",
2874 bfd_get_filename (input_bfd
),
2876 ppc_elf_howto_table
[ (int)r_type
]->name
,
2877 bfd_get_section_name (abfd
, sec
));
2879 bfd_set_error (bfd_error_bad_value
);
2883 addend
-= (sdata2
->sym_hash
->root
.u
.def
.value
2884 + sdata2
->sym_hash
->root
.u
.def
.section
->output_section
->vma
2885 + sdata2
->sym_hash
->root
.u
.def
.section
->output_offset
);
2889 /* relocate against either _SDA_BASE_, _SDA2_BASE_, or 0 */
2890 case (int)R_PPC_EMB_SDA21
:
2891 case (int)R_PPC_EMB_RELSDA
:
2893 const char *name
= bfd_get_section_name (abfd
, sec
);
2896 BFD_ASSERT (sec
!= (asection
*)0);
2897 if (strcmp (name
, ".sdata") == 0 || strcmp (name
, ".sbss") == 0)
2900 addend
-= (sdata
->sym_hash
->root
.u
.def
.value
2901 + sdata
->sym_hash
->root
.u
.def
.section
->output_section
->vma
2902 + sdata
->sym_hash
->root
.u
.def
.section
->output_offset
);
2905 else if (strcmp (name
, ".sdata2") == 0 || strcmp (name
, ".sbss2") == 0)
2908 addend
-= (sdata2
->sym_hash
->root
.u
.def
.value
2909 + sdata2
->sym_hash
->root
.u
.def
.section
->output_section
->vma
2910 + sdata2
->sym_hash
->root
.u
.def
.section
->output_offset
);
2913 else if (strcmp (name
, ".PPC.EMB.sdata0") == 0 || strcmp (name
, ".PPC.EMB.sbss0") == 0)
2920 (*_bfd_error_handler
) ("%s: The target (%s) of a %s relocation is in the wrong section (%s)",
2921 bfd_get_filename (input_bfd
),
2923 ppc_elf_howto_table
[ (int)r_type
]->name
,
2924 bfd_get_section_name (abfd
, sec
));
2926 bfd_set_error (bfd_error_bad_value
);
2931 if (r_type
== R_PPC_EMB_SDA21
)
2932 { /* fill in register field */
2933 insn
= bfd_get_32 (output_bfd
, contents
+ offset
);
2934 insn
= (insn
& ~RA_REGISTER_MASK
) | (reg
<< RA_REGISTER_SHIFT
);
2935 bfd_put_32 (output_bfd
, insn
, contents
+ offset
);
2940 /* Relocate against the beginning of the section */
2941 case (int)R_PPC_SECTOFF
:
2942 case (int)R_PPC_SECTOFF_LO
:
2943 case (int)R_PPC_SECTOFF_HI
:
2944 BFD_ASSERT (sec
!= (asection
*)0);
2945 addend
-= sec
->output_section
->vma
;
2948 case (int)R_PPC_SECTOFF_HA
:
2949 BFD_ASSERT (sec
!= (asection
*)0);
2950 addend
-= sec
->output_section
->vma
;
2951 addend
+= ((relocation
+ addend
) & 0x8000) << 1;
2954 /* Negative relocations */
2955 case (int)R_PPC_EMB_NADDR32
:
2956 case (int)R_PPC_EMB_NADDR16
:
2957 case (int)R_PPC_EMB_NADDR16_LO
:
2958 case (int)R_PPC_EMB_NADDR16_HI
:
2959 addend
-= 2*relocation
;
2962 case (int)R_PPC_EMB_NADDR16_HA
:
2963 addend
-= 2*relocation
;
2964 addend
+= ((relocation
+ addend
) & 0x8000) << 1;
2967 /* NOP relocation that prevents garbage collecting linkers from omitting a
2969 case (int)R_PPC_EMB_MRKREF
:
2972 case (int)R_PPC_COPY
:
2973 case (int)R_PPC_GLOB_DAT
:
2974 case (int)R_PPC_JMP_SLOT
:
2975 case (int)R_PPC_RELATIVE
:
2976 case (int)R_PPC_PLT32
:
2977 case (int)R_PPC_PLTREL32
:
2978 case (int)R_PPC_PLT16_LO
:
2979 case (int)R_PPC_PLT16_HI
:
2980 case (int)R_PPC_PLT16_HA
:
2981 case (int)R_PPC_EMB_RELSEC16
:
2982 case (int)R_PPC_EMB_RELST_LO
:
2983 case (int)R_PPC_EMB_RELST_HI
:
2984 case (int)R_PPC_EMB_RELST_HA
:
2985 case (int)R_PPC_EMB_BIT_FLD
:
2986 (*_bfd_error_handler
) ("%s: Relocation %s is not yet supported for symbol %s.",
2987 bfd_get_filename (input_bfd
),
2988 ppc_elf_howto_table
[ (int)r_type
]->name
,
2991 bfd_set_error (bfd_error_invalid_operation
);
2998 fprintf (stderr
, "\ttype = %s (%d), name = %s, symbol index = %ld, offset = %ld, addend = %ld\n",
3007 r
= _bfd_final_link_relocate (howto
,
3015 if (r
!= bfd_reloc_ok
)
3023 case bfd_reloc_overflow
:
3028 name
= h
->root
.root
.string
;
3031 name
= bfd_elf_string_from_elf_section (input_bfd
,
3032 symtab_hdr
->sh_link
,
3038 name
= bfd_section_name (input_bfd
, sec
);
3041 (*info
->callbacks
->reloc_overflow
)(info
,
3057 fprintf (stderr
, "\n");
3064 #define TARGET_LITTLE_SYM bfd_elf32_powerpcle_vec
3065 #define TARGET_LITTLE_NAME "elf32-powerpcle"
3066 #define TARGET_BIG_SYM bfd_elf32_powerpc_vec
3067 #define TARGET_BIG_NAME "elf32-powerpc"
3068 #define ELF_ARCH bfd_arch_powerpc
3069 #define ELF_MACHINE_CODE EM_PPC
3070 #define ELF_MAXPAGESIZE 0x10000
3071 #define elf_info_to_howto ppc_elf_info_to_howto
3073 #ifdef EM_CYGNUS_POWERPC
3074 #define ELF_MACHINE_ALT1 EM_CYGNUS_POWERPC
3078 #define ELF_MACHINE_ALT2 EM_PPC_OLD
3081 #define bfd_elf32_bfd_copy_private_bfd_data ppc_elf_copy_private_bfd_data
3082 #define bfd_elf32_bfd_merge_private_bfd_data ppc_elf_merge_private_bfd_data
3083 #define bfd_elf32_bfd_set_private_flags ppc_elf_set_private_flags
3084 #define bfd_elf32_bfd_reloc_type_lookup ppc_elf_reloc_type_lookup
3085 #define elf_backend_section_from_shdr ppc_elf_section_from_shdr
3086 #define elf_backend_relocate_section ppc_elf_relocate_section
3087 #define elf_backend_create_dynamic_sections _bfd_elf_create_dynamic_sections
3088 #define elf_backend_check_relocs ppc_elf_check_relocs
3089 #define elf_backend_adjust_dynamic_symbol ppc_elf_adjust_dynamic_symbol
3090 #define elf_backend_add_symbol_hook ppc_elf_add_symbol_hook
3091 #define elf_backend_size_dynamic_sections ppc_elf_size_dynamic_sections
3092 #define elf_backend_finish_dynamic_symbol ppc_elf_finish_dynamic_symbol
3093 #define elf_backend_finish_dynamic_sections ppc_elf_finish_dynamic_sections
3094 #define elf_backend_fake_sections ppc_elf_fake_sections
3095 #define elf_backend_additional_program_headers ppc_elf_additional_program_headers
3096 #define elf_backend_modify_segment_map ppc_elf_modify_segment_map
3098 #include "elf32-target.h"