1 /* PowerPC-specific support for 32-bit ELF
2 Copyright 1994, 1995, 1996, 1997, 1998 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. */
32 #define START_RELOC_NUMBERS(name) enum name {
33 #define RELOC_NUMBER(name, number) name = number ,
34 #define END_RELOC_NUMBERS };
37 #define USE_RELA /* we want RELA relocations, not REL */
40 static reloc_howto_type
*ppc_elf_reloc_type_lookup
41 PARAMS ((bfd
*abfd
, bfd_reloc_code_real_type code
));
42 static void ppc_elf_info_to_howto
43 PARAMS ((bfd
*abfd
, arelent
*cache_ptr
, Elf32_Internal_Rela
*dst
));
44 static void ppc_elf_howto_init
PARAMS ((void));
45 static bfd_reloc_status_type ppc_elf_addr16_ha_reloc
46 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
47 static boolean ppc_elf_set_private_flags
PARAMS ((bfd
*, flagword
));
48 static boolean ppc_elf_copy_private_bfd_data
PARAMS ((bfd
*, bfd
*));
49 static boolean ppc_elf_merge_private_bfd_data
PARAMS ((bfd
*, bfd
*));
51 static int ppc_elf_additional_program_headers
PARAMS ((bfd
*));
52 static boolean ppc_elf_modify_segment_map
PARAMS ((bfd
*));
54 static boolean ppc_elf_create_dynamic_sections
55 PARAMS ((bfd
*, struct bfd_link_info
*));
57 static boolean ppc_elf_section_from_shdr
PARAMS ((bfd
*,
58 Elf32_Internal_Shdr
*,
60 static boolean ppc_elf_fake_sections
61 PARAMS ((bfd
*, Elf32_Internal_Shdr
*, asection
*));
63 static elf_linker_section_t
*ppc_elf_create_linker_section
65 struct bfd_link_info
*info
,
66 enum elf_linker_section_enum
));
68 static boolean ppc_elf_check_relocs
PARAMS ((bfd
*,
69 struct bfd_link_info
*,
71 const Elf_Internal_Rela
*));
73 static asection
* ppc_elf_gc_mark_hook
PARAMS ((bfd
*abfd
,
74 struct bfd_link_info
*info
,
75 Elf_Internal_Rela
*rel
,
76 struct elf_link_hash_entry
*h
,
77 Elf_Internal_Sym
*sym
));
79 static boolean ppc_elf_gc_sweep_hook
PARAMS ((bfd
*abfd
,
80 struct bfd_link_info
*info
,
82 const Elf_Internal_Rela
*relocs
));
84 static boolean ppc_elf_adjust_dynamic_symbol
PARAMS ((struct bfd_link_info
*,
85 struct elf_link_hash_entry
*));
87 static boolean ppc_elf_adjust_dynindx
PARAMS ((struct elf_link_hash_entry
*, PTR
));
89 static boolean ppc_elf_size_dynamic_sections
PARAMS ((bfd
*, struct bfd_link_info
*));
91 static boolean ppc_elf_relocate_section
PARAMS ((bfd
*,
92 struct bfd_link_info
*info
,
96 Elf_Internal_Rela
*relocs
,
97 Elf_Internal_Sym
*local_syms
,
100 static boolean ppc_elf_add_symbol_hook
PARAMS ((bfd
*,
101 struct bfd_link_info
*,
102 const Elf_Internal_Sym
*,
108 static boolean ppc_elf_finish_dynamic_symbol
PARAMS ((bfd
*,
109 struct bfd_link_info
*,
110 struct elf_link_hash_entry
*,
111 Elf_Internal_Sym
*));
113 static boolean ppc_elf_finish_dynamic_sections
PARAMS ((bfd
*, struct bfd_link_info
*));
115 #define BRANCH_PREDICT_BIT 0x200000 /* branch prediction bit for branch taken relocs */
116 #define RA_REGISTER_MASK 0x001f0000 /* mask to set RA in memory instructions */
117 #define RA_REGISTER_SHIFT 16 /* value to shift register by to insert RA */
119 /* The name of the dynamic interpreter. This is put in the .interp
122 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
124 /* The size in bytes of an entry in the procedure linkage table, and of the initial size
125 of the plt reserved for the dynamic linker. */
127 #define PLT_ENTRY_SIZE 12
128 #define PLT_INITIAL_ENTRY_SIZE 72
131 static reloc_howto_type
*ppc_elf_howto_table
[ (int)R_PPC_max
];
133 static reloc_howto_type ppc_elf_howto_raw
[] =
135 /* This reloc does nothing. */
136 HOWTO (R_PPC_NONE
, /* type */
138 2, /* size (0 = byte, 1 = short, 2 = long) */
140 false, /* pc_relative */
142 complain_overflow_bitfield
, /* complain_on_overflow */
143 bfd_elf_generic_reloc
, /* special_function */
144 "R_PPC_NONE", /* name */
145 false, /* partial_inplace */
148 false), /* pcrel_offset */
150 /* A standard 32 bit relocation. */
151 HOWTO (R_PPC_ADDR32
, /* type */
153 2, /* size (0 = byte, 1 = short, 2 = long) */
155 false, /* pc_relative */
157 complain_overflow_bitfield
, /* complain_on_overflow */
158 bfd_elf_generic_reloc
, /* special_function */
159 "R_PPC_ADDR32", /* name */
160 false, /* partial_inplace */
162 0xffffffff, /* dst_mask */
163 false), /* pcrel_offset */
165 /* An absolute 26 bit branch; the lower two bits must be zero.
166 FIXME: we don't check that, we just clear them. */
167 HOWTO (R_PPC_ADDR24
, /* type */
169 2, /* size (0 = byte, 1 = short, 2 = long) */
171 false, /* pc_relative */
173 complain_overflow_bitfield
, /* complain_on_overflow */
174 bfd_elf_generic_reloc
, /* special_function */
175 "R_PPC_ADDR24", /* name */
176 false, /* partial_inplace */
178 0x3fffffc, /* dst_mask */
179 false), /* pcrel_offset */
181 /* A standard 16 bit relocation. */
182 HOWTO (R_PPC_ADDR16
, /* type */
184 1, /* size (0 = byte, 1 = short, 2 = long) */
186 false, /* pc_relative */
188 complain_overflow_bitfield
, /* complain_on_overflow */
189 bfd_elf_generic_reloc
, /* special_function */
190 "R_PPC_ADDR16", /* name */
191 false, /* partial_inplace */
193 0xffff, /* dst_mask */
194 false), /* pcrel_offset */
196 /* A 16 bit relocation without overflow. */
197 HOWTO (R_PPC_ADDR16_LO
, /* type */
199 1, /* size (0 = byte, 1 = short, 2 = long) */
201 false, /* pc_relative */
203 complain_overflow_dont
,/* complain_on_overflow */
204 bfd_elf_generic_reloc
, /* special_function */
205 "R_PPC_ADDR16_LO", /* name */
206 false, /* partial_inplace */
208 0xffff, /* dst_mask */
209 false), /* pcrel_offset */
211 /* The high order 16 bits of an address. */
212 HOWTO (R_PPC_ADDR16_HI
, /* type */
214 1, /* size (0 = byte, 1 = short, 2 = long) */
216 false, /* pc_relative */
218 complain_overflow_dont
, /* complain_on_overflow */
219 bfd_elf_generic_reloc
, /* special_function */
220 "R_PPC_ADDR16_HI", /* name */
221 false, /* partial_inplace */
223 0xffff, /* dst_mask */
224 false), /* pcrel_offset */
226 /* The high order 16 bits of an address, plus 1 if the contents of
227 the low 16 bits, treated as a signed number, is negative. */
228 HOWTO (R_PPC_ADDR16_HA
, /* type */
230 1, /* size (0 = byte, 1 = short, 2 = long) */
232 false, /* pc_relative */
234 complain_overflow_dont
, /* complain_on_overflow */
235 ppc_elf_addr16_ha_reloc
, /* special_function */
236 "R_PPC_ADDR16_HA", /* name */
237 false, /* partial_inplace */
239 0xffff, /* dst_mask */
240 false), /* pcrel_offset */
242 /* An absolute 16 bit branch; the lower two bits must be zero.
243 FIXME: we don't check that, we just clear them. */
244 HOWTO (R_PPC_ADDR14
, /* type */
246 2, /* size (0 = byte, 1 = short, 2 = long) */
248 false, /* pc_relative */
250 complain_overflow_bitfield
, /* complain_on_overflow */
251 bfd_elf_generic_reloc
, /* special_function */
252 "R_PPC_ADDR14", /* name */
253 false, /* partial_inplace */
255 0xfffc, /* dst_mask */
256 false), /* pcrel_offset */
258 /* An absolute 16 bit branch, for which bit 10 should be set to
259 indicate that the branch is expected to be taken. The lower two
260 bits must be zero. */
261 HOWTO (R_PPC_ADDR14_BRTAKEN
, /* type */
263 2, /* size (0 = byte, 1 = short, 2 = long) */
265 false, /* pc_relative */
267 complain_overflow_bitfield
, /* complain_on_overflow */
268 bfd_elf_generic_reloc
, /* special_function */
269 "R_PPC_ADDR14_BRTAKEN",/* name */
270 false, /* partial_inplace */
272 0xfffc, /* dst_mask */
273 false), /* pcrel_offset */
275 /* An absolute 16 bit branch, for which bit 10 should be set to
276 indicate that the branch is not expected to be taken. The lower
277 two bits must be zero. */
278 HOWTO (R_PPC_ADDR14_BRNTAKEN
, /* type */
280 2, /* size (0 = byte, 1 = short, 2 = long) */
282 false, /* pc_relative */
284 complain_overflow_bitfield
, /* complain_on_overflow */
285 bfd_elf_generic_reloc
, /* special_function */
286 "R_PPC_ADDR14_BRNTAKEN",/* name */
287 false, /* partial_inplace */
289 0xfffc, /* dst_mask */
290 false), /* pcrel_offset */
292 /* A relative 26 bit branch; the lower two bits must be zero. */
293 HOWTO (R_PPC_REL24
, /* type */
295 2, /* size (0 = byte, 1 = short, 2 = long) */
297 true, /* pc_relative */
299 complain_overflow_signed
, /* complain_on_overflow */
300 bfd_elf_generic_reloc
, /* special_function */
301 "R_PPC_REL24", /* name */
302 false, /* partial_inplace */
304 0x3fffffc, /* dst_mask */
305 true), /* pcrel_offset */
307 /* A relative 16 bit branch; the lower two bits must be zero. */
308 HOWTO (R_PPC_REL14
, /* type */
310 2, /* size (0 = byte, 1 = short, 2 = long) */
312 true, /* pc_relative */
314 complain_overflow_signed
, /* complain_on_overflow */
315 bfd_elf_generic_reloc
, /* special_function */
316 "R_PPC_REL14", /* name */
317 false, /* partial_inplace */
319 0xfffc, /* dst_mask */
320 true), /* pcrel_offset */
322 /* A relative 16 bit branch. Bit 10 should be set to indicate that
323 the branch is expected to be taken. The lower two bits must be
325 HOWTO (R_PPC_REL14_BRTAKEN
, /* type */
327 2, /* size (0 = byte, 1 = short, 2 = long) */
329 true, /* pc_relative */
331 complain_overflow_signed
, /* complain_on_overflow */
332 bfd_elf_generic_reloc
, /* special_function */
333 "R_PPC_REL14_BRTAKEN", /* name */
334 false, /* partial_inplace */
336 0xfffc, /* dst_mask */
337 true), /* pcrel_offset */
339 /* A relative 16 bit branch. Bit 10 should be set to indicate that
340 the branch is not expected to be taken. The lower two bits must
342 HOWTO (R_PPC_REL14_BRNTAKEN
, /* type */
344 2, /* size (0 = byte, 1 = short, 2 = long) */
346 true, /* pc_relative */
348 complain_overflow_signed
, /* complain_on_overflow */
349 bfd_elf_generic_reloc
, /* special_function */
350 "R_PPC_REL14_BRNTAKEN",/* name */
351 false, /* partial_inplace */
353 0xfffc, /* dst_mask */
354 true), /* pcrel_offset */
356 /* Like R_PPC_ADDR16, but referring to the GOT table entry for the
358 HOWTO (R_PPC_GOT16
, /* type */
360 1, /* size (0 = byte, 1 = short, 2 = long) */
362 false, /* pc_relative */
364 complain_overflow_signed
, /* complain_on_overflow */
365 bfd_elf_generic_reloc
, /* special_function */
366 "R_PPC_GOT16", /* name */
367 false, /* partial_inplace */
369 0xffff, /* dst_mask */
370 false), /* pcrel_offset */
372 /* Like R_PPC_ADDR16_LO, but referring to the GOT table entry for
374 HOWTO (R_PPC_GOT16_LO
, /* type */
376 1, /* size (0 = byte, 1 = short, 2 = long) */
378 false, /* pc_relative */
380 complain_overflow_bitfield
, /* complain_on_overflow */
381 bfd_elf_generic_reloc
, /* special_function */
382 "R_PPC_GOT16_LO", /* name */
383 false, /* partial_inplace */
385 0xffff, /* dst_mask */
386 false), /* pcrel_offset */
388 /* Like R_PPC_ADDR16_HI, but referring to the GOT table entry for
390 HOWTO (R_PPC_GOT16_HI
, /* type */
392 1, /* size (0 = byte, 1 = short, 2 = long) */
394 false, /* pc_relative */
396 complain_overflow_bitfield
, /* complain_on_overflow */
397 bfd_elf_generic_reloc
, /* special_function */
398 "R_PPC_GOT16_HI", /* name */
399 false, /* partial_inplace */
401 0xffff, /* dst_mask */
402 false), /* pcrel_offset */
404 /* Like R_PPC_ADDR16_HA, but referring to the GOT table entry for
406 HOWTO (R_PPC_GOT16_HA
, /* type */
408 1, /* size (0 = byte, 1 = short, 2 = long) */
410 false, /* pc_relative */
412 complain_overflow_bitfield
, /* complain_on_overflow */
413 ppc_elf_addr16_ha_reloc
, /* special_function */
414 "R_PPC_GOT16_HA", /* name */
415 false, /* partial_inplace */
417 0xffff, /* dst_mask */
418 false), /* pcrel_offset */
420 /* Like R_PPC_REL24, but referring to the procedure linkage table
421 entry for the symbol. */
422 HOWTO (R_PPC_PLTREL24
, /* type */
424 2, /* size (0 = byte, 1 = short, 2 = long) */
426 true, /* pc_relative */
428 complain_overflow_signed
, /* complain_on_overflow */
429 bfd_elf_generic_reloc
, /* special_function */
430 "R_PPC_PLTREL24", /* name */
431 false, /* partial_inplace */
433 0x3fffffc, /* dst_mask */
434 true), /* pcrel_offset */
436 /* This is used only by the dynamic linker. The symbol should exist
437 both in the object being run and in some shared library. The
438 dynamic linker copies the data addressed by the symbol from the
439 shared library into the object, because the object being
440 run has to have the data at some particular address. */
441 HOWTO (R_PPC_COPY
, /* type */
443 2, /* size (0 = byte, 1 = short, 2 = long) */
445 false, /* pc_relative */
447 complain_overflow_bitfield
, /* complain_on_overflow */
448 bfd_elf_generic_reloc
, /* special_function */
449 "R_PPC_COPY", /* name */
450 false, /* partial_inplace */
453 false), /* pcrel_offset */
455 /* Like R_PPC_ADDR32, but used when setting global offset table
457 HOWTO (R_PPC_GLOB_DAT
, /* type */
459 2, /* size (0 = byte, 1 = short, 2 = long) */
461 false, /* pc_relative */
463 complain_overflow_bitfield
, /* complain_on_overflow */
464 bfd_elf_generic_reloc
, /* special_function */
465 "R_PPC_GLOB_DAT", /* name */
466 false, /* partial_inplace */
468 0xffffffff, /* dst_mask */
469 false), /* pcrel_offset */
471 /* Marks a procedure linkage table entry for a symbol. */
472 HOWTO (R_PPC_JMP_SLOT
, /* type */
474 2, /* size (0 = byte, 1 = short, 2 = long) */
476 false, /* pc_relative */
478 complain_overflow_bitfield
, /* complain_on_overflow */
479 bfd_elf_generic_reloc
, /* special_function */
480 "R_PPC_JMP_SLOT", /* name */
481 false, /* partial_inplace */
484 false), /* pcrel_offset */
486 /* Used only by the dynamic linker. When the object is run, this
487 longword is set to the load address of the object, plus the
489 HOWTO (R_PPC_RELATIVE
, /* type */
491 2, /* size (0 = byte, 1 = short, 2 = long) */
493 false, /* pc_relative */
495 complain_overflow_bitfield
, /* complain_on_overflow */
496 bfd_elf_generic_reloc
, /* special_function */
497 "R_PPC_RELATIVE", /* name */
498 false, /* partial_inplace */
500 0xffffffff, /* dst_mask */
501 false), /* pcrel_offset */
503 /* Like R_PPC_REL24, but uses the value of the symbol within the
504 object rather than the final value. Normally used for
505 _GLOBAL_OFFSET_TABLE_. */
506 HOWTO (R_PPC_LOCAL24PC
, /* type */
508 2, /* size (0 = byte, 1 = short, 2 = long) */
510 true, /* pc_relative */
512 complain_overflow_signed
, /* complain_on_overflow */
513 bfd_elf_generic_reloc
, /* special_function */
514 "R_PPC_LOCAL24PC", /* name */
515 false, /* partial_inplace */
517 0x3fffffc, /* dst_mask */
518 true), /* pcrel_offset */
520 /* Like R_PPC_ADDR32, but may be unaligned. */
521 HOWTO (R_PPC_UADDR32
, /* type */
523 2, /* size (0 = byte, 1 = short, 2 = long) */
525 false, /* pc_relative */
527 complain_overflow_bitfield
, /* complain_on_overflow */
528 bfd_elf_generic_reloc
, /* special_function */
529 "R_PPC_UADDR32", /* name */
530 false, /* partial_inplace */
532 0xffffffff, /* dst_mask */
533 false), /* pcrel_offset */
535 /* Like R_PPC_ADDR16, but may be unaligned. */
536 HOWTO (R_PPC_UADDR16
, /* type */
538 1, /* size (0 = byte, 1 = short, 2 = long) */
540 false, /* pc_relative */
542 complain_overflow_bitfield
, /* complain_on_overflow */
543 bfd_elf_generic_reloc
, /* special_function */
544 "R_PPC_UADDR16", /* name */
545 false, /* partial_inplace */
547 0xffff, /* dst_mask */
548 false), /* pcrel_offset */
550 /* 32-bit PC relative */
551 HOWTO (R_PPC_REL32
, /* type */
553 2, /* size (0 = byte, 1 = short, 2 = long) */
555 true, /* pc_relative */
557 complain_overflow_bitfield
, /* complain_on_overflow */
558 bfd_elf_generic_reloc
, /* special_function */
559 "R_PPC_REL32", /* name */
560 false, /* partial_inplace */
562 0xffffffff, /* dst_mask */
563 true), /* pcrel_offset */
565 /* 32-bit relocation to the symbol's procedure linkage table.
566 FIXME: not supported. */
567 HOWTO (R_PPC_PLT32
, /* type */
569 2, /* size (0 = byte, 1 = short, 2 = long) */
571 false, /* pc_relative */
573 complain_overflow_bitfield
, /* complain_on_overflow */
574 bfd_elf_generic_reloc
, /* special_function */
575 "R_PPC_PLT32", /* name */
576 false, /* partial_inplace */
579 false), /* pcrel_offset */
581 /* 32-bit PC relative relocation to the symbol's procedure linkage table.
582 FIXME: not supported. */
583 HOWTO (R_PPC_PLTREL32
, /* type */
585 2, /* size (0 = byte, 1 = short, 2 = long) */
587 true, /* pc_relative */
589 complain_overflow_bitfield
, /* complain_on_overflow */
590 bfd_elf_generic_reloc
, /* special_function */
591 "R_PPC_PLTREL32", /* name */
592 false, /* partial_inplace */
595 true), /* pcrel_offset */
597 /* Like R_PPC_ADDR16_LO, but referring to the PLT table entry for
599 HOWTO (R_PPC_PLT16_LO
, /* type */
601 1, /* size (0 = byte, 1 = short, 2 = long) */
603 false, /* pc_relative */
605 complain_overflow_bitfield
, /* complain_on_overflow */
606 bfd_elf_generic_reloc
, /* special_function */
607 "R_PPC_PLT16_LO", /* name */
608 false, /* partial_inplace */
610 0xffff, /* dst_mask */
611 false), /* pcrel_offset */
613 /* Like R_PPC_ADDR16_HI, but referring to the PLT table entry for
615 HOWTO (R_PPC_PLT16_HI
, /* type */
617 1, /* size (0 = byte, 1 = short, 2 = long) */
619 false, /* pc_relative */
621 complain_overflow_bitfield
, /* complain_on_overflow */
622 bfd_elf_generic_reloc
, /* special_function */
623 "R_PPC_PLT16_HI", /* name */
624 false, /* partial_inplace */
626 0xffff, /* dst_mask */
627 false), /* pcrel_offset */
629 /* Like R_PPC_ADDR16_HA, but referring to the PLT table entry for
630 the symbol. FIXME: Not supported. */
631 HOWTO (R_PPC_PLT16_HA
, /* type */
633 1, /* size (0 = byte, 1 = short, 2 = long) */
635 false, /* pc_relative */
637 complain_overflow_bitfield
, /* complain_on_overflow */
638 bfd_elf_generic_reloc
, /* special_function */
639 "R_PPC_PLT16_HA", /* name */
640 false, /* partial_inplace */
642 0xffff, /* dst_mask */
643 false), /* pcrel_offset */
645 /* A sign-extended 16 bit value relative to _SDA_BASE_, for use with
647 HOWTO (R_PPC_SDAREL16
, /* type */
649 1, /* size (0 = byte, 1 = short, 2 = long) */
651 false, /* pc_relative */
653 complain_overflow_signed
, /* complain_on_overflow */
654 bfd_elf_generic_reloc
, /* special_function */
655 "R_PPC_SDAREL16", /* name */
656 false, /* partial_inplace */
658 0xffff, /* dst_mask */
659 false), /* pcrel_offset */
661 /* 32-bit section relative relocation. */
662 HOWTO (R_PPC_SECTOFF
, /* type */
664 2, /* size (0 = byte, 1 = short, 2 = long) */
666 true, /* pc_relative */
668 complain_overflow_bitfield
, /* complain_on_overflow */
669 bfd_elf_generic_reloc
, /* special_function */
670 "R_PPC_SECTOFF", /* name */
671 false, /* partial_inplace */
674 true), /* pcrel_offset */
676 /* 16-bit lower half section relative relocation. */
677 HOWTO (R_PPC_SECTOFF_LO
, /* type */
679 1, /* size (0 = byte, 1 = short, 2 = long) */
681 false, /* pc_relative */
683 complain_overflow_bitfield
, /* complain_on_overflow */
684 bfd_elf_generic_reloc
, /* special_function */
685 "R_PPC_SECTOFF_LO", /* name */
686 false, /* partial_inplace */
688 0xffff, /* dst_mask */
689 false), /* pcrel_offset */
691 /* 16-bit upper half section relative relocation. */
692 HOWTO (R_PPC_SECTOFF_HI
, /* type */
694 1, /* size (0 = byte, 1 = short, 2 = long) */
696 false, /* pc_relative */
698 complain_overflow_bitfield
, /* complain_on_overflow */
699 bfd_elf_generic_reloc
, /* special_function */
700 "R_PPC_SECTOFF_HI", /* name */
701 false, /* partial_inplace */
703 0xffff, /* dst_mask */
704 false), /* pcrel_offset */
706 /* 16-bit upper half adjusted section relative relocation. */
707 HOWTO (R_PPC_SECTOFF_HA
, /* type */
709 1, /* size (0 = byte, 1 = short, 2 = long) */
711 false, /* pc_relative */
713 complain_overflow_bitfield
, /* complain_on_overflow */
714 bfd_elf_generic_reloc
, /* special_function */
715 "R_PPC_SECTOFF_HA", /* name */
716 false, /* partial_inplace */
718 0xffff, /* dst_mask */
719 false), /* pcrel_offset */
721 /* The remaining relocs are from the Embedded ELF ABI, and are not
722 in the SVR4 ELF ABI. */
724 /* 32 bit value resulting from the addend minus the symbol */
725 HOWTO (R_PPC_EMB_NADDR32
, /* type */
727 2, /* size (0 = byte, 1 = short, 2 = long) */
729 false, /* pc_relative */
731 complain_overflow_bitfield
, /* complain_on_overflow */
732 bfd_elf_generic_reloc
, /* special_function */
733 "R_PPC_EMB_NADDR32", /* name */
734 false, /* partial_inplace */
736 0xffffffff, /* dst_mask */
737 false), /* pcrel_offset */
739 /* 16 bit value resulting from the addend minus the symbol */
740 HOWTO (R_PPC_EMB_NADDR16
, /* type */
742 1, /* size (0 = byte, 1 = short, 2 = long) */
744 false, /* pc_relative */
746 complain_overflow_bitfield
, /* complain_on_overflow */
747 bfd_elf_generic_reloc
, /* special_function */
748 "R_PPC_EMB_NADDR16", /* name */
749 false, /* partial_inplace */
751 0xffff, /* dst_mask */
752 false), /* pcrel_offset */
754 /* 16 bit value resulting from the addend minus the symbol */
755 HOWTO (R_PPC_EMB_NADDR16_LO
, /* type */
757 1, /* size (0 = byte, 1 = short, 2 = long) */
759 false, /* pc_relative */
761 complain_overflow_dont
,/* complain_on_overflow */
762 bfd_elf_generic_reloc
, /* special_function */
763 "R_PPC_EMB_ADDR16_LO", /* name */
764 false, /* partial_inplace */
766 0xffff, /* dst_mask */
767 false), /* pcrel_offset */
769 /* The high order 16 bits of the addend minus the symbol */
770 HOWTO (R_PPC_EMB_NADDR16_HI
, /* type */
772 1, /* size (0 = byte, 1 = short, 2 = long) */
774 false, /* pc_relative */
776 complain_overflow_dont
, /* complain_on_overflow */
777 bfd_elf_generic_reloc
, /* special_function */
778 "R_PPC_EMB_NADDR16_HI", /* name */
779 false, /* partial_inplace */
781 0xffff, /* dst_mask */
782 false), /* pcrel_offset */
784 /* The high order 16 bits of the result of the addend minus the address,
785 plus 1 if the contents of the low 16 bits, treated as a signed number,
787 HOWTO (R_PPC_EMB_NADDR16_HA
, /* type */
789 1, /* size (0 = byte, 1 = short, 2 = long) */
791 false, /* pc_relative */
793 complain_overflow_dont
, /* complain_on_overflow */
794 bfd_elf_generic_reloc
, /* special_function */
795 "R_PPC_EMB_NADDR16_HA", /* name */
796 false, /* partial_inplace */
798 0xffff, /* dst_mask */
799 false), /* pcrel_offset */
801 /* 16 bit value resulting from allocating a 4 byte word to hold an
802 address in the .sdata section, and returning the offset from
803 _SDA_BASE_ for that relocation */
804 HOWTO (R_PPC_EMB_SDAI16
, /* type */
806 1, /* size (0 = byte, 1 = short, 2 = long) */
808 false, /* pc_relative */
810 complain_overflow_bitfield
, /* complain_on_overflow */
811 bfd_elf_generic_reloc
, /* special_function */
812 "R_PPC_EMB_SDAI16", /* name */
813 false, /* partial_inplace */
815 0xffff, /* dst_mask */
816 false), /* pcrel_offset */
818 /* 16 bit value resulting from allocating a 4 byte word to hold an
819 address in the .sdata2 section, and returning the offset from
820 _SDA2_BASE_ for that relocation */
821 HOWTO (R_PPC_EMB_SDA2I16
, /* type */
823 1, /* size (0 = byte, 1 = short, 2 = long) */
825 false, /* pc_relative */
827 complain_overflow_bitfield
, /* complain_on_overflow */
828 bfd_elf_generic_reloc
, /* special_function */
829 "R_PPC_EMB_SDA2I16", /* name */
830 false, /* partial_inplace */
832 0xffff, /* dst_mask */
833 false), /* pcrel_offset */
835 /* A sign-extended 16 bit value relative to _SDA2_BASE_, for use with
837 HOWTO (R_PPC_EMB_SDA2REL
, /* type */
839 1, /* size (0 = byte, 1 = short, 2 = long) */
841 false, /* pc_relative */
843 complain_overflow_signed
, /* complain_on_overflow */
844 bfd_elf_generic_reloc
, /* special_function */
845 "R_PPC_EMB_SDA2REL", /* name */
846 false, /* partial_inplace */
848 0xffff, /* dst_mask */
849 false), /* pcrel_offset */
851 /* Relocate against either _SDA_BASE_ or _SDA2_BASE_, filling in the 16 bit
852 signed offset from the appropriate base, and filling in the register
853 field with the appropriate register (0, 2, or 13). */
854 HOWTO (R_PPC_EMB_SDA21
, /* type */
856 2, /* size (0 = byte, 1 = short, 2 = long) */
858 false, /* pc_relative */
860 complain_overflow_signed
, /* complain_on_overflow */
861 bfd_elf_generic_reloc
, /* special_function */
862 "R_PPC_EMB_SDA21", /* name */
863 false, /* partial_inplace */
865 0xffff, /* dst_mask */
866 false), /* pcrel_offset */
868 /* Relocation not handled: R_PPC_EMB_MRKREF */
869 /* Relocation not handled: R_PPC_EMB_RELSEC16 */
870 /* Relocation not handled: R_PPC_EMB_RELST_LO */
871 /* Relocation not handled: R_PPC_EMB_RELST_HI */
872 /* Relocation not handled: R_PPC_EMB_RELST_HA */
873 /* Relocation not handled: R_PPC_EMB_BIT_FLD */
875 /* PC relative relocation against either _SDA_BASE_ or _SDA2_BASE_, filling
876 in the 16 bit signed offset from the appropriate base, and filling in the
877 register field with the appropriate register (0, 2, or 13). */
878 HOWTO (R_PPC_EMB_RELSDA
, /* type */
880 1, /* size (0 = byte, 1 = short, 2 = long) */
882 true, /* pc_relative */
884 complain_overflow_signed
, /* complain_on_overflow */
885 bfd_elf_generic_reloc
, /* special_function */
886 "R_PPC_EMB_RELSDA", /* name */
887 false, /* partial_inplace */
889 0xffff, /* dst_mask */
890 false), /* pcrel_offset */
892 /* GNU extension to record C++ vtable hierarchy */
893 HOWTO (R_PPC_GNU_VTINHERIT
, /* type */
895 0, /* size (0 = byte, 1 = short, 2 = long) */
897 false, /* pc_relative */
899 complain_overflow_dont
, /* complain_on_overflow */
900 NULL
, /* special_function */
901 "R_PPC_GNU_VTINHERIT", /* name */
902 false, /* partial_inplace */
905 false), /* pcrel_offset */
907 /* GNU extension to record C++ vtable member usage */
908 HOWTO (R_PPC_GNU_VTENTRY
, /* type */
910 0, /* size (0 = byte, 1 = short, 2 = long) */
912 false, /* pc_relative */
914 complain_overflow_dont
, /* complain_on_overflow */
915 NULL
, /* special_function */
916 "R_PPC_GNU_VTENTRY", /* name */
917 false, /* partial_inplace */
920 false), /* pcrel_offset */
922 /* Phony reloc to handle AIX style TOC entries */
923 HOWTO (R_PPC_TOC16
, /* type */
925 1, /* size (0 = byte, 1 = short, 2 = long) */
927 false, /* pc_relative */
929 complain_overflow_signed
, /* complain_on_overflow */
930 bfd_elf_generic_reloc
, /* special_function */
931 "R_PPC_TOC16", /* name */
932 false, /* partial_inplace */
934 0xffff, /* dst_mask */
935 false), /* pcrel_offset */
939 /* Initialize the ppc_elf_howto_table, so that linear accesses can be done. */
942 ppc_elf_howto_init ()
944 unsigned int i
, type
;
946 for (i
= 0; i
< sizeof (ppc_elf_howto_raw
) / sizeof (ppc_elf_howto_raw
[0]); i
++)
948 type
= ppc_elf_howto_raw
[i
].type
;
949 BFD_ASSERT (type
< sizeof(ppc_elf_howto_table
) / sizeof(ppc_elf_howto_table
[0]));
950 ppc_elf_howto_table
[type
] = &ppc_elf_howto_raw
[i
];
955 static reloc_howto_type
*
956 ppc_elf_reloc_type_lookup (abfd
, code
)
958 bfd_reloc_code_real_type code
;
960 enum ppc_reloc_type ppc_reloc
= R_PPC_NONE
;
962 if (!ppc_elf_howto_table
[R_PPC_ADDR32
])
963 /* Initialize howto table if needed */
964 ppc_elf_howto_init ();
969 return (reloc_howto_type
*)NULL
;
971 case BFD_RELOC_NONE
: ppc_reloc
= R_PPC_NONE
; break;
972 case BFD_RELOC_32
: ppc_reloc
= R_PPC_ADDR32
; break;
973 case BFD_RELOC_PPC_BA26
: ppc_reloc
= R_PPC_ADDR24
; break;
974 case BFD_RELOC_16
: ppc_reloc
= R_PPC_ADDR16
; break;
975 case BFD_RELOC_LO16
: ppc_reloc
= R_PPC_ADDR16_LO
; break;
976 case BFD_RELOC_HI16
: ppc_reloc
= R_PPC_ADDR16_HI
; break;
977 case BFD_RELOC_HI16_S
: ppc_reloc
= R_PPC_ADDR16_HA
; break;
978 case BFD_RELOC_PPC_BA16
: ppc_reloc
= R_PPC_ADDR14
; break;
979 case BFD_RELOC_PPC_BA16_BRTAKEN
: ppc_reloc
= R_PPC_ADDR14_BRTAKEN
; break;
980 case BFD_RELOC_PPC_BA16_BRNTAKEN
: ppc_reloc
= R_PPC_ADDR14_BRNTAKEN
; break;
981 case BFD_RELOC_PPC_B26
: ppc_reloc
= R_PPC_REL24
; break;
982 case BFD_RELOC_PPC_B16
: ppc_reloc
= R_PPC_REL14
; break;
983 case BFD_RELOC_PPC_B16_BRTAKEN
: ppc_reloc
= R_PPC_REL14_BRTAKEN
; break;
984 case BFD_RELOC_PPC_B16_BRNTAKEN
: ppc_reloc
= R_PPC_REL14_BRNTAKEN
; break;
985 case BFD_RELOC_16_GOTOFF
: ppc_reloc
= R_PPC_GOT16
; break;
986 case BFD_RELOC_LO16_GOTOFF
: ppc_reloc
= R_PPC_GOT16_LO
; break;
987 case BFD_RELOC_HI16_GOTOFF
: ppc_reloc
= R_PPC_GOT16_HI
; break;
988 case BFD_RELOC_HI16_S_GOTOFF
: ppc_reloc
= R_PPC_GOT16_HA
; break;
989 case BFD_RELOC_24_PLT_PCREL
: ppc_reloc
= R_PPC_PLTREL24
; break;
990 case BFD_RELOC_PPC_COPY
: ppc_reloc
= R_PPC_COPY
; break;
991 case BFD_RELOC_PPC_GLOB_DAT
: ppc_reloc
= R_PPC_GLOB_DAT
; break;
992 case BFD_RELOC_PPC_LOCAL24PC
: ppc_reloc
= R_PPC_LOCAL24PC
; break;
993 case BFD_RELOC_32_PCREL
: ppc_reloc
= R_PPC_REL32
; break;
994 case BFD_RELOC_32_PLTOFF
: ppc_reloc
= R_PPC_PLT32
; break;
995 case BFD_RELOC_32_PLT_PCREL
: ppc_reloc
= R_PPC_PLTREL32
; break;
996 case BFD_RELOC_LO16_PLTOFF
: ppc_reloc
= R_PPC_PLT16_LO
; break;
997 case BFD_RELOC_HI16_PLTOFF
: ppc_reloc
= R_PPC_PLT16_HI
; break;
998 case BFD_RELOC_HI16_S_PLTOFF
: ppc_reloc
= R_PPC_PLT16_HA
; break;
999 case BFD_RELOC_GPREL16
: ppc_reloc
= R_PPC_SDAREL16
; break;
1000 case BFD_RELOC_32_BASEREL
: ppc_reloc
= R_PPC_SECTOFF
; break;
1001 case BFD_RELOC_LO16_BASEREL
: ppc_reloc
= R_PPC_SECTOFF_LO
; break;
1002 case BFD_RELOC_HI16_BASEREL
: ppc_reloc
= R_PPC_SECTOFF_HI
; break;
1003 case BFD_RELOC_HI16_S_BASEREL
: ppc_reloc
= R_PPC_SECTOFF_HA
; break;
1004 case BFD_RELOC_CTOR
: ppc_reloc
= R_PPC_ADDR32
; break;
1005 case BFD_RELOC_PPC_TOC16
: ppc_reloc
= R_PPC_TOC16
; break;
1006 case BFD_RELOC_PPC_EMB_NADDR32
: ppc_reloc
= R_PPC_EMB_NADDR32
; break;
1007 case BFD_RELOC_PPC_EMB_NADDR16
: ppc_reloc
= R_PPC_EMB_NADDR16
; break;
1008 case BFD_RELOC_PPC_EMB_NADDR16_LO
: ppc_reloc
= R_PPC_EMB_NADDR16_LO
; break;
1009 case BFD_RELOC_PPC_EMB_NADDR16_HI
: ppc_reloc
= R_PPC_EMB_NADDR16_HI
; break;
1010 case BFD_RELOC_PPC_EMB_NADDR16_HA
: ppc_reloc
= R_PPC_EMB_NADDR16_HA
; break;
1011 case BFD_RELOC_PPC_EMB_SDAI16
: ppc_reloc
= R_PPC_EMB_SDAI16
; break;
1012 case BFD_RELOC_PPC_EMB_SDA2I16
: ppc_reloc
= R_PPC_EMB_SDA2I16
; break;
1013 case BFD_RELOC_PPC_EMB_SDA2REL
: ppc_reloc
= R_PPC_EMB_SDA2REL
; break;
1014 case BFD_RELOC_PPC_EMB_SDA21
: ppc_reloc
= R_PPC_EMB_SDA21
; break;
1015 case BFD_RELOC_PPC_EMB_MRKREF
: ppc_reloc
= R_PPC_EMB_MRKREF
; break;
1016 case BFD_RELOC_PPC_EMB_RELSEC16
: ppc_reloc
= R_PPC_EMB_RELSEC16
; break;
1017 case BFD_RELOC_PPC_EMB_RELST_LO
: ppc_reloc
= R_PPC_EMB_RELST_LO
; break;
1018 case BFD_RELOC_PPC_EMB_RELST_HI
: ppc_reloc
= R_PPC_EMB_RELST_HI
; break;
1019 case BFD_RELOC_PPC_EMB_RELST_HA
: ppc_reloc
= R_PPC_EMB_RELST_HA
; break;
1020 case BFD_RELOC_PPC_EMB_BIT_FLD
: ppc_reloc
= R_PPC_EMB_BIT_FLD
; break;
1021 case BFD_RELOC_PPC_EMB_RELSDA
: ppc_reloc
= R_PPC_EMB_RELSDA
; break;
1022 case BFD_RELOC_VTABLE_INHERIT
: ppc_reloc
= R_PPC_GNU_VTINHERIT
; break;
1023 case BFD_RELOC_VTABLE_ENTRY
: ppc_reloc
= R_PPC_GNU_VTENTRY
; break;
1026 return ppc_elf_howto_table
[ (int)ppc_reloc
];
1029 /* Set the howto pointer for a PowerPC ELF reloc. */
1032 ppc_elf_info_to_howto (abfd
, cache_ptr
, dst
)
1035 Elf32_Internal_Rela
*dst
;
1037 if (!ppc_elf_howto_table
[ R_PPC_ADDR32
]) /* Initialize howto table if needed */
1038 ppc_elf_howto_init ();
1040 BFD_ASSERT (ELF32_R_TYPE (dst
->r_info
) < (unsigned int) R_PPC_max
);
1041 cache_ptr
->howto
= ppc_elf_howto_table
[ELF32_R_TYPE (dst
->r_info
)];
1044 /* Handle the R_PPC_ADDR16_HA reloc. */
1046 static bfd_reloc_status_type
1047 ppc_elf_addr16_ha_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1048 output_bfd
, error_message
)
1050 arelent
*reloc_entry
;
1053 asection
*input_section
;
1055 char **error_message
;
1059 if (output_bfd
!= NULL
)
1061 reloc_entry
->address
+= input_section
->output_offset
;
1062 return bfd_reloc_ok
;
1065 if (reloc_entry
->address
> input_section
->_cooked_size
)
1066 return bfd_reloc_outofrange
;
1068 if (bfd_is_com_section (symbol
->section
))
1071 relocation
= symbol
->value
;
1073 relocation
+= symbol
->section
->output_section
->vma
;
1074 relocation
+= symbol
->section
->output_offset
;
1075 relocation
+= reloc_entry
->addend
;
1077 reloc_entry
->addend
+= (relocation
& 0x8000) << 1;
1079 return bfd_reloc_continue
;
1082 /* Function to set whether a module needs the -mrelocatable bit set. */
1085 ppc_elf_set_private_flags (abfd
, flags
)
1089 BFD_ASSERT (!elf_flags_init (abfd
)
1090 || elf_elfheader (abfd
)->e_flags
== flags
);
1092 elf_elfheader (abfd
)->e_flags
= flags
;
1093 elf_flags_init (abfd
) = true;
1097 /* Copy backend specific data from one object module to another */
1099 ppc_elf_copy_private_bfd_data (ibfd
, obfd
)
1103 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
1104 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
1107 BFD_ASSERT (!elf_flags_init (obfd
)
1108 || elf_elfheader (obfd
)->e_flags
== elf_elfheader (ibfd
)->e_flags
);
1110 elf_elfheader (obfd
)->e_flags
= elf_elfheader (ibfd
)->e_flags
;
1111 elf_flags_init (obfd
) = true;
1115 /* Merge backend specific data from an object file to the output
1116 object file when linking */
1118 ppc_elf_merge_private_bfd_data (ibfd
, obfd
)
1126 /* Check if we have the same endianess */
1127 if (ibfd
->xvec
->byteorder
!= obfd
->xvec
->byteorder
1128 && obfd
->xvec
->byteorder
!= BFD_ENDIAN_UNKNOWN
)
1132 if (bfd_big_endian (ibfd
))
1133 msg
= _("%s: compiled for a big endian system and target is little endian");
1135 msg
= _("%s: compiled for a little endian system and target is big endian");
1137 (*_bfd_error_handler
) (msg
, bfd_get_filename (ibfd
));
1139 bfd_set_error (bfd_error_wrong_format
);
1143 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
1144 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
1147 new_flags
= elf_elfheader (ibfd
)->e_flags
;
1148 old_flags
= elf_elfheader (obfd
)->e_flags
;
1149 if (!elf_flags_init (obfd
)) /* First call, no flags set */
1151 elf_flags_init (obfd
) = true;
1152 elf_elfheader (obfd
)->e_flags
= new_flags
;
1155 else if (new_flags
== old_flags
) /* Compatible flags are ok */
1158 else /* Incompatible flags */
1160 /* Warn about -mrelocatable mismatch. Allow -mrelocatable-lib to be linked
1163 if ((new_flags
& EF_PPC_RELOCATABLE
) != 0
1164 && (old_flags
& (EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
)) == 0)
1167 (*_bfd_error_handler
)
1168 (_("%s: compiled with -mrelocatable and linked with modules compiled normally"),
1169 bfd_get_filename (ibfd
));
1171 else if ((new_flags
& (EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
)) == 0
1172 && (old_flags
& EF_PPC_RELOCATABLE
) != 0)
1175 (*_bfd_error_handler
)
1176 (_("%s: compiled normally and linked with modules compiled with -mrelocatable"),
1177 bfd_get_filename (ibfd
));
1179 /* If -mrelocatable-lib is linked with an object without -mrelocatable-lib, turn off
1180 the -mrelocatable-lib, since at least one module isn't relocatable. */
1181 else if ((old_flags
& EF_PPC_RELOCATABLE_LIB
) != 0
1182 && (new_flags
& EF_PPC_RELOCATABLE_LIB
) == 0)
1183 elf_elfheader (obfd
)->e_flags
&= ~EF_PPC_RELOCATABLE_LIB
;
1186 /* Do not warn about eabi vs. V.4 mismatch, just or in the bit if any module uses it */
1187 elf_elfheader (obfd
)->e_flags
|= (new_flags
& EF_PPC_EMB
);
1189 new_flags
&= ~ (EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
| EF_PPC_EMB
);
1190 old_flags
&= ~ (EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
| EF_PPC_EMB
);
1192 /* Warn about any other mismatches */
1193 if (new_flags
!= old_flags
)
1196 (*_bfd_error_handler
)
1197 (_("%s: uses different e_flags (0x%lx) fields than previous modules (0x%lx)"),
1198 bfd_get_filename (ibfd
), (long)new_flags
, (long)old_flags
);
1203 bfd_set_error (bfd_error_bad_value
);
1212 /* Handle a PowerPC specific section when reading an object file. This
1213 is called when elfcode.h finds a section with an unknown type. */
1216 ppc_elf_section_from_shdr (abfd
, hdr
, name
)
1218 Elf32_Internal_Shdr
*hdr
;
1224 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
))
1227 newsect
= hdr
->bfd_section
;
1228 flags
= bfd_get_section_flags (abfd
, newsect
);
1229 if (hdr
->sh_flags
& SHF_EXCLUDE
)
1230 flags
|= SEC_EXCLUDE
;
1232 if (hdr
->sh_type
== SHT_ORDERED
)
1233 flags
|= SEC_SORT_ENTRIES
;
1235 bfd_set_section_flags (abfd
, newsect
, flags
);
1240 /* Set up any other section flags and such that may be necessary. */
1243 ppc_elf_fake_sections (abfd
, shdr
, asect
)
1245 Elf32_Internal_Shdr
*shdr
;
1248 if ((asect
->flags
& SEC_EXCLUDE
) != 0)
1249 shdr
->sh_flags
|= SHF_EXCLUDE
;
1251 if ((asect
->flags
& SEC_SORT_ENTRIES
) != 0)
1252 shdr
->sh_type
= SHT_ORDERED
;
1258 /* Create a special linker section */
1259 static elf_linker_section_t
*
1260 ppc_elf_create_linker_section (abfd
, info
, which
)
1262 struct bfd_link_info
*info
;
1263 enum elf_linker_section_enum which
;
1265 bfd
*dynobj
= elf_hash_table (info
)->dynobj
;
1266 elf_linker_section_t
*lsect
;
1268 /* Record the first bfd section that needs the special section */
1270 dynobj
= elf_hash_table (info
)->dynobj
= abfd
;
1272 /* If this is the first time, create the section */
1273 lsect
= elf_linker_section (dynobj
, which
);
1276 elf_linker_section_t defaults
;
1277 static elf_linker_section_t zero_section
;
1279 defaults
= zero_section
;
1280 defaults
.which
= which
;
1281 defaults
.hole_written_p
= false;
1282 defaults
.alignment
= 2;
1284 /* Both of these sections are (technically) created by the user
1285 putting data in them, so they shouldn't be marked
1288 The linker creates them so it has somewhere to attach their
1289 respective symbols. In fact, if they were empty it would
1290 be OK to leave the symbol set to 0 (or any random number), because
1291 the appropriate register should never be used. */
1292 defaults
.flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
1298 (*_bfd_error_handler
) (_("%s: Unknown special linker type %d"),
1299 bfd_get_filename (abfd
),
1302 bfd_set_error (bfd_error_bad_value
);
1303 return (elf_linker_section_t
*)0;
1305 case LINKER_SECTION_SDATA
: /* .sdata/.sbss section */
1306 defaults
.name
= ".sdata";
1307 defaults
.rel_name
= ".rela.sdata";
1308 defaults
.bss_name
= ".sbss";
1309 defaults
.sym_name
= "_SDA_BASE_";
1310 defaults
.sym_offset
= 32768;
1313 case LINKER_SECTION_SDATA2
: /* .sdata2/.sbss2 section */
1314 defaults
.name
= ".sdata2";
1315 defaults
.rel_name
= ".rela.sdata2";
1316 defaults
.bss_name
= ".sbss2";
1317 defaults
.sym_name
= "_SDA2_BASE_";
1318 defaults
.sym_offset
= 32768;
1319 defaults
.flags
|= SEC_READONLY
;
1323 lsect
= _bfd_elf_create_linker_section (abfd
, info
, which
, &defaults
);
1330 /* If we have a non-zero sized .sbss2 or .PPC.EMB.sbss0 sections, we need to bump up
1331 the number of section headers. */
1334 ppc_elf_additional_program_headers (abfd
)
1342 s
= bfd_get_section_by_name (abfd
, ".interp");
1346 s
= bfd_get_section_by_name (abfd
, ".sbss2");
1347 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0 && s
->_raw_size
> 0)
1350 s
= bfd_get_section_by_name (abfd
, ".PPC.EMB.sbss0");
1351 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0 && s
->_raw_size
> 0)
1357 /* Modify the segment map if needed */
1360 ppc_elf_modify_segment_map (abfd
)
1366 /* We have to create .dynsbss and .rela.sbss here so that they get mapped
1367 to output sections (just like _bfd_elf_create_dynamic_sections has
1368 to create .dynbss and .rela.bss). */
1371 ppc_elf_create_dynamic_sections (abfd
, info
)
1373 struct bfd_link_info
*info
;
1375 register asection
*s
;
1378 if (!_bfd_elf_create_dynamic_sections(abfd
, info
))
1381 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
1382 | SEC_LINKER_CREATED
);
1384 s
= bfd_make_section (abfd
, ".dynsbss");
1386 || ! bfd_set_section_flags (abfd
, s
, SEC_ALLOC
))
1391 s
= bfd_make_section (abfd
, ".rela.sbss");
1393 || ! bfd_set_section_flags (abfd
, s
, flags
| SEC_READONLY
)
1394 || ! bfd_set_section_alignment (abfd
, s
, 2))
1400 /* Adjust a symbol defined by a dynamic object and referenced by a
1401 regular object. The current definition is in some section of the
1402 dynamic object, but we're not including those sections. We have to
1403 change the definition to something the rest of the link can
1407 ppc_elf_adjust_dynamic_symbol (info
, h
)
1408 struct bfd_link_info
*info
;
1409 struct elf_link_hash_entry
*h
;
1411 bfd
*dynobj
= elf_hash_table (info
)->dynobj
;
1413 unsigned int power_of_two
;
1417 fprintf (stderr
, "ppc_elf_adjust_dynamic_symbol called for %s\n", h
->root
.root
.string
);
1420 /* Make sure we know what is going on here. */
1421 BFD_ASSERT (dynobj
!= NULL
1422 && ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
)
1423 || h
->weakdef
!= NULL
1424 || ((h
->elf_link_hash_flags
1425 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0
1426 && (h
->elf_link_hash_flags
1427 & ELF_LINK_HASH_REF_REGULAR
) != 0
1428 && (h
->elf_link_hash_flags
1429 & ELF_LINK_HASH_DEF_REGULAR
) == 0)));
1432 /* If this is a function, put it in the procedure linkage table. We
1433 will fill in the contents of the procedure linkage table later,
1434 when we know the address of the .got section. */
1435 if (h
->type
== STT_FUNC
1436 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
1439 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) == 0
1440 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_REF_DYNAMIC
) == 0)
1442 /* This case can occur if we saw a PLT32 reloc in an input
1443 file, but the symbol was never referred to by a dynamic
1444 object. In such a case, we don't actually need to build
1445 a procedure linkage table, and we can just do a PC32
1447 BFD_ASSERT ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0);
1451 /* GC may have rendered this entry unused. Note, however, that in
1452 an executable all references to the symbol go to the PLT, so we
1453 can't turn it off in that case.
1454 ??? The correct thing to do here is to reference count all uses
1455 of the symbol, not just those to the GOT or PLT. */
1457 if (h
->plt
.refcount
<= 0 && info
->shared
)
1459 h
->plt
.offset
= (bfd_vma
) -1;
1460 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
1464 /* Make sure this symbol is output as a dynamic symbol. */
1465 if (h
->dynindx
== -1)
1467 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
1470 BFD_ASSERT (h
->dynindx
!= -1);
1472 s
= bfd_get_section_by_name (dynobj
, ".plt");
1473 BFD_ASSERT (s
!= NULL
);
1475 /* If this is the first .plt entry, make room for the special
1477 if (s
->_raw_size
== 0)
1478 s
->_raw_size
+= PLT_INITIAL_ENTRY_SIZE
;
1480 /* The PowerPC PLT is actually composed of two parts, the first part
1481 is 2 words (for a load and a jump), and then there is a remaining
1482 word available at the end. */
1483 plt_offset
= (PLT_INITIAL_ENTRY_SIZE
1484 + 8 * ((s
->_raw_size
- PLT_INITIAL_ENTRY_SIZE
) / PLT_ENTRY_SIZE
));
1486 /* If this symbol is not defined in a regular file, and we are
1487 not generating a shared library, then set the symbol to this
1488 location in the .plt. This is required to make function
1489 pointers compare as equal between the normal executable and
1490 the shared library. */
1492 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
1494 h
->root
.u
.def
.section
= s
;
1495 h
->root
.u
.def
.value
= plt_offset
;
1498 h
->plt
.offset
= plt_offset
;
1500 /* Make room for this entry. */
1501 s
->_raw_size
+= PLT_ENTRY_SIZE
;
1503 /* We also need to make an entry in the .rela.plt section. */
1504 s
= bfd_get_section_by_name (dynobj
, ".rela.plt");
1505 BFD_ASSERT (s
!= NULL
);
1506 s
->_raw_size
+= sizeof (Elf32_External_Rela
);
1511 /* If this is a weak symbol, and there is a real definition, the
1512 processor independent code will have arranged for us to see the
1513 real definition first, and we can just use the same value. */
1514 if (h
->weakdef
!= NULL
)
1516 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
1517 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
1518 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
1519 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
1523 /* This is a reference to a symbol defined by a dynamic object which
1524 is not a function. */
1526 /* If we are creating a shared library, we must presume that the
1527 only references to the symbol are via the global offset table.
1528 For such cases we need not do anything here; the relocations will
1529 be handled correctly by relocate_section. */
1533 /* We must allocate the symbol in our .dynbss section, which will
1534 become part of the .bss section of the executable. There will be
1535 an entry for this symbol in the .dynsym section. The dynamic
1536 object will contain position independent code, so all references
1537 from the dynamic object to this symbol will go through the global
1538 offset table. The dynamic linker will use the .dynsym entry to
1539 determine the address it must put in the global offset table, so
1540 both the dynamic object and the regular object will refer to the
1541 same memory location for the variable.
1543 Of course, if the symbol is sufficiently small, we must instead
1544 allocate it in .sbss. FIXME: It would be better to do this if and
1545 only if there were actually SDAREL relocs for that symbol. */
1547 if (h
->size
<= elf_gp_size (dynobj
))
1548 s
= bfd_get_section_by_name (dynobj
, ".dynsbss");
1550 s
= bfd_get_section_by_name (dynobj
, ".dynbss");
1551 BFD_ASSERT (s
!= NULL
);
1553 /* We must generate a R_PPC_COPY reloc to tell the dynamic linker to
1554 copy the initial value out of the dynamic object and into the
1555 runtime process image. We need to remember the offset into the
1556 .rela.bss section we are going to use. */
1557 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
1561 if (h
->size
<= elf_gp_size (dynobj
))
1562 srel
= bfd_get_section_by_name (dynobj
, ".rela.sbss");
1564 srel
= bfd_get_section_by_name (dynobj
, ".rela.bss");
1565 BFD_ASSERT (srel
!= NULL
);
1566 srel
->_raw_size
+= sizeof (Elf32_External_Rela
);
1567 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_COPY
;
1570 /* We need to figure out the alignment required for this symbol. I
1571 have no idea how ELF linkers handle this. */
1572 power_of_two
= bfd_log2 (h
->size
);
1573 if (power_of_two
> 4)
1576 /* Apply the required alignment. */
1577 s
->_raw_size
= BFD_ALIGN (s
->_raw_size
,
1578 (bfd_size_type
) (1 << power_of_two
));
1579 if (power_of_two
> bfd_get_section_alignment (dynobj
, s
))
1581 if (! bfd_set_section_alignment (dynobj
, s
, power_of_two
))
1585 /* Define the symbol as being at this point in the section. */
1586 h
->root
.u
.def
.section
= s
;
1587 h
->root
.u
.def
.value
= s
->_raw_size
;
1589 /* Increment the section size to make room for the symbol. */
1590 s
->_raw_size
+= h
->size
;
1596 /* Increment the index of a dynamic symbol by a given amount. Called
1597 via elf_link_hash_traverse. */
1600 ppc_elf_adjust_dynindx (h
, cparg
)
1601 struct elf_link_hash_entry
*h
;
1604 int *cp
= (int *) cparg
;
1607 fprintf (stderr
, "ppc_elf_adjust_dynindx called, h->dynindx = %d, *cp = %d\n", h
->dynindx
, *cp
);
1610 if (h
->dynindx
!= -1)
1617 /* Set the sizes of the dynamic sections. */
1620 ppc_elf_size_dynamic_sections (output_bfd
, info
)
1622 struct bfd_link_info
*info
;
1631 fprintf (stderr
, "ppc_elf_size_dynamic_sections called\n");
1634 dynobj
= elf_hash_table (info
)->dynobj
;
1635 BFD_ASSERT (dynobj
!= NULL
);
1637 if (elf_hash_table (info
)->dynamic_sections_created
)
1639 /* Set the contents of the .interp section to the interpreter. */
1642 s
= bfd_get_section_by_name (dynobj
, ".interp");
1643 BFD_ASSERT (s
!= NULL
);
1644 s
->_raw_size
= sizeof ELF_DYNAMIC_INTERPRETER
;
1645 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
1650 /* We may have created entries in the .rela.got, .rela.sdata, and
1651 .rela.sdata2 sections. However, if we are not creating the
1652 dynamic sections, we will not actually use these entries. Reset
1653 the size of .rela.got, et al, which will cause it to get
1654 stripped from the output file below. */
1655 static char *rela_sections
[] = { ".rela.got", ".rela.sdata",
1656 ".rela.sdata2", ".rela.sbss",
1660 for (p
= rela_sections
; *p
!= (char *)0; p
++)
1662 s
= bfd_get_section_by_name (dynobj
, *p
);
1668 /* The check_relocs and adjust_dynamic_symbol entry points have
1669 determined the sizes of the various dynamic sections. Allocate
1674 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
1679 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
1682 /* It's OK to base decisions on the section name, because none
1683 of the dynobj section names depend upon the input files. */
1684 name
= bfd_get_section_name (dynobj
, s
);
1688 if (strcmp (name
, ".plt") == 0)
1690 if (s
->_raw_size
== 0)
1692 /* Strip this section if we don't need it; see the
1698 /* Remember whether there is a PLT. */
1702 else if (strncmp (name
, ".rela", 5) == 0)
1704 if (s
->_raw_size
== 0)
1706 /* If we don't need this section, strip it from the
1707 output file. This is mostly to handle .rela.bss and
1708 .rela.plt. We must create both sections in
1709 create_dynamic_sections, because they must be created
1710 before the linker maps input sections to output
1711 sections. The linker does that before
1712 adjust_dynamic_symbol is called, and it is that
1713 function which decides whether anything needs to go
1714 into these sections. */
1720 const char *outname
;
1722 /* Remember whether there are any relocation sections. */
1725 /* If this relocation section applies to a read only
1726 section, then we probably need a DT_TEXTREL entry. */
1727 outname
= bfd_get_section_name (output_bfd
,
1729 target
= bfd_get_section_by_name (output_bfd
, outname
+ 5);
1731 && (target
->flags
& SEC_READONLY
) != 0
1732 && (target
->flags
& SEC_ALLOC
) != 0)
1735 /* We use the reloc_count field as a counter if we need
1736 to copy relocs into the output file. */
1740 else if (strcmp (name
, ".got") != 0
1741 && strcmp (name
, ".sdata") != 0
1742 && strcmp (name
, ".sdata2") != 0)
1744 /* It's not one of our sections, so don't allocate space. */
1752 for (spp
= &s
->output_section
->owner
->sections
;
1753 *spp
!= s
->output_section
;
1754 spp
= &(*spp
)->next
)
1756 *spp
= s
->output_section
->next
;
1757 --s
->output_section
->owner
->section_count
;
1762 /* Allocate memory for the section contents. */
1763 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->_raw_size
);
1764 if (s
->contents
== NULL
&& s
->_raw_size
!= 0)
1768 if (elf_hash_table (info
)->dynamic_sections_created
)
1770 /* Add some entries to the .dynamic section. We fill in the
1771 values later, in ppc_elf_finish_dynamic_sections, but we
1772 must add the entries now so that we get the correct size for
1773 the .dynamic section. The DT_DEBUG entry is filled in by the
1774 dynamic linker and used by the debugger. */
1777 if (! bfd_elf32_add_dynamic_entry (info
, DT_DEBUG
, 0))
1783 if (! bfd_elf32_add_dynamic_entry (info
, DT_PLTGOT
, 0)
1784 || ! bfd_elf32_add_dynamic_entry (info
, DT_PLTRELSZ
, 0)
1785 || ! bfd_elf32_add_dynamic_entry (info
, DT_PLTREL
, DT_RELA
)
1786 || ! bfd_elf32_add_dynamic_entry (info
, DT_JMPREL
, 0))
1792 if (! bfd_elf32_add_dynamic_entry (info
, DT_RELA
, 0)
1793 || ! bfd_elf32_add_dynamic_entry (info
, DT_RELASZ
, 0)
1794 || ! bfd_elf32_add_dynamic_entry (info
, DT_RELAENT
,
1795 sizeof (Elf32_External_Rela
)))
1801 if (! bfd_elf32_add_dynamic_entry (info
, DT_TEXTREL
, 0))
1806 /* If we are generating a shared library, we generate a section
1807 symbol for each output section. These are local symbols, which
1808 means that they must come first in the dynamic symbol table.
1809 That means we must increment the dynamic symbol index of every
1810 other dynamic symbol.
1812 FIXME: We assume that there will never be relocations to
1813 locations in linker-created sections that do not have
1814 externally-visible names. Instead, we should work out precisely
1815 which sections relocations are targetted at. */
1820 for (c
= 0, s
= output_bfd
->sections
; s
!= NULL
; s
= s
->next
)
1822 if ((s
->flags
& SEC_LINKER_CREATED
) != 0
1823 || (s
->flags
& SEC_ALLOC
) == 0)
1825 elf_section_data (s
)->dynindx
= -1;
1829 /* These symbols will have no names, so we don't need to
1830 fiddle with dynstr_index. */
1832 elf_section_data (s
)->dynindx
= c
+ 1;
1837 elf_link_hash_traverse (elf_hash_table (info
),
1838 ppc_elf_adjust_dynindx
,
1840 elf_hash_table (info
)->dynsymcount
+= c
;
1847 /* Look through the relocs for a section during the first phase, and
1848 allocate space in the global offset table or procedure linkage
1852 ppc_elf_check_relocs (abfd
, info
, sec
, relocs
)
1854 struct bfd_link_info
*info
;
1856 const Elf_Internal_Rela
*relocs
;
1859 Elf_Internal_Shdr
*symtab_hdr
;
1860 struct elf_link_hash_entry
**sym_hashes
, **sym_hashes_end
;
1861 const Elf_Internal_Rela
*rel
;
1862 const Elf_Internal_Rela
*rel_end
;
1863 bfd_signed_vma
*local_got_refcounts
;
1864 elf_linker_section_t
*sdata
;
1865 elf_linker_section_t
*sdata2
;
1868 asection
*srelgot
= NULL
;
1870 if (info
->relocateable
)
1874 fprintf (stderr
, "ppc_elf_check_relocs called for section %s in %s\n",
1875 bfd_get_section_name (abfd
, sec
),
1876 bfd_get_filename (abfd
));
1879 /* Create the linker generated sections all the time so that the
1880 special symbols are created. */
1882 if ((sdata
= elf_linker_section (abfd
, LINKER_SECTION_SDATA
)) == NULL
)
1884 sdata
= ppc_elf_create_linker_section (abfd
, info
, LINKER_SECTION_SDATA
);
1890 if ((sdata2
= elf_linker_section (abfd
, LINKER_SECTION_SDATA2
)) == NULL
)
1892 sdata2
= ppc_elf_create_linker_section (abfd
, info
, LINKER_SECTION_SDATA2
);
1897 dynobj
= elf_hash_table (info
)->dynobj
;
1898 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
1899 local_got_refcounts
= elf_local_got_refcounts (abfd
);
1901 sym_hashes
= elf_sym_hashes (abfd
);
1902 sym_hashes_end
= sym_hashes
+ symtab_hdr
->sh_size
/sizeof(Elf32_External_Sym
);
1903 if (!elf_bad_symtab (abfd
))
1904 sym_hashes_end
-= symtab_hdr
->sh_info
;
1908 rel_end
= relocs
+ sec
->reloc_count
;
1909 for (rel
= relocs
; rel
< rel_end
; rel
++)
1911 unsigned long r_symndx
;
1912 struct elf_link_hash_entry
*h
;
1914 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1915 if (r_symndx
< symtab_hdr
->sh_info
)
1918 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1920 switch (ELF32_R_TYPE (rel
->r_info
))
1922 /* GOT16 relocations */
1924 case R_PPC_GOT16_LO
:
1925 case R_PPC_GOT16_HI
:
1926 case R_PPC_GOT16_HA
:
1927 /* This symbol requires a global offset table entry. */
1933 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
1934 if (! _bfd_elf_create_got_section (dynobj
, info
))
1937 sgot
= bfd_get_section_by_name (dynobj
, ".got");
1938 BFD_ASSERT (sgot
!= NULL
);
1942 && (h
!= NULL
|| info
->shared
))
1944 srelgot
= bfd_get_section_by_name (dynobj
, ".rela.got");
1945 if (srelgot
== NULL
)
1947 srelgot
= bfd_make_section (dynobj
, ".rela.got");
1949 || ! bfd_set_section_flags (dynobj
, srelgot
,
1954 | SEC_LINKER_CREATED
1956 || ! bfd_set_section_alignment (dynobj
, srelgot
, 2))
1963 if (h
->got
.refcount
== -1)
1965 /* Make sure this symbol is output as a dynamic symbol. */
1966 if (h
->dynindx
== -1)
1967 if (!bfd_elf32_link_record_dynamic_symbol (info
, h
))
1970 /* Allocate space in the .got. */
1971 sgot
->_raw_size
+= 4;
1972 /* Allocate relocation space. */
1973 srelgot
->_raw_size
+= sizeof (Elf32_External_Rela
);
1975 h
->got
.refcount
= 1;
1982 /* This is a global offset table entry for a local symbol. */
1983 if (local_got_refcounts
== NULL
)
1986 register unsigned int i
;
1988 size
= symtab_hdr
->sh_info
* sizeof (bfd_signed_vma
);
1989 local_got_refcounts
= (bfd_signed_vma
*)
1990 bfd_alloc (abfd
, size
);
1991 if (local_got_refcounts
== NULL
)
1993 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
1994 memset (local_got_refcounts
, -1, size
);
1996 if (local_got_refcounts
[r_symndx
] == -1)
1998 sgot
->_raw_size
+= 4;
2000 /* If we are generating a shared object, we need to
2001 output a R_PPC_RELATIVE reloc so that the
2002 dynamic linker can adjust this GOT entry. */
2004 srelgot
->_raw_size
+= sizeof (Elf32_External_Rela
);
2006 local_got_refcounts
[r_symndx
] = 1;
2009 local_got_refcounts
[r_symndx
]++;
2013 /* Indirect .sdata relocation */
2014 case R_PPC_EMB_SDAI16
:
2017 ((*_bfd_error_handler
)
2018 (_("%s: relocation %s cannot be used when making a shared object"),
2019 bfd_get_filename (abfd
), "R_PPC_EMB_SDAI16"));
2023 if (srelgot
== NULL
&& (h
!= NULL
|| info
->shared
))
2025 srelgot
= bfd_get_section_by_name (dynobj
, ".rela.got");
2026 if (srelgot
== NULL
)
2028 srelgot
= bfd_make_section (dynobj
, ".rela.got");
2030 || ! bfd_set_section_flags (dynobj
, srelgot
,
2035 | SEC_LINKER_CREATED
2037 || ! bfd_set_section_alignment (dynobj
, srelgot
, 2))
2042 if (!bfd_elf32_create_pointer_linker_section (abfd
, info
, sdata
, h
, rel
))
2047 /* Indirect .sdata2 relocation */
2048 case R_PPC_EMB_SDA2I16
:
2051 ((*_bfd_error_handler
)
2052 (_("%s: relocation %s cannot be used when making a shared object"),
2053 bfd_get_filename (abfd
), "R_PPC_EMB_SDA2I16"));
2057 if (srelgot
== NULL
&& (h
!= NULL
|| info
->shared
))
2059 srelgot
= bfd_get_section_by_name (dynobj
, ".rela.got");
2060 if (srelgot
== NULL
)
2062 srelgot
= bfd_make_section (dynobj
, ".rela.got");
2064 || ! bfd_set_section_flags (dynobj
, srelgot
,
2069 | SEC_LINKER_CREATED
2071 || ! bfd_set_section_alignment (dynobj
, srelgot
, 2))
2076 if (!bfd_elf32_create_pointer_linker_section (abfd
, info
, sdata2
, h
, rel
))
2081 case R_PPC_SDAREL16
:
2082 case R_PPC_EMB_SDA2REL
:
2083 case R_PPC_EMB_SDA21
:
2086 ((*_bfd_error_handler
)
2087 (_("%s: relocation %s cannot be used when making a shared object"),
2088 bfd_get_filename (abfd
),
2089 ppc_elf_howto_table
[(int)ELF32_R_TYPE (rel
->r_info
)]->name
));
2095 case R_PPC_PLTREL24
:
2096 case R_PPC_PLT16_LO
:
2097 case R_PPC_PLT16_HI
:
2098 case R_PPC_PLT16_HA
:
2100 fprintf (stderr
, "Reloc requires a PLT entry\n");
2102 /* This symbol requires a procedure linkage table entry. We
2103 actually build the entry in adjust_dynamic_symbol,
2104 because this might be a case of linking PIC code without
2105 linking in any dynamic objects, in which case we don't
2106 need to generate a procedure linkage table after all. */
2110 /* It does not make sense to have a procedure linkage
2111 table entry for a local symbol. */
2112 bfd_set_error (bfd_error_bad_value
);
2116 /* Make sure this symbol is output as a dynamic symbol. */
2117 if (h
->dynindx
== -1)
2119 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
2122 if (h
->plt
.refcount
== -1)
2124 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
2125 h
->plt
.refcount
= 1;
2131 /* The following relocations don't need to propagate the
2132 relocation if linking a shared object since they are
2133 section relative. */
2135 case R_PPC_SECTOFF_LO
:
2136 case R_PPC_SECTOFF_HI
:
2137 case R_PPC_SECTOFF_HA
:
2140 /* This refers only to functions defined in the shared library */
2141 case R_PPC_LOCAL24PC
:
2144 /* This relocation describes the C++ object vtable hierarchy.
2145 Reconstruct it for later use during GC. */
2146 case R_PPC_GNU_VTINHERIT
:
2147 if (!_bfd_elf32_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
2151 /* This relocation describes which C++ vtable entries are actually
2152 used. Record for later use during GC. */
2153 case R_PPC_GNU_VTENTRY
:
2154 if (!_bfd_elf32_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
2158 /* When creating a shared object, we must copy these
2159 relocs into the output file. We create a reloc
2160 section in dynobj and make room for the reloc. */
2163 case R_PPC_REL14_BRTAKEN
:
2164 case R_PPC_REL14_BRNTAKEN
:
2167 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
2175 fprintf (stderr
, "ppc_elf_check_relocs need to create relocation for %s\n",
2176 (h
&& h
->root
.root
.string
) ? h
->root
.root
.string
: "<unknown>");
2182 name
= (bfd_elf_string_from_elf_section
2184 elf_elfheader (abfd
)->e_shstrndx
,
2185 elf_section_data (sec
)->rel_hdr
.sh_name
));
2189 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
2190 && strcmp (bfd_get_section_name (abfd
, sec
),
2193 sreloc
= bfd_get_section_by_name (dynobj
, name
);
2198 sreloc
= bfd_make_section (dynobj
, name
);
2199 flags
= (SEC_HAS_CONTENTS
| SEC_READONLY
2200 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
2201 if ((sec
->flags
& SEC_ALLOC
) != 0)
2202 flags
|= SEC_ALLOC
| SEC_LOAD
;
2204 || ! bfd_set_section_flags (dynobj
, sreloc
, flags
)
2205 || ! bfd_set_section_alignment (dynobj
, sreloc
, 2))
2210 sreloc
->_raw_size
+= sizeof (Elf32_External_Rela
);
2212 /* FIXME: We should here do what the m68k and i386
2213 backends do: if the reloc is pc-relative, record it
2214 in case it turns out that the reloc is unnecessary
2215 because the symbol is forced local by versioning or
2216 we are linking with -Bdynamic. Fortunately this
2217 case is not frequent. */
2227 /* Return the section that should be marked against GC for a given
2231 ppc_elf_gc_mark_hook (abfd
, info
, rel
, h
, sym
)
2233 struct bfd_link_info
*info
;
2234 Elf_Internal_Rela
*rel
;
2235 struct elf_link_hash_entry
*h
;
2236 Elf_Internal_Sym
*sym
;
2240 switch (ELF32_R_TYPE (rel
->r_info
))
2242 case R_PPC_GNU_VTINHERIT
:
2243 case R_PPC_GNU_VTENTRY
:
2247 switch (h
->root
.type
)
2249 case bfd_link_hash_defined
:
2250 case bfd_link_hash_defweak
:
2251 return h
->root
.u
.def
.section
;
2253 case bfd_link_hash_common
:
2254 return h
->root
.u
.c
.p
->section
;
2260 if (!(elf_bad_symtab (abfd
)
2261 && ELF_ST_BIND (sym
->st_info
) != STB_LOCAL
)
2262 && ! ((sym
->st_shndx
<= 0 || sym
->st_shndx
>= SHN_LORESERVE
)
2263 && sym
->st_shndx
!= SHN_COMMON
))
2265 return bfd_section_from_elf_index (abfd
, sym
->st_shndx
);
2272 /* Update the got entry reference counts for the section being removed. */
2275 ppc_elf_gc_sweep_hook (abfd
, info
, sec
, relocs
)
2277 struct bfd_link_info
*info
;
2279 const Elf_Internal_Rela
*relocs
;
2281 Elf_Internal_Shdr
*symtab_hdr
;
2282 struct elf_link_hash_entry
**sym_hashes
;
2283 bfd_signed_vma
*local_got_refcounts
;
2284 const Elf_Internal_Rela
*rel
, *relend
;
2285 unsigned long r_symndx
;
2286 struct elf_link_hash_entry
*h
;
2288 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
2289 sym_hashes
= elf_sym_hashes (abfd
);
2290 local_got_refcounts
= elf_local_got_refcounts (abfd
);
2292 relend
= relocs
+ sec
->reloc_count
;
2293 for (rel
= relocs
; rel
< relend
; rel
++)
2294 switch (ELF32_R_TYPE (rel
->r_info
))
2297 case R_PPC_GOT16_LO
:
2298 case R_PPC_GOT16_HI
:
2299 case R_PPC_GOT16_HA
:
2300 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2301 if (r_symndx
>= symtab_hdr
->sh_info
)
2303 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2304 if (h
->got
.refcount
> 0)
2309 if (local_got_refcounts
[r_symndx
] > 0)
2310 local_got_refcounts
[r_symndx
]--;
2315 case R_PPC_PLTREL24
:
2316 case R_PPC_PLT16_LO
:
2317 case R_PPC_PLT16_HI
:
2318 case R_PPC_PLT16_HA
:
2319 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2320 if (r_symndx
>= symtab_hdr
->sh_info
)
2322 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2323 if (h
->plt
.refcount
> 0)
2335 /* Hook called by the linker routine which adds symbols from an object
2336 file. We use it to put .comm items in .sbss, and not .bss. */
2340 ppc_elf_add_symbol_hook (abfd
, info
, sym
, namep
, flagsp
, secp
, valp
)
2342 struct bfd_link_info
*info
;
2343 const Elf_Internal_Sym
*sym
;
2349 if (sym
->st_shndx
== SHN_COMMON
2350 && !info
->relocateable
2351 && sym
->st_size
<= (bfd_vma
) bfd_get_gp_size (abfd
))
2353 /* Common symbols less than or equal to -G nn bytes are automatically
2355 elf_linker_section_t
*sdata
2356 = ppc_elf_create_linker_section (abfd
, info
, LINKER_SECTION_SDATA
);
2358 if (!sdata
->bss_section
)
2360 /* We don't go through bfd_make_section, because we don't
2361 want to attach this common section to DYNOBJ. The linker
2362 will move the symbols to the appropriate output section
2363 when it defines common symbols. */
2364 sdata
->bss_section
= ((asection
*)
2365 bfd_zalloc (abfd
, sizeof (asection
)));
2366 if (sdata
->bss_section
== NULL
)
2368 sdata
->bss_section
->name
= sdata
->bss_name
;
2369 sdata
->bss_section
->flags
= SEC_IS_COMMON
;
2370 sdata
->bss_section
->output_section
= sdata
->bss_section
;
2371 sdata
->bss_section
->symbol
=
2372 (asymbol
*) bfd_zalloc (abfd
, sizeof (asymbol
));
2373 sdata
->bss_section
->symbol_ptr_ptr
=
2374 (asymbol
**) bfd_zalloc (abfd
, sizeof (asymbol
*));
2375 if (sdata
->bss_section
->symbol
== NULL
2376 || sdata
->bss_section
->symbol_ptr_ptr
== NULL
)
2378 sdata
->bss_section
->symbol
->name
= sdata
->bss_name
;
2379 sdata
->bss_section
->symbol
->flags
= BSF_SECTION_SYM
;
2380 sdata
->bss_section
->symbol
->section
= sdata
->bss_section
;
2381 *sdata
->bss_section
->symbol_ptr_ptr
= sdata
->bss_section
->symbol
;
2384 *secp
= sdata
->bss_section
;
2385 *valp
= sym
->st_size
;
2392 /* Finish up dynamic symbol handling. We set the contents of various
2393 dynamic sections here. */
2396 ppc_elf_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
2398 struct bfd_link_info
*info
;
2399 struct elf_link_hash_entry
*h
;
2400 Elf_Internal_Sym
*sym
;
2405 fprintf (stderr
, "ppc_elf_finish_dynamic_symbol called for %s",
2406 h
->root
.root
.string
);
2409 dynobj
= elf_hash_table (info
)->dynobj
;
2410 BFD_ASSERT (dynobj
!= NULL
);
2412 if (h
->plt
.offset
!= (bfd_vma
) -1)
2416 Elf_Internal_Rela rela
;
2419 fprintf (stderr
, ", plt_offset = %d", h
->plt
.offset
);
2422 /* This symbol has an entry in the procedure linkage table. Set
2425 BFD_ASSERT (h
->dynindx
!= -1);
2427 splt
= bfd_get_section_by_name (dynobj
, ".plt");
2428 srela
= bfd_get_section_by_name (dynobj
, ".rela.plt");
2429 BFD_ASSERT (splt
!= NULL
&& srela
!= NULL
);
2431 /* We don't need to fill in the .plt. The ppc dynamic linker
2434 /* Fill in the entry in the .rela.plt section. */
2435 rela
.r_offset
= (splt
->output_section
->vma
2436 + splt
->output_offset
2438 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_PPC_JMP_SLOT
);
2440 bfd_elf32_swap_reloca_out (output_bfd
, &rela
,
2441 ((Elf32_External_Rela
*) srela
->contents
2442 + ((h
->plt
.offset
- PLT_INITIAL_ENTRY_SIZE
) / 8)));
2444 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
2446 /* Mark the symbol as undefined, rather than as defined in
2447 the .plt section. Leave the value alone. */
2448 sym
->st_shndx
= SHN_UNDEF
;
2452 if (h
->got
.offset
!= (bfd_vma
) -1)
2456 Elf_Internal_Rela rela
;
2458 /* This symbol has an entry in the global offset table. Set it
2461 sgot
= bfd_get_section_by_name (dynobj
, ".got");
2462 srela
= bfd_get_section_by_name (dynobj
, ".rela.got");
2463 BFD_ASSERT (sgot
!= NULL
&& srela
!= NULL
);
2465 rela
.r_offset
= (sgot
->output_section
->vma
2466 + sgot
->output_offset
2467 + (h
->got
.offset
&~ 1));
2469 /* If this is a -Bsymbolic link, and the symbol is defined
2470 locally, we just want to emit a RELATIVE reloc. The entry in
2471 the global offset table will already have been initialized in
2472 the relocate_section function. */
2474 && (info
->symbolic
|| h
->dynindx
== -1)
2475 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
))
2477 rela
.r_info
= ELF32_R_INFO (0, R_PPC_RELATIVE
);
2478 rela
.r_addend
= (h
->root
.u
.def
.value
2479 + h
->root
.u
.def
.section
->output_section
->vma
2480 + h
->root
.u
.def
.section
->output_offset
);
2484 BFD_ASSERT((h
->got
.offset
& 1) == 0);
2485 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ h
->got
.offset
);
2486 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_PPC_GLOB_DAT
);
2490 bfd_elf32_swap_reloca_out (output_bfd
, &rela
,
2491 ((Elf32_External_Rela
*) srela
->contents
2492 + srela
->reloc_count
));
2493 ++srela
->reloc_count
;
2496 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_COPY
) != 0)
2499 Elf_Internal_Rela rela
;
2501 /* This symbols needs a copy reloc. Set it up. */
2504 fprintf (stderr
, ", copy");
2507 BFD_ASSERT (h
->dynindx
!= -1);
2509 if (h
->size
<= elf_gp_size (dynobj
))
2510 s
= bfd_get_section_by_name (h
->root
.u
.def
.section
->owner
,
2513 s
= bfd_get_section_by_name (h
->root
.u
.def
.section
->owner
,
2515 BFD_ASSERT (s
!= NULL
);
2517 rela
.r_offset
= (h
->root
.u
.def
.value
2518 + h
->root
.u
.def
.section
->output_section
->vma
2519 + h
->root
.u
.def
.section
->output_offset
);
2520 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_PPC_COPY
);
2522 bfd_elf32_swap_reloca_out (output_bfd
, &rela
,
2523 ((Elf32_External_Rela
*) s
->contents
2529 fprintf (stderr
, "\n");
2532 /* Mark some specially defined symbols as absolute. */
2533 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
2534 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0
2535 || strcmp (h
->root
.root
.string
, "_PROCEDURE_LINKAGE_TABLE_") == 0)
2536 sym
->st_shndx
= SHN_ABS
;
2542 /* Finish up the dynamic sections. */
2545 ppc_elf_finish_dynamic_sections (output_bfd
, info
)
2547 struct bfd_link_info
*info
;
2550 bfd
*dynobj
= elf_hash_table (info
)->dynobj
;
2551 asection
*sgot
= bfd_get_section_by_name (dynobj
, ".got");
2554 fprintf (stderr
, "ppc_elf_finish_dynamic_sections called\n");
2557 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
2559 if (elf_hash_table (info
)->dynamic_sections_created
)
2562 Elf32_External_Dyn
*dyncon
, *dynconend
;
2564 splt
= bfd_get_section_by_name (dynobj
, ".plt");
2565 BFD_ASSERT (splt
!= NULL
&& sdyn
!= NULL
);
2567 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
2568 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
2569 for (; dyncon
< dynconend
; dyncon
++)
2571 Elf_Internal_Dyn dyn
;
2575 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
2579 case DT_PLTGOT
: name
= ".plt"; size
= false; break;
2580 case DT_PLTRELSZ
: name
= ".rela.plt"; size
= true; break;
2581 case DT_JMPREL
: name
= ".rela.plt"; size
= false; break;
2582 default: name
= NULL
; size
= false; break;
2589 s
= bfd_get_section_by_name (output_bfd
, name
);
2595 dyn
.d_un
.d_ptr
= s
->vma
;
2598 if (s
->_cooked_size
!= 0)
2599 dyn
.d_un
.d_val
= s
->_cooked_size
;
2601 dyn
.d_un
.d_val
= s
->_raw_size
;
2604 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
2609 /* Add a blrl instruction at _GLOBAL_OFFSET_TABLE_-4 so that a function can
2610 easily find the address of the _GLOBAL_OFFSET_TABLE_. */
2613 unsigned char *contents
= sgot
->contents
;
2614 bfd_put_32 (output_bfd
, 0x4e800021 /* blrl */, contents
);
2617 bfd_put_32 (output_bfd
, (bfd_vma
) 0, contents
+4);
2619 bfd_put_32 (output_bfd
,
2620 sdyn
->output_section
->vma
+ sdyn
->output_offset
,
2623 elf_section_data (sgot
->output_section
)->this_hdr
.sh_entsize
= 4;
2630 Elf_Internal_Sym sym
;
2633 /* Set up the section symbols for the output sections. */
2635 sdynsym
= bfd_get_section_by_name (dynobj
, ".dynsym");
2636 BFD_ASSERT (sdynsym
!= NULL
);
2640 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_SECTION
);
2643 for (s
= output_bfd
->sections
; s
!= NULL
; s
= s
->next
)
2647 sym
.st_value
= s
->vma
;
2649 indx
= elf_section_data (s
)->this_idx
;
2650 dindx
= elf_section_data (s
)->dynindx
;
2653 BFD_ASSERT(indx
> 0);
2654 BFD_ASSERT(dindx
> 0);
2656 if (dindx
> maxdindx
)
2659 sym
.st_shndx
= indx
;
2661 bfd_elf32_swap_symbol_out (output_bfd
, &sym
,
2662 (PTR
) (((Elf32_External_Sym
*)
2668 /* Set the sh_info field of the output .dynsym section to the
2669 index of the first global symbol. */
2670 elf_section_data (sdynsym
->output_section
)->this_hdr
.sh_info
=
2678 /* The RELOCATE_SECTION function is called by the ELF backend linker
2679 to handle the relocations for a section.
2681 The relocs are always passed as Rela structures; if the section
2682 actually uses Rel structures, the r_addend field will always be
2685 This function is responsible for adjust the section contents as
2686 necessary, and (if using Rela relocs and generating a
2687 relocateable output file) adjusting the reloc addend as
2690 This function does not have to worry about setting the reloc
2691 address or the reloc symbol index.
2693 LOCAL_SYMS is a pointer to the swapped in local symbols.
2695 LOCAL_SECTIONS is an array giving the section in the input file
2696 corresponding to the st_shndx field of each local symbol.
2698 The global hash table entry for the global symbols can be found
2699 via elf_sym_hashes (input_bfd).
2701 When generating relocateable output, this function must handle
2702 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
2703 going to be the section symbol corresponding to the output
2704 section, which means that the addend must be adjusted
2708 ppc_elf_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
2709 contents
, relocs
, local_syms
, local_sections
)
2711 struct bfd_link_info
*info
;
2713 asection
*input_section
;
2715 Elf_Internal_Rela
*relocs
;
2716 Elf_Internal_Sym
*local_syms
;
2717 asection
**local_sections
;
2719 Elf_Internal_Shdr
*symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
2720 struct elf_link_hash_entry
**sym_hashes
= elf_sym_hashes (input_bfd
);
2721 bfd
*dynobj
= elf_hash_table (info
)->dynobj
;
2722 elf_linker_section_t
*sdata
= (dynobj
) ? elf_linker_section (dynobj
, LINKER_SECTION_SDATA
) : NULL
;
2723 elf_linker_section_t
*sdata2
= (dynobj
) ? elf_linker_section (dynobj
, LINKER_SECTION_SDATA2
) : NULL
;
2724 Elf_Internal_Rela
*rel
= relocs
;
2725 Elf_Internal_Rela
*relend
= relocs
+ input_section
->reloc_count
;
2726 asection
*sreloc
= NULL
;
2727 asection
*splt
= NULL
;
2728 asection
*sgot
= NULL
;
2729 bfd_vma
*local_got_offsets
;
2734 fprintf (stderr
, "ppc_elf_relocate_section called for %s section %s, %ld relocations%s\n",
2735 bfd_get_filename (input_bfd
),
2736 bfd_section_name(input_bfd
, input_section
),
2737 (long)input_section
->reloc_count
,
2738 (info
->relocateable
) ? " (relocatable)" : "");
2741 if (!ppc_elf_howto_table
[ R_PPC_ADDR32
]) /* Initialize howto table if needed */
2742 ppc_elf_howto_init ();
2744 local_got_offsets
= elf_local_got_offsets (input_bfd
);
2746 for (; rel
< relend
; rel
++)
2748 enum ppc_reloc_type r_type
= (enum ppc_reloc_type
)ELF32_R_TYPE (rel
->r_info
);
2749 bfd_vma offset
= rel
->r_offset
;
2750 bfd_vma addend
= rel
->r_addend
;
2751 bfd_reloc_status_type r
= bfd_reloc_other
;
2752 Elf_Internal_Sym
*sym
= (Elf_Internal_Sym
*)0;
2753 asection
*sec
= (asection
*)0;
2754 struct elf_link_hash_entry
*h
= (struct elf_link_hash_entry
*)0;
2755 const char *sym_name
= (const char *)0;
2756 reloc_howto_type
*howto
;
2757 unsigned long r_symndx
;
2760 /* Unknown relocation handling */
2761 if ((unsigned)r_type
>= (unsigned)R_PPC_max
|| !ppc_elf_howto_table
[(int)r_type
])
2763 (*_bfd_error_handler
) (_("%s: unknown relocation type %d"),
2764 bfd_get_filename (input_bfd
),
2767 bfd_set_error (bfd_error_bad_value
);
2772 howto
= ppc_elf_howto_table
[(int)r_type
];
2773 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2775 if (info
->relocateable
)
2777 /* This is a relocateable link. We don't have to change
2778 anything, unless the reloc is against a section symbol,
2779 in which case we have to adjust according to where the
2780 section symbol winds up in the output section. */
2781 if (r_symndx
< symtab_hdr
->sh_info
)
2783 sym
= local_syms
+ r_symndx
;
2784 if ((unsigned)ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
2786 sec
= local_sections
[r_symndx
];
2787 addend
= rel
->r_addend
+= sec
->output_offset
+ sym
->st_value
;
2792 fprintf (stderr
, "\ttype = %s (%d), symbol index = %ld, offset = %ld, addend = %ld\n",
2802 /* This is a final link. */
2803 if (r_symndx
< symtab_hdr
->sh_info
)
2805 sym
= local_syms
+ r_symndx
;
2806 sec
= local_sections
[r_symndx
];
2807 sym_name
= "<local symbol>";
2809 relocation
= (sec
->output_section
->vma
2810 + sec
->output_offset
2815 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2816 while (h
->root
.type
== bfd_link_hash_indirect
2817 || h
->root
.type
== bfd_link_hash_warning
)
2818 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2819 sym_name
= h
->root
.root
.string
;
2820 if (h
->root
.type
== bfd_link_hash_defined
2821 || h
->root
.type
== bfd_link_hash_defweak
)
2823 sec
= h
->root
.u
.def
.section
;
2824 if ((r_type
== R_PPC_PLT32
2825 && h
->plt
.offset
!= (bfd_vma
) -1)
2826 || (r_type
== R_PPC_LOCAL24PC
2827 && sec
->output_section
== NULL
)
2828 || ((r_type
== R_PPC_GOT16
2829 || r_type
== R_PPC_GOT16_LO
2830 || r_type
== R_PPC_GOT16_HI
2831 || r_type
== R_PPC_GOT16_HA
)
2832 && elf_hash_table (info
)->dynamic_sections_created
2834 || (! info
->symbolic
&& h
->dynindx
!= -1)
2835 || (h
->elf_link_hash_flags
2836 & ELF_LINK_HASH_DEF_REGULAR
) == 0))
2838 && ((! info
->symbolic
&& h
->dynindx
!= -1)
2839 || (h
->elf_link_hash_flags
2840 & ELF_LINK_HASH_DEF_REGULAR
) == 0)
2841 && (input_section
->flags
& SEC_ALLOC
) != 0
2842 && (r_type
== R_PPC_ADDR32
2843 || r_type
== R_PPC_ADDR24
2844 || r_type
== R_PPC_ADDR16
2845 || r_type
== R_PPC_ADDR16_LO
2846 || r_type
== R_PPC_ADDR16_HI
2847 || r_type
== R_PPC_ADDR16_HA
2848 || r_type
== R_PPC_ADDR14
2849 || r_type
== R_PPC_ADDR14_BRTAKEN
2850 || r_type
== R_PPC_ADDR14_BRNTAKEN
2851 || r_type
== R_PPC_PLTREL24
2852 || r_type
== R_PPC_COPY
2853 || r_type
== R_PPC_GLOB_DAT
2854 || r_type
== R_PPC_JMP_SLOT
2855 || r_type
== R_PPC_UADDR32
2856 || r_type
== R_PPC_UADDR16
2857 || r_type
== R_PPC_SDAREL16
2858 || r_type
== R_PPC_EMB_NADDR32
2859 || r_type
== R_PPC_EMB_NADDR16
2860 || r_type
== R_PPC_EMB_NADDR16_LO
2861 || r_type
== R_PPC_EMB_NADDR16_HI
2862 || r_type
== R_PPC_EMB_NADDR16_HA
2863 || r_type
== R_PPC_EMB_SDAI16
2864 || r_type
== R_PPC_EMB_SDA2I16
2865 || r_type
== R_PPC_EMB_SDA2REL
2866 || r_type
== R_PPC_EMB_SDA21
2867 || r_type
== R_PPC_EMB_MRKREF
2868 || r_type
== R_PPC_EMB_BIT_FLD
2869 || r_type
== R_PPC_EMB_RELSDA
2870 || ((r_type
== R_PPC_REL24
2871 || r_type
== R_PPC_REL32
2872 || r_type
== R_PPC_REL14
2873 || r_type
== R_PPC_REL14_BRTAKEN
2874 || r_type
== R_PPC_REL14_BRNTAKEN
2875 || r_type
== R_PPC_RELATIVE
)
2876 && strcmp (h
->root
.root
.string
,
2877 "_GLOBAL_OFFSET_TABLE_") != 0))))
2879 /* In these cases, we don't need the relocation
2880 value. We check specially because in some
2881 obscure cases sec->output_section will be NULL. */
2885 relocation
= (h
->root
.u
.def
.value
2886 + sec
->output_section
->vma
2887 + sec
->output_offset
);
2889 else if (h
->root
.type
== bfd_link_hash_undefweak
)
2891 else if (info
->shared
)
2895 (*info
->callbacks
->undefined_symbol
)(info
,
2896 h
->root
.root
.string
,
2905 switch ((int)r_type
)
2908 (*_bfd_error_handler
) (_("%s: unknown relocation type %d for symbol %s"),
2909 bfd_get_filename (input_bfd
),
2910 (int)r_type
, sym_name
);
2912 bfd_set_error (bfd_error_bad_value
);
2916 /* Relocations that need no special processing. */
2917 case (int)R_PPC_LOCAL24PC
:
2918 /* It makes no sense to point a local relocation
2919 at a symbol not in this object. */
2921 && (h
->root
.type
== bfd_link_hash_defined
2922 || h
->root
.type
== bfd_link_hash_defweak
)
2923 && sec
->output_section
== NULL
)
2925 (*info
->callbacks
->undefined_symbol
) (info
,
2926 h
->root
.root
.string
,
2935 /* Relocations that may need to be propagated if this is a shared
2937 case (int)R_PPC_REL24
:
2938 case (int)R_PPC_REL32
:
2939 case (int)R_PPC_REL14
:
2940 /* If these relocations are not to a named symbol, they can be
2941 handled right here, no need to bother the dynamic linker. */
2943 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
2947 /* Relocations that always need to be propagated if this is a shared
2949 case (int)R_PPC_NONE
:
2950 case (int)R_PPC_ADDR32
:
2951 case (int)R_PPC_ADDR24
:
2952 case (int)R_PPC_ADDR16
:
2953 case (int)R_PPC_ADDR16_LO
:
2954 case (int)R_PPC_ADDR16_HI
:
2955 case (int)R_PPC_ADDR16_HA
:
2956 case (int)R_PPC_ADDR14
:
2957 case (int)R_PPC_UADDR32
:
2958 case (int)R_PPC_UADDR16
:
2961 Elf_Internal_Rela outrel
;
2965 fprintf (stderr
, "ppc_elf_relocate_section need to create relocation for %s\n",
2966 (h
&& h
->root
.root
.string
) ? h
->root
.root
.string
: "<unknown>");
2969 /* When generating a shared object, these relocations
2970 are copied into the output file to be resolved at run
2977 name
= (bfd_elf_string_from_elf_section
2979 elf_elfheader (input_bfd
)->e_shstrndx
,
2980 elf_section_data (input_section
)->rel_hdr
.sh_name
));
2984 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
2985 && strcmp (bfd_get_section_name (input_bfd
,
2989 sreloc
= bfd_get_section_by_name (dynobj
, name
);
2990 BFD_ASSERT (sreloc
!= NULL
);
2995 if (elf_section_data (input_section
)->stab_info
== NULL
)
2996 outrel
.r_offset
= rel
->r_offset
;
3001 off
= (_bfd_stab_section_offset
3002 (output_bfd
, &elf_hash_table (info
)->stab_info
,
3004 &elf_section_data (input_section
)->stab_info
,
3006 if (off
== (bfd_vma
) -1)
3008 outrel
.r_offset
= off
;
3011 outrel
.r_offset
+= (input_section
->output_section
->vma
3012 + input_section
->output_offset
);
3015 memset (&outrel
, 0, sizeof outrel
);
3016 /* h->dynindx may be -1 if this symbol was marked to
3019 && ((! info
->symbolic
&& h
->dynindx
!= -1)
3020 || (h
->elf_link_hash_flags
3021 & ELF_LINK_HASH_DEF_REGULAR
) == 0))
3023 BFD_ASSERT (h
->dynindx
!= -1);
3024 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
3025 outrel
.r_addend
= rel
->r_addend
;
3029 if (r_type
== R_PPC_ADDR32
)
3031 outrel
.r_info
= ELF32_R_INFO (0, R_PPC_RELATIVE
);
3032 outrel
.r_addend
= relocation
+ rel
->r_addend
;
3039 sec
= local_sections
[r_symndx
];
3042 BFD_ASSERT (h
->root
.type
== bfd_link_hash_defined
3044 == bfd_link_hash_defweak
));
3045 sec
= h
->root
.u
.def
.section
;
3047 if (sec
!= NULL
&& bfd_is_abs_section (sec
))
3049 else if (sec
== NULL
|| sec
->owner
== NULL
)
3051 bfd_set_error (bfd_error_bad_value
);
3058 osec
= sec
->output_section
;
3059 indx
= elf_section_data (osec
)->dynindx
;
3060 BFD_ASSERT(indx
> 0);
3064 printf("indx=%d section=%s flags=%08x name=%s\n",
3065 indx
, osec
->name
, osec
->flags
,
3066 h
->root
.root
.string
);
3071 outrel
.r_info
= ELF32_R_INFO (indx
, r_type
);
3072 outrel
.r_addend
= relocation
+ rel
->r_addend
;
3076 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
,
3077 (((Elf32_External_Rela
*)
3079 + sreloc
->reloc_count
));
3080 ++sreloc
->reloc_count
;
3082 /* This reloc will be computed at runtime, so there's no
3083 need to do anything now, unless this is a RELATIVE
3084 reloc in an unallocated section. */
3086 || (input_section
->flags
& SEC_ALLOC
) != 0
3087 || ELF32_R_TYPE (outrel
.r_info
) != R_PPC_RELATIVE
)
3091 /* Arithmetic adjust relocations that aren't going into a
3093 if (r_type
== R_PPC_ADDR16_HA
3094 /* It's just possible that this symbol is a weak symbol
3095 that's not actually defined anywhere. In that case,
3096 'sec' would be NULL, and we should leave the symbol
3097 alone (it will be set to zero elsewhere in the link). */
3100 addend
+= ((relocation
+ addend
) & 0x8000) << 1;
3104 /* branch taken prediction relocations */
3105 case (int)R_PPC_ADDR14_BRTAKEN
:
3106 case (int)R_PPC_REL14_BRTAKEN
:
3107 insn
= bfd_get_32 (output_bfd
, contents
+ offset
);
3108 if ((relocation
- offset
) & 0x8000)
3109 insn
&= ~BRANCH_PREDICT_BIT
;
3111 insn
|= BRANCH_PREDICT_BIT
;
3112 bfd_put_32 (output_bfd
, insn
, contents
+ offset
);
3115 /* branch not taken predicition relocations */
3116 case (int)R_PPC_ADDR14_BRNTAKEN
:
3117 case (int)R_PPC_REL14_BRNTAKEN
:
3118 insn
= bfd_get_32 (output_bfd
, contents
+ offset
);
3119 if ((relocation
- offset
) & 0x8000)
3120 insn
|= BRANCH_PREDICT_BIT
;
3122 insn
&= ~BRANCH_PREDICT_BIT
;
3123 bfd_put_32 (output_bfd
, insn
, contents
+ offset
);
3126 /* GOT16 relocations */
3127 case (int)R_PPC_GOT16
:
3128 case (int)R_PPC_GOT16_LO
:
3129 case (int)R_PPC_GOT16_HI
:
3130 case (int)R_PPC_GOT16_HA
:
3131 /* Relocation is to the entry for this symbol in the global
3135 sgot
= bfd_get_section_by_name (dynobj
, ".got");
3136 BFD_ASSERT (sgot
!= NULL
);
3143 off
= h
->got
.offset
;
3144 BFD_ASSERT (off
!= (bfd_vma
) -1);
3146 if (! elf_hash_table (info
)->dynamic_sections_created
3148 && (info
->symbolic
|| h
->dynindx
== -1)
3149 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
)))
3151 /* This is actually a static link, or it is a
3152 -Bsymbolic link and the symbol is defined
3153 locally. We must initialize this entry in the
3154 global offset table. Since the offset must
3155 always be a multiple of 4, we use the least
3156 significant bit to record whether we have
3157 initialized it already.
3159 When doing a dynamic link, we create a .rela.got
3160 relocation entry to initialize the value. This
3161 is done in the finish_dynamic_symbol routine. */
3166 bfd_put_32 (output_bfd
, relocation
,
3167 sgot
->contents
+ off
);
3172 relocation
= sgot
->output_offset
+ off
- 4;
3178 BFD_ASSERT (local_got_offsets
!= NULL
3179 && local_got_offsets
[r_symndx
] != (bfd_vma
) -1);
3181 off
= local_got_offsets
[r_symndx
];
3183 /* The offset must always be a multiple of 4. We use
3184 the least significant bit to record whether we have
3185 already processed this entry. */
3190 bfd_put_32 (output_bfd
, relocation
, sgot
->contents
+ off
);
3195 Elf_Internal_Rela outrel
;
3197 /* We need to generate a R_PPC_RELATIVE reloc
3198 for the dynamic linker. */
3199 srelgot
= bfd_get_section_by_name (dynobj
, ".rela.got");
3200 BFD_ASSERT (srelgot
!= NULL
);
3202 outrel
.r_offset
= (sgot
->output_section
->vma
3203 + sgot
->output_offset
3205 outrel
.r_info
= ELF32_R_INFO (0, R_PPC_RELATIVE
);
3206 outrel
.r_addend
= relocation
;
3207 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
,
3208 (((Elf32_External_Rela
*)
3210 + srelgot
->reloc_count
));
3211 ++srelgot
->reloc_count
;
3214 local_got_offsets
[r_symndx
] |= 1;
3217 relocation
= sgot
->output_offset
+ off
- 4;
3221 /* Indirect .sdata relocation */
3222 case (int)R_PPC_EMB_SDAI16
:
3223 BFD_ASSERT (sdata
!= NULL
);
3224 relocation
= bfd_elf32_finish_pointer_linker_section (output_bfd
, input_bfd
, info
,
3225 sdata
, h
, relocation
, rel
,
3229 /* Indirect .sdata2 relocation */
3230 case (int)R_PPC_EMB_SDA2I16
:
3231 BFD_ASSERT (sdata2
!= NULL
);
3232 relocation
= bfd_elf32_finish_pointer_linker_section (output_bfd
, input_bfd
, info
,
3233 sdata2
, h
, relocation
, rel
,
3237 /* Handle the TOC16 reloc. We want to use the offset within the .got
3238 section, not the actual VMA. This is appropriate when generating
3239 an embedded ELF object, for which the .got section acts like the
3240 AIX .toc section. */
3241 case (int)R_PPC_TOC16
: /* phony GOT16 relocations */
3242 BFD_ASSERT (sec
!= (asection
*)0);
3243 BFD_ASSERT (bfd_is_und_section (sec
)
3244 || strcmp (bfd_get_section_name (abfd
, sec
), ".got") == 0
3245 || strcmp (bfd_get_section_name (abfd
, sec
), ".cgot") == 0)
3247 addend
-= sec
->output_section
->vma
+ sec
->output_offset
+ 0x8000;
3250 case (int)R_PPC_PLTREL24
:
3251 /* Relocation is to the entry for this symbol in the
3252 procedure linkage table. */
3253 BFD_ASSERT (h
!= NULL
);
3255 if (h
->plt
.offset
== (bfd_vma
) -1)
3257 /* We didn't make a PLT entry for this symbol. This
3258 happens when statically linking PIC code, or when
3259 using -Bsymbolic. */
3265 splt
= bfd_get_section_by_name (dynobj
, ".plt");
3266 BFD_ASSERT (splt
!= NULL
);
3269 relocation
= (splt
->output_section
->vma
3270 + splt
->output_offset
3274 /* relocate against _SDA_BASE_ */
3275 case (int)R_PPC_SDAREL16
:
3276 BFD_ASSERT (sec
!= (asection
*)0);
3277 if (strcmp (bfd_get_section_name (abfd
, sec
), ".sdata") != 0
3278 && strcmp (bfd_get_section_name (abfd
, sec
), ".dynsbss") != 0
3279 && strcmp (bfd_get_section_name (abfd
, sec
), ".sbss") != 0)
3281 (*_bfd_error_handler
) (_("%s: The target (%s) of a %s relocation is in the wrong section (%s)"),
3282 bfd_get_filename (input_bfd
),
3284 ppc_elf_howto_table
[ (int)r_type
]->name
,
3285 bfd_get_section_name (abfd
, sec
));
3287 bfd_set_error (bfd_error_bad_value
);
3291 addend
-= (sdata
->sym_hash
->root
.u
.def
.value
3292 + sdata
->sym_hash
->root
.u
.def
.section
->output_section
->vma
3293 + sdata
->sym_hash
->root
.u
.def
.section
->output_offset
);
3297 /* relocate against _SDA2_BASE_ */
3298 case (int)R_PPC_EMB_SDA2REL
:
3299 BFD_ASSERT (sec
!= (asection
*)0);
3300 if (strcmp (bfd_get_section_name (abfd
, sec
), ".sdata2") != 0
3301 && strcmp (bfd_get_section_name (abfd
, sec
), ".sbss2") != 0)
3303 (*_bfd_error_handler
) (_("%s: The target (%s) of a %s relocation is in the wrong section (%s)"),
3304 bfd_get_filename (input_bfd
),
3306 ppc_elf_howto_table
[ (int)r_type
]->name
,
3307 bfd_get_section_name (abfd
, sec
));
3309 bfd_set_error (bfd_error_bad_value
);
3313 addend
-= (sdata2
->sym_hash
->root
.u
.def
.value
3314 + sdata2
->sym_hash
->root
.u
.def
.section
->output_section
->vma
3315 + sdata2
->sym_hash
->root
.u
.def
.section
->output_offset
);
3319 /* relocate against either _SDA_BASE_, _SDA2_BASE_, or 0 */
3320 case (int)R_PPC_EMB_SDA21
:
3321 case (int)R_PPC_EMB_RELSDA
:
3323 const char *name
= bfd_get_section_name (abfd
, sec
);
3326 BFD_ASSERT (sec
!= (asection
*)0);
3327 if (strcmp (name
, ".sdata") == 0 || strcmp (name
, ".sbss") == 0)
3330 addend
-= (sdata
->sym_hash
->root
.u
.def
.value
3331 + sdata
->sym_hash
->root
.u
.def
.section
->output_section
->vma
3332 + sdata
->sym_hash
->root
.u
.def
.section
->output_offset
);
3335 else if (strcmp (name
, ".sdata2") == 0 || strcmp (name
, ".sbss2") == 0)
3338 addend
-= (sdata2
->sym_hash
->root
.u
.def
.value
3339 + sdata2
->sym_hash
->root
.u
.def
.section
->output_section
->vma
3340 + sdata2
->sym_hash
->root
.u
.def
.section
->output_offset
);
3343 else if (strcmp (name
, ".PPC.EMB.sdata0") == 0 || strcmp (name
, ".PPC.EMB.sbss0") == 0)
3350 (*_bfd_error_handler
) (_("%s: The target (%s) of a %s relocation is in the wrong section (%s)"),
3351 bfd_get_filename (input_bfd
),
3353 ppc_elf_howto_table
[ (int)r_type
]->name
,
3354 bfd_get_section_name (abfd
, sec
));
3356 bfd_set_error (bfd_error_bad_value
);
3361 if (r_type
== R_PPC_EMB_SDA21
)
3362 { /* fill in register field */
3363 insn
= bfd_get_32 (output_bfd
, contents
+ offset
);
3364 insn
= (insn
& ~RA_REGISTER_MASK
) | (reg
<< RA_REGISTER_SHIFT
);
3365 bfd_put_32 (output_bfd
, insn
, contents
+ offset
);
3370 /* Relocate against the beginning of the section */
3371 case (int)R_PPC_SECTOFF
:
3372 case (int)R_PPC_SECTOFF_LO
:
3373 case (int)R_PPC_SECTOFF_HI
:
3374 BFD_ASSERT (sec
!= (asection
*)0);
3375 addend
-= sec
->output_section
->vma
;
3378 case (int)R_PPC_SECTOFF_HA
:
3379 BFD_ASSERT (sec
!= (asection
*)0);
3380 addend
-= sec
->output_section
->vma
;
3381 addend
+= ((relocation
+ addend
) & 0x8000) << 1;
3384 /* Negative relocations */
3385 case (int)R_PPC_EMB_NADDR32
:
3386 case (int)R_PPC_EMB_NADDR16
:
3387 case (int)R_PPC_EMB_NADDR16_LO
:
3388 case (int)R_PPC_EMB_NADDR16_HI
:
3389 addend
-= 2*relocation
;
3392 case (int)R_PPC_EMB_NADDR16_HA
:
3393 addend
-= 2*relocation
;
3394 addend
+= ((relocation
+ addend
) & 0x8000) << 1;
3397 /* NOP relocation that prevents garbage collecting linkers from omitting a
3399 case (int)R_PPC_EMB_MRKREF
:
3402 case (int)R_PPC_COPY
:
3403 case (int)R_PPC_GLOB_DAT
:
3404 case (int)R_PPC_JMP_SLOT
:
3405 case (int)R_PPC_RELATIVE
:
3406 case (int)R_PPC_PLT32
:
3407 case (int)R_PPC_PLTREL32
:
3408 case (int)R_PPC_PLT16_LO
:
3409 case (int)R_PPC_PLT16_HI
:
3410 case (int)R_PPC_PLT16_HA
:
3411 case (int)R_PPC_EMB_RELSEC16
:
3412 case (int)R_PPC_EMB_RELST_LO
:
3413 case (int)R_PPC_EMB_RELST_HI
:
3414 case (int)R_PPC_EMB_RELST_HA
:
3415 case (int)R_PPC_EMB_BIT_FLD
:
3416 (*_bfd_error_handler
) (_("%s: Relocation %s is not yet supported for symbol %s."),
3417 bfd_get_filename (input_bfd
),
3418 ppc_elf_howto_table
[ (int)r_type
]->name
,
3421 bfd_set_error (bfd_error_invalid_operation
);
3425 case (int)R_PPC_GNU_VTINHERIT
:
3426 case (int)R_PPC_GNU_VTENTRY
:
3427 /* These are no-ops in the end. */
3433 fprintf (stderr
, "\ttype = %s (%d), name = %s, symbol index = %ld, offset = %ld, addend = %ld\n",
3442 r
= _bfd_final_link_relocate (howto
,
3450 if (r
!= bfd_reloc_ok
)
3458 case bfd_reloc_overflow
:
3463 name
= h
->root
.root
.string
;
3466 name
= bfd_elf_string_from_elf_section (input_bfd
,
3467 symtab_hdr
->sh_link
,
3473 name
= bfd_section_name (input_bfd
, sec
);
3476 (*info
->callbacks
->reloc_overflow
)(info
,
3492 fprintf (stderr
, "\n");
3499 #define TARGET_LITTLE_SYM bfd_elf32_powerpcle_vec
3500 #define TARGET_LITTLE_NAME "elf32-powerpcle"
3501 #define TARGET_BIG_SYM bfd_elf32_powerpc_vec
3502 #define TARGET_BIG_NAME "elf32-powerpc"
3503 #define ELF_ARCH bfd_arch_powerpc
3504 #define ELF_MACHINE_CODE EM_PPC
3505 #define ELF_MAXPAGESIZE 0x10000
3506 #define elf_info_to_howto ppc_elf_info_to_howto
3508 #ifdef EM_CYGNUS_POWERPC
3509 #define ELF_MACHINE_ALT1 EM_CYGNUS_POWERPC
3513 #define ELF_MACHINE_ALT2 EM_PPC_OLD
3516 #define elf_backend_plt_not_loaded 1
3517 #define elf_backend_got_symbol_offset 4
3518 #define elf_backend_can_gc_sections 1
3519 #define elf_backend_got_header_size 12
3520 #define elf_backend_plt_header_size PLT_INITIAL_ENTRY_SIZE
3522 #define bfd_elf32_bfd_copy_private_bfd_data ppc_elf_copy_private_bfd_data
3523 #define bfd_elf32_bfd_merge_private_bfd_data ppc_elf_merge_private_bfd_data
3524 #define bfd_elf32_bfd_set_private_flags ppc_elf_set_private_flags
3525 #define bfd_elf32_bfd_reloc_type_lookup ppc_elf_reloc_type_lookup
3526 #define bfd_elf32_bfd_final_link _bfd_elf32_gc_common_final_link
3528 #define elf_backend_gc_mark_hook ppc_elf_gc_mark_hook
3529 #define elf_backend_gc_sweep_hook ppc_elf_gc_sweep_hook
3530 #define elf_backend_section_from_shdr ppc_elf_section_from_shdr
3531 #define elf_backend_relocate_section ppc_elf_relocate_section
3532 #define elf_backend_create_dynamic_sections ppc_elf_create_dynamic_sections
3533 #define elf_backend_check_relocs ppc_elf_check_relocs
3534 #define elf_backend_adjust_dynamic_symbol ppc_elf_adjust_dynamic_symbol
3535 #define elf_backend_add_symbol_hook ppc_elf_add_symbol_hook
3536 #define elf_backend_size_dynamic_sections ppc_elf_size_dynamic_sections
3537 #define elf_backend_finish_dynamic_symbol ppc_elf_finish_dynamic_symbol
3538 #define elf_backend_finish_dynamic_sections ppc_elf_finish_dynamic_sections
3539 #define elf_backend_fake_sections ppc_elf_fake_sections
3540 #define elf_backend_additional_program_headers ppc_elf_additional_program_headers
3541 #define elf_backend_modify_segment_map ppc_elf_modify_segment_map
3543 #include "elf32-target.h"