1 /* PowerPC-specific support for 32-bit ELF
2 Copyright 1994, 1995, 1996 Free Software Foundation, Inc.
3 Written by Ian Lance Taylor, Cygnus Support.
5 This file is part of BFD, the Binary File Descriptor library.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
21 /* This file is based on a preliminary PowerPC ELF ABI. The
22 information may not match the final PowerPC ELF ABI. It includes
23 suggestions from the in-progress Embedded PowerPC ABI, and that
24 information may also not match. */
33 #define USE_RELA /* we want RELA relocations, not REL */
35 /* PowerPC relocations defined by the ABIs */
46 R_PPC_ADDR14_BRTAKEN
= 8,
47 R_PPC_ADDR14_BRNTAKEN
= 9,
50 R_PPC_REL14_BRTAKEN
= 12,
51 R_PPC_REL14_BRNTAKEN
= 13,
72 R_PPC_SECTOFF_LO
= 34,
73 R_PPC_SECTOFF_HI
= 35,
74 R_PPC_SECTOFF_HA
= 36,
76 /* The remaining relocs are from the Embedded ELF ABI, and are not
77 in the SVR4 ELF ABI. */
78 R_PPC_EMB_NADDR32
= 101,
79 R_PPC_EMB_NADDR16
= 102,
80 R_PPC_EMB_NADDR16_LO
= 103,
81 R_PPC_EMB_NADDR16_HI
= 104,
82 R_PPC_EMB_NADDR16_HA
= 105,
83 R_PPC_EMB_SDAI16
= 106,
84 R_PPC_EMB_SDA2I16
= 107,
85 R_PPC_EMB_SDA2REL
= 108,
86 R_PPC_EMB_SDA21
= 109,
87 R_PPC_EMB_MRKREF
= 110,
88 R_PPC_EMB_RELSEC16
= 111,
89 R_PPC_EMB_RELST_LO
= 112,
90 R_PPC_EMB_RELST_HI
= 113,
91 R_PPC_EMB_RELST_HA
= 114,
92 R_PPC_EMB_BIT_FLD
= 115,
93 R_PPC_EMB_RELSDA
= 116,
95 /* This is a phony reloc to handle any old fashioned TOC16 references
96 that may still be in object files. */
102 static reloc_howto_type
*ppc_elf_reloc_type_lookup
103 PARAMS ((bfd
*abfd
, bfd_reloc_code_real_type code
));
104 static void ppc_elf_info_to_howto
105 PARAMS ((bfd
*abfd
, arelent
*cache_ptr
, Elf32_Internal_Rela
*dst
));
106 static void ppc_elf_howto_init
PARAMS ((void));
107 static boolean ppc_elf_set_private_flags
PARAMS ((bfd
*, flagword
));
108 static boolean ppc_elf_copy_private_bfd_data
PARAMS ((bfd
*, bfd
*));
109 static boolean ppc_elf_merge_private_bfd_data
PARAMS ((bfd
*, bfd
*));
111 static int ppc_elf_additional_program_headers
PARAMS ((bfd
*));
112 static boolean ppc_elf_modify_segment_map
PARAMS ((bfd
*));
114 static boolean ppc_elf_section_from_shdr
PARAMS ((bfd
*,
115 Elf32_Internal_Shdr
*,
118 static elf_linker_section_t
*ppc_elf_create_linker_section
120 struct bfd_link_info
*info
,
121 enum elf_linker_section_enum
));
123 static boolean ppc_elf_check_relocs
PARAMS ((bfd
*,
124 struct bfd_link_info
*,
126 const Elf_Internal_Rela
*));
128 static boolean ppc_elf_adjust_dynamic_symbol
PARAMS ((struct bfd_link_info
*,
129 struct elf_link_hash_entry
*));
131 static boolean ppc_elf_adjust_dynindx
PARAMS ((struct elf_link_hash_entry
*, PTR
));
133 static boolean ppc_elf_size_dynamic_sections
PARAMS ((bfd
*, struct bfd_link_info
*));
135 static boolean ppc_elf_relocate_section
PARAMS ((bfd
*,
136 struct bfd_link_info
*info
,
140 Elf_Internal_Rela
*relocs
,
141 Elf_Internal_Sym
*local_syms
,
144 static boolean ppc_elf_add_symbol_hook
PARAMS ((bfd
*,
145 struct bfd_link_info
*,
146 const Elf_Internal_Sym
*,
152 static boolean ppc_elf_finish_dynamic_symbol
PARAMS ((bfd
*,
153 struct bfd_link_info
*,
154 struct elf_link_hash_entry
*,
155 Elf_Internal_Sym
*));
157 static boolean ppc_elf_finish_dynamic_sections
PARAMS ((bfd
*, struct bfd_link_info
*));
159 #define BRANCH_PREDICT_BIT 0x200000 /* branch prediction bit for branch taken relocs */
160 #define RA_REGISTER_MASK 0x001f0000 /* mask to set RA in memory instructions */
161 #define RA_REGISTER_SHIFT 16 /* value to shift register by to insert RA */
163 /* The name of the dynamic interpreter. This is put in the .interp
166 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
168 /* The size in bytes of an entry in the procedure linkage table, and of the initial size
169 of the plt reserved for the dynamic linker. */
171 #define PLT_ENTRY_SIZE 12
172 #define PLT_INITIAL_ENTRY_SIZE 72
175 static reloc_howto_type
*ppc_elf_howto_table
[ (int)R_PPC_max
];
177 static reloc_howto_type ppc_elf_howto_raw
[] =
179 /* This reloc does nothing. */
180 HOWTO (R_PPC_NONE
, /* type */
182 2, /* size (0 = byte, 1 = short, 2 = long) */
184 false, /* pc_relative */
186 complain_overflow_bitfield
, /* complain_on_overflow */
187 bfd_elf_generic_reloc
, /* special_function */
188 "R_PPC_NONE", /* name */
189 false, /* partial_inplace */
192 false), /* pcrel_offset */
194 /* A standard 32 bit relocation. */
195 HOWTO (R_PPC_ADDR32
, /* type */
197 2, /* size (0 = byte, 1 = short, 2 = long) */
199 false, /* pc_relative */
201 complain_overflow_bitfield
, /* complain_on_overflow */
202 bfd_elf_generic_reloc
, /* special_function */
203 "R_PPC_ADDR32", /* name */
204 false, /* partial_inplace */
206 0xffffffff, /* dst_mask */
207 false), /* pcrel_offset */
209 /* An absolute 26 bit branch; the lower two bits must be zero.
210 FIXME: we don't check that, we just clear them. */
211 HOWTO (R_PPC_ADDR24
, /* type */
213 2, /* size (0 = byte, 1 = short, 2 = long) */
215 false, /* pc_relative */
217 complain_overflow_bitfield
, /* complain_on_overflow */
218 bfd_elf_generic_reloc
, /* special_function */
219 "R_PPC_ADDR24", /* name */
220 false, /* partial_inplace */
222 0x3fffffc, /* dst_mask */
223 false), /* pcrel_offset */
225 /* A standard 16 bit relocation. */
226 HOWTO (R_PPC_ADDR16
, /* type */
228 1, /* size (0 = byte, 1 = short, 2 = long) */
230 false, /* pc_relative */
232 complain_overflow_bitfield
, /* complain_on_overflow */
233 bfd_elf_generic_reloc
, /* special_function */
234 "R_PPC_ADDR16", /* name */
235 false, /* partial_inplace */
237 0xffff, /* dst_mask */
238 false), /* pcrel_offset */
240 /* A 16 bit relocation without overflow. */
241 HOWTO (R_PPC_ADDR16_LO
, /* type */
243 1, /* size (0 = byte, 1 = short, 2 = long) */
245 false, /* pc_relative */
247 complain_overflow_dont
,/* complain_on_overflow */
248 bfd_elf_generic_reloc
, /* special_function */
249 "R_PPC_ADDR16_LO", /* name */
250 false, /* partial_inplace */
252 0xffff, /* dst_mask */
253 false), /* pcrel_offset */
255 /* The high order 16 bits of an address. */
256 HOWTO (R_PPC_ADDR16_HI
, /* type */
258 1, /* size (0 = byte, 1 = short, 2 = long) */
260 false, /* pc_relative */
262 complain_overflow_dont
, /* complain_on_overflow */
263 bfd_elf_generic_reloc
, /* special_function */
264 "R_PPC_ADDR16_HI", /* name */
265 false, /* partial_inplace */
267 0xffff, /* dst_mask */
268 false), /* pcrel_offset */
270 /* The high order 16 bits of an address, plus 1 if the contents of
271 the low 16 bits, treated as a signed number, is negative. */
272 HOWTO (R_PPC_ADDR16_HA
, /* type */
274 1, /* size (0 = byte, 1 = short, 2 = long) */
276 false, /* pc_relative */
278 complain_overflow_dont
, /* complain_on_overflow */
279 bfd_elf_generic_reloc
, /* special_function */
280 "R_PPC_ADDR16_HA", /* name */
281 false, /* partial_inplace */
283 0xffff, /* dst_mask */
284 false), /* pcrel_offset */
286 /* An absolute 16 bit branch; the lower two bits must be zero.
287 FIXME: we don't check that, we just clear them. */
288 HOWTO (R_PPC_ADDR14
, /* type */
290 2, /* size (0 = byte, 1 = short, 2 = long) */
292 false, /* pc_relative */
294 complain_overflow_bitfield
, /* complain_on_overflow */
295 bfd_elf_generic_reloc
, /* special_function */
296 "R_PPC_ADDR14", /* name */
297 false, /* partial_inplace */
299 0xfffc, /* dst_mask */
300 false), /* pcrel_offset */
302 /* An absolute 16 bit branch, for which bit 10 should be set to
303 indicate that the branch is expected to be taken. The lower two
304 bits must be zero. */
305 HOWTO (R_PPC_ADDR14_BRTAKEN
, /* type */
307 2, /* size (0 = byte, 1 = short, 2 = long) */
309 false, /* pc_relative */
311 complain_overflow_bitfield
, /* complain_on_overflow */
312 bfd_elf_generic_reloc
, /* special_function */
313 "R_PPC_ADDR14_BRTAKEN",/* name */
314 false, /* partial_inplace */
316 0xfffc, /* dst_mask */
317 false), /* pcrel_offset */
319 /* An absolute 16 bit branch, for which bit 10 should be set to
320 indicate that the branch is not expected to be taken. The lower
321 two bits must be zero. */
322 HOWTO (R_PPC_ADDR14_BRNTAKEN
, /* type */
324 2, /* size (0 = byte, 1 = short, 2 = long) */
326 false, /* pc_relative */
328 complain_overflow_bitfield
, /* complain_on_overflow */
329 bfd_elf_generic_reloc
, /* special_function */
330 "R_PPC_ADDR14_BRNTAKEN",/* name */
331 false, /* partial_inplace */
333 0xfffc, /* dst_mask */
334 false), /* pcrel_offset */
336 /* A relative 26 bit branch; the lower two bits must be zero. */
337 HOWTO (R_PPC_REL24
, /* type */
339 2, /* size (0 = byte, 1 = short, 2 = long) */
341 true, /* pc_relative */
343 complain_overflow_signed
, /* complain_on_overflow */
344 bfd_elf_generic_reloc
, /* special_function */
345 "R_PPC_REL24", /* name */
346 false, /* partial_inplace */
348 0x3fffffc, /* dst_mask */
349 true), /* pcrel_offset */
351 /* A relative 16 bit branch; the lower two bits must be zero. */
352 HOWTO (R_PPC_REL14
, /* type */
354 2, /* size (0 = byte, 1 = short, 2 = long) */
356 true, /* pc_relative */
358 complain_overflow_signed
, /* complain_on_overflow */
359 bfd_elf_generic_reloc
, /* special_function */
360 "R_PPC_REL14", /* name */
361 false, /* partial_inplace */
363 0xfffc, /* dst_mask */
364 true), /* pcrel_offset */
366 /* A relative 16 bit branch. Bit 10 should be set to indicate that
367 the branch is expected to be taken. The lower two bits must be
369 HOWTO (R_PPC_REL14_BRTAKEN
, /* type */
371 2, /* size (0 = byte, 1 = short, 2 = long) */
373 true, /* pc_relative */
375 complain_overflow_signed
, /* complain_on_overflow */
376 bfd_elf_generic_reloc
, /* special_function */
377 "R_PPC_REL14_BRTAKEN", /* name */
378 false, /* partial_inplace */
380 0xfffc, /* dst_mask */
381 true), /* pcrel_offset */
383 /* A relative 16 bit branch. Bit 10 should be set to indicate that
384 the branch is not expected to be taken. The lower two bits must
386 HOWTO (R_PPC_REL14_BRNTAKEN
, /* type */
388 2, /* size (0 = byte, 1 = short, 2 = long) */
390 true, /* pc_relative */
392 complain_overflow_signed
, /* complain_on_overflow */
393 bfd_elf_generic_reloc
, /* special_function */
394 "R_PPC_REL14_BRNTAKEN",/* name */
395 false, /* partial_inplace */
397 0xfffc, /* dst_mask */
398 true), /* pcrel_offset */
400 /* Like R_PPC_ADDR16, but referring to the GOT table entry for the
402 HOWTO (R_PPC_GOT16
, /* type */
404 1, /* size (0 = byte, 1 = short, 2 = long) */
406 false, /* pc_relative */
408 complain_overflow_signed
, /* complain_on_overflow */
409 bfd_elf_generic_reloc
, /* special_function */
410 "R_PPC_GOT16", /* name */
411 false, /* partial_inplace */
413 0xffff, /* dst_mask */
414 false), /* pcrel_offset */
416 /* Like R_PPC_ADDR16_LO, but referring to the GOT table entry for
418 HOWTO (R_PPC_GOT16_LO
, /* type */
420 1, /* size (0 = byte, 1 = short, 2 = long) */
422 false, /* pc_relative */
424 complain_overflow_bitfield
, /* complain_on_overflow */
425 bfd_elf_generic_reloc
, /* special_function */
426 "R_PPC_GOT16_LO", /* name */
427 false, /* partial_inplace */
429 0xffff, /* dst_mask */
430 false), /* pcrel_offset */
432 /* Like R_PPC_ADDR16_HI, but referring to the GOT table entry for
434 HOWTO (R_PPC_GOT16_HI
, /* type */
436 1, /* size (0 = byte, 1 = short, 2 = long) */
438 false, /* pc_relative */
440 complain_overflow_bitfield
, /* complain_on_overflow */
441 bfd_elf_generic_reloc
, /* special_function */
442 "R_PPC_GOT16_HI", /* name */
443 false, /* partial_inplace */
445 0xffff, /* dst_mask */
446 false), /* pcrel_offset */
448 /* Like R_PPC_ADDR16_HA, but referring to the GOT table entry for
450 HOWTO (R_PPC_GOT16_HA
, /* type */
452 1, /* size (0 = byte, 1 = short, 2 = long) */
454 false, /* pc_relative */
456 complain_overflow_bitfield
, /* complain_on_overflow */
457 bfd_elf_generic_reloc
, /* special_function */
458 "R_PPC_GOT16_HA", /* name */
459 false, /* partial_inplace */
461 0xffff, /* dst_mask */
462 false), /* pcrel_offset */
464 /* Like R_PPC_REL24, but referring to the procedure linkage table
465 entry for the symbol. FIXME: Not supported. */
466 HOWTO (R_PPC_PLTREL24
, /* type */
468 2, /* size (0 = byte, 1 = short, 2 = long) */
470 true, /* pc_relative */
472 complain_overflow_signed
, /* complain_on_overflow */
473 bfd_elf_generic_reloc
, /* special_function */
474 "R_PPC_PLTREL24", /* name */
475 false, /* partial_inplace */
477 0x3fffffc, /* dst_mask */
478 true), /* pcrel_offset */
480 /* This is used only by the dynamic linker. The symbol should exist
481 both in the object being run and in some shared library. The
482 dynamic linker copies the data addressed by the symbol from the
483 shared library into the object. I have no idea what the purpose
485 HOWTO (R_PPC_COPY
, /* type */
487 2, /* size (0 = byte, 1 = short, 2 = long) */
489 false, /* pc_relative */
491 complain_overflow_bitfield
, /* complain_on_overflow */
492 bfd_elf_generic_reloc
, /* special_function */
493 "R_PPC_COPY", /* name */
494 false, /* partial_inplace */
497 false), /* pcrel_offset */
499 /* Like R_PPC_ADDR32, but used when setting global offset table
501 HOWTO (R_PPC_GLOB_DAT
, /* type */
503 2, /* size (0 = byte, 1 = short, 2 = long) */
505 false, /* pc_relative */
507 complain_overflow_bitfield
, /* complain_on_overflow */
508 bfd_elf_generic_reloc
, /* special_function */
509 "R_PPC_GLOB_DAT", /* name */
510 false, /* partial_inplace */
512 0xffffffff, /* dst_mask */
513 false), /* pcrel_offset */
515 /* Marks a procedure linkage table entry for a symbol. */
516 HOWTO (R_PPC_JMP_SLOT
, /* type */
518 2, /* size (0 = byte, 1 = short, 2 = long) */
520 false, /* pc_relative */
522 complain_overflow_bitfield
, /* complain_on_overflow */
523 bfd_elf_generic_reloc
, /* special_function */
524 "R_PPC_JMP_SLOT", /* name */
525 false, /* partial_inplace */
528 false), /* pcrel_offset */
530 /* Used only by the dynamic linker. When the object is run, this
531 longword is set to the load address of the object, plus the
533 HOWTO (R_PPC_RELATIVE
, /* type */
535 2, /* size (0 = byte, 1 = short, 2 = long) */
537 false, /* pc_relative */
539 complain_overflow_bitfield
, /* complain_on_overflow */
540 bfd_elf_generic_reloc
, /* special_function */
541 "R_PPC_RELATIVE", /* name */
542 false, /* partial_inplace */
544 0xffffffff, /* dst_mask */
545 false), /* pcrel_offset */
547 /* Like R_PPC_REL24, but uses the value of the symbol within the
548 object rather than the final value. Normally used for
549 _GLOBAL_OFFSET_TABLE_. FIXME: Not supported. */
550 HOWTO (R_PPC_LOCAL24PC
, /* type */
552 2, /* size (0 = byte, 1 = short, 2 = long) */
554 true, /* pc_relative */
556 complain_overflow_signed
, /* complain_on_overflow */
557 bfd_elf_generic_reloc
, /* special_function */
558 "R_PPC_LOCAL24PC", /* name */
559 false, /* partial_inplace */
561 0x3fffffc, /* dst_mask */
562 true), /* pcrel_offset */
564 /* Like R_PPC_ADDR32, but may be unaligned. */
565 HOWTO (R_PPC_UADDR32
, /* type */
567 2, /* size (0 = byte, 1 = short, 2 = long) */
569 false, /* pc_relative */
571 complain_overflow_bitfield
, /* complain_on_overflow */
572 bfd_elf_generic_reloc
, /* special_function */
573 "R_PPC_UADDR32", /* name */
574 false, /* partial_inplace */
576 0xffffffff, /* dst_mask */
577 false), /* pcrel_offset */
579 /* Like R_PPC_ADDR16, but may be unaligned. */
580 HOWTO (R_PPC_UADDR16
, /* type */
582 1, /* size (0 = byte, 1 = short, 2 = long) */
584 false, /* pc_relative */
586 complain_overflow_bitfield
, /* complain_on_overflow */
587 bfd_elf_generic_reloc
, /* special_function */
588 "R_PPC_UADDR16", /* name */
589 false, /* partial_inplace */
591 0xffff, /* dst_mask */
592 false), /* pcrel_offset */
594 /* 32-bit PC relative */
595 HOWTO (R_PPC_REL32
, /* type */
597 2, /* size (0 = byte, 1 = short, 2 = long) */
599 true, /* pc_relative */
601 complain_overflow_bitfield
, /* complain_on_overflow */
602 bfd_elf_generic_reloc
, /* special_function */
603 "R_PPC_REL32", /* name */
604 false, /* partial_inplace */
606 0xffffffff, /* dst_mask */
607 true), /* pcrel_offset */
609 /* 32-bit relocation to the symbol's procedure linkage table.
610 FIXEME: not supported. */
611 HOWTO (R_PPC_PLT32
, /* type */
613 2, /* size (0 = byte, 1 = short, 2 = long) */
615 false, /* pc_relative */
617 complain_overflow_bitfield
, /* complain_on_overflow */
618 bfd_elf_generic_reloc
, /* special_function */
619 "R_PPC_PLT32", /* name */
620 false, /* partial_inplace */
623 false), /* pcrel_offset */
625 /* 32-bit PC relative relocation to the symbol's procedure linkage table.
626 FIXEME: not supported. */
627 HOWTO (R_PPC_PLTREL32
, /* type */
629 2, /* size (0 = byte, 1 = short, 2 = long) */
631 true, /* pc_relative */
633 complain_overflow_bitfield
, /* complain_on_overflow */
634 bfd_elf_generic_reloc
, /* special_function */
635 "R_PPC_PLTREL32", /* name */
636 false, /* partial_inplace */
639 true), /* pcrel_offset */
641 /* Like R_PPC_ADDR16_LO, but referring to the PLT table entry for
643 HOWTO (R_PPC_PLT16_LO
, /* type */
645 1, /* size (0 = byte, 1 = short, 2 = long) */
647 false, /* pc_relative */
649 complain_overflow_bitfield
, /* complain_on_overflow */
650 bfd_elf_generic_reloc
, /* special_function */
651 "R_PPC_PLT16_LO", /* name */
652 false, /* partial_inplace */
654 0xffff, /* dst_mask */
655 false), /* pcrel_offset */
657 /* Like R_PPC_ADDR16_HI, but referring to the PLT table entry for
659 HOWTO (R_PPC_PLT16_HI
, /* type */
661 1, /* size (0 = byte, 1 = short, 2 = long) */
663 false, /* pc_relative */
665 complain_overflow_bitfield
, /* complain_on_overflow */
666 bfd_elf_generic_reloc
, /* special_function */
667 "R_PPC_PLT16_HI", /* name */
668 false, /* partial_inplace */
670 0xffff, /* dst_mask */
671 false), /* pcrel_offset */
673 /* Like R_PPC_ADDR16_HA, but referring to the PLT table entry for
674 the symbol. FIXME: Not supported. */
675 HOWTO (R_PPC_PLT16_HA
, /* type */
677 1, /* size (0 = byte, 1 = short, 2 = long) */
679 false, /* pc_relative */
681 complain_overflow_bitfield
, /* complain_on_overflow */
682 bfd_elf_generic_reloc
, /* special_function */
683 "R_PPC_PLT16_HA", /* name */
684 false, /* partial_inplace */
686 0xffff, /* dst_mask */
687 false), /* pcrel_offset */
689 /* A sign-extended 16 bit value relative to _SDA_BASE_, for use with
691 HOWTO (R_PPC_SDAREL16
, /* type */
693 1, /* size (0 = byte, 1 = short, 2 = long) */
695 false, /* pc_relative */
697 complain_overflow_signed
, /* complain_on_overflow */
698 bfd_elf_generic_reloc
, /* special_function */
699 "R_PPC_SDAREL16", /* name */
700 false, /* partial_inplace */
702 0xffff, /* dst_mask */
703 false), /* pcrel_offset */
705 /* 32-bit section relative relocation. */
706 HOWTO (R_PPC_SECTOFF
, /* type */
708 2, /* size (0 = byte, 1 = short, 2 = long) */
710 true, /* pc_relative */
712 complain_overflow_bitfield
, /* complain_on_overflow */
713 bfd_elf_generic_reloc
, /* special_function */
714 "R_PPC_SECTOFF", /* name */
715 false, /* partial_inplace */
718 true), /* pcrel_offset */
720 /* 16-bit lower half section relative relocation. */
721 HOWTO (R_PPC_SECTOFF_LO
, /* type */
723 1, /* size (0 = byte, 1 = short, 2 = long) */
725 false, /* pc_relative */
727 complain_overflow_bitfield
, /* complain_on_overflow */
728 bfd_elf_generic_reloc
, /* special_function */
729 "R_PPC_SECTOFF_LO", /* name */
730 false, /* partial_inplace */
732 0xffff, /* dst_mask */
733 false), /* pcrel_offset */
735 /* 16-bit upper half section relative relocation. */
736 HOWTO (R_PPC_SECTOFF_HI
, /* type */
738 1, /* size (0 = byte, 1 = short, 2 = long) */
740 false, /* pc_relative */
742 complain_overflow_bitfield
, /* complain_on_overflow */
743 bfd_elf_generic_reloc
, /* special_function */
744 "R_PPC_SECTOFF_HI", /* name */
745 false, /* partial_inplace */
747 0xffff, /* dst_mask */
748 false), /* pcrel_offset */
750 /* 16-bit upper half adjusted section relative relocation. */
751 HOWTO (R_PPC_SECTOFF_HA
, /* type */
753 1, /* size (0 = byte, 1 = short, 2 = long) */
755 false, /* pc_relative */
757 complain_overflow_bitfield
, /* complain_on_overflow */
758 bfd_elf_generic_reloc
, /* special_function */
759 "R_PPC_SECTOFF_HA", /* name */
760 false, /* partial_inplace */
762 0xffff, /* dst_mask */
763 false), /* pcrel_offset */
765 /* The remaining relocs are from the Embedded ELF ABI, and are not
766 in the SVR4 ELF ABI. */
768 /* 32 bit value resulting from the addend minus the symbol */
769 HOWTO (R_PPC_EMB_NADDR32
, /* type */
771 2, /* size (0 = byte, 1 = short, 2 = long) */
773 false, /* pc_relative */
775 complain_overflow_bitfield
, /* complain_on_overflow */
776 bfd_elf_generic_reloc
, /* special_function */
777 "R_PPC_EMB_NADDR32", /* name */
778 false, /* partial_inplace */
780 0xffffffff, /* dst_mask */
781 false), /* pcrel_offset */
783 /* 16 bit value resulting from the addend minus the symbol */
784 HOWTO (R_PPC_EMB_NADDR16
, /* type */
786 1, /* size (0 = byte, 1 = short, 2 = long) */
788 false, /* pc_relative */
790 complain_overflow_bitfield
, /* complain_on_overflow */
791 bfd_elf_generic_reloc
, /* special_function */
792 "R_PPC_EMB_NADDR16", /* name */
793 false, /* partial_inplace */
795 0xffff, /* dst_mask */
796 false), /* pcrel_offset */
798 /* 16 bit value resulting from the addend minus the symbol */
799 HOWTO (R_PPC_EMB_NADDR16_LO
, /* type */
801 1, /* size (0 = byte, 1 = short, 2 = long) */
803 false, /* pc_relative */
805 complain_overflow_dont
,/* complain_on_overflow */
806 bfd_elf_generic_reloc
, /* special_function */
807 "R_PPC_EMB_ADDR16_LO", /* name */
808 false, /* partial_inplace */
810 0xffff, /* dst_mask */
811 false), /* pcrel_offset */
813 /* The high order 16 bits of the addend minus the symbol */
814 HOWTO (R_PPC_EMB_NADDR16_HI
, /* type */
816 1, /* size (0 = byte, 1 = short, 2 = long) */
818 false, /* pc_relative */
820 complain_overflow_dont
, /* complain_on_overflow */
821 bfd_elf_generic_reloc
, /* special_function */
822 "R_PPC_EMB_NADDR16_HI", /* name */
823 false, /* partial_inplace */
825 0xffff, /* dst_mask */
826 false), /* pcrel_offset */
828 /* The high order 16 bits of the result of the addend minus the address,
829 plus 1 if the contents of the low 16 bits, treated as a signed number,
831 HOWTO (R_PPC_EMB_NADDR16_HA
, /* type */
833 1, /* size (0 = byte, 1 = short, 2 = long) */
835 false, /* pc_relative */
837 complain_overflow_dont
, /* complain_on_overflow */
838 bfd_elf_generic_reloc
, /* special_function */
839 "R_PPC_EMB_NADDR16_HA", /* name */
840 false, /* partial_inplace */
842 0xffff, /* dst_mask */
843 false), /* pcrel_offset */
845 /* 16 bit value resulting from allocating a 4 byte word to hold an
846 address in the .sdata section, and returning the offset from
847 _SDA_BASE_ for that relocation */
848 HOWTO (R_PPC_EMB_SDAI16
, /* type */
850 1, /* size (0 = byte, 1 = short, 2 = long) */
852 false, /* pc_relative */
854 complain_overflow_bitfield
, /* complain_on_overflow */
855 bfd_elf_generic_reloc
, /* special_function */
856 "R_PPC_EMB_SDAI16", /* name */
857 false, /* partial_inplace */
859 0xffff, /* dst_mask */
860 false), /* pcrel_offset */
862 /* 16 bit value resulting from allocating a 4 byte word to hold an
863 address in the .sdata2 section, and returning the offset from
864 _SDA2_BASE_ for that relocation */
865 HOWTO (R_PPC_EMB_SDA2I16
, /* type */
867 1, /* size (0 = byte, 1 = short, 2 = long) */
869 false, /* pc_relative */
871 complain_overflow_bitfield
, /* complain_on_overflow */
872 bfd_elf_generic_reloc
, /* special_function */
873 "R_PPC_EMB_SDA2I16", /* name */
874 false, /* partial_inplace */
876 0xffff, /* dst_mask */
877 false), /* pcrel_offset */
879 /* A sign-extended 16 bit value relative to _SDA2_BASE_, for use with
881 HOWTO (R_PPC_EMB_SDA2REL
, /* type */
883 1, /* size (0 = byte, 1 = short, 2 = long) */
885 false, /* pc_relative */
887 complain_overflow_signed
, /* complain_on_overflow */
888 bfd_elf_generic_reloc
, /* special_function */
889 "R_PPC_EMB_SDA2REL", /* name */
890 false, /* partial_inplace */
892 0xffff, /* dst_mask */
893 false), /* pcrel_offset */
895 /* Relocate against either _SDA_BASE_ or _SDA2_BASE_, filling in the 16 bit
896 signed offset from the appropriate base, and filling in the register
897 field with the appropriate register (0, 2, or 13). */
898 HOWTO (R_PPC_EMB_SDA21
, /* type */
900 2, /* size (0 = byte, 1 = short, 2 = long) */
902 false, /* pc_relative */
904 complain_overflow_signed
, /* complain_on_overflow */
905 bfd_elf_generic_reloc
, /* special_function */
906 "R_PPC_EMB_SDA21", /* name */
907 false, /* partial_inplace */
909 0xffff, /* dst_mask */
910 false), /* pcrel_offset */
912 /* Relocation not handled: R_PPC_EMB_MRKREF */
913 /* Relocation not handled: R_PPC_EMB_RELSEC16 */
914 /* Relocation not handled: R_PPC_EMB_RELST_LO */
915 /* Relocation not handled: R_PPC_EMB_RELST_HI */
916 /* Relocation not handled: R_PPC_EMB_RELST_HA */
917 /* Relocation not handled: R_PPC_EMB_BIT_FLD */
919 /* PC relative relocation against either _SDA_BASE_ or _SDA2_BASE_, filling
920 in the 16 bit signed offset from the appropriate base, and filling in the
921 register field with the appropriate register (0, 2, or 13). */
922 HOWTO (R_PPC_EMB_RELSDA
, /* type */
924 1, /* size (0 = byte, 1 = short, 2 = long) */
926 true, /* pc_relative */
928 complain_overflow_signed
, /* complain_on_overflow */
929 bfd_elf_generic_reloc
, /* special_function */
930 "R_PPC_EMB_RELSDA", /* name */
931 false, /* partial_inplace */
933 0xffff, /* dst_mask */
934 false), /* pcrel_offset */
936 /* Phony reloc to handle AIX style TOC entries */
937 HOWTO (R_PPC_TOC16
, /* type */
939 1, /* size (0 = byte, 1 = short, 2 = long) */
941 false, /* pc_relative */
943 complain_overflow_signed
, /* complain_on_overflow */
944 bfd_elf_generic_reloc
, /* special_function */
945 "R_PPC_TOC16", /* name */
946 false, /* partial_inplace */
948 0xffff, /* dst_mask */
949 false), /* pcrel_offset */
953 /* Initialize the ppc_elf_howto_table, so that linear accesses can be done. */
956 ppc_elf_howto_init ()
958 unsigned int i
, type
;
960 for (i
= 0; i
< sizeof (ppc_elf_howto_raw
) / sizeof (ppc_elf_howto_raw
[0]); i
++)
962 type
= ppc_elf_howto_raw
[i
].type
;
963 BFD_ASSERT (type
< sizeof(ppc_elf_howto_table
) / sizeof(ppc_elf_howto_table
[0]));
964 ppc_elf_howto_table
[type
] = &ppc_elf_howto_raw
[i
];
969 static reloc_howto_type
*
970 ppc_elf_reloc_type_lookup (abfd
, code
)
972 bfd_reloc_code_real_type code
;
974 enum ppc_reloc_type ppc_reloc
= R_PPC_NONE
;
976 if (!ppc_elf_howto_table
[ R_PPC_ADDR32
]) /* Initialize howto table if needed */
977 ppc_elf_howto_init ();
982 return (reloc_howto_type
*)NULL
;
984 case BFD_RELOC_NONE
: ppc_reloc
= R_PPC_NONE
; break;
985 case BFD_RELOC_32
: ppc_reloc
= R_PPC_ADDR32
; break;
986 case BFD_RELOC_PPC_BA26
: ppc_reloc
= R_PPC_ADDR24
; break;
987 case BFD_RELOC_16
: ppc_reloc
= R_PPC_ADDR16
; break;
988 case BFD_RELOC_LO16
: ppc_reloc
= R_PPC_ADDR16_LO
; break;
989 case BFD_RELOC_HI16
: ppc_reloc
= R_PPC_ADDR16_HI
; break;
990 case BFD_RELOC_HI16_S
: ppc_reloc
= R_PPC_ADDR16_HA
; break;
991 case BFD_RELOC_PPC_BA16
: ppc_reloc
= R_PPC_ADDR14
; break;
992 case BFD_RELOC_PPC_BA16_BRTAKEN
: ppc_reloc
= R_PPC_ADDR14_BRTAKEN
; break;
993 case BFD_RELOC_PPC_BA16_BRNTAKEN
: ppc_reloc
= R_PPC_ADDR14_BRNTAKEN
; break;
994 case BFD_RELOC_PPC_B26
: ppc_reloc
= R_PPC_REL24
; break;
995 case BFD_RELOC_PPC_B16
: ppc_reloc
= R_PPC_REL14
; break;
996 case BFD_RELOC_PPC_B16_BRTAKEN
: ppc_reloc
= R_PPC_REL14_BRTAKEN
; break;
997 case BFD_RELOC_PPC_B16_BRNTAKEN
: ppc_reloc
= R_PPC_REL14_BRNTAKEN
; break;
998 case BFD_RELOC_16_GOTOFF
: ppc_reloc
= R_PPC_GOT16
; break;
999 case BFD_RELOC_LO16_GOTOFF
: ppc_reloc
= R_PPC_GOT16_LO
; break;
1000 case BFD_RELOC_HI16_GOTOFF
: ppc_reloc
= R_PPC_GOT16_HI
; break;
1001 case BFD_RELOC_HI16_S_GOTOFF
: ppc_reloc
= R_PPC_GOT16_HA
; break;
1002 case BFD_RELOC_24_PLT_PCREL
: ppc_reloc
= R_PPC_PLTREL24
; break;
1003 case BFD_RELOC_PPC_COPY
: ppc_reloc
= R_PPC_COPY
; break;
1004 case BFD_RELOC_PPC_GLOB_DAT
: ppc_reloc
= R_PPC_GLOB_DAT
; break;
1005 case BFD_RELOC_PPC_LOCAL24PC
: ppc_reloc
= R_PPC_LOCAL24PC
; break;
1006 case BFD_RELOC_32_PCREL
: ppc_reloc
= R_PPC_REL32
; break;
1007 case BFD_RELOC_32_PLTOFF
: ppc_reloc
= R_PPC_PLT32
; break;
1008 case BFD_RELOC_32_PLT_PCREL
: ppc_reloc
= R_PPC_PLTREL32
; break;
1009 case BFD_RELOC_LO16_PLTOFF
: ppc_reloc
= R_PPC_PLT16_LO
; break;
1010 case BFD_RELOC_HI16_PLTOFF
: ppc_reloc
= R_PPC_PLT16_HI
; break;
1011 case BFD_RELOC_HI16_S_PLTOFF
: ppc_reloc
= R_PPC_PLT16_HA
; break;
1012 case BFD_RELOC_GPREL16
: ppc_reloc
= R_PPC_SDAREL16
; break;
1013 case BFD_RELOC_32_BASEREL
: ppc_reloc
= R_PPC_SECTOFF
; break;
1014 case BFD_RELOC_LO16_BASEREL
: ppc_reloc
= R_PPC_SECTOFF_LO
; break;
1015 case BFD_RELOC_HI16_BASEREL
: ppc_reloc
= R_PPC_SECTOFF_HI
; break;
1016 case BFD_RELOC_HI16_S_BASEREL
: ppc_reloc
= R_PPC_SECTOFF_HA
; break;
1017 case BFD_RELOC_CTOR
: ppc_reloc
= R_PPC_ADDR32
; break;
1018 case BFD_RELOC_PPC_TOC16
: ppc_reloc
= R_PPC_TOC16
; break;
1019 case BFD_RELOC_PPC_EMB_NADDR32
: ppc_reloc
= R_PPC_EMB_NADDR32
; break;
1020 case BFD_RELOC_PPC_EMB_NADDR16
: ppc_reloc
= R_PPC_EMB_NADDR16
; break;
1021 case BFD_RELOC_PPC_EMB_NADDR16_LO
: ppc_reloc
= R_PPC_EMB_NADDR16_LO
; break;
1022 case BFD_RELOC_PPC_EMB_NADDR16_HI
: ppc_reloc
= R_PPC_EMB_NADDR16_HI
; break;
1023 case BFD_RELOC_PPC_EMB_NADDR16_HA
: ppc_reloc
= R_PPC_EMB_NADDR16_HA
; break;
1024 case BFD_RELOC_PPC_EMB_SDAI16
: ppc_reloc
= R_PPC_EMB_SDAI16
; break;
1025 case BFD_RELOC_PPC_EMB_SDA2I16
: ppc_reloc
= R_PPC_EMB_SDA2I16
; break;
1026 case BFD_RELOC_PPC_EMB_SDA2REL
: ppc_reloc
= R_PPC_EMB_SDA2REL
; break;
1027 case BFD_RELOC_PPC_EMB_SDA21
: ppc_reloc
= R_PPC_EMB_SDA21
; break;
1028 case BFD_RELOC_PPC_EMB_MRKREF
: ppc_reloc
= R_PPC_EMB_MRKREF
; break;
1029 case BFD_RELOC_PPC_EMB_RELSEC16
: ppc_reloc
= R_PPC_EMB_RELSEC16
; break;
1030 case BFD_RELOC_PPC_EMB_RELST_LO
: ppc_reloc
= R_PPC_EMB_RELST_LO
; break;
1031 case BFD_RELOC_PPC_EMB_RELST_HI
: ppc_reloc
= R_PPC_EMB_RELST_HI
; break;
1032 case BFD_RELOC_PPC_EMB_RELST_HA
: ppc_reloc
= R_PPC_EMB_RELST_HA
; break;
1033 case BFD_RELOC_PPC_EMB_BIT_FLD
: ppc_reloc
= R_PPC_EMB_BIT_FLD
; break;
1034 case BFD_RELOC_PPC_EMB_RELSDA
: ppc_reloc
= R_PPC_EMB_RELSDA
; break;
1037 return ppc_elf_howto_table
[ (int)ppc_reloc
];
1040 /* Set the howto pointer for a PowerPC ELF reloc. */
1043 ppc_elf_info_to_howto (abfd
, cache_ptr
, dst
)
1046 Elf32_Internal_Rela
*dst
;
1048 if (!ppc_elf_howto_table
[ R_PPC_ADDR32
]) /* Initialize howto table if needed */
1049 ppc_elf_howto_init ();
1051 BFD_ASSERT (ELF32_R_TYPE (dst
->r_info
) < (unsigned int) R_PPC_max
);
1052 cache_ptr
->howto
= ppc_elf_howto_table
[ELF32_R_TYPE (dst
->r_info
)];
1055 /* Function to set whether a module needs the -mrelocatable bit set. */
1058 ppc_elf_set_private_flags (abfd
, flags
)
1062 BFD_ASSERT (!elf_flags_init (abfd
)
1063 || elf_elfheader (abfd
)->e_flags
== flags
);
1065 elf_elfheader (abfd
)->e_flags
= flags
;
1066 elf_flags_init (abfd
) = true;
1070 /* Copy backend specific data from one object module to another */
1072 ppc_elf_copy_private_bfd_data (ibfd
, obfd
)
1076 /* This function is selected based on the input vector. We only
1077 want to copy information over if the output BFD also uses Elf
1079 if (bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
1082 BFD_ASSERT (!elf_flags_init (obfd
)
1083 || elf_elfheader (obfd
)->e_flags
== elf_elfheader (ibfd
)->e_flags
);
1085 elf_elfheader (obfd
)->e_flags
= elf_elfheader (ibfd
)->e_flags
;
1086 elf_flags_init (obfd
) = true;
1090 /* Merge backend specific data from an object file to the output
1091 object file when linking */
1093 ppc_elf_merge_private_bfd_data (ibfd
, obfd
)
1101 /* Check if we have the same endianess */
1102 if (ibfd
->xvec
->byteorder
!= obfd
->xvec
->byteorder
1103 && obfd
->xvec
->byteorder
!= BFD_ENDIAN_UNKNOWN
)
1105 (*_bfd_error_handler
)
1106 ("%s: compiled for a %s endian system and target is %s endian",
1107 bfd_get_filename (ibfd
),
1108 bfd_big_endian (ibfd
) ? "big" : "little",
1109 bfd_big_endian (obfd
) ? "big" : "little");
1111 bfd_set_error (bfd_error_wrong_format
);
1115 /* This function is selected based on the input vector. We only
1116 want to copy information over if the output BFD also uses Elf
1118 if (bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
1121 new_flags
= elf_elfheader (ibfd
)->e_flags
;
1122 old_flags
= elf_elfheader (obfd
)->e_flags
;
1123 if (!elf_flags_init (obfd
)) /* First call, no flags set */
1125 elf_flags_init (obfd
) = true;
1126 elf_elfheader (obfd
)->e_flags
= new_flags
;
1129 else if (new_flags
== old_flags
) /* Compatible flags are ok */
1132 else /* Incompatible flags */
1134 /* Warn about -mrelocatable mismatch. Allow -mrelocatable-lib to be linked
1137 if ((new_flags
& EF_PPC_RELOCATABLE
) != 0
1138 && (old_flags
& (EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
)) == 0)
1141 (*_bfd_error_handler
)
1142 ("%s: compiled with -mrelocatable and linked with modules compiled normally",
1143 bfd_get_filename (ibfd
));
1145 else if ((new_flags
& (EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
)) == 0
1146 && (old_flags
& EF_PPC_RELOCATABLE
) != 0)
1149 (*_bfd_error_handler
)
1150 ("%s: compiled normally and linked with modules compiled with -mrelocatable",
1151 bfd_get_filename (ibfd
));
1153 else if ((new_flags
& EF_PPC_RELOCATABLE_LIB
) != 0)
1154 elf_elfheader (obfd
)->e_flags
|= EF_PPC_RELOCATABLE_LIB
;
1157 /* Do not warn about eabi vs. V.4 mismatch, just or in the bit if any module uses it */
1158 elf_elfheader (obfd
)->e_flags
|= (new_flags
& EF_PPC_EMB
);
1160 new_flags
&= ~ (EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
| EF_PPC_EMB
);
1161 old_flags
&= ~ (EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
| EF_PPC_EMB
);
1163 /* Warn about any other mismatches */
1164 if (new_flags
!= old_flags
)
1167 (*_bfd_error_handler
)
1168 ("%s: uses different e_flags (0x%lx) fields than previous modules (0x%lx)",
1169 bfd_get_filename (ibfd
), (long)new_flags
, (long)old_flags
);
1174 bfd_set_error (bfd_error_bad_value
);
1183 /* Handle a PowerPC specific section when reading an object file. This
1184 is called when elfcode.h finds a section with an unknown type. */
1187 ppc_elf_section_from_shdr (abfd
, hdr
, name
)
1189 Elf32_Internal_Shdr
*hdr
;
1195 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
))
1198 newsect
= hdr
->bfd_section
;
1199 flags
= bfd_get_section_flags (abfd
, newsect
);
1200 if (hdr
->sh_flags
& SHF_EXCLUDE
)
1201 flags
|= SEC_EXCLUDE
;
1203 if (hdr
->sh_type
== SHT_ORDERED
)
1204 flags
|= SEC_SORT_ENTRIES
;
1206 bfd_set_section_flags (abfd
, newsect
, flags
);
1211 /* Set up any other section flags and such that may be necessary. */
1214 ppc_elf_fake_sections (abfd
, shdr
, asect
)
1216 Elf32_Internal_Shdr
*shdr
;
1219 if ((asect
->flags
& SEC_EXCLUDE
) != 0)
1220 shdr
->sh_flags
|= SHF_EXCLUDE
;
1222 if ((asect
->flags
& SEC_SORT_ENTRIES
) != 0)
1223 shdr
->sh_type
= SHT_ORDERED
;
1229 /* Create a special linker section */
1230 static elf_linker_section_t
*
1231 ppc_elf_create_linker_section (abfd
, info
, which
)
1233 struct bfd_link_info
*info
;
1234 enum elf_linker_section_enum which
;
1236 bfd
*dynobj
= elf_hash_table (info
)->dynobj
;
1237 elf_linker_section_t
*lsect
;
1239 /* Record the first bfd section that needs the special section */
1241 dynobj
= elf_hash_table (info
)->dynobj
= abfd
;
1243 /* If this is the first time, create the section */
1244 lsect
= elf_linker_section (dynobj
, which
);
1247 elf_linker_section_t defaults
;
1248 static elf_linker_section_t zero_section
;
1250 defaults
= zero_section
;
1251 defaults
.which
= which
;
1252 defaults
.hole_written_p
= false;
1253 defaults
.alignment
= 2;
1254 defaults
.flags
= SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
;
1259 (*_bfd_error_handler
) ("%s: Unknown special linker type %d",
1260 bfd_get_filename (abfd
),
1263 bfd_set_error (bfd_error_bad_value
);
1264 return (elf_linker_section_t
*)0;
1266 case LINKER_SECTION_GOT
: /* .got section */
1267 defaults
.name
= ".got";
1268 defaults
.rel_name
= ".rela.got";
1269 defaults
.sym_name
= "_GLOBAL_OFFSET_TABLE_";
1270 defaults
.max_hole_offset
= 32764;
1271 defaults
.hole_size
= 16;
1272 defaults
.sym_offset
= 4;
1275 case LINKER_SECTION_PLT
: /* .plt section */
1276 defaults
.name
= ".plt";
1277 defaults
.rel_name
= ".rela.plt";
1278 defaults
.sym_name
= (char *)0;
1279 defaults
.max_hole_offset
= 0;
1280 defaults
.hole_size
= 0;
1281 defaults
.sym_offset
= 0;
1282 defaults
.flags
&= ~SEC_LOAD
;
1285 case LINKER_SECTION_SDATA
: /* .sdata/.sbss section */
1286 defaults
.name
= ".sdata";
1287 defaults
.rel_name
= ".rela.sdata";
1288 defaults
.bss_name
= ".sbss";
1289 defaults
.sym_name
= "_SDA_BASE_";
1290 defaults
.sym_offset
= 32768;
1293 case LINKER_SECTION_SDATA2
: /* .sdata2/.sbss2 section */
1294 defaults
.name
= ".sdata2";
1295 defaults
.rel_name
= ".rela.sdata2";
1296 defaults
.bss_name
= ".sbss2";
1297 defaults
.sym_name
= "_SDA2_BASE_";
1298 defaults
.sym_offset
= 32768;
1299 defaults
.flags
|= SEC_READONLY
;
1303 lsect
= _bfd_elf_create_linker_section (abfd
, info
, which
, &defaults
);
1310 /* If we have a non-zero sized .sbss2 or .PPC.EMB.sbss0 sections, we need to bump up
1311 the number of section headers. */
1314 ppc_elf_additional_program_headers (abfd
)
1322 s
= bfd_get_section_by_name (abfd
, ".interp");
1326 s
= bfd_get_section_by_name (abfd
, ".sbss2");
1327 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0 && s
->_raw_size
> 0)
1330 s
= bfd_get_section_by_name (abfd
, ".PPC.EMB.sbss0");
1331 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0 && s
->_raw_size
> 0)
1337 /* Modify the segment map if needed */
1340 ppc_elf_modify_segment_map (abfd
)
1346 /* Adjust a symbol defined by a dynamic object and referenced by a
1347 regular object. The current definition is in some section of the
1348 dynamic object, but we're not including those sections. We have to
1349 change the definition to something the rest of the link can
1353 ppc_elf_adjust_dynamic_symbol (info
, h
)
1354 struct bfd_link_info
*info
;
1355 struct elf_link_hash_entry
*h
;
1357 bfd
*dynobj
= elf_hash_table (info
)->dynobj
;
1359 unsigned int power_of_two
;
1363 fprintf (stderr
, "ppc_elf_adjust_dynamic_symbol called for %s\n", h
->root
.root
.string
);
1366 /* Make sure we know what is going on here. */
1367 BFD_ASSERT (dynobj
!= NULL
1368 && ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
)
1369 || h
->weakdef
!= NULL
1370 || ((h
->elf_link_hash_flags
1371 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0
1372 && (h
->elf_link_hash_flags
1373 & ELF_LINK_HASH_REF_REGULAR
) != 0
1374 && (h
->elf_link_hash_flags
1375 & ELF_LINK_HASH_DEF_REGULAR
) == 0)));
1378 /* If this is a function, put it in the procedure linkage table. We
1379 will fill in the contents of the procedure linkage table later,
1380 when we know the address of the .got section. */
1381 if (h
->type
== STT_FUNC
1382 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
1385 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) == 0
1386 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_REF_DYNAMIC
) == 0)
1388 /* This case can occur if we saw a PLT32 reloc in an input
1389 file, but the symbol was never referred to by a dynamic
1390 object. In such a case, we don't actually need to build
1391 a procedure linkage table, and we can just do a PC32
1393 BFD_ASSERT ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0);
1397 /* Make sure this symbol is output as a dynamic symbol. */
1398 if (h
->dynindx
== -1)
1400 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
1404 s
= bfd_get_section_by_name (dynobj
, ".plt");
1405 BFD_ASSERT (s
!= NULL
);
1407 /* If this is the first .plt entry, make room for the special
1409 if (s
->_raw_size
== 0)
1410 s
->_raw_size
+= PLT_INITIAL_ENTRY_SIZE
;
1412 /* The PowerPC PLT is actually composed of two parts, the first part
1413 is 2 words (for a load and a jump), and then there is a remaining
1414 word available at the end. */
1415 plt_offset
= (PLT_INITIAL_ENTRY_SIZE
1416 + 8 * ((s
->_raw_size
- PLT_INITIAL_ENTRY_SIZE
) / PLT_ENTRY_SIZE
));
1418 /* If this symbol is not defined in a regular file, and we are
1419 not generating a shared library, then set the symbol to this
1420 location in the .plt. This is required to make function
1421 pointers compare as equal between the normal executable and
1422 the shared library. */
1424 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
1426 h
->root
.u
.def
.section
= s
;
1427 h
->root
.u
.def
.value
= plt_offset
;
1430 h
->plt_offset
= plt_offset
;
1432 /* Make room for this entry. */
1433 s
->_raw_size
+= PLT_ENTRY_SIZE
;
1435 /* We also need to make an entry in the .rela.plt section. */
1437 s
= bfd_get_section_by_name (dynobj
, ".rela.plt");
1438 BFD_ASSERT (s
!= NULL
);
1439 s
->_raw_size
+= sizeof (Elf32_External_Rela
);
1444 /* If this is a weak symbol, and there is a real definition, the
1445 processor independent code will have arranged for us to see the
1446 real definition first, and we can just use the same value. */
1447 if (h
->weakdef
!= NULL
)
1449 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
1450 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
1451 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
1452 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
1456 /* This is a reference to a symbol defined by a dynamic object which
1457 is not a function. */
1459 /* If we are creating a shared library, we must presume that the
1460 only references to the symbol are via the global offset table.
1461 For such cases we need not do anything here; the relocations will
1462 be handled correctly by relocate_section. */
1466 /* We must allocate the symbol in our .dynbss section, which will
1467 become part of the .bss section of the executable. There will be
1468 an entry for this symbol in the .dynsym section. The dynamic
1469 object will contain position independent code, so all references
1470 from the dynamic object to this symbol will go through the global
1471 offset table. The dynamic linker will use the .dynsym entry to
1472 determine the address it must put in the global offset table, so
1473 both the dynamic object and the regular object will refer to the
1474 same memory location for the variable. */
1476 s
= bfd_get_section_by_name (dynobj
, ".dynbss");
1477 BFD_ASSERT (s
!= NULL
);
1479 /* If the symbol is currently defined in the .bss section of the
1480 dynamic object, then it is OK to simply initialize it to zero.
1481 If the symbol is in some other section, we must generate a
1482 R_386_COPY reloc to tell the dynamic linker to copy the initial
1483 value out of the dynamic object and into the runtime process
1484 image. We need to remember the offset into the .rela.bss section
1485 we are going to use. */
1486 if ((h
->root
.u
.def
.section
->flags
& SEC_LOAD
) != 0)
1490 srel
= bfd_get_section_by_name (dynobj
, ".rela.bss");
1491 BFD_ASSERT (srel
!= NULL
);
1492 srel
->_raw_size
+= sizeof (Elf32_External_Rel
);
1493 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_COPY
;
1496 /* We need to figure out the alignment required for this symbol. I
1497 have no idea how ELF linkers handle this. */
1498 power_of_two
= bfd_log2 (h
->size
);
1499 if (power_of_two
> 3)
1502 /* Apply the required alignment. */
1503 s
->_raw_size
= BFD_ALIGN (s
->_raw_size
,
1504 (bfd_size_type
) (1 << power_of_two
));
1505 if (power_of_two
> bfd_get_section_alignment (dynobj
, s
))
1507 if (! bfd_set_section_alignment (dynobj
, s
, power_of_two
))
1511 /* Define the symbol as being at this point in the section. */
1512 h
->root
.u
.def
.section
= s
;
1513 h
->root
.u
.def
.value
= s
->_raw_size
;
1515 /* Increment the section size to make room for the symbol. */
1516 s
->_raw_size
+= h
->size
;
1522 /* Increment the index of a dynamic symbol by a given amount. Called
1523 via elf_link_hash_traverse. */
1526 ppc_elf_adjust_dynindx (h
, cparg
)
1527 struct elf_link_hash_entry
*h
;
1530 int *cp
= (int *) cparg
;
1533 fprintf (stderr
, "ppc_elf_adjust_dynindx called, h->dynindx = %d, *cp = %d\n", h
->dynindx
, *cp
);
1536 if (h
->dynindx
!= -1)
1543 /* Set the sizes of the dynamic sections. */
1546 ppc_elf_size_dynamic_sections (output_bfd
, info
)
1548 struct bfd_link_info
*info
;
1557 fprintf (stderr
, "ppc_elf_size_dynamic_sections called\n");
1560 dynobj
= elf_hash_table (info
)->dynobj
;
1561 BFD_ASSERT (dynobj
!= NULL
);
1563 if (elf_hash_table (info
)->dynamic_sections_created
)
1565 /* Set the contents of the .interp section to the interpreter. */
1568 s
= bfd_get_section_by_name (dynobj
, ".interp");
1569 BFD_ASSERT (s
!= NULL
);
1570 s
->_raw_size
= sizeof ELF_DYNAMIC_INTERPRETER
;
1571 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
1574 /* Make space for the trailing nop in .plt. */
1575 s
= bfd_get_section_by_name (dynobj
, ".plt");
1576 BFD_ASSERT (s
!= NULL
);
1577 if (s
->_raw_size
> 0)
1582 /* We may have created entries in the .rela.got, .rela.sdata, and
1583 .rela.sdata2 section2. However, if we are not creating the
1584 dynamic sections, we will not actually use these entries. Reset
1585 the size of .rela.got, et al, which will cause it to get
1586 stripped from the output file below. */
1587 static char *rela_sections
[] = { ".rela.got", ".rela.sdata", ".rela.sdata", (char *)0 };
1590 for (p
= rela_sections
; *p
!= (char *)0; p
++)
1592 s
= bfd_get_section_by_name (dynobj
, *p
);
1598 /* The check_relocs and adjust_dynamic_symbol entry points have
1599 determined the sizes of the various dynamic sections. Allocate
1604 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
1609 if ((s
->flags
& SEC_IN_MEMORY
) == 0)
1612 /* It's OK to base decisions on the section name, because none
1613 of the dynobj section names depend upon the input files. */
1614 name
= bfd_get_section_name (dynobj
, s
);
1618 if (strcmp (name
, ".plt") == 0)
1620 if (s
->_raw_size
== 0)
1622 /* Strip this section if we don't need it; see the
1628 /* Remember whether there is a PLT. */
1632 else if (strncmp (name
, ".rela", 5) == 0)
1634 if (s
->_raw_size
== 0)
1636 /* If we don't need this section, strip it from the
1637 output file. This is mostly to handle .rela.bss and
1638 .rela.plt. We must create both sections in
1639 create_dynamic_sections, because they must be created
1640 before the linker maps input sections to output
1641 sections. The linker does that before
1642 adjust_dynamic_symbol is called, and it is that
1643 function which decides whether anything needs to go
1644 into these sections. */
1651 /* Remember whether there are any reloc sections other
1653 if (strcmp (name
, ".rela.plt") != 0)
1657 /* If this relocation section applies to a read only
1658 section, then we probably need a DT_TEXTREL
1659 entry. The entries in the .rel.plt section
1660 really apply to the .got section, which we
1661 created ourselves and so know is not readonly. */
1662 target
= bfd_get_section_by_name (output_bfd
, name
+ 4);
1664 && (target
->flags
& SEC_READONLY
) != 0)
1668 /* We use the reloc_count field as a counter if we need
1669 to copy relocs into the output file. */
1673 else if (strcmp (name
, ".got") != 0
1674 && strcmp (name
, ".sdata") != 0
1675 && strcmp (name
, ".sdata2") != 0)
1677 /* It's not one of our sections, so don't allocate space. */
1685 for (spp
= &s
->output_section
->owner
->sections
;
1686 *spp
!= s
->output_section
;
1687 spp
= &(*spp
)->next
)
1689 *spp
= s
->output_section
->next
;
1690 --s
->output_section
->owner
->section_count
;
1695 /* Allocate memory for the section contents. */
1696 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->_raw_size
);
1697 if (s
->contents
== NULL
&& s
->_raw_size
!= 0)
1701 if (elf_hash_table (info
)->dynamic_sections_created
)
1703 /* Add some entries to the .dynamic section. We fill in the
1704 values later, in ppc_elf_finish_dynamic_sections, but we
1705 must add the entries now so that we get the correct size for
1706 the .dynamic section. The DT_DEBUG entry is filled in by the
1707 dynamic linker and used by the debugger. */
1710 if (! bfd_elf32_add_dynamic_entry (info
, DT_DEBUG
, 0))
1716 if (! bfd_elf32_add_dynamic_entry (info
, DT_PLTGOT
, 0)
1717 || ! bfd_elf32_add_dynamic_entry (info
, DT_PLTRELSZ
, 0)
1718 || ! bfd_elf32_add_dynamic_entry (info
, DT_PLTREL
, DT_REL
)
1719 || ! bfd_elf32_add_dynamic_entry (info
, DT_JMPREL
, 0))
1725 if (! bfd_elf32_add_dynamic_entry (info
, DT_RELA
, 0)
1726 || ! bfd_elf32_add_dynamic_entry (info
, DT_RELASZ
, DT_RELA
)
1727 || ! bfd_elf32_add_dynamic_entry (info
, DT_RELENT
,
1728 sizeof (Elf32_External_Rela
)))
1734 if (! bfd_elf32_add_dynamic_entry (info
, DT_TEXTREL
, 0))
1739 /* If we are generating a shared library, we generate a section
1740 symbol for each output section. These are local symbols, which
1741 means that they must come first in the dynamic symbol table.
1742 That means we must increment the dynamic symbol index of every
1743 other dynamic symbol. */
1748 c
= bfd_count_sections (output_bfd
);
1749 elf_link_hash_traverse (elf_hash_table (info
),
1750 ppc_elf_adjust_dynindx
,
1752 elf_hash_table (info
)->dynsymcount
+= c
;
1754 for (i
= 1, s
= output_bfd
->sections
; s
!= NULL
; s
= s
->next
, i
++)
1756 elf_section_data (s
)->dynindx
= i
;
1757 /* These symbols will have no names, so we don't need to
1758 fiddle with dynstr_index. */
1766 /* Look through the relocs for a section during the first phase, and
1767 allocate space in the global offset table or procedure linkage
1771 ppc_elf_check_relocs (abfd
, info
, sec
, relocs
)
1773 struct bfd_link_info
*info
;
1775 const Elf_Internal_Rela
*relocs
;
1778 Elf_Internal_Shdr
*symtab_hdr
;
1779 struct elf_link_hash_entry
**sym_hashes
;
1780 const Elf_Internal_Rela
*rel
;
1781 const Elf_Internal_Rela
*rel_end
;
1782 elf_linker_section_t
*got
;
1783 elf_linker_section_t
*plt
;
1784 elf_linker_section_t
*sdata
;
1785 elf_linker_section_t
*sdata2
;
1788 if (info
->relocateable
)
1792 fprintf (stderr
, "ppc_elf_check_relocs called for section %s in %s\n",
1793 bfd_get_section_name (abfd
, sec
),
1794 bfd_get_filename (abfd
));
1797 /* Create the linker generated sections all the time so that the special
1798 symbols are created. */
1799 if ((got
= elf_linker_section (abfd
, LINKER_SECTION_GOT
)) == NULL
)
1801 got
= ppc_elf_create_linker_section (abfd
, info
, LINKER_SECTION_GOT
);
1807 if ((plt
= elf_linker_section (abfd
, LINKER_SECTION_PLT
)) == NULL
)
1809 plt
= ppc_elf_create_linker_section (abfd
, info
, LINKER_SECTION_PLT
);
1815 if ((sdata
= elf_linker_section (abfd
, LINKER_SECTION_SDATA
)) == NULL
)
1817 sdata
= ppc_elf_create_linker_section (abfd
, info
, LINKER_SECTION_SDATA
);
1823 if ((sdata2
= elf_linker_section (abfd
, LINKER_SECTION_SDATA2
)) == NULL
)
1825 sdata2
= ppc_elf_create_linker_section (abfd
, info
, LINKER_SECTION_SDATA2
);
1830 dynobj
= elf_hash_table (info
)->dynobj
;
1831 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
1832 sym_hashes
= elf_sym_hashes (abfd
);
1836 rel_end
= relocs
+ sec
->reloc_count
;
1837 for (rel
= relocs
; rel
< rel_end
; rel
++)
1839 unsigned long r_symndx
;
1840 struct elf_link_hash_entry
*h
;
1842 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1843 if (r_symndx
< symtab_hdr
->sh_info
)
1846 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1848 switch (ELF32_R_TYPE (rel
->r_info
))
1853 /* GOT16 relocations */
1855 case R_PPC_GOT16_LO
:
1856 case R_PPC_GOT16_HI
:
1857 case R_PPC_GOT16_HA
:
1858 if (got
->rel_section
== NULL
1859 && (h
!= NULL
|| info
->shared
)
1860 && !_bfd_elf_make_linker_section_rela (dynobj
, got
, 2))
1863 if (!bfd_elf32_create_pointer_linker_section (abfd
, info
, got
, h
, rel
))
1868 /* Indirect .sdata relocation */
1869 case R_PPC_EMB_SDAI16
:
1870 if (got
->rel_section
== NULL
1871 && (h
!= NULL
|| info
->shared
)
1872 && !_bfd_elf_make_linker_section_rela (dynobj
, got
, 2))
1875 if (!bfd_elf32_create_pointer_linker_section (abfd
, info
, sdata
, h
, rel
))
1880 /* Indirect .sdata2 relocation */
1881 case R_PPC_EMB_SDA2I16
:
1882 if (got
->rel_section
== NULL
1883 && (h
!= NULL
|| info
->shared
)
1884 && !_bfd_elf_make_linker_section_rela (dynobj
, got
, 2))
1887 if (!bfd_elf32_create_pointer_linker_section (abfd
, info
, sdata2
, h
, rel
))
1893 case R_PPC_PLTREL24
:
1894 case R_PPC_PLT16_LO
:
1895 case R_PPC_PLT16_HI
:
1896 case R_PPC_PLT16_HA
:
1898 fprintf (stderr
, "Reloc requires a PLT entry\n");
1900 /* This symbol requires a procedure linkage table entry. We
1901 actually build the entry in adjust_dynamic_symbol,
1902 because this might be a case of linking PIC code without
1903 linking in any dynamic objects, in which case we don't
1904 need to generate a procedure linkage table after all. */
1908 /* It does not make sense to have a procedure linkage
1909 table entry for a local symbol. */
1910 bfd_set_error (bfd_error_bad_value
);
1914 /* Make sure this symbol is output as a dynamic symbol. */
1915 if (h
->dynindx
== -1)
1917 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
1921 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
1928 && strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
1932 case R_SPARC_DISP16
:
1933 case R_SPARC_DISP32
:
1934 case R_SPARC_WDISP30
:
1935 case R_SPARC_WDISP22
:
1948 && (sec
->flags
& SEC_ALLOC
) != 0)
1950 /* When creating a shared object, we must copy these
1951 relocs into the output file. We create a reloc
1952 section in dynobj and make room for the reloc. */
1957 name
= (bfd_elf_string_from_elf_section
1959 elf_elfheader (abfd
)->e_shstrndx
,
1960 elf_section_data (sec
)->rel_hdr
.sh_name
));
1964 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
1965 && strcmp (bfd_get_section_name (abfd
, sec
),
1968 sreloc
= bfd_get_section_by_name (dynobj
, name
);
1971 sreloc
= bfd_make_section (dynobj
, name
);
1973 || ! bfd_set_section_flags (dynobj
, sreloc
,
1979 || ! bfd_set_section_alignment (dynobj
, sreloc
, 2))
1984 sreloc
->_raw_size
+= sizeof (Elf32_External_Rela
);
1996 /* Hook called by the linker routine which adds symbols from an object
1997 file. We use it to put .comm items in .sbss, and not .bss. */
2001 ppc_elf_add_symbol_hook (abfd
, info
, sym
, namep
, flagsp
, secp
, valp
)
2003 struct bfd_link_info
*info
;
2004 const Elf_Internal_Sym
*sym
;
2010 if (sym
->st_shndx
== SHN_COMMON
&& sym
->st_size
<= bfd_get_gp_size (abfd
))
2012 /* Common symbols less than or equal to -G nn bytes are automatically
2014 elf_linker_section_t
*sdata
= ppc_elf_create_linker_section (abfd
, info
, LINKER_SECTION_SDATA
);
2015 if (!sdata
->bss_section
)
2017 sdata
->bss_section
= bfd_make_section (elf_hash_table (info
)->dynobj
, sdata
->bss_name
);
2018 sdata
->bss_section
->flags
= (sdata
->bss_section
->flags
& ~SEC_LOAD
) | SEC_IS_COMMON
;
2021 *secp
= sdata
->bss_section
;
2022 *valp
= sym
->st_size
;
2029 /* Finish up dynamic symbol handling. We set the contents of various
2030 dynamic sections here. */
2033 ppc_elf_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
2035 struct bfd_link_info
*info
;
2036 struct elf_link_hash_entry
*h
;
2037 Elf_Internal_Sym
*sym
;
2042 fprintf (stderr
, "ppc_elf_finish_dynamic_symbol called for %s", h
->root
.root
.string
);
2045 dynobj
= elf_hash_table (info
)->dynobj
;
2046 BFD_ASSERT (dynobj
!= NULL
);
2048 if (h
->plt_offset
!= (bfd_vma
) -1)
2052 Elf_Internal_Rela rela
;
2055 fprintf (stderr
, ", plt_offset = %d", h
->plt_offset
);
2058 /* This symbol has an entry in the procedure linkage table. Set
2061 BFD_ASSERT (h
->dynindx
!= -1);
2063 splt
= bfd_get_section_by_name (dynobj
, ".plt");
2064 srela
= bfd_get_section_by_name (dynobj
, ".rela.plt");
2065 BFD_ASSERT (splt
!= NULL
&& srela
!= NULL
);
2067 /* We don't need to fill in the .plt. The solaris dynamic linker will
2070 /* Fill in the entry in the .rela.plt section. */
2071 rela
.r_offset
= (splt
->output_section
->vma
2072 + splt
->output_offset
2074 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_PPC_JMP_SLOT
);
2076 bfd_elf32_swap_reloca_out (output_bfd
, &rela
,
2077 ((Elf32_External_Rela
*) srela
->contents
2078 + ((h
->plt_offset
- PLT_INITIAL_ENTRY_SIZE
) / 8)));
2080 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
2082 /* Mark the symbol as undefined, rather than as defined in
2083 the .plt section. Leave the value alone. */
2084 sym
->st_shndx
= SHN_UNDEF
;
2088 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_COPY
) != 0)
2091 Elf_Internal_Rela rela
;
2093 /* This symbols needs a copy reloc. Set it up. */
2096 fprintf (stderr
, ", copy");
2099 BFD_ASSERT (h
->dynindx
!= -1);
2101 s
= bfd_get_section_by_name (h
->root
.u
.def
.section
->owner
,
2103 BFD_ASSERT (s
!= NULL
);
2105 rela
.r_offset
= (h
->root
.u
.def
.value
2106 + h
->root
.u
.def
.section
->output_section
->vma
2107 + h
->root
.u
.def
.section
->output_offset
);
2108 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_PPC_COPY
);
2110 bfd_elf32_swap_reloca_out (output_bfd
, &rela
,
2111 ((Elf32_External_Rela
*) s
->contents
2117 fprintf (stderr
, "\n");
2120 /* Mark some specially defined symbols as absolute. */
2121 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
2122 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0
2123 || strcmp (h
->root
.root
.string
, "_PROCEDURE_LINKAGE_TABLE_") == 0)
2124 sym
->st_shndx
= SHN_ABS
;
2130 /* Finish up the dynamic sections. */
2133 ppc_elf_finish_dynamic_sections (output_bfd
, info
)
2135 struct bfd_link_info
*info
;
2138 bfd
*dynobj
= elf_hash_table (info
)->dynobj
;
2139 elf_linker_section_t
*got
= elf_linker_section (dynobj
, LINKER_SECTION_GOT
);
2142 fprintf (stderr
, "ppc_elf_finish_dynamic_sections called\n");
2145 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
2147 if (elf_hash_table (info
)->dynamic_sections_created
)
2150 Elf32_External_Dyn
*dyncon
, *dynconend
;
2152 splt
= bfd_get_section_by_name (dynobj
, ".plt");
2153 BFD_ASSERT (splt
!= NULL
&& sdyn
!= NULL
);
2155 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
2156 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
2157 for (; dyncon
< dynconend
; dyncon
++)
2159 Elf_Internal_Dyn dyn
;
2163 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
2167 case DT_PLTGOT
: name
= ".plt"; size
= false; break;
2168 case DT_PLTRELSZ
: name
= ".rela.plt"; size
= true; break;
2169 case DT_JMPREL
: name
= ".rela.plt"; size
= false; break;
2170 default: name
= NULL
; size
= false; break;
2177 s
= bfd_get_section_by_name (output_bfd
, name
);
2183 dyn
.d_un
.d_ptr
= s
->vma
;
2186 if (s
->_cooked_size
!= 0)
2187 dyn
.d_un
.d_val
= s
->_cooked_size
;
2189 dyn
.d_un
.d_val
= s
->_raw_size
;
2192 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
2197 /* Add a blrl instruction at _GLOBAL_OFFSET_TABLE_-4 so that a function can
2198 easily find the address of the _GLOBAL_OFFSET_TABLE_. */
2201 unsigned char *contents
= got
->section
->contents
+ got
->hole_offset
;
2202 bfd_put_32 (output_bfd
, 0x4e800021 /* blrl */, contents
);
2205 bfd_put_32 (output_bfd
, (bfd_vma
) 0, contents
+4);
2207 bfd_put_32 (output_bfd
,
2208 sdyn
->output_section
->vma
+ sdyn
->output_offset
,
2211 elf_section_data (got
->section
->output_section
)->this_hdr
.sh_entsize
= 4;
2218 Elf_Internal_Sym sym
;
2220 /* Set up the section symbols for the output sections. */
2222 sdynsym
= bfd_get_section_by_name (dynobj
, ".dynsym");
2223 BFD_ASSERT (sdynsym
!= NULL
);
2227 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_SECTION
);
2230 for (s
= output_bfd
->sections
; s
!= NULL
; s
= s
->next
)
2234 sym
.st_value
= s
->vma
;
2236 indx
= elf_section_data (s
)->this_idx
;
2237 BFD_ASSERT (indx
> 0);
2238 sym
.st_shndx
= indx
;
2240 bfd_elf32_swap_symbol_out (output_bfd
, &sym
,
2241 (PTR
) (((Elf32_External_Sym
*)
2243 + elf_section_data (s
)->dynindx
));
2246 /* Set the sh_info field of the output .dynsym section to the
2247 index of the first global symbol. */
2248 elf_section_data (sdynsym
->output_section
)->this_hdr
.sh_info
=
2249 bfd_count_sections (output_bfd
) + 1;
2256 /* The RELOCATE_SECTION function is called by the ELF backend linker
2257 to handle the relocations for a section.
2259 The relocs are always passed as Rela structures; if the section
2260 actually uses Rel structures, the r_addend field will always be
2263 This function is responsible for adjust the section contents as
2264 necessary, and (if using Rela relocs and generating a
2265 relocateable output file) adjusting the reloc addend as
2268 This function does not have to worry about setting the reloc
2269 address or the reloc symbol index.
2271 LOCAL_SYMS is a pointer to the swapped in local symbols.
2273 LOCAL_SECTIONS is an array giving the section in the input file
2274 corresponding to the st_shndx field of each local symbol.
2276 The global hash table entry for the global symbols can be found
2277 via elf_sym_hashes (input_bfd).
2279 When generating relocateable output, this function must handle
2280 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
2281 going to be the section symbol corresponding to the output
2282 section, which means that the addend must be adjusted
2286 ppc_elf_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
2287 contents
, relocs
, local_syms
, local_sections
)
2289 struct bfd_link_info
*info
;
2291 asection
*input_section
;
2293 Elf_Internal_Rela
*relocs
;
2294 Elf_Internal_Sym
*local_syms
;
2295 asection
**local_sections
;
2297 Elf_Internal_Shdr
*symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
2298 struct elf_link_hash_entry
**sym_hashes
= elf_sym_hashes (input_bfd
);
2299 bfd
*dynobj
= elf_hash_table (info
)->dynobj
;
2300 elf_linker_section_t
*got
= (dynobj
) ? elf_linker_section (dynobj
, LINKER_SECTION_GOT
) : NULL
;
2301 elf_linker_section_t
*sdata
= (dynobj
) ? elf_linker_section (dynobj
, LINKER_SECTION_SDATA
) : NULL
;
2302 elf_linker_section_t
*sdata2
= (dynobj
) ? elf_linker_section (dynobj
, LINKER_SECTION_SDATA2
) : NULL
;
2303 Elf_Internal_Rela
*rel
= relocs
;
2304 Elf_Internal_Rela
*relend
= relocs
+ input_section
->reloc_count
;
2309 fprintf (stderr
, "ppc_elf_relocate_section called for %s section %s, %ld relocations%s\n",
2310 bfd_get_filename (input_bfd
),
2311 bfd_section_name(input_bfd
, input_section
),
2312 (long)input_section
->reloc_count
,
2313 (info
->relocateable
) ? " (relocatable)" : "");
2316 if (!ppc_elf_howto_table
[ R_PPC_ADDR32
]) /* Initialize howto table if needed */
2317 ppc_elf_howto_init ();
2319 for (; rel
< relend
; rel
++)
2321 enum ppc_reloc_type r_type
= (enum ppc_reloc_type
)ELF32_R_TYPE (rel
->r_info
);
2322 bfd_vma offset
= rel
->r_offset
;
2323 bfd_vma addend
= rel
->r_addend
;
2324 bfd_reloc_status_type r
= bfd_reloc_other
;
2325 Elf_Internal_Sym
*sym
= (Elf_Internal_Sym
*)0;
2326 asection
*sec
= (asection
*)0;
2327 struct elf_link_hash_entry
*h
= (struct elf_link_hash_entry
*)0;
2328 const char *sym_name
= (const char *)0;
2329 reloc_howto_type
*howto
;
2330 unsigned long r_symndx
;
2333 /* Unknown relocation handling */
2334 if ((unsigned)r_type
>= (unsigned)R_PPC_max
|| !ppc_elf_howto_table
[(int)r_type
])
2336 (*_bfd_error_handler
) ("%s: unknown relocation type %d",
2337 bfd_get_filename (input_bfd
),
2340 bfd_set_error (bfd_error_bad_value
);
2345 howto
= ppc_elf_howto_table
[(int)r_type
];
2346 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2348 if (info
->relocateable
)
2350 /* This is a relocateable link. We don't have to change
2351 anything, unless the reloc is against a section symbol,
2352 in which case we have to adjust according to where the
2353 section symbol winds up in the output section. */
2354 if (r_symndx
< symtab_hdr
->sh_info
)
2356 sym
= local_syms
+ r_symndx
;
2357 if ((unsigned)ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
2359 sec
= local_sections
[r_symndx
];
2360 addend
= rel
->r_addend
+= sec
->output_offset
+ sym
->st_value
;
2365 fprintf (stderr
, "\ttype = %s (%d), symbol index = %ld, offset = %ld, addend = %ld\n",
2375 /* This is a final link. */
2376 if (r_symndx
< symtab_hdr
->sh_info
)
2378 sym
= local_syms
+ r_symndx
;
2379 sec
= local_sections
[r_symndx
];
2380 sym_name
= "<local symbol>";
2382 relocation
= (sec
->output_section
->vma
2383 + sec
->output_offset
2388 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2389 while (h
->root
.type
== bfd_link_hash_indirect
2390 || h
->root
.type
== bfd_link_hash_warning
)
2391 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2392 sym_name
= h
->root
.root
.string
;
2393 if (h
->root
.type
== bfd_link_hash_defined
2394 || h
->root
.type
== bfd_link_hash_defweak
)
2396 sec
= h
->root
.u
.def
.section
;
2397 if (!sec
|| !sec
->output_section
)
2399 (*_bfd_error_handler
) ("%s: Section in shared library for symbol %s\n",
2400 bfd_get_filename (input_bfd
),
2405 relocation
= (h
->root
.u
.def
.value
2406 + sec
->output_section
->vma
2407 + sec
->output_offset
);
2409 else if (h
->root
.type
== bfd_link_hash_undefweak
)
2411 else if (info
->shared
)
2415 (*info
->callbacks
->undefined_symbol
)(info
,
2416 h
->root
.root
.string
,
2425 switch ((int)r_type
)
2428 (*_bfd_error_handler
) ("%s: unknown relocation type %d for symbol %s",
2429 bfd_get_filename (input_bfd
),
2430 (int)r_type
, sym_name
);
2432 bfd_set_error (bfd_error_bad_value
);
2436 /* relocations that need no special processing */
2437 case (int)R_PPC_NONE
:
2438 case (int)R_PPC_ADDR32
:
2439 case (int)R_PPC_ADDR24
:
2440 case (int)R_PPC_ADDR16
:
2441 case (int)R_PPC_ADDR16_LO
:
2442 case (int)R_PPC_ADDR16_HI
:
2443 case (int)R_PPC_ADDR14
:
2444 case (int)R_PPC_REL24
:
2445 case (int)R_PPC_REL14
:
2446 case (int)R_PPC_UADDR32
:
2447 case (int)R_PPC_UADDR16
:
2448 case (int)R_PPC_REL32
:
2451 /* branch taken prediction relocations */
2452 case (int)R_PPC_ADDR14_BRTAKEN
:
2453 case (int)R_PPC_REL14_BRTAKEN
:
2454 insn
= bfd_get_32 (output_bfd
, contents
+ offset
);
2455 if ((relocation
- offset
) & 0x8000)
2456 insn
&= ~BRANCH_PREDICT_BIT
;
2458 insn
|= BRANCH_PREDICT_BIT
;
2459 bfd_put_32 (output_bfd
, insn
, contents
+ offset
);
2462 /* branch not taken predicition relocations */
2463 case (int)R_PPC_ADDR14_BRNTAKEN
:
2464 case (int)R_PPC_REL14_BRNTAKEN
:
2465 insn
= bfd_get_32 (output_bfd
, contents
+ offset
);
2466 if ((relocation
- offset
) & 0x8000)
2467 insn
|= BRANCH_PREDICT_BIT
;
2469 insn
&= ~BRANCH_PREDICT_BIT
;
2470 bfd_put_32 (output_bfd
, insn
, contents
+ offset
);
2473 /* GOT16 relocations */
2474 case (int)R_PPC_GOT16
:
2475 case (int)R_PPC_GOT16_LO
:
2476 case (int)R_PPC_GOT16_HI
:
2477 case (int)R_PPC_GOT16_HA
:
2478 relocation
= bfd_elf32_finish_pointer_linker_section (output_bfd
, input_bfd
, info
,
2479 got
, h
, relocation
, rel
,
2483 /* Indirect .sdata relocation */
2484 case (int)R_PPC_EMB_SDAI16
:
2485 BFD_ASSERT (sdata
!= NULL
);
2486 relocation
= bfd_elf32_finish_pointer_linker_section (output_bfd
, input_bfd
, info
,
2487 sdata
, h
, relocation
, rel
,
2491 /* Indirect .sdata2 relocation */
2492 case (int)R_PPC_EMB_SDA2I16
:
2493 BFD_ASSERT (sdata2
!= NULL
);
2494 relocation
= bfd_elf32_finish_pointer_linker_section (output_bfd
, input_bfd
, info
,
2495 sdata2
, h
, relocation
, rel
,
2499 /* Handle the TOC16 reloc. We want to use the offset within the .got
2500 section, not the actual VMA. This is appropriate when generating
2501 an embedded ELF object, for which the .got section acts like the
2502 AIX .toc section. */
2503 case (int)R_PPC_TOC16
: /* phony GOT16 relocations */
2504 BFD_ASSERT (sec
!= (asection
*)0);
2505 BFD_ASSERT (bfd_is_und_section (sec
)
2506 || strcmp (bfd_get_section_name (abfd
, sec
), ".got") == 0
2507 || strcmp (bfd_get_section_name (abfd
, sec
), ".cgot") == 0)
2509 addend
-= sec
->output_section
->vma
+ sec
->output_offset
+ 0x8000;
2512 /* arithmetic adjust relocations */
2513 case (int)R_PPC_ADDR16_HA
:
2514 BFD_ASSERT (sec
!= (asection
*)0);
2515 addend
+= ((relocation
+ addend
) & 0x8000) << 1;
2518 /* relocate against _SDA_BASE_ */
2519 case (int)R_PPC_SDAREL16
:
2520 BFD_ASSERT (sec
!= (asection
*)0);
2521 if (strcmp (bfd_get_section_name (abfd
, sec
), ".sdata") != 0
2522 && strcmp (bfd_get_section_name (abfd
, sec
), ".sbss") != 0)
2524 (*_bfd_error_handler
) ("%s: The target (%s) of a %s relocation is in the wrong section (%s)",
2525 bfd_get_filename (input_bfd
),
2527 ppc_elf_howto_table
[ (int)r_type
]->name
,
2528 bfd_get_section_name (abfd
, sec
));
2530 bfd_set_error (bfd_error_bad_value
);
2534 addend
-= (sdata
->sym_hash
->root
.u
.def
.value
2535 + sdata
->sym_hash
->root
.u
.def
.section
->output_section
->vma
2536 + sdata
->sym_hash
->root
.u
.def
.section
->output_offset
);
2540 /* relocate against _SDA2_BASE_ */
2541 case (int)R_PPC_EMB_SDA2REL
:
2542 BFD_ASSERT (sec
!= (asection
*)0);
2543 if (strcmp (bfd_get_section_name (abfd
, sec
), ".sdata2") != 0
2544 && strcmp (bfd_get_section_name (abfd
, sec
), ".sbss2") != 0)
2546 (*_bfd_error_handler
) ("%s: The target (%s) of a %s relocation is in the wrong section (%s)",
2547 bfd_get_filename (input_bfd
),
2549 ppc_elf_howto_table
[ (int)r_type
]->name
,
2550 bfd_get_section_name (abfd
, sec
));
2552 bfd_set_error (bfd_error_bad_value
);
2556 addend
-= (sdata2
->sym_hash
->root
.u
.def
.value
2557 + sdata2
->sym_hash
->root
.u
.def
.section
->output_section
->vma
2558 + sdata2
->sym_hash
->root
.u
.def
.section
->output_offset
);
2562 /* relocate against either _SDA_BASE_, _SDA2_BASE_, or 0 */
2563 case (int)R_PPC_EMB_SDA21
:
2564 case (int)R_PPC_EMB_RELSDA
:
2566 const char *name
= bfd_get_section_name (abfd
, sec
);
2569 BFD_ASSERT (sec
!= (asection
*)0);
2570 if (strcmp (name
, ".sdata") == 0 || strcmp (name
, ".sbss") == 0)
2573 addend
-= (sdata
->sym_hash
->root
.u
.def
.value
2574 + sdata
->sym_hash
->root
.u
.def
.section
->output_section
->vma
2575 + sdata
->sym_hash
->root
.u
.def
.section
->output_offset
);
2578 else if (strcmp (name
, ".sdata2") == 0 || strcmp (name
, ".sbss2") == 0)
2581 addend
-= (sdata2
->sym_hash
->root
.u
.def
.value
2582 + sdata2
->sym_hash
->root
.u
.def
.section
->output_section
->vma
2583 + sdata2
->sym_hash
->root
.u
.def
.section
->output_offset
);
2586 else if (strcmp (name
, ".PPC.EMB.sdata0") == 0 || strcmp (name
, ".PPC.EMB.sbss0") == 0)
2593 (*_bfd_error_handler
) ("%s: The target (%s) of a %s relocation is in the wrong section (%s)",
2594 bfd_get_filename (input_bfd
),
2596 ppc_elf_howto_table
[ (int)r_type
]->name
,
2597 bfd_get_section_name (abfd
, sec
));
2599 bfd_set_error (bfd_error_bad_value
);
2604 if (r_type
== R_PPC_EMB_SDA21
)
2605 { /* fill in register field */
2606 insn
= bfd_get_32 (output_bfd
, contents
+ offset
);
2607 insn
= (insn
& ~RA_REGISTER_MASK
) | (reg
<< RA_REGISTER_SHIFT
);
2608 bfd_put_32 (output_bfd
, insn
, contents
+ offset
);
2613 /* Relocate against the beginning of the section */
2614 case (int)R_PPC_SECTOFF
:
2615 case (int)R_PPC_SECTOFF_LO
:
2616 case (int)R_PPC_SECTOFF_HI
:
2617 BFD_ASSERT (sec
!= (asection
*)0);
2618 addend
-= sec
->output_section
->vma
;
2621 case (int)R_PPC_SECTOFF_HA
:
2622 BFD_ASSERT (sec
!= (asection
*)0);
2623 addend
-= sec
->output_section
->vma
;
2624 addend
+= ((relocation
+ addend
) & 0x8000) << 1;
2627 /* Negative relocations */
2628 case (int)R_PPC_EMB_NADDR32
:
2629 case (int)R_PPC_EMB_NADDR16
:
2630 case (int)R_PPC_EMB_NADDR16_LO
:
2631 case (int)R_PPC_EMB_NADDR16_HI
:
2632 addend
-= 2*relocation
;
2635 case (int)R_PPC_EMB_NADDR16_HA
:
2636 addend
-= 2*relocation
;
2637 addend
+= ((relocation
+ addend
) & 0x8000) << 1;
2640 /* NOP relocation that prevents garbage collecting linkers from omitting a
2642 case (int)R_PPC_EMB_MRKREF
:
2645 case (int)R_PPC_PLTREL24
:
2646 case (int)R_PPC_COPY
:
2647 case (int)R_PPC_GLOB_DAT
:
2648 case (int)R_PPC_JMP_SLOT
:
2649 case (int)R_PPC_RELATIVE
:
2650 case (int)R_PPC_LOCAL24PC
:
2651 case (int)R_PPC_PLT32
:
2652 case (int)R_PPC_PLTREL32
:
2653 case (int)R_PPC_PLT16_LO
:
2654 case (int)R_PPC_PLT16_HI
:
2655 case (int)R_PPC_PLT16_HA
:
2656 case (int)R_PPC_EMB_RELSEC16
:
2657 case (int)R_PPC_EMB_RELST_LO
:
2658 case (int)R_PPC_EMB_RELST_HI
:
2659 case (int)R_PPC_EMB_RELST_HA
:
2660 case (int)R_PPC_EMB_BIT_FLD
:
2661 (*_bfd_error_handler
) ("%s: Relocation %s is not yet supported for symbol %s.",
2662 bfd_get_filename (input_bfd
),
2663 ppc_elf_howto_table
[ (int)r_type
]->name
,
2666 bfd_set_error (bfd_error_invalid_operation
);
2673 fprintf (stderr
, "\ttype = %s (%d), name = %s, symbol index = %ld, offset = %ld, addend = %ld\n",
2682 r
= _bfd_final_link_relocate (howto
,
2690 if (r
!= bfd_reloc_ok
)
2698 case bfd_reloc_overflow
:
2703 name
= h
->root
.root
.string
;
2706 name
= bfd_elf_string_from_elf_section (input_bfd
,
2707 symtab_hdr
->sh_link
,
2713 name
= bfd_section_name (input_bfd
, sec
);
2716 (*info
->callbacks
->reloc_overflow
)(info
,
2732 fprintf (stderr
, "\n");
2739 #define TARGET_LITTLE_SYM bfd_elf32_powerpcle_vec
2740 #define TARGET_LITTLE_NAME "elf32-powerpcle"
2741 #define TARGET_BIG_SYM bfd_elf32_powerpc_vec
2742 #define TARGET_BIG_NAME "elf32-powerpc"
2743 #define ELF_ARCH bfd_arch_powerpc
2744 #define ELF_MACHINE_CODE EM_PPC
2745 #define ELF_MAXPAGESIZE 0x10000
2746 #define elf_info_to_howto ppc_elf_info_to_howto
2748 #ifdef EM_CYGNUS_POWERPC
2749 #define ELF_MACHINE_ALT1 EM_CYGNUS_POWERPC
2753 #define ELF_MACHINE_ALT2 EM_PPC_OLD
2756 #define bfd_elf32_bfd_copy_private_bfd_data ppc_elf_copy_private_bfd_data
2757 #define bfd_elf32_bfd_merge_private_bfd_data ppc_elf_merge_private_bfd_data
2758 #define bfd_elf32_bfd_set_private_flags ppc_elf_set_private_flags
2759 #define bfd_elf32_bfd_reloc_type_lookup ppc_elf_reloc_type_lookup
2760 #define elf_backend_section_from_shdr ppc_elf_section_from_shdr
2761 #define elf_backend_relocate_section ppc_elf_relocate_section
2762 #define elf_backend_create_dynamic_sections _bfd_elf_create_dynamic_sections
2763 #define elf_backend_check_relocs ppc_elf_check_relocs
2764 #define elf_backend_adjust_dynamic_symbol ppc_elf_adjust_dynamic_symbol
2765 #define elf_backend_add_symbol_hook ppc_elf_add_symbol_hook
2766 #define elf_backend_size_dynamic_sections ppc_elf_size_dynamic_sections
2767 #define elf_backend_finish_dynamic_symbol ppc_elf_finish_dynamic_symbol
2768 #define elf_backend_finish_dynamic_sections ppc_elf_finish_dynamic_sections
2769 #define elf_backend_fake_sections ppc_elf_fake_sections
2770 #define elf_backend_additional_program_headers ppc_elf_additional_program_headers
2771 #define elf_backend_modify_segment_map ppc_elf_modify_segment_map
2773 #include "elf32-target.h"