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 bfd_reloc_status_type ppc_elf_unsupported_reloc
103 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
104 static bfd_reloc_status_type ppc_elf_std_reloc
105 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
107 static reloc_howto_type
*ppc_elf_reloc_type_lookup
108 PARAMS ((bfd
*abfd
, bfd_reloc_code_real_type code
));
109 static void ppc_elf_info_to_howto
110 PARAMS ((bfd
*abfd
, arelent
*cache_ptr
, Elf32_Internal_Rela
*dst
));
111 static void ppc_elf_howto_init
PARAMS ((void));
112 static boolean ppc_elf_set_private_flags
PARAMS ((bfd
*, flagword
));
113 static boolean ppc_elf_copy_private_bfd_data
PARAMS ((bfd
*, bfd
*));
114 static boolean ppc_elf_merge_private_bfd_data
PARAMS ((bfd
*, bfd
*));
116 static boolean ppc_elf_section_from_shdr
PARAMS ((bfd
*,
117 Elf32_Internal_Shdr
*,
120 static bfd
*ppc_elf_create_dynamic_sections
PARAMS ((bfd
*abfd
,
121 struct bfd_link_info
*info
));
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_finish_dynamic_symbol
PARAMS ((bfd
*,
145 struct bfd_link_info
*,
146 struct elf_link_hash_entry
*,
147 Elf_Internal_Sym
*));
149 static boolean ppc_elf_finish_dynamic_sections
PARAMS ((bfd
*, struct bfd_link_info
*));
151 #define BRANCH_PREDICT_BIT 0x200000
153 /* The name of the dynamic interpreter. This is put in the .interp
156 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
159 static reloc_howto_type
*ppc_elf_howto_table
[ (int)R_PPC_max
];
161 static reloc_howto_type ppc_elf_howto_raw
[] =
163 /* This reloc does nothing. */
164 HOWTO (R_PPC_NONE
, /* type */
166 2, /* size (0 = byte, 1 = short, 2 = long) */
168 false, /* pc_relative */
170 complain_overflow_bitfield
, /* complain_on_overflow */
171 ppc_elf_std_reloc
, /* special_function */
172 "R_PPC_NONE", /* name */
173 false, /* partial_inplace */
176 false), /* pcrel_offset */
178 /* A standard 32 bit relocation. */
179 HOWTO (R_PPC_ADDR32
, /* type */
181 2, /* size (0 = byte, 1 = short, 2 = long) */
183 false, /* pc_relative */
185 complain_overflow_bitfield
, /* complain_on_overflow */
186 ppc_elf_std_reloc
, /* special_function */
187 "R_PPC_ADDR32", /* name */
188 false, /* partial_inplace */
190 0xffffffff, /* dst_mask */
191 false), /* pcrel_offset */
193 /* An absolute 26 bit branch; the lower two bits must be zero.
194 FIXME: we don't check that, we just clear them. */
195 HOWTO (R_PPC_ADDR24
, /* type */
197 2, /* size (0 = byte, 1 = short, 2 = long) */
199 false, /* pc_relative */
201 complain_overflow_bitfield
, /* complain_on_overflow */
202 ppc_elf_std_reloc
, /* special_function */
203 "R_PPC_ADDR24", /* name */
204 false, /* partial_inplace */
206 0x3fffffc, /* dst_mask */
207 false), /* pcrel_offset */
209 /* A standard 16 bit relocation. */
210 HOWTO (R_PPC_ADDR16
, /* type */
212 1, /* size (0 = byte, 1 = short, 2 = long) */
214 false, /* pc_relative */
216 complain_overflow_bitfield
, /* complain_on_overflow */
217 ppc_elf_std_reloc
, /* special_function */
218 "R_PPC_ADDR16", /* name */
219 false, /* partial_inplace */
221 0xffff, /* dst_mask */
222 false), /* pcrel_offset */
224 /* A 16 bit relocation without overflow. */
225 HOWTO (R_PPC_ADDR16_LO
, /* type */
227 1, /* size (0 = byte, 1 = short, 2 = long) */
229 false, /* pc_relative */
231 complain_overflow_dont
,/* complain_on_overflow */
232 ppc_elf_std_reloc
, /* special_function */
233 "R_PPC_ADDR16_LO", /* name */
234 false, /* partial_inplace */
236 0xffff, /* dst_mask */
237 false), /* pcrel_offset */
239 /* The high order 16 bits of an address. */
240 HOWTO (R_PPC_ADDR16_HI
, /* type */
242 1, /* size (0 = byte, 1 = short, 2 = long) */
244 false, /* pc_relative */
246 complain_overflow_dont
, /* complain_on_overflow */
247 ppc_elf_std_reloc
, /* special_function */
248 "R_PPC_ADDR16_HI", /* name */
249 false, /* partial_inplace */
251 0xffff, /* dst_mask */
252 false), /* pcrel_offset */
254 /* The high order 16 bits of an address, plus 1 if the contents of
255 the low 16 bits, treated as a signed number, is negative. */
256 HOWTO (R_PPC_ADDR16_HA
, /* 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_HA", /* name */
265 false, /* partial_inplace */
267 0xffff, /* dst_mask */
268 false), /* pcrel_offset */
270 /* An absolute 16 bit branch; the lower two bits must be zero.
271 FIXME: we don't check that, we just clear them. */
272 HOWTO (R_PPC_ADDR14
, /* type */
274 2, /* size (0 = byte, 1 = short, 2 = long) */
276 false, /* pc_relative */
278 complain_overflow_bitfield
, /* complain_on_overflow */
279 ppc_elf_std_reloc
, /* special_function */
280 "R_PPC_ADDR14", /* name */
281 false, /* partial_inplace */
283 0xfffc, /* dst_mask */
284 false), /* pcrel_offset */
286 /* An absolute 16 bit branch, for which bit 10 should be set to
287 indicate that the branch is expected to be taken. The lower two
288 bits must be zero. */
289 HOWTO (R_PPC_ADDR14_BRTAKEN
, /* type */
291 2, /* size (0 = byte, 1 = short, 2 = long) */
293 false, /* pc_relative */
295 complain_overflow_bitfield
, /* complain_on_overflow */
296 bfd_elf_generic_reloc
, /* special_function */
297 "R_PPC_ADDR14_BRTAKEN",/* name */
298 false, /* partial_inplace */
300 0xfffc, /* dst_mask */
301 false), /* pcrel_offset */
303 /* An absolute 16 bit branch, for which bit 10 should be set to
304 indicate that the branch is not expected to be taken. The lower
305 two bits must be zero. */
306 HOWTO (R_PPC_ADDR14_BRNTAKEN
, /* type */
308 2, /* size (0 = byte, 1 = short, 2 = long) */
310 false, /* pc_relative */
312 complain_overflow_bitfield
, /* complain_on_overflow */
313 bfd_elf_generic_reloc
, /* special_function */
314 "R_PPC_ADDR14_BRNTAKEN",/* name */
315 false, /* partial_inplace */
317 0xfffc, /* dst_mask */
318 false), /* pcrel_offset */
320 /* A relative 26 bit branch; the lower two bits must be zero. */
321 HOWTO (R_PPC_REL24
, /* type */
323 2, /* size (0 = byte, 1 = short, 2 = long) */
325 true, /* pc_relative */
327 complain_overflow_signed
, /* complain_on_overflow */
328 ppc_elf_std_reloc
, /* special_function */
329 "R_PPC_REL24", /* name */
330 false, /* partial_inplace */
332 0x3fffffc, /* dst_mask */
333 true), /* pcrel_offset */
335 /* A relative 16 bit branch; the lower two bits must be zero. */
336 HOWTO (R_PPC_REL14
, /* type */
338 2, /* size (0 = byte, 1 = short, 2 = long) */
340 true, /* pc_relative */
342 complain_overflow_signed
, /* complain_on_overflow */
343 ppc_elf_std_reloc
, /* special_function */
344 "R_PPC_REL14", /* name */
345 false, /* partial_inplace */
347 0xfffc, /* dst_mask */
348 true), /* pcrel_offset */
350 /* A relative 16 bit branch. Bit 10 should be set to indicate that
351 the branch is expected to be taken. The lower two bits must be
353 HOWTO (R_PPC_REL14_BRTAKEN
, /* type */
355 2, /* size (0 = byte, 1 = short, 2 = long) */
357 true, /* pc_relative */
359 complain_overflow_signed
, /* complain_on_overflow */
360 bfd_elf_generic_reloc
, /* special_function */
361 "R_PPC_REL14_BRTAKEN", /* name */
362 false, /* partial_inplace */
364 0xfffc, /* dst_mask */
365 true), /* pcrel_offset */
367 /* A relative 16 bit branch. Bit 10 should be set to indicate that
368 the branch is not expected to be taken. The lower two bits must
370 HOWTO (R_PPC_REL14_BRNTAKEN
, /* type */
372 2, /* size (0 = byte, 1 = short, 2 = long) */
374 true, /* pc_relative */
376 complain_overflow_signed
, /* complain_on_overflow */
377 bfd_elf_generic_reloc
, /* special_function */
378 "R_PPC_REL14_BRNTAKEN",/* name */
379 false, /* partial_inplace */
381 0xfffc, /* dst_mask */
382 true), /* pcrel_offset */
384 /* Like R_PPC_ADDR16, but referring to the GOT table entry for the
386 HOWTO (R_PPC_GOT16
, /* type */
388 1, /* size (0 = byte, 1 = short, 2 = long) */
390 false, /* pc_relative */
392 complain_overflow_signed
, /* complain_on_overflow */
393 bfd_elf_generic_reloc
, /* special_function */
394 "R_PPC_GOT16", /* name */
395 false, /* partial_inplace */
397 0xffff, /* dst_mask */
398 false), /* pcrel_offset */
400 /* Like R_PPC_ADDR16_LO, but referring to the GOT table entry for
402 HOWTO (R_PPC_GOT16_LO
, /* type */
404 1, /* size (0 = byte, 1 = short, 2 = long) */
406 false, /* pc_relative */
408 complain_overflow_bitfield
, /* complain_on_overflow */
409 bfd_elf_generic_reloc
, /* special_function */
410 "R_PPC_GOT16_LO", /* name */
411 false, /* partial_inplace */
413 0xffff, /* dst_mask */
414 false), /* pcrel_offset */
416 /* Like R_PPC_ADDR16_HI, but referring to the GOT table entry for
418 HOWTO (R_PPC_GOT16_HI
, /* 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_HI", /* name */
427 false, /* partial_inplace */
429 0xffff, /* dst_mask */
430 false), /* pcrel_offset */
432 /* Like R_PPC_ADDR16_HA, but referring to the GOT table entry for
433 the symbol. FIXME: Not supported. */
434 HOWTO (R_PPC_GOT16_HA
, /* type */
436 1, /* size (0 = byte, 1 = short, 2 = long) */
438 false, /* pc_relative */
440 complain_overflow_bitfield
, /* complain_on_overflow */
441 ppc_elf_unsupported_reloc
, /* special_function */
442 "R_PPC_GOT16_HA", /* name */
443 false, /* partial_inplace */
445 0xffff, /* dst_mask */
446 false), /* pcrel_offset */
448 /* Like R_PPC_REL24, but referring to the procedure linkage table
449 entry for the symbol. FIXME: Not supported. */
450 HOWTO (R_PPC_PLTREL24
, /* type */
452 2, /* size (0 = byte, 1 = short, 2 = long) */
454 true, /* pc_relative */
456 complain_overflow_signed
, /* complain_on_overflow */
457 ppc_elf_unsupported_reloc
, /* special_function */
458 "R_PPC_PLTREL24", /* name */
459 false, /* partial_inplace */
461 0x3fffffc, /* dst_mask */
462 true), /* pcrel_offset */
464 /* This is used only by the dynamic linker. The symbol should exist
465 both in the object being run and in some shared library. The
466 dynamic linker copies the data addressed by the symbol from the
467 shared library into the object. I have no idea what the purpose
469 HOWTO (R_PPC_COPY
, /* type */
471 2, /* size (0 = byte, 1 = short, 2 = long) */
473 false, /* pc_relative */
475 complain_overflow_bitfield
, /* complain_on_overflow */
476 ppc_elf_unsupported_reloc
, /* special_function */
477 "R_PPC_COPY", /* name */
478 false, /* partial_inplace */
481 false), /* pcrel_offset */
483 /* Like R_PPC_ADDR32, but used when setting global offset table
485 HOWTO (R_PPC_GLOB_DAT
, /* type */
487 2, /* size (0 = byte, 1 = short, 2 = long) */
489 false, /* pc_relative */
491 complain_overflow_bitfield
, /* complain_on_overflow */
492 ppc_elf_unsupported_reloc
, /* special_function */
493 "R_PPC_GLOB_DAT", /* name */
494 false, /* partial_inplace */
496 0xffffffff, /* dst_mask */
497 false), /* pcrel_offset */
499 /* Marks a procedure linkage table entry for a symbol. */
500 HOWTO (R_PPC_JMP_SLOT
, /* type */
502 2, /* size (0 = byte, 1 = short, 2 = long) */
504 false, /* pc_relative */
506 complain_overflow_bitfield
, /* complain_on_overflow */
507 ppc_elf_unsupported_reloc
, /* special_function */
508 "R_PPC_JMP_SLOT", /* name */
509 false, /* partial_inplace */
512 false), /* pcrel_offset */
514 /* Used only by the dynamic linker. When the object is run, this
515 longword is set to the load address of the object, plus the
517 HOWTO (R_PPC_RELATIVE
, /* type */
519 2, /* size (0 = byte, 1 = short, 2 = long) */
521 false, /* pc_relative */
523 complain_overflow_bitfield
, /* complain_on_overflow */
524 ppc_elf_unsupported_reloc
, /* special_function */
525 "R_PPC_RELATIVE", /* name */
526 false, /* partial_inplace */
528 0xffffffff, /* dst_mask */
529 false), /* pcrel_offset */
531 /* Like R_PPC_REL24, but uses the value of the symbol within the
532 object rather than the final value. Normally used for
533 _GLOBAL_OFFSET_TABLE_. FIXME: Not supported. */
534 HOWTO (R_PPC_LOCAL24PC
, /* type */
536 2, /* size (0 = byte, 1 = short, 2 = long) */
538 true, /* pc_relative */
540 complain_overflow_signed
, /* complain_on_overflow */
541 ppc_elf_unsupported_reloc
, /* special_function */
542 "R_PPC_LOCAL24PC", /* name */
543 false, /* partial_inplace */
545 0x3fffffc, /* dst_mask */
546 true), /* pcrel_offset */
548 /* Like R_PPC_ADDR32, but may be unaligned. */
549 HOWTO (R_PPC_UADDR32
, /* type */
551 2, /* size (0 = byte, 1 = short, 2 = long) */
553 false, /* pc_relative */
555 complain_overflow_bitfield
, /* complain_on_overflow */
556 ppc_elf_std_reloc
, /* special_function */
557 "R_PPC_UADDR32", /* name */
558 false, /* partial_inplace */
560 0xffffffff, /* dst_mask */
561 false), /* pcrel_offset */
563 /* Like R_PPC_ADDR16, but may be unaligned. */
564 HOWTO (R_PPC_UADDR16
, /* type */
566 1, /* size (0 = byte, 1 = short, 2 = long) */
568 false, /* pc_relative */
570 complain_overflow_bitfield
, /* complain_on_overflow */
571 ppc_elf_std_reloc
, /* special_function */
572 "R_PPC_UADDR16", /* name */
573 false, /* partial_inplace */
575 0xffff, /* dst_mask */
576 false), /* pcrel_offset */
578 /* 32-bit PC relative */
579 HOWTO (R_PPC_REL32
, /* type */
581 2, /* size (0 = byte, 1 = short, 2 = long) */
583 true, /* pc_relative */
585 complain_overflow_bitfield
, /* complain_on_overflow */
586 ppc_elf_std_reloc
, /* special_function */
587 "R_PPC_REL32", /* name */
588 false, /* partial_inplace */
590 0xffffffff, /* dst_mask */
591 true), /* pcrel_offset */
593 /* 32-bit relocation to the symbol's procedure linkage table.
594 FIXEME: not supported. */
595 HOWTO (R_PPC_PLT32
, /* type */
597 2, /* size (0 = byte, 1 = short, 2 = long) */
599 false, /* pc_relative */
601 complain_overflow_bitfield
, /* complain_on_overflow */
602 ppc_elf_unsupported_reloc
, /* special_function */
603 "R_PPC_PLT32", /* name */
604 false, /* partial_inplace */
607 false), /* pcrel_offset */
609 /* 32-bit PC relative relocation to the symbol's procedure linkage table.
610 FIXEME: not supported. */
611 HOWTO (R_PPC_PLTREL32
, /* type */
613 2, /* size (0 = byte, 1 = short, 2 = long) */
615 true, /* pc_relative */
617 complain_overflow_bitfield
, /* complain_on_overflow */
618 ppc_elf_unsupported_reloc
, /* special_function */
619 "R_PPC_PLTREL32", /* name */
620 false, /* partial_inplace */
623 true), /* pcrel_offset */
625 /* Like R_PPC_ADDR16_LO, but referring to the PLT table entry for
627 HOWTO (R_PPC_PLT16_LO
, /* type */
629 1, /* size (0 = byte, 1 = short, 2 = long) */
631 false, /* pc_relative */
633 complain_overflow_bitfield
, /* complain_on_overflow */
634 ppc_elf_unsupported_reloc
, /* special_function */
635 "R_PPC_PLT16_LO", /* name */
636 false, /* partial_inplace */
638 0xffff, /* dst_mask */
639 false), /* pcrel_offset */
641 /* Like R_PPC_ADDR16_HI, but referring to the PLT table entry for
643 HOWTO (R_PPC_PLT16_HI
, /* type */
645 1, /* size (0 = byte, 1 = short, 2 = long) */
647 false, /* pc_relative */
649 complain_overflow_bitfield
, /* complain_on_overflow */
650 ppc_elf_unsupported_reloc
, /* special_function */
651 "R_PPC_PLT16_HI", /* name */
652 false, /* partial_inplace */
654 0xffff, /* dst_mask */
655 false), /* pcrel_offset */
657 /* Like R_PPC_ADDR16_HA, but referring to the PLT table entry for
658 the symbol. FIXME: Not supported. */
659 HOWTO (R_PPC_PLT16_HA
, /* type */
661 1, /* size (0 = byte, 1 = short, 2 = long) */
663 false, /* pc_relative */
665 complain_overflow_bitfield
, /* complain_on_overflow */
666 ppc_elf_unsupported_reloc
, /* special_function */
667 "R_PPC_PLT16_HA", /* name */
668 false, /* partial_inplace */
670 0xffff, /* dst_mask */
671 false), /* pcrel_offset */
673 /* A sign-extended 16 bit value relative to _SDA_BASE, for use with
675 HOWTO (R_PPC_SDAREL16
, /* type */
677 1, /* size (0 = byte, 1 = short, 2 = long) */
679 false, /* pc_relative */
681 complain_overflow_signed
, /* complain_on_overflow */
682 bfd_elf_generic_reloc
, /* special_function */
683 "R_PPC_SDAREL16", /* name */
684 false, /* partial_inplace */
686 0xffff, /* dst_mask */
687 false), /* pcrel_offset */
689 /* These next 4 relocations were added by Sun. */
690 /* 32-bit section relative relocation. FIXME: not supported. */
691 HOWTO (R_PPC_SECTOFF
, /* type */
693 2, /* size (0 = byte, 1 = short, 2 = long) */
695 true, /* pc_relative */
697 complain_overflow_bitfield
, /* complain_on_overflow */
698 ppc_elf_unsupported_reloc
, /* special_function */
699 "R_PPC_SECTOFF", /* name */
700 false, /* partial_inplace */
703 true), /* pcrel_offset */
705 /* 16-bit lower half section relative relocation. FIXME: not supported. */
706 HOWTO (R_PPC_SECTOFF_LO
, /* type */
708 1, /* size (0 = byte, 1 = short, 2 = long) */
710 false, /* pc_relative */
712 complain_overflow_bitfield
, /* complain_on_overflow */
713 ppc_elf_unsupported_reloc
, /* special_function */
714 "R_PPC_SECTOFF_LO", /* name */
715 false, /* partial_inplace */
717 0xffff, /* dst_mask */
718 false), /* pcrel_offset */
720 /* 16-bit upper half section relative relocation. FIXME: not supported. */
721 HOWTO (R_PPC_SECTOFF_HI
, /* type */
723 1, /* size (0 = byte, 1 = short, 2 = long) */
725 false, /* pc_relative */
727 complain_overflow_bitfield
, /* complain_on_overflow */
728 ppc_elf_unsupported_reloc
, /* special_function */
729 "R_PPC_SECTOFF_HI", /* name */
730 false, /* partial_inplace */
732 0xffff, /* dst_mask */
733 false), /* pcrel_offset */
735 /* 16-bit upper half adjusted section relative relocation. FIXME: not supported. */
736 HOWTO (R_PPC_SECTOFF_HA
, /* type */
738 1, /* size (0 = byte, 1 = short, 2 = long) */
740 false, /* pc_relative */
742 complain_overflow_bitfield
, /* complain_on_overflow */
743 ppc_elf_unsupported_reloc
, /* special_function */
744 "R_PPC_SECTOFF_HA", /* name */
745 false, /* partial_inplace */
747 0xffff, /* dst_mask */
748 false), /* pcrel_offset */
750 /* The remaining relocs are from the Embedded ELF ABI, and are not
751 in the SVR4 ELF ABI. */
753 /* 32 bit value resulting from the addend minus the symbol */
754 HOWTO (R_PPC_EMB_NADDR32
, /* type */
756 2, /* size (0 = byte, 1 = short, 2 = long) */
758 false, /* pc_relative */
760 complain_overflow_bitfield
, /* complain_on_overflow */
761 ppc_elf_unsupported_reloc
, /* special_function */
762 "R_PPC_EMB_NADDR32", /* name */
763 false, /* partial_inplace */
765 0xffffffff, /* dst_mask */
766 false), /* pcrel_offset */
768 /* 16 bit value resulting from the addend minus the symbol */
769 HOWTO (R_PPC_EMB_NADDR16
, /* type */
771 1, /* size (0 = byte, 1 = short, 2 = long) */
773 false, /* pc_relative */
775 complain_overflow_bitfield
, /* complain_on_overflow */
776 ppc_elf_unsupported_reloc
, /* special_function */
777 "R_PPC_EMB_NADDR16", /* name */
778 false, /* partial_inplace */
780 0xffff, /* dst_mask */
781 false), /* pcrel_offset */
783 /* 16 bit value resulting from the addend minus the symbol */
784 HOWTO (R_PPC_EMB_NADDR16_LO
, /* type */
786 1, /* size (0 = byte, 1 = short, 2 = long) */
788 false, /* pc_relative */
790 complain_overflow_dont
,/* complain_on_overflow */
791 ppc_elf_unsupported_reloc
, /* special_function */
792 "R_PPC_EMB_ADDR16_LO", /* name */
793 false, /* partial_inplace */
795 0xffff, /* dst_mask */
796 false), /* pcrel_offset */
798 /* The high order 16 bits of the addend minus the symbol */
799 HOWTO (R_PPC_EMB_NADDR16_HI
, /* type */
801 1, /* size (0 = byte, 1 = short, 2 = long) */
803 false, /* pc_relative */
805 complain_overflow_dont
, /* complain_on_overflow */
806 ppc_elf_unsupported_reloc
, /* special_function */
807 "R_PPC_EMB_NADDR16_HI", /* name */
808 false, /* partial_inplace */
810 0xffff, /* dst_mask */
811 false), /* pcrel_offset */
813 /* The high order 16 bits of the result of the addend minus the address,
814 plus 1 if the contents of the low 16 bits, treated as a signed number,
816 HOWTO (R_PPC_EMB_NADDR16_HA
, /* type */
818 1, /* size (0 = byte, 1 = short, 2 = long) */
820 false, /* pc_relative */
822 complain_overflow_dont
, /* complain_on_overflow */
823 ppc_elf_unsupported_reloc
, /* special_function */
824 "R_PPC_EMB_NADDR16_HA", /* name */
825 false, /* partial_inplace */
827 0xffff, /* dst_mask */
828 false), /* pcrel_offset */
830 /* Phony reloc to handle AIX style TOC entries */
831 HOWTO (R_PPC_TOC16
, /* type */
833 1, /* size (0 = byte, 1 = short, 2 = long) */
835 false, /* pc_relative */
837 complain_overflow_signed
, /* complain_on_overflow */
838 bfd_elf_generic_reloc
, /* special_function */
839 "R_PPC_TOC16", /* name */
840 false, /* partial_inplace */
842 0xffff, /* dst_mask */
843 false), /* pcrel_offset */
847 /* Initialize the ppc_elf_howto_table, so that linear accesses can be done. */
850 ppc_elf_howto_init ()
852 unsigned int i
, type
;
854 for (i
= 0; i
< sizeof (ppc_elf_howto_raw
) / sizeof (ppc_elf_howto_raw
[0]); i
++)
856 type
= ppc_elf_howto_raw
[i
].type
;
857 BFD_ASSERT (type
< sizeof(ppc_elf_howto_table
) / sizeof(ppc_elf_howto_table
[0]));
858 ppc_elf_howto_table
[type
] = &ppc_elf_howto_raw
[i
];
863 static reloc_howto_type
*
864 ppc_elf_reloc_type_lookup (abfd
, code
)
866 bfd_reloc_code_real_type code
;
868 enum ppc_reloc_type ppc_reloc
= R_PPC_NONE
;
870 if (!ppc_elf_howto_table
[ R_PPC_ADDR32
]) /* Initialize howto table if needed */
871 ppc_elf_howto_init ();
876 return (reloc_howto_type
*)NULL
;
878 case BFD_RELOC_NONE
: ppc_reloc
= R_PPC_NONE
; break;
879 case BFD_RELOC_32
: ppc_reloc
= R_PPC_ADDR32
; break;
880 case BFD_RELOC_PPC_BA26
: ppc_reloc
= R_PPC_ADDR24
; break;
881 case BFD_RELOC_16
: ppc_reloc
= R_PPC_ADDR16
; break;
882 case BFD_RELOC_LO16
: ppc_reloc
= R_PPC_ADDR16_LO
; break;
883 case BFD_RELOC_HI16
: ppc_reloc
= R_PPC_ADDR16_HI
; break;
884 case BFD_RELOC_HI16_S
: ppc_reloc
= R_PPC_ADDR16_HA
; break;
885 case BFD_RELOC_PPC_BA16
: ppc_reloc
= R_PPC_ADDR14
; break;
886 case BFD_RELOC_PPC_BA16_BRTAKEN
: ppc_reloc
= R_PPC_ADDR14_BRTAKEN
; break;
887 case BFD_RELOC_PPC_BA16_BRNTAKEN
: ppc_reloc
= R_PPC_ADDR14_BRNTAKEN
; break;
888 case BFD_RELOC_PPC_B26
: ppc_reloc
= R_PPC_REL24
; break;
889 case BFD_RELOC_PPC_B16
: ppc_reloc
= R_PPC_REL14
; break;
890 case BFD_RELOC_PPC_B16_BRTAKEN
: ppc_reloc
= R_PPC_REL14_BRTAKEN
; break;
891 case BFD_RELOC_PPC_B16_BRNTAKEN
: ppc_reloc
= R_PPC_REL14_BRNTAKEN
; break;
892 case BFD_RELOC_16_GOTOFF
: ppc_reloc
= R_PPC_GOT16
; break;
893 case BFD_RELOC_LO16_GOTOFF
: ppc_reloc
= R_PPC_GOT16_LO
; break;
894 case BFD_RELOC_HI16_GOTOFF
: ppc_reloc
= R_PPC_GOT16_HI
; break;
895 case BFD_RELOC_HI16_S_GOTOFF
: ppc_reloc
= R_PPC_GOT16_HA
; break;
896 case BFD_RELOC_24_PLT_PCREL
: ppc_reloc
= R_PPC_PLTREL24
; break;
897 case BFD_RELOC_PPC_COPY
: ppc_reloc
= R_PPC_COPY
; break;
898 case BFD_RELOC_PPC_GLOB_DAT
: ppc_reloc
= R_PPC_GLOB_DAT
; break;
899 case BFD_RELOC_PPC_LOCAL24PC
: ppc_reloc
= R_PPC_LOCAL24PC
; break;
900 case BFD_RELOC_32_PCREL
: ppc_reloc
= R_PPC_REL32
; break;
901 case BFD_RELOC_32_PLTOFF
: ppc_reloc
= R_PPC_PLT32
; break;
902 case BFD_RELOC_32_PLT_PCREL
: ppc_reloc
= R_PPC_PLTREL32
; break;
903 case BFD_RELOC_LO16_PLTOFF
: ppc_reloc
= R_PPC_PLT16_LO
; break;
904 case BFD_RELOC_HI16_PLTOFF
: ppc_reloc
= R_PPC_PLT16_HI
; break;
905 case BFD_RELOC_HI16_S_PLTOFF
: ppc_reloc
= R_PPC_PLT16_HA
; break;
906 case BFD_RELOC_GPREL16
: ppc_reloc
= R_PPC_SDAREL16
; break;
907 case BFD_RELOC_32_BASEREL
: ppc_reloc
= R_PPC_SECTOFF
; break;
908 case BFD_RELOC_LO16_BASEREL
: ppc_reloc
= R_PPC_SECTOFF_LO
; break;
909 case BFD_RELOC_HI16_BASEREL
: ppc_reloc
= R_PPC_SECTOFF_HI
; break;
910 case BFD_RELOC_HI16_S_BASEREL
: ppc_reloc
= R_PPC_SECTOFF_HA
; break;
911 case BFD_RELOC_CTOR
: ppc_reloc
= R_PPC_ADDR32
; break;
912 case BFD_RELOC_PPC_TOC16
: ppc_reloc
= R_PPC_TOC16
; break;
915 return ppc_elf_howto_table
[ (int)ppc_reloc
];
918 /* Set the howto pointer for a PowerPC ELF reloc. */
921 ppc_elf_info_to_howto (abfd
, cache_ptr
, dst
)
924 Elf32_Internal_Rela
*dst
;
926 if (!ppc_elf_howto_table
[ R_PPC_ADDR32
]) /* Initialize howto table if needed */
927 ppc_elf_howto_init ();
929 BFD_ASSERT (ELF32_R_TYPE (dst
->r_info
) < (unsigned int) R_PPC_max
);
930 cache_ptr
->howto
= ppc_elf_howto_table
[ELF32_R_TYPE (dst
->r_info
)];
933 /* Function to set whether a module needs the -mrelocatable bit set. */
936 ppc_elf_set_private_flags (abfd
, flags
)
940 BFD_ASSERT (!elf_flags_init (abfd
)
941 || elf_elfheader (abfd
)->e_flags
== flags
);
943 elf_elfheader (abfd
)->e_flags
= flags
;
944 elf_flags_init (abfd
) = true;
948 /* Copy backend specific data from one object module to another */
950 ppc_elf_copy_private_bfd_data (ibfd
, obfd
)
954 /* This function is selected based on the input vector. We only
955 want to copy information over if the output BFD also uses Elf
957 if (bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
960 BFD_ASSERT (!elf_flags_init (obfd
)
961 || elf_elfheader (obfd
)->e_flags
== elf_elfheader (ibfd
)->e_flags
);
963 elf_elfheader (obfd
)->e_flags
= elf_elfheader (ibfd
)->e_flags
;
964 elf_flags_init (obfd
) = true;
968 /* Merge backend specific data from an object file to the output
969 object file when linking */
971 ppc_elf_merge_private_bfd_data (ibfd
, obfd
)
979 /* Check if we have the same endianess */
980 if (ibfd
->xvec
->byteorder
!= obfd
->xvec
->byteorder
981 && obfd
->xvec
->byteorder
!= BFD_ENDIAN_UNKNOWN
)
983 (*_bfd_error_handler
)
984 ("%s: compiled for a %s endian system and target is %s endian",
985 bfd_get_filename (ibfd
),
986 bfd_big_endian (ibfd
) ? "big" : "little",
987 bfd_big_endian (obfd
) ? "big" : "little");
989 bfd_set_error (bfd_error_wrong_format
);
993 /* This function is selected based on the input vector. We only
994 want to copy information over if the output BFD also uses Elf
996 if (bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
999 new_flags
= elf_elfheader (ibfd
)->e_flags
;
1000 old_flags
= elf_elfheader (obfd
)->e_flags
;
1001 if (!elf_flags_init (obfd
)) /* First call, no flags set */
1003 elf_flags_init (obfd
) = true;
1004 elf_elfheader (obfd
)->e_flags
= new_flags
;
1007 else if (new_flags
== old_flags
) /* Compatible flags are ok */
1010 else /* Incompatible flags */
1012 /* Warn about -mrelocatable mismatch. Allow -mrelocatable-lib to be linked
1015 if ((new_flags
& EF_PPC_RELOCATABLE
) != 0
1016 && (old_flags
& (EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
)) == 0)
1019 (*_bfd_error_handler
)
1020 ("%s: compiled with -mrelocatable and linked with modules compiled normally",
1021 bfd_get_filename (ibfd
));
1023 else if ((new_flags
& (EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
)) == 0
1024 && (old_flags
& EF_PPC_RELOCATABLE
) != 0)
1027 (*_bfd_error_handler
)
1028 ("%s: compiled normally and linked with modules compiled with -mrelocatable",
1029 bfd_get_filename (ibfd
));
1031 else if ((new_flags
& EF_PPC_RELOCATABLE_LIB
) != 0)
1032 elf_elfheader (obfd
)->e_flags
|= EF_PPC_RELOCATABLE_LIB
;
1034 new_flags
&= ~ (EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
);
1035 old_flags
&= ~ (EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
);
1037 /* Warn about eabi vs. V.4 mismatch */
1038 if ((new_flags
& EF_PPC_EMB
) != 0 && (old_flags
& EF_PPC_EMB
) == 0)
1040 new_flags
&= ~EF_PPC_EMB
;
1042 (*_bfd_error_handler
)
1043 ("%s: compiled for the eabi and linked with modules compiled for System V",
1044 bfd_get_filename (ibfd
));
1046 else if ((new_flags
& EF_PPC_EMB
) == 0 && (old_flags
& EF_PPC_EMB
) != 0)
1048 old_flags
&= ~EF_PPC_EMB
;
1050 (*_bfd_error_handler
)
1051 ("%s: compiled for System V and linked with modules compiled for eabi",
1052 bfd_get_filename (ibfd
));
1055 /* Warn about any other mismatches */
1056 if (new_flags
!= old_flags
)
1059 (*_bfd_error_handler
)
1060 ("%s: uses different e_flags (0x%lx) fields than previous modules (0x%lx)",
1061 bfd_get_filename (ibfd
), (long)new_flags
, (long)old_flags
);
1066 bfd_set_error (bfd_error_bad_value
);
1075 /* ELF relocs are against symbols. If we are producing relocateable
1076 output, and the reloc is against an external symbol, and nothing
1077 has given us any additional addend, the resulting reloc will also
1078 be against the same symbol. In such a case, we don't want to
1079 change anything about the way the reloc is handled, since it will
1080 all be done at final link time. Rather than put special case code
1081 into bfd_perform_relocation, all the reloc types use this howto
1082 function. It just short circuits the reloc if producing
1083 relocateable output against an external symbol. */
1086 static bfd_reloc_status_type
1087 ppc_elf_std_reloc (abfd
,
1095 arelent
*reloc_entry
;
1098 asection
*input_section
;
1100 char **error_message
;
1102 if (output_bfd
!= (bfd
*) NULL
1103 && (symbol
->flags
& BSF_SECTION_SYM
) == 0
1104 && (! reloc_entry
->howto
->partial_inplace
|| reloc_entry
->addend
== 0))
1106 reloc_entry
->address
+= input_section
->output_offset
;
1107 return bfd_reloc_ok
;
1110 return bfd_reloc_continue
;
1113 /* Don't pretend we can deal with unsupported relocs. */
1116 static bfd_reloc_status_type
1117 ppc_elf_unsupported_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1118 output_bfd
, error_message
)
1120 arelent
*reloc_entry
;
1123 asection
*input_section
;
1125 char **error_message
;
1127 BFD_ASSERT (reloc_entry
->howto
!= (reloc_howto_type
*)0);
1128 (*_bfd_error_handler
)
1129 ("%s: relocation %s (%d) is not currently supported",
1130 bfd_get_filename (abfd
),
1131 reloc_entry
->howto
->name
,
1132 reloc_entry
->howto
->type
);
1134 return bfd_reloc_notsupported
;
1138 /* Handle a PowerPC specific section when reading an object file. This
1139 is called when elfcode.h finds a section with an unknown type. */
1142 ppc_elf_section_from_shdr (abfd
, hdr
, name
)
1144 Elf32_Internal_Shdr
*hdr
;
1150 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
))
1153 newsect
= hdr
->bfd_section
;
1154 flags
= bfd_get_section_flags (abfd
, newsect
);
1155 if (hdr
->sh_flags
& SHF_EXCLUDE
)
1156 flags
|= SEC_EXCLUDE
;
1158 if (hdr
->sh_type
== SHT_ORDERED
)
1159 flags
|= SEC_SORT_ENTRIES
;
1161 bfd_set_section_flags (abfd
, newsect
, flags
);
1166 /* Set up any other section flags and such that may be necessary. */
1169 ppc_elf_fake_sections (abfd
, shdr
, asect
)
1171 Elf32_Internal_Shdr
*shdr
;
1174 if ((asect
->flags
& SEC_EXCLUDE
) != 0)
1175 shdr
->sh_flags
|= SHF_EXCLUDE
;
1177 if ((asect
->flags
& SEC_SORT_ENTRIES
) != 0)
1178 shdr
->sh_type
= SHT_ORDERED
;
1182 /* Create the PowerPC dynamic sections */
1185 ppc_elf_create_dynamic_sections (abfd
, info
)
1187 struct bfd_link_info
*info
;
1189 struct elf_link_hash_entry
*h
;
1190 struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
1192 /* Create the .got section. */
1193 if (! _bfd_elf_create_got_section (abfd
, info
))
1196 /* Also create the .got.neg section where we put negative offsets */
1197 if (bfd_get_section_by_name (abfd
, ".got.neg") == NULL
)
1199 asection
*s
= bfd_make_section (abfd
, ".got.neg");
1201 || !bfd_set_section_flags (abfd
, s
,
1202 SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
)
1203 || !bfd_set_section_alignment (abfd
, s
, 2))
1207 elf_hash_table (info
)->dynobj
= abfd
;
1212 /* Adjust a symbol defined by a dynamic object and referenced by a
1213 regular object. The current definition is in some section of the
1214 dynamic object, but we're not including those sections. We have to
1215 change the definition to something the rest of the link can
1219 ppc_elf_adjust_dynamic_symbol (info
, h
)
1220 struct bfd_link_info
*info
;
1221 struct elf_link_hash_entry
*h
;
1224 fprintf (stderr
, "ppc_elf_adjust_dynamic_symbol called\n");
1230 /* Increment the index of a dynamic symbol by a given amount. Called
1231 via elf_link_hash_traverse. */
1234 ppc_elf_adjust_dynindx (h
, cparg
)
1235 struct elf_link_hash_entry
*h
;
1238 int *cp
= (int *) cparg
;
1241 fprintf (stderr
, "ppc_elf_adjust_dynindx called, h->dynindx = %d, *cp = %d\n", h
->dynindx
, *cp
);
1244 if (h
->dynindx
!= -1)
1251 /* Set the sizes of the dynamic sections. */
1254 ppc_elf_size_dynamic_sections (output_bfd
, info
)
1256 struct bfd_link_info
*info
;
1264 fprintf (stderr
, "ppc_elf_size_dynamic_sections called\n");
1267 dynobj
= elf_hash_table (info
)->dynobj
;
1268 BFD_ASSERT (dynobj
!= NULL
);
1270 if (elf_hash_table (info
)->dynamic_sections_created
)
1272 /* Set the contents of the .interp section to the interpreter. */
1275 s
= bfd_get_section_by_name (dynobj
, ".interp");
1276 BFD_ASSERT (s
!= NULL
);
1277 s
->_raw_size
= sizeof ELF_DYNAMIC_INTERPRETER
;
1278 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
1281 /* Make space for the trailing nop in .plt. */
1282 s
= bfd_get_section_by_name (dynobj
, ".plt");
1283 BFD_ASSERT (s
!= NULL
);
1284 if (s
->_raw_size
> 0)
1289 /* We may have created entries in the .rela.got section.
1290 However, if we are not creating the dynamic sections, we will
1291 not actually use these entries. Reset the size of .rela.got,
1292 which will cause it to get stripped from the output file
1294 s
= bfd_get_section_by_name (dynobj
, ".rela.got");
1298 /* Ditto for .rela.got.neg */
1299 s
= bfd_get_section_by_name (dynobj
, ".rela.got.neg");
1304 /* The check_relocs and adjust_dynamic_symbol entry points have
1305 determined the sizes of the various dynamic sections. Allocate
1309 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
1314 if ((s
->flags
& SEC_IN_MEMORY
) == 0)
1317 /* It's OK to base decisions on the section name, because none
1318 of the dynobj section names depend upon the input files. */
1319 name
= bfd_get_section_name (dynobj
, s
);
1323 if (strncmp (name
, ".rela", 5) == 0)
1325 if (s
->_raw_size
== 0)
1327 /* If we don't need this section, strip it from the
1328 output file. This is to handle .rela.bss and
1329 .rel.plt. We must create it in
1330 create_dynamic_sections, because it must be created
1331 before the linker maps input sections to output
1332 sections. The linker does that before
1333 adjust_dynamic_symbol is called, and it is that
1334 function which decides whether anything needs to go
1335 into these sections. */
1342 /* If this relocation section applies to a read only
1343 section, then we probably need a DT_TEXTREL entry. */
1344 target
= bfd_get_section_by_name (output_bfd
, name
+ 5);
1346 && (target
->flags
& SEC_READONLY
) != 0)
1349 if (strcmp (name
, ".rela.plt") == 0)
1352 /* We use the reloc_count field as a counter if we need
1353 to copy relocs into the output file. */
1357 else if (strcmp (name
, ".plt") != 0
1358 && strcmp (name
, ".got") != 0
1359 && strcmp (name
, ".got.neg") != 0)
1361 /* It's not one of our sections, so don't allocate space. */
1369 for (spp
= &s
->output_section
->owner
->sections
;
1370 *spp
!= s
->output_section
;
1371 spp
= &(*spp
)->next
)
1373 *spp
= s
->output_section
->next
;
1374 --s
->output_section
->owner
->section_count
;
1379 /* Allocate memory for the section contents. */
1380 s
->contents
= (bfd_byte
*) bfd_alloc (dynobj
, s
->_raw_size
);
1381 if (s
->contents
== NULL
&& s
->_raw_size
!= 0)
1385 if (elf_hash_table (info
)->dynamic_sections_created
)
1387 /* Add some entries to the .dynamic section. We fill in the
1388 values later, in ppc_elf_finish_dynamic_sections, but we
1389 must add the entries now so that we get the correct size for
1390 the .dynamic section. The DT_DEBUG entry is filled in by the
1391 dynamic linker and used by the debugger. */
1394 if (! bfd_elf32_add_dynamic_entry (info
, DT_DEBUG
, 0))
1398 if (! bfd_elf32_add_dynamic_entry (info
, DT_PLTGOT
, 0))
1403 if (! bfd_elf32_add_dynamic_entry (info
, DT_PLTRELSZ
, 0)
1404 || ! bfd_elf32_add_dynamic_entry (info
, DT_PLTREL
, DT_RELA
)
1405 || ! bfd_elf32_add_dynamic_entry (info
, DT_JMPREL
, 0))
1409 if (! bfd_elf32_add_dynamic_entry (info
, DT_RELA
, 0)
1410 || ! bfd_elf32_add_dynamic_entry (info
, DT_RELASZ
, 0)
1411 || ! bfd_elf32_add_dynamic_entry (info
, DT_RELAENT
,
1412 sizeof (Elf32_External_Rela
)))
1417 if (! bfd_elf32_add_dynamic_entry (info
, DT_TEXTREL
, 0))
1422 /* If we are generating a shared library, we generate a section
1423 symbol for each output section. These are local symbols, which
1424 means that they must come first in the dynamic symbol table.
1425 That means we must increment the dynamic symbol index of every
1426 other dynamic symbol. */
1431 c
= bfd_count_sections (output_bfd
);
1432 elf_link_hash_traverse (elf_hash_table (info
),
1433 ppc_elf_adjust_dynindx
,
1435 elf_hash_table (info
)->dynsymcount
+= c
;
1437 for (i
= 1, s
= output_bfd
->sections
; s
!= NULL
; s
= s
->next
, i
++)
1439 elf_section_data (s
)->dynindx
= i
;
1440 /* These symbols will have no names, so we don't need to
1441 fiddle with dynstr_index. */
1449 /* Look through the relocs for a section during the first phase, and
1450 allocate space in the global offset table or procedure linkage
1454 ppc_elf_check_relocs (abfd
, info
, sec
, relocs
)
1456 struct bfd_link_info
*info
;
1458 const Elf_Internal_Rela
*relocs
;
1461 Elf_Internal_Shdr
*symtab_hdr
;
1462 struct elf_link_hash_entry
**sym_hashes
;
1463 bfd_vma
*local_got_offsets
;
1464 const Elf_Internal_Rela
*rel
;
1465 const Elf_Internal_Rela
*rel_end
;
1469 asection
*srelgot_neg
;
1472 if (info
->relocateable
)
1476 fprintf (stderr
, "ppc_elf_check_relocs called for section %s\n", sec
->name
);
1479 dynobj
= elf_hash_table (info
)->dynobj
;
1480 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
1481 sym_hashes
= elf_sym_hashes (abfd
);
1482 local_got_offsets
= elf_local_got_offsets (abfd
);
1488 rel_end
= relocs
+ sec
->reloc_count
;
1489 for (rel
= relocs
; rel
< rel_end
; rel
++)
1491 unsigned long r_symndx
;
1492 struct elf_link_hash_entry
*h
;
1494 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1495 if (r_symndx
< symtab_hdr
->sh_info
)
1498 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1500 switch (ELF32_R_TYPE (rel
->r_info
))
1503 case R_PPC_GOT16_LO
:
1504 case R_PPC_GOT16_HI
:
1505 case R_PPC_GOT16_HA
:
1507 fprintf (stderr
, "Reloc requires a GOT entry\n");
1509 /* This symbol requires a global offset table entry. */
1513 dynobj
= ppc_elf_create_dynamic_sections (abfd
, info
);
1520 sgot
= bfd_get_section_by_name (dynobj
, ".got");
1521 sgot_neg
= bfd_get_section_by_name (dynobj
, ".got.neg");
1522 BFD_ASSERT (sgot
!= NULL
&& sgot_neg
!= NULL
);
1526 && (h
!= NULL
|| info
->shared
))
1528 srelgot
= bfd_get_section_by_name (dynobj
, ".rela.got");
1529 if (srelgot
== NULL
)
1531 srelgot
= bfd_make_section (dynobj
, ".rela.got");
1533 || ! bfd_set_section_flags (dynobj
, srelgot
,
1539 || ! bfd_set_section_alignment (dynobj
, srelgot
, 2))
1543 srelgot_neg
= bfd_get_section_by_name (dynobj
, ".rela.got.neg");
1544 if (srelgot_neg
== NULL
)
1546 srelgot_neg
= bfd_make_section (dynobj
, ".rela.got.neg");
1548 || ! bfd_set_section_flags (dynobj
, srelgot_neg
,
1554 || ! bfd_set_section_alignment (dynobj
, srelgot
, 2))
1561 if (h
->got_offset
!= (bfd_vma
) -1)
1563 /* We have already allocated space in the .got. */
1566 h
->got_offset
= sgot
->_raw_size
;
1568 /* Make sure this symbol is output as a dynamic symbol. */
1569 if (h
->dynindx
== -1)
1571 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
1575 srelgot
->_raw_size
+= sizeof (Elf32_External_Rela
);
1579 /* This is a global offset table entry for a local
1581 if (local_got_offsets
== NULL
)
1584 register unsigned int i
;
1586 size
= symtab_hdr
->sh_info
* sizeof (bfd_vma
);
1587 local_got_offsets
= (bfd_vma
*) bfd_alloc (abfd
, size
);
1588 if (local_got_offsets
== NULL
)
1590 elf_local_got_offsets (abfd
) = local_got_offsets
;
1591 for (i
= 0; i
< symtab_hdr
->sh_info
; i
++)
1592 local_got_offsets
[i
] = (bfd_vma
) -1;
1594 if (local_got_offsets
[r_symndx
] != (bfd_vma
) -1)
1596 /* We have already allocated space in the .got. */
1599 local_got_offsets
[r_symndx
] = sgot
->_raw_size
;
1603 /* If we are generating a shared object, we need to
1604 output a R_PPC_RELATIVE reloc so that the
1605 dynamic linker can adjust this GOT entry. */
1606 srelgot
->_raw_size
+= sizeof (Elf32_External_Rela
);
1610 sgot
->_raw_size
+= 4;
1615 case R_PPC_PLTREL24
:
1616 case R_PPC_PLT16_LO
:
1617 case R_PPC_PLT16_HI
:
1618 case R_PPC_PLT16_HA
:
1620 fprintf (stderr
, "Reloc requires a PLT entry\n");
1622 /* This symbol requires a procedure linkage table entry. We
1623 actually build the entry in adjust_dynamic_symbol,
1624 because this might be a case of linking PIC code without
1625 linking in any dynamic objects, in which case we don't
1626 need to generate a procedure linkage table after all. */
1630 /* It does not make sense to have a procedure linkage
1631 table entry for a local symbol. */
1632 bfd_set_error (bfd_error_bad_value
);
1636 /* Make sure this symbol is output as a dynamic symbol. */
1637 if (h
->dynindx
== -1)
1639 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
1643 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
1650 && strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
1654 case R_SPARC_DISP16
:
1655 case R_SPARC_DISP32
:
1656 case R_SPARC_WDISP30
:
1657 case R_SPARC_WDISP22
:
1670 && (sec
->flags
& SEC_ALLOC
) != 0)
1672 /* When creating a shared object, we must copy these
1673 relocs into the output file. We create a reloc
1674 section in dynobj and make room for the reloc. */
1679 name
= (bfd_elf_string_from_elf_section
1681 elf_elfheader (abfd
)->e_shstrndx
,
1682 elf_section_data (sec
)->rel_hdr
.sh_name
));
1686 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
1687 && strcmp (bfd_get_section_name (abfd
, sec
),
1690 sreloc
= bfd_get_section_by_name (dynobj
, name
);
1693 sreloc
= bfd_make_section (dynobj
, name
);
1695 || ! bfd_set_section_flags (dynobj
, sreloc
,
1701 || ! bfd_set_section_alignment (dynobj
, sreloc
, 2))
1706 sreloc
->_raw_size
+= sizeof (Elf32_External_Rela
);
1721 /* Finish up dynamic symbol handling. We set the contents of various
1722 dynamic sections here. */
1725 ppc_elf_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
1727 struct bfd_link_info
*info
;
1728 struct elf_link_hash_entry
*h
;
1729 Elf_Internal_Sym
*sym
;
1734 fprintf (stderr
, "ppc_elf_finish_dynamic_symbol called\n");
1737 dynobj
= elf_hash_table (info
)->dynobj
;
1739 if (h
->plt_offset
!= (bfd_vma
) -1)
1743 Elf_Internal_Rela rela
;
1745 /* This symbol has an entry in the procedure linkage table. Set
1748 BFD_ASSERT (h
->dynindx
!= -1);
1750 splt
= bfd_get_section_by_name (dynobj
, ".plt");
1751 srela
= bfd_get_section_by_name (dynobj
, ".rela.plt");
1752 BFD_ASSERT (splt
!= NULL
&& srela
!= NULL
);
1754 /* Fill in the entry in the procedure linkage table. */
1756 bfd_put_32 (output_bfd
,
1757 PLT_ENTRY_WORD0
+ h
->plt_offset
,
1758 splt
->contents
+ h
->plt_offset
);
1759 bfd_put_32 (output_bfd
,
1761 + (((- (h
->plt_offset
+ 4)) >> 2) & 0x3fffff)),
1762 splt
->contents
+ h
->plt_offset
+ 4);
1763 bfd_put_32 (output_bfd
, PLT_ENTRY_WORD2
,
1764 splt
->contents
+ h
->plt_offset
+ 8);
1766 /* Fill in the entry in the .rela.plt section. */
1767 rela
.r_offset
= (splt
->output_section
->vma
1768 + splt
->output_offset
1770 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_SPARC_JMP_SLOT
);
1772 bfd_elf32_swap_reloca_out (output_bfd
, &rela
,
1773 ((Elf32_External_Rela
*) srela
->contents
1774 + h
->plt_offset
/ PLT_ENTRY_SIZE
- 4));
1777 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
1779 /* Mark the symbol as undefined, rather than as defined in
1780 the .plt section. Leave the value alone. */
1781 sym
->st_shndx
= SHN_UNDEF
;
1785 if (h
->got_offset
!= (bfd_vma
) -1)
1789 Elf_Internal_Rela rela
;
1791 /* This symbol has an entry in the global offset table. Set it
1794 BFD_ASSERT (h
->dynindx
!= -1);
1796 sgot
= bfd_get_section_by_name (dynobj
, ".got");
1797 srela
= bfd_get_section_by_name (dynobj
, ".rela.got");
1798 BFD_ASSERT (sgot
!= NULL
&& srela
!= NULL
);
1800 rela
.r_offset
= (sgot
->output_section
->vma
1801 + sgot
->output_offset
1802 + (h
->got_offset
&~ 1));
1804 /* If this is a -Bsymbolic link, and the symbol is defined
1805 locally, we just want to emit a RELATIVE reloc. The entry in
1806 the global offset table will already have been initialized in
1807 the relocate_section function. */
1810 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
))
1811 rela
.r_info
= ELF32_R_INFO (0, R_PPC_RELATIVE
);
1814 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ h
->got_offset
);
1815 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_PPC_GLOB_DAT
);
1819 bfd_elf32_swap_reloca_out (output_bfd
, &rela
,
1820 ((Elf32_External_Rela
*) srela
->contents
1821 + srela
->reloc_count
));
1822 ++srela
->reloc_count
;
1825 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_COPY
) != 0)
1828 Elf_Internal_Rela rela
;
1830 /* This symbols needs a copy reloc. Set it up. */
1832 BFD_ASSERT (h
->dynindx
!= -1);
1834 s
= bfd_get_section_by_name (h
->root
.u
.def
.section
->owner
,
1836 BFD_ASSERT (s
!= NULL
);
1838 rela
.r_offset
= (h
->root
.u
.def
.value
1839 + h
->root
.u
.def
.section
->output_section
->vma
1840 + h
->root
.u
.def
.section
->output_offset
);
1841 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_PPC_COPY
);
1843 bfd_elf32_swap_reloca_out (output_bfd
, &rela
,
1844 ((Elf32_External_Rela
*) s
->contents
1849 /* Mark some specially defined symbols as absolute. */
1850 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
1851 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0
1852 || strcmp (h
->root
.root
.string
, "_PROCEDURE_LINKAGE_TABLE_") == 0)
1853 sym
->st_shndx
= SHN_ABS
;
1859 /* Finish up the dynamic sections. */
1862 ppc_elf_finish_dynamic_sections (output_bfd
, info
)
1864 struct bfd_link_info
*info
;
1871 fprintf (stderr
, "ppc_elf_finish_dynamic_sections called\n");
1874 dynobj
= elf_hash_table (info
)->dynobj
;
1876 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
1878 if (elf_hash_table (info
)->dynamic_sections_created
)
1881 Elf32_External_Dyn
*dyncon
, *dynconend
;
1883 splt
= bfd_get_section_by_name (dynobj
, ".plt");
1884 BFD_ASSERT (splt
!= NULL
&& sdyn
!= NULL
);
1886 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
1887 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
1888 for (; dyncon
< dynconend
; dyncon
++)
1890 Elf_Internal_Dyn dyn
;
1894 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
1898 case DT_PLTGOT
: name
= ".plt"; size
= false; break;
1899 case DT_PLTRELSZ
: name
= ".rela.plt"; size
= true; break;
1900 case DT_JMPREL
: name
= ".rela.plt"; size
= false; break;
1901 default: name
= NULL
; size
= false; break;
1908 s
= bfd_get_section_by_name (output_bfd
, name
);
1914 dyn
.d_un
.d_ptr
= s
->vma
;
1917 if (s
->_cooked_size
!= 0)
1918 dyn
.d_un
.d_val
= s
->_cooked_size
;
1920 dyn
.d_un
.d_val
= s
->_raw_size
;
1923 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
1927 /* Clear the first four entries in the procedure linkage table,
1928 and put a nop in the last four bytes. */
1930 if (splt
->_raw_size
> 0)
1932 memset (splt
->contents
, 0, 4 * PLT_ENTRY_SIZE
);
1933 bfd_put_32 (output_bfd
, SPARC_NOP
,
1934 splt
->contents
+ splt
->_raw_size
- 4);
1937 elf_section_data (splt
->output_section
)->this_hdr
.sh_entsize
=
1942 /* Set the first entry in the global offset table to the address of
1943 the dynamic section. */
1944 sgot
= bfd_get_section_by_name (dynobj
, ".got");
1945 BFD_ASSERT (sgot
!= NULL
);
1946 if (sgot
->_raw_size
> 0)
1949 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
);
1951 bfd_put_32 (output_bfd
,
1952 sdyn
->output_section
->vma
+ sdyn
->output_offset
,
1956 elf_section_data (sgot
->output_section
)->this_hdr
.sh_entsize
= 4;
1962 Elf_Internal_Sym sym
;
1964 /* Set up the section symbols for the output sections. */
1966 sdynsym
= bfd_get_section_by_name (dynobj
, ".dynsym");
1967 BFD_ASSERT (sdynsym
!= NULL
);
1971 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_SECTION
);
1974 for (s
= output_bfd
->sections
; s
!= NULL
; s
= s
->next
)
1978 sym
.st_value
= s
->vma
;
1980 indx
= elf_section_data (s
)->this_idx
;
1981 BFD_ASSERT (indx
> 0);
1982 sym
.st_shndx
= indx
;
1984 bfd_elf32_swap_symbol_out (output_bfd
, &sym
,
1985 (PTR
) (((Elf32_External_Sym
*)
1987 + elf_section_data (s
)->dynindx
));
1990 /* Set the sh_info field of the output .dynsym section to the
1991 index of the first global symbol. */
1992 elf_section_data (sdynsym
->output_section
)->this_hdr
.sh_info
=
1993 bfd_count_sections (output_bfd
) + 1;
2000 /* The RELOCATE_SECTION function is called by the ELF backend linker
2001 to handle the relocations for a section.
2003 The relocs are always passed as Rela structures; if the section
2004 actually uses Rel structures, the r_addend field will always be
2007 This function is responsible for adjust the section contents as
2008 necessary, and (if using Rela relocs and generating a
2009 relocateable output file) adjusting the reloc addend as
2012 This function does not have to worry about setting the reloc
2013 address or the reloc symbol index.
2015 LOCAL_SYMS is a pointer to the swapped in local symbols.
2017 LOCAL_SECTIONS is an array giving the section in the input file
2018 corresponding to the st_shndx field of each local symbol.
2020 The global hash table entry for the global symbols can be found
2021 via elf_sym_hashes (input_bfd).
2023 When generating relocateable output, this function must handle
2024 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
2025 going to be the section symbol corresponding to the output
2026 section, which means that the addend must be adjusted
2030 ppc_elf_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
2031 contents
, relocs
, local_syms
, local_sections
)
2033 struct bfd_link_info
*info
;
2035 asection
*input_section
;
2037 Elf_Internal_Rela
*relocs
;
2038 Elf_Internal_Sym
*local_syms
;
2039 asection
**local_sections
;
2041 Elf_Internal_Shdr
*symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
2042 struct elf_link_hash_entry
**sym_hashes
= elf_sym_hashes (input_bfd
);
2043 bfd
*dynobj
= elf_hash_table (info
)->dynobj
;
2044 bfd_vma
*local_got_offsets
= elf_local_got_offsets (input_bfd
);
2045 asection
*sgot
= (asection
*)0;
2046 Elf_Internal_Rela
*rel
= relocs
;
2047 Elf_Internal_Rela
*relend
= relocs
+ input_section
->reloc_count
;
2052 fprintf (stderr
, "ppc_elf_relocate_section called for %s section %s, %ld relocations%s\n",
2053 bfd_get_filename (input_bfd
),
2054 bfd_section_name(input_bfd
, input_section
),
2055 (long)input_section
->reloc_count
,
2056 (info
->relocateable
) ? " (relocatable)" : "");
2059 if (!ppc_elf_howto_table
[ R_PPC_ADDR32
]) /* Initialize howto table if needed */
2060 ppc_elf_howto_init ();
2062 for (; rel
< relend
; rel
++)
2064 enum ppc_reloc_type r_type
= (enum ppc_reloc_type
)ELF32_R_TYPE (rel
->r_info
);
2065 bfd_vma offset
= rel
->r_offset
;
2066 bfd_vma addend
= rel
->r_addend
;
2067 bfd_reloc_status_type r
= bfd_reloc_other
;
2068 Elf_Internal_Sym
*sym
= (Elf_Internal_Sym
*)0;
2069 asection
*sec
= (asection
*)0;
2070 struct elf_link_hash_entry
*h
= (struct elf_link_hash_entry
*)0;
2071 reloc_howto_type
*howto
;
2072 unsigned long r_symndx
;
2075 /* Unknown relocation handling */
2076 if ((unsigned)r_type
>= (unsigned)R_PPC_max
|| !ppc_elf_howto_table
[(int)r_type
])
2078 (*_bfd_error_handler
) ("%s: unknown relocation type %d",
2079 bfd_get_filename (input_bfd
),
2082 bfd_set_error (bfd_error_bad_value
);
2087 howto
= ppc_elf_howto_table
[(int)r_type
];
2088 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2090 if (info
->relocateable
)
2092 /* This is a relocateable link. We don't have to change
2093 anything, unless the reloc is against a section symbol,
2094 in which case we have to adjust according to where the
2095 section symbol winds up in the output section. */
2096 if (r_symndx
< symtab_hdr
->sh_info
)
2098 sym
= local_syms
+ r_symndx
;
2099 if ((unsigned)ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
2101 sec
= local_sections
[r_symndx
];
2102 addend
= rel
->r_addend
+= sec
->output_offset
+ sym
->st_value
;
2107 fprintf (stderr
, "\ttype = %s (%d), symbol index = %ld, offset = %ld, addend = %ld\n",
2117 /* This is a final link. */
2119 /* Complain about known relocation that are not yet supported */
2120 if (howto
->special_function
== ppc_elf_unsupported_reloc
)
2122 (*_bfd_error_handler
)
2123 ("%s: relocation %s (%d) is not currently supported",
2124 bfd_get_filename (input_bfd
),
2128 bfd_set_error (bfd_error_bad_value
);
2133 if (r_symndx
< symtab_hdr
->sh_info
)
2135 sym
= local_syms
+ r_symndx
;
2136 sec
= local_sections
[r_symndx
];
2137 relocation
= (sec
->output_section
->vma
2138 + sec
->output_offset
2143 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2144 if (h
->root
.type
== bfd_link_hash_defined
2145 || h
->root
.type
== bfd_link_hash_defweak
)
2147 sec
= h
->root
.u
.def
.section
;
2148 relocation
= (h
->root
.u
.def
.value
2149 + sec
->output_section
->vma
2150 + sec
->output_offset
);
2152 else if (h
->root
.type
== bfd_link_hash_undefweak
)
2154 else if (info
->shared
)
2158 (*info
->callbacks
->undefined_symbol
)(info
,
2159 h
->root
.root
.string
,
2168 switch ((int)r_type
)
2171 (*_bfd_error_handler
) ("%s: unknown relocation type %d",
2172 bfd_get_filename (input_bfd
),
2175 bfd_set_error (bfd_error_bad_value
);
2179 case R_PPC_NONE
: /* relocations that need no special processing */
2183 case R_PPC_ADDR16_LO
:
2184 case R_PPC_ADDR16_HI
:
2193 case (int)R_PPC_ADDR14_BRTAKEN
: /* branch taken prediction relocations */
2194 case (int)R_PPC_REL14_BRTAKEN
:
2195 insn
= bfd_get_32 (output_bfd
, contents
+ offset
);
2196 if ((relocation
- offset
) & 0x8000)
2197 insn
&= ~BRANCH_PREDICT_BIT
;
2199 insn
|= BRANCH_PREDICT_BIT
;
2200 bfd_put_32 (output_bfd
, insn
, contents
+ offset
);
2203 case (int)R_PPC_ADDR14_BRNTAKEN
: /* branch not taken predicition relocations */
2204 case (int)R_PPC_REL14_BRNTAKEN
:
2205 insn
= bfd_get_32 (output_bfd
, contents
+ offset
);
2206 if ((relocation
- offset
) & 0x8000)
2207 insn
|= BRANCH_PREDICT_BIT
;
2209 insn
&= ~BRANCH_PREDICT_BIT
;
2210 bfd_put_32 (output_bfd
, insn
, contents
+ offset
);
2213 case (int)R_PPC_GOT16
: /* GOT16 relocations */
2214 case (int)R_PPC_GOT16_LO
:
2215 case (int)R_PPC_GOT16_HI
:
2216 case (int)R_PPC_GOT16_HA
:
2218 fprintf (stderr
, "GOT relocations in section %s from section %s\n", input_section
->name
, sec
->name
);
2222 dynobj
= ppc_elf_create_dynamic_sections (output_bfd
, info
);
2230 BFD_ASSERT (sec
!= (asection
*)0);
2233 sgot
= bfd_get_section_by_name (dynobj
, ".got");
2234 BFD_ASSERT (sgot
!= NULL
);
2241 off
= h
->got_offset
;
2242 BFD_ASSERT (off
!= (bfd_vma
) -1);
2244 if (! elf_hash_table (info
)->dynamic_sections_created
2247 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
)))
2249 /* This is actually a static link, or it is a
2250 -Bsymbolic link and the symbol is defined
2251 locally. We must initialize this entry in the
2252 global offset table. Since the offset must
2253 always be a multiple of 4, we use the least
2254 significant bit to record whether we have
2255 initialized it already.
2257 When doing a dynamic link, we create a .rela.got
2258 relocation entry to initialize the value. This
2259 is done in the finish_dynamic_symbol routine. */
2264 bfd_put_32 (output_bfd
, relocation
,
2265 sgot
->contents
+ off
);
2270 relocation
= sgot
->output_offset
+ off
;
2276 BFD_ASSERT (local_got_offsets
!= NULL
2277 && local_got_offsets
[r_symndx
] != (bfd_vma
) -1);
2279 off
= local_got_offsets
[r_symndx
];
2281 /* The offset must always be a multiple of 4. We use
2282 the least significant bit to record whether we have
2283 already processed this entry. */
2288 bfd_put_32 (output_bfd
, relocation
, sgot
->contents
+ off
);
2293 Elf_Internal_Rela outrel
;
2295 /* We need to generate a R_PPC_RELATIVE reloc
2296 for the dynamic linker. */
2297 srelgot
= bfd_get_section_by_name (dynobj
, ".rela.got");
2298 BFD_ASSERT (srelgot
!= NULL
);
2300 outrel
.r_offset
= (sgot
->output_section
->vma
2301 + sgot
->output_offset
2303 outrel
.r_info
= ELF32_R_INFO (0, R_PPC_RELATIVE
);
2304 outrel
.r_addend
= 0;
2305 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
,
2306 (((Elf32_External_Rela
*)
2308 + srelgot
->reloc_count
));
2309 ++srelgot
->reloc_count
;
2312 local_got_offsets
[r_symndx
] |= 1;
2315 relocation
= sgot
->output_offset
+ off
;
2320 /* Handle the TOC16 reloc. We want to use the offset within the .got
2321 section, not the actual VMA. This is appropriate when generating
2322 an embedded ELF object, for which the .got section acts like the
2323 AIX .toc section. */
2324 case (int)R_PPC_TOC16
: /* phony GOT16 relocations */
2325 BFD_ASSERT (sec
!= (asection
*)0);
2326 BFD_ASSERT (bfd_is_und_section (sec
)
2327 || strcmp (bfd_get_section_name (abfd
, sec
), ".got") == 0
2328 || strcmp (bfd_get_section_name (abfd
, sec
), ".cgot") == 0
2329 || strcmp (bfd_get_section_name (abfd
, sec
), ".sdata") == 0
2330 || strcmp (bfd_get_section_name (abfd
, sec
), ".sbss") == 0)
2332 addend
-= sec
->output_section
->vma
+ 0x8000;
2335 case (int)R_PPC_ADDR16_HA
: /* arithmetic adjust relocations */
2336 BFD_ASSERT (sec
!= (asection
*)0);
2337 addend
+= ((relocation
+ addend
) & 0x8000) << 1;
2340 case R_PPC_PLTREL24
:
2342 case R_PPC_GLOB_DAT
:
2343 case R_PPC_JMP_SLOT
:
2344 case R_PPC_RELATIVE
:
2345 case R_PPC_LOCAL24PC
:
2347 case R_PPC_PLTREL32
:
2348 case R_PPC_PLT16_LO
:
2349 case R_PPC_PLT16_HI
:
2350 case R_PPC_PLT16_HA
:
2351 case R_PPC_SDAREL16
:
2353 case R_PPC_SECTOFF_LO
:
2354 case R_PPC_SECTOFF_HI
:
2355 case R_PPC_SECTOFF_HA
:
2356 case R_PPC_EMB_NADDR32
:
2357 case R_PPC_EMB_NADDR16
:
2358 case R_PPC_EMB_NADDR16_LO
:
2359 case R_PPC_EMB_NADDR16_HI
:
2360 case R_PPC_EMB_NADDR16_HA
:
2361 case R_PPC_EMB_SDAI16
:
2362 case R_PPC_EMB_SDA2I16
:
2363 case R_PPC_EMB_SDA2REL
:
2364 case R_PPC_EMB_SDA21
:
2365 case R_PPC_EMB_MRKREF
:
2366 case R_PPC_EMB_RELSEC16
:
2367 case R_PPC_EMB_RELST_LO
:
2368 case R_PPC_EMB_RELST_HI
:
2369 case R_PPC_EMB_RELST_HA
:
2370 case R_PPC_EMB_BIT_FLD
:
2371 case R_PPC_EMB_RELSDA
:
2372 (*_bfd_error_handler
) ("%s: Relocation %s is not yet supported.",
2373 bfd_get_filename (input_bfd
),
2374 ppc_elf_howto_table
[ (int)r_type
]->name
);
2376 bfd_set_error (bfd_error_bad_value
);
2383 fprintf (stderr
, "\ttype = %s (%d), symbol index = %ld, offset = %ld, addend = %ld\n",
2391 r
= _bfd_final_link_relocate (howto
,
2399 if (r
!= bfd_reloc_ok
)
2407 case bfd_reloc_overflow
:
2412 name
= h
->root
.root
.string
;
2415 name
= bfd_elf_string_from_elf_section (input_bfd
,
2416 symtab_hdr
->sh_link
,
2422 name
= bfd_section_name (input_bfd
, sec
);
2425 (*info
->callbacks
->reloc_overflow
)(info
,
2441 fprintf (stderr
, "\n");
2448 #define TARGET_LITTLE_SYM bfd_elf32_powerpcle_vec
2449 #define TARGET_LITTLE_NAME "elf32-powerpcle"
2450 #define TARGET_BIG_SYM bfd_elf32_powerpc_vec
2451 #define TARGET_BIG_NAME "elf32-powerpc"
2452 #define ELF_ARCH bfd_arch_powerpc
2453 #define ELF_MACHINE_CODE EM_PPC
2454 #define ELF_MAXPAGESIZE 0x10000
2455 #define elf_info_to_howto ppc_elf_info_to_howto
2457 #ifdef EM_CYGNUS_POWERPC
2458 #define ELF_MACHINE_ALT1 EM_CYGNUS_POWERPC
2462 #define ELF_MACHINE_ALT2 EM_PPC_OLD
2465 #define bfd_elf32_bfd_copy_private_bfd_data ppc_elf_copy_private_bfd_data
2466 #define bfd_elf32_bfd_merge_private_bfd_data ppc_elf_merge_private_bfd_data
2467 #define bfd_elf32_bfd_set_private_flags ppc_elf_set_private_flags
2468 #define bfd_elf32_bfd_reloc_type_lookup ppc_elf_reloc_type_lookup
2469 #define elf_backend_section_from_shdr ppc_elf_section_from_shdr
2470 #define elf_backend_relocate_section ppc_elf_relocate_section
2471 #define elf_backend_create_dynamic_sections _bfd_elf_create_dynamic_sections
2472 #define elf_backend_check_relocs ppc_elf_check_relocs
2473 #define elf_backend_adjust_dynamic_symbol ppc_elf_adjust_dynamic_symbol
2474 #define elf_backend_size_dynamic_sections ppc_elf_size_dynamic_sections
2475 #define elf_backend_finish_dynamic_symbol ppc_elf_finish_dynamic_symbol
2476 #define elf_backend_finish_dynamic_sections ppc_elf_finish_dynamic_sections
2477 #define elf_backend_fake_sections ppc_elf_fake_sections
2479 #include "elf32-target.h"