1 /* PowerPC-specific support for 32-bit ELF
2 Copyright 1994, 1995, 1996, 1997, 1998 Free Software Foundation, Inc.
3 Written by Ian Lance Taylor, Cygnus Support.
5 This file is part of BFD, the Binary File Descriptor library.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
21 /* This file is based on a preliminary PowerPC ELF ABI. The
22 information may not match the final PowerPC ELF ABI. It includes
23 suggestions from the in-progress Embedded PowerPC ABI, and that
24 information may also not match. */
33 #define USE_RELA /* we want RELA relocations, not REL */
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
, Elf32_Internal_Rela
*dst
));
40 static void ppc_elf_howto_init
PARAMS ((void));
41 static bfd_reloc_status_type ppc_elf_addr16_ha_reloc
42 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
43 static boolean ppc_elf_set_private_flags
PARAMS ((bfd
*, flagword
));
44 static boolean ppc_elf_copy_private_bfd_data
PARAMS ((bfd
*, bfd
*));
45 static boolean ppc_elf_merge_private_bfd_data
PARAMS ((bfd
*, bfd
*));
47 static int ppc_elf_additional_program_headers
PARAMS ((bfd
*));
48 static boolean ppc_elf_modify_segment_map
PARAMS ((bfd
*));
50 static boolean ppc_elf_create_dynamic_sections
51 PARAMS ((bfd
*, struct bfd_link_info
*));
53 static boolean ppc_elf_section_from_shdr
PARAMS ((bfd
*,
54 Elf32_Internal_Shdr
*,
56 static boolean ppc_elf_fake_sections
57 PARAMS ((bfd
*, Elf32_Internal_Shdr
*, asection
*));
59 static elf_linker_section_t
*ppc_elf_create_linker_section
61 struct bfd_link_info
*info
,
62 enum elf_linker_section_enum
));
64 static boolean ppc_elf_check_relocs
PARAMS ((bfd
*,
65 struct bfd_link_info
*,
67 const Elf_Internal_Rela
*));
69 static asection
* ppc_elf_gc_mark_hook
PARAMS ((bfd
*abfd
,
70 struct bfd_link_info
*info
,
71 Elf_Internal_Rela
*rel
,
72 struct elf_link_hash_entry
*h
,
73 Elf_Internal_Sym
*sym
));
75 static boolean ppc_elf_gc_sweep_hook
PARAMS ((bfd
*abfd
,
76 struct bfd_link_info
*info
,
78 const Elf_Internal_Rela
*relocs
));
80 static boolean ppc_elf_adjust_dynamic_symbol
PARAMS ((struct bfd_link_info
*,
81 struct elf_link_hash_entry
*));
83 static boolean ppc_elf_adjust_dynindx
PARAMS ((struct elf_link_hash_entry
*, PTR
));
85 static boolean ppc_elf_size_dynamic_sections
PARAMS ((bfd
*, struct bfd_link_info
*));
87 static boolean ppc_elf_relocate_section
PARAMS ((bfd
*,
88 struct bfd_link_info
*info
,
92 Elf_Internal_Rela
*relocs
,
93 Elf_Internal_Sym
*local_syms
,
96 static boolean ppc_elf_add_symbol_hook
PARAMS ((bfd
*,
97 struct bfd_link_info
*,
98 const Elf_Internal_Sym
*,
104 static boolean ppc_elf_finish_dynamic_symbol
PARAMS ((bfd
*,
105 struct bfd_link_info
*,
106 struct elf_link_hash_entry
*,
107 Elf_Internal_Sym
*));
109 static boolean ppc_elf_finish_dynamic_sections
PARAMS ((bfd
*, struct bfd_link_info
*));
111 #define BRANCH_PREDICT_BIT 0x200000 /* branch prediction bit for branch taken relocs */
112 #define RA_REGISTER_MASK 0x001f0000 /* mask to set RA in memory instructions */
113 #define RA_REGISTER_SHIFT 16 /* value to shift register by to insert RA */
115 /* The name of the dynamic interpreter. This is put in the .interp
118 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
120 /* The size in bytes of an entry in the procedure linkage table, and of the initial size
121 of the plt reserved for the dynamic linker. */
123 #define PLT_ENTRY_SIZE 12
124 #define PLT_INITIAL_ENTRY_SIZE 72
127 static reloc_howto_type
*ppc_elf_howto_table
[ (int)R_PPC_max
];
129 static reloc_howto_type ppc_elf_howto_raw
[] =
131 /* This reloc does nothing. */
132 HOWTO (R_PPC_NONE
, /* type */
134 2, /* size (0 = byte, 1 = short, 2 = long) */
136 false, /* pc_relative */
138 complain_overflow_bitfield
, /* complain_on_overflow */
139 bfd_elf_generic_reloc
, /* special_function */
140 "R_PPC_NONE", /* name */
141 false, /* partial_inplace */
144 false), /* pcrel_offset */
146 /* A standard 32 bit relocation. */
147 HOWTO (R_PPC_ADDR32
, /* type */
149 2, /* size (0 = byte, 1 = short, 2 = long) */
151 false, /* pc_relative */
153 complain_overflow_bitfield
, /* complain_on_overflow */
154 bfd_elf_generic_reloc
, /* special_function */
155 "R_PPC_ADDR32", /* name */
156 false, /* partial_inplace */
158 0xffffffff, /* dst_mask */
159 false), /* pcrel_offset */
161 /* An absolute 26 bit branch; the lower two bits must be zero.
162 FIXME: we don't check that, we just clear them. */
163 HOWTO (R_PPC_ADDR24
, /* type */
165 2, /* size (0 = byte, 1 = short, 2 = long) */
167 false, /* pc_relative */
169 complain_overflow_bitfield
, /* complain_on_overflow */
170 bfd_elf_generic_reloc
, /* special_function */
171 "R_PPC_ADDR24", /* name */
172 false, /* partial_inplace */
174 0x3fffffc, /* dst_mask */
175 false), /* pcrel_offset */
177 /* A standard 16 bit relocation. */
178 HOWTO (R_PPC_ADDR16
, /* type */
180 1, /* size (0 = byte, 1 = short, 2 = long) */
182 false, /* pc_relative */
184 complain_overflow_bitfield
, /* complain_on_overflow */
185 bfd_elf_generic_reloc
, /* special_function */
186 "R_PPC_ADDR16", /* name */
187 false, /* partial_inplace */
189 0xffff, /* dst_mask */
190 false), /* pcrel_offset */
192 /* A 16 bit relocation without overflow. */
193 HOWTO (R_PPC_ADDR16_LO
, /* type */
195 1, /* size (0 = byte, 1 = short, 2 = long) */
197 false, /* pc_relative */
199 complain_overflow_dont
,/* complain_on_overflow */
200 bfd_elf_generic_reloc
, /* special_function */
201 "R_PPC_ADDR16_LO", /* name */
202 false, /* partial_inplace */
204 0xffff, /* dst_mask */
205 false), /* pcrel_offset */
207 /* The high order 16 bits of an address. */
208 HOWTO (R_PPC_ADDR16_HI
, /* type */
210 1, /* size (0 = byte, 1 = short, 2 = long) */
212 false, /* pc_relative */
214 complain_overflow_dont
, /* complain_on_overflow */
215 bfd_elf_generic_reloc
, /* special_function */
216 "R_PPC_ADDR16_HI", /* name */
217 false, /* partial_inplace */
219 0xffff, /* dst_mask */
220 false), /* pcrel_offset */
222 /* The high order 16 bits of an address, plus 1 if the contents of
223 the low 16 bits, treated as a signed number, is negative. */
224 HOWTO (R_PPC_ADDR16_HA
, /* type */
226 1, /* size (0 = byte, 1 = short, 2 = long) */
228 false, /* pc_relative */
230 complain_overflow_dont
, /* complain_on_overflow */
231 ppc_elf_addr16_ha_reloc
, /* special_function */
232 "R_PPC_ADDR16_HA", /* name */
233 false, /* partial_inplace */
235 0xffff, /* dst_mask */
236 false), /* pcrel_offset */
238 /* An absolute 16 bit branch; the lower two bits must be zero.
239 FIXME: we don't check that, we just clear them. */
240 HOWTO (R_PPC_ADDR14
, /* type */
242 2, /* size (0 = byte, 1 = short, 2 = long) */
244 false, /* pc_relative */
246 complain_overflow_bitfield
, /* complain_on_overflow */
247 bfd_elf_generic_reloc
, /* special_function */
248 "R_PPC_ADDR14", /* name */
249 false, /* partial_inplace */
251 0xfffc, /* dst_mask */
252 false), /* pcrel_offset */
254 /* An absolute 16 bit branch, for which bit 10 should be set to
255 indicate that the branch is expected to be taken. The lower two
256 bits must be zero. */
257 HOWTO (R_PPC_ADDR14_BRTAKEN
, /* type */
259 2, /* size (0 = byte, 1 = short, 2 = long) */
261 false, /* pc_relative */
263 complain_overflow_bitfield
, /* complain_on_overflow */
264 bfd_elf_generic_reloc
, /* special_function */
265 "R_PPC_ADDR14_BRTAKEN",/* name */
266 false, /* partial_inplace */
268 0xfffc, /* dst_mask */
269 false), /* pcrel_offset */
271 /* An absolute 16 bit branch, for which bit 10 should be set to
272 indicate that the branch is not expected to be taken. The lower
273 two bits must be zero. */
274 HOWTO (R_PPC_ADDR14_BRNTAKEN
, /* type */
276 2, /* size (0 = byte, 1 = short, 2 = long) */
278 false, /* pc_relative */
280 complain_overflow_bitfield
, /* complain_on_overflow */
281 bfd_elf_generic_reloc
, /* special_function */
282 "R_PPC_ADDR14_BRNTAKEN",/* name */
283 false, /* partial_inplace */
285 0xfffc, /* dst_mask */
286 false), /* pcrel_offset */
288 /* A relative 26 bit branch; the lower two bits must be zero. */
289 HOWTO (R_PPC_REL24
, /* type */
291 2, /* size (0 = byte, 1 = short, 2 = long) */
293 true, /* pc_relative */
295 complain_overflow_signed
, /* complain_on_overflow */
296 bfd_elf_generic_reloc
, /* special_function */
297 "R_PPC_REL24", /* name */
298 false, /* partial_inplace */
300 0x3fffffc, /* dst_mask */
301 true), /* pcrel_offset */
303 /* A relative 16 bit branch; the lower two bits must be zero. */
304 HOWTO (R_PPC_REL14
, /* type */
306 2, /* size (0 = byte, 1 = short, 2 = long) */
308 true, /* pc_relative */
310 complain_overflow_signed
, /* complain_on_overflow */
311 bfd_elf_generic_reloc
, /* special_function */
312 "R_PPC_REL14", /* name */
313 false, /* partial_inplace */
315 0xfffc, /* dst_mask */
316 true), /* pcrel_offset */
318 /* A relative 16 bit branch. Bit 10 should be set to indicate that
319 the branch is expected to be taken. The lower two bits must be
321 HOWTO (R_PPC_REL14_BRTAKEN
, /* type */
323 2, /* size (0 = byte, 1 = short, 2 = long) */
325 true, /* pc_relative */
327 complain_overflow_signed
, /* complain_on_overflow */
328 bfd_elf_generic_reloc
, /* special_function */
329 "R_PPC_REL14_BRTAKEN", /* name */
330 false, /* partial_inplace */
332 0xfffc, /* dst_mask */
333 true), /* pcrel_offset */
335 /* A relative 16 bit branch. Bit 10 should be set to indicate that
336 the branch is not expected to be taken. The lower two bits must
338 HOWTO (R_PPC_REL14_BRNTAKEN
, /* type */
340 2, /* size (0 = byte, 1 = short, 2 = long) */
342 true, /* pc_relative */
344 complain_overflow_signed
, /* complain_on_overflow */
345 bfd_elf_generic_reloc
, /* special_function */
346 "R_PPC_REL14_BRNTAKEN",/* name */
347 false, /* partial_inplace */
349 0xfffc, /* dst_mask */
350 true), /* pcrel_offset */
352 /* Like R_PPC_ADDR16, but referring to the GOT table entry for the
354 HOWTO (R_PPC_GOT16
, /* type */
356 1, /* size (0 = byte, 1 = short, 2 = long) */
358 false, /* pc_relative */
360 complain_overflow_signed
, /* complain_on_overflow */
361 bfd_elf_generic_reloc
, /* special_function */
362 "R_PPC_GOT16", /* name */
363 false, /* partial_inplace */
365 0xffff, /* dst_mask */
366 false), /* pcrel_offset */
368 /* Like R_PPC_ADDR16_LO, but referring to the GOT table entry for
370 HOWTO (R_PPC_GOT16_LO
, /* type */
372 1, /* size (0 = byte, 1 = short, 2 = long) */
374 false, /* pc_relative */
376 complain_overflow_bitfield
, /* complain_on_overflow */
377 bfd_elf_generic_reloc
, /* special_function */
378 "R_PPC_GOT16_LO", /* name */
379 false, /* partial_inplace */
381 0xffff, /* dst_mask */
382 false), /* pcrel_offset */
384 /* Like R_PPC_ADDR16_HI, but referring to the GOT table entry for
386 HOWTO (R_PPC_GOT16_HI
, /* type */
388 1, /* size (0 = byte, 1 = short, 2 = long) */
390 false, /* pc_relative */
392 complain_overflow_bitfield
, /* complain_on_overflow */
393 bfd_elf_generic_reloc
, /* special_function */
394 "R_PPC_GOT16_HI", /* name */
395 false, /* partial_inplace */
397 0xffff, /* dst_mask */
398 false), /* pcrel_offset */
400 /* Like R_PPC_ADDR16_HA, but referring to the GOT table entry for
402 HOWTO (R_PPC_GOT16_HA
, /* type */
404 1, /* size (0 = byte, 1 = short, 2 = long) */
406 false, /* pc_relative */
408 complain_overflow_bitfield
, /* complain_on_overflow */
409 ppc_elf_addr16_ha_reloc
, /* special_function */
410 "R_PPC_GOT16_HA", /* name */
411 false, /* partial_inplace */
413 0xffff, /* dst_mask */
414 false), /* pcrel_offset */
416 /* Like R_PPC_REL24, but referring to the procedure linkage table
417 entry for the symbol. */
418 HOWTO (R_PPC_PLTREL24
, /* type */
420 2, /* size (0 = byte, 1 = short, 2 = long) */
422 true, /* pc_relative */
424 complain_overflow_signed
, /* complain_on_overflow */
425 bfd_elf_generic_reloc
, /* special_function */
426 "R_PPC_PLTREL24", /* name */
427 false, /* partial_inplace */
429 0x3fffffc, /* dst_mask */
430 true), /* pcrel_offset */
432 /* This is used only by the dynamic linker. The symbol should exist
433 both in the object being run and in some shared library. The
434 dynamic linker copies the data addressed by the symbol from the
435 shared library into the object, because the object being
436 run has to have the data at some particular address. */
437 HOWTO (R_PPC_COPY
, /* type */
439 2, /* size (0 = byte, 1 = short, 2 = long) */
441 false, /* pc_relative */
443 complain_overflow_bitfield
, /* complain_on_overflow */
444 bfd_elf_generic_reloc
, /* special_function */
445 "R_PPC_COPY", /* name */
446 false, /* partial_inplace */
449 false), /* pcrel_offset */
451 /* Like R_PPC_ADDR32, but used when setting global offset table
453 HOWTO (R_PPC_GLOB_DAT
, /* type */
455 2, /* size (0 = byte, 1 = short, 2 = long) */
457 false, /* pc_relative */
459 complain_overflow_bitfield
, /* complain_on_overflow */
460 bfd_elf_generic_reloc
, /* special_function */
461 "R_PPC_GLOB_DAT", /* name */
462 false, /* partial_inplace */
464 0xffffffff, /* dst_mask */
465 false), /* pcrel_offset */
467 /* Marks a procedure linkage table entry for a symbol. */
468 HOWTO (R_PPC_JMP_SLOT
, /* type */
470 2, /* size (0 = byte, 1 = short, 2 = long) */
472 false, /* pc_relative */
474 complain_overflow_bitfield
, /* complain_on_overflow */
475 bfd_elf_generic_reloc
, /* special_function */
476 "R_PPC_JMP_SLOT", /* name */
477 false, /* partial_inplace */
480 false), /* pcrel_offset */
482 /* Used only by the dynamic linker. When the object is run, this
483 longword is set to the load address of the object, plus the
485 HOWTO (R_PPC_RELATIVE
, /* type */
487 2, /* size (0 = byte, 1 = short, 2 = long) */
489 false, /* pc_relative */
491 complain_overflow_bitfield
, /* complain_on_overflow */
492 bfd_elf_generic_reloc
, /* special_function */
493 "R_PPC_RELATIVE", /* name */
494 false, /* partial_inplace */
496 0xffffffff, /* dst_mask */
497 false), /* pcrel_offset */
499 /* Like R_PPC_REL24, but uses the value of the symbol within the
500 object rather than the final value. Normally used for
501 _GLOBAL_OFFSET_TABLE_. */
502 HOWTO (R_PPC_LOCAL24PC
, /* type */
504 2, /* size (0 = byte, 1 = short, 2 = long) */
506 true, /* pc_relative */
508 complain_overflow_signed
, /* complain_on_overflow */
509 bfd_elf_generic_reloc
, /* special_function */
510 "R_PPC_LOCAL24PC", /* name */
511 false, /* partial_inplace */
513 0x3fffffc, /* dst_mask */
514 true), /* pcrel_offset */
516 /* Like R_PPC_ADDR32, but may be unaligned. */
517 HOWTO (R_PPC_UADDR32
, /* type */
519 2, /* size (0 = byte, 1 = short, 2 = long) */
521 false, /* pc_relative */
523 complain_overflow_bitfield
, /* complain_on_overflow */
524 bfd_elf_generic_reloc
, /* special_function */
525 "R_PPC_UADDR32", /* name */
526 false, /* partial_inplace */
528 0xffffffff, /* dst_mask */
529 false), /* pcrel_offset */
531 /* Like R_PPC_ADDR16, but may be unaligned. */
532 HOWTO (R_PPC_UADDR16
, /* type */
534 1, /* size (0 = byte, 1 = short, 2 = long) */
536 false, /* pc_relative */
538 complain_overflow_bitfield
, /* complain_on_overflow */
539 bfd_elf_generic_reloc
, /* special_function */
540 "R_PPC_UADDR16", /* name */
541 false, /* partial_inplace */
543 0xffff, /* dst_mask */
544 false), /* pcrel_offset */
546 /* 32-bit PC relative */
547 HOWTO (R_PPC_REL32
, /* type */
549 2, /* size (0 = byte, 1 = short, 2 = long) */
551 true, /* pc_relative */
553 complain_overflow_bitfield
, /* complain_on_overflow */
554 bfd_elf_generic_reloc
, /* special_function */
555 "R_PPC_REL32", /* name */
556 false, /* partial_inplace */
558 0xffffffff, /* dst_mask */
559 true), /* pcrel_offset */
561 /* 32-bit relocation to the symbol's procedure linkage table.
562 FIXME: not supported. */
563 HOWTO (R_PPC_PLT32
, /* type */
565 2, /* size (0 = byte, 1 = short, 2 = long) */
567 false, /* pc_relative */
569 complain_overflow_bitfield
, /* complain_on_overflow */
570 bfd_elf_generic_reloc
, /* special_function */
571 "R_PPC_PLT32", /* name */
572 false, /* partial_inplace */
575 false), /* pcrel_offset */
577 /* 32-bit PC relative relocation to the symbol's procedure linkage table.
578 FIXME: not supported. */
579 HOWTO (R_PPC_PLTREL32
, /* type */
581 2, /* size (0 = byte, 1 = short, 2 = long) */
583 true, /* pc_relative */
585 complain_overflow_bitfield
, /* complain_on_overflow */
586 bfd_elf_generic_reloc
, /* special_function */
587 "R_PPC_PLTREL32", /* name */
588 false, /* partial_inplace */
591 true), /* pcrel_offset */
593 /* Like R_PPC_ADDR16_LO, but referring to the PLT table entry for
595 HOWTO (R_PPC_PLT16_LO
, /* type */
597 1, /* size (0 = byte, 1 = short, 2 = long) */
599 false, /* pc_relative */
601 complain_overflow_bitfield
, /* complain_on_overflow */
602 bfd_elf_generic_reloc
, /* special_function */
603 "R_PPC_PLT16_LO", /* name */
604 false, /* partial_inplace */
606 0xffff, /* dst_mask */
607 false), /* pcrel_offset */
609 /* Like R_PPC_ADDR16_HI, but referring to the PLT table entry for
611 HOWTO (R_PPC_PLT16_HI
, /* type */
613 1, /* size (0 = byte, 1 = short, 2 = long) */
615 false, /* pc_relative */
617 complain_overflow_bitfield
, /* complain_on_overflow */
618 bfd_elf_generic_reloc
, /* special_function */
619 "R_PPC_PLT16_HI", /* name */
620 false, /* partial_inplace */
622 0xffff, /* dst_mask */
623 false), /* pcrel_offset */
625 /* Like R_PPC_ADDR16_HA, but referring to the PLT table entry for
626 the symbol. FIXME: Not supported. */
627 HOWTO (R_PPC_PLT16_HA
, /* type */
629 1, /* size (0 = byte, 1 = short, 2 = long) */
631 false, /* pc_relative */
633 complain_overflow_bitfield
, /* complain_on_overflow */
634 bfd_elf_generic_reloc
, /* special_function */
635 "R_PPC_PLT16_HA", /* name */
636 false, /* partial_inplace */
638 0xffff, /* dst_mask */
639 false), /* pcrel_offset */
641 /* A sign-extended 16 bit value relative to _SDA_BASE_, for use with
643 HOWTO (R_PPC_SDAREL16
, /* type */
645 1, /* size (0 = byte, 1 = short, 2 = long) */
647 false, /* pc_relative */
649 complain_overflow_signed
, /* complain_on_overflow */
650 bfd_elf_generic_reloc
, /* special_function */
651 "R_PPC_SDAREL16", /* name */
652 false, /* partial_inplace */
654 0xffff, /* dst_mask */
655 false), /* pcrel_offset */
657 /* 32-bit section relative relocation. */
658 HOWTO (R_PPC_SECTOFF
, /* type */
660 2, /* size (0 = byte, 1 = short, 2 = long) */
662 true, /* pc_relative */
664 complain_overflow_bitfield
, /* complain_on_overflow */
665 bfd_elf_generic_reloc
, /* special_function */
666 "R_PPC_SECTOFF", /* name */
667 false, /* partial_inplace */
670 true), /* pcrel_offset */
672 /* 16-bit lower half section relative relocation. */
673 HOWTO (R_PPC_SECTOFF_LO
, /* type */
675 1, /* size (0 = byte, 1 = short, 2 = long) */
677 false, /* pc_relative */
679 complain_overflow_bitfield
, /* complain_on_overflow */
680 bfd_elf_generic_reloc
, /* special_function */
681 "R_PPC_SECTOFF_LO", /* name */
682 false, /* partial_inplace */
684 0xffff, /* dst_mask */
685 false), /* pcrel_offset */
687 /* 16-bit upper half section relative relocation. */
688 HOWTO (R_PPC_SECTOFF_HI
, /* type */
690 1, /* size (0 = byte, 1 = short, 2 = long) */
692 false, /* pc_relative */
694 complain_overflow_bitfield
, /* complain_on_overflow */
695 bfd_elf_generic_reloc
, /* special_function */
696 "R_PPC_SECTOFF_HI", /* name */
697 false, /* partial_inplace */
699 0xffff, /* dst_mask */
700 false), /* pcrel_offset */
702 /* 16-bit upper half adjusted section relative relocation. */
703 HOWTO (R_PPC_SECTOFF_HA
, /* type */
705 1, /* size (0 = byte, 1 = short, 2 = long) */
707 false, /* pc_relative */
709 complain_overflow_bitfield
, /* complain_on_overflow */
710 bfd_elf_generic_reloc
, /* special_function */
711 "R_PPC_SECTOFF_HA", /* name */
712 false, /* partial_inplace */
714 0xffff, /* dst_mask */
715 false), /* pcrel_offset */
717 /* The remaining relocs are from the Embedded ELF ABI, and are not
718 in the SVR4 ELF ABI. */
720 /* 32 bit value resulting from the addend minus the symbol */
721 HOWTO (R_PPC_EMB_NADDR32
, /* type */
723 2, /* size (0 = byte, 1 = short, 2 = long) */
725 false, /* pc_relative */
727 complain_overflow_bitfield
, /* complain_on_overflow */
728 bfd_elf_generic_reloc
, /* special_function */
729 "R_PPC_EMB_NADDR32", /* name */
730 false, /* partial_inplace */
732 0xffffffff, /* dst_mask */
733 false), /* pcrel_offset */
735 /* 16 bit value resulting from the addend minus the symbol */
736 HOWTO (R_PPC_EMB_NADDR16
, /* type */
738 1, /* size (0 = byte, 1 = short, 2 = long) */
740 false, /* pc_relative */
742 complain_overflow_bitfield
, /* complain_on_overflow */
743 bfd_elf_generic_reloc
, /* special_function */
744 "R_PPC_EMB_NADDR16", /* name */
745 false, /* partial_inplace */
747 0xffff, /* dst_mask */
748 false), /* pcrel_offset */
750 /* 16 bit value resulting from the addend minus the symbol */
751 HOWTO (R_PPC_EMB_NADDR16_LO
, /* type */
753 1, /* size (0 = byte, 1 = short, 2 = long) */
755 false, /* pc_relative */
757 complain_overflow_dont
,/* complain_on_overflow */
758 bfd_elf_generic_reloc
, /* special_function */
759 "R_PPC_EMB_ADDR16_LO", /* name */
760 false, /* partial_inplace */
762 0xffff, /* dst_mask */
763 false), /* pcrel_offset */
765 /* The high order 16 bits of the addend minus the symbol */
766 HOWTO (R_PPC_EMB_NADDR16_HI
, /* type */
768 1, /* size (0 = byte, 1 = short, 2 = long) */
770 false, /* pc_relative */
772 complain_overflow_dont
, /* complain_on_overflow */
773 bfd_elf_generic_reloc
, /* special_function */
774 "R_PPC_EMB_NADDR16_HI", /* name */
775 false, /* partial_inplace */
777 0xffff, /* dst_mask */
778 false), /* pcrel_offset */
780 /* The high order 16 bits of the result of the addend minus the address,
781 plus 1 if the contents of the low 16 bits, treated as a signed number,
783 HOWTO (R_PPC_EMB_NADDR16_HA
, /* type */
785 1, /* size (0 = byte, 1 = short, 2 = long) */
787 false, /* pc_relative */
789 complain_overflow_dont
, /* complain_on_overflow */
790 bfd_elf_generic_reloc
, /* special_function */
791 "R_PPC_EMB_NADDR16_HA", /* name */
792 false, /* partial_inplace */
794 0xffff, /* dst_mask */
795 false), /* pcrel_offset */
797 /* 16 bit value resulting from allocating a 4 byte word to hold an
798 address in the .sdata section, and returning the offset from
799 _SDA_BASE_ for that relocation */
800 HOWTO (R_PPC_EMB_SDAI16
, /* type */
802 1, /* size (0 = byte, 1 = short, 2 = long) */
804 false, /* pc_relative */
806 complain_overflow_bitfield
, /* complain_on_overflow */
807 bfd_elf_generic_reloc
, /* special_function */
808 "R_PPC_EMB_SDAI16", /* name */
809 false, /* partial_inplace */
811 0xffff, /* dst_mask */
812 false), /* pcrel_offset */
814 /* 16 bit value resulting from allocating a 4 byte word to hold an
815 address in the .sdata2 section, and returning the offset from
816 _SDA2_BASE_ for that relocation */
817 HOWTO (R_PPC_EMB_SDA2I16
, /* type */
819 1, /* size (0 = byte, 1 = short, 2 = long) */
821 false, /* pc_relative */
823 complain_overflow_bitfield
, /* complain_on_overflow */
824 bfd_elf_generic_reloc
, /* special_function */
825 "R_PPC_EMB_SDA2I16", /* name */
826 false, /* partial_inplace */
828 0xffff, /* dst_mask */
829 false), /* pcrel_offset */
831 /* A sign-extended 16 bit value relative to _SDA2_BASE_, for use with
833 HOWTO (R_PPC_EMB_SDA2REL
, /* type */
835 1, /* size (0 = byte, 1 = short, 2 = long) */
837 false, /* pc_relative */
839 complain_overflow_signed
, /* complain_on_overflow */
840 bfd_elf_generic_reloc
, /* special_function */
841 "R_PPC_EMB_SDA2REL", /* name */
842 false, /* partial_inplace */
844 0xffff, /* dst_mask */
845 false), /* pcrel_offset */
847 /* Relocate against either _SDA_BASE_ or _SDA2_BASE_, filling in the 16 bit
848 signed offset from the appropriate base, and filling in the register
849 field with the appropriate register (0, 2, or 13). */
850 HOWTO (R_PPC_EMB_SDA21
, /* type */
852 2, /* size (0 = byte, 1 = short, 2 = long) */
854 false, /* pc_relative */
856 complain_overflow_signed
, /* complain_on_overflow */
857 bfd_elf_generic_reloc
, /* special_function */
858 "R_PPC_EMB_SDA21", /* name */
859 false, /* partial_inplace */
861 0xffff, /* dst_mask */
862 false), /* pcrel_offset */
864 /* Relocation not handled: R_PPC_EMB_MRKREF */
865 /* Relocation not handled: R_PPC_EMB_RELSEC16 */
866 /* Relocation not handled: R_PPC_EMB_RELST_LO */
867 /* Relocation not handled: R_PPC_EMB_RELST_HI */
868 /* Relocation not handled: R_PPC_EMB_RELST_HA */
869 /* Relocation not handled: R_PPC_EMB_BIT_FLD */
871 /* PC relative relocation against either _SDA_BASE_ or _SDA2_BASE_, filling
872 in the 16 bit signed offset from the appropriate base, and filling in the
873 register field with the appropriate register (0, 2, or 13). */
874 HOWTO (R_PPC_EMB_RELSDA
, /* type */
876 1, /* size (0 = byte, 1 = short, 2 = long) */
878 true, /* pc_relative */
880 complain_overflow_signed
, /* complain_on_overflow */
881 bfd_elf_generic_reloc
, /* special_function */
882 "R_PPC_EMB_RELSDA", /* name */
883 false, /* partial_inplace */
885 0xffff, /* dst_mask */
886 false), /* pcrel_offset */
888 /* GNU extension to record C++ vtable hierarchy */
889 HOWTO (R_PPC_GNU_VTINHERIT
, /* type */
891 0, /* size (0 = byte, 1 = short, 2 = long) */
893 false, /* pc_relative */
895 complain_overflow_dont
, /* complain_on_overflow */
896 NULL
, /* special_function */
897 "R_PPC_GNU_VTINHERIT", /* name */
898 false, /* partial_inplace */
901 false), /* pcrel_offset */
903 /* GNU extension to record C++ vtable member usage */
904 HOWTO (R_PPC_GNU_VTENTRY
, /* type */
906 0, /* size (0 = byte, 1 = short, 2 = long) */
908 false, /* pc_relative */
910 complain_overflow_dont
, /* complain_on_overflow */
911 NULL
, /* special_function */
912 "R_PPC_GNU_VTENTRY", /* name */
913 false, /* partial_inplace */
916 false), /* pcrel_offset */
918 /* Phony reloc to handle AIX style TOC entries */
919 HOWTO (R_PPC_TOC16
, /* type */
921 1, /* size (0 = byte, 1 = short, 2 = long) */
923 false, /* pc_relative */
925 complain_overflow_signed
, /* complain_on_overflow */
926 bfd_elf_generic_reloc
, /* special_function */
927 "R_PPC_TOC16", /* name */
928 false, /* partial_inplace */
930 0xffff, /* dst_mask */
931 false), /* pcrel_offset */
935 /* Initialize the ppc_elf_howto_table, so that linear accesses can be done. */
938 ppc_elf_howto_init ()
940 unsigned int i
, type
;
942 for (i
= 0; i
< sizeof (ppc_elf_howto_raw
) / sizeof (ppc_elf_howto_raw
[0]); i
++)
944 type
= ppc_elf_howto_raw
[i
].type
;
945 BFD_ASSERT (type
< sizeof(ppc_elf_howto_table
) / sizeof(ppc_elf_howto_table
[0]));
946 ppc_elf_howto_table
[type
] = &ppc_elf_howto_raw
[i
];
951 static reloc_howto_type
*
952 ppc_elf_reloc_type_lookup (abfd
, code
)
954 bfd_reloc_code_real_type code
;
956 enum ppc_reloc_type ppc_reloc
= R_PPC_NONE
;
958 if (!ppc_elf_howto_table
[R_PPC_ADDR32
])
959 /* Initialize howto table if needed */
960 ppc_elf_howto_init ();
965 return (reloc_howto_type
*)NULL
;
967 case BFD_RELOC_NONE
: ppc_reloc
= R_PPC_NONE
; break;
968 case BFD_RELOC_32
: ppc_reloc
= R_PPC_ADDR32
; break;
969 case BFD_RELOC_PPC_BA26
: ppc_reloc
= R_PPC_ADDR24
; break;
970 case BFD_RELOC_16
: ppc_reloc
= R_PPC_ADDR16
; break;
971 case BFD_RELOC_LO16
: ppc_reloc
= R_PPC_ADDR16_LO
; break;
972 case BFD_RELOC_HI16
: ppc_reloc
= R_PPC_ADDR16_HI
; break;
973 case BFD_RELOC_HI16_S
: ppc_reloc
= R_PPC_ADDR16_HA
; break;
974 case BFD_RELOC_PPC_BA16
: ppc_reloc
= R_PPC_ADDR14
; break;
975 case BFD_RELOC_PPC_BA16_BRTAKEN
: ppc_reloc
= R_PPC_ADDR14_BRTAKEN
; break;
976 case BFD_RELOC_PPC_BA16_BRNTAKEN
: ppc_reloc
= R_PPC_ADDR14_BRNTAKEN
; break;
977 case BFD_RELOC_PPC_B26
: ppc_reloc
= R_PPC_REL24
; break;
978 case BFD_RELOC_PPC_B16
: ppc_reloc
= R_PPC_REL14
; break;
979 case BFD_RELOC_PPC_B16_BRTAKEN
: ppc_reloc
= R_PPC_REL14_BRTAKEN
; break;
980 case BFD_RELOC_PPC_B16_BRNTAKEN
: ppc_reloc
= R_PPC_REL14_BRNTAKEN
; break;
981 case BFD_RELOC_16_GOTOFF
: ppc_reloc
= R_PPC_GOT16
; break;
982 case BFD_RELOC_LO16_GOTOFF
: ppc_reloc
= R_PPC_GOT16_LO
; break;
983 case BFD_RELOC_HI16_GOTOFF
: ppc_reloc
= R_PPC_GOT16_HI
; break;
984 case BFD_RELOC_HI16_S_GOTOFF
: ppc_reloc
= R_PPC_GOT16_HA
; break;
985 case BFD_RELOC_24_PLT_PCREL
: ppc_reloc
= R_PPC_PLTREL24
; break;
986 case BFD_RELOC_PPC_COPY
: ppc_reloc
= R_PPC_COPY
; break;
987 case BFD_RELOC_PPC_GLOB_DAT
: ppc_reloc
= R_PPC_GLOB_DAT
; break;
988 case BFD_RELOC_PPC_LOCAL24PC
: ppc_reloc
= R_PPC_LOCAL24PC
; break;
989 case BFD_RELOC_32_PCREL
: ppc_reloc
= R_PPC_REL32
; break;
990 case BFD_RELOC_32_PLTOFF
: ppc_reloc
= R_PPC_PLT32
; break;
991 case BFD_RELOC_32_PLT_PCREL
: ppc_reloc
= R_PPC_PLTREL32
; break;
992 case BFD_RELOC_LO16_PLTOFF
: ppc_reloc
= R_PPC_PLT16_LO
; break;
993 case BFD_RELOC_HI16_PLTOFF
: ppc_reloc
= R_PPC_PLT16_HI
; break;
994 case BFD_RELOC_HI16_S_PLTOFF
: ppc_reloc
= R_PPC_PLT16_HA
; break;
995 case BFD_RELOC_GPREL16
: ppc_reloc
= R_PPC_SDAREL16
; break;
996 case BFD_RELOC_32_BASEREL
: ppc_reloc
= R_PPC_SECTOFF
; break;
997 case BFD_RELOC_LO16_BASEREL
: ppc_reloc
= R_PPC_SECTOFF_LO
; break;
998 case BFD_RELOC_HI16_BASEREL
: ppc_reloc
= R_PPC_SECTOFF_HI
; break;
999 case BFD_RELOC_HI16_S_BASEREL
: ppc_reloc
= R_PPC_SECTOFF_HA
; break;
1000 case BFD_RELOC_CTOR
: ppc_reloc
= R_PPC_ADDR32
; break;
1001 case BFD_RELOC_PPC_TOC16
: ppc_reloc
= R_PPC_TOC16
; break;
1002 case BFD_RELOC_PPC_EMB_NADDR32
: ppc_reloc
= R_PPC_EMB_NADDR32
; break;
1003 case BFD_RELOC_PPC_EMB_NADDR16
: ppc_reloc
= R_PPC_EMB_NADDR16
; break;
1004 case BFD_RELOC_PPC_EMB_NADDR16_LO
: ppc_reloc
= R_PPC_EMB_NADDR16_LO
; break;
1005 case BFD_RELOC_PPC_EMB_NADDR16_HI
: ppc_reloc
= R_PPC_EMB_NADDR16_HI
; break;
1006 case BFD_RELOC_PPC_EMB_NADDR16_HA
: ppc_reloc
= R_PPC_EMB_NADDR16_HA
; break;
1007 case BFD_RELOC_PPC_EMB_SDAI16
: ppc_reloc
= R_PPC_EMB_SDAI16
; break;
1008 case BFD_RELOC_PPC_EMB_SDA2I16
: ppc_reloc
= R_PPC_EMB_SDA2I16
; break;
1009 case BFD_RELOC_PPC_EMB_SDA2REL
: ppc_reloc
= R_PPC_EMB_SDA2REL
; break;
1010 case BFD_RELOC_PPC_EMB_SDA21
: ppc_reloc
= R_PPC_EMB_SDA21
; break;
1011 case BFD_RELOC_PPC_EMB_MRKREF
: ppc_reloc
= R_PPC_EMB_MRKREF
; break;
1012 case BFD_RELOC_PPC_EMB_RELSEC16
: ppc_reloc
= R_PPC_EMB_RELSEC16
; break;
1013 case BFD_RELOC_PPC_EMB_RELST_LO
: ppc_reloc
= R_PPC_EMB_RELST_LO
; break;
1014 case BFD_RELOC_PPC_EMB_RELST_HI
: ppc_reloc
= R_PPC_EMB_RELST_HI
; break;
1015 case BFD_RELOC_PPC_EMB_RELST_HA
: ppc_reloc
= R_PPC_EMB_RELST_HA
; break;
1016 case BFD_RELOC_PPC_EMB_BIT_FLD
: ppc_reloc
= R_PPC_EMB_BIT_FLD
; break;
1017 case BFD_RELOC_PPC_EMB_RELSDA
: ppc_reloc
= R_PPC_EMB_RELSDA
; break;
1018 case BFD_RELOC_VTABLE_INHERIT
: ppc_reloc
= R_PPC_GNU_VTINHERIT
; break;
1019 case BFD_RELOC_VTABLE_ENTRY
: ppc_reloc
= R_PPC_GNU_VTENTRY
; break;
1022 return ppc_elf_howto_table
[ (int)ppc_reloc
];
1025 /* Set the howto pointer for a PowerPC ELF reloc. */
1028 ppc_elf_info_to_howto (abfd
, cache_ptr
, dst
)
1031 Elf32_Internal_Rela
*dst
;
1033 if (!ppc_elf_howto_table
[ R_PPC_ADDR32
]) /* Initialize howto table if needed */
1034 ppc_elf_howto_init ();
1036 BFD_ASSERT (ELF32_R_TYPE (dst
->r_info
) < (unsigned int) R_PPC_max
);
1037 cache_ptr
->howto
= ppc_elf_howto_table
[ELF32_R_TYPE (dst
->r_info
)];
1040 /* Handle the R_PPC_ADDR16_HA reloc. */
1042 static bfd_reloc_status_type
1043 ppc_elf_addr16_ha_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1044 output_bfd
, error_message
)
1046 arelent
*reloc_entry
;
1049 asection
*input_section
;
1051 char **error_message
;
1055 if (output_bfd
!= NULL
)
1057 reloc_entry
->address
+= input_section
->output_offset
;
1058 return bfd_reloc_ok
;
1061 if (reloc_entry
->address
> input_section
->_cooked_size
)
1062 return bfd_reloc_outofrange
;
1064 if (bfd_is_com_section (symbol
->section
))
1067 relocation
= symbol
->value
;
1069 relocation
+= symbol
->section
->output_section
->vma
;
1070 relocation
+= symbol
->section
->output_offset
;
1071 relocation
+= reloc_entry
->addend
;
1073 reloc_entry
->addend
+= (relocation
& 0x8000) << 1;
1075 return bfd_reloc_continue
;
1078 /* Function to set whether a module needs the -mrelocatable bit set. */
1081 ppc_elf_set_private_flags (abfd
, flags
)
1085 BFD_ASSERT (!elf_flags_init (abfd
)
1086 || elf_elfheader (abfd
)->e_flags
== flags
);
1088 elf_elfheader (abfd
)->e_flags
= flags
;
1089 elf_flags_init (abfd
) = true;
1093 /* Copy backend specific data from one object module to another */
1095 ppc_elf_copy_private_bfd_data (ibfd
, obfd
)
1099 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
1100 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
1103 BFD_ASSERT (!elf_flags_init (obfd
)
1104 || elf_elfheader (obfd
)->e_flags
== elf_elfheader (ibfd
)->e_flags
);
1106 elf_elfheader (obfd
)->e_flags
= elf_elfheader (ibfd
)->e_flags
;
1107 elf_flags_init (obfd
) = true;
1111 /* Merge backend specific data from an object file to the output
1112 object file when linking */
1114 ppc_elf_merge_private_bfd_data (ibfd
, obfd
)
1122 /* Check if we have the same endianess */
1123 if (ibfd
->xvec
->byteorder
!= obfd
->xvec
->byteorder
1124 && obfd
->xvec
->byteorder
!= BFD_ENDIAN_UNKNOWN
)
1128 if (bfd_big_endian (ibfd
))
1129 msg
= _("%s: compiled for a big endian system and target is little endian");
1131 msg
= _("%s: compiled for a little endian system and target is big endian");
1133 (*_bfd_error_handler
) (msg
, bfd_get_filename (ibfd
));
1135 bfd_set_error (bfd_error_wrong_format
);
1139 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
1140 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
1143 new_flags
= elf_elfheader (ibfd
)->e_flags
;
1144 old_flags
= elf_elfheader (obfd
)->e_flags
;
1145 if (!elf_flags_init (obfd
)) /* First call, no flags set */
1147 elf_flags_init (obfd
) = true;
1148 elf_elfheader (obfd
)->e_flags
= new_flags
;
1151 else if (new_flags
== old_flags
) /* Compatible flags are ok */
1154 else /* Incompatible flags */
1156 /* Warn about -mrelocatable mismatch. Allow -mrelocatable-lib to be linked
1159 if ((new_flags
& EF_PPC_RELOCATABLE
) != 0
1160 && (old_flags
& (EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
)) == 0)
1163 (*_bfd_error_handler
)
1164 (_("%s: compiled with -mrelocatable and linked with modules compiled normally"),
1165 bfd_get_filename (ibfd
));
1167 else if ((new_flags
& (EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
)) == 0
1168 && (old_flags
& EF_PPC_RELOCATABLE
) != 0)
1171 (*_bfd_error_handler
)
1172 (_("%s: compiled normally and linked with modules compiled with -mrelocatable"),
1173 bfd_get_filename (ibfd
));
1175 /* If -mrelocatable-lib is linked with an object without -mrelocatable-lib, turn off
1176 the -mrelocatable-lib, since at least one module isn't relocatable. */
1177 else if ((old_flags
& EF_PPC_RELOCATABLE_LIB
) != 0
1178 && (new_flags
& EF_PPC_RELOCATABLE_LIB
) == 0)
1179 elf_elfheader (obfd
)->e_flags
&= ~EF_PPC_RELOCATABLE_LIB
;
1182 /* Do not warn about eabi vs. V.4 mismatch, just or in the bit if any module uses it */
1183 elf_elfheader (obfd
)->e_flags
|= (new_flags
& EF_PPC_EMB
);
1185 new_flags
&= ~ (EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
| EF_PPC_EMB
);
1186 old_flags
&= ~ (EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
| EF_PPC_EMB
);
1188 /* Warn about any other mismatches */
1189 if (new_flags
!= old_flags
)
1192 (*_bfd_error_handler
)
1193 (_("%s: uses different e_flags (0x%lx) fields than previous modules (0x%lx)"),
1194 bfd_get_filename (ibfd
), (long)new_flags
, (long)old_flags
);
1199 bfd_set_error (bfd_error_bad_value
);
1208 /* Handle a PowerPC specific section when reading an object file. This
1209 is called when elfcode.h finds a section with an unknown type. */
1212 ppc_elf_section_from_shdr (abfd
, hdr
, name
)
1214 Elf32_Internal_Shdr
*hdr
;
1220 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
))
1223 newsect
= hdr
->bfd_section
;
1224 flags
= bfd_get_section_flags (abfd
, newsect
);
1225 if (hdr
->sh_flags
& SHF_EXCLUDE
)
1226 flags
|= SEC_EXCLUDE
;
1228 if (hdr
->sh_type
== SHT_ORDERED
)
1229 flags
|= SEC_SORT_ENTRIES
;
1231 bfd_set_section_flags (abfd
, newsect
, flags
);
1236 /* Set up any other section flags and such that may be necessary. */
1239 ppc_elf_fake_sections (abfd
, shdr
, asect
)
1241 Elf32_Internal_Shdr
*shdr
;
1244 if ((asect
->flags
& SEC_EXCLUDE
) != 0)
1245 shdr
->sh_flags
|= SHF_EXCLUDE
;
1247 if ((asect
->flags
& SEC_SORT_ENTRIES
) != 0)
1248 shdr
->sh_type
= SHT_ORDERED
;
1254 /* Create a special linker section */
1255 static elf_linker_section_t
*
1256 ppc_elf_create_linker_section (abfd
, info
, which
)
1258 struct bfd_link_info
*info
;
1259 enum elf_linker_section_enum which
;
1261 bfd
*dynobj
= elf_hash_table (info
)->dynobj
;
1262 elf_linker_section_t
*lsect
;
1264 /* Record the first bfd section that needs the special section */
1266 dynobj
= elf_hash_table (info
)->dynobj
= abfd
;
1268 /* If this is the first time, create the section */
1269 lsect
= elf_linker_section (dynobj
, which
);
1272 elf_linker_section_t defaults
;
1273 static elf_linker_section_t zero_section
;
1275 defaults
= zero_section
;
1276 defaults
.which
= which
;
1277 defaults
.hole_written_p
= false;
1278 defaults
.alignment
= 2;
1280 /* Both of these sections are (technically) created by the user
1281 putting data in them, so they shouldn't be marked
1284 The linker creates them so it has somewhere to attach their
1285 respective symbols. In fact, if they were empty it would
1286 be OK to leave the symbol set to 0 (or any random number), because
1287 the appropriate register should never be used. */
1288 defaults
.flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
1294 (*_bfd_error_handler
) (_("%s: Unknown special linker type %d"),
1295 bfd_get_filename (abfd
),
1298 bfd_set_error (bfd_error_bad_value
);
1299 return (elf_linker_section_t
*)0;
1301 case LINKER_SECTION_SDATA
: /* .sdata/.sbss section */
1302 defaults
.name
= ".sdata";
1303 defaults
.rel_name
= ".rela.sdata";
1304 defaults
.bss_name
= ".sbss";
1305 defaults
.sym_name
= "_SDA_BASE_";
1306 defaults
.sym_offset
= 32768;
1309 case LINKER_SECTION_SDATA2
: /* .sdata2/.sbss2 section */
1310 defaults
.name
= ".sdata2";
1311 defaults
.rel_name
= ".rela.sdata2";
1312 defaults
.bss_name
= ".sbss2";
1313 defaults
.sym_name
= "_SDA2_BASE_";
1314 defaults
.sym_offset
= 32768;
1315 defaults
.flags
|= SEC_READONLY
;
1319 lsect
= _bfd_elf_create_linker_section (abfd
, info
, which
, &defaults
);
1326 /* If we have a non-zero sized .sbss2 or .PPC.EMB.sbss0 sections, we need to bump up
1327 the number of section headers. */
1330 ppc_elf_additional_program_headers (abfd
)
1338 s
= bfd_get_section_by_name (abfd
, ".interp");
1342 s
= bfd_get_section_by_name (abfd
, ".sbss2");
1343 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0 && s
->_raw_size
> 0)
1346 s
= bfd_get_section_by_name (abfd
, ".PPC.EMB.sbss0");
1347 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0 && s
->_raw_size
> 0)
1353 /* Modify the segment map if needed */
1356 ppc_elf_modify_segment_map (abfd
)
1362 /* We have to create .dynsbss and .rela.sbss here so that they get mapped
1363 to output sections (just like _bfd_elf_create_dynamic_sections has
1364 to create .dynbss and .rela.bss). */
1367 ppc_elf_create_dynamic_sections (abfd
, info
)
1369 struct bfd_link_info
*info
;
1371 register asection
*s
;
1374 if (!_bfd_elf_create_dynamic_sections(abfd
, info
))
1377 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
1378 | SEC_LINKER_CREATED
);
1380 s
= bfd_make_section (abfd
, ".dynsbss");
1382 || ! bfd_set_section_flags (abfd
, s
, SEC_ALLOC
))
1387 s
= bfd_make_section (abfd
, ".rela.sbss");
1389 || ! bfd_set_section_flags (abfd
, s
, flags
| SEC_READONLY
)
1390 || ! bfd_set_section_alignment (abfd
, s
, 2))
1396 /* Adjust a symbol defined by a dynamic object and referenced by a
1397 regular object. The current definition is in some section of the
1398 dynamic object, but we're not including those sections. We have to
1399 change the definition to something the rest of the link can
1403 ppc_elf_adjust_dynamic_symbol (info
, h
)
1404 struct bfd_link_info
*info
;
1405 struct elf_link_hash_entry
*h
;
1407 bfd
*dynobj
= elf_hash_table (info
)->dynobj
;
1409 unsigned int power_of_two
;
1413 fprintf (stderr
, "ppc_elf_adjust_dynamic_symbol called for %s\n", h
->root
.root
.string
);
1416 /* Make sure we know what is going on here. */
1417 BFD_ASSERT (dynobj
!= NULL
1418 && ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
)
1419 || h
->weakdef
!= NULL
1420 || ((h
->elf_link_hash_flags
1421 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0
1422 && (h
->elf_link_hash_flags
1423 & ELF_LINK_HASH_REF_REGULAR
) != 0
1424 && (h
->elf_link_hash_flags
1425 & ELF_LINK_HASH_DEF_REGULAR
) == 0)));
1428 /* If this is a function, put it in the procedure linkage table. We
1429 will fill in the contents of the procedure linkage table later,
1430 when we know the address of the .got section. */
1431 if (h
->type
== STT_FUNC
1432 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
1435 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) == 0
1436 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_REF_DYNAMIC
) == 0)
1438 /* This case can occur if we saw a PLT32 reloc in an input
1439 file, but the symbol was never referred to by a dynamic
1440 object. In such a case, we don't actually need to build
1441 a procedure linkage table, and we can just do a PC32
1443 BFD_ASSERT ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0);
1447 /* GC may have rendered this entry unused. Note, however, that in
1448 an executable all references to the symbol go to the PLT, so we
1449 can't turn it off in that case.
1450 ??? The correct thing to do here is to reference count all uses
1451 of the symbol, not just those to the GOT or PLT. */
1453 if (h
->plt
.refcount
<= 0 && info
->shared
)
1455 h
->plt
.offset
= (bfd_vma
) -1;
1456 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
1460 /* Make sure this symbol is output as a dynamic symbol. */
1461 if (h
->dynindx
== -1)
1463 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
1466 BFD_ASSERT (h
->dynindx
!= -1);
1468 s
= bfd_get_section_by_name (dynobj
, ".plt");
1469 BFD_ASSERT (s
!= NULL
);
1471 /* If this is the first .plt entry, make room for the special
1473 if (s
->_raw_size
== 0)
1474 s
->_raw_size
+= PLT_INITIAL_ENTRY_SIZE
;
1476 /* The PowerPC PLT is actually composed of two parts, the first part
1477 is 2 words (for a load and a jump), and then there is a remaining
1478 word available at the end. */
1479 plt_offset
= (PLT_INITIAL_ENTRY_SIZE
1480 + 8 * ((s
->_raw_size
- PLT_INITIAL_ENTRY_SIZE
) / PLT_ENTRY_SIZE
));
1482 /* If this symbol is not defined in a regular file, and we are
1483 not generating a shared library, then set the symbol to this
1484 location in the .plt. This is required to make function
1485 pointers compare as equal between the normal executable and
1486 the shared library. */
1488 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
1490 h
->root
.u
.def
.section
= s
;
1491 h
->root
.u
.def
.value
= plt_offset
;
1494 h
->plt
.offset
= plt_offset
;
1496 /* Make room for this entry. */
1497 s
->_raw_size
+= PLT_ENTRY_SIZE
;
1499 /* We also need to make an entry in the .rela.plt section. */
1500 s
= bfd_get_section_by_name (dynobj
, ".rela.plt");
1501 BFD_ASSERT (s
!= NULL
);
1502 s
->_raw_size
+= sizeof (Elf32_External_Rela
);
1507 /* If this is a weak symbol, and there is a real definition, the
1508 processor independent code will have arranged for us to see the
1509 real definition first, and we can just use the same value. */
1510 if (h
->weakdef
!= NULL
)
1512 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
1513 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
1514 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
1515 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
1519 /* This is a reference to a symbol defined by a dynamic object which
1520 is not a function. */
1522 /* If we are creating a shared library, we must presume that the
1523 only references to the symbol are via the global offset table.
1524 For such cases we need not do anything here; the relocations will
1525 be handled correctly by relocate_section. */
1529 /* We must allocate the symbol in our .dynbss section, which will
1530 become part of the .bss section of the executable. There will be
1531 an entry for this symbol in the .dynsym section. The dynamic
1532 object will contain position independent code, so all references
1533 from the dynamic object to this symbol will go through the global
1534 offset table. The dynamic linker will use the .dynsym entry to
1535 determine the address it must put in the global offset table, so
1536 both the dynamic object and the regular object will refer to the
1537 same memory location for the variable.
1539 Of course, if the symbol is sufficiently small, we must instead
1540 allocate it in .sbss. FIXME: It would be better to do this if and
1541 only if there were actually SDAREL relocs for that symbol. */
1543 if (h
->size
<= elf_gp_size (dynobj
))
1544 s
= bfd_get_section_by_name (dynobj
, ".dynsbss");
1546 s
= bfd_get_section_by_name (dynobj
, ".dynbss");
1547 BFD_ASSERT (s
!= NULL
);
1549 /* We must generate a R_PPC_COPY reloc to tell the dynamic linker to
1550 copy the initial value out of the dynamic object and into the
1551 runtime process image. We need to remember the offset into the
1552 .rela.bss section we are going to use. */
1553 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
1557 if (h
->size
<= elf_gp_size (dynobj
))
1558 srel
= bfd_get_section_by_name (dynobj
, ".rela.sbss");
1560 srel
= bfd_get_section_by_name (dynobj
, ".rela.bss");
1561 BFD_ASSERT (srel
!= NULL
);
1562 srel
->_raw_size
+= sizeof (Elf32_External_Rela
);
1563 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_COPY
;
1566 /* We need to figure out the alignment required for this symbol. I
1567 have no idea how ELF linkers handle this. */
1568 power_of_two
= bfd_log2 (h
->size
);
1569 if (power_of_two
> 4)
1572 /* Apply the required alignment. */
1573 s
->_raw_size
= BFD_ALIGN (s
->_raw_size
,
1574 (bfd_size_type
) (1 << power_of_two
));
1575 if (power_of_two
> bfd_get_section_alignment (dynobj
, s
))
1577 if (! bfd_set_section_alignment (dynobj
, s
, power_of_two
))
1581 /* Define the symbol as being at this point in the section. */
1582 h
->root
.u
.def
.section
= s
;
1583 h
->root
.u
.def
.value
= s
->_raw_size
;
1585 /* Increment the section size to make room for the symbol. */
1586 s
->_raw_size
+= h
->size
;
1592 /* Increment the index of a dynamic symbol by a given amount. Called
1593 via elf_link_hash_traverse. */
1596 ppc_elf_adjust_dynindx (h
, cparg
)
1597 struct elf_link_hash_entry
*h
;
1600 int *cp
= (int *) cparg
;
1603 fprintf (stderr
, "ppc_elf_adjust_dynindx called, h->dynindx = %d, *cp = %d\n", h
->dynindx
, *cp
);
1606 if (h
->dynindx
!= -1)
1613 /* Set the sizes of the dynamic sections. */
1616 ppc_elf_size_dynamic_sections (output_bfd
, info
)
1618 struct bfd_link_info
*info
;
1627 fprintf (stderr
, "ppc_elf_size_dynamic_sections called\n");
1630 dynobj
= elf_hash_table (info
)->dynobj
;
1631 BFD_ASSERT (dynobj
!= NULL
);
1633 if (elf_hash_table (info
)->dynamic_sections_created
)
1635 /* Set the contents of the .interp section to the interpreter. */
1638 s
= bfd_get_section_by_name (dynobj
, ".interp");
1639 BFD_ASSERT (s
!= NULL
);
1640 s
->_raw_size
= sizeof ELF_DYNAMIC_INTERPRETER
;
1641 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
1646 /* We may have created entries in the .rela.got, .rela.sdata, and
1647 .rela.sdata2 sections. However, if we are not creating the
1648 dynamic sections, we will not actually use these entries. Reset
1649 the size of .rela.got, et al, which will cause it to get
1650 stripped from the output file below. */
1651 static char *rela_sections
[] = { ".rela.got", ".rela.sdata",
1652 ".rela.sdata2", ".rela.sbss",
1656 for (p
= rela_sections
; *p
!= (char *)0; p
++)
1658 s
= bfd_get_section_by_name (dynobj
, *p
);
1664 /* The check_relocs and adjust_dynamic_symbol entry points have
1665 determined the sizes of the various dynamic sections. Allocate
1670 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
1675 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
1678 /* It's OK to base decisions on the section name, because none
1679 of the dynobj section names depend upon the input files. */
1680 name
= bfd_get_section_name (dynobj
, s
);
1684 if (strcmp (name
, ".plt") == 0)
1686 if (s
->_raw_size
== 0)
1688 /* Strip this section if we don't need it; see the
1694 /* Remember whether there is a PLT. */
1698 else if (strncmp (name
, ".rela", 5) == 0)
1700 if (s
->_raw_size
== 0)
1702 /* If we don't need this section, strip it from the
1703 output file. This is mostly to handle .rela.bss and
1704 .rela.plt. We must create both sections in
1705 create_dynamic_sections, because they must be created
1706 before the linker maps input sections to output
1707 sections. The linker does that before
1708 adjust_dynamic_symbol is called, and it is that
1709 function which decides whether anything needs to go
1710 into these sections. */
1716 const char *outname
;
1718 /* Remember whether there are any relocation sections. */
1721 /* If this relocation section applies to a read only
1722 section, then we probably need a DT_TEXTREL entry. */
1723 outname
= bfd_get_section_name (output_bfd
,
1725 target
= bfd_get_section_by_name (output_bfd
, outname
+ 5);
1727 && (target
->flags
& SEC_READONLY
) != 0
1728 && (target
->flags
& SEC_ALLOC
) != 0)
1731 /* We use the reloc_count field as a counter if we need
1732 to copy relocs into the output file. */
1736 else if (strcmp (name
, ".got") != 0
1737 && strcmp (name
, ".sdata") != 0
1738 && strcmp (name
, ".sdata2") != 0)
1740 /* It's not one of our sections, so don't allocate space. */
1748 for (spp
= &s
->output_section
->owner
->sections
;
1749 *spp
!= s
->output_section
;
1750 spp
= &(*spp
)->next
)
1752 *spp
= s
->output_section
->next
;
1753 --s
->output_section
->owner
->section_count
;
1758 /* Allocate memory for the section contents. */
1759 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->_raw_size
);
1760 if (s
->contents
== NULL
&& s
->_raw_size
!= 0)
1764 if (elf_hash_table (info
)->dynamic_sections_created
)
1766 /* Add some entries to the .dynamic section. We fill in the
1767 values later, in ppc_elf_finish_dynamic_sections, but we
1768 must add the entries now so that we get the correct size for
1769 the .dynamic section. The DT_DEBUG entry is filled in by the
1770 dynamic linker and used by the debugger. */
1773 if (! bfd_elf32_add_dynamic_entry (info
, DT_DEBUG
, 0))
1779 if (! bfd_elf32_add_dynamic_entry (info
, DT_PLTGOT
, 0)
1780 || ! bfd_elf32_add_dynamic_entry (info
, DT_PLTRELSZ
, 0)
1781 || ! bfd_elf32_add_dynamic_entry (info
, DT_PLTREL
, DT_RELA
)
1782 || ! bfd_elf32_add_dynamic_entry (info
, DT_JMPREL
, 0))
1788 if (! bfd_elf32_add_dynamic_entry (info
, DT_RELA
, 0)
1789 || ! bfd_elf32_add_dynamic_entry (info
, DT_RELASZ
, 0)
1790 || ! bfd_elf32_add_dynamic_entry (info
, DT_RELAENT
,
1791 sizeof (Elf32_External_Rela
)))
1797 if (! bfd_elf32_add_dynamic_entry (info
, DT_TEXTREL
, 0))
1802 /* If we are generating a shared library, we generate a section
1803 symbol for each output section. These are local symbols, which
1804 means that they must come first in the dynamic symbol table.
1805 That means we must increment the dynamic symbol index of every
1806 other dynamic symbol.
1808 FIXME: We assume that there will never be relocations to
1809 locations in linker-created sections that do not have
1810 externally-visible names. Instead, we should work out precisely
1811 which sections relocations are targetted at. */
1816 for (c
= 0, s
= output_bfd
->sections
; s
!= NULL
; s
= s
->next
)
1818 if ((s
->flags
& SEC_LINKER_CREATED
) != 0
1819 || (s
->flags
& SEC_ALLOC
) == 0)
1821 elf_section_data (s
)->dynindx
= -1;
1825 /* These symbols will have no names, so we don't need to
1826 fiddle with dynstr_index. */
1828 elf_section_data (s
)->dynindx
= c
+ 1;
1833 elf_link_hash_traverse (elf_hash_table (info
),
1834 ppc_elf_adjust_dynindx
,
1836 elf_hash_table (info
)->dynsymcount
+= c
;
1843 /* Look through the relocs for a section during the first phase, and
1844 allocate space in the global offset table or procedure linkage
1848 ppc_elf_check_relocs (abfd
, info
, sec
, relocs
)
1850 struct bfd_link_info
*info
;
1852 const Elf_Internal_Rela
*relocs
;
1855 Elf_Internal_Shdr
*symtab_hdr
;
1856 struct elf_link_hash_entry
**sym_hashes
, **sym_hashes_end
;
1857 const Elf_Internal_Rela
*rel
;
1858 const Elf_Internal_Rela
*rel_end
;
1859 bfd_signed_vma
*local_got_refcounts
;
1860 elf_linker_section_t
*sdata
;
1861 elf_linker_section_t
*sdata2
;
1864 asection
*srelgot
= NULL
;
1866 if (info
->relocateable
)
1870 fprintf (stderr
, "ppc_elf_check_relocs called for section %s in %s\n",
1871 bfd_get_section_name (abfd
, sec
),
1872 bfd_get_filename (abfd
));
1875 /* Create the linker generated sections all the time so that the
1876 special symbols are created. */
1878 if ((sdata
= elf_linker_section (abfd
, LINKER_SECTION_SDATA
)) == NULL
)
1880 sdata
= ppc_elf_create_linker_section (abfd
, info
, LINKER_SECTION_SDATA
);
1886 if ((sdata2
= elf_linker_section (abfd
, LINKER_SECTION_SDATA2
)) == NULL
)
1888 sdata2
= ppc_elf_create_linker_section (abfd
, info
, LINKER_SECTION_SDATA2
);
1893 dynobj
= elf_hash_table (info
)->dynobj
;
1894 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
1895 local_got_refcounts
= elf_local_got_refcounts (abfd
);
1897 sym_hashes
= elf_sym_hashes (abfd
);
1898 sym_hashes_end
= sym_hashes
+ symtab_hdr
->sh_size
/sizeof(Elf32_External_Sym
);
1899 if (!elf_bad_symtab (abfd
))
1900 sym_hashes_end
-= symtab_hdr
->sh_info
;
1904 rel_end
= relocs
+ sec
->reloc_count
;
1905 for (rel
= relocs
; rel
< rel_end
; rel
++)
1907 unsigned long r_symndx
;
1908 struct elf_link_hash_entry
*h
;
1910 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1911 if (r_symndx
< symtab_hdr
->sh_info
)
1914 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1916 switch (ELF32_R_TYPE (rel
->r_info
))
1918 /* GOT16 relocations */
1920 case R_PPC_GOT16_LO
:
1921 case R_PPC_GOT16_HI
:
1922 case R_PPC_GOT16_HA
:
1923 /* This symbol requires a global offset table entry. */
1929 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
1930 if (! _bfd_elf_create_got_section (dynobj
, info
))
1933 sgot
= bfd_get_section_by_name (dynobj
, ".got");
1934 BFD_ASSERT (sgot
!= NULL
);
1938 && (h
!= NULL
|| info
->shared
))
1940 srelgot
= bfd_get_section_by_name (dynobj
, ".rela.got");
1941 if (srelgot
== NULL
)
1943 srelgot
= bfd_make_section (dynobj
, ".rela.got");
1945 || ! bfd_set_section_flags (dynobj
, srelgot
,
1950 | SEC_LINKER_CREATED
1952 || ! bfd_set_section_alignment (dynobj
, srelgot
, 2))
1959 if (h
->got
.refcount
== -1)
1961 /* Make sure this symbol is output as a dynamic symbol. */
1962 if (h
->dynindx
== -1)
1963 if (!bfd_elf32_link_record_dynamic_symbol (info
, h
))
1966 /* Allocate space in the .got. */
1967 sgot
->_raw_size
+= 4;
1968 /* Allocate relocation space. */
1969 srelgot
->_raw_size
+= sizeof (Elf32_External_Rela
);
1971 h
->got
.refcount
= 1;
1978 /* This is a global offset table entry for a local symbol. */
1979 if (local_got_refcounts
== NULL
)
1982 register unsigned int i
;
1984 size
= symtab_hdr
->sh_info
* sizeof (bfd_signed_vma
);
1985 local_got_refcounts
= (bfd_signed_vma
*)
1986 bfd_alloc (abfd
, size
);
1987 if (local_got_refcounts
== NULL
)
1989 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
1990 memset (local_got_refcounts
, -1, size
);
1992 if (local_got_refcounts
[r_symndx
] == -1)
1994 sgot
->_raw_size
+= 4;
1996 /* If we are generating a shared object, we need to
1997 output a R_PPC_RELATIVE reloc so that the
1998 dynamic linker can adjust this GOT entry. */
2000 srelgot
->_raw_size
+= sizeof (Elf32_External_Rela
);
2002 local_got_refcounts
[r_symndx
] = 1;
2005 local_got_refcounts
[r_symndx
]++;
2009 /* Indirect .sdata relocation */
2010 case R_PPC_EMB_SDAI16
:
2013 ((*_bfd_error_handler
)
2014 (_("%s: relocation %s cannot be used when making a shared object"),
2015 bfd_get_filename (abfd
), "R_PPC_EMB_SDAI16"));
2019 if (srelgot
== NULL
&& (h
!= NULL
|| info
->shared
))
2021 srelgot
= bfd_get_section_by_name (dynobj
, ".rela.got");
2022 if (srelgot
== NULL
)
2024 srelgot
= bfd_make_section (dynobj
, ".rela.got");
2026 || ! bfd_set_section_flags (dynobj
, srelgot
,
2031 | SEC_LINKER_CREATED
2033 || ! bfd_set_section_alignment (dynobj
, srelgot
, 2))
2038 if (!bfd_elf32_create_pointer_linker_section (abfd
, info
, sdata
, h
, rel
))
2043 /* Indirect .sdata2 relocation */
2044 case R_PPC_EMB_SDA2I16
:
2047 ((*_bfd_error_handler
)
2048 (_("%s: relocation %s cannot be used when making a shared object"),
2049 bfd_get_filename (abfd
), "R_PPC_EMB_SDA2I16"));
2053 if (srelgot
== NULL
&& (h
!= NULL
|| info
->shared
))
2055 srelgot
= bfd_get_section_by_name (dynobj
, ".rela.got");
2056 if (srelgot
== NULL
)
2058 srelgot
= bfd_make_section (dynobj
, ".rela.got");
2060 || ! bfd_set_section_flags (dynobj
, srelgot
,
2065 | SEC_LINKER_CREATED
2067 || ! bfd_set_section_alignment (dynobj
, srelgot
, 2))
2072 if (!bfd_elf32_create_pointer_linker_section (abfd
, info
, sdata2
, h
, rel
))
2077 case R_PPC_SDAREL16
:
2078 case R_PPC_EMB_SDA2REL
:
2079 case R_PPC_EMB_SDA21
:
2082 ((*_bfd_error_handler
)
2083 (_("%s: relocation %s cannot be used when making a shared object"),
2084 bfd_get_filename (abfd
),
2085 ppc_elf_howto_table
[(int)ELF32_R_TYPE (rel
->r_info
)]->name
));
2091 case R_PPC_PLTREL24
:
2092 case R_PPC_PLT16_LO
:
2093 case R_PPC_PLT16_HI
:
2094 case R_PPC_PLT16_HA
:
2096 fprintf (stderr
, "Reloc requires a PLT entry\n");
2098 /* This symbol requires a procedure linkage table entry. We
2099 actually build the entry in adjust_dynamic_symbol,
2100 because this might be a case of linking PIC code without
2101 linking in any dynamic objects, in which case we don't
2102 need to generate a procedure linkage table after all. */
2106 /* It does not make sense to have a procedure linkage
2107 table entry for a local symbol. */
2108 bfd_set_error (bfd_error_bad_value
);
2112 /* Make sure this symbol is output as a dynamic symbol. */
2113 if (h
->dynindx
== -1)
2115 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
2118 if (h
->plt
.refcount
== -1)
2120 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
2121 h
->plt
.refcount
= 1;
2127 /* The following relocations don't need to propagate the
2128 relocation if linking a shared object since they are
2129 section relative. */
2131 case R_PPC_SECTOFF_LO
:
2132 case R_PPC_SECTOFF_HI
:
2133 case R_PPC_SECTOFF_HA
:
2136 /* This refers only to functions defined in the shared library */
2137 case R_PPC_LOCAL24PC
:
2140 /* This relocation describes the C++ object vtable hierarchy.
2141 Reconstruct it for later use during GC. */
2142 case R_PPC_GNU_VTINHERIT
:
2143 if (!_bfd_elf32_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
2147 /* This relocation describes which C++ vtable entries are actually
2148 used. Record for later use during GC. */
2149 case R_PPC_GNU_VTENTRY
:
2150 if (!_bfd_elf32_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
2154 /* When creating a shared object, we must copy these
2155 relocs into the output file. We create a reloc
2156 section in dynobj and make room for the reloc. */
2159 case R_PPC_REL14_BRTAKEN
:
2160 case R_PPC_REL14_BRNTAKEN
:
2163 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
2171 fprintf (stderr
, "ppc_elf_check_relocs need to create relocation for %s\n",
2172 (h
&& h
->root
.root
.string
) ? h
->root
.root
.string
: "<unknown>");
2178 name
= (bfd_elf_string_from_elf_section
2180 elf_elfheader (abfd
)->e_shstrndx
,
2181 elf_section_data (sec
)->rel_hdr
.sh_name
));
2185 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
2186 && strcmp (bfd_get_section_name (abfd
, sec
),
2189 sreloc
= bfd_get_section_by_name (dynobj
, name
);
2194 sreloc
= bfd_make_section (dynobj
, name
);
2195 flags
= (SEC_HAS_CONTENTS
| SEC_READONLY
2196 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
2197 if ((sec
->flags
& SEC_ALLOC
) != 0)
2198 flags
|= SEC_ALLOC
| SEC_LOAD
;
2200 || ! bfd_set_section_flags (dynobj
, sreloc
, flags
)
2201 || ! bfd_set_section_alignment (dynobj
, sreloc
, 2))
2206 sreloc
->_raw_size
+= sizeof (Elf32_External_Rela
);
2208 /* FIXME: We should here do what the m68k and i386
2209 backends do: if the reloc is pc-relative, record it
2210 in case it turns out that the reloc is unnecessary
2211 because the symbol is forced local by versioning or
2212 we are linking with -Bdynamic. Fortunately this
2213 case is not frequent. */
2223 /* Return the section that should be marked against GC for a given
2227 ppc_elf_gc_mark_hook (abfd
, info
, rel
, h
, sym
)
2229 struct bfd_link_info
*info
;
2230 Elf_Internal_Rela
*rel
;
2231 struct elf_link_hash_entry
*h
;
2232 Elf_Internal_Sym
*sym
;
2236 switch (ELF32_R_TYPE (rel
->r_info
))
2238 case R_PPC_GNU_VTINHERIT
:
2239 case R_PPC_GNU_VTENTRY
:
2243 switch (h
->root
.type
)
2245 case bfd_link_hash_defined
:
2246 case bfd_link_hash_defweak
:
2247 return h
->root
.u
.def
.section
;
2249 case bfd_link_hash_common
:
2250 return h
->root
.u
.c
.p
->section
;
2256 if (!(elf_bad_symtab (abfd
)
2257 && ELF_ST_BIND (sym
->st_info
) != STB_LOCAL
)
2258 && ! ((sym
->st_shndx
<= 0 || sym
->st_shndx
>= SHN_LORESERVE
)
2259 && sym
->st_shndx
!= SHN_COMMON
))
2261 return bfd_section_from_elf_index (abfd
, sym
->st_shndx
);
2268 /* Update the got entry reference counts for the section being removed. */
2271 ppc_elf_gc_sweep_hook (abfd
, info
, sec
, relocs
)
2273 struct bfd_link_info
*info
;
2275 const Elf_Internal_Rela
*relocs
;
2277 Elf_Internal_Shdr
*symtab_hdr
;
2278 struct elf_link_hash_entry
**sym_hashes
;
2279 bfd_signed_vma
*local_got_refcounts
;
2280 const Elf_Internal_Rela
*rel
, *relend
;
2281 unsigned long r_symndx
;
2282 struct elf_link_hash_entry
*h
;
2284 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
2285 sym_hashes
= elf_sym_hashes (abfd
);
2286 local_got_refcounts
= elf_local_got_refcounts (abfd
);
2288 relend
= relocs
+ sec
->reloc_count
;
2289 for (rel
= relocs
; rel
< relend
; rel
++)
2290 switch (ELF32_R_TYPE (rel
->r_info
))
2293 case R_PPC_GOT16_LO
:
2294 case R_PPC_GOT16_HI
:
2295 case R_PPC_GOT16_HA
:
2296 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2297 if (r_symndx
>= symtab_hdr
->sh_info
)
2299 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2300 if (h
->got
.refcount
> 0)
2305 if (local_got_refcounts
[r_symndx
] > 0)
2306 local_got_refcounts
[r_symndx
]--;
2311 case R_PPC_PLTREL24
:
2312 case R_PPC_PLT16_LO
:
2313 case R_PPC_PLT16_HI
:
2314 case R_PPC_PLT16_HA
:
2315 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2316 if (r_symndx
>= symtab_hdr
->sh_info
)
2318 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2319 if (h
->plt
.refcount
> 0)
2331 /* Hook called by the linker routine which adds symbols from an object
2332 file. We use it to put .comm items in .sbss, and not .bss. */
2336 ppc_elf_add_symbol_hook (abfd
, info
, sym
, namep
, flagsp
, secp
, valp
)
2338 struct bfd_link_info
*info
;
2339 const Elf_Internal_Sym
*sym
;
2345 if (sym
->st_shndx
== SHN_COMMON
2346 && !info
->relocateable
2347 && sym
->st_size
<= (bfd_vma
) bfd_get_gp_size (abfd
))
2349 /* Common symbols less than or equal to -G nn bytes are automatically
2351 elf_linker_section_t
*sdata
2352 = ppc_elf_create_linker_section (abfd
, info
, LINKER_SECTION_SDATA
);
2354 if (!sdata
->bss_section
)
2356 /* We don't go through bfd_make_section, because we don't
2357 want to attach this common section to DYNOBJ. The linker
2358 will move the symbols to the appropriate output section
2359 when it defines common symbols. */
2360 sdata
->bss_section
= ((asection
*)
2361 bfd_zalloc (abfd
, sizeof (asection
)));
2362 if (sdata
->bss_section
== NULL
)
2364 sdata
->bss_section
->name
= sdata
->bss_name
;
2365 sdata
->bss_section
->flags
= SEC_IS_COMMON
;
2366 sdata
->bss_section
->output_section
= sdata
->bss_section
;
2367 sdata
->bss_section
->symbol
=
2368 (asymbol
*) bfd_zalloc (abfd
, sizeof (asymbol
));
2369 sdata
->bss_section
->symbol_ptr_ptr
=
2370 (asymbol
**) bfd_zalloc (abfd
, sizeof (asymbol
*));
2371 if (sdata
->bss_section
->symbol
== NULL
2372 || sdata
->bss_section
->symbol_ptr_ptr
== NULL
)
2374 sdata
->bss_section
->symbol
->name
= sdata
->bss_name
;
2375 sdata
->bss_section
->symbol
->flags
= BSF_SECTION_SYM
;
2376 sdata
->bss_section
->symbol
->section
= sdata
->bss_section
;
2377 *sdata
->bss_section
->symbol_ptr_ptr
= sdata
->bss_section
->symbol
;
2380 *secp
= sdata
->bss_section
;
2381 *valp
= sym
->st_size
;
2388 /* Finish up dynamic symbol handling. We set the contents of various
2389 dynamic sections here. */
2392 ppc_elf_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
2394 struct bfd_link_info
*info
;
2395 struct elf_link_hash_entry
*h
;
2396 Elf_Internal_Sym
*sym
;
2401 fprintf (stderr
, "ppc_elf_finish_dynamic_symbol called for %s",
2402 h
->root
.root
.string
);
2405 dynobj
= elf_hash_table (info
)->dynobj
;
2406 BFD_ASSERT (dynobj
!= NULL
);
2408 if (h
->plt
.offset
!= (bfd_vma
) -1)
2412 Elf_Internal_Rela rela
;
2415 fprintf (stderr
, ", plt_offset = %d", h
->plt
.offset
);
2418 /* This symbol has an entry in the procedure linkage table. Set
2421 BFD_ASSERT (h
->dynindx
!= -1);
2423 splt
= bfd_get_section_by_name (dynobj
, ".plt");
2424 srela
= bfd_get_section_by_name (dynobj
, ".rela.plt");
2425 BFD_ASSERT (splt
!= NULL
&& srela
!= NULL
);
2427 /* We don't need to fill in the .plt. The ppc dynamic linker
2430 /* Fill in the entry in the .rela.plt section. */
2431 rela
.r_offset
= (splt
->output_section
->vma
2432 + splt
->output_offset
2434 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_PPC_JMP_SLOT
);
2436 bfd_elf32_swap_reloca_out (output_bfd
, &rela
,
2437 ((Elf32_External_Rela
*) srela
->contents
2438 + ((h
->plt
.offset
- PLT_INITIAL_ENTRY_SIZE
) / 8)));
2440 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
2442 /* Mark the symbol as undefined, rather than as defined in
2443 the .plt section. Leave the value alone. */
2444 sym
->st_shndx
= SHN_UNDEF
;
2448 if (h
->got
.offset
!= (bfd_vma
) -1)
2452 Elf_Internal_Rela rela
;
2454 /* This symbol has an entry in the global offset table. Set it
2457 sgot
= bfd_get_section_by_name (dynobj
, ".got");
2458 srela
= bfd_get_section_by_name (dynobj
, ".rela.got");
2459 BFD_ASSERT (sgot
!= NULL
&& srela
!= NULL
);
2461 rela
.r_offset
= (sgot
->output_section
->vma
2462 + sgot
->output_offset
2463 + (h
->got
.offset
&~ 1));
2465 /* If this is a -Bsymbolic link, and the symbol is defined
2466 locally, we just want to emit a RELATIVE reloc. The entry in
2467 the global offset table will already have been initialized in
2468 the relocate_section function. */
2470 && (info
->symbolic
|| h
->dynindx
== -1)
2471 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
))
2473 rela
.r_info
= ELF32_R_INFO (0, R_PPC_RELATIVE
);
2474 rela
.r_addend
= (h
->root
.u
.def
.value
2475 + h
->root
.u
.def
.section
->output_section
->vma
2476 + h
->root
.u
.def
.section
->output_offset
);
2480 BFD_ASSERT((h
->got
.offset
& 1) == 0);
2481 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ h
->got
.offset
);
2482 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_PPC_GLOB_DAT
);
2486 bfd_elf32_swap_reloca_out (output_bfd
, &rela
,
2487 ((Elf32_External_Rela
*) srela
->contents
2488 + srela
->reloc_count
));
2489 ++srela
->reloc_count
;
2492 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_COPY
) != 0)
2495 Elf_Internal_Rela rela
;
2497 /* This symbols needs a copy reloc. Set it up. */
2500 fprintf (stderr
, ", copy");
2503 BFD_ASSERT (h
->dynindx
!= -1);
2505 if (h
->size
<= elf_gp_size (dynobj
))
2506 s
= bfd_get_section_by_name (h
->root
.u
.def
.section
->owner
,
2509 s
= bfd_get_section_by_name (h
->root
.u
.def
.section
->owner
,
2511 BFD_ASSERT (s
!= NULL
);
2513 rela
.r_offset
= (h
->root
.u
.def
.value
2514 + h
->root
.u
.def
.section
->output_section
->vma
2515 + h
->root
.u
.def
.section
->output_offset
);
2516 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_PPC_COPY
);
2518 bfd_elf32_swap_reloca_out (output_bfd
, &rela
,
2519 ((Elf32_External_Rela
*) s
->contents
2525 fprintf (stderr
, "\n");
2528 /* Mark some specially defined symbols as absolute. */
2529 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
2530 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0
2531 || strcmp (h
->root
.root
.string
, "_PROCEDURE_LINKAGE_TABLE_") == 0)
2532 sym
->st_shndx
= SHN_ABS
;
2538 /* Finish up the dynamic sections. */
2541 ppc_elf_finish_dynamic_sections (output_bfd
, info
)
2543 struct bfd_link_info
*info
;
2546 bfd
*dynobj
= elf_hash_table (info
)->dynobj
;
2547 asection
*sgot
= bfd_get_section_by_name (dynobj
, ".got");
2550 fprintf (stderr
, "ppc_elf_finish_dynamic_sections called\n");
2553 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
2555 if (elf_hash_table (info
)->dynamic_sections_created
)
2558 Elf32_External_Dyn
*dyncon
, *dynconend
;
2560 splt
= bfd_get_section_by_name (dynobj
, ".plt");
2561 BFD_ASSERT (splt
!= NULL
&& sdyn
!= NULL
);
2563 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
2564 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
2565 for (; dyncon
< dynconend
; dyncon
++)
2567 Elf_Internal_Dyn dyn
;
2571 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
2575 case DT_PLTGOT
: name
= ".plt"; size
= false; break;
2576 case DT_PLTRELSZ
: name
= ".rela.plt"; size
= true; break;
2577 case DT_JMPREL
: name
= ".rela.plt"; size
= false; break;
2578 default: name
= NULL
; size
= false; break;
2585 s
= bfd_get_section_by_name (output_bfd
, name
);
2591 dyn
.d_un
.d_ptr
= s
->vma
;
2594 if (s
->_cooked_size
!= 0)
2595 dyn
.d_un
.d_val
= s
->_cooked_size
;
2597 dyn
.d_un
.d_val
= s
->_raw_size
;
2600 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
2605 /* Add a blrl instruction at _GLOBAL_OFFSET_TABLE_-4 so that a function can
2606 easily find the address of the _GLOBAL_OFFSET_TABLE_. */
2609 unsigned char *contents
= sgot
->contents
;
2610 bfd_put_32 (output_bfd
, 0x4e800021 /* blrl */, contents
);
2613 bfd_put_32 (output_bfd
, (bfd_vma
) 0, contents
+4);
2615 bfd_put_32 (output_bfd
,
2616 sdyn
->output_section
->vma
+ sdyn
->output_offset
,
2619 elf_section_data (sgot
->output_section
)->this_hdr
.sh_entsize
= 4;
2626 Elf_Internal_Sym sym
;
2629 /* Set up the section symbols for the output sections. */
2631 sdynsym
= bfd_get_section_by_name (dynobj
, ".dynsym");
2632 BFD_ASSERT (sdynsym
!= NULL
);
2636 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_SECTION
);
2639 for (s
= output_bfd
->sections
; s
!= NULL
; s
= s
->next
)
2643 sym
.st_value
= s
->vma
;
2645 indx
= elf_section_data (s
)->this_idx
;
2646 dindx
= elf_section_data (s
)->dynindx
;
2649 BFD_ASSERT(indx
> 0);
2650 BFD_ASSERT(dindx
> 0);
2652 if (dindx
> maxdindx
)
2655 sym
.st_shndx
= indx
;
2657 bfd_elf32_swap_symbol_out (output_bfd
, &sym
,
2658 (PTR
) (((Elf32_External_Sym
*)
2664 /* Set the sh_info field of the output .dynsym section to the
2665 index of the first global symbol. */
2666 elf_section_data (sdynsym
->output_section
)->this_hdr
.sh_info
=
2674 /* The RELOCATE_SECTION function is called by the ELF backend linker
2675 to handle the relocations for a section.
2677 The relocs are always passed as Rela structures; if the section
2678 actually uses Rel structures, the r_addend field will always be
2681 This function is responsible for adjust the section contents as
2682 necessary, and (if using Rela relocs and generating a
2683 relocateable output file) adjusting the reloc addend as
2686 This function does not have to worry about setting the reloc
2687 address or the reloc symbol index.
2689 LOCAL_SYMS is a pointer to the swapped in local symbols.
2691 LOCAL_SECTIONS is an array giving the section in the input file
2692 corresponding to the st_shndx field of each local symbol.
2694 The global hash table entry for the global symbols can be found
2695 via elf_sym_hashes (input_bfd).
2697 When generating relocateable output, this function must handle
2698 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
2699 going to be the section symbol corresponding to the output
2700 section, which means that the addend must be adjusted
2704 ppc_elf_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
2705 contents
, relocs
, local_syms
, local_sections
)
2707 struct bfd_link_info
*info
;
2709 asection
*input_section
;
2711 Elf_Internal_Rela
*relocs
;
2712 Elf_Internal_Sym
*local_syms
;
2713 asection
**local_sections
;
2715 Elf_Internal_Shdr
*symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
2716 struct elf_link_hash_entry
**sym_hashes
= elf_sym_hashes (input_bfd
);
2717 bfd
*dynobj
= elf_hash_table (info
)->dynobj
;
2718 elf_linker_section_t
*sdata
= (dynobj
) ? elf_linker_section (dynobj
, LINKER_SECTION_SDATA
) : NULL
;
2719 elf_linker_section_t
*sdata2
= (dynobj
) ? elf_linker_section (dynobj
, LINKER_SECTION_SDATA2
) : NULL
;
2720 Elf_Internal_Rela
*rel
= relocs
;
2721 Elf_Internal_Rela
*relend
= relocs
+ input_section
->reloc_count
;
2722 asection
*sreloc
= NULL
;
2723 asection
*splt
= NULL
;
2724 asection
*sgot
= NULL
;
2725 bfd_vma
*local_got_offsets
;
2730 fprintf (stderr
, "ppc_elf_relocate_section called for %s section %s, %ld relocations%s\n",
2731 bfd_get_filename (input_bfd
),
2732 bfd_section_name(input_bfd
, input_section
),
2733 (long)input_section
->reloc_count
,
2734 (info
->relocateable
) ? " (relocatable)" : "");
2737 if (!ppc_elf_howto_table
[ R_PPC_ADDR32
]) /* Initialize howto table if needed */
2738 ppc_elf_howto_init ();
2740 local_got_offsets
= elf_local_got_offsets (input_bfd
);
2742 for (; rel
< relend
; rel
++)
2744 enum ppc_reloc_type r_type
= (enum ppc_reloc_type
)ELF32_R_TYPE (rel
->r_info
);
2745 bfd_vma offset
= rel
->r_offset
;
2746 bfd_vma addend
= rel
->r_addend
;
2747 bfd_reloc_status_type r
= bfd_reloc_other
;
2748 Elf_Internal_Sym
*sym
= (Elf_Internal_Sym
*)0;
2749 asection
*sec
= (asection
*)0;
2750 struct elf_link_hash_entry
*h
= (struct elf_link_hash_entry
*)0;
2751 const char *sym_name
= (const char *)0;
2752 reloc_howto_type
*howto
;
2753 unsigned long r_symndx
;
2756 /* Unknown relocation handling */
2757 if ((unsigned)r_type
>= (unsigned)R_PPC_max
|| !ppc_elf_howto_table
[(int)r_type
])
2759 (*_bfd_error_handler
) (_("%s: unknown relocation type %d"),
2760 bfd_get_filename (input_bfd
),
2763 bfd_set_error (bfd_error_bad_value
);
2768 howto
= ppc_elf_howto_table
[(int)r_type
];
2769 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2771 if (info
->relocateable
)
2773 /* This is a relocateable link. We don't have to change
2774 anything, unless the reloc is against a section symbol,
2775 in which case we have to adjust according to where the
2776 section symbol winds up in the output section. */
2777 if (r_symndx
< symtab_hdr
->sh_info
)
2779 sym
= local_syms
+ r_symndx
;
2780 if ((unsigned)ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
2782 sec
= local_sections
[r_symndx
];
2783 addend
= rel
->r_addend
+= sec
->output_offset
+ sym
->st_value
;
2788 fprintf (stderr
, "\ttype = %s (%d), symbol index = %ld, offset = %ld, addend = %ld\n",
2798 /* This is a final link. */
2799 if (r_symndx
< symtab_hdr
->sh_info
)
2801 sym
= local_syms
+ r_symndx
;
2802 sec
= local_sections
[r_symndx
];
2803 sym_name
= "<local symbol>";
2805 relocation
= (sec
->output_section
->vma
2806 + sec
->output_offset
2811 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2812 while (h
->root
.type
== bfd_link_hash_indirect
2813 || h
->root
.type
== bfd_link_hash_warning
)
2814 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2815 sym_name
= h
->root
.root
.string
;
2816 if (h
->root
.type
== bfd_link_hash_defined
2817 || h
->root
.type
== bfd_link_hash_defweak
)
2819 sec
= h
->root
.u
.def
.section
;
2820 if ((r_type
== R_PPC_PLT32
2821 && h
->plt
.offset
!= (bfd_vma
) -1)
2822 || (r_type
== R_PPC_LOCAL24PC
2823 && sec
->output_section
== NULL
)
2824 || ((r_type
== R_PPC_GOT16
2825 || r_type
== R_PPC_GOT16_LO
2826 || r_type
== R_PPC_GOT16_HI
2827 || r_type
== R_PPC_GOT16_HA
)
2828 && elf_hash_table (info
)->dynamic_sections_created
2830 || (! info
->symbolic
&& h
->dynindx
!= -1)
2831 || (h
->elf_link_hash_flags
2832 & ELF_LINK_HASH_DEF_REGULAR
) == 0))
2834 && ((! info
->symbolic
&& h
->dynindx
!= -1)
2835 || (h
->elf_link_hash_flags
2836 & ELF_LINK_HASH_DEF_REGULAR
) == 0)
2837 && (input_section
->flags
& SEC_ALLOC
) != 0
2838 && (r_type
== R_PPC_ADDR32
2839 || r_type
== R_PPC_ADDR24
2840 || r_type
== R_PPC_ADDR16
2841 || r_type
== R_PPC_ADDR16_LO
2842 || r_type
== R_PPC_ADDR16_HI
2843 || r_type
== R_PPC_ADDR16_HA
2844 || r_type
== R_PPC_ADDR14
2845 || r_type
== R_PPC_ADDR14_BRTAKEN
2846 || r_type
== R_PPC_ADDR14_BRNTAKEN
2847 || r_type
== R_PPC_PLTREL24
2848 || r_type
== R_PPC_COPY
2849 || r_type
== R_PPC_GLOB_DAT
2850 || r_type
== R_PPC_JMP_SLOT
2851 || r_type
== R_PPC_UADDR32
2852 || r_type
== R_PPC_UADDR16
2853 || r_type
== R_PPC_SDAREL16
2854 || r_type
== R_PPC_EMB_NADDR32
2855 || r_type
== R_PPC_EMB_NADDR16
2856 || r_type
== R_PPC_EMB_NADDR16_LO
2857 || r_type
== R_PPC_EMB_NADDR16_HI
2858 || r_type
== R_PPC_EMB_NADDR16_HA
2859 || r_type
== R_PPC_EMB_SDAI16
2860 || r_type
== R_PPC_EMB_SDA2I16
2861 || r_type
== R_PPC_EMB_SDA2REL
2862 || r_type
== R_PPC_EMB_SDA21
2863 || r_type
== R_PPC_EMB_MRKREF
2864 || r_type
== R_PPC_EMB_BIT_FLD
2865 || r_type
== R_PPC_EMB_RELSDA
2866 || ((r_type
== R_PPC_REL24
2867 || r_type
== R_PPC_REL32
2868 || r_type
== R_PPC_REL14
2869 || r_type
== R_PPC_REL14_BRTAKEN
2870 || r_type
== R_PPC_REL14_BRNTAKEN
2871 || r_type
== R_PPC_RELATIVE
)
2872 && strcmp (h
->root
.root
.string
,
2873 "_GLOBAL_OFFSET_TABLE_") != 0))))
2875 /* In these cases, we don't need the relocation
2876 value. We check specially because in some
2877 obscure cases sec->output_section will be NULL. */
2881 relocation
= (h
->root
.u
.def
.value
2882 + sec
->output_section
->vma
2883 + sec
->output_offset
);
2885 else if (h
->root
.type
== bfd_link_hash_undefweak
)
2887 else if (info
->shared
)
2891 (*info
->callbacks
->undefined_symbol
)(info
,
2892 h
->root
.root
.string
,
2901 switch ((int)r_type
)
2904 (*_bfd_error_handler
) (_("%s: unknown relocation type %d for symbol %s"),
2905 bfd_get_filename (input_bfd
),
2906 (int)r_type
, sym_name
);
2908 bfd_set_error (bfd_error_bad_value
);
2912 /* Relocations that need no special processing. */
2913 case (int)R_PPC_LOCAL24PC
:
2914 /* It makes no sense to point a local relocation
2915 at a symbol not in this object. */
2917 && (h
->root
.type
== bfd_link_hash_defined
2918 || h
->root
.type
== bfd_link_hash_defweak
)
2919 && sec
->output_section
== NULL
)
2921 (*info
->callbacks
->undefined_symbol
) (info
,
2922 h
->root
.root
.string
,
2931 /* Relocations that may need to be propagated if this is a shared
2933 case (int)R_PPC_REL24
:
2934 case (int)R_PPC_REL32
:
2935 case (int)R_PPC_REL14
:
2936 /* If these relocations are not to a named symbol, they can be
2937 handled right here, no need to bother the dynamic linker. */
2939 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
2943 /* Relocations that always need to be propagated if this is a shared
2945 case (int)R_PPC_NONE
:
2946 case (int)R_PPC_ADDR32
:
2947 case (int)R_PPC_ADDR24
:
2948 case (int)R_PPC_ADDR16
:
2949 case (int)R_PPC_ADDR16_LO
:
2950 case (int)R_PPC_ADDR16_HI
:
2951 case (int)R_PPC_ADDR16_HA
:
2952 case (int)R_PPC_ADDR14
:
2953 case (int)R_PPC_UADDR32
:
2954 case (int)R_PPC_UADDR16
:
2957 Elf_Internal_Rela outrel
;
2961 fprintf (stderr
, "ppc_elf_relocate_section need to create relocation for %s\n",
2962 (h
&& h
->root
.root
.string
) ? h
->root
.root
.string
: "<unknown>");
2965 /* When generating a shared object, these relocations
2966 are copied into the output file to be resolved at run
2973 name
= (bfd_elf_string_from_elf_section
2975 elf_elfheader (input_bfd
)->e_shstrndx
,
2976 elf_section_data (input_section
)->rel_hdr
.sh_name
));
2980 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
2981 && strcmp (bfd_get_section_name (input_bfd
,
2985 sreloc
= bfd_get_section_by_name (dynobj
, name
);
2986 BFD_ASSERT (sreloc
!= NULL
);
2991 if (elf_section_data (input_section
)->stab_info
== NULL
)
2992 outrel
.r_offset
= rel
->r_offset
;
2997 off
= (_bfd_stab_section_offset
2998 (output_bfd
, &elf_hash_table (info
)->stab_info
,
3000 &elf_section_data (input_section
)->stab_info
,
3002 if (off
== (bfd_vma
) -1)
3004 outrel
.r_offset
= off
;
3007 outrel
.r_offset
+= (input_section
->output_section
->vma
3008 + input_section
->output_offset
);
3011 memset (&outrel
, 0, sizeof outrel
);
3012 /* h->dynindx may be -1 if this symbol was marked to
3015 && ((! info
->symbolic
&& h
->dynindx
!= -1)
3016 || (h
->elf_link_hash_flags
3017 & ELF_LINK_HASH_DEF_REGULAR
) == 0))
3019 BFD_ASSERT (h
->dynindx
!= -1);
3020 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
3021 outrel
.r_addend
= rel
->r_addend
;
3025 if (r_type
== R_PPC_ADDR32
)
3027 outrel
.r_info
= ELF32_R_INFO (0, R_PPC_RELATIVE
);
3028 outrel
.r_addend
= relocation
+ rel
->r_addend
;
3035 sec
= local_sections
[r_symndx
];
3038 BFD_ASSERT (h
->root
.type
== bfd_link_hash_defined
3040 == bfd_link_hash_defweak
));
3041 sec
= h
->root
.u
.def
.section
;
3043 if (sec
!= NULL
&& bfd_is_abs_section (sec
))
3045 else if (sec
== NULL
|| sec
->owner
== NULL
)
3047 bfd_set_error (bfd_error_bad_value
);
3054 osec
= sec
->output_section
;
3055 indx
= elf_section_data (osec
)->dynindx
;
3056 BFD_ASSERT(indx
> 0);
3060 printf("indx=%d section=%s flags=%08x name=%s\n",
3061 indx
, osec
->name
, osec
->flags
,
3062 h
->root
.root
.string
);
3067 outrel
.r_info
= ELF32_R_INFO (indx
, r_type
);
3068 outrel
.r_addend
= relocation
+ rel
->r_addend
;
3072 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
,
3073 (((Elf32_External_Rela
*)
3075 + sreloc
->reloc_count
));
3076 ++sreloc
->reloc_count
;
3078 /* This reloc will be computed at runtime, so there's no
3079 need to do anything now, unless this is a RELATIVE
3080 reloc in an unallocated section. */
3082 || (input_section
->flags
& SEC_ALLOC
) != 0
3083 || ELF32_R_TYPE (outrel
.r_info
) != R_PPC_RELATIVE
)
3087 /* Arithmetic adjust relocations that aren't going into a
3089 if (r_type
== R_PPC_ADDR16_HA
3090 /* It's just possible that this symbol is a weak symbol
3091 that's not actually defined anywhere. In that case,
3092 'sec' would be NULL, and we should leave the symbol
3093 alone (it will be set to zero elsewhere in the link). */
3096 addend
+= ((relocation
+ addend
) & 0x8000) << 1;
3100 /* branch taken prediction relocations */
3101 case (int)R_PPC_ADDR14_BRTAKEN
:
3102 case (int)R_PPC_REL14_BRTAKEN
:
3103 insn
= bfd_get_32 (output_bfd
, contents
+ offset
);
3104 if ((relocation
- offset
) & 0x8000)
3105 insn
&= ~BRANCH_PREDICT_BIT
;
3107 insn
|= BRANCH_PREDICT_BIT
;
3108 bfd_put_32 (output_bfd
, insn
, contents
+ offset
);
3111 /* branch not taken predicition relocations */
3112 case (int)R_PPC_ADDR14_BRNTAKEN
:
3113 case (int)R_PPC_REL14_BRNTAKEN
:
3114 insn
= bfd_get_32 (output_bfd
, contents
+ offset
);
3115 if ((relocation
- offset
) & 0x8000)
3116 insn
|= BRANCH_PREDICT_BIT
;
3118 insn
&= ~BRANCH_PREDICT_BIT
;
3119 bfd_put_32 (output_bfd
, insn
, contents
+ offset
);
3122 /* GOT16 relocations */
3123 case (int)R_PPC_GOT16
:
3124 case (int)R_PPC_GOT16_LO
:
3125 case (int)R_PPC_GOT16_HI
:
3126 case (int)R_PPC_GOT16_HA
:
3127 /* Relocation is to the entry for this symbol in the global
3131 sgot
= bfd_get_section_by_name (dynobj
, ".got");
3132 BFD_ASSERT (sgot
!= NULL
);
3139 off
= h
->got
.offset
;
3140 BFD_ASSERT (off
!= (bfd_vma
) -1);
3142 if (! elf_hash_table (info
)->dynamic_sections_created
3144 && (info
->symbolic
|| h
->dynindx
== -1)
3145 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
)))
3147 /* This is actually a static link, or it is a
3148 -Bsymbolic link and the symbol is defined
3149 locally. We must initialize this entry in the
3150 global offset table. Since the offset must
3151 always be a multiple of 4, we use the least
3152 significant bit to record whether we have
3153 initialized it already.
3155 When doing a dynamic link, we create a .rela.got
3156 relocation entry to initialize the value. This
3157 is done in the finish_dynamic_symbol routine. */
3162 bfd_put_32 (output_bfd
, relocation
,
3163 sgot
->contents
+ off
);
3168 relocation
= sgot
->output_offset
+ off
- 4;
3174 BFD_ASSERT (local_got_offsets
!= NULL
3175 && local_got_offsets
[r_symndx
] != (bfd_vma
) -1);
3177 off
= local_got_offsets
[r_symndx
];
3179 /* The offset must always be a multiple of 4. We use
3180 the least significant bit to record whether we have
3181 already processed this entry. */
3186 bfd_put_32 (output_bfd
, relocation
, sgot
->contents
+ off
);
3191 Elf_Internal_Rela outrel
;
3193 /* We need to generate a R_PPC_RELATIVE reloc
3194 for the dynamic linker. */
3195 srelgot
= bfd_get_section_by_name (dynobj
, ".rela.got");
3196 BFD_ASSERT (srelgot
!= NULL
);
3198 outrel
.r_offset
= (sgot
->output_section
->vma
3199 + sgot
->output_offset
3201 outrel
.r_info
= ELF32_R_INFO (0, R_PPC_RELATIVE
);
3202 outrel
.r_addend
= relocation
;
3203 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
,
3204 (((Elf32_External_Rela
*)
3206 + srelgot
->reloc_count
));
3207 ++srelgot
->reloc_count
;
3210 local_got_offsets
[r_symndx
] |= 1;
3213 relocation
= sgot
->output_offset
+ off
- 4;
3217 /* Indirect .sdata relocation */
3218 case (int)R_PPC_EMB_SDAI16
:
3219 BFD_ASSERT (sdata
!= NULL
);
3220 relocation
= bfd_elf32_finish_pointer_linker_section (output_bfd
, input_bfd
, info
,
3221 sdata
, h
, relocation
, rel
,
3225 /* Indirect .sdata2 relocation */
3226 case (int)R_PPC_EMB_SDA2I16
:
3227 BFD_ASSERT (sdata2
!= NULL
);
3228 relocation
= bfd_elf32_finish_pointer_linker_section (output_bfd
, input_bfd
, info
,
3229 sdata2
, h
, relocation
, rel
,
3233 /* Handle the TOC16 reloc. We want to use the offset within the .got
3234 section, not the actual VMA. This is appropriate when generating
3235 an embedded ELF object, for which the .got section acts like the
3236 AIX .toc section. */
3237 case (int)R_PPC_TOC16
: /* phony GOT16 relocations */
3238 BFD_ASSERT (sec
!= (asection
*)0);
3239 BFD_ASSERT (bfd_is_und_section (sec
)
3240 || strcmp (bfd_get_section_name (abfd
, sec
), ".got") == 0
3241 || strcmp (bfd_get_section_name (abfd
, sec
), ".cgot") == 0)
3243 addend
-= sec
->output_section
->vma
+ sec
->output_offset
+ 0x8000;
3246 case (int)R_PPC_PLTREL24
:
3247 /* Relocation is to the entry for this symbol in the
3248 procedure linkage table. */
3249 BFD_ASSERT (h
!= NULL
);
3251 if (h
->plt
.offset
== (bfd_vma
) -1)
3253 /* We didn't make a PLT entry for this symbol. This
3254 happens when statically linking PIC code, or when
3255 using -Bsymbolic. */
3261 splt
= bfd_get_section_by_name (dynobj
, ".plt");
3262 BFD_ASSERT (splt
!= NULL
);
3265 relocation
= (splt
->output_section
->vma
3266 + splt
->output_offset
3270 /* relocate against _SDA_BASE_ */
3271 case (int)R_PPC_SDAREL16
:
3272 BFD_ASSERT (sec
!= (asection
*)0);
3273 if (strcmp (bfd_get_section_name (abfd
, sec
), ".sdata") != 0
3274 && strcmp (bfd_get_section_name (abfd
, sec
), ".dynsbss") != 0
3275 && strcmp (bfd_get_section_name (abfd
, sec
), ".sbss") != 0)
3277 (*_bfd_error_handler
) (_("%s: The target (%s) of a %s relocation is in the wrong section (%s)"),
3278 bfd_get_filename (input_bfd
),
3280 ppc_elf_howto_table
[ (int)r_type
]->name
,
3281 bfd_get_section_name (abfd
, sec
));
3283 bfd_set_error (bfd_error_bad_value
);
3287 addend
-= (sdata
->sym_hash
->root
.u
.def
.value
3288 + sdata
->sym_hash
->root
.u
.def
.section
->output_section
->vma
3289 + sdata
->sym_hash
->root
.u
.def
.section
->output_offset
);
3293 /* relocate against _SDA2_BASE_ */
3294 case (int)R_PPC_EMB_SDA2REL
:
3295 BFD_ASSERT (sec
!= (asection
*)0);
3296 if (strcmp (bfd_get_section_name (abfd
, sec
), ".sdata2") != 0
3297 && strcmp (bfd_get_section_name (abfd
, sec
), ".sbss2") != 0)
3299 (*_bfd_error_handler
) (_("%s: The target (%s) of a %s relocation is in the wrong section (%s)"),
3300 bfd_get_filename (input_bfd
),
3302 ppc_elf_howto_table
[ (int)r_type
]->name
,
3303 bfd_get_section_name (abfd
, sec
));
3305 bfd_set_error (bfd_error_bad_value
);
3309 addend
-= (sdata2
->sym_hash
->root
.u
.def
.value
3310 + sdata2
->sym_hash
->root
.u
.def
.section
->output_section
->vma
3311 + sdata2
->sym_hash
->root
.u
.def
.section
->output_offset
);
3315 /* relocate against either _SDA_BASE_, _SDA2_BASE_, or 0 */
3316 case (int)R_PPC_EMB_SDA21
:
3317 case (int)R_PPC_EMB_RELSDA
:
3319 const char *name
= bfd_get_section_name (abfd
, sec
);
3322 BFD_ASSERT (sec
!= (asection
*)0);
3323 if (strcmp (name
, ".sdata") == 0 || strcmp (name
, ".sbss") == 0)
3326 addend
-= (sdata
->sym_hash
->root
.u
.def
.value
3327 + sdata
->sym_hash
->root
.u
.def
.section
->output_section
->vma
3328 + sdata
->sym_hash
->root
.u
.def
.section
->output_offset
);
3331 else if (strcmp (name
, ".sdata2") == 0 || strcmp (name
, ".sbss2") == 0)
3334 addend
-= (sdata2
->sym_hash
->root
.u
.def
.value
3335 + sdata2
->sym_hash
->root
.u
.def
.section
->output_section
->vma
3336 + sdata2
->sym_hash
->root
.u
.def
.section
->output_offset
);
3339 else if (strcmp (name
, ".PPC.EMB.sdata0") == 0 || strcmp (name
, ".PPC.EMB.sbss0") == 0)
3346 (*_bfd_error_handler
) (_("%s: The target (%s) of a %s relocation is in the wrong section (%s)"),
3347 bfd_get_filename (input_bfd
),
3349 ppc_elf_howto_table
[ (int)r_type
]->name
,
3350 bfd_get_section_name (abfd
, sec
));
3352 bfd_set_error (bfd_error_bad_value
);
3357 if (r_type
== R_PPC_EMB_SDA21
)
3358 { /* fill in register field */
3359 insn
= bfd_get_32 (output_bfd
, contents
+ offset
);
3360 insn
= (insn
& ~RA_REGISTER_MASK
) | (reg
<< RA_REGISTER_SHIFT
);
3361 bfd_put_32 (output_bfd
, insn
, contents
+ offset
);
3366 /* Relocate against the beginning of the section */
3367 case (int)R_PPC_SECTOFF
:
3368 case (int)R_PPC_SECTOFF_LO
:
3369 case (int)R_PPC_SECTOFF_HI
:
3370 BFD_ASSERT (sec
!= (asection
*)0);
3371 addend
-= sec
->output_section
->vma
;
3374 case (int)R_PPC_SECTOFF_HA
:
3375 BFD_ASSERT (sec
!= (asection
*)0);
3376 addend
-= sec
->output_section
->vma
;
3377 addend
+= ((relocation
+ addend
) & 0x8000) << 1;
3380 /* Negative relocations */
3381 case (int)R_PPC_EMB_NADDR32
:
3382 case (int)R_PPC_EMB_NADDR16
:
3383 case (int)R_PPC_EMB_NADDR16_LO
:
3384 case (int)R_PPC_EMB_NADDR16_HI
:
3385 addend
-= 2*relocation
;
3388 case (int)R_PPC_EMB_NADDR16_HA
:
3389 addend
-= 2*relocation
;
3390 addend
+= ((relocation
+ addend
) & 0x8000) << 1;
3393 /* NOP relocation that prevents garbage collecting linkers from omitting a
3395 case (int)R_PPC_EMB_MRKREF
:
3398 case (int)R_PPC_COPY
:
3399 case (int)R_PPC_GLOB_DAT
:
3400 case (int)R_PPC_JMP_SLOT
:
3401 case (int)R_PPC_RELATIVE
:
3402 case (int)R_PPC_PLT32
:
3403 case (int)R_PPC_PLTREL32
:
3404 case (int)R_PPC_PLT16_LO
:
3405 case (int)R_PPC_PLT16_HI
:
3406 case (int)R_PPC_PLT16_HA
:
3407 case (int)R_PPC_EMB_RELSEC16
:
3408 case (int)R_PPC_EMB_RELST_LO
:
3409 case (int)R_PPC_EMB_RELST_HI
:
3410 case (int)R_PPC_EMB_RELST_HA
:
3411 case (int)R_PPC_EMB_BIT_FLD
:
3412 (*_bfd_error_handler
) (_("%s: Relocation %s is not yet supported for symbol %s."),
3413 bfd_get_filename (input_bfd
),
3414 ppc_elf_howto_table
[ (int)r_type
]->name
,
3417 bfd_set_error (bfd_error_invalid_operation
);
3421 case (int)R_PPC_GNU_VTINHERIT
:
3422 case (int)R_PPC_GNU_VTENTRY
:
3423 /* These are no-ops in the end. */
3429 fprintf (stderr
, "\ttype = %s (%d), name = %s, symbol index = %ld, offset = %ld, addend = %ld\n",
3438 r
= _bfd_final_link_relocate (howto
,
3446 if (r
!= bfd_reloc_ok
)
3454 case bfd_reloc_overflow
:
3459 name
= h
->root
.root
.string
;
3462 name
= bfd_elf_string_from_elf_section (input_bfd
,
3463 symtab_hdr
->sh_link
,
3469 name
= bfd_section_name (input_bfd
, sec
);
3472 (*info
->callbacks
->reloc_overflow
)(info
,
3488 fprintf (stderr
, "\n");
3495 #define TARGET_LITTLE_SYM bfd_elf32_powerpcle_vec
3496 #define TARGET_LITTLE_NAME "elf32-powerpcle"
3497 #define TARGET_BIG_SYM bfd_elf32_powerpc_vec
3498 #define TARGET_BIG_NAME "elf32-powerpc"
3499 #define ELF_ARCH bfd_arch_powerpc
3500 #define ELF_MACHINE_CODE EM_PPC
3501 #define ELF_MAXPAGESIZE 0x10000
3502 #define elf_info_to_howto ppc_elf_info_to_howto
3504 #ifdef EM_CYGNUS_POWERPC
3505 #define ELF_MACHINE_ALT1 EM_CYGNUS_POWERPC
3509 #define ELF_MACHINE_ALT2 EM_PPC_OLD
3512 #define elf_backend_plt_not_loaded 1
3513 #define elf_backend_got_symbol_offset 4
3514 #define elf_backend_can_gc_sections 1
3515 #define elf_backend_got_header_size 12
3516 #define elf_backend_plt_header_size PLT_INITIAL_ENTRY_SIZE
3518 #define bfd_elf32_bfd_copy_private_bfd_data ppc_elf_copy_private_bfd_data
3519 #define bfd_elf32_bfd_merge_private_bfd_data ppc_elf_merge_private_bfd_data
3520 #define bfd_elf32_bfd_set_private_flags ppc_elf_set_private_flags
3521 #define bfd_elf32_bfd_reloc_type_lookup ppc_elf_reloc_type_lookup
3522 #define bfd_elf32_bfd_final_link _bfd_elf32_gc_common_final_link
3524 #define elf_backend_gc_mark_hook ppc_elf_gc_mark_hook
3525 #define elf_backend_gc_sweep_hook ppc_elf_gc_sweep_hook
3526 #define elf_backend_section_from_shdr ppc_elf_section_from_shdr
3527 #define elf_backend_relocate_section ppc_elf_relocate_section
3528 #define elf_backend_create_dynamic_sections ppc_elf_create_dynamic_sections
3529 #define elf_backend_check_relocs ppc_elf_check_relocs
3530 #define elf_backend_adjust_dynamic_symbol ppc_elf_adjust_dynamic_symbol
3531 #define elf_backend_add_symbol_hook ppc_elf_add_symbol_hook
3532 #define elf_backend_size_dynamic_sections ppc_elf_size_dynamic_sections
3533 #define elf_backend_finish_dynamic_symbol ppc_elf_finish_dynamic_symbol
3534 #define elf_backend_finish_dynamic_sections ppc_elf_finish_dynamic_sections
3535 #define elf_backend_fake_sections ppc_elf_fake_sections
3536 #define elf_backend_additional_program_headers ppc_elf_additional_program_headers
3537 #define elf_backend_modify_segment_map ppc_elf_modify_segment_map
3539 #include "elf32-target.h"