1 /* PowerPC-specific support for 32-bit ELF
2 Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002
3 Free Software Foundation, Inc.
4 Written by Ian Lance Taylor, Cygnus Support.
6 This file is part of BFD, the Binary File Descriptor library.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
22 /* This file is based on a preliminary PowerPC ELF ABI. The
23 information may not match the final PowerPC ELF ABI. It includes
24 suggestions from the in-progress Embedded PowerPC ABI, and that
25 information may also not match. */
34 /* RELA relocations are used here. */
36 static reloc_howto_type
*ppc_elf_reloc_type_lookup
37 PARAMS ((bfd
*abfd
, bfd_reloc_code_real_type code
));
38 static void ppc_elf_info_to_howto
39 PARAMS ((bfd
*abfd
, arelent
*cache_ptr
, Elf_Internal_Rela
*dst
));
40 static void ppc_elf_howto_init
PARAMS ((void));
41 static int ppc_elf_sort_rela
PARAMS ((const PTR
, const PTR
));
42 static boolean ppc_elf_relax_section
43 PARAMS ((bfd
*, asection
*, struct bfd_link_info
*, boolean
*));
44 static bfd_reloc_status_type ppc_elf_addr16_ha_reloc
45 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
46 static boolean ppc_elf_object_p
PARAMS ((bfd
*));
47 static boolean ppc_elf_set_private_flags
PARAMS ((bfd
*, flagword
));
48 static boolean ppc_elf_merge_private_bfd_data
PARAMS ((bfd
*, bfd
*));
50 static int ppc_elf_additional_program_headers
PARAMS ((bfd
*));
51 static boolean ppc_elf_modify_segment_map
PARAMS ((bfd
*));
53 static asection
*ppc_elf_create_got
54 PARAMS ((bfd
*, struct bfd_link_info
*));
55 static boolean ppc_elf_create_dynamic_sections
56 PARAMS ((bfd
*, struct bfd_link_info
*));
58 static boolean ppc_elf_section_from_shdr
PARAMS ((bfd
*,
61 static boolean ppc_elf_fake_sections
62 PARAMS ((bfd
*, Elf_Internal_Shdr
*, asection
*));
64 static elf_linker_section_t
*ppc_elf_create_linker_section
66 struct bfd_link_info
*info
,
67 enum elf_linker_section_enum
));
69 static boolean ppc_elf_check_relocs
PARAMS ((bfd
*,
70 struct bfd_link_info
*,
72 const Elf_Internal_Rela
*));
74 static asection
* ppc_elf_gc_mark_hook
PARAMS ((asection
*sec
,
75 struct bfd_link_info
*info
,
76 Elf_Internal_Rela
*rel
,
77 struct elf_link_hash_entry
*h
,
78 Elf_Internal_Sym
*sym
));
80 static boolean ppc_elf_gc_sweep_hook
PARAMS ((bfd
*abfd
,
81 struct bfd_link_info
*info
,
83 const Elf_Internal_Rela
*relocs
));
85 static boolean ppc_elf_adjust_dynamic_symbol
PARAMS ((struct bfd_link_info
*,
86 struct elf_link_hash_entry
*));
88 static boolean ppc_elf_size_dynamic_sections
PARAMS ((bfd
*, struct bfd_link_info
*));
90 static boolean ppc_elf_relocate_section
PARAMS ((bfd
*,
91 struct bfd_link_info
*info
,
95 Elf_Internal_Rela
*relocs
,
96 Elf_Internal_Sym
*local_syms
,
99 static boolean ppc_elf_add_symbol_hook
PARAMS ((bfd
*,
100 struct bfd_link_info
*,
101 const Elf_Internal_Sym
*,
107 static boolean ppc_elf_finish_dynamic_symbol
PARAMS ((bfd
*,
108 struct bfd_link_info
*,
109 struct elf_link_hash_entry
*,
110 Elf_Internal_Sym
*));
112 static boolean ppc_elf_finish_dynamic_sections
PARAMS ((bfd
*, struct bfd_link_info
*));
113 static enum elf_reloc_type_class ppc_elf_reloc_type_class
114 PARAMS ((const Elf_Internal_Rela
*));
115 static boolean ppc_elf_grok_prstatus
116 PARAMS ((bfd
*abfd
, Elf_Internal_Note
*note
));
117 static boolean ppc_elf_grok_psinfo
118 PARAMS ((bfd
*abfd
, Elf_Internal_Note
*note
));
120 #define BRANCH_PREDICT_BIT 0x200000 /* branch prediction bit for branch taken relocs */
121 #define RA_REGISTER_MASK 0x001f0000 /* mask to set RA in memory instructions */
122 #define RA_REGISTER_SHIFT 16 /* value to shift register by to insert RA */
124 /* The name of the dynamic interpreter. This is put in the .interp
127 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
129 /* The size in bytes of an entry in the procedure linkage table. */
130 #define PLT_ENTRY_SIZE 12
131 /* The initial size of the plt reserved for the dynamic linker. */
132 #define PLT_INITIAL_ENTRY_SIZE 72
133 /* The size of the gap between entries in the PLT. */
134 #define PLT_SLOT_SIZE 8
135 /* The number of single-slot PLT entries (the rest use two slots). */
136 #define PLT_NUM_SINGLE_ENTRIES 8192
138 /* Will references to this symbol always reference the symbol
140 #define SYMBOL_REFERENCES_LOCAL(INFO, H) \
143 || H->dynindx == -1 \
144 || ELF_ST_VISIBILITY (H->other) == STV_INTERNAL \
145 || ELF_ST_VISIBILITY (H->other) == STV_HIDDEN) \
146 && (H->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) != 0)
148 /* Will _calls_ to this symbol always call the version in this object? */
149 #define SYMBOL_CALLS_LOCAL(INFO, H) \
152 || H->dynindx == -1 \
153 || ELF_ST_VISIBILITY (H->other) != STV_DEFAULT) \
154 && (H->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) != 0)
156 static reloc_howto_type
*ppc_elf_howto_table
[(int) R_PPC_max
];
158 static reloc_howto_type ppc_elf_howto_raw
[] = {
159 /* This reloc does nothing. */
160 HOWTO (R_PPC_NONE
, /* type */
162 2, /* size (0 = byte, 1 = short, 2 = long) */
164 false, /* pc_relative */
166 complain_overflow_bitfield
, /* complain_on_overflow */
167 bfd_elf_generic_reloc
, /* special_function */
168 "R_PPC_NONE", /* name */
169 false, /* partial_inplace */
172 false), /* pcrel_offset */
174 /* A standard 32 bit relocation. */
175 HOWTO (R_PPC_ADDR32
, /* type */
177 2, /* size (0 = byte, 1 = short, 2 = long) */
179 false, /* pc_relative */
181 complain_overflow_bitfield
, /* complain_on_overflow */
182 bfd_elf_generic_reloc
, /* special_function */
183 "R_PPC_ADDR32", /* name */
184 false, /* partial_inplace */
186 0xffffffff, /* dst_mask */
187 false), /* pcrel_offset */
189 /* An absolute 26 bit branch; the lower two bits must be zero.
190 FIXME: we don't check that, we just clear them. */
191 HOWTO (R_PPC_ADDR24
, /* type */
193 2, /* size (0 = byte, 1 = short, 2 = long) */
195 false, /* pc_relative */
197 complain_overflow_bitfield
, /* complain_on_overflow */
198 bfd_elf_generic_reloc
, /* special_function */
199 "R_PPC_ADDR24", /* name */
200 false, /* partial_inplace */
202 0x3fffffc, /* dst_mask */
203 false), /* pcrel_offset */
205 /* A standard 16 bit relocation. */
206 HOWTO (R_PPC_ADDR16
, /* type */
208 1, /* size (0 = byte, 1 = short, 2 = long) */
210 false, /* pc_relative */
212 complain_overflow_bitfield
, /* complain_on_overflow */
213 bfd_elf_generic_reloc
, /* special_function */
214 "R_PPC_ADDR16", /* name */
215 false, /* partial_inplace */
217 0xffff, /* dst_mask */
218 false), /* pcrel_offset */
220 /* A 16 bit relocation without overflow. */
221 HOWTO (R_PPC_ADDR16_LO
, /* type */
223 1, /* size (0 = byte, 1 = short, 2 = long) */
225 false, /* pc_relative */
227 complain_overflow_dont
,/* complain_on_overflow */
228 bfd_elf_generic_reloc
, /* special_function */
229 "R_PPC_ADDR16_LO", /* name */
230 false, /* partial_inplace */
232 0xffff, /* dst_mask */
233 false), /* pcrel_offset */
235 /* The high order 16 bits of an address. */
236 HOWTO (R_PPC_ADDR16_HI
, /* type */
238 1, /* size (0 = byte, 1 = short, 2 = long) */
240 false, /* pc_relative */
242 complain_overflow_dont
, /* complain_on_overflow */
243 bfd_elf_generic_reloc
, /* special_function */
244 "R_PPC_ADDR16_HI", /* name */
245 false, /* partial_inplace */
247 0xffff, /* dst_mask */
248 false), /* pcrel_offset */
250 /* The high order 16 bits of an address, plus 1 if the contents of
251 the low 16 bits, treated as a signed number, is negative. */
252 HOWTO (R_PPC_ADDR16_HA
, /* type */
254 1, /* size (0 = byte, 1 = short, 2 = long) */
256 false, /* pc_relative */
258 complain_overflow_dont
, /* complain_on_overflow */
259 ppc_elf_addr16_ha_reloc
, /* special_function */
260 "R_PPC_ADDR16_HA", /* name */
261 false, /* partial_inplace */
263 0xffff, /* dst_mask */
264 false), /* pcrel_offset */
266 /* An absolute 16 bit branch; the lower two bits must be zero.
267 FIXME: we don't check that, we just clear them. */
268 HOWTO (R_PPC_ADDR14
, /* type */
270 2, /* size (0 = byte, 1 = short, 2 = long) */
272 false, /* pc_relative */
274 complain_overflow_bitfield
, /* complain_on_overflow */
275 bfd_elf_generic_reloc
, /* special_function */
276 "R_PPC_ADDR14", /* name */
277 false, /* partial_inplace */
279 0xfffc, /* dst_mask */
280 false), /* pcrel_offset */
282 /* An absolute 16 bit branch, for which bit 10 should be set to
283 indicate that the branch is expected to be taken. The lower two
284 bits must be zero. */
285 HOWTO (R_PPC_ADDR14_BRTAKEN
, /* type */
287 2, /* size (0 = byte, 1 = short, 2 = long) */
289 false, /* pc_relative */
291 complain_overflow_bitfield
, /* complain_on_overflow */
292 bfd_elf_generic_reloc
, /* special_function */
293 "R_PPC_ADDR14_BRTAKEN",/* name */
294 false, /* partial_inplace */
296 0xfffc, /* dst_mask */
297 false), /* pcrel_offset */
299 /* An absolute 16 bit branch, for which bit 10 should be set to
300 indicate that the branch is not expected to be taken. The lower
301 two bits must be zero. */
302 HOWTO (R_PPC_ADDR14_BRNTAKEN
, /* type */
304 2, /* size (0 = byte, 1 = short, 2 = long) */
306 false, /* pc_relative */
308 complain_overflow_bitfield
, /* complain_on_overflow */
309 bfd_elf_generic_reloc
, /* special_function */
310 "R_PPC_ADDR14_BRNTAKEN",/* name */
311 false, /* partial_inplace */
313 0xfffc, /* dst_mask */
314 false), /* pcrel_offset */
316 /* A relative 26 bit branch; the lower two bits must be zero. */
317 HOWTO (R_PPC_REL24
, /* type */
319 2, /* size (0 = byte, 1 = short, 2 = long) */
321 true, /* pc_relative */
323 complain_overflow_signed
, /* complain_on_overflow */
324 bfd_elf_generic_reloc
, /* special_function */
325 "R_PPC_REL24", /* name */
326 false, /* partial_inplace */
328 0x3fffffc, /* dst_mask */
329 true), /* pcrel_offset */
331 /* A relative 16 bit branch; the lower two bits must be zero. */
332 HOWTO (R_PPC_REL14
, /* type */
334 2, /* size (0 = byte, 1 = short, 2 = long) */
336 true, /* pc_relative */
338 complain_overflow_signed
, /* complain_on_overflow */
339 bfd_elf_generic_reloc
, /* special_function */
340 "R_PPC_REL14", /* name */
341 false, /* partial_inplace */
343 0xfffc, /* dst_mask */
344 true), /* pcrel_offset */
346 /* A relative 16 bit branch. Bit 10 should be set to indicate that
347 the branch is expected to be taken. The lower two bits must be
349 HOWTO (R_PPC_REL14_BRTAKEN
, /* type */
351 2, /* size (0 = byte, 1 = short, 2 = long) */
353 true, /* pc_relative */
355 complain_overflow_signed
, /* complain_on_overflow */
356 bfd_elf_generic_reloc
, /* special_function */
357 "R_PPC_REL14_BRTAKEN", /* name */
358 false, /* partial_inplace */
360 0xfffc, /* dst_mask */
361 true), /* pcrel_offset */
363 /* A relative 16 bit branch. Bit 10 should be set to indicate that
364 the branch is not expected to be taken. The lower two bits must
366 HOWTO (R_PPC_REL14_BRNTAKEN
, /* type */
368 2, /* size (0 = byte, 1 = short, 2 = long) */
370 true, /* pc_relative */
372 complain_overflow_signed
, /* complain_on_overflow */
373 bfd_elf_generic_reloc
, /* special_function */
374 "R_PPC_REL14_BRNTAKEN",/* name */
375 false, /* partial_inplace */
377 0xfffc, /* dst_mask */
378 true), /* pcrel_offset */
380 /* Like R_PPC_ADDR16, but referring to the GOT table entry for the
382 HOWTO (R_PPC_GOT16
, /* type */
384 1, /* size (0 = byte, 1 = short, 2 = long) */
386 false, /* pc_relative */
388 complain_overflow_signed
, /* complain_on_overflow */
389 bfd_elf_generic_reloc
, /* special_function */
390 "R_PPC_GOT16", /* name */
391 false, /* partial_inplace */
393 0xffff, /* dst_mask */
394 false), /* pcrel_offset */
396 /* Like R_PPC_ADDR16_LO, but referring to the GOT table entry for
398 HOWTO (R_PPC_GOT16_LO
, /* type */
400 1, /* size (0 = byte, 1 = short, 2 = long) */
402 false, /* pc_relative */
404 complain_overflow_dont
, /* complain_on_overflow */
405 bfd_elf_generic_reloc
, /* special_function */
406 "R_PPC_GOT16_LO", /* name */
407 false, /* partial_inplace */
409 0xffff, /* dst_mask */
410 false), /* pcrel_offset */
412 /* Like R_PPC_ADDR16_HI, but referring to the GOT table entry for
414 HOWTO (R_PPC_GOT16_HI
, /* type */
416 1, /* size (0 = byte, 1 = short, 2 = long) */
418 false, /* pc_relative */
420 complain_overflow_bitfield
, /* complain_on_overflow */
421 bfd_elf_generic_reloc
, /* special_function */
422 "R_PPC_GOT16_HI", /* name */
423 false, /* partial_inplace */
425 0xffff, /* dst_mask */
426 false), /* pcrel_offset */
428 /* Like R_PPC_ADDR16_HA, but referring to the GOT table entry for
430 HOWTO (R_PPC_GOT16_HA
, /* type */
432 1, /* size (0 = byte, 1 = short, 2 = long) */
434 false, /* pc_relative */
436 complain_overflow_bitfield
, /* complain_on_overflow */
437 ppc_elf_addr16_ha_reloc
, /* special_function */
438 "R_PPC_GOT16_HA", /* name */
439 false, /* partial_inplace */
441 0xffff, /* dst_mask */
442 false), /* pcrel_offset */
444 /* Like R_PPC_REL24, but referring to the procedure linkage table
445 entry for the symbol. */
446 HOWTO (R_PPC_PLTREL24
, /* type */
448 2, /* size (0 = byte, 1 = short, 2 = long) */
450 true, /* pc_relative */
452 complain_overflow_signed
, /* complain_on_overflow */
453 bfd_elf_generic_reloc
, /* special_function */
454 "R_PPC_PLTREL24", /* name */
455 false, /* partial_inplace */
457 0x3fffffc, /* dst_mask */
458 true), /* pcrel_offset */
460 /* This is used only by the dynamic linker. The symbol should exist
461 both in the object being run and in some shared library. The
462 dynamic linker copies the data addressed by the symbol from the
463 shared library into the object, because the object being
464 run has to have the data at some particular address. */
465 HOWTO (R_PPC_COPY
, /* type */
467 2, /* size (0 = byte, 1 = short, 2 = long) */
469 false, /* pc_relative */
471 complain_overflow_bitfield
, /* complain_on_overflow */
472 bfd_elf_generic_reloc
, /* special_function */
473 "R_PPC_COPY", /* name */
474 false, /* partial_inplace */
477 false), /* pcrel_offset */
479 /* Like R_PPC_ADDR32, but used when setting global offset table
481 HOWTO (R_PPC_GLOB_DAT
, /* type */
483 2, /* size (0 = byte, 1 = short, 2 = long) */
485 false, /* pc_relative */
487 complain_overflow_bitfield
, /* complain_on_overflow */
488 bfd_elf_generic_reloc
, /* special_function */
489 "R_PPC_GLOB_DAT", /* name */
490 false, /* partial_inplace */
492 0xffffffff, /* dst_mask */
493 false), /* pcrel_offset */
495 /* Marks a procedure linkage table entry for a symbol. */
496 HOWTO (R_PPC_JMP_SLOT
, /* type */
498 2, /* size (0 = byte, 1 = short, 2 = long) */
500 false, /* pc_relative */
502 complain_overflow_bitfield
, /* complain_on_overflow */
503 bfd_elf_generic_reloc
, /* special_function */
504 "R_PPC_JMP_SLOT", /* name */
505 false, /* partial_inplace */
508 false), /* pcrel_offset */
510 /* Used only by the dynamic linker. When the object is run, this
511 longword is set to the load address of the object, plus the
513 HOWTO (R_PPC_RELATIVE
, /* type */
515 2, /* size (0 = byte, 1 = short, 2 = long) */
517 false, /* pc_relative */
519 complain_overflow_bitfield
, /* complain_on_overflow */
520 bfd_elf_generic_reloc
, /* special_function */
521 "R_PPC_RELATIVE", /* name */
522 false, /* partial_inplace */
524 0xffffffff, /* dst_mask */
525 false), /* pcrel_offset */
527 /* Like R_PPC_REL24, but uses the value of the symbol within the
528 object rather than the final value. Normally used for
529 _GLOBAL_OFFSET_TABLE_. */
530 HOWTO (R_PPC_LOCAL24PC
, /* type */
532 2, /* size (0 = byte, 1 = short, 2 = long) */
534 true, /* pc_relative */
536 complain_overflow_signed
, /* complain_on_overflow */
537 bfd_elf_generic_reloc
, /* special_function */
538 "R_PPC_LOCAL24PC", /* name */
539 false, /* partial_inplace */
541 0x3fffffc, /* dst_mask */
542 true), /* pcrel_offset */
544 /* Like R_PPC_ADDR32, but may be unaligned. */
545 HOWTO (R_PPC_UADDR32
, /* type */
547 2, /* size (0 = byte, 1 = short, 2 = long) */
549 false, /* pc_relative */
551 complain_overflow_bitfield
, /* complain_on_overflow */
552 bfd_elf_generic_reloc
, /* special_function */
553 "R_PPC_UADDR32", /* name */
554 false, /* partial_inplace */
556 0xffffffff, /* dst_mask */
557 false), /* pcrel_offset */
559 /* Like R_PPC_ADDR16, but may be unaligned. */
560 HOWTO (R_PPC_UADDR16
, /* type */
562 1, /* size (0 = byte, 1 = short, 2 = long) */
564 false, /* pc_relative */
566 complain_overflow_bitfield
, /* complain_on_overflow */
567 bfd_elf_generic_reloc
, /* special_function */
568 "R_PPC_UADDR16", /* name */
569 false, /* partial_inplace */
571 0xffff, /* dst_mask */
572 false), /* pcrel_offset */
574 /* 32-bit PC relative */
575 HOWTO (R_PPC_REL32
, /* type */
577 2, /* size (0 = byte, 1 = short, 2 = long) */
579 true, /* pc_relative */
581 complain_overflow_bitfield
, /* complain_on_overflow */
582 bfd_elf_generic_reloc
, /* special_function */
583 "R_PPC_REL32", /* name */
584 false, /* partial_inplace */
586 0xffffffff, /* dst_mask */
587 true), /* pcrel_offset */
589 /* 32-bit relocation to the symbol's procedure linkage table.
590 FIXME: not supported. */
591 HOWTO (R_PPC_PLT32
, /* type */
593 2, /* size (0 = byte, 1 = short, 2 = long) */
595 false, /* pc_relative */
597 complain_overflow_bitfield
, /* complain_on_overflow */
598 bfd_elf_generic_reloc
, /* special_function */
599 "R_PPC_PLT32", /* name */
600 false, /* partial_inplace */
603 false), /* pcrel_offset */
605 /* 32-bit PC relative relocation to the symbol's procedure linkage table.
606 FIXME: not supported. */
607 HOWTO (R_PPC_PLTREL32
, /* type */
609 2, /* size (0 = byte, 1 = short, 2 = long) */
611 true, /* pc_relative */
613 complain_overflow_bitfield
, /* complain_on_overflow */
614 bfd_elf_generic_reloc
, /* special_function */
615 "R_PPC_PLTREL32", /* name */
616 false, /* partial_inplace */
619 true), /* pcrel_offset */
621 /* Like R_PPC_ADDR16_LO, but referring to the PLT table entry for
623 HOWTO (R_PPC_PLT16_LO
, /* type */
625 1, /* size (0 = byte, 1 = short, 2 = long) */
627 false, /* pc_relative */
629 complain_overflow_dont
, /* complain_on_overflow */
630 bfd_elf_generic_reloc
, /* special_function */
631 "R_PPC_PLT16_LO", /* name */
632 false, /* partial_inplace */
634 0xffff, /* dst_mask */
635 false), /* pcrel_offset */
637 /* Like R_PPC_ADDR16_HI, but referring to the PLT table entry for
639 HOWTO (R_PPC_PLT16_HI
, /* type */
641 1, /* size (0 = byte, 1 = short, 2 = long) */
643 false, /* pc_relative */
645 complain_overflow_bitfield
, /* complain_on_overflow */
646 bfd_elf_generic_reloc
, /* special_function */
647 "R_PPC_PLT16_HI", /* name */
648 false, /* partial_inplace */
650 0xffff, /* dst_mask */
651 false), /* pcrel_offset */
653 /* Like R_PPC_ADDR16_HA, but referring to the PLT table entry for
655 HOWTO (R_PPC_PLT16_HA
, /* type */
657 1, /* size (0 = byte, 1 = short, 2 = long) */
659 false, /* pc_relative */
661 complain_overflow_bitfield
, /* complain_on_overflow */
662 ppc_elf_addr16_ha_reloc
, /* special_function */
663 "R_PPC_PLT16_HA", /* name */
664 false, /* partial_inplace */
666 0xffff, /* dst_mask */
667 false), /* pcrel_offset */
669 /* A sign-extended 16 bit value relative to _SDA_BASE_, for use with
671 HOWTO (R_PPC_SDAREL16
, /* type */
673 1, /* size (0 = byte, 1 = short, 2 = long) */
675 false, /* pc_relative */
677 complain_overflow_signed
, /* complain_on_overflow */
678 bfd_elf_generic_reloc
, /* special_function */
679 "R_PPC_SDAREL16", /* name */
680 false, /* partial_inplace */
682 0xffff, /* dst_mask */
683 false), /* pcrel_offset */
685 /* 16-bit section relative relocation. */
686 HOWTO (R_PPC_SECTOFF
, /* type */
688 1, /* size (0 = byte, 1 = short, 2 = long) */
690 false, /* pc_relative */
692 complain_overflow_bitfield
, /* complain_on_overflow */
693 bfd_elf_generic_reloc
, /* special_function */
694 "R_PPC_SECTOFF", /* name */
695 false, /* partial_inplace */
697 0xffff, /* dst_mask */
698 false), /* pcrel_offset */
700 /* 16-bit lower half section relative relocation. */
701 HOWTO (R_PPC_SECTOFF_LO
, /* type */
703 1, /* size (0 = byte, 1 = short, 2 = long) */
705 false, /* pc_relative */
707 complain_overflow_dont
, /* complain_on_overflow */
708 bfd_elf_generic_reloc
, /* special_function */
709 "R_PPC_SECTOFF_LO", /* name */
710 false, /* partial_inplace */
712 0xffff, /* dst_mask */
713 false), /* pcrel_offset */
715 /* 16-bit upper half section relative relocation. */
716 HOWTO (R_PPC_SECTOFF_HI
, /* type */
718 1, /* size (0 = byte, 1 = short, 2 = long) */
720 false, /* pc_relative */
722 complain_overflow_bitfield
, /* complain_on_overflow */
723 bfd_elf_generic_reloc
, /* special_function */
724 "R_PPC_SECTOFF_HI", /* name */
725 false, /* partial_inplace */
727 0xffff, /* dst_mask */
728 false), /* pcrel_offset */
730 /* 16-bit upper half adjusted section relative relocation. */
731 HOWTO (R_PPC_SECTOFF_HA
, /* type */
733 1, /* size (0 = byte, 1 = short, 2 = long) */
735 false, /* pc_relative */
737 complain_overflow_bitfield
, /* complain_on_overflow */
738 ppc_elf_addr16_ha_reloc
, /* special_function */
739 "R_PPC_SECTOFF_HA", /* name */
740 false, /* partial_inplace */
742 0xffff, /* dst_mask */
743 false), /* pcrel_offset */
745 /* The remaining relocs are from the Embedded ELF ABI, and are not
746 in the SVR4 ELF ABI. */
748 /* 32 bit value resulting from the addend minus the symbol */
749 HOWTO (R_PPC_EMB_NADDR32
, /* type */
751 2, /* size (0 = byte, 1 = short, 2 = long) */
753 false, /* pc_relative */
755 complain_overflow_bitfield
, /* complain_on_overflow */
756 bfd_elf_generic_reloc
, /* special_function */
757 "R_PPC_EMB_NADDR32", /* name */
758 false, /* partial_inplace */
760 0xffffffff, /* dst_mask */
761 false), /* pcrel_offset */
763 /* 16 bit value resulting from the addend minus the symbol */
764 HOWTO (R_PPC_EMB_NADDR16
, /* type */
766 1, /* size (0 = byte, 1 = short, 2 = long) */
768 false, /* pc_relative */
770 complain_overflow_bitfield
, /* complain_on_overflow */
771 bfd_elf_generic_reloc
, /* special_function */
772 "R_PPC_EMB_NADDR16", /* name */
773 false, /* partial_inplace */
775 0xffff, /* dst_mask */
776 false), /* pcrel_offset */
778 /* 16 bit value resulting from the addend minus the symbol */
779 HOWTO (R_PPC_EMB_NADDR16_LO
, /* type */
781 1, /* size (0 = byte, 1 = short, 2 = long) */
783 false, /* pc_relative */
785 complain_overflow_dont
,/* complain_on_overflow */
786 bfd_elf_generic_reloc
, /* special_function */
787 "R_PPC_EMB_ADDR16_LO", /* name */
788 false, /* partial_inplace */
790 0xffff, /* dst_mask */
791 false), /* pcrel_offset */
793 /* The high order 16 bits of the addend minus the symbol */
794 HOWTO (R_PPC_EMB_NADDR16_HI
, /* type */
796 1, /* size (0 = byte, 1 = short, 2 = long) */
798 false, /* pc_relative */
800 complain_overflow_dont
, /* complain_on_overflow */
801 bfd_elf_generic_reloc
, /* special_function */
802 "R_PPC_EMB_NADDR16_HI", /* name */
803 false, /* partial_inplace */
805 0xffff, /* dst_mask */
806 false), /* pcrel_offset */
808 /* The high order 16 bits of the result of the addend minus the address,
809 plus 1 if the contents of the low 16 bits, treated as a signed number,
811 HOWTO (R_PPC_EMB_NADDR16_HA
, /* type */
813 1, /* size (0 = byte, 1 = short, 2 = long) */
815 false, /* pc_relative */
817 complain_overflow_dont
, /* complain_on_overflow */
818 ppc_elf_addr16_ha_reloc
, /* special_function */
819 "R_PPC_EMB_NADDR16_HA", /* name */
820 false, /* partial_inplace */
822 0xffff, /* dst_mask */
823 false), /* pcrel_offset */
825 /* 16 bit value resulting from allocating a 4 byte word to hold an
826 address in the .sdata section, and returning the offset from
827 _SDA_BASE_ for that relocation */
828 HOWTO (R_PPC_EMB_SDAI16
, /* type */
830 1, /* size (0 = byte, 1 = short, 2 = long) */
832 false, /* pc_relative */
834 complain_overflow_bitfield
, /* complain_on_overflow */
835 bfd_elf_generic_reloc
, /* special_function */
836 "R_PPC_EMB_SDAI16", /* name */
837 false, /* partial_inplace */
839 0xffff, /* dst_mask */
840 false), /* pcrel_offset */
842 /* 16 bit value resulting from allocating a 4 byte word to hold an
843 address in the .sdata2 section, and returning the offset from
844 _SDA2_BASE_ for that relocation */
845 HOWTO (R_PPC_EMB_SDA2I16
, /* type */
847 1, /* size (0 = byte, 1 = short, 2 = long) */
849 false, /* pc_relative */
851 complain_overflow_bitfield
, /* complain_on_overflow */
852 bfd_elf_generic_reloc
, /* special_function */
853 "R_PPC_EMB_SDA2I16", /* name */
854 false, /* partial_inplace */
856 0xffff, /* dst_mask */
857 false), /* pcrel_offset */
859 /* A sign-extended 16 bit value relative to _SDA2_BASE_, for use with
861 HOWTO (R_PPC_EMB_SDA2REL
, /* type */
863 1, /* size (0 = byte, 1 = short, 2 = long) */
865 false, /* pc_relative */
867 complain_overflow_signed
, /* complain_on_overflow */
868 bfd_elf_generic_reloc
, /* special_function */
869 "R_PPC_EMB_SDA2REL", /* name */
870 false, /* partial_inplace */
872 0xffff, /* dst_mask */
873 false), /* pcrel_offset */
875 /* Relocate against either _SDA_BASE_ or _SDA2_BASE_, filling in the 16 bit
876 signed offset from the appropriate base, and filling in the register
877 field with the appropriate register (0, 2, or 13). */
878 HOWTO (R_PPC_EMB_SDA21
, /* type */
880 2, /* size (0 = byte, 1 = short, 2 = long) */
882 false, /* pc_relative */
884 complain_overflow_signed
, /* complain_on_overflow */
885 bfd_elf_generic_reloc
, /* special_function */
886 "R_PPC_EMB_SDA21", /* name */
887 false, /* partial_inplace */
889 0xffff, /* dst_mask */
890 false), /* pcrel_offset */
892 /* Relocation not handled: R_PPC_EMB_MRKREF */
893 /* Relocation not handled: R_PPC_EMB_RELSEC16 */
894 /* Relocation not handled: R_PPC_EMB_RELST_LO */
895 /* Relocation not handled: R_PPC_EMB_RELST_HI */
896 /* Relocation not handled: R_PPC_EMB_RELST_HA */
897 /* Relocation not handled: R_PPC_EMB_BIT_FLD */
899 /* PC relative relocation against either _SDA_BASE_ or _SDA2_BASE_, filling
900 in the 16 bit signed offset from the appropriate base, and filling in the
901 register field with the appropriate register (0, 2, or 13). */
902 HOWTO (R_PPC_EMB_RELSDA
, /* type */
904 1, /* size (0 = byte, 1 = short, 2 = long) */
906 true, /* pc_relative */
908 complain_overflow_signed
, /* complain_on_overflow */
909 bfd_elf_generic_reloc
, /* special_function */
910 "R_PPC_EMB_RELSDA", /* name */
911 false, /* partial_inplace */
913 0xffff, /* dst_mask */
914 false), /* pcrel_offset */
916 /* GNU extension to record C++ vtable hierarchy */
917 HOWTO (R_PPC_GNU_VTINHERIT
, /* type */
919 0, /* size (0 = byte, 1 = short, 2 = long) */
921 false, /* pc_relative */
923 complain_overflow_dont
, /* complain_on_overflow */
924 NULL
, /* special_function */
925 "R_PPC_GNU_VTINHERIT", /* name */
926 false, /* partial_inplace */
929 false), /* pcrel_offset */
931 /* GNU extension to record C++ vtable member usage */
932 HOWTO (R_PPC_GNU_VTENTRY
, /* type */
934 0, /* size (0 = byte, 1 = short, 2 = long) */
936 false, /* pc_relative */
938 complain_overflow_dont
, /* complain_on_overflow */
939 NULL
, /* special_function */
940 "R_PPC_GNU_VTENTRY", /* name */
941 false, /* partial_inplace */
944 false), /* pcrel_offset */
946 /* Phony reloc to handle AIX style TOC entries */
947 HOWTO (R_PPC_TOC16
, /* type */
949 1, /* size (0 = byte, 1 = short, 2 = long) */
951 false, /* pc_relative */
953 complain_overflow_signed
, /* complain_on_overflow */
954 bfd_elf_generic_reloc
, /* special_function */
955 "R_PPC_TOC16", /* name */
956 false, /* partial_inplace */
958 0xffff, /* dst_mask */
959 false), /* pcrel_offset */
962 /* Initialize the ppc_elf_howto_table, so that linear accesses can be done. */
965 ppc_elf_howto_init ()
967 unsigned int i
, type
;
969 for (i
= 0; i
< sizeof (ppc_elf_howto_raw
) / sizeof (ppc_elf_howto_raw
[0]); i
++)
971 type
= ppc_elf_howto_raw
[i
].type
;
972 BFD_ASSERT (type
< sizeof (ppc_elf_howto_table
) / sizeof (ppc_elf_howto_table
[0]));
973 ppc_elf_howto_table
[type
] = &ppc_elf_howto_raw
[i
];
977 /* This function handles relaxing for the PPC with option --mpc860c0[=<n>].
979 The MPC860, revision C0 or earlier contains a bug in the die.
980 If all of the following conditions are true, the next instruction
981 to be executed *may* be treated as a no-op.
982 1/ A forward branch is executed.
983 2/ The branch is predicted as not taken.
984 3/ The branch is taken.
985 4/ The branch is located in the last 5 words of a page.
986 (The EOP limit is 5 by default but may be specified as any value from 1-10.)
988 Our software solution is to detect these problematic branches in a
989 linker pass and modify them as follows:
990 1/ Unconditional branches - Since these are always predicted taken,
991 there is no problem and no action is required.
992 2/ Conditional backward branches - No problem, no action required.
993 3/ Conditional forward branches - Ensure that the "inverse prediction
994 bit" is set (ensure it is predicted taken).
995 4/ Conditional register branches - Ensure that the "y bit" is set
996 (ensure it is predicted taken).
999 /* Sort sections by address. */
1002 ppc_elf_sort_rela (arg1
, arg2
)
1006 const Elf_Internal_Rela
**rela1
= (const Elf_Internal_Rela
**) arg1
;
1007 const Elf_Internal_Rela
**rela2
= (const Elf_Internal_Rela
**) arg2
;
1009 /* Sort by offset. */
1010 return ((*rela1
)->r_offset
- (*rela2
)->r_offset
);
1014 ppc_elf_relax_section (abfd
, isec
, link_info
, again
)
1017 struct bfd_link_info
*link_info
;
1020 #define PAGESIZE 0x1000
1022 bfd_byte
*contents
= NULL
;
1023 bfd_byte
*free_contents
= NULL
;
1024 Elf_Internal_Rela
*internal_relocs
= NULL
;
1025 Elf_Internal_Rela
*free_relocs
= NULL
;
1026 Elf_Internal_Rela
**rela_comb
= NULL
;
1027 int comb_curr
, comb_count
;
1029 /* We never have to do this more than once per input section. */
1032 /* If needed, initialize this section's cooked size. */
1033 if (isec
->_cooked_size
== 0)
1034 isec
->_cooked_size
= isec
->_raw_size
;
1036 /* We're only interested in text sections which overlap the
1037 troublesome area at the end of a page. */
1038 if (link_info
->mpc860c0
&& (isec
->flags
& SEC_CODE
) && isec
->_cooked_size
)
1040 bfd_vma dot
, end_page
, end_section
;
1041 boolean section_modified
;
1043 /* Get the section contents. */
1044 /* Get cached copy if it exists. */
1045 if (elf_section_data (isec
)->this_hdr
.contents
!= NULL
)
1046 contents
= elf_section_data (isec
)->this_hdr
.contents
;
1049 /* Go get them off disk. */
1050 contents
= (bfd_byte
*) bfd_malloc (isec
->_raw_size
);
1051 if (contents
== NULL
)
1053 free_contents
= contents
;
1055 if (! bfd_get_section_contents (abfd
, isec
, contents
,
1056 (file_ptr
) 0, isec
->_raw_size
))
1062 if (isec
->reloc_count
)
1067 /* Get a copy of the native relocations. */
1068 internal_relocs
= _bfd_elf32_link_read_relocs (
1069 abfd
, isec
, (PTR
) NULL
, (Elf_Internal_Rela
*) NULL
,
1070 link_info
->keep_memory
);
1071 if (internal_relocs
== NULL
)
1073 if (! link_info
->keep_memory
)
1074 free_relocs
= internal_relocs
;
1076 /* Setup a faster access method for the reloc info we need. */
1077 amt
= isec
->reloc_count
;
1078 amt
*= sizeof (Elf_Internal_Rela
*);
1079 rela_comb
= (Elf_Internal_Rela
**) bfd_malloc (amt
);
1080 if (rela_comb
== NULL
)
1082 for (n
= 0; n
< isec
->reloc_count
; ++n
)
1086 r_type
= ELF32_R_TYPE (internal_relocs
[n
].r_info
);
1087 if (r_type
< 0 || r_type
>= (int) R_PPC_max
)
1090 /* Prologue constants are sometimes present in the ".text"
1091 sections and they can be identified by their associated relocation.
1092 We don't want to process those words and some others which
1093 can also be identified by their relocations. However, not all
1094 conditional branches will have a relocation so we will
1095 only ignore words that 1) have a reloc, and 2) the reloc
1096 is not applicable to a conditional branch.
1097 The array rela_comb is built here for use in the EOP scan loop. */
1100 case R_PPC_ADDR14_BRNTAKEN
: /* absolute, predicted not taken */
1101 case R_PPC_REL14
: /* relative cond. br. */
1102 case R_PPC_REL14_BRNTAKEN
: /* rel. cond. br., predicted not taken */
1103 /* We should check the instruction. */
1106 /* The word is not a conditional branch - ignore it. */
1107 rela_comb
[comb_count
++] = &internal_relocs
[n
];
1112 qsort (rela_comb
, (size_t) comb_count
, sizeof (int), ppc_elf_sort_rela
);
1115 /* Enumerate each EOP region that overlaps this section. */
1116 end_section
= isec
->vma
+ isec
->_cooked_size
;
1117 dot
= end_page
= (isec
->vma
| (PAGESIZE
- 1)) + 1;
1118 dot
-= link_info
->mpc860c0
;
1119 section_modified
= false;
1120 if (dot
< isec
->vma
) /* Increment the start position if this section */
1121 dot
= isec
->vma
; /* begins in the middle of its first EOP region. */
1124 dot
+= PAGESIZE
, end_page
+= PAGESIZE
)
1127 /* Check each word in this EOP region. */
1128 for (; dot
< end_page
; dot
+= 4)
1130 bfd_vma isec_offset
;
1132 boolean skip
, modified
;
1134 /* Don't process this word if there is a relocation for it and
1135 the relocation indicates the word is not a conditional branch. */
1137 isec_offset
= dot
- isec
->vma
;
1138 for (; comb_curr
<comb_count
; ++comb_curr
)
1142 r_offset
= rela_comb
[comb_curr
]->r_offset
;
1143 if (r_offset
>= isec_offset
)
1145 if (r_offset
== isec_offset
) skip
= true;
1151 /* Check the current word for a problematic conditional branch. */
1152 #define BO0(insn) ((insn) & 0x02000000)
1153 #define BO2(insn) ((insn) & 0x00800000)
1154 #define BO4(insn) ((insn) & 0x00200000)
1155 insn
= (unsigned long) bfd_get_32 (abfd
, contents
+ isec_offset
);
1157 if ((insn
& 0xFc000000) == 0x40000000)
1159 /* Instruction is BCx */
1160 if ((!BO0(insn
) || !BO2(insn
)) && !BO4(insn
))
1163 /* This branch is predicted as "normal".
1164 If this is a forward branch, it is problematic. */
1166 target
= insn
& 0x0000Fffc; /*extract*/
1167 target
= (target
^ 0x8000) - 0x8000; /*sign extend*/
1168 if ((insn
& 0x00000002) == 0)
1169 target
+= dot
; /*convert to abs*/
1172 insn
|= 0x00200000; /* set the prediction bit */
1177 else if ((insn
& 0xFc00Fffe) == 0x4c000420)
1179 /* Instruction is BCCTRx */
1180 if ((!BO0(insn
) || !BO2(insn
)) && !BO4(insn
))
1182 /* This branch is predicted as not-taken.
1183 If this is a forward branch, it is problematic.
1184 Since we can't tell statically if it will branch forward,
1185 always set the prediction bit. */
1186 insn
|= 0x00200000; /* set the prediction bit */
1190 else if ((insn
& 0xFc00Fffe) == 0x4c000020)
1192 /* Instruction is BCLRx */
1193 if ((!BO0(insn
) || !BO2(insn
)) && !BO4(insn
))
1195 /* This branch is predicted as not-taken.
1196 If this is a forward branch, it is problematic.
1197 Since we can't tell statically if it will branch forward,
1198 always set the prediction bit. */
1199 insn
|= 0x00200000; /* set the prediction bit */
1208 bfd_put_32 (abfd
, (bfd_vma
) insn
, contents
+ isec_offset
);
1209 section_modified
= true;
1213 if (section_modified
)
1215 elf_section_data (isec
)->this_hdr
.contents
= contents
;
1216 free_contents
= NULL
;
1220 if (rela_comb
!= NULL
)
1226 if (free_relocs
!= NULL
)
1232 if (free_contents
!= NULL
)
1234 if (! link_info
->keep_memory
)
1235 free (free_contents
);
1238 /* Cache the section contents for elf_link_input_bfd. */
1239 elf_section_data (isec
)->this_hdr
.contents
= contents
;
1241 free_contents
= NULL
;
1247 if (rela_comb
!= NULL
)
1249 if (free_relocs
!= NULL
)
1251 if (free_contents
!= NULL
)
1252 free (free_contents
);
1256 static reloc_howto_type
*
1257 ppc_elf_reloc_type_lookup (abfd
, code
)
1258 bfd
*abfd ATTRIBUTE_UNUSED
;
1259 bfd_reloc_code_real_type code
;
1261 enum elf_ppc_reloc_type ppc_reloc
= R_PPC_NONE
;
1263 if (!ppc_elf_howto_table
[R_PPC_ADDR32
])
1264 /* Initialize howto table if needed. */
1265 ppc_elf_howto_init ();
1270 return (reloc_howto_type
*) NULL
;
1272 case BFD_RELOC_NONE
: ppc_reloc
= R_PPC_NONE
; break;
1273 case BFD_RELOC_32
: ppc_reloc
= R_PPC_ADDR32
; break;
1274 case BFD_RELOC_PPC_BA26
: ppc_reloc
= R_PPC_ADDR24
; break;
1275 case BFD_RELOC_16
: ppc_reloc
= R_PPC_ADDR16
; break;
1276 case BFD_RELOC_LO16
: ppc_reloc
= R_PPC_ADDR16_LO
; break;
1277 case BFD_RELOC_HI16
: ppc_reloc
= R_PPC_ADDR16_HI
; break;
1278 case BFD_RELOC_HI16_S
: ppc_reloc
= R_PPC_ADDR16_HA
; break;
1279 case BFD_RELOC_PPC_BA16
: ppc_reloc
= R_PPC_ADDR14
; break;
1280 case BFD_RELOC_PPC_BA16_BRTAKEN
: ppc_reloc
= R_PPC_ADDR14_BRTAKEN
; break;
1281 case BFD_RELOC_PPC_BA16_BRNTAKEN
: ppc_reloc
= R_PPC_ADDR14_BRNTAKEN
; break;
1282 case BFD_RELOC_PPC_B26
: ppc_reloc
= R_PPC_REL24
; break;
1283 case BFD_RELOC_PPC_B16
: ppc_reloc
= R_PPC_REL14
; break;
1284 case BFD_RELOC_PPC_B16_BRTAKEN
: ppc_reloc
= R_PPC_REL14_BRTAKEN
; break;
1285 case BFD_RELOC_PPC_B16_BRNTAKEN
: ppc_reloc
= R_PPC_REL14_BRNTAKEN
; break;
1286 case BFD_RELOC_16_GOTOFF
: ppc_reloc
= R_PPC_GOT16
; break;
1287 case BFD_RELOC_LO16_GOTOFF
: ppc_reloc
= R_PPC_GOT16_LO
; break;
1288 case BFD_RELOC_HI16_GOTOFF
: ppc_reloc
= R_PPC_GOT16_HI
; break;
1289 case BFD_RELOC_HI16_S_GOTOFF
: ppc_reloc
= R_PPC_GOT16_HA
; break;
1290 case BFD_RELOC_24_PLT_PCREL
: ppc_reloc
= R_PPC_PLTREL24
; break;
1291 case BFD_RELOC_PPC_COPY
: ppc_reloc
= R_PPC_COPY
; break;
1292 case BFD_RELOC_PPC_GLOB_DAT
: ppc_reloc
= R_PPC_GLOB_DAT
; break;
1293 case BFD_RELOC_PPC_LOCAL24PC
: ppc_reloc
= R_PPC_LOCAL24PC
; break;
1294 case BFD_RELOC_32_PCREL
: ppc_reloc
= R_PPC_REL32
; break;
1295 case BFD_RELOC_32_PLTOFF
: ppc_reloc
= R_PPC_PLT32
; break;
1296 case BFD_RELOC_32_PLT_PCREL
: ppc_reloc
= R_PPC_PLTREL32
; break;
1297 case BFD_RELOC_LO16_PLTOFF
: ppc_reloc
= R_PPC_PLT16_LO
; break;
1298 case BFD_RELOC_HI16_PLTOFF
: ppc_reloc
= R_PPC_PLT16_HI
; break;
1299 case BFD_RELOC_HI16_S_PLTOFF
: ppc_reloc
= R_PPC_PLT16_HA
; break;
1300 case BFD_RELOC_GPREL16
: ppc_reloc
= R_PPC_SDAREL16
; break;
1301 case BFD_RELOC_16_BASEREL
: ppc_reloc
= R_PPC_SECTOFF
; break;
1302 case BFD_RELOC_LO16_BASEREL
: ppc_reloc
= R_PPC_SECTOFF_LO
; break;
1303 case BFD_RELOC_HI16_BASEREL
: ppc_reloc
= R_PPC_SECTOFF_HI
; break;
1304 case BFD_RELOC_HI16_S_BASEREL
: ppc_reloc
= R_PPC_SECTOFF_HA
; break;
1305 case BFD_RELOC_CTOR
: ppc_reloc
= R_PPC_ADDR32
; break;
1306 case BFD_RELOC_PPC_TOC16
: ppc_reloc
= R_PPC_TOC16
; break;
1307 case BFD_RELOC_PPC_EMB_NADDR32
: ppc_reloc
= R_PPC_EMB_NADDR32
; break;
1308 case BFD_RELOC_PPC_EMB_NADDR16
: ppc_reloc
= R_PPC_EMB_NADDR16
; break;
1309 case BFD_RELOC_PPC_EMB_NADDR16_LO
: ppc_reloc
= R_PPC_EMB_NADDR16_LO
; break;
1310 case BFD_RELOC_PPC_EMB_NADDR16_HI
: ppc_reloc
= R_PPC_EMB_NADDR16_HI
; break;
1311 case BFD_RELOC_PPC_EMB_NADDR16_HA
: ppc_reloc
= R_PPC_EMB_NADDR16_HA
; break;
1312 case BFD_RELOC_PPC_EMB_SDAI16
: ppc_reloc
= R_PPC_EMB_SDAI16
; break;
1313 case BFD_RELOC_PPC_EMB_SDA2I16
: ppc_reloc
= R_PPC_EMB_SDA2I16
; break;
1314 case BFD_RELOC_PPC_EMB_SDA2REL
: ppc_reloc
= R_PPC_EMB_SDA2REL
; break;
1315 case BFD_RELOC_PPC_EMB_SDA21
: ppc_reloc
= R_PPC_EMB_SDA21
; break;
1316 case BFD_RELOC_PPC_EMB_MRKREF
: ppc_reloc
= R_PPC_EMB_MRKREF
; break;
1317 case BFD_RELOC_PPC_EMB_RELSEC16
: ppc_reloc
= R_PPC_EMB_RELSEC16
; break;
1318 case BFD_RELOC_PPC_EMB_RELST_LO
: ppc_reloc
= R_PPC_EMB_RELST_LO
; break;
1319 case BFD_RELOC_PPC_EMB_RELST_HI
: ppc_reloc
= R_PPC_EMB_RELST_HI
; break;
1320 case BFD_RELOC_PPC_EMB_RELST_HA
: ppc_reloc
= R_PPC_EMB_RELST_HA
; break;
1321 case BFD_RELOC_PPC_EMB_BIT_FLD
: ppc_reloc
= R_PPC_EMB_BIT_FLD
; break;
1322 case BFD_RELOC_PPC_EMB_RELSDA
: ppc_reloc
= R_PPC_EMB_RELSDA
; break;
1323 case BFD_RELOC_VTABLE_INHERIT
: ppc_reloc
= R_PPC_GNU_VTINHERIT
; break;
1324 case BFD_RELOC_VTABLE_ENTRY
: ppc_reloc
= R_PPC_GNU_VTENTRY
; break;
1327 return ppc_elf_howto_table
[(int) ppc_reloc
];
1330 /* Set the howto pointer for a PowerPC ELF reloc. */
1333 ppc_elf_info_to_howto (abfd
, cache_ptr
, dst
)
1334 bfd
*abfd ATTRIBUTE_UNUSED
;
1336 Elf_Internal_Rela
*dst
;
1338 if (!ppc_elf_howto_table
[R_PPC_ADDR32
])
1339 /* Initialize howto table if needed. */
1340 ppc_elf_howto_init ();
1342 BFD_ASSERT (ELF32_R_TYPE (dst
->r_info
) < (unsigned int) R_PPC_max
);
1343 cache_ptr
->howto
= ppc_elf_howto_table
[ELF32_R_TYPE (dst
->r_info
)];
1346 /* Handle the R_PPC_ADDR16_HA reloc. */
1348 static bfd_reloc_status_type
1349 ppc_elf_addr16_ha_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1350 output_bfd
, error_message
)
1351 bfd
*abfd ATTRIBUTE_UNUSED
;
1352 arelent
*reloc_entry
;
1354 PTR data ATTRIBUTE_UNUSED
;
1355 asection
*input_section
;
1357 char **error_message ATTRIBUTE_UNUSED
;
1361 if (output_bfd
!= NULL
)
1363 reloc_entry
->address
+= input_section
->output_offset
;
1364 return bfd_reloc_ok
;
1367 if (reloc_entry
->address
> input_section
->_cooked_size
)
1368 return bfd_reloc_outofrange
;
1370 if (bfd_is_com_section (symbol
->section
))
1373 relocation
= symbol
->value
;
1375 relocation
+= symbol
->section
->output_section
->vma
;
1376 relocation
+= symbol
->section
->output_offset
;
1377 relocation
+= reloc_entry
->addend
;
1379 reloc_entry
->addend
+= (relocation
& 0x8000) << 1;
1381 return bfd_reloc_continue
;
1384 /* Fix bad default arch selected for a 32 bit input bfd when the
1385 default is 64 bit. */
1388 ppc_elf_object_p (abfd
)
1391 if (abfd
->arch_info
->the_default
&& abfd
->arch_info
->bits_per_word
== 64)
1393 Elf_Internal_Ehdr
*i_ehdr
= elf_elfheader (abfd
);
1395 if (i_ehdr
->e_ident
[EI_CLASS
] == ELFCLASS32
)
1397 /* Relies on arch after 64 bit default being 32 bit default. */
1398 abfd
->arch_info
= abfd
->arch_info
->next
;
1399 BFD_ASSERT (abfd
->arch_info
->bits_per_word
== 32);
1405 /* Function to set whether a module needs the -mrelocatable bit set. */
1408 ppc_elf_set_private_flags (abfd
, flags
)
1412 BFD_ASSERT (!elf_flags_init (abfd
)
1413 || elf_elfheader (abfd
)->e_flags
== flags
);
1415 elf_elfheader (abfd
)->e_flags
= flags
;
1416 elf_flags_init (abfd
) = true;
1420 /* Merge backend specific data from an object file to the output
1421 object file when linking */
1423 ppc_elf_merge_private_bfd_data (ibfd
, obfd
)
1431 /* Check if we have the same endianess */
1432 if (! _bfd_generic_verify_endian_match (ibfd
, obfd
))
1435 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
1436 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
1439 new_flags
= elf_elfheader (ibfd
)->e_flags
;
1440 old_flags
= elf_elfheader (obfd
)->e_flags
;
1441 if (!elf_flags_init (obfd
)) /* First call, no flags set */
1443 elf_flags_init (obfd
) = true;
1444 elf_elfheader (obfd
)->e_flags
= new_flags
;
1447 else if (new_flags
== old_flags
) /* Compatible flags are ok */
1450 else /* Incompatible flags */
1452 /* Warn about -mrelocatable mismatch. Allow -mrelocatable-lib to be linked
1455 if ((new_flags
& EF_PPC_RELOCATABLE
) != 0
1456 && (old_flags
& (EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
)) == 0)
1459 (*_bfd_error_handler
)
1460 (_("%s: compiled with -mrelocatable and linked with modules compiled normally"),
1461 bfd_archive_filename (ibfd
));
1463 else if ((new_flags
& (EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
)) == 0
1464 && (old_flags
& EF_PPC_RELOCATABLE
) != 0)
1467 (*_bfd_error_handler
)
1468 (_("%s: compiled normally and linked with modules compiled with -mrelocatable"),
1469 bfd_archive_filename (ibfd
));
1472 /* The output is -mrelocatable-lib iff both the input files are. */
1473 if (! (new_flags
& EF_PPC_RELOCATABLE_LIB
))
1474 elf_elfheader (obfd
)->e_flags
&= ~EF_PPC_RELOCATABLE_LIB
;
1476 /* The output is -mrelocatable iff it can't be -mrelocatable-lib,
1477 but each input file is either -mrelocatable or -mrelocatable-lib. */
1478 if (! (elf_elfheader (obfd
)->e_flags
& EF_PPC_RELOCATABLE_LIB
)
1479 && (new_flags
& (EF_PPC_RELOCATABLE_LIB
| EF_PPC_RELOCATABLE
))
1480 && (old_flags
& (EF_PPC_RELOCATABLE_LIB
| EF_PPC_RELOCATABLE
)))
1481 elf_elfheader (obfd
)->e_flags
|= EF_PPC_RELOCATABLE
;
1483 /* Do not warn about eabi vs. V.4 mismatch, just or in the bit if any module uses it */
1484 elf_elfheader (obfd
)->e_flags
|= (new_flags
& EF_PPC_EMB
);
1486 new_flags
&= ~ (EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
| EF_PPC_EMB
);
1487 old_flags
&= ~ (EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
| EF_PPC_EMB
);
1489 /* Warn about any other mismatches */
1490 if (new_flags
!= old_flags
)
1493 (*_bfd_error_handler
)
1494 (_("%s: uses different e_flags (0x%lx) fields than previous modules (0x%lx)"),
1495 bfd_archive_filename (ibfd
), (long) new_flags
, (long) old_flags
);
1500 bfd_set_error (bfd_error_bad_value
);
1508 /* Handle a PowerPC specific section when reading an object file. This
1509 is called when elfcode.h finds a section with an unknown type. */
1512 ppc_elf_section_from_shdr (abfd
, hdr
, name
)
1514 Elf_Internal_Shdr
*hdr
;
1520 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
))
1523 newsect
= hdr
->bfd_section
;
1524 flags
= bfd_get_section_flags (abfd
, newsect
);
1525 if (hdr
->sh_flags
& SHF_EXCLUDE
)
1526 flags
|= SEC_EXCLUDE
;
1528 if (hdr
->sh_type
== SHT_ORDERED
)
1529 flags
|= SEC_SORT_ENTRIES
;
1531 bfd_set_section_flags (abfd
, newsect
, flags
);
1535 /* Set up any other section flags and such that may be necessary. */
1538 ppc_elf_fake_sections (abfd
, shdr
, asect
)
1539 bfd
*abfd ATTRIBUTE_UNUSED
;
1540 Elf_Internal_Shdr
*shdr
;
1543 if ((asect
->flags
& SEC_EXCLUDE
) != 0)
1544 shdr
->sh_flags
|= SHF_EXCLUDE
;
1546 if ((asect
->flags
& SEC_SORT_ENTRIES
) != 0)
1547 shdr
->sh_type
= SHT_ORDERED
;
1552 /* Create a special linker section */
1553 static elf_linker_section_t
*
1554 ppc_elf_create_linker_section (abfd
, info
, which
)
1556 struct bfd_link_info
*info
;
1557 enum elf_linker_section_enum which
;
1559 bfd
*dynobj
= elf_hash_table (info
)->dynobj
;
1560 elf_linker_section_t
*lsect
;
1562 /* Record the first bfd section that needs the special section */
1564 dynobj
= elf_hash_table (info
)->dynobj
= abfd
;
1566 /* If this is the first time, create the section */
1567 lsect
= elf_linker_section (dynobj
, which
);
1570 elf_linker_section_t defaults
;
1571 static elf_linker_section_t zero_section
;
1573 defaults
= zero_section
;
1574 defaults
.which
= which
;
1575 defaults
.hole_written_p
= false;
1576 defaults
.alignment
= 2;
1578 /* Both of these sections are (technically) created by the user
1579 putting data in them, so they shouldn't be marked
1582 The linker creates them so it has somewhere to attach their
1583 respective symbols. In fact, if they were empty it would
1584 be OK to leave the symbol set to 0 (or any random number), because
1585 the appropriate register should never be used. */
1586 defaults
.flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
1592 (*_bfd_error_handler
) (_("%s: Unknown special linker type %d"),
1593 bfd_get_filename (abfd
),
1596 bfd_set_error (bfd_error_bad_value
);
1597 return (elf_linker_section_t
*) 0;
1599 case LINKER_SECTION_SDATA
: /* .sdata/.sbss section */
1600 defaults
.name
= ".sdata";
1601 defaults
.rel_name
= ".rela.sdata";
1602 defaults
.bss_name
= ".sbss";
1603 defaults
.sym_name
= "_SDA_BASE_";
1604 defaults
.sym_offset
= 32768;
1607 case LINKER_SECTION_SDATA2
: /* .sdata2/.sbss2 section */
1608 defaults
.name
= ".sdata2";
1609 defaults
.rel_name
= ".rela.sdata2";
1610 defaults
.bss_name
= ".sbss2";
1611 defaults
.sym_name
= "_SDA2_BASE_";
1612 defaults
.sym_offset
= 32768;
1613 defaults
.flags
|= SEC_READONLY
;
1617 lsect
= _bfd_elf_create_linker_section (abfd
, info
, which
, &defaults
);
1623 /* If we have a non-zero sized .sbss2 or .PPC.EMB.sbss0 sections, we
1624 need to bump up the number of section headers. */
1627 ppc_elf_additional_program_headers (abfd
)
1635 s
= bfd_get_section_by_name (abfd
, ".interp");
1639 s
= bfd_get_section_by_name (abfd
, ".sbss2");
1640 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0 && s
->_raw_size
> 0)
1643 s
= bfd_get_section_by_name (abfd
, ".PPC.EMB.sbss0");
1644 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0 && s
->_raw_size
> 0)
1650 /* Modify the segment map if needed. */
1653 ppc_elf_modify_segment_map (abfd
)
1654 bfd
*abfd ATTRIBUTE_UNUSED
;
1659 /* The powerpc .got has a blrl instruction in it. Mark it executable. */
1662 ppc_elf_create_got (abfd
, info
)
1664 struct bfd_link_info
*info
;
1666 register asection
*s
;
1669 if (!_bfd_elf_create_got_section (abfd
, info
))
1672 s
= bfd_get_section_by_name (abfd
, ".got");
1676 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_CODE
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
1677 | SEC_LINKER_CREATED
);
1678 if (!bfd_set_section_flags (abfd
, s
, flags
))
1683 /* We have to create .dynsbss and .rela.sbss here so that they get mapped
1684 to output sections (just like _bfd_elf_create_dynamic_sections has
1685 to create .dynbss and .rela.bss). */
1688 ppc_elf_create_dynamic_sections (abfd
, info
)
1690 struct bfd_link_info
*info
;
1692 register asection
*s
;
1695 if (!ppc_elf_create_got (abfd
, info
))
1698 if (!_bfd_elf_create_dynamic_sections (abfd
, info
))
1701 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
1702 | SEC_LINKER_CREATED
);
1704 s
= bfd_make_section (abfd
, ".dynsbss");
1706 || ! bfd_set_section_flags (abfd
, s
, SEC_ALLOC
))
1711 s
= bfd_make_section (abfd
, ".rela.sbss");
1713 || ! bfd_set_section_flags (abfd
, s
, flags
| SEC_READONLY
)
1714 || ! bfd_set_section_alignment (abfd
, s
, 2))
1718 s
= bfd_get_section_by_name (abfd
, ".plt");
1722 flags
= SEC_ALLOC
| SEC_CODE
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
;
1723 return bfd_set_section_flags (abfd
, s
, flags
);
1726 /* Adjust a symbol defined by a dynamic object and referenced by a
1727 regular object. The current definition is in some section of the
1728 dynamic object, but we're not including those sections. We have to
1729 change the definition to something the rest of the link can
1733 ppc_elf_adjust_dynamic_symbol (info
, h
)
1734 struct bfd_link_info
*info
;
1735 struct elf_link_hash_entry
*h
;
1737 bfd
*dynobj
= elf_hash_table (info
)->dynobj
;
1739 unsigned int power_of_two
;
1743 fprintf (stderr
, "ppc_elf_adjust_dynamic_symbol called for %s\n", h
->root
.root
.string
);
1746 /* Make sure we know what is going on here. */
1747 BFD_ASSERT (dynobj
!= NULL
1748 && ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
)
1749 || h
->weakdef
!= NULL
1750 || ((h
->elf_link_hash_flags
1751 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0
1752 && (h
->elf_link_hash_flags
1753 & ELF_LINK_HASH_REF_REGULAR
) != 0
1754 && (h
->elf_link_hash_flags
1755 & ELF_LINK_HASH_DEF_REGULAR
) == 0)));
1757 /* If this is a function, put it in the procedure linkage table. We
1758 will fill in the contents of the procedure linkage table later,
1759 when we know the address of the .got section. */
1760 if (h
->type
== STT_FUNC
1761 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
1763 if (! elf_hash_table (info
)->dynamic_sections_created
1764 || SYMBOL_CALLS_LOCAL (info
, h
)
1765 || (info
->shared
&& h
->plt
.refcount
<= 0))
1767 /* A PLT entry is not required/allowed when:
1769 1. We are not using ld.so; because then the PLT entry
1770 can't be set up, so we can't use one.
1772 2. We know for certain that a call to this symbol
1773 will go to this object.
1775 3. GC has rendered the entry unused.
1776 Note, however, that in an executable all references to the
1777 symbol go to the PLT, so we can't turn it off in that case.
1778 ??? The correct thing to do here is to reference count
1779 all uses of the symbol, not just those to the GOT or PLT. */
1780 h
->plt
.offset
= (bfd_vma
) -1;
1781 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
1785 /* Make sure this symbol is output as a dynamic symbol. */
1786 if (h
->dynindx
== -1)
1788 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
1791 BFD_ASSERT (h
->dynindx
!= -1);
1793 s
= bfd_get_section_by_name (dynobj
, ".plt");
1794 BFD_ASSERT (s
!= NULL
);
1796 /* If this is the first .plt entry, make room for the special
1798 if (s
->_raw_size
== 0)
1799 s
->_raw_size
+= PLT_INITIAL_ENTRY_SIZE
;
1801 /* The PowerPC PLT is actually composed of two parts, the first part
1802 is 2 words (for a load and a jump), and then there is a remaining
1803 word available at the end. */
1804 plt_offset
= (PLT_INITIAL_ENTRY_SIZE
1806 * ((s
->_raw_size
- PLT_INITIAL_ENTRY_SIZE
)
1807 / PLT_ENTRY_SIZE
)));
1809 /* If this symbol is not defined in a regular file, and we are
1810 not generating a shared library, then set the symbol to this
1811 location in the .plt. This is required to make function
1812 pointers compare as equal between the normal executable and
1813 the shared library. */
1815 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
1817 h
->root
.u
.def
.section
= s
;
1818 h
->root
.u
.def
.value
= plt_offset
;
1821 h
->plt
.offset
= plt_offset
;
1823 /* Make room for this entry. After the 8192nd entry, room
1824 for two entries is allocated. */
1825 if ((s
->_raw_size
- PLT_INITIAL_ENTRY_SIZE
) / PLT_ENTRY_SIZE
1826 >= PLT_NUM_SINGLE_ENTRIES
)
1827 s
->_raw_size
+= 2 * PLT_ENTRY_SIZE
;
1829 s
->_raw_size
+= PLT_ENTRY_SIZE
;
1831 /* We also need to make an entry in the .rela.plt section. */
1832 s
= bfd_get_section_by_name (dynobj
, ".rela.plt");
1833 BFD_ASSERT (s
!= NULL
);
1834 s
->_raw_size
+= sizeof (Elf32_External_Rela
);
1839 h
->plt
.offset
= (bfd_vma
) -1;
1841 /* If this is a weak symbol, and there is a real definition, the
1842 processor independent code will have arranged for us to see the
1843 real definition first, and we can just use the same value. */
1844 if (h
->weakdef
!= NULL
)
1846 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
1847 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
1848 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
1849 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
1853 /* This is a reference to a symbol defined by a dynamic object which
1854 is not a function. */
1856 /* If we are creating a shared library, we must presume that the
1857 only references to the symbol are via the global offset table.
1858 For such cases we need not do anything here; the relocations will
1859 be handled correctly by relocate_section. */
1863 /* We must allocate the symbol in our .dynbss section, which will
1864 become part of the .bss section of the executable. There will be
1865 an entry for this symbol in the .dynsym section. The dynamic
1866 object will contain position independent code, so all references
1867 from the dynamic object to this symbol will go through the global
1868 offset table. The dynamic linker will use the .dynsym entry to
1869 determine the address it must put in the global offset table, so
1870 both the dynamic object and the regular object will refer to the
1871 same memory location for the variable.
1873 Of course, if the symbol is sufficiently small, we must instead
1874 allocate it in .sbss. FIXME: It would be better to do this if and
1875 only if there were actually SDAREL relocs for that symbol. */
1877 if (h
->size
<= elf_gp_size (dynobj
))
1878 s
= bfd_get_section_by_name (dynobj
, ".dynsbss");
1880 s
= bfd_get_section_by_name (dynobj
, ".dynbss");
1881 BFD_ASSERT (s
!= NULL
);
1883 /* We must generate a R_PPC_COPY reloc to tell the dynamic linker to
1884 copy the initial value out of the dynamic object and into the
1885 runtime process image. We need to remember the offset into the
1886 .rela.bss section we are going to use. */
1887 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
1891 if (h
->size
<= elf_gp_size (dynobj
))
1892 srel
= bfd_get_section_by_name (dynobj
, ".rela.sbss");
1894 srel
= bfd_get_section_by_name (dynobj
, ".rela.bss");
1895 BFD_ASSERT (srel
!= NULL
);
1896 srel
->_raw_size
+= sizeof (Elf32_External_Rela
);
1897 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_COPY
;
1900 /* We need to figure out the alignment required for this symbol. I
1901 have no idea how ELF linkers handle this. */
1902 power_of_two
= bfd_log2 (h
->size
);
1903 if (power_of_two
> 4)
1906 /* Apply the required alignment. */
1907 s
->_raw_size
= BFD_ALIGN (s
->_raw_size
,
1908 (bfd_size_type
) (1 << power_of_two
));
1909 if (power_of_two
> bfd_get_section_alignment (dynobj
, s
))
1911 if (! bfd_set_section_alignment (dynobj
, s
, power_of_two
))
1915 /* Define the symbol as being at this point in the section. */
1916 h
->root
.u
.def
.section
= s
;
1917 h
->root
.u
.def
.value
= s
->_raw_size
;
1919 /* Increment the section size to make room for the symbol. */
1920 s
->_raw_size
+= h
->size
;
1925 /* Set the sizes of the dynamic sections. */
1928 ppc_elf_size_dynamic_sections (output_bfd
, info
)
1929 bfd
*output_bfd ATTRIBUTE_UNUSED
;
1930 struct bfd_link_info
*info
;
1938 fprintf (stderr
, "ppc_elf_size_dynamic_sections called\n");
1941 dynobj
= elf_hash_table (info
)->dynobj
;
1942 BFD_ASSERT (dynobj
!= NULL
);
1944 if (elf_hash_table (info
)->dynamic_sections_created
)
1946 /* Set the contents of the .interp section to the interpreter. */
1949 s
= bfd_get_section_by_name (dynobj
, ".interp");
1950 BFD_ASSERT (s
!= NULL
);
1951 s
->_raw_size
= sizeof ELF_DYNAMIC_INTERPRETER
;
1952 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
1957 /* We may have created entries in the .rela.got, .rela.sdata, and
1958 .rela.sdata2 sections. However, if we are not creating the
1959 dynamic sections, we will not actually use these entries. Reset
1960 the size of .rela.got, et al, which will cause it to get
1961 stripped from the output file below. */
1962 static char *rela_sections
[] = { ".rela.got", ".rela.sdata",
1963 ".rela.sdata2", ".rela.sbss",
1967 for (p
= rela_sections
; *p
!= (char *) 0; p
++)
1969 s
= bfd_get_section_by_name (dynobj
, *p
);
1975 /* The check_relocs and adjust_dynamic_symbol entry points have
1976 determined the sizes of the various dynamic sections. Allocate
1980 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
1985 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
1988 /* It's OK to base decisions on the section name, because none
1989 of the dynobj section names depend upon the input files. */
1990 name
= bfd_get_section_name (dynobj
, s
);
1994 if (strcmp (name
, ".plt") == 0)
1996 if (s
->_raw_size
== 0)
1998 /* Strip this section if we don't need it; see the
2004 /* Remember whether there is a PLT. */
2008 else if (strncmp (name
, ".rela", 5) == 0)
2010 if (s
->_raw_size
== 0)
2012 /* If we don't need this section, strip it from the
2013 output file. This is mostly to handle .rela.bss and
2014 .rela.plt. We must create both sections in
2015 create_dynamic_sections, because they must be created
2016 before the linker maps input sections to output
2017 sections. The linker does that before
2018 adjust_dynamic_symbol is called, and it is that
2019 function which decides whether anything needs to go
2020 into these sections. */
2025 /* Remember whether there are any relocation sections. */
2028 /* We use the reloc_count field as a counter if we need
2029 to copy relocs into the output file. */
2033 else if (strcmp (name
, ".got") != 0
2034 && strcmp (name
, ".sdata") != 0
2035 && strcmp (name
, ".sdata2") != 0)
2037 /* It's not one of our sections, so don't allocate space. */
2043 _bfd_strip_section_from_output (info
, s
);
2047 /* Allocate memory for the section contents. */
2048 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->_raw_size
);
2049 if (s
->contents
== NULL
&& s
->_raw_size
!= 0)
2053 if (elf_hash_table (info
)->dynamic_sections_created
)
2055 /* Add some entries to the .dynamic section. We fill in the
2056 values later, in ppc_elf_finish_dynamic_sections, but we
2057 must add the entries now so that we get the correct size for
2058 the .dynamic section. The DT_DEBUG entry is filled in by the
2059 dynamic linker and used by the debugger. */
2060 #define add_dynamic_entry(TAG, VAL) \
2061 bfd_elf32_add_dynamic_entry (info, (bfd_vma) (TAG), (bfd_vma) (VAL))
2065 if (!add_dynamic_entry (DT_DEBUG
, 0))
2071 if (!add_dynamic_entry (DT_PLTGOT
, 0)
2072 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
2073 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
2074 || !add_dynamic_entry (DT_JMPREL
, 0))
2080 if (!add_dynamic_entry (DT_RELA
, 0)
2081 || !add_dynamic_entry (DT_RELASZ
, 0)
2082 || !add_dynamic_entry (DT_RELAENT
, sizeof (Elf32_External_Rela
)))
2086 if ((info
->flags
& DF_TEXTREL
) != 0)
2088 if (!add_dynamic_entry (DT_TEXTREL
, 0))
2090 info
->flags
|= DF_TEXTREL
;
2093 #undef add_dynamic_entry
2098 /* Look through the relocs for a section during the first phase, and
2099 allocate space in the global offset table or procedure linkage
2103 ppc_elf_check_relocs (abfd
, info
, sec
, relocs
)
2105 struct bfd_link_info
*info
;
2107 const Elf_Internal_Rela
*relocs
;
2110 Elf_Internal_Shdr
*symtab_hdr
;
2111 struct elf_link_hash_entry
**sym_hashes
, **sym_hashes_end
;
2112 const Elf_Internal_Rela
*rel
;
2113 const Elf_Internal_Rela
*rel_end
;
2114 bfd_signed_vma
*local_got_refcounts
;
2115 elf_linker_section_t
*sdata
;
2116 elf_linker_section_t
*sdata2
;
2118 asection
*sgot
= NULL
;
2119 asection
*srelgot
= NULL
;
2121 if (info
->relocateable
)
2125 fprintf (stderr
, "ppc_elf_check_relocs called for section %s in %s\n",
2126 bfd_get_section_name (abfd
, sec
),
2127 bfd_archive_filename (abfd
));
2130 /* Create the linker generated sections all the time so that the
2131 special symbols are created. */
2133 if ((sdata
= elf_linker_section (abfd
, LINKER_SECTION_SDATA
)) == NULL
)
2135 sdata
= ppc_elf_create_linker_section (abfd
, info
, LINKER_SECTION_SDATA
);
2140 if ((sdata2
= elf_linker_section (abfd
, LINKER_SECTION_SDATA2
)) == NULL
)
2142 sdata2
= ppc_elf_create_linker_section (abfd
, info
, LINKER_SECTION_SDATA2
);
2147 dynobj
= elf_hash_table (info
)->dynobj
;
2148 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
2149 local_got_refcounts
= elf_local_got_refcounts (abfd
);
2151 sym_hashes
= elf_sym_hashes (abfd
);
2152 sym_hashes_end
= sym_hashes
+ symtab_hdr
->sh_size
/sizeof (Elf32_External_Sym
);
2153 if (!elf_bad_symtab (abfd
))
2154 sym_hashes_end
-= symtab_hdr
->sh_info
;
2158 rel_end
= relocs
+ sec
->reloc_count
;
2159 for (rel
= relocs
; rel
< rel_end
; rel
++)
2161 unsigned long r_symndx
;
2162 struct elf_link_hash_entry
*h
;
2164 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2165 if (r_symndx
< symtab_hdr
->sh_info
)
2168 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2170 /* If a relocation refers to _GLOBAL_OFFSET_TABLE_, create the .got.
2171 This shows up in particular in an R_PPC_ADDR32 in the eabi
2173 if (h
&& strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
2178 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
2179 sgot
= ppc_elf_create_got (dynobj
, info
);
2185 switch (ELF32_R_TYPE (rel
->r_info
))
2187 /* GOT16 relocations */
2189 case R_PPC_GOT16_LO
:
2190 case R_PPC_GOT16_HI
:
2191 case R_PPC_GOT16_HA
:
2192 /* This symbol requires a global offset table entry. */
2197 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
2198 sgot
= ppc_elf_create_got (dynobj
, info
);
2204 && (h
!= NULL
|| info
->shared
))
2206 srelgot
= bfd_get_section_by_name (dynobj
, ".rela.got");
2207 if (srelgot
== NULL
)
2209 srelgot
= bfd_make_section (dynobj
, ".rela.got");
2211 || ! bfd_set_section_flags (dynobj
, srelgot
,
2216 | SEC_LINKER_CREATED
2218 || ! bfd_set_section_alignment (dynobj
, srelgot
, 2))
2225 if (h
->got
.refcount
== 0)
2227 /* Make sure this symbol is output as a dynamic symbol. */
2228 if (h
->dynindx
== -1)
2229 if (!bfd_elf32_link_record_dynamic_symbol (info
, h
))
2232 /* Allocate space in the .got. */
2233 sgot
->_raw_size
+= 4;
2234 /* Allocate relocation space. */
2235 srelgot
->_raw_size
+= sizeof (Elf32_External_Rela
);
2241 /* This is a global offset table entry for a local symbol. */
2242 if (local_got_refcounts
== NULL
)
2246 size
= symtab_hdr
->sh_info
;
2247 size
*= sizeof (bfd_signed_vma
);
2249 = (bfd_signed_vma
*) bfd_zalloc (abfd
, size
);
2250 if (local_got_refcounts
== NULL
)
2252 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
2254 if (local_got_refcounts
[r_symndx
] == 0)
2256 sgot
->_raw_size
+= 4;
2258 /* If we are generating a shared object, we need to
2259 output a R_PPC_RELATIVE reloc so that the
2260 dynamic linker can adjust this GOT entry. */
2262 srelgot
->_raw_size
+= sizeof (Elf32_External_Rela
);
2264 local_got_refcounts
[r_symndx
]++;
2268 /* Indirect .sdata relocation */
2269 case R_PPC_EMB_SDAI16
:
2272 ((*_bfd_error_handler
)
2273 (_("%s: relocation %s cannot be used when making a shared object"),
2274 bfd_archive_filename (abfd
), "R_PPC_EMB_SDAI16"));
2278 if (srelgot
== NULL
&& (h
!= NULL
|| info
->shared
))
2280 srelgot
= bfd_get_section_by_name (dynobj
, ".rela.got");
2281 if (srelgot
== NULL
)
2283 srelgot
= bfd_make_section (dynobj
, ".rela.got");
2285 || ! bfd_set_section_flags (dynobj
, srelgot
,
2290 | SEC_LINKER_CREATED
2292 || ! bfd_set_section_alignment (dynobj
, srelgot
, 2))
2297 if (!bfd_elf32_create_pointer_linker_section (abfd
, info
, sdata
, h
, rel
))
2302 /* Indirect .sdata2 relocation */
2303 case R_PPC_EMB_SDA2I16
:
2306 ((*_bfd_error_handler
)
2307 (_("%s: relocation %s cannot be used when making a shared object"),
2308 bfd_archive_filename (abfd
), "R_PPC_EMB_SDA2I16"));
2312 if (srelgot
== NULL
&& (h
!= NULL
|| info
->shared
))
2314 srelgot
= bfd_get_section_by_name (dynobj
, ".rela.got");
2315 if (srelgot
== NULL
)
2317 srelgot
= bfd_make_section (dynobj
, ".rela.got");
2319 || ! bfd_set_section_flags (dynobj
, srelgot
,
2324 | SEC_LINKER_CREATED
2326 || ! bfd_set_section_alignment (dynobj
, srelgot
, 2))
2331 if (!bfd_elf32_create_pointer_linker_section (abfd
, info
, sdata2
, h
, rel
))
2336 case R_PPC_SDAREL16
:
2337 case R_PPC_EMB_SDA2REL
:
2338 case R_PPC_EMB_SDA21
:
2341 ((*_bfd_error_handler
)
2342 (_("%s: relocation %s cannot be used when making a shared object"),
2343 bfd_archive_filename (abfd
),
2344 ppc_elf_howto_table
[(int) ELF32_R_TYPE (rel
->r_info
)]->name
));
2350 case R_PPC_PLTREL24
:
2351 case R_PPC_PLT16_LO
:
2352 case R_PPC_PLT16_HI
:
2353 case R_PPC_PLT16_HA
:
2355 fprintf (stderr
, "Reloc requires a PLT entry\n");
2357 /* This symbol requires a procedure linkage table entry. We
2358 actually build the entry in adjust_dynamic_symbol,
2359 because this might be a case of linking PIC code without
2360 linking in any dynamic objects, in which case we don't
2361 need to generate a procedure linkage table after all. */
2365 /* It does not make sense to have a procedure linkage
2366 table entry for a local symbol. */
2367 bfd_set_error (bfd_error_bad_value
);
2371 /* Make sure this symbol is output as a dynamic symbol. */
2372 if (h
->dynindx
== -1)
2374 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
2377 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
2381 /* The following relocations don't need to propagate the
2382 relocation if linking a shared object since they are
2383 section relative. */
2385 case R_PPC_SECTOFF_LO
:
2386 case R_PPC_SECTOFF_HI
:
2387 case R_PPC_SECTOFF_HA
:
2390 /* This refers only to functions defined in the shared library */
2391 case R_PPC_LOCAL24PC
:
2394 /* This relocation describes the C++ object vtable hierarchy.
2395 Reconstruct it for later use during GC. */
2396 case R_PPC_GNU_VTINHERIT
:
2397 if (!_bfd_elf32_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
2401 /* This relocation describes which C++ vtable entries are actually
2402 used. Record for later use during GC. */
2403 case R_PPC_GNU_VTENTRY
:
2404 if (!_bfd_elf32_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
2408 /* When creating a shared object, we must copy these
2409 relocs into the output file. We create a reloc
2410 section in dynobj and make room for the reloc. */
2413 case R_PPC_REL14_BRTAKEN
:
2414 case R_PPC_REL14_BRNTAKEN
:
2417 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0
2418 || SYMBOL_REFERENCES_LOCAL (info
, h
))
2426 fprintf (stderr
, "ppc_elf_check_relocs need to create relocation for %s\n",
2427 (h
&& h
->root
.root
.string
) ? h
->root
.root
.string
: "<unknown>");
2433 name
= (bfd_elf_string_from_elf_section
2435 elf_elfheader (abfd
)->e_shstrndx
,
2436 elf_section_data (sec
)->rel_hdr
.sh_name
));
2440 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
2441 && strcmp (bfd_get_section_name (abfd
, sec
),
2444 sreloc
= bfd_get_section_by_name (dynobj
, name
);
2449 sreloc
= bfd_make_section (dynobj
, name
);
2450 flags
= (SEC_HAS_CONTENTS
| SEC_READONLY
2451 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
2452 if ((sec
->flags
& SEC_ALLOC
) != 0)
2453 flags
|= SEC_ALLOC
| SEC_LOAD
;
2455 || ! bfd_set_section_flags (dynobj
, sreloc
, flags
)
2456 || ! bfd_set_section_alignment (dynobj
, sreloc
, 2))
2459 if (sec
->flags
& SEC_READONLY
)
2460 info
->flags
|= DF_TEXTREL
;
2463 sreloc
->_raw_size
+= sizeof (Elf32_External_Rela
);
2465 /* FIXME: We should here do what the m68k and i386
2466 backends do: if the reloc is pc-relative, record it
2467 in case it turns out that the reloc is unnecessary
2468 because the symbol is forced local by versioning or
2469 we are linking with -Bdynamic. Fortunately this
2470 case is not frequent. */
2480 /* Return the section that should be marked against GC for a given
2484 ppc_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
)
2486 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
2487 Elf_Internal_Rela
*rel
;
2488 struct elf_link_hash_entry
*h
;
2489 Elf_Internal_Sym
*sym
;
2493 switch (ELF32_R_TYPE (rel
->r_info
))
2495 case R_PPC_GNU_VTINHERIT
:
2496 case R_PPC_GNU_VTENTRY
:
2500 switch (h
->root
.type
)
2502 case bfd_link_hash_defined
:
2503 case bfd_link_hash_defweak
:
2504 return h
->root
.u
.def
.section
;
2506 case bfd_link_hash_common
:
2507 return h
->root
.u
.c
.p
->section
;
2515 return bfd_section_from_elf_index (sec
->owner
, sym
->st_shndx
);
2520 /* Update the got entry reference counts for the section being removed. */
2523 ppc_elf_gc_sweep_hook (abfd
, info
, sec
, relocs
)
2525 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
2527 const Elf_Internal_Rela
*relocs
;
2529 Elf_Internal_Shdr
*symtab_hdr
;
2530 struct elf_link_hash_entry
**sym_hashes
;
2531 bfd_signed_vma
*local_got_refcounts
;
2532 const Elf_Internal_Rela
*rel
, *relend
;
2533 unsigned long r_symndx
;
2534 struct elf_link_hash_entry
*h
;
2536 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
2537 sym_hashes
= elf_sym_hashes (abfd
);
2538 local_got_refcounts
= elf_local_got_refcounts (abfd
);
2540 relend
= relocs
+ sec
->reloc_count
;
2541 for (rel
= relocs
; rel
< relend
; rel
++)
2542 switch (ELF32_R_TYPE (rel
->r_info
))
2545 case R_PPC_GOT16_LO
:
2546 case R_PPC_GOT16_HI
:
2547 case R_PPC_GOT16_HA
:
2548 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2549 if (r_symndx
>= symtab_hdr
->sh_info
)
2551 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2552 if (h
->got
.refcount
> 0)
2555 else if (local_got_refcounts
!= NULL
)
2557 if (local_got_refcounts
[r_symndx
] > 0)
2558 local_got_refcounts
[r_symndx
]--;
2563 case R_PPC_PLTREL24
:
2564 case R_PPC_PLT16_LO
:
2565 case R_PPC_PLT16_HI
:
2566 case R_PPC_PLT16_HA
:
2567 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2568 if (r_symndx
>= symtab_hdr
->sh_info
)
2570 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2571 if (h
->plt
.refcount
> 0)
2583 /* Hook called by the linker routine which adds symbols from an object
2584 file. We use it to put .comm items in .sbss, and not .bss. */
2587 ppc_elf_add_symbol_hook (abfd
, info
, sym
, namep
, flagsp
, secp
, valp
)
2589 struct bfd_link_info
*info
;
2590 const Elf_Internal_Sym
*sym
;
2591 const char **namep ATTRIBUTE_UNUSED
;
2592 flagword
*flagsp ATTRIBUTE_UNUSED
;
2596 if (sym
->st_shndx
== SHN_COMMON
2597 && !info
->relocateable
2598 && sym
->st_size
<= elf_gp_size (abfd
)
2599 && info
->hash
->creator
->flavour
== bfd_target_elf_flavour
)
2601 /* Common symbols less than or equal to -G nn bytes are automatically
2603 elf_linker_section_t
*sdata
2604 = ppc_elf_create_linker_section (abfd
, info
, LINKER_SECTION_SDATA
);
2606 if (!sdata
->bss_section
)
2610 /* We don't go through bfd_make_section, because we don't
2611 want to attach this common section to DYNOBJ. The linker
2612 will move the symbols to the appropriate output section
2613 when it defines common symbols. */
2614 amt
= sizeof (asection
);
2615 sdata
->bss_section
= (asection
*) bfd_zalloc (abfd
, amt
);
2616 if (sdata
->bss_section
== NULL
)
2618 sdata
->bss_section
->name
= sdata
->bss_name
;
2619 sdata
->bss_section
->flags
= SEC_IS_COMMON
;
2620 sdata
->bss_section
->output_section
= sdata
->bss_section
;
2621 amt
= sizeof (asymbol
);
2622 sdata
->bss_section
->symbol
= (asymbol
*) bfd_zalloc (abfd
, amt
);
2623 amt
= sizeof (asymbol
*);
2624 sdata
->bss_section
->symbol_ptr_ptr
=
2625 (asymbol
**) bfd_zalloc (abfd
, amt
);
2626 if (sdata
->bss_section
->symbol
== NULL
2627 || sdata
->bss_section
->symbol_ptr_ptr
== NULL
)
2629 sdata
->bss_section
->symbol
->name
= sdata
->bss_name
;
2630 sdata
->bss_section
->symbol
->flags
= BSF_SECTION_SYM
;
2631 sdata
->bss_section
->symbol
->section
= sdata
->bss_section
;
2632 *sdata
->bss_section
->symbol_ptr_ptr
= sdata
->bss_section
->symbol
;
2635 *secp
= sdata
->bss_section
;
2636 *valp
= sym
->st_size
;
2642 /* Finish up dynamic symbol handling. We set the contents of various
2643 dynamic sections here. */
2646 ppc_elf_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
2648 struct bfd_link_info
*info
;
2649 struct elf_link_hash_entry
*h
;
2650 Elf_Internal_Sym
*sym
;
2655 fprintf (stderr
, "ppc_elf_finish_dynamic_symbol called for %s",
2656 h
->root
.root
.string
);
2659 dynobj
= elf_hash_table (info
)->dynobj
;
2660 BFD_ASSERT (dynobj
!= NULL
);
2662 if (h
->plt
.offset
!= (bfd_vma
) -1)
2666 Elf_Internal_Rela rela
;
2668 bfd_vma reloc_index
;
2671 fprintf (stderr
, ", plt_offset = %d", h
->plt
.offset
);
2674 /* This symbol has an entry in the procedure linkage table. Set
2677 BFD_ASSERT (h
->dynindx
!= -1);
2679 splt
= bfd_get_section_by_name (dynobj
, ".plt");
2680 srela
= bfd_get_section_by_name (dynobj
, ".rela.plt");
2681 BFD_ASSERT (splt
!= NULL
&& srela
!= NULL
);
2683 /* We don't need to fill in the .plt. The ppc dynamic linker
2686 /* Fill in the entry in the .rela.plt section. */
2687 rela
.r_offset
= (splt
->output_section
->vma
2688 + splt
->output_offset
2690 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_PPC_JMP_SLOT
);
2693 reloc_index
= (h
->plt
.offset
- PLT_INITIAL_ENTRY_SIZE
) / PLT_SLOT_SIZE
;
2694 if (reloc_index
> PLT_NUM_SINGLE_ENTRIES
)
2695 reloc_index
-= (reloc_index
- PLT_NUM_SINGLE_ENTRIES
) / 2;
2696 loc
= srela
->contents
+ reloc_index
* sizeof (Elf32_External_Rela
);
2697 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
2699 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
2701 /* Mark the symbol as undefined, rather than as defined in
2702 the .plt section. Leave the value alone. */
2703 sym
->st_shndx
= SHN_UNDEF
;
2704 /* If the symbol is weak, we do need to clear the value.
2705 Otherwise, the PLT entry would provide a definition for
2706 the symbol even if the symbol wasn't defined anywhere,
2707 and so the symbol would never be NULL. */
2708 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_REF_REGULAR_NONWEAK
)
2714 if (h
->got
.offset
!= (bfd_vma
) -1)
2718 Elf_Internal_Rela rela
;
2721 /* This symbol has an entry in the global offset table. Set it
2724 sgot
= bfd_get_section_by_name (dynobj
, ".got");
2725 srela
= bfd_get_section_by_name (dynobj
, ".rela.got");
2726 BFD_ASSERT (sgot
!= NULL
&& srela
!= NULL
);
2728 rela
.r_offset
= (sgot
->output_section
->vma
2729 + sgot
->output_offset
2730 + (h
->got
.offset
&~ (bfd_vma
) 1));
2732 /* If this is a -Bsymbolic link, and the symbol is defined
2733 locally, we just want to emit a RELATIVE reloc. The entry in
2734 the global offset table will already have been initialized in
2735 the relocate_section function. */
2737 && SYMBOL_REFERENCES_LOCAL (info
, h
))
2739 rela
.r_info
= ELF32_R_INFO (0, R_PPC_RELATIVE
);
2740 rela
.r_addend
= (h
->root
.u
.def
.value
2741 + h
->root
.u
.def
.section
->output_section
->vma
2742 + h
->root
.u
.def
.section
->output_offset
);
2746 BFD_ASSERT ((h
->got
.offset
& 1) == 0);
2747 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_PPC_GLOB_DAT
);
2751 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ h
->got
.offset
);
2752 loc
= srela
->contents
;
2753 loc
+= srela
->reloc_count
++ * sizeof (Elf32_External_Rela
);
2754 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
2757 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_COPY
) != 0)
2760 Elf_Internal_Rela rela
;
2763 /* This symbols needs a copy reloc. Set it up. */
2766 fprintf (stderr
, ", copy");
2769 BFD_ASSERT (h
->dynindx
!= -1);
2771 if (h
->size
<= elf_gp_size (dynobj
))
2772 s
= bfd_get_section_by_name (h
->root
.u
.def
.section
->owner
,
2775 s
= bfd_get_section_by_name (h
->root
.u
.def
.section
->owner
,
2777 BFD_ASSERT (s
!= NULL
);
2779 rela
.r_offset
= (h
->root
.u
.def
.value
2780 + h
->root
.u
.def
.section
->output_section
->vma
2781 + h
->root
.u
.def
.section
->output_offset
);
2782 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_PPC_COPY
);
2784 loc
= s
->contents
+ s
->reloc_count
++ * sizeof (Elf32_External_Rela
);
2785 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
2789 fprintf (stderr
, "\n");
2792 /* Mark some specially defined symbols as absolute. */
2793 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
2794 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0
2795 || strcmp (h
->root
.root
.string
, "_PROCEDURE_LINKAGE_TABLE_") == 0)
2796 sym
->st_shndx
= SHN_ABS
;
2801 /* Finish up the dynamic sections. */
2804 ppc_elf_finish_dynamic_sections (output_bfd
, info
)
2806 struct bfd_link_info
*info
;
2809 bfd
*dynobj
= elf_hash_table (info
)->dynobj
;
2810 asection
*sgot
= bfd_get_section_by_name (dynobj
, ".got");
2813 fprintf (stderr
, "ppc_elf_finish_dynamic_sections called\n");
2816 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
2818 if (elf_hash_table (info
)->dynamic_sections_created
)
2821 Elf32_External_Dyn
*dyncon
, *dynconend
;
2823 splt
= bfd_get_section_by_name (dynobj
, ".plt");
2824 BFD_ASSERT (splt
!= NULL
&& sdyn
!= NULL
);
2826 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
2827 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
2828 for (; dyncon
< dynconend
; dyncon
++)
2830 Elf_Internal_Dyn dyn
;
2834 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
2838 case DT_PLTGOT
: name
= ".plt"; size
= false; break;
2839 case DT_PLTRELSZ
: name
= ".rela.plt"; size
= true; break;
2840 case DT_JMPREL
: name
= ".rela.plt"; size
= false; break;
2841 default: name
= NULL
; size
= false; break;
2848 s
= bfd_get_section_by_name (output_bfd
, name
);
2854 dyn
.d_un
.d_ptr
= s
->vma
;
2857 if (s
->_cooked_size
!= 0)
2858 dyn
.d_un
.d_val
= s
->_cooked_size
;
2860 dyn
.d_un
.d_val
= s
->_raw_size
;
2863 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
2868 /* Add a blrl instruction at _GLOBAL_OFFSET_TABLE_-4 so that a function can
2869 easily find the address of the _GLOBAL_OFFSET_TABLE_. */
2872 unsigned char *contents
= sgot
->contents
;
2873 bfd_put_32 (output_bfd
, (bfd_vma
) 0x4e800021 /* blrl */, contents
);
2876 bfd_put_32 (output_bfd
, (bfd_vma
) 0, contents
+4);
2878 bfd_put_32 (output_bfd
,
2879 sdyn
->output_section
->vma
+ sdyn
->output_offset
,
2882 elf_section_data (sgot
->output_section
)->this_hdr
.sh_entsize
= 4;
2888 /* The RELOCATE_SECTION function is called by the ELF backend linker
2889 to handle the relocations for a section.
2891 The relocs are always passed as Rela structures; if the section
2892 actually uses Rel structures, the r_addend field will always be
2895 This function is responsible for adjust the section contents as
2896 necessary, and (if using Rela relocs and generating a
2897 relocateable output file) adjusting the reloc addend as
2900 This function does not have to worry about setting the reloc
2901 address or the reloc symbol index.
2903 LOCAL_SYMS is a pointer to the swapped in local symbols.
2905 LOCAL_SECTIONS is an array giving the section in the input file
2906 corresponding to the st_shndx field of each local symbol.
2908 The global hash table entry for the global symbols can be found
2909 via elf_sym_hashes (input_bfd).
2911 When generating relocateable output, this function must handle
2912 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
2913 going to be the section symbol corresponding to the output
2914 section, which means that the addend must be adjusted
2918 ppc_elf_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
2919 contents
, relocs
, local_syms
, local_sections
)
2921 struct bfd_link_info
*info
;
2923 asection
*input_section
;
2925 Elf_Internal_Rela
*relocs
;
2926 Elf_Internal_Sym
*local_syms
;
2927 asection
**local_sections
;
2929 Elf_Internal_Shdr
*symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
2930 struct elf_link_hash_entry
**sym_hashes
= elf_sym_hashes (input_bfd
);
2931 bfd
*dynobj
= elf_hash_table (info
)->dynobj
;
2932 elf_linker_section_t
*sdata
= (dynobj
) ? elf_linker_section (dynobj
, LINKER_SECTION_SDATA
) : NULL
;
2933 elf_linker_section_t
*sdata2
= (dynobj
) ? elf_linker_section (dynobj
, LINKER_SECTION_SDATA2
) : NULL
;
2934 Elf_Internal_Rela
*rel
= relocs
;
2935 Elf_Internal_Rela
*relend
= relocs
+ input_section
->reloc_count
;
2936 asection
*sreloc
= NULL
;
2939 bfd_vma
*local_got_offsets
;
2944 fprintf (stderr
, "ppc_elf_relocate_section called for %s section %s, %ld relocations%s\n",
2945 bfd_archive_filename (input_bfd
),
2946 bfd_section_name(input_bfd
, input_section
),
2947 (long) input_section
->reloc_count
,
2948 (info
->relocateable
) ? " (relocatable)" : "");
2951 if (info
->relocateable
)
2954 if (!ppc_elf_howto_table
[R_PPC_ADDR32
])
2955 /* Initialize howto table if needed. */
2956 ppc_elf_howto_init ();
2958 local_got_offsets
= elf_local_got_offsets (input_bfd
);
2963 splt
= bfd_get_section_by_name (dynobj
, ".plt");
2964 sgot
= bfd_get_section_by_name (dynobj
, ".got");
2967 for (; rel
< relend
; rel
++)
2969 enum elf_ppc_reloc_type r_type
= (enum elf_ppc_reloc_type
)ELF32_R_TYPE (rel
->r_info
);
2970 bfd_vma offset
= rel
->r_offset
;
2971 bfd_vma addend
= rel
->r_addend
;
2972 bfd_reloc_status_type r
= bfd_reloc_other
;
2973 Elf_Internal_Sym
*sym
= (Elf_Internal_Sym
*) 0;
2974 asection
*sec
= (asection
*) 0;
2975 struct elf_link_hash_entry
*h
= (struct elf_link_hash_entry
*) 0;
2976 const char *sym_name
= (const char *) 0;
2977 reloc_howto_type
*howto
;
2978 unsigned long r_symndx
;
2980 int will_become_local
;
2982 /* Unknown relocation handling */
2983 if ((unsigned) r_type
>= (unsigned) R_PPC_max
2984 || !ppc_elf_howto_table
[(int) r_type
])
2986 (*_bfd_error_handler
) (_("%s: unknown relocation type %d"),
2987 bfd_archive_filename (input_bfd
),
2990 bfd_set_error (bfd_error_bad_value
);
2995 howto
= ppc_elf_howto_table
[(int) r_type
];
2996 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2998 if (r_symndx
< symtab_hdr
->sh_info
)
3000 sym
= local_syms
+ r_symndx
;
3001 sec
= local_sections
[r_symndx
];
3002 sym_name
= "<local symbol>";
3004 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, sec
, rel
);
3005 addend
= rel
->r_addend
;
3006 /* Relocs to local symbols are always resolved. */
3007 will_become_local
= 1;
3011 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
3012 while (h
->root
.type
== bfd_link_hash_indirect
3013 || h
->root
.type
== bfd_link_hash_warning
)
3014 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
3015 sym_name
= h
->root
.root
.string
;
3017 /* Can this relocation be resolved immediately? */
3018 will_become_local
= SYMBOL_REFERENCES_LOCAL (info
, h
);
3020 if (h
->root
.type
== bfd_link_hash_defined
3021 || h
->root
.type
== bfd_link_hash_defweak
)
3023 sec
= h
->root
.u
.def
.section
;
3024 if (((r_type
== R_PPC_PLT32
3025 || r_type
== R_PPC_PLTREL24
)
3027 && h
->plt
.offset
!= (bfd_vma
) -1)
3028 || (r_type
== R_PPC_LOCAL24PC
3029 && sec
->output_section
== NULL
)
3030 || ((r_type
== R_PPC_GOT16
3031 || r_type
== R_PPC_GOT16_LO
3032 || r_type
== R_PPC_GOT16_HI
3033 || r_type
== R_PPC_GOT16_HA
)
3034 && elf_hash_table (info
)->dynamic_sections_created
3035 && (! info
->shared
|| ! will_become_local
))
3037 && ! will_become_local
3038 && ((input_section
->flags
& SEC_ALLOC
) != 0
3039 /* Testing SEC_DEBUGGING here may be wrong.
3040 It's here to avoid a crash when
3041 generating a shared library with DWARF
3042 debugging information. */
3043 || ((input_section
->flags
& SEC_DEBUGGING
) != 0
3044 && (h
->elf_link_hash_flags
3045 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0))
3046 && (r_type
== R_PPC_ADDR32
3047 || r_type
== R_PPC_ADDR24
3048 || r_type
== R_PPC_ADDR16
3049 || r_type
== R_PPC_ADDR16_LO
3050 || r_type
== R_PPC_ADDR16_HI
3051 || r_type
== R_PPC_ADDR16_HA
3052 || r_type
== R_PPC_ADDR14
3053 || r_type
== R_PPC_ADDR14_BRTAKEN
3054 || r_type
== R_PPC_ADDR14_BRNTAKEN
3055 || r_type
== R_PPC_COPY
3056 || r_type
== R_PPC_GLOB_DAT
3057 || r_type
== R_PPC_JMP_SLOT
3058 || r_type
== R_PPC_UADDR32
3059 || r_type
== R_PPC_UADDR16
3060 || r_type
== R_PPC_SDAREL16
3061 || r_type
== R_PPC_EMB_NADDR32
3062 || r_type
== R_PPC_EMB_NADDR16
3063 || r_type
== R_PPC_EMB_NADDR16_LO
3064 || r_type
== R_PPC_EMB_NADDR16_HI
3065 || r_type
== R_PPC_EMB_NADDR16_HA
3066 || r_type
== R_PPC_EMB_SDAI16
3067 || r_type
== R_PPC_EMB_SDA2I16
3068 || r_type
== R_PPC_EMB_SDA2REL
3069 || r_type
== R_PPC_EMB_SDA21
3070 || r_type
== R_PPC_EMB_MRKREF
3071 || r_type
== R_PPC_EMB_BIT_FLD
3072 || r_type
== R_PPC_EMB_RELSDA
3073 || ((r_type
== R_PPC_REL24
3074 || r_type
== R_PPC_REL32
3075 || r_type
== R_PPC_REL14
3076 || r_type
== R_PPC_REL14_BRTAKEN
3077 || r_type
== R_PPC_REL14_BRNTAKEN
3078 || r_type
== R_PPC_RELATIVE
)
3079 && strcmp (h
->root
.root
.string
,
3080 "_GLOBAL_OFFSET_TABLE_") != 0))))
3082 /* In these cases, we don't need the relocation
3083 value. We check specially because in some
3084 obscure cases sec->output_section will be NULL. */
3087 else if (sec
->output_section
== NULL
)
3089 (*_bfd_error_handler
)
3090 (_("%s: warning: unresolvable relocation against symbol `%s' from %s section"),
3091 bfd_archive_filename (input_bfd
), h
->root
.root
.string
,
3092 bfd_get_section_name (input_bfd
, input_section
));
3096 relocation
= (h
->root
.u
.def
.value
3097 + sec
->output_section
->vma
3098 + sec
->output_offset
);
3100 else if (h
->root
.type
== bfd_link_hash_undefweak
)
3102 else if (info
->shared
3103 && (!info
->symbolic
|| info
->allow_shlib_undefined
)
3104 && !info
->no_undefined
3105 && ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
)
3109 if (! (*info
->callbacks
->undefined_symbol
) (info
,
3110 h
->root
.root
.string
,
3115 || info
->no_undefined
3116 || ELF_ST_VISIBILITY (h
->other
))))
3122 switch ((int) r_type
)
3125 (*_bfd_error_handler
) (_("%s: unknown relocation type %d for symbol %s"),
3126 bfd_archive_filename (input_bfd
),
3127 (int) r_type
, sym_name
);
3129 bfd_set_error (bfd_error_bad_value
);
3133 case (int) R_PPC_NONE
:
3136 /* Relocations that need no special processing. */
3137 case (int) R_PPC_LOCAL24PC
:
3138 /* It makes no sense to point a local relocation
3139 at a symbol not in this object. */
3141 && (h
->root
.type
== bfd_link_hash_defined
3142 || h
->root
.type
== bfd_link_hash_defweak
)
3143 && sec
->output_section
== NULL
)
3145 if (! (*info
->callbacks
->undefined_symbol
) (info
,
3146 h
->root
.root
.string
,
3156 /* Relocations that may need to be propagated if this is a shared
3158 case (int) R_PPC_REL24
:
3159 case (int) R_PPC_REL32
:
3160 case (int) R_PPC_REL14
:
3161 /* If these relocations are not to a named symbol, they can be
3162 handled right here, no need to bother the dynamic linker. */
3164 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0
3165 || SYMBOL_REFERENCES_LOCAL (info
, h
))
3169 /* Relocations that always need to be propagated if this is a shared
3171 case (int) R_PPC_ADDR32
:
3172 case (int) R_PPC_ADDR24
:
3173 case (int) R_PPC_ADDR16
:
3174 case (int) R_PPC_ADDR16_LO
:
3175 case (int) R_PPC_ADDR16_HI
:
3176 case (int) R_PPC_ADDR16_HA
:
3177 case (int) R_PPC_ADDR14
:
3178 case (int) R_PPC_UADDR32
:
3179 case (int) R_PPC_UADDR16
:
3180 if (info
->shared
&& r_symndx
!= 0)
3182 Elf_Internal_Rela outrel
;
3187 fprintf (stderr
, "ppc_elf_relocate_section need to create relocation for %s\n",
3188 (h
&& h
->root
.root
.string
) ? h
->root
.root
.string
: "<unknown>");
3191 /* When generating a shared object, these relocations
3192 are copied into the output file to be resolved at run
3199 name
= (bfd_elf_string_from_elf_section
3201 elf_elfheader (input_bfd
)->e_shstrndx
,
3202 elf_section_data (input_section
)->rel_hdr
.sh_name
));
3206 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
3207 && strcmp (bfd_get_section_name (input_bfd
,
3211 sreloc
= bfd_get_section_by_name (dynobj
, name
);
3212 BFD_ASSERT (sreloc
!= NULL
);
3218 _bfd_elf_section_offset (output_bfd
, info
, input_section
,
3220 if (outrel
.r_offset
== (bfd_vma
) -1
3221 || outrel
.r_offset
== (bfd_vma
) -2)
3222 skip
= (int) outrel
.r_offset
;
3223 outrel
.r_offset
+= (input_section
->output_section
->vma
3224 + input_section
->output_offset
);
3227 memset (&outrel
, 0, sizeof outrel
);
3228 /* h->dynindx may be -1 if this symbol was marked to
3230 else if (! will_become_local
)
3232 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
3233 outrel
.r_addend
= rel
->r_addend
;
3237 if (r_type
== R_PPC_ADDR32
)
3239 outrel
.r_info
= ELF32_R_INFO (0, R_PPC_RELATIVE
);
3240 outrel
.r_addend
= relocation
+ rel
->r_addend
;
3247 sec
= local_sections
[r_symndx
];
3250 BFD_ASSERT (h
->root
.type
== bfd_link_hash_defined
3252 == bfd_link_hash_defweak
));
3253 sec
= h
->root
.u
.def
.section
;
3255 if (sec
!= NULL
&& bfd_is_abs_section (sec
))
3257 else if (sec
== NULL
|| sec
->owner
== NULL
)
3259 bfd_set_error (bfd_error_bad_value
);
3266 osec
= sec
->output_section
;
3267 indx
= elf_section_data (osec
)->dynindx
;
3268 BFD_ASSERT (indx
> 0);
3272 printf ("indx=%d section=%s flags=%08x name=%s\n",
3273 indx
, osec
->name
, osec
->flags
,
3274 h
->root
.root
.string
);
3279 outrel
.r_info
= ELF32_R_INFO (indx
, r_type
);
3280 outrel
.r_addend
= relocation
+ rel
->r_addend
;
3284 loc
= sreloc
->contents
;
3285 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rela
);
3286 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
3291 /* This reloc will be computed at runtime. We clear the memory
3292 so that it contains predictable value. */
3294 && ((input_section
->flags
& SEC_ALLOC
) != 0
3295 || ELF32_R_TYPE (outrel
.r_info
) != R_PPC_RELATIVE
))
3297 relocation
= howto
->pc_relative
? outrel
.r_offset
: 0;
3303 /* Arithmetic adjust relocations that aren't going into a
3305 if (r_type
== R_PPC_ADDR16_HA
3306 /* It's just possible that this symbol is a weak symbol
3307 that's not actually defined anywhere. In that case,
3308 'sec' would be NULL, and we should leave the symbol
3309 alone (it will be set to zero elsewhere in the link). */
3312 addend
+= ((relocation
+ addend
) & 0x8000) << 1;
3316 /* branch taken prediction relocations */
3317 case (int) R_PPC_ADDR14_BRTAKEN
:
3318 case (int) R_PPC_REL14_BRTAKEN
:
3319 insn
= bfd_get_32 (output_bfd
, contents
+ offset
);
3320 if ((relocation
- offset
) & 0x8000)
3321 insn
&= ~BRANCH_PREDICT_BIT
;
3323 insn
|= BRANCH_PREDICT_BIT
;
3324 bfd_put_32 (output_bfd
, (bfd_vma
) insn
, contents
+ offset
);
3327 /* branch not taken predicition relocations */
3328 case (int) R_PPC_ADDR14_BRNTAKEN
:
3329 case (int) R_PPC_REL14_BRNTAKEN
:
3330 insn
= bfd_get_32 (output_bfd
, contents
+ offset
);
3331 if ((relocation
- offset
) & 0x8000)
3332 insn
|= BRANCH_PREDICT_BIT
;
3334 insn
&= ~BRANCH_PREDICT_BIT
;
3335 bfd_put_32 (output_bfd
, (bfd_vma
) insn
, contents
+ offset
);
3338 /* GOT16 relocations */
3339 case (int) R_PPC_GOT16
:
3340 case (int) R_PPC_GOT16_LO
:
3341 case (int) R_PPC_GOT16_HI
:
3342 case (int) R_PPC_GOT16_HA
:
3343 /* Relocation is to the entry for this symbol in the global
3345 BFD_ASSERT (sgot
!= NULL
);
3351 off
= h
->got
.offset
;
3352 BFD_ASSERT (off
!= (bfd_vma
) -1);
3354 if (! elf_hash_table (info
)->dynamic_sections_created
3356 && SYMBOL_REFERENCES_LOCAL (info
, h
)))
3358 /* This is actually a static link, or it is a
3359 -Bsymbolic link and the symbol is defined
3360 locally. We must initialize this entry in the
3361 global offset table. Since the offset must
3362 always be a multiple of 4, we use the least
3363 significant bit to record whether we have
3364 initialized it already.
3366 When doing a dynamic link, we create a .rela.got
3367 relocation entry to initialize the value. This
3368 is done in the finish_dynamic_symbol routine. */
3373 bfd_put_32 (output_bfd
, relocation
,
3374 sgot
->contents
+ off
);
3379 relocation
= sgot
->output_offset
+ off
- 4;
3385 BFD_ASSERT (local_got_offsets
!= NULL
3386 && local_got_offsets
[r_symndx
] != (bfd_vma
) -1);
3388 off
= local_got_offsets
[r_symndx
];
3390 /* The offset must always be a multiple of 4. We use
3391 the least significant bit to record whether we have
3392 already processed this entry. */
3401 Elf_Internal_Rela outrel
;
3404 /* We need to generate a R_PPC_RELATIVE reloc
3405 for the dynamic linker. */
3406 srelgot
= bfd_get_section_by_name (dynobj
, ".rela.got");
3407 BFD_ASSERT (srelgot
!= NULL
);
3409 outrel
.r_offset
= (sgot
->output_section
->vma
3410 + sgot
->output_offset
3412 outrel
.r_info
= ELF32_R_INFO (0, R_PPC_RELATIVE
);
3413 outrel
.r_addend
= relocation
;
3414 loc
= srelgot
->contents
;
3415 loc
+= srelgot
->reloc_count
++ * sizeof (Elf32_External_Rela
);
3416 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
3420 bfd_put_32 (output_bfd
, relocation
, sgot
->contents
+ off
);
3421 local_got_offsets
[r_symndx
] |= 1;
3424 relocation
= sgot
->output_offset
+ off
- 4;
3428 /* Indirect .sdata relocation */
3429 case (int) R_PPC_EMB_SDAI16
:
3430 BFD_ASSERT (sdata
!= NULL
);
3431 relocation
= bfd_elf32_finish_pointer_linker_section (output_bfd
, input_bfd
, info
,
3432 sdata
, h
, relocation
, rel
,
3436 /* Indirect .sdata2 relocation */
3437 case (int) R_PPC_EMB_SDA2I16
:
3438 BFD_ASSERT (sdata2
!= NULL
);
3439 relocation
= bfd_elf32_finish_pointer_linker_section (output_bfd
, input_bfd
, info
,
3440 sdata2
, h
, relocation
, rel
,
3444 /* Handle the TOC16 reloc. We want to use the offset within the .got
3445 section, not the actual VMA. This is appropriate when generating
3446 an embedded ELF object, for which the .got section acts like the
3447 AIX .toc section. */
3448 case (int) R_PPC_TOC16
: /* phony GOT16 relocations */
3449 BFD_ASSERT (sec
!= (asection
*) 0);
3450 BFD_ASSERT (bfd_is_und_section (sec
)
3451 || strcmp (bfd_get_section_name (abfd
, sec
), ".got") == 0
3452 || strcmp (bfd_get_section_name (abfd
, sec
), ".cgot") == 0)
3454 addend
-= sec
->output_section
->vma
+ sec
->output_offset
+ 0x8000;
3457 case (int) R_PPC_PLTREL24
:
3458 /* Relocation is to the entry for this symbol in the
3459 procedure linkage table. */
3460 BFD_ASSERT (h
!= NULL
);
3462 if (h
->plt
.offset
== (bfd_vma
) -1
3465 /* We didn't make a PLT entry for this symbol. This
3466 happens when statically linking PIC code, or when
3467 using -Bsymbolic. */
3471 relocation
= (splt
->output_section
->vma
3472 + splt
->output_offset
3476 /* relocate against _SDA_BASE_ */
3477 case (int) R_PPC_SDAREL16
:
3481 BFD_ASSERT (sec
!= (asection
*) 0);
3482 name
= bfd_get_section_name (abfd
, sec
->output_section
);
3483 if (! ((strncmp (name
, ".sdata", 6) == 0
3484 && (name
[6] == 0 || name
[6] == '.'))
3485 || (strncmp (name
, ".sbss", 5) == 0
3486 && (name
[5] == 0 || name
[5] == '.'))))
3488 (*_bfd_error_handler
) (_("%s: The target (%s) of a %s relocation is in the wrong output section (%s)"),
3489 bfd_archive_filename (input_bfd
),
3491 ppc_elf_howto_table
[(int) r_type
]->name
,
3494 addend
-= (sdata
->sym_hash
->root
.u
.def
.value
3495 + sdata
->sym_hash
->root
.u
.def
.section
->output_section
->vma
3496 + sdata
->sym_hash
->root
.u
.def
.section
->output_offset
);
3500 /* relocate against _SDA2_BASE_ */
3501 case (int) R_PPC_EMB_SDA2REL
:
3505 BFD_ASSERT (sec
!= (asection
*) 0);
3506 name
= bfd_get_section_name (abfd
, sec
->output_section
);
3507 if (! (strncmp (name
, ".sdata2", 7) == 0
3508 || strncmp (name
, ".sbss2", 6) == 0))
3510 (*_bfd_error_handler
) (_("%s: The target (%s) of a %s relocation is in the wrong output section (%s)"),
3511 bfd_archive_filename (input_bfd
),
3513 ppc_elf_howto_table
[(int) r_type
]->name
,
3516 bfd_set_error (bfd_error_bad_value
);
3520 addend
-= (sdata2
->sym_hash
->root
.u
.def
.value
3521 + sdata2
->sym_hash
->root
.u
.def
.section
->output_section
->vma
3522 + sdata2
->sym_hash
->root
.u
.def
.section
->output_offset
);
3526 /* relocate against either _SDA_BASE_, _SDA2_BASE_, or 0 */
3527 case (int) R_PPC_EMB_SDA21
:
3528 case (int) R_PPC_EMB_RELSDA
:
3533 BFD_ASSERT (sec
!= (asection
*) 0);
3534 name
= bfd_get_section_name (abfd
, sec
->output_section
);
3535 if (((strncmp (name
, ".sdata", 6) == 0
3536 && (name
[6] == 0 || name
[6] == '.'))
3537 || (strncmp (name
, ".sbss", 5) == 0
3538 && (name
[5] == 0 || name
[5] == '.'))))
3541 addend
-= (sdata
->sym_hash
->root
.u
.def
.value
3542 + sdata
->sym_hash
->root
.u
.def
.section
->output_section
->vma
3543 + sdata
->sym_hash
->root
.u
.def
.section
->output_offset
);
3546 else if (strncmp (name
, ".sdata2", 7) == 0
3547 || strncmp (name
, ".sbss2", 6) == 0)
3550 addend
-= (sdata2
->sym_hash
->root
.u
.def
.value
3551 + sdata2
->sym_hash
->root
.u
.def
.section
->output_section
->vma
3552 + sdata2
->sym_hash
->root
.u
.def
.section
->output_offset
);
3555 else if (strcmp (name
, ".PPC.EMB.sdata0") == 0
3556 || strcmp (name
, ".PPC.EMB.sbss0") == 0)
3563 (*_bfd_error_handler
) (_("%s: The target (%s) of a %s relocation is in the wrong output section (%s)"),
3564 bfd_archive_filename (input_bfd
),
3566 ppc_elf_howto_table
[(int) r_type
]->name
,
3569 bfd_set_error (bfd_error_bad_value
);
3574 if (r_type
== R_PPC_EMB_SDA21
)
3575 { /* fill in register field */
3576 insn
= bfd_get_32 (output_bfd
, contents
+ offset
);
3577 insn
= (insn
& ~RA_REGISTER_MASK
) | (reg
<< RA_REGISTER_SHIFT
);
3578 bfd_put_32 (output_bfd
, (bfd_vma
) insn
, contents
+ offset
);
3583 /* Relocate against the beginning of the section */
3584 case (int) R_PPC_SECTOFF
:
3585 case (int) R_PPC_SECTOFF_LO
:
3586 case (int) R_PPC_SECTOFF_HI
:
3587 BFD_ASSERT (sec
!= (asection
*) 0);
3588 addend
-= sec
->output_section
->vma
;
3591 case (int) R_PPC_SECTOFF_HA
:
3592 BFD_ASSERT (sec
!= (asection
*) 0);
3593 addend
-= sec
->output_section
->vma
;
3594 addend
+= ((relocation
+ addend
) & 0x8000) << 1;
3597 /* Negative relocations */
3598 case (int) R_PPC_EMB_NADDR32
:
3599 case (int) R_PPC_EMB_NADDR16
:
3600 case (int) R_PPC_EMB_NADDR16_LO
:
3601 case (int) R_PPC_EMB_NADDR16_HI
:
3602 addend
-= 2 * relocation
;
3605 case (int) R_PPC_EMB_NADDR16_HA
:
3606 addend
-= 2 * relocation
;
3607 addend
+= ((relocation
+ addend
) & 0x8000) << 1;
3610 /* NOP relocation that prevents garbage collecting linkers from omitting a
3612 case (int) R_PPC_EMB_MRKREF
:
3615 case (int) R_PPC_COPY
:
3616 case (int) R_PPC_GLOB_DAT
:
3617 case (int) R_PPC_JMP_SLOT
:
3618 case (int) R_PPC_RELATIVE
:
3619 case (int) R_PPC_PLT32
:
3620 case (int) R_PPC_PLTREL32
:
3621 case (int) R_PPC_PLT16_LO
:
3622 case (int) R_PPC_PLT16_HI
:
3623 case (int) R_PPC_PLT16_HA
:
3624 case (int) R_PPC_EMB_RELSEC16
:
3625 case (int) R_PPC_EMB_RELST_LO
:
3626 case (int) R_PPC_EMB_RELST_HI
:
3627 case (int) R_PPC_EMB_RELST_HA
:
3628 case (int) R_PPC_EMB_BIT_FLD
:
3629 (*_bfd_error_handler
) (_("%s: Relocation %s is not yet supported for symbol %s."),
3630 bfd_archive_filename (input_bfd
),
3631 ppc_elf_howto_table
[(int) r_type
]->name
,
3634 bfd_set_error (bfd_error_invalid_operation
);
3638 case (int) R_PPC_GNU_VTINHERIT
:
3639 case (int) R_PPC_GNU_VTENTRY
:
3640 /* These are no-ops in the end. */
3645 fprintf (stderr
, "\ttype = %s (%d), name = %s, symbol index = %ld, offset = %ld, addend = %ld\n",
3654 r
= _bfd_final_link_relocate (howto
,
3662 if (r
== bfd_reloc_ok
)
3664 else if (r
== bfd_reloc_overflow
)
3670 if (h
->root
.type
== bfd_link_hash_undefweak
3671 && howto
->pc_relative
)
3673 /* Assume this is a call protected by other code that
3674 detect the symbol is undefined. If this is the case,
3675 we can safely ignore the overflow. If not, the
3676 program is hosed anyway, and a little warning isn't
3682 name
= h
->root
.root
.string
;
3686 name
= bfd_elf_string_from_elf_section (input_bfd
,
3687 symtab_hdr
->sh_link
,
3692 name
= bfd_section_name (input_bfd
, sec
);
3695 if (! (*info
->callbacks
->reloc_overflow
) (info
,
3709 fprintf (stderr
, "\n");
3715 static enum elf_reloc_type_class
3716 ppc_elf_reloc_type_class (rela
)
3717 const Elf_Internal_Rela
*rela
;
3719 switch ((int) ELF32_R_TYPE (rela
->r_info
))
3721 case R_PPC_RELATIVE
:
3722 return reloc_class_relative
;
3725 case R_PPC_JMP_SLOT
:
3726 return reloc_class_plt
;
3728 return reloc_class_copy
;
3730 return reloc_class_normal
;
3734 /* Support for core dump NOTE sections */
3736 ppc_elf_grok_prstatus (abfd
, note
)
3738 Elf_Internal_Note
*note
;
3741 unsigned int raw_size
;
3743 switch (note
->descsz
)
3748 case 268: /* Linux/PPC */
3750 elf_tdata (abfd
)->core_signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
3753 elf_tdata (abfd
)->core_pid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
3762 /* Make a ".reg/999" section. */
3763 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
3764 raw_size
, note
->descpos
+ offset
);
3768 ppc_elf_grok_psinfo (abfd
, note
)
3770 Elf_Internal_Note
*note
;
3772 switch (note
->descsz
)
3777 case 128: /* Linux/PPC elf_prpsinfo */
3778 elf_tdata (abfd
)->core_program
3779 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 32, 16);
3780 elf_tdata (abfd
)->core_command
3781 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 48, 80);
3784 /* Note that for some reason, a spurious space is tacked
3785 onto the end of the args in some (at least one anyway)
3786 implementations, so strip it off if it exists. */
3789 char *command
= elf_tdata (abfd
)->core_command
;
3790 int n
= strlen (command
);
3792 if (0 < n
&& command
[n
- 1] == ' ')
3793 command
[n
- 1] = '\0';
3799 #define TARGET_LITTLE_SYM bfd_elf32_powerpcle_vec
3800 #define TARGET_LITTLE_NAME "elf32-powerpcle"
3801 #define TARGET_BIG_SYM bfd_elf32_powerpc_vec
3802 #define TARGET_BIG_NAME "elf32-powerpc"
3803 #define ELF_ARCH bfd_arch_powerpc
3804 #define ELF_MACHINE_CODE EM_PPC
3805 #define ELF_MAXPAGESIZE 0x10000
3806 #define elf_info_to_howto ppc_elf_info_to_howto
3808 #ifdef EM_CYGNUS_POWERPC
3809 #define ELF_MACHINE_ALT1 EM_CYGNUS_POWERPC
3813 #define ELF_MACHINE_ALT2 EM_PPC_OLD
3816 #define elf_backend_plt_not_loaded 1
3817 #define elf_backend_got_symbol_offset 4
3818 #define elf_backend_can_gc_sections 1
3819 #define elf_backend_can_refcount 1
3820 #define elf_backend_got_header_size 12
3821 #define elf_backend_plt_header_size PLT_INITIAL_ENTRY_SIZE
3822 #define elf_backend_rela_normal 1
3824 #define bfd_elf32_bfd_merge_private_bfd_data ppc_elf_merge_private_bfd_data
3825 #define bfd_elf32_bfd_relax_section ppc_elf_relax_section
3826 #define bfd_elf32_bfd_reloc_type_lookup ppc_elf_reloc_type_lookup
3827 #define bfd_elf32_bfd_set_private_flags ppc_elf_set_private_flags
3828 #define bfd_elf32_bfd_final_link _bfd_elf32_gc_common_final_link
3830 #define elf_backend_object_p ppc_elf_object_p
3831 #define elf_backend_gc_mark_hook ppc_elf_gc_mark_hook
3832 #define elf_backend_gc_sweep_hook ppc_elf_gc_sweep_hook
3833 #define elf_backend_section_from_shdr ppc_elf_section_from_shdr
3834 #define elf_backend_relocate_section ppc_elf_relocate_section
3835 #define elf_backend_create_dynamic_sections ppc_elf_create_dynamic_sections
3836 #define elf_backend_check_relocs ppc_elf_check_relocs
3837 #define elf_backend_adjust_dynamic_symbol ppc_elf_adjust_dynamic_symbol
3838 #define elf_backend_add_symbol_hook ppc_elf_add_symbol_hook
3839 #define elf_backend_size_dynamic_sections ppc_elf_size_dynamic_sections
3840 #define elf_backend_finish_dynamic_symbol ppc_elf_finish_dynamic_symbol
3841 #define elf_backend_finish_dynamic_sections ppc_elf_finish_dynamic_sections
3842 #define elf_backend_fake_sections ppc_elf_fake_sections
3843 #define elf_backend_additional_program_headers ppc_elf_additional_program_headers
3844 #define elf_backend_modify_segment_map ppc_elf_modify_segment_map
3845 #define elf_backend_grok_prstatus ppc_elf_grok_prstatus
3846 #define elf_backend_grok_psinfo ppc_elf_grok_psinfo
3847 #define elf_backend_reloc_type_class ppc_elf_reloc_type_class
3849 #include "elf32-target.h"