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