Fix the behaviour of --allow-shlib-undefined, so that it does what it claims
[deliverable/binutils-gdb.git] / bfd / elf64-ppc.c
1 /* PowerPC64-specific support for 64-bit ELF.
2 Copyright 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
3 Written by Linus Nordberg, Swox AB <info@swox.com>,
4 based on elf32-ppc.c by Ian Lance Taylor.
5
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/ppc64.h"
31 #include "elf64-ppc.h"
32
33 static void ppc_howto_init
34 PARAMS ((void));
35 static reloc_howto_type *ppc64_elf_reloc_type_lookup
36 PARAMS ((bfd *abfd, bfd_reloc_code_real_type code));
37 static void ppc64_elf_info_to_howto
38 PARAMS ((bfd *abfd, arelent *cache_ptr, Elf_Internal_Rela *dst));
39 static bfd_reloc_status_type ppc64_elf_ha_reloc
40 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
41 static bfd_reloc_status_type ppc64_elf_brtaken_reloc
42 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
43 static bfd_reloc_status_type ppc64_elf_sectoff_reloc
44 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
45 static bfd_reloc_status_type ppc64_elf_sectoff_ha_reloc
46 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
47 static bfd_reloc_status_type ppc64_elf_toc_reloc
48 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
49 static bfd_reloc_status_type ppc64_elf_toc_ha_reloc
50 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
51 static bfd_reloc_status_type ppc64_elf_toc64_reloc
52 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
53 static bfd_reloc_status_type ppc64_elf_unhandled_reloc
54 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
55 static bfd_boolean ppc64_elf_object_p
56 PARAMS ((bfd *));
57 static bfd_boolean ppc64_elf_merge_private_bfd_data
58 PARAMS ((bfd *, bfd *));
59 static bfd_boolean ppc64_elf_new_section_hook
60 PARAMS ((bfd *, asection *));
61
62
63 /* The name of the dynamic interpreter. This is put in the .interp
64 section. */
65 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
66
67 /* The size in bytes of an entry in the procedure linkage table. */
68 #define PLT_ENTRY_SIZE 24
69
70 /* The initial size of the plt reserved for the dynamic linker. */
71 #define PLT_INITIAL_ENTRY_SIZE PLT_ENTRY_SIZE
72
73 /* TOC base pointers offset from start of TOC. */
74 #define TOC_BASE_OFF 0x8000
75
76 /* Offset of tp and dtp pointers from start of TLS block. */
77 #define TP_OFFSET 0x7000
78 #define DTP_OFFSET 0x8000
79
80 /* .plt call stub instructions. */
81 #define ADDIS_R12_R2 0x3d820000 /* addis %r12,%r2,xxx@ha */
82 #define STD_R2_40R1 0xf8410028 /* std %r2,40(%r1) */
83 #define LD_R11_0R12 0xe96c0000 /* ld %r11,xxx+0@l(%r12) */
84 #define LD_R2_0R12 0xe84c0000 /* ld %r2,xxx+8@l(%r12) */
85 #define MTCTR_R11 0x7d6903a6 /* mtctr %r11 */
86 /* ld %r11,xxx+16@l(%r12) */
87 #define BCTR 0x4e800420 /* bctr */
88
89 /* The normal stub is this size. */
90 #define PLT_CALL_STUB_SIZE (7*4)
91
92 /* But sometimes the .plt entry crosses a 64k boundary, and we need
93 to adjust the high word with this insn. */
94 #define ADDIS_R12_R12_1 0x3d8c0001 /* addis %r12,%r12,1 */
95
96 /* The .glink fixup call stub is the same as the .plt call stub, but
97 the first instruction restores r2, and the std is omitted. */
98 #define LD_R2_40R1 0xe8410028 /* ld %r2,40(%r1) */
99
100 /* Always allow this much space. */
101 #define GLINK_CALL_STUB_SIZE (8*4)
102
103 /* Pad with this. */
104 #define NOP 0x60000000
105
106 /* Some other nops. */
107 #define CROR_151515 0x4def7b82
108 #define CROR_313131 0x4ffffb82
109
110 /* .glink entries for the first 32k functions are two instructions. */
111 #define LI_R0_0 0x38000000 /* li %r0,0 */
112 #define B_DOT 0x48000000 /* b . */
113
114 /* After that, we need two instructions to load the index, followed by
115 a branch. */
116 #define LIS_R0_0 0x3c000000 /* lis %r0,0 */
117 #define ORI_R0_R0_0 0x60000000 /* ori %r0,%r0,0 */
118
119 /* Instructions to save and restore floating point regs. */
120 #define STFD_FR0_0R1 0xd8010000 /* stfd %fr0,0(%r1) */
121 #define LFD_FR0_0R1 0xc8010000 /* lfd %fr0,0(%r1) */
122 #define BLR 0x4e800020 /* blr */
123
124 /* Since .opd is an array of descriptors and each entry will end up
125 with identical R_PPC64_RELATIVE relocs, there is really no need to
126 propagate .opd relocs; The dynamic linker should be taught to
127 relocate .opd without reloc entries. */
128 #ifndef NO_OPD_RELOCS
129 #define NO_OPD_RELOCS 0
130 #endif
131 \f
132 #define ONES(n) (((bfd_vma) 1 << ((n) - 1) << 1) - 1)
133
134 /* Relocation HOWTO's. */
135 static reloc_howto_type *ppc64_elf_howto_table[(int) R_PPC64_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_dont, /* 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 0x03fffffc, /* 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 0x0000fffc, /* 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 0x0000fffc, /* 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 0x0000fffc, /* 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 0x03fffffc, /* 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 0x0000fffc, /* 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 0x0000fffc, /* 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 0x0000fffc, /* 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 0, /* this one is variable size */
431 0, /* bitsize */
432 FALSE, /* pc_relative */
433 0, /* bitpos */
434 complain_overflow_dont, /* 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 ONES (64), /* 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 ONES (64), /* 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 0xffffffff, /* 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 0xffffffff, /* 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 bits. */
677 HOWTO (R_PPC64_REL30, /* type */
678 2, /* rightshift */
679 2, /* size (0 = byte, 1 = short, 2 = long) */
680 30, /* bitsize */
681 TRUE, /* pc_relative */
682 0, /* bitpos */
683 complain_overflow_dont, /* complain_on_overflow */
684 bfd_elf_generic_reloc, /* special_function */
685 "R_PPC64_REL30", /* name */
686 FALSE, /* partial_inplace */
687 0, /* src_mask */
688 0xfffffffc, /* dst_mask */
689 TRUE), /* pcrel_offset */
690
691 /* Relocs in the 64-bit PowerPC ELF ABI, not in the 32-bit ABI. */
692
693 /* A standard 64-bit relocation. */
694 HOWTO (R_PPC64_ADDR64, /* type */
695 0, /* rightshift */
696 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
697 64, /* bitsize */
698 FALSE, /* pc_relative */
699 0, /* bitpos */
700 complain_overflow_dont, /* complain_on_overflow */
701 bfd_elf_generic_reloc, /* special_function */
702 "R_PPC64_ADDR64", /* name */
703 FALSE, /* partial_inplace */
704 0, /* src_mask */
705 ONES (64), /* dst_mask */
706 FALSE), /* pcrel_offset */
707
708 /* The bits 32-47 of an address. */
709 HOWTO (R_PPC64_ADDR16_HIGHER, /* type */
710 32, /* rightshift */
711 1, /* size (0 = byte, 1 = short, 2 = long) */
712 16, /* bitsize */
713 FALSE, /* pc_relative */
714 0, /* bitpos */
715 complain_overflow_dont, /* complain_on_overflow */
716 bfd_elf_generic_reloc, /* special_function */
717 "R_PPC64_ADDR16_HIGHER", /* name */
718 FALSE, /* partial_inplace */
719 0, /* src_mask */
720 0xffff, /* dst_mask */
721 FALSE), /* pcrel_offset */
722
723 /* The bits 32-47 of an address, plus 1 if the contents of the low
724 16 bits, treated as a signed number, is negative. */
725 HOWTO (R_PPC64_ADDR16_HIGHERA, /* type */
726 32, /* rightshift */
727 1, /* size (0 = byte, 1 = short, 2 = long) */
728 16, /* bitsize */
729 FALSE, /* pc_relative */
730 0, /* bitpos */
731 complain_overflow_dont, /* complain_on_overflow */
732 ppc64_elf_ha_reloc, /* special_function */
733 "R_PPC64_ADDR16_HIGHERA", /* name */
734 FALSE, /* partial_inplace */
735 0, /* src_mask */
736 0xffff, /* dst_mask */
737 FALSE), /* pcrel_offset */
738
739 /* The bits 48-63 of an address. */
740 HOWTO (R_PPC64_ADDR16_HIGHEST,/* type */
741 48, /* rightshift */
742 1, /* size (0 = byte, 1 = short, 2 = long) */
743 16, /* bitsize */
744 FALSE, /* pc_relative */
745 0, /* bitpos */
746 complain_overflow_dont, /* complain_on_overflow */
747 bfd_elf_generic_reloc, /* special_function */
748 "R_PPC64_ADDR16_HIGHEST", /* name */
749 FALSE, /* partial_inplace */
750 0, /* src_mask */
751 0xffff, /* dst_mask */
752 FALSE), /* pcrel_offset */
753
754 /* The bits 48-63 of an address, plus 1 if the contents of the low
755 16 bits, treated as a signed number, is negative. */
756 HOWTO (R_PPC64_ADDR16_HIGHESTA,/* type */
757 48, /* rightshift */
758 1, /* size (0 = byte, 1 = short, 2 = long) */
759 16, /* bitsize */
760 FALSE, /* pc_relative */
761 0, /* bitpos */
762 complain_overflow_dont, /* complain_on_overflow */
763 ppc64_elf_ha_reloc, /* special_function */
764 "R_PPC64_ADDR16_HIGHESTA", /* name */
765 FALSE, /* partial_inplace */
766 0, /* src_mask */
767 0xffff, /* dst_mask */
768 FALSE), /* pcrel_offset */
769
770 /* Like ADDR64, but may be unaligned. */
771 HOWTO (R_PPC64_UADDR64, /* type */
772 0, /* rightshift */
773 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
774 64, /* bitsize */
775 FALSE, /* pc_relative */
776 0, /* bitpos */
777 complain_overflow_dont, /* complain_on_overflow */
778 bfd_elf_generic_reloc, /* special_function */
779 "R_PPC64_UADDR64", /* name */
780 FALSE, /* partial_inplace */
781 0, /* src_mask */
782 ONES (64), /* dst_mask */
783 FALSE), /* pcrel_offset */
784
785 /* 64-bit relative relocation. */
786 HOWTO (R_PPC64_REL64, /* type */
787 0, /* rightshift */
788 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
789 64, /* bitsize */
790 TRUE, /* pc_relative */
791 0, /* bitpos */
792 complain_overflow_dont, /* complain_on_overflow */
793 bfd_elf_generic_reloc, /* special_function */
794 "R_PPC64_REL64", /* name */
795 FALSE, /* partial_inplace */
796 0, /* src_mask */
797 ONES (64), /* dst_mask */
798 TRUE), /* pcrel_offset */
799
800 /* 64-bit relocation to the symbol's procedure linkage table. */
801 HOWTO (R_PPC64_PLT64, /* type */
802 0, /* rightshift */
803 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
804 64, /* bitsize */
805 FALSE, /* pc_relative */
806 0, /* bitpos */
807 complain_overflow_dont, /* complain_on_overflow */
808 ppc64_elf_unhandled_reloc, /* special_function */
809 "R_PPC64_PLT64", /* name */
810 FALSE, /* partial_inplace */
811 0, /* src_mask */
812 ONES (64), /* dst_mask */
813 FALSE), /* pcrel_offset */
814
815 /* 64-bit PC relative relocation to the symbol's procedure linkage
816 table. */
817 /* FIXME: R_PPC64_PLTREL64 not supported. */
818 HOWTO (R_PPC64_PLTREL64, /* type */
819 0, /* rightshift */
820 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
821 64, /* bitsize */
822 TRUE, /* pc_relative */
823 0, /* bitpos */
824 complain_overflow_dont, /* complain_on_overflow */
825 ppc64_elf_unhandled_reloc, /* special_function */
826 "R_PPC64_PLTREL64", /* name */
827 FALSE, /* partial_inplace */
828 0, /* src_mask */
829 ONES (64), /* dst_mask */
830 TRUE), /* pcrel_offset */
831
832 /* 16 bit TOC-relative relocation. */
833
834 /* R_PPC64_TOC16 47 half16* S + A - .TOC. */
835 HOWTO (R_PPC64_TOC16, /* type */
836 0, /* rightshift */
837 1, /* size (0 = byte, 1 = short, 2 = long) */
838 16, /* bitsize */
839 FALSE, /* pc_relative */
840 0, /* bitpos */
841 complain_overflow_signed, /* complain_on_overflow */
842 ppc64_elf_toc_reloc, /* special_function */
843 "R_PPC64_TOC16", /* name */
844 FALSE, /* partial_inplace */
845 0, /* src_mask */
846 0xffff, /* dst_mask */
847 FALSE), /* pcrel_offset */
848
849 /* 16 bit TOC-relative relocation without overflow. */
850
851 /* R_PPC64_TOC16_LO 48 half16 #lo (S + A - .TOC.) */
852 HOWTO (R_PPC64_TOC16_LO, /* type */
853 0, /* rightshift */
854 1, /* size (0 = byte, 1 = short, 2 = long) */
855 16, /* bitsize */
856 FALSE, /* pc_relative */
857 0, /* bitpos */
858 complain_overflow_dont, /* complain_on_overflow */
859 ppc64_elf_toc_reloc, /* special_function */
860 "R_PPC64_TOC16_LO", /* name */
861 FALSE, /* partial_inplace */
862 0, /* src_mask */
863 0xffff, /* dst_mask */
864 FALSE), /* pcrel_offset */
865
866 /* 16 bit TOC-relative relocation, high 16 bits. */
867
868 /* R_PPC64_TOC16_HI 49 half16 #hi (S + A - .TOC.) */
869 HOWTO (R_PPC64_TOC16_HI, /* type */
870 16, /* rightshift */
871 1, /* size (0 = byte, 1 = short, 2 = long) */
872 16, /* bitsize */
873 FALSE, /* pc_relative */
874 0, /* bitpos */
875 complain_overflow_dont, /* complain_on_overflow */
876 ppc64_elf_toc_reloc, /* special_function */
877 "R_PPC64_TOC16_HI", /* name */
878 FALSE, /* partial_inplace */
879 0, /* src_mask */
880 0xffff, /* dst_mask */
881 FALSE), /* pcrel_offset */
882
883 /* 16 bit TOC-relative relocation, high 16 bits, plus 1 if the
884 contents of the low 16 bits, treated as a signed number, is
885 negative. */
886
887 /* R_PPC64_TOC16_HA 50 half16 #ha (S + A - .TOC.) */
888 HOWTO (R_PPC64_TOC16_HA, /* type */
889 16, /* rightshift */
890 1, /* size (0 = byte, 1 = short, 2 = long) */
891 16, /* bitsize */
892 FALSE, /* pc_relative */
893 0, /* bitpos */
894 complain_overflow_dont, /* complain_on_overflow */
895 ppc64_elf_toc_ha_reloc, /* special_function */
896 "R_PPC64_TOC16_HA", /* name */
897 FALSE, /* partial_inplace */
898 0, /* src_mask */
899 0xffff, /* dst_mask */
900 FALSE), /* pcrel_offset */
901
902 /* 64-bit relocation; insert value of TOC base (.TOC.). */
903
904 /* R_PPC64_TOC 51 doubleword64 .TOC. */
905 HOWTO (R_PPC64_TOC, /* type */
906 0, /* rightshift */
907 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
908 64, /* bitsize */
909 FALSE, /* pc_relative */
910 0, /* bitpos */
911 complain_overflow_bitfield, /* complain_on_overflow */
912 ppc64_elf_toc64_reloc, /* special_function */
913 "R_PPC64_TOC", /* name */
914 FALSE, /* partial_inplace */
915 0, /* src_mask */
916 ONES (64), /* dst_mask */
917 FALSE), /* pcrel_offset */
918
919 /* Like R_PPC64_GOT16, but also informs the link editor that the
920 value to relocate may (!) refer to a PLT entry which the link
921 editor (a) may replace with the symbol value. If the link editor
922 is unable to fully resolve the symbol, it may (b) create a PLT
923 entry and store the address to the new PLT entry in the GOT.
924 This permits lazy resolution of function symbols at run time.
925 The link editor may also skip all of this and just (c) emit a
926 R_PPC64_GLOB_DAT to tie the symbol to the GOT entry. */
927 /* FIXME: R_PPC64_PLTGOT16 not implemented. */
928 HOWTO (R_PPC64_PLTGOT16, /* type */
929 0, /* rightshift */
930 1, /* size (0 = byte, 1 = short, 2 = long) */
931 16, /* bitsize */
932 FALSE, /* pc_relative */
933 0, /* bitpos */
934 complain_overflow_signed, /* complain_on_overflow */
935 ppc64_elf_unhandled_reloc, /* special_function */
936 "R_PPC64_PLTGOT16", /* name */
937 FALSE, /* partial_inplace */
938 0, /* src_mask */
939 0xffff, /* dst_mask */
940 FALSE), /* pcrel_offset */
941
942 /* Like R_PPC64_PLTGOT16, but without overflow. */
943 /* FIXME: R_PPC64_PLTGOT16_LO not implemented. */
944 HOWTO (R_PPC64_PLTGOT16_LO, /* type */
945 0, /* rightshift */
946 1, /* size (0 = byte, 1 = short, 2 = long) */
947 16, /* bitsize */
948 FALSE, /* pc_relative */
949 0, /* bitpos */
950 complain_overflow_dont, /* complain_on_overflow */
951 ppc64_elf_unhandled_reloc, /* special_function */
952 "R_PPC64_PLTGOT16_LO", /* name */
953 FALSE, /* partial_inplace */
954 0, /* src_mask */
955 0xffff, /* dst_mask */
956 FALSE), /* pcrel_offset */
957
958 /* Like R_PPC64_PLT_GOT16, but using bits 16-31 of the address. */
959 /* FIXME: R_PPC64_PLTGOT16_HI not implemented. */
960 HOWTO (R_PPC64_PLTGOT16_HI, /* type */
961 16, /* rightshift */
962 1, /* size (0 = byte, 1 = short, 2 = long) */
963 16, /* bitsize */
964 FALSE, /* pc_relative */
965 0, /* bitpos */
966 complain_overflow_dont, /* complain_on_overflow */
967 ppc64_elf_unhandled_reloc, /* special_function */
968 "R_PPC64_PLTGOT16_HI", /* name */
969 FALSE, /* partial_inplace */
970 0, /* src_mask */
971 0xffff, /* dst_mask */
972 FALSE), /* pcrel_offset */
973
974 /* Like R_PPC64_PLT_GOT16, but using bits 16-31 of the address, plus
975 1 if the contents of the low 16 bits, treated as a signed number,
976 is negative. */
977 /* FIXME: R_PPC64_PLTGOT16_HA not implemented. */
978 HOWTO (R_PPC64_PLTGOT16_HA, /* type */
979 16, /* rightshift */
980 1, /* size (0 = byte, 1 = short, 2 = long) */
981 16, /* bitsize */
982 FALSE, /* pc_relative */
983 0, /* bitpos */
984 complain_overflow_dont,/* complain_on_overflow */
985 ppc64_elf_unhandled_reloc, /* special_function */
986 "R_PPC64_PLTGOT16_HA", /* name */
987 FALSE, /* partial_inplace */
988 0, /* src_mask */
989 0xffff, /* dst_mask */
990 FALSE), /* pcrel_offset */
991
992 /* Like R_PPC64_ADDR16, but for instructions with a DS field. */
993 HOWTO (R_PPC64_ADDR16_DS, /* type */
994 0, /* rightshift */
995 1, /* size (0 = byte, 1 = short, 2 = long) */
996 16, /* bitsize */
997 FALSE, /* pc_relative */
998 0, /* bitpos */
999 complain_overflow_bitfield, /* complain_on_overflow */
1000 bfd_elf_generic_reloc, /* special_function */
1001 "R_PPC64_ADDR16_DS", /* name */
1002 FALSE, /* partial_inplace */
1003 0, /* src_mask */
1004 0xfffc, /* dst_mask */
1005 FALSE), /* pcrel_offset */
1006
1007 /* Like R_PPC64_ADDR16_LO, but for instructions with a DS field. */
1008 HOWTO (R_PPC64_ADDR16_LO_DS, /* type */
1009 0, /* rightshift */
1010 1, /* size (0 = byte, 1 = short, 2 = long) */
1011 16, /* bitsize */
1012 FALSE, /* pc_relative */
1013 0, /* bitpos */
1014 complain_overflow_dont,/* complain_on_overflow */
1015 bfd_elf_generic_reloc, /* special_function */
1016 "R_PPC64_ADDR16_LO_DS",/* name */
1017 FALSE, /* partial_inplace */
1018 0, /* src_mask */
1019 0xfffc, /* dst_mask */
1020 FALSE), /* pcrel_offset */
1021
1022 /* Like R_PPC64_GOT16, but for instructions with a DS field. */
1023 HOWTO (R_PPC64_GOT16_DS, /* type */
1024 0, /* rightshift */
1025 1, /* size (0 = byte, 1 = short, 2 = long) */
1026 16, /* bitsize */
1027 FALSE, /* pc_relative */
1028 0, /* bitpos */
1029 complain_overflow_signed, /* complain_on_overflow */
1030 ppc64_elf_unhandled_reloc, /* special_function */
1031 "R_PPC64_GOT16_DS", /* name */
1032 FALSE, /* partial_inplace */
1033 0, /* src_mask */
1034 0xfffc, /* dst_mask */
1035 FALSE), /* pcrel_offset */
1036
1037 /* Like R_PPC64_GOT16_LO, but for instructions with a DS field. */
1038 HOWTO (R_PPC64_GOT16_LO_DS, /* type */
1039 0, /* rightshift */
1040 1, /* size (0 = byte, 1 = short, 2 = long) */
1041 16, /* bitsize */
1042 FALSE, /* pc_relative */
1043 0, /* bitpos */
1044 complain_overflow_dont, /* complain_on_overflow */
1045 ppc64_elf_unhandled_reloc, /* special_function */
1046 "R_PPC64_GOT16_LO_DS", /* name */
1047 FALSE, /* partial_inplace */
1048 0, /* src_mask */
1049 0xfffc, /* dst_mask */
1050 FALSE), /* pcrel_offset */
1051
1052 /* Like R_PPC64_PLT16_LO, but for instructions with a DS field. */
1053 HOWTO (R_PPC64_PLT16_LO_DS, /* type */
1054 0, /* rightshift */
1055 1, /* size (0 = byte, 1 = short, 2 = long) */
1056 16, /* bitsize */
1057 FALSE, /* pc_relative */
1058 0, /* bitpos */
1059 complain_overflow_dont, /* complain_on_overflow */
1060 ppc64_elf_unhandled_reloc, /* special_function */
1061 "R_PPC64_PLT16_LO_DS", /* name */
1062 FALSE, /* partial_inplace */
1063 0, /* src_mask */
1064 0xfffc, /* dst_mask */
1065 FALSE), /* pcrel_offset */
1066
1067 /* Like R_PPC64_SECTOFF, but for instructions with a DS field. */
1068 HOWTO (R_PPC64_SECTOFF_DS, /* type */
1069 0, /* rightshift */
1070 1, /* size (0 = byte, 1 = short, 2 = long) */
1071 16, /* bitsize */
1072 FALSE, /* pc_relative */
1073 0, /* bitpos */
1074 complain_overflow_bitfield, /* complain_on_overflow */
1075 ppc64_elf_sectoff_reloc, /* special_function */
1076 "R_PPC64_SECTOFF_DS", /* name */
1077 FALSE, /* partial_inplace */
1078 0, /* src_mask */
1079 0xfffc, /* dst_mask */
1080 FALSE), /* pcrel_offset */
1081
1082 /* Like R_PPC64_SECTOFF_LO, but for instructions with a DS field. */
1083 HOWTO (R_PPC64_SECTOFF_LO_DS, /* type */
1084 0, /* rightshift */
1085 1, /* size (0 = byte, 1 = short, 2 = long) */
1086 16, /* bitsize */
1087 FALSE, /* pc_relative */
1088 0, /* bitpos */
1089 complain_overflow_dont, /* complain_on_overflow */
1090 ppc64_elf_sectoff_reloc, /* special_function */
1091 "R_PPC64_SECTOFF_LO_DS",/* name */
1092 FALSE, /* partial_inplace */
1093 0, /* src_mask */
1094 0xfffc, /* dst_mask */
1095 FALSE), /* pcrel_offset */
1096
1097 /* Like R_PPC64_TOC16, but for instructions with a DS field. */
1098 HOWTO (R_PPC64_TOC16_DS, /* type */
1099 0, /* rightshift */
1100 1, /* size (0 = byte, 1 = short, 2 = long) */
1101 16, /* bitsize */
1102 FALSE, /* pc_relative */
1103 0, /* bitpos */
1104 complain_overflow_signed, /* complain_on_overflow */
1105 ppc64_elf_toc_reloc, /* special_function */
1106 "R_PPC64_TOC16_DS", /* name */
1107 FALSE, /* partial_inplace */
1108 0, /* src_mask */
1109 0xfffc, /* dst_mask */
1110 FALSE), /* pcrel_offset */
1111
1112 /* Like R_PPC64_TOC16_LO, but for instructions with a DS field. */
1113 HOWTO (R_PPC64_TOC16_LO_DS, /* type */
1114 0, /* rightshift */
1115 1, /* size (0 = byte, 1 = short, 2 = long) */
1116 16, /* bitsize */
1117 FALSE, /* pc_relative */
1118 0, /* bitpos */
1119 complain_overflow_dont, /* complain_on_overflow */
1120 ppc64_elf_toc_reloc, /* special_function */
1121 "R_PPC64_TOC16_LO_DS", /* name */
1122 FALSE, /* partial_inplace */
1123 0, /* src_mask */
1124 0xfffc, /* dst_mask */
1125 FALSE), /* pcrel_offset */
1126
1127 /* Like R_PPC64_PLTGOT16, but for instructions with a DS field. */
1128 /* FIXME: R_PPC64_PLTGOT16_DS not implemented. */
1129 HOWTO (R_PPC64_PLTGOT16_DS, /* type */
1130 0, /* rightshift */
1131 1, /* size (0 = byte, 1 = short, 2 = long) */
1132 16, /* bitsize */
1133 FALSE, /* pc_relative */
1134 0, /* bitpos */
1135 complain_overflow_signed, /* complain_on_overflow */
1136 ppc64_elf_unhandled_reloc, /* special_function */
1137 "R_PPC64_PLTGOT16_DS", /* name */
1138 FALSE, /* partial_inplace */
1139 0, /* src_mask */
1140 0xfffc, /* dst_mask */
1141 FALSE), /* pcrel_offset */
1142
1143 /* Like R_PPC64_PLTGOT16_LO, but for instructions with a DS field. */
1144 /* FIXME: R_PPC64_PLTGOT16_LO not implemented. */
1145 HOWTO (R_PPC64_PLTGOT16_LO_DS,/* type */
1146 0, /* rightshift */
1147 1, /* size (0 = byte, 1 = short, 2 = long) */
1148 16, /* bitsize */
1149 FALSE, /* pc_relative */
1150 0, /* bitpos */
1151 complain_overflow_dont, /* complain_on_overflow */
1152 ppc64_elf_unhandled_reloc, /* special_function */
1153 "R_PPC64_PLTGOT16_LO_DS",/* name */
1154 FALSE, /* partial_inplace */
1155 0, /* src_mask */
1156 0xfffc, /* dst_mask */
1157 FALSE), /* pcrel_offset */
1158
1159 /* Marker reloc for TLS. */
1160 HOWTO (R_PPC64_TLS,
1161 0, /* rightshift */
1162 2, /* size (0 = byte, 1 = short, 2 = long) */
1163 32, /* bitsize */
1164 FALSE, /* pc_relative */
1165 0, /* bitpos */
1166 complain_overflow_dont, /* complain_on_overflow */
1167 bfd_elf_generic_reloc, /* special_function */
1168 "R_PPC64_TLS", /* name */
1169 FALSE, /* partial_inplace */
1170 0, /* src_mask */
1171 0, /* dst_mask */
1172 FALSE), /* pcrel_offset */
1173
1174 /* Computes the load module index of the load module that contains the
1175 definition of its TLS sym. */
1176 HOWTO (R_PPC64_DTPMOD64,
1177 0, /* rightshift */
1178 4, /* size (0 = byte, 1 = short, 2 = long) */
1179 64, /* bitsize */
1180 FALSE, /* pc_relative */
1181 0, /* bitpos */
1182 complain_overflow_dont, /* complain_on_overflow */
1183 ppc64_elf_unhandled_reloc, /* special_function */
1184 "R_PPC64_DTPMOD64", /* name */
1185 FALSE, /* partial_inplace */
1186 0, /* src_mask */
1187 ONES (64), /* dst_mask */
1188 FALSE), /* pcrel_offset */
1189
1190 /* Computes a dtv-relative displacement, the difference between the value
1191 of sym+add and the base address of the thread-local storage block that
1192 contains the definition of sym, minus 0x8000. */
1193 HOWTO (R_PPC64_DTPREL64,
1194 0, /* rightshift */
1195 4, /* size (0 = byte, 1 = short, 2 = long) */
1196 64, /* bitsize */
1197 FALSE, /* pc_relative */
1198 0, /* bitpos */
1199 complain_overflow_dont, /* complain_on_overflow */
1200 ppc64_elf_unhandled_reloc, /* special_function */
1201 "R_PPC64_DTPREL64", /* name */
1202 FALSE, /* partial_inplace */
1203 0, /* src_mask */
1204 ONES (64), /* dst_mask */
1205 FALSE), /* pcrel_offset */
1206
1207 /* A 16 bit dtprel reloc. */
1208 HOWTO (R_PPC64_DTPREL16,
1209 0, /* rightshift */
1210 1, /* size (0 = byte, 1 = short, 2 = long) */
1211 16, /* bitsize */
1212 FALSE, /* pc_relative */
1213 0, /* bitpos */
1214 complain_overflow_signed, /* complain_on_overflow */
1215 ppc64_elf_unhandled_reloc, /* special_function */
1216 "R_PPC64_DTPREL16", /* name */
1217 FALSE, /* partial_inplace */
1218 0, /* src_mask */
1219 0xffff, /* dst_mask */
1220 FALSE), /* pcrel_offset */
1221
1222 /* Like DTPREL16, but no overflow. */
1223 HOWTO (R_PPC64_DTPREL16_LO,
1224 0, /* rightshift */
1225 1, /* size (0 = byte, 1 = short, 2 = long) */
1226 16, /* bitsize */
1227 FALSE, /* pc_relative */
1228 0, /* bitpos */
1229 complain_overflow_dont, /* complain_on_overflow */
1230 ppc64_elf_unhandled_reloc, /* special_function */
1231 "R_PPC64_DTPREL16_LO", /* name */
1232 FALSE, /* partial_inplace */
1233 0, /* src_mask */
1234 0xffff, /* dst_mask */
1235 FALSE), /* pcrel_offset */
1236
1237 /* Like DTPREL16_LO, but next higher group of 16 bits. */
1238 HOWTO (R_PPC64_DTPREL16_HI,
1239 16, /* rightshift */
1240 1, /* size (0 = byte, 1 = short, 2 = long) */
1241 16, /* bitsize */
1242 FALSE, /* pc_relative */
1243 0, /* bitpos */
1244 complain_overflow_dont, /* complain_on_overflow */
1245 ppc64_elf_unhandled_reloc, /* special_function */
1246 "R_PPC64_DTPREL16_HI", /* name */
1247 FALSE, /* partial_inplace */
1248 0, /* src_mask */
1249 0xffff, /* dst_mask */
1250 FALSE), /* pcrel_offset */
1251
1252 /* Like DTPREL16_HI, but adjust for low 16 bits. */
1253 HOWTO (R_PPC64_DTPREL16_HA,
1254 16, /* rightshift */
1255 1, /* size (0 = byte, 1 = short, 2 = long) */
1256 16, /* bitsize */
1257 FALSE, /* pc_relative */
1258 0, /* bitpos */
1259 complain_overflow_dont, /* complain_on_overflow */
1260 ppc64_elf_unhandled_reloc, /* special_function */
1261 "R_PPC64_DTPREL16_HA", /* name */
1262 FALSE, /* partial_inplace */
1263 0, /* src_mask */
1264 0xffff, /* dst_mask */
1265 FALSE), /* pcrel_offset */
1266
1267 /* Like DTPREL16_HI, but next higher group of 16 bits. */
1268 HOWTO (R_PPC64_DTPREL16_HIGHER,
1269 32, /* rightshift */
1270 1, /* size (0 = byte, 1 = short, 2 = long) */
1271 16, /* bitsize */
1272 FALSE, /* pc_relative */
1273 0, /* bitpos */
1274 complain_overflow_dont, /* complain_on_overflow */
1275 ppc64_elf_unhandled_reloc, /* special_function */
1276 "R_PPC64_DTPREL16_HIGHER", /* name */
1277 FALSE, /* partial_inplace */
1278 0, /* src_mask */
1279 0xffff, /* dst_mask */
1280 FALSE), /* pcrel_offset */
1281
1282 /* Like DTPREL16_HIGHER, but adjust for low 16 bits. */
1283 HOWTO (R_PPC64_DTPREL16_HIGHERA,
1284 32, /* rightshift */
1285 1, /* size (0 = byte, 1 = short, 2 = long) */
1286 16, /* bitsize */
1287 FALSE, /* pc_relative */
1288 0, /* bitpos */
1289 complain_overflow_dont, /* complain_on_overflow */
1290 ppc64_elf_unhandled_reloc, /* special_function */
1291 "R_PPC64_DTPREL16_HIGHERA", /* name */
1292 FALSE, /* partial_inplace */
1293 0, /* src_mask */
1294 0xffff, /* dst_mask */
1295 FALSE), /* pcrel_offset */
1296
1297 /* Like DTPREL16_HIGHER, but next higher group of 16 bits. */
1298 HOWTO (R_PPC64_DTPREL16_HIGHEST,
1299 48, /* rightshift */
1300 1, /* size (0 = byte, 1 = short, 2 = long) */
1301 16, /* bitsize */
1302 FALSE, /* pc_relative */
1303 0, /* bitpos */
1304 complain_overflow_dont, /* complain_on_overflow */
1305 ppc64_elf_unhandled_reloc, /* special_function */
1306 "R_PPC64_DTPREL16_HIGHEST", /* name */
1307 FALSE, /* partial_inplace */
1308 0, /* src_mask */
1309 0xffff, /* dst_mask */
1310 FALSE), /* pcrel_offset */
1311
1312 /* Like DTPREL16_HIGHEST, but adjust for low 16 bits. */
1313 HOWTO (R_PPC64_DTPREL16_HIGHESTA,
1314 48, /* rightshift */
1315 1, /* size (0 = byte, 1 = short, 2 = long) */
1316 16, /* bitsize */
1317 FALSE, /* pc_relative */
1318 0, /* bitpos */
1319 complain_overflow_dont, /* complain_on_overflow */
1320 ppc64_elf_unhandled_reloc, /* special_function */
1321 "R_PPC64_DTPREL16_HIGHESTA", /* name */
1322 FALSE, /* partial_inplace */
1323 0, /* src_mask */
1324 0xffff, /* dst_mask */
1325 FALSE), /* pcrel_offset */
1326
1327 /* Like DTPREL16, but for insns with a DS field. */
1328 HOWTO (R_PPC64_DTPREL16_DS,
1329 0, /* rightshift */
1330 1, /* size (0 = byte, 1 = short, 2 = long) */
1331 16, /* bitsize */
1332 FALSE, /* pc_relative */
1333 0, /* bitpos */
1334 complain_overflow_signed, /* complain_on_overflow */
1335 ppc64_elf_unhandled_reloc, /* special_function */
1336 "R_PPC64_DTPREL16_DS", /* name */
1337 FALSE, /* partial_inplace */
1338 0, /* src_mask */
1339 0xfffc, /* dst_mask */
1340 FALSE), /* pcrel_offset */
1341
1342 /* Like DTPREL16_DS, but no overflow. */
1343 HOWTO (R_PPC64_DTPREL16_LO_DS,
1344 0, /* rightshift */
1345 1, /* size (0 = byte, 1 = short, 2 = long) */
1346 16, /* bitsize */
1347 FALSE, /* pc_relative */
1348 0, /* bitpos */
1349 complain_overflow_dont, /* complain_on_overflow */
1350 ppc64_elf_unhandled_reloc, /* special_function */
1351 "R_PPC64_DTPREL16_LO_DS", /* name */
1352 FALSE, /* partial_inplace */
1353 0, /* src_mask */
1354 0xfffc, /* dst_mask */
1355 FALSE), /* pcrel_offset */
1356
1357 /* Computes a tp-relative displacement, the difference between the value of
1358 sym+add and the value of the thread pointer (r13). */
1359 HOWTO (R_PPC64_TPREL64,
1360 0, /* rightshift */
1361 4, /* size (0 = byte, 1 = short, 2 = long) */
1362 64, /* bitsize */
1363 FALSE, /* pc_relative */
1364 0, /* bitpos */
1365 complain_overflow_dont, /* complain_on_overflow */
1366 ppc64_elf_unhandled_reloc, /* special_function */
1367 "R_PPC64_TPREL64", /* name */
1368 FALSE, /* partial_inplace */
1369 0, /* src_mask */
1370 ONES (64), /* dst_mask */
1371 FALSE), /* pcrel_offset */
1372
1373 /* A 16 bit tprel reloc. */
1374 HOWTO (R_PPC64_TPREL16,
1375 0, /* rightshift */
1376 1, /* size (0 = byte, 1 = short, 2 = long) */
1377 16, /* bitsize */
1378 FALSE, /* pc_relative */
1379 0, /* bitpos */
1380 complain_overflow_signed, /* complain_on_overflow */
1381 ppc64_elf_unhandled_reloc, /* special_function */
1382 "R_PPC64_TPREL16", /* name */
1383 FALSE, /* partial_inplace */
1384 0, /* src_mask */
1385 0xffff, /* dst_mask */
1386 FALSE), /* pcrel_offset */
1387
1388 /* Like TPREL16, but no overflow. */
1389 HOWTO (R_PPC64_TPREL16_LO,
1390 0, /* rightshift */
1391 1, /* size (0 = byte, 1 = short, 2 = long) */
1392 16, /* bitsize */
1393 FALSE, /* pc_relative */
1394 0, /* bitpos */
1395 complain_overflow_dont, /* complain_on_overflow */
1396 ppc64_elf_unhandled_reloc, /* special_function */
1397 "R_PPC64_TPREL16_LO", /* name */
1398 FALSE, /* partial_inplace */
1399 0, /* src_mask */
1400 0xffff, /* dst_mask */
1401 FALSE), /* pcrel_offset */
1402
1403 /* Like TPREL16_LO, but next higher group of 16 bits. */
1404 HOWTO (R_PPC64_TPREL16_HI,
1405 16, /* rightshift */
1406 1, /* size (0 = byte, 1 = short, 2 = long) */
1407 16, /* bitsize */
1408 FALSE, /* pc_relative */
1409 0, /* bitpos */
1410 complain_overflow_dont, /* complain_on_overflow */
1411 ppc64_elf_unhandled_reloc, /* special_function */
1412 "R_PPC64_TPREL16_HI", /* name */
1413 FALSE, /* partial_inplace */
1414 0, /* src_mask */
1415 0xffff, /* dst_mask */
1416 FALSE), /* pcrel_offset */
1417
1418 /* Like TPREL16_HI, but adjust for low 16 bits. */
1419 HOWTO (R_PPC64_TPREL16_HA,
1420 16, /* rightshift */
1421 1, /* size (0 = byte, 1 = short, 2 = long) */
1422 16, /* bitsize */
1423 FALSE, /* pc_relative */
1424 0, /* bitpos */
1425 complain_overflow_dont, /* complain_on_overflow */
1426 ppc64_elf_unhandled_reloc, /* special_function */
1427 "R_PPC64_TPREL16_HA", /* name */
1428 FALSE, /* partial_inplace */
1429 0, /* src_mask */
1430 0xffff, /* dst_mask */
1431 FALSE), /* pcrel_offset */
1432
1433 /* Like TPREL16_HI, but next higher group of 16 bits. */
1434 HOWTO (R_PPC64_TPREL16_HIGHER,
1435 32, /* rightshift */
1436 1, /* size (0 = byte, 1 = short, 2 = long) */
1437 16, /* bitsize */
1438 FALSE, /* pc_relative */
1439 0, /* bitpos */
1440 complain_overflow_dont, /* complain_on_overflow */
1441 ppc64_elf_unhandled_reloc, /* special_function */
1442 "R_PPC64_TPREL16_HIGHER", /* name */
1443 FALSE, /* partial_inplace */
1444 0, /* src_mask */
1445 0xffff, /* dst_mask */
1446 FALSE), /* pcrel_offset */
1447
1448 /* Like TPREL16_HIGHER, but adjust for low 16 bits. */
1449 HOWTO (R_PPC64_TPREL16_HIGHERA,
1450 32, /* rightshift */
1451 1, /* size (0 = byte, 1 = short, 2 = long) */
1452 16, /* bitsize */
1453 FALSE, /* pc_relative */
1454 0, /* bitpos */
1455 complain_overflow_dont, /* complain_on_overflow */
1456 ppc64_elf_unhandled_reloc, /* special_function */
1457 "R_PPC64_TPREL16_HIGHERA", /* name */
1458 FALSE, /* partial_inplace */
1459 0, /* src_mask */
1460 0xffff, /* dst_mask */
1461 FALSE), /* pcrel_offset */
1462
1463 /* Like TPREL16_HIGHER, but next higher group of 16 bits. */
1464 HOWTO (R_PPC64_TPREL16_HIGHEST,
1465 48, /* rightshift */
1466 1, /* size (0 = byte, 1 = short, 2 = long) */
1467 16, /* bitsize */
1468 FALSE, /* pc_relative */
1469 0, /* bitpos */
1470 complain_overflow_dont, /* complain_on_overflow */
1471 ppc64_elf_unhandled_reloc, /* special_function */
1472 "R_PPC64_TPREL16_HIGHEST", /* name */
1473 FALSE, /* partial_inplace */
1474 0, /* src_mask */
1475 0xffff, /* dst_mask */
1476 FALSE), /* pcrel_offset */
1477
1478 /* Like TPREL16_HIGHEST, but adjust for low 16 bits. */
1479 HOWTO (R_PPC64_TPREL16_HIGHESTA,
1480 48, /* rightshift */
1481 1, /* size (0 = byte, 1 = short, 2 = long) */
1482 16, /* bitsize */
1483 FALSE, /* pc_relative */
1484 0, /* bitpos */
1485 complain_overflow_dont, /* complain_on_overflow */
1486 ppc64_elf_unhandled_reloc, /* special_function */
1487 "R_PPC64_TPREL16_HIGHESTA", /* name */
1488 FALSE, /* partial_inplace */
1489 0, /* src_mask */
1490 0xffff, /* dst_mask */
1491 FALSE), /* pcrel_offset */
1492
1493 /* Like TPREL16, but for insns with a DS field. */
1494 HOWTO (R_PPC64_TPREL16_DS,
1495 0, /* rightshift */
1496 1, /* size (0 = byte, 1 = short, 2 = long) */
1497 16, /* bitsize */
1498 FALSE, /* pc_relative */
1499 0, /* bitpos */
1500 complain_overflow_signed, /* complain_on_overflow */
1501 ppc64_elf_unhandled_reloc, /* special_function */
1502 "R_PPC64_TPREL16_DS", /* name */
1503 FALSE, /* partial_inplace */
1504 0, /* src_mask */
1505 0xfffc, /* dst_mask */
1506 FALSE), /* pcrel_offset */
1507
1508 /* Like TPREL16_DS, but no overflow. */
1509 HOWTO (R_PPC64_TPREL16_LO_DS,
1510 0, /* rightshift */
1511 1, /* size (0 = byte, 1 = short, 2 = long) */
1512 16, /* bitsize */
1513 FALSE, /* pc_relative */
1514 0, /* bitpos */
1515 complain_overflow_dont, /* complain_on_overflow */
1516 ppc64_elf_unhandled_reloc, /* special_function */
1517 "R_PPC64_TPREL16_LO_DS", /* name */
1518 FALSE, /* partial_inplace */
1519 0, /* src_mask */
1520 0xfffc, /* dst_mask */
1521 FALSE), /* pcrel_offset */
1522
1523 /* Allocates two contiguous entries in the GOT to hold a tls_index structure,
1524 with values (sym+add)@dtpmod and (sym+add)@dtprel, and computes the offset
1525 to the first entry relative to the TOC base (r2). */
1526 HOWTO (R_PPC64_GOT_TLSGD16,
1527 0, /* rightshift */
1528 1, /* size (0 = byte, 1 = short, 2 = long) */
1529 16, /* bitsize */
1530 FALSE, /* pc_relative */
1531 0, /* bitpos */
1532 complain_overflow_signed, /* complain_on_overflow */
1533 ppc64_elf_unhandled_reloc, /* special_function */
1534 "R_PPC64_GOT_TLSGD16", /* name */
1535 FALSE, /* partial_inplace */
1536 0, /* src_mask */
1537 0xffff, /* dst_mask */
1538 FALSE), /* pcrel_offset */
1539
1540 /* Like GOT_TLSGD16, but no overflow. */
1541 HOWTO (R_PPC64_GOT_TLSGD16_LO,
1542 0, /* rightshift */
1543 1, /* size (0 = byte, 1 = short, 2 = long) */
1544 16, /* bitsize */
1545 FALSE, /* pc_relative */
1546 0, /* bitpos */
1547 complain_overflow_dont, /* complain_on_overflow */
1548 ppc64_elf_unhandled_reloc, /* special_function */
1549 "R_PPC64_GOT_TLSGD16_LO", /* name */
1550 FALSE, /* partial_inplace */
1551 0, /* src_mask */
1552 0xffff, /* dst_mask */
1553 FALSE), /* pcrel_offset */
1554
1555 /* Like GOT_TLSGD16_LO, but next higher group of 16 bits. */
1556 HOWTO (R_PPC64_GOT_TLSGD16_HI,
1557 16, /* rightshift */
1558 1, /* size (0 = byte, 1 = short, 2 = long) */
1559 16, /* bitsize */
1560 FALSE, /* pc_relative */
1561 0, /* bitpos */
1562 complain_overflow_dont, /* complain_on_overflow */
1563 ppc64_elf_unhandled_reloc, /* special_function */
1564 "R_PPC64_GOT_TLSGD16_HI", /* name */
1565 FALSE, /* partial_inplace */
1566 0, /* src_mask */
1567 0xffff, /* dst_mask */
1568 FALSE), /* pcrel_offset */
1569
1570 /* Like GOT_TLSGD16_HI, but adjust for low 16 bits. */
1571 HOWTO (R_PPC64_GOT_TLSGD16_HA,
1572 16, /* rightshift */
1573 1, /* size (0 = byte, 1 = short, 2 = long) */
1574 16, /* bitsize */
1575 FALSE, /* pc_relative */
1576 0, /* bitpos */
1577 complain_overflow_dont, /* complain_on_overflow */
1578 ppc64_elf_unhandled_reloc, /* special_function */
1579 "R_PPC64_GOT_TLSGD16_HA", /* name */
1580 FALSE, /* partial_inplace */
1581 0, /* src_mask */
1582 0xffff, /* dst_mask */
1583 FALSE), /* pcrel_offset */
1584
1585 /* Allocates two contiguous entries in the GOT to hold a tls_index structure,
1586 with values (sym+add)@dtpmod and zero, and computes the offset to the
1587 first entry relative to the TOC base (r2). */
1588 HOWTO (R_PPC64_GOT_TLSLD16,
1589 0, /* rightshift */
1590 1, /* size (0 = byte, 1 = short, 2 = long) */
1591 16, /* bitsize */
1592 FALSE, /* pc_relative */
1593 0, /* bitpos */
1594 complain_overflow_signed, /* complain_on_overflow */
1595 ppc64_elf_unhandled_reloc, /* special_function */
1596 "R_PPC64_GOT_TLSLD16", /* name */
1597 FALSE, /* partial_inplace */
1598 0, /* src_mask */
1599 0xffff, /* dst_mask */
1600 FALSE), /* pcrel_offset */
1601
1602 /* Like GOT_TLSLD16, but no overflow. */
1603 HOWTO (R_PPC64_GOT_TLSLD16_LO,
1604 0, /* rightshift */
1605 1, /* size (0 = byte, 1 = short, 2 = long) */
1606 16, /* bitsize */
1607 FALSE, /* pc_relative */
1608 0, /* bitpos */
1609 complain_overflow_dont, /* complain_on_overflow */
1610 ppc64_elf_unhandled_reloc, /* special_function */
1611 "R_PPC64_GOT_TLSLD16_LO", /* name */
1612 FALSE, /* partial_inplace */
1613 0, /* src_mask */
1614 0xffff, /* dst_mask */
1615 FALSE), /* pcrel_offset */
1616
1617 /* Like GOT_TLSLD16_LO, but next higher group of 16 bits. */
1618 HOWTO (R_PPC64_GOT_TLSLD16_HI,
1619 16, /* rightshift */
1620 1, /* size (0 = byte, 1 = short, 2 = long) */
1621 16, /* bitsize */
1622 FALSE, /* pc_relative */
1623 0, /* bitpos */
1624 complain_overflow_dont, /* complain_on_overflow */
1625 ppc64_elf_unhandled_reloc, /* special_function */
1626 "R_PPC64_GOT_TLSLD16_HI", /* name */
1627 FALSE, /* partial_inplace */
1628 0, /* src_mask */
1629 0xffff, /* dst_mask */
1630 FALSE), /* pcrel_offset */
1631
1632 /* Like GOT_TLSLD16_HI, but adjust for low 16 bits. */
1633 HOWTO (R_PPC64_GOT_TLSLD16_HA,
1634 16, /* rightshift */
1635 1, /* size (0 = byte, 1 = short, 2 = long) */
1636 16, /* bitsize */
1637 FALSE, /* pc_relative */
1638 0, /* bitpos */
1639 complain_overflow_dont, /* complain_on_overflow */
1640 ppc64_elf_unhandled_reloc, /* special_function */
1641 "R_PPC64_GOT_TLSLD16_HA", /* name */
1642 FALSE, /* partial_inplace */
1643 0, /* src_mask */
1644 0xffff, /* dst_mask */
1645 FALSE), /* pcrel_offset */
1646
1647 /* Allocates an entry in the GOT with value (sym+add)@dtprel, and computes
1648 the offset to the entry relative to the TOC base (r2). */
1649 HOWTO (R_PPC64_GOT_DTPREL16_DS,
1650 0, /* rightshift */
1651 1, /* size (0 = byte, 1 = short, 2 = long) */
1652 16, /* bitsize */
1653 FALSE, /* pc_relative */
1654 0, /* bitpos */
1655 complain_overflow_signed, /* complain_on_overflow */
1656 ppc64_elf_unhandled_reloc, /* special_function */
1657 "R_PPC64_GOT_DTPREL16_DS", /* name */
1658 FALSE, /* partial_inplace */
1659 0, /* src_mask */
1660 0xfffc, /* dst_mask */
1661 FALSE), /* pcrel_offset */
1662
1663 /* Like GOT_DTPREL16_DS, but no overflow. */
1664 HOWTO (R_PPC64_GOT_DTPREL16_LO_DS,
1665 0, /* rightshift */
1666 1, /* size (0 = byte, 1 = short, 2 = long) */
1667 16, /* bitsize */
1668 FALSE, /* pc_relative */
1669 0, /* bitpos */
1670 complain_overflow_dont, /* complain_on_overflow */
1671 ppc64_elf_unhandled_reloc, /* special_function */
1672 "R_PPC64_GOT_DTPREL16_LO_DS", /* name */
1673 FALSE, /* partial_inplace */
1674 0, /* src_mask */
1675 0xfffc, /* dst_mask */
1676 FALSE), /* pcrel_offset */
1677
1678 /* Like GOT_DTPREL16_LO_DS, but next higher group of 16 bits. */
1679 HOWTO (R_PPC64_GOT_DTPREL16_HI,
1680 16, /* rightshift */
1681 1, /* size (0 = byte, 1 = short, 2 = long) */
1682 16, /* bitsize */
1683 FALSE, /* pc_relative */
1684 0, /* bitpos */
1685 complain_overflow_dont, /* complain_on_overflow */
1686 ppc64_elf_unhandled_reloc, /* special_function */
1687 "R_PPC64_GOT_DTPREL16_HI", /* name */
1688 FALSE, /* partial_inplace */
1689 0, /* src_mask */
1690 0xffff, /* dst_mask */
1691 FALSE), /* pcrel_offset */
1692
1693 /* Like GOT_DTPREL16_HI, but adjust for low 16 bits. */
1694 HOWTO (R_PPC64_GOT_DTPREL16_HA,
1695 16, /* rightshift */
1696 1, /* size (0 = byte, 1 = short, 2 = long) */
1697 16, /* bitsize */
1698 FALSE, /* pc_relative */
1699 0, /* bitpos */
1700 complain_overflow_dont, /* complain_on_overflow */
1701 ppc64_elf_unhandled_reloc, /* special_function */
1702 "R_PPC64_GOT_DTPREL16_HA", /* name */
1703 FALSE, /* partial_inplace */
1704 0, /* src_mask */
1705 0xffff, /* dst_mask */
1706 FALSE), /* pcrel_offset */
1707
1708 /* Allocates an entry in the GOT with value (sym+add)@tprel, and computes the
1709 offset to the entry relative to the TOC base (r2). */
1710 HOWTO (R_PPC64_GOT_TPREL16_DS,
1711 0, /* rightshift */
1712 1, /* size (0 = byte, 1 = short, 2 = long) */
1713 16, /* bitsize */
1714 FALSE, /* pc_relative */
1715 0, /* bitpos */
1716 complain_overflow_signed, /* complain_on_overflow */
1717 ppc64_elf_unhandled_reloc, /* special_function */
1718 "R_PPC64_GOT_TPREL16_DS", /* name */
1719 FALSE, /* partial_inplace */
1720 0, /* src_mask */
1721 0xffff, /* dst_mask */
1722 FALSE), /* pcrel_offset */
1723
1724 /* Like GOT_TPREL16_DS, but no overflow. */
1725 HOWTO (R_PPC64_GOT_TPREL16_LO_DS,
1726 0, /* rightshift */
1727 1, /* size (0 = byte, 1 = short, 2 = long) */
1728 16, /* bitsize */
1729 FALSE, /* pc_relative */
1730 0, /* bitpos */
1731 complain_overflow_dont, /* complain_on_overflow */
1732 ppc64_elf_unhandled_reloc, /* special_function */
1733 "R_PPC64_GOT_TPREL16_LO_DS", /* name */
1734 FALSE, /* partial_inplace */
1735 0, /* src_mask */
1736 0xffff, /* dst_mask */
1737 FALSE), /* pcrel_offset */
1738
1739 /* Like GOT_TPREL16_LO_DS, but next higher group of 16 bits. */
1740 HOWTO (R_PPC64_GOT_TPREL16_HI,
1741 16, /* rightshift */
1742 1, /* size (0 = byte, 1 = short, 2 = long) */
1743 16, /* bitsize */
1744 FALSE, /* pc_relative */
1745 0, /* bitpos */
1746 complain_overflow_dont, /* complain_on_overflow */
1747 ppc64_elf_unhandled_reloc, /* special_function */
1748 "R_PPC64_GOT_TPREL16_HI", /* name */
1749 FALSE, /* partial_inplace */
1750 0, /* src_mask */
1751 0xffff, /* dst_mask */
1752 FALSE), /* pcrel_offset */
1753
1754 /* Like GOT_TPREL16_HI, but adjust for low 16 bits. */
1755 HOWTO (R_PPC64_GOT_TPREL16_HA,
1756 16, /* rightshift */
1757 1, /* size (0 = byte, 1 = short, 2 = long) */
1758 16, /* bitsize */
1759 FALSE, /* pc_relative */
1760 0, /* bitpos */
1761 complain_overflow_dont, /* complain_on_overflow */
1762 ppc64_elf_unhandled_reloc, /* special_function */
1763 "R_PPC64_GOT_TPREL16_HA", /* name */
1764 FALSE, /* partial_inplace */
1765 0, /* src_mask */
1766 0xffff, /* dst_mask */
1767 FALSE), /* pcrel_offset */
1768
1769 /* GNU extension to record C++ vtable hierarchy. */
1770 HOWTO (R_PPC64_GNU_VTINHERIT, /* type */
1771 0, /* rightshift */
1772 0, /* size (0 = byte, 1 = short, 2 = long) */
1773 0, /* bitsize */
1774 FALSE, /* pc_relative */
1775 0, /* bitpos */
1776 complain_overflow_dont, /* complain_on_overflow */
1777 NULL, /* special_function */
1778 "R_PPC64_GNU_VTINHERIT", /* name */
1779 FALSE, /* partial_inplace */
1780 0, /* src_mask */
1781 0, /* dst_mask */
1782 FALSE), /* pcrel_offset */
1783
1784 /* GNU extension to record C++ vtable member usage. */
1785 HOWTO (R_PPC64_GNU_VTENTRY, /* type */
1786 0, /* rightshift */
1787 0, /* size (0 = byte, 1 = short, 2 = long) */
1788 0, /* bitsize */
1789 FALSE, /* pc_relative */
1790 0, /* bitpos */
1791 complain_overflow_dont, /* complain_on_overflow */
1792 NULL, /* special_function */
1793 "R_PPC64_GNU_VTENTRY", /* name */
1794 FALSE, /* partial_inplace */
1795 0, /* src_mask */
1796 0, /* dst_mask */
1797 FALSE), /* pcrel_offset */
1798 };
1799
1800 \f
1801 /* Initialize the ppc64_elf_howto_table, so that linear accesses can
1802 be done. */
1803
1804 static void
1805 ppc_howto_init ()
1806 {
1807 unsigned int i, type;
1808
1809 for (i = 0;
1810 i < sizeof (ppc64_elf_howto_raw) / sizeof (ppc64_elf_howto_raw[0]);
1811 i++)
1812 {
1813 type = ppc64_elf_howto_raw[i].type;
1814 BFD_ASSERT (type < (sizeof (ppc64_elf_howto_table)
1815 / sizeof (ppc64_elf_howto_table[0])));
1816 ppc64_elf_howto_table[type] = &ppc64_elf_howto_raw[i];
1817 }
1818 }
1819
1820 static reloc_howto_type *
1821 ppc64_elf_reloc_type_lookup (abfd, code)
1822 bfd *abfd ATTRIBUTE_UNUSED;
1823 bfd_reloc_code_real_type code;
1824 {
1825 enum elf_ppc64_reloc_type r = R_PPC64_NONE;
1826
1827 if (!ppc64_elf_howto_table[R_PPC64_ADDR32])
1828 /* Initialize howto table if needed. */
1829 ppc_howto_init ();
1830
1831 switch ((int) code)
1832 {
1833 default:
1834 return (reloc_howto_type *) NULL;
1835
1836 case BFD_RELOC_NONE: r = R_PPC64_NONE;
1837 break;
1838 case BFD_RELOC_32: r = R_PPC64_ADDR32;
1839 break;
1840 case BFD_RELOC_PPC_BA26: r = R_PPC64_ADDR24;
1841 break;
1842 case BFD_RELOC_16: r = R_PPC64_ADDR16;
1843 break;
1844 case BFD_RELOC_LO16: r = R_PPC64_ADDR16_LO;
1845 break;
1846 case BFD_RELOC_HI16: r = R_PPC64_ADDR16_HI;
1847 break;
1848 case BFD_RELOC_HI16_S: r = R_PPC64_ADDR16_HA;
1849 break;
1850 case BFD_RELOC_PPC_BA16: r = R_PPC64_ADDR14;
1851 break;
1852 case BFD_RELOC_PPC_BA16_BRTAKEN: r = R_PPC64_ADDR14_BRTAKEN;
1853 break;
1854 case BFD_RELOC_PPC_BA16_BRNTAKEN: r = R_PPC64_ADDR14_BRNTAKEN;
1855 break;
1856 case BFD_RELOC_PPC_B26: r = R_PPC64_REL24;
1857 break;
1858 case BFD_RELOC_PPC_B16: r = R_PPC64_REL14;
1859 break;
1860 case BFD_RELOC_PPC_B16_BRTAKEN: r = R_PPC64_REL14_BRTAKEN;
1861 break;
1862 case BFD_RELOC_PPC_B16_BRNTAKEN: r = R_PPC64_REL14_BRNTAKEN;
1863 break;
1864 case BFD_RELOC_16_GOTOFF: r = R_PPC64_GOT16;
1865 break;
1866 case BFD_RELOC_LO16_GOTOFF: r = R_PPC64_GOT16_LO;
1867 break;
1868 case BFD_RELOC_HI16_GOTOFF: r = R_PPC64_GOT16_HI;
1869 break;
1870 case BFD_RELOC_HI16_S_GOTOFF: r = R_PPC64_GOT16_HA;
1871 break;
1872 case BFD_RELOC_PPC_COPY: r = R_PPC64_COPY;
1873 break;
1874 case BFD_RELOC_PPC_GLOB_DAT: r = R_PPC64_GLOB_DAT;
1875 break;
1876 case BFD_RELOC_32_PCREL: r = R_PPC64_REL32;
1877 break;
1878 case BFD_RELOC_32_PLTOFF: r = R_PPC64_PLT32;
1879 break;
1880 case BFD_RELOC_32_PLT_PCREL: r = R_PPC64_PLTREL32;
1881 break;
1882 case BFD_RELOC_LO16_PLTOFF: r = R_PPC64_PLT16_LO;
1883 break;
1884 case BFD_RELOC_HI16_PLTOFF: r = R_PPC64_PLT16_HI;
1885 break;
1886 case BFD_RELOC_HI16_S_PLTOFF: r = R_PPC64_PLT16_HA;
1887 break;
1888 case BFD_RELOC_16_BASEREL: r = R_PPC64_SECTOFF;
1889 break;
1890 case BFD_RELOC_LO16_BASEREL: r = R_PPC64_SECTOFF_LO;
1891 break;
1892 case BFD_RELOC_HI16_BASEREL: r = R_PPC64_SECTOFF_HI;
1893 break;
1894 case BFD_RELOC_HI16_S_BASEREL: r = R_PPC64_SECTOFF_HA;
1895 break;
1896 case BFD_RELOC_CTOR: r = R_PPC64_ADDR64;
1897 break;
1898 case BFD_RELOC_64: r = R_PPC64_ADDR64;
1899 break;
1900 case BFD_RELOC_PPC64_HIGHER: r = R_PPC64_ADDR16_HIGHER;
1901 break;
1902 case BFD_RELOC_PPC64_HIGHER_S: r = R_PPC64_ADDR16_HIGHERA;
1903 break;
1904 case BFD_RELOC_PPC64_HIGHEST: r = R_PPC64_ADDR16_HIGHEST;
1905 break;
1906 case BFD_RELOC_PPC64_HIGHEST_S: r = R_PPC64_ADDR16_HIGHESTA;
1907 break;
1908 case BFD_RELOC_64_PCREL: r = R_PPC64_REL64;
1909 break;
1910 case BFD_RELOC_64_PLTOFF: r = R_PPC64_PLT64;
1911 break;
1912 case BFD_RELOC_64_PLT_PCREL: r = R_PPC64_PLTREL64;
1913 break;
1914 case BFD_RELOC_PPC_TOC16: r = R_PPC64_TOC16;
1915 break;
1916 case BFD_RELOC_PPC64_TOC16_LO: r = R_PPC64_TOC16_LO;
1917 break;
1918 case BFD_RELOC_PPC64_TOC16_HI: r = R_PPC64_TOC16_HI;
1919 break;
1920 case BFD_RELOC_PPC64_TOC16_HA: r = R_PPC64_TOC16_HA;
1921 break;
1922 case BFD_RELOC_PPC64_TOC: r = R_PPC64_TOC;
1923 break;
1924 case BFD_RELOC_PPC64_PLTGOT16: r = R_PPC64_PLTGOT16;
1925 break;
1926 case BFD_RELOC_PPC64_PLTGOT16_LO: r = R_PPC64_PLTGOT16_LO;
1927 break;
1928 case BFD_RELOC_PPC64_PLTGOT16_HI: r = R_PPC64_PLTGOT16_HI;
1929 break;
1930 case BFD_RELOC_PPC64_PLTGOT16_HA: r = R_PPC64_PLTGOT16_HA;
1931 break;
1932 case BFD_RELOC_PPC64_ADDR16_DS: r = R_PPC64_ADDR16_DS;
1933 break;
1934 case BFD_RELOC_PPC64_ADDR16_LO_DS: r = R_PPC64_ADDR16_LO_DS;
1935 break;
1936 case BFD_RELOC_PPC64_GOT16_DS: r = R_PPC64_GOT16_DS;
1937 break;
1938 case BFD_RELOC_PPC64_GOT16_LO_DS: r = R_PPC64_GOT16_LO_DS;
1939 break;
1940 case BFD_RELOC_PPC64_PLT16_LO_DS: r = R_PPC64_PLT16_LO_DS;
1941 break;
1942 case BFD_RELOC_PPC64_SECTOFF_DS: r = R_PPC64_SECTOFF_DS;
1943 break;
1944 case BFD_RELOC_PPC64_SECTOFF_LO_DS: r = R_PPC64_SECTOFF_LO_DS;
1945 break;
1946 case BFD_RELOC_PPC64_TOC16_DS: r = R_PPC64_TOC16_DS;
1947 break;
1948 case BFD_RELOC_PPC64_TOC16_LO_DS: r = R_PPC64_TOC16_LO_DS;
1949 break;
1950 case BFD_RELOC_PPC64_PLTGOT16_DS: r = R_PPC64_PLTGOT16_DS;
1951 break;
1952 case BFD_RELOC_PPC64_PLTGOT16_LO_DS: r = R_PPC64_PLTGOT16_LO_DS;
1953 break;
1954 case BFD_RELOC_PPC_TLS: r = R_PPC64_TLS;
1955 break;
1956 case BFD_RELOC_PPC_DTPMOD: r = R_PPC64_DTPMOD64;
1957 break;
1958 case BFD_RELOC_PPC_TPREL16: r = R_PPC64_TPREL16;
1959 break;
1960 case BFD_RELOC_PPC_TPREL16_LO: r = R_PPC64_TPREL16_LO;
1961 break;
1962 case BFD_RELOC_PPC_TPREL16_HI: r = R_PPC64_TPREL16_HI;
1963 break;
1964 case BFD_RELOC_PPC_TPREL16_HA: r = R_PPC64_TPREL16_HA;
1965 break;
1966 case BFD_RELOC_PPC_TPREL: r = R_PPC64_TPREL64;
1967 break;
1968 case BFD_RELOC_PPC_DTPREL16: r = R_PPC64_DTPREL16;
1969 break;
1970 case BFD_RELOC_PPC_DTPREL16_LO: r = R_PPC64_DTPREL16_LO;
1971 break;
1972 case BFD_RELOC_PPC_DTPREL16_HI: r = R_PPC64_DTPREL16_HI;
1973 break;
1974 case BFD_RELOC_PPC_DTPREL16_HA: r = R_PPC64_DTPREL16_HA;
1975 break;
1976 case BFD_RELOC_PPC_DTPREL: r = R_PPC64_DTPREL64;
1977 break;
1978 case BFD_RELOC_PPC_GOT_TLSGD16: r = R_PPC64_GOT_TLSGD16;
1979 break;
1980 case BFD_RELOC_PPC_GOT_TLSGD16_LO: r = R_PPC64_GOT_TLSGD16_LO;
1981 break;
1982 case BFD_RELOC_PPC_GOT_TLSGD16_HI: r = R_PPC64_GOT_TLSGD16_HI;
1983 break;
1984 case BFD_RELOC_PPC_GOT_TLSGD16_HA: r = R_PPC64_GOT_TLSGD16_HA;
1985 break;
1986 case BFD_RELOC_PPC_GOT_TLSLD16: r = R_PPC64_GOT_TLSLD16;
1987 break;
1988 case BFD_RELOC_PPC_GOT_TLSLD16_LO: r = R_PPC64_GOT_TLSLD16_LO;
1989 break;
1990 case BFD_RELOC_PPC_GOT_TLSLD16_HI: r = R_PPC64_GOT_TLSLD16_HI;
1991 break;
1992 case BFD_RELOC_PPC_GOT_TLSLD16_HA: r = R_PPC64_GOT_TLSLD16_HA;
1993 break;
1994 case BFD_RELOC_PPC_GOT_TPREL16: r = R_PPC64_GOT_TPREL16_DS;
1995 break;
1996 case BFD_RELOC_PPC_GOT_TPREL16_LO: r = R_PPC64_GOT_TPREL16_LO_DS;
1997 break;
1998 case BFD_RELOC_PPC_GOT_TPREL16_HI: r = R_PPC64_GOT_TPREL16_HI;
1999 break;
2000 case BFD_RELOC_PPC_GOT_TPREL16_HA: r = R_PPC64_GOT_TPREL16_HA;
2001 break;
2002 case BFD_RELOC_PPC_GOT_DTPREL16: r = R_PPC64_GOT_DTPREL16_DS;
2003 break;
2004 case BFD_RELOC_PPC_GOT_DTPREL16_LO: r = R_PPC64_GOT_DTPREL16_LO_DS;
2005 break;
2006 case BFD_RELOC_PPC_GOT_DTPREL16_HI: r = R_PPC64_GOT_DTPREL16_HI;
2007 break;
2008 case BFD_RELOC_PPC_GOT_DTPREL16_HA: r = R_PPC64_GOT_DTPREL16_HA;
2009 break;
2010 case BFD_RELOC_PPC64_TPREL16_DS: r = R_PPC64_TPREL16_DS;
2011 break;
2012 case BFD_RELOC_PPC64_TPREL16_LO_DS: r = R_PPC64_TPREL16_LO_DS;
2013 break;
2014 case BFD_RELOC_PPC64_TPREL16_HIGHER: r = R_PPC64_TPREL16_HIGHER;
2015 break;
2016 case BFD_RELOC_PPC64_TPREL16_HIGHERA: r = R_PPC64_TPREL16_HIGHERA;
2017 break;
2018 case BFD_RELOC_PPC64_TPREL16_HIGHEST: r = R_PPC64_TPREL16_HIGHEST;
2019 break;
2020 case BFD_RELOC_PPC64_TPREL16_HIGHESTA: r = R_PPC64_TPREL16_HIGHESTA;
2021 break;
2022 case BFD_RELOC_PPC64_DTPREL16_DS: r = R_PPC64_DTPREL16_DS;
2023 break;
2024 case BFD_RELOC_PPC64_DTPREL16_LO_DS: r = R_PPC64_DTPREL16_LO_DS;
2025 break;
2026 case BFD_RELOC_PPC64_DTPREL16_HIGHER: r = R_PPC64_DTPREL16_HIGHER;
2027 break;
2028 case BFD_RELOC_PPC64_DTPREL16_HIGHERA: r = R_PPC64_DTPREL16_HIGHERA;
2029 break;
2030 case BFD_RELOC_PPC64_DTPREL16_HIGHEST: r = R_PPC64_DTPREL16_HIGHEST;
2031 break;
2032 case BFD_RELOC_PPC64_DTPREL16_HIGHESTA: r = R_PPC64_DTPREL16_HIGHESTA;
2033 break;
2034 case BFD_RELOC_VTABLE_INHERIT: r = R_PPC64_GNU_VTINHERIT;
2035 break;
2036 case BFD_RELOC_VTABLE_ENTRY: r = R_PPC64_GNU_VTENTRY;
2037 break;
2038 }
2039
2040 return ppc64_elf_howto_table[(int) r];
2041 };
2042
2043 /* Set the howto pointer for a PowerPC ELF reloc. */
2044
2045 static void
2046 ppc64_elf_info_to_howto (abfd, cache_ptr, dst)
2047 bfd *abfd ATTRIBUTE_UNUSED;
2048 arelent *cache_ptr;
2049 Elf_Internal_Rela *dst;
2050 {
2051 unsigned int type;
2052
2053 /* Initialize howto table if needed. */
2054 if (!ppc64_elf_howto_table[R_PPC64_ADDR32])
2055 ppc_howto_init ();
2056
2057 type = ELF64_R_TYPE (dst->r_info);
2058 BFD_ASSERT (type < (sizeof (ppc64_elf_howto_table)
2059 / sizeof (ppc64_elf_howto_table[0])));
2060 cache_ptr->howto = ppc64_elf_howto_table[type];
2061 }
2062
2063 /* Handle the R_PPC64_ADDR16_HA and similar relocs. */
2064
2065 static bfd_reloc_status_type
2066 ppc64_elf_ha_reloc (abfd, reloc_entry, symbol, data,
2067 input_section, output_bfd, error_message)
2068 bfd *abfd;
2069 arelent *reloc_entry;
2070 asymbol *symbol;
2071 PTR data;
2072 asection *input_section;
2073 bfd *output_bfd;
2074 char **error_message;
2075 {
2076 /* If this is a relocatable link (output_bfd test tells us), just
2077 call the generic function. Any adjustment will be done at final
2078 link time. */
2079 if (output_bfd != NULL)
2080 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
2081 input_section, output_bfd, error_message);
2082
2083 /* Adjust the addend for sign extension of the low 16 bits.
2084 We won't actually be using the low 16 bits, so trashing them
2085 doesn't matter. */
2086 reloc_entry->addend += 0x8000;
2087 return bfd_reloc_continue;
2088 }
2089
2090 static bfd_reloc_status_type
2091 ppc64_elf_brtaken_reloc (abfd, reloc_entry, symbol, data,
2092 input_section, output_bfd, error_message)
2093 bfd *abfd;
2094 arelent *reloc_entry;
2095 asymbol *symbol;
2096 PTR data;
2097 asection *input_section;
2098 bfd *output_bfd;
2099 char **error_message;
2100 {
2101 long insn;
2102 enum elf_ppc64_reloc_type r_type;
2103 bfd_size_type octets;
2104 /* Disabled until we sort out how ld should choose 'y' vs 'at'. */
2105 bfd_boolean is_power4 = FALSE;
2106
2107 /* If this is a relocatable link (output_bfd test tells us), just
2108 call the generic function. Any adjustment will be done at final
2109 link time. */
2110 if (output_bfd != NULL)
2111 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
2112 input_section, output_bfd, error_message);
2113
2114 octets = reloc_entry->address * bfd_octets_per_byte (abfd);
2115 insn = bfd_get_32 (abfd, (bfd_byte *) data + octets);
2116 insn &= ~(0x01 << 21);
2117 r_type = (enum elf_ppc64_reloc_type) reloc_entry->howto->type;
2118 if (r_type == R_PPC64_ADDR14_BRTAKEN
2119 || r_type == R_PPC64_REL14_BRTAKEN)
2120 insn |= 0x01 << 21; /* 'y' or 't' bit, lowest bit of BO field. */
2121
2122 if (is_power4)
2123 {
2124 /* Set 'a' bit. This is 0b00010 in BO field for branch
2125 on CR(BI) insns (BO == 001at or 011at), and 0b01000
2126 for branch on CTR insns (BO == 1a00t or 1a01t). */
2127 if ((insn & (0x14 << 21)) == (0x04 << 21))
2128 insn |= 0x02 << 21;
2129 else if ((insn & (0x14 << 21)) == (0x10 << 21))
2130 insn |= 0x08 << 21;
2131 else
2132 return bfd_reloc_continue;
2133 }
2134 else
2135 {
2136 bfd_vma target = 0;
2137 bfd_vma from;
2138
2139 if (!bfd_is_com_section (symbol->section))
2140 target = symbol->value;
2141 target += symbol->section->output_section->vma;
2142 target += symbol->section->output_offset;
2143 target += reloc_entry->addend;
2144
2145 from = (reloc_entry->address
2146 + input_section->output_offset
2147 + input_section->output_section->vma);
2148
2149 /* Invert 'y' bit if not the default. */
2150 if ((bfd_signed_vma) (target - from) < 0)
2151 insn ^= 0x01 << 21;
2152 }
2153 bfd_put_32 (abfd, (bfd_vma) insn, (bfd_byte *) data + octets);
2154 return bfd_reloc_continue;
2155 }
2156
2157 static bfd_reloc_status_type
2158 ppc64_elf_sectoff_reloc (abfd, reloc_entry, symbol, data,
2159 input_section, output_bfd, error_message)
2160 bfd *abfd;
2161 arelent *reloc_entry;
2162 asymbol *symbol;
2163 PTR data;
2164 asection *input_section;
2165 bfd *output_bfd;
2166 char **error_message;
2167 {
2168 /* If this is a relocatable link (output_bfd test tells us), just
2169 call the generic function. Any adjustment will be done at final
2170 link time. */
2171 if (output_bfd != NULL)
2172 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
2173 input_section, output_bfd, error_message);
2174
2175 /* Subtract the symbol section base address. */
2176 reloc_entry->addend -= symbol->section->output_section->vma;
2177 return bfd_reloc_continue;
2178 }
2179
2180 static bfd_reloc_status_type
2181 ppc64_elf_sectoff_ha_reloc (abfd, reloc_entry, symbol, data,
2182 input_section, output_bfd, error_message)
2183 bfd *abfd;
2184 arelent *reloc_entry;
2185 asymbol *symbol;
2186 PTR data;
2187 asection *input_section;
2188 bfd *output_bfd;
2189 char **error_message;
2190 {
2191 /* If this is a relocatable link (output_bfd test tells us), just
2192 call the generic function. Any adjustment will be done at final
2193 link time. */
2194 if (output_bfd != NULL)
2195 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
2196 input_section, output_bfd, error_message);
2197
2198 /* Subtract the symbol section base address. */
2199 reloc_entry->addend -= symbol->section->output_section->vma;
2200
2201 /* Adjust the addend for sign extension of the low 16 bits. */
2202 reloc_entry->addend += 0x8000;
2203 return bfd_reloc_continue;
2204 }
2205
2206 static bfd_reloc_status_type
2207 ppc64_elf_toc_reloc (abfd, reloc_entry, symbol, data,
2208 input_section, output_bfd, error_message)
2209 bfd *abfd;
2210 arelent *reloc_entry;
2211 asymbol *symbol;
2212 PTR data;
2213 asection *input_section;
2214 bfd *output_bfd;
2215 char **error_message;
2216 {
2217 bfd_vma TOCstart;
2218
2219 /* If this is a relocatable link (output_bfd test tells us), just
2220 call the generic function. Any adjustment will be done at final
2221 link time. */
2222 if (output_bfd != NULL)
2223 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
2224 input_section, output_bfd, error_message);
2225
2226 TOCstart = _bfd_get_gp_value (input_section->output_section->owner);
2227 if (TOCstart == 0)
2228 TOCstart = ppc64_elf_toc (input_section->output_section->owner);
2229
2230 /* Subtract the TOC base address. */
2231 reloc_entry->addend -= TOCstart + TOC_BASE_OFF;
2232 return bfd_reloc_continue;
2233 }
2234
2235 static bfd_reloc_status_type
2236 ppc64_elf_toc_ha_reloc (abfd, reloc_entry, symbol, data,
2237 input_section, output_bfd, error_message)
2238 bfd *abfd;
2239 arelent *reloc_entry;
2240 asymbol *symbol;
2241 PTR data;
2242 asection *input_section;
2243 bfd *output_bfd;
2244 char **error_message;
2245 {
2246 bfd_vma TOCstart;
2247
2248 /* If this is a relocatable link (output_bfd test tells us), just
2249 call the generic function. Any adjustment will be done at final
2250 link time. */
2251 if (output_bfd != NULL)
2252 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
2253 input_section, output_bfd, error_message);
2254
2255 TOCstart = _bfd_get_gp_value (input_section->output_section->owner);
2256 if (TOCstart == 0)
2257 TOCstart = ppc64_elf_toc (input_section->output_section->owner);
2258
2259 /* Subtract the TOC base address. */
2260 reloc_entry->addend -= TOCstart + TOC_BASE_OFF;
2261
2262 /* Adjust the addend for sign extension of the low 16 bits. */
2263 reloc_entry->addend += 0x8000;
2264 return bfd_reloc_continue;
2265 }
2266
2267 static bfd_reloc_status_type
2268 ppc64_elf_toc64_reloc (abfd, reloc_entry, symbol, data,
2269 input_section, output_bfd, error_message)
2270 bfd *abfd;
2271 arelent *reloc_entry;
2272 asymbol *symbol;
2273 PTR data;
2274 asection *input_section;
2275 bfd *output_bfd;
2276 char **error_message;
2277 {
2278 bfd_vma TOCstart;
2279 bfd_size_type octets;
2280
2281 /* If this is a relocatable link (output_bfd test tells us), just
2282 call the generic function. Any adjustment will be done at final
2283 link time. */
2284 if (output_bfd != NULL)
2285 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
2286 input_section, output_bfd, error_message);
2287
2288 TOCstart = _bfd_get_gp_value (input_section->output_section->owner);
2289 if (TOCstart == 0)
2290 TOCstart = ppc64_elf_toc (input_section->output_section->owner);
2291
2292 octets = reloc_entry->address * bfd_octets_per_byte (abfd);
2293 bfd_put_64 (abfd, TOCstart + TOC_BASE_OFF, (bfd_byte *) data + octets);
2294 return bfd_reloc_ok;
2295 }
2296
2297 static bfd_reloc_status_type
2298 ppc64_elf_unhandled_reloc (abfd, reloc_entry, symbol, data,
2299 input_section, output_bfd, error_message)
2300 bfd *abfd;
2301 arelent *reloc_entry;
2302 asymbol *symbol;
2303 PTR data;
2304 asection *input_section;
2305 bfd *output_bfd;
2306 char **error_message;
2307 {
2308 /* If this is a relocatable link (output_bfd test tells us), just
2309 call the generic function. Any adjustment will be done at final
2310 link time. */
2311 if (output_bfd != NULL)
2312 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
2313 input_section, output_bfd, error_message);
2314
2315 if (error_message != NULL)
2316 {
2317 static char buf[60];
2318 sprintf (buf, "generic linker can't handle %s",
2319 reloc_entry->howto->name);
2320 *error_message = buf;
2321 }
2322 return bfd_reloc_dangerous;
2323 }
2324
2325 /* Fix bad default arch selected for a 64 bit input bfd when the
2326 default is 32 bit. */
2327
2328 static bfd_boolean
2329 ppc64_elf_object_p (abfd)
2330 bfd *abfd;
2331 {
2332 if (abfd->arch_info->the_default && abfd->arch_info->bits_per_word == 32)
2333 {
2334 Elf_Internal_Ehdr *i_ehdr = elf_elfheader (abfd);
2335
2336 if (i_ehdr->e_ident[EI_CLASS] == ELFCLASS64)
2337 {
2338 /* Relies on arch after 32 bit default being 64 bit default. */
2339 abfd->arch_info = abfd->arch_info->next;
2340 BFD_ASSERT (abfd->arch_info->bits_per_word == 64);
2341 }
2342 }
2343 return TRUE;
2344 }
2345
2346 /* Merge backend specific data from an object file to the output
2347 object file when linking. */
2348
2349 static bfd_boolean
2350 ppc64_elf_merge_private_bfd_data (ibfd, obfd)
2351 bfd *ibfd;
2352 bfd *obfd;
2353 {
2354 /* Check if we have the same endianess. */
2355 if (ibfd->xvec->byteorder != obfd->xvec->byteorder
2356 && ibfd->xvec->byteorder != BFD_ENDIAN_UNKNOWN
2357 && obfd->xvec->byteorder != BFD_ENDIAN_UNKNOWN)
2358 {
2359 const char *msg;
2360
2361 if (bfd_big_endian (ibfd))
2362 msg = _("%s: compiled for a big endian system and target is little endian");
2363 else
2364 msg = _("%s: compiled for a little endian system and target is big endian");
2365
2366 (*_bfd_error_handler) (msg, bfd_archive_filename (ibfd));
2367
2368 bfd_set_error (bfd_error_wrong_format);
2369 return FALSE;
2370 }
2371
2372 return TRUE;
2373 }
2374
2375 struct _ppc64_elf_section_data
2376 {
2377 struct bfd_elf_section_data elf;
2378
2379 /* An array with one entry for each opd function descriptor. */
2380 union
2381 {
2382 /* Points to the function code section for local opd entries. */
2383 asection **func_sec;
2384 /* After editing .opd, adjust references to opd local syms. */
2385 long *adjust;
2386 } opd;
2387
2388 /* An array for toc sections, indexed by offset/8.
2389 Specifies the relocation symbol index used at a given toc offset. */
2390 unsigned *t_symndx;
2391 };
2392
2393 #define ppc64_elf_section_data(sec) \
2394 ((struct _ppc64_elf_section_data *) elf_section_data (sec))
2395
2396 static bfd_boolean
2397 ppc64_elf_new_section_hook (abfd, sec)
2398 bfd *abfd;
2399 asection *sec;
2400 {
2401 struct _ppc64_elf_section_data *sdata;
2402 bfd_size_type amt = sizeof (*sdata);
2403
2404 sdata = (struct _ppc64_elf_section_data *) bfd_zalloc (abfd, amt);
2405 if (sdata == NULL)
2406 return FALSE;
2407 sec->used_by_bfd = (PTR) sdata;
2408
2409 return _bfd_elf_new_section_hook (abfd, sec);
2410 }
2411 \f
2412 /* The following functions are specific to the ELF linker, while
2413 functions above are used generally. Those named ppc64_elf_* are
2414 called by the main ELF linker code. They appear in this file more
2415 or less in the order in which they are called. eg.
2416 ppc64_elf_check_relocs is called early in the link process,
2417 ppc64_elf_finish_dynamic_sections is one of the last functions
2418 called.
2419
2420 PowerPC64-ELF uses a similar scheme to PowerPC64-XCOFF in that
2421 functions have both a function code symbol and a function descriptor
2422 symbol. A call to foo in a relocatable object file looks like:
2423
2424 . .text
2425 . x:
2426 . bl .foo
2427 . nop
2428
2429 The function definition in another object file might be:
2430
2431 . .section .opd
2432 . foo: .quad .foo
2433 . .quad .TOC.@tocbase
2434 . .quad 0
2435 .
2436 . .text
2437 . .foo: blr
2438
2439 When the linker resolves the call during a static link, the branch
2440 unsurprisingly just goes to .foo and the .opd information is unused.
2441 If the function definition is in a shared library, things are a little
2442 different: The call goes via a plt call stub, the opd information gets
2443 copied to the plt, and the linker patches the nop.
2444
2445 . x:
2446 . bl .foo_stub
2447 . ld 2,40(1)
2448 .
2449 .
2450 . .foo_stub:
2451 . addis 12,2,Lfoo@toc@ha # in practice, the call stub
2452 . addi 12,12,Lfoo@toc@l # is slightly optimized, but
2453 . std 2,40(1) # this is the general idea
2454 . ld 11,0(12)
2455 . ld 2,8(12)
2456 . mtctr 11
2457 . ld 11,16(12)
2458 . bctr
2459 .
2460 . .section .plt
2461 . Lfoo: reloc (R_PPC64_JMP_SLOT, foo)
2462
2463 The "reloc ()" notation is supposed to indicate that the linker emits
2464 an R_PPC64_JMP_SLOT reloc against foo. The dynamic linker does the opd
2465 copying.
2466
2467 What are the difficulties here? Well, firstly, the relocations
2468 examined by the linker in check_relocs are against the function code
2469 sym .foo, while the dynamic relocation in the plt is emitted against
2470 the function descriptor symbol, foo. Somewhere along the line, we need
2471 to carefully copy dynamic link information from one symbol to the other.
2472 Secondly, the generic part of the elf linker will make .foo a dynamic
2473 symbol as is normal for most other backends. We need foo dynamic
2474 instead, at least for an application final link. However, when
2475 creating a shared library containing foo, we need to have both symbols
2476 dynamic so that references to .foo are satisfied during the early
2477 stages of linking. Otherwise the linker might decide to pull in a
2478 definition from some other object, eg. a static library. */
2479
2480 /* The linker needs to keep track of the number of relocs that it
2481 decides to copy as dynamic relocs in check_relocs for each symbol.
2482 This is so that it can later discard them if they are found to be
2483 unnecessary. We store the information in a field extending the
2484 regular ELF linker hash table. */
2485
2486 struct ppc_dyn_relocs
2487 {
2488 struct ppc_dyn_relocs *next;
2489
2490 /* The input section of the reloc. */
2491 asection *sec;
2492
2493 /* Total number of relocs copied for the input section. */
2494 bfd_size_type count;
2495
2496 /* Number of pc-relative relocs copied for the input section. */
2497 bfd_size_type pc_count;
2498 };
2499
2500 /* Track GOT entries needed for a given symbol. We might need more
2501 than one got entry per symbol. */
2502 struct got_entry
2503 {
2504 struct got_entry *next;
2505
2506 /* The symbol addend that we'll be placing in the GOT. */
2507 bfd_vma addend;
2508
2509 /* Reference count until size_dynamic_sections, GOT offset thereafter. */
2510 union
2511 {
2512 bfd_signed_vma refcount;
2513 bfd_vma offset;
2514 } got;
2515
2516 /* Zero for non-tls entries, or TLS_TLS and one of TLS_GD, TLS_LD,
2517 TLS_TPREL or TLS_DTPREL for tls entries. */
2518 char tls_type;
2519 };
2520
2521 /* The same for PLT. */
2522 struct plt_entry
2523 {
2524 struct plt_entry *next;
2525
2526 bfd_vma addend;
2527
2528 union
2529 {
2530 bfd_signed_vma refcount;
2531 bfd_vma offset;
2532 } plt;
2533 };
2534
2535 /* Of those relocs that might be copied as dynamic relocs, this macro
2536 selects those that must be copied when linking a shared library,
2537 even when the symbol is local. */
2538
2539 #define MUST_BE_DYN_RELOC(RTYPE) \
2540 ((RTYPE) != R_PPC64_REL32 \
2541 && (RTYPE) != R_PPC64_REL64 \
2542 && (RTYPE) != R_PPC64_REL30)
2543
2544 /* Section name for stubs is the associated section name plus this
2545 string. */
2546 #define STUB_SUFFIX ".stub"
2547
2548 /* Linker stubs.
2549 ppc_stub_long_branch:
2550 Used when a 14 bit branch (or even a 24 bit branch) can't reach its
2551 destination, but a 24 bit branch in a stub section will reach.
2552 . b dest
2553
2554 ppc_stub_plt_branch:
2555 Similar to the above, but a 24 bit branch in the stub section won't
2556 reach its destination.
2557 . addis %r12,%r2,xxx@toc@ha
2558 . ld %r11,xxx@toc@l(%r12)
2559 . mtctr %r11
2560 . bctr
2561
2562 ppc_stub_plt_call:
2563 Used to call a function in a shared library.
2564 . addis %r12,%r2,xxx@toc@ha
2565 . std %r2,40(%r1)
2566 . ld %r11,xxx+0@toc@l(%r12)
2567 . ld %r2,xxx+8@toc@l(%r12)
2568 . mtctr %r11
2569 . ld %r11,xxx+16@toc@l(%r12)
2570 . bctr
2571 */
2572
2573 enum ppc_stub_type {
2574 ppc_stub_none,
2575 ppc_stub_long_branch,
2576 ppc_stub_plt_branch,
2577 ppc_stub_plt_call
2578 };
2579
2580 struct ppc_stub_hash_entry {
2581
2582 /* Base hash table entry structure. */
2583 struct bfd_hash_entry root;
2584
2585 /* The stub section. */
2586 asection *stub_sec;
2587
2588 /* Offset within stub_sec of the beginning of this stub. */
2589 bfd_vma stub_offset;
2590
2591 /* Given the symbol's value and its section we can determine its final
2592 value when building the stubs (so the stub knows where to jump. */
2593 bfd_vma target_value;
2594 asection *target_section;
2595
2596 enum ppc_stub_type stub_type;
2597
2598 /* The symbol table entry, if any, that this was derived from. */
2599 struct ppc_link_hash_entry *h;
2600
2601 /* And the reloc addend that this was derived from. */
2602 bfd_vma addend;
2603
2604 /* Where this stub is being called from, or, in the case of combined
2605 stub sections, the first input section in the group. */
2606 asection *id_sec;
2607 };
2608
2609 struct ppc_branch_hash_entry {
2610
2611 /* Base hash table entry structure. */
2612 struct bfd_hash_entry root;
2613
2614 /* Offset within .branch_lt. */
2615 unsigned int offset;
2616
2617 /* Generation marker. */
2618 unsigned int iter;
2619 };
2620
2621 struct ppc_link_hash_entry
2622 {
2623 struct elf_link_hash_entry elf;
2624
2625 /* A pointer to the most recently used stub hash entry against this
2626 symbol. */
2627 struct ppc_stub_hash_entry *stub_cache;
2628
2629 /* Track dynamic relocs copied for this symbol. */
2630 struct ppc_dyn_relocs *dyn_relocs;
2631
2632 /* Link between function code and descriptor symbols. */
2633 struct elf_link_hash_entry *oh;
2634
2635 /* Flag function code and descriptor symbols. */
2636 unsigned int is_func:1;
2637 unsigned int is_func_descriptor:1;
2638 unsigned int is_entry:1;
2639
2640 /* Contexts in which symbol is used in the GOT (or TOC).
2641 TLS_GD .. TLS_EXPLICIT bits are or'd into the mask as the
2642 corresponding relocs are encountered during check_relocs.
2643 tls_optimize clears TLS_GD .. TLS_TPREL when optimizing to
2644 indicate the corresponding GOT entry type is not needed.
2645 tls_optimize may also set TLS_TPRELGD when a GD reloc turns into
2646 a TPREL one. We use a separate flag rather than setting TPREL
2647 just for convenience in distinguishing the two cases. */
2648 #define TLS_GD 1 /* GD reloc. */
2649 #define TLS_LD 2 /* LD reloc. */
2650 #define TLS_TPREL 4 /* TPREL reloc, => IE. */
2651 #define TLS_DTPREL 8 /* DTPREL reloc, => LD. */
2652 #define TLS_TLS 16 /* Any TLS reloc. */
2653 #define TLS_EXPLICIT 32 /* Marks TOC section TLS relocs. */
2654 #define TLS_TPRELGD 64 /* TPREL reloc resulting from GD->IE. */
2655 char tls_mask;
2656 };
2657
2658 /* ppc64 ELF linker hash table. */
2659
2660 struct ppc_link_hash_table
2661 {
2662 struct elf_link_hash_table elf;
2663
2664 /* The stub hash table. */
2665 struct bfd_hash_table stub_hash_table;
2666
2667 /* Another hash table for plt_branch stubs. */
2668 struct bfd_hash_table branch_hash_table;
2669
2670 /* Linker stub bfd. */
2671 bfd *stub_bfd;
2672
2673 /* Linker call-backs. */
2674 asection * (*add_stub_section) PARAMS ((const char *, asection *));
2675 void (*layout_sections_again) PARAMS ((void));
2676
2677 /* Array to keep track of which stub sections have been created, and
2678 information on stub grouping. */
2679 struct map_stub {
2680 /* This is the section to which stubs in the group will be attached. */
2681 asection *link_sec;
2682 /* The stub section. */
2683 asection *stub_sec;
2684 } *stub_group;
2685
2686 /* Assorted information used by ppc64_elf_size_stubs. */
2687 int top_index;
2688 asection **input_list;
2689
2690 /* Short-cuts to get to dynamic linker sections. */
2691 asection *sgot;
2692 asection *srelgot;
2693 asection *splt;
2694 asection *srelplt;
2695 asection *sdynbss;
2696 asection *srelbss;
2697 asection *sglink;
2698 asection *sfpr;
2699 asection *sbrlt;
2700 asection *srelbrlt;
2701
2702 /* Short-cut to first output tls section. */
2703 asection *tls_sec;
2704
2705 /* Shortcut to .__tls_get_addr. */
2706 struct elf_link_hash_entry *tls_get_addr;
2707
2708 /* TLS local dynamic got entry handling. */
2709 union {
2710 bfd_signed_vma refcount;
2711 bfd_vma offset;
2712 } tlsld_got;
2713
2714 /* Set on error. */
2715 unsigned int stub_error;
2716
2717 /* Flag set when small branches are detected. Used to
2718 select suitable defaults for the stub group size. */
2719 unsigned int has_14bit_branch;
2720
2721 /* Set if we detect a reference undefined weak symbol. */
2722 unsigned int have_undefweak;
2723
2724 /* Incremented every time we size stubs. */
2725 unsigned int stub_iteration;
2726
2727 /* Small local sym to section mapping cache. */
2728 struct sym_sec_cache sym_sec;
2729 };
2730
2731 static struct bfd_hash_entry *stub_hash_newfunc
2732 PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *));
2733 static struct bfd_hash_entry *branch_hash_newfunc
2734 PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *));
2735 static struct bfd_hash_entry *link_hash_newfunc
2736 PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *));
2737 static struct bfd_link_hash_table *ppc64_elf_link_hash_table_create
2738 PARAMS ((bfd *));
2739 static void ppc64_elf_link_hash_table_free
2740 PARAMS ((struct bfd_link_hash_table *));
2741 static char *ppc_stub_name
2742 PARAMS ((const asection *, const asection *,
2743 const struct ppc_link_hash_entry *, const Elf_Internal_Rela *));
2744 static struct ppc_stub_hash_entry *ppc_get_stub_entry
2745 PARAMS ((const asection *, const asection *, struct elf_link_hash_entry *,
2746 const Elf_Internal_Rela *, struct ppc_link_hash_table *));
2747 static struct ppc_stub_hash_entry *ppc_add_stub
2748 PARAMS ((const char *, asection *, struct ppc_link_hash_table *));
2749 static bfd_boolean create_linkage_sections
2750 PARAMS ((bfd *, struct bfd_link_info *));
2751 static bfd_boolean create_got_section
2752 PARAMS ((bfd *, struct bfd_link_info *));
2753 static bfd_boolean ppc64_elf_create_dynamic_sections
2754 PARAMS ((bfd *, struct bfd_link_info *));
2755 static void ppc64_elf_copy_indirect_symbol
2756 PARAMS ((struct elf_backend_data *, struct elf_link_hash_entry *,
2757 struct elf_link_hash_entry *));
2758 static bfd_boolean update_local_sym_info
2759 PARAMS ((bfd *, Elf_Internal_Shdr *, unsigned long, bfd_vma, int));
2760 static bfd_boolean update_plt_info
2761 PARAMS ((bfd *, struct ppc_link_hash_entry *, bfd_vma));
2762 static bfd_boolean ppc64_elf_check_relocs
2763 PARAMS ((bfd *, struct bfd_link_info *, asection *,
2764 const Elf_Internal_Rela *));
2765 static asection * ppc64_elf_gc_mark_hook
2766 PARAMS ((asection *, struct bfd_link_info *, Elf_Internal_Rela *,
2767 struct elf_link_hash_entry *, Elf_Internal_Sym *));
2768 static bfd_boolean ppc64_elf_gc_sweep_hook
2769 PARAMS ((bfd *, struct bfd_link_info *, asection *,
2770 const Elf_Internal_Rela *));
2771 static bfd_boolean func_desc_adjust
2772 PARAMS ((struct elf_link_hash_entry *, PTR));
2773 static bfd_boolean ppc64_elf_func_desc_adjust
2774 PARAMS ((bfd *, struct bfd_link_info *));
2775 static bfd_boolean ppc64_elf_adjust_dynamic_symbol
2776 PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *));
2777 static void ppc64_elf_hide_symbol
2778 PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *, bfd_boolean));
2779 static bfd_boolean get_sym_h
2780 PARAMS ((struct elf_link_hash_entry **, Elf_Internal_Sym **, asection **,
2781 char **, Elf_Internal_Sym **, unsigned long, bfd *));
2782 static int get_tls_mask
2783 PARAMS ((char **, Elf_Internal_Sym **, const Elf_Internal_Rela *, bfd *));
2784 static bfd_boolean allocate_dynrelocs
2785 PARAMS ((struct elf_link_hash_entry *, PTR));
2786 static bfd_boolean readonly_dynrelocs
2787 PARAMS ((struct elf_link_hash_entry *, PTR));
2788 static enum elf_reloc_type_class ppc64_elf_reloc_type_class
2789 PARAMS ((const Elf_Internal_Rela *));
2790 static bfd_boolean ppc64_elf_size_dynamic_sections
2791 PARAMS ((bfd *, struct bfd_link_info *));
2792 static enum ppc_stub_type ppc_type_of_stub
2793 PARAMS ((asection *, const Elf_Internal_Rela *,
2794 struct ppc_link_hash_entry **, bfd_vma));
2795 static bfd_byte *build_plt_stub
2796 PARAMS ((bfd *, bfd_byte *, int, int));
2797 static bfd_boolean ppc_build_one_stub
2798 PARAMS ((struct bfd_hash_entry *, PTR));
2799 static bfd_boolean ppc_size_one_stub
2800 PARAMS ((struct bfd_hash_entry *, PTR));
2801 static void group_sections
2802 PARAMS ((struct ppc_link_hash_table *, bfd_size_type, bfd_boolean));
2803 static bfd_boolean ppc64_elf_relocate_section
2804 PARAMS ((bfd *, struct bfd_link_info *info, bfd *, asection *, bfd_byte *,
2805 Elf_Internal_Rela *relocs, Elf_Internal_Sym *local_syms,
2806 asection **));
2807 static bfd_boolean ppc64_elf_finish_dynamic_symbol
2808 PARAMS ((bfd *, struct bfd_link_info *, struct elf_link_hash_entry *,
2809 Elf_Internal_Sym *));
2810 static bfd_boolean ppc64_elf_finish_dynamic_sections
2811 PARAMS ((bfd *, struct bfd_link_info *));
2812
2813 /* Get the ppc64 ELF linker hash table from a link_info structure. */
2814
2815 #define ppc_hash_table(p) \
2816 ((struct ppc_link_hash_table *) ((p)->hash))
2817
2818 #define ppc_stub_hash_lookup(table, string, create, copy) \
2819 ((struct ppc_stub_hash_entry *) \
2820 bfd_hash_lookup ((table), (string), (create), (copy)))
2821
2822 #define ppc_branch_hash_lookup(table, string, create, copy) \
2823 ((struct ppc_branch_hash_entry *) \
2824 bfd_hash_lookup ((table), (string), (create), (copy)))
2825
2826 /* Create an entry in the stub hash table. */
2827
2828 static struct bfd_hash_entry *
2829 stub_hash_newfunc (entry, table, string)
2830 struct bfd_hash_entry *entry;
2831 struct bfd_hash_table *table;
2832 const char *string;
2833 {
2834 /* Allocate the structure if it has not already been allocated by a
2835 subclass. */
2836 if (entry == NULL)
2837 {
2838 entry = bfd_hash_allocate (table, sizeof (struct ppc_stub_hash_entry));
2839 if (entry == NULL)
2840 return entry;
2841 }
2842
2843 /* Call the allocation method of the superclass. */
2844 entry = bfd_hash_newfunc (entry, table, string);
2845 if (entry != NULL)
2846 {
2847 struct ppc_stub_hash_entry *eh;
2848
2849 /* Initialize the local fields. */
2850 eh = (struct ppc_stub_hash_entry *) entry;
2851 eh->stub_sec = NULL;
2852 eh->stub_offset = 0;
2853 eh->target_value = 0;
2854 eh->target_section = NULL;
2855 eh->stub_type = ppc_stub_none;
2856 eh->h = NULL;
2857 eh->id_sec = NULL;
2858 }
2859
2860 return entry;
2861 }
2862
2863 /* Create an entry in the branch hash table. */
2864
2865 static struct bfd_hash_entry *
2866 branch_hash_newfunc (entry, table, string)
2867 struct bfd_hash_entry *entry;
2868 struct bfd_hash_table *table;
2869 const char *string;
2870 {
2871 /* Allocate the structure if it has not already been allocated by a
2872 subclass. */
2873 if (entry == NULL)
2874 {
2875 entry = bfd_hash_allocate (table, sizeof (struct ppc_branch_hash_entry));
2876 if (entry == NULL)
2877 return entry;
2878 }
2879
2880 /* Call the allocation method of the superclass. */
2881 entry = bfd_hash_newfunc (entry, table, string);
2882 if (entry != NULL)
2883 {
2884 struct ppc_branch_hash_entry *eh;
2885
2886 /* Initialize the local fields. */
2887 eh = (struct ppc_branch_hash_entry *) entry;
2888 eh->offset = 0;
2889 eh->iter = 0;
2890 }
2891
2892 return entry;
2893 }
2894
2895 /* Create an entry in a ppc64 ELF linker hash table. */
2896
2897 static struct bfd_hash_entry *
2898 link_hash_newfunc (entry, table, string)
2899 struct bfd_hash_entry *entry;
2900 struct bfd_hash_table *table;
2901 const char *string;
2902 {
2903 /* Allocate the structure if it has not already been allocated by a
2904 subclass. */
2905 if (entry == NULL)
2906 {
2907 entry = bfd_hash_allocate (table, sizeof (struct ppc_link_hash_entry));
2908 if (entry == NULL)
2909 return entry;
2910 }
2911
2912 /* Call the allocation method of the superclass. */
2913 entry = _bfd_elf_link_hash_newfunc (entry, table, string);
2914 if (entry != NULL)
2915 {
2916 struct ppc_link_hash_entry *eh = (struct ppc_link_hash_entry *) entry;
2917
2918 eh->stub_cache = NULL;
2919 eh->dyn_relocs = NULL;
2920 eh->oh = NULL;
2921 eh->is_func = 0;
2922 eh->is_func_descriptor = 0;
2923 eh->is_entry = 0;
2924 eh->tls_mask = 0;
2925 }
2926
2927 return entry;
2928 }
2929
2930 /* Create a ppc64 ELF linker hash table. */
2931
2932 static struct bfd_link_hash_table *
2933 ppc64_elf_link_hash_table_create (abfd)
2934 bfd *abfd;
2935 {
2936 struct ppc_link_hash_table *htab;
2937 bfd_size_type amt = sizeof (struct ppc_link_hash_table);
2938
2939 htab = (struct ppc_link_hash_table *) bfd_malloc (amt);
2940 if (htab == NULL)
2941 return NULL;
2942
2943 if (! _bfd_elf_link_hash_table_init (&htab->elf, abfd, link_hash_newfunc))
2944 {
2945 free (htab);
2946 return NULL;
2947 }
2948
2949 /* Init the stub hash table too. */
2950 if (!bfd_hash_table_init (&htab->stub_hash_table, stub_hash_newfunc))
2951 return NULL;
2952
2953 /* And the branch hash table. */
2954 if (!bfd_hash_table_init (&htab->branch_hash_table, branch_hash_newfunc))
2955 return NULL;
2956
2957 htab->stub_bfd = NULL;
2958 htab->add_stub_section = NULL;
2959 htab->layout_sections_again = NULL;
2960 htab->stub_group = NULL;
2961 htab->sgot = NULL;
2962 htab->srelgot = NULL;
2963 htab->splt = NULL;
2964 htab->srelplt = NULL;
2965 htab->sdynbss = NULL;
2966 htab->srelbss = NULL;
2967 htab->sglink = NULL;
2968 htab->sfpr = NULL;
2969 htab->sbrlt = NULL;
2970 htab->srelbrlt = NULL;
2971 htab->tls_sec = NULL;
2972 htab->tls_get_addr = NULL;
2973 htab->tlsld_got.refcount = 0;
2974 htab->stub_error = 0;
2975 htab->has_14bit_branch = 0;
2976 htab->have_undefweak = 0;
2977 htab->stub_iteration = 0;
2978 htab->sym_sec.abfd = NULL;
2979 /* Initializing two fields of the union is just cosmetic. We really
2980 only care about glist, but when compiled on a 32-bit host the
2981 bfd_vma fields are larger. Setting the bfd_vma to zero makes
2982 debugger inspection of these fields look nicer. */
2983 htab->elf.init_refcount.refcount = 0;
2984 htab->elf.init_refcount.glist = NULL;
2985 htab->elf.init_offset.offset = 0;
2986 htab->elf.init_offset.glist = NULL;
2987
2988 return &htab->elf.root;
2989 }
2990
2991 /* Free the derived linker hash table. */
2992
2993 static void
2994 ppc64_elf_link_hash_table_free (hash)
2995 struct bfd_link_hash_table *hash;
2996 {
2997 struct ppc_link_hash_table *ret = (struct ppc_link_hash_table *) hash;
2998
2999 bfd_hash_table_free (&ret->stub_hash_table);
3000 bfd_hash_table_free (&ret->branch_hash_table);
3001 _bfd_generic_link_hash_table_free (hash);
3002 }
3003
3004 /* Build a name for an entry in the stub hash table. */
3005
3006 static char *
3007 ppc_stub_name (input_section, sym_sec, h, rel)
3008 const asection *input_section;
3009 const asection *sym_sec;
3010 const struct ppc_link_hash_entry *h;
3011 const Elf_Internal_Rela *rel;
3012 {
3013 char *stub_name;
3014 bfd_size_type len;
3015
3016 /* rel->r_addend is actually 64 bit, but who uses more than +/- 2^31
3017 offsets from a sym as a branch target? In fact, we could
3018 probably assume the addend is always zero. */
3019 BFD_ASSERT (((int) rel->r_addend & 0xffffffff) == rel->r_addend);
3020
3021 if (h)
3022 {
3023 len = 8 + 1 + strlen (h->elf.root.root.string) + 1 + 8 + 1;
3024 stub_name = bfd_malloc (len);
3025 if (stub_name != NULL)
3026 {
3027 sprintf (stub_name, "%08x_%s+%x",
3028 input_section->id & 0xffffffff,
3029 h->elf.root.root.string,
3030 (int) rel->r_addend & 0xffffffff);
3031 }
3032 }
3033 else
3034 {
3035 len = 8 + 1 + 8 + 1 + 8 + 1 + 16 + 1;
3036 stub_name = bfd_malloc (len);
3037 if (stub_name != NULL)
3038 {
3039 sprintf (stub_name, "%08x_%x:%x+%x",
3040 input_section->id & 0xffffffff,
3041 sym_sec->id & 0xffffffff,
3042 (int) ELF64_R_SYM (rel->r_info) & 0xffffffff,
3043 (int) rel->r_addend & 0xffffffff);
3044 }
3045 }
3046 return stub_name;
3047 }
3048
3049 /* Look up an entry in the stub hash. Stub entries are cached because
3050 creating the stub name takes a bit of time. */
3051
3052 static struct ppc_stub_hash_entry *
3053 ppc_get_stub_entry (input_section, sym_sec, hash, rel, htab)
3054 const asection *input_section;
3055 const asection *sym_sec;
3056 struct elf_link_hash_entry *hash;
3057 const Elf_Internal_Rela *rel;
3058 struct ppc_link_hash_table *htab;
3059 {
3060 struct ppc_stub_hash_entry *stub_entry;
3061 struct ppc_link_hash_entry *h = (struct ppc_link_hash_entry *) hash;
3062 const asection *id_sec;
3063
3064 /* If this input section is part of a group of sections sharing one
3065 stub section, then use the id of the first section in the group.
3066 Stub names need to include a section id, as there may well be
3067 more than one stub used to reach say, printf, and we need to
3068 distinguish between them. */
3069 id_sec = htab->stub_group[input_section->id].link_sec;
3070
3071 if (h != NULL && h->stub_cache != NULL
3072 && h->stub_cache->h == h
3073 && h->stub_cache->id_sec == id_sec)
3074 {
3075 stub_entry = h->stub_cache;
3076 }
3077 else
3078 {
3079 char *stub_name;
3080
3081 stub_name = ppc_stub_name (id_sec, sym_sec, h, rel);
3082 if (stub_name == NULL)
3083 return NULL;
3084
3085 stub_entry = ppc_stub_hash_lookup (&htab->stub_hash_table,
3086 stub_name, FALSE, FALSE);
3087 if (h != NULL)
3088 h->stub_cache = stub_entry;
3089
3090 free (stub_name);
3091 }
3092
3093 return stub_entry;
3094 }
3095
3096 /* Add a new stub entry to the stub hash. Not all fields of the new
3097 stub entry are initialised. */
3098
3099 static struct ppc_stub_hash_entry *
3100 ppc_add_stub (stub_name, section, htab)
3101 const char *stub_name;
3102 asection *section;
3103 struct ppc_link_hash_table *htab;
3104 {
3105 asection *link_sec;
3106 asection *stub_sec;
3107 struct ppc_stub_hash_entry *stub_entry;
3108
3109 link_sec = htab->stub_group[section->id].link_sec;
3110 stub_sec = htab->stub_group[section->id].stub_sec;
3111 if (stub_sec == NULL)
3112 {
3113 stub_sec = htab->stub_group[link_sec->id].stub_sec;
3114 if (stub_sec == NULL)
3115 {
3116 size_t namelen;
3117 bfd_size_type len;
3118 char *s_name;
3119
3120 namelen = strlen (link_sec->name);
3121 len = namelen + sizeof (STUB_SUFFIX);
3122 s_name = bfd_alloc (htab->stub_bfd, len);
3123 if (s_name == NULL)
3124 return NULL;
3125
3126 memcpy (s_name, link_sec->name, namelen);
3127 memcpy (s_name + namelen, STUB_SUFFIX, sizeof (STUB_SUFFIX));
3128 stub_sec = (*htab->add_stub_section) (s_name, link_sec);
3129 if (stub_sec == NULL)
3130 return NULL;
3131 htab->stub_group[link_sec->id].stub_sec = stub_sec;
3132 }
3133 htab->stub_group[section->id].stub_sec = stub_sec;
3134 }
3135
3136 /* Enter this entry into the linker stub hash table. */
3137 stub_entry = ppc_stub_hash_lookup (&htab->stub_hash_table, stub_name,
3138 TRUE, FALSE);
3139 if (stub_entry == NULL)
3140 {
3141 (*_bfd_error_handler) (_("%s: cannot create stub entry %s"),
3142 bfd_archive_filename (section->owner),
3143 stub_name);
3144 return NULL;
3145 }
3146
3147 stub_entry->stub_sec = stub_sec;
3148 stub_entry->stub_offset = 0;
3149 stub_entry->id_sec = link_sec;
3150 return stub_entry;
3151 }
3152
3153 /* Create sections for linker generated code. */
3154
3155 static bfd_boolean
3156 create_linkage_sections (dynobj, info)
3157 bfd *dynobj;
3158 struct bfd_link_info *info;
3159 {
3160 struct ppc_link_hash_table *htab;
3161 flagword flags;
3162
3163 htab = ppc_hash_table (info);
3164
3165 /* Create .sfpr for code to save and restore fp regs. */
3166 flags = (SEC_ALLOC | SEC_LOAD | SEC_CODE | SEC_READONLY
3167 | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED);
3168 htab->sfpr = bfd_make_section_anyway (dynobj, ".sfpr");
3169 if (htab->sfpr == NULL
3170 || ! bfd_set_section_flags (dynobj, htab->sfpr, flags)
3171 || ! bfd_set_section_alignment (dynobj, htab->sfpr, 2))
3172 return FALSE;
3173
3174 /* Create .glink for lazy dynamic linking support. */
3175 htab->sglink = bfd_make_section_anyway (dynobj, ".glink");
3176 if (htab->sglink == NULL
3177 || ! bfd_set_section_flags (dynobj, htab->sglink, flags)
3178 || ! bfd_set_section_alignment (dynobj, htab->sglink, 2))
3179 return FALSE;
3180
3181 /* Create .branch_lt for plt_branch stubs. */
3182 flags = (SEC_ALLOC | SEC_LOAD
3183 | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED);
3184 htab->sbrlt = bfd_make_section_anyway (dynobj, ".branch_lt");
3185 if (htab->sbrlt == NULL
3186 || ! bfd_set_section_flags (dynobj, htab->sbrlt, flags)
3187 || ! bfd_set_section_alignment (dynobj, htab->sbrlt, 3))
3188 return FALSE;
3189
3190 if (info->shared)
3191 {
3192 flags = (SEC_ALLOC | SEC_LOAD | SEC_READONLY
3193 | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED);
3194 htab->srelbrlt = bfd_make_section_anyway (dynobj, ".rela.branch_lt");
3195 if (!htab->srelbrlt
3196 || ! bfd_set_section_flags (dynobj, htab->srelbrlt, flags)
3197 || ! bfd_set_section_alignment (dynobj, htab->srelbrlt, 3))
3198 return FALSE;
3199 }
3200 return TRUE;
3201 }
3202
3203 /* Create .got and .rela.got sections in DYNOBJ, and set up
3204 shortcuts to them in our hash table. */
3205
3206 static bfd_boolean
3207 create_got_section (dynobj, info)
3208 bfd *dynobj;
3209 struct bfd_link_info *info;
3210 {
3211 struct ppc_link_hash_table *htab;
3212
3213 if (! _bfd_elf_create_got_section (dynobj, info))
3214 return FALSE;
3215
3216 htab = ppc_hash_table (info);
3217 htab->sgot = bfd_get_section_by_name (dynobj, ".got");
3218 if (!htab->sgot)
3219 abort ();
3220
3221 htab->srelgot = bfd_make_section (dynobj, ".rela.got");
3222 if (!htab->srelgot
3223 || ! bfd_set_section_flags (dynobj, htab->srelgot,
3224 (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS
3225 | SEC_IN_MEMORY | SEC_LINKER_CREATED
3226 | SEC_READONLY))
3227 || ! bfd_set_section_alignment (dynobj, htab->srelgot, 3))
3228 return FALSE;
3229 return TRUE;
3230 }
3231
3232 /* Create the dynamic sections, and set up shortcuts. */
3233
3234 static bfd_boolean
3235 ppc64_elf_create_dynamic_sections (dynobj, info)
3236 bfd *dynobj;
3237 struct bfd_link_info *info;
3238 {
3239 struct ppc_link_hash_table *htab;
3240
3241 htab = ppc_hash_table (info);
3242 if (!htab->sgot && !create_got_section (dynobj, info))
3243 return FALSE;
3244
3245 if (!_bfd_elf_create_dynamic_sections (dynobj, info))
3246 return FALSE;
3247
3248 htab->splt = bfd_get_section_by_name (dynobj, ".plt");
3249 htab->srelplt = bfd_get_section_by_name (dynobj, ".rela.plt");
3250 htab->sdynbss = bfd_get_section_by_name (dynobj, ".dynbss");
3251 if (!info->shared)
3252 htab->srelbss = bfd_get_section_by_name (dynobj, ".rela.bss");
3253
3254 if (!htab->splt || !htab->srelplt || !htab->sdynbss
3255 || (!info->shared && !htab->srelbss))
3256 abort ();
3257
3258 return TRUE;
3259 }
3260
3261 /* Copy the extra info we tack onto an elf_link_hash_entry. */
3262
3263 static void
3264 ppc64_elf_copy_indirect_symbol (bed, dir, ind)
3265 struct elf_backend_data *bed ATTRIBUTE_UNUSED;
3266 struct elf_link_hash_entry *dir, *ind;
3267 {
3268 struct ppc_link_hash_entry *edir, *eind;
3269
3270 edir = (struct ppc_link_hash_entry *) dir;
3271 eind = (struct ppc_link_hash_entry *) ind;
3272
3273 /* Copy over any dynamic relocs we may have on the indirect sym. */
3274 if (eind->dyn_relocs != NULL)
3275 {
3276 if (edir->dyn_relocs != NULL)
3277 {
3278 struct ppc_dyn_relocs **pp;
3279 struct ppc_dyn_relocs *p;
3280
3281 if (eind->elf.root.type == bfd_link_hash_indirect)
3282 abort ();
3283
3284 /* Add reloc counts against the weak sym to the strong sym
3285 list. Merge any entries against the same section. */
3286 for (pp = &eind->dyn_relocs; (p = *pp) != NULL; )
3287 {
3288 struct ppc_dyn_relocs *q;
3289
3290 for (q = edir->dyn_relocs; q != NULL; q = q->next)
3291 if (q->sec == p->sec)
3292 {
3293 q->pc_count += p->pc_count;
3294 q->count += p->count;
3295 *pp = p->next;
3296 break;
3297 }
3298 if (q == NULL)
3299 pp = &p->next;
3300 }
3301 *pp = edir->dyn_relocs;
3302 }
3303
3304 edir->dyn_relocs = eind->dyn_relocs;
3305 eind->dyn_relocs = NULL;
3306 }
3307
3308 edir->is_func |= eind->is_func;
3309 edir->is_func_descriptor |= eind->is_func_descriptor;
3310 edir->is_entry |= eind->is_entry;
3311 edir->tls_mask |= eind->tls_mask;
3312
3313 /* Copy down any references that we may have already seen to the
3314 symbol which just became indirect. */
3315 edir->elf.elf_link_hash_flags |=
3316 (eind->elf.elf_link_hash_flags
3317 & (ELF_LINK_HASH_REF_DYNAMIC
3318 | ELF_LINK_HASH_REF_REGULAR
3319 | ELF_LINK_HASH_REF_REGULAR_NONWEAK
3320 | ELF_LINK_NON_GOT_REF));
3321
3322 /* If we were called to copy over info for a weak sym, that's all. */
3323 if (eind->elf.root.type != bfd_link_hash_indirect)
3324 return;
3325
3326 /* Copy over got entries. */
3327 if (eind->elf.got.glist != NULL)
3328 {
3329 if (edir->elf.got.glist != NULL)
3330 {
3331 struct got_entry **entp;
3332 struct got_entry *ent;
3333
3334 for (entp = &eind->elf.got.glist; (ent = *entp) != NULL; )
3335 {
3336 struct got_entry *dent;
3337
3338 for (dent = edir->elf.got.glist; dent != NULL; dent = dent->next)
3339 if (dent->addend == ent->addend
3340 && dent->tls_type == ent->tls_type)
3341 {
3342 dent->got.refcount += ent->got.refcount;
3343 *entp = ent->next;
3344 break;
3345 }
3346 if (dent == NULL)
3347 entp = &ent->next;
3348 }
3349 *entp = edir->elf.got.glist;
3350 }
3351
3352 edir->elf.got.glist = eind->elf.got.glist;
3353 eind->elf.got.glist = NULL;
3354 }
3355
3356 /* And plt entries. */
3357 if (eind->elf.plt.plist != NULL)
3358 {
3359 if (edir->elf.plt.plist != NULL)
3360 {
3361 struct plt_entry **entp;
3362 struct plt_entry *ent;
3363
3364 for (entp = &eind->elf.plt.plist; (ent = *entp) != NULL; )
3365 {
3366 struct plt_entry *dent;
3367
3368 for (dent = edir->elf.plt.plist; dent != NULL; dent = dent->next)
3369 if (dent->addend == ent->addend)
3370 {
3371 dent->plt.refcount += ent->plt.refcount;
3372 *entp = ent->next;
3373 break;
3374 }
3375 if (dent == NULL)
3376 entp = &ent->next;
3377 }
3378 *entp = edir->elf.plt.plist;
3379 }
3380
3381 edir->elf.plt.plist = eind->elf.plt.plist;
3382 eind->elf.plt.plist = NULL;
3383 }
3384
3385 if (edir->elf.dynindx == -1)
3386 {
3387 edir->elf.dynindx = eind->elf.dynindx;
3388 edir->elf.dynstr_index = eind->elf.dynstr_index;
3389 eind->elf.dynindx = -1;
3390 eind->elf.dynstr_index = 0;
3391 }
3392 else
3393 BFD_ASSERT (eind->elf.dynindx == -1);
3394 }
3395
3396 /* Set a flag, used by ppc64_elf_gc_mark_hook, on the entry symbol and
3397 symbols undefined on the command-line. */
3398
3399 bfd_boolean
3400 ppc64_elf_mark_entry_syms (info)
3401 struct bfd_link_info *info;
3402 {
3403 struct ppc_link_hash_table *htab;
3404 struct bfd_sym_chain *sym;
3405
3406 htab = ppc_hash_table (info);
3407 for (sym = info->gc_sym_list; sym; sym = sym->next)
3408 {
3409 struct elf_link_hash_entry *h;
3410
3411 h = elf_link_hash_lookup (&htab->elf, sym->name, FALSE, FALSE, FALSE);
3412 if (h != NULL)
3413 ((struct ppc_link_hash_entry *) h)->is_entry = 1;
3414 }
3415 return TRUE;
3416 }
3417
3418 static bfd_boolean
3419 update_local_sym_info (abfd, symtab_hdr, r_symndx, r_addend, tls_type)
3420 bfd *abfd;
3421 Elf_Internal_Shdr *symtab_hdr;
3422 unsigned long r_symndx;
3423 bfd_vma r_addend;
3424 int tls_type;
3425 {
3426 struct got_entry **local_got_ents = elf_local_got_ents (abfd);
3427 char *local_got_tls_masks;
3428
3429 if (local_got_ents == NULL)
3430 {
3431 bfd_size_type size = symtab_hdr->sh_info;
3432
3433 size *= sizeof (*local_got_ents) + sizeof (*local_got_tls_masks);
3434 local_got_ents = (struct got_entry **) bfd_zalloc (abfd, size);
3435 if (local_got_ents == NULL)
3436 return FALSE;
3437 elf_local_got_ents (abfd) = local_got_ents;
3438 }
3439
3440 if ((tls_type & TLS_EXPLICIT) == 0)
3441 {
3442 struct got_entry *ent;
3443
3444 for (ent = local_got_ents[r_symndx]; ent != NULL; ent = ent->next)
3445 if (ent->addend == r_addend && ent->tls_type == tls_type)
3446 break;
3447 if (ent == NULL)
3448 {
3449 bfd_size_type amt = sizeof (*ent);
3450 ent = (struct got_entry *) bfd_alloc (abfd, amt);
3451 if (ent == NULL)
3452 return FALSE;
3453 ent->next = local_got_ents[r_symndx];
3454 ent->addend = r_addend;
3455 ent->tls_type = tls_type;
3456 ent->got.refcount = 0;
3457 local_got_ents[r_symndx] = ent;
3458 }
3459 ent->got.refcount += 1;
3460 }
3461
3462 local_got_tls_masks = (char *) (local_got_ents + symtab_hdr->sh_info);
3463 local_got_tls_masks[r_symndx] |= tls_type;
3464 return TRUE;
3465 }
3466
3467 static bfd_boolean
3468 update_plt_info (abfd, eh, addend)
3469 bfd *abfd;
3470 struct ppc_link_hash_entry *eh;
3471 bfd_vma addend;
3472 {
3473 struct plt_entry *ent;
3474
3475 for (ent = eh->elf.plt.plist; ent != NULL; ent = ent->next)
3476 if (ent->addend == addend)
3477 break;
3478 if (ent == NULL)
3479 {
3480 bfd_size_type amt = sizeof (*ent);
3481 ent = (struct plt_entry *) bfd_alloc (abfd, amt);
3482 if (ent == NULL)
3483 return FALSE;
3484 ent->next = eh->elf.plt.plist;
3485 ent->addend = addend;
3486 ent->plt.refcount = 0;
3487 eh->elf.plt.plist = ent;
3488 }
3489 ent->plt.refcount += 1;
3490 eh->elf.elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
3491 eh->is_func = 1;
3492 return TRUE;
3493 }
3494
3495 /* Look through the relocs for a section during the first phase, and
3496 calculate needed space in the global offset table, procedure
3497 linkage table, and dynamic reloc sections. */
3498
3499 static bfd_boolean
3500 ppc64_elf_check_relocs (abfd, info, sec, relocs)
3501 bfd *abfd;
3502 struct bfd_link_info *info;
3503 asection *sec;
3504 const Elf_Internal_Rela *relocs;
3505 {
3506 struct ppc_link_hash_table *htab;
3507 Elf_Internal_Shdr *symtab_hdr;
3508 struct elf_link_hash_entry **sym_hashes, **sym_hashes_end;
3509 const Elf_Internal_Rela *rel;
3510 const Elf_Internal_Rela *rel_end;
3511 asection *sreloc;
3512 asection **opd_sym_map;
3513
3514 if (info->relocateable)
3515 return TRUE;
3516
3517 htab = ppc_hash_table (info);
3518 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
3519
3520 sym_hashes = elf_sym_hashes (abfd);
3521 sym_hashes_end = (sym_hashes
3522 + symtab_hdr->sh_size / sizeof (Elf64_External_Sym)
3523 - symtab_hdr->sh_info);
3524
3525 sreloc = NULL;
3526 opd_sym_map = NULL;
3527 if (strcmp (bfd_get_section_name (abfd, sec), ".opd") == 0)
3528 {
3529 /* Garbage collection needs some extra help with .opd sections.
3530 We don't want to necessarily keep everything referenced by
3531 relocs in .opd, as that would keep all functions. Instead,
3532 if we reference an .opd symbol (a function descriptor), we
3533 want to keep the function code symbol's section. This is
3534 easy for global symbols, but for local syms we need to keep
3535 information about the associated function section. Later, if
3536 edit_opd deletes entries, we'll use this array to adjust
3537 local syms in .opd. */
3538 union opd_info {
3539 asection *func_section;
3540 long entry_adjust;
3541 };
3542 bfd_size_type amt;
3543
3544 amt = sec->_raw_size * sizeof (union opd_info) / 24;
3545 opd_sym_map = (asection **) bfd_zalloc (abfd, amt);
3546 if (opd_sym_map == NULL)
3547 return FALSE;
3548 ppc64_elf_section_data (sec)->opd.func_sec = opd_sym_map;
3549 }
3550
3551 if (htab->elf.dynobj == NULL)
3552 htab->elf.dynobj = abfd;
3553 if (htab->sfpr == NULL
3554 && !create_linkage_sections (htab->elf.dynobj, info))
3555 return FALSE;
3556
3557 rel_end = relocs + sec->reloc_count;
3558 for (rel = relocs; rel < rel_end; rel++)
3559 {
3560 unsigned long r_symndx;
3561 struct elf_link_hash_entry *h;
3562 enum elf_ppc64_reloc_type r_type;
3563 int tls_type = 0;
3564
3565 r_symndx = ELF64_R_SYM (rel->r_info);
3566 if (r_symndx < symtab_hdr->sh_info)
3567 h = NULL;
3568 else
3569 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
3570
3571 r_type = (enum elf_ppc64_reloc_type) ELF64_R_TYPE (rel->r_info);
3572 switch (r_type)
3573 {
3574 case R_PPC64_GOT_TLSLD16:
3575 case R_PPC64_GOT_TLSLD16_LO:
3576 case R_PPC64_GOT_TLSLD16_HI:
3577 case R_PPC64_GOT_TLSLD16_HA:
3578 htab->tlsld_got.refcount += 1;
3579 tls_type = TLS_TLS | TLS_LD;
3580 goto dogottls;
3581
3582 case R_PPC64_GOT_TLSGD16:
3583 case R_PPC64_GOT_TLSGD16_LO:
3584 case R_PPC64_GOT_TLSGD16_HI:
3585 case R_PPC64_GOT_TLSGD16_HA:
3586 tls_type = TLS_TLS | TLS_GD;
3587 goto dogottls;
3588
3589 case R_PPC64_GOT_TPREL16_DS:
3590 case R_PPC64_GOT_TPREL16_LO_DS:
3591 case R_PPC64_GOT_TPREL16_HI:
3592 case R_PPC64_GOT_TPREL16_HA:
3593 if (info->shared)
3594 info->flags |= DF_STATIC_TLS;
3595 tls_type = TLS_TLS | TLS_TPREL;
3596 goto dogottls;
3597
3598 case R_PPC64_GOT_DTPREL16_DS:
3599 case R_PPC64_GOT_DTPREL16_LO_DS:
3600 case R_PPC64_GOT_DTPREL16_HI:
3601 case R_PPC64_GOT_DTPREL16_HA:
3602 tls_type = TLS_TLS | TLS_DTPREL;
3603 dogottls:
3604 sec->has_tls_reloc = 1;
3605 /* Fall thru */
3606
3607 case R_PPC64_GOT16:
3608 case R_PPC64_GOT16_DS:
3609 case R_PPC64_GOT16_HA:
3610 case R_PPC64_GOT16_HI:
3611 case R_PPC64_GOT16_LO:
3612 case R_PPC64_GOT16_LO_DS:
3613 /* This symbol requires a global offset table entry. */
3614 if (htab->sgot == NULL
3615 && !create_got_section (htab->elf.dynobj, info))
3616 return FALSE;
3617
3618 if (h != NULL)
3619 {
3620 struct ppc_link_hash_entry *eh;
3621 struct got_entry *ent;
3622
3623 eh = (struct ppc_link_hash_entry *) h;
3624 for (ent = eh->elf.got.glist; ent != NULL; ent = ent->next)
3625 if (ent->addend == rel->r_addend
3626 && ent->tls_type == tls_type)
3627 break;
3628 if (ent == NULL)
3629 {
3630 bfd_size_type amt = sizeof (*ent);
3631 ent = (struct got_entry *) bfd_alloc (abfd, amt);
3632 if (ent == NULL)
3633 return FALSE;
3634 ent->next = eh->elf.got.glist;
3635 ent->addend = rel->r_addend;
3636 ent->tls_type = tls_type;
3637 ent->got.refcount = 0;
3638 eh->elf.got.glist = ent;
3639 }
3640 ent->got.refcount += 1;
3641 eh->tls_mask |= tls_type;
3642 }
3643 else
3644 /* This is a global offset table entry for a local symbol. */
3645 if (!update_local_sym_info (abfd, symtab_hdr, r_symndx,
3646 rel->r_addend, tls_type))
3647 return FALSE;
3648 break;
3649
3650 case R_PPC64_PLT16_HA:
3651 case R_PPC64_PLT16_HI:
3652 case R_PPC64_PLT16_LO:
3653 case R_PPC64_PLT32:
3654 case R_PPC64_PLT64:
3655 /* This symbol requires a procedure linkage table entry. We
3656 actually build the entry in adjust_dynamic_symbol,
3657 because this might be a case of linking PIC code without
3658 linking in any dynamic objects, in which case we don't
3659 need to generate a procedure linkage table after all. */
3660 if (h == NULL)
3661 {
3662 /* It does not make sense to have a procedure linkage
3663 table entry for a local symbol. */
3664 bfd_set_error (bfd_error_bad_value);
3665 return FALSE;
3666 }
3667 else
3668 if (!update_plt_info (abfd, (struct ppc_link_hash_entry *) h,
3669 rel->r_addend))
3670 return FALSE;
3671 break;
3672
3673 /* The following relocations don't need to propagate the
3674 relocation if linking a shared object since they are
3675 section relative. */
3676 case R_PPC64_SECTOFF:
3677 case R_PPC64_SECTOFF_LO:
3678 case R_PPC64_SECTOFF_HI:
3679 case R_PPC64_SECTOFF_HA:
3680 case R_PPC64_SECTOFF_DS:
3681 case R_PPC64_SECTOFF_LO_DS:
3682 case R_PPC64_TOC16:
3683 case R_PPC64_TOC16_LO:
3684 case R_PPC64_TOC16_HI:
3685 case R_PPC64_TOC16_HA:
3686 case R_PPC64_TOC16_DS:
3687 case R_PPC64_TOC16_LO_DS:
3688 case R_PPC64_DTPREL16:
3689 case R_PPC64_DTPREL16_LO:
3690 case R_PPC64_DTPREL16_HI:
3691 case R_PPC64_DTPREL16_HA:
3692 case R_PPC64_DTPREL16_DS:
3693 case R_PPC64_DTPREL16_LO_DS:
3694 case R_PPC64_DTPREL16_HIGHER:
3695 case R_PPC64_DTPREL16_HIGHERA:
3696 case R_PPC64_DTPREL16_HIGHEST:
3697 case R_PPC64_DTPREL16_HIGHESTA:
3698 break;
3699
3700 /* This relocation describes the C++ object vtable hierarchy.
3701 Reconstruct it for later use during GC. */
3702 case R_PPC64_GNU_VTINHERIT:
3703 if (!_bfd_elf64_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
3704 return FALSE;
3705 break;
3706
3707 /* This relocation describes which C++ vtable entries are actually
3708 used. Record for later use during GC. */
3709 case R_PPC64_GNU_VTENTRY:
3710 if (!_bfd_elf64_gc_record_vtentry (abfd, sec, h, rel->r_addend))
3711 return FALSE;
3712 break;
3713
3714 case R_PPC64_REL14:
3715 case R_PPC64_REL14_BRTAKEN:
3716 case R_PPC64_REL14_BRNTAKEN:
3717 htab->has_14bit_branch = 1;
3718 /* Fall through. */
3719
3720 case R_PPC64_REL24:
3721 if (h != NULL
3722 && h->root.root.string[0] == '.'
3723 && h->root.root.string[1] != 0)
3724 {
3725 /* We may need a .plt entry if the function this reloc
3726 refers to is in a shared lib. */
3727 if (!update_plt_info (abfd, (struct ppc_link_hash_entry *) h,
3728 rel->r_addend))
3729 return FALSE;
3730 if (h == htab->tls_get_addr)
3731 sec->has_tls_reloc = 1;
3732 else if ((strncmp (h->root.root.string, ".__tls_get_addr", 15)
3733 == 0)
3734 && (h->root.root.string[15] == 0
3735 || h->root.root.string[15] == '@'))
3736 {
3737 htab->tls_get_addr = h;
3738 sec->has_tls_reloc = 1;
3739 }
3740 }
3741 break;
3742
3743 case R_PPC64_TPREL64:
3744 tls_type = TLS_EXPLICIT | TLS_TLS | TLS_TPREL;
3745 if (info->shared)
3746 info->flags |= DF_STATIC_TLS;
3747 goto dotlstoc;
3748
3749 case R_PPC64_DTPMOD64:
3750 if (rel + 1 < rel_end
3751 && rel[1].r_info == ELF64_R_INFO (r_symndx, R_PPC64_DTPREL64)
3752 && rel[1].r_offset == rel->r_offset + 8)
3753 tls_type = TLS_EXPLICIT | TLS_TLS | TLS_GD;
3754 else
3755 tls_type = TLS_EXPLICIT | TLS_TLS | TLS_LD;
3756 goto dotlstoc;
3757
3758 case R_PPC64_DTPREL64:
3759 tls_type = TLS_EXPLICIT | TLS_TLS | TLS_DTPREL;
3760 if (rel != relocs
3761 && rel[-1].r_info == ELF64_R_INFO (r_symndx, R_PPC64_DTPMOD64)
3762 && rel[-1].r_offset == rel->r_offset - 8)
3763 /* This is the second reloc of a dtpmod, dtprel pair.
3764 Don't mark with TLS_DTPREL. */
3765 goto dodyn;
3766
3767 dotlstoc:
3768 sec->has_tls_reloc = 1;
3769 if (h != NULL)
3770 {
3771 struct ppc_link_hash_entry *eh;
3772 eh = (struct ppc_link_hash_entry *) h;
3773 eh->tls_mask |= tls_type;
3774 }
3775 else
3776 if (!update_local_sym_info (abfd, symtab_hdr, r_symndx,
3777 rel->r_addend, tls_type))
3778 return FALSE;
3779
3780 if (ppc64_elf_section_data (sec)->t_symndx == NULL)
3781 {
3782 /* One extra to simplify get_tls_mask. */
3783 bfd_size_type amt = sec->_raw_size * sizeof (unsigned) / 8 + 1;
3784 ppc64_elf_section_data (sec)->t_symndx
3785 = (unsigned *) bfd_zalloc (abfd, amt);
3786 if (ppc64_elf_section_data (sec)->t_symndx == NULL)
3787 return FALSE;
3788 }
3789 BFD_ASSERT (rel->r_offset % 8 == 0);
3790 ppc64_elf_section_data (sec)->t_symndx[rel->r_offset / 8] = r_symndx;
3791
3792 /* Mark the second slot of a GD or LD entry.
3793 -1 to indicate GD and -2 to indicate LD. */
3794 if (tls_type == (TLS_EXPLICIT | TLS_TLS | TLS_GD))
3795 ppc64_elf_section_data (sec)->t_symndx[rel->r_offset / 8 + 1] = -1;
3796 else if (tls_type == (TLS_EXPLICIT | TLS_TLS | TLS_LD))
3797 ppc64_elf_section_data (sec)->t_symndx[rel->r_offset / 8 + 1] = -2;
3798 goto dodyn;
3799
3800 case R_PPC64_TPREL16:
3801 case R_PPC64_TPREL16_LO:
3802 case R_PPC64_TPREL16_HI:
3803 case R_PPC64_TPREL16_HA:
3804 case R_PPC64_TPREL16_DS:
3805 case R_PPC64_TPREL16_LO_DS:
3806 case R_PPC64_TPREL16_HIGHER:
3807 case R_PPC64_TPREL16_HIGHERA:
3808 case R_PPC64_TPREL16_HIGHEST:
3809 case R_PPC64_TPREL16_HIGHESTA:
3810 if (info->shared)
3811 {
3812 info->flags |= DF_STATIC_TLS;
3813 goto dodyn;
3814 }
3815 break;
3816
3817 case R_PPC64_ADDR64:
3818 if (opd_sym_map != NULL
3819 && h != NULL
3820 && h->root.root.string[0] == '.'
3821 && h->root.root.string[1] != 0)
3822 {
3823 struct elf_link_hash_entry *fdh;
3824
3825 fdh = elf_link_hash_lookup (&htab->elf, h->root.root.string + 1,
3826 FALSE, FALSE, FALSE);
3827 if (fdh != NULL)
3828 {
3829 ((struct ppc_link_hash_entry *) fdh)->is_func_descriptor = 1;
3830 ((struct ppc_link_hash_entry *) fdh)->oh = h;
3831 ((struct ppc_link_hash_entry *) h)->is_func = 1;
3832 ((struct ppc_link_hash_entry *) h)->oh = fdh;
3833 }
3834 }
3835 if (opd_sym_map != NULL
3836 && h == NULL
3837 && rel + 1 < rel_end
3838 && ((enum elf_ppc64_reloc_type) ELF64_R_TYPE ((rel + 1)->r_info)
3839 == R_PPC64_TOC))
3840 {
3841 asection *s;
3842
3843 s = bfd_section_from_r_symndx (abfd, &htab->sym_sec, sec,
3844 r_symndx);
3845 if (s == NULL)
3846 return FALSE;
3847 else if (s != sec)
3848 opd_sym_map[rel->r_offset / 24] = s;
3849 }
3850 /* Fall through. */
3851
3852 case R_PPC64_REL30:
3853 case R_PPC64_REL32:
3854 case R_PPC64_REL64:
3855 case R_PPC64_ADDR14:
3856 case R_PPC64_ADDR14_BRNTAKEN:
3857 case R_PPC64_ADDR14_BRTAKEN:
3858 case R_PPC64_ADDR16:
3859 case R_PPC64_ADDR16_DS:
3860 case R_PPC64_ADDR16_HA:
3861 case R_PPC64_ADDR16_HI:
3862 case R_PPC64_ADDR16_HIGHER:
3863 case R_PPC64_ADDR16_HIGHERA:
3864 case R_PPC64_ADDR16_HIGHEST:
3865 case R_PPC64_ADDR16_HIGHESTA:
3866 case R_PPC64_ADDR16_LO:
3867 case R_PPC64_ADDR16_LO_DS:
3868 case R_PPC64_ADDR24:
3869 case R_PPC64_ADDR32:
3870 case R_PPC64_UADDR16:
3871 case R_PPC64_UADDR32:
3872 case R_PPC64_UADDR64:
3873 case R_PPC64_TOC:
3874 /* Don't propagate .opd relocs. */
3875 if (NO_OPD_RELOCS && opd_sym_map != NULL)
3876 break;
3877
3878 /* If we are creating a shared library, and this is a reloc
3879 against a global symbol, or a non PC relative reloc
3880 against a local symbol, then we need to copy the reloc
3881 into the shared library. However, if we are linking with
3882 -Bsymbolic, we do not need to copy a reloc against a
3883 global symbol which is defined in an object we are
3884 including in the link (i.e., DEF_REGULAR is set). At
3885 this point we have not seen all the input files, so it is
3886 possible that DEF_REGULAR is not set now but will be set
3887 later (it is never cleared). In case of a weak definition,
3888 DEF_REGULAR may be cleared later by a strong definition in
3889 a shared library. We account for that possibility below by
3890 storing information in the relocs_copied field of the hash
3891 table entry. A similar situation occurs when creating
3892 shared libraries and symbol visibility changes render the
3893 symbol local.
3894
3895 If on the other hand, we are creating an executable, we
3896 may need to keep relocations for symbols satisfied by a
3897 dynamic library if we manage to avoid copy relocs for the
3898 symbol. */
3899 dodyn:
3900 if ((info->shared
3901 && (sec->flags & SEC_ALLOC) != 0
3902 && (MUST_BE_DYN_RELOC (r_type)
3903 || (h != NULL
3904 && (! info->symbolic
3905 || h->root.type == bfd_link_hash_defweak
3906 || (h->elf_link_hash_flags
3907 & ELF_LINK_HASH_DEF_REGULAR) == 0))))
3908 || (!info->shared
3909 && (sec->flags & SEC_ALLOC) != 0
3910 && h != NULL
3911 && (h->root.type == bfd_link_hash_defweak
3912 || (h->elf_link_hash_flags
3913 & ELF_LINK_HASH_DEF_REGULAR) == 0)))
3914 {
3915 struct ppc_dyn_relocs *p;
3916 struct ppc_dyn_relocs **head;
3917
3918 /* We must copy these reloc types into the output file.
3919 Create a reloc section in dynobj and make room for
3920 this reloc. */
3921 if (sreloc == NULL)
3922 {
3923 const char *name;
3924 bfd *dynobj;
3925
3926 name = (bfd_elf_string_from_elf_section
3927 (abfd,
3928 elf_elfheader (abfd)->e_shstrndx,
3929 elf_section_data (sec)->rel_hdr.sh_name));
3930 if (name == NULL)
3931 return FALSE;
3932
3933 if (strncmp (name, ".rela", 5) != 0
3934 || strcmp (bfd_get_section_name (abfd, sec),
3935 name + 5) != 0)
3936 {
3937 (*_bfd_error_handler)
3938 (_("%s: bad relocation section name `%s\'"),
3939 bfd_archive_filename (abfd), name);
3940 bfd_set_error (bfd_error_bad_value);
3941 }
3942
3943 dynobj = htab->elf.dynobj;
3944 sreloc = bfd_get_section_by_name (dynobj, name);
3945 if (sreloc == NULL)
3946 {
3947 flagword flags;
3948
3949 sreloc = bfd_make_section (dynobj, name);
3950 flags = (SEC_HAS_CONTENTS | SEC_READONLY
3951 | SEC_IN_MEMORY | SEC_LINKER_CREATED);
3952 if ((sec->flags & SEC_ALLOC) != 0)
3953 flags |= SEC_ALLOC | SEC_LOAD;
3954 if (sreloc == NULL
3955 || ! bfd_set_section_flags (dynobj, sreloc, flags)
3956 || ! bfd_set_section_alignment (dynobj, sreloc, 3))
3957 return FALSE;
3958 }
3959 elf_section_data (sec)->sreloc = sreloc;
3960 }
3961
3962 /* If this is a global symbol, we count the number of
3963 relocations we need for this symbol. */
3964 if (h != NULL)
3965 {
3966 head = &((struct ppc_link_hash_entry *) h)->dyn_relocs;
3967 }
3968 else
3969 {
3970 /* Track dynamic relocs needed for local syms too.
3971 We really need local syms available to do this
3972 easily. Oh well. */
3973
3974 asection *s;
3975 s = bfd_section_from_r_symndx (abfd, &htab->sym_sec,
3976 sec, r_symndx);
3977 if (s == NULL)
3978 return FALSE;
3979
3980 head = ((struct ppc_dyn_relocs **)
3981 &elf_section_data (s)->local_dynrel);
3982 }
3983
3984 p = *head;
3985 if (p == NULL || p->sec != sec)
3986 {
3987 p = ((struct ppc_dyn_relocs *)
3988 bfd_alloc (htab->elf.dynobj,
3989 (bfd_size_type) sizeof *p));
3990 if (p == NULL)
3991 return FALSE;
3992 p->next = *head;
3993 *head = p;
3994 p->sec = sec;
3995 p->count = 0;
3996 p->pc_count = 0;
3997 }
3998
3999 p->count += 1;
4000 if (!MUST_BE_DYN_RELOC (r_type))
4001 p->pc_count += 1;
4002 }
4003 break;
4004
4005 default:
4006 break;
4007 }
4008 }
4009
4010 return TRUE;
4011 }
4012
4013 /* Return the section that should be marked against GC for a given
4014 relocation. */
4015
4016 static asection *
4017 ppc64_elf_gc_mark_hook (sec, info, rel, h, sym)
4018 asection *sec;
4019 struct bfd_link_info *info ATTRIBUTE_UNUSED;
4020 Elf_Internal_Rela *rel;
4021 struct elf_link_hash_entry *h;
4022 Elf_Internal_Sym *sym;
4023 {
4024 asection *rsec = NULL;
4025
4026 if (h != NULL)
4027 {
4028 enum elf_ppc64_reloc_type r_type;
4029 struct ppc_link_hash_entry *fdh;
4030
4031 r_type = (enum elf_ppc64_reloc_type) ELF64_R_TYPE (rel->r_info);
4032 switch (r_type)
4033 {
4034 case R_PPC64_GNU_VTINHERIT:
4035 case R_PPC64_GNU_VTENTRY:
4036 break;
4037
4038 default:
4039 switch (h->root.type)
4040 {
4041 case bfd_link_hash_defined:
4042 case bfd_link_hash_defweak:
4043 fdh = (struct ppc_link_hash_entry *) h;
4044
4045 /* Function descriptor syms cause the associated
4046 function code sym section to be marked. */
4047 if (fdh->is_func_descriptor)
4048 rsec = fdh->oh->root.u.def.section;
4049
4050 /* Function entry syms return NULL if they are in .opd
4051 and are not ._start (or others undefined on the ld
4052 command line). Thus we avoid marking all function
4053 sections, as all functions are referenced in .opd. */
4054 else if ((fdh->oh != NULL
4055 && ((struct ppc_link_hash_entry *) fdh->oh)->is_entry)
4056 || ppc64_elf_section_data (sec)->opd.func_sec == NULL)
4057 rsec = h->root.u.def.section;
4058 break;
4059
4060 case bfd_link_hash_common:
4061 rsec = h->root.u.c.p->section;
4062 break;
4063
4064 default:
4065 break;
4066 }
4067 }
4068 }
4069 else
4070 {
4071 asection **opd_sym_section;
4072
4073 rsec = bfd_section_from_elf_index (sec->owner, sym->st_shndx);
4074 opd_sym_section = ppc64_elf_section_data (rsec)->opd.func_sec;
4075 if (opd_sym_section != NULL)
4076 rsec = opd_sym_section[sym->st_value / 24];
4077 else if (ppc64_elf_section_data (sec)->opd.func_sec != NULL)
4078 rsec = NULL;
4079 }
4080
4081 return rsec;
4082 }
4083
4084 /* Update the .got, .plt. and dynamic reloc reference counts for the
4085 section being removed. */
4086
4087 static bfd_boolean
4088 ppc64_elf_gc_sweep_hook (abfd, info, sec, relocs)
4089 bfd *abfd;
4090 struct bfd_link_info *info;
4091 asection *sec;
4092 const Elf_Internal_Rela *relocs;
4093 {
4094 struct ppc_link_hash_table *htab;
4095 Elf_Internal_Shdr *symtab_hdr;
4096 struct elf_link_hash_entry **sym_hashes;
4097 struct got_entry **local_got_ents;
4098 const Elf_Internal_Rela *rel, *relend;
4099
4100 elf_section_data (sec)->local_dynrel = NULL;
4101
4102 htab = ppc_hash_table (info);
4103 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
4104 sym_hashes = elf_sym_hashes (abfd);
4105 local_got_ents = elf_local_got_ents (abfd);
4106
4107 relend = relocs + sec->reloc_count;
4108 for (rel = relocs; rel < relend; rel++)
4109 {
4110 unsigned long r_symndx;
4111 enum elf_ppc64_reloc_type r_type;
4112 struct elf_link_hash_entry *h = NULL;
4113 char tls_type = 0;
4114
4115 r_symndx = ELF64_R_SYM (rel->r_info);
4116 r_type = (enum elf_ppc64_reloc_type) ELF64_R_TYPE (rel->r_info);
4117 if (r_symndx >= symtab_hdr->sh_info)
4118 {
4119 struct ppc_link_hash_entry *eh;
4120 struct ppc_dyn_relocs **pp;
4121 struct ppc_dyn_relocs *p;
4122
4123 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
4124 eh = (struct ppc_link_hash_entry *) h;
4125
4126 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next)
4127 if (p->sec == sec)
4128 {
4129 /* Everything must go for SEC. */
4130 *pp = p->next;
4131 break;
4132 }
4133 }
4134
4135 switch (r_type)
4136 {
4137 case R_PPC64_GOT_TLSLD16:
4138 case R_PPC64_GOT_TLSLD16_LO:
4139 case R_PPC64_GOT_TLSLD16_HI:
4140 case R_PPC64_GOT_TLSLD16_HA:
4141 htab->tlsld_got.refcount -= 1;
4142 tls_type = TLS_TLS | TLS_LD;
4143 goto dogot;
4144
4145 case R_PPC64_GOT_TLSGD16:
4146 case R_PPC64_GOT_TLSGD16_LO:
4147 case R_PPC64_GOT_TLSGD16_HI:
4148 case R_PPC64_GOT_TLSGD16_HA:
4149 tls_type = TLS_TLS | TLS_GD;
4150 goto dogot;
4151
4152 case R_PPC64_GOT_TPREL16_DS:
4153 case R_PPC64_GOT_TPREL16_LO_DS:
4154 case R_PPC64_GOT_TPREL16_HI:
4155 case R_PPC64_GOT_TPREL16_HA:
4156 tls_type = TLS_TLS | TLS_TPREL;
4157 goto dogot;
4158
4159 case R_PPC64_GOT_DTPREL16_DS:
4160 case R_PPC64_GOT_DTPREL16_LO_DS:
4161 case R_PPC64_GOT_DTPREL16_HI:
4162 case R_PPC64_GOT_DTPREL16_HA:
4163 tls_type = TLS_TLS | TLS_DTPREL;
4164 goto dogot;
4165
4166 case R_PPC64_GOT16:
4167 case R_PPC64_GOT16_DS:
4168 case R_PPC64_GOT16_HA:
4169 case R_PPC64_GOT16_HI:
4170 case R_PPC64_GOT16_LO:
4171 case R_PPC64_GOT16_LO_DS:
4172 dogot:
4173 {
4174 struct got_entry *ent;
4175
4176 if (h != NULL)
4177 ent = h->got.glist;
4178 else
4179 ent = local_got_ents[r_symndx];
4180
4181 for (; ent != NULL; ent = ent->next)
4182 if (ent->addend == rel->r_addend
4183 && ent->tls_type == tls_type)
4184 break;
4185 if (ent == NULL)
4186 abort ();
4187 if (ent->got.refcount > 0)
4188 ent->got.refcount -= 1;
4189 }
4190 break;
4191
4192 case R_PPC64_PLT16_HA:
4193 case R_PPC64_PLT16_HI:
4194 case R_PPC64_PLT16_LO:
4195 case R_PPC64_PLT32:
4196 case R_PPC64_PLT64:
4197 case R_PPC64_REL14:
4198 case R_PPC64_REL14_BRNTAKEN:
4199 case R_PPC64_REL14_BRTAKEN:
4200 case R_PPC64_REL24:
4201 if (h != NULL)
4202 {
4203 struct plt_entry *ent;
4204
4205 for (ent = h->plt.plist; ent != NULL; ent = ent->next)
4206 if (ent->addend == rel->r_addend)
4207 break;
4208 if (ent == NULL)
4209 abort ();
4210 if (ent->plt.refcount > 0)
4211 ent->plt.refcount -= 1;
4212 }
4213 break;
4214
4215 default:
4216 break;
4217 }
4218 }
4219 return TRUE;
4220 }
4221
4222 /* Called via elf_link_hash_traverse to transfer dynamic linking
4223 information on function code symbol entries to their corresponding
4224 function descriptor symbol entries. */
4225 static bfd_boolean
4226 func_desc_adjust (h, inf)
4227 struct elf_link_hash_entry *h;
4228 PTR inf;
4229 {
4230 struct bfd_link_info *info;
4231 struct ppc_link_hash_table *htab;
4232 struct plt_entry *ent;
4233
4234 if (h->root.type == bfd_link_hash_indirect)
4235 return TRUE;
4236
4237 if (h->root.type == bfd_link_hash_warning)
4238 h = (struct elf_link_hash_entry *) h->root.u.i.link;
4239
4240 info = (struct bfd_link_info *) inf;
4241 htab = ppc_hash_table (info);
4242
4243 /* If this is a function code symbol, transfer dynamic linking
4244 information to the function descriptor symbol. */
4245 if (!((struct ppc_link_hash_entry *) h)->is_func)
4246 return TRUE;
4247
4248 if (h->root.type == bfd_link_hash_undefweak
4249 && (h->elf_link_hash_flags & ELF_LINK_HASH_REF_REGULAR))
4250 htab->have_undefweak = TRUE;
4251
4252 for (ent = h->plt.plist; ent != NULL; ent = ent->next)
4253 if (ent->plt.refcount > 0)
4254 break;
4255 if (ent != NULL
4256 && h->root.root.string[0] == '.'
4257 && h->root.root.string[1] != '\0')
4258 {
4259 struct elf_link_hash_entry *fdh = ((struct ppc_link_hash_entry *) h)->oh;
4260 bfd_boolean force_local;
4261
4262 /* Find the corresponding function descriptor symbol. Create it
4263 as undefined if necessary. */
4264
4265 if (fdh == NULL)
4266 fdh = elf_link_hash_lookup (&htab->elf, h->root.root.string + 1,
4267 FALSE, FALSE, TRUE);
4268
4269 if (fdh == NULL
4270 && info->shared
4271 && (h->root.type == bfd_link_hash_undefined
4272 || h->root.type == bfd_link_hash_undefweak))
4273 {
4274 bfd *abfd;
4275 asymbol *newsym;
4276 struct bfd_link_hash_entry *bh;
4277
4278 abfd = h->root.u.undef.abfd;
4279 newsym = bfd_make_empty_symbol (abfd);
4280 newsym->name = h->root.root.string + 1;
4281 newsym->section = bfd_und_section_ptr;
4282 newsym->value = 0;
4283 newsym->flags = BSF_OBJECT;
4284 if (h->root.type == bfd_link_hash_undefweak)
4285 newsym->flags |= BSF_WEAK;
4286
4287 bh = &fdh->root;
4288 if ( !(_bfd_generic_link_add_one_symbol
4289 (info, abfd, newsym->name, newsym->flags,
4290 newsym->section, newsym->value, NULL, FALSE, FALSE, &bh)))
4291 {
4292 return FALSE;
4293 }
4294 fdh = (struct elf_link_hash_entry *) bh;
4295 fdh->elf_link_hash_flags &= ~ELF_LINK_NON_ELF;
4296 }
4297
4298 if (fdh != NULL
4299 && (fdh->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0
4300 && (info->shared
4301 || (fdh->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0
4302 || (fdh->elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) != 0))
4303 {
4304 if (fdh->dynindx == -1)
4305 if (! bfd_elf64_link_record_dynamic_symbol (info, fdh))
4306 return FALSE;
4307 fdh->elf_link_hash_flags |= (h->elf_link_hash_flags
4308 & (ELF_LINK_HASH_REF_REGULAR
4309 | ELF_LINK_HASH_REF_DYNAMIC
4310 | ELF_LINK_HASH_REF_REGULAR_NONWEAK
4311 | ELF_LINK_NON_GOT_REF));
4312 if (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
4313 {
4314 fdh->plt.plist = h->plt.plist;
4315 fdh->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
4316 }
4317 ((struct ppc_link_hash_entry *) fdh)->is_func_descriptor = 1;
4318 ((struct ppc_link_hash_entry *) fdh)->oh = h;
4319 ((struct ppc_link_hash_entry *) h)->oh = fdh;
4320 }
4321
4322 /* Now that the info is on the function descriptor, clear the
4323 function code sym info. Any function code syms for which we
4324 don't have a definition in a regular file, we force local.
4325 This prevents a shared library from exporting syms that have
4326 been imported from another library. Function code syms that
4327 are really in the library we must leave global to prevent the
4328 linker dragging in a definition from a static library. */
4329 force_local = (info->shared
4330 && ((h->elf_link_hash_flags
4331 & ELF_LINK_HASH_DEF_REGULAR) == 0
4332 || fdh == NULL
4333 || (fdh->elf_link_hash_flags
4334 & ELF_LINK_HASH_DEF_REGULAR) == 0
4335 || (fdh->elf_link_hash_flags
4336 & ELF_LINK_FORCED_LOCAL) != 0));
4337 _bfd_elf_link_hash_hide_symbol (info, h, force_local);
4338 }
4339
4340 return TRUE;
4341 }
4342
4343 #define MIN_SAVE_FPR 14
4344 #define MAX_SAVE_FPR 31
4345
4346 /* Called near the start of bfd_elf_size_dynamic_sections. We use
4347 this hook to a) provide some gcc support functions, and b) transfer
4348 dynamic linking information gathered so far on function code symbol
4349 entries, to their corresponding function descriptor symbol entries. */
4350 static bfd_boolean
4351 ppc64_elf_func_desc_adjust (obfd, info)
4352 bfd *obfd ATTRIBUTE_UNUSED;
4353 struct bfd_link_info *info;
4354 {
4355 struct ppc_link_hash_table *htab;
4356 unsigned int lowest_savef = MAX_SAVE_FPR + 2;
4357 unsigned int lowest_restf = MAX_SAVE_FPR + 2;
4358 unsigned int i;
4359 struct elf_link_hash_entry *h;
4360 bfd_byte *p;
4361 char sym[10];
4362
4363 htab = ppc_hash_table (info);
4364
4365 if (htab->sfpr == NULL)
4366 /* We don't have any relocs. */
4367 return TRUE;
4368
4369 /* First provide any missing ._savef* and ._restf* functions. */
4370 memcpy (sym, "._savef14", 10);
4371 for (i = MIN_SAVE_FPR; i <= MAX_SAVE_FPR; i++)
4372 {
4373 sym[7] = i / 10 + '0';
4374 sym[8] = i % 10 + '0';
4375 h = elf_link_hash_lookup (&htab->elf, sym, FALSE, FALSE, TRUE);
4376 if (h != NULL
4377 && h->root.type == bfd_link_hash_undefined)
4378 {
4379 if (lowest_savef > i)
4380 lowest_savef = i;
4381 h->root.type = bfd_link_hash_defined;
4382 h->root.u.def.section = htab->sfpr;
4383 h->root.u.def.value = (i - lowest_savef) * 4;
4384 h->type = STT_FUNC;
4385 h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
4386 _bfd_elf_link_hash_hide_symbol (info, h, info->shared);
4387 }
4388 }
4389
4390 memcpy (sym, "._restf14", 10);
4391 for (i = MIN_SAVE_FPR; i <= MAX_SAVE_FPR; i++)
4392 {
4393 sym[7] = i / 10 + '0';
4394 sym[8] = i % 10 + '0';
4395 h = elf_link_hash_lookup (&htab->elf, sym, FALSE, FALSE, TRUE);
4396 if (h != NULL
4397 && h->root.type == bfd_link_hash_undefined)
4398 {
4399 if (lowest_restf > i)
4400 lowest_restf = i;
4401 h->root.type = bfd_link_hash_defined;
4402 h->root.u.def.section = htab->sfpr;
4403 h->root.u.def.value = ((MAX_SAVE_FPR + 2 - lowest_savef) * 4
4404 + (i - lowest_restf) * 4);
4405 h->type = STT_FUNC;
4406 h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
4407 _bfd_elf_link_hash_hide_symbol (info, h, info->shared);
4408 }
4409 }
4410
4411 elf_link_hash_traverse (&htab->elf, func_desc_adjust, (PTR) info);
4412
4413 htab->sfpr->_raw_size = ((MAX_SAVE_FPR + 2 - lowest_savef) * 4
4414 + (MAX_SAVE_FPR + 2 - lowest_restf) * 4);
4415
4416 if (htab->sfpr->_raw_size == 0)
4417 {
4418 if (!htab->have_undefweak)
4419 {
4420 _bfd_strip_section_from_output (info, htab->sfpr);
4421 return TRUE;
4422 }
4423
4424 htab->sfpr->_raw_size = 4;
4425 }
4426
4427 p = (bfd_byte *) bfd_alloc (htab->elf.dynobj, htab->sfpr->_raw_size);
4428 if (p == NULL)
4429 return FALSE;
4430 htab->sfpr->contents = p;
4431
4432 for (i = lowest_savef; i <= MAX_SAVE_FPR; i++)
4433 {
4434 unsigned int fpr = i << 21;
4435 unsigned int stackoff = (1 << 16) - (MAX_SAVE_FPR + 1 - i) * 8;
4436 bfd_put_32 (htab->elf.dynobj, STFD_FR0_0R1 + fpr + stackoff, p);
4437 p += 4;
4438 }
4439 if (lowest_savef <= MAX_SAVE_FPR)
4440 {
4441 bfd_put_32 (htab->elf.dynobj, BLR, p);
4442 p += 4;
4443 }
4444
4445 for (i = lowest_restf; i <= MAX_SAVE_FPR; i++)
4446 {
4447 unsigned int fpr = i << 21;
4448 unsigned int stackoff = (1 << 16) - (MAX_SAVE_FPR + 1 - i) * 8;
4449 bfd_put_32 (htab->elf.dynobj, LFD_FR0_0R1 + fpr + stackoff, p);
4450 p += 4;
4451 }
4452 if (lowest_restf <= MAX_SAVE_FPR
4453 || htab->sfpr->_raw_size == 4)
4454 {
4455 bfd_put_32 (htab->elf.dynobj, BLR, p);
4456 }
4457
4458 return TRUE;
4459 }
4460
4461 /* Adjust a symbol defined by a dynamic object and referenced by a
4462 regular object. The current definition is in some section of the
4463 dynamic object, but we're not including those sections. We have to
4464 change the definition to something the rest of the link can
4465 understand. */
4466
4467 static bfd_boolean
4468 ppc64_elf_adjust_dynamic_symbol (info, h)
4469 struct bfd_link_info *info;
4470 struct elf_link_hash_entry *h;
4471 {
4472 struct ppc_link_hash_table *htab;
4473 struct ppc_link_hash_entry * eh;
4474 struct ppc_dyn_relocs *p;
4475 asection *s;
4476 unsigned int power_of_two;
4477
4478 htab = ppc_hash_table (info);
4479
4480 /* Deal with function syms. */
4481 if (h->type == STT_FUNC
4482 || (h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0)
4483 {
4484 /* Clear procedure linkage table information for any symbol that
4485 won't need a .plt entry. */
4486 struct plt_entry *ent;
4487 for (ent = h->plt.plist; ent != NULL; ent = ent->next)
4488 if (ent->plt.refcount > 0)
4489 break;
4490 if (!((struct ppc_link_hash_entry *) h)->is_func_descriptor
4491 || ent == NULL
4492 || (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0
4493 || (! info->shared
4494 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) == 0
4495 && (h->elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) == 0))
4496 {
4497 h->plt.plist = NULL;
4498 h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
4499 }
4500 return TRUE;
4501 }
4502 else
4503 h->plt.plist = NULL;
4504
4505 /* If this is a weak symbol, and there is a real definition, the
4506 processor independent code will have arranged for us to see the
4507 real definition first, and we can just use the same value. */
4508 if (h->weakdef != NULL)
4509 {
4510 BFD_ASSERT (h->weakdef->root.type == bfd_link_hash_defined
4511 || h->weakdef->root.type == bfd_link_hash_defweak);
4512 h->root.u.def.section = h->weakdef->root.u.def.section;
4513 h->root.u.def.value = h->weakdef->root.u.def.value;
4514 return TRUE;
4515 }
4516
4517 /* This is a reference to a symbol defined by a dynamic object which
4518 is not a function. */
4519
4520 /* If we are creating a shared library, we must presume that the
4521 only references to the symbol are via the global offset table.
4522 For such cases we need not do anything here; the relocations will
4523 be handled correctly by relocate_section. */
4524 if (info->shared)
4525 return TRUE;
4526
4527 /* If there are no references to this symbol that do not use the
4528 GOT, we don't need to generate a copy reloc. */
4529 if ((h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0)
4530 return TRUE;
4531
4532 eh = (struct ppc_link_hash_entry *) h;
4533 for (p = eh->dyn_relocs; p != NULL; p = p->next)
4534 {
4535 s = p->sec->output_section;
4536 if (s != NULL && (s->flags & SEC_READONLY) != 0)
4537 break;
4538 }
4539
4540 /* If we didn't find any dynamic relocs in read-only sections, then
4541 we'll be keeping the dynamic relocs and avoiding the copy reloc. */
4542 if (p == NULL)
4543 {
4544 h->elf_link_hash_flags &= ~ELF_LINK_NON_GOT_REF;
4545 return TRUE;
4546 }
4547
4548 /* We must allocate the symbol in our .dynbss section, which will
4549 become part of the .bss section of the executable. There will be
4550 an entry for this symbol in the .dynsym section. The dynamic
4551 object will contain position independent code, so all references
4552 from the dynamic object to this symbol will go through the global
4553 offset table. The dynamic linker will use the .dynsym entry to
4554 determine the address it must put in the global offset table, so
4555 both the dynamic object and the regular object will refer to the
4556 same memory location for the variable. */
4557
4558 /* We must generate a R_PPC64_COPY reloc to tell the dynamic linker
4559 to copy the initial value out of the dynamic object and into the
4560 runtime process image. We need to remember the offset into the
4561 .rela.bss section we are going to use. */
4562 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
4563 {
4564 htab->srelbss->_raw_size += sizeof (Elf64_External_Rela);
4565 h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_COPY;
4566 }
4567
4568 /* We need to figure out the alignment required for this symbol. I
4569 have no idea how ELF linkers handle this. */
4570 power_of_two = bfd_log2 (h->size);
4571 if (power_of_two > 4)
4572 power_of_two = 4;
4573
4574 /* Apply the required alignment. */
4575 s = htab->sdynbss;
4576 s->_raw_size = BFD_ALIGN (s->_raw_size, (bfd_size_type) (1 << power_of_two));
4577 if (power_of_two > bfd_get_section_alignment (htab->elf.dynobj, s))
4578 {
4579 if (! bfd_set_section_alignment (htab->elf.dynobj, s, power_of_two))
4580 return FALSE;
4581 }
4582
4583 /* Define the symbol as being at this point in the section. */
4584 h->root.u.def.section = s;
4585 h->root.u.def.value = s->_raw_size;
4586
4587 /* Increment the section size to make room for the symbol. */
4588 s->_raw_size += h->size;
4589
4590 return TRUE;
4591 }
4592
4593 /* If given a function descriptor symbol, hide both the function code
4594 sym and the descriptor. */
4595 static void
4596 ppc64_elf_hide_symbol (info, h, force_local)
4597 struct bfd_link_info *info;
4598 struct elf_link_hash_entry *h;
4599 bfd_boolean force_local;
4600 {
4601 _bfd_elf_link_hash_hide_symbol (info, h, force_local);
4602
4603 if (((struct ppc_link_hash_entry *) h)->is_func_descriptor)
4604 {
4605 struct elf_link_hash_entry *fh = ((struct ppc_link_hash_entry *) h)->oh;
4606
4607 if (fh == NULL)
4608 {
4609 const char *p, *q;
4610 struct ppc_link_hash_table *htab;
4611 char save;
4612
4613 /* We aren't supposed to use alloca in BFD because on
4614 systems which do not have alloca the version in libiberty
4615 calls xmalloc, which might cause the program to crash
4616 when it runs out of memory. This function doesn't have a
4617 return status, so there's no way to gracefully return an
4618 error. So cheat. We know that string[-1] can be safely
4619 dereferenced; It's either a string in an ELF string
4620 table, or allocated in an objalloc structure. */
4621
4622 p = h->root.root.string - 1;
4623 save = *p;
4624 *(char *) p = '.';
4625 htab = ppc_hash_table (info);
4626 fh = elf_link_hash_lookup (&htab->elf, p, FALSE, FALSE, FALSE);
4627 *(char *) p = save;
4628
4629 /* Unfortunately, if it so happens that the string we were
4630 looking for was allocated immediately before this string,
4631 then we overwrote the string terminator. That's the only
4632 reason the lookup should fail. */
4633 if (fh == NULL)
4634 {
4635 q = h->root.root.string + strlen (h->root.root.string);
4636 while (q >= h->root.root.string && *q == *p)
4637 --q, --p;
4638 if (q < h->root.root.string && *p == '.')
4639 fh = elf_link_hash_lookup (&htab->elf, p, FALSE, FALSE, FALSE);
4640 }
4641 if (fh != NULL)
4642 {
4643 ((struct ppc_link_hash_entry *) h)->oh = fh;
4644 ((struct ppc_link_hash_entry *) fh)->oh = h;
4645 }
4646 }
4647 if (fh != NULL)
4648 _bfd_elf_link_hash_hide_symbol (info, fh, force_local);
4649 }
4650 }
4651
4652 static bfd_boolean
4653 get_sym_h (hp, symp, symsecp, tls_maskp, locsymsp, r_symndx, ibfd)
4654 struct elf_link_hash_entry **hp;
4655 Elf_Internal_Sym **symp;
4656 asection **symsecp;
4657 char **tls_maskp;
4658 Elf_Internal_Sym **locsymsp;
4659 unsigned long r_symndx;
4660 bfd *ibfd;
4661 {
4662 Elf_Internal_Shdr *symtab_hdr = &elf_tdata (ibfd)->symtab_hdr;
4663
4664 if (r_symndx >= symtab_hdr->sh_info)
4665 {
4666 struct elf_link_hash_entry **sym_hashes = elf_sym_hashes (ibfd);
4667 struct elf_link_hash_entry *h;
4668
4669 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
4670 while (h->root.type == bfd_link_hash_indirect
4671 || h->root.type == bfd_link_hash_warning)
4672 h = (struct elf_link_hash_entry *) h->root.u.i.link;
4673
4674 if (hp != NULL)
4675 *hp = h;
4676
4677 if (symp != NULL)
4678 *symp = NULL;
4679
4680 if (symsecp != NULL)
4681 {
4682 asection *symsec = NULL;
4683 if (h->root.type == bfd_link_hash_defined
4684 || h->root.type == bfd_link_hash_defweak)
4685 symsec = h->root.u.def.section;
4686 *symsecp = symsec;
4687 }
4688
4689 if (tls_maskp != NULL)
4690 {
4691 struct ppc_link_hash_entry *eh;
4692
4693 eh = (struct ppc_link_hash_entry *) h;
4694 *tls_maskp = &eh->tls_mask;
4695 }
4696 }
4697 else
4698 {
4699 Elf_Internal_Sym *sym;
4700 Elf_Internal_Sym *locsyms = *locsymsp;
4701
4702 if (locsyms == NULL)
4703 {
4704 locsyms = (Elf_Internal_Sym *) symtab_hdr->contents;
4705 if (locsyms == NULL)
4706 locsyms = bfd_elf_get_elf_syms (ibfd, symtab_hdr,
4707 symtab_hdr->sh_info,
4708 0, NULL, NULL, NULL);
4709 if (locsyms == NULL)
4710 return FALSE;
4711 *locsymsp = locsyms;
4712 }
4713 sym = locsyms + r_symndx;
4714
4715 if (hp != NULL)
4716 *hp = NULL;
4717
4718 if (symp != NULL)
4719 *symp = sym;
4720
4721 if (symsecp != NULL)
4722 {
4723 asection *symsec = NULL;
4724 if ((sym->st_shndx != SHN_UNDEF
4725 && sym->st_shndx < SHN_LORESERVE)
4726 || sym->st_shndx > SHN_HIRESERVE)
4727 symsec = bfd_section_from_elf_index (ibfd, sym->st_shndx);
4728 *symsecp = symsec;
4729 }
4730
4731 if (tls_maskp != NULL)
4732 {
4733 struct got_entry **lgot_ents;
4734 char *tls_mask;
4735
4736 tls_mask = NULL;
4737 lgot_ents = elf_local_got_ents (ibfd);
4738 if (lgot_ents != NULL)
4739 {
4740 char *lgot_masks = (char *) (lgot_ents + symtab_hdr->sh_info);
4741 tls_mask = &lgot_masks[r_symndx];
4742 }
4743 *tls_maskp = tls_mask;
4744 }
4745 }
4746 return TRUE;
4747 }
4748
4749 /* Returns TLS_MASKP for the given REL symbol. Function return is 0 on
4750 error, 2 on a toc GD type suitable for optimization, 3 on a toc LD
4751 type suitable for optimization, and 1 otherwise. */
4752
4753 static int
4754 get_tls_mask (tls_maskp, locsymsp, rel, ibfd)
4755 char **tls_maskp;
4756 Elf_Internal_Sym **locsymsp;
4757 const Elf_Internal_Rela *rel;
4758 bfd *ibfd;
4759 {
4760 unsigned long r_symndx;
4761 unsigned int next_r;
4762 struct elf_link_hash_entry *h;
4763 Elf_Internal_Sym *sym;
4764 asection *sec;
4765 bfd_vma off;
4766
4767 r_symndx = ELF64_R_SYM (rel->r_info);
4768 if (!get_sym_h (&h, &sym, &sec, tls_maskp, locsymsp, r_symndx, ibfd))
4769 return 0;
4770
4771 if ((*tls_maskp != NULL && **tls_maskp != 0)
4772 || sec == NULL
4773 || ppc64_elf_section_data (sec)->t_symndx == NULL)
4774 return 1;
4775
4776 /* Look inside a TOC section too. */
4777 if (h != NULL)
4778 {
4779 BFD_ASSERT (h->root.type == bfd_link_hash_defined);
4780 off = h->root.u.def.value;
4781 }
4782 else
4783 off = sym->st_value;
4784 off += rel->r_addend;
4785 BFD_ASSERT (off % 8 == 0);
4786 r_symndx = ppc64_elf_section_data (sec)->t_symndx[off / 8];
4787 next_r = ppc64_elf_section_data (sec)->t_symndx[off / 8 + 1];
4788 if (!get_sym_h (&h, &sym, &sec, tls_maskp, locsymsp, r_symndx, ibfd))
4789 return 0;
4790 if (h == NULL
4791 || h->root.type == bfd_link_hash_defined
4792 || h->root.type == bfd_link_hash_defweak)
4793 {
4794 if (next_r == (unsigned) -1)
4795 return 2;
4796 if (next_r == (unsigned) -2
4797 && (h == NULL
4798 || !(h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC)))
4799 return 3;
4800 }
4801 return 1;
4802 }
4803
4804 bfd_boolean
4805 ppc64_elf_edit_opd (obfd, info)
4806 bfd *obfd;
4807 struct bfd_link_info *info;
4808 {
4809 bfd *ibfd;
4810
4811 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
4812 {
4813 asection *sec;
4814 Elf_Internal_Rela *relstart, *rel, *relend;
4815 Elf_Internal_Shdr *symtab_hdr;
4816 Elf_Internal_Sym *local_syms;
4817 struct elf_link_hash_entry **sym_hashes;
4818 bfd_vma offset;
4819 bfd_size_type amt;
4820 long *adjust;
4821 bfd_boolean need_edit;
4822
4823 sec = bfd_get_section_by_name (ibfd, ".opd");
4824 if (sec == NULL)
4825 continue;
4826
4827 amt = sec->_raw_size * sizeof (long) / 24;
4828 adjust = ppc64_elf_section_data (sec)->opd.adjust;
4829 if (adjust == NULL)
4830 {
4831 /* Must be a ld -r link. ie. check_relocs hasn't been
4832 called. */
4833 adjust = (long *) bfd_zalloc (obfd, amt);
4834 ppc64_elf_section_data (sec)->opd.adjust = adjust;
4835 }
4836 memset (adjust, 0, (size_t) amt);
4837
4838 if (sec->output_section == bfd_abs_section_ptr)
4839 continue;
4840
4841 /* Look through the section relocs. */
4842 if ((sec->flags & SEC_RELOC) == 0 || sec->reloc_count == 0)
4843 continue;
4844
4845 local_syms = NULL;
4846 symtab_hdr = &elf_tdata (ibfd)->symtab_hdr;
4847 sym_hashes = elf_sym_hashes (ibfd);
4848
4849 /* Read the relocations. */
4850 relstart = _bfd_elf64_link_read_relocs (ibfd, sec, (PTR) NULL,
4851 (Elf_Internal_Rela *) NULL,
4852 info->keep_memory);
4853 if (relstart == NULL)
4854 return FALSE;
4855
4856 /* First run through the relocs to check they are sane, and to
4857 determine whether we need to edit this opd section. */
4858 need_edit = FALSE;
4859 offset = 0;
4860 relend = relstart + sec->reloc_count;
4861 for (rel = relstart; rel < relend; rel++)
4862 {
4863 enum elf_ppc64_reloc_type r_type;
4864 unsigned long r_symndx;
4865 asection *sym_sec;
4866 struct elf_link_hash_entry *h;
4867 Elf_Internal_Sym *sym;
4868
4869 /* .opd contains a regular array of 24 byte entries. We're
4870 only interested in the reloc pointing to a function entry
4871 point. */
4872 r_type = (enum elf_ppc64_reloc_type) ELF64_R_TYPE (rel->r_info);
4873 if (r_type == R_PPC64_TOC)
4874 continue;
4875
4876 if (r_type != R_PPC64_ADDR64)
4877 {
4878 (*_bfd_error_handler)
4879 (_("%s: unexpected reloc type %u in .opd section"),
4880 bfd_archive_filename (ibfd), r_type);
4881 need_edit = FALSE;
4882 break;
4883 }
4884
4885 if (rel + 1 >= relend)
4886 continue;
4887 r_type = (enum elf_ppc64_reloc_type) ELF64_R_TYPE ((rel + 1)->r_info);
4888 if (r_type != R_PPC64_TOC)
4889 continue;
4890
4891 if (rel->r_offset != offset)
4892 {
4893 /* If someone messes with .opd alignment then after a
4894 "ld -r" we might have padding in the middle of .opd.
4895 Also, there's nothing to prevent someone putting
4896 something silly in .opd with the assembler. No .opd
4897 optimization for them! */
4898 (*_bfd_error_handler)
4899 (_("%s: .opd is not a regular array of opd entries"),
4900 bfd_archive_filename (ibfd));
4901 need_edit = FALSE;
4902 break;
4903 }
4904
4905 r_symndx = ELF64_R_SYM (rel->r_info);
4906 if (!get_sym_h (&h, &sym, &sym_sec, NULL, &local_syms,
4907 r_symndx, ibfd))
4908 goto error_free_rel;
4909
4910 if (sym_sec == NULL || sym_sec->owner == NULL)
4911 {
4912 const char *sym_name;
4913 if (h != NULL)
4914 sym_name = h->root.root.string;
4915 else
4916 sym_name = bfd_elf_local_sym_name (ibfd, sym);
4917
4918 (*_bfd_error_handler)
4919 (_("%s: undefined sym `%s' in .opd section"),
4920 bfd_archive_filename (ibfd),
4921 sym_name);
4922 need_edit = FALSE;
4923 break;
4924 }
4925
4926 /* opd entries are always for functions defined in the
4927 current input bfd. If the symbol isn't defined in the
4928 input bfd, then we won't be using the function in this
4929 bfd; It must be defined in a linkonce section in another
4930 bfd, or is weak. It's also possible that we are
4931 discarding the function due to a linker script /DISCARD/,
4932 which we test for via the output_section. */
4933 if (sym_sec->owner != ibfd
4934 || sym_sec->output_section == bfd_abs_section_ptr)
4935 need_edit = TRUE;
4936
4937 offset += 24;
4938 }
4939
4940 if (need_edit)
4941 {
4942 Elf_Internal_Rela *write_rel;
4943 bfd_byte *rptr, *wptr;
4944 bfd_boolean skip;
4945
4946 /* This seems a waste of time as input .opd sections are all
4947 zeros as generated by gcc, but I suppose there's no reason
4948 this will always be so. We might start putting something in
4949 the third word of .opd entries. */
4950 if ((sec->flags & SEC_IN_MEMORY) == 0)
4951 {
4952 bfd_byte *loc = bfd_alloc (ibfd, sec->_raw_size);
4953 if (loc == NULL
4954 || !bfd_get_section_contents (ibfd, sec, loc, (bfd_vma) 0,
4955 sec->_raw_size))
4956 {
4957 if (local_syms != NULL
4958 && symtab_hdr->contents != (unsigned char *) local_syms)
4959 free (local_syms);
4960 error_free_rel:
4961 if (elf_section_data (sec)->relocs != relstart)
4962 free (relstart);
4963 return FALSE;
4964 }
4965 sec->contents = loc;
4966 sec->flags |= (SEC_IN_MEMORY | SEC_HAS_CONTENTS);
4967 }
4968
4969 elf_section_data (sec)->relocs = relstart;
4970
4971 wptr = sec->contents;
4972 rptr = sec->contents;
4973 write_rel = relstart;
4974 skip = FALSE;
4975 offset = 0;
4976 for (rel = relstart; rel < relend; rel++)
4977 {
4978 if (rel->r_offset == offset)
4979 {
4980 unsigned long r_symndx;
4981 asection *sym_sec;
4982 struct elf_link_hash_entry *h;
4983 Elf_Internal_Sym *sym;
4984
4985 r_symndx = ELF64_R_SYM (rel->r_info);
4986 get_sym_h (&h, &sym, &sym_sec, NULL, &local_syms,
4987 r_symndx, ibfd);
4988
4989 skip = (sym_sec->owner != ibfd
4990 || sym_sec->output_section == bfd_abs_section_ptr);
4991 if (skip)
4992 {
4993 if (h != NULL && sym_sec->owner == ibfd)
4994 {
4995 /* Arrange for the function descriptor sym
4996 to be dropped. */
4997 struct ppc_link_hash_entry *fdh;
4998 struct ppc_link_hash_entry *fh;
4999
5000 fh = (struct ppc_link_hash_entry *) h;
5001 fdh = (struct ppc_link_hash_entry *) fh->oh;
5002 if (fdh == NULL)
5003 {
5004 const char *fd_name;
5005 struct ppc_link_hash_table *htab;
5006
5007 fd_name = h->root.root.string + 1;
5008 htab = ppc_hash_table (info);
5009 fdh = (struct ppc_link_hash_entry *)
5010 elf_link_hash_lookup (&htab->elf, fd_name,
5011 FALSE, FALSE, FALSE);
5012 fdh->is_func_descriptor = 1;
5013 fdh->oh = &fh->elf;
5014 fh->is_func = 1;
5015 fh->oh = &fdh->elf;
5016 }
5017
5018 fdh->elf.root.u.def.value = 0;
5019 fdh->elf.root.u.def.section = sym_sec;
5020 }
5021 }
5022 else
5023 {
5024 /* We'll be keeping this opd entry. */
5025
5026 if (h != NULL)
5027 {
5028 /* Redefine the function descriptor symbol
5029 to this location in the opd section.
5030 We've checked above that opd relocs are
5031 ordered. */
5032 struct ppc_link_hash_entry *fdh;
5033 struct ppc_link_hash_entry *fh;
5034
5035 fh = (struct ppc_link_hash_entry *) h;
5036 fdh = (struct ppc_link_hash_entry *) fh->oh;
5037 if (fdh == NULL)
5038 {
5039 const char *fd_name;
5040 struct ppc_link_hash_table *htab;
5041
5042 fd_name = h->root.root.string + 1;
5043 htab = ppc_hash_table (info);
5044 fdh = (struct ppc_link_hash_entry *)
5045 elf_link_hash_lookup (&htab->elf, fd_name,
5046 FALSE, FALSE, FALSE);
5047 fdh->is_func_descriptor = 1;
5048 fdh->oh = &fh->elf;
5049 fh->is_func = 1;
5050 fh->oh = &fdh->elf;
5051 }
5052
5053 fdh->elf.root.u.def.value = wptr - sec->contents;
5054 }
5055 else
5056 {
5057 /* Local syms are a bit tricky. We could
5058 tweak them as they can be cached, but
5059 we'd need to look through the local syms
5060 for the function descriptor sym which we
5061 don't have at the moment. So keep an
5062 array of adjustments. */
5063 adjust[rel->r_offset / 24] = wptr - rptr;
5064 }
5065
5066 if (wptr != rptr)
5067 memcpy (wptr, rptr, 24);
5068 wptr += 24;
5069 }
5070 rptr += 24;
5071 offset += 24;
5072 }
5073
5074 /* We need to adjust any reloc offsets to point to the
5075 new opd entries. While we're at it, we may as well
5076 remove redundant relocs. */
5077 if (!skip)
5078 {
5079 rel->r_offset += wptr - rptr;
5080 if (write_rel != rel)
5081 memcpy (write_rel, rel, sizeof (*rel));
5082 ++write_rel;
5083 }
5084 }
5085
5086 sec->_cooked_size = wptr - sec->contents;
5087 sec->reloc_count = write_rel - relstart;
5088 /* Fudge the size too, as this is used later in
5089 elf_bfd_final_link if we are emitting relocs. */
5090 elf_section_data (sec)->rel_hdr.sh_size
5091 = sec->reloc_count * elf_section_data (sec)->rel_hdr.sh_entsize;
5092 BFD_ASSERT (elf_section_data (sec)->rel_hdr2 == NULL);
5093 }
5094 else if (elf_section_data (sec)->relocs != relstart)
5095 free (relstart);
5096
5097 if (local_syms != NULL
5098 && symtab_hdr->contents != (unsigned char *) local_syms)
5099 {
5100 if (!info->keep_memory)
5101 free (local_syms);
5102 else
5103 symtab_hdr->contents = (unsigned char *) local_syms;
5104 }
5105 }
5106
5107 return TRUE;
5108 }
5109
5110 /* Set htab->tls_sec. */
5111
5112 bfd_boolean
5113 ppc64_elf_tls_setup (obfd, info)
5114 bfd *obfd;
5115 struct bfd_link_info *info;
5116 {
5117 asection *tls;
5118 struct ppc_link_hash_table *htab;
5119
5120 for (tls = obfd->sections; tls != NULL; tls = tls->next)
5121 if ((tls->flags & (SEC_THREAD_LOCAL | SEC_LOAD))
5122 == (SEC_THREAD_LOCAL | SEC_LOAD))
5123 break;
5124
5125 htab = ppc_hash_table (info);
5126 htab->tls_sec = tls;
5127
5128 if (htab->tls_get_addr != NULL)
5129 {
5130 struct elf_link_hash_entry *h = htab->tls_get_addr;
5131
5132 while (h->root.type == bfd_link_hash_indirect
5133 || h->root.type == bfd_link_hash_warning)
5134 h = (struct elf_link_hash_entry *) h->root.u.i.link;
5135
5136 htab->tls_get_addr = h;
5137 }
5138
5139 return tls != NULL;
5140 }
5141
5142 /* Run through all the TLS relocs looking for optimization
5143 opportunities. The linker has been hacked (see ppc64elf.em) to do
5144 a preliminary section layout so that we know the TLS segment
5145 offsets. We can't optimize earlier because some optimizations need
5146 to know the tp offset, and we need to optimize before allocating
5147 dynamic relocations. */
5148
5149 bfd_boolean
5150 ppc64_elf_tls_optimize (obfd, info)
5151 bfd *obfd ATTRIBUTE_UNUSED;
5152 struct bfd_link_info *info;
5153 {
5154 bfd *ibfd;
5155 asection *sec;
5156 struct ppc_link_hash_table *htab;
5157
5158 if (info->relocateable || info->shared)
5159 return TRUE;
5160
5161 htab = ppc_hash_table (info);
5162 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
5163 {
5164 Elf_Internal_Sym *locsyms = NULL;
5165
5166 for (sec = ibfd->sections; sec != NULL; sec = sec->next)
5167 if (sec->has_tls_reloc && !bfd_is_abs_section (sec->output_section))
5168 {
5169 Elf_Internal_Rela *relstart, *rel, *relend;
5170 int expecting_tls_get_addr;
5171
5172 /* Read the relocations. */
5173 relstart = _bfd_elf64_link_read_relocs (ibfd, sec, (PTR) NULL,
5174 (Elf_Internal_Rela *) NULL,
5175 info->keep_memory);
5176 if (relstart == NULL)
5177 return FALSE;
5178
5179 expecting_tls_get_addr = 0;
5180 relend = relstart + sec->reloc_count;
5181 for (rel = relstart; rel < relend; rel++)
5182 {
5183 enum elf_ppc64_reloc_type r_type;
5184 unsigned long r_symndx;
5185 struct elf_link_hash_entry *h;
5186 Elf_Internal_Sym *sym;
5187 asection *sym_sec;
5188 char *tls_mask;
5189 char tls_set, tls_clear, tls_type = 0;
5190 bfd_vma value;
5191 bfd_boolean ok_tprel, is_local;
5192
5193 r_symndx = ELF64_R_SYM (rel->r_info);
5194 if (!get_sym_h (&h, &sym, &sym_sec, &tls_mask, &locsyms,
5195 r_symndx, ibfd))
5196 {
5197 err_free_rel:
5198 if (elf_section_data (sec)->relocs != relstart)
5199 free (relstart);
5200 if (locsyms != NULL
5201 && (elf_tdata (ibfd)->symtab_hdr.contents
5202 != (unsigned char *) locsyms))
5203 free (locsyms);
5204 return FALSE;
5205 }
5206
5207 if (h != NULL)
5208 {
5209 if (h->root.type != bfd_link_hash_defined
5210 && h->root.type != bfd_link_hash_defweak)
5211 continue;
5212 value = h->root.u.def.value;
5213 }
5214 else
5215 value = sym->st_value;
5216
5217 ok_tprel = FALSE;
5218 is_local = FALSE;
5219 if (h == NULL
5220 || !(h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC))
5221 {
5222 is_local = TRUE;
5223 value += sym_sec->output_offset;
5224 value += sym_sec->output_section->vma;
5225 value -= htab->tls_sec->vma;
5226 ok_tprel = (value + TP_OFFSET + ((bfd_vma) 1 << 31)
5227 < (bfd_vma) 1 << 32);
5228 }
5229
5230 r_type
5231 = (enum elf_ppc64_reloc_type) ELF64_R_TYPE (rel->r_info);
5232 switch (r_type)
5233 {
5234 case R_PPC64_GOT_TLSLD16:
5235 case R_PPC64_GOT_TLSLD16_LO:
5236 case R_PPC64_GOT_TLSLD16_HI:
5237 case R_PPC64_GOT_TLSLD16_HA:
5238 /* These relocs should never be against a symbol
5239 defined in a shared lib. Leave them alone if
5240 that turns out to be the case. */
5241 if (!is_local)
5242 continue;
5243
5244 htab->tlsld_got.refcount -= 1;
5245 /* LD -> LE */
5246 tls_set = 0;
5247 tls_clear = TLS_LD;
5248 tls_type = TLS_TLS | TLS_LD;
5249 expecting_tls_get_addr = 1;
5250 break;
5251
5252 case R_PPC64_GOT_TLSGD16:
5253 case R_PPC64_GOT_TLSGD16_LO:
5254 case R_PPC64_GOT_TLSGD16_HI:
5255 case R_PPC64_GOT_TLSGD16_HA:
5256 if (ok_tprel)
5257 /* GD -> LE */
5258 tls_set = 0;
5259 else
5260 /* GD -> IE */
5261 tls_set = TLS_TLS | TLS_TPRELGD;
5262 tls_clear = TLS_GD;
5263 tls_type = TLS_TLS | TLS_GD;
5264 expecting_tls_get_addr = 1;
5265 break;
5266
5267 case R_PPC64_GOT_TPREL16_DS:
5268 case R_PPC64_GOT_TPREL16_LO_DS:
5269 case R_PPC64_GOT_TPREL16_HI:
5270 case R_PPC64_GOT_TPREL16_HA:
5271 expecting_tls_get_addr = 0;
5272 if (ok_tprel)
5273 {
5274 /* IE -> LE */
5275 tls_set = 0;
5276 tls_clear = TLS_TPREL;
5277 tls_type = TLS_TLS | TLS_TPREL;
5278 break;
5279 }
5280 else
5281 continue;
5282
5283 case R_PPC64_REL14:
5284 case R_PPC64_REL14_BRTAKEN:
5285 case R_PPC64_REL14_BRNTAKEN:
5286 case R_PPC64_REL24:
5287 if (h != NULL
5288 && h == htab->tls_get_addr)
5289 {
5290 if (!expecting_tls_get_addr
5291 && rel != relstart
5292 && ((ELF64_R_TYPE (rel[-1].r_info)
5293 == R_PPC64_TOC16)
5294 || (ELF64_R_TYPE (rel[-1].r_info)
5295 == R_PPC64_TOC16_LO)))
5296 {
5297 /* Check for toc tls entries. */
5298 char *toc_tls;
5299 int retval;
5300
5301 retval = get_tls_mask (&toc_tls, &locsyms,
5302 rel - 1, ibfd);
5303 if (retval == 0)
5304 goto err_free_rel;
5305 if (toc_tls != NULL)
5306 expecting_tls_get_addr = retval > 1;
5307 }
5308
5309 if (expecting_tls_get_addr)
5310 {
5311 struct plt_entry *ent;
5312 for (ent = h->plt.plist; ent; ent = ent->next)
5313 if (ent->addend == 0)
5314 {
5315 if (ent->plt.refcount > 0)
5316 ent->plt.refcount -= 1;
5317 break;
5318 }
5319 }
5320 }
5321 expecting_tls_get_addr = 0;
5322 continue;
5323
5324 case R_PPC64_TPREL64:
5325 expecting_tls_get_addr = 0;
5326 if (ok_tprel)
5327 {
5328 /* IE -> LE */
5329 tls_set = TLS_EXPLICIT;
5330 tls_clear = TLS_TPREL;
5331 break;
5332 }
5333 else
5334 continue;
5335
5336 case R_PPC64_DTPMOD64:
5337 expecting_tls_get_addr = 0;
5338 if (rel + 1 < relend
5339 && (rel[1].r_info
5340 == ELF64_R_INFO (r_symndx, R_PPC64_DTPREL64))
5341 && rel[1].r_offset == rel->r_offset + 8)
5342 {
5343 if (ok_tprel)
5344 /* GD -> LE */
5345 tls_set = TLS_EXPLICIT | TLS_GD;
5346 else
5347 /* GD -> IE */
5348 tls_set = TLS_EXPLICIT | TLS_GD | TLS_TPRELGD;
5349 tls_clear = TLS_GD;
5350 }
5351 else
5352 {
5353 if (!is_local)
5354 continue;
5355
5356 /* LD -> LE */
5357 tls_set = TLS_EXPLICIT;
5358 tls_clear = TLS_LD;
5359 }
5360 break;
5361
5362 default:
5363 expecting_tls_get_addr = 0;
5364 continue;
5365 }
5366
5367 if ((tls_set & TLS_EXPLICIT) == 0)
5368 {
5369 struct got_entry *ent;
5370
5371 /* Adjust got entry for this reloc. */
5372 if (h != NULL)
5373 ent = h->got.glist;
5374 else
5375 ent = elf_local_got_ents (ibfd)[r_symndx];
5376
5377 for (; ent != NULL; ent = ent->next)
5378 if (ent->addend == rel->r_addend
5379 && ent->tls_type == tls_type)
5380 break;
5381 if (ent == NULL)
5382 abort ();
5383
5384 if (tls_set == 0)
5385 {
5386 /* We managed to get rid of a got entry. */
5387 if (ent->got.refcount > 0)
5388 ent->got.refcount -= 1;
5389 }
5390 }
5391 else if (h != NULL)
5392 {
5393 struct ppc_link_hash_entry * eh;
5394 struct ppc_dyn_relocs **pp;
5395 struct ppc_dyn_relocs *p;
5396
5397 /* Adjust dynamic relocs. */
5398 eh = (struct ppc_link_hash_entry *) h;
5399 for (pp = &eh->dyn_relocs;
5400 (p = *pp) != NULL;
5401 pp = &p->next)
5402 if (p->sec == sec)
5403 {
5404 /* If we got rid of a DTPMOD/DTPREL reloc
5405 pair then we'll lose one or two dyn
5406 relocs. */
5407 if (tls_set == (TLS_EXPLICIT | TLS_GD))
5408 p->count -= 1;
5409 p->count -= 1;
5410 if (p->count == 0)
5411 *pp = p->next;
5412 break;
5413 }
5414 }
5415
5416 *tls_mask |= tls_set;
5417 *tls_mask &= ~tls_clear;
5418 }
5419
5420 if (elf_section_data (sec)->relocs != relstart)
5421 free (relstart);
5422 }
5423
5424 if (locsyms != NULL
5425 && (elf_tdata (ibfd)->symtab_hdr.contents
5426 != (unsigned char *) locsyms))
5427 {
5428 if (!info->keep_memory)
5429 free (locsyms);
5430 else
5431 elf_tdata (ibfd)->symtab_hdr.contents = (unsigned char *) locsyms;
5432 }
5433 }
5434 return TRUE;
5435 }
5436
5437 /* This is the condition under which ppc64_elf_finish_dynamic_symbol
5438 will be called from elflink.h. If elflink.h doesn't call our
5439 finish_dynamic_symbol routine, we'll need to do something about
5440 initializing any .plt and .got entries in ppc64_elf_relocate_section. */
5441 #define WILL_CALL_FINISH_DYNAMIC_SYMBOL(DYN, INFO, H) \
5442 ((DYN) \
5443 && ((INFO)->shared \
5444 || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) \
5445 && ((H)->dynindx != -1 \
5446 || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0))
5447
5448 /* Allocate space in .plt, .got and associated reloc sections for
5449 dynamic relocs. */
5450
5451 static bfd_boolean
5452 allocate_dynrelocs (h, inf)
5453 struct elf_link_hash_entry *h;
5454 PTR inf;
5455 {
5456 struct bfd_link_info *info;
5457 struct ppc_link_hash_table *htab;
5458 asection *s;
5459 struct ppc_link_hash_entry *eh;
5460 struct ppc_dyn_relocs *p;
5461 struct got_entry *gent;
5462
5463 if (h->root.type == bfd_link_hash_indirect)
5464 return TRUE;
5465
5466 if (h->root.type == bfd_link_hash_warning)
5467 h = (struct elf_link_hash_entry *) h->root.u.i.link;
5468
5469 info = (struct bfd_link_info *) inf;
5470 htab = ppc_hash_table (info);
5471
5472 if (htab->elf.dynamic_sections_created
5473 && h->dynindx != -1
5474 && WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, info, h))
5475 {
5476 struct plt_entry *pent;
5477 bfd_boolean doneone = FALSE;
5478 for (pent = h->plt.plist; pent != NULL; pent = pent->next)
5479 if (pent->plt.refcount > 0)
5480 {
5481 BFD_ASSERT (((struct ppc_link_hash_entry *) h)->is_func_descriptor);
5482
5483 /* If this is the first .plt entry, make room for the special
5484 first entry. */
5485 s = htab->splt;
5486 if (s->_raw_size == 0)
5487 s->_raw_size += PLT_INITIAL_ENTRY_SIZE;
5488
5489 pent->plt.offset = s->_raw_size;
5490
5491 /* Make room for this entry. */
5492 s->_raw_size += PLT_ENTRY_SIZE;
5493
5494 /* Make room for the .glink code. */
5495 s = htab->sglink;
5496 if (s->_raw_size == 0)
5497 s->_raw_size += GLINK_CALL_STUB_SIZE;
5498 /* We need bigger stubs past index 32767. */
5499 if (s->_raw_size >= GLINK_CALL_STUB_SIZE + 32768*2*4)
5500 s->_raw_size += 4;
5501 s->_raw_size += 2*4;
5502
5503 /* We also need to make an entry in the .rela.plt section. */
5504 s = htab->srelplt;
5505 s->_raw_size += sizeof (Elf64_External_Rela);
5506 doneone = TRUE;
5507 }
5508 else
5509 pent->plt.offset = (bfd_vma) -1;
5510 if (!doneone)
5511 {
5512 h->plt.plist = NULL;
5513 h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
5514 }
5515 }
5516 else
5517 {
5518 h->plt.plist = NULL;
5519 h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
5520 }
5521
5522 eh = (struct ppc_link_hash_entry *) h;
5523 /* Run through the TLS GD got entries first if we're changing them
5524 to TPREL. */
5525 if ((eh->tls_mask & TLS_TPRELGD) != 0)
5526 for (gent = h->got.glist; gent != NULL; gent = gent->next)
5527 if (gent->got.refcount > 0
5528 && (gent->tls_type & TLS_GD) != 0)
5529 {
5530 /* This was a GD entry that has been converted to TPREL. If
5531 there happens to be a TPREL entry we can use that one. */
5532 struct got_entry *ent;
5533 for (ent = h->got.glist; ent != NULL; ent = ent->next)
5534 if (ent->got.refcount > 0
5535 && (ent->tls_type & TLS_TPREL) != 0
5536 && ent->addend == gent->addend)
5537 {
5538 gent->got.refcount = 0;
5539 break;
5540 }
5541
5542 /* If not, then we'll be using our own TPREL entry. */
5543 if (gent->got.refcount != 0)
5544 gent->tls_type = TLS_TLS | TLS_TPREL;
5545 }
5546
5547 for (gent = h->got.glist; gent != NULL; gent = gent->next)
5548 if (gent->got.refcount > 0)
5549 {
5550 bfd_boolean dyn;
5551
5552 /* Make sure this symbol is output as a dynamic symbol.
5553 Undefined weak syms won't yet be marked as dynamic,
5554 nor will all TLS symbols. */
5555 if (h->dynindx == -1
5556 && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0)
5557 {
5558 if (! bfd_elf64_link_record_dynamic_symbol (info, h))
5559 return FALSE;
5560 }
5561
5562 if ((gent->tls_type & TLS_LD) != 0)
5563 {
5564 gent->got.offset = htab->tlsld_got.offset;
5565 continue;
5566 }
5567
5568 s = htab->sgot;
5569 gent->got.offset = s->_raw_size;
5570 s->_raw_size += (gent->tls_type & eh->tls_mask & TLS_GD) ? 16 : 8;
5571 dyn = htab->elf.dynamic_sections_created;
5572 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info, h))
5573 htab->srelgot->_raw_size
5574 += (gent->tls_type & eh->tls_mask & TLS_GD
5575 ? 2 * sizeof (Elf64_External_Rela)
5576 : sizeof (Elf64_External_Rela));
5577 }
5578 else
5579 gent->got.offset = (bfd_vma) -1;
5580
5581 if (eh->dyn_relocs == NULL)
5582 return TRUE;
5583
5584 /* In the shared -Bsymbolic case, discard space allocated for
5585 dynamic pc-relative relocs against symbols which turn out to be
5586 defined in regular objects. For the normal shared case, discard
5587 space for relocs that have become local due to symbol visibility
5588 changes. */
5589
5590 if (info->shared)
5591 {
5592 if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) != 0
5593 && ((h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0
5594 || info->symbolic))
5595 {
5596 struct ppc_dyn_relocs **pp;
5597
5598 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; )
5599 {
5600 p->count -= p->pc_count;
5601 p->pc_count = 0;
5602 if (p->count == 0)
5603 *pp = p->next;
5604 else
5605 pp = &p->next;
5606 }
5607 }
5608 }
5609 else
5610 {
5611 /* For the non-shared case, discard space for relocs against
5612 symbols which turn out to need copy relocs or are not
5613 dynamic. */
5614
5615 if ((h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0
5616 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0
5617 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
5618 {
5619 /* Make sure this symbol is output as a dynamic symbol.
5620 Undefined weak syms won't yet be marked as dynamic. */
5621 if (h->dynindx == -1
5622 && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0)
5623 {
5624 if (! bfd_elf64_link_record_dynamic_symbol (info, h))
5625 return FALSE;
5626 }
5627
5628 /* If that succeeded, we know we'll be keeping all the
5629 relocs. */
5630 if (h->dynindx != -1)
5631 goto keep;
5632 }
5633
5634 eh->dyn_relocs = NULL;
5635
5636 keep: ;
5637 }
5638
5639 /* Finally, allocate space. */
5640 for (p = eh->dyn_relocs; p != NULL; p = p->next)
5641 {
5642 asection *sreloc = elf_section_data (p->sec)->sreloc;
5643 sreloc->_raw_size += p->count * sizeof (Elf64_External_Rela);
5644 }
5645
5646 return TRUE;
5647 }
5648
5649 /* Find any dynamic relocs that apply to read-only sections. */
5650
5651 static bfd_boolean
5652 readonly_dynrelocs (h, inf)
5653 struct elf_link_hash_entry *h;
5654 PTR inf;
5655 {
5656 struct ppc_link_hash_entry *eh;
5657 struct ppc_dyn_relocs *p;
5658
5659 if (h->root.type == bfd_link_hash_warning)
5660 h = (struct elf_link_hash_entry *) h->root.u.i.link;
5661
5662 eh = (struct ppc_link_hash_entry *) h;
5663 for (p = eh->dyn_relocs; p != NULL; p = p->next)
5664 {
5665 asection *s = p->sec->output_section;
5666
5667 if (s != NULL && (s->flags & SEC_READONLY) != 0)
5668 {
5669 struct bfd_link_info *info = (struct bfd_link_info *) inf;
5670
5671 info->flags |= DF_TEXTREL;
5672
5673 /* Not an error, just cut short the traversal. */
5674 return FALSE;
5675 }
5676 }
5677 return TRUE;
5678 }
5679
5680 /* Set the sizes of the dynamic sections. */
5681
5682 static bfd_boolean
5683 ppc64_elf_size_dynamic_sections (output_bfd, info)
5684 bfd *output_bfd ATTRIBUTE_UNUSED;
5685 struct bfd_link_info *info;
5686 {
5687 struct ppc_link_hash_table *htab;
5688 bfd *dynobj;
5689 asection *s;
5690 bfd_boolean relocs;
5691 bfd *ibfd;
5692
5693 htab = ppc_hash_table (info);
5694 dynobj = htab->elf.dynobj;
5695 if (dynobj == NULL)
5696 abort ();
5697
5698 if (htab->elf.dynamic_sections_created)
5699 {
5700 /* Set the contents of the .interp section to the interpreter. */
5701 if (! info->shared)
5702 {
5703 s = bfd_get_section_by_name (dynobj, ".interp");
5704 if (s == NULL)
5705 abort ();
5706 s->_raw_size = sizeof ELF_DYNAMIC_INTERPRETER;
5707 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
5708 }
5709 }
5710
5711 if (htab->tlsld_got.refcount > 0)
5712 {
5713 htab->tlsld_got.offset = htab->sgot->_raw_size;
5714 htab->sgot->_raw_size += 16;
5715 if (info->shared)
5716 htab->srelgot->_raw_size += sizeof (Elf64_External_Rela);
5717 }
5718 else
5719 htab->tlsld_got.offset = (bfd_vma) -1;
5720
5721 /* Set up .got offsets for local syms, and space for local dynamic
5722 relocs. */
5723 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
5724 {
5725 struct got_entry **lgot_ents;
5726 struct got_entry **end_lgot_ents;
5727 char *lgot_masks;
5728 bfd_size_type locsymcount;
5729 Elf_Internal_Shdr *symtab_hdr;
5730 asection *srel;
5731
5732 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour)
5733 continue;
5734
5735 for (s = ibfd->sections; s != NULL; s = s->next)
5736 {
5737 struct ppc_dyn_relocs *p;
5738
5739 for (p = *((struct ppc_dyn_relocs **)
5740 &elf_section_data (s)->local_dynrel);
5741 p != NULL;
5742 p = p->next)
5743 {
5744 if (!bfd_is_abs_section (p->sec)
5745 && bfd_is_abs_section (p->sec->output_section))
5746 {
5747 /* Input section has been discarded, either because
5748 it is a copy of a linkonce section or due to
5749 linker script /DISCARD/, so we'll be discarding
5750 the relocs too. */
5751 }
5752 else if (p->count != 0)
5753 {
5754 srel = elf_section_data (p->sec)->sreloc;
5755 srel->_raw_size += p->count * sizeof (Elf64_External_Rela);
5756 if ((p->sec->output_section->flags & SEC_READONLY) != 0)
5757 info->flags |= DF_TEXTREL;
5758 }
5759 }
5760 }
5761
5762 lgot_ents = elf_local_got_ents (ibfd);
5763 if (!lgot_ents)
5764 continue;
5765
5766 symtab_hdr = &elf_tdata (ibfd)->symtab_hdr;
5767 locsymcount = symtab_hdr->sh_info;
5768 end_lgot_ents = lgot_ents + locsymcount;
5769 lgot_masks = (char *) end_lgot_ents;
5770 s = htab->sgot;
5771 srel = htab->srelgot;
5772 for (; lgot_ents < end_lgot_ents; ++lgot_ents, ++lgot_masks)
5773 {
5774 struct got_entry *ent;
5775
5776 for (ent = *lgot_ents; ent != NULL; ent = ent->next)
5777 if (ent->got.refcount > 0)
5778 {
5779 if ((ent->tls_type & *lgot_masks & TLS_LD) != 0)
5780 {
5781 if (htab->tlsld_got.offset == (bfd_vma) -1)
5782 {
5783 htab->tlsld_got.offset = s->_raw_size;
5784 s->_raw_size += 16;
5785 if (info->shared)
5786 srel->_raw_size += sizeof (Elf64_External_Rela);
5787 }
5788 ent->got.offset = htab->tlsld_got.offset;
5789 }
5790 else
5791 {
5792 ent->got.offset = s->_raw_size;
5793 if ((ent->tls_type & *lgot_masks & TLS_GD) != 0)
5794 {
5795 s->_raw_size += 16;
5796 if (info->shared)
5797 srel->_raw_size += 2 * sizeof (Elf64_External_Rela);
5798 }
5799 else
5800 {
5801 s->_raw_size += 8;
5802 if (info->shared)
5803 srel->_raw_size += sizeof (Elf64_External_Rela);
5804 }
5805 }
5806 }
5807 else
5808 ent->got.offset = (bfd_vma) -1;
5809 }
5810 }
5811
5812 /* Allocate global sym .plt and .got entries, and space for global
5813 sym dynamic relocs. */
5814 elf_link_hash_traverse (&htab->elf, allocate_dynrelocs, (PTR) info);
5815
5816 /* We now have determined the sizes of the various dynamic sections.
5817 Allocate memory for them. */
5818 relocs = FALSE;
5819 for (s = dynobj->sections; s != NULL; s = s->next)
5820 {
5821 if ((s->flags & SEC_LINKER_CREATED) == 0)
5822 continue;
5823
5824 /* Reset _cooked_size since prelim layout will set it wrongly,
5825 and a non-zero _cooked_size sticks. */
5826 s->_cooked_size = 0;
5827
5828 if (s == htab->sbrlt || s == htab->srelbrlt)
5829 /* These haven't been allocated yet; don't strip. */
5830 continue;
5831 else if (s == htab->splt
5832 || s == htab->sgot
5833 || s == htab->sglink)
5834 {
5835 /* Strip this section if we don't need it; see the
5836 comment below. */
5837 }
5838 else if (strncmp (bfd_get_section_name (dynobj, s), ".rela", 5) == 0)
5839 {
5840 if (s->_raw_size == 0)
5841 {
5842 /* If we don't need this section, strip it from the
5843 output file. This is mostly to handle .rela.bss and
5844 .rela.plt. We must create both sections in
5845 create_dynamic_sections, because they must be created
5846 before the linker maps input sections to output
5847 sections. The linker does that before
5848 adjust_dynamic_symbol is called, and it is that
5849 function which decides whether anything needs to go
5850 into these sections. */
5851 }
5852 else
5853 {
5854 if (s != htab->srelplt)
5855 relocs = TRUE;
5856
5857 /* We use the reloc_count field as a counter if we need
5858 to copy relocs into the output file. */
5859 s->reloc_count = 0;
5860 }
5861 }
5862 else
5863 {
5864 /* It's not one of our sections, so don't allocate space. */
5865 continue;
5866 }
5867
5868 if (s->_raw_size == 0)
5869 {
5870 _bfd_strip_section_from_output (info, s);
5871 continue;
5872 }
5873
5874 /* .plt is in the bss section. We don't initialise it. */
5875 if ((s->flags & SEC_LOAD) == 0)
5876 continue;
5877
5878 /* Allocate memory for the section contents. We use bfd_zalloc
5879 here in case unused entries are not reclaimed before the
5880 section's contents are written out. This should not happen,
5881 but this way if it does we get a R_PPC64_NONE reloc in .rela
5882 sections instead of garbage.
5883 We also rely on the section contents being zero when writing
5884 the GOT. */
5885 s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->_raw_size);
5886 if (s->contents == NULL)
5887 return FALSE;
5888 }
5889
5890 if (htab->elf.dynamic_sections_created)
5891 {
5892 /* Add some entries to the .dynamic section. We fill in the
5893 values later, in ppc64_elf_finish_dynamic_sections, but we
5894 must add the entries now so that we get the correct size for
5895 the .dynamic section. The DT_DEBUG entry is filled in by the
5896 dynamic linker and used by the debugger. */
5897 #define add_dynamic_entry(TAG, VAL) \
5898 bfd_elf64_add_dynamic_entry (info, (bfd_vma) (TAG), (bfd_vma) (VAL))
5899
5900 if (!info->shared)
5901 {
5902 if (!add_dynamic_entry (DT_DEBUG, 0))
5903 return FALSE;
5904 }
5905
5906 if (htab->splt != NULL && htab->splt->_raw_size != 0)
5907 {
5908 if (!add_dynamic_entry (DT_PLTGOT, 0)
5909 || !add_dynamic_entry (DT_PLTRELSZ, 0)
5910 || !add_dynamic_entry (DT_PLTREL, DT_RELA)
5911 || !add_dynamic_entry (DT_JMPREL, 0)
5912 || !add_dynamic_entry (DT_PPC64_GLINK, 0))
5913 return FALSE;
5914 }
5915
5916 if (NO_OPD_RELOCS)
5917 {
5918 if (!add_dynamic_entry (DT_PPC64_OPD, 0)
5919 || !add_dynamic_entry (DT_PPC64_OPDSZ, 0))
5920 return FALSE;
5921 }
5922
5923 if (relocs)
5924 {
5925 if (!add_dynamic_entry (DT_RELA, 0)
5926 || !add_dynamic_entry (DT_RELASZ, 0)
5927 || !add_dynamic_entry (DT_RELAENT, sizeof (Elf64_External_Rela)))
5928 return FALSE;
5929
5930 /* If any dynamic relocs apply to a read-only section,
5931 then we need a DT_TEXTREL entry. */
5932 if ((info->flags & DF_TEXTREL) == 0)
5933 elf_link_hash_traverse (&htab->elf, readonly_dynrelocs,
5934 (PTR) info);
5935
5936 if ((info->flags & DF_TEXTREL) != 0)
5937 {
5938 if (!add_dynamic_entry (DT_TEXTREL, 0))
5939 return FALSE;
5940 }
5941 }
5942 }
5943 #undef add_dynamic_entry
5944
5945 return TRUE;
5946 }
5947
5948 /* Determine the type of stub needed, if any, for a call. */
5949
5950 static INLINE enum ppc_stub_type
5951 ppc_type_of_stub (input_sec, rel, hash, destination)
5952 asection *input_sec;
5953 const Elf_Internal_Rela *rel;
5954 struct ppc_link_hash_entry **hash;
5955 bfd_vma destination;
5956 {
5957 struct ppc_link_hash_entry *h = *hash;
5958 bfd_vma location;
5959 bfd_vma branch_offset;
5960 bfd_vma max_branch_offset;
5961 unsigned int r_type;
5962
5963 if (h != NULL)
5964 {
5965 if (h->oh != NULL
5966 && h->oh->dynindx != -1)
5967 {
5968 struct plt_entry *ent;
5969 for (ent = h->oh->plt.plist; ent != NULL; ent = ent->next)
5970 if (ent->addend == rel->r_addend
5971 && ent->plt.offset != (bfd_vma) -1)
5972 {
5973 *hash = (struct ppc_link_hash_entry *) h->oh;
5974 return ppc_stub_plt_call;
5975 }
5976 }
5977
5978 if (h->elf.root.type == bfd_link_hash_undefweak
5979 || h->elf.root.type == bfd_link_hash_undefined)
5980 return ppc_stub_none;
5981 }
5982
5983 /* Determine where the call point is. */
5984 location = (input_sec->output_offset
5985 + input_sec->output_section->vma
5986 + rel->r_offset);
5987
5988 branch_offset = destination - location;
5989 r_type = ELF64_R_TYPE (rel->r_info);
5990
5991 /* Determine if a long branch stub is needed. */
5992 max_branch_offset = 1 << 25;
5993 if (r_type != (unsigned int) R_PPC64_REL24)
5994 max_branch_offset = 1 << 15;
5995
5996 if (branch_offset + max_branch_offset >= 2 * max_branch_offset)
5997 /* We need a stub. Figure out whether a long_branch or plt_branch
5998 is needed later. */
5999 return ppc_stub_long_branch;
6000
6001 return ppc_stub_none;
6002 }
6003
6004 /* Build a .plt call stub. */
6005
6006 static bfd_byte *
6007 build_plt_stub (obfd, p, offset, glink)
6008 bfd *obfd;
6009 bfd_byte *p;
6010 int offset;
6011 int glink;
6012 {
6013 #define PPC_LO(v) ((v) & 0xffff)
6014 #define PPC_HI(v) (((v) >> 16) & 0xffff)
6015 #define PPC_HA(v) PPC_HI ((v) + 0x8000)
6016
6017 if (glink)
6018 bfd_put_32 (obfd, LD_R2_40R1, p), p += 4;
6019 bfd_put_32 (obfd, ADDIS_R12_R2 | PPC_HA (offset), p), p += 4;
6020 if (!glink)
6021 bfd_put_32 (obfd, STD_R2_40R1, p), p += 4;
6022 bfd_put_32 (obfd, LD_R11_0R12 | PPC_LO (offset), p), p += 4;
6023 if (PPC_HA (offset + 8) != PPC_HA (offset))
6024 bfd_put_32 (obfd, ADDIS_R12_R12_1, p), p += 4;
6025 offset += 8;
6026 bfd_put_32 (obfd, LD_R2_0R12 | PPC_LO (offset), p), p += 4;
6027 if (PPC_HA (offset + 8) != PPC_HA (offset))
6028 bfd_put_32 (obfd, ADDIS_R12_R12_1, p), p += 4;
6029 offset += 8;
6030 bfd_put_32 (obfd, MTCTR_R11, p), p += 4;
6031 bfd_put_32 (obfd, LD_R11_0R12 | PPC_LO (offset), p), p += 4;
6032 bfd_put_32 (obfd, BCTR, p), p += 4;
6033 return p;
6034 }
6035
6036 static bfd_boolean
6037 ppc_build_one_stub (gen_entry, in_arg)
6038 struct bfd_hash_entry *gen_entry;
6039 PTR in_arg;
6040 {
6041 struct ppc_stub_hash_entry *stub_entry;
6042 struct ppc_branch_hash_entry *br_entry;
6043 struct bfd_link_info *info;
6044 struct ppc_link_hash_table *htab;
6045 asection *stub_sec;
6046 bfd *stub_bfd;
6047 bfd_byte *loc;
6048 bfd_byte *p;
6049 unsigned int indx;
6050 struct plt_entry *ent;
6051 bfd_vma off;
6052 int size;
6053
6054 /* Massage our args to the form they really have. */
6055 stub_entry = (struct ppc_stub_hash_entry *) gen_entry;
6056 info = (struct bfd_link_info *) in_arg;
6057
6058 htab = ppc_hash_table (info);
6059 stub_sec = stub_entry->stub_sec;
6060
6061 /* Make a note of the offset within the stubs for this entry. */
6062 stub_entry->stub_offset = stub_sec->_cooked_size;
6063 loc = stub_sec->contents + stub_entry->stub_offset;
6064
6065 stub_bfd = stub_sec->owner;
6066
6067 switch (stub_entry->stub_type)
6068 {
6069 case ppc_stub_long_branch:
6070 /* Branches are relative. This is where we are going to. */
6071 off = (stub_entry->target_value
6072 + stub_entry->target_section->output_offset
6073 + stub_entry->target_section->output_section->vma);
6074
6075 /* And this is where we are coming from. */
6076 off -= (stub_entry->stub_offset
6077 + stub_sec->output_offset
6078 + stub_sec->output_section->vma);
6079
6080 BFD_ASSERT (off + (1 << 25) < (bfd_vma) (1 << 26));
6081
6082 bfd_put_32 (stub_bfd, (bfd_vma) B_DOT | (off & 0x3fffffc), loc);
6083 size = 4;
6084 break;
6085
6086 case ppc_stub_plt_branch:
6087 br_entry = ppc_branch_hash_lookup (&htab->branch_hash_table,
6088 stub_entry->root.string + 9,
6089 FALSE, FALSE);
6090 if (br_entry == NULL)
6091 {
6092 (*_bfd_error_handler) (_("can't find branch stub `%s'"),
6093 stub_entry->root.string + 9);
6094 htab->stub_error = TRUE;
6095 return FALSE;
6096 }
6097
6098 off = (stub_entry->target_value
6099 + stub_entry->target_section->output_offset
6100 + stub_entry->target_section->output_section->vma);
6101
6102 bfd_put_64 (htab->sbrlt->owner, off,
6103 htab->sbrlt->contents + br_entry->offset);
6104
6105 if (info->shared)
6106 {
6107 /* Create a reloc for the branch lookup table entry. */
6108 Elf_Internal_Rela rela;
6109 bfd_byte *loc;
6110
6111 rela.r_offset = (br_entry->offset
6112 + htab->sbrlt->output_offset
6113 + htab->sbrlt->output_section->vma);
6114 rela.r_info = ELF64_R_INFO (0, R_PPC64_RELATIVE);
6115 rela.r_addend = off;
6116
6117 loc = htab->srelbrlt->contents;
6118 loc += htab->srelbrlt->reloc_count++ * sizeof (Elf64_External_Rela);
6119 bfd_elf64_swap_reloca_out (htab->srelbrlt->owner, &rela, loc);
6120 }
6121
6122 off = (br_entry->offset
6123 + htab->sbrlt->output_offset
6124 + htab->sbrlt->output_section->vma
6125 - elf_gp (htab->sbrlt->output_section->owner)
6126 - TOC_BASE_OFF);
6127
6128 if (off + 0x80000000 > 0xffffffff || (off & 7) != 0)
6129 {
6130 (*_bfd_error_handler)
6131 (_("linkage table error against `%s'"),
6132 stub_entry->root.string);
6133 bfd_set_error (bfd_error_bad_value);
6134 htab->stub_error = TRUE;
6135 return FALSE;
6136 }
6137
6138 indx = off;
6139 bfd_put_32 (stub_bfd, (bfd_vma) ADDIS_R12_R2 | PPC_HA (indx), loc);
6140 bfd_put_32 (stub_bfd, (bfd_vma) LD_R11_0R12 | PPC_LO (indx), loc + 4);
6141 bfd_put_32 (stub_bfd, (bfd_vma) MTCTR_R11, loc + 8);
6142 bfd_put_32 (stub_bfd, (bfd_vma) BCTR, loc + 12);
6143 size = 16;
6144 break;
6145
6146 case ppc_stub_plt_call:
6147 /* Do the best we can for shared libraries built without
6148 exporting ".foo" for each "foo". This can happen when symbol
6149 versioning scripts strip all bar a subset of symbols. */
6150 if (stub_entry->h->oh->root.type != bfd_link_hash_defined
6151 && stub_entry->h->oh->root.type != bfd_link_hash_defweak)
6152 {
6153 /* Point the symbol at the stub. There may be multiple stubs,
6154 we don't really care; The main thing is to make this sym
6155 defined somewhere. */
6156 stub_entry->h->oh->root.type = bfd_link_hash_defined;
6157 stub_entry->h->oh->root.u.def.section = stub_entry->stub_sec;
6158 stub_entry->h->oh->root.u.def.value = stub_entry->stub_offset;
6159 }
6160
6161 /* Now build the stub. */
6162 off = (bfd_vma) -1;
6163 for (ent = stub_entry->h->elf.plt.plist; ent != NULL; ent = ent->next)
6164 if (ent->addend == stub_entry->addend)
6165 {
6166 off = ent->plt.offset;
6167 break;
6168 }
6169 if (off >= (bfd_vma) -2)
6170 abort ();
6171
6172 off &= ~ (bfd_vma) 1;
6173 off += (htab->splt->output_offset
6174 + htab->splt->output_section->vma
6175 - elf_gp (htab->splt->output_section->owner)
6176 - TOC_BASE_OFF);
6177
6178 if (off + 0x80000000 > 0xffffffff || (off & 7) != 0)
6179 {
6180 (*_bfd_error_handler)
6181 (_("linkage table error against `%s'"),
6182 stub_entry->h->elf.root.root.string);
6183 bfd_set_error (bfd_error_bad_value);
6184 htab->stub_error = TRUE;
6185 return FALSE;
6186 }
6187
6188 p = build_plt_stub (stub_bfd, loc, (int) off, 0);
6189 size = p - loc;
6190 break;
6191
6192 default:
6193 BFD_FAIL ();
6194 return FALSE;
6195 }
6196
6197 stub_sec->_cooked_size += size;
6198 return TRUE;
6199 }
6200
6201 /* As above, but don't actually build the stub. Just bump offset so
6202 we know stub section sizes, and select plt_branch stubs where
6203 long_branch stubs won't do. */
6204
6205 static bfd_boolean
6206 ppc_size_one_stub (gen_entry, in_arg)
6207 struct bfd_hash_entry *gen_entry;
6208 PTR in_arg;
6209 {
6210 struct ppc_stub_hash_entry *stub_entry;
6211 struct ppc_link_hash_table *htab;
6212 bfd_vma off;
6213 int size;
6214
6215 /* Massage our args to the form they really have. */
6216 stub_entry = (struct ppc_stub_hash_entry *) gen_entry;
6217 htab = (struct ppc_link_hash_table *) in_arg;
6218
6219 if (stub_entry->stub_type == ppc_stub_plt_call)
6220 {
6221 struct plt_entry *ent;
6222 off = (bfd_vma) -1;
6223 for (ent = stub_entry->h->elf.plt.plist; ent != NULL; ent = ent->next)
6224 if (ent->addend == stub_entry->addend)
6225 {
6226 off = ent->plt.offset & ~(bfd_vma) 1;
6227 break;
6228 }
6229 if (off >= (bfd_vma) -2)
6230 abort ();
6231 off += (htab->splt->output_offset
6232 + htab->splt->output_section->vma
6233 - elf_gp (htab->splt->output_section->owner)
6234 - TOC_BASE_OFF);
6235
6236 size = 28;
6237 if (PPC_HA ((int) off + 16) != PPC_HA ((int) off))
6238 size += 4;
6239 }
6240 else
6241 {
6242 /* ppc_stub_long_branch or ppc_stub_plt_branch. */
6243 stub_entry->stub_type = ppc_stub_long_branch;
6244 size = 4;
6245
6246 off = (stub_entry->target_value
6247 + stub_entry->target_section->output_offset
6248 + stub_entry->target_section->output_section->vma);
6249 off -= (stub_entry->stub_sec->_raw_size
6250 + stub_entry->stub_sec->output_offset
6251 + stub_entry->stub_sec->output_section->vma);
6252
6253 if (off + (1 << 25) >= (bfd_vma) (1 << 26))
6254 {
6255 struct ppc_branch_hash_entry *br_entry;
6256
6257 br_entry = ppc_branch_hash_lookup (&htab->branch_hash_table,
6258 stub_entry->root.string + 9,
6259 TRUE, FALSE);
6260 if (br_entry == NULL)
6261 {
6262 (*_bfd_error_handler) (_("can't build branch stub `%s'"),
6263 stub_entry->root.string + 9);
6264 htab->stub_error = TRUE;
6265 return FALSE;
6266 }
6267
6268 if (br_entry->iter != htab->stub_iteration)
6269 {
6270 br_entry->iter = htab->stub_iteration;
6271 br_entry->offset = htab->sbrlt->_raw_size;
6272 htab->sbrlt->_raw_size += 8;
6273 }
6274 stub_entry->stub_type = ppc_stub_plt_branch;
6275 size = 16;
6276 }
6277 }
6278
6279 stub_entry->stub_sec->_raw_size += size;
6280 return TRUE;
6281 }
6282
6283 /* Set up various things so that we can make a list of input sections
6284 for each output section included in the link. Returns -1 on error,
6285 0 when no stubs will be needed, and 1 on success. */
6286
6287 int
6288 ppc64_elf_setup_section_lists (output_bfd, info)
6289 bfd *output_bfd;
6290 struct bfd_link_info *info;
6291 {
6292 bfd *input_bfd;
6293 int top_id, top_index;
6294 asection *section;
6295 asection **input_list, **list;
6296 bfd_size_type amt;
6297 struct ppc_link_hash_table *htab = ppc_hash_table (info);
6298
6299 if (htab->elf.root.creator->flavour != bfd_target_elf_flavour
6300 || htab->sbrlt == NULL)
6301 return 0;
6302
6303 /* Find the top input section id. */
6304 for (input_bfd = info->input_bfds, top_id = 0;
6305 input_bfd != NULL;
6306 input_bfd = input_bfd->link_next)
6307 {
6308 for (section = input_bfd->sections;
6309 section != NULL;
6310 section = section->next)
6311 {
6312 if (top_id < section->id)
6313 top_id = section->id;
6314 }
6315 }
6316
6317 amt = sizeof (struct map_stub) * (top_id + 1);
6318 htab->stub_group = (struct map_stub *) bfd_zmalloc (amt);
6319 if (htab->stub_group == NULL)
6320 return -1;
6321
6322 /* We can't use output_bfd->section_count here to find the top output
6323 section index as some sections may have been removed, and
6324 _bfd_strip_section_from_output doesn't renumber the indices. */
6325 for (section = output_bfd->sections, top_index = 0;
6326 section != NULL;
6327 section = section->next)
6328 {
6329 if (top_index < section->index)
6330 top_index = section->index;
6331 }
6332
6333 htab->top_index = top_index;
6334 amt = sizeof (asection *) * (top_index + 1);
6335 input_list = (asection **) bfd_malloc (amt);
6336 htab->input_list = input_list;
6337 if (input_list == NULL)
6338 return -1;
6339
6340 /* For sections we aren't interested in, mark their entries with a
6341 value we can check later. */
6342 list = input_list + top_index;
6343 do
6344 *list = bfd_abs_section_ptr;
6345 while (list-- != input_list);
6346
6347 for (section = output_bfd->sections;
6348 section != NULL;
6349 section = section->next)
6350 {
6351 if ((section->flags & SEC_CODE) != 0)
6352 input_list[section->index] = NULL;
6353 }
6354
6355 return 1;
6356 }
6357
6358 /* The linker repeatedly calls this function for each input section,
6359 in the order that input sections are linked into output sections.
6360 Build lists of input sections to determine groupings between which
6361 we may insert linker stubs. */
6362
6363 void
6364 ppc64_elf_next_input_section (info, isec)
6365 struct bfd_link_info *info;
6366 asection *isec;
6367 {
6368 struct ppc_link_hash_table *htab = ppc_hash_table (info);
6369
6370 if (isec->output_section->index <= htab->top_index)
6371 {
6372 asection **list = htab->input_list + isec->output_section->index;
6373 if (*list != bfd_abs_section_ptr)
6374 {
6375 /* Steal the link_sec pointer for our list. */
6376 #define PREV_SEC(sec) (htab->stub_group[(sec)->id].link_sec)
6377 /* This happens to make the list in reverse order,
6378 which is what we want. */
6379 PREV_SEC (isec) = *list;
6380 *list = isec;
6381 }
6382 }
6383 }
6384
6385 /* See whether we can group stub sections together. Grouping stub
6386 sections may result in fewer stubs. More importantly, we need to
6387 put all .init* and .fini* stubs at the beginning of the .init or
6388 .fini output sections respectively, because glibc splits the
6389 _init and _fini functions into multiple parts. Putting a stub in
6390 the middle of a function is not a good idea. */
6391
6392 static void
6393 group_sections (htab, stub_group_size, stubs_always_before_branch)
6394 struct ppc_link_hash_table *htab;
6395 bfd_size_type stub_group_size;
6396 bfd_boolean stubs_always_before_branch;
6397 {
6398 asection **list = htab->input_list + htab->top_index;
6399 do
6400 {
6401 asection *tail = *list;
6402 if (tail == bfd_abs_section_ptr)
6403 continue;
6404 while (tail != NULL)
6405 {
6406 asection *curr;
6407 asection *prev;
6408 bfd_size_type total;
6409 bfd_boolean big_sec;
6410
6411 curr = tail;
6412 if (tail->_cooked_size)
6413 total = tail->_cooked_size;
6414 else
6415 total = tail->_raw_size;
6416 big_sec = total >= stub_group_size;
6417
6418 while ((prev = PREV_SEC (curr)) != NULL
6419 && ((total += curr->output_offset - prev->output_offset)
6420 < stub_group_size))
6421 curr = prev;
6422
6423 /* OK, the size from the start of CURR to the end is less
6424 than stub_group_size and thus can be handled by one stub
6425 section. (or the tail section is itself larger than
6426 stub_group_size, in which case we may be toast.) We
6427 should really be keeping track of the total size of stubs
6428 added here, as stubs contribute to the final output
6429 section size. That's a little tricky, and this way will
6430 only break if stubs added make the total size more than
6431 2^25, ie. for the default stub_group_size, if stubs total
6432 more than 2097152 bytes, or nearly 75000 plt call stubs. */
6433 do
6434 {
6435 prev = PREV_SEC (tail);
6436 /* Set up this stub group. */
6437 htab->stub_group[tail->id].link_sec = curr;
6438 }
6439 while (tail != curr && (tail = prev) != NULL);
6440
6441 /* But wait, there's more! Input sections up to stub_group_size
6442 bytes before the stub section can be handled by it too.
6443 Don't do this if we have a really large section after the
6444 stubs, as adding more stubs increases the chance that
6445 branches may not reach into the stub section. */
6446 if (!stubs_always_before_branch && !big_sec)
6447 {
6448 total = 0;
6449 while (prev != NULL
6450 && ((total += tail->output_offset - prev->output_offset)
6451 < stub_group_size))
6452 {
6453 tail = prev;
6454 prev = PREV_SEC (tail);
6455 htab->stub_group[tail->id].link_sec = curr;
6456 }
6457 }
6458 tail = prev;
6459 }
6460 }
6461 while (list-- != htab->input_list);
6462 free (htab->input_list);
6463 #undef PREV_SEC
6464 }
6465
6466 /* Determine and set the size of the stub section for a final link.
6467
6468 The basic idea here is to examine all the relocations looking for
6469 PC-relative calls to a target that is unreachable with a "bl"
6470 instruction. */
6471
6472 bfd_boolean
6473 ppc64_elf_size_stubs (output_bfd, stub_bfd, info, group_size,
6474 add_stub_section, layout_sections_again)
6475 bfd *output_bfd;
6476 bfd *stub_bfd;
6477 struct bfd_link_info *info;
6478 bfd_signed_vma group_size;
6479 asection * (*add_stub_section) PARAMS ((const char *, asection *));
6480 void (*layout_sections_again) PARAMS ((void));
6481 {
6482 bfd_size_type stub_group_size;
6483 bfd_boolean stubs_always_before_branch;
6484 struct ppc_link_hash_table *htab = ppc_hash_table (info);
6485
6486 /* Stash our params away. */
6487 htab->stub_bfd = stub_bfd;
6488 htab->add_stub_section = add_stub_section;
6489 htab->layout_sections_again = layout_sections_again;
6490 stubs_always_before_branch = group_size < 0;
6491 if (group_size < 0)
6492 stub_group_size = -group_size;
6493 else
6494 stub_group_size = group_size;
6495 if (stub_group_size == 1)
6496 {
6497 /* Default values. */
6498 if (stubs_always_before_branch)
6499 {
6500 stub_group_size = 0x1e00000;
6501 if (htab->has_14bit_branch)
6502 stub_group_size = 0x7800;
6503 }
6504 else
6505 {
6506 stub_group_size = 0x1c00000;
6507 if (htab->has_14bit_branch)
6508 stub_group_size = 0x7000;
6509 }
6510 }
6511
6512 group_sections (htab, stub_group_size, stubs_always_before_branch);
6513
6514 while (1)
6515 {
6516 bfd *input_bfd;
6517 unsigned int bfd_indx;
6518 asection *stub_sec;
6519 bfd_boolean stub_changed;
6520
6521 htab->stub_iteration += 1;
6522 stub_changed = FALSE;
6523
6524 for (input_bfd = info->input_bfds, bfd_indx = 0;
6525 input_bfd != NULL;
6526 input_bfd = input_bfd->link_next, bfd_indx++)
6527 {
6528 Elf_Internal_Shdr *symtab_hdr;
6529 asection *section;
6530 Elf_Internal_Sym *local_syms = NULL;
6531
6532 /* We'll need the symbol table in a second. */
6533 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
6534 if (symtab_hdr->sh_info == 0)
6535 continue;
6536
6537 /* Walk over each section attached to the input bfd. */
6538 for (section = input_bfd->sections;
6539 section != NULL;
6540 section = section->next)
6541 {
6542 Elf_Internal_Rela *internal_relocs, *irelaend, *irela;
6543
6544 /* If there aren't any relocs, then there's nothing more
6545 to do. */
6546 if ((section->flags & SEC_RELOC) == 0
6547 || section->reloc_count == 0)
6548 continue;
6549
6550 /* If this section is a link-once section that will be
6551 discarded, then don't create any stubs. */
6552 if (section->output_section == NULL
6553 || section->output_section->owner != output_bfd)
6554 continue;
6555
6556 /* Get the relocs. */
6557 internal_relocs
6558 = _bfd_elf64_link_read_relocs (input_bfd, section, NULL,
6559 (Elf_Internal_Rela *) NULL,
6560 info->keep_memory);
6561 if (internal_relocs == NULL)
6562 goto error_ret_free_local;
6563
6564 /* Now examine each relocation. */
6565 irela = internal_relocs;
6566 irelaend = irela + section->reloc_count;
6567 for (; irela < irelaend; irela++)
6568 {
6569 unsigned int r_type, r_indx;
6570 enum ppc_stub_type stub_type;
6571 struct ppc_stub_hash_entry *stub_entry;
6572 asection *sym_sec;
6573 bfd_vma sym_value;
6574 bfd_vma destination;
6575 struct ppc_link_hash_entry *hash;
6576 struct elf_link_hash_entry *h;
6577 Elf_Internal_Sym *sym;
6578 char *stub_name;
6579 const asection *id_sec;
6580
6581 r_type = ELF64_R_TYPE (irela->r_info);
6582 r_indx = ELF64_R_SYM (irela->r_info);
6583
6584 if (r_type >= (unsigned int) R_PPC64_max)
6585 {
6586 bfd_set_error (bfd_error_bad_value);
6587 goto error_ret_free_internal;
6588 }
6589
6590 /* Only look for stubs on branch instructions. */
6591 if (r_type != (unsigned int) R_PPC64_REL24
6592 && r_type != (unsigned int) R_PPC64_REL14
6593 && r_type != (unsigned int) R_PPC64_REL14_BRTAKEN
6594 && r_type != (unsigned int) R_PPC64_REL14_BRNTAKEN)
6595 continue;
6596
6597 /* Now determine the call target, its name, value,
6598 section. */
6599 destination = 0;
6600 if (!get_sym_h (&h, &sym, &sym_sec, NULL, &local_syms,
6601 r_indx, input_bfd))
6602 goto error_ret_free_internal;
6603 hash = (struct ppc_link_hash_entry *) h;
6604
6605 if (hash == NULL)
6606 {
6607 /* It's a local symbol. */
6608 sym_value = sym->st_value;
6609 destination = (sym_value + irela->r_addend
6610 + sym_sec->output_offset
6611 + sym_sec->output_section->vma);
6612 }
6613 else
6614 {
6615 /* It's an external symbol. */
6616 sym_value = 0;
6617 if (hash->elf.root.type == bfd_link_hash_defined
6618 || hash->elf.root.type == bfd_link_hash_defweak)
6619 {
6620 sym_value = hash->elf.root.u.def.value;
6621 if (sym_sec->output_section != NULL)
6622 destination = (sym_value + irela->r_addend
6623 + sym_sec->output_offset
6624 + sym_sec->output_section->vma);
6625 }
6626 else if (hash->elf.root.type == bfd_link_hash_undefweak)
6627 ;
6628 else if (hash->elf.root.type == bfd_link_hash_undefined)
6629 ;
6630 else
6631 {
6632 bfd_set_error (bfd_error_bad_value);
6633 goto error_ret_free_internal;
6634 }
6635 }
6636
6637 /* Determine what (if any) linker stub is needed. */
6638 stub_type = ppc_type_of_stub (section, irela, &hash,
6639 destination);
6640 if (stub_type == ppc_stub_none)
6641 continue;
6642
6643 /* __tls_get_addr calls might be eliminated. */
6644 if (stub_type != ppc_stub_plt_call
6645 && hash != NULL
6646 && &hash->elf == htab->tls_get_addr
6647 && section->has_tls_reloc
6648 && irela != internal_relocs)
6649 {
6650 /* Get tls info. */
6651 char *tls_mask;
6652
6653 if (!get_tls_mask (&tls_mask, &local_syms,
6654 irela - 1, input_bfd))
6655 goto error_ret_free_internal;
6656 if (*tls_mask != 0)
6657 continue;
6658 }
6659
6660 /* Support for grouping stub sections. */
6661 id_sec = htab->stub_group[section->id].link_sec;
6662
6663 /* Get the name of this stub. */
6664 stub_name = ppc_stub_name (id_sec, sym_sec, hash, irela);
6665 if (!stub_name)
6666 goto error_ret_free_internal;
6667
6668 stub_entry = ppc_stub_hash_lookup (&htab->stub_hash_table,
6669 stub_name, FALSE, FALSE);
6670 if (stub_entry != NULL)
6671 {
6672 /* The proper stub has already been created. */
6673 free (stub_name);
6674 continue;
6675 }
6676
6677 stub_entry = ppc_add_stub (stub_name, section, htab);
6678 if (stub_entry == NULL)
6679 {
6680 free (stub_name);
6681 error_ret_free_internal:
6682 if (elf_section_data (section)->relocs == NULL)
6683 free (internal_relocs);
6684 error_ret_free_local:
6685 if (local_syms != NULL
6686 && (symtab_hdr->contents
6687 != (unsigned char *) local_syms))
6688 free (local_syms);
6689 return FALSE;
6690 }
6691
6692 stub_entry->target_value = sym_value;
6693 stub_entry->target_section = sym_sec;
6694 stub_entry->stub_type = stub_type;
6695 stub_entry->h = hash;
6696 stub_entry->addend = irela->r_addend;
6697 stub_changed = TRUE;
6698 }
6699
6700 /* We're done with the internal relocs, free them. */
6701 if (elf_section_data (section)->relocs != internal_relocs)
6702 free (internal_relocs);
6703 }
6704
6705 if (local_syms != NULL
6706 && symtab_hdr->contents != (unsigned char *) local_syms)
6707 {
6708 if (!info->keep_memory)
6709 free (local_syms);
6710 else
6711 symtab_hdr->contents = (unsigned char *) local_syms;
6712 }
6713 }
6714
6715 if (!stub_changed)
6716 break;
6717
6718 /* OK, we've added some stubs. Find out the new size of the
6719 stub sections. */
6720 for (stub_sec = htab->stub_bfd->sections;
6721 stub_sec != NULL;
6722 stub_sec = stub_sec->next)
6723 {
6724 stub_sec->_raw_size = 0;
6725 stub_sec->_cooked_size = 0;
6726 }
6727 htab->sbrlt->_raw_size = 0;
6728 htab->sbrlt->_cooked_size = 0;
6729
6730 bfd_hash_traverse (&htab->stub_hash_table, ppc_size_one_stub, htab);
6731
6732 /* Ask the linker to do its stuff. */
6733 (*htab->layout_sections_again) ();
6734 }
6735
6736 /* It would be nice to strip .branch_lt from the output if the
6737 section is empty, but it's too late. If we strip sections here,
6738 the dynamic symbol table is corrupted since the section symbol
6739 for the stripped section isn't written. */
6740
6741 return TRUE;
6742 }
6743
6744 /* Called after we have determined section placement. If sections
6745 move, we'll be called again. Provide a value for TOCstart. */
6746
6747 bfd_vma
6748 ppc64_elf_toc (obfd)
6749 bfd *obfd;
6750 {
6751 asection *s;
6752 bfd_vma TOCstart;
6753
6754 /* The TOC consists of sections .got, .toc, .tocbss, .plt in that
6755 order. The TOC starts where the first of these sections starts. */
6756 s = bfd_get_section_by_name (obfd, ".got");
6757 if (s == NULL)
6758 s = bfd_get_section_by_name (obfd, ".toc");
6759 if (s == NULL)
6760 s = bfd_get_section_by_name (obfd, ".tocbss");
6761 if (s == NULL)
6762 s = bfd_get_section_by_name (obfd, ".plt");
6763 if (s == NULL)
6764 {
6765 /* This may happen for
6766 o references to TOC base (SYM@toc / TOC[tc0]) without a
6767 .toc directive
6768 o bad linker script
6769 o --gc-sections and empty TOC sections
6770
6771 FIXME: Warn user? */
6772
6773 /* Look for a likely section. We probably won't even be
6774 using TOCstart. */
6775 for (s = obfd->sections; s != NULL; s = s->next)
6776 if ((s->flags & (SEC_ALLOC | SEC_SMALL_DATA | SEC_READONLY))
6777 == (SEC_ALLOC | SEC_SMALL_DATA))
6778 break;
6779 if (s == NULL)
6780 for (s = obfd->sections; s != NULL; s = s->next)
6781 if ((s->flags & (SEC_ALLOC | SEC_SMALL_DATA))
6782 == (SEC_ALLOC | SEC_SMALL_DATA))
6783 break;
6784 if (s == NULL)
6785 for (s = obfd->sections; s != NULL; s = s->next)
6786 if ((s->flags & (SEC_ALLOC | SEC_READONLY)) == SEC_ALLOC)
6787 break;
6788 if (s == NULL)
6789 for (s = obfd->sections; s != NULL; s = s->next)
6790 if ((s->flags & SEC_ALLOC) == SEC_ALLOC)
6791 break;
6792 }
6793
6794 TOCstart = 0;
6795 if (s != NULL)
6796 TOCstart = s->output_section->vma + s->output_offset;
6797
6798 return TOCstart;
6799 }
6800
6801 /* Build all the stubs associated with the current output file.
6802 The stubs are kept in a hash table attached to the main linker
6803 hash table. This function is called via gldelf64ppc_finish. */
6804
6805 bfd_boolean
6806 ppc64_elf_build_stubs (info)
6807 struct bfd_link_info *info;
6808 {
6809 struct ppc_link_hash_table *htab = ppc_hash_table (info);
6810 asection *stub_sec;
6811 bfd_vma plt_r2;
6812 bfd_byte *p;
6813
6814 for (stub_sec = htab->stub_bfd->sections;
6815 stub_sec != NULL;
6816 stub_sec = stub_sec->next)
6817 {
6818 bfd_size_type size;
6819
6820 /* Allocate memory to hold the linker stubs. */
6821 size = stub_sec->_raw_size;
6822 if (size != 0)
6823 {
6824 stub_sec->contents = (bfd_byte *) bfd_zalloc (htab->stub_bfd, size);
6825 if (stub_sec->contents == NULL)
6826 return FALSE;
6827 }
6828 stub_sec->_cooked_size = 0;
6829 }
6830
6831 if (htab->splt != NULL)
6832 {
6833 unsigned int indx;
6834
6835 /* Build the .glink plt call stub. */
6836 plt_r2 = (htab->splt->output_offset
6837 + htab->splt->output_section->vma
6838 - elf_gp (htab->splt->output_section->owner)
6839 - TOC_BASE_OFF);
6840 p = htab->sglink->contents;
6841 p = build_plt_stub (htab->sglink->owner, p, (int) plt_r2, 1);
6842 while (p < htab->sglink->contents + GLINK_CALL_STUB_SIZE)
6843 {
6844 bfd_put_32 (htab->sglink->owner, NOP, p);
6845 p += 4;
6846 }
6847
6848 /* Build the .glink lazy link call stubs. */
6849 indx = 0;
6850 while (p < htab->sglink->contents + htab->sglink->_raw_size)
6851 {
6852 if (indx < 0x8000)
6853 {
6854 bfd_put_32 (htab->sglink->owner, LI_R0_0 | indx, p);
6855 p += 4;
6856 }
6857 else
6858 {
6859 bfd_put_32 (htab->sglink->owner, LIS_R0_0 | PPC_HI (indx), p);
6860 p += 4;
6861 bfd_put_32 (htab->sglink->owner, ORI_R0_R0_0 | PPC_LO (indx), p);
6862 p += 4;
6863 }
6864 bfd_put_32 (htab->sglink->owner,
6865 B_DOT | ((htab->sglink->contents - p) & 0x3fffffc), p);
6866 indx++;
6867 p += 4;
6868 }
6869 htab->sglink->_cooked_size = p - htab->sglink->contents;
6870 }
6871
6872 if (htab->sbrlt->_raw_size != 0)
6873 {
6874 htab->sbrlt->contents = (bfd_byte *) bfd_zalloc (htab->sbrlt->owner,
6875 htab->sbrlt->_raw_size);
6876 if (htab->sbrlt->contents == NULL)
6877 return FALSE;
6878 }
6879
6880 /* Build the stubs as directed by the stub hash table. */
6881 bfd_hash_traverse (&htab->stub_hash_table, ppc_build_one_stub, info);
6882
6883 for (stub_sec = htab->stub_bfd->sections;
6884 stub_sec != NULL;
6885 stub_sec = stub_sec->next)
6886 {
6887 if (stub_sec->_raw_size != stub_sec->_cooked_size)
6888 break;
6889 }
6890
6891 if (stub_sec != NULL
6892 || htab->sglink->_raw_size != htab->sglink->_cooked_size)
6893 {
6894 htab->stub_error = TRUE;
6895 (*_bfd_error_handler) (_("stubs don't match calculated size"));
6896 }
6897
6898 return !htab->stub_error;
6899 }
6900
6901 /* The RELOCATE_SECTION function is called by the ELF backend linker
6902 to handle the relocations for a section.
6903
6904 The relocs are always passed as Rela structures; if the section
6905 actually uses Rel structures, the r_addend field will always be
6906 zero.
6907
6908 This function is responsible for adjust the section contents as
6909 necessary, and (if using Rela relocs and generating a
6910 relocateable output file) adjusting the reloc addend as
6911 necessary.
6912
6913 This function does not have to worry about setting the reloc
6914 address or the reloc symbol index.
6915
6916 LOCAL_SYMS is a pointer to the swapped in local symbols.
6917
6918 LOCAL_SECTIONS is an array giving the section in the input file
6919 corresponding to the st_shndx field of each local symbol.
6920
6921 The global hash table entry for the global symbols can be found
6922 via elf_sym_hashes (input_bfd).
6923
6924 When generating relocateable output, this function must handle
6925 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
6926 going to be the section symbol corresponding to the output
6927 section, which means that the addend must be adjusted
6928 accordingly. */
6929
6930 static bfd_boolean
6931 ppc64_elf_relocate_section (output_bfd, info, input_bfd, input_section,
6932 contents, relocs, local_syms, local_sections)
6933 bfd *output_bfd;
6934 struct bfd_link_info *info;
6935 bfd *input_bfd;
6936 asection *input_section;
6937 bfd_byte *contents;
6938 Elf_Internal_Rela *relocs;
6939 Elf_Internal_Sym *local_syms;
6940 asection **local_sections;
6941 {
6942 struct ppc_link_hash_table *htab;
6943 Elf_Internal_Shdr *symtab_hdr;
6944 struct elf_link_hash_entry **sym_hashes;
6945 Elf_Internal_Rela *rel;
6946 Elf_Internal_Rela *relend;
6947 Elf_Internal_Rela outrel;
6948 bfd_byte *loc;
6949 struct got_entry **local_got_ents;
6950 bfd_vma TOCstart;
6951 bfd_boolean ret = TRUE;
6952 bfd_boolean is_opd;
6953 /* Disabled until we sort out how ld should choose 'y' vs 'at'. */
6954 bfd_boolean is_power4 = FALSE;
6955
6956 if (info->relocateable)
6957 return TRUE;
6958
6959 /* Initialize howto table if needed. */
6960 if (!ppc64_elf_howto_table[R_PPC64_ADDR32])
6961 ppc_howto_init ();
6962
6963 htab = ppc_hash_table (info);
6964 if ((htab->tlsld_got.offset & 1) == 0)
6965 {
6966 if (info->shared)
6967 {
6968 outrel.r_offset = (htab->sgot->output_section->vma
6969 + htab->sgot->output_offset
6970 + htab->tlsld_got.offset);
6971 outrel.r_info = ELF64_R_INFO (0, R_PPC64_DTPMOD64);
6972 outrel.r_addend = 0;
6973
6974 loc = htab->srelgot->contents;
6975 loc += htab->srelgot->reloc_count++ * sizeof (Elf64_External_Rela);
6976 bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc);
6977 }
6978 else
6979 bfd_put_64 (output_bfd, (bfd_vma) 1,
6980 htab->sgot->contents + htab->tlsld_got.offset);
6981
6982 htab->tlsld_got.offset |= 1;
6983 }
6984 local_got_ents = elf_local_got_ents (input_bfd);
6985 TOCstart = elf_gp (output_bfd);
6986 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
6987 sym_hashes = elf_sym_hashes (input_bfd);
6988 is_opd = ppc64_elf_section_data (input_section)->opd.adjust != NULL;
6989
6990 rel = relocs;
6991 relend = relocs + input_section->reloc_count;
6992 for (; rel < relend; rel++)
6993 {
6994 enum elf_ppc64_reloc_type r_type;
6995 bfd_vma addend;
6996 bfd_reloc_status_type r;
6997 Elf_Internal_Sym *sym;
6998 asection *sec;
6999 struct elf_link_hash_entry *h;
7000 struct elf_link_hash_entry *fdh;
7001 const char *sym_name;
7002 unsigned long r_symndx;
7003 char tls_mask, tls_gd, tls_type;
7004 bfd_vma relocation;
7005 bfd_boolean unresolved_reloc;
7006 bfd_boolean warned;
7007 long insn;
7008 struct ppc_stub_hash_entry *stub_entry;
7009 bfd_vma max_br_offset;
7010 bfd_vma from;
7011
7012 r_type = (enum elf_ppc64_reloc_type) ELF64_R_TYPE (rel->r_info);
7013 r_symndx = ELF64_R_SYM (rel->r_info);
7014 r = bfd_reloc_other;
7015 sym = (Elf_Internal_Sym *) 0;
7016 sec = (asection *) 0;
7017 h = (struct elf_link_hash_entry *) 0;
7018 sym_name = (const char *) 0;
7019 unresolved_reloc = FALSE;
7020 warned = FALSE;
7021
7022 if (r_type == R_PPC64_TOC)
7023 {
7024 /* Relocation value is TOC base. Symbol is ignored. */
7025 relocation = TOCstart + TOC_BASE_OFF;
7026 }
7027 else if (r_symndx < symtab_hdr->sh_info)
7028 {
7029 /* It's a local symbol. */
7030 sym = local_syms + r_symndx;
7031 sec = local_sections[r_symndx];
7032 sym_name = bfd_elf_local_sym_name (input_bfd, sym);
7033 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, sec, rel);
7034 if (elf_section_data (sec) != NULL)
7035 {
7036 long *opd_sym_adjust;
7037
7038 opd_sym_adjust = ppc64_elf_section_data (sec)->opd.adjust;
7039 if (opd_sym_adjust != NULL && sym->st_value % 24 == 0)
7040 relocation += opd_sym_adjust[sym->st_value / 24];
7041 }
7042 }
7043 else
7044 {
7045 /* It's a global symbol. */
7046 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
7047 while (h->root.type == bfd_link_hash_indirect
7048 || h->root.type == bfd_link_hash_warning)
7049 h = (struct elf_link_hash_entry *) h->root.u.i.link;
7050 sym_name = h->root.root.string;
7051 relocation = 0;
7052 if (h->root.type == bfd_link_hash_defined
7053 || h->root.type == bfd_link_hash_defweak)
7054 {
7055 sec = h->root.u.def.section;
7056 if (sec->output_section == NULL)
7057 /* Set a flag that will be cleared later if we find a
7058 relocation value for this symbol. output_section
7059 is typically NULL for symbols satisfied by a shared
7060 library. */
7061 unresolved_reloc = TRUE;
7062 else
7063 relocation = (h->root.u.def.value
7064 + sec->output_section->vma
7065 + sec->output_offset);
7066 }
7067 else if (h->root.type == bfd_link_hash_undefweak)
7068 ;
7069 else if (info->shared
7070 && !info->no_undefined
7071 && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
7072 ;
7073 else
7074 {
7075 if (! ((*info->callbacks->undefined_symbol)
7076 (info, h->root.root.string, input_bfd, input_section,
7077 rel->r_offset, (!info->shared
7078 || info->no_undefined
7079 || ELF_ST_VISIBILITY (h->other)))))
7080 return FALSE;
7081 warned = TRUE;
7082 }
7083 }
7084
7085 /* TLS optimizations. Replace instruction sequences and relocs
7086 based on information we collected in tls_optimize. We edit
7087 RELOCS so that --emit-relocs will output something sensible
7088 for the final instruction stream. */
7089 tls_mask = 0;
7090 tls_gd = 0;
7091 if (IS_TLS_RELOC (r_type))
7092 {
7093 if (h != NULL)
7094 tls_mask = ((struct ppc_link_hash_entry *) h)->tls_mask;
7095 else if (local_got_ents != NULL)
7096 {
7097 char *lgot_masks;
7098 lgot_masks = (char *) (local_got_ents + symtab_hdr->sh_info);
7099 tls_mask = lgot_masks[r_symndx];
7100 }
7101 }
7102
7103 /* Ensure reloc mapping code below stays sane. */
7104 if (R_PPC64_TOC16_LO_DS != R_PPC64_TOC16_DS + 1
7105 || R_PPC64_TOC16_LO != R_PPC64_TOC16 + 1
7106 || (R_PPC64_GOT_TLSLD16 & 3) != (R_PPC64_GOT_TLSGD16 & 3)
7107 || (R_PPC64_GOT_TLSLD16_LO & 3) != (R_PPC64_GOT_TLSGD16_LO & 3)
7108 || (R_PPC64_GOT_TLSLD16_HI & 3) != (R_PPC64_GOT_TLSGD16_HI & 3)
7109 || (R_PPC64_GOT_TLSLD16_HA & 3) != (R_PPC64_GOT_TLSGD16_HA & 3)
7110 || (R_PPC64_GOT_TLSLD16 & 3) != (R_PPC64_GOT_TPREL16_DS & 3)
7111 || (R_PPC64_GOT_TLSLD16_LO & 3) != (R_PPC64_GOT_TPREL16_LO_DS & 3)
7112 || (R_PPC64_GOT_TLSLD16_HI & 3) != (R_PPC64_GOT_TPREL16_HI & 3)
7113 || (R_PPC64_GOT_TLSLD16_HA & 3) != (R_PPC64_GOT_TPREL16_HA & 3))
7114 abort ();
7115 switch (r_type)
7116 {
7117 default:
7118 break;
7119
7120 case R_PPC64_TOC16:
7121 case R_PPC64_TOC16_LO:
7122 case R_PPC64_TOC16_DS:
7123 case R_PPC64_TOC16_LO_DS:
7124 {
7125 /* Check for toc tls entries. */
7126 char *toc_tls;
7127 int retval;
7128
7129 retval = get_tls_mask (&toc_tls, &local_syms, rel, input_bfd);
7130 if (retval == 0)
7131 return FALSE;
7132
7133 if (toc_tls)
7134 {
7135 tls_mask = *toc_tls;
7136 if (r_type == R_PPC64_TOC16_DS
7137 || r_type == R_PPC64_TOC16_LO_DS)
7138 goto toctprel;
7139 else
7140 {
7141 /* If we found a GD reloc pair, then we might be
7142 doing a GD->IE transition. */
7143 if (retval == 2)
7144 {
7145 tls_gd = TLS_TPRELGD;
7146 if (tls_mask != 0 && (tls_mask & TLS_GD) == 0)
7147 goto tls_get_addr_check;
7148 }
7149 else if (retval == 3)
7150 {
7151 if (tls_mask != 0 && (tls_mask & TLS_LD) == 0)
7152 goto tls_get_addr_check;
7153 }
7154 }
7155 }
7156 }
7157 break;
7158
7159 case R_PPC64_GOT_TPREL16_DS:
7160 case R_PPC64_GOT_TPREL16_LO_DS:
7161 toctprel:
7162 if (tls_mask != 0
7163 && (tls_mask & TLS_TPREL) == 0)
7164 {
7165 bfd_vma insn;
7166 insn = bfd_get_32 (output_bfd, contents + rel->r_offset - 2);
7167 insn &= 31 << 21;
7168 insn |= 0x3c0d0000; /* addis 0,13,0 */
7169 bfd_put_32 (output_bfd, insn, contents + rel->r_offset - 2);
7170 r_type = R_PPC64_TPREL16_HA;
7171 rel->r_info = ELF64_R_INFO (r_symndx, r_type);
7172 }
7173 break;
7174
7175 case R_PPC64_TLS:
7176 if (tls_mask == 0)
7177 {
7178 /* Check for toc tls entries. */
7179 char *toc_tls;
7180
7181 if (!get_tls_mask (&toc_tls, &local_syms, rel, input_bfd))
7182 return FALSE;
7183
7184 if (toc_tls)
7185 tls_mask = *toc_tls;
7186 }
7187 if (tls_mask != 0
7188 && (tls_mask & TLS_TPREL) == 0)
7189 {
7190 bfd_vma insn, rtra;
7191 insn = bfd_get_32 (output_bfd, contents + rel->r_offset);
7192 if ((insn & ((31 << 26) | (31 << 11)))
7193 == ((31 << 26) | (13 << 11)))
7194 rtra = insn & ((1 << 26) - (1 << 16));
7195 else if ((insn & ((31 << 26) | (31 << 16)))
7196 == ((31 << 26) | (13 << 16)))
7197 rtra = (insn & (31 << 21)) | ((insn & (31 << 11)) << 5);
7198 else
7199 abort ();
7200 if ((insn & ((1 << 11) - (1 << 1))) == 266 << 1)
7201 /* add -> addi. */
7202 insn = 14 << 26;
7203 else if ((insn & (31 << 1)) == 23 << 1
7204 && ((insn & (31 << 6)) < 14 << 6
7205 || ((insn & (31 << 6)) >= 16 << 6
7206 && (insn & (31 << 6)) < 24 << 6)))
7207 /* load and store indexed -> dform. */
7208 insn = (32 | ((insn >> 6) & 31)) << 26;
7209 else if ((insn & (31 << 1)) == 21 << 1
7210 && (insn & (0x1a << 6)) == 0)
7211 /* ldx, ldux, stdx, stdux -> ld, ldu, std, stdu. */
7212 insn = (((58 | ((insn >> 6) & 4)) << 26)
7213 | ((insn >> 6) & 1));
7214 else if ((insn & (31 << 1)) == 21 << 1
7215 && (insn & ((1 << 11) - (1 << 1))) == 341 << 1)
7216 /* lwax -> lwa. */
7217 insn = (58 << 26) | 2;
7218 else
7219 abort ();
7220 insn |= rtra;
7221 bfd_put_32 (output_bfd, insn, contents + rel->r_offset);
7222 r_type = R_PPC64_TPREL16_LO;
7223 rel->r_info = ELF64_R_INFO (r_symndx, r_type);
7224 /* Was PPC64_TLS which sits on insn boundary, now
7225 PPC64_TPREL16_LO which is at insn+2. */
7226 rel->r_offset += 2;
7227 }
7228 break;
7229
7230 case R_PPC64_GOT_TLSGD16_HI:
7231 case R_PPC64_GOT_TLSGD16_HA:
7232 tls_gd = TLS_TPRELGD;
7233 if (tls_mask != 0 && (tls_mask & TLS_GD) == 0)
7234 goto tls_gdld_hi;
7235 break;
7236
7237 case R_PPC64_GOT_TLSLD16_HI:
7238 case R_PPC64_GOT_TLSLD16_HA:
7239 if (tls_mask != 0 && (tls_mask & TLS_LD) == 0)
7240 {
7241 tls_gdld_hi:
7242 if ((tls_mask & tls_gd) != 0)
7243 r_type = (((r_type - (R_PPC64_GOT_TLSGD16 & 3)) & 3)
7244 + R_PPC64_GOT_TPREL16_DS);
7245 else
7246 {
7247 bfd_put_32 (output_bfd, NOP, contents + rel->r_offset);
7248 rel->r_offset -= 2;
7249 r_type = R_PPC64_NONE;
7250 }
7251 rel->r_info = ELF64_R_INFO (r_symndx, r_type);
7252 }
7253 break;
7254
7255 case R_PPC64_GOT_TLSGD16:
7256 case R_PPC64_GOT_TLSGD16_LO:
7257 tls_gd = TLS_TPRELGD;
7258 if (tls_mask != 0 && (tls_mask & TLS_GD) == 0)
7259 goto tls_get_addr_check;
7260 break;
7261
7262 case R_PPC64_GOT_TLSLD16:
7263 case R_PPC64_GOT_TLSLD16_LO:
7264 if (tls_mask != 0 && (tls_mask & TLS_LD) == 0)
7265 {
7266 tls_get_addr_check:
7267 if (rel + 1 < relend)
7268 {
7269 enum elf_ppc64_reloc_type r_type2;
7270 unsigned long r_symndx2;
7271 struct elf_link_hash_entry *h2;
7272 bfd_vma insn1, insn2, insn3;
7273 bfd_vma offset;
7274
7275 /* The next instruction should be a call to
7276 __tls_get_addr. Peek at the reloc to be sure. */
7277 r_type2
7278 = (enum elf_ppc64_reloc_type) ELF64_R_TYPE (rel[1].r_info);
7279 r_symndx2 = ELF64_R_SYM (rel[1].r_info);
7280 if (r_symndx2 < symtab_hdr->sh_info
7281 || (r_type2 != R_PPC64_REL14
7282 && r_type2 != R_PPC64_REL14_BRTAKEN
7283 && r_type2 != R_PPC64_REL14_BRNTAKEN
7284 && r_type2 != R_PPC64_REL24))
7285 break;
7286
7287 h2 = sym_hashes[r_symndx2 - symtab_hdr->sh_info];
7288 while (h2->root.type == bfd_link_hash_indirect
7289 || h2->root.type == bfd_link_hash_warning)
7290 h2 = (struct elf_link_hash_entry *) h2->root.u.i.link;
7291 if (h2 == NULL || h2 != htab->tls_get_addr)
7292 break;
7293
7294 /* OK, it checks out. Replace the call. */
7295 offset = rel[1].r_offset;
7296 insn1 = bfd_get_32 (output_bfd,
7297 contents + rel->r_offset - 2);
7298 insn3 = bfd_get_32 (output_bfd,
7299 contents + offset + 4);
7300 if ((tls_mask & tls_gd) != 0)
7301 {
7302 /* IE */
7303 insn1 &= (1 << 26) - (1 << 2);
7304 insn1 |= 58 << 26; /* ld */
7305 insn2 = 0x7c636a14; /* add 3,3,13 */
7306 rel[1].r_info = ELF64_R_INFO (r_symndx2, R_PPC64_NONE);
7307 if ((tls_mask & TLS_EXPLICIT) == 0)
7308 r_type = (((r_type - (R_PPC64_GOT_TLSGD16 & 3)) & 3)
7309 + R_PPC64_GOT_TPREL16_DS);
7310 else
7311 r_type += R_PPC64_TOC16_DS - R_PPC64_TOC16;
7312 rel->r_info = ELF64_R_INFO (r_symndx, r_type);
7313 }
7314 else
7315 {
7316 /* LE */
7317 insn1 = 0x3c6d0000; /* addis 3,13,0 */
7318 insn2 = 0x38630000; /* addi 3,3,0 */
7319 if (tls_gd == 0)
7320 {
7321 /* Was an LD reloc. */
7322 r_symndx = 0;
7323 rel->r_addend = htab->tls_sec->vma + DTP_OFFSET;
7324 rel[1].r_addend = htab->tls_sec->vma + DTP_OFFSET;
7325 }
7326 r_type = R_PPC64_TPREL16_HA;
7327 rel->r_info = ELF64_R_INFO (r_symndx, r_type);
7328 rel[1].r_info = ELF64_R_INFO (r_symndx,
7329 R_PPC64_TPREL16_LO);
7330 rel[1].r_offset += 2;
7331 }
7332 if (insn3 == NOP
7333 || insn3 == CROR_151515 || insn3 == CROR_313131)
7334 {
7335 insn3 = insn2;
7336 insn2 = NOP;
7337 rel[1].r_offset += 4;
7338 }
7339 bfd_put_32 (output_bfd, insn1, contents + rel->r_offset - 2);
7340 bfd_put_32 (output_bfd, insn2, contents + offset);
7341 bfd_put_32 (output_bfd, insn3, contents + offset + 4);
7342 if (tls_gd == 0)
7343 {
7344 /* We changed the symbol on an LD reloc. Start over
7345 in order to get h, sym, sec etc. right. */
7346 rel--;
7347 continue;
7348 }
7349 }
7350 }
7351 break;
7352
7353 case R_PPC64_DTPMOD64:
7354 if (rel + 1 < relend
7355 && rel[1].r_info == ELF64_R_INFO (r_symndx, R_PPC64_DTPREL64)
7356 && rel[1].r_offset == rel->r_offset + 8)
7357 {
7358 if ((tls_mask & TLS_GD) == 0)
7359 {
7360 rel[1].r_info = ELF64_R_INFO (r_symndx, R_PPC64_NONE);
7361 if ((tls_mask & TLS_TPRELGD) != 0)
7362 r_type = R_PPC64_TPREL64;
7363 else
7364 {
7365 bfd_put_64 (output_bfd, (bfd_vma) 1,
7366 contents + rel->r_offset);
7367 r_type = R_PPC64_NONE;
7368 }
7369 rel->r_info = ELF64_R_INFO (r_symndx, r_type);
7370 }
7371 }
7372 else
7373 {
7374 if ((tls_mask & TLS_LD) == 0)
7375 {
7376 bfd_put_64 (output_bfd, (bfd_vma) 1,
7377 contents + rel->r_offset);
7378 r_type = R_PPC64_NONE;
7379 rel->r_info = ELF64_R_INFO (r_symndx, r_type);
7380 }
7381 }
7382 break;
7383
7384 case R_PPC64_TPREL64:
7385 if ((tls_mask & TLS_TPREL) == 0)
7386 {
7387 r_type = R_PPC64_NONE;
7388 rel->r_info = ELF64_R_INFO (r_symndx, r_type);
7389 }
7390 break;
7391 }
7392
7393 /* Handle other relocations that tweak non-addend part of insn. */
7394 insn = 0;
7395 switch (r_type)
7396 {
7397 default:
7398 break;
7399
7400 /* Branch taken prediction relocations. */
7401 case R_PPC64_ADDR14_BRTAKEN:
7402 case R_PPC64_REL14_BRTAKEN:
7403 insn = 0x01 << 21; /* 'y' or 't' bit, lowest bit of BO field. */
7404 /* Fall thru. */
7405
7406 /* Branch not taken prediction relocations. */
7407 case R_PPC64_ADDR14_BRNTAKEN:
7408 case R_PPC64_REL14_BRNTAKEN:
7409 insn |= bfd_get_32 (output_bfd,
7410 contents + rel->r_offset) & ~(0x01 << 21);
7411 if (is_power4)
7412 {
7413 /* Set 'a' bit. This is 0b00010 in BO field for branch
7414 on CR(BI) insns (BO == 001at or 011at), and 0b01000
7415 for branch on CTR insns (BO == 1a00t or 1a01t). */
7416 if ((insn & (0x14 << 21)) == (0x04 << 21))
7417 insn |= 0x02 << 21;
7418 else if ((insn & (0x14 << 21)) == (0x10 << 21))
7419 insn |= 0x08 << 21;
7420 else
7421 break;
7422 }
7423 else
7424 {
7425 from = (rel->r_offset
7426 + input_section->output_offset
7427 + input_section->output_section->vma);
7428
7429 /* Invert 'y' bit if not the default. */
7430 if ((bfd_signed_vma) (relocation + rel->r_addend - from) < 0)
7431 insn ^= 0x01 << 21;
7432 }
7433
7434 bfd_put_32 (output_bfd, (bfd_vma) insn, contents + rel->r_offset);
7435 break;
7436
7437 case R_PPC64_REL24:
7438 /* A REL24 branching to a linkage function is followed by a
7439 nop. We replace the nop with a ld in order to restore
7440 the TOC base pointer. Only calls to shared objects need
7441 to alter the TOC base. These are recognized by their
7442 need for a PLT entry. */
7443 if (h != NULL
7444 && (fdh = ((struct ppc_link_hash_entry *) h)->oh) != NULL
7445 && fdh->plt.plist != NULL
7446 && (stub_entry = ppc_get_stub_entry (input_section, sec, fdh,
7447 rel, htab)) != NULL)
7448 {
7449 bfd_boolean can_plt_call = 0;
7450
7451 if (rel->r_offset + 8 <= input_section->_cooked_size)
7452 {
7453 insn = bfd_get_32 (input_bfd, contents + rel->r_offset + 4);
7454 if (insn == NOP
7455 || insn == CROR_151515 || insn == CROR_313131)
7456 {
7457 bfd_put_32 (input_bfd, (bfd_vma) LD_R2_40R1,
7458 contents + rel->r_offset + 4);
7459 can_plt_call = 1;
7460 }
7461 }
7462
7463 if (!can_plt_call)
7464 {
7465 /* If this is a plain branch rather than a branch
7466 and link, don't require a nop. */
7467 insn = bfd_get_32 (input_bfd, contents + rel->r_offset);
7468 if ((insn & 1) == 0)
7469 can_plt_call = 1;
7470 }
7471
7472 if (can_plt_call)
7473 {
7474 relocation = (stub_entry->stub_offset
7475 + stub_entry->stub_sec->output_offset
7476 + stub_entry->stub_sec->output_section->vma);
7477 unresolved_reloc = FALSE;
7478 }
7479 }
7480
7481 if (h != NULL
7482 && h->root.type == bfd_link_hash_undefweak
7483 && relocation == 0
7484 && rel->r_addend == 0)
7485 {
7486 /* Tweak calls to undefined weak functions to point at a
7487 blr. We can thus call a weak function without first
7488 checking whether the function is defined. We have a
7489 blr at the end of .sfpr. */
7490 BFD_ASSERT (htab->sfpr->_raw_size != 0);
7491 relocation = (htab->sfpr->_raw_size - 4
7492 + htab->sfpr->output_offset
7493 + htab->sfpr->output_section->vma);
7494 from = (rel->r_offset
7495 + input_section->output_offset
7496 + input_section->output_section->vma);
7497
7498 /* But let's not be silly about it. If the blr isn't in
7499 reach, just go to the next instruction. */
7500 if (relocation - from + (1 << 25) >= (1 << 26)
7501 || htab->sfpr->_raw_size == 0)
7502 relocation = from + 4;
7503 }
7504 break;
7505 }
7506
7507 /* Set `addend'. */
7508 tls_type = 0;
7509 addend = rel->r_addend;
7510 switch (r_type)
7511 {
7512 default:
7513 (*_bfd_error_handler)
7514 (_("%s: unknown relocation type %d for symbol %s"),
7515 bfd_archive_filename (input_bfd), (int) r_type, sym_name);
7516
7517 bfd_set_error (bfd_error_bad_value);
7518 ret = FALSE;
7519 continue;
7520
7521 case R_PPC64_NONE:
7522 case R_PPC64_TLS:
7523 case R_PPC64_GNU_VTINHERIT:
7524 case R_PPC64_GNU_VTENTRY:
7525 continue;
7526
7527 /* GOT16 relocations. Like an ADDR16 using the symbol's
7528 address in the GOT as relocation value instead of the
7529 symbol's value itself. Also, create a GOT entry for the
7530 symbol and put the symbol value there. */
7531 case R_PPC64_GOT_TLSGD16:
7532 case R_PPC64_GOT_TLSGD16_LO:
7533 case R_PPC64_GOT_TLSGD16_HI:
7534 case R_PPC64_GOT_TLSGD16_HA:
7535 tls_type = TLS_TLS | TLS_GD;
7536 goto dogot;
7537
7538 case R_PPC64_GOT_TLSLD16:
7539 case R_PPC64_GOT_TLSLD16_LO:
7540 case R_PPC64_GOT_TLSLD16_HI:
7541 case R_PPC64_GOT_TLSLD16_HA:
7542 tls_type = TLS_TLS | TLS_LD;
7543 goto dogot;
7544
7545 case R_PPC64_GOT_TPREL16_DS:
7546 case R_PPC64_GOT_TPREL16_LO_DS:
7547 case R_PPC64_GOT_TPREL16_HI:
7548 case R_PPC64_GOT_TPREL16_HA:
7549 tls_type = TLS_TLS | TLS_TPREL;
7550 goto dogot;
7551
7552 case R_PPC64_GOT_DTPREL16_DS:
7553 case R_PPC64_GOT_DTPREL16_LO_DS:
7554 case R_PPC64_GOT_DTPREL16_HI:
7555 case R_PPC64_GOT_DTPREL16_HA:
7556 tls_type = TLS_TLS | TLS_DTPREL;
7557 goto dogot;
7558
7559 case R_PPC64_GOT16:
7560 case R_PPC64_GOT16_LO:
7561 case R_PPC64_GOT16_HI:
7562 case R_PPC64_GOT16_HA:
7563 case R_PPC64_GOT16_DS:
7564 case R_PPC64_GOT16_LO_DS:
7565 dogot:
7566 {
7567 /* Relocation is to the entry for this symbol in the global
7568 offset table. */
7569 struct got_entry *ent;
7570 bfd_vma off;
7571 unsigned long indx;
7572
7573 if (htab->sgot == NULL)
7574 abort ();
7575
7576 if (h != NULL)
7577 ent = h->got.glist;
7578 else
7579 {
7580 if (local_got_ents == NULL)
7581 abort ();
7582 ent = local_got_ents[r_symndx];
7583 }
7584
7585 for (; ent != NULL; ent = ent->next)
7586 if (ent->addend == rel->r_addend
7587 && ent->tls_type == tls_type)
7588 break;
7589 if (ent == NULL)
7590 abort ();
7591
7592 off = ent->got.offset;
7593 indx = 0;
7594 if (h != NULL)
7595 {
7596 bfd_boolean dyn = htab->elf.dynamic_sections_created;
7597 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info, h)
7598 || (info->shared
7599 && (info->symbolic
7600 || h->dynindx == -1
7601 || (h->elf_link_hash_flags
7602 & ELF_LINK_FORCED_LOCAL))
7603 && (h->elf_link_hash_flags
7604 & ELF_LINK_HASH_DEF_REGULAR)))
7605 /* This is actually a static link, or it is a
7606 -Bsymbolic link and the symbol is defined
7607 locally, or the symbol was forced to be local
7608 because of a version file. */
7609 ;
7610 else
7611 {
7612 indx = h->dynindx;
7613 unresolved_reloc = FALSE;
7614 }
7615 }
7616
7617 /* The offset must always be a multiple of 8. We use the
7618 least significant bit to record whether we have already
7619 processed this entry. */
7620 if ((off & 1) != 0)
7621 off &= ~1;
7622 else
7623 {
7624 /* Generate relocs for the dynamic linker, except in
7625 the case of TLSLD where we'll use one entry per
7626 module. */
7627 if ((info->shared || indx != 0)
7628 && tls_type != (TLS_TLS | TLS_LD))
7629 {
7630 outrel.r_offset = (htab->sgot->output_section->vma
7631 + htab->sgot->output_offset
7632 + off);
7633 if (tls_type == (TLS_TLS | TLS_GD))
7634 {
7635 outrel.r_info = ELF64_R_INFO (indx, R_PPC64_DTPMOD64);
7636 outrel.r_addend = 0;
7637 loc = htab->srelgot->contents;
7638 loc += (htab->srelgot->reloc_count++
7639 * sizeof (Elf64_External_Rela));
7640 bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc);
7641 outrel.r_info = ELF64_R_INFO (indx, R_PPC64_DTPREL64);
7642 outrel.r_offset += 8;
7643 }
7644 else if (tls_type == (TLS_TLS | TLS_DTPREL))
7645 outrel.r_info = ELF64_R_INFO (indx, R_PPC64_DTPREL64);
7646 else if (tls_type == (TLS_TLS | TLS_TPREL))
7647 outrel.r_info = ELF64_R_INFO (indx, R_PPC64_TPREL64);
7648 else if (indx == 0)
7649 outrel.r_info = ELF64_R_INFO (indx, R_PPC64_RELATIVE);
7650 else
7651 outrel.r_info = ELF64_R_INFO (indx, R_PPC64_GLOB_DAT);
7652 outrel.r_addend = rel->r_addend;
7653 if (indx == 0)
7654 outrel.r_addend += relocation;
7655 loc = htab->srelgot->contents;
7656 loc += (htab->srelgot->reloc_count++
7657 * sizeof (Elf64_External_Rela));
7658 bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc);
7659 }
7660
7661 /* Init the .got section contents if we're not
7662 emitting a reloc. */
7663 if (!(info->shared || indx != 0)
7664 && tls_type != (TLS_TLS | TLS_LD))
7665 {
7666 relocation += ent->addend;
7667 if (tls_type != 0)
7668 {
7669 relocation -= htab->tls_sec->vma + DTP_OFFSET;
7670 if ((tls_type & TLS_TPREL) != 0)
7671 relocation += DTP_OFFSET - TP_OFFSET;
7672 }
7673
7674 if ((tls_type & TLS_GD) != 0)
7675 {
7676 bfd_put_64 (output_bfd, relocation,
7677 htab->sgot->contents + off + 8);
7678 relocation = 1;
7679 }
7680 bfd_put_64 (output_bfd, relocation,
7681 htab->sgot->contents + off);
7682 }
7683 ent->got.offset |= 1;
7684 }
7685
7686 if (off >= (bfd_vma) -2)
7687 abort ();
7688
7689 relocation = htab->sgot->output_offset + off;
7690
7691 /* TOC base (r2) is TOC start plus 0x8000. */
7692 addend = - TOC_BASE_OFF;
7693 }
7694 break;
7695
7696 case R_PPC64_PLT16_HA:
7697 case R_PPC64_PLT16_HI:
7698 case R_PPC64_PLT16_LO:
7699 case R_PPC64_PLT32:
7700 case R_PPC64_PLT64:
7701 /* Relocation is to the entry for this symbol in the
7702 procedure linkage table. */
7703
7704 /* Resolve a PLT reloc against a local symbol directly,
7705 without using the procedure linkage table. */
7706 if (h == NULL)
7707 break;
7708
7709 /* It's possible that we didn't make a PLT entry for this
7710 symbol. This happens when statically linking PIC code,
7711 or when using -Bsymbolic. Go find a match if there is a
7712 PLT entry. */
7713 if (htab->splt != NULL)
7714 {
7715 struct plt_entry *ent;
7716 for (ent = h->plt.plist; ent != NULL; ent = ent->next)
7717 if (ent->addend == rel->r_addend
7718 && ent->plt.offset != (bfd_vma) -1)
7719 {
7720 relocation = (htab->splt->output_section->vma
7721 + htab->splt->output_offset
7722 + ent->plt.offset);
7723 unresolved_reloc = FALSE;
7724 }
7725 }
7726 break;
7727
7728 /* TOC16 relocs. We want the offset relative to the TOC base,
7729 which is the address of the start of the TOC plus 0x8000.
7730 The TOC consists of sections .got, .toc, .tocbss, and .plt,
7731 in this order. */
7732 case R_PPC64_TOC16:
7733 case R_PPC64_TOC16_LO:
7734 case R_PPC64_TOC16_HI:
7735 case R_PPC64_TOC16_DS:
7736 case R_PPC64_TOC16_LO_DS:
7737 case R_PPC64_TOC16_HA:
7738 addend -= TOCstart + TOC_BASE_OFF;
7739 break;
7740
7741 /* Relocate against the beginning of the section. */
7742 case R_PPC64_SECTOFF:
7743 case R_PPC64_SECTOFF_LO:
7744 case R_PPC64_SECTOFF_HI:
7745 case R_PPC64_SECTOFF_DS:
7746 case R_PPC64_SECTOFF_LO_DS:
7747 case R_PPC64_SECTOFF_HA:
7748 if (sec != (asection *) 0)
7749 addend -= sec->output_section->vma;
7750 break;
7751
7752 case R_PPC64_REL14:
7753 case R_PPC64_REL14_BRNTAKEN:
7754 case R_PPC64_REL14_BRTAKEN:
7755 case R_PPC64_REL24:
7756 break;
7757
7758 case R_PPC64_TPREL16:
7759 case R_PPC64_TPREL16_LO:
7760 case R_PPC64_TPREL16_HI:
7761 case R_PPC64_TPREL16_HA:
7762 case R_PPC64_TPREL16_DS:
7763 case R_PPC64_TPREL16_LO_DS:
7764 case R_PPC64_TPREL16_HIGHER:
7765 case R_PPC64_TPREL16_HIGHERA:
7766 case R_PPC64_TPREL16_HIGHEST:
7767 case R_PPC64_TPREL16_HIGHESTA:
7768 addend -= htab->tls_sec->vma + TP_OFFSET;
7769 if (info->shared)
7770 /* The TPREL16 relocs shouldn't really be used in shared
7771 libs as they will result in DT_TEXTREL being set, but
7772 support them anyway. */
7773 goto dodyn;
7774 break;
7775
7776 case R_PPC64_DTPREL16:
7777 case R_PPC64_DTPREL16_LO:
7778 case R_PPC64_DTPREL16_HI:
7779 case R_PPC64_DTPREL16_HA:
7780 case R_PPC64_DTPREL16_DS:
7781 case R_PPC64_DTPREL16_LO_DS:
7782 case R_PPC64_DTPREL16_HIGHER:
7783 case R_PPC64_DTPREL16_HIGHERA:
7784 case R_PPC64_DTPREL16_HIGHEST:
7785 case R_PPC64_DTPREL16_HIGHESTA:
7786 addend -= htab->tls_sec->vma + DTP_OFFSET;
7787 break;
7788
7789 case R_PPC64_TPREL64:
7790 addend -= htab->tls_sec->vma + TP_OFFSET;
7791 goto dodyn;
7792
7793 case R_PPC64_DTPREL64:
7794 addend -= htab->tls_sec->vma + DTP_OFFSET;
7795 /* Fall thru */
7796
7797 /* Relocations that may need to be propagated if this is a
7798 dynamic object. */
7799 case R_PPC64_DTPMOD64:
7800 case R_PPC64_REL30:
7801 case R_PPC64_REL32:
7802 case R_PPC64_REL64:
7803 case R_PPC64_ADDR14:
7804 case R_PPC64_ADDR14_BRNTAKEN:
7805 case R_PPC64_ADDR14_BRTAKEN:
7806 case R_PPC64_ADDR16:
7807 case R_PPC64_ADDR16_DS:
7808 case R_PPC64_ADDR16_HA:
7809 case R_PPC64_ADDR16_HI:
7810 case R_PPC64_ADDR16_HIGHER:
7811 case R_PPC64_ADDR16_HIGHERA:
7812 case R_PPC64_ADDR16_HIGHEST:
7813 case R_PPC64_ADDR16_HIGHESTA:
7814 case R_PPC64_ADDR16_LO:
7815 case R_PPC64_ADDR16_LO_DS:
7816 case R_PPC64_ADDR24:
7817 case R_PPC64_ADDR32:
7818 case R_PPC64_ADDR64:
7819 case R_PPC64_UADDR16:
7820 case R_PPC64_UADDR32:
7821 case R_PPC64_UADDR64:
7822 /* r_symndx will be zero only for relocs against symbols
7823 from removed linkonce sections, or sections discarded by
7824 a linker script. */
7825 dodyn:
7826 if (r_symndx == 0)
7827 break;
7828 /* Fall thru. */
7829
7830 case R_PPC64_TOC:
7831 if ((input_section->flags & SEC_ALLOC) == 0)
7832 break;
7833
7834 if (NO_OPD_RELOCS && is_opd)
7835 break;
7836
7837 if ((info->shared
7838 && (MUST_BE_DYN_RELOC (r_type)
7839 || (h != NULL
7840 && h->dynindx != -1
7841 && (! info->symbolic
7842 || (h->elf_link_hash_flags
7843 & ELF_LINK_HASH_DEF_REGULAR) == 0))))
7844 || (!info->shared
7845 && h != NULL
7846 && h->dynindx != -1
7847 && (h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0
7848 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0
7849 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0))
7850 {
7851 Elf_Internal_Rela outrel;
7852 bfd_boolean skip, relocate;
7853 asection *sreloc;
7854 bfd_byte *loc;
7855
7856 /* When generating a dynamic object, these relocations
7857 are copied into the output file to be resolved at run
7858 time. */
7859
7860 skip = FALSE;
7861 relocate = FALSE;
7862
7863 outrel.r_offset =
7864 _bfd_elf_section_offset (output_bfd, info, input_section,
7865 rel->r_offset);
7866 if (outrel.r_offset == (bfd_vma) -1)
7867 skip = TRUE;
7868 else if (outrel.r_offset == (bfd_vma) -2)
7869 skip = TRUE, relocate = TRUE;
7870 outrel.r_offset += (input_section->output_section->vma
7871 + input_section->output_offset);
7872 outrel.r_addend = rel->r_addend;
7873
7874 if (skip)
7875 memset (&outrel, 0, sizeof outrel);
7876 else if (h != NULL
7877 && h->dynindx != -1
7878 && !is_opd
7879 && (!MUST_BE_DYN_RELOC (r_type)
7880 || !info->shared
7881 || !info->symbolic
7882 || (h->elf_link_hash_flags
7883 & ELF_LINK_HASH_DEF_REGULAR) == 0))
7884 outrel.r_info = ELF64_R_INFO (h->dynindx, r_type);
7885 else
7886 {
7887 /* This symbol is local, or marked to become local,
7888 or this is an opd section reloc which must point
7889 at a local function. */
7890 outrel.r_addend += relocation;
7891 /* ??? why? */
7892 relocate = TRUE;
7893 if (r_type == R_PPC64_ADDR64 || r_type == R_PPC64_TOC)
7894 {
7895 if (is_opd && h != NULL)
7896 {
7897 /* Lie about opd entries. This case occurs
7898 when building shared libraries and we
7899 reference a function in another shared
7900 lib. The same thing happens for a weak
7901 definition in an application that's
7902 overridden by a strong definition in a
7903 shared lib. (I believe this is a generic
7904 bug in binutils handling of weak syms.)
7905 In these cases we won't use the opd
7906 entry in this lib. */
7907 unresolved_reloc = FALSE;
7908 }
7909 outrel.r_info = ELF64_R_INFO (0, R_PPC64_RELATIVE);
7910 }
7911 else
7912 {
7913 long indx = 0;
7914
7915 if (bfd_is_abs_section (sec))
7916 ;
7917 else if (sec == NULL || sec->owner == NULL)
7918 {
7919 bfd_set_error (bfd_error_bad_value);
7920 return FALSE;
7921 }
7922 else
7923 {
7924 asection *osec;
7925
7926 osec = sec->output_section;
7927 indx = elf_section_data (osec)->dynindx;
7928
7929 /* We are turning this relocation into one
7930 against a section symbol, so subtract out
7931 the output section's address but not the
7932 offset of the input section in the output
7933 section. */
7934 outrel.r_addend -= osec->vma;
7935 }
7936
7937 outrel.r_info = ELF64_R_INFO (indx, r_type);
7938 }
7939 }
7940
7941 sreloc = elf_section_data (input_section)->sreloc;
7942 if (sreloc == NULL)
7943 abort ();
7944
7945 loc = sreloc->contents;
7946 loc += sreloc->reloc_count++ * sizeof (Elf64_External_Rela);
7947 bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc);
7948
7949 /* If this reloc is against an external symbol, it will
7950 be computed at runtime, so there's no need to do
7951 anything now. */
7952 if (! relocate)
7953 continue;
7954 }
7955 break;
7956
7957 case R_PPC64_COPY:
7958 case R_PPC64_GLOB_DAT:
7959 case R_PPC64_JMP_SLOT:
7960 case R_PPC64_RELATIVE:
7961 /* We shouldn't ever see these dynamic relocs in relocatable
7962 files. */
7963 /* Fall through. */
7964
7965 case R_PPC64_PLTGOT16:
7966 case R_PPC64_PLTGOT16_DS:
7967 case R_PPC64_PLTGOT16_HA:
7968 case R_PPC64_PLTGOT16_HI:
7969 case R_PPC64_PLTGOT16_LO:
7970 case R_PPC64_PLTGOT16_LO_DS:
7971 case R_PPC64_PLTREL32:
7972 case R_PPC64_PLTREL64:
7973 /* These ones haven't been implemented yet. */
7974
7975 (*_bfd_error_handler)
7976 (_("%s: Relocation %s is not supported for symbol %s."),
7977 bfd_archive_filename (input_bfd),
7978 ppc64_elf_howto_table[(int) r_type]->name, sym_name);
7979
7980 bfd_set_error (bfd_error_invalid_operation);
7981 ret = FALSE;
7982 continue;
7983 }
7984
7985 /* Do any further special processing. */
7986 switch (r_type)
7987 {
7988 default:
7989 break;
7990
7991 case R_PPC64_ADDR16_HA:
7992 case R_PPC64_ADDR16_HIGHERA:
7993 case R_PPC64_ADDR16_HIGHESTA:
7994 case R_PPC64_GOT16_HA:
7995 case R_PPC64_PLTGOT16_HA:
7996 case R_PPC64_PLT16_HA:
7997 case R_PPC64_TOC16_HA:
7998 case R_PPC64_SECTOFF_HA:
7999 case R_PPC64_TPREL16_HA:
8000 case R_PPC64_DTPREL16_HA:
8001 case R_PPC64_GOT_TLSGD16_HA:
8002 case R_PPC64_GOT_TLSLD16_HA:
8003 case R_PPC64_GOT_TPREL16_HA:
8004 case R_PPC64_GOT_DTPREL16_HA:
8005 case R_PPC64_TPREL16_HIGHER:
8006 case R_PPC64_TPREL16_HIGHERA:
8007 case R_PPC64_TPREL16_HIGHEST:
8008 case R_PPC64_TPREL16_HIGHESTA:
8009 case R_PPC64_DTPREL16_HIGHER:
8010 case R_PPC64_DTPREL16_HIGHERA:
8011 case R_PPC64_DTPREL16_HIGHEST:
8012 case R_PPC64_DTPREL16_HIGHESTA:
8013 /* It's just possible that this symbol is a weak symbol
8014 that's not actually defined anywhere. In that case,
8015 'sec' would be NULL, and we should leave the symbol
8016 alone (it will be set to zero elsewhere in the link). */
8017 if (sec != NULL)
8018 /* Add 0x10000 if sign bit in 0:15 is set. */
8019 addend += ((relocation + addend) & 0x8000) << 1;
8020 break;
8021
8022 case R_PPC64_ADDR16_DS:
8023 case R_PPC64_ADDR16_LO_DS:
8024 case R_PPC64_GOT16_DS:
8025 case R_PPC64_GOT16_LO_DS:
8026 case R_PPC64_PLT16_LO_DS:
8027 case R_PPC64_SECTOFF_DS:
8028 case R_PPC64_SECTOFF_LO_DS:
8029 case R_PPC64_TOC16_DS:
8030 case R_PPC64_TOC16_LO_DS:
8031 case R_PPC64_PLTGOT16_DS:
8032 case R_PPC64_PLTGOT16_LO_DS:
8033 case R_PPC64_GOT_TPREL16_DS:
8034 case R_PPC64_GOT_TPREL16_LO_DS:
8035 case R_PPC64_GOT_DTPREL16_DS:
8036 case R_PPC64_GOT_DTPREL16_LO_DS:
8037 case R_PPC64_TPREL16_DS:
8038 case R_PPC64_TPREL16_LO_DS:
8039 case R_PPC64_DTPREL16_DS:
8040 case R_PPC64_DTPREL16_LO_DS:
8041 if (((relocation + addend) & 3) != 0)
8042 {
8043 (*_bfd_error_handler)
8044 (_("%s: error: relocation %s not a multiple of 4"),
8045 bfd_archive_filename (input_bfd),
8046 ppc64_elf_howto_table[(int) r_type]->name);
8047 bfd_set_error (bfd_error_bad_value);
8048 ret = FALSE;
8049 continue;
8050 }
8051 break;
8052
8053 case R_PPC64_REL14:
8054 case R_PPC64_REL14_BRNTAKEN:
8055 case R_PPC64_REL14_BRTAKEN:
8056 max_br_offset = 1 << 15;
8057 goto branch_check;
8058
8059 case R_PPC64_REL24:
8060 max_br_offset = 1 << 25;
8061
8062 branch_check:
8063 /* If the branch is out of reach, then redirect the
8064 call to the local stub for this function. */
8065 from = (rel->r_offset
8066 + input_section->output_offset
8067 + input_section->output_section->vma);
8068 if (relocation + addend - from + max_br_offset >= 2 * max_br_offset
8069 && (stub_entry = ppc_get_stub_entry (input_section, sec, h,
8070 rel, htab)) != NULL)
8071 {
8072 /* Munge up the value and addend so that we call the stub
8073 rather than the procedure directly. */
8074 relocation = (stub_entry->stub_offset
8075 + stub_entry->stub_sec->output_offset
8076 + stub_entry->stub_sec->output_section->vma);
8077 addend = 0;
8078 }
8079 break;
8080 }
8081
8082 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
8083 because such sections are not SEC_ALLOC and thus ld.so will
8084 not process them. */
8085 if (unresolved_reloc
8086 && !((input_section->flags & SEC_DEBUGGING) != 0
8087 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0))
8088 {
8089 (*_bfd_error_handler)
8090 (_("%s(%s+0x%lx): unresolvable relocation against symbol `%s'"),
8091 bfd_archive_filename (input_bfd),
8092 bfd_get_section_name (input_bfd, input_section),
8093 (long) rel->r_offset,
8094 h->root.root.string);
8095 ret = FALSE;
8096 }
8097
8098 r = _bfd_final_link_relocate (ppc64_elf_howto_table[(int) r_type],
8099 input_bfd,
8100 input_section,
8101 contents,
8102 rel->r_offset,
8103 relocation,
8104 addend);
8105
8106 if (r != bfd_reloc_ok)
8107 {
8108 const char *name;
8109
8110 if (h != NULL)
8111 {
8112 if (h->root.type == bfd_link_hash_undefweak
8113 && ppc64_elf_howto_table[(int) r_type]->pc_relative)
8114 {
8115 /* Assume this is a call protected by other code that
8116 detects the symbol is undefined. If this is the case,
8117 we can safely ignore the overflow. If not, the
8118 program is hosed anyway, and a little warning isn't
8119 going to help. */
8120
8121 continue;
8122 }
8123
8124 name = h->root.root.string;
8125 }
8126 else
8127 {
8128 name = bfd_elf_local_sym_name (input_bfd, sym);
8129 if (name == NULL)
8130 continue;
8131 }
8132
8133 if (r == bfd_reloc_overflow)
8134 {
8135 if (warned)
8136 continue;
8137 if (!((*info->callbacks->reloc_overflow)
8138 (info, name, ppc64_elf_howto_table[(int) r_type]->name,
8139 rel->r_addend, input_bfd, input_section, rel->r_offset)))
8140 return FALSE;
8141 }
8142 else
8143 {
8144 (*_bfd_error_handler)
8145 (_("%s(%s+0x%lx): reloc against `%s': error %d"),
8146 bfd_archive_filename (input_bfd),
8147 bfd_get_section_name (input_bfd, input_section),
8148 (long) rel->r_offset, name, (int) r);
8149 ret = FALSE;
8150 }
8151 }
8152 }
8153
8154 return ret;
8155 }
8156
8157 /* Finish up dynamic symbol handling. We set the contents of various
8158 dynamic sections here. */
8159
8160 static bfd_boolean
8161 ppc64_elf_finish_dynamic_symbol (output_bfd, info, h, sym)
8162 bfd *output_bfd;
8163 struct bfd_link_info *info;
8164 struct elf_link_hash_entry *h;
8165 Elf_Internal_Sym *sym;
8166 {
8167 struct ppc_link_hash_table *htab;
8168 bfd *dynobj;
8169
8170 htab = ppc_hash_table (info);
8171 dynobj = htab->elf.dynobj;
8172
8173 if (((struct ppc_link_hash_entry *) h)->is_func_descriptor)
8174 {
8175 struct plt_entry *ent;
8176 Elf_Internal_Rela rela;
8177 bfd_byte *loc;
8178
8179 for (ent = h->plt.plist; ent != NULL; ent = ent->next)
8180 if (ent->plt.offset != (bfd_vma) -1)
8181 {
8182 /* This symbol has an entry in the procedure linkage
8183 table. Set it up. */
8184
8185 if (htab->splt == NULL
8186 || htab->srelplt == NULL
8187 || htab->sglink == NULL)
8188 abort ();
8189
8190 /* Create a JMP_SLOT reloc to inform the dynamic linker to
8191 fill in the PLT entry. */
8192 rela.r_offset = (htab->splt->output_section->vma
8193 + htab->splt->output_offset
8194 + ent->plt.offset);
8195 rela.r_info = ELF64_R_INFO (h->dynindx, R_PPC64_JMP_SLOT);
8196 rela.r_addend = ent->addend;
8197
8198 loc = htab->srelplt->contents;
8199 loc += ((ent->plt.offset - PLT_INITIAL_ENTRY_SIZE) / PLT_ENTRY_SIZE
8200 * sizeof (Elf64_External_Rela));
8201 bfd_elf64_swap_reloca_out (output_bfd, &rela, loc);
8202 }
8203 }
8204
8205 if ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_COPY) != 0)
8206 {
8207 Elf_Internal_Rela rela;
8208 bfd_byte *loc;
8209
8210 /* This symbol needs a copy reloc. Set it up. */
8211
8212 if (h->dynindx == -1
8213 || (h->root.type != bfd_link_hash_defined
8214 && h->root.type != bfd_link_hash_defweak)
8215 || htab->srelbss == NULL)
8216 abort ();
8217
8218 rela.r_offset = (h->root.u.def.value
8219 + h->root.u.def.section->output_section->vma
8220 + h->root.u.def.section->output_offset);
8221 rela.r_info = ELF64_R_INFO (h->dynindx, R_PPC64_COPY);
8222 rela.r_addend = 0;
8223 loc = htab->srelbss->contents;
8224 loc += htab->srelbss->reloc_count++ * sizeof (Elf64_External_Rela);
8225 bfd_elf64_swap_reloca_out (output_bfd, &rela, loc);
8226 }
8227
8228 /* Mark some specially defined symbols as absolute. */
8229 if (strcmp (h->root.root.string, "_DYNAMIC") == 0)
8230 sym->st_shndx = SHN_ABS;
8231
8232 return TRUE;
8233 }
8234
8235 /* Used to decide how to sort relocs in an optimal manner for the
8236 dynamic linker, before writing them out. */
8237
8238 static enum elf_reloc_type_class
8239 ppc64_elf_reloc_type_class (rela)
8240 const Elf_Internal_Rela *rela;
8241 {
8242 enum elf_ppc64_reloc_type r_type;
8243
8244 r_type = (enum elf_ppc64_reloc_type) ELF64_R_TYPE (rela->r_info);
8245 switch (r_type)
8246 {
8247 case R_PPC64_RELATIVE:
8248 return reloc_class_relative;
8249 case R_PPC64_JMP_SLOT:
8250 return reloc_class_plt;
8251 case R_PPC64_COPY:
8252 return reloc_class_copy;
8253 default:
8254 return reloc_class_normal;
8255 }
8256 }
8257
8258 /* Finish up the dynamic sections. */
8259
8260 static bfd_boolean
8261 ppc64_elf_finish_dynamic_sections (output_bfd, info)
8262 bfd *output_bfd;
8263 struct bfd_link_info *info;
8264 {
8265 struct ppc_link_hash_table *htab;
8266 bfd *dynobj;
8267 asection *sdyn;
8268
8269 htab = ppc_hash_table (info);
8270 dynobj = htab->elf.dynobj;
8271 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
8272
8273 if (htab->elf.dynamic_sections_created)
8274 {
8275 Elf64_External_Dyn *dyncon, *dynconend;
8276
8277 if (sdyn == NULL || htab->sgot == NULL)
8278 abort ();
8279
8280 dyncon = (Elf64_External_Dyn *) sdyn->contents;
8281 dynconend = (Elf64_External_Dyn *) (sdyn->contents + sdyn->_raw_size);
8282 for (; dyncon < dynconend; dyncon++)
8283 {
8284 Elf_Internal_Dyn dyn;
8285 asection *s;
8286
8287 bfd_elf64_swap_dyn_in (dynobj, dyncon, &dyn);
8288
8289 switch (dyn.d_tag)
8290 {
8291 default:
8292 continue;
8293
8294 case DT_PPC64_GLINK:
8295 s = htab->sglink;
8296 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
8297 break;
8298
8299 case DT_PPC64_OPD:
8300 s = bfd_get_section_by_name (output_bfd, ".opd");
8301 if (s == NULL)
8302 continue;
8303 dyn.d_un.d_ptr = s->vma;
8304 break;
8305
8306 case DT_PPC64_OPDSZ:
8307 s = bfd_get_section_by_name (output_bfd, ".opd");
8308 if (s == NULL)
8309 continue;
8310 dyn.d_un.d_val = s->_raw_size;
8311 break;
8312
8313 case DT_PLTGOT:
8314 s = htab->splt;
8315 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
8316 break;
8317
8318 case DT_JMPREL:
8319 s = htab->srelplt;
8320 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
8321 break;
8322
8323 case DT_PLTRELSZ:
8324 dyn.d_un.d_val = htab->srelplt->_raw_size;
8325 break;
8326
8327 case DT_RELASZ:
8328 /* Don't count procedure linkage table relocs in the
8329 overall reloc count. */
8330 s = htab->srelplt;
8331 if (s == NULL)
8332 continue;
8333 dyn.d_un.d_val -= s->_raw_size;
8334 break;
8335
8336 case DT_RELA:
8337 /* We may not be using the standard ELF linker script.
8338 If .rela.plt is the first .rela section, we adjust
8339 DT_RELA to not include it. */
8340 s = htab->srelplt;
8341 if (s == NULL)
8342 continue;
8343 if (dyn.d_un.d_ptr != s->output_section->vma + s->output_offset)
8344 continue;
8345 dyn.d_un.d_ptr += s->_raw_size;
8346 break;
8347 }
8348
8349 bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon);
8350 }
8351 }
8352
8353 if (htab->sgot != NULL && htab->sgot->_raw_size != 0)
8354 {
8355 /* Fill in the first entry in the global offset table.
8356 We use it to hold the link-time TOCbase. */
8357 bfd_put_64 (output_bfd,
8358 elf_gp (output_bfd) + TOC_BASE_OFF,
8359 htab->sgot->contents);
8360
8361 /* Set .got entry size. */
8362 elf_section_data (htab->sgot->output_section)->this_hdr.sh_entsize = 8;
8363 }
8364
8365 if (htab->splt != NULL && htab->splt->_raw_size != 0)
8366 {
8367 /* Set .plt entry size. */
8368 elf_section_data (htab->splt->output_section)->this_hdr.sh_entsize
8369 = PLT_ENTRY_SIZE;
8370 }
8371
8372 return TRUE;
8373 }
8374
8375 #define TARGET_LITTLE_SYM bfd_elf64_powerpcle_vec
8376 #define TARGET_LITTLE_NAME "elf64-powerpcle"
8377 #define TARGET_BIG_SYM bfd_elf64_powerpc_vec
8378 #define TARGET_BIG_NAME "elf64-powerpc"
8379 #define ELF_ARCH bfd_arch_powerpc
8380 #define ELF_MACHINE_CODE EM_PPC64
8381 #define ELF_MAXPAGESIZE 0x10000
8382 #define elf_info_to_howto ppc64_elf_info_to_howto
8383
8384 #ifdef EM_CYGNUS_POWERPC
8385 #define ELF_MACHINE_ALT1 EM_CYGNUS_POWERPC
8386 #endif
8387
8388 #ifdef EM_PPC_OLD
8389 #define ELF_MACHINE_ALT2 EM_PPC_OLD
8390 #endif
8391
8392 #define elf_backend_want_got_sym 0
8393 #define elf_backend_want_plt_sym 0
8394 #define elf_backend_plt_alignment 3
8395 #define elf_backend_plt_not_loaded 1
8396 #define elf_backend_got_symbol_offset 0
8397 #define elf_backend_got_header_size 8
8398 #define elf_backend_plt_header_size PLT_INITIAL_ENTRY_SIZE
8399 #define elf_backend_can_gc_sections 1
8400 #define elf_backend_can_refcount 1
8401 #define elf_backend_rela_normal 1
8402
8403 #define bfd_elf64_bfd_reloc_type_lookup ppc64_elf_reloc_type_lookup
8404 #define bfd_elf64_bfd_merge_private_bfd_data ppc64_elf_merge_private_bfd_data
8405 #define bfd_elf64_new_section_hook ppc64_elf_new_section_hook
8406 #define bfd_elf64_bfd_link_hash_table_create ppc64_elf_link_hash_table_create
8407 #define bfd_elf64_bfd_link_hash_table_free ppc64_elf_link_hash_table_free
8408
8409 #define elf_backend_object_p ppc64_elf_object_p
8410 #define elf_backend_create_dynamic_sections ppc64_elf_create_dynamic_sections
8411 #define elf_backend_copy_indirect_symbol ppc64_elf_copy_indirect_symbol
8412 #define elf_backend_check_relocs ppc64_elf_check_relocs
8413 #define elf_backend_gc_mark_hook ppc64_elf_gc_mark_hook
8414 #define elf_backend_gc_sweep_hook ppc64_elf_gc_sweep_hook
8415 #define elf_backend_adjust_dynamic_symbol ppc64_elf_adjust_dynamic_symbol
8416 #define elf_backend_hide_symbol ppc64_elf_hide_symbol
8417 #define elf_backend_always_size_sections ppc64_elf_func_desc_adjust
8418 #define elf_backend_size_dynamic_sections ppc64_elf_size_dynamic_sections
8419 #define elf_backend_relocate_section ppc64_elf_relocate_section
8420 #define elf_backend_finish_dynamic_symbol ppc64_elf_finish_dynamic_symbol
8421 #define elf_backend_reloc_type_class ppc64_elf_reloc_type_class
8422 #define elf_backend_finish_dynamic_sections ppc64_elf_finish_dynamic_sections
8423
8424 #include "elf64-target.h"
This page took 0.255531 seconds and 4 git commands to generate.