* elflink.c (_bfd_elf_create_dynamic_sections): Don't set SEC_CODE
[binutils-gdb.git] / bfd / elf64-ppc.c
1 /* PowerPC64-specific support for 64-bit ELF.
2 Copyright 1999, 2000, 2001, 2002 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
6 This file is part of BFD, the Binary File Descriptor library.
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
21
22 /* This file is based on the 64-bit PowerPC ELF ABI. It is also based
23 on the file elf32-ppc.c. */
24
25 #include "bfd.h"
26 #include "sysdep.h"
27 #include "bfdlink.h"
28 #include "libbfd.h"
29 #include "elf-bfd.h"
30 #include "elf/ppc.h"
31 #include "elf64-ppc.h"
32
33 #define USE_RELA /* we want RELA relocations, not REL. */
34
35
36 static void ppc_howto_init
37 PARAMS ((void));
38 static reloc_howto_type *ppc64_elf_reloc_type_lookup
39 PARAMS ((bfd *abfd, bfd_reloc_code_real_type code));
40 static void ppc64_elf_info_to_howto
41 PARAMS ((bfd *abfd, arelent *cache_ptr, Elf64_Internal_Rela *dst));
42 static bfd_reloc_status_type ppc64_elf_addr16_ha_reloc
43 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
44 static boolean ppc64_elf_set_private_flags
45 PARAMS ((bfd *, flagword));
46 static boolean ppc64_elf_merge_private_bfd_data
47 PARAMS ((bfd *, bfd *));
48 static boolean ppc64_elf_section_from_shdr
49 PARAMS ((bfd *, Elf64_Internal_Shdr *, char *));
50 static struct bfd_hash_entry *link_hash_newfunc
51 PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *));
52 static struct bfd_link_hash_table *ppc64_elf_link_hash_table_create
53 PARAMS ((bfd *));
54 static boolean create_got_section
55 PARAMS ((bfd *, struct bfd_link_info *));
56 static boolean ppc64_elf_create_dynamic_sections
57 PARAMS ((bfd *, struct bfd_link_info *));
58 static void ppc64_elf_copy_indirect_symbol
59 PARAMS ((struct elf_link_hash_entry *, struct elf_link_hash_entry *));
60 static boolean ppc64_elf_check_relocs
61 PARAMS ((bfd *, struct bfd_link_info *, asection *,
62 const Elf_Internal_Rela *));
63 static asection * ppc64_elf_gc_mark_hook
64 PARAMS ((bfd *abfd, struct bfd_link_info *info, Elf_Internal_Rela *rel,
65 struct elf_link_hash_entry *h, Elf_Internal_Sym *sym));
66 static boolean ppc64_elf_gc_sweep_hook
67 PARAMS ((bfd *abfd, struct bfd_link_info *info, asection *sec,
68 const Elf_Internal_Rela *relocs));
69 static boolean ppc64_elf_adjust_dynamic_symbol
70 PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *));
71 static boolean allocate_dynrelocs
72 PARAMS ((struct elf_link_hash_entry *, PTR));
73 static boolean readonly_dynrelocs
74 PARAMS ((struct elf_link_hash_entry *, PTR));
75 static enum elf_reloc_type_class ppc64_elf_reloc_type_class
76 PARAMS ((const Elf_Internal_Rela *));
77 static boolean ppc64_elf_size_dynamic_sections
78 PARAMS ((bfd *, struct bfd_link_info *));
79 static bfd_byte *build_plt_stub
80 PARAMS ((bfd *, bfd_byte *, int, int));
81 static boolean build_one_stub
82 PARAMS ((struct elf_link_hash_entry *, PTR));
83 static boolean ppc64_elf_fake_sections
84 PARAMS ((bfd *, Elf64_Internal_Shdr *, asection *));
85 static boolean ppc64_elf_relocate_section
86 PARAMS ((bfd *, struct bfd_link_info *info, bfd *, asection *, bfd_byte *,
87 Elf_Internal_Rela *relocs, Elf_Internal_Sym *local_syms,
88 asection **));
89 static boolean ppc64_elf_finish_dynamic_symbol
90 PARAMS ((bfd *, struct bfd_link_info *, struct elf_link_hash_entry *,
91 Elf_Internal_Sym *));
92 static boolean ppc64_elf_finish_dynamic_sections
93 PARAMS ((bfd *, struct bfd_link_info *));
94
95
96 /* Mask to set RA in memory instructions. */
97 #define RA_REGISTER_MASK 0x001f0000
98
99 /* Value to shift register by to insert RA. */
100 #define RA_REGISTER_SHIFT 16
101
102 /* The name of the dynamic interpreter. This is put in the .interp
103 section. */
104 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
105
106 /* The size in bytes of an entry in the procedure linkage table. */
107 #define PLT_ENTRY_SIZE 24
108
109 /* The initial size of the plt reserved for the dynamic linker. */
110 #define PLT_INITIAL_ENTRY_SIZE PLT_ENTRY_SIZE
111
112 /* TOC base pointers offset from start of TOC. */
113 #define TOC_BASE_OFF (0x8000)
114
115 /* .plt call stub instructions. */
116 #define ADDIS_R12_R2 0x3d820000 /* addis %r12,%r2,xxx@ha */
117 #define STD_R2_40R1 0xf8410028 /* std %r2,40(%r1) */
118 #define LD_R11_0R12 0xe96c0000 /* ld %r11,xxx+0@l(%r12) */
119 #define LD_R2_0R12 0xe84c0000 /* ld %r2,xxx+8@l(%r12) */
120 #define MTCTR_R11 0x7d6903a6 /* mtctr %r11 */
121 /* ld %r11,xxx+16@l(%r12) */
122 #define BCTR 0x4e800420 /* bctr */
123
124 /* The normal stub is this size. */
125 #define PLT_CALL_STUB_SIZE (7*4)
126
127 /* But sometimes the .plt entry crosses a 64k boundary, and we need
128 to adjust the high word with this insn. */
129 #define ADDIS_R12_R12_1 0x3d8c0001 /* addis %r12,%r12,1 */
130
131 /* The .glink fixup call stub is the same as the .plt call stub, but
132 the first instruction restores r2, and the std is omitted. */
133 #define LD_R2_40R1 0xe8410028 /* ld %r2,40(%r1) */
134
135 /* Always allow this much space. */
136 #define GLINK_CALL_STUB_SIZE (8*4)
137
138 /* Pad with this. */
139 #define NOP 0x60000000
140
141 /* .glink entries for the first 32k functions are two instructions. */
142 #define LI_R0_0 0x38000000 /* li %r0,0 */
143 #define B_DOT 0x48000000 /* b . */
144
145 /* After that, we need two instructions to load the index, followed by
146 a branch. */
147 #define LIS_R0_0 0x3c000000 /* lis %r0,0 */
148 #define ORI_R0_R0_0 0x60008000 /* ori %r0,%r0,0 */
149 \f
150 /* Relocation HOWTO's. */
151 static reloc_howto_type *ppc64_elf_howto_table[(int) R_PPC_max];
152
153 static reloc_howto_type ppc64_elf_howto_raw[] = {
154 /* This reloc does nothing. */
155 HOWTO (R_PPC64_NONE, /* type */
156 0, /* rightshift */
157 2, /* size (0 = byte, 1 = short, 2 = long) */
158 32, /* bitsize */
159 false, /* pc_relative */
160 0, /* bitpos */
161 complain_overflow_bitfield, /* complain_on_overflow */
162 bfd_elf_generic_reloc, /* special_function */
163 "R_PPC64_NONE", /* name */
164 false, /* partial_inplace */
165 0, /* src_mask */
166 0, /* dst_mask */
167 false), /* pcrel_offset */
168
169 /* A standard 32 bit relocation. */
170 HOWTO (R_PPC64_ADDR32, /* type */
171 0, /* rightshift */
172 2, /* size (0 = byte, 1 = short, 2 = long) */
173 32, /* bitsize */
174 false, /* pc_relative */
175 0, /* bitpos */
176 complain_overflow_bitfield, /* complain_on_overflow */
177 bfd_elf_generic_reloc, /* special_function */
178 "R_PPC64_ADDR32", /* name */
179 false, /* partial_inplace */
180 0, /* src_mask */
181 0xffffffff, /* dst_mask */
182 false), /* pcrel_offset */
183
184 /* An absolute 26 bit branch; the lower two bits must be zero.
185 FIXME: we don't check that, we just clear them. */
186 HOWTO (R_PPC64_ADDR24, /* type */
187 0, /* rightshift */
188 2, /* size (0 = byte, 1 = short, 2 = long) */
189 26, /* bitsize */
190 false, /* pc_relative */
191 0, /* bitpos */
192 complain_overflow_bitfield, /* complain_on_overflow */
193 bfd_elf_generic_reloc, /* special_function */
194 "R_PPC64_ADDR24", /* name */
195 false, /* partial_inplace */
196 0, /* src_mask */
197 0x3fffffc, /* dst_mask */
198 false), /* pcrel_offset */
199
200 /* A standard 16 bit relocation. */
201 HOWTO (R_PPC64_ADDR16, /* type */
202 0, /* rightshift */
203 1, /* size (0 = byte, 1 = short, 2 = long) */
204 16, /* bitsize */
205 false, /* pc_relative */
206 0, /* bitpos */
207 complain_overflow_bitfield, /* complain_on_overflow */
208 bfd_elf_generic_reloc, /* special_function */
209 "R_PPC64_ADDR16", /* name */
210 false, /* partial_inplace */
211 0, /* src_mask */
212 0xffff, /* dst_mask */
213 false), /* pcrel_offset */
214
215 /* A 16 bit relocation without overflow. */
216 HOWTO (R_PPC64_ADDR16_LO, /* type */
217 0, /* rightshift */
218 1, /* size (0 = byte, 1 = short, 2 = long) */
219 16, /* bitsize */
220 false, /* pc_relative */
221 0, /* bitpos */
222 complain_overflow_dont,/* complain_on_overflow */
223 bfd_elf_generic_reloc, /* special_function */
224 "R_PPC64_ADDR16_LO", /* name */
225 false, /* partial_inplace */
226 0, /* src_mask */
227 0xffff, /* dst_mask */
228 false), /* pcrel_offset */
229
230 /* Bits 16-31 of an address. */
231 HOWTO (R_PPC64_ADDR16_HI, /* type */
232 16, /* rightshift */
233 1, /* size (0 = byte, 1 = short, 2 = long) */
234 16, /* bitsize */
235 false, /* pc_relative */
236 0, /* bitpos */
237 complain_overflow_dont, /* complain_on_overflow */
238 bfd_elf_generic_reloc, /* special_function */
239 "R_PPC64_ADDR16_HI", /* name */
240 false, /* partial_inplace */
241 0, /* src_mask */
242 0xffff, /* dst_mask */
243 false), /* pcrel_offset */
244
245 /* Bits 16-31 of an address, plus 1 if the contents of the low 16
246 bits, treated as a signed number, is negative. */
247 HOWTO (R_PPC64_ADDR16_HA, /* type */
248 16, /* rightshift */
249 1, /* size (0 = byte, 1 = short, 2 = long) */
250 16, /* bitsize */
251 false, /* pc_relative */
252 0, /* bitpos */
253 complain_overflow_dont, /* complain_on_overflow */
254 ppc64_elf_addr16_ha_reloc, /* special_function */
255 "R_PPC64_ADDR16_HA", /* name */
256 false, /* partial_inplace */
257 0, /* src_mask */
258 0xffff, /* dst_mask */
259 false), /* pcrel_offset */
260
261 /* An absolute 16 bit branch; the lower two bits must be zero.
262 FIXME: we don't check that, we just clear them. */
263 HOWTO (R_PPC64_ADDR14, /* type */
264 0, /* rightshift */
265 2, /* size (0 = byte, 1 = short, 2 = long) */
266 16, /* bitsize */
267 false, /* pc_relative */
268 0, /* bitpos */
269 complain_overflow_bitfield, /* complain_on_overflow */
270 bfd_elf_generic_reloc, /* special_function */
271 "R_PPC64_ADDR14", /* name */
272 false, /* partial_inplace */
273 0, /* src_mask */
274 0xfffc, /* dst_mask */
275 false), /* pcrel_offset */
276
277 /* An absolute 16 bit branch, for which bit 10 should be set to
278 indicate that the branch is expected to be taken. The lower two
279 bits must be zero. */
280 HOWTO (R_PPC64_ADDR14_BRTAKEN, /* type */
281 0, /* rightshift */
282 2, /* size (0 = byte, 1 = short, 2 = long) */
283 16, /* bitsize */
284 false, /* pc_relative */
285 0, /* bitpos */
286 complain_overflow_bitfield, /* complain_on_overflow */
287 bfd_elf_generic_reloc, /* special_function */
288 "R_PPC64_ADDR14_BRTAKEN",/* name */
289 false, /* partial_inplace */
290 0, /* src_mask */
291 0xfffc, /* dst_mask */
292 false), /* pcrel_offset */
293
294 /* An absolute 16 bit branch, for which bit 10 should be set to
295 indicate that the branch is not expected to be taken. The lower
296 two bits must be zero. */
297 HOWTO (R_PPC64_ADDR14_BRNTAKEN, /* type */
298 0, /* rightshift */
299 2, /* size (0 = byte, 1 = short, 2 = long) */
300 16, /* bitsize */
301 false, /* pc_relative */
302 0, /* bitpos */
303 complain_overflow_bitfield, /* complain_on_overflow */
304 bfd_elf_generic_reloc, /* special_function */
305 "R_PPC64_ADDR14_BRNTAKEN",/* name */
306 false, /* partial_inplace */
307 0, /* src_mask */
308 0xfffc, /* dst_mask */
309 false), /* pcrel_offset */
310
311 /* A relative 26 bit branch; the lower two bits must be zero. */
312 HOWTO (R_PPC64_REL24, /* type */
313 0, /* rightshift */
314 2, /* size (0 = byte, 1 = short, 2 = long) */
315 26, /* bitsize */
316 true, /* pc_relative */
317 0, /* bitpos */
318 complain_overflow_signed, /* complain_on_overflow */
319 bfd_elf_generic_reloc, /* special_function */
320 "R_PPC64_REL24", /* name */
321 false, /* partial_inplace */
322 0, /* src_mask */
323 0x3fffffc, /* dst_mask */
324 true), /* pcrel_offset */
325
326 /* A relative 16 bit branch; the lower two bits must be zero. */
327 HOWTO (R_PPC64_REL14, /* type */
328 0, /* rightshift */
329 2, /* size (0 = byte, 1 = short, 2 = long) */
330 16, /* bitsize */
331 true, /* pc_relative */
332 0, /* bitpos */
333 complain_overflow_signed, /* complain_on_overflow */
334 bfd_elf_generic_reloc, /* special_function */
335 "R_PPC64_REL14", /* name */
336 false, /* partial_inplace */
337 0, /* src_mask */
338 0xfffc, /* dst_mask */
339 true), /* pcrel_offset */
340
341 /* A relative 16 bit branch. Bit 10 should be set to indicate that
342 the branch is expected to be taken. The lower two bits must be
343 zero. */
344 HOWTO (R_PPC64_REL14_BRTAKEN, /* type */
345 0, /* rightshift */
346 2, /* size (0 = byte, 1 = short, 2 = long) */
347 16, /* bitsize */
348 true, /* pc_relative */
349 0, /* bitpos */
350 complain_overflow_signed, /* complain_on_overflow */
351 bfd_elf_generic_reloc, /* special_function */
352 "R_PPC64_REL14_BRTAKEN", /* name */
353 false, /* partial_inplace */
354 0, /* src_mask */
355 0xfffc, /* dst_mask */
356 true), /* pcrel_offset */
357
358 /* A relative 16 bit branch. Bit 10 should be set to indicate that
359 the branch is not expected to be taken. The lower two bits must
360 be zero. */
361 HOWTO (R_PPC64_REL14_BRNTAKEN, /* type */
362 0, /* rightshift */
363 2, /* size (0 = byte, 1 = short, 2 = long) */
364 16, /* bitsize */
365 true, /* pc_relative */
366 0, /* bitpos */
367 complain_overflow_signed, /* complain_on_overflow */
368 bfd_elf_generic_reloc, /* special_function */
369 "R_PPC64_REL14_BRNTAKEN",/* name */
370 false, /* partial_inplace */
371 0, /* src_mask */
372 0xfffc, /* dst_mask */
373 true), /* pcrel_offset */
374
375 /* Like R_PPC64_ADDR16, but referring to the GOT table entry for the
376 symbol. */
377 HOWTO (R_PPC64_GOT16, /* type */
378 0, /* rightshift */
379 1, /* size (0 = byte, 1 = short, 2 = long) */
380 16, /* bitsize */
381 false, /* pc_relative */
382 0, /* bitpos */
383 complain_overflow_signed, /* complain_on_overflow */
384 bfd_elf_generic_reloc, /* special_function */
385 "R_PPC64_GOT16", /* name */
386 false, /* partial_inplace */
387 0, /* src_mask */
388 0xffff, /* dst_mask */
389 false), /* pcrel_offset */
390
391 /* Like R_PPC64_ADDR16_LO, but referring to the GOT table entry for
392 the symbol. */
393 HOWTO (R_PPC64_GOT16_LO, /* type */
394 0, /* rightshift */
395 1, /* size (0 = byte, 1 = short, 2 = long) */
396 16, /* bitsize */
397 false, /* pc_relative */
398 0, /* bitpos */
399 complain_overflow_dont, /* complain_on_overflow */
400 bfd_elf_generic_reloc, /* special_function */
401 "R_PPC64_GOT16_LO", /* name */
402 false, /* partial_inplace */
403 0, /* src_mask */
404 0xffff, /* dst_mask */
405 false), /* pcrel_offset */
406
407 /* Like R_PPC64_ADDR16_HI, but referring to the GOT table entry for
408 the symbol. */
409 HOWTO (R_PPC64_GOT16_HI, /* type */
410 16, /* rightshift */
411 1, /* size (0 = byte, 1 = short, 2 = long) */
412 16, /* bitsize */
413 false, /* pc_relative */
414 0, /* bitpos */
415 complain_overflow_dont,/* complain_on_overflow */
416 bfd_elf_generic_reloc, /* special_function */
417 "R_PPC64_GOT16_HI", /* name */
418 false, /* partial_inplace */
419 0, /* src_mask */
420 0xffff, /* dst_mask */
421 false), /* pcrel_offset */
422
423 /* Like R_PPC64_ADDR16_HA, but referring to the GOT table entry for
424 the symbol. */
425 HOWTO (R_PPC64_GOT16_HA, /* type */
426 16, /* rightshift */
427 1, /* size (0 = byte, 1 = short, 2 = long) */
428 16, /* bitsize */
429 false, /* pc_relative */
430 0, /* bitpos */
431 complain_overflow_dont,/* complain_on_overflow */
432 ppc64_elf_addr16_ha_reloc, /* special_function */
433 "R_PPC64_GOT16_HA", /* name */
434 false, /* partial_inplace */
435 0, /* src_mask */
436 0xffff, /* dst_mask */
437 false), /* pcrel_offset */
438
439 /* This is used only by the dynamic linker. The symbol should exist
440 both in the object being run and in some shared library. The
441 dynamic linker copies the data addressed by the symbol from the
442 shared library into the object, because the object being
443 run has to have the data at some particular address. */
444 HOWTO (R_PPC64_COPY, /* type */
445 0, /* rightshift */
446 2, /* size (0 = byte, 1 = short, 2 = long) */
447 32, /* bitsize */
448 false, /* pc_relative */
449 0, /* bitpos */
450 complain_overflow_bitfield, /* complain_on_overflow */
451 bfd_elf_generic_reloc, /* special_function */
452 "R_PPC64_COPY", /* name */
453 false, /* partial_inplace */
454 0, /* src_mask */
455 0, /* dst_mask */
456 false), /* pcrel_offset */
457
458 /* Like R_PPC64_ADDR64, but used when setting global offset table
459 entries. */
460 HOWTO (R_PPC64_GLOB_DAT, /* type */
461 0, /* rightshift */
462 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
463 64, /* bitsize */
464 false, /* pc_relative */
465 0, /* bitpos */
466 complain_overflow_dont, /* complain_on_overflow */
467 bfd_elf_generic_reloc, /* special_function */
468 "R_PPC64_GLOB_DAT", /* name */
469 false, /* partial_inplace */
470 0, /* src_mask */
471 0xffffffffffffffff, /* dst_mask */
472 false), /* pcrel_offset */
473
474 /* Created by the link editor. Marks a procedure linkage table
475 entry for a symbol. */
476 HOWTO (R_PPC64_JMP_SLOT, /* type */
477 0, /* rightshift */
478 0, /* size (0 = byte, 1 = short, 2 = long) */
479 0, /* bitsize */
480 false, /* pc_relative */
481 0, /* bitpos */
482 complain_overflow_dont, /* complain_on_overflow */
483 bfd_elf_generic_reloc, /* special_function */
484 "R_PPC64_JMP_SLOT", /* name */
485 false, /* partial_inplace */
486 0, /* src_mask */
487 0, /* dst_mask */
488 false), /* pcrel_offset */
489
490 /* Used only by the dynamic linker. When the object is run, this
491 doubleword64 is set to the load address of the object, plus the
492 addend. */
493 HOWTO (R_PPC64_RELATIVE, /* type */
494 0, /* rightshift */
495 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
496 64, /* bitsize */
497 false, /* pc_relative */
498 0, /* bitpos */
499 complain_overflow_dont, /* complain_on_overflow */
500 bfd_elf_generic_reloc, /* special_function */
501 "R_PPC64_RELATIVE", /* name */
502 false, /* partial_inplace */
503 0, /* src_mask */
504 0xffffffffffffffff, /* dst_mask */
505 false), /* pcrel_offset */
506
507 /* Like R_PPC64_ADDR32, but may be unaligned. */
508 HOWTO (R_PPC64_UADDR32, /* type */
509 0, /* rightshift */
510 2, /* size (0 = byte, 1 = short, 2 = long) */
511 32, /* bitsize */
512 false, /* pc_relative */
513 0, /* bitpos */
514 complain_overflow_bitfield, /* complain_on_overflow */
515 bfd_elf_generic_reloc, /* special_function */
516 "R_PPC64_UADDR32", /* name */
517 false, /* partial_inplace */
518 0, /* src_mask */
519 0xffffffff, /* dst_mask */
520 false), /* pcrel_offset */
521
522 /* Like R_PPC64_ADDR16, but may be unaligned. */
523 HOWTO (R_PPC64_UADDR16, /* type */
524 0, /* rightshift */
525 1, /* size (0 = byte, 1 = short, 2 = long) */
526 16, /* bitsize */
527 false, /* pc_relative */
528 0, /* bitpos */
529 complain_overflow_bitfield, /* complain_on_overflow */
530 bfd_elf_generic_reloc, /* special_function */
531 "R_PPC64_UADDR16", /* name */
532 false, /* partial_inplace */
533 0, /* src_mask */
534 0xffff, /* dst_mask */
535 false), /* pcrel_offset */
536
537 /* 32-bit PC relative. */
538 HOWTO (R_PPC64_REL32, /* type */
539 0, /* rightshift */
540 2, /* size (0 = byte, 1 = short, 2 = long) */
541 32, /* bitsize */
542 true, /* pc_relative */
543 0, /* bitpos */
544 /* FIXME: Verify. Was complain_overflow_bitfield. */
545 complain_overflow_signed, /* complain_on_overflow */
546 bfd_elf_generic_reloc, /* special_function */
547 "R_PPC64_REL32", /* name */
548 false, /* partial_inplace */
549 0, /* src_mask */
550 0xffffffff, /* dst_mask */
551 true), /* pcrel_offset */
552
553 /* 32-bit relocation to the symbol's procedure linkage table.
554 FIXME: R_PPC64_PLT32 not supported. */
555 HOWTO (R_PPC64_PLT32, /* type */
556 0, /* rightshift */
557 2, /* size (0 = byte, 1 = short, 2 = long) */
558 32, /* bitsize */
559 false, /* pc_relative */
560 0, /* bitpos */
561 complain_overflow_bitfield, /* complain_on_overflow */
562 bfd_elf_generic_reloc, /* special_function */
563 "R_PPC64_PLT32", /* name */
564 false, /* partial_inplace */
565 0, /* src_mask */
566 0, /* dst_mask */
567 false), /* pcrel_offset */
568
569 /* 32-bit PC relative relocation to the symbol's procedure linkage table.
570 FIXME: R_PPC64_PLTREL32 not supported. */
571 HOWTO (R_PPC64_PLTREL32, /* type */
572 0, /* rightshift */
573 2, /* size (0 = byte, 1 = short, 2 = long) */
574 32, /* bitsize */
575 true, /* pc_relative */
576 0, /* bitpos */
577 complain_overflow_signed, /* complain_on_overflow */
578 bfd_elf_generic_reloc, /* special_function */
579 "R_PPC64_PLTREL32", /* name */
580 false, /* partial_inplace */
581 0, /* src_mask */
582 0, /* dst_mask */
583 true), /* pcrel_offset */
584
585 /* Like R_PPC64_ADDR16_LO, but referring to the PLT table entry for
586 the symbol. */
587 HOWTO (R_PPC64_PLT16_LO, /* type */
588 0, /* rightshift */
589 1, /* size (0 = byte, 1 = short, 2 = long) */
590 16, /* bitsize */
591 false, /* pc_relative */
592 0, /* bitpos */
593 complain_overflow_dont, /* complain_on_overflow */
594 bfd_elf_generic_reloc, /* special_function */
595 "R_PPC64_PLT16_LO", /* name */
596 false, /* partial_inplace */
597 0, /* src_mask */
598 0xffff, /* dst_mask */
599 false), /* pcrel_offset */
600
601 /* Like R_PPC64_ADDR16_HI, but referring to the PLT table entry for
602 the symbol. */
603 HOWTO (R_PPC64_PLT16_HI, /* type */
604 16, /* rightshift */
605 1, /* size (0 = byte, 1 = short, 2 = long) */
606 16, /* bitsize */
607 false, /* pc_relative */
608 0, /* bitpos */
609 complain_overflow_dont, /* complain_on_overflow */
610 bfd_elf_generic_reloc, /* special_function */
611 "R_PPC64_PLT16_HI", /* name */
612 false, /* partial_inplace */
613 0, /* src_mask */
614 0xffff, /* dst_mask */
615 false), /* pcrel_offset */
616
617 /* Like R_PPC64_ADDR16_HA, but referring to the PLT table entry for
618 the symbol. */
619 HOWTO (R_PPC64_PLT16_HA, /* type */
620 16, /* rightshift */
621 1, /* size (0 = byte, 1 = short, 2 = long) */
622 16, /* bitsize */
623 false, /* pc_relative */
624 0, /* bitpos */
625 complain_overflow_dont, /* complain_on_overflow */
626 ppc64_elf_addr16_ha_reloc, /* special_function */
627 "R_PPC64_PLT16_HA", /* name */
628 false, /* partial_inplace */
629 0, /* src_mask */
630 0xffff, /* dst_mask */
631 false), /* pcrel_offset */
632
633 /* 32-bit section relative relocation. */
634 /* FIXME: Verify R_PPC64_SECTOFF. Seems strange with size=2 and
635 dst_mask=0. */
636 HOWTO (R_PPC64_SECTOFF, /* type */
637 0, /* rightshift */
638 2, /* size (0 = byte, 1 = short, 2 = long) */
639 32, /* bitsize */
640 true, /* pc_relative */
641 0, /* bitpos */
642 complain_overflow_bitfield, /* complain_on_overflow */
643 bfd_elf_generic_reloc, /* special_function */
644 "R_PPC64_SECTOFF", /* name */
645 false, /* partial_inplace */
646 0, /* src_mask */
647 0, /* dst_mask */
648 true), /* pcrel_offset */
649
650 /* 16-bit lower half section relative relocation. */
651 HOWTO (R_PPC64_SECTOFF_LO, /* type */
652 0, /* rightshift */
653 1, /* size (0 = byte, 1 = short, 2 = long) */
654 16, /* bitsize */
655 false, /* pc_relative */
656 0, /* bitpos */
657 complain_overflow_dont, /* complain_on_overflow */
658 bfd_elf_generic_reloc, /* special_function */
659 "R_PPC64_SECTOFF_LO", /* name */
660 false, /* partial_inplace */
661 0, /* src_mask */
662 0xffff, /* dst_mask */
663 false), /* pcrel_offset */
664
665 /* 16-bit upper half section relative relocation. */
666 HOWTO (R_PPC64_SECTOFF_HI, /* type */
667 16, /* rightshift */
668 1, /* size (0 = byte, 1 = short, 2 = long) */
669 16, /* bitsize */
670 false, /* pc_relative */
671 0, /* bitpos */
672 complain_overflow_dont, /* complain_on_overflow */
673 bfd_elf_generic_reloc, /* special_function */
674 "R_PPC64_SECTOFF_HI", /* name */
675 false, /* partial_inplace */
676 0, /* src_mask */
677 0xffff, /* dst_mask */
678 false), /* pcrel_offset */
679
680 /* 16-bit upper half adjusted section relative relocation. */
681 HOWTO (R_PPC64_SECTOFF_HA, /* type */
682 16, /* rightshift */
683 1, /* size (0 = byte, 1 = short, 2 = long) */
684 16, /* bitsize */
685 false, /* pc_relative */
686 0, /* bitpos */
687 complain_overflow_dont, /* complain_on_overflow */
688 ppc64_elf_addr16_ha_reloc, /* special_function */
689 "R_PPC64_SECTOFF_HA", /* name */
690 false, /* partial_inplace */
691 0, /* src_mask */
692 0xffff, /* dst_mask */
693 false), /* pcrel_offset */
694
695 /* Like R_PPC64_REL24 without touching the two least significant
696 bits. */
697 /* FIXME: Verify R_PPC64_ADDR30. */
698 HOWTO (R_PPC64_ADDR30, /* type */
699 2, /* rightshift */
700 2, /* size (0 = byte, 1 = short, 2 = long) */
701 30, /* bitsize */
702 true, /* pc_relative */
703 0, /* bitpos */
704 complain_overflow_dont, /* complain_on_overflow */
705 bfd_elf_generic_reloc, /* special_function */
706 "R_PPC64_ADDR30", /* name */
707 false, /* partial_inplace */
708 0, /* src_mask */
709 0xfffffffc, /* dst_mask */
710 true), /* pcrel_offset */
711
712 /* Relocs in the 64-bit PowerPC ELF ABI, not in the 32-bit ABI. */
713
714 /* A standard 64-bit relocation. */
715 HOWTO (R_PPC64_ADDR64, /* type */
716 0, /* rightshift */
717 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
718 64, /* bitsize */
719 false, /* pc_relative */
720 0, /* bitpos */
721 complain_overflow_dont, /* complain_on_overflow */
722 bfd_elf_generic_reloc, /* special_function */
723 "R_PPC64_ADDR64", /* name */
724 false, /* partial_inplace */
725 0, /* src_mask */
726 0xffffffffffffffff, /* dst_mask */
727 false), /* pcrel_offset */
728
729 /* The bits 32-47 of an address. */
730 HOWTO (R_PPC64_ADDR16_HIGHER, /* type */
731 32, /* rightshift */
732 1, /* size (0 = byte, 1 = short, 2 = long) */
733 16, /* bitsize */
734 false, /* pc_relative */
735 0, /* bitpos */
736 complain_overflow_dont, /* complain_on_overflow */
737 bfd_elf_generic_reloc, /* special_function */
738 "R_PPC64_ADDR16_HIGHER", /* name */
739 false, /* partial_inplace */
740 0, /* src_mask */
741 0xffff, /* dst_mask */
742 false), /* pcrel_offset */
743
744 /* The bits 32-47 of an address, plus 1 if the contents of the low
745 16 bits, treated as a signed number, is negative. */
746 HOWTO (R_PPC64_ADDR16_HIGHERA, /* type */
747 32, /* rightshift */
748 1, /* size (0 = byte, 1 = short, 2 = long) */
749 16, /* bitsize */
750 false, /* pc_relative */
751 0, /* bitpos */
752 complain_overflow_dont, /* complain_on_overflow */
753 ppc64_elf_addr16_ha_reloc, /* special_function */
754 "R_PPC64_ADDR16_HIGHERA", /* name */
755 false, /* partial_inplace */
756 0, /* src_mask */
757 0xffff, /* dst_mask */
758 false), /* pcrel_offset */
759
760 /* The bits 48-63 of an address. */
761 HOWTO (R_PPC64_ADDR16_HIGHEST,/* type */
762 48, /* rightshift */
763 1, /* size (0 = byte, 1 = short, 2 = long) */
764 16, /* bitsize */
765 false, /* pc_relative */
766 0, /* bitpos */
767 complain_overflow_dont, /* complain_on_overflow */
768 bfd_elf_generic_reloc, /* special_function */
769 "R_PPC64_ADDR16_HIGHEST", /* name */
770 false, /* partial_inplace */
771 0, /* src_mask */
772 0xffff, /* dst_mask */
773 false), /* pcrel_offset */
774
775 /* The bits 48-63 of an address, plus 1 if the contents of the low
776 16 bits, treated as a signed number, is negative. */
777 HOWTO (R_PPC64_ADDR16_HIGHESTA,/* type */
778 48, /* rightshift */
779 1, /* size (0 = byte, 1 = short, 2 = long) */
780 16, /* bitsize */
781 false, /* pc_relative */
782 0, /* bitpos */
783 complain_overflow_dont, /* complain_on_overflow */
784 ppc64_elf_addr16_ha_reloc, /* special_function */
785 "R_PPC64_ADDR16_HIGHESTA", /* name */
786 false, /* partial_inplace */
787 0, /* src_mask */
788 0xffff, /* dst_mask */
789 false), /* pcrel_offset */
790
791 /* Like ADDR64, but may be unaligned. */
792 HOWTO (R_PPC64_UADDR64, /* type */
793 0, /* rightshift */
794 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
795 64, /* bitsize */
796 false, /* pc_relative */
797 0, /* bitpos */
798 complain_overflow_dont, /* complain_on_overflow */
799 bfd_elf_generic_reloc, /* special_function */
800 "R_PPC64_UADDR64", /* name */
801 false, /* partial_inplace */
802 0, /* src_mask */
803 0xffffffffffffffff, /* dst_mask */
804 false), /* pcrel_offset */
805
806 /* 64-bit relative relocation. */
807 HOWTO (R_PPC64_REL64, /* type */
808 0, /* rightshift */
809 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
810 64, /* bitsize */
811 true, /* pc_relative */
812 0, /* bitpos */
813 complain_overflow_dont, /* complain_on_overflow */
814 bfd_elf_generic_reloc, /* special_function */
815 "R_PPC64_REL64", /* name */
816 false, /* partial_inplace */
817 0, /* src_mask */
818 0xffffffffffffffff, /* dst_mask */
819 true), /* pcrel_offset */
820
821 /* 64-bit relocation to the symbol's procedure linkage table. */
822 /* FIXME: R_PPC64_PLT64 not supported. */
823 HOWTO (R_PPC64_PLT64, /* type */
824 0, /* rightshift */
825 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
826 64, /* bitsize */
827 false, /* pc_relative */
828 0, /* bitpos */
829 complain_overflow_dont, /* complain_on_overflow */
830 bfd_elf_generic_reloc, /* special_function */
831 "R_PPC64_PLT64", /* name */
832 false, /* partial_inplace */
833 0, /* src_mask */
834 0, /* dst_mask */
835 false), /* pcrel_offset */
836
837 /* 64-bit PC relative relocation to the symbol's procedure linkage
838 table. */
839 /* FIXME: R_PPC64_PLTREL64 not supported. */
840 HOWTO (R_PPC64_PLTREL64, /* type */
841 0, /* rightshift */
842 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
843 64, /* bitsize */
844 true, /* pc_relative */
845 0, /* bitpos */
846 complain_overflow_dont, /* complain_on_overflow */
847 bfd_elf_generic_reloc, /* special_function */
848 "R_PPC64_PLTREL64", /* name */
849 false, /* partial_inplace */
850 0, /* src_mask */
851 0, /* dst_mask */
852 true), /* pcrel_offset */
853
854 /* 16 bit TOC-relative relocation. */
855
856 /* R_PPC64_TOC16 47 half16* S + A - .TOC. */
857 HOWTO (R_PPC64_TOC16, /* type */
858 0, /* rightshift */
859 1, /* size (0 = byte, 1 = short, 2 = long) */
860 16, /* bitsize */
861 false, /* pc_relative */
862 0, /* bitpos */
863 complain_overflow_signed, /* complain_on_overflow */
864 bfd_elf_generic_reloc, /* special_function */
865 "R_PPC64_TOC16", /* name */
866 false, /* partial_inplace */
867 0, /* src_mask */
868 0xffff, /* dst_mask */
869 false), /* pcrel_offset */
870
871 /* 16 bit TOC-relative relocation without overflow. */
872
873 /* R_PPC64_TOC16_LO 48 half16 #lo (S + A - .TOC.) */
874 HOWTO (R_PPC64_TOC16_LO, /* type */
875 0, /* rightshift */
876 1, /* size (0 = byte, 1 = short, 2 = long) */
877 16, /* bitsize */
878 false, /* pc_relative */
879 0, /* bitpos */
880 complain_overflow_dont, /* complain_on_overflow */
881 bfd_elf_generic_reloc, /* special_function */
882 "R_PPC64_TOC16_LO", /* name */
883 false, /* partial_inplace */
884 0, /* src_mask */
885 0xffff, /* dst_mask */
886 false), /* pcrel_offset */
887
888 /* 16 bit TOC-relative relocation, high 16 bits. */
889
890 /* R_PPC64_TOC16_HI 49 half16 #hi (S + A - .TOC.) */
891 HOWTO (R_PPC64_TOC16_HI, /* type */
892 16, /* rightshift */
893 1, /* size (0 = byte, 1 = short, 2 = long) */
894 16, /* bitsize */
895 false, /* pc_relative */
896 0, /* bitpos */
897 complain_overflow_dont, /* complain_on_overflow */
898 bfd_elf_generic_reloc, /* special_function */
899 "R_PPC64_TOC16_HI", /* name */
900 false, /* partial_inplace */
901 0, /* src_mask */
902 0xffff, /* dst_mask */
903 false), /* pcrel_offset */
904
905 /* 16 bit TOC-relative relocation, high 16 bits, plus 1 if the
906 contents of the low 16 bits, treated as a signed number, is
907 negative. */
908
909 /* R_PPC64_TOC16_HA 50 half16 #ha (S + A - .TOC.) */
910 HOWTO (R_PPC64_TOC16_HA, /* type */
911 16, /* rightshift */
912 1, /* size (0 = byte, 1 = short, 2 = long) */
913 16, /* bitsize */
914 false, /* pc_relative */
915 0, /* bitpos */
916 complain_overflow_dont, /* complain_on_overflow */
917 ppc64_elf_addr16_ha_reloc, /* special_function */
918 "R_PPC64_TOC16_HA", /* name */
919 false, /* partial_inplace */
920 0, /* src_mask */
921 0xffff, /* dst_mask */
922 false), /* pcrel_offset */
923
924 /* 64-bit relocation; insert value of TOC base (.TOC.). */
925
926 /* R_PPC64_TOC 51 doubleword64 .TOC. */
927 HOWTO (R_PPC64_TOC, /* type */
928 0, /* rightshift */
929 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
930 64, /* bitsize */
931 false, /* pc_relative */
932 0, /* bitpos */
933 complain_overflow_bitfield, /* complain_on_overflow */
934 bfd_elf_generic_reloc, /* special_function */
935 "R_PPC64_TOC", /* name */
936 false, /* partial_inplace */
937 0, /* src_mask */
938 0xffffffffffffffff, /* dst_mask */
939 false), /* pcrel_offset */
940
941 /* Like R_PPC64_GOT16, but also informs the link editor that the
942 value to relocate may (!) refer to a PLT entry which the link
943 editor (a) may replace with the symbol value. If the link editor
944 is unable to fully resolve the symbol, it may (b) create a PLT
945 entry and store the address to the new PLT entry in the GOT.
946 This permits lazy resolution of function symbols at run time.
947 The link editor may also skip all of this and just (c) emit a
948 R_PPC64_GLOB_DAT to tie the symbol to the GOT entry. */
949 /* FIXME: R_PPC64_PLTGOT16 not implemented. */
950 HOWTO (R_PPC64_PLTGOT16, /* type */
951 0, /* rightshift */
952 1, /* size (0 = byte, 1 = short, 2 = long) */
953 16, /* bitsize */
954 false, /* pc_relative */
955 0, /* bitpos */
956 complain_overflow_signed, /* complain_on_overflow */
957 bfd_elf_generic_reloc, /* special_function */
958 "R_PPC64_PLTGOT16", /* name */
959 false, /* partial_inplace */
960 0, /* src_mask */
961 0xffff, /* dst_mask */
962 false), /* pcrel_offset */
963
964 /* Like R_PPC64_PLTGOT16, but without overflow. */
965 /* FIXME: R_PPC64_PLTGOT16_LO not implemented. */
966 HOWTO (R_PPC64_PLTGOT16_LO, /* type */
967 0, /* rightshift */
968 1, /* size (0 = byte, 1 = short, 2 = long) */
969 16, /* bitsize */
970 false, /* pc_relative */
971 0, /* bitpos */
972 complain_overflow_dont, /* complain_on_overflow */
973 bfd_elf_generic_reloc, /* special_function */
974 "R_PPC64_PLTGOT16_LO", /* name */
975 false, /* partial_inplace */
976 0, /* src_mask */
977 0xffff, /* dst_mask */
978 false), /* pcrel_offset */
979
980 /* Like R_PPC64_PLT_GOT16, but using bits 16-31 of the address. */
981 /* FIXME: R_PPC64_PLTGOT16_HI not implemented. */
982 HOWTO (R_PPC64_PLTGOT16_HI, /* type */
983 16, /* rightshift */
984 1, /* size (0 = byte, 1 = short, 2 = long) */
985 16, /* bitsize */
986 false, /* pc_relative */
987 0, /* bitpos */
988 complain_overflow_dont, /* complain_on_overflow */
989 bfd_elf_generic_reloc, /* special_function */
990 "R_PPC64_PLTGOT16_HI", /* name */
991 false, /* partial_inplace */
992 0, /* src_mask */
993 0xffff, /* dst_mask */
994 false), /* pcrel_offset */
995
996 /* Like R_PPC64_PLT_GOT16, but using bits 16-31 of the address, plus
997 1 if the contents of the low 16 bits, treated as a signed number,
998 is negative. */
999 /* FIXME: R_PPC64_PLTGOT16_HA not implemented. */
1000 HOWTO (R_PPC64_PLTGOT16_HA, /* type */
1001 16, /* rightshift */
1002 1, /* size (0 = byte, 1 = short, 2 = long) */
1003 16, /* bitsize */
1004 false, /* pc_relative */
1005 0, /* bitpos */
1006 complain_overflow_dont,/* complain_on_overflow */
1007 ppc64_elf_addr16_ha_reloc, /* special_function */
1008 "R_PPC64_PLTGOT16_HA", /* name */
1009 false, /* partial_inplace */
1010 0, /* src_mask */
1011 0xffff, /* dst_mask */
1012 false), /* pcrel_offset */
1013
1014 /* Like R_PPC64_ADDR16, but for instructions with a DS field. */
1015 HOWTO (R_PPC64_ADDR16_DS, /* type */
1016 0, /* rightshift */
1017 1, /* size (0 = byte, 1 = short, 2 = long) */
1018 16, /* bitsize */
1019 false, /* pc_relative */
1020 0, /* bitpos */
1021 complain_overflow_bitfield, /* complain_on_overflow */
1022 bfd_elf_generic_reloc, /* special_function */
1023 "R_PPC64_ADDR16_DS", /* name */
1024 false, /* partial_inplace */
1025 0, /* src_mask */
1026 0xfffc, /* dst_mask */
1027 false), /* pcrel_offset */
1028
1029 /* Like R_PPC64_ADDR16_LO, but for instructions with a DS field. */
1030 HOWTO (R_PPC64_ADDR16_LO_DS, /* type */
1031 0, /* rightshift */
1032 1, /* size (0 = byte, 1 = short, 2 = long) */
1033 16, /* bitsize */
1034 false, /* pc_relative */
1035 0, /* bitpos */
1036 complain_overflow_dont,/* complain_on_overflow */
1037 bfd_elf_generic_reloc, /* special_function */
1038 "R_PPC64_ADDR16_LO_DS",/* name */
1039 false, /* partial_inplace */
1040 0, /* src_mask */
1041 0xfffc, /* dst_mask */
1042 false), /* pcrel_offset */
1043
1044 /* Like R_PPC64_GOT16, but for instructions with a DS field. */
1045 HOWTO (R_PPC64_GOT16_DS, /* type */
1046 0, /* rightshift */
1047 1, /* size (0 = byte, 1 = short, 2 = long) */
1048 16, /* bitsize */
1049 false, /* pc_relative */
1050 0, /* bitpos */
1051 complain_overflow_signed, /* complain_on_overflow */
1052 bfd_elf_generic_reloc, /* special_function */
1053 "R_PPC64_GOT16_DS", /* name */
1054 false, /* partial_inplace */
1055 0, /* src_mask */
1056 0xfffc, /* dst_mask */
1057 false), /* pcrel_offset */
1058
1059 /* Like R_PPC64_GOT16_LO, but for instructions with a DS field. */
1060 HOWTO (R_PPC64_GOT16_LO_DS, /* type */
1061 0, /* rightshift */
1062 1, /* size (0 = byte, 1 = short, 2 = long) */
1063 16, /* bitsize */
1064 false, /* pc_relative */
1065 0, /* bitpos */
1066 complain_overflow_dont, /* complain_on_overflow */
1067 bfd_elf_generic_reloc, /* special_function */
1068 "R_PPC64_GOT16_LO_DS", /* name */
1069 false, /* partial_inplace */
1070 0, /* src_mask */
1071 0xfffc, /* dst_mask */
1072 false), /* pcrel_offset */
1073
1074 /* Like R_PPC64_PLT16_LO, but for instructions with a DS field. */
1075 HOWTO (R_PPC64_PLT16_LO_DS, /* type */
1076 0, /* rightshift */
1077 1, /* size (0 = byte, 1 = short, 2 = long) */
1078 16, /* bitsize */
1079 false, /* pc_relative */
1080 0, /* bitpos */
1081 complain_overflow_dont, /* complain_on_overflow */
1082 bfd_elf_generic_reloc, /* special_function */
1083 "R_PPC64_PLT16_LO_DS", /* name */
1084 false, /* partial_inplace */
1085 0, /* src_mask */
1086 0xfffc, /* dst_mask */
1087 false), /* pcrel_offset */
1088
1089 /* Like R_PPC64_SECTOFF, but for instructions with a DS field. */
1090 /* FIXME: Verify R_PPC64_SECTOFF. Seems strange with size=2 and
1091 dst_mask=0. */
1092 HOWTO (R_PPC64_SECTOFF_DS, /* type */
1093 0, /* rightshift */
1094 2, /* size (0 = byte, 1 = short, 2 = long) */
1095 32, /* bitsize */
1096 true, /* pc_relative */
1097 0, /* bitpos */
1098 complain_overflow_bitfield, /* complain_on_overflow */
1099 bfd_elf_generic_reloc, /* special_function */
1100 "R_PPC64_SECTOFF_DS", /* name */
1101 false, /* partial_inplace */
1102 0, /* src_mask */
1103 0, /* dst_mask */
1104 true), /* pcrel_offset */
1105
1106 /* Like R_PPC64_SECTOFF_LO, but for instructions with a DS field. */
1107 HOWTO (R_PPC64_SECTOFF_LO_DS, /* type */
1108 0, /* rightshift */
1109 1, /* size (0 = byte, 1 = short, 2 = long) */
1110 16, /* bitsize */
1111 false, /* pc_relative */
1112 0, /* bitpos */
1113 complain_overflow_dont, /* complain_on_overflow */
1114 bfd_elf_generic_reloc, /* special_function */
1115 "R_PPC64_SECTOFF_LO_DS",/* name */
1116 false, /* partial_inplace */
1117 0, /* src_mask */
1118 0xfffc, /* dst_mask */
1119 false), /* pcrel_offset */
1120
1121 /* Like R_PPC64_TOC16, but for instructions with a DS field. */
1122 HOWTO (R_PPC64_TOC16_DS, /* type */
1123 0, /* rightshift */
1124 1, /* size (0 = byte, 1 = short, 2 = long) */
1125 16, /* bitsize */
1126 false, /* pc_relative */
1127 0, /* bitpos */
1128 complain_overflow_signed, /* complain_on_overflow */
1129 bfd_elf_generic_reloc, /* special_function */
1130 "R_PPC64_TOC16_DS", /* name */
1131 false, /* partial_inplace */
1132 0, /* src_mask */
1133 0xfffc, /* dst_mask */
1134 false), /* pcrel_offset */
1135
1136 /* Like R_PPC64_TOC16_LO, but for instructions with a DS field. */
1137 HOWTO (R_PPC64_TOC16_LO_DS, /* type */
1138 0, /* rightshift */
1139 1, /* size (0 = byte, 1 = short, 2 = long) */
1140 16, /* bitsize */
1141 false, /* pc_relative */
1142 0, /* bitpos */
1143 complain_overflow_dont, /* complain_on_overflow */
1144 bfd_elf_generic_reloc, /* special_function */
1145 "R_PPC64_TOC16_LO_DS", /* name */
1146 false, /* partial_inplace */
1147 0, /* src_mask */
1148 0xfffc, /* dst_mask */
1149 false), /* pcrel_offset */
1150
1151 /* Like R_PPC64_PLTGOT16, but for instructions with a DS field. */
1152 /* FIXME: R_PPC64_PLTGOT16_DS not implemented. */
1153 HOWTO (R_PPC64_PLTGOT16_DS, /* type */
1154 0, /* rightshift */
1155 1, /* size (0 = byte, 1 = short, 2 = long) */
1156 16, /* bitsize */
1157 false, /* pc_relative */
1158 0, /* bitpos */
1159 complain_overflow_signed, /* complain_on_overflow */
1160 bfd_elf_generic_reloc, /* special_function */
1161 "R_PPC64_PLTGOT16_DS", /* name */
1162 false, /* partial_inplace */
1163 0, /* src_mask */
1164 0xfffc, /* dst_mask */
1165 false), /* pcrel_offset */
1166
1167 /* Like R_PPC64_PLTGOT16_LO, but for instructions with a DS field. */
1168 /* FIXME: R_PPC64_PLTGOT16_LO not implemented. */
1169 HOWTO (R_PPC64_PLTGOT16_LO_DS,/* type */
1170 0, /* rightshift */
1171 1, /* size (0 = byte, 1 = short, 2 = long) */
1172 16, /* bitsize */
1173 false, /* pc_relative */
1174 0, /* bitpos */
1175 complain_overflow_dont, /* complain_on_overflow */
1176 bfd_elf_generic_reloc, /* special_function */
1177 "R_PPC64_PLTGOT16_LO_DS",/* name */
1178 false, /* partial_inplace */
1179 0, /* src_mask */
1180 0xfffc, /* dst_mask */
1181 false), /* pcrel_offset */
1182
1183 /* GNU extension to record C++ vtable hierarchy. */
1184 HOWTO (R_PPC64_GNU_VTINHERIT, /* type */
1185 0, /* rightshift */
1186 0, /* size (0 = byte, 1 = short, 2 = long) */
1187 0, /* bitsize */
1188 false, /* pc_relative */
1189 0, /* bitpos */
1190 complain_overflow_dont, /* complain_on_overflow */
1191 NULL, /* special_function */
1192 "R_PPC64_GNU_VTINHERIT", /* name */
1193 false, /* partial_inplace */
1194 0, /* src_mask */
1195 0, /* dst_mask */
1196 false), /* pcrel_offset */
1197
1198 /* GNU extension to record C++ vtable member usage. */
1199 HOWTO (R_PPC64_GNU_VTENTRY, /* type */
1200 0, /* rightshift */
1201 0, /* size (0 = byte, 1 = short, 2 = long) */
1202 0, /* bitsize */
1203 false, /* pc_relative */
1204 0, /* bitpos */
1205 complain_overflow_dont, /* complain_on_overflow */
1206 NULL, /* special_function */
1207 "R_PPC64_GNU_VTENTRY", /* name */
1208 false, /* partial_inplace */
1209 0, /* src_mask */
1210 0, /* dst_mask */
1211 false), /* pcrel_offset */
1212 };
1213
1214 \f
1215 /* Initialize the ppc64_elf_howto_table, so that linear accesses can
1216 be done. */
1217
1218 static void
1219 ppc_howto_init ()
1220 {
1221 unsigned int i, type;
1222
1223 for (i = 0;
1224 i < sizeof (ppc64_elf_howto_raw) / sizeof (ppc64_elf_howto_raw[0]);
1225 i++)
1226 {
1227 type = ppc64_elf_howto_raw[i].type;
1228 BFD_ASSERT (type < (sizeof (ppc64_elf_howto_table)
1229 / sizeof (ppc64_elf_howto_table[0])));
1230 ppc64_elf_howto_table[type] = &ppc64_elf_howto_raw[i];
1231 }
1232 }
1233
1234 static reloc_howto_type *
1235 ppc64_elf_reloc_type_lookup (abfd, code)
1236 bfd *abfd ATTRIBUTE_UNUSED;
1237 bfd_reloc_code_real_type code;
1238 {
1239 enum elf_ppc_reloc_type ppc_reloc = R_PPC_NONE;
1240
1241 if (!ppc64_elf_howto_table[R_PPC64_ADDR32])
1242 /* Initialize howto table if needed. */
1243 ppc_howto_init ();
1244
1245 switch ((int) code)
1246 {
1247 default:
1248 return (reloc_howto_type *) NULL;
1249
1250 case BFD_RELOC_NONE: ppc_reloc = R_PPC64_NONE;
1251 break;
1252 case BFD_RELOC_32: ppc_reloc = R_PPC64_ADDR32;
1253 break;
1254 case BFD_RELOC_PPC_BA26: ppc_reloc = R_PPC64_ADDR24;
1255 break;
1256 case BFD_RELOC_16: ppc_reloc = R_PPC64_ADDR16;
1257 break;
1258 case BFD_RELOC_LO16: ppc_reloc = R_PPC64_ADDR16_LO;
1259 break;
1260 case BFD_RELOC_HI16: ppc_reloc = R_PPC64_ADDR16_HI;
1261 break;
1262 case BFD_RELOC_HI16_S: ppc_reloc = R_PPC64_ADDR16_HA;
1263 break;
1264 case BFD_RELOC_PPC_BA16: ppc_reloc = R_PPC64_ADDR14;
1265 break;
1266 case BFD_RELOC_PPC_BA16_BRTAKEN: ppc_reloc = R_PPC64_ADDR14_BRTAKEN;
1267 break;
1268 case BFD_RELOC_PPC_BA16_BRNTAKEN: ppc_reloc = R_PPC64_ADDR14_BRNTAKEN;
1269 break;
1270 case BFD_RELOC_PPC_B26: ppc_reloc = R_PPC64_REL24;
1271 break;
1272 case BFD_RELOC_PPC_B16: ppc_reloc = R_PPC64_REL14;
1273 break;
1274 case BFD_RELOC_PPC_B16_BRTAKEN: ppc_reloc = R_PPC64_REL14_BRTAKEN;
1275 break;
1276 case BFD_RELOC_PPC_B16_BRNTAKEN: ppc_reloc = R_PPC64_REL14_BRNTAKEN;
1277 break;
1278 case BFD_RELOC_16_GOTOFF: ppc_reloc = R_PPC64_GOT16;
1279 break;
1280 case BFD_RELOC_LO16_GOTOFF: ppc_reloc = R_PPC64_GOT16_LO;
1281 break;
1282 case BFD_RELOC_HI16_GOTOFF: ppc_reloc = R_PPC64_GOT16_HI;
1283 break;
1284 case BFD_RELOC_HI16_S_GOTOFF: ppc_reloc = R_PPC64_GOT16_HA;
1285 break;
1286 case BFD_RELOC_PPC_COPY: ppc_reloc = R_PPC64_COPY;
1287 break;
1288 case BFD_RELOC_PPC_GLOB_DAT: ppc_reloc = R_PPC64_GLOB_DAT;
1289 break;
1290 case BFD_RELOC_32_PCREL: ppc_reloc = R_PPC64_REL32;
1291 break;
1292 case BFD_RELOC_32_PLTOFF: ppc_reloc = R_PPC64_PLT32;
1293 break;
1294 case BFD_RELOC_32_PLT_PCREL: ppc_reloc = R_PPC64_PLTREL32;
1295 break;
1296 case BFD_RELOC_LO16_PLTOFF: ppc_reloc = R_PPC64_PLT16_LO;
1297 break;
1298 case BFD_RELOC_HI16_PLTOFF: ppc_reloc = R_PPC64_PLT16_HI;
1299 break;
1300 case BFD_RELOC_HI16_S_PLTOFF: ppc_reloc = R_PPC64_PLT16_HA;
1301 break;
1302 case BFD_RELOC_32_BASEREL: ppc_reloc = R_PPC64_SECTOFF;
1303 break;
1304 case BFD_RELOC_LO16_BASEREL: ppc_reloc = R_PPC64_SECTOFF_LO;
1305 break;
1306 case BFD_RELOC_HI16_BASEREL: ppc_reloc = R_PPC64_SECTOFF_HI;
1307 break;
1308 case BFD_RELOC_HI16_S_BASEREL: ppc_reloc = R_PPC64_SECTOFF_HA;
1309 break;
1310 /* FIXME: Is CTOR 32 or 64 bits? Fix md_apply_fix3 in
1311 gas/config/tc-ppc.c too. */
1312 case BFD_RELOC_CTOR: ppc_reloc = R_PPC64_ADDR32;
1313 break;
1314 case BFD_RELOC_64: ppc_reloc = R_PPC64_ADDR64;
1315 break;
1316 case BFD_RELOC_PPC64_HIGHER: ppc_reloc = R_PPC64_ADDR16_HIGHER;
1317 break;
1318 case BFD_RELOC_PPC64_HIGHER_S: ppc_reloc = R_PPC64_ADDR16_HIGHERA;
1319 break;
1320 case BFD_RELOC_PPC64_HIGHEST: ppc_reloc = R_PPC64_ADDR16_HIGHEST;
1321 break;
1322 case BFD_RELOC_PPC64_HIGHEST_S: ppc_reloc = R_PPC64_ADDR16_HIGHESTA;
1323 break;
1324 case BFD_RELOC_64_PCREL: ppc_reloc = R_PPC64_REL64;
1325 break;
1326 case BFD_RELOC_64_PLTOFF: ppc_reloc = R_PPC64_PLT64;
1327 break;
1328 case BFD_RELOC_64_PLT_PCREL: ppc_reloc = R_PPC64_PLTREL64;
1329 break;
1330 case BFD_RELOC_PPC_TOC16: ppc_reloc = R_PPC64_TOC16;
1331 break;
1332 case BFD_RELOC_PPC64_TOC16_LO: ppc_reloc = R_PPC64_TOC16_LO;
1333 break;
1334 case BFD_RELOC_PPC64_TOC16_HI: ppc_reloc = R_PPC64_TOC16_HI;
1335 break;
1336 case BFD_RELOC_PPC64_TOC16_HA: ppc_reloc = R_PPC64_TOC16_HA;
1337 break;
1338 case BFD_RELOC_PPC64_TOC: ppc_reloc = R_PPC64_TOC;
1339 break;
1340 case BFD_RELOC_PPC64_PLTGOT16: ppc_reloc = R_PPC64_PLTGOT16;
1341 break;
1342 case BFD_RELOC_PPC64_PLTGOT16_LO: ppc_reloc = R_PPC64_PLTGOT16_LO;
1343 break;
1344 case BFD_RELOC_PPC64_PLTGOT16_HI: ppc_reloc = R_PPC64_PLTGOT16_HI;
1345 break;
1346 case BFD_RELOC_PPC64_PLTGOT16_HA: ppc_reloc = R_PPC64_PLTGOT16_HA;
1347 break;
1348 case BFD_RELOC_PPC64_ADDR16_DS: ppc_reloc = R_PPC64_ADDR16_DS;
1349 break;
1350 case BFD_RELOC_PPC64_ADDR16_LO_DS: ppc_reloc = R_PPC64_ADDR16_LO_DS;
1351 break;
1352 case BFD_RELOC_PPC64_GOT16_DS: ppc_reloc = R_PPC64_GOT16_DS;
1353 break;
1354 case BFD_RELOC_PPC64_GOT16_LO_DS: ppc_reloc = R_PPC64_GOT16_LO_DS;
1355 break;
1356 case BFD_RELOC_PPC64_PLT16_LO_DS: ppc_reloc = R_PPC64_PLT16_LO_DS;
1357 break;
1358 case BFD_RELOC_PPC64_SECTOFF_DS: ppc_reloc = R_PPC64_SECTOFF_DS;
1359 break;
1360 case BFD_RELOC_PPC64_SECTOFF_LO_DS: ppc_reloc = R_PPC64_SECTOFF_LO_DS;
1361 break;
1362 case BFD_RELOC_PPC64_TOC16_DS: ppc_reloc = R_PPC64_TOC16_DS;
1363 break;
1364 case BFD_RELOC_PPC64_TOC16_LO_DS: ppc_reloc = R_PPC64_TOC16_LO_DS;
1365 break;
1366 case BFD_RELOC_PPC64_PLTGOT16_DS: ppc_reloc = R_PPC64_PLTGOT16_DS;
1367 break;
1368 case BFD_RELOC_PPC64_PLTGOT16_LO_DS: ppc_reloc = R_PPC64_PLTGOT16_LO_DS;
1369 break;
1370 case BFD_RELOC_VTABLE_INHERIT: ppc_reloc = R_PPC64_GNU_VTINHERIT;
1371 break;
1372 case BFD_RELOC_VTABLE_ENTRY: ppc_reloc = R_PPC64_GNU_VTENTRY;
1373 break;
1374 }
1375
1376 return ppc64_elf_howto_table[(int) ppc_reloc];
1377 };
1378
1379 /* Set the howto pointer for a PowerPC ELF reloc. */
1380
1381 static void
1382 ppc64_elf_info_to_howto (abfd, cache_ptr, dst)
1383 bfd *abfd ATTRIBUTE_UNUSED;
1384 arelent *cache_ptr;
1385 Elf64_Internal_Rela *dst;
1386 {
1387 unsigned int type;
1388
1389 if (!ppc64_elf_howto_table[R_PPC64_ADDR32])
1390 /* Initialize howto table if needed. */
1391 ppc_howto_init ();
1392
1393 type = ELF64_R_TYPE (dst->r_info);
1394 BFD_ASSERT (type < (sizeof (ppc64_elf_howto_table)
1395 / sizeof (ppc64_elf_howto_table[0])));
1396 cache_ptr->howto = ppc64_elf_howto_table[type];
1397 }
1398
1399 /* Handle the R_PPC_ADDR16_HA and similar relocs. */
1400
1401 static bfd_reloc_status_type
1402 ppc64_elf_addr16_ha_reloc (abfd, reloc_entry, symbol, data, input_section,
1403 output_bfd, error_message)
1404 bfd *abfd ATTRIBUTE_UNUSED;
1405 arelent *reloc_entry;
1406 asymbol *symbol;
1407 PTR data ATTRIBUTE_UNUSED;
1408 asection *input_section;
1409 bfd *output_bfd;
1410 char **error_message ATTRIBUTE_UNUSED;
1411 {
1412 bfd_vma relocation;
1413
1414 if (output_bfd != NULL)
1415 {
1416 reloc_entry->address += input_section->output_offset;
1417 return bfd_reloc_ok;
1418 }
1419
1420 if (reloc_entry->address > input_section->_cooked_size)
1421 return bfd_reloc_outofrange;
1422
1423 if (bfd_is_com_section (symbol->section))
1424 relocation = 0;
1425 else
1426 relocation = symbol->value;
1427
1428 relocation += symbol->section->output_section->vma;
1429 relocation += symbol->section->output_offset;
1430 relocation += reloc_entry->addend;
1431
1432 reloc_entry->addend += (relocation & 0x8000) << 1;
1433
1434 return bfd_reloc_continue;
1435 }
1436
1437 /* Function to set whether a module needs the -mrelocatable bit set. */
1438
1439 static boolean
1440 ppc64_elf_set_private_flags (abfd, flags)
1441 bfd *abfd;
1442 flagword flags;
1443 {
1444 BFD_ASSERT (!elf_flags_init (abfd)
1445 || elf_elfheader (abfd)->e_flags == flags);
1446
1447 elf_elfheader (abfd)->e_flags = flags;
1448 elf_flags_init (abfd) = true;
1449 return true;
1450 }
1451
1452 /* Merge backend specific data from an object file to the output
1453 object file when linking. */
1454 static boolean
1455 ppc64_elf_merge_private_bfd_data (ibfd, obfd)
1456 bfd *ibfd;
1457 bfd *obfd;
1458 {
1459 flagword old_flags;
1460 flagword new_flags;
1461 boolean error;
1462
1463 /* Check if we have the same endianess. */
1464 if (ibfd->xvec->byteorder != obfd->xvec->byteorder
1465 && obfd->xvec->byteorder != BFD_ENDIAN_UNKNOWN)
1466 {
1467 const char *msg;
1468
1469 if (bfd_big_endian (ibfd))
1470 msg = _("%s: compiled for a big endian system and target is little endian");
1471 else
1472 msg = _("%s: compiled for a little endian system and target is big endian");
1473
1474 (*_bfd_error_handler) (msg, bfd_archive_filename (ibfd));
1475
1476 bfd_set_error (bfd_error_wrong_format);
1477 return false;
1478 }
1479
1480 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
1481 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
1482 return true;
1483
1484 new_flags = elf_elfheader (ibfd)->e_flags;
1485 old_flags = elf_elfheader (obfd)->e_flags;
1486 if (!elf_flags_init (obfd))
1487 {
1488 /* First call, no flags set. */
1489 elf_flags_init (obfd) = true;
1490 elf_elfheader (obfd)->e_flags = new_flags;
1491 }
1492
1493 else if (new_flags == old_flags)
1494 /* Compatible flags are ok. */
1495 ;
1496
1497 else
1498 {
1499 /* Incompatible flags. Warn about -mrelocatable mismatch.
1500 Allow -mrelocatable-lib to be linked with either. */
1501 error = false;
1502 if ((new_flags & EF_PPC_RELOCATABLE) != 0
1503 && (old_flags & (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB)) == 0)
1504 {
1505 error = true;
1506 (*_bfd_error_handler)
1507 (_("%s: compiled with -mrelocatable and linked with modules compiled normally"),
1508 bfd_archive_filename (ibfd));
1509 }
1510 else if ((new_flags & (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB)) == 0
1511 && (old_flags & EF_PPC_RELOCATABLE) != 0)
1512 {
1513 error = true;
1514 (*_bfd_error_handler)
1515 (_("%s: compiled normally and linked with modules compiled with -mrelocatable"),
1516 bfd_archive_filename (ibfd));
1517 }
1518
1519 /* The output is -mrelocatable-lib iff both the input files are. */
1520 if (! (new_flags & EF_PPC_RELOCATABLE_LIB))
1521 elf_elfheader (obfd)->e_flags &= ~EF_PPC_RELOCATABLE_LIB;
1522
1523 /* The output is -mrelocatable iff it can't be -mrelocatable-lib,
1524 but each input file is either -mrelocatable or -mrelocatable-lib. */
1525 if (! (elf_elfheader (obfd)->e_flags & EF_PPC_RELOCATABLE_LIB)
1526 && (new_flags & (EF_PPC_RELOCATABLE_LIB | EF_PPC_RELOCATABLE))
1527 && (old_flags & (EF_PPC_RELOCATABLE_LIB | EF_PPC_RELOCATABLE)))
1528 elf_elfheader (obfd)->e_flags |= EF_PPC_RELOCATABLE;
1529
1530 /* Do not warn about eabi vs. V.4 mismatch, just or in the bit
1531 if any module uses it. */
1532 elf_elfheader (obfd)->e_flags |= (new_flags & EF_PPC_EMB);
1533
1534 new_flags &= ~(EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB | EF_PPC_EMB);
1535 old_flags &= ~(EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB | EF_PPC_EMB);
1536
1537 /* Warn about any other mismatches. */
1538 if (new_flags != old_flags)
1539 {
1540 error = true;
1541 (*_bfd_error_handler)
1542 (_("%s: uses different e_flags (0x%lx) fields than previous modules (0x%lx)"),
1543 bfd_archive_filename (ibfd), (long) new_flags, (long) old_flags);
1544 }
1545
1546 if (error)
1547 {
1548 bfd_set_error (bfd_error_bad_value);
1549 return false;
1550 }
1551 }
1552
1553 return true;
1554 }
1555
1556 /* Handle a PowerPC specific section when reading an object file. This
1557 is called when elfcode.h finds a section with an unknown type. */
1558
1559 static boolean
1560 ppc64_elf_section_from_shdr (abfd, hdr, name)
1561 bfd *abfd;
1562 Elf64_Internal_Shdr *hdr;
1563 char *name;
1564 {
1565 asection *newsect;
1566 flagword flags;
1567
1568 if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name))
1569 return false;
1570
1571 newsect = hdr->bfd_section;
1572 flags = bfd_get_section_flags (abfd, newsect);
1573 if (hdr->sh_flags & SHF_EXCLUDE)
1574 flags |= SEC_EXCLUDE;
1575
1576 if (hdr->sh_type == SHT_ORDERED)
1577 flags |= SEC_SORT_ENTRIES;
1578
1579 bfd_set_section_flags (abfd, newsect, flags);
1580 return true;
1581 }
1582 \f
1583 /* The following functions are specific to the ELF linker, while
1584 functions above are used generally. Those named ppc64_elf_* are
1585 called by the main ELF linker code. They appear in this file more
1586 or less in the order in which they are called. eg.
1587 ppc64_elf_check_relocs is called early in the link process,
1588 ppc64_elf_finish_dynamic_sections is one of the last functions
1589 called. */
1590
1591 /* The linker needs to keep track of the number of relocs that it
1592 decides to copy as dynamic relocs in check_relocs for each symbol.
1593 This is so that it can later discard them if they are found to be
1594 unnecessary. We store the information in a field extending the
1595 regular ELF linker hash table. */
1596
1597 struct ppc_dyn_relocs
1598 {
1599 struct ppc_dyn_relocs *next;
1600
1601 /* The input section of the reloc. */
1602 asection *sec;
1603
1604 /* Total number of relocs copied for the input section. */
1605 bfd_size_type count;
1606
1607 /* Number of pc-relative relocs copied for the input section. */
1608 bfd_size_type pc_count;
1609 };
1610
1611 /* Of those relocs that might be copied as dynamic relocs, this macro
1612 selects between relative and absolute types. */
1613
1614 #define IS_ABSOLUTE_RELOC(RTYPE) \
1615 ((RTYPE) != R_PPC64_REL14 \
1616 && (RTYPE) != R_PPC64_REL14_BRNTAKEN \
1617 && (RTYPE) != R_PPC64_REL14_BRTAKEN \
1618 && (RTYPE) != R_PPC64_REL24 \
1619 && (RTYPE) != R_PPC64_REL32 \
1620 && (RTYPE) != R_PPC64_REL64)
1621
1622 /* ppc64 ELF linker hash entry. */
1623
1624 struct ppc_link_hash_entry
1625 {
1626 struct elf_link_hash_entry elf;
1627
1628 /* Track dynamic relocs copied for this symbol. */
1629 struct ppc_dyn_relocs *dyn_relocs;
1630 };
1631
1632 /* ppc64 ELF linker hash table. */
1633
1634 struct ppc_link_hash_table
1635 {
1636 struct elf_link_hash_table elf;
1637
1638 /* Short-cuts to get to dynamic linker sections. */
1639 asection *sgot;
1640 asection *srelgot;
1641 asection *splt;
1642 asection *srelplt;
1643 asection *sdynbss;
1644 asection *srelbss;
1645 asection *sstub;
1646 asection *sglink;
1647
1648 /* Set on error. */
1649 int plt_overflow;
1650
1651 /* Small local sym to section mapping cache. */
1652 struct sym_sec_cache sym_sec;
1653 };
1654
1655 /* Get the ppc64 ELF linker hash table from a link_info structure. */
1656
1657 #define ppc_hash_table(p) \
1658 ((struct ppc_link_hash_table *) ((p)->hash))
1659
1660 /* Create an entry in a ppc64 ELF linker hash table. */
1661
1662 static struct bfd_hash_entry *
1663 link_hash_newfunc (entry, table, string)
1664 struct bfd_hash_entry *entry;
1665 struct bfd_hash_table *table;
1666 const char *string;
1667 {
1668 /* Allocate the structure if it has not already been allocated by a
1669 subclass. */
1670 if (entry == NULL)
1671 {
1672 entry = bfd_hash_allocate (table, sizeof (struct ppc_link_hash_entry));
1673 if (entry == NULL)
1674 return entry;
1675 }
1676
1677 /* Call the allocation method of the superclass. */
1678 entry = _bfd_elf_link_hash_newfunc (entry, table, string);
1679 if (entry != NULL)
1680 {
1681 struct ppc_link_hash_entry *eh = (struct ppc_link_hash_entry *) entry;
1682
1683 eh->dyn_relocs = NULL;
1684 }
1685
1686 return entry;
1687 }
1688
1689 /* Create a ppc64 ELF linker hash table. */
1690
1691 static struct bfd_link_hash_table *
1692 ppc64_elf_link_hash_table_create (abfd)
1693 bfd *abfd;
1694 {
1695 struct ppc_link_hash_table *htab;
1696 bfd_size_type amt = sizeof (struct ppc_link_hash_table);
1697
1698 htab = (struct ppc_link_hash_table *) bfd_alloc (abfd, amt);
1699 if (htab == NULL)
1700 return NULL;
1701
1702 if (! _bfd_elf_link_hash_table_init (&htab->elf, abfd, link_hash_newfunc))
1703 {
1704 bfd_release (abfd, htab);
1705 return NULL;
1706 }
1707
1708 htab->sgot = NULL;
1709 htab->srelgot = NULL;
1710 htab->splt = NULL;
1711 htab->srelplt = NULL;
1712 htab->sdynbss = NULL;
1713 htab->srelbss = NULL;
1714 htab->sstub = NULL;
1715 htab->sglink = NULL;
1716 htab->plt_overflow = 0;
1717 htab->sym_sec.abfd = NULL;
1718
1719 return &htab->elf.root;
1720 }
1721
1722 /* Create .got and .rela.got sections in DYNOBJ, and set up
1723 shortcuts to them in our hash table. */
1724
1725 static boolean
1726 create_got_section (dynobj, info)
1727 bfd *dynobj;
1728 struct bfd_link_info *info;
1729 {
1730 struct ppc_link_hash_table *htab;
1731
1732 if (! _bfd_elf_create_got_section (dynobj, info))
1733 return false;
1734
1735 htab = ppc_hash_table (info);
1736 htab->sgot = bfd_get_section_by_name (dynobj, ".got");
1737 if (!htab->sgot)
1738 abort ();
1739
1740 htab->srelgot = bfd_make_section (dynobj, ".rela.got");
1741 if (!htab->srelgot
1742 || ! bfd_set_section_flags (dynobj, htab->srelgot,
1743 (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS
1744 | SEC_IN_MEMORY | SEC_LINKER_CREATED
1745 | SEC_READONLY))
1746 || ! bfd_set_section_alignment (dynobj, htab->srelgot, 3))
1747 return false;
1748 return true;
1749 }
1750
1751 /* Create the .stub and .glink sections as well as the ordinary
1752 dynamic sections. */
1753
1754 static boolean
1755 ppc64_elf_create_dynamic_sections (dynobj, info)
1756 bfd *dynobj;
1757 struct bfd_link_info *info;
1758 {
1759 struct ppc_link_hash_table *htab;
1760 flagword flags;
1761
1762 htab = ppc_hash_table (info);
1763 if (!htab->sgot && !create_got_section (dynobj, info))
1764 return false;
1765
1766 if (!_bfd_elf_create_dynamic_sections (dynobj, info))
1767 return false;
1768
1769 htab->splt = bfd_get_section_by_name (dynobj, ".plt");
1770 htab->srelplt = bfd_get_section_by_name (dynobj, ".rela.plt");
1771 htab->sdynbss = bfd_get_section_by_name (dynobj, ".dynbss");
1772 if (!info->shared)
1773 htab->srelbss = bfd_get_section_by_name (dynobj, ".rela.bss");
1774
1775 if (!htab->splt || !htab->srelplt || !htab->sdynbss
1776 || (!info->shared && !htab->srelbss))
1777 abort ();
1778
1779 /* Create .stub and .glink for global linkage functions. */
1780 flags = (SEC_ALLOC | SEC_LOAD | SEC_CODE | SEC_READONLY
1781 | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED);
1782 htab->sstub = bfd_make_section (dynobj, ".stub");
1783 if (htab->sstub == NULL
1784 || ! bfd_set_section_flags (dynobj, htab->sstub, flags)
1785 || ! bfd_set_section_alignment (dynobj, htab->sstub, 2))
1786 return false;
1787 htab->sglink = bfd_make_section (dynobj, ".glink");
1788 if (htab->sglink == NULL
1789 || ! bfd_set_section_flags (dynobj, htab->sglink, flags)
1790 || ! bfd_set_section_alignment (dynobj, htab->sglink, 3))
1791 return false;
1792
1793 return true;
1794 }
1795
1796 /* Copy the extra info we tack onto an elf_link_hash_entry. */
1797
1798 static void
1799 ppc64_elf_copy_indirect_symbol (dir, ind)
1800 struct elf_link_hash_entry *dir, *ind;
1801 {
1802 struct ppc_link_hash_entry *edir, *eind;
1803
1804 edir = (struct ppc_link_hash_entry *) dir;
1805 eind = (struct ppc_link_hash_entry *) ind;
1806
1807 if (eind->dyn_relocs != NULL)
1808 {
1809 if (edir->dyn_relocs != NULL)
1810 {
1811 struct ppc_dyn_relocs **pp;
1812 struct ppc_dyn_relocs *p;
1813
1814 if (ind->root.type == bfd_link_hash_indirect)
1815 abort ();
1816
1817 /* Add reloc counts against the weak sym to the strong sym
1818 list. Merge any entries against the same section. */
1819 for (pp = &eind->dyn_relocs; (p = *pp) != NULL; )
1820 {
1821 struct ppc_dyn_relocs *q;
1822
1823 for (q = edir->dyn_relocs; q != NULL; q = q->next)
1824 if (q->sec == p->sec)
1825 {
1826 q->pc_count += p->pc_count;
1827 q->count += p->count;
1828 *pp = p->next;
1829 break;
1830 }
1831 if (q == NULL)
1832 pp = &p->next;
1833 }
1834 *pp = edir->dyn_relocs;
1835 }
1836
1837 edir->dyn_relocs = eind->dyn_relocs;
1838 eind->dyn_relocs = NULL;
1839 }
1840
1841 _bfd_elf_link_hash_copy_indirect (dir, ind);
1842 }
1843
1844 /* Look through the relocs for a section during the first phase, and
1845 calculate needed space in the global offset table, procedure
1846 linkage table, and dynamic reloc sections. */
1847
1848 static boolean
1849 ppc64_elf_check_relocs (abfd, info, sec, relocs)
1850 bfd *abfd;
1851 struct bfd_link_info *info;
1852 asection *sec;
1853 const Elf_Internal_Rela *relocs;
1854 {
1855 struct ppc_link_hash_table *htab;
1856 Elf_Internal_Shdr *symtab_hdr;
1857 struct elf_link_hash_entry **sym_hashes, **sym_hashes_end;
1858 const Elf_Internal_Rela *rel;
1859 const Elf_Internal_Rela *rel_end;
1860 asection *sreloc;
1861
1862 if (info->relocateable)
1863 return true;
1864
1865 htab = ppc_hash_table (info);
1866 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
1867
1868 sym_hashes = elf_sym_hashes (abfd);
1869 sym_hashes_end = (sym_hashes
1870 + symtab_hdr->sh_size / sizeof (Elf64_External_Sym));
1871 if (!elf_bad_symtab (abfd))
1872 sym_hashes_end -= symtab_hdr->sh_info;
1873
1874 sreloc = NULL;
1875
1876 rel_end = relocs + sec->reloc_count;
1877 for (rel = relocs; rel < rel_end; rel++)
1878 {
1879 unsigned long r_symndx;
1880 struct elf_link_hash_entry *h;
1881 enum elf_ppc_reloc_type r_type;
1882
1883 r_symndx = ELF64_R_SYM (rel->r_info);
1884 if (r_symndx < symtab_hdr->sh_info)
1885 h = NULL;
1886 else
1887 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
1888
1889 r_type = (enum elf_ppc_reloc_type) ELF64_R_TYPE (rel->r_info);
1890 switch (r_type)
1891 {
1892 /* GOT16 relocations */
1893 case R_PPC64_GOT16:
1894 case R_PPC64_GOT16_DS:
1895 case R_PPC64_GOT16_HA:
1896 case R_PPC64_GOT16_HI:
1897 case R_PPC64_GOT16_LO:
1898 case R_PPC64_GOT16_LO_DS:
1899
1900 /* This symbol requires a global offset table entry. */
1901 if (htab->sgot == NULL)
1902 {
1903 if (htab->elf.dynobj == NULL)
1904 htab->elf.dynobj = abfd;
1905 if (!create_got_section (htab->elf.dynobj, info))
1906 return false;
1907 }
1908
1909 if (h != NULL)
1910 {
1911 h->got.refcount += 1;
1912 }
1913 else
1914 {
1915 bfd_signed_vma *local_got_refcounts;
1916
1917 /* This is a global offset table entry for a local symbol. */
1918 local_got_refcounts = elf_local_got_refcounts (abfd);
1919 if (local_got_refcounts == NULL)
1920 {
1921 bfd_size_type size;
1922
1923 size = symtab_hdr->sh_info;
1924 size *= sizeof (bfd_signed_vma);
1925 local_got_refcounts = ((bfd_signed_vma *)
1926 bfd_zalloc (abfd, size));
1927 if (local_got_refcounts == NULL)
1928 return false;
1929 elf_local_got_refcounts (abfd) = local_got_refcounts;
1930 }
1931 local_got_refcounts[r_symndx] += 1;
1932 }
1933 break;
1934
1935 case R_PPC64_PLT16_HA:
1936 case R_PPC64_PLT16_HI:
1937 case R_PPC64_PLT16_LO:
1938 case R_PPC64_PLT32:
1939 case R_PPC64_PLT64:
1940 /* This symbol requires a procedure linkage table entry. We
1941 actually build the entry in adjust_dynamic_symbol,
1942 because this might be a case of linking PIC code without
1943 linking in any dynamic objects, in which case we don't
1944 need to generate a procedure linkage table after all. */
1945 if (h == NULL)
1946 {
1947 /* It does not make sense to have a procedure linkage
1948 table entry for a local symbol. */
1949 bfd_set_error (bfd_error_bad_value);
1950 return false;
1951 }
1952
1953 h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
1954 h->plt.refcount += 1;
1955 break;
1956
1957 /* The following relocations don't need to propagate the
1958 relocation if linking a shared object since they are
1959 section relative. */
1960 case R_PPC64_SECTOFF:
1961 case R_PPC64_SECTOFF_LO:
1962 case R_PPC64_SECTOFF_HI:
1963 case R_PPC64_SECTOFF_HA:
1964 case R_PPC64_SECTOFF_DS:
1965 case R_PPC64_SECTOFF_LO_DS:
1966 case R_PPC64_TOC16:
1967 case R_PPC64_TOC16_LO:
1968 case R_PPC64_TOC16_HI:
1969 case R_PPC64_TOC16_HA:
1970 case R_PPC64_TOC16_DS:
1971 case R_PPC64_TOC16_LO_DS:
1972 break;
1973
1974 /* This relocation describes the C++ object vtable hierarchy.
1975 Reconstruct it for later use during GC. */
1976 case R_PPC64_GNU_VTINHERIT:
1977 if (!_bfd_elf64_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
1978 return false;
1979 break;
1980
1981 /* This relocation describes which C++ vtable entries are actually
1982 used. Record for later use during GC. */
1983 case R_PPC64_GNU_VTENTRY:
1984 if (!_bfd_elf64_gc_record_vtentry (abfd, sec, h, rel->r_addend))
1985 return false;
1986 break;
1987
1988 case R_PPC64_REL24:
1989 if (h != NULL)
1990 {
1991 /* We may need a .plt entry if the function this reloc
1992 refers to is in a shared lib. */
1993 h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
1994 h->plt.refcount += 1;
1995 }
1996 break;
1997
1998 case R_PPC64_REL64:
1999 case R_PPC64_REL32:
2000 case R_PPC64_REL14:
2001 case R_PPC64_REL14_BRTAKEN:
2002 case R_PPC64_REL14_BRNTAKEN:
2003 case R_PPC64_ADDR14:
2004 case R_PPC64_ADDR14_BRNTAKEN:
2005 case R_PPC64_ADDR14_BRTAKEN:
2006 case R_PPC64_ADDR16:
2007 case R_PPC64_ADDR16_DS:
2008 case R_PPC64_ADDR16_HA:
2009 case R_PPC64_ADDR16_HI:
2010 case R_PPC64_ADDR16_HIGHER:
2011 case R_PPC64_ADDR16_HIGHERA:
2012 case R_PPC64_ADDR16_HIGHEST:
2013 case R_PPC64_ADDR16_HIGHESTA:
2014 case R_PPC64_ADDR16_LO:
2015 case R_PPC64_ADDR16_LO_DS:
2016 case R_PPC64_ADDR24:
2017 case R_PPC64_ADDR30:
2018 case R_PPC64_ADDR32:
2019 case R_PPC64_ADDR64:
2020 case R_PPC64_UADDR16:
2021 case R_PPC64_UADDR32:
2022 case R_PPC64_UADDR64:
2023 case R_PPC64_TOC:
2024 /* If we are creating a shared library, and this is a reloc
2025 against a global symbol, or a non PC relative reloc
2026 against a local symbol, then we need to copy the reloc
2027 into the shared library. However, if we are linking with
2028 -Bsymbolic, we do not need to copy a reloc against a
2029 global symbol which is defined in an object we are
2030 including in the link (i.e., DEF_REGULAR is set). At
2031 this point we have not seen all the input files, so it is
2032 possible that DEF_REGULAR is not set now but will be set
2033 later (it is never cleared). In case of a weak definition,
2034 DEF_REGULAR may be cleared later by a strong definition in
2035 a shared library. We account for that possibility below by
2036 storing information in the relocs_copied field of the hash
2037 table entry. A similar situation occurs when creating
2038 shared libraries and symbol visibility changes render the
2039 symbol local.
2040
2041 If on the other hand, we are creating an executable, we
2042 may need to keep relocations for symbols satisfied by a
2043 dynamic library if we manage to avoid copy relocs for the
2044 symbol. */
2045 if ((info->shared
2046 && (sec->flags & SEC_ALLOC) != 0
2047 && (IS_ABSOLUTE_RELOC (r_type)
2048 || (h != NULL
2049 && (! info->symbolic
2050 || h->root.type == bfd_link_hash_defweak
2051 || (h->elf_link_hash_flags
2052 & ELF_LINK_HASH_DEF_REGULAR) == 0))))
2053 || (!info->shared
2054 && (sec->flags & SEC_ALLOC) != 0
2055 && h != NULL
2056 && (h->root.type == bfd_link_hash_defweak
2057 || (h->elf_link_hash_flags
2058 & ELF_LINK_HASH_DEF_REGULAR) == 0)))
2059 {
2060 struct ppc_dyn_relocs *p;
2061 struct ppc_dyn_relocs **head;
2062
2063 #if 0
2064 /* Don't propagate .opd relocs. */
2065 if (strcmp (bfd_get_section_name (abfd, sec), ".opd") == 0)
2066 break;
2067 #endif
2068
2069 /* We must copy these reloc types into the output file.
2070 Create a reloc section in dynobj and make room for
2071 this reloc. */
2072 if (sreloc == NULL)
2073 {
2074 const char *name;
2075 bfd *dynobj;
2076
2077 name = (bfd_elf_string_from_elf_section
2078 (abfd,
2079 elf_elfheader (abfd)->e_shstrndx,
2080 elf_section_data (sec)->rel_hdr.sh_name));
2081 if (name == NULL)
2082 return false;
2083
2084 if (strncmp (name, ".rela", 5) != 0
2085 || strcmp (bfd_get_section_name (abfd, sec),
2086 name + 5) != 0)
2087 {
2088 (*_bfd_error_handler)
2089 (_("%s: bad relocation section name `%s\'"),
2090 bfd_archive_filename (abfd), name);
2091 bfd_set_error (bfd_error_bad_value);
2092 }
2093
2094 if (htab->elf.dynobj == NULL)
2095 htab->elf.dynobj = abfd;
2096
2097 dynobj = htab->elf.dynobj;
2098 sreloc = bfd_get_section_by_name (dynobj, name);
2099 if (sreloc == NULL)
2100 {
2101 flagword flags;
2102
2103 sreloc = bfd_make_section (dynobj, name);
2104 flags = (SEC_HAS_CONTENTS | SEC_READONLY
2105 | SEC_IN_MEMORY | SEC_LINKER_CREATED);
2106 if ((sec->flags & SEC_ALLOC) != 0)
2107 flags |= SEC_ALLOC | SEC_LOAD;
2108 if (sreloc == NULL
2109 || ! bfd_set_section_flags (dynobj, sreloc, flags)
2110 || ! bfd_set_section_alignment (dynobj, sreloc, 3))
2111 return false;
2112 }
2113 elf_section_data (sec)->sreloc = sreloc;
2114 }
2115
2116 /* If this is a global symbol, we count the number of
2117 relocations we need for this symbol. */
2118 if (h != NULL)
2119 {
2120 head = &((struct ppc_link_hash_entry *) h)->dyn_relocs;
2121 }
2122 else
2123 {
2124 /* Track dynamic relocs needed for local syms too.
2125 We really need local syms available to do this
2126 easily. Oh well. */
2127
2128 asection *s;
2129 s = bfd_section_from_r_symndx (abfd, &htab->sym_sec,
2130 sec, r_symndx);
2131 if (s == NULL)
2132 return false;
2133
2134 head = ((struct ppc_dyn_relocs **)
2135 &elf_section_data (s)->local_dynrel);
2136 }
2137
2138 p = *head;
2139 if (p == NULL || p->sec != sec)
2140 {
2141 p = ((struct ppc_dyn_relocs *)
2142 bfd_alloc (htab->elf.dynobj,
2143 (bfd_size_type) sizeof *p));
2144 if (p == NULL)
2145 return false;
2146 p->next = *head;
2147 *head = p;
2148 p->sec = sec;
2149 p->count = 0;
2150 p->pc_count = 0;
2151 }
2152
2153 p->count += 1;
2154 if (!IS_ABSOLUTE_RELOC (r_type))
2155 p->pc_count += 1;
2156 }
2157 break;
2158
2159 default:
2160 }
2161 }
2162
2163 return true;
2164 }
2165
2166 /* Return the section that should be marked against GC for a given
2167 relocation. */
2168
2169 static asection *
2170 ppc64_elf_gc_mark_hook (abfd, info, rel, h, sym)
2171 bfd *abfd;
2172 struct bfd_link_info *info ATTRIBUTE_UNUSED;
2173 Elf_Internal_Rela *rel;
2174 struct elf_link_hash_entry *h;
2175 Elf_Internal_Sym *sym;
2176 {
2177 if (h != NULL)
2178 {
2179 enum elf_ppc_reloc_type r_type;
2180
2181 r_type = (enum elf_ppc_reloc_type) ELF64_R_TYPE (rel->r_info);
2182 switch (r_type)
2183 {
2184 case R_PPC64_GNU_VTINHERIT:
2185 case R_PPC64_GNU_VTENTRY:
2186 break;
2187
2188 default:
2189 switch (h->root.type)
2190 {
2191 case bfd_link_hash_defined:
2192 case bfd_link_hash_defweak:
2193 return h->root.u.def.section;
2194
2195 case bfd_link_hash_common:
2196 return h->root.u.c.p->section;
2197
2198 default:
2199 break;
2200 }
2201 }
2202 }
2203 else
2204 {
2205 return bfd_section_from_elf_index (abfd, sym->st_shndx);
2206 }
2207
2208 return NULL;
2209 }
2210
2211 /* Update the .got, .plt. and dynamic reloc reference counts for the
2212 section being removed. */
2213
2214 static boolean
2215 ppc64_elf_gc_sweep_hook (abfd, info, sec, relocs)
2216 bfd *abfd;
2217 struct bfd_link_info *info ATTRIBUTE_UNUSED;
2218 asection *sec;
2219 const Elf_Internal_Rela *relocs;
2220 {
2221 Elf_Internal_Shdr *symtab_hdr;
2222 struct elf_link_hash_entry **sym_hashes;
2223 bfd_signed_vma *local_got_refcounts;
2224 const Elf_Internal_Rela *rel, *relend;
2225
2226 elf_section_data (sec)->local_dynrel = NULL;
2227
2228 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
2229 sym_hashes = elf_sym_hashes (abfd);
2230 local_got_refcounts = elf_local_got_refcounts (abfd);
2231
2232 relend = relocs + sec->reloc_count;
2233 for (rel = relocs; rel < relend; rel++)
2234 {
2235 unsigned long r_symndx;
2236 enum elf_ppc_reloc_type r_type;
2237 struct elf_link_hash_entry *h;
2238
2239 r_symndx = ELF64_R_SYM (rel->r_info);
2240 r_type = (enum elf_ppc_reloc_type) ELF64_R_TYPE (rel->r_info);
2241 switch (r_type)
2242 {
2243 case R_PPC64_GOT16:
2244 case R_PPC64_GOT16_DS:
2245 case R_PPC64_GOT16_HA:
2246 case R_PPC64_GOT16_HI:
2247 case R_PPC64_GOT16_LO:
2248 case R_PPC64_GOT16_LO_DS:
2249 if (r_symndx >= symtab_hdr->sh_info)
2250 {
2251 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
2252 if (h->got.refcount > 0)
2253 h->got.refcount--;
2254 }
2255 else
2256 {
2257 if (local_got_refcounts[r_symndx] > 0)
2258 local_got_refcounts[r_symndx]--;
2259 }
2260 break;
2261
2262 case R_PPC64_PLT16_HA:
2263 case R_PPC64_PLT16_HI:
2264 case R_PPC64_PLT16_LO:
2265 case R_PPC64_PLT32:
2266 case R_PPC64_PLT64:
2267 if (r_symndx >= symtab_hdr->sh_info)
2268 {
2269 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
2270 if (h->plt.refcount > 0)
2271 h->plt.refcount--;
2272 }
2273 break;
2274
2275 case R_PPC64_REL24:
2276 if (r_symndx >= symtab_hdr->sh_info)
2277 {
2278 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
2279 if (h->plt.refcount > 0)
2280 h->plt.refcount--;
2281 }
2282 /* Fall thru. */
2283
2284 case R_PPC64_REL14:
2285 case R_PPC64_REL14_BRNTAKEN:
2286 case R_PPC64_REL14_BRTAKEN:
2287 case R_PPC64_REL32:
2288 case R_PPC64_REL64:
2289 if (r_symndx >= symtab_hdr->sh_info)
2290 {
2291 struct ppc_link_hash_entry *eh;
2292 struct ppc_dyn_relocs **pp;
2293 struct ppc_dyn_relocs *p;
2294
2295 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
2296 eh = (struct ppc_link_hash_entry *) h;
2297
2298 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next)
2299 if (p->sec == sec)
2300 {
2301 p->pc_count -= 1;
2302 p->count -= 1;
2303 if (p->count == 0)
2304 *pp = p->next;
2305 break;
2306 }
2307 }
2308 break;
2309
2310 case R_PPC64_ADDR14:
2311 case R_PPC64_ADDR14_BRNTAKEN:
2312 case R_PPC64_ADDR14_BRTAKEN:
2313 case R_PPC64_ADDR16:
2314 case R_PPC64_ADDR16_DS:
2315 case R_PPC64_ADDR16_HA:
2316 case R_PPC64_ADDR16_HI:
2317 case R_PPC64_ADDR16_HIGHER:
2318 case R_PPC64_ADDR16_HIGHERA:
2319 case R_PPC64_ADDR16_HIGHEST:
2320 case R_PPC64_ADDR16_HIGHESTA:
2321 case R_PPC64_ADDR16_LO:
2322 case R_PPC64_ADDR16_LO_DS:
2323 case R_PPC64_ADDR24:
2324 case R_PPC64_ADDR30:
2325 case R_PPC64_ADDR32:
2326 case R_PPC64_ADDR64:
2327 case R_PPC64_UADDR16:
2328 case R_PPC64_UADDR32:
2329 case R_PPC64_UADDR64:
2330 case R_PPC64_TOC:
2331 if (r_symndx >= symtab_hdr->sh_info)
2332 {
2333 struct ppc_link_hash_entry *eh;
2334 struct ppc_dyn_relocs **pp;
2335 struct ppc_dyn_relocs *p;
2336
2337 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
2338 eh = (struct ppc_link_hash_entry *) h;
2339
2340 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next)
2341 if (p->sec == sec)
2342 {
2343 p->count -= 1;
2344 if (p->count == 0)
2345 *pp = p->next;
2346 break;
2347 }
2348 }
2349 break;
2350
2351 default:
2352 break;
2353 }
2354 }
2355 return true;
2356 }
2357
2358 /* Adjust a symbol defined by a dynamic object and referenced by a
2359 regular object. The current definition is in some section of the
2360 dynamic object, but we're not including those sections. We have to
2361 change the definition to something the rest of the link can
2362 understand. */
2363
2364 static boolean
2365 ppc64_elf_adjust_dynamic_symbol (info, h)
2366 struct bfd_link_info *info;
2367 struct elf_link_hash_entry *h;
2368 {
2369 struct ppc_link_hash_table *htab;
2370 struct ppc_link_hash_entry * eh;
2371 struct ppc_dyn_relocs *p;
2372 asection *s;
2373 unsigned int power_of_two;
2374
2375 htab = ppc_hash_table (info);
2376
2377 /* If this is a function, put it in the procedure linkage table. We
2378 will fill in the contents of the procedure linkage table later. */
2379 if (h->type == STT_FUNC
2380 || (h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0)
2381 {
2382 struct elf_link_hash_entry *fdh;
2383
2384 /* If it's a function entry point, the name starts with a dot
2385 unless someone has written some poor assembly code. The ABI
2386 for .plt calls requires that there be a function descriptor
2387 sym which has the name of the function minus the dot. */
2388
2389 if (h->plt.refcount <= 0
2390 || h->root.root.string[0] != '.'
2391 || h->root.root.string[1] == '\0'
2392 || (! info->shared
2393 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) == 0
2394 && (h->elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) == 0))
2395 {
2396 /* This case can occur if we saw a PLT reloc in an input
2397 file, but the symbol was never referred to by a dynamic
2398 object, or if all references were garbage collected. In
2399 such a case, we don't actually need to build a procedure
2400 linkage table entry. */
2401 h->plt.offset = (bfd_vma) -1;
2402 h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
2403 return true;
2404 }
2405
2406 /* Find the corresponding function descriptor symbol. Create it
2407 as undefined if necessary. ppc_elf64_finish_dynamic_symbol
2408 will look it up again and create a JMP_SLOT reloc for it. */
2409
2410 fdh = elf_link_hash_lookup (elf_hash_table (info),
2411 h->root.root.string + 1,
2412 false, false, false);
2413
2414 if (fdh == NULL)
2415 {
2416 asymbol *newsym;
2417
2418 /* Create it as undefined. */
2419 newsym = bfd_make_empty_symbol (htab->elf.dynobj);
2420 newsym->name = h->root.root.string + 1;
2421 newsym->section = bfd_und_section_ptr;
2422 newsym->value = 0;
2423 newsym->flags = BSF_DYNAMIC | BSF_OBJECT;
2424
2425 if ( !(_bfd_generic_link_add_one_symbol
2426 (info, htab->elf.dynobj, newsym->name, newsym->flags,
2427 newsym->section, newsym->value, NULL, false, false,
2428 (struct bfd_link_hash_entry **) &fdh)))
2429 {
2430 return false;
2431 }
2432 }
2433 return true;
2434 }
2435 else
2436 h->plt.offset = (bfd_vma) -1;
2437
2438 /* If this is a weak symbol, and there is a real definition, the
2439 processor independent code will have arranged for us to see the
2440 real definition first, and we can just use the same value. */
2441 if (h->weakdef != NULL)
2442 {
2443 BFD_ASSERT (h->weakdef->root.type == bfd_link_hash_defined
2444 || h->weakdef->root.type == bfd_link_hash_defweak);
2445 h->root.u.def.section = h->weakdef->root.u.def.section;
2446 h->root.u.def.value = h->weakdef->root.u.def.value;
2447 return true;
2448 }
2449
2450 /* This is a reference to a symbol defined by a dynamic object which
2451 is not a function. */
2452
2453 /* If we are creating a shared library, we must presume that the
2454 only references to the symbol are via the global offset table.
2455 For such cases we need not do anything here; the relocations will
2456 be handled correctly by relocate_section. */
2457 if (info->shared)
2458 return true;
2459
2460 /* If there are no references to this symbol that do not use the
2461 GOT, we don't need to generate a copy reloc. */
2462 if ((h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0)
2463 return true;
2464
2465 eh = (struct ppc_link_hash_entry *) h;
2466 for (p = eh->dyn_relocs; p != NULL; p = p->next)
2467 {
2468 s = p->sec->output_section;
2469 if (s != NULL && (s->flags & SEC_READONLY) != 0)
2470 break;
2471 }
2472
2473 /* If we didn't find any dynamic relocs in read-only sections, then
2474 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
2475 if (p == NULL)
2476 {
2477 h->elf_link_hash_flags &= ~ELF_LINK_NON_GOT_REF;
2478 return true;
2479 }
2480
2481 /* We must allocate the symbol in our .dynbss section, which will
2482 become part of the .bss section of the executable. There will be
2483 an entry for this symbol in the .dynsym section. The dynamic
2484 object will contain position independent code, so all references
2485 from the dynamic object to this symbol will go through the global
2486 offset table. The dynamic linker will use the .dynsym entry to
2487 determine the address it must put in the global offset table, so
2488 both the dynamic object and the regular object will refer to the
2489 same memory location for the variable. */
2490
2491 /* We must generate a R_PPC_COPY reloc to tell the dynamic linker to
2492 copy the initial value out of the dynamic object and into the
2493 runtime process image. We need to remember the offset into the
2494 .rela.bss section we are going to use. */
2495 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
2496 {
2497 htab->srelbss->_raw_size += sizeof (Elf64_External_Rela);
2498 h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_COPY;
2499 }
2500
2501 /* We need to figure out the alignment required for this symbol. I
2502 have no idea how ELF linkers handle this. */
2503 power_of_two = bfd_log2 (h->size);
2504 if (power_of_two > 4)
2505 power_of_two = 4;
2506
2507 /* Apply the required alignment. */
2508 s = htab->sdynbss;
2509 s->_raw_size = BFD_ALIGN (s->_raw_size, (bfd_size_type) (1 << power_of_two));
2510 if (power_of_two > bfd_get_section_alignment (htab->elf.dynobj, s))
2511 {
2512 if (! bfd_set_section_alignment (htab->elf.dynobj, s, power_of_two))
2513 return false;
2514 }
2515
2516 /* Define the symbol as being at this point in the section. */
2517 h->root.u.def.section = s;
2518 h->root.u.def.value = s->_raw_size;
2519
2520 /* Increment the section size to make room for the symbol. */
2521 s->_raw_size += h->size;
2522
2523 return true;
2524 }
2525
2526 /* This is the condition under which ppc64_elf_finish_dynamic_symbol
2527 will be called from elflink.h. If elflink.h doesn't call our
2528 finish_dynamic_symbol routine, we'll need to do something about
2529 initializing any .plt and .got entries in ppc64_elf_relocate_section. */
2530 #define WILL_CALL_FINISH_DYNAMIC_SYMBOL(DYN, INFO, H) \
2531 ((DYN) \
2532 && ((INFO)->shared \
2533 || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) \
2534 && ((H)->dynindx != -1 \
2535 || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0))
2536
2537 /* Allocate space in .plt, .got and associated reloc sections for
2538 dynamic relocs. */
2539
2540 static boolean
2541 allocate_dynrelocs (h, inf)
2542 struct elf_link_hash_entry *h;
2543 PTR inf;
2544 {
2545 struct bfd_link_info *info;
2546 struct ppc_link_hash_table *htab;
2547 asection *s;
2548 struct ppc_link_hash_entry *eh;
2549 struct ppc_dyn_relocs *p;
2550
2551 if (h->root.type == bfd_link_hash_indirect
2552 || h->root.type == bfd_link_hash_warning)
2553 return true;
2554
2555 info = (struct bfd_link_info *) inf;
2556 htab = ppc_hash_table (info);
2557
2558 if (htab->elf.dynamic_sections_created
2559 && h->plt.refcount > 0)
2560 {
2561 /* Make sure this symbol is output as a dynamic symbol.
2562 Undefined weak syms won't yet be marked as dynamic. */
2563 if (h->dynindx == -1
2564 && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0)
2565 {
2566 if (! bfd_elf64_link_record_dynamic_symbol (info, h))
2567 return false;
2568 }
2569
2570 BFD_ASSERT (h->root.root.string[0] == '.'
2571 && h->root.root.string[1] != '\0');
2572
2573 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, info, h))
2574 {
2575 /* Make sure the corresponding function descriptor symbol is
2576 dynamic too. */
2577
2578 if (h->dynindx != -1)
2579 {
2580 struct elf_link_hash_entry *fdh;
2581
2582 fdh = elf_link_hash_lookup (elf_hash_table (info),
2583 h->root.root.string + 1,
2584 false, false, false);
2585
2586 if (fdh == NULL)
2587 abort ();
2588
2589 if (fdh->dynindx == -1
2590 && (fdh->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0)
2591 {
2592 if (! bfd_elf64_link_record_dynamic_symbol (info, fdh))
2593 return false;
2594 }
2595 }
2596
2597 /* If this is the first .plt entry, make room for the special
2598 first entry. */
2599 s = htab->splt;
2600 if (s->_raw_size == 0)
2601 s->_raw_size += PLT_INITIAL_ENTRY_SIZE;
2602
2603 h->plt.offset = s->_raw_size;
2604 h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
2605
2606 /* Make room for this entry. */
2607 s->_raw_size += PLT_ENTRY_SIZE;
2608
2609 /* Make room for the .stub and .glink code. */
2610 s = htab->sstub;
2611 s->_raw_size += PLT_CALL_STUB_SIZE;
2612
2613 s = htab->sglink;
2614 if (s->_raw_size == 0)
2615 s->_raw_size += GLINK_CALL_STUB_SIZE;
2616 /* We need bigger stubs past index 32767. */
2617 if (s->_raw_size >= GLINK_CALL_STUB_SIZE + 32768*2*4)
2618 s->_raw_size += 4;
2619 s->_raw_size += 2*4;
2620
2621 /* We also need to make an entry in the .rela.plt section. */
2622 s = htab->srelplt;
2623 s->_raw_size += sizeof (Elf64_External_Rela);
2624 }
2625 else
2626 {
2627 h->plt.offset = (bfd_vma) -1;
2628 h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
2629 }
2630 }
2631 else
2632 {
2633 h->plt.offset = (bfd_vma) -1;
2634 h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
2635 }
2636
2637 if (h->got.refcount > 0)
2638 {
2639 boolean dyn;
2640
2641 /* Make sure this symbol is output as a dynamic symbol.
2642 Undefined weak syms won't yet be marked as dynamic. */
2643 if (h->dynindx == -1
2644 && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0)
2645 {
2646 if (! bfd_elf64_link_record_dynamic_symbol (info, h))
2647 return false;
2648 }
2649
2650 s = htab->sgot;
2651 h->got.offset = s->_raw_size;
2652 s->_raw_size += 8;
2653 dyn = htab->elf.dynamic_sections_created;
2654 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info, h))
2655 htab->srelgot->_raw_size += sizeof (Elf64_External_Rela);
2656 }
2657 else
2658 h->got.offset = (bfd_vma) -1;
2659
2660 eh = (struct ppc_link_hash_entry *) h;
2661 if (eh->dyn_relocs == NULL)
2662 return true;
2663
2664 /* In the shared -Bsymbolic case, discard space allocated for
2665 dynamic pc-relative relocs against symbols which turn out to be
2666 defined in regular objects. For the normal shared case, discard
2667 space for relocs that have become local due to symbol visibility
2668 changes. */
2669
2670 if (info->shared)
2671 {
2672 if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) != 0
2673 && ((h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0
2674 || info->symbolic))
2675 {
2676 struct ppc_dyn_relocs **pp;
2677
2678 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; )
2679 {
2680 p->count -= p->pc_count;
2681 p->pc_count = 0;
2682 if (p->count == 0)
2683 *pp = p->next;
2684 else
2685 pp = &p->next;
2686 }
2687 }
2688 }
2689 else
2690 {
2691 /* For the non-shared case, discard space for relocs against
2692 symbols which turn out to need copy relocs or are not
2693 dynamic. */
2694
2695 if ((h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0
2696 && (((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0
2697 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
2698 || (htab->elf.dynamic_sections_created
2699 && (h->root.type == bfd_link_hash_undefweak
2700 || h->root.type == bfd_link_hash_undefined))))
2701 {
2702 /* Make sure this symbol is output as a dynamic symbol.
2703 Undefined weak syms won't yet be marked as dynamic. */
2704 if (h->dynindx == -1
2705 && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0)
2706 {
2707 if (! bfd_elf64_link_record_dynamic_symbol (info, h))
2708 return false;
2709 }
2710
2711 /* If that succeeded, we know we'll be keeping all the
2712 relocs. */
2713 if (h->dynindx != -1)
2714 goto keep;
2715 }
2716
2717 eh->dyn_relocs = NULL;
2718
2719 keep: ;
2720 }
2721
2722 /* Finally, allocate space. */
2723 for (p = eh->dyn_relocs; p != NULL; p = p->next)
2724 {
2725 asection *sreloc = elf_section_data (p->sec)->sreloc;
2726 sreloc->_raw_size += p->count * sizeof (Elf64_External_Rela);
2727 }
2728
2729 return true;
2730 }
2731
2732 /* Find any dynamic relocs that apply to read-only sections. */
2733
2734 static boolean
2735 readonly_dynrelocs (h, inf)
2736 struct elf_link_hash_entry *h;
2737 PTR inf;
2738 {
2739 struct ppc_link_hash_entry *eh;
2740 struct ppc_dyn_relocs *p;
2741
2742 eh = (struct ppc_link_hash_entry *) h;
2743 for (p = eh->dyn_relocs; p != NULL; p = p->next)
2744 {
2745 asection *s = p->sec->output_section;
2746
2747 if (s != NULL && (s->flags & SEC_READONLY) != 0)
2748 {
2749 struct bfd_link_info *info = (struct bfd_link_info *) inf;
2750
2751 info->flags |= DF_TEXTREL;
2752
2753 /* Not an error, just cut short the traversal. */
2754 return false;
2755 }
2756 }
2757 return true;
2758 }
2759
2760 /* Set the sizes of the dynamic sections. */
2761
2762 static boolean
2763 ppc64_elf_size_dynamic_sections (output_bfd, info)
2764 bfd *output_bfd ATTRIBUTE_UNUSED;
2765 struct bfd_link_info *info;
2766 {
2767 struct ppc_link_hash_table *htab;
2768 bfd *dynobj;
2769 asection *s;
2770 boolean relocs;
2771 bfd *ibfd;
2772
2773 htab = ppc_hash_table (info);
2774 dynobj = htab->elf.dynobj;
2775 if (dynobj == NULL)
2776 abort ();
2777
2778 if (htab->elf.dynamic_sections_created)
2779 {
2780 /* Set the contents of the .interp section to the interpreter. */
2781 if (! info->shared)
2782 {
2783 s = bfd_get_section_by_name (dynobj, ".interp");
2784 if (s == NULL)
2785 abort ();
2786 s->_raw_size = sizeof ELF_DYNAMIC_INTERPRETER;
2787 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
2788 }
2789 }
2790
2791 /* Set up .got offsets for local syms, and space for local dynamic
2792 relocs. */
2793 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
2794 {
2795 bfd_signed_vma *local_got;
2796 bfd_signed_vma *end_local_got;
2797 bfd_size_type locsymcount;
2798 Elf_Internal_Shdr *symtab_hdr;
2799 asection *srel;
2800
2801 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour)
2802 continue;
2803
2804 for (s = ibfd->sections; s != NULL; s = s->next)
2805 {
2806 struct ppc_dyn_relocs *p;
2807
2808 for (p = *((struct ppc_dyn_relocs **)
2809 &elf_section_data (s)->local_dynrel);
2810 p != NULL;
2811 p = p->next)
2812 {
2813 if (!bfd_is_abs_section (p->sec)
2814 && bfd_is_abs_section (p->sec->output_section))
2815 {
2816 /* Input section has been discarded, either because
2817 it is a copy of a linkonce section or due to
2818 linker script /DISCARD/, so we'll be discarding
2819 the relocs too. */
2820 }
2821 else
2822 {
2823 srel = elf_section_data (p->sec)->sreloc;
2824 srel->_raw_size += p->count * sizeof (Elf64_External_Rela);
2825 }
2826 }
2827 }
2828
2829 local_got = elf_local_got_refcounts (ibfd);
2830 if (!local_got)
2831 continue;
2832
2833 symtab_hdr = &elf_tdata (ibfd)->symtab_hdr;
2834 locsymcount = symtab_hdr->sh_info;
2835 end_local_got = local_got + locsymcount;
2836 s = htab->sgot;
2837 srel = htab->srelgot;
2838 for (; local_got < end_local_got; ++local_got)
2839 {
2840 if (*local_got > 0)
2841 {
2842 *local_got = s->_raw_size;
2843 s->_raw_size += 8;
2844 if (info->shared)
2845 srel->_raw_size += sizeof (Elf64_External_Rela);
2846 }
2847 else
2848 *local_got = (bfd_vma) -1;
2849 }
2850 }
2851
2852 /* Allocate global sym .plt and .got entries, and space for global
2853 sym dynamic relocs. */
2854 elf_link_hash_traverse (&htab->elf, allocate_dynrelocs, (PTR) info);
2855
2856 /* We now have determined the sizes of the various dynamic sections.
2857 Allocate memory for them. */
2858 relocs = false;
2859 for (s = dynobj->sections; s != NULL; s = s->next)
2860 {
2861 bfd_vma size;
2862
2863 if ((s->flags & SEC_LINKER_CREATED) == 0)
2864 continue;
2865
2866 if (s == htab->splt
2867 || s == htab->sgot
2868 || s == htab->sstub
2869 || s == htab->sglink)
2870 {
2871 /* Strip this section if we don't need it; see the
2872 comment below. */
2873 }
2874 else if (strncmp (bfd_get_section_name (dynobj, s), ".rela", 5) == 0)
2875 {
2876 if (s->_raw_size == 0)
2877 {
2878 /* If we don't need this section, strip it from the
2879 output file. This is mostly to handle .rela.bss and
2880 .rela.plt. We must create both sections in
2881 create_dynamic_sections, because they must be created
2882 before the linker maps input sections to output
2883 sections. The linker does that before
2884 adjust_dynamic_symbol is called, and it is that
2885 function which decides whether anything needs to go
2886 into these sections. */
2887 }
2888 else
2889 {
2890 if (s != htab->srelplt)
2891 relocs = true;
2892
2893 /* We use the reloc_count field as a counter if we need
2894 to copy relocs into the output file. */
2895 s->reloc_count = 0;
2896 }
2897 }
2898 else
2899 {
2900 /* It's not one of our sections, so don't allocate space. */
2901 continue;
2902 }
2903
2904 if (s->_raw_size == 0)
2905 {
2906 _bfd_strip_section_from_output (info, s);
2907 continue;
2908 }
2909
2910 /* Allocate memory for the section contents. We use bfd_zalloc
2911 here in case unused entries are not reclaimed before the
2912 section's contents are written out. This should not happen,
2913 but this way if it does, we get a R_PPC64_NONE reloc instead
2914 of garbage. */
2915 size = s->_raw_size;
2916 if (s == htab->sstub)
2917 {
2918 /* .stub may grow. Allocate enough for the maximum growth. */
2919 size += (size + 65536 + 65535) / 65536 * 4;
2920 }
2921 s->contents = (bfd_byte *) bfd_zalloc (dynobj, size);
2922 if (s->contents == NULL)
2923 return false;
2924 }
2925
2926 if (elf_hash_table (info)->dynamic_sections_created)
2927 {
2928 /* Add some entries to the .dynamic section. We fill in the
2929 values later, in ppc64_elf_finish_dynamic_sections, but we
2930 must add the entries now so that we get the correct size for
2931 the .dynamic section. The DT_DEBUG entry is filled in by the
2932 dynamic linker and used by the debugger. */
2933 #define add_dynamic_entry(TAG, VAL) \
2934 bfd_elf64_add_dynamic_entry (info, (bfd_vma) (TAG), (bfd_vma) (VAL))
2935
2936 if (!info->shared)
2937 {
2938 if (!add_dynamic_entry (DT_DEBUG, 0))
2939 return false;
2940 }
2941
2942 if (htab->splt->_raw_size != 0)
2943 {
2944 if (!add_dynamic_entry (DT_PLTGOT, 0)
2945 || !add_dynamic_entry (DT_PLTRELSZ, 0)
2946 || !add_dynamic_entry (DT_PLTREL, DT_RELA)
2947 || !add_dynamic_entry (DT_JMPREL, 0)
2948 || !add_dynamic_entry (DT_PPC64_GLINK, 0))
2949 return false;
2950 }
2951
2952 if (relocs)
2953 {
2954 if (!add_dynamic_entry (DT_RELA, 0)
2955 || !add_dynamic_entry (DT_RELASZ, 0)
2956 || !add_dynamic_entry (DT_RELAENT, sizeof (Elf64_External_Rela)))
2957 return false;
2958
2959 /* If any dynamic relocs apply to a read-only section,
2960 then we need a DT_TEXTREL entry. */
2961 elf_link_hash_traverse (&htab->elf, readonly_dynrelocs, (PTR) info);
2962
2963 if ((info->flags & DF_TEXTREL) != 0)
2964 {
2965 if (!add_dynamic_entry (DT_TEXTREL, 0))
2966 return false;
2967 }
2968 }
2969 }
2970 #undef add_dynamic_entry
2971
2972 return true;
2973 }
2974
2975 /* Called after we have seen all the input files/sections, but before
2976 final symbol resolution and section placement has been determined.
2977
2978 We use this hook to provide a value for TOCstart, which we store in
2979 the output bfd elf_gp. */
2980
2981 boolean
2982 ppc64_elf_set_toc (obfd, info)
2983 bfd *obfd;
2984 struct bfd_link_info *info;
2985 {
2986 if (!info->relocateable)
2987 {
2988 asection *s;
2989 bfd_vma TOCstart;
2990
2991 /* The TOC consists of sections .got, .toc, .tocbss, .plt in that
2992 order. The TOC starts where the first of these sections starts. */
2993 s = bfd_get_section_by_name (obfd, ".got");
2994 if (s == NULL)
2995 s = bfd_get_section_by_name (obfd, ".toc");
2996 if (s == NULL)
2997 s = bfd_get_section_by_name (obfd, ".tocbss");
2998 if (s == NULL)
2999 s = bfd_get_section_by_name (obfd, ".plt");
3000 if (s == NULL)
3001 {
3002 /* This may happen for
3003 o references to TOC base (SYM@toc / TOC[tc0]) without a
3004 .toc directive
3005 o bad linker script
3006 o --gc-sections and empty TOC sections
3007
3008 FIXME: Warn user? */
3009
3010 /* Look for a likely section. We probably won't even be
3011 using TOCstart. */
3012 for (s = obfd->sections; s != NULL; s = s->next)
3013 if ((s->flags & (SEC_ALLOC | SEC_SMALL_DATA | SEC_READONLY))
3014 == (SEC_ALLOC | SEC_SMALL_DATA))
3015 break;
3016 if (s == NULL)
3017 for (s = obfd->sections; s != NULL; s = s->next)
3018 if ((s->flags & (SEC_ALLOC | SEC_SMALL_DATA))
3019 == (SEC_ALLOC | SEC_SMALL_DATA))
3020 break;
3021 if (s == NULL)
3022 for (s = obfd->sections; s != NULL; s = s->next)
3023 if ((s->flags & (SEC_ALLOC | SEC_READONLY)) == SEC_ALLOC)
3024 break;
3025 if (s == NULL)
3026 for (s = obfd->sections; s != NULL; s = s->next)
3027 if ((s->flags & SEC_ALLOC) == SEC_ALLOC)
3028 break;
3029 }
3030
3031 TOCstart = 0;
3032 if (s != NULL)
3033 TOCstart = s->output_section->vma + s->output_offset;
3034
3035 elf_gp (obfd) = TOCstart;
3036 }
3037 return true;
3038 }
3039
3040 /* PowerPC64 .plt entries are 24 bytes long, which doesn't divide
3041 evenly into 64k. Sometimes with a large enough .plt, we'll need to
3042 use offsets differing in the high 16 bits when accessing a .plt
3043 entry from a .plt call stub. This function adjusts the size of
3044 .stub to accommodate the extra stub instruction needed in such
3045 cases. */
3046
3047 boolean
3048 ppc64_elf_size_stubs (obfd, info, changed)
3049 bfd *obfd;
3050 struct bfd_link_info *info;
3051 int *changed;
3052 {
3053 struct ppc_link_hash_table *htab = ppc_hash_table (info);
3054 bfd_vma plt_offset, next_64k;
3055 long base, num, extra;
3056
3057 /* .plt and .stub should be both present, or both absent. */
3058 if ((htab->splt == NULL || htab->splt->_raw_size == 0)
3059 != (htab->sstub == NULL || htab->sstub->_raw_size == 0))
3060 abort ();
3061
3062 /* If no .plt, then nothing to do. */
3063 if (htab->splt == NULL || htab->splt->_raw_size == 0)
3064 return true;
3065
3066 plt_offset = (htab->splt->output_section->vma
3067 + htab->splt->output_offset
3068 - elf_gp (obfd));
3069 next_64k = (plt_offset + 65535) & -65536;
3070
3071 /* If the .plt doesn't have any entries crossing a 64k boundary,
3072 then there is no need for bigger stubs. */
3073 if (next_64k <= plt_offset + htab->splt->_raw_size)
3074 return true;
3075
3076 /* OK, so we have at least one transition. Since .plt entries are
3077 24 bytes long, we'll strike it lucky every 3*64k, with the 64k
3078 boundary between .plt entries. */
3079 base = next_64k / 65536;
3080 num = (plt_offset + htab->splt->_raw_size - next_64k) / 65536;
3081 extra = (base % 3 + num + 1) * 2 / 3;
3082
3083 /* Allow one extra instruction for each EXTRA. The change in .stub
3084 may change the location of .toc and .plt. .toc and .plt ought to
3085 move as a group, but someone might be playing with eg. .plt
3086 alignment, so don't allow .stub size to decrease. */
3087 if (htab->sstub->_cooked_size < htab->sstub->_raw_size + extra * 4)
3088 {
3089 htab->sstub->_cooked_size = htab->sstub->_raw_size + extra * 4;
3090 *changed = true;
3091 }
3092 return true;
3093 }
3094
3095 /* Build a .plt call stub. */
3096
3097 static bfd_byte *
3098 build_plt_stub (obfd, p, offset, glink)
3099 bfd *obfd;
3100 bfd_byte *p;
3101 int offset;
3102 int glink;
3103 {
3104 #define PPC_LO(v) ((v) & 0xffff)
3105 #define PPC_HI(v) (((v) >> 16) & 0xffff)
3106 #define PPC_HA(v) PPC_HI ((v) + 0x8000)
3107
3108 if (glink)
3109 bfd_put_32 (obfd, LD_R2_40R1, p), p += 4;
3110 bfd_put_32 (obfd, ADDIS_R12_R2 | PPC_HA (offset), p), p += 4;
3111 if (!glink)
3112 bfd_put_32 (obfd, STD_R2_40R1, p), p += 4;
3113 bfd_put_32 (obfd, LD_R11_0R12 | PPC_LO (offset), p), p += 4;
3114 if (PPC_HA (offset + 8) != PPC_HA (offset))
3115 bfd_put_32 (obfd, ADDIS_R12_R12_1, p), p += 4;
3116 offset += 8;
3117 bfd_put_32 (obfd, LD_R2_0R12 | PPC_LO (offset), p), p += 4;
3118 if (PPC_HA (offset + 8) != PPC_HA (offset))
3119 bfd_put_32 (obfd, ADDIS_R12_R12_1, p), p += 4;
3120 offset += 8;
3121 bfd_put_32 (obfd, MTCTR_R11, p), p += 4;
3122 bfd_put_32 (obfd, LD_R11_0R12 | PPC_LO (offset), p), p += 4;
3123 bfd_put_32 (obfd, BCTR, p), p += 4;
3124 return p;
3125 }
3126
3127 /* Build the stubs for one function call. */
3128
3129 static boolean
3130 build_one_stub (h, inf)
3131 struct elf_link_hash_entry *h;
3132 PTR inf;
3133 {
3134 struct bfd_link_info *info;
3135 struct ppc_link_hash_table *htab;
3136
3137 if (h->root.type == bfd_link_hash_indirect
3138 || h->root.type == bfd_link_hash_warning)
3139 return true;
3140
3141 info = (struct bfd_link_info *) inf;
3142 htab = ppc_hash_table (info);
3143
3144 if (htab->elf.dynamic_sections_created
3145 && h->plt.offset != (bfd_vma) -1)
3146 {
3147 asection *s;
3148 bfd_vma plt_r2;
3149 bfd_byte *p;
3150 unsigned int indx;
3151
3152 /* Point the function at the linkage stub. This works because
3153 the only references to the function code sym are calls.
3154 Function pointer comparisons use the function descriptor. */
3155 s = htab->sstub;
3156 h->root.type = bfd_link_hash_defined;
3157 h->root.u.def.section = s;
3158 h->root.u.def.value = s->_cooked_size;
3159
3160 /* Build the .plt call stub. */
3161 plt_r2 = (htab->splt->output_section->vma
3162 + htab->splt->output_offset
3163 + h->plt.offset
3164 - elf_gp (htab->splt->output_section->owner)
3165 - TOC_BASE_OFF);
3166
3167 if (plt_r2 + 0x80000000 > 0xffffffff)
3168 {
3169 (*_bfd_error_handler)
3170 (_("linkage table overflow against `%s'"),
3171 h->root.root.string);
3172 bfd_set_error (bfd_error_bad_value);
3173 htab->plt_overflow = true;
3174 return false;
3175 }
3176 p = s->contents + s->_cooked_size;
3177 p = build_plt_stub (s->owner, p, (int) plt_r2, 0);
3178 s->_cooked_size = p - s->contents;
3179
3180 /* Build the .glink lazy link call stub. */
3181 s = htab->sglink;
3182 p = s->contents + s->_cooked_size;
3183 indx = s->reloc_count;
3184 if (indx < 0x8000)
3185 {
3186 bfd_put_32 (s->owner, LI_R0_0 | indx, p);
3187 p += 4;
3188 }
3189 else
3190 {
3191 bfd_put_32 (s->owner, LIS_R0_0 | PPC_HI (indx), p);
3192 p += 4;
3193 bfd_put_32 (s->owner, ORI_R0_R0_0 | PPC_LO (indx), p);
3194 p += 4;
3195 }
3196 bfd_put_32 (s->owner, B_DOT | ((s->contents - p) & 0x3fffffc), p);
3197 p += 4;
3198 s->_cooked_size = p - s->contents;
3199 s->reloc_count += 1;
3200 }
3201 return true;
3202 }
3203
3204 boolean
3205 ppc64_elf_build_stubs (obfd, info)
3206 bfd *obfd;
3207 struct bfd_link_info *info;
3208 {
3209 struct ppc_link_hash_table *htab = ppc_hash_table (info);
3210 bfd_vma old_stub_size;
3211 bfd_vma plt_r2;
3212 bfd_byte *p;
3213
3214 /* If no .plt stubs, then nothing to do. */
3215 if (htab->sstub == NULL || htab->sstub->_raw_size == 0)
3216 return true;
3217
3218 old_stub_size = htab->sstub->_cooked_size;
3219 htab->sstub->_cooked_size = 0;
3220
3221 /* Build the .glink plt call stub. */
3222 plt_r2 = (htab->splt->output_section->vma
3223 + htab->splt->output_offset
3224 - elf_gp (obfd)
3225 - TOC_BASE_OFF);
3226 p = htab->sglink->contents;
3227 p = build_plt_stub (htab->sglink->owner, p, (int) plt_r2, 1);
3228 while (p - htab->sglink->contents < GLINK_CALL_STUB_SIZE)
3229 {
3230 bfd_put_32 (htab->sglink->owner, NOP, p);
3231 p += 4;
3232 }
3233 htab->sglink->_cooked_size = p - htab->sglink->contents;
3234
3235 /* Use reloc_count to count entries. */
3236 htab->sglink->reloc_count = 0;
3237
3238 elf_link_hash_traverse (&htab->elf, build_one_stub, (PTR) info);
3239 htab->sglink->reloc_count = 0;
3240
3241 if (htab->plt_overflow)
3242 return false;
3243
3244 if (old_stub_size != htab->sstub->_cooked_size
3245 || htab->sglink->_raw_size != htab->sglink->_cooked_size)
3246 {
3247 (*_bfd_error_handler)
3248 (_("stub section size doesn't match calculated size"));
3249 bfd_set_error (bfd_error_bad_value);
3250 return false;
3251 }
3252 return true;
3253 }
3254
3255 /* Set up any other section flags and such that may be necessary. */
3256
3257 static boolean
3258 ppc64_elf_fake_sections (abfd, shdr, asect)
3259 bfd *abfd ATTRIBUTE_UNUSED;
3260 Elf64_Internal_Shdr *shdr;
3261 asection *asect;
3262 {
3263 if ((asect->flags & SEC_EXCLUDE) != 0)
3264 shdr->sh_flags |= SHF_EXCLUDE;
3265
3266 if ((asect->flags & SEC_SORT_ENTRIES) != 0)
3267 shdr->sh_type = SHT_ORDERED;
3268
3269 return true;
3270 }
3271
3272 /* The RELOCATE_SECTION function is called by the ELF backend linker
3273 to handle the relocations for a section.
3274
3275 The relocs are always passed as Rela structures; if the section
3276 actually uses Rel structures, the r_addend field will always be
3277 zero.
3278
3279 This function is responsible for adjust the section contents as
3280 necessary, and (if using Rela relocs and generating a
3281 relocateable output file) adjusting the reloc addend as
3282 necessary.
3283
3284 This function does not have to worry about setting the reloc
3285 address or the reloc symbol index.
3286
3287 LOCAL_SYMS is a pointer to the swapped in local symbols.
3288
3289 LOCAL_SECTIONS is an array giving the section in the input file
3290 corresponding to the st_shndx field of each local symbol.
3291
3292 The global hash table entry for the global symbols can be found
3293 via elf_sym_hashes (input_bfd).
3294
3295 When generating relocateable output, this function must handle
3296 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
3297 going to be the section symbol corresponding to the output
3298 section, which means that the addend must be adjusted
3299 accordingly. */
3300
3301 static boolean
3302 ppc64_elf_relocate_section (output_bfd, info, input_bfd, input_section,
3303 contents, relocs, local_syms, local_sections)
3304 bfd *output_bfd;
3305 struct bfd_link_info *info;
3306 bfd *input_bfd;
3307 asection *input_section;
3308 bfd_byte *contents;
3309 Elf_Internal_Rela *relocs;
3310 Elf_Internal_Sym *local_syms;
3311 asection **local_sections;
3312 {
3313 struct ppc_link_hash_table *htab;
3314 Elf_Internal_Shdr *symtab_hdr;
3315 struct elf_link_hash_entry **sym_hashes;
3316 Elf_Internal_Rela *rel;
3317 Elf_Internal_Rela *relend;
3318 bfd_vma *local_got_offsets;
3319 bfd_vma TOCstart;
3320 boolean ret = true;
3321
3322 /* Initialize howto table if needed. */
3323 if (!ppc64_elf_howto_table[R_PPC64_ADDR32])
3324 ppc_howto_init ();
3325
3326 htab = ppc_hash_table (info);
3327 local_got_offsets = elf_local_got_offsets (input_bfd);
3328 TOCstart = elf_gp (output_bfd);
3329 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
3330 sym_hashes = elf_sym_hashes (input_bfd);
3331
3332 rel = relocs;
3333 relend = relocs + input_section->reloc_count;
3334 for (; rel < relend; rel++)
3335 {
3336 enum elf_ppc_reloc_type r_type;
3337 bfd_vma offset;
3338 bfd_vma addend;
3339 bfd_reloc_status_type r;
3340 Elf_Internal_Sym *sym;
3341 asection *sec;
3342 struct elf_link_hash_entry *h;
3343 const char *sym_name;
3344 unsigned long r_symndx;
3345 bfd_vma relocation;
3346 boolean unresolved_reloc;
3347 long insn;
3348
3349 r_type = (enum elf_ppc_reloc_type) ELF64_R_TYPE (rel->r_info);
3350 r_symndx = ELF64_R_SYM (rel->r_info);
3351
3352 if (info->relocateable)
3353 {
3354 /* This is a relocatable link. We don't have to change
3355 anything, unless the reloc is against a section symbol,
3356 in which case we have to adjust according to where the
3357 section symbol winds up in the output section. */
3358 if (r_symndx < symtab_hdr->sh_info)
3359 {
3360 sym = local_syms + r_symndx;
3361 if ((unsigned) ELF_ST_TYPE (sym->st_info) == STT_SECTION)
3362 {
3363 sec = local_sections[r_symndx];
3364 rel->r_addend += sec->output_offset + sym->st_value;
3365 }
3366 }
3367 continue;
3368 }
3369
3370 /* This is a final link. */
3371
3372 offset = rel->r_offset;
3373 addend = rel->r_addend;
3374 r = bfd_reloc_other;
3375 sym = (Elf_Internal_Sym *) 0;
3376 sec = (asection *) 0;
3377 h = (struct elf_link_hash_entry *) 0;
3378 sym_name = (const char *) 0;
3379 unresolved_reloc = false;
3380
3381 if (r_type == R_PPC64_TOC)
3382 {
3383 /* Relocation value is TOC base. Symbol is ignored. */
3384 relocation = TOCstart + TOC_BASE_OFF;
3385 }
3386 else if (r_symndx < symtab_hdr->sh_info)
3387 {
3388 /* It's a local symbol. */
3389 sym = local_syms + r_symndx;
3390 sec = local_sections[r_symndx];
3391 sym_name = "<local symbol>";
3392
3393 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, sec, rel);
3394 addend = rel->r_addend;
3395 }
3396 else
3397 {
3398 /* It's a global symbol. */
3399 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
3400 while (h->root.type == bfd_link_hash_indirect
3401 || h->root.type == bfd_link_hash_warning)
3402 h = (struct elf_link_hash_entry *) h->root.u.i.link;
3403 sym_name = h->root.root.string;
3404 relocation = 0;
3405 if (h->root.type == bfd_link_hash_defined
3406 || h->root.type == bfd_link_hash_defweak)
3407 {
3408 sec = h->root.u.def.section;
3409 if (sec->output_section == NULL)
3410 /* Set a flag that will be cleared later if we find a
3411 relocation value for this symbol. output_section
3412 is typically NULL for symbols satisfied by a shared
3413 library. */
3414 unresolved_reloc = true;
3415 else
3416 relocation = (h->root.u.def.value
3417 + sec->output_section->vma
3418 + sec->output_offset);
3419 }
3420 else if (h->root.type == bfd_link_hash_undefweak)
3421 ;
3422 else if (info->shared
3423 && (!info->symbolic || info->allow_shlib_undefined)
3424 && !info->no_undefined
3425 && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
3426 ;
3427 else
3428 {
3429 if (! ((*info->callbacks->undefined_symbol)
3430 (info, h->root.root.string, input_bfd, input_section,
3431 offset, (!info->shared
3432 || info->no_undefined
3433 || ELF_ST_VISIBILITY (h->other)))))
3434 return false;
3435 relocation = 0;
3436 }
3437 }
3438
3439 /* First handle relocations that tweak non-addend part of insn. */
3440 insn = 0;
3441 switch (r_type)
3442 {
3443 default:
3444 break;
3445
3446 /* Branch taken prediction relocations. */
3447 case R_PPC64_ADDR14_BRTAKEN:
3448 case R_PPC64_REL14_BRTAKEN:
3449 insn = 0x01 << 21; /* Set 't' bit, lowest bit of BO field. */
3450 /* Fall thru. */
3451
3452 /* Branch not taken prediction relocations. */
3453 case R_PPC64_ADDR14_BRNTAKEN:
3454 case R_PPC64_REL14_BRNTAKEN:
3455 insn |= bfd_get_32 (output_bfd, contents + offset) & ~(0x01 << 21);
3456 /* Set 'a' bit. This is 0b00010 in BO field for branch on CR(BI)
3457 insns (BO == 001at or 011at), and 0b01000 for branch on CTR
3458 insns (BO == 1a00t or 1a01t). */
3459 if ((insn & (0x14 << 21)) == (0x04 << 21))
3460 insn |= 0x02 << 21;
3461 else if ((insn & (0x14 << 21)) == (0x10 << 21))
3462 insn |= 0x08 << 21;
3463 else
3464 break;
3465
3466 bfd_put_32 (output_bfd, (bfd_vma) insn, contents + offset);
3467 break;
3468
3469 case R_PPC64_REL24:
3470 case R_PPC64_ADDR24:
3471 /* An ADDR24 or REL24 branching to a linkage function may be
3472 followed by a nop that we have to replace with a ld in
3473 order to restore the TOC base pointer. Only calls to
3474 shared objects need to alter the TOC base. These are
3475 recognized by their need for a PLT entry. */
3476 if (h != NULL
3477 && (h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0
3478 /* Make sure that there really is an instruction after
3479 the branch that we can decode. */
3480 && offset + 8 <= input_section->_cooked_size)
3481 {
3482 bfd_byte *pnext;
3483
3484 pnext = contents + offset + 4;
3485 insn = bfd_get_32 (input_bfd, pnext);
3486
3487 if (insn == 0x60000000 /* nop (ori r0,r0,0) */
3488 || insn == 0x4def7b82 /* cror 15,15,15 */
3489 || insn == 0x4ffffb82) /* cror 31,31,31 */
3490 {
3491 bfd_put_32 (input_bfd,
3492 (bfd_vma) 0xe8410028, /* ld r2,40(r1) */
3493 pnext);
3494 }
3495 }
3496 break;
3497 }
3498
3499 /* Set `addend'. */
3500 switch (r_type)
3501 {
3502 default:
3503 (*_bfd_error_handler)
3504 (_("%s: unknown relocation type %d for symbol %s"),
3505 bfd_archive_filename (input_bfd), (int) r_type, sym_name);
3506
3507 bfd_set_error (bfd_error_bad_value);
3508 ret = false;
3509 continue;
3510
3511 case R_PPC64_NONE:
3512 case R_PPC_GNU_VTINHERIT:
3513 case R_PPC_GNU_VTENTRY:
3514 continue;
3515
3516 /* GOT16 relocations. Like an ADDR16 using the symbol's
3517 address in the GOT as relocation value instead of the
3518 symbols value itself. Also, create a GOT entry for the
3519 symbol and put the symbol value there. */
3520 case R_PPC64_GOT16:
3521 case R_PPC64_GOT16_LO:
3522 case R_PPC64_GOT16_HI:
3523 case R_PPC64_GOT16_HA:
3524 case R_PPC64_GOT16_DS:
3525 case R_PPC64_GOT16_LO_DS:
3526 {
3527 /* Relocation is to the entry for this symbol in the global
3528 offset table. */
3529 bfd_vma off;
3530
3531 if (htab->sgot == NULL)
3532 abort ();
3533
3534 if (h != NULL)
3535 {
3536 boolean dyn;
3537
3538 off = h->got.offset;
3539 dyn = htab->elf.dynamic_sections_created;
3540 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info, h)
3541 || (info->shared
3542 && (info->symbolic
3543 || h->dynindx == -1
3544 || (h->elf_link_hash_flags
3545 & ELF_LINK_FORCED_LOCAL))
3546 && (h->elf_link_hash_flags
3547 & ELF_LINK_HASH_DEF_REGULAR)))
3548 {
3549 /* This is actually a static link, or it is a
3550 -Bsymbolic link and the symbol is defined
3551 locally, or the symbol was forced to be local
3552 because of a version file. We must initialize
3553 this entry in the global offset table. Since the
3554 offset must always be a multiple of 8, we use the
3555 least significant bit to record whether we have
3556 initialized it already.
3557
3558 When doing a dynamic link, we create a .rel.got
3559 relocation entry to initialize the value. This
3560 is done in the finish_dynamic_symbol routine. */
3561 if ((off & 1) != 0)
3562 off &= ~1;
3563 else
3564 {
3565 bfd_put_64 (output_bfd, relocation,
3566 htab->sgot->contents + off);
3567 h->got.offset |= 1;
3568 }
3569 }
3570 else
3571 unresolved_reloc = false;
3572 }
3573 else
3574 {
3575 if (local_got_offsets == NULL)
3576 abort ();
3577
3578 off = local_got_offsets[r_symndx];
3579
3580 /* The offset must always be a multiple of 8. We use
3581 the least significant bit to record whether we have
3582 already processed this entry. */
3583 if ((off & 1) != 0)
3584 off &= ~1;
3585 else
3586 {
3587 bfd_put_64 (output_bfd, relocation,
3588 htab->sgot->contents + off);
3589
3590 if (info->shared)
3591 {
3592 Elf_Internal_Rela outrel;
3593 Elf64_External_Rela *loc;
3594
3595 /* We need to generate a R_PPC64_RELATIVE reloc
3596 for the dynamic linker. */
3597 outrel.r_offset = (htab->sgot->output_section->vma
3598 + htab->sgot->output_offset
3599 + off);
3600 outrel.r_info = ELF64_R_INFO (0, R_PPC64_RELATIVE);
3601 outrel.r_addend = relocation;
3602 loc = (Elf64_External_Rela *) htab->srelgot->contents;
3603 loc += htab->srelgot->reloc_count++;
3604 bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc);
3605 }
3606
3607 local_got_offsets[r_symndx] |= 1;
3608 }
3609 }
3610
3611 if (off >= (bfd_vma) -2)
3612 abort ();
3613
3614 relocation = htab->sgot->output_offset + off;
3615
3616 /* TOC base (r2) is TOC start plus 0x8000. */
3617 addend -= TOC_BASE_OFF;
3618 }
3619 break;
3620
3621 case R_PPC64_PLT16_HA:
3622 case R_PPC64_PLT16_HI:
3623 case R_PPC64_PLT16_LO:
3624 case R_PPC64_PLT32:
3625 case R_PPC64_PLT64:
3626 /* Relocation is to the entry for this symbol in the
3627 procedure linkage table. */
3628
3629 /* Resolve a PLT reloc against a local symbol directly,
3630 without using the procedure linkage table. */
3631 if (h == NULL)
3632 break;
3633
3634 if (h->plt.offset == (bfd_vma) -1
3635 || htab->splt == NULL)
3636 {
3637 /* We didn't make a PLT entry for this symbol. This
3638 happens when statically linking PIC code, or when
3639 using -Bsymbolic. */
3640 break;
3641 }
3642
3643 relocation = (htab->splt->output_section->vma
3644 + htab->splt->output_offset
3645 + h->plt.offset);
3646 unresolved_reloc = false;
3647 break;
3648
3649 /* TOC16 relocs. We want the offset relative to the TOC base,
3650 which is the address of the start of the TOC plus 0x8000.
3651 The TOC consists of sections .got, .toc, .tocbss, and .plt,
3652 in this order. */
3653 case R_PPC64_TOC16:
3654 case R_PPC64_TOC16_LO:
3655 case R_PPC64_TOC16_HI:
3656 case R_PPC64_TOC16_DS:
3657 case R_PPC64_TOC16_LO_DS:
3658 case R_PPC64_TOC16_HA:
3659 addend -= TOCstart + TOC_BASE_OFF;
3660 break;
3661
3662 /* Relocate against the beginning of the section. */
3663 case R_PPC64_SECTOFF:
3664 case R_PPC64_SECTOFF_LO:
3665 case R_PPC64_SECTOFF_HI:
3666 case R_PPC64_SECTOFF_DS:
3667 case R_PPC64_SECTOFF_LO_DS:
3668 case R_PPC64_SECTOFF_HA:
3669 if (sec != (asection *) 0)
3670 addend -= sec->output_section->vma;
3671 break;
3672
3673 case R_PPC64_REL24:
3674 break;
3675
3676 /* Relocations that may need to be propagated if this is a
3677 dynamic object. */
3678 case R_PPC64_REL14:
3679 case R_PPC64_REL14_BRNTAKEN:
3680 case R_PPC64_REL14_BRTAKEN:
3681 case R_PPC64_REL32:
3682 case R_PPC64_REL64:
3683 case R_PPC64_ADDR14:
3684 case R_PPC64_ADDR14_BRNTAKEN:
3685 case R_PPC64_ADDR14_BRTAKEN:
3686 case R_PPC64_ADDR16:
3687 case R_PPC64_ADDR16_DS:
3688 case R_PPC64_ADDR16_HA:
3689 case R_PPC64_ADDR16_HI:
3690 case R_PPC64_ADDR16_HIGHER:
3691 case R_PPC64_ADDR16_HIGHERA:
3692 case R_PPC64_ADDR16_HIGHEST:
3693 case R_PPC64_ADDR16_HIGHESTA:
3694 case R_PPC64_ADDR16_LO:
3695 case R_PPC64_ADDR16_LO_DS:
3696 case R_PPC64_ADDR24:
3697 case R_PPC64_ADDR30:
3698 case R_PPC64_ADDR32:
3699 case R_PPC64_ADDR64:
3700 case R_PPC64_UADDR16:
3701 case R_PPC64_UADDR32:
3702 case R_PPC64_UADDR64:
3703 /* r_symndx will be zero only for relocs against symbols
3704 from removed linkonce sections, or sections discarded by
3705 a linker script. */
3706 if (r_symndx == 0)
3707 break;
3708 /* Fall thru. */
3709
3710 case R_PPC64_TOC:
3711 if ((input_section->flags & SEC_ALLOC) == 0)
3712 break;
3713
3714 if ((info->shared
3715 && (IS_ABSOLUTE_RELOC (r_type)
3716 || (h != NULL
3717 && h->dynindx != -1
3718 && (! info->symbolic
3719 || (h->elf_link_hash_flags
3720 & ELF_LINK_HASH_DEF_REGULAR) == 0))))
3721 || (!info->shared
3722 && h != NULL
3723 && h->dynindx != -1
3724 && (h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0
3725 && (((h->elf_link_hash_flags
3726 & ELF_LINK_HASH_DEF_DYNAMIC) != 0
3727 && (h->elf_link_hash_flags
3728 & ELF_LINK_HASH_DEF_REGULAR) == 0)
3729 || h->root.type == bfd_link_hash_undefweak
3730 || h->root.type == bfd_link_hash_undefined)))
3731 {
3732 Elf_Internal_Rela outrel;
3733 boolean skip, relocate;
3734 asection *sreloc;
3735 Elf64_External_Rela *loc;
3736
3737 #if 0
3738 if (strcmp (bfd_get_section_name (output_bfd, input_section),
3739 ".opd") == 0)
3740 break;
3741 #endif
3742
3743 /* When generating a dynamic object, these relocations
3744 are copied into the output file to be resolved at run
3745 time. */
3746
3747 skip = false;
3748
3749 outrel.r_offset =
3750 _bfd_elf_section_offset (output_bfd, info, input_section,
3751 rel->r_offset);
3752 if (outrel.r_offset == (bfd_vma) -1)
3753 skip = true;
3754
3755 outrel.r_offset += (input_section->output_section->vma
3756 + input_section->output_offset);
3757 outrel.r_addend = addend;
3758
3759 if (skip)
3760 {
3761 relocate = false;
3762 memset (&outrel, 0, sizeof outrel);
3763 }
3764 else if (h != NULL
3765 && h->dynindx != -1
3766 && (!IS_ABSOLUTE_RELOC (r_type)
3767 || !info->shared
3768 || !info->symbolic
3769 || (h->elf_link_hash_flags
3770 & ELF_LINK_HASH_DEF_REGULAR) == 0))
3771 {
3772 relocate = false;
3773 outrel.r_info = ELF64_R_INFO (h->dynindx, r_type);
3774 }
3775 else
3776 {
3777 /* This symbol is local, or marked to become local. */
3778 outrel.r_addend += relocation;
3779 relocate = true;
3780 if (r_type == R_PPC64_ADDR64)
3781 {
3782 outrel.r_info = ELF64_R_INFO (0, R_PPC64_RELATIVE);
3783 }
3784 else
3785 {
3786 long indx = 0;
3787
3788 if (r_type == R_PPC64_TOC || bfd_is_abs_section (sec))
3789 ;
3790 else if (sec == NULL || sec->owner == NULL)
3791 {
3792 bfd_set_error (bfd_error_bad_value);
3793 return false;
3794 }
3795 else
3796 {
3797 asection *osec;
3798
3799 osec = sec->output_section;
3800 indx = elf_section_data (osec)->dynindx;
3801
3802 /* We are turning this relocation into one
3803 against a section symbol, so subtract out
3804 the output section's address but not the
3805 offset of the input section in the output
3806 section. */
3807 outrel.r_addend -= osec->vma;
3808 }
3809
3810 outrel.r_info = ELF64_R_INFO (indx, r_type);
3811 }
3812 }
3813
3814 sreloc = elf_section_data (input_section)->sreloc;
3815 if (sreloc == NULL)
3816 abort ();
3817
3818 loc = (Elf64_External_Rela *) sreloc->contents;
3819 loc += sreloc->reloc_count++;
3820 bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc);
3821
3822 /* If this reloc is against an external symbol, it will
3823 be computed at runtime, so there's no need to do
3824 anything now. */
3825 if (! relocate)
3826 continue;
3827 }
3828 break;
3829
3830 case R_PPC64_COPY:
3831 case R_PPC64_GLOB_DAT:
3832 case R_PPC64_JMP_SLOT:
3833 case R_PPC64_RELATIVE:
3834 /* We shouldn't ever see these dynamic relocs in relocatable
3835 files. */
3836 /* Fall thru */
3837
3838 case R_PPC64_PLTGOT16:
3839 case R_PPC64_PLTGOT16_DS:
3840 case R_PPC64_PLTGOT16_HA:
3841 case R_PPC64_PLTGOT16_HI:
3842 case R_PPC64_PLTGOT16_LO:
3843 case R_PPC64_PLTGOT16_LO_DS:
3844 case R_PPC64_PLTREL32:
3845 case R_PPC64_PLTREL64:
3846 /* These ones haven't been implemented yet. */
3847
3848 (*_bfd_error_handler)
3849 (_("%s: Relocation %s is not supported for symbol %s."),
3850 bfd_archive_filename (input_bfd),
3851 ppc64_elf_howto_table[(int) r_type]->name, sym_name);
3852
3853 bfd_set_error (bfd_error_invalid_operation);
3854 ret = false;
3855 continue;
3856 }
3857
3858 /* Do any further special processing. */
3859 switch (r_type)
3860 {
3861 default:
3862 break;
3863
3864 case R_PPC64_ADDR16_HA:
3865 case R_PPC64_ADDR16_HIGHERA:
3866 case R_PPC64_ADDR16_HIGHESTA:
3867 case R_PPC64_PLT16_HA:
3868 case R_PPC64_TOC16_HA:
3869 case R_PPC64_SECTOFF_HA:
3870 /* It's just possible that this symbol is a weak symbol
3871 that's not actually defined anywhere. In that case,
3872 'sec' would be NULL, and we should leave the symbol
3873 alone (it will be set to zero elsewhere in the link). */
3874 if (sec != NULL)
3875 /* Add 0x10000 if sign bit in 0:15 is set. */
3876 addend += ((relocation + addend) & 0x8000) << 1;
3877 break;
3878
3879 case R_PPC64_ADDR16_DS:
3880 case R_PPC64_ADDR16_LO_DS:
3881 case R_PPC64_GOT16_DS:
3882 case R_PPC64_GOT16_LO_DS:
3883 case R_PPC64_PLT16_LO_DS:
3884 case R_PPC64_SECTOFF_DS:
3885 case R_PPC64_SECTOFF_LO_DS:
3886 case R_PPC64_TOC16_DS:
3887 case R_PPC64_TOC16_LO_DS:
3888 case R_PPC64_PLTGOT16_DS:
3889 case R_PPC64_PLTGOT16_LO_DS:
3890 if (((relocation + addend) & 3) != 0)
3891 {
3892 (*_bfd_error_handler)
3893 (_("%s: error: relocation %s not a multiple of 4"),
3894 bfd_archive_filename (input_bfd),
3895 ppc64_elf_howto_table[(int) r_type]->name);
3896 bfd_set_error (bfd_error_bad_value);
3897 ret = false;
3898 continue;
3899 }
3900 break;
3901 }
3902
3903 /* FIXME: Why do we allow debugging sections to escape this error?
3904 More importantly, why do we not emit dynamic relocs above in
3905 debugging sections (which are ! SEC_ALLOC)? If we had
3906 emitted the dynamic reloc, we could remove the fudge here. */
3907 if (unresolved_reloc
3908 && !(info->shared
3909 && (input_section->flags & SEC_DEBUGGING) != 0
3910 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0))
3911 (*_bfd_error_handler)
3912 (_("%s(%s+0x%lx): unresolvable relocation against symbol `%s'"),
3913 bfd_archive_filename (input_bfd),
3914 bfd_get_section_name (input_bfd, input_section),
3915 (long) rel->r_offset,
3916 h->root.root.string);
3917
3918 r = _bfd_final_link_relocate (ppc64_elf_howto_table[(int) r_type],
3919 input_bfd,
3920 input_section,
3921 contents,
3922 offset,
3923 relocation,
3924 addend);
3925
3926 if (r == bfd_reloc_ok)
3927 ;
3928 else if (r == bfd_reloc_overflow)
3929 {
3930 const char *name;
3931
3932 if (h != NULL)
3933 {
3934 if (h->root.type == bfd_link_hash_undefweak
3935 && ppc64_elf_howto_table[(int) r_type]->pc_relative)
3936 {
3937 /* Assume this is a call protected by other code that
3938 detects the symbol is undefined. If this is the case,
3939 we can safely ignore the overflow. If not, the
3940 program is hosed anyway, and a little warning isn't
3941 going to help. */
3942
3943 continue;
3944 }
3945
3946 name = h->root.root.string;
3947 }
3948 else
3949 {
3950 name = bfd_elf_string_from_elf_section (input_bfd,
3951 symtab_hdr->sh_link,
3952 sym->st_name);
3953 if (name == NULL)
3954 continue;
3955 if (*name == '\0')
3956 name = bfd_section_name (input_bfd, sec);
3957 }
3958
3959 if (! ((*info->callbacks->reloc_overflow)
3960 (info, name, ppc64_elf_howto_table[(int) r_type]->name,
3961 (bfd_vma) 0, input_bfd, input_section, offset)))
3962 return false;
3963 }
3964 else
3965 ret = false;
3966 }
3967
3968 return ret;
3969 }
3970
3971 /* Finish up dynamic symbol handling. We set the contents of various
3972 dynamic sections here. */
3973
3974 static boolean
3975 ppc64_elf_finish_dynamic_symbol (output_bfd, info, h, sym)
3976 bfd *output_bfd;
3977 struct bfd_link_info *info;
3978 struct elf_link_hash_entry *h;
3979 Elf_Internal_Sym *sym;
3980 {
3981 struct ppc_link_hash_table *htab;
3982 bfd *dynobj;
3983
3984 htab = ppc_hash_table (info);
3985 dynobj = htab->elf.dynobj;
3986
3987 if (h->plt.offset != (bfd_vma) -1)
3988 {
3989 struct elf_link_hash_entry *funcdesc_h;
3990 Elf_Internal_Rela rela;
3991 Elf64_External_Rela *loc;
3992
3993 /* This symbol has an entry in the procedure linkage table. Set
3994 it up. */
3995
3996 if (htab->splt == NULL
3997 || htab->srelplt == NULL
3998 || htab->sglink == NULL
3999 || h->root.root.string[0] != '.'
4000 || h->root.root.string[1] == '\0')
4001 abort ();
4002
4003 /* Find its corresponding function descriptor.
4004 ppc64_elf_adjust_dynamic_symbol has already set it up for us. */
4005
4006 funcdesc_h = elf_link_hash_lookup (elf_hash_table (info),
4007 h->root.root.string + 1,
4008 false, false, false);
4009
4010 if (funcdesc_h == NULL || funcdesc_h->dynindx == -1)
4011 abort ();
4012
4013 /* Create a JMP_SLOT reloc to inform the dynamic linker to
4014 fill in the PLT entry. */
4015
4016 rela.r_offset = (htab->splt->output_section->vma
4017 + htab->splt->output_offset
4018 + h->plt.offset);
4019 rela.r_info = ELF64_R_INFO (funcdesc_h->dynindx, R_PPC64_JMP_SLOT);
4020 rela.r_addend = 0;
4021
4022 loc = (Elf64_External_Rela *) htab->srelplt->contents;
4023 loc += (h->plt.offset - PLT_INITIAL_ENTRY_SIZE) / PLT_ENTRY_SIZE;
4024 bfd_elf64_swap_reloca_out (output_bfd, &rela, loc);
4025 }
4026
4027 if (h->got.offset != (bfd_vma) -1)
4028 {
4029 Elf_Internal_Rela rela;
4030 Elf64_External_Rela *loc;
4031
4032 /* This symbol has an entry in the global offset table. Set it
4033 up. */
4034
4035 if (htab->sgot == NULL || htab->srelgot == NULL)
4036 abort ();
4037
4038 rela.r_offset = (htab->sgot->output_section->vma
4039 + htab->sgot->output_offset
4040 + (h->got.offset &~ (bfd_vma) 1));
4041
4042 /* If this is a static link, or it is a -Bsymbolic link and the
4043 symbol is defined locally or was forced to be local because
4044 of a version file, we just want to emit a RELATIVE reloc.
4045 The entry in the global offset table will already have been
4046 initialized in the relocate_section function. */
4047 if (info->shared
4048 && (info->symbolic
4049 || h->dynindx == -1
4050 || (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL))
4051 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR))
4052 {
4053 BFD_ASSERT((h->got.offset & 1) != 0);
4054 rela.r_info = ELF64_R_INFO (0, R_PPC64_RELATIVE);
4055 rela.r_addend = (h->root.u.def.value
4056 + h->root.u.def.section->output_section->vma
4057 + h->root.u.def.section->output_offset);
4058 }
4059 else
4060 {
4061 BFD_ASSERT ((h->got.offset & 1) == 0);
4062 bfd_put_64 (output_bfd, (bfd_vma) 0,
4063 htab->sgot->contents + h->got.offset);
4064 rela.r_info = ELF64_R_INFO (h->dynindx, R_PPC64_GLOB_DAT);
4065 rela.r_addend = 0;
4066 }
4067
4068 loc = (Elf64_External_Rela *) htab->srelgot->contents;
4069 loc += htab->srelgot->reloc_count++;
4070 bfd_elf64_swap_reloca_out (output_bfd, &rela, loc);
4071 }
4072
4073 if ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_COPY) != 0)
4074 {
4075 Elf_Internal_Rela rela;
4076 Elf64_External_Rela *loc;
4077
4078 /* This symbol needs a copy reloc. Set it up. */
4079
4080 if (h->dynindx == -1
4081 || (h->root.type != bfd_link_hash_defined
4082 && h->root.type != bfd_link_hash_defweak)
4083 || htab->srelbss == NULL)
4084 abort ();
4085
4086 rela.r_offset = (h->root.u.def.value
4087 + h->root.u.def.section->output_section->vma
4088 + h->root.u.def.section->output_offset);
4089 rela.r_info = ELF64_R_INFO (h->dynindx, R_PPC64_COPY);
4090 rela.r_addend = 0;
4091 loc = (Elf64_External_Rela *) htab->srelbss->contents;
4092 loc += htab->srelbss->reloc_count++;
4093 bfd_elf64_swap_reloca_out (output_bfd, &rela, loc);
4094 }
4095
4096 /* Mark some specially defined symbols as absolute. */
4097 if (strcmp (h->root.root.string, "_DYNAMIC") == 0)
4098 sym->st_shndx = SHN_ABS;
4099
4100 return true;
4101 }
4102
4103 /* Used to decide how to sort relocs in an optimal manner for the
4104 dynamic linker, before writing them out. */
4105
4106 static enum elf_reloc_type_class
4107 ppc64_elf_reloc_type_class (rela)
4108 const Elf_Internal_Rela *rela;
4109 {
4110 enum elf_ppc_reloc_type r_type;
4111
4112 r_type = (enum elf_ppc_reloc_type) ELF64_R_TYPE (rela->r_info);
4113 switch (r_type)
4114 {
4115 case R_PPC64_RELATIVE:
4116 return reloc_class_relative;
4117 case R_PPC64_JMP_SLOT:
4118 return reloc_class_plt;
4119 case R_PPC64_COPY:
4120 return reloc_class_copy;
4121 default:
4122 return reloc_class_normal;
4123 }
4124 }
4125
4126 /* Finish up the dynamic sections. */
4127
4128 static boolean
4129 ppc64_elf_finish_dynamic_sections (output_bfd, info)
4130 bfd *output_bfd;
4131 struct bfd_link_info *info;
4132 {
4133 struct ppc_link_hash_table *htab;
4134 bfd *dynobj;
4135 asection *sdyn;
4136
4137 htab = ppc_hash_table (info);
4138 dynobj = htab->elf.dynobj;
4139 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
4140
4141 if (htab->elf.dynamic_sections_created)
4142 {
4143 Elf64_External_Dyn *dyncon, *dynconend;
4144
4145 if (sdyn == NULL || htab->sgot == NULL)
4146 abort ();
4147
4148 dyncon = (Elf64_External_Dyn *) sdyn->contents;
4149 dynconend = (Elf64_External_Dyn *) (sdyn->contents + sdyn->_raw_size);
4150 for (; dyncon < dynconend; dyncon++)
4151 {
4152 Elf_Internal_Dyn dyn;
4153
4154 bfd_elf64_swap_dyn_in (dynobj, dyncon, &dyn);
4155
4156 switch (dyn.d_tag)
4157 {
4158 default:
4159 continue;
4160
4161 case DT_PPC64_GLINK:
4162 dyn.d_un.d_ptr = (htab->sglink->output_section->vma
4163 + htab->sglink->output_offset);
4164 break;
4165
4166 case DT_PLTGOT:
4167 dyn.d_un.d_ptr = (htab->splt->output_section->vma
4168 + htab->splt->output_offset);
4169 break;
4170
4171 case DT_JMPREL:
4172 dyn.d_un.d_ptr = (htab->srelplt->output_section->vma
4173 + htab->srelplt->output_offset);
4174 break;
4175
4176 case DT_PLTRELSZ:
4177 dyn.d_un.d_val = htab->srelplt->_raw_size;
4178 break;
4179
4180 case DT_RELASZ:
4181 /* Don't count procedure linkage table relocs in the
4182 overall reloc count. */
4183 if (htab->srelplt != NULL)
4184 dyn.d_un.d_val -= htab->srelplt->_raw_size;
4185 break;
4186 }
4187
4188 bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon);
4189 }
4190 }
4191
4192 if (htab->sgot != NULL && htab->sgot->_raw_size != 0)
4193 {
4194 /* Fill in the first entry in the global offset table.
4195 We use it to hold the link-time TOCbase. */
4196 bfd_put_64 (output_bfd,
4197 elf_gp (output_bfd) - TOC_BASE_OFF,
4198 htab->sgot->contents);
4199
4200 /* Set .got entry size. */
4201 elf_section_data (htab->sgot->output_section)->this_hdr.sh_entsize = 8;
4202 }
4203
4204 if (htab->splt != NULL && htab->splt->_raw_size != 0)
4205 {
4206 /* Set .plt entry size. */
4207 elf_section_data (htab->splt->output_section)->this_hdr.sh_entsize
4208 = PLT_ENTRY_SIZE;
4209 }
4210
4211 return true;
4212 }
4213
4214 #define TARGET_LITTLE_SYM bfd_elf64_powerpcle_vec
4215 #define TARGET_LITTLE_NAME "elf64-powerpcle"
4216 #define TARGET_BIG_SYM bfd_elf64_powerpc_vec
4217 #define TARGET_BIG_NAME "elf64-powerpc"
4218 #define ELF_ARCH bfd_arch_powerpc
4219 #define ELF_MACHINE_CODE EM_PPC64
4220 #define ELF_MAXPAGESIZE 0x10000
4221 #define elf_info_to_howto ppc64_elf_info_to_howto
4222
4223 #ifdef EM_CYGNUS_POWERPC
4224 #define ELF_MACHINE_ALT1 EM_CYGNUS_POWERPC
4225 #endif
4226
4227 #ifdef EM_PPC_OLD
4228 #define ELF_MACHINE_ALT2 EM_PPC_OLD
4229 #endif
4230
4231 #define elf_backend_want_got_sym 0
4232 #define elf_backend_want_plt_sym 0
4233 #define elf_backend_plt_alignment 3
4234 #define elf_backend_plt_not_loaded 1
4235 #define elf_backend_got_symbol_offset 0
4236 #define elf_backend_got_header_size 8
4237 #define elf_backend_plt_header_size PLT_INITIAL_ENTRY_SIZE
4238 #define elf_backend_can_gc_sections 1
4239 #define elf_backend_can_refcount 1
4240
4241 #define bfd_elf64_bfd_reloc_type_lookup ppc64_elf_reloc_type_lookup
4242 #define bfd_elf64_bfd_set_private_flags ppc64_elf_set_private_flags
4243 #define bfd_elf64_bfd_merge_private_bfd_data ppc64_elf_merge_private_bfd_data
4244 #define bfd_elf64_bfd_link_hash_table_create ppc64_elf_link_hash_table_create
4245
4246 #define elf_backend_section_from_shdr ppc64_elf_section_from_shdr
4247 #define elf_backend_create_dynamic_sections ppc64_elf_create_dynamic_sections
4248 #define elf_backend_copy_indirect_symbol ppc64_elf_copy_indirect_symbol
4249 #define elf_backend_check_relocs ppc64_elf_check_relocs
4250 #define elf_backend_gc_mark_hook ppc64_elf_gc_mark_hook
4251 #define elf_backend_gc_sweep_hook ppc64_elf_gc_sweep_hook
4252 #define elf_backend_adjust_dynamic_symbol ppc64_elf_adjust_dynamic_symbol
4253 #define elf_backend_size_dynamic_sections ppc64_elf_size_dynamic_sections
4254 #define elf_backend_fake_sections ppc64_elf_fake_sections
4255 #define elf_backend_relocate_section ppc64_elf_relocate_section
4256 #define elf_backend_finish_dynamic_symbol ppc64_elf_finish_dynamic_symbol
4257 #define elf_backend_reloc_type_class ppc64_elf_reloc_type_class
4258 #define elf_backend_finish_dynamic_sections ppc64_elf_finish_dynamic_sections
4259
4260 #include "elf64-target.h"