source: trunk/src/binutils/bfd/elf64-ppc.c@ 2013

Last change on this file since 2013 was 607, checked in by bird, 22 years ago

Initial revision

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