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
* sizeof (bfd_signed_vma
);
1730 local_got_refcounts
= (bfd_signed_vma
*)
1731 bfd_alloc (abfd
, size
);
1732 if (local_got_refcounts
== NULL
)
1734 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
1735 memset (local_got_refcounts
, -1, size
);
1737 if (local_got_refcounts
[r_symndx
] == -1)
1739 sgot
->_raw_size
+= 8;
1741 /* If we are generating a shared object, we need to
1742 output a R_PPC64_RELATIVE reloc so that the
1743 dynamic linker can adjust this GOT entry. */
1745 srelgot
->_raw_size
+= sizeof (Elf64_External_Rela
);
1747 local_got_refcounts
[r_symndx
] = 1;
1750 local_got_refcounts
[r_symndx
]++;
1756 case R_PPC64_PLT16_LO
:
1757 case R_PPC64_PLT16_HI
:
1758 case R_PPC64_PLT16_HA
:
1759 case R_PPC64_PLTGOT16_DS
:
1760 case R_PPC64_PLTGOT16_LO_DS
:
1762 fprintf (stderr
, "Reloc requires a PLT entry\n");
1764 /* This symbol requires a procedure linkage table entry. We
1765 actually build the entry in adjust_dynamic_symbol,
1766 because this might be a case of linking PIC code without
1767 linking in any dynamic objects, in which case we don't
1768 need to generate a procedure linkage table after all. */
1772 /* It does not make sense to have a procedure linkage
1773 table entry for a local symbol. */
1774 bfd_set_error (bfd_error_bad_value
);
1778 /* Make sure this symbol is output as a dynamic symbol. */
1779 if (h
->dynindx
== -1)
1781 if (! bfd_elf64_link_record_dynamic_symbol (info
, h
))
1784 if (h
->plt
.refcount
== -1)
1786 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
1787 h
->plt
.refcount
= 1;
1793 /* The following relocations don't need to propagate the
1794 relocation if linking a shared object since they are
1795 section relative. */
1796 case R_PPC64_SECTOFF
:
1797 case R_PPC64_SECTOFF_LO
:
1798 case R_PPC64_SECTOFF_HI
:
1799 case R_PPC64_SECTOFF_HA
:
1800 case R_PPC64_SECTOFF_DS
:
1801 case R_PPC64_SECTOFF_LO_DS
:
1803 case R_PPC64_TOC16_LO
:
1804 case R_PPC64_TOC16_HI
:
1805 case R_PPC64_TOC16_HA
:
1806 case R_PPC64_TOC16_DS
:
1807 case R_PPC64_TOC16_LO_DS
:
1810 /* This relocation describes the C++ object vtable hierarchy.
1811 Reconstruct it for later use during GC. */
1812 case R_PPC64_GNU_VTINHERIT
:
1813 if (!_bfd_elf64_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
1817 /* This relocation describes which C++ vtable entries are actually
1818 used. Record for later use during GC. */
1819 case R_PPC64_GNU_VTENTRY
:
1820 if (!_bfd_elf64_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
1824 /* When creating a shared object, we must copy these
1825 relocs into the output file. We create a reloc
1826 section in dynobj and make room for the reloc. */
1831 case R_PPC64_REL14_BRTAKEN
:
1832 case R_PPC64_REL14_BRNTAKEN
:
1844 fprintf (stderr
, "ppc64_elf_check_relocs need to create relocation for %s\n",
1845 (h
&& h
->root
.root
.string
1846 ? h
->root
.root
.string
1853 name
= (bfd_elf_string_from_elf_section
1855 elf_elfheader (abfd
)->e_shstrndx
,
1856 elf_section_data (sec
)->rel_hdr
.sh_name
));
1860 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
1861 && strcmp (bfd_get_section_name (abfd
, sec
),
1864 sreloc
= bfd_get_section_by_name (dynobj
, name
);
1869 sreloc
= bfd_make_section (dynobj
, name
);
1870 flags
= (SEC_HAS_CONTENTS
| SEC_READONLY
1871 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
1872 if ((sec
->flags
& SEC_ALLOC
) != 0)
1873 flags
|= SEC_ALLOC
| SEC_LOAD
;
1875 || ! bfd_set_section_flags (dynobj
, sreloc
, flags
)
1876 || ! bfd_set_section_alignment (dynobj
, sreloc
, 2))
1881 sreloc
->_raw_size
+= sizeof (Elf64_External_Rela
);
1883 /* FIXME: We should here do what the m68k and i386
1884 backends do: if the reloc is pc-relative, record it
1885 in case it turns out that the reloc is unnecessary
1886 because the symbol is forced local by versioning or
1887 we are linking with -Bdynamic. Fortunately this
1888 case is not frequent. */
1898 /* Return the section that should be marked against GC for a given
1902 ppc64_elf_gc_mark_hook (abfd
, info
, rel
, h
, sym
)
1904 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
1905 Elf_Internal_Rela
*rel
;
1906 struct elf_link_hash_entry
*h
;
1907 Elf_Internal_Sym
*sym
;
1911 switch (ELF64_R_TYPE (rel
->r_info
))
1913 case R_PPC64_GNU_VTINHERIT
:
1914 case R_PPC64_GNU_VTENTRY
:
1918 switch (h
->root
.type
)
1920 case bfd_link_hash_defined
:
1921 case bfd_link_hash_defweak
:
1922 return h
->root
.u
.def
.section
;
1924 case bfd_link_hash_common
:
1925 return h
->root
.u
.c
.p
->section
;
1934 if (! (elf_bad_symtab (abfd
)
1935 && ELF_ST_BIND (sym
->st_info
) != STB_LOCAL
)
1936 && ! ((sym
->st_shndx
<= 0 || sym
->st_shndx
>= SHN_LORESERVE
)
1937 && sym
->st_shndx
!= SHN_COMMON
))
1939 return bfd_section_from_elf_index (abfd
, sym
->st_shndx
);
1946 /* Update the got entry reference counts for the section being removed. */
1949 ppc64_elf_gc_sweep_hook (abfd
, info
, sec
, relocs
)
1951 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
1953 const Elf_Internal_Rela
*relocs
;
1955 Elf_Internal_Shdr
*symtab_hdr
;
1956 struct elf_link_hash_entry
**sym_hashes
;
1957 bfd_signed_vma
*local_got_refcounts
;
1958 const Elf_Internal_Rela
*rel
, *relend
;
1959 unsigned long r_symndx
;
1960 struct elf_link_hash_entry
*h
;
1962 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
1963 sym_hashes
= elf_sym_hashes (abfd
);
1964 local_got_refcounts
= elf_local_got_refcounts (abfd
);
1966 relend
= relocs
+ sec
->reloc_count
;
1967 for (rel
= relocs
; rel
< relend
; rel
++)
1968 switch (ELF64_R_TYPE (rel
->r_info
))
1971 case R_PPC64_GOT16_LO
:
1972 case R_PPC64_GOT16_HI
:
1973 case R_PPC64_GOT16_HA
:
1974 r_symndx
= ELF64_R_SYM (rel
->r_info
);
1975 if (r_symndx
>= symtab_hdr
->sh_info
)
1977 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1978 if (h
->got
.refcount
> 0)
1983 if (local_got_refcounts
[r_symndx
] > 0)
1984 local_got_refcounts
[r_symndx
]--;
1989 case R_PPC64_PLT16_LO
:
1990 case R_PPC64_PLT16_HI
:
1991 case R_PPC64_PLT16_HA
:
1992 r_symndx
= ELF64_R_SYM (rel
->r_info
);
1993 if (r_symndx
>= symtab_hdr
->sh_info
)
1995 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1996 if (h
->plt
.refcount
> 0)
2008 /* Adjust a symbol defined by a dynamic object and referenced by a
2009 regular object. The current definition is in some section of the
2010 dynamic object, but we're not including those sections. We have to
2011 change the definition to something the rest of the link can
2015 ppc64_elf_adjust_dynamic_symbol (info
, h
)
2016 struct bfd_link_info
*info
;
2017 struct elf_link_hash_entry
*h
;
2019 bfd
*dynobj
= elf_hash_table (info
)->dynobj
;
2021 unsigned int power_of_two
;
2025 fprintf (stderr
, "ppc64_elf_adjust_dynamic_symbol called for %s\n",
2026 h
->root
.root
.string
);
2029 /* Make sure we know what is going on here. */
2030 BFD_ASSERT (dynobj
!= NULL
2031 && ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
)
2032 || h
->weakdef
!= NULL
2033 || ((h
->elf_link_hash_flags
2034 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0
2035 && (h
->elf_link_hash_flags
2036 & ELF_LINK_HASH_REF_REGULAR
) != 0
2037 && (h
->elf_link_hash_flags
2038 & ELF_LINK_HASH_DEF_REGULAR
) == 0)));
2040 /* If this is a function, alter the symbol to refer to global
2041 linkage code, which will be generated by ppc64_elf_relocate_section.
2042 Also, allocate a slot in the PLT. */
2043 if (h
->type
== STT_FUNC
2044 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
2046 asection
*splt
, *sglink
;
2048 if (! elf_hash_table (info
)->dynamic_sections_created
2049 || ((!info
->shared
|| info
->symbolic
|| h
->dynindx
== -1)
2050 && (h
->elf_link_hash_flags
2051 & ELF_LINK_HASH_DEF_REGULAR
) != 0))
2053 /* A PLT entry is not required/allowed when:
2055 1. We are not using ld.so; because then the PLT entry
2056 can't be set up, so we can't use one.
2058 2. We know for certain that a symbol is defined in
2059 this object, because this object is the application,
2060 is linked with -Bsymbolic, or because the symbol is local.
2062 We used to end up here for GC if
2063 (info->shared && h->plt.refcount <= 0)
2064 We can't use plt.refcount here since
2065 ppc64_elf_check_relocs can't detect all needs for
2066 PLT. FIXME: Rewrite GC. */
2068 h
->plt
.offset
= (bfd_vma
) -1;
2069 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
2073 splt
= bfd_get_section_by_name (dynobj
, ".plt");
2074 sglink
= bfd_get_section_by_name (dynobj
, ".glink");
2075 BFD_ASSERT (splt
!= NULL
&& sglink
!= NULL
);
2077 /* If it's a function entry point (the name starts with a dot)
2078 (FIXME: Could it ever be anything else?), find its
2079 corresponding function descriptor symbol and make sure it's
2080 output as a dynamic symbol. Create it as undefined if
2081 necessary. ppc64_elf_finish_dynamic_symbol will look it up
2082 again and create a JMP_SLOT reloc for it. FIXME: The second
2083 lookup could be avoided by adding a new flag to
2084 elf_link_hash_entry->elf_link_hash_flags. */
2086 if (h
->root
.root
.string
[0] == '.')
2088 struct elf_link_hash_entry
*fdh
;
2090 /* FIXME: Follow bfd_link_hash_indirect? */
2091 fdh
= elf_link_hash_lookup (elf_hash_table (info
),
2092 h
->root
.root
.string
+ 1,
2093 false, false, false);
2095 if (fdh
== (struct elf_link_hash_entry
*) NULL
)
2099 /* Create it as undefined. */
2100 newsym
= bfd_make_empty_symbol (dynobj
);
2101 BFD_ASSERT (newsym
!= NULL
);
2102 /* FIXME: Need own copy of name? */
2103 newsym
->name
= h
->root
.root
.string
+ 1;
2104 newsym
->section
= bfd_und_section_ptr
;
2106 newsym
->flags
= BSF_DYNAMIC
| BSF_OBJECT
;
2108 if ( ! (_bfd_generic_link_add_one_symbol
2109 (info
, dynobj
, newsym
->name
, newsym
->flags
,
2110 newsym
->section
, newsym
->value
,
2114 (struct bfd_link_hash_entry
**) &fdh
)))
2116 /* FIXME: Print error message. */
2119 fdh
->root
.type
= bfd_link_hash_undefined
;
2121 fprintf (stderr
, "\tcreated %s", newsym
->name
);
2126 fprintf (stderr
, "\tfound %s", fdh
->root
.root
.string
);
2127 fprintf (stderr
, "\n");
2130 BFD_ASSERT (fdh
!= NULL
);
2132 /* Make sure it's output as a dynamic symbol. */
2133 if (fdh
->dynindx
== -1)
2135 if (! bfd_elf64_link_record_dynamic_symbol (info
, fdh
))
2138 BFD_ASSERT (fdh
->dynindx
!= -1);
2141 /* If this is the first .plt entry, make room for the special
2143 if (splt
->_raw_size
== 0)
2144 splt
->_raw_size
= PLT_INITIAL_ENTRY_SIZE
;
2146 plt_offset
= splt
->_raw_size
;
2148 /* FIXME: What about function pointer comparisons in 64-bit PPC?
2149 We can't use the same trick as 32-bit PPC, since we set the
2150 symbol to the linkage function. This will make function entry
2151 point comparison work as expected within one object, but not
2152 across object boundaries. From the ABI:
2154 In this ABI, the address of a function is actually the address of a
2155 function descriptor. A reference to a function, other than a function
2156 call, will normally load the address of the function descriptor from
2157 the global offset table. The dynamic linker will ensure that for a
2158 given function, the same address is used for all references to the
2159 function from any global offset table. Thus, function address
2160 comparisons will work as expected.
2162 When making a call to the function, the code may refer to the
2163 procedure linkage table entry, in order to permit lazy symbol
2164 resolution at run time. In order to support correct function address
2165 comparisons, the compiler should be careful to only generate
2166 references to the procedure linkage table entry for function calls.
2167 For any other use of a function, the compiler should use the real
2170 I don't see how this could ever work when passing a pointer to
2171 a function across an object boundary. The compiler has no
2172 way of knowing how to find the function descriptor for a
2173 function whose entrypoint is taken as an argument.
2175 Or should the compiler arrange so that the function descriptor
2176 address is passed and make the callee dig out the entry point
2179 /* If this symbol is not defined in a regular file, and we are
2180 not generating a shared library, then set the symbol to this
2181 location in the .plt. This is required to make function
2182 pointers compare as equal between the normal executable and
2183 the shared library. */
2185 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
2187 h
->root
.u
.def
.section
= splt
;
2188 h
->root
.u
.def
.value
= plt_offset
;
2192 /* FIXME: How should a linkage symbol be defined? It shouldn't
2193 be global, since it can't be used by any other object than
2194 this one. Set ELF_LINK_FORCED_LOCAL? */
2195 h
->root
.type
= bfd_link_hash_defined
;
2196 h
->root
.u
.def
.section
= sglink
;
2197 h
->root
.u
.def
.value
= sglink
->_raw_size
;
2198 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
2199 h
->plt
.offset
= plt_offset
;
2201 /* Make room for global linkage code in .glink. */
2202 sglink
->_raw_size
+= PPC64_ELF_GLINK_SIZE
;
2204 /* Make room for this entry in PLT. */
2205 splt
->_raw_size
+= PLT_ENTRY_SIZE
;
2207 /* We also need to make an entry in the .rela.plt section. */
2208 s
= bfd_get_section_by_name (dynobj
, ".rela.plt");
2209 BFD_ASSERT (s
!= NULL
);
2210 s
->_raw_size
+= sizeof (Elf64_External_Rela
);
2215 /* If this is a weak symbol, and there is a real definition, the
2216 processor independent code will have arranged for us to see the
2217 real definition first, and we can just use the same value. */
2218 if (h
->weakdef
!= NULL
)
2220 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
2221 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
2222 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
2223 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
2227 /* This is a reference to a symbol defined by a dynamic object which
2228 is not a function. */
2230 /* If we are creating a shared library, we must presume that the
2231 only references to the symbol are via the global offset table.
2232 For such cases we need not do anything here; the relocations will
2233 be handled correctly by relocate_section. */
2237 /* We must allocate the symbol in our .dynbss section, which will
2238 become part of the .bss section of the executable. There will be
2239 an entry for this symbol in the .dynsym section. The dynamic
2240 object will contain position independent code, so all references
2241 from the dynamic object to this symbol will go through the global
2242 offset table. The dynamic linker will use the .dynsym entry to
2243 determine the address it must put in the global offset table, so
2244 both the dynamic object and the regular object will refer to the
2245 same memory location for the variable. */
2246 s
= bfd_get_section_by_name (dynobj
, ".dynbss");
2247 BFD_ASSERT (s
!= NULL
);
2249 /* We must generate a R_PPC_COPY reloc to tell the dynamic linker to
2250 copy the initial value out of the dynamic object and into the
2251 runtime process image. We need to remember the offset into the
2252 .rela.bss section we are going to use. */
2253 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
2257 srel
= bfd_get_section_by_name (dynobj
, ".rela.bss");
2258 BFD_ASSERT (srel
!= NULL
);
2259 srel
->_raw_size
+= sizeof (Elf64_External_Rela
);
2260 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_COPY
;
2263 /* We need to figure out the alignment required for this symbol. I
2264 have no idea how ELF linkers handle this. */
2265 power_of_two
= bfd_log2 (h
->size
);
2266 if (power_of_two
> 4)
2269 /* Apply the required alignment. */
2270 s
->_raw_size
= BFD_ALIGN (s
->_raw_size
,
2271 (bfd_size_type
) (1 << power_of_two
));
2272 if (power_of_two
> bfd_get_section_alignment (dynobj
, s
))
2274 if (! bfd_set_section_alignment (dynobj
, s
, power_of_two
))
2278 /* Define the symbol as being at this point in the section. */
2279 h
->root
.u
.def
.section
= s
;
2280 h
->root
.u
.def
.value
= s
->_raw_size
;
2282 /* Increment the section size to make room for the symbol. */
2283 s
->_raw_size
+= h
->size
;
2288 /* Increment the index of a dynamic symbol by a given amount. Called
2289 via elf_link_hash_traverse. */
2292 ppc_adjust_dynindx (h
, cparg
)
2293 struct elf_link_hash_entry
*h
;
2296 int *cp
= (int *) cparg
;
2300 "ppc_adjust_dynindx: h->dynindx = %ld, *cp = %d (%s)\n",
2302 h
->root
.root
.string
? h
->root
.root
.string
: "<unknown>");
2305 if (h
->dynindx
!= -1)
2311 /* Set the sizes of the dynamic sections. */
2314 ppc64_elf_size_dynamic_sections (output_bfd
, info
)
2316 struct bfd_link_info
*info
;
2325 fprintf (stderr
, "ppc64_elf_size_dynamic_sections called\n");
2328 dynobj
= elf_hash_table (info
)->dynobj
;
2329 BFD_ASSERT (dynobj
!= NULL
);
2331 if (elf_hash_table (info
)->dynamic_sections_created
)
2333 /* Set the contents of the .interp section to the interpreter. */
2336 s
= bfd_get_section_by_name (dynobj
, ".interp");
2337 BFD_ASSERT (s
!= NULL
);
2338 s
->_raw_size
= sizeof ELF_DYNAMIC_INTERPRETER
;
2339 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
2344 /* We may have created entries in the .rela.got section.
2345 However, if we are not creating the dynamic sections, we will
2346 not actually use these entries. Reset the size of .rela.got
2347 which will cause it to get stripped from the output file
2349 s
= bfd_get_section_by_name (dynobj
, ".rela.got");
2354 /* The check_relocs and adjust_dynamic_symbol entry points have
2355 determined the sizes of the various dynamic sections. Allocate
2360 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
2365 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
2368 /* It's OK to base decisions on the section name, because none
2369 of the dynobj section names depend upon the input files. */
2370 name
= bfd_get_section_name (dynobj
, s
);
2374 if (strcmp (name
, ".plt") == 0)
2376 if (s
->_raw_size
== 0)
2378 /* Strip this section if we don't need it; see the
2384 /* Remember whether there is a PLT. */
2388 else if (strncmp (name
, ".rela", 5) == 0)
2390 if (s
->_raw_size
== 0)
2392 /* If we don't need this section, strip it from the
2393 output file. This is mostly to handle .rela.bss and
2394 .rela.plt. We must create both sections in
2395 create_dynamic_sections, because they must be created
2396 before the linker maps input sections to output
2397 sections. The linker does that before
2398 adjust_dynamic_symbol is called, and it is that
2399 function which decides whether anything needs to go
2400 into these sections. */
2406 const char *outname
;
2408 /* Remember whether there are any relocation sections. */
2411 /* If this relocation section applies to a read only
2412 section, then we probably need a DT_TEXTREL entry. */
2413 outname
= bfd_get_section_name (output_bfd
,
2415 target
= bfd_get_section_by_name (output_bfd
, outname
+ 5);
2417 && (target
->flags
& SEC_READONLY
) != 0
2418 && (target
->flags
& SEC_ALLOC
) != 0)
2421 /* We use the reloc_count field as a counter if we need
2422 to copy relocs into the output file. */
2426 else if (strcmp (name
, ".got") != 0
2427 && strcmp (name
, ".toc") != 0
2428 && strcmp (name
, ".glink") != 0)
2430 /* It's not one of our sections, so don't allocate space. */
2436 _bfd_strip_section_from_output (info
, s
);
2441 fprintf (stderr
, "\tallocating %lu bytes for section %s\n",
2442 (unsigned long) s
->_raw_size
, name
);
2445 /* Allocate memory for the section contents. */
2446 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->_raw_size
);
2447 if (s
->contents
== NULL
&& s
->_raw_size
!= 0)
2451 if (elf_hash_table (info
)->dynamic_sections_created
)
2453 /* Add some entries to the .dynamic section. We fill in the
2454 values later, in ppc64_elf_finish_dynamic_sections, but we
2455 must add the entries now so that we get the correct size for
2456 the .dynamic section. The DT_DEBUG entry is filled in by the
2457 dynamic linker and used by the debugger. */
2460 if (! bfd_elf64_add_dynamic_entry (info
, DT_DEBUG
, 0))
2466 if (! bfd_elf64_add_dynamic_entry (info
, DT_PLTGOT
, 0)
2467 || ! bfd_elf64_add_dynamic_entry (info
, DT_PLTRELSZ
, 0)
2468 || ! bfd_elf64_add_dynamic_entry (info
, DT_PLTREL
, DT_RELA
)
2469 || ! bfd_elf64_add_dynamic_entry (info
, DT_JMPREL
, 0))
2475 if (! bfd_elf64_add_dynamic_entry (info
, DT_RELA
, 0)
2476 || ! bfd_elf64_add_dynamic_entry (info
, DT_RELASZ
, 0)
2477 || ! bfd_elf64_add_dynamic_entry (info
, DT_RELAENT
,
2478 sizeof (Elf64_External_Rela
)))
2484 if (! bfd_elf64_add_dynamic_entry (info
, DT_TEXTREL
, 0))
2489 /* If we are generating a shared library, we generate a section
2490 symbol for each output section. These are local symbols, which
2491 means that they must come first in the dynamic symbol table.
2492 That means we must increment the dynamic symbol index of every
2493 other dynamic symbol.
2495 FIXME: We assume that there will never be relocations to
2496 locations in linker-created sections that do not have
2497 externally-visible names. Instead, we should work out precisely
2498 which sections relocations are targetted at. */
2503 for (c
= 0, s
= output_bfd
->sections
; s
!= NULL
; s
= s
->next
)
2505 if ((s
->flags
& SEC_LINKER_CREATED
) != 0
2506 || (s
->flags
& SEC_ALLOC
) == 0)
2508 elf_section_data (s
)->dynindx
= -1;
2512 /* These symbols will have no names, so we don't need to
2513 fiddle with dynstr_index. */
2515 elf_section_data (s
)->dynindx
= c
+ 1;
2520 elf_link_hash_traverse (elf_hash_table (info
),
2523 elf_hash_table (info
)->dynsymcount
+= c
;
2529 /* Called after we have seen all the input files/sections, but before
2530 final symbol resolution and section placement has been determined.
2532 We use this hook to provide a value for TOCstart, which we store in
2533 the output bfd elf_gp, then we call the generic ELF final link
2537 ppc64_elf_final_link (abfd
, info
)
2539 struct bfd_link_info
*info
;
2541 if (! info
->relocateable
)
2546 /* The TOC consists of sections .got, .toc, .tocbss, .plt in this
2547 order. The TOC starts where the first of these sections starts. */
2548 s
= bfd_get_section_by_name (abfd
, ".got");
2550 s
= bfd_get_section_by_name (abfd
, ".toc");
2552 s
= bfd_get_section_by_name (abfd
, ".tocbss");
2554 s
= bfd_get_section_by_name (abfd
, ".plt");
2557 /* This may happen for
2558 o references to TOC base (SYM@toc / TOC[tc0]) without a
2561 o --gc-sections and empty TOC sections
2563 FIXME: Warn user? */
2565 /* Look for a likely section. We probably won't even be
2567 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
2568 if ((s
->flags
& (SEC_ALLOC
| SEC_SMALL_DATA
| SEC_READONLY
))
2569 == (SEC_ALLOC
| SEC_SMALL_DATA
))
2572 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
2573 if ((s
->flags
& (SEC_ALLOC
| SEC_SMALL_DATA
))
2574 == (SEC_ALLOC
| SEC_SMALL_DATA
))
2577 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
2578 if ((s
->flags
& (SEC_ALLOC
| SEC_READONLY
)) == SEC_ALLOC
)
2581 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
2582 if ((s
->flags
& SEC_ALLOC
) == SEC_ALLOC
)
2588 TOCstart
= s
->output_section
->vma
+ s
->output_offset
;
2590 elf_gp (abfd
) = TOCstart
;
2593 /* Invoke the regular gc ELF backend linker to do all the work. */
2594 return _bfd_elf64_gc_common_final_link (abfd
, info
);
2597 /* Set up any other section flags and such that may be necessary. */
2600 ppc64_elf_fake_sections (abfd
, shdr
, asect
)
2601 bfd
*abfd ATTRIBUTE_UNUSED
;
2602 Elf64_Internal_Shdr
*shdr
;
2605 if ((asect
->flags
& SEC_EXCLUDE
) != 0)
2606 shdr
->sh_flags
|= SHF_EXCLUDE
;
2608 if ((asect
->flags
& SEC_SORT_ENTRIES
) != 0)
2609 shdr
->sh_type
= SHT_ORDERED
;
2614 /* The RELOCATE_SECTION function is called by the ELF backend linker
2615 to handle the relocations for a section.
2617 The relocs are always passed as Rela structures; if the section
2618 actually uses Rel structures, the r_addend field will always be
2621 This function is responsible for adjust the section contents as
2622 necessary, and (if using Rela relocs and generating a
2623 relocateable output file) adjusting the reloc addend as
2626 This function does not have to worry about setting the reloc
2627 address or the reloc symbol index.
2629 LOCAL_SYMS is a pointer to the swapped in local symbols.
2631 LOCAL_SECTIONS is an array giving the section in the input file
2632 corresponding to the st_shndx field of each local symbol.
2634 The global hash table entry for the global symbols can be found
2635 via elf_sym_hashes (input_bfd).
2637 When generating relocateable output, this function must handle
2638 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
2639 going to be the section symbol corresponding to the output
2640 section, which means that the addend must be adjusted
2644 ppc64_elf_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
2645 contents
, relocs
, local_syms
, local_sections
)
2647 struct bfd_link_info
*info
;
2649 asection
*input_section
;
2651 Elf_Internal_Rela
*relocs
;
2652 Elf_Internal_Sym
*local_syms
;
2653 asection
**local_sections
;
2655 Elf_Internal_Shdr
*symtab_hdr
;
2656 struct elf_link_hash_entry
**sym_hashes
;
2658 Elf_Internal_Rela
*rel
;
2659 Elf_Internal_Rela
*relend
;
2663 bfd_vma
*local_got_offsets
;
2669 fprintf (stderr
, "ppc64_elf_relocate_section called for %s section %s, %ld relocations%s\n",
2670 bfd_get_filename (input_bfd
),
2671 bfd_section_name (input_bfd
, input_section
),
2672 (long) input_section
->reloc_count
,
2673 (info
->relocateable
) ? " (relocatable)" : "");
2676 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
2677 /* Initialize howto table if needed. */
2680 local_got_offsets
= elf_local_got_offsets (input_bfd
);
2685 dynobj
= elf_hash_table (info
)->dynobj
;
2688 splt
= bfd_get_section_by_name (dynobj
, ".plt");
2689 sgot
= bfd_get_section_by_name (dynobj
, ".got");
2691 TOCstart
= elf_gp (output_bfd
);
2693 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
2694 sym_hashes
= elf_sym_hashes (input_bfd
);
2696 relend
= relocs
+ input_section
->reloc_count
;
2697 for (; rel
< relend
; rel
++)
2699 enum elf_ppc_reloc_type r_type
;
2702 bfd_reloc_status_type r
;
2703 Elf_Internal_Sym
*sym
;
2705 struct elf_link_hash_entry
*h
;
2706 const char *sym_name
;
2707 reloc_howto_type
*howto
;
2708 unsigned long r_symndx
;
2711 r_type
= (enum elf_ppc_reloc_type
) ELF64_R_TYPE (rel
->r_info
);
2712 offset
= rel
->r_offset
;
2713 addend
= rel
->r_addend
;
2714 r
= bfd_reloc_other
;
2715 sym
= (Elf_Internal_Sym
*) 0;
2716 sec
= (asection
*) 0;
2717 h
= (struct elf_link_hash_entry
*) 0;
2718 sym_name
= (const char *) 0;
2720 /* Unknown relocation handling. */
2721 if ((unsigned) r_type
>= (unsigned) R_PPC_max
2722 || !ppc64_elf_howto_table
[(int) r_type
])
2724 (*_bfd_error_handler
) (_("%s: unknown relocation type %d"),
2725 bfd_get_filename (input_bfd
),
2727 bfd_set_error (bfd_error_bad_value
);
2732 howto
= ppc64_elf_howto_table
[(int) r_type
];
2733 r_symndx
= ELF64_R_SYM (rel
->r_info
);
2735 if (info
->relocateable
)
2737 /* This is a relocatable link. We don't have to change
2738 anything, unless the reloc is against a section symbol,
2739 in which case we have to adjust according to where the
2740 section symbol winds up in the output section. */
2741 if (r_symndx
< symtab_hdr
->sh_info
)
2743 sym
= local_syms
+ r_symndx
;
2744 if ((unsigned) ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
2746 sec
= local_sections
[r_symndx
];
2747 addend
= rel
->r_addend
+= sec
->output_offset
+ sym
->st_value
;
2752 fprintf (stderr
, "\ttype = %s (%d), symbol index = %ld, offset = %ld, addend = %ld\n",
2762 /* This is a final link. */
2764 /* Set `relocation'. */
2765 if (r_type
== R_PPC64_TOC
)
2767 /* Relocation value is TOC base. Symbol is ignored. */
2768 relocation
= TOCstart
+ TOC_BASE_OFF
;
2770 else if (r_symndx
< symtab_hdr
->sh_info
)
2772 /* It's a local symbol. */
2773 sym
= local_syms
+ r_symndx
;
2774 sec
= local_sections
[r_symndx
];
2775 sym_name
= "<local symbol>";
2777 relocation
= (sec
->output_section
->vma
2778 + sec
->output_offset
2783 /* It's a global symbol. */
2784 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2785 while (h
->root
.type
== bfd_link_hash_indirect
2786 || h
->root
.type
== bfd_link_hash_warning
)
2787 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2788 sym_name
= h
->root
.root
.string
;
2789 if (h
->root
.type
== bfd_link_hash_defined
2790 || h
->root
.type
== bfd_link_hash_defweak
)
2792 sec
= h
->root
.u
.def
.section
;
2793 if ((r_type
== R_PPC64_PLT32
2794 && h
->plt
.offset
!= (bfd_vma
) -1)
2795 || ((r_type
== R_PPC64_GOT16
2796 || r_type
== R_PPC64_GOT16_LO
2797 || r_type
== R_PPC64_GOT16_HI
2798 || r_type
== R_PPC64_GOT16_HA
2799 || r_type
== R_PPC64_GOT16_DS
2800 || r_type
== R_PPC64_GOT16_LO_DS
)
2801 && elf_hash_table (info
)->dynamic_sections_created
2803 || (! info
->symbolic
&& h
->dynindx
!= -1)
2804 || (h
->elf_link_hash_flags
2805 & ELF_LINK_HASH_DEF_REGULAR
) == 0))
2807 && ((! info
->symbolic
&& h
->dynindx
!= -1)
2808 || (h
->elf_link_hash_flags
2809 & ELF_LINK_HASH_DEF_REGULAR
) == 0)
2810 && (input_section
->flags
& SEC_ALLOC
) != 0
2811 && (r_type
== R_PPC64_ADDR64
2812 || r_type
== R_PPC64_ADDR32
2813 || r_type
== R_PPC64_ADDR24
2814 || r_type
== R_PPC64_ADDR16
2815 || r_type
== R_PPC64_ADDR16_LO
2816 || r_type
== R_PPC64_ADDR16_DS
2817 || r_type
== R_PPC64_ADDR16_LO_DS
2818 || r_type
== R_PPC64_ADDR16_HI
2819 || r_type
== R_PPC64_ADDR16_HA
2820 || r_type
== R_PPC64_ADDR16_HIGHER
2821 || r_type
== R_PPC64_ADDR16_HIGHERA
2822 || r_type
== R_PPC64_ADDR16_HIGHEST
2823 || r_type
== R_PPC64_ADDR16_HIGHESTA
2824 || r_type
== R_PPC64_ADDR14
2825 || r_type
== R_PPC64_ADDR14_BRTAKEN
2826 || r_type
== R_PPC64_ADDR14_BRNTAKEN
2827 || r_type
== R_PPC64_COPY
2828 || r_type
== R_PPC64_GLOB_DAT
2829 || r_type
== R_PPC64_JMP_SLOT
2830 || r_type
== R_PPC64_UADDR64
2831 || r_type
== R_PPC64_UADDR32
2832 || r_type
== R_PPC64_UADDR16
)))
2834 /* In these cases, we don't need the relocation
2835 value. We check specially because in some
2836 obscure cases sec->output_section will be NULL. */
2840 relocation
= (h
->root
.u
.def
.value
2841 + sec
->output_section
->vma
2842 + sec
->output_offset
);
2844 else if (h
->root
.type
== bfd_link_hash_undefweak
)
2846 else if (info
->shared
&& !info
->symbolic
&& !info
->no_undefined
)
2850 if (! ((*info
->callbacks
->undefined_symbol
)
2851 (info
, h
->root
.root
.string
, input_bfd
, input_section
,
2852 rel
->r_offset
, (!info
->shared
2853 || info
->no_undefined
2854 || ELF_ST_VISIBILITY (h
->other
)))))
2860 switch ((int) r_type
)
2862 case (int) R_PPC64_ADDR16_DS
:
2863 case (int) R_PPC64_ADDR16_LO_DS
:
2864 case (int) R_PPC64_GOT16_DS
:
2865 case (int) R_PPC64_GOT16_LO_DS
:
2866 case (int) R_PPC64_PLT16_LO_DS
:
2867 case (int) R_PPC64_SECTOFF_DS
:
2868 case (int) R_PPC64_SECTOFF_LO_DS
:
2869 case (int) R_PPC64_TOC16_DS
:
2870 case (int) R_PPC64_TOC16_LO_DS
:
2871 case (int) R_PPC64_PLTGOT16_DS
:
2872 case (int) R_PPC64_PLTGOT16_LO_DS
:
2873 if (((relocation
+ addend
) & 3) != 0)
2875 (*_bfd_error_handler
) (_("%s: error: relocation %s not a multiple of 4"),
2876 bfd_get_filename (input_bfd
),
2878 bfd_set_error (bfd_error_bad_value
);
2885 switch ((int) r_type
)
2888 (*_bfd_error_handler
) (_("%s: unknown relocation type %d for symbol %s"),
2889 bfd_get_filename (input_bfd
),
2890 (int) r_type
, sym_name
);
2892 bfd_set_error (bfd_error_bad_value
);
2896 /* Relocations that may need to be propagated if this is a shared
2898 case (int) R_PPC64_REL24
:
2899 case (int) R_PPC64_ADDR24
:
2900 /* An ADDR24 or REL24 branching to a linkage function may be
2901 followed by a nop that we have to replace with an ld in
2902 order to restore the TOC base pointer. Only calls to
2903 shared objects need to alter the TOC base. These are
2904 recognized by their need for a PLT entry. */
2906 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0
2907 /* Make sure that there really is an instruction after
2908 the branch that we can decode. */
2909 && (rel
->r_offset
- input_section
->vma
+ 8
2910 <= input_section
->_cooked_size
))
2915 pnext
= contents
+ (rel
->r_offset
- input_section
->vma
) + 4;
2916 insn
= bfd_get_32 (input_bfd
, pnext
);
2918 if (insn
== 0x60000000 /* nop (ori r0,r0,0) */
2919 || insn
== 0x4def7b82 /* cror 15,15,15 */
2920 || insn
== 0x4ffffb82) /* cror 31,31,31 */
2922 bfd_put_32 (input_bfd
, 0xe8410028, pnext
); /* ld r2,40(r1) */
2924 fprintf (stderr
, "ppc64_elf_relocate_section: " \
2925 "patched nop after call to %s\n", sym_name
);
2931 case (int) R_PPC64_REL64
:
2932 case (int) R_PPC64_REL32
:
2933 case (int) R_PPC64_REL14
:
2934 /* If these relocations are not to a named symbol, they can be
2935 handled right here, no need to bother the dynamic linker. */
2936 if (h
== NULL
&& r_type
!= R_PPC64_ADDR24
)
2940 /* Relocations that always need to be propagated if this is a shared
2942 case (int) R_PPC64_NONE
:
2943 case (int) R_PPC64_ADDR64
:
2944 case (int) R_PPC64_ADDR32
:
2945 case (int) R_PPC64_ADDR16
:
2946 case (int) R_PPC64_ADDR16_LO
:
2947 case (int) R_PPC64_ADDR16_DS
:
2948 case (int) R_PPC64_ADDR16_LO_DS
:
2949 case (int) R_PPC64_ADDR16_HI
:
2950 case (int) R_PPC64_ADDR16_HA
:
2951 case (int) R_PPC64_ADDR16_HIGHER
:
2952 case (int) R_PPC64_ADDR16_HIGHERA
:
2953 case (int) R_PPC64_ADDR16_HIGHEST
:
2954 case (int) R_PPC64_ADDR16_HIGHESTA
:
2955 case (int) R_PPC64_ADDR14
:
2956 case (int) R_PPC64_UADDR64
:
2957 case (int) R_PPC64_UADDR32
:
2958 case (int) R_PPC64_UADDR16
:
2959 case (int) R_PPC64_TOC
:
2962 Elf_Internal_Rela outrel
;
2966 fprintf (stderr
, "ppc64_elf_relocate_section need to create relocation for %s\n",
2967 (h
&& h
->root
.root
.string
2968 ? h
->root
.root
.string
2972 /* When generating a shared object, these relocations
2973 are copied into the output file to be resolved at run
2980 name
= (bfd_elf_string_from_elf_section
2982 elf_elfheader (input_bfd
)->e_shstrndx
,
2983 elf_section_data (input_section
)->rel_hdr
.sh_name
));
2987 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
2988 && strcmp (bfd_get_section_name (input_bfd
,
2992 sreloc
= bfd_get_section_by_name (dynobj
, name
);
2993 BFD_ASSERT (sreloc
!= NULL
);
2998 if (elf_section_data (input_section
)->stab_info
== NULL
)
2999 outrel
.r_offset
= rel
->r_offset
;
3004 off
= (_bfd_stab_section_offset
3005 (output_bfd
, &elf_hash_table (info
)->stab_info
,
3007 &elf_section_data (input_section
)->stab_info
,
3009 if (off
== (bfd_vma
) -1)
3011 outrel
.r_offset
= off
;
3014 outrel
.r_offset
+= (input_section
->output_section
->vma
3015 + input_section
->output_offset
);
3018 memset (&outrel
, 0, sizeof outrel
);
3019 /* h->dynindx may be -1 if this symbol was marked to
3022 && ((! info
->symbolic
&& h
->dynindx
!= -1)
3023 || (h
->elf_link_hash_flags
3024 & ELF_LINK_HASH_DEF_REGULAR
) == 0))
3026 BFD_ASSERT (h
->dynindx
!= -1);
3027 outrel
.r_info
= ELF64_R_INFO (h
->dynindx
, r_type
);
3028 outrel
.r_addend
= rel
->r_addend
;
3032 if (r_type
== R_PPC64_ADDR64
)
3034 outrel
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
3035 outrel
.r_addend
= relocation
+ rel
->r_addend
;
3042 sec
= local_sections
[r_symndx
];
3045 BFD_ASSERT (h
->root
.type
== bfd_link_hash_defined
3047 == bfd_link_hash_defweak
));
3048 sec
= h
->root
.u
.def
.section
;
3051 if (r_type
== R_PPC64_TOC
3052 || (sec
!= NULL
&& bfd_is_abs_section (sec
)))
3056 else if (sec
== NULL
|| sec
->owner
== NULL
)
3058 bfd_set_error (bfd_error_bad_value
);
3065 osec
= sec
->output_section
;
3066 indx
= elf_section_data (osec
)->dynindx
;
3067 BFD_ASSERT (indx
> 0);
3071 printf ("indx=%ld section=%s flags=%08x name=%s\n",
3072 indx
, osec
->name
, osec
->flags
,
3073 h
->root
.root
.string
);
3078 outrel
.r_info
= ELF64_R_INFO (indx
, r_type
);
3079 outrel
.r_addend
= relocation
+ rel
->r_addend
;
3083 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
,
3084 (((Elf64_External_Rela
*)
3086 + sreloc
->reloc_count
));
3087 ++sreloc
->reloc_count
;
3089 /* This reloc will be computed at runtime, so there's no
3090 need to do anything now, unless this is a RELATIVE
3091 reloc in an unallocated section. */
3093 || (input_section
->flags
& SEC_ALLOC
) != 0
3094 || ELF64_R_TYPE (outrel
.r_info
) != R_PPC64_RELATIVE
)
3098 /* Arithmetic adjust relocations that aren't going into a
3100 if ((r_type
== R_PPC64_ADDR16_HA
3101 || r_type
== R_PPC64_ADDR16_HIGHERA
3102 || r_type
== R_PPC64_ADDR16_HIGHESTA
)
3103 /* It's just possible that this symbol is a weak symbol
3104 that's not actually defined anywhere. In that case,
3105 'sec' would be NULL, and we should leave the symbol
3106 alone (it will be set to zero elsewhere in the link). */
3109 addend
+= ((relocation
+ addend
) & 0x8000) << 1;
3113 /* Branch taken prediction relocations. */
3114 case (int) R_PPC64_ADDR14_BRTAKEN
:
3115 case (int) R_PPC64_REL14_BRTAKEN
:
3116 insn
= bfd_get_32 (output_bfd
, contents
+ offset
);
3117 if ((relocation
- offset
) & 0x8000)
3118 insn
&= ~BRANCH_PREDICT_BIT
;
3120 insn
|= BRANCH_PREDICT_BIT
;
3121 bfd_put_32 (output_bfd
, insn
, contents
+ offset
);
3124 /* Branch not taken predicition relocations. */
3125 case (int) R_PPC64_ADDR14_BRNTAKEN
:
3126 case (int) R_PPC64_REL14_BRNTAKEN
:
3127 insn
= bfd_get_32 (output_bfd
, contents
+ offset
);
3128 if ((relocation
- offset
) & 0x8000)
3129 insn
|= BRANCH_PREDICT_BIT
;
3131 insn
&= ~BRANCH_PREDICT_BIT
;
3132 bfd_put_32 (output_bfd
, insn
, contents
+ offset
);
3136 /* GOT16 relocations. Like an ADDR16 using the symbol's
3137 address in the GOT as relocation value instead of the
3138 symbols value itself. Also, create a GOT entry for the
3139 symbol and put the symbol value there. */
3140 /* FIXME: If the symbol is not in the .got section
3141 (typically in the .toc section) we fail (h->got.offset is
3143 /* NOTE: Sets `relocation'. */
3144 case (int) R_PPC64_GOT16
:
3145 case (int) R_PPC64_GOT16_LO
:
3146 case (int) R_PPC64_GOT16_HI
:
3147 case (int) R_PPC64_GOT16_HA
:
3148 case (int) R_PPC64_GOT16_DS
:
3149 case (int) R_PPC64_GOT16_LO_DS
:
3151 /* Relocation is to the entry for this symbol in the global
3154 BFD_ASSERT (sgot
!= NULL
);
3158 off
= h
->got
.offset
;
3159 BFD_ASSERT (off
!= (bfd_vma
) -1);
3161 if (! elf_hash_table (info
)->dynamic_sections_created
3163 && (info
->symbolic
|| h
->dynindx
== -1)
3164 && (h
->elf_link_hash_flags
3165 & ELF_LINK_HASH_DEF_REGULAR
)))
3167 /* This is actually a static link, or it is a
3168 -Bsymbolic link and the symbol is defined
3169 locally. We must initialize this entry in the
3170 global offset table. Since the offset must
3171 always be a multiple of 4, we use the least
3172 significant bit to record whether we have
3173 initialized it already.
3175 When doing a dynamic link, we create a .rela.got
3176 relocation entry to initialize the value. This
3177 is done in the finish_dynamic_symbol routine. */
3182 bfd_put_64 (output_bfd
, relocation
,
3183 sgot
->contents
+ off
);
3190 BFD_ASSERT (local_got_offsets
!= NULL
3191 && local_got_offsets
[r_symndx
] != (bfd_vma
) -1);
3193 off
= local_got_offsets
[r_symndx
];
3195 /* The offset must always be a multiple of 4. We use
3196 the least significant bit to record whether we have
3197 already processed this entry. */
3202 bfd_put_64 (output_bfd
, relocation
, sgot
->contents
+ off
);
3207 Elf_Internal_Rela outrel
;
3209 /* We need to generate a R_PPC64_RELATIVE reloc
3210 for the dynamic linker. */
3211 srelgot
= bfd_get_section_by_name (dynobj
, ".rela.got");
3212 BFD_ASSERT (srelgot
!= NULL
);
3214 outrel
.r_offset
= (sgot
->output_section
->vma
3215 + sgot
->output_offset
3217 outrel
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
3218 outrel
.r_addend
= relocation
;
3219 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
,
3220 (((Elf64_External_Rela
*)
3222 + srelgot
->reloc_count
));
3223 ++srelgot
->reloc_count
;
3226 local_got_offsets
[r_symndx
] |= 1;
3230 relocation
= sgot
->output_offset
+ off
;
3231 /* TOC base (r2) is TOC start plus 0x8000. */
3232 addend
-= TOC_BASE_OFF
;
3236 /* TOC16 relocs. We want the offset relative to the TOC base,
3237 which is the address of the start of the TOC plus 0x8000.
3238 The TOC consists of sections .got, .toc, .tocbss, and .plt,
3241 case (int) R_PPC64_TOC16
:
3242 case (int) R_PPC64_TOC16_LO
:
3243 case (int) R_PPC64_TOC16_HI
:
3244 case (int) R_PPC64_TOC16_DS
:
3245 case (int) R_PPC64_TOC16_LO_DS
:
3246 BFD_ASSERT (sec
!= (asection
*) 0);
3247 /* Only .got, .toc and *UND* symbols are allowed. */
3248 BFD_ASSERT (bfd_is_und_section (sec
)
3249 || strcmp (bfd_get_section_name (abfd
, sec
),
3251 || strcmp (bfd_get_section_name (abfd
, sec
),
3254 addend
-= TOCstart
+ TOC_BASE_OFF
;
3257 case (int) R_PPC64_TOC16_HA
:
3258 BFD_ASSERT (sec
!= (asection
*) 0);
3259 BFD_ASSERT (bfd_is_und_section (sec
)
3260 || strcmp (bfd_get_section_name (abfd
, sec
),
3262 || strcmp (bfd_get_section_name (abfd
, sec
),
3265 addend
-= TOCstart
+ TOC_BASE_OFF
;
3266 /* Add 1 to 16-bit word 16:31 if sign bit in 0:15 is set. */
3267 addend
+= ((relocation
+ addend
) & 0x8000) << 1;
3270 /* Relocate against the beginning of the section. */
3271 case (int) R_PPC64_SECTOFF
:
3272 case (int) R_PPC64_SECTOFF_LO
:
3273 case (int) R_PPC64_SECTOFF_HI
:
3274 case (int) R_PPC64_SECTOFF_DS
:
3275 case (int) R_PPC64_SECTOFF_LO_DS
:
3276 BFD_ASSERT (sec
!= (asection
*) 0);
3277 addend
-= sec
->output_section
->vma
;
3280 case (int) R_PPC64_SECTOFF_HA
:
3281 BFD_ASSERT (sec
!= (asection
*) 0);
3282 addend
-= sec
->output_section
->vma
;
3283 addend
+= ((relocation
+ addend
) & 0x8000) << 1;
3286 case (int) R_PPC64_COPY
:
3287 case (int) R_PPC64_GLOB_DAT
:
3288 case (int) R_PPC64_JMP_SLOT
:
3289 case (int) R_PPC64_RELATIVE
:
3290 case (int) R_PPC64_PLT32
:
3291 case (int) R_PPC64_PLTREL32
:
3292 case (int) R_PPC64_PLT16_LO
:
3293 case (int) R_PPC64_PLT16_LO_DS
:
3294 case (int) R_PPC64_PLT16_HI
:
3295 case (int) R_PPC64_PLT16_HA
:
3296 case (int) R_PPC64_PLT64
:
3297 case (int) R_PPC64_PLTREL64
:
3298 case (int) R_PPC64_PLTGOT16
:
3299 case (int) R_PPC64_PLTGOT16_LO
:
3300 case (int) R_PPC64_PLTGOT16_DS
:
3301 case (int) R_PPC64_PLTGOT16_LO_DS
:
3302 case (int) R_PPC64_PLTGOT16_HI
:
3303 case (int) R_PPC64_PLTGOT16_HA
:
3304 (*_bfd_error_handler
) (_("%s: Relocation %s is not yet supported for symbol %s."),
3305 bfd_get_filename (input_bfd
),
3306 ppc64_elf_howto_table
[(int) r_type
]->name
,
3309 bfd_set_error (bfd_error_invalid_operation
);
3313 case (int) R_PPC_GNU_VTINHERIT
:
3314 case (int) R_PPC_GNU_VTENTRY
:
3315 /* These are no-ops in the end. */
3320 fprintf (stderr
, " type = %s (%d), name = %s, sym index = %ld, offset = %ld, addend = %ld\n",
3329 r
= _bfd_final_link_relocate (howto
,
3337 if (r
== bfd_reloc_ok
)
3339 else if (r
== bfd_reloc_overflow
)
3345 if (h
->root
.type
== bfd_link_hash_undefweak
3346 && howto
->pc_relative
)
3348 /* Assume this is a call protected by other code that
3349 detects the symbol is undefined. If this is the case,
3350 we can safely ignore the overflow. If not, the
3351 program is hosed anyway, and a little warning isn't
3357 name
= h
->root
.root
.string
;
3361 name
= bfd_elf_string_from_elf_section (input_bfd
,
3362 symtab_hdr
->sh_link
,
3367 name
= bfd_section_name (input_bfd
, sec
);
3370 if (! (*info
->callbacks
->reloc_overflow
) (info
,
3384 fprintf (stderr
, "\n");
3390 /* Finish up dynamic symbol handling. We set the contents of various
3391 dynamic sections here. */
3394 ppc64_elf_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
3396 struct bfd_link_info
*info
;
3397 struct elf_link_hash_entry
*h
;
3398 Elf_Internal_Sym
*sym
;
3403 fprintf (stderr
, "ppc64_elf_finish_dynamic_symbol called for %s",
3404 h
->root
.root
.string
);
3407 dynobj
= elf_hash_table (info
)->dynobj
;
3408 BFD_ASSERT (dynobj
!= NULL
);
3410 if (h
->plt
.offset
!= (bfd_vma
) -1)
3412 asection
*splt
, *srela
, *sglink
;
3413 Elf_Internal_Rela rela
;
3414 bfd_vma reloc_index
, plt_offset
;
3415 struct elf_link_hash_entry
*funcdesc_h
;
3418 fprintf (stderr
, ", plt_offset = 0x%lx", (unsigned long) h
->plt
.offset
);
3421 /* This symbol has an entry in the procedure linkage table. Set
3424 BFD_ASSERT (h
->dynindx
!= -1);
3426 splt
= bfd_get_section_by_name (dynobj
, ".plt");
3427 srela
= bfd_get_section_by_name (dynobj
, ".rela.plt");
3428 BFD_ASSERT (splt
!= NULL
&& srela
!= NULL
);
3430 /* We don't need to fill in the .plt. The dynamic linker will
3433 /* We may need to create a linkage function. */
3434 sglink
= bfd_get_section_by_name (dynobj
, ".glink");
3435 if (sglink
!= NULL
&& h
->root
.u
.def
.section
== sglink
)
3439 const unsigned int *stub
;
3441 /* Where to write it. */
3442 p
= h
->root
.u
.def
.section
->contents
+ h
->root
.u
.def
.value
;
3444 /* The function descriptor is in the PLT. */
3445 pltoff
= splt
->output_section
->vma
3446 + splt
->output_section
->output_offset
3448 - elf_gp (output_bfd
) - TOC_BASE_OFF
;
3450 if (pltoff
+ 0x8000 > 0xffff)
3452 (*_bfd_error_handler
)
3453 (_("linkage table overflow against `%s'"),
3454 h
->root
.root
.string
);
3458 stub
= ppc64_elf_glink_code
;
3459 bfd_put_32 (output_bfd
, *stub
| (pltoff
& 0xfffc), p
);
3460 while (p
+= 4, ++stub
< (ppc64_elf_glink_code
3461 + (sizeof (ppc64_elf_glink_code
)
3462 / sizeof (*ppc64_elf_glink_code
))));
3464 bfd_put_32 (output_bfd
, *stub
, p
);
3467 fprintf (stderr
, ", linkage function");
3471 /* Create a JMP_SLOT reloc to inform the dynamic linker to fix
3474 /* Save the PLT offset, since `h' may be changed below. */
3475 plt_offset
= h
->plt
.offset
;
3477 /* If it's a function entry point, find its corresponding
3478 function descriptor. ppc64_elf_adjust_dynamic_symbol have
3479 already set it up for us. */
3481 /* FIXME: Is it safe to assume that this symbol is a function? */
3482 BFD_ASSERT (h
->root
.root
.string
[0] == '.');
3484 /* FIXME: Follow bfd_link_hash_indirect? */
3485 funcdesc_h
= elf_link_hash_lookup (elf_hash_table (info
),
3486 h
->root
.root
.string
+ 1,
3487 false, false, false);
3488 BFD_ASSERT (funcdesc_h
!= NULL
);
3489 BFD_ASSERT (funcdesc_h
->dynindx
!= -1);
3491 /* FIXME: Rename the symbol for the function entry point to
3492 `linkage_for_FUNC'? */
3494 rela
.r_offset
= (splt
->output_section
->vma
3495 + splt
->output_offset
3497 rela
.r_info
= ELF64_R_INFO (funcdesc_h
->dynindx
, R_PPC64_JMP_SLOT
);
3500 reloc_index
= (plt_offset
- PLT_INITIAL_ENTRY_SIZE
) / PLT_ENTRY_SIZE
;
3501 bfd_elf64_swap_reloca_out (output_bfd
, &rela
,
3502 ((Elf64_External_Rela
*) srela
->contents
3505 fprintf (stderr
, ", JMP_SLOT for %s", funcdesc_h
->root
.root
.string
);
3509 /* FIXME: Really do this? */
3510 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
3512 /* Mark the symbol as undefined, rather than as defined in
3513 the .plt section. Leave the value alone. */
3514 sym
->st_shndx
= SHN_UNDEF
;
3519 if (h
->got
.offset
!= (bfd_vma
) -1)
3523 Elf_Internal_Rela rela
;
3526 fprintf (stderr
, ", got.offset = %08lx", (unsigned long) h
->got
.offset
);
3529 /* This symbol has an entry in the global offset table. Set it
3532 sgot
= bfd_get_section_by_name (dynobj
, ".got");
3533 srela
= bfd_get_section_by_name (dynobj
, ".rela.got");
3534 BFD_ASSERT (sgot
!= NULL
&& srela
!= NULL
);
3536 rela
.r_offset
= (sgot
->output_section
->vma
3537 + sgot
->output_offset
3538 + (h
->got
.offset
&~ 1));
3540 /* If this is a -Bsymbolic link, and the symbol is defined
3541 locally, we just want to emit a RELATIVE reloc. The entry in
3542 the global offset table will already have been initialized in
3543 the relocate_section function. */
3545 && (info
->symbolic
|| h
->dynindx
== -1)
3546 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
))
3548 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
3549 rela
.r_addend
= (h
->root
.u
.def
.value
3550 + h
->root
.u
.def
.section
->output_section
->vma
3551 + h
->root
.u
.def
.section
->output_offset
);
3555 BFD_ASSERT ((h
->got
.offset
& 1) == 0);
3556 bfd_put_64 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ h
->got
.offset
);
3557 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_PPC64_GLOB_DAT
);
3561 bfd_elf64_swap_reloca_out (output_bfd
, &rela
,
3562 ((Elf64_External_Rela
*) srela
->contents
3563 + srela
->reloc_count
));
3564 ++srela
->reloc_count
;
3567 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_COPY
) != 0)
3570 Elf_Internal_Rela rela
;
3572 /* This symbols needs a copy reloc. Set it up. */
3575 fprintf (stderr
, ", copy");
3578 BFD_ASSERT (h
->dynindx
!= -1);
3580 s
= bfd_get_section_by_name (h
->root
.u
.def
.section
->owner
,
3582 BFD_ASSERT (s
!= NULL
);
3584 rela
.r_offset
= (h
->root
.u
.def
.value
3585 + h
->root
.u
.def
.section
->output_section
->vma
3586 + h
->root
.u
.def
.section
->output_offset
);
3587 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_PPC64_COPY
);
3589 bfd_elf64_swap_reloca_out (output_bfd
, &rela
,
3590 ((Elf64_External_Rela
*) s
->contents
3596 fprintf (stderr
, "\n");
3599 /* Mark some specially defined symbols as absolute. */
3600 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0)
3601 sym
->st_shndx
= SHN_ABS
;
3606 /* Finish up the dynamic sections. */
3609 ppc64_elf_finish_dynamic_sections (output_bfd
, info
)
3611 struct bfd_link_info
*info
;
3614 bfd
*dynobj
= elf_hash_table (info
)->dynobj
;
3617 fprintf (stderr
, "ppc64_elf_finish_dynamic_sections called\n");
3620 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
3622 if (elf_hash_table (info
)->dynamic_sections_created
)
3625 Elf64_External_Dyn
*dyncon
, *dynconend
;
3627 splt
= bfd_get_section_by_name (dynobj
, ".plt");
3628 BFD_ASSERT (splt
!= NULL
&& sdyn
!= NULL
);
3630 dyncon
= (Elf64_External_Dyn
*) sdyn
->contents
;
3631 dynconend
= (Elf64_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
3632 for (; dyncon
< dynconend
; dyncon
++)
3634 Elf_Internal_Dyn dyn
;
3638 bfd_elf64_swap_dyn_in (dynobj
, dyncon
, &dyn
);
3642 case DT_PLTGOT
: name
= ".plt"; size
= false; break;
3643 case DT_PLTRELSZ
: name
= ".rela.plt"; size
= true; break;
3644 case DT_JMPREL
: name
= ".rela.plt"; size
= false; break;
3645 default: name
= NULL
; size
= false; break;
3652 s
= bfd_get_section_by_name (output_bfd
, name
);
3658 dyn
.d_un
.d_ptr
= s
->vma
;
3661 if (s
->_cooked_size
!= 0)
3662 dyn
.d_un
.d_val
= s
->_cooked_size
;
3664 dyn
.d_un
.d_val
= s
->_raw_size
;
3667 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
3676 Elf_Internal_Sym sym
;
3679 /* Set up the section symbols for the output sections. */
3681 sdynsym
= bfd_get_section_by_name (dynobj
, ".dynsym");
3682 BFD_ASSERT (sdynsym
!= NULL
);
3686 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_SECTION
);
3689 for (s
= output_bfd
->sections
; s
!= NULL
; s
= s
->next
)
3693 sym
.st_value
= s
->vma
;
3695 indx
= elf_section_data (s
)->this_idx
;
3696 dindx
= elf_section_data (s
)->dynindx
;
3699 BFD_ASSERT (indx
> 0);
3700 BFD_ASSERT (dindx
> 0);
3702 if (dindx
> maxdindx
)
3705 sym
.st_shndx
= indx
;
3707 bfd_elf64_swap_symbol_out (output_bfd
, &sym
,
3708 (PTR
) (((Elf64_External_Sym
*)
3714 /* Set the sh_info field of the output .dynsym section to the
3715 index of the first global symbol. */
3716 elf_section_data (sdynsym
->output_section
)->this_hdr
.sh_info
=
3723 #define TARGET_LITTLE_SYM bfd_elf64_powerpcle_vec
3724 #define TARGET_LITTLE_NAME "elf64-powerpcle"
3725 #define TARGET_BIG_SYM bfd_elf64_powerpc_vec
3726 #define TARGET_BIG_NAME "elf64-powerpc"
3727 #define ELF_ARCH bfd_arch_powerpc
3728 #define ELF_MACHINE_CODE EM_PPC64
3729 #define ELF_MAXPAGESIZE 0x10000
3730 #define elf_info_to_howto ppc64_elf_info_to_howto
3732 #ifdef EM_CYGNUS_POWERPC
3733 #define ELF_MACHINE_ALT1 EM_CYGNUS_POWERPC
3737 #define ELF_MACHINE_ALT2 EM_PPC_OLD
3740 #define elf_backend_want_got_sym 0
3741 #define elf_backend_want_plt_sym 0
3742 #define elf_backend_plt_alignment 3
3743 #define elf_backend_plt_not_loaded 1
3744 #define elf_backend_got_symbol_offset 0
3745 #define elf_backend_got_header_size 0
3746 #define elf_backend_can_gc_sections 1
3748 #define elf_backend_plt_header_size PLT_INITIAL_ENTRY_SIZE
3750 #define bfd_elf64_bfd_copy_private_bfd_data ppc64_elf_copy_private_bfd_data
3751 #define bfd_elf64_bfd_merge_private_bfd_data ppc64_elf_merge_private_bfd_data
3752 #define bfd_elf64_bfd_reloc_type_lookup ppc64_elf_reloc_type_lookup
3753 #define bfd_elf64_bfd_set_private_flags ppc64_elf_set_private_flags
3754 #define bfd_elf64_bfd_final_link ppc64_elf_final_link
3756 #define elf_backend_gc_mark_hook ppc64_elf_gc_mark_hook
3757 #define elf_backend_gc_sweep_hook ppc64_elf_gc_sweep_hook
3758 #define elf_backend_section_from_shdr ppc64_elf_section_from_shdr
3759 #define elf_backend_relocate_section ppc64_elf_relocate_section
3760 #define elf_backend_create_dynamic_sections ppc64_elf_create_dynamic_sections
3761 #define elf_backend_check_relocs ppc64_elf_check_relocs
3762 #define elf_backend_adjust_dynamic_symbol ppc64_elf_adjust_dynamic_symbol
3763 #define elf_backend_size_dynamic_sections ppc64_elf_size_dynamic_sections
3764 #define elf_backend_finish_dynamic_symbol ppc64_elf_finish_dynamic_symbol
3765 #define elf_backend_finish_dynamic_sections ppc64_elf_finish_dynamic_sections
3766 #define elf_backend_fake_sections ppc64_elf_fake_sections
3768 #include "elf64-target.h"