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
*,
120 static elf_linker_section_t
*ppc_elf_create_linker_section
122 struct bfd_link_info
*info
,
123 enum elf_linker_section_enum
));
125 static boolean ppc_elf_check_relocs
PARAMS ((bfd
*,
126 struct bfd_link_info
*,
128 const Elf_Internal_Rela
*));
130 static boolean ppc_elf_adjust_dynamic_symbol
PARAMS ((struct bfd_link_info
*,
131 struct elf_link_hash_entry
*));
133 static boolean ppc_elf_adjust_dynindx
PARAMS ((struct elf_link_hash_entry
*, PTR
));
135 static boolean ppc_elf_size_dynamic_sections
PARAMS ((bfd
*, struct bfd_link_info
*));
137 static boolean ppc_elf_relocate_section
PARAMS ((bfd
*,
138 struct bfd_link_info
*info
,
142 Elf_Internal_Rela
*relocs
,
143 Elf_Internal_Sym
*local_syms
,
146 static boolean ppc_elf_add_symbol_hook
PARAMS ((bfd
*,
147 struct bfd_link_info
*,
148 const Elf_Internal_Sym
*,
154 static boolean ppc_elf_finish_dynamic_symbol
PARAMS ((bfd
*,
155 struct bfd_link_info
*,
156 struct elf_link_hash_entry
*,
157 Elf_Internal_Sym
*));
159 static boolean ppc_elf_finish_dynamic_sections
PARAMS ((bfd
*, struct bfd_link_info
*));
161 #define BRANCH_PREDICT_BIT 0x200000 /* branch prediction bit for branch taken relocs */
162 #define RA_REGISTER_MASK 0x001f0000 /* mask to set RA in memory instructions */
163 #define RA_REGISTER_SHIFT 16 /* value to shift register by to insert RA */
165 /* The name of the dynamic interpreter. This is put in the .interp
168 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
170 /* The size in bytes of an entry in the procedure linkage table, and of the initial size
171 of the plt reserved for the dynamic linker. */
173 #define PLT_ENTRY_SIZE 12
174 #define PLT_INITIAL_ENTRY_SIZE 72
177 static reloc_howto_type
*ppc_elf_howto_table
[ (int)R_PPC_max
];
179 static reloc_howto_type ppc_elf_howto_raw
[] =
181 /* This reloc does nothing. */
182 HOWTO (R_PPC_NONE
, /* type */
184 2, /* size (0 = byte, 1 = short, 2 = long) */
186 false, /* pc_relative */
188 complain_overflow_bitfield
, /* complain_on_overflow */
189 bfd_elf_generic_reloc
, /* special_function */
190 "R_PPC_NONE", /* name */
191 false, /* partial_inplace */
194 false), /* pcrel_offset */
196 /* A standard 32 bit relocation. */
197 HOWTO (R_PPC_ADDR32
, /* type */
199 2, /* size (0 = byte, 1 = short, 2 = long) */
201 false, /* pc_relative */
203 complain_overflow_bitfield
, /* complain_on_overflow */
204 bfd_elf_generic_reloc
, /* special_function */
205 "R_PPC_ADDR32", /* name */
206 false, /* partial_inplace */
208 0xffffffff, /* dst_mask */
209 false), /* pcrel_offset */
211 /* An absolute 26 bit branch; the lower two bits must be zero.
212 FIXME: we don't check that, we just clear them. */
213 HOWTO (R_PPC_ADDR24
, /* type */
215 2, /* size (0 = byte, 1 = short, 2 = long) */
217 false, /* pc_relative */
219 complain_overflow_bitfield
, /* complain_on_overflow */
220 bfd_elf_generic_reloc
, /* special_function */
221 "R_PPC_ADDR24", /* name */
222 false, /* partial_inplace */
224 0x3fffffc, /* dst_mask */
225 false), /* pcrel_offset */
227 /* A standard 16 bit relocation. */
228 HOWTO (R_PPC_ADDR16
, /* type */
230 1, /* size (0 = byte, 1 = short, 2 = long) */
232 false, /* pc_relative */
234 complain_overflow_bitfield
, /* complain_on_overflow */
235 bfd_elf_generic_reloc
, /* special_function */
236 "R_PPC_ADDR16", /* name */
237 false, /* partial_inplace */
239 0xffff, /* dst_mask */
240 false), /* pcrel_offset */
242 /* A 16 bit relocation without overflow. */
243 HOWTO (R_PPC_ADDR16_LO
, /* type */
245 1, /* size (0 = byte, 1 = short, 2 = long) */
247 false, /* pc_relative */
249 complain_overflow_dont
,/* complain_on_overflow */
250 bfd_elf_generic_reloc
, /* special_function */
251 "R_PPC_ADDR16_LO", /* name */
252 false, /* partial_inplace */
254 0xffff, /* dst_mask */
255 false), /* pcrel_offset */
257 /* The high order 16 bits of an address. */
258 HOWTO (R_PPC_ADDR16_HI
, /* type */
260 1, /* size (0 = byte, 1 = short, 2 = long) */
262 false, /* pc_relative */
264 complain_overflow_dont
, /* complain_on_overflow */
265 bfd_elf_generic_reloc
, /* special_function */
266 "R_PPC_ADDR16_HI", /* name */
267 false, /* partial_inplace */
269 0xffff, /* dst_mask */
270 false), /* pcrel_offset */
272 /* The high order 16 bits of an address, plus 1 if the contents of
273 the low 16 bits, treated as a signed number, is negative. */
274 HOWTO (R_PPC_ADDR16_HA
, /* type */
276 1, /* size (0 = byte, 1 = short, 2 = long) */
278 false, /* pc_relative */
280 complain_overflow_dont
, /* complain_on_overflow */
281 ppc_elf_addr16_ha_reloc
, /* special_function */
282 "R_PPC_ADDR16_HA", /* name */
283 false, /* partial_inplace */
285 0xffff, /* dst_mask */
286 false), /* pcrel_offset */
288 /* An absolute 16 bit branch; the lower two bits must be zero.
289 FIXME: we don't check that, we just clear them. */
290 HOWTO (R_PPC_ADDR14
, /* type */
292 2, /* size (0 = byte, 1 = short, 2 = long) */
294 false, /* pc_relative */
296 complain_overflow_bitfield
, /* complain_on_overflow */
297 bfd_elf_generic_reloc
, /* special_function */
298 "R_PPC_ADDR14", /* name */
299 false, /* partial_inplace */
301 0xfffc, /* dst_mask */
302 false), /* pcrel_offset */
304 /* An absolute 16 bit branch, for which bit 10 should be set to
305 indicate that the branch is expected to be taken. The lower two
306 bits must be zero. */
307 HOWTO (R_PPC_ADDR14_BRTAKEN
, /* type */
309 2, /* size (0 = byte, 1 = short, 2 = long) */
311 false, /* pc_relative */
313 complain_overflow_bitfield
, /* complain_on_overflow */
314 bfd_elf_generic_reloc
, /* special_function */
315 "R_PPC_ADDR14_BRTAKEN",/* name */
316 false, /* partial_inplace */
318 0xfffc, /* dst_mask */
319 false), /* pcrel_offset */
321 /* An absolute 16 bit branch, for which bit 10 should be set to
322 indicate that the branch is not expected to be taken. The lower
323 two bits must be zero. */
324 HOWTO (R_PPC_ADDR14_BRNTAKEN
, /* type */
326 2, /* size (0 = byte, 1 = short, 2 = long) */
328 false, /* pc_relative */
330 complain_overflow_bitfield
, /* complain_on_overflow */
331 bfd_elf_generic_reloc
, /* special_function */
332 "R_PPC_ADDR14_BRNTAKEN",/* name */
333 false, /* partial_inplace */
335 0xfffc, /* dst_mask */
336 false), /* pcrel_offset */
338 /* A relative 26 bit branch; the lower two bits must be zero. */
339 HOWTO (R_PPC_REL24
, /* type */
341 2, /* size (0 = byte, 1 = short, 2 = long) */
343 true, /* pc_relative */
345 complain_overflow_signed
, /* complain_on_overflow */
346 bfd_elf_generic_reloc
, /* special_function */
347 "R_PPC_REL24", /* name */
348 false, /* partial_inplace */
350 0x3fffffc, /* dst_mask */
351 true), /* pcrel_offset */
353 /* A relative 16 bit branch; the lower two bits must be zero. */
354 HOWTO (R_PPC_REL14
, /* type */
356 2, /* size (0 = byte, 1 = short, 2 = long) */
358 true, /* pc_relative */
360 complain_overflow_signed
, /* complain_on_overflow */
361 bfd_elf_generic_reloc
, /* special_function */
362 "R_PPC_REL14", /* name */
363 false, /* partial_inplace */
365 0xfffc, /* dst_mask */
366 true), /* pcrel_offset */
368 /* A relative 16 bit branch. Bit 10 should be set to indicate that
369 the branch is expected to be taken. The lower two bits must be
371 HOWTO (R_PPC_REL14_BRTAKEN
, /* type */
373 2, /* size (0 = byte, 1 = short, 2 = long) */
375 true, /* pc_relative */
377 complain_overflow_signed
, /* complain_on_overflow */
378 bfd_elf_generic_reloc
, /* special_function */
379 "R_PPC_REL14_BRTAKEN", /* name */
380 false, /* partial_inplace */
382 0xfffc, /* dst_mask */
383 true), /* pcrel_offset */
385 /* A relative 16 bit branch. Bit 10 should be set to indicate that
386 the branch is not expected to be taken. The lower two bits must
388 HOWTO (R_PPC_REL14_BRNTAKEN
, /* type */
390 2, /* size (0 = byte, 1 = short, 2 = long) */
392 true, /* pc_relative */
394 complain_overflow_signed
, /* complain_on_overflow */
395 bfd_elf_generic_reloc
, /* special_function */
396 "R_PPC_REL14_BRNTAKEN",/* name */
397 false, /* partial_inplace */
399 0xfffc, /* dst_mask */
400 true), /* pcrel_offset */
402 /* Like R_PPC_ADDR16, but referring to the GOT table entry for the
404 HOWTO (R_PPC_GOT16
, /* type */
406 1, /* size (0 = byte, 1 = short, 2 = long) */
408 false, /* pc_relative */
410 complain_overflow_signed
, /* complain_on_overflow */
411 bfd_elf_generic_reloc
, /* special_function */
412 "R_PPC_GOT16", /* name */
413 false, /* partial_inplace */
415 0xffff, /* dst_mask */
416 false), /* pcrel_offset */
418 /* Like R_PPC_ADDR16_LO, but referring to the GOT table entry for
420 HOWTO (R_PPC_GOT16_LO
, /* type */
422 1, /* size (0 = byte, 1 = short, 2 = long) */
424 false, /* pc_relative */
426 complain_overflow_bitfield
, /* complain_on_overflow */
427 bfd_elf_generic_reloc
, /* special_function */
428 "R_PPC_GOT16_LO", /* name */
429 false, /* partial_inplace */
431 0xffff, /* dst_mask */
432 false), /* pcrel_offset */
434 /* Like R_PPC_ADDR16_HI, but referring to the GOT table entry for
436 HOWTO (R_PPC_GOT16_HI
, /* type */
438 1, /* size (0 = byte, 1 = short, 2 = long) */
440 false, /* pc_relative */
442 complain_overflow_bitfield
, /* complain_on_overflow */
443 bfd_elf_generic_reloc
, /* special_function */
444 "R_PPC_GOT16_HI", /* name */
445 false, /* partial_inplace */
447 0xffff, /* dst_mask */
448 false), /* pcrel_offset */
450 /* Like R_PPC_ADDR16_HA, but referring to the GOT table entry for
452 HOWTO (R_PPC_GOT16_HA
, /* type */
454 1, /* size (0 = byte, 1 = short, 2 = long) */
456 false, /* pc_relative */
458 complain_overflow_bitfield
, /* complain_on_overflow */
459 bfd_elf_generic_reloc
, /* special_function */
460 "R_PPC_GOT16_HA", /* name */
461 false, /* partial_inplace */
463 0xffff, /* dst_mask */
464 false), /* pcrel_offset */
466 /* Like R_PPC_REL24, but referring to the procedure linkage table
467 entry for the symbol. FIXME: Not supported. */
468 HOWTO (R_PPC_PLTREL24
, /* type */
470 2, /* size (0 = byte, 1 = short, 2 = long) */
472 true, /* pc_relative */
474 complain_overflow_signed
, /* complain_on_overflow */
475 bfd_elf_generic_reloc
, /* special_function */
476 "R_PPC_PLTREL24", /* name */
477 false, /* partial_inplace */
479 0x3fffffc, /* dst_mask */
480 true), /* pcrel_offset */
482 /* This is used only by the dynamic linker. The symbol should exist
483 both in the object being run and in some shared library. The
484 dynamic linker copies the data addressed by the symbol from the
485 shared library into the object. I have no idea what the purpose
487 HOWTO (R_PPC_COPY
, /* type */
489 2, /* size (0 = byte, 1 = short, 2 = long) */
491 false, /* pc_relative */
493 complain_overflow_bitfield
, /* complain_on_overflow */
494 bfd_elf_generic_reloc
, /* special_function */
495 "R_PPC_COPY", /* name */
496 false, /* partial_inplace */
499 false), /* pcrel_offset */
501 /* Like R_PPC_ADDR32, but used when setting global offset table
503 HOWTO (R_PPC_GLOB_DAT
, /* type */
505 2, /* size (0 = byte, 1 = short, 2 = long) */
507 false, /* pc_relative */
509 complain_overflow_bitfield
, /* complain_on_overflow */
510 bfd_elf_generic_reloc
, /* special_function */
511 "R_PPC_GLOB_DAT", /* name */
512 false, /* partial_inplace */
514 0xffffffff, /* dst_mask */
515 false), /* pcrel_offset */
517 /* Marks a procedure linkage table entry for a symbol. */
518 HOWTO (R_PPC_JMP_SLOT
, /* type */
520 2, /* size (0 = byte, 1 = short, 2 = long) */
522 false, /* pc_relative */
524 complain_overflow_bitfield
, /* complain_on_overflow */
525 bfd_elf_generic_reloc
, /* special_function */
526 "R_PPC_JMP_SLOT", /* name */
527 false, /* partial_inplace */
530 false), /* pcrel_offset */
532 /* Used only by the dynamic linker. When the object is run, this
533 longword is set to the load address of the object, plus the
535 HOWTO (R_PPC_RELATIVE
, /* type */
537 2, /* size (0 = byte, 1 = short, 2 = long) */
539 false, /* pc_relative */
541 complain_overflow_bitfield
, /* complain_on_overflow */
542 bfd_elf_generic_reloc
, /* special_function */
543 "R_PPC_RELATIVE", /* name */
544 false, /* partial_inplace */
546 0xffffffff, /* dst_mask */
547 false), /* pcrel_offset */
549 /* Like R_PPC_REL24, but uses the value of the symbol within the
550 object rather than the final value. Normally used for
551 _GLOBAL_OFFSET_TABLE_. FIXME: Not supported. */
552 HOWTO (R_PPC_LOCAL24PC
, /* type */
554 2, /* size (0 = byte, 1 = short, 2 = long) */
556 true, /* pc_relative */
558 complain_overflow_signed
, /* complain_on_overflow */
559 bfd_elf_generic_reloc
, /* special_function */
560 "R_PPC_LOCAL24PC", /* name */
561 false, /* partial_inplace */
563 0x3fffffc, /* dst_mask */
564 true), /* pcrel_offset */
566 /* Like R_PPC_ADDR32, but may be unaligned. */
567 HOWTO (R_PPC_UADDR32
, /* type */
569 2, /* size (0 = byte, 1 = short, 2 = long) */
571 false, /* pc_relative */
573 complain_overflow_bitfield
, /* complain_on_overflow */
574 bfd_elf_generic_reloc
, /* special_function */
575 "R_PPC_UADDR32", /* name */
576 false, /* partial_inplace */
578 0xffffffff, /* dst_mask */
579 false), /* pcrel_offset */
581 /* Like R_PPC_ADDR16, but may be unaligned. */
582 HOWTO (R_PPC_UADDR16
, /* type */
584 1, /* size (0 = byte, 1 = short, 2 = long) */
586 false, /* pc_relative */
588 complain_overflow_bitfield
, /* complain_on_overflow */
589 bfd_elf_generic_reloc
, /* special_function */
590 "R_PPC_UADDR16", /* name */
591 false, /* partial_inplace */
593 0xffff, /* dst_mask */
594 false), /* pcrel_offset */
596 /* 32-bit PC relative */
597 HOWTO (R_PPC_REL32
, /* type */
599 2, /* size (0 = byte, 1 = short, 2 = long) */
601 true, /* pc_relative */
603 complain_overflow_bitfield
, /* complain_on_overflow */
604 bfd_elf_generic_reloc
, /* special_function */
605 "R_PPC_REL32", /* name */
606 false, /* partial_inplace */
608 0xffffffff, /* dst_mask */
609 true), /* pcrel_offset */
611 /* 32-bit relocation to the symbol's procedure linkage table.
612 FIXEME: not supported. */
613 HOWTO (R_PPC_PLT32
, /* type */
615 2, /* size (0 = byte, 1 = short, 2 = long) */
617 false, /* pc_relative */
619 complain_overflow_bitfield
, /* complain_on_overflow */
620 bfd_elf_generic_reloc
, /* special_function */
621 "R_PPC_PLT32", /* name */
622 false, /* partial_inplace */
625 false), /* pcrel_offset */
627 /* 32-bit PC relative relocation to the symbol's procedure linkage table.
628 FIXEME: not supported. */
629 HOWTO (R_PPC_PLTREL32
, /* type */
631 2, /* size (0 = byte, 1 = short, 2 = long) */
633 true, /* pc_relative */
635 complain_overflow_bitfield
, /* complain_on_overflow */
636 bfd_elf_generic_reloc
, /* special_function */
637 "R_PPC_PLTREL32", /* name */
638 false, /* partial_inplace */
641 true), /* pcrel_offset */
643 /* Like R_PPC_ADDR16_LO, but referring to the PLT table entry for
645 HOWTO (R_PPC_PLT16_LO
, /* type */
647 1, /* size (0 = byte, 1 = short, 2 = long) */
649 false, /* pc_relative */
651 complain_overflow_bitfield
, /* complain_on_overflow */
652 bfd_elf_generic_reloc
, /* special_function */
653 "R_PPC_PLT16_LO", /* name */
654 false, /* partial_inplace */
656 0xffff, /* dst_mask */
657 false), /* pcrel_offset */
659 /* Like R_PPC_ADDR16_HI, but referring to the PLT table entry for
661 HOWTO (R_PPC_PLT16_HI
, /* type */
663 1, /* size (0 = byte, 1 = short, 2 = long) */
665 false, /* pc_relative */
667 complain_overflow_bitfield
, /* complain_on_overflow */
668 bfd_elf_generic_reloc
, /* special_function */
669 "R_PPC_PLT16_HI", /* name */
670 false, /* partial_inplace */
672 0xffff, /* dst_mask */
673 false), /* pcrel_offset */
675 /* Like R_PPC_ADDR16_HA, but referring to the PLT table entry for
676 the symbol. FIXME: Not supported. */
677 HOWTO (R_PPC_PLT16_HA
, /* type */
679 1, /* size (0 = byte, 1 = short, 2 = long) */
681 false, /* pc_relative */
683 complain_overflow_bitfield
, /* complain_on_overflow */
684 bfd_elf_generic_reloc
, /* special_function */
685 "R_PPC_PLT16_HA", /* name */
686 false, /* partial_inplace */
688 0xffff, /* dst_mask */
689 false), /* pcrel_offset */
691 /* A sign-extended 16 bit value relative to _SDA_BASE_, for use with
693 HOWTO (R_PPC_SDAREL16
, /* type */
695 1, /* size (0 = byte, 1 = short, 2 = long) */
697 false, /* pc_relative */
699 complain_overflow_signed
, /* complain_on_overflow */
700 bfd_elf_generic_reloc
, /* special_function */
701 "R_PPC_SDAREL16", /* name */
702 false, /* partial_inplace */
704 0xffff, /* dst_mask */
705 false), /* pcrel_offset */
707 /* 32-bit section relative relocation. */
708 HOWTO (R_PPC_SECTOFF
, /* type */
710 2, /* size (0 = byte, 1 = short, 2 = long) */
712 true, /* pc_relative */
714 complain_overflow_bitfield
, /* complain_on_overflow */
715 bfd_elf_generic_reloc
, /* special_function */
716 "R_PPC_SECTOFF", /* name */
717 false, /* partial_inplace */
720 true), /* pcrel_offset */
722 /* 16-bit lower half section relative relocation. */
723 HOWTO (R_PPC_SECTOFF_LO
, /* type */
725 1, /* size (0 = byte, 1 = short, 2 = long) */
727 false, /* pc_relative */
729 complain_overflow_bitfield
, /* complain_on_overflow */
730 bfd_elf_generic_reloc
, /* special_function */
731 "R_PPC_SECTOFF_LO", /* name */
732 false, /* partial_inplace */
734 0xffff, /* dst_mask */
735 false), /* pcrel_offset */
737 /* 16-bit upper half section relative relocation. */
738 HOWTO (R_PPC_SECTOFF_HI
, /* type */
740 1, /* size (0 = byte, 1 = short, 2 = long) */
742 false, /* pc_relative */
744 complain_overflow_bitfield
, /* complain_on_overflow */
745 bfd_elf_generic_reloc
, /* special_function */
746 "R_PPC_SECTOFF_HI", /* name */
747 false, /* partial_inplace */
749 0xffff, /* dst_mask */
750 false), /* pcrel_offset */
752 /* 16-bit upper half adjusted section relative relocation. */
753 HOWTO (R_PPC_SECTOFF_HA
, /* type */
755 1, /* size (0 = byte, 1 = short, 2 = long) */
757 false, /* pc_relative */
759 complain_overflow_bitfield
, /* complain_on_overflow */
760 bfd_elf_generic_reloc
, /* special_function */
761 "R_PPC_SECTOFF_HA", /* name */
762 false, /* partial_inplace */
764 0xffff, /* dst_mask */
765 false), /* pcrel_offset */
767 /* The remaining relocs are from the Embedded ELF ABI, and are not
768 in the SVR4 ELF ABI. */
770 /* 32 bit value resulting from the addend minus the symbol */
771 HOWTO (R_PPC_EMB_NADDR32
, /* type */
773 2, /* size (0 = byte, 1 = short, 2 = long) */
775 false, /* pc_relative */
777 complain_overflow_bitfield
, /* complain_on_overflow */
778 bfd_elf_generic_reloc
, /* special_function */
779 "R_PPC_EMB_NADDR32", /* name */
780 false, /* partial_inplace */
782 0xffffffff, /* dst_mask */
783 false), /* pcrel_offset */
785 /* 16 bit value resulting from the addend minus the symbol */
786 HOWTO (R_PPC_EMB_NADDR16
, /* type */
788 1, /* size (0 = byte, 1 = short, 2 = long) */
790 false, /* pc_relative */
792 complain_overflow_bitfield
, /* complain_on_overflow */
793 bfd_elf_generic_reloc
, /* special_function */
794 "R_PPC_EMB_NADDR16", /* name */
795 false, /* partial_inplace */
797 0xffff, /* dst_mask */
798 false), /* pcrel_offset */
800 /* 16 bit value resulting from the addend minus the symbol */
801 HOWTO (R_PPC_EMB_NADDR16_LO
, /* type */
803 1, /* size (0 = byte, 1 = short, 2 = long) */
805 false, /* pc_relative */
807 complain_overflow_dont
,/* complain_on_overflow */
808 bfd_elf_generic_reloc
, /* special_function */
809 "R_PPC_EMB_ADDR16_LO", /* name */
810 false, /* partial_inplace */
812 0xffff, /* dst_mask */
813 false), /* pcrel_offset */
815 /* The high order 16 bits of the addend minus the symbol */
816 HOWTO (R_PPC_EMB_NADDR16_HI
, /* type */
818 1, /* size (0 = byte, 1 = short, 2 = long) */
820 false, /* pc_relative */
822 complain_overflow_dont
, /* complain_on_overflow */
823 bfd_elf_generic_reloc
, /* special_function */
824 "R_PPC_EMB_NADDR16_HI", /* name */
825 false, /* partial_inplace */
827 0xffff, /* dst_mask */
828 false), /* pcrel_offset */
830 /* The high order 16 bits of the result of the addend minus the address,
831 plus 1 if the contents of the low 16 bits, treated as a signed number,
833 HOWTO (R_PPC_EMB_NADDR16_HA
, /* type */
835 1, /* size (0 = byte, 1 = short, 2 = long) */
837 false, /* pc_relative */
839 complain_overflow_dont
, /* complain_on_overflow */
840 bfd_elf_generic_reloc
, /* special_function */
841 "R_PPC_EMB_NADDR16_HA", /* name */
842 false, /* partial_inplace */
844 0xffff, /* dst_mask */
845 false), /* pcrel_offset */
847 /* 16 bit value resulting from allocating a 4 byte word to hold an
848 address in the .sdata section, and returning the offset from
849 _SDA_BASE_ for that relocation */
850 HOWTO (R_PPC_EMB_SDAI16
, /* type */
852 1, /* size (0 = byte, 1 = short, 2 = long) */
854 false, /* pc_relative */
856 complain_overflow_bitfield
, /* complain_on_overflow */
857 bfd_elf_generic_reloc
, /* special_function */
858 "R_PPC_EMB_SDAI16", /* name */
859 false, /* partial_inplace */
861 0xffff, /* dst_mask */
862 false), /* pcrel_offset */
864 /* 16 bit value resulting from allocating a 4 byte word to hold an
865 address in the .sdata2 section, and returning the offset from
866 _SDA2_BASE_ for that relocation */
867 HOWTO (R_PPC_EMB_SDA2I16
, /* type */
869 1, /* size (0 = byte, 1 = short, 2 = long) */
871 false, /* pc_relative */
873 complain_overflow_bitfield
, /* complain_on_overflow */
874 bfd_elf_generic_reloc
, /* special_function */
875 "R_PPC_EMB_SDA2I16", /* name */
876 false, /* partial_inplace */
878 0xffff, /* dst_mask */
879 false), /* pcrel_offset */
881 /* A sign-extended 16 bit value relative to _SDA2_BASE_, for use with
883 HOWTO (R_PPC_EMB_SDA2REL
, /* type */
885 1, /* size (0 = byte, 1 = short, 2 = long) */
887 false, /* pc_relative */
889 complain_overflow_signed
, /* complain_on_overflow */
890 bfd_elf_generic_reloc
, /* special_function */
891 "R_PPC_EMB_SDA2REL", /* name */
892 false, /* partial_inplace */
894 0xffff, /* dst_mask */
895 false), /* pcrel_offset */
897 /* Relocate against either _SDA_BASE_ or _SDA2_BASE_, filling in the 16 bit
898 signed offset from the appropriate base, and filling in the register
899 field with the appropriate register (0, 2, or 13). */
900 HOWTO (R_PPC_EMB_SDA21
, /* type */
902 2, /* size (0 = byte, 1 = short, 2 = long) */
904 false, /* pc_relative */
906 complain_overflow_signed
, /* complain_on_overflow */
907 bfd_elf_generic_reloc
, /* special_function */
908 "R_PPC_EMB_SDA21", /* name */
909 false, /* partial_inplace */
911 0xffff, /* dst_mask */
912 false), /* pcrel_offset */
914 /* Relocation not handled: R_PPC_EMB_MRKREF */
915 /* Relocation not handled: R_PPC_EMB_RELSEC16 */
916 /* Relocation not handled: R_PPC_EMB_RELST_LO */
917 /* Relocation not handled: R_PPC_EMB_RELST_HI */
918 /* Relocation not handled: R_PPC_EMB_RELST_HA */
919 /* Relocation not handled: R_PPC_EMB_BIT_FLD */
921 /* PC relative relocation against either _SDA_BASE_ or _SDA2_BASE_, filling
922 in the 16 bit signed offset from the appropriate base, and filling in the
923 register field with the appropriate register (0, 2, or 13). */
924 HOWTO (R_PPC_EMB_RELSDA
, /* type */
926 1, /* size (0 = byte, 1 = short, 2 = long) */
928 true, /* pc_relative */
930 complain_overflow_signed
, /* complain_on_overflow */
931 bfd_elf_generic_reloc
, /* special_function */
932 "R_PPC_EMB_RELSDA", /* name */
933 false, /* partial_inplace */
935 0xffff, /* dst_mask */
936 false), /* pcrel_offset */
938 /* Phony reloc to handle AIX style TOC entries */
939 HOWTO (R_PPC_TOC16
, /* type */
941 1, /* size (0 = byte, 1 = short, 2 = long) */
943 false, /* pc_relative */
945 complain_overflow_signed
, /* complain_on_overflow */
946 bfd_elf_generic_reloc
, /* special_function */
947 "R_PPC_TOC16", /* name */
948 false, /* partial_inplace */
950 0xffff, /* dst_mask */
951 false), /* pcrel_offset */
955 /* Initialize the ppc_elf_howto_table, so that linear accesses can be done. */
958 ppc_elf_howto_init ()
960 unsigned int i
, type
;
962 for (i
= 0; i
< sizeof (ppc_elf_howto_raw
) / sizeof (ppc_elf_howto_raw
[0]); i
++)
964 type
= ppc_elf_howto_raw
[i
].type
;
965 BFD_ASSERT (type
< sizeof(ppc_elf_howto_table
) / sizeof(ppc_elf_howto_table
[0]));
966 ppc_elf_howto_table
[type
] = &ppc_elf_howto_raw
[i
];
971 static reloc_howto_type
*
972 ppc_elf_reloc_type_lookup (abfd
, code
)
974 bfd_reloc_code_real_type code
;
976 enum ppc_reloc_type ppc_reloc
= R_PPC_NONE
;
978 if (!ppc_elf_howto_table
[ R_PPC_ADDR32
]) /* Initialize howto table if needed */
979 ppc_elf_howto_init ();
984 return (reloc_howto_type
*)NULL
;
986 case BFD_RELOC_NONE
: ppc_reloc
= R_PPC_NONE
; break;
987 case BFD_RELOC_32
: ppc_reloc
= R_PPC_ADDR32
; break;
988 case BFD_RELOC_PPC_BA26
: ppc_reloc
= R_PPC_ADDR24
; break;
989 case BFD_RELOC_16
: ppc_reloc
= R_PPC_ADDR16
; break;
990 case BFD_RELOC_LO16
: ppc_reloc
= R_PPC_ADDR16_LO
; break;
991 case BFD_RELOC_HI16
: ppc_reloc
= R_PPC_ADDR16_HI
; break;
992 case BFD_RELOC_HI16_S
: ppc_reloc
= R_PPC_ADDR16_HA
; break;
993 case BFD_RELOC_PPC_BA16
: ppc_reloc
= R_PPC_ADDR14
; break;
994 case BFD_RELOC_PPC_BA16_BRTAKEN
: ppc_reloc
= R_PPC_ADDR14_BRTAKEN
; break;
995 case BFD_RELOC_PPC_BA16_BRNTAKEN
: ppc_reloc
= R_PPC_ADDR14_BRNTAKEN
; break;
996 case BFD_RELOC_PPC_B26
: ppc_reloc
= R_PPC_REL24
; break;
997 case BFD_RELOC_PPC_B16
: ppc_reloc
= R_PPC_REL14
; break;
998 case BFD_RELOC_PPC_B16_BRTAKEN
: ppc_reloc
= R_PPC_REL14_BRTAKEN
; break;
999 case BFD_RELOC_PPC_B16_BRNTAKEN
: ppc_reloc
= R_PPC_REL14_BRNTAKEN
; break;
1000 case BFD_RELOC_16_GOTOFF
: ppc_reloc
= R_PPC_GOT16
; break;
1001 case BFD_RELOC_LO16_GOTOFF
: ppc_reloc
= R_PPC_GOT16_LO
; break;
1002 case BFD_RELOC_HI16_GOTOFF
: ppc_reloc
= R_PPC_GOT16_HI
; break;
1003 case BFD_RELOC_HI16_S_GOTOFF
: ppc_reloc
= R_PPC_GOT16_HA
; break;
1004 case BFD_RELOC_24_PLT_PCREL
: ppc_reloc
= R_PPC_PLTREL24
; break;
1005 case BFD_RELOC_PPC_COPY
: ppc_reloc
= R_PPC_COPY
; break;
1006 case BFD_RELOC_PPC_GLOB_DAT
: ppc_reloc
= R_PPC_GLOB_DAT
; break;
1007 case BFD_RELOC_PPC_LOCAL24PC
: ppc_reloc
= R_PPC_LOCAL24PC
; break;
1008 case BFD_RELOC_32_PCREL
: ppc_reloc
= R_PPC_REL32
; break;
1009 case BFD_RELOC_32_PLTOFF
: ppc_reloc
= R_PPC_PLT32
; break;
1010 case BFD_RELOC_32_PLT_PCREL
: ppc_reloc
= R_PPC_PLTREL32
; break;
1011 case BFD_RELOC_LO16_PLTOFF
: ppc_reloc
= R_PPC_PLT16_LO
; break;
1012 case BFD_RELOC_HI16_PLTOFF
: ppc_reloc
= R_PPC_PLT16_HI
; break;
1013 case BFD_RELOC_HI16_S_PLTOFF
: ppc_reloc
= R_PPC_PLT16_HA
; break;
1014 case BFD_RELOC_GPREL16
: ppc_reloc
= R_PPC_SDAREL16
; break;
1015 case BFD_RELOC_32_BASEREL
: ppc_reloc
= R_PPC_SECTOFF
; break;
1016 case BFD_RELOC_LO16_BASEREL
: ppc_reloc
= R_PPC_SECTOFF_LO
; break;
1017 case BFD_RELOC_HI16_BASEREL
: ppc_reloc
= R_PPC_SECTOFF_HI
; break;
1018 case BFD_RELOC_HI16_S_BASEREL
: ppc_reloc
= R_PPC_SECTOFF_HA
; break;
1019 case BFD_RELOC_CTOR
: ppc_reloc
= R_PPC_ADDR32
; break;
1020 case BFD_RELOC_PPC_TOC16
: ppc_reloc
= R_PPC_TOC16
; break;
1021 case BFD_RELOC_PPC_EMB_NADDR32
: ppc_reloc
= R_PPC_EMB_NADDR32
; break;
1022 case BFD_RELOC_PPC_EMB_NADDR16
: ppc_reloc
= R_PPC_EMB_NADDR16
; break;
1023 case BFD_RELOC_PPC_EMB_NADDR16_LO
: ppc_reloc
= R_PPC_EMB_NADDR16_LO
; break;
1024 case BFD_RELOC_PPC_EMB_NADDR16_HI
: ppc_reloc
= R_PPC_EMB_NADDR16_HI
; break;
1025 case BFD_RELOC_PPC_EMB_NADDR16_HA
: ppc_reloc
= R_PPC_EMB_NADDR16_HA
; break;
1026 case BFD_RELOC_PPC_EMB_SDAI16
: ppc_reloc
= R_PPC_EMB_SDAI16
; break;
1027 case BFD_RELOC_PPC_EMB_SDA2I16
: ppc_reloc
= R_PPC_EMB_SDA2I16
; break;
1028 case BFD_RELOC_PPC_EMB_SDA2REL
: ppc_reloc
= R_PPC_EMB_SDA2REL
; break;
1029 case BFD_RELOC_PPC_EMB_SDA21
: ppc_reloc
= R_PPC_EMB_SDA21
; break;
1030 case BFD_RELOC_PPC_EMB_MRKREF
: ppc_reloc
= R_PPC_EMB_MRKREF
; break;
1031 case BFD_RELOC_PPC_EMB_RELSEC16
: ppc_reloc
= R_PPC_EMB_RELSEC16
; break;
1032 case BFD_RELOC_PPC_EMB_RELST_LO
: ppc_reloc
= R_PPC_EMB_RELST_LO
; break;
1033 case BFD_RELOC_PPC_EMB_RELST_HI
: ppc_reloc
= R_PPC_EMB_RELST_HI
; break;
1034 case BFD_RELOC_PPC_EMB_RELST_HA
: ppc_reloc
= R_PPC_EMB_RELST_HA
; break;
1035 case BFD_RELOC_PPC_EMB_BIT_FLD
: ppc_reloc
= R_PPC_EMB_BIT_FLD
; break;
1036 case BFD_RELOC_PPC_EMB_RELSDA
: ppc_reloc
= R_PPC_EMB_RELSDA
; break;
1039 return ppc_elf_howto_table
[ (int)ppc_reloc
];
1042 /* Set the howto pointer for a PowerPC ELF reloc. */
1045 ppc_elf_info_to_howto (abfd
, cache_ptr
, dst
)
1048 Elf32_Internal_Rela
*dst
;
1050 if (!ppc_elf_howto_table
[ R_PPC_ADDR32
]) /* Initialize howto table if needed */
1051 ppc_elf_howto_init ();
1053 BFD_ASSERT (ELF32_R_TYPE (dst
->r_info
) < (unsigned int) R_PPC_max
);
1054 cache_ptr
->howto
= ppc_elf_howto_table
[ELF32_R_TYPE (dst
->r_info
)];
1057 /* Handle the R_PPC_ADDR16_HA reloc. */
1059 static bfd_reloc_status_type
1060 ppc_elf_addr16_ha_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1061 output_bfd
, error_message
)
1063 arelent
*reloc_entry
;
1066 asection
*input_section
;
1068 char **error_message
;
1072 if (output_bfd
!= NULL
)
1074 reloc_entry
->address
+= input_section
->output_offset
;
1075 return bfd_reloc_ok
;
1078 if (reloc_entry
->address
> input_section
->_cooked_size
)
1079 return bfd_reloc_outofrange
;
1081 if (bfd_is_com_section (symbol
->section
))
1084 relocation
= symbol
->value
;
1086 relocation
+= symbol
->section
->output_section
->vma
;
1087 relocation
+= symbol
->section
->output_offset
;
1088 relocation
+= reloc_entry
->addend
;
1090 reloc_entry
->addend
+= (relocation
& 0x8000) << 1;
1092 return bfd_reloc_continue
;
1095 /* Function to set whether a module needs the -mrelocatable bit set. */
1098 ppc_elf_set_private_flags (abfd
, flags
)
1102 BFD_ASSERT (!elf_flags_init (abfd
)
1103 || elf_elfheader (abfd
)->e_flags
== flags
);
1105 elf_elfheader (abfd
)->e_flags
= flags
;
1106 elf_flags_init (abfd
) = true;
1110 /* Copy backend specific data from one object module to another */
1112 ppc_elf_copy_private_bfd_data (ibfd
, obfd
)
1116 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
1117 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
1120 BFD_ASSERT (!elf_flags_init (obfd
)
1121 || elf_elfheader (obfd
)->e_flags
== elf_elfheader (ibfd
)->e_flags
);
1123 elf_elfheader (obfd
)->e_flags
= elf_elfheader (ibfd
)->e_flags
;
1124 elf_flags_init (obfd
) = true;
1128 /* Merge backend specific data from an object file to the output
1129 object file when linking */
1131 ppc_elf_merge_private_bfd_data (ibfd
, obfd
)
1139 /* Check if we have the same endianess */
1140 if (ibfd
->xvec
->byteorder
!= obfd
->xvec
->byteorder
1141 && obfd
->xvec
->byteorder
!= BFD_ENDIAN_UNKNOWN
)
1143 (*_bfd_error_handler
)
1144 ("%s: compiled for a %s endian system and target is %s endian",
1145 bfd_get_filename (ibfd
),
1146 bfd_big_endian (ibfd
) ? "big" : "little",
1147 bfd_big_endian (obfd
) ? "big" : "little");
1149 bfd_set_error (bfd_error_wrong_format
);
1153 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
1154 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
1157 new_flags
= elf_elfheader (ibfd
)->e_flags
;
1158 old_flags
= elf_elfheader (obfd
)->e_flags
;
1159 if (!elf_flags_init (obfd
)) /* First call, no flags set */
1161 elf_flags_init (obfd
) = true;
1162 elf_elfheader (obfd
)->e_flags
= new_flags
;
1165 else if (new_flags
== old_flags
) /* Compatible flags are ok */
1168 else /* Incompatible flags */
1170 /* Warn about -mrelocatable mismatch. Allow -mrelocatable-lib to be linked
1173 if ((new_flags
& EF_PPC_RELOCATABLE
) != 0
1174 && (old_flags
& (EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
)) == 0)
1177 (*_bfd_error_handler
)
1178 ("%s: compiled with -mrelocatable and linked with modules compiled normally",
1179 bfd_get_filename (ibfd
));
1181 else if ((new_flags
& (EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
)) == 0
1182 && (old_flags
& EF_PPC_RELOCATABLE
) != 0)
1185 (*_bfd_error_handler
)
1186 ("%s: compiled normally and linked with modules compiled with -mrelocatable",
1187 bfd_get_filename (ibfd
));
1189 /* If -mrelocatable-lib is linked with an object without -mrelocatable-lib, turn off
1190 the -mrelocatable-lib, since at least one module isn't relocatable. */
1191 else if ((old_flags
& EF_PPC_RELOCATABLE_LIB
) != 0
1192 && (new_flags
& EF_PPC_RELOCATABLE_LIB
) == 0)
1193 elf_elfheader (obfd
)->e_flags
&= ~EF_PPC_RELOCATABLE_LIB
;
1196 /* Do not warn about eabi vs. V.4 mismatch, just or in the bit if any module uses it */
1197 elf_elfheader (obfd
)->e_flags
|= (new_flags
& EF_PPC_EMB
);
1199 new_flags
&= ~ (EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
| EF_PPC_EMB
);
1200 old_flags
&= ~ (EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
| EF_PPC_EMB
);
1202 /* Warn about any other mismatches */
1203 if (new_flags
!= old_flags
)
1206 (*_bfd_error_handler
)
1207 ("%s: uses different e_flags (0x%lx) fields than previous modules (0x%lx)",
1208 bfd_get_filename (ibfd
), (long)new_flags
, (long)old_flags
);
1213 bfd_set_error (bfd_error_bad_value
);
1222 /* Handle a PowerPC specific section when reading an object file. This
1223 is called when elfcode.h finds a section with an unknown type. */
1226 ppc_elf_section_from_shdr (abfd
, hdr
, name
)
1228 Elf32_Internal_Shdr
*hdr
;
1234 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
))
1237 newsect
= hdr
->bfd_section
;
1238 flags
= bfd_get_section_flags (abfd
, newsect
);
1239 if (hdr
->sh_flags
& SHF_EXCLUDE
)
1240 flags
|= SEC_EXCLUDE
;
1242 if (hdr
->sh_type
== SHT_ORDERED
)
1243 flags
|= SEC_SORT_ENTRIES
;
1245 bfd_set_section_flags (abfd
, newsect
, flags
);
1250 /* Set up any other section flags and such that may be necessary. */
1253 ppc_elf_fake_sections (abfd
, shdr
, asect
)
1255 Elf32_Internal_Shdr
*shdr
;
1258 if ((asect
->flags
& SEC_EXCLUDE
) != 0)
1259 shdr
->sh_flags
|= SHF_EXCLUDE
;
1261 if ((asect
->flags
& SEC_SORT_ENTRIES
) != 0)
1262 shdr
->sh_type
= SHT_ORDERED
;
1268 /* Create a special linker section */
1269 static elf_linker_section_t
*
1270 ppc_elf_create_linker_section (abfd
, info
, which
)
1272 struct bfd_link_info
*info
;
1273 enum elf_linker_section_enum which
;
1275 bfd
*dynobj
= elf_hash_table (info
)->dynobj
;
1276 elf_linker_section_t
*lsect
;
1278 /* Record the first bfd section that needs the special section */
1280 dynobj
= elf_hash_table (info
)->dynobj
= abfd
;
1282 /* If this is the first time, create the section */
1283 lsect
= elf_linker_section (dynobj
, which
);
1286 elf_linker_section_t defaults
;
1287 static elf_linker_section_t zero_section
;
1289 defaults
= zero_section
;
1290 defaults
.which
= which
;
1291 defaults
.hole_written_p
= false;
1292 defaults
.alignment
= 2;
1293 defaults
.flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
1294 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
1299 (*_bfd_error_handler
) ("%s: Unknown special linker type %d",
1300 bfd_get_filename (abfd
),
1303 bfd_set_error (bfd_error_bad_value
);
1304 return (elf_linker_section_t
*)0;
1306 case LINKER_SECTION_GOT
: /* .got section */
1307 defaults
.name
= ".got";
1308 defaults
.rel_name
= ".rela.got";
1309 defaults
.sym_name
= "_GLOBAL_OFFSET_TABLE_";
1310 defaults
.max_hole_offset
= 32764;
1311 defaults
.hole_size
= 16;
1312 defaults
.sym_offset
= 4;
1315 case LINKER_SECTION_PLT
: /* .plt section */
1316 defaults
.name
= ".plt";
1317 defaults
.rel_name
= ".rela.plt";
1318 defaults
.sym_name
= (char *)0;
1319 defaults
.max_hole_offset
= 0;
1320 defaults
.hole_size
= 0;
1321 defaults
.sym_offset
= 0;
1322 defaults
.flags
&= ~SEC_LOAD
;
1325 case LINKER_SECTION_SDATA
: /* .sdata/.sbss section */
1326 defaults
.name
= ".sdata";
1327 defaults
.rel_name
= ".rela.sdata";
1328 defaults
.bss_name
= ".sbss";
1329 defaults
.sym_name
= "_SDA_BASE_";
1330 defaults
.sym_offset
= 32768;
1333 case LINKER_SECTION_SDATA2
: /* .sdata2/.sbss2 section */
1334 defaults
.name
= ".sdata2";
1335 defaults
.rel_name
= ".rela.sdata2";
1336 defaults
.bss_name
= ".sbss2";
1337 defaults
.sym_name
= "_SDA2_BASE_";
1338 defaults
.sym_offset
= 32768;
1339 defaults
.flags
|= SEC_READONLY
;
1343 lsect
= _bfd_elf_create_linker_section (abfd
, info
, which
, &defaults
);
1350 /* If we have a non-zero sized .sbss2 or .PPC.EMB.sbss0 sections, we need to bump up
1351 the number of section headers. */
1354 ppc_elf_additional_program_headers (abfd
)
1362 s
= bfd_get_section_by_name (abfd
, ".interp");
1366 s
= bfd_get_section_by_name (abfd
, ".sbss2");
1367 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0 && s
->_raw_size
> 0)
1370 s
= bfd_get_section_by_name (abfd
, ".PPC.EMB.sbss0");
1371 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0 && s
->_raw_size
> 0)
1377 /* Modify the segment map if needed */
1380 ppc_elf_modify_segment_map (abfd
)
1386 /* Adjust a symbol defined by a dynamic object and referenced by a
1387 regular object. The current definition is in some section of the
1388 dynamic object, but we're not including those sections. We have to
1389 change the definition to something the rest of the link can
1393 ppc_elf_adjust_dynamic_symbol (info
, h
)
1394 struct bfd_link_info
*info
;
1395 struct elf_link_hash_entry
*h
;
1397 bfd
*dynobj
= elf_hash_table (info
)->dynobj
;
1399 unsigned int power_of_two
;
1403 fprintf (stderr
, "ppc_elf_adjust_dynamic_symbol called for %s\n", h
->root
.root
.string
);
1406 /* Make sure we know what is going on here. */
1407 BFD_ASSERT (dynobj
!= NULL
1408 && ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
)
1409 || h
->weakdef
!= NULL
1410 || ((h
->elf_link_hash_flags
1411 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0
1412 && (h
->elf_link_hash_flags
1413 & ELF_LINK_HASH_REF_REGULAR
) != 0
1414 && (h
->elf_link_hash_flags
1415 & ELF_LINK_HASH_DEF_REGULAR
) == 0)));
1418 /* If this is a function, put it in the procedure linkage table. We
1419 will fill in the contents of the procedure linkage table later,
1420 when we know the address of the .got section. */
1421 if (h
->type
== STT_FUNC
1422 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
1425 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) == 0
1426 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_REF_DYNAMIC
) == 0)
1428 /* This case can occur if we saw a PLT32 reloc in an input
1429 file, but the symbol was never referred to by a dynamic
1430 object. In such a case, we don't actually need to build
1431 a procedure linkage table, and we can just do a PC32
1433 BFD_ASSERT ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0);
1437 /* Make sure this symbol is output as a dynamic symbol. */
1438 if (h
->dynindx
== -1)
1440 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
1444 s
= bfd_get_section_by_name (dynobj
, ".plt");
1445 BFD_ASSERT (s
!= NULL
);
1447 /* If this is the first .plt entry, make room for the special
1449 if (s
->_raw_size
== 0)
1450 s
->_raw_size
+= PLT_INITIAL_ENTRY_SIZE
;
1452 /* The PowerPC PLT is actually composed of two parts, the first part
1453 is 2 words (for a load and a jump), and then there is a remaining
1454 word available at the end. */
1455 plt_offset
= (PLT_INITIAL_ENTRY_SIZE
1456 + 8 * ((s
->_raw_size
- PLT_INITIAL_ENTRY_SIZE
) / PLT_ENTRY_SIZE
));
1458 /* If this symbol is not defined in a regular file, and we are
1459 not generating a shared library, then set the symbol to this
1460 location in the .plt. This is required to make function
1461 pointers compare as equal between the normal executable and
1462 the shared library. */
1464 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
1466 h
->root
.u
.def
.section
= s
;
1467 h
->root
.u
.def
.value
= plt_offset
;
1470 h
->plt_offset
= plt_offset
;
1472 /* Make room for this entry. */
1473 s
->_raw_size
+= PLT_ENTRY_SIZE
;
1476 /* We also need to make an entry in the .got.plt section, which
1477 will be placed in the .got section by the linker script. */
1479 s
= bfd_get_section_by_name (dynobj
, ".got.plt");
1480 BFD_ASSERT (s
!= NULL
);
1484 /* We also need to make an entry in the .rela.plt section. */
1486 s
= bfd_get_section_by_name (dynobj
, ".rela.plt");
1487 BFD_ASSERT (s
!= NULL
);
1488 s
->_raw_size
+= sizeof (Elf32_External_Rela
);
1493 /* If this is a weak symbol, and there is a real definition, the
1494 processor independent code will have arranged for us to see the
1495 real definition first, and we can just use the same value. */
1496 if (h
->weakdef
!= NULL
)
1498 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
1499 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
1500 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
1501 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
1505 /* This is a reference to a symbol defined by a dynamic object which
1506 is not a function. */
1508 /* If we are creating a shared library, we must presume that the
1509 only references to the symbol are via the global offset table.
1510 For such cases we need not do anything here; the relocations will
1511 be handled correctly by relocate_section. */
1515 /* We must allocate the symbol in our .dynbss section, which will
1516 become part of the .bss section of the executable. There will be
1517 an entry for this symbol in the .dynsym section. The dynamic
1518 object will contain position independent code, so all references
1519 from the dynamic object to this symbol will go through the global
1520 offset table. The dynamic linker will use the .dynsym entry to
1521 determine the address it must put in the global offset table, so
1522 both the dynamic object and the regular object will refer to the
1523 same memory location for the variable. */
1525 s
= bfd_get_section_by_name (dynobj
, ".dynbss");
1526 BFD_ASSERT (s
!= NULL
);
1528 /* If the symbol is currently defined in the .bss section of the
1529 dynamic object, then it is OK to simply initialize it to zero.
1530 If the symbol is in some other section, we must generate a
1531 R_PPC_COPY reloc to tell the dynamic linker to copy the initial
1532 value out of the dynamic object and into the runtime process
1533 image. We need to remember the offset into the .rela.bss section
1534 we are going to use. */
1535 if ((h
->root
.u
.def
.section
->flags
& SEC_LOAD
) != 0)
1539 srel
= bfd_get_section_by_name (dynobj
, ".rela.bss");
1540 BFD_ASSERT (srel
!= NULL
);
1541 srel
->_raw_size
+= sizeof (Elf32_External_Rel
);
1542 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_COPY
;
1545 /* We need to figure out the alignment required for this symbol. I
1546 have no idea how ELF linkers handle this. */
1547 power_of_two
= bfd_log2 (h
->size
);
1548 if (power_of_two
> 3)
1551 /* Apply the required alignment. */
1552 s
->_raw_size
= BFD_ALIGN (s
->_raw_size
,
1553 (bfd_size_type
) (1 << power_of_two
));
1554 if (power_of_two
> bfd_get_section_alignment (dynobj
, s
))
1556 if (! bfd_set_section_alignment (dynobj
, s
, power_of_two
))
1560 /* Define the symbol as being at this point in the section. */
1561 h
->root
.u
.def
.section
= s
;
1562 h
->root
.u
.def
.value
= s
->_raw_size
;
1564 /* Increment the section size to make room for the symbol. */
1565 s
->_raw_size
+= h
->size
;
1571 /* Increment the index of a dynamic symbol by a given amount. Called
1572 via elf_link_hash_traverse. */
1575 ppc_elf_adjust_dynindx (h
, cparg
)
1576 struct elf_link_hash_entry
*h
;
1579 int *cp
= (int *) cparg
;
1582 fprintf (stderr
, "ppc_elf_adjust_dynindx called, h->dynindx = %d, *cp = %d\n", h
->dynindx
, *cp
);
1585 if (h
->dynindx
!= -1)
1592 /* Set the sizes of the dynamic sections. */
1595 ppc_elf_size_dynamic_sections (output_bfd
, info
)
1597 struct bfd_link_info
*info
;
1606 fprintf (stderr
, "ppc_elf_size_dynamic_sections called\n");
1609 dynobj
= elf_hash_table (info
)->dynobj
;
1610 BFD_ASSERT (dynobj
!= NULL
);
1612 if (elf_hash_table (info
)->dynamic_sections_created
)
1614 /* Set the contents of the .interp section to the interpreter. */
1617 s
= bfd_get_section_by_name (dynobj
, ".interp");
1618 BFD_ASSERT (s
!= NULL
);
1619 s
->_raw_size
= sizeof ELF_DYNAMIC_INTERPRETER
;
1620 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
1625 /* We may have created entries in the .rela.got, .rela.sdata, and
1626 .rela.sdata2 sections. However, if we are not creating the
1627 dynamic sections, we will not actually use these entries. Reset
1628 the size of .rela.got, et al, which will cause it to get
1629 stripped from the output file below. */
1630 static char *rela_sections
[] = { ".rela.got", ".rela.sdata", ".rela.sdata", (char *)0 };
1633 for (p
= rela_sections
; *p
!= (char *)0; p
++)
1635 s
= bfd_get_section_by_name (dynobj
, *p
);
1641 /* The check_relocs and adjust_dynamic_symbol entry points have
1642 determined the sizes of the various dynamic sections. Allocate
1647 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
1652 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
1655 /* It's OK to base decisions on the section name, because none
1656 of the dynobj section names depend upon the input files. */
1657 name
= bfd_get_section_name (dynobj
, s
);
1661 if (strcmp (name
, ".plt") == 0)
1663 if (s
->_raw_size
== 0)
1665 /* Strip this section if we don't need it; see the
1671 /* Remember whether there is a PLT. */
1675 else if (strncmp (name
, ".rela", 5) == 0)
1677 if (s
->_raw_size
== 0)
1679 /* If we don't need this section, strip it from the
1680 output file. This is mostly to handle .rela.bss and
1681 .rela.plt. We must create both sections in
1682 create_dynamic_sections, because they must be created
1683 before the linker maps input sections to output
1684 sections. The linker does that before
1685 adjust_dynamic_symbol is called, and it is that
1686 function which decides whether anything needs to go
1687 into these sections. */
1694 /* Remember whether there are any reloc sections other
1696 if (strcmp (name
, ".rela.plt") != 0)
1698 const char *outname
;
1702 /* If this relocation section applies to a read only
1703 section, then we probably need a DT_TEXTREL
1704 entry. The entries in the .rel.plt section
1705 really apply to the .got section, which we
1706 created ourselves and so know is not readonly. */
1707 outname
= bfd_get_section_name (output_bfd
,
1709 target
= bfd_get_section_by_name (output_bfd
, outname
+ 4);
1711 && (target
->flags
& SEC_READONLY
) != 0)
1715 /* We use the reloc_count field as a counter if we need
1716 to copy relocs into the output file. */
1720 else if (strcmp (name
, ".got") != 0
1721 && strcmp (name
, ".sdata") != 0
1722 && strcmp (name
, ".sdata2") != 0)
1724 /* It's not one of our sections, so don't allocate space. */
1732 for (spp
= &s
->output_section
->owner
->sections
;
1733 *spp
!= s
->output_section
;
1734 spp
= &(*spp
)->next
)
1736 *spp
= s
->output_section
->next
;
1737 --s
->output_section
->owner
->section_count
;
1742 /* Allocate memory for the section contents. */
1743 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->_raw_size
);
1744 if (s
->contents
== NULL
&& s
->_raw_size
!= 0)
1748 if (elf_hash_table (info
)->dynamic_sections_created
)
1750 /* Add some entries to the .dynamic section. We fill in the
1751 values later, in ppc_elf_finish_dynamic_sections, but we
1752 must add the entries now so that we get the correct size for
1753 the .dynamic section. The DT_DEBUG entry is filled in by the
1754 dynamic linker and used by the debugger. */
1757 if (! bfd_elf32_add_dynamic_entry (info
, DT_DEBUG
, 0))
1763 if (! bfd_elf32_add_dynamic_entry (info
, DT_PLTGOT
, 0)
1764 || ! bfd_elf32_add_dynamic_entry (info
, DT_PLTRELSZ
, 0)
1765 || ! bfd_elf32_add_dynamic_entry (info
, DT_PLTREL
, DT_REL
)
1766 || ! bfd_elf32_add_dynamic_entry (info
, DT_JMPREL
, 0))
1772 if (! bfd_elf32_add_dynamic_entry (info
, DT_RELA
, 0)
1773 || ! bfd_elf32_add_dynamic_entry (info
, DT_RELASZ
, DT_RELA
)
1774 || ! bfd_elf32_add_dynamic_entry (info
, DT_RELENT
,
1775 sizeof (Elf32_External_Rela
)))
1781 if (! bfd_elf32_add_dynamic_entry (info
, DT_TEXTREL
, 0))
1786 /* If we are generating a shared library, we generate a section
1787 symbol for each output section. These are local symbols, which
1788 means that they must come first in the dynamic symbol table.
1789 That means we must increment the dynamic symbol index of every
1790 other dynamic symbol. */
1795 c
= bfd_count_sections (output_bfd
);
1796 elf_link_hash_traverse (elf_hash_table (info
),
1797 ppc_elf_adjust_dynindx
,
1799 elf_hash_table (info
)->dynsymcount
+= c
;
1801 for (i
= 1, s
= output_bfd
->sections
; s
!= NULL
; s
= s
->next
, i
++)
1803 elf_section_data (s
)->dynindx
= i
;
1804 /* These symbols will have no names, so we don't need to
1805 fiddle with dynstr_index. */
1813 /* Look through the relocs for a section during the first phase, and
1814 allocate space in the global offset table or procedure linkage
1818 ppc_elf_check_relocs (abfd
, info
, sec
, relocs
)
1820 struct bfd_link_info
*info
;
1822 const Elf_Internal_Rela
*relocs
;
1826 Elf_Internal_Shdr
*symtab_hdr
;
1827 struct elf_link_hash_entry
**sym_hashes
;
1828 const Elf_Internal_Rela
*rel
;
1829 const Elf_Internal_Rela
*rel_end
;
1830 bfd_vma
*local_got_offsets
;
1831 elf_linker_section_t
*got
;
1832 elf_linker_section_t
*plt
;
1833 elf_linker_section_t
*sdata
;
1834 elf_linker_section_t
*sdata2
;
1837 if (info
->relocateable
)
1841 fprintf (stderr
, "ppc_elf_check_relocs called for section %s in %s\n",
1842 bfd_get_section_name (abfd
, sec
),
1843 bfd_get_filename (abfd
));
1846 /* Create the linker generated sections all the time so that the special
1847 symbols are created. */
1848 if ((got
= elf_linker_section (abfd
, LINKER_SECTION_GOT
)) == NULL
)
1850 got
= ppc_elf_create_linker_section (abfd
, info
, LINKER_SECTION_GOT
);
1856 if ((plt
= elf_linker_section (abfd
, LINKER_SECTION_PLT
)) == NULL
)
1858 plt
= ppc_elf_create_linker_section (abfd
, info
, LINKER_SECTION_PLT
);
1864 if ((sdata
= elf_linker_section (abfd
, LINKER_SECTION_SDATA
)) == NULL
)
1866 sdata
= ppc_elf_create_linker_section (abfd
, info
, LINKER_SECTION_SDATA
);
1872 if ((sdata2
= elf_linker_section (abfd
, LINKER_SECTION_SDATA2
)) == NULL
)
1874 sdata2
= ppc_elf_create_linker_section (abfd
, info
, LINKER_SECTION_SDATA2
);
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");
1929 if (got
->rel_section
== NULL
1930 && (h
!= NULL
|| info
->shared
)
1931 && !_bfd_elf_make_linker_section_rela (dynobj
, got
, 2))
1937 if (!bfd_elf32_create_pointer_linker_section (abfd
, info
, sdata
, h
, rel
))
1942 /* Indirect .sdata2 relocation */
1943 case R_PPC_EMB_SDA2I16
:
1946 (*_bfd_error_handler
) ("%s: relocation %s cannot be used when making a shared object",
1947 bfd_get_filename (abfd
),
1948 "R_PPC_EMB_SDA2I16");
1953 if (got
->rel_section
== NULL
1954 && (h
!= NULL
|| info
->shared
)
1955 && !_bfd_elf_make_linker_section_rela (dynobj
, got
, 2))
1958 if (!bfd_elf32_create_pointer_linker_section (abfd
, info
, sdata2
, h
, rel
))
1963 case R_PPC_SDAREL16
:
1964 case R_PPC_EMB_SDA2REL
:
1965 case R_PPC_EMB_SDA21
:
1968 (*_bfd_error_handler
) ("%s: relocation %s cannot be used when making a shared object",
1969 bfd_get_filename (abfd
),
1970 ppc_elf_howto_table
[(int)ELF32_R_TYPE (rel
->r_info
)]->name
);
1976 case R_PPC_PLTREL24
:
1977 case R_PPC_PLT16_LO
:
1978 case R_PPC_PLT16_HI
:
1979 case R_PPC_PLT16_HA
:
1981 fprintf (stderr
, "Reloc requires a PLT entry\n");
1983 /* This symbol requires a procedure linkage table entry. We
1984 actually build the entry in adjust_dynamic_symbol,
1985 because this might be a case of linking PIC code without
1986 linking in any dynamic objects, in which case we don't
1987 need to generate a procedure linkage table after all. */
1991 /* It does not make sense to have a procedure linkage
1992 table entry for a local symbol. */
1993 bfd_set_error (bfd_error_bad_value
);
1998 /* Make sure this symbol is output as a dynamic symbol. */
1999 if (h
->dynindx
== -1)
2001 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
2008 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
2011 /* the following relocations don't need to propigate the relocation if
2012 linking a shared object since they are section relative. */
2014 case R_PPC_SECTOFF_LO
:
2015 case R_PPC_SECTOFF_HI
:
2016 case R_PPC_SECTOFF_HA
:
2019 /* This refers only to functions defined in the shared library */
2020 case R_PPC_LOCAL24PC
:
2023 /* When creating a shared object, we must copy these
2024 relocs into the output file. We create a reloc
2025 section in dynobj and make room for the reloc. */
2028 && strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
2033 case R_PPC_REL14_BRTAKEN
:
2034 case R_PPC_REL14_BRNTAKEN
:
2041 && (sec
->flags
& SEC_ALLOC
) != 0)
2044 fprintf (stderr
, "ppc_elf_check_relocs need to create relocation for %s\n",
2045 (h
&& h
->root
.root
.string
) ? h
->root
.root
.string
: "<unknown>");
2051 name
= (bfd_elf_string_from_elf_section
2053 elf_elfheader (abfd
)->e_shstrndx
,
2054 elf_section_data (sec
)->rel_hdr
.sh_name
));
2061 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
2062 && strcmp (bfd_get_section_name (abfd
, sec
),
2065 sreloc
= bfd_get_section_by_name (dynobj
, name
);
2068 sreloc
= bfd_make_section (dynobj
, name
);
2070 || ! bfd_set_section_flags (dynobj
, sreloc
,
2075 | SEC_LINKER_CREATED
2077 || ! bfd_set_section_alignment (dynobj
, sreloc
, 2))
2085 sreloc
->_raw_size
+= sizeof (Elf32_External_Rela
);
2096 /* Hook called by the linker routine which adds symbols from an object
2097 file. We use it to put .comm items in .sbss, and not .bss. */
2101 ppc_elf_add_symbol_hook (abfd
, info
, sym
, namep
, flagsp
, secp
, valp
)
2103 struct bfd_link_info
*info
;
2104 const Elf_Internal_Sym
*sym
;
2110 if (sym
->st_shndx
== SHN_COMMON
&& !info
->relocateable
&& sym
->st_size
<= bfd_get_gp_size (abfd
))
2112 /* Common symbols less than or equal to -G nn bytes are automatically
2114 elf_linker_section_t
*sdata
= ppc_elf_create_linker_section (abfd
, info
, LINKER_SECTION_SDATA
);
2115 if (!sdata
->bss_section
)
2117 /* We don't go through bfd_make_section, because we don't
2118 want to attach this common section to DYNOBJ. The linker
2119 will move the symbols to the appropriate output section
2120 when it defines common symbols. */
2121 sdata
->bss_section
= ((asection
*)
2122 bfd_zalloc (abfd
, sizeof (asection
)));
2123 if (sdata
->bss_section
== NULL
)
2125 sdata
->bss_section
->name
= sdata
->bss_name
;
2126 sdata
->bss_section
->flags
= SEC_IS_COMMON
;
2127 sdata
->bss_section
->output_section
= sdata
->bss_section
;
2128 sdata
->bss_section
->symbol
=
2129 (asymbol
*) bfd_zalloc (abfd
, sizeof (asymbol
));
2130 sdata
->bss_section
->symbol_ptr_ptr
=
2131 (asymbol
**) bfd_zalloc (abfd
, sizeof (asymbol
*));
2132 if (sdata
->bss_section
->symbol
== NULL
2133 || sdata
->bss_section
->symbol_ptr_ptr
== NULL
)
2135 sdata
->bss_section
->symbol
->name
= sdata
->bss_name
;
2136 sdata
->bss_section
->symbol
->flags
= BSF_SECTION_SYM
;
2137 sdata
->bss_section
->symbol
->section
= sdata
->bss_section
;
2138 *sdata
->bss_section
->symbol_ptr_ptr
= sdata
->bss_section
->symbol
;
2141 *secp
= sdata
->bss_section
;
2142 *valp
= sym
->st_size
;
2149 /* Finish up dynamic symbol handling. We set the contents of various
2150 dynamic sections here. */
2153 ppc_elf_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
2155 struct bfd_link_info
*info
;
2156 struct elf_link_hash_entry
*h
;
2157 Elf_Internal_Sym
*sym
;
2162 fprintf (stderr
, "ppc_elf_finish_dynamic_symbol called for %s", h
->root
.root
.string
);
2165 dynobj
= elf_hash_table (info
)->dynobj
;
2166 BFD_ASSERT (dynobj
!= NULL
);
2168 if (h
->plt_offset
!= (bfd_vma
) -1)
2172 Elf_Internal_Rela rela
;
2175 fprintf (stderr
, ", plt_offset = %d", h
->plt_offset
);
2178 /* This symbol has an entry in the procedure linkage table. Set
2181 BFD_ASSERT (h
->dynindx
!= -1);
2183 splt
= bfd_get_section_by_name (dynobj
, ".plt");
2184 srela
= bfd_get_section_by_name (dynobj
, ".rela.plt");
2185 BFD_ASSERT (splt
!= NULL
&& srela
!= NULL
);
2187 /* We don't need to fill in the .plt. The solaris dynamic linker will
2190 /* Fill in the entry in the .rela.plt section. */
2191 rela
.r_offset
= (splt
->output_section
->vma
2192 + splt
->output_offset
2194 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_PPC_JMP_SLOT
);
2196 bfd_elf32_swap_reloca_out (output_bfd
, &rela
,
2197 ((Elf32_External_Rela
*) srela
->contents
2198 + ((h
->plt_offset
- PLT_INITIAL_ENTRY_SIZE
) / 8)));
2200 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
2202 /* Mark the symbol as undefined, rather than as defined in
2203 the .plt section. Leave the value alone. */
2204 sym
->st_shndx
= SHN_UNDEF
;
2208 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_COPY
) != 0)
2211 Elf_Internal_Rela rela
;
2213 /* This symbols needs a copy reloc. Set it up. */
2216 fprintf (stderr
, ", copy");
2219 BFD_ASSERT (h
->dynindx
!= -1);
2221 s
= bfd_get_section_by_name (h
->root
.u
.def
.section
->owner
,
2223 BFD_ASSERT (s
!= NULL
);
2225 rela
.r_offset
= (h
->root
.u
.def
.value
2226 + h
->root
.u
.def
.section
->output_section
->vma
2227 + h
->root
.u
.def
.section
->output_offset
);
2228 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_PPC_COPY
);
2230 bfd_elf32_swap_reloca_out (output_bfd
, &rela
,
2231 ((Elf32_External_Rela
*) s
->contents
2237 fprintf (stderr
, "\n");
2240 /* Mark some specially defined symbols as absolute. */
2241 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
2242 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0
2243 || strcmp (h
->root
.root
.string
, "_PROCEDURE_LINKAGE_TABLE_") == 0)
2244 sym
->st_shndx
= SHN_ABS
;
2250 /* Finish up the dynamic sections. */
2253 ppc_elf_finish_dynamic_sections (output_bfd
, info
)
2255 struct bfd_link_info
*info
;
2258 bfd
*dynobj
= elf_hash_table (info
)->dynobj
;
2259 elf_linker_section_t
*got
= elf_linker_section (dynobj
, LINKER_SECTION_GOT
);
2262 fprintf (stderr
, "ppc_elf_finish_dynamic_sections called\n");
2265 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
2267 if (elf_hash_table (info
)->dynamic_sections_created
)
2270 Elf32_External_Dyn
*dyncon
, *dynconend
;
2272 splt
= bfd_get_section_by_name (dynobj
, ".plt");
2273 BFD_ASSERT (splt
!= NULL
&& sdyn
!= NULL
);
2275 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
2276 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
2277 for (; dyncon
< dynconend
; dyncon
++)
2279 Elf_Internal_Dyn dyn
;
2283 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
2287 case DT_PLTGOT
: name
= ".plt"; size
= false; break;
2288 case DT_PLTRELSZ
: name
= ".rela.plt"; size
= true; break;
2289 case DT_JMPREL
: name
= ".rela.plt"; size
= false; break;
2290 default: name
= NULL
; size
= false; break;
2297 s
= bfd_get_section_by_name (output_bfd
, name
);
2303 dyn
.d_un
.d_ptr
= s
->vma
;
2306 if (s
->_cooked_size
!= 0)
2307 dyn
.d_un
.d_val
= s
->_cooked_size
;
2309 dyn
.d_un
.d_val
= s
->_raw_size
;
2312 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
2317 /* Add a blrl instruction at _GLOBAL_OFFSET_TABLE_-4 so that a function can
2318 easily find the address of the _GLOBAL_OFFSET_TABLE_. */
2321 unsigned char *contents
= got
->section
->contents
+ got
->hole_offset
;
2322 bfd_put_32 (output_bfd
, 0x4e800021 /* blrl */, contents
);
2325 bfd_put_32 (output_bfd
, (bfd_vma
) 0, contents
+4);
2327 bfd_put_32 (output_bfd
,
2328 sdyn
->output_section
->vma
+ sdyn
->output_offset
,
2331 elf_section_data (got
->section
->output_section
)->this_hdr
.sh_entsize
= 4;
2338 Elf_Internal_Sym sym
;
2340 /* Set up the section symbols for the output sections. */
2342 sdynsym
= bfd_get_section_by_name (dynobj
, ".dynsym");
2343 BFD_ASSERT (sdynsym
!= NULL
);
2347 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_SECTION
);
2350 for (s
= output_bfd
->sections
; s
!= NULL
; s
= s
->next
)
2354 sym
.st_value
= s
->vma
;
2356 indx
= elf_section_data (s
)->this_idx
;
2357 BFD_ASSERT (indx
> 0);
2358 sym
.st_shndx
= indx
;
2360 bfd_elf32_swap_symbol_out (output_bfd
, &sym
,
2361 (PTR
) (((Elf32_External_Sym
*)
2363 + elf_section_data (s
)->dynindx
));
2366 /* Set the sh_info field of the output .dynsym section to the
2367 index of the first global symbol. */
2368 elf_section_data (sdynsym
->output_section
)->this_hdr
.sh_info
=
2369 bfd_count_sections (output_bfd
) + 1;
2376 /* The RELOCATE_SECTION function is called by the ELF backend linker
2377 to handle the relocations for a section.
2379 The relocs are always passed as Rela structures; if the section
2380 actually uses Rel structures, the r_addend field will always be
2383 This function is responsible for adjust the section contents as
2384 necessary, and (if using Rela relocs and generating a
2385 relocateable output file) adjusting the reloc addend as
2388 This function does not have to worry about setting the reloc
2389 address or the reloc symbol index.
2391 LOCAL_SYMS is a pointer to the swapped in local symbols.
2393 LOCAL_SECTIONS is an array giving the section in the input file
2394 corresponding to the st_shndx field of each local symbol.
2396 The global hash table entry for the global symbols can be found
2397 via elf_sym_hashes (input_bfd).
2399 When generating relocateable output, this function must handle
2400 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
2401 going to be the section symbol corresponding to the output
2402 section, which means that the addend must be adjusted
2406 ppc_elf_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
2407 contents
, relocs
, local_syms
, local_sections
)
2409 struct bfd_link_info
*info
;
2411 asection
*input_section
;
2413 Elf_Internal_Rela
*relocs
;
2414 Elf_Internal_Sym
*local_syms
;
2415 asection
**local_sections
;
2417 Elf_Internal_Shdr
*symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
2418 struct elf_link_hash_entry
**sym_hashes
= elf_sym_hashes (input_bfd
);
2419 bfd
*dynobj
= elf_hash_table (info
)->dynobj
;
2420 elf_linker_section_t
*got
= (dynobj
) ? elf_linker_section (dynobj
, LINKER_SECTION_GOT
) : NULL
;
2421 elf_linker_section_t
*sdata
= (dynobj
) ? elf_linker_section (dynobj
, LINKER_SECTION_SDATA
) : NULL
;
2422 elf_linker_section_t
*sdata2
= (dynobj
) ? elf_linker_section (dynobj
, LINKER_SECTION_SDATA2
) : NULL
;
2423 Elf_Internal_Rela
*rel
= relocs
;
2424 Elf_Internal_Rela
*relend
= relocs
+ input_section
->reloc_count
;
2425 asection
*sreloc
= NULL
;
2430 fprintf (stderr
, "ppc_elf_relocate_section called for %s section %s, %ld relocations%s\n",
2431 bfd_get_filename (input_bfd
),
2432 bfd_section_name(input_bfd
, input_section
),
2433 (long)input_section
->reloc_count
,
2434 (info
->relocateable
) ? " (relocatable)" : "");
2437 if (!ppc_elf_howto_table
[ R_PPC_ADDR32
]) /* Initialize howto table if needed */
2438 ppc_elf_howto_init ();
2440 for (; rel
< relend
; rel
++)
2442 enum ppc_reloc_type r_type
= (enum ppc_reloc_type
)ELF32_R_TYPE (rel
->r_info
);
2443 bfd_vma offset
= rel
->r_offset
;
2444 bfd_vma addend
= rel
->r_addend
;
2445 bfd_reloc_status_type r
= bfd_reloc_other
;
2446 Elf_Internal_Sym
*sym
= (Elf_Internal_Sym
*)0;
2447 asection
*sec
= (asection
*)0;
2448 struct elf_link_hash_entry
*h
= (struct elf_link_hash_entry
*)0;
2449 const char *sym_name
= (const char *)0;
2450 reloc_howto_type
*howto
;
2451 unsigned long r_symndx
;
2454 /* Unknown relocation handling */
2455 if ((unsigned)r_type
>= (unsigned)R_PPC_max
|| !ppc_elf_howto_table
[(int)r_type
])
2457 (*_bfd_error_handler
) ("%s: unknown relocation type %d",
2458 bfd_get_filename (input_bfd
),
2461 bfd_set_error (bfd_error_bad_value
);
2466 howto
= ppc_elf_howto_table
[(int)r_type
];
2467 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2469 if (info
->relocateable
)
2471 /* This is a relocateable link. We don't have to change
2472 anything, unless the reloc is against a section symbol,
2473 in which case we have to adjust according to where the
2474 section symbol winds up in the output section. */
2475 if (r_symndx
< symtab_hdr
->sh_info
)
2477 sym
= local_syms
+ r_symndx
;
2478 if ((unsigned)ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
2480 sec
= local_sections
[r_symndx
];
2481 addend
= rel
->r_addend
+= sec
->output_offset
+ sym
->st_value
;
2486 fprintf (stderr
, "\ttype = %s (%d), symbol index = %ld, offset = %ld, addend = %ld\n",
2496 /* This is a final link. */
2497 if (r_symndx
< symtab_hdr
->sh_info
)
2499 sym
= local_syms
+ r_symndx
;
2500 sec
= local_sections
[r_symndx
];
2501 sym_name
= "<local symbol>";
2503 relocation
= (sec
->output_section
->vma
2504 + sec
->output_offset
2509 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2510 while (h
->root
.type
== bfd_link_hash_indirect
2511 || h
->root
.type
== bfd_link_hash_warning
)
2512 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2513 sym_name
= h
->root
.root
.string
;
2514 if (h
->root
.type
== bfd_link_hash_defined
2515 || h
->root
.type
== bfd_link_hash_defweak
)
2517 sec
= h
->root
.u
.def
.section
;
2518 if ((r_type
== R_PPC_PLT32
2519 && h
->plt_offset
!= (bfd_vma
) -1)
2520 || ((r_type
== R_PPC_GOT16
2521 || r_type
== R_PPC_GOT16_LO
2522 || r_type
== R_PPC_GOT16_HI
2523 || r_type
== R_PPC_GOT16_HA
)
2524 && elf_hash_table (info
)->dynamic_sections_created
2527 || (h
->elf_link_hash_flags
2528 & ELF_LINK_HASH_DEF_REGULAR
) == 0))
2530 && (! info
->symbolic
2531 || (h
->elf_link_hash_flags
2532 & ELF_LINK_HASH_DEF_REGULAR
) == 0)
2533 && (input_section
->flags
& SEC_ALLOC
) != 0
2534 && (r_type
== R_PPC_ADDR32
2535 || r_type
== R_PPC_ADDR24
2536 || r_type
== R_PPC_ADDR16
2537 || r_type
== R_PPC_ADDR16_LO
2538 || r_type
== R_PPC_ADDR16_HI
2539 || r_type
== R_PPC_ADDR16_HA
2540 || r_type
== R_PPC_ADDR14
2541 || r_type
== R_PPC_ADDR14_BRTAKEN
2542 || r_type
== R_PPC_ADDR14_BRNTAKEN
2543 || r_type
== R_PPC_PLTREL24
2544 || r_type
== R_PPC_COPY
2545 || r_type
== R_PPC_GLOB_DAT
2546 || r_type
== R_PPC_JMP_SLOT
2547 || r_type
== R_PPC_UADDR32
2548 || r_type
== R_PPC_UADDR16
2549 || r_type
== R_PPC_REL32
2550 || r_type
== R_PPC_SDAREL16
2551 || r_type
== R_PPC_EMB_NADDR32
2552 || r_type
== R_PPC_EMB_NADDR16
2553 || r_type
== R_PPC_EMB_NADDR16_LO
2554 || r_type
== R_PPC_EMB_NADDR16_HI
2555 || r_type
== R_PPC_EMB_NADDR16_HA
2556 || r_type
== R_PPC_EMB_SDAI16
2557 || r_type
== R_PPC_EMB_SDA2I16
2558 || r_type
== R_PPC_EMB_SDA2REL
2559 || r_type
== R_PPC_EMB_SDA21
2560 || r_type
== R_PPC_EMB_MRKREF
2561 || r_type
== R_PPC_EMB_BIT_FLD
2562 || r_type
== R_PPC_EMB_RELSDA
2563 || ((r_type
== R_PPC_REL24
2564 || r_type
== R_PPC_REL14
2565 || r_type
== R_PPC_REL14_BRTAKEN
2566 || r_type
== R_PPC_REL14_BRNTAKEN
2567 || r_type
== R_PPC_RELATIVE
)
2568 && strcmp (h
->root
.root
.string
,
2569 "_GLOBAL_OFFSET_TABLE_") != 0))))
2571 /* In these cases, we don't need the relocation
2572 value. We check specially because in some
2573 obscure cases sec->output_section will be NULL. */
2577 relocation
= (h
->root
.u
.def
.value
2578 + sec
->output_section
->vma
2579 + sec
->output_offset
);
2581 else if (h
->root
.type
== bfd_link_hash_undefweak
)
2583 else if (info
->shared
)
2587 (*info
->callbacks
->undefined_symbol
)(info
,
2588 h
->root
.root
.string
,
2597 switch ((int)r_type
)
2600 (*_bfd_error_handler
) ("%s: unknown relocation type %d for symbol %s",
2601 bfd_get_filename (input_bfd
),
2602 (int)r_type
, sym_name
);
2604 bfd_set_error (bfd_error_bad_value
);
2608 /* relocations that need no special processing */
2609 case (int)R_PPC_LOCAL24PC
:
2612 case (int)R_PPC_REL24
:
2613 case (int)R_PPC_REL14
:
2615 && strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
2619 /* Relocations that need to be propigated if this is a shared object */
2620 case (int)R_PPC_NONE
:
2621 case (int)R_PPC_ADDR32
:
2622 case (int)R_PPC_ADDR24
:
2623 case (int)R_PPC_ADDR16
:
2624 case (int)R_PPC_ADDR16_LO
:
2625 case (int)R_PPC_ADDR16_HI
:
2626 case (int)R_PPC_ADDR14
:
2627 case (int)R_PPC_UADDR32
:
2628 case (int)R_PPC_UADDR16
:
2629 case (int)R_PPC_REL32
:
2630 case (int)R_PPC_PLTREL24
:
2632 && (input_section
->flags
& SEC_ALLOC
) != 0)
2634 Elf_Internal_Rela outrel
;
2637 fprintf (stderr
, "ppc_elf_relocate_section need to create relocation for %s\n",
2638 (h
&& h
->root
.root
.string
) ? h
->root
.root
.string
: "<unknown>");
2641 /* When generating a shared object, these relocations
2642 are copied into the output file to be resolved at run
2649 name
= (bfd_elf_string_from_elf_section
2651 elf_elfheader (input_bfd
)->e_shstrndx
,
2652 elf_section_data (input_section
)->rel_hdr
.sh_name
));
2656 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
2657 && strcmp (bfd_get_section_name (input_bfd
,
2661 sreloc
= bfd_get_section_by_name (dynobj
, name
);
2662 BFD_ASSERT (sreloc
!= NULL
);
2665 outrel
.r_offset
= (rel
->r_offset
2666 + input_section
->output_section
->vma
2667 + input_section
->output_offset
);
2669 && (! info
->symbolic
2670 || (h
->elf_link_hash_flags
2671 & ELF_LINK_HASH_DEF_REGULAR
) == 0))
2673 BFD_ASSERT (h
->dynindx
!= -1);
2674 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
2675 outrel
.r_addend
= rel
->r_addend
;
2679 if (r_type
== R_PPC_ADDR32
)
2681 outrel
.r_info
= ELF32_R_INFO (0, R_PPC_RELATIVE
);
2682 outrel
.r_addend
= relocation
+ rel
->r_addend
;
2689 sec
= local_sections
[r_symndx
];
2692 BFD_ASSERT (h
->root
.type
== bfd_link_hash_defined
2694 == bfd_link_hash_defweak
));
2695 sec
= h
->root
.u
.def
.section
;
2697 if (sec
!= NULL
&& bfd_is_abs_section (sec
))
2699 else if (sec
== NULL
|| sec
->owner
== NULL
)
2701 bfd_set_error (bfd_error_bad_value
);
2708 osec
= sec
->output_section
;
2709 indx
= elf_section_data (osec
)->dynindx
;
2714 outrel
.r_info
= ELF32_R_INFO (indx
, r_type
);
2715 outrel
.r_addend
= relocation
+ rel
->r_addend
;
2719 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
,
2720 (((Elf32_External_Rela
*)
2722 + sreloc
->reloc_count
));
2723 ++sreloc
->reloc_count
;
2725 /* This reloc will be computed at runtime, so there's no
2726 need to do anything now. */
2731 /* branch taken prediction relocations */
2732 case (int)R_PPC_ADDR14_BRTAKEN
:
2733 case (int)R_PPC_REL14_BRTAKEN
:
2734 insn
= bfd_get_32 (output_bfd
, contents
+ offset
);
2735 if ((relocation
- offset
) & 0x8000)
2736 insn
&= ~BRANCH_PREDICT_BIT
;
2738 insn
|= BRANCH_PREDICT_BIT
;
2739 bfd_put_32 (output_bfd
, insn
, contents
+ offset
);
2742 /* branch not taken predicition relocations */
2743 case (int)R_PPC_ADDR14_BRNTAKEN
:
2744 case (int)R_PPC_REL14_BRNTAKEN
:
2745 insn
= bfd_get_32 (output_bfd
, contents
+ offset
);
2746 if ((relocation
- offset
) & 0x8000)
2747 insn
|= BRANCH_PREDICT_BIT
;
2749 insn
&= ~BRANCH_PREDICT_BIT
;
2750 bfd_put_32 (output_bfd
, insn
, contents
+ offset
);
2753 /* GOT16 relocations */
2754 case (int)R_PPC_GOT16
:
2755 case (int)R_PPC_GOT16_LO
:
2756 case (int)R_PPC_GOT16_HI
:
2757 case (int)R_PPC_GOT16_HA
:
2758 relocation
= bfd_elf32_finish_pointer_linker_section (output_bfd
, input_bfd
, info
,
2759 got
, h
, relocation
, rel
,
2763 /* Indirect .sdata relocation */
2764 case (int)R_PPC_EMB_SDAI16
:
2765 BFD_ASSERT (sdata
!= NULL
);
2766 relocation
= bfd_elf32_finish_pointer_linker_section (output_bfd
, input_bfd
, info
,
2767 sdata
, h
, relocation
, rel
,
2771 /* Indirect .sdata2 relocation */
2772 case (int)R_PPC_EMB_SDA2I16
:
2773 BFD_ASSERT (sdata2
!= NULL
);
2774 relocation
= bfd_elf32_finish_pointer_linker_section (output_bfd
, input_bfd
, info
,
2775 sdata2
, h
, relocation
, rel
,
2779 /* Handle the TOC16 reloc. We want to use the offset within the .got
2780 section, not the actual VMA. This is appropriate when generating
2781 an embedded ELF object, for which the .got section acts like the
2782 AIX .toc section. */
2783 case (int)R_PPC_TOC16
: /* phony GOT16 relocations */
2784 BFD_ASSERT (sec
!= (asection
*)0);
2785 BFD_ASSERT (bfd_is_und_section (sec
)
2786 || strcmp (bfd_get_section_name (abfd
, sec
), ".got") == 0
2787 || strcmp (bfd_get_section_name (abfd
, sec
), ".cgot") == 0)
2789 addend
-= sec
->output_section
->vma
+ sec
->output_offset
+ 0x8000;
2792 /* arithmetic adjust relocations */
2793 case (int)R_PPC_ADDR16_HA
:
2794 BFD_ASSERT (sec
!= (asection
*)0);
2795 addend
+= ((relocation
+ addend
) & 0x8000) << 1;
2798 /* relocate against _SDA_BASE_ */
2799 case (int)R_PPC_SDAREL16
:
2800 BFD_ASSERT (sec
!= (asection
*)0);
2801 if (strcmp (bfd_get_section_name (abfd
, sec
), ".sdata") != 0
2802 && strcmp (bfd_get_section_name (abfd
, sec
), ".sbss") != 0)
2804 (*_bfd_error_handler
) ("%s: The target (%s) of a %s relocation is in the wrong section (%s)",
2805 bfd_get_filename (input_bfd
),
2807 ppc_elf_howto_table
[ (int)r_type
]->name
,
2808 bfd_get_section_name (abfd
, sec
));
2810 bfd_set_error (bfd_error_bad_value
);
2814 addend
-= (sdata
->sym_hash
->root
.u
.def
.value
2815 + sdata
->sym_hash
->root
.u
.def
.section
->output_section
->vma
2816 + sdata
->sym_hash
->root
.u
.def
.section
->output_offset
);
2820 /* relocate against _SDA2_BASE_ */
2821 case (int)R_PPC_EMB_SDA2REL
:
2822 BFD_ASSERT (sec
!= (asection
*)0);
2823 if (strcmp (bfd_get_section_name (abfd
, sec
), ".sdata2") != 0
2824 && strcmp (bfd_get_section_name (abfd
, sec
), ".sbss2") != 0)
2826 (*_bfd_error_handler
) ("%s: The target (%s) of a %s relocation is in the wrong section (%s)",
2827 bfd_get_filename (input_bfd
),
2829 ppc_elf_howto_table
[ (int)r_type
]->name
,
2830 bfd_get_section_name (abfd
, sec
));
2832 bfd_set_error (bfd_error_bad_value
);
2836 addend
-= (sdata2
->sym_hash
->root
.u
.def
.value
2837 + sdata2
->sym_hash
->root
.u
.def
.section
->output_section
->vma
2838 + sdata2
->sym_hash
->root
.u
.def
.section
->output_offset
);
2842 /* relocate against either _SDA_BASE_, _SDA2_BASE_, or 0 */
2843 case (int)R_PPC_EMB_SDA21
:
2844 case (int)R_PPC_EMB_RELSDA
:
2846 const char *name
= bfd_get_section_name (abfd
, sec
);
2849 BFD_ASSERT (sec
!= (asection
*)0);
2850 if (strcmp (name
, ".sdata") == 0 || strcmp (name
, ".sbss") == 0)
2853 addend
-= (sdata
->sym_hash
->root
.u
.def
.value
2854 + sdata
->sym_hash
->root
.u
.def
.section
->output_section
->vma
2855 + sdata
->sym_hash
->root
.u
.def
.section
->output_offset
);
2858 else if (strcmp (name
, ".sdata2") == 0 || strcmp (name
, ".sbss2") == 0)
2861 addend
-= (sdata2
->sym_hash
->root
.u
.def
.value
2862 + sdata2
->sym_hash
->root
.u
.def
.section
->output_section
->vma
2863 + sdata2
->sym_hash
->root
.u
.def
.section
->output_offset
);
2866 else if (strcmp (name
, ".PPC.EMB.sdata0") == 0 || strcmp (name
, ".PPC.EMB.sbss0") == 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
);
2884 if (r_type
== R_PPC_EMB_SDA21
)
2885 { /* fill in register field */
2886 insn
= bfd_get_32 (output_bfd
, contents
+ offset
);
2887 insn
= (insn
& ~RA_REGISTER_MASK
) | (reg
<< RA_REGISTER_SHIFT
);
2888 bfd_put_32 (output_bfd
, insn
, contents
+ offset
);
2893 /* Relocate against the beginning of the section */
2894 case (int)R_PPC_SECTOFF
:
2895 case (int)R_PPC_SECTOFF_LO
:
2896 case (int)R_PPC_SECTOFF_HI
:
2897 BFD_ASSERT (sec
!= (asection
*)0);
2898 addend
-= sec
->output_section
->vma
;
2901 case (int)R_PPC_SECTOFF_HA
:
2902 BFD_ASSERT (sec
!= (asection
*)0);
2903 addend
-= sec
->output_section
->vma
;
2904 addend
+= ((relocation
+ addend
) & 0x8000) << 1;
2907 /* Negative relocations */
2908 case (int)R_PPC_EMB_NADDR32
:
2909 case (int)R_PPC_EMB_NADDR16
:
2910 case (int)R_PPC_EMB_NADDR16_LO
:
2911 case (int)R_PPC_EMB_NADDR16_HI
:
2912 addend
-= 2*relocation
;
2915 case (int)R_PPC_EMB_NADDR16_HA
:
2916 addend
-= 2*relocation
;
2917 addend
+= ((relocation
+ addend
) & 0x8000) << 1;
2920 /* NOP relocation that prevents garbage collecting linkers from omitting a
2922 case (int)R_PPC_EMB_MRKREF
:
2925 case (int)R_PPC_COPY
:
2926 case (int)R_PPC_GLOB_DAT
:
2927 case (int)R_PPC_JMP_SLOT
:
2928 case (int)R_PPC_RELATIVE
:
2929 case (int)R_PPC_PLT32
:
2930 case (int)R_PPC_PLTREL32
:
2931 case (int)R_PPC_PLT16_LO
:
2932 case (int)R_PPC_PLT16_HI
:
2933 case (int)R_PPC_PLT16_HA
:
2934 case (int)R_PPC_EMB_RELSEC16
:
2935 case (int)R_PPC_EMB_RELST_LO
:
2936 case (int)R_PPC_EMB_RELST_HI
:
2937 case (int)R_PPC_EMB_RELST_HA
:
2938 case (int)R_PPC_EMB_BIT_FLD
:
2939 (*_bfd_error_handler
) ("%s: Relocation %s is not yet supported for symbol %s.",
2940 bfd_get_filename (input_bfd
),
2941 ppc_elf_howto_table
[ (int)r_type
]->name
,
2944 bfd_set_error (bfd_error_invalid_operation
);
2951 fprintf (stderr
, "\ttype = %s (%d), name = %s, symbol index = %ld, offset = %ld, addend = %ld\n",
2960 r
= _bfd_final_link_relocate (howto
,
2968 if (r
!= bfd_reloc_ok
)
2976 case bfd_reloc_overflow
:
2981 name
= h
->root
.root
.string
;
2984 name
= bfd_elf_string_from_elf_section (input_bfd
,
2985 symtab_hdr
->sh_link
,
2991 name
= bfd_section_name (input_bfd
, sec
);
2994 (*info
->callbacks
->reloc_overflow
)(info
,
3010 fprintf (stderr
, "\n");
3017 #define TARGET_LITTLE_SYM bfd_elf32_powerpcle_vec
3018 #define TARGET_LITTLE_NAME "elf32-powerpcle"
3019 #define TARGET_BIG_SYM bfd_elf32_powerpc_vec
3020 #define TARGET_BIG_NAME "elf32-powerpc"
3021 #define ELF_ARCH bfd_arch_powerpc
3022 #define ELF_MACHINE_CODE EM_PPC
3023 #define ELF_MAXPAGESIZE 0x10000
3024 #define elf_info_to_howto ppc_elf_info_to_howto
3026 #ifdef EM_CYGNUS_POWERPC
3027 #define ELF_MACHINE_ALT1 EM_CYGNUS_POWERPC
3031 #define ELF_MACHINE_ALT2 EM_PPC_OLD
3034 #define bfd_elf32_bfd_copy_private_bfd_data ppc_elf_copy_private_bfd_data
3035 #define bfd_elf32_bfd_merge_private_bfd_data ppc_elf_merge_private_bfd_data
3036 #define bfd_elf32_bfd_set_private_flags ppc_elf_set_private_flags
3037 #define bfd_elf32_bfd_reloc_type_lookup ppc_elf_reloc_type_lookup
3038 #define elf_backend_section_from_shdr ppc_elf_section_from_shdr
3039 #define elf_backend_relocate_section ppc_elf_relocate_section
3040 #define elf_backend_create_dynamic_sections _bfd_elf_create_dynamic_sections
3041 #define elf_backend_check_relocs ppc_elf_check_relocs
3042 #define elf_backend_adjust_dynamic_symbol ppc_elf_adjust_dynamic_symbol
3043 #define elf_backend_add_symbol_hook ppc_elf_add_symbol_hook
3044 #define elf_backend_size_dynamic_sections ppc_elf_size_dynamic_sections
3045 #define elf_backend_finish_dynamic_symbol ppc_elf_finish_dynamic_symbol
3046 #define elf_backend_finish_dynamic_sections ppc_elf_finish_dynamic_sections
3047 #define elf_backend_fake_sections ppc_elf_fake_sections
3048 #define elf_backend_additional_program_headers ppc_elf_additional_program_headers
3049 #define elf_backend_modify_segment_map ppc_elf_modify_segment_map
3051 #include "elf32-target.h"