1 /* PowerPC64-specific support for 64-bit ELF.
2 Copyright 1999, 2000, 2001 Free Software Foundation, Inc.
3 Written by Linus Nordberg, Swox AB <info@swox.com>,
4 based on elf32-ppc.c by Ian Lance Taylor.
6 This file is part of BFD, the Binary File Descriptor library.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
22 /* This file is based on the 64-bit PowerPC ELF ABI. It is also based
23 on the file elf32-ppc.c. */
32 #define USE_RELA /* we want RELA relocations, not REL. */
35 static void ppc_howto_init
37 static reloc_howto_type
*ppc64_elf_reloc_type_lookup
38 PARAMS ((bfd
*abfd
, bfd_reloc_code_real_type code
));
39 static void ppc64_elf_info_to_howto
40 PARAMS ((bfd
*abfd
, arelent
*cache_ptr
, Elf64_Internal_Rela
*dst
));
41 static bfd_reloc_status_type ppc64_elf_addr16_ha_reloc
42 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
43 static boolean ppc64_elf_set_private_flags
44 PARAMS ((bfd
*, flagword
));
45 static boolean ppc64_elf_copy_private_bfd_data
46 PARAMS ((bfd
*, bfd
*));
47 static boolean ppc64_elf_merge_private_bfd_data
48 PARAMS ((bfd
*, bfd
*));
49 static boolean ppc64_elf_section_from_shdr
50 PARAMS ((bfd
*, Elf64_Internal_Shdr
*, char *));
51 static boolean ppc64_elf_create_dynamic_sections
52 PARAMS ((bfd
*, struct bfd_link_info
*));
53 static boolean ppc64_elf_check_relocs
54 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
55 const Elf_Internal_Rela
*));
56 static asection
* ppc64_elf_gc_mark_hook
57 PARAMS ((bfd
*abfd
, struct bfd_link_info
*info
, Elf_Internal_Rela
*rel
,
58 struct elf_link_hash_entry
*h
, Elf_Internal_Sym
*sym
));
59 static boolean ppc64_elf_gc_sweep_hook
60 PARAMS ((bfd
*abfd
, struct bfd_link_info
*info
, asection
*sec
,
61 const Elf_Internal_Rela
*relocs
));
62 static boolean ppc64_elf_adjust_dynamic_symbol
63 PARAMS ((struct bfd_link_info
*, struct elf_link_hash_entry
*));
64 static boolean ppc_adjust_dynindx
65 PARAMS ((struct elf_link_hash_entry
*, PTR
));
66 static boolean ppc64_elf_size_dynamic_sections
67 PARAMS ((bfd
*, struct bfd_link_info
*));
68 static boolean ppc64_elf_final_link
69 PARAMS ((bfd
*, struct bfd_link_info
*));
70 static boolean ppc64_elf_fake_sections
71 PARAMS ((bfd
*, Elf64_Internal_Shdr
*, asection
*));
72 static boolean ppc64_elf_relocate_section
73 PARAMS ((bfd
*, struct bfd_link_info
*info
, bfd
*, asection
*, bfd_byte
*,
74 Elf_Internal_Rela
*relocs
, Elf_Internal_Sym
*local_syms
,
76 static boolean ppc64_elf_finish_dynamic_symbol
77 PARAMS ((bfd
*, struct bfd_link_info
*, struct elf_link_hash_entry
*,
79 static boolean ppc64_elf_finish_dynamic_sections
80 PARAMS ((bfd
*, struct bfd_link_info
*));
83 /* Branch prediction bit for branch taken relocs. */
84 #define BRANCH_PREDICT_BIT 0x200000
86 /* Mask to set RA in memory instructions. */
87 #define RA_REGISTER_MASK 0x001f0000
89 /* Value to shift register by to insert RA. */
90 #define RA_REGISTER_SHIFT 16
92 /* The name of the dynamic interpreter. This is put in the .interp
94 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
96 /* The size in bytes of an entry in the procedure linkage table. */
97 #define PLT_ENTRY_SIZE 24
99 /* The initial size of the plt reserved for the dynamic linker. */
100 #define PLT_INITIAL_ENTRY_SIZE 96
102 /* TOC base pointers offset from start of TOC. */
103 #define TOC_BASE_OFF (0x8000)
105 /* Global linkage stub. The first instruction has its offset patched. */
106 /* FIXME: Need traceback table? */
107 static const unsigned int ppc64_elf_glink_code
[] = {
108 0xe9820000, /* ld %r12,0(%r2) */
109 0xf8410028, /* std %r2,40(%r1) */
110 0xe80c0000, /* ld %r0,0(%r12) */
111 0xe84c0008, /* ld %r2,8(%r12) */
112 0x7c0903a6, /* mtctr %r0 */
113 0x4e800420 /* bctr */
116 #define PPC64_ELF_GLINK_SIZE \
117 ((sizeof ppc64_elf_glink_code / sizeof ppc64_elf_glink_code[0]) * 4)
119 /* Relocation HOWTO's. */
120 static reloc_howto_type
*ppc64_elf_howto_table
[(int) R_PPC_max
];
122 static reloc_howto_type ppc64_elf_howto_raw
[] = {
123 /* This reloc does nothing. */
124 HOWTO (R_PPC64_NONE
, /* type */
126 2, /* size (0 = byte, 1 = short, 2 = long) */
128 false, /* pc_relative */
130 complain_overflow_bitfield
, /* complain_on_overflow */
131 bfd_elf_generic_reloc
, /* special_function */
132 "R_PPC64_NONE", /* name */
133 false, /* partial_inplace */
136 false), /* pcrel_offset */
138 /* A standard 32 bit relocation. */
139 HOWTO (R_PPC64_ADDR32
, /* type */
141 2, /* size (0 = byte, 1 = short, 2 = long) */
143 false, /* pc_relative */
145 complain_overflow_bitfield
, /* complain_on_overflow */
146 bfd_elf_generic_reloc
, /* special_function */
147 "R_PPC64_ADDR32", /* name */
148 false, /* partial_inplace */
150 0xffffffff, /* dst_mask */
151 false), /* pcrel_offset */
153 /* An absolute 26 bit branch; the lower two bits must be zero.
154 FIXME: we don't check that, we just clear them. */
155 HOWTO (R_PPC64_ADDR24
, /* type */
157 2, /* size (0 = byte, 1 = short, 2 = long) */
159 false, /* pc_relative */
161 complain_overflow_bitfield
, /* complain_on_overflow */
162 bfd_elf_generic_reloc
, /* special_function */
163 "R_PPC64_ADDR24", /* name */
164 false, /* partial_inplace */
166 0x3fffffc, /* dst_mask */
167 false), /* pcrel_offset */
169 /* A standard 16 bit relocation. */
170 HOWTO (R_PPC64_ADDR16
, /* type */
172 1, /* size (0 = byte, 1 = short, 2 = long) */
174 false, /* pc_relative */
176 complain_overflow_bitfield
, /* complain_on_overflow */
177 bfd_elf_generic_reloc
, /* special_function */
178 "R_PPC64_ADDR16", /* name */
179 false, /* partial_inplace */
181 0xffff, /* dst_mask */
182 false), /* pcrel_offset */
184 /* A 16 bit relocation without overflow. */
185 HOWTO (R_PPC64_ADDR16_LO
, /* type */
187 1, /* size (0 = byte, 1 = short, 2 = long) */
189 false, /* pc_relative */
191 complain_overflow_dont
,/* complain_on_overflow */
192 bfd_elf_generic_reloc
, /* special_function */
193 "R_PPC64_ADDR16_LO", /* name */
194 false, /* partial_inplace */
196 0xffff, /* dst_mask */
197 false), /* pcrel_offset */
199 /* Bits 16-31 of an address. */
200 HOWTO (R_PPC64_ADDR16_HI
, /* type */
202 1, /* size (0 = byte, 1 = short, 2 = long) */
204 false, /* pc_relative */
206 complain_overflow_dont
, /* complain_on_overflow */
207 bfd_elf_generic_reloc
, /* special_function */
208 "R_PPC64_ADDR16_HI", /* name */
209 false, /* partial_inplace */
211 0xffff, /* dst_mask */
212 false), /* pcrel_offset */
214 /* Bits 16-31 of an address, plus 1 if the contents of the low 16
215 bits, treated as a signed number, is negative. */
216 HOWTO (R_PPC64_ADDR16_HA
, /* type */
218 1, /* size (0 = byte, 1 = short, 2 = long) */
220 false, /* pc_relative */
222 complain_overflow_dont
, /* complain_on_overflow */
223 ppc64_elf_addr16_ha_reloc
, /* special_function */
224 "R_PPC64_ADDR16_HA", /* name */
225 false, /* partial_inplace */
227 0xffff, /* dst_mask */
228 false), /* pcrel_offset */
230 /* An absolute 16 bit branch; the lower two bits must be zero.
231 FIXME: we don't check that, we just clear them. */
232 HOWTO (R_PPC64_ADDR14
, /* type */
234 2, /* size (0 = byte, 1 = short, 2 = long) */
236 false, /* pc_relative */
238 complain_overflow_bitfield
, /* complain_on_overflow */
239 bfd_elf_generic_reloc
, /* special_function */
240 "R_PPC64_ADDR14", /* name */
241 false, /* partial_inplace */
243 0xfffc, /* dst_mask */
244 false), /* pcrel_offset */
246 /* An absolute 16 bit branch, for which bit 10 should be set to
247 indicate that the branch is expected to be taken. The lower two
248 bits must be zero. */
249 HOWTO (R_PPC64_ADDR14_BRTAKEN
, /* type */
251 2, /* size (0 = byte, 1 = short, 2 = long) */
253 false, /* pc_relative */
255 complain_overflow_bitfield
, /* complain_on_overflow */
256 bfd_elf_generic_reloc
, /* special_function */
257 "R_PPC64_ADDR14_BRTAKEN",/* name */
258 false, /* partial_inplace */
260 0xfffc, /* dst_mask */
261 false), /* pcrel_offset */
263 /* An absolute 16 bit branch, for which bit 10 should be set to
264 indicate that the branch is not expected to be taken. The lower
265 two bits must be zero. */
266 HOWTO (R_PPC64_ADDR14_BRNTAKEN
, /* type */
268 2, /* size (0 = byte, 1 = short, 2 = long) */
270 false, /* pc_relative */
272 complain_overflow_bitfield
, /* complain_on_overflow */
273 bfd_elf_generic_reloc
, /* special_function */
274 "R_PPC64_ADDR14_BRNTAKEN",/* name */
275 false, /* partial_inplace */
277 0xfffc, /* dst_mask */
278 false), /* pcrel_offset */
280 /* A relative 26 bit branch; the lower two bits must be zero. */
281 HOWTO (R_PPC64_REL24
, /* type */
283 2, /* size (0 = byte, 1 = short, 2 = long) */
285 true, /* pc_relative */
287 complain_overflow_signed
, /* complain_on_overflow */
288 bfd_elf_generic_reloc
, /* special_function */
289 "R_PPC64_REL24", /* name */
290 false, /* partial_inplace */
292 0x3fffffc, /* dst_mask */
293 true), /* pcrel_offset */
295 /* A relative 16 bit branch; the lower two bits must be zero. */
296 HOWTO (R_PPC64_REL14
, /* type */
298 2, /* size (0 = byte, 1 = short, 2 = long) */
300 true, /* pc_relative */
302 complain_overflow_signed
, /* complain_on_overflow */
303 bfd_elf_generic_reloc
, /* special_function */
304 "R_PPC64_REL14", /* name */
305 false, /* partial_inplace */
307 0xfffc, /* dst_mask */
308 true), /* pcrel_offset */
310 /* A relative 16 bit branch. Bit 10 should be set to indicate that
311 the branch is expected to be taken. The lower two bits must be
313 HOWTO (R_PPC64_REL14_BRTAKEN
, /* type */
315 2, /* size (0 = byte, 1 = short, 2 = long) */
317 true, /* pc_relative */
319 complain_overflow_signed
, /* complain_on_overflow */
320 bfd_elf_generic_reloc
, /* special_function */
321 "R_PPC64_REL14_BRTAKEN", /* name */
322 false, /* partial_inplace */
324 0xfffc, /* dst_mask */
325 true), /* pcrel_offset */
327 /* A relative 16 bit branch. Bit 10 should be set to indicate that
328 the branch is not expected to be taken. The lower two bits must
330 HOWTO (R_PPC64_REL14_BRNTAKEN
, /* type */
332 2, /* size (0 = byte, 1 = short, 2 = long) */
334 true, /* pc_relative */
336 complain_overflow_signed
, /* complain_on_overflow */
337 bfd_elf_generic_reloc
, /* special_function */
338 "R_PPC64_REL14_BRNTAKEN",/* name */
339 false, /* partial_inplace */
341 0xfffc, /* dst_mask */
342 true), /* pcrel_offset */
344 /* Like R_PPC64_ADDR16, but referring to the GOT table entry for the
346 HOWTO (R_PPC64_GOT16
, /* type */
348 1, /* size (0 = byte, 1 = short, 2 = long) */
350 false, /* pc_relative */
352 complain_overflow_signed
, /* complain_on_overflow */
353 bfd_elf_generic_reloc
, /* special_function */
354 "R_PPC64_GOT16", /* name */
355 false, /* partial_inplace */
357 0xffff, /* dst_mask */
358 false), /* pcrel_offset */
360 /* Like R_PPC64_ADDR16_LO, but referring to the GOT table entry for
362 HOWTO (R_PPC64_GOT16_LO
, /* type */
364 1, /* size (0 = byte, 1 = short, 2 = long) */
366 false, /* pc_relative */
368 complain_overflow_dont
, /* complain_on_overflow */
369 bfd_elf_generic_reloc
, /* special_function */
370 "R_PPC64_GOT16_LO", /* name */
371 false, /* partial_inplace */
373 0xffff, /* dst_mask */
374 false), /* pcrel_offset */
376 /* Like R_PPC64_ADDR16_HI, but referring to the GOT table entry for
378 HOWTO (R_PPC64_GOT16_HI
, /* type */
380 1, /* size (0 = byte, 1 = short, 2 = long) */
382 false, /* pc_relative */
384 complain_overflow_dont
,/* complain_on_overflow */
385 bfd_elf_generic_reloc
, /* special_function */
386 "R_PPC64_GOT16_HI", /* name */
387 false, /* partial_inplace */
389 0xffff, /* dst_mask */
390 false), /* pcrel_offset */
392 /* Like R_PPC64_ADDR16_HA, but referring to the GOT table entry for
394 HOWTO (R_PPC64_GOT16_HA
, /* type */
396 1, /* size (0 = byte, 1 = short, 2 = long) */
398 false, /* pc_relative */
400 complain_overflow_dont
,/* complain_on_overflow */
401 ppc64_elf_addr16_ha_reloc
, /* special_function */
402 "R_PPC64_GOT16_HA", /* name */
403 false, /* partial_inplace */
405 0xffff, /* dst_mask */
406 false), /* pcrel_offset */
408 /* This is used only by the dynamic linker. The symbol should exist
409 both in the object being run and in some shared library. The
410 dynamic linker copies the data addressed by the symbol from the
411 shared library into the object, because the object being
412 run has to have the data at some particular address. */
413 HOWTO (R_PPC64_COPY
, /* type */
415 2, /* size (0 = byte, 1 = short, 2 = long) */
417 false, /* pc_relative */
419 complain_overflow_bitfield
, /* complain_on_overflow */
420 bfd_elf_generic_reloc
, /* special_function */
421 "R_PPC64_COPY", /* name */
422 false, /* partial_inplace */
425 false), /* pcrel_offset */
427 /* Like R_PPC64_ADDR64, but used when setting global offset table
429 HOWTO (R_PPC64_GLOB_DAT
, /* type */
431 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
433 false, /* pc_relative */
435 complain_overflow_dont
, /* complain_on_overflow */
436 bfd_elf_generic_reloc
, /* special_function */
437 "R_PPC64_GLOB_DAT", /* name */
438 false, /* partial_inplace */
440 0xffffffffffffffff, /* dst_mask */
441 false), /* pcrel_offset */
443 /* Created by the link editor. Marks a procedure linkage table
444 entry for a symbol. */
445 HOWTO (R_PPC64_JMP_SLOT
, /* type */
447 0, /* size (0 = byte, 1 = short, 2 = long) */
449 false, /* pc_relative */
451 complain_overflow_dont
, /* complain_on_overflow */
452 bfd_elf_generic_reloc
, /* special_function */
453 "R_PPC64_JMP_SLOT", /* name */
454 false, /* partial_inplace */
457 false), /* pcrel_offset */
459 /* Used only by the dynamic linker. When the object is run, this
460 doubleword64 is set to the load address of the object, plus the
462 HOWTO (R_PPC64_RELATIVE
, /* type */
464 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
466 false, /* pc_relative */
468 complain_overflow_dont
, /* complain_on_overflow */
469 bfd_elf_generic_reloc
, /* special_function */
470 "R_PPC64_RELATIVE", /* name */
471 false, /* partial_inplace */
473 0xffffffffffffffff, /* dst_mask */
474 false), /* pcrel_offset */
476 /* Like R_PPC64_ADDR32, but may be unaligned. */
477 HOWTO (R_PPC64_UADDR32
, /* type */
479 2, /* size (0 = byte, 1 = short, 2 = long) */
481 false, /* pc_relative */
483 complain_overflow_bitfield
, /* complain_on_overflow */
484 bfd_elf_generic_reloc
, /* special_function */
485 "R_PPC64_UADDR32", /* name */
486 false, /* partial_inplace */
488 0xffffffff, /* dst_mask */
489 false), /* pcrel_offset */
491 /* Like R_PPC64_ADDR16, but may be unaligned. */
492 HOWTO (R_PPC64_UADDR16
, /* type */
494 1, /* size (0 = byte, 1 = short, 2 = long) */
496 false, /* pc_relative */
498 complain_overflow_bitfield
, /* complain_on_overflow */
499 bfd_elf_generic_reloc
, /* special_function */
500 "R_PPC64_UADDR16", /* name */
501 false, /* partial_inplace */
503 0xffff, /* dst_mask */
504 false), /* pcrel_offset */
506 /* 32-bit PC relative. */
507 HOWTO (R_PPC64_REL32
, /* type */
509 2, /* size (0 = byte, 1 = short, 2 = long) */
511 true, /* pc_relative */
513 /* FIXME: Verify. Was complain_overflow_bitfield. */
514 complain_overflow_signed
, /* complain_on_overflow */
515 bfd_elf_generic_reloc
, /* special_function */
516 "R_PPC64_REL32", /* name */
517 false, /* partial_inplace */
519 0xffffffff, /* dst_mask */
520 true), /* pcrel_offset */
522 /* 32-bit relocation to the symbol's procedure linkage table.
523 FIXME: R_PPC64_PLT32 not supported. */
524 HOWTO (R_PPC64_PLT32
, /* type */
526 2, /* size (0 = byte, 1 = short, 2 = long) */
528 false, /* pc_relative */
530 complain_overflow_bitfield
, /* complain_on_overflow */
531 bfd_elf_generic_reloc
, /* special_function */
532 "R_PPC64_PLT32", /* name */
533 false, /* partial_inplace */
536 false), /* pcrel_offset */
538 /* 32-bit PC relative relocation to the symbol's procedure linkage table.
539 FIXME: R_PPC64_PLTREL32 not supported. */
540 HOWTO (R_PPC64_PLTREL32
, /* type */
542 2, /* size (0 = byte, 1 = short, 2 = long) */
544 true, /* pc_relative */
546 complain_overflow_signed
, /* complain_on_overflow */
547 bfd_elf_generic_reloc
, /* special_function */
548 "R_PPC64_PLTREL32", /* name */
549 false, /* partial_inplace */
552 true), /* pcrel_offset */
554 /* Like R_PPC64_ADDR16_LO, but referring to the PLT table entry for
556 HOWTO (R_PPC64_PLT16_LO
, /* type */
558 1, /* size (0 = byte, 1 = short, 2 = long) */
560 false, /* pc_relative */
562 complain_overflow_dont
, /* complain_on_overflow */
563 bfd_elf_generic_reloc
, /* special_function */
564 "R_PPC64_PLT16_LO", /* name */
565 false, /* partial_inplace */
567 0xffff, /* dst_mask */
568 false), /* pcrel_offset */
570 /* Like R_PPC64_ADDR16_HI, but referring to the PLT table entry for
572 HOWTO (R_PPC64_PLT16_HI
, /* type */
574 1, /* size (0 = byte, 1 = short, 2 = long) */
576 false, /* pc_relative */
578 complain_overflow_dont
, /* complain_on_overflow */
579 bfd_elf_generic_reloc
, /* special_function */
580 "R_PPC64_PLT16_HI", /* name */
581 false, /* partial_inplace */
583 0xffff, /* dst_mask */
584 false), /* pcrel_offset */
586 /* Like R_PPC64_ADDR16_HA, but referring to the PLT table entry for
588 HOWTO (R_PPC64_PLT16_HA
, /* type */
590 1, /* size (0 = byte, 1 = short, 2 = long) */
592 false, /* pc_relative */
594 complain_overflow_dont
, /* complain_on_overflow */
595 ppc64_elf_addr16_ha_reloc
, /* special_function */
596 "R_PPC64_PLT16_HA", /* name */
597 false, /* partial_inplace */
599 0xffff, /* dst_mask */
600 false), /* pcrel_offset */
602 /* 32-bit section relative relocation. */
603 /* FIXME: Verify R_PPC64_SECTOFF. Seems strange with size=2 and
605 HOWTO (R_PPC64_SECTOFF
, /* type */
607 2, /* size (0 = byte, 1 = short, 2 = long) */
609 true, /* pc_relative */
611 complain_overflow_bitfield
, /* complain_on_overflow */
612 bfd_elf_generic_reloc
, /* special_function */
613 "R_PPC64_SECTOFF", /* name */
614 false, /* partial_inplace */
617 true), /* pcrel_offset */
619 /* 16-bit lower half section relative relocation. */
620 HOWTO (R_PPC64_SECTOFF_LO
, /* type */
622 1, /* size (0 = byte, 1 = short, 2 = long) */
624 false, /* pc_relative */
626 complain_overflow_dont
, /* complain_on_overflow */
627 bfd_elf_generic_reloc
, /* special_function */
628 "R_PPC64_SECTOFF_LO", /* name */
629 false, /* partial_inplace */
631 0xffff, /* dst_mask */
632 false), /* pcrel_offset */
634 /* 16-bit upper half section relative relocation. */
635 HOWTO (R_PPC64_SECTOFF_HI
, /* type */
637 1, /* size (0 = byte, 1 = short, 2 = long) */
639 false, /* pc_relative */
641 complain_overflow_dont
, /* complain_on_overflow */
642 bfd_elf_generic_reloc
, /* special_function */
643 "R_PPC64_SECTOFF_HI", /* name */
644 false, /* partial_inplace */
646 0xffff, /* dst_mask */
647 false), /* pcrel_offset */
649 /* 16-bit upper half adjusted section relative relocation. */
650 HOWTO (R_PPC64_SECTOFF_HA
, /* type */
652 1, /* size (0 = byte, 1 = short, 2 = long) */
654 false, /* pc_relative */
656 complain_overflow_dont
, /* complain_on_overflow */
657 ppc64_elf_addr16_ha_reloc
, /* special_function */
658 "R_PPC64_SECTOFF_HA", /* name */
659 false, /* partial_inplace */
661 0xffff, /* dst_mask */
662 false), /* pcrel_offset */
664 /* Like R_PPC64_REL24 without touching the two least significant
666 /* FIXME: Verify R_PPC64_ADDR30. */
667 HOWTO (R_PPC64_ADDR30
, /* type */
669 2, /* size (0 = byte, 1 = short, 2 = long) */
671 true, /* pc_relative */
673 complain_overflow_dont
, /* complain_on_overflow */
674 bfd_elf_generic_reloc
, /* special_function */
675 "R_PPC64_ADDR30", /* name */
676 false, /* partial_inplace */
678 0xfffffffc, /* dst_mask */
679 true), /* pcrel_offset */
681 /* Relocs in the 64-bit PowerPC ELF ABI, not in the 32-bit ABI. */
683 /* A standard 64-bit relocation. */
684 HOWTO (R_PPC64_ADDR64
, /* type */
686 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
688 false, /* pc_relative */
690 complain_overflow_dont
, /* complain_on_overflow */
691 bfd_elf_generic_reloc
, /* special_function */
692 "R_PPC64_ADDR64", /* name */
693 false, /* partial_inplace */
695 0xffffffffffffffff, /* dst_mask */
696 false), /* pcrel_offset */
698 /* The bits 32-47 of an address. */
699 HOWTO (R_PPC64_ADDR16_HIGHER
, /* type */
701 1, /* size (0 = byte, 1 = short, 2 = long) */
703 false, /* pc_relative */
705 complain_overflow_dont
, /* complain_on_overflow */
706 bfd_elf_generic_reloc
, /* special_function */
707 "R_PPC64_ADDR16_HIGHER", /* name */
708 false, /* partial_inplace */
710 0xffff, /* dst_mask */
711 false), /* pcrel_offset */
713 /* The bits 32-47 of an address, plus 1 if the contents of the low
714 16 bits, treated as a signed number, is negative. */
715 HOWTO (R_PPC64_ADDR16_HIGHERA
, /* type */
717 1, /* size (0 = byte, 1 = short, 2 = long) */
719 false, /* pc_relative */
721 complain_overflow_dont
, /* complain_on_overflow */
722 ppc64_elf_addr16_ha_reloc
, /* special_function */
723 "R_PPC64_ADDR16_HIGHERA", /* name */
724 false, /* partial_inplace */
726 0xffff, /* dst_mask */
727 false), /* pcrel_offset */
729 /* The bits 48-63 of an address. */
730 HOWTO (R_PPC64_ADDR16_HIGHEST
,/* type */
732 1, /* size (0 = byte, 1 = short, 2 = long) */
734 false, /* pc_relative */
736 complain_overflow_dont
, /* complain_on_overflow */
737 bfd_elf_generic_reloc
, /* special_function */
738 "R_PPC64_ADDR16_HIGHEST", /* name */
739 false, /* partial_inplace */
741 0xffff, /* dst_mask */
742 false), /* pcrel_offset */
744 /* The bits 48-63 of an address, plus 1 if the contents of the low
745 16 bits, treated as a signed number, is negative. */
746 HOWTO (R_PPC64_ADDR16_HIGHESTA
,/* type */
748 1, /* size (0 = byte, 1 = short, 2 = long) */
750 false, /* pc_relative */
752 complain_overflow_dont
, /* complain_on_overflow */
753 ppc64_elf_addr16_ha_reloc
, /* special_function */
754 "R_PPC64_ADDR16_HIGHESTA", /* name */
755 false, /* partial_inplace */
757 0xffff, /* dst_mask */
758 false), /* pcrel_offset */
760 /* Like ADDR64, but may be unaligned. */
761 HOWTO (R_PPC64_UADDR64
, /* type */
763 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
765 false, /* pc_relative */
767 complain_overflow_dont
, /* complain_on_overflow */
768 bfd_elf_generic_reloc
, /* special_function */
769 "R_PPC64_UADDR64", /* name */
770 false, /* partial_inplace */
772 0xffffffffffffffff, /* dst_mask */
773 false), /* pcrel_offset */
775 /* 64-bit relative relocation. */
776 HOWTO (R_PPC64_REL64
, /* type */
778 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
780 true, /* pc_relative */
782 complain_overflow_dont
, /* complain_on_overflow */
783 bfd_elf_generic_reloc
, /* special_function */
784 "R_PPC64_REL64", /* name */
785 false, /* partial_inplace */
787 0xffffffffffffffff, /* dst_mask */
788 true), /* pcrel_offset */
790 /* 64-bit relocation to the symbol's procedure linkage table. */
791 /* FIXME: R_PPC64_PLT64 not supported. */
792 HOWTO (R_PPC64_PLT64
, /* type */
794 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
796 false, /* pc_relative */
798 complain_overflow_dont
, /* complain_on_overflow */
799 bfd_elf_generic_reloc
, /* special_function */
800 "R_PPC64_PLT64", /* name */
801 false, /* partial_inplace */
804 false), /* pcrel_offset */
806 /* 64-bit PC relative relocation to the symbol's procedure linkage
808 /* FIXME: R_PPC64_PLTREL64 not supported. */
809 HOWTO (R_PPC64_PLTREL64
, /* type */
811 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
813 true, /* pc_relative */
815 complain_overflow_dont
, /* complain_on_overflow */
816 bfd_elf_generic_reloc
, /* special_function */
817 "R_PPC64_PLTREL64", /* name */
818 false, /* partial_inplace */
821 true), /* pcrel_offset */
823 /* 16 bit TOC-relative relocation. */
825 /* R_PPC64_TOC16 47 half16* S + A - .TOC. */
826 HOWTO (R_PPC64_TOC16
, /* type */
828 1, /* size (0 = byte, 1 = short, 2 = long) */
830 false, /* pc_relative */
832 complain_overflow_signed
, /* complain_on_overflow */
833 bfd_elf_generic_reloc
, /* special_function */
834 "R_PPC64_TOC16", /* name */
835 false, /* partial_inplace */
837 0xffff, /* dst_mask */
838 false), /* pcrel_offset */
840 /* 16 bit TOC-relative relocation without overflow. */
842 /* R_PPC64_TOC16_LO 48 half16 #lo (S + A - .TOC.) */
843 HOWTO (R_PPC64_TOC16_LO
, /* type */
845 1, /* size (0 = byte, 1 = short, 2 = long) */
847 false, /* pc_relative */
849 complain_overflow_dont
, /* complain_on_overflow */
850 bfd_elf_generic_reloc
, /* special_function */
851 "R_PPC64_TOC16_LO", /* name */
852 false, /* partial_inplace */
854 0xffff, /* dst_mask */
855 false), /* pcrel_offset */
857 /* 16 bit TOC-relative relocation, high 16 bits. */
859 /* R_PPC64_TOC16_HI 49 half16 #hi (S + A - .TOC.) */
860 HOWTO (R_PPC64_TOC16_HI
, /* type */
862 1, /* size (0 = byte, 1 = short, 2 = long) */
864 false, /* pc_relative */
866 complain_overflow_dont
, /* complain_on_overflow */
867 bfd_elf_generic_reloc
, /* special_function */
868 "R_PPC64_TOC16_HI", /* name */
869 false, /* partial_inplace */
871 0xffff, /* dst_mask */
872 false), /* pcrel_offset */
874 /* 16 bit TOC-relative relocation, high 16 bits, plus 1 if the
875 contents of the low 16 bits, treated as a signed number, is
878 /* R_PPC64_TOC16_HA 50 half16 #ha (S + A - .TOC.) */
879 HOWTO (R_PPC64_TOC16_HA
, /* type */
881 1, /* size (0 = byte, 1 = short, 2 = long) */
883 false, /* pc_relative */
885 complain_overflow_dont
, /* complain_on_overflow */
886 ppc64_elf_addr16_ha_reloc
, /* special_function */
887 "R_PPC64_TOC16_HA", /* name */
888 false, /* partial_inplace */
890 0xffff, /* dst_mask */
891 false), /* pcrel_offset */
893 /* 64-bit relocation; insert value of TOC base (.TOC.). */
895 /* R_PPC64_TOC 51 doubleword64 .TOC. */
896 HOWTO (R_PPC64_TOC
, /* type */
898 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
900 false, /* pc_relative */
902 complain_overflow_bitfield
, /* complain_on_overflow */
903 bfd_elf_generic_reloc
, /* special_function */
904 "R_PPC64_TOC", /* name */
905 false, /* partial_inplace */
907 0xffffffffffffffff, /* dst_mask */
908 false), /* pcrel_offset */
910 /* Like R_PPC64_GOT16, but also informs the link editor that the
911 value to relocate may (!) refer to a PLT entry which the link
912 editor (a) may replace with the symbol value. If the link editor
913 is unable to fully resolve the symbol, it may (b) create a PLT
914 entry and store the address to the new PLT entry in the GOT.
915 This permits lazy resolution of function symbols at run time.
916 The link editor may also skip all of this and just (c) emit a
917 R_PPC64_GLOB_DAT to tie the symbol to the GOT entry. */
918 /* FIXME: R_PPC64_PLTGOT16 not implemented. */
919 HOWTO (R_PPC64_PLTGOT16
, /* 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_PPC64_PLTGOT16", /* name */
928 false, /* partial_inplace */
930 0xffff, /* dst_mask */
931 false), /* pcrel_offset */
933 /* Like R_PPC64_PLTGOT16, but without overflow. */
934 /* FIXME: R_PPC64_PLTGOT16_LO not implemented. */
935 HOWTO (R_PPC64_PLTGOT16_LO
, /* type */
937 1, /* size (0 = byte, 1 = short, 2 = long) */
939 false, /* pc_relative */
941 complain_overflow_dont
, /* complain_on_overflow */
942 bfd_elf_generic_reloc
, /* special_function */
943 "R_PPC64_PLTGOT16_LO", /* name */
944 false, /* partial_inplace */
946 0xffff, /* dst_mask */
947 false), /* pcrel_offset */
949 /* Like R_PPC64_PLT_GOT16, but using bits 16-31 of the address. */
950 /* FIXME: R_PPC64_PLTGOT16_HI not implemented. */
951 HOWTO (R_PPC64_PLTGOT16_HI
, /* type */
953 1, /* size (0 = byte, 1 = short, 2 = long) */
955 false, /* pc_relative */
957 complain_overflow_dont
, /* complain_on_overflow */
958 bfd_elf_generic_reloc
, /* special_function */
959 "R_PPC64_PLTGOT16_HI", /* name */
960 false, /* partial_inplace */
962 0xffff, /* dst_mask */
963 false), /* pcrel_offset */
965 /* Like R_PPC64_PLT_GOT16, but using bits 16-31 of the address, plus
966 1 if the contents of the low 16 bits, treated as a signed number,
968 /* FIXME: R_PPC64_PLTGOT16_HA not implemented. */
969 HOWTO (R_PPC64_PLTGOT16_HA
, /* type */
971 1, /* size (0 = byte, 1 = short, 2 = long) */
973 false, /* pc_relative */
975 complain_overflow_dont
,/* complain_on_overflow */
976 ppc64_elf_addr16_ha_reloc
, /* special_function */
977 "R_PPC64_PLTGOT16_HA", /* name */
978 false, /* partial_inplace */
980 0xffff, /* dst_mask */
981 false), /* pcrel_offset */
983 /* Like R_PPC64_ADDR16, but for instructions with a DS field. */
984 HOWTO (R_PPC64_ADDR16_DS
, /* type */
986 1, /* size (0 = byte, 1 = short, 2 = long) */
988 false, /* pc_relative */
990 complain_overflow_bitfield
, /* complain_on_overflow */
991 bfd_elf_generic_reloc
, /* special_function */
992 "R_PPC64_ADDR16_DS", /* name */
993 false, /* partial_inplace */
995 0xfffc, /* dst_mask */
996 false), /* pcrel_offset */
998 /* Like R_PPC64_ADDR16_LO, but for instructions with a DS field. */
999 HOWTO (R_PPC64_ADDR16_LO_DS
, /* type */
1001 1, /* size (0 = byte, 1 = short, 2 = long) */
1003 false, /* pc_relative */
1005 complain_overflow_dont
,/* complain_on_overflow */
1006 bfd_elf_generic_reloc
, /* special_function */
1007 "R_PPC64_ADDR16_LO_DS",/* name */
1008 false, /* partial_inplace */
1010 0xfffc, /* dst_mask */
1011 false), /* pcrel_offset */
1013 /* Like R_PPC64_GOT16, but for instructions with a DS field. */
1014 HOWTO (R_PPC64_GOT16_DS
, /* type */
1016 1, /* size (0 = byte, 1 = short, 2 = long) */
1018 false, /* pc_relative */
1020 complain_overflow_signed
, /* complain_on_overflow */
1021 bfd_elf_generic_reloc
, /* special_function */
1022 "R_PPC64_GOT16_DS", /* name */
1023 false, /* partial_inplace */
1025 0xfffc, /* dst_mask */
1026 false), /* pcrel_offset */
1028 /* Like R_PPC64_GOT16_LO, but for instructions with a DS field. */
1029 HOWTO (R_PPC64_GOT16_LO_DS
, /* type */
1031 1, /* size (0 = byte, 1 = short, 2 = long) */
1033 false, /* pc_relative */
1035 complain_overflow_dont
, /* complain_on_overflow */
1036 bfd_elf_generic_reloc
, /* special_function */
1037 "R_PPC64_GOT16_LO_DS", /* name */
1038 false, /* partial_inplace */
1040 0xfffc, /* dst_mask */
1041 false), /* pcrel_offset */
1043 /* Like R_PPC64_PLT16_LO, but for instructions with a DS field. */
1044 HOWTO (R_PPC64_PLT16_LO_DS
, /* type */
1046 1, /* size (0 = byte, 1 = short, 2 = long) */
1048 false, /* pc_relative */
1050 complain_overflow_dont
, /* complain_on_overflow */
1051 bfd_elf_generic_reloc
, /* special_function */
1052 "R_PPC64_PLT16_LO_DS", /* name */
1053 false, /* partial_inplace */
1055 0xfffc, /* dst_mask */
1056 false), /* pcrel_offset */
1058 /* Like R_PPC64_SECTOFF, but for instructions with a DS field. */
1059 /* FIXME: Verify R_PPC64_SECTOFF. Seems strange with size=2 and
1061 HOWTO (R_PPC64_SECTOFF_DS
, /* type */
1063 2, /* size (0 = byte, 1 = short, 2 = long) */
1065 true, /* pc_relative */
1067 complain_overflow_bitfield
, /* complain_on_overflow */
1068 bfd_elf_generic_reloc
, /* special_function */
1069 "R_PPC64_SECTOFF_DS", /* name */
1070 false, /* partial_inplace */
1073 true), /* pcrel_offset */
1075 /* Like R_PPC64_SECTOFF_LO, but for instructions with a DS field. */
1076 HOWTO (R_PPC64_SECTOFF_LO_DS
, /* type */
1078 1, /* size (0 = byte, 1 = short, 2 = long) */
1080 false, /* pc_relative */
1082 complain_overflow_dont
, /* complain_on_overflow */
1083 bfd_elf_generic_reloc
, /* special_function */
1084 "R_PPC64_SECTOFF_LO_DS",/* name */
1085 false, /* partial_inplace */
1087 0xfffc, /* dst_mask */
1088 false), /* pcrel_offset */
1090 /* Like R_PPC64_TOC16, but for instructions with a DS field. */
1091 HOWTO (R_PPC64_TOC16_DS
, /* type */
1093 1, /* size (0 = byte, 1 = short, 2 = long) */
1095 false, /* pc_relative */
1097 complain_overflow_signed
, /* complain_on_overflow */
1098 bfd_elf_generic_reloc
, /* special_function */
1099 "R_PPC64_TOC16_DS", /* name */
1100 false, /* partial_inplace */
1102 0xfffc, /* dst_mask */
1103 false), /* pcrel_offset */
1105 /* Like R_PPC64_TOC16_LO, but for instructions with a DS field. */
1106 HOWTO (R_PPC64_TOC16_LO_DS
, /* type */
1108 1, /* size (0 = byte, 1 = short, 2 = long) */
1110 false, /* pc_relative */
1112 complain_overflow_dont
, /* complain_on_overflow */
1113 bfd_elf_generic_reloc
, /* special_function */
1114 "R_PPC64_TOC16_LO_DS", /* name */
1115 false, /* partial_inplace */
1117 0xfffc, /* dst_mask */
1118 false), /* pcrel_offset */
1120 /* Like R_PPC64_PLTGOT16, but for instructions with a DS field. */
1121 /* FIXME: R_PPC64_PLTGOT16_DS not implemented. */
1122 HOWTO (R_PPC64_PLTGOT16_DS
, /* type */
1124 1, /* size (0 = byte, 1 = short, 2 = long) */
1126 false, /* pc_relative */
1128 complain_overflow_signed
, /* complain_on_overflow */
1129 bfd_elf_generic_reloc
, /* special_function */
1130 "R_PPC64_PLTGOT16_DS", /* name */
1131 false, /* partial_inplace */
1133 0xfffc, /* dst_mask */
1134 false), /* pcrel_offset */
1136 /* Like R_PPC64_PLTGOT16_LO, but for instructions with a DS field. */
1137 /* FIXME: R_PPC64_PLTGOT16_LO not implemented. */
1138 HOWTO (R_PPC64_PLTGOT16_LO_DS
,/* type */
1140 1, /* size (0 = byte, 1 = short, 2 = long) */
1142 false, /* pc_relative */
1144 complain_overflow_dont
, /* complain_on_overflow */
1145 bfd_elf_generic_reloc
, /* special_function */
1146 "R_PPC64_PLTGOT16_LO_DS",/* name */
1147 false, /* partial_inplace */
1149 0xfffc, /* dst_mask */
1150 false), /* pcrel_offset */
1152 /* GNU extension to record C++ vtable hierarchy. */
1153 HOWTO (R_PPC64_GNU_VTINHERIT
, /* type */
1155 0, /* size (0 = byte, 1 = short, 2 = long) */
1157 false, /* pc_relative */
1159 complain_overflow_dont
, /* complain_on_overflow */
1160 NULL
, /* special_function */
1161 "R_PPC64_GNU_VTINHERIT", /* name */
1162 false, /* partial_inplace */
1165 false), /* pcrel_offset */
1167 /* GNU extension to record C++ vtable member usage. */
1168 HOWTO (R_PPC64_GNU_VTENTRY
, /* type */
1170 0, /* size (0 = byte, 1 = short, 2 = long) */
1172 false, /* pc_relative */
1174 complain_overflow_dont
, /* complain_on_overflow */
1175 NULL
, /* special_function */
1176 "R_PPC64_GNU_VTENTRY", /* name */
1177 false, /* partial_inplace */
1180 false), /* pcrel_offset */
1184 /* Initialize the ppc64_elf_howto_table, so that linear accesses can
1190 unsigned int i
, type
;
1193 i
< sizeof (ppc64_elf_howto_raw
) / sizeof (ppc64_elf_howto_raw
[0]);
1196 type
= ppc64_elf_howto_raw
[i
].type
;
1197 BFD_ASSERT (type
< (sizeof (ppc64_elf_howto_table
)
1198 / sizeof (ppc64_elf_howto_table
[0])));
1199 ppc64_elf_howto_table
[type
] = &ppc64_elf_howto_raw
[i
];
1203 static reloc_howto_type
*
1204 ppc64_elf_reloc_type_lookup (abfd
, code
)
1205 bfd
*abfd ATTRIBUTE_UNUSED
;
1206 bfd_reloc_code_real_type code
;
1208 enum elf_ppc_reloc_type ppc_reloc
= R_PPC_NONE
;
1210 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
1211 /* Initialize howto table if needed. */
1217 return (reloc_howto_type
*) NULL
;
1219 case BFD_RELOC_NONE
: ppc_reloc
= R_PPC64_NONE
;
1221 case BFD_RELOC_32
: ppc_reloc
= R_PPC64_ADDR32
;
1223 case BFD_RELOC_PPC_BA26
: ppc_reloc
= R_PPC64_ADDR24
;
1225 case BFD_RELOC_16
: ppc_reloc
= R_PPC64_ADDR16
;
1227 case BFD_RELOC_LO16
: ppc_reloc
= R_PPC64_ADDR16_LO
;
1229 case BFD_RELOC_HI16
: ppc_reloc
= R_PPC64_ADDR16_HI
;
1231 case BFD_RELOC_HI16_S
: ppc_reloc
= R_PPC64_ADDR16_HA
;
1233 case BFD_RELOC_PPC_BA16
: ppc_reloc
= R_PPC64_ADDR14
;
1235 case BFD_RELOC_PPC_BA16_BRTAKEN
: ppc_reloc
= R_PPC64_ADDR14_BRTAKEN
;
1237 case BFD_RELOC_PPC_BA16_BRNTAKEN
: ppc_reloc
= R_PPC64_ADDR14_BRNTAKEN
;
1239 case BFD_RELOC_PPC_B26
: ppc_reloc
= R_PPC64_REL24
;
1241 case BFD_RELOC_PPC_B16
: ppc_reloc
= R_PPC64_REL14
;
1243 case BFD_RELOC_PPC_B16_BRTAKEN
: ppc_reloc
= R_PPC64_REL14_BRTAKEN
;
1245 case BFD_RELOC_PPC_B16_BRNTAKEN
: ppc_reloc
= R_PPC64_REL14_BRNTAKEN
;
1247 case BFD_RELOC_16_GOTOFF
: ppc_reloc
= R_PPC64_GOT16
;
1249 case BFD_RELOC_LO16_GOTOFF
: ppc_reloc
= R_PPC64_GOT16_LO
;
1251 case BFD_RELOC_HI16_GOTOFF
: ppc_reloc
= R_PPC64_GOT16_HI
;
1253 case BFD_RELOC_HI16_S_GOTOFF
: ppc_reloc
= R_PPC64_GOT16_HA
;
1255 case BFD_RELOC_PPC_COPY
: ppc_reloc
= R_PPC64_COPY
;
1257 case BFD_RELOC_PPC_GLOB_DAT
: ppc_reloc
= R_PPC64_GLOB_DAT
;
1259 case BFD_RELOC_32_PCREL
: ppc_reloc
= R_PPC64_REL32
;
1261 case BFD_RELOC_32_PLTOFF
: ppc_reloc
= R_PPC64_PLT32
;
1263 case BFD_RELOC_32_PLT_PCREL
: ppc_reloc
= R_PPC64_PLTREL32
;
1265 case BFD_RELOC_LO16_PLTOFF
: ppc_reloc
= R_PPC64_PLT16_LO
;
1267 case BFD_RELOC_HI16_PLTOFF
: ppc_reloc
= R_PPC64_PLT16_HI
;
1269 case BFD_RELOC_HI16_S_PLTOFF
: ppc_reloc
= R_PPC64_PLT16_HA
;
1271 case BFD_RELOC_32_BASEREL
: ppc_reloc
= R_PPC64_SECTOFF
;
1273 case BFD_RELOC_LO16_BASEREL
: ppc_reloc
= R_PPC64_SECTOFF_LO
;
1275 case BFD_RELOC_HI16_BASEREL
: ppc_reloc
= R_PPC64_SECTOFF_HI
;
1277 case BFD_RELOC_HI16_S_BASEREL
: ppc_reloc
= R_PPC64_SECTOFF_HA
;
1279 /* FIXME: Is CTOR 32 or 64 bits? Fix md_apply_fix3 in
1280 gas/config/tc-ppc.c too. */
1281 case BFD_RELOC_CTOR
: ppc_reloc
= R_PPC64_ADDR32
;
1283 case BFD_RELOC_64
: ppc_reloc
= R_PPC64_ADDR64
;
1285 case BFD_RELOC_PPC64_HIGHER
: ppc_reloc
= R_PPC64_ADDR16_HIGHER
;
1287 case BFD_RELOC_PPC64_HIGHER_S
: ppc_reloc
= R_PPC64_ADDR16_HIGHERA
;
1289 case BFD_RELOC_PPC64_HIGHEST
: ppc_reloc
= R_PPC64_ADDR16_HIGHEST
;
1291 case BFD_RELOC_PPC64_HIGHEST_S
: ppc_reloc
= R_PPC64_ADDR16_HIGHESTA
;
1293 case BFD_RELOC_64_PCREL
: ppc_reloc
= R_PPC64_REL64
;
1295 case BFD_RELOC_64_PLTOFF
: ppc_reloc
= R_PPC64_PLT64
;
1297 case BFD_RELOC_64_PLT_PCREL
: ppc_reloc
= R_PPC64_PLTREL64
;
1299 case BFD_RELOC_PPC_TOC16
: ppc_reloc
= R_PPC64_TOC16
;
1301 case BFD_RELOC_PPC64_TOC16_LO
: ppc_reloc
= R_PPC64_TOC16_LO
;
1303 case BFD_RELOC_PPC64_TOC16_HI
: ppc_reloc
= R_PPC64_TOC16_HI
;
1305 case BFD_RELOC_PPC64_TOC16_HA
: ppc_reloc
= R_PPC64_TOC16_HA
;
1307 case BFD_RELOC_PPC64_TOC
: ppc_reloc
= R_PPC64_TOC
;
1309 case BFD_RELOC_PPC64_PLTGOT16
: ppc_reloc
= R_PPC64_PLTGOT16
;
1311 case BFD_RELOC_PPC64_PLTGOT16_LO
: ppc_reloc
= R_PPC64_PLTGOT16_LO
;
1313 case BFD_RELOC_PPC64_PLTGOT16_HI
: ppc_reloc
= R_PPC64_PLTGOT16_HI
;
1315 case BFD_RELOC_PPC64_PLTGOT16_HA
: ppc_reloc
= R_PPC64_PLTGOT16_HA
;
1317 case BFD_RELOC_PPC64_ADDR16_DS
: ppc_reloc
= R_PPC64_ADDR16_DS
;
1319 case BFD_RELOC_PPC64_ADDR16_LO_DS
: ppc_reloc
= R_PPC64_ADDR16_LO_DS
;
1321 case BFD_RELOC_PPC64_GOT16_DS
: ppc_reloc
= R_PPC64_GOT16_DS
;
1323 case BFD_RELOC_PPC64_GOT16_LO_DS
: ppc_reloc
= R_PPC64_GOT16_LO_DS
;
1325 case BFD_RELOC_PPC64_PLT16_LO_DS
: ppc_reloc
= R_PPC64_PLT16_LO_DS
;
1327 case BFD_RELOC_PPC64_SECTOFF_DS
: ppc_reloc
= R_PPC64_SECTOFF_DS
;
1329 case BFD_RELOC_PPC64_SECTOFF_LO_DS
: ppc_reloc
= R_PPC64_SECTOFF_LO_DS
;
1331 case BFD_RELOC_PPC64_TOC16_DS
: ppc_reloc
= R_PPC64_TOC16_DS
;
1333 case BFD_RELOC_PPC64_TOC16_LO_DS
: ppc_reloc
= R_PPC64_TOC16_LO_DS
;
1335 case BFD_RELOC_PPC64_PLTGOT16_DS
: ppc_reloc
= R_PPC64_PLTGOT16_DS
;
1337 case BFD_RELOC_PPC64_PLTGOT16_LO_DS
: ppc_reloc
= R_PPC64_PLTGOT16_LO_DS
;
1339 case BFD_RELOC_VTABLE_INHERIT
: ppc_reloc
= R_PPC64_GNU_VTINHERIT
;
1341 case BFD_RELOC_VTABLE_ENTRY
: ppc_reloc
= R_PPC64_GNU_VTENTRY
;
1345 return ppc64_elf_howto_table
[(int) ppc_reloc
];
1348 /* Set the howto pointer for a PowerPC ELF reloc. */
1351 ppc64_elf_info_to_howto (abfd
, cache_ptr
, dst
)
1352 bfd
*abfd ATTRIBUTE_UNUSED
;
1354 Elf64_Internal_Rela
*dst
;
1356 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
1357 /* Initialize howto table if needed. */
1360 BFD_ASSERT (ELF64_R_TYPE (dst
->r_info
) < (unsigned int) R_PPC_max
);
1361 cache_ptr
->howto
= ppc64_elf_howto_table
[ELF64_R_TYPE (dst
->r_info
)];
1364 /* Handle the R_PPC_ADDR16_HA reloc. */
1366 static bfd_reloc_status_type
1367 ppc64_elf_addr16_ha_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1368 output_bfd
, error_message
)
1369 bfd
*abfd ATTRIBUTE_UNUSED
;
1370 arelent
*reloc_entry
;
1372 PTR data ATTRIBUTE_UNUSED
;
1373 asection
*input_section
;
1375 char **error_message ATTRIBUTE_UNUSED
;
1379 if (output_bfd
!= NULL
)
1381 reloc_entry
->address
+= input_section
->output_offset
;
1382 return bfd_reloc_ok
;
1385 if (reloc_entry
->address
> input_section
->_cooked_size
)
1386 return bfd_reloc_outofrange
;
1388 if (bfd_is_com_section (symbol
->section
))
1391 relocation
= symbol
->value
;
1393 relocation
+= symbol
->section
->output_section
->vma
;
1394 relocation
+= symbol
->section
->output_offset
;
1395 relocation
+= reloc_entry
->addend
;
1397 reloc_entry
->addend
+= (relocation
& 0x8000) << 1;
1399 return bfd_reloc_continue
;
1402 /* Function to set whether a module needs the -mrelocatable bit set. */
1405 ppc64_elf_set_private_flags (abfd
, flags
)
1409 BFD_ASSERT (!elf_flags_init (abfd
)
1410 || elf_elfheader (abfd
)->e_flags
== flags
);
1412 elf_elfheader (abfd
)->e_flags
= flags
;
1413 elf_flags_init (abfd
) = true;
1417 /* Copy backend specific data from one object module to another. */
1419 ppc64_elf_copy_private_bfd_data (ibfd
, obfd
)
1423 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
1424 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
1427 BFD_ASSERT (!elf_flags_init (obfd
)
1428 || elf_elfheader (obfd
)->e_flags
== elf_elfheader (ibfd
)->e_flags
);
1430 elf_elfheader (obfd
)->e_flags
= elf_elfheader (ibfd
)->e_flags
;
1431 elf_flags_init (obfd
) = true;
1435 /* Merge backend specific data from an object file to the output
1436 object file when linking. */
1438 ppc64_elf_merge_private_bfd_data (ibfd
, obfd
)
1446 /* Check if we have the same endianess. */
1447 if (ibfd
->xvec
->byteorder
!= obfd
->xvec
->byteorder
1448 && obfd
->xvec
->byteorder
!= BFD_ENDIAN_UNKNOWN
)
1452 if (bfd_big_endian (ibfd
))
1453 msg
= _("%s: compiled for a big endian system and target is little endian");
1455 msg
= _("%s: compiled for a little endian system and target is big endian");
1457 (*_bfd_error_handler
) (msg
, bfd_get_filename (ibfd
));
1459 bfd_set_error (bfd_error_wrong_format
);
1463 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
1464 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
1467 new_flags
= elf_elfheader (ibfd
)->e_flags
;
1468 old_flags
= elf_elfheader (obfd
)->e_flags
;
1469 if (!elf_flags_init (obfd
))
1471 /* First call, no flags set. */
1472 elf_flags_init (obfd
) = true;
1473 elf_elfheader (obfd
)->e_flags
= new_flags
;
1476 else if (new_flags
== old_flags
)
1477 /* Compatible flags are ok. */
1482 /* Incompatible flags. Warn about -mrelocatable mismatch.
1483 Allow -mrelocatable-lib to be linked with either. */
1485 if ((new_flags
& EF_PPC_RELOCATABLE
) != 0
1486 && (old_flags
& (EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
)) == 0)
1489 (*_bfd_error_handler
)
1490 (_("%s: compiled with -mrelocatable and linked with modules compiled normally"),
1491 bfd_get_filename (ibfd
));
1493 else if ((new_flags
& (EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
)) == 0
1494 && (old_flags
& EF_PPC_RELOCATABLE
) != 0)
1497 (*_bfd_error_handler
)
1498 (_("%s: compiled normally and linked with modules compiled with -mrelocatable"),
1499 bfd_get_filename (ibfd
));
1502 /* The output is -mrelocatable-lib iff both the input files are. */
1503 if (! (new_flags
& EF_PPC_RELOCATABLE_LIB
))
1504 elf_elfheader (obfd
)->e_flags
&= ~EF_PPC_RELOCATABLE_LIB
;
1506 /* The output is -mrelocatable iff it can't be -mrelocatable-lib,
1507 but each input file is either -mrelocatable or -mrelocatable-lib. */
1508 if (! (elf_elfheader (obfd
)->e_flags
& EF_PPC_RELOCATABLE_LIB
)
1509 && (new_flags
& (EF_PPC_RELOCATABLE_LIB
| EF_PPC_RELOCATABLE
))
1510 && (old_flags
& (EF_PPC_RELOCATABLE_LIB
| EF_PPC_RELOCATABLE
)))
1511 elf_elfheader (obfd
)->e_flags
|= EF_PPC_RELOCATABLE
;
1513 /* Do not warn about eabi vs. V.4 mismatch, just or in the bit
1514 if any module uses it. */
1515 elf_elfheader (obfd
)->e_flags
|= (new_flags
& EF_PPC_EMB
);
1517 new_flags
&= ~(EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
| EF_PPC_EMB
);
1518 old_flags
&= ~(EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
| EF_PPC_EMB
);
1520 /* Warn about any other mismatches. */
1521 if (new_flags
!= old_flags
)
1524 (*_bfd_error_handler
)
1525 (_("%s: uses different e_flags (0x%lx) fields than previous modules (0x%lx)"),
1526 bfd_get_filename (ibfd
), (long) new_flags
, (long) old_flags
);
1531 bfd_set_error (bfd_error_bad_value
);
1539 /* Handle a PowerPC specific section when reading an object file. This
1540 is called when elfcode.h finds a section with an unknown type. */
1543 ppc64_elf_section_from_shdr (abfd
, hdr
, name
)
1545 Elf64_Internal_Shdr
*hdr
;
1551 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
))
1554 newsect
= hdr
->bfd_section
;
1555 flags
= bfd_get_section_flags (abfd
, newsect
);
1556 if (hdr
->sh_flags
& SHF_EXCLUDE
)
1557 flags
|= SEC_EXCLUDE
;
1559 if (hdr
->sh_type
== SHT_ORDERED
)
1560 flags
|= SEC_SORT_ENTRIES
;
1562 bfd_set_section_flags (abfd
, newsect
, flags
);
1566 /* The following routines are specific to the ELF linker, while
1567 routines above are used generally. They appear in this file more
1568 or less in the order in which they are called from external
1569 routines. eg. ppc64_elf_check_relocs is called early in the link
1570 process, ppc64_elf_finish_dynamic_sections is one of the last
1571 functions called. */
1573 /* Create the .glink section as well as the ordinary dynamic
1577 ppc64_elf_create_dynamic_sections (abfd
, info
)
1579 struct bfd_link_info
*info
;
1584 if (!_bfd_elf_create_dynamic_sections (abfd
, info
))
1587 /* Our .plt just contains pointers, no code. */
1588 s
= bfd_get_section_by_name (abfd
, ".plt");
1591 flags
= bfd_get_section_flags (abfd
, s
);
1593 if (! bfd_set_section_flags (abfd
, s
, flags
))
1596 /* Create .glink for global linkage functions. */
1597 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
1598 | SEC_LINKER_CREATED
);
1599 s
= bfd_make_section (abfd
, ".glink");
1601 || ! bfd_set_section_flags (abfd
, s
, flags
)
1602 || ! bfd_set_section_alignment (abfd
, s
, 3))
1608 /* Look through the relocs for a section during the first phase, and
1609 allocate space in the global offset table or procedure linkage
1613 ppc64_elf_check_relocs (abfd
, info
, sec
, relocs
)
1615 struct bfd_link_info
*info
;
1617 const Elf_Internal_Rela
*relocs
;
1620 Elf_Internal_Shdr
*symtab_hdr
;
1621 struct elf_link_hash_entry
**sym_hashes
, **sym_hashes_end
;
1622 const Elf_Internal_Rela
*rel
;
1623 const Elf_Internal_Rela
*rel_end
;
1624 bfd_signed_vma
*local_got_refcounts
;
1626 asection
*sgot
= NULL
;
1627 asection
*srelgot
= NULL
;
1629 if (info
->relocateable
)
1633 fprintf (stderr
, "ppc64_elf_check_relocs called for section %s in %s\n",
1634 bfd_get_section_name (abfd
, sec
),
1635 bfd_get_filename (abfd
));
1638 dynobj
= elf_hash_table (info
)->dynobj
;
1639 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
1640 local_got_refcounts
= elf_local_got_refcounts (abfd
);
1642 sym_hashes
= elf_sym_hashes (abfd
);
1643 sym_hashes_end
= (sym_hashes
1644 + symtab_hdr
->sh_size
/ sizeof (Elf64_External_Sym
));
1645 if (!elf_bad_symtab (abfd
))
1646 sym_hashes_end
-= symtab_hdr
->sh_info
;
1650 rel_end
= relocs
+ sec
->reloc_count
;
1651 for (rel
= relocs
; rel
< rel_end
; rel
++)
1653 unsigned long r_symndx
;
1654 struct elf_link_hash_entry
*h
;
1656 r_symndx
= ELF64_R_SYM (rel
->r_info
);
1657 if (r_symndx
< symtab_hdr
->sh_info
)
1660 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1662 switch (ELF64_R_TYPE (rel
->r_info
))
1664 /* GOT16 relocations */
1666 case R_PPC64_GOT16_LO
:
1667 case R_PPC64_GOT16_HI
:
1668 case R_PPC64_GOT16_HA
:
1669 case R_PPC64_GOT16_DS
:
1670 case R_PPC64_GOT16_LO_DS
:
1671 /* This symbol requires a global offset table entry. */
1676 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
1677 if (! _bfd_elf_create_got_section (dynobj
, info
))
1679 sgot
= bfd_get_section_by_name (dynobj
, ".got");
1680 BFD_ASSERT (sgot
!= NULL
);
1684 && (h
!= NULL
|| info
->shared
))
1686 srelgot
= bfd_get_section_by_name (dynobj
, ".rela.got");
1687 if (srelgot
== NULL
)
1689 srelgot
= bfd_make_section (dynobj
, ".rela.got");
1691 || ! bfd_set_section_flags (dynobj
, srelgot
,
1696 | SEC_LINKER_CREATED
1698 || ! bfd_set_section_alignment (dynobj
, srelgot
, 2))
1705 if (h
->got
.refcount
== -1)
1707 /* Make sure this symbol is output as a dynamic symbol. */
1708 if (h
->dynindx
== -1)
1709 if (!bfd_elf64_link_record_dynamic_symbol (info
, h
))
1712 /* Allocate space in the .got. */
1713 sgot
->_raw_size
+= 8;
1714 /* Allocate relocation space. */
1715 srelgot
->_raw_size
+= sizeof (Elf64_External_Rela
);
1717 h
->got
.refcount
= 1;
1724 /* This is a global offset table entry for a local symbol. */
1725 if (local_got_refcounts
== NULL
)
1729 size
= symtab_hdr
->sh_info
;
1730 size
*= sizeof (bfd_signed_vma
);
1731 local_got_refcounts
= ((bfd_signed_vma
*)
1732 bfd_alloc (abfd
, size
));
1733 if (local_got_refcounts
== NULL
)
1735 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
1736 memset (local_got_refcounts
, -1, (size_t) size
);
1738 if (local_got_refcounts
[r_symndx
] == -1)
1740 sgot
->_raw_size
+= 8;
1742 /* If we are generating a shared object, we need to
1743 output a R_PPC64_RELATIVE reloc so that the
1744 dynamic linker can adjust this GOT entry. */
1746 srelgot
->_raw_size
+= sizeof (Elf64_External_Rela
);
1748 local_got_refcounts
[r_symndx
] = 1;
1751 local_got_refcounts
[r_symndx
]++;
1757 case R_PPC64_PLT16_LO
:
1758 case R_PPC64_PLT16_HI
:
1759 case R_PPC64_PLT16_HA
:
1760 case R_PPC64_PLTGOT16_DS
:
1761 case R_PPC64_PLTGOT16_LO_DS
:
1763 fprintf (stderr
, "Reloc requires a PLT entry\n");
1765 /* This symbol requires a procedure linkage table entry. We
1766 actually build the entry in adjust_dynamic_symbol,
1767 because this might be a case of linking PIC code without
1768 linking in any dynamic objects, in which case we don't
1769 need to generate a procedure linkage table after all. */
1773 /* It does not make sense to have a procedure linkage
1774 table entry for a local symbol. */
1775 bfd_set_error (bfd_error_bad_value
);
1779 /* Make sure this symbol is output as a dynamic symbol. */
1780 if (h
->dynindx
== -1)
1782 if (! bfd_elf64_link_record_dynamic_symbol (info
, h
))
1785 if (h
->plt
.refcount
== -1)
1787 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
1788 h
->plt
.refcount
= 1;
1794 /* The following relocations don't need to propagate the
1795 relocation if linking a shared object since they are
1796 section relative. */
1797 case R_PPC64_SECTOFF
:
1798 case R_PPC64_SECTOFF_LO
:
1799 case R_PPC64_SECTOFF_HI
:
1800 case R_PPC64_SECTOFF_HA
:
1801 case R_PPC64_SECTOFF_DS
:
1802 case R_PPC64_SECTOFF_LO_DS
:
1804 case R_PPC64_TOC16_LO
:
1805 case R_PPC64_TOC16_HI
:
1806 case R_PPC64_TOC16_HA
:
1807 case R_PPC64_TOC16_DS
:
1808 case R_PPC64_TOC16_LO_DS
:
1811 /* This relocation describes the C++ object vtable hierarchy.
1812 Reconstruct it for later use during GC. */
1813 case R_PPC64_GNU_VTINHERIT
:
1814 if (!_bfd_elf64_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
1818 /* This relocation describes which C++ vtable entries are actually
1819 used. Record for later use during GC. */
1820 case R_PPC64_GNU_VTENTRY
:
1821 if (!_bfd_elf64_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
1825 /* When creating a shared object, we must copy these
1826 relocs into the output file. We create a reloc
1827 section in dynobj and make room for the reloc. */
1832 case R_PPC64_REL14_BRTAKEN
:
1833 case R_PPC64_REL14_BRNTAKEN
:
1845 fprintf (stderr
, "ppc64_elf_check_relocs need to create relocation for %s\n",
1846 (h
&& h
->root
.root
.string
1847 ? h
->root
.root
.string
1854 name
= (bfd_elf_string_from_elf_section
1856 elf_elfheader (abfd
)->e_shstrndx
,
1857 elf_section_data (sec
)->rel_hdr
.sh_name
));
1861 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
1862 && strcmp (bfd_get_section_name (abfd
, sec
),
1865 sreloc
= bfd_get_section_by_name (dynobj
, name
);
1870 sreloc
= bfd_make_section (dynobj
, name
);
1871 flags
= (SEC_HAS_CONTENTS
| SEC_READONLY
1872 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
1873 if ((sec
->flags
& SEC_ALLOC
) != 0)
1874 flags
|= SEC_ALLOC
| SEC_LOAD
;
1876 || ! bfd_set_section_flags (dynobj
, sreloc
, flags
)
1877 || ! bfd_set_section_alignment (dynobj
, sreloc
, 2))
1882 sreloc
->_raw_size
+= sizeof (Elf64_External_Rela
);
1884 /* FIXME: We should here do what the m68k and i386
1885 backends do: if the reloc is pc-relative, record it
1886 in case it turns out that the reloc is unnecessary
1887 because the symbol is forced local by versioning or
1888 we are linking with -Bdynamic. Fortunately this
1889 case is not frequent. */
1899 /* Return the section that should be marked against GC for a given
1903 ppc64_elf_gc_mark_hook (abfd
, info
, rel
, h
, sym
)
1905 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
1906 Elf_Internal_Rela
*rel
;
1907 struct elf_link_hash_entry
*h
;
1908 Elf_Internal_Sym
*sym
;
1912 switch (ELF64_R_TYPE (rel
->r_info
))
1914 case R_PPC64_GNU_VTINHERIT
:
1915 case R_PPC64_GNU_VTENTRY
:
1919 switch (h
->root
.type
)
1921 case bfd_link_hash_defined
:
1922 case bfd_link_hash_defweak
:
1923 return h
->root
.u
.def
.section
;
1925 case bfd_link_hash_common
:
1926 return h
->root
.u
.c
.p
->section
;
1935 if (! (elf_bad_symtab (abfd
)
1936 && ELF_ST_BIND (sym
->st_info
) != STB_LOCAL
)
1937 && ! ((sym
->st_shndx
<= 0 || sym
->st_shndx
>= SHN_LORESERVE
)
1938 && sym
->st_shndx
!= SHN_COMMON
))
1940 return bfd_section_from_elf_index (abfd
, sym
->st_shndx
);
1947 /* Update the got entry reference counts for the section being removed. */
1950 ppc64_elf_gc_sweep_hook (abfd
, info
, sec
, relocs
)
1952 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
1954 const Elf_Internal_Rela
*relocs
;
1956 Elf_Internal_Shdr
*symtab_hdr
;
1957 struct elf_link_hash_entry
**sym_hashes
;
1958 bfd_signed_vma
*local_got_refcounts
;
1959 const Elf_Internal_Rela
*rel
, *relend
;
1960 unsigned long r_symndx
;
1961 struct elf_link_hash_entry
*h
;
1963 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
1964 sym_hashes
= elf_sym_hashes (abfd
);
1965 local_got_refcounts
= elf_local_got_refcounts (abfd
);
1967 relend
= relocs
+ sec
->reloc_count
;
1968 for (rel
= relocs
; rel
< relend
; rel
++)
1969 switch (ELF64_R_TYPE (rel
->r_info
))
1972 case R_PPC64_GOT16_LO
:
1973 case R_PPC64_GOT16_HI
:
1974 case R_PPC64_GOT16_HA
:
1975 r_symndx
= ELF64_R_SYM (rel
->r_info
);
1976 if (r_symndx
>= symtab_hdr
->sh_info
)
1978 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1979 if (h
->got
.refcount
> 0)
1984 if (local_got_refcounts
[r_symndx
] > 0)
1985 local_got_refcounts
[r_symndx
]--;
1990 case R_PPC64_PLT16_LO
:
1991 case R_PPC64_PLT16_HI
:
1992 case R_PPC64_PLT16_HA
:
1993 r_symndx
= ELF64_R_SYM (rel
->r_info
);
1994 if (r_symndx
>= symtab_hdr
->sh_info
)
1996 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1997 if (h
->plt
.refcount
> 0)
2009 /* Adjust a symbol defined by a dynamic object and referenced by a
2010 regular object. The current definition is in some section of the
2011 dynamic object, but we're not including those sections. We have to
2012 change the definition to something the rest of the link can
2016 ppc64_elf_adjust_dynamic_symbol (info
, h
)
2017 struct bfd_link_info
*info
;
2018 struct elf_link_hash_entry
*h
;
2020 bfd
*dynobj
= elf_hash_table (info
)->dynobj
;
2022 unsigned int power_of_two
;
2026 fprintf (stderr
, "ppc64_elf_adjust_dynamic_symbol called for %s\n",
2027 h
->root
.root
.string
);
2030 /* Make sure we know what is going on here. */
2031 BFD_ASSERT (dynobj
!= NULL
2032 && ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
)
2033 || h
->weakdef
!= NULL
2034 || ((h
->elf_link_hash_flags
2035 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0
2036 && (h
->elf_link_hash_flags
2037 & ELF_LINK_HASH_REF_REGULAR
) != 0
2038 && (h
->elf_link_hash_flags
2039 & ELF_LINK_HASH_DEF_REGULAR
) == 0)));
2041 /* If this is a function, alter the symbol to refer to global
2042 linkage code, which will be generated by ppc64_elf_relocate_section.
2043 Also, allocate a slot in the PLT. */
2044 if (h
->type
== STT_FUNC
2045 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
2047 asection
*splt
, *sglink
;
2049 if (! elf_hash_table (info
)->dynamic_sections_created
2050 || ((!info
->shared
|| info
->symbolic
|| h
->dynindx
== -1)
2051 && (h
->elf_link_hash_flags
2052 & ELF_LINK_HASH_DEF_REGULAR
) != 0))
2054 /* A PLT entry is not required/allowed when:
2056 1. We are not using ld.so; because then the PLT entry
2057 can't be set up, so we can't use one.
2059 2. We know for certain that a symbol is defined in
2060 this object, because this object is the application,
2061 is linked with -Bsymbolic, or because the symbol is local.
2063 We used to end up here for GC if
2064 (info->shared && h->plt.refcount <= 0)
2065 We can't use plt.refcount here since
2066 ppc64_elf_check_relocs can't detect all needs for
2067 PLT. FIXME: Rewrite GC. */
2069 h
->plt
.offset
= (bfd_vma
) -1;
2070 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
2074 splt
= bfd_get_section_by_name (dynobj
, ".plt");
2075 sglink
= bfd_get_section_by_name (dynobj
, ".glink");
2076 BFD_ASSERT (splt
!= NULL
&& sglink
!= NULL
);
2078 /* If it's a function entry point (the name starts with a dot)
2079 (FIXME: Could it ever be anything else?), find its
2080 corresponding function descriptor symbol and make sure it's
2081 output as a dynamic symbol. Create it as undefined if
2082 necessary. ppc64_elf_finish_dynamic_symbol will look it up
2083 again and create a JMP_SLOT reloc for it. FIXME: The second
2084 lookup could be avoided by adding a new flag to
2085 elf_link_hash_entry->elf_link_hash_flags. */
2087 if (h
->root
.root
.string
[0] == '.')
2089 struct elf_link_hash_entry
*fdh
;
2091 /* FIXME: Follow bfd_link_hash_indirect? */
2092 fdh
= elf_link_hash_lookup (elf_hash_table (info
),
2093 h
->root
.root
.string
+ 1,
2094 false, false, false);
2096 if (fdh
== (struct elf_link_hash_entry
*) NULL
)
2100 /* Create it as undefined. */
2101 newsym
= bfd_make_empty_symbol (dynobj
);
2102 BFD_ASSERT (newsym
!= NULL
);
2103 /* FIXME: Need own copy of name? */
2104 newsym
->name
= h
->root
.root
.string
+ 1;
2105 newsym
->section
= bfd_und_section_ptr
;
2107 newsym
->flags
= BSF_DYNAMIC
| BSF_OBJECT
;
2109 if ( ! (_bfd_generic_link_add_one_symbol
2110 (info
, dynobj
, newsym
->name
, newsym
->flags
,
2111 newsym
->section
, newsym
->value
,
2115 (struct bfd_link_hash_entry
**) &fdh
)))
2117 /* FIXME: Print error message. */
2120 fdh
->root
.type
= bfd_link_hash_undefined
;
2122 fprintf (stderr
, "\tcreated %s", newsym
->name
);
2127 fprintf (stderr
, "\tfound %s", fdh
->root
.root
.string
);
2128 fprintf (stderr
, "\n");
2131 BFD_ASSERT (fdh
!= NULL
);
2133 /* Make sure it's output as a dynamic symbol. */
2134 if (fdh
->dynindx
== -1)
2136 if (! bfd_elf64_link_record_dynamic_symbol (info
, fdh
))
2139 BFD_ASSERT (fdh
->dynindx
!= -1);
2142 /* If this is the first .plt entry, make room for the special
2144 if (splt
->_raw_size
== 0)
2145 splt
->_raw_size
= PLT_INITIAL_ENTRY_SIZE
;
2147 plt_offset
= splt
->_raw_size
;
2149 /* FIXME: What about function pointer comparisons in 64-bit PPC?
2150 We can't use the same trick as 32-bit PPC, since we set the
2151 symbol to the linkage function. This will make function entry
2152 point comparison work as expected within one object, but not
2153 across object boundaries. From the ABI:
2155 In this ABI, the address of a function is actually the address of a
2156 function descriptor. A reference to a function, other than a function
2157 call, will normally load the address of the function descriptor from
2158 the global offset table. The dynamic linker will ensure that for a
2159 given function, the same address is used for all references to the
2160 function from any global offset table. Thus, function address
2161 comparisons will work as expected.
2163 When making a call to the function, the code may refer to the
2164 procedure linkage table entry, in order to permit lazy symbol
2165 resolution at run time. In order to support correct function address
2166 comparisons, the compiler should be careful to only generate
2167 references to the procedure linkage table entry for function calls.
2168 For any other use of a function, the compiler should use the real
2171 I don't see how this could ever work when passing a pointer to
2172 a function across an object boundary. The compiler has no
2173 way of knowing how to find the function descriptor for a
2174 function whose entrypoint is taken as an argument.
2176 Or should the compiler arrange so that the function descriptor
2177 address is passed and make the callee dig out the entry point
2180 /* If this symbol is not defined in a regular file, and we are
2181 not generating a shared library, then set the symbol to this
2182 location in the .plt. This is required to make function
2183 pointers compare as equal between the normal executable and
2184 the shared library. */
2186 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
2188 h
->root
.u
.def
.section
= splt
;
2189 h
->root
.u
.def
.value
= plt_offset
;
2193 /* FIXME: How should a linkage symbol be defined? It shouldn't
2194 be global, since it can't be used by any other object than
2195 this one. Set ELF_LINK_FORCED_LOCAL? */
2196 h
->root
.type
= bfd_link_hash_defined
;
2197 h
->root
.u
.def
.section
= sglink
;
2198 h
->root
.u
.def
.value
= sglink
->_raw_size
;
2199 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
2200 h
->plt
.offset
= plt_offset
;
2202 /* Make room for global linkage code in .glink. */
2203 sglink
->_raw_size
+= PPC64_ELF_GLINK_SIZE
;
2205 /* Make room for this entry in PLT. */
2206 splt
->_raw_size
+= PLT_ENTRY_SIZE
;
2208 /* We also need to make an entry in the .rela.plt section. */
2209 s
= bfd_get_section_by_name (dynobj
, ".rela.plt");
2210 BFD_ASSERT (s
!= NULL
);
2211 s
->_raw_size
+= sizeof (Elf64_External_Rela
);
2216 /* If this is a weak symbol, and there is a real definition, the
2217 processor independent code will have arranged for us to see the
2218 real definition first, and we can just use the same value. */
2219 if (h
->weakdef
!= NULL
)
2221 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
2222 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
2223 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
2224 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
2228 /* This is a reference to a symbol defined by a dynamic object which
2229 is not a function. */
2231 /* If we are creating a shared library, we must presume that the
2232 only references to the symbol are via the global offset table.
2233 For such cases we need not do anything here; the relocations will
2234 be handled correctly by relocate_section. */
2238 /* We must allocate the symbol in our .dynbss section, which will
2239 become part of the .bss section of the executable. There will be
2240 an entry for this symbol in the .dynsym section. The dynamic
2241 object will contain position independent code, so all references
2242 from the dynamic object to this symbol will go through the global
2243 offset table. The dynamic linker will use the .dynsym entry to
2244 determine the address it must put in the global offset table, so
2245 both the dynamic object and the regular object will refer to the
2246 same memory location for the variable. */
2247 s
= bfd_get_section_by_name (dynobj
, ".dynbss");
2248 BFD_ASSERT (s
!= NULL
);
2250 /* We must generate a R_PPC_COPY reloc to tell the dynamic linker to
2251 copy the initial value out of the dynamic object and into the
2252 runtime process image. We need to remember the offset into the
2253 .rela.bss section we are going to use. */
2254 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
2258 srel
= bfd_get_section_by_name (dynobj
, ".rela.bss");
2259 BFD_ASSERT (srel
!= NULL
);
2260 srel
->_raw_size
+= sizeof (Elf64_External_Rela
);
2261 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_COPY
;
2264 /* We need to figure out the alignment required for this symbol. I
2265 have no idea how ELF linkers handle this. */
2266 power_of_two
= bfd_log2 (h
->size
);
2267 if (power_of_two
> 4)
2270 /* Apply the required alignment. */
2271 s
->_raw_size
= BFD_ALIGN (s
->_raw_size
,
2272 (bfd_size_type
) (1 << power_of_two
));
2273 if (power_of_two
> bfd_get_section_alignment (dynobj
, s
))
2275 if (! bfd_set_section_alignment (dynobj
, s
, power_of_two
))
2279 /* Define the symbol as being at this point in the section. */
2280 h
->root
.u
.def
.section
= s
;
2281 h
->root
.u
.def
.value
= s
->_raw_size
;
2283 /* Increment the section size to make room for the symbol. */
2284 s
->_raw_size
+= h
->size
;
2289 /* Increment the index of a dynamic symbol by a given amount. Called
2290 via elf_link_hash_traverse. */
2293 ppc_adjust_dynindx (h
, cparg
)
2294 struct elf_link_hash_entry
*h
;
2297 int *cp
= (int *) cparg
;
2301 "ppc_adjust_dynindx: h->dynindx = %ld, *cp = %d (%s)\n",
2303 h
->root
.root
.string
? h
->root
.root
.string
: "<unknown>");
2306 if (h
->dynindx
!= -1)
2312 /* Set the sizes of the dynamic sections. */
2315 ppc64_elf_size_dynamic_sections (output_bfd
, info
)
2317 struct bfd_link_info
*info
;
2326 fprintf (stderr
, "ppc64_elf_size_dynamic_sections called\n");
2329 dynobj
= elf_hash_table (info
)->dynobj
;
2330 BFD_ASSERT (dynobj
!= NULL
);
2332 if (elf_hash_table (info
)->dynamic_sections_created
)
2334 /* Set the contents of the .interp section to the interpreter. */
2337 s
= bfd_get_section_by_name (dynobj
, ".interp");
2338 BFD_ASSERT (s
!= NULL
);
2339 s
->_raw_size
= sizeof ELF_DYNAMIC_INTERPRETER
;
2340 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
2345 /* We may have created entries in the .rela.got section.
2346 However, if we are not creating the dynamic sections, we will
2347 not actually use these entries. Reset the size of .rela.got
2348 which will cause it to get stripped from the output file
2350 s
= bfd_get_section_by_name (dynobj
, ".rela.got");
2355 /* The check_relocs and adjust_dynamic_symbol entry points have
2356 determined the sizes of the various dynamic sections. Allocate
2361 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
2366 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
2369 /* It's OK to base decisions on the section name, because none
2370 of the dynobj section names depend upon the input files. */
2371 name
= bfd_get_section_name (dynobj
, s
);
2375 if (strcmp (name
, ".plt") == 0)
2377 if (s
->_raw_size
== 0)
2379 /* Strip this section if we don't need it; see the
2385 /* Remember whether there is a PLT. */
2389 else if (strncmp (name
, ".rela", 5) == 0)
2391 if (s
->_raw_size
== 0)
2393 /* If we don't need this section, strip it from the
2394 output file. This is mostly to handle .rela.bss and
2395 .rela.plt. We must create both sections in
2396 create_dynamic_sections, because they must be created
2397 before the linker maps input sections to output
2398 sections. The linker does that before
2399 adjust_dynamic_symbol is called, and it is that
2400 function which decides whether anything needs to go
2401 into these sections. */
2407 const char *outname
;
2409 /* Remember whether there are any relocation sections. */
2412 /* If this relocation section applies to a read only
2413 section, then we probably need a DT_TEXTREL entry. */
2414 outname
= bfd_get_section_name (output_bfd
,
2416 target
= bfd_get_section_by_name (output_bfd
, outname
+ 5);
2418 && (target
->flags
& SEC_READONLY
) != 0
2419 && (target
->flags
& SEC_ALLOC
) != 0)
2422 /* We use the reloc_count field as a counter if we need
2423 to copy relocs into the output file. */
2427 else if (strcmp (name
, ".got") != 0
2428 && strcmp (name
, ".toc") != 0
2429 && strcmp (name
, ".glink") != 0)
2431 /* It's not one of our sections, so don't allocate space. */
2437 _bfd_strip_section_from_output (info
, s
);
2442 fprintf (stderr
, "\tallocating %lu bytes for section %s\n",
2443 (unsigned long) s
->_raw_size
, name
);
2446 /* Allocate memory for the section contents. */
2447 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->_raw_size
);
2448 if (s
->contents
== NULL
&& s
->_raw_size
!= 0)
2452 if (elf_hash_table (info
)->dynamic_sections_created
)
2454 /* Add some entries to the .dynamic section. We fill in the
2455 values later, in ppc64_elf_finish_dynamic_sections, but we
2456 must add the entries now so that we get the correct size for
2457 the .dynamic section. The DT_DEBUG entry is filled in by the
2458 dynamic linker and used by the debugger. */
2459 #define add_dynamic_entry(TAG, VAL) \
2460 bfd_elf64_add_dynamic_entry (info, (bfd_vma) (TAG), (bfd_vma) (VAL))
2464 if (!add_dynamic_entry (DT_DEBUG
, 0))
2470 if (!add_dynamic_entry (DT_PLTGOT
, 0)
2471 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
2472 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
2473 || !add_dynamic_entry (DT_JMPREL
, 0))
2479 if (!add_dynamic_entry (DT_RELA
, 0)
2480 || !add_dynamic_entry (DT_RELASZ
, 0)
2481 || !add_dynamic_entry (DT_RELAENT
, sizeof (Elf64_External_Rela
)))
2487 if (!add_dynamic_entry (DT_TEXTREL
, 0))
2491 #undef add_dynamic_entry
2493 /* If we are generating a shared library, we generate a section
2494 symbol for each output section. These are local symbols, which
2495 means that they must come first in the dynamic symbol table.
2496 That means we must increment the dynamic symbol index of every
2497 other dynamic symbol.
2499 FIXME: We assume that there will never be relocations to
2500 locations in linker-created sections that do not have
2501 externally-visible names. Instead, we should work out precisely
2502 which sections relocations are targetted at. */
2507 for (c
= 0, s
= output_bfd
->sections
; s
!= NULL
; s
= s
->next
)
2509 if ((s
->flags
& SEC_LINKER_CREATED
) != 0
2510 || (s
->flags
& SEC_ALLOC
) == 0)
2512 elf_section_data (s
)->dynindx
= -1;
2516 /* These symbols will have no names, so we don't need to
2517 fiddle with dynstr_index. */
2519 elf_section_data (s
)->dynindx
= c
+ 1;
2524 elf_link_hash_traverse (elf_hash_table (info
),
2527 elf_hash_table (info
)->dynsymcount
+= c
;
2533 /* Called after we have seen all the input files/sections, but before
2534 final symbol resolution and section placement has been determined.
2536 We use this hook to provide a value for TOCstart, which we store in
2537 the output bfd elf_gp, then we call the generic ELF final link
2541 ppc64_elf_final_link (abfd
, info
)
2543 struct bfd_link_info
*info
;
2545 if (! info
->relocateable
)
2550 /* The TOC consists of sections .got, .toc, .tocbss, .plt in this
2551 order. The TOC starts where the first of these sections starts. */
2552 s
= bfd_get_section_by_name (abfd
, ".got");
2554 s
= bfd_get_section_by_name (abfd
, ".toc");
2556 s
= bfd_get_section_by_name (abfd
, ".tocbss");
2558 s
= bfd_get_section_by_name (abfd
, ".plt");
2561 /* This may happen for
2562 o references to TOC base (SYM@toc / TOC[tc0]) without a
2565 o --gc-sections and empty TOC sections
2567 FIXME: Warn user? */
2569 /* Look for a likely section. We probably won't even be
2571 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
2572 if ((s
->flags
& (SEC_ALLOC
| SEC_SMALL_DATA
| SEC_READONLY
))
2573 == (SEC_ALLOC
| SEC_SMALL_DATA
))
2576 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
2577 if ((s
->flags
& (SEC_ALLOC
| SEC_SMALL_DATA
))
2578 == (SEC_ALLOC
| SEC_SMALL_DATA
))
2581 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
2582 if ((s
->flags
& (SEC_ALLOC
| SEC_READONLY
)) == SEC_ALLOC
)
2585 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
2586 if ((s
->flags
& SEC_ALLOC
) == SEC_ALLOC
)
2592 TOCstart
= s
->output_section
->vma
+ s
->output_offset
;
2594 elf_gp (abfd
) = TOCstart
;
2597 /* Invoke the regular gc ELF backend linker to do all the work. */
2598 return _bfd_elf64_gc_common_final_link (abfd
, info
);
2601 /* Set up any other section flags and such that may be necessary. */
2604 ppc64_elf_fake_sections (abfd
, shdr
, asect
)
2605 bfd
*abfd ATTRIBUTE_UNUSED
;
2606 Elf64_Internal_Shdr
*shdr
;
2609 if ((asect
->flags
& SEC_EXCLUDE
) != 0)
2610 shdr
->sh_flags
|= SHF_EXCLUDE
;
2612 if ((asect
->flags
& SEC_SORT_ENTRIES
) != 0)
2613 shdr
->sh_type
= SHT_ORDERED
;
2618 /* The RELOCATE_SECTION function is called by the ELF backend linker
2619 to handle the relocations for a section.
2621 The relocs are always passed as Rela structures; if the section
2622 actually uses Rel structures, the r_addend field will always be
2625 This function is responsible for adjust the section contents as
2626 necessary, and (if using Rela relocs and generating a
2627 relocateable output file) adjusting the reloc addend as
2630 This function does not have to worry about setting the reloc
2631 address or the reloc symbol index.
2633 LOCAL_SYMS is a pointer to the swapped in local symbols.
2635 LOCAL_SECTIONS is an array giving the section in the input file
2636 corresponding to the st_shndx field of each local symbol.
2638 The global hash table entry for the global symbols can be found
2639 via elf_sym_hashes (input_bfd).
2641 When generating relocateable output, this function must handle
2642 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
2643 going to be the section symbol corresponding to the output
2644 section, which means that the addend must be adjusted
2648 ppc64_elf_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
2649 contents
, relocs
, local_syms
, local_sections
)
2651 struct bfd_link_info
*info
;
2653 asection
*input_section
;
2655 Elf_Internal_Rela
*relocs
;
2656 Elf_Internal_Sym
*local_syms
;
2657 asection
**local_sections
;
2659 Elf_Internal_Shdr
*symtab_hdr
;
2660 struct elf_link_hash_entry
**sym_hashes
;
2662 Elf_Internal_Rela
*rel
;
2663 Elf_Internal_Rela
*relend
;
2667 bfd_vma
*local_got_offsets
;
2672 fprintf (stderr
, "ppc64_elf_relocate_section called for %s section %s, %ld relocations%s\n",
2673 bfd_get_filename (input_bfd
),
2674 bfd_section_name (input_bfd
, input_section
),
2675 (long) input_section
->reloc_count
,
2676 (info
->relocateable
) ? " (relocatable)" : "");
2679 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
2680 /* Initialize howto table if needed. */
2683 local_got_offsets
= elf_local_got_offsets (input_bfd
);
2688 dynobj
= elf_hash_table (info
)->dynobj
;
2691 splt
= bfd_get_section_by_name (dynobj
, ".plt");
2692 sgot
= bfd_get_section_by_name (dynobj
, ".got");
2694 TOCstart
= elf_gp (output_bfd
);
2696 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
2697 sym_hashes
= elf_sym_hashes (input_bfd
);
2699 relend
= relocs
+ input_section
->reloc_count
;
2700 for (; rel
< relend
; rel
++)
2702 enum elf_ppc_reloc_type r_type
;
2705 bfd_reloc_status_type r
;
2706 Elf_Internal_Sym
*sym
;
2708 struct elf_link_hash_entry
*h
;
2709 const char *sym_name
;
2710 reloc_howto_type
*howto
;
2711 unsigned long r_symndx
;
2715 r_type
= (enum elf_ppc_reloc_type
) ELF64_R_TYPE (rel
->r_info
);
2716 offset
= rel
->r_offset
;
2717 addend
= rel
->r_addend
;
2718 r
= bfd_reloc_other
;
2719 sym
= (Elf_Internal_Sym
*) 0;
2720 sec
= (asection
*) 0;
2721 h
= (struct elf_link_hash_entry
*) 0;
2722 sym_name
= (const char *) 0;
2724 /* Unknown relocation handling. */
2725 if ((unsigned) r_type
>= (unsigned) R_PPC_max
2726 || !ppc64_elf_howto_table
[(int) r_type
])
2728 (*_bfd_error_handler
) (_("%s: unknown relocation type %d"),
2729 bfd_get_filename (input_bfd
),
2731 bfd_set_error (bfd_error_bad_value
);
2736 howto
= ppc64_elf_howto_table
[(int) r_type
];
2737 r_symndx
= ELF64_R_SYM (rel
->r_info
);
2739 if (info
->relocateable
)
2741 /* This is a relocatable link. We don't have to change
2742 anything, unless the reloc is against a section symbol,
2743 in which case we have to adjust according to where the
2744 section symbol winds up in the output section. */
2745 if (r_symndx
< symtab_hdr
->sh_info
)
2747 sym
= local_syms
+ r_symndx
;
2748 if ((unsigned) ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
2750 sec
= local_sections
[r_symndx
];
2751 addend
= rel
->r_addend
+= sec
->output_offset
+ sym
->st_value
;
2756 fprintf (stderr
, "\ttype = %s (%d), symbol index = %ld, offset = %ld, addend = %ld\n",
2766 /* This is a final link. */
2768 /* Set `relocation'. */
2769 if (r_type
== R_PPC64_TOC
)
2771 /* Relocation value is TOC base. Symbol is ignored. */
2772 relocation
= TOCstart
+ TOC_BASE_OFF
;
2774 else if (r_symndx
< symtab_hdr
->sh_info
)
2776 /* It's a local symbol. */
2777 sym
= local_syms
+ r_symndx
;
2778 sec
= local_sections
[r_symndx
];
2779 sym_name
= "<local symbol>";
2781 relocation
= (sec
->output_section
->vma
2782 + sec
->output_offset
2787 /* It's a global symbol. */
2788 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2789 while (h
->root
.type
== bfd_link_hash_indirect
2790 || h
->root
.type
== bfd_link_hash_warning
)
2791 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2792 sym_name
= h
->root
.root
.string
;
2793 if (h
->root
.type
== bfd_link_hash_defined
2794 || h
->root
.type
== bfd_link_hash_defweak
)
2796 sec
= h
->root
.u
.def
.section
;
2797 if ((r_type
== R_PPC64_PLT32
2798 && h
->plt
.offset
!= (bfd_vma
) -1)
2799 || ((r_type
== R_PPC64_GOT16
2800 || r_type
== R_PPC64_GOT16_LO
2801 || r_type
== R_PPC64_GOT16_HI
2802 || r_type
== R_PPC64_GOT16_HA
2803 || r_type
== R_PPC64_GOT16_DS
2804 || r_type
== R_PPC64_GOT16_LO_DS
)
2805 && elf_hash_table (info
)->dynamic_sections_created
2807 || (! info
->symbolic
&& h
->dynindx
!= -1)
2808 || (h
->elf_link_hash_flags
2809 & ELF_LINK_HASH_DEF_REGULAR
) == 0))
2811 && ((! info
->symbolic
&& h
->dynindx
!= -1)
2812 || (h
->elf_link_hash_flags
2813 & ELF_LINK_HASH_DEF_REGULAR
) == 0)
2814 && (input_section
->flags
& SEC_ALLOC
) != 0
2815 && (r_type
== R_PPC64_ADDR64
2816 || r_type
== R_PPC64_ADDR32
2817 || r_type
== R_PPC64_ADDR24
2818 || r_type
== R_PPC64_ADDR16
2819 || r_type
== R_PPC64_ADDR16_LO
2820 || r_type
== R_PPC64_ADDR16_DS
2821 || r_type
== R_PPC64_ADDR16_LO_DS
2822 || r_type
== R_PPC64_ADDR16_HI
2823 || r_type
== R_PPC64_ADDR16_HA
2824 || r_type
== R_PPC64_ADDR16_HIGHER
2825 || r_type
== R_PPC64_ADDR16_HIGHERA
2826 || r_type
== R_PPC64_ADDR16_HIGHEST
2827 || r_type
== R_PPC64_ADDR16_HIGHESTA
2828 || r_type
== R_PPC64_ADDR14
2829 || r_type
== R_PPC64_ADDR14_BRTAKEN
2830 || r_type
== R_PPC64_ADDR14_BRNTAKEN
2831 || r_type
== R_PPC64_COPY
2832 || r_type
== R_PPC64_GLOB_DAT
2833 || r_type
== R_PPC64_JMP_SLOT
2834 || r_type
== R_PPC64_UADDR64
2835 || r_type
== R_PPC64_UADDR32
2836 || r_type
== R_PPC64_UADDR16
)))
2838 /* In these cases, we don't need the relocation
2839 value. We check specially because in some
2840 obscure cases sec->output_section will be NULL. */
2844 relocation
= (h
->root
.u
.def
.value
2845 + sec
->output_section
->vma
2846 + sec
->output_offset
);
2848 else if (h
->root
.type
== bfd_link_hash_undefweak
)
2850 else if (info
->shared
&& !info
->symbolic
&& !info
->no_undefined
)
2854 if (! ((*info
->callbacks
->undefined_symbol
)
2855 (info
, h
->root
.root
.string
, input_bfd
, input_section
,
2856 rel
->r_offset
, (!info
->shared
2857 || info
->no_undefined
2858 || ELF_ST_VISIBILITY (h
->other
)))))
2864 switch ((int) r_type
)
2866 case (int) R_PPC64_ADDR16_DS
:
2867 case (int) R_PPC64_ADDR16_LO_DS
:
2868 case (int) R_PPC64_GOT16_DS
:
2869 case (int) R_PPC64_GOT16_LO_DS
:
2870 case (int) R_PPC64_PLT16_LO_DS
:
2871 case (int) R_PPC64_SECTOFF_DS
:
2872 case (int) R_PPC64_SECTOFF_LO_DS
:
2873 case (int) R_PPC64_TOC16_DS
:
2874 case (int) R_PPC64_TOC16_LO_DS
:
2875 case (int) R_PPC64_PLTGOT16_DS
:
2876 case (int) R_PPC64_PLTGOT16_LO_DS
:
2877 if (((relocation
+ addend
) & 3) != 0)
2879 (*_bfd_error_handler
) (_("%s: error: relocation %s not a multiple of 4"),
2880 bfd_get_filename (input_bfd
),
2882 bfd_set_error (bfd_error_bad_value
);
2889 switch ((int) r_type
)
2892 (*_bfd_error_handler
) (_("%s: unknown relocation type %d for symbol %s"),
2893 bfd_get_filename (input_bfd
),
2894 (int) r_type
, sym_name
);
2896 bfd_set_error (bfd_error_bad_value
);
2900 /* Relocations that may need to be propagated if this is a shared
2902 case (int) R_PPC64_REL24
:
2903 case (int) R_PPC64_ADDR24
:
2904 /* An ADDR24 or REL24 branching to a linkage function may be
2905 followed by a nop that we have to replace with an ld in
2906 order to restore the TOC base pointer. Only calls to
2907 shared objects need to alter the TOC base. These are
2908 recognized by their need for a PLT entry. */
2910 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0
2911 /* Make sure that there really is an instruction after
2912 the branch that we can decode. */
2913 && (rel
->r_offset
- input_section
->vma
+ 8
2914 <= input_section
->_cooked_size
))
2918 pnext
= contents
+ (rel
->r_offset
- input_section
->vma
) + 4;
2919 insn
= bfd_get_32 (input_bfd
, pnext
);
2921 if (insn
== 0x60000000 /* nop (ori r0,r0,0) */
2922 || insn
== 0x4def7b82 /* cror 15,15,15 */
2923 || insn
== 0x4ffffb82) /* cror 31,31,31 */
2925 bfd_put_32 (input_bfd
,
2926 (bfd_vma
) 0xe8410028, /* ld r2,40(r1) */
2929 fprintf (stderr
, "ppc64_elf_relocate_section: " \
2930 "patched nop after call to %s\n", sym_name
);
2936 case (int) R_PPC64_REL64
:
2937 case (int) R_PPC64_REL32
:
2938 case (int) R_PPC64_REL14
:
2939 /* If these relocations are not to a named symbol, they can be
2940 handled right here, no need to bother the dynamic linker. */
2941 if (h
== NULL
&& r_type
!= R_PPC64_ADDR24
)
2945 /* Relocations that always need to be propagated if this is a shared
2947 case (int) R_PPC64_NONE
:
2948 case (int) R_PPC64_ADDR64
:
2949 case (int) R_PPC64_ADDR32
:
2950 case (int) R_PPC64_ADDR16
:
2951 case (int) R_PPC64_ADDR16_LO
:
2952 case (int) R_PPC64_ADDR16_DS
:
2953 case (int) R_PPC64_ADDR16_LO_DS
:
2954 case (int) R_PPC64_ADDR16_HI
:
2955 case (int) R_PPC64_ADDR16_HA
:
2956 case (int) R_PPC64_ADDR16_HIGHER
:
2957 case (int) R_PPC64_ADDR16_HIGHERA
:
2958 case (int) R_PPC64_ADDR16_HIGHEST
:
2959 case (int) R_PPC64_ADDR16_HIGHESTA
:
2960 case (int) R_PPC64_ADDR14
:
2961 case (int) R_PPC64_UADDR64
:
2962 case (int) R_PPC64_UADDR32
:
2963 case (int) R_PPC64_UADDR16
:
2964 case (int) R_PPC64_TOC
:
2967 Elf_Internal_Rela outrel
;
2971 fprintf (stderr
, "ppc64_elf_relocate_section need to create relocation for %s\n",
2972 (h
&& h
->root
.root
.string
2973 ? h
->root
.root
.string
2977 /* When generating a shared object, these relocations
2978 are copied into the output file to be resolved at run
2985 name
= (bfd_elf_string_from_elf_section
2987 elf_elfheader (input_bfd
)->e_shstrndx
,
2988 elf_section_data (input_section
)->rel_hdr
.sh_name
));
2992 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
2993 && strcmp (bfd_get_section_name (input_bfd
,
2997 sreloc
= bfd_get_section_by_name (dynobj
, name
);
2998 BFD_ASSERT (sreloc
!= NULL
);
3003 if (elf_section_data (input_section
)->stab_info
== NULL
)
3004 outrel
.r_offset
= rel
->r_offset
;
3009 off
= (_bfd_stab_section_offset
3010 (output_bfd
, &elf_hash_table (info
)->stab_info
,
3012 &elf_section_data (input_section
)->stab_info
,
3014 if (off
== (bfd_vma
) -1)
3016 outrel
.r_offset
= off
;
3019 outrel
.r_offset
+= (input_section
->output_section
->vma
3020 + input_section
->output_offset
);
3023 memset (&outrel
, 0, sizeof outrel
);
3024 /* h->dynindx may be -1 if this symbol was marked to
3027 && ((! info
->symbolic
&& h
->dynindx
!= -1)
3028 || (h
->elf_link_hash_flags
3029 & ELF_LINK_HASH_DEF_REGULAR
) == 0))
3031 BFD_ASSERT (h
->dynindx
!= -1);
3032 outrel
.r_info
= ELF64_R_INFO (h
->dynindx
, r_type
);
3033 outrel
.r_addend
= rel
->r_addend
;
3037 if (r_type
== R_PPC64_ADDR64
)
3039 outrel
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
3040 outrel
.r_addend
= relocation
+ rel
->r_addend
;
3047 sec
= local_sections
[r_symndx
];
3050 BFD_ASSERT (h
->root
.type
== bfd_link_hash_defined
3052 == bfd_link_hash_defweak
));
3053 sec
= h
->root
.u
.def
.section
;
3056 if (r_type
== R_PPC64_TOC
3057 || (sec
!= NULL
&& bfd_is_abs_section (sec
)))
3061 else if (sec
== NULL
|| sec
->owner
== NULL
)
3063 bfd_set_error (bfd_error_bad_value
);
3070 osec
= sec
->output_section
;
3071 indx
= elf_section_data (osec
)->dynindx
;
3072 BFD_ASSERT (indx
> 0);
3076 printf ("indx=%ld section=%s flags=%08x name=%s\n",
3077 indx
, osec
->name
, osec
->flags
,
3078 h
->root
.root
.string
);
3083 outrel
.r_info
= ELF64_R_INFO (indx
, r_type
);
3084 outrel
.r_addend
= relocation
+ rel
->r_addend
;
3088 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
,
3089 (((Elf64_External_Rela
*)
3091 + sreloc
->reloc_count
));
3092 ++sreloc
->reloc_count
;
3094 /* This reloc will be computed at runtime, so there's no
3095 need to do anything now, unless this is a RELATIVE
3096 reloc in an unallocated section. */
3098 || (input_section
->flags
& SEC_ALLOC
) != 0
3099 || ELF64_R_TYPE (outrel
.r_info
) != R_PPC64_RELATIVE
)
3103 /* Arithmetic adjust relocations that aren't going into a
3105 if ((r_type
== R_PPC64_ADDR16_HA
3106 || r_type
== R_PPC64_ADDR16_HIGHERA
3107 || r_type
== R_PPC64_ADDR16_HIGHESTA
)
3108 /* It's just possible that this symbol is a weak symbol
3109 that's not actually defined anywhere. In that case,
3110 'sec' would be NULL, and we should leave the symbol
3111 alone (it will be set to zero elsewhere in the link). */
3114 addend
+= ((relocation
+ addend
) & 0x8000) << 1;
3118 /* Branch taken prediction relocations. */
3119 case (int) R_PPC64_ADDR14_BRTAKEN
:
3120 case (int) R_PPC64_REL14_BRTAKEN
:
3121 insn
= bfd_get_32 (output_bfd
, contents
+ offset
);
3122 if ((relocation
- offset
) & 0x8000)
3123 insn
&= ~BRANCH_PREDICT_BIT
;
3125 insn
|= BRANCH_PREDICT_BIT
;
3126 bfd_put_32 (output_bfd
, (bfd_vma
) insn
, contents
+ offset
);
3129 /* Branch not taken predicition relocations. */
3130 case (int) R_PPC64_ADDR14_BRNTAKEN
:
3131 case (int) R_PPC64_REL14_BRNTAKEN
:
3132 insn
= bfd_get_32 (output_bfd
, contents
+ offset
);
3133 if ((relocation
- offset
) & 0x8000)
3134 insn
|= BRANCH_PREDICT_BIT
;
3136 insn
&= ~BRANCH_PREDICT_BIT
;
3137 bfd_put_32 (output_bfd
, (bfd_vma
) insn
, contents
+ offset
);
3141 /* GOT16 relocations. Like an ADDR16 using the symbol's
3142 address in the GOT as relocation value instead of the
3143 symbols value itself. Also, create a GOT entry for the
3144 symbol and put the symbol value there. */
3145 /* FIXME: If the symbol is not in the .got section
3146 (typically in the .toc section) we fail (h->got.offset is
3148 /* NOTE: Sets `relocation'. */
3149 case (int) R_PPC64_GOT16
:
3150 case (int) R_PPC64_GOT16_LO
:
3151 case (int) R_PPC64_GOT16_HI
:
3152 case (int) R_PPC64_GOT16_HA
:
3153 case (int) R_PPC64_GOT16_DS
:
3154 case (int) R_PPC64_GOT16_LO_DS
:
3156 /* Relocation is to the entry for this symbol in the global
3159 BFD_ASSERT (sgot
!= NULL
);
3163 off
= h
->got
.offset
;
3164 BFD_ASSERT (off
!= (bfd_vma
) -1);
3166 if (! elf_hash_table (info
)->dynamic_sections_created
3168 && (info
->symbolic
|| h
->dynindx
== -1)
3169 && (h
->elf_link_hash_flags
3170 & ELF_LINK_HASH_DEF_REGULAR
)))
3172 /* This is actually a static link, or it is a
3173 -Bsymbolic link and the symbol is defined
3174 locally. We must initialize this entry in the
3175 global offset table. Since the offset must
3176 always be a multiple of 4, we use the least
3177 significant bit to record whether we have
3178 initialized it already.
3180 When doing a dynamic link, we create a .rela.got
3181 relocation entry to initialize the value. This
3182 is done in the finish_dynamic_symbol routine. */
3187 bfd_put_64 (output_bfd
, relocation
,
3188 sgot
->contents
+ off
);
3195 BFD_ASSERT (local_got_offsets
!= NULL
3196 && local_got_offsets
[r_symndx
] != (bfd_vma
) -1);
3198 off
= local_got_offsets
[r_symndx
];
3200 /* The offset must always be a multiple of 4. We use
3201 the least significant bit to record whether we have
3202 already processed this entry. */
3207 bfd_put_64 (output_bfd
, relocation
, sgot
->contents
+ off
);
3212 Elf_Internal_Rela outrel
;
3214 /* We need to generate a R_PPC64_RELATIVE reloc
3215 for the dynamic linker. */
3216 srelgot
= bfd_get_section_by_name (dynobj
, ".rela.got");
3217 BFD_ASSERT (srelgot
!= NULL
);
3219 outrel
.r_offset
= (sgot
->output_section
->vma
3220 + sgot
->output_offset
3222 outrel
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
3223 outrel
.r_addend
= relocation
;
3224 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
,
3225 (((Elf64_External_Rela
*)
3227 + srelgot
->reloc_count
));
3228 ++srelgot
->reloc_count
;
3231 local_got_offsets
[r_symndx
] |= 1;
3235 relocation
= sgot
->output_offset
+ off
;
3236 /* TOC base (r2) is TOC start plus 0x8000. */
3237 addend
-= TOC_BASE_OFF
;
3241 /* TOC16 relocs. We want the offset relative to the TOC base,
3242 which is the address of the start of the TOC plus 0x8000.
3243 The TOC consists of sections .got, .toc, .tocbss, and .plt,
3246 case (int) R_PPC64_TOC16
:
3247 case (int) R_PPC64_TOC16_LO
:
3248 case (int) R_PPC64_TOC16_HI
:
3249 case (int) R_PPC64_TOC16_DS
:
3250 case (int) R_PPC64_TOC16_LO_DS
:
3251 BFD_ASSERT (sec
!= (asection
*) 0);
3252 /* Only .got, .toc and *UND* symbols are allowed. */
3253 BFD_ASSERT (bfd_is_und_section (sec
)
3254 || strcmp (bfd_get_section_name (abfd
, sec
),
3256 || strcmp (bfd_get_section_name (abfd
, sec
),
3259 addend
-= TOCstart
+ TOC_BASE_OFF
;
3262 case (int) R_PPC64_TOC16_HA
:
3263 BFD_ASSERT (sec
!= (asection
*) 0);
3264 BFD_ASSERT (bfd_is_und_section (sec
)
3265 || strcmp (bfd_get_section_name (abfd
, sec
),
3267 || strcmp (bfd_get_section_name (abfd
, sec
),
3270 addend
-= TOCstart
+ TOC_BASE_OFF
;
3271 /* Add 1 to 16-bit word 16:31 if sign bit in 0:15 is set. */
3272 addend
+= ((relocation
+ addend
) & 0x8000) << 1;
3275 /* Relocate against the beginning of the section. */
3276 case (int) R_PPC64_SECTOFF
:
3277 case (int) R_PPC64_SECTOFF_LO
:
3278 case (int) R_PPC64_SECTOFF_HI
:
3279 case (int) R_PPC64_SECTOFF_DS
:
3280 case (int) R_PPC64_SECTOFF_LO_DS
:
3281 BFD_ASSERT (sec
!= (asection
*) 0);
3282 addend
-= sec
->output_section
->vma
;
3285 case (int) R_PPC64_SECTOFF_HA
:
3286 BFD_ASSERT (sec
!= (asection
*) 0);
3287 addend
-= sec
->output_section
->vma
;
3288 addend
+= ((relocation
+ addend
) & 0x8000) << 1;
3291 case (int) R_PPC64_COPY
:
3292 case (int) R_PPC64_GLOB_DAT
:
3293 case (int) R_PPC64_JMP_SLOT
:
3294 case (int) R_PPC64_RELATIVE
:
3295 case (int) R_PPC64_PLT32
:
3296 case (int) R_PPC64_PLTREL32
:
3297 case (int) R_PPC64_PLT16_LO
:
3298 case (int) R_PPC64_PLT16_LO_DS
:
3299 case (int) R_PPC64_PLT16_HI
:
3300 case (int) R_PPC64_PLT16_HA
:
3301 case (int) R_PPC64_PLT64
:
3302 case (int) R_PPC64_PLTREL64
:
3303 case (int) R_PPC64_PLTGOT16
:
3304 case (int) R_PPC64_PLTGOT16_LO
:
3305 case (int) R_PPC64_PLTGOT16_DS
:
3306 case (int) R_PPC64_PLTGOT16_LO_DS
:
3307 case (int) R_PPC64_PLTGOT16_HI
:
3308 case (int) R_PPC64_PLTGOT16_HA
:
3309 (*_bfd_error_handler
) (_("%s: Relocation %s is not yet supported for symbol %s."),
3310 bfd_get_filename (input_bfd
),
3311 ppc64_elf_howto_table
[(int) r_type
]->name
,
3314 bfd_set_error (bfd_error_invalid_operation
);
3318 case (int) R_PPC_GNU_VTINHERIT
:
3319 case (int) R_PPC_GNU_VTENTRY
:
3320 /* These are no-ops in the end. */
3325 fprintf (stderr
, " type = %s (%d), name = %s, sym index = %ld, offset = %ld, addend = %ld\n",
3334 r
= _bfd_final_link_relocate (howto
,
3342 if (r
== bfd_reloc_ok
)
3344 else if (r
== bfd_reloc_overflow
)
3350 if (h
->root
.type
== bfd_link_hash_undefweak
3351 && howto
->pc_relative
)
3353 /* Assume this is a call protected by other code that
3354 detects the symbol is undefined. If this is the case,
3355 we can safely ignore the overflow. If not, the
3356 program is hosed anyway, and a little warning isn't
3362 name
= h
->root
.root
.string
;
3366 name
= bfd_elf_string_from_elf_section (input_bfd
,
3367 symtab_hdr
->sh_link
,
3372 name
= bfd_section_name (input_bfd
, sec
);
3375 if (! (*info
->callbacks
->reloc_overflow
) (info
,
3389 fprintf (stderr
, "\n");
3395 /* Finish up dynamic symbol handling. We set the contents of various
3396 dynamic sections here. */
3399 ppc64_elf_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
3401 struct bfd_link_info
*info
;
3402 struct elf_link_hash_entry
*h
;
3403 Elf_Internal_Sym
*sym
;
3408 fprintf (stderr
, "ppc64_elf_finish_dynamic_symbol called for %s",
3409 h
->root
.root
.string
);
3412 dynobj
= elf_hash_table (info
)->dynobj
;
3413 BFD_ASSERT (dynobj
!= NULL
);
3415 if (h
->plt
.offset
!= (bfd_vma
) -1)
3417 asection
*splt
, *srela
, *sglink
;
3418 Elf_Internal_Rela rela
;
3419 bfd_vma reloc_index
, plt_offset
;
3420 struct elf_link_hash_entry
*funcdesc_h
;
3423 fprintf (stderr
, ", plt_offset = 0x%lx", (unsigned long) h
->plt
.offset
);
3426 /* This symbol has an entry in the procedure linkage table. Set
3429 BFD_ASSERT (h
->dynindx
!= -1);
3431 splt
= bfd_get_section_by_name (dynobj
, ".plt");
3432 srela
= bfd_get_section_by_name (dynobj
, ".rela.plt");
3433 BFD_ASSERT (splt
!= NULL
&& srela
!= NULL
);
3435 /* We don't need to fill in the .plt. The dynamic linker will
3438 /* We may need to create a linkage function. */
3439 sglink
= bfd_get_section_by_name (dynobj
, ".glink");
3440 if (sglink
!= NULL
&& h
->root
.u
.def
.section
== sglink
)
3444 const unsigned int *stub
;
3446 /* Where to write it. */
3447 p
= h
->root
.u
.def
.section
->contents
+ h
->root
.u
.def
.value
;
3449 /* The function descriptor is in the PLT. */
3450 pltoff
= splt
->output_section
->vma
3451 + splt
->output_section
->output_offset
3453 - elf_gp (output_bfd
) - TOC_BASE_OFF
;
3455 if (pltoff
+ 0x8000 > 0xffff)
3457 (*_bfd_error_handler
)
3458 (_("linkage table overflow against `%s'"),
3459 h
->root
.root
.string
);
3463 stub
= ppc64_elf_glink_code
;
3464 bfd_put_32 (output_bfd
, *stub
| (pltoff
& 0xfffc), p
);
3465 while (p
+= 4, ++stub
< (ppc64_elf_glink_code
3466 + (sizeof (ppc64_elf_glink_code
)
3467 / sizeof (*ppc64_elf_glink_code
))));
3469 bfd_put_32 (output_bfd
, (bfd_vma
) *stub
, p
);
3472 fprintf (stderr
, ", linkage function");
3476 /* Create a JMP_SLOT reloc to inform the dynamic linker to fix
3479 /* Save the PLT offset, since `h' may be changed below. */
3480 plt_offset
= h
->plt
.offset
;
3482 /* If it's a function entry point, find its corresponding
3483 function descriptor. ppc64_elf_adjust_dynamic_symbol have
3484 already set it up for us. */
3486 /* FIXME: Is it safe to assume that this symbol is a function? */
3487 BFD_ASSERT (h
->root
.root
.string
[0] == '.');
3489 /* FIXME: Follow bfd_link_hash_indirect? */
3490 funcdesc_h
= elf_link_hash_lookup (elf_hash_table (info
),
3491 h
->root
.root
.string
+ 1,
3492 false, false, false);
3493 BFD_ASSERT (funcdesc_h
!= NULL
);
3494 BFD_ASSERT (funcdesc_h
->dynindx
!= -1);
3496 /* FIXME: Rename the symbol for the function entry point to
3497 `linkage_for_FUNC'? */
3499 rela
.r_offset
= (splt
->output_section
->vma
3500 + splt
->output_offset
3502 rela
.r_info
= ELF64_R_INFO (funcdesc_h
->dynindx
, R_PPC64_JMP_SLOT
);
3505 reloc_index
= (plt_offset
- PLT_INITIAL_ENTRY_SIZE
) / PLT_ENTRY_SIZE
;
3506 bfd_elf64_swap_reloca_out (output_bfd
, &rela
,
3507 ((Elf64_External_Rela
*) srela
->contents
3510 fprintf (stderr
, ", JMP_SLOT for %s", funcdesc_h
->root
.root
.string
);
3514 /* FIXME: Really do this? */
3515 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
3517 /* Mark the symbol as undefined, rather than as defined in
3518 the .plt section. Leave the value alone. */
3519 sym
->st_shndx
= SHN_UNDEF
;
3524 if (h
->got
.offset
!= (bfd_vma
) -1)
3528 Elf_Internal_Rela rela
;
3531 fprintf (stderr
, ", got.offset = %08lx", (unsigned long) h
->got
.offset
);
3534 /* This symbol has an entry in the global offset table. Set it
3537 sgot
= bfd_get_section_by_name (dynobj
, ".got");
3538 srela
= bfd_get_section_by_name (dynobj
, ".rela.got");
3539 BFD_ASSERT (sgot
!= NULL
&& srela
!= NULL
);
3541 rela
.r_offset
= (sgot
->output_section
->vma
3542 + sgot
->output_offset
3543 + (h
->got
.offset
&~ (bfd_vma
) 1));
3545 /* If this is a -Bsymbolic link, and the symbol is defined
3546 locally, we just want to emit a RELATIVE reloc. The entry in
3547 the global offset table will already have been initialized in
3548 the relocate_section function. */
3550 && (info
->symbolic
|| h
->dynindx
== -1)
3551 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
))
3553 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
3554 rela
.r_addend
= (h
->root
.u
.def
.value
3555 + h
->root
.u
.def
.section
->output_section
->vma
3556 + h
->root
.u
.def
.section
->output_offset
);
3560 BFD_ASSERT ((h
->got
.offset
& 1) == 0);
3561 bfd_put_64 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ h
->got
.offset
);
3562 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_PPC64_GLOB_DAT
);
3566 bfd_elf64_swap_reloca_out (output_bfd
, &rela
,
3567 ((Elf64_External_Rela
*) srela
->contents
3568 + srela
->reloc_count
));
3569 ++srela
->reloc_count
;
3572 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_COPY
) != 0)
3575 Elf_Internal_Rela rela
;
3577 /* This symbols needs a copy reloc. Set it up. */
3580 fprintf (stderr
, ", copy");
3583 BFD_ASSERT (h
->dynindx
!= -1);
3585 s
= bfd_get_section_by_name (h
->root
.u
.def
.section
->owner
,
3587 BFD_ASSERT (s
!= NULL
);
3589 rela
.r_offset
= (h
->root
.u
.def
.value
3590 + h
->root
.u
.def
.section
->output_section
->vma
3591 + h
->root
.u
.def
.section
->output_offset
);
3592 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_PPC64_COPY
);
3594 bfd_elf64_swap_reloca_out (output_bfd
, &rela
,
3595 ((Elf64_External_Rela
*) s
->contents
3601 fprintf (stderr
, "\n");
3604 /* Mark some specially defined symbols as absolute. */
3605 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0)
3606 sym
->st_shndx
= SHN_ABS
;
3611 /* Finish up the dynamic sections. */
3614 ppc64_elf_finish_dynamic_sections (output_bfd
, info
)
3616 struct bfd_link_info
*info
;
3619 bfd
*dynobj
= elf_hash_table (info
)->dynobj
;
3622 fprintf (stderr
, "ppc64_elf_finish_dynamic_sections called\n");
3625 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
3627 if (elf_hash_table (info
)->dynamic_sections_created
)
3630 Elf64_External_Dyn
*dyncon
, *dynconend
;
3632 splt
= bfd_get_section_by_name (dynobj
, ".plt");
3633 BFD_ASSERT (splt
!= NULL
&& sdyn
!= NULL
);
3635 dyncon
= (Elf64_External_Dyn
*) sdyn
->contents
;
3636 dynconend
= (Elf64_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
3637 for (; dyncon
< dynconend
; dyncon
++)
3639 Elf_Internal_Dyn dyn
;
3643 bfd_elf64_swap_dyn_in (dynobj
, dyncon
, &dyn
);
3647 case DT_PLTGOT
: name
= ".plt"; size
= false; break;
3648 case DT_PLTRELSZ
: name
= ".rela.plt"; size
= true; break;
3649 case DT_JMPREL
: name
= ".rela.plt"; size
= false; break;
3650 default: name
= NULL
; size
= false; break;
3657 s
= bfd_get_section_by_name (output_bfd
, name
);
3663 dyn
.d_un
.d_ptr
= s
->vma
;
3666 if (s
->_cooked_size
!= 0)
3667 dyn
.d_un
.d_val
= s
->_cooked_size
;
3669 dyn
.d_un
.d_val
= s
->_raw_size
;
3672 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
3681 Elf_Internal_Sym sym
;
3684 /* Set up the section symbols for the output sections. */
3686 sdynsym
= bfd_get_section_by_name (dynobj
, ".dynsym");
3687 BFD_ASSERT (sdynsym
!= NULL
);
3691 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_SECTION
);
3694 for (s
= output_bfd
->sections
; s
!= NULL
; s
= s
->next
)
3698 sym
.st_value
= s
->vma
;
3700 indx
= elf_section_data (s
)->this_idx
;
3701 dindx
= elf_section_data (s
)->dynindx
;
3704 BFD_ASSERT (indx
> 0);
3705 BFD_ASSERT (dindx
> 0);
3707 if (dindx
> maxdindx
)
3710 sym
.st_shndx
= indx
;
3712 bfd_elf64_swap_symbol_out (output_bfd
, &sym
,
3713 (PTR
) (((Elf64_External_Sym
*)
3719 /* Set the sh_info field of the output .dynsym section to the
3720 index of the first global symbol. */
3721 elf_section_data (sdynsym
->output_section
)->this_hdr
.sh_info
=
3728 #define TARGET_LITTLE_SYM bfd_elf64_powerpcle_vec
3729 #define TARGET_LITTLE_NAME "elf64-powerpcle"
3730 #define TARGET_BIG_SYM bfd_elf64_powerpc_vec
3731 #define TARGET_BIG_NAME "elf64-powerpc"
3732 #define ELF_ARCH bfd_arch_powerpc
3733 #define ELF_MACHINE_CODE EM_PPC64
3734 #define ELF_MAXPAGESIZE 0x10000
3735 #define elf_info_to_howto ppc64_elf_info_to_howto
3737 #ifdef EM_CYGNUS_POWERPC
3738 #define ELF_MACHINE_ALT1 EM_CYGNUS_POWERPC
3742 #define ELF_MACHINE_ALT2 EM_PPC_OLD
3745 #define elf_backend_want_got_sym 0
3746 #define elf_backend_want_plt_sym 0
3747 #define elf_backend_plt_alignment 3
3748 #define elf_backend_plt_not_loaded 1
3749 #define elf_backend_got_symbol_offset 0
3750 #define elf_backend_got_header_size 0
3751 #define elf_backend_can_gc_sections 1
3753 #define elf_backend_plt_header_size PLT_INITIAL_ENTRY_SIZE
3755 #define bfd_elf64_bfd_copy_private_bfd_data ppc64_elf_copy_private_bfd_data
3756 #define bfd_elf64_bfd_merge_private_bfd_data ppc64_elf_merge_private_bfd_data
3757 #define bfd_elf64_bfd_reloc_type_lookup ppc64_elf_reloc_type_lookup
3758 #define bfd_elf64_bfd_set_private_flags ppc64_elf_set_private_flags
3759 #define bfd_elf64_bfd_final_link ppc64_elf_final_link
3761 #define elf_backend_gc_mark_hook ppc64_elf_gc_mark_hook
3762 #define elf_backend_gc_sweep_hook ppc64_elf_gc_sweep_hook
3763 #define elf_backend_section_from_shdr ppc64_elf_section_from_shdr
3764 #define elf_backend_relocate_section ppc64_elf_relocate_section
3765 #define elf_backend_create_dynamic_sections ppc64_elf_create_dynamic_sections
3766 #define elf_backend_check_relocs ppc64_elf_check_relocs
3767 #define elf_backend_adjust_dynamic_symbol ppc64_elf_adjust_dynamic_symbol
3768 #define elf_backend_size_dynamic_sections ppc64_elf_size_dynamic_sections
3769 #define elf_backend_finish_dynamic_symbol ppc64_elf_finish_dynamic_symbol
3770 #define elf_backend_finish_dynamic_sections ppc64_elf_finish_dynamic_sections
3771 #define elf_backend_fake_sections ppc64_elf_fake_sections
3773 #include "elf64-target.h"