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 struct bfd_hash_entry
*link_hash_newfunc
52 PARAMS ((struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *));
53 static struct bfd_link_hash_table
*ppc64_elf_link_hash_table_create
55 static boolean create_got_section
56 PARAMS ((bfd
*, struct bfd_link_info
*));
57 static boolean ppc64_elf_create_dynamic_sections
58 PARAMS ((bfd
*, struct bfd_link_info
*));
59 static void ppc64_elf_copy_indirect_symbol
60 PARAMS ((struct elf_link_hash_entry
*, struct elf_link_hash_entry
*));
61 static boolean ppc64_elf_check_relocs
62 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
63 const Elf_Internal_Rela
*));
64 static asection
* ppc64_elf_gc_mark_hook
65 PARAMS ((bfd
*abfd
, struct bfd_link_info
*info
, Elf_Internal_Rela
*rel
,
66 struct elf_link_hash_entry
*h
, Elf_Internal_Sym
*sym
));
67 static boolean ppc64_elf_gc_sweep_hook
68 PARAMS ((bfd
*abfd
, struct bfd_link_info
*info
, asection
*sec
,
69 const Elf_Internal_Rela
*relocs
));
70 static boolean ppc64_elf_adjust_dynamic_symbol
71 PARAMS ((struct bfd_link_info
*, struct elf_link_hash_entry
*));
72 static boolean allocate_dynrelocs
73 PARAMS ((struct elf_link_hash_entry
*, PTR
));
74 static boolean readonly_dynrelocs
75 PARAMS ((struct elf_link_hash_entry
*, PTR
));
76 static enum elf_reloc_type_class ppc64_elf_reloc_type_class
77 PARAMS ((const Elf_Internal_Rela
*));
78 static boolean ppc64_elf_size_dynamic_sections
79 PARAMS ((bfd
*, struct bfd_link_info
*));
80 static boolean ppc64_elf_final_link
81 PARAMS ((bfd
*, struct bfd_link_info
*));
82 static boolean ppc64_elf_fake_sections
83 PARAMS ((bfd
*, Elf64_Internal_Shdr
*, asection
*));
84 static boolean ppc64_elf_relocate_section
85 PARAMS ((bfd
*, struct bfd_link_info
*info
, bfd
*, asection
*, bfd_byte
*,
86 Elf_Internal_Rela
*relocs
, Elf_Internal_Sym
*local_syms
,
88 static boolean ppc64_elf_finish_dynamic_symbol
89 PARAMS ((bfd
*, struct bfd_link_info
*, struct elf_link_hash_entry
*,
91 static boolean ppc64_elf_finish_dynamic_sections
92 PARAMS ((bfd
*, struct bfd_link_info
*));
95 /* Branch prediction bit for branch taken relocs. */
96 #define BRANCH_PREDICT_BIT 0x200000
98 /* Mask to set RA in memory instructions. */
99 #define RA_REGISTER_MASK 0x001f0000
101 /* Value to shift register by to insert RA. */
102 #define RA_REGISTER_SHIFT 16
104 /* The name of the dynamic interpreter. This is put in the .interp
106 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
108 /* The size in bytes of an entry in the procedure linkage table. */
109 #define PLT_ENTRY_SIZE 24
111 /* The initial size of the plt reserved for the dynamic linker. */
112 #define PLT_INITIAL_ENTRY_SIZE 96
114 /* TOC base pointers offset from start of TOC. */
115 #define TOC_BASE_OFF (0x8000)
117 /* Global linkage stub. The first instruction has its offset patched. */
118 /* FIXME: Need traceback table? */
119 static const unsigned int ppc64_elf_glink_code
[] = {
120 0xe9820000, /* ld %r12,0(%r2) */
121 0xf8410028, /* std %r2,40(%r1) */
122 0xe80c0000, /* ld %r0,0(%r12) */
123 0xe84c0008, /* ld %r2,8(%r12) */
124 0x7c0903a6, /* mtctr %r0 */
125 0x4e800420 /* bctr */
128 #define PPC64_ELF_GLINK_SIZE \
129 ((sizeof ppc64_elf_glink_code / sizeof ppc64_elf_glink_code[0]) * 4)
131 /* Relocation HOWTO's. */
132 static reloc_howto_type
*ppc64_elf_howto_table
[(int) R_PPC_max
];
134 static reloc_howto_type ppc64_elf_howto_raw
[] = {
135 /* This reloc does nothing. */
136 HOWTO (R_PPC64_NONE
, /* type */
138 2, /* size (0 = byte, 1 = short, 2 = long) */
140 false, /* pc_relative */
142 complain_overflow_bitfield
, /* complain_on_overflow */
143 bfd_elf_generic_reloc
, /* special_function */
144 "R_PPC64_NONE", /* name */
145 false, /* partial_inplace */
148 false), /* pcrel_offset */
150 /* A standard 32 bit relocation. */
151 HOWTO (R_PPC64_ADDR32
, /* type */
153 2, /* size (0 = byte, 1 = short, 2 = long) */
155 false, /* pc_relative */
157 complain_overflow_bitfield
, /* complain_on_overflow */
158 bfd_elf_generic_reloc
, /* special_function */
159 "R_PPC64_ADDR32", /* name */
160 false, /* partial_inplace */
162 0xffffffff, /* dst_mask */
163 false), /* pcrel_offset */
165 /* An absolute 26 bit branch; the lower two bits must be zero.
166 FIXME: we don't check that, we just clear them. */
167 HOWTO (R_PPC64_ADDR24
, /* type */
169 2, /* size (0 = byte, 1 = short, 2 = long) */
171 false, /* pc_relative */
173 complain_overflow_bitfield
, /* complain_on_overflow */
174 bfd_elf_generic_reloc
, /* special_function */
175 "R_PPC64_ADDR24", /* name */
176 false, /* partial_inplace */
178 0x3fffffc, /* dst_mask */
179 false), /* pcrel_offset */
181 /* A standard 16 bit relocation. */
182 HOWTO (R_PPC64_ADDR16
, /* type */
184 1, /* size (0 = byte, 1 = short, 2 = long) */
186 false, /* pc_relative */
188 complain_overflow_bitfield
, /* complain_on_overflow */
189 bfd_elf_generic_reloc
, /* special_function */
190 "R_PPC64_ADDR16", /* name */
191 false, /* partial_inplace */
193 0xffff, /* dst_mask */
194 false), /* pcrel_offset */
196 /* A 16 bit relocation without overflow. */
197 HOWTO (R_PPC64_ADDR16_LO
, /* type */
199 1, /* size (0 = byte, 1 = short, 2 = long) */
201 false, /* pc_relative */
203 complain_overflow_dont
,/* complain_on_overflow */
204 bfd_elf_generic_reloc
, /* special_function */
205 "R_PPC64_ADDR16_LO", /* name */
206 false, /* partial_inplace */
208 0xffff, /* dst_mask */
209 false), /* pcrel_offset */
211 /* Bits 16-31 of an address. */
212 HOWTO (R_PPC64_ADDR16_HI
, /* type */
214 1, /* size (0 = byte, 1 = short, 2 = long) */
216 false, /* pc_relative */
218 complain_overflow_dont
, /* complain_on_overflow */
219 bfd_elf_generic_reloc
, /* special_function */
220 "R_PPC64_ADDR16_HI", /* name */
221 false, /* partial_inplace */
223 0xffff, /* dst_mask */
224 false), /* pcrel_offset */
226 /* Bits 16-31 of an address, plus 1 if the contents of the low 16
227 bits, treated as a signed number, is negative. */
228 HOWTO (R_PPC64_ADDR16_HA
, /* type */
230 1, /* size (0 = byte, 1 = short, 2 = long) */
232 false, /* pc_relative */
234 complain_overflow_dont
, /* complain_on_overflow */
235 ppc64_elf_addr16_ha_reloc
, /* special_function */
236 "R_PPC64_ADDR16_HA", /* name */
237 false, /* partial_inplace */
239 0xffff, /* dst_mask */
240 false), /* pcrel_offset */
242 /* An absolute 16 bit branch; the lower two bits must be zero.
243 FIXME: we don't check that, we just clear them. */
244 HOWTO (R_PPC64_ADDR14
, /* type */
246 2, /* size (0 = byte, 1 = short, 2 = long) */
248 false, /* pc_relative */
250 complain_overflow_bitfield
, /* complain_on_overflow */
251 bfd_elf_generic_reloc
, /* special_function */
252 "R_PPC64_ADDR14", /* name */
253 false, /* partial_inplace */
255 0xfffc, /* dst_mask */
256 false), /* pcrel_offset */
258 /* An absolute 16 bit branch, for which bit 10 should be set to
259 indicate that the branch is expected to be taken. The lower two
260 bits must be zero. */
261 HOWTO (R_PPC64_ADDR14_BRTAKEN
, /* type */
263 2, /* size (0 = byte, 1 = short, 2 = long) */
265 false, /* pc_relative */
267 complain_overflow_bitfield
, /* complain_on_overflow */
268 bfd_elf_generic_reloc
, /* special_function */
269 "R_PPC64_ADDR14_BRTAKEN",/* name */
270 false, /* partial_inplace */
272 0xfffc, /* dst_mask */
273 false), /* pcrel_offset */
275 /* An absolute 16 bit branch, for which bit 10 should be set to
276 indicate that the branch is not expected to be taken. The lower
277 two bits must be zero. */
278 HOWTO (R_PPC64_ADDR14_BRNTAKEN
, /* type */
280 2, /* size (0 = byte, 1 = short, 2 = long) */
282 false, /* pc_relative */
284 complain_overflow_bitfield
, /* complain_on_overflow */
285 bfd_elf_generic_reloc
, /* special_function */
286 "R_PPC64_ADDR14_BRNTAKEN",/* name */
287 false, /* partial_inplace */
289 0xfffc, /* dst_mask */
290 false), /* pcrel_offset */
292 /* A relative 26 bit branch; the lower two bits must be zero. */
293 HOWTO (R_PPC64_REL24
, /* type */
295 2, /* size (0 = byte, 1 = short, 2 = long) */
297 true, /* pc_relative */
299 complain_overflow_signed
, /* complain_on_overflow */
300 bfd_elf_generic_reloc
, /* special_function */
301 "R_PPC64_REL24", /* name */
302 false, /* partial_inplace */
304 0x3fffffc, /* dst_mask */
305 true), /* pcrel_offset */
307 /* A relative 16 bit branch; the lower two bits must be zero. */
308 HOWTO (R_PPC64_REL14
, /* type */
310 2, /* size (0 = byte, 1 = short, 2 = long) */
312 true, /* pc_relative */
314 complain_overflow_signed
, /* complain_on_overflow */
315 bfd_elf_generic_reloc
, /* special_function */
316 "R_PPC64_REL14", /* name */
317 false, /* partial_inplace */
319 0xfffc, /* dst_mask */
320 true), /* pcrel_offset */
322 /* A relative 16 bit branch. Bit 10 should be set to indicate that
323 the branch is expected to be taken. The lower two bits must be
325 HOWTO (R_PPC64_REL14_BRTAKEN
, /* type */
327 2, /* size (0 = byte, 1 = short, 2 = long) */
329 true, /* pc_relative */
331 complain_overflow_signed
, /* complain_on_overflow */
332 bfd_elf_generic_reloc
, /* special_function */
333 "R_PPC64_REL14_BRTAKEN", /* name */
334 false, /* partial_inplace */
336 0xfffc, /* dst_mask */
337 true), /* pcrel_offset */
339 /* A relative 16 bit branch. Bit 10 should be set to indicate that
340 the branch is not expected to be taken. The lower two bits must
342 HOWTO (R_PPC64_REL14_BRNTAKEN
, /* type */
344 2, /* size (0 = byte, 1 = short, 2 = long) */
346 true, /* pc_relative */
348 complain_overflow_signed
, /* complain_on_overflow */
349 bfd_elf_generic_reloc
, /* special_function */
350 "R_PPC64_REL14_BRNTAKEN",/* name */
351 false, /* partial_inplace */
353 0xfffc, /* dst_mask */
354 true), /* pcrel_offset */
356 /* Like R_PPC64_ADDR16, but referring to the GOT table entry for the
358 HOWTO (R_PPC64_GOT16
, /* type */
360 1, /* size (0 = byte, 1 = short, 2 = long) */
362 false, /* pc_relative */
364 complain_overflow_signed
, /* complain_on_overflow */
365 bfd_elf_generic_reloc
, /* special_function */
366 "R_PPC64_GOT16", /* name */
367 false, /* partial_inplace */
369 0xffff, /* dst_mask */
370 false), /* pcrel_offset */
372 /* Like R_PPC64_ADDR16_LO, but referring to the GOT table entry for
374 HOWTO (R_PPC64_GOT16_LO
, /* type */
376 1, /* size (0 = byte, 1 = short, 2 = long) */
378 false, /* pc_relative */
380 complain_overflow_dont
, /* complain_on_overflow */
381 bfd_elf_generic_reloc
, /* special_function */
382 "R_PPC64_GOT16_LO", /* name */
383 false, /* partial_inplace */
385 0xffff, /* dst_mask */
386 false), /* pcrel_offset */
388 /* Like R_PPC64_ADDR16_HI, but referring to the GOT table entry for
390 HOWTO (R_PPC64_GOT16_HI
, /* type */
392 1, /* size (0 = byte, 1 = short, 2 = long) */
394 false, /* pc_relative */
396 complain_overflow_dont
,/* complain_on_overflow */
397 bfd_elf_generic_reloc
, /* special_function */
398 "R_PPC64_GOT16_HI", /* name */
399 false, /* partial_inplace */
401 0xffff, /* dst_mask */
402 false), /* pcrel_offset */
404 /* Like R_PPC64_ADDR16_HA, but referring to the GOT table entry for
406 HOWTO (R_PPC64_GOT16_HA
, /* type */
408 1, /* size (0 = byte, 1 = short, 2 = long) */
410 false, /* pc_relative */
412 complain_overflow_dont
,/* complain_on_overflow */
413 ppc64_elf_addr16_ha_reloc
, /* special_function */
414 "R_PPC64_GOT16_HA", /* name */
415 false, /* partial_inplace */
417 0xffff, /* dst_mask */
418 false), /* pcrel_offset */
420 /* This is used only by the dynamic linker. The symbol should exist
421 both in the object being run and in some shared library. The
422 dynamic linker copies the data addressed by the symbol from the
423 shared library into the object, because the object being
424 run has to have the data at some particular address. */
425 HOWTO (R_PPC64_COPY
, /* type */
427 2, /* size (0 = byte, 1 = short, 2 = long) */
429 false, /* pc_relative */
431 complain_overflow_bitfield
, /* complain_on_overflow */
432 bfd_elf_generic_reloc
, /* special_function */
433 "R_PPC64_COPY", /* name */
434 false, /* partial_inplace */
437 false), /* pcrel_offset */
439 /* Like R_PPC64_ADDR64, but used when setting global offset table
441 HOWTO (R_PPC64_GLOB_DAT
, /* type */
443 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
445 false, /* pc_relative */
447 complain_overflow_dont
, /* complain_on_overflow */
448 bfd_elf_generic_reloc
, /* special_function */
449 "R_PPC64_GLOB_DAT", /* name */
450 false, /* partial_inplace */
452 0xffffffffffffffff, /* dst_mask */
453 false), /* pcrel_offset */
455 /* Created by the link editor. Marks a procedure linkage table
456 entry for a symbol. */
457 HOWTO (R_PPC64_JMP_SLOT
, /* type */
459 0, /* size (0 = byte, 1 = short, 2 = long) */
461 false, /* pc_relative */
463 complain_overflow_dont
, /* complain_on_overflow */
464 bfd_elf_generic_reloc
, /* special_function */
465 "R_PPC64_JMP_SLOT", /* name */
466 false, /* partial_inplace */
469 false), /* pcrel_offset */
471 /* Used only by the dynamic linker. When the object is run, this
472 doubleword64 is set to the load address of the object, plus the
474 HOWTO (R_PPC64_RELATIVE
, /* type */
476 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
478 false, /* pc_relative */
480 complain_overflow_dont
, /* complain_on_overflow */
481 bfd_elf_generic_reloc
, /* special_function */
482 "R_PPC64_RELATIVE", /* name */
483 false, /* partial_inplace */
485 0xffffffffffffffff, /* dst_mask */
486 false), /* pcrel_offset */
488 /* Like R_PPC64_ADDR32, but may be unaligned. */
489 HOWTO (R_PPC64_UADDR32
, /* type */
491 2, /* size (0 = byte, 1 = short, 2 = long) */
493 false, /* pc_relative */
495 complain_overflow_bitfield
, /* complain_on_overflow */
496 bfd_elf_generic_reloc
, /* special_function */
497 "R_PPC64_UADDR32", /* name */
498 false, /* partial_inplace */
500 0xffffffff, /* dst_mask */
501 false), /* pcrel_offset */
503 /* Like R_PPC64_ADDR16, but may be unaligned. */
504 HOWTO (R_PPC64_UADDR16
, /* type */
506 1, /* size (0 = byte, 1 = short, 2 = long) */
508 false, /* pc_relative */
510 complain_overflow_bitfield
, /* complain_on_overflow */
511 bfd_elf_generic_reloc
, /* special_function */
512 "R_PPC64_UADDR16", /* name */
513 false, /* partial_inplace */
515 0xffff, /* dst_mask */
516 false), /* pcrel_offset */
518 /* 32-bit PC relative. */
519 HOWTO (R_PPC64_REL32
, /* type */
521 2, /* size (0 = byte, 1 = short, 2 = long) */
523 true, /* pc_relative */
525 /* FIXME: Verify. Was complain_overflow_bitfield. */
526 complain_overflow_signed
, /* complain_on_overflow */
527 bfd_elf_generic_reloc
, /* special_function */
528 "R_PPC64_REL32", /* name */
529 false, /* partial_inplace */
531 0xffffffff, /* dst_mask */
532 true), /* pcrel_offset */
534 /* 32-bit relocation to the symbol's procedure linkage table.
535 FIXME: R_PPC64_PLT32 not supported. */
536 HOWTO (R_PPC64_PLT32
, /* type */
538 2, /* size (0 = byte, 1 = short, 2 = long) */
540 false, /* pc_relative */
542 complain_overflow_bitfield
, /* complain_on_overflow */
543 bfd_elf_generic_reloc
, /* special_function */
544 "R_PPC64_PLT32", /* name */
545 false, /* partial_inplace */
548 false), /* pcrel_offset */
550 /* 32-bit PC relative relocation to the symbol's procedure linkage table.
551 FIXME: R_PPC64_PLTREL32 not supported. */
552 HOWTO (R_PPC64_PLTREL32
, /* type */
554 2, /* size (0 = byte, 1 = short, 2 = long) */
556 true, /* pc_relative */
558 complain_overflow_signed
, /* complain_on_overflow */
559 bfd_elf_generic_reloc
, /* special_function */
560 "R_PPC64_PLTREL32", /* name */
561 false, /* partial_inplace */
564 true), /* pcrel_offset */
566 /* Like R_PPC64_ADDR16_LO, but referring to the PLT table entry for
568 HOWTO (R_PPC64_PLT16_LO
, /* type */
570 1, /* size (0 = byte, 1 = short, 2 = long) */
572 false, /* pc_relative */
574 complain_overflow_dont
, /* complain_on_overflow */
575 bfd_elf_generic_reloc
, /* special_function */
576 "R_PPC64_PLT16_LO", /* name */
577 false, /* partial_inplace */
579 0xffff, /* dst_mask */
580 false), /* pcrel_offset */
582 /* Like R_PPC64_ADDR16_HI, but referring to the PLT table entry for
584 HOWTO (R_PPC64_PLT16_HI
, /* type */
586 1, /* size (0 = byte, 1 = short, 2 = long) */
588 false, /* pc_relative */
590 complain_overflow_dont
, /* complain_on_overflow */
591 bfd_elf_generic_reloc
, /* special_function */
592 "R_PPC64_PLT16_HI", /* name */
593 false, /* partial_inplace */
595 0xffff, /* dst_mask */
596 false), /* pcrel_offset */
598 /* Like R_PPC64_ADDR16_HA, but referring to the PLT table entry for
600 HOWTO (R_PPC64_PLT16_HA
, /* type */
602 1, /* size (0 = byte, 1 = short, 2 = long) */
604 false, /* pc_relative */
606 complain_overflow_dont
, /* complain_on_overflow */
607 ppc64_elf_addr16_ha_reloc
, /* special_function */
608 "R_PPC64_PLT16_HA", /* name */
609 false, /* partial_inplace */
611 0xffff, /* dst_mask */
612 false), /* pcrel_offset */
614 /* 32-bit section relative relocation. */
615 /* FIXME: Verify R_PPC64_SECTOFF. Seems strange with size=2 and
617 HOWTO (R_PPC64_SECTOFF
, /* type */
619 2, /* size (0 = byte, 1 = short, 2 = long) */
621 true, /* pc_relative */
623 complain_overflow_bitfield
, /* complain_on_overflow */
624 bfd_elf_generic_reloc
, /* special_function */
625 "R_PPC64_SECTOFF", /* name */
626 false, /* partial_inplace */
629 true), /* pcrel_offset */
631 /* 16-bit lower half section relative relocation. */
632 HOWTO (R_PPC64_SECTOFF_LO
, /* type */
634 1, /* size (0 = byte, 1 = short, 2 = long) */
636 false, /* pc_relative */
638 complain_overflow_dont
, /* complain_on_overflow */
639 bfd_elf_generic_reloc
, /* special_function */
640 "R_PPC64_SECTOFF_LO", /* name */
641 false, /* partial_inplace */
643 0xffff, /* dst_mask */
644 false), /* pcrel_offset */
646 /* 16-bit upper half section relative relocation. */
647 HOWTO (R_PPC64_SECTOFF_HI
, /* type */
649 1, /* size (0 = byte, 1 = short, 2 = long) */
651 false, /* pc_relative */
653 complain_overflow_dont
, /* complain_on_overflow */
654 bfd_elf_generic_reloc
, /* special_function */
655 "R_PPC64_SECTOFF_HI", /* name */
656 false, /* partial_inplace */
658 0xffff, /* dst_mask */
659 false), /* pcrel_offset */
661 /* 16-bit upper half adjusted section relative relocation. */
662 HOWTO (R_PPC64_SECTOFF_HA
, /* type */
664 1, /* size (0 = byte, 1 = short, 2 = long) */
666 false, /* pc_relative */
668 complain_overflow_dont
, /* complain_on_overflow */
669 ppc64_elf_addr16_ha_reloc
, /* special_function */
670 "R_PPC64_SECTOFF_HA", /* name */
671 false, /* partial_inplace */
673 0xffff, /* dst_mask */
674 false), /* pcrel_offset */
676 /* Like R_PPC64_REL24 without touching the two least significant
678 /* FIXME: Verify R_PPC64_ADDR30. */
679 HOWTO (R_PPC64_ADDR30
, /* type */
681 2, /* size (0 = byte, 1 = short, 2 = long) */
683 true, /* pc_relative */
685 complain_overflow_dont
, /* complain_on_overflow */
686 bfd_elf_generic_reloc
, /* special_function */
687 "R_PPC64_ADDR30", /* name */
688 false, /* partial_inplace */
690 0xfffffffc, /* dst_mask */
691 true), /* pcrel_offset */
693 /* Relocs in the 64-bit PowerPC ELF ABI, not in the 32-bit ABI. */
695 /* A standard 64-bit relocation. */
696 HOWTO (R_PPC64_ADDR64
, /* type */
698 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
700 false, /* pc_relative */
702 complain_overflow_dont
, /* complain_on_overflow */
703 bfd_elf_generic_reloc
, /* special_function */
704 "R_PPC64_ADDR64", /* name */
705 false, /* partial_inplace */
707 0xffffffffffffffff, /* dst_mask */
708 false), /* pcrel_offset */
710 /* The bits 32-47 of an address. */
711 HOWTO (R_PPC64_ADDR16_HIGHER
, /* type */
713 1, /* size (0 = byte, 1 = short, 2 = long) */
715 false, /* pc_relative */
717 complain_overflow_dont
, /* complain_on_overflow */
718 bfd_elf_generic_reloc
, /* special_function */
719 "R_PPC64_ADDR16_HIGHER", /* name */
720 false, /* partial_inplace */
722 0xffff, /* dst_mask */
723 false), /* pcrel_offset */
725 /* The bits 32-47 of an address, plus 1 if the contents of the low
726 16 bits, treated as a signed number, is negative. */
727 HOWTO (R_PPC64_ADDR16_HIGHERA
, /* type */
729 1, /* size (0 = byte, 1 = short, 2 = long) */
731 false, /* pc_relative */
733 complain_overflow_dont
, /* complain_on_overflow */
734 ppc64_elf_addr16_ha_reloc
, /* special_function */
735 "R_PPC64_ADDR16_HIGHERA", /* name */
736 false, /* partial_inplace */
738 0xffff, /* dst_mask */
739 false), /* pcrel_offset */
741 /* The bits 48-63 of an address. */
742 HOWTO (R_PPC64_ADDR16_HIGHEST
,/* type */
744 1, /* size (0 = byte, 1 = short, 2 = long) */
746 false, /* pc_relative */
748 complain_overflow_dont
, /* complain_on_overflow */
749 bfd_elf_generic_reloc
, /* special_function */
750 "R_PPC64_ADDR16_HIGHEST", /* name */
751 false, /* partial_inplace */
753 0xffff, /* dst_mask */
754 false), /* pcrel_offset */
756 /* The bits 48-63 of an address, plus 1 if the contents of the low
757 16 bits, treated as a signed number, is negative. */
758 HOWTO (R_PPC64_ADDR16_HIGHESTA
,/* type */
760 1, /* size (0 = byte, 1 = short, 2 = long) */
762 false, /* pc_relative */
764 complain_overflow_dont
, /* complain_on_overflow */
765 ppc64_elf_addr16_ha_reloc
, /* special_function */
766 "R_PPC64_ADDR16_HIGHESTA", /* name */
767 false, /* partial_inplace */
769 0xffff, /* dst_mask */
770 false), /* pcrel_offset */
772 /* Like ADDR64, but may be unaligned. */
773 HOWTO (R_PPC64_UADDR64
, /* type */
775 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
777 false, /* pc_relative */
779 complain_overflow_dont
, /* complain_on_overflow */
780 bfd_elf_generic_reloc
, /* special_function */
781 "R_PPC64_UADDR64", /* name */
782 false, /* partial_inplace */
784 0xffffffffffffffff, /* dst_mask */
785 false), /* pcrel_offset */
787 /* 64-bit relative relocation. */
788 HOWTO (R_PPC64_REL64
, /* type */
790 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
792 true, /* pc_relative */
794 complain_overflow_dont
, /* complain_on_overflow */
795 bfd_elf_generic_reloc
, /* special_function */
796 "R_PPC64_REL64", /* name */
797 false, /* partial_inplace */
799 0xffffffffffffffff, /* dst_mask */
800 true), /* pcrel_offset */
802 /* 64-bit relocation to the symbol's procedure linkage table. */
803 /* FIXME: R_PPC64_PLT64 not supported. */
804 HOWTO (R_PPC64_PLT64
, /* type */
806 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
808 false, /* pc_relative */
810 complain_overflow_dont
, /* complain_on_overflow */
811 bfd_elf_generic_reloc
, /* special_function */
812 "R_PPC64_PLT64", /* name */
813 false, /* partial_inplace */
816 false), /* pcrel_offset */
818 /* 64-bit PC relative relocation to the symbol's procedure linkage
820 /* FIXME: R_PPC64_PLTREL64 not supported. */
821 HOWTO (R_PPC64_PLTREL64
, /* type */
823 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
825 true, /* pc_relative */
827 complain_overflow_dont
, /* complain_on_overflow */
828 bfd_elf_generic_reloc
, /* special_function */
829 "R_PPC64_PLTREL64", /* name */
830 false, /* partial_inplace */
833 true), /* pcrel_offset */
835 /* 16 bit TOC-relative relocation. */
837 /* R_PPC64_TOC16 47 half16* S + A - .TOC. */
838 HOWTO (R_PPC64_TOC16
, /* type */
840 1, /* size (0 = byte, 1 = short, 2 = long) */
842 false, /* pc_relative */
844 complain_overflow_signed
, /* complain_on_overflow */
845 bfd_elf_generic_reloc
, /* special_function */
846 "R_PPC64_TOC16", /* name */
847 false, /* partial_inplace */
849 0xffff, /* dst_mask */
850 false), /* pcrel_offset */
852 /* 16 bit TOC-relative relocation without overflow. */
854 /* R_PPC64_TOC16_LO 48 half16 #lo (S + A - .TOC.) */
855 HOWTO (R_PPC64_TOC16_LO
, /* type */
857 1, /* size (0 = byte, 1 = short, 2 = long) */
859 false, /* pc_relative */
861 complain_overflow_dont
, /* complain_on_overflow */
862 bfd_elf_generic_reloc
, /* special_function */
863 "R_PPC64_TOC16_LO", /* name */
864 false, /* partial_inplace */
866 0xffff, /* dst_mask */
867 false), /* pcrel_offset */
869 /* 16 bit TOC-relative relocation, high 16 bits. */
871 /* R_PPC64_TOC16_HI 49 half16 #hi (S + A - .TOC.) */
872 HOWTO (R_PPC64_TOC16_HI
, /* type */
874 1, /* size (0 = byte, 1 = short, 2 = long) */
876 false, /* pc_relative */
878 complain_overflow_dont
, /* complain_on_overflow */
879 bfd_elf_generic_reloc
, /* special_function */
880 "R_PPC64_TOC16_HI", /* name */
881 false, /* partial_inplace */
883 0xffff, /* dst_mask */
884 false), /* pcrel_offset */
886 /* 16 bit TOC-relative relocation, high 16 bits, plus 1 if the
887 contents of the low 16 bits, treated as a signed number, is
890 /* R_PPC64_TOC16_HA 50 half16 #ha (S + A - .TOC.) */
891 HOWTO (R_PPC64_TOC16_HA
, /* type */
893 1, /* size (0 = byte, 1 = short, 2 = long) */
895 false, /* pc_relative */
897 complain_overflow_dont
, /* complain_on_overflow */
898 ppc64_elf_addr16_ha_reloc
, /* special_function */
899 "R_PPC64_TOC16_HA", /* name */
900 false, /* partial_inplace */
902 0xffff, /* dst_mask */
903 false), /* pcrel_offset */
905 /* 64-bit relocation; insert value of TOC base (.TOC.). */
907 /* R_PPC64_TOC 51 doubleword64 .TOC. */
908 HOWTO (R_PPC64_TOC
, /* type */
910 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
912 false, /* pc_relative */
914 complain_overflow_bitfield
, /* complain_on_overflow */
915 bfd_elf_generic_reloc
, /* special_function */
916 "R_PPC64_TOC", /* name */
917 false, /* partial_inplace */
919 0xffffffffffffffff, /* dst_mask */
920 false), /* pcrel_offset */
922 /* Like R_PPC64_GOT16, but also informs the link editor that the
923 value to relocate may (!) refer to a PLT entry which the link
924 editor (a) may replace with the symbol value. If the link editor
925 is unable to fully resolve the symbol, it may (b) create a PLT
926 entry and store the address to the new PLT entry in the GOT.
927 This permits lazy resolution of function symbols at run time.
928 The link editor may also skip all of this and just (c) emit a
929 R_PPC64_GLOB_DAT to tie the symbol to the GOT entry. */
930 /* FIXME: R_PPC64_PLTGOT16 not implemented. */
931 HOWTO (R_PPC64_PLTGOT16
, /* type */
933 1, /* size (0 = byte, 1 = short, 2 = long) */
935 false, /* pc_relative */
937 complain_overflow_signed
, /* complain_on_overflow */
938 bfd_elf_generic_reloc
, /* special_function */
939 "R_PPC64_PLTGOT16", /* name */
940 false, /* partial_inplace */
942 0xffff, /* dst_mask */
943 false), /* pcrel_offset */
945 /* Like R_PPC64_PLTGOT16, but without overflow. */
946 /* FIXME: R_PPC64_PLTGOT16_LO not implemented. */
947 HOWTO (R_PPC64_PLTGOT16_LO
, /* type */
949 1, /* size (0 = byte, 1 = short, 2 = long) */
951 false, /* pc_relative */
953 complain_overflow_dont
, /* complain_on_overflow */
954 bfd_elf_generic_reloc
, /* special_function */
955 "R_PPC64_PLTGOT16_LO", /* name */
956 false, /* partial_inplace */
958 0xffff, /* dst_mask */
959 false), /* pcrel_offset */
961 /* Like R_PPC64_PLT_GOT16, but using bits 16-31 of the address. */
962 /* FIXME: R_PPC64_PLTGOT16_HI not implemented. */
963 HOWTO (R_PPC64_PLTGOT16_HI
, /* type */
965 1, /* size (0 = byte, 1 = short, 2 = long) */
967 false, /* pc_relative */
969 complain_overflow_dont
, /* complain_on_overflow */
970 bfd_elf_generic_reloc
, /* special_function */
971 "R_PPC64_PLTGOT16_HI", /* name */
972 false, /* partial_inplace */
974 0xffff, /* dst_mask */
975 false), /* pcrel_offset */
977 /* Like R_PPC64_PLT_GOT16, but using bits 16-31 of the address, plus
978 1 if the contents of the low 16 bits, treated as a signed number,
980 /* FIXME: R_PPC64_PLTGOT16_HA not implemented. */
981 HOWTO (R_PPC64_PLTGOT16_HA
, /* type */
983 1, /* size (0 = byte, 1 = short, 2 = long) */
985 false, /* pc_relative */
987 complain_overflow_dont
,/* complain_on_overflow */
988 ppc64_elf_addr16_ha_reloc
, /* special_function */
989 "R_PPC64_PLTGOT16_HA", /* name */
990 false, /* partial_inplace */
992 0xffff, /* dst_mask */
993 false), /* pcrel_offset */
995 /* Like R_PPC64_ADDR16, but for instructions with a DS field. */
996 HOWTO (R_PPC64_ADDR16_DS
, /* type */
998 1, /* size (0 = byte, 1 = short, 2 = long) */
1000 false, /* pc_relative */
1002 complain_overflow_bitfield
, /* complain_on_overflow */
1003 bfd_elf_generic_reloc
, /* special_function */
1004 "R_PPC64_ADDR16_DS", /* name */
1005 false, /* partial_inplace */
1007 0xfffc, /* dst_mask */
1008 false), /* pcrel_offset */
1010 /* Like R_PPC64_ADDR16_LO, but for instructions with a DS field. */
1011 HOWTO (R_PPC64_ADDR16_LO_DS
, /* type */
1013 1, /* size (0 = byte, 1 = short, 2 = long) */
1015 false, /* pc_relative */
1017 complain_overflow_dont
,/* complain_on_overflow */
1018 bfd_elf_generic_reloc
, /* special_function */
1019 "R_PPC64_ADDR16_LO_DS",/* name */
1020 false, /* partial_inplace */
1022 0xfffc, /* dst_mask */
1023 false), /* pcrel_offset */
1025 /* Like R_PPC64_GOT16, but for instructions with a DS field. */
1026 HOWTO (R_PPC64_GOT16_DS
, /* type */
1028 1, /* size (0 = byte, 1 = short, 2 = long) */
1030 false, /* pc_relative */
1032 complain_overflow_signed
, /* complain_on_overflow */
1033 bfd_elf_generic_reloc
, /* special_function */
1034 "R_PPC64_GOT16_DS", /* name */
1035 false, /* partial_inplace */
1037 0xfffc, /* dst_mask */
1038 false), /* pcrel_offset */
1040 /* Like R_PPC64_GOT16_LO, but for instructions with a DS field. */
1041 HOWTO (R_PPC64_GOT16_LO_DS
, /* type */
1043 1, /* size (0 = byte, 1 = short, 2 = long) */
1045 false, /* pc_relative */
1047 complain_overflow_dont
, /* complain_on_overflow */
1048 bfd_elf_generic_reloc
, /* special_function */
1049 "R_PPC64_GOT16_LO_DS", /* name */
1050 false, /* partial_inplace */
1052 0xfffc, /* dst_mask */
1053 false), /* pcrel_offset */
1055 /* Like R_PPC64_PLT16_LO, but for instructions with a DS field. */
1056 HOWTO (R_PPC64_PLT16_LO_DS
, /* type */
1058 1, /* size (0 = byte, 1 = short, 2 = long) */
1060 false, /* pc_relative */
1062 complain_overflow_dont
, /* complain_on_overflow */
1063 bfd_elf_generic_reloc
, /* special_function */
1064 "R_PPC64_PLT16_LO_DS", /* name */
1065 false, /* partial_inplace */
1067 0xfffc, /* dst_mask */
1068 false), /* pcrel_offset */
1070 /* Like R_PPC64_SECTOFF, but for instructions with a DS field. */
1071 /* FIXME: Verify R_PPC64_SECTOFF. Seems strange with size=2 and
1073 HOWTO (R_PPC64_SECTOFF_DS
, /* type */
1075 2, /* size (0 = byte, 1 = short, 2 = long) */
1077 true, /* pc_relative */
1079 complain_overflow_bitfield
, /* complain_on_overflow */
1080 bfd_elf_generic_reloc
, /* special_function */
1081 "R_PPC64_SECTOFF_DS", /* name */
1082 false, /* partial_inplace */
1085 true), /* pcrel_offset */
1087 /* Like R_PPC64_SECTOFF_LO, but for instructions with a DS field. */
1088 HOWTO (R_PPC64_SECTOFF_LO_DS
, /* type */
1090 1, /* size (0 = byte, 1 = short, 2 = long) */
1092 false, /* pc_relative */
1094 complain_overflow_dont
, /* complain_on_overflow */
1095 bfd_elf_generic_reloc
, /* special_function */
1096 "R_PPC64_SECTOFF_LO_DS",/* name */
1097 false, /* partial_inplace */
1099 0xfffc, /* dst_mask */
1100 false), /* pcrel_offset */
1102 /* Like R_PPC64_TOC16, but for instructions with a DS field. */
1103 HOWTO (R_PPC64_TOC16_DS
, /* type */
1105 1, /* size (0 = byte, 1 = short, 2 = long) */
1107 false, /* pc_relative */
1109 complain_overflow_signed
, /* complain_on_overflow */
1110 bfd_elf_generic_reloc
, /* special_function */
1111 "R_PPC64_TOC16_DS", /* name */
1112 false, /* partial_inplace */
1114 0xfffc, /* dst_mask */
1115 false), /* pcrel_offset */
1117 /* Like R_PPC64_TOC16_LO, but for instructions with a DS field. */
1118 HOWTO (R_PPC64_TOC16_LO_DS
, /* type */
1120 1, /* size (0 = byte, 1 = short, 2 = long) */
1122 false, /* pc_relative */
1124 complain_overflow_dont
, /* complain_on_overflow */
1125 bfd_elf_generic_reloc
, /* special_function */
1126 "R_PPC64_TOC16_LO_DS", /* name */
1127 false, /* partial_inplace */
1129 0xfffc, /* dst_mask */
1130 false), /* pcrel_offset */
1132 /* Like R_PPC64_PLTGOT16, but for instructions with a DS field. */
1133 /* FIXME: R_PPC64_PLTGOT16_DS not implemented. */
1134 HOWTO (R_PPC64_PLTGOT16_DS
, /* type */
1136 1, /* size (0 = byte, 1 = short, 2 = long) */
1138 false, /* pc_relative */
1140 complain_overflow_signed
, /* complain_on_overflow */
1141 bfd_elf_generic_reloc
, /* special_function */
1142 "R_PPC64_PLTGOT16_DS", /* name */
1143 false, /* partial_inplace */
1145 0xfffc, /* dst_mask */
1146 false), /* pcrel_offset */
1148 /* Like R_PPC64_PLTGOT16_LO, but for instructions with a DS field. */
1149 /* FIXME: R_PPC64_PLTGOT16_LO not implemented. */
1150 HOWTO (R_PPC64_PLTGOT16_LO_DS
,/* type */
1152 1, /* size (0 = byte, 1 = short, 2 = long) */
1154 false, /* pc_relative */
1156 complain_overflow_dont
, /* complain_on_overflow */
1157 bfd_elf_generic_reloc
, /* special_function */
1158 "R_PPC64_PLTGOT16_LO_DS",/* name */
1159 false, /* partial_inplace */
1161 0xfffc, /* dst_mask */
1162 false), /* pcrel_offset */
1164 /* GNU extension to record C++ vtable hierarchy. */
1165 HOWTO (R_PPC64_GNU_VTINHERIT
, /* type */
1167 0, /* size (0 = byte, 1 = short, 2 = long) */
1169 false, /* pc_relative */
1171 complain_overflow_dont
, /* complain_on_overflow */
1172 NULL
, /* special_function */
1173 "R_PPC64_GNU_VTINHERIT", /* name */
1174 false, /* partial_inplace */
1177 false), /* pcrel_offset */
1179 /* GNU extension to record C++ vtable member usage. */
1180 HOWTO (R_PPC64_GNU_VTENTRY
, /* type */
1182 0, /* size (0 = byte, 1 = short, 2 = long) */
1184 false, /* pc_relative */
1186 complain_overflow_dont
, /* complain_on_overflow */
1187 NULL
, /* special_function */
1188 "R_PPC64_GNU_VTENTRY", /* name */
1189 false, /* partial_inplace */
1192 false), /* pcrel_offset */
1196 /* Initialize the ppc64_elf_howto_table, so that linear accesses can
1202 unsigned int i
, type
;
1205 i
< sizeof (ppc64_elf_howto_raw
) / sizeof (ppc64_elf_howto_raw
[0]);
1208 type
= ppc64_elf_howto_raw
[i
].type
;
1209 BFD_ASSERT (type
< (sizeof (ppc64_elf_howto_table
)
1210 / sizeof (ppc64_elf_howto_table
[0])));
1211 ppc64_elf_howto_table
[type
] = &ppc64_elf_howto_raw
[i
];
1215 static reloc_howto_type
*
1216 ppc64_elf_reloc_type_lookup (abfd
, code
)
1217 bfd
*abfd ATTRIBUTE_UNUSED
;
1218 bfd_reloc_code_real_type code
;
1220 enum elf_ppc_reloc_type ppc_reloc
= R_PPC_NONE
;
1222 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
1223 /* Initialize howto table if needed. */
1229 return (reloc_howto_type
*) NULL
;
1231 case BFD_RELOC_NONE
: ppc_reloc
= R_PPC64_NONE
;
1233 case BFD_RELOC_32
: ppc_reloc
= R_PPC64_ADDR32
;
1235 case BFD_RELOC_PPC_BA26
: ppc_reloc
= R_PPC64_ADDR24
;
1237 case BFD_RELOC_16
: ppc_reloc
= R_PPC64_ADDR16
;
1239 case BFD_RELOC_LO16
: ppc_reloc
= R_PPC64_ADDR16_LO
;
1241 case BFD_RELOC_HI16
: ppc_reloc
= R_PPC64_ADDR16_HI
;
1243 case BFD_RELOC_HI16_S
: ppc_reloc
= R_PPC64_ADDR16_HA
;
1245 case BFD_RELOC_PPC_BA16
: ppc_reloc
= R_PPC64_ADDR14
;
1247 case BFD_RELOC_PPC_BA16_BRTAKEN
: ppc_reloc
= R_PPC64_ADDR14_BRTAKEN
;
1249 case BFD_RELOC_PPC_BA16_BRNTAKEN
: ppc_reloc
= R_PPC64_ADDR14_BRNTAKEN
;
1251 case BFD_RELOC_PPC_B26
: ppc_reloc
= R_PPC64_REL24
;
1253 case BFD_RELOC_PPC_B16
: ppc_reloc
= R_PPC64_REL14
;
1255 case BFD_RELOC_PPC_B16_BRTAKEN
: ppc_reloc
= R_PPC64_REL14_BRTAKEN
;
1257 case BFD_RELOC_PPC_B16_BRNTAKEN
: ppc_reloc
= R_PPC64_REL14_BRNTAKEN
;
1259 case BFD_RELOC_16_GOTOFF
: ppc_reloc
= R_PPC64_GOT16
;
1261 case BFD_RELOC_LO16_GOTOFF
: ppc_reloc
= R_PPC64_GOT16_LO
;
1263 case BFD_RELOC_HI16_GOTOFF
: ppc_reloc
= R_PPC64_GOT16_HI
;
1265 case BFD_RELOC_HI16_S_GOTOFF
: ppc_reloc
= R_PPC64_GOT16_HA
;
1267 case BFD_RELOC_PPC_COPY
: ppc_reloc
= R_PPC64_COPY
;
1269 case BFD_RELOC_PPC_GLOB_DAT
: ppc_reloc
= R_PPC64_GLOB_DAT
;
1271 case BFD_RELOC_32_PCREL
: ppc_reloc
= R_PPC64_REL32
;
1273 case BFD_RELOC_32_PLTOFF
: ppc_reloc
= R_PPC64_PLT32
;
1275 case BFD_RELOC_32_PLT_PCREL
: ppc_reloc
= R_PPC64_PLTREL32
;
1277 case BFD_RELOC_LO16_PLTOFF
: ppc_reloc
= R_PPC64_PLT16_LO
;
1279 case BFD_RELOC_HI16_PLTOFF
: ppc_reloc
= R_PPC64_PLT16_HI
;
1281 case BFD_RELOC_HI16_S_PLTOFF
: ppc_reloc
= R_PPC64_PLT16_HA
;
1283 case BFD_RELOC_32_BASEREL
: ppc_reloc
= R_PPC64_SECTOFF
;
1285 case BFD_RELOC_LO16_BASEREL
: ppc_reloc
= R_PPC64_SECTOFF_LO
;
1287 case BFD_RELOC_HI16_BASEREL
: ppc_reloc
= R_PPC64_SECTOFF_HI
;
1289 case BFD_RELOC_HI16_S_BASEREL
: ppc_reloc
= R_PPC64_SECTOFF_HA
;
1291 /* FIXME: Is CTOR 32 or 64 bits? Fix md_apply_fix3 in
1292 gas/config/tc-ppc.c too. */
1293 case BFD_RELOC_CTOR
: ppc_reloc
= R_PPC64_ADDR32
;
1295 case BFD_RELOC_64
: ppc_reloc
= R_PPC64_ADDR64
;
1297 case BFD_RELOC_PPC64_HIGHER
: ppc_reloc
= R_PPC64_ADDR16_HIGHER
;
1299 case BFD_RELOC_PPC64_HIGHER_S
: ppc_reloc
= R_PPC64_ADDR16_HIGHERA
;
1301 case BFD_RELOC_PPC64_HIGHEST
: ppc_reloc
= R_PPC64_ADDR16_HIGHEST
;
1303 case BFD_RELOC_PPC64_HIGHEST_S
: ppc_reloc
= R_PPC64_ADDR16_HIGHESTA
;
1305 case BFD_RELOC_64_PCREL
: ppc_reloc
= R_PPC64_REL64
;
1307 case BFD_RELOC_64_PLTOFF
: ppc_reloc
= R_PPC64_PLT64
;
1309 case BFD_RELOC_64_PLT_PCREL
: ppc_reloc
= R_PPC64_PLTREL64
;
1311 case BFD_RELOC_PPC_TOC16
: ppc_reloc
= R_PPC64_TOC16
;
1313 case BFD_RELOC_PPC64_TOC16_LO
: ppc_reloc
= R_PPC64_TOC16_LO
;
1315 case BFD_RELOC_PPC64_TOC16_HI
: ppc_reloc
= R_PPC64_TOC16_HI
;
1317 case BFD_RELOC_PPC64_TOC16_HA
: ppc_reloc
= R_PPC64_TOC16_HA
;
1319 case BFD_RELOC_PPC64_TOC
: ppc_reloc
= R_PPC64_TOC
;
1321 case BFD_RELOC_PPC64_PLTGOT16
: ppc_reloc
= R_PPC64_PLTGOT16
;
1323 case BFD_RELOC_PPC64_PLTGOT16_LO
: ppc_reloc
= R_PPC64_PLTGOT16_LO
;
1325 case BFD_RELOC_PPC64_PLTGOT16_HI
: ppc_reloc
= R_PPC64_PLTGOT16_HI
;
1327 case BFD_RELOC_PPC64_PLTGOT16_HA
: ppc_reloc
= R_PPC64_PLTGOT16_HA
;
1329 case BFD_RELOC_PPC64_ADDR16_DS
: ppc_reloc
= R_PPC64_ADDR16_DS
;
1331 case BFD_RELOC_PPC64_ADDR16_LO_DS
: ppc_reloc
= R_PPC64_ADDR16_LO_DS
;
1333 case BFD_RELOC_PPC64_GOT16_DS
: ppc_reloc
= R_PPC64_GOT16_DS
;
1335 case BFD_RELOC_PPC64_GOT16_LO_DS
: ppc_reloc
= R_PPC64_GOT16_LO_DS
;
1337 case BFD_RELOC_PPC64_PLT16_LO_DS
: ppc_reloc
= R_PPC64_PLT16_LO_DS
;
1339 case BFD_RELOC_PPC64_SECTOFF_DS
: ppc_reloc
= R_PPC64_SECTOFF_DS
;
1341 case BFD_RELOC_PPC64_SECTOFF_LO_DS
: ppc_reloc
= R_PPC64_SECTOFF_LO_DS
;
1343 case BFD_RELOC_PPC64_TOC16_DS
: ppc_reloc
= R_PPC64_TOC16_DS
;
1345 case BFD_RELOC_PPC64_TOC16_LO_DS
: ppc_reloc
= R_PPC64_TOC16_LO_DS
;
1347 case BFD_RELOC_PPC64_PLTGOT16_DS
: ppc_reloc
= R_PPC64_PLTGOT16_DS
;
1349 case BFD_RELOC_PPC64_PLTGOT16_LO_DS
: ppc_reloc
= R_PPC64_PLTGOT16_LO_DS
;
1351 case BFD_RELOC_VTABLE_INHERIT
: ppc_reloc
= R_PPC64_GNU_VTINHERIT
;
1353 case BFD_RELOC_VTABLE_ENTRY
: ppc_reloc
= R_PPC64_GNU_VTENTRY
;
1357 return ppc64_elf_howto_table
[(int) ppc_reloc
];
1360 /* Set the howto pointer for a PowerPC ELF reloc. */
1363 ppc64_elf_info_to_howto (abfd
, cache_ptr
, dst
)
1364 bfd
*abfd ATTRIBUTE_UNUSED
;
1366 Elf64_Internal_Rela
*dst
;
1370 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
1371 /* Initialize howto table if needed. */
1374 type
= ELF64_R_TYPE (dst
->r_info
);
1375 BFD_ASSERT (type
< (sizeof (ppc64_elf_howto_table
)
1376 / sizeof (ppc64_elf_howto_table
[0])));
1377 cache_ptr
->howto
= ppc64_elf_howto_table
[type
];
1380 /* Handle the R_PPC_ADDR16_HA and similar relocs. */
1382 static bfd_reloc_status_type
1383 ppc64_elf_addr16_ha_reloc (abfd
, reloc_entry
, symbol
, data
, input_section
,
1384 output_bfd
, error_message
)
1385 bfd
*abfd ATTRIBUTE_UNUSED
;
1386 arelent
*reloc_entry
;
1388 PTR data ATTRIBUTE_UNUSED
;
1389 asection
*input_section
;
1391 char **error_message ATTRIBUTE_UNUSED
;
1395 if (output_bfd
!= NULL
)
1397 reloc_entry
->address
+= input_section
->output_offset
;
1398 return bfd_reloc_ok
;
1401 if (reloc_entry
->address
> input_section
->_cooked_size
)
1402 return bfd_reloc_outofrange
;
1404 if (bfd_is_com_section (symbol
->section
))
1407 relocation
= symbol
->value
;
1409 relocation
+= symbol
->section
->output_section
->vma
;
1410 relocation
+= symbol
->section
->output_offset
;
1411 relocation
+= reloc_entry
->addend
;
1413 reloc_entry
->addend
+= (relocation
& 0x8000) << 1;
1415 return bfd_reloc_continue
;
1418 /* Function to set whether a module needs the -mrelocatable bit set. */
1421 ppc64_elf_set_private_flags (abfd
, flags
)
1425 BFD_ASSERT (!elf_flags_init (abfd
)
1426 || elf_elfheader (abfd
)->e_flags
== flags
);
1428 elf_elfheader (abfd
)->e_flags
= flags
;
1429 elf_flags_init (abfd
) = true;
1433 /* Copy backend specific data from one object module to another. */
1435 ppc64_elf_copy_private_bfd_data (ibfd
, obfd
)
1439 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
1440 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
1443 BFD_ASSERT (!elf_flags_init (obfd
)
1444 || elf_elfheader (obfd
)->e_flags
== elf_elfheader (ibfd
)->e_flags
);
1446 elf_elfheader (obfd
)->e_flags
= elf_elfheader (ibfd
)->e_flags
;
1447 elf_flags_init (obfd
) = true;
1451 /* Merge backend specific data from an object file to the output
1452 object file when linking. */
1454 ppc64_elf_merge_private_bfd_data (ibfd
, obfd
)
1462 /* Check if we have the same endianess. */
1463 if (ibfd
->xvec
->byteorder
!= obfd
->xvec
->byteorder
1464 && obfd
->xvec
->byteorder
!= BFD_ENDIAN_UNKNOWN
)
1468 if (bfd_big_endian (ibfd
))
1469 msg
= _("%s: compiled for a big endian system and target is little endian");
1471 msg
= _("%s: compiled for a little endian system and target is big endian");
1473 (*_bfd_error_handler
) (msg
, bfd_archive_filename (ibfd
));
1475 bfd_set_error (bfd_error_wrong_format
);
1479 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
1480 || bfd_get_flavour (obfd
) != bfd_target_elf_flavour
)
1483 new_flags
= elf_elfheader (ibfd
)->e_flags
;
1484 old_flags
= elf_elfheader (obfd
)->e_flags
;
1485 if (!elf_flags_init (obfd
))
1487 /* First call, no flags set. */
1488 elf_flags_init (obfd
) = true;
1489 elf_elfheader (obfd
)->e_flags
= new_flags
;
1492 else if (new_flags
== old_flags
)
1493 /* Compatible flags are ok. */
1498 /* Incompatible flags. Warn about -mrelocatable mismatch.
1499 Allow -mrelocatable-lib to be linked with either. */
1501 if ((new_flags
& EF_PPC_RELOCATABLE
) != 0
1502 && (old_flags
& (EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
)) == 0)
1505 (*_bfd_error_handler
)
1506 (_("%s: compiled with -mrelocatable and linked with modules compiled normally"),
1507 bfd_archive_filename (ibfd
));
1509 else if ((new_flags
& (EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
)) == 0
1510 && (old_flags
& EF_PPC_RELOCATABLE
) != 0)
1513 (*_bfd_error_handler
)
1514 (_("%s: compiled normally and linked with modules compiled with -mrelocatable"),
1515 bfd_archive_filename (ibfd
));
1518 /* The output is -mrelocatable-lib iff both the input files are. */
1519 if (! (new_flags
& EF_PPC_RELOCATABLE_LIB
))
1520 elf_elfheader (obfd
)->e_flags
&= ~EF_PPC_RELOCATABLE_LIB
;
1522 /* The output is -mrelocatable iff it can't be -mrelocatable-lib,
1523 but each input file is either -mrelocatable or -mrelocatable-lib. */
1524 if (! (elf_elfheader (obfd
)->e_flags
& EF_PPC_RELOCATABLE_LIB
)
1525 && (new_flags
& (EF_PPC_RELOCATABLE_LIB
| EF_PPC_RELOCATABLE
))
1526 && (old_flags
& (EF_PPC_RELOCATABLE_LIB
| EF_PPC_RELOCATABLE
)))
1527 elf_elfheader (obfd
)->e_flags
|= EF_PPC_RELOCATABLE
;
1529 /* Do not warn about eabi vs. V.4 mismatch, just or in the bit
1530 if any module uses it. */
1531 elf_elfheader (obfd
)->e_flags
|= (new_flags
& EF_PPC_EMB
);
1533 new_flags
&= ~(EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
| EF_PPC_EMB
);
1534 old_flags
&= ~(EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
| EF_PPC_EMB
);
1536 /* Warn about any other mismatches. */
1537 if (new_flags
!= old_flags
)
1540 (*_bfd_error_handler
)
1541 (_("%s: uses different e_flags (0x%lx) fields than previous modules (0x%lx)"),
1542 bfd_archive_filename (ibfd
), (long) new_flags
, (long) old_flags
);
1547 bfd_set_error (bfd_error_bad_value
);
1555 /* Handle a PowerPC specific section when reading an object file. This
1556 is called when elfcode.h finds a section with an unknown type. */
1559 ppc64_elf_section_from_shdr (abfd
, hdr
, name
)
1561 Elf64_Internal_Shdr
*hdr
;
1567 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
))
1570 newsect
= hdr
->bfd_section
;
1571 flags
= bfd_get_section_flags (abfd
, newsect
);
1572 if (hdr
->sh_flags
& SHF_EXCLUDE
)
1573 flags
|= SEC_EXCLUDE
;
1575 if (hdr
->sh_type
== SHT_ORDERED
)
1576 flags
|= SEC_SORT_ENTRIES
;
1578 bfd_set_section_flags (abfd
, newsect
, flags
);
1582 /* The following functions are specific to the ELF linker, while
1583 functions above are used generally. Those named ppc64_elf_* are
1584 called by the main ELF linker code. They appear in this file more
1585 or less in the order in which they are called. eg.
1586 ppc64_elf_check_relocs is called early in the link process,
1587 ppc64_elf_finish_dynamic_sections is one of the last functions
1590 /* The linker needs to keep track of the number of relocs that it
1591 decides to copy as dynamic relocs in check_relocs for each symbol.
1592 This is so that it can later discard them if they are found to be
1593 unnecessary. We store the information in a field extending the
1594 regular ELF linker hash table. */
1596 struct ppc_dyn_relocs
1598 struct ppc_dyn_relocs
*next
;
1600 /* The input section of the reloc. */
1603 /* Total number of relocs copied for the input section. */
1604 bfd_size_type count
;
1606 /* Number of pc-relative relocs copied for the input section. */
1607 bfd_size_type pc_count
;
1610 /* Of those relocs that might be copied as dynamic relocs, this macro
1611 selects between relative and absolute types. */
1613 #define IS_ABSOLUTE_RELOC(RTYPE) \
1614 ((RTYPE) != R_PPC64_REL14 \
1615 && (RTYPE) != R_PPC64_REL14_BRNTAKEN \
1616 && (RTYPE) != R_PPC64_REL14_BRTAKEN \
1617 && (RTYPE) != R_PPC64_REL24 \
1618 && (RTYPE) != R_PPC64_REL32 \
1619 && (RTYPE) != R_PPC64_REL64)
1621 /* ppc64 ELF linker hash entry. */
1623 struct ppc_link_hash_entry
1625 struct elf_link_hash_entry elf
;
1627 /* Track dynamic relocs copied for this symbol. */
1628 struct ppc_dyn_relocs
*dyn_relocs
;
1631 /* ppc64 ELF linker hash table. */
1633 struct ppc_link_hash_table
1635 struct elf_link_hash_table elf
;
1637 /* Short-cuts to get to dynamic linker sections. */
1647 /* Get the ppc64 ELF linker hash table from a link_info structure. */
1649 #define ppc_hash_table(p) \
1650 ((struct ppc_link_hash_table *) ((p)->hash))
1652 /* Create an entry in a ppc64 ELF linker hash table. */
1654 static struct bfd_hash_entry
*
1655 link_hash_newfunc (entry
, table
, string
)
1656 struct bfd_hash_entry
*entry
;
1657 struct bfd_hash_table
*table
;
1660 /* Allocate the structure if it has not already been allocated by a
1664 entry
= bfd_hash_allocate (table
, sizeof (struct ppc_link_hash_entry
));
1669 /* Call the allocation method of the superclass. */
1670 entry
= _bfd_elf_link_hash_newfunc (entry
, table
, string
);
1673 struct ppc_link_hash_entry
*eh
= (struct ppc_link_hash_entry
*) entry
;
1675 eh
->dyn_relocs
= NULL
;
1681 /* Create a ppc64 ELF linker hash table. */
1683 static struct bfd_link_hash_table
*
1684 ppc64_elf_link_hash_table_create (abfd
)
1687 struct ppc_link_hash_table
*htab
;
1688 bfd_size_type amt
= sizeof (struct ppc_link_hash_table
);
1690 htab
= (struct ppc_link_hash_table
*) bfd_alloc (abfd
, amt
);
1694 if (! _bfd_elf_link_hash_table_init (&htab
->elf
, abfd
, link_hash_newfunc
))
1696 bfd_release (abfd
, htab
);
1701 htab
->srelgot
= NULL
;
1703 htab
->srelplt
= NULL
;
1704 htab
->sdynbss
= NULL
;
1705 htab
->srelbss
= NULL
;
1706 htab
->sglink
= NULL
;
1708 return &htab
->elf
.root
;
1711 /* Create .got and .rela.got sections in DYNOBJ, and set up
1712 shortcuts to them in our hash table. */
1715 create_got_section (dynobj
, info
)
1717 struct bfd_link_info
*info
;
1719 struct ppc_link_hash_table
*htab
;
1721 if (! _bfd_elf_create_got_section (dynobj
, info
))
1724 htab
= ppc_hash_table (info
);
1725 htab
->sgot
= bfd_get_section_by_name (dynobj
, ".got");
1729 htab
->srelgot
= bfd_make_section (dynobj
, ".rela.got");
1731 || ! bfd_set_section_flags (dynobj
, htab
->srelgot
,
1732 (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
1733 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
1735 || ! bfd_set_section_alignment (dynobj
, htab
->srelgot
, 3))
1740 /* Create the .glink section as well as the ordinary dynamic
1744 ppc64_elf_create_dynamic_sections (dynobj
, info
)
1746 struct bfd_link_info
*info
;
1748 struct ppc_link_hash_table
*htab
;
1751 htab
= ppc_hash_table (info
);
1752 if (!htab
->sgot
&& !create_got_section (dynobj
, info
))
1755 if (!_bfd_elf_create_dynamic_sections (dynobj
, info
))
1758 htab
->splt
= bfd_get_section_by_name (dynobj
, ".plt");
1759 htab
->srelplt
= bfd_get_section_by_name (dynobj
, ".rela.plt");
1760 htab
->sdynbss
= bfd_get_section_by_name (dynobj
, ".dynbss");
1762 htab
->srelbss
= bfd_get_section_by_name (dynobj
, ".rela.bss");
1764 if (!htab
->splt
|| !htab
->srelplt
|| !htab
->sdynbss
1765 || (!info
->shared
&& !htab
->srelbss
))
1768 /* Our .plt just contains pointers, no code. */
1769 flags
= bfd_get_section_flags (dynobj
, htab
->splt
);
1771 if (! bfd_set_section_flags (dynobj
, htab
->splt
, flags
))
1774 /* Create .glink for global linkage functions. */
1775 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
1776 | SEC_LINKER_CREATED
);
1777 htab
->sglink
= bfd_make_section (dynobj
, ".glink");
1778 if (htab
->sglink
== NULL
1779 || ! bfd_set_section_flags (dynobj
, htab
->sglink
, flags
)
1780 || ! bfd_set_section_alignment (dynobj
, htab
->sglink
, 3))
1786 /* Copy the extra info we tack onto an elf_link_hash_entry. */
1789 ppc64_elf_copy_indirect_symbol (dir
, ind
)
1790 struct elf_link_hash_entry
*dir
, *ind
;
1792 struct ppc_link_hash_entry
*edir
, *eind
;
1794 edir
= (struct ppc_link_hash_entry
*) dir
;
1795 eind
= (struct ppc_link_hash_entry
*) ind
;
1797 if (eind
->dyn_relocs
!= NULL
)
1799 if (edir
->dyn_relocs
!= NULL
)
1801 struct ppc_dyn_relocs
**pp
;
1802 struct ppc_dyn_relocs
*p
;
1804 if (ind
->root
.type
== bfd_link_hash_indirect
)
1807 /* Add reloc counts against the weak sym to the strong sym
1808 list. Merge any entries against the same section. */
1809 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
; )
1811 struct ppc_dyn_relocs
*q
;
1813 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
1814 if (q
->sec
== p
->sec
)
1816 q
->pc_count
+= p
->pc_count
;
1817 q
->count
+= p
->count
;
1824 *pp
= edir
->dyn_relocs
;
1827 edir
->dyn_relocs
= eind
->dyn_relocs
;
1828 eind
->dyn_relocs
= NULL
;
1831 _bfd_elf_link_hash_copy_indirect (dir
, ind
);
1834 /* Look through the relocs for a section during the first phase, and
1835 calculate needed space in the global offset table, procedure
1836 linkage table, and dynamic reloc sections. */
1839 ppc64_elf_check_relocs (abfd
, info
, sec
, relocs
)
1841 struct bfd_link_info
*info
;
1843 const Elf_Internal_Rela
*relocs
;
1845 struct ppc_link_hash_table
*htab
;
1846 Elf_Internal_Shdr
*symtab_hdr
;
1847 struct elf_link_hash_entry
**sym_hashes
, **sym_hashes_end
;
1848 const Elf_Internal_Rela
*rel
;
1849 const Elf_Internal_Rela
*rel_end
;
1852 if (info
->relocateable
)
1855 htab
= ppc_hash_table (info
);
1856 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
1858 sym_hashes
= elf_sym_hashes (abfd
);
1859 sym_hashes_end
= (sym_hashes
1860 + symtab_hdr
->sh_size
/ sizeof (Elf64_External_Sym
));
1861 if (!elf_bad_symtab (abfd
))
1862 sym_hashes_end
-= symtab_hdr
->sh_info
;
1866 rel_end
= relocs
+ sec
->reloc_count
;
1867 for (rel
= relocs
; rel
< rel_end
; rel
++)
1869 unsigned long r_symndx
;
1870 struct elf_link_hash_entry
*h
;
1871 enum elf_ppc_reloc_type r_type
;
1873 r_symndx
= ELF64_R_SYM (rel
->r_info
);
1874 if (r_symndx
< symtab_hdr
->sh_info
)
1877 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1879 r_type
= (enum elf_ppc_reloc_type
) ELF64_R_TYPE (rel
->r_info
);
1882 /* GOT16 relocations */
1884 case R_PPC64_GOT16_DS
:
1885 case R_PPC64_GOT16_HA
:
1886 case R_PPC64_GOT16_HI
:
1887 case R_PPC64_GOT16_LO
:
1888 case R_PPC64_GOT16_LO_DS
:
1890 /* This symbol requires a global offset table entry. */
1891 if (htab
->sgot
== NULL
)
1893 if (htab
->elf
.dynobj
== NULL
)
1894 htab
->elf
.dynobj
= abfd
;
1895 if (!create_got_section (htab
->elf
.dynobj
, info
))
1901 h
->got
.refcount
+= 1;
1905 bfd_signed_vma
*local_got_refcounts
;
1907 /* This is a global offset table entry for a local symbol. */
1908 local_got_refcounts
= elf_local_got_refcounts (abfd
);
1909 if (local_got_refcounts
== NULL
)
1913 size
= symtab_hdr
->sh_info
;
1914 size
*= sizeof (bfd_signed_vma
);
1915 local_got_refcounts
= ((bfd_signed_vma
*)
1916 bfd_zalloc (abfd
, size
));
1917 if (local_got_refcounts
== NULL
)
1919 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
1921 local_got_refcounts
[r_symndx
] += 1;
1925 case R_PPC64_PLT16_HA
:
1926 case R_PPC64_PLT16_HI
:
1927 case R_PPC64_PLT16_LO
:
1930 /* This symbol requires a procedure linkage table entry. We
1931 actually build the entry in adjust_dynamic_symbol,
1932 because this might be a case of linking PIC code without
1933 linking in any dynamic objects, in which case we don't
1934 need to generate a procedure linkage table after all. */
1937 /* It does not make sense to have a procedure linkage
1938 table entry for a local symbol. */
1939 bfd_set_error (bfd_error_bad_value
);
1943 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
1944 h
->plt
.refcount
+= 1;
1947 /* The following relocations don't need to propagate the
1948 relocation if linking a shared object since they are
1949 section relative. */
1950 case R_PPC64_SECTOFF
:
1951 case R_PPC64_SECTOFF_LO
:
1952 case R_PPC64_SECTOFF_HI
:
1953 case R_PPC64_SECTOFF_HA
:
1954 case R_PPC64_SECTOFF_DS
:
1955 case R_PPC64_SECTOFF_LO_DS
:
1957 case R_PPC64_TOC16_LO
:
1958 case R_PPC64_TOC16_HI
:
1959 case R_PPC64_TOC16_HA
:
1960 case R_PPC64_TOC16_DS
:
1961 case R_PPC64_TOC16_LO_DS
:
1964 /* This relocation describes the C++ object vtable hierarchy.
1965 Reconstruct it for later use during GC. */
1966 case R_PPC64_GNU_VTINHERIT
:
1967 if (!_bfd_elf64_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
1971 /* This relocation describes which C++ vtable entries are actually
1972 used. Record for later use during GC. */
1973 case R_PPC64_GNU_VTENTRY
:
1974 if (!_bfd_elf64_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
1982 case R_PPC64_REL14_BRTAKEN
:
1983 case R_PPC64_REL14_BRNTAKEN
:
1984 case R_PPC64_ADDR14
:
1985 case R_PPC64_ADDR14_BRNTAKEN
:
1986 case R_PPC64_ADDR14_BRTAKEN
:
1987 case R_PPC64_ADDR16
:
1988 case R_PPC64_ADDR16_DS
:
1989 case R_PPC64_ADDR16_HA
:
1990 case R_PPC64_ADDR16_HI
:
1991 case R_PPC64_ADDR16_HIGHER
:
1992 case R_PPC64_ADDR16_HIGHERA
:
1993 case R_PPC64_ADDR16_HIGHEST
:
1994 case R_PPC64_ADDR16_HIGHESTA
:
1995 case R_PPC64_ADDR16_LO
:
1996 case R_PPC64_ADDR16_LO_DS
:
1997 case R_PPC64_ADDR24
:
1998 case R_PPC64_ADDR30
:
1999 case R_PPC64_ADDR32
:
2000 case R_PPC64_ADDR64
:
2001 case R_PPC64_UADDR16
:
2002 case R_PPC64_UADDR32
:
2003 case R_PPC64_UADDR64
:
2005 /* If we are creating a shared library, and this is a reloc
2006 against a global symbol, or a non PC relative reloc
2007 against a local symbol, then we need to copy the reloc
2008 into the shared library. However, if we are linking with
2009 -Bsymbolic, we do not need to copy a reloc against a
2010 global symbol which is defined in an object we are
2011 including in the link (i.e., DEF_REGULAR is set). At
2012 this point we have not seen all the input files, so it is
2013 possible that DEF_REGULAR is not set now but will be set
2014 later (it is never cleared). In case of a weak definition,
2015 DEF_REGULAR may be cleared later by a strong definition in
2016 a shared library. We account for that possibility below by
2017 storing information in the relocs_copied field of the hash
2018 table entry. A similar situation occurs when creating
2019 shared libraries and symbol visibility changes render the
2022 If on the other hand, we are creating an executable, we
2023 may need to keep relocations for symbols satisfied by a
2024 dynamic library if we manage to avoid copy relocs for the
2027 && (sec
->flags
& SEC_ALLOC
) != 0
2028 && (IS_ABSOLUTE_RELOC (r_type
)
2030 && (! info
->symbolic
2031 || h
->root
.type
== bfd_link_hash_defweak
2032 || (h
->elf_link_hash_flags
2033 & ELF_LINK_HASH_DEF_REGULAR
) == 0))))
2035 && (sec
->flags
& SEC_ALLOC
) != 0
2037 && (h
->root
.type
== bfd_link_hash_defweak
2038 || (h
->elf_link_hash_flags
2039 & ELF_LINK_HASH_DEF_REGULAR
) == 0)))
2041 /* We must copy these reloc types into the output file.
2042 Create a reloc section in dynobj and make room for
2049 name
= (bfd_elf_string_from_elf_section
2051 elf_elfheader (abfd
)->e_shstrndx
,
2052 elf_section_data (sec
)->rel_hdr
.sh_name
));
2056 if (strncmp (name
, ".rela", 5) != 0
2057 || strcmp (bfd_get_section_name (abfd
, sec
),
2060 (*_bfd_error_handler
)
2061 (_("%s: bad relocation section name `%s\'"),
2062 bfd_archive_filename (abfd
), name
);
2065 if (htab
->elf
.dynobj
== NULL
)
2066 htab
->elf
.dynobj
= abfd
;
2068 dynobj
= htab
->elf
.dynobj
;
2069 sreloc
= bfd_get_section_by_name (dynobj
, name
);
2074 sreloc
= bfd_make_section (dynobj
, name
);
2075 flags
= (SEC_HAS_CONTENTS
| SEC_READONLY
2076 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
2077 if ((sec
->flags
& SEC_ALLOC
) != 0)
2078 flags
|= SEC_ALLOC
| SEC_LOAD
;
2080 || ! bfd_set_section_flags (dynobj
, sreloc
, flags
)
2081 || ! bfd_set_section_alignment (dynobj
, sreloc
, 3))
2084 elf_section_data (sec
)->sreloc
= sreloc
;
2087 /* If this is a global symbol, we count the number of
2088 relocations we need for this symbol. */
2091 struct ppc_link_hash_entry
*eh
;
2092 struct ppc_dyn_relocs
*p
;
2094 eh
= (struct ppc_link_hash_entry
*) h
;
2097 if (p
== NULL
|| p
->sec
!= sec
)
2099 p
= ((struct ppc_dyn_relocs
*)
2100 bfd_alloc (htab
->elf
.dynobj
,
2101 (bfd_size_type
) sizeof *p
));
2104 p
->next
= eh
->dyn_relocs
;
2112 if (!IS_ABSOLUTE_RELOC (r_type
))
2117 /* Track dynamic relocs needed for local syms too. */
2118 elf_section_data (sec
)->local_dynrel
+= 1;
2130 /* Return the section that should be marked against GC for a given
2134 ppc64_elf_gc_mark_hook (abfd
, info
, rel
, h
, sym
)
2136 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
2137 Elf_Internal_Rela
*rel
;
2138 struct elf_link_hash_entry
*h
;
2139 Elf_Internal_Sym
*sym
;
2143 enum elf_ppc_reloc_type r_type
;
2145 r_type
= (enum elf_ppc_reloc_type
) ELF64_R_TYPE (rel
->r_info
);
2148 case R_PPC64_GNU_VTINHERIT
:
2149 case R_PPC64_GNU_VTENTRY
:
2153 switch (h
->root
.type
)
2155 case bfd_link_hash_defined
:
2156 case bfd_link_hash_defweak
:
2157 return h
->root
.u
.def
.section
;
2159 case bfd_link_hash_common
:
2160 return h
->root
.u
.c
.p
->section
;
2169 if (! (elf_bad_symtab (abfd
)
2170 && ELF_ST_BIND (sym
->st_info
) != STB_LOCAL
)
2171 && ! ((sym
->st_shndx
<= 0 || sym
->st_shndx
>= SHN_LORESERVE
)
2172 && sym
->st_shndx
!= SHN_COMMON
))
2174 return bfd_section_from_elf_index (abfd
, sym
->st_shndx
);
2181 /* Update the .got, .plt. and dynamic reloc reference counts for the
2182 section being removed. */
2185 ppc64_elf_gc_sweep_hook (abfd
, info
, sec
, relocs
)
2187 struct bfd_link_info
*info ATTRIBUTE_UNUSED
;
2189 const Elf_Internal_Rela
*relocs
;
2191 Elf_Internal_Shdr
*symtab_hdr
;
2192 struct elf_link_hash_entry
**sym_hashes
;
2193 bfd_signed_vma
*local_got_refcounts
;
2194 const Elf_Internal_Rela
*rel
, *relend
;
2196 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
2197 sym_hashes
= elf_sym_hashes (abfd
);
2198 local_got_refcounts
= elf_local_got_refcounts (abfd
);
2200 relend
= relocs
+ sec
->reloc_count
;
2201 for (rel
= relocs
; rel
< relend
; rel
++)
2203 unsigned long r_symndx
;
2204 enum elf_ppc_reloc_type r_type
;
2205 struct elf_link_hash_entry
*h
;
2207 r_symndx
= ELF64_R_SYM (rel
->r_info
);
2208 r_type
= (enum elf_ppc_reloc_type
) ELF64_R_TYPE (rel
->r_info
);
2212 case R_PPC64_GOT16_DS
:
2213 case R_PPC64_GOT16_HA
:
2214 case R_PPC64_GOT16_HI
:
2215 case R_PPC64_GOT16_LO
:
2216 case R_PPC64_GOT16_LO_DS
:
2217 if (r_symndx
>= symtab_hdr
->sh_info
)
2219 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2220 if (h
->got
.refcount
> 0)
2225 if (local_got_refcounts
[r_symndx
] > 0)
2226 local_got_refcounts
[r_symndx
]--;
2230 case R_PPC64_PLT16_HA
:
2231 case R_PPC64_PLT16_HI
:
2232 case R_PPC64_PLT16_LO
:
2235 if (r_symndx
>= symtab_hdr
->sh_info
)
2237 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2238 if (h
->plt
.refcount
> 0)
2244 case R_PPC64_REL14_BRNTAKEN
:
2245 case R_PPC64_REL14_BRTAKEN
:
2249 if (r_symndx
>= symtab_hdr
->sh_info
)
2251 struct ppc_link_hash_entry
*eh
;
2252 struct ppc_dyn_relocs
**pp
;
2253 struct ppc_dyn_relocs
*p
;
2255 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2256 eh
= (struct ppc_link_hash_entry
*) h
;
2258 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; pp
= &p
->next
)
2270 case R_PPC64_ADDR14
:
2271 case R_PPC64_ADDR14_BRNTAKEN
:
2272 case R_PPC64_ADDR14_BRTAKEN
:
2273 case R_PPC64_ADDR16
:
2274 case R_PPC64_ADDR16_DS
:
2275 case R_PPC64_ADDR16_HA
:
2276 case R_PPC64_ADDR16_HI
:
2277 case R_PPC64_ADDR16_HIGHER
:
2278 case R_PPC64_ADDR16_HIGHERA
:
2279 case R_PPC64_ADDR16_HIGHEST
:
2280 case R_PPC64_ADDR16_HIGHESTA
:
2281 case R_PPC64_ADDR16_LO
:
2282 case R_PPC64_ADDR16_LO_DS
:
2283 case R_PPC64_ADDR24
:
2284 case R_PPC64_ADDR30
:
2285 case R_PPC64_ADDR32
:
2286 case R_PPC64_ADDR64
:
2287 case R_PPC64_UADDR16
:
2288 case R_PPC64_UADDR32
:
2289 case R_PPC64_UADDR64
:
2291 if (r_symndx
>= symtab_hdr
->sh_info
)
2293 struct ppc_link_hash_entry
*eh
;
2294 struct ppc_dyn_relocs
**pp
;
2295 struct ppc_dyn_relocs
*p
;
2297 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2298 eh
= (struct ppc_link_hash_entry
*) h
;
2300 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; pp
= &p
->next
)
2318 /* Adjust a symbol defined by a dynamic object and referenced by a
2319 regular object. The current definition is in some section of the
2320 dynamic object, but we're not including those sections. We have to
2321 change the definition to something the rest of the link can
2325 ppc64_elf_adjust_dynamic_symbol (info
, h
)
2326 struct bfd_link_info
*info
;
2327 struct elf_link_hash_entry
*h
;
2329 struct ppc_link_hash_table
*htab
;
2330 struct ppc_link_hash_entry
* eh
;
2331 struct ppc_dyn_relocs
*p
;
2333 unsigned int power_of_two
;
2335 htab
= ppc_hash_table (info
);
2337 /* If this is a function, put it in the procedure linkage table. We
2338 will fill in the contents of the procedure linkage table later. */
2339 if (h
->type
== STT_FUNC
2340 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
2342 struct elf_link_hash_entry
*fdh
;
2344 /* If it's a function entry point, the name starts with a dot
2345 unless someone has written some poor assembly code. The ABI
2346 for .plt calls requires that there be a function descriptor
2347 sym which has the name of the function minus the dot. */
2349 if (h
->plt
.refcount
<= 0
2350 || h
->root
.root
.string
[0] != '.'
2351 || h
->root
.root
.string
[1] == '\0'
2353 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) == 0
2354 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_REF_DYNAMIC
) == 0))
2356 /* This case can occur if we saw a PLT reloc in an input
2357 file, but the symbol was never referred to by a dynamic
2358 object, or if all references were garbage collected. In
2359 such a case, we don't actually need to build a procedure
2360 linkage table entry. */
2361 h
->plt
.offset
= (bfd_vma
) -1;
2362 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
2366 /* Find the corresponding function descriptor symbol. Create it
2367 as undefined if necessary. ppc_elf64_finish_dynamic_symbol
2368 will look it up again and create a JMP_SLOT reloc for it. */
2370 fdh
= elf_link_hash_lookup (elf_hash_table (info
),
2371 h
->root
.root
.string
+ 1,
2372 false, false, false);
2378 /* Create it as undefined. */
2379 newsym
= bfd_make_empty_symbol (htab
->elf
.dynobj
);
2380 newsym
->name
= h
->root
.root
.string
+ 1;
2381 newsym
->section
= bfd_und_section_ptr
;
2383 newsym
->flags
= BSF_DYNAMIC
| BSF_OBJECT
;
2385 if ( !(_bfd_generic_link_add_one_symbol
2386 (info
, htab
->elf
.dynobj
, newsym
->name
, newsym
->flags
,
2387 newsym
->section
, newsym
->value
, NULL
, false, false,
2388 (struct bfd_link_hash_entry
**) &fdh
)))
2396 h
->plt
.offset
= (bfd_vma
) -1;
2398 /* If this is a weak symbol, and there is a real definition, the
2399 processor independent code will have arranged for us to see the
2400 real definition first, and we can just use the same value. */
2401 if (h
->weakdef
!= NULL
)
2403 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
2404 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
2405 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
2406 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
2410 /* This is a reference to a symbol defined by a dynamic object which
2411 is not a function. */
2413 /* If we are creating a shared library, we must presume that the
2414 only references to the symbol are via the global offset table.
2415 For such cases we need not do anything here; the relocations will
2416 be handled correctly by relocate_section. */
2420 /* If there are no references to this symbol that do not use the
2421 GOT, we don't need to generate a copy reloc. */
2422 if ((h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0)
2425 eh
= (struct ppc_link_hash_entry
*) h
;
2426 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
2428 s
= p
->sec
->output_section
;
2429 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
2433 /* If we didn't find any dynamic relocs in read-only sections, then
2434 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
2437 h
->elf_link_hash_flags
&= ~ELF_LINK_NON_GOT_REF
;
2441 /* We must allocate the symbol in our .dynbss section, which will
2442 become part of the .bss section of the executable. There will be
2443 an entry for this symbol in the .dynsym section. The dynamic
2444 object will contain position independent code, so all references
2445 from the dynamic object to this symbol will go through the global
2446 offset table. The dynamic linker will use the .dynsym entry to
2447 determine the address it must put in the global offset table, so
2448 both the dynamic object and the regular object will refer to the
2449 same memory location for the variable. */
2451 /* We must generate a R_PPC_COPY reloc to tell the dynamic linker to
2452 copy the initial value out of the dynamic object and into the
2453 runtime process image. We need to remember the offset into the
2454 .rela.bss section we are going to use. */
2455 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
2457 htab
->srelbss
->_raw_size
+= sizeof (Elf64_External_Rela
);
2458 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_COPY
;
2461 /* We need to figure out the alignment required for this symbol. I
2462 have no idea how ELF linkers handle this. */
2463 power_of_two
= bfd_log2 (h
->size
);
2464 if (power_of_two
> 4)
2467 /* Apply the required alignment. */
2469 s
->_raw_size
= BFD_ALIGN (s
->_raw_size
, (bfd_size_type
) (1 << power_of_two
));
2470 if (power_of_two
> bfd_get_section_alignment (htab
->elf
.dynobj
, s
))
2472 if (! bfd_set_section_alignment (htab
->elf
.dynobj
, s
, power_of_two
))
2476 /* Define the symbol as being at this point in the section. */
2477 h
->root
.u
.def
.section
= s
;
2478 h
->root
.u
.def
.value
= s
->_raw_size
;
2480 /* Increment the section size to make room for the symbol. */
2481 s
->_raw_size
+= h
->size
;
2486 /* This is the condition under which ppc64_elf_finish_dynamic_symbol
2487 will be called from elflink.h. If elflink.h doesn't call our
2488 finish_dynamic_symbol routine, we'll need to do something about
2489 initializing any .plt and .got entries in ppc64_elf_relocate_section. */
2490 #define WILL_CALL_FINISH_DYNAMIC_SYMBOL(DYN, INFO, H) \
2492 && ((INFO)->shared \
2493 || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) \
2494 && ((H)->dynindx != -1 \
2495 || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0))
2497 /* Allocate space in .plt, .got and associated reloc sections for
2501 allocate_dynrelocs (h
, inf
)
2502 struct elf_link_hash_entry
*h
;
2505 struct bfd_link_info
*info
;
2506 struct ppc_link_hash_table
*htab
;
2508 struct ppc_link_hash_entry
*eh
;
2509 struct ppc_dyn_relocs
*p
;
2511 if (h
->root
.type
== bfd_link_hash_indirect
2512 || h
->root
.type
== bfd_link_hash_warning
)
2515 info
= (struct bfd_link_info
*) inf
;
2516 htab
= ppc_hash_table (info
);
2518 if (htab
->elf
.dynamic_sections_created
2519 && h
->plt
.refcount
> 0)
2521 /* Make sure this symbol is output as a dynamic symbol.
2522 Undefined weak syms won't yet be marked as dynamic. */
2523 if (h
->dynindx
== -1
2524 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
2526 if (! bfd_elf64_link_record_dynamic_symbol (info
, h
))
2530 BFD_ASSERT (h
->root
.root
.string
[0] == '.'
2531 && h
->root
.root
.string
[1] != '\0');
2533 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, info
, h
))
2535 /* Make sure the corresponding function descriptor symbol is
2538 if (h
->dynindx
!= -1)
2540 struct elf_link_hash_entry
*fdh
;
2542 fdh
= elf_link_hash_lookup (elf_hash_table (info
),
2543 h
->root
.root
.string
+ 1,
2544 false, false, false);
2549 if (fdh
->dynindx
== -1
2550 && (fdh
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
2552 if (! bfd_elf64_link_record_dynamic_symbol (info
, fdh
))
2557 /* If this is the first .plt entry, make room for the special
2560 if (s
->_raw_size
== 0)
2561 s
->_raw_size
+= PLT_INITIAL_ENTRY_SIZE
;
2563 h
->plt
.offset
= s
->_raw_size
;
2565 /* Make room for this entry. */
2566 s
->_raw_size
+= PLT_ENTRY_SIZE
;
2568 /* Point the function at the linkage stub. This works because
2569 the only references to the function code sym are calls.
2570 Function pointer comparisons use the function descriptor. */
2572 h
->root
.type
= bfd_link_hash_defined
;
2573 h
->root
.u
.def
.section
= s
;
2574 h
->root
.u
.def
.value
= s
->_raw_size
;
2575 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
2577 /* Make room for global linkage code in .glink. */
2578 s
->_raw_size
+= PPC64_ELF_GLINK_SIZE
;
2580 /* We also need to make an entry in the .rela.plt section. */
2582 s
->_raw_size
+= sizeof (Elf64_External_Rela
);
2586 h
->plt
.offset
= (bfd_vma
) -1;
2587 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
2592 h
->plt
.offset
= (bfd_vma
) -1;
2593 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
2596 if (h
->got
.refcount
> 0)
2600 /* Make sure this symbol is output as a dynamic symbol.
2601 Undefined weak syms won't yet be marked as dynamic. */
2602 if (h
->dynindx
== -1
2603 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
2605 if (! bfd_elf64_link_record_dynamic_symbol (info
, h
))
2610 h
->got
.offset
= s
->_raw_size
;
2612 dyn
= htab
->elf
.dynamic_sections_created
;
2613 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
, h
))
2614 htab
->srelgot
->_raw_size
+= sizeof (Elf64_External_Rela
);
2617 h
->got
.offset
= (bfd_vma
) -1;
2619 eh
= (struct ppc_link_hash_entry
*) h
;
2620 if (eh
->dyn_relocs
== NULL
)
2623 /* In the shared -Bsymbolic case, discard space allocated for
2624 dynamic pc-relative relocs against symbols which turn out to be
2625 defined in regular objects. For the normal shared case, discard
2626 space for relocs that have become local due to symbol visibility
2631 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) != 0
2632 && ((h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) != 0
2635 struct ppc_dyn_relocs
**pp
;
2637 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
2639 p
->count
-= p
->pc_count
;
2650 /* For the non-shared case, discard space for relocs against
2651 symbols which turn out to need copy relocs or are not
2654 if ((h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0
2655 && (((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
2656 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
2657 || (htab
->elf
.dynamic_sections_created
2658 && (h
->root
.type
== bfd_link_hash_undefweak
2659 || h
->root
.type
== bfd_link_hash_undefined
))))
2661 /* Make sure this symbol is output as a dynamic symbol.
2662 Undefined weak syms won't yet be marked as dynamic. */
2663 if (h
->dynindx
== -1
2664 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
2666 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
2670 /* If that succeeded, we know we'll be keeping all the
2672 if (h
->dynindx
!= -1)
2676 eh
->dyn_relocs
= NULL
;
2681 /* Finally, allocate space. */
2682 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
2684 asection
*sreloc
= elf_section_data (p
->sec
)->sreloc
;
2685 sreloc
->_raw_size
+= p
->count
* sizeof (Elf64_External_Rela
);
2691 /* Find any dynamic relocs that apply to read-only sections. */
2694 readonly_dynrelocs (h
, inf
)
2695 struct elf_link_hash_entry
*h
;
2698 struct ppc_link_hash_entry
*eh
;
2699 struct ppc_dyn_relocs
*p
;
2701 eh
= (struct ppc_link_hash_entry
*) h
;
2702 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
2704 asection
*s
= p
->sec
->output_section
;
2706 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
2708 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
2710 info
->flags
|= DF_TEXTREL
;
2712 /* Not an error, just cut short the traversal. */
2719 /* Set the sizes of the dynamic sections. */
2722 ppc64_elf_size_dynamic_sections (output_bfd
, info
)
2723 bfd
*output_bfd ATTRIBUTE_UNUSED
;
2724 struct bfd_link_info
*info
;
2726 struct ppc_link_hash_table
*htab
;
2732 htab
= ppc_hash_table (info
);
2733 dynobj
= htab
->elf
.dynobj
;
2737 if (htab
->elf
.dynamic_sections_created
)
2739 /* Set the contents of the .interp section to the interpreter. */
2742 s
= bfd_get_section_by_name (dynobj
, ".interp");
2745 s
->_raw_size
= sizeof ELF_DYNAMIC_INTERPRETER
;
2746 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
2750 /* Set up .got offsets for local syms, and space for local dynamic
2752 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
2754 bfd_signed_vma
*local_got
;
2755 bfd_signed_vma
*end_local_got
;
2756 bfd_size_type locsymcount
;
2757 Elf_Internal_Shdr
*symtab_hdr
;
2760 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
)
2763 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
2765 bfd_size_type count
= elf_section_data (s
)->local_dynrel
;
2769 srel
= elf_section_data (s
)->sreloc
;
2770 srel
->_raw_size
+= count
* sizeof (Elf64_External_Rela
);
2774 local_got
= elf_local_got_refcounts (ibfd
);
2778 symtab_hdr
= &elf_tdata (ibfd
)->symtab_hdr
;
2779 locsymcount
= symtab_hdr
->sh_info
;
2780 end_local_got
= local_got
+ locsymcount
;
2782 srel
= htab
->srelgot
;
2783 for (; local_got
< end_local_got
; ++local_got
)
2787 *local_got
= s
->_raw_size
;
2790 srel
->_raw_size
+= sizeof (Elf64_External_Rela
);
2793 *local_got
= (bfd_vma
) -1;
2797 /* Allocate global sym .plt and .got entries, and space for global
2798 sym dynamic relocs. */
2799 elf_link_hash_traverse (&htab
->elf
, allocate_dynrelocs
, (PTR
) info
);
2801 /* We now have determined the sizes of the various dynamic sections.
2802 Allocate memory for them. */
2804 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
2806 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
2811 || s
== htab
->sglink
)
2813 /* Strip this section if we don't need it; see the
2816 else if (strncmp (bfd_get_section_name (dynobj
, s
), ".rela", 5) == 0)
2818 if (s
->_raw_size
== 0)
2820 /* If we don't need this section, strip it from the
2821 output file. This is mostly to handle .rela.bss and
2822 .rela.plt. We must create both sections in
2823 create_dynamic_sections, because they must be created
2824 before the linker maps input sections to output
2825 sections. The linker does that before
2826 adjust_dynamic_symbol is called, and it is that
2827 function which decides whether anything needs to go
2828 into these sections. */
2832 if (s
!= htab
->srelplt
)
2835 /* We use the reloc_count field as a counter if we need
2836 to copy relocs into the output file. */
2842 /* It's not one of our sections, so don't allocate space. */
2846 if (s
->_raw_size
== 0)
2848 _bfd_strip_section_from_output (info
, s
);
2852 /* Allocate memory for the section contents. We use bfd_zalloc
2853 here in case unused entries are not reclaimed before the
2854 section's contents are written out. This should not happen,
2855 but this way if it does, we get a R_PPC64_NONE reloc instead
2857 s
->contents
= (bfd_byte
*) bfd_zalloc (dynobj
, s
->_raw_size
);
2858 if (s
->contents
== NULL
)
2862 if (elf_hash_table (info
)->dynamic_sections_created
)
2864 /* Add some entries to the .dynamic section. We fill in the
2865 values later, in ppc64_elf_finish_dynamic_sections, but we
2866 must add the entries now so that we get the correct size for
2867 the .dynamic section. The DT_DEBUG entry is filled in by the
2868 dynamic linker and used by the debugger. */
2869 #define add_dynamic_entry(TAG, VAL) \
2870 bfd_elf64_add_dynamic_entry (info, (bfd_vma) (TAG), (bfd_vma) (VAL))
2874 if (!add_dynamic_entry (DT_DEBUG
, 0))
2878 if (htab
->splt
->_raw_size
!= 0)
2880 if (!add_dynamic_entry (DT_PLTGOT
, 0)
2881 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
2882 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
2883 || !add_dynamic_entry (DT_JMPREL
, 0))
2889 if (!add_dynamic_entry (DT_RELA
, 0)
2890 || !add_dynamic_entry (DT_RELASZ
, 0)
2891 || !add_dynamic_entry (DT_RELAENT
, sizeof (Elf64_External_Rela
)))
2894 /* If any dynamic relocs apply to a read-only section,
2895 then we need a DT_TEXTREL entry. */
2896 elf_link_hash_traverse (&htab
->elf
, readonly_dynrelocs
, (PTR
) info
);
2898 if ((info
->flags
& DF_TEXTREL
) != 0)
2900 if (!add_dynamic_entry (DT_TEXTREL
, 0))
2905 #undef add_dynamic_entry
2910 /* Called after we have seen all the input files/sections, but before
2911 final symbol resolution and section placement has been determined.
2913 We use this hook to provide a value for TOCstart, which we store in
2914 the output bfd elf_gp, then we call the generic ELF final link
2918 ppc64_elf_final_link (abfd
, info
)
2920 struct bfd_link_info
*info
;
2922 if (! info
->relocateable
)
2927 /* The TOC consists of sections .got, .toc, .tocbss, .plt in this
2928 order. The TOC starts where the first of these sections starts. */
2929 s
= bfd_get_section_by_name (abfd
, ".got");
2931 s
= bfd_get_section_by_name (abfd
, ".toc");
2933 s
= bfd_get_section_by_name (abfd
, ".tocbss");
2935 s
= bfd_get_section_by_name (abfd
, ".plt");
2938 /* This may happen for
2939 o references to TOC base (SYM@toc / TOC[tc0]) without a
2942 o --gc-sections and empty TOC sections
2944 FIXME: Warn user? */
2946 /* Look for a likely section. We probably won't even be
2948 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
2949 if ((s
->flags
& (SEC_ALLOC
| SEC_SMALL_DATA
| SEC_READONLY
))
2950 == (SEC_ALLOC
| SEC_SMALL_DATA
))
2953 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
2954 if ((s
->flags
& (SEC_ALLOC
| SEC_SMALL_DATA
))
2955 == (SEC_ALLOC
| SEC_SMALL_DATA
))
2958 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
2959 if ((s
->flags
& (SEC_ALLOC
| SEC_READONLY
)) == SEC_ALLOC
)
2962 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
2963 if ((s
->flags
& SEC_ALLOC
) == SEC_ALLOC
)
2969 TOCstart
= s
->output_section
->vma
+ s
->output_offset
;
2971 elf_gp (abfd
) = TOCstart
;
2974 /* Invoke the regular ELF backend linker to do all the work. */
2975 return bfd_elf64_bfd_final_link (abfd
, info
);
2978 /* Set up any other section flags and such that may be necessary. */
2981 ppc64_elf_fake_sections (abfd
, shdr
, asect
)
2982 bfd
*abfd ATTRIBUTE_UNUSED
;
2983 Elf64_Internal_Shdr
*shdr
;
2986 if ((asect
->flags
& SEC_EXCLUDE
) != 0)
2987 shdr
->sh_flags
|= SHF_EXCLUDE
;
2989 if ((asect
->flags
& SEC_SORT_ENTRIES
) != 0)
2990 shdr
->sh_type
= SHT_ORDERED
;
2995 /* The RELOCATE_SECTION function is called by the ELF backend linker
2996 to handle the relocations for a section.
2998 The relocs are always passed as Rela structures; if the section
2999 actually uses Rel structures, the r_addend field will always be
3002 This function is responsible for adjust the section contents as
3003 necessary, and (if using Rela relocs and generating a
3004 relocateable output file) adjusting the reloc addend as
3007 This function does not have to worry about setting the reloc
3008 address or the reloc symbol index.
3010 LOCAL_SYMS is a pointer to the swapped in local symbols.
3012 LOCAL_SECTIONS is an array giving the section in the input file
3013 corresponding to the st_shndx field of each local symbol.
3015 The global hash table entry for the global symbols can be found
3016 via elf_sym_hashes (input_bfd).
3018 When generating relocateable output, this function must handle
3019 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
3020 going to be the section symbol corresponding to the output
3021 section, which means that the addend must be adjusted
3025 ppc64_elf_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
3026 contents
, relocs
, local_syms
, local_sections
)
3028 struct bfd_link_info
*info
;
3030 asection
*input_section
;
3032 Elf_Internal_Rela
*relocs
;
3033 Elf_Internal_Sym
*local_syms
;
3034 asection
**local_sections
;
3036 struct ppc_link_hash_table
*htab
;
3037 Elf_Internal_Shdr
*symtab_hdr
;
3038 struct elf_link_hash_entry
**sym_hashes
;
3039 Elf_Internal_Rela
*rel
;
3040 Elf_Internal_Rela
*relend
;
3041 bfd_vma
*local_got_offsets
;
3045 /* Initialize howto table if needed. */
3046 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
3049 htab
= ppc_hash_table (info
);
3050 local_got_offsets
= elf_local_got_offsets (input_bfd
);
3051 TOCstart
= elf_gp (output_bfd
);
3052 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
3053 sym_hashes
= elf_sym_hashes (input_bfd
);
3056 relend
= relocs
+ input_section
->reloc_count
;
3057 for (; rel
< relend
; rel
++)
3059 enum elf_ppc_reloc_type r_type
;
3062 bfd_reloc_status_type r
;
3063 Elf_Internal_Sym
*sym
;
3065 struct elf_link_hash_entry
*h
;
3066 const char *sym_name
;
3067 unsigned long r_symndx
;
3069 boolean unresolved_reloc
;
3072 r_type
= (enum elf_ppc_reloc_type
) ELF64_R_TYPE (rel
->r_info
);
3073 r_symndx
= ELF64_R_SYM (rel
->r_info
);
3075 if (info
->relocateable
)
3077 /* This is a relocatable link. We don't have to change
3078 anything, unless the reloc is against a section symbol,
3079 in which case we have to adjust according to where the
3080 section symbol winds up in the output section. */
3081 if (r_symndx
< symtab_hdr
->sh_info
)
3083 sym
= local_syms
+ r_symndx
;
3084 if ((unsigned) ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
3086 sec
= local_sections
[r_symndx
];
3087 rel
->r_addend
+= sec
->output_offset
+ sym
->st_value
;
3093 /* This is a final link. */
3095 offset
= rel
->r_offset
;
3096 addend
= rel
->r_addend
;
3097 r
= bfd_reloc_other
;
3098 sym
= (Elf_Internal_Sym
*) 0;
3099 sec
= (asection
*) 0;
3100 h
= (struct elf_link_hash_entry
*) 0;
3101 sym_name
= (const char *) 0;
3102 unresolved_reloc
= false;
3104 if (r_type
== R_PPC64_TOC
)
3106 /* Relocation value is TOC base. Symbol is ignored. */
3107 relocation
= TOCstart
+ TOC_BASE_OFF
;
3109 else if (r_symndx
< symtab_hdr
->sh_info
)
3111 /* It's a local symbol. */
3112 sym
= local_syms
+ r_symndx
;
3113 sec
= local_sections
[r_symndx
];
3114 sym_name
= "<local symbol>";
3116 relocation
= (sec
->output_section
->vma
3117 + sec
->output_offset
3122 /* It's a global symbol. */
3123 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
3124 while (h
->root
.type
== bfd_link_hash_indirect
3125 || h
->root
.type
== bfd_link_hash_warning
)
3126 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
3127 sym_name
= h
->root
.root
.string
;
3129 if (h
->root
.type
== bfd_link_hash_defined
3130 || h
->root
.type
== bfd_link_hash_defweak
)
3132 sec
= h
->root
.u
.def
.section
;
3133 if (sec
->output_section
== NULL
)
3134 /* Set a flag that will be cleared later if we find a
3135 relocation value for this symbol. output_section
3136 is typically NULL for symbols satisfied by a shared
3138 unresolved_reloc
= true;
3140 relocation
= (h
->root
.u
.def
.value
3141 + sec
->output_section
->vma
3142 + sec
->output_offset
);
3144 else if (h
->root
.type
== bfd_link_hash_undefweak
)
3146 else if (info
->shared
3147 && (!info
->symbolic
|| info
->allow_shlib_undefined
)
3148 && !info
->no_undefined
3149 && ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
)
3153 if (! ((*info
->callbacks
->undefined_symbol
)
3154 (info
, h
->root
.root
.string
, input_bfd
, input_section
,
3155 offset
, (!info
->shared
3156 || info
->no_undefined
3157 || ELF_ST_VISIBILITY (h
->other
)))))
3163 /* First handle relocations that tweak non-addend part of insn. */
3169 /* Branch taken prediction relocations. */
3170 case R_PPC64_ADDR14_BRTAKEN
:
3171 case R_PPC64_REL14_BRTAKEN
:
3172 insn
= bfd_get_32 (output_bfd
, contents
+ offset
);
3173 if ((relocation
- offset
) & 0x8000)
3174 insn
&= ~BRANCH_PREDICT_BIT
;
3176 insn
|= BRANCH_PREDICT_BIT
;
3177 bfd_put_32 (output_bfd
, (bfd_vma
) insn
, contents
+ offset
);
3180 /* Branch not taken predicition relocations. */
3181 case R_PPC64_ADDR14_BRNTAKEN
:
3182 case R_PPC64_REL14_BRNTAKEN
:
3183 insn
= bfd_get_32 (output_bfd
, contents
+ offset
);
3184 if ((relocation
- offset
) & 0x8000)
3185 insn
|= BRANCH_PREDICT_BIT
;
3187 insn
&= ~BRANCH_PREDICT_BIT
;
3188 bfd_put_32 (output_bfd
, (bfd_vma
) insn
, contents
+ offset
);
3192 case R_PPC64_ADDR24
:
3193 /* An ADDR24 or REL24 branching to a linkage function may be
3194 followed by a nop that we have to replace with a ld in
3195 order to restore the TOC base pointer. Only calls to
3196 shared objects need to alter the TOC base. These are
3197 recognized by their need for a PLT entry. */
3199 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0
3200 /* Make sure that there really is an instruction after
3201 the branch that we can decode. */
3202 && offset
+ 8 <= input_section
->_cooked_size
)
3206 pnext
= contents
+ offset
+ 4;
3207 insn
= bfd_get_32 (input_bfd
, pnext
);
3209 if (insn
== 0x60000000 /* nop (ori r0,r0,0) */
3210 || insn
== 0x4def7b82 /* cror 15,15,15 */
3211 || insn
== 0x4ffffb82) /* cror 31,31,31 */
3213 bfd_put_32 (input_bfd
,
3214 (bfd_vma
) 0xe8410028, /* ld r2,40(r1) */
3225 (*_bfd_error_handler
)
3226 (_("%s: unknown relocation type %d for symbol %s"),
3227 bfd_archive_filename (input_bfd
), (int) r_type
, sym_name
);
3229 bfd_set_error (bfd_error_bad_value
);
3234 case R_PPC_GNU_VTINHERIT
:
3235 case R_PPC_GNU_VTENTRY
:
3238 /* GOT16 relocations. Like an ADDR16 using the symbol's
3239 address in the GOT as relocation value instead of the
3240 symbols value itself. Also, create a GOT entry for the
3241 symbol and put the symbol value there. */
3243 case R_PPC64_GOT16_LO
:
3244 case R_PPC64_GOT16_HI
:
3245 case R_PPC64_GOT16_HA
:
3246 case R_PPC64_GOT16_DS
:
3247 case R_PPC64_GOT16_LO_DS
:
3249 /* Relocation is to the entry for this symbol in the global
3253 if (htab
->sgot
== NULL
)
3260 off
= h
->got
.offset
;
3261 dyn
= htab
->elf
.dynamic_sections_created
;
3262 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
, h
)
3266 || (h
->elf_link_hash_flags
3267 & ELF_LINK_FORCED_LOCAL
))
3268 && (h
->elf_link_hash_flags
3269 & ELF_LINK_HASH_DEF_REGULAR
)))
3271 /* This is actually a static link, or it is a
3272 -Bsymbolic link and the symbol is defined
3273 locally, or the symbol was forced to be local
3274 because of a version file. We must initialize
3275 this entry in the global offset table. Since the
3276 offset must always be a multiple of 8, we use the
3277 least significant bit to record whether we have
3278 initialized it already.
3280 When doing a dynamic link, we create a .rel.got
3281 relocation entry to initialize the value. This
3282 is done in the finish_dynamic_symbol routine. */
3287 bfd_put_64 (output_bfd
, relocation
,
3288 htab
->sgot
->contents
+ off
);
3293 unresolved_reloc
= false;
3297 if (local_got_offsets
== NULL
)
3300 off
= local_got_offsets
[r_symndx
];
3302 /* The offset must always be a multiple of 8. We use
3303 the least significant bit to record whether we have
3304 already processed this entry. */
3309 bfd_put_64 (output_bfd
, relocation
,
3310 htab
->sgot
->contents
+ off
);
3314 Elf_Internal_Rela outrel
;
3315 Elf64_External_Rela
*loc
;
3317 /* We need to generate a R_PPC64_RELATIVE reloc
3318 for the dynamic linker. */
3319 outrel
.r_offset
= (htab
->sgot
->output_section
->vma
3320 + htab
->sgot
->output_offset
3322 outrel
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
3323 outrel
.r_addend
= relocation
;
3324 loc
= (Elf64_External_Rela
*) htab
->srelgot
->contents
;
3325 loc
+= htab
->srelgot
->reloc_count
++;
3326 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
3329 local_got_offsets
[r_symndx
] |= 1;
3333 if (off
>= (bfd_vma
) -2)
3336 relocation
= htab
->sgot
->output_offset
+ off
;
3338 /* TOC base (r2) is TOC start plus 0x8000. */
3339 addend
-= TOC_BASE_OFF
;
3343 case R_PPC64_PLT16_HA
:
3344 case R_PPC64_PLT16_HI
:
3345 case R_PPC64_PLT16_LO
:
3348 /* Relocation is to the entry for this symbol in the
3349 procedure linkage table. */
3351 /* Resolve a PLT reloc against a local symbol directly,
3352 without using the procedure linkage table. */
3356 if (h
->plt
.offset
== (bfd_vma
) -1
3357 || htab
->splt
== NULL
)
3359 /* We didn't make a PLT entry for this symbol. This
3360 happens when statically linking PIC code, or when
3361 using -Bsymbolic. */
3365 relocation
= (htab
->splt
->output_section
->vma
3366 + htab
->splt
->output_offset
3368 unresolved_reloc
= false;
3371 /* TOC16 relocs. We want the offset relative to the TOC base,
3372 which is the address of the start of the TOC plus 0x8000.
3373 The TOC consists of sections .got, .toc, .tocbss, and .plt,
3377 case R_PPC64_TOC16_LO
:
3378 case R_PPC64_TOC16_HI
:
3379 case R_PPC64_TOC16_DS
:
3380 case R_PPC64_TOC16_LO_DS
:
3381 case R_PPC64_TOC16_HA
:
3382 /* Only .got, .toc and *UND* symbols are allowed. */
3383 BFD_ASSERT (sec
!= (asection
*) 0
3384 && (bfd_is_und_section (sec
)
3385 || strcmp (bfd_get_section_name (abfd
, sec
),
3387 || strcmp (bfd_get_section_name (abfd
, sec
),
3390 addend
-= TOCstart
+ TOC_BASE_OFF
;
3393 /* Relocate against the beginning of the section. */
3394 case R_PPC64_SECTOFF
:
3395 case R_PPC64_SECTOFF_LO
:
3396 case R_PPC64_SECTOFF_HI
:
3397 case R_PPC64_SECTOFF_DS
:
3398 case R_PPC64_SECTOFF_LO_DS
:
3399 case R_PPC64_SECTOFF_HA
:
3400 if (sec
!= (asection
*) 0)
3401 addend
-= sec
->output_section
->vma
;
3404 /* Relocations that may need to be propagated if this is a
3407 case R_PPC64_REL14_BRNTAKEN
:
3408 case R_PPC64_REL14_BRTAKEN
:
3412 case R_PPC64_ADDR14
:
3413 case R_PPC64_ADDR14_BRNTAKEN
:
3414 case R_PPC64_ADDR14_BRTAKEN
:
3415 case R_PPC64_ADDR16
:
3416 case R_PPC64_ADDR16_DS
:
3417 case R_PPC64_ADDR16_HA
:
3418 case R_PPC64_ADDR16_HI
:
3419 case R_PPC64_ADDR16_HIGHER
:
3420 case R_PPC64_ADDR16_HIGHERA
:
3421 case R_PPC64_ADDR16_HIGHEST
:
3422 case R_PPC64_ADDR16_HIGHESTA
:
3423 case R_PPC64_ADDR16_LO
:
3424 case R_PPC64_ADDR16_LO_DS
:
3425 case R_PPC64_ADDR24
:
3426 case R_PPC64_ADDR30
:
3427 case R_PPC64_ADDR32
:
3428 case R_PPC64_ADDR64
:
3429 case R_PPC64_UADDR16
:
3430 case R_PPC64_UADDR32
:
3431 case R_PPC64_UADDR64
:
3434 && (input_section
->flags
& SEC_ALLOC
) != 0
3435 && (IS_ABSOLUTE_RELOC (r_type
)
3438 && (! info
->symbolic
3439 || (h
->elf_link_hash_flags
3440 & ELF_LINK_HASH_DEF_REGULAR
) == 0))))
3442 && (input_section
->flags
& SEC_ALLOC
) != 0
3445 && (h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0
3446 && (((h
->elf_link_hash_flags
3447 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0
3448 && (h
->elf_link_hash_flags
3449 & ELF_LINK_HASH_DEF_REGULAR
) == 0)
3450 || h
->root
.type
== bfd_link_hash_undefweak
3451 || h
->root
.type
== bfd_link_hash_undefined
)))
3453 Elf_Internal_Rela outrel
;
3454 boolean skip
, relocate
;
3456 Elf64_External_Rela
*loc
;
3458 /* When generating a dynamic object, these relocations
3459 are copied into the output file to be resolved at run
3464 if (elf_section_data (input_section
)->stab_info
== NULL
)
3465 outrel
.r_offset
= offset
;
3470 off
= (_bfd_stab_section_offset
3471 (output_bfd
, htab
->elf
.stab_info
, input_section
,
3472 &elf_section_data (input_section
)->stab_info
,
3474 if (off
== (bfd_vma
) -1)
3476 outrel
.r_offset
= off
;
3479 outrel
.r_offset
+= (input_section
->output_section
->vma
3480 + input_section
->output_offset
);
3481 outrel
.r_addend
= addend
;
3486 memset (&outrel
, 0, sizeof outrel
);
3490 && (!IS_ABSOLUTE_RELOC (r_type
)
3493 || (h
->elf_link_hash_flags
3494 & ELF_LINK_HASH_DEF_REGULAR
) == 0))
3497 outrel
.r_info
= ELF64_R_INFO (h
->dynindx
, r_type
);
3501 /* This symbol is local, or marked to become local. */
3502 outrel
.r_addend
+= relocation
;
3504 if (r_type
== R_PPC64_ADDR64
)
3506 outrel
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
3512 if (r_type
== R_PPC64_TOC
|| bfd_is_abs_section (sec
))
3514 else if (sec
== NULL
|| sec
->owner
== NULL
)
3516 bfd_set_error (bfd_error_bad_value
);
3523 osec
= sec
->output_section
;
3524 indx
= elf_section_data (osec
)->dynindx
;
3526 /* We are turning this relocation into one
3527 against a section symbol, so subtract out
3528 the output section's address but not the
3529 offset of the input section in the output
3531 outrel
.r_addend
-= osec
->vma
;
3534 outrel
.r_info
= ELF64_R_INFO (indx
, r_type
);
3538 sreloc
= elf_section_data (input_section
)->sreloc
;
3542 loc
= (Elf64_External_Rela
*) sreloc
->contents
;
3543 loc
+= sreloc
->reloc_count
++;
3544 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
3546 /* If this reloc is against an external symbol, it will
3547 be computed at runtime, so there's no need to do
3555 case R_PPC64_GLOB_DAT
:
3556 case R_PPC64_JMP_SLOT
:
3557 case R_PPC64_RELATIVE
:
3558 /* We shouldn't ever see these dynamic relocs in relocatable
3562 case R_PPC64_PLTGOT16
:
3563 case R_PPC64_PLTGOT16_DS
:
3564 case R_PPC64_PLTGOT16_HA
:
3565 case R_PPC64_PLTGOT16_HI
:
3566 case R_PPC64_PLTGOT16_LO
:
3567 case R_PPC64_PLTGOT16_LO_DS
:
3568 case R_PPC64_PLTREL32
:
3569 case R_PPC64_PLTREL64
:
3570 /* These ones haven't been implemented yet. */
3572 (*_bfd_error_handler
)
3573 (_("%s: Relocation %s is not supported for symbol %s."),
3574 bfd_archive_filename (input_bfd
),
3575 ppc64_elf_howto_table
[(int) r_type
]->name
, sym_name
);
3577 bfd_set_error (bfd_error_invalid_operation
);
3582 /* Do any further special processing. */
3588 case R_PPC64_ADDR16_HA
:
3589 case R_PPC64_ADDR16_HIGHERA
:
3590 case R_PPC64_ADDR16_HIGHESTA
:
3591 case R_PPC64_PLT16_HA
:
3592 case R_PPC64_TOC16_HA
:
3593 case R_PPC64_SECTOFF_HA
:
3594 /* It's just possible that this symbol is a weak symbol
3595 that's not actually defined anywhere. In that case,
3596 'sec' would be NULL, and we should leave the symbol
3597 alone (it will be set to zero elsewhere in the link). */
3599 /* Add 0x10000 if sign bit in 0:15 is set. */
3600 addend
+= ((relocation
+ addend
) & 0x8000) << 1;
3603 case R_PPC64_ADDR16_DS
:
3604 case R_PPC64_ADDR16_LO_DS
:
3605 case R_PPC64_GOT16_DS
:
3606 case R_PPC64_GOT16_LO_DS
:
3607 case R_PPC64_PLT16_LO_DS
:
3608 case R_PPC64_SECTOFF_DS
:
3609 case R_PPC64_SECTOFF_LO_DS
:
3610 case R_PPC64_TOC16_DS
:
3611 case R_PPC64_TOC16_LO_DS
:
3612 case R_PPC64_PLTGOT16_DS
:
3613 case R_PPC64_PLTGOT16_LO_DS
:
3614 if (((relocation
+ addend
) & 3) != 0)
3616 (*_bfd_error_handler
)
3617 (_("%s: error: relocation %s not a multiple of 4"),
3618 bfd_archive_filename (input_bfd
),
3619 ppc64_elf_howto_table
[(int) r_type
]->name
);
3620 bfd_set_error (bfd_error_bad_value
);
3627 /* FIXME: Why do we allow debugging sections to escape this error?
3628 More importantly, why do we not emit dynamic relocs above in
3629 debugging sections (which are ! SEC_ALLOC)? If we had
3630 emitted the dynamic reloc, we could remove the fudge here. */
3631 if (unresolved_reloc
3633 && (input_section
->flags
& SEC_DEBUGGING
) != 0
3634 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0))
3635 (*_bfd_error_handler
)
3636 (_("%s(%s+0x%lx): unresolvable relocation against symbol `%s'"),
3637 bfd_archive_filename (input_bfd
),
3638 bfd_get_section_name (input_bfd
, input_section
),
3639 (long) rel
->r_offset
,
3640 h
->root
.root
.string
);
3642 r
= _bfd_final_link_relocate (ppc64_elf_howto_table
[(int) r_type
],
3650 if (r
== bfd_reloc_ok
)
3652 else if (r
== bfd_reloc_overflow
)
3658 if (h
->root
.type
== bfd_link_hash_undefweak
3659 && ppc64_elf_howto_table
[(int) r_type
]->pc_relative
)
3661 /* Assume this is a call protected by other code that
3662 detects the symbol is undefined. If this is the case,
3663 we can safely ignore the overflow. If not, the
3664 program is hosed anyway, and a little warning isn't
3670 name
= h
->root
.root
.string
;
3674 name
= bfd_elf_string_from_elf_section (input_bfd
,
3675 symtab_hdr
->sh_link
,
3680 name
= bfd_section_name (input_bfd
, sec
);
3683 if (! ((*info
->callbacks
->reloc_overflow
)
3684 (info
, name
, ppc64_elf_howto_table
[(int) r_type
]->name
,
3685 (bfd_vma
) 0, input_bfd
, input_section
, offset
)))
3695 /* Finish up dynamic symbol handling. We set the contents of various
3696 dynamic sections here. */
3699 ppc64_elf_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
3701 struct bfd_link_info
*info
;
3702 struct elf_link_hash_entry
*h
;
3703 Elf_Internal_Sym
*sym
;
3705 struct ppc_link_hash_table
*htab
;
3708 htab
= ppc_hash_table (info
);
3709 dynobj
= htab
->elf
.dynobj
;
3711 if (h
->plt
.offset
!= (bfd_vma
) -1)
3713 struct elf_link_hash_entry
*funcdesc_h
;
3714 Elf_Internal_Rela rela
;
3715 Elf64_External_Rela
*loc
;
3717 /* This symbol has an entry in the procedure linkage table. Set
3720 if (h
->dynindx
== -1
3721 || htab
->splt
== NULL
3722 || htab
->srelplt
== NULL
3723 || htab
->sglink
== NULL
3724 || h
->root
.root
.string
[0] != '.'
3725 || h
->root
.root
.string
[1] == '\0')
3728 /* Find its corresponding function descriptor.
3729 ppc64_elf_adjust_dynamic_symbol has already set it up for us. */
3731 funcdesc_h
= elf_link_hash_lookup (elf_hash_table (info
),
3732 h
->root
.root
.string
+ 1,
3733 false, false, false);
3735 if (funcdesc_h
== NULL
|| funcdesc_h
->dynindx
== -1)
3738 /* Create a JMP_SLOT reloc to inform the dynamic linker to
3739 fill in the PLT entry. */
3741 rela
.r_offset
= (htab
->splt
->output_section
->vma
3742 + htab
->splt
->output_offset
3744 rela
.r_info
= ELF64_R_INFO (funcdesc_h
->dynindx
, R_PPC64_JMP_SLOT
);
3747 loc
= (Elf64_External_Rela
*) htab
->srelplt
->contents
;
3748 loc
+= (h
->plt
.offset
- PLT_INITIAL_ENTRY_SIZE
) / PLT_ENTRY_SIZE
;
3749 bfd_elf64_swap_reloca_out (output_bfd
, &rela
, loc
);
3751 /* We need to create a linkage function. */
3752 if (h
->root
.u
.def
.section
== htab
->sglink
)
3756 const unsigned int *stub
;
3758 /* Where to write it. */
3759 p
= h
->root
.u
.def
.section
->contents
+ h
->root
.u
.def
.value
;
3761 /* The function descriptor is in the PLT. */
3762 pltoff
= htab
->splt
->output_section
->vma
3763 + htab
->splt
->output_section
->output_offset
3765 - elf_gp (output_bfd
) - TOC_BASE_OFF
;
3767 if (pltoff
+ 0x8000 > 0xffff)
3769 (*_bfd_error_handler
)
3770 (_("linkage table overflow against `%s'"),
3771 h
->root
.root
.string
);
3775 stub
= ppc64_elf_glink_code
;
3776 bfd_put_32 (output_bfd
, *stub
| (pltoff
& 0xfffc), p
);
3777 while (p
+= 4, ++stub
< (ppc64_elf_glink_code
3778 + (sizeof (ppc64_elf_glink_code
)
3779 / sizeof (*ppc64_elf_glink_code
))));
3781 bfd_put_32 (output_bfd
, (bfd_vma
) *stub
, p
);
3788 if (h
->got
.offset
!= (bfd_vma
) -1)
3790 Elf_Internal_Rela rela
;
3791 Elf64_External_Rela
*loc
;
3793 /* This symbol has an entry in the global offset table. Set it
3796 if (htab
->sgot
== NULL
|| htab
->srelgot
== NULL
)
3799 rela
.r_offset
= (htab
->sgot
->output_section
->vma
3800 + htab
->sgot
->output_offset
3801 + (h
->got
.offset
&~ (bfd_vma
) 1));
3803 /* If this is a static link, or it is a -Bsymbolic link and the
3804 symbol is defined locally or was forced to be local because
3805 of a version file, we just want to emit a RELATIVE reloc.
3806 The entry in the global offset table will already have been
3807 initialized in the relocate_section function. */
3811 || (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
))
3812 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
))
3814 BFD_ASSERT((h
->got
.offset
& 1) != 0);
3815 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
3816 rela
.r_addend
= (h
->root
.u
.def
.value
3817 + h
->root
.u
.def
.section
->output_section
->vma
3818 + h
->root
.u
.def
.section
->output_offset
);
3822 BFD_ASSERT ((h
->got
.offset
& 1) == 0);
3823 bfd_put_64 (output_bfd
, (bfd_vma
) 0,
3824 htab
->sgot
->contents
+ h
->got
.offset
);
3825 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_PPC64_GLOB_DAT
);
3829 loc
= (Elf64_External_Rela
*) htab
->srelgot
->contents
;
3830 loc
+= htab
->srelgot
->reloc_count
++;
3831 bfd_elf64_swap_reloca_out (output_bfd
, &rela
, loc
);
3834 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_COPY
) != 0)
3836 Elf_Internal_Rela rela
;
3837 Elf64_External_Rela
*loc
;
3839 /* This symbol needs a copy reloc. Set it up. */
3841 if (h
->dynindx
== -1
3842 || (h
->root
.type
!= bfd_link_hash_defined
3843 && h
->root
.type
!= bfd_link_hash_defweak
)
3844 || htab
->srelbss
== NULL
)
3847 rela
.r_offset
= (h
->root
.u
.def
.value
3848 + h
->root
.u
.def
.section
->output_section
->vma
3849 + h
->root
.u
.def
.section
->output_offset
);
3850 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_PPC64_COPY
);
3852 loc
= (Elf64_External_Rela
*) htab
->srelbss
->contents
;
3853 loc
+= htab
->srelbss
->reloc_count
++;
3854 bfd_elf64_swap_reloca_out (output_bfd
, &rela
, loc
);
3857 /* Mark some specially defined symbols as absolute. */
3858 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0)
3859 sym
->st_shndx
= SHN_ABS
;
3864 /* Used to decide how to sort relocs in an optimal manner for the
3865 dynamic linker, before writing them out. */
3867 static enum elf_reloc_type_class
3868 ppc64_elf_reloc_type_class (rela
)
3869 const Elf_Internal_Rela
*rela
;
3871 enum elf_ppc_reloc_type r_type
;
3873 r_type
= (enum elf_ppc_reloc_type
) ELF64_R_TYPE (rela
->r_info
);
3876 case R_PPC64_RELATIVE
:
3877 return reloc_class_relative
;
3878 case R_PPC64_JMP_SLOT
:
3879 return reloc_class_plt
;
3881 return reloc_class_copy
;
3883 return reloc_class_normal
;
3887 /* Finish up the dynamic sections. */
3890 ppc64_elf_finish_dynamic_sections (output_bfd
, info
)
3892 struct bfd_link_info
*info
;
3894 struct ppc_link_hash_table
*htab
;
3898 htab
= ppc_hash_table (info
);
3899 dynobj
= htab
->elf
.dynobj
;
3900 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
3902 if (htab
->elf
.dynamic_sections_created
)
3904 Elf64_External_Dyn
*dyncon
, *dynconend
;
3906 if (sdyn
== NULL
|| htab
->sgot
== NULL
)
3909 dyncon
= (Elf64_External_Dyn
*) sdyn
->contents
;
3910 dynconend
= (Elf64_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
3911 for (; dyncon
< dynconend
; dyncon
++)
3913 Elf_Internal_Dyn dyn
;
3915 bfd_elf64_swap_dyn_in (dynobj
, dyncon
, &dyn
);
3923 dyn
.d_un
.d_ptr
= htab
->splt
->output_section
->vma
;
3927 dyn
.d_un
.d_ptr
= htab
->srelplt
->output_section
->vma
;
3931 if (htab
->srelplt
->output_section
->_cooked_size
!= 0)
3932 dyn
.d_un
.d_val
= htab
->srelplt
->output_section
->_cooked_size
;
3934 dyn
.d_un
.d_val
= htab
->srelplt
->output_section
->_raw_size
;
3938 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
3945 #define TARGET_LITTLE_SYM bfd_elf64_powerpcle_vec
3946 #define TARGET_LITTLE_NAME "elf64-powerpcle"
3947 #define TARGET_BIG_SYM bfd_elf64_powerpc_vec
3948 #define TARGET_BIG_NAME "elf64-powerpc"
3949 #define ELF_ARCH bfd_arch_powerpc
3950 #define ELF_MACHINE_CODE EM_PPC64
3951 #define ELF_MAXPAGESIZE 0x10000
3952 #define elf_info_to_howto ppc64_elf_info_to_howto
3954 #ifdef EM_CYGNUS_POWERPC
3955 #define ELF_MACHINE_ALT1 EM_CYGNUS_POWERPC
3959 #define ELF_MACHINE_ALT2 EM_PPC_OLD
3962 #define elf_backend_want_got_sym 0
3963 #define elf_backend_want_plt_sym 0
3964 #define elf_backend_plt_alignment 3
3965 #define elf_backend_plt_not_loaded 1
3966 #define elf_backend_got_symbol_offset 0
3967 #define elf_backend_got_header_size 0
3968 #define elf_backend_can_gc_sections 1
3969 #define elf_backend_can_refcount 1
3971 #define elf_backend_plt_header_size PLT_INITIAL_ENTRY_SIZE
3973 #define bfd_elf64_bfd_reloc_type_lookup ppc64_elf_reloc_type_lookup
3974 #define bfd_elf64_bfd_set_private_flags ppc64_elf_set_private_flags
3975 #define bfd_elf64_bfd_copy_private_bfd_data ppc64_elf_copy_private_bfd_data
3976 #define bfd_elf64_bfd_merge_private_bfd_data ppc64_elf_merge_private_bfd_data
3977 #define bfd_elf64_bfd_link_hash_table_create ppc64_elf_link_hash_table_create
3978 #define bfd_elf64_bfd_final_link ppc64_elf_final_link
3980 #define elf_backend_section_from_shdr ppc64_elf_section_from_shdr
3981 #define elf_backend_create_dynamic_sections ppc64_elf_create_dynamic_sections
3982 #define elf_backend_copy_indirect_symbol ppc64_elf_copy_indirect_symbol
3983 #define elf_backend_check_relocs ppc64_elf_check_relocs
3984 #define elf_backend_gc_mark_hook ppc64_elf_gc_mark_hook
3985 #define elf_backend_gc_sweep_hook ppc64_elf_gc_sweep_hook
3986 #define elf_backend_adjust_dynamic_symbol ppc64_elf_adjust_dynamic_symbol
3987 #define elf_backend_size_dynamic_sections ppc64_elf_size_dynamic_sections
3988 #define elf_backend_fake_sections ppc64_elf_fake_sections
3989 #define elf_backend_relocate_section ppc64_elf_relocate_section
3990 #define elf_backend_finish_dynamic_symbol ppc64_elf_finish_dynamic_symbol
3991 #define elf_backend_reloc_type_class ppc64_elf_reloc_type_class
3992 #define elf_backend_finish_dynamic_sections ppc64_elf_finish_dynamic_sections
3994 #include "elf64-target.h"