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
;
1779 Elf_Internal_Shdr
*symtab_hdr
;
1780 struct elf_link_hash_entry
**sym_hashes
;
1781 const Elf_Internal_Rela
*rel
;
1782 const Elf_Internal_Rela
*rel_end
;
1783 elf_linker_section_t
*got
;
1784 elf_linker_section_t
*plt
;
1785 elf_linker_section_t
*sdata
;
1786 elf_linker_section_t
*sdata2
;
1789 if (info
->relocateable
)
1793 fprintf (stderr
, "ppc_elf_check_relocs called for section %s in %s\n",
1794 bfd_get_section_name (abfd
, sec
),
1795 bfd_get_filename (abfd
));
1798 /* Create the linker generated sections all the time so that the special
1799 symbols are created. */
1800 if ((got
= elf_linker_section (abfd
, LINKER_SECTION_GOT
)) == NULL
)
1802 got
= ppc_elf_create_linker_section (abfd
, info
, LINKER_SECTION_GOT
);
1808 if ((plt
= elf_linker_section (abfd
, LINKER_SECTION_PLT
)) == NULL
)
1810 plt
= ppc_elf_create_linker_section (abfd
, info
, LINKER_SECTION_PLT
);
1816 if ((sdata
= elf_linker_section (abfd
, LINKER_SECTION_SDATA
)) == NULL
)
1818 sdata
= ppc_elf_create_linker_section (abfd
, info
, LINKER_SECTION_SDATA
);
1824 if ((sdata2
= elf_linker_section (abfd
, LINKER_SECTION_SDATA2
)) == NULL
)
1826 sdata2
= ppc_elf_create_linker_section (abfd
, info
, LINKER_SECTION_SDATA2
);
1831 dynobj
= elf_hash_table (info
)->dynobj
;
1832 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
1833 sym_hashes
= elf_sym_hashes (abfd
);
1837 rel_end
= relocs
+ sec
->reloc_count
;
1838 for (rel
= relocs
; rel
< rel_end
; rel
++)
1840 unsigned long r_symndx
;
1841 struct elf_link_hash_entry
*h
;
1843 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1844 if (r_symndx
< symtab_hdr
->sh_info
)
1847 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1849 switch (ELF32_R_TYPE (rel
->r_info
))
1851 /* GOT16 relocations */
1853 case R_PPC_GOT16_LO
:
1854 case R_PPC_GOT16_HI
:
1855 case R_PPC_GOT16_HA
:
1856 if (got
->rel_section
== NULL
1857 && (h
!= NULL
|| info
->shared
)
1858 && !_bfd_elf_make_linker_section_rela (dynobj
, got
, 2))
1864 if (!bfd_elf32_create_pointer_linker_section (abfd
, info
, got
, h
, rel
))
1869 /* Indirect .sdata relocation */
1870 case R_PPC_EMB_SDAI16
:
1873 (*_bfd_error_handler
) ("%s: relocation %s cannot be used when making a shared object",
1874 bfd_get_filename (abfd
),
1875 "R_PPC_EMB_SDAI16");
1880 if (got
->rel_section
== NULL
1881 && (h
!= NULL
|| info
->shared
)
1882 && !_bfd_elf_make_linker_section_rela (dynobj
, got
, 2))
1888 if (!bfd_elf32_create_pointer_linker_section (abfd
, info
, sdata
, h
, rel
))
1893 /* Indirect .sdata2 relocation */
1894 case R_PPC_EMB_SDA2I16
:
1897 (*_bfd_error_handler
) ("%s: relocation %s cannot be used when making a shared object",
1898 bfd_get_filename (abfd
),
1899 "R_PPC_EMB_SDA2I16");
1904 if (got
->rel_section
== NULL
1905 && (h
!= NULL
|| info
->shared
)
1906 && !_bfd_elf_make_linker_section_rela (dynobj
, got
, 2))
1909 if (!bfd_elf32_create_pointer_linker_section (abfd
, info
, sdata2
, h
, rel
))
1914 case R_PPC_SDAREL16
:
1915 case R_PPC_EMB_SDA2REL
:
1916 case R_PPC_EMB_SDA21
:
1919 (*_bfd_error_handler
) ("%s: relocation %s cannot be used when making a shared object",
1920 bfd_get_filename (abfd
),
1921 ppc_elf_howto_table
[(int)ELF32_R_TYPE (rel
->r_info
)]->name
);
1927 case R_PPC_PLTREL24
:
1928 case R_PPC_PLT16_LO
:
1929 case R_PPC_PLT16_HI
:
1930 case R_PPC_PLT16_HA
:
1932 fprintf (stderr
, "Reloc requires a PLT entry\n");
1934 /* This symbol requires a procedure linkage table entry. We
1935 actually build the entry in adjust_dynamic_symbol,
1936 because this might be a case of linking PIC code without
1937 linking in any dynamic objects, in which case we don't
1938 need to generate a procedure linkage table after all. */
1942 /* It does not make sense to have a procedure linkage
1943 table entry for a local symbol. */
1944 bfd_set_error (bfd_error_bad_value
);
1949 /* Make sure this symbol is output as a dynamic symbol. */
1950 if (h
->dynindx
== -1)
1952 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
1959 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
1962 /* the following relocations don't need to propigate the relocation if
1963 linking a shared object since they are section relative. */
1965 case R_PPC_SECTOFF_LO
:
1966 case R_PPC_SECTOFF_HI
:
1967 case R_PPC_SECTOFF_HA
:
1970 /* When creating a shared object, we must copy these
1971 relocs into the output file. We create a reloc
1972 section in dynobj and make room for the reloc. */
1975 && strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
1980 case R_PPC_REL14_BRTAKEN
:
1981 case R_PPC_REL14_BRNTAKEN
:
1988 && (sec
->flags
& SEC_ALLOC
) != 0)
1994 name
= (bfd_elf_string_from_elf_section
1996 elf_elfheader (abfd
)->e_shstrndx
,
1997 elf_section_data (sec
)->rel_hdr
.sh_name
));
2004 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
2005 && strcmp (bfd_get_section_name (abfd
, sec
),
2008 sreloc
= bfd_get_section_by_name (dynobj
, name
);
2011 sreloc
= bfd_make_section (dynobj
, name
);
2013 || ! bfd_set_section_flags (dynobj
, sreloc
,
2019 || ! bfd_set_section_alignment (dynobj
, sreloc
, 2))
2027 sreloc
->_raw_size
+= sizeof (Elf32_External_Rela
);
2038 /* Hook called by the linker routine which adds symbols from an object
2039 file. We use it to put .comm items in .sbss, and not .bss. */
2043 ppc_elf_add_symbol_hook (abfd
, info
, sym
, namep
, flagsp
, secp
, valp
)
2045 struct bfd_link_info
*info
;
2046 const Elf_Internal_Sym
*sym
;
2052 if (sym
->st_shndx
== SHN_COMMON
&& !info
->relocateable
&& sym
->st_size
<= bfd_get_gp_size (abfd
))
2054 /* Common symbols less than or equal to -G nn bytes are automatically
2056 elf_linker_section_t
*sdata
= ppc_elf_create_linker_section (abfd
, info
, LINKER_SECTION_SDATA
);
2057 if (!sdata
->bss_section
)
2059 sdata
->bss_section
= bfd_make_section (elf_hash_table (info
)->dynobj
, sdata
->bss_name
);
2060 sdata
->bss_section
->flags
= (sdata
->bss_section
->flags
& ~SEC_LOAD
) | SEC_IS_COMMON
;
2063 *secp
= sdata
->bss_section
;
2064 *valp
= sym
->st_size
;
2071 /* Finish up dynamic symbol handling. We set the contents of various
2072 dynamic sections here. */
2075 ppc_elf_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
2077 struct bfd_link_info
*info
;
2078 struct elf_link_hash_entry
*h
;
2079 Elf_Internal_Sym
*sym
;
2084 fprintf (stderr
, "ppc_elf_finish_dynamic_symbol called for %s", h
->root
.root
.string
);
2087 dynobj
= elf_hash_table (info
)->dynobj
;
2088 BFD_ASSERT (dynobj
!= NULL
);
2090 if (h
->plt_offset
!= (bfd_vma
) -1)
2094 Elf_Internal_Rela rela
;
2097 fprintf (stderr
, ", plt_offset = %d", h
->plt_offset
);
2100 /* This symbol has an entry in the procedure linkage table. Set
2103 BFD_ASSERT (h
->dynindx
!= -1);
2105 splt
= bfd_get_section_by_name (dynobj
, ".plt");
2106 srela
= bfd_get_section_by_name (dynobj
, ".rela.plt");
2107 BFD_ASSERT (splt
!= NULL
&& srela
!= NULL
);
2109 /* We don't need to fill in the .plt. The solaris dynamic linker will
2112 /* Fill in the entry in the .rela.plt section. */
2113 rela
.r_offset
= (splt
->output_section
->vma
2114 + splt
->output_offset
2116 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_PPC_JMP_SLOT
);
2118 bfd_elf32_swap_reloca_out (output_bfd
, &rela
,
2119 ((Elf32_External_Rela
*) srela
->contents
2120 + ((h
->plt_offset
- PLT_INITIAL_ENTRY_SIZE
) / 8)));
2122 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
2124 /* Mark the symbol as undefined, rather than as defined in
2125 the .plt section. Leave the value alone. */
2126 sym
->st_shndx
= SHN_UNDEF
;
2130 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_COPY
) != 0)
2133 Elf_Internal_Rela rela
;
2135 /* This symbols needs a copy reloc. Set it up. */
2138 fprintf (stderr
, ", copy");
2141 BFD_ASSERT (h
->dynindx
!= -1);
2143 s
= bfd_get_section_by_name (h
->root
.u
.def
.section
->owner
,
2145 BFD_ASSERT (s
!= NULL
);
2147 rela
.r_offset
= (h
->root
.u
.def
.value
2148 + h
->root
.u
.def
.section
->output_section
->vma
2149 + h
->root
.u
.def
.section
->output_offset
);
2150 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_PPC_COPY
);
2152 bfd_elf32_swap_reloca_out (output_bfd
, &rela
,
2153 ((Elf32_External_Rela
*) s
->contents
2159 fprintf (stderr
, "\n");
2162 /* Mark some specially defined symbols as absolute. */
2163 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
2164 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0
2165 || strcmp (h
->root
.root
.string
, "_PROCEDURE_LINKAGE_TABLE_") == 0)
2166 sym
->st_shndx
= SHN_ABS
;
2172 /* Finish up the dynamic sections. */
2175 ppc_elf_finish_dynamic_sections (output_bfd
, info
)
2177 struct bfd_link_info
*info
;
2180 bfd
*dynobj
= elf_hash_table (info
)->dynobj
;
2181 elf_linker_section_t
*got
= elf_linker_section (dynobj
, LINKER_SECTION_GOT
);
2184 fprintf (stderr
, "ppc_elf_finish_dynamic_sections called\n");
2187 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
2189 if (elf_hash_table (info
)->dynamic_sections_created
)
2192 Elf32_External_Dyn
*dyncon
, *dynconend
;
2194 splt
= bfd_get_section_by_name (dynobj
, ".plt");
2195 BFD_ASSERT (splt
!= NULL
&& sdyn
!= NULL
);
2197 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
2198 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
2199 for (; dyncon
< dynconend
; dyncon
++)
2201 Elf_Internal_Dyn dyn
;
2205 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
2209 case DT_PLTGOT
: name
= ".plt"; size
= false; break;
2210 case DT_PLTRELSZ
: name
= ".rela.plt"; size
= true; break;
2211 case DT_JMPREL
: name
= ".rela.plt"; size
= false; break;
2212 default: name
= NULL
; size
= false; break;
2219 s
= bfd_get_section_by_name (output_bfd
, name
);
2225 dyn
.d_un
.d_ptr
= s
->vma
;
2228 if (s
->_cooked_size
!= 0)
2229 dyn
.d_un
.d_val
= s
->_cooked_size
;
2231 dyn
.d_un
.d_val
= s
->_raw_size
;
2234 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
2239 /* Add a blrl instruction at _GLOBAL_OFFSET_TABLE_-4 so that a function can
2240 easily find the address of the _GLOBAL_OFFSET_TABLE_. */
2243 unsigned char *contents
= got
->section
->contents
+ got
->hole_offset
;
2244 bfd_put_32 (output_bfd
, 0x4e800021 /* blrl */, contents
);
2247 bfd_put_32 (output_bfd
, (bfd_vma
) 0, contents
+4);
2249 bfd_put_32 (output_bfd
,
2250 sdyn
->output_section
->vma
+ sdyn
->output_offset
,
2253 elf_section_data (got
->section
->output_section
)->this_hdr
.sh_entsize
= 4;
2260 Elf_Internal_Sym sym
;
2262 /* Set up the section symbols for the output sections. */
2264 sdynsym
= bfd_get_section_by_name (dynobj
, ".dynsym");
2265 BFD_ASSERT (sdynsym
!= NULL
);
2269 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_SECTION
);
2272 for (s
= output_bfd
->sections
; s
!= NULL
; s
= s
->next
)
2276 sym
.st_value
= s
->vma
;
2278 indx
= elf_section_data (s
)->this_idx
;
2279 BFD_ASSERT (indx
> 0);
2280 sym
.st_shndx
= indx
;
2282 bfd_elf32_swap_symbol_out (output_bfd
, &sym
,
2283 (PTR
) (((Elf32_External_Sym
*)
2285 + elf_section_data (s
)->dynindx
));
2288 /* Set the sh_info field of the output .dynsym section to the
2289 index of the first global symbol. */
2290 elf_section_data (sdynsym
->output_section
)->this_hdr
.sh_info
=
2291 bfd_count_sections (output_bfd
) + 1;
2298 /* The RELOCATE_SECTION function is called by the ELF backend linker
2299 to handle the relocations for a section.
2301 The relocs are always passed as Rela structures; if the section
2302 actually uses Rel structures, the r_addend field will always be
2305 This function is responsible for adjust the section contents as
2306 necessary, and (if using Rela relocs and generating a
2307 relocateable output file) adjusting the reloc addend as
2310 This function does not have to worry about setting the reloc
2311 address or the reloc symbol index.
2313 LOCAL_SYMS is a pointer to the swapped in local symbols.
2315 LOCAL_SECTIONS is an array giving the section in the input file
2316 corresponding to the st_shndx field of each local symbol.
2318 The global hash table entry for the global symbols can be found
2319 via elf_sym_hashes (input_bfd).
2321 When generating relocateable output, this function must handle
2322 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
2323 going to be the section symbol corresponding to the output
2324 section, which means that the addend must be adjusted
2328 ppc_elf_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
2329 contents
, relocs
, local_syms
, local_sections
)
2331 struct bfd_link_info
*info
;
2333 asection
*input_section
;
2335 Elf_Internal_Rela
*relocs
;
2336 Elf_Internal_Sym
*local_syms
;
2337 asection
**local_sections
;
2339 Elf_Internal_Shdr
*symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
2340 struct elf_link_hash_entry
**sym_hashes
= elf_sym_hashes (input_bfd
);
2341 bfd
*dynobj
= elf_hash_table (info
)->dynobj
;
2342 elf_linker_section_t
*got
= (dynobj
) ? elf_linker_section (dynobj
, LINKER_SECTION_GOT
) : NULL
;
2343 elf_linker_section_t
*sdata
= (dynobj
) ? elf_linker_section (dynobj
, LINKER_SECTION_SDATA
) : NULL
;
2344 elf_linker_section_t
*sdata2
= (dynobj
) ? elf_linker_section (dynobj
, LINKER_SECTION_SDATA2
) : NULL
;
2345 Elf_Internal_Rela
*rel
= relocs
;
2346 Elf_Internal_Rela
*relend
= relocs
+ input_section
->reloc_count
;
2351 fprintf (stderr
, "ppc_elf_relocate_section called for %s section %s, %ld relocations%s\n",
2352 bfd_get_filename (input_bfd
),
2353 bfd_section_name(input_bfd
, input_section
),
2354 (long)input_section
->reloc_count
,
2355 (info
->relocateable
) ? " (relocatable)" : "");
2358 if (!ppc_elf_howto_table
[ R_PPC_ADDR32
]) /* Initialize howto table if needed */
2359 ppc_elf_howto_init ();
2361 for (; rel
< relend
; rel
++)
2363 enum ppc_reloc_type r_type
= (enum ppc_reloc_type
)ELF32_R_TYPE (rel
->r_info
);
2364 bfd_vma offset
= rel
->r_offset
;
2365 bfd_vma addend
= rel
->r_addend
;
2366 bfd_reloc_status_type r
= bfd_reloc_other
;
2367 Elf_Internal_Sym
*sym
= (Elf_Internal_Sym
*)0;
2368 asection
*sec
= (asection
*)0;
2369 struct elf_link_hash_entry
*h
= (struct elf_link_hash_entry
*)0;
2370 const char *sym_name
= (const char *)0;
2371 reloc_howto_type
*howto
;
2372 unsigned long r_symndx
;
2375 /* Unknown relocation handling */
2376 if ((unsigned)r_type
>= (unsigned)R_PPC_max
|| !ppc_elf_howto_table
[(int)r_type
])
2378 (*_bfd_error_handler
) ("%s: unknown relocation type %d",
2379 bfd_get_filename (input_bfd
),
2382 bfd_set_error (bfd_error_bad_value
);
2387 howto
= ppc_elf_howto_table
[(int)r_type
];
2388 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2390 if (info
->relocateable
)
2392 /* This is a relocateable link. We don't have to change
2393 anything, unless the reloc is against a section symbol,
2394 in which case we have to adjust according to where the
2395 section symbol winds up in the output section. */
2396 if (r_symndx
< symtab_hdr
->sh_info
)
2398 sym
= local_syms
+ r_symndx
;
2399 if ((unsigned)ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
2401 sec
= local_sections
[r_symndx
];
2402 addend
= rel
->r_addend
+= sec
->output_offset
+ sym
->st_value
;
2407 fprintf (stderr
, "\ttype = %s (%d), symbol index = %ld, offset = %ld, addend = %ld\n",
2417 /* This is a final link. */
2418 if (r_symndx
< symtab_hdr
->sh_info
)
2420 sym
= local_syms
+ r_symndx
;
2421 sec
= local_sections
[r_symndx
];
2422 sym_name
= "<local symbol>";
2424 relocation
= (sec
->output_section
->vma
2425 + sec
->output_offset
2430 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2431 while (h
->root
.type
== bfd_link_hash_indirect
2432 || h
->root
.type
== bfd_link_hash_warning
)
2433 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2434 sym_name
= h
->root
.root
.string
;
2435 if (h
->root
.type
== bfd_link_hash_defined
2436 || h
->root
.type
== bfd_link_hash_defweak
)
2438 sec
= h
->root
.u
.def
.section
;
2439 if (!sec
|| !sec
->output_section
)
2441 (*_bfd_error_handler
) ("%s: Section in shared library for symbol %s\n",
2442 bfd_get_filename (input_bfd
),
2447 relocation
= (h
->root
.u
.def
.value
2448 + sec
->output_section
->vma
2449 + sec
->output_offset
);
2451 else if (h
->root
.type
== bfd_link_hash_undefweak
)
2453 else if (info
->shared
)
2457 (*info
->callbacks
->undefined_symbol
)(info
,
2458 h
->root
.root
.string
,
2467 switch ((int)r_type
)
2470 (*_bfd_error_handler
) ("%s: unknown relocation type %d for symbol %s",
2471 bfd_get_filename (input_bfd
),
2472 (int)r_type
, sym_name
);
2474 bfd_set_error (bfd_error_bad_value
);
2478 /* relocations that need no special processing */
2479 case (int)R_PPC_NONE
:
2480 case (int)R_PPC_ADDR32
:
2481 case (int)R_PPC_ADDR24
:
2482 case (int)R_PPC_ADDR16
:
2483 case (int)R_PPC_ADDR16_LO
:
2484 case (int)R_PPC_ADDR16_HI
:
2485 case (int)R_PPC_ADDR14
:
2486 case (int)R_PPC_REL24
:
2487 case (int)R_PPC_REL14
:
2488 case (int)R_PPC_UADDR32
:
2489 case (int)R_PPC_UADDR16
:
2490 case (int)R_PPC_REL32
:
2493 /* branch taken prediction relocations */
2494 case (int)R_PPC_ADDR14_BRTAKEN
:
2495 case (int)R_PPC_REL14_BRTAKEN
:
2496 insn
= bfd_get_32 (output_bfd
, contents
+ offset
);
2497 if ((relocation
- offset
) & 0x8000)
2498 insn
&= ~BRANCH_PREDICT_BIT
;
2500 insn
|= BRANCH_PREDICT_BIT
;
2501 bfd_put_32 (output_bfd
, insn
, contents
+ offset
);
2504 /* branch not taken predicition relocations */
2505 case (int)R_PPC_ADDR14_BRNTAKEN
:
2506 case (int)R_PPC_REL14_BRNTAKEN
:
2507 insn
= bfd_get_32 (output_bfd
, contents
+ offset
);
2508 if ((relocation
- offset
) & 0x8000)
2509 insn
|= BRANCH_PREDICT_BIT
;
2511 insn
&= ~BRANCH_PREDICT_BIT
;
2512 bfd_put_32 (output_bfd
, insn
, contents
+ offset
);
2515 /* GOT16 relocations */
2516 case (int)R_PPC_GOT16
:
2517 case (int)R_PPC_GOT16_LO
:
2518 case (int)R_PPC_GOT16_HI
:
2519 case (int)R_PPC_GOT16_HA
:
2520 relocation
= bfd_elf32_finish_pointer_linker_section (output_bfd
, input_bfd
, info
,
2521 got
, h
, relocation
, rel
,
2525 /* Indirect .sdata relocation */
2526 case (int)R_PPC_EMB_SDAI16
:
2527 BFD_ASSERT (sdata
!= NULL
);
2528 relocation
= bfd_elf32_finish_pointer_linker_section (output_bfd
, input_bfd
, info
,
2529 sdata
, h
, relocation
, rel
,
2533 /* Indirect .sdata2 relocation */
2534 case (int)R_PPC_EMB_SDA2I16
:
2535 BFD_ASSERT (sdata2
!= NULL
);
2536 relocation
= bfd_elf32_finish_pointer_linker_section (output_bfd
, input_bfd
, info
,
2537 sdata2
, h
, relocation
, rel
,
2541 /* Handle the TOC16 reloc. We want to use the offset within the .got
2542 section, not the actual VMA. This is appropriate when generating
2543 an embedded ELF object, for which the .got section acts like the
2544 AIX .toc section. */
2545 case (int)R_PPC_TOC16
: /* phony GOT16 relocations */
2546 BFD_ASSERT (sec
!= (asection
*)0);
2547 BFD_ASSERT (bfd_is_und_section (sec
)
2548 || strcmp (bfd_get_section_name (abfd
, sec
), ".got") == 0
2549 || strcmp (bfd_get_section_name (abfd
, sec
), ".cgot") == 0)
2551 addend
-= sec
->output_section
->vma
+ sec
->output_offset
+ 0x8000;
2554 /* arithmetic adjust relocations */
2555 case (int)R_PPC_ADDR16_HA
:
2556 BFD_ASSERT (sec
!= (asection
*)0);
2557 addend
+= ((relocation
+ addend
) & 0x8000) << 1;
2560 /* relocate against _SDA_BASE_ */
2561 case (int)R_PPC_SDAREL16
:
2562 BFD_ASSERT (sec
!= (asection
*)0);
2563 if (strcmp (bfd_get_section_name (abfd
, sec
), ".sdata") != 0
2564 && strcmp (bfd_get_section_name (abfd
, sec
), ".sbss") != 0)
2566 (*_bfd_error_handler
) ("%s: The target (%s) of a %s relocation is in the wrong section (%s)",
2567 bfd_get_filename (input_bfd
),
2569 ppc_elf_howto_table
[ (int)r_type
]->name
,
2570 bfd_get_section_name (abfd
, sec
));
2572 bfd_set_error (bfd_error_bad_value
);
2576 addend
-= (sdata
->sym_hash
->root
.u
.def
.value
2577 + sdata
->sym_hash
->root
.u
.def
.section
->output_section
->vma
2578 + sdata
->sym_hash
->root
.u
.def
.section
->output_offset
);
2582 /* relocate against _SDA2_BASE_ */
2583 case (int)R_PPC_EMB_SDA2REL
:
2584 BFD_ASSERT (sec
!= (asection
*)0);
2585 if (strcmp (bfd_get_section_name (abfd
, sec
), ".sdata2") != 0
2586 && strcmp (bfd_get_section_name (abfd
, sec
), ".sbss2") != 0)
2588 (*_bfd_error_handler
) ("%s: The target (%s) of a %s relocation is in the wrong section (%s)",
2589 bfd_get_filename (input_bfd
),
2591 ppc_elf_howto_table
[ (int)r_type
]->name
,
2592 bfd_get_section_name (abfd
, sec
));
2594 bfd_set_error (bfd_error_bad_value
);
2598 addend
-= (sdata2
->sym_hash
->root
.u
.def
.value
2599 + sdata2
->sym_hash
->root
.u
.def
.section
->output_section
->vma
2600 + sdata2
->sym_hash
->root
.u
.def
.section
->output_offset
);
2604 /* relocate against either _SDA_BASE_, _SDA2_BASE_, or 0 */
2605 case (int)R_PPC_EMB_SDA21
:
2606 case (int)R_PPC_EMB_RELSDA
:
2608 const char *name
= bfd_get_section_name (abfd
, sec
);
2611 BFD_ASSERT (sec
!= (asection
*)0);
2612 if (strcmp (name
, ".sdata") == 0 || strcmp (name
, ".sbss") == 0)
2615 addend
-= (sdata
->sym_hash
->root
.u
.def
.value
2616 + sdata
->sym_hash
->root
.u
.def
.section
->output_section
->vma
2617 + sdata
->sym_hash
->root
.u
.def
.section
->output_offset
);
2620 else if (strcmp (name
, ".sdata2") == 0 || strcmp (name
, ".sbss2") == 0)
2623 addend
-= (sdata2
->sym_hash
->root
.u
.def
.value
2624 + sdata2
->sym_hash
->root
.u
.def
.section
->output_section
->vma
2625 + sdata2
->sym_hash
->root
.u
.def
.section
->output_offset
);
2628 else if (strcmp (name
, ".PPC.EMB.sdata0") == 0 || strcmp (name
, ".PPC.EMB.sbss0") == 0)
2635 (*_bfd_error_handler
) ("%s: The target (%s) of a %s relocation is in the wrong section (%s)",
2636 bfd_get_filename (input_bfd
),
2638 ppc_elf_howto_table
[ (int)r_type
]->name
,
2639 bfd_get_section_name (abfd
, sec
));
2641 bfd_set_error (bfd_error_bad_value
);
2646 if (r_type
== R_PPC_EMB_SDA21
)
2647 { /* fill in register field */
2648 insn
= bfd_get_32 (output_bfd
, contents
+ offset
);
2649 insn
= (insn
& ~RA_REGISTER_MASK
) | (reg
<< RA_REGISTER_SHIFT
);
2650 bfd_put_32 (output_bfd
, insn
, contents
+ offset
);
2655 /* Relocate against the beginning of the section */
2656 case (int)R_PPC_SECTOFF
:
2657 case (int)R_PPC_SECTOFF_LO
:
2658 case (int)R_PPC_SECTOFF_HI
:
2659 BFD_ASSERT (sec
!= (asection
*)0);
2660 addend
-= sec
->output_section
->vma
;
2663 case (int)R_PPC_SECTOFF_HA
:
2664 BFD_ASSERT (sec
!= (asection
*)0);
2665 addend
-= sec
->output_section
->vma
;
2666 addend
+= ((relocation
+ addend
) & 0x8000) << 1;
2669 /* Negative relocations */
2670 case (int)R_PPC_EMB_NADDR32
:
2671 case (int)R_PPC_EMB_NADDR16
:
2672 case (int)R_PPC_EMB_NADDR16_LO
:
2673 case (int)R_PPC_EMB_NADDR16_HI
:
2674 addend
-= 2*relocation
;
2677 case (int)R_PPC_EMB_NADDR16_HA
:
2678 addend
-= 2*relocation
;
2679 addend
+= ((relocation
+ addend
) & 0x8000) << 1;
2682 /* NOP relocation that prevents garbage collecting linkers from omitting a
2684 case (int)R_PPC_EMB_MRKREF
:
2687 case (int)R_PPC_PLTREL24
:
2688 case (int)R_PPC_COPY
:
2689 case (int)R_PPC_GLOB_DAT
:
2690 case (int)R_PPC_JMP_SLOT
:
2691 case (int)R_PPC_RELATIVE
:
2692 case (int)R_PPC_LOCAL24PC
:
2693 case (int)R_PPC_PLT32
:
2694 case (int)R_PPC_PLTREL32
:
2695 case (int)R_PPC_PLT16_LO
:
2696 case (int)R_PPC_PLT16_HI
:
2697 case (int)R_PPC_PLT16_HA
:
2698 case (int)R_PPC_EMB_RELSEC16
:
2699 case (int)R_PPC_EMB_RELST_LO
:
2700 case (int)R_PPC_EMB_RELST_HI
:
2701 case (int)R_PPC_EMB_RELST_HA
:
2702 case (int)R_PPC_EMB_BIT_FLD
:
2703 (*_bfd_error_handler
) ("%s: Relocation %s is not yet supported for symbol %s.",
2704 bfd_get_filename (input_bfd
),
2705 ppc_elf_howto_table
[ (int)r_type
]->name
,
2708 bfd_set_error (bfd_error_invalid_operation
);
2715 fprintf (stderr
, "\ttype = %s (%d), name = %s, symbol index = %ld, offset = %ld, addend = %ld\n",
2724 r
= _bfd_final_link_relocate (howto
,
2732 if (r
!= bfd_reloc_ok
)
2740 case bfd_reloc_overflow
:
2745 name
= h
->root
.root
.string
;
2748 name
= bfd_elf_string_from_elf_section (input_bfd
,
2749 symtab_hdr
->sh_link
,
2755 name
= bfd_section_name (input_bfd
, sec
);
2758 (*info
->callbacks
->reloc_overflow
)(info
,
2774 fprintf (stderr
, "\n");
2781 #define TARGET_LITTLE_SYM bfd_elf32_powerpcle_vec
2782 #define TARGET_LITTLE_NAME "elf32-powerpcle"
2783 #define TARGET_BIG_SYM bfd_elf32_powerpc_vec
2784 #define TARGET_BIG_NAME "elf32-powerpc"
2785 #define ELF_ARCH bfd_arch_powerpc
2786 #define ELF_MACHINE_CODE EM_PPC
2787 #define ELF_MAXPAGESIZE 0x10000
2788 #define elf_info_to_howto ppc_elf_info_to_howto
2790 #ifdef EM_CYGNUS_POWERPC
2791 #define ELF_MACHINE_ALT1 EM_CYGNUS_POWERPC
2795 #define ELF_MACHINE_ALT2 EM_PPC_OLD
2798 #define bfd_elf32_bfd_copy_private_bfd_data ppc_elf_copy_private_bfd_data
2799 #define bfd_elf32_bfd_merge_private_bfd_data ppc_elf_merge_private_bfd_data
2800 #define bfd_elf32_bfd_set_private_flags ppc_elf_set_private_flags
2801 #define bfd_elf32_bfd_reloc_type_lookup ppc_elf_reloc_type_lookup
2802 #define elf_backend_section_from_shdr ppc_elf_section_from_shdr
2803 #define elf_backend_relocate_section ppc_elf_relocate_section
2804 #define elf_backend_create_dynamic_sections _bfd_elf_create_dynamic_sections
2805 #define elf_backend_check_relocs ppc_elf_check_relocs
2806 #define elf_backend_adjust_dynamic_symbol ppc_elf_adjust_dynamic_symbol
2807 #define elf_backend_add_symbol_hook ppc_elf_add_symbol_hook
2808 #define elf_backend_size_dynamic_sections ppc_elf_size_dynamic_sections
2809 #define elf_backend_finish_dynamic_symbol ppc_elf_finish_dynamic_symbol
2810 #define elf_backend_finish_dynamic_sections ppc_elf_finish_dynamic_sections
2811 #define elf_backend_fake_sections ppc_elf_fake_sections
2812 #define elf_backend_additional_program_headers ppc_elf_additional_program_headers
2813 #define elf_backend_modify_segment_map ppc_elf_modify_segment_map
2815 #include "elf32-target.h"