* elf64-ppc.c (ppc64_elf_get_symbol_info): New function.
[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_ha_reloc
43 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
44 static bfd_reloc_status_type ppc64_elf_brtaken_reloc
45 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
46 static bfd_reloc_status_type ppc64_elf_sectoff_reloc
47 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
48 static bfd_reloc_status_type ppc64_elf_sectoff_ha_reloc
49 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
50 static bfd_reloc_status_type ppc64_elf_toc_reloc
51 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
52 static bfd_reloc_status_type ppc64_elf_toc_ha_reloc
53 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
54 static bfd_reloc_status_type ppc64_elf_toc64_reloc
55 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
56 static bfd_reloc_status_type ppc64_elf_unhandled_reloc
57 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
58 static void ppc64_elf_get_symbol_info
59 PARAMS ((bfd *, asymbol *, symbol_info *));
60 static boolean ppc64_elf_set_private_flags
61 PARAMS ((bfd *, flagword));
62 static boolean ppc64_elf_merge_private_bfd_data
63 PARAMS ((bfd *, bfd *));
64 static boolean ppc64_elf_section_from_shdr
65 PARAMS ((bfd *, Elf64_Internal_Shdr *, char *));
66
67
68 /* The name of the dynamic interpreter. This is put in the .interp
69 section. */
70 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
71
72 /* The size in bytes of an entry in the procedure linkage table. */
73 #define PLT_ENTRY_SIZE 24
74
75 /* The initial size of the plt reserved for the dynamic linker. */
76 #define PLT_INITIAL_ENTRY_SIZE PLT_ENTRY_SIZE
77
78 /* TOC base pointers offset from start of TOC. */
79 #define TOC_BASE_OFF (0x8000)
80
81 /* .plt call stub instructions. */
82 #define ADDIS_R12_R2 0x3d820000 /* addis %r12,%r2,xxx@ha */
83 #define STD_R2_40R1 0xf8410028 /* std %r2,40(%r1) */
84 #define LD_R11_0R12 0xe96c0000 /* ld %r11,xxx+0@l(%r12) */
85 #define LD_R2_0R12 0xe84c0000 /* ld %r2,xxx+8@l(%r12) */
86 #define MTCTR_R11 0x7d6903a6 /* mtctr %r11 */
87 /* ld %r11,xxx+16@l(%r12) */
88 #define BCTR 0x4e800420 /* bctr */
89
90 /* The normal stub is this size. */
91 #define PLT_CALL_STUB_SIZE (7*4)
92
93 /* But sometimes the .plt entry crosses a 64k boundary, and we need
94 to adjust the high word with this insn. */
95 #define ADDIS_R12_R12_1 0x3d8c0001 /* addis %r12,%r12,1 */
96
97 /* The .glink fixup call stub is the same as the .plt call stub, but
98 the first instruction restores r2, and the std is omitted. */
99 #define LD_R2_40R1 0xe8410028 /* ld %r2,40(%r1) */
100
101 /* Always allow this much space. */
102 #define GLINK_CALL_STUB_SIZE (8*4)
103
104 /* Pad with this. */
105 #define NOP 0x60000000
106
107 /* Some other nops. */
108 #define CROR_151515 0x4def7b82
109 #define CROR_313131 0x4ffffb82
110
111 /* .glink entries for the first 32k functions are two instructions. */
112 #define LI_R0_0 0x38000000 /* li %r0,0 */
113 #define B_DOT 0x48000000 /* b . */
114
115 /* After that, we need two instructions to load the index, followed by
116 a branch. */
117 #define LIS_R0_0 0x3c000000 /* lis %r0,0 */
118 #define ORI_R0_R0_0 0x60000000 /* ori %r0,%r0,0 */
119
120 /* Instructions to save and restore floating point regs. */
121 #define STFD_FR0_0R1 0xd8010000 /* stfd %fr0,0(%r1) */
122 #define LFD_FR0_0R1 0xc8010000 /* lfd %fr0,0(%r1) */
123 #define BLR 0x4e800020 /* blr */
124
125 /* Since .opd is an array of descriptors and each entry will end up
126 with identical R_PPC64_RELATIVE relocs, there is really no need to
127 propagate .opd relocs; The dynamic linker should be taught to
128 relocate .opd without reloc entries. FIXME: .opd should be trimmed
129 of unused values. */
130 #ifndef NO_OPD_RELOCS
131 #define NO_OPD_RELOCS 0
132 #endif
133 \f
134 /* Relocation HOWTO's. */
135 static reloc_howto_type *ppc64_elf_howto_table[(int) R_PPC_max];
136
137 static reloc_howto_type ppc64_elf_howto_raw[] = {
138 /* This reloc does nothing. */
139 HOWTO (R_PPC64_NONE, /* type */
140 0, /* rightshift */
141 2, /* size (0 = byte, 1 = short, 2 = long) */
142 32, /* bitsize */
143 false, /* pc_relative */
144 0, /* bitpos */
145 complain_overflow_bitfield, /* complain_on_overflow */
146 bfd_elf_generic_reloc, /* special_function */
147 "R_PPC64_NONE", /* name */
148 false, /* partial_inplace */
149 0, /* src_mask */
150 0, /* dst_mask */
151 false), /* pcrel_offset */
152
153 /* A standard 32 bit relocation. */
154 HOWTO (R_PPC64_ADDR32, /* type */
155 0, /* rightshift */
156 2, /* size (0 = byte, 1 = short, 2 = long) */
157 32, /* bitsize */
158 false, /* pc_relative */
159 0, /* bitpos */
160 complain_overflow_bitfield, /* complain_on_overflow */
161 bfd_elf_generic_reloc, /* special_function */
162 "R_PPC64_ADDR32", /* name */
163 false, /* partial_inplace */
164 0, /* src_mask */
165 0xffffffff, /* dst_mask */
166 false), /* pcrel_offset */
167
168 /* An absolute 26 bit branch; the lower two bits must be zero.
169 FIXME: we don't check that, we just clear them. */
170 HOWTO (R_PPC64_ADDR24, /* type */
171 0, /* rightshift */
172 2, /* size (0 = byte, 1 = short, 2 = long) */
173 26, /* 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_ADDR24", /* name */
179 false, /* partial_inplace */
180 0, /* src_mask */
181 0x3fffffc, /* dst_mask */
182 false), /* pcrel_offset */
183
184 /* A standard 16 bit relocation. */
185 HOWTO (R_PPC64_ADDR16, /* type */
186 0, /* rightshift */
187 1, /* size (0 = byte, 1 = short, 2 = long) */
188 16, /* bitsize */
189 false, /* pc_relative */
190 0, /* bitpos */
191 complain_overflow_bitfield, /* complain_on_overflow */
192 bfd_elf_generic_reloc, /* special_function */
193 "R_PPC64_ADDR16", /* name */
194 false, /* partial_inplace */
195 0, /* src_mask */
196 0xffff, /* dst_mask */
197 false), /* pcrel_offset */
198
199 /* A 16 bit relocation without overflow. */
200 HOWTO (R_PPC64_ADDR16_LO, /* type */
201 0, /* rightshift */
202 1, /* size (0 = byte, 1 = short, 2 = long) */
203 16, /* bitsize */
204 false, /* pc_relative */
205 0, /* bitpos */
206 complain_overflow_dont,/* complain_on_overflow */
207 bfd_elf_generic_reloc, /* special_function */
208 "R_PPC64_ADDR16_LO", /* name */
209 false, /* partial_inplace */
210 0, /* src_mask */
211 0xffff, /* dst_mask */
212 false), /* pcrel_offset */
213
214 /* Bits 16-31 of an address. */
215 HOWTO (R_PPC64_ADDR16_HI, /* type */
216 16, /* rightshift */
217 1, /* size (0 = byte, 1 = short, 2 = long) */
218 16, /* bitsize */
219 false, /* pc_relative */
220 0, /* bitpos */
221 complain_overflow_dont, /* complain_on_overflow */
222 bfd_elf_generic_reloc, /* special_function */
223 "R_PPC64_ADDR16_HI", /* name */
224 false, /* partial_inplace */
225 0, /* src_mask */
226 0xffff, /* dst_mask */
227 false), /* pcrel_offset */
228
229 /* Bits 16-31 of an address, plus 1 if the contents of the low 16
230 bits, treated as a signed number, is negative. */
231 HOWTO (R_PPC64_ADDR16_HA, /* 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 ppc64_elf_ha_reloc, /* special_function */
239 "R_PPC64_ADDR16_HA", /* name */
240 false, /* partial_inplace */
241 0, /* src_mask */
242 0xffff, /* dst_mask */
243 false), /* pcrel_offset */
244
245 /* An absolute 16 bit branch; the lower two bits must be zero.
246 FIXME: we don't check that, we just clear them. */
247 HOWTO (R_PPC64_ADDR14, /* type */
248 0, /* rightshift */
249 2, /* size (0 = byte, 1 = short, 2 = long) */
250 16, /* bitsize */
251 false, /* pc_relative */
252 0, /* bitpos */
253 complain_overflow_bitfield, /* complain_on_overflow */
254 bfd_elf_generic_reloc, /* special_function */
255 "R_PPC64_ADDR14", /* name */
256 false, /* partial_inplace */
257 0, /* src_mask */
258 0xfffc, /* dst_mask */
259 false), /* pcrel_offset */
260
261 /* An absolute 16 bit branch, for which bit 10 should be set to
262 indicate that the branch is expected to be taken. The lower two
263 bits must be zero. */
264 HOWTO (R_PPC64_ADDR14_BRTAKEN, /* type */
265 0, /* rightshift */
266 2, /* size (0 = byte, 1 = short, 2 = long) */
267 16, /* bitsize */
268 false, /* pc_relative */
269 0, /* bitpos */
270 complain_overflow_bitfield, /* complain_on_overflow */
271 ppc64_elf_brtaken_reloc, /* special_function */
272 "R_PPC64_ADDR14_BRTAKEN",/* name */
273 false, /* partial_inplace */
274 0, /* src_mask */
275 0xfffc, /* dst_mask */
276 false), /* pcrel_offset */
277
278 /* An absolute 16 bit branch, for which bit 10 should be set to
279 indicate that the branch is not expected to be taken. The lower
280 two bits must be zero. */
281 HOWTO (R_PPC64_ADDR14_BRNTAKEN, /* type */
282 0, /* rightshift */
283 2, /* size (0 = byte, 1 = short, 2 = long) */
284 16, /* bitsize */
285 false, /* pc_relative */
286 0, /* bitpos */
287 complain_overflow_bitfield, /* complain_on_overflow */
288 ppc64_elf_brtaken_reloc, /* special_function */
289 "R_PPC64_ADDR14_BRNTAKEN",/* name */
290 false, /* partial_inplace */
291 0, /* src_mask */
292 0xfffc, /* dst_mask */
293 false), /* pcrel_offset */
294
295 /* A relative 26 bit branch; the lower two bits must be zero. */
296 HOWTO (R_PPC64_REL24, /* type */
297 0, /* rightshift */
298 2, /* size (0 = byte, 1 = short, 2 = long) */
299 26, /* bitsize */
300 true, /* pc_relative */
301 0, /* bitpos */
302 complain_overflow_signed, /* complain_on_overflow */
303 bfd_elf_generic_reloc, /* special_function */
304 "R_PPC64_REL24", /* name */
305 false, /* partial_inplace */
306 0, /* src_mask */
307 0x3fffffc, /* dst_mask */
308 true), /* pcrel_offset */
309
310 /* A relative 16 bit branch; the lower two bits must be zero. */
311 HOWTO (R_PPC64_REL14, /* type */
312 0, /* rightshift */
313 2, /* size (0 = byte, 1 = short, 2 = long) */
314 16, /* bitsize */
315 true, /* pc_relative */
316 0, /* bitpos */
317 complain_overflow_signed, /* complain_on_overflow */
318 bfd_elf_generic_reloc, /* special_function */
319 "R_PPC64_REL14", /* name */
320 false, /* partial_inplace */
321 0, /* src_mask */
322 0xfffc, /* dst_mask */
323 true), /* pcrel_offset */
324
325 /* A relative 16 bit branch. Bit 10 should be set to indicate that
326 the branch is expected to be taken. The lower two bits must be
327 zero. */
328 HOWTO (R_PPC64_REL14_BRTAKEN, /* type */
329 0, /* rightshift */
330 2, /* size (0 = byte, 1 = short, 2 = long) */
331 16, /* bitsize */
332 true, /* pc_relative */
333 0, /* bitpos */
334 complain_overflow_signed, /* complain_on_overflow */
335 ppc64_elf_brtaken_reloc, /* special_function */
336 "R_PPC64_REL14_BRTAKEN", /* name */
337 false, /* partial_inplace */
338 0, /* src_mask */
339 0xfffc, /* dst_mask */
340 true), /* pcrel_offset */
341
342 /* A relative 16 bit branch. Bit 10 should be set to indicate that
343 the branch is not expected to be taken. The lower two bits must
344 be zero. */
345 HOWTO (R_PPC64_REL14_BRNTAKEN, /* type */
346 0, /* rightshift */
347 2, /* size (0 = byte, 1 = short, 2 = long) */
348 16, /* bitsize */
349 true, /* pc_relative */
350 0, /* bitpos */
351 complain_overflow_signed, /* complain_on_overflow */
352 ppc64_elf_brtaken_reloc, /* special_function */
353 "R_PPC64_REL14_BRNTAKEN",/* name */
354 false, /* partial_inplace */
355 0, /* src_mask */
356 0xfffc, /* dst_mask */
357 true), /* pcrel_offset */
358
359 /* Like R_PPC64_ADDR16, but referring to the GOT table entry for the
360 symbol. */
361 HOWTO (R_PPC64_GOT16, /* type */
362 0, /* rightshift */
363 1, /* size (0 = byte, 1 = short, 2 = long) */
364 16, /* bitsize */
365 false, /* pc_relative */
366 0, /* bitpos */
367 complain_overflow_signed, /* complain_on_overflow */
368 ppc64_elf_unhandled_reloc, /* special_function */
369 "R_PPC64_GOT16", /* name */
370 false, /* partial_inplace */
371 0, /* src_mask */
372 0xffff, /* dst_mask */
373 false), /* pcrel_offset */
374
375 /* Like R_PPC64_ADDR16_LO, but referring to the GOT table entry for
376 the symbol. */
377 HOWTO (R_PPC64_GOT16_LO, /* 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_dont, /* complain_on_overflow */
384 ppc64_elf_unhandled_reloc, /* special_function */
385 "R_PPC64_GOT16_LO", /* name */
386 false, /* partial_inplace */
387 0, /* src_mask */
388 0xffff, /* dst_mask */
389 false), /* pcrel_offset */
390
391 /* Like R_PPC64_ADDR16_HI, but referring to the GOT table entry for
392 the symbol. */
393 HOWTO (R_PPC64_GOT16_HI, /* type */
394 16, /* 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 ppc64_elf_unhandled_reloc, /* special_function */
401 "R_PPC64_GOT16_HI", /* name */
402 false, /* partial_inplace */
403 0, /* src_mask */
404 0xffff, /* dst_mask */
405 false), /* pcrel_offset */
406
407 /* Like R_PPC64_ADDR16_HA, but referring to the GOT table entry for
408 the symbol. */
409 HOWTO (R_PPC64_GOT16_HA, /* 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 ppc64_elf_unhandled_reloc, /* special_function */
417 "R_PPC64_GOT16_HA", /* name */
418 false, /* partial_inplace */
419 0, /* src_mask */
420 0xffff, /* dst_mask */
421 false), /* pcrel_offset */
422
423 /* This is used only by the dynamic linker. The symbol should exist
424 both in the object being run and in some shared library. The
425 dynamic linker copies the data addressed by the symbol from the
426 shared library into the object, because the object being
427 run has to have the data at some particular address. */
428 HOWTO (R_PPC64_COPY, /* type */
429 0, /* rightshift */
430 2, /* size (0 = byte, 1 = short, 2 = long) */
431 32, /* bitsize */
432 false, /* pc_relative */
433 0, /* bitpos */
434 complain_overflow_bitfield, /* complain_on_overflow */
435 ppc64_elf_unhandled_reloc, /* special_function */
436 "R_PPC64_COPY", /* name */
437 false, /* partial_inplace */
438 0, /* src_mask */
439 0, /* dst_mask */
440 false), /* pcrel_offset */
441
442 /* Like R_PPC64_ADDR64, but used when setting global offset table
443 entries. */
444 HOWTO (R_PPC64_GLOB_DAT, /* type */
445 0, /* rightshift */
446 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
447 64, /* bitsize */
448 false, /* pc_relative */
449 0, /* bitpos */
450 complain_overflow_dont, /* complain_on_overflow */
451 ppc64_elf_unhandled_reloc, /* special_function */
452 "R_PPC64_GLOB_DAT", /* name */
453 false, /* partial_inplace */
454 0, /* src_mask */
455 0xffffffffffffffff, /* dst_mask */
456 false), /* pcrel_offset */
457
458 /* Created by the link editor. Marks a procedure linkage table
459 entry for a symbol. */
460 HOWTO (R_PPC64_JMP_SLOT, /* type */
461 0, /* rightshift */
462 0, /* size (0 = byte, 1 = short, 2 = long) */
463 0, /* bitsize */
464 false, /* pc_relative */
465 0, /* bitpos */
466 complain_overflow_dont, /* complain_on_overflow */
467 ppc64_elf_unhandled_reloc, /* special_function */
468 "R_PPC64_JMP_SLOT", /* name */
469 false, /* partial_inplace */
470 0, /* src_mask */
471 0, /* dst_mask */
472 false), /* pcrel_offset */
473
474 /* Used only by the dynamic linker. When the object is run, this
475 doubleword64 is set to the load address of the object, plus the
476 addend. */
477 HOWTO (R_PPC64_RELATIVE, /* type */
478 0, /* rightshift */
479 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
480 64, /* bitsize */
481 false, /* pc_relative */
482 0, /* bitpos */
483 complain_overflow_dont, /* complain_on_overflow */
484 bfd_elf_generic_reloc, /* special_function */
485 "R_PPC64_RELATIVE", /* name */
486 false, /* partial_inplace */
487 0, /* src_mask */
488 0xffffffffffffffff, /* dst_mask */
489 false), /* pcrel_offset */
490
491 /* Like R_PPC64_ADDR32, but may be unaligned. */
492 HOWTO (R_PPC64_UADDR32, /* type */
493 0, /* rightshift */
494 2, /* size (0 = byte, 1 = short, 2 = long) */
495 32, /* bitsize */
496 false, /* pc_relative */
497 0, /* bitpos */
498 complain_overflow_bitfield, /* complain_on_overflow */
499 bfd_elf_generic_reloc, /* special_function */
500 "R_PPC64_UADDR32", /* name */
501 false, /* partial_inplace */
502 0, /* src_mask */
503 0xffffffff, /* dst_mask */
504 false), /* pcrel_offset */
505
506 /* Like R_PPC64_ADDR16, but may be unaligned. */
507 HOWTO (R_PPC64_UADDR16, /* type */
508 0, /* rightshift */
509 1, /* size (0 = byte, 1 = short, 2 = long) */
510 16, /* bitsize */
511 false, /* pc_relative */
512 0, /* bitpos */
513 complain_overflow_bitfield, /* complain_on_overflow */
514 bfd_elf_generic_reloc, /* special_function */
515 "R_PPC64_UADDR16", /* name */
516 false, /* partial_inplace */
517 0, /* src_mask */
518 0xffff, /* dst_mask */
519 false), /* pcrel_offset */
520
521 /* 32-bit PC relative. */
522 HOWTO (R_PPC64_REL32, /* type */
523 0, /* rightshift */
524 2, /* size (0 = byte, 1 = short, 2 = long) */
525 32, /* bitsize */
526 true, /* pc_relative */
527 0, /* bitpos */
528 /* FIXME: Verify. Was complain_overflow_bitfield. */
529 complain_overflow_signed, /* complain_on_overflow */
530 bfd_elf_generic_reloc, /* special_function */
531 "R_PPC64_REL32", /* name */
532 false, /* partial_inplace */
533 0, /* src_mask */
534 0xffffffff, /* dst_mask */
535 true), /* pcrel_offset */
536
537 /* 32-bit relocation to the symbol's procedure linkage table. */
538 HOWTO (R_PPC64_PLT32, /* type */
539 0, /* rightshift */
540 2, /* size (0 = byte, 1 = short, 2 = long) */
541 32, /* bitsize */
542 false, /* pc_relative */
543 0, /* bitpos */
544 complain_overflow_bitfield, /* complain_on_overflow */
545 ppc64_elf_unhandled_reloc, /* special_function */
546 "R_PPC64_PLT32", /* name */
547 false, /* partial_inplace */
548 0, /* src_mask */
549 0, /* dst_mask */
550 false), /* pcrel_offset */
551
552 /* 32-bit PC relative relocation to the symbol's procedure linkage table.
553 FIXME: R_PPC64_PLTREL32 not supported. */
554 HOWTO (R_PPC64_PLTREL32, /* type */
555 0, /* rightshift */
556 2, /* size (0 = byte, 1 = short, 2 = long) */
557 32, /* bitsize */
558 true, /* pc_relative */
559 0, /* bitpos */
560 complain_overflow_signed, /* complain_on_overflow */
561 bfd_elf_generic_reloc, /* special_function */
562 "R_PPC64_PLTREL32", /* name */
563 false, /* partial_inplace */
564 0, /* src_mask */
565 0, /* dst_mask */
566 true), /* pcrel_offset */
567
568 /* Like R_PPC64_ADDR16_LO, but referring to the PLT table entry for
569 the symbol. */
570 HOWTO (R_PPC64_PLT16_LO, /* type */
571 0, /* rightshift */
572 1, /* size (0 = byte, 1 = short, 2 = long) */
573 16, /* bitsize */
574 false, /* pc_relative */
575 0, /* bitpos */
576 complain_overflow_dont, /* complain_on_overflow */
577 ppc64_elf_unhandled_reloc, /* special_function */
578 "R_PPC64_PLT16_LO", /* name */
579 false, /* partial_inplace */
580 0, /* src_mask */
581 0xffff, /* dst_mask */
582 false), /* pcrel_offset */
583
584 /* Like R_PPC64_ADDR16_HI, but referring to the PLT table entry for
585 the symbol. */
586 HOWTO (R_PPC64_PLT16_HI, /* type */
587 16, /* rightshift */
588 1, /* size (0 = byte, 1 = short, 2 = long) */
589 16, /* bitsize */
590 false, /* pc_relative */
591 0, /* bitpos */
592 complain_overflow_dont, /* complain_on_overflow */
593 ppc64_elf_unhandled_reloc, /* special_function */
594 "R_PPC64_PLT16_HI", /* name */
595 false, /* partial_inplace */
596 0, /* src_mask */
597 0xffff, /* dst_mask */
598 false), /* pcrel_offset */
599
600 /* Like R_PPC64_ADDR16_HA, but referring to the PLT table entry for
601 the symbol. */
602 HOWTO (R_PPC64_PLT16_HA, /* type */
603 16, /* rightshift */
604 1, /* size (0 = byte, 1 = short, 2 = long) */
605 16, /* bitsize */
606 false, /* pc_relative */
607 0, /* bitpos */
608 complain_overflow_dont, /* complain_on_overflow */
609 ppc64_elf_unhandled_reloc, /* special_function */
610 "R_PPC64_PLT16_HA", /* name */
611 false, /* partial_inplace */
612 0, /* src_mask */
613 0xffff, /* dst_mask */
614 false), /* pcrel_offset */
615
616 /* 16-bit section relative relocation. */
617 HOWTO (R_PPC64_SECTOFF, /* type */
618 0, /* rightshift */
619 1, /* size (0 = byte, 1 = short, 2 = long) */
620 16, /* bitsize */
621 false, /* pc_relative */
622 0, /* bitpos */
623 complain_overflow_bitfield, /* complain_on_overflow */
624 ppc64_elf_sectoff_reloc, /* special_function */
625 "R_PPC64_SECTOFF", /* name */
626 false, /* partial_inplace */
627 0, /* src_mask */
628 0xffff, /* dst_mask */
629 false), /* pcrel_offset */
630
631 /* Like R_PPC64_SECTOFF, but no overflow warning. */
632 HOWTO (R_PPC64_SECTOFF_LO, /* type */
633 0, /* rightshift */
634 1, /* size (0 = byte, 1 = short, 2 = long) */
635 16, /* bitsize */
636 false, /* pc_relative */
637 0, /* bitpos */
638 complain_overflow_dont, /* complain_on_overflow */
639 ppc64_elf_sectoff_reloc, /* special_function */
640 "R_PPC64_SECTOFF_LO", /* name */
641 false, /* partial_inplace */
642 0, /* src_mask */
643 0xffff, /* dst_mask */
644 false), /* pcrel_offset */
645
646 /* 16-bit upper half section relative relocation. */
647 HOWTO (R_PPC64_SECTOFF_HI, /* type */
648 16, /* rightshift */
649 1, /* size (0 = byte, 1 = short, 2 = long) */
650 16, /* bitsize */
651 false, /* pc_relative */
652 0, /* bitpos */
653 complain_overflow_dont, /* complain_on_overflow */
654 ppc64_elf_sectoff_reloc, /* special_function */
655 "R_PPC64_SECTOFF_HI", /* name */
656 false, /* partial_inplace */
657 0, /* src_mask */
658 0xffff, /* dst_mask */
659 false), /* pcrel_offset */
660
661 /* 16-bit upper half adjusted section relative relocation. */
662 HOWTO (R_PPC64_SECTOFF_HA, /* type */
663 16, /* rightshift */
664 1, /* size (0 = byte, 1 = short, 2 = long) */
665 16, /* bitsize */
666 false, /* pc_relative */
667 0, /* bitpos */
668 complain_overflow_dont, /* complain_on_overflow */
669 ppc64_elf_sectoff_ha_reloc, /* special_function */
670 "R_PPC64_SECTOFF_HA", /* name */
671 false, /* partial_inplace */
672 0, /* src_mask */
673 0xffff, /* dst_mask */
674 false), /* pcrel_offset */
675
676 /* Like R_PPC64_REL24 without touching the two least significant
677 bits. Should have been named R_PPC64_REL30! */
678 HOWTO (R_PPC64_ADDR30, /* type */
679 2, /* rightshift */
680 2, /* size (0 = byte, 1 = short, 2 = long) */
681 30, /* bitsize */
682 true, /* pc_relative */
683 0, /* bitpos */
684 complain_overflow_dont, /* complain_on_overflow */
685 bfd_elf_generic_reloc, /* special_function */
686 "R_PPC64_ADDR30", /* name */
687 false, /* partial_inplace */
688 0, /* src_mask */
689 0xfffffffc, /* dst_mask */
690 true), /* pcrel_offset */
691
692 /* Relocs in the 64-bit PowerPC ELF ABI, not in the 32-bit ABI. */
693
694 /* A standard 64-bit relocation. */
695 HOWTO (R_PPC64_ADDR64, /* type */
696 0, /* rightshift */
697 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
698 64, /* bitsize */
699 false, /* pc_relative */
700 0, /* bitpos */
701 complain_overflow_dont, /* complain_on_overflow */
702 bfd_elf_generic_reloc, /* special_function */
703 "R_PPC64_ADDR64", /* name */
704 false, /* partial_inplace */
705 0, /* src_mask */
706 0xffffffffffffffff, /* dst_mask */
707 false), /* pcrel_offset */
708
709 /* The bits 32-47 of an address. */
710 HOWTO (R_PPC64_ADDR16_HIGHER, /* type */
711 32, /* rightshift */
712 1, /* size (0 = byte, 1 = short, 2 = long) */
713 16, /* bitsize */
714 false, /* pc_relative */
715 0, /* bitpos */
716 complain_overflow_dont, /* complain_on_overflow */
717 bfd_elf_generic_reloc, /* special_function */
718 "R_PPC64_ADDR16_HIGHER", /* name */
719 false, /* partial_inplace */
720 0, /* src_mask */
721 0xffff, /* dst_mask */
722 false), /* pcrel_offset */
723
724 /* The bits 32-47 of an address, plus 1 if the contents of the low
725 16 bits, treated as a signed number, is negative. */
726 HOWTO (R_PPC64_ADDR16_HIGHERA, /* type */
727 32, /* rightshift */
728 1, /* size (0 = byte, 1 = short, 2 = long) */
729 16, /* bitsize */
730 false, /* pc_relative */
731 0, /* bitpos */
732 complain_overflow_dont, /* complain_on_overflow */
733 ppc64_elf_ha_reloc, /* special_function */
734 "R_PPC64_ADDR16_HIGHERA", /* name */
735 false, /* partial_inplace */
736 0, /* src_mask */
737 0xffff, /* dst_mask */
738 false), /* pcrel_offset */
739
740 /* The bits 48-63 of an address. */
741 HOWTO (R_PPC64_ADDR16_HIGHEST,/* type */
742 48, /* rightshift */
743 1, /* size (0 = byte, 1 = short, 2 = long) */
744 16, /* bitsize */
745 false, /* pc_relative */
746 0, /* bitpos */
747 complain_overflow_dont, /* complain_on_overflow */
748 bfd_elf_generic_reloc, /* special_function */
749 "R_PPC64_ADDR16_HIGHEST", /* name */
750 false, /* partial_inplace */
751 0, /* src_mask */
752 0xffff, /* dst_mask */
753 false), /* pcrel_offset */
754
755 /* The bits 48-63 of an address, plus 1 if the contents of the low
756 16 bits, treated as a signed number, is negative. */
757 HOWTO (R_PPC64_ADDR16_HIGHESTA,/* type */
758 48, /* rightshift */
759 1, /* size (0 = byte, 1 = short, 2 = long) */
760 16, /* bitsize */
761 false, /* pc_relative */
762 0, /* bitpos */
763 complain_overflow_dont, /* complain_on_overflow */
764 ppc64_elf_ha_reloc, /* special_function */
765 "R_PPC64_ADDR16_HIGHESTA", /* name */
766 false, /* partial_inplace */
767 0, /* src_mask */
768 0xffff, /* dst_mask */
769 false), /* pcrel_offset */
770
771 /* Like ADDR64, but may be unaligned. */
772 HOWTO (R_PPC64_UADDR64, /* type */
773 0, /* rightshift */
774 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
775 64, /* bitsize */
776 false, /* pc_relative */
777 0, /* bitpos */
778 complain_overflow_dont, /* complain_on_overflow */
779 bfd_elf_generic_reloc, /* special_function */
780 "R_PPC64_UADDR64", /* name */
781 false, /* partial_inplace */
782 0, /* src_mask */
783 0xffffffffffffffff, /* dst_mask */
784 false), /* pcrel_offset */
785
786 /* 64-bit relative relocation. */
787 HOWTO (R_PPC64_REL64, /* type */
788 0, /* rightshift */
789 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
790 64, /* bitsize */
791 true, /* pc_relative */
792 0, /* bitpos */
793 complain_overflow_dont, /* complain_on_overflow */
794 bfd_elf_generic_reloc, /* special_function */
795 "R_PPC64_REL64", /* name */
796 false, /* partial_inplace */
797 0, /* src_mask */
798 0xffffffffffffffff, /* dst_mask */
799 true), /* pcrel_offset */
800
801 /* 64-bit relocation to the symbol's procedure linkage table. */
802 HOWTO (R_PPC64_PLT64, /* type */
803 0, /* rightshift */
804 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
805 64, /* bitsize */
806 false, /* pc_relative */
807 0, /* bitpos */
808 complain_overflow_dont, /* complain_on_overflow */
809 ppc64_elf_unhandled_reloc, /* special_function */
810 "R_PPC64_PLT64", /* name */
811 false, /* partial_inplace */
812 0, /* src_mask */
813 0, /* dst_mask */
814 false), /* pcrel_offset */
815
816 /* 64-bit PC relative relocation to the symbol's procedure linkage
817 table. */
818 /* FIXME: R_PPC64_PLTREL64 not supported. */
819 HOWTO (R_PPC64_PLTREL64, /* type */
820 0, /* rightshift */
821 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
822 64, /* bitsize */
823 true, /* pc_relative */
824 0, /* bitpos */
825 complain_overflow_dont, /* complain_on_overflow */
826 ppc64_elf_unhandled_reloc, /* special_function */
827 "R_PPC64_PLTREL64", /* name */
828 false, /* partial_inplace */
829 0, /* src_mask */
830 0, /* dst_mask */
831 true), /* pcrel_offset */
832
833 /* 16 bit TOC-relative relocation. */
834
835 /* R_PPC64_TOC16 47 half16* S + A - .TOC. */
836 HOWTO (R_PPC64_TOC16, /* type */
837 0, /* rightshift */
838 1, /* size (0 = byte, 1 = short, 2 = long) */
839 16, /* bitsize */
840 false, /* pc_relative */
841 0, /* bitpos */
842 complain_overflow_signed, /* complain_on_overflow */
843 ppc64_elf_toc_reloc, /* special_function */
844 "R_PPC64_TOC16", /* name */
845 false, /* partial_inplace */
846 0, /* src_mask */
847 0xffff, /* dst_mask */
848 false), /* pcrel_offset */
849
850 /* 16 bit TOC-relative relocation without overflow. */
851
852 /* R_PPC64_TOC16_LO 48 half16 #lo (S + A - .TOC.) */
853 HOWTO (R_PPC64_TOC16_LO, /* type */
854 0, /* rightshift */
855 1, /* size (0 = byte, 1 = short, 2 = long) */
856 16, /* bitsize */
857 false, /* pc_relative */
858 0, /* bitpos */
859 complain_overflow_dont, /* complain_on_overflow */
860 ppc64_elf_toc_reloc, /* special_function */
861 "R_PPC64_TOC16_LO", /* name */
862 false, /* partial_inplace */
863 0, /* src_mask */
864 0xffff, /* dst_mask */
865 false), /* pcrel_offset */
866
867 /* 16 bit TOC-relative relocation, high 16 bits. */
868
869 /* R_PPC64_TOC16_HI 49 half16 #hi (S + A - .TOC.) */
870 HOWTO (R_PPC64_TOC16_HI, /* type */
871 16, /* rightshift */
872 1, /* size (0 = byte, 1 = short, 2 = long) */
873 16, /* bitsize */
874 false, /* pc_relative */
875 0, /* bitpos */
876 complain_overflow_dont, /* complain_on_overflow */
877 ppc64_elf_toc_reloc, /* special_function */
878 "R_PPC64_TOC16_HI", /* name */
879 false, /* partial_inplace */
880 0, /* src_mask */
881 0xffff, /* dst_mask */
882 false), /* pcrel_offset */
883
884 /* 16 bit TOC-relative relocation, high 16 bits, plus 1 if the
885 contents of the low 16 bits, treated as a signed number, is
886 negative. */
887
888 /* R_PPC64_TOC16_HA 50 half16 #ha (S + A - .TOC.) */
889 HOWTO (R_PPC64_TOC16_HA, /* type */
890 16, /* rightshift */
891 1, /* size (0 = byte, 1 = short, 2 = long) */
892 16, /* bitsize */
893 false, /* pc_relative */
894 0, /* bitpos */
895 complain_overflow_dont, /* complain_on_overflow */
896 ppc64_elf_toc_ha_reloc, /* special_function */
897 "R_PPC64_TOC16_HA", /* name */
898 false, /* partial_inplace */
899 0, /* src_mask */
900 0xffff, /* dst_mask */
901 false), /* pcrel_offset */
902
903 /* 64-bit relocation; insert value of TOC base (.TOC.). */
904
905 /* R_PPC64_TOC 51 doubleword64 .TOC. */
906 HOWTO (R_PPC64_TOC, /* type */
907 0, /* rightshift */
908 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
909 64, /* bitsize */
910 false, /* pc_relative */
911 0, /* bitpos */
912 complain_overflow_bitfield, /* complain_on_overflow */
913 ppc64_elf_toc64_reloc, /* special_function */
914 "R_PPC64_TOC", /* name */
915 false, /* partial_inplace */
916 0, /* src_mask */
917 0xffffffffffffffff, /* dst_mask */
918 false), /* pcrel_offset */
919
920 /* Like R_PPC64_GOT16, but also informs the link editor that the
921 value to relocate may (!) refer to a PLT entry which the link
922 editor (a) may replace with the symbol value. If the link editor
923 is unable to fully resolve the symbol, it may (b) create a PLT
924 entry and store the address to the new PLT entry in the GOT.
925 This permits lazy resolution of function symbols at run time.
926 The link editor may also skip all of this and just (c) emit a
927 R_PPC64_GLOB_DAT to tie the symbol to the GOT entry. */
928 /* FIXME: R_PPC64_PLTGOT16 not implemented. */
929 HOWTO (R_PPC64_PLTGOT16, /* type */
930 0, /* rightshift */
931 1, /* size (0 = byte, 1 = short, 2 = long) */
932 16, /* bitsize */
933 false, /* pc_relative */
934 0, /* bitpos */
935 complain_overflow_signed, /* complain_on_overflow */
936 ppc64_elf_unhandled_reloc, /* special_function */
937 "R_PPC64_PLTGOT16", /* name */
938 false, /* partial_inplace */
939 0, /* src_mask */
940 0xffff, /* dst_mask */
941 false), /* pcrel_offset */
942
943 /* Like R_PPC64_PLTGOT16, but without overflow. */
944 /* FIXME: R_PPC64_PLTGOT16_LO not implemented. */
945 HOWTO (R_PPC64_PLTGOT16_LO, /* type */
946 0, /* rightshift */
947 1, /* size (0 = byte, 1 = short, 2 = long) */
948 16, /* bitsize */
949 false, /* pc_relative */
950 0, /* bitpos */
951 complain_overflow_dont, /* complain_on_overflow */
952 ppc64_elf_unhandled_reloc, /* special_function */
953 "R_PPC64_PLTGOT16_LO", /* name */
954 false, /* partial_inplace */
955 0, /* src_mask */
956 0xffff, /* dst_mask */
957 false), /* pcrel_offset */
958
959 /* Like R_PPC64_PLT_GOT16, but using bits 16-31 of the address. */
960 /* FIXME: R_PPC64_PLTGOT16_HI not implemented. */
961 HOWTO (R_PPC64_PLTGOT16_HI, /* type */
962 16, /* rightshift */
963 1, /* size (0 = byte, 1 = short, 2 = long) */
964 16, /* bitsize */
965 false, /* pc_relative */
966 0, /* bitpos */
967 complain_overflow_dont, /* complain_on_overflow */
968 ppc64_elf_unhandled_reloc, /* special_function */
969 "R_PPC64_PLTGOT16_HI", /* name */
970 false, /* partial_inplace */
971 0, /* src_mask */
972 0xffff, /* dst_mask */
973 false), /* pcrel_offset */
974
975 /* Like R_PPC64_PLT_GOT16, but using bits 16-31 of the address, plus
976 1 if the contents of the low 16 bits, treated as a signed number,
977 is negative. */
978 /* FIXME: R_PPC64_PLTGOT16_HA not implemented. */
979 HOWTO (R_PPC64_PLTGOT16_HA, /* type */
980 16, /* rightshift */
981 1, /* size (0 = byte, 1 = short, 2 = long) */
982 16, /* bitsize */
983 false, /* pc_relative */
984 0, /* bitpos */
985 complain_overflow_dont,/* complain_on_overflow */
986 ppc64_elf_unhandled_reloc, /* special_function */
987 "R_PPC64_PLTGOT16_HA", /* name */
988 false, /* partial_inplace */
989 0, /* src_mask */
990 0xffff, /* dst_mask */
991 false), /* pcrel_offset */
992
993 /* Like R_PPC64_ADDR16, but for instructions with a DS field. */
994 HOWTO (R_PPC64_ADDR16_DS, /* type */
995 0, /* rightshift */
996 1, /* size (0 = byte, 1 = short, 2 = long) */
997 16, /* bitsize */
998 false, /* pc_relative */
999 0, /* bitpos */
1000 complain_overflow_bitfield, /* complain_on_overflow */
1001 bfd_elf_generic_reloc, /* special_function */
1002 "R_PPC64_ADDR16_DS", /* name */
1003 false, /* partial_inplace */
1004 0, /* src_mask */
1005 0xfffc, /* dst_mask */
1006 false), /* pcrel_offset */
1007
1008 /* Like R_PPC64_ADDR16_LO, but for instructions with a DS field. */
1009 HOWTO (R_PPC64_ADDR16_LO_DS, /* type */
1010 0, /* rightshift */
1011 1, /* size (0 = byte, 1 = short, 2 = long) */
1012 16, /* bitsize */
1013 false, /* pc_relative */
1014 0, /* bitpos */
1015 complain_overflow_dont,/* complain_on_overflow */
1016 bfd_elf_generic_reloc, /* special_function */
1017 "R_PPC64_ADDR16_LO_DS",/* name */
1018 false, /* partial_inplace */
1019 0, /* src_mask */
1020 0xfffc, /* dst_mask */
1021 false), /* pcrel_offset */
1022
1023 /* Like R_PPC64_GOT16, but for instructions with a DS field. */
1024 HOWTO (R_PPC64_GOT16_DS, /* type */
1025 0, /* rightshift */
1026 1, /* size (0 = byte, 1 = short, 2 = long) */
1027 16, /* bitsize */
1028 false, /* pc_relative */
1029 0, /* bitpos */
1030 complain_overflow_signed, /* complain_on_overflow */
1031 ppc64_elf_unhandled_reloc, /* special_function */
1032 "R_PPC64_GOT16_DS", /* name */
1033 false, /* partial_inplace */
1034 0, /* src_mask */
1035 0xfffc, /* dst_mask */
1036 false), /* pcrel_offset */
1037
1038 /* Like R_PPC64_GOT16_LO, but for instructions with a DS field. */
1039 HOWTO (R_PPC64_GOT16_LO_DS, /* type */
1040 0, /* rightshift */
1041 1, /* size (0 = byte, 1 = short, 2 = long) */
1042 16, /* bitsize */
1043 false, /* pc_relative */
1044 0, /* bitpos */
1045 complain_overflow_dont, /* complain_on_overflow */
1046 ppc64_elf_unhandled_reloc, /* special_function */
1047 "R_PPC64_GOT16_LO_DS", /* name */
1048 false, /* partial_inplace */
1049 0, /* src_mask */
1050 0xfffc, /* dst_mask */
1051 false), /* pcrel_offset */
1052
1053 /* Like R_PPC64_PLT16_LO, but for instructions with a DS field. */
1054 HOWTO (R_PPC64_PLT16_LO_DS, /* type */
1055 0, /* rightshift */
1056 1, /* size (0 = byte, 1 = short, 2 = long) */
1057 16, /* bitsize */
1058 false, /* pc_relative */
1059 0, /* bitpos */
1060 complain_overflow_dont, /* complain_on_overflow */
1061 ppc64_elf_unhandled_reloc, /* special_function */
1062 "R_PPC64_PLT16_LO_DS", /* name */
1063 false, /* partial_inplace */
1064 0, /* src_mask */
1065 0xfffc, /* dst_mask */
1066 false), /* pcrel_offset */
1067
1068 /* Like R_PPC64_SECTOFF, but for instructions with a DS field. */
1069 HOWTO (R_PPC64_SECTOFF_DS, /* type */
1070 0, /* rightshift */
1071 1, /* size (0 = byte, 1 = short, 2 = long) */
1072 16, /* bitsize */
1073 false, /* pc_relative */
1074 0, /* bitpos */
1075 complain_overflow_bitfield, /* complain_on_overflow */
1076 ppc64_elf_sectoff_reloc, /* special_function */
1077 "R_PPC64_SECTOFF_DS", /* name */
1078 false, /* partial_inplace */
1079 0, /* src_mask */
1080 0xfffc, /* dst_mask */
1081 false), /* pcrel_offset */
1082
1083 /* Like R_PPC64_SECTOFF_LO, but for instructions with a DS field. */
1084 HOWTO (R_PPC64_SECTOFF_LO_DS, /* type */
1085 0, /* rightshift */
1086 1, /* size (0 = byte, 1 = short, 2 = long) */
1087 16, /* bitsize */
1088 false, /* pc_relative */
1089 0, /* bitpos */
1090 complain_overflow_dont, /* complain_on_overflow */
1091 ppc64_elf_sectoff_reloc, /* special_function */
1092 "R_PPC64_SECTOFF_LO_DS",/* name */
1093 false, /* partial_inplace */
1094 0, /* src_mask */
1095 0xfffc, /* dst_mask */
1096 false), /* pcrel_offset */
1097
1098 /* Like R_PPC64_TOC16, but for instructions with a DS field. */
1099 HOWTO (R_PPC64_TOC16_DS, /* type */
1100 0, /* rightshift */
1101 1, /* size (0 = byte, 1 = short, 2 = long) */
1102 16, /* bitsize */
1103 false, /* pc_relative */
1104 0, /* bitpos */
1105 complain_overflow_signed, /* complain_on_overflow */
1106 ppc64_elf_toc_reloc, /* special_function */
1107 "R_PPC64_TOC16_DS", /* name */
1108 false, /* partial_inplace */
1109 0, /* src_mask */
1110 0xfffc, /* dst_mask */
1111 false), /* pcrel_offset */
1112
1113 /* Like R_PPC64_TOC16_LO, but for instructions with a DS field. */
1114 HOWTO (R_PPC64_TOC16_LO_DS, /* type */
1115 0, /* rightshift */
1116 1, /* size (0 = byte, 1 = short, 2 = long) */
1117 16, /* bitsize */
1118 false, /* pc_relative */
1119 0, /* bitpos */
1120 complain_overflow_dont, /* complain_on_overflow */
1121 ppc64_elf_toc_reloc, /* special_function */
1122 "R_PPC64_TOC16_LO_DS", /* name */
1123 false, /* partial_inplace */
1124 0, /* src_mask */
1125 0xfffc, /* dst_mask */
1126 false), /* pcrel_offset */
1127
1128 /* Like R_PPC64_PLTGOT16, but for instructions with a DS field. */
1129 /* FIXME: R_PPC64_PLTGOT16_DS not implemented. */
1130 HOWTO (R_PPC64_PLTGOT16_DS, /* type */
1131 0, /* rightshift */
1132 1, /* size (0 = byte, 1 = short, 2 = long) */
1133 16, /* bitsize */
1134 false, /* pc_relative */
1135 0, /* bitpos */
1136 complain_overflow_signed, /* complain_on_overflow */
1137 ppc64_elf_unhandled_reloc, /* special_function */
1138 "R_PPC64_PLTGOT16_DS", /* name */
1139 false, /* partial_inplace */
1140 0, /* src_mask */
1141 0xfffc, /* dst_mask */
1142 false), /* pcrel_offset */
1143
1144 /* Like R_PPC64_PLTGOT16_LO, but for instructions with a DS field. */
1145 /* FIXME: R_PPC64_PLTGOT16_LO not implemented. */
1146 HOWTO (R_PPC64_PLTGOT16_LO_DS,/* type */
1147 0, /* rightshift */
1148 1, /* size (0 = byte, 1 = short, 2 = long) */
1149 16, /* bitsize */
1150 false, /* pc_relative */
1151 0, /* bitpos */
1152 complain_overflow_dont, /* complain_on_overflow */
1153 ppc64_elf_unhandled_reloc, /* special_function */
1154 "R_PPC64_PLTGOT16_LO_DS",/* name */
1155 false, /* partial_inplace */
1156 0, /* src_mask */
1157 0xfffc, /* dst_mask */
1158 false), /* pcrel_offset */
1159
1160 /* GNU extension to record C++ vtable hierarchy. */
1161 HOWTO (R_PPC64_GNU_VTINHERIT, /* type */
1162 0, /* rightshift */
1163 0, /* size (0 = byte, 1 = short, 2 = long) */
1164 0, /* bitsize */
1165 false, /* pc_relative */
1166 0, /* bitpos */
1167 complain_overflow_dont, /* complain_on_overflow */
1168 NULL, /* special_function */
1169 "R_PPC64_GNU_VTINHERIT", /* name */
1170 false, /* partial_inplace */
1171 0, /* src_mask */
1172 0, /* dst_mask */
1173 false), /* pcrel_offset */
1174
1175 /* GNU extension to record C++ vtable member usage. */
1176 HOWTO (R_PPC64_GNU_VTENTRY, /* type */
1177 0, /* rightshift */
1178 0, /* size (0 = byte, 1 = short, 2 = long) */
1179 0, /* bitsize */
1180 false, /* pc_relative */
1181 0, /* bitpos */
1182 complain_overflow_dont, /* complain_on_overflow */
1183 NULL, /* special_function */
1184 "R_PPC64_GNU_VTENTRY", /* name */
1185 false, /* partial_inplace */
1186 0, /* src_mask */
1187 0, /* dst_mask */
1188 false), /* pcrel_offset */
1189 };
1190
1191 \f
1192 /* Initialize the ppc64_elf_howto_table, so that linear accesses can
1193 be done. */
1194
1195 static void
1196 ppc_howto_init ()
1197 {
1198 unsigned int i, type;
1199
1200 for (i = 0;
1201 i < sizeof (ppc64_elf_howto_raw) / sizeof (ppc64_elf_howto_raw[0]);
1202 i++)
1203 {
1204 type = ppc64_elf_howto_raw[i].type;
1205 BFD_ASSERT (type < (sizeof (ppc64_elf_howto_table)
1206 / sizeof (ppc64_elf_howto_table[0])));
1207 ppc64_elf_howto_table[type] = &ppc64_elf_howto_raw[i];
1208 }
1209 }
1210
1211 static reloc_howto_type *
1212 ppc64_elf_reloc_type_lookup (abfd, code)
1213 bfd *abfd ATTRIBUTE_UNUSED;
1214 bfd_reloc_code_real_type code;
1215 {
1216 enum elf_ppc_reloc_type ppc_reloc = R_PPC_NONE;
1217
1218 if (!ppc64_elf_howto_table[R_PPC64_ADDR32])
1219 /* Initialize howto table if needed. */
1220 ppc_howto_init ();
1221
1222 switch ((int) code)
1223 {
1224 default:
1225 return (reloc_howto_type *) NULL;
1226
1227 case BFD_RELOC_NONE: ppc_reloc = R_PPC64_NONE;
1228 break;
1229 case BFD_RELOC_32: ppc_reloc = R_PPC64_ADDR32;
1230 break;
1231 case BFD_RELOC_PPC_BA26: ppc_reloc = R_PPC64_ADDR24;
1232 break;
1233 case BFD_RELOC_16: ppc_reloc = R_PPC64_ADDR16;
1234 break;
1235 case BFD_RELOC_LO16: ppc_reloc = R_PPC64_ADDR16_LO;
1236 break;
1237 case BFD_RELOC_HI16: ppc_reloc = R_PPC64_ADDR16_HI;
1238 break;
1239 case BFD_RELOC_HI16_S: ppc_reloc = R_PPC64_ADDR16_HA;
1240 break;
1241 case BFD_RELOC_PPC_BA16: ppc_reloc = R_PPC64_ADDR14;
1242 break;
1243 case BFD_RELOC_PPC_BA16_BRTAKEN: ppc_reloc = R_PPC64_ADDR14_BRTAKEN;
1244 break;
1245 case BFD_RELOC_PPC_BA16_BRNTAKEN: ppc_reloc = R_PPC64_ADDR14_BRNTAKEN;
1246 break;
1247 case BFD_RELOC_PPC_B26: ppc_reloc = R_PPC64_REL24;
1248 break;
1249 case BFD_RELOC_PPC_B16: ppc_reloc = R_PPC64_REL14;
1250 break;
1251 case BFD_RELOC_PPC_B16_BRTAKEN: ppc_reloc = R_PPC64_REL14_BRTAKEN;
1252 break;
1253 case BFD_RELOC_PPC_B16_BRNTAKEN: ppc_reloc = R_PPC64_REL14_BRNTAKEN;
1254 break;
1255 case BFD_RELOC_16_GOTOFF: ppc_reloc = R_PPC64_GOT16;
1256 break;
1257 case BFD_RELOC_LO16_GOTOFF: ppc_reloc = R_PPC64_GOT16_LO;
1258 break;
1259 case BFD_RELOC_HI16_GOTOFF: ppc_reloc = R_PPC64_GOT16_HI;
1260 break;
1261 case BFD_RELOC_HI16_S_GOTOFF: ppc_reloc = R_PPC64_GOT16_HA;
1262 break;
1263 case BFD_RELOC_PPC_COPY: ppc_reloc = R_PPC64_COPY;
1264 break;
1265 case BFD_RELOC_PPC_GLOB_DAT: ppc_reloc = R_PPC64_GLOB_DAT;
1266 break;
1267 case BFD_RELOC_32_PCREL: ppc_reloc = R_PPC64_REL32;
1268 break;
1269 case BFD_RELOC_32_PLTOFF: ppc_reloc = R_PPC64_PLT32;
1270 break;
1271 case BFD_RELOC_32_PLT_PCREL: ppc_reloc = R_PPC64_PLTREL32;
1272 break;
1273 case BFD_RELOC_LO16_PLTOFF: ppc_reloc = R_PPC64_PLT16_LO;
1274 break;
1275 case BFD_RELOC_HI16_PLTOFF: ppc_reloc = R_PPC64_PLT16_HI;
1276 break;
1277 case BFD_RELOC_HI16_S_PLTOFF: ppc_reloc = R_PPC64_PLT16_HA;
1278 break;
1279 case BFD_RELOC_16_BASEREL: ppc_reloc = R_PPC64_SECTOFF;
1280 break;
1281 case BFD_RELOC_LO16_BASEREL: ppc_reloc = R_PPC64_SECTOFF_LO;
1282 break;
1283 case BFD_RELOC_HI16_BASEREL: ppc_reloc = R_PPC64_SECTOFF_HI;
1284 break;
1285 case BFD_RELOC_HI16_S_BASEREL: ppc_reloc = R_PPC64_SECTOFF_HA;
1286 break;
1287 case BFD_RELOC_CTOR: ppc_reloc = R_PPC64_ADDR64;
1288 break;
1289 case BFD_RELOC_64: ppc_reloc = R_PPC64_ADDR64;
1290 break;
1291 case BFD_RELOC_PPC64_HIGHER: ppc_reloc = R_PPC64_ADDR16_HIGHER;
1292 break;
1293 case BFD_RELOC_PPC64_HIGHER_S: ppc_reloc = R_PPC64_ADDR16_HIGHERA;
1294 break;
1295 case BFD_RELOC_PPC64_HIGHEST: ppc_reloc = R_PPC64_ADDR16_HIGHEST;
1296 break;
1297 case BFD_RELOC_PPC64_HIGHEST_S: ppc_reloc = R_PPC64_ADDR16_HIGHESTA;
1298 break;
1299 case BFD_RELOC_64_PCREL: ppc_reloc = R_PPC64_REL64;
1300 break;
1301 case BFD_RELOC_64_PLTOFF: ppc_reloc = R_PPC64_PLT64;
1302 break;
1303 case BFD_RELOC_64_PLT_PCREL: ppc_reloc = R_PPC64_PLTREL64;
1304 break;
1305 case BFD_RELOC_PPC_TOC16: ppc_reloc = R_PPC64_TOC16;
1306 break;
1307 case BFD_RELOC_PPC64_TOC16_LO: ppc_reloc = R_PPC64_TOC16_LO;
1308 break;
1309 case BFD_RELOC_PPC64_TOC16_HI: ppc_reloc = R_PPC64_TOC16_HI;
1310 break;
1311 case BFD_RELOC_PPC64_TOC16_HA: ppc_reloc = R_PPC64_TOC16_HA;
1312 break;
1313 case BFD_RELOC_PPC64_TOC: ppc_reloc = R_PPC64_TOC;
1314 break;
1315 case BFD_RELOC_PPC64_PLTGOT16: ppc_reloc = R_PPC64_PLTGOT16;
1316 break;
1317 case BFD_RELOC_PPC64_PLTGOT16_LO: ppc_reloc = R_PPC64_PLTGOT16_LO;
1318 break;
1319 case BFD_RELOC_PPC64_PLTGOT16_HI: ppc_reloc = R_PPC64_PLTGOT16_HI;
1320 break;
1321 case BFD_RELOC_PPC64_PLTGOT16_HA: ppc_reloc = R_PPC64_PLTGOT16_HA;
1322 break;
1323 case BFD_RELOC_PPC64_ADDR16_DS: ppc_reloc = R_PPC64_ADDR16_DS;
1324 break;
1325 case BFD_RELOC_PPC64_ADDR16_LO_DS: ppc_reloc = R_PPC64_ADDR16_LO_DS;
1326 break;
1327 case BFD_RELOC_PPC64_GOT16_DS: ppc_reloc = R_PPC64_GOT16_DS;
1328 break;
1329 case BFD_RELOC_PPC64_GOT16_LO_DS: ppc_reloc = R_PPC64_GOT16_LO_DS;
1330 break;
1331 case BFD_RELOC_PPC64_PLT16_LO_DS: ppc_reloc = R_PPC64_PLT16_LO_DS;
1332 break;
1333 case BFD_RELOC_PPC64_SECTOFF_DS: ppc_reloc = R_PPC64_SECTOFF_DS;
1334 break;
1335 case BFD_RELOC_PPC64_SECTOFF_LO_DS: ppc_reloc = R_PPC64_SECTOFF_LO_DS;
1336 break;
1337 case BFD_RELOC_PPC64_TOC16_DS: ppc_reloc = R_PPC64_TOC16_DS;
1338 break;
1339 case BFD_RELOC_PPC64_TOC16_LO_DS: ppc_reloc = R_PPC64_TOC16_LO_DS;
1340 break;
1341 case BFD_RELOC_PPC64_PLTGOT16_DS: ppc_reloc = R_PPC64_PLTGOT16_DS;
1342 break;
1343 case BFD_RELOC_PPC64_PLTGOT16_LO_DS: ppc_reloc = R_PPC64_PLTGOT16_LO_DS;
1344 break;
1345 case BFD_RELOC_VTABLE_INHERIT: ppc_reloc = R_PPC64_GNU_VTINHERIT;
1346 break;
1347 case BFD_RELOC_VTABLE_ENTRY: ppc_reloc = R_PPC64_GNU_VTENTRY;
1348 break;
1349 }
1350
1351 return ppc64_elf_howto_table[(int) ppc_reloc];
1352 };
1353
1354 /* Set the howto pointer for a PowerPC ELF reloc. */
1355
1356 static void
1357 ppc64_elf_info_to_howto (abfd, cache_ptr, dst)
1358 bfd *abfd ATTRIBUTE_UNUSED;
1359 arelent *cache_ptr;
1360 Elf64_Internal_Rela *dst;
1361 {
1362 unsigned int type;
1363
1364 /* Initialize howto table if needed. */
1365 if (!ppc64_elf_howto_table[R_PPC64_ADDR32])
1366 ppc_howto_init ();
1367
1368 type = ELF64_R_TYPE (dst->r_info);
1369 BFD_ASSERT (type < (sizeof (ppc64_elf_howto_table)
1370 / sizeof (ppc64_elf_howto_table[0])));
1371 cache_ptr->howto = ppc64_elf_howto_table[type];
1372 }
1373
1374 /* Handle the R_PPC_ADDR16_HA and similar relocs. */
1375
1376 static bfd_reloc_status_type
1377 ppc64_elf_ha_reloc (abfd, reloc_entry, symbol, data,
1378 input_section, output_bfd, error_message)
1379 bfd *abfd;
1380 arelent *reloc_entry;
1381 asymbol *symbol;
1382 PTR data;
1383 asection *input_section;
1384 bfd *output_bfd;
1385 char **error_message;
1386 {
1387 /* If this is a relocatable link (output_bfd test tells us), just
1388 call the generic function. Any adjustment will be done at final
1389 link time. */
1390 if (output_bfd != NULL)
1391 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
1392 input_section, output_bfd, error_message);
1393
1394 /* Adjust the addend for sign extension of the low 16 bits.
1395 We won't actually be using the low 16 bits, so trashing them
1396 doesn't matter. */
1397 reloc_entry->addend += 0x8000;
1398 return bfd_reloc_continue;
1399 }
1400
1401 static bfd_reloc_status_type
1402 ppc64_elf_brtaken_reloc (abfd, reloc_entry, symbol, data,
1403 input_section, output_bfd, error_message)
1404 bfd *abfd;
1405 arelent *reloc_entry;
1406 asymbol *symbol;
1407 PTR data;
1408 asection *input_section;
1409 bfd *output_bfd;
1410 char **error_message;
1411 {
1412 long insn;
1413 enum elf_ppc_reloc_type r_type;
1414 bfd_size_type octets;
1415 /* Disabled until we sort out how ld should choose 'y' vs 'at'. */
1416 boolean is_power4 = false;
1417
1418 /* If this is a relocatable link (output_bfd test tells us), just
1419 call the generic function. Any adjustment will be done at final
1420 link time. */
1421 if (output_bfd != NULL)
1422 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
1423 input_section, output_bfd, error_message);
1424
1425 octets = reloc_entry->address * bfd_octets_per_byte (abfd);
1426 insn = bfd_get_32 (abfd, (bfd_byte *) data + octets);
1427 insn &= ~(0x01 << 21);
1428 r_type = (enum elf_ppc_reloc_type) reloc_entry->howto->type;
1429 if (r_type == R_PPC64_ADDR14_BRTAKEN
1430 || r_type == R_PPC64_REL14_BRTAKEN)
1431 insn |= 0x01 << 21; /* 'y' or 't' bit, lowest bit of BO field. */
1432
1433 if (is_power4)
1434 {
1435 /* Set 'a' bit. This is 0b00010 in BO field for branch
1436 on CR(BI) insns (BO == 001at or 011at), and 0b01000
1437 for branch on CTR insns (BO == 1a00t or 1a01t). */
1438 if ((insn & (0x14 << 21)) == (0x04 << 21))
1439 insn |= 0x02 << 21;
1440 else if ((insn & (0x14 << 21)) == (0x10 << 21))
1441 insn |= 0x08 << 21;
1442 else
1443 return bfd_reloc_continue;
1444 }
1445 else
1446 {
1447 bfd_vma target = 0;
1448 bfd_vma from;
1449
1450 if (!bfd_is_com_section (symbol->section))
1451 target = symbol->value;
1452 target += symbol->section->output_section->vma;
1453 target += symbol->section->output_offset;
1454 target += reloc_entry->addend;
1455
1456 from = (reloc_entry->address
1457 + input_section->output_offset
1458 + input_section->output_section->vma);
1459
1460 /* Invert 'y' bit if not the default. */
1461 if ((bfd_signed_vma) (target - from) < 0)
1462 insn ^= 0x01 << 21;
1463 }
1464 bfd_put_32 (abfd, (bfd_vma) insn, (bfd_byte *) data + octets);
1465 return bfd_reloc_continue;
1466 }
1467
1468 static bfd_reloc_status_type
1469 ppc64_elf_sectoff_reloc (abfd, reloc_entry, symbol, data,
1470 input_section, output_bfd, error_message)
1471 bfd *abfd;
1472 arelent *reloc_entry;
1473 asymbol *symbol;
1474 PTR data;
1475 asection *input_section;
1476 bfd *output_bfd;
1477 char **error_message;
1478 {
1479 /* If this is a relocatable link (output_bfd test tells us), just
1480 call the generic function. Any adjustment will be done at final
1481 link time. */
1482 if (output_bfd != NULL)
1483 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
1484 input_section, output_bfd, error_message);
1485
1486 /* Subtract the symbol section base address. */
1487 reloc_entry->addend -= symbol->section->output_section->vma;
1488 return bfd_reloc_continue;
1489 }
1490
1491 static bfd_reloc_status_type
1492 ppc64_elf_sectoff_ha_reloc (abfd, reloc_entry, symbol, data,
1493 input_section, output_bfd, error_message)
1494 bfd *abfd;
1495 arelent *reloc_entry;
1496 asymbol *symbol;
1497 PTR data;
1498 asection *input_section;
1499 bfd *output_bfd;
1500 char **error_message;
1501 {
1502 /* If this is a relocatable link (output_bfd test tells us), just
1503 call the generic function. Any adjustment will be done at final
1504 link time. */
1505 if (output_bfd != NULL)
1506 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
1507 input_section, output_bfd, error_message);
1508
1509 /* Subtract the symbol section base address. */
1510 reloc_entry->addend -= symbol->section->output_section->vma;
1511
1512 /* Adjust the addend for sign extension of the low 16 bits. */
1513 reloc_entry->addend += 0x8000;
1514 return bfd_reloc_continue;
1515 }
1516
1517 static bfd_reloc_status_type
1518 ppc64_elf_toc_reloc (abfd, reloc_entry, symbol, data,
1519 input_section, output_bfd, error_message)
1520 bfd *abfd;
1521 arelent *reloc_entry;
1522 asymbol *symbol;
1523 PTR data;
1524 asection *input_section;
1525 bfd *output_bfd;
1526 char **error_message;
1527 {
1528 bfd_vma TOCstart;
1529
1530 /* If this is a relocatable link (output_bfd test tells us), just
1531 call the generic function. Any adjustment will be done at final
1532 link time. */
1533 if (output_bfd != NULL)
1534 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
1535 input_section, output_bfd, error_message);
1536
1537 TOCstart = _bfd_get_gp_value (input_section->output_section->owner);
1538 if (TOCstart == 0)
1539 TOCstart = ppc64_elf_toc (input_section->output_section->owner);
1540
1541 /* Subtract the TOC base address. */
1542 reloc_entry->addend -= TOCstart + TOC_BASE_OFF;
1543 return bfd_reloc_continue;
1544 }
1545
1546 static bfd_reloc_status_type
1547 ppc64_elf_toc_ha_reloc (abfd, reloc_entry, symbol, data,
1548 input_section, output_bfd, error_message)
1549 bfd *abfd;
1550 arelent *reloc_entry;
1551 asymbol *symbol;
1552 PTR data;
1553 asection *input_section;
1554 bfd *output_bfd;
1555 char **error_message;
1556 {
1557 bfd_vma TOCstart;
1558
1559 /* If this is a relocatable link (output_bfd test tells us), just
1560 call the generic function. Any adjustment will be done at final
1561 link time. */
1562 if (output_bfd != NULL)
1563 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
1564 input_section, output_bfd, error_message);
1565
1566 TOCstart = _bfd_get_gp_value (input_section->output_section->owner);
1567 if (TOCstart == 0)
1568 TOCstart = ppc64_elf_toc (input_section->output_section->owner);
1569
1570 /* Subtract the TOC base address. */
1571 reloc_entry->addend -= TOCstart + TOC_BASE_OFF;
1572
1573 /* Adjust the addend for sign extension of the low 16 bits. */
1574 reloc_entry->addend += 0x8000;
1575 return bfd_reloc_continue;
1576 }
1577
1578 static bfd_reloc_status_type
1579 ppc64_elf_toc64_reloc (abfd, reloc_entry, symbol, data,
1580 input_section, output_bfd, error_message)
1581 bfd *abfd;
1582 arelent *reloc_entry;
1583 asymbol *symbol;
1584 PTR data;
1585 asection *input_section;
1586 bfd *output_bfd;
1587 char **error_message;
1588 {
1589 bfd_vma TOCstart;
1590 bfd_size_type octets;
1591
1592 /* If this is a relocatable link (output_bfd test tells us), just
1593 call the generic function. Any adjustment will be done at final
1594 link time. */
1595 if (output_bfd != NULL)
1596 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
1597 input_section, output_bfd, error_message);
1598
1599 TOCstart = _bfd_get_gp_value (input_section->output_section->owner);
1600 if (TOCstart == 0)
1601 TOCstart = ppc64_elf_toc (input_section->output_section->owner);
1602
1603 octets = reloc_entry->address * bfd_octets_per_byte (abfd);
1604 bfd_put_64 (abfd, TOCstart + TOC_BASE_OFF, (bfd_byte *) data + octets);
1605 return bfd_reloc_ok;
1606 }
1607
1608 static bfd_reloc_status_type
1609 ppc64_elf_unhandled_reloc (abfd, reloc_entry, symbol, data,
1610 input_section, output_bfd, error_message)
1611 bfd *abfd;
1612 arelent *reloc_entry;
1613 asymbol *symbol;
1614 PTR data;
1615 asection *input_section;
1616 bfd *output_bfd;
1617 char **error_message;
1618 {
1619 /* If this is a relocatable link (output_bfd test tells us), just
1620 call the generic function. Any adjustment will be done at final
1621 link time. */
1622 if (output_bfd != NULL)
1623 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
1624 input_section, output_bfd, error_message);
1625
1626 if (error_message != NULL)
1627 {
1628 static char buf[60];
1629 sprintf (buf, "generic linker can't handle %s",
1630 reloc_entry->howto->name);
1631 *error_message = buf;
1632 }
1633 return bfd_reloc_dangerous;
1634 }
1635
1636 /* Return symbol info as per usual for ELF targets, except that
1637 symbols in .opd are given 'd' or 'D' for type. */
1638
1639 static void
1640 ppc64_elf_get_symbol_info (abfd, symbol, ret)
1641 bfd *abfd;
1642 asymbol *symbol;
1643 symbol_info *ret;
1644 {
1645 _bfd_elf_get_symbol_info (abfd, symbol, ret);
1646 if (ret->type == '?'
1647 && (symbol->flags & (BSF_GLOBAL | BSF_LOCAL)) != 0
1648 && strcmp (symbol->section->name, ".opd") == 0)
1649 ret->type = (symbol->flags & BSF_GLOBAL) != 0 ? 'D' : 'd';
1650 }
1651
1652 /* Function to set whether a module needs the -mrelocatable bit set. */
1653
1654 static boolean
1655 ppc64_elf_set_private_flags (abfd, flags)
1656 bfd *abfd;
1657 flagword flags;
1658 {
1659 BFD_ASSERT (!elf_flags_init (abfd)
1660 || elf_elfheader (abfd)->e_flags == flags);
1661
1662 elf_elfheader (abfd)->e_flags = flags;
1663 elf_flags_init (abfd) = true;
1664 return true;
1665 }
1666
1667 /* Merge backend specific data from an object file to the output
1668 object file when linking. */
1669 static boolean
1670 ppc64_elf_merge_private_bfd_data (ibfd, obfd)
1671 bfd *ibfd;
1672 bfd *obfd;
1673 {
1674 flagword old_flags;
1675 flagword new_flags;
1676 boolean error;
1677
1678 /* Check if we have the same endianess. */
1679 if (ibfd->xvec->byteorder != obfd->xvec->byteorder
1680 && obfd->xvec->byteorder != BFD_ENDIAN_UNKNOWN)
1681 {
1682 const char *msg;
1683
1684 if (bfd_big_endian (ibfd))
1685 msg = _("%s: compiled for a big endian system and target is little endian");
1686 else
1687 msg = _("%s: compiled for a little endian system and target is big endian");
1688
1689 (*_bfd_error_handler) (msg, bfd_archive_filename (ibfd));
1690
1691 bfd_set_error (bfd_error_wrong_format);
1692 return false;
1693 }
1694
1695 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
1696 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
1697 return true;
1698
1699 new_flags = elf_elfheader (ibfd)->e_flags;
1700 old_flags = elf_elfheader (obfd)->e_flags;
1701 if (!elf_flags_init (obfd))
1702 {
1703 /* First call, no flags set. */
1704 elf_flags_init (obfd) = true;
1705 elf_elfheader (obfd)->e_flags = new_flags;
1706 }
1707
1708 else if (new_flags == old_flags)
1709 /* Compatible flags are ok. */
1710 ;
1711
1712 else
1713 {
1714 /* Incompatible flags. Warn about -mrelocatable mismatch.
1715 Allow -mrelocatable-lib to be linked with either. */
1716 error = false;
1717 if ((new_flags & EF_PPC_RELOCATABLE) != 0
1718 && (old_flags & (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB)) == 0)
1719 {
1720 error = true;
1721 (*_bfd_error_handler)
1722 (_("%s: compiled with -mrelocatable and linked with modules compiled normally"),
1723 bfd_archive_filename (ibfd));
1724 }
1725 else if ((new_flags & (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB)) == 0
1726 && (old_flags & EF_PPC_RELOCATABLE) != 0)
1727 {
1728 error = true;
1729 (*_bfd_error_handler)
1730 (_("%s: compiled normally and linked with modules compiled with -mrelocatable"),
1731 bfd_archive_filename (ibfd));
1732 }
1733
1734 /* The output is -mrelocatable-lib iff both the input files are. */
1735 if (! (new_flags & EF_PPC_RELOCATABLE_LIB))
1736 elf_elfheader (obfd)->e_flags &= ~EF_PPC_RELOCATABLE_LIB;
1737
1738 /* The output is -mrelocatable iff it can't be -mrelocatable-lib,
1739 but each input file is either -mrelocatable or -mrelocatable-lib. */
1740 if (! (elf_elfheader (obfd)->e_flags & EF_PPC_RELOCATABLE_LIB)
1741 && (new_flags & (EF_PPC_RELOCATABLE_LIB | EF_PPC_RELOCATABLE))
1742 && (old_flags & (EF_PPC_RELOCATABLE_LIB | EF_PPC_RELOCATABLE)))
1743 elf_elfheader (obfd)->e_flags |= EF_PPC_RELOCATABLE;
1744
1745 /* Do not warn about eabi vs. V.4 mismatch, just or in the bit
1746 if any module uses it. */
1747 elf_elfheader (obfd)->e_flags |= (new_flags & EF_PPC_EMB);
1748
1749 new_flags &= ~(EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB | EF_PPC_EMB);
1750 old_flags &= ~(EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB | EF_PPC_EMB);
1751
1752 /* Warn about any other mismatches. */
1753 if (new_flags != old_flags)
1754 {
1755 error = true;
1756 (*_bfd_error_handler)
1757 (_("%s: uses different e_flags (0x%lx) fields than previous modules (0x%lx)"),
1758 bfd_archive_filename (ibfd), (long) new_flags, (long) old_flags);
1759 }
1760
1761 if (error)
1762 {
1763 bfd_set_error (bfd_error_bad_value);
1764 return false;
1765 }
1766 }
1767
1768 return true;
1769 }
1770
1771 /* Handle a PowerPC specific section when reading an object file. This
1772 is called when elfcode.h finds a section with an unknown type. */
1773
1774 static boolean
1775 ppc64_elf_section_from_shdr (abfd, hdr, name)
1776 bfd *abfd;
1777 Elf64_Internal_Shdr *hdr;
1778 char *name;
1779 {
1780 asection *newsect;
1781 flagword flags;
1782
1783 if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name))
1784 return false;
1785
1786 newsect = hdr->bfd_section;
1787 flags = bfd_get_section_flags (abfd, newsect);
1788 if (hdr->sh_flags & SHF_EXCLUDE)
1789 flags |= SEC_EXCLUDE;
1790
1791 if (hdr->sh_type == SHT_ORDERED)
1792 flags |= SEC_SORT_ENTRIES;
1793
1794 bfd_set_section_flags (abfd, newsect, flags);
1795 return true;
1796 }
1797 \f
1798 /* The following functions are specific to the ELF linker, while
1799 functions above are used generally. Those named ppc64_elf_* are
1800 called by the main ELF linker code. They appear in this file more
1801 or less in the order in which they are called. eg.
1802 ppc64_elf_check_relocs is called early in the link process,
1803 ppc64_elf_finish_dynamic_sections is one of the last functions
1804 called.
1805
1806 PowerPC64-ELF uses a similar scheme to PowerPC64-XCOFF in that
1807 functions have both a function code symbol and a function descriptor
1808 symbol. A call to foo in a relocatable object file looks like:
1809
1810 . .text
1811 . x:
1812 . bl .foo
1813 . nop
1814
1815 The function definition in another object file might be:
1816
1817 . .section .opd
1818 . foo: .quad .foo
1819 . .quad .TOC.@tocbase
1820 . .quad 0
1821 .
1822 . .text
1823 . .foo: blr
1824
1825 When the linker resolves the call during a static link, the branch
1826 unsurprisingly just goes to .foo and the .opd information is unused.
1827 If the function definition is in a shared library, things are a little
1828 different: The call goes via a plt call stub, the opd information gets
1829 copied to the plt, and the linker patches the nop.
1830
1831 . x:
1832 . bl .foo_stub
1833 . ld 2,40(1)
1834 .
1835 .
1836 . .foo_stub:
1837 . addis 12,2,Lfoo@toc@ha # in practice, the call stub
1838 . addi 12,12,Lfoo@toc@l # is slightly optimised, but
1839 . std 2,40(1) # this is the general idea
1840 . ld 11,0(12)
1841 . ld 2,8(12)
1842 . mtctr 11
1843 . ld 11,16(12)
1844 . bctr
1845 .
1846 . .section .plt
1847 . Lfoo: reloc (R_PPC64_JMP_SLOT, foo)
1848
1849 The "reloc ()" notation is supposed to indicate that the linker emits
1850 an R_PPC64_JMP_SLOT reloc against foo. The dynamic linker does the opd
1851 copying.
1852
1853 What are the difficulties here? Well, firstly, the relocations
1854 examined by the linker in check_relocs are against the function code
1855 sym .foo, while the dynamic relocation in the plt is emitted against
1856 the function descriptor symbol, foo. Somewhere along the line, we need
1857 to carefully copy dynamic link information from one symbol to the other.
1858 Secondly, the generic part of the elf linker will make .foo a dynamic
1859 symbol as is normal for most other backends. We need foo dynamic
1860 instead, at least for an application final link. However, when
1861 creating a shared library containing foo, we need to have both symbols
1862 dynamic so that references to .foo are satisfied during the early
1863 stages of linking. Otherwise the linker might decide to pull in a
1864 definition from some other object, eg. a static library. */
1865
1866 /* The linker needs to keep track of the number of relocs that it
1867 decides to copy as dynamic relocs in check_relocs for each symbol.
1868 This is so that it can later discard them if they are found to be
1869 unnecessary. We store the information in a field extending the
1870 regular ELF linker hash table. */
1871
1872 struct ppc_dyn_relocs
1873 {
1874 struct ppc_dyn_relocs *next;
1875
1876 /* The input section of the reloc. */
1877 asection *sec;
1878
1879 /* Total number of relocs copied for the input section. */
1880 bfd_size_type count;
1881
1882 /* Number of pc-relative relocs copied for the input section. */
1883 bfd_size_type pc_count;
1884 };
1885
1886 /* Of those relocs that might be copied as dynamic relocs, this macro
1887 selects between relative and absolute types. */
1888
1889 #define IS_ABSOLUTE_RELOC(RTYPE) \
1890 ((RTYPE) != R_PPC64_REL32 \
1891 && (RTYPE) != R_PPC64_REL64 \
1892 && (RTYPE) != R_PPC64_ADDR30)
1893
1894 /* Section name for stubs is the associated section name plus this
1895 string. */
1896 #define STUB_SUFFIX ".stub"
1897
1898 /* Linker stubs.
1899 ppc_stub_long_branch:
1900 Used when a 14 bit branch (or even a 24 bit branch) can't reach its
1901 destination, but a 24 bit branch in a stub section will reach.
1902 . b dest
1903
1904 ppc_stub_plt_branch:
1905 Similar to the above, but a 24 bit branch in the stub section won't
1906 reach its destination.
1907 . addis %r12,%r2,xxx@ha
1908 . ld %r11,xxx@l(%r12)
1909 . mtctr %r11
1910 . bctr
1911
1912 ppc_stub_plt_call:
1913 Used to call a function in a shared library.
1914 . addis %r12,%r2,xxx@ha
1915 . std %r2,40(%r1)
1916 . ld %r11,xxx+0@l(%r12)
1917 . ld %r2,xxx+8@l(%r12)
1918 . mtctr %r11
1919 . ld %r11,xxx+16@l(%r12)
1920 . bctr
1921 */
1922
1923 enum ppc_stub_type {
1924 ppc_stub_none,
1925 ppc_stub_long_branch,
1926 ppc_stub_plt_branch,
1927 ppc_stub_plt_call
1928 };
1929
1930 struct ppc_stub_hash_entry {
1931
1932 /* Base hash table entry structure. */
1933 struct bfd_hash_entry root;
1934
1935 /* The stub section. */
1936 asection *stub_sec;
1937
1938 /* Offset within stub_sec of the beginning of this stub. */
1939 bfd_vma stub_offset;
1940
1941 /* Given the symbol's value and its section we can determine its final
1942 value when building the stubs (so the stub knows where to jump. */
1943 bfd_vma target_value;
1944 asection *target_section;
1945
1946 enum ppc_stub_type stub_type;
1947
1948 /* The symbol table entry, if any, that this was derived from. */
1949 struct ppc_link_hash_entry *h;
1950
1951 /* Where this stub is being called from, or, in the case of combined
1952 stub sections, the first input section in the group. */
1953 asection *id_sec;
1954 };
1955
1956 struct ppc_branch_hash_entry {
1957
1958 /* Base hash table entry structure. */
1959 struct bfd_hash_entry root;
1960
1961 /* Offset within .branch_lt. */
1962 unsigned int offset;
1963
1964 /* Generation marker. */
1965 unsigned int iter;
1966 };
1967
1968 struct ppc_link_hash_entry
1969 {
1970 struct elf_link_hash_entry elf;
1971
1972 /* A pointer to the most recently used stub hash entry against this
1973 symbol. */
1974 struct ppc_stub_hash_entry *stub_cache;
1975
1976 /* Track dynamic relocs copied for this symbol. */
1977 struct ppc_dyn_relocs *dyn_relocs;
1978
1979 /* Link between function code and descriptor symbols. */
1980 struct elf_link_hash_entry *oh;
1981
1982 /* Flag function code and descriptor symbols. */
1983 unsigned int is_func:1;
1984 unsigned int is_func_descriptor:1;
1985 };
1986
1987 /* ppc64 ELF linker hash table. */
1988
1989 struct ppc_link_hash_table
1990 {
1991 struct elf_link_hash_table elf;
1992
1993 /* The stub hash table. */
1994 struct bfd_hash_table stub_hash_table;
1995
1996 /* Another hash table for plt_branch stubs. */
1997 struct bfd_hash_table branch_hash_table;
1998
1999 /* Linker stub bfd. */
2000 bfd *stub_bfd;
2001
2002 /* Linker call-backs. */
2003 asection * (*add_stub_section) PARAMS ((const char *, asection *));
2004 void (*layout_sections_again) PARAMS ((void));
2005
2006 /* Array to keep track of which stub sections have been created, and
2007 information on stub grouping. */
2008 struct map_stub {
2009 /* This is the section to which stubs in the group will be attached. */
2010 asection *link_sec;
2011 /* The stub section. */
2012 asection *stub_sec;
2013 } *stub_group;
2014
2015 /* Assorted information used by ppc64_elf_size_stubs. */
2016 unsigned int bfd_count;
2017 int top_index;
2018 asection **input_list;
2019 Elf_Internal_Sym **all_local_syms;
2020
2021 /* Short-cuts to get to dynamic linker sections. */
2022 asection *sgot;
2023 asection *srelgot;
2024 asection *splt;
2025 asection *srelplt;
2026 asection *sdynbss;
2027 asection *srelbss;
2028 asection *sglink;
2029 asection *sfpr;
2030 asection *sbrlt;
2031 asection *srelbrlt;
2032
2033 /* Set on error. */
2034 unsigned int stub_error;
2035
2036 /* Flag set when small branches are detected. Used to
2037 select suitable defaults for the stub group size. */
2038 unsigned int has_14bit_branch;
2039
2040 /* Set if we detect a reference undefined weak symbol. */
2041 unsigned int have_undefweak;
2042
2043 /* Incremented every time we size stubs. */
2044 unsigned int stub_iteration;
2045
2046 /* Small local sym to section mapping cache. */
2047 struct sym_sec_cache sym_sec;
2048 };
2049
2050 static struct bfd_hash_entry *stub_hash_newfunc
2051 PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *));
2052 static struct bfd_hash_entry *branch_hash_newfunc
2053 PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *));
2054 static struct bfd_hash_entry *link_hash_newfunc
2055 PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *));
2056 static struct bfd_link_hash_table *ppc64_elf_link_hash_table_create
2057 PARAMS ((bfd *));
2058 static void ppc64_elf_link_hash_table_free
2059 PARAMS ((struct bfd_link_hash_table *));
2060 static char *ppc_stub_name
2061 PARAMS ((const asection *, const asection *,
2062 const struct ppc_link_hash_entry *, const Elf_Internal_Rela *));
2063 static struct ppc_stub_hash_entry *ppc_get_stub_entry
2064 PARAMS ((const asection *, const asection *, struct elf_link_hash_entry *,
2065 const Elf_Internal_Rela *, struct ppc_link_hash_table *));
2066 static struct ppc_stub_hash_entry *ppc_add_stub
2067 PARAMS ((const char *, asection *, struct ppc_link_hash_table *));
2068 static boolean create_linkage_sections
2069 PARAMS ((bfd *, struct bfd_link_info *));
2070 static boolean create_got_section
2071 PARAMS ((bfd *, struct bfd_link_info *));
2072 static boolean ppc64_elf_create_dynamic_sections
2073 PARAMS ((bfd *, struct bfd_link_info *));
2074 static void ppc64_elf_copy_indirect_symbol
2075 PARAMS ((struct elf_link_hash_entry *, struct elf_link_hash_entry *));
2076 static boolean ppc64_elf_check_relocs
2077 PARAMS ((bfd *, struct bfd_link_info *, asection *,
2078 const Elf_Internal_Rela *));
2079 static asection * ppc64_elf_gc_mark_hook
2080 PARAMS ((bfd *abfd, struct bfd_link_info *info, Elf_Internal_Rela *rel,
2081 struct elf_link_hash_entry *h, Elf_Internal_Sym *sym));
2082 static boolean ppc64_elf_gc_sweep_hook
2083 PARAMS ((bfd *abfd, struct bfd_link_info *info, asection *sec,
2084 const Elf_Internal_Rela *relocs));
2085 static boolean func_desc_adjust
2086 PARAMS ((struct elf_link_hash_entry *, PTR));
2087 static boolean ppc64_elf_func_desc_adjust
2088 PARAMS ((bfd *, struct bfd_link_info *));
2089 static boolean ppc64_elf_adjust_dynamic_symbol
2090 PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *));
2091 static void ppc64_elf_hide_symbol
2092 PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *, boolean));
2093 static boolean allocate_dynrelocs
2094 PARAMS ((struct elf_link_hash_entry *, PTR));
2095 static boolean readonly_dynrelocs
2096 PARAMS ((struct elf_link_hash_entry *, PTR));
2097 static enum elf_reloc_type_class ppc64_elf_reloc_type_class
2098 PARAMS ((const Elf_Internal_Rela *));
2099 static boolean ppc64_elf_size_dynamic_sections
2100 PARAMS ((bfd *, struct bfd_link_info *));
2101 static INLINE enum ppc_stub_type ppc_type_of_stub
2102 PARAMS ((asection *, const Elf_Internal_Rela *,
2103 struct ppc_link_hash_entry **, bfd_vma));
2104 static bfd_byte *build_plt_stub
2105 PARAMS ((bfd *, bfd_byte *, int, int));
2106 static boolean ppc_build_one_stub
2107 PARAMS ((struct bfd_hash_entry *, PTR));
2108 static boolean ppc_size_one_stub
2109 PARAMS ((struct bfd_hash_entry *, PTR));
2110 static void group_sections
2111 PARAMS ((struct ppc_link_hash_table *, bfd_size_type, boolean));
2112 static boolean get_local_syms
2113 PARAMS ((bfd *, struct ppc_link_hash_table *));
2114 static boolean ppc64_elf_fake_sections
2115 PARAMS ((bfd *, Elf64_Internal_Shdr *, asection *));
2116 static boolean ppc64_elf_relocate_section
2117 PARAMS ((bfd *, struct bfd_link_info *info, bfd *, asection *, bfd_byte *,
2118 Elf_Internal_Rela *relocs, Elf_Internal_Sym *local_syms,
2119 asection **));
2120 static boolean ppc64_elf_finish_dynamic_symbol
2121 PARAMS ((bfd *, struct bfd_link_info *, struct elf_link_hash_entry *,
2122 Elf_Internal_Sym *));
2123 static boolean ppc64_elf_finish_dynamic_sections
2124 PARAMS ((bfd *, struct bfd_link_info *));
2125
2126 /* Get the ppc64 ELF linker hash table from a link_info structure. */
2127
2128 #define ppc_hash_table(p) \
2129 ((struct ppc_link_hash_table *) ((p)->hash))
2130
2131 #define ppc_stub_hash_lookup(table, string, create, copy) \
2132 ((struct ppc_stub_hash_entry *) \
2133 bfd_hash_lookup ((table), (string), (create), (copy)))
2134
2135 #define ppc_branch_hash_lookup(table, string, create, copy) \
2136 ((struct ppc_branch_hash_entry *) \
2137 bfd_hash_lookup ((table), (string), (create), (copy)))
2138
2139 /* Create an entry in the stub hash table. */
2140
2141 static struct bfd_hash_entry *
2142 stub_hash_newfunc (entry, table, string)
2143 struct bfd_hash_entry *entry;
2144 struct bfd_hash_table *table;
2145 const char *string;
2146 {
2147 /* Allocate the structure if it has not already been allocated by a
2148 subclass. */
2149 if (entry == NULL)
2150 {
2151 entry = bfd_hash_allocate (table, sizeof (struct ppc_stub_hash_entry));
2152 if (entry == NULL)
2153 return entry;
2154 }
2155
2156 /* Call the allocation method of the superclass. */
2157 entry = bfd_hash_newfunc (entry, table, string);
2158 if (entry != NULL)
2159 {
2160 struct ppc_stub_hash_entry *eh;
2161
2162 /* Initialize the local fields. */
2163 eh = (struct ppc_stub_hash_entry *) entry;
2164 eh->stub_sec = NULL;
2165 eh->stub_offset = 0;
2166 eh->target_value = 0;
2167 eh->target_section = NULL;
2168 eh->stub_type = ppc_stub_none;
2169 eh->h = NULL;
2170 eh->id_sec = NULL;
2171 }
2172
2173 return entry;
2174 }
2175
2176 /* Create an entry in the branch hash table. */
2177
2178 static struct bfd_hash_entry *
2179 branch_hash_newfunc (entry, table, string)
2180 struct bfd_hash_entry *entry;
2181 struct bfd_hash_table *table;
2182 const char *string;
2183 {
2184 /* Allocate the structure if it has not already been allocated by a
2185 subclass. */
2186 if (entry == NULL)
2187 {
2188 entry = bfd_hash_allocate (table, sizeof (struct ppc_branch_hash_entry));
2189 if (entry == NULL)
2190 return entry;
2191 }
2192
2193 /* Call the allocation method of the superclass. */
2194 entry = bfd_hash_newfunc (entry, table, string);
2195 if (entry != NULL)
2196 {
2197 struct ppc_branch_hash_entry *eh;
2198
2199 /* Initialize the local fields. */
2200 eh = (struct ppc_branch_hash_entry *) entry;
2201 eh->offset = 0;
2202 eh->iter = 0;
2203 }
2204
2205 return entry;
2206 }
2207
2208 /* Create an entry in a ppc64 ELF linker hash table. */
2209
2210 static struct bfd_hash_entry *
2211 link_hash_newfunc (entry, table, string)
2212 struct bfd_hash_entry *entry;
2213 struct bfd_hash_table *table;
2214 const char *string;
2215 {
2216 /* Allocate the structure if it has not already been allocated by a
2217 subclass. */
2218 if (entry == NULL)
2219 {
2220 entry = bfd_hash_allocate (table, sizeof (struct ppc_link_hash_entry));
2221 if (entry == NULL)
2222 return entry;
2223 }
2224
2225 /* Call the allocation method of the superclass. */
2226 entry = _bfd_elf_link_hash_newfunc (entry, table, string);
2227 if (entry != NULL)
2228 {
2229 struct ppc_link_hash_entry *eh = (struct ppc_link_hash_entry *) entry;
2230
2231 eh->stub_cache = NULL;
2232 eh->dyn_relocs = NULL;
2233 eh->oh = NULL;
2234 eh->is_func = 0;
2235 eh->is_func_descriptor = 0;
2236 }
2237
2238 return entry;
2239 }
2240
2241 /* Create a ppc64 ELF linker hash table. */
2242
2243 static struct bfd_link_hash_table *
2244 ppc64_elf_link_hash_table_create (abfd)
2245 bfd *abfd;
2246 {
2247 struct ppc_link_hash_table *htab;
2248 bfd_size_type amt = sizeof (struct ppc_link_hash_table);
2249
2250 htab = (struct ppc_link_hash_table *) bfd_malloc (amt);
2251 if (htab == NULL)
2252 return NULL;
2253
2254 if (! _bfd_elf_link_hash_table_init (&htab->elf, abfd, link_hash_newfunc))
2255 {
2256 free (htab);
2257 return NULL;
2258 }
2259
2260 /* Init the stub hash table too. */
2261 if (!bfd_hash_table_init (&htab->stub_hash_table, stub_hash_newfunc))
2262 return NULL;
2263
2264 /* And the branch hash table. */
2265 if (!bfd_hash_table_init (&htab->branch_hash_table, branch_hash_newfunc))
2266 return NULL;
2267
2268 htab->stub_bfd = NULL;
2269 htab->add_stub_section = NULL;
2270 htab->layout_sections_again = NULL;
2271 htab->stub_group = NULL;
2272 htab->sgot = NULL;
2273 htab->srelgot = NULL;
2274 htab->splt = NULL;
2275 htab->srelplt = NULL;
2276 htab->sdynbss = NULL;
2277 htab->srelbss = NULL;
2278 htab->sglink = NULL;
2279 htab->sfpr = NULL;
2280 htab->sbrlt = NULL;
2281 htab->srelbrlt = NULL;
2282 htab->stub_error = 0;
2283 htab->has_14bit_branch = 0;
2284 htab->have_undefweak = 0;
2285 htab->stub_iteration = 0;
2286 htab->sym_sec.abfd = NULL;
2287
2288 return &htab->elf.root;
2289 }
2290
2291 /* Free the derived linker hash table. */
2292
2293 static void
2294 ppc64_elf_link_hash_table_free (hash)
2295 struct bfd_link_hash_table *hash;
2296 {
2297 struct ppc_link_hash_table *ret = (struct ppc_link_hash_table *) hash;
2298
2299 bfd_hash_table_free (&ret->stub_hash_table);
2300 bfd_hash_table_free (&ret->branch_hash_table);
2301 _bfd_generic_link_hash_table_free (hash);
2302 }
2303
2304 /* Build a name for an entry in the stub hash table. */
2305
2306 static char *
2307 ppc_stub_name (input_section, sym_sec, h, rel)
2308 const asection *input_section;
2309 const asection *sym_sec;
2310 const struct ppc_link_hash_entry *h;
2311 const Elf_Internal_Rela *rel;
2312 {
2313 char *stub_name;
2314 bfd_size_type len;
2315
2316 /* rel->r_addend is actually 64 bit, but who uses more than +/- 2^31
2317 offsets from a sym as a branch target? In fact, we could
2318 probably assume the addend is always zero. */
2319 BFD_ASSERT (((int) rel->r_addend & 0xffffffff) == rel->r_addend);
2320
2321 if (h)
2322 {
2323 len = 8 + 1 + strlen (h->elf.root.root.string) + 1 + 8 + 1;
2324 stub_name = bfd_malloc (len);
2325 if (stub_name != NULL)
2326 {
2327 sprintf (stub_name, "%08x_%s+%x",
2328 input_section->id & 0xffffffff,
2329 h->elf.root.root.string,
2330 (int) rel->r_addend & 0xffffffff);
2331 }
2332 }
2333 else
2334 {
2335 len = 8 + 1 + 8 + 1 + 8 + 1 + 16 + 1;
2336 stub_name = bfd_malloc (len);
2337 if (stub_name != NULL)
2338 {
2339 sprintf (stub_name, "%08x_%x:%x+%x",
2340 input_section->id & 0xffffffff,
2341 sym_sec->id & 0xffffffff,
2342 (int) ELF64_R_SYM (rel->r_info) & 0xffffffff,
2343 (int) rel->r_addend & 0xffffffff);
2344 }
2345 }
2346 return stub_name;
2347 }
2348
2349 /* Look up an entry in the stub hash. Stub entries are cached because
2350 creating the stub name takes a bit of time. */
2351
2352 static struct ppc_stub_hash_entry *
2353 ppc_get_stub_entry (input_section, sym_sec, hash, rel, htab)
2354 const asection *input_section;
2355 const asection *sym_sec;
2356 struct elf_link_hash_entry *hash;
2357 const Elf_Internal_Rela *rel;
2358 struct ppc_link_hash_table *htab;
2359 {
2360 struct ppc_stub_hash_entry *stub_entry;
2361 struct ppc_link_hash_entry *h = (struct ppc_link_hash_entry *) hash;
2362 const asection *id_sec;
2363
2364 /* If this input section is part of a group of sections sharing one
2365 stub section, then use the id of the first section in the group.
2366 Stub names need to include a section id, as there may well be
2367 more than one stub used to reach say, printf, and we need to
2368 distinguish between them. */
2369 id_sec = htab->stub_group[input_section->id].link_sec;
2370
2371 if (h != NULL && h->stub_cache != NULL
2372 && h->stub_cache->h == h
2373 && h->stub_cache->id_sec == id_sec)
2374 {
2375 stub_entry = h->stub_cache;
2376 }
2377 else
2378 {
2379 char *stub_name;
2380
2381 stub_name = ppc_stub_name (id_sec, sym_sec, h, rel);
2382 if (stub_name == NULL)
2383 return NULL;
2384
2385 stub_entry = ppc_stub_hash_lookup (&htab->stub_hash_table,
2386 stub_name, false, false);
2387 if (h != NULL)
2388 h->stub_cache = stub_entry;
2389
2390 free (stub_name);
2391 }
2392
2393 return stub_entry;
2394 }
2395
2396 /* Add a new stub entry to the stub hash. Not all fields of the new
2397 stub entry are initialised. */
2398
2399 static struct ppc_stub_hash_entry *
2400 ppc_add_stub (stub_name, section, htab)
2401 const char *stub_name;
2402 asection *section;
2403 struct ppc_link_hash_table *htab;
2404 {
2405 asection *link_sec;
2406 asection *stub_sec;
2407 struct ppc_stub_hash_entry *stub_entry;
2408
2409 link_sec = htab->stub_group[section->id].link_sec;
2410 stub_sec = htab->stub_group[section->id].stub_sec;
2411 if (stub_sec == NULL)
2412 {
2413 stub_sec = htab->stub_group[link_sec->id].stub_sec;
2414 if (stub_sec == NULL)
2415 {
2416 bfd_size_type len;
2417 char *s_name;
2418
2419 len = strlen (link_sec->name) + sizeof (STUB_SUFFIX);
2420 s_name = bfd_alloc (htab->stub_bfd, len);
2421 if (s_name == NULL)
2422 return NULL;
2423
2424 strcpy (s_name, link_sec->name);
2425 strcpy (s_name + len - sizeof (STUB_SUFFIX), STUB_SUFFIX);
2426 stub_sec = (*htab->add_stub_section) (s_name, link_sec);
2427 if (stub_sec == NULL)
2428 return NULL;
2429 htab->stub_group[link_sec->id].stub_sec = stub_sec;
2430 }
2431 htab->stub_group[section->id].stub_sec = stub_sec;
2432 }
2433
2434 /* Enter this entry into the linker stub hash table. */
2435 stub_entry = ppc_stub_hash_lookup (&htab->stub_hash_table, stub_name,
2436 true, false);
2437 if (stub_entry == NULL)
2438 {
2439 (*_bfd_error_handler) (_("%s: cannot create stub entry %s"),
2440 bfd_archive_filename (section->owner),
2441 stub_name);
2442 return NULL;
2443 }
2444
2445 stub_entry->stub_sec = stub_sec;
2446 stub_entry->stub_offset = 0;
2447 stub_entry->id_sec = link_sec;
2448 return stub_entry;
2449 }
2450
2451 /* Create sections for linker generated code. */
2452
2453 static boolean
2454 create_linkage_sections (dynobj, info)
2455 bfd *dynobj;
2456 struct bfd_link_info *info;
2457 {
2458 struct ppc_link_hash_table *htab;
2459 flagword flags;
2460
2461 htab = ppc_hash_table (info);
2462
2463 /* Create .sfpr for code to save and restore fp regs. */
2464 flags = (SEC_ALLOC | SEC_LOAD | SEC_CODE | SEC_READONLY
2465 | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED);
2466 htab->sfpr = bfd_make_section_anyway (dynobj, ".sfpr");
2467 if (htab->sfpr == NULL
2468 || ! bfd_set_section_flags (dynobj, htab->sfpr, flags)
2469 || ! bfd_set_section_alignment (dynobj, htab->sfpr, 2))
2470 return false;
2471
2472 /* Create .glink for lazy dynamic linking support. */
2473 htab->sglink = bfd_make_section_anyway (dynobj, ".glink");
2474 if (htab->sglink == NULL
2475 || ! bfd_set_section_flags (dynobj, htab->sglink, flags)
2476 || ! bfd_set_section_alignment (dynobj, htab->sglink, 2))
2477 return false;
2478
2479 /* Create .branch_lt for plt_branch stubs. */
2480 flags = (SEC_ALLOC | SEC_LOAD
2481 | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED);
2482 htab->sbrlt = bfd_make_section_anyway (dynobj, ".branch_lt");
2483 if (htab->sbrlt == NULL
2484 || ! bfd_set_section_flags (dynobj, htab->sbrlt, flags)
2485 || ! bfd_set_section_alignment (dynobj, htab->sbrlt, 3))
2486 return false;
2487
2488 if (info->shared)
2489 {
2490 flags = (SEC_ALLOC | SEC_LOAD | SEC_READONLY
2491 | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED);
2492 htab->srelbrlt = bfd_make_section (dynobj, ".rela.branch_lt");
2493 if (!htab->srelbrlt
2494 || ! bfd_set_section_flags (dynobj, htab->srelbrlt, flags)
2495 || ! bfd_set_section_alignment (dynobj, htab->srelbrlt, 3))
2496 return false;
2497 }
2498 return true;
2499 }
2500
2501 /* Create .got and .rela.got sections in DYNOBJ, and set up
2502 shortcuts to them in our hash table. */
2503
2504 static boolean
2505 create_got_section (dynobj, info)
2506 bfd *dynobj;
2507 struct bfd_link_info *info;
2508 {
2509 struct ppc_link_hash_table *htab;
2510
2511 if (! _bfd_elf_create_got_section (dynobj, info))
2512 return false;
2513
2514 htab = ppc_hash_table (info);
2515 htab->sgot = bfd_get_section_by_name (dynobj, ".got");
2516 if (!htab->sgot)
2517 abort ();
2518
2519 htab->srelgot = bfd_make_section (dynobj, ".rela.got");
2520 if (!htab->srelgot
2521 || ! bfd_set_section_flags (dynobj, htab->srelgot,
2522 (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS
2523 | SEC_IN_MEMORY | SEC_LINKER_CREATED
2524 | SEC_READONLY))
2525 || ! bfd_set_section_alignment (dynobj, htab->srelgot, 3))
2526 return false;
2527 return true;
2528 }
2529
2530 /* Create the dynamic sections, and set up shortcuts. */
2531
2532 static boolean
2533 ppc64_elf_create_dynamic_sections (dynobj, info)
2534 bfd *dynobj;
2535 struct bfd_link_info *info;
2536 {
2537 struct ppc_link_hash_table *htab;
2538
2539 htab = ppc_hash_table (info);
2540 if (!htab->sgot && !create_got_section (dynobj, info))
2541 return false;
2542
2543 if (!_bfd_elf_create_dynamic_sections (dynobj, info))
2544 return false;
2545
2546 htab->splt = bfd_get_section_by_name (dynobj, ".plt");
2547 htab->srelplt = bfd_get_section_by_name (dynobj, ".rela.plt");
2548 htab->sdynbss = bfd_get_section_by_name (dynobj, ".dynbss");
2549 if (!info->shared)
2550 htab->srelbss = bfd_get_section_by_name (dynobj, ".rela.bss");
2551
2552 if (!htab->splt || !htab->srelplt || !htab->sdynbss
2553 || (!info->shared && !htab->srelbss))
2554 abort ();
2555
2556 return true;
2557 }
2558
2559 /* Copy the extra info we tack onto an elf_link_hash_entry. */
2560
2561 static void
2562 ppc64_elf_copy_indirect_symbol (dir, ind)
2563 struct elf_link_hash_entry *dir, *ind;
2564 {
2565 struct ppc_link_hash_entry *edir, *eind;
2566
2567 edir = (struct ppc_link_hash_entry *) dir;
2568 eind = (struct ppc_link_hash_entry *) ind;
2569
2570 if (eind->dyn_relocs != NULL)
2571 {
2572 if (edir->dyn_relocs != NULL)
2573 {
2574 struct ppc_dyn_relocs **pp;
2575 struct ppc_dyn_relocs *p;
2576
2577 if (ind->root.type == bfd_link_hash_indirect)
2578 abort ();
2579
2580 /* Add reloc counts against the weak sym to the strong sym
2581 list. Merge any entries against the same section. */
2582 for (pp = &eind->dyn_relocs; (p = *pp) != NULL; )
2583 {
2584 struct ppc_dyn_relocs *q;
2585
2586 for (q = edir->dyn_relocs; q != NULL; q = q->next)
2587 if (q->sec == p->sec)
2588 {
2589 q->pc_count += p->pc_count;
2590 q->count += p->count;
2591 *pp = p->next;
2592 break;
2593 }
2594 if (q == NULL)
2595 pp = &p->next;
2596 }
2597 *pp = edir->dyn_relocs;
2598 }
2599
2600 edir->dyn_relocs = eind->dyn_relocs;
2601 eind->dyn_relocs = NULL;
2602 }
2603
2604 edir->is_func |= eind->is_func;
2605 edir->is_func_descriptor |= eind->is_func_descriptor;
2606
2607 _bfd_elf_link_hash_copy_indirect (dir, ind);
2608 }
2609
2610 /* Look through the relocs for a section during the first phase, and
2611 calculate needed space in the global offset table, procedure
2612 linkage table, and dynamic reloc sections. */
2613
2614 static boolean
2615 ppc64_elf_check_relocs (abfd, info, sec, relocs)
2616 bfd *abfd;
2617 struct bfd_link_info *info;
2618 asection *sec;
2619 const Elf_Internal_Rela *relocs;
2620 {
2621 struct ppc_link_hash_table *htab;
2622 Elf_Internal_Shdr *symtab_hdr;
2623 struct elf_link_hash_entry **sym_hashes, **sym_hashes_end;
2624 const Elf_Internal_Rela *rel;
2625 const Elf_Internal_Rela *rel_end;
2626 asection *sreloc;
2627 boolean is_opd;
2628
2629 if (info->relocateable)
2630 return true;
2631
2632 htab = ppc_hash_table (info);
2633 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
2634
2635 sym_hashes = elf_sym_hashes (abfd);
2636 sym_hashes_end = (sym_hashes
2637 + symtab_hdr->sh_size / sizeof (Elf64_External_Sym));
2638 if (!elf_bad_symtab (abfd))
2639 sym_hashes_end -= symtab_hdr->sh_info;
2640
2641 sreloc = NULL;
2642 is_opd = strcmp (bfd_get_section_name (abfd, sec), ".opd") == 0;
2643
2644 if (htab->elf.dynobj == NULL)
2645 htab->elf.dynobj = abfd;
2646 if (htab->sfpr == NULL
2647 && !create_linkage_sections (htab->elf.dynobj, info))
2648 return false;
2649
2650 rel_end = relocs + sec->reloc_count;
2651 for (rel = relocs; rel < rel_end; rel++)
2652 {
2653 unsigned long r_symndx;
2654 struct elf_link_hash_entry *h;
2655 enum elf_ppc_reloc_type r_type;
2656
2657 r_symndx = ELF64_R_SYM (rel->r_info);
2658 if (r_symndx < symtab_hdr->sh_info)
2659 h = NULL;
2660 else
2661 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
2662
2663 r_type = (enum elf_ppc_reloc_type) ELF64_R_TYPE (rel->r_info);
2664 switch (r_type)
2665 {
2666 /* GOT16 relocations */
2667 case R_PPC64_GOT16:
2668 case R_PPC64_GOT16_DS:
2669 case R_PPC64_GOT16_HA:
2670 case R_PPC64_GOT16_HI:
2671 case R_PPC64_GOT16_LO:
2672 case R_PPC64_GOT16_LO_DS:
2673
2674 /* This symbol requires a global offset table entry. */
2675 if (htab->sgot == NULL
2676 && !create_got_section (htab->elf.dynobj, info))
2677 return false;
2678
2679 if (h != NULL)
2680 {
2681 h->got.refcount += 1;
2682 }
2683 else
2684 {
2685 bfd_signed_vma *local_got_refcounts;
2686
2687 /* This is a global offset table entry for a local symbol. */
2688 local_got_refcounts = elf_local_got_refcounts (abfd);
2689 if (local_got_refcounts == NULL)
2690 {
2691 bfd_size_type size;
2692
2693 size = symtab_hdr->sh_info;
2694 size *= sizeof (bfd_signed_vma);
2695 local_got_refcounts = ((bfd_signed_vma *)
2696 bfd_zalloc (abfd, size));
2697 if (local_got_refcounts == NULL)
2698 return false;
2699 elf_local_got_refcounts (abfd) = local_got_refcounts;
2700 }
2701 local_got_refcounts[r_symndx] += 1;
2702 }
2703 break;
2704
2705 case R_PPC64_PLT16_HA:
2706 case R_PPC64_PLT16_HI:
2707 case R_PPC64_PLT16_LO:
2708 case R_PPC64_PLT32:
2709 case R_PPC64_PLT64:
2710 /* This symbol requires a procedure linkage table entry. We
2711 actually build the entry in adjust_dynamic_symbol,
2712 because this might be a case of linking PIC code without
2713 linking in any dynamic objects, in which case we don't
2714 need to generate a procedure linkage table after all. */
2715 if (h == NULL)
2716 {
2717 /* It does not make sense to have a procedure linkage
2718 table entry for a local symbol. */
2719 bfd_set_error (bfd_error_bad_value);
2720 return false;
2721 }
2722
2723 h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
2724 h->plt.refcount += 1;
2725 ((struct ppc_link_hash_entry *) h)->is_func = 1;
2726 break;
2727
2728 /* The following relocations don't need to propagate the
2729 relocation if linking a shared object since they are
2730 section relative. */
2731 case R_PPC64_SECTOFF:
2732 case R_PPC64_SECTOFF_LO:
2733 case R_PPC64_SECTOFF_HI:
2734 case R_PPC64_SECTOFF_HA:
2735 case R_PPC64_SECTOFF_DS:
2736 case R_PPC64_SECTOFF_LO_DS:
2737 case R_PPC64_TOC16:
2738 case R_PPC64_TOC16_LO:
2739 case R_PPC64_TOC16_HI:
2740 case R_PPC64_TOC16_HA:
2741 case R_PPC64_TOC16_DS:
2742 case R_PPC64_TOC16_LO_DS:
2743 break;
2744
2745 /* This relocation describes the C++ object vtable hierarchy.
2746 Reconstruct it for later use during GC. */
2747 case R_PPC64_GNU_VTINHERIT:
2748 if (!_bfd_elf64_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
2749 return false;
2750 break;
2751
2752 /* This relocation describes which C++ vtable entries are actually
2753 used. Record for later use during GC. */
2754 case R_PPC64_GNU_VTENTRY:
2755 if (!_bfd_elf64_gc_record_vtentry (abfd, sec, h, rel->r_addend))
2756 return false;
2757 break;
2758
2759 case R_PPC64_REL14:
2760 case R_PPC64_REL14_BRTAKEN:
2761 case R_PPC64_REL14_BRNTAKEN:
2762 htab->has_14bit_branch = 1;
2763 /* Fall through. */
2764
2765 case R_PPC64_REL24:
2766 if (h != NULL
2767 && h->root.root.string[0] == '.'
2768 && h->root.root.string[1] != 0)
2769 {
2770 /* We may need a .plt entry if the function this reloc
2771 refers to is in a shared lib. */
2772 h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
2773 h->plt.refcount += 1;
2774 ((struct ppc_link_hash_entry *) h)->is_func = 1;
2775 }
2776 break;
2777
2778 case R_PPC64_ADDR64:
2779 if (is_opd
2780 && h != NULL
2781 && h->root.root.string[0] == '.'
2782 && h->root.root.string[1] != 0)
2783 {
2784 struct elf_link_hash_entry *fdh;
2785
2786 fdh = elf_link_hash_lookup (&htab->elf, h->root.root.string + 1,
2787 false, false, false);
2788 if (fdh != NULL)
2789 {
2790 ((struct ppc_link_hash_entry *) fdh)->is_func_descriptor = 1;
2791 ((struct ppc_link_hash_entry *) fdh)->oh = h;
2792 ((struct ppc_link_hash_entry *) h)->is_func = 1;
2793 ((struct ppc_link_hash_entry *) h)->oh = fdh;
2794 }
2795 }
2796 /* Fall through. */
2797
2798 case R_PPC64_REL64:
2799 case R_PPC64_REL32:
2800 case R_PPC64_ADDR14:
2801 case R_PPC64_ADDR14_BRNTAKEN:
2802 case R_PPC64_ADDR14_BRTAKEN:
2803 case R_PPC64_ADDR16:
2804 case R_PPC64_ADDR16_DS:
2805 case R_PPC64_ADDR16_HA:
2806 case R_PPC64_ADDR16_HI:
2807 case R_PPC64_ADDR16_HIGHER:
2808 case R_PPC64_ADDR16_HIGHERA:
2809 case R_PPC64_ADDR16_HIGHEST:
2810 case R_PPC64_ADDR16_HIGHESTA:
2811 case R_PPC64_ADDR16_LO:
2812 case R_PPC64_ADDR16_LO_DS:
2813 case R_PPC64_ADDR24:
2814 case R_PPC64_ADDR30:
2815 case R_PPC64_ADDR32:
2816 case R_PPC64_UADDR16:
2817 case R_PPC64_UADDR32:
2818 case R_PPC64_UADDR64:
2819 case R_PPC64_TOC:
2820 /* Don't propagate .opd relocs. */
2821 if (NO_OPD_RELOCS && is_opd)
2822 break;
2823
2824 /* If we are creating a shared library, and this is a reloc
2825 against a global symbol, or a non PC relative reloc
2826 against a local symbol, then we need to copy the reloc
2827 into the shared library. However, if we are linking with
2828 -Bsymbolic, we do not need to copy a reloc against a
2829 global symbol which is defined in an object we are
2830 including in the link (i.e., DEF_REGULAR is set). At
2831 this point we have not seen all the input files, so it is
2832 possible that DEF_REGULAR is not set now but will be set
2833 later (it is never cleared). In case of a weak definition,
2834 DEF_REGULAR may be cleared later by a strong definition in
2835 a shared library. We account for that possibility below by
2836 storing information in the relocs_copied field of the hash
2837 table entry. A similar situation occurs when creating
2838 shared libraries and symbol visibility changes render the
2839 symbol local.
2840
2841 If on the other hand, we are creating an executable, we
2842 may need to keep relocations for symbols satisfied by a
2843 dynamic library if we manage to avoid copy relocs for the
2844 symbol. */
2845 if ((info->shared
2846 && (sec->flags & SEC_ALLOC) != 0
2847 && (IS_ABSOLUTE_RELOC (r_type)
2848 || (h != NULL
2849 && (! info->symbolic
2850 || h->root.type == bfd_link_hash_defweak
2851 || (h->elf_link_hash_flags
2852 & ELF_LINK_HASH_DEF_REGULAR) == 0))))
2853 || (!info->shared
2854 && (sec->flags & SEC_ALLOC) != 0
2855 && h != NULL
2856 && (h->root.type == bfd_link_hash_defweak
2857 || (h->elf_link_hash_flags
2858 & ELF_LINK_HASH_DEF_REGULAR) == 0)))
2859 {
2860 struct ppc_dyn_relocs *p;
2861 struct ppc_dyn_relocs **head;
2862
2863 /* We must copy these reloc types into the output file.
2864 Create a reloc section in dynobj and make room for
2865 this reloc. */
2866 if (sreloc == NULL)
2867 {
2868 const char *name;
2869 bfd *dynobj;
2870
2871 name = (bfd_elf_string_from_elf_section
2872 (abfd,
2873 elf_elfheader (abfd)->e_shstrndx,
2874 elf_section_data (sec)->rel_hdr.sh_name));
2875 if (name == NULL)
2876 return false;
2877
2878 if (strncmp (name, ".rela", 5) != 0
2879 || strcmp (bfd_get_section_name (abfd, sec),
2880 name + 5) != 0)
2881 {
2882 (*_bfd_error_handler)
2883 (_("%s: bad relocation section name `%s\'"),
2884 bfd_archive_filename (abfd), name);
2885 bfd_set_error (bfd_error_bad_value);
2886 }
2887
2888 dynobj = htab->elf.dynobj;
2889 sreloc = bfd_get_section_by_name (dynobj, name);
2890 if (sreloc == NULL)
2891 {
2892 flagword flags;
2893
2894 sreloc = bfd_make_section (dynobj, name);
2895 flags = (SEC_HAS_CONTENTS | SEC_READONLY
2896 | SEC_IN_MEMORY | SEC_LINKER_CREATED);
2897 if ((sec->flags & SEC_ALLOC) != 0)
2898 flags |= SEC_ALLOC | SEC_LOAD;
2899 if (sreloc == NULL
2900 || ! bfd_set_section_flags (dynobj, sreloc, flags)
2901 || ! bfd_set_section_alignment (dynobj, sreloc, 3))
2902 return false;
2903 }
2904 elf_section_data (sec)->sreloc = sreloc;
2905 }
2906
2907 /* If this is a global symbol, we count the number of
2908 relocations we need for this symbol. */
2909 if (h != NULL)
2910 {
2911 head = &((struct ppc_link_hash_entry *) h)->dyn_relocs;
2912 }
2913 else
2914 {
2915 /* Track dynamic relocs needed for local syms too.
2916 We really need local syms available to do this
2917 easily. Oh well. */
2918
2919 asection *s;
2920 s = bfd_section_from_r_symndx (abfd, &htab->sym_sec,
2921 sec, r_symndx);
2922 if (s == NULL)
2923 return false;
2924
2925 head = ((struct ppc_dyn_relocs **)
2926 &elf_section_data (s)->local_dynrel);
2927 }
2928
2929 p = *head;
2930 if (p == NULL || p->sec != sec)
2931 {
2932 p = ((struct ppc_dyn_relocs *)
2933 bfd_alloc (htab->elf.dynobj,
2934 (bfd_size_type) sizeof *p));
2935 if (p == NULL)
2936 return false;
2937 p->next = *head;
2938 *head = p;
2939 p->sec = sec;
2940 p->count = 0;
2941 p->pc_count = 0;
2942 }
2943
2944 p->count += 1;
2945 if (!IS_ABSOLUTE_RELOC (r_type))
2946 p->pc_count += 1;
2947 }
2948 break;
2949
2950 default:
2951 break;
2952 }
2953 }
2954
2955 return true;
2956 }
2957
2958 /* Return the section that should be marked against GC for a given
2959 relocation. */
2960
2961 static asection *
2962 ppc64_elf_gc_mark_hook (abfd, info, rel, h, sym)
2963 bfd *abfd;
2964 struct bfd_link_info *info ATTRIBUTE_UNUSED;
2965 Elf_Internal_Rela *rel;
2966 struct elf_link_hash_entry *h;
2967 Elf_Internal_Sym *sym;
2968 {
2969 if (h != NULL)
2970 {
2971 enum elf_ppc_reloc_type r_type;
2972
2973 r_type = (enum elf_ppc_reloc_type) ELF64_R_TYPE (rel->r_info);
2974 switch (r_type)
2975 {
2976 case R_PPC64_GNU_VTINHERIT:
2977 case R_PPC64_GNU_VTENTRY:
2978 break;
2979
2980 default:
2981 switch (h->root.type)
2982 {
2983 case bfd_link_hash_defined:
2984 case bfd_link_hash_defweak:
2985 return h->root.u.def.section;
2986
2987 case bfd_link_hash_common:
2988 return h->root.u.c.p->section;
2989
2990 default:
2991 break;
2992 }
2993 }
2994 }
2995 else
2996 {
2997 return bfd_section_from_elf_index (abfd, sym->st_shndx);
2998 }
2999
3000 return NULL;
3001 }
3002
3003 /* Update the .got, .plt. and dynamic reloc reference counts for the
3004 section being removed. */
3005
3006 static boolean
3007 ppc64_elf_gc_sweep_hook (abfd, info, sec, relocs)
3008 bfd *abfd;
3009 struct bfd_link_info *info ATTRIBUTE_UNUSED;
3010 asection *sec;
3011 const Elf_Internal_Rela *relocs;
3012 {
3013 Elf_Internal_Shdr *symtab_hdr;
3014 struct elf_link_hash_entry **sym_hashes;
3015 bfd_signed_vma *local_got_refcounts;
3016 const Elf_Internal_Rela *rel, *relend;
3017
3018 elf_section_data (sec)->local_dynrel = NULL;
3019
3020 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
3021 sym_hashes = elf_sym_hashes (abfd);
3022 local_got_refcounts = elf_local_got_refcounts (abfd);
3023
3024 relend = relocs + sec->reloc_count;
3025 for (rel = relocs; rel < relend; rel++)
3026 {
3027 unsigned long r_symndx;
3028 enum elf_ppc_reloc_type r_type;
3029 struct elf_link_hash_entry *h;
3030
3031 r_symndx = ELF64_R_SYM (rel->r_info);
3032 r_type = (enum elf_ppc_reloc_type) ELF64_R_TYPE (rel->r_info);
3033 switch (r_type)
3034 {
3035 case R_PPC64_GOT16:
3036 case R_PPC64_GOT16_DS:
3037 case R_PPC64_GOT16_HA:
3038 case R_PPC64_GOT16_HI:
3039 case R_PPC64_GOT16_LO:
3040 case R_PPC64_GOT16_LO_DS:
3041 if (r_symndx >= symtab_hdr->sh_info)
3042 {
3043 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
3044 if (h->got.refcount > 0)
3045 h->got.refcount--;
3046 }
3047 else
3048 {
3049 if (local_got_refcounts[r_symndx] > 0)
3050 local_got_refcounts[r_symndx]--;
3051 }
3052 break;
3053
3054 case R_PPC64_PLT16_HA:
3055 case R_PPC64_PLT16_HI:
3056 case R_PPC64_PLT16_LO:
3057 case R_PPC64_PLT32:
3058 case R_PPC64_PLT64:
3059 if (r_symndx >= symtab_hdr->sh_info)
3060 {
3061 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
3062 if (h->plt.refcount > 0)
3063 h->plt.refcount--;
3064 }
3065 break;
3066
3067 case R_PPC64_REL14:
3068 case R_PPC64_REL14_BRNTAKEN:
3069 case R_PPC64_REL14_BRTAKEN:
3070 case R_PPC64_REL24:
3071 if (r_symndx >= symtab_hdr->sh_info)
3072 {
3073 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
3074 if (h->plt.refcount > 0)
3075 h->plt.refcount--;
3076 }
3077 break;
3078
3079 case R_PPC64_REL32:
3080 case R_PPC64_REL64:
3081 if (r_symndx >= symtab_hdr->sh_info)
3082 {
3083 struct ppc_link_hash_entry *eh;
3084 struct ppc_dyn_relocs **pp;
3085 struct ppc_dyn_relocs *p;
3086
3087 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
3088 eh = (struct ppc_link_hash_entry *) h;
3089
3090 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next)
3091 if (p->sec == sec)
3092 {
3093 p->pc_count -= 1;
3094 p->count -= 1;
3095 if (p->count == 0)
3096 *pp = p->next;
3097 break;
3098 }
3099 }
3100 break;
3101
3102 case R_PPC64_ADDR14:
3103 case R_PPC64_ADDR14_BRNTAKEN:
3104 case R_PPC64_ADDR14_BRTAKEN:
3105 case R_PPC64_ADDR16:
3106 case R_PPC64_ADDR16_DS:
3107 case R_PPC64_ADDR16_HA:
3108 case R_PPC64_ADDR16_HI:
3109 case R_PPC64_ADDR16_HIGHER:
3110 case R_PPC64_ADDR16_HIGHERA:
3111 case R_PPC64_ADDR16_HIGHEST:
3112 case R_PPC64_ADDR16_HIGHESTA:
3113 case R_PPC64_ADDR16_LO:
3114 case R_PPC64_ADDR16_LO_DS:
3115 case R_PPC64_ADDR24:
3116 case R_PPC64_ADDR30:
3117 case R_PPC64_ADDR32:
3118 case R_PPC64_ADDR64:
3119 case R_PPC64_UADDR16:
3120 case R_PPC64_UADDR32:
3121 case R_PPC64_UADDR64:
3122 case R_PPC64_TOC:
3123 if (r_symndx >= symtab_hdr->sh_info)
3124 {
3125 struct ppc_link_hash_entry *eh;
3126 struct ppc_dyn_relocs **pp;
3127 struct ppc_dyn_relocs *p;
3128
3129 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
3130 eh = (struct ppc_link_hash_entry *) h;
3131
3132 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next)
3133 if (p->sec == sec)
3134 {
3135 p->count -= 1;
3136 if (p->count == 0)
3137 *pp = p->next;
3138 break;
3139 }
3140 }
3141 break;
3142
3143 default:
3144 break;
3145 }
3146 }
3147 return true;
3148 }
3149
3150 /* Called via elf_link_hash_traverse to transfer dynamic linking
3151 information on function code symbol entries to their corresponding
3152 function descriptor symbol entries. */
3153 static boolean
3154 func_desc_adjust (h, inf)
3155 struct elf_link_hash_entry *h;
3156 PTR inf;
3157 {
3158 struct bfd_link_info *info;
3159 struct ppc_link_hash_table *htab;
3160
3161 if (h->root.type == bfd_link_hash_indirect)
3162 return true;
3163
3164 if (h->root.type == bfd_link_hash_warning)
3165 h = (struct elf_link_hash_entry *) h->root.u.i.link;
3166
3167 info = (struct bfd_link_info *) inf;
3168 htab = ppc_hash_table (info);
3169
3170 /* If this is a function code symbol, transfer dynamic linking
3171 information to the function descriptor symbol. */
3172 if (!((struct ppc_link_hash_entry *) h)->is_func)
3173 return true;
3174
3175 if (h->root.type == bfd_link_hash_undefweak
3176 && (h->elf_link_hash_flags & ELF_LINK_HASH_REF_REGULAR))
3177 htab->have_undefweak = true;
3178
3179 if (h->plt.refcount > 0
3180 && h->root.root.string[0] == '.'
3181 && h->root.root.string[1] != '\0')
3182 {
3183 struct elf_link_hash_entry *fdh = ((struct ppc_link_hash_entry *) h)->oh;
3184 boolean force_local;
3185
3186 /* Find the corresponding function descriptor symbol. Create it
3187 as undefined if necessary. */
3188
3189 if (fdh == NULL)
3190 fdh = elf_link_hash_lookup (&htab->elf, h->root.root.string + 1,
3191 false, false, true);
3192
3193 if (fdh == NULL
3194 && info->shared
3195 && (h->root.type == bfd_link_hash_undefined
3196 || h->root.type == bfd_link_hash_undefweak))
3197 {
3198 bfd *abfd;
3199 asymbol *newsym;
3200
3201 abfd = h->root.u.undef.abfd;
3202 newsym = bfd_make_empty_symbol (abfd);
3203 newsym->name = h->root.root.string + 1;
3204 newsym->section = bfd_und_section_ptr;
3205 newsym->value = 0;
3206 newsym->flags = BSF_OBJECT;
3207 if (h->root.type == bfd_link_hash_undefweak)
3208 newsym->flags |= BSF_WEAK;
3209
3210 if ( !(_bfd_generic_link_add_one_symbol
3211 (info, abfd, newsym->name, newsym->flags,
3212 newsym->section, newsym->value, NULL, false, false,
3213 (struct bfd_link_hash_entry **) &fdh)))
3214 {
3215 return false;
3216 }
3217 fdh->elf_link_hash_flags &= ~ELF_LINK_NON_ELF;
3218 }
3219
3220 if (fdh != NULL
3221 && (fdh->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0
3222 && (info->shared
3223 || (fdh->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0
3224 || (fdh->elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) != 0))
3225 {
3226 if (fdh->dynindx == -1)
3227 if (! bfd_elf64_link_record_dynamic_symbol (info, fdh))
3228 return false;
3229 fdh->elf_link_hash_flags |= (h->elf_link_hash_flags
3230 & (ELF_LINK_HASH_REF_REGULAR
3231 | ELF_LINK_HASH_REF_DYNAMIC
3232 | ELF_LINK_HASH_REF_REGULAR_NONWEAK
3233 | ELF_LINK_NON_GOT_REF));
3234 if (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
3235 {
3236 fdh->plt.refcount = h->plt.refcount;
3237 fdh->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
3238 }
3239 ((struct ppc_link_hash_entry *) fdh)->is_func_descriptor = 1;
3240 ((struct ppc_link_hash_entry *) fdh)->oh = h;
3241 ((struct ppc_link_hash_entry *) h)->oh = fdh;
3242 }
3243
3244 /* Now that the info is on the function descriptor, clear the
3245 function code sym info. Any function code syms for which we
3246 don't have a definition in a regular file, we force local.
3247 This prevents a shared library from exporting syms that have
3248 been imported from another library. Function code syms that
3249 are really in the library we must leave global to prevent the
3250 linker dragging in a definition from a static library. */
3251 force_local = (info->shared
3252 && ((h->elf_link_hash_flags
3253 & ELF_LINK_HASH_DEF_REGULAR) == 0
3254 || fdh == NULL
3255 || (fdh->elf_link_hash_flags
3256 & ELF_LINK_HASH_DEF_REGULAR) == 0
3257 || (fdh->elf_link_hash_flags
3258 & ELF_LINK_FORCED_LOCAL) != 0));
3259 _bfd_elf_link_hash_hide_symbol (info, h, force_local);
3260 }
3261
3262 return true;
3263 }
3264
3265 #define MIN_SAVE_FPR 14
3266 #define MAX_SAVE_FPR 31
3267
3268 /* Called near the start of bfd_elf_size_dynamic_sections. We use
3269 this hook to a) provide some gcc support functions, and b) transfer
3270 dynamic linking information gathered so far on function code symbol
3271 entries, to their corresponding function descriptor symbol entries. */
3272 static boolean
3273 ppc64_elf_func_desc_adjust (obfd, info)
3274 bfd *obfd ATTRIBUTE_UNUSED;
3275 struct bfd_link_info *info;
3276 {
3277 struct ppc_link_hash_table *htab;
3278 unsigned int lowest_savef = MAX_SAVE_FPR + 2;
3279 unsigned int lowest_restf = MAX_SAVE_FPR + 2;
3280 unsigned int i;
3281 struct elf_link_hash_entry *h;
3282 bfd_byte *p;
3283 char sym[10];
3284
3285 htab = ppc_hash_table (info);
3286
3287 if (htab->sfpr == NULL)
3288 /* We don't have any relocs. */
3289 return true;
3290
3291 /* First provide any missing ._savef* and ._restf* functions. */
3292 memcpy (sym, "._savef14", 10);
3293 for (i = MIN_SAVE_FPR; i <= MAX_SAVE_FPR; i++)
3294 {
3295 sym[7] = i / 10 + '0';
3296 sym[8] = i % 10 + '0';
3297 h = elf_link_hash_lookup (&htab->elf, sym, false, false, true);
3298 if (h != NULL
3299 && h->root.type == bfd_link_hash_undefined)
3300 {
3301 if (lowest_savef > i)
3302 lowest_savef = i;
3303 h->root.type = bfd_link_hash_defined;
3304 h->root.u.def.section = htab->sfpr;
3305 h->root.u.def.value = (i - lowest_savef) * 4;
3306 h->type = STT_FUNC;
3307 h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
3308 _bfd_elf_link_hash_hide_symbol (info, h, info->shared);
3309 }
3310 }
3311
3312 memcpy (sym, "._restf14", 10);
3313 for (i = MIN_SAVE_FPR; i <= MAX_SAVE_FPR; i++)
3314 {
3315 sym[7] = i / 10 + '0';
3316 sym[8] = i % 10 + '0';
3317 h = elf_link_hash_lookup (&htab->elf, sym, false, false, true);
3318 if (h != NULL
3319 && h->root.type == bfd_link_hash_undefined)
3320 {
3321 if (lowest_restf > i)
3322 lowest_restf = i;
3323 h->root.type = bfd_link_hash_defined;
3324 h->root.u.def.section = htab->sfpr;
3325 h->root.u.def.value = ((MAX_SAVE_FPR + 2 - lowest_savef) * 4
3326 + (i - lowest_restf) * 4);
3327 h->type = STT_FUNC;
3328 h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
3329 _bfd_elf_link_hash_hide_symbol (info, h, info->shared);
3330 }
3331 }
3332
3333 elf_link_hash_traverse (&htab->elf, func_desc_adjust, (PTR) info);
3334
3335 htab->sfpr->_raw_size = ((MAX_SAVE_FPR + 2 - lowest_savef) * 4
3336 + (MAX_SAVE_FPR + 2 - lowest_restf) * 4);
3337
3338 if (htab->sfpr->_raw_size == 0)
3339 {
3340 if (!htab->have_undefweak)
3341 {
3342 _bfd_strip_section_from_output (info, htab->sfpr);
3343 return true;
3344 }
3345
3346 htab->sfpr->_raw_size = 4;
3347 }
3348
3349 p = (bfd_byte *) bfd_alloc (htab->elf.dynobj, htab->sfpr->_raw_size);
3350 if (p == NULL)
3351 return false;
3352 htab->sfpr->contents = p;
3353
3354 for (i = lowest_savef; i <= MAX_SAVE_FPR; i++)
3355 {
3356 unsigned int fpr = i << 21;
3357 unsigned int stackoff = (1 << 16) - (MAX_SAVE_FPR + 1 - i) * 8;
3358 bfd_put_32 (htab->elf.dynobj, STFD_FR0_0R1 + fpr + stackoff, p);
3359 p += 4;
3360 }
3361 if (lowest_savef <= MAX_SAVE_FPR)
3362 {
3363 bfd_put_32 (htab->elf.dynobj, BLR, p);
3364 p += 4;
3365 }
3366
3367 for (i = lowest_restf; i <= MAX_SAVE_FPR; i++)
3368 {
3369 unsigned int fpr = i << 21;
3370 unsigned int stackoff = (1 << 16) - (MAX_SAVE_FPR + 1 - i) * 8;
3371 bfd_put_32 (htab->elf.dynobj, LFD_FR0_0R1 + fpr + stackoff, p);
3372 p += 4;
3373 }
3374 if (lowest_restf <= MAX_SAVE_FPR
3375 || htab->sfpr->_raw_size == 4)
3376 {
3377 bfd_put_32 (htab->elf.dynobj, BLR, p);
3378 }
3379
3380 return true;
3381 }
3382
3383 /* Adjust a symbol defined by a dynamic object and referenced by a
3384 regular object. The current definition is in some section of the
3385 dynamic object, but we're not including those sections. We have to
3386 change the definition to something the rest of the link can
3387 understand. */
3388
3389 static boolean
3390 ppc64_elf_adjust_dynamic_symbol (info, h)
3391 struct bfd_link_info *info;
3392 struct elf_link_hash_entry *h;
3393 {
3394 struct ppc_link_hash_table *htab;
3395 struct ppc_link_hash_entry * eh;
3396 struct ppc_dyn_relocs *p;
3397 asection *s;
3398 unsigned int power_of_two;
3399
3400 htab = ppc_hash_table (info);
3401
3402 /* Deal with function syms. */
3403 if (h->type == STT_FUNC
3404 || (h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0)
3405 {
3406 /* Clear procedure linkage table information for any symbol that
3407 won't need a .plt entry. */
3408 if (!((struct ppc_link_hash_entry *) h)->is_func_descriptor
3409 || h->plt.refcount <= 0
3410 || (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0
3411 || (! info->shared
3412 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) == 0
3413 && (h->elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) == 0))
3414 {
3415 h->plt.offset = (bfd_vma) -1;
3416 h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
3417 }
3418 return true;
3419 }
3420 else
3421 h->plt.offset = (bfd_vma) -1;
3422
3423 /* If this is a weak symbol, and there is a real definition, the
3424 processor independent code will have arranged for us to see the
3425 real definition first, and we can just use the same value. */
3426 if (h->weakdef != NULL)
3427 {
3428 BFD_ASSERT (h->weakdef->root.type == bfd_link_hash_defined
3429 || h->weakdef->root.type == bfd_link_hash_defweak);
3430 h->root.u.def.section = h->weakdef->root.u.def.section;
3431 h->root.u.def.value = h->weakdef->root.u.def.value;
3432 return true;
3433 }
3434
3435 /* This is a reference to a symbol defined by a dynamic object which
3436 is not a function. */
3437
3438 /* If we are creating a shared library, we must presume that the
3439 only references to the symbol are via the global offset table.
3440 For such cases we need not do anything here; the relocations will
3441 be handled correctly by relocate_section. */
3442 if (info->shared)
3443 return true;
3444
3445 /* If there are no references to this symbol that do not use the
3446 GOT, we don't need to generate a copy reloc. */
3447 if ((h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0)
3448 return true;
3449
3450 eh = (struct ppc_link_hash_entry *) h;
3451 for (p = eh->dyn_relocs; p != NULL; p = p->next)
3452 {
3453 s = p->sec->output_section;
3454 if (s != NULL && (s->flags & SEC_READONLY) != 0)
3455 break;
3456 }
3457
3458 /* If we didn't find any dynamic relocs in read-only sections, then
3459 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
3460 if (p == NULL)
3461 {
3462 h->elf_link_hash_flags &= ~ELF_LINK_NON_GOT_REF;
3463 return true;
3464 }
3465
3466 /* We must allocate the symbol in our .dynbss section, which will
3467 become part of the .bss section of the executable. There will be
3468 an entry for this symbol in the .dynsym section. The dynamic
3469 object will contain position independent code, so all references
3470 from the dynamic object to this symbol will go through the global
3471 offset table. The dynamic linker will use the .dynsym entry to
3472 determine the address it must put in the global offset table, so
3473 both the dynamic object and the regular object will refer to the
3474 same memory location for the variable. */
3475
3476 /* We must generate a R_PPC_COPY reloc to tell the dynamic linker to
3477 copy the initial value out of the dynamic object and into the
3478 runtime process image. We need to remember the offset into the
3479 .rela.bss section we are going to use. */
3480 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
3481 {
3482 htab->srelbss->_raw_size += sizeof (Elf64_External_Rela);
3483 h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_COPY;
3484 }
3485
3486 /* We need to figure out the alignment required for this symbol. I
3487 have no idea how ELF linkers handle this. */
3488 power_of_two = bfd_log2 (h->size);
3489 if (power_of_two > 4)
3490 power_of_two = 4;
3491
3492 /* Apply the required alignment. */
3493 s = htab->sdynbss;
3494 s->_raw_size = BFD_ALIGN (s->_raw_size, (bfd_size_type) (1 << power_of_two));
3495 if (power_of_two > bfd_get_section_alignment (htab->elf.dynobj, s))
3496 {
3497 if (! bfd_set_section_alignment (htab->elf.dynobj, s, power_of_two))
3498 return false;
3499 }
3500
3501 /* Define the symbol as being at this point in the section. */
3502 h->root.u.def.section = s;
3503 h->root.u.def.value = s->_raw_size;
3504
3505 /* Increment the section size to make room for the symbol. */
3506 s->_raw_size += h->size;
3507
3508 return true;
3509 }
3510
3511 /* If given a function descriptor symbol, hide both the function code
3512 sym and the descriptor. */
3513 static void
3514 ppc64_elf_hide_symbol (info, h, force_local)
3515 struct bfd_link_info *info;
3516 struct elf_link_hash_entry *h;
3517 boolean force_local;
3518 {
3519 _bfd_elf_link_hash_hide_symbol (info, h, force_local);
3520
3521 if (((struct ppc_link_hash_entry *) h)->is_func_descriptor)
3522 {
3523 struct elf_link_hash_entry *fh = ((struct ppc_link_hash_entry *) h)->oh;
3524
3525 if (fh == NULL)
3526 {
3527 const char *p, *q;
3528 struct ppc_link_hash_table *htab;
3529 char save;
3530
3531 /* We aren't supposed to use alloca in BFD because on
3532 systems which do not have alloca the version in libiberty
3533 calls xmalloc, which might cause the program to crash
3534 when it runs out of memory. This function doesn't have a
3535 return status, so there's no way to gracefully return an
3536 error. So cheat. We know that string[-1] can be safely
3537 dereferenced; It's either a string in an ELF string
3538 table, or allocated in an objalloc structure. */
3539
3540 p = h->root.root.string - 1;
3541 save = *p;
3542 *(char *) p = '.';
3543 htab = ppc_hash_table (info);
3544 fh = elf_link_hash_lookup (&htab->elf, p, false, false, false);
3545 *(char *) p = save;
3546
3547 /* Unfortunately, if it so happens that the string we were
3548 looking for was allocated immediately before this string,
3549 then we overwrote the string terminator. That's the only
3550 reason the lookup should fail. */
3551 if (fh == NULL)
3552 {
3553 q = h->root.root.string + strlen (h->root.root.string);
3554 while (q >= h->root.root.string && *q == *p)
3555 --q, --p;
3556 if (q < h->root.root.string && *p == '.')
3557 fh = elf_link_hash_lookup (&htab->elf, p, false, false, false);
3558 }
3559 if (fh != NULL)
3560 {
3561 ((struct ppc_link_hash_entry *) h)->oh = fh;
3562 ((struct ppc_link_hash_entry *) fh)->oh = h;
3563 }
3564 }
3565 if (fh != NULL)
3566 _bfd_elf_link_hash_hide_symbol (info, fh, force_local);
3567 }
3568 }
3569
3570 /* This is the condition under which ppc64_elf_finish_dynamic_symbol
3571 will be called from elflink.h. If elflink.h doesn't call our
3572 finish_dynamic_symbol routine, we'll need to do something about
3573 initializing any .plt and .got entries in ppc64_elf_relocate_section. */
3574 #define WILL_CALL_FINISH_DYNAMIC_SYMBOL(DYN, INFO, H) \
3575 ((DYN) \
3576 && ((INFO)->shared \
3577 || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) \
3578 && ((H)->dynindx != -1 \
3579 || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0))
3580
3581 /* Allocate space in .plt, .got and associated reloc sections for
3582 dynamic relocs. */
3583
3584 static boolean
3585 allocate_dynrelocs (h, inf)
3586 struct elf_link_hash_entry *h;
3587 PTR inf;
3588 {
3589 struct bfd_link_info *info;
3590 struct ppc_link_hash_table *htab;
3591 asection *s;
3592 struct ppc_link_hash_entry *eh;
3593 struct ppc_dyn_relocs *p;
3594
3595 if (h->root.type == bfd_link_hash_indirect)
3596 return true;
3597
3598 if (h->root.type == bfd_link_hash_warning)
3599 h = (struct elf_link_hash_entry *) h->root.u.i.link;
3600
3601 info = (struct bfd_link_info *) inf;
3602 htab = ppc_hash_table (info);
3603
3604 if (htab->elf.dynamic_sections_created
3605 && h->plt.refcount > 0
3606 && h->dynindx != -1)
3607 {
3608 BFD_ASSERT (((struct ppc_link_hash_entry *) h)->is_func_descriptor);
3609
3610 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, info, h))
3611 {
3612 /* If this is the first .plt entry, make room for the special
3613 first entry. */
3614 s = htab->splt;
3615 if (s->_raw_size == 0)
3616 s->_raw_size += PLT_INITIAL_ENTRY_SIZE;
3617
3618 h->plt.offset = s->_raw_size;
3619
3620 /* Make room for this entry. */
3621 s->_raw_size += PLT_ENTRY_SIZE;
3622
3623 /* Make room for the .glink code. */
3624 s = htab->sglink;
3625 if (s->_raw_size == 0)
3626 s->_raw_size += GLINK_CALL_STUB_SIZE;
3627 /* We need bigger stubs past index 32767. */
3628 if (s->_raw_size >= GLINK_CALL_STUB_SIZE + 32768*2*4)
3629 s->_raw_size += 4;
3630 s->_raw_size += 2*4;
3631
3632 /* We also need to make an entry in the .rela.plt section. */
3633 s = htab->srelplt;
3634 s->_raw_size += sizeof (Elf64_External_Rela);
3635 }
3636 else
3637 {
3638 h->plt.offset = (bfd_vma) -1;
3639 h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
3640 }
3641 }
3642 else
3643 {
3644 h->plt.offset = (bfd_vma) -1;
3645 h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
3646 }
3647
3648 if (h->got.refcount > 0)
3649 {
3650 boolean dyn;
3651
3652 /* Make sure this symbol is output as a dynamic symbol.
3653 Undefined weak syms won't yet be marked as dynamic. */
3654 if (h->dynindx == -1
3655 && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0)
3656 {
3657 if (! bfd_elf64_link_record_dynamic_symbol (info, h))
3658 return false;
3659 }
3660
3661 s = htab->sgot;
3662 h->got.offset = s->_raw_size;
3663 s->_raw_size += 8;
3664 dyn = htab->elf.dynamic_sections_created;
3665 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info, h))
3666 htab->srelgot->_raw_size += sizeof (Elf64_External_Rela);
3667 }
3668 else
3669 h->got.offset = (bfd_vma) -1;
3670
3671 eh = (struct ppc_link_hash_entry *) h;
3672 if (eh->dyn_relocs == NULL)
3673 return true;
3674
3675 /* In the shared -Bsymbolic case, discard space allocated for
3676 dynamic pc-relative relocs against symbols which turn out to be
3677 defined in regular objects. For the normal shared case, discard
3678 space for relocs that have become local due to symbol visibility
3679 changes. */
3680
3681 if (info->shared)
3682 {
3683 if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) != 0
3684 && ((h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0
3685 || info->symbolic))
3686 {
3687 struct ppc_dyn_relocs **pp;
3688
3689 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; )
3690 {
3691 p->count -= p->pc_count;
3692 p->pc_count = 0;
3693 if (p->count == 0)
3694 *pp = p->next;
3695 else
3696 pp = &p->next;
3697 }
3698 }
3699 }
3700 else
3701 {
3702 /* For the non-shared case, discard space for relocs against
3703 symbols which turn out to need copy relocs or are not
3704 dynamic. */
3705
3706 if ((h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0
3707 && (((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0
3708 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
3709 || (htab->elf.dynamic_sections_created
3710 && (h->root.type == bfd_link_hash_undefweak
3711 || h->root.type == bfd_link_hash_undefined))))
3712 {
3713 /* Make sure this symbol is output as a dynamic symbol.
3714 Undefined weak syms won't yet be marked as dynamic. */
3715 if (h->dynindx == -1
3716 && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0)
3717 {
3718 if (! bfd_elf64_link_record_dynamic_symbol (info, h))
3719 return false;
3720 }
3721
3722 /* If that succeeded, we know we'll be keeping all the
3723 relocs. */
3724 if (h->dynindx != -1)
3725 goto keep;
3726 }
3727
3728 eh->dyn_relocs = NULL;
3729
3730 keep: ;
3731 }
3732
3733 /* Finally, allocate space. */
3734 for (p = eh->dyn_relocs; p != NULL; p = p->next)
3735 {
3736 asection *sreloc = elf_section_data (p->sec)->sreloc;
3737 sreloc->_raw_size += p->count * sizeof (Elf64_External_Rela);
3738 }
3739
3740 return true;
3741 }
3742
3743 /* Find any dynamic relocs that apply to read-only sections. */
3744
3745 static boolean
3746 readonly_dynrelocs (h, inf)
3747 struct elf_link_hash_entry *h;
3748 PTR inf;
3749 {
3750 struct ppc_link_hash_entry *eh;
3751 struct ppc_dyn_relocs *p;
3752
3753 if (h->root.type == bfd_link_hash_warning)
3754 h = (struct elf_link_hash_entry *) h->root.u.i.link;
3755
3756 eh = (struct ppc_link_hash_entry *) h;
3757 for (p = eh->dyn_relocs; p != NULL; p = p->next)
3758 {
3759 asection *s = p->sec->output_section;
3760
3761 if (s != NULL && (s->flags & SEC_READONLY) != 0)
3762 {
3763 struct bfd_link_info *info = (struct bfd_link_info *) inf;
3764
3765 info->flags |= DF_TEXTREL;
3766
3767 /* Not an error, just cut short the traversal. */
3768 return false;
3769 }
3770 }
3771 return true;
3772 }
3773
3774 /* Set the sizes of the dynamic sections. */
3775
3776 static boolean
3777 ppc64_elf_size_dynamic_sections (output_bfd, info)
3778 bfd *output_bfd ATTRIBUTE_UNUSED;
3779 struct bfd_link_info *info;
3780 {
3781 struct ppc_link_hash_table *htab;
3782 bfd *dynobj;
3783 asection *s;
3784 boolean relocs;
3785 bfd *ibfd;
3786
3787 htab = ppc_hash_table (info);
3788 dynobj = htab->elf.dynobj;
3789 if (dynobj == NULL)
3790 abort ();
3791
3792 if (htab->elf.dynamic_sections_created)
3793 {
3794 /* Set the contents of the .interp section to the interpreter. */
3795 if (! info->shared)
3796 {
3797 s = bfd_get_section_by_name (dynobj, ".interp");
3798 if (s == NULL)
3799 abort ();
3800 s->_raw_size = sizeof ELF_DYNAMIC_INTERPRETER;
3801 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
3802 }
3803 }
3804
3805 /* Set up .got offsets for local syms, and space for local dynamic
3806 relocs. */
3807 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
3808 {
3809 bfd_signed_vma *local_got;
3810 bfd_signed_vma *end_local_got;
3811 bfd_size_type locsymcount;
3812 Elf_Internal_Shdr *symtab_hdr;
3813 asection *srel;
3814
3815 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour)
3816 continue;
3817
3818 for (s = ibfd->sections; s != NULL; s = s->next)
3819 {
3820 struct ppc_dyn_relocs *p;
3821
3822 for (p = *((struct ppc_dyn_relocs **)
3823 &elf_section_data (s)->local_dynrel);
3824 p != NULL;
3825 p = p->next)
3826 {
3827 if (!bfd_is_abs_section (p->sec)
3828 && bfd_is_abs_section (p->sec->output_section))
3829 {
3830 /* Input section has been discarded, either because
3831 it is a copy of a linkonce section or due to
3832 linker script /DISCARD/, so we'll be discarding
3833 the relocs too. */
3834 }
3835 else if (p->count != 0)
3836 {
3837 srel = elf_section_data (p->sec)->sreloc;
3838 srel->_raw_size += p->count * sizeof (Elf64_External_Rela);
3839 if ((p->sec->output_section->flags & SEC_READONLY) != 0)
3840 info->flags |= DF_TEXTREL;
3841 }
3842 }
3843 }
3844
3845 local_got = elf_local_got_refcounts (ibfd);
3846 if (!local_got)
3847 continue;
3848
3849 symtab_hdr = &elf_tdata (ibfd)->symtab_hdr;
3850 locsymcount = symtab_hdr->sh_info;
3851 end_local_got = local_got + locsymcount;
3852 s = htab->sgot;
3853 srel = htab->srelgot;
3854 for (; local_got < end_local_got; ++local_got)
3855 {
3856 if (*local_got > 0)
3857 {
3858 *local_got = s->_raw_size;
3859 s->_raw_size += 8;
3860 if (info->shared)
3861 srel->_raw_size += sizeof (Elf64_External_Rela);
3862 }
3863 else
3864 *local_got = (bfd_vma) -1;
3865 }
3866 }
3867
3868 /* Allocate global sym .plt and .got entries, and space for global
3869 sym dynamic relocs. */
3870 elf_link_hash_traverse (&htab->elf, allocate_dynrelocs, (PTR) info);
3871
3872 /* We now have determined the sizes of the various dynamic sections.
3873 Allocate memory for them. */
3874 relocs = false;
3875 for (s = dynobj->sections; s != NULL; s = s->next)
3876 {
3877 if ((s->flags & SEC_LINKER_CREATED) == 0)
3878 continue;
3879
3880 if (s == htab->sbrlt || s == htab->srelbrlt)
3881 /* These haven't been allocated yet; don't strip. */
3882 continue;
3883 else if (s == htab->splt
3884 || s == htab->sgot
3885 || s == htab->sglink)
3886 {
3887 /* Strip this section if we don't need it; see the
3888 comment below. */
3889 }
3890 else if (strncmp (bfd_get_section_name (dynobj, s), ".rela", 5) == 0)
3891 {
3892 if (s->_raw_size == 0)
3893 {
3894 /* If we don't need this section, strip it from the
3895 output file. This is mostly to handle .rela.bss and
3896 .rela.plt. We must create both sections in
3897 create_dynamic_sections, because they must be created
3898 before the linker maps input sections to output
3899 sections. The linker does that before
3900 adjust_dynamic_symbol is called, and it is that
3901 function which decides whether anything needs to go
3902 into these sections. */
3903 }
3904 else
3905 {
3906 if (s != htab->srelplt)
3907 relocs = true;
3908
3909 /* We use the reloc_count field as a counter if we need
3910 to copy relocs into the output file. */
3911 s->reloc_count = 0;
3912 }
3913 }
3914 else
3915 {
3916 /* It's not one of our sections, so don't allocate space. */
3917 continue;
3918 }
3919
3920 if (s->_raw_size == 0)
3921 {
3922 _bfd_strip_section_from_output (info, s);
3923 continue;
3924 }
3925
3926 /* Allocate memory for the section contents. We use bfd_zalloc
3927 here in case unused entries are not reclaimed before the
3928 section's contents are written out. This should not happen,
3929 but this way if it does, we get a R_PPC64_NONE reloc instead
3930 of garbage. */
3931 s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->_raw_size);
3932 if (s->contents == NULL)
3933 return false;
3934 }
3935
3936 if (htab->elf.dynamic_sections_created)
3937 {
3938 /* Add some entries to the .dynamic section. We fill in the
3939 values later, in ppc64_elf_finish_dynamic_sections, but we
3940 must add the entries now so that we get the correct size for
3941 the .dynamic section. The DT_DEBUG entry is filled in by the
3942 dynamic linker and used by the debugger. */
3943 #define add_dynamic_entry(TAG, VAL) \
3944 bfd_elf64_add_dynamic_entry (info, (bfd_vma) (TAG), (bfd_vma) (VAL))
3945
3946 if (!info->shared)
3947 {
3948 if (!add_dynamic_entry (DT_DEBUG, 0))
3949 return false;
3950 }
3951
3952 if (htab->splt != NULL && htab->splt->_raw_size != 0)
3953 {
3954 if (!add_dynamic_entry (DT_PLTGOT, 0)
3955 || !add_dynamic_entry (DT_PLTRELSZ, 0)
3956 || !add_dynamic_entry (DT_PLTREL, DT_RELA)
3957 || !add_dynamic_entry (DT_JMPREL, 0)
3958 || !add_dynamic_entry (DT_PPC64_GLINK, 0))
3959 return false;
3960 }
3961
3962 if (NO_OPD_RELOCS)
3963 {
3964 if (!add_dynamic_entry (DT_PPC64_OPD, 0)
3965 || !add_dynamic_entry (DT_PPC64_OPDSZ, 0))
3966 return false;
3967 }
3968
3969 if (relocs)
3970 {
3971 if (!add_dynamic_entry (DT_RELA, 0)
3972 || !add_dynamic_entry (DT_RELASZ, 0)
3973 || !add_dynamic_entry (DT_RELAENT, sizeof (Elf64_External_Rela)))
3974 return false;
3975
3976 /* If any dynamic relocs apply to a read-only section,
3977 then we need a DT_TEXTREL entry. */
3978 if ((info->flags & DF_TEXTREL) == 0)
3979 elf_link_hash_traverse (&htab->elf, readonly_dynrelocs,
3980 (PTR) info);
3981
3982 if ((info->flags & DF_TEXTREL) != 0)
3983 {
3984 if (!add_dynamic_entry (DT_TEXTREL, 0))
3985 return false;
3986 }
3987 }
3988 }
3989 #undef add_dynamic_entry
3990
3991 return true;
3992 }
3993
3994 /* Determine the type of stub needed, if any, for a call. */
3995
3996 static INLINE enum ppc_stub_type
3997 ppc_type_of_stub (input_sec, rel, hash, destination)
3998 asection *input_sec;
3999 const Elf_Internal_Rela *rel;
4000 struct ppc_link_hash_entry **hash;
4001 bfd_vma destination;
4002 {
4003 struct ppc_link_hash_entry *h = *hash;
4004 bfd_vma location;
4005 bfd_vma branch_offset;
4006 bfd_vma max_branch_offset;
4007 unsigned int r_type;
4008
4009 if (h != NULL)
4010 {
4011 if (h->oh != NULL
4012 && h->oh->plt.offset != (bfd_vma) -1
4013 && h->oh->dynindx != -1)
4014 {
4015 *hash = (struct ppc_link_hash_entry *) h->oh;
4016 return ppc_stub_plt_call;
4017 }
4018
4019 if (h->elf.root.type == bfd_link_hash_undefweak
4020 || h->elf.root.type == bfd_link_hash_undefined)
4021 return ppc_stub_none;
4022 }
4023
4024 /* Determine where the call point is. */
4025 location = (input_sec->output_offset
4026 + input_sec->output_section->vma
4027 + rel->r_offset);
4028
4029 branch_offset = destination - location;
4030 r_type = ELF64_R_TYPE (rel->r_info);
4031
4032 /* Determine if a long branch stub is needed. */
4033 max_branch_offset = 1 << 25;
4034 if (r_type != (unsigned int) R_PPC64_REL24)
4035 max_branch_offset = 1 << 15;
4036
4037 if (branch_offset + max_branch_offset >= 2 * max_branch_offset)
4038 /* We need a stub. Figure out whether a long_branch or plt_branch
4039 is needed later. */
4040 return ppc_stub_long_branch;
4041
4042 return ppc_stub_none;
4043 }
4044
4045 /* Build a .plt call stub. */
4046
4047 static bfd_byte *
4048 build_plt_stub (obfd, p, offset, glink)
4049 bfd *obfd;
4050 bfd_byte *p;
4051 int offset;
4052 int glink;
4053 {
4054 #define PPC_LO(v) ((v) & 0xffff)
4055 #define PPC_HI(v) (((v) >> 16) & 0xffff)
4056 #define PPC_HA(v) PPC_HI ((v) + 0x8000)
4057
4058 if (glink)
4059 bfd_put_32 (obfd, LD_R2_40R1, p), p += 4;
4060 bfd_put_32 (obfd, ADDIS_R12_R2 | PPC_HA (offset), p), p += 4;
4061 if (!glink)
4062 bfd_put_32 (obfd, STD_R2_40R1, p), p += 4;
4063 bfd_put_32 (obfd, LD_R11_0R12 | PPC_LO (offset), p), p += 4;
4064 if (PPC_HA (offset + 8) != PPC_HA (offset))
4065 bfd_put_32 (obfd, ADDIS_R12_R12_1, p), p += 4;
4066 offset += 8;
4067 bfd_put_32 (obfd, LD_R2_0R12 | PPC_LO (offset), p), p += 4;
4068 if (PPC_HA (offset + 8) != PPC_HA (offset))
4069 bfd_put_32 (obfd, ADDIS_R12_R12_1, p), p += 4;
4070 offset += 8;
4071 bfd_put_32 (obfd, MTCTR_R11, p), p += 4;
4072 bfd_put_32 (obfd, LD_R11_0R12 | PPC_LO (offset), p), p += 4;
4073 bfd_put_32 (obfd, BCTR, p), p += 4;
4074 return p;
4075 }
4076
4077 static boolean
4078 ppc_build_one_stub (gen_entry, in_arg)
4079 struct bfd_hash_entry *gen_entry;
4080 PTR in_arg;
4081 {
4082 struct ppc_stub_hash_entry *stub_entry;
4083 struct ppc_branch_hash_entry *br_entry;
4084 struct bfd_link_info *info;
4085 struct ppc_link_hash_table *htab;
4086 asection *stub_sec;
4087 bfd *stub_bfd;
4088 bfd_byte *loc;
4089 bfd_byte *p;
4090 unsigned int indx;
4091 bfd_vma off;
4092 int size;
4093
4094 /* Massage our args to the form they really have. */
4095 stub_entry = (struct ppc_stub_hash_entry *) gen_entry;
4096 info = (struct bfd_link_info *) in_arg;
4097
4098 htab = ppc_hash_table (info);
4099 stub_sec = stub_entry->stub_sec;
4100
4101 /* Make a note of the offset within the stubs for this entry. */
4102 stub_entry->stub_offset = stub_sec->_cooked_size;
4103 loc = stub_sec->contents + stub_entry->stub_offset;
4104
4105 stub_bfd = stub_sec->owner;
4106
4107 switch (stub_entry->stub_type)
4108 {
4109 case ppc_stub_long_branch:
4110 /* Branches are relative. This is where we are going to. */
4111 off = (stub_entry->target_value
4112 + stub_entry->target_section->output_offset
4113 + stub_entry->target_section->output_section->vma);
4114
4115 /* And this is where we are coming from. */
4116 off -= (stub_entry->stub_offset
4117 + stub_sec->output_offset
4118 + stub_sec->output_section->vma);
4119
4120 BFD_ASSERT (off + (1 << 25) < (bfd_vma) (1 << 26));
4121
4122 bfd_put_32 (stub_bfd, (bfd_vma) B_DOT | (off & 0x3fffffc), loc);
4123 size = 4;
4124 break;
4125
4126 case ppc_stub_plt_branch:
4127 br_entry = ppc_branch_hash_lookup (&htab->branch_hash_table,
4128 stub_entry->root.string + 9,
4129 false, false);
4130 if (br_entry == NULL)
4131 {
4132 (*_bfd_error_handler) (_("can't find branch stub `%s'"),
4133 stub_entry->root.string + 9);
4134 htab->stub_error = true;
4135 return false;
4136 }
4137
4138 off = (stub_entry->target_value
4139 + stub_entry->target_section->output_offset
4140 + stub_entry->target_section->output_section->vma);
4141
4142 bfd_put_64 (htab->sbrlt->owner, off,
4143 htab->sbrlt->contents + br_entry->offset);
4144
4145 if (info->shared)
4146 {
4147 /* Create a reloc for the branch lookup table entry. */
4148 Elf_Internal_Rela rela;
4149 Elf64_External_Rela *r;
4150
4151 rela.r_offset = (br_entry->offset
4152 + htab->sbrlt->output_offset
4153 + htab->sbrlt->output_section->vma);
4154 rela.r_info = ELF64_R_INFO (0, R_PPC64_RELATIVE);
4155 rela.r_addend = off;
4156
4157 r = (Elf64_External_Rela *) htab->srelbrlt->contents;
4158 r += htab->srelbrlt->reloc_count++;
4159 bfd_elf64_swap_reloca_out (htab->srelbrlt->owner, &rela, r);
4160 }
4161
4162 off = (br_entry->offset
4163 + htab->sbrlt->output_offset
4164 + htab->sbrlt->output_section->vma
4165 - elf_gp (htab->sbrlt->output_section->owner)
4166 - TOC_BASE_OFF);
4167
4168 if (off + 0x80000000 > 0xffffffff || (off & 7) != 0)
4169 {
4170 (*_bfd_error_handler)
4171 (_("linkage table error against `%s'"),
4172 stub_entry->root.string);
4173 bfd_set_error (bfd_error_bad_value);
4174 htab->stub_error = true;
4175 return false;
4176 }
4177
4178 indx = off;
4179 bfd_put_32 (stub_bfd, (bfd_vma) ADDIS_R12_R2 | PPC_HA (indx), loc);
4180 bfd_put_32 (stub_bfd, (bfd_vma) LD_R11_0R12 | PPC_LO (indx), loc + 4);
4181 bfd_put_32 (stub_bfd, (bfd_vma) MTCTR_R11, loc + 8);
4182 bfd_put_32 (stub_bfd, (bfd_vma) BCTR, loc + 12);
4183 size = 16;
4184 break;
4185
4186 case ppc_stub_plt_call:
4187 /* Build the .glink lazy link call stub. */
4188 p = htab->sglink->contents + htab->sglink->_cooked_size;
4189 indx = htab->sglink->reloc_count;
4190 if (indx < 0x8000)
4191 {
4192 bfd_put_32 (htab->sglink->owner, LI_R0_0 | indx, p);
4193 p += 4;
4194 }
4195 else
4196 {
4197 bfd_put_32 (htab->sglink->owner, LIS_R0_0 | PPC_HI (indx), p);
4198 p += 4;
4199 bfd_put_32 (htab->sglink->owner, ORI_R0_R0_0 | PPC_LO (indx), p);
4200 p += 4;
4201 }
4202 bfd_put_32 (htab->sglink->owner,
4203 B_DOT | ((htab->sglink->contents - p) & 0x3fffffc), p);
4204 p += 4;
4205 htab->sglink->_cooked_size = p - htab->sglink->contents;
4206 htab->sglink->reloc_count += 1;
4207
4208 /* Do the best we can for shared libraries built without
4209 exporting ".foo" for each "foo". This can happen when symbol
4210 versioning scripts strip all bar a subset of symbols. */
4211 if (stub_entry->h->oh->root.type != bfd_link_hash_defined
4212 && stub_entry->h->oh->root.type != bfd_link_hash_defweak)
4213 {
4214 /* Point the symbol at the stub. There may be multiple stubs,
4215 we don't really care; The main thing is to make this sym
4216 defined somewhere. */
4217 stub_entry->h->oh->root.type = bfd_link_hash_defined;
4218 stub_entry->h->oh->root.u.def.section = stub_entry->stub_sec;
4219 stub_entry->h->oh->root.u.def.value = stub_entry->stub_offset;
4220 }
4221
4222 /* Now build the stub. */
4223 off = stub_entry->h->elf.plt.offset;
4224 if (off >= (bfd_vma) -2)
4225 abort ();
4226
4227 off &= ~ (bfd_vma) 1;
4228 off += (htab->splt->output_offset
4229 + htab->splt->output_section->vma
4230 - elf_gp (htab->splt->output_section->owner)
4231 - TOC_BASE_OFF);
4232
4233 if (off + 0x80000000 > 0xffffffff || (off & 7) != 0)
4234 {
4235 (*_bfd_error_handler)
4236 (_("linkage table error against `%s'"),
4237 stub_entry->h->elf.root.root.string);
4238 bfd_set_error (bfd_error_bad_value);
4239 htab->stub_error = true;
4240 return false;
4241 }
4242
4243 p = build_plt_stub (stub_bfd, loc, (int) off, 0);
4244 size = p - loc;
4245 break;
4246
4247 default:
4248 BFD_FAIL ();
4249 return false;
4250 }
4251
4252 stub_sec->_cooked_size += size;
4253 return true;
4254 }
4255
4256 /* As above, but don't actually build the stub. Just bump offset so
4257 we know stub section sizes, and select plt_branch stubs where
4258 long_branch stubs won't do. */
4259
4260 static boolean
4261 ppc_size_one_stub (gen_entry, in_arg)
4262 struct bfd_hash_entry *gen_entry;
4263 PTR in_arg;
4264 {
4265 struct ppc_stub_hash_entry *stub_entry;
4266 struct ppc_link_hash_table *htab;
4267 bfd_vma off;
4268 int size;
4269
4270 /* Massage our args to the form they really have. */
4271 stub_entry = (struct ppc_stub_hash_entry *) gen_entry;
4272 htab = (struct ppc_link_hash_table *) in_arg;
4273
4274 if (stub_entry->stub_type == ppc_stub_plt_call)
4275 {
4276 off = stub_entry->h->elf.plt.offset & ~(bfd_vma) 1;
4277 off += (htab->splt->output_offset
4278 + htab->splt->output_section->vma
4279 - elf_gp (htab->splt->output_section->owner)
4280 - TOC_BASE_OFF);
4281
4282 size = 28;
4283 if (PPC_HA ((int) off + 16) != PPC_HA ((int) off))
4284 size += 4;
4285 }
4286 else
4287 {
4288 /* ppc_stub_long_branch or ppc_stub_plt_branch. */
4289 stub_entry->stub_type = ppc_stub_long_branch;
4290 size = 4;
4291
4292 off = (stub_entry->target_value
4293 + stub_entry->target_section->output_offset
4294 + stub_entry->target_section->output_section->vma);
4295 off -= (stub_entry->stub_sec->_raw_size
4296 + stub_entry->stub_sec->output_offset
4297 + stub_entry->stub_sec->output_section->vma);
4298
4299 if (off + (1 << 25) >= (bfd_vma) (1 << 26))
4300 {
4301 struct ppc_branch_hash_entry *br_entry;
4302
4303 br_entry = ppc_branch_hash_lookup (&htab->branch_hash_table,
4304 stub_entry->root.string + 9,
4305 true, false);
4306 if (br_entry == NULL)
4307 {
4308 (*_bfd_error_handler) (_("can't build branch stub `%s'"),
4309 stub_entry->root.string + 9);
4310 htab->stub_error = true;
4311 return false;
4312 }
4313
4314 if (br_entry->iter != htab->stub_iteration)
4315 {
4316 br_entry->iter = htab->stub_iteration;
4317 br_entry->offset = htab->sbrlt->_raw_size;
4318 htab->sbrlt->_raw_size += 8;
4319 }
4320 stub_entry->stub_type = ppc_stub_plt_branch;
4321 size = 16;
4322 }
4323 }
4324
4325 stub_entry->stub_sec->_raw_size += size;
4326 return true;
4327 }
4328
4329 /* Set up various things so that we can make a list of input sections
4330 for each output section included in the link. Returns -1 on error,
4331 0 when no stubs will be needed, and 1 on success. */
4332
4333 int
4334 ppc64_elf_setup_section_lists (output_bfd, info)
4335 bfd *output_bfd;
4336 struct bfd_link_info *info;
4337 {
4338 bfd *input_bfd;
4339 unsigned int bfd_count;
4340 int top_id, top_index;
4341 asection *section;
4342 asection **input_list, **list;
4343 bfd_size_type amt;
4344 struct ppc_link_hash_table *htab = ppc_hash_table (info);
4345
4346 if (htab->elf.root.creator->flavour != bfd_target_elf_flavour
4347 || htab->sbrlt == NULL)
4348 return 0;
4349
4350 /* Count the number of input BFDs and find the top input section id. */
4351 for (input_bfd = info->input_bfds, bfd_count = 0, top_id = 0;
4352 input_bfd != NULL;
4353 input_bfd = input_bfd->link_next)
4354 {
4355 bfd_count += 1;
4356 for (section = input_bfd->sections;
4357 section != NULL;
4358 section = section->next)
4359 {
4360 if (top_id < section->id)
4361 top_id = section->id;
4362 }
4363 }
4364 htab->bfd_count = bfd_count;
4365
4366 amt = sizeof (struct map_stub) * (top_id + 1);
4367 htab->stub_group = (struct map_stub *) bfd_zmalloc (amt);
4368 if (htab->stub_group == NULL)
4369 return -1;
4370
4371 /* We can't use output_bfd->section_count here to find the top output
4372 section index as some sections may have been removed, and
4373 _bfd_strip_section_from_output doesn't renumber the indices. */
4374 for (section = output_bfd->sections, top_index = 0;
4375 section != NULL;
4376 section = section->next)
4377 {
4378 if (top_index < section->index)
4379 top_index = section->index;
4380 }
4381
4382 htab->top_index = top_index;
4383 amt = sizeof (asection *) * (top_index + 1);
4384 input_list = (asection **) bfd_malloc (amt);
4385 htab->input_list = input_list;
4386 if (input_list == NULL)
4387 return -1;
4388
4389 /* For sections we aren't interested in, mark their entries with a
4390 value we can check later. */
4391 list = input_list + top_index;
4392 do
4393 *list = bfd_abs_section_ptr;
4394 while (list-- != input_list);
4395
4396 for (section = output_bfd->sections;
4397 section != NULL;
4398 section = section->next)
4399 {
4400 if ((section->flags & SEC_CODE) != 0)
4401 input_list[section->index] = NULL;
4402 }
4403
4404 return 1;
4405 }
4406
4407 /* The linker repeatedly calls this function for each input section,
4408 in the order that input sections are linked into output sections.
4409 Build lists of input sections to determine groupings between which
4410 we may insert linker stubs. */
4411
4412 void
4413 ppc64_elf_next_input_section (info, isec)
4414 struct bfd_link_info *info;
4415 asection *isec;
4416 {
4417 struct ppc_link_hash_table *htab = ppc_hash_table (info);
4418
4419 if (isec->output_section->index <= htab->top_index)
4420 {
4421 asection **list = htab->input_list + isec->output_section->index;
4422 if (*list != bfd_abs_section_ptr)
4423 {
4424 /* Steal the link_sec pointer for our list. */
4425 #define PREV_SEC(sec) (htab->stub_group[(sec)->id].link_sec)
4426 /* This happens to make the list in reverse order,
4427 which is what we want. */
4428 PREV_SEC (isec) = *list;
4429 *list = isec;
4430 }
4431 }
4432 }
4433
4434 /* See whether we can group stub sections together. Grouping stub
4435 sections may result in fewer stubs. More importantly, we need to
4436 put all .init* and .fini* stubs at the beginning of the .init or
4437 .fini output sections respectively, because glibc splits the
4438 _init and _fini functions into multiple parts. Putting a stub in
4439 the middle of a function is not a good idea. */
4440
4441 static void
4442 group_sections (htab, stub_group_size, stubs_always_before_branch)
4443 struct ppc_link_hash_table *htab;
4444 bfd_size_type stub_group_size;
4445 boolean stubs_always_before_branch;
4446 {
4447 asection **list = htab->input_list + htab->top_index;
4448 do
4449 {
4450 asection *tail = *list;
4451 if (tail == bfd_abs_section_ptr)
4452 continue;
4453 while (tail != NULL)
4454 {
4455 asection *curr;
4456 asection *prev;
4457 bfd_size_type total;
4458
4459 curr = tail;
4460 if (tail->_cooked_size)
4461 total = tail->_cooked_size;
4462 else
4463 total = tail->_raw_size;
4464 while ((prev = PREV_SEC (curr)) != NULL
4465 && ((total += curr->output_offset - prev->output_offset)
4466 < stub_group_size))
4467 curr = prev;
4468
4469 /* OK, the size from the start of CURR to the end is less
4470 than stub_group_size and thus can be handled by one stub
4471 section. (or the tail section is itself larger than
4472 stub_group_size, in which case we may be toast.) We
4473 should really be keeping track of the total size of stubs
4474 added here, as stubs contribute to the final output
4475 section size. That's a little tricky, and this way will
4476 only break if stubs added make the total size more than
4477 2^25, ie. for the default stub_group_size, if stubs total
4478 more than 2834432 bytes, or over 100000 plt call stubs. */
4479 do
4480 {
4481 prev = PREV_SEC (tail);
4482 /* Set up this stub group. */
4483 htab->stub_group[tail->id].link_sec = curr;
4484 }
4485 while (tail != curr && (tail = prev) != NULL);
4486
4487 /* But wait, there's more! Input sections up to stub_group_size
4488 bytes before the stub section can be handled by it too. */
4489 if (!stubs_always_before_branch)
4490 {
4491 total = 0;
4492 while (prev != NULL
4493 && ((total += tail->output_offset - prev->output_offset)
4494 < stub_group_size))
4495 {
4496 tail = prev;
4497 prev = PREV_SEC (tail);
4498 htab->stub_group[tail->id].link_sec = curr;
4499 }
4500 }
4501 tail = prev;
4502 }
4503 }
4504 while (list-- != htab->input_list);
4505 free (htab->input_list);
4506 #undef PREV_SEC
4507 }
4508
4509 /* Read in all local syms for all input bfds. */
4510
4511 static boolean
4512 get_local_syms (input_bfd, htab)
4513 bfd *input_bfd;
4514 struct ppc_link_hash_table *htab;
4515 {
4516 unsigned int bfd_indx;
4517 Elf_Internal_Sym *local_syms, **all_local_syms;
4518
4519 /* We want to read in symbol extension records only once. To do this
4520 we need to read in the local symbols in parallel and save them for
4521 later use; so hold pointers to the local symbols in an array. */
4522 bfd_size_type amt = sizeof (Elf_Internal_Sym *) * htab->bfd_count;
4523 all_local_syms = (Elf_Internal_Sym **) bfd_zmalloc (amt);
4524 htab->all_local_syms = all_local_syms;
4525 if (all_local_syms == NULL)
4526 return false;
4527
4528 /* Walk over all the input BFDs, swapping in local symbols.
4529 If we are creating a shared library, create hash entries for the
4530 export stubs. */
4531 for (bfd_indx = 0;
4532 input_bfd != NULL;
4533 input_bfd = input_bfd->link_next, bfd_indx++)
4534 {
4535 Elf_Internal_Shdr *symtab_hdr;
4536 Elf_Internal_Shdr *shndx_hdr;
4537 Elf_Internal_Sym *isym;
4538 Elf64_External_Sym *ext_syms, *esym, *end_sy;
4539 Elf_External_Sym_Shndx *shndx_buf, *shndx;
4540 bfd_size_type sec_size;
4541
4542 /* We'll need the symbol table in a second. */
4543 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
4544 if (symtab_hdr->sh_info == 0)
4545 continue;
4546
4547 /* We need an array of the local symbols attached to the input bfd.
4548 Unfortunately, we're going to have to read & swap them in. */
4549 sec_size = symtab_hdr->sh_info;
4550 sec_size *= sizeof (Elf_Internal_Sym);
4551 local_syms = (Elf_Internal_Sym *) bfd_malloc (sec_size);
4552 if (local_syms == NULL)
4553 return false;
4554
4555 all_local_syms[bfd_indx] = local_syms;
4556 sec_size = symtab_hdr->sh_info;
4557 sec_size *= sizeof (Elf64_External_Sym);
4558 ext_syms = (Elf64_External_Sym *) bfd_malloc (sec_size);
4559 if (ext_syms == NULL)
4560 return false;
4561
4562 if (bfd_seek (input_bfd, symtab_hdr->sh_offset, SEEK_SET) != 0
4563 || bfd_bread ((PTR) ext_syms, sec_size, input_bfd) != sec_size)
4564 {
4565 error_ret_free_ext_syms:
4566 free (ext_syms);
4567 return false;
4568 }
4569
4570 shndx_buf = NULL;
4571 shndx_hdr = &elf_tdata (input_bfd)->symtab_shndx_hdr;
4572 if (shndx_hdr->sh_size != 0)
4573 {
4574 sec_size = symtab_hdr->sh_info;
4575 sec_size *= sizeof (Elf_External_Sym_Shndx);
4576 shndx_buf = (Elf_External_Sym_Shndx *) bfd_malloc (sec_size);
4577 if (shndx_buf == NULL)
4578 goto error_ret_free_ext_syms;
4579
4580 if (bfd_seek (input_bfd, shndx_hdr->sh_offset, SEEK_SET) != 0
4581 || bfd_bread ((PTR) shndx_buf, sec_size, input_bfd) != sec_size)
4582 {
4583 free (shndx_buf);
4584 goto error_ret_free_ext_syms;
4585 }
4586 }
4587
4588 /* Swap the local symbols in. */
4589 for (esym = ext_syms, end_sy = esym + symtab_hdr->sh_info,
4590 isym = local_syms, shndx = shndx_buf;
4591 esym < end_sy;
4592 esym++, isym++, shndx = (shndx ? shndx + 1 : NULL))
4593 bfd_elf64_swap_symbol_in (input_bfd, esym, shndx, isym);
4594
4595 /* Now we can free the external symbols. */
4596 free (shndx_buf);
4597 free (ext_syms);
4598 }
4599
4600 return true;
4601 }
4602
4603 /* Determine and set the size of the stub section for a final link.
4604
4605 The basic idea here is to examine all the relocations looking for
4606 PC-relative calls to a target that is unreachable with a "bl"
4607 instruction. */
4608
4609 boolean
4610 ppc64_elf_size_stubs (output_bfd, stub_bfd, info, group_size,
4611 add_stub_section, layout_sections_again)
4612 bfd *output_bfd;
4613 bfd *stub_bfd;
4614 struct bfd_link_info *info;
4615 bfd_signed_vma group_size;
4616 asection * (*add_stub_section) PARAMS ((const char *, asection *));
4617 void (*layout_sections_again) PARAMS ((void));
4618 {
4619 bfd_size_type stub_group_size;
4620 boolean stubs_always_before_branch;
4621 boolean ret = false;
4622 struct ppc_link_hash_table *htab = ppc_hash_table (info);
4623
4624 /* Stash our params away. */
4625 htab->stub_bfd = stub_bfd;
4626 htab->add_stub_section = add_stub_section;
4627 htab->layout_sections_again = layout_sections_again;
4628 stubs_always_before_branch = group_size < 0;
4629 if (group_size < 0)
4630 stub_group_size = -group_size;
4631 else
4632 stub_group_size = group_size;
4633 if (stub_group_size == 1)
4634 {
4635 /* Default values. */
4636 stub_group_size = 30720000;
4637 if (htab->has_14bit_branch)
4638 stub_group_size = 30000;
4639 }
4640
4641 group_sections (htab, stub_group_size, stubs_always_before_branch);
4642
4643 if (! get_local_syms (info->input_bfds, htab))
4644 {
4645 if (htab->all_local_syms)
4646 goto error_ret_free_local;
4647 return false;
4648 }
4649
4650 while (1)
4651 {
4652 bfd *input_bfd;
4653 unsigned int bfd_indx;
4654 asection *stub_sec;
4655 boolean stub_changed;
4656
4657 htab->stub_iteration += 1;
4658 stub_changed = false;
4659
4660 for (input_bfd = info->input_bfds, bfd_indx = 0;
4661 input_bfd != NULL;
4662 input_bfd = input_bfd->link_next, bfd_indx++)
4663 {
4664 Elf_Internal_Shdr *symtab_hdr;
4665 asection *section;
4666 Elf_Internal_Sym *local_syms;
4667
4668 /* We'll need the symbol table in a second. */
4669 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
4670 if (symtab_hdr->sh_info == 0)
4671 continue;
4672
4673 local_syms = htab->all_local_syms[bfd_indx];
4674
4675 /* Walk over each section attached to the input bfd. */
4676 for (section = input_bfd->sections;
4677 section != NULL;
4678 section = section->next)
4679 {
4680 Elf_Internal_Shdr *input_rel_hdr;
4681 Elf64_External_Rela *external_relocs, *erelaend, *erela;
4682 Elf_Internal_Rela *internal_relocs, *irelaend, *irela;
4683 bfd_size_type amt;
4684
4685 /* If there aren't any relocs, then there's nothing more
4686 to do. */
4687 if ((section->flags & SEC_RELOC) == 0
4688 || section->reloc_count == 0)
4689 continue;
4690
4691 /* If this section is a link-once section that will be
4692 discarded, then don't create any stubs. */
4693 if (section->output_section == NULL
4694 || section->output_section->owner != output_bfd)
4695 continue;
4696
4697 /* Allocate space for the external relocations. */
4698 amt = section->reloc_count;
4699 amt *= sizeof (Elf64_External_Rela);
4700 external_relocs = (Elf64_External_Rela *) bfd_malloc (amt);
4701 if (external_relocs == NULL)
4702 {
4703 goto error_ret_free_local;
4704 }
4705
4706 /* Likewise for the internal relocations. */
4707 amt = section->reloc_count;
4708 amt *= sizeof (Elf_Internal_Rela);
4709 internal_relocs = (Elf_Internal_Rela *) bfd_malloc (amt);
4710 if (internal_relocs == NULL)
4711 {
4712 free (external_relocs);
4713 goto error_ret_free_local;
4714 }
4715
4716 /* Read in the external relocs. */
4717 input_rel_hdr = &elf_section_data (section)->rel_hdr;
4718 if (bfd_seek (input_bfd, input_rel_hdr->sh_offset, SEEK_SET) != 0
4719 || bfd_bread ((PTR) external_relocs,
4720 input_rel_hdr->sh_size,
4721 input_bfd) != input_rel_hdr->sh_size)
4722 {
4723 free (external_relocs);
4724 error_ret_free_internal:
4725 free (internal_relocs);
4726 goto error_ret_free_local;
4727 }
4728
4729 /* Swap in the relocs. */
4730 erela = external_relocs;
4731 erelaend = erela + section->reloc_count;
4732 irela = internal_relocs;
4733 for (; erela < erelaend; erela++, irela++)
4734 bfd_elf64_swap_reloca_in (input_bfd, erela, irela);
4735
4736 /* We're done with the external relocs, free them. */
4737 free (external_relocs);
4738
4739 /* Now examine each relocation. */
4740 irela = internal_relocs;
4741 irelaend = irela + section->reloc_count;
4742 for (; irela < irelaend; irela++)
4743 {
4744 unsigned int r_type, r_indx;
4745 enum ppc_stub_type stub_type;
4746 struct ppc_stub_hash_entry *stub_entry;
4747 asection *sym_sec;
4748 bfd_vma sym_value;
4749 bfd_vma destination;
4750 struct ppc_link_hash_entry *hash;
4751 char *stub_name;
4752 const asection *id_sec;
4753
4754 r_type = ELF64_R_TYPE (irela->r_info);
4755 r_indx = ELF64_R_SYM (irela->r_info);
4756
4757 if (r_type >= (unsigned int) R_PPC_max)
4758 {
4759 bfd_set_error (bfd_error_bad_value);
4760 goto error_ret_free_internal;
4761 }
4762
4763 /* Only look for stubs on branch instructions. */
4764 if (r_type != (unsigned int) R_PPC64_REL24
4765 && r_type != (unsigned int) R_PPC64_REL14
4766 && r_type != (unsigned int) R_PPC64_REL14_BRTAKEN
4767 && r_type != (unsigned int) R_PPC64_REL14_BRNTAKEN)
4768 continue;
4769
4770 /* Now determine the call target, its name, value,
4771 section. */
4772 sym_sec = NULL;
4773 sym_value = 0;
4774 destination = 0;
4775 hash = NULL;
4776 if (r_indx < symtab_hdr->sh_info)
4777 {
4778 /* It's a local symbol. */
4779 Elf_Internal_Sym *sym;
4780 Elf_Internal_Shdr *hdr;
4781
4782 sym = local_syms + r_indx;
4783 hdr = elf_elfsections (input_bfd)[sym->st_shndx];
4784 sym_sec = hdr->bfd_section;
4785 if (ELF_ST_TYPE (sym->st_info) != STT_SECTION)
4786 sym_value = sym->st_value;
4787 destination = (sym_value + irela->r_addend
4788 + sym_sec->output_offset
4789 + sym_sec->output_section->vma);
4790 }
4791 else
4792 {
4793 /* It's an external symbol. */
4794 int e_indx;
4795
4796 e_indx = r_indx - symtab_hdr->sh_info;
4797 hash = ((struct ppc_link_hash_entry *)
4798 elf_sym_hashes (input_bfd)[e_indx]);
4799
4800 while (hash->elf.root.type == bfd_link_hash_indirect
4801 || hash->elf.root.type == bfd_link_hash_warning)
4802 hash = ((struct ppc_link_hash_entry *)
4803 hash->elf.root.u.i.link);
4804
4805 if (hash->elf.root.type == bfd_link_hash_defined
4806 || hash->elf.root.type == bfd_link_hash_defweak)
4807 {
4808 sym_sec = hash->elf.root.u.def.section;
4809 sym_value = hash->elf.root.u.def.value;
4810 if (sym_sec->output_section != NULL)
4811 destination = (sym_value + irela->r_addend
4812 + sym_sec->output_offset
4813 + sym_sec->output_section->vma);
4814 }
4815 else if (hash->elf.root.type == bfd_link_hash_undefweak)
4816 ;
4817 else if (hash->elf.root.type == bfd_link_hash_undefined)
4818 ;
4819 else
4820 {
4821 bfd_set_error (bfd_error_bad_value);
4822 goto error_ret_free_internal;
4823 }
4824 }
4825
4826 /* Determine what (if any) linker stub is needed. */
4827 stub_type = ppc_type_of_stub (section, irela, &hash,
4828 destination);
4829 if (stub_type == ppc_stub_none)
4830 continue;
4831
4832 /* Support for grouping stub sections. */
4833 id_sec = htab->stub_group[section->id].link_sec;
4834
4835 /* Get the name of this stub. */
4836 stub_name = ppc_stub_name (id_sec, sym_sec, hash, irela);
4837 if (!stub_name)
4838 goto error_ret_free_internal;
4839
4840 stub_entry = ppc_stub_hash_lookup (&htab->stub_hash_table,
4841 stub_name, false, false);
4842 if (stub_entry != NULL)
4843 {
4844 /* The proper stub has already been created. */
4845 free (stub_name);
4846 continue;
4847 }
4848
4849 stub_entry = ppc_add_stub (stub_name, section, htab);
4850 if (stub_entry == NULL)
4851 {
4852 free (stub_name);
4853 goto error_ret_free_local;
4854 }
4855
4856 stub_entry->target_value = sym_value;
4857 stub_entry->target_section = sym_sec;
4858 stub_entry->stub_type = stub_type;
4859 stub_entry->h = hash;
4860 stub_changed = true;
4861 }
4862
4863 /* We're done with the internal relocs, free them. */
4864 free (internal_relocs);
4865 }
4866 }
4867
4868 if (!stub_changed)
4869 break;
4870
4871 /* OK, we've added some stubs. Find out the new size of the
4872 stub sections. */
4873 for (stub_sec = htab->stub_bfd->sections;
4874 stub_sec != NULL;
4875 stub_sec = stub_sec->next)
4876 {
4877 stub_sec->_raw_size = 0;
4878 stub_sec->_cooked_size = 0;
4879 }
4880 htab->sbrlt->_raw_size = 0;
4881 htab->sbrlt->_cooked_size = 0;
4882
4883 bfd_hash_traverse (&htab->stub_hash_table, ppc_size_one_stub, htab);
4884
4885 /* Ask the linker to do its stuff. */
4886 (*htab->layout_sections_again) ();
4887 }
4888
4889 /* It would be nice to strip .branch_lt from the output if the
4890 section is empty, but it's too late. If we strip sections here,
4891 the dynamic symbol table is corrupted since the section symbol
4892 for the stripped section isn't written. */
4893
4894 ret = true;
4895
4896 error_ret_free_local:
4897 while (htab->bfd_count-- > 0)
4898 if (htab->all_local_syms[htab->bfd_count])
4899 free (htab->all_local_syms[htab->bfd_count]);
4900 free (htab->all_local_syms);
4901
4902 return ret;
4903 }
4904
4905 /* Called after we have determined section placement. If sections
4906 move, we'll be called again. Provide a value for TOCstart. */
4907
4908 bfd_vma
4909 ppc64_elf_toc (obfd)
4910 bfd *obfd;
4911 {
4912 asection *s;
4913 bfd_vma TOCstart;
4914
4915 /* The TOC consists of sections .got, .toc, .tocbss, .plt in that
4916 order. The TOC starts where the first of these sections starts. */
4917 s = bfd_get_section_by_name (obfd, ".got");
4918 if (s == NULL)
4919 s = bfd_get_section_by_name (obfd, ".toc");
4920 if (s == NULL)
4921 s = bfd_get_section_by_name (obfd, ".tocbss");
4922 if (s == NULL)
4923 s = bfd_get_section_by_name (obfd, ".plt");
4924 if (s == NULL)
4925 {
4926 /* This may happen for
4927 o references to TOC base (SYM@toc / TOC[tc0]) without a
4928 .toc directive
4929 o bad linker script
4930 o --gc-sections and empty TOC sections
4931
4932 FIXME: Warn user? */
4933
4934 /* Look for a likely section. We probably won't even be
4935 using TOCstart. */
4936 for (s = obfd->sections; s != NULL; s = s->next)
4937 if ((s->flags & (SEC_ALLOC | SEC_SMALL_DATA | SEC_READONLY))
4938 == (SEC_ALLOC | SEC_SMALL_DATA))
4939 break;
4940 if (s == NULL)
4941 for (s = obfd->sections; s != NULL; s = s->next)
4942 if ((s->flags & (SEC_ALLOC | SEC_SMALL_DATA))
4943 == (SEC_ALLOC | SEC_SMALL_DATA))
4944 break;
4945 if (s == NULL)
4946 for (s = obfd->sections; s != NULL; s = s->next)
4947 if ((s->flags & (SEC_ALLOC | SEC_READONLY)) == SEC_ALLOC)
4948 break;
4949 if (s == NULL)
4950 for (s = obfd->sections; s != NULL; s = s->next)
4951 if ((s->flags & SEC_ALLOC) == SEC_ALLOC)
4952 break;
4953 }
4954
4955 TOCstart = 0;
4956 if (s != NULL)
4957 TOCstart = s->output_section->vma + s->output_offset;
4958
4959 return TOCstart;
4960 }
4961
4962 /* Build all the stubs associated with the current output file.
4963 The stubs are kept in a hash table attached to the main linker
4964 hash table. This function is called via gldelf64ppc_finish. */
4965
4966 boolean
4967 ppc64_elf_build_stubs (info)
4968 struct bfd_link_info *info;
4969 {
4970 struct ppc_link_hash_table *htab = ppc_hash_table (info);
4971 asection *stub_sec;
4972 bfd_vma plt_r2;
4973 bfd_byte *p;
4974
4975 for (stub_sec = htab->stub_bfd->sections;
4976 stub_sec != NULL;
4977 stub_sec = stub_sec->next)
4978 {
4979 bfd_size_type size;
4980
4981 /* Allocate memory to hold the linker stubs. */
4982 size = stub_sec->_raw_size;
4983 if (size != 0)
4984 {
4985 stub_sec->contents = (bfd_byte *) bfd_zalloc (htab->stub_bfd, size);
4986 if (stub_sec->contents == NULL)
4987 return false;
4988 }
4989 stub_sec->_cooked_size = 0;
4990 }
4991
4992 if (htab->splt != NULL)
4993 {
4994 /* Build the .glink plt call stub. */
4995 plt_r2 = (htab->splt->output_offset
4996 + htab->splt->output_section->vma
4997 - elf_gp (htab->splt->output_section->owner)
4998 - TOC_BASE_OFF);
4999 p = htab->sglink->contents;
5000 p = build_plt_stub (htab->sglink->owner, p, (int) plt_r2, 1);
5001 while (p - htab->sglink->contents < GLINK_CALL_STUB_SIZE)
5002 {
5003 bfd_put_32 (htab->sglink->owner, NOP, p);
5004 p += 4;
5005 }
5006 htab->sglink->_cooked_size = p - htab->sglink->contents;
5007
5008 /* Use reloc_count to count entries. */
5009 htab->sglink->reloc_count = 0;
5010 }
5011
5012 if (htab->sbrlt->_raw_size != 0)
5013 {
5014 htab->sbrlt->contents = (bfd_byte *) bfd_zalloc (htab->sbrlt->owner,
5015 htab->sbrlt->_raw_size);
5016 if (htab->sbrlt->contents == NULL)
5017 return false;
5018 }
5019
5020 /* Build the stubs as directed by the stub hash table. */
5021 bfd_hash_traverse (&htab->stub_hash_table, ppc_build_one_stub, info);
5022 htab->sglink->reloc_count = 0;
5023
5024 for (stub_sec = htab->stub_bfd->sections;
5025 stub_sec != NULL;
5026 stub_sec = stub_sec->next)
5027 {
5028 if (stub_sec->_raw_size != stub_sec->_cooked_size)
5029 break;
5030 }
5031
5032 if (stub_sec != NULL
5033 || htab->sglink->_raw_size != htab->sglink->_cooked_size)
5034 {
5035 htab->stub_error = true;
5036 (*_bfd_error_handler) (_("stubs don't match calculated size"));
5037 }
5038
5039 return !htab->stub_error;
5040 }
5041
5042 /* Set up any other section flags and such that may be necessary. */
5043
5044 static boolean
5045 ppc64_elf_fake_sections (abfd, shdr, asect)
5046 bfd *abfd ATTRIBUTE_UNUSED;
5047 Elf64_Internal_Shdr *shdr;
5048 asection *asect;
5049 {
5050 if ((asect->flags & SEC_EXCLUDE) != 0)
5051 shdr->sh_flags |= SHF_EXCLUDE;
5052
5053 if ((asect->flags & SEC_SORT_ENTRIES) != 0)
5054 shdr->sh_type = SHT_ORDERED;
5055
5056 return true;
5057 }
5058
5059 /* The RELOCATE_SECTION function is called by the ELF backend linker
5060 to handle the relocations for a section.
5061
5062 The relocs are always passed as Rela structures; if the section
5063 actually uses Rel structures, the r_addend field will always be
5064 zero.
5065
5066 This function is responsible for adjust the section contents as
5067 necessary, and (if using Rela relocs and generating a
5068 relocateable output file) adjusting the reloc addend as
5069 necessary.
5070
5071 This function does not have to worry about setting the reloc
5072 address or the reloc symbol index.
5073
5074 LOCAL_SYMS is a pointer to the swapped in local symbols.
5075
5076 LOCAL_SECTIONS is an array giving the section in the input file
5077 corresponding to the st_shndx field of each local symbol.
5078
5079 The global hash table entry for the global symbols can be found
5080 via elf_sym_hashes (input_bfd).
5081
5082 When generating relocateable output, this function must handle
5083 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
5084 going to be the section symbol corresponding to the output
5085 section, which means that the addend must be adjusted
5086 accordingly. */
5087
5088 static boolean
5089 ppc64_elf_relocate_section (output_bfd, info, input_bfd, input_section,
5090 contents, relocs, local_syms, local_sections)
5091 bfd *output_bfd;
5092 struct bfd_link_info *info;
5093 bfd *input_bfd;
5094 asection *input_section;
5095 bfd_byte *contents;
5096 Elf_Internal_Rela *relocs;
5097 Elf_Internal_Sym *local_syms;
5098 asection **local_sections;
5099 {
5100 struct ppc_link_hash_table *htab;
5101 Elf_Internal_Shdr *symtab_hdr;
5102 struct elf_link_hash_entry **sym_hashes;
5103 Elf_Internal_Rela *rel;
5104 Elf_Internal_Rela *relend;
5105 bfd_vma *local_got_offsets;
5106 bfd_vma TOCstart;
5107 boolean ret = true;
5108 boolean is_opd;
5109 /* Disabled until we sort out how ld should choose 'y' vs 'at'. */
5110 boolean is_power4 = false;
5111
5112 if (info->relocateable)
5113 return true;
5114
5115 /* Initialize howto table if needed. */
5116 if (!ppc64_elf_howto_table[R_PPC64_ADDR32])
5117 ppc_howto_init ();
5118
5119 htab = ppc_hash_table (info);
5120 local_got_offsets = elf_local_got_offsets (input_bfd);
5121 TOCstart = elf_gp (output_bfd);
5122 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
5123 sym_hashes = elf_sym_hashes (input_bfd);
5124 is_opd = strcmp (bfd_get_section_name (abfd, input_section), ".opd") == 0;
5125
5126 rel = relocs;
5127 relend = relocs + input_section->reloc_count;
5128 for (; rel < relend; rel++)
5129 {
5130 enum elf_ppc_reloc_type r_type;
5131 bfd_vma offset;
5132 bfd_vma addend;
5133 bfd_reloc_status_type r;
5134 Elf_Internal_Sym *sym;
5135 asection *sec;
5136 struct elf_link_hash_entry *h;
5137 struct elf_link_hash_entry *fdh;
5138 const char *sym_name;
5139 unsigned long r_symndx;
5140 bfd_vma relocation;
5141 boolean unresolved_reloc;
5142 boolean warned;
5143 long insn;
5144 struct ppc_stub_hash_entry *stub_entry;
5145 bfd_vma max_br_offset;
5146 bfd_vma from;
5147
5148 r_type = (enum elf_ppc_reloc_type) ELF64_R_TYPE (rel->r_info);
5149 r_symndx = ELF64_R_SYM (rel->r_info);
5150 offset = rel->r_offset;
5151 addend = rel->r_addend;
5152 r = bfd_reloc_other;
5153 sym = (Elf_Internal_Sym *) 0;
5154 sec = (asection *) 0;
5155 h = (struct elf_link_hash_entry *) 0;
5156 sym_name = (const char *) 0;
5157 unresolved_reloc = false;
5158 warned = false;
5159
5160 if (r_type == R_PPC64_TOC)
5161 {
5162 /* Relocation value is TOC base. Symbol is ignored. */
5163 relocation = TOCstart + TOC_BASE_OFF;
5164 }
5165 else if (r_symndx < symtab_hdr->sh_info)
5166 {
5167 /* It's a local symbol. */
5168 sym = local_syms + r_symndx;
5169 sec = local_sections[r_symndx];
5170 sym_name = "<local symbol>";
5171
5172 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, sec, rel);
5173 /* rel may have changed, update our copy of addend. */
5174 addend = rel->r_addend;
5175 }
5176 else
5177 {
5178 /* It's a global symbol. */
5179 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
5180 while (h->root.type == bfd_link_hash_indirect
5181 || h->root.type == bfd_link_hash_warning)
5182 h = (struct elf_link_hash_entry *) h->root.u.i.link;
5183 sym_name = h->root.root.string;
5184 relocation = 0;
5185 if (h->root.type == bfd_link_hash_defined
5186 || h->root.type == bfd_link_hash_defweak)
5187 {
5188 sec = h->root.u.def.section;
5189 if (sec->output_section == NULL)
5190 /* Set a flag that will be cleared later if we find a
5191 relocation value for this symbol. output_section
5192 is typically NULL for symbols satisfied by a shared
5193 library. */
5194 unresolved_reloc = true;
5195 else
5196 relocation = (h->root.u.def.value
5197 + sec->output_section->vma
5198 + sec->output_offset);
5199 }
5200 else if (h->root.type == bfd_link_hash_undefweak)
5201 ;
5202 else if (info->shared
5203 && (!info->symbolic || info->allow_shlib_undefined)
5204 && !info->no_undefined
5205 && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
5206 ;
5207 else
5208 {
5209 if (! ((*info->callbacks->undefined_symbol)
5210 (info, h->root.root.string, input_bfd, input_section,
5211 offset, (!info->shared
5212 || info->no_undefined
5213 || ELF_ST_VISIBILITY (h->other)))))
5214 return false;
5215 warned = true;
5216 }
5217 }
5218
5219 /* First handle relocations that tweak non-addend part of insn. */
5220 insn = 0;
5221 switch (r_type)
5222 {
5223 default:
5224 break;
5225
5226 /* Branch taken prediction relocations. */
5227 case R_PPC64_ADDR14_BRTAKEN:
5228 case R_PPC64_REL14_BRTAKEN:
5229 insn = 0x01 << 21; /* 'y' or 't' bit, lowest bit of BO field. */
5230 /* Fall thru. */
5231
5232 /* Branch not taken prediction relocations. */
5233 case R_PPC64_ADDR14_BRNTAKEN:
5234 case R_PPC64_REL14_BRNTAKEN:
5235 insn |= bfd_get_32 (output_bfd, contents + offset) & ~(0x01 << 21);
5236 if (is_power4)
5237 {
5238 /* Set 'a' bit. This is 0b00010 in BO field for branch
5239 on CR(BI) insns (BO == 001at or 011at), and 0b01000
5240 for branch on CTR insns (BO == 1a00t or 1a01t). */
5241 if ((insn & (0x14 << 21)) == (0x04 << 21))
5242 insn |= 0x02 << 21;
5243 else if ((insn & (0x14 << 21)) == (0x10 << 21))
5244 insn |= 0x08 << 21;
5245 else
5246 break;
5247 }
5248 else
5249 {
5250 from = (offset
5251 + input_section->output_offset
5252 + input_section->output_section->vma);
5253
5254 /* Invert 'y' bit if not the default. */
5255 if ((bfd_signed_vma) (relocation + addend - from) < 0)
5256 insn ^= 0x01 << 21;
5257 }
5258
5259 bfd_put_32 (output_bfd, (bfd_vma) insn, contents + offset);
5260 break;
5261
5262 case R_PPC64_REL24:
5263 /* A REL24 branching to a linkage function is followed by a
5264 nop. We replace the nop with a ld in order to restore
5265 the TOC base pointer. Only calls to shared objects need
5266 to alter the TOC base. These are recognized by their
5267 need for a PLT entry. */
5268 if (h != NULL
5269 && (fdh = ((struct ppc_link_hash_entry *) h)->oh) != NULL
5270 && fdh->plt.offset != (bfd_vma) -1
5271 && (stub_entry = ppc_get_stub_entry (input_section, sec, fdh,
5272 rel, htab)) != NULL)
5273 {
5274 boolean can_plt_call = 0;
5275
5276 if (offset + 8 <= input_section->_cooked_size)
5277 {
5278 insn = bfd_get_32 (input_bfd, contents + offset + 4);
5279 if (insn == NOP
5280 || insn == CROR_151515 || insn == CROR_313131)
5281 {
5282 bfd_put_32 (input_bfd, (bfd_vma) LD_R2_40R1,
5283 contents + offset + 4);
5284 can_plt_call = 1;
5285 }
5286 }
5287
5288 if (!can_plt_call)
5289 {
5290 /* If this is a plain branch rather than a branch
5291 and link, don't require a nop. */
5292 insn = bfd_get_32 (input_bfd, contents + offset);
5293 if ((insn & 1) == 0)
5294 can_plt_call = 1;
5295 }
5296
5297 if (can_plt_call)
5298 {
5299 relocation = (stub_entry->stub_offset
5300 + stub_entry->stub_sec->output_offset
5301 + stub_entry->stub_sec->output_section->vma);
5302 addend = 0;
5303 unresolved_reloc = false;
5304 }
5305 }
5306
5307 if (h != NULL
5308 && h->root.type == bfd_link_hash_undefweak
5309 && relocation == 0
5310 && addend == 0)
5311 {
5312 /* Tweak calls to undefined weak functions to point at a
5313 blr. We can thus call a weak function without first
5314 checking whether the function is defined. We have a
5315 blr at the end of .sfpr. */
5316 BFD_ASSERT (htab->sfpr->_raw_size != 0);
5317 relocation = (htab->sfpr->_raw_size - 4
5318 + htab->sfpr->output_offset
5319 + htab->sfpr->output_section->vma);
5320 from = (offset
5321 + input_section->output_offset
5322 + input_section->output_section->vma);
5323
5324 /* But let's not be silly about it. If the blr isn't in
5325 reach, just go to the next instruction. */
5326 if (relocation - from + (1 << 25) >= (1 << 26)
5327 || htab->sfpr->_raw_size == 0)
5328 relocation = from + 4;
5329 }
5330 break;
5331 }
5332
5333 /* Set `addend'. */
5334 switch (r_type)
5335 {
5336 default:
5337 (*_bfd_error_handler)
5338 (_("%s: unknown relocation type %d for symbol %s"),
5339 bfd_archive_filename (input_bfd), (int) r_type, sym_name);
5340
5341 bfd_set_error (bfd_error_bad_value);
5342 ret = false;
5343 continue;
5344
5345 case R_PPC64_NONE:
5346 case R_PPC_GNU_VTINHERIT:
5347 case R_PPC_GNU_VTENTRY:
5348 continue;
5349
5350 /* GOT16 relocations. Like an ADDR16 using the symbol's
5351 address in the GOT as relocation value instead of the
5352 symbols value itself. Also, create a GOT entry for the
5353 symbol and put the symbol value there. */
5354 case R_PPC64_GOT16:
5355 case R_PPC64_GOT16_LO:
5356 case R_PPC64_GOT16_HI:
5357 case R_PPC64_GOT16_HA:
5358 case R_PPC64_GOT16_DS:
5359 case R_PPC64_GOT16_LO_DS:
5360 {
5361 /* Relocation is to the entry for this symbol in the global
5362 offset table. */
5363 bfd_vma off;
5364
5365 if (htab->sgot == NULL)
5366 abort ();
5367
5368 if (h != NULL)
5369 {
5370 boolean dyn;
5371
5372 off = h->got.offset;
5373 dyn = htab->elf.dynamic_sections_created;
5374 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info, h)
5375 || (info->shared
5376 && (info->symbolic
5377 || h->dynindx == -1
5378 || (h->elf_link_hash_flags
5379 & ELF_LINK_FORCED_LOCAL))
5380 && (h->elf_link_hash_flags
5381 & ELF_LINK_HASH_DEF_REGULAR)))
5382 {
5383 /* This is actually a static link, or it is a
5384 -Bsymbolic link and the symbol is defined
5385 locally, or the symbol was forced to be local
5386 because of a version file. We must initialize
5387 this entry in the global offset table. Since the
5388 offset must always be a multiple of 8, we use the
5389 least significant bit to record whether we have
5390 initialized it already.
5391
5392 When doing a dynamic link, we create a .rel.got
5393 relocation entry to initialize the value. This
5394 is done in the finish_dynamic_symbol routine. */
5395 if ((off & 1) != 0)
5396 off &= ~1;
5397 else
5398 {
5399 bfd_put_64 (output_bfd, relocation,
5400 htab->sgot->contents + off);
5401 h->got.offset |= 1;
5402 }
5403 }
5404 else
5405 unresolved_reloc = false;
5406 }
5407 else
5408 {
5409 if (local_got_offsets == NULL)
5410 abort ();
5411
5412 off = local_got_offsets[r_symndx];
5413
5414 /* The offset must always be a multiple of 8. We use
5415 the least significant bit to record whether we have
5416 already processed this entry. */
5417 if ((off & 1) != 0)
5418 off &= ~1;
5419 else
5420 {
5421 bfd_put_64 (output_bfd, relocation,
5422 htab->sgot->contents + off);
5423
5424 if (info->shared)
5425 {
5426 Elf_Internal_Rela outrel;
5427 Elf64_External_Rela *loc;
5428
5429 /* We need to generate a R_PPC64_RELATIVE reloc
5430 for the dynamic linker. */
5431 outrel.r_offset = (htab->sgot->output_section->vma
5432 + htab->sgot->output_offset
5433 + off);
5434 outrel.r_info = ELF64_R_INFO (0, R_PPC64_RELATIVE);
5435 outrel.r_addend = relocation;
5436 loc = (Elf64_External_Rela *) htab->srelgot->contents;
5437 loc += htab->srelgot->reloc_count++;
5438 bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc);
5439 }
5440
5441 local_got_offsets[r_symndx] |= 1;
5442 }
5443 }
5444
5445 if (off >= (bfd_vma) -2)
5446 abort ();
5447
5448 relocation = htab->sgot->output_offset + off;
5449
5450 /* TOC base (r2) is TOC start plus 0x8000. */
5451 addend -= TOC_BASE_OFF;
5452 }
5453 break;
5454
5455 case R_PPC64_PLT16_HA:
5456 case R_PPC64_PLT16_HI:
5457 case R_PPC64_PLT16_LO:
5458 case R_PPC64_PLT32:
5459 case R_PPC64_PLT64:
5460 /* Relocation is to the entry for this symbol in the
5461 procedure linkage table. */
5462
5463 /* Resolve a PLT reloc against a local symbol directly,
5464 without using the procedure linkage table. */
5465 if (h == NULL)
5466 break;
5467
5468 if (h->plt.offset == (bfd_vma) -1
5469 || htab->splt == NULL)
5470 {
5471 /* We didn't make a PLT entry for this symbol. This
5472 happens when statically linking PIC code, or when
5473 using -Bsymbolic. */
5474 break;
5475 }
5476
5477 relocation = (htab->splt->output_section->vma
5478 + htab->splt->output_offset
5479 + h->plt.offset);
5480 unresolved_reloc = false;
5481 break;
5482
5483 /* TOC16 relocs. We want the offset relative to the TOC base,
5484 which is the address of the start of the TOC plus 0x8000.
5485 The TOC consists of sections .got, .toc, .tocbss, and .plt,
5486 in this order. */
5487 case R_PPC64_TOC16:
5488 case R_PPC64_TOC16_LO:
5489 case R_PPC64_TOC16_HI:
5490 case R_PPC64_TOC16_DS:
5491 case R_PPC64_TOC16_LO_DS:
5492 case R_PPC64_TOC16_HA:
5493 addend -= TOCstart + TOC_BASE_OFF;
5494 break;
5495
5496 /* Relocate against the beginning of the section. */
5497 case R_PPC64_SECTOFF:
5498 case R_PPC64_SECTOFF_LO:
5499 case R_PPC64_SECTOFF_HI:
5500 case R_PPC64_SECTOFF_DS:
5501 case R_PPC64_SECTOFF_LO_DS:
5502 case R_PPC64_SECTOFF_HA:
5503 if (sec != (asection *) 0)
5504 addend -= sec->output_section->vma;
5505 break;
5506
5507 case R_PPC64_REL14:
5508 case R_PPC64_REL14_BRNTAKEN:
5509 case R_PPC64_REL14_BRTAKEN:
5510 case R_PPC64_REL24:
5511 break;
5512
5513 /* Relocations that may need to be propagated if this is a
5514 dynamic object. */
5515 case R_PPC64_REL32:
5516 case R_PPC64_REL64:
5517 case R_PPC64_ADDR14:
5518 case R_PPC64_ADDR14_BRNTAKEN:
5519 case R_PPC64_ADDR14_BRTAKEN:
5520 case R_PPC64_ADDR16:
5521 case R_PPC64_ADDR16_DS:
5522 case R_PPC64_ADDR16_HA:
5523 case R_PPC64_ADDR16_HI:
5524 case R_PPC64_ADDR16_HIGHER:
5525 case R_PPC64_ADDR16_HIGHERA:
5526 case R_PPC64_ADDR16_HIGHEST:
5527 case R_PPC64_ADDR16_HIGHESTA:
5528 case R_PPC64_ADDR16_LO:
5529 case R_PPC64_ADDR16_LO_DS:
5530 case R_PPC64_ADDR24:
5531 case R_PPC64_ADDR30:
5532 case R_PPC64_ADDR32:
5533 case R_PPC64_ADDR64:
5534 case R_PPC64_UADDR16:
5535 case R_PPC64_UADDR32:
5536 case R_PPC64_UADDR64:
5537 /* r_symndx will be zero only for relocs against symbols
5538 from removed linkonce sections, or sections discarded by
5539 a linker script. */
5540 if (r_symndx == 0)
5541 break;
5542 /* Fall thru. */
5543
5544 case R_PPC64_TOC:
5545 if ((input_section->flags & SEC_ALLOC) == 0)
5546 break;
5547
5548 if (NO_OPD_RELOCS && is_opd)
5549 break;
5550
5551 if ((info->shared
5552 && (IS_ABSOLUTE_RELOC (r_type)
5553 || (h != NULL
5554 && h->dynindx != -1
5555 && (! info->symbolic
5556 || (h->elf_link_hash_flags
5557 & ELF_LINK_HASH_DEF_REGULAR) == 0))))
5558 || (!info->shared
5559 && h != NULL
5560 && h->dynindx != -1
5561 && (h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0
5562 && (((h->elf_link_hash_flags
5563 & ELF_LINK_HASH_DEF_DYNAMIC) != 0
5564 && (h->elf_link_hash_flags
5565 & ELF_LINK_HASH_DEF_REGULAR) == 0)
5566 || h->root.type == bfd_link_hash_undefweak
5567 || h->root.type == bfd_link_hash_undefined)))
5568 {
5569 Elf_Internal_Rela outrel;
5570 boolean skip, relocate;
5571 asection *sreloc;
5572 Elf64_External_Rela *loc;
5573
5574 /* When generating a dynamic object, these relocations
5575 are copied into the output file to be resolved at run
5576 time. */
5577
5578 skip = false;
5579 relocate = false;
5580
5581 outrel.r_offset =
5582 _bfd_elf_section_offset (output_bfd, info, input_section,
5583 rel->r_offset);
5584 if (outrel.r_offset == (bfd_vma) -1)
5585 skip = true;
5586 else if (outrel.r_offset == (bfd_vma) -2)
5587 skip = true, relocate = true;
5588 outrel.r_offset += (input_section->output_section->vma
5589 + input_section->output_offset);
5590 outrel.r_addend = addend;
5591
5592 if (skip)
5593 memset (&outrel, 0, sizeof outrel);
5594 else if (h != NULL
5595 && h->dynindx != -1
5596 && !is_opd
5597 && (!IS_ABSOLUTE_RELOC (r_type)
5598 || !info->shared
5599 || !info->symbolic
5600 || (h->elf_link_hash_flags
5601 & ELF_LINK_HASH_DEF_REGULAR) == 0))
5602 outrel.r_info = ELF64_R_INFO (h->dynindx, r_type);
5603 else
5604 {
5605 /* This symbol is local, or marked to become local,
5606 or this is an opd section reloc which must point
5607 at a local function. */
5608 outrel.r_addend += relocation;
5609 relocate = true;
5610 if (r_type == R_PPC64_ADDR64 || r_type == R_PPC64_TOC)
5611 {
5612 if (is_opd && h != NULL && info->shared)
5613 {
5614 /* Lie about opd entries. This case occurs
5615 when building shared libraries and we
5616 reference a function in another shared
5617 lib. In that case we won't use the opd
5618 entry in this lib; We ought to edit the
5619 opd section to remove unused entries. */
5620 unresolved_reloc = false;
5621 }
5622 outrel.r_info = ELF64_R_INFO (0, R_PPC64_RELATIVE);
5623 }
5624 else
5625 {
5626 long indx = 0;
5627
5628 if (bfd_is_abs_section (sec))
5629 ;
5630 else if (sec == NULL || sec->owner == NULL)
5631 {
5632 bfd_set_error (bfd_error_bad_value);
5633 return false;
5634 }
5635 else
5636 {
5637 asection *osec;
5638
5639 osec = sec->output_section;
5640 indx = elf_section_data (osec)->dynindx;
5641
5642 /* We are turning this relocation into one
5643 against a section symbol, so subtract out
5644 the output section's address but not the
5645 offset of the input section in the output
5646 section. */
5647 outrel.r_addend -= osec->vma;
5648 }
5649
5650 outrel.r_info = ELF64_R_INFO (indx, r_type);
5651 }
5652 }
5653
5654 sreloc = elf_section_data (input_section)->sreloc;
5655 if (sreloc == NULL)
5656 abort ();
5657
5658 loc = (Elf64_External_Rela *) sreloc->contents;
5659 loc += sreloc->reloc_count++;
5660 bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc);
5661
5662 /* If this reloc is against an external symbol, it will
5663 be computed at runtime, so there's no need to do
5664 anything now. */
5665 if (! relocate)
5666 continue;
5667 }
5668 break;
5669
5670 case R_PPC64_COPY:
5671 case R_PPC64_GLOB_DAT:
5672 case R_PPC64_JMP_SLOT:
5673 case R_PPC64_RELATIVE:
5674 /* We shouldn't ever see these dynamic relocs in relocatable
5675 files. */
5676 /* Fall thru */
5677
5678 case R_PPC64_PLTGOT16:
5679 case R_PPC64_PLTGOT16_DS:
5680 case R_PPC64_PLTGOT16_HA:
5681 case R_PPC64_PLTGOT16_HI:
5682 case R_PPC64_PLTGOT16_LO:
5683 case R_PPC64_PLTGOT16_LO_DS:
5684 case R_PPC64_PLTREL32:
5685 case R_PPC64_PLTREL64:
5686 /* These ones haven't been implemented yet. */
5687
5688 (*_bfd_error_handler)
5689 (_("%s: Relocation %s is not supported for symbol %s."),
5690 bfd_archive_filename (input_bfd),
5691 ppc64_elf_howto_table[(int) r_type]->name, sym_name);
5692
5693 bfd_set_error (bfd_error_invalid_operation);
5694 ret = false;
5695 continue;
5696 }
5697
5698 /* Do any further special processing. */
5699 switch (r_type)
5700 {
5701 default:
5702 break;
5703
5704 case R_PPC64_ADDR16_HA:
5705 case R_PPC64_ADDR16_HIGHERA:
5706 case R_PPC64_ADDR16_HIGHESTA:
5707 case R_PPC64_PLT16_HA:
5708 case R_PPC64_TOC16_HA:
5709 case R_PPC64_SECTOFF_HA:
5710 /* It's just possible that this symbol is a weak symbol
5711 that's not actually defined anywhere. In that case,
5712 'sec' would be NULL, and we should leave the symbol
5713 alone (it will be set to zero elsewhere in the link). */
5714 if (sec != NULL)
5715 /* Add 0x10000 if sign bit in 0:15 is set. */
5716 addend += ((relocation + addend) & 0x8000) << 1;
5717 break;
5718
5719 case R_PPC64_ADDR16_DS:
5720 case R_PPC64_ADDR16_LO_DS:
5721 case R_PPC64_GOT16_DS:
5722 case R_PPC64_GOT16_LO_DS:
5723 case R_PPC64_PLT16_LO_DS:
5724 case R_PPC64_SECTOFF_DS:
5725 case R_PPC64_SECTOFF_LO_DS:
5726 case R_PPC64_TOC16_DS:
5727 case R_PPC64_TOC16_LO_DS:
5728 case R_PPC64_PLTGOT16_DS:
5729 case R_PPC64_PLTGOT16_LO_DS:
5730 if (((relocation + addend) & 3) != 0)
5731 {
5732 (*_bfd_error_handler)
5733 (_("%s: error: relocation %s not a multiple of 4"),
5734 bfd_archive_filename (input_bfd),
5735 ppc64_elf_howto_table[(int) r_type]->name);
5736 bfd_set_error (bfd_error_bad_value);
5737 ret = false;
5738 continue;
5739 }
5740 break;
5741
5742 case R_PPC64_REL14:
5743 case R_PPC64_REL14_BRNTAKEN:
5744 case R_PPC64_REL14_BRTAKEN:
5745 max_br_offset = 1 << 15;
5746 goto branch_check;
5747
5748 case R_PPC64_REL24:
5749 max_br_offset = 1 << 25;
5750
5751 branch_check:
5752 /* If the branch is out of reach, then redirect the
5753 call to the local stub for this function. */
5754 from = (offset
5755 + input_section->output_offset
5756 + input_section->output_section->vma);
5757 if (relocation + addend - from + max_br_offset >= 2 * max_br_offset
5758 && (stub_entry = ppc_get_stub_entry (input_section, sec, h,
5759 rel, htab)) != NULL)
5760 {
5761 /* Munge up the value and addend so that we call the stub
5762 rather than the procedure directly. */
5763 relocation = (stub_entry->stub_offset
5764 + stub_entry->stub_sec->output_offset
5765 + stub_entry->stub_sec->output_section->vma);
5766 addend = 0;
5767 }
5768 break;
5769 }
5770
5771 /* FIXME: Why do we allow debugging sections to escape this error?
5772 More importantly, why do we not emit dynamic relocs above in
5773 debugging sections (which are ! SEC_ALLOC)? If we had
5774 emitted the dynamic reloc, we could remove the fudge here. */
5775 if (unresolved_reloc
5776 && !(info->shared
5777 && (input_section->flags & SEC_DEBUGGING) != 0
5778 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0))
5779 {
5780 (*_bfd_error_handler)
5781 (_("%s(%s+0x%lx): unresolvable relocation against symbol `%s'"),
5782 bfd_archive_filename (input_bfd),
5783 bfd_get_section_name (input_bfd, input_section),
5784 (long) rel->r_offset,
5785 h->root.root.string);
5786 ret = false;
5787 }
5788
5789 r = _bfd_final_link_relocate (ppc64_elf_howto_table[(int) r_type],
5790 input_bfd,
5791 input_section,
5792 contents,
5793 offset,
5794 relocation,
5795 addend);
5796
5797 if (r != bfd_reloc_ok)
5798 {
5799 const char *name;
5800
5801 if (h != NULL)
5802 {
5803 if (h->root.type == bfd_link_hash_undefweak
5804 && ppc64_elf_howto_table[(int) r_type]->pc_relative)
5805 {
5806 /* Assume this is a call protected by other code that
5807 detects the symbol is undefined. If this is the case,
5808 we can safely ignore the overflow. If not, the
5809 program is hosed anyway, and a little warning isn't
5810 going to help. */
5811
5812 continue;
5813 }
5814
5815 name = h->root.root.string;
5816 }
5817 else
5818 {
5819 name = bfd_elf_string_from_elf_section (input_bfd,
5820 symtab_hdr->sh_link,
5821 sym->st_name);
5822 if (name == NULL)
5823 continue;
5824 if (*name == '\0')
5825 name = bfd_section_name (input_bfd, sec);
5826 }
5827
5828 if (r == bfd_reloc_overflow)
5829 {
5830 if (warned)
5831 continue;
5832 if (!((*info->callbacks->reloc_overflow)
5833 (info, name, ppc64_elf_howto_table[(int) r_type]->name,
5834 rel->r_addend, input_bfd, input_section, offset)))
5835 return false;
5836 }
5837 else
5838 {
5839 (*_bfd_error_handler)
5840 (_("%s(%s+0x%lx): reloc against `%s': error %d"),
5841 bfd_archive_filename (input_bfd),
5842 bfd_get_section_name (input_bfd, input_section),
5843 (long) rel->r_offset, name, (int) r);
5844 ret = false;
5845 }
5846 }
5847 }
5848
5849 return ret;
5850 }
5851
5852 /* Finish up dynamic symbol handling. We set the contents of various
5853 dynamic sections here. */
5854
5855 static boolean
5856 ppc64_elf_finish_dynamic_symbol (output_bfd, info, h, sym)
5857 bfd *output_bfd;
5858 struct bfd_link_info *info;
5859 struct elf_link_hash_entry *h;
5860 Elf_Internal_Sym *sym;
5861 {
5862 struct ppc_link_hash_table *htab;
5863 bfd *dynobj;
5864
5865 htab = ppc_hash_table (info);
5866 dynobj = htab->elf.dynobj;
5867
5868 if (h->plt.offset != (bfd_vma) -1
5869 && ((struct ppc_link_hash_entry *) h)->is_func_descriptor)
5870 {
5871 Elf_Internal_Rela rela;
5872 Elf64_External_Rela *loc;
5873
5874 /* This symbol has an entry in the procedure linkage table. Set
5875 it up. */
5876
5877 if (htab->splt == NULL
5878 || htab->srelplt == NULL
5879 || htab->sglink == NULL)
5880 abort ();
5881
5882 /* Create a JMP_SLOT reloc to inform the dynamic linker to
5883 fill in the PLT entry. */
5884
5885 rela.r_offset = (htab->splt->output_section->vma
5886 + htab->splt->output_offset
5887 + h->plt.offset);
5888 rela.r_info = ELF64_R_INFO (h->dynindx, R_PPC64_JMP_SLOT);
5889 rela.r_addend = 0;
5890
5891 loc = (Elf64_External_Rela *) htab->srelplt->contents;
5892 loc += (h->plt.offset - PLT_INITIAL_ENTRY_SIZE) / PLT_ENTRY_SIZE;
5893 bfd_elf64_swap_reloca_out (output_bfd, &rela, loc);
5894 }
5895
5896 if (h->got.offset != (bfd_vma) -1)
5897 {
5898 Elf_Internal_Rela rela;
5899 Elf64_External_Rela *loc;
5900
5901 /* This symbol has an entry in the global offset table. Set it
5902 up. */
5903
5904 if (htab->sgot == NULL || htab->srelgot == NULL)
5905 abort ();
5906
5907 rela.r_offset = (htab->sgot->output_section->vma
5908 + htab->sgot->output_offset
5909 + (h->got.offset &~ (bfd_vma) 1));
5910
5911 /* If this is a static link, or it is a -Bsymbolic link and the
5912 symbol is defined locally or was forced to be local because
5913 of a version file, we just want to emit a RELATIVE reloc.
5914 The entry in the global offset table will already have been
5915 initialized in the relocate_section function. */
5916 if (info->shared
5917 && (info->symbolic
5918 || h->dynindx == -1
5919 || (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL))
5920 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR))
5921 {
5922 BFD_ASSERT((h->got.offset & 1) != 0);
5923 rela.r_info = ELF64_R_INFO (0, R_PPC64_RELATIVE);
5924 rela.r_addend = (h->root.u.def.value
5925 + h->root.u.def.section->output_section->vma
5926 + h->root.u.def.section->output_offset);
5927 }
5928 else
5929 {
5930 BFD_ASSERT ((h->got.offset & 1) == 0);
5931 bfd_put_64 (output_bfd, (bfd_vma) 0,
5932 htab->sgot->contents + h->got.offset);
5933 rela.r_info = ELF64_R_INFO (h->dynindx, R_PPC64_GLOB_DAT);
5934 rela.r_addend = 0;
5935 }
5936
5937 loc = (Elf64_External_Rela *) htab->srelgot->contents;
5938 loc += htab->srelgot->reloc_count++;
5939 bfd_elf64_swap_reloca_out (output_bfd, &rela, loc);
5940 }
5941
5942 if ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_COPY) != 0)
5943 {
5944 Elf_Internal_Rela rela;
5945 Elf64_External_Rela *loc;
5946
5947 /* This symbol needs a copy reloc. Set it up. */
5948
5949 if (h->dynindx == -1
5950 || (h->root.type != bfd_link_hash_defined
5951 && h->root.type != bfd_link_hash_defweak)
5952 || htab->srelbss == NULL)
5953 abort ();
5954
5955 rela.r_offset = (h->root.u.def.value
5956 + h->root.u.def.section->output_section->vma
5957 + h->root.u.def.section->output_offset);
5958 rela.r_info = ELF64_R_INFO (h->dynindx, R_PPC64_COPY);
5959 rela.r_addend = 0;
5960 loc = (Elf64_External_Rela *) htab->srelbss->contents;
5961 loc += htab->srelbss->reloc_count++;
5962 bfd_elf64_swap_reloca_out (output_bfd, &rela, loc);
5963 }
5964
5965 /* Mark some specially defined symbols as absolute. */
5966 if (strcmp (h->root.root.string, "_DYNAMIC") == 0)
5967 sym->st_shndx = SHN_ABS;
5968
5969 return true;
5970 }
5971
5972 /* Used to decide how to sort relocs in an optimal manner for the
5973 dynamic linker, before writing them out. */
5974
5975 static enum elf_reloc_type_class
5976 ppc64_elf_reloc_type_class (rela)
5977 const Elf_Internal_Rela *rela;
5978 {
5979 enum elf_ppc_reloc_type r_type;
5980
5981 r_type = (enum elf_ppc_reloc_type) ELF64_R_TYPE (rela->r_info);
5982 switch (r_type)
5983 {
5984 case R_PPC64_RELATIVE:
5985 return reloc_class_relative;
5986 case R_PPC64_JMP_SLOT:
5987 return reloc_class_plt;
5988 case R_PPC64_COPY:
5989 return reloc_class_copy;
5990 default:
5991 return reloc_class_normal;
5992 }
5993 }
5994
5995 /* Finish up the dynamic sections. */
5996
5997 static boolean
5998 ppc64_elf_finish_dynamic_sections (output_bfd, info)
5999 bfd *output_bfd;
6000 struct bfd_link_info *info;
6001 {
6002 struct ppc_link_hash_table *htab;
6003 bfd *dynobj;
6004 asection *sdyn;
6005
6006 htab = ppc_hash_table (info);
6007 dynobj = htab->elf.dynobj;
6008 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
6009
6010 if (htab->elf.dynamic_sections_created)
6011 {
6012 Elf64_External_Dyn *dyncon, *dynconend;
6013
6014 if (sdyn == NULL || htab->sgot == NULL)
6015 abort ();
6016
6017 dyncon = (Elf64_External_Dyn *) sdyn->contents;
6018 dynconend = (Elf64_External_Dyn *) (sdyn->contents + sdyn->_raw_size);
6019 for (; dyncon < dynconend; dyncon++)
6020 {
6021 Elf_Internal_Dyn dyn;
6022 asection *s;
6023
6024 bfd_elf64_swap_dyn_in (dynobj, dyncon, &dyn);
6025
6026 switch (dyn.d_tag)
6027 {
6028 default:
6029 continue;
6030
6031 case DT_PPC64_GLINK:
6032 dyn.d_un.d_ptr = (htab->sglink->output_section->vma
6033 + htab->sglink->output_offset);
6034 break;
6035
6036 case DT_PPC64_OPD:
6037 s = bfd_get_section_by_name (output_bfd, ".opd");
6038 if (s != NULL)
6039 dyn.d_un.d_ptr = s->vma;
6040 break;
6041
6042 case DT_PPC64_OPDSZ:
6043 s = bfd_get_section_by_name (output_bfd, ".opd");
6044 if (s != NULL)
6045 dyn.d_un.d_val = s->_raw_size;
6046 break;
6047
6048 case DT_PLTGOT:
6049 dyn.d_un.d_ptr = (htab->splt->output_section->vma
6050 + htab->splt->output_offset);
6051 break;
6052
6053 case DT_JMPREL:
6054 dyn.d_un.d_ptr = (htab->srelplt->output_section->vma
6055 + htab->srelplt->output_offset);
6056 break;
6057
6058 case DT_PLTRELSZ:
6059 dyn.d_un.d_val = htab->srelplt->_raw_size;
6060 break;
6061
6062 case DT_RELASZ:
6063 /* Don't count procedure linkage table relocs in the
6064 overall reloc count. */
6065 if (htab->srelplt != NULL)
6066 dyn.d_un.d_val -= htab->srelplt->_raw_size;
6067 break;
6068 }
6069
6070 bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon);
6071 }
6072 }
6073
6074 if (htab->sgot != NULL && htab->sgot->_raw_size != 0)
6075 {
6076 /* Fill in the first entry in the global offset table.
6077 We use it to hold the link-time TOCbase. */
6078 bfd_put_64 (output_bfd,
6079 elf_gp (output_bfd) + TOC_BASE_OFF,
6080 htab->sgot->contents);
6081
6082 /* Set .got entry size. */
6083 elf_section_data (htab->sgot->output_section)->this_hdr.sh_entsize = 8;
6084 }
6085
6086 if (htab->splt != NULL && htab->splt->_raw_size != 0)
6087 {
6088 /* Set .plt entry size. */
6089 elf_section_data (htab->splt->output_section)->this_hdr.sh_entsize
6090 = PLT_ENTRY_SIZE;
6091 }
6092
6093 return true;
6094 }
6095
6096 #define TARGET_LITTLE_SYM bfd_elf64_powerpcle_vec
6097 #define TARGET_LITTLE_NAME "elf64-powerpcle"
6098 #define TARGET_BIG_SYM bfd_elf64_powerpc_vec
6099 #define TARGET_BIG_NAME "elf64-powerpc"
6100 #define ELF_ARCH bfd_arch_powerpc
6101 #define ELF_MACHINE_CODE EM_PPC64
6102 #define ELF_MAXPAGESIZE 0x10000
6103 #define elf_info_to_howto ppc64_elf_info_to_howto
6104
6105 #ifdef EM_CYGNUS_POWERPC
6106 #define ELF_MACHINE_ALT1 EM_CYGNUS_POWERPC
6107 #endif
6108
6109 #ifdef EM_PPC_OLD
6110 #define ELF_MACHINE_ALT2 EM_PPC_OLD
6111 #endif
6112
6113 #define elf_backend_want_got_sym 0
6114 #define elf_backend_want_plt_sym 0
6115 #define elf_backend_plt_alignment 3
6116 #define elf_backend_plt_not_loaded 1
6117 #define elf_backend_got_symbol_offset 0
6118 #define elf_backend_got_header_size 8
6119 #define elf_backend_plt_header_size PLT_INITIAL_ENTRY_SIZE
6120 #define elf_backend_can_gc_sections 1
6121 #define elf_backend_can_refcount 1
6122 #define elf_backend_rela_normal 1
6123
6124 #define bfd_elf64_bfd_reloc_type_lookup ppc64_elf_reloc_type_lookup
6125 #define bfd_elf64_bfd_set_private_flags ppc64_elf_set_private_flags
6126 #define bfd_elf64_bfd_merge_private_bfd_data ppc64_elf_merge_private_bfd_data
6127 #define bfd_elf64_bfd_link_hash_table_create ppc64_elf_link_hash_table_create
6128 #define bfd_elf64_bfd_link_hash_table_free ppc64_elf_link_hash_table_free
6129 #define bfd_elf64_get_symbol_info ppc64_elf_get_symbol_info
6130
6131 #define elf_backend_section_from_shdr ppc64_elf_section_from_shdr
6132 #define elf_backend_create_dynamic_sections ppc64_elf_create_dynamic_sections
6133 #define elf_backend_copy_indirect_symbol ppc64_elf_copy_indirect_symbol
6134 #define elf_backend_check_relocs ppc64_elf_check_relocs
6135 #define elf_backend_gc_mark_hook ppc64_elf_gc_mark_hook
6136 #define elf_backend_gc_sweep_hook ppc64_elf_gc_sweep_hook
6137 #define elf_backend_adjust_dynamic_symbol ppc64_elf_adjust_dynamic_symbol
6138 #define elf_backend_hide_symbol ppc64_elf_hide_symbol
6139 #define elf_backend_always_size_sections ppc64_elf_func_desc_adjust
6140 #define elf_backend_size_dynamic_sections ppc64_elf_size_dynamic_sections
6141 #define elf_backend_fake_sections ppc64_elf_fake_sections
6142 #define elf_backend_relocate_section ppc64_elf_relocate_section
6143 #define elf_backend_finish_dynamic_symbol ppc64_elf_finish_dynamic_symbol
6144 #define elf_backend_reloc_type_class ppc64_elf_reloc_type_class
6145 #define elf_backend_finish_dynamic_sections ppc64_elf_finish_dynamic_sections
6146
6147 #include "elf64-target.h"