1 /* PowerPC64-specific support for 64-bit ELF.
2 Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
3 Free Software Foundation, Inc.
4 Written by Linus Nordberg, Swox AB <info@swox.com>,
5 based on elf32-ppc.c by Ian Lance Taylor.
6 Largely rewritten by Alan Modra <amodra@bigpond.net.au>
8 This file is part of BFD, the Binary File Descriptor library.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License along
21 with this program; if not, write to the Free Software Foundation, Inc.,
22 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
25 /* The 64-bit PowerPC ELF ABI may be found at
26 http://www.linuxbase.org/spec/ELF/ppc64/PPC-elf64abi.txt, and
27 http://www.linuxbase.org/spec/ELF/ppc64/spec/book1.html */
35 #include "elf/ppc64.h"
36 #include "elf64-ppc.h"
38 static bfd_reloc_status_type ppc64_elf_ha_reloc
39 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
40 static bfd_reloc_status_type ppc64_elf_branch_reloc
41 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
42 static bfd_reloc_status_type ppc64_elf_brtaken_reloc
43 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
44 static bfd_reloc_status_type ppc64_elf_sectoff_reloc
45 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
46 static bfd_reloc_status_type ppc64_elf_sectoff_ha_reloc
47 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
48 static bfd_reloc_status_type ppc64_elf_toc_reloc
49 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
50 static bfd_reloc_status_type ppc64_elf_toc_ha_reloc
51 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
52 static bfd_reloc_status_type ppc64_elf_toc64_reloc
53 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
54 static bfd_reloc_status_type ppc64_elf_unhandled_reloc
55 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
56 static bfd_vma opd_entry_value
57 (asection
*, bfd_vma
, asection
**, bfd_vma
*);
59 #define TARGET_LITTLE_SYM bfd_elf64_powerpcle_vec
60 #define TARGET_LITTLE_NAME "elf64-powerpcle"
61 #define TARGET_BIG_SYM bfd_elf64_powerpc_vec
62 #define TARGET_BIG_NAME "elf64-powerpc"
63 #define ELF_ARCH bfd_arch_powerpc
64 #define ELF_MACHINE_CODE EM_PPC64
65 #define ELF_MAXPAGESIZE 0x10000
66 #define ELF_COMMONPAGESIZE 0x1000
67 #define elf_info_to_howto ppc64_elf_info_to_howto
69 #define elf_backend_want_got_sym 0
70 #define elf_backend_want_plt_sym 0
71 #define elf_backend_plt_alignment 3
72 #define elf_backend_plt_not_loaded 1
73 #define elf_backend_got_header_size 8
74 #define elf_backend_can_gc_sections 1
75 #define elf_backend_can_refcount 1
76 #define elf_backend_rela_normal 1
77 #define elf_backend_default_execstack 0
79 #define bfd_elf64_mkobject ppc64_elf_mkobject
80 #define bfd_elf64_bfd_reloc_type_lookup ppc64_elf_reloc_type_lookup
81 #define bfd_elf64_bfd_reloc_name_lookup ppc64_elf_reloc_name_lookup
82 #define bfd_elf64_bfd_merge_private_bfd_data ppc64_elf_merge_private_bfd_data
83 #define bfd_elf64_new_section_hook ppc64_elf_new_section_hook
84 #define bfd_elf64_bfd_link_hash_table_create ppc64_elf_link_hash_table_create
85 #define bfd_elf64_bfd_link_hash_table_free ppc64_elf_link_hash_table_free
86 #define bfd_elf64_get_synthetic_symtab ppc64_elf_get_synthetic_symtab
88 #define elf_backend_object_p ppc64_elf_object_p
89 #define elf_backend_grok_prstatus ppc64_elf_grok_prstatus
90 #define elf_backend_grok_psinfo ppc64_elf_grok_psinfo
91 #define elf_backend_write_core_note ppc64_elf_write_core_note
92 #define elf_backend_create_dynamic_sections ppc64_elf_create_dynamic_sections
93 #define elf_backend_copy_indirect_symbol ppc64_elf_copy_indirect_symbol
94 #define elf_backend_add_symbol_hook ppc64_elf_add_symbol_hook
95 #define elf_backend_check_directives ppc64_elf_check_directives
96 #define elf_backend_as_needed_cleanup ppc64_elf_as_needed_cleanup
97 #define elf_backend_archive_symbol_lookup ppc64_elf_archive_symbol_lookup
98 #define elf_backend_check_relocs ppc64_elf_check_relocs
99 #define elf_backend_gc_mark_dynamic_ref ppc64_elf_gc_mark_dynamic_ref
100 #define elf_backend_gc_mark_hook ppc64_elf_gc_mark_hook
101 #define elf_backend_gc_sweep_hook ppc64_elf_gc_sweep_hook
102 #define elf_backend_adjust_dynamic_symbol ppc64_elf_adjust_dynamic_symbol
103 #define elf_backend_hide_symbol ppc64_elf_hide_symbol
104 #define elf_backend_always_size_sections ppc64_elf_func_desc_adjust
105 #define elf_backend_size_dynamic_sections ppc64_elf_size_dynamic_sections
106 #define elf_backend_init_index_section _bfd_elf_init_2_index_sections
107 #define elf_backend_action_discarded ppc64_elf_action_discarded
108 #define elf_backend_relocate_section ppc64_elf_relocate_section
109 #define elf_backend_finish_dynamic_symbol ppc64_elf_finish_dynamic_symbol
110 #define elf_backend_reloc_type_class ppc64_elf_reloc_type_class
111 #define elf_backend_finish_dynamic_sections ppc64_elf_finish_dynamic_sections
112 #define elf_backend_link_output_symbol_hook ppc64_elf_output_symbol_hook
113 #define elf_backend_special_sections ppc64_elf_special_sections
115 /* The name of the dynamic interpreter. This is put in the .interp
117 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
119 /* The size in bytes of an entry in the procedure linkage table. */
120 #define PLT_ENTRY_SIZE 24
122 /* The initial size of the plt reserved for the dynamic linker. */
123 #define PLT_INITIAL_ENTRY_SIZE PLT_ENTRY_SIZE
125 /* TOC base pointers offset from start of TOC. */
126 #define TOC_BASE_OFF 0x8000
128 /* Offset of tp and dtp pointers from start of TLS block. */
129 #define TP_OFFSET 0x7000
130 #define DTP_OFFSET 0x8000
132 /* .plt call stub instructions. The normal stub is like this, but
133 sometimes the .plt entry crosses a 64k boundary and we need to
134 insert an addis to adjust r12. */
135 #define PLT_CALL_STUB_SIZE (7*4)
136 #define ADDIS_R12_R2 0x3d820000 /* addis %r12,%r2,xxx@ha */
137 #define STD_R2_40R1 0xf8410028 /* std %r2,40(%r1) */
138 #define LD_R11_0R12 0xe96c0000 /* ld %r11,xxx+0@l(%r12) */
139 #define LD_R2_0R12 0xe84c0000 /* ld %r2,xxx+8@l(%r12) */
140 #define MTCTR_R11 0x7d6903a6 /* mtctr %r11 */
141 /* ld %r11,xxx+16@l(%r12) */
142 #define BCTR 0x4e800420 /* bctr */
145 #define ADDIS_R12_R12 0x3d8c0000 /* addis %r12,%r12,off@ha */
146 #define ADDIS_R2_R2 0x3c420000 /* addis %r2,%r2,off@ha */
147 #define ADDI_R2_R2 0x38420000 /* addi %r2,%r2,off@l */
149 #define LD_R2_40R1 0xe8410028 /* ld %r2,40(%r1) */
151 /* glink call stub instructions. We enter with the index in R0. */
152 #define GLINK_CALL_STUB_SIZE (16*4)
156 #define MFLR_R12 0x7d8802a6 /* mflr %12 */
157 #define BCL_20_31 0x429f0005 /* bcl 20,31,1f */
159 #define MFLR_R11 0x7d6802a6 /* mflr %11 */
160 #define LD_R2_M16R11 0xe84bfff0 /* ld %2,(0b-1b)(%11) */
161 #define MTLR_R12 0x7d8803a6 /* mtlr %12 */
162 #define ADD_R12_R2_R11 0x7d825a14 /* add %12,%2,%11 */
170 #define NOP 0x60000000
172 /* Some other nops. */
173 #define CROR_151515 0x4def7b82
174 #define CROR_313131 0x4ffffb82
176 /* .glink entries for the first 32k functions are two instructions. */
177 #define LI_R0_0 0x38000000 /* li %r0,0 */
178 #define B_DOT 0x48000000 /* b . */
180 /* After that, we need two instructions to load the index, followed by
182 #define LIS_R0_0 0x3c000000 /* lis %r0,0 */
183 #define ORI_R0_R0_0 0x60000000 /* ori %r0,%r0,0 */
185 /* Instructions used by the save and restore reg functions. */
186 #define STD_R0_0R1 0xf8010000 /* std %r0,0(%r1) */
187 #define STD_R0_0R12 0xf80c0000 /* std %r0,0(%r12) */
188 #define LD_R0_0R1 0xe8010000 /* ld %r0,0(%r1) */
189 #define LD_R0_0R12 0xe80c0000 /* ld %r0,0(%r12) */
190 #define STFD_FR0_0R1 0xd8010000 /* stfd %fr0,0(%r1) */
191 #define LFD_FR0_0R1 0xc8010000 /* lfd %fr0,0(%r1) */
192 #define LI_R12_0 0x39800000 /* li %r12,0 */
193 #define STVX_VR0_R12_R0 0x7c0c01ce /* stvx %v0,%r12,%r0 */
194 #define LVX_VR0_R12_R0 0x7c0c00ce /* lvx %v0,%r12,%r0 */
195 #define MTLR_R0 0x7c0803a6 /* mtlr %r0 */
196 #define BLR 0x4e800020 /* blr */
198 /* Since .opd is an array of descriptors and each entry will end up
199 with identical R_PPC64_RELATIVE relocs, there is really no need to
200 propagate .opd relocs; The dynamic linker should be taught to
201 relocate .opd without reloc entries. */
202 #ifndef NO_OPD_RELOCS
203 #define NO_OPD_RELOCS 0
206 #define ONES(n) (((bfd_vma) 1 << ((n) - 1) << 1) - 1)
208 /* Relocation HOWTO's. */
209 static reloc_howto_type
*ppc64_elf_howto_table
[(int) R_PPC64_max
];
211 static reloc_howto_type ppc64_elf_howto_raw
[] = {
212 /* This reloc does nothing. */
213 HOWTO (R_PPC64_NONE
, /* type */
215 2, /* size (0 = byte, 1 = short, 2 = long) */
217 FALSE
, /* pc_relative */
219 complain_overflow_dont
, /* complain_on_overflow */
220 bfd_elf_generic_reloc
, /* special_function */
221 "R_PPC64_NONE", /* name */
222 FALSE
, /* partial_inplace */
225 FALSE
), /* pcrel_offset */
227 /* A standard 32 bit relocation. */
228 HOWTO (R_PPC64_ADDR32
, /* type */
230 2, /* size (0 = byte, 1 = short, 2 = long) */
232 FALSE
, /* pc_relative */
234 complain_overflow_bitfield
, /* complain_on_overflow */
235 bfd_elf_generic_reloc
, /* special_function */
236 "R_PPC64_ADDR32", /* name */
237 FALSE
, /* partial_inplace */
239 0xffffffff, /* dst_mask */
240 FALSE
), /* pcrel_offset */
242 /* An absolute 26 bit branch; the lower two bits must be zero.
243 FIXME: we don't check that, we just clear them. */
244 HOWTO (R_PPC64_ADDR24
, /* 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_ADDR24", /* name */
253 FALSE
, /* partial_inplace */
255 0x03fffffc, /* dst_mask */
256 FALSE
), /* pcrel_offset */
258 /* A standard 16 bit relocation. */
259 HOWTO (R_PPC64_ADDR16
, /* type */
261 1, /* size (0 = byte, 1 = short, 2 = long) */
263 FALSE
, /* pc_relative */
265 complain_overflow_bitfield
, /* complain_on_overflow */
266 bfd_elf_generic_reloc
, /* special_function */
267 "R_PPC64_ADDR16", /* name */
268 FALSE
, /* partial_inplace */
270 0xffff, /* dst_mask */
271 FALSE
), /* pcrel_offset */
273 /* A 16 bit relocation without overflow. */
274 HOWTO (R_PPC64_ADDR16_LO
, /* type */
276 1, /* size (0 = byte, 1 = short, 2 = long) */
278 FALSE
, /* pc_relative */
280 complain_overflow_dont
,/* complain_on_overflow */
281 bfd_elf_generic_reloc
, /* special_function */
282 "R_PPC64_ADDR16_LO", /* name */
283 FALSE
, /* partial_inplace */
285 0xffff, /* dst_mask */
286 FALSE
), /* pcrel_offset */
288 /* Bits 16-31 of an address. */
289 HOWTO (R_PPC64_ADDR16_HI
, /* type */
291 1, /* size (0 = byte, 1 = short, 2 = long) */
293 FALSE
, /* pc_relative */
295 complain_overflow_dont
, /* complain_on_overflow */
296 bfd_elf_generic_reloc
, /* special_function */
297 "R_PPC64_ADDR16_HI", /* name */
298 FALSE
, /* partial_inplace */
300 0xffff, /* dst_mask */
301 FALSE
), /* pcrel_offset */
303 /* Bits 16-31 of an address, plus 1 if the contents of the low 16
304 bits, treated as a signed number, is negative. */
305 HOWTO (R_PPC64_ADDR16_HA
, /* type */
307 1, /* size (0 = byte, 1 = short, 2 = long) */
309 FALSE
, /* pc_relative */
311 complain_overflow_dont
, /* complain_on_overflow */
312 ppc64_elf_ha_reloc
, /* special_function */
313 "R_PPC64_ADDR16_HA", /* name */
314 FALSE
, /* partial_inplace */
316 0xffff, /* dst_mask */
317 FALSE
), /* pcrel_offset */
319 /* An absolute 16 bit branch; the lower two bits must be zero.
320 FIXME: we don't check that, we just clear them. */
321 HOWTO (R_PPC64_ADDR14
, /* type */
323 2, /* size (0 = byte, 1 = short, 2 = long) */
325 FALSE
, /* pc_relative */
327 complain_overflow_bitfield
, /* complain_on_overflow */
328 ppc64_elf_branch_reloc
, /* special_function */
329 "R_PPC64_ADDR14", /* name */
330 FALSE
, /* partial_inplace */
332 0x0000fffc, /* dst_mask */
333 FALSE
), /* pcrel_offset */
335 /* An absolute 16 bit branch, for which bit 10 should be set to
336 indicate that the branch is expected to be taken. The lower two
337 bits must be zero. */
338 HOWTO (R_PPC64_ADDR14_BRTAKEN
, /* type */
340 2, /* size (0 = byte, 1 = short, 2 = long) */
342 FALSE
, /* pc_relative */
344 complain_overflow_bitfield
, /* complain_on_overflow */
345 ppc64_elf_brtaken_reloc
, /* special_function */
346 "R_PPC64_ADDR14_BRTAKEN",/* name */
347 FALSE
, /* partial_inplace */
349 0x0000fffc, /* dst_mask */
350 FALSE
), /* pcrel_offset */
352 /* An absolute 16 bit branch, for which bit 10 should be set to
353 indicate that the branch is not expected to be taken. The lower
354 two bits must be zero. */
355 HOWTO (R_PPC64_ADDR14_BRNTAKEN
, /* type */
357 2, /* size (0 = byte, 1 = short, 2 = long) */
359 FALSE
, /* pc_relative */
361 complain_overflow_bitfield
, /* complain_on_overflow */
362 ppc64_elf_brtaken_reloc
, /* special_function */
363 "R_PPC64_ADDR14_BRNTAKEN",/* name */
364 FALSE
, /* partial_inplace */
366 0x0000fffc, /* dst_mask */
367 FALSE
), /* pcrel_offset */
369 /* A relative 26 bit branch; the lower two bits must be zero. */
370 HOWTO (R_PPC64_REL24
, /* type */
372 2, /* size (0 = byte, 1 = short, 2 = long) */
374 TRUE
, /* pc_relative */
376 complain_overflow_signed
, /* complain_on_overflow */
377 ppc64_elf_branch_reloc
, /* special_function */
378 "R_PPC64_REL24", /* name */
379 FALSE
, /* partial_inplace */
381 0x03fffffc, /* dst_mask */
382 TRUE
), /* pcrel_offset */
384 /* A relative 16 bit branch; the lower two bits must be zero. */
385 HOWTO (R_PPC64_REL14
, /* type */
387 2, /* size (0 = byte, 1 = short, 2 = long) */
389 TRUE
, /* pc_relative */
391 complain_overflow_signed
, /* complain_on_overflow */
392 ppc64_elf_branch_reloc
, /* special_function */
393 "R_PPC64_REL14", /* name */
394 FALSE
, /* partial_inplace */
396 0x0000fffc, /* dst_mask */
397 TRUE
), /* pcrel_offset */
399 /* A relative 16 bit branch. Bit 10 should be set to indicate that
400 the branch is expected to be taken. The lower two bits must be
402 HOWTO (R_PPC64_REL14_BRTAKEN
, /* type */
404 2, /* size (0 = byte, 1 = short, 2 = long) */
406 TRUE
, /* pc_relative */
408 complain_overflow_signed
, /* complain_on_overflow */
409 ppc64_elf_brtaken_reloc
, /* special_function */
410 "R_PPC64_REL14_BRTAKEN", /* name */
411 FALSE
, /* partial_inplace */
413 0x0000fffc, /* dst_mask */
414 TRUE
), /* pcrel_offset */
416 /* A relative 16 bit branch. Bit 10 should be set to indicate that
417 the branch is not expected to be taken. The lower two bits must
419 HOWTO (R_PPC64_REL14_BRNTAKEN
, /* type */
421 2, /* size (0 = byte, 1 = short, 2 = long) */
423 TRUE
, /* pc_relative */
425 complain_overflow_signed
, /* complain_on_overflow */
426 ppc64_elf_brtaken_reloc
, /* special_function */
427 "R_PPC64_REL14_BRNTAKEN",/* name */
428 FALSE
, /* partial_inplace */
430 0x0000fffc, /* dst_mask */
431 TRUE
), /* pcrel_offset */
433 /* Like R_PPC64_ADDR16, but referring to the GOT table entry for the
435 HOWTO (R_PPC64_GOT16
, /* type */
437 1, /* size (0 = byte, 1 = short, 2 = long) */
439 FALSE
, /* pc_relative */
441 complain_overflow_signed
, /* complain_on_overflow */
442 ppc64_elf_unhandled_reloc
, /* special_function */
443 "R_PPC64_GOT16", /* name */
444 FALSE
, /* partial_inplace */
446 0xffff, /* dst_mask */
447 FALSE
), /* pcrel_offset */
449 /* Like R_PPC64_ADDR16_LO, but referring to the GOT table entry for
451 HOWTO (R_PPC64_GOT16_LO
, /* type */
453 1, /* size (0 = byte, 1 = short, 2 = long) */
455 FALSE
, /* pc_relative */
457 complain_overflow_dont
, /* complain_on_overflow */
458 ppc64_elf_unhandled_reloc
, /* special_function */
459 "R_PPC64_GOT16_LO", /* name */
460 FALSE
, /* partial_inplace */
462 0xffff, /* dst_mask */
463 FALSE
), /* pcrel_offset */
465 /* Like R_PPC64_ADDR16_HI, but referring to the GOT table entry for
467 HOWTO (R_PPC64_GOT16_HI
, /* type */
469 1, /* size (0 = byte, 1 = short, 2 = long) */
471 FALSE
, /* pc_relative */
473 complain_overflow_dont
,/* complain_on_overflow */
474 ppc64_elf_unhandled_reloc
, /* special_function */
475 "R_PPC64_GOT16_HI", /* name */
476 FALSE
, /* partial_inplace */
478 0xffff, /* dst_mask */
479 FALSE
), /* pcrel_offset */
481 /* Like R_PPC64_ADDR16_HA, but referring to the GOT table entry for
483 HOWTO (R_PPC64_GOT16_HA
, /* type */
485 1, /* size (0 = byte, 1 = short, 2 = long) */
487 FALSE
, /* pc_relative */
489 complain_overflow_dont
,/* complain_on_overflow */
490 ppc64_elf_unhandled_reloc
, /* special_function */
491 "R_PPC64_GOT16_HA", /* name */
492 FALSE
, /* partial_inplace */
494 0xffff, /* dst_mask */
495 FALSE
), /* pcrel_offset */
497 /* This is used only by the dynamic linker. The symbol should exist
498 both in the object being run and in some shared library. The
499 dynamic linker copies the data addressed by the symbol from the
500 shared library into the object, because the object being
501 run has to have the data at some particular address. */
502 HOWTO (R_PPC64_COPY
, /* type */
504 0, /* this one is variable size */
506 FALSE
, /* pc_relative */
508 complain_overflow_dont
, /* complain_on_overflow */
509 ppc64_elf_unhandled_reloc
, /* special_function */
510 "R_PPC64_COPY", /* name */
511 FALSE
, /* partial_inplace */
514 FALSE
), /* pcrel_offset */
516 /* Like R_PPC64_ADDR64, but used when setting global offset table
518 HOWTO (R_PPC64_GLOB_DAT
, /* type */
520 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
522 FALSE
, /* pc_relative */
524 complain_overflow_dont
, /* complain_on_overflow */
525 ppc64_elf_unhandled_reloc
, /* special_function */
526 "R_PPC64_GLOB_DAT", /* name */
527 FALSE
, /* partial_inplace */
529 ONES (64), /* dst_mask */
530 FALSE
), /* pcrel_offset */
532 /* Created by the link editor. Marks a procedure linkage table
533 entry for a symbol. */
534 HOWTO (R_PPC64_JMP_SLOT
, /* type */
536 0, /* size (0 = byte, 1 = short, 2 = long) */
538 FALSE
, /* pc_relative */
540 complain_overflow_dont
, /* complain_on_overflow */
541 ppc64_elf_unhandled_reloc
, /* special_function */
542 "R_PPC64_JMP_SLOT", /* name */
543 FALSE
, /* partial_inplace */
546 FALSE
), /* pcrel_offset */
548 /* Used only by the dynamic linker. When the object is run, this
549 doubleword64 is set to the load address of the object, plus the
551 HOWTO (R_PPC64_RELATIVE
, /* type */
553 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
555 FALSE
, /* pc_relative */
557 complain_overflow_dont
, /* complain_on_overflow */
558 bfd_elf_generic_reloc
, /* special_function */
559 "R_PPC64_RELATIVE", /* name */
560 FALSE
, /* partial_inplace */
562 ONES (64), /* dst_mask */
563 FALSE
), /* pcrel_offset */
565 /* Like R_PPC64_ADDR32, but may be unaligned. */
566 HOWTO (R_PPC64_UADDR32
, /* type */
568 2, /* size (0 = byte, 1 = short, 2 = long) */
570 FALSE
, /* pc_relative */
572 complain_overflow_bitfield
, /* complain_on_overflow */
573 bfd_elf_generic_reloc
, /* special_function */
574 "R_PPC64_UADDR32", /* name */
575 FALSE
, /* partial_inplace */
577 0xffffffff, /* dst_mask */
578 FALSE
), /* pcrel_offset */
580 /* Like R_PPC64_ADDR16, but may be unaligned. */
581 HOWTO (R_PPC64_UADDR16
, /* type */
583 1, /* size (0 = byte, 1 = short, 2 = long) */
585 FALSE
, /* pc_relative */
587 complain_overflow_bitfield
, /* complain_on_overflow */
588 bfd_elf_generic_reloc
, /* special_function */
589 "R_PPC64_UADDR16", /* name */
590 FALSE
, /* partial_inplace */
592 0xffff, /* dst_mask */
593 FALSE
), /* pcrel_offset */
595 /* 32-bit PC relative. */
596 HOWTO (R_PPC64_REL32
, /* type */
598 2, /* size (0 = byte, 1 = short, 2 = long) */
600 TRUE
, /* pc_relative */
602 /* FIXME: Verify. Was complain_overflow_bitfield. */
603 complain_overflow_signed
, /* complain_on_overflow */
604 bfd_elf_generic_reloc
, /* special_function */
605 "R_PPC64_REL32", /* name */
606 FALSE
, /* partial_inplace */
608 0xffffffff, /* dst_mask */
609 TRUE
), /* pcrel_offset */
611 /* 32-bit relocation to the symbol's procedure linkage table. */
612 HOWTO (R_PPC64_PLT32
, /* type */
614 2, /* size (0 = byte, 1 = short, 2 = long) */
616 FALSE
, /* pc_relative */
618 complain_overflow_bitfield
, /* complain_on_overflow */
619 ppc64_elf_unhandled_reloc
, /* special_function */
620 "R_PPC64_PLT32", /* name */
621 FALSE
, /* partial_inplace */
623 0xffffffff, /* dst_mask */
624 FALSE
), /* pcrel_offset */
626 /* 32-bit PC relative relocation to the symbol's procedure linkage table.
627 FIXME: R_PPC64_PLTREL32 not supported. */
628 HOWTO (R_PPC64_PLTREL32
, /* type */
630 2, /* size (0 = byte, 1 = short, 2 = long) */
632 TRUE
, /* pc_relative */
634 complain_overflow_signed
, /* complain_on_overflow */
635 bfd_elf_generic_reloc
, /* special_function */
636 "R_PPC64_PLTREL32", /* name */
637 FALSE
, /* partial_inplace */
639 0xffffffff, /* dst_mask */
640 TRUE
), /* pcrel_offset */
642 /* Like R_PPC64_ADDR16_LO, but referring to the PLT table entry for
644 HOWTO (R_PPC64_PLT16_LO
, /* type */
646 1, /* size (0 = byte, 1 = short, 2 = long) */
648 FALSE
, /* pc_relative */
650 complain_overflow_dont
, /* complain_on_overflow */
651 ppc64_elf_unhandled_reloc
, /* special_function */
652 "R_PPC64_PLT16_LO", /* name */
653 FALSE
, /* partial_inplace */
655 0xffff, /* dst_mask */
656 FALSE
), /* pcrel_offset */
658 /* Like R_PPC64_ADDR16_HI, but referring to the PLT table entry for
660 HOWTO (R_PPC64_PLT16_HI
, /* type */
662 1, /* size (0 = byte, 1 = short, 2 = long) */
664 FALSE
, /* pc_relative */
666 complain_overflow_dont
, /* complain_on_overflow */
667 ppc64_elf_unhandled_reloc
, /* special_function */
668 "R_PPC64_PLT16_HI", /* name */
669 FALSE
, /* partial_inplace */
671 0xffff, /* dst_mask */
672 FALSE
), /* pcrel_offset */
674 /* Like R_PPC64_ADDR16_HA, but referring to the PLT table entry for
676 HOWTO (R_PPC64_PLT16_HA
, /* type */
678 1, /* size (0 = byte, 1 = short, 2 = long) */
680 FALSE
, /* pc_relative */
682 complain_overflow_dont
, /* complain_on_overflow */
683 ppc64_elf_unhandled_reloc
, /* special_function */
684 "R_PPC64_PLT16_HA", /* name */
685 FALSE
, /* partial_inplace */
687 0xffff, /* dst_mask */
688 FALSE
), /* pcrel_offset */
690 /* 16-bit section relative relocation. */
691 HOWTO (R_PPC64_SECTOFF
, /* type */
693 1, /* size (0 = byte, 1 = short, 2 = long) */
695 FALSE
, /* pc_relative */
697 complain_overflow_bitfield
, /* complain_on_overflow */
698 ppc64_elf_sectoff_reloc
, /* special_function */
699 "R_PPC64_SECTOFF", /* name */
700 FALSE
, /* partial_inplace */
702 0xffff, /* dst_mask */
703 FALSE
), /* pcrel_offset */
705 /* Like R_PPC64_SECTOFF, but no overflow warning. */
706 HOWTO (R_PPC64_SECTOFF_LO
, /* type */
708 1, /* size (0 = byte, 1 = short, 2 = long) */
710 FALSE
, /* pc_relative */
712 complain_overflow_dont
, /* complain_on_overflow */
713 ppc64_elf_sectoff_reloc
, /* special_function */
714 "R_PPC64_SECTOFF_LO", /* name */
715 FALSE
, /* partial_inplace */
717 0xffff, /* dst_mask */
718 FALSE
), /* pcrel_offset */
720 /* 16-bit upper half section relative relocation. */
721 HOWTO (R_PPC64_SECTOFF_HI
, /* type */
723 1, /* size (0 = byte, 1 = short, 2 = long) */
725 FALSE
, /* pc_relative */
727 complain_overflow_dont
, /* complain_on_overflow */
728 ppc64_elf_sectoff_reloc
, /* special_function */
729 "R_PPC64_SECTOFF_HI", /* name */
730 FALSE
, /* partial_inplace */
732 0xffff, /* dst_mask */
733 FALSE
), /* pcrel_offset */
735 /* 16-bit upper half adjusted section relative relocation. */
736 HOWTO (R_PPC64_SECTOFF_HA
, /* type */
738 1, /* size (0 = byte, 1 = short, 2 = long) */
740 FALSE
, /* pc_relative */
742 complain_overflow_dont
, /* complain_on_overflow */
743 ppc64_elf_sectoff_ha_reloc
, /* special_function */
744 "R_PPC64_SECTOFF_HA", /* name */
745 FALSE
, /* partial_inplace */
747 0xffff, /* dst_mask */
748 FALSE
), /* pcrel_offset */
750 /* Like R_PPC64_REL24 without touching the two least significant bits. */
751 HOWTO (R_PPC64_REL30
, /* type */
753 2, /* size (0 = byte, 1 = short, 2 = long) */
755 TRUE
, /* pc_relative */
757 complain_overflow_dont
, /* complain_on_overflow */
758 bfd_elf_generic_reloc
, /* special_function */
759 "R_PPC64_REL30", /* name */
760 FALSE
, /* partial_inplace */
762 0xfffffffc, /* dst_mask */
763 TRUE
), /* pcrel_offset */
765 /* Relocs in the 64-bit PowerPC ELF ABI, not in the 32-bit ABI. */
767 /* A standard 64-bit relocation. */
768 HOWTO (R_PPC64_ADDR64
, /* type */
770 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
772 FALSE
, /* pc_relative */
774 complain_overflow_dont
, /* complain_on_overflow */
775 bfd_elf_generic_reloc
, /* special_function */
776 "R_PPC64_ADDR64", /* name */
777 FALSE
, /* partial_inplace */
779 ONES (64), /* dst_mask */
780 FALSE
), /* pcrel_offset */
782 /* The bits 32-47 of an address. */
783 HOWTO (R_PPC64_ADDR16_HIGHER
, /* type */
785 1, /* size (0 = byte, 1 = short, 2 = long) */
787 FALSE
, /* pc_relative */
789 complain_overflow_dont
, /* complain_on_overflow */
790 bfd_elf_generic_reloc
, /* special_function */
791 "R_PPC64_ADDR16_HIGHER", /* name */
792 FALSE
, /* partial_inplace */
794 0xffff, /* dst_mask */
795 FALSE
), /* pcrel_offset */
797 /* The bits 32-47 of an address, plus 1 if the contents of the low
798 16 bits, treated as a signed number, is negative. */
799 HOWTO (R_PPC64_ADDR16_HIGHERA
, /* type */
801 1, /* size (0 = byte, 1 = short, 2 = long) */
803 FALSE
, /* pc_relative */
805 complain_overflow_dont
, /* complain_on_overflow */
806 ppc64_elf_ha_reloc
, /* special_function */
807 "R_PPC64_ADDR16_HIGHERA", /* name */
808 FALSE
, /* partial_inplace */
810 0xffff, /* dst_mask */
811 FALSE
), /* pcrel_offset */
813 /* The bits 48-63 of an address. */
814 HOWTO (R_PPC64_ADDR16_HIGHEST
,/* type */
816 1, /* size (0 = byte, 1 = short, 2 = long) */
818 FALSE
, /* pc_relative */
820 complain_overflow_dont
, /* complain_on_overflow */
821 bfd_elf_generic_reloc
, /* special_function */
822 "R_PPC64_ADDR16_HIGHEST", /* name */
823 FALSE
, /* partial_inplace */
825 0xffff, /* dst_mask */
826 FALSE
), /* pcrel_offset */
828 /* The bits 48-63 of an address, plus 1 if the contents of the low
829 16 bits, treated as a signed number, is negative. */
830 HOWTO (R_PPC64_ADDR16_HIGHESTA
,/* type */
832 1, /* size (0 = byte, 1 = short, 2 = long) */
834 FALSE
, /* pc_relative */
836 complain_overflow_dont
, /* complain_on_overflow */
837 ppc64_elf_ha_reloc
, /* special_function */
838 "R_PPC64_ADDR16_HIGHESTA", /* name */
839 FALSE
, /* partial_inplace */
841 0xffff, /* dst_mask */
842 FALSE
), /* pcrel_offset */
844 /* Like ADDR64, but may be unaligned. */
845 HOWTO (R_PPC64_UADDR64
, /* type */
847 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
849 FALSE
, /* pc_relative */
851 complain_overflow_dont
, /* complain_on_overflow */
852 bfd_elf_generic_reloc
, /* special_function */
853 "R_PPC64_UADDR64", /* name */
854 FALSE
, /* partial_inplace */
856 ONES (64), /* dst_mask */
857 FALSE
), /* pcrel_offset */
859 /* 64-bit relative relocation. */
860 HOWTO (R_PPC64_REL64
, /* type */
862 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
864 TRUE
, /* pc_relative */
866 complain_overflow_dont
, /* complain_on_overflow */
867 bfd_elf_generic_reloc
, /* special_function */
868 "R_PPC64_REL64", /* name */
869 FALSE
, /* partial_inplace */
871 ONES (64), /* dst_mask */
872 TRUE
), /* pcrel_offset */
874 /* 64-bit relocation to the symbol's procedure linkage table. */
875 HOWTO (R_PPC64_PLT64
, /* type */
877 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
879 FALSE
, /* pc_relative */
881 complain_overflow_dont
, /* complain_on_overflow */
882 ppc64_elf_unhandled_reloc
, /* special_function */
883 "R_PPC64_PLT64", /* name */
884 FALSE
, /* partial_inplace */
886 ONES (64), /* dst_mask */
887 FALSE
), /* pcrel_offset */
889 /* 64-bit PC relative relocation to the symbol's procedure linkage
891 /* FIXME: R_PPC64_PLTREL64 not supported. */
892 HOWTO (R_PPC64_PLTREL64
, /* type */
894 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
896 TRUE
, /* pc_relative */
898 complain_overflow_dont
, /* complain_on_overflow */
899 ppc64_elf_unhandled_reloc
, /* special_function */
900 "R_PPC64_PLTREL64", /* name */
901 FALSE
, /* partial_inplace */
903 ONES (64), /* dst_mask */
904 TRUE
), /* pcrel_offset */
906 /* 16 bit TOC-relative relocation. */
908 /* R_PPC64_TOC16 47 half16* S + A - .TOC. */
909 HOWTO (R_PPC64_TOC16
, /* type */
911 1, /* size (0 = byte, 1 = short, 2 = long) */
913 FALSE
, /* pc_relative */
915 complain_overflow_signed
, /* complain_on_overflow */
916 ppc64_elf_toc_reloc
, /* special_function */
917 "R_PPC64_TOC16", /* name */
918 FALSE
, /* partial_inplace */
920 0xffff, /* dst_mask */
921 FALSE
), /* pcrel_offset */
923 /* 16 bit TOC-relative relocation without overflow. */
925 /* R_PPC64_TOC16_LO 48 half16 #lo (S + A - .TOC.) */
926 HOWTO (R_PPC64_TOC16_LO
, /* type */
928 1, /* size (0 = byte, 1 = short, 2 = long) */
930 FALSE
, /* pc_relative */
932 complain_overflow_dont
, /* complain_on_overflow */
933 ppc64_elf_toc_reloc
, /* special_function */
934 "R_PPC64_TOC16_LO", /* name */
935 FALSE
, /* partial_inplace */
937 0xffff, /* dst_mask */
938 FALSE
), /* pcrel_offset */
940 /* 16 bit TOC-relative relocation, high 16 bits. */
942 /* R_PPC64_TOC16_HI 49 half16 #hi (S + A - .TOC.) */
943 HOWTO (R_PPC64_TOC16_HI
, /* type */
945 1, /* size (0 = byte, 1 = short, 2 = long) */
947 FALSE
, /* pc_relative */
949 complain_overflow_dont
, /* complain_on_overflow */
950 ppc64_elf_toc_reloc
, /* special_function */
951 "R_PPC64_TOC16_HI", /* name */
952 FALSE
, /* partial_inplace */
954 0xffff, /* dst_mask */
955 FALSE
), /* pcrel_offset */
957 /* 16 bit TOC-relative relocation, high 16 bits, plus 1 if the
958 contents of the low 16 bits, treated as a signed number, is
961 /* R_PPC64_TOC16_HA 50 half16 #ha (S + A - .TOC.) */
962 HOWTO (R_PPC64_TOC16_HA
, /* type */
964 1, /* size (0 = byte, 1 = short, 2 = long) */
966 FALSE
, /* pc_relative */
968 complain_overflow_dont
, /* complain_on_overflow */
969 ppc64_elf_toc_ha_reloc
, /* special_function */
970 "R_PPC64_TOC16_HA", /* name */
971 FALSE
, /* partial_inplace */
973 0xffff, /* dst_mask */
974 FALSE
), /* pcrel_offset */
976 /* 64-bit relocation; insert value of TOC base (.TOC.). */
978 /* R_PPC64_TOC 51 doubleword64 .TOC. */
979 HOWTO (R_PPC64_TOC
, /* type */
981 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
983 FALSE
, /* pc_relative */
985 complain_overflow_bitfield
, /* complain_on_overflow */
986 ppc64_elf_toc64_reloc
, /* special_function */
987 "R_PPC64_TOC", /* name */
988 FALSE
, /* partial_inplace */
990 ONES (64), /* dst_mask */
991 FALSE
), /* pcrel_offset */
993 /* Like R_PPC64_GOT16, but also informs the link editor that the
994 value to relocate may (!) refer to a PLT entry which the link
995 editor (a) may replace with the symbol value. If the link editor
996 is unable to fully resolve the symbol, it may (b) create a PLT
997 entry and store the address to the new PLT entry in the GOT.
998 This permits lazy resolution of function symbols at run time.
999 The link editor may also skip all of this and just (c) emit a
1000 R_PPC64_GLOB_DAT to tie the symbol to the GOT entry. */
1001 /* FIXME: R_PPC64_PLTGOT16 not implemented. */
1002 HOWTO (R_PPC64_PLTGOT16
, /* type */
1004 1, /* size (0 = byte, 1 = short, 2 = long) */
1006 FALSE
, /* pc_relative */
1008 complain_overflow_signed
, /* complain_on_overflow */
1009 ppc64_elf_unhandled_reloc
, /* special_function */
1010 "R_PPC64_PLTGOT16", /* name */
1011 FALSE
, /* partial_inplace */
1013 0xffff, /* dst_mask */
1014 FALSE
), /* pcrel_offset */
1016 /* Like R_PPC64_PLTGOT16, but without overflow. */
1017 /* FIXME: R_PPC64_PLTGOT16_LO not implemented. */
1018 HOWTO (R_PPC64_PLTGOT16_LO
, /* type */
1020 1, /* size (0 = byte, 1 = short, 2 = long) */
1022 FALSE
, /* pc_relative */
1024 complain_overflow_dont
, /* complain_on_overflow */
1025 ppc64_elf_unhandled_reloc
, /* special_function */
1026 "R_PPC64_PLTGOT16_LO", /* name */
1027 FALSE
, /* partial_inplace */
1029 0xffff, /* dst_mask */
1030 FALSE
), /* pcrel_offset */
1032 /* Like R_PPC64_PLT_GOT16, but using bits 16-31 of the address. */
1033 /* FIXME: R_PPC64_PLTGOT16_HI not implemented. */
1034 HOWTO (R_PPC64_PLTGOT16_HI
, /* type */
1035 16, /* rightshift */
1036 1, /* size (0 = byte, 1 = short, 2 = long) */
1038 FALSE
, /* pc_relative */
1040 complain_overflow_dont
, /* complain_on_overflow */
1041 ppc64_elf_unhandled_reloc
, /* special_function */
1042 "R_PPC64_PLTGOT16_HI", /* name */
1043 FALSE
, /* partial_inplace */
1045 0xffff, /* dst_mask */
1046 FALSE
), /* pcrel_offset */
1048 /* Like R_PPC64_PLT_GOT16, but using bits 16-31 of the address, plus
1049 1 if the contents of the low 16 bits, treated as a signed number,
1051 /* FIXME: R_PPC64_PLTGOT16_HA not implemented. */
1052 HOWTO (R_PPC64_PLTGOT16_HA
, /* type */
1053 16, /* rightshift */
1054 1, /* size (0 = byte, 1 = short, 2 = long) */
1056 FALSE
, /* pc_relative */
1058 complain_overflow_dont
,/* complain_on_overflow */
1059 ppc64_elf_unhandled_reloc
, /* special_function */
1060 "R_PPC64_PLTGOT16_HA", /* name */
1061 FALSE
, /* partial_inplace */
1063 0xffff, /* dst_mask */
1064 FALSE
), /* pcrel_offset */
1066 /* Like R_PPC64_ADDR16, but for instructions with a DS field. */
1067 HOWTO (R_PPC64_ADDR16_DS
, /* type */
1069 1, /* size (0 = byte, 1 = short, 2 = long) */
1071 FALSE
, /* pc_relative */
1073 complain_overflow_bitfield
, /* complain_on_overflow */
1074 bfd_elf_generic_reloc
, /* special_function */
1075 "R_PPC64_ADDR16_DS", /* name */
1076 FALSE
, /* partial_inplace */
1078 0xfffc, /* dst_mask */
1079 FALSE
), /* pcrel_offset */
1081 /* Like R_PPC64_ADDR16_LO, but for instructions with a DS field. */
1082 HOWTO (R_PPC64_ADDR16_LO_DS
, /* type */
1084 1, /* size (0 = byte, 1 = short, 2 = long) */
1086 FALSE
, /* pc_relative */
1088 complain_overflow_dont
,/* complain_on_overflow */
1089 bfd_elf_generic_reloc
, /* special_function */
1090 "R_PPC64_ADDR16_LO_DS",/* name */
1091 FALSE
, /* partial_inplace */
1093 0xfffc, /* dst_mask */
1094 FALSE
), /* pcrel_offset */
1096 /* Like R_PPC64_GOT16, but for instructions with a DS field. */
1097 HOWTO (R_PPC64_GOT16_DS
, /* type */
1099 1, /* size (0 = byte, 1 = short, 2 = long) */
1101 FALSE
, /* pc_relative */
1103 complain_overflow_signed
, /* complain_on_overflow */
1104 ppc64_elf_unhandled_reloc
, /* special_function */
1105 "R_PPC64_GOT16_DS", /* name */
1106 FALSE
, /* partial_inplace */
1108 0xfffc, /* dst_mask */
1109 FALSE
), /* pcrel_offset */
1111 /* Like R_PPC64_GOT16_LO, but for instructions with a DS field. */
1112 HOWTO (R_PPC64_GOT16_LO_DS
, /* type */
1114 1, /* size (0 = byte, 1 = short, 2 = long) */
1116 FALSE
, /* pc_relative */
1118 complain_overflow_dont
, /* complain_on_overflow */
1119 ppc64_elf_unhandled_reloc
, /* special_function */
1120 "R_PPC64_GOT16_LO_DS", /* name */
1121 FALSE
, /* partial_inplace */
1123 0xfffc, /* dst_mask */
1124 FALSE
), /* pcrel_offset */
1126 /* Like R_PPC64_PLT16_LO, but for instructions with a DS field. */
1127 HOWTO (R_PPC64_PLT16_LO_DS
, /* type */
1129 1, /* size (0 = byte, 1 = short, 2 = long) */
1131 FALSE
, /* pc_relative */
1133 complain_overflow_dont
, /* complain_on_overflow */
1134 ppc64_elf_unhandled_reloc
, /* special_function */
1135 "R_PPC64_PLT16_LO_DS", /* name */
1136 FALSE
, /* partial_inplace */
1138 0xfffc, /* dst_mask */
1139 FALSE
), /* pcrel_offset */
1141 /* Like R_PPC64_SECTOFF, but for instructions with a DS field. */
1142 HOWTO (R_PPC64_SECTOFF_DS
, /* type */
1144 1, /* size (0 = byte, 1 = short, 2 = long) */
1146 FALSE
, /* pc_relative */
1148 complain_overflow_bitfield
, /* complain_on_overflow */
1149 ppc64_elf_sectoff_reloc
, /* special_function */
1150 "R_PPC64_SECTOFF_DS", /* name */
1151 FALSE
, /* partial_inplace */
1153 0xfffc, /* dst_mask */
1154 FALSE
), /* pcrel_offset */
1156 /* Like R_PPC64_SECTOFF_LO, but for instructions with a DS field. */
1157 HOWTO (R_PPC64_SECTOFF_LO_DS
, /* type */
1159 1, /* size (0 = byte, 1 = short, 2 = long) */
1161 FALSE
, /* pc_relative */
1163 complain_overflow_dont
, /* complain_on_overflow */
1164 ppc64_elf_sectoff_reloc
, /* special_function */
1165 "R_PPC64_SECTOFF_LO_DS",/* name */
1166 FALSE
, /* partial_inplace */
1168 0xfffc, /* dst_mask */
1169 FALSE
), /* pcrel_offset */
1171 /* Like R_PPC64_TOC16, but for instructions with a DS field. */
1172 HOWTO (R_PPC64_TOC16_DS
, /* type */
1174 1, /* size (0 = byte, 1 = short, 2 = long) */
1176 FALSE
, /* pc_relative */
1178 complain_overflow_signed
, /* complain_on_overflow */
1179 ppc64_elf_toc_reloc
, /* special_function */
1180 "R_PPC64_TOC16_DS", /* name */
1181 FALSE
, /* partial_inplace */
1183 0xfffc, /* dst_mask */
1184 FALSE
), /* pcrel_offset */
1186 /* Like R_PPC64_TOC16_LO, but for instructions with a DS field. */
1187 HOWTO (R_PPC64_TOC16_LO_DS
, /* type */
1189 1, /* size (0 = byte, 1 = short, 2 = long) */
1191 FALSE
, /* pc_relative */
1193 complain_overflow_dont
, /* complain_on_overflow */
1194 ppc64_elf_toc_reloc
, /* special_function */
1195 "R_PPC64_TOC16_LO_DS", /* name */
1196 FALSE
, /* partial_inplace */
1198 0xfffc, /* dst_mask */
1199 FALSE
), /* pcrel_offset */
1201 /* Like R_PPC64_PLTGOT16, but for instructions with a DS field. */
1202 /* FIXME: R_PPC64_PLTGOT16_DS not implemented. */
1203 HOWTO (R_PPC64_PLTGOT16_DS
, /* type */
1205 1, /* size (0 = byte, 1 = short, 2 = long) */
1207 FALSE
, /* pc_relative */
1209 complain_overflow_signed
, /* complain_on_overflow */
1210 ppc64_elf_unhandled_reloc
, /* special_function */
1211 "R_PPC64_PLTGOT16_DS", /* name */
1212 FALSE
, /* partial_inplace */
1214 0xfffc, /* dst_mask */
1215 FALSE
), /* pcrel_offset */
1217 /* Like R_PPC64_PLTGOT16_LO, but for instructions with a DS field. */
1218 /* FIXME: R_PPC64_PLTGOT16_LO not implemented. */
1219 HOWTO (R_PPC64_PLTGOT16_LO_DS
,/* type */
1221 1, /* size (0 = byte, 1 = short, 2 = long) */
1223 FALSE
, /* pc_relative */
1225 complain_overflow_dont
, /* complain_on_overflow */
1226 ppc64_elf_unhandled_reloc
, /* special_function */
1227 "R_PPC64_PLTGOT16_LO_DS",/* name */
1228 FALSE
, /* partial_inplace */
1230 0xfffc, /* dst_mask */
1231 FALSE
), /* pcrel_offset */
1233 /* Marker reloc for TLS. */
1236 2, /* size (0 = byte, 1 = short, 2 = long) */
1238 FALSE
, /* pc_relative */
1240 complain_overflow_dont
, /* complain_on_overflow */
1241 bfd_elf_generic_reloc
, /* special_function */
1242 "R_PPC64_TLS", /* name */
1243 FALSE
, /* partial_inplace */
1246 FALSE
), /* pcrel_offset */
1248 /* Computes the load module index of the load module that contains the
1249 definition of its TLS sym. */
1250 HOWTO (R_PPC64_DTPMOD64
,
1252 4, /* size (0 = byte, 1 = short, 2 = long) */
1254 FALSE
, /* pc_relative */
1256 complain_overflow_dont
, /* complain_on_overflow */
1257 ppc64_elf_unhandled_reloc
, /* special_function */
1258 "R_PPC64_DTPMOD64", /* name */
1259 FALSE
, /* partial_inplace */
1261 ONES (64), /* dst_mask */
1262 FALSE
), /* pcrel_offset */
1264 /* Computes a dtv-relative displacement, the difference between the value
1265 of sym+add and the base address of the thread-local storage block that
1266 contains the definition of sym, minus 0x8000. */
1267 HOWTO (R_PPC64_DTPREL64
,
1269 4, /* size (0 = byte, 1 = short, 2 = long) */
1271 FALSE
, /* pc_relative */
1273 complain_overflow_dont
, /* complain_on_overflow */
1274 ppc64_elf_unhandled_reloc
, /* special_function */
1275 "R_PPC64_DTPREL64", /* name */
1276 FALSE
, /* partial_inplace */
1278 ONES (64), /* dst_mask */
1279 FALSE
), /* pcrel_offset */
1281 /* A 16 bit dtprel reloc. */
1282 HOWTO (R_PPC64_DTPREL16
,
1284 1, /* size (0 = byte, 1 = short, 2 = long) */
1286 FALSE
, /* pc_relative */
1288 complain_overflow_signed
, /* complain_on_overflow */
1289 ppc64_elf_unhandled_reloc
, /* special_function */
1290 "R_PPC64_DTPREL16", /* name */
1291 FALSE
, /* partial_inplace */
1293 0xffff, /* dst_mask */
1294 FALSE
), /* pcrel_offset */
1296 /* Like DTPREL16, but no overflow. */
1297 HOWTO (R_PPC64_DTPREL16_LO
,
1299 1, /* size (0 = byte, 1 = short, 2 = long) */
1301 FALSE
, /* pc_relative */
1303 complain_overflow_dont
, /* complain_on_overflow */
1304 ppc64_elf_unhandled_reloc
, /* special_function */
1305 "R_PPC64_DTPREL16_LO", /* name */
1306 FALSE
, /* partial_inplace */
1308 0xffff, /* dst_mask */
1309 FALSE
), /* pcrel_offset */
1311 /* Like DTPREL16_LO, but next higher group of 16 bits. */
1312 HOWTO (R_PPC64_DTPREL16_HI
,
1313 16, /* rightshift */
1314 1, /* size (0 = byte, 1 = short, 2 = long) */
1316 FALSE
, /* pc_relative */
1318 complain_overflow_dont
, /* complain_on_overflow */
1319 ppc64_elf_unhandled_reloc
, /* special_function */
1320 "R_PPC64_DTPREL16_HI", /* name */
1321 FALSE
, /* partial_inplace */
1323 0xffff, /* dst_mask */
1324 FALSE
), /* pcrel_offset */
1326 /* Like DTPREL16_HI, but adjust for low 16 bits. */
1327 HOWTO (R_PPC64_DTPREL16_HA
,
1328 16, /* rightshift */
1329 1, /* size (0 = byte, 1 = short, 2 = long) */
1331 FALSE
, /* pc_relative */
1333 complain_overflow_dont
, /* complain_on_overflow */
1334 ppc64_elf_unhandled_reloc
, /* special_function */
1335 "R_PPC64_DTPREL16_HA", /* name */
1336 FALSE
, /* partial_inplace */
1338 0xffff, /* dst_mask */
1339 FALSE
), /* pcrel_offset */
1341 /* Like DTPREL16_HI, but next higher group of 16 bits. */
1342 HOWTO (R_PPC64_DTPREL16_HIGHER
,
1343 32, /* rightshift */
1344 1, /* size (0 = byte, 1 = short, 2 = long) */
1346 FALSE
, /* pc_relative */
1348 complain_overflow_dont
, /* complain_on_overflow */
1349 ppc64_elf_unhandled_reloc
, /* special_function */
1350 "R_PPC64_DTPREL16_HIGHER", /* name */
1351 FALSE
, /* partial_inplace */
1353 0xffff, /* dst_mask */
1354 FALSE
), /* pcrel_offset */
1356 /* Like DTPREL16_HIGHER, but adjust for low 16 bits. */
1357 HOWTO (R_PPC64_DTPREL16_HIGHERA
,
1358 32, /* rightshift */
1359 1, /* size (0 = byte, 1 = short, 2 = long) */
1361 FALSE
, /* pc_relative */
1363 complain_overflow_dont
, /* complain_on_overflow */
1364 ppc64_elf_unhandled_reloc
, /* special_function */
1365 "R_PPC64_DTPREL16_HIGHERA", /* name */
1366 FALSE
, /* partial_inplace */
1368 0xffff, /* dst_mask */
1369 FALSE
), /* pcrel_offset */
1371 /* Like DTPREL16_HIGHER, but next higher group of 16 bits. */
1372 HOWTO (R_PPC64_DTPREL16_HIGHEST
,
1373 48, /* rightshift */
1374 1, /* size (0 = byte, 1 = short, 2 = long) */
1376 FALSE
, /* pc_relative */
1378 complain_overflow_dont
, /* complain_on_overflow */
1379 ppc64_elf_unhandled_reloc
, /* special_function */
1380 "R_PPC64_DTPREL16_HIGHEST", /* name */
1381 FALSE
, /* partial_inplace */
1383 0xffff, /* dst_mask */
1384 FALSE
), /* pcrel_offset */
1386 /* Like DTPREL16_HIGHEST, but adjust for low 16 bits. */
1387 HOWTO (R_PPC64_DTPREL16_HIGHESTA
,
1388 48, /* rightshift */
1389 1, /* size (0 = byte, 1 = short, 2 = long) */
1391 FALSE
, /* pc_relative */
1393 complain_overflow_dont
, /* complain_on_overflow */
1394 ppc64_elf_unhandled_reloc
, /* special_function */
1395 "R_PPC64_DTPREL16_HIGHESTA", /* name */
1396 FALSE
, /* partial_inplace */
1398 0xffff, /* dst_mask */
1399 FALSE
), /* pcrel_offset */
1401 /* Like DTPREL16, but for insns with a DS field. */
1402 HOWTO (R_PPC64_DTPREL16_DS
,
1404 1, /* size (0 = byte, 1 = short, 2 = long) */
1406 FALSE
, /* pc_relative */
1408 complain_overflow_signed
, /* complain_on_overflow */
1409 ppc64_elf_unhandled_reloc
, /* special_function */
1410 "R_PPC64_DTPREL16_DS", /* name */
1411 FALSE
, /* partial_inplace */
1413 0xfffc, /* dst_mask */
1414 FALSE
), /* pcrel_offset */
1416 /* Like DTPREL16_DS, but no overflow. */
1417 HOWTO (R_PPC64_DTPREL16_LO_DS
,
1419 1, /* size (0 = byte, 1 = short, 2 = long) */
1421 FALSE
, /* pc_relative */
1423 complain_overflow_dont
, /* complain_on_overflow */
1424 ppc64_elf_unhandled_reloc
, /* special_function */
1425 "R_PPC64_DTPREL16_LO_DS", /* name */
1426 FALSE
, /* partial_inplace */
1428 0xfffc, /* dst_mask */
1429 FALSE
), /* pcrel_offset */
1431 /* Computes a tp-relative displacement, the difference between the value of
1432 sym+add and the value of the thread pointer (r13). */
1433 HOWTO (R_PPC64_TPREL64
,
1435 4, /* size (0 = byte, 1 = short, 2 = long) */
1437 FALSE
, /* pc_relative */
1439 complain_overflow_dont
, /* complain_on_overflow */
1440 ppc64_elf_unhandled_reloc
, /* special_function */
1441 "R_PPC64_TPREL64", /* name */
1442 FALSE
, /* partial_inplace */
1444 ONES (64), /* dst_mask */
1445 FALSE
), /* pcrel_offset */
1447 /* A 16 bit tprel reloc. */
1448 HOWTO (R_PPC64_TPREL16
,
1450 1, /* size (0 = byte, 1 = short, 2 = long) */
1452 FALSE
, /* pc_relative */
1454 complain_overflow_signed
, /* complain_on_overflow */
1455 ppc64_elf_unhandled_reloc
, /* special_function */
1456 "R_PPC64_TPREL16", /* name */
1457 FALSE
, /* partial_inplace */
1459 0xffff, /* dst_mask */
1460 FALSE
), /* pcrel_offset */
1462 /* Like TPREL16, but no overflow. */
1463 HOWTO (R_PPC64_TPREL16_LO
,
1465 1, /* size (0 = byte, 1 = short, 2 = long) */
1467 FALSE
, /* pc_relative */
1469 complain_overflow_dont
, /* complain_on_overflow */
1470 ppc64_elf_unhandled_reloc
, /* special_function */
1471 "R_PPC64_TPREL16_LO", /* name */
1472 FALSE
, /* partial_inplace */
1474 0xffff, /* dst_mask */
1475 FALSE
), /* pcrel_offset */
1477 /* Like TPREL16_LO, but next higher group of 16 bits. */
1478 HOWTO (R_PPC64_TPREL16_HI
,
1479 16, /* rightshift */
1480 1, /* size (0 = byte, 1 = short, 2 = long) */
1482 FALSE
, /* pc_relative */
1484 complain_overflow_dont
, /* complain_on_overflow */
1485 ppc64_elf_unhandled_reloc
, /* special_function */
1486 "R_PPC64_TPREL16_HI", /* name */
1487 FALSE
, /* partial_inplace */
1489 0xffff, /* dst_mask */
1490 FALSE
), /* pcrel_offset */
1492 /* Like TPREL16_HI, but adjust for low 16 bits. */
1493 HOWTO (R_PPC64_TPREL16_HA
,
1494 16, /* rightshift */
1495 1, /* size (0 = byte, 1 = short, 2 = long) */
1497 FALSE
, /* pc_relative */
1499 complain_overflow_dont
, /* complain_on_overflow */
1500 ppc64_elf_unhandled_reloc
, /* special_function */
1501 "R_PPC64_TPREL16_HA", /* name */
1502 FALSE
, /* partial_inplace */
1504 0xffff, /* dst_mask */
1505 FALSE
), /* pcrel_offset */
1507 /* Like TPREL16_HI, but next higher group of 16 bits. */
1508 HOWTO (R_PPC64_TPREL16_HIGHER
,
1509 32, /* rightshift */
1510 1, /* size (0 = byte, 1 = short, 2 = long) */
1512 FALSE
, /* pc_relative */
1514 complain_overflow_dont
, /* complain_on_overflow */
1515 ppc64_elf_unhandled_reloc
, /* special_function */
1516 "R_PPC64_TPREL16_HIGHER", /* name */
1517 FALSE
, /* partial_inplace */
1519 0xffff, /* dst_mask */
1520 FALSE
), /* pcrel_offset */
1522 /* Like TPREL16_HIGHER, but adjust for low 16 bits. */
1523 HOWTO (R_PPC64_TPREL16_HIGHERA
,
1524 32, /* rightshift */
1525 1, /* size (0 = byte, 1 = short, 2 = long) */
1527 FALSE
, /* pc_relative */
1529 complain_overflow_dont
, /* complain_on_overflow */
1530 ppc64_elf_unhandled_reloc
, /* special_function */
1531 "R_PPC64_TPREL16_HIGHERA", /* name */
1532 FALSE
, /* partial_inplace */
1534 0xffff, /* dst_mask */
1535 FALSE
), /* pcrel_offset */
1537 /* Like TPREL16_HIGHER, but next higher group of 16 bits. */
1538 HOWTO (R_PPC64_TPREL16_HIGHEST
,
1539 48, /* rightshift */
1540 1, /* size (0 = byte, 1 = short, 2 = long) */
1542 FALSE
, /* pc_relative */
1544 complain_overflow_dont
, /* complain_on_overflow */
1545 ppc64_elf_unhandled_reloc
, /* special_function */
1546 "R_PPC64_TPREL16_HIGHEST", /* name */
1547 FALSE
, /* partial_inplace */
1549 0xffff, /* dst_mask */
1550 FALSE
), /* pcrel_offset */
1552 /* Like TPREL16_HIGHEST, but adjust for low 16 bits. */
1553 HOWTO (R_PPC64_TPREL16_HIGHESTA
,
1554 48, /* rightshift */
1555 1, /* size (0 = byte, 1 = short, 2 = long) */
1557 FALSE
, /* pc_relative */
1559 complain_overflow_dont
, /* complain_on_overflow */
1560 ppc64_elf_unhandled_reloc
, /* special_function */
1561 "R_PPC64_TPREL16_HIGHESTA", /* name */
1562 FALSE
, /* partial_inplace */
1564 0xffff, /* dst_mask */
1565 FALSE
), /* pcrel_offset */
1567 /* Like TPREL16, but for insns with a DS field. */
1568 HOWTO (R_PPC64_TPREL16_DS
,
1570 1, /* size (0 = byte, 1 = short, 2 = long) */
1572 FALSE
, /* pc_relative */
1574 complain_overflow_signed
, /* complain_on_overflow */
1575 ppc64_elf_unhandled_reloc
, /* special_function */
1576 "R_PPC64_TPREL16_DS", /* name */
1577 FALSE
, /* partial_inplace */
1579 0xfffc, /* dst_mask */
1580 FALSE
), /* pcrel_offset */
1582 /* Like TPREL16_DS, but no overflow. */
1583 HOWTO (R_PPC64_TPREL16_LO_DS
,
1585 1, /* size (0 = byte, 1 = short, 2 = long) */
1587 FALSE
, /* pc_relative */
1589 complain_overflow_dont
, /* complain_on_overflow */
1590 ppc64_elf_unhandled_reloc
, /* special_function */
1591 "R_PPC64_TPREL16_LO_DS", /* name */
1592 FALSE
, /* partial_inplace */
1594 0xfffc, /* dst_mask */
1595 FALSE
), /* pcrel_offset */
1597 /* Allocates two contiguous entries in the GOT to hold a tls_index structure,
1598 with values (sym+add)@dtpmod and (sym+add)@dtprel, and computes the offset
1599 to the first entry relative to the TOC base (r2). */
1600 HOWTO (R_PPC64_GOT_TLSGD16
,
1602 1, /* size (0 = byte, 1 = short, 2 = long) */
1604 FALSE
, /* pc_relative */
1606 complain_overflow_signed
, /* complain_on_overflow */
1607 ppc64_elf_unhandled_reloc
, /* special_function */
1608 "R_PPC64_GOT_TLSGD16", /* name */
1609 FALSE
, /* partial_inplace */
1611 0xffff, /* dst_mask */
1612 FALSE
), /* pcrel_offset */
1614 /* Like GOT_TLSGD16, but no overflow. */
1615 HOWTO (R_PPC64_GOT_TLSGD16_LO
,
1617 1, /* size (0 = byte, 1 = short, 2 = long) */
1619 FALSE
, /* pc_relative */
1621 complain_overflow_dont
, /* complain_on_overflow */
1622 ppc64_elf_unhandled_reloc
, /* special_function */
1623 "R_PPC64_GOT_TLSGD16_LO", /* name */
1624 FALSE
, /* partial_inplace */
1626 0xffff, /* dst_mask */
1627 FALSE
), /* pcrel_offset */
1629 /* Like GOT_TLSGD16_LO, but next higher group of 16 bits. */
1630 HOWTO (R_PPC64_GOT_TLSGD16_HI
,
1631 16, /* rightshift */
1632 1, /* size (0 = byte, 1 = short, 2 = long) */
1634 FALSE
, /* pc_relative */
1636 complain_overflow_dont
, /* complain_on_overflow */
1637 ppc64_elf_unhandled_reloc
, /* special_function */
1638 "R_PPC64_GOT_TLSGD16_HI", /* name */
1639 FALSE
, /* partial_inplace */
1641 0xffff, /* dst_mask */
1642 FALSE
), /* pcrel_offset */
1644 /* Like GOT_TLSGD16_HI, but adjust for low 16 bits. */
1645 HOWTO (R_PPC64_GOT_TLSGD16_HA
,
1646 16, /* rightshift */
1647 1, /* size (0 = byte, 1 = short, 2 = long) */
1649 FALSE
, /* pc_relative */
1651 complain_overflow_dont
, /* complain_on_overflow */
1652 ppc64_elf_unhandled_reloc
, /* special_function */
1653 "R_PPC64_GOT_TLSGD16_HA", /* name */
1654 FALSE
, /* partial_inplace */
1656 0xffff, /* dst_mask */
1657 FALSE
), /* pcrel_offset */
1659 /* Allocates two contiguous entries in the GOT to hold a tls_index structure,
1660 with values (sym+add)@dtpmod and zero, and computes the offset to the
1661 first entry relative to the TOC base (r2). */
1662 HOWTO (R_PPC64_GOT_TLSLD16
,
1664 1, /* size (0 = byte, 1 = short, 2 = long) */
1666 FALSE
, /* pc_relative */
1668 complain_overflow_signed
, /* complain_on_overflow */
1669 ppc64_elf_unhandled_reloc
, /* special_function */
1670 "R_PPC64_GOT_TLSLD16", /* name */
1671 FALSE
, /* partial_inplace */
1673 0xffff, /* dst_mask */
1674 FALSE
), /* pcrel_offset */
1676 /* Like GOT_TLSLD16, but no overflow. */
1677 HOWTO (R_PPC64_GOT_TLSLD16_LO
,
1679 1, /* size (0 = byte, 1 = short, 2 = long) */
1681 FALSE
, /* pc_relative */
1683 complain_overflow_dont
, /* complain_on_overflow */
1684 ppc64_elf_unhandled_reloc
, /* special_function */
1685 "R_PPC64_GOT_TLSLD16_LO", /* name */
1686 FALSE
, /* partial_inplace */
1688 0xffff, /* dst_mask */
1689 FALSE
), /* pcrel_offset */
1691 /* Like GOT_TLSLD16_LO, but next higher group of 16 bits. */
1692 HOWTO (R_PPC64_GOT_TLSLD16_HI
,
1693 16, /* rightshift */
1694 1, /* size (0 = byte, 1 = short, 2 = long) */
1696 FALSE
, /* pc_relative */
1698 complain_overflow_dont
, /* complain_on_overflow */
1699 ppc64_elf_unhandled_reloc
, /* special_function */
1700 "R_PPC64_GOT_TLSLD16_HI", /* name */
1701 FALSE
, /* partial_inplace */
1703 0xffff, /* dst_mask */
1704 FALSE
), /* pcrel_offset */
1706 /* Like GOT_TLSLD16_HI, but adjust for low 16 bits. */
1707 HOWTO (R_PPC64_GOT_TLSLD16_HA
,
1708 16, /* rightshift */
1709 1, /* size (0 = byte, 1 = short, 2 = long) */
1711 FALSE
, /* pc_relative */
1713 complain_overflow_dont
, /* complain_on_overflow */
1714 ppc64_elf_unhandled_reloc
, /* special_function */
1715 "R_PPC64_GOT_TLSLD16_HA", /* name */
1716 FALSE
, /* partial_inplace */
1718 0xffff, /* dst_mask */
1719 FALSE
), /* pcrel_offset */
1721 /* Allocates an entry in the GOT with value (sym+add)@dtprel, and computes
1722 the offset to the entry relative to the TOC base (r2). */
1723 HOWTO (R_PPC64_GOT_DTPREL16_DS
,
1725 1, /* size (0 = byte, 1 = short, 2 = long) */
1727 FALSE
, /* pc_relative */
1729 complain_overflow_signed
, /* complain_on_overflow */
1730 ppc64_elf_unhandled_reloc
, /* special_function */
1731 "R_PPC64_GOT_DTPREL16_DS", /* name */
1732 FALSE
, /* partial_inplace */
1734 0xfffc, /* dst_mask */
1735 FALSE
), /* pcrel_offset */
1737 /* Like GOT_DTPREL16_DS, but no overflow. */
1738 HOWTO (R_PPC64_GOT_DTPREL16_LO_DS
,
1740 1, /* size (0 = byte, 1 = short, 2 = long) */
1742 FALSE
, /* pc_relative */
1744 complain_overflow_dont
, /* complain_on_overflow */
1745 ppc64_elf_unhandled_reloc
, /* special_function */
1746 "R_PPC64_GOT_DTPREL16_LO_DS", /* name */
1747 FALSE
, /* partial_inplace */
1749 0xfffc, /* dst_mask */
1750 FALSE
), /* pcrel_offset */
1752 /* Like GOT_DTPREL16_LO_DS, but next higher group of 16 bits. */
1753 HOWTO (R_PPC64_GOT_DTPREL16_HI
,
1754 16, /* rightshift */
1755 1, /* size (0 = byte, 1 = short, 2 = long) */
1757 FALSE
, /* pc_relative */
1759 complain_overflow_dont
, /* complain_on_overflow */
1760 ppc64_elf_unhandled_reloc
, /* special_function */
1761 "R_PPC64_GOT_DTPREL16_HI", /* name */
1762 FALSE
, /* partial_inplace */
1764 0xffff, /* dst_mask */
1765 FALSE
), /* pcrel_offset */
1767 /* Like GOT_DTPREL16_HI, but adjust for low 16 bits. */
1768 HOWTO (R_PPC64_GOT_DTPREL16_HA
,
1769 16, /* rightshift */
1770 1, /* size (0 = byte, 1 = short, 2 = long) */
1772 FALSE
, /* pc_relative */
1774 complain_overflow_dont
, /* complain_on_overflow */
1775 ppc64_elf_unhandled_reloc
, /* special_function */
1776 "R_PPC64_GOT_DTPREL16_HA", /* name */
1777 FALSE
, /* partial_inplace */
1779 0xffff, /* dst_mask */
1780 FALSE
), /* pcrel_offset */
1782 /* Allocates an entry in the GOT with value (sym+add)@tprel, and computes the
1783 offset to the entry relative to the TOC base (r2). */
1784 HOWTO (R_PPC64_GOT_TPREL16_DS
,
1786 1, /* size (0 = byte, 1 = short, 2 = long) */
1788 FALSE
, /* pc_relative */
1790 complain_overflow_signed
, /* complain_on_overflow */
1791 ppc64_elf_unhandled_reloc
, /* special_function */
1792 "R_PPC64_GOT_TPREL16_DS", /* name */
1793 FALSE
, /* partial_inplace */
1795 0xfffc, /* dst_mask */
1796 FALSE
), /* pcrel_offset */
1798 /* Like GOT_TPREL16_DS, but no overflow. */
1799 HOWTO (R_PPC64_GOT_TPREL16_LO_DS
,
1801 1, /* size (0 = byte, 1 = short, 2 = long) */
1803 FALSE
, /* pc_relative */
1805 complain_overflow_dont
, /* complain_on_overflow */
1806 ppc64_elf_unhandled_reloc
, /* special_function */
1807 "R_PPC64_GOT_TPREL16_LO_DS", /* name */
1808 FALSE
, /* partial_inplace */
1810 0xfffc, /* dst_mask */
1811 FALSE
), /* pcrel_offset */
1813 /* Like GOT_TPREL16_LO_DS, but next higher group of 16 bits. */
1814 HOWTO (R_PPC64_GOT_TPREL16_HI
,
1815 16, /* rightshift */
1816 1, /* size (0 = byte, 1 = short, 2 = long) */
1818 FALSE
, /* pc_relative */
1820 complain_overflow_dont
, /* complain_on_overflow */
1821 ppc64_elf_unhandled_reloc
, /* special_function */
1822 "R_PPC64_GOT_TPREL16_HI", /* name */
1823 FALSE
, /* partial_inplace */
1825 0xffff, /* dst_mask */
1826 FALSE
), /* pcrel_offset */
1828 /* Like GOT_TPREL16_HI, but adjust for low 16 bits. */
1829 HOWTO (R_PPC64_GOT_TPREL16_HA
,
1830 16, /* rightshift */
1831 1, /* size (0 = byte, 1 = short, 2 = long) */
1833 FALSE
, /* pc_relative */
1835 complain_overflow_dont
, /* complain_on_overflow */
1836 ppc64_elf_unhandled_reloc
, /* special_function */
1837 "R_PPC64_GOT_TPREL16_HA", /* name */
1838 FALSE
, /* partial_inplace */
1840 0xffff, /* dst_mask */
1841 FALSE
), /* pcrel_offset */
1843 /* GNU extension to record C++ vtable hierarchy. */
1844 HOWTO (R_PPC64_GNU_VTINHERIT
, /* type */
1846 0, /* size (0 = byte, 1 = short, 2 = long) */
1848 FALSE
, /* pc_relative */
1850 complain_overflow_dont
, /* complain_on_overflow */
1851 NULL
, /* special_function */
1852 "R_PPC64_GNU_VTINHERIT", /* name */
1853 FALSE
, /* partial_inplace */
1856 FALSE
), /* pcrel_offset */
1858 /* GNU extension to record C++ vtable member usage. */
1859 HOWTO (R_PPC64_GNU_VTENTRY
, /* type */
1861 0, /* size (0 = byte, 1 = short, 2 = long) */
1863 FALSE
, /* pc_relative */
1865 complain_overflow_dont
, /* complain_on_overflow */
1866 NULL
, /* special_function */
1867 "R_PPC64_GNU_VTENTRY", /* name */
1868 FALSE
, /* partial_inplace */
1871 FALSE
), /* pcrel_offset */
1875 /* Initialize the ppc64_elf_howto_table, so that linear accesses can
1879 ppc_howto_init (void)
1881 unsigned int i
, type
;
1884 i
< sizeof (ppc64_elf_howto_raw
) / sizeof (ppc64_elf_howto_raw
[0]);
1887 type
= ppc64_elf_howto_raw
[i
].type
;
1888 BFD_ASSERT (type
< (sizeof (ppc64_elf_howto_table
)
1889 / sizeof (ppc64_elf_howto_table
[0])));
1890 ppc64_elf_howto_table
[type
] = &ppc64_elf_howto_raw
[i
];
1894 static reloc_howto_type
*
1895 ppc64_elf_reloc_type_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
1896 bfd_reloc_code_real_type code
)
1898 enum elf_ppc64_reloc_type r
= R_PPC64_NONE
;
1900 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
1901 /* Initialize howto table if needed. */
1909 case BFD_RELOC_NONE
: r
= R_PPC64_NONE
;
1911 case BFD_RELOC_32
: r
= R_PPC64_ADDR32
;
1913 case BFD_RELOC_PPC_BA26
: r
= R_PPC64_ADDR24
;
1915 case BFD_RELOC_16
: r
= R_PPC64_ADDR16
;
1917 case BFD_RELOC_LO16
: r
= R_PPC64_ADDR16_LO
;
1919 case BFD_RELOC_HI16
: r
= R_PPC64_ADDR16_HI
;
1921 case BFD_RELOC_HI16_S
: r
= R_PPC64_ADDR16_HA
;
1923 case BFD_RELOC_PPC_BA16
: r
= R_PPC64_ADDR14
;
1925 case BFD_RELOC_PPC_BA16_BRTAKEN
: r
= R_PPC64_ADDR14_BRTAKEN
;
1927 case BFD_RELOC_PPC_BA16_BRNTAKEN
: r
= R_PPC64_ADDR14_BRNTAKEN
;
1929 case BFD_RELOC_PPC_B26
: r
= R_PPC64_REL24
;
1931 case BFD_RELOC_PPC_B16
: r
= R_PPC64_REL14
;
1933 case BFD_RELOC_PPC_B16_BRTAKEN
: r
= R_PPC64_REL14_BRTAKEN
;
1935 case BFD_RELOC_PPC_B16_BRNTAKEN
: r
= R_PPC64_REL14_BRNTAKEN
;
1937 case BFD_RELOC_16_GOTOFF
: r
= R_PPC64_GOT16
;
1939 case BFD_RELOC_LO16_GOTOFF
: r
= R_PPC64_GOT16_LO
;
1941 case BFD_RELOC_HI16_GOTOFF
: r
= R_PPC64_GOT16_HI
;
1943 case BFD_RELOC_HI16_S_GOTOFF
: r
= R_PPC64_GOT16_HA
;
1945 case BFD_RELOC_PPC_COPY
: r
= R_PPC64_COPY
;
1947 case BFD_RELOC_PPC_GLOB_DAT
: r
= R_PPC64_GLOB_DAT
;
1949 case BFD_RELOC_32_PCREL
: r
= R_PPC64_REL32
;
1951 case BFD_RELOC_32_PLTOFF
: r
= R_PPC64_PLT32
;
1953 case BFD_RELOC_32_PLT_PCREL
: r
= R_PPC64_PLTREL32
;
1955 case BFD_RELOC_LO16_PLTOFF
: r
= R_PPC64_PLT16_LO
;
1957 case BFD_RELOC_HI16_PLTOFF
: r
= R_PPC64_PLT16_HI
;
1959 case BFD_RELOC_HI16_S_PLTOFF
: r
= R_PPC64_PLT16_HA
;
1961 case BFD_RELOC_16_BASEREL
: r
= R_PPC64_SECTOFF
;
1963 case BFD_RELOC_LO16_BASEREL
: r
= R_PPC64_SECTOFF_LO
;
1965 case BFD_RELOC_HI16_BASEREL
: r
= R_PPC64_SECTOFF_HI
;
1967 case BFD_RELOC_HI16_S_BASEREL
: r
= R_PPC64_SECTOFF_HA
;
1969 case BFD_RELOC_CTOR
: r
= R_PPC64_ADDR64
;
1971 case BFD_RELOC_64
: r
= R_PPC64_ADDR64
;
1973 case BFD_RELOC_PPC64_HIGHER
: r
= R_PPC64_ADDR16_HIGHER
;
1975 case BFD_RELOC_PPC64_HIGHER_S
: r
= R_PPC64_ADDR16_HIGHERA
;
1977 case BFD_RELOC_PPC64_HIGHEST
: r
= R_PPC64_ADDR16_HIGHEST
;
1979 case BFD_RELOC_PPC64_HIGHEST_S
: r
= R_PPC64_ADDR16_HIGHESTA
;
1981 case BFD_RELOC_64_PCREL
: r
= R_PPC64_REL64
;
1983 case BFD_RELOC_64_PLTOFF
: r
= R_PPC64_PLT64
;
1985 case BFD_RELOC_64_PLT_PCREL
: r
= R_PPC64_PLTREL64
;
1987 case BFD_RELOC_PPC_TOC16
: r
= R_PPC64_TOC16
;
1989 case BFD_RELOC_PPC64_TOC16_LO
: r
= R_PPC64_TOC16_LO
;
1991 case BFD_RELOC_PPC64_TOC16_HI
: r
= R_PPC64_TOC16_HI
;
1993 case BFD_RELOC_PPC64_TOC16_HA
: r
= R_PPC64_TOC16_HA
;
1995 case BFD_RELOC_PPC64_TOC
: r
= R_PPC64_TOC
;
1997 case BFD_RELOC_PPC64_PLTGOT16
: r
= R_PPC64_PLTGOT16
;
1999 case BFD_RELOC_PPC64_PLTGOT16_LO
: r
= R_PPC64_PLTGOT16_LO
;
2001 case BFD_RELOC_PPC64_PLTGOT16_HI
: r
= R_PPC64_PLTGOT16_HI
;
2003 case BFD_RELOC_PPC64_PLTGOT16_HA
: r
= R_PPC64_PLTGOT16_HA
;
2005 case BFD_RELOC_PPC64_ADDR16_DS
: r
= R_PPC64_ADDR16_DS
;
2007 case BFD_RELOC_PPC64_ADDR16_LO_DS
: r
= R_PPC64_ADDR16_LO_DS
;
2009 case BFD_RELOC_PPC64_GOT16_DS
: r
= R_PPC64_GOT16_DS
;
2011 case BFD_RELOC_PPC64_GOT16_LO_DS
: r
= R_PPC64_GOT16_LO_DS
;
2013 case BFD_RELOC_PPC64_PLT16_LO_DS
: r
= R_PPC64_PLT16_LO_DS
;
2015 case BFD_RELOC_PPC64_SECTOFF_DS
: r
= R_PPC64_SECTOFF_DS
;
2017 case BFD_RELOC_PPC64_SECTOFF_LO_DS
: r
= R_PPC64_SECTOFF_LO_DS
;
2019 case BFD_RELOC_PPC64_TOC16_DS
: r
= R_PPC64_TOC16_DS
;
2021 case BFD_RELOC_PPC64_TOC16_LO_DS
: r
= R_PPC64_TOC16_LO_DS
;
2023 case BFD_RELOC_PPC64_PLTGOT16_DS
: r
= R_PPC64_PLTGOT16_DS
;
2025 case BFD_RELOC_PPC64_PLTGOT16_LO_DS
: r
= R_PPC64_PLTGOT16_LO_DS
;
2027 case BFD_RELOC_PPC_TLS
: r
= R_PPC64_TLS
;
2029 case BFD_RELOC_PPC_DTPMOD
: r
= R_PPC64_DTPMOD64
;
2031 case BFD_RELOC_PPC_TPREL16
: r
= R_PPC64_TPREL16
;
2033 case BFD_RELOC_PPC_TPREL16_LO
: r
= R_PPC64_TPREL16_LO
;
2035 case BFD_RELOC_PPC_TPREL16_HI
: r
= R_PPC64_TPREL16_HI
;
2037 case BFD_RELOC_PPC_TPREL16_HA
: r
= R_PPC64_TPREL16_HA
;
2039 case BFD_RELOC_PPC_TPREL
: r
= R_PPC64_TPREL64
;
2041 case BFD_RELOC_PPC_DTPREL16
: r
= R_PPC64_DTPREL16
;
2043 case BFD_RELOC_PPC_DTPREL16_LO
: r
= R_PPC64_DTPREL16_LO
;
2045 case BFD_RELOC_PPC_DTPREL16_HI
: r
= R_PPC64_DTPREL16_HI
;
2047 case BFD_RELOC_PPC_DTPREL16_HA
: r
= R_PPC64_DTPREL16_HA
;
2049 case BFD_RELOC_PPC_DTPREL
: r
= R_PPC64_DTPREL64
;
2051 case BFD_RELOC_PPC_GOT_TLSGD16
: r
= R_PPC64_GOT_TLSGD16
;
2053 case BFD_RELOC_PPC_GOT_TLSGD16_LO
: r
= R_PPC64_GOT_TLSGD16_LO
;
2055 case BFD_RELOC_PPC_GOT_TLSGD16_HI
: r
= R_PPC64_GOT_TLSGD16_HI
;
2057 case BFD_RELOC_PPC_GOT_TLSGD16_HA
: r
= R_PPC64_GOT_TLSGD16_HA
;
2059 case BFD_RELOC_PPC_GOT_TLSLD16
: r
= R_PPC64_GOT_TLSLD16
;
2061 case BFD_RELOC_PPC_GOT_TLSLD16_LO
: r
= R_PPC64_GOT_TLSLD16_LO
;
2063 case BFD_RELOC_PPC_GOT_TLSLD16_HI
: r
= R_PPC64_GOT_TLSLD16_HI
;
2065 case BFD_RELOC_PPC_GOT_TLSLD16_HA
: r
= R_PPC64_GOT_TLSLD16_HA
;
2067 case BFD_RELOC_PPC_GOT_TPREL16
: r
= R_PPC64_GOT_TPREL16_DS
;
2069 case BFD_RELOC_PPC_GOT_TPREL16_LO
: r
= R_PPC64_GOT_TPREL16_LO_DS
;
2071 case BFD_RELOC_PPC_GOT_TPREL16_HI
: r
= R_PPC64_GOT_TPREL16_HI
;
2073 case BFD_RELOC_PPC_GOT_TPREL16_HA
: r
= R_PPC64_GOT_TPREL16_HA
;
2075 case BFD_RELOC_PPC_GOT_DTPREL16
: r
= R_PPC64_GOT_DTPREL16_DS
;
2077 case BFD_RELOC_PPC_GOT_DTPREL16_LO
: r
= R_PPC64_GOT_DTPREL16_LO_DS
;
2079 case BFD_RELOC_PPC_GOT_DTPREL16_HI
: r
= R_PPC64_GOT_DTPREL16_HI
;
2081 case BFD_RELOC_PPC_GOT_DTPREL16_HA
: r
= R_PPC64_GOT_DTPREL16_HA
;
2083 case BFD_RELOC_PPC64_TPREL16_DS
: r
= R_PPC64_TPREL16_DS
;
2085 case BFD_RELOC_PPC64_TPREL16_LO_DS
: r
= R_PPC64_TPREL16_LO_DS
;
2087 case BFD_RELOC_PPC64_TPREL16_HIGHER
: r
= R_PPC64_TPREL16_HIGHER
;
2089 case BFD_RELOC_PPC64_TPREL16_HIGHERA
: r
= R_PPC64_TPREL16_HIGHERA
;
2091 case BFD_RELOC_PPC64_TPREL16_HIGHEST
: r
= R_PPC64_TPREL16_HIGHEST
;
2093 case BFD_RELOC_PPC64_TPREL16_HIGHESTA
: r
= R_PPC64_TPREL16_HIGHESTA
;
2095 case BFD_RELOC_PPC64_DTPREL16_DS
: r
= R_PPC64_DTPREL16_DS
;
2097 case BFD_RELOC_PPC64_DTPREL16_LO_DS
: r
= R_PPC64_DTPREL16_LO_DS
;
2099 case BFD_RELOC_PPC64_DTPREL16_HIGHER
: r
= R_PPC64_DTPREL16_HIGHER
;
2101 case BFD_RELOC_PPC64_DTPREL16_HIGHERA
: r
= R_PPC64_DTPREL16_HIGHERA
;
2103 case BFD_RELOC_PPC64_DTPREL16_HIGHEST
: r
= R_PPC64_DTPREL16_HIGHEST
;
2105 case BFD_RELOC_PPC64_DTPREL16_HIGHESTA
: r
= R_PPC64_DTPREL16_HIGHESTA
;
2107 case BFD_RELOC_VTABLE_INHERIT
: r
= R_PPC64_GNU_VTINHERIT
;
2109 case BFD_RELOC_VTABLE_ENTRY
: r
= R_PPC64_GNU_VTENTRY
;
2113 return ppc64_elf_howto_table
[r
];
2116 static reloc_howto_type
*
2117 ppc64_elf_reloc_name_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
2123 i
< sizeof (ppc64_elf_howto_raw
) / sizeof (ppc64_elf_howto_raw
[0]);
2125 if (ppc64_elf_howto_raw
[i
].name
!= NULL
2126 && strcasecmp (ppc64_elf_howto_raw
[i
].name
, r_name
) == 0)
2127 return &ppc64_elf_howto_raw
[i
];
2132 /* Set the howto pointer for a PowerPC ELF reloc. */
2135 ppc64_elf_info_to_howto (bfd
*abfd ATTRIBUTE_UNUSED
, arelent
*cache_ptr
,
2136 Elf_Internal_Rela
*dst
)
2140 /* Initialize howto table if needed. */
2141 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
2144 type
= ELF64_R_TYPE (dst
->r_info
);
2145 if (type
>= (sizeof (ppc64_elf_howto_table
)
2146 / sizeof (ppc64_elf_howto_table
[0])))
2148 (*_bfd_error_handler
) (_("%B: invalid relocation type %d"),
2150 type
= R_PPC64_NONE
;
2152 cache_ptr
->howto
= ppc64_elf_howto_table
[type
];
2155 /* Handle the R_PPC64_ADDR16_HA and similar relocs. */
2157 static bfd_reloc_status_type
2158 ppc64_elf_ha_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2159 void *data
, asection
*input_section
,
2160 bfd
*output_bfd
, char **error_message
)
2162 /* If this is a relocatable link (output_bfd test tells us), just
2163 call the generic function. Any adjustment will be done at final
2165 if (output_bfd
!= NULL
)
2166 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2167 input_section
, output_bfd
, error_message
);
2169 /* Adjust the addend for sign extension of the low 16 bits.
2170 We won't actually be using the low 16 bits, so trashing them
2172 reloc_entry
->addend
+= 0x8000;
2173 return bfd_reloc_continue
;
2176 static bfd_reloc_status_type
2177 ppc64_elf_branch_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2178 void *data
, asection
*input_section
,
2179 bfd
*output_bfd
, char **error_message
)
2181 if (output_bfd
!= NULL
)
2182 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2183 input_section
, output_bfd
, error_message
);
2185 if (strcmp (symbol
->section
->name
, ".opd") == 0
2186 && (symbol
->section
->owner
->flags
& DYNAMIC
) == 0)
2188 bfd_vma dest
= opd_entry_value (symbol
->section
,
2189 symbol
->value
+ reloc_entry
->addend
,
2191 if (dest
!= (bfd_vma
) -1)
2192 reloc_entry
->addend
= dest
- (symbol
->value
2193 + symbol
->section
->output_section
->vma
2194 + symbol
->section
->output_offset
);
2196 return bfd_reloc_continue
;
2199 static bfd_reloc_status_type
2200 ppc64_elf_brtaken_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2201 void *data
, asection
*input_section
,
2202 bfd
*output_bfd
, char **error_message
)
2205 enum elf_ppc64_reloc_type r_type
;
2206 bfd_size_type octets
;
2207 /* Disabled until we sort out how ld should choose 'y' vs 'at'. */
2208 bfd_boolean is_power4
= FALSE
;
2210 /* If this is a relocatable link (output_bfd test tells us), just
2211 call the generic function. Any adjustment will be done at final
2213 if (output_bfd
!= NULL
)
2214 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2215 input_section
, output_bfd
, error_message
);
2217 octets
= reloc_entry
->address
* bfd_octets_per_byte (abfd
);
2218 insn
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ octets
);
2219 insn
&= ~(0x01 << 21);
2220 r_type
= reloc_entry
->howto
->type
;
2221 if (r_type
== R_PPC64_ADDR14_BRTAKEN
2222 || r_type
== R_PPC64_REL14_BRTAKEN
)
2223 insn
|= 0x01 << 21; /* 'y' or 't' bit, lowest bit of BO field. */
2227 /* Set 'a' bit. This is 0b00010 in BO field for branch
2228 on CR(BI) insns (BO == 001at or 011at), and 0b01000
2229 for branch on CTR insns (BO == 1a00t or 1a01t). */
2230 if ((insn
& (0x14 << 21)) == (0x04 << 21))
2232 else if ((insn
& (0x14 << 21)) == (0x10 << 21))
2242 if (!bfd_is_com_section (symbol
->section
))
2243 target
= symbol
->value
;
2244 target
+= symbol
->section
->output_section
->vma
;
2245 target
+= symbol
->section
->output_offset
;
2246 target
+= reloc_entry
->addend
;
2248 from
= (reloc_entry
->address
2249 + input_section
->output_offset
2250 + input_section
->output_section
->vma
);
2252 /* Invert 'y' bit if not the default. */
2253 if ((bfd_signed_vma
) (target
- from
) < 0)
2256 bfd_put_32 (abfd
, insn
, (bfd_byte
*) data
+ octets
);
2258 return ppc64_elf_branch_reloc (abfd
, reloc_entry
, symbol
, data
,
2259 input_section
, output_bfd
, error_message
);
2262 static bfd_reloc_status_type
2263 ppc64_elf_sectoff_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2264 void *data
, asection
*input_section
,
2265 bfd
*output_bfd
, char **error_message
)
2267 /* If this is a relocatable link (output_bfd test tells us), just
2268 call the generic function. Any adjustment will be done at final
2270 if (output_bfd
!= NULL
)
2271 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2272 input_section
, output_bfd
, error_message
);
2274 /* Subtract the symbol section base address. */
2275 reloc_entry
->addend
-= symbol
->section
->output_section
->vma
;
2276 return bfd_reloc_continue
;
2279 static bfd_reloc_status_type
2280 ppc64_elf_sectoff_ha_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2281 void *data
, asection
*input_section
,
2282 bfd
*output_bfd
, char **error_message
)
2284 /* If this is a relocatable link (output_bfd test tells us), just
2285 call the generic function. Any adjustment will be done at final
2287 if (output_bfd
!= NULL
)
2288 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2289 input_section
, output_bfd
, error_message
);
2291 /* Subtract the symbol section base address. */
2292 reloc_entry
->addend
-= symbol
->section
->output_section
->vma
;
2294 /* Adjust the addend for sign extension of the low 16 bits. */
2295 reloc_entry
->addend
+= 0x8000;
2296 return bfd_reloc_continue
;
2299 static bfd_reloc_status_type
2300 ppc64_elf_toc_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2301 void *data
, asection
*input_section
,
2302 bfd
*output_bfd
, char **error_message
)
2306 /* If this is a relocatable link (output_bfd test tells us), just
2307 call the generic function. Any adjustment will be done at final
2309 if (output_bfd
!= NULL
)
2310 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2311 input_section
, output_bfd
, error_message
);
2313 TOCstart
= _bfd_get_gp_value (input_section
->output_section
->owner
);
2315 TOCstart
= ppc64_elf_toc (input_section
->output_section
->owner
);
2317 /* Subtract the TOC base address. */
2318 reloc_entry
->addend
-= TOCstart
+ TOC_BASE_OFF
;
2319 return bfd_reloc_continue
;
2322 static bfd_reloc_status_type
2323 ppc64_elf_toc_ha_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2324 void *data
, asection
*input_section
,
2325 bfd
*output_bfd
, char **error_message
)
2329 /* If this is a relocatable link (output_bfd test tells us), just
2330 call the generic function. Any adjustment will be done at final
2332 if (output_bfd
!= NULL
)
2333 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2334 input_section
, output_bfd
, error_message
);
2336 TOCstart
= _bfd_get_gp_value (input_section
->output_section
->owner
);
2338 TOCstart
= ppc64_elf_toc (input_section
->output_section
->owner
);
2340 /* Subtract the TOC base address. */
2341 reloc_entry
->addend
-= TOCstart
+ TOC_BASE_OFF
;
2343 /* Adjust the addend for sign extension of the low 16 bits. */
2344 reloc_entry
->addend
+= 0x8000;
2345 return bfd_reloc_continue
;
2348 static bfd_reloc_status_type
2349 ppc64_elf_toc64_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2350 void *data
, asection
*input_section
,
2351 bfd
*output_bfd
, char **error_message
)
2354 bfd_size_type octets
;
2356 /* If this is a relocatable link (output_bfd test tells us), just
2357 call the generic function. Any adjustment will be done at final
2359 if (output_bfd
!= NULL
)
2360 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2361 input_section
, output_bfd
, error_message
);
2363 TOCstart
= _bfd_get_gp_value (input_section
->output_section
->owner
);
2365 TOCstart
= ppc64_elf_toc (input_section
->output_section
->owner
);
2367 octets
= reloc_entry
->address
* bfd_octets_per_byte (abfd
);
2368 bfd_put_64 (abfd
, TOCstart
+ TOC_BASE_OFF
, (bfd_byte
*) data
+ octets
);
2369 return bfd_reloc_ok
;
2372 static bfd_reloc_status_type
2373 ppc64_elf_unhandled_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2374 void *data
, asection
*input_section
,
2375 bfd
*output_bfd
, char **error_message
)
2377 /* If this is a relocatable link (output_bfd test tells us), just
2378 call the generic function. Any adjustment will be done at final
2380 if (output_bfd
!= NULL
)
2381 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2382 input_section
, output_bfd
, error_message
);
2384 if (error_message
!= NULL
)
2386 static char buf
[60];
2387 sprintf (buf
, "generic linker can't handle %s",
2388 reloc_entry
->howto
->name
);
2389 *error_message
= buf
;
2391 return bfd_reloc_dangerous
;
2394 struct ppc64_elf_obj_tdata
2396 struct elf_obj_tdata elf
;
2398 /* Shortcuts to dynamic linker sections. */
2402 /* Used during garbage collection. We attach global symbols defined
2403 on removed .opd entries to this section so that the sym is removed. */
2404 asection
*deleted_section
;
2406 /* TLS local dynamic got entry handling. Suppose for multiple GOT
2407 sections means we potentially need one of these for each input bfd. */
2409 bfd_signed_vma refcount
;
2413 /* A copy of relocs before they are modified for --emit-relocs. */
2414 Elf_Internal_Rela
*opd_relocs
;
2417 #define ppc64_elf_tdata(bfd) \
2418 ((struct ppc64_elf_obj_tdata *) (bfd)->tdata.any)
2420 #define ppc64_tlsld_got(bfd) \
2421 (&ppc64_elf_tdata (bfd)->tlsld_got)
2423 /* Override the generic function because we store some extras. */
2426 ppc64_elf_mkobject (bfd
*abfd
)
2428 if (abfd
->tdata
.any
== NULL
)
2430 bfd_size_type amt
= sizeof (struct ppc64_elf_obj_tdata
);
2431 abfd
->tdata
.any
= bfd_zalloc (abfd
, amt
);
2432 if (abfd
->tdata
.any
== NULL
)
2435 return bfd_elf_mkobject (abfd
);
2438 /* Return 1 if target is one of ours. */
2441 is_ppc64_elf_target (const struct bfd_target
*targ
)
2443 extern const bfd_target bfd_elf64_powerpc_vec
;
2444 extern const bfd_target bfd_elf64_powerpcle_vec
;
2446 return targ
== &bfd_elf64_powerpc_vec
|| targ
== &bfd_elf64_powerpcle_vec
;
2449 /* Fix bad default arch selected for a 64 bit input bfd when the
2450 default is 32 bit. */
2453 ppc64_elf_object_p (bfd
*abfd
)
2455 if (abfd
->arch_info
->the_default
&& abfd
->arch_info
->bits_per_word
== 32)
2457 Elf_Internal_Ehdr
*i_ehdr
= elf_elfheader (abfd
);
2459 if (i_ehdr
->e_ident
[EI_CLASS
] == ELFCLASS64
)
2461 /* Relies on arch after 32 bit default being 64 bit default. */
2462 abfd
->arch_info
= abfd
->arch_info
->next
;
2463 BFD_ASSERT (abfd
->arch_info
->bits_per_word
== 64);
2469 /* Support for core dump NOTE sections. */
2472 ppc64_elf_grok_prstatus (bfd
*abfd
, Elf_Internal_Note
*note
)
2474 size_t offset
, size
;
2476 if (note
->descsz
!= 504)
2480 elf_tdata (abfd
)->core_signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
2483 elf_tdata (abfd
)->core_pid
= bfd_get_32 (abfd
, note
->descdata
+ 32);
2489 /* Make a ".reg/999" section. */
2490 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
2491 size
, note
->descpos
+ offset
);
2495 ppc64_elf_grok_psinfo (bfd
*abfd
, Elf_Internal_Note
*note
)
2497 if (note
->descsz
!= 136)
2500 elf_tdata (abfd
)->core_program
2501 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 40, 16);
2502 elf_tdata (abfd
)->core_command
2503 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 56, 80);
2509 ppc64_elf_write_core_note (bfd
*abfd
, char *buf
, int *bufsiz
, int note_type
,
2522 va_start (ap
, note_type
);
2523 memset (data
, 0, 40);
2524 strncpy (data
+ 40, va_arg (ap
, const char *), 16);
2525 strncpy (data
+ 56, va_arg (ap
, const char *), 80);
2527 return elfcore_write_note (abfd
, buf
, bufsiz
,
2528 "CORE", note_type
, data
, sizeof (data
));
2539 va_start (ap
, note_type
);
2540 memset (data
, 0, 112);
2541 pid
= va_arg (ap
, long);
2542 bfd_put_32 (abfd
, pid
, data
+ 32);
2543 cursig
= va_arg (ap
, int);
2544 bfd_put_16 (abfd
, cursig
, data
+ 12);
2545 greg
= va_arg (ap
, const void *);
2546 memcpy (data
+ 112, greg
, 384);
2547 memset (data
+ 496, 0, 8);
2549 return elfcore_write_note (abfd
, buf
, bufsiz
,
2550 "CORE", note_type
, data
, sizeof (data
));
2555 /* Merge backend specific data from an object file to the output
2556 object file when linking. */
2559 ppc64_elf_merge_private_bfd_data (bfd
*ibfd
, bfd
*obfd
)
2561 /* Check if we have the same endianess. */
2562 if (ibfd
->xvec
->byteorder
!= obfd
->xvec
->byteorder
2563 && ibfd
->xvec
->byteorder
!= BFD_ENDIAN_UNKNOWN
2564 && obfd
->xvec
->byteorder
!= BFD_ENDIAN_UNKNOWN
)
2568 if (bfd_big_endian (ibfd
))
2569 msg
= _("%B: compiled for a big endian system "
2570 "and target is little endian");
2572 msg
= _("%B: compiled for a little endian system "
2573 "and target is big endian");
2575 (*_bfd_error_handler
) (msg
, ibfd
);
2577 bfd_set_error (bfd_error_wrong_format
);
2584 /* Add extra PPC sections. */
2586 static const struct bfd_elf_special_section ppc64_elf_special_sections
[]=
2588 { STRING_COMMA_LEN (".plt"), 0, SHT_NOBITS
, 0 },
2589 { STRING_COMMA_LEN (".sbss"), -2, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
},
2590 { STRING_COMMA_LEN (".sdata"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
2591 { STRING_COMMA_LEN (".toc"), 0, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
2592 { STRING_COMMA_LEN (".toc1"), 0, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
2593 { STRING_COMMA_LEN (".tocbss"), 0, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
},
2594 { NULL
, 0, 0, 0, 0 }
2597 enum _ppc64_sec_type
{
2603 struct _ppc64_elf_section_data
2605 struct bfd_elf_section_data elf
;
2607 /* An array with one entry for each opd function descriptor. */
2610 /* Points to the function code section for local opd entries. */
2611 asection
**opd_func_sec
;
2612 /* After editing .opd, adjust references to opd local syms. */
2615 /* An array for toc sections, indexed by offset/8.
2616 Specifies the relocation symbol index used at a given toc offset. */
2620 enum _ppc64_sec_type sec_type
:2;
2622 /* Flag set when small branches are detected. Used to
2623 select suitable defaults for the stub group size. */
2624 unsigned int has_14bit_branch
:1;
2627 #define ppc64_elf_section_data(sec) \
2628 ((struct _ppc64_elf_section_data *) elf_section_data (sec))
2631 ppc64_elf_new_section_hook (bfd
*abfd
, asection
*sec
)
2633 if (!sec
->used_by_bfd
)
2635 struct _ppc64_elf_section_data
*sdata
;
2636 bfd_size_type amt
= sizeof (*sdata
);
2638 sdata
= bfd_zalloc (abfd
, amt
);
2641 sec
->used_by_bfd
= sdata
;
2644 return _bfd_elf_new_section_hook (abfd
, sec
);
2648 get_opd_info (asection
* sec
)
2651 && ppc64_elf_section_data (sec
) != NULL
2652 && ppc64_elf_section_data (sec
)->sec_type
== sec_opd
)
2653 return ppc64_elf_section_data (sec
)->u
.opd_adjust
;
2657 /* Parameters for the qsort hook. */
2658 static asection
*synthetic_opd
;
2659 static bfd_boolean synthetic_relocatable
;
2661 /* qsort comparison function for ppc64_elf_get_synthetic_symtab. */
2664 compare_symbols (const void *ap
, const void *bp
)
2666 const asymbol
*a
= * (const asymbol
**) ap
;
2667 const asymbol
*b
= * (const asymbol
**) bp
;
2669 /* Section symbols first. */
2670 if ((a
->flags
& BSF_SECTION_SYM
) && !(b
->flags
& BSF_SECTION_SYM
))
2672 if (!(a
->flags
& BSF_SECTION_SYM
) && (b
->flags
& BSF_SECTION_SYM
))
2675 /* then .opd symbols. */
2676 if (a
->section
== synthetic_opd
&& b
->section
!= synthetic_opd
)
2678 if (a
->section
!= synthetic_opd
&& b
->section
== synthetic_opd
)
2681 /* then other code symbols. */
2682 if ((a
->section
->flags
& (SEC_CODE
| SEC_ALLOC
| SEC_THREAD_LOCAL
))
2683 == (SEC_CODE
| SEC_ALLOC
)
2684 && (b
->section
->flags
& (SEC_CODE
| SEC_ALLOC
| SEC_THREAD_LOCAL
))
2685 != (SEC_CODE
| SEC_ALLOC
))
2688 if ((a
->section
->flags
& (SEC_CODE
| SEC_ALLOC
| SEC_THREAD_LOCAL
))
2689 != (SEC_CODE
| SEC_ALLOC
)
2690 && (b
->section
->flags
& (SEC_CODE
| SEC_ALLOC
| SEC_THREAD_LOCAL
))
2691 == (SEC_CODE
| SEC_ALLOC
))
2694 if (synthetic_relocatable
)
2696 if (a
->section
->id
< b
->section
->id
)
2699 if (a
->section
->id
> b
->section
->id
)
2703 if (a
->value
+ a
->section
->vma
< b
->value
+ b
->section
->vma
)
2706 if (a
->value
+ a
->section
->vma
> b
->value
+ b
->section
->vma
)
2709 /* For syms with the same value, prefer strong dynamic global function
2710 syms over other syms. */
2711 if ((a
->flags
& BSF_GLOBAL
) != 0 && (b
->flags
& BSF_GLOBAL
) == 0)
2714 if ((a
->flags
& BSF_GLOBAL
) == 0 && (b
->flags
& BSF_GLOBAL
) != 0)
2717 if ((a
->flags
& BSF_FUNCTION
) != 0 && (b
->flags
& BSF_FUNCTION
) == 0)
2720 if ((a
->flags
& BSF_FUNCTION
) == 0 && (b
->flags
& BSF_FUNCTION
) != 0)
2723 if ((a
->flags
& BSF_WEAK
) == 0 && (b
->flags
& BSF_WEAK
) != 0)
2726 if ((a
->flags
& BSF_WEAK
) != 0 && (b
->flags
& BSF_WEAK
) == 0)
2729 if ((a
->flags
& BSF_DYNAMIC
) != 0 && (b
->flags
& BSF_DYNAMIC
) == 0)
2732 if ((a
->flags
& BSF_DYNAMIC
) == 0 && (b
->flags
& BSF_DYNAMIC
) != 0)
2738 /* Search SYMS for a symbol of the given VALUE. */
2741 sym_exists_at (asymbol
**syms
, long lo
, long hi
, int id
, bfd_vma value
)
2749 mid
= (lo
+ hi
) >> 1;
2750 if (syms
[mid
]->value
+ syms
[mid
]->section
->vma
< value
)
2752 else if (syms
[mid
]->value
+ syms
[mid
]->section
->vma
> value
)
2762 mid
= (lo
+ hi
) >> 1;
2763 if (syms
[mid
]->section
->id
< id
)
2765 else if (syms
[mid
]->section
->id
> id
)
2767 else if (syms
[mid
]->value
< value
)
2769 else if (syms
[mid
]->value
> value
)
2778 /* Create synthetic symbols, effectively restoring "dot-symbol" function
2782 ppc64_elf_get_synthetic_symtab (bfd
*abfd
,
2783 long static_count
, asymbol
**static_syms
,
2784 long dyn_count
, asymbol
**dyn_syms
,
2791 long symcount
, codesecsym
, codesecsymend
, secsymend
, opdsymend
;
2793 bfd_boolean relocatable
= (abfd
->flags
& (EXEC_P
| DYNAMIC
)) == 0;
2798 opd
= bfd_get_section_by_name (abfd
, ".opd");
2802 symcount
= static_count
;
2804 symcount
+= dyn_count
;
2808 syms
= bfd_malloc ((symcount
+ 1) * sizeof (*syms
));
2812 if (!relocatable
&& static_count
!= 0 && dyn_count
!= 0)
2814 /* Use both symbol tables. */
2815 memcpy (syms
, static_syms
, static_count
* sizeof (*syms
));
2816 memcpy (syms
+ static_count
, dyn_syms
, (dyn_count
+ 1) * sizeof (*syms
));
2818 else if (!relocatable
&& static_count
== 0)
2819 memcpy (syms
, dyn_syms
, (symcount
+ 1) * sizeof (*syms
));
2821 memcpy (syms
, static_syms
, (symcount
+ 1) * sizeof (*syms
));
2823 synthetic_opd
= opd
;
2824 synthetic_relocatable
= relocatable
;
2825 qsort (syms
, symcount
, sizeof (*syms
), compare_symbols
);
2827 if (!relocatable
&& symcount
> 1)
2830 /* Trim duplicate syms, since we may have merged the normal and
2831 dynamic symbols. Actually, we only care about syms that have
2832 different values, so trim any with the same value. */
2833 for (i
= 1, j
= 1; i
< symcount
; ++i
)
2834 if (syms
[i
- 1]->value
+ syms
[i
- 1]->section
->vma
2835 != syms
[i
]->value
+ syms
[i
]->section
->vma
)
2836 syms
[j
++] = syms
[i
];
2841 if (syms
[i
]->section
== opd
)
2845 for (; i
< symcount
; ++i
)
2846 if (((syms
[i
]->section
->flags
& (SEC_CODE
| SEC_ALLOC
| SEC_THREAD_LOCAL
))
2847 != (SEC_CODE
| SEC_ALLOC
))
2848 || (syms
[i
]->flags
& BSF_SECTION_SYM
) == 0)
2852 for (; i
< symcount
; ++i
)
2853 if ((syms
[i
]->flags
& BSF_SECTION_SYM
) == 0)
2857 for (; i
< symcount
; ++i
)
2858 if (syms
[i
]->section
!= opd
)
2862 for (; i
< symcount
; ++i
)
2863 if ((syms
[i
]->section
->flags
& (SEC_CODE
| SEC_ALLOC
| SEC_THREAD_LOCAL
))
2864 != (SEC_CODE
| SEC_ALLOC
))
2869 if (opdsymend
== secsymend
)
2874 bfd_boolean (*slurp_relocs
) (bfd
*, asection
*, asymbol
**, bfd_boolean
);
2879 slurp_relocs
= get_elf_backend_data (abfd
)->s
->slurp_reloc_table
;
2880 relcount
= (opd
->flags
& SEC_RELOC
) ? opd
->reloc_count
: 0;
2884 if (!(*slurp_relocs
) (abfd
, opd
, static_syms
, FALSE
))
2891 for (i
= secsymend
, r
= opd
->relocation
; i
< opdsymend
; ++i
)
2895 while (r
< opd
->relocation
+ relcount
2896 && r
->address
< syms
[i
]->value
+ opd
->vma
)
2899 if (r
== opd
->relocation
+ relcount
)
2902 if (r
->address
!= syms
[i
]->value
+ opd
->vma
)
2905 if (r
->howto
->type
!= R_PPC64_ADDR64
)
2908 sym
= *r
->sym_ptr_ptr
;
2909 if (!sym_exists_at (syms
, opdsymend
, symcount
,
2910 sym
->section
->id
, sym
->value
+ r
->addend
))
2913 size
+= sizeof (asymbol
);
2914 size
+= strlen (syms
[i
]->name
) + 2;
2918 s
= *ret
= bfd_malloc (size
);
2925 names
= (char *) (s
+ count
);
2927 for (i
= secsymend
, r
= opd
->relocation
; i
< opdsymend
; ++i
)
2931 while (r
< opd
->relocation
+ relcount
2932 && r
->address
< syms
[i
]->value
+ opd
->vma
)
2935 if (r
== opd
->relocation
+ relcount
)
2938 if (r
->address
!= syms
[i
]->value
+ opd
->vma
)
2941 if (r
->howto
->type
!= R_PPC64_ADDR64
)
2944 sym
= *r
->sym_ptr_ptr
;
2945 if (!sym_exists_at (syms
, opdsymend
, symcount
,
2946 sym
->section
->id
, sym
->value
+ r
->addend
))
2951 s
->section
= sym
->section
;
2952 s
->value
= sym
->value
+ r
->addend
;
2955 len
= strlen (syms
[i
]->name
);
2956 memcpy (names
, syms
[i
]->name
, len
+ 1);
2967 if (!bfd_malloc_and_get_section (abfd
, opd
, &contents
))
2971 free_contents_and_exit
:
2979 for (i
= secsymend
; i
< opdsymend
; ++i
)
2983 ent
= bfd_get_64 (abfd
, contents
+ syms
[i
]->value
);
2984 if (!sym_exists_at (syms
, opdsymend
, symcount
, -1, ent
))
2987 size
+= sizeof (asymbol
);
2988 size
+= strlen (syms
[i
]->name
) + 2;
2992 s
= *ret
= bfd_malloc (size
);
2994 goto free_contents_and_exit
;
2996 names
= (char *) (s
+ count
);
2998 for (i
= secsymend
; i
< opdsymend
; ++i
)
3002 ent
= bfd_get_64 (abfd
, contents
+ syms
[i
]->value
);
3003 if (!sym_exists_at (syms
, opdsymend
, symcount
, -1, ent
))
3007 asection
*sec
= abfd
->sections
;
3014 long mid
= (lo
+ hi
) >> 1;
3015 if (syms
[mid
]->section
->vma
< ent
)
3017 else if (syms
[mid
]->section
->vma
> ent
)
3021 sec
= syms
[mid
]->section
;
3026 if (lo
>= hi
&& lo
> codesecsym
)
3027 sec
= syms
[lo
- 1]->section
;
3029 for (; sec
!= NULL
; sec
= sec
->next
)
3033 if ((sec
->flags
& SEC_ALLOC
) == 0
3034 || (sec
->flags
& SEC_LOAD
) == 0)
3036 if ((sec
->flags
& SEC_CODE
) != 0)
3039 s
->value
= ent
- s
->section
->vma
;
3042 len
= strlen (syms
[i
]->name
);
3043 memcpy (names
, syms
[i
]->name
, len
+ 1);
3056 /* The following functions are specific to the ELF linker, while
3057 functions above are used generally. Those named ppc64_elf_* are
3058 called by the main ELF linker code. They appear in this file more
3059 or less in the order in which they are called. eg.
3060 ppc64_elf_check_relocs is called early in the link process,
3061 ppc64_elf_finish_dynamic_sections is one of the last functions
3064 PowerPC64-ELF uses a similar scheme to PowerPC64-XCOFF in that
3065 functions have both a function code symbol and a function descriptor
3066 symbol. A call to foo in a relocatable object file looks like:
3073 The function definition in another object file might be:
3077 . .quad .TOC.@tocbase
3083 When the linker resolves the call during a static link, the branch
3084 unsurprisingly just goes to .foo and the .opd information is unused.
3085 If the function definition is in a shared library, things are a little
3086 different: The call goes via a plt call stub, the opd information gets
3087 copied to the plt, and the linker patches the nop.
3095 . addis 12,2,Lfoo@toc@ha # in practice, the call stub
3096 . addi 12,12,Lfoo@toc@l # is slightly optimized, but
3097 . std 2,40(1) # this is the general idea
3105 . Lfoo: reloc (R_PPC64_JMP_SLOT, foo)
3107 The "reloc ()" notation is supposed to indicate that the linker emits
3108 an R_PPC64_JMP_SLOT reloc against foo. The dynamic linker does the opd
3111 What are the difficulties here? Well, firstly, the relocations
3112 examined by the linker in check_relocs are against the function code
3113 sym .foo, while the dynamic relocation in the plt is emitted against
3114 the function descriptor symbol, foo. Somewhere along the line, we need
3115 to carefully copy dynamic link information from one symbol to the other.
3116 Secondly, the generic part of the elf linker will make .foo a dynamic
3117 symbol as is normal for most other backends. We need foo dynamic
3118 instead, at least for an application final link. However, when
3119 creating a shared library containing foo, we need to have both symbols
3120 dynamic so that references to .foo are satisfied during the early
3121 stages of linking. Otherwise the linker might decide to pull in a
3122 definition from some other object, eg. a static library.
3124 Update: As of August 2004, we support a new convention. Function
3125 calls may use the function descriptor symbol, ie. "bl foo". This
3126 behaves exactly as "bl .foo". */
3128 /* The linker needs to keep track of the number of relocs that it
3129 decides to copy as dynamic relocs in check_relocs for each symbol.
3130 This is so that it can later discard them if they are found to be
3131 unnecessary. We store the information in a field extending the
3132 regular ELF linker hash table. */
3134 struct ppc_dyn_relocs
3136 struct ppc_dyn_relocs
*next
;
3138 /* The input section of the reloc. */
3141 /* Total number of relocs copied for the input section. */
3142 bfd_size_type count
;
3144 /* Number of pc-relative relocs copied for the input section. */
3145 bfd_size_type pc_count
;
3148 /* Track GOT entries needed for a given symbol. We might need more
3149 than one got entry per symbol. */
3152 struct got_entry
*next
;
3154 /* The symbol addend that we'll be placing in the GOT. */
3157 /* Unlike other ELF targets, we use separate GOT entries for the same
3158 symbol referenced from different input files. This is to support
3159 automatic multiple TOC/GOT sections, where the TOC base can vary
3160 from one input file to another.
3162 Point to the BFD owning this GOT entry. */
3165 /* Zero for non-tls entries, or TLS_TLS and one of TLS_GD, TLS_LD,
3166 TLS_TPREL or TLS_DTPREL for tls entries. */
3169 /* Reference count until size_dynamic_sections, GOT offset thereafter. */
3172 bfd_signed_vma refcount
;
3177 /* The same for PLT. */
3180 struct plt_entry
*next
;
3186 bfd_signed_vma refcount
;
3191 /* Of those relocs that might be copied as dynamic relocs, this macro
3192 selects those that must be copied when linking a shared library,
3193 even when the symbol is local. */
3195 #define MUST_BE_DYN_RELOC(RTYPE) \
3196 ((RTYPE) != R_PPC64_REL32 \
3197 && (RTYPE) != R_PPC64_REL64 \
3198 && (RTYPE) != R_PPC64_REL30)
3200 /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
3201 copying dynamic variables from a shared lib into an app's dynbss
3202 section, and instead use a dynamic relocation to point into the
3203 shared lib. With code that gcc generates, it's vital that this be
3204 enabled; In the PowerPC64 ABI, the address of a function is actually
3205 the address of a function descriptor, which resides in the .opd
3206 section. gcc uses the descriptor directly rather than going via the
3207 GOT as some other ABI's do, which means that initialized function
3208 pointers must reference the descriptor. Thus, a function pointer
3209 initialized to the address of a function in a shared library will
3210 either require a copy reloc, or a dynamic reloc. Using a copy reloc
3211 redefines the function descriptor symbol to point to the copy. This
3212 presents a problem as a plt entry for that function is also
3213 initialized from the function descriptor symbol and the copy reloc
3214 may not be initialized first. */
3215 #define ELIMINATE_COPY_RELOCS 1
3217 /* Section name for stubs is the associated section name plus this
3219 #define STUB_SUFFIX ".stub"
3222 ppc_stub_long_branch:
3223 Used when a 14 bit branch (or even a 24 bit branch) can't reach its
3224 destination, but a 24 bit branch in a stub section will reach.
3227 ppc_stub_plt_branch:
3228 Similar to the above, but a 24 bit branch in the stub section won't
3229 reach its destination.
3230 . addis %r12,%r2,xxx@toc@ha
3231 . ld %r11,xxx@toc@l(%r12)
3236 Used to call a function in a shared library. If it so happens that
3237 the plt entry referenced crosses a 64k boundary, then an extra
3238 "addis %r12,%r12,1" will be inserted before the load at xxx+8 or
3239 xxx+16 as appropriate.
3240 . addis %r12,%r2,xxx@toc@ha
3242 . ld %r11,xxx+0@toc@l(%r12)
3243 . ld %r2,xxx+8@toc@l(%r12)
3245 . ld %r11,xxx+16@toc@l(%r12)
3248 ppc_stub_long_branch and ppc_stub_plt_branch may also have additional
3249 code to adjust the value and save r2 to support multiple toc sections.
3250 A ppc_stub_long_branch with an r2 offset looks like:
3252 . addis %r2,%r2,off@ha
3253 . addi %r2,%r2,off@l
3256 A ppc_stub_plt_branch with an r2 offset looks like:
3258 . addis %r12,%r2,xxx@toc@ha
3259 . ld %r11,xxx@toc@l(%r12)
3260 . addis %r2,%r2,off@ha
3261 . addi %r2,%r2,off@l
3266 enum ppc_stub_type
{
3268 ppc_stub_long_branch
,
3269 ppc_stub_long_branch_r2off
,
3270 ppc_stub_plt_branch
,
3271 ppc_stub_plt_branch_r2off
,
3275 struct ppc_stub_hash_entry
{
3277 /* Base hash table entry structure. */
3278 struct bfd_hash_entry root
;
3280 enum ppc_stub_type stub_type
;
3282 /* The stub section. */
3285 /* Offset within stub_sec of the beginning of this stub. */
3286 bfd_vma stub_offset
;
3288 /* Given the symbol's value and its section we can determine its final
3289 value when building the stubs (so the stub knows where to jump. */
3290 bfd_vma target_value
;
3291 asection
*target_section
;
3293 /* The symbol table entry, if any, that this was derived from. */
3294 struct ppc_link_hash_entry
*h
;
3296 /* And the reloc addend that this was derived from. */
3299 /* Where this stub is being called from, or, in the case of combined
3300 stub sections, the first input section in the group. */
3304 struct ppc_branch_hash_entry
{
3306 /* Base hash table entry structure. */
3307 struct bfd_hash_entry root
;
3309 /* Offset within branch lookup table. */
3310 unsigned int offset
;
3312 /* Generation marker. */
3316 struct ppc_link_hash_entry
3318 struct elf_link_hash_entry elf
;
3321 /* A pointer to the most recently used stub hash entry against this
3323 struct ppc_stub_hash_entry
*stub_cache
;
3325 /* A pointer to the next symbol starting with a '.' */
3326 struct ppc_link_hash_entry
*next_dot_sym
;
3329 /* Track dynamic relocs copied for this symbol. */
3330 struct ppc_dyn_relocs
*dyn_relocs
;
3332 /* Link between function code and descriptor symbols. */
3333 struct ppc_link_hash_entry
*oh
;
3335 /* Flag function code and descriptor symbols. */
3336 unsigned int is_func
:1;
3337 unsigned int is_func_descriptor
:1;
3338 unsigned int fake
:1;
3340 /* Whether global opd/toc sym has been adjusted or not.
3341 After ppc64_elf_edit_opd/ppc64_elf_edit_toc has run, this flag
3342 should be set for all globals defined in any opd/toc section. */
3343 unsigned int adjust_done
:1;
3345 /* Set if we twiddled this symbol to weak at some stage. */
3346 unsigned int was_undefined
:1;
3348 /* Contexts in which symbol is used in the GOT (or TOC).
3349 TLS_GD .. TLS_EXPLICIT bits are or'd into the mask as the
3350 corresponding relocs are encountered during check_relocs.
3351 tls_optimize clears TLS_GD .. TLS_TPREL when optimizing to
3352 indicate the corresponding GOT entry type is not needed.
3353 tls_optimize may also set TLS_TPRELGD when a GD reloc turns into
3354 a TPREL one. We use a separate flag rather than setting TPREL
3355 just for convenience in distinguishing the two cases. */
3356 #define TLS_GD 1 /* GD reloc. */
3357 #define TLS_LD 2 /* LD reloc. */
3358 #define TLS_TPREL 4 /* TPREL reloc, => IE. */
3359 #define TLS_DTPREL 8 /* DTPREL reloc, => LD. */
3360 #define TLS_TLS 16 /* Any TLS reloc. */
3361 #define TLS_EXPLICIT 32 /* Marks TOC section TLS relocs. */
3362 #define TLS_TPRELGD 64 /* TPREL reloc resulting from GD->IE. */
3366 /* ppc64 ELF linker hash table. */
3368 struct ppc_link_hash_table
3370 struct elf_link_hash_table elf
;
3372 /* The stub hash table. */
3373 struct bfd_hash_table stub_hash_table
;
3375 /* Another hash table for plt_branch stubs. */
3376 struct bfd_hash_table branch_hash_table
;
3378 /* Linker stub bfd. */
3381 /* Linker call-backs. */
3382 asection
* (*add_stub_section
) (const char *, asection
*);
3383 void (*layout_sections_again
) (void);
3385 /* Array to keep track of which stub sections have been created, and
3386 information on stub grouping. */
3388 /* This is the section to which stubs in the group will be attached. */
3390 /* The stub section. */
3392 /* Along with elf_gp, specifies the TOC pointer used in this group. */
3396 /* Temp used when calculating TOC pointers. */
3399 /* Highest input section id. */
3402 /* Highest output section index. */
3405 /* Used when adding symbols. */
3406 struct ppc_link_hash_entry
*dot_syms
;
3408 /* List of input sections for each output section. */
3409 asection
**input_list
;
3411 /* Short-cuts to get to dynamic linker sections. */
3422 /* Shortcut to .__tls_get_addr and __tls_get_addr. */
3423 struct ppc_link_hash_entry
*tls_get_addr
;
3424 struct ppc_link_hash_entry
*tls_get_addr_fd
;
3427 unsigned long stub_count
[ppc_stub_plt_call
];
3429 /* Number of stubs against global syms. */
3430 unsigned long stub_globals
;
3432 /* Set if we should emit symbols for stubs. */
3433 unsigned int emit_stub_syms
:1;
3435 /* Support for multiple toc sections. */
3436 unsigned int no_multi_toc
:1;
3437 unsigned int multi_toc_needed
:1;
3440 unsigned int stub_error
:1;
3442 /* Temp used by ppc64_elf_check_directives. */
3443 unsigned int twiddled_syms
:1;
3445 /* Incremented every time we size stubs. */
3446 unsigned int stub_iteration
;
3448 /* Small local sym to section mapping cache. */
3449 struct sym_sec_cache sym_sec
;
3452 /* Rename some of the generic section flags to better document how they
3454 #define has_toc_reloc has_gp_reloc
3455 #define makes_toc_func_call need_finalize_relax
3456 #define call_check_in_progress reloc_done
3458 /* Get the ppc64 ELF linker hash table from a link_info structure. */
3460 #define ppc_hash_table(p) \
3461 ((struct ppc_link_hash_table *) ((p)->hash))
3463 #define ppc_stub_hash_lookup(table, string, create, copy) \
3464 ((struct ppc_stub_hash_entry *) \
3465 bfd_hash_lookup ((table), (string), (create), (copy)))
3467 #define ppc_branch_hash_lookup(table, string, create, copy) \
3468 ((struct ppc_branch_hash_entry *) \
3469 bfd_hash_lookup ((table), (string), (create), (copy)))
3471 /* Create an entry in the stub hash table. */
3473 static struct bfd_hash_entry
*
3474 stub_hash_newfunc (struct bfd_hash_entry
*entry
,
3475 struct bfd_hash_table
*table
,
3478 /* Allocate the structure if it has not already been allocated by a
3482 entry
= bfd_hash_allocate (table
, sizeof (struct ppc_stub_hash_entry
));
3487 /* Call the allocation method of the superclass. */
3488 entry
= bfd_hash_newfunc (entry
, table
, string
);
3491 struct ppc_stub_hash_entry
*eh
;
3493 /* Initialize the local fields. */
3494 eh
= (struct ppc_stub_hash_entry
*) entry
;
3495 eh
->stub_type
= ppc_stub_none
;
3496 eh
->stub_sec
= NULL
;
3497 eh
->stub_offset
= 0;
3498 eh
->target_value
= 0;
3499 eh
->target_section
= NULL
;
3507 /* Create an entry in the branch hash table. */
3509 static struct bfd_hash_entry
*
3510 branch_hash_newfunc (struct bfd_hash_entry
*entry
,
3511 struct bfd_hash_table
*table
,
3514 /* Allocate the structure if it has not already been allocated by a
3518 entry
= bfd_hash_allocate (table
, sizeof (struct ppc_branch_hash_entry
));
3523 /* Call the allocation method of the superclass. */
3524 entry
= bfd_hash_newfunc (entry
, table
, string
);
3527 struct ppc_branch_hash_entry
*eh
;
3529 /* Initialize the local fields. */
3530 eh
= (struct ppc_branch_hash_entry
*) entry
;
3538 /* Create an entry in a ppc64 ELF linker hash table. */
3540 static struct bfd_hash_entry
*
3541 link_hash_newfunc (struct bfd_hash_entry
*entry
,
3542 struct bfd_hash_table
*table
,
3545 /* Allocate the structure if it has not already been allocated by a
3549 entry
= bfd_hash_allocate (table
, sizeof (struct ppc_link_hash_entry
));
3554 /* Call the allocation method of the superclass. */
3555 entry
= _bfd_elf_link_hash_newfunc (entry
, table
, string
);
3558 struct ppc_link_hash_entry
*eh
= (struct ppc_link_hash_entry
*) entry
;
3560 memset (&eh
->u
.stub_cache
, 0,
3561 (sizeof (struct ppc_link_hash_entry
)
3562 - offsetof (struct ppc_link_hash_entry
, u
.stub_cache
)));
3564 /* When making function calls, old ABI code references function entry
3565 points (dot symbols), while new ABI code references the function
3566 descriptor symbol. We need to make any combination of reference and
3567 definition work together, without breaking archive linking.
3569 For a defined function "foo" and an undefined call to "bar":
3570 An old object defines "foo" and ".foo", references ".bar" (possibly
3572 A new object defines "foo" and references "bar".
3574 A new object thus has no problem with its undefined symbols being
3575 satisfied by definitions in an old object. On the other hand, the
3576 old object won't have ".bar" satisfied by a new object.
3578 Keep a list of newly added dot-symbols. */
3580 if (string
[0] == '.')
3582 struct ppc_link_hash_table
*htab
;
3584 htab
= (struct ppc_link_hash_table
*) table
;
3585 eh
->u
.next_dot_sym
= htab
->dot_syms
;
3586 htab
->dot_syms
= eh
;
3593 /* Create a ppc64 ELF linker hash table. */
3595 static struct bfd_link_hash_table
*
3596 ppc64_elf_link_hash_table_create (bfd
*abfd
)
3598 struct ppc_link_hash_table
*htab
;
3599 bfd_size_type amt
= sizeof (struct ppc_link_hash_table
);
3601 htab
= bfd_zmalloc (amt
);
3605 if (!_bfd_elf_link_hash_table_init (&htab
->elf
, abfd
, link_hash_newfunc
,
3606 sizeof (struct ppc_link_hash_entry
)))
3612 /* Init the stub hash table too. */
3613 if (!bfd_hash_table_init (&htab
->stub_hash_table
, stub_hash_newfunc
,
3614 sizeof (struct ppc_stub_hash_entry
)))
3617 /* And the branch hash table. */
3618 if (!bfd_hash_table_init (&htab
->branch_hash_table
, branch_hash_newfunc
,
3619 sizeof (struct ppc_branch_hash_entry
)))
3622 /* Initializing two fields of the union is just cosmetic. We really
3623 only care about glist, but when compiled on a 32-bit host the
3624 bfd_vma fields are larger. Setting the bfd_vma to zero makes
3625 debugger inspection of these fields look nicer. */
3626 htab
->elf
.init_got_refcount
.refcount
= 0;
3627 htab
->elf
.init_got_refcount
.glist
= NULL
;
3628 htab
->elf
.init_plt_refcount
.refcount
= 0;
3629 htab
->elf
.init_plt_refcount
.glist
= NULL
;
3630 htab
->elf
.init_got_offset
.offset
= 0;
3631 htab
->elf
.init_got_offset
.glist
= NULL
;
3632 htab
->elf
.init_plt_offset
.offset
= 0;
3633 htab
->elf
.init_plt_offset
.glist
= NULL
;
3635 return &htab
->elf
.root
;
3638 /* Free the derived linker hash table. */
3641 ppc64_elf_link_hash_table_free (struct bfd_link_hash_table
*hash
)
3643 struct ppc_link_hash_table
*ret
= (struct ppc_link_hash_table
*) hash
;
3645 bfd_hash_table_free (&ret
->stub_hash_table
);
3646 bfd_hash_table_free (&ret
->branch_hash_table
);
3647 _bfd_generic_link_hash_table_free (hash
);
3650 /* Satisfy the ELF linker by filling in some fields in our fake bfd. */
3653 ppc64_elf_init_stub_bfd (bfd
*abfd
, struct bfd_link_info
*info
)
3655 struct ppc_link_hash_table
*htab
;
3657 elf_elfheader (abfd
)->e_ident
[EI_CLASS
] = ELFCLASS64
;
3659 /* Always hook our dynamic sections into the first bfd, which is the
3660 linker created stub bfd. This ensures that the GOT header is at
3661 the start of the output TOC section. */
3662 htab
= ppc_hash_table (info
);
3663 htab
->stub_bfd
= abfd
;
3664 htab
->elf
.dynobj
= abfd
;
3667 /* Build a name for an entry in the stub hash table. */
3670 ppc_stub_name (const asection
*input_section
,
3671 const asection
*sym_sec
,
3672 const struct ppc_link_hash_entry
*h
,
3673 const Elf_Internal_Rela
*rel
)
3678 /* rel->r_addend is actually 64 bit, but who uses more than +/- 2^31
3679 offsets from a sym as a branch target? In fact, we could
3680 probably assume the addend is always zero. */
3681 BFD_ASSERT (((int) rel
->r_addend
& 0xffffffff) == rel
->r_addend
);
3685 len
= 8 + 1 + strlen (h
->elf
.root
.root
.string
) + 1 + 8 + 1;
3686 stub_name
= bfd_malloc (len
);
3687 if (stub_name
== NULL
)
3690 sprintf (stub_name
, "%08x.%s+%x",
3691 input_section
->id
& 0xffffffff,
3692 h
->elf
.root
.root
.string
,
3693 (int) rel
->r_addend
& 0xffffffff);
3697 len
= 8 + 1 + 8 + 1 + 8 + 1 + 8 + 1;
3698 stub_name
= bfd_malloc (len
);
3699 if (stub_name
== NULL
)
3702 sprintf (stub_name
, "%08x.%x:%x+%x",
3703 input_section
->id
& 0xffffffff,
3704 sym_sec
->id
& 0xffffffff,
3705 (int) ELF64_R_SYM (rel
->r_info
) & 0xffffffff,
3706 (int) rel
->r_addend
& 0xffffffff);
3708 if (stub_name
[len
- 2] == '+' && stub_name
[len
- 1] == '0')
3709 stub_name
[len
- 2] = 0;
3713 /* Look up an entry in the stub hash. Stub entries are cached because
3714 creating the stub name takes a bit of time. */
3716 static struct ppc_stub_hash_entry
*
3717 ppc_get_stub_entry (const asection
*input_section
,
3718 const asection
*sym_sec
,
3719 struct ppc_link_hash_entry
*h
,
3720 const Elf_Internal_Rela
*rel
,
3721 struct ppc_link_hash_table
*htab
)
3723 struct ppc_stub_hash_entry
*stub_entry
;
3724 const asection
*id_sec
;
3726 /* If this input section is part of a group of sections sharing one
3727 stub section, then use the id of the first section in the group.
3728 Stub names need to include a section id, as there may well be
3729 more than one stub used to reach say, printf, and we need to
3730 distinguish between them. */
3731 id_sec
= htab
->stub_group
[input_section
->id
].link_sec
;
3733 if (h
!= NULL
&& h
->u
.stub_cache
!= NULL
3734 && h
->u
.stub_cache
->h
== h
3735 && h
->u
.stub_cache
->id_sec
== id_sec
)
3737 stub_entry
= h
->u
.stub_cache
;
3743 stub_name
= ppc_stub_name (id_sec
, sym_sec
, h
, rel
);
3744 if (stub_name
== NULL
)
3747 stub_entry
= ppc_stub_hash_lookup (&htab
->stub_hash_table
,
3748 stub_name
, FALSE
, FALSE
);
3750 h
->u
.stub_cache
= stub_entry
;
3758 /* Add a new stub entry to the stub hash. Not all fields of the new
3759 stub entry are initialised. */
3761 static struct ppc_stub_hash_entry
*
3762 ppc_add_stub (const char *stub_name
,
3764 struct ppc_link_hash_table
*htab
)
3768 struct ppc_stub_hash_entry
*stub_entry
;
3770 link_sec
= htab
->stub_group
[section
->id
].link_sec
;
3771 stub_sec
= htab
->stub_group
[section
->id
].stub_sec
;
3772 if (stub_sec
== NULL
)
3774 stub_sec
= htab
->stub_group
[link_sec
->id
].stub_sec
;
3775 if (stub_sec
== NULL
)
3781 namelen
= strlen (link_sec
->name
);
3782 len
= namelen
+ sizeof (STUB_SUFFIX
);
3783 s_name
= bfd_alloc (htab
->stub_bfd
, len
);
3787 memcpy (s_name
, link_sec
->name
, namelen
);
3788 memcpy (s_name
+ namelen
, STUB_SUFFIX
, sizeof (STUB_SUFFIX
));
3789 stub_sec
= (*htab
->add_stub_section
) (s_name
, link_sec
);
3790 if (stub_sec
== NULL
)
3792 htab
->stub_group
[link_sec
->id
].stub_sec
= stub_sec
;
3794 htab
->stub_group
[section
->id
].stub_sec
= stub_sec
;
3797 /* Enter this entry into the linker stub hash table. */
3798 stub_entry
= ppc_stub_hash_lookup (&htab
->stub_hash_table
, stub_name
,
3800 if (stub_entry
== NULL
)
3802 (*_bfd_error_handler
) (_("%B: cannot create stub entry %s"),
3803 section
->owner
, stub_name
);
3807 stub_entry
->stub_sec
= stub_sec
;
3808 stub_entry
->stub_offset
= 0;
3809 stub_entry
->id_sec
= link_sec
;
3813 /* Create sections for linker generated code. */
3816 create_linkage_sections (bfd
*dynobj
, struct bfd_link_info
*info
)
3818 struct ppc_link_hash_table
*htab
;
3821 htab
= ppc_hash_table (info
);
3823 /* Create .sfpr for code to save and restore fp regs. */
3824 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_CODE
| SEC_READONLY
3825 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
3826 htab
->sfpr
= bfd_make_section_anyway_with_flags (dynobj
, ".sfpr",
3828 if (htab
->sfpr
== NULL
3829 || ! bfd_set_section_alignment (dynobj
, htab
->sfpr
, 2))
3832 /* Create .glink for lazy dynamic linking support. */
3833 htab
->glink
= bfd_make_section_anyway_with_flags (dynobj
, ".glink",
3835 if (htab
->glink
== NULL
3836 || ! bfd_set_section_alignment (dynobj
, htab
->glink
, 3))
3839 /* Create branch lookup table for plt_branch stubs. */
3840 flags
= (SEC_ALLOC
| SEC_LOAD
3841 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
3842 htab
->brlt
= bfd_make_section_anyway_with_flags (dynobj
, ".branch_lt",
3844 if (htab
->brlt
== NULL
3845 || ! bfd_set_section_alignment (dynobj
, htab
->brlt
, 3))
3851 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
3852 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
3853 htab
->relbrlt
= bfd_make_section_anyway_with_flags (dynobj
,
3857 || ! bfd_set_section_alignment (dynobj
, htab
->relbrlt
, 3))
3863 /* Create .got and .rela.got sections in ABFD, and .got in dynobj if
3864 not already done. */
3867 create_got_section (bfd
*abfd
, struct bfd_link_info
*info
)
3869 asection
*got
, *relgot
;
3871 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
3875 if (! _bfd_elf_create_got_section (htab
->elf
.dynobj
, info
))
3878 htab
->got
= bfd_get_section_by_name (htab
->elf
.dynobj
, ".got");
3883 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
3884 | SEC_LINKER_CREATED
);
3886 got
= bfd_make_section_anyway_with_flags (abfd
, ".got", flags
);
3888 || !bfd_set_section_alignment (abfd
, got
, 3))
3891 relgot
= bfd_make_section_anyway_with_flags (abfd
, ".rela.got",
3892 flags
| SEC_READONLY
);
3894 || ! bfd_set_section_alignment (abfd
, relgot
, 3))
3897 ppc64_elf_tdata (abfd
)->got
= got
;
3898 ppc64_elf_tdata (abfd
)->relgot
= relgot
;
3902 /* Create the dynamic sections, and set up shortcuts. */
3905 ppc64_elf_create_dynamic_sections (bfd
*dynobj
, struct bfd_link_info
*info
)
3907 struct ppc_link_hash_table
*htab
;
3909 if (!_bfd_elf_create_dynamic_sections (dynobj
, info
))
3912 htab
= ppc_hash_table (info
);
3914 htab
->got
= bfd_get_section_by_name (dynobj
, ".got");
3915 htab
->plt
= bfd_get_section_by_name (dynobj
, ".plt");
3916 htab
->relplt
= bfd_get_section_by_name (dynobj
, ".rela.plt");
3917 htab
->dynbss
= bfd_get_section_by_name (dynobj
, ".dynbss");
3919 htab
->relbss
= bfd_get_section_by_name (dynobj
, ".rela.bss");
3921 if (!htab
->got
|| !htab
->plt
|| !htab
->relplt
|| !htab
->dynbss
3922 || (!info
->shared
&& !htab
->relbss
))
3928 /* Merge PLT info on FROM with that on TO. */
3931 move_plt_plist (struct ppc_link_hash_entry
*from
,
3932 struct ppc_link_hash_entry
*to
)
3934 if (from
->elf
.plt
.plist
!= NULL
)
3936 if (to
->elf
.plt
.plist
!= NULL
)
3938 struct plt_entry
**entp
;
3939 struct plt_entry
*ent
;
3941 for (entp
= &from
->elf
.plt
.plist
; (ent
= *entp
) != NULL
; )
3943 struct plt_entry
*dent
;
3945 for (dent
= to
->elf
.plt
.plist
; dent
!= NULL
; dent
= dent
->next
)
3946 if (dent
->addend
== ent
->addend
)
3948 dent
->plt
.refcount
+= ent
->plt
.refcount
;
3955 *entp
= to
->elf
.plt
.plist
;
3958 to
->elf
.plt
.plist
= from
->elf
.plt
.plist
;
3959 from
->elf
.plt
.plist
= NULL
;
3963 /* Copy the extra info we tack onto an elf_link_hash_entry. */
3966 ppc64_elf_copy_indirect_symbol (struct bfd_link_info
*info
,
3967 struct elf_link_hash_entry
*dir
,
3968 struct elf_link_hash_entry
*ind
)
3970 struct ppc_link_hash_entry
*edir
, *eind
;
3972 edir
= (struct ppc_link_hash_entry
*) dir
;
3973 eind
= (struct ppc_link_hash_entry
*) ind
;
3975 /* Copy over any dynamic relocs we may have on the indirect sym. */
3976 if (eind
->dyn_relocs
!= NULL
)
3978 if (edir
->dyn_relocs
!= NULL
)
3980 struct ppc_dyn_relocs
**pp
;
3981 struct ppc_dyn_relocs
*p
;
3983 /* Add reloc counts against the indirect sym to the direct sym
3984 list. Merge any entries against the same section. */
3985 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
; )
3987 struct ppc_dyn_relocs
*q
;
3989 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
3990 if (q
->sec
== p
->sec
)
3992 q
->pc_count
+= p
->pc_count
;
3993 q
->count
+= p
->count
;
4000 *pp
= edir
->dyn_relocs
;
4003 edir
->dyn_relocs
= eind
->dyn_relocs
;
4004 eind
->dyn_relocs
= NULL
;
4007 edir
->is_func
|= eind
->is_func
;
4008 edir
->is_func_descriptor
|= eind
->is_func_descriptor
;
4009 edir
->tls_mask
|= eind
->tls_mask
;
4011 /* If called to transfer flags for a weakdef during processing
4012 of elf_adjust_dynamic_symbol, don't copy NON_GOT_REF.
4013 We clear it ourselves for ELIMINATE_COPY_RELOCS. */
4014 if (!(ELIMINATE_COPY_RELOCS
4015 && eind
->elf
.root
.type
!= bfd_link_hash_indirect
4016 && edir
->elf
.dynamic_adjusted
))
4017 edir
->elf
.non_got_ref
|= eind
->elf
.non_got_ref
;
4019 edir
->elf
.ref_dynamic
|= eind
->elf
.ref_dynamic
;
4020 edir
->elf
.ref_regular
|= eind
->elf
.ref_regular
;
4021 edir
->elf
.ref_regular_nonweak
|= eind
->elf
.ref_regular_nonweak
;
4022 edir
->elf
.needs_plt
|= eind
->elf
.needs_plt
;
4024 /* If we were called to copy over info for a weak sym, that's all. */
4025 if (eind
->elf
.root
.type
!= bfd_link_hash_indirect
)
4028 /* Copy over got entries that we may have already seen to the
4029 symbol which just became indirect. */
4030 if (eind
->elf
.got
.glist
!= NULL
)
4032 if (edir
->elf
.got
.glist
!= NULL
)
4034 struct got_entry
**entp
;
4035 struct got_entry
*ent
;
4037 for (entp
= &eind
->elf
.got
.glist
; (ent
= *entp
) != NULL
; )
4039 struct got_entry
*dent
;
4041 for (dent
= edir
->elf
.got
.glist
; dent
!= NULL
; dent
= dent
->next
)
4042 if (dent
->addend
== ent
->addend
4043 && dent
->owner
== ent
->owner
4044 && dent
->tls_type
== ent
->tls_type
)
4046 dent
->got
.refcount
+= ent
->got
.refcount
;
4053 *entp
= edir
->elf
.got
.glist
;
4056 edir
->elf
.got
.glist
= eind
->elf
.got
.glist
;
4057 eind
->elf
.got
.glist
= NULL
;
4060 /* And plt entries. */
4061 move_plt_plist (eind
, edir
);
4063 if (eind
->elf
.dynindx
!= -1)
4065 if (edir
->elf
.dynindx
!= -1)
4066 _bfd_elf_strtab_delref (elf_hash_table (info
)->dynstr
,
4067 edir
->elf
.dynstr_index
);
4068 edir
->elf
.dynindx
= eind
->elf
.dynindx
;
4069 edir
->elf
.dynstr_index
= eind
->elf
.dynstr_index
;
4070 eind
->elf
.dynindx
= -1;
4071 eind
->elf
.dynstr_index
= 0;
4075 /* Find the function descriptor hash entry from the given function code
4076 hash entry FH. Link the entries via their OH fields. */
4078 static struct ppc_link_hash_entry
*
4079 get_fdh (struct ppc_link_hash_entry
*fh
, struct ppc_link_hash_table
*htab
)
4081 struct ppc_link_hash_entry
*fdh
= fh
->oh
;
4085 const char *fd_name
= fh
->elf
.root
.root
.string
+ 1;
4087 fdh
= (struct ppc_link_hash_entry
*)
4088 elf_link_hash_lookup (&htab
->elf
, fd_name
, FALSE
, FALSE
, FALSE
);
4091 fdh
->is_func_descriptor
= 1;
4101 /* Make a fake function descriptor sym for the code sym FH. */
4103 static struct ppc_link_hash_entry
*
4104 make_fdh (struct bfd_link_info
*info
,
4105 struct ppc_link_hash_entry
*fh
)
4109 struct bfd_link_hash_entry
*bh
;
4110 struct ppc_link_hash_entry
*fdh
;
4112 abfd
= fh
->elf
.root
.u
.undef
.abfd
;
4113 newsym
= bfd_make_empty_symbol (abfd
);
4114 newsym
->name
= fh
->elf
.root
.root
.string
+ 1;
4115 newsym
->section
= bfd_und_section_ptr
;
4117 newsym
->flags
= BSF_WEAK
;
4120 if (!_bfd_generic_link_add_one_symbol (info
, abfd
, newsym
->name
,
4121 newsym
->flags
, newsym
->section
,
4122 newsym
->value
, NULL
, FALSE
, FALSE
,
4126 fdh
= (struct ppc_link_hash_entry
*) bh
;
4127 fdh
->elf
.non_elf
= 0;
4129 fdh
->is_func_descriptor
= 1;
4136 /* Fix function descriptor symbols defined in .opd sections to be
4140 ppc64_elf_add_symbol_hook (bfd
*ibfd ATTRIBUTE_UNUSED
,
4141 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
4142 Elf_Internal_Sym
*isym
,
4143 const char **name ATTRIBUTE_UNUSED
,
4144 flagword
*flags ATTRIBUTE_UNUSED
,
4146 bfd_vma
*value ATTRIBUTE_UNUSED
)
4149 && strcmp (bfd_get_section_name (ibfd
, *sec
), ".opd") == 0)
4150 isym
->st_info
= ELF_ST_INFO (ELF_ST_BIND (isym
->st_info
), STT_FUNC
);
4155 /* This function makes an old ABI object reference to ".bar" cause the
4156 inclusion of a new ABI object archive that defines "bar".
4157 NAME is a symbol defined in an archive. Return a symbol in the hash
4158 table that might be satisfied by the archive symbols. */
4160 static struct elf_link_hash_entry
*
4161 ppc64_elf_archive_symbol_lookup (bfd
*abfd
,
4162 struct bfd_link_info
*info
,
4165 struct elf_link_hash_entry
*h
;
4169 h
= _bfd_elf_archive_symbol_lookup (abfd
, info
, name
);
4171 /* Don't return this sym if it is a fake function descriptor
4172 created by add_symbol_adjust. */
4173 && !(h
->root
.type
== bfd_link_hash_undefweak
4174 && ((struct ppc_link_hash_entry
*) h
)->fake
))
4180 len
= strlen (name
);
4181 dot_name
= bfd_alloc (abfd
, len
+ 2);
4182 if (dot_name
== NULL
)
4183 return (struct elf_link_hash_entry
*) 0 - 1;
4185 memcpy (dot_name
+ 1, name
, len
+ 1);
4186 h
= _bfd_elf_archive_symbol_lookup (abfd
, info
, dot_name
);
4187 bfd_release (abfd
, dot_name
);
4191 /* This function satisfies all old ABI object references to ".bar" if a
4192 new ABI object defines "bar". Well, at least, undefined dot symbols
4193 are made weak. This stops later archive searches from including an
4194 object if we already have a function descriptor definition. It also
4195 prevents the linker complaining about undefined symbols.
4196 We also check and correct mismatched symbol visibility here. The
4197 most restrictive visibility of the function descriptor and the
4198 function entry symbol is used. */
4201 add_symbol_adjust (struct ppc_link_hash_entry
*eh
, struct bfd_link_info
*info
)
4203 struct ppc_link_hash_table
*htab
;
4204 struct ppc_link_hash_entry
*fdh
;
4206 if (eh
->elf
.root
.type
== bfd_link_hash_indirect
)
4209 if (eh
->elf
.root
.type
== bfd_link_hash_warning
)
4210 eh
= (struct ppc_link_hash_entry
*) eh
->elf
.root
.u
.i
.link
;
4212 if (eh
->elf
.root
.root
.string
[0] != '.')
4215 htab
= ppc_hash_table (info
);
4216 fdh
= get_fdh (eh
, htab
);
4218 && !info
->relocatable
4219 && (eh
->elf
.root
.type
== bfd_link_hash_undefined
4220 || eh
->elf
.root
.type
== bfd_link_hash_undefweak
)
4221 && eh
->elf
.ref_regular
)
4223 /* Make an undefweak function descriptor sym, which is enough to
4224 pull in an --as-needed shared lib, but won't cause link
4225 errors. Archives are handled elsewhere. */
4226 fdh
= make_fdh (info
, eh
);
4230 fdh
->elf
.ref_regular
= 1;
4232 else if (fdh
!= NULL
)
4234 unsigned entry_vis
= ELF_ST_VISIBILITY (eh
->elf
.other
) - 1;
4235 unsigned descr_vis
= ELF_ST_VISIBILITY (fdh
->elf
.other
) - 1;
4236 if (entry_vis
< descr_vis
)
4237 fdh
->elf
.other
+= entry_vis
- descr_vis
;
4238 else if (entry_vis
> descr_vis
)
4239 eh
->elf
.other
+= descr_vis
- entry_vis
;
4241 if ((fdh
->elf
.root
.type
== bfd_link_hash_defined
4242 || fdh
->elf
.root
.type
== bfd_link_hash_defweak
)
4243 && eh
->elf
.root
.type
== bfd_link_hash_undefined
)
4245 eh
->elf
.root
.type
= bfd_link_hash_undefweak
;
4246 eh
->was_undefined
= 1;
4247 htab
->twiddled_syms
= 1;
4254 /* Process list of dot-symbols we made in link_hash_newfunc. */
4257 ppc64_elf_check_directives (bfd
*ibfd
, struct bfd_link_info
*info
)
4259 struct ppc_link_hash_table
*htab
;
4260 struct ppc_link_hash_entry
**p
, *eh
;
4262 htab
= ppc_hash_table (info
);
4263 if (!is_ppc64_elf_target (htab
->elf
.root
.creator
))
4266 if (is_ppc64_elf_target (ibfd
->xvec
))
4268 p
= &htab
->dot_syms
;
4269 while ((eh
= *p
) != NULL
)
4272 if (!add_symbol_adjust (eh
, info
))
4274 p
= &eh
->u
.next_dot_sym
;
4278 /* Clear the list for non-ppc64 input files. */
4279 p
= &htab
->dot_syms
;
4280 while ((eh
= *p
) != NULL
)
4283 p
= &eh
->u
.next_dot_sym
;
4286 /* We need to fix the undefs list for any syms we have twiddled to
4288 if (htab
->twiddled_syms
)
4290 bfd_link_repair_undef_list (&htab
->elf
.root
);
4291 htab
->twiddled_syms
= 0;
4296 /* Undo hash table changes when an --as-needed input file is determined
4297 not to be needed. */
4300 ppc64_elf_as_needed_cleanup (bfd
*ibfd ATTRIBUTE_UNUSED
,
4301 struct bfd_link_info
*info
)
4303 ppc_hash_table (info
)->dot_syms
= NULL
;
4308 update_local_sym_info (bfd
*abfd
, Elf_Internal_Shdr
*symtab_hdr
,
4309 unsigned long r_symndx
, bfd_vma r_addend
, int tls_type
)
4311 struct got_entry
**local_got_ents
= elf_local_got_ents (abfd
);
4312 char *local_got_tls_masks
;
4314 if (local_got_ents
== NULL
)
4316 bfd_size_type size
= symtab_hdr
->sh_info
;
4318 size
*= sizeof (*local_got_ents
) + sizeof (*local_got_tls_masks
);
4319 local_got_ents
= bfd_zalloc (abfd
, size
);
4320 if (local_got_ents
== NULL
)
4322 elf_local_got_ents (abfd
) = local_got_ents
;
4325 if ((tls_type
& TLS_EXPLICIT
) == 0)
4327 struct got_entry
*ent
;
4329 for (ent
= local_got_ents
[r_symndx
]; ent
!= NULL
; ent
= ent
->next
)
4330 if (ent
->addend
== r_addend
4331 && ent
->owner
== abfd
4332 && ent
->tls_type
== tls_type
)
4336 bfd_size_type amt
= sizeof (*ent
);
4337 ent
= bfd_alloc (abfd
, amt
);
4340 ent
->next
= local_got_ents
[r_symndx
];
4341 ent
->addend
= r_addend
;
4343 ent
->tls_type
= tls_type
;
4344 ent
->got
.refcount
= 0;
4345 local_got_ents
[r_symndx
] = ent
;
4347 ent
->got
.refcount
+= 1;
4350 local_got_tls_masks
= (char *) (local_got_ents
+ symtab_hdr
->sh_info
);
4351 local_got_tls_masks
[r_symndx
] |= tls_type
;
4356 update_plt_info (bfd
*abfd
, struct ppc_link_hash_entry
*eh
, bfd_vma addend
)
4358 struct plt_entry
*ent
;
4360 for (ent
= eh
->elf
.plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
4361 if (ent
->addend
== addend
)
4365 bfd_size_type amt
= sizeof (*ent
);
4366 ent
= bfd_alloc (abfd
, amt
);
4369 ent
->next
= eh
->elf
.plt
.plist
;
4370 ent
->addend
= addend
;
4371 ent
->plt
.refcount
= 0;
4372 eh
->elf
.plt
.plist
= ent
;
4374 ent
->plt
.refcount
+= 1;
4375 eh
->elf
.needs_plt
= 1;
4376 if (eh
->elf
.root
.root
.string
[0] == '.'
4377 && eh
->elf
.root
.root
.string
[1] != '\0')
4382 /* Look through the relocs for a section during the first phase, and
4383 calculate needed space in the global offset table, procedure
4384 linkage table, and dynamic reloc sections. */
4387 ppc64_elf_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
,
4388 asection
*sec
, const Elf_Internal_Rela
*relocs
)
4390 struct ppc_link_hash_table
*htab
;
4391 Elf_Internal_Shdr
*symtab_hdr
;
4392 struct elf_link_hash_entry
**sym_hashes
, **sym_hashes_end
;
4393 const Elf_Internal_Rela
*rel
;
4394 const Elf_Internal_Rela
*rel_end
;
4396 asection
**opd_sym_map
;
4398 if (info
->relocatable
)
4401 /* Don't do anything special with non-loaded, non-alloced sections.
4402 In particular, any relocs in such sections should not affect GOT
4403 and PLT reference counting (ie. we don't allow them to create GOT
4404 or PLT entries), there's no possibility or desire to optimize TLS
4405 relocs, and there's not much point in propagating relocs to shared
4406 libs that the dynamic linker won't relocate. */
4407 if ((sec
->flags
& SEC_ALLOC
) == 0)
4410 htab
= ppc_hash_table (info
);
4411 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
4413 sym_hashes
= elf_sym_hashes (abfd
);
4414 sym_hashes_end
= (sym_hashes
4415 + symtab_hdr
->sh_size
/ sizeof (Elf64_External_Sym
)
4416 - symtab_hdr
->sh_info
);
4420 if (strcmp (bfd_get_section_name (abfd
, sec
), ".opd") == 0)
4422 /* Garbage collection needs some extra help with .opd sections.
4423 We don't want to necessarily keep everything referenced by
4424 relocs in .opd, as that would keep all functions. Instead,
4425 if we reference an .opd symbol (a function descriptor), we
4426 want to keep the function code symbol's section. This is
4427 easy for global symbols, but for local syms we need to keep
4428 information about the associated function section. Later, if
4429 edit_opd deletes entries, we'll use this array to adjust
4430 local syms in .opd. */
4432 asection
*func_section
;
4437 amt
= sec
->size
* sizeof (union opd_info
) / 8;
4438 opd_sym_map
= bfd_zalloc (abfd
, amt
);
4439 if (opd_sym_map
== NULL
)
4441 ppc64_elf_section_data (sec
)->u
.opd_func_sec
= opd_sym_map
;
4442 BFD_ASSERT (ppc64_elf_section_data (sec
)->sec_type
== sec_normal
);
4443 ppc64_elf_section_data (sec
)->sec_type
= sec_opd
;
4446 if (htab
->sfpr
== NULL
4447 && !create_linkage_sections (htab
->elf
.dynobj
, info
))
4450 rel_end
= relocs
+ sec
->reloc_count
;
4451 for (rel
= relocs
; rel
< rel_end
; rel
++)
4453 unsigned long r_symndx
;
4454 struct elf_link_hash_entry
*h
;
4455 enum elf_ppc64_reloc_type r_type
;
4457 struct _ppc64_elf_section_data
*ppc64_sec
;
4459 r_symndx
= ELF64_R_SYM (rel
->r_info
);
4460 if (r_symndx
< symtab_hdr
->sh_info
)
4464 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
4465 while (h
->root
.type
== bfd_link_hash_indirect
4466 || h
->root
.type
== bfd_link_hash_warning
)
4467 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
4470 r_type
= ELF64_R_TYPE (rel
->r_info
);
4473 case R_PPC64_GOT_TLSLD16
:
4474 case R_PPC64_GOT_TLSLD16_LO
:
4475 case R_PPC64_GOT_TLSLD16_HI
:
4476 case R_PPC64_GOT_TLSLD16_HA
:
4477 ppc64_tlsld_got (abfd
)->refcount
+= 1;
4478 tls_type
= TLS_TLS
| TLS_LD
;
4481 case R_PPC64_GOT_TLSGD16
:
4482 case R_PPC64_GOT_TLSGD16_LO
:
4483 case R_PPC64_GOT_TLSGD16_HI
:
4484 case R_PPC64_GOT_TLSGD16_HA
:
4485 tls_type
= TLS_TLS
| TLS_GD
;
4488 case R_PPC64_GOT_TPREL16_DS
:
4489 case R_PPC64_GOT_TPREL16_LO_DS
:
4490 case R_PPC64_GOT_TPREL16_HI
:
4491 case R_PPC64_GOT_TPREL16_HA
:
4493 info
->flags
|= DF_STATIC_TLS
;
4494 tls_type
= TLS_TLS
| TLS_TPREL
;
4497 case R_PPC64_GOT_DTPREL16_DS
:
4498 case R_PPC64_GOT_DTPREL16_LO_DS
:
4499 case R_PPC64_GOT_DTPREL16_HI
:
4500 case R_PPC64_GOT_DTPREL16_HA
:
4501 tls_type
= TLS_TLS
| TLS_DTPREL
;
4503 sec
->has_tls_reloc
= 1;
4507 case R_PPC64_GOT16_DS
:
4508 case R_PPC64_GOT16_HA
:
4509 case R_PPC64_GOT16_HI
:
4510 case R_PPC64_GOT16_LO
:
4511 case R_PPC64_GOT16_LO_DS
:
4512 /* This symbol requires a global offset table entry. */
4513 sec
->has_toc_reloc
= 1;
4514 if (ppc64_elf_tdata (abfd
)->got
== NULL
4515 && !create_got_section (abfd
, info
))
4520 struct ppc_link_hash_entry
*eh
;
4521 struct got_entry
*ent
;
4523 eh
= (struct ppc_link_hash_entry
*) h
;
4524 for (ent
= eh
->elf
.got
.glist
; ent
!= NULL
; ent
= ent
->next
)
4525 if (ent
->addend
== rel
->r_addend
4526 && ent
->owner
== abfd
4527 && ent
->tls_type
== tls_type
)
4531 bfd_size_type amt
= sizeof (*ent
);
4532 ent
= bfd_alloc (abfd
, amt
);
4535 ent
->next
= eh
->elf
.got
.glist
;
4536 ent
->addend
= rel
->r_addend
;
4538 ent
->tls_type
= tls_type
;
4539 ent
->got
.refcount
= 0;
4540 eh
->elf
.got
.glist
= ent
;
4542 ent
->got
.refcount
+= 1;
4543 eh
->tls_mask
|= tls_type
;
4546 /* This is a global offset table entry for a local symbol. */
4547 if (!update_local_sym_info (abfd
, symtab_hdr
, r_symndx
,
4548 rel
->r_addend
, tls_type
))
4552 case R_PPC64_PLT16_HA
:
4553 case R_PPC64_PLT16_HI
:
4554 case R_PPC64_PLT16_LO
:
4557 /* This symbol requires a procedure linkage table entry. We
4558 actually build the entry in adjust_dynamic_symbol,
4559 because this might be a case of linking PIC code without
4560 linking in any dynamic objects, in which case we don't
4561 need to generate a procedure linkage table after all. */
4564 /* It does not make sense to have a procedure linkage
4565 table entry for a local symbol. */
4566 bfd_set_error (bfd_error_bad_value
);
4570 if (!update_plt_info (abfd
, (struct ppc_link_hash_entry
*) h
,
4575 /* The following relocations don't need to propagate the
4576 relocation if linking a shared object since they are
4577 section relative. */
4578 case R_PPC64_SECTOFF
:
4579 case R_PPC64_SECTOFF_LO
:
4580 case R_PPC64_SECTOFF_HI
:
4581 case R_PPC64_SECTOFF_HA
:
4582 case R_PPC64_SECTOFF_DS
:
4583 case R_PPC64_SECTOFF_LO_DS
:
4584 case R_PPC64_DTPREL16
:
4585 case R_PPC64_DTPREL16_LO
:
4586 case R_PPC64_DTPREL16_HI
:
4587 case R_PPC64_DTPREL16_HA
:
4588 case R_PPC64_DTPREL16_DS
:
4589 case R_PPC64_DTPREL16_LO_DS
:
4590 case R_PPC64_DTPREL16_HIGHER
:
4591 case R_PPC64_DTPREL16_HIGHERA
:
4592 case R_PPC64_DTPREL16_HIGHEST
:
4593 case R_PPC64_DTPREL16_HIGHESTA
:
4598 case R_PPC64_TOC16_LO
:
4599 case R_PPC64_TOC16_HI
:
4600 case R_PPC64_TOC16_HA
:
4601 case R_PPC64_TOC16_DS
:
4602 case R_PPC64_TOC16_LO_DS
:
4603 sec
->has_toc_reloc
= 1;
4606 /* This relocation describes the C++ object vtable hierarchy.
4607 Reconstruct it for later use during GC. */
4608 case R_PPC64_GNU_VTINHERIT
:
4609 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
4613 /* This relocation describes which C++ vtable entries are actually
4614 used. Record for later use during GC. */
4615 case R_PPC64_GNU_VTENTRY
:
4616 if (!bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
4621 case R_PPC64_REL14_BRTAKEN
:
4622 case R_PPC64_REL14_BRNTAKEN
:
4624 asection
*dest
= NULL
;
4626 /* Heuristic: If jumping outside our section, chances are
4627 we are going to need a stub. */
4630 /* If the sym is weak it may be overridden later, so
4631 don't assume we know where a weak sym lives. */
4632 if (h
->root
.type
== bfd_link_hash_defined
)
4633 dest
= h
->root
.u
.def
.section
;
4636 dest
= bfd_section_from_r_symndx (abfd
, &htab
->sym_sec
,
4639 ppc64_elf_section_data (sec
)->has_14bit_branch
= 1;
4646 /* We may need a .plt entry if the function this reloc
4647 refers to is in a shared lib. */
4648 if (!update_plt_info (abfd
, (struct ppc_link_hash_entry
*) h
,
4651 if (h
== &htab
->tls_get_addr
->elf
4652 || h
== &htab
->tls_get_addr_fd
->elf
)
4653 sec
->has_tls_reloc
= 1;
4654 else if (htab
->tls_get_addr
== NULL
4655 && CONST_STRNEQ (h
->root
.root
.string
, ".__tls_get_addr")
4656 && (h
->root
.root
.string
[15] == 0
4657 || h
->root
.root
.string
[15] == '@'))
4659 htab
->tls_get_addr
= (struct ppc_link_hash_entry
*) h
;
4660 sec
->has_tls_reloc
= 1;
4662 else if (htab
->tls_get_addr_fd
== NULL
4663 && CONST_STRNEQ (h
->root
.root
.string
, "__tls_get_addr")
4664 && (h
->root
.root
.string
[14] == 0
4665 || h
->root
.root
.string
[14] == '@'))
4667 htab
->tls_get_addr_fd
= (struct ppc_link_hash_entry
*) h
;
4668 sec
->has_tls_reloc
= 1;
4673 case R_PPC64_TPREL64
:
4674 tls_type
= TLS_EXPLICIT
| TLS_TLS
| TLS_TPREL
;
4676 info
->flags
|= DF_STATIC_TLS
;
4679 case R_PPC64_DTPMOD64
:
4680 if (rel
+ 1 < rel_end
4681 && rel
[1].r_info
== ELF64_R_INFO (r_symndx
, R_PPC64_DTPREL64
)
4682 && rel
[1].r_offset
== rel
->r_offset
+ 8)
4683 tls_type
= TLS_EXPLICIT
| TLS_TLS
| TLS_GD
;
4685 tls_type
= TLS_EXPLICIT
| TLS_TLS
| TLS_LD
;
4688 case R_PPC64_DTPREL64
:
4689 tls_type
= TLS_EXPLICIT
| TLS_TLS
| TLS_DTPREL
;
4691 && rel
[-1].r_info
== ELF64_R_INFO (r_symndx
, R_PPC64_DTPMOD64
)
4692 && rel
[-1].r_offset
== rel
->r_offset
- 8)
4693 /* This is the second reloc of a dtpmod, dtprel pair.
4694 Don't mark with TLS_DTPREL. */
4698 sec
->has_tls_reloc
= 1;
4701 struct ppc_link_hash_entry
*eh
;
4702 eh
= (struct ppc_link_hash_entry
*) h
;
4703 eh
->tls_mask
|= tls_type
;
4706 if (!update_local_sym_info (abfd
, symtab_hdr
, r_symndx
,
4707 rel
->r_addend
, tls_type
))
4710 ppc64_sec
= ppc64_elf_section_data (sec
);
4711 if (ppc64_sec
->sec_type
!= sec_toc
)
4713 /* One extra to simplify get_tls_mask. */
4714 bfd_size_type amt
= sec
->size
* sizeof (unsigned) / 8 + 1;
4715 ppc64_sec
->u
.t_symndx
= bfd_zalloc (abfd
, amt
);
4716 if (ppc64_sec
->u
.t_symndx
== NULL
)
4718 BFD_ASSERT (ppc64_sec
->sec_type
== sec_normal
);
4719 ppc64_sec
->sec_type
= sec_toc
;
4721 BFD_ASSERT (rel
->r_offset
% 8 == 0);
4722 ppc64_sec
->u
.t_symndx
[rel
->r_offset
/ 8] = r_symndx
;
4724 /* Mark the second slot of a GD or LD entry.
4725 -1 to indicate GD and -2 to indicate LD. */
4726 if (tls_type
== (TLS_EXPLICIT
| TLS_TLS
| TLS_GD
))
4727 ppc64_sec
->u
.t_symndx
[rel
->r_offset
/ 8 + 1] = -1;
4728 else if (tls_type
== (TLS_EXPLICIT
| TLS_TLS
| TLS_LD
))
4729 ppc64_sec
->u
.t_symndx
[rel
->r_offset
/ 8 + 1] = -2;
4732 case R_PPC64_TPREL16
:
4733 case R_PPC64_TPREL16_LO
:
4734 case R_PPC64_TPREL16_HI
:
4735 case R_PPC64_TPREL16_HA
:
4736 case R_PPC64_TPREL16_DS
:
4737 case R_PPC64_TPREL16_LO_DS
:
4738 case R_PPC64_TPREL16_HIGHER
:
4739 case R_PPC64_TPREL16_HIGHERA
:
4740 case R_PPC64_TPREL16_HIGHEST
:
4741 case R_PPC64_TPREL16_HIGHESTA
:
4744 info
->flags
|= DF_STATIC_TLS
;
4749 case R_PPC64_ADDR64
:
4750 if (opd_sym_map
!= NULL
4751 && rel
+ 1 < rel_end
4752 && ELF64_R_TYPE ((rel
+ 1)->r_info
) == R_PPC64_TOC
)
4756 if (h
->root
.root
.string
[0] == '.'
4757 && h
->root
.root
.string
[1] != 0
4758 && get_fdh ((struct ppc_link_hash_entry
*) h
, htab
))
4761 ((struct ppc_link_hash_entry
*) h
)->is_func
= 1;
4767 s
= bfd_section_from_r_symndx (abfd
, &htab
->sym_sec
, sec
,
4772 opd_sym_map
[rel
->r_offset
/ 8] = s
;
4780 case R_PPC64_ADDR14
:
4781 case R_PPC64_ADDR14_BRNTAKEN
:
4782 case R_PPC64_ADDR14_BRTAKEN
:
4783 case R_PPC64_ADDR16
:
4784 case R_PPC64_ADDR16_DS
:
4785 case R_PPC64_ADDR16_HA
:
4786 case R_PPC64_ADDR16_HI
:
4787 case R_PPC64_ADDR16_HIGHER
:
4788 case R_PPC64_ADDR16_HIGHERA
:
4789 case R_PPC64_ADDR16_HIGHEST
:
4790 case R_PPC64_ADDR16_HIGHESTA
:
4791 case R_PPC64_ADDR16_LO
:
4792 case R_PPC64_ADDR16_LO_DS
:
4793 case R_PPC64_ADDR24
:
4794 case R_PPC64_ADDR32
:
4795 case R_PPC64_UADDR16
:
4796 case R_PPC64_UADDR32
:
4797 case R_PPC64_UADDR64
:
4799 if (h
!= NULL
&& !info
->shared
)
4800 /* We may need a copy reloc. */
4803 /* Don't propagate .opd relocs. */
4804 if (NO_OPD_RELOCS
&& opd_sym_map
!= NULL
)
4807 /* If we are creating a shared library, and this is a reloc
4808 against a global symbol, or a non PC relative reloc
4809 against a local symbol, then we need to copy the reloc
4810 into the shared library. However, if we are linking with
4811 -Bsymbolic, we do not need to copy a reloc against a
4812 global symbol which is defined in an object we are
4813 including in the link (i.e., DEF_REGULAR is set). At
4814 this point we have not seen all the input files, so it is
4815 possible that DEF_REGULAR is not set now but will be set
4816 later (it is never cleared). In case of a weak definition,
4817 DEF_REGULAR may be cleared later by a strong definition in
4818 a shared library. We account for that possibility below by
4819 storing information in the dyn_relocs field of the hash
4820 table entry. A similar situation occurs when creating
4821 shared libraries and symbol visibility changes render the
4824 If on the other hand, we are creating an executable, we
4825 may need to keep relocations for symbols satisfied by a
4826 dynamic library if we manage to avoid copy relocs for the
4830 && (MUST_BE_DYN_RELOC (r_type
)
4832 && (! info
->symbolic
4833 || h
->root
.type
== bfd_link_hash_defweak
4834 || !h
->def_regular
))))
4835 || (ELIMINATE_COPY_RELOCS
4838 && (h
->root
.type
== bfd_link_hash_defweak
4839 || !h
->def_regular
)))
4841 struct ppc_dyn_relocs
*p
;
4842 struct ppc_dyn_relocs
**head
;
4844 /* We must copy these reloc types into the output file.
4845 Create a reloc section in dynobj and make room for
4852 name
= (bfd_elf_string_from_elf_section
4854 elf_elfheader (abfd
)->e_shstrndx
,
4855 elf_section_data (sec
)->rel_hdr
.sh_name
));
4859 if (! CONST_STRNEQ (name
, ".rela")
4860 || strcmp (bfd_get_section_name (abfd
, sec
),
4863 (*_bfd_error_handler
)
4864 (_("%B: bad relocation section name `%s\'"),
4866 bfd_set_error (bfd_error_bad_value
);
4869 dynobj
= htab
->elf
.dynobj
;
4870 sreloc
= bfd_get_section_by_name (dynobj
, name
);
4875 flags
= (SEC_HAS_CONTENTS
| SEC_READONLY
4876 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
4877 | SEC_ALLOC
| SEC_LOAD
);
4878 sreloc
= bfd_make_section_with_flags (dynobj
,
4882 || ! bfd_set_section_alignment (dynobj
, sreloc
, 3))
4885 elf_section_data (sec
)->sreloc
= sreloc
;
4888 /* If this is a global symbol, we count the number of
4889 relocations we need for this symbol. */
4892 head
= &((struct ppc_link_hash_entry
*) h
)->dyn_relocs
;
4896 /* Track dynamic relocs needed for local syms too.
4897 We really need local syms available to do this
4903 s
= bfd_section_from_r_symndx (abfd
, &htab
->sym_sec
,
4908 vpp
= &elf_section_data (s
)->local_dynrel
;
4909 head
= (struct ppc_dyn_relocs
**) vpp
;
4913 if (p
== NULL
|| p
->sec
!= sec
)
4915 p
= bfd_alloc (htab
->elf
.dynobj
, sizeof *p
);
4926 if (!MUST_BE_DYN_RELOC (r_type
))
4939 /* OFFSET in OPD_SEC specifies a function descriptor. Return the address
4940 of the code entry point, and its section. */
4943 opd_entry_value (asection
*opd_sec
,
4945 asection
**code_sec
,
4948 bfd
*opd_bfd
= opd_sec
->owner
;
4949 Elf_Internal_Rela
*relocs
;
4950 Elf_Internal_Rela
*lo
, *hi
, *look
;
4953 /* No relocs implies we are linking a --just-symbols object. */
4954 if (opd_sec
->reloc_count
== 0)
4958 if (!bfd_get_section_contents (opd_bfd
, opd_sec
, &val
, offset
, 8))
4959 return (bfd_vma
) -1;
4961 if (code_sec
!= NULL
)
4963 asection
*sec
, *likely
= NULL
;
4964 for (sec
= opd_bfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
4966 && (sec
->flags
& SEC_LOAD
) != 0
4967 && (sec
->flags
& SEC_ALLOC
) != 0)
4972 if (code_off
!= NULL
)
4973 *code_off
= val
- likely
->vma
;
4979 relocs
= ppc64_elf_tdata (opd_bfd
)->opd_relocs
;
4981 relocs
= _bfd_elf_link_read_relocs (opd_bfd
, opd_sec
, NULL
, NULL
, TRUE
);
4983 /* Go find the opd reloc at the sym address. */
4985 BFD_ASSERT (lo
!= NULL
);
4986 hi
= lo
+ opd_sec
->reloc_count
- 1; /* ignore last reloc */
4990 look
= lo
+ (hi
- lo
) / 2;
4991 if (look
->r_offset
< offset
)
4993 else if (look
->r_offset
> offset
)
4997 Elf_Internal_Shdr
*symtab_hdr
= &elf_tdata (opd_bfd
)->symtab_hdr
;
4998 if (ELF64_R_TYPE (look
->r_info
) == R_PPC64_ADDR64
4999 && ELF64_R_TYPE ((look
+ 1)->r_info
) == R_PPC64_TOC
)
5001 unsigned long symndx
= ELF64_R_SYM (look
->r_info
);
5004 if (symndx
< symtab_hdr
->sh_info
)
5006 Elf_Internal_Sym
*sym
;
5008 sym
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
5011 sym
= bfd_elf_get_elf_syms (opd_bfd
, symtab_hdr
,
5012 symtab_hdr
->sh_info
,
5013 0, NULL
, NULL
, NULL
);
5016 symtab_hdr
->contents
= (bfd_byte
*) sym
;
5020 val
= sym
->st_value
;
5022 if ((sym
->st_shndx
!= SHN_UNDEF
5023 && sym
->st_shndx
< SHN_LORESERVE
)
5024 || sym
->st_shndx
> SHN_HIRESERVE
)
5025 sec
= bfd_section_from_elf_index (opd_bfd
, sym
->st_shndx
);
5026 BFD_ASSERT ((sec
->flags
& SEC_MERGE
) == 0);
5030 struct elf_link_hash_entry
**sym_hashes
;
5031 struct elf_link_hash_entry
*rh
;
5033 sym_hashes
= elf_sym_hashes (opd_bfd
);
5034 rh
= sym_hashes
[symndx
- symtab_hdr
->sh_info
];
5035 while (rh
->root
.type
== bfd_link_hash_indirect
5036 || rh
->root
.type
== bfd_link_hash_warning
)
5037 rh
= ((struct elf_link_hash_entry
*) rh
->root
.u
.i
.link
);
5038 BFD_ASSERT (rh
->root
.type
== bfd_link_hash_defined
5039 || rh
->root
.type
== bfd_link_hash_defweak
);
5040 val
= rh
->root
.u
.def
.value
;
5041 sec
= rh
->root
.u
.def
.section
;
5043 val
+= look
->r_addend
;
5044 if (code_off
!= NULL
)
5046 if (code_sec
!= NULL
)
5048 if (sec
!= NULL
&& sec
->output_section
!= NULL
)
5049 val
+= sec
->output_section
->vma
+ sec
->output_offset
;
5058 /* Mark sections containing dynamically referenced symbols. When
5059 building shared libraries, we must assume that any visible symbol is
5063 ppc64_elf_gc_mark_dynamic_ref (struct elf_link_hash_entry
*h
, void *inf
)
5065 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
5066 struct ppc_link_hash_entry
*eh
= (struct ppc_link_hash_entry
*) h
;
5068 if (eh
->elf
.root
.type
== bfd_link_hash_warning
)
5069 eh
= (struct ppc_link_hash_entry
*) eh
->elf
.root
.u
.i
.link
;
5071 /* Dynamic linking info is on the func descriptor sym. */
5073 && eh
->oh
->is_func_descriptor
5074 && (eh
->oh
->elf
.root
.type
== bfd_link_hash_defined
5075 || eh
->oh
->elf
.root
.type
== bfd_link_hash_defweak
))
5078 if ((eh
->elf
.root
.type
== bfd_link_hash_defined
5079 || eh
->elf
.root
.type
== bfd_link_hash_defweak
)
5080 && (eh
->elf
.ref_dynamic
5081 || (!info
->executable
5082 && eh
->elf
.def_regular
5083 && ELF_ST_VISIBILITY (eh
->elf
.other
) != STV_INTERNAL
5084 && ELF_ST_VISIBILITY (eh
->elf
.other
) != STV_HIDDEN
)))
5088 eh
->elf
.root
.u
.def
.section
->flags
|= SEC_KEEP
;
5090 /* Function descriptor syms cause the associated
5091 function code sym section to be marked. */
5092 if (eh
->is_func_descriptor
5093 && (eh
->oh
->elf
.root
.type
== bfd_link_hash_defined
5094 || eh
->oh
->elf
.root
.type
== bfd_link_hash_defweak
))
5095 eh
->oh
->elf
.root
.u
.def
.section
->flags
|= SEC_KEEP
;
5096 else if (get_opd_info (eh
->elf
.root
.u
.def
.section
) != NULL
5097 && opd_entry_value (eh
->elf
.root
.u
.def
.section
,
5098 eh
->elf
.root
.u
.def
.value
,
5099 &code_sec
, NULL
) != (bfd_vma
) -1)
5100 code_sec
->flags
|= SEC_KEEP
;
5106 /* Return the section that should be marked against GC for a given
5110 ppc64_elf_gc_mark_hook (asection
*sec
,
5111 struct bfd_link_info
*info
,
5112 Elf_Internal_Rela
*rel
,
5113 struct elf_link_hash_entry
*h
,
5114 Elf_Internal_Sym
*sym
)
5118 /* First mark all our entry sym sections. */
5119 if (info
->gc_sym_list
!= NULL
)
5121 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
5122 struct bfd_sym_chain
*sym
= info
->gc_sym_list
;
5124 info
->gc_sym_list
= NULL
;
5125 for (; sym
!= NULL
; sym
= sym
->next
)
5127 struct ppc_link_hash_entry
*eh
;
5129 eh
= (struct ppc_link_hash_entry
*)
5130 elf_link_hash_lookup (&htab
->elf
, sym
->name
, FALSE
, FALSE
, FALSE
);
5133 if (eh
->elf
.root
.type
!= bfd_link_hash_defined
5134 && eh
->elf
.root
.type
!= bfd_link_hash_defweak
)
5137 if (eh
->is_func_descriptor
5138 && (eh
->oh
->elf
.root
.type
== bfd_link_hash_defined
5139 || eh
->oh
->elf
.root
.type
== bfd_link_hash_defweak
))
5140 rsec
= eh
->oh
->elf
.root
.u
.def
.section
;
5141 else if (get_opd_info (eh
->elf
.root
.u
.def
.section
) != NULL
5142 && opd_entry_value (eh
->elf
.root
.u
.def
.section
,
5143 eh
->elf
.root
.u
.def
.value
,
5144 &rsec
, NULL
) != (bfd_vma
) -1)
5150 _bfd_elf_gc_mark (info
, rsec
, ppc64_elf_gc_mark_hook
);
5152 rsec
= eh
->elf
.root
.u
.def
.section
;
5154 _bfd_elf_gc_mark (info
, rsec
, ppc64_elf_gc_mark_hook
);
5158 /* Syms return NULL if we're marking .opd, so we avoid marking all
5159 function sections, as all functions are referenced in .opd. */
5161 if (get_opd_info (sec
) != NULL
)
5166 enum elf_ppc64_reloc_type r_type
;
5167 struct ppc_link_hash_entry
*eh
;
5169 r_type
= ELF64_R_TYPE (rel
->r_info
);
5172 case R_PPC64_GNU_VTINHERIT
:
5173 case R_PPC64_GNU_VTENTRY
:
5177 switch (h
->root
.type
)
5179 case bfd_link_hash_defined
:
5180 case bfd_link_hash_defweak
:
5181 eh
= (struct ppc_link_hash_entry
*) h
;
5183 && eh
->oh
->is_func_descriptor
5184 && (eh
->oh
->elf
.root
.type
== bfd_link_hash_defined
5185 || eh
->oh
->elf
.root
.type
== bfd_link_hash_defweak
))
5188 /* Function descriptor syms cause the associated
5189 function code sym section to be marked. */
5190 if (eh
->is_func_descriptor
5191 && (eh
->oh
->elf
.root
.type
== bfd_link_hash_defined
5192 || eh
->oh
->elf
.root
.type
== bfd_link_hash_defweak
))
5194 /* They also mark their opd section. */
5195 if (!eh
->elf
.root
.u
.def
.section
->gc_mark
)
5196 _bfd_elf_gc_mark (info
, eh
->elf
.root
.u
.def
.section
,
5197 ppc64_elf_gc_mark_hook
);
5199 rsec
= eh
->oh
->elf
.root
.u
.def
.section
;
5201 else if (get_opd_info (eh
->elf
.root
.u
.def
.section
) != NULL
5202 && opd_entry_value (eh
->elf
.root
.u
.def
.section
,
5203 eh
->elf
.root
.u
.def
.value
,
5204 &rsec
, NULL
) != (bfd_vma
) -1)
5206 if (!eh
->elf
.root
.u
.def
.section
->gc_mark
)
5207 _bfd_elf_gc_mark (info
, eh
->elf
.root
.u
.def
.section
,
5208 ppc64_elf_gc_mark_hook
);
5211 rsec
= h
->root
.u
.def
.section
;
5214 case bfd_link_hash_common
:
5215 rsec
= h
->root
.u
.c
.p
->section
;
5225 asection
**opd_sym_section
;
5227 rsec
= bfd_section_from_elf_index (sec
->owner
, sym
->st_shndx
);
5228 opd_sym_section
= get_opd_info (rsec
);
5229 if (opd_sym_section
!= NULL
)
5232 _bfd_elf_gc_mark (info
, rsec
, ppc64_elf_gc_mark_hook
);
5234 rsec
= opd_sym_section
[(sym
->st_value
+ rel
->r_addend
) / 8];
5241 /* Update the .got, .plt. and dynamic reloc reference counts for the
5242 section being removed. */
5245 ppc64_elf_gc_sweep_hook (bfd
*abfd
, struct bfd_link_info
*info
,
5246 asection
*sec
, const Elf_Internal_Rela
*relocs
)
5248 struct ppc_link_hash_table
*htab
;
5249 Elf_Internal_Shdr
*symtab_hdr
;
5250 struct elf_link_hash_entry
**sym_hashes
;
5251 struct got_entry
**local_got_ents
;
5252 const Elf_Internal_Rela
*rel
, *relend
;
5254 if ((sec
->flags
& SEC_ALLOC
) == 0)
5257 elf_section_data (sec
)->local_dynrel
= NULL
;
5259 htab
= ppc_hash_table (info
);
5260 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
5261 sym_hashes
= elf_sym_hashes (abfd
);
5262 local_got_ents
= elf_local_got_ents (abfd
);
5264 relend
= relocs
+ sec
->reloc_count
;
5265 for (rel
= relocs
; rel
< relend
; rel
++)
5267 unsigned long r_symndx
;
5268 enum elf_ppc64_reloc_type r_type
;
5269 struct elf_link_hash_entry
*h
= NULL
;
5272 r_symndx
= ELF64_R_SYM (rel
->r_info
);
5273 r_type
= ELF64_R_TYPE (rel
->r_info
);
5274 if (r_symndx
>= symtab_hdr
->sh_info
)
5276 struct ppc_link_hash_entry
*eh
;
5277 struct ppc_dyn_relocs
**pp
;
5278 struct ppc_dyn_relocs
*p
;
5280 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
5281 while (h
->root
.type
== bfd_link_hash_indirect
5282 || h
->root
.type
== bfd_link_hash_warning
)
5283 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
5284 eh
= (struct ppc_link_hash_entry
*) h
;
5286 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; pp
= &p
->next
)
5289 /* Everything must go for SEC. */
5297 case R_PPC64_GOT_TLSLD16
:
5298 case R_PPC64_GOT_TLSLD16_LO
:
5299 case R_PPC64_GOT_TLSLD16_HI
:
5300 case R_PPC64_GOT_TLSLD16_HA
:
5301 ppc64_tlsld_got (abfd
)->refcount
-= 1;
5302 tls_type
= TLS_TLS
| TLS_LD
;
5305 case R_PPC64_GOT_TLSGD16
:
5306 case R_PPC64_GOT_TLSGD16_LO
:
5307 case R_PPC64_GOT_TLSGD16_HI
:
5308 case R_PPC64_GOT_TLSGD16_HA
:
5309 tls_type
= TLS_TLS
| TLS_GD
;
5312 case R_PPC64_GOT_TPREL16_DS
:
5313 case R_PPC64_GOT_TPREL16_LO_DS
:
5314 case R_PPC64_GOT_TPREL16_HI
:
5315 case R_PPC64_GOT_TPREL16_HA
:
5316 tls_type
= TLS_TLS
| TLS_TPREL
;
5319 case R_PPC64_GOT_DTPREL16_DS
:
5320 case R_PPC64_GOT_DTPREL16_LO_DS
:
5321 case R_PPC64_GOT_DTPREL16_HI
:
5322 case R_PPC64_GOT_DTPREL16_HA
:
5323 tls_type
= TLS_TLS
| TLS_DTPREL
;
5327 case R_PPC64_GOT16_DS
:
5328 case R_PPC64_GOT16_HA
:
5329 case R_PPC64_GOT16_HI
:
5330 case R_PPC64_GOT16_LO
:
5331 case R_PPC64_GOT16_LO_DS
:
5334 struct got_entry
*ent
;
5339 ent
= local_got_ents
[r_symndx
];
5341 for (; ent
!= NULL
; ent
= ent
->next
)
5342 if (ent
->addend
== rel
->r_addend
5343 && ent
->owner
== abfd
5344 && ent
->tls_type
== tls_type
)
5348 if (ent
->got
.refcount
> 0)
5349 ent
->got
.refcount
-= 1;
5353 case R_PPC64_PLT16_HA
:
5354 case R_PPC64_PLT16_HI
:
5355 case R_PPC64_PLT16_LO
:
5359 case R_PPC64_REL14_BRNTAKEN
:
5360 case R_PPC64_REL14_BRTAKEN
:
5364 struct plt_entry
*ent
;
5366 for (ent
= h
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
5367 if (ent
->addend
== rel
->r_addend
)
5371 if (ent
->plt
.refcount
> 0)
5372 ent
->plt
.refcount
-= 1;
5383 /* The maximum size of .sfpr. */
5384 #define SFPR_MAX (218*4)
5386 struct sfpr_def_parms
5388 const char name
[12];
5389 unsigned char lo
, hi
;
5390 bfd_byte
* (*write_ent
) (bfd
*, bfd_byte
*, int);
5391 bfd_byte
* (*write_tail
) (bfd
*, bfd_byte
*, int);
5394 /* Auto-generate _save*, _rest* functions in .sfpr. */
5397 sfpr_define (struct bfd_link_info
*info
, const struct sfpr_def_parms
*parm
)
5399 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
5401 size_t len
= strlen (parm
->name
);
5402 bfd_boolean writing
= FALSE
;
5405 memcpy (sym
, parm
->name
, len
);
5408 for (i
= parm
->lo
; i
<= parm
->hi
; i
++)
5410 struct elf_link_hash_entry
*h
;
5412 sym
[len
+ 0] = i
/ 10 + '0';
5413 sym
[len
+ 1] = i
% 10 + '0';
5414 h
= elf_link_hash_lookup (&htab
->elf
, sym
, FALSE
, FALSE
, TRUE
);
5418 h
->root
.type
= bfd_link_hash_defined
;
5419 h
->root
.u
.def
.section
= htab
->sfpr
;
5420 h
->root
.u
.def
.value
= htab
->sfpr
->size
;
5423 _bfd_elf_link_hash_hide_symbol (info
, h
, TRUE
);
5425 if (htab
->sfpr
->contents
== NULL
)
5427 htab
->sfpr
->contents
= bfd_alloc (htab
->elf
.dynobj
, SFPR_MAX
);
5428 if (htab
->sfpr
->contents
== NULL
)
5434 bfd_byte
*p
= htab
->sfpr
->contents
+ htab
->sfpr
->size
;
5436 p
= (*parm
->write_ent
) (htab
->elf
.dynobj
, p
, i
);
5438 p
= (*parm
->write_tail
) (htab
->elf
.dynobj
, p
, i
);
5439 htab
->sfpr
->size
= p
- htab
->sfpr
->contents
;
5447 savegpr0 (bfd
*abfd
, bfd_byte
*p
, int r
)
5449 bfd_put_32 (abfd
, STD_R0_0R1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
5454 savegpr0_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
5456 p
= savegpr0 (abfd
, p
, r
);
5457 bfd_put_32 (abfd
, STD_R0_0R1
+ 16, p
);
5459 bfd_put_32 (abfd
, BLR
, p
);
5464 restgpr0 (bfd
*abfd
, bfd_byte
*p
, int r
)
5466 bfd_put_32 (abfd
, LD_R0_0R1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
5471 restgpr0_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
5473 bfd_put_32 (abfd
, LD_R0_0R1
+ 16, p
);
5475 p
= restgpr0 (abfd
, p
, r
);
5476 bfd_put_32 (abfd
, MTLR_R0
, p
);
5480 p
= restgpr0 (abfd
, p
, 30);
5481 p
= restgpr0 (abfd
, p
, 31);
5483 bfd_put_32 (abfd
, BLR
, p
);
5488 savegpr1 (bfd
*abfd
, bfd_byte
*p
, int r
)
5490 bfd_put_32 (abfd
, STD_R0_0R12
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
5495 savegpr1_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
5497 p
= savegpr1 (abfd
, p
, r
);
5498 bfd_put_32 (abfd
, BLR
, p
);
5503 restgpr1 (bfd
*abfd
, bfd_byte
*p
, int r
)
5505 bfd_put_32 (abfd
, LD_R0_0R12
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
5510 restgpr1_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
5512 p
= restgpr1 (abfd
, p
, r
);
5513 bfd_put_32 (abfd
, BLR
, p
);
5518 savefpr (bfd
*abfd
, bfd_byte
*p
, int r
)
5520 bfd_put_32 (abfd
, STFD_FR0_0R1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
5525 savefpr0_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
5527 p
= savefpr (abfd
, p
, r
);
5528 bfd_put_32 (abfd
, STD_R0_0R1
+ 16, p
);
5530 bfd_put_32 (abfd
, BLR
, p
);
5535 restfpr (bfd
*abfd
, bfd_byte
*p
, int r
)
5537 bfd_put_32 (abfd
, LFD_FR0_0R1
+ (r
<< 21) + (1 << 16) - (32 - r
) * 8, p
);
5542 restfpr0_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
5544 bfd_put_32 (abfd
, LD_R0_0R1
+ 16, p
);
5546 p
= restfpr (abfd
, p
, r
);
5547 bfd_put_32 (abfd
, MTLR_R0
, p
);
5551 p
= restfpr (abfd
, p
, 30);
5552 p
= restfpr (abfd
, p
, 31);
5554 bfd_put_32 (abfd
, BLR
, p
);
5559 savefpr1_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
5561 p
= savefpr (abfd
, p
, r
);
5562 bfd_put_32 (abfd
, BLR
, p
);
5567 restfpr1_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
5569 p
= restfpr (abfd
, p
, r
);
5570 bfd_put_32 (abfd
, BLR
, p
);
5575 savevr (bfd
*abfd
, bfd_byte
*p
, int r
)
5577 bfd_put_32 (abfd
, LI_R12_0
+ (1 << 16) - (32 - r
) * 16, p
);
5579 bfd_put_32 (abfd
, STVX_VR0_R12_R0
+ (r
<< 21), p
);
5584 savevr_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
5586 p
= savevr (abfd
, p
, r
);
5587 bfd_put_32 (abfd
, BLR
, p
);
5592 restvr (bfd
*abfd
, bfd_byte
*p
, int r
)
5594 bfd_put_32 (abfd
, LI_R12_0
+ (1 << 16) - (32 - r
) * 16, p
);
5596 bfd_put_32 (abfd
, LVX_VR0_R12_R0
+ (r
<< 21), p
);
5601 restvr_tail (bfd
*abfd
, bfd_byte
*p
, int r
)
5603 p
= restvr (abfd
, p
, r
);
5604 bfd_put_32 (abfd
, BLR
, p
);
5608 /* Called via elf_link_hash_traverse to transfer dynamic linking
5609 information on function code symbol entries to their corresponding
5610 function descriptor symbol entries. */
5613 func_desc_adjust (struct elf_link_hash_entry
*h
, void *inf
)
5615 struct bfd_link_info
*info
;
5616 struct ppc_link_hash_table
*htab
;
5617 struct plt_entry
*ent
;
5618 struct ppc_link_hash_entry
*fh
;
5619 struct ppc_link_hash_entry
*fdh
;
5620 bfd_boolean force_local
;
5622 fh
= (struct ppc_link_hash_entry
*) h
;
5623 if (fh
->elf
.root
.type
== bfd_link_hash_indirect
)
5626 if (fh
->elf
.root
.type
== bfd_link_hash_warning
)
5627 fh
= (struct ppc_link_hash_entry
*) fh
->elf
.root
.u
.i
.link
;
5630 htab
= ppc_hash_table (info
);
5632 /* Resolve undefined references to dot-symbols as the value
5633 in the function descriptor, if we have one in a regular object.
5634 This is to satisfy cases like ".quad .foo". Calls to functions
5635 in dynamic objects are handled elsewhere. */
5636 if (fh
->elf
.root
.type
== bfd_link_hash_undefweak
5637 && fh
->was_undefined
5638 && (fh
->oh
->elf
.root
.type
== bfd_link_hash_defined
5639 || fh
->oh
->elf
.root
.type
== bfd_link_hash_defweak
)
5640 && get_opd_info (fh
->oh
->elf
.root
.u
.def
.section
) != NULL
5641 && opd_entry_value (fh
->oh
->elf
.root
.u
.def
.section
,
5642 fh
->oh
->elf
.root
.u
.def
.value
,
5643 &fh
->elf
.root
.u
.def
.section
,
5644 &fh
->elf
.root
.u
.def
.value
) != (bfd_vma
) -1)
5646 fh
->elf
.root
.type
= fh
->oh
->elf
.root
.type
;
5647 fh
->elf
.forced_local
= 1;
5650 /* If this is a function code symbol, transfer dynamic linking
5651 information to the function descriptor symbol. */
5655 for (ent
= fh
->elf
.plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
5656 if (ent
->plt
.refcount
> 0)
5659 || fh
->elf
.root
.root
.string
[0] != '.'
5660 || fh
->elf
.root
.root
.string
[1] == '\0')
5663 /* Find the corresponding function descriptor symbol. Create it
5664 as undefined if necessary. */
5666 fdh
= get_fdh (fh
, htab
);
5668 while (fdh
->elf
.root
.type
== bfd_link_hash_indirect
5669 || fdh
->elf
.root
.type
== bfd_link_hash_warning
)
5670 fdh
= (struct ppc_link_hash_entry
*) fdh
->elf
.root
.u
.i
.link
;
5674 && (fh
->elf
.root
.type
== bfd_link_hash_undefined
5675 || fh
->elf
.root
.type
== bfd_link_hash_undefweak
))
5677 fdh
= make_fdh (info
, fh
);
5682 /* Fake function descriptors are made undefweak. If the function
5683 code symbol is strong undefined, make the fake sym the same.
5684 If the function code symbol is defined, then force the fake
5685 descriptor local; We can't support overriding of symbols in a
5686 shared library on a fake descriptor. */
5690 && fdh
->elf
.root
.type
== bfd_link_hash_undefweak
)
5692 if (fh
->elf
.root
.type
== bfd_link_hash_undefined
)
5694 fdh
->elf
.root
.type
= bfd_link_hash_undefined
;
5695 bfd_link_add_undef (&htab
->elf
.root
, &fdh
->elf
.root
);
5697 else if (fh
->elf
.root
.type
== bfd_link_hash_defined
5698 || fh
->elf
.root
.type
== bfd_link_hash_defweak
)
5700 _bfd_elf_link_hash_hide_symbol (info
, &fdh
->elf
, TRUE
);
5705 && !fdh
->elf
.forced_local
5707 || fdh
->elf
.def_dynamic
5708 || fdh
->elf
.ref_dynamic
5709 || (fdh
->elf
.root
.type
== bfd_link_hash_undefweak
5710 && ELF_ST_VISIBILITY (fdh
->elf
.other
) == STV_DEFAULT
)))
5712 if (fdh
->elf
.dynindx
== -1)
5713 if (! bfd_elf_link_record_dynamic_symbol (info
, &fdh
->elf
))
5715 fdh
->elf
.ref_regular
|= fh
->elf
.ref_regular
;
5716 fdh
->elf
.ref_dynamic
|= fh
->elf
.ref_dynamic
;
5717 fdh
->elf
.ref_regular_nonweak
|= fh
->elf
.ref_regular_nonweak
;
5718 fdh
->elf
.non_got_ref
|= fh
->elf
.non_got_ref
;
5719 if (ELF_ST_VISIBILITY (fh
->elf
.other
) == STV_DEFAULT
)
5721 move_plt_plist (fh
, fdh
);
5722 fdh
->elf
.needs_plt
= 1;
5724 fdh
->is_func_descriptor
= 1;
5729 /* Now that the info is on the function descriptor, clear the
5730 function code sym info. Any function code syms for which we
5731 don't have a definition in a regular file, we force local.
5732 This prevents a shared library from exporting syms that have
5733 been imported from another library. Function code syms that
5734 are really in the library we must leave global to prevent the
5735 linker dragging in a definition from a static library. */
5736 force_local
= (!fh
->elf
.def_regular
5738 || !fdh
->elf
.def_regular
5739 || fdh
->elf
.forced_local
);
5740 _bfd_elf_link_hash_hide_symbol (info
, &fh
->elf
, force_local
);
5745 /* Called near the start of bfd_elf_size_dynamic_sections. We use
5746 this hook to a) provide some gcc support functions, and b) transfer
5747 dynamic linking information gathered so far on function code symbol
5748 entries, to their corresponding function descriptor symbol entries. */
5751 ppc64_elf_func_desc_adjust (bfd
*obfd ATTRIBUTE_UNUSED
,
5752 struct bfd_link_info
*info
)
5754 struct ppc_link_hash_table
*htab
;
5756 const struct sfpr_def_parms funcs
[] =
5758 { "_savegpr0_", 14, 31, savegpr0
, savegpr0_tail
},
5759 { "_restgpr0_", 14, 29, restgpr0
, restgpr0_tail
},
5760 { "_restgpr0_", 30, 31, restgpr0
, restgpr0_tail
},
5761 { "_savegpr1_", 14, 31, savegpr1
, savegpr1_tail
},
5762 { "_restgpr1_", 14, 31, restgpr1
, restgpr1_tail
},
5763 { "_savefpr_", 14, 31, savefpr
, savefpr0_tail
},
5764 { "_restfpr_", 14, 29, restfpr
, restfpr0_tail
},
5765 { "_restfpr_", 30, 31, restfpr
, restfpr0_tail
},
5766 { "._savef", 14, 31, savefpr
, savefpr1_tail
},
5767 { "._restf", 14, 31, restfpr
, restfpr1_tail
},
5768 { "_savevr_", 20, 31, savevr
, savevr_tail
},
5769 { "_restvr_", 20, 31, restvr
, restvr_tail
}
5772 htab
= ppc_hash_table (info
);
5773 if (htab
->sfpr
== NULL
)
5774 /* We don't have any relocs. */
5777 /* Provide any missing _save* and _rest* functions. */
5778 htab
->sfpr
->size
= 0;
5779 for (i
= 0; i
< sizeof (funcs
) / sizeof (funcs
[0]); i
++)
5780 if (!sfpr_define (info
, &funcs
[i
]))
5783 elf_link_hash_traverse (&htab
->elf
, func_desc_adjust
, info
);
5785 if (htab
->sfpr
->size
== 0)
5786 htab
->sfpr
->flags
|= SEC_EXCLUDE
;
5791 /* Adjust a symbol defined by a dynamic object and referenced by a
5792 regular object. The current definition is in some section of the
5793 dynamic object, but we're not including those sections. We have to
5794 change the definition to something the rest of the link can
5798 ppc64_elf_adjust_dynamic_symbol (struct bfd_link_info
*info
,
5799 struct elf_link_hash_entry
*h
)
5801 struct ppc_link_hash_table
*htab
;
5804 htab
= ppc_hash_table (info
);
5806 /* Deal with function syms. */
5807 if (h
->type
== STT_FUNC
5810 /* Clear procedure linkage table information for any symbol that
5811 won't need a .plt entry. */
5812 struct plt_entry
*ent
;
5813 for (ent
= h
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
5814 if (ent
->plt
.refcount
> 0)
5817 || SYMBOL_CALLS_LOCAL (info
, h
)
5818 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
5819 && h
->root
.type
== bfd_link_hash_undefweak
))
5821 h
->plt
.plist
= NULL
;
5826 h
->plt
.plist
= NULL
;
5828 /* If this is a weak symbol, and there is a real definition, the
5829 processor independent code will have arranged for us to see the
5830 real definition first, and we can just use the same value. */
5831 if (h
->u
.weakdef
!= NULL
)
5833 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
5834 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
5835 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
5836 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
5837 if (ELIMINATE_COPY_RELOCS
)
5838 h
->non_got_ref
= h
->u
.weakdef
->non_got_ref
;
5842 /* If we are creating a shared library, we must presume that the
5843 only references to the symbol are via the global offset table.
5844 For such cases we need not do anything here; the relocations will
5845 be handled correctly by relocate_section. */
5849 /* If there are no references to this symbol that do not use the
5850 GOT, we don't need to generate a copy reloc. */
5851 if (!h
->non_got_ref
)
5854 /* Don't generate a copy reloc for symbols defined in the executable. */
5855 if (!h
->def_dynamic
|| !h
->ref_regular
|| h
->def_regular
)
5858 if (ELIMINATE_COPY_RELOCS
)
5860 struct ppc_link_hash_entry
* eh
;
5861 struct ppc_dyn_relocs
*p
;
5863 eh
= (struct ppc_link_hash_entry
*) h
;
5864 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
5866 s
= p
->sec
->output_section
;
5867 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
5871 /* If we didn't find any dynamic relocs in read-only sections, then
5872 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
5880 if (h
->plt
.plist
!= NULL
)
5882 /* We should never get here, but unfortunately there are versions
5883 of gcc out there that improperly (for this ABI) put initialized
5884 function pointers, vtable refs and suchlike in read-only
5885 sections. Allow them to proceed, but warn that this might
5886 break at runtime. */
5887 (*_bfd_error_handler
)
5888 (_("copy reloc against `%s' requires lazy plt linking; "
5889 "avoid setting LD_BIND_NOW=1 or upgrade gcc"),
5890 h
->root
.root
.string
);
5893 /* This is a reference to a symbol defined by a dynamic object which
5894 is not a function. */
5898 (*_bfd_error_handler
) (_("dynamic variable `%s' is zero size"),
5899 h
->root
.root
.string
);
5903 /* We must allocate the symbol in our .dynbss section, which will
5904 become part of the .bss section of the executable. There will be
5905 an entry for this symbol in the .dynsym section. The dynamic
5906 object will contain position independent code, so all references
5907 from the dynamic object to this symbol will go through the global
5908 offset table. The dynamic linker will use the .dynsym entry to
5909 determine the address it must put in the global offset table, so
5910 both the dynamic object and the regular object will refer to the
5911 same memory location for the variable. */
5913 /* We must generate a R_PPC64_COPY reloc to tell the dynamic linker
5914 to copy the initial value out of the dynamic object and into the
5915 runtime process image. We need to remember the offset into the
5916 .rela.bss section we are going to use. */
5917 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
5919 htab
->relbss
->size
+= sizeof (Elf64_External_Rela
);
5925 return _bfd_elf_adjust_dynamic_copy (h
, s
);
5928 /* If given a function descriptor symbol, hide both the function code
5929 sym and the descriptor. */
5931 ppc64_elf_hide_symbol (struct bfd_link_info
*info
,
5932 struct elf_link_hash_entry
*h
,
5933 bfd_boolean force_local
)
5935 struct ppc_link_hash_entry
*eh
;
5936 _bfd_elf_link_hash_hide_symbol (info
, h
, force_local
);
5938 eh
= (struct ppc_link_hash_entry
*) h
;
5939 if (eh
->is_func_descriptor
)
5941 struct ppc_link_hash_entry
*fh
= eh
->oh
;
5946 struct ppc_link_hash_table
*htab
;
5949 /* We aren't supposed to use alloca in BFD because on
5950 systems which do not have alloca the version in libiberty
5951 calls xmalloc, which might cause the program to crash
5952 when it runs out of memory. This function doesn't have a
5953 return status, so there's no way to gracefully return an
5954 error. So cheat. We know that string[-1] can be safely
5955 accessed; It's either a string in an ELF string table,
5956 or allocated in an objalloc structure. */
5958 p
= eh
->elf
.root
.root
.string
- 1;
5961 htab
= ppc_hash_table (info
);
5962 fh
= (struct ppc_link_hash_entry
*)
5963 elf_link_hash_lookup (&htab
->elf
, p
, FALSE
, FALSE
, FALSE
);
5966 /* Unfortunately, if it so happens that the string we were
5967 looking for was allocated immediately before this string,
5968 then we overwrote the string terminator. That's the only
5969 reason the lookup should fail. */
5972 q
= eh
->elf
.root
.root
.string
+ strlen (eh
->elf
.root
.root
.string
);
5973 while (q
>= eh
->elf
.root
.root
.string
&& *q
== *p
)
5975 if (q
< eh
->elf
.root
.root
.string
&& *p
== '.')
5976 fh
= (struct ppc_link_hash_entry
*)
5977 elf_link_hash_lookup (&htab
->elf
, p
, FALSE
, FALSE
, FALSE
);
5986 _bfd_elf_link_hash_hide_symbol (info
, &fh
->elf
, force_local
);
5991 get_sym_h (struct elf_link_hash_entry
**hp
,
5992 Elf_Internal_Sym
**symp
,
5995 Elf_Internal_Sym
**locsymsp
,
5996 unsigned long r_symndx
,
5999 Elf_Internal_Shdr
*symtab_hdr
= &elf_tdata (ibfd
)->symtab_hdr
;
6001 if (r_symndx
>= symtab_hdr
->sh_info
)
6003 struct elf_link_hash_entry
**sym_hashes
= elf_sym_hashes (ibfd
);
6004 struct elf_link_hash_entry
*h
;
6006 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
6007 while (h
->root
.type
== bfd_link_hash_indirect
6008 || h
->root
.type
== bfd_link_hash_warning
)
6009 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
6017 if (symsecp
!= NULL
)
6019 asection
*symsec
= NULL
;
6020 if (h
->root
.type
== bfd_link_hash_defined
6021 || h
->root
.type
== bfd_link_hash_defweak
)
6022 symsec
= h
->root
.u
.def
.section
;
6026 if (tls_maskp
!= NULL
)
6028 struct ppc_link_hash_entry
*eh
;
6030 eh
= (struct ppc_link_hash_entry
*) h
;
6031 *tls_maskp
= &eh
->tls_mask
;
6036 Elf_Internal_Sym
*sym
;
6037 Elf_Internal_Sym
*locsyms
= *locsymsp
;
6039 if (locsyms
== NULL
)
6041 locsyms
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
6042 if (locsyms
== NULL
)
6043 locsyms
= bfd_elf_get_elf_syms (ibfd
, symtab_hdr
,
6044 symtab_hdr
->sh_info
,
6045 0, NULL
, NULL
, NULL
);
6046 if (locsyms
== NULL
)
6048 *locsymsp
= locsyms
;
6050 sym
= locsyms
+ r_symndx
;
6058 if (symsecp
!= NULL
)
6060 asection
*symsec
= NULL
;
6061 if ((sym
->st_shndx
!= SHN_UNDEF
6062 && sym
->st_shndx
< SHN_LORESERVE
)
6063 || sym
->st_shndx
> SHN_HIRESERVE
)
6064 symsec
= bfd_section_from_elf_index (ibfd
, sym
->st_shndx
);
6068 if (tls_maskp
!= NULL
)
6070 struct got_entry
**lgot_ents
;
6074 lgot_ents
= elf_local_got_ents (ibfd
);
6075 if (lgot_ents
!= NULL
)
6077 char *lgot_masks
= (char *) (lgot_ents
+ symtab_hdr
->sh_info
);
6078 tls_mask
= &lgot_masks
[r_symndx
];
6080 *tls_maskp
= tls_mask
;
6086 /* Returns TLS_MASKP for the given REL symbol. Function return is 0 on
6087 error, 2 on a toc GD type suitable for optimization, 3 on a toc LD
6088 type suitable for optimization, and 1 otherwise. */
6091 get_tls_mask (char **tls_maskp
, unsigned long *toc_symndx
,
6092 Elf_Internal_Sym
**locsymsp
,
6093 const Elf_Internal_Rela
*rel
, bfd
*ibfd
)
6095 unsigned long r_symndx
;
6097 struct elf_link_hash_entry
*h
;
6098 Elf_Internal_Sym
*sym
;
6102 r_symndx
= ELF64_R_SYM (rel
->r_info
);
6103 if (!get_sym_h (&h
, &sym
, &sec
, tls_maskp
, locsymsp
, r_symndx
, ibfd
))
6106 if ((*tls_maskp
!= NULL
&& **tls_maskp
!= 0)
6108 || ppc64_elf_section_data (sec
)->sec_type
!= sec_toc
)
6111 /* Look inside a TOC section too. */
6114 BFD_ASSERT (h
->root
.type
== bfd_link_hash_defined
);
6115 off
= h
->root
.u
.def
.value
;
6118 off
= sym
->st_value
;
6119 off
+= rel
->r_addend
;
6120 BFD_ASSERT (off
% 8 == 0);
6121 r_symndx
= ppc64_elf_section_data (sec
)->u
.t_symndx
[off
/ 8];
6122 next_r
= ppc64_elf_section_data (sec
)->u
.t_symndx
[off
/ 8 + 1];
6123 if (!get_sym_h (&h
, &sym
, &sec
, tls_maskp
, locsymsp
, r_symndx
, ibfd
))
6125 if (toc_symndx
!= NULL
)
6126 *toc_symndx
= r_symndx
;
6128 || ((h
->root
.type
== bfd_link_hash_defined
6129 || h
->root
.type
== bfd_link_hash_defweak
)
6130 && !h
->def_dynamic
))
6131 && (next_r
== -1 || next_r
== -2))
6136 /* Adjust all global syms defined in opd sections. In gcc generated
6137 code for the old ABI, these will already have been done. */
6140 adjust_opd_syms (struct elf_link_hash_entry
*h
, void *inf ATTRIBUTE_UNUSED
)
6142 struct ppc_link_hash_entry
*eh
;
6146 if (h
->root
.type
== bfd_link_hash_indirect
)
6149 if (h
->root
.type
== bfd_link_hash_warning
)
6150 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
6152 if (h
->root
.type
!= bfd_link_hash_defined
6153 && h
->root
.type
!= bfd_link_hash_defweak
)
6156 eh
= (struct ppc_link_hash_entry
*) h
;
6157 if (eh
->adjust_done
)
6160 sym_sec
= eh
->elf
.root
.u
.def
.section
;
6161 opd_adjust
= get_opd_info (sym_sec
);
6162 if (opd_adjust
!= NULL
)
6164 long adjust
= opd_adjust
[eh
->elf
.root
.u
.def
.value
/ 8];
6167 /* This entry has been deleted. */
6168 asection
*dsec
= ppc64_elf_tdata (sym_sec
->owner
)->deleted_section
;
6171 for (dsec
= sym_sec
->owner
->sections
; dsec
; dsec
= dsec
->next
)
6172 if (elf_discarded_section (dsec
))
6174 ppc64_elf_tdata (sym_sec
->owner
)->deleted_section
= dsec
;
6178 eh
->elf
.root
.u
.def
.value
= 0;
6179 eh
->elf
.root
.u
.def
.section
= dsec
;
6182 eh
->elf
.root
.u
.def
.value
+= adjust
;
6183 eh
->adjust_done
= 1;
6188 /* Handles decrementing dynamic reloc counts for the reloc specified by
6189 R_INFO in section SEC. If LOCAL_SYMS is NULL, then H and SYM_SEC
6190 have already been determined. */
6193 dec_dynrel_count (bfd_vma r_info
,
6195 struct bfd_link_info
*info
,
6196 Elf_Internal_Sym
**local_syms
,
6197 struct elf_link_hash_entry
*h
,
6200 enum elf_ppc64_reloc_type r_type
;
6201 struct ppc_dyn_relocs
*p
;
6202 struct ppc_dyn_relocs
**pp
;
6204 /* Can this reloc be dynamic? This switch, and later tests here
6205 should be kept in sync with the code in check_relocs. */
6206 r_type
= ELF64_R_TYPE (r_info
);
6212 case R_PPC64_TPREL16
:
6213 case R_PPC64_TPREL16_LO
:
6214 case R_PPC64_TPREL16_HI
:
6215 case R_PPC64_TPREL16_HA
:
6216 case R_PPC64_TPREL16_DS
:
6217 case R_PPC64_TPREL16_LO_DS
:
6218 case R_PPC64_TPREL16_HIGHER
:
6219 case R_PPC64_TPREL16_HIGHERA
:
6220 case R_PPC64_TPREL16_HIGHEST
:
6221 case R_PPC64_TPREL16_HIGHESTA
:
6225 case R_PPC64_TPREL64
:
6226 case R_PPC64_DTPMOD64
:
6227 case R_PPC64_DTPREL64
:
6228 case R_PPC64_ADDR64
:
6232 case R_PPC64_ADDR14
:
6233 case R_PPC64_ADDR14_BRNTAKEN
:
6234 case R_PPC64_ADDR14_BRTAKEN
:
6235 case R_PPC64_ADDR16
:
6236 case R_PPC64_ADDR16_DS
:
6237 case R_PPC64_ADDR16_HA
:
6238 case R_PPC64_ADDR16_HI
:
6239 case R_PPC64_ADDR16_HIGHER
:
6240 case R_PPC64_ADDR16_HIGHERA
:
6241 case R_PPC64_ADDR16_HIGHEST
:
6242 case R_PPC64_ADDR16_HIGHESTA
:
6243 case R_PPC64_ADDR16_LO
:
6244 case R_PPC64_ADDR16_LO_DS
:
6245 case R_PPC64_ADDR24
:
6246 case R_PPC64_ADDR32
:
6247 case R_PPC64_UADDR16
:
6248 case R_PPC64_UADDR32
:
6249 case R_PPC64_UADDR64
:
6254 if (local_syms
!= NULL
)
6256 unsigned long r_symndx
;
6257 Elf_Internal_Sym
*sym
;
6258 bfd
*ibfd
= sec
->owner
;
6260 r_symndx
= ELF64_R_SYM (r_info
);
6261 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, local_syms
, r_symndx
, ibfd
))
6266 && (MUST_BE_DYN_RELOC (r_type
)
6269 || h
->root
.type
== bfd_link_hash_defweak
6270 || !h
->def_regular
))))
6271 || (ELIMINATE_COPY_RELOCS
6274 && (h
->root
.type
== bfd_link_hash_defweak
6275 || !h
->def_regular
)))
6281 pp
= &((struct ppc_link_hash_entry
*) h
)->dyn_relocs
;
6284 if (sym_sec
!= NULL
)
6286 void *vpp
= &elf_section_data (sym_sec
)->local_dynrel
;
6287 pp
= (struct ppc_dyn_relocs
**) vpp
;
6291 void *vpp
= &elf_section_data (sec
)->local_dynrel
;
6292 pp
= (struct ppc_dyn_relocs
**) vpp
;
6295 /* elf_gc_sweep may have already removed all dyn relocs associated
6296 with local syms for a given section. Don't report a dynreloc
6302 while ((p
= *pp
) != NULL
)
6306 if (!MUST_BE_DYN_RELOC (r_type
))
6316 (*_bfd_error_handler
) (_("dynreloc miscount for %B, section %A"),
6318 bfd_set_error (bfd_error_bad_value
);
6322 /* Remove unused Official Procedure Descriptor entries. Currently we
6323 only remove those associated with functions in discarded link-once
6324 sections, or weakly defined functions that have been overridden. It
6325 would be possible to remove many more entries for statically linked
6329 ppc64_elf_edit_opd (bfd
*obfd
, struct bfd_link_info
*info
,
6330 bfd_boolean no_opd_opt
,
6331 bfd_boolean non_overlapping
)
6334 bfd_boolean some_edited
= FALSE
;
6335 asection
*need_pad
= NULL
;
6337 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
6340 Elf_Internal_Rela
*relstart
, *rel
, *relend
;
6341 Elf_Internal_Shdr
*symtab_hdr
;
6342 Elf_Internal_Sym
*local_syms
;
6343 struct elf_link_hash_entry
**sym_hashes
;
6347 bfd_boolean need_edit
, add_aux_fields
;
6348 bfd_size_type cnt_16b
= 0;
6350 sec
= bfd_get_section_by_name (ibfd
, ".opd");
6351 if (sec
== NULL
|| sec
->size
== 0)
6354 amt
= sec
->size
* sizeof (long) / 8;
6355 opd_adjust
= get_opd_info (sec
);
6356 if (opd_adjust
== NULL
)
6358 /* check_relocs hasn't been called. Must be a ld -r link
6359 or --just-symbols object. */
6360 opd_adjust
= bfd_alloc (obfd
, amt
);
6361 if (opd_adjust
== NULL
)
6363 ppc64_elf_section_data (sec
)->u
.opd_adjust
= opd_adjust
;
6364 BFD_ASSERT (ppc64_elf_section_data (sec
)->sec_type
== sec_normal
);
6365 ppc64_elf_section_data (sec
)->sec_type
= sec_opd
;
6367 memset (opd_adjust
, 0, amt
);
6372 if (sec
->sec_info_type
== ELF_INFO_TYPE_JUST_SYMS
)
6375 if (sec
->output_section
== bfd_abs_section_ptr
)
6378 /* Look through the section relocs. */
6379 if ((sec
->flags
& SEC_RELOC
) == 0 || sec
->reloc_count
== 0)
6383 symtab_hdr
= &elf_tdata (ibfd
)->symtab_hdr
;
6384 sym_hashes
= elf_sym_hashes (ibfd
);
6386 /* Read the relocations. */
6387 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
6389 if (relstart
== NULL
)
6392 /* First run through the relocs to check they are sane, and to
6393 determine whether we need to edit this opd section. */
6397 relend
= relstart
+ sec
->reloc_count
;
6398 for (rel
= relstart
; rel
< relend
; )
6400 enum elf_ppc64_reloc_type r_type
;
6401 unsigned long r_symndx
;
6403 struct elf_link_hash_entry
*h
;
6404 Elf_Internal_Sym
*sym
;
6406 /* .opd contains a regular array of 16 or 24 byte entries. We're
6407 only interested in the reloc pointing to a function entry
6409 if (rel
->r_offset
!= offset
6410 || rel
+ 1 >= relend
6411 || (rel
+ 1)->r_offset
!= offset
+ 8)
6413 /* If someone messes with .opd alignment then after a
6414 "ld -r" we might have padding in the middle of .opd.
6415 Also, there's nothing to prevent someone putting
6416 something silly in .opd with the assembler. No .opd
6417 optimization for them! */
6419 (*_bfd_error_handler
)
6420 (_("%B: .opd is not a regular array of opd entries"), ibfd
);
6425 if ((r_type
= ELF64_R_TYPE (rel
->r_info
)) != R_PPC64_ADDR64
6426 || (r_type
= ELF64_R_TYPE ((rel
+ 1)->r_info
)) != R_PPC64_TOC
)
6428 (*_bfd_error_handler
)
6429 (_("%B: unexpected reloc type %u in .opd section"),
6435 r_symndx
= ELF64_R_SYM (rel
->r_info
);
6436 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
6440 if (sym_sec
== NULL
|| sym_sec
->owner
== NULL
)
6442 const char *sym_name
;
6444 sym_name
= h
->root
.root
.string
;
6446 sym_name
= bfd_elf_sym_name (ibfd
, symtab_hdr
, sym
,
6449 (*_bfd_error_handler
)
6450 (_("%B: undefined sym `%s' in .opd section"),
6456 /* opd entries are always for functions defined in the
6457 current input bfd. If the symbol isn't defined in the
6458 input bfd, then we won't be using the function in this
6459 bfd; It must be defined in a linkonce section in another
6460 bfd, or is weak. It's also possible that we are
6461 discarding the function due to a linker script /DISCARD/,
6462 which we test for via the output_section. */
6463 if (sym_sec
->owner
!= ibfd
6464 || sym_sec
->output_section
== bfd_abs_section_ptr
)
6469 || (rel
+ 1 == relend
&& rel
->r_offset
== offset
+ 16))
6471 if (sec
->size
== offset
+ 24)
6476 if (rel
== relend
&& sec
->size
== offset
+ 16)
6484 if (rel
->r_offset
== offset
+ 24)
6486 else if (rel
->r_offset
!= offset
+ 16)
6488 else if (rel
+ 1 < relend
6489 && ELF64_R_TYPE (rel
[0].r_info
) == R_PPC64_ADDR64
6490 && ELF64_R_TYPE (rel
[1].r_info
) == R_PPC64_TOC
)
6495 else if (rel
+ 2 < relend
6496 && ELF64_R_TYPE (rel
[1].r_info
) == R_PPC64_ADDR64
6497 && ELF64_R_TYPE (rel
[2].r_info
) == R_PPC64_TOC
)
6506 add_aux_fields
= non_overlapping
&& cnt_16b
> 0;
6508 if (need_edit
|| add_aux_fields
)
6510 Elf_Internal_Rela
*write_rel
;
6511 bfd_byte
*rptr
, *wptr
;
6512 bfd_byte
*new_contents
= NULL
;
6516 /* This seems a waste of time as input .opd sections are all
6517 zeros as generated by gcc, but I suppose there's no reason
6518 this will always be so. We might start putting something in
6519 the third word of .opd entries. */
6520 if ((sec
->flags
& SEC_IN_MEMORY
) == 0)
6523 if (!bfd_malloc_and_get_section (ibfd
, sec
, &loc
))
6528 if (local_syms
!= NULL
6529 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
6531 if (elf_section_data (sec
)->relocs
!= relstart
)
6535 sec
->contents
= loc
;
6536 sec
->flags
|= (SEC_IN_MEMORY
| SEC_HAS_CONTENTS
);
6539 elf_section_data (sec
)->relocs
= relstart
;
6541 new_contents
= sec
->contents
;
6544 new_contents
= bfd_malloc (sec
->size
+ cnt_16b
* 8);
6545 if (new_contents
== NULL
)
6549 wptr
= new_contents
;
6550 rptr
= sec
->contents
;
6552 write_rel
= relstart
;
6556 for (rel
= relstart
; rel
< relend
; rel
++)
6558 unsigned long r_symndx
;
6560 struct elf_link_hash_entry
*h
;
6561 Elf_Internal_Sym
*sym
;
6563 r_symndx
= ELF64_R_SYM (rel
->r_info
);
6564 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
6568 if (rel
->r_offset
== offset
)
6570 struct ppc_link_hash_entry
*fdh
= NULL
;
6572 /* See if the .opd entry is full 24 byte or
6573 16 byte (with fd_aux entry overlapped with next
6576 if ((rel
+ 2 == relend
&& sec
->size
== offset
+ 16)
6577 || (rel
+ 3 < relend
6578 && rel
[2].r_offset
== offset
+ 16
6579 && rel
[3].r_offset
== offset
+ 24
6580 && ELF64_R_TYPE (rel
[2].r_info
) == R_PPC64_ADDR64
6581 && ELF64_R_TYPE (rel
[3].r_info
) == R_PPC64_TOC
))
6585 && h
->root
.root
.string
[0] == '.')
6587 fdh
= get_fdh ((struct ppc_link_hash_entry
*) h
,
6588 ppc_hash_table (info
));
6590 && fdh
->elf
.root
.type
!= bfd_link_hash_defined
6591 && fdh
->elf
.root
.type
!= bfd_link_hash_defweak
)
6595 skip
= (sym_sec
->owner
!= ibfd
6596 || sym_sec
->output_section
== bfd_abs_section_ptr
);
6599 if (fdh
!= NULL
&& sym_sec
->owner
== ibfd
)
6601 /* Arrange for the function descriptor sym
6603 fdh
->elf
.root
.u
.def
.value
= 0;
6604 fdh
->elf
.root
.u
.def
.section
= sym_sec
;
6606 opd_adjust
[rel
->r_offset
/ 8] = -1;
6610 /* We'll be keeping this opd entry. */
6614 /* Redefine the function descriptor symbol to
6615 this location in the opd section. It is
6616 necessary to update the value here rather
6617 than using an array of adjustments as we do
6618 for local symbols, because various places
6619 in the generic ELF code use the value
6620 stored in u.def.value. */
6621 fdh
->elf
.root
.u
.def
.value
= wptr
- new_contents
;
6622 fdh
->adjust_done
= 1;
6625 /* Local syms are a bit tricky. We could
6626 tweak them as they can be cached, but
6627 we'd need to look through the local syms
6628 for the function descriptor sym which we
6629 don't have at the moment. So keep an
6630 array of adjustments. */
6631 opd_adjust
[rel
->r_offset
/ 8]
6632 = (wptr
- new_contents
) - (rptr
- sec
->contents
);
6635 memcpy (wptr
, rptr
, opd_ent_size
);
6636 wptr
+= opd_ent_size
;
6637 if (add_aux_fields
&& opd_ent_size
== 16)
6639 memset (wptr
, '\0', 8);
6643 rptr
+= opd_ent_size
;
6644 offset
+= opd_ent_size
;
6650 && !info
->relocatable
6651 && !dec_dynrel_count (rel
->r_info
, sec
, info
,
6657 /* We need to adjust any reloc offsets to point to the
6658 new opd entries. While we're at it, we may as well
6659 remove redundant relocs. */
6660 rel
->r_offset
+= opd_adjust
[(offset
- opd_ent_size
) / 8];
6661 if (write_rel
!= rel
)
6662 memcpy (write_rel
, rel
, sizeof (*rel
));
6667 sec
->size
= wptr
- new_contents
;
6668 sec
->reloc_count
= write_rel
- relstart
;
6671 free (sec
->contents
);
6672 sec
->contents
= new_contents
;
6675 /* Fudge the header size too, as this is used later in
6676 elf_bfd_final_link if we are emitting relocs. */
6677 elf_section_data (sec
)->rel_hdr
.sh_size
6678 = sec
->reloc_count
* elf_section_data (sec
)->rel_hdr
.sh_entsize
;
6679 BFD_ASSERT (elf_section_data (sec
)->rel_hdr2
== NULL
);
6682 else if (elf_section_data (sec
)->relocs
!= relstart
)
6685 if (local_syms
!= NULL
6686 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
6688 if (!info
->keep_memory
)
6691 symtab_hdr
->contents
= (unsigned char *) local_syms
;
6696 elf_link_hash_traverse (elf_hash_table (info
), adjust_opd_syms
, NULL
);
6698 /* If we are doing a final link and the last .opd entry is just 16 byte
6699 long, add a 8 byte padding after it. */
6700 if (need_pad
!= NULL
&& !info
->relocatable
)
6704 if ((need_pad
->flags
& SEC_IN_MEMORY
) == 0)
6706 BFD_ASSERT (need_pad
->size
> 0);
6708 p
= bfd_malloc (need_pad
->size
+ 8);
6712 if (! bfd_get_section_contents (need_pad
->owner
, need_pad
,
6713 p
, 0, need_pad
->size
))
6716 need_pad
->contents
= p
;
6717 need_pad
->flags
|= (SEC_IN_MEMORY
| SEC_HAS_CONTENTS
);
6721 p
= bfd_realloc (need_pad
->contents
, need_pad
->size
+ 8);
6725 need_pad
->contents
= p
;
6728 memset (need_pad
->contents
+ need_pad
->size
, 0, 8);
6729 need_pad
->size
+= 8;
6735 /* Set htab->tls_get_addr and call the generic ELF tls_setup function. */
6738 ppc64_elf_tls_setup (bfd
*obfd
, struct bfd_link_info
*info
)
6740 struct ppc_link_hash_table
*htab
;
6742 htab
= ppc_hash_table (info
);
6743 if (htab
->tls_get_addr
!= NULL
)
6745 struct ppc_link_hash_entry
*h
= htab
->tls_get_addr
;
6747 while (h
->elf
.root
.type
== bfd_link_hash_indirect
6748 || h
->elf
.root
.type
== bfd_link_hash_warning
)
6749 h
= (struct ppc_link_hash_entry
*) h
->elf
.root
.u
.i
.link
;
6751 htab
->tls_get_addr
= h
;
6753 if (htab
->tls_get_addr_fd
== NULL
6755 && h
->oh
->is_func_descriptor
6756 && (h
->oh
->elf
.root
.type
== bfd_link_hash_defined
6757 || h
->oh
->elf
.root
.type
== bfd_link_hash_defweak
))
6758 htab
->tls_get_addr_fd
= h
->oh
;
6761 if (htab
->tls_get_addr_fd
!= NULL
)
6763 struct ppc_link_hash_entry
*h
= htab
->tls_get_addr_fd
;
6765 while (h
->elf
.root
.type
== bfd_link_hash_indirect
6766 || h
->elf
.root
.type
== bfd_link_hash_warning
)
6767 h
= (struct ppc_link_hash_entry
*) h
->elf
.root
.u
.i
.link
;
6769 htab
->tls_get_addr_fd
= h
;
6772 return _bfd_elf_tls_setup (obfd
, info
);
6775 /* Run through all the TLS relocs looking for optimization
6776 opportunities. The linker has been hacked (see ppc64elf.em) to do
6777 a preliminary section layout so that we know the TLS segment
6778 offsets. We can't optimize earlier because some optimizations need
6779 to know the tp offset, and we need to optimize before allocating
6780 dynamic relocations. */
6783 ppc64_elf_tls_optimize (bfd
*obfd ATTRIBUTE_UNUSED
, struct bfd_link_info
*info
)
6787 struct ppc_link_hash_table
*htab
;
6789 if (info
->relocatable
|| info
->shared
)
6792 htab
= ppc_hash_table (info
);
6793 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
6795 Elf_Internal_Sym
*locsyms
= NULL
;
6796 asection
*toc
= bfd_get_section_by_name (ibfd
, ".toc");
6797 unsigned char *toc_ref
= NULL
;
6799 /* Look at all the sections for this file, with TOC last. */
6800 for (sec
= (ibfd
->sections
== toc
&& toc
&& toc
->next
? toc
->next
6803 sec
= (sec
== toc
? NULL
6804 : sec
->next
== NULL
? toc
6805 : sec
->next
== toc
&& toc
->next
? toc
->next
6807 if (sec
->has_tls_reloc
&& !bfd_is_abs_section (sec
->output_section
))
6809 Elf_Internal_Rela
*relstart
, *rel
, *relend
;
6810 int expecting_tls_get_addr
;
6811 long toc_ref_index
= 0;
6813 /* Read the relocations. */
6814 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
6816 if (relstart
== NULL
)
6819 expecting_tls_get_addr
= 0;
6820 relend
= relstart
+ sec
->reloc_count
;
6821 for (rel
= relstart
; rel
< relend
; rel
++)
6823 enum elf_ppc64_reloc_type r_type
;
6824 unsigned long r_symndx
;
6825 struct elf_link_hash_entry
*h
;
6826 Elf_Internal_Sym
*sym
;
6829 char tls_set
, tls_clear
, tls_type
= 0;
6831 bfd_boolean ok_tprel
, is_local
;
6833 r_symndx
= ELF64_R_SYM (rel
->r_info
);
6834 if (!get_sym_h (&h
, &sym
, &sym_sec
, &tls_mask
, &locsyms
,
6838 if (elf_section_data (sec
)->relocs
!= relstart
)
6840 if (toc_ref
!= NULL
)
6843 && (elf_tdata (ibfd
)->symtab_hdr
.contents
6844 != (unsigned char *) locsyms
))
6851 if (h
->root
.type
!= bfd_link_hash_defined
6852 && h
->root
.type
!= bfd_link_hash_defweak
)
6854 value
= h
->root
.u
.def
.value
;
6857 /* Symbols referenced by TLS relocs must be of type
6858 STT_TLS. So no need for .opd local sym adjust. */
6859 value
= sym
->st_value
;
6867 value
+= sym_sec
->output_offset
;
6868 value
+= sym_sec
->output_section
->vma
;
6869 value
-= htab
->elf
.tls_sec
->vma
;
6870 ok_tprel
= (value
+ TP_OFFSET
+ ((bfd_vma
) 1 << 31)
6871 < (bfd_vma
) 1 << 32);
6874 r_type
= ELF64_R_TYPE (rel
->r_info
);
6877 case R_PPC64_GOT_TLSLD16
:
6878 case R_PPC64_GOT_TLSLD16_LO
:
6879 case R_PPC64_GOT_TLSLD16_HI
:
6880 case R_PPC64_GOT_TLSLD16_HA
:
6881 /* These relocs should never be against a symbol
6882 defined in a shared lib. Leave them alone if
6883 that turns out to be the case. */
6884 ppc64_tlsld_got (ibfd
)->refcount
-= 1;
6891 tls_type
= TLS_TLS
| TLS_LD
;
6892 expecting_tls_get_addr
= 1;
6895 case R_PPC64_GOT_TLSGD16
:
6896 case R_PPC64_GOT_TLSGD16_LO
:
6897 case R_PPC64_GOT_TLSGD16_HI
:
6898 case R_PPC64_GOT_TLSGD16_HA
:
6904 tls_set
= TLS_TLS
| TLS_TPRELGD
;
6906 tls_type
= TLS_TLS
| TLS_GD
;
6907 expecting_tls_get_addr
= 1;
6910 case R_PPC64_GOT_TPREL16_DS
:
6911 case R_PPC64_GOT_TPREL16_LO_DS
:
6912 case R_PPC64_GOT_TPREL16_HI
:
6913 case R_PPC64_GOT_TPREL16_HA
:
6914 expecting_tls_get_addr
= 0;
6919 tls_clear
= TLS_TPREL
;
6920 tls_type
= TLS_TLS
| TLS_TPREL
;
6927 case R_PPC64_REL14_BRTAKEN
:
6928 case R_PPC64_REL14_BRNTAKEN
:
6931 && (h
== &htab
->tls_get_addr
->elf
6932 || h
== &htab
->tls_get_addr_fd
->elf
))
6934 if (!expecting_tls_get_addr
6936 && ((ELF64_R_TYPE (rel
[-1].r_info
)
6938 || (ELF64_R_TYPE (rel
[-1].r_info
)
6939 == R_PPC64_TOC16_LO
)))
6941 /* Check for toc tls entries. */
6945 retval
= get_tls_mask (&toc_tls
, NULL
, &locsyms
,
6949 if (retval
> 1 && toc_tls
!= NULL
)
6951 expecting_tls_get_addr
= 1;
6952 if (toc_ref
!= NULL
)
6953 toc_ref
[toc_ref_index
] = 1;
6957 if (expecting_tls_get_addr
)
6959 struct plt_entry
*ent
;
6960 for (ent
= h
->plt
.plist
; ent
; ent
= ent
->next
)
6961 if (ent
->addend
== 0)
6963 if (ent
->plt
.refcount
> 0)
6964 ent
->plt
.refcount
-= 1;
6969 expecting_tls_get_addr
= 0;
6973 case R_PPC64_TOC16_LO
:
6975 expecting_tls_get_addr
= 0;
6976 if (sym_sec
== toc
&& toc
!= NULL
)
6978 /* Mark this toc entry as referenced by a TLS
6979 code sequence. We can do that now in the
6980 case of R_PPC64_TLS, and after checking for
6981 tls_get_addr for the TOC16 relocs. */
6982 if (toc_ref
== NULL
)
6984 toc_ref
= bfd_zmalloc (toc
->size
/ 8);
6985 if (toc_ref
== NULL
)
6989 value
= h
->root
.u
.def
.value
;
6991 value
= sym
->st_value
;
6992 value
+= rel
->r_addend
;
6993 BFD_ASSERT (value
< toc
->size
&& value
% 8 == 0);
6994 toc_ref_index
= value
/ 8;
6995 if (r_type
== R_PPC64_TLS
)
6996 toc_ref
[toc_ref_index
] = 1;
7000 case R_PPC64_TPREL64
:
7001 expecting_tls_get_addr
= 0;
7004 || !toc_ref
[rel
->r_offset
/ 8])
7009 tls_set
= TLS_EXPLICIT
;
7010 tls_clear
= TLS_TPREL
;
7016 case R_PPC64_DTPMOD64
:
7017 expecting_tls_get_addr
= 0;
7020 || !toc_ref
[rel
->r_offset
/ 8])
7022 if (rel
+ 1 < relend
7024 == ELF64_R_INFO (r_symndx
, R_PPC64_DTPREL64
))
7025 && rel
[1].r_offset
== rel
->r_offset
+ 8)
7029 tls_set
= TLS_EXPLICIT
| TLS_GD
;
7032 tls_set
= TLS_EXPLICIT
| TLS_GD
| TLS_TPRELGD
;
7041 tls_set
= TLS_EXPLICIT
;
7047 expecting_tls_get_addr
= 0;
7051 if ((tls_set
& TLS_EXPLICIT
) == 0)
7053 struct got_entry
*ent
;
7055 /* Adjust got entry for this reloc. */
7059 ent
= elf_local_got_ents (ibfd
)[r_symndx
];
7061 for (; ent
!= NULL
; ent
= ent
->next
)
7062 if (ent
->addend
== rel
->r_addend
7063 && ent
->owner
== ibfd
7064 && ent
->tls_type
== tls_type
)
7071 /* We managed to get rid of a got entry. */
7072 if (ent
->got
.refcount
> 0)
7073 ent
->got
.refcount
-= 1;
7078 /* If we got rid of a DTPMOD/DTPREL reloc pair then
7079 we'll lose one or two dyn relocs. */
7080 if (!dec_dynrel_count (rel
->r_info
, sec
, info
,
7084 if (tls_set
== (TLS_EXPLICIT
| TLS_GD
))
7086 if (!dec_dynrel_count ((rel
+ 1)->r_info
, sec
, info
,
7092 *tls_mask
|= tls_set
;
7093 *tls_mask
&= ~tls_clear
;
7096 if (elf_section_data (sec
)->relocs
!= relstart
)
7100 if (toc_ref
!= NULL
)
7104 && (elf_tdata (ibfd
)->symtab_hdr
.contents
7105 != (unsigned char *) locsyms
))
7107 if (!info
->keep_memory
)
7110 elf_tdata (ibfd
)->symtab_hdr
.contents
= (unsigned char *) locsyms
;
7116 /* Called via elf_link_hash_traverse from ppc64_elf_edit_toc to adjust
7117 the values of any global symbols in a toc section that has been
7118 edited. Globals in toc sections should be a rarity, so this function
7119 sets a flag if any are found in toc sections other than the one just
7120 edited, so that futher hash table traversals can be avoided. */
7122 struct adjust_toc_info
7125 unsigned long *skip
;
7126 bfd_boolean global_toc_syms
;
7130 adjust_toc_syms (struct elf_link_hash_entry
*h
, void *inf
)
7132 struct ppc_link_hash_entry
*eh
;
7133 struct adjust_toc_info
*toc_inf
= (struct adjust_toc_info
*) inf
;
7135 if (h
->root
.type
== bfd_link_hash_indirect
)
7138 if (h
->root
.type
== bfd_link_hash_warning
)
7139 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
7141 if (h
->root
.type
!= bfd_link_hash_defined
7142 && h
->root
.type
!= bfd_link_hash_defweak
)
7145 eh
= (struct ppc_link_hash_entry
*) h
;
7146 if (eh
->adjust_done
)
7149 if (eh
->elf
.root
.u
.def
.section
== toc_inf
->toc
)
7151 unsigned long skip
= toc_inf
->skip
[eh
->elf
.root
.u
.def
.value
>> 3];
7152 if (skip
!= (unsigned long) -1)
7153 eh
->elf
.root
.u
.def
.value
-= skip
;
7156 (*_bfd_error_handler
)
7157 (_("%s defined in removed toc entry"), eh
->elf
.root
.root
.string
);
7158 eh
->elf
.root
.u
.def
.section
= &bfd_abs_section
;
7159 eh
->elf
.root
.u
.def
.value
= 0;
7161 eh
->adjust_done
= 1;
7163 else if (strcmp (eh
->elf
.root
.u
.def
.section
->name
, ".toc") == 0)
7164 toc_inf
->global_toc_syms
= TRUE
;
7169 /* Examine all relocs referencing .toc sections in order to remove
7170 unused .toc entries. */
7173 ppc64_elf_edit_toc (bfd
*obfd ATTRIBUTE_UNUSED
, struct bfd_link_info
*info
)
7176 struct adjust_toc_info toc_inf
;
7178 toc_inf
.global_toc_syms
= TRUE
;
7179 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
7181 asection
*toc
, *sec
;
7182 Elf_Internal_Shdr
*symtab_hdr
;
7183 Elf_Internal_Sym
*local_syms
;
7184 struct elf_link_hash_entry
**sym_hashes
;
7185 Elf_Internal_Rela
*relstart
, *rel
;
7186 unsigned long *skip
, *drop
;
7187 unsigned char *used
;
7188 unsigned char *keep
, last
, some_unused
;
7190 toc
= bfd_get_section_by_name (ibfd
, ".toc");
7193 || toc
->sec_info_type
== ELF_INFO_TYPE_JUST_SYMS
7194 || elf_discarded_section (toc
))
7198 symtab_hdr
= &elf_tdata (ibfd
)->symtab_hdr
;
7199 sym_hashes
= elf_sym_hashes (ibfd
);
7201 /* Look at sections dropped from the final link. */
7204 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
7206 if (sec
->reloc_count
== 0
7207 || !elf_discarded_section (sec
)
7208 || get_opd_info (sec
)
7209 || (sec
->flags
& SEC_ALLOC
) == 0
7210 || (sec
->flags
& SEC_DEBUGGING
) != 0)
7213 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
, FALSE
);
7214 if (relstart
== NULL
)
7217 /* Run through the relocs to see which toc entries might be
7219 for (rel
= relstart
; rel
< relstart
+ sec
->reloc_count
; ++rel
)
7221 enum elf_ppc64_reloc_type r_type
;
7222 unsigned long r_symndx
;
7224 struct elf_link_hash_entry
*h
;
7225 Elf_Internal_Sym
*sym
;
7228 r_type
= ELF64_R_TYPE (rel
->r_info
);
7235 case R_PPC64_TOC16_LO
:
7236 case R_PPC64_TOC16_HI
:
7237 case R_PPC64_TOC16_HA
:
7238 case R_PPC64_TOC16_DS
:
7239 case R_PPC64_TOC16_LO_DS
:
7243 r_symndx
= ELF64_R_SYM (rel
->r_info
);
7244 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
7252 val
= h
->root
.u
.def
.value
;
7254 val
= sym
->st_value
;
7255 val
+= rel
->r_addend
;
7257 if (val
>= toc
->size
)
7260 /* Anything in the toc ought to be aligned to 8 bytes.
7261 If not, don't mark as unused. */
7267 skip
= bfd_zmalloc (sizeof (*skip
) * (toc
->size
+ 7) / 8);
7275 if (elf_section_data (sec
)->relocs
!= relstart
)
7282 used
= bfd_zmalloc (sizeof (*used
) * (toc
->size
+ 7) / 8);
7286 if (local_syms
!= NULL
7287 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
7291 && elf_section_data (sec
)->relocs
!= relstart
)
7298 /* Now check all kept sections that might reference the toc.
7299 Check the toc itself last. */
7300 for (sec
= (ibfd
->sections
== toc
&& toc
->next
? toc
->next
7303 sec
= (sec
== toc
? NULL
7304 : sec
->next
== NULL
? toc
7305 : sec
->next
== toc
&& toc
->next
? toc
->next
7310 if (sec
->reloc_count
== 0
7311 || elf_discarded_section (sec
)
7312 || get_opd_info (sec
)
7313 || (sec
->flags
& SEC_ALLOC
) == 0
7314 || (sec
->flags
& SEC_DEBUGGING
) != 0)
7317 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
, TRUE
);
7318 if (relstart
== NULL
)
7321 /* Mark toc entries referenced as used. */
7324 for (rel
= relstart
; rel
< relstart
+ sec
->reloc_count
; ++rel
)
7326 enum elf_ppc64_reloc_type r_type
;
7327 unsigned long r_symndx
;
7329 struct elf_link_hash_entry
*h
;
7330 Elf_Internal_Sym
*sym
;
7333 r_type
= ELF64_R_TYPE (rel
->r_info
);
7337 case R_PPC64_TOC16_LO
:
7338 case R_PPC64_TOC16_HI
:
7339 case R_PPC64_TOC16_HA
:
7340 case R_PPC64_TOC16_DS
:
7341 case R_PPC64_TOC16_LO_DS
:
7342 /* In case we're taking addresses of toc entries. */
7343 case R_PPC64_ADDR64
:
7350 r_symndx
= ELF64_R_SYM (rel
->r_info
);
7351 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
7362 val
= h
->root
.u
.def
.value
;
7364 val
= sym
->st_value
;
7365 val
+= rel
->r_addend
;
7367 if (val
>= toc
->size
)
7370 /* For the toc section, we only mark as used if
7371 this entry itself isn't unused. */
7374 && (used
[rel
->r_offset
>> 3]
7375 || !skip
[rel
->r_offset
>> 3]))
7376 /* Do all the relocs again, to catch reference
7385 /* Merge the used and skip arrays. Assume that TOC
7386 doublewords not appearing as either used or unused belong
7387 to to an entry more than one doubleword in size. */
7388 for (drop
= skip
, keep
= used
, last
= 0, some_unused
= 0;
7389 drop
< skip
+ (toc
->size
+ 7) / 8;
7410 bfd_byte
*contents
, *src
;
7413 /* Shuffle the toc contents, and at the same time convert the
7414 skip array from booleans into offsets. */
7415 if (!bfd_malloc_and_get_section (ibfd
, toc
, &contents
))
7418 elf_section_data (toc
)->this_hdr
.contents
= contents
;
7420 for (src
= contents
, off
= 0, drop
= skip
;
7421 src
< contents
+ toc
->size
;
7426 *drop
= (unsigned long) -1;
7432 memcpy (src
- off
, src
, 8);
7435 toc
->rawsize
= toc
->size
;
7436 toc
->size
= src
- contents
- off
;
7438 if (toc
->reloc_count
!= 0)
7440 Elf_Internal_Rela
*wrel
;
7443 /* Read toc relocs. */
7444 relstart
= _bfd_elf_link_read_relocs (ibfd
, toc
, NULL
, NULL
,
7446 if (relstart
== NULL
)
7449 /* Remove unused toc relocs, and adjust those we keep. */
7451 for (rel
= relstart
; rel
< relstart
+ toc
->reloc_count
; ++rel
)
7452 if (skip
[rel
->r_offset
>> 3] != (unsigned long) -1)
7454 wrel
->r_offset
= rel
->r_offset
- skip
[rel
->r_offset
>> 3];
7455 wrel
->r_info
= rel
->r_info
;
7456 wrel
->r_addend
= rel
->r_addend
;
7459 else if (!dec_dynrel_count (rel
->r_info
, toc
, info
,
7460 &local_syms
, NULL
, NULL
))
7463 toc
->reloc_count
= wrel
- relstart
;
7464 sz
= elf_section_data (toc
)->rel_hdr
.sh_entsize
;
7465 elf_section_data (toc
)->rel_hdr
.sh_size
= toc
->reloc_count
* sz
;
7466 BFD_ASSERT (elf_section_data (toc
)->rel_hdr2
== NULL
);
7469 /* Adjust addends for relocs against the toc section sym. */
7470 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
7472 if (sec
->reloc_count
== 0
7473 || elf_discarded_section (sec
))
7476 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
7478 if (relstart
== NULL
)
7481 for (rel
= relstart
; rel
< relstart
+ sec
->reloc_count
; ++rel
)
7483 enum elf_ppc64_reloc_type r_type
;
7484 unsigned long r_symndx
;
7486 struct elf_link_hash_entry
*h
;
7487 Elf_Internal_Sym
*sym
;
7489 r_type
= ELF64_R_TYPE (rel
->r_info
);
7496 case R_PPC64_TOC16_LO
:
7497 case R_PPC64_TOC16_HI
:
7498 case R_PPC64_TOC16_HA
:
7499 case R_PPC64_TOC16_DS
:
7500 case R_PPC64_TOC16_LO_DS
:
7501 case R_PPC64_ADDR64
:
7505 r_symndx
= ELF64_R_SYM (rel
->r_info
);
7506 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
7510 if (sym_sec
!= toc
|| h
!= NULL
|| sym
->st_value
!= 0)
7513 rel
->r_addend
-= skip
[rel
->r_addend
>> 3];
7517 /* We shouldn't have local or global symbols defined in the TOC,
7518 but handle them anyway. */
7519 if (local_syms
!= NULL
)
7521 Elf_Internal_Sym
*sym
;
7523 for (sym
= local_syms
;
7524 sym
< local_syms
+ symtab_hdr
->sh_info
;
7526 if (sym
->st_shndx
!= SHN_UNDEF
7527 && (sym
->st_shndx
< SHN_LORESERVE
7528 || sym
->st_shndx
> SHN_HIRESERVE
)
7529 && sym
->st_value
!= 0
7530 && bfd_section_from_elf_index (ibfd
, sym
->st_shndx
) == toc
)
7532 if (skip
[sym
->st_value
>> 3] != (unsigned long) -1)
7533 sym
->st_value
-= skip
[sym
->st_value
>> 3];
7536 (*_bfd_error_handler
)
7537 (_("%s defined in removed toc entry"),
7538 bfd_elf_sym_name (ibfd
, symtab_hdr
, sym
,
7541 sym
->st_shndx
= SHN_ABS
;
7543 symtab_hdr
->contents
= (unsigned char *) local_syms
;
7547 /* Finally, adjust any global syms defined in the toc. */
7548 if (toc_inf
.global_toc_syms
)
7551 toc_inf
.skip
= skip
;
7552 toc_inf
.global_toc_syms
= FALSE
;
7553 elf_link_hash_traverse (elf_hash_table (info
), adjust_toc_syms
,
7558 if (local_syms
!= NULL
7559 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
7561 if (!info
->keep_memory
)
7564 symtab_hdr
->contents
= (unsigned char *) local_syms
;
7572 /* Allocate space in .plt, .got and associated reloc sections for
7576 allocate_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
7578 struct bfd_link_info
*info
;
7579 struct ppc_link_hash_table
*htab
;
7581 struct ppc_link_hash_entry
*eh
;
7582 struct ppc_dyn_relocs
*p
;
7583 struct got_entry
*gent
;
7585 if (h
->root
.type
== bfd_link_hash_indirect
)
7588 if (h
->root
.type
== bfd_link_hash_warning
)
7589 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
7591 info
= (struct bfd_link_info
*) inf
;
7592 htab
= ppc_hash_table (info
);
7594 if (htab
->elf
.dynamic_sections_created
7596 && WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, info
->shared
, h
))
7598 struct plt_entry
*pent
;
7599 bfd_boolean doneone
= FALSE
;
7600 for (pent
= h
->plt
.plist
; pent
!= NULL
; pent
= pent
->next
)
7601 if (pent
->plt
.refcount
> 0)
7603 /* If this is the first .plt entry, make room for the special
7607 s
->size
+= PLT_INITIAL_ENTRY_SIZE
;
7609 pent
->plt
.offset
= s
->size
;
7611 /* Make room for this entry. */
7612 s
->size
+= PLT_ENTRY_SIZE
;
7614 /* Make room for the .glink code. */
7617 s
->size
+= GLINK_CALL_STUB_SIZE
;
7618 /* We need bigger stubs past index 32767. */
7619 if (s
->size
>= GLINK_CALL_STUB_SIZE
+ 32768*2*4)
7623 /* We also need to make an entry in the .rela.plt section. */
7625 s
->size
+= sizeof (Elf64_External_Rela
);
7629 pent
->plt
.offset
= (bfd_vma
) -1;
7632 h
->plt
.plist
= NULL
;
7638 h
->plt
.plist
= NULL
;
7642 eh
= (struct ppc_link_hash_entry
*) h
;
7643 /* Run through the TLS GD got entries first if we're changing them
7645 if ((eh
->tls_mask
& TLS_TPRELGD
) != 0)
7646 for (gent
= h
->got
.glist
; gent
!= NULL
; gent
= gent
->next
)
7647 if (gent
->got
.refcount
> 0
7648 && (gent
->tls_type
& TLS_GD
) != 0)
7650 /* This was a GD entry that has been converted to TPREL. If
7651 there happens to be a TPREL entry we can use that one. */
7652 struct got_entry
*ent
;
7653 for (ent
= h
->got
.glist
; ent
!= NULL
; ent
= ent
->next
)
7654 if (ent
->got
.refcount
> 0
7655 && (ent
->tls_type
& TLS_TPREL
) != 0
7656 && ent
->addend
== gent
->addend
7657 && ent
->owner
== gent
->owner
)
7659 gent
->got
.refcount
= 0;
7663 /* If not, then we'll be using our own TPREL entry. */
7664 if (gent
->got
.refcount
!= 0)
7665 gent
->tls_type
= TLS_TLS
| TLS_TPREL
;
7668 for (gent
= h
->got
.glist
; gent
!= NULL
; gent
= gent
->next
)
7669 if (gent
->got
.refcount
> 0)
7673 /* Make sure this symbol is output as a dynamic symbol.
7674 Undefined weak syms won't yet be marked as dynamic,
7675 nor will all TLS symbols. */
7676 if (h
->dynindx
== -1
7677 && !h
->forced_local
)
7679 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
7683 if ((gent
->tls_type
& TLS_LD
) != 0
7686 gent
->got
.offset
= ppc64_tlsld_got (gent
->owner
)->offset
;
7690 s
= ppc64_elf_tdata (gent
->owner
)->got
;
7691 gent
->got
.offset
= s
->size
;
7693 += (gent
->tls_type
& eh
->tls_mask
& (TLS_GD
| TLS_LD
)) ? 16 : 8;
7694 dyn
= htab
->elf
.dynamic_sections_created
;
7696 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, h
))
7697 && (ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
7698 || h
->root
.type
!= bfd_link_hash_undefweak
))
7699 ppc64_elf_tdata (gent
->owner
)->relgot
->size
7700 += (gent
->tls_type
& eh
->tls_mask
& TLS_GD
7701 ? 2 * sizeof (Elf64_External_Rela
)
7702 : sizeof (Elf64_External_Rela
));
7705 gent
->got
.offset
= (bfd_vma
) -1;
7707 if (eh
->dyn_relocs
== NULL
)
7710 /* In the shared -Bsymbolic case, discard space allocated for
7711 dynamic pc-relative relocs against symbols which turn out to be
7712 defined in regular objects. For the normal shared case, discard
7713 space for relocs that have become local due to symbol visibility
7718 /* Relocs that use pc_count are those that appear on a call insn,
7719 or certain REL relocs (see MUST_BE_DYN_RELOC) that can be
7720 generated via assembly. We want calls to protected symbols to
7721 resolve directly to the function rather than going via the plt.
7722 If people want function pointer comparisons to work as expected
7723 then they should avoid writing weird assembly. */
7724 if (SYMBOL_CALLS_LOCAL (info
, h
))
7726 struct ppc_dyn_relocs
**pp
;
7728 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
7730 p
->count
-= p
->pc_count
;
7739 /* Also discard relocs on undefined weak syms with non-default
7741 if (eh
->dyn_relocs
!= NULL
7742 && h
->root
.type
== bfd_link_hash_undefweak
)
7744 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
7745 eh
->dyn_relocs
= NULL
;
7747 /* Make sure this symbol is output as a dynamic symbol.
7748 Undefined weak syms won't yet be marked as dynamic. */
7749 else if (h
->dynindx
== -1
7750 && !h
->forced_local
)
7752 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
7757 else if (ELIMINATE_COPY_RELOCS
)
7759 /* For the non-shared case, discard space for relocs against
7760 symbols which turn out to need copy relocs or are not
7767 /* Make sure this symbol is output as a dynamic symbol.
7768 Undefined weak syms won't yet be marked as dynamic. */
7769 if (h
->dynindx
== -1
7770 && !h
->forced_local
)
7772 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
7776 /* If that succeeded, we know we'll be keeping all the
7778 if (h
->dynindx
!= -1)
7782 eh
->dyn_relocs
= NULL
;
7787 /* Finally, allocate space. */
7788 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
7790 asection
*sreloc
= elf_section_data (p
->sec
)->sreloc
;
7791 sreloc
->size
+= p
->count
* sizeof (Elf64_External_Rela
);
7797 /* Find any dynamic relocs that apply to read-only sections. */
7800 readonly_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
7802 struct ppc_link_hash_entry
*eh
;
7803 struct ppc_dyn_relocs
*p
;
7805 if (h
->root
.type
== bfd_link_hash_warning
)
7806 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
7808 eh
= (struct ppc_link_hash_entry
*) h
;
7809 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
7811 asection
*s
= p
->sec
->output_section
;
7813 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
7815 struct bfd_link_info
*info
= inf
;
7817 info
->flags
|= DF_TEXTREL
;
7819 /* Not an error, just cut short the traversal. */
7826 /* Set the sizes of the dynamic sections. */
7829 ppc64_elf_size_dynamic_sections (bfd
*output_bfd ATTRIBUTE_UNUSED
,
7830 struct bfd_link_info
*info
)
7832 struct ppc_link_hash_table
*htab
;
7838 htab
= ppc_hash_table (info
);
7839 dynobj
= htab
->elf
.dynobj
;
7843 if (htab
->elf
.dynamic_sections_created
)
7845 /* Set the contents of the .interp section to the interpreter. */
7846 if (info
->executable
)
7848 s
= bfd_get_section_by_name (dynobj
, ".interp");
7851 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
7852 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
7856 /* Set up .got offsets for local syms, and space for local dynamic
7858 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
7860 struct got_entry
**lgot_ents
;
7861 struct got_entry
**end_lgot_ents
;
7863 bfd_size_type locsymcount
;
7864 Elf_Internal_Shdr
*symtab_hdr
;
7867 if (!is_ppc64_elf_target (ibfd
->xvec
))
7870 if (ppc64_tlsld_got (ibfd
)->refcount
> 0)
7872 s
= ppc64_elf_tdata (ibfd
)->got
;
7873 ppc64_tlsld_got (ibfd
)->offset
= s
->size
;
7877 srel
= ppc64_elf_tdata (ibfd
)->relgot
;
7878 srel
->size
+= sizeof (Elf64_External_Rela
);
7882 ppc64_tlsld_got (ibfd
)->offset
= (bfd_vma
) -1;
7884 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
7886 struct ppc_dyn_relocs
*p
;
7888 for (p
= elf_section_data (s
)->local_dynrel
; p
!= NULL
; p
= p
->next
)
7890 if (!bfd_is_abs_section (p
->sec
)
7891 && bfd_is_abs_section (p
->sec
->output_section
))
7893 /* Input section has been discarded, either because
7894 it is a copy of a linkonce section or due to
7895 linker script /DISCARD/, so we'll be discarding
7898 else if (p
->count
!= 0)
7900 srel
= elf_section_data (p
->sec
)->sreloc
;
7901 srel
->size
+= p
->count
* sizeof (Elf64_External_Rela
);
7902 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0)
7903 info
->flags
|= DF_TEXTREL
;
7908 lgot_ents
= elf_local_got_ents (ibfd
);
7912 symtab_hdr
= &elf_tdata (ibfd
)->symtab_hdr
;
7913 locsymcount
= symtab_hdr
->sh_info
;
7914 end_lgot_ents
= lgot_ents
+ locsymcount
;
7915 lgot_masks
= (char *) end_lgot_ents
;
7916 s
= ppc64_elf_tdata (ibfd
)->got
;
7917 srel
= ppc64_elf_tdata (ibfd
)->relgot
;
7918 for (; lgot_ents
< end_lgot_ents
; ++lgot_ents
, ++lgot_masks
)
7920 struct got_entry
*ent
;
7922 for (ent
= *lgot_ents
; ent
!= NULL
; ent
= ent
->next
)
7923 if (ent
->got
.refcount
> 0)
7925 if ((ent
->tls_type
& *lgot_masks
& TLS_LD
) != 0)
7927 if (ppc64_tlsld_got (ibfd
)->offset
== (bfd_vma
) -1)
7929 ppc64_tlsld_got (ibfd
)->offset
= s
->size
;
7932 srel
->size
+= sizeof (Elf64_External_Rela
);
7934 ent
->got
.offset
= ppc64_tlsld_got (ibfd
)->offset
;
7938 ent
->got
.offset
= s
->size
;
7939 if ((ent
->tls_type
& *lgot_masks
& TLS_GD
) != 0)
7943 srel
->size
+= 2 * sizeof (Elf64_External_Rela
);
7949 srel
->size
+= sizeof (Elf64_External_Rela
);
7954 ent
->got
.offset
= (bfd_vma
) -1;
7958 /* Allocate global sym .plt and .got entries, and space for global
7959 sym dynamic relocs. */
7960 elf_link_hash_traverse (&htab
->elf
, allocate_dynrelocs
, info
);
7962 /* We now have determined the sizes of the various dynamic sections.
7963 Allocate memory for them. */
7965 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
7967 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
7970 if (s
== htab
->brlt
|| s
== htab
->relbrlt
)
7971 /* These haven't been allocated yet; don't strip. */
7973 else if (s
== htab
->got
7976 || s
== htab
->dynbss
)
7978 /* Strip this section if we don't need it; see the
7981 else if (CONST_STRNEQ (bfd_get_section_name (dynobj
, s
), ".rela"))
7985 if (s
!= htab
->relplt
)
7988 /* We use the reloc_count field as a counter if we need
7989 to copy relocs into the output file. */
7995 /* It's not one of our sections, so don't allocate space. */
8001 /* If we don't need this section, strip it from the
8002 output file. This is mostly to handle .rela.bss and
8003 .rela.plt. We must create both sections in
8004 create_dynamic_sections, because they must be created
8005 before the linker maps input sections to output
8006 sections. The linker does that before
8007 adjust_dynamic_symbol is called, and it is that
8008 function which decides whether anything needs to go
8009 into these sections. */
8010 s
->flags
|= SEC_EXCLUDE
;
8014 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
8017 /* Allocate memory for the section contents. We use bfd_zalloc
8018 here in case unused entries are not reclaimed before the
8019 section's contents are written out. This should not happen,
8020 but this way if it does we get a R_PPC64_NONE reloc in .rela
8021 sections instead of garbage.
8022 We also rely on the section contents being zero when writing
8024 s
->contents
= bfd_zalloc (dynobj
, s
->size
);
8025 if (s
->contents
== NULL
)
8029 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
8031 if (!is_ppc64_elf_target (ibfd
->xvec
))
8034 s
= ppc64_elf_tdata (ibfd
)->got
;
8035 if (s
!= NULL
&& s
!= htab
->got
)
8038 s
->flags
|= SEC_EXCLUDE
;
8041 s
->contents
= bfd_zalloc (ibfd
, s
->size
);
8042 if (s
->contents
== NULL
)
8046 s
= ppc64_elf_tdata (ibfd
)->relgot
;
8050 s
->flags
|= SEC_EXCLUDE
;
8053 s
->contents
= bfd_zalloc (ibfd
, s
->size
);
8054 if (s
->contents
== NULL
)
8062 if (htab
->elf
.dynamic_sections_created
)
8064 /* Add some entries to the .dynamic section. We fill in the
8065 values later, in ppc64_elf_finish_dynamic_sections, but we
8066 must add the entries now so that we get the correct size for
8067 the .dynamic section. The DT_DEBUG entry is filled in by the
8068 dynamic linker and used by the debugger. */
8069 #define add_dynamic_entry(TAG, VAL) \
8070 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
8072 if (info
->executable
)
8074 if (!add_dynamic_entry (DT_DEBUG
, 0))
8078 if (htab
->plt
!= NULL
&& htab
->plt
->size
!= 0)
8080 if (!add_dynamic_entry (DT_PLTGOT
, 0)
8081 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
8082 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
8083 || !add_dynamic_entry (DT_JMPREL
, 0)
8084 || !add_dynamic_entry (DT_PPC64_GLINK
, 0))
8090 if (!add_dynamic_entry (DT_PPC64_OPD
, 0)
8091 || !add_dynamic_entry (DT_PPC64_OPDSZ
, 0))
8097 if (!add_dynamic_entry (DT_RELA
, 0)
8098 || !add_dynamic_entry (DT_RELASZ
, 0)
8099 || !add_dynamic_entry (DT_RELAENT
, sizeof (Elf64_External_Rela
)))
8102 /* If any dynamic relocs apply to a read-only section,
8103 then we need a DT_TEXTREL entry. */
8104 if ((info
->flags
& DF_TEXTREL
) == 0)
8105 elf_link_hash_traverse (&htab
->elf
, readonly_dynrelocs
, info
);
8107 if ((info
->flags
& DF_TEXTREL
) != 0)
8109 if (!add_dynamic_entry (DT_TEXTREL
, 0))
8114 #undef add_dynamic_entry
8119 /* Determine the type of stub needed, if any, for a call. */
8121 static inline enum ppc_stub_type
8122 ppc_type_of_stub (asection
*input_sec
,
8123 const Elf_Internal_Rela
*rel
,
8124 struct ppc_link_hash_entry
**hash
,
8125 bfd_vma destination
)
8127 struct ppc_link_hash_entry
*h
= *hash
;
8129 bfd_vma branch_offset
;
8130 bfd_vma max_branch_offset
;
8131 enum elf_ppc64_reloc_type r_type
;
8135 struct ppc_link_hash_entry
*fdh
= h
;
8137 && fdh
->oh
->is_func_descriptor
)
8140 if (fdh
->elf
.dynindx
!= -1)
8142 struct plt_entry
*ent
;
8144 for (ent
= fdh
->elf
.plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
8145 if (ent
->addend
== rel
->r_addend
8146 && ent
->plt
.offset
!= (bfd_vma
) -1)
8149 return ppc_stub_plt_call
;
8153 /* Here, we know we don't have a plt entry. If we don't have a
8154 either a defined function descriptor or a defined entry symbol
8155 in a regular object file, then it is pointless trying to make
8156 any other type of stub. */
8157 if (!((fdh
->elf
.root
.type
== bfd_link_hash_defined
8158 || fdh
->elf
.root
.type
== bfd_link_hash_defweak
)
8159 && fdh
->elf
.root
.u
.def
.section
->output_section
!= NULL
)
8160 && !((h
->elf
.root
.type
== bfd_link_hash_defined
8161 || h
->elf
.root
.type
== bfd_link_hash_defweak
)
8162 && h
->elf
.root
.u
.def
.section
->output_section
!= NULL
))
8163 return ppc_stub_none
;
8166 /* Determine where the call point is. */
8167 location
= (input_sec
->output_offset
8168 + input_sec
->output_section
->vma
8171 branch_offset
= destination
- location
;
8172 r_type
= ELF64_R_TYPE (rel
->r_info
);
8174 /* Determine if a long branch stub is needed. */
8175 max_branch_offset
= 1 << 25;
8176 if (r_type
!= R_PPC64_REL24
)
8177 max_branch_offset
= 1 << 15;
8179 if (branch_offset
+ max_branch_offset
>= 2 * max_branch_offset
)
8180 /* We need a stub. Figure out whether a long_branch or plt_branch
8182 return ppc_stub_long_branch
;
8184 return ppc_stub_none
;
8187 /* Build a .plt call stub. */
8189 static inline bfd_byte
*
8190 build_plt_stub (bfd
*obfd
, bfd_byte
*p
, int offset
)
8192 #define PPC_LO(v) ((v) & 0xffff)
8193 #define PPC_HI(v) (((v) >> 16) & 0xffff)
8194 #define PPC_HA(v) PPC_HI ((v) + 0x8000)
8196 bfd_put_32 (obfd
, ADDIS_R12_R2
| PPC_HA (offset
), p
), p
+= 4;
8197 bfd_put_32 (obfd
, STD_R2_40R1
, p
), p
+= 4;
8198 bfd_put_32 (obfd
, LD_R11_0R12
| PPC_LO (offset
), p
), p
+= 4;
8199 if (PPC_HA (offset
+ 8) != PPC_HA (offset
))
8200 bfd_put_32 (obfd
, ADDIS_R12_R12
| 1, p
), p
+= 4;
8202 bfd_put_32 (obfd
, LD_R2_0R12
| PPC_LO (offset
), p
), p
+= 4;
8203 if (PPC_HA (offset
+ 8) != PPC_HA (offset
))
8204 bfd_put_32 (obfd
, ADDIS_R12_R12
| 1, p
), p
+= 4;
8206 bfd_put_32 (obfd
, MTCTR_R11
, p
), p
+= 4;
8207 bfd_put_32 (obfd
, LD_R11_0R12
| PPC_LO (offset
), p
), p
+= 4;
8208 bfd_put_32 (obfd
, BCTR
, p
), p
+= 4;
8213 ppc_build_one_stub (struct bfd_hash_entry
*gen_entry
, void *in_arg
)
8215 struct ppc_stub_hash_entry
*stub_entry
;
8216 struct ppc_branch_hash_entry
*br_entry
;
8217 struct bfd_link_info
*info
;
8218 struct ppc_link_hash_table
*htab
;
8222 struct plt_entry
*ent
;
8226 /* Massage our args to the form they really have. */
8227 stub_entry
= (struct ppc_stub_hash_entry
*) gen_entry
;
8230 htab
= ppc_hash_table (info
);
8232 /* Make a note of the offset within the stubs for this entry. */
8233 stub_entry
->stub_offset
= stub_entry
->stub_sec
->size
;
8234 loc
= stub_entry
->stub_sec
->contents
+ stub_entry
->stub_offset
;
8236 htab
->stub_count
[stub_entry
->stub_type
- 1] += 1;
8237 switch (stub_entry
->stub_type
)
8239 case ppc_stub_long_branch
:
8240 case ppc_stub_long_branch_r2off
:
8241 /* Branches are relative. This is where we are going to. */
8242 off
= dest
= (stub_entry
->target_value
8243 + stub_entry
->target_section
->output_offset
8244 + stub_entry
->target_section
->output_section
->vma
);
8246 /* And this is where we are coming from. */
8247 off
-= (stub_entry
->stub_offset
8248 + stub_entry
->stub_sec
->output_offset
8249 + stub_entry
->stub_sec
->output_section
->vma
);
8251 if (stub_entry
->stub_type
!= ppc_stub_long_branch_r2off
)
8257 r2off
= (htab
->stub_group
[stub_entry
->target_section
->id
].toc_off
8258 - htab
->stub_group
[stub_entry
->id_sec
->id
].toc_off
);
8259 bfd_put_32 (htab
->stub_bfd
, STD_R2_40R1
, loc
);
8261 bfd_put_32 (htab
->stub_bfd
, ADDIS_R2_R2
| PPC_HA (r2off
), loc
);
8263 bfd_put_32 (htab
->stub_bfd
, ADDI_R2_R2
| PPC_LO (r2off
), loc
);
8268 bfd_put_32 (htab
->stub_bfd
, B_DOT
| (off
& 0x3fffffc), loc
);
8270 if (off
+ (1 << 25) >= (bfd_vma
) (1 << 26))
8272 (*_bfd_error_handler
) (_("long branch stub `%s' offset overflow"),
8273 stub_entry
->root
.string
);
8274 htab
->stub_error
= TRUE
;
8278 if (info
->emitrelocations
)
8280 Elf_Internal_Rela
*relocs
, *r
;
8281 struct bfd_elf_section_data
*elfsec_data
;
8283 elfsec_data
= elf_section_data (stub_entry
->stub_sec
);
8284 relocs
= elfsec_data
->relocs
;
8287 bfd_size_type relsize
;
8288 relsize
= stub_entry
->stub_sec
->reloc_count
* sizeof (*relocs
);
8289 relocs
= bfd_alloc (htab
->stub_bfd
, relsize
);
8292 elfsec_data
->relocs
= relocs
;
8293 elfsec_data
->rel_hdr
.sh_size
= relsize
;
8294 elfsec_data
->rel_hdr
.sh_entsize
= 24;
8295 stub_entry
->stub_sec
->reloc_count
= 0;
8297 r
= relocs
+ stub_entry
->stub_sec
->reloc_count
;
8298 stub_entry
->stub_sec
->reloc_count
+= 1;
8299 r
->r_offset
= loc
- stub_entry
->stub_sec
->contents
;
8300 r
->r_info
= ELF64_R_INFO (0, R_PPC64_REL24
);
8302 if (stub_entry
->h
!= NULL
)
8304 struct elf_link_hash_entry
**hashes
;
8305 unsigned long symndx
;
8306 struct ppc_link_hash_entry
*h
;
8308 hashes
= elf_sym_hashes (htab
->stub_bfd
);
8311 bfd_size_type hsize
;
8313 hsize
= (htab
->stub_globals
+ 1) * sizeof (*hashes
);
8314 hashes
= bfd_zalloc (htab
->stub_bfd
, hsize
);
8317 elf_sym_hashes (htab
->stub_bfd
) = hashes
;
8318 htab
->stub_globals
= 1;
8320 symndx
= htab
->stub_globals
++;
8322 hashes
[symndx
] = &h
->elf
;
8323 r
->r_info
= ELF64_R_INFO (symndx
, R_PPC64_REL24
);
8324 if (h
->oh
!= NULL
&& h
->oh
->is_func
)
8326 if (h
->elf
.root
.u
.def
.section
!= stub_entry
->target_section
)
8327 /* H is an opd symbol. The addend must be zero. */
8331 off
= (h
->elf
.root
.u
.def
.value
8332 + h
->elf
.root
.u
.def
.section
->output_offset
8333 + h
->elf
.root
.u
.def
.section
->output_section
->vma
);
8340 case ppc_stub_plt_branch
:
8341 case ppc_stub_plt_branch_r2off
:
8342 br_entry
= ppc_branch_hash_lookup (&htab
->branch_hash_table
,
8343 stub_entry
->root
.string
+ 9,
8345 if (br_entry
== NULL
)
8347 (*_bfd_error_handler
) (_("can't find branch stub `%s'"),
8348 stub_entry
->root
.string
);
8349 htab
->stub_error
= TRUE
;
8353 off
= (stub_entry
->target_value
8354 + stub_entry
->target_section
->output_offset
8355 + stub_entry
->target_section
->output_section
->vma
);
8357 bfd_put_64 (htab
->brlt
->owner
, off
,
8358 htab
->brlt
->contents
+ br_entry
->offset
);
8360 if (htab
->relbrlt
!= NULL
)
8362 /* Create a reloc for the branch lookup table entry. */
8363 Elf_Internal_Rela rela
;
8366 rela
.r_offset
= (br_entry
->offset
8367 + htab
->brlt
->output_offset
8368 + htab
->brlt
->output_section
->vma
);
8369 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
8370 rela
.r_addend
= off
;
8372 rl
= htab
->relbrlt
->contents
;
8373 rl
+= htab
->relbrlt
->reloc_count
++ * sizeof (Elf64_External_Rela
);
8374 bfd_elf64_swap_reloca_out (htab
->relbrlt
->owner
, &rela
, rl
);
8376 else if (info
->emitrelocations
)
8378 Elf_Internal_Rela
*relocs
, *r
;
8379 struct bfd_elf_section_data
*elfsec_data
;
8381 elfsec_data
= elf_section_data (htab
->brlt
);
8382 relocs
= elfsec_data
->relocs
;
8385 bfd_size_type relsize
;
8386 relsize
= htab
->brlt
->reloc_count
* sizeof (*relocs
);
8387 relocs
= bfd_alloc (htab
->brlt
->owner
, relsize
);
8390 elfsec_data
->relocs
= relocs
;
8391 elfsec_data
->rel_hdr
.sh_size
= relsize
;
8392 elfsec_data
->rel_hdr
.sh_entsize
= 24;
8393 htab
->brlt
->reloc_count
= 0;
8395 r
= relocs
+ htab
->brlt
->reloc_count
;
8396 htab
->brlt
->reloc_count
+= 1;
8397 r
->r_offset
= (br_entry
->offset
8398 + htab
->brlt
->output_offset
8399 + htab
->brlt
->output_section
->vma
);
8400 r
->r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
8404 off
= (br_entry
->offset
8405 + htab
->brlt
->output_offset
8406 + htab
->brlt
->output_section
->vma
8407 - elf_gp (htab
->brlt
->output_section
->owner
)
8408 - htab
->stub_group
[stub_entry
->id_sec
->id
].toc_off
);
8410 if (off
+ 0x80008000 > 0xffffffff || (off
& 7) != 0)
8412 (*_bfd_error_handler
)
8413 (_("linkage table error against `%s'"),
8414 stub_entry
->root
.string
);
8415 bfd_set_error (bfd_error_bad_value
);
8416 htab
->stub_error
= TRUE
;
8421 if (stub_entry
->stub_type
!= ppc_stub_plt_branch_r2off
)
8423 bfd_put_32 (htab
->stub_bfd
, ADDIS_R12_R2
| PPC_HA (indx
), loc
);
8425 bfd_put_32 (htab
->stub_bfd
, LD_R11_0R12
| PPC_LO (indx
), loc
);
8432 r2off
= (htab
->stub_group
[stub_entry
->target_section
->id
].toc_off
8433 - htab
->stub_group
[stub_entry
->id_sec
->id
].toc_off
);
8434 bfd_put_32 (htab
->stub_bfd
, STD_R2_40R1
, loc
);
8436 bfd_put_32 (htab
->stub_bfd
, ADDIS_R12_R2
| PPC_HA (indx
), loc
);
8438 bfd_put_32 (htab
->stub_bfd
, LD_R11_0R12
| PPC_LO (indx
), loc
);
8440 bfd_put_32 (htab
->stub_bfd
, ADDIS_R2_R2
| PPC_HA (r2off
), loc
);
8442 bfd_put_32 (htab
->stub_bfd
, ADDI_R2_R2
| PPC_LO (r2off
), loc
);
8446 bfd_put_32 (htab
->stub_bfd
, MTCTR_R11
, loc
);
8448 bfd_put_32 (htab
->stub_bfd
, BCTR
, loc
);
8451 case ppc_stub_plt_call
:
8452 /* Do the best we can for shared libraries built without
8453 exporting ".foo" for each "foo". This can happen when symbol
8454 versioning scripts strip all bar a subset of symbols. */
8455 if (stub_entry
->h
->oh
!= NULL
8456 && stub_entry
->h
->oh
->elf
.root
.type
!= bfd_link_hash_defined
8457 && stub_entry
->h
->oh
->elf
.root
.type
!= bfd_link_hash_defweak
)
8459 /* Point the symbol at the stub. There may be multiple stubs,
8460 we don't really care; The main thing is to make this sym
8461 defined somewhere. Maybe defining the symbol in the stub
8462 section is a silly idea. If we didn't do this, htab->top_id
8464 stub_entry
->h
->oh
->elf
.root
.type
= bfd_link_hash_defined
;
8465 stub_entry
->h
->oh
->elf
.root
.u
.def
.section
= stub_entry
->stub_sec
;
8466 stub_entry
->h
->oh
->elf
.root
.u
.def
.value
= stub_entry
->stub_offset
;
8469 /* Now build the stub. */
8471 for (ent
= stub_entry
->h
->elf
.plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
8472 if (ent
->addend
== stub_entry
->addend
)
8474 off
= ent
->plt
.offset
;
8477 if (off
>= (bfd_vma
) -2)
8480 off
&= ~ (bfd_vma
) 1;
8481 off
+= (htab
->plt
->output_offset
8482 + htab
->plt
->output_section
->vma
8483 - elf_gp (htab
->plt
->output_section
->owner
)
8484 - htab
->stub_group
[stub_entry
->id_sec
->id
].toc_off
);
8486 if (off
+ 0x80008000 > 0xffffffff || (off
& 7) != 0)
8488 (*_bfd_error_handler
)
8489 (_("linkage table error against `%s'"),
8490 stub_entry
->h
->elf
.root
.root
.string
);
8491 bfd_set_error (bfd_error_bad_value
);
8492 htab
->stub_error
= TRUE
;
8496 p
= build_plt_stub (htab
->stub_bfd
, loc
, off
);
8505 stub_entry
->stub_sec
->size
+= size
;
8507 if (htab
->emit_stub_syms
)
8509 struct elf_link_hash_entry
*h
;
8512 const char *const stub_str
[] = { "long_branch",
8513 "long_branch_r2off",
8518 len1
= strlen (stub_str
[stub_entry
->stub_type
- 1]);
8519 len2
= strlen (stub_entry
->root
.string
);
8520 name
= bfd_malloc (len1
+ len2
+ 2);
8523 memcpy (name
, stub_entry
->root
.string
, 9);
8524 memcpy (name
+ 9, stub_str
[stub_entry
->stub_type
- 1], len1
);
8525 memcpy (name
+ len1
+ 9, stub_entry
->root
.string
+ 8, len2
- 8 + 1);
8526 h
= elf_link_hash_lookup (&htab
->elf
, name
, TRUE
, FALSE
, FALSE
);
8529 if (h
->root
.type
== bfd_link_hash_new
)
8531 h
->root
.type
= bfd_link_hash_defined
;
8532 h
->root
.u
.def
.section
= stub_entry
->stub_sec
;
8533 h
->root
.u
.def
.value
= stub_entry
->stub_offset
;
8536 h
->ref_regular_nonweak
= 1;
8537 h
->forced_local
= 1;
8545 /* As above, but don't actually build the stub. Just bump offset so
8546 we know stub section sizes, and select plt_branch stubs where
8547 long_branch stubs won't do. */
8550 ppc_size_one_stub (struct bfd_hash_entry
*gen_entry
, void *in_arg
)
8552 struct ppc_stub_hash_entry
*stub_entry
;
8553 struct bfd_link_info
*info
;
8554 struct ppc_link_hash_table
*htab
;
8558 /* Massage our args to the form they really have. */
8559 stub_entry
= (struct ppc_stub_hash_entry
*) gen_entry
;
8562 htab
= ppc_hash_table (info
);
8564 if (stub_entry
->stub_type
== ppc_stub_plt_call
)
8566 struct plt_entry
*ent
;
8568 for (ent
= stub_entry
->h
->elf
.plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
8569 if (ent
->addend
== stub_entry
->addend
)
8571 off
= ent
->plt
.offset
& ~(bfd_vma
) 1;
8574 if (off
>= (bfd_vma
) -2)
8576 off
+= (htab
->plt
->output_offset
8577 + htab
->plt
->output_section
->vma
8578 - elf_gp (htab
->plt
->output_section
->owner
)
8579 - htab
->stub_group
[stub_entry
->id_sec
->id
].toc_off
);
8581 size
= PLT_CALL_STUB_SIZE
;
8582 if (PPC_HA (off
+ 16) != PPC_HA (off
))
8587 /* ppc_stub_long_branch or ppc_stub_plt_branch, or their r2off
8589 off
= (stub_entry
->target_value
8590 + stub_entry
->target_section
->output_offset
8591 + stub_entry
->target_section
->output_section
->vma
);
8592 off
-= (stub_entry
->stub_sec
->size
8593 + stub_entry
->stub_sec
->output_offset
8594 + stub_entry
->stub_sec
->output_section
->vma
);
8596 /* Reset the stub type from the plt variant in case we now
8597 can reach with a shorter stub. */
8598 if (stub_entry
->stub_type
>= ppc_stub_plt_branch
)
8599 stub_entry
->stub_type
+= ppc_stub_long_branch
- ppc_stub_plt_branch
;
8602 if (stub_entry
->stub_type
== ppc_stub_long_branch_r2off
)
8608 /* If the branch offset if too big, use a ppc_stub_plt_branch. */
8609 if (off
+ (1 << 25) >= (bfd_vma
) (1 << 26))
8611 struct ppc_branch_hash_entry
*br_entry
;
8613 br_entry
= ppc_branch_hash_lookup (&htab
->branch_hash_table
,
8614 stub_entry
->root
.string
+ 9,
8616 if (br_entry
== NULL
)
8618 (*_bfd_error_handler
) (_("can't build branch stub `%s'"),
8619 stub_entry
->root
.string
);
8620 htab
->stub_error
= TRUE
;
8624 if (br_entry
->iter
!= htab
->stub_iteration
)
8626 br_entry
->iter
= htab
->stub_iteration
;
8627 br_entry
->offset
= htab
->brlt
->size
;
8628 htab
->brlt
->size
+= 8;
8630 if (htab
->relbrlt
!= NULL
)
8631 htab
->relbrlt
->size
+= sizeof (Elf64_External_Rela
);
8632 else if (info
->emitrelocations
)
8634 htab
->brlt
->reloc_count
+= 1;
8635 htab
->brlt
->flags
|= SEC_RELOC
;
8639 stub_entry
->stub_type
+= ppc_stub_plt_branch
- ppc_stub_long_branch
;
8641 if (stub_entry
->stub_type
!= ppc_stub_plt_branch
)
8644 else if (info
->emitrelocations
)
8646 stub_entry
->stub_sec
->reloc_count
+= 1;
8647 stub_entry
->stub_sec
->flags
|= SEC_RELOC
;
8651 stub_entry
->stub_sec
->size
+= size
;
8655 /* Set up various things so that we can make a list of input sections
8656 for each output section included in the link. Returns -1 on error,
8657 0 when no stubs will be needed, and 1 on success. */
8660 ppc64_elf_setup_section_lists (bfd
*output_bfd
,
8661 struct bfd_link_info
*info
,
8665 int top_id
, top_index
, id
;
8667 asection
**input_list
;
8669 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
8671 htab
->no_multi_toc
= no_multi_toc
;
8673 if (htab
->brlt
== NULL
)
8676 /* Find the top input section id. */
8677 for (input_bfd
= info
->input_bfds
, top_id
= 3;
8679 input_bfd
= input_bfd
->link_next
)
8681 for (section
= input_bfd
->sections
;
8683 section
= section
->next
)
8685 if (top_id
< section
->id
)
8686 top_id
= section
->id
;
8690 htab
->top_id
= top_id
;
8691 amt
= sizeof (struct map_stub
) * (top_id
+ 1);
8692 htab
->stub_group
= bfd_zmalloc (amt
);
8693 if (htab
->stub_group
== NULL
)
8696 /* Set toc_off for com, und, abs and ind sections. */
8697 for (id
= 0; id
< 3; id
++)
8698 htab
->stub_group
[id
].toc_off
= TOC_BASE_OFF
;
8700 elf_gp (output_bfd
) = htab
->toc_curr
= ppc64_elf_toc (output_bfd
);
8702 /* We can't use output_bfd->section_count here to find the top output
8703 section index as some sections may have been removed, and
8704 strip_excluded_output_sections doesn't renumber the indices. */
8705 for (section
= output_bfd
->sections
, top_index
= 0;
8707 section
= section
->next
)
8709 if (top_index
< section
->index
)
8710 top_index
= section
->index
;
8713 htab
->top_index
= top_index
;
8714 amt
= sizeof (asection
*) * (top_index
+ 1);
8715 input_list
= bfd_zmalloc (amt
);
8716 htab
->input_list
= input_list
;
8717 if (input_list
== NULL
)
8723 /* The linker repeatedly calls this function for each TOC input section
8724 and linker generated GOT section. Group input bfds such that the toc
8725 within a group is less than 64k in size. Will break with cute linker
8726 scripts that play games with dot in the output toc section. */
8729 ppc64_elf_next_toc_section (struct bfd_link_info
*info
, asection
*isec
)
8731 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
8733 if (!htab
->no_multi_toc
)
8735 bfd_vma addr
= isec
->output_offset
+ isec
->output_section
->vma
;
8736 bfd_vma off
= addr
- htab
->toc_curr
;
8738 if (off
+ isec
->size
> 0x10000)
8739 htab
->toc_curr
= addr
;
8741 elf_gp (isec
->owner
) = (htab
->toc_curr
8742 - elf_gp (isec
->output_section
->owner
)
8747 /* Called after the last call to the above function. */
8750 ppc64_elf_reinit_toc (bfd
*output_bfd
, struct bfd_link_info
*info
)
8752 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
8754 htab
->multi_toc_needed
= htab
->toc_curr
!= elf_gp (output_bfd
);
8756 /* toc_curr tracks the TOC offset used for code sections below in
8757 ppc64_elf_next_input_section. Start off at 0x8000. */
8758 htab
->toc_curr
= TOC_BASE_OFF
;
8761 /* No toc references were found in ISEC. If the code in ISEC makes no
8762 calls, then there's no need to use toc adjusting stubs when branching
8763 into ISEC. Actually, indirect calls from ISEC are OK as they will
8764 load r2. Returns -1 on error, 0 for no stub needed, 1 for stub
8765 needed, and 2 if a cyclical call-graph was found but no other reason
8766 for a stub was detected. If called from the top level, a return of
8767 2 means the same as a return of 0. */
8770 toc_adjusting_stub_needed (struct bfd_link_info
*info
, asection
*isec
)
8772 Elf_Internal_Rela
*relstart
, *rel
;
8773 Elf_Internal_Sym
*local_syms
;
8775 struct ppc_link_hash_table
*htab
;
8777 /* We know none of our code bearing sections will need toc stubs. */
8778 if ((isec
->flags
& SEC_LINKER_CREATED
) != 0)
8781 if (isec
->size
== 0)
8784 if (isec
->output_section
== NULL
)
8787 /* Hack for linux kernel. .fixup contains branches, but only back to
8788 the function that hit an exception. */
8789 if (strcmp (isec
->name
, ".fixup") == 0)
8792 if (isec
->reloc_count
== 0)
8795 relstart
= _bfd_elf_link_read_relocs (isec
->owner
, isec
, NULL
, NULL
,
8797 if (relstart
== NULL
)
8800 /* Look for branches to outside of this section. */
8803 htab
= ppc_hash_table (info
);
8804 for (rel
= relstart
; rel
< relstart
+ isec
->reloc_count
; ++rel
)
8806 enum elf_ppc64_reloc_type r_type
;
8807 unsigned long r_symndx
;
8808 struct elf_link_hash_entry
*h
;
8809 Elf_Internal_Sym
*sym
;
8815 r_type
= ELF64_R_TYPE (rel
->r_info
);
8816 if (r_type
!= R_PPC64_REL24
8817 && r_type
!= R_PPC64_REL14
8818 && r_type
!= R_PPC64_REL14_BRTAKEN
8819 && r_type
!= R_PPC64_REL14_BRNTAKEN
)
8822 r_symndx
= ELF64_R_SYM (rel
->r_info
);
8823 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
, r_symndx
,
8830 /* Calls to dynamic lib functions go through a plt call stub
8831 that uses r2. Branches to undefined symbols might be a call
8832 using old-style dot symbols that can be satisfied by a plt
8833 call into a new-style dynamic library. */
8834 if (sym_sec
== NULL
)
8836 struct ppc_link_hash_entry
*eh
= (struct ppc_link_hash_entry
*) h
;
8839 && eh
->oh
->elf
.plt
.plist
!= NULL
)
8845 /* Ignore other undefined symbols. */
8849 /* Assume branches to other sections not included in the link need
8850 stubs too, to cover -R and absolute syms. */
8851 if (sym_sec
->output_section
== NULL
)
8858 sym_value
= sym
->st_value
;
8861 if (h
->root
.type
!= bfd_link_hash_defined
8862 && h
->root
.type
!= bfd_link_hash_defweak
)
8864 sym_value
= h
->root
.u
.def
.value
;
8866 sym_value
+= rel
->r_addend
;
8868 /* If this branch reloc uses an opd sym, find the code section. */
8869 opd_adjust
= get_opd_info (sym_sec
);
8870 if (opd_adjust
!= NULL
)
8876 adjust
= opd_adjust
[sym
->st_value
/ 8];
8878 /* Assume deleted functions won't ever be called. */
8880 sym_value
+= adjust
;
8883 dest
= opd_entry_value (sym_sec
, sym_value
, &sym_sec
, NULL
);
8884 if (dest
== (bfd_vma
) -1)
8889 + sym_sec
->output_offset
8890 + sym_sec
->output_section
->vma
);
8892 /* Ignore branch to self. */
8893 if (sym_sec
== isec
)
8896 /* If the called function uses the toc, we need a stub. */
8897 if (sym_sec
->has_toc_reloc
8898 || sym_sec
->makes_toc_func_call
)
8904 /* Assume any branch that needs a long branch stub might in fact
8905 need a plt_branch stub. A plt_branch stub uses r2. */
8906 else if (dest
- (isec
->output_offset
8907 + isec
->output_section
->vma
8908 + rel
->r_offset
) + (1 << 25) >= (2 << 25))
8914 /* If calling back to a section in the process of being tested, we
8915 can't say for sure that no toc adjusting stubs are needed, so
8916 don't return zero. */
8917 else if (sym_sec
->call_check_in_progress
)
8920 /* Branches to another section that itself doesn't have any TOC
8921 references are OK. Recursively call ourselves to check. */
8922 else if (sym_sec
->id
<= htab
->top_id
8923 && htab
->stub_group
[sym_sec
->id
].toc_off
== 0)
8927 /* Mark current section as indeterminate, so that other
8928 sections that call back to current won't be marked as
8930 isec
->call_check_in_progress
= 1;
8931 recur
= toc_adjusting_stub_needed (info
, sym_sec
);
8932 isec
->call_check_in_progress
= 0;
8936 /* An error. Exit. */
8940 else if (recur
<= 1)
8942 /* Known result. Mark as checked and set section flag. */
8943 htab
->stub_group
[sym_sec
->id
].toc_off
= 1;
8946 sym_sec
->makes_toc_func_call
= 1;
8953 /* Unknown result. Continue checking. */
8959 if (local_syms
!= NULL
8960 && (elf_tdata (isec
->owner
)->symtab_hdr
.contents
8961 != (unsigned char *) local_syms
))
8963 if (elf_section_data (isec
)->relocs
!= relstart
)
8969 /* The linker repeatedly calls this function for each input section,
8970 in the order that input sections are linked into output sections.
8971 Build lists of input sections to determine groupings between which
8972 we may insert linker stubs. */
8975 ppc64_elf_next_input_section (struct bfd_link_info
*info
, asection
*isec
)
8977 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
8979 if ((isec
->output_section
->flags
& SEC_CODE
) != 0
8980 && isec
->output_section
->index
<= htab
->top_index
)
8982 asection
**list
= htab
->input_list
+ isec
->output_section
->index
;
8983 /* Steal the link_sec pointer for our list. */
8984 #define PREV_SEC(sec) (htab->stub_group[(sec)->id].link_sec)
8985 /* This happens to make the list in reverse order,
8986 which is what we want. */
8987 PREV_SEC (isec
) = *list
;
8991 if (htab
->multi_toc_needed
)
8993 /* If a code section has a function that uses the TOC then we need
8994 to use the right TOC (obviously). Also, make sure that .opd gets
8995 the correct TOC value for R_PPC64_TOC relocs that don't have or
8996 can't find their function symbol (shouldn't ever happen now). */
8997 if (isec
->has_toc_reloc
|| (isec
->flags
& SEC_CODE
) == 0)
8999 if (elf_gp (isec
->owner
) != 0)
9000 htab
->toc_curr
= elf_gp (isec
->owner
);
9002 else if (htab
->stub_group
[isec
->id
].toc_off
== 0)
9004 int ret
= toc_adjusting_stub_needed (info
, isec
);
9008 isec
->makes_toc_func_call
= ret
& 1;
9012 /* Functions that don't use the TOC can belong in any TOC group.
9013 Use the last TOC base. This happens to make _init and _fini
9015 htab
->stub_group
[isec
->id
].toc_off
= htab
->toc_curr
;
9019 /* See whether we can group stub sections together. Grouping stub
9020 sections may result in fewer stubs. More importantly, we need to
9021 put all .init* and .fini* stubs at the beginning of the .init or
9022 .fini output sections respectively, because glibc splits the
9023 _init and _fini functions into multiple parts. Putting a stub in
9024 the middle of a function is not a good idea. */
9027 group_sections (struct ppc_link_hash_table
*htab
,
9028 bfd_size_type stub_group_size
,
9029 bfd_boolean stubs_always_before_branch
)
9032 bfd_size_type stub14_group_size
;
9033 bfd_boolean suppress_size_errors
;
9035 suppress_size_errors
= FALSE
;
9036 stub14_group_size
= stub_group_size
;
9037 if (stub_group_size
== 1)
9039 /* Default values. */
9040 if (stubs_always_before_branch
)
9042 stub_group_size
= 0x1e00000;
9043 stub14_group_size
= 0x7800;
9047 stub_group_size
= 0x1c00000;
9048 stub14_group_size
= 0x7000;
9050 suppress_size_errors
= TRUE
;
9053 list
= htab
->input_list
+ htab
->top_index
;
9056 asection
*tail
= *list
;
9057 while (tail
!= NULL
)
9061 bfd_size_type total
;
9062 bfd_boolean big_sec
;
9067 big_sec
= total
> (ppc64_elf_section_data (tail
)->has_14bit_branch
9068 ? stub14_group_size
: stub_group_size
);
9069 if (big_sec
&& !suppress_size_errors
)
9070 (*_bfd_error_handler
) (_("%B section %A exceeds stub group size"),
9072 curr_toc
= htab
->stub_group
[tail
->id
].toc_off
;
9074 while ((prev
= PREV_SEC (curr
)) != NULL
9075 && ((total
+= curr
->output_offset
- prev
->output_offset
)
9076 < (ppc64_elf_section_data (prev
)->has_14bit_branch
9077 ? stub14_group_size
: stub_group_size
))
9078 && htab
->stub_group
[prev
->id
].toc_off
== curr_toc
)
9081 /* OK, the size from the start of CURR to the end is less
9082 than stub_group_size and thus can be handled by one stub
9083 section. (or the tail section is itself larger than
9084 stub_group_size, in which case we may be toast.) We
9085 should really be keeping track of the total size of stubs
9086 added here, as stubs contribute to the final output
9087 section size. That's a little tricky, and this way will
9088 only break if stubs added make the total size more than
9089 2^25, ie. for the default stub_group_size, if stubs total
9090 more than 2097152 bytes, or nearly 75000 plt call stubs. */
9093 prev
= PREV_SEC (tail
);
9094 /* Set up this stub group. */
9095 htab
->stub_group
[tail
->id
].link_sec
= curr
;
9097 while (tail
!= curr
&& (tail
= prev
) != NULL
);
9099 /* But wait, there's more! Input sections up to stub_group_size
9100 bytes before the stub section can be handled by it too.
9101 Don't do this if we have a really large section after the
9102 stubs, as adding more stubs increases the chance that
9103 branches may not reach into the stub section. */
9104 if (!stubs_always_before_branch
&& !big_sec
)
9108 && ((total
+= tail
->output_offset
- prev
->output_offset
)
9109 < (ppc64_elf_section_data (prev
)->has_14bit_branch
9110 ? stub14_group_size
: stub_group_size
))
9111 && htab
->stub_group
[prev
->id
].toc_off
== curr_toc
)
9114 prev
= PREV_SEC (tail
);
9115 htab
->stub_group
[tail
->id
].link_sec
= curr
;
9121 while (list
-- != htab
->input_list
);
9122 free (htab
->input_list
);
9126 /* Determine and set the size of the stub section for a final link.
9128 The basic idea here is to examine all the relocations looking for
9129 PC-relative calls to a target that is unreachable with a "bl"
9133 ppc64_elf_size_stubs (bfd
*output_bfd
,
9134 struct bfd_link_info
*info
,
9135 bfd_signed_vma group_size
,
9136 asection
*(*add_stub_section
) (const char *, asection
*),
9137 void (*layout_sections_again
) (void))
9139 bfd_size_type stub_group_size
;
9140 bfd_boolean stubs_always_before_branch
;
9141 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
9143 /* Stash our params away. */
9144 htab
->add_stub_section
= add_stub_section
;
9145 htab
->layout_sections_again
= layout_sections_again
;
9146 stubs_always_before_branch
= group_size
< 0;
9148 stub_group_size
= -group_size
;
9150 stub_group_size
= group_size
;
9152 group_sections (htab
, stub_group_size
, stubs_always_before_branch
);
9157 unsigned int bfd_indx
;
9160 htab
->stub_iteration
+= 1;
9162 for (input_bfd
= info
->input_bfds
, bfd_indx
= 0;
9164 input_bfd
= input_bfd
->link_next
, bfd_indx
++)
9166 Elf_Internal_Shdr
*symtab_hdr
;
9168 Elf_Internal_Sym
*local_syms
= NULL
;
9170 if (!is_ppc64_elf_target (input_bfd
->xvec
))
9173 /* We'll need the symbol table in a second. */
9174 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
9175 if (symtab_hdr
->sh_info
== 0)
9178 /* Walk over each section attached to the input bfd. */
9179 for (section
= input_bfd
->sections
;
9181 section
= section
->next
)
9183 Elf_Internal_Rela
*internal_relocs
, *irelaend
, *irela
;
9185 /* If there aren't any relocs, then there's nothing more
9187 if ((section
->flags
& SEC_RELOC
) == 0
9188 || (section
->flags
& SEC_ALLOC
) == 0
9189 || (section
->flags
& SEC_LOAD
) == 0
9190 || (section
->flags
& SEC_CODE
) == 0
9191 || section
->reloc_count
== 0)
9194 /* If this section is a link-once section that will be
9195 discarded, then don't create any stubs. */
9196 if (section
->output_section
== NULL
9197 || section
->output_section
->owner
!= output_bfd
)
9200 /* Get the relocs. */
9202 = _bfd_elf_link_read_relocs (input_bfd
, section
, NULL
, NULL
,
9204 if (internal_relocs
== NULL
)
9205 goto error_ret_free_local
;
9207 /* Now examine each relocation. */
9208 irela
= internal_relocs
;
9209 irelaend
= irela
+ section
->reloc_count
;
9210 for (; irela
< irelaend
; irela
++)
9212 enum elf_ppc64_reloc_type r_type
;
9213 unsigned int r_indx
;
9214 enum ppc_stub_type stub_type
;
9215 struct ppc_stub_hash_entry
*stub_entry
;
9216 asection
*sym_sec
, *code_sec
;
9218 bfd_vma destination
;
9219 bfd_boolean ok_dest
;
9220 struct ppc_link_hash_entry
*hash
;
9221 struct ppc_link_hash_entry
*fdh
;
9222 struct elf_link_hash_entry
*h
;
9223 Elf_Internal_Sym
*sym
;
9225 const asection
*id_sec
;
9228 r_type
= ELF64_R_TYPE (irela
->r_info
);
9229 r_indx
= ELF64_R_SYM (irela
->r_info
);
9231 if (r_type
>= R_PPC64_max
)
9233 bfd_set_error (bfd_error_bad_value
);
9234 goto error_ret_free_internal
;
9237 /* Only look for stubs on branch instructions. */
9238 if (r_type
!= R_PPC64_REL24
9239 && r_type
!= R_PPC64_REL14
9240 && r_type
!= R_PPC64_REL14_BRTAKEN
9241 && r_type
!= R_PPC64_REL14_BRNTAKEN
)
9244 /* Now determine the call target, its name, value,
9246 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
9248 goto error_ret_free_internal
;
9249 hash
= (struct ppc_link_hash_entry
*) h
;
9256 sym_value
= sym
->st_value
;
9259 else if (hash
->elf
.root
.type
== bfd_link_hash_defined
9260 || hash
->elf
.root
.type
== bfd_link_hash_defweak
)
9262 sym_value
= hash
->elf
.root
.u
.def
.value
;
9263 if (sym_sec
->output_section
!= NULL
)
9266 else if (hash
->elf
.root
.type
== bfd_link_hash_undefweak
9267 || hash
->elf
.root
.type
== bfd_link_hash_undefined
)
9269 /* Recognise an old ABI func code entry sym, and
9270 use the func descriptor sym instead if it is
9272 if (hash
->elf
.root
.root
.string
[0] == '.'
9273 && (fdh
= get_fdh (hash
, htab
)) != NULL
)
9275 if (fdh
->elf
.root
.type
== bfd_link_hash_defined
9276 || fdh
->elf
.root
.type
== bfd_link_hash_defweak
)
9278 sym_sec
= fdh
->elf
.root
.u
.def
.section
;
9279 sym_value
= fdh
->elf
.root
.u
.def
.value
;
9280 if (sym_sec
->output_section
!= NULL
)
9289 bfd_set_error (bfd_error_bad_value
);
9290 goto error_ret_free_internal
;
9296 sym_value
+= irela
->r_addend
;
9297 destination
= (sym_value
9298 + sym_sec
->output_offset
9299 + sym_sec
->output_section
->vma
);
9303 opd_adjust
= get_opd_info (sym_sec
);
9304 if (opd_adjust
!= NULL
)
9310 long adjust
= opd_adjust
[sym_value
/ 8];
9313 sym_value
+= adjust
;
9315 dest
= opd_entry_value (sym_sec
, sym_value
,
9316 &code_sec
, &sym_value
);
9317 if (dest
!= (bfd_vma
) -1)
9322 /* Fixup old ABI sym to point at code
9324 hash
->elf
.root
.type
= bfd_link_hash_defweak
;
9325 hash
->elf
.root
.u
.def
.section
= code_sec
;
9326 hash
->elf
.root
.u
.def
.value
= sym_value
;
9331 /* Determine what (if any) linker stub is needed. */
9332 stub_type
= ppc_type_of_stub (section
, irela
, &hash
,
9335 if (stub_type
!= ppc_stub_plt_call
)
9337 /* Check whether we need a TOC adjusting stub.
9338 Since the linker pastes together pieces from
9339 different object files when creating the
9340 _init and _fini functions, it may be that a
9341 call to what looks like a local sym is in
9342 fact a call needing a TOC adjustment. */
9343 if (code_sec
!= NULL
9344 && code_sec
->output_section
!= NULL
9345 && (htab
->stub_group
[code_sec
->id
].toc_off
9346 != htab
->stub_group
[section
->id
].toc_off
)
9347 && (code_sec
->has_toc_reloc
9348 || code_sec
->makes_toc_func_call
))
9349 stub_type
= ppc_stub_long_branch_r2off
;
9352 if (stub_type
== ppc_stub_none
)
9355 /* __tls_get_addr calls might be eliminated. */
9356 if (stub_type
!= ppc_stub_plt_call
9358 && (hash
== htab
->tls_get_addr
9359 || hash
== htab
->tls_get_addr_fd
)
9360 && section
->has_tls_reloc
9361 && irela
!= internal_relocs
)
9366 if (!get_tls_mask (&tls_mask
, NULL
, &local_syms
,
9367 irela
- 1, input_bfd
))
9368 goto error_ret_free_internal
;
9373 /* Support for grouping stub sections. */
9374 id_sec
= htab
->stub_group
[section
->id
].link_sec
;
9376 /* Get the name of this stub. */
9377 stub_name
= ppc_stub_name (id_sec
, sym_sec
, hash
, irela
);
9379 goto error_ret_free_internal
;
9381 stub_entry
= ppc_stub_hash_lookup (&htab
->stub_hash_table
,
9382 stub_name
, FALSE
, FALSE
);
9383 if (stub_entry
!= NULL
)
9385 /* The proper stub has already been created. */
9390 stub_entry
= ppc_add_stub (stub_name
, section
, htab
);
9391 if (stub_entry
== NULL
)
9394 error_ret_free_internal
:
9395 if (elf_section_data (section
)->relocs
== NULL
)
9396 free (internal_relocs
);
9397 error_ret_free_local
:
9398 if (local_syms
!= NULL
9399 && (symtab_hdr
->contents
9400 != (unsigned char *) local_syms
))
9405 stub_entry
->stub_type
= stub_type
;
9406 stub_entry
->target_value
= sym_value
;
9407 stub_entry
->target_section
= code_sec
;
9408 stub_entry
->h
= hash
;
9409 stub_entry
->addend
= irela
->r_addend
;
9411 if (stub_entry
->h
!= NULL
)
9412 htab
->stub_globals
+= 1;
9415 /* We're done with the internal relocs, free them. */
9416 if (elf_section_data (section
)->relocs
!= internal_relocs
)
9417 free (internal_relocs
);
9420 if (local_syms
!= NULL
9421 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
9423 if (!info
->keep_memory
)
9426 symtab_hdr
->contents
= (unsigned char *) local_syms
;
9430 /* We may have added some stubs. Find out the new size of the
9432 for (stub_sec
= htab
->stub_bfd
->sections
;
9434 stub_sec
= stub_sec
->next
)
9435 if ((stub_sec
->flags
& SEC_LINKER_CREATED
) == 0)
9437 stub_sec
->rawsize
= stub_sec
->size
;
9439 stub_sec
->reloc_count
= 0;
9440 stub_sec
->flags
&= ~SEC_RELOC
;
9443 htab
->brlt
->size
= 0;
9444 htab
->brlt
->reloc_count
= 0;
9445 htab
->brlt
->flags
&= ~SEC_RELOC
;
9446 if (htab
->relbrlt
!= NULL
)
9447 htab
->relbrlt
->size
= 0;
9449 bfd_hash_traverse (&htab
->stub_hash_table
, ppc_size_one_stub
, info
);
9451 for (stub_sec
= htab
->stub_bfd
->sections
;
9453 stub_sec
= stub_sec
->next
)
9454 if ((stub_sec
->flags
& SEC_LINKER_CREATED
) == 0
9455 && stub_sec
->rawsize
!= stub_sec
->size
)
9458 /* Exit from this loop when no stubs have been added, and no stubs
9459 have changed size. */
9460 if (stub_sec
== NULL
)
9463 /* Ask the linker to do its stuff. */
9464 (*htab
->layout_sections_again
) ();
9467 /* It would be nice to strip htab->brlt from the output if the
9468 section is empty, but it's too late. If we strip sections here,
9469 the dynamic symbol table is corrupted since the section symbol
9470 for the stripped section isn't written. */
9475 /* Called after we have determined section placement. If sections
9476 move, we'll be called again. Provide a value for TOCstart. */
9479 ppc64_elf_toc (bfd
*obfd
)
9484 /* The TOC consists of sections .got, .toc, .tocbss, .plt in that
9485 order. The TOC starts where the first of these sections starts. */
9486 s
= bfd_get_section_by_name (obfd
, ".got");
9488 s
= bfd_get_section_by_name (obfd
, ".toc");
9490 s
= bfd_get_section_by_name (obfd
, ".tocbss");
9492 s
= bfd_get_section_by_name (obfd
, ".plt");
9495 /* This may happen for
9496 o references to TOC base (SYM@toc / TOC[tc0]) without a
9499 o --gc-sections and empty TOC sections
9501 FIXME: Warn user? */
9503 /* Look for a likely section. We probably won't even be
9505 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
9506 if ((s
->flags
& (SEC_ALLOC
| SEC_SMALL_DATA
| SEC_READONLY
))
9507 == (SEC_ALLOC
| SEC_SMALL_DATA
))
9510 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
9511 if ((s
->flags
& (SEC_ALLOC
| SEC_SMALL_DATA
))
9512 == (SEC_ALLOC
| SEC_SMALL_DATA
))
9515 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
9516 if ((s
->flags
& (SEC_ALLOC
| SEC_READONLY
)) == SEC_ALLOC
)
9519 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
9520 if ((s
->flags
& SEC_ALLOC
) == SEC_ALLOC
)
9526 TOCstart
= s
->output_section
->vma
+ s
->output_offset
;
9531 /* Build all the stubs associated with the current output file.
9532 The stubs are kept in a hash table attached to the main linker
9533 hash table. This function is called via gldelf64ppc_finish. */
9536 ppc64_elf_build_stubs (bfd_boolean emit_stub_syms
,
9537 struct bfd_link_info
*info
,
9540 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
9543 int stub_sec_count
= 0;
9545 htab
->emit_stub_syms
= emit_stub_syms
;
9547 /* Allocate memory to hold the linker stubs. */
9548 for (stub_sec
= htab
->stub_bfd
->sections
;
9550 stub_sec
= stub_sec
->next
)
9551 if ((stub_sec
->flags
& SEC_LINKER_CREATED
) == 0
9552 && stub_sec
->size
!= 0)
9554 stub_sec
->contents
= bfd_zalloc (htab
->stub_bfd
, stub_sec
->size
);
9555 if (stub_sec
->contents
== NULL
)
9557 /* We want to check that built size is the same as calculated
9558 size. rawsize is a convenient location to use. */
9559 stub_sec
->rawsize
= stub_sec
->size
;
9563 if (htab
->glink
!= NULL
&& htab
->glink
->size
!= 0)
9568 /* Build the .glink plt call stub. */
9569 if (htab
->emit_stub_syms
)
9571 struct elf_link_hash_entry
*h
;
9572 h
= elf_link_hash_lookup (&htab
->elf
, "__glink", TRUE
, FALSE
, FALSE
);
9575 if (h
->root
.type
== bfd_link_hash_new
)
9577 h
->root
.type
= bfd_link_hash_defined
;
9578 h
->root
.u
.def
.section
= htab
->glink
;
9579 h
->root
.u
.def
.value
= 8;
9582 h
->ref_regular_nonweak
= 1;
9583 h
->forced_local
= 1;
9587 p
= htab
->glink
->contents
;
9588 plt0
= (htab
->plt
->output_section
->vma
9589 + htab
->plt
->output_offset
9590 - (htab
->glink
->output_section
->vma
9591 + htab
->glink
->output_offset
9593 bfd_put_64 (htab
->glink
->owner
, plt0
, p
);
9595 bfd_put_32 (htab
->glink
->owner
, MFLR_R12
, p
);
9597 bfd_put_32 (htab
->glink
->owner
, BCL_20_31
, p
);
9599 bfd_put_32 (htab
->glink
->owner
, MFLR_R11
, p
);
9601 bfd_put_32 (htab
->glink
->owner
, LD_R2_M16R11
, p
);
9603 bfd_put_32 (htab
->glink
->owner
, MTLR_R12
, p
);
9605 bfd_put_32 (htab
->glink
->owner
, ADD_R12_R2_R11
, p
);
9607 bfd_put_32 (htab
->glink
->owner
, LD_R11_0R12
, p
);
9609 bfd_put_32 (htab
->glink
->owner
, LD_R2_0R12
| 8, p
);
9611 bfd_put_32 (htab
->glink
->owner
, MTCTR_R11
, p
);
9613 bfd_put_32 (htab
->glink
->owner
, LD_R11_0R12
| 16, p
);
9615 bfd_put_32 (htab
->glink
->owner
, BCTR
, p
);
9617 while (p
- htab
->glink
->contents
< GLINK_CALL_STUB_SIZE
)
9619 bfd_put_32 (htab
->glink
->owner
, NOP
, p
);
9623 /* Build the .glink lazy link call stubs. */
9625 while (p
< htab
->glink
->contents
+ htab
->glink
->size
)
9629 bfd_put_32 (htab
->glink
->owner
, LI_R0_0
| indx
, p
);
9634 bfd_put_32 (htab
->glink
->owner
, LIS_R0_0
| PPC_HI (indx
), p
);
9636 bfd_put_32 (htab
->glink
->owner
, ORI_R0_R0_0
| PPC_LO (indx
), p
);
9639 bfd_put_32 (htab
->glink
->owner
,
9640 B_DOT
| ((htab
->glink
->contents
- p
+ 8) & 0x3fffffc), p
);
9644 htab
->glink
->rawsize
= p
- htab
->glink
->contents
;
9647 if (htab
->brlt
->size
!= 0)
9649 htab
->brlt
->contents
= bfd_zalloc (htab
->brlt
->owner
,
9651 if (htab
->brlt
->contents
== NULL
)
9654 if (htab
->relbrlt
!= NULL
&& htab
->relbrlt
->size
!= 0)
9656 htab
->relbrlt
->contents
= bfd_zalloc (htab
->relbrlt
->owner
,
9657 htab
->relbrlt
->size
);
9658 if (htab
->relbrlt
->contents
== NULL
)
9662 /* Build the stubs as directed by the stub hash table. */
9663 bfd_hash_traverse (&htab
->stub_hash_table
, ppc_build_one_stub
, info
);
9665 if (htab
->relbrlt
!= NULL
)
9666 htab
->relbrlt
->reloc_count
= 0;
9668 for (stub_sec
= htab
->stub_bfd
->sections
;
9670 stub_sec
= stub_sec
->next
)
9671 if ((stub_sec
->flags
& SEC_LINKER_CREATED
) == 0)
9673 stub_sec_count
+= 1;
9674 if (stub_sec
->rawsize
!= stub_sec
->size
)
9678 if (stub_sec
!= NULL
9679 || htab
->glink
->rawsize
!= htab
->glink
->size
)
9681 htab
->stub_error
= TRUE
;
9682 (*_bfd_error_handler
) (_("stubs don't match calculated size"));
9685 if (htab
->stub_error
)
9690 *stats
= bfd_malloc (500);
9694 sprintf (*stats
, _("linker stubs in %u group%s\n"
9697 " long branch %lu\n"
9698 " long toc adj %lu\n"
9701 stub_sec_count
== 1 ? "" : "s",
9702 htab
->stub_count
[ppc_stub_long_branch
- 1],
9703 htab
->stub_count
[ppc_stub_long_branch_r2off
- 1],
9704 htab
->stub_count
[ppc_stub_plt_branch
- 1],
9705 htab
->stub_count
[ppc_stub_plt_branch_r2off
- 1],
9706 htab
->stub_count
[ppc_stub_plt_call
- 1]);
9711 /* This function undoes the changes made by add_symbol_adjust. */
9714 undo_symbol_twiddle (struct elf_link_hash_entry
*h
, void *inf ATTRIBUTE_UNUSED
)
9716 struct ppc_link_hash_entry
*eh
;
9718 if (h
->root
.type
== bfd_link_hash_indirect
)
9721 if (h
->root
.type
== bfd_link_hash_warning
)
9722 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
9724 eh
= (struct ppc_link_hash_entry
*) h
;
9725 if (eh
->elf
.root
.type
!= bfd_link_hash_undefweak
|| !eh
->was_undefined
)
9728 eh
->elf
.root
.type
= bfd_link_hash_undefined
;
9733 ppc64_elf_restore_symbols (struct bfd_link_info
*info
)
9735 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
9736 elf_link_hash_traverse (&htab
->elf
, undo_symbol_twiddle
, info
);
9739 /* What to do when ld finds relocations against symbols defined in
9740 discarded sections. */
9743 ppc64_elf_action_discarded (asection
*sec
)
9745 if (strcmp (".opd", sec
->name
) == 0)
9748 if (strcmp (".toc", sec
->name
) == 0)
9751 if (strcmp (".toc1", sec
->name
) == 0)
9754 return _bfd_elf_default_action_discarded (sec
);
9757 /* The RELOCATE_SECTION function is called by the ELF backend linker
9758 to handle the relocations for a section.
9760 The relocs are always passed as Rela structures; if the section
9761 actually uses Rel structures, the r_addend field will always be
9764 This function is responsible for adjust the section contents as
9765 necessary, and (if using Rela relocs and generating a
9766 relocatable output file) adjusting the reloc addend as
9769 This function does not have to worry about setting the reloc
9770 address or the reloc symbol index.
9772 LOCAL_SYMS is a pointer to the swapped in local symbols.
9774 LOCAL_SECTIONS is an array giving the section in the input file
9775 corresponding to the st_shndx field of each local symbol.
9777 The global hash table entry for the global symbols can be found
9778 via elf_sym_hashes (input_bfd).
9780 When generating relocatable output, this function must handle
9781 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
9782 going to be the section symbol corresponding to the output
9783 section, which means that the addend must be adjusted
9787 ppc64_elf_relocate_section (bfd
*output_bfd
,
9788 struct bfd_link_info
*info
,
9790 asection
*input_section
,
9792 Elf_Internal_Rela
*relocs
,
9793 Elf_Internal_Sym
*local_syms
,
9794 asection
**local_sections
)
9796 struct ppc_link_hash_table
*htab
;
9797 Elf_Internal_Shdr
*symtab_hdr
;
9798 struct elf_link_hash_entry
**sym_hashes
;
9799 Elf_Internal_Rela
*rel
;
9800 Elf_Internal_Rela
*relend
;
9801 Elf_Internal_Rela outrel
;
9803 struct got_entry
**local_got_ents
;
9805 bfd_boolean ret
= TRUE
;
9807 /* Disabled until we sort out how ld should choose 'y' vs 'at'. */
9808 bfd_boolean is_power4
= FALSE
;
9809 bfd_vma d_offset
= (bfd_big_endian (output_bfd
) ? 2 : 0);
9811 /* Initialize howto table if needed. */
9812 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
9815 htab
= ppc_hash_table (info
);
9817 /* Don't relocate stub sections. */
9818 if (input_section
->owner
== htab
->stub_bfd
)
9821 local_got_ents
= elf_local_got_ents (input_bfd
);
9822 TOCstart
= elf_gp (output_bfd
);
9823 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
9824 sym_hashes
= elf_sym_hashes (input_bfd
);
9825 is_opd
= ppc64_elf_section_data (input_section
)->sec_type
== sec_opd
;
9828 relend
= relocs
+ input_section
->reloc_count
;
9829 for (; rel
< relend
; rel
++)
9831 enum elf_ppc64_reloc_type r_type
;
9832 bfd_vma addend
, orig_addend
;
9833 bfd_reloc_status_type r
;
9834 Elf_Internal_Sym
*sym
;
9836 struct elf_link_hash_entry
*h_elf
;
9837 struct ppc_link_hash_entry
*h
;
9838 struct ppc_link_hash_entry
*fdh
;
9839 const char *sym_name
;
9840 unsigned long r_symndx
, toc_symndx
;
9841 char tls_mask
, tls_gd
, tls_type
;
9844 bfd_boolean unresolved_reloc
;
9846 unsigned long insn
, mask
;
9847 struct ppc_stub_hash_entry
*stub_entry
;
9848 bfd_vma max_br_offset
;
9851 r_type
= ELF64_R_TYPE (rel
->r_info
);
9852 r_symndx
= ELF64_R_SYM (rel
->r_info
);
9854 /* For old style R_PPC64_TOC relocs with a zero symbol, use the
9855 symbol of the previous ADDR64 reloc. The symbol gives us the
9856 proper TOC base to use. */
9857 if (rel
->r_info
== ELF64_R_INFO (0, R_PPC64_TOC
)
9859 && ELF64_R_TYPE (rel
[-1].r_info
) == R_PPC64_ADDR64
9861 r_symndx
= ELF64_R_SYM (rel
[-1].r_info
);
9867 unresolved_reloc
= FALSE
;
9869 orig_addend
= rel
->r_addend
;
9871 if (r_symndx
< symtab_hdr
->sh_info
)
9873 /* It's a local symbol. */
9876 sym
= local_syms
+ r_symndx
;
9877 sec
= local_sections
[r_symndx
];
9878 sym_name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, sym
, sec
);
9879 sym_type
= ELF64_ST_TYPE (sym
->st_info
);
9880 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
9881 opd_adjust
= get_opd_info (sec
);
9882 if (opd_adjust
!= NULL
)
9884 long adjust
= opd_adjust
[(sym
->st_value
+ rel
->r_addend
) / 8];
9889 /* If this is a relocation against the opd section sym
9890 and we have edited .opd, adjust the reloc addend so
9891 that ld -r and ld --emit-relocs output is correct.
9892 If it is a reloc against some other .opd symbol,
9893 then the symbol value will be adjusted later. */
9894 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
9895 rel
->r_addend
+= adjust
;
9897 relocation
+= adjust
;
9903 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
9904 r_symndx
, symtab_hdr
, sym_hashes
,
9905 h_elf
, sec
, relocation
,
9906 unresolved_reloc
, warned
);
9907 sym_name
= h_elf
->root
.root
.string
;
9908 sym_type
= h_elf
->type
;
9910 h
= (struct ppc_link_hash_entry
*) h_elf
;
9912 if (sec
!= NULL
&& elf_discarded_section (sec
))
9914 /* For relocs against symbols from removed linkonce sections,
9915 or sections discarded by a linker script, we just want the
9916 section contents zeroed. Avoid any special processing. */
9917 _bfd_clear_contents (ppc64_elf_howto_table
[r_type
], input_bfd
,
9918 contents
+ rel
->r_offset
);
9924 if (info
->relocatable
)
9927 /* TLS optimizations. Replace instruction sequences and relocs
9928 based on information we collected in tls_optimize. We edit
9929 RELOCS so that --emit-relocs will output something sensible
9930 for the final instruction stream. */
9934 if (IS_PPC64_TLS_RELOC (r_type
))
9937 tls_mask
= h
->tls_mask
;
9938 else if (local_got_ents
!= NULL
)
9941 lgot_masks
= (char *) (local_got_ents
+ symtab_hdr
->sh_info
);
9942 tls_mask
= lgot_masks
[r_symndx
];
9944 if (tls_mask
== 0 && r_type
== R_PPC64_TLS
)
9946 /* Check for toc tls entries. */
9949 if (!get_tls_mask (&toc_tls
, &toc_symndx
, &local_syms
,
9954 tls_mask
= *toc_tls
;
9958 /* Check that tls relocs are used with tls syms, and non-tls
9959 relocs are used with non-tls syms. */
9961 && r_type
!= R_PPC64_NONE
9963 || h
->elf
.root
.type
== bfd_link_hash_defined
9964 || h
->elf
.root
.type
== bfd_link_hash_defweak
)
9965 && IS_PPC64_TLS_RELOC (r_type
) != (sym_type
== STT_TLS
))
9967 if (r_type
== R_PPC64_TLS
&& tls_mask
!= 0)
9968 /* R_PPC64_TLS is OK against a symbol in the TOC. */
9971 (*_bfd_error_handler
)
9972 (sym_type
== STT_TLS
9973 ? _("%B(%A+0x%lx): %s used with TLS symbol %s")
9974 : _("%B(%A+0x%lx): %s used with non-TLS symbol %s"),
9977 (long) rel
->r_offset
,
9978 ppc64_elf_howto_table
[r_type
]->name
,
9982 /* Ensure reloc mapping code below stays sane. */
9983 if (R_PPC64_TOC16_LO_DS
!= R_PPC64_TOC16_DS
+ 1
9984 || R_PPC64_TOC16_LO
!= R_PPC64_TOC16
+ 1
9985 || (R_PPC64_GOT_TLSLD16
& 3) != (R_PPC64_GOT_TLSGD16
& 3)
9986 || (R_PPC64_GOT_TLSLD16_LO
& 3) != (R_PPC64_GOT_TLSGD16_LO
& 3)
9987 || (R_PPC64_GOT_TLSLD16_HI
& 3) != (R_PPC64_GOT_TLSGD16_HI
& 3)
9988 || (R_PPC64_GOT_TLSLD16_HA
& 3) != (R_PPC64_GOT_TLSGD16_HA
& 3)
9989 || (R_PPC64_GOT_TLSLD16
& 3) != (R_PPC64_GOT_TPREL16_DS
& 3)
9990 || (R_PPC64_GOT_TLSLD16_LO
& 3) != (R_PPC64_GOT_TPREL16_LO_DS
& 3)
9991 || (R_PPC64_GOT_TLSLD16_HI
& 3) != (R_PPC64_GOT_TPREL16_HI
& 3)
9992 || (R_PPC64_GOT_TLSLD16_HA
& 3) != (R_PPC64_GOT_TPREL16_HA
& 3))
10000 case R_PPC64_TOC16
:
10001 case R_PPC64_TOC16_LO
:
10002 case R_PPC64_TOC16_DS
:
10003 case R_PPC64_TOC16_LO_DS
:
10005 /* Check for toc tls entries. */
10009 retval
= get_tls_mask (&toc_tls
, &toc_symndx
, &local_syms
,
10016 tls_mask
= *toc_tls
;
10017 if (r_type
== R_PPC64_TOC16_DS
10018 || r_type
== R_PPC64_TOC16_LO_DS
)
10021 && (tls_mask
& (TLS_DTPREL
| TLS_TPREL
)) == 0)
10026 /* If we found a GD reloc pair, then we might be
10027 doing a GD->IE transition. */
10030 tls_gd
= TLS_TPRELGD
;
10031 if (tls_mask
!= 0 && (tls_mask
& TLS_GD
) == 0)
10032 goto tls_get_addr_check
;
10034 else if (retval
== 3)
10036 if (tls_mask
!= 0 && (tls_mask
& TLS_LD
) == 0)
10037 goto tls_get_addr_check
;
10044 case R_PPC64_GOT_TPREL16_DS
:
10045 case R_PPC64_GOT_TPREL16_LO_DS
:
10047 && (tls_mask
& TLS_TPREL
) == 0)
10050 insn
= bfd_get_32 (output_bfd
, contents
+ rel
->r_offset
- d_offset
);
10052 insn
|= 0x3c0d0000; /* addis 0,13,0 */
10053 bfd_put_32 (output_bfd
, insn
, contents
+ rel
->r_offset
- d_offset
);
10054 r_type
= R_PPC64_TPREL16_HA
;
10055 if (toc_symndx
!= 0)
10057 rel
->r_info
= ELF64_R_INFO (toc_symndx
, r_type
);
10058 /* We changed the symbol. Start over in order to
10059 get h, sym, sec etc. right. */
10064 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
10070 && (tls_mask
& TLS_TPREL
) == 0)
10073 insn
= bfd_get_32 (output_bfd
, contents
+ rel
->r_offset
);
10074 if ((insn
& ((0x3f << 26) | (31 << 11)))
10075 == ((31 << 26) | (13 << 11)))
10076 rtra
= insn
& ((1 << 26) - (1 << 16));
10077 else if ((insn
& ((0x3f << 26) | (31 << 16)))
10078 == ((31 << 26) | (13 << 16)))
10079 rtra
= (insn
& (31 << 21)) | ((insn
& (31 << 11)) << 5);
10082 if ((insn
& ((1 << 11) - (1 << 1))) == 266 << 1)
10085 else if ((insn
& (31 << 1)) == 23 << 1
10086 && ((insn
& (31 << 6)) < 14 << 6
10087 || ((insn
& (31 << 6)) >= 16 << 6
10088 && (insn
& (31 << 6)) < 24 << 6)))
10089 /* load and store indexed -> dform. */
10090 insn
= (32 | ((insn
>> 6) & 31)) << 26;
10091 else if ((insn
& (31 << 1)) == 21 << 1
10092 && (insn
& (0x1a << 6)) == 0)
10093 /* ldx, ldux, stdx, stdux -> ld, ldu, std, stdu. */
10094 insn
= (((58 | ((insn
>> 6) & 4)) << 26)
10095 | ((insn
>> 6) & 1));
10096 else if ((insn
& (31 << 1)) == 21 << 1
10097 && (insn
& ((1 << 11) - (1 << 1))) == 341 << 1)
10099 insn
= (58 << 26) | 2;
10103 bfd_put_32 (output_bfd
, insn
, contents
+ rel
->r_offset
);
10104 /* Was PPC64_TLS which sits on insn boundary, now
10105 PPC64_TPREL16_LO which is at low-order half-word. */
10106 rel
->r_offset
+= d_offset
;
10107 r_type
= R_PPC64_TPREL16_LO
;
10108 if (toc_symndx
!= 0)
10110 rel
->r_info
= ELF64_R_INFO (toc_symndx
, r_type
);
10111 /* We changed the symbol. Start over in order to
10112 get h, sym, sec etc. right. */
10117 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
10121 case R_PPC64_GOT_TLSGD16_HI
:
10122 case R_PPC64_GOT_TLSGD16_HA
:
10123 tls_gd
= TLS_TPRELGD
;
10124 if (tls_mask
!= 0 && (tls_mask
& TLS_GD
) == 0)
10128 case R_PPC64_GOT_TLSLD16_HI
:
10129 case R_PPC64_GOT_TLSLD16_HA
:
10130 if (tls_mask
!= 0 && (tls_mask
& TLS_LD
) == 0)
10133 if ((tls_mask
& tls_gd
) != 0)
10134 r_type
= (((r_type
- (R_PPC64_GOT_TLSGD16
& 3)) & 3)
10135 + R_PPC64_GOT_TPREL16_DS
);
10138 bfd_put_32 (output_bfd
, NOP
, contents
+ rel
->r_offset
);
10139 rel
->r_offset
-= d_offset
;
10140 r_type
= R_PPC64_NONE
;
10142 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
10146 case R_PPC64_GOT_TLSGD16
:
10147 case R_PPC64_GOT_TLSGD16_LO
:
10148 tls_gd
= TLS_TPRELGD
;
10149 if (tls_mask
!= 0 && (tls_mask
& TLS_GD
) == 0)
10150 goto tls_get_addr_check
;
10153 case R_PPC64_GOT_TLSLD16
:
10154 case R_PPC64_GOT_TLSLD16_LO
:
10155 if (tls_mask
!= 0 && (tls_mask
& TLS_LD
) == 0)
10157 tls_get_addr_check
:
10158 if (rel
+ 1 < relend
)
10160 enum elf_ppc64_reloc_type r_type2
;
10161 unsigned long r_symndx2
;
10162 struct elf_link_hash_entry
*h2
;
10163 bfd_vma insn1
, insn2
, insn3
;
10166 /* The next instruction should be a call to
10167 __tls_get_addr. Peek at the reloc to be sure. */
10168 r_type2
= ELF64_R_TYPE (rel
[1].r_info
);
10169 r_symndx2
= ELF64_R_SYM (rel
[1].r_info
);
10170 if (r_symndx2
< symtab_hdr
->sh_info
10171 || (r_type2
!= R_PPC64_REL14
10172 && r_type2
!= R_PPC64_REL14_BRTAKEN
10173 && r_type2
!= R_PPC64_REL14_BRNTAKEN
10174 && r_type2
!= R_PPC64_REL24
))
10177 h2
= sym_hashes
[r_symndx2
- symtab_hdr
->sh_info
];
10178 while (h2
->root
.type
== bfd_link_hash_indirect
10179 || h2
->root
.type
== bfd_link_hash_warning
)
10180 h2
= (struct elf_link_hash_entry
*) h2
->root
.u
.i
.link
;
10181 if (h2
== NULL
|| (h2
!= &htab
->tls_get_addr
->elf
10182 && h2
!= &htab
->tls_get_addr_fd
->elf
))
10185 /* OK, it checks out. Replace the call. */
10186 offset
= rel
[1].r_offset
;
10187 insn1
= bfd_get_32 (output_bfd
,
10188 contents
+ rel
->r_offset
- d_offset
);
10189 insn3
= bfd_get_32 (output_bfd
,
10190 contents
+ offset
+ 4);
10191 if ((tls_mask
& tls_gd
) != 0)
10194 insn1
&= (1 << 26) - (1 << 2);
10195 insn1
|= 58 << 26; /* ld */
10196 insn2
= 0x7c636a14; /* add 3,3,13 */
10197 rel
[1].r_info
= ELF64_R_INFO (r_symndx2
, R_PPC64_NONE
);
10198 if ((tls_mask
& TLS_EXPLICIT
) == 0)
10199 r_type
= (((r_type
- (R_PPC64_GOT_TLSGD16
& 3)) & 3)
10200 + R_PPC64_GOT_TPREL16_DS
);
10202 r_type
+= R_PPC64_TOC16_DS
- R_PPC64_TOC16
;
10203 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
10208 insn1
= 0x3c6d0000; /* addis 3,13,0 */
10209 insn2
= 0x38630000; /* addi 3,3,0 */
10212 /* Was an LD reloc. */
10214 rel
->r_addend
= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
10215 rel
[1].r_addend
= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
10217 else if (toc_symndx
!= 0)
10218 r_symndx
= toc_symndx
;
10219 r_type
= R_PPC64_TPREL16_HA
;
10220 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
10221 rel
[1].r_info
= ELF64_R_INFO (r_symndx
,
10222 R_PPC64_TPREL16_LO
);
10223 rel
[1].r_offset
+= d_offset
;
10226 || insn3
== CROR_151515
|| insn3
== CROR_313131
)
10230 rel
[1].r_offset
+= 4;
10232 bfd_put_32 (output_bfd
, insn1
, contents
+ rel
->r_offset
- d_offset
);
10233 bfd_put_32 (output_bfd
, insn2
, contents
+ offset
);
10234 bfd_put_32 (output_bfd
, insn3
, contents
+ offset
+ 4);
10235 if (tls_gd
== 0 || toc_symndx
!= 0)
10237 /* We changed the symbol. Start over in order
10238 to get h, sym, sec etc. right. */
10246 case R_PPC64_DTPMOD64
:
10247 if (rel
+ 1 < relend
10248 && rel
[1].r_info
== ELF64_R_INFO (r_symndx
, R_PPC64_DTPREL64
)
10249 && rel
[1].r_offset
== rel
->r_offset
+ 8)
10251 if ((tls_mask
& TLS_GD
) == 0)
10253 rel
[1].r_info
= ELF64_R_INFO (r_symndx
, R_PPC64_NONE
);
10254 if ((tls_mask
& TLS_TPRELGD
) != 0)
10255 r_type
= R_PPC64_TPREL64
;
10258 bfd_put_64 (output_bfd
, 1, contents
+ rel
->r_offset
);
10259 r_type
= R_PPC64_NONE
;
10261 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
10266 if ((tls_mask
& TLS_LD
) == 0)
10268 bfd_put_64 (output_bfd
, 1, contents
+ rel
->r_offset
);
10269 r_type
= R_PPC64_NONE
;
10270 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
10275 case R_PPC64_TPREL64
:
10276 if ((tls_mask
& TLS_TPREL
) == 0)
10278 r_type
= R_PPC64_NONE
;
10279 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
10284 /* Handle other relocations that tweak non-addend part of insn. */
10286 max_br_offset
= 1 << 25;
10287 addend
= rel
->r_addend
;
10293 /* Branch taken prediction relocations. */
10294 case R_PPC64_ADDR14_BRTAKEN
:
10295 case R_PPC64_REL14_BRTAKEN
:
10296 insn
= 0x01 << 21; /* 'y' or 't' bit, lowest bit of BO field. */
10299 /* Branch not taken prediction relocations. */
10300 case R_PPC64_ADDR14_BRNTAKEN
:
10301 case R_PPC64_REL14_BRNTAKEN
:
10302 insn
|= bfd_get_32 (output_bfd
,
10303 contents
+ rel
->r_offset
) & ~(0x01 << 21);
10306 case R_PPC64_REL14
:
10307 max_br_offset
= 1 << 15;
10310 case R_PPC64_REL24
:
10311 /* Calls to functions with a different TOC, such as calls to
10312 shared objects, need to alter the TOC pointer. This is
10313 done using a linkage stub. A REL24 branching to these
10314 linkage stubs needs to be followed by a nop, as the nop
10315 will be replaced with an instruction to restore the TOC
10320 && (((fdh
= h
->oh
) != NULL
10321 && fdh
->elf
.plt
.plist
!= NULL
)
10322 || (fdh
= h
)->elf
.plt
.plist
!= NULL
))
10324 && sec
->output_section
!= NULL
10325 && sec
->id
<= htab
->top_id
10326 && (htab
->stub_group
[sec
->id
].toc_off
10327 != htab
->stub_group
[input_section
->id
].toc_off
)))
10328 && (stub_entry
= ppc_get_stub_entry (input_section
, sec
, fdh
,
10329 rel
, htab
)) != NULL
10330 && (stub_entry
->stub_type
== ppc_stub_plt_call
10331 || stub_entry
->stub_type
== ppc_stub_plt_branch_r2off
10332 || stub_entry
->stub_type
== ppc_stub_long_branch_r2off
))
10334 bfd_boolean can_plt_call
= FALSE
;
10336 if (rel
->r_offset
+ 8 <= input_section
->size
)
10339 nop
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
+ 4);
10341 || nop
== CROR_151515
|| nop
== CROR_313131
)
10343 bfd_put_32 (input_bfd
, LD_R2_40R1
,
10344 contents
+ rel
->r_offset
+ 4);
10345 can_plt_call
= TRUE
;
10351 if (stub_entry
->stub_type
== ppc_stub_plt_call
)
10353 /* If this is a plain branch rather than a branch
10354 and link, don't require a nop. However, don't
10355 allow tail calls in a shared library as they
10356 will result in r2 being corrupted. */
10358 br
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
10359 if (info
->executable
&& (br
& 1) == 0)
10360 can_plt_call
= TRUE
;
10365 && strcmp (h
->elf
.root
.root
.string
,
10366 ".__libc_start_main") == 0)
10368 /* Allow crt1 branch to go via a toc adjusting stub. */
10369 can_plt_call
= TRUE
;
10373 if (strcmp (input_section
->output_section
->name
,
10375 || strcmp (input_section
->output_section
->name
,
10377 (*_bfd_error_handler
)
10378 (_("%B(%A+0x%lx): automatic multiple TOCs "
10379 "not supported using your crt files; "
10380 "recompile with -mminimal-toc or upgrade gcc"),
10383 (long) rel
->r_offset
);
10385 (*_bfd_error_handler
)
10386 (_("%B(%A+0x%lx): sibling call optimization to `%s' "
10387 "does not allow automatic multiple TOCs; "
10388 "recompile with -mminimal-toc or "
10389 "-fno-optimize-sibling-calls, "
10390 "or make `%s' extern"),
10393 (long) rel
->r_offset
,
10396 bfd_set_error (bfd_error_bad_value
);
10402 && stub_entry
->stub_type
== ppc_stub_plt_call
)
10403 unresolved_reloc
= FALSE
;
10406 if (stub_entry
== NULL
10407 && get_opd_info (sec
) != NULL
)
10409 /* The branch destination is the value of the opd entry. */
10410 bfd_vma off
= (relocation
+ addend
10411 - sec
->output_section
->vma
10412 - sec
->output_offset
);
10413 bfd_vma dest
= opd_entry_value (sec
, off
, NULL
, NULL
);
10414 if (dest
!= (bfd_vma
) -1)
10421 /* If the branch is out of reach we ought to have a long
10423 from
= (rel
->r_offset
10424 + input_section
->output_offset
10425 + input_section
->output_section
->vma
);
10427 if (stub_entry
== NULL
10428 && (relocation
+ addend
- from
+ max_br_offset
10429 >= 2 * max_br_offset
)
10430 && r_type
!= R_PPC64_ADDR14_BRTAKEN
10431 && r_type
!= R_PPC64_ADDR14_BRNTAKEN
)
10432 stub_entry
= ppc_get_stub_entry (input_section
, sec
, h
, rel
,
10435 if (stub_entry
!= NULL
)
10437 /* Munge up the value and addend so that we call the stub
10438 rather than the procedure directly. */
10439 relocation
= (stub_entry
->stub_offset
10440 + stub_entry
->stub_sec
->output_offset
10441 + stub_entry
->stub_sec
->output_section
->vma
);
10449 /* Set 'a' bit. This is 0b00010 in BO field for branch
10450 on CR(BI) insns (BO == 001at or 011at), and 0b01000
10451 for branch on CTR insns (BO == 1a00t or 1a01t). */
10452 if ((insn
& (0x14 << 21)) == (0x04 << 21))
10453 insn
|= 0x02 << 21;
10454 else if ((insn
& (0x14 << 21)) == (0x10 << 21))
10455 insn
|= 0x08 << 21;
10461 /* Invert 'y' bit if not the default. */
10462 if ((bfd_signed_vma
) (relocation
+ addend
- from
) < 0)
10463 insn
^= 0x01 << 21;
10466 bfd_put_32 (output_bfd
, insn
, contents
+ rel
->r_offset
);
10469 /* NOP out calls to undefined weak functions.
10470 We can thus call a weak function without first
10471 checking whether the function is defined. */
10473 && h
->elf
.root
.type
== bfd_link_hash_undefweak
10474 && r_type
== R_PPC64_REL24
10478 bfd_put_32 (output_bfd
, NOP
, contents
+ rel
->r_offset
);
10484 /* Set `addend'. */
10489 (*_bfd_error_handler
)
10490 (_("%B: unknown relocation type %d for symbol %s"),
10491 input_bfd
, (int) r_type
, sym_name
);
10493 bfd_set_error (bfd_error_bad_value
);
10499 case R_PPC64_GNU_VTINHERIT
:
10500 case R_PPC64_GNU_VTENTRY
:
10503 /* GOT16 relocations. Like an ADDR16 using the symbol's
10504 address in the GOT as relocation value instead of the
10505 symbol's value itself. Also, create a GOT entry for the
10506 symbol and put the symbol value there. */
10507 case R_PPC64_GOT_TLSGD16
:
10508 case R_PPC64_GOT_TLSGD16_LO
:
10509 case R_PPC64_GOT_TLSGD16_HI
:
10510 case R_PPC64_GOT_TLSGD16_HA
:
10511 tls_type
= TLS_TLS
| TLS_GD
;
10514 case R_PPC64_GOT_TLSLD16
:
10515 case R_PPC64_GOT_TLSLD16_LO
:
10516 case R_PPC64_GOT_TLSLD16_HI
:
10517 case R_PPC64_GOT_TLSLD16_HA
:
10518 tls_type
= TLS_TLS
| TLS_LD
;
10521 case R_PPC64_GOT_TPREL16_DS
:
10522 case R_PPC64_GOT_TPREL16_LO_DS
:
10523 case R_PPC64_GOT_TPREL16_HI
:
10524 case R_PPC64_GOT_TPREL16_HA
:
10525 tls_type
= TLS_TLS
| TLS_TPREL
;
10528 case R_PPC64_GOT_DTPREL16_DS
:
10529 case R_PPC64_GOT_DTPREL16_LO_DS
:
10530 case R_PPC64_GOT_DTPREL16_HI
:
10531 case R_PPC64_GOT_DTPREL16_HA
:
10532 tls_type
= TLS_TLS
| TLS_DTPREL
;
10535 case R_PPC64_GOT16
:
10536 case R_PPC64_GOT16_LO
:
10537 case R_PPC64_GOT16_HI
:
10538 case R_PPC64_GOT16_HA
:
10539 case R_PPC64_GOT16_DS
:
10540 case R_PPC64_GOT16_LO_DS
:
10543 /* Relocation is to the entry for this symbol in the global
10548 unsigned long indx
= 0;
10550 if (tls_type
== (TLS_TLS
| TLS_LD
)
10552 || !h
->elf
.def_dynamic
))
10553 offp
= &ppc64_tlsld_got (input_bfd
)->offset
;
10556 struct got_entry
*ent
;
10560 bfd_boolean dyn
= htab
->elf
.dynamic_sections_created
;
10561 if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
,
10564 && SYMBOL_REFERENCES_LOCAL (info
, &h
->elf
)))
10565 /* This is actually a static link, or it is a
10566 -Bsymbolic link and the symbol is defined
10567 locally, or the symbol was forced to be local
10568 because of a version file. */
10572 indx
= h
->elf
.dynindx
;
10573 unresolved_reloc
= FALSE
;
10575 ent
= h
->elf
.got
.glist
;
10579 if (local_got_ents
== NULL
)
10581 ent
= local_got_ents
[r_symndx
];
10584 for (; ent
!= NULL
; ent
= ent
->next
)
10585 if (ent
->addend
== orig_addend
10586 && ent
->owner
== input_bfd
10587 && ent
->tls_type
== tls_type
)
10591 offp
= &ent
->got
.offset
;
10594 got
= ppc64_elf_tdata (input_bfd
)->got
;
10598 /* The offset must always be a multiple of 8. We use the
10599 least significant bit to record whether we have already
10600 processed this entry. */
10602 if ((off
& 1) != 0)
10606 /* Generate relocs for the dynamic linker, except in
10607 the case of TLSLD where we'll use one entry per
10609 asection
*relgot
= ppc64_elf_tdata (input_bfd
)->relgot
;
10612 if ((info
->shared
|| indx
!= 0)
10614 || ELF_ST_VISIBILITY (h
->elf
.other
) == STV_DEFAULT
10615 || h
->elf
.root
.type
!= bfd_link_hash_undefweak
))
10617 outrel
.r_offset
= (got
->output_section
->vma
10618 + got
->output_offset
10620 outrel
.r_addend
= addend
;
10621 if (tls_type
& (TLS_LD
| TLS_GD
))
10623 outrel
.r_addend
= 0;
10624 outrel
.r_info
= ELF64_R_INFO (indx
, R_PPC64_DTPMOD64
);
10625 if (tls_type
== (TLS_TLS
| TLS_GD
))
10627 loc
= relgot
->contents
;
10628 loc
+= (relgot
->reloc_count
++
10629 * sizeof (Elf64_External_Rela
));
10630 bfd_elf64_swap_reloca_out (output_bfd
,
10632 outrel
.r_offset
+= 8;
10633 outrel
.r_addend
= addend
;
10635 = ELF64_R_INFO (indx
, R_PPC64_DTPREL64
);
10638 else if (tls_type
== (TLS_TLS
| TLS_DTPREL
))
10639 outrel
.r_info
= ELF64_R_INFO (indx
, R_PPC64_DTPREL64
);
10640 else if (tls_type
== (TLS_TLS
| TLS_TPREL
))
10641 outrel
.r_info
= ELF64_R_INFO (indx
, R_PPC64_TPREL64
);
10642 else if (indx
== 0)
10644 outrel
.r_info
= ELF64_R_INFO (indx
, R_PPC64_RELATIVE
);
10646 /* Write the .got section contents for the sake
10648 loc
= got
->contents
+ off
;
10649 bfd_put_64 (output_bfd
, outrel
.r_addend
+ relocation
,
10653 outrel
.r_info
= ELF64_R_INFO (indx
, R_PPC64_GLOB_DAT
);
10655 if (indx
== 0 && tls_type
!= (TLS_TLS
| TLS_LD
))
10657 outrel
.r_addend
+= relocation
;
10658 if (tls_type
& (TLS_GD
| TLS_DTPREL
| TLS_TPREL
))
10659 outrel
.r_addend
-= htab
->elf
.tls_sec
->vma
;
10661 loc
= relgot
->contents
;
10662 loc
+= (relgot
->reloc_count
++
10663 * sizeof (Elf64_External_Rela
));
10664 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
10667 /* Init the .got section contents here if we're not
10668 emitting a reloc. */
10671 relocation
+= addend
;
10672 if (tls_type
== (TLS_TLS
| TLS_LD
))
10674 else if (tls_type
!= 0)
10676 relocation
-= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
10677 if (tls_type
== (TLS_TLS
| TLS_TPREL
))
10678 relocation
+= DTP_OFFSET
- TP_OFFSET
;
10680 if (tls_type
== (TLS_TLS
| TLS_GD
))
10682 bfd_put_64 (output_bfd
, relocation
,
10683 got
->contents
+ off
+ 8);
10688 bfd_put_64 (output_bfd
, relocation
,
10689 got
->contents
+ off
);
10693 if (off
>= (bfd_vma
) -2)
10696 relocation
= got
->output_offset
+ off
;
10698 /* TOC base (r2) is TOC start plus 0x8000. */
10699 addend
= -TOC_BASE_OFF
;
10703 case R_PPC64_PLT16_HA
:
10704 case R_PPC64_PLT16_HI
:
10705 case R_PPC64_PLT16_LO
:
10706 case R_PPC64_PLT32
:
10707 case R_PPC64_PLT64
:
10708 /* Relocation is to the entry for this symbol in the
10709 procedure linkage table. */
10711 /* Resolve a PLT reloc against a local symbol directly,
10712 without using the procedure linkage table. */
10716 /* It's possible that we didn't make a PLT entry for this
10717 symbol. This happens when statically linking PIC code,
10718 or when using -Bsymbolic. Go find a match if there is a
10720 if (htab
->plt
!= NULL
)
10722 struct plt_entry
*ent
;
10723 for (ent
= h
->elf
.plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
10724 if (ent
->addend
== orig_addend
10725 && ent
->plt
.offset
!= (bfd_vma
) -1)
10727 relocation
= (htab
->plt
->output_section
->vma
10728 + htab
->plt
->output_offset
10729 + ent
->plt
.offset
);
10730 unresolved_reloc
= FALSE
;
10736 /* Relocation value is TOC base. */
10737 relocation
= TOCstart
;
10739 relocation
+= htab
->stub_group
[input_section
->id
].toc_off
;
10740 else if (unresolved_reloc
)
10742 else if (sec
!= NULL
&& sec
->id
<= htab
->top_id
)
10743 relocation
+= htab
->stub_group
[sec
->id
].toc_off
;
10745 unresolved_reloc
= TRUE
;
10748 /* TOC16 relocs. We want the offset relative to the TOC base,
10749 which is the address of the start of the TOC plus 0x8000.
10750 The TOC consists of sections .got, .toc, .tocbss, and .plt,
10752 case R_PPC64_TOC16
:
10753 case R_PPC64_TOC16_LO
:
10754 case R_PPC64_TOC16_HI
:
10755 case R_PPC64_TOC16_DS
:
10756 case R_PPC64_TOC16_LO_DS
:
10757 case R_PPC64_TOC16_HA
:
10758 addend
-= TOCstart
+ htab
->stub_group
[input_section
->id
].toc_off
;
10761 /* Relocate against the beginning of the section. */
10762 case R_PPC64_SECTOFF
:
10763 case R_PPC64_SECTOFF_LO
:
10764 case R_PPC64_SECTOFF_HI
:
10765 case R_PPC64_SECTOFF_DS
:
10766 case R_PPC64_SECTOFF_LO_DS
:
10767 case R_PPC64_SECTOFF_HA
:
10769 addend
-= sec
->output_section
->vma
;
10772 case R_PPC64_REL14
:
10773 case R_PPC64_REL14_BRNTAKEN
:
10774 case R_PPC64_REL14_BRTAKEN
:
10775 case R_PPC64_REL24
:
10778 case R_PPC64_TPREL16
:
10779 case R_PPC64_TPREL16_LO
:
10780 case R_PPC64_TPREL16_HI
:
10781 case R_PPC64_TPREL16_HA
:
10782 case R_PPC64_TPREL16_DS
:
10783 case R_PPC64_TPREL16_LO_DS
:
10784 case R_PPC64_TPREL16_HIGHER
:
10785 case R_PPC64_TPREL16_HIGHERA
:
10786 case R_PPC64_TPREL16_HIGHEST
:
10787 case R_PPC64_TPREL16_HIGHESTA
:
10788 addend
-= htab
->elf
.tls_sec
->vma
+ TP_OFFSET
;
10790 /* The TPREL16 relocs shouldn't really be used in shared
10791 libs as they will result in DT_TEXTREL being set, but
10792 support them anyway. */
10796 case R_PPC64_DTPREL16
:
10797 case R_PPC64_DTPREL16_LO
:
10798 case R_PPC64_DTPREL16_HI
:
10799 case R_PPC64_DTPREL16_HA
:
10800 case R_PPC64_DTPREL16_DS
:
10801 case R_PPC64_DTPREL16_LO_DS
:
10802 case R_PPC64_DTPREL16_HIGHER
:
10803 case R_PPC64_DTPREL16_HIGHERA
:
10804 case R_PPC64_DTPREL16_HIGHEST
:
10805 case R_PPC64_DTPREL16_HIGHESTA
:
10806 addend
-= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
10809 case R_PPC64_DTPMOD64
:
10814 case R_PPC64_TPREL64
:
10815 addend
-= htab
->elf
.tls_sec
->vma
+ TP_OFFSET
;
10818 case R_PPC64_DTPREL64
:
10819 addend
-= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
10822 /* Relocations that may need to be propagated if this is a
10824 case R_PPC64_REL30
:
10825 case R_PPC64_REL32
:
10826 case R_PPC64_REL64
:
10827 case R_PPC64_ADDR14
:
10828 case R_PPC64_ADDR14_BRNTAKEN
:
10829 case R_PPC64_ADDR14_BRTAKEN
:
10830 case R_PPC64_ADDR16
:
10831 case R_PPC64_ADDR16_DS
:
10832 case R_PPC64_ADDR16_HA
:
10833 case R_PPC64_ADDR16_HI
:
10834 case R_PPC64_ADDR16_HIGHER
:
10835 case R_PPC64_ADDR16_HIGHERA
:
10836 case R_PPC64_ADDR16_HIGHEST
:
10837 case R_PPC64_ADDR16_HIGHESTA
:
10838 case R_PPC64_ADDR16_LO
:
10839 case R_PPC64_ADDR16_LO_DS
:
10840 case R_PPC64_ADDR24
:
10841 case R_PPC64_ADDR32
:
10842 case R_PPC64_ADDR64
:
10843 case R_PPC64_UADDR16
:
10844 case R_PPC64_UADDR32
:
10845 case R_PPC64_UADDR64
:
10847 if ((input_section
->flags
& SEC_ALLOC
) == 0)
10850 if (NO_OPD_RELOCS
&& is_opd
)
10855 || ELF_ST_VISIBILITY (h
->elf
.other
) == STV_DEFAULT
10856 || h
->elf
.root
.type
!= bfd_link_hash_undefweak
)
10857 && (MUST_BE_DYN_RELOC (r_type
)
10858 || !SYMBOL_CALLS_LOCAL (info
, &h
->elf
)))
10859 || (ELIMINATE_COPY_RELOCS
10862 && h
->elf
.dynindx
!= -1
10863 && !h
->elf
.non_got_ref
10864 && h
->elf
.def_dynamic
10865 && !h
->elf
.def_regular
))
10867 Elf_Internal_Rela outrel
;
10868 bfd_boolean skip
, relocate
;
10873 /* When generating a dynamic object, these relocations
10874 are copied into the output file to be resolved at run
10880 out_off
= _bfd_elf_section_offset (output_bfd
, info
,
10881 input_section
, rel
->r_offset
);
10882 if (out_off
== (bfd_vma
) -1)
10884 else if (out_off
== (bfd_vma
) -2)
10885 skip
= TRUE
, relocate
= TRUE
;
10886 out_off
+= (input_section
->output_section
->vma
10887 + input_section
->output_offset
);
10888 outrel
.r_offset
= out_off
;
10889 outrel
.r_addend
= rel
->r_addend
;
10891 /* Optimize unaligned reloc use. */
10892 if ((r_type
== R_PPC64_ADDR64
&& (out_off
& 7) != 0)
10893 || (r_type
== R_PPC64_UADDR64
&& (out_off
& 7) == 0))
10894 r_type
^= R_PPC64_ADDR64
^ R_PPC64_UADDR64
;
10895 else if ((r_type
== R_PPC64_ADDR32
&& (out_off
& 3) != 0)
10896 || (r_type
== R_PPC64_UADDR32
&& (out_off
& 3) == 0))
10897 r_type
^= R_PPC64_ADDR32
^ R_PPC64_UADDR32
;
10898 else if ((r_type
== R_PPC64_ADDR16
&& (out_off
& 1) != 0)
10899 || (r_type
== R_PPC64_UADDR16
&& (out_off
& 1) == 0))
10900 r_type
^= R_PPC64_ADDR16
^ R_PPC64_UADDR16
;
10903 memset (&outrel
, 0, sizeof outrel
);
10904 else if (!SYMBOL_REFERENCES_LOCAL (info
, &h
->elf
)
10906 && r_type
!= R_PPC64_TOC
)
10907 outrel
.r_info
= ELF64_R_INFO (h
->elf
.dynindx
, r_type
);
10910 /* This symbol is local, or marked to become local,
10911 or this is an opd section reloc which must point
10912 at a local function. */
10913 outrel
.r_addend
+= relocation
;
10914 if (r_type
== R_PPC64_ADDR64
|| r_type
== R_PPC64_TOC
)
10916 if (is_opd
&& h
!= NULL
)
10918 /* Lie about opd entries. This case occurs
10919 when building shared libraries and we
10920 reference a function in another shared
10921 lib. The same thing happens for a weak
10922 definition in an application that's
10923 overridden by a strong definition in a
10924 shared lib. (I believe this is a generic
10925 bug in binutils handling of weak syms.)
10926 In these cases we won't use the opd
10927 entry in this lib. */
10928 unresolved_reloc
= FALSE
;
10930 outrel
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
10932 /* We need to relocate .opd contents for ld.so.
10933 Prelink also wants simple and consistent rules
10934 for relocs. This make all RELATIVE relocs have
10935 *r_offset equal to r_addend. */
10942 if (bfd_is_abs_section (sec
))
10944 else if (sec
== NULL
|| sec
->owner
== NULL
)
10946 bfd_set_error (bfd_error_bad_value
);
10953 osec
= sec
->output_section
;
10954 indx
= elf_section_data (osec
)->dynindx
;
10958 if ((osec
->flags
& SEC_READONLY
) == 0
10959 && htab
->elf
.data_index_section
!= NULL
)
10960 osec
= htab
->elf
.data_index_section
;
10962 osec
= htab
->elf
.text_index_section
;
10963 indx
= elf_section_data (osec
)->dynindx
;
10965 BFD_ASSERT (indx
!= 0);
10967 /* We are turning this relocation into one
10968 against a section symbol, so subtract out
10969 the output section's address but not the
10970 offset of the input section in the output
10972 outrel
.r_addend
-= osec
->vma
;
10975 outrel
.r_info
= ELF64_R_INFO (indx
, r_type
);
10979 sreloc
= elf_section_data (input_section
)->sreloc
;
10980 if (sreloc
== NULL
)
10983 if (sreloc
->reloc_count
* sizeof (Elf64_External_Rela
)
10986 loc
= sreloc
->contents
;
10987 loc
+= sreloc
->reloc_count
++ * sizeof (Elf64_External_Rela
);
10988 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
10990 /* If this reloc is against an external symbol, it will
10991 be computed at runtime, so there's no need to do
10992 anything now. However, for the sake of prelink ensure
10993 that the section contents are a known value. */
10996 unresolved_reloc
= FALSE
;
10997 /* The value chosen here is quite arbitrary as ld.so
10998 ignores section contents except for the special
10999 case of .opd where the contents might be accessed
11000 before relocation. Choose zero, as that won't
11001 cause reloc overflow. */
11004 /* Use *r_offset == r_addend for R_PPC64_ADDR64 relocs
11005 to improve backward compatibility with older
11007 if (r_type
== R_PPC64_ADDR64
)
11008 addend
= outrel
.r_addend
;
11009 /* Adjust pc_relative relocs to have zero in *r_offset. */
11010 else if (ppc64_elf_howto_table
[r_type
]->pc_relative
)
11011 addend
= (input_section
->output_section
->vma
11012 + input_section
->output_offset
11019 case R_PPC64_GLOB_DAT
:
11020 case R_PPC64_JMP_SLOT
:
11021 case R_PPC64_RELATIVE
:
11022 /* We shouldn't ever see these dynamic relocs in relocatable
11024 /* Fall through. */
11026 case R_PPC64_PLTGOT16
:
11027 case R_PPC64_PLTGOT16_DS
:
11028 case R_PPC64_PLTGOT16_HA
:
11029 case R_PPC64_PLTGOT16_HI
:
11030 case R_PPC64_PLTGOT16_LO
:
11031 case R_PPC64_PLTGOT16_LO_DS
:
11032 case R_PPC64_PLTREL32
:
11033 case R_PPC64_PLTREL64
:
11034 /* These ones haven't been implemented yet. */
11036 (*_bfd_error_handler
)
11037 (_("%B: relocation %s is not supported for symbol %s."),
11039 ppc64_elf_howto_table
[r_type
]->name
, sym_name
);
11041 bfd_set_error (bfd_error_invalid_operation
);
11046 /* Do any further special processing. */
11052 case R_PPC64_ADDR16_HA
:
11053 case R_PPC64_ADDR16_HIGHERA
:
11054 case R_PPC64_ADDR16_HIGHESTA
:
11055 case R_PPC64_TOC16_HA
:
11056 case R_PPC64_SECTOFF_HA
:
11057 case R_PPC64_TPREL16_HA
:
11058 case R_PPC64_DTPREL16_HA
:
11059 case R_PPC64_TPREL16_HIGHER
:
11060 case R_PPC64_TPREL16_HIGHERA
:
11061 case R_PPC64_TPREL16_HIGHEST
:
11062 case R_PPC64_TPREL16_HIGHESTA
:
11063 case R_PPC64_DTPREL16_HIGHER
:
11064 case R_PPC64_DTPREL16_HIGHERA
:
11065 case R_PPC64_DTPREL16_HIGHEST
:
11066 case R_PPC64_DTPREL16_HIGHESTA
:
11067 /* It's just possible that this symbol is a weak symbol
11068 that's not actually defined anywhere. In that case,
11069 'sec' would be NULL, and we should leave the symbol
11070 alone (it will be set to zero elsewhere in the link). */
11075 case R_PPC64_GOT16_HA
:
11076 case R_PPC64_PLTGOT16_HA
:
11077 case R_PPC64_PLT16_HA
:
11078 case R_PPC64_GOT_TLSGD16_HA
:
11079 case R_PPC64_GOT_TLSLD16_HA
:
11080 case R_PPC64_GOT_TPREL16_HA
:
11081 case R_PPC64_GOT_DTPREL16_HA
:
11082 /* Add 0x10000 if sign bit in 0:15 is set.
11083 Bits 0:15 are not used. */
11087 case R_PPC64_ADDR16_DS
:
11088 case R_PPC64_ADDR16_LO_DS
:
11089 case R_PPC64_GOT16_DS
:
11090 case R_PPC64_GOT16_LO_DS
:
11091 case R_PPC64_PLT16_LO_DS
:
11092 case R_PPC64_SECTOFF_DS
:
11093 case R_PPC64_SECTOFF_LO_DS
:
11094 case R_PPC64_TOC16_DS
:
11095 case R_PPC64_TOC16_LO_DS
:
11096 case R_PPC64_PLTGOT16_DS
:
11097 case R_PPC64_PLTGOT16_LO_DS
:
11098 case R_PPC64_GOT_TPREL16_DS
:
11099 case R_PPC64_GOT_TPREL16_LO_DS
:
11100 case R_PPC64_GOT_DTPREL16_DS
:
11101 case R_PPC64_GOT_DTPREL16_LO_DS
:
11102 case R_PPC64_TPREL16_DS
:
11103 case R_PPC64_TPREL16_LO_DS
:
11104 case R_PPC64_DTPREL16_DS
:
11105 case R_PPC64_DTPREL16_LO_DS
:
11106 insn
= bfd_get_32 (input_bfd
, contents
+ (rel
->r_offset
& ~3));
11108 /* If this reloc is against an lq insn, then the value must be
11109 a multiple of 16. This is somewhat of a hack, but the
11110 "correct" way to do this by defining _DQ forms of all the
11111 _DS relocs bloats all reloc switches in this file. It
11112 doesn't seem to make much sense to use any of these relocs
11113 in data, so testing the insn should be safe. */
11114 if ((insn
& (0x3f << 26)) == (56u << 26))
11116 if (((relocation
+ addend
) & mask
) != 0)
11118 (*_bfd_error_handler
)
11119 (_("%B: error: relocation %s not a multiple of %d"),
11121 ppc64_elf_howto_table
[r_type
]->name
,
11123 bfd_set_error (bfd_error_bad_value
);
11130 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
11131 because such sections are not SEC_ALLOC and thus ld.so will
11132 not process them. */
11133 if (unresolved_reloc
11134 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
11135 && h
->elf
.def_dynamic
))
11137 (*_bfd_error_handler
)
11138 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
11141 (long) rel
->r_offset
,
11142 ppc64_elf_howto_table
[(int) r_type
]->name
,
11143 h
->elf
.root
.root
.string
);
11147 r
= _bfd_final_link_relocate (ppc64_elf_howto_table
[(int) r_type
],
11155 if (r
!= bfd_reloc_ok
)
11157 if (sym_name
== NULL
)
11158 sym_name
= "(null)";
11159 if (r
== bfd_reloc_overflow
)
11164 && h
->elf
.root
.type
== bfd_link_hash_undefweak
11165 && ppc64_elf_howto_table
[r_type
]->pc_relative
)
11167 /* Assume this is a call protected by other code that
11168 detects the symbol is undefined. If this is the case,
11169 we can safely ignore the overflow. If not, the
11170 program is hosed anyway, and a little warning isn't
11176 if (!((*info
->callbacks
->reloc_overflow
)
11177 (info
, (h
? &h
->elf
.root
: NULL
), sym_name
,
11178 ppc64_elf_howto_table
[r_type
]->name
,
11179 orig_addend
, input_bfd
, input_section
, rel
->r_offset
)))
11184 (*_bfd_error_handler
)
11185 (_("%B(%A+0x%lx): %s reloc against `%s': error %d"),
11188 (long) rel
->r_offset
,
11189 ppc64_elf_howto_table
[r_type
]->name
,
11197 /* If we're emitting relocations, then shortly after this function
11198 returns, reloc offsets and addends for this section will be
11199 adjusted. Worse, reloc symbol indices will be for the output
11200 file rather than the input. Save a copy of the relocs for
11201 opd_entry_value. */
11202 if (is_opd
&& (info
->emitrelocations
|| info
->relocatable
))
11205 amt
= input_section
->reloc_count
* sizeof (Elf_Internal_Rela
);
11206 rel
= bfd_alloc (input_bfd
, amt
);
11207 BFD_ASSERT (ppc64_elf_tdata (input_bfd
)->opd_relocs
== NULL
);
11208 ppc64_elf_tdata (input_bfd
)->opd_relocs
= rel
;
11211 memcpy (rel
, relocs
, amt
);
11216 /* Adjust the value of any local symbols in opd sections. */
11219 ppc64_elf_output_symbol_hook (struct bfd_link_info
*info
,
11220 const char *name ATTRIBUTE_UNUSED
,
11221 Elf_Internal_Sym
*elfsym
,
11222 asection
*input_sec
,
11223 struct elf_link_hash_entry
*h
)
11225 long *opd_adjust
, adjust
;
11231 opd_adjust
= get_opd_info (input_sec
);
11232 if (opd_adjust
== NULL
)
11235 value
= elfsym
->st_value
- input_sec
->output_offset
;
11236 if (!info
->relocatable
)
11237 value
-= input_sec
->output_section
->vma
;
11239 adjust
= opd_adjust
[value
/ 8];
11241 elfsym
->st_value
= 0;
11243 elfsym
->st_value
+= adjust
;
11247 /* Finish up dynamic symbol handling. We set the contents of various
11248 dynamic sections here. */
11251 ppc64_elf_finish_dynamic_symbol (bfd
*output_bfd
,
11252 struct bfd_link_info
*info
,
11253 struct elf_link_hash_entry
*h
,
11254 Elf_Internal_Sym
*sym
)
11256 struct ppc_link_hash_table
*htab
;
11257 struct plt_entry
*ent
;
11258 Elf_Internal_Rela rela
;
11261 htab
= ppc_hash_table (info
);
11263 for (ent
= h
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
11264 if (ent
->plt
.offset
!= (bfd_vma
) -1)
11266 /* This symbol has an entry in the procedure linkage
11267 table. Set it up. */
11269 if (htab
->plt
== NULL
11270 || htab
->relplt
== NULL
11271 || htab
->glink
== NULL
)
11274 /* Create a JMP_SLOT reloc to inform the dynamic linker to
11275 fill in the PLT entry. */
11276 rela
.r_offset
= (htab
->plt
->output_section
->vma
11277 + htab
->plt
->output_offset
11278 + ent
->plt
.offset
);
11279 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_PPC64_JMP_SLOT
);
11280 rela
.r_addend
= ent
->addend
;
11282 loc
= htab
->relplt
->contents
;
11283 loc
+= ((ent
->plt
.offset
- PLT_INITIAL_ENTRY_SIZE
) / PLT_ENTRY_SIZE
11284 * sizeof (Elf64_External_Rela
));
11285 bfd_elf64_swap_reloca_out (output_bfd
, &rela
, loc
);
11290 Elf_Internal_Rela rela
;
11293 /* This symbol needs a copy reloc. Set it up. */
11295 if (h
->dynindx
== -1
11296 || (h
->root
.type
!= bfd_link_hash_defined
11297 && h
->root
.type
!= bfd_link_hash_defweak
)
11298 || htab
->relbss
== NULL
)
11301 rela
.r_offset
= (h
->root
.u
.def
.value
11302 + h
->root
.u
.def
.section
->output_section
->vma
11303 + h
->root
.u
.def
.section
->output_offset
);
11304 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_PPC64_COPY
);
11306 loc
= htab
->relbss
->contents
;
11307 loc
+= htab
->relbss
->reloc_count
++ * sizeof (Elf64_External_Rela
);
11308 bfd_elf64_swap_reloca_out (output_bfd
, &rela
, loc
);
11311 /* Mark some specially defined symbols as absolute. */
11312 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0)
11313 sym
->st_shndx
= SHN_ABS
;
11318 /* Used to decide how to sort relocs in an optimal manner for the
11319 dynamic linker, before writing them out. */
11321 static enum elf_reloc_type_class
11322 ppc64_elf_reloc_type_class (const Elf_Internal_Rela
*rela
)
11324 enum elf_ppc64_reloc_type r_type
;
11326 r_type
= ELF64_R_TYPE (rela
->r_info
);
11329 case R_PPC64_RELATIVE
:
11330 return reloc_class_relative
;
11331 case R_PPC64_JMP_SLOT
:
11332 return reloc_class_plt
;
11334 return reloc_class_copy
;
11336 return reloc_class_normal
;
11340 /* Finish up the dynamic sections. */
11343 ppc64_elf_finish_dynamic_sections (bfd
*output_bfd
,
11344 struct bfd_link_info
*info
)
11346 struct ppc_link_hash_table
*htab
;
11350 htab
= ppc_hash_table (info
);
11351 dynobj
= htab
->elf
.dynobj
;
11352 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
11354 if (htab
->elf
.dynamic_sections_created
)
11356 Elf64_External_Dyn
*dyncon
, *dynconend
;
11358 if (sdyn
== NULL
|| htab
->got
== NULL
)
11361 dyncon
= (Elf64_External_Dyn
*) sdyn
->contents
;
11362 dynconend
= (Elf64_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
11363 for (; dyncon
< dynconend
; dyncon
++)
11365 Elf_Internal_Dyn dyn
;
11368 bfd_elf64_swap_dyn_in (dynobj
, dyncon
, &dyn
);
11375 case DT_PPC64_GLINK
:
11377 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
11378 /* We stupidly defined DT_PPC64_GLINK to be the start
11379 of glink rather than the first entry point, which is
11380 what ld.so needs, and now have a bigger stub to
11381 support automatic multiple TOCs. */
11382 dyn
.d_un
.d_ptr
+= GLINK_CALL_STUB_SIZE
- 32;
11386 s
= bfd_get_section_by_name (output_bfd
, ".opd");
11389 dyn
.d_un
.d_ptr
= s
->vma
;
11392 case DT_PPC64_OPDSZ
:
11393 s
= bfd_get_section_by_name (output_bfd
, ".opd");
11396 dyn
.d_un
.d_val
= s
->size
;
11401 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
11406 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
11410 dyn
.d_un
.d_val
= htab
->relplt
->size
;
11414 /* Don't count procedure linkage table relocs in the
11415 overall reloc count. */
11419 dyn
.d_un
.d_val
-= s
->size
;
11423 /* We may not be using the standard ELF linker script.
11424 If .rela.plt is the first .rela section, we adjust
11425 DT_RELA to not include it. */
11429 if (dyn
.d_un
.d_ptr
!= s
->output_section
->vma
+ s
->output_offset
)
11431 dyn
.d_un
.d_ptr
+= s
->size
;
11435 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
11439 if (htab
->got
!= NULL
&& htab
->got
->size
!= 0)
11441 /* Fill in the first entry in the global offset table.
11442 We use it to hold the link-time TOCbase. */
11443 bfd_put_64 (output_bfd
,
11444 elf_gp (output_bfd
) + TOC_BASE_OFF
,
11445 htab
->got
->contents
);
11447 /* Set .got entry size. */
11448 elf_section_data (htab
->got
->output_section
)->this_hdr
.sh_entsize
= 8;
11451 if (htab
->plt
!= NULL
&& htab
->plt
->size
!= 0)
11453 /* Set .plt entry size. */
11454 elf_section_data (htab
->plt
->output_section
)->this_hdr
.sh_entsize
11458 /* brlt is SEC_LINKER_CREATED, so we need to write out relocs for
11459 brlt ourselves if emitrelocations. */
11460 if (htab
->brlt
!= NULL
11461 && htab
->brlt
->reloc_count
!= 0
11462 && !_bfd_elf_link_output_relocs (output_bfd
,
11464 &elf_section_data (htab
->brlt
)->rel_hdr
,
11465 elf_section_data (htab
->brlt
)->relocs
,
11469 /* We need to handle writing out multiple GOT sections ourselves,
11470 since we didn't add them to DYNOBJ. We know dynobj is the first
11472 while ((dynobj
= dynobj
->link_next
) != NULL
)
11476 if (!is_ppc64_elf_target (dynobj
->xvec
))
11479 s
= ppc64_elf_tdata (dynobj
)->got
;
11482 && s
->output_section
!= bfd_abs_section_ptr
11483 && !bfd_set_section_contents (output_bfd
, s
->output_section
,
11484 s
->contents
, s
->output_offset
,
11487 s
= ppc64_elf_tdata (dynobj
)->relgot
;
11490 && s
->output_section
!= bfd_abs_section_ptr
11491 && !bfd_set_section_contents (output_bfd
, s
->output_section
,
11492 s
->contents
, s
->output_offset
,
11500 #include "elf64-target.h"