1 /* PowerPC64-specific support for 64-bit ELF.
2 Copyright 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
3 Written by Linus Nordberg, Swox AB <info@swox.com>,
4 based on elf32-ppc.c by Ian Lance Taylor.
5 Largely rewritten by Alan Modra <amodra@bigpond.net.au>
7 This file is part of BFD, the Binary File Descriptor library.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License along
20 with this program; if not, write to the Free Software Foundation, Inc.,
21 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
23 /* The 64-bit PowerPC ELF ABI may be found at
24 http://www.linuxbase.org/spec/ELF/ppc64/PPC-elf64abi.txt, and
25 http://www.linuxbase.org/spec/ELF/ppc64/spec/book1.html */
32 #include "elf/ppc64.h"
33 #include "elf64-ppc.h"
35 static bfd_reloc_status_type ppc64_elf_ha_reloc
36 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
37 static bfd_reloc_status_type ppc64_elf_brtaken_reloc
38 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
39 static bfd_reloc_status_type ppc64_elf_sectoff_reloc
40 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
41 static bfd_reloc_status_type ppc64_elf_sectoff_ha_reloc
42 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
43 static bfd_reloc_status_type ppc64_elf_toc_reloc
44 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
45 static bfd_reloc_status_type ppc64_elf_toc_ha_reloc
46 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
47 static bfd_reloc_status_type ppc64_elf_toc64_reloc
48 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
49 static bfd_reloc_status_type ppc64_elf_unhandled_reloc
50 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
53 #define TARGET_LITTLE_SYM bfd_elf64_powerpcle_vec
54 #define TARGET_LITTLE_NAME "elf64-powerpcle"
55 #define TARGET_BIG_SYM bfd_elf64_powerpc_vec
56 #define TARGET_BIG_NAME "elf64-powerpc"
57 #define ELF_ARCH bfd_arch_powerpc
58 #define ELF_MACHINE_CODE EM_PPC64
59 #define ELF_MAXPAGESIZE 0x10000
60 #define elf_info_to_howto ppc64_elf_info_to_howto
62 #define elf_backend_want_got_sym 0
63 #define elf_backend_want_plt_sym 0
64 #define elf_backend_plt_alignment 3
65 #define elf_backend_plt_not_loaded 1
66 #define elf_backend_got_symbol_offset 0
67 #define elf_backend_got_header_size 8
68 #define elf_backend_can_gc_sections 1
69 #define elf_backend_can_refcount 1
70 #define elf_backend_rela_normal 1
72 #define bfd_elf64_mkobject ppc64_elf_mkobject
73 #define bfd_elf64_bfd_reloc_type_lookup ppc64_elf_reloc_type_lookup
74 #define bfd_elf64_bfd_merge_private_bfd_data ppc64_elf_merge_private_bfd_data
75 #define bfd_elf64_new_section_hook ppc64_elf_new_section_hook
76 #define bfd_elf64_bfd_link_hash_table_create ppc64_elf_link_hash_table_create
77 #define bfd_elf64_bfd_link_hash_table_free ppc64_elf_link_hash_table_free
79 #define elf_backend_object_p ppc64_elf_object_p
80 #define elf_backend_grok_prstatus ppc64_elf_grok_prstatus
81 #define elf_backend_grok_psinfo ppc64_elf_grok_psinfo
82 #define elf_backend_create_dynamic_sections ppc64_elf_create_dynamic_sections
83 #define elf_backend_copy_indirect_symbol ppc64_elf_copy_indirect_symbol
84 #define elf_backend_check_relocs ppc64_elf_check_relocs
85 #define elf_backend_gc_mark_hook ppc64_elf_gc_mark_hook
86 #define elf_backend_gc_sweep_hook ppc64_elf_gc_sweep_hook
87 #define elf_backend_adjust_dynamic_symbol ppc64_elf_adjust_dynamic_symbol
88 #define elf_backend_hide_symbol ppc64_elf_hide_symbol
89 #define elf_backend_always_size_sections ppc64_elf_func_desc_adjust
90 #define elf_backend_size_dynamic_sections ppc64_elf_size_dynamic_sections
91 #define elf_backend_relocate_section ppc64_elf_relocate_section
92 #define elf_backend_finish_dynamic_symbol ppc64_elf_finish_dynamic_symbol
93 #define elf_backend_reloc_type_class ppc64_elf_reloc_type_class
94 #define elf_backend_finish_dynamic_sections ppc64_elf_finish_dynamic_sections
95 #define elf_backend_link_output_symbol_hook ppc64_elf_output_symbol_hook
96 #define elf_backend_special_sections ppc64_elf_special_sections
98 /* The name of the dynamic interpreter. This is put in the .interp
100 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
102 /* The size in bytes of an entry in the procedure linkage table. */
103 #define PLT_ENTRY_SIZE 24
105 /* The initial size of the plt reserved for the dynamic linker. */
106 #define PLT_INITIAL_ENTRY_SIZE PLT_ENTRY_SIZE
108 /* TOC base pointers offset from start of TOC. */
109 #define TOC_BASE_OFF 0x8000
111 /* Offset of tp and dtp pointers from start of TLS block. */
112 #define TP_OFFSET 0x7000
113 #define DTP_OFFSET 0x8000
115 /* .plt call stub instructions. The normal stub is like this, but
116 sometimes the .plt entry crosses a 64k boundary and we need to
117 insert an addis to adjust r12. */
118 #define PLT_CALL_STUB_SIZE (7*4)
119 #define ADDIS_R12_R2 0x3d820000 /* addis %r12,%r2,xxx@ha */
120 #define STD_R2_40R1 0xf8410028 /* std %r2,40(%r1) */
121 #define LD_R11_0R12 0xe96c0000 /* ld %r11,xxx+0@l(%r12) */
122 #define LD_R2_0R12 0xe84c0000 /* ld %r2,xxx+8@l(%r12) */
123 #define MTCTR_R11 0x7d6903a6 /* mtctr %r11 */
124 /* ld %r11,xxx+16@l(%r12) */
125 #define BCTR 0x4e800420 /* bctr */
128 #define ADDIS_R2_R2 0x3c420000 /* addis %r2,%r2,off@ha */
129 #define ADDI_R2_R2 0x38420000 /* addi %r2,%r2,off@l */
131 #define LD_R2_40R1 0xe8410028 /* ld %r2,40(%r1) */
133 /* glink call stub instructions. We enter with the index in R0, and the
134 address of glink entry in CTR. From that, we can calculate PLT0. */
135 #define GLINK_CALL_STUB_SIZE (16*4)
136 #define MFCTR_R12 0x7d8902a6 /* mfctr %r12 */
137 #define SLDI_R11_R0_3 0x780b1f24 /* sldi %r11,%r0,3 */
138 #define ADDIC_R2_R0_32K 0x34408000 /* addic. %r2,%r0,-32768 */
139 #define SUB_R12_R12_R11 0x7d8b6050 /* sub %r12,%r12,%r11 */
140 #define SRADI_R2_R2_63 0x7c42fe76 /* sradi %r2,%r2,63 */
141 #define SLDI_R11_R0_2 0x780b1764 /* sldi %r11,%r0,2 */
142 #define AND_R2_R2_R11 0x7c425838 /* and %r2,%r2,%r11 */
143 /* sub %r12,%r12,%r11 */
144 #define ADD_R12_R12_R2 0x7d8c1214 /* add %r12,%r12,%r2 */
145 #define ADDIS_R12_R12 0x3d8c0000 /* addis %r12,%r12,xxx@ha */
146 /* ld %r11,xxx@l(%r12) */
147 #define ADDI_R12_R12 0x398c0000 /* addi %r12,%r12,xxx@l */
150 /* ld %r11,16(%r12) */
154 #define NOP 0x60000000
156 /* Some other nops. */
157 #define CROR_151515 0x4def7b82
158 #define CROR_313131 0x4ffffb82
160 /* .glink entries for the first 32k functions are two instructions. */
161 #define LI_R0_0 0x38000000 /* li %r0,0 */
162 #define B_DOT 0x48000000 /* b . */
164 /* After that, we need two instructions to load the index, followed by
166 #define LIS_R0_0 0x3c000000 /* lis %r0,0 */
167 #define ORI_R0_R0_0 0x60000000 /* ori %r0,%r0,0 */
169 /* Instructions to save and restore floating point regs. */
170 #define STFD_FR0_0R1 0xd8010000 /* stfd %fr0,0(%r1) */
171 #define LFD_FR0_0R1 0xc8010000 /* lfd %fr0,0(%r1) */
172 #define BLR 0x4e800020 /* blr */
174 /* Since .opd is an array of descriptors and each entry will end up
175 with identical R_PPC64_RELATIVE relocs, there is really no need to
176 propagate .opd relocs; The dynamic linker should be taught to
177 relocate .opd without reloc entries. */
178 #ifndef NO_OPD_RELOCS
179 #define NO_OPD_RELOCS 0
182 #define ONES(n) (((bfd_vma) 1 << ((n) - 1) << 1) - 1)
184 /* Relocation HOWTO's. */
185 static reloc_howto_type
*ppc64_elf_howto_table
[(int) R_PPC64_max
];
187 static reloc_howto_type ppc64_elf_howto_raw
[] = {
188 /* This reloc does nothing. */
189 HOWTO (R_PPC64_NONE
, /* type */
191 2, /* size (0 = byte, 1 = short, 2 = long) */
193 FALSE
, /* pc_relative */
195 complain_overflow_dont
, /* complain_on_overflow */
196 bfd_elf_generic_reloc
, /* special_function */
197 "R_PPC64_NONE", /* name */
198 FALSE
, /* partial_inplace */
201 FALSE
), /* pcrel_offset */
203 /* A standard 32 bit relocation. */
204 HOWTO (R_PPC64_ADDR32
, /* type */
206 2, /* size (0 = byte, 1 = short, 2 = long) */
208 FALSE
, /* pc_relative */
210 complain_overflow_bitfield
, /* complain_on_overflow */
211 bfd_elf_generic_reloc
, /* special_function */
212 "R_PPC64_ADDR32", /* name */
213 FALSE
, /* partial_inplace */
215 0xffffffff, /* dst_mask */
216 FALSE
), /* pcrel_offset */
218 /* An absolute 26 bit branch; the lower two bits must be zero.
219 FIXME: we don't check that, we just clear them. */
220 HOWTO (R_PPC64_ADDR24
, /* type */
222 2, /* size (0 = byte, 1 = short, 2 = long) */
224 FALSE
, /* pc_relative */
226 complain_overflow_bitfield
, /* complain_on_overflow */
227 bfd_elf_generic_reloc
, /* special_function */
228 "R_PPC64_ADDR24", /* name */
229 FALSE
, /* partial_inplace */
231 0x03fffffc, /* dst_mask */
232 FALSE
), /* pcrel_offset */
234 /* A standard 16 bit relocation. */
235 HOWTO (R_PPC64_ADDR16
, /* type */
237 1, /* size (0 = byte, 1 = short, 2 = long) */
239 FALSE
, /* pc_relative */
241 complain_overflow_bitfield
, /* complain_on_overflow */
242 bfd_elf_generic_reloc
, /* special_function */
243 "R_PPC64_ADDR16", /* name */
244 FALSE
, /* partial_inplace */
246 0xffff, /* dst_mask */
247 FALSE
), /* pcrel_offset */
249 /* A 16 bit relocation without overflow. */
250 HOWTO (R_PPC64_ADDR16_LO
, /* type */
252 1, /* size (0 = byte, 1 = short, 2 = long) */
254 FALSE
, /* pc_relative */
256 complain_overflow_dont
,/* complain_on_overflow */
257 bfd_elf_generic_reloc
, /* special_function */
258 "R_PPC64_ADDR16_LO", /* name */
259 FALSE
, /* partial_inplace */
261 0xffff, /* dst_mask */
262 FALSE
), /* pcrel_offset */
264 /* Bits 16-31 of an address. */
265 HOWTO (R_PPC64_ADDR16_HI
, /* type */
267 1, /* size (0 = byte, 1 = short, 2 = long) */
269 FALSE
, /* pc_relative */
271 complain_overflow_dont
, /* complain_on_overflow */
272 bfd_elf_generic_reloc
, /* special_function */
273 "R_PPC64_ADDR16_HI", /* name */
274 FALSE
, /* partial_inplace */
276 0xffff, /* dst_mask */
277 FALSE
), /* pcrel_offset */
279 /* Bits 16-31 of an address, plus 1 if the contents of the low 16
280 bits, treated as a signed number, is negative. */
281 HOWTO (R_PPC64_ADDR16_HA
, /* type */
283 1, /* size (0 = byte, 1 = short, 2 = long) */
285 FALSE
, /* pc_relative */
287 complain_overflow_dont
, /* complain_on_overflow */
288 ppc64_elf_ha_reloc
, /* special_function */
289 "R_PPC64_ADDR16_HA", /* name */
290 FALSE
, /* partial_inplace */
292 0xffff, /* dst_mask */
293 FALSE
), /* pcrel_offset */
295 /* An absolute 16 bit branch; the lower two bits must be zero.
296 FIXME: we don't check that, we just clear them. */
297 HOWTO (R_PPC64_ADDR14
, /* type */
299 2, /* size (0 = byte, 1 = short, 2 = long) */
301 FALSE
, /* pc_relative */
303 complain_overflow_bitfield
, /* complain_on_overflow */
304 bfd_elf_generic_reloc
, /* special_function */
305 "R_PPC64_ADDR14", /* name */
306 FALSE
, /* partial_inplace */
308 0x0000fffc, /* dst_mask */
309 FALSE
), /* pcrel_offset */
311 /* An absolute 16 bit branch, for which bit 10 should be set to
312 indicate that the branch is expected to be taken. The lower two
313 bits must be zero. */
314 HOWTO (R_PPC64_ADDR14_BRTAKEN
, /* type */
316 2, /* size (0 = byte, 1 = short, 2 = long) */
318 FALSE
, /* pc_relative */
320 complain_overflow_bitfield
, /* complain_on_overflow */
321 ppc64_elf_brtaken_reloc
, /* special_function */
322 "R_PPC64_ADDR14_BRTAKEN",/* name */
323 FALSE
, /* partial_inplace */
325 0x0000fffc, /* dst_mask */
326 FALSE
), /* pcrel_offset */
328 /* An absolute 16 bit branch, for which bit 10 should be set to
329 indicate that the branch is not expected to be taken. The lower
330 two bits must be zero. */
331 HOWTO (R_PPC64_ADDR14_BRNTAKEN
, /* type */
333 2, /* size (0 = byte, 1 = short, 2 = long) */
335 FALSE
, /* pc_relative */
337 complain_overflow_bitfield
, /* complain_on_overflow */
338 ppc64_elf_brtaken_reloc
, /* special_function */
339 "R_PPC64_ADDR14_BRNTAKEN",/* name */
340 FALSE
, /* partial_inplace */
342 0x0000fffc, /* dst_mask */
343 FALSE
), /* pcrel_offset */
345 /* A relative 26 bit branch; the lower two bits must be zero. */
346 HOWTO (R_PPC64_REL24
, /* type */
348 2, /* size (0 = byte, 1 = short, 2 = long) */
350 TRUE
, /* pc_relative */
352 complain_overflow_signed
, /* complain_on_overflow */
353 bfd_elf_generic_reloc
, /* special_function */
354 "R_PPC64_REL24", /* name */
355 FALSE
, /* partial_inplace */
357 0x03fffffc, /* dst_mask */
358 TRUE
), /* pcrel_offset */
360 /* A relative 16 bit branch; the lower two bits must be zero. */
361 HOWTO (R_PPC64_REL14
, /* type */
363 2, /* size (0 = byte, 1 = short, 2 = long) */
365 TRUE
, /* pc_relative */
367 complain_overflow_signed
, /* complain_on_overflow */
368 bfd_elf_generic_reloc
, /* special_function */
369 "R_PPC64_REL14", /* name */
370 FALSE
, /* partial_inplace */
372 0x0000fffc, /* dst_mask */
373 TRUE
), /* pcrel_offset */
375 /* A relative 16 bit branch. Bit 10 should be set to indicate that
376 the branch is expected to be taken. The lower two bits must be
378 HOWTO (R_PPC64_REL14_BRTAKEN
, /* type */
380 2, /* size (0 = byte, 1 = short, 2 = long) */
382 TRUE
, /* pc_relative */
384 complain_overflow_signed
, /* complain_on_overflow */
385 ppc64_elf_brtaken_reloc
, /* special_function */
386 "R_PPC64_REL14_BRTAKEN", /* name */
387 FALSE
, /* partial_inplace */
389 0x0000fffc, /* dst_mask */
390 TRUE
), /* pcrel_offset */
392 /* A relative 16 bit branch. Bit 10 should be set to indicate that
393 the branch is not expected to be taken. The lower two bits must
395 HOWTO (R_PPC64_REL14_BRNTAKEN
, /* type */
397 2, /* size (0 = byte, 1 = short, 2 = long) */
399 TRUE
, /* pc_relative */
401 complain_overflow_signed
, /* complain_on_overflow */
402 ppc64_elf_brtaken_reloc
, /* special_function */
403 "R_PPC64_REL14_BRNTAKEN",/* name */
404 FALSE
, /* partial_inplace */
406 0x0000fffc, /* dst_mask */
407 TRUE
), /* pcrel_offset */
409 /* Like R_PPC64_ADDR16, but referring to the GOT table entry for the
411 HOWTO (R_PPC64_GOT16
, /* type */
413 1, /* size (0 = byte, 1 = short, 2 = long) */
415 FALSE
, /* pc_relative */
417 complain_overflow_signed
, /* complain_on_overflow */
418 ppc64_elf_unhandled_reloc
, /* special_function */
419 "R_PPC64_GOT16", /* name */
420 FALSE
, /* partial_inplace */
422 0xffff, /* dst_mask */
423 FALSE
), /* pcrel_offset */
425 /* Like R_PPC64_ADDR16_LO, but referring to the GOT table entry for
427 HOWTO (R_PPC64_GOT16_LO
, /* type */
429 1, /* size (0 = byte, 1 = short, 2 = long) */
431 FALSE
, /* pc_relative */
433 complain_overflow_dont
, /* complain_on_overflow */
434 ppc64_elf_unhandled_reloc
, /* special_function */
435 "R_PPC64_GOT16_LO", /* name */
436 FALSE
, /* partial_inplace */
438 0xffff, /* dst_mask */
439 FALSE
), /* pcrel_offset */
441 /* Like R_PPC64_ADDR16_HI, but referring to the GOT table entry for
443 HOWTO (R_PPC64_GOT16_HI
, /* type */
445 1, /* size (0 = byte, 1 = short, 2 = long) */
447 FALSE
, /* pc_relative */
449 complain_overflow_dont
,/* complain_on_overflow */
450 ppc64_elf_unhandled_reloc
, /* special_function */
451 "R_PPC64_GOT16_HI", /* name */
452 FALSE
, /* partial_inplace */
454 0xffff, /* dst_mask */
455 FALSE
), /* pcrel_offset */
457 /* Like R_PPC64_ADDR16_HA, but referring to the GOT table entry for
459 HOWTO (R_PPC64_GOT16_HA
, /* type */
461 1, /* size (0 = byte, 1 = short, 2 = long) */
463 FALSE
, /* pc_relative */
465 complain_overflow_dont
,/* complain_on_overflow */
466 ppc64_elf_unhandled_reloc
, /* special_function */
467 "R_PPC64_GOT16_HA", /* name */
468 FALSE
, /* partial_inplace */
470 0xffff, /* dst_mask */
471 FALSE
), /* pcrel_offset */
473 /* This is used only by the dynamic linker. The symbol should exist
474 both in the object being run and in some shared library. The
475 dynamic linker copies the data addressed by the symbol from the
476 shared library into the object, because the object being
477 run has to have the data at some particular address. */
478 HOWTO (R_PPC64_COPY
, /* type */
480 0, /* this one is variable size */
482 FALSE
, /* pc_relative */
484 complain_overflow_dont
, /* complain_on_overflow */
485 ppc64_elf_unhandled_reloc
, /* special_function */
486 "R_PPC64_COPY", /* name */
487 FALSE
, /* partial_inplace */
490 FALSE
), /* pcrel_offset */
492 /* Like R_PPC64_ADDR64, but used when setting global offset table
494 HOWTO (R_PPC64_GLOB_DAT
, /* type */
496 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
498 FALSE
, /* pc_relative */
500 complain_overflow_dont
, /* complain_on_overflow */
501 ppc64_elf_unhandled_reloc
, /* special_function */
502 "R_PPC64_GLOB_DAT", /* name */
503 FALSE
, /* partial_inplace */
505 ONES (64), /* dst_mask */
506 FALSE
), /* pcrel_offset */
508 /* Created by the link editor. Marks a procedure linkage table
509 entry for a symbol. */
510 HOWTO (R_PPC64_JMP_SLOT
, /* type */
512 0, /* size (0 = byte, 1 = short, 2 = long) */
514 FALSE
, /* pc_relative */
516 complain_overflow_dont
, /* complain_on_overflow */
517 ppc64_elf_unhandled_reloc
, /* special_function */
518 "R_PPC64_JMP_SLOT", /* name */
519 FALSE
, /* partial_inplace */
522 FALSE
), /* pcrel_offset */
524 /* Used only by the dynamic linker. When the object is run, this
525 doubleword64 is set to the load address of the object, plus the
527 HOWTO (R_PPC64_RELATIVE
, /* type */
529 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
531 FALSE
, /* pc_relative */
533 complain_overflow_dont
, /* complain_on_overflow */
534 bfd_elf_generic_reloc
, /* special_function */
535 "R_PPC64_RELATIVE", /* name */
536 FALSE
, /* partial_inplace */
538 ONES (64), /* dst_mask */
539 FALSE
), /* pcrel_offset */
541 /* Like R_PPC64_ADDR32, but may be unaligned. */
542 HOWTO (R_PPC64_UADDR32
, /* type */
544 2, /* size (0 = byte, 1 = short, 2 = long) */
546 FALSE
, /* pc_relative */
548 complain_overflow_bitfield
, /* complain_on_overflow */
549 bfd_elf_generic_reloc
, /* special_function */
550 "R_PPC64_UADDR32", /* name */
551 FALSE
, /* partial_inplace */
553 0xffffffff, /* dst_mask */
554 FALSE
), /* pcrel_offset */
556 /* Like R_PPC64_ADDR16, but may be unaligned. */
557 HOWTO (R_PPC64_UADDR16
, /* type */
559 1, /* size (0 = byte, 1 = short, 2 = long) */
561 FALSE
, /* pc_relative */
563 complain_overflow_bitfield
, /* complain_on_overflow */
564 bfd_elf_generic_reloc
, /* special_function */
565 "R_PPC64_UADDR16", /* name */
566 FALSE
, /* partial_inplace */
568 0xffff, /* dst_mask */
569 FALSE
), /* pcrel_offset */
571 /* 32-bit PC relative. */
572 HOWTO (R_PPC64_REL32
, /* type */
574 2, /* size (0 = byte, 1 = short, 2 = long) */
576 TRUE
, /* pc_relative */
578 /* FIXME: Verify. Was complain_overflow_bitfield. */
579 complain_overflow_signed
, /* complain_on_overflow */
580 bfd_elf_generic_reloc
, /* special_function */
581 "R_PPC64_REL32", /* name */
582 FALSE
, /* partial_inplace */
584 0xffffffff, /* dst_mask */
585 TRUE
), /* pcrel_offset */
587 /* 32-bit relocation to the symbol's procedure linkage table. */
588 HOWTO (R_PPC64_PLT32
, /* type */
590 2, /* size (0 = byte, 1 = short, 2 = long) */
592 FALSE
, /* pc_relative */
594 complain_overflow_bitfield
, /* complain_on_overflow */
595 ppc64_elf_unhandled_reloc
, /* special_function */
596 "R_PPC64_PLT32", /* name */
597 FALSE
, /* partial_inplace */
599 0xffffffff, /* dst_mask */
600 FALSE
), /* pcrel_offset */
602 /* 32-bit PC relative relocation to the symbol's procedure linkage table.
603 FIXME: R_PPC64_PLTREL32 not supported. */
604 HOWTO (R_PPC64_PLTREL32
, /* type */
606 2, /* size (0 = byte, 1 = short, 2 = long) */
608 TRUE
, /* pc_relative */
610 complain_overflow_signed
, /* complain_on_overflow */
611 bfd_elf_generic_reloc
, /* special_function */
612 "R_PPC64_PLTREL32", /* name */
613 FALSE
, /* partial_inplace */
615 0xffffffff, /* dst_mask */
616 TRUE
), /* pcrel_offset */
618 /* Like R_PPC64_ADDR16_LO, but referring to the PLT table entry for
620 HOWTO (R_PPC64_PLT16_LO
, /* type */
622 1, /* size (0 = byte, 1 = short, 2 = long) */
624 FALSE
, /* pc_relative */
626 complain_overflow_dont
, /* complain_on_overflow */
627 ppc64_elf_unhandled_reloc
, /* special_function */
628 "R_PPC64_PLT16_LO", /* name */
629 FALSE
, /* partial_inplace */
631 0xffff, /* dst_mask */
632 FALSE
), /* pcrel_offset */
634 /* Like R_PPC64_ADDR16_HI, but referring to the PLT table entry for
636 HOWTO (R_PPC64_PLT16_HI
, /* type */
638 1, /* size (0 = byte, 1 = short, 2 = long) */
640 FALSE
, /* pc_relative */
642 complain_overflow_dont
, /* complain_on_overflow */
643 ppc64_elf_unhandled_reloc
, /* special_function */
644 "R_PPC64_PLT16_HI", /* name */
645 FALSE
, /* partial_inplace */
647 0xffff, /* dst_mask */
648 FALSE
), /* pcrel_offset */
650 /* Like R_PPC64_ADDR16_HA, but referring to the PLT table entry for
652 HOWTO (R_PPC64_PLT16_HA
, /* type */
654 1, /* size (0 = byte, 1 = short, 2 = long) */
656 FALSE
, /* pc_relative */
658 complain_overflow_dont
, /* complain_on_overflow */
659 ppc64_elf_unhandled_reloc
, /* special_function */
660 "R_PPC64_PLT16_HA", /* name */
661 FALSE
, /* partial_inplace */
663 0xffff, /* dst_mask */
664 FALSE
), /* pcrel_offset */
666 /* 16-bit section relative relocation. */
667 HOWTO (R_PPC64_SECTOFF
, /* type */
669 1, /* size (0 = byte, 1 = short, 2 = long) */
671 FALSE
, /* pc_relative */
673 complain_overflow_bitfield
, /* complain_on_overflow */
674 ppc64_elf_sectoff_reloc
, /* special_function */
675 "R_PPC64_SECTOFF", /* name */
676 FALSE
, /* partial_inplace */
678 0xffff, /* dst_mask */
679 FALSE
), /* pcrel_offset */
681 /* Like R_PPC64_SECTOFF, but no overflow warning. */
682 HOWTO (R_PPC64_SECTOFF_LO
, /* type */
684 1, /* size (0 = byte, 1 = short, 2 = long) */
686 FALSE
, /* pc_relative */
688 complain_overflow_dont
, /* complain_on_overflow */
689 ppc64_elf_sectoff_reloc
, /* special_function */
690 "R_PPC64_SECTOFF_LO", /* name */
691 FALSE
, /* partial_inplace */
693 0xffff, /* dst_mask */
694 FALSE
), /* pcrel_offset */
696 /* 16-bit upper half section relative relocation. */
697 HOWTO (R_PPC64_SECTOFF_HI
, /* type */
699 1, /* size (0 = byte, 1 = short, 2 = long) */
701 FALSE
, /* pc_relative */
703 complain_overflow_dont
, /* complain_on_overflow */
704 ppc64_elf_sectoff_reloc
, /* special_function */
705 "R_PPC64_SECTOFF_HI", /* name */
706 FALSE
, /* partial_inplace */
708 0xffff, /* dst_mask */
709 FALSE
), /* pcrel_offset */
711 /* 16-bit upper half adjusted section relative relocation. */
712 HOWTO (R_PPC64_SECTOFF_HA
, /* type */
714 1, /* size (0 = byte, 1 = short, 2 = long) */
716 FALSE
, /* pc_relative */
718 complain_overflow_dont
, /* complain_on_overflow */
719 ppc64_elf_sectoff_ha_reloc
, /* special_function */
720 "R_PPC64_SECTOFF_HA", /* name */
721 FALSE
, /* partial_inplace */
723 0xffff, /* dst_mask */
724 FALSE
), /* pcrel_offset */
726 /* Like R_PPC64_REL24 without touching the two least significant bits. */
727 HOWTO (R_PPC64_REL30
, /* type */
729 2, /* size (0 = byte, 1 = short, 2 = long) */
731 TRUE
, /* pc_relative */
733 complain_overflow_dont
, /* complain_on_overflow */
734 bfd_elf_generic_reloc
, /* special_function */
735 "R_PPC64_REL30", /* name */
736 FALSE
, /* partial_inplace */
738 0xfffffffc, /* dst_mask */
739 TRUE
), /* pcrel_offset */
741 /* Relocs in the 64-bit PowerPC ELF ABI, not in the 32-bit ABI. */
743 /* A standard 64-bit relocation. */
744 HOWTO (R_PPC64_ADDR64
, /* type */
746 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
748 FALSE
, /* pc_relative */
750 complain_overflow_dont
, /* complain_on_overflow */
751 bfd_elf_generic_reloc
, /* special_function */
752 "R_PPC64_ADDR64", /* name */
753 FALSE
, /* partial_inplace */
755 ONES (64), /* dst_mask */
756 FALSE
), /* pcrel_offset */
758 /* The bits 32-47 of an address. */
759 HOWTO (R_PPC64_ADDR16_HIGHER
, /* type */
761 1, /* size (0 = byte, 1 = short, 2 = long) */
763 FALSE
, /* pc_relative */
765 complain_overflow_dont
, /* complain_on_overflow */
766 bfd_elf_generic_reloc
, /* special_function */
767 "R_PPC64_ADDR16_HIGHER", /* name */
768 FALSE
, /* partial_inplace */
770 0xffff, /* dst_mask */
771 FALSE
), /* pcrel_offset */
773 /* The bits 32-47 of an address, plus 1 if the contents of the low
774 16 bits, treated as a signed number, is negative. */
775 HOWTO (R_PPC64_ADDR16_HIGHERA
, /* type */
777 1, /* size (0 = byte, 1 = short, 2 = long) */
779 FALSE
, /* pc_relative */
781 complain_overflow_dont
, /* complain_on_overflow */
782 ppc64_elf_ha_reloc
, /* special_function */
783 "R_PPC64_ADDR16_HIGHERA", /* name */
784 FALSE
, /* partial_inplace */
786 0xffff, /* dst_mask */
787 FALSE
), /* pcrel_offset */
789 /* The bits 48-63 of an address. */
790 HOWTO (R_PPC64_ADDR16_HIGHEST
,/* type */
792 1, /* size (0 = byte, 1 = short, 2 = long) */
794 FALSE
, /* pc_relative */
796 complain_overflow_dont
, /* complain_on_overflow */
797 bfd_elf_generic_reloc
, /* special_function */
798 "R_PPC64_ADDR16_HIGHEST", /* name */
799 FALSE
, /* partial_inplace */
801 0xffff, /* dst_mask */
802 FALSE
), /* pcrel_offset */
804 /* The bits 48-63 of an address, plus 1 if the contents of the low
805 16 bits, treated as a signed number, is negative. */
806 HOWTO (R_PPC64_ADDR16_HIGHESTA
,/* type */
808 1, /* size (0 = byte, 1 = short, 2 = long) */
810 FALSE
, /* pc_relative */
812 complain_overflow_dont
, /* complain_on_overflow */
813 ppc64_elf_ha_reloc
, /* special_function */
814 "R_PPC64_ADDR16_HIGHESTA", /* name */
815 FALSE
, /* partial_inplace */
817 0xffff, /* dst_mask */
818 FALSE
), /* pcrel_offset */
820 /* Like ADDR64, but may be unaligned. */
821 HOWTO (R_PPC64_UADDR64
, /* type */
823 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
825 FALSE
, /* pc_relative */
827 complain_overflow_dont
, /* complain_on_overflow */
828 bfd_elf_generic_reloc
, /* special_function */
829 "R_PPC64_UADDR64", /* name */
830 FALSE
, /* partial_inplace */
832 ONES (64), /* dst_mask */
833 FALSE
), /* pcrel_offset */
835 /* 64-bit relative relocation. */
836 HOWTO (R_PPC64_REL64
, /* type */
838 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
840 TRUE
, /* pc_relative */
842 complain_overflow_dont
, /* complain_on_overflow */
843 bfd_elf_generic_reloc
, /* special_function */
844 "R_PPC64_REL64", /* name */
845 FALSE
, /* partial_inplace */
847 ONES (64), /* dst_mask */
848 TRUE
), /* pcrel_offset */
850 /* 64-bit relocation to the symbol's procedure linkage table. */
851 HOWTO (R_PPC64_PLT64
, /* type */
853 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
855 FALSE
, /* pc_relative */
857 complain_overflow_dont
, /* complain_on_overflow */
858 ppc64_elf_unhandled_reloc
, /* special_function */
859 "R_PPC64_PLT64", /* name */
860 FALSE
, /* partial_inplace */
862 ONES (64), /* dst_mask */
863 FALSE
), /* pcrel_offset */
865 /* 64-bit PC relative relocation to the symbol's procedure linkage
867 /* FIXME: R_PPC64_PLTREL64 not supported. */
868 HOWTO (R_PPC64_PLTREL64
, /* type */
870 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
872 TRUE
, /* pc_relative */
874 complain_overflow_dont
, /* complain_on_overflow */
875 ppc64_elf_unhandled_reloc
, /* special_function */
876 "R_PPC64_PLTREL64", /* name */
877 FALSE
, /* partial_inplace */
879 ONES (64), /* dst_mask */
880 TRUE
), /* pcrel_offset */
882 /* 16 bit TOC-relative relocation. */
884 /* R_PPC64_TOC16 47 half16* S + A - .TOC. */
885 HOWTO (R_PPC64_TOC16
, /* type */
887 1, /* size (0 = byte, 1 = short, 2 = long) */
889 FALSE
, /* pc_relative */
891 complain_overflow_signed
, /* complain_on_overflow */
892 ppc64_elf_toc_reloc
, /* special_function */
893 "R_PPC64_TOC16", /* name */
894 FALSE
, /* partial_inplace */
896 0xffff, /* dst_mask */
897 FALSE
), /* pcrel_offset */
899 /* 16 bit TOC-relative relocation without overflow. */
901 /* R_PPC64_TOC16_LO 48 half16 #lo (S + A - .TOC.) */
902 HOWTO (R_PPC64_TOC16_LO
, /* type */
904 1, /* size (0 = byte, 1 = short, 2 = long) */
906 FALSE
, /* pc_relative */
908 complain_overflow_dont
, /* complain_on_overflow */
909 ppc64_elf_toc_reloc
, /* special_function */
910 "R_PPC64_TOC16_LO", /* name */
911 FALSE
, /* partial_inplace */
913 0xffff, /* dst_mask */
914 FALSE
), /* pcrel_offset */
916 /* 16 bit TOC-relative relocation, high 16 bits. */
918 /* R_PPC64_TOC16_HI 49 half16 #hi (S + A - .TOC.) */
919 HOWTO (R_PPC64_TOC16_HI
, /* type */
921 1, /* size (0 = byte, 1 = short, 2 = long) */
923 FALSE
, /* pc_relative */
925 complain_overflow_dont
, /* complain_on_overflow */
926 ppc64_elf_toc_reloc
, /* special_function */
927 "R_PPC64_TOC16_HI", /* name */
928 FALSE
, /* partial_inplace */
930 0xffff, /* dst_mask */
931 FALSE
), /* pcrel_offset */
933 /* 16 bit TOC-relative relocation, high 16 bits, plus 1 if the
934 contents of the low 16 bits, treated as a signed number, is
937 /* R_PPC64_TOC16_HA 50 half16 #ha (S + A - .TOC.) */
938 HOWTO (R_PPC64_TOC16_HA
, /* type */
940 1, /* size (0 = byte, 1 = short, 2 = long) */
942 FALSE
, /* pc_relative */
944 complain_overflow_dont
, /* complain_on_overflow */
945 ppc64_elf_toc_ha_reloc
, /* special_function */
946 "R_PPC64_TOC16_HA", /* name */
947 FALSE
, /* partial_inplace */
949 0xffff, /* dst_mask */
950 FALSE
), /* pcrel_offset */
952 /* 64-bit relocation; insert value of TOC base (.TOC.). */
954 /* R_PPC64_TOC 51 doubleword64 .TOC. */
955 HOWTO (R_PPC64_TOC
, /* type */
957 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
959 FALSE
, /* pc_relative */
961 complain_overflow_bitfield
, /* complain_on_overflow */
962 ppc64_elf_toc64_reloc
, /* special_function */
963 "R_PPC64_TOC", /* name */
964 FALSE
, /* partial_inplace */
966 ONES (64), /* dst_mask */
967 FALSE
), /* pcrel_offset */
969 /* Like R_PPC64_GOT16, but also informs the link editor that the
970 value to relocate may (!) refer to a PLT entry which the link
971 editor (a) may replace with the symbol value. If the link editor
972 is unable to fully resolve the symbol, it may (b) create a PLT
973 entry and store the address to the new PLT entry in the GOT.
974 This permits lazy resolution of function symbols at run time.
975 The link editor may also skip all of this and just (c) emit a
976 R_PPC64_GLOB_DAT to tie the symbol to the GOT entry. */
977 /* FIXME: R_PPC64_PLTGOT16 not implemented. */
978 HOWTO (R_PPC64_PLTGOT16
, /* type */
980 1, /* size (0 = byte, 1 = short, 2 = long) */
982 FALSE
, /* pc_relative */
984 complain_overflow_signed
, /* complain_on_overflow */
985 ppc64_elf_unhandled_reloc
, /* special_function */
986 "R_PPC64_PLTGOT16", /* name */
987 FALSE
, /* partial_inplace */
989 0xffff, /* dst_mask */
990 FALSE
), /* pcrel_offset */
992 /* Like R_PPC64_PLTGOT16, but without overflow. */
993 /* FIXME: R_PPC64_PLTGOT16_LO not implemented. */
994 HOWTO (R_PPC64_PLTGOT16_LO
, /* type */
996 1, /* size (0 = byte, 1 = short, 2 = long) */
998 FALSE
, /* pc_relative */
1000 complain_overflow_dont
, /* complain_on_overflow */
1001 ppc64_elf_unhandled_reloc
, /* special_function */
1002 "R_PPC64_PLTGOT16_LO", /* name */
1003 FALSE
, /* partial_inplace */
1005 0xffff, /* dst_mask */
1006 FALSE
), /* pcrel_offset */
1008 /* Like R_PPC64_PLT_GOT16, but using bits 16-31 of the address. */
1009 /* FIXME: R_PPC64_PLTGOT16_HI not implemented. */
1010 HOWTO (R_PPC64_PLTGOT16_HI
, /* type */
1011 16, /* rightshift */
1012 1, /* size (0 = byte, 1 = short, 2 = long) */
1014 FALSE
, /* pc_relative */
1016 complain_overflow_dont
, /* complain_on_overflow */
1017 ppc64_elf_unhandled_reloc
, /* special_function */
1018 "R_PPC64_PLTGOT16_HI", /* name */
1019 FALSE
, /* partial_inplace */
1021 0xffff, /* dst_mask */
1022 FALSE
), /* pcrel_offset */
1024 /* Like R_PPC64_PLT_GOT16, but using bits 16-31 of the address, plus
1025 1 if the contents of the low 16 bits, treated as a signed number,
1027 /* FIXME: R_PPC64_PLTGOT16_HA not implemented. */
1028 HOWTO (R_PPC64_PLTGOT16_HA
, /* type */
1029 16, /* rightshift */
1030 1, /* size (0 = byte, 1 = short, 2 = long) */
1032 FALSE
, /* pc_relative */
1034 complain_overflow_dont
,/* complain_on_overflow */
1035 ppc64_elf_unhandled_reloc
, /* special_function */
1036 "R_PPC64_PLTGOT16_HA", /* name */
1037 FALSE
, /* partial_inplace */
1039 0xffff, /* dst_mask */
1040 FALSE
), /* pcrel_offset */
1042 /* Like R_PPC64_ADDR16, but for instructions with a DS field. */
1043 HOWTO (R_PPC64_ADDR16_DS
, /* type */
1045 1, /* size (0 = byte, 1 = short, 2 = long) */
1047 FALSE
, /* pc_relative */
1049 complain_overflow_bitfield
, /* complain_on_overflow */
1050 bfd_elf_generic_reloc
, /* special_function */
1051 "R_PPC64_ADDR16_DS", /* name */
1052 FALSE
, /* partial_inplace */
1054 0xfffc, /* dst_mask */
1055 FALSE
), /* pcrel_offset */
1057 /* Like R_PPC64_ADDR16_LO, but for instructions with a DS field. */
1058 HOWTO (R_PPC64_ADDR16_LO_DS
, /* type */
1060 1, /* size (0 = byte, 1 = short, 2 = long) */
1062 FALSE
, /* pc_relative */
1064 complain_overflow_dont
,/* complain_on_overflow */
1065 bfd_elf_generic_reloc
, /* special_function */
1066 "R_PPC64_ADDR16_LO_DS",/* name */
1067 FALSE
, /* partial_inplace */
1069 0xfffc, /* dst_mask */
1070 FALSE
), /* pcrel_offset */
1072 /* Like R_PPC64_GOT16, but for instructions with a DS field. */
1073 HOWTO (R_PPC64_GOT16_DS
, /* type */
1075 1, /* size (0 = byte, 1 = short, 2 = long) */
1077 FALSE
, /* pc_relative */
1079 complain_overflow_signed
, /* complain_on_overflow */
1080 ppc64_elf_unhandled_reloc
, /* special_function */
1081 "R_PPC64_GOT16_DS", /* name */
1082 FALSE
, /* partial_inplace */
1084 0xfffc, /* dst_mask */
1085 FALSE
), /* pcrel_offset */
1087 /* Like R_PPC64_GOT16_LO, but for instructions with a DS field. */
1088 HOWTO (R_PPC64_GOT16_LO_DS
, /* type */
1090 1, /* size (0 = byte, 1 = short, 2 = long) */
1092 FALSE
, /* pc_relative */
1094 complain_overflow_dont
, /* complain_on_overflow */
1095 ppc64_elf_unhandled_reloc
, /* special_function */
1096 "R_PPC64_GOT16_LO_DS", /* name */
1097 FALSE
, /* partial_inplace */
1099 0xfffc, /* dst_mask */
1100 FALSE
), /* pcrel_offset */
1102 /* Like R_PPC64_PLT16_LO, but for instructions with a DS field. */
1103 HOWTO (R_PPC64_PLT16_LO_DS
, /* type */
1105 1, /* size (0 = byte, 1 = short, 2 = long) */
1107 FALSE
, /* pc_relative */
1109 complain_overflow_dont
, /* complain_on_overflow */
1110 ppc64_elf_unhandled_reloc
, /* special_function */
1111 "R_PPC64_PLT16_LO_DS", /* name */
1112 FALSE
, /* partial_inplace */
1114 0xfffc, /* dst_mask */
1115 FALSE
), /* pcrel_offset */
1117 /* Like R_PPC64_SECTOFF, but for instructions with a DS field. */
1118 HOWTO (R_PPC64_SECTOFF_DS
, /* type */
1120 1, /* size (0 = byte, 1 = short, 2 = long) */
1122 FALSE
, /* pc_relative */
1124 complain_overflow_bitfield
, /* complain_on_overflow */
1125 ppc64_elf_sectoff_reloc
, /* special_function */
1126 "R_PPC64_SECTOFF_DS", /* name */
1127 FALSE
, /* partial_inplace */
1129 0xfffc, /* dst_mask */
1130 FALSE
), /* pcrel_offset */
1132 /* Like R_PPC64_SECTOFF_LO, but for instructions with a DS field. */
1133 HOWTO (R_PPC64_SECTOFF_LO_DS
, /* type */
1135 1, /* size (0 = byte, 1 = short, 2 = long) */
1137 FALSE
, /* pc_relative */
1139 complain_overflow_dont
, /* complain_on_overflow */
1140 ppc64_elf_sectoff_reloc
, /* special_function */
1141 "R_PPC64_SECTOFF_LO_DS",/* name */
1142 FALSE
, /* partial_inplace */
1144 0xfffc, /* dst_mask */
1145 FALSE
), /* pcrel_offset */
1147 /* Like R_PPC64_TOC16, but for instructions with a DS field. */
1148 HOWTO (R_PPC64_TOC16_DS
, /* type */
1150 1, /* size (0 = byte, 1 = short, 2 = long) */
1152 FALSE
, /* pc_relative */
1154 complain_overflow_signed
, /* complain_on_overflow */
1155 ppc64_elf_toc_reloc
, /* special_function */
1156 "R_PPC64_TOC16_DS", /* name */
1157 FALSE
, /* partial_inplace */
1159 0xfffc, /* dst_mask */
1160 FALSE
), /* pcrel_offset */
1162 /* Like R_PPC64_TOC16_LO, but for instructions with a DS field. */
1163 HOWTO (R_PPC64_TOC16_LO_DS
, /* type */
1165 1, /* size (0 = byte, 1 = short, 2 = long) */
1167 FALSE
, /* pc_relative */
1169 complain_overflow_dont
, /* complain_on_overflow */
1170 ppc64_elf_toc_reloc
, /* special_function */
1171 "R_PPC64_TOC16_LO_DS", /* name */
1172 FALSE
, /* partial_inplace */
1174 0xfffc, /* dst_mask */
1175 FALSE
), /* pcrel_offset */
1177 /* Like R_PPC64_PLTGOT16, but for instructions with a DS field. */
1178 /* FIXME: R_PPC64_PLTGOT16_DS not implemented. */
1179 HOWTO (R_PPC64_PLTGOT16_DS
, /* type */
1181 1, /* size (0 = byte, 1 = short, 2 = long) */
1183 FALSE
, /* pc_relative */
1185 complain_overflow_signed
, /* complain_on_overflow */
1186 ppc64_elf_unhandled_reloc
, /* special_function */
1187 "R_PPC64_PLTGOT16_DS", /* name */
1188 FALSE
, /* partial_inplace */
1190 0xfffc, /* dst_mask */
1191 FALSE
), /* pcrel_offset */
1193 /* Like R_PPC64_PLTGOT16_LO, but for instructions with a DS field. */
1194 /* FIXME: R_PPC64_PLTGOT16_LO not implemented. */
1195 HOWTO (R_PPC64_PLTGOT16_LO_DS
,/* type */
1197 1, /* size (0 = byte, 1 = short, 2 = long) */
1199 FALSE
, /* pc_relative */
1201 complain_overflow_dont
, /* complain_on_overflow */
1202 ppc64_elf_unhandled_reloc
, /* special_function */
1203 "R_PPC64_PLTGOT16_LO_DS",/* name */
1204 FALSE
, /* partial_inplace */
1206 0xfffc, /* dst_mask */
1207 FALSE
), /* pcrel_offset */
1209 /* Marker reloc for TLS. */
1212 2, /* size (0 = byte, 1 = short, 2 = long) */
1214 FALSE
, /* pc_relative */
1216 complain_overflow_dont
, /* complain_on_overflow */
1217 bfd_elf_generic_reloc
, /* special_function */
1218 "R_PPC64_TLS", /* name */
1219 FALSE
, /* partial_inplace */
1222 FALSE
), /* pcrel_offset */
1224 /* Computes the load module index of the load module that contains the
1225 definition of its TLS sym. */
1226 HOWTO (R_PPC64_DTPMOD64
,
1228 4, /* size (0 = byte, 1 = short, 2 = long) */
1230 FALSE
, /* pc_relative */
1232 complain_overflow_dont
, /* complain_on_overflow */
1233 ppc64_elf_unhandled_reloc
, /* special_function */
1234 "R_PPC64_DTPMOD64", /* name */
1235 FALSE
, /* partial_inplace */
1237 ONES (64), /* dst_mask */
1238 FALSE
), /* pcrel_offset */
1240 /* Computes a dtv-relative displacement, the difference between the value
1241 of sym+add and the base address of the thread-local storage block that
1242 contains the definition of sym, minus 0x8000. */
1243 HOWTO (R_PPC64_DTPREL64
,
1245 4, /* size (0 = byte, 1 = short, 2 = long) */
1247 FALSE
, /* pc_relative */
1249 complain_overflow_dont
, /* complain_on_overflow */
1250 ppc64_elf_unhandled_reloc
, /* special_function */
1251 "R_PPC64_DTPREL64", /* name */
1252 FALSE
, /* partial_inplace */
1254 ONES (64), /* dst_mask */
1255 FALSE
), /* pcrel_offset */
1257 /* A 16 bit dtprel reloc. */
1258 HOWTO (R_PPC64_DTPREL16
,
1260 1, /* size (0 = byte, 1 = short, 2 = long) */
1262 FALSE
, /* pc_relative */
1264 complain_overflow_signed
, /* complain_on_overflow */
1265 ppc64_elf_unhandled_reloc
, /* special_function */
1266 "R_PPC64_DTPREL16", /* name */
1267 FALSE
, /* partial_inplace */
1269 0xffff, /* dst_mask */
1270 FALSE
), /* pcrel_offset */
1272 /* Like DTPREL16, but no overflow. */
1273 HOWTO (R_PPC64_DTPREL16_LO
,
1275 1, /* size (0 = byte, 1 = short, 2 = long) */
1277 FALSE
, /* pc_relative */
1279 complain_overflow_dont
, /* complain_on_overflow */
1280 ppc64_elf_unhandled_reloc
, /* special_function */
1281 "R_PPC64_DTPREL16_LO", /* name */
1282 FALSE
, /* partial_inplace */
1284 0xffff, /* dst_mask */
1285 FALSE
), /* pcrel_offset */
1287 /* Like DTPREL16_LO, but next higher group of 16 bits. */
1288 HOWTO (R_PPC64_DTPREL16_HI
,
1289 16, /* rightshift */
1290 1, /* size (0 = byte, 1 = short, 2 = long) */
1292 FALSE
, /* pc_relative */
1294 complain_overflow_dont
, /* complain_on_overflow */
1295 ppc64_elf_unhandled_reloc
, /* special_function */
1296 "R_PPC64_DTPREL16_HI", /* name */
1297 FALSE
, /* partial_inplace */
1299 0xffff, /* dst_mask */
1300 FALSE
), /* pcrel_offset */
1302 /* Like DTPREL16_HI, but adjust for low 16 bits. */
1303 HOWTO (R_PPC64_DTPREL16_HA
,
1304 16, /* rightshift */
1305 1, /* size (0 = byte, 1 = short, 2 = long) */
1307 FALSE
, /* pc_relative */
1309 complain_overflow_dont
, /* complain_on_overflow */
1310 ppc64_elf_unhandled_reloc
, /* special_function */
1311 "R_PPC64_DTPREL16_HA", /* name */
1312 FALSE
, /* partial_inplace */
1314 0xffff, /* dst_mask */
1315 FALSE
), /* pcrel_offset */
1317 /* Like DTPREL16_HI, but next higher group of 16 bits. */
1318 HOWTO (R_PPC64_DTPREL16_HIGHER
,
1319 32, /* rightshift */
1320 1, /* size (0 = byte, 1 = short, 2 = long) */
1322 FALSE
, /* pc_relative */
1324 complain_overflow_dont
, /* complain_on_overflow */
1325 ppc64_elf_unhandled_reloc
, /* special_function */
1326 "R_PPC64_DTPREL16_HIGHER", /* name */
1327 FALSE
, /* partial_inplace */
1329 0xffff, /* dst_mask */
1330 FALSE
), /* pcrel_offset */
1332 /* Like DTPREL16_HIGHER, but adjust for low 16 bits. */
1333 HOWTO (R_PPC64_DTPREL16_HIGHERA
,
1334 32, /* rightshift */
1335 1, /* size (0 = byte, 1 = short, 2 = long) */
1337 FALSE
, /* pc_relative */
1339 complain_overflow_dont
, /* complain_on_overflow */
1340 ppc64_elf_unhandled_reloc
, /* special_function */
1341 "R_PPC64_DTPREL16_HIGHERA", /* name */
1342 FALSE
, /* partial_inplace */
1344 0xffff, /* dst_mask */
1345 FALSE
), /* pcrel_offset */
1347 /* Like DTPREL16_HIGHER, but next higher group of 16 bits. */
1348 HOWTO (R_PPC64_DTPREL16_HIGHEST
,
1349 48, /* rightshift */
1350 1, /* size (0 = byte, 1 = short, 2 = long) */
1352 FALSE
, /* pc_relative */
1354 complain_overflow_dont
, /* complain_on_overflow */
1355 ppc64_elf_unhandled_reloc
, /* special_function */
1356 "R_PPC64_DTPREL16_HIGHEST", /* name */
1357 FALSE
, /* partial_inplace */
1359 0xffff, /* dst_mask */
1360 FALSE
), /* pcrel_offset */
1362 /* Like DTPREL16_HIGHEST, but adjust for low 16 bits. */
1363 HOWTO (R_PPC64_DTPREL16_HIGHESTA
,
1364 48, /* rightshift */
1365 1, /* size (0 = byte, 1 = short, 2 = long) */
1367 FALSE
, /* pc_relative */
1369 complain_overflow_dont
, /* complain_on_overflow */
1370 ppc64_elf_unhandled_reloc
, /* special_function */
1371 "R_PPC64_DTPREL16_HIGHESTA", /* name */
1372 FALSE
, /* partial_inplace */
1374 0xffff, /* dst_mask */
1375 FALSE
), /* pcrel_offset */
1377 /* Like DTPREL16, but for insns with a DS field. */
1378 HOWTO (R_PPC64_DTPREL16_DS
,
1380 1, /* size (0 = byte, 1 = short, 2 = long) */
1382 FALSE
, /* pc_relative */
1384 complain_overflow_signed
, /* complain_on_overflow */
1385 ppc64_elf_unhandled_reloc
, /* special_function */
1386 "R_PPC64_DTPREL16_DS", /* name */
1387 FALSE
, /* partial_inplace */
1389 0xfffc, /* dst_mask */
1390 FALSE
), /* pcrel_offset */
1392 /* Like DTPREL16_DS, but no overflow. */
1393 HOWTO (R_PPC64_DTPREL16_LO_DS
,
1395 1, /* size (0 = byte, 1 = short, 2 = long) */
1397 FALSE
, /* pc_relative */
1399 complain_overflow_dont
, /* complain_on_overflow */
1400 ppc64_elf_unhandled_reloc
, /* special_function */
1401 "R_PPC64_DTPREL16_LO_DS", /* name */
1402 FALSE
, /* partial_inplace */
1404 0xfffc, /* dst_mask */
1405 FALSE
), /* pcrel_offset */
1407 /* Computes a tp-relative displacement, the difference between the value of
1408 sym+add and the value of the thread pointer (r13). */
1409 HOWTO (R_PPC64_TPREL64
,
1411 4, /* size (0 = byte, 1 = short, 2 = long) */
1413 FALSE
, /* pc_relative */
1415 complain_overflow_dont
, /* complain_on_overflow */
1416 ppc64_elf_unhandled_reloc
, /* special_function */
1417 "R_PPC64_TPREL64", /* name */
1418 FALSE
, /* partial_inplace */
1420 ONES (64), /* dst_mask */
1421 FALSE
), /* pcrel_offset */
1423 /* A 16 bit tprel reloc. */
1424 HOWTO (R_PPC64_TPREL16
,
1426 1, /* size (0 = byte, 1 = short, 2 = long) */
1428 FALSE
, /* pc_relative */
1430 complain_overflow_signed
, /* complain_on_overflow */
1431 ppc64_elf_unhandled_reloc
, /* special_function */
1432 "R_PPC64_TPREL16", /* name */
1433 FALSE
, /* partial_inplace */
1435 0xffff, /* dst_mask */
1436 FALSE
), /* pcrel_offset */
1438 /* Like TPREL16, but no overflow. */
1439 HOWTO (R_PPC64_TPREL16_LO
,
1441 1, /* size (0 = byte, 1 = short, 2 = long) */
1443 FALSE
, /* pc_relative */
1445 complain_overflow_dont
, /* complain_on_overflow */
1446 ppc64_elf_unhandled_reloc
, /* special_function */
1447 "R_PPC64_TPREL16_LO", /* name */
1448 FALSE
, /* partial_inplace */
1450 0xffff, /* dst_mask */
1451 FALSE
), /* pcrel_offset */
1453 /* Like TPREL16_LO, but next higher group of 16 bits. */
1454 HOWTO (R_PPC64_TPREL16_HI
,
1455 16, /* rightshift */
1456 1, /* size (0 = byte, 1 = short, 2 = long) */
1458 FALSE
, /* pc_relative */
1460 complain_overflow_dont
, /* complain_on_overflow */
1461 ppc64_elf_unhandled_reloc
, /* special_function */
1462 "R_PPC64_TPREL16_HI", /* name */
1463 FALSE
, /* partial_inplace */
1465 0xffff, /* dst_mask */
1466 FALSE
), /* pcrel_offset */
1468 /* Like TPREL16_HI, but adjust for low 16 bits. */
1469 HOWTO (R_PPC64_TPREL16_HA
,
1470 16, /* rightshift */
1471 1, /* size (0 = byte, 1 = short, 2 = long) */
1473 FALSE
, /* pc_relative */
1475 complain_overflow_dont
, /* complain_on_overflow */
1476 ppc64_elf_unhandled_reloc
, /* special_function */
1477 "R_PPC64_TPREL16_HA", /* name */
1478 FALSE
, /* partial_inplace */
1480 0xffff, /* dst_mask */
1481 FALSE
), /* pcrel_offset */
1483 /* Like TPREL16_HI, but next higher group of 16 bits. */
1484 HOWTO (R_PPC64_TPREL16_HIGHER
,
1485 32, /* rightshift */
1486 1, /* size (0 = byte, 1 = short, 2 = long) */
1488 FALSE
, /* pc_relative */
1490 complain_overflow_dont
, /* complain_on_overflow */
1491 ppc64_elf_unhandled_reloc
, /* special_function */
1492 "R_PPC64_TPREL16_HIGHER", /* name */
1493 FALSE
, /* partial_inplace */
1495 0xffff, /* dst_mask */
1496 FALSE
), /* pcrel_offset */
1498 /* Like TPREL16_HIGHER, but adjust for low 16 bits. */
1499 HOWTO (R_PPC64_TPREL16_HIGHERA
,
1500 32, /* rightshift */
1501 1, /* size (0 = byte, 1 = short, 2 = long) */
1503 FALSE
, /* pc_relative */
1505 complain_overflow_dont
, /* complain_on_overflow */
1506 ppc64_elf_unhandled_reloc
, /* special_function */
1507 "R_PPC64_TPREL16_HIGHERA", /* name */
1508 FALSE
, /* partial_inplace */
1510 0xffff, /* dst_mask */
1511 FALSE
), /* pcrel_offset */
1513 /* Like TPREL16_HIGHER, but next higher group of 16 bits. */
1514 HOWTO (R_PPC64_TPREL16_HIGHEST
,
1515 48, /* rightshift */
1516 1, /* size (0 = byte, 1 = short, 2 = long) */
1518 FALSE
, /* pc_relative */
1520 complain_overflow_dont
, /* complain_on_overflow */
1521 ppc64_elf_unhandled_reloc
, /* special_function */
1522 "R_PPC64_TPREL16_HIGHEST", /* name */
1523 FALSE
, /* partial_inplace */
1525 0xffff, /* dst_mask */
1526 FALSE
), /* pcrel_offset */
1528 /* Like TPREL16_HIGHEST, but adjust for low 16 bits. */
1529 HOWTO (R_PPC64_TPREL16_HIGHESTA
,
1530 48, /* rightshift */
1531 1, /* size (0 = byte, 1 = short, 2 = long) */
1533 FALSE
, /* pc_relative */
1535 complain_overflow_dont
, /* complain_on_overflow */
1536 ppc64_elf_unhandled_reloc
, /* special_function */
1537 "R_PPC64_TPREL16_HIGHESTA", /* name */
1538 FALSE
, /* partial_inplace */
1540 0xffff, /* dst_mask */
1541 FALSE
), /* pcrel_offset */
1543 /* Like TPREL16, but for insns with a DS field. */
1544 HOWTO (R_PPC64_TPREL16_DS
,
1546 1, /* size (0 = byte, 1 = short, 2 = long) */
1548 FALSE
, /* pc_relative */
1550 complain_overflow_signed
, /* complain_on_overflow */
1551 ppc64_elf_unhandled_reloc
, /* special_function */
1552 "R_PPC64_TPREL16_DS", /* name */
1553 FALSE
, /* partial_inplace */
1555 0xfffc, /* dst_mask */
1556 FALSE
), /* pcrel_offset */
1558 /* Like TPREL16_DS, but no overflow. */
1559 HOWTO (R_PPC64_TPREL16_LO_DS
,
1561 1, /* size (0 = byte, 1 = short, 2 = long) */
1563 FALSE
, /* pc_relative */
1565 complain_overflow_dont
, /* complain_on_overflow */
1566 ppc64_elf_unhandled_reloc
, /* special_function */
1567 "R_PPC64_TPREL16_LO_DS", /* name */
1568 FALSE
, /* partial_inplace */
1570 0xfffc, /* dst_mask */
1571 FALSE
), /* pcrel_offset */
1573 /* Allocates two contiguous entries in the GOT to hold a tls_index structure,
1574 with values (sym+add)@dtpmod and (sym+add)@dtprel, and computes the offset
1575 to the first entry relative to the TOC base (r2). */
1576 HOWTO (R_PPC64_GOT_TLSGD16
,
1578 1, /* size (0 = byte, 1 = short, 2 = long) */
1580 FALSE
, /* pc_relative */
1582 complain_overflow_signed
, /* complain_on_overflow */
1583 ppc64_elf_unhandled_reloc
, /* special_function */
1584 "R_PPC64_GOT_TLSGD16", /* name */
1585 FALSE
, /* partial_inplace */
1587 0xffff, /* dst_mask */
1588 FALSE
), /* pcrel_offset */
1590 /* Like GOT_TLSGD16, but no overflow. */
1591 HOWTO (R_PPC64_GOT_TLSGD16_LO
,
1593 1, /* size (0 = byte, 1 = short, 2 = long) */
1595 FALSE
, /* pc_relative */
1597 complain_overflow_dont
, /* complain_on_overflow */
1598 ppc64_elf_unhandled_reloc
, /* special_function */
1599 "R_PPC64_GOT_TLSGD16_LO", /* name */
1600 FALSE
, /* partial_inplace */
1602 0xffff, /* dst_mask */
1603 FALSE
), /* pcrel_offset */
1605 /* Like GOT_TLSGD16_LO, but next higher group of 16 bits. */
1606 HOWTO (R_PPC64_GOT_TLSGD16_HI
,
1607 16, /* rightshift */
1608 1, /* size (0 = byte, 1 = short, 2 = long) */
1610 FALSE
, /* pc_relative */
1612 complain_overflow_dont
, /* complain_on_overflow */
1613 ppc64_elf_unhandled_reloc
, /* special_function */
1614 "R_PPC64_GOT_TLSGD16_HI", /* name */
1615 FALSE
, /* partial_inplace */
1617 0xffff, /* dst_mask */
1618 FALSE
), /* pcrel_offset */
1620 /* Like GOT_TLSGD16_HI, but adjust for low 16 bits. */
1621 HOWTO (R_PPC64_GOT_TLSGD16_HA
,
1622 16, /* rightshift */
1623 1, /* size (0 = byte, 1 = short, 2 = long) */
1625 FALSE
, /* pc_relative */
1627 complain_overflow_dont
, /* complain_on_overflow */
1628 ppc64_elf_unhandled_reloc
, /* special_function */
1629 "R_PPC64_GOT_TLSGD16_HA", /* name */
1630 FALSE
, /* partial_inplace */
1632 0xffff, /* dst_mask */
1633 FALSE
), /* pcrel_offset */
1635 /* Allocates two contiguous entries in the GOT to hold a tls_index structure,
1636 with values (sym+add)@dtpmod and zero, and computes the offset to the
1637 first entry relative to the TOC base (r2). */
1638 HOWTO (R_PPC64_GOT_TLSLD16
,
1640 1, /* size (0 = byte, 1 = short, 2 = long) */
1642 FALSE
, /* pc_relative */
1644 complain_overflow_signed
, /* complain_on_overflow */
1645 ppc64_elf_unhandled_reloc
, /* special_function */
1646 "R_PPC64_GOT_TLSLD16", /* name */
1647 FALSE
, /* partial_inplace */
1649 0xffff, /* dst_mask */
1650 FALSE
), /* pcrel_offset */
1652 /* Like GOT_TLSLD16, but no overflow. */
1653 HOWTO (R_PPC64_GOT_TLSLD16_LO
,
1655 1, /* size (0 = byte, 1 = short, 2 = long) */
1657 FALSE
, /* pc_relative */
1659 complain_overflow_dont
, /* complain_on_overflow */
1660 ppc64_elf_unhandled_reloc
, /* special_function */
1661 "R_PPC64_GOT_TLSLD16_LO", /* name */
1662 FALSE
, /* partial_inplace */
1664 0xffff, /* dst_mask */
1665 FALSE
), /* pcrel_offset */
1667 /* Like GOT_TLSLD16_LO, but next higher group of 16 bits. */
1668 HOWTO (R_PPC64_GOT_TLSLD16_HI
,
1669 16, /* rightshift */
1670 1, /* size (0 = byte, 1 = short, 2 = long) */
1672 FALSE
, /* pc_relative */
1674 complain_overflow_dont
, /* complain_on_overflow */
1675 ppc64_elf_unhandled_reloc
, /* special_function */
1676 "R_PPC64_GOT_TLSLD16_HI", /* name */
1677 FALSE
, /* partial_inplace */
1679 0xffff, /* dst_mask */
1680 FALSE
), /* pcrel_offset */
1682 /* Like GOT_TLSLD16_HI, but adjust for low 16 bits. */
1683 HOWTO (R_PPC64_GOT_TLSLD16_HA
,
1684 16, /* rightshift */
1685 1, /* size (0 = byte, 1 = short, 2 = long) */
1687 FALSE
, /* pc_relative */
1689 complain_overflow_dont
, /* complain_on_overflow */
1690 ppc64_elf_unhandled_reloc
, /* special_function */
1691 "R_PPC64_GOT_TLSLD16_HA", /* name */
1692 FALSE
, /* partial_inplace */
1694 0xffff, /* dst_mask */
1695 FALSE
), /* pcrel_offset */
1697 /* Allocates an entry in the GOT with value (sym+add)@dtprel, and computes
1698 the offset to the entry relative to the TOC base (r2). */
1699 HOWTO (R_PPC64_GOT_DTPREL16_DS
,
1701 1, /* size (0 = byte, 1 = short, 2 = long) */
1703 FALSE
, /* pc_relative */
1705 complain_overflow_signed
, /* complain_on_overflow */
1706 ppc64_elf_unhandled_reloc
, /* special_function */
1707 "R_PPC64_GOT_DTPREL16_DS", /* name */
1708 FALSE
, /* partial_inplace */
1710 0xfffc, /* dst_mask */
1711 FALSE
), /* pcrel_offset */
1713 /* Like GOT_DTPREL16_DS, but no overflow. */
1714 HOWTO (R_PPC64_GOT_DTPREL16_LO_DS
,
1716 1, /* size (0 = byte, 1 = short, 2 = long) */
1718 FALSE
, /* pc_relative */
1720 complain_overflow_dont
, /* complain_on_overflow */
1721 ppc64_elf_unhandled_reloc
, /* special_function */
1722 "R_PPC64_GOT_DTPREL16_LO_DS", /* name */
1723 FALSE
, /* partial_inplace */
1725 0xfffc, /* dst_mask */
1726 FALSE
), /* pcrel_offset */
1728 /* Like GOT_DTPREL16_LO_DS, but next higher group of 16 bits. */
1729 HOWTO (R_PPC64_GOT_DTPREL16_HI
,
1730 16, /* rightshift */
1731 1, /* size (0 = byte, 1 = short, 2 = long) */
1733 FALSE
, /* pc_relative */
1735 complain_overflow_dont
, /* complain_on_overflow */
1736 ppc64_elf_unhandled_reloc
, /* special_function */
1737 "R_PPC64_GOT_DTPREL16_HI", /* name */
1738 FALSE
, /* partial_inplace */
1740 0xffff, /* dst_mask */
1741 FALSE
), /* pcrel_offset */
1743 /* Like GOT_DTPREL16_HI, but adjust for low 16 bits. */
1744 HOWTO (R_PPC64_GOT_DTPREL16_HA
,
1745 16, /* rightshift */
1746 1, /* size (0 = byte, 1 = short, 2 = long) */
1748 FALSE
, /* pc_relative */
1750 complain_overflow_dont
, /* complain_on_overflow */
1751 ppc64_elf_unhandled_reloc
, /* special_function */
1752 "R_PPC64_GOT_DTPREL16_HA", /* name */
1753 FALSE
, /* partial_inplace */
1755 0xffff, /* dst_mask */
1756 FALSE
), /* pcrel_offset */
1758 /* Allocates an entry in the GOT with value (sym+add)@tprel, and computes the
1759 offset to the entry relative to the TOC base (r2). */
1760 HOWTO (R_PPC64_GOT_TPREL16_DS
,
1762 1, /* size (0 = byte, 1 = short, 2 = long) */
1764 FALSE
, /* pc_relative */
1766 complain_overflow_signed
, /* complain_on_overflow */
1767 ppc64_elf_unhandled_reloc
, /* special_function */
1768 "R_PPC64_GOT_TPREL16_DS", /* name */
1769 FALSE
, /* partial_inplace */
1771 0xfffc, /* dst_mask */
1772 FALSE
), /* pcrel_offset */
1774 /* Like GOT_TPREL16_DS, but no overflow. */
1775 HOWTO (R_PPC64_GOT_TPREL16_LO_DS
,
1777 1, /* size (0 = byte, 1 = short, 2 = long) */
1779 FALSE
, /* pc_relative */
1781 complain_overflow_dont
, /* complain_on_overflow */
1782 ppc64_elf_unhandled_reloc
, /* special_function */
1783 "R_PPC64_GOT_TPREL16_LO_DS", /* name */
1784 FALSE
, /* partial_inplace */
1786 0xfffc, /* dst_mask */
1787 FALSE
), /* pcrel_offset */
1789 /* Like GOT_TPREL16_LO_DS, but next higher group of 16 bits. */
1790 HOWTO (R_PPC64_GOT_TPREL16_HI
,
1791 16, /* rightshift */
1792 1, /* size (0 = byte, 1 = short, 2 = long) */
1794 FALSE
, /* pc_relative */
1796 complain_overflow_dont
, /* complain_on_overflow */
1797 ppc64_elf_unhandled_reloc
, /* special_function */
1798 "R_PPC64_GOT_TPREL16_HI", /* name */
1799 FALSE
, /* partial_inplace */
1801 0xffff, /* dst_mask */
1802 FALSE
), /* pcrel_offset */
1804 /* Like GOT_TPREL16_HI, but adjust for low 16 bits. */
1805 HOWTO (R_PPC64_GOT_TPREL16_HA
,
1806 16, /* rightshift */
1807 1, /* size (0 = byte, 1 = short, 2 = long) */
1809 FALSE
, /* pc_relative */
1811 complain_overflow_dont
, /* complain_on_overflow */
1812 ppc64_elf_unhandled_reloc
, /* special_function */
1813 "R_PPC64_GOT_TPREL16_HA", /* name */
1814 FALSE
, /* partial_inplace */
1816 0xffff, /* dst_mask */
1817 FALSE
), /* pcrel_offset */
1819 /* GNU extension to record C++ vtable hierarchy. */
1820 HOWTO (R_PPC64_GNU_VTINHERIT
, /* type */
1822 0, /* size (0 = byte, 1 = short, 2 = long) */
1824 FALSE
, /* pc_relative */
1826 complain_overflow_dont
, /* complain_on_overflow */
1827 NULL
, /* special_function */
1828 "R_PPC64_GNU_VTINHERIT", /* name */
1829 FALSE
, /* partial_inplace */
1832 FALSE
), /* pcrel_offset */
1834 /* GNU extension to record C++ vtable member usage. */
1835 HOWTO (R_PPC64_GNU_VTENTRY
, /* type */
1837 0, /* size (0 = byte, 1 = short, 2 = long) */
1839 FALSE
, /* pc_relative */
1841 complain_overflow_dont
, /* complain_on_overflow */
1842 NULL
, /* special_function */
1843 "R_PPC64_GNU_VTENTRY", /* name */
1844 FALSE
, /* partial_inplace */
1847 FALSE
), /* pcrel_offset */
1851 /* Initialize the ppc64_elf_howto_table, so that linear accesses can
1855 ppc_howto_init (void)
1857 unsigned int i
, type
;
1860 i
< sizeof (ppc64_elf_howto_raw
) / sizeof (ppc64_elf_howto_raw
[0]);
1863 type
= ppc64_elf_howto_raw
[i
].type
;
1864 BFD_ASSERT (type
< (sizeof (ppc64_elf_howto_table
)
1865 / sizeof (ppc64_elf_howto_table
[0])));
1866 ppc64_elf_howto_table
[type
] = &ppc64_elf_howto_raw
[i
];
1870 static reloc_howto_type
*
1871 ppc64_elf_reloc_type_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
1872 bfd_reloc_code_real_type code
)
1874 enum elf_ppc64_reloc_type r
= R_PPC64_NONE
;
1876 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
1877 /* Initialize howto table if needed. */
1885 case BFD_RELOC_NONE
: r
= R_PPC64_NONE
;
1887 case BFD_RELOC_32
: r
= R_PPC64_ADDR32
;
1889 case BFD_RELOC_PPC_BA26
: r
= R_PPC64_ADDR24
;
1891 case BFD_RELOC_16
: r
= R_PPC64_ADDR16
;
1893 case BFD_RELOC_LO16
: r
= R_PPC64_ADDR16_LO
;
1895 case BFD_RELOC_HI16
: r
= R_PPC64_ADDR16_HI
;
1897 case BFD_RELOC_HI16_S
: r
= R_PPC64_ADDR16_HA
;
1899 case BFD_RELOC_PPC_BA16
: r
= R_PPC64_ADDR14
;
1901 case BFD_RELOC_PPC_BA16_BRTAKEN
: r
= R_PPC64_ADDR14_BRTAKEN
;
1903 case BFD_RELOC_PPC_BA16_BRNTAKEN
: r
= R_PPC64_ADDR14_BRNTAKEN
;
1905 case BFD_RELOC_PPC_B26
: r
= R_PPC64_REL24
;
1907 case BFD_RELOC_PPC_B16
: r
= R_PPC64_REL14
;
1909 case BFD_RELOC_PPC_B16_BRTAKEN
: r
= R_PPC64_REL14_BRTAKEN
;
1911 case BFD_RELOC_PPC_B16_BRNTAKEN
: r
= R_PPC64_REL14_BRNTAKEN
;
1913 case BFD_RELOC_16_GOTOFF
: r
= R_PPC64_GOT16
;
1915 case BFD_RELOC_LO16_GOTOFF
: r
= R_PPC64_GOT16_LO
;
1917 case BFD_RELOC_HI16_GOTOFF
: r
= R_PPC64_GOT16_HI
;
1919 case BFD_RELOC_HI16_S_GOTOFF
: r
= R_PPC64_GOT16_HA
;
1921 case BFD_RELOC_PPC_COPY
: r
= R_PPC64_COPY
;
1923 case BFD_RELOC_PPC_GLOB_DAT
: r
= R_PPC64_GLOB_DAT
;
1925 case BFD_RELOC_32_PCREL
: r
= R_PPC64_REL32
;
1927 case BFD_RELOC_32_PLTOFF
: r
= R_PPC64_PLT32
;
1929 case BFD_RELOC_32_PLT_PCREL
: r
= R_PPC64_PLTREL32
;
1931 case BFD_RELOC_LO16_PLTOFF
: r
= R_PPC64_PLT16_LO
;
1933 case BFD_RELOC_HI16_PLTOFF
: r
= R_PPC64_PLT16_HI
;
1935 case BFD_RELOC_HI16_S_PLTOFF
: r
= R_PPC64_PLT16_HA
;
1937 case BFD_RELOC_16_BASEREL
: r
= R_PPC64_SECTOFF
;
1939 case BFD_RELOC_LO16_BASEREL
: r
= R_PPC64_SECTOFF_LO
;
1941 case BFD_RELOC_HI16_BASEREL
: r
= R_PPC64_SECTOFF_HI
;
1943 case BFD_RELOC_HI16_S_BASEREL
: r
= R_PPC64_SECTOFF_HA
;
1945 case BFD_RELOC_CTOR
: r
= R_PPC64_ADDR64
;
1947 case BFD_RELOC_64
: r
= R_PPC64_ADDR64
;
1949 case BFD_RELOC_PPC64_HIGHER
: r
= R_PPC64_ADDR16_HIGHER
;
1951 case BFD_RELOC_PPC64_HIGHER_S
: r
= R_PPC64_ADDR16_HIGHERA
;
1953 case BFD_RELOC_PPC64_HIGHEST
: r
= R_PPC64_ADDR16_HIGHEST
;
1955 case BFD_RELOC_PPC64_HIGHEST_S
: r
= R_PPC64_ADDR16_HIGHESTA
;
1957 case BFD_RELOC_64_PCREL
: r
= R_PPC64_REL64
;
1959 case BFD_RELOC_64_PLTOFF
: r
= R_PPC64_PLT64
;
1961 case BFD_RELOC_64_PLT_PCREL
: r
= R_PPC64_PLTREL64
;
1963 case BFD_RELOC_PPC_TOC16
: r
= R_PPC64_TOC16
;
1965 case BFD_RELOC_PPC64_TOC16_LO
: r
= R_PPC64_TOC16_LO
;
1967 case BFD_RELOC_PPC64_TOC16_HI
: r
= R_PPC64_TOC16_HI
;
1969 case BFD_RELOC_PPC64_TOC16_HA
: r
= R_PPC64_TOC16_HA
;
1971 case BFD_RELOC_PPC64_TOC
: r
= R_PPC64_TOC
;
1973 case BFD_RELOC_PPC64_PLTGOT16
: r
= R_PPC64_PLTGOT16
;
1975 case BFD_RELOC_PPC64_PLTGOT16_LO
: r
= R_PPC64_PLTGOT16_LO
;
1977 case BFD_RELOC_PPC64_PLTGOT16_HI
: r
= R_PPC64_PLTGOT16_HI
;
1979 case BFD_RELOC_PPC64_PLTGOT16_HA
: r
= R_PPC64_PLTGOT16_HA
;
1981 case BFD_RELOC_PPC64_ADDR16_DS
: r
= R_PPC64_ADDR16_DS
;
1983 case BFD_RELOC_PPC64_ADDR16_LO_DS
: r
= R_PPC64_ADDR16_LO_DS
;
1985 case BFD_RELOC_PPC64_GOT16_DS
: r
= R_PPC64_GOT16_DS
;
1987 case BFD_RELOC_PPC64_GOT16_LO_DS
: r
= R_PPC64_GOT16_LO_DS
;
1989 case BFD_RELOC_PPC64_PLT16_LO_DS
: r
= R_PPC64_PLT16_LO_DS
;
1991 case BFD_RELOC_PPC64_SECTOFF_DS
: r
= R_PPC64_SECTOFF_DS
;
1993 case BFD_RELOC_PPC64_SECTOFF_LO_DS
: r
= R_PPC64_SECTOFF_LO_DS
;
1995 case BFD_RELOC_PPC64_TOC16_DS
: r
= R_PPC64_TOC16_DS
;
1997 case BFD_RELOC_PPC64_TOC16_LO_DS
: r
= R_PPC64_TOC16_LO_DS
;
1999 case BFD_RELOC_PPC64_PLTGOT16_DS
: r
= R_PPC64_PLTGOT16_DS
;
2001 case BFD_RELOC_PPC64_PLTGOT16_LO_DS
: r
= R_PPC64_PLTGOT16_LO_DS
;
2003 case BFD_RELOC_PPC_TLS
: r
= R_PPC64_TLS
;
2005 case BFD_RELOC_PPC_DTPMOD
: r
= R_PPC64_DTPMOD64
;
2007 case BFD_RELOC_PPC_TPREL16
: r
= R_PPC64_TPREL16
;
2009 case BFD_RELOC_PPC_TPREL16_LO
: r
= R_PPC64_TPREL16_LO
;
2011 case BFD_RELOC_PPC_TPREL16_HI
: r
= R_PPC64_TPREL16_HI
;
2013 case BFD_RELOC_PPC_TPREL16_HA
: r
= R_PPC64_TPREL16_HA
;
2015 case BFD_RELOC_PPC_TPREL
: r
= R_PPC64_TPREL64
;
2017 case BFD_RELOC_PPC_DTPREL16
: r
= R_PPC64_DTPREL16
;
2019 case BFD_RELOC_PPC_DTPREL16_LO
: r
= R_PPC64_DTPREL16_LO
;
2021 case BFD_RELOC_PPC_DTPREL16_HI
: r
= R_PPC64_DTPREL16_HI
;
2023 case BFD_RELOC_PPC_DTPREL16_HA
: r
= R_PPC64_DTPREL16_HA
;
2025 case BFD_RELOC_PPC_DTPREL
: r
= R_PPC64_DTPREL64
;
2027 case BFD_RELOC_PPC_GOT_TLSGD16
: r
= R_PPC64_GOT_TLSGD16
;
2029 case BFD_RELOC_PPC_GOT_TLSGD16_LO
: r
= R_PPC64_GOT_TLSGD16_LO
;
2031 case BFD_RELOC_PPC_GOT_TLSGD16_HI
: r
= R_PPC64_GOT_TLSGD16_HI
;
2033 case BFD_RELOC_PPC_GOT_TLSGD16_HA
: r
= R_PPC64_GOT_TLSGD16_HA
;
2035 case BFD_RELOC_PPC_GOT_TLSLD16
: r
= R_PPC64_GOT_TLSLD16
;
2037 case BFD_RELOC_PPC_GOT_TLSLD16_LO
: r
= R_PPC64_GOT_TLSLD16_LO
;
2039 case BFD_RELOC_PPC_GOT_TLSLD16_HI
: r
= R_PPC64_GOT_TLSLD16_HI
;
2041 case BFD_RELOC_PPC_GOT_TLSLD16_HA
: r
= R_PPC64_GOT_TLSLD16_HA
;
2043 case BFD_RELOC_PPC_GOT_TPREL16
: r
= R_PPC64_GOT_TPREL16_DS
;
2045 case BFD_RELOC_PPC_GOT_TPREL16_LO
: r
= R_PPC64_GOT_TPREL16_LO_DS
;
2047 case BFD_RELOC_PPC_GOT_TPREL16_HI
: r
= R_PPC64_GOT_TPREL16_HI
;
2049 case BFD_RELOC_PPC_GOT_TPREL16_HA
: r
= R_PPC64_GOT_TPREL16_HA
;
2051 case BFD_RELOC_PPC_GOT_DTPREL16
: r
= R_PPC64_GOT_DTPREL16_DS
;
2053 case BFD_RELOC_PPC_GOT_DTPREL16_LO
: r
= R_PPC64_GOT_DTPREL16_LO_DS
;
2055 case BFD_RELOC_PPC_GOT_DTPREL16_HI
: r
= R_PPC64_GOT_DTPREL16_HI
;
2057 case BFD_RELOC_PPC_GOT_DTPREL16_HA
: r
= R_PPC64_GOT_DTPREL16_HA
;
2059 case BFD_RELOC_PPC64_TPREL16_DS
: r
= R_PPC64_TPREL16_DS
;
2061 case BFD_RELOC_PPC64_TPREL16_LO_DS
: r
= R_PPC64_TPREL16_LO_DS
;
2063 case BFD_RELOC_PPC64_TPREL16_HIGHER
: r
= R_PPC64_TPREL16_HIGHER
;
2065 case BFD_RELOC_PPC64_TPREL16_HIGHERA
: r
= R_PPC64_TPREL16_HIGHERA
;
2067 case BFD_RELOC_PPC64_TPREL16_HIGHEST
: r
= R_PPC64_TPREL16_HIGHEST
;
2069 case BFD_RELOC_PPC64_TPREL16_HIGHESTA
: r
= R_PPC64_TPREL16_HIGHESTA
;
2071 case BFD_RELOC_PPC64_DTPREL16_DS
: r
= R_PPC64_DTPREL16_DS
;
2073 case BFD_RELOC_PPC64_DTPREL16_LO_DS
: r
= R_PPC64_DTPREL16_LO_DS
;
2075 case BFD_RELOC_PPC64_DTPREL16_HIGHER
: r
= R_PPC64_DTPREL16_HIGHER
;
2077 case BFD_RELOC_PPC64_DTPREL16_HIGHERA
: r
= R_PPC64_DTPREL16_HIGHERA
;
2079 case BFD_RELOC_PPC64_DTPREL16_HIGHEST
: r
= R_PPC64_DTPREL16_HIGHEST
;
2081 case BFD_RELOC_PPC64_DTPREL16_HIGHESTA
: r
= R_PPC64_DTPREL16_HIGHESTA
;
2083 case BFD_RELOC_VTABLE_INHERIT
: r
= R_PPC64_GNU_VTINHERIT
;
2085 case BFD_RELOC_VTABLE_ENTRY
: r
= R_PPC64_GNU_VTENTRY
;
2089 return ppc64_elf_howto_table
[r
];
2092 /* Set the howto pointer for a PowerPC ELF reloc. */
2095 ppc64_elf_info_to_howto (bfd
*abfd ATTRIBUTE_UNUSED
, arelent
*cache_ptr
,
2096 Elf_Internal_Rela
*dst
)
2100 /* Initialize howto table if needed. */
2101 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
2104 type
= ELF64_R_TYPE (dst
->r_info
);
2105 BFD_ASSERT (type
< (sizeof (ppc64_elf_howto_table
)
2106 / sizeof (ppc64_elf_howto_table
[0])));
2107 cache_ptr
->howto
= ppc64_elf_howto_table
[type
];
2110 /* Handle the R_PPC64_ADDR16_HA and similar relocs. */
2112 static bfd_reloc_status_type
2113 ppc64_elf_ha_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2114 void *data
, asection
*input_section
,
2115 bfd
*output_bfd
, char **error_message
)
2117 /* If this is a relocatable link (output_bfd test tells us), just
2118 call the generic function. Any adjustment will be done at final
2120 if (output_bfd
!= NULL
)
2121 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2122 input_section
, output_bfd
, error_message
);
2124 /* Adjust the addend for sign extension of the low 16 bits.
2125 We won't actually be using the low 16 bits, so trashing them
2127 reloc_entry
->addend
+= 0x8000;
2128 return bfd_reloc_continue
;
2131 static bfd_reloc_status_type
2132 ppc64_elf_brtaken_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2133 void *data
, asection
*input_section
,
2134 bfd
*output_bfd
, char **error_message
)
2137 enum elf_ppc64_reloc_type r_type
;
2138 bfd_size_type octets
;
2139 /* Disabled until we sort out how ld should choose 'y' vs 'at'. */
2140 bfd_boolean is_power4
= FALSE
;
2142 /* If this is a relocatable link (output_bfd test tells us), just
2143 call the generic function. Any adjustment will be done at final
2145 if (output_bfd
!= NULL
)
2146 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2147 input_section
, output_bfd
, error_message
);
2149 octets
= reloc_entry
->address
* bfd_octets_per_byte (abfd
);
2150 insn
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ octets
);
2151 insn
&= ~(0x01 << 21);
2152 r_type
= reloc_entry
->howto
->type
;
2153 if (r_type
== R_PPC64_ADDR14_BRTAKEN
2154 || r_type
== R_PPC64_REL14_BRTAKEN
)
2155 insn
|= 0x01 << 21; /* 'y' or 't' bit, lowest bit of BO field. */
2159 /* Set 'a' bit. This is 0b00010 in BO field for branch
2160 on CR(BI) insns (BO == 001at or 011at), and 0b01000
2161 for branch on CTR insns (BO == 1a00t or 1a01t). */
2162 if ((insn
& (0x14 << 21)) == (0x04 << 21))
2164 else if ((insn
& (0x14 << 21)) == (0x10 << 21))
2167 return bfd_reloc_continue
;
2174 if (!bfd_is_com_section (symbol
->section
))
2175 target
= symbol
->value
;
2176 target
+= symbol
->section
->output_section
->vma
;
2177 target
+= symbol
->section
->output_offset
;
2178 target
+= reloc_entry
->addend
;
2180 from
= (reloc_entry
->address
2181 + input_section
->output_offset
2182 + input_section
->output_section
->vma
);
2184 /* Invert 'y' bit if not the default. */
2185 if ((bfd_signed_vma
) (target
- from
) < 0)
2188 bfd_put_32 (abfd
, insn
, (bfd_byte
*) data
+ octets
);
2189 return bfd_reloc_continue
;
2192 static bfd_reloc_status_type
2193 ppc64_elf_sectoff_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2194 void *data
, asection
*input_section
,
2195 bfd
*output_bfd
, char **error_message
)
2197 /* If this is a relocatable link (output_bfd test tells us), just
2198 call the generic function. Any adjustment will be done at final
2200 if (output_bfd
!= NULL
)
2201 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2202 input_section
, output_bfd
, error_message
);
2204 /* Subtract the symbol section base address. */
2205 reloc_entry
->addend
-= symbol
->section
->output_section
->vma
;
2206 return bfd_reloc_continue
;
2209 static bfd_reloc_status_type
2210 ppc64_elf_sectoff_ha_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2211 void *data
, asection
*input_section
,
2212 bfd
*output_bfd
, char **error_message
)
2214 /* If this is a relocatable link (output_bfd test tells us), just
2215 call the generic function. Any adjustment will be done at final
2217 if (output_bfd
!= NULL
)
2218 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2219 input_section
, output_bfd
, error_message
);
2221 /* Subtract the symbol section base address. */
2222 reloc_entry
->addend
-= symbol
->section
->output_section
->vma
;
2224 /* Adjust the addend for sign extension of the low 16 bits. */
2225 reloc_entry
->addend
+= 0x8000;
2226 return bfd_reloc_continue
;
2229 static bfd_reloc_status_type
2230 ppc64_elf_toc_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2231 void *data
, asection
*input_section
,
2232 bfd
*output_bfd
, char **error_message
)
2236 /* If this is a relocatable link (output_bfd test tells us), just
2237 call the generic function. Any adjustment will be done at final
2239 if (output_bfd
!= NULL
)
2240 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2241 input_section
, output_bfd
, error_message
);
2243 TOCstart
= _bfd_get_gp_value (input_section
->output_section
->owner
);
2245 TOCstart
= ppc64_elf_toc (input_section
->output_section
->owner
);
2247 /* Subtract the TOC base address. */
2248 reloc_entry
->addend
-= TOCstart
+ TOC_BASE_OFF
;
2249 return bfd_reloc_continue
;
2252 static bfd_reloc_status_type
2253 ppc64_elf_toc_ha_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2254 void *data
, asection
*input_section
,
2255 bfd
*output_bfd
, char **error_message
)
2259 /* If this is a relocatable link (output_bfd test tells us), just
2260 call the generic function. Any adjustment will be done at final
2262 if (output_bfd
!= NULL
)
2263 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2264 input_section
, output_bfd
, error_message
);
2266 TOCstart
= _bfd_get_gp_value (input_section
->output_section
->owner
);
2268 TOCstart
= ppc64_elf_toc (input_section
->output_section
->owner
);
2270 /* Subtract the TOC base address. */
2271 reloc_entry
->addend
-= TOCstart
+ TOC_BASE_OFF
;
2273 /* Adjust the addend for sign extension of the low 16 bits. */
2274 reloc_entry
->addend
+= 0x8000;
2275 return bfd_reloc_continue
;
2278 static bfd_reloc_status_type
2279 ppc64_elf_toc64_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2280 void *data
, asection
*input_section
,
2281 bfd
*output_bfd
, char **error_message
)
2284 bfd_size_type octets
;
2286 /* If this is a relocatable link (output_bfd test tells us), just
2287 call the generic function. Any adjustment will be done at final
2289 if (output_bfd
!= NULL
)
2290 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2291 input_section
, output_bfd
, error_message
);
2293 TOCstart
= _bfd_get_gp_value (input_section
->output_section
->owner
);
2295 TOCstart
= ppc64_elf_toc (input_section
->output_section
->owner
);
2297 octets
= reloc_entry
->address
* bfd_octets_per_byte (abfd
);
2298 bfd_put_64 (abfd
, TOCstart
+ TOC_BASE_OFF
, (bfd_byte
*) data
+ octets
);
2299 return bfd_reloc_ok
;
2302 static bfd_reloc_status_type
2303 ppc64_elf_unhandled_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2304 void *data
, asection
*input_section
,
2305 bfd
*output_bfd
, char **error_message
)
2307 /* If this is a relocatable link (output_bfd test tells us), just
2308 call the generic function. Any adjustment will be done at final
2310 if (output_bfd
!= NULL
)
2311 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2312 input_section
, output_bfd
, error_message
);
2314 if (error_message
!= NULL
)
2316 static char buf
[60];
2317 sprintf (buf
, "generic linker can't handle %s",
2318 reloc_entry
->howto
->name
);
2319 *error_message
= buf
;
2321 return bfd_reloc_dangerous
;
2324 struct ppc64_elf_obj_tdata
2326 struct elf_obj_tdata elf
;
2328 /* Shortcuts to dynamic linker sections. */
2332 /* TLS local dynamic got entry handling. Suppose for multiple GOT
2333 sections means we potentially need one of these for each input bfd. */
2335 bfd_signed_vma refcount
;
2340 #define ppc64_elf_tdata(bfd) \
2341 ((struct ppc64_elf_obj_tdata *) (bfd)->tdata.any)
2343 #define ppc64_tlsld_got(bfd) \
2344 (&ppc64_elf_tdata (bfd)->tlsld_got)
2346 /* Override the generic function because we store some extras. */
2349 ppc64_elf_mkobject (bfd
*abfd
)
2351 bfd_size_type amt
= sizeof (struct ppc64_elf_obj_tdata
);
2352 abfd
->tdata
.any
= bfd_zalloc (abfd
, amt
);
2353 if (abfd
->tdata
.any
== NULL
)
2358 /* Fix bad default arch selected for a 64 bit input bfd when the
2359 default is 32 bit. */
2362 ppc64_elf_object_p (bfd
*abfd
)
2364 if (abfd
->arch_info
->the_default
&& abfd
->arch_info
->bits_per_word
== 32)
2366 Elf_Internal_Ehdr
*i_ehdr
= elf_elfheader (abfd
);
2368 if (i_ehdr
->e_ident
[EI_CLASS
] == ELFCLASS64
)
2370 /* Relies on arch after 32 bit default being 64 bit default. */
2371 abfd
->arch_info
= abfd
->arch_info
->next
;
2372 BFD_ASSERT (abfd
->arch_info
->bits_per_word
== 64);
2378 /* Support for core dump NOTE sections. */
2381 ppc64_elf_grok_prstatus (bfd
*abfd
, Elf_Internal_Note
*note
)
2383 size_t offset
, raw_size
;
2385 if (note
->descsz
!= 504)
2389 elf_tdata (abfd
)->core_signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
2392 elf_tdata (abfd
)->core_pid
= bfd_get_32 (abfd
, note
->descdata
+ 32);
2398 /* Make a ".reg/999" section. */
2399 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
2400 raw_size
, note
->descpos
+ offset
);
2404 ppc64_elf_grok_psinfo (bfd
*abfd
, Elf_Internal_Note
*note
)
2406 if (note
->descsz
!= 136)
2409 elf_tdata (abfd
)->core_program
2410 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 40, 16);
2411 elf_tdata (abfd
)->core_command
2412 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 56, 80);
2417 /* Merge backend specific data from an object file to the output
2418 object file when linking. */
2421 ppc64_elf_merge_private_bfd_data (bfd
*ibfd
, bfd
*obfd
)
2423 /* Check if we have the same endianess. */
2424 if (ibfd
->xvec
->byteorder
!= obfd
->xvec
->byteorder
2425 && ibfd
->xvec
->byteorder
!= BFD_ENDIAN_UNKNOWN
2426 && obfd
->xvec
->byteorder
!= BFD_ENDIAN_UNKNOWN
)
2430 if (bfd_big_endian (ibfd
))
2431 msg
= _("%s: compiled for a big endian system "
2432 "and target is little endian");
2434 msg
= _("%s: compiled for a little endian system "
2435 "and target is big endian");
2437 (*_bfd_error_handler
) (msg
, bfd_archive_filename (ibfd
));
2439 bfd_set_error (bfd_error_wrong_format
);
2446 /* Add extra PPC sections. */
2448 static struct bfd_elf_special_section
const ppc64_elf_special_sections
[]=
2450 { ".sdata", 6, -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
2451 { ".sbss", 5, -2, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
},
2452 { ".plt", 4, 0, SHT_NOBITS
, 0 },
2453 { ".toc", 4, 0, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
2454 { ".toc1", 5, 0, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
2455 { ".tocbss", 7, 0, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
},
2456 { NULL
, 0, 0, 0, 0 }
2459 struct _ppc64_elf_section_data
2461 struct bfd_elf_section_data elf
;
2463 /* An array with one entry for each opd function descriptor. */
2466 /* Points to the function code section for local opd entries. */
2467 asection
**func_sec
;
2468 /* After editing .opd, adjust references to opd local syms. */
2472 /* An array for toc sections, indexed by offset/8.
2473 Specifies the relocation symbol index used at a given toc offset. */
2477 #define ppc64_elf_section_data(sec) \
2478 ((struct _ppc64_elf_section_data *) elf_section_data (sec))
2481 ppc64_elf_new_section_hook (bfd
*abfd
, asection
*sec
)
2483 struct _ppc64_elf_section_data
*sdata
;
2484 bfd_size_type amt
= sizeof (*sdata
);
2486 sdata
= bfd_zalloc (abfd
, amt
);
2489 sec
->used_by_bfd
= sdata
;
2491 return _bfd_elf_new_section_hook (abfd
, sec
);
2494 /* The following functions are specific to the ELF linker, while
2495 functions above are used generally. Those named ppc64_elf_* are
2496 called by the main ELF linker code. They appear in this file more
2497 or less in the order in which they are called. eg.
2498 ppc64_elf_check_relocs is called early in the link process,
2499 ppc64_elf_finish_dynamic_sections is one of the last functions
2502 PowerPC64-ELF uses a similar scheme to PowerPC64-XCOFF in that
2503 functions have both a function code symbol and a function descriptor
2504 symbol. A call to foo in a relocatable object file looks like:
2511 The function definition in another object file might be:
2515 . .quad .TOC.@tocbase
2521 When the linker resolves the call during a static link, the branch
2522 unsurprisingly just goes to .foo and the .opd information is unused.
2523 If the function definition is in a shared library, things are a little
2524 different: The call goes via a plt call stub, the opd information gets
2525 copied to the plt, and the linker patches the nop.
2533 . addis 12,2,Lfoo@toc@ha # in practice, the call stub
2534 . addi 12,12,Lfoo@toc@l # is slightly optimized, but
2535 . std 2,40(1) # this is the general idea
2543 . Lfoo: reloc (R_PPC64_JMP_SLOT, foo)
2545 The "reloc ()" notation is supposed to indicate that the linker emits
2546 an R_PPC64_JMP_SLOT reloc against foo. The dynamic linker does the opd
2549 What are the difficulties here? Well, firstly, the relocations
2550 examined by the linker in check_relocs are against the function code
2551 sym .foo, while the dynamic relocation in the plt is emitted against
2552 the function descriptor symbol, foo. Somewhere along the line, we need
2553 to carefully copy dynamic link information from one symbol to the other.
2554 Secondly, the generic part of the elf linker will make .foo a dynamic
2555 symbol as is normal for most other backends. We need foo dynamic
2556 instead, at least for an application final link. However, when
2557 creating a shared library containing foo, we need to have both symbols
2558 dynamic so that references to .foo are satisfied during the early
2559 stages of linking. Otherwise the linker might decide to pull in a
2560 definition from some other object, eg. a static library. */
2562 /* The linker needs to keep track of the number of relocs that it
2563 decides to copy as dynamic relocs in check_relocs for each symbol.
2564 This is so that it can later discard them if they are found to be
2565 unnecessary. We store the information in a field extending the
2566 regular ELF linker hash table. */
2568 struct ppc_dyn_relocs
2570 struct ppc_dyn_relocs
*next
;
2572 /* The input section of the reloc. */
2575 /* Total number of relocs copied for the input section. */
2576 bfd_size_type count
;
2578 /* Number of pc-relative relocs copied for the input section. */
2579 bfd_size_type pc_count
;
2582 /* Track GOT entries needed for a given symbol. We might need more
2583 than one got entry per symbol. */
2586 struct got_entry
*next
;
2588 /* The symbol addend that we'll be placing in the GOT. */
2591 /* Unlike other ELF targets, we use separate GOT entries for the same
2592 symbol referenced from different input files. This is to support
2593 automatic multiple TOC/GOT sections, where the TOC base can vary
2594 from one input file to another.
2596 Point to the BFD owning this GOT entry. */
2599 /* Zero for non-tls entries, or TLS_TLS and one of TLS_GD, TLS_LD,
2600 TLS_TPREL or TLS_DTPREL for tls entries. */
2603 /* Reference count until size_dynamic_sections, GOT offset thereafter. */
2606 bfd_signed_vma refcount
;
2611 /* The same for PLT. */
2614 struct plt_entry
*next
;
2620 bfd_signed_vma refcount
;
2625 /* Of those relocs that might be copied as dynamic relocs, this macro
2626 selects those that must be copied when linking a shared library,
2627 even when the symbol is local. */
2629 #define MUST_BE_DYN_RELOC(RTYPE) \
2630 ((RTYPE) != R_PPC64_REL32 \
2631 && (RTYPE) != R_PPC64_REL64 \
2632 && (RTYPE) != R_PPC64_REL30)
2634 /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
2635 copying dynamic variables from a shared lib into an app's dynbss
2636 section, and instead use a dynamic relocation to point into the
2637 shared lib. With code that gcc generates, it's vital that this be
2638 enabled; In the PowerPC64 ABI, the address of a function is actually
2639 the address of a function descriptor, which resides in the .opd
2640 section. gcc uses the descriptor directly rather than going via the
2641 GOT as some other ABI's do, which means that initialized function
2642 pointers must reference the descriptor. Thus, a function pointer
2643 initialized to the address of a function in a shared library will
2644 either require a copy reloc, or a dynamic reloc. Using a copy reloc
2645 redefines the function descriptor symbol to point to the copy. This
2646 presents a problem as a plt entry for that function is also
2647 initialized from the function descriptor symbol and the copy reloc
2648 may not be initialized first. */
2649 #define ELIMINATE_COPY_RELOCS 1
2651 /* Section name for stubs is the associated section name plus this
2653 #define STUB_SUFFIX ".stub"
2656 ppc_stub_long_branch:
2657 Used when a 14 bit branch (or even a 24 bit branch) can't reach its
2658 destination, but a 24 bit branch in a stub section will reach.
2661 ppc_stub_plt_branch:
2662 Similar to the above, but a 24 bit branch in the stub section won't
2663 reach its destination.
2664 . addis %r12,%r2,xxx@toc@ha
2665 . ld %r11,xxx@toc@l(%r12)
2670 Used to call a function in a shared library.
2671 . addis %r12,%r2,xxx@toc@ha
2673 . ld %r11,xxx+0@toc@l(%r12)
2674 . ld %r2,xxx+8@toc@l(%r12)
2676 . ld %r11,xxx+16@toc@l(%r12)
2679 ppc_stub_long_branch and ppc_stub_plt_branch may also have additional
2680 code to adjust the value and save r2 to support multiple toc sections.
2681 A ppc_stub_long_branch with an r2 offset looks like:
2683 . addis %r2,%r2,off@ha
2684 . addi %r2,%r2,off@l
2687 A ppc_stub_plt_branch with an r2 offset looks like:
2689 . addis %r12,%r2,xxx@toc@ha
2690 . ld %r11,xxx@toc@l(%r12)
2691 . addis %r2,%r2,off@ha
2692 . addi %r2,%r2,off@l
2697 enum ppc_stub_type
{
2699 ppc_stub_long_branch
,
2700 ppc_stub_long_branch_r2off
,
2701 ppc_stub_plt_branch
,
2702 ppc_stub_plt_branch_r2off
,
2706 struct ppc_stub_hash_entry
{
2708 /* Base hash table entry structure. */
2709 struct bfd_hash_entry root
;
2711 enum ppc_stub_type stub_type
;
2713 /* The stub section. */
2716 /* Offset within stub_sec of the beginning of this stub. */
2717 bfd_vma stub_offset
;
2719 /* Given the symbol's value and its section we can determine its final
2720 value when building the stubs (so the stub knows where to jump. */
2721 bfd_vma target_value
;
2722 asection
*target_section
;
2724 /* The symbol table entry, if any, that this was derived from. */
2725 struct ppc_link_hash_entry
*h
;
2727 /* And the reloc addend that this was derived from. */
2730 /* Where this stub is being called from, or, in the case of combined
2731 stub sections, the first input section in the group. */
2735 struct ppc_branch_hash_entry
{
2737 /* Base hash table entry structure. */
2738 struct bfd_hash_entry root
;
2740 /* Offset within .branch_lt. */
2741 unsigned int offset
;
2743 /* Generation marker. */
2747 struct ppc_link_hash_entry
2749 struct elf_link_hash_entry elf
;
2751 /* A pointer to the most recently used stub hash entry against this
2753 struct ppc_stub_hash_entry
*stub_cache
;
2755 /* Track dynamic relocs copied for this symbol. */
2756 struct ppc_dyn_relocs
*dyn_relocs
;
2758 /* Link between function code and descriptor symbols. */
2759 struct elf_link_hash_entry
*oh
;
2761 /* Flag function code and descriptor symbols. */
2762 unsigned int is_func
:1;
2763 unsigned int is_func_descriptor
:1;
2764 unsigned int is_entry
:1;
2766 /* Whether global opd sym has been adjusted or not. */
2767 unsigned int adjust_done
:1;
2769 /* Contexts in which symbol is used in the GOT (or TOC).
2770 TLS_GD .. TLS_EXPLICIT bits are or'd into the mask as the
2771 corresponding relocs are encountered during check_relocs.
2772 tls_optimize clears TLS_GD .. TLS_TPREL when optimizing to
2773 indicate the corresponding GOT entry type is not needed.
2774 tls_optimize may also set TLS_TPRELGD when a GD reloc turns into
2775 a TPREL one. We use a separate flag rather than setting TPREL
2776 just for convenience in distinguishing the two cases. */
2777 #define TLS_GD 1 /* GD reloc. */
2778 #define TLS_LD 2 /* LD reloc. */
2779 #define TLS_TPREL 4 /* TPREL reloc, => IE. */
2780 #define TLS_DTPREL 8 /* DTPREL reloc, => LD. */
2781 #define TLS_TLS 16 /* Any TLS reloc. */
2782 #define TLS_EXPLICIT 32 /* Marks TOC section TLS relocs. */
2783 #define TLS_TPRELGD 64 /* TPREL reloc resulting from GD->IE. */
2787 /* ppc64 ELF linker hash table. */
2789 struct ppc_link_hash_table
2791 struct elf_link_hash_table elf
;
2793 /* The stub hash table. */
2794 struct bfd_hash_table stub_hash_table
;
2796 /* Another hash table for plt_branch stubs. */
2797 struct bfd_hash_table branch_hash_table
;
2799 /* Linker stub bfd. */
2802 /* Linker call-backs. */
2803 asection
* (*add_stub_section
) (const char *, asection
*);
2804 void (*layout_sections_again
) (void);
2806 /* Array to keep track of which stub sections have been created, and
2807 information on stub grouping. */
2809 /* This is the section to which stubs in the group will be attached. */
2811 /* The stub section. */
2813 /* Along with elf_gp, specifies the TOC pointer used in this group. */
2817 /* Support for multiple toc sections. */
2818 unsigned int no_multi_toc
;
2819 unsigned int multi_toc_needed
;
2821 /* Temp used when calculating TOC pointers. */
2824 /* Highest input section id. */
2827 /* Highest output section index. */
2830 /* List of input sections for each output section. */
2831 asection
**input_list
;
2833 /* Short-cuts to get to dynamic linker sections. */
2844 /* Shortcut to .__tls_get_addr. */
2845 struct elf_link_hash_entry
*tls_get_addr
;
2848 unsigned long stub_count
[ppc_stub_plt_call
];
2850 /* Set if we should emit symbols for stubs. */
2851 unsigned int emit_stub_syms
;
2854 unsigned int stub_error
;
2856 /* Flag set when small branches are detected. Used to
2857 select suitable defaults for the stub group size. */
2858 unsigned int has_14bit_branch
;
2860 /* Set if we detect a reference undefined weak symbol. */
2861 unsigned int have_undefweak
;
2863 /* Incremented every time we size stubs. */
2864 unsigned int stub_iteration
;
2866 /* Small local sym to section mapping cache. */
2867 struct sym_sec_cache sym_sec
;
2870 /* Get the ppc64 ELF linker hash table from a link_info structure. */
2872 #define ppc_hash_table(p) \
2873 ((struct ppc_link_hash_table *) ((p)->hash))
2875 #define ppc_stub_hash_lookup(table, string, create, copy) \
2876 ((struct ppc_stub_hash_entry *) \
2877 bfd_hash_lookup ((table), (string), (create), (copy)))
2879 #define ppc_branch_hash_lookup(table, string, create, copy) \
2880 ((struct ppc_branch_hash_entry *) \
2881 bfd_hash_lookup ((table), (string), (create), (copy)))
2883 /* Create an entry in the stub hash table. */
2885 static struct bfd_hash_entry
*
2886 stub_hash_newfunc (struct bfd_hash_entry
*entry
,
2887 struct bfd_hash_table
*table
,
2890 /* Allocate the structure if it has not already been allocated by a
2894 entry
= bfd_hash_allocate (table
, sizeof (struct ppc_stub_hash_entry
));
2899 /* Call the allocation method of the superclass. */
2900 entry
= bfd_hash_newfunc (entry
, table
, string
);
2903 struct ppc_stub_hash_entry
*eh
;
2905 /* Initialize the local fields. */
2906 eh
= (struct ppc_stub_hash_entry
*) entry
;
2907 eh
->stub_type
= ppc_stub_none
;
2908 eh
->stub_sec
= NULL
;
2909 eh
->stub_offset
= 0;
2910 eh
->target_value
= 0;
2911 eh
->target_section
= NULL
;
2919 /* Create an entry in the branch hash table. */
2921 static struct bfd_hash_entry
*
2922 branch_hash_newfunc (struct bfd_hash_entry
*entry
,
2923 struct bfd_hash_table
*table
,
2926 /* Allocate the structure if it has not already been allocated by a
2930 entry
= bfd_hash_allocate (table
, sizeof (struct ppc_branch_hash_entry
));
2935 /* Call the allocation method of the superclass. */
2936 entry
= bfd_hash_newfunc (entry
, table
, string
);
2939 struct ppc_branch_hash_entry
*eh
;
2941 /* Initialize the local fields. */
2942 eh
= (struct ppc_branch_hash_entry
*) entry
;
2950 /* Create an entry in a ppc64 ELF linker hash table. */
2952 static struct bfd_hash_entry
*
2953 link_hash_newfunc (struct bfd_hash_entry
*entry
,
2954 struct bfd_hash_table
*table
,
2957 /* Allocate the structure if it has not already been allocated by a
2961 entry
= bfd_hash_allocate (table
, sizeof (struct ppc_link_hash_entry
));
2966 /* Call the allocation method of the superclass. */
2967 entry
= _bfd_elf_link_hash_newfunc (entry
, table
, string
);
2970 struct ppc_link_hash_entry
*eh
= (struct ppc_link_hash_entry
*) entry
;
2972 eh
->stub_cache
= NULL
;
2973 eh
->dyn_relocs
= NULL
;
2976 eh
->is_func_descriptor
= 0;
2978 eh
->adjust_done
= 0;
2985 /* Create a ppc64 ELF linker hash table. */
2987 static struct bfd_link_hash_table
*
2988 ppc64_elf_link_hash_table_create (bfd
*abfd
)
2990 struct ppc_link_hash_table
*htab
;
2991 bfd_size_type amt
= sizeof (struct ppc_link_hash_table
);
2993 htab
= bfd_zmalloc (amt
);
2997 if (! _bfd_elf_link_hash_table_init (&htab
->elf
, abfd
, link_hash_newfunc
))
3003 /* Init the stub hash table too. */
3004 if (!bfd_hash_table_init (&htab
->stub_hash_table
, stub_hash_newfunc
))
3007 /* And the branch hash table. */
3008 if (!bfd_hash_table_init (&htab
->branch_hash_table
, branch_hash_newfunc
))
3011 /* Initializing two fields of the union is just cosmetic. We really
3012 only care about glist, but when compiled on a 32-bit host the
3013 bfd_vma fields are larger. Setting the bfd_vma to zero makes
3014 debugger inspection of these fields look nicer. */
3015 htab
->elf
.init_refcount
.refcount
= 0;
3016 htab
->elf
.init_refcount
.glist
= NULL
;
3017 htab
->elf
.init_offset
.offset
= 0;
3018 htab
->elf
.init_offset
.glist
= NULL
;
3020 return &htab
->elf
.root
;
3023 /* Free the derived linker hash table. */
3026 ppc64_elf_link_hash_table_free (struct bfd_link_hash_table
*hash
)
3028 struct ppc_link_hash_table
*ret
= (struct ppc_link_hash_table
*) hash
;
3030 bfd_hash_table_free (&ret
->stub_hash_table
);
3031 bfd_hash_table_free (&ret
->branch_hash_table
);
3032 _bfd_generic_link_hash_table_free (hash
);
3035 /* Satisfy the ELF linker by filling in some fields in our fake bfd. */
3038 ppc64_elf_init_stub_bfd (bfd
*abfd
, struct bfd_link_info
*info
)
3040 struct ppc_link_hash_table
*htab
;
3042 elf_elfheader (abfd
)->e_ident
[EI_CLASS
] = ELFCLASS64
;
3044 /* Always hook our dynamic sections into the first bfd, which is the
3045 linker created stub bfd. This ensures that the GOT header is at
3046 the start of the output TOC section. */
3047 htab
= ppc_hash_table (info
);
3048 htab
->stub_bfd
= abfd
;
3049 htab
->elf
.dynobj
= abfd
;
3052 /* Build a name for an entry in the stub hash table. */
3055 ppc_stub_name (const asection
*input_section
,
3056 const asection
*sym_sec
,
3057 const struct ppc_link_hash_entry
*h
,
3058 const Elf_Internal_Rela
*rel
)
3063 /* rel->r_addend is actually 64 bit, but who uses more than +/- 2^31
3064 offsets from a sym as a branch target? In fact, we could
3065 probably assume the addend is always zero. */
3066 BFD_ASSERT (((int) rel
->r_addend
& 0xffffffff) == rel
->r_addend
);
3070 len
= 8 + 1 + strlen (h
->elf
.root
.root
.string
) + 1 + 8 + 1;
3071 stub_name
= bfd_malloc (len
);
3072 if (stub_name
!= NULL
)
3074 sprintf (stub_name
, "%08x.%s+%x",
3075 input_section
->id
& 0xffffffff,
3076 h
->elf
.root
.root
.string
,
3077 (int) rel
->r_addend
& 0xffffffff);
3082 len
= 8 + 1 + 8 + 1 + 8 + 1 + 8 + 1;
3083 stub_name
= bfd_malloc (len
);
3084 if (stub_name
!= NULL
)
3086 sprintf (stub_name
, "%08x.%x:%x+%x",
3087 input_section
->id
& 0xffffffff,
3088 sym_sec
->id
& 0xffffffff,
3089 (int) ELF64_R_SYM (rel
->r_info
) & 0xffffffff,
3090 (int) rel
->r_addend
& 0xffffffff);
3096 /* Look up an entry in the stub hash. Stub entries are cached because
3097 creating the stub name takes a bit of time. */
3099 static struct ppc_stub_hash_entry
*
3100 ppc_get_stub_entry (const asection
*input_section
,
3101 const asection
*sym_sec
,
3102 struct elf_link_hash_entry
*hash
,
3103 const Elf_Internal_Rela
*rel
,
3104 struct ppc_link_hash_table
*htab
)
3106 struct ppc_stub_hash_entry
*stub_entry
;
3107 struct ppc_link_hash_entry
*h
= (struct ppc_link_hash_entry
*) hash
;
3108 const asection
*id_sec
;
3110 /* If this input section is part of a group of sections sharing one
3111 stub section, then use the id of the first section in the group.
3112 Stub names need to include a section id, as there may well be
3113 more than one stub used to reach say, printf, and we need to
3114 distinguish between them. */
3115 id_sec
= htab
->stub_group
[input_section
->id
].link_sec
;
3117 if (h
!= NULL
&& h
->stub_cache
!= NULL
3118 && h
->stub_cache
->h
== h
3119 && h
->stub_cache
->id_sec
== id_sec
)
3121 stub_entry
= h
->stub_cache
;
3127 stub_name
= ppc_stub_name (id_sec
, sym_sec
, h
, rel
);
3128 if (stub_name
== NULL
)
3131 stub_entry
= ppc_stub_hash_lookup (&htab
->stub_hash_table
,
3132 stub_name
, FALSE
, FALSE
);
3134 h
->stub_cache
= stub_entry
;
3142 /* Add a new stub entry to the stub hash. Not all fields of the new
3143 stub entry are initialised. */
3145 static struct ppc_stub_hash_entry
*
3146 ppc_add_stub (const char *stub_name
,
3148 struct ppc_link_hash_table
*htab
)
3152 struct ppc_stub_hash_entry
*stub_entry
;
3154 link_sec
= htab
->stub_group
[section
->id
].link_sec
;
3155 stub_sec
= htab
->stub_group
[section
->id
].stub_sec
;
3156 if (stub_sec
== NULL
)
3158 stub_sec
= htab
->stub_group
[link_sec
->id
].stub_sec
;
3159 if (stub_sec
== NULL
)
3165 namelen
= strlen (link_sec
->name
);
3166 len
= namelen
+ sizeof (STUB_SUFFIX
);
3167 s_name
= bfd_alloc (htab
->stub_bfd
, len
);
3171 memcpy (s_name
, link_sec
->name
, namelen
);
3172 memcpy (s_name
+ namelen
, STUB_SUFFIX
, sizeof (STUB_SUFFIX
));
3173 stub_sec
= (*htab
->add_stub_section
) (s_name
, link_sec
);
3174 if (stub_sec
== NULL
)
3176 htab
->stub_group
[link_sec
->id
].stub_sec
= stub_sec
;
3178 htab
->stub_group
[section
->id
].stub_sec
= stub_sec
;
3181 /* Enter this entry into the linker stub hash table. */
3182 stub_entry
= ppc_stub_hash_lookup (&htab
->stub_hash_table
, stub_name
,
3184 if (stub_entry
== NULL
)
3186 (*_bfd_error_handler
) (_("%s: cannot create stub entry %s"),
3187 bfd_archive_filename (section
->owner
),
3192 stub_entry
->stub_sec
= stub_sec
;
3193 stub_entry
->stub_offset
= 0;
3194 stub_entry
->id_sec
= link_sec
;
3198 /* Create sections for linker generated code. */
3201 create_linkage_sections (bfd
*dynobj
, struct bfd_link_info
*info
)
3203 struct ppc_link_hash_table
*htab
;
3206 htab
= ppc_hash_table (info
);
3208 /* Create .sfpr for code to save and restore fp regs. */
3209 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_CODE
| SEC_READONLY
3210 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
3211 htab
->sfpr
= bfd_make_section_anyway (dynobj
, ".sfpr");
3212 if (htab
->sfpr
== NULL
3213 || ! bfd_set_section_flags (dynobj
, htab
->sfpr
, flags
)
3214 || ! bfd_set_section_alignment (dynobj
, htab
->sfpr
, 2))
3217 /* Create .glink for lazy dynamic linking support. */
3218 htab
->glink
= bfd_make_section_anyway (dynobj
, ".glink");
3219 if (htab
->glink
== NULL
3220 || ! bfd_set_section_flags (dynobj
, htab
->glink
, flags
)
3221 || ! bfd_set_section_alignment (dynobj
, htab
->glink
, 2))
3224 /* Create .branch_lt for plt_branch stubs. */
3225 flags
= (SEC_ALLOC
| SEC_LOAD
3226 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
3227 htab
->brlt
= bfd_make_section_anyway (dynobj
, ".branch_lt");
3228 if (htab
->brlt
== NULL
3229 || ! bfd_set_section_flags (dynobj
, htab
->brlt
, flags
)
3230 || ! bfd_set_section_alignment (dynobj
, htab
->brlt
, 3))
3235 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
3236 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
3237 htab
->relbrlt
= bfd_make_section_anyway (dynobj
, ".rela.branch_lt");
3239 || ! bfd_set_section_flags (dynobj
, htab
->relbrlt
, flags
)
3240 || ! bfd_set_section_alignment (dynobj
, htab
->relbrlt
, 3))
3246 /* Create .got and .rela.got sections in ABFD, and .got in dynobj if
3247 not already done. */
3250 create_got_section (bfd
*abfd
, struct bfd_link_info
*info
)
3252 asection
*got
, *relgot
;
3254 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
3258 if (! _bfd_elf_create_got_section (htab
->elf
.dynobj
, info
))
3261 htab
->got
= bfd_get_section_by_name (htab
->elf
.dynobj
, ".got");
3266 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
3267 | SEC_LINKER_CREATED
);
3269 got
= bfd_make_section (abfd
, ".got");
3271 || !bfd_set_section_flags (abfd
, got
, flags
)
3272 || !bfd_set_section_alignment (abfd
, got
, 3))
3275 relgot
= bfd_make_section (abfd
, ".rela.got");
3277 || ! bfd_set_section_flags (abfd
, relgot
, flags
| SEC_READONLY
)
3278 || ! bfd_set_section_alignment (abfd
, relgot
, 3))
3281 ppc64_elf_tdata (abfd
)->got
= got
;
3282 ppc64_elf_tdata (abfd
)->relgot
= relgot
;
3286 /* Create the dynamic sections, and set up shortcuts. */
3289 ppc64_elf_create_dynamic_sections (bfd
*dynobj
, struct bfd_link_info
*info
)
3291 struct ppc_link_hash_table
*htab
;
3293 if (!_bfd_elf_create_dynamic_sections (dynobj
, info
))
3296 htab
= ppc_hash_table (info
);
3298 htab
->got
= bfd_get_section_by_name (dynobj
, ".got");
3299 htab
->plt
= bfd_get_section_by_name (dynobj
, ".plt");
3300 htab
->relplt
= bfd_get_section_by_name (dynobj
, ".rela.plt");
3301 htab
->dynbss
= bfd_get_section_by_name (dynobj
, ".dynbss");
3303 htab
->relbss
= bfd_get_section_by_name (dynobj
, ".rela.bss");
3305 if (!htab
->got
|| !htab
->plt
|| !htab
->relplt
|| !htab
->dynbss
3306 || (!info
->shared
&& !htab
->relbss
))
3312 /* Copy the extra info we tack onto an elf_link_hash_entry. */
3315 ppc64_elf_copy_indirect_symbol
3316 (const struct elf_backend_data
*bed ATTRIBUTE_UNUSED
,
3317 struct elf_link_hash_entry
*dir
,
3318 struct elf_link_hash_entry
*ind
)
3320 struct ppc_link_hash_entry
*edir
, *eind
;
3323 edir
= (struct ppc_link_hash_entry
*) dir
;
3324 eind
= (struct ppc_link_hash_entry
*) ind
;
3326 /* Copy over any dynamic relocs we may have on the indirect sym. */
3327 if (eind
->dyn_relocs
!= NULL
)
3329 if (edir
->dyn_relocs
!= NULL
)
3331 struct ppc_dyn_relocs
**pp
;
3332 struct ppc_dyn_relocs
*p
;
3334 if (eind
->elf
.root
.type
== bfd_link_hash_indirect
)
3337 /* Add reloc counts against the weak sym to the strong sym
3338 list. Merge any entries against the same section. */
3339 for (pp
= &eind
->dyn_relocs
; (p
= *pp
) != NULL
; )
3341 struct ppc_dyn_relocs
*q
;
3343 for (q
= edir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
3344 if (q
->sec
== p
->sec
)
3346 q
->pc_count
+= p
->pc_count
;
3347 q
->count
+= p
->count
;
3354 *pp
= edir
->dyn_relocs
;
3357 edir
->dyn_relocs
= eind
->dyn_relocs
;
3358 eind
->dyn_relocs
= NULL
;
3361 edir
->is_func
|= eind
->is_func
;
3362 edir
->is_func_descriptor
|= eind
->is_func_descriptor
;
3363 edir
->is_entry
|= eind
->is_entry
;
3364 edir
->tls_mask
|= eind
->tls_mask
;
3366 mask
= (ELF_LINK_HASH_REF_DYNAMIC
| ELF_LINK_HASH_REF_REGULAR
3367 | ELF_LINK_HASH_REF_REGULAR_NONWEAK
| ELF_LINK_NON_GOT_REF
3368 | ELF_LINK_HASH_NEEDS_PLT
);
3369 /* If called to transfer flags for a weakdef during processing
3370 of elf_adjust_dynamic_symbol, don't copy ELF_LINK_NON_GOT_REF.
3371 We clear it ourselves for ELIMINATE_COPY_RELOCS. */
3372 if (ELIMINATE_COPY_RELOCS
3373 && eind
->elf
.root
.type
!= bfd_link_hash_indirect
3374 && (edir
->elf
.elf_link_hash_flags
& ELF_LINK_HASH_DYNAMIC_ADJUSTED
) != 0)
3375 mask
&= ~ELF_LINK_NON_GOT_REF
;
3377 edir
->elf
.elf_link_hash_flags
|= eind
->elf
.elf_link_hash_flags
& mask
;
3379 /* If we were called to copy over info for a weak sym, that's all. */
3380 if (eind
->elf
.root
.type
!= bfd_link_hash_indirect
)
3383 /* Copy over got entries that we may have already seen to the
3384 symbol which just became indirect. */
3385 if (eind
->elf
.got
.glist
!= NULL
)
3387 if (edir
->elf
.got
.glist
!= NULL
)
3389 struct got_entry
**entp
;
3390 struct got_entry
*ent
;
3392 for (entp
= &eind
->elf
.got
.glist
; (ent
= *entp
) != NULL
; )
3394 struct got_entry
*dent
;
3396 for (dent
= edir
->elf
.got
.glist
; dent
!= NULL
; dent
= dent
->next
)
3397 if (dent
->addend
== ent
->addend
3398 && dent
->owner
== ent
->owner
3399 && dent
->tls_type
== ent
->tls_type
)
3401 dent
->got
.refcount
+= ent
->got
.refcount
;
3408 *entp
= edir
->elf
.got
.glist
;
3411 edir
->elf
.got
.glist
= eind
->elf
.got
.glist
;
3412 eind
->elf
.got
.glist
= NULL
;
3415 /* And plt entries. */
3416 if (eind
->elf
.plt
.plist
!= NULL
)
3418 if (edir
->elf
.plt
.plist
!= NULL
)
3420 struct plt_entry
**entp
;
3421 struct plt_entry
*ent
;
3423 for (entp
= &eind
->elf
.plt
.plist
; (ent
= *entp
) != NULL
; )
3425 struct plt_entry
*dent
;
3427 for (dent
= edir
->elf
.plt
.plist
; dent
!= NULL
; dent
= dent
->next
)
3428 if (dent
->addend
== ent
->addend
)
3430 dent
->plt
.refcount
+= ent
->plt
.refcount
;
3437 *entp
= edir
->elf
.plt
.plist
;
3440 edir
->elf
.plt
.plist
= eind
->elf
.plt
.plist
;
3441 eind
->elf
.plt
.plist
= NULL
;
3444 if (edir
->elf
.dynindx
== -1)
3446 edir
->elf
.dynindx
= eind
->elf
.dynindx
;
3447 edir
->elf
.dynstr_index
= eind
->elf
.dynstr_index
;
3448 eind
->elf
.dynindx
= -1;
3449 eind
->elf
.dynstr_index
= 0;
3452 BFD_ASSERT (eind
->elf
.dynindx
== -1);
3455 /* Set a flag, used by ppc64_elf_gc_mark_hook, on the entry symbol and
3456 symbols undefined on the command-line. */
3459 ppc64_elf_mark_entry_syms (struct bfd_link_info
*info
)
3461 struct ppc_link_hash_table
*htab
;
3462 struct bfd_sym_chain
*sym
;
3464 htab
= ppc_hash_table (info
);
3465 for (sym
= info
->gc_sym_list
; sym
; sym
= sym
->next
)
3467 struct elf_link_hash_entry
*h
;
3469 h
= elf_link_hash_lookup (&htab
->elf
, sym
->name
, FALSE
, FALSE
, FALSE
);
3471 ((struct ppc_link_hash_entry
*) h
)->is_entry
= 1;
3477 update_local_sym_info (bfd
*abfd
, Elf_Internal_Shdr
*symtab_hdr
,
3478 unsigned long r_symndx
, bfd_vma r_addend
, int tls_type
)
3480 struct got_entry
**local_got_ents
= elf_local_got_ents (abfd
);
3481 char *local_got_tls_masks
;
3483 if (local_got_ents
== NULL
)
3485 bfd_size_type size
= symtab_hdr
->sh_info
;
3487 size
*= sizeof (*local_got_ents
) + sizeof (*local_got_tls_masks
);
3488 local_got_ents
= bfd_zalloc (abfd
, size
);
3489 if (local_got_ents
== NULL
)
3491 elf_local_got_ents (abfd
) = local_got_ents
;
3494 if ((tls_type
& TLS_EXPLICIT
) == 0)
3496 struct got_entry
*ent
;
3498 for (ent
= local_got_ents
[r_symndx
]; ent
!= NULL
; ent
= ent
->next
)
3499 if (ent
->addend
== r_addend
3500 && ent
->owner
== abfd
3501 && ent
->tls_type
== tls_type
)
3505 bfd_size_type amt
= sizeof (*ent
);
3506 ent
= bfd_alloc (abfd
, amt
);
3509 ent
->next
= local_got_ents
[r_symndx
];
3510 ent
->addend
= r_addend
;
3512 ent
->tls_type
= tls_type
;
3513 ent
->got
.refcount
= 0;
3514 local_got_ents
[r_symndx
] = ent
;
3516 ent
->got
.refcount
+= 1;
3519 local_got_tls_masks
= (char *) (local_got_ents
+ symtab_hdr
->sh_info
);
3520 local_got_tls_masks
[r_symndx
] |= tls_type
;
3525 update_plt_info (bfd
*abfd
, struct ppc_link_hash_entry
*eh
, bfd_vma addend
)
3527 struct plt_entry
*ent
;
3529 for (ent
= eh
->elf
.plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
3530 if (ent
->addend
== addend
)
3534 bfd_size_type amt
= sizeof (*ent
);
3535 ent
= bfd_alloc (abfd
, amt
);
3538 ent
->next
= eh
->elf
.plt
.plist
;
3539 ent
->addend
= addend
;
3540 ent
->plt
.refcount
= 0;
3541 eh
->elf
.plt
.plist
= ent
;
3543 ent
->plt
.refcount
+= 1;
3544 eh
->elf
.elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
3549 /* Find the function descriptor hash entry from the given function code
3550 hash entry FH. Link the entries via their OH fields. */
3551 static struct ppc_link_hash_entry
*
3552 get_fdh (struct ppc_link_hash_entry
*fh
, struct ppc_link_hash_table
*htab
)
3554 struct ppc_link_hash_entry
*fdh
= (struct ppc_link_hash_entry
*) fh
->oh
;
3558 const char *fd_name
= fh
->elf
.root
.root
.string
+ 1;
3560 fdh
= (struct ppc_link_hash_entry
*)
3561 elf_link_hash_lookup (&htab
->elf
, fd_name
, FALSE
, FALSE
, FALSE
);
3564 fdh
->is_func_descriptor
= 1;
3574 /* Look through the relocs for a section during the first phase, and
3575 calculate needed space in the global offset table, procedure
3576 linkage table, and dynamic reloc sections. */
3579 ppc64_elf_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
,
3580 asection
*sec
, const Elf_Internal_Rela
*relocs
)
3582 struct ppc_link_hash_table
*htab
;
3583 Elf_Internal_Shdr
*symtab_hdr
;
3584 struct elf_link_hash_entry
**sym_hashes
, **sym_hashes_end
;
3585 const Elf_Internal_Rela
*rel
;
3586 const Elf_Internal_Rela
*rel_end
;
3588 asection
**opd_sym_map
;
3590 if (info
->relocatable
)
3593 /* Don't do anything special with non-loaded, non-alloced sections.
3594 In particular, any relocs in such sections should not affect GOT
3595 and PLT reference counting (ie. we don't allow them to create GOT
3596 or PLT entries), there's no possibility or desire to optimize TLS
3597 relocs, and there's not much point in propagating relocs to shared
3598 libs that the dynamic linker won't relocate. */
3599 if ((sec
->flags
& SEC_ALLOC
) == 0)
3602 htab
= ppc_hash_table (info
);
3603 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
3605 sym_hashes
= elf_sym_hashes (abfd
);
3606 sym_hashes_end
= (sym_hashes
3607 + symtab_hdr
->sh_size
/ sizeof (Elf64_External_Sym
)
3608 - symtab_hdr
->sh_info
);
3612 if (strcmp (bfd_get_section_name (abfd
, sec
), ".opd") == 0)
3614 /* Garbage collection needs some extra help with .opd sections.
3615 We don't want to necessarily keep everything referenced by
3616 relocs in .opd, as that would keep all functions. Instead,
3617 if we reference an .opd symbol (a function descriptor), we
3618 want to keep the function code symbol's section. This is
3619 easy for global symbols, but for local syms we need to keep
3620 information about the associated function section. Later, if
3621 edit_opd deletes entries, we'll use this array to adjust
3622 local syms in .opd. */
3624 asection
*func_section
;
3629 amt
= sec
->_raw_size
* sizeof (union opd_info
) / 24;
3630 opd_sym_map
= bfd_zalloc (abfd
, amt
);
3631 if (opd_sym_map
== NULL
)
3633 ppc64_elf_section_data (sec
)->opd
.func_sec
= opd_sym_map
;
3636 if (htab
->sfpr
== NULL
3637 && !create_linkage_sections (htab
->elf
.dynobj
, info
))
3640 rel_end
= relocs
+ sec
->reloc_count
;
3641 for (rel
= relocs
; rel
< rel_end
; rel
++)
3643 unsigned long r_symndx
;
3644 struct elf_link_hash_entry
*h
;
3645 enum elf_ppc64_reloc_type r_type
;
3648 r_symndx
= ELF64_R_SYM (rel
->r_info
);
3649 if (r_symndx
< symtab_hdr
->sh_info
)
3652 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
3654 r_type
= ELF64_R_TYPE (rel
->r_info
);
3657 case R_PPC64_GOT_TLSLD16
:
3658 case R_PPC64_GOT_TLSLD16_LO
:
3659 case R_PPC64_GOT_TLSLD16_HI
:
3660 case R_PPC64_GOT_TLSLD16_HA
:
3661 ppc64_tlsld_got (abfd
)->refcount
+= 1;
3662 tls_type
= TLS_TLS
| TLS_LD
;
3665 case R_PPC64_GOT_TLSGD16
:
3666 case R_PPC64_GOT_TLSGD16_LO
:
3667 case R_PPC64_GOT_TLSGD16_HI
:
3668 case R_PPC64_GOT_TLSGD16_HA
:
3669 tls_type
= TLS_TLS
| TLS_GD
;
3672 case R_PPC64_GOT_TPREL16_DS
:
3673 case R_PPC64_GOT_TPREL16_LO_DS
:
3674 case R_PPC64_GOT_TPREL16_HI
:
3675 case R_PPC64_GOT_TPREL16_HA
:
3677 info
->flags
|= DF_STATIC_TLS
;
3678 tls_type
= TLS_TLS
| TLS_TPREL
;
3681 case R_PPC64_GOT_DTPREL16_DS
:
3682 case R_PPC64_GOT_DTPREL16_LO_DS
:
3683 case R_PPC64_GOT_DTPREL16_HI
:
3684 case R_PPC64_GOT_DTPREL16_HA
:
3685 tls_type
= TLS_TLS
| TLS_DTPREL
;
3687 sec
->has_tls_reloc
= 1;
3691 case R_PPC64_GOT16_DS
:
3692 case R_PPC64_GOT16_HA
:
3693 case R_PPC64_GOT16_HI
:
3694 case R_PPC64_GOT16_LO
:
3695 case R_PPC64_GOT16_LO_DS
:
3696 /* This symbol requires a global offset table entry. */
3697 sec
->has_gp_reloc
= 1;
3698 if (ppc64_elf_tdata (abfd
)->got
== NULL
3699 && !create_got_section (abfd
, info
))
3704 struct ppc_link_hash_entry
*eh
;
3705 struct got_entry
*ent
;
3707 eh
= (struct ppc_link_hash_entry
*) h
;
3708 for (ent
= eh
->elf
.got
.glist
; ent
!= NULL
; ent
= ent
->next
)
3709 if (ent
->addend
== rel
->r_addend
3710 && ent
->owner
== abfd
3711 && ent
->tls_type
== tls_type
)
3715 bfd_size_type amt
= sizeof (*ent
);
3716 ent
= bfd_alloc (abfd
, amt
);
3719 ent
->next
= eh
->elf
.got
.glist
;
3720 ent
->addend
= rel
->r_addend
;
3722 ent
->tls_type
= tls_type
;
3723 ent
->got
.refcount
= 0;
3724 eh
->elf
.got
.glist
= ent
;
3726 ent
->got
.refcount
+= 1;
3727 eh
->tls_mask
|= tls_type
;
3730 /* This is a global offset table entry for a local symbol. */
3731 if (!update_local_sym_info (abfd
, symtab_hdr
, r_symndx
,
3732 rel
->r_addend
, tls_type
))
3736 case R_PPC64_PLT16_HA
:
3737 case R_PPC64_PLT16_HI
:
3738 case R_PPC64_PLT16_LO
:
3741 /* This symbol requires a procedure linkage table entry. We
3742 actually build the entry in adjust_dynamic_symbol,
3743 because this might be a case of linking PIC code without
3744 linking in any dynamic objects, in which case we don't
3745 need to generate a procedure linkage table after all. */
3748 /* It does not make sense to have a procedure linkage
3749 table entry for a local symbol. */
3750 bfd_set_error (bfd_error_bad_value
);
3754 if (!update_plt_info (abfd
, (struct ppc_link_hash_entry
*) h
,
3759 /* The following relocations don't need to propagate the
3760 relocation if linking a shared object since they are
3761 section relative. */
3762 case R_PPC64_SECTOFF
:
3763 case R_PPC64_SECTOFF_LO
:
3764 case R_PPC64_SECTOFF_HI
:
3765 case R_PPC64_SECTOFF_HA
:
3766 case R_PPC64_SECTOFF_DS
:
3767 case R_PPC64_SECTOFF_LO_DS
:
3768 case R_PPC64_DTPREL16
:
3769 case R_PPC64_DTPREL16_LO
:
3770 case R_PPC64_DTPREL16_HI
:
3771 case R_PPC64_DTPREL16_HA
:
3772 case R_PPC64_DTPREL16_DS
:
3773 case R_PPC64_DTPREL16_LO_DS
:
3774 case R_PPC64_DTPREL16_HIGHER
:
3775 case R_PPC64_DTPREL16_HIGHERA
:
3776 case R_PPC64_DTPREL16_HIGHEST
:
3777 case R_PPC64_DTPREL16_HIGHESTA
:
3782 case R_PPC64_TOC16_LO
:
3783 case R_PPC64_TOC16_HI
:
3784 case R_PPC64_TOC16_HA
:
3785 case R_PPC64_TOC16_DS
:
3786 case R_PPC64_TOC16_LO_DS
:
3787 sec
->has_gp_reloc
= 1;
3790 /* This relocation describes the C++ object vtable hierarchy.
3791 Reconstruct it for later use during GC. */
3792 case R_PPC64_GNU_VTINHERIT
:
3793 if (!_bfd_elf64_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
3797 /* This relocation describes which C++ vtable entries are actually
3798 used. Record for later use during GC. */
3799 case R_PPC64_GNU_VTENTRY
:
3800 if (!_bfd_elf64_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
3805 case R_PPC64_REL14_BRTAKEN
:
3806 case R_PPC64_REL14_BRNTAKEN
:
3807 htab
->has_14bit_branch
= 1;
3812 && h
->root
.root
.string
[0] == '.'
3813 && h
->root
.root
.string
[1] != 0)
3815 /* We may need a .plt entry if the function this reloc
3816 refers to is in a shared lib. */
3817 if (!update_plt_info (abfd
, (struct ppc_link_hash_entry
*) h
,
3820 if (h
== htab
->tls_get_addr
)
3821 sec
->has_tls_reloc
= 1;
3822 else if ((strncmp (h
->root
.root
.string
, ".__tls_get_addr", 15)
3824 && (h
->root
.root
.string
[15] == 0
3825 || h
->root
.root
.string
[15] == '@'))
3827 htab
->tls_get_addr
= h
;
3828 sec
->has_tls_reloc
= 1;
3833 case R_PPC64_TPREL64
:
3834 tls_type
= TLS_EXPLICIT
| TLS_TLS
| TLS_TPREL
;
3836 info
->flags
|= DF_STATIC_TLS
;
3839 case R_PPC64_DTPMOD64
:
3840 if (rel
+ 1 < rel_end
3841 && rel
[1].r_info
== ELF64_R_INFO (r_symndx
, R_PPC64_DTPREL64
)
3842 && rel
[1].r_offset
== rel
->r_offset
+ 8)
3843 tls_type
= TLS_EXPLICIT
| TLS_TLS
| TLS_GD
;
3845 tls_type
= TLS_EXPLICIT
| TLS_TLS
| TLS_LD
;
3848 case R_PPC64_DTPREL64
:
3849 tls_type
= TLS_EXPLICIT
| TLS_TLS
| TLS_DTPREL
;
3851 && rel
[-1].r_info
== ELF64_R_INFO (r_symndx
, R_PPC64_DTPMOD64
)
3852 && rel
[-1].r_offset
== rel
->r_offset
- 8)
3853 /* This is the second reloc of a dtpmod, dtprel pair.
3854 Don't mark with TLS_DTPREL. */
3858 sec
->has_tls_reloc
= 1;
3861 struct ppc_link_hash_entry
*eh
;
3862 eh
= (struct ppc_link_hash_entry
*) h
;
3863 eh
->tls_mask
|= tls_type
;
3866 if (!update_local_sym_info (abfd
, symtab_hdr
, r_symndx
,
3867 rel
->r_addend
, tls_type
))
3870 if (ppc64_elf_section_data (sec
)->t_symndx
== NULL
)
3872 /* One extra to simplify get_tls_mask. */
3873 bfd_size_type amt
= sec
->_raw_size
* sizeof (unsigned) / 8 + 1;
3874 ppc64_elf_section_data (sec
)->t_symndx
= bfd_zalloc (abfd
, amt
);
3875 if (ppc64_elf_section_data (sec
)->t_symndx
== NULL
)
3878 BFD_ASSERT (rel
->r_offset
% 8 == 0);
3879 ppc64_elf_section_data (sec
)->t_symndx
[rel
->r_offset
/ 8] = r_symndx
;
3881 /* Mark the second slot of a GD or LD entry.
3882 -1 to indicate GD and -2 to indicate LD. */
3883 if (tls_type
== (TLS_EXPLICIT
| TLS_TLS
| TLS_GD
))
3884 ppc64_elf_section_data (sec
)->t_symndx
[rel
->r_offset
/ 8 + 1] = -1;
3885 else if (tls_type
== (TLS_EXPLICIT
| TLS_TLS
| TLS_LD
))
3886 ppc64_elf_section_data (sec
)->t_symndx
[rel
->r_offset
/ 8 + 1] = -2;
3889 case R_PPC64_TPREL16
:
3890 case R_PPC64_TPREL16_LO
:
3891 case R_PPC64_TPREL16_HI
:
3892 case R_PPC64_TPREL16_HA
:
3893 case R_PPC64_TPREL16_DS
:
3894 case R_PPC64_TPREL16_LO_DS
:
3895 case R_PPC64_TPREL16_HIGHER
:
3896 case R_PPC64_TPREL16_HIGHERA
:
3897 case R_PPC64_TPREL16_HIGHEST
:
3898 case R_PPC64_TPREL16_HIGHESTA
:
3901 info
->flags
|= DF_STATIC_TLS
;
3906 case R_PPC64_ADDR64
:
3907 if (opd_sym_map
!= NULL
3909 && h
->root
.root
.string
[0] == '.'
3910 && h
->root
.root
.string
[1] != 0)
3911 get_fdh ((struct ppc_link_hash_entry
*) h
, htab
);
3913 if (opd_sym_map
!= NULL
3915 && rel
+ 1 < rel_end
3916 && ELF64_R_TYPE ((rel
+ 1)->r_info
) == R_PPC64_TOC
)
3920 s
= bfd_section_from_r_symndx (abfd
, &htab
->sym_sec
, sec
,
3925 opd_sym_map
[rel
->r_offset
/ 24] = s
;
3932 case R_PPC64_ADDR14
:
3933 case R_PPC64_ADDR14_BRNTAKEN
:
3934 case R_PPC64_ADDR14_BRTAKEN
:
3935 case R_PPC64_ADDR16
:
3936 case R_PPC64_ADDR16_DS
:
3937 case R_PPC64_ADDR16_HA
:
3938 case R_PPC64_ADDR16_HI
:
3939 case R_PPC64_ADDR16_HIGHER
:
3940 case R_PPC64_ADDR16_HIGHERA
:
3941 case R_PPC64_ADDR16_HIGHEST
:
3942 case R_PPC64_ADDR16_HIGHESTA
:
3943 case R_PPC64_ADDR16_LO
:
3944 case R_PPC64_ADDR16_LO_DS
:
3945 case R_PPC64_ADDR24
:
3946 case R_PPC64_ADDR32
:
3947 case R_PPC64_UADDR16
:
3948 case R_PPC64_UADDR32
:
3949 case R_PPC64_UADDR64
:
3951 if (h
!= NULL
&& !info
->shared
)
3952 /* We may need a copy reloc. */
3953 h
->elf_link_hash_flags
|= ELF_LINK_NON_GOT_REF
;
3955 /* Don't propagate .opd relocs. */
3956 if (NO_OPD_RELOCS
&& opd_sym_map
!= NULL
)
3959 /* If we are creating a shared library, and this is a reloc
3960 against a global symbol, or a non PC relative reloc
3961 against a local symbol, then we need to copy the reloc
3962 into the shared library. However, if we are linking with
3963 -Bsymbolic, we do not need to copy a reloc against a
3964 global symbol which is defined in an object we are
3965 including in the link (i.e., DEF_REGULAR is set). At
3966 this point we have not seen all the input files, so it is
3967 possible that DEF_REGULAR is not set now but will be set
3968 later (it is never cleared). In case of a weak definition,
3969 DEF_REGULAR may be cleared later by a strong definition in
3970 a shared library. We account for that possibility below by
3971 storing information in the dyn_relocs field of the hash
3972 table entry. A similar situation occurs when creating
3973 shared libraries and symbol visibility changes render the
3976 If on the other hand, we are creating an executable, we
3977 may need to keep relocations for symbols satisfied by a
3978 dynamic library if we manage to avoid copy relocs for the
3982 && (MUST_BE_DYN_RELOC (r_type
)
3984 && (! info
->symbolic
3985 || h
->root
.type
== bfd_link_hash_defweak
3986 || (h
->elf_link_hash_flags
3987 & ELF_LINK_HASH_DEF_REGULAR
) == 0))))
3988 || (ELIMINATE_COPY_RELOCS
3991 && (h
->root
.type
== bfd_link_hash_defweak
3992 || (h
->elf_link_hash_flags
3993 & ELF_LINK_HASH_DEF_REGULAR
) == 0)))
3995 struct ppc_dyn_relocs
*p
;
3996 struct ppc_dyn_relocs
**head
;
3998 /* We must copy these reloc types into the output file.
3999 Create a reloc section in dynobj and make room for
4006 name
= (bfd_elf_string_from_elf_section
4008 elf_elfheader (abfd
)->e_shstrndx
,
4009 elf_section_data (sec
)->rel_hdr
.sh_name
));
4013 if (strncmp (name
, ".rela", 5) != 0
4014 || strcmp (bfd_get_section_name (abfd
, sec
),
4017 (*_bfd_error_handler
)
4018 (_("%s: bad relocation section name `%s\'"),
4019 bfd_archive_filename (abfd
), name
);
4020 bfd_set_error (bfd_error_bad_value
);
4023 dynobj
= htab
->elf
.dynobj
;
4024 sreloc
= bfd_get_section_by_name (dynobj
, name
);
4029 sreloc
= bfd_make_section (dynobj
, name
);
4030 flags
= (SEC_HAS_CONTENTS
| SEC_READONLY
4031 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
4032 if ((sec
->flags
& SEC_ALLOC
) != 0)
4033 flags
|= SEC_ALLOC
| SEC_LOAD
;
4035 || ! bfd_set_section_flags (dynobj
, sreloc
, flags
)
4036 || ! bfd_set_section_alignment (dynobj
, sreloc
, 3))
4039 elf_section_data (sec
)->sreloc
= sreloc
;
4042 /* If this is a global symbol, we count the number of
4043 relocations we need for this symbol. */
4046 head
= &((struct ppc_link_hash_entry
*) h
)->dyn_relocs
;
4050 /* Track dynamic relocs needed for local syms too.
4051 We really need local syms available to do this
4055 s
= bfd_section_from_r_symndx (abfd
, &htab
->sym_sec
,
4060 head
= ((struct ppc_dyn_relocs
**)
4061 &elf_section_data (s
)->local_dynrel
);
4065 if (p
== NULL
|| p
->sec
!= sec
)
4067 p
= bfd_alloc (htab
->elf
.dynobj
, sizeof *p
);
4078 if (!MUST_BE_DYN_RELOC (r_type
))
4091 /* Return the section that should be marked against GC for a given
4095 ppc64_elf_gc_mark_hook (asection
*sec
,
4096 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
4097 Elf_Internal_Rela
*rel
,
4098 struct elf_link_hash_entry
*h
,
4099 Elf_Internal_Sym
*sym
)
4101 asection
*rsec
= NULL
;
4105 enum elf_ppc64_reloc_type r_type
;
4106 struct ppc_link_hash_entry
*fdh
;
4108 r_type
= ELF64_R_TYPE (rel
->r_info
);
4111 case R_PPC64_GNU_VTINHERIT
:
4112 case R_PPC64_GNU_VTENTRY
:
4116 switch (h
->root
.type
)
4118 case bfd_link_hash_defined
:
4119 case bfd_link_hash_defweak
:
4120 fdh
= (struct ppc_link_hash_entry
*) h
;
4122 /* Function descriptor syms cause the associated
4123 function code sym section to be marked. */
4124 if (fdh
->is_func_descriptor
)
4125 rsec
= fdh
->oh
->root
.u
.def
.section
;
4127 /* Function entry syms return NULL if they are in .opd
4128 and are not ._start (or others undefined on the ld
4129 command line). Thus we avoid marking all function
4130 sections, as all functions are referenced in .opd. */
4131 else if ((fdh
->oh
!= NULL
4132 && ((struct ppc_link_hash_entry
*) fdh
->oh
)->is_entry
)
4133 || ppc64_elf_section_data (sec
)->opd
.func_sec
== NULL
)
4134 rsec
= h
->root
.u
.def
.section
;
4137 case bfd_link_hash_common
:
4138 rsec
= h
->root
.u
.c
.p
->section
;
4148 asection
**opd_sym_section
;
4150 rsec
= bfd_section_from_elf_index (sec
->owner
, sym
->st_shndx
);
4151 opd_sym_section
= ppc64_elf_section_data (rsec
)->opd
.func_sec
;
4152 if (opd_sym_section
!= NULL
)
4153 rsec
= opd_sym_section
[sym
->st_value
/ 24];
4154 else if (ppc64_elf_section_data (sec
)->opd
.func_sec
!= NULL
)
4161 /* Update the .got, .plt. and dynamic reloc reference counts for the
4162 section being removed. */
4165 ppc64_elf_gc_sweep_hook (bfd
*abfd
, struct bfd_link_info
*info
,
4166 asection
*sec
, const Elf_Internal_Rela
*relocs
)
4168 struct ppc_link_hash_table
*htab
;
4169 Elf_Internal_Shdr
*symtab_hdr
;
4170 struct elf_link_hash_entry
**sym_hashes
;
4171 struct got_entry
**local_got_ents
;
4172 const Elf_Internal_Rela
*rel
, *relend
;
4174 if ((sec
->flags
& SEC_ALLOC
) == 0)
4177 elf_section_data (sec
)->local_dynrel
= NULL
;
4179 htab
= ppc_hash_table (info
);
4180 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
4181 sym_hashes
= elf_sym_hashes (abfd
);
4182 local_got_ents
= elf_local_got_ents (abfd
);
4184 relend
= relocs
+ sec
->reloc_count
;
4185 for (rel
= relocs
; rel
< relend
; rel
++)
4187 unsigned long r_symndx
;
4188 enum elf_ppc64_reloc_type r_type
;
4189 struct elf_link_hash_entry
*h
= NULL
;
4192 r_symndx
= ELF64_R_SYM (rel
->r_info
);
4193 r_type
= ELF64_R_TYPE (rel
->r_info
);
4194 if (r_symndx
>= symtab_hdr
->sh_info
)
4196 struct ppc_link_hash_entry
*eh
;
4197 struct ppc_dyn_relocs
**pp
;
4198 struct ppc_dyn_relocs
*p
;
4200 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
4201 eh
= (struct ppc_link_hash_entry
*) h
;
4203 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; pp
= &p
->next
)
4206 /* Everything must go for SEC. */
4214 case R_PPC64_GOT_TLSLD16
:
4215 case R_PPC64_GOT_TLSLD16_LO
:
4216 case R_PPC64_GOT_TLSLD16_HI
:
4217 case R_PPC64_GOT_TLSLD16_HA
:
4218 ppc64_tlsld_got (abfd
)->refcount
-= 1;
4219 tls_type
= TLS_TLS
| TLS_LD
;
4222 case R_PPC64_GOT_TLSGD16
:
4223 case R_PPC64_GOT_TLSGD16_LO
:
4224 case R_PPC64_GOT_TLSGD16_HI
:
4225 case R_PPC64_GOT_TLSGD16_HA
:
4226 tls_type
= TLS_TLS
| TLS_GD
;
4229 case R_PPC64_GOT_TPREL16_DS
:
4230 case R_PPC64_GOT_TPREL16_LO_DS
:
4231 case R_PPC64_GOT_TPREL16_HI
:
4232 case R_PPC64_GOT_TPREL16_HA
:
4233 tls_type
= TLS_TLS
| TLS_TPREL
;
4236 case R_PPC64_GOT_DTPREL16_DS
:
4237 case R_PPC64_GOT_DTPREL16_LO_DS
:
4238 case R_PPC64_GOT_DTPREL16_HI
:
4239 case R_PPC64_GOT_DTPREL16_HA
:
4240 tls_type
= TLS_TLS
| TLS_DTPREL
;
4244 case R_PPC64_GOT16_DS
:
4245 case R_PPC64_GOT16_HA
:
4246 case R_PPC64_GOT16_HI
:
4247 case R_PPC64_GOT16_LO
:
4248 case R_PPC64_GOT16_LO_DS
:
4251 struct got_entry
*ent
;
4256 ent
= local_got_ents
[r_symndx
];
4258 for (; ent
!= NULL
; ent
= ent
->next
)
4259 if (ent
->addend
== rel
->r_addend
4260 && ent
->owner
== abfd
4261 && ent
->tls_type
== tls_type
)
4265 if (ent
->got
.refcount
> 0)
4266 ent
->got
.refcount
-= 1;
4270 case R_PPC64_PLT16_HA
:
4271 case R_PPC64_PLT16_HI
:
4272 case R_PPC64_PLT16_LO
:
4276 case R_PPC64_REL14_BRNTAKEN
:
4277 case R_PPC64_REL14_BRTAKEN
:
4281 struct plt_entry
*ent
;
4283 for (ent
= h
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
4284 if (ent
->addend
== rel
->r_addend
)
4288 if (ent
->plt
.refcount
> 0)
4289 ent
->plt
.refcount
-= 1;
4300 /* Called via elf_link_hash_traverse to transfer dynamic linking
4301 information on function code symbol entries to their corresponding
4302 function descriptor symbol entries. */
4304 func_desc_adjust (struct elf_link_hash_entry
*h
, void *inf
)
4306 struct bfd_link_info
*info
;
4307 struct ppc_link_hash_table
*htab
;
4308 struct plt_entry
*ent
;
4309 struct ppc_link_hash_entry
*fh
;
4310 struct ppc_link_hash_entry
*fdh
;
4311 bfd_boolean force_local
;
4313 fh
= (struct ppc_link_hash_entry
*) h
;
4314 if (fh
->elf
.root
.type
== bfd_link_hash_indirect
)
4317 if (fh
->elf
.root
.type
== bfd_link_hash_warning
)
4318 fh
= (struct ppc_link_hash_entry
*) fh
->elf
.root
.u
.i
.link
;
4321 htab
= ppc_hash_table (info
);
4323 /* If this is a function code symbol, transfer dynamic linking
4324 information to the function descriptor symbol. */
4328 if (fh
->elf
.root
.type
== bfd_link_hash_undefweak
4329 && (fh
->elf
.elf_link_hash_flags
& ELF_LINK_HASH_REF_REGULAR
))
4330 htab
->have_undefweak
= TRUE
;
4332 for (ent
= fh
->elf
.plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
4333 if (ent
->plt
.refcount
> 0)
4336 || fh
->elf
.root
.root
.string
[0] != '.'
4337 || fh
->elf
.root
.root
.string
[1] == '\0')
4340 /* Find the corresponding function descriptor symbol. Create it
4341 as undefined if necessary. */
4343 fdh
= get_fdh (fh
, htab
);
4345 while (fdh
->elf
.root
.type
== bfd_link_hash_indirect
4346 || fdh
->elf
.root
.type
== bfd_link_hash_warning
)
4347 fdh
= (struct ppc_link_hash_entry
*) fdh
->elf
.root
.u
.i
.link
;
4351 && (fh
->elf
.root
.type
== bfd_link_hash_undefined
4352 || fh
->elf
.root
.type
== bfd_link_hash_undefweak
))
4356 struct bfd_link_hash_entry
*bh
;
4358 abfd
= fh
->elf
.root
.u
.undef
.abfd
;
4359 newsym
= bfd_make_empty_symbol (abfd
);
4360 newsym
->name
= fh
->elf
.root
.root
.string
+ 1;
4361 newsym
->section
= bfd_und_section_ptr
;
4363 newsym
->flags
= BSF_OBJECT
;
4364 if (fh
->elf
.root
.type
== bfd_link_hash_undefweak
)
4365 newsym
->flags
|= BSF_WEAK
;
4367 bh
= &fdh
->elf
.root
;
4368 if ( !(_bfd_generic_link_add_one_symbol
4369 (info
, abfd
, newsym
->name
, newsym
->flags
,
4370 newsym
->section
, newsym
->value
, NULL
, FALSE
, FALSE
, &bh
)))
4374 fdh
= (struct ppc_link_hash_entry
*) bh
;
4375 fdh
->elf
.elf_link_hash_flags
&= ~ELF_LINK_NON_ELF
;
4377 fdh
->elf
.type
= STT_OBJECT
;
4381 && (fdh
->elf
.elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0
4383 || (fdh
->elf
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
4384 || (fdh
->elf
.elf_link_hash_flags
& ELF_LINK_HASH_REF_DYNAMIC
) != 0
4385 || (fdh
->elf
.root
.type
== bfd_link_hash_undefweak
4386 && ELF_ST_VISIBILITY (fdh
->elf
.other
) == STV_DEFAULT
)))
4388 if (fdh
->elf
.dynindx
== -1)
4389 if (! bfd_elf64_link_record_dynamic_symbol (info
, &fdh
->elf
))
4391 fdh
->elf
.elf_link_hash_flags
4392 |= (fh
->elf
.elf_link_hash_flags
& (ELF_LINK_HASH_REF_REGULAR
4393 | ELF_LINK_HASH_REF_DYNAMIC
4394 | ELF_LINK_HASH_REF_REGULAR_NONWEAK
4395 | ELF_LINK_NON_GOT_REF
));
4396 if (ELF_ST_VISIBILITY (fh
->elf
.other
) == STV_DEFAULT
)
4398 fdh
->elf
.plt
.plist
= fh
->elf
.plt
.plist
;
4399 fdh
->elf
.elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
4401 fdh
->is_func_descriptor
= 1;
4406 /* Now that the info is on the function descriptor, clear the
4407 function code sym info. Any function code syms for which we
4408 don't have a definition in a regular file, we force local.
4409 This prevents a shared library from exporting syms that have
4410 been imported from another library. Function code syms that
4411 are really in the library we must leave global to prevent the
4412 linker dragging in a definition from a static library. */
4415 && ((fh
->elf
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0
4417 || (fdh
->elf
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0
4418 || (fdh
->elf
.elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) != 0));
4419 _bfd_elf_link_hash_hide_symbol (info
, &fh
->elf
, force_local
);
4424 #define MIN_SAVE_FPR 14
4425 #define MAX_SAVE_FPR 31
4427 /* Called near the start of bfd_elf_size_dynamic_sections. We use
4428 this hook to a) provide some gcc support functions, and b) transfer
4429 dynamic linking information gathered so far on function code symbol
4430 entries, to their corresponding function descriptor symbol entries. */
4432 ppc64_elf_func_desc_adjust (bfd
*obfd ATTRIBUTE_UNUSED
,
4433 struct bfd_link_info
*info
)
4435 struct ppc_link_hash_table
*htab
;
4436 unsigned int lowest_savef
= MAX_SAVE_FPR
+ 2;
4437 unsigned int lowest_restf
= MAX_SAVE_FPR
+ 2;
4439 struct elf_link_hash_entry
*h
;
4443 htab
= ppc_hash_table (info
);
4445 if (htab
->sfpr
== NULL
)
4446 /* We don't have any relocs. */
4449 /* First provide any missing ._savef* and ._restf* functions. */
4450 memcpy (sym
, "._savef14", 10);
4451 for (i
= MIN_SAVE_FPR
; i
<= MAX_SAVE_FPR
; i
++)
4453 sym
[7] = i
/ 10 + '0';
4454 sym
[8] = i
% 10 + '0';
4455 h
= elf_link_hash_lookup (&htab
->elf
, sym
, FALSE
, FALSE
, TRUE
);
4457 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
4459 if (lowest_savef
> i
)
4461 h
->root
.type
= bfd_link_hash_defined
;
4462 h
->root
.u
.def
.section
= htab
->sfpr
;
4463 h
->root
.u
.def
.value
= (i
- lowest_savef
) * 4;
4465 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
4466 _bfd_elf_link_hash_hide_symbol (info
, h
, TRUE
);
4470 memcpy (sym
, "._restf14", 10);
4471 for (i
= MIN_SAVE_FPR
; i
<= MAX_SAVE_FPR
; i
++)
4473 sym
[7] = i
/ 10 + '0';
4474 sym
[8] = i
% 10 + '0';
4475 h
= elf_link_hash_lookup (&htab
->elf
, sym
, FALSE
, FALSE
, TRUE
);
4477 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
4479 if (lowest_restf
> i
)
4481 h
->root
.type
= bfd_link_hash_defined
;
4482 h
->root
.u
.def
.section
= htab
->sfpr
;
4483 h
->root
.u
.def
.value
= ((MAX_SAVE_FPR
+ 2 - lowest_savef
) * 4
4484 + (i
- lowest_restf
) * 4);
4486 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
4487 _bfd_elf_link_hash_hide_symbol (info
, h
, TRUE
);
4491 elf_link_hash_traverse (&htab
->elf
, func_desc_adjust
, info
);
4493 htab
->sfpr
->_raw_size
= ((MAX_SAVE_FPR
+ 2 - lowest_savef
) * 4
4494 + (MAX_SAVE_FPR
+ 2 - lowest_restf
) * 4);
4496 if (htab
->sfpr
->_raw_size
== 0)
4498 if (!htab
->have_undefweak
)
4500 _bfd_strip_section_from_output (info
, htab
->sfpr
);
4504 htab
->sfpr
->_raw_size
= 4;
4507 p
= bfd_alloc (htab
->elf
.dynobj
, htab
->sfpr
->_raw_size
);
4510 htab
->sfpr
->contents
= p
;
4512 for (i
= lowest_savef
; i
<= MAX_SAVE_FPR
; i
++)
4514 unsigned int fpr
= i
<< 21;
4515 unsigned int stackoff
= (1 << 16) - (MAX_SAVE_FPR
+ 1 - i
) * 8;
4516 bfd_put_32 (htab
->elf
.dynobj
, STFD_FR0_0R1
+ fpr
+ stackoff
, p
);
4519 if (lowest_savef
<= MAX_SAVE_FPR
)
4521 bfd_put_32 (htab
->elf
.dynobj
, BLR
, p
);
4525 for (i
= lowest_restf
; i
<= MAX_SAVE_FPR
; i
++)
4527 unsigned int fpr
= i
<< 21;
4528 unsigned int stackoff
= (1 << 16) - (MAX_SAVE_FPR
+ 1 - i
) * 8;
4529 bfd_put_32 (htab
->elf
.dynobj
, LFD_FR0_0R1
+ fpr
+ stackoff
, p
);
4532 if (lowest_restf
<= MAX_SAVE_FPR
4533 || htab
->sfpr
->_raw_size
== 4)
4535 bfd_put_32 (htab
->elf
.dynobj
, BLR
, p
);
4541 /* Adjust a symbol defined by a dynamic object and referenced by a
4542 regular object. The current definition is in some section of the
4543 dynamic object, but we're not including those sections. We have to
4544 change the definition to something the rest of the link can
4548 ppc64_elf_adjust_dynamic_symbol (struct bfd_link_info
*info
,
4549 struct elf_link_hash_entry
*h
)
4551 struct ppc_link_hash_table
*htab
;
4553 unsigned int power_of_two
;
4555 htab
= ppc_hash_table (info
);
4557 /* Deal with function syms. */
4558 if (h
->type
== STT_FUNC
4559 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
4561 /* Clear procedure linkage table information for any symbol that
4562 won't need a .plt entry. */
4563 struct plt_entry
*ent
;
4564 for (ent
= h
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
4565 if (ent
->plt
.refcount
> 0)
4567 if (!((struct ppc_link_hash_entry
*) h
)->is_func_descriptor
4569 || SYMBOL_CALLS_LOCAL (info
, h
)
4570 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
4571 && h
->root
.type
== bfd_link_hash_undefweak
))
4573 h
->plt
.plist
= NULL
;
4574 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
4578 h
->plt
.plist
= NULL
;
4580 /* If this is a weak symbol, and there is a real definition, the
4581 processor independent code will have arranged for us to see the
4582 real definition first, and we can just use the same value. */
4583 if (h
->weakdef
!= NULL
)
4585 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
4586 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
4587 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
4588 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
4589 if (ELIMINATE_COPY_RELOCS
)
4590 h
->elf_link_hash_flags
4591 = ((h
->elf_link_hash_flags
& ~ELF_LINK_NON_GOT_REF
)
4592 | (h
->weakdef
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
));
4596 /* If we are creating a shared library, we must presume that the
4597 only references to the symbol are via the global offset table.
4598 For such cases we need not do anything here; the relocations will
4599 be handled correctly by relocate_section. */
4603 /* If there are no references to this symbol that do not use the
4604 GOT, we don't need to generate a copy reloc. */
4605 if ((h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0)
4608 if (ELIMINATE_COPY_RELOCS
)
4610 struct ppc_link_hash_entry
* eh
;
4611 struct ppc_dyn_relocs
*p
;
4613 eh
= (struct ppc_link_hash_entry
*) h
;
4614 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
4616 s
= p
->sec
->output_section
;
4617 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
4621 /* If we didn't find any dynamic relocs in read-only sections, then
4622 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
4625 h
->elf_link_hash_flags
&= ~ELF_LINK_NON_GOT_REF
;
4630 if (h
->plt
.plist
!= NULL
)
4632 /* We should never get here, but unfortunately there are versions
4633 of gcc out there that improperly (for this ABI) put initialized
4634 function pointers, vtable refs and suchlike in read-only
4635 sections. Allow them to proceed, but warn that this might
4636 break at runtime. */
4637 (*_bfd_error_handler
)
4638 (_("copy reloc against `%s' requires lazy plt linking; "
4639 "avoid setting LD_BIND_NOW=1 or upgrade gcc"),
4640 h
->root
.root
.string
);
4643 /* This is a reference to a symbol defined by a dynamic object which
4644 is not a function. */
4646 /* We must allocate the symbol in our .dynbss section, which will
4647 become part of the .bss section of the executable. There will be
4648 an entry for this symbol in the .dynsym section. The dynamic
4649 object will contain position independent code, so all references
4650 from the dynamic object to this symbol will go through the global
4651 offset table. The dynamic linker will use the .dynsym entry to
4652 determine the address it must put in the global offset table, so
4653 both the dynamic object and the regular object will refer to the
4654 same memory location for the variable. */
4656 /* We must generate a R_PPC64_COPY reloc to tell the dynamic linker
4657 to copy the initial value out of the dynamic object and into the
4658 runtime process image. We need to remember the offset into the
4659 .rela.bss section we are going to use. */
4660 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
4662 htab
->relbss
->_raw_size
+= sizeof (Elf64_External_Rela
);
4663 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_COPY
;
4666 /* We need to figure out the alignment required for this symbol. I
4667 have no idea how ELF linkers handle this. */
4668 power_of_two
= bfd_log2 (h
->size
);
4669 if (power_of_two
> 4)
4672 /* Apply the required alignment. */
4674 s
->_raw_size
= BFD_ALIGN (s
->_raw_size
, (bfd_size_type
) (1 << power_of_two
));
4675 if (power_of_two
> bfd_get_section_alignment (htab
->elf
.dynobj
, s
))
4677 if (! bfd_set_section_alignment (htab
->elf
.dynobj
, s
, power_of_two
))
4681 /* Define the symbol as being at this point in the section. */
4682 h
->root
.u
.def
.section
= s
;
4683 h
->root
.u
.def
.value
= s
->_raw_size
;
4685 /* Increment the section size to make room for the symbol. */
4686 s
->_raw_size
+= h
->size
;
4691 /* If given a function descriptor symbol, hide both the function code
4692 sym and the descriptor. */
4694 ppc64_elf_hide_symbol (struct bfd_link_info
*info
,
4695 struct elf_link_hash_entry
*h
,
4696 bfd_boolean force_local
)
4698 _bfd_elf_link_hash_hide_symbol (info
, h
, force_local
);
4700 if (((struct ppc_link_hash_entry
*) h
)->is_func_descriptor
)
4702 struct elf_link_hash_entry
*fh
= ((struct ppc_link_hash_entry
*) h
)->oh
;
4707 struct ppc_link_hash_table
*htab
;
4710 /* We aren't supposed to use alloca in BFD because on
4711 systems which do not have alloca the version in libiberty
4712 calls xmalloc, which might cause the program to crash
4713 when it runs out of memory. This function doesn't have a
4714 return status, so there's no way to gracefully return an
4715 error. So cheat. We know that string[-1] can be safely
4716 dereferenced; It's either a string in an ELF string
4717 table, or allocated in an objalloc structure. */
4719 p
= h
->root
.root
.string
- 1;
4722 htab
= ppc_hash_table (info
);
4723 fh
= elf_link_hash_lookup (&htab
->elf
, p
, FALSE
, FALSE
, FALSE
);
4726 /* Unfortunately, if it so happens that the string we were
4727 looking for was allocated immediately before this string,
4728 then we overwrote the string terminator. That's the only
4729 reason the lookup should fail. */
4732 q
= h
->root
.root
.string
+ strlen (h
->root
.root
.string
);
4733 while (q
>= h
->root
.root
.string
&& *q
== *p
)
4735 if (q
< h
->root
.root
.string
&& *p
== '.')
4736 fh
= elf_link_hash_lookup (&htab
->elf
, p
, FALSE
, FALSE
, FALSE
);
4740 ((struct ppc_link_hash_entry
*) h
)->oh
= fh
;
4741 ((struct ppc_link_hash_entry
*) fh
)->oh
= h
;
4745 _bfd_elf_link_hash_hide_symbol (info
, fh
, force_local
);
4750 get_sym_h (struct elf_link_hash_entry
**hp
, Elf_Internal_Sym
**symp
,
4751 asection
**symsecp
, char **tls_maskp
, Elf_Internal_Sym
**locsymsp
,
4752 unsigned long r_symndx
, bfd
*ibfd
)
4754 Elf_Internal_Shdr
*symtab_hdr
= &elf_tdata (ibfd
)->symtab_hdr
;
4756 if (r_symndx
>= symtab_hdr
->sh_info
)
4758 struct elf_link_hash_entry
**sym_hashes
= elf_sym_hashes (ibfd
);
4759 struct elf_link_hash_entry
*h
;
4761 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
4762 while (h
->root
.type
== bfd_link_hash_indirect
4763 || h
->root
.type
== bfd_link_hash_warning
)
4764 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
4772 if (symsecp
!= NULL
)
4774 asection
*symsec
= NULL
;
4775 if (h
->root
.type
== bfd_link_hash_defined
4776 || h
->root
.type
== bfd_link_hash_defweak
)
4777 symsec
= h
->root
.u
.def
.section
;
4781 if (tls_maskp
!= NULL
)
4783 struct ppc_link_hash_entry
*eh
;
4785 eh
= (struct ppc_link_hash_entry
*) h
;
4786 *tls_maskp
= &eh
->tls_mask
;
4791 Elf_Internal_Sym
*sym
;
4792 Elf_Internal_Sym
*locsyms
= *locsymsp
;
4794 if (locsyms
== NULL
)
4796 locsyms
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
4797 if (locsyms
== NULL
)
4798 locsyms
= bfd_elf_get_elf_syms (ibfd
, symtab_hdr
,
4799 symtab_hdr
->sh_info
,
4800 0, NULL
, NULL
, NULL
);
4801 if (locsyms
== NULL
)
4803 *locsymsp
= locsyms
;
4805 sym
= locsyms
+ r_symndx
;
4813 if (symsecp
!= NULL
)
4815 asection
*symsec
= NULL
;
4816 if ((sym
->st_shndx
!= SHN_UNDEF
4817 && sym
->st_shndx
< SHN_LORESERVE
)
4818 || sym
->st_shndx
> SHN_HIRESERVE
)
4819 symsec
= bfd_section_from_elf_index (ibfd
, sym
->st_shndx
);
4823 if (tls_maskp
!= NULL
)
4825 struct got_entry
**lgot_ents
;
4829 lgot_ents
= elf_local_got_ents (ibfd
);
4830 if (lgot_ents
!= NULL
)
4832 char *lgot_masks
= (char *) (lgot_ents
+ symtab_hdr
->sh_info
);
4833 tls_mask
= &lgot_masks
[r_symndx
];
4835 *tls_maskp
= tls_mask
;
4841 /* Returns TLS_MASKP for the given REL symbol. Function return is 0 on
4842 error, 2 on a toc GD type suitable for optimization, 3 on a toc LD
4843 type suitable for optimization, and 1 otherwise. */
4846 get_tls_mask (char **tls_maskp
, unsigned long *toc_symndx
,
4847 Elf_Internal_Sym
**locsymsp
,
4848 const Elf_Internal_Rela
*rel
, bfd
*ibfd
)
4850 unsigned long r_symndx
;
4852 struct elf_link_hash_entry
*h
;
4853 Elf_Internal_Sym
*sym
;
4857 r_symndx
= ELF64_R_SYM (rel
->r_info
);
4858 if (!get_sym_h (&h
, &sym
, &sec
, tls_maskp
, locsymsp
, r_symndx
, ibfd
))
4861 if ((*tls_maskp
!= NULL
&& **tls_maskp
!= 0)
4863 || ppc64_elf_section_data (sec
)->t_symndx
== NULL
)
4866 /* Look inside a TOC section too. */
4869 BFD_ASSERT (h
->root
.type
== bfd_link_hash_defined
);
4870 off
= h
->root
.u
.def
.value
;
4873 off
= sym
->st_value
;
4874 off
+= rel
->r_addend
;
4875 BFD_ASSERT (off
% 8 == 0);
4876 r_symndx
= ppc64_elf_section_data (sec
)->t_symndx
[off
/ 8];
4877 next_r
= ppc64_elf_section_data (sec
)->t_symndx
[off
/ 8 + 1];
4878 if (!get_sym_h (&h
, &sym
, &sec
, tls_maskp
, locsymsp
, r_symndx
, ibfd
))
4880 if (toc_symndx
!= NULL
)
4881 *toc_symndx
= r_symndx
;
4883 || ((h
->root
.type
== bfd_link_hash_defined
4884 || h
->root
.type
== bfd_link_hash_defweak
)
4885 && !(h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
)))
4886 && (next_r
== -1 || next_r
== -2))
4891 /* Adjust all global syms defined in opd sections. In gcc generated
4892 code these will already have been done, but I suppose we have to
4893 cater for all sorts of hand written assembly. */
4896 adjust_opd_syms (struct elf_link_hash_entry
*h
, void *inf ATTRIBUTE_UNUSED
)
4898 struct ppc_link_hash_entry
*eh
;
4902 if (h
->root
.type
== bfd_link_hash_indirect
)
4905 if (h
->root
.type
== bfd_link_hash_warning
)
4906 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
4908 if (h
->root
.type
!= bfd_link_hash_defined
4909 && h
->root
.type
!= bfd_link_hash_defweak
)
4912 eh
= (struct ppc_link_hash_entry
*) h
;
4913 if (eh
->adjust_done
)
4916 sym_sec
= eh
->elf
.root
.u
.def
.section
;
4918 && elf_section_data (sym_sec
) != NULL
4919 && (opd_adjust
= ppc64_elf_section_data (sym_sec
)->opd
.adjust
) != NULL
)
4921 eh
->elf
.root
.u
.def
.value
+= opd_adjust
[eh
->elf
.root
.u
.def
.value
/ 24];
4922 eh
->adjust_done
= 1;
4927 /* Remove unused Official Procedure Descriptor entries. Currently we
4928 only remove those associated with functions in discarded link-once
4929 sections, or weakly defined functions that have been overridden. It
4930 would be possible to remove many more entries for statically linked
4934 ppc64_elf_edit_opd (bfd
*obfd
, struct bfd_link_info
*info
)
4937 bfd_boolean some_edited
= FALSE
;
4939 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
4942 Elf_Internal_Rela
*relstart
, *rel
, *relend
;
4943 Elf_Internal_Shdr
*symtab_hdr
;
4944 Elf_Internal_Sym
*local_syms
;
4945 struct elf_link_hash_entry
**sym_hashes
;
4949 bfd_boolean need_edit
;
4951 sec
= bfd_get_section_by_name (ibfd
, ".opd");
4955 amt
= sec
->_raw_size
* sizeof (long) / 24;
4956 adjust
= ppc64_elf_section_data (sec
)->opd
.adjust
;
4959 /* Must be a ld -r link. ie. check_relocs hasn't been
4961 adjust
= bfd_zalloc (obfd
, amt
);
4962 ppc64_elf_section_data (sec
)->opd
.adjust
= adjust
;
4964 memset (adjust
, 0, amt
);
4966 if (sec
->output_section
== bfd_abs_section_ptr
)
4969 /* Look through the section relocs. */
4970 if ((sec
->flags
& SEC_RELOC
) == 0 || sec
->reloc_count
== 0)
4974 symtab_hdr
= &elf_tdata (ibfd
)->symtab_hdr
;
4975 sym_hashes
= elf_sym_hashes (ibfd
);
4977 /* Read the relocations. */
4978 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
4980 if (relstart
== NULL
)
4983 /* First run through the relocs to check they are sane, and to
4984 determine whether we need to edit this opd section. */
4987 relend
= relstart
+ sec
->reloc_count
;
4988 for (rel
= relstart
; rel
< relend
; )
4990 enum elf_ppc64_reloc_type r_type
;
4991 unsigned long r_symndx
;
4993 struct elf_link_hash_entry
*h
;
4994 Elf_Internal_Sym
*sym
;
4996 /* .opd contains a regular array of 24 byte entries. We're
4997 only interested in the reloc pointing to a function entry
4999 if (rel
->r_offset
!= offset
5000 || rel
+ 1 >= relend
5001 || (rel
+ 1)->r_offset
!= offset
+ 8)
5003 /* If someone messes with .opd alignment then after a
5004 "ld -r" we might have padding in the middle of .opd.
5005 Also, there's nothing to prevent someone putting
5006 something silly in .opd with the assembler. No .opd
5007 optimization for them! */
5008 (*_bfd_error_handler
)
5009 (_("%s: .opd is not a regular array of opd entries"),
5010 bfd_archive_filename (ibfd
));
5015 if ((r_type
= ELF64_R_TYPE (rel
->r_info
)) != R_PPC64_ADDR64
5016 || (r_type
= ELF64_R_TYPE ((rel
+ 1)->r_info
)) != R_PPC64_TOC
)
5018 (*_bfd_error_handler
)
5019 (_("%s: unexpected reloc type %u in .opd section"),
5020 bfd_archive_filename (ibfd
), r_type
);
5025 r_symndx
= ELF64_R_SYM (rel
->r_info
);
5026 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
5030 if (sym_sec
== NULL
|| sym_sec
->owner
== NULL
)
5032 const char *sym_name
;
5034 sym_name
= h
->root
.root
.string
;
5036 sym_name
= bfd_elf_local_sym_name (ibfd
, sym
);
5038 (*_bfd_error_handler
)
5039 (_("%s: undefined sym `%s' in .opd section"),
5040 bfd_archive_filename (ibfd
),
5046 /* opd entries are always for functions defined in the
5047 current input bfd. If the symbol isn't defined in the
5048 input bfd, then we won't be using the function in this
5049 bfd; It must be defined in a linkonce section in another
5050 bfd, or is weak. It's also possible that we are
5051 discarding the function due to a linker script /DISCARD/,
5052 which we test for via the output_section. */
5053 if (sym_sec
->owner
!= ibfd
5054 || sym_sec
->output_section
== bfd_abs_section_ptr
)
5059 /* Allow for the possibility of a reloc on the third word. */
5061 && rel
->r_offset
== offset
- 8)
5067 Elf_Internal_Rela
*write_rel
;
5068 bfd_byte
*rptr
, *wptr
;
5071 /* This seems a waste of time as input .opd sections are all
5072 zeros as generated by gcc, but I suppose there's no reason
5073 this will always be so. We might start putting something in
5074 the third word of .opd entries. */
5075 if ((sec
->flags
& SEC_IN_MEMORY
) == 0)
5077 bfd_byte
*loc
= bfd_alloc (ibfd
, sec
->_raw_size
);
5079 || !bfd_get_section_contents (ibfd
, sec
, loc
, 0,
5083 if (local_syms
!= NULL
5084 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
5086 if (elf_section_data (sec
)->relocs
!= relstart
)
5090 sec
->contents
= loc
;
5091 sec
->flags
|= (SEC_IN_MEMORY
| SEC_HAS_CONTENTS
);
5094 elf_section_data (sec
)->relocs
= relstart
;
5096 wptr
= sec
->contents
;
5097 rptr
= sec
->contents
;
5098 write_rel
= relstart
;
5101 for (rel
= relstart
; rel
< relend
; rel
++)
5103 unsigned long r_symndx
;
5105 struct elf_link_hash_entry
*h
;
5106 Elf_Internal_Sym
*sym
;
5108 r_symndx
= ELF64_R_SYM (rel
->r_info
);
5109 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
5113 if (rel
->r_offset
== offset
)
5115 struct ppc_link_hash_entry
*fdh
= NULL
;
5117 fdh
= get_fdh ((struct ppc_link_hash_entry
*) h
,
5118 ppc_hash_table (info
));
5120 skip
= (sym_sec
->owner
!= ibfd
5121 || sym_sec
->output_section
== bfd_abs_section_ptr
);
5124 if (h
!= NULL
&& sym_sec
->owner
== ibfd
)
5126 /* Arrange for the function descriptor sym
5128 fdh
->elf
.root
.u
.def
.value
= 0;
5129 fdh
->elf
.root
.u
.def
.section
= sym_sec
;
5134 /* We'll be keeping this opd entry. */
5138 /* Redefine the function descriptor symbol to
5139 this location in the opd section. It is
5140 necessary to update the value here rather
5141 than using an array of adjustments as we do
5142 for local symbols, because various places
5143 in the generic ELF code use the value
5144 stored in u.def.value. */
5145 fdh
->elf
.root
.u
.def
.value
= wptr
- sec
->contents
;
5146 fdh
->adjust_done
= 1;
5149 /* Local syms are a bit tricky. We could
5150 tweak them as they can be cached, but
5151 we'd need to look through the local syms
5152 for the function descriptor sym which we
5153 don't have at the moment. So keep an
5154 array of adjustments. */
5155 adjust
[rel
->r_offset
/ 24] = wptr
- rptr
;
5158 memcpy (wptr
, rptr
, 24);
5167 BFD_ASSERT (MUST_BE_DYN_RELOC (ELF64_R_TYPE (rel
->r_info
)));
5170 /* We won't be needing dynamic relocs here. */
5171 struct ppc_dyn_relocs
**pp
;
5172 struct ppc_dyn_relocs
*p
;
5175 pp
= &((struct ppc_link_hash_entry
*) h
)->dyn_relocs
;
5176 else if (sym_sec
!= NULL
)
5177 pp
= ((struct ppc_dyn_relocs
**)
5178 &elf_section_data (sym_sec
)->local_dynrel
);
5180 pp
= ((struct ppc_dyn_relocs
**)
5181 &elf_section_data (sec
)->local_dynrel
);
5182 while ((p
= *pp
) != NULL
)
5197 /* We need to adjust any reloc offsets to point to the
5198 new opd entries. While we're at it, we may as well
5199 remove redundant relocs. */
5200 rel
->r_offset
+= wptr
- rptr
;
5201 if (write_rel
!= rel
)
5202 memcpy (write_rel
, rel
, sizeof (*rel
));
5207 sec
->_cooked_size
= wptr
- sec
->contents
;
5208 sec
->reloc_count
= write_rel
- relstart
;
5209 /* Fudge the size too, as this is used later in
5210 elf_bfd_final_link if we are emitting relocs. */
5211 elf_section_data (sec
)->rel_hdr
.sh_size
5212 = sec
->reloc_count
* elf_section_data (sec
)->rel_hdr
.sh_entsize
;
5213 BFD_ASSERT (elf_section_data (sec
)->rel_hdr2
== NULL
);
5216 else if (elf_section_data (sec
)->relocs
!= relstart
)
5219 if (local_syms
!= NULL
5220 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
5222 if (!info
->keep_memory
)
5225 symtab_hdr
->contents
= (unsigned char *) local_syms
;
5230 elf_link_hash_traverse (elf_hash_table (info
), adjust_opd_syms
, NULL
);
5235 /* Set htab->tls_get_addr and call the generic ELF tls_setup function. */
5238 ppc64_elf_tls_setup (bfd
*obfd
, struct bfd_link_info
*info
)
5240 struct ppc_link_hash_table
*htab
;
5242 htab
= ppc_hash_table (info
);
5243 if (htab
->tls_get_addr
!= NULL
)
5245 struct elf_link_hash_entry
*h
= htab
->tls_get_addr
;
5247 while (h
->root
.type
== bfd_link_hash_indirect
5248 || h
->root
.type
== bfd_link_hash_warning
)
5249 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
5251 htab
->tls_get_addr
= h
;
5254 return _bfd_elf_tls_setup (obfd
, info
);
5257 /* Run through all the TLS relocs looking for optimization
5258 opportunities. The linker has been hacked (see ppc64elf.em) to do
5259 a preliminary section layout so that we know the TLS segment
5260 offsets. We can't optimize earlier because some optimizations need
5261 to know the tp offset, and we need to optimize before allocating
5262 dynamic relocations. */
5265 ppc64_elf_tls_optimize (bfd
*obfd ATTRIBUTE_UNUSED
, struct bfd_link_info
*info
)
5269 struct ppc_link_hash_table
*htab
;
5271 if (info
->relocatable
|| info
->shared
)
5274 htab
= ppc_hash_table (info
);
5275 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
5277 Elf_Internal_Sym
*locsyms
= NULL
;
5279 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
5280 if (sec
->has_tls_reloc
&& !bfd_is_abs_section (sec
->output_section
))
5282 Elf_Internal_Rela
*relstart
, *rel
, *relend
;
5283 int expecting_tls_get_addr
;
5285 /* Read the relocations. */
5286 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
5288 if (relstart
== NULL
)
5291 expecting_tls_get_addr
= 0;
5292 relend
= relstart
+ sec
->reloc_count
;
5293 for (rel
= relstart
; rel
< relend
; rel
++)
5295 enum elf_ppc64_reloc_type r_type
;
5296 unsigned long r_symndx
;
5297 struct elf_link_hash_entry
*h
;
5298 Elf_Internal_Sym
*sym
;
5301 char tls_set
, tls_clear
, tls_type
= 0;
5303 bfd_boolean ok_tprel
, is_local
;
5305 r_symndx
= ELF64_R_SYM (rel
->r_info
);
5306 if (!get_sym_h (&h
, &sym
, &sym_sec
, &tls_mask
, &locsyms
,
5310 if (elf_section_data (sec
)->relocs
!= relstart
)
5313 && (elf_tdata (ibfd
)->symtab_hdr
.contents
5314 != (unsigned char *) locsyms
))
5321 if (h
->root
.type
!= bfd_link_hash_defined
5322 && h
->root
.type
!= bfd_link_hash_defweak
)
5324 value
= h
->root
.u
.def
.value
;
5328 value
= sym
->st_value
;
5330 if (elf_section_data (sym_sec
) != NULL
)
5333 adjust
= ppc64_elf_section_data (sym_sec
)->opd
.adjust
;
5335 value
+= adjust
[value
/ 24];
5342 || !(h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
))
5345 value
+= sym_sec
->output_offset
;
5346 value
+= sym_sec
->output_section
->vma
;
5347 value
-= htab
->elf
.tls_sec
->vma
;
5348 ok_tprel
= (value
+ TP_OFFSET
+ ((bfd_vma
) 1 << 31)
5349 < (bfd_vma
) 1 << 32);
5352 r_type
= ELF64_R_TYPE (rel
->r_info
);
5355 case R_PPC64_GOT_TLSLD16
:
5356 case R_PPC64_GOT_TLSLD16_LO
:
5357 case R_PPC64_GOT_TLSLD16_HI
:
5358 case R_PPC64_GOT_TLSLD16_HA
:
5359 /* These relocs should never be against a symbol
5360 defined in a shared lib. Leave them alone if
5361 that turns out to be the case. */
5362 ppc64_tlsld_got (ibfd
)->refcount
-= 1;
5369 tls_type
= TLS_TLS
| TLS_LD
;
5370 expecting_tls_get_addr
= 1;
5373 case R_PPC64_GOT_TLSGD16
:
5374 case R_PPC64_GOT_TLSGD16_LO
:
5375 case R_PPC64_GOT_TLSGD16_HI
:
5376 case R_PPC64_GOT_TLSGD16_HA
:
5382 tls_set
= TLS_TLS
| TLS_TPRELGD
;
5384 tls_type
= TLS_TLS
| TLS_GD
;
5385 expecting_tls_get_addr
= 1;
5388 case R_PPC64_GOT_TPREL16_DS
:
5389 case R_PPC64_GOT_TPREL16_LO_DS
:
5390 case R_PPC64_GOT_TPREL16_HI
:
5391 case R_PPC64_GOT_TPREL16_HA
:
5392 expecting_tls_get_addr
= 0;
5397 tls_clear
= TLS_TPREL
;
5398 tls_type
= TLS_TLS
| TLS_TPREL
;
5405 case R_PPC64_REL14_BRTAKEN
:
5406 case R_PPC64_REL14_BRNTAKEN
:
5409 && h
== htab
->tls_get_addr
)
5411 if (!expecting_tls_get_addr
5413 && ((ELF64_R_TYPE (rel
[-1].r_info
)
5415 || (ELF64_R_TYPE (rel
[-1].r_info
)
5416 == R_PPC64_TOC16_LO
)))
5418 /* Check for toc tls entries. */
5422 retval
= get_tls_mask (&toc_tls
, NULL
, &locsyms
,
5426 if (toc_tls
!= NULL
)
5427 expecting_tls_get_addr
= retval
> 1;
5430 if (expecting_tls_get_addr
)
5432 struct plt_entry
*ent
;
5433 for (ent
= h
->plt
.plist
; ent
; ent
= ent
->next
)
5434 if (ent
->addend
== 0)
5436 if (ent
->plt
.refcount
> 0)
5437 ent
->plt
.refcount
-= 1;
5442 expecting_tls_get_addr
= 0;
5445 case R_PPC64_TPREL64
:
5446 expecting_tls_get_addr
= 0;
5450 tls_set
= TLS_EXPLICIT
;
5451 tls_clear
= TLS_TPREL
;
5457 case R_PPC64_DTPMOD64
:
5458 expecting_tls_get_addr
= 0;
5459 if (rel
+ 1 < relend
5461 == ELF64_R_INFO (r_symndx
, R_PPC64_DTPREL64
))
5462 && rel
[1].r_offset
== rel
->r_offset
+ 8)
5466 tls_set
= TLS_EXPLICIT
| TLS_GD
;
5469 tls_set
= TLS_EXPLICIT
| TLS_GD
| TLS_TPRELGD
;
5478 tls_set
= TLS_EXPLICIT
;
5484 expecting_tls_get_addr
= 0;
5488 if ((tls_set
& TLS_EXPLICIT
) == 0)
5490 struct got_entry
*ent
;
5492 /* Adjust got entry for this reloc. */
5496 ent
= elf_local_got_ents (ibfd
)[r_symndx
];
5498 for (; ent
!= NULL
; ent
= ent
->next
)
5499 if (ent
->addend
== rel
->r_addend
5500 && ent
->owner
== ibfd
5501 && ent
->tls_type
== tls_type
)
5508 /* We managed to get rid of a got entry. */
5509 if (ent
->got
.refcount
> 0)
5510 ent
->got
.refcount
-= 1;
5515 struct ppc_link_hash_entry
* eh
;
5516 struct ppc_dyn_relocs
**pp
;
5517 struct ppc_dyn_relocs
*p
;
5519 /* Adjust dynamic relocs. */
5520 eh
= (struct ppc_link_hash_entry
*) h
;
5521 for (pp
= &eh
->dyn_relocs
;
5526 /* If we got rid of a DTPMOD/DTPREL reloc
5527 pair then we'll lose one or two dyn
5529 if (tls_set
== (TLS_EXPLICIT
| TLS_GD
))
5538 *tls_mask
|= tls_set
;
5539 *tls_mask
&= ~tls_clear
;
5542 if (elf_section_data (sec
)->relocs
!= relstart
)
5547 && (elf_tdata (ibfd
)->symtab_hdr
.contents
5548 != (unsigned char *) locsyms
))
5550 if (!info
->keep_memory
)
5553 elf_tdata (ibfd
)->symtab_hdr
.contents
= (unsigned char *) locsyms
;
5559 /* This is the condition under which ppc64_elf_finish_dynamic_symbol
5560 will be called from elflink.h. If elflink.h doesn't call our
5561 finish_dynamic_symbol routine, we'll need to do something about
5562 initializing any .plt and .got entries in ppc64_elf_relocate_section. */
5563 #define WILL_CALL_FINISH_DYNAMIC_SYMBOL(DYN, SHARED, H) \
5566 || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) \
5567 && ((H)->dynindx != -1 \
5568 || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0))
5570 /* Allocate space in .plt, .got and associated reloc sections for
5574 allocate_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
5576 struct bfd_link_info
*info
;
5577 struct ppc_link_hash_table
*htab
;
5579 struct ppc_link_hash_entry
*eh
;
5580 struct ppc_dyn_relocs
*p
;
5581 struct got_entry
*gent
;
5583 if (h
->root
.type
== bfd_link_hash_indirect
)
5586 if (h
->root
.type
== bfd_link_hash_warning
)
5587 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
5589 info
= (struct bfd_link_info
*) inf
;
5590 htab
= ppc_hash_table (info
);
5592 if (htab
->elf
.dynamic_sections_created
5594 && WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, info
->shared
, h
))
5596 struct plt_entry
*pent
;
5597 bfd_boolean doneone
= FALSE
;
5598 for (pent
= h
->plt
.plist
; pent
!= NULL
; pent
= pent
->next
)
5599 if (pent
->plt
.refcount
> 0)
5601 BFD_ASSERT (((struct ppc_link_hash_entry
*) h
)->is_func_descriptor
);
5603 /* If this is the first .plt entry, make room for the special
5606 if (s
->_raw_size
== 0)
5607 s
->_raw_size
+= PLT_INITIAL_ENTRY_SIZE
;
5609 pent
->plt
.offset
= s
->_raw_size
;
5611 /* Make room for this entry. */
5612 s
->_raw_size
+= PLT_ENTRY_SIZE
;
5614 /* Make room for the .glink code. */
5616 if (s
->_raw_size
== 0)
5617 s
->_raw_size
+= GLINK_CALL_STUB_SIZE
;
5618 /* We need bigger stubs past index 32767. */
5619 if (s
->_raw_size
>= GLINK_CALL_STUB_SIZE
+ 32768*2*4)
5621 s
->_raw_size
+= 2*4;
5623 /* We also need to make an entry in the .rela.plt section. */
5625 s
->_raw_size
+= sizeof (Elf64_External_Rela
);
5629 pent
->plt
.offset
= (bfd_vma
) -1;
5632 h
->plt
.plist
= NULL
;
5633 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
5638 h
->plt
.plist
= NULL
;
5639 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_NEEDS_PLT
;
5642 eh
= (struct ppc_link_hash_entry
*) h
;
5643 /* Run through the TLS GD got entries first if we're changing them
5645 if ((eh
->tls_mask
& TLS_TPRELGD
) != 0)
5646 for (gent
= h
->got
.glist
; gent
!= NULL
; gent
= gent
->next
)
5647 if (gent
->got
.refcount
> 0
5648 && (gent
->tls_type
& TLS_GD
) != 0)
5650 /* This was a GD entry that has been converted to TPREL. If
5651 there happens to be a TPREL entry we can use that one. */
5652 struct got_entry
*ent
;
5653 for (ent
= h
->got
.glist
; ent
!= NULL
; ent
= ent
->next
)
5654 if (ent
->got
.refcount
> 0
5655 && (ent
->tls_type
& TLS_TPREL
) != 0
5656 && ent
->addend
== gent
->addend
5657 && ent
->owner
== gent
->owner
)
5659 gent
->got
.refcount
= 0;
5663 /* If not, then we'll be using our own TPREL entry. */
5664 if (gent
->got
.refcount
!= 0)
5665 gent
->tls_type
= TLS_TLS
| TLS_TPREL
;
5668 for (gent
= h
->got
.glist
; gent
!= NULL
; gent
= gent
->next
)
5669 if (gent
->got
.refcount
> 0)
5673 /* Make sure this symbol is output as a dynamic symbol.
5674 Undefined weak syms won't yet be marked as dynamic,
5675 nor will all TLS symbols. */
5676 if (h
->dynindx
== -1
5677 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
5679 if (! bfd_elf64_link_record_dynamic_symbol (info
, h
))
5683 if ((gent
->tls_type
& TLS_LD
) != 0
5684 && !(h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
))
5686 gent
->got
.offset
= ppc64_tlsld_got (gent
->owner
)->offset
;
5690 s
= ppc64_elf_tdata (gent
->owner
)->got
;
5691 gent
->got
.offset
= s
->_raw_size
;
5693 += (gent
->tls_type
& eh
->tls_mask
& (TLS_GD
| TLS_LD
)) ? 16 : 8;
5694 dyn
= htab
->elf
.dynamic_sections_created
;
5696 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, h
))
5697 && (ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
5698 || h
->root
.type
!= bfd_link_hash_undefweak
))
5699 ppc64_elf_tdata (gent
->owner
)->relgot
->_raw_size
5700 += (gent
->tls_type
& eh
->tls_mask
& TLS_GD
5701 ? 2 * sizeof (Elf64_External_Rela
)
5702 : sizeof (Elf64_External_Rela
));
5705 gent
->got
.offset
= (bfd_vma
) -1;
5707 if (eh
->dyn_relocs
== NULL
)
5710 /* In the shared -Bsymbolic case, discard space allocated for
5711 dynamic pc-relative relocs against symbols which turn out to be
5712 defined in regular objects. For the normal shared case, discard
5713 space for relocs that have become local due to symbol visibility
5718 /* Relocs that use pc_count are those that appear on a call insn,
5719 or certain REL relocs (see MUST_BE_DYN_RELOC) that can be
5720 generated via assembly. We want calls to protected symbols to
5721 resolve directly to the function rather than going via the plt.
5722 If people want function pointer comparisons to work as expected
5723 then they should avoid writing weird assembly. */
5724 if (SYMBOL_CALLS_LOCAL (info
, h
))
5726 struct ppc_dyn_relocs
**pp
;
5728 for (pp
= &eh
->dyn_relocs
; (p
= *pp
) != NULL
; )
5730 p
->count
-= p
->pc_count
;
5739 /* Also discard relocs on undefined weak syms with non-default
5741 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
5742 && h
->root
.type
== bfd_link_hash_undefweak
)
5743 eh
->dyn_relocs
= NULL
;
5745 else if (ELIMINATE_COPY_RELOCS
)
5747 /* For the non-shared case, discard space for relocs against
5748 symbols which turn out to need copy relocs or are not
5751 if ((h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0
5752 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
5753 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
5755 /* Make sure this symbol is output as a dynamic symbol.
5756 Undefined weak syms won't yet be marked as dynamic. */
5757 if (h
->dynindx
== -1
5758 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
5760 if (! bfd_elf64_link_record_dynamic_symbol (info
, h
))
5764 /* If that succeeded, we know we'll be keeping all the
5766 if (h
->dynindx
!= -1)
5770 eh
->dyn_relocs
= NULL
;
5775 /* Finally, allocate space. */
5776 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
5778 asection
*sreloc
= elf_section_data (p
->sec
)->sreloc
;
5779 sreloc
->_raw_size
+= p
->count
* sizeof (Elf64_External_Rela
);
5785 /* Find any dynamic relocs that apply to read-only sections. */
5788 readonly_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
5790 struct ppc_link_hash_entry
*eh
;
5791 struct ppc_dyn_relocs
*p
;
5793 if (h
->root
.type
== bfd_link_hash_warning
)
5794 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
5796 eh
= (struct ppc_link_hash_entry
*) h
;
5797 for (p
= eh
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
5799 asection
*s
= p
->sec
->output_section
;
5801 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
5803 struct bfd_link_info
*info
= inf
;
5805 info
->flags
|= DF_TEXTREL
;
5807 /* Not an error, just cut short the traversal. */
5814 /* Set the sizes of the dynamic sections. */
5817 ppc64_elf_size_dynamic_sections (bfd
*output_bfd ATTRIBUTE_UNUSED
,
5818 struct bfd_link_info
*info
)
5820 struct ppc_link_hash_table
*htab
;
5826 htab
= ppc_hash_table (info
);
5827 dynobj
= htab
->elf
.dynobj
;
5831 if (htab
->elf
.dynamic_sections_created
)
5833 /* Set the contents of the .interp section to the interpreter. */
5834 if (info
->executable
)
5836 s
= bfd_get_section_by_name (dynobj
, ".interp");
5839 s
->_raw_size
= sizeof ELF_DYNAMIC_INTERPRETER
;
5840 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
5844 /* Set up .got offsets for local syms, and space for local dynamic
5846 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
5848 struct got_entry
**lgot_ents
;
5849 struct got_entry
**end_lgot_ents
;
5851 bfd_size_type locsymcount
;
5852 Elf_Internal_Shdr
*symtab_hdr
;
5855 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
)
5858 if (ppc64_tlsld_got (ibfd
)->refcount
> 0)
5860 s
= ppc64_elf_tdata (ibfd
)->got
;
5861 ppc64_tlsld_got (ibfd
)->offset
= s
->_raw_size
;
5865 srel
= ppc64_elf_tdata (ibfd
)->relgot
;
5866 srel
->_raw_size
+= sizeof (Elf64_External_Rela
);
5870 ppc64_tlsld_got (ibfd
)->offset
= (bfd_vma
) -1;
5872 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
5874 struct ppc_dyn_relocs
*p
;
5876 for (p
= *((struct ppc_dyn_relocs
**)
5877 &elf_section_data (s
)->local_dynrel
);
5881 if (!bfd_is_abs_section (p
->sec
)
5882 && bfd_is_abs_section (p
->sec
->output_section
))
5884 /* Input section has been discarded, either because
5885 it is a copy of a linkonce section or due to
5886 linker script /DISCARD/, so we'll be discarding
5889 else if (p
->count
!= 0)
5891 srel
= elf_section_data (p
->sec
)->sreloc
;
5892 srel
->_raw_size
+= p
->count
* sizeof (Elf64_External_Rela
);
5893 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0)
5894 info
->flags
|= DF_TEXTREL
;
5899 lgot_ents
= elf_local_got_ents (ibfd
);
5903 symtab_hdr
= &elf_tdata (ibfd
)->symtab_hdr
;
5904 locsymcount
= symtab_hdr
->sh_info
;
5905 end_lgot_ents
= lgot_ents
+ locsymcount
;
5906 lgot_masks
= (char *) end_lgot_ents
;
5907 s
= ppc64_elf_tdata (ibfd
)->got
;
5908 srel
= ppc64_elf_tdata (ibfd
)->relgot
;
5909 for (; lgot_ents
< end_lgot_ents
; ++lgot_ents
, ++lgot_masks
)
5911 struct got_entry
*ent
;
5913 for (ent
= *lgot_ents
; ent
!= NULL
; ent
= ent
->next
)
5914 if (ent
->got
.refcount
> 0)
5916 if ((ent
->tls_type
& *lgot_masks
& TLS_LD
) != 0)
5918 if (ppc64_tlsld_got (ibfd
)->offset
== (bfd_vma
) -1)
5920 ppc64_tlsld_got (ibfd
)->offset
= s
->_raw_size
;
5923 srel
->_raw_size
+= sizeof (Elf64_External_Rela
);
5925 ent
->got
.offset
= ppc64_tlsld_got (ibfd
)->offset
;
5929 ent
->got
.offset
= s
->_raw_size
;
5930 if ((ent
->tls_type
& *lgot_masks
& TLS_GD
) != 0)
5934 srel
->_raw_size
+= 2 * sizeof (Elf64_External_Rela
);
5940 srel
->_raw_size
+= sizeof (Elf64_External_Rela
);
5945 ent
->got
.offset
= (bfd_vma
) -1;
5949 /* Allocate global sym .plt and .got entries, and space for global
5950 sym dynamic relocs. */
5951 elf_link_hash_traverse (&htab
->elf
, allocate_dynrelocs
, info
);
5953 /* We now have determined the sizes of the various dynamic sections.
5954 Allocate memory for them. */
5956 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
5958 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
5961 /* Reset _cooked_size since prelim layout will set it wrongly,
5962 and a non-zero _cooked_size sticks. */
5963 s
->_cooked_size
= 0;
5965 if (s
== htab
->brlt
|| s
== htab
->relbrlt
)
5966 /* These haven't been allocated yet; don't strip. */
5968 else if (s
== htab
->got
5970 || s
== htab
->glink
)
5972 /* Strip this section if we don't need it; see the
5975 else if (strncmp (bfd_get_section_name (dynobj
, s
), ".rela", 5) == 0)
5977 if (s
->_raw_size
== 0)
5979 /* If we don't need this section, strip it from the
5980 output file. This is mostly to handle .rela.bss and
5981 .rela.plt. We must create both sections in
5982 create_dynamic_sections, because they must be created
5983 before the linker maps input sections to output
5984 sections. The linker does that before
5985 adjust_dynamic_symbol is called, and it is that
5986 function which decides whether anything needs to go
5987 into these sections. */
5991 if (s
!= htab
->relplt
)
5994 /* We use the reloc_count field as a counter if we need
5995 to copy relocs into the output file. */
6001 /* It's not one of our sections, so don't allocate space. */
6005 if (s
->_raw_size
== 0)
6007 _bfd_strip_section_from_output (info
, s
);
6011 /* .plt is in the bss section. We don't initialise it. */
6015 /* Allocate memory for the section contents. We use bfd_zalloc
6016 here in case unused entries are not reclaimed before the
6017 section's contents are written out. This should not happen,
6018 but this way if it does we get a R_PPC64_NONE reloc in .rela
6019 sections instead of garbage.
6020 We also rely on the section contents being zero when writing
6022 s
->contents
= bfd_zalloc (dynobj
, s
->_raw_size
);
6023 if (s
->contents
== NULL
)
6027 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
6029 s
= ppc64_elf_tdata (ibfd
)->got
;
6030 if (s
!= NULL
&& s
!= htab
->got
)
6032 s
->_cooked_size
= 0;
6033 if (s
->_raw_size
== 0)
6034 _bfd_strip_section_from_output (info
, s
);
6037 s
->contents
= bfd_zalloc (ibfd
, s
->_raw_size
);
6038 if (s
->contents
== NULL
)
6042 s
= ppc64_elf_tdata (ibfd
)->relgot
;
6045 s
->_cooked_size
= 0;
6046 if (s
->_raw_size
== 0)
6047 _bfd_strip_section_from_output (info
, s
);
6050 s
->contents
= bfd_zalloc (ibfd
, s
->_raw_size
);
6051 if (s
->contents
== NULL
)
6059 if (htab
->elf
.dynamic_sections_created
)
6061 /* Add some entries to the .dynamic section. We fill in the
6062 values later, in ppc64_elf_finish_dynamic_sections, but we
6063 must add the entries now so that we get the correct size for
6064 the .dynamic section. The DT_DEBUG entry is filled in by the
6065 dynamic linker and used by the debugger. */
6066 #define add_dynamic_entry(TAG, VAL) \
6067 bfd_elf64_add_dynamic_entry (info, (TAG), (VAL))
6069 if (info
->executable
)
6071 if (!add_dynamic_entry (DT_DEBUG
, 0))
6075 if (htab
->plt
!= NULL
&& htab
->plt
->_raw_size
!= 0)
6077 if (!add_dynamic_entry (DT_PLTGOT
, 0)
6078 || !add_dynamic_entry (DT_PLTRELSZ
, 0)
6079 || !add_dynamic_entry (DT_PLTREL
, DT_RELA
)
6080 || !add_dynamic_entry (DT_JMPREL
, 0)
6081 || !add_dynamic_entry (DT_PPC64_GLINK
, 0))
6087 if (!add_dynamic_entry (DT_PPC64_OPD
, 0)
6088 || !add_dynamic_entry (DT_PPC64_OPDSZ
, 0))
6094 if (!add_dynamic_entry (DT_RELA
, 0)
6095 || !add_dynamic_entry (DT_RELASZ
, 0)
6096 || !add_dynamic_entry (DT_RELAENT
, sizeof (Elf64_External_Rela
)))
6099 /* If any dynamic relocs apply to a read-only section,
6100 then we need a DT_TEXTREL entry. */
6101 if ((info
->flags
& DF_TEXTREL
) == 0)
6102 elf_link_hash_traverse (&htab
->elf
, readonly_dynrelocs
, info
);
6104 if ((info
->flags
& DF_TEXTREL
) != 0)
6106 if (!add_dynamic_entry (DT_TEXTREL
, 0))
6111 #undef add_dynamic_entry
6116 /* Determine the type of stub needed, if any, for a call. */
6118 static inline enum ppc_stub_type
6119 ppc_type_of_stub (asection
*input_sec
,
6120 const Elf_Internal_Rela
*rel
,
6121 struct ppc_link_hash_entry
**hash
,
6122 bfd_vma destination
)
6124 struct ppc_link_hash_entry
*h
= *hash
;
6126 bfd_vma branch_offset
;
6127 bfd_vma max_branch_offset
;
6128 enum elf_ppc64_reloc_type r_type
;
6133 && h
->oh
->dynindx
!= -1)
6135 struct plt_entry
*ent
;
6136 for (ent
= h
->oh
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
6137 if (ent
->addend
== rel
->r_addend
6138 && ent
->plt
.offset
!= (bfd_vma
) -1)
6140 *hash
= (struct ppc_link_hash_entry
*) h
->oh
;
6141 return ppc_stub_plt_call
;
6145 if (!(h
->elf
.root
.type
== bfd_link_hash_defined
6146 || h
->elf
.root
.type
== bfd_link_hash_defweak
)
6147 || h
->elf
.root
.u
.def
.section
->output_section
== NULL
)
6148 return ppc_stub_none
;
6151 /* Determine where the call point is. */
6152 location
= (input_sec
->output_offset
6153 + input_sec
->output_section
->vma
6156 branch_offset
= destination
- location
;
6157 r_type
= ELF64_R_TYPE (rel
->r_info
);
6159 /* Determine if a long branch stub is needed. */
6160 max_branch_offset
= 1 << 25;
6161 if (r_type
!= R_PPC64_REL24
)
6162 max_branch_offset
= 1 << 15;
6164 if (branch_offset
+ max_branch_offset
>= 2 * max_branch_offset
)
6165 /* We need a stub. Figure out whether a long_branch or plt_branch
6167 return ppc_stub_long_branch
;
6169 return ppc_stub_none
;
6172 /* Build a .plt call stub. */
6174 static inline bfd_byte
*
6175 build_plt_stub (bfd
*obfd
, bfd_byte
*p
, int offset
)
6177 #define PPC_LO(v) ((v) & 0xffff)
6178 #define PPC_HI(v) (((v) >> 16) & 0xffff)
6179 #define PPC_HA(v) PPC_HI ((v) + 0x8000)
6181 bfd_put_32 (obfd
, ADDIS_R12_R2
| PPC_HA (offset
), p
), p
+= 4;
6182 bfd_put_32 (obfd
, STD_R2_40R1
, p
), p
+= 4;
6183 bfd_put_32 (obfd
, LD_R11_0R12
| PPC_LO (offset
), p
), p
+= 4;
6184 if (PPC_HA (offset
+ 8) != PPC_HA (offset
))
6185 bfd_put_32 (obfd
, ADDIS_R12_R12
| 1, p
), p
+= 4;
6187 bfd_put_32 (obfd
, LD_R2_0R12
| PPC_LO (offset
), p
), p
+= 4;
6188 if (PPC_HA (offset
+ 8) != PPC_HA (offset
))
6189 bfd_put_32 (obfd
, ADDIS_R12_R12
| 1, p
), p
+= 4;
6191 bfd_put_32 (obfd
, MTCTR_R11
, p
), p
+= 4;
6192 bfd_put_32 (obfd
, LD_R11_0R12
| PPC_LO (offset
), p
), p
+= 4;
6193 bfd_put_32 (obfd
, BCTR
, p
), p
+= 4;
6198 ppc_build_one_stub (struct bfd_hash_entry
*gen_entry
, void *in_arg
)
6200 struct ppc_stub_hash_entry
*stub_entry
;
6201 struct ppc_branch_hash_entry
*br_entry
;
6202 struct bfd_link_info
*info
;
6203 struct ppc_link_hash_table
*htab
;
6207 struct plt_entry
*ent
;
6211 /* Massage our args to the form they really have. */
6212 stub_entry
= (struct ppc_stub_hash_entry
*) gen_entry
;
6215 htab
= ppc_hash_table (info
);
6217 /* Make a note of the offset within the stubs for this entry. */
6218 stub_entry
->stub_offset
= stub_entry
->stub_sec
->_cooked_size
;
6219 loc
= stub_entry
->stub_sec
->contents
+ stub_entry
->stub_offset
;
6221 htab
->stub_count
[stub_entry
->stub_type
- 1] += 1;
6222 switch (stub_entry
->stub_type
)
6224 case ppc_stub_long_branch
:
6225 case ppc_stub_long_branch_r2off
:
6226 /* Branches are relative. This is where we are going to. */
6227 off
= (stub_entry
->target_value
6228 + stub_entry
->target_section
->output_offset
6229 + stub_entry
->target_section
->output_section
->vma
);
6231 /* And this is where we are coming from. */
6232 off
-= (stub_entry
->stub_offset
6233 + stub_entry
->stub_sec
->output_offset
6234 + stub_entry
->stub_sec
->output_section
->vma
);
6236 if (stub_entry
->stub_type
!= ppc_stub_long_branch_r2off
)
6242 r2off
= (htab
->stub_group
[stub_entry
->target_section
->id
].toc_off
6243 - htab
->stub_group
[stub_entry
->id_sec
->id
].toc_off
);
6244 bfd_put_32 (htab
->stub_bfd
, STD_R2_40R1
, loc
);
6246 bfd_put_32 (htab
->stub_bfd
, ADDIS_R2_R2
| PPC_HA (r2off
), loc
);
6248 bfd_put_32 (htab
->stub_bfd
, ADDI_R2_R2
| PPC_LO (r2off
), loc
);
6253 bfd_put_32 (htab
->stub_bfd
, B_DOT
| (off
& 0x3fffffc), loc
);
6255 BFD_ASSERT (off
+ (1 << 25) < (bfd_vma
) (1 << 26));
6258 case ppc_stub_plt_branch
:
6259 case ppc_stub_plt_branch_r2off
:
6260 br_entry
= ppc_branch_hash_lookup (&htab
->branch_hash_table
,
6261 stub_entry
->root
.string
+ 9,
6263 if (br_entry
== NULL
)
6265 (*_bfd_error_handler
) (_("can't find branch stub `%s'"),
6266 stub_entry
->root
.string
+ 9);
6267 htab
->stub_error
= TRUE
;
6271 off
= (stub_entry
->target_value
6272 + stub_entry
->target_section
->output_offset
6273 + stub_entry
->target_section
->output_section
->vma
);
6275 bfd_put_64 (htab
->brlt
->owner
, off
,
6276 htab
->brlt
->contents
+ br_entry
->offset
);
6280 /* Create a reloc for the branch lookup table entry. */
6281 Elf_Internal_Rela rela
;
6284 rela
.r_offset
= (br_entry
->offset
6285 + htab
->brlt
->output_offset
6286 + htab
->brlt
->output_section
->vma
);
6287 rela
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
6288 rela
.r_addend
= off
;
6290 rl
= htab
->relbrlt
->contents
;
6291 rl
+= htab
->relbrlt
->reloc_count
++ * sizeof (Elf64_External_Rela
);
6292 bfd_elf64_swap_reloca_out (htab
->relbrlt
->owner
, &rela
, rl
);
6295 off
= (br_entry
->offset
6296 + htab
->brlt
->output_offset
6297 + htab
->brlt
->output_section
->vma
6298 - elf_gp (htab
->brlt
->output_section
->owner
)
6299 - htab
->stub_group
[stub_entry
->id_sec
->id
].toc_off
);
6301 if (off
+ 0x80008000 > 0xffffffff || (off
& 7) != 0)
6303 (*_bfd_error_handler
)
6304 (_("linkage table error against `%s'"),
6305 stub_entry
->root
.string
);
6306 bfd_set_error (bfd_error_bad_value
);
6307 htab
->stub_error
= TRUE
;
6312 if (stub_entry
->stub_type
!= ppc_stub_plt_branch_r2off
)
6314 bfd_put_32 (htab
->stub_bfd
, ADDIS_R12_R2
| PPC_HA (indx
), loc
);
6316 bfd_put_32 (htab
->stub_bfd
, LD_R11_0R12
| PPC_LO (indx
), loc
);
6323 r2off
= (htab
->stub_group
[stub_entry
->target_section
->id
].toc_off
6324 - htab
->stub_group
[stub_entry
->id_sec
->id
].toc_off
);
6325 bfd_put_32 (htab
->stub_bfd
, STD_R2_40R1
, loc
);
6327 bfd_put_32 (htab
->stub_bfd
, ADDIS_R12_R2
| PPC_HA (indx
), loc
);
6329 bfd_put_32 (htab
->stub_bfd
, LD_R11_0R12
| PPC_LO (indx
), loc
);
6331 bfd_put_32 (htab
->stub_bfd
, ADDIS_R2_R2
| PPC_HA (r2off
), loc
);
6333 bfd_put_32 (htab
->stub_bfd
, ADDI_R2_R2
| PPC_LO (r2off
), loc
);
6337 bfd_put_32 (htab
->stub_bfd
, MTCTR_R11
, loc
);
6339 bfd_put_32 (htab
->stub_bfd
, BCTR
, loc
);
6342 case ppc_stub_plt_call
:
6343 /* Do the best we can for shared libraries built without
6344 exporting ".foo" for each "foo". This can happen when symbol
6345 versioning scripts strip all bar a subset of symbols. */
6346 if (stub_entry
->h
->oh
->root
.type
!= bfd_link_hash_defined
6347 && stub_entry
->h
->oh
->root
.type
!= bfd_link_hash_defweak
)
6349 /* Point the symbol at the stub. There may be multiple stubs,
6350 we don't really care; The main thing is to make this sym
6351 defined somewhere. Maybe defining the symbol in the stub
6352 section is a silly idea. If we didn't do this, htab->top_id
6354 stub_entry
->h
->oh
->root
.type
= bfd_link_hash_defined
;
6355 stub_entry
->h
->oh
->root
.u
.def
.section
= stub_entry
->stub_sec
;
6356 stub_entry
->h
->oh
->root
.u
.def
.value
= stub_entry
->stub_offset
;
6359 /* Now build the stub. */
6361 for (ent
= stub_entry
->h
->elf
.plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
6362 if (ent
->addend
== stub_entry
->addend
)
6364 off
= ent
->plt
.offset
;
6367 if (off
>= (bfd_vma
) -2)
6370 off
&= ~ (bfd_vma
) 1;
6371 off
+= (htab
->plt
->output_offset
6372 + htab
->plt
->output_section
->vma
6373 - elf_gp (htab
->plt
->output_section
->owner
)
6374 - htab
->stub_group
[stub_entry
->id_sec
->id
].toc_off
);
6376 if (off
+ 0x80008000 > 0xffffffff || (off
& 7) != 0)
6378 (*_bfd_error_handler
)
6379 (_("linkage table error against `%s'"),
6380 stub_entry
->h
->elf
.root
.root
.string
);
6381 bfd_set_error (bfd_error_bad_value
);
6382 htab
->stub_error
= TRUE
;
6386 p
= build_plt_stub (htab
->stub_bfd
, loc
, off
);
6395 stub_entry
->stub_sec
->_cooked_size
+= size
;
6397 if (htab
->emit_stub_syms
6398 && !(stub_entry
->stub_type
== ppc_stub_plt_call
6399 && stub_entry
->h
->oh
->root
.type
== bfd_link_hash_defined
6400 && stub_entry
->h
->oh
->root
.u
.def
.section
== stub_entry
->stub_sec
6401 && stub_entry
->h
->oh
->root
.u
.def
.value
== stub_entry
->stub_offset
))
6403 struct elf_link_hash_entry
*h
;
6404 h
= elf_link_hash_lookup (&htab
->elf
, stub_entry
->root
.string
,
6405 TRUE
, FALSE
, FALSE
);
6408 if (h
->root
.type
== bfd_link_hash_new
)
6410 h
->root
.type
= bfd_link_hash_defined
;
6411 h
->root
.u
.def
.section
= stub_entry
->stub_sec
;
6412 h
->root
.u
.def
.value
= stub_entry
->stub_offset
;
6413 h
->elf_link_hash_flags
= (ELF_LINK_HASH_REF_REGULAR
6414 | ELF_LINK_HASH_DEF_REGULAR
6415 | ELF_LINK_HASH_REF_REGULAR_NONWEAK
6416 | ELF_LINK_FORCED_LOCAL
);
6423 /* As above, but don't actually build the stub. Just bump offset so
6424 we know stub section sizes, and select plt_branch stubs where
6425 long_branch stubs won't do. */
6428 ppc_size_one_stub (struct bfd_hash_entry
*gen_entry
, void *in_arg
)
6430 struct ppc_stub_hash_entry
*stub_entry
;
6431 struct bfd_link_info
*info
;
6432 struct ppc_link_hash_table
*htab
;
6436 /* Massage our args to the form they really have. */
6437 stub_entry
= (struct ppc_stub_hash_entry
*) gen_entry
;
6440 htab
= ppc_hash_table (info
);
6442 if (stub_entry
->stub_type
== ppc_stub_plt_call
)
6444 struct plt_entry
*ent
;
6446 for (ent
= stub_entry
->h
->elf
.plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
6447 if (ent
->addend
== stub_entry
->addend
)
6449 off
= ent
->plt
.offset
& ~(bfd_vma
) 1;
6452 if (off
>= (bfd_vma
) -2)
6454 off
+= (htab
->plt
->output_offset
6455 + htab
->plt
->output_section
->vma
6456 - elf_gp (htab
->plt
->output_section
->owner
)
6457 - htab
->stub_group
[stub_entry
->id_sec
->id
].toc_off
);
6459 size
= PLT_CALL_STUB_SIZE
;
6460 if (PPC_HA (off
+ 16) != PPC_HA (off
))
6465 /* ppc_stub_long_branch or ppc_stub_plt_branch, or their r2off
6467 off
= (stub_entry
->target_value
6468 + stub_entry
->target_section
->output_offset
6469 + stub_entry
->target_section
->output_section
->vma
);
6470 off
-= (stub_entry
->stub_sec
->_raw_size
6471 + stub_entry
->stub_sec
->output_offset
6472 + stub_entry
->stub_sec
->output_section
->vma
);
6474 /* Reset the stub type from the plt variant in case we now
6475 can reach with a shorter stub. */
6476 if (stub_entry
->stub_type
>= ppc_stub_plt_branch
)
6477 stub_entry
->stub_type
+= ppc_stub_long_branch
- ppc_stub_plt_branch
;
6480 if (stub_entry
->stub_type
== ppc_stub_long_branch_r2off
)
6486 /* If the branch offset if too big, use a ppc_stub_plt_branch. */
6487 if (off
+ (1 << 25) >= (bfd_vma
) (1 << 26))
6489 struct ppc_branch_hash_entry
*br_entry
;
6491 br_entry
= ppc_branch_hash_lookup (&htab
->branch_hash_table
,
6492 stub_entry
->root
.string
+ 9,
6494 if (br_entry
== NULL
)
6496 (*_bfd_error_handler
) (_("can't build branch stub `%s'"),
6497 stub_entry
->root
.string
+ 9);
6498 htab
->stub_error
= TRUE
;
6502 if (br_entry
->iter
!= htab
->stub_iteration
)
6504 br_entry
->iter
= htab
->stub_iteration
;
6505 br_entry
->offset
= htab
->brlt
->_raw_size
;
6506 htab
->brlt
->_raw_size
+= 8;
6509 htab
->relbrlt
->_raw_size
+= sizeof (Elf64_External_Rela
);
6512 stub_entry
->stub_type
+= ppc_stub_plt_branch
- ppc_stub_long_branch
;
6514 if (stub_entry
->stub_type
!= ppc_stub_plt_branch
)
6519 stub_entry
->stub_sec
->_raw_size
+= size
;
6523 /* Set up various things so that we can make a list of input sections
6524 for each output section included in the link. Returns -1 on error,
6525 0 when no stubs will be needed, and 1 on success. */
6528 ppc64_elf_setup_section_lists (bfd
*output_bfd
, struct bfd_link_info
*info
)
6531 int top_id
, top_index
, id
;
6533 asection
**input_list
;
6535 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
6537 if (htab
->brlt
== NULL
)
6540 /* Find the top input section id. */
6541 for (input_bfd
= info
->input_bfds
, top_id
= 3;
6543 input_bfd
= input_bfd
->link_next
)
6545 for (section
= input_bfd
->sections
;
6547 section
= section
->next
)
6549 if (top_id
< section
->id
)
6550 top_id
= section
->id
;
6554 htab
->top_id
= top_id
;
6555 amt
= sizeof (struct map_stub
) * (top_id
+ 1);
6556 htab
->stub_group
= bfd_zmalloc (amt
);
6557 if (htab
->stub_group
== NULL
)
6560 /* Set toc_off for com, und, abs and ind sections. */
6561 for (id
= 0; id
< 3; id
++)
6562 htab
->stub_group
[id
].toc_off
= TOC_BASE_OFF
;
6564 elf_gp (output_bfd
) = htab
->toc_curr
= ppc64_elf_toc (output_bfd
);
6566 /* We can't use output_bfd->section_count here to find the top output
6567 section index as some sections may have been removed, and
6568 _bfd_strip_section_from_output doesn't renumber the indices. */
6569 for (section
= output_bfd
->sections
, top_index
= 0;
6571 section
= section
->next
)
6573 if (top_index
< section
->index
)
6574 top_index
= section
->index
;
6577 htab
->top_index
= top_index
;
6578 amt
= sizeof (asection
*) * (top_index
+ 1);
6579 input_list
= bfd_zmalloc (amt
);
6580 htab
->input_list
= input_list
;
6581 if (input_list
== NULL
)
6587 /* The linker repeatedly calls this function for each TOC input section
6588 and linker generated GOT section. Group input bfds such that the toc
6589 within a group is less than 64k in size. Will break with cute linker
6590 scripts that play games with dot in the output toc section. */
6593 ppc64_elf_next_toc_section (struct bfd_link_info
*info
, asection
*isec
)
6595 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
6597 if (!htab
->no_multi_toc
)
6599 bfd_vma addr
= isec
->output_offset
+ isec
->output_section
->vma
;
6600 bfd_vma off
= addr
- htab
->toc_curr
;
6601 if (off
+ isec
->_raw_size
> 0x10000)
6603 htab
->toc_curr
= addr
;
6604 htab
->multi_toc_needed
= 1;
6606 elf_gp (isec
->owner
) = (htab
->toc_curr
6607 - elf_gp (isec
->output_section
->owner
)
6612 /* Called after the last call to the above function. */
6615 ppc64_elf_reinit_toc (bfd
*output_bfd ATTRIBUTE_UNUSED
,
6616 struct bfd_link_info
*info
)
6618 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
6620 /* toc_curr tracks the TOC offset used for code sections below in
6621 ppc64_elf_next_input_section. Start off at 0x8000. */
6622 htab
->toc_curr
= TOC_BASE_OFF
;
6625 /* No toc references were found in ISEC. If the code in ISEC makes no
6626 calls, then there's no need to use toc adjusting stubs when branching
6627 into ISEC. Actually, indirect calls from ISEC are OK as they will
6631 toc_adjusting_stub_needed (struct bfd_link_info
*info
, asection
*isec
)
6638 /* We know none of our code bearing sections will need toc stubs. */
6639 if ((isec
->flags
& SEC_LINKER_CREATED
) != 0)
6642 if (isec
->_raw_size
== 0)
6645 /* Hack for linux kernel. .fixup contains branches, but only back to
6646 the function that hit an exception. */
6647 branch_ok
= strcmp (isec
->name
, ".fixup") == 0;
6649 contents
= elf_section_data (isec
)->this_hdr
.contents
;
6650 if (contents
== NULL
)
6652 contents
= bfd_malloc (isec
->_raw_size
);
6653 if (contents
== NULL
)
6655 if (! bfd_get_section_contents (isec
->owner
, isec
, contents
,
6656 0, isec
->_raw_size
))
6661 if (info
->keep_memory
)
6662 elf_section_data (isec
)->this_hdr
.contents
= contents
;
6665 /* Code scan, because we don't necessarily have relocs on calls to
6666 static functions. */
6668 for (i
= 0; i
< isec
->_raw_size
; i
+= 4)
6670 unsigned long insn
= bfd_get_32 (isec
->owner
, contents
+ i
);
6671 /* Is this a branch? */
6672 if ((insn
& (0x3f << 26)) == (18 << 26)
6673 /* If branch and link, it's a function call. */
6675 /* Sibling calls use a plain branch. I don't know a way
6676 of deciding whether a branch is really a sibling call. */
6684 if (elf_section_data (isec
)->this_hdr
.contents
!= contents
)
6689 /* The linker repeatedly calls this function for each input section,
6690 in the order that input sections are linked into output sections.
6691 Build lists of input sections to determine groupings between which
6692 we may insert linker stubs. */
6695 ppc64_elf_next_input_section (struct bfd_link_info
*info
, asection
*isec
)
6697 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
6700 if ((isec
->output_section
->flags
& SEC_CODE
) != 0
6701 && isec
->output_section
->index
<= htab
->top_index
)
6703 asection
**list
= htab
->input_list
+ isec
->output_section
->index
;
6704 /* Steal the link_sec pointer for our list. */
6705 #define PREV_SEC(sec) (htab->stub_group[(sec)->id].link_sec)
6706 /* This happens to make the list in reverse order,
6707 which is what we want. */
6708 PREV_SEC (isec
) = *list
;
6712 /* If a code section has a function that uses the TOC then we need
6713 to use the right TOC (obviously). Also, make sure that .opd gets
6714 the correct TOC value for R_PPC64_TOC relocs that don't have or
6715 can't find their function symbol (shouldn't ever happen now). */
6716 if (isec
->has_gp_reloc
|| (isec
->flags
& SEC_CODE
) == 0)
6718 if (elf_gp (isec
->owner
) != 0)
6719 htab
->toc_curr
= elf_gp (isec
->owner
);
6721 else if ((ret
= toc_adjusting_stub_needed (info
, isec
)) < 0)
6724 isec
->has_gp_reloc
= ret
;
6726 /* Functions that don't use the TOC can belong in any TOC group.
6727 Use the last TOC base. This happens to make _init and _fini
6729 htab
->stub_group
[isec
->id
].toc_off
= htab
->toc_curr
;
6733 /* See whether we can group stub sections together. Grouping stub
6734 sections may result in fewer stubs. More importantly, we need to
6735 put all .init* and .fini* stubs at the beginning of the .init or
6736 .fini output sections respectively, because glibc splits the
6737 _init and _fini functions into multiple parts. Putting a stub in
6738 the middle of a function is not a good idea. */
6741 group_sections (struct ppc_link_hash_table
*htab
,
6742 bfd_size_type stub_group_size
,
6743 bfd_boolean stubs_always_before_branch
)
6745 asection
**list
= htab
->input_list
+ htab
->top_index
;
6748 asection
*tail
= *list
;
6749 while (tail
!= NULL
)
6753 bfd_size_type total
;
6754 bfd_boolean big_sec
;
6758 if (tail
->_cooked_size
)
6759 total
= tail
->_cooked_size
;
6761 total
= tail
->_raw_size
;
6762 big_sec
= total
>= stub_group_size
;
6763 curr_toc
= htab
->stub_group
[tail
->id
].toc_off
;
6765 while ((prev
= PREV_SEC (curr
)) != NULL
6766 && ((total
+= curr
->output_offset
- prev
->output_offset
)
6768 && htab
->stub_group
[prev
->id
].toc_off
== curr_toc
)
6771 /* OK, the size from the start of CURR to the end is less
6772 than stub_group_size and thus can be handled by one stub
6773 section. (or the tail section is itself larger than
6774 stub_group_size, in which case we may be toast.) We
6775 should really be keeping track of the total size of stubs
6776 added here, as stubs contribute to the final output
6777 section size. That's a little tricky, and this way will
6778 only break if stubs added make the total size more than
6779 2^25, ie. for the default stub_group_size, if stubs total
6780 more than 2097152 bytes, or nearly 75000 plt call stubs. */
6783 prev
= PREV_SEC (tail
);
6784 /* Set up this stub group. */
6785 htab
->stub_group
[tail
->id
].link_sec
= curr
;
6787 while (tail
!= curr
&& (tail
= prev
) != NULL
);
6789 /* But wait, there's more! Input sections up to stub_group_size
6790 bytes before the stub section can be handled by it too.
6791 Don't do this if we have a really large section after the
6792 stubs, as adding more stubs increases the chance that
6793 branches may not reach into the stub section. */
6794 if (!stubs_always_before_branch
&& !big_sec
)
6798 && ((total
+= tail
->output_offset
- prev
->output_offset
)
6800 && htab
->stub_group
[prev
->id
].toc_off
== curr_toc
)
6803 prev
= PREV_SEC (tail
);
6804 htab
->stub_group
[tail
->id
].link_sec
= curr
;
6810 while (list
-- != htab
->input_list
);
6811 free (htab
->input_list
);
6815 /* Determine and set the size of the stub section for a final link.
6817 The basic idea here is to examine all the relocations looking for
6818 PC-relative calls to a target that is unreachable with a "bl"
6822 ppc64_elf_size_stubs (bfd
*output_bfd
,
6823 struct bfd_link_info
*info
,
6824 bfd_signed_vma group_size
,
6825 asection
*(*add_stub_section
) (const char *, asection
*),
6826 void (*layout_sections_again
) (void))
6828 bfd_size_type stub_group_size
;
6829 bfd_boolean stubs_always_before_branch
;
6830 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
6832 /* Stash our params away. */
6833 htab
->add_stub_section
= add_stub_section
;
6834 htab
->layout_sections_again
= layout_sections_again
;
6835 stubs_always_before_branch
= group_size
< 0;
6837 stub_group_size
= -group_size
;
6839 stub_group_size
= group_size
;
6840 if (stub_group_size
== 1)
6842 /* Default values. */
6843 if (stubs_always_before_branch
)
6845 stub_group_size
= 0x1e00000;
6846 if (htab
->has_14bit_branch
)
6847 stub_group_size
= 0x7800;
6851 stub_group_size
= 0x1c00000;
6852 if (htab
->has_14bit_branch
)
6853 stub_group_size
= 0x7000;
6857 group_sections (htab
, stub_group_size
, stubs_always_before_branch
);
6862 unsigned int bfd_indx
;
6864 bfd_boolean stub_changed
;
6866 htab
->stub_iteration
+= 1;
6867 stub_changed
= FALSE
;
6869 for (input_bfd
= info
->input_bfds
, bfd_indx
= 0;
6871 input_bfd
= input_bfd
->link_next
, bfd_indx
++)
6873 Elf_Internal_Shdr
*symtab_hdr
;
6875 Elf_Internal_Sym
*local_syms
= NULL
;
6877 /* We'll need the symbol table in a second. */
6878 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
6879 if (symtab_hdr
->sh_info
== 0)
6882 /* Walk over each section attached to the input bfd. */
6883 for (section
= input_bfd
->sections
;
6885 section
= section
->next
)
6887 Elf_Internal_Rela
*internal_relocs
, *irelaend
, *irela
;
6889 /* If there aren't any relocs, then there's nothing more
6891 if ((section
->flags
& SEC_RELOC
) == 0
6892 || section
->reloc_count
== 0)
6895 /* If this section is a link-once section that will be
6896 discarded, then don't create any stubs. */
6897 if (section
->output_section
== NULL
6898 || section
->output_section
->owner
!= output_bfd
)
6901 /* Get the relocs. */
6903 = _bfd_elf_link_read_relocs (input_bfd
, section
, NULL
, NULL
,
6905 if (internal_relocs
== NULL
)
6906 goto error_ret_free_local
;
6908 /* Now examine each relocation. */
6909 irela
= internal_relocs
;
6910 irelaend
= irela
+ section
->reloc_count
;
6911 for (; irela
< irelaend
; irela
++)
6913 enum elf_ppc64_reloc_type r_type
;
6914 unsigned int r_indx
;
6915 enum ppc_stub_type stub_type
;
6916 struct ppc_stub_hash_entry
*stub_entry
;
6919 bfd_vma destination
;
6920 struct ppc_link_hash_entry
*hash
;
6921 struct elf_link_hash_entry
*h
;
6922 Elf_Internal_Sym
*sym
;
6924 const asection
*id_sec
;
6926 r_type
= ELF64_R_TYPE (irela
->r_info
);
6927 r_indx
= ELF64_R_SYM (irela
->r_info
);
6929 if (r_type
>= R_PPC64_max
)
6931 bfd_set_error (bfd_error_bad_value
);
6932 goto error_ret_free_internal
;
6935 /* Only look for stubs on branch instructions. */
6936 if (r_type
!= R_PPC64_REL24
6937 && r_type
!= R_PPC64_REL14
6938 && r_type
!= R_PPC64_REL14_BRTAKEN
6939 && r_type
!= R_PPC64_REL14_BRNTAKEN
)
6942 /* Now determine the call target, its name, value,
6945 if (!get_sym_h (&h
, &sym
, &sym_sec
, NULL
, &local_syms
,
6947 goto error_ret_free_internal
;
6948 hash
= (struct ppc_link_hash_entry
*) h
;
6952 /* It's a local symbol. */
6953 sym_value
= sym
->st_value
;
6954 destination
= (sym_value
+ irela
->r_addend
6955 + sym_sec
->output_offset
6956 + sym_sec
->output_section
->vma
);
6960 /* It's an external symbol. */
6962 if (hash
->elf
.root
.type
== bfd_link_hash_defined
6963 || hash
->elf
.root
.type
== bfd_link_hash_defweak
)
6965 sym_value
= hash
->elf
.root
.u
.def
.value
;
6966 if (sym_sec
->output_section
!= NULL
)
6967 destination
= (sym_value
+ irela
->r_addend
6968 + sym_sec
->output_offset
6969 + sym_sec
->output_section
->vma
);
6971 else if (hash
->elf
.root
.type
== bfd_link_hash_undefweak
)
6973 else if (hash
->elf
.root
.type
== bfd_link_hash_undefined
)
6977 bfd_set_error (bfd_error_bad_value
);
6978 goto error_ret_free_internal
;
6982 /* Determine what (if any) linker stub is needed. */
6983 stub_type
= ppc_type_of_stub (section
, irela
, &hash
,
6986 if (stub_type
!= ppc_stub_plt_call
)
6988 /* Check whether we need a TOC adjusting stub.
6989 Since the linker pastes together pieces from
6990 different object files when creating the
6991 _init and _fini functions, it may be that a
6992 call to what looks like a local sym is in
6993 fact a call needing a TOC adjustment. */
6995 && sym_sec
->output_section
!= NULL
6996 && (htab
->stub_group
[sym_sec
->id
].toc_off
6997 != htab
->stub_group
[section
->id
].toc_off
)
6998 && sym_sec
->has_gp_reloc
6999 && section
->has_gp_reloc
)
7000 stub_type
= ppc_stub_long_branch_r2off
;
7003 if (stub_type
== ppc_stub_none
)
7006 /* __tls_get_addr calls might be eliminated. */
7007 if (stub_type
!= ppc_stub_plt_call
7009 && &hash
->elf
== htab
->tls_get_addr
7010 && section
->has_tls_reloc
7011 && irela
!= internal_relocs
)
7016 if (!get_tls_mask (&tls_mask
, NULL
, &local_syms
,
7017 irela
- 1, input_bfd
))
7018 goto error_ret_free_internal
;
7023 /* Support for grouping stub sections. */
7024 id_sec
= htab
->stub_group
[section
->id
].link_sec
;
7026 /* Get the name of this stub. */
7027 stub_name
= ppc_stub_name (id_sec
, sym_sec
, hash
, irela
);
7029 goto error_ret_free_internal
;
7031 stub_entry
= ppc_stub_hash_lookup (&htab
->stub_hash_table
,
7032 stub_name
, FALSE
, FALSE
);
7033 if (stub_entry
!= NULL
)
7035 /* The proper stub has already been created. */
7040 stub_entry
= ppc_add_stub (stub_name
, section
, htab
);
7041 if (stub_entry
== NULL
)
7044 error_ret_free_internal
:
7045 if (elf_section_data (section
)->relocs
== NULL
)
7046 free (internal_relocs
);
7047 error_ret_free_local
:
7048 if (local_syms
!= NULL
7049 && (symtab_hdr
->contents
7050 != (unsigned char *) local_syms
))
7055 stub_entry
->stub_type
= stub_type
;
7056 stub_entry
->target_value
= sym_value
;
7057 stub_entry
->target_section
= sym_sec
;
7058 stub_entry
->h
= hash
;
7059 stub_entry
->addend
= irela
->r_addend
;
7060 stub_changed
= TRUE
;
7063 /* We're done with the internal relocs, free them. */
7064 if (elf_section_data (section
)->relocs
!= internal_relocs
)
7065 free (internal_relocs
);
7068 if (local_syms
!= NULL
7069 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
7071 if (!info
->keep_memory
)
7074 symtab_hdr
->contents
= (unsigned char *) local_syms
;
7081 /* OK, we've added some stubs. Find out the new size of the
7083 for (stub_sec
= htab
->stub_bfd
->sections
;
7085 stub_sec
= stub_sec
->next
)
7086 if ((stub_sec
->flags
& SEC_LINKER_CREATED
) == 0)
7088 stub_sec
->_raw_size
= 0;
7089 stub_sec
->_cooked_size
= 0;
7091 htab
->brlt
->_raw_size
= 0;
7092 htab
->brlt
->_cooked_size
= 0;
7095 htab
->relbrlt
->_raw_size
= 0;
7096 htab
->relbrlt
->_cooked_size
= 0;
7099 bfd_hash_traverse (&htab
->stub_hash_table
, ppc_size_one_stub
, info
);
7101 /* Ask the linker to do its stuff. */
7102 (*htab
->layout_sections_again
) ();
7105 /* It would be nice to strip .branch_lt from the output if the
7106 section is empty, but it's too late. If we strip sections here,
7107 the dynamic symbol table is corrupted since the section symbol
7108 for the stripped section isn't written. */
7113 /* Called after we have determined section placement. If sections
7114 move, we'll be called again. Provide a value for TOCstart. */
7117 ppc64_elf_toc (bfd
*obfd
)
7122 /* The TOC consists of sections .got, .toc, .tocbss, .plt in that
7123 order. The TOC starts where the first of these sections starts. */
7124 s
= bfd_get_section_by_name (obfd
, ".got");
7126 s
= bfd_get_section_by_name (obfd
, ".toc");
7128 s
= bfd_get_section_by_name (obfd
, ".tocbss");
7130 s
= bfd_get_section_by_name (obfd
, ".plt");
7133 /* This may happen for
7134 o references to TOC base (SYM@toc / TOC[tc0]) without a
7137 o --gc-sections and empty TOC sections
7139 FIXME: Warn user? */
7141 /* Look for a likely section. We probably won't even be
7143 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
7144 if ((s
->flags
& (SEC_ALLOC
| SEC_SMALL_DATA
| SEC_READONLY
))
7145 == (SEC_ALLOC
| SEC_SMALL_DATA
))
7148 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
7149 if ((s
->flags
& (SEC_ALLOC
| SEC_SMALL_DATA
))
7150 == (SEC_ALLOC
| SEC_SMALL_DATA
))
7153 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
7154 if ((s
->flags
& (SEC_ALLOC
| SEC_READONLY
)) == SEC_ALLOC
)
7157 for (s
= obfd
->sections
; s
!= NULL
; s
= s
->next
)
7158 if ((s
->flags
& SEC_ALLOC
) == SEC_ALLOC
)
7164 TOCstart
= s
->output_section
->vma
+ s
->output_offset
;
7169 /* Build all the stubs associated with the current output file.
7170 The stubs are kept in a hash table attached to the main linker
7171 hash table. This function is called via gldelf64ppc_finish. */
7174 ppc64_elf_build_stubs (bfd_boolean emit_stub_syms
,
7175 struct bfd_link_info
*info
,
7178 struct ppc_link_hash_table
*htab
= ppc_hash_table (info
);
7181 int stub_sec_count
= 0;
7183 htab
->emit_stub_syms
= emit_stub_syms
;
7184 for (stub_sec
= htab
->stub_bfd
->sections
;
7186 stub_sec
= stub_sec
->next
)
7187 if ((stub_sec
->flags
& SEC_LINKER_CREATED
) == 0)
7191 /* Allocate memory to hold the linker stubs. */
7192 size
= stub_sec
->_raw_size
;
7195 stub_sec
->contents
= bfd_zalloc (htab
->stub_bfd
, size
);
7196 if (stub_sec
->contents
== NULL
)
7199 stub_sec
->_cooked_size
= 0;
7202 if (htab
->plt
!= NULL
)
7207 /* Build the .glink plt call stub. */
7208 plt0
= (htab
->plt
->output_section
->vma
7209 + htab
->plt
->output_offset
7210 - (htab
->glink
->output_section
->vma
7211 + htab
->glink
->output_offset
7212 + GLINK_CALL_STUB_SIZE
));
7213 if (plt0
+ 0x80008000 > 0xffffffff)
7215 (*_bfd_error_handler
) (_(".glink and .plt too far apart"));
7216 bfd_set_error (bfd_error_bad_value
);
7220 if (htab
->emit_stub_syms
)
7222 struct elf_link_hash_entry
*h
;
7223 h
= elf_link_hash_lookup (&htab
->elf
, "__glink", TRUE
, FALSE
, FALSE
);
7226 if (h
->root
.type
== bfd_link_hash_new
)
7228 h
->root
.type
= bfd_link_hash_defined
;
7229 h
->root
.u
.def
.section
= htab
->glink
;
7230 h
->root
.u
.def
.value
= 0;
7231 h
->elf_link_hash_flags
= (ELF_LINK_HASH_REF_REGULAR
7232 | ELF_LINK_HASH_DEF_REGULAR
7233 | ELF_LINK_HASH_REF_REGULAR_NONWEAK
7234 | ELF_LINK_FORCED_LOCAL
);
7237 p
= htab
->glink
->contents
;
7238 bfd_put_32 (htab
->glink
->owner
, MFCTR_R12
, p
);
7240 bfd_put_32 (htab
->glink
->owner
, SLDI_R11_R0_3
, p
);
7242 bfd_put_32 (htab
->glink
->owner
, ADDIC_R2_R0_32K
, p
);
7244 bfd_put_32 (htab
->glink
->owner
, SUB_R12_R12_R11
, p
);
7246 bfd_put_32 (htab
->glink
->owner
, SRADI_R2_R2_63
, p
);
7248 bfd_put_32 (htab
->glink
->owner
, SLDI_R11_R0_2
, p
);
7250 bfd_put_32 (htab
->glink
->owner
, AND_R2_R2_R11
, p
);
7252 bfd_put_32 (htab
->glink
->owner
, SUB_R12_R12_R11
, p
);
7254 bfd_put_32 (htab
->glink
->owner
, ADD_R12_R12_R2
, p
);
7256 bfd_put_32 (htab
->glink
->owner
, ADDIS_R12_R12
| PPC_HA (plt0
), p
);
7258 bfd_put_32 (htab
->glink
->owner
, LD_R11_0R12
| PPC_LO (plt0
), p
);
7260 bfd_put_32 (htab
->glink
->owner
, ADDI_R12_R12
| PPC_LO (plt0
), p
);
7262 bfd_put_32 (htab
->glink
->owner
, LD_R2_0R12
| 8, p
);
7264 bfd_put_32 (htab
->glink
->owner
, MTCTR_R11
, p
);
7266 bfd_put_32 (htab
->glink
->owner
, LD_R11_0R12
| 16, p
);
7268 bfd_put_32 (htab
->glink
->owner
, BCTR
, p
);
7271 /* Build the .glink lazy link call stubs. */
7273 while (p
< htab
->glink
->contents
+ htab
->glink
->_raw_size
)
7277 bfd_put_32 (htab
->glink
->owner
, LI_R0_0
| indx
, p
);
7282 bfd_put_32 (htab
->glink
->owner
, LIS_R0_0
| PPC_HI (indx
), p
);
7284 bfd_put_32 (htab
->glink
->owner
, ORI_R0_R0_0
| PPC_LO (indx
), p
);
7287 bfd_put_32 (htab
->glink
->owner
,
7288 B_DOT
| ((htab
->glink
->contents
- p
) & 0x3fffffc), p
);
7292 htab
->glink
->_cooked_size
= p
- htab
->glink
->contents
;
7295 if (htab
->brlt
->_raw_size
!= 0)
7297 htab
->brlt
->contents
= bfd_zalloc (htab
->brlt
->owner
,
7298 htab
->brlt
->_raw_size
);
7299 if (htab
->brlt
->contents
== NULL
)
7302 if (info
->shared
&& htab
->relbrlt
->_raw_size
!= 0)
7304 htab
->relbrlt
->contents
= bfd_zalloc (htab
->relbrlt
->owner
,
7305 htab
->relbrlt
->_raw_size
);
7306 if (htab
->relbrlt
->contents
== NULL
)
7310 /* Build the stubs as directed by the stub hash table. */
7311 bfd_hash_traverse (&htab
->stub_hash_table
, ppc_build_one_stub
, info
);
7313 for (stub_sec
= htab
->stub_bfd
->sections
;
7315 stub_sec
= stub_sec
->next
)
7316 if ((stub_sec
->flags
& SEC_LINKER_CREATED
) == 0)
7318 stub_sec_count
+= 1;
7319 if (stub_sec
->_raw_size
!= stub_sec
->_cooked_size
)
7323 if (stub_sec
!= NULL
7324 || htab
->glink
->_raw_size
!= htab
->glink
->_cooked_size
)
7326 htab
->stub_error
= TRUE
;
7327 (*_bfd_error_handler
) (_("stubs don't match calculated size"));
7330 if (htab
->stub_error
)
7335 *stats
= bfd_malloc (500);
7339 sprintf (*stats
, _("linker stubs in %u groups\n"
7342 " long branch %lu\n"
7343 " long toc adj %lu\n"
7346 htab
->stub_count
[ppc_stub_long_branch
- 1],
7347 htab
->stub_count
[ppc_stub_long_branch_r2off
- 1],
7348 htab
->stub_count
[ppc_stub_plt_branch
- 1],
7349 htab
->stub_count
[ppc_stub_plt_branch_r2off
- 1],
7350 htab
->stub_count
[ppc_stub_plt_call
- 1]);
7355 /* The RELOCATE_SECTION function is called by the ELF backend linker
7356 to handle the relocations for a section.
7358 The relocs are always passed as Rela structures; if the section
7359 actually uses Rel structures, the r_addend field will always be
7362 This function is responsible for adjust the section contents as
7363 necessary, and (if using Rela relocs and generating a
7364 relocatable output file) adjusting the reloc addend as
7367 This function does not have to worry about setting the reloc
7368 address or the reloc symbol index.
7370 LOCAL_SYMS is a pointer to the swapped in local symbols.
7372 LOCAL_SECTIONS is an array giving the section in the input file
7373 corresponding to the st_shndx field of each local symbol.
7375 The global hash table entry for the global symbols can be found
7376 via elf_sym_hashes (input_bfd).
7378 When generating relocatable output, this function must handle
7379 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
7380 going to be the section symbol corresponding to the output
7381 section, which means that the addend must be adjusted
7385 ppc64_elf_relocate_section (bfd
*output_bfd
,
7386 struct bfd_link_info
*info
,
7388 asection
*input_section
,
7390 Elf_Internal_Rela
*relocs
,
7391 Elf_Internal_Sym
*local_syms
,
7392 asection
**local_sections
)
7394 struct ppc_link_hash_table
*htab
;
7395 Elf_Internal_Shdr
*symtab_hdr
;
7396 struct elf_link_hash_entry
**sym_hashes
;
7397 Elf_Internal_Rela
*rel
;
7398 Elf_Internal_Rela
*relend
;
7399 Elf_Internal_Rela outrel
;
7401 struct got_entry
**local_got_ents
;
7403 bfd_boolean ret
= TRUE
;
7405 /* Disabled until we sort out how ld should choose 'y' vs 'at'. */
7406 bfd_boolean is_power4
= FALSE
;
7408 if (info
->relocatable
)
7411 /* Initialize howto table if needed. */
7412 if (!ppc64_elf_howto_table
[R_PPC64_ADDR32
])
7415 htab
= ppc_hash_table (info
);
7416 local_got_ents
= elf_local_got_ents (input_bfd
);
7417 TOCstart
= elf_gp (output_bfd
);
7418 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
7419 sym_hashes
= elf_sym_hashes (input_bfd
);
7420 is_opd
= ppc64_elf_section_data (input_section
)->opd
.adjust
!= NULL
;
7423 relend
= relocs
+ input_section
->reloc_count
;
7424 for (; rel
< relend
; rel
++)
7426 enum elf_ppc64_reloc_type r_type
;
7428 bfd_reloc_status_type r
;
7429 Elf_Internal_Sym
*sym
;
7431 struct elf_link_hash_entry
*h
;
7432 struct elf_link_hash_entry
*fdh
;
7433 const char *sym_name
;
7434 unsigned long r_symndx
, toc_symndx
;
7435 char tls_mask
, tls_gd
, tls_type
;
7438 bfd_boolean unresolved_reloc
;
7440 unsigned long insn
, mask
;
7441 struct ppc_stub_hash_entry
*stub_entry
;
7442 bfd_vma max_br_offset
;
7445 r_type
= ELF64_R_TYPE (rel
->r_info
);
7446 r_symndx
= ELF64_R_SYM (rel
->r_info
);
7448 /* For old style R_PPC64_TOC relocs with a zero symbol, use the
7449 symbol of the previous ADDR64 reloc. The symbol gives us the
7450 proper TOC base to use. */
7451 if (rel
->r_info
== ELF64_R_INFO (0, R_PPC64_TOC
)
7453 && ELF64_R_TYPE (rel
[-1].r_info
) == R_PPC64_ADDR64
7455 r_symndx
= ELF64_R_SYM (rel
[-1].r_info
);
7461 unresolved_reloc
= FALSE
;
7464 if (r_symndx
< symtab_hdr
->sh_info
)
7466 /* It's a local symbol. */
7467 sym
= local_syms
+ r_symndx
;
7468 sec
= local_sections
[r_symndx
];
7469 sym_name
= bfd_elf_local_sym_name (input_bfd
, sym
);
7470 sym_type
= ELF64_ST_TYPE (sym
->st_info
);
7471 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
7472 if (elf_section_data (sec
) != NULL
)
7474 long *opd_sym_adjust
;
7476 opd_sym_adjust
= ppc64_elf_section_data (sec
)->opd
.adjust
;
7477 if (opd_sym_adjust
!= NULL
)
7478 relocation
+= opd_sym_adjust
[sym
->st_value
/ 24];
7483 RELOC_FOR_GLOBAL_SYMBOL (h
, sym_hashes
, r_symndx
,
7484 symtab_hdr
, relocation
, sec
,
7485 unresolved_reloc
, info
,
7487 sym_name
= h
->root
.root
.string
;
7491 /* TLS optimizations. Replace instruction sequences and relocs
7492 based on information we collected in tls_optimize. We edit
7493 RELOCS so that --emit-relocs will output something sensible
7494 for the final instruction stream. */
7498 if (IS_PPC64_TLS_RELOC (r_type
))
7501 tls_mask
= ((struct ppc_link_hash_entry
*) h
)->tls_mask
;
7502 else if (local_got_ents
!= NULL
)
7505 lgot_masks
= (char *) (local_got_ents
+ symtab_hdr
->sh_info
);
7506 tls_mask
= lgot_masks
[r_symndx
];
7508 if (tls_mask
== 0 && r_type
== R_PPC64_TLS
)
7510 /* Check for toc tls entries. */
7513 if (!get_tls_mask (&toc_tls
, &toc_symndx
, &local_syms
,
7518 tls_mask
= *toc_tls
;
7522 /* Check that tls relocs are used with tls syms, and non-tls
7523 relocs are used with non-tls syms. */
7525 && r_type
!= R_PPC64_NONE
7527 || h
->root
.type
== bfd_link_hash_defined
7528 || h
->root
.type
== bfd_link_hash_defweak
)
7529 && IS_PPC64_TLS_RELOC (r_type
) != (sym_type
== STT_TLS
))
7531 if (r_type
== R_PPC64_TLS
&& tls_mask
!= 0)
7532 /* R_PPC64_TLS is OK against a symbol in the TOC. */
7535 (*_bfd_error_handler
)
7536 (sym_type
== STT_TLS
7537 ? _("%s(%s+0x%lx): %s used with TLS symbol %s")
7538 : _("%s(%s+0x%lx): %s used with non-TLS symbol %s"),
7539 bfd_archive_filename (input_bfd
),
7540 input_section
->name
,
7541 (long) rel
->r_offset
,
7542 ppc64_elf_howto_table
[r_type
]->name
,
7546 /* Ensure reloc mapping code below stays sane. */
7547 if (R_PPC64_TOC16_LO_DS
!= R_PPC64_TOC16_DS
+ 1
7548 || R_PPC64_TOC16_LO
!= R_PPC64_TOC16
+ 1
7549 || (R_PPC64_GOT_TLSLD16
& 3) != (R_PPC64_GOT_TLSGD16
& 3)
7550 || (R_PPC64_GOT_TLSLD16_LO
& 3) != (R_PPC64_GOT_TLSGD16_LO
& 3)
7551 || (R_PPC64_GOT_TLSLD16_HI
& 3) != (R_PPC64_GOT_TLSGD16_HI
& 3)
7552 || (R_PPC64_GOT_TLSLD16_HA
& 3) != (R_PPC64_GOT_TLSGD16_HA
& 3)
7553 || (R_PPC64_GOT_TLSLD16
& 3) != (R_PPC64_GOT_TPREL16_DS
& 3)
7554 || (R_PPC64_GOT_TLSLD16_LO
& 3) != (R_PPC64_GOT_TPREL16_LO_DS
& 3)
7555 || (R_PPC64_GOT_TLSLD16_HI
& 3) != (R_PPC64_GOT_TPREL16_HI
& 3)
7556 || (R_PPC64_GOT_TLSLD16_HA
& 3) != (R_PPC64_GOT_TPREL16_HA
& 3))
7565 case R_PPC64_TOC16_LO
:
7566 case R_PPC64_TOC16_DS
:
7567 case R_PPC64_TOC16_LO_DS
:
7569 /* Check for toc tls entries. */
7573 retval
= get_tls_mask (&toc_tls
, &toc_symndx
, &local_syms
,
7580 tls_mask
= *toc_tls
;
7581 if (r_type
== R_PPC64_TOC16_DS
7582 || r_type
== R_PPC64_TOC16_LO_DS
)
7585 && (tls_mask
& (TLS_DTPREL
| TLS_TPREL
)) == 0)
7590 /* If we found a GD reloc pair, then we might be
7591 doing a GD->IE transition. */
7594 tls_gd
= TLS_TPRELGD
;
7595 if (tls_mask
!= 0 && (tls_mask
& TLS_GD
) == 0)
7596 goto tls_get_addr_check
;
7598 else if (retval
== 3)
7600 if (tls_mask
!= 0 && (tls_mask
& TLS_LD
) == 0)
7601 goto tls_get_addr_check
;
7608 case R_PPC64_GOT_TPREL16_DS
:
7609 case R_PPC64_GOT_TPREL16_LO_DS
:
7611 && (tls_mask
& TLS_TPREL
) == 0)
7614 insn
= bfd_get_32 (output_bfd
, contents
+ rel
->r_offset
- 2);
7616 insn
|= 0x3c0d0000; /* addis 0,13,0 */
7617 bfd_put_32 (output_bfd
, insn
, contents
+ rel
->r_offset
- 2);
7618 r_type
= R_PPC64_TPREL16_HA
;
7619 if (toc_symndx
!= 0)
7621 rel
->r_info
= ELF64_R_INFO (toc_symndx
, r_type
);
7622 /* We changed the symbol. Start over in order to
7623 get h, sym, sec etc. right. */
7628 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
7634 && (tls_mask
& TLS_TPREL
) == 0)
7637 insn
= bfd_get_32 (output_bfd
, contents
+ rel
->r_offset
);
7638 if ((insn
& ((0x3f << 26) | (31 << 11)))
7639 == ((31 << 26) | (13 << 11)))
7640 rtra
= insn
& ((1 << 26) - (1 << 16));
7641 else if ((insn
& ((0x3f << 26) | (31 << 16)))
7642 == ((31 << 26) | (13 << 16)))
7643 rtra
= (insn
& (31 << 21)) | ((insn
& (31 << 11)) << 5);
7646 if ((insn
& ((1 << 11) - (1 << 1))) == 266 << 1)
7649 else if ((insn
& (31 << 1)) == 23 << 1
7650 && ((insn
& (31 << 6)) < 14 << 6
7651 || ((insn
& (31 << 6)) >= 16 << 6
7652 && (insn
& (31 << 6)) < 24 << 6)))
7653 /* load and store indexed -> dform. */
7654 insn
= (32 | ((insn
>> 6) & 31)) << 26;
7655 else if ((insn
& (31 << 1)) == 21 << 1
7656 && (insn
& (0x1a << 6)) == 0)
7657 /* ldx, ldux, stdx, stdux -> ld, ldu, std, stdu. */
7658 insn
= (((58 | ((insn
>> 6) & 4)) << 26)
7659 | ((insn
>> 6) & 1));
7660 else if ((insn
& (31 << 1)) == 21 << 1
7661 && (insn
& ((1 << 11) - (1 << 1))) == 341 << 1)
7663 insn
= (58 << 26) | 2;
7667 bfd_put_32 (output_bfd
, insn
, contents
+ rel
->r_offset
);
7668 /* Was PPC64_TLS which sits on insn boundary, now
7669 PPC64_TPREL16_LO which is at insn+2. */
7671 r_type
= R_PPC64_TPREL16_LO
;
7672 if (toc_symndx
!= 0)
7674 rel
->r_info
= ELF64_R_INFO (toc_symndx
, r_type
);
7675 /* We changed the symbol. Start over in order to
7676 get h, sym, sec etc. right. */
7681 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
7685 case R_PPC64_GOT_TLSGD16_HI
:
7686 case R_PPC64_GOT_TLSGD16_HA
:
7687 tls_gd
= TLS_TPRELGD
;
7688 if (tls_mask
!= 0 && (tls_mask
& TLS_GD
) == 0)
7692 case R_PPC64_GOT_TLSLD16_HI
:
7693 case R_PPC64_GOT_TLSLD16_HA
:
7694 if (tls_mask
!= 0 && (tls_mask
& TLS_LD
) == 0)
7697 if ((tls_mask
& tls_gd
) != 0)
7698 r_type
= (((r_type
- (R_PPC64_GOT_TLSGD16
& 3)) & 3)
7699 + R_PPC64_GOT_TPREL16_DS
);
7702 bfd_put_32 (output_bfd
, NOP
, contents
+ rel
->r_offset
);
7704 r_type
= R_PPC64_NONE
;
7706 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
7710 case R_PPC64_GOT_TLSGD16
:
7711 case R_PPC64_GOT_TLSGD16_LO
:
7712 tls_gd
= TLS_TPRELGD
;
7713 if (tls_mask
!= 0 && (tls_mask
& TLS_GD
) == 0)
7714 goto tls_get_addr_check
;
7717 case R_PPC64_GOT_TLSLD16
:
7718 case R_PPC64_GOT_TLSLD16_LO
:
7719 if (tls_mask
!= 0 && (tls_mask
& TLS_LD
) == 0)
7722 if (rel
+ 1 < relend
)
7724 enum elf_ppc64_reloc_type r_type2
;
7725 unsigned long r_symndx2
;
7726 struct elf_link_hash_entry
*h2
;
7727 bfd_vma insn1
, insn2
, insn3
;
7730 /* The next instruction should be a call to
7731 __tls_get_addr. Peek at the reloc to be sure. */
7732 r_type2
= ELF64_R_TYPE (rel
[1].r_info
);
7733 r_symndx2
= ELF64_R_SYM (rel
[1].r_info
);
7734 if (r_symndx2
< symtab_hdr
->sh_info
7735 || (r_type2
!= R_PPC64_REL14
7736 && r_type2
!= R_PPC64_REL14_BRTAKEN
7737 && r_type2
!= R_PPC64_REL14_BRNTAKEN
7738 && r_type2
!= R_PPC64_REL24
))
7741 h2
= sym_hashes
[r_symndx2
- symtab_hdr
->sh_info
];
7742 while (h2
->root
.type
== bfd_link_hash_indirect
7743 || h2
->root
.type
== bfd_link_hash_warning
)
7744 h2
= (struct elf_link_hash_entry
*) h2
->root
.u
.i
.link
;
7745 if (h2
== NULL
|| h2
!= htab
->tls_get_addr
)
7748 /* OK, it checks out. Replace the call. */
7749 offset
= rel
[1].r_offset
;
7750 insn1
= bfd_get_32 (output_bfd
,
7751 contents
+ rel
->r_offset
- 2);
7752 insn3
= bfd_get_32 (output_bfd
,
7753 contents
+ offset
+ 4);
7754 if ((tls_mask
& tls_gd
) != 0)
7757 insn1
&= (1 << 26) - (1 << 2);
7758 insn1
|= 58 << 26; /* ld */
7759 insn2
= 0x7c636a14; /* add 3,3,13 */
7760 rel
[1].r_info
= ELF64_R_INFO (r_symndx2
, R_PPC64_NONE
);
7761 if ((tls_mask
& TLS_EXPLICIT
) == 0)
7762 r_type
= (((r_type
- (R_PPC64_GOT_TLSGD16
& 3)) & 3)
7763 + R_PPC64_GOT_TPREL16_DS
);
7765 r_type
+= R_PPC64_TOC16_DS
- R_PPC64_TOC16
;
7766 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
7771 insn1
= 0x3c6d0000; /* addis 3,13,0 */
7772 insn2
= 0x38630000; /* addi 3,3,0 */
7775 /* Was an LD reloc. */
7777 rel
->r_addend
= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
7778 rel
[1].r_addend
= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
7780 else if (toc_symndx
!= 0)
7781 r_symndx
= toc_symndx
;
7782 r_type
= R_PPC64_TPREL16_HA
;
7783 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
7784 rel
[1].r_info
= ELF64_R_INFO (r_symndx
,
7785 R_PPC64_TPREL16_LO
);
7786 rel
[1].r_offset
+= 2;
7789 || insn3
== CROR_151515
|| insn3
== CROR_313131
)
7793 rel
[1].r_offset
+= 4;
7795 bfd_put_32 (output_bfd
, insn1
, contents
+ rel
->r_offset
- 2);
7796 bfd_put_32 (output_bfd
, insn2
, contents
+ offset
);
7797 bfd_put_32 (output_bfd
, insn3
, contents
+ offset
+ 4);
7798 if (tls_gd
== 0 || toc_symndx
!= 0)
7800 /* We changed the symbol. Start over in order
7801 to get h, sym, sec etc. right. */
7809 case R_PPC64_DTPMOD64
:
7810 if (rel
+ 1 < relend
7811 && rel
[1].r_info
== ELF64_R_INFO (r_symndx
, R_PPC64_DTPREL64
)
7812 && rel
[1].r_offset
== rel
->r_offset
+ 8)
7814 if ((tls_mask
& TLS_GD
) == 0)
7816 rel
[1].r_info
= ELF64_R_INFO (r_symndx
, R_PPC64_NONE
);
7817 if ((tls_mask
& TLS_TPRELGD
) != 0)
7818 r_type
= R_PPC64_TPREL64
;
7821 bfd_put_64 (output_bfd
, 1, contents
+ rel
->r_offset
);
7822 r_type
= R_PPC64_NONE
;
7824 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
7829 if ((tls_mask
& TLS_LD
) == 0)
7831 bfd_put_64 (output_bfd
, 1, contents
+ rel
->r_offset
);
7832 r_type
= R_PPC64_NONE
;
7833 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
7838 case R_PPC64_TPREL64
:
7839 if ((tls_mask
& TLS_TPREL
) == 0)
7841 r_type
= R_PPC64_NONE
;
7842 rel
->r_info
= ELF64_R_INFO (r_symndx
, r_type
);
7847 /* Handle other relocations that tweak non-addend part of insn. */
7854 /* Branch taken prediction relocations. */
7855 case R_PPC64_ADDR14_BRTAKEN
:
7856 case R_PPC64_REL14_BRTAKEN
:
7857 insn
= 0x01 << 21; /* 'y' or 't' bit, lowest bit of BO field. */
7860 /* Branch not taken prediction relocations. */
7861 case R_PPC64_ADDR14_BRNTAKEN
:
7862 case R_PPC64_REL14_BRNTAKEN
:
7863 insn
|= bfd_get_32 (output_bfd
,
7864 contents
+ rel
->r_offset
) & ~(0x01 << 21);
7867 /* Set 'a' bit. This is 0b00010 in BO field for branch
7868 on CR(BI) insns (BO == 001at or 011at), and 0b01000
7869 for branch on CTR insns (BO == 1a00t or 1a01t). */
7870 if ((insn
& (0x14 << 21)) == (0x04 << 21))
7872 else if ((insn
& (0x14 << 21)) == (0x10 << 21))
7879 from
= (rel
->r_offset
7880 + input_section
->output_offset
7881 + input_section
->output_section
->vma
);
7883 /* Invert 'y' bit if not the default. */
7884 if ((bfd_signed_vma
) (relocation
+ rel
->r_addend
- from
) < 0)
7888 bfd_put_32 (output_bfd
, insn
, contents
+ rel
->r_offset
);
7892 /* Calls to functions with a different TOC, such as calls to
7893 shared objects, need to alter the TOC pointer. This is
7894 done using a linkage stub. A REL24 branching to these
7895 linkage stubs needs to be followed by a nop, as the nop
7896 will be replaced with an instruction to restore the TOC
7899 && (fdh
= ((struct ppc_link_hash_entry
*) h
)->oh
) != NULL
7900 && fdh
->plt
.plist
!= NULL
)
7901 || ((fdh
= h
, sec
) != NULL
7902 && sec
->output_section
!= NULL
7903 && (htab
->stub_group
[sec
->id
].toc_off
7904 != htab
->stub_group
[input_section
->id
].toc_off
)))
7905 && (stub_entry
= ppc_get_stub_entry (input_section
, sec
, fdh
,
7907 && (stub_entry
->stub_type
== ppc_stub_plt_call
7908 || stub_entry
->stub_type
== ppc_stub_plt_branch_r2off
7909 || stub_entry
->stub_type
== ppc_stub_long_branch_r2off
))
7911 bfd_boolean can_plt_call
= 0;
7913 if (rel
->r_offset
+ 8 <= input_section
->_cooked_size
)
7915 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
+ 4);
7917 || insn
== CROR_151515
|| insn
== CROR_313131
)
7919 bfd_put_32 (input_bfd
, LD_R2_40R1
,
7920 contents
+ rel
->r_offset
+ 4);
7927 if (stub_entry
->stub_type
== ppc_stub_plt_call
)
7929 /* If this is a plain branch rather than a branch
7930 and link, don't require a nop. */
7931 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
7932 if ((insn
& 1) == 0)
7936 && strcmp (h
->root
.root
.string
,
7937 ".__libc_start_main") == 0)
7939 /* Allow crt1 branch to go via a toc adjusting stub. */
7944 if (strcmp (input_section
->output_section
->name
,
7946 || strcmp (input_section
->output_section
->name
,
7948 (*_bfd_error_handler
)
7949 (_("%s(%s+0x%lx): automatic multiple TOCs "
7950 "not supported using your crt files; "
7951 "recompile with -mminimal-toc or upgrade gcc"),
7952 bfd_archive_filename (input_bfd
),
7953 input_section
->name
,
7954 (long) rel
->r_offset
);
7956 (*_bfd_error_handler
)
7957 (_("%s(%s+0x%lx): sibling call optimization to `%s' "
7958 "does not allow automatic multiple TOCs; "
7959 "recompile with -mminimal-toc or "
7960 "-fno-optimize-sibling-calls, "
7961 "or make `%s' extern"),
7962 bfd_archive_filename (input_bfd
),
7963 input_section
->name
,
7964 (long) rel
->r_offset
,
7967 bfd_set_error (bfd_error_bad_value
);
7974 relocation
= (stub_entry
->stub_offset
7975 + stub_entry
->stub_sec
->output_offset
7976 + stub_entry
->stub_sec
->output_section
->vma
);
7977 if (stub_entry
->stub_type
== ppc_stub_plt_call
)
7978 unresolved_reloc
= FALSE
;
7983 && h
->root
.type
== bfd_link_hash_undefweak
7985 && rel
->r_addend
== 0)
7987 /* Tweak calls to undefined weak functions to point at a
7988 blr. We can thus call a weak function without first
7989 checking whether the function is defined. We have a
7990 blr at the end of .sfpr. */
7991 BFD_ASSERT (htab
->sfpr
->_raw_size
!= 0);
7992 relocation
= (htab
->sfpr
->_raw_size
- 4
7993 + htab
->sfpr
->output_offset
7994 + htab
->sfpr
->output_section
->vma
);
7995 from
= (rel
->r_offset
7996 + input_section
->output_offset
7997 + input_section
->output_section
->vma
);
7999 /* But let's not be silly about it. If the blr isn't in
8000 reach, just go to the next instruction. */
8001 if (relocation
- from
+ (1 << 25) >= (1 << 26)
8002 || htab
->sfpr
->_raw_size
== 0)
8003 relocation
= from
+ 4;
8010 addend
= rel
->r_addend
;
8014 (*_bfd_error_handler
)
8015 (_("%s: unknown relocation type %d for symbol %s"),
8016 bfd_archive_filename (input_bfd
), (int) r_type
, sym_name
);
8018 bfd_set_error (bfd_error_bad_value
);
8024 case R_PPC64_GNU_VTINHERIT
:
8025 case R_PPC64_GNU_VTENTRY
:
8028 /* GOT16 relocations. Like an ADDR16 using the symbol's
8029 address in the GOT as relocation value instead of the
8030 symbol's value itself. Also, create a GOT entry for the
8031 symbol and put the symbol value there. */
8032 case R_PPC64_GOT_TLSGD16
:
8033 case R_PPC64_GOT_TLSGD16_LO
:
8034 case R_PPC64_GOT_TLSGD16_HI
:
8035 case R_PPC64_GOT_TLSGD16_HA
:
8036 tls_type
= TLS_TLS
| TLS_GD
;
8039 case R_PPC64_GOT_TLSLD16
:
8040 case R_PPC64_GOT_TLSLD16_LO
:
8041 case R_PPC64_GOT_TLSLD16_HI
:
8042 case R_PPC64_GOT_TLSLD16_HA
:
8043 tls_type
= TLS_TLS
| TLS_LD
;
8046 case R_PPC64_GOT_TPREL16_DS
:
8047 case R_PPC64_GOT_TPREL16_LO_DS
:
8048 case R_PPC64_GOT_TPREL16_HI
:
8049 case R_PPC64_GOT_TPREL16_HA
:
8050 tls_type
= TLS_TLS
| TLS_TPREL
;
8053 case R_PPC64_GOT_DTPREL16_DS
:
8054 case R_PPC64_GOT_DTPREL16_LO_DS
:
8055 case R_PPC64_GOT_DTPREL16_HI
:
8056 case R_PPC64_GOT_DTPREL16_HA
:
8057 tls_type
= TLS_TLS
| TLS_DTPREL
;
8061 case R_PPC64_GOT16_LO
:
8062 case R_PPC64_GOT16_HI
:
8063 case R_PPC64_GOT16_HA
:
8064 case R_PPC64_GOT16_DS
:
8065 case R_PPC64_GOT16_LO_DS
:
8068 /* Relocation is to the entry for this symbol in the global
8073 unsigned long indx
= 0;
8075 if (tls_type
== (TLS_TLS
| TLS_LD
)
8077 || !(h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
)))
8078 offp
= &ppc64_tlsld_got (input_bfd
)->offset
;
8081 struct got_entry
*ent
;
8085 bfd_boolean dyn
= htab
->elf
.dynamic_sections_created
;
8086 if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
8088 && SYMBOL_REFERENCES_LOCAL (info
, h
)))
8089 /* This is actually a static link, or it is a
8090 -Bsymbolic link and the symbol is defined
8091 locally, or the symbol was forced to be local
8092 because of a version file. */
8097 unresolved_reloc
= FALSE
;
8103 if (local_got_ents
== NULL
)
8105 ent
= local_got_ents
[r_symndx
];
8108 for (; ent
!= NULL
; ent
= ent
->next
)
8109 if (ent
->addend
== rel
->r_addend
8110 && ent
->owner
== input_bfd
8111 && ent
->tls_type
== tls_type
)
8115 offp
= &ent
->got
.offset
;
8118 got
= ppc64_elf_tdata (input_bfd
)->got
;
8122 /* The offset must always be a multiple of 8. We use the
8123 least significant bit to record whether we have already
8124 processed this entry. */
8130 /* Generate relocs for the dynamic linker, except in
8131 the case of TLSLD where we'll use one entry per
8133 asection
*relgot
= ppc64_elf_tdata (input_bfd
)->relgot
;
8136 if ((info
->shared
|| indx
!= 0)
8138 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
8139 || h
->root
.type
!= bfd_link_hash_undefweak
))
8141 outrel
.r_offset
= (got
->output_section
->vma
8142 + got
->output_offset
8144 outrel
.r_addend
= rel
->r_addend
;
8145 if (tls_type
& (TLS_LD
| TLS_GD
))
8147 outrel
.r_addend
= 0;
8148 outrel
.r_info
= ELF64_R_INFO (indx
, R_PPC64_DTPMOD64
);
8149 if (tls_type
== (TLS_TLS
| TLS_GD
))
8151 loc
= relgot
->contents
;
8152 loc
+= (relgot
->reloc_count
++
8153 * sizeof (Elf64_External_Rela
));
8154 bfd_elf64_swap_reloca_out (output_bfd
,
8156 outrel
.r_offset
+= 8;
8157 outrel
.r_addend
= rel
->r_addend
;
8159 = ELF64_R_INFO (indx
, R_PPC64_DTPREL64
);
8162 else if (tls_type
== (TLS_TLS
| TLS_DTPREL
))
8163 outrel
.r_info
= ELF64_R_INFO (indx
, R_PPC64_DTPREL64
);
8164 else if (tls_type
== (TLS_TLS
| TLS_TPREL
))
8165 outrel
.r_info
= ELF64_R_INFO (indx
, R_PPC64_TPREL64
);
8168 outrel
.r_info
= ELF64_R_INFO (indx
, R_PPC64_RELATIVE
);
8170 /* Write the .got section contents for the sake
8172 loc
= got
->contents
+ off
;
8173 bfd_put_64 (output_bfd
, outrel
.r_addend
+ relocation
,
8177 outrel
.r_info
= ELF64_R_INFO (indx
, R_PPC64_GLOB_DAT
);
8179 if (indx
== 0 && tls_type
!= (TLS_TLS
| TLS_LD
))
8181 outrel
.r_addend
+= relocation
;
8182 if (tls_type
& (TLS_GD
| TLS_DTPREL
| TLS_TPREL
))
8183 outrel
.r_addend
-= htab
->elf
.tls_sec
->vma
;
8185 loc
= relgot
->contents
;
8186 loc
+= (relgot
->reloc_count
++
8187 * sizeof (Elf64_External_Rela
));
8188 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
8191 /* Init the .got section contents here if we're not
8192 emitting a reloc. */
8195 relocation
+= rel
->r_addend
;
8196 if (tls_type
== (TLS_TLS
| TLS_LD
))
8198 else if (tls_type
!= 0)
8200 relocation
-= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
8201 if (tls_type
== (TLS_TLS
| TLS_TPREL
))
8202 relocation
+= DTP_OFFSET
- TP_OFFSET
;
8204 if (tls_type
== (TLS_TLS
| TLS_GD
))
8206 bfd_put_64 (output_bfd
, relocation
,
8207 got
->contents
+ off
+ 8);
8212 bfd_put_64 (output_bfd
, relocation
,
8213 got
->contents
+ off
);
8217 if (off
>= (bfd_vma
) -2)
8220 relocation
= got
->output_offset
+ off
;
8222 /* TOC base (r2) is TOC start plus 0x8000. */
8223 addend
= -TOC_BASE_OFF
;
8227 case R_PPC64_PLT16_HA
:
8228 case R_PPC64_PLT16_HI
:
8229 case R_PPC64_PLT16_LO
:
8232 /* Relocation is to the entry for this symbol in the
8233 procedure linkage table. */
8235 /* Resolve a PLT reloc against a local symbol directly,
8236 without using the procedure linkage table. */
8240 /* It's possible that we didn't make a PLT entry for this
8241 symbol. This happens when statically linking PIC code,
8242 or when using -Bsymbolic. Go find a match if there is a
8244 if (htab
->plt
!= NULL
)
8246 struct plt_entry
*ent
;
8247 for (ent
= h
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
8248 if (ent
->addend
== rel
->r_addend
8249 && ent
->plt
.offset
!= (bfd_vma
) -1)
8251 relocation
= (htab
->plt
->output_section
->vma
8252 + htab
->plt
->output_offset
8254 unresolved_reloc
= FALSE
;
8260 /* Relocation value is TOC base. */
8261 relocation
= TOCstart
;
8263 relocation
+= htab
->stub_group
[input_section
->id
].toc_off
;
8264 else if (unresolved_reloc
)
8266 else if (sec
!= NULL
&& sec
->id
<= htab
->top_id
)
8267 relocation
+= htab
->stub_group
[sec
->id
].toc_off
;
8269 unresolved_reloc
= TRUE
;
8272 /* TOC16 relocs. We want the offset relative to the TOC base,
8273 which is the address of the start of the TOC plus 0x8000.
8274 The TOC consists of sections .got, .toc, .tocbss, and .plt,
8277 case R_PPC64_TOC16_LO
:
8278 case R_PPC64_TOC16_HI
:
8279 case R_PPC64_TOC16_DS
:
8280 case R_PPC64_TOC16_LO_DS
:
8281 case R_PPC64_TOC16_HA
:
8282 addend
-= TOCstart
+ htab
->stub_group
[input_section
->id
].toc_off
;
8285 /* Relocate against the beginning of the section. */
8286 case R_PPC64_SECTOFF
:
8287 case R_PPC64_SECTOFF_LO
:
8288 case R_PPC64_SECTOFF_HI
:
8289 case R_PPC64_SECTOFF_DS
:
8290 case R_PPC64_SECTOFF_LO_DS
:
8291 case R_PPC64_SECTOFF_HA
:
8293 addend
-= sec
->output_section
->vma
;
8297 case R_PPC64_REL14_BRNTAKEN
:
8298 case R_PPC64_REL14_BRTAKEN
:
8302 case R_PPC64_TPREL16
:
8303 case R_PPC64_TPREL16_LO
:
8304 case R_PPC64_TPREL16_HI
:
8305 case R_PPC64_TPREL16_HA
:
8306 case R_PPC64_TPREL16_DS
:
8307 case R_PPC64_TPREL16_LO_DS
:
8308 case R_PPC64_TPREL16_HIGHER
:
8309 case R_PPC64_TPREL16_HIGHERA
:
8310 case R_PPC64_TPREL16_HIGHEST
:
8311 case R_PPC64_TPREL16_HIGHESTA
:
8312 addend
-= htab
->elf
.tls_sec
->vma
+ TP_OFFSET
;
8314 /* The TPREL16 relocs shouldn't really be used in shared
8315 libs as they will result in DT_TEXTREL being set, but
8316 support them anyway. */
8320 case R_PPC64_DTPREL16
:
8321 case R_PPC64_DTPREL16_LO
:
8322 case R_PPC64_DTPREL16_HI
:
8323 case R_PPC64_DTPREL16_HA
:
8324 case R_PPC64_DTPREL16_DS
:
8325 case R_PPC64_DTPREL16_LO_DS
:
8326 case R_PPC64_DTPREL16_HIGHER
:
8327 case R_PPC64_DTPREL16_HIGHERA
:
8328 case R_PPC64_DTPREL16_HIGHEST
:
8329 case R_PPC64_DTPREL16_HIGHESTA
:
8330 addend
-= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
8333 case R_PPC64_DTPMOD64
:
8338 case R_PPC64_TPREL64
:
8339 addend
-= htab
->elf
.tls_sec
->vma
+ TP_OFFSET
;
8342 case R_PPC64_DTPREL64
:
8343 addend
-= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
8346 /* Relocations that may need to be propagated if this is a
8351 case R_PPC64_ADDR14
:
8352 case R_PPC64_ADDR14_BRNTAKEN
:
8353 case R_PPC64_ADDR14_BRTAKEN
:
8354 case R_PPC64_ADDR16
:
8355 case R_PPC64_ADDR16_DS
:
8356 case R_PPC64_ADDR16_HA
:
8357 case R_PPC64_ADDR16_HI
:
8358 case R_PPC64_ADDR16_HIGHER
:
8359 case R_PPC64_ADDR16_HIGHERA
:
8360 case R_PPC64_ADDR16_HIGHEST
:
8361 case R_PPC64_ADDR16_HIGHESTA
:
8362 case R_PPC64_ADDR16_LO
:
8363 case R_PPC64_ADDR16_LO_DS
:
8364 case R_PPC64_ADDR24
:
8365 case R_PPC64_ADDR32
:
8366 case R_PPC64_ADDR64
:
8367 case R_PPC64_UADDR16
:
8368 case R_PPC64_UADDR32
:
8369 case R_PPC64_UADDR64
:
8370 /* r_symndx will be zero only for relocs against symbols
8371 from removed linkonce sections, or sections discarded by
8379 if ((input_section
->flags
& SEC_ALLOC
) == 0)
8382 if (NO_OPD_RELOCS
&& is_opd
)
8387 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
8388 || h
->root
.type
!= bfd_link_hash_undefweak
)
8389 && (MUST_BE_DYN_RELOC (r_type
)
8390 || !SYMBOL_CALLS_LOCAL (info
, h
)))
8391 || (ELIMINATE_COPY_RELOCS
8395 && (h
->elf_link_hash_flags
& ELF_LINK_NON_GOT_REF
) == 0
8396 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
8397 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0))
8399 Elf_Internal_Rela outrel
;
8400 bfd_boolean skip
, relocate
;
8405 /* When generating a dynamic object, these relocations
8406 are copied into the output file to be resolved at run
8412 out_off
= _bfd_elf_section_offset (output_bfd
, info
,
8413 input_section
, rel
->r_offset
);
8414 if (out_off
== (bfd_vma
) -1)
8416 else if (out_off
== (bfd_vma
) -2)
8417 skip
= TRUE
, relocate
= TRUE
;
8418 out_off
+= (input_section
->output_section
->vma
8419 + input_section
->output_offset
);
8420 outrel
.r_offset
= out_off
;
8421 outrel
.r_addend
= rel
->r_addend
;
8423 /* Optimize unaligned reloc use. */
8424 if ((r_type
== R_PPC64_ADDR64
&& (out_off
& 7) != 0)
8425 || (r_type
== R_PPC64_UADDR64
&& (out_off
& 7) == 0))
8426 r_type
^= R_PPC64_ADDR64
^ R_PPC64_UADDR64
;
8427 else if ((r_type
== R_PPC64_ADDR32
&& (out_off
& 3) != 0)
8428 || (r_type
== R_PPC64_UADDR32
&& (out_off
& 3) == 0))
8429 r_type
^= R_PPC64_ADDR32
^ R_PPC64_UADDR32
;
8430 else if ((r_type
== R_PPC64_ADDR16
&& (out_off
& 1) != 0)
8431 || (r_type
== R_PPC64_UADDR16
&& (out_off
& 1) == 0))
8432 r_type
^= R_PPC64_ADDR16
^ R_PPC64_UADDR16
;
8435 memset (&outrel
, 0, sizeof outrel
);
8436 else if (!SYMBOL_REFERENCES_LOCAL (info
, h
)
8438 && r_type
!= R_PPC64_TOC
)
8439 outrel
.r_info
= ELF64_R_INFO (h
->dynindx
, r_type
);
8442 /* This symbol is local, or marked to become local,
8443 or this is an opd section reloc which must point
8444 at a local function. */
8445 outrel
.r_addend
+= relocation
;
8446 if (r_type
== R_PPC64_ADDR64
|| r_type
== R_PPC64_TOC
)
8448 if (is_opd
&& h
!= NULL
)
8450 /* Lie about opd entries. This case occurs
8451 when building shared libraries and we
8452 reference a function in another shared
8453 lib. The same thing happens for a weak
8454 definition in an application that's
8455 overridden by a strong definition in a
8456 shared lib. (I believe this is a generic
8457 bug in binutils handling of weak syms.)
8458 In these cases we won't use the opd
8459 entry in this lib. */
8460 unresolved_reloc
= FALSE
;
8462 outrel
.r_info
= ELF64_R_INFO (0, R_PPC64_RELATIVE
);
8464 /* We need to relocate .opd contents for ld.so.
8465 Prelink also wants simple and consistent rules
8466 for relocs. This make all RELATIVE relocs have
8467 *r_offset equal to r_addend. */
8474 if (bfd_is_abs_section (sec
))
8476 else if (sec
== NULL
|| sec
->owner
== NULL
)
8478 bfd_set_error (bfd_error_bad_value
);
8485 osec
= sec
->output_section
;
8486 indx
= elf_section_data (osec
)->dynindx
;
8488 /* We are turning this relocation into one
8489 against a section symbol, so subtract out
8490 the output section's address but not the
8491 offset of the input section in the output
8493 outrel
.r_addend
-= osec
->vma
;
8496 outrel
.r_info
= ELF64_R_INFO (indx
, r_type
);
8500 sreloc
= elf_section_data (input_section
)->sreloc
;
8504 loc
= sreloc
->contents
;
8505 loc
+= sreloc
->reloc_count
++ * sizeof (Elf64_External_Rela
);
8506 bfd_elf64_swap_reloca_out (output_bfd
, &outrel
, loc
);
8508 /* If this reloc is against an external symbol, it will
8509 be computed at runtime, so there's no need to do
8510 anything now. However, for the sake of prelink ensure
8511 that the section contents are a known value. */
8514 unresolved_reloc
= FALSE
;
8515 /* The value chosen here is quite arbitrary as ld.so
8516 ignores section contents except for the special
8517 case of .opd where the contents might be accessed
8518 before relocation. Choose zero, as that won't
8519 cause reloc overflow. */
8522 /* Use *r_offset == r_addend for R_PPC64_ADDR64 relocs
8523 to improve backward compatibility with older
8525 if (r_type
== R_PPC64_ADDR64
)
8526 addend
= outrel
.r_addend
;
8527 /* Adjust pc_relative relocs to have zero in *r_offset. */
8528 else if (ppc64_elf_howto_table
[r_type
]->pc_relative
)
8529 addend
= (input_section
->output_section
->vma
8530 + input_section
->output_offset
8537 case R_PPC64_GLOB_DAT
:
8538 case R_PPC64_JMP_SLOT
:
8539 case R_PPC64_RELATIVE
:
8540 /* We shouldn't ever see these dynamic relocs in relocatable
8544 case R_PPC64_PLTGOT16
:
8545 case R_PPC64_PLTGOT16_DS
:
8546 case R_PPC64_PLTGOT16_HA
:
8547 case R_PPC64_PLTGOT16_HI
:
8548 case R_PPC64_PLTGOT16_LO
:
8549 case R_PPC64_PLTGOT16_LO_DS
:
8550 case R_PPC64_PLTREL32
:
8551 case R_PPC64_PLTREL64
:
8552 /* These ones haven't been implemented yet. */
8554 (*_bfd_error_handler
)
8555 (_("%s: relocation %s is not supported for symbol %s."),
8556 bfd_archive_filename (input_bfd
),
8557 ppc64_elf_howto_table
[r_type
]->name
, sym_name
);
8559 bfd_set_error (bfd_error_invalid_operation
);
8564 /* Do any further special processing. */
8570 case R_PPC64_ADDR16_HA
:
8571 case R_PPC64_ADDR16_HIGHERA
:
8572 case R_PPC64_ADDR16_HIGHESTA
:
8573 case R_PPC64_GOT16_HA
:
8574 case R_PPC64_PLTGOT16_HA
:
8575 case R_PPC64_PLT16_HA
:
8576 case R_PPC64_TOC16_HA
:
8577 case R_PPC64_SECTOFF_HA
:
8578 case R_PPC64_TPREL16_HA
:
8579 case R_PPC64_DTPREL16_HA
:
8580 case R_PPC64_GOT_TLSGD16_HA
:
8581 case R_PPC64_GOT_TLSLD16_HA
:
8582 case R_PPC64_GOT_TPREL16_HA
:
8583 case R_PPC64_GOT_DTPREL16_HA
:
8584 case R_PPC64_TPREL16_HIGHER
:
8585 case R_PPC64_TPREL16_HIGHERA
:
8586 case R_PPC64_TPREL16_HIGHEST
:
8587 case R_PPC64_TPREL16_HIGHESTA
:
8588 case R_PPC64_DTPREL16_HIGHER
:
8589 case R_PPC64_DTPREL16_HIGHERA
:
8590 case R_PPC64_DTPREL16_HIGHEST
:
8591 case R_PPC64_DTPREL16_HIGHESTA
:
8592 /* It's just possible that this symbol is a weak symbol
8593 that's not actually defined anywhere. In that case,
8594 'sec' would be NULL, and we should leave the symbol
8595 alone (it will be set to zero elsewhere in the link). */
8597 /* Add 0x10000 if sign bit in 0:15 is set.
8598 Bits 0:15 are not used. */
8602 case R_PPC64_ADDR16_DS
:
8603 case R_PPC64_ADDR16_LO_DS
:
8604 case R_PPC64_GOT16_DS
:
8605 case R_PPC64_GOT16_LO_DS
:
8606 case R_PPC64_PLT16_LO_DS
:
8607 case R_PPC64_SECTOFF_DS
:
8608 case R_PPC64_SECTOFF_LO_DS
:
8609 case R_PPC64_TOC16_DS
:
8610 case R_PPC64_TOC16_LO_DS
:
8611 case R_PPC64_PLTGOT16_DS
:
8612 case R_PPC64_PLTGOT16_LO_DS
:
8613 case R_PPC64_GOT_TPREL16_DS
:
8614 case R_PPC64_GOT_TPREL16_LO_DS
:
8615 case R_PPC64_GOT_DTPREL16_DS
:
8616 case R_PPC64_GOT_DTPREL16_LO_DS
:
8617 case R_PPC64_TPREL16_DS
:
8618 case R_PPC64_TPREL16_LO_DS
:
8619 case R_PPC64_DTPREL16_DS
:
8620 case R_PPC64_DTPREL16_LO_DS
:
8621 insn
= bfd_get_32 (input_bfd
, contents
+ (rel
->r_offset
& ~3));
8623 /* If this reloc is against an lq insn, then the value must be
8624 a multiple of 16. This is somewhat of a hack, but the
8625 "correct" way to do this by defining _DQ forms of all the
8626 _DS relocs bloats all reloc switches in this file. It
8627 doesn't seem to make much sense to use any of these relocs
8628 in data, so testing the insn should be safe. */
8629 if ((insn
& (0x3f << 26)) == (56u << 26))
8631 if (((relocation
+ addend
) & mask
) != 0)
8633 (*_bfd_error_handler
)
8634 (_("%s: error: relocation %s not a multiple of %d"),
8635 bfd_archive_filename (input_bfd
),
8636 ppc64_elf_howto_table
[r_type
]->name
,
8638 bfd_set_error (bfd_error_bad_value
);
8645 case R_PPC64_REL14_BRNTAKEN
:
8646 case R_PPC64_REL14_BRTAKEN
:
8647 max_br_offset
= 1 << 15;
8651 max_br_offset
= 1 << 25;
8654 /* If the branch is out of reach or the TOC register needs
8655 adjusting, then redirect the call to the local stub for
8657 from
= (rel
->r_offset
8658 + input_section
->output_offset
8659 + input_section
->output_section
->vma
);
8660 if ((relocation
+ addend
- from
+ max_br_offset
>= 2 * max_br_offset
8662 && sec
->output_section
!= NULL
8663 && sec
->id
<= htab
->top_id
8664 && (htab
->stub_group
[sec
->id
].toc_off
8665 != htab
->stub_group
[input_section
->id
].toc_off
)))
8666 && (stub_entry
= ppc_get_stub_entry (input_section
, sec
, h
,
8667 rel
, htab
)) != NULL
)
8669 /* Munge up the value and addend so that we call the stub
8670 rather than the procedure directly. */
8671 relocation
= (stub_entry
->stub_offset
8672 + stub_entry
->stub_sec
->output_offset
8673 + stub_entry
->stub_sec
->output_section
->vma
);
8679 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
8680 because such sections are not SEC_ALLOC and thus ld.so will
8681 not process them. */
8682 if (unresolved_reloc
8683 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
8684 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0))
8686 (*_bfd_error_handler
)
8687 (_("%s(%s+0x%lx): unresolvable %s relocation against symbol `%s'"),
8688 bfd_archive_filename (input_bfd
),
8689 bfd_get_section_name (input_bfd
, input_section
),
8690 (long) rel
->r_offset
,
8691 ppc64_elf_howto_table
[(int) r_type
]->name
,
8692 h
->root
.root
.string
);
8696 r
= _bfd_final_link_relocate (ppc64_elf_howto_table
[(int) r_type
],
8704 if (r
!= bfd_reloc_ok
)
8706 if (sym_name
== NULL
)
8707 sym_name
= "(null)";
8708 if (r
== bfd_reloc_overflow
)
8713 && h
->root
.type
== bfd_link_hash_undefweak
8714 && ppc64_elf_howto_table
[r_type
]->pc_relative
)
8716 /* Assume this is a call protected by other code that
8717 detects the symbol is undefined. If this is the case,
8718 we can safely ignore the overflow. If not, the
8719 program is hosed anyway, and a little warning isn't
8725 if (!((*info
->callbacks
->reloc_overflow
)
8726 (info
, sym_name
, ppc64_elf_howto_table
[r_type
]->name
,
8727 rel
->r_addend
, input_bfd
, input_section
, rel
->r_offset
)))
8732 (*_bfd_error_handler
)
8733 (_("%s(%s+0x%lx): %s reloc against `%s': error %d"),
8734 bfd_archive_filename (input_bfd
),
8735 bfd_get_section_name (input_bfd
, input_section
),
8736 (long) rel
->r_offset
,
8737 ppc64_elf_howto_table
[r_type
]->name
,
8748 /* Adjust the value of any local symbols in opd sections. */
8751 ppc64_elf_output_symbol_hook (struct bfd_link_info
*info
,
8752 const char *name ATTRIBUTE_UNUSED
,
8753 Elf_Internal_Sym
*elfsym
,
8754 asection
*input_sec
,
8755 struct elf_link_hash_entry
*h
)
8761 || input_sec
== NULL
8762 || ppc64_elf_section_data (input_sec
) == NULL
8763 || (adjust
= ppc64_elf_section_data (input_sec
)->opd
.adjust
) == NULL
)
8766 value
= elfsym
->st_value
- input_sec
->output_offset
;
8767 if (!info
->relocatable
)
8768 value
-= input_sec
->output_section
->vma
;
8770 elfsym
->st_value
+= adjust
[value
/ 24];
8774 /* Finish up dynamic symbol handling. We set the contents of various
8775 dynamic sections here. */
8778 ppc64_elf_finish_dynamic_symbol (bfd
*output_bfd
,
8779 struct bfd_link_info
*info
,
8780 struct elf_link_hash_entry
*h
,
8781 Elf_Internal_Sym
*sym
)
8783 struct ppc_link_hash_table
*htab
;
8786 htab
= ppc_hash_table (info
);
8787 dynobj
= htab
->elf
.dynobj
;
8789 if (((struct ppc_link_hash_entry
*) h
)->is_func_descriptor
)
8791 struct plt_entry
*ent
;
8792 Elf_Internal_Rela rela
;
8795 for (ent
= h
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
8796 if (ent
->plt
.offset
!= (bfd_vma
) -1)
8798 /* This symbol has an entry in the procedure linkage
8799 table. Set it up. */
8801 if (htab
->plt
== NULL
8802 || htab
->relplt
== NULL
8803 || htab
->glink
== NULL
)
8806 /* Create a JMP_SLOT reloc to inform the dynamic linker to
8807 fill in the PLT entry. */
8808 rela
.r_offset
= (htab
->plt
->output_section
->vma
8809 + htab
->plt
->output_offset
8811 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_PPC64_JMP_SLOT
);
8812 rela
.r_addend
= ent
->addend
;
8814 loc
= htab
->relplt
->contents
;
8815 loc
+= ((ent
->plt
.offset
- PLT_INITIAL_ENTRY_SIZE
) / PLT_ENTRY_SIZE
8816 * sizeof (Elf64_External_Rela
));
8817 bfd_elf64_swap_reloca_out (output_bfd
, &rela
, loc
);
8821 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_COPY
) != 0)
8823 Elf_Internal_Rela rela
;
8826 /* This symbol needs a copy reloc. Set it up. */
8828 if (h
->dynindx
== -1
8829 || (h
->root
.type
!= bfd_link_hash_defined
8830 && h
->root
.type
!= bfd_link_hash_defweak
)
8831 || htab
->relbss
== NULL
)
8834 rela
.r_offset
= (h
->root
.u
.def
.value
8835 + h
->root
.u
.def
.section
->output_section
->vma
8836 + h
->root
.u
.def
.section
->output_offset
);
8837 rela
.r_info
= ELF64_R_INFO (h
->dynindx
, R_PPC64_COPY
);
8839 loc
= htab
->relbss
->contents
;
8840 loc
+= htab
->relbss
->reloc_count
++ * sizeof (Elf64_External_Rela
);
8841 bfd_elf64_swap_reloca_out (output_bfd
, &rela
, loc
);
8844 /* Mark some specially defined symbols as absolute. */
8845 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0)
8846 sym
->st_shndx
= SHN_ABS
;
8851 /* Used to decide how to sort relocs in an optimal manner for the
8852 dynamic linker, before writing them out. */
8854 static enum elf_reloc_type_class
8855 ppc64_elf_reloc_type_class (const Elf_Internal_Rela
*rela
)
8857 enum elf_ppc64_reloc_type r_type
;
8859 r_type
= ELF64_R_TYPE (rela
->r_info
);
8862 case R_PPC64_RELATIVE
:
8863 return reloc_class_relative
;
8864 case R_PPC64_JMP_SLOT
:
8865 return reloc_class_plt
;
8867 return reloc_class_copy
;
8869 return reloc_class_normal
;
8873 /* Finish up the dynamic sections. */
8876 ppc64_elf_finish_dynamic_sections (bfd
*output_bfd
,
8877 struct bfd_link_info
*info
)
8879 struct ppc_link_hash_table
*htab
;
8883 htab
= ppc_hash_table (info
);
8884 dynobj
= htab
->elf
.dynobj
;
8885 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
8887 if (htab
->elf
.dynamic_sections_created
)
8889 Elf64_External_Dyn
*dyncon
, *dynconend
;
8891 if (sdyn
== NULL
|| htab
->got
== NULL
)
8894 dyncon
= (Elf64_External_Dyn
*) sdyn
->contents
;
8895 dynconend
= (Elf64_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
8896 for (; dyncon
< dynconend
; dyncon
++)
8898 Elf_Internal_Dyn dyn
;
8901 bfd_elf64_swap_dyn_in (dynobj
, dyncon
, &dyn
);
8908 case DT_PPC64_GLINK
:
8910 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
8911 /* We stupidly defined DT_PPC64_GLINK to be the start
8912 of glink rather than the first entry point, which is
8913 what ld.so needs, and now have a bigger stub to
8914 support automatic multiple TOCs. */
8915 dyn
.d_un
.d_ptr
+= GLINK_CALL_STUB_SIZE
- 32;
8919 s
= bfd_get_section_by_name (output_bfd
, ".opd");
8922 dyn
.d_un
.d_ptr
= s
->vma
;
8925 case DT_PPC64_OPDSZ
:
8926 s
= bfd_get_section_by_name (output_bfd
, ".opd");
8929 dyn
.d_un
.d_val
= s
->_raw_size
;
8934 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
8939 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
8943 dyn
.d_un
.d_val
= htab
->relplt
->_raw_size
;
8947 /* Don't count procedure linkage table relocs in the
8948 overall reloc count. */
8952 dyn
.d_un
.d_val
-= s
->_raw_size
;
8956 /* We may not be using the standard ELF linker script.
8957 If .rela.plt is the first .rela section, we adjust
8958 DT_RELA to not include it. */
8962 if (dyn
.d_un
.d_ptr
!= s
->output_section
->vma
+ s
->output_offset
)
8964 dyn
.d_un
.d_ptr
+= s
->_raw_size
;
8968 bfd_elf64_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
8972 if (htab
->got
!= NULL
&& htab
->got
->_raw_size
!= 0)
8974 /* Fill in the first entry in the global offset table.
8975 We use it to hold the link-time TOCbase. */
8976 bfd_put_64 (output_bfd
,
8977 elf_gp (output_bfd
) + TOC_BASE_OFF
,
8978 htab
->got
->contents
);
8980 /* Set .got entry size. */
8981 elf_section_data (htab
->got
->output_section
)->this_hdr
.sh_entsize
= 8;
8984 if (htab
->plt
!= NULL
&& htab
->plt
->_raw_size
!= 0)
8986 /* Set .plt entry size. */
8987 elf_section_data (htab
->plt
->output_section
)->this_hdr
.sh_entsize
8991 /* We need to handle writing out multiple GOT sections ourselves,
8992 since we didn't add them to DYNOBJ. */
8993 while ((dynobj
= dynobj
->link_next
) != NULL
)
8996 s
= ppc64_elf_tdata (dynobj
)->got
;
8998 && s
->_raw_size
!= 0
8999 && s
->output_section
!= bfd_abs_section_ptr
9000 && !bfd_set_section_contents (output_bfd
, s
->output_section
,
9001 s
->contents
, s
->output_offset
,
9004 s
= ppc64_elf_tdata (dynobj
)->relgot
;
9006 && s
->_raw_size
!= 0
9007 && s
->output_section
!= bfd_abs_section_ptr
9008 && !bfd_set_section_contents (output_bfd
, s
->output_section
,
9009 s
->contents
, s
->output_offset
,
9017 #include "elf64-target.h"