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