Fix typo
[deliverable/binutils-gdb.git] / bfd / elf64-ppc.c
CommitLineData
5bd4f169
AM
1/* PowerPC64-specific support for 64-bit ELF.
2 Copyright 1999, 2000, 2001 Free Software Foundation, Inc.
3 Written by Linus Nordberg, Swox AB <info@swox.com>,
4 based on elf32-ppc.c by Ian Lance Taylor.
5
6This file is part of BFD, the Binary File Descriptor library.
7
8This program is free software; you can redistribute it and/or modify
9it under the terms of the GNU General Public License as published by
10the Free Software Foundation; either version 2 of the License, or
11(at your option) any later version.
12
13This program is distributed in the hope that it will be useful,
14but WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16GNU General Public License for more details.
17
18You should have received a copy of the GNU General Public License
19along with this program; if not, write to the Free Software
20Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
21
22/* This file is based on the 64-bit PowerPC ELF ABI. It is also based
23 on the file elf32-ppc.c. */
24
25#include "bfd.h"
26#include "sysdep.h"
27#include "bfdlink.h"
28#include "libbfd.h"
29#include "elf-bfd.h"
30#include "elf/ppc.h"
31
32#define USE_RELA /* we want RELA relocations, not REL. */
33
34
35static void ppc_howto_init
36 PARAMS ((void));
37static reloc_howto_type *ppc64_elf_reloc_type_lookup
38 PARAMS ((bfd *abfd, bfd_reloc_code_real_type code));
39static void ppc64_elf_info_to_howto
40 PARAMS ((bfd *abfd, arelent *cache_ptr, Elf64_Internal_Rela *dst));
41static bfd_reloc_status_type ppc64_elf_addr16_ha_reloc
42 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
43static boolean ppc64_elf_set_private_flags
44 PARAMS ((bfd *, flagword));
45static boolean ppc64_elf_copy_private_bfd_data
46 PARAMS ((bfd *, bfd *));
47static boolean ppc64_elf_merge_private_bfd_data
48 PARAMS ((bfd *, bfd *));
49static boolean ppc64_elf_section_from_shdr
50 PARAMS ((bfd *, Elf64_Internal_Shdr *, char *));
51static boolean ppc64_elf_create_dynamic_sections
52 PARAMS ((bfd *, struct bfd_link_info *));
53static boolean ppc64_elf_check_relocs
54 PARAMS ((bfd *, struct bfd_link_info *, asection *,
55 const Elf_Internal_Rela *));
56static asection * ppc64_elf_gc_mark_hook
57 PARAMS ((bfd *abfd, struct bfd_link_info *info, Elf_Internal_Rela *rel,
58 struct elf_link_hash_entry *h, Elf_Internal_Sym *sym));
59static boolean ppc64_elf_gc_sweep_hook
60 PARAMS ((bfd *abfd, struct bfd_link_info *info, asection *sec,
61 const Elf_Internal_Rela *relocs));
62static boolean ppc64_elf_adjust_dynamic_symbol
63 PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *));
64static boolean ppc_adjust_dynindx
65 PARAMS ((struct elf_link_hash_entry *, PTR));
66static boolean ppc64_elf_size_dynamic_sections
67 PARAMS ((bfd *, struct bfd_link_info *));
68static boolean ppc64_elf_final_link
69 PARAMS ((bfd *, struct bfd_link_info *));
70static boolean ppc64_elf_fake_sections
71 PARAMS ((bfd *, Elf64_Internal_Shdr *, asection *));
72static boolean ppc64_elf_relocate_section
73 PARAMS ((bfd *, struct bfd_link_info *info, bfd *, asection *, bfd_byte *,
74 Elf_Internal_Rela *relocs, Elf_Internal_Sym *local_syms,
75 asection **));
76static boolean ppc64_elf_finish_dynamic_symbol
77 PARAMS ((bfd *, struct bfd_link_info *, struct elf_link_hash_entry *,
78 Elf_Internal_Sym *));
79static boolean ppc64_elf_finish_dynamic_sections
80 PARAMS ((bfd *, struct bfd_link_info *));
81
82
83/* Branch prediction bit for branch taken relocs. */
84#define BRANCH_PREDICT_BIT 0x200000
85
86/* Mask to set RA in memory instructions. */
87#define RA_REGISTER_MASK 0x001f0000
88
89/* Value to shift register by to insert RA. */
90#define RA_REGISTER_SHIFT 16
91
92/* The name of the dynamic interpreter. This is put in the .interp
93 section. */
94#define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
95
96/* The size in bytes of an entry in the procedure linkage table. */
97#define PLT_ENTRY_SIZE 24
98
99/* The initial size of the plt reserved for the dynamic linker. */
100#define PLT_INITIAL_ENTRY_SIZE 96
101
102/* TOC base pointers offset from start of TOC. */
103#define TOC_BASE_OFF (0x8000)
104
105/* Global linkage stub. The first instruction has its offset patched. */
106/* FIXME: Need traceback table? */
107static const unsigned int ppc64_elf_glink_code[] = {
108 0xe9820000, /* ld %r12,0(%r2) */
109 0xf8410028, /* std %r2,40(%r1) */
110 0xe80c0000, /* ld %r0,0(%r12) */
111 0xe84c0008, /* ld %r2,8(%r12) */
112 0x7c0903a6, /* mtctr %r0 */
113 0x4e800420 /* bctr */
114};
115
116#define PPC64_ELF_GLINK_SIZE \
117 ((sizeof ppc64_elf_glink_code / sizeof ppc64_elf_glink_code[0]) * 4)
118\f
119/* Relocation HOWTO's. */
120static reloc_howto_type *ppc64_elf_howto_table[(int) R_PPC_max];
121
122static reloc_howto_type ppc64_elf_howto_raw[] = {
123 /* This reloc does nothing. */
124 HOWTO (R_PPC64_NONE, /* type */
125 0, /* rightshift */
126 2, /* size (0 = byte, 1 = short, 2 = long) */
127 32, /* bitsize */
128 false, /* pc_relative */
129 0, /* bitpos */
130 complain_overflow_bitfield, /* complain_on_overflow */
131 bfd_elf_generic_reloc, /* special_function */
132 "R_PPC64_NONE", /* name */
133 false, /* partial_inplace */
134 0, /* src_mask */
135 0, /* dst_mask */
136 false), /* pcrel_offset */
137
138 /* A standard 32 bit relocation. */
139 HOWTO (R_PPC64_ADDR32, /* type */
140 0, /* rightshift */
141 2, /* size (0 = byte, 1 = short, 2 = long) */
142 32, /* bitsize */
143 false, /* pc_relative */
144 0, /* bitpos */
145 complain_overflow_bitfield, /* complain_on_overflow */
146 bfd_elf_generic_reloc, /* special_function */
147 "R_PPC64_ADDR32", /* name */
148 false, /* partial_inplace */
149 0, /* src_mask */
150 0xffffffff, /* dst_mask */
151 false), /* pcrel_offset */
152
153 /* An absolute 26 bit branch; the lower two bits must be zero.
154 FIXME: we don't check that, we just clear them. */
155 HOWTO (R_PPC64_ADDR24, /* type */
156 0, /* rightshift */
157 2, /* size (0 = byte, 1 = short, 2 = long) */
158 26, /* bitsize */
159 false, /* pc_relative */
160 0, /* bitpos */
161 complain_overflow_bitfield, /* complain_on_overflow */
162 bfd_elf_generic_reloc, /* special_function */
163 "R_PPC64_ADDR24", /* name */
164 false, /* partial_inplace */
165 0, /* src_mask */
166 0x3fffffc, /* dst_mask */
167 false), /* pcrel_offset */
168
169 /* A standard 16 bit relocation. */
170 HOWTO (R_PPC64_ADDR16, /* type */
171 0, /* rightshift */
172 1, /* size (0 = byte, 1 = short, 2 = long) */
173 16, /* bitsize */
174 false, /* pc_relative */
175 0, /* bitpos */
176 complain_overflow_bitfield, /* complain_on_overflow */
177 bfd_elf_generic_reloc, /* special_function */
178 "R_PPC64_ADDR16", /* name */
179 false, /* partial_inplace */
180 0, /* src_mask */
181 0xffff, /* dst_mask */
182 false), /* pcrel_offset */
183
184 /* A 16 bit relocation without overflow. */
185 HOWTO (R_PPC64_ADDR16_LO, /* type */
186 0, /* rightshift */
187 1, /* size (0 = byte, 1 = short, 2 = long) */
188 16, /* bitsize */
189 false, /* pc_relative */
190 0, /* bitpos */
191 complain_overflow_dont,/* complain_on_overflow */
192 bfd_elf_generic_reloc, /* special_function */
193 "R_PPC64_ADDR16_LO", /* name */
194 false, /* partial_inplace */
195 0, /* src_mask */
196 0xffff, /* dst_mask */
197 false), /* pcrel_offset */
198
199 /* Bits 16-31 of an address. */
200 HOWTO (R_PPC64_ADDR16_HI, /* type */
201 16, /* rightshift */
202 1, /* size (0 = byte, 1 = short, 2 = long) */
203 16, /* bitsize */
204 false, /* pc_relative */
205 0, /* bitpos */
206 complain_overflow_dont, /* complain_on_overflow */
207 bfd_elf_generic_reloc, /* special_function */
208 "R_PPC64_ADDR16_HI", /* name */
209 false, /* partial_inplace */
210 0, /* src_mask */
211 0xffff, /* dst_mask */
212 false), /* pcrel_offset */
213
214 /* Bits 16-31 of an address, plus 1 if the contents of the low 16
215 bits, treated as a signed number, is negative. */
216 HOWTO (R_PPC64_ADDR16_HA, /* type */
217 16, /* rightshift */
218 1, /* size (0 = byte, 1 = short, 2 = long) */
219 16, /* bitsize */
220 false, /* pc_relative */
221 0, /* bitpos */
222 complain_overflow_dont, /* complain_on_overflow */
223 ppc64_elf_addr16_ha_reloc, /* special_function */
224 "R_PPC64_ADDR16_HA", /* name */
225 false, /* partial_inplace */
226 0, /* src_mask */
227 0xffff, /* dst_mask */
228 false), /* pcrel_offset */
229
230 /* An absolute 16 bit branch; the lower two bits must be zero.
231 FIXME: we don't check that, we just clear them. */
232 HOWTO (R_PPC64_ADDR14, /* type */
233 0, /* rightshift */
234 2, /* size (0 = byte, 1 = short, 2 = long) */
235 16, /* bitsize */
236 false, /* pc_relative */
237 0, /* bitpos */
238 complain_overflow_bitfield, /* complain_on_overflow */
239 bfd_elf_generic_reloc, /* special_function */
240 "R_PPC64_ADDR14", /* name */
241 false, /* partial_inplace */
242 0, /* src_mask */
243 0xfffc, /* dst_mask */
244 false), /* pcrel_offset */
245
246 /* An absolute 16 bit branch, for which bit 10 should be set to
247 indicate that the branch is expected to be taken. The lower two
248 bits must be zero. */
249 HOWTO (R_PPC64_ADDR14_BRTAKEN, /* type */
250 0, /* rightshift */
251 2, /* size (0 = byte, 1 = short, 2 = long) */
252 16, /* bitsize */
253 false, /* pc_relative */
254 0, /* bitpos */
255 complain_overflow_bitfield, /* complain_on_overflow */
256 bfd_elf_generic_reloc, /* special_function */
257 "R_PPC64_ADDR14_BRTAKEN",/* name */
258 false, /* partial_inplace */
259 0, /* src_mask */
260 0xfffc, /* dst_mask */
261 false), /* pcrel_offset */
262
263 /* An absolute 16 bit branch, for which bit 10 should be set to
264 indicate that the branch is not expected to be taken. The lower
265 two bits must be zero. */
266 HOWTO (R_PPC64_ADDR14_BRNTAKEN, /* type */
267 0, /* rightshift */
268 2, /* size (0 = byte, 1 = short, 2 = long) */
269 16, /* bitsize */
270 false, /* pc_relative */
271 0, /* bitpos */
272 complain_overflow_bitfield, /* complain_on_overflow */
273 bfd_elf_generic_reloc, /* special_function */
274 "R_PPC64_ADDR14_BRNTAKEN",/* name */
275 false, /* partial_inplace */
276 0, /* src_mask */
277 0xfffc, /* dst_mask */
278 false), /* pcrel_offset */
279
280 /* A relative 26 bit branch; the lower two bits must be zero. */
281 HOWTO (R_PPC64_REL24, /* type */
282 0, /* rightshift */
283 2, /* size (0 = byte, 1 = short, 2 = long) */
284 26, /* bitsize */
285 true, /* pc_relative */
286 0, /* bitpos */
287 complain_overflow_signed, /* complain_on_overflow */
288 bfd_elf_generic_reloc, /* special_function */
289 "R_PPC64_REL24", /* name */
290 false, /* partial_inplace */
291 0, /* src_mask */
292 0x3fffffc, /* dst_mask */
293 true), /* pcrel_offset */
294
295 /* A relative 16 bit branch; the lower two bits must be zero. */
296 HOWTO (R_PPC64_REL14, /* type */
297 0, /* rightshift */
298 2, /* size (0 = byte, 1 = short, 2 = long) */
299 16, /* bitsize */
300 true, /* pc_relative */
301 0, /* bitpos */
302 complain_overflow_signed, /* complain_on_overflow */
303 bfd_elf_generic_reloc, /* special_function */
304 "R_PPC64_REL14", /* name */
305 false, /* partial_inplace */
306 0, /* src_mask */
307 0xfffc, /* dst_mask */
308 true), /* pcrel_offset */
309
310 /* A relative 16 bit branch. Bit 10 should be set to indicate that
311 the branch is expected to be taken. The lower two bits must be
312 zero. */
313 HOWTO (R_PPC64_REL14_BRTAKEN, /* type */
314 0, /* rightshift */
315 2, /* size (0 = byte, 1 = short, 2 = long) */
316 16, /* bitsize */
317 true, /* pc_relative */
318 0, /* bitpos */
319 complain_overflow_signed, /* complain_on_overflow */
320 bfd_elf_generic_reloc, /* special_function */
321 "R_PPC64_REL14_BRTAKEN", /* name */
322 false, /* partial_inplace */
323 0, /* src_mask */
324 0xfffc, /* dst_mask */
325 true), /* pcrel_offset */
326
327 /* A relative 16 bit branch. Bit 10 should be set to indicate that
328 the branch is not expected to be taken. The lower two bits must
329 be zero. */
330 HOWTO (R_PPC64_REL14_BRNTAKEN, /* type */
331 0, /* rightshift */
332 2, /* size (0 = byte, 1 = short, 2 = long) */
333 16, /* bitsize */
334 true, /* pc_relative */
335 0, /* bitpos */
336 complain_overflow_signed, /* complain_on_overflow */
337 bfd_elf_generic_reloc, /* special_function */
338 "R_PPC64_REL14_BRNTAKEN",/* name */
339 false, /* partial_inplace */
340 0, /* src_mask */
341 0xfffc, /* dst_mask */
342 true), /* pcrel_offset */
343
344 /* Like R_PPC64_ADDR16, but referring to the GOT table entry for the
345 symbol. */
346 HOWTO (R_PPC64_GOT16, /* type */
347 0, /* rightshift */
348 1, /* size (0 = byte, 1 = short, 2 = long) */
349 16, /* bitsize */
350 false, /* pc_relative */
351 0, /* bitpos */
352 complain_overflow_signed, /* complain_on_overflow */
353 bfd_elf_generic_reloc, /* special_function */
354 "R_PPC64_GOT16", /* name */
355 false, /* partial_inplace */
356 0, /* src_mask */
357 0xffff, /* dst_mask */
358 false), /* pcrel_offset */
359
360 /* Like R_PPC64_ADDR16_LO, but referring to the GOT table entry for
361 the symbol. */
362 HOWTO (R_PPC64_GOT16_LO, /* type */
363 0, /* rightshift */
364 1, /* size (0 = byte, 1 = short, 2 = long) */
365 16, /* bitsize */
366 false, /* pc_relative */
367 0, /* bitpos */
368 complain_overflow_dont, /* complain_on_overflow */
369 bfd_elf_generic_reloc, /* special_function */
370 "R_PPC64_GOT16_LO", /* name */
371 false, /* partial_inplace */
372 0, /* src_mask */
373 0xffff, /* dst_mask */
374 false), /* pcrel_offset */
375
376 /* Like R_PPC64_ADDR16_HI, but referring to the GOT table entry for
377 the symbol. */
378 HOWTO (R_PPC64_GOT16_HI, /* type */
379 16, /* rightshift */
380 1, /* size (0 = byte, 1 = short, 2 = long) */
381 16, /* bitsize */
382 false, /* pc_relative */
383 0, /* bitpos */
384 complain_overflow_dont,/* complain_on_overflow */
385 bfd_elf_generic_reloc, /* special_function */
386 "R_PPC64_GOT16_HI", /* name */
387 false, /* partial_inplace */
388 0, /* src_mask */
389 0xffff, /* dst_mask */
390 false), /* pcrel_offset */
391
392 /* Like R_PPC64_ADDR16_HA, but referring to the GOT table entry for
393 the symbol. */
394 HOWTO (R_PPC64_GOT16_HA, /* type */
395 16, /* rightshift */
396 1, /* size (0 = byte, 1 = short, 2 = long) */
397 16, /* bitsize */
398 false, /* pc_relative */
399 0, /* bitpos */
400 complain_overflow_dont,/* complain_on_overflow */
401 ppc64_elf_addr16_ha_reloc, /* special_function */
402 "R_PPC64_GOT16_HA", /* name */
403 false, /* partial_inplace */
404 0, /* src_mask */
405 0xffff, /* dst_mask */
406 false), /* pcrel_offset */
407
408 /* This is used only by the dynamic linker. The symbol should exist
409 both in the object being run and in some shared library. The
410 dynamic linker copies the data addressed by the symbol from the
411 shared library into the object, because the object being
412 run has to have the data at some particular address. */
413 HOWTO (R_PPC64_COPY, /* type */
414 0, /* rightshift */
415 2, /* size (0 = byte, 1 = short, 2 = long) */
416 32, /* bitsize */
417 false, /* pc_relative */
418 0, /* bitpos */
419 complain_overflow_bitfield, /* complain_on_overflow */
420 bfd_elf_generic_reloc, /* special_function */
421 "R_PPC64_COPY", /* name */
422 false, /* partial_inplace */
423 0, /* src_mask */
424 0, /* dst_mask */
425 false), /* pcrel_offset */
426
427 /* Like R_PPC64_ADDR64, but used when setting global offset table
428 entries. */
429 HOWTO (R_PPC64_GLOB_DAT, /* type */
430 0, /* rightshift */
431 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
432 64, /* bitsize */
433 false, /* pc_relative */
434 0, /* bitpos */
435 complain_overflow_dont, /* complain_on_overflow */
436 bfd_elf_generic_reloc, /* special_function */
437 "R_PPC64_GLOB_DAT", /* name */
438 false, /* partial_inplace */
439 0, /* src_mask */
440 0xffffffffffffffff, /* dst_mask */
441 false), /* pcrel_offset */
442
443 /* Created by the link editor. Marks a procedure linkage table
444 entry for a symbol. */
445 HOWTO (R_PPC64_JMP_SLOT, /* type */
446 0, /* rightshift */
447 0, /* size (0 = byte, 1 = short, 2 = long) */
448 0, /* bitsize */
449 false, /* pc_relative */
450 0, /* bitpos */
451 complain_overflow_dont, /* complain_on_overflow */
452 bfd_elf_generic_reloc, /* special_function */
453 "R_PPC64_JMP_SLOT", /* name */
454 false, /* partial_inplace */
455 0, /* src_mask */
456 0, /* dst_mask */
457 false), /* pcrel_offset */
458
459 /* Used only by the dynamic linker. When the object is run, this
460 doubleword64 is set to the load address of the object, plus the
461 addend. */
462 HOWTO (R_PPC64_RELATIVE, /* type */
463 0, /* rightshift */
464 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
465 64, /* bitsize */
466 false, /* pc_relative */
467 0, /* bitpos */
468 complain_overflow_dont, /* complain_on_overflow */
469 bfd_elf_generic_reloc, /* special_function */
470 "R_PPC64_RELATIVE", /* name */
471 false, /* partial_inplace */
472 0, /* src_mask */
473 0xffffffffffffffff, /* dst_mask */
474 false), /* pcrel_offset */
475
476 /* Like R_PPC64_ADDR32, but may be unaligned. */
477 HOWTO (R_PPC64_UADDR32, /* type */
478 0, /* rightshift */
479 2, /* size (0 = byte, 1 = short, 2 = long) */
480 32, /* bitsize */
481 false, /* pc_relative */
482 0, /* bitpos */
483 complain_overflow_bitfield, /* complain_on_overflow */
484 bfd_elf_generic_reloc, /* special_function */
485 "R_PPC64_UADDR32", /* name */
486 false, /* partial_inplace */
487 0, /* src_mask */
488 0xffffffff, /* dst_mask */
489 false), /* pcrel_offset */
490
491 /* Like R_PPC64_ADDR16, but may be unaligned. */
492 HOWTO (R_PPC64_UADDR16, /* type */
493 0, /* rightshift */
494 1, /* size (0 = byte, 1 = short, 2 = long) */
495 16, /* bitsize */
496 false, /* pc_relative */
497 0, /* bitpos */
498 complain_overflow_bitfield, /* complain_on_overflow */
499 bfd_elf_generic_reloc, /* special_function */
500 "R_PPC64_UADDR16", /* name */
501 false, /* partial_inplace */
502 0, /* src_mask */
503 0xffff, /* dst_mask */
504 false), /* pcrel_offset */
505
506 /* 32-bit PC relative. */
507 HOWTO (R_PPC64_REL32, /* type */
508 0, /* rightshift */
509 2, /* size (0 = byte, 1 = short, 2 = long) */
510 32, /* bitsize */
511 true, /* pc_relative */
512 0, /* bitpos */
513 /* FIXME: Verify. Was complain_overflow_bitfield. */
514 complain_overflow_signed, /* complain_on_overflow */
515 bfd_elf_generic_reloc, /* special_function */
516 "R_PPC64_REL32", /* name */
517 false, /* partial_inplace */
518 0, /* src_mask */
519 0xffffffff, /* dst_mask */
520 true), /* pcrel_offset */
521
522 /* 32-bit relocation to the symbol's procedure linkage table.
523 FIXME: R_PPC64_PLT32 not supported. */
524 HOWTO (R_PPC64_PLT32, /* type */
525 0, /* rightshift */
526 2, /* size (0 = byte, 1 = short, 2 = long) */
527 32, /* bitsize */
528 false, /* pc_relative */
529 0, /* bitpos */
530 complain_overflow_bitfield, /* complain_on_overflow */
531 bfd_elf_generic_reloc, /* special_function */
532 "R_PPC64_PLT32", /* name */
533 false, /* partial_inplace */
534 0, /* src_mask */
535 0, /* dst_mask */
536 false), /* pcrel_offset */
537
538 /* 32-bit PC relative relocation to the symbol's procedure linkage table.
539 FIXME: R_PPC64_PLTREL32 not supported. */
540 HOWTO (R_PPC64_PLTREL32, /* type */
541 0, /* rightshift */
542 2, /* size (0 = byte, 1 = short, 2 = long) */
543 32, /* bitsize */
544 true, /* pc_relative */
545 0, /* bitpos */
546 complain_overflow_signed, /* complain_on_overflow */
547 bfd_elf_generic_reloc, /* special_function */
548 "R_PPC64_PLTREL32", /* name */
549 false, /* partial_inplace */
550 0, /* src_mask */
551 0, /* dst_mask */
552 true), /* pcrel_offset */
553
554 /* Like R_PPC64_ADDR16_LO, but referring to the PLT table entry for
555 the symbol. */
556 HOWTO (R_PPC64_PLT16_LO, /* type */
557 0, /* rightshift */
558 1, /* size (0 = byte, 1 = short, 2 = long) */
559 16, /* bitsize */
560 false, /* pc_relative */
561 0, /* bitpos */
562 complain_overflow_dont, /* complain_on_overflow */
563 bfd_elf_generic_reloc, /* special_function */
564 "R_PPC64_PLT16_LO", /* name */
565 false, /* partial_inplace */
566 0, /* src_mask */
567 0xffff, /* dst_mask */
568 false), /* pcrel_offset */
569
570 /* Like R_PPC64_ADDR16_HI, but referring to the PLT table entry for
571 the symbol. */
572 HOWTO (R_PPC64_PLT16_HI, /* type */
573 16, /* rightshift */
574 1, /* size (0 = byte, 1 = short, 2 = long) */
575 16, /* bitsize */
576 false, /* pc_relative */
577 0, /* bitpos */
578 complain_overflow_dont, /* complain_on_overflow */
579 bfd_elf_generic_reloc, /* special_function */
580 "R_PPC64_PLT16_HI", /* name */
581 false, /* partial_inplace */
582 0, /* src_mask */
583 0xffff, /* dst_mask */
584 false), /* pcrel_offset */
585
586 /* Like R_PPC64_ADDR16_HA, but referring to the PLT table entry for
587 the symbol. */
588 HOWTO (R_PPC64_PLT16_HA, /* type */
589 16, /* rightshift */
590 1, /* size (0 = byte, 1 = short, 2 = long) */
591 16, /* bitsize */
592 false, /* pc_relative */
593 0, /* bitpos */
594 complain_overflow_dont, /* complain_on_overflow */
595 ppc64_elf_addr16_ha_reloc, /* special_function */
596 "R_PPC64_PLT16_HA", /* name */
597 false, /* partial_inplace */
598 0, /* src_mask */
599 0xffff, /* dst_mask */
600 false), /* pcrel_offset */
601
602 /* 32-bit section relative relocation. */
603 /* FIXME: Verify R_PPC64_SECTOFF. Seems strange with size=2 and
604 dst_mask=0. */
605 HOWTO (R_PPC64_SECTOFF, /* type */
606 0, /* rightshift */
607 2, /* size (0 = byte, 1 = short, 2 = long) */
608 32, /* bitsize */
609 true, /* pc_relative */
610 0, /* bitpos */
611 complain_overflow_bitfield, /* complain_on_overflow */
612 bfd_elf_generic_reloc, /* special_function */
613 "R_PPC64_SECTOFF", /* name */
614 false, /* partial_inplace */
615 0, /* src_mask */
616 0, /* dst_mask */
617 true), /* pcrel_offset */
618
619 /* 16-bit lower half section relative relocation. */
620 HOWTO (R_PPC64_SECTOFF_LO, /* type */
621 0, /* rightshift */
622 1, /* size (0 = byte, 1 = short, 2 = long) */
623 16, /* bitsize */
624 false, /* pc_relative */
625 0, /* bitpos */
626 complain_overflow_dont, /* complain_on_overflow */
627 bfd_elf_generic_reloc, /* special_function */
628 "R_PPC64_SECTOFF_LO", /* name */
629 false, /* partial_inplace */
630 0, /* src_mask */
631 0xffff, /* dst_mask */
632 false), /* pcrel_offset */
633
634 /* 16-bit upper half section relative relocation. */
635 HOWTO (R_PPC64_SECTOFF_HI, /* type */
636 16, /* rightshift */
637 1, /* size (0 = byte, 1 = short, 2 = long) */
638 16, /* bitsize */
639 false, /* pc_relative */
640 0, /* bitpos */
641 complain_overflow_dont, /* complain_on_overflow */
642 bfd_elf_generic_reloc, /* special_function */
643 "R_PPC64_SECTOFF_HI", /* name */
644 false, /* partial_inplace */
645 0, /* src_mask */
646 0xffff, /* dst_mask */
647 false), /* pcrel_offset */
648
649 /* 16-bit upper half adjusted section relative relocation. */
650 HOWTO (R_PPC64_SECTOFF_HA, /* type */
651 16, /* rightshift */
652 1, /* size (0 = byte, 1 = short, 2 = long) */
653 16, /* bitsize */
654 false, /* pc_relative */
655 0, /* bitpos */
656 complain_overflow_dont, /* complain_on_overflow */
657 ppc64_elf_addr16_ha_reloc, /* special_function */
658 "R_PPC64_SECTOFF_HA", /* name */
659 false, /* partial_inplace */
660 0, /* src_mask */
661 0xffff, /* dst_mask */
662 false), /* pcrel_offset */
663
664 /* Like R_PPC64_REL24 without touching the two least significant
665 bits. */
666 /* FIXME: Verify R_PPC64_ADDR30. */
667 HOWTO (R_PPC64_ADDR30, /* type */
668 2, /* rightshift */
669 2, /* size (0 = byte, 1 = short, 2 = long) */
670 30, /* bitsize */
671 true, /* pc_relative */
672 0, /* bitpos */
673 complain_overflow_dont, /* complain_on_overflow */
674 bfd_elf_generic_reloc, /* special_function */
675 "R_PPC64_ADDR30", /* name */
676 false, /* partial_inplace */
677 0, /* src_mask */
678 0xfffffffc, /* dst_mask */
679 true), /* pcrel_offset */
680
681 /* Relocs in the 64-bit PowerPC ELF ABI, not in the 32-bit ABI. */
682
683 /* A standard 64-bit relocation. */
684 HOWTO (R_PPC64_ADDR64, /* type */
685 0, /* rightshift */
686 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
687 64, /* bitsize */
688 false, /* pc_relative */
689 0, /* bitpos */
690 complain_overflow_dont, /* complain_on_overflow */
691 bfd_elf_generic_reloc, /* special_function */
692 "R_PPC64_ADDR64", /* name */
693 false, /* partial_inplace */
694 0, /* src_mask */
695 0xffffffffffffffff, /* dst_mask */
696 false), /* pcrel_offset */
697
698 /* The bits 32-47 of an address. */
699 HOWTO (R_PPC64_ADDR16_HIGHER, /* type */
700 32, /* rightshift */
701 1, /* size (0 = byte, 1 = short, 2 = long) */
702 16, /* bitsize */
703 false, /* pc_relative */
704 0, /* bitpos */
705 complain_overflow_dont, /* complain_on_overflow */
706 bfd_elf_generic_reloc, /* special_function */
707 "R_PPC64_ADDR16_HIGHER", /* name */
708 false, /* partial_inplace */
709 0, /* src_mask */
710 0xffff, /* dst_mask */
711 false), /* pcrel_offset */
712
713 /* The bits 32-47 of an address, plus 1 if the contents of the low
714 16 bits, treated as a signed number, is negative. */
715 HOWTO (R_PPC64_ADDR16_HIGHERA, /* type */
716 32, /* rightshift */
717 1, /* size (0 = byte, 1 = short, 2 = long) */
718 16, /* bitsize */
719 false, /* pc_relative */
720 0, /* bitpos */
721 complain_overflow_dont, /* complain_on_overflow */
722 ppc64_elf_addr16_ha_reloc, /* special_function */
723 "R_PPC64_ADDR16_HIGHERA", /* name */
724 false, /* partial_inplace */
725 0, /* src_mask */
726 0xffff, /* dst_mask */
727 false), /* pcrel_offset */
728
729 /* The bits 48-63 of an address. */
730 HOWTO (R_PPC64_ADDR16_HIGHEST,/* type */
731 48, /* rightshift */
732 1, /* size (0 = byte, 1 = short, 2 = long) */
733 16, /* bitsize */
734 false, /* pc_relative */
735 0, /* bitpos */
736 complain_overflow_dont, /* complain_on_overflow */
737 bfd_elf_generic_reloc, /* special_function */
738 "R_PPC64_ADDR16_HIGHEST", /* name */
739 false, /* partial_inplace */
740 0, /* src_mask */
741 0xffff, /* dst_mask */
742 false), /* pcrel_offset */
743
744 /* The bits 48-63 of an address, plus 1 if the contents of the low
745 16 bits, treated as a signed number, is negative. */
746 HOWTO (R_PPC64_ADDR16_HIGHESTA,/* type */
747 48, /* rightshift */
748 1, /* size (0 = byte, 1 = short, 2 = long) */
749 16, /* bitsize */
750 false, /* pc_relative */
751 0, /* bitpos */
752 complain_overflow_dont, /* complain_on_overflow */
753 ppc64_elf_addr16_ha_reloc, /* special_function */
754 "R_PPC64_ADDR16_HIGHESTA", /* name */
755 false, /* partial_inplace */
756 0, /* src_mask */
757 0xffff, /* dst_mask */
758 false), /* pcrel_offset */
759
760 /* Like ADDR64, but may be unaligned. */
761 HOWTO (R_PPC64_UADDR64, /* type */
762 0, /* rightshift */
763 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
764 64, /* bitsize */
765 false, /* pc_relative */
766 0, /* bitpos */
767 complain_overflow_dont, /* complain_on_overflow */
768 bfd_elf_generic_reloc, /* special_function */
769 "R_PPC64_UADDR64", /* name */
770 false, /* partial_inplace */
771 0, /* src_mask */
772 0xffffffffffffffff, /* dst_mask */
773 false), /* pcrel_offset */
774
775 /* 64-bit relative relocation. */
776 HOWTO (R_PPC64_REL64, /* type */
777 0, /* rightshift */
778 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
779 64, /* bitsize */
780 true, /* pc_relative */
781 0, /* bitpos */
782 complain_overflow_dont, /* complain_on_overflow */
783 bfd_elf_generic_reloc, /* special_function */
784 "R_PPC64_REL64", /* name */
785 false, /* partial_inplace */
786 0, /* src_mask */
787 0xffffffffffffffff, /* dst_mask */
788 true), /* pcrel_offset */
789
790 /* 64-bit relocation to the symbol's procedure linkage table. */
791 /* FIXME: R_PPC64_PLT64 not supported. */
792 HOWTO (R_PPC64_PLT64, /* type */
793 0, /* rightshift */
794 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
795 64, /* bitsize */
796 false, /* pc_relative */
797 0, /* bitpos */
798 complain_overflow_dont, /* complain_on_overflow */
799 bfd_elf_generic_reloc, /* special_function */
800 "R_PPC64_PLT64", /* name */
801 false, /* partial_inplace */
802 0, /* src_mask */
803 0, /* dst_mask */
804 false), /* pcrel_offset */
805
806 /* 64-bit PC relative relocation to the symbol's procedure linkage
807 table. */
808 /* FIXME: R_PPC64_PLTREL64 not supported. */
809 HOWTO (R_PPC64_PLTREL64, /* type */
810 0, /* rightshift */
811 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
812 64, /* bitsize */
813 true, /* pc_relative */
814 0, /* bitpos */
815 complain_overflow_dont, /* complain_on_overflow */
816 bfd_elf_generic_reloc, /* special_function */
817 "R_PPC64_PLTREL64", /* name */
818 false, /* partial_inplace */
819 0, /* src_mask */
820 0, /* dst_mask */
821 true), /* pcrel_offset */
822
823 /* 16 bit TOC-relative relocation. */
824
825 /* R_PPC64_TOC16 47 half16* S + A - .TOC. */
826 HOWTO (R_PPC64_TOC16, /* type */
827 0, /* rightshift */
828 1, /* size (0 = byte, 1 = short, 2 = long) */
829 16, /* bitsize */
830 false, /* pc_relative */
831 0, /* bitpos */
832 complain_overflow_signed, /* complain_on_overflow */
833 bfd_elf_generic_reloc, /* special_function */
834 "R_PPC64_TOC16", /* name */
835 false, /* partial_inplace */
836 0, /* src_mask */
837 0xffff, /* dst_mask */
838 false), /* pcrel_offset */
839
840 /* 16 bit TOC-relative relocation without overflow. */
841
842 /* R_PPC64_TOC16_LO 48 half16 #lo (S + A - .TOC.) */
843 HOWTO (R_PPC64_TOC16_LO, /* type */
844 0, /* rightshift */
845 1, /* size (0 = byte, 1 = short, 2 = long) */
846 16, /* bitsize */
847 false, /* pc_relative */
848 0, /* bitpos */
849 complain_overflow_dont, /* complain_on_overflow */
850 bfd_elf_generic_reloc, /* special_function */
851 "R_PPC64_TOC16_LO", /* name */
852 false, /* partial_inplace */
853 0, /* src_mask */
854 0xffff, /* dst_mask */
855 false), /* pcrel_offset */
856
857 /* 16 bit TOC-relative relocation, high 16 bits. */
858
859 /* R_PPC64_TOC16_HI 49 half16 #hi (S + A - .TOC.) */
860 HOWTO (R_PPC64_TOC16_HI, /* type */
861 16, /* rightshift */
862 1, /* size (0 = byte, 1 = short, 2 = long) */
863 16, /* bitsize */
864 false, /* pc_relative */
865 0, /* bitpos */
866 complain_overflow_dont, /* complain_on_overflow */
867 bfd_elf_generic_reloc, /* special_function */
868 "R_PPC64_TOC16_HI", /* name */
869 false, /* partial_inplace */
870 0, /* src_mask */
871 0xffff, /* dst_mask */
872 false), /* pcrel_offset */
873
874 /* 16 bit TOC-relative relocation, high 16 bits, plus 1 if the
875 contents of the low 16 bits, treated as a signed number, is
876 negative. */
877
878 /* R_PPC64_TOC16_HA 50 half16 #ha (S + A - .TOC.) */
879 HOWTO (R_PPC64_TOC16_HA, /* type */
880 16, /* rightshift */
881 1, /* size (0 = byte, 1 = short, 2 = long) */
882 16, /* bitsize */
883 false, /* pc_relative */
884 0, /* bitpos */
885 complain_overflow_dont, /* complain_on_overflow */
886 ppc64_elf_addr16_ha_reloc, /* special_function */
887 "R_PPC64_TOC16_HA", /* name */
888 false, /* partial_inplace */
889 0, /* src_mask */
890 0xffff, /* dst_mask */
891 false), /* pcrel_offset */
892
893 /* 64-bit relocation; insert value of TOC base (.TOC.). */
894
895 /* R_PPC64_TOC 51 doubleword64 .TOC. */
896 HOWTO (R_PPC64_TOC, /* type */
897 0, /* rightshift */
898 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
899 64, /* bitsize */
900 false, /* pc_relative */
901 0, /* bitpos */
902 complain_overflow_bitfield, /* complain_on_overflow */
903 bfd_elf_generic_reloc, /* special_function */
904 "R_PPC64_TOC", /* name */
905 false, /* partial_inplace */
906 0, /* src_mask */
907 0xffffffffffffffff, /* dst_mask */
908 false), /* pcrel_offset */
909
910 /* Like R_PPC64_GOT16, but also informs the link editor that the
911 value to relocate may (!) refer to a PLT entry which the link
912 editor (a) may replace with the symbol value. If the link editor
913 is unable to fully resolve the symbol, it may (b) create a PLT
914 entry and store the address to the new PLT entry in the GOT.
915 This permits lazy resolution of function symbols at run time.
916 The link editor may also skip all of this and just (c) emit a
917 R_PPC64_GLOB_DAT to tie the symbol to the GOT entry. */
918 /* FIXME: R_PPC64_PLTGOT16 not implemented. */
919 HOWTO (R_PPC64_PLTGOT16, /* type */
920 0, /* rightshift */
921 1, /* size (0 = byte, 1 = short, 2 = long) */
922 16, /* bitsize */
923 false, /* pc_relative */
924 0, /* bitpos */
925 complain_overflow_signed, /* complain_on_overflow */
926 bfd_elf_generic_reloc, /* special_function */
927 "R_PPC64_PLTGOT16", /* name */
928 false, /* partial_inplace */
929 0, /* src_mask */
930 0xffff, /* dst_mask */
931 false), /* pcrel_offset */
932
933 /* Like R_PPC64_PLTGOT16, but without overflow. */
934 /* FIXME: R_PPC64_PLTGOT16_LO not implemented. */
935 HOWTO (R_PPC64_PLTGOT16_LO, /* type */
936 0, /* rightshift */
937 1, /* size (0 = byte, 1 = short, 2 = long) */
938 16, /* bitsize */
939 false, /* pc_relative */
940 0, /* bitpos */
941 complain_overflow_dont, /* complain_on_overflow */
942 bfd_elf_generic_reloc, /* special_function */
943 "R_PPC64_PLTGOT16_LO", /* name */
944 false, /* partial_inplace */
945 0, /* src_mask */
946 0xffff, /* dst_mask */
947 false), /* pcrel_offset */
948
949 /* Like R_PPC64_PLT_GOT16, but using bits 16-31 of the address. */
950 /* FIXME: R_PPC64_PLTGOT16_HI not implemented. */
951 HOWTO (R_PPC64_PLTGOT16_HI, /* type */
952 16, /* rightshift */
953 1, /* size (0 = byte, 1 = short, 2 = long) */
954 16, /* bitsize */
955 false, /* pc_relative */
956 0, /* bitpos */
957 complain_overflow_dont, /* complain_on_overflow */
958 bfd_elf_generic_reloc, /* special_function */
959 "R_PPC64_PLTGOT16_HI", /* name */
960 false, /* partial_inplace */
961 0, /* src_mask */
962 0xffff, /* dst_mask */
963 false), /* pcrel_offset */
964
965 /* Like R_PPC64_PLT_GOT16, but using bits 16-31 of the address, plus
966 1 if the contents of the low 16 bits, treated as a signed number,
967 is negative. */
968 /* FIXME: R_PPC64_PLTGOT16_HA not implemented. */
969 HOWTO (R_PPC64_PLTGOT16_HA, /* type */
970 16, /* rightshift */
971 1, /* size (0 = byte, 1 = short, 2 = long) */
972 16, /* bitsize */
973 false, /* pc_relative */
974 0, /* bitpos */
975 complain_overflow_dont,/* complain_on_overflow */
976 ppc64_elf_addr16_ha_reloc, /* special_function */
977 "R_PPC64_PLTGOT16_HA", /* name */
978 false, /* partial_inplace */
979 0, /* src_mask */
980 0xffff, /* dst_mask */
981 false), /* pcrel_offset */
982
983 /* Like R_PPC64_ADDR16, but for instructions with a DS field. */
984 HOWTO (R_PPC64_ADDR16_DS, /* type */
985 0, /* rightshift */
986 1, /* size (0 = byte, 1 = short, 2 = long) */
987 16, /* bitsize */
988 false, /* pc_relative */
989 0, /* bitpos */
990 complain_overflow_bitfield, /* complain_on_overflow */
991 bfd_elf_generic_reloc, /* special_function */
992 "R_PPC64_ADDR16_DS", /* name */
993 false, /* partial_inplace */
994 0, /* src_mask */
995 0xfffc, /* dst_mask */
996 false), /* pcrel_offset */
997
998 /* Like R_PPC64_ADDR16_LO, but for instructions with a DS field. */
999 HOWTO (R_PPC64_ADDR16_LO_DS, /* type */
1000 0, /* rightshift */
1001 1, /* size (0 = byte, 1 = short, 2 = long) */
1002 16, /* bitsize */
1003 false, /* pc_relative */
1004 0, /* bitpos */
1005 complain_overflow_dont,/* complain_on_overflow */
1006 bfd_elf_generic_reloc, /* special_function */
1007 "R_PPC64_ADDR16_LO_DS",/* name */
1008 false, /* partial_inplace */
1009 0, /* src_mask */
1010 0xfffc, /* dst_mask */
1011 false), /* pcrel_offset */
1012
1013 /* Like R_PPC64_GOT16, but for instructions with a DS field. */
1014 HOWTO (R_PPC64_GOT16_DS, /* type */
1015 0, /* rightshift */
1016 1, /* size (0 = byte, 1 = short, 2 = long) */
1017 16, /* bitsize */
1018 false, /* pc_relative */
1019 0, /* bitpos */
1020 complain_overflow_signed, /* complain_on_overflow */
1021 bfd_elf_generic_reloc, /* special_function */
1022 "R_PPC64_GOT16_DS", /* name */
1023 false, /* partial_inplace */
1024 0, /* src_mask */
1025 0xfffc, /* dst_mask */
1026 false), /* pcrel_offset */
1027
1028 /* Like R_PPC64_GOT16_LO, but for instructions with a DS field. */
1029 HOWTO (R_PPC64_GOT16_LO_DS, /* type */
1030 0, /* rightshift */
1031 1, /* size (0 = byte, 1 = short, 2 = long) */
1032 16, /* bitsize */
1033 false, /* pc_relative */
1034 0, /* bitpos */
1035 complain_overflow_dont, /* complain_on_overflow */
1036 bfd_elf_generic_reloc, /* special_function */
1037 "R_PPC64_GOT16_LO_DS", /* name */
1038 false, /* partial_inplace */
1039 0, /* src_mask */
1040 0xfffc, /* dst_mask */
1041 false), /* pcrel_offset */
1042
1043 /* Like R_PPC64_PLT16_LO, but for instructions with a DS field. */
1044 HOWTO (R_PPC64_PLT16_LO_DS, /* type */
1045 0, /* rightshift */
1046 1, /* size (0 = byte, 1 = short, 2 = long) */
1047 16, /* bitsize */
1048 false, /* pc_relative */
1049 0, /* bitpos */
1050 complain_overflow_dont, /* complain_on_overflow */
1051 bfd_elf_generic_reloc, /* special_function */
1052 "R_PPC64_PLT16_LO_DS", /* name */
1053 false, /* partial_inplace */
1054 0, /* src_mask */
1055 0xfffc, /* dst_mask */
1056 false), /* pcrel_offset */
1057
1058 /* Like R_PPC64_SECTOFF, but for instructions with a DS field. */
1059 /* FIXME: Verify R_PPC64_SECTOFF. Seems strange with size=2 and
1060 dst_mask=0. */
1061 HOWTO (R_PPC64_SECTOFF_DS, /* type */
1062 0, /* rightshift */
1063 2, /* size (0 = byte, 1 = short, 2 = long) */
1064 32, /* bitsize */
1065 true, /* pc_relative */
1066 0, /* bitpos */
1067 complain_overflow_bitfield, /* complain_on_overflow */
1068 bfd_elf_generic_reloc, /* special_function */
1069 "R_PPC64_SECTOFF_DS", /* name */
1070 false, /* partial_inplace */
1071 0, /* src_mask */
1072 0, /* dst_mask */
1073 true), /* pcrel_offset */
1074
1075 /* Like R_PPC64_SECTOFF_LO, but for instructions with a DS field. */
1076 HOWTO (R_PPC64_SECTOFF_LO_DS, /* type */
1077 0, /* rightshift */
1078 1, /* size (0 = byte, 1 = short, 2 = long) */
1079 16, /* bitsize */
1080 false, /* pc_relative */
1081 0, /* bitpos */
1082 complain_overflow_dont, /* complain_on_overflow */
1083 bfd_elf_generic_reloc, /* special_function */
1084 "R_PPC64_SECTOFF_LO_DS",/* name */
1085 false, /* partial_inplace */
1086 0, /* src_mask */
1087 0xfffc, /* dst_mask */
1088 false), /* pcrel_offset */
1089
1090 /* Like R_PPC64_TOC16, but for instructions with a DS field. */
1091 HOWTO (R_PPC64_TOC16_DS, /* type */
1092 0, /* rightshift */
1093 1, /* size (0 = byte, 1 = short, 2 = long) */
1094 16, /* bitsize */
1095 false, /* pc_relative */
1096 0, /* bitpos */
1097 complain_overflow_signed, /* complain_on_overflow */
1098 bfd_elf_generic_reloc, /* special_function */
1099 "R_PPC64_TOC16_DS", /* name */
1100 false, /* partial_inplace */
1101 0, /* src_mask */
1102 0xfffc, /* dst_mask */
1103 false), /* pcrel_offset */
1104
1105 /* Like R_PPC64_TOC16_LO, but for instructions with a DS field. */
1106 HOWTO (R_PPC64_TOC16_LO_DS, /* type */
1107 0, /* rightshift */
1108 1, /* size (0 = byte, 1 = short, 2 = long) */
1109 16, /* bitsize */
1110 false, /* pc_relative */
1111 0, /* bitpos */
1112 complain_overflow_dont, /* complain_on_overflow */
1113 bfd_elf_generic_reloc, /* special_function */
1114 "R_PPC64_TOC16_LO_DS", /* name */
1115 false, /* partial_inplace */
1116 0, /* src_mask */
1117 0xfffc, /* dst_mask */
1118 false), /* pcrel_offset */
1119
1120 /* Like R_PPC64_PLTGOT16, but for instructions with a DS field. */
1121 /* FIXME: R_PPC64_PLTGOT16_DS not implemented. */
1122 HOWTO (R_PPC64_PLTGOT16_DS, /* type */
1123 0, /* rightshift */
1124 1, /* size (0 = byte, 1 = short, 2 = long) */
1125 16, /* bitsize */
1126 false, /* pc_relative */
1127 0, /* bitpos */
1128 complain_overflow_signed, /* complain_on_overflow */
1129 bfd_elf_generic_reloc, /* special_function */
1130 "R_PPC64_PLTGOT16_DS", /* name */
1131 false, /* partial_inplace */
1132 0, /* src_mask */
1133 0xfffc, /* dst_mask */
1134 false), /* pcrel_offset */
1135
1136 /* Like R_PPC64_PLTGOT16_LO, but for instructions with a DS field. */
1137 /* FIXME: R_PPC64_PLTGOT16_LO not implemented. */
1138 HOWTO (R_PPC64_PLTGOT16_LO_DS,/* type */
1139 0, /* rightshift */
1140 1, /* size (0 = byte, 1 = short, 2 = long) */
1141 16, /* bitsize */
1142 false, /* pc_relative */
1143 0, /* bitpos */
1144 complain_overflow_dont, /* complain_on_overflow */
1145 bfd_elf_generic_reloc, /* special_function */
1146 "R_PPC64_PLTGOT16_LO_DS",/* name */
1147 false, /* partial_inplace */
1148 0, /* src_mask */
1149 0xfffc, /* dst_mask */
1150 false), /* pcrel_offset */
1151
1152 /* GNU extension to record C++ vtable hierarchy. */
1153 HOWTO (R_PPC64_GNU_VTINHERIT, /* type */
1154 0, /* rightshift */
1155 0, /* size (0 = byte, 1 = short, 2 = long) */
1156 0, /* bitsize */
1157 false, /* pc_relative */
1158 0, /* bitpos */
1159 complain_overflow_dont, /* complain_on_overflow */
1160 NULL, /* special_function */
1161 "R_PPC64_GNU_VTINHERIT", /* name */
1162 false, /* partial_inplace */
1163 0, /* src_mask */
1164 0, /* dst_mask */
1165 false), /* pcrel_offset */
1166
1167 /* GNU extension to record C++ vtable member usage. */
1168 HOWTO (R_PPC64_GNU_VTENTRY, /* type */
1169 0, /* rightshift */
1170 0, /* size (0 = byte, 1 = short, 2 = long) */
1171 0, /* bitsize */
1172 false, /* pc_relative */
1173 0, /* bitpos */
1174 complain_overflow_dont, /* complain_on_overflow */
1175 NULL, /* special_function */
1176 "R_PPC64_GNU_VTENTRY", /* name */
1177 false, /* partial_inplace */
1178 0, /* src_mask */
1179 0, /* dst_mask */
1180 false), /* pcrel_offset */
1181};
1182
1183\f
1184/* Initialize the ppc64_elf_howto_table, so that linear accesses can
1185 be done. */
1186
1187static void
1188ppc_howto_init ()
1189{
1190 unsigned int i, type;
1191
1192 for (i = 0;
1193 i < sizeof (ppc64_elf_howto_raw) / sizeof (ppc64_elf_howto_raw[0]);
1194 i++)
1195 {
1196 type = ppc64_elf_howto_raw[i].type;
1197 BFD_ASSERT (type < (sizeof (ppc64_elf_howto_table)
1198 / sizeof (ppc64_elf_howto_table[0])));
1199 ppc64_elf_howto_table[type] = &ppc64_elf_howto_raw[i];
1200 }
1201}
1202
1203static reloc_howto_type *
1204ppc64_elf_reloc_type_lookup (abfd, code)
1205 bfd *abfd ATTRIBUTE_UNUSED;
1206 bfd_reloc_code_real_type code;
1207{
1208 enum elf_ppc_reloc_type ppc_reloc = R_PPC_NONE;
1209
1210 if (!ppc64_elf_howto_table[R_PPC64_ADDR32])
1211 /* Initialize howto table if needed. */
1212 ppc_howto_init ();
1213
1214 switch ((int) code)
1215 {
1216 default:
1217 return (reloc_howto_type *) NULL;
1218
1219 case BFD_RELOC_NONE: ppc_reloc = R_PPC64_NONE;
1220 break;
1221 case BFD_RELOC_32: ppc_reloc = R_PPC64_ADDR32;
1222 break;
1223 case BFD_RELOC_PPC_BA26: ppc_reloc = R_PPC64_ADDR24;
1224 break;
1225 case BFD_RELOC_16: ppc_reloc = R_PPC64_ADDR16;
1226 break;
1227 case BFD_RELOC_LO16: ppc_reloc = R_PPC64_ADDR16_LO;
1228 break;
1229 case BFD_RELOC_HI16: ppc_reloc = R_PPC64_ADDR16_HI;
1230 break;
1231 case BFD_RELOC_HI16_S: ppc_reloc = R_PPC64_ADDR16_HA;
1232 break;
1233 case BFD_RELOC_PPC_BA16: ppc_reloc = R_PPC64_ADDR14;
1234 break;
1235 case BFD_RELOC_PPC_BA16_BRTAKEN: ppc_reloc = R_PPC64_ADDR14_BRTAKEN;
1236 break;
1237 case BFD_RELOC_PPC_BA16_BRNTAKEN: ppc_reloc = R_PPC64_ADDR14_BRNTAKEN;
1238 break;
1239 case BFD_RELOC_PPC_B26: ppc_reloc = R_PPC64_REL24;
1240 break;
1241 case BFD_RELOC_PPC_B16: ppc_reloc = R_PPC64_REL14;
1242 break;
1243 case BFD_RELOC_PPC_B16_BRTAKEN: ppc_reloc = R_PPC64_REL14_BRTAKEN;
1244 break;
1245 case BFD_RELOC_PPC_B16_BRNTAKEN: ppc_reloc = R_PPC64_REL14_BRNTAKEN;
1246 break;
1247 case BFD_RELOC_16_GOTOFF: ppc_reloc = R_PPC64_GOT16;
1248 break;
1249 case BFD_RELOC_LO16_GOTOFF: ppc_reloc = R_PPC64_GOT16_LO;
1250 break;
1251 case BFD_RELOC_HI16_GOTOFF: ppc_reloc = R_PPC64_GOT16_HI;
1252 break;
1253 case BFD_RELOC_HI16_S_GOTOFF: ppc_reloc = R_PPC64_GOT16_HA;
1254 break;
1255 case BFD_RELOC_PPC_COPY: ppc_reloc = R_PPC64_COPY;
1256 break;
1257 case BFD_RELOC_PPC_GLOB_DAT: ppc_reloc = R_PPC64_GLOB_DAT;
1258 break;
1259 case BFD_RELOC_32_PCREL: ppc_reloc = R_PPC64_REL32;
1260 break;
1261 case BFD_RELOC_32_PLTOFF: ppc_reloc = R_PPC64_PLT32;
1262 break;
1263 case BFD_RELOC_32_PLT_PCREL: ppc_reloc = R_PPC64_PLTREL32;
1264 break;
1265 case BFD_RELOC_LO16_PLTOFF: ppc_reloc = R_PPC64_PLT16_LO;
1266 break;
1267 case BFD_RELOC_HI16_PLTOFF: ppc_reloc = R_PPC64_PLT16_HI;
1268 break;
1269 case BFD_RELOC_HI16_S_PLTOFF: ppc_reloc = R_PPC64_PLT16_HA;
1270 break;
1271 case BFD_RELOC_32_BASEREL: ppc_reloc = R_PPC64_SECTOFF;
1272 break;
1273 case BFD_RELOC_LO16_BASEREL: ppc_reloc = R_PPC64_SECTOFF_LO;
1274 break;
1275 case BFD_RELOC_HI16_BASEREL: ppc_reloc = R_PPC64_SECTOFF_HI;
1276 break;
1277 case BFD_RELOC_HI16_S_BASEREL: ppc_reloc = R_PPC64_SECTOFF_HA;
1278 break;
1279 /* FIXME: Is CTOR 32 or 64 bits? Fix md_apply_fix3 in
1280 gas/config/tc-ppc.c too. */
1281 case BFD_RELOC_CTOR: ppc_reloc = R_PPC64_ADDR32;
1282 break;
1283 case BFD_RELOC_64: ppc_reloc = R_PPC64_ADDR64;
1284 break;
1285 case BFD_RELOC_PPC64_HIGHER: ppc_reloc = R_PPC64_ADDR16_HIGHER;
1286 break;
1287 case BFD_RELOC_PPC64_HIGHER_S: ppc_reloc = R_PPC64_ADDR16_HIGHERA;
1288 break;
1289 case BFD_RELOC_PPC64_HIGHEST: ppc_reloc = R_PPC64_ADDR16_HIGHEST;
1290 break;
1291 case BFD_RELOC_PPC64_HIGHEST_S: ppc_reloc = R_PPC64_ADDR16_HIGHESTA;
1292 break;
1293 case BFD_RELOC_64_PCREL: ppc_reloc = R_PPC64_REL64;
1294 break;
1295 case BFD_RELOC_64_PLTOFF: ppc_reloc = R_PPC64_PLT64;
1296 break;
1297 case BFD_RELOC_64_PLT_PCREL: ppc_reloc = R_PPC64_PLTREL64;
1298 break;
1299 case BFD_RELOC_PPC_TOC16: ppc_reloc = R_PPC64_TOC16;
1300 break;
1301 case BFD_RELOC_PPC64_TOC16_LO: ppc_reloc = R_PPC64_TOC16_LO;
1302 break;
1303 case BFD_RELOC_PPC64_TOC16_HI: ppc_reloc = R_PPC64_TOC16_HI;
1304 break;
1305 case BFD_RELOC_PPC64_TOC16_HA: ppc_reloc = R_PPC64_TOC16_HA;
1306 break;
1307 case BFD_RELOC_PPC64_TOC: ppc_reloc = R_PPC64_TOC;
1308 break;
1309 case BFD_RELOC_PPC64_PLTGOT16: ppc_reloc = R_PPC64_PLTGOT16;
1310 break;
1311 case BFD_RELOC_PPC64_PLTGOT16_LO: ppc_reloc = R_PPC64_PLTGOT16_LO;
1312 break;
1313 case BFD_RELOC_PPC64_PLTGOT16_HI: ppc_reloc = R_PPC64_PLTGOT16_HI;
1314 break;
1315 case BFD_RELOC_PPC64_PLTGOT16_HA: ppc_reloc = R_PPC64_PLTGOT16_HA;
1316 break;
1317 case BFD_RELOC_PPC64_ADDR16_DS: ppc_reloc = R_PPC64_ADDR16_DS;
1318 break;
1319 case BFD_RELOC_PPC64_ADDR16_LO_DS: ppc_reloc = R_PPC64_ADDR16_LO_DS;
1320 break;
1321 case BFD_RELOC_PPC64_GOT16_DS: ppc_reloc = R_PPC64_GOT16_DS;
1322 break;
1323 case BFD_RELOC_PPC64_GOT16_LO_DS: ppc_reloc = R_PPC64_GOT16_LO_DS;
1324 break;
1325 case BFD_RELOC_PPC64_PLT16_LO_DS: ppc_reloc = R_PPC64_PLT16_LO_DS;
1326 break;
1327 case BFD_RELOC_PPC64_SECTOFF_DS: ppc_reloc = R_PPC64_SECTOFF_DS;
1328 break;
1329 case BFD_RELOC_PPC64_SECTOFF_LO_DS: ppc_reloc = R_PPC64_SECTOFF_LO_DS;
1330 break;
1331 case BFD_RELOC_PPC64_TOC16_DS: ppc_reloc = R_PPC64_TOC16_DS;
1332 break;
1333 case BFD_RELOC_PPC64_TOC16_LO_DS: ppc_reloc = R_PPC64_TOC16_LO_DS;
1334 break;
1335 case BFD_RELOC_PPC64_PLTGOT16_DS: ppc_reloc = R_PPC64_PLTGOT16_DS;
1336 break;
1337 case BFD_RELOC_PPC64_PLTGOT16_LO_DS: ppc_reloc = R_PPC64_PLTGOT16_LO_DS;
1338 break;
1339 case BFD_RELOC_VTABLE_INHERIT: ppc_reloc = R_PPC64_GNU_VTINHERIT;
1340 break;
1341 case BFD_RELOC_VTABLE_ENTRY: ppc_reloc = R_PPC64_GNU_VTENTRY;
1342 break;
1343 }
1344
1345 return ppc64_elf_howto_table[(int) ppc_reloc];
1346};
1347
1348/* Set the howto pointer for a PowerPC ELF reloc. */
1349
1350static void
1351ppc64_elf_info_to_howto (abfd, cache_ptr, dst)
1352 bfd *abfd ATTRIBUTE_UNUSED;
1353 arelent *cache_ptr;
1354 Elf64_Internal_Rela *dst;
1355{
1356 if (!ppc64_elf_howto_table[R_PPC64_ADDR32])
1357 /* Initialize howto table if needed. */
1358 ppc_howto_init ();
1359
1360 BFD_ASSERT (ELF64_R_TYPE (dst->r_info) < (unsigned int) R_PPC_max);
1361 cache_ptr->howto = ppc64_elf_howto_table[ELF64_R_TYPE (dst->r_info)];
1362}
1363
1364/* Handle the R_PPC_ADDR16_HA reloc. */
1365
1366static bfd_reloc_status_type
1367ppc64_elf_addr16_ha_reloc (abfd, reloc_entry, symbol, data, input_section,
1368 output_bfd, error_message)
1369 bfd *abfd ATTRIBUTE_UNUSED;
1370 arelent *reloc_entry;
1371 asymbol *symbol;
1372 PTR data ATTRIBUTE_UNUSED;
1373 asection *input_section;
1374 bfd *output_bfd;
1375 char **error_message ATTRIBUTE_UNUSED;
1376{
1377 bfd_vma relocation;
1378
1379 if (output_bfd != NULL)
1380 {
1381 reloc_entry->address += input_section->output_offset;
1382 return bfd_reloc_ok;
1383 }
1384
1385 if (reloc_entry->address > input_section->_cooked_size)
1386 return bfd_reloc_outofrange;
1387
1388 if (bfd_is_com_section (symbol->section))
1389 relocation = 0;
1390 else
1391 relocation = symbol->value;
1392
1393 relocation += symbol->section->output_section->vma;
1394 relocation += symbol->section->output_offset;
1395 relocation += reloc_entry->addend;
1396
1397 reloc_entry->addend += (relocation & 0x8000) << 1;
1398
1399 return bfd_reloc_continue;
1400}
1401
1402/* Function to set whether a module needs the -mrelocatable bit set. */
1403
1404static boolean
1405ppc64_elf_set_private_flags (abfd, flags)
1406 bfd *abfd;
1407 flagword flags;
1408{
1409 BFD_ASSERT (!elf_flags_init (abfd)
1410 || elf_elfheader (abfd)->e_flags == flags);
1411
1412 elf_elfheader (abfd)->e_flags = flags;
1413 elf_flags_init (abfd) = true;
1414 return true;
1415}
1416
1417/* Copy backend specific data from one object module to another. */
1418static boolean
1419ppc64_elf_copy_private_bfd_data (ibfd, obfd)
1420 bfd *ibfd;
1421 bfd *obfd;
1422{
1423 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
1424 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
1425 return true;
1426
1427 BFD_ASSERT (!elf_flags_init (obfd)
1428 || elf_elfheader (obfd)->e_flags == elf_elfheader (ibfd)->e_flags);
1429
1430 elf_elfheader (obfd)->e_flags = elf_elfheader (ibfd)->e_flags;
1431 elf_flags_init (obfd) = true;
1432 return true;
1433}
1434
1435/* Merge backend specific data from an object file to the output
1436 object file when linking. */
1437static boolean
1438ppc64_elf_merge_private_bfd_data (ibfd, obfd)
1439 bfd *ibfd;
1440 bfd *obfd;
1441{
1442 flagword old_flags;
1443 flagword new_flags;
1444 boolean error;
1445
1446 /* Check if we have the same endianess. */
1447 if (ibfd->xvec->byteorder != obfd->xvec->byteorder
1448 && obfd->xvec->byteorder != BFD_ENDIAN_UNKNOWN)
1449 {
1450 const char *msg;
1451
1452 if (bfd_big_endian (ibfd))
1453 msg = _("%s: compiled for a big endian system and target is little endian");
1454 else
1455 msg = _("%s: compiled for a little endian system and target is big endian");
1456
1457 (*_bfd_error_handler) (msg, bfd_get_filename (ibfd));
1458
1459 bfd_set_error (bfd_error_wrong_format);
1460 return false;
1461 }
1462
1463 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
1464 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
1465 return true;
1466
1467 new_flags = elf_elfheader (ibfd)->e_flags;
1468 old_flags = elf_elfheader (obfd)->e_flags;
1469 if (!elf_flags_init (obfd))
1470 {
1471 /* First call, no flags set. */
1472 elf_flags_init (obfd) = true;
1473 elf_elfheader (obfd)->e_flags = new_flags;
1474 }
1475
1476 else if (new_flags == old_flags)
1477 /* Compatible flags are ok. */
1478 ;
1479
1480 else
1481 {
1482 /* Incompatible flags. Warn about -mrelocatable mismatch.
1483 Allow -mrelocatable-lib to be linked with either. */
1484 error = false;
1485 if ((new_flags & EF_PPC_RELOCATABLE) != 0
1486 && (old_flags & (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB)) == 0)
1487 {
1488 error = true;
1489 (*_bfd_error_handler)
1490 (_("%s: compiled with -mrelocatable and linked with modules compiled normally"),
1491 bfd_get_filename (ibfd));
1492 }
1493 else if ((new_flags & (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB)) == 0
1494 && (old_flags & EF_PPC_RELOCATABLE) != 0)
1495 {
1496 error = true;
1497 (*_bfd_error_handler)
1498 (_("%s: compiled normally and linked with modules compiled with -mrelocatable"),
1499 bfd_get_filename (ibfd));
1500 }
1501
1502 /* The output is -mrelocatable-lib iff both the input files are. */
1503 if (! (new_flags & EF_PPC_RELOCATABLE_LIB))
1504 elf_elfheader (obfd)->e_flags &= ~EF_PPC_RELOCATABLE_LIB;
1505
1506 /* The output is -mrelocatable iff it can't be -mrelocatable-lib,
1507 but each input file is either -mrelocatable or -mrelocatable-lib. */
1508 if (! (elf_elfheader (obfd)->e_flags & EF_PPC_RELOCATABLE_LIB)
1509 && (new_flags & (EF_PPC_RELOCATABLE_LIB | EF_PPC_RELOCATABLE))
1510 && (old_flags & (EF_PPC_RELOCATABLE_LIB | EF_PPC_RELOCATABLE)))
1511 elf_elfheader (obfd)->e_flags |= EF_PPC_RELOCATABLE;
1512
1513 /* Do not warn about eabi vs. V.4 mismatch, just or in the bit
1514 if any module uses it. */
1515 elf_elfheader (obfd)->e_flags |= (new_flags & EF_PPC_EMB);
1516
1517 new_flags &= ~(EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB | EF_PPC_EMB);
1518 old_flags &= ~(EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB | EF_PPC_EMB);
1519
1520 /* Warn about any other mismatches. */
1521 if (new_flags != old_flags)
1522 {
1523 error = true;
1524 (*_bfd_error_handler)
1525 (_("%s: uses different e_flags (0x%lx) fields than previous modules (0x%lx)"),
1526 bfd_get_filename (ibfd), (long) new_flags, (long) old_flags);
1527 }
1528
1529 if (error)
1530 {
1531 bfd_set_error (bfd_error_bad_value);
1532 return false;
1533 }
1534 }
1535
1536 return true;
1537}
1538
1539/* Handle a PowerPC specific section when reading an object file. This
1540 is called when elfcode.h finds a section with an unknown type. */
1541
1542static boolean
1543ppc64_elf_section_from_shdr (abfd, hdr, name)
1544 bfd *abfd;
1545 Elf64_Internal_Shdr *hdr;
1546 char *name;
1547{
1548 asection *newsect;
1549 flagword flags;
1550
1551 if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name))
1552 return false;
1553
1554 newsect = hdr->bfd_section;
1555 flags = bfd_get_section_flags (abfd, newsect);
1556 if (hdr->sh_flags & SHF_EXCLUDE)
1557 flags |= SEC_EXCLUDE;
1558
1559 if (hdr->sh_type == SHT_ORDERED)
1560 flags |= SEC_SORT_ENTRIES;
1561
1562 bfd_set_section_flags (abfd, newsect, flags);
1563 return true;
1564}
1565\f
1566/* The following routines are specific to the ELF linker, while
1567 routines above are used generally. They appear in this file more
1568 or less in the order in which they are called from external
1569 routines. eg. ppc64_elf_check_relocs is called early in the link
1570 process, ppc64_elf_finish_dynamic_sections is one of the last
1571 functions called. */
1572
1573/* Create the .glink section as well as the ordinary dynamic
1574 sections. */
1575
1576static boolean
1577ppc64_elf_create_dynamic_sections (abfd, info)
1578 bfd *abfd;
1579 struct bfd_link_info *info;
1580{
1581 asection *s;
1582 flagword flags;
1583
1584 if (!_bfd_elf_create_dynamic_sections (abfd, info))
1585 return false;
1586
1587 /* Our .plt just contains pointers, no code. */
1588 s = bfd_get_section_by_name (abfd, ".plt");
1589 if (s == NULL)
1590 return false;
1591 flags = bfd_get_section_flags (abfd, s);
1592 flags &= ~SEC_CODE;
1593 if (! bfd_set_section_flags (abfd, s, flags))
1594 return false;
1595
1596 /* Create .glink for global linkage functions. */
1597 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
1598 | SEC_LINKER_CREATED);
1599 s = bfd_make_section (abfd, ".glink");
1600 if (s == NULL
1601 || ! bfd_set_section_flags (abfd, s, flags)
1602 || ! bfd_set_section_alignment (abfd, s, 3))
1603 return false;
1604
1605 return true;
1606}
1607
1608/* Look through the relocs for a section during the first phase, and
1609 allocate space in the global offset table or procedure linkage
1610 table. */
1611
1612static boolean
1613ppc64_elf_check_relocs (abfd, info, sec, relocs)
1614 bfd *abfd;
1615 struct bfd_link_info *info;
1616 asection *sec;
1617 const Elf_Internal_Rela *relocs;
1618{
1619 bfd *dynobj;
1620 Elf_Internal_Shdr *symtab_hdr;
1621 struct elf_link_hash_entry **sym_hashes, **sym_hashes_end;
1622 const Elf_Internal_Rela *rel;
1623 const Elf_Internal_Rela *rel_end;
1624 bfd_signed_vma *local_got_refcounts;
1625 asection *sreloc;
1626 asection *sgot = NULL;
1627 asection *srelgot = NULL;
1628
1629 if (info->relocateable)
1630 return true;
1631
1632#ifdef DEBUG
1633 fprintf (stderr, "ppc64_elf_check_relocs called for section %s in %s\n",
1634 bfd_get_section_name (abfd, sec),
1635 bfd_get_filename (abfd));
1636#endif
1637
1638 dynobj = elf_hash_table (info)->dynobj;
1639 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
1640 local_got_refcounts = elf_local_got_refcounts (abfd);
1641
1642 sym_hashes = elf_sym_hashes (abfd);
1643 sym_hashes_end = (sym_hashes
1644 + symtab_hdr->sh_size / sizeof (Elf64_External_Sym));
1645 if (!elf_bad_symtab (abfd))
1646 sym_hashes_end -= symtab_hdr->sh_info;
1647
1648 sreloc = NULL;
1649
1650 rel_end = relocs + sec->reloc_count;
1651 for (rel = relocs; rel < rel_end; rel++)
1652 {
1653 unsigned long r_symndx;
1654 struct elf_link_hash_entry *h;
1655
1656 r_symndx = ELF64_R_SYM (rel->r_info);
1657 if (r_symndx < symtab_hdr->sh_info)
1658 h = NULL;
1659 else
1660 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
1661
1662 switch (ELF64_R_TYPE (rel->r_info))
1663 {
1664 /* GOT16 relocations */
1665 case R_PPC64_GOT16:
1666 case R_PPC64_GOT16_LO:
1667 case R_PPC64_GOT16_HI:
1668 case R_PPC64_GOT16_HA:
1669 case R_PPC64_GOT16_DS:
1670 case R_PPC64_GOT16_LO_DS:
1671 /* This symbol requires a global offset table entry. */
1672
1673 if (sgot == NULL)
1674 {
1675 if (dynobj == NULL)
1676 elf_hash_table (info)->dynobj = dynobj = abfd;
1677 if (! _bfd_elf_create_got_section (dynobj, info))
1678 return false;
1679 sgot = bfd_get_section_by_name (dynobj, ".got");
1680 BFD_ASSERT (sgot != NULL);
1681 }
1682
1683 if (srelgot == NULL
1684 && (h != NULL || info->shared))
1685 {
1686 srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
1687 if (srelgot == NULL)
1688 {
1689 srelgot = bfd_make_section (dynobj, ".rela.got");
1690 if (srelgot == NULL
1691 || ! bfd_set_section_flags (dynobj, srelgot,
1692 (SEC_ALLOC
1693 | SEC_LOAD
1694 | SEC_HAS_CONTENTS
1695 | SEC_IN_MEMORY
1696 | SEC_LINKER_CREATED
1697 | SEC_READONLY))
1698 || ! bfd_set_section_alignment (dynobj, srelgot, 2))
1699 return false;
1700 }
1701 }
1702
1703 if (h != NULL)
1704 {
1705 if (h->got.refcount == -1)
1706 {
1707 /* Make sure this symbol is output as a dynamic symbol. */
1708 if (h->dynindx == -1)
1709 if (!bfd_elf64_link_record_dynamic_symbol (info, h))
1710 return false;
1711
1712 /* Allocate space in the .got. */
1713 sgot->_raw_size += 8;
1714 /* Allocate relocation space. */
1715 srelgot->_raw_size += sizeof (Elf64_External_Rela);
1716
1717 h->got.refcount = 1;
1718 }
1719 else
1720 h->got.refcount++;
1721 }
1722 else
1723 {
1724 /* This is a global offset table entry for a local symbol. */
1725 if (local_got_refcounts == NULL)
1726 {
1727 size_t size;
1728
1729 size = symtab_hdr->sh_info * sizeof (bfd_signed_vma);
1730 local_got_refcounts = (bfd_signed_vma *)
1731 bfd_alloc (abfd, size);
1732 if (local_got_refcounts == NULL)
1733 return false;
1734 elf_local_got_refcounts (abfd) = local_got_refcounts;
1735 memset (local_got_refcounts, -1, size);
1736 }
1737 if (local_got_refcounts[r_symndx] == -1)
1738 {
1739 sgot->_raw_size += 8;
1740
1741 /* If we are generating a shared object, we need to
1742 output a R_PPC64_RELATIVE reloc so that the
1743 dynamic linker can adjust this GOT entry. */
1744 if (info->shared)
1745 srelgot->_raw_size += sizeof (Elf64_External_Rela);
1746
1747 local_got_refcounts[r_symndx] = 1;
1748 }
1749 else
1750 local_got_refcounts[r_symndx]++;
1751 }
1752 break;
1753
1754 case R_PPC64_PLT64:
1755 case R_PPC64_PLT32:
1756 case R_PPC64_PLT16_LO:
1757 case R_PPC64_PLT16_HI:
1758 case R_PPC64_PLT16_HA:
1759 case R_PPC64_PLTGOT16_DS:
1760 case R_PPC64_PLTGOT16_LO_DS:
1761#ifdef DEBUG
1762 fprintf (stderr, "Reloc requires a PLT entry\n");
1763#endif
1764 /* This symbol requires a procedure linkage table entry. We
1765 actually build the entry in adjust_dynamic_symbol,
1766 because this might be a case of linking PIC code without
1767 linking in any dynamic objects, in which case we don't
1768 need to generate a procedure linkage table after all. */
1769
1770 if (h == NULL)
1771 {
1772 /* It does not make sense to have a procedure linkage
1773 table entry for a local symbol. */
1774 bfd_set_error (bfd_error_bad_value);
1775 return false;
1776 }
1777
1778 /* Make sure this symbol is output as a dynamic symbol. */
1779 if (h->dynindx == -1)
1780 {
1781 if (! bfd_elf64_link_record_dynamic_symbol (info, h))
1782 return false;
1783 }
1784 if (h->plt.refcount == -1)
1785 {
1786 h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
1787 h->plt.refcount = 1;
1788 }
1789 else
1790 h->plt.refcount++;
1791 break;
1792
1793 /* The following relocations don't need to propagate the
1794 relocation if linking a shared object since they are
1795 section relative. */
1796 case R_PPC64_SECTOFF:
1797 case R_PPC64_SECTOFF_LO:
1798 case R_PPC64_SECTOFF_HI:
1799 case R_PPC64_SECTOFF_HA:
1800 case R_PPC64_SECTOFF_DS:
1801 case R_PPC64_SECTOFF_LO_DS:
1802 case R_PPC64_TOC16:
1803 case R_PPC64_TOC16_LO:
1804 case R_PPC64_TOC16_HI:
1805 case R_PPC64_TOC16_HA:
1806 case R_PPC64_TOC16_DS:
1807 case R_PPC64_TOC16_LO_DS:
1808 break;
1809
1810 /* This relocation describes the C++ object vtable hierarchy.
1811 Reconstruct it for later use during GC. */
1812 case R_PPC64_GNU_VTINHERIT:
1813 if (!_bfd_elf64_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
1814 return false;
1815 break;
1816
1817 /* This relocation describes which C++ vtable entries are actually
1818 used. Record for later use during GC. */
1819 case R_PPC64_GNU_VTENTRY:
1820 if (!_bfd_elf64_gc_record_vtentry (abfd, sec, h, rel->r_addend))
1821 return false;
1822 break;
1823
1824 /* When creating a shared object, we must copy these
1825 relocs into the output file. We create a reloc
1826 section in dynobj and make room for the reloc. */
1827 case R_PPC64_REL64:
1828 case R_PPC64_REL32:
1829 case R_PPC64_REL24:
1830 case R_PPC64_REL14:
1831 case R_PPC64_REL14_BRTAKEN:
1832 case R_PPC64_REL14_BRNTAKEN:
1833 if (h == NULL)
1834 break;
1835 /* fall through */
1836
1837 case R_PPC64_TOC:
1838 /* fall through */
1839
1840 default:
1841 if (info->shared)
1842 {
1843#ifdef DEBUG
1844 fprintf (stderr, "ppc64_elf_check_relocs need to create relocation for %s\n",
1845 (h && h->root.root.string
1846 ? h->root.root.string
1847 : "<unknown>"));
1848#endif
1849 if (sreloc == NULL)
1850 {
1851 const char *name;
1852
1853 name = (bfd_elf_string_from_elf_section
1854 (abfd,
1855 elf_elfheader (abfd)->e_shstrndx,
1856 elf_section_data (sec)->rel_hdr.sh_name));
1857 if (name == NULL)
1858 return false;
1859
1860 BFD_ASSERT (strncmp (name, ".rela", 5) == 0
1861 && strcmp (bfd_get_section_name (abfd, sec),
1862 name + 5) == 0);
1863
1864 sreloc = bfd_get_section_by_name (dynobj, name);
1865 if (sreloc == NULL)
1866 {
1867 flagword flags;
1868
1869 sreloc = bfd_make_section (dynobj, name);
1870 flags = (SEC_HAS_CONTENTS | SEC_READONLY
1871 | SEC_IN_MEMORY | SEC_LINKER_CREATED);
1872 if ((sec->flags & SEC_ALLOC) != 0)
1873 flags |= SEC_ALLOC | SEC_LOAD;
1874 if (sreloc == NULL
1875 || ! bfd_set_section_flags (dynobj, sreloc, flags)
1876 || ! bfd_set_section_alignment (dynobj, sreloc, 2))
1877 return false;
1878 }
1879 }
1880
1881 sreloc->_raw_size += sizeof (Elf64_External_Rela);
1882
1883 /* FIXME: We should here do what the m68k and i386
1884 backends do: if the reloc is pc-relative, record it
1885 in case it turns out that the reloc is unnecessary
1886 because the symbol is forced local by versioning or
1887 we are linking with -Bdynamic. Fortunately this
1888 case is not frequent. */
1889 }
1890
1891 break;
1892 }
1893 }
1894
1895 return true;
1896}
1897
1898/* Return the section that should be marked against GC for a given
1899 relocation. */
1900
1901static asection *
1902ppc64_elf_gc_mark_hook (abfd, info, rel, h, sym)
1903 bfd *abfd;
1904 struct bfd_link_info *info ATTRIBUTE_UNUSED;
1905 Elf_Internal_Rela *rel;
1906 struct elf_link_hash_entry *h;
1907 Elf_Internal_Sym *sym;
1908{
1909 if (h != NULL)
1910 {
1911 switch (ELF64_R_TYPE (rel->r_info))
1912 {
1913 case R_PPC64_GNU_VTINHERIT:
1914 case R_PPC64_GNU_VTENTRY:
1915 break;
1916
1917 default:
1918 switch (h->root.type)
1919 {
1920 case bfd_link_hash_defined:
1921 case bfd_link_hash_defweak:
1922 return h->root.u.def.section;
1923
1924 case bfd_link_hash_common:
1925 return h->root.u.c.p->section;
1926
1927 default:
1928 break;
1929 }
1930 }
1931 }
1932 else
1933 {
1934 if (! (elf_bad_symtab (abfd)
1935 && ELF_ST_BIND (sym->st_info) != STB_LOCAL)
1936 && ! ((sym->st_shndx <= 0 || sym->st_shndx >= SHN_LORESERVE)
1937 && sym->st_shndx != SHN_COMMON))
1938 {
1939 return bfd_section_from_elf_index (abfd, sym->st_shndx);
1940 }
1941 }
1942
1943 return NULL;
1944}
1945
1946/* Update the got entry reference counts for the section being removed. */
1947
1948static boolean
1949ppc64_elf_gc_sweep_hook (abfd, info, sec, relocs)
1950 bfd *abfd;
1951 struct bfd_link_info *info ATTRIBUTE_UNUSED;
1952 asection *sec;
1953 const Elf_Internal_Rela *relocs;
1954{
1955 Elf_Internal_Shdr *symtab_hdr;
1956 struct elf_link_hash_entry **sym_hashes;
1957 bfd_signed_vma *local_got_refcounts;
1958 const Elf_Internal_Rela *rel, *relend;
1959 unsigned long r_symndx;
1960 struct elf_link_hash_entry *h;
1961
1962 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
1963 sym_hashes = elf_sym_hashes (abfd);
1964 local_got_refcounts = elf_local_got_refcounts (abfd);
1965
1966 relend = relocs + sec->reloc_count;
1967 for (rel = relocs; rel < relend; rel++)
1968 switch (ELF64_R_TYPE (rel->r_info))
1969 {
1970 case R_PPC64_GOT16:
1971 case R_PPC64_GOT16_LO:
1972 case R_PPC64_GOT16_HI:
1973 case R_PPC64_GOT16_HA:
1974 r_symndx = ELF64_R_SYM (rel->r_info);
1975 if (r_symndx >= symtab_hdr->sh_info)
1976 {
1977 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
1978 if (h->got.refcount > 0)
1979 h->got.refcount--;
1980 }
1981 else
1982 {
1983 if (local_got_refcounts[r_symndx] > 0)
1984 local_got_refcounts[r_symndx]--;
1985 }
1986 break;
1987
1988 case R_PPC64_PLT32:
1989 case R_PPC64_PLT16_LO:
1990 case R_PPC64_PLT16_HI:
1991 case R_PPC64_PLT16_HA:
1992 r_symndx = ELF64_R_SYM (rel->r_info);
1993 if (r_symndx >= symtab_hdr->sh_info)
1994 {
1995 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
1996 if (h->plt.refcount > 0)
1997 h->plt.refcount--;
1998 }
1999 break;
2000
2001 default:
2002 break;
2003 }
2004
2005 return true;
2006}
2007
2008/* Adjust a symbol defined by a dynamic object and referenced by a
2009 regular object. The current definition is in some section of the
2010 dynamic object, but we're not including those sections. We have to
2011 change the definition to something the rest of the link can
2012 understand. */
2013
2014static boolean
2015ppc64_elf_adjust_dynamic_symbol (info, h)
2016 struct bfd_link_info *info;
2017 struct elf_link_hash_entry *h;
2018{
2019 bfd *dynobj = elf_hash_table (info)->dynobj;
2020 asection *s;
2021 unsigned int power_of_two;
2022 bfd_vma plt_offset;
2023
2024#ifdef DEBUG
2025 fprintf (stderr, "ppc64_elf_adjust_dynamic_symbol called for %s\n",
2026 h->root.root.string);
2027#endif
2028
2029 /* Make sure we know what is going on here. */
2030 BFD_ASSERT (dynobj != NULL
2031 && ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT)
2032 || h->weakdef != NULL
2033 || ((h->elf_link_hash_flags
2034 & ELF_LINK_HASH_DEF_DYNAMIC) != 0
2035 && (h->elf_link_hash_flags
2036 & ELF_LINK_HASH_REF_REGULAR) != 0
2037 && (h->elf_link_hash_flags
2038 & ELF_LINK_HASH_DEF_REGULAR) == 0)));
2039
2040 /* If this is a function, alter the symbol to refer to global
2041 linkage code, which will be generated by ppc64_elf_relocate_section.
2042 Also, allocate a slot in the PLT. */
2043 if (h->type == STT_FUNC
2044 || (h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0)
2045 {
2046 asection *splt, *sglink;
2047
2048 if (! elf_hash_table (info)->dynamic_sections_created
2049 || ((!info->shared || info->symbolic || h->dynindx == -1)
2050 && (h->elf_link_hash_flags
2051 & ELF_LINK_HASH_DEF_REGULAR) != 0))
2052 {
2053 /* A PLT entry is not required/allowed when:
2054
2055 1. We are not using ld.so; because then the PLT entry
2056 can't be set up, so we can't use one.
2057
2058 2. We know for certain that a symbol is defined in
2059 this object, because this object is the application,
2060 is linked with -Bsymbolic, or because the symbol is local.
2061
2062 We used to end up here for GC if
2063 (info->shared && h->plt.refcount <= 0)
2064 We can't use plt.refcount here since
2065 ppc64_elf_check_relocs can't detect all needs for
2066 PLT. FIXME: Rewrite GC. */
2067
2068 h->plt.offset = (bfd_vma) -1;
2069 h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
2070 return true;
2071 }
2072
2073 splt = bfd_get_section_by_name (dynobj, ".plt");
2074 sglink = bfd_get_section_by_name (dynobj, ".glink");
2075 BFD_ASSERT (splt != NULL && sglink != NULL);
2076
2077 /* If it's a function entry point (the name starts with a dot)
2078 (FIXME: Could it ever be anything else?), find its
2079 corresponding function descriptor symbol and make sure it's
2080 output as a dynamic symbol. Create it as undefined if
2081 necessary. ppc64_elf_finish_dynamic_symbol will look it up
2082 again and create a JMP_SLOT reloc for it. FIXME: The second
2083 lookup could be avoided by adding a new flag to
2084 elf_link_hash_entry->elf_link_hash_flags. */
2085
2086 if (h->root.root.string[0] == '.')
2087 {
2088 struct elf_link_hash_entry *fdh;
2089
2090 /* FIXME: Follow bfd_link_hash_indirect? */
2091 fdh = elf_link_hash_lookup (elf_hash_table (info),
2092 h->root.root.string + 1,
2093 false, false, false);
2094
2095 if (fdh == (struct elf_link_hash_entry *) NULL)
2096 {
2097 asymbol *newsym;
2098
2099 /* Create it as undefined. */
2100 newsym = bfd_make_empty_symbol (dynobj);
2101 BFD_ASSERT (newsym != NULL);
2102 /* FIXME: Need own copy of name? */
2103 newsym->name = h->root.root.string + 1;
2104 newsym->section = bfd_und_section_ptr;
2105 newsym->value = 0;
2106 newsym->flags = BSF_DYNAMIC | BSF_OBJECT;
2107
2108 if ( ! (_bfd_generic_link_add_one_symbol
2109 (info, dynobj, newsym->name, newsym->flags,
2110 newsym->section, newsym->value,
2111 NULL, /* string */
2112 true, /* copy */
2113 false, /*collect*/
2114 (struct bfd_link_hash_entry **) &fdh)))
2115 {
2116 /* FIXME: Print error message. */
2117 return false;
2118 }
2119 fdh->root.type = bfd_link_hash_undefined;
2120#ifdef DEBUG
2121 fprintf (stderr, "\tcreated %s", newsym->name);
2122#endif
2123 }
2124#ifdef DEBUG
2125 else
2126 fprintf (stderr, "\tfound %s", fdh->root.root.string);
2127 fprintf (stderr, "\n");
2128#endif
2129
2130 BFD_ASSERT (fdh != NULL);
2131
2132 /* Make sure it's output as a dynamic symbol. */
2133 if (fdh->dynindx == -1)
2134 {
2135 if (! bfd_elf64_link_record_dynamic_symbol (info, fdh))
2136 return false;
2137 }
2138 BFD_ASSERT (fdh->dynindx != -1);
2139 }
2140
2141 /* If this is the first .plt entry, make room for the special
2142 first entry. */
2143 if (splt->_raw_size == 0)
2144 splt->_raw_size = PLT_INITIAL_ENTRY_SIZE;
2145
2146 plt_offset = splt->_raw_size;
2147
2148 /* FIXME: What about function pointer comparisons in 64-bit PPC?
2149 We can't use the same trick as 32-bit PPC, since we set the
2150 symbol to the linkage function. This will make function entry
2151 point comparison work as expected within one object, but not
2152 across object boundaries. From the ABI:
2153
2154 In this ABI, the address of a function is actually the address of a
2155 function descriptor. A reference to a function, other than a function
2156 call, will normally load the address of the function descriptor from
2157 the global offset table. The dynamic linker will ensure that for a
2158 given function, the same address is used for all references to the
2159 function from any global offset table. Thus, function address
2160 comparisons will work as expected.
2161
2162 When making a call to the function, the code may refer to the
2163 procedure linkage table entry, in order to permit lazy symbol
2164 resolution at run time. In order to support correct function address
2165 comparisons, the compiler should be careful to only generate
2166 references to the procedure linkage table entry for function calls.
2167 For any other use of a function, the compiler should use the real
2168 address.
2169
2170 I don't see how this could ever work when passing a pointer to
2171 a function across an object boundary. The compiler has no
2172 way of knowing how to find the function descriptor for a
2173 function whose entrypoint is taken as an argument.
2174
2175 Or should the compiler arrange so that the function descriptor
2176 address is passed and make the callee dig out the entry point
2177 from that? */
2178#if 0
2179 /* If this symbol is not defined in a regular file, and we are
2180 not generating a shared library, then set the symbol to this
2181 location in the .plt. This is required to make function
2182 pointers compare as equal between the normal executable and
2183 the shared library. */
2184 if (! info->shared
2185 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
2186 {
2187 h->root.u.def.section = splt;
2188 h->root.u.def.value = plt_offset;
2189 }
2190#endif
2191
2192 /* FIXME: How should a linkage symbol be defined? It shouldn't
2193 be global, since it can't be used by any other object than
2194 this one. Set ELF_LINK_FORCED_LOCAL? */
2195 h->root.type = bfd_link_hash_defined;
2196 h->root.u.def.section = sglink;
2197 h->root.u.def.value = sglink->_raw_size;
2198 h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
2199 h->plt.offset = plt_offset;
2200
2201 /* Make room for global linkage code in .glink. */
2202 sglink->_raw_size += PPC64_ELF_GLINK_SIZE;
2203
2204 /* Make room for this entry in PLT. */
2205 splt->_raw_size += PLT_ENTRY_SIZE;
2206
2207 /* We also need to make an entry in the .rela.plt section. */
2208 s = bfd_get_section_by_name (dynobj, ".rela.plt");
2209 BFD_ASSERT (s != NULL);
2210 s->_raw_size += sizeof (Elf64_External_Rela);
2211
2212 return true;
2213 }
2214
2215 /* If this is a weak symbol, and there is a real definition, the
2216 processor independent code will have arranged for us to see the
2217 real definition first, and we can just use the same value. */
2218 if (h->weakdef != NULL)
2219 {
2220 BFD_ASSERT (h->weakdef->root.type == bfd_link_hash_defined
2221 || h->weakdef->root.type == bfd_link_hash_defweak);
2222 h->root.u.def.section = h->weakdef->root.u.def.section;
2223 h->root.u.def.value = h->weakdef->root.u.def.value;
2224 return true;
2225 }
2226
2227 /* This is a reference to a symbol defined by a dynamic object which
2228 is not a function. */
2229
2230 /* If we are creating a shared library, we must presume that the
2231 only references to the symbol are via the global offset table.
2232 For such cases we need not do anything here; the relocations will
2233 be handled correctly by relocate_section. */
2234 if (info->shared)
2235 return true;
2236
2237 /* We must allocate the symbol in our .dynbss section, which will
2238 become part of the .bss section of the executable. There will be
2239 an entry for this symbol in the .dynsym section. The dynamic
2240 object will contain position independent code, so all references
2241 from the dynamic object to this symbol will go through the global
2242 offset table. The dynamic linker will use the .dynsym entry to
2243 determine the address it must put in the global offset table, so
2244 both the dynamic object and the regular object will refer to the
2245 same memory location for the variable. */
2246 s = bfd_get_section_by_name (dynobj, ".dynbss");
2247 BFD_ASSERT (s != NULL);
2248
2249 /* We must generate a R_PPC_COPY reloc to tell the dynamic linker to
2250 copy the initial value out of the dynamic object and into the
2251 runtime process image. We need to remember the offset into the
2252 .rela.bss section we are going to use. */
2253 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
2254 {
2255 asection *srel;
2256
2257 srel = bfd_get_section_by_name (dynobj, ".rela.bss");
2258 BFD_ASSERT (srel != NULL);
2259 srel->_raw_size += sizeof (Elf64_External_Rela);
2260 h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_COPY;
2261 }
2262
2263 /* We need to figure out the alignment required for this symbol. I
2264 have no idea how ELF linkers handle this. */
2265 power_of_two = bfd_log2 (h->size);
2266 if (power_of_two > 4)
2267 power_of_two = 4;
2268
2269 /* Apply the required alignment. */
2270 s->_raw_size = BFD_ALIGN (s->_raw_size,
2271 (bfd_size_type) (1 << power_of_two));
2272 if (power_of_two > bfd_get_section_alignment (dynobj, s))
2273 {
2274 if (! bfd_set_section_alignment (dynobj, s, power_of_two))
2275 return false;
2276 }
2277
2278 /* Define the symbol as being at this point in the section. */
2279 h->root.u.def.section = s;
2280 h->root.u.def.value = s->_raw_size;
2281
2282 /* Increment the section size to make room for the symbol. */
2283 s->_raw_size += h->size;
2284
2285 return true;
2286}
2287
2288/* Increment the index of a dynamic symbol by a given amount. Called
2289 via elf_link_hash_traverse. */
2290
2291static boolean
2292ppc_adjust_dynindx (h, cparg)
2293 struct elf_link_hash_entry *h;
2294 PTR cparg;
2295{
2296 int *cp = (int *) cparg;
2297
2298#ifdef DEBUG
2299 fprintf (stderr,
2300 "ppc_adjust_dynindx: h->dynindx = %ld, *cp = %d (%s)\n",
2301 h->dynindx, *cp,
2302 h->root.root.string ? h->root.root.string : "<unknown>");
2303#endif
2304
2305 if (h->dynindx != -1)
2306 h->dynindx += *cp;
2307
2308 return true;
2309}
2310
2311/* Set the sizes of the dynamic sections. */
2312
2313static boolean
2314ppc64_elf_size_dynamic_sections (output_bfd, info)
2315 bfd *output_bfd;
2316 struct bfd_link_info *info;
2317{
2318 bfd *dynobj;
2319 asection *s;
2320 boolean plt;
2321 boolean relocs;
2322 boolean reltext;
2323
2324#ifdef DEBUG
2325 fprintf (stderr, "ppc64_elf_size_dynamic_sections called\n");
2326#endif
2327
2328 dynobj = elf_hash_table (info)->dynobj;
2329 BFD_ASSERT (dynobj != NULL);
2330
2331 if (elf_hash_table (info)->dynamic_sections_created)
2332 {
2333 /* Set the contents of the .interp section to the interpreter. */
2334 if (! info->shared)
2335 {
2336 s = bfd_get_section_by_name (dynobj, ".interp");
2337 BFD_ASSERT (s != NULL);
2338 s->_raw_size = sizeof ELF_DYNAMIC_INTERPRETER;
2339 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
2340 }
2341 }
2342 else
2343 {
2344 /* We may have created entries in the .rela.got section.
2345 However, if we are not creating the dynamic sections, we will
2346 not actually use these entries. Reset the size of .rela.got
2347 which will cause it to get stripped from the output file
2348 below. */
2349 s = bfd_get_section_by_name (dynobj, ".rela.got");
2350 if (s != NULL)
2351 s->_raw_size = 0;
2352 }
2353
2354 /* The check_relocs and adjust_dynamic_symbol entry points have
2355 determined the sizes of the various dynamic sections. Allocate
2356 memory for them. */
2357 plt = false;
2358 relocs = false;
2359 reltext = false;
2360 for (s = dynobj->sections; s != NULL; s = s->next)
2361 {
2362 const char *name;
2363 boolean strip;
2364
2365 if ((s->flags & SEC_LINKER_CREATED) == 0)
2366 continue;
2367
2368 /* It's OK to base decisions on the section name, because none
2369 of the dynobj section names depend upon the input files. */
2370 name = bfd_get_section_name (dynobj, s);
2371
2372 strip = false;
2373
2374 if (strcmp (name, ".plt") == 0)
2375 {
2376 if (s->_raw_size == 0)
2377 {
2378 /* Strip this section if we don't need it; see the
2379 comment below. */
2380 strip = true;
2381 }
2382 else
2383 {
2384 /* Remember whether there is a PLT. */
2385 plt = true;
2386 }
2387 }
2388 else if (strncmp (name, ".rela", 5) == 0)
2389 {
2390 if (s->_raw_size == 0)
2391 {
2392 /* If we don't need this section, strip it from the
2393 output file. This is mostly to handle .rela.bss and
2394 .rela.plt. We must create both sections in
2395 create_dynamic_sections, because they must be created
2396 before the linker maps input sections to output
2397 sections. The linker does that before
2398 adjust_dynamic_symbol is called, and it is that
2399 function which decides whether anything needs to go
2400 into these sections. */
2401 strip = true;
2402 }
2403 else
2404 {
2405 asection *target;
2406 const char *outname;
2407
2408 /* Remember whether there are any relocation sections. */
2409 relocs = true;
2410
2411 /* If this relocation section applies to a read only
2412 section, then we probably need a DT_TEXTREL entry. */
2413 outname = bfd_get_section_name (output_bfd,
2414 s->output_section);
2415 target = bfd_get_section_by_name (output_bfd, outname + 5);
2416 if (target != NULL
2417 && (target->flags & SEC_READONLY) != 0
2418 && (target->flags & SEC_ALLOC) != 0)
2419 reltext = true;
2420
2421 /* We use the reloc_count field as a counter if we need
2422 to copy relocs into the output file. */
2423 s->reloc_count = 0;
2424 }
2425 }
2426 else if (strcmp (name, ".got") != 0
2427 && strcmp (name, ".toc") != 0
2428 && strcmp (name, ".glink") != 0)
2429 {
2430 /* It's not one of our sections, so don't allocate space. */
2431 continue;
2432 }
2433
2434 if (strip)
2435 {
2436 _bfd_strip_section_from_output (info, s);
2437 continue;
2438 }
2439
2440#ifdef DEBUG
2441 fprintf (stderr, "\tallocating %lu bytes for section %s\n",
2442 (unsigned long) s->_raw_size, name);
2443#endif
2444
2445 /* Allocate memory for the section contents. */
2446 s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->_raw_size);
2447 if (s->contents == NULL && s->_raw_size != 0)
2448 return false;
2449 }
2450
2451 if (elf_hash_table (info)->dynamic_sections_created)
2452 {
2453 /* Add some entries to the .dynamic section. We fill in the
2454 values later, in ppc64_elf_finish_dynamic_sections, but we
2455 must add the entries now so that we get the correct size for
2456 the .dynamic section. The DT_DEBUG entry is filled in by the
2457 dynamic linker and used by the debugger. */
2458 if (! info->shared)
2459 {
2460 if (! bfd_elf64_add_dynamic_entry (info, DT_DEBUG, 0))
2461 return false;
2462 }
2463
2464 if (plt)
2465 {
2466 if (! bfd_elf64_add_dynamic_entry (info, DT_PLTGOT, 0)
2467 || ! bfd_elf64_add_dynamic_entry (info, DT_PLTRELSZ, 0)
2468 || ! bfd_elf64_add_dynamic_entry (info, DT_PLTREL, DT_RELA)
2469 || ! bfd_elf64_add_dynamic_entry (info, DT_JMPREL, 0))
2470 return false;
2471 }
2472
2473 if (relocs)
2474 {
2475 if (! bfd_elf64_add_dynamic_entry (info, DT_RELA, 0)
2476 || ! bfd_elf64_add_dynamic_entry (info, DT_RELASZ, 0)
2477 || ! bfd_elf64_add_dynamic_entry (info, DT_RELAENT,
2478 sizeof (Elf64_External_Rela)))
2479 return false;
2480 }
2481
2482 if (reltext)
2483 {
2484 if (! bfd_elf64_add_dynamic_entry (info, DT_TEXTREL, 0))
2485 return false;
2486 }
2487 }
2488
2489 /* If we are generating a shared library, we generate a section
2490 symbol for each output section. These are local symbols, which
2491 means that they must come first in the dynamic symbol table.
2492 That means we must increment the dynamic symbol index of every
2493 other dynamic symbol.
2494
2495 FIXME: We assume that there will never be relocations to
2496 locations in linker-created sections that do not have
2497 externally-visible names. Instead, we should work out precisely
2498 which sections relocations are targetted at. */
2499 if (info->shared)
2500 {
2501 int c;
2502
2503 for (c = 0, s = output_bfd->sections; s != NULL; s = s->next)
2504 {
2505 if ((s->flags & SEC_LINKER_CREATED) != 0
2506 || (s->flags & SEC_ALLOC) == 0)
2507 {
2508 elf_section_data (s)->dynindx = -1;
2509 continue;
2510 }
2511
2512 /* These symbols will have no names, so we don't need to
2513 fiddle with dynstr_index. */
2514
2515 elf_section_data (s)->dynindx = c + 1;
2516
2517 c++;
2518 }
2519
2520 elf_link_hash_traverse (elf_hash_table (info),
2521 ppc_adjust_dynindx,
2522 (PTR) &c);
2523 elf_hash_table (info)->dynsymcount += c;
2524 }
2525
2526 return true;
2527}
2528
2529/* Called after we have seen all the input files/sections, but before
2530 final symbol resolution and section placement has been determined.
2531
2532 We use this hook to provide a value for TOCstart, which we store in
2533 the output bfd elf_gp, then we call the generic ELF final link
2534 routine. */
2535
2536static boolean
2537ppc64_elf_final_link (abfd, info)
2538 bfd *abfd;
2539 struct bfd_link_info *info;
2540{
2541 if (! info->relocateable)
2542 {
2543 asection *s;
2544 bfd_vma TOCstart;
2545
2546 /* The TOC consists of sections .got, .toc, .tocbss, .plt in this
2547 order. The TOC starts where the first of these sections starts. */
2548 s = bfd_get_section_by_name (abfd, ".got");
2549 if (s == NULL)
2550 s = bfd_get_section_by_name (abfd, ".toc");
2551 if (s == NULL)
2552 s = bfd_get_section_by_name (abfd, ".tocbss");
2553 if (s == NULL)
2554 s = bfd_get_section_by_name (abfd, ".plt");
2555 if (s == NULL)
2556 {
2557 /* This may happen for
2558 o references to TOC base (SYM@toc / TOC[tc0]) without a
2559 .toc directive
2560 o bad linker script
2561 o --gc-sections and empty TOC sections
2562
2563 FIXME: Warn user? */
2564
2565 /* Look for a likely section. We probably won't even be
2566 using TOCstart. */
2567 for (s = abfd->sections; s != NULL; s = s->next)
2568 if ((s->flags & (SEC_ALLOC | SEC_SMALL_DATA | SEC_READONLY))
2569 == (SEC_ALLOC | SEC_SMALL_DATA))
2570 break;
2571 if (s == NULL)
2572 for (s = abfd->sections; s != NULL; s = s->next)
2573 if ((s->flags & (SEC_ALLOC | SEC_SMALL_DATA))
2574 == (SEC_ALLOC | SEC_SMALL_DATA))
2575 break;
2576 if (s == NULL)
2577 for (s = abfd->sections; s != NULL; s = s->next)
2578 if ((s->flags & (SEC_ALLOC | SEC_READONLY)) == SEC_ALLOC)
2579 break;
2580 if (s == NULL)
2581 for (s = abfd->sections; s != NULL; s = s->next)
2582 if ((s->flags & SEC_ALLOC) == SEC_ALLOC)
2583 break;
2584 }
2585
2586 TOCstart = 0;
2587 if (s != NULL)
2588 TOCstart = s->output_section->vma + s->output_offset;
2589
2590 elf_gp (abfd) = TOCstart;
2591 }
2592
2593 /* Invoke the regular gc ELF backend linker to do all the work. */
2594 return _bfd_elf64_gc_common_final_link (abfd, info);
2595}
2596
2597/* Set up any other section flags and such that may be necessary. */
2598
2599static boolean
2600ppc64_elf_fake_sections (abfd, shdr, asect)
2601 bfd *abfd ATTRIBUTE_UNUSED;
2602 Elf64_Internal_Shdr *shdr;
2603 asection *asect;
2604{
2605 if ((asect->flags & SEC_EXCLUDE) != 0)
2606 shdr->sh_flags |= SHF_EXCLUDE;
2607
2608 if ((asect->flags & SEC_SORT_ENTRIES) != 0)
2609 shdr->sh_type = SHT_ORDERED;
2610
2611 return true;
2612}
2613
2614/* The RELOCATE_SECTION function is called by the ELF backend linker
2615 to handle the relocations for a section.
2616
2617 The relocs are always passed as Rela structures; if the section
2618 actually uses Rel structures, the r_addend field will always be
2619 zero.
2620
2621 This function is responsible for adjust the section contents as
2622 necessary, and (if using Rela relocs and generating a
2623 relocateable output file) adjusting the reloc addend as
2624 necessary.
2625
2626 This function does not have to worry about setting the reloc
2627 address or the reloc symbol index.
2628
2629 LOCAL_SYMS is a pointer to the swapped in local symbols.
2630
2631 LOCAL_SECTIONS is an array giving the section in the input file
2632 corresponding to the st_shndx field of each local symbol.
2633
2634 The global hash table entry for the global symbols can be found
2635 via elf_sym_hashes (input_bfd).
2636
2637 When generating relocateable output, this function must handle
2638 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
2639 going to be the section symbol corresponding to the output
2640 section, which means that the addend must be adjusted
2641 accordingly. */
2642
2643static boolean
2644ppc64_elf_relocate_section (output_bfd, info, input_bfd, input_section,
2645 contents, relocs, local_syms, local_sections)
2646 bfd *output_bfd;
2647 struct bfd_link_info *info;
2648 bfd *input_bfd;
2649 asection *input_section;
2650 bfd_byte *contents;
2651 Elf_Internal_Rela *relocs;
2652 Elf_Internal_Sym *local_syms;
2653 asection **local_sections;
2654{
2655 Elf_Internal_Shdr *symtab_hdr;
2656 struct elf_link_hash_entry **sym_hashes;
2657 bfd *dynobj;
2658 Elf_Internal_Rela *rel;
2659 Elf_Internal_Rela *relend;
2660 asection *sreloc;
2661 asection *splt;
2662 asection *sgot;
2663 bfd_vma *local_got_offsets;
2664 bfd_vma TOCstart;
2665 boolean ret = true;
2666 long insn;
2667
2668#ifdef DEBUG
2669 fprintf (stderr, "ppc64_elf_relocate_section called for %s section %s, %ld relocations%s\n",
2670 bfd_get_filename (input_bfd),
2671 bfd_section_name (input_bfd, input_section),
2672 (long) input_section->reloc_count,
2673 (info->relocateable) ? " (relocatable)" : "");
2674#endif
2675
2676 if (!ppc64_elf_howto_table[R_PPC64_ADDR32])
2677 /* Initialize howto table if needed. */
2678 ppc_howto_init ();
2679
2680 local_got_offsets = elf_local_got_offsets (input_bfd);
2681
2682 sreloc = NULL;
2683 splt = NULL;
2684 sgot = NULL;
2685 dynobj = elf_hash_table (info)->dynobj;
2686 if (dynobj != NULL)
2687 {
2688 splt = bfd_get_section_by_name (dynobj, ".plt");
2689 sgot = bfd_get_section_by_name (dynobj, ".got");
2690 }
2691 TOCstart = elf_gp (output_bfd);
2692
2693 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
2694 sym_hashes = elf_sym_hashes (input_bfd);
2695 rel = relocs;
2696 relend = relocs + input_section->reloc_count;
2697 for (; rel < relend; rel++)
2698 {
2699 enum elf_ppc_reloc_type r_type;
2700 bfd_vma offset;
2701 bfd_vma addend;
2702 bfd_reloc_status_type r;
2703 Elf_Internal_Sym *sym;
2704 asection *sec;
2705 struct elf_link_hash_entry *h;
2706 const char *sym_name;
2707 reloc_howto_type *howto;
2708 unsigned long r_symndx;
2709 bfd_vma relocation;
2710
2711 r_type = (enum elf_ppc_reloc_type) ELF64_R_TYPE (rel->r_info);
2712 offset = rel->r_offset;
2713 addend = rel->r_addend;
2714 r = bfd_reloc_other;
2715 sym = (Elf_Internal_Sym *) 0;
2716 sec = (asection *) 0;
2717 h = (struct elf_link_hash_entry *) 0;
2718 sym_name = (const char *) 0;
2719
2720 /* Unknown relocation handling. */
2721 if ((unsigned) r_type >= (unsigned) R_PPC_max
2722 || !ppc64_elf_howto_table[(int) r_type])
2723 {
2724 (*_bfd_error_handler) (_("%s: unknown relocation type %d"),
2725 bfd_get_filename (input_bfd),
2726 (int) r_type);
2727 bfd_set_error (bfd_error_bad_value);
2728 ret = false;
2729 continue;
2730 }
2731
2732 howto = ppc64_elf_howto_table[(int) r_type];
2733 r_symndx = ELF64_R_SYM (rel->r_info);
2734
2735 if (info->relocateable)
2736 {
2737 /* This is a relocatable link. We don't have to change
2738 anything, unless the reloc is against a section symbol,
2739 in which case we have to adjust according to where the
2740 section symbol winds up in the output section. */
2741 if (r_symndx < symtab_hdr->sh_info)
2742 {
2743 sym = local_syms + r_symndx;
2744 if ((unsigned) ELF_ST_TYPE (sym->st_info) == STT_SECTION)
2745 {
2746 sec = local_sections[r_symndx];
2747 addend = rel->r_addend += sec->output_offset + sym->st_value;
2748 }
2749 }
2750
2751#ifdef DEBUG
2752 fprintf (stderr, "\ttype = %s (%d), symbol index = %ld, offset = %ld, addend = %ld\n",
2753 howto->name,
2754 (int) r_type,
2755 r_symndx,
2756 (long) offset,
2757 (long) addend);
2758#endif
2759 continue;
2760 }
2761
2762 /* This is a final link. */
2763
2764 /* Set `relocation'. */
2765 if (r_type == R_PPC64_TOC)
2766 {
2767 /* Relocation value is TOC base. Symbol is ignored. */
2768 relocation = TOCstart + TOC_BASE_OFF;
2769 }
2770 else if (r_symndx < symtab_hdr->sh_info)
2771 {
2772 /* It's a local symbol. */
2773 sym = local_syms + r_symndx;
2774 sec = local_sections[r_symndx];
2775 sym_name = "<local symbol>";
2776
2777 relocation = (sec->output_section->vma
2778 + sec->output_offset
2779 + sym->st_value);
2780 }
2781 else
2782 {
2783 /* It's a global symbol. */
2784 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
2785 while (h->root.type == bfd_link_hash_indirect
2786 || h->root.type == bfd_link_hash_warning)
2787 h = (struct elf_link_hash_entry *) h->root.u.i.link;
2788 sym_name = h->root.root.string;
2789 if (h->root.type == bfd_link_hash_defined
2790 || h->root.type == bfd_link_hash_defweak)
2791 {
2792 sec = h->root.u.def.section;
2793 if ((r_type == R_PPC64_PLT32
2794 && h->plt.offset != (bfd_vma) -1)
2795 || ((r_type == R_PPC64_GOT16
2796 || r_type == R_PPC64_GOT16_LO
2797 || r_type == R_PPC64_GOT16_HI
2798 || r_type == R_PPC64_GOT16_HA
2799 || r_type == R_PPC64_GOT16_DS
2800 || r_type == R_PPC64_GOT16_LO_DS)
2801 && elf_hash_table (info)->dynamic_sections_created
2802 && (! info->shared
2803 || (! info->symbolic && h->dynindx != -1)
2804 || (h->elf_link_hash_flags
2805 & ELF_LINK_HASH_DEF_REGULAR) == 0))
2806 || (info->shared
2807 && ((! info->symbolic && h->dynindx != -1)
2808 || (h->elf_link_hash_flags
2809 & ELF_LINK_HASH_DEF_REGULAR) == 0)
2810 && (input_section->flags & SEC_ALLOC) != 0
2811 && (r_type == R_PPC64_ADDR64
2812 || r_type == R_PPC64_ADDR32
2813 || r_type == R_PPC64_ADDR24
2814 || r_type == R_PPC64_ADDR16
2815 || r_type == R_PPC64_ADDR16_LO
2816 || r_type == R_PPC64_ADDR16_DS
2817 || r_type == R_PPC64_ADDR16_LO_DS
2818 || r_type == R_PPC64_ADDR16_HI
2819 || r_type == R_PPC64_ADDR16_HA
2820 || r_type == R_PPC64_ADDR16_HIGHER
2821 || r_type == R_PPC64_ADDR16_HIGHERA
2822 || r_type == R_PPC64_ADDR16_HIGHEST
2823 || r_type == R_PPC64_ADDR16_HIGHESTA
2824 || r_type == R_PPC64_ADDR14
2825 || r_type == R_PPC64_ADDR14_BRTAKEN
2826 || r_type == R_PPC64_ADDR14_BRNTAKEN
2827 || r_type == R_PPC64_COPY
2828 || r_type == R_PPC64_GLOB_DAT
2829 || r_type == R_PPC64_JMP_SLOT
2830 || r_type == R_PPC64_UADDR64
2831 || r_type == R_PPC64_UADDR32
2832 || r_type == R_PPC64_UADDR16)))
2833 {
2834 /* In these cases, we don't need the relocation
2835 value. We check specially because in some
2836 obscure cases sec->output_section will be NULL. */
2837 relocation = 0;
2838 }
2839 else
2840 relocation = (h->root.u.def.value
2841 + sec->output_section->vma
2842 + sec->output_offset);
2843 }
2844 else if (h->root.type == bfd_link_hash_undefweak)
2845 relocation = 0;
2846 else if (info->shared && !info->symbolic && !info->no_undefined)
2847 relocation = 0;
2848 else
2849 {
2850 if (! ((*info->callbacks->undefined_symbol)
2851 (info, h->root.root.string, input_bfd, input_section,
2852 rel->r_offset, (!info->shared
2853 || info->no_undefined
2854 || ELF_ST_VISIBILITY (h->other)))))
2855 return false;
2856 relocation = 0;
2857 }
2858 }
2859
2860 switch ((int) r_type)
2861 {
2862 case (int) R_PPC64_ADDR16_DS:
2863 case (int) R_PPC64_ADDR16_LO_DS:
2864 case (int) R_PPC64_GOT16_DS:
2865 case (int) R_PPC64_GOT16_LO_DS:
2866 case (int) R_PPC64_PLT16_LO_DS:
2867 case (int) R_PPC64_SECTOFF_DS:
2868 case (int) R_PPC64_SECTOFF_LO_DS:
2869 case (int) R_PPC64_TOC16_DS:
2870 case (int) R_PPC64_TOC16_LO_DS:
2871 case (int) R_PPC64_PLTGOT16_DS:
2872 case (int) R_PPC64_PLTGOT16_LO_DS:
2873 if (((relocation + addend) & 3) != 0)
2874 {
2875 (*_bfd_error_handler) (_("%s: error: relocation %s not a multiple of 4"),
2876 bfd_get_filename (input_bfd),
2877 howto->name);
2878 bfd_set_error (bfd_error_bad_value);
2879 ret = false;
2880 continue;
2881 }
2882 }
2883
2884 /* Set `addend'. */
2885 switch ((int) r_type)
2886 {
2887 default:
2888 (*_bfd_error_handler) (_("%s: unknown relocation type %d for symbol %s"),
2889 bfd_get_filename (input_bfd),
2890 (int) r_type, sym_name);
2891
2892 bfd_set_error (bfd_error_bad_value);
2893 ret = false;
2894 continue;
2895
2896 /* Relocations that may need to be propagated if this is a shared
2897 object. */
2898 case (int) R_PPC64_REL24:
2899 case (int) R_PPC64_ADDR24:
2900 /* An ADDR24 or REL24 branching to a linkage function may be
2901 followed by a nop that we have to replace with an ld in
2902 order to restore the TOC base pointer. Only calls to
2903 shared objects need to alter the TOC base. These are
2904 recognized by their need for a PLT entry. */
2905 if (h != NULL
2906 && (h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0
2907 /* Make sure that there really is an instruction after
2908 the branch that we can decode. */
2909 && (rel->r_offset - input_section->vma + 8
2910 <= input_section->_cooked_size))
2911 {
2912 bfd_byte *pnext;
2913 unsigned long insn;
2914
2915 pnext = contents + (rel->r_offset - input_section->vma) + 4;
2916 insn = bfd_get_32 (input_bfd, pnext);
2917
2918 if (insn == 0x60000000 /* nop (ori r0,r0,0) */
2919 || insn == 0x4def7b82 /* cror 15,15,15 */
2920 || insn == 0x4ffffb82) /* cror 31,31,31 */
2921 {
2922 bfd_put_32 (input_bfd, 0xe8410028, pnext); /* ld r2,40(r1) */
2923#ifdef DEBUG
2924 fprintf (stderr, "ppc64_elf_relocate_section: " \
2925 "patched nop after call to %s\n", sym_name);
2926#endif
2927 }
2928 }
2929 /* fall through */
2930
2931 case (int) R_PPC64_REL64:
2932 case (int) R_PPC64_REL32:
2933 case (int) R_PPC64_REL14:
2934 /* If these relocations are not to a named symbol, they can be
2935 handled right here, no need to bother the dynamic linker. */
2936 if (h == NULL && r_type != R_PPC64_ADDR24)
2937 break;
2938 /* fall through */
2939
2940 /* Relocations that always need to be propagated if this is a shared
2941 object. */
2942 case (int) R_PPC64_NONE:
2943 case (int) R_PPC64_ADDR64:
2944 case (int) R_PPC64_ADDR32:
2945 case (int) R_PPC64_ADDR16:
2946 case (int) R_PPC64_ADDR16_LO:
2947 case (int) R_PPC64_ADDR16_DS:
2948 case (int) R_PPC64_ADDR16_LO_DS:
2949 case (int) R_PPC64_ADDR16_HI:
2950 case (int) R_PPC64_ADDR16_HA:
2951 case (int) R_PPC64_ADDR16_HIGHER:
2952 case (int) R_PPC64_ADDR16_HIGHERA:
2953 case (int) R_PPC64_ADDR16_HIGHEST:
2954 case (int) R_PPC64_ADDR16_HIGHESTA:
2955 case (int) R_PPC64_ADDR14:
2956 case (int) R_PPC64_UADDR64:
2957 case (int) R_PPC64_UADDR32:
2958 case (int) R_PPC64_UADDR16:
2959 case (int) R_PPC64_TOC:
2960 if (info->shared)
2961 {
2962 Elf_Internal_Rela outrel;
2963 boolean skip;
2964
2965#ifdef DEBUG
2966 fprintf (stderr, "ppc64_elf_relocate_section need to create relocation for %s\n",
2967 (h && h->root.root.string
2968 ? h->root.root.string
2969 : "<unknown>"));
2970#endif
2971
2972 /* When generating a shared object, these relocations
2973 are copied into the output file to be resolved at run
2974 time. */
2975
2976 if (sreloc == NULL)
2977 {
2978 const char *name;
2979
2980 name = (bfd_elf_string_from_elf_section
2981 (input_bfd,
2982 elf_elfheader (input_bfd)->e_shstrndx,
2983 elf_section_data (input_section)->rel_hdr.sh_name));
2984 if (name == NULL)
2985 return false;
2986
2987 BFD_ASSERT (strncmp (name, ".rela", 5) == 0
2988 && strcmp (bfd_get_section_name (input_bfd,
2989 input_section),
2990 name + 5) == 0);
2991
2992 sreloc = bfd_get_section_by_name (dynobj, name);
2993 BFD_ASSERT (sreloc != NULL);
2994 }
2995
2996 skip = false;
2997
2998 if (elf_section_data (input_section)->stab_info == NULL)
2999 outrel.r_offset = rel->r_offset;
3000 else
3001 {
3002 bfd_vma off;
3003
3004 off = (_bfd_stab_section_offset
3005 (output_bfd, &elf_hash_table (info)->stab_info,
3006 input_section,
3007 &elf_section_data (input_section)->stab_info,
3008 rel->r_offset));
3009 if (off == (bfd_vma) -1)
3010 skip = true;
3011 outrel.r_offset = off;
3012 }
3013
3014 outrel.r_offset += (input_section->output_section->vma
3015 + input_section->output_offset);
3016
3017 if (skip)
3018 memset (&outrel, 0, sizeof outrel);
3019 /* h->dynindx may be -1 if this symbol was marked to
3020 become local. */
3021 else if (h != NULL
3022 && ((! info->symbolic && h->dynindx != -1)
3023 || (h->elf_link_hash_flags
3024 & ELF_LINK_HASH_DEF_REGULAR) == 0))
3025 {
3026 BFD_ASSERT (h->dynindx != -1);
3027 outrel.r_info = ELF64_R_INFO (h->dynindx, r_type);
3028 outrel.r_addend = rel->r_addend;
3029 }
3030 else
3031 {
3032 if (r_type == R_PPC64_ADDR64)
3033 {
3034 outrel.r_info = ELF64_R_INFO (0, R_PPC64_RELATIVE);
3035 outrel.r_addend = relocation + rel->r_addend;
3036 }
3037 else
3038 {
3039 long indx;
3040
3041 if (h == NULL)
3042 sec = local_sections[r_symndx];
3043 else
3044 {
3045 BFD_ASSERT (h->root.type == bfd_link_hash_defined
3046 || (h->root.type
3047 == bfd_link_hash_defweak));
3048 sec = h->root.u.def.section;
3049 }
3050
3051 if (r_type == R_PPC64_TOC
3052 || (sec != NULL && bfd_is_abs_section (sec)))
3053 {
3054 indx = 0;
3055 }
3056 else if (sec == NULL || sec->owner == NULL)
3057 {
3058 bfd_set_error (bfd_error_bad_value);
3059 return false;
3060 }
3061 else
3062 {
3063 asection *osec;
3064
3065 osec = sec->output_section;
3066 indx = elf_section_data (osec)->dynindx;
3067 BFD_ASSERT (indx > 0);
3068#ifdef DEBUG
3069 if (indx <= 0)
3070 {
3071 printf ("indx=%ld section=%s flags=%08x name=%s\n",
3072 indx, osec->name, osec->flags,
3073 h->root.root.string);
3074 }
3075#endif
3076 }
3077
3078 outrel.r_info = ELF64_R_INFO (indx, r_type);
3079 outrel.r_addend = relocation + rel->r_addend;
3080 }
3081 }
3082
3083 bfd_elf64_swap_reloca_out (output_bfd, &outrel,
3084 (((Elf64_External_Rela *)
3085 sreloc->contents)
3086 + sreloc->reloc_count));
3087 ++sreloc->reloc_count;
3088
3089 /* This reloc will be computed at runtime, so there's no
3090 need to do anything now, unless this is a RELATIVE
3091 reloc in an unallocated section. */
3092 if (skip
3093 || (input_section->flags & SEC_ALLOC) != 0
3094 || ELF64_R_TYPE (outrel.r_info) != R_PPC64_RELATIVE)
3095 continue;
3096 }
3097
3098 /* Arithmetic adjust relocations that aren't going into a
3099 shared object. */
3100 if ((r_type == R_PPC64_ADDR16_HA
3101 || r_type == R_PPC64_ADDR16_HIGHERA
3102 || r_type == R_PPC64_ADDR16_HIGHESTA)
3103 /* It's just possible that this symbol is a weak symbol
3104 that's not actually defined anywhere. In that case,
3105 'sec' would be NULL, and we should leave the symbol
3106 alone (it will be set to zero elsewhere in the link). */
3107 && sec != NULL)
3108 {
3109 addend += ((relocation + addend) & 0x8000) << 1;
3110 }
3111 break;
3112
3113 /* Branch taken prediction relocations. */
3114 case (int) R_PPC64_ADDR14_BRTAKEN:
3115 case (int) R_PPC64_REL14_BRTAKEN:
3116 insn = bfd_get_32 (output_bfd, contents + offset);
3117 if ((relocation - offset) & 0x8000)
3118 insn &= ~BRANCH_PREDICT_BIT;
3119 else
3120 insn |= BRANCH_PREDICT_BIT;
3121 bfd_put_32 (output_bfd, insn, contents + offset);
3122 break;
3123
3124 /* Branch not taken predicition relocations. */
3125 case (int) R_PPC64_ADDR14_BRNTAKEN:
3126 case (int) R_PPC64_REL14_BRNTAKEN:
3127 insn = bfd_get_32 (output_bfd, contents + offset);
3128 if ((relocation - offset) & 0x8000)
3129 insn |= BRANCH_PREDICT_BIT;
3130 else
3131 insn &= ~BRANCH_PREDICT_BIT;
3132 bfd_put_32 (output_bfd, insn, contents + offset);
3133 break;
3134
3135
3136 /* GOT16 relocations. Like an ADDR16 using the symbol's
3137 address in the GOT as relocation value instead of the
3138 symbols value itself. Also, create a GOT entry for the
3139 symbol and put the symbol value there. */
3140 /* FIXME: If the symbol is not in the .got section
3141 (typically in the .toc section) we fail (h->got.offset is
3142 0). */
3143 /* NOTE: Sets `relocation'. */
3144 case (int) R_PPC64_GOT16:
3145 case (int) R_PPC64_GOT16_LO:
3146 case (int) R_PPC64_GOT16_HI:
3147 case (int) R_PPC64_GOT16_HA:
3148 case (int) R_PPC64_GOT16_DS:
3149 case (int) R_PPC64_GOT16_LO_DS:
3150 {
3151 /* Relocation is to the entry for this symbol in the global
3152 offset table. */
3153 bfd_vma off;
3154 BFD_ASSERT (sgot != NULL);
3155
3156 if (h != NULL)
3157 {
3158 off = h->got.offset;
3159 BFD_ASSERT (off != (bfd_vma) -1);
3160
3161 if (! elf_hash_table (info)->dynamic_sections_created
3162 || (info->shared
3163 && (info->symbolic || h->dynindx == -1)
3164 && (h->elf_link_hash_flags
3165 & ELF_LINK_HASH_DEF_REGULAR)))
3166 {
3167 /* This is actually a static link, or it is a
3168 -Bsymbolic link and the symbol is defined
3169 locally. We must initialize this entry in the
3170 global offset table. Since the offset must
3171 always be a multiple of 4, we use the least
3172 significant bit to record whether we have
3173 initialized it already.
3174
3175 When doing a dynamic link, we create a .rela.got
3176 relocation entry to initialize the value. This
3177 is done in the finish_dynamic_symbol routine. */
3178 if ((off & 1) != 0)
3179 off &= ~1;
3180 else
3181 {
3182 bfd_put_64 (output_bfd, relocation,
3183 sgot->contents + off);
3184 h->got.offset |= 1;
3185 }
3186 }
3187 }
3188 else
3189 {
3190 BFD_ASSERT (local_got_offsets != NULL
3191 && local_got_offsets[r_symndx] != (bfd_vma) -1);
3192
3193 off = local_got_offsets[r_symndx];
3194
3195 /* The offset must always be a multiple of 4. We use
3196 the least significant bit to record whether we have
3197 already processed this entry. */
3198 if ((off & 1) != 0)
3199 off &= ~1;
3200 else
3201 {
3202 bfd_put_64 (output_bfd, relocation, sgot->contents + off);
3203
3204 if (info->shared)
3205 {
3206 asection *srelgot;
3207 Elf_Internal_Rela outrel;
3208
3209 /* We need to generate a R_PPC64_RELATIVE reloc
3210 for the dynamic linker. */
3211 srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
3212 BFD_ASSERT (srelgot != NULL);
3213
3214 outrel.r_offset = (sgot->output_section->vma
3215 + sgot->output_offset
3216 + off);
3217 outrel.r_info = ELF64_R_INFO (0, R_PPC64_RELATIVE);
3218 outrel.r_addend = relocation;
3219 bfd_elf64_swap_reloca_out (output_bfd, &outrel,
3220 (((Elf64_External_Rela *)
3221 srelgot->contents)
3222 + srelgot->reloc_count));
3223 ++srelgot->reloc_count;
3224 }
3225
3226 local_got_offsets[r_symndx] |= 1;
3227 }
3228 }
3229
3230 relocation = sgot->output_offset + off;
3231 /* TOC base (r2) is TOC start plus 0x8000. */
3232 addend -= TOC_BASE_OFF;
3233 break;
3234 }
3235
3236 /* TOC16 relocs. We want the offset relative to the TOC base,
3237 which is the address of the start of the TOC plus 0x8000.
3238 The TOC consists of sections .got, .toc, .tocbss, and .plt,
3239 in this order. */
3240
3241 case (int) R_PPC64_TOC16:
3242 case (int) R_PPC64_TOC16_LO:
3243 case (int) R_PPC64_TOC16_HI:
3244 case (int) R_PPC64_TOC16_DS:
3245 case (int) R_PPC64_TOC16_LO_DS:
3246 BFD_ASSERT (sec != (asection *) 0);
3247 /* Only .got, .toc and *UND* symbols are allowed. */
3248 BFD_ASSERT (bfd_is_und_section (sec)
3249 || strcmp (bfd_get_section_name (abfd, sec),
3250 ".got") == 0
3251 || strcmp (bfd_get_section_name (abfd, sec),
3252 ".toc") == 0);
3253
3254 addend -= TOCstart + TOC_BASE_OFF;
3255 break;
3256
3257 case (int) R_PPC64_TOC16_HA:
3258 BFD_ASSERT (sec != (asection *) 0);
3259 BFD_ASSERT (bfd_is_und_section (sec)
3260 || strcmp (bfd_get_section_name (abfd, sec),
3261 ".got") == 0
3262 || strcmp (bfd_get_section_name (abfd, sec),
3263 ".toc") == 0);
3264
3265 addend -= TOCstart + TOC_BASE_OFF;
3266 /* Add 1 to 16-bit word 16:31 if sign bit in 0:15 is set. */
3267 addend += ((relocation + addend) & 0x8000) << 1;
3268 break;
3269
3270 /* Relocate against the beginning of the section. */
3271 case (int) R_PPC64_SECTOFF:
3272 case (int) R_PPC64_SECTOFF_LO:
3273 case (int) R_PPC64_SECTOFF_HI:
3274 case (int) R_PPC64_SECTOFF_DS:
3275 case (int) R_PPC64_SECTOFF_LO_DS:
3276 BFD_ASSERT (sec != (asection *) 0);
3277 addend -= sec->output_section->vma;
3278 break;
3279
3280 case (int) R_PPC64_SECTOFF_HA:
3281 BFD_ASSERT (sec != (asection *) 0);
3282 addend -= sec->output_section->vma;
3283 addend += ((relocation + addend) & 0x8000) << 1;
3284 break;
3285
3286 case (int) R_PPC64_COPY:
3287 case (int) R_PPC64_GLOB_DAT:
3288 case (int) R_PPC64_JMP_SLOT:
3289 case (int) R_PPC64_RELATIVE:
3290 case (int) R_PPC64_PLT32:
3291 case (int) R_PPC64_PLTREL32:
3292 case (int) R_PPC64_PLT16_LO:
3293 case (int) R_PPC64_PLT16_LO_DS:
3294 case (int) R_PPC64_PLT16_HI:
3295 case (int) R_PPC64_PLT16_HA:
3296 case (int) R_PPC64_PLT64:
3297 case (int) R_PPC64_PLTREL64:
3298 case (int) R_PPC64_PLTGOT16:
3299 case (int) R_PPC64_PLTGOT16_LO:
3300 case (int) R_PPC64_PLTGOT16_DS:
3301 case (int) R_PPC64_PLTGOT16_LO_DS:
3302 case (int) R_PPC64_PLTGOT16_HI:
3303 case (int) R_PPC64_PLTGOT16_HA:
3304 (*_bfd_error_handler) (_("%s: Relocation %s is not yet supported for symbol %s."),
3305 bfd_get_filename (input_bfd),
3306 ppc64_elf_howto_table[(int) r_type]->name,
3307 sym_name);
3308
3309 bfd_set_error (bfd_error_invalid_operation);
3310 ret = false;
3311 continue;
3312
3313 case (int) R_PPC_GNU_VTINHERIT:
3314 case (int) R_PPC_GNU_VTENTRY:
3315 /* These are no-ops in the end. */
3316 continue;
3317 }
3318
3319#ifdef DEBUG
3320 fprintf (stderr, " type = %s (%d), name = %s, sym index = %ld, offset = %ld, addend = %ld\n",
3321 howto->name,
3322 (int) r_type,
3323 sym_name,
3324 r_symndx,
3325 (long) offset,
3326 (long) addend);
3327#endif
3328
3329 r = _bfd_final_link_relocate (howto,
3330 input_bfd,
3331 input_section,
3332 contents,
3333 offset,
3334 relocation,
3335 addend);
3336
3337 if (r == bfd_reloc_ok)
3338 ;
3339 else if (r == bfd_reloc_overflow)
3340 {
3341 const char *name;
3342
3343 if (h != NULL)
3344 {
3345 if (h->root.type == bfd_link_hash_undefweak
3346 && howto->pc_relative)
3347 {
3348 /* Assume this is a call protected by other code that
3349 detects the symbol is undefined. If this is the case,
3350 we can safely ignore the overflow. If not, the
3351 program is hosed anyway, and a little warning isn't
3352 going to help. */
3353
3354 continue;
3355 }
3356
3357 name = h->root.root.string;
3358 }
3359 else
3360 {
3361 name = bfd_elf_string_from_elf_section (input_bfd,
3362 symtab_hdr->sh_link,
3363 sym->st_name);
3364 if (name == NULL)
3365 continue;
3366 if (*name == '\0')
3367 name = bfd_section_name (input_bfd, sec);
3368 }
3369
3370 if (! (*info->callbacks->reloc_overflow) (info,
3371 name,
3372 howto->name,
3373 (bfd_vma) 0,
3374 input_bfd,
3375 input_section,
3376 offset))
3377 return false;
3378 }
3379 else
3380 ret = false;
3381 }
3382
3383#ifdef DEBUG
3384 fprintf (stderr, "\n");
3385#endif
3386
3387 return ret;
3388}
3389
3390/* Finish up dynamic symbol handling. We set the contents of various
3391 dynamic sections here. */
3392
3393static boolean
3394ppc64_elf_finish_dynamic_symbol (output_bfd, info, h, sym)
3395 bfd *output_bfd;
3396 struct bfd_link_info *info;
3397 struct elf_link_hash_entry *h;
3398 Elf_Internal_Sym *sym;
3399{
3400 bfd *dynobj;
3401
3402#ifdef DEBUG
3403 fprintf (stderr, "ppc64_elf_finish_dynamic_symbol called for %s",
3404 h->root.root.string);
3405#endif
3406
3407 dynobj = elf_hash_table (info)->dynobj;
3408 BFD_ASSERT (dynobj != NULL);
3409
3410 if (h->plt.offset != (bfd_vma) -1)
3411 {
3412 asection *splt, *srela, *sglink;
3413 Elf_Internal_Rela rela;
3414 bfd_vma reloc_index, plt_offset;
3415 struct elf_link_hash_entry *funcdesc_h;
3416
3417#ifdef DEBUG
3418 fprintf (stderr, ", plt_offset = 0x%lx", (unsigned long) h->plt.offset);
3419#endif
3420
3421 /* This symbol has an entry in the procedure linkage table. Set
3422 it up. */
3423
3424 BFD_ASSERT (h->dynindx != -1);
3425
3426 splt = bfd_get_section_by_name (dynobj, ".plt");
3427 srela = bfd_get_section_by_name (dynobj, ".rela.plt");
3428 BFD_ASSERT (splt != NULL && srela != NULL);
3429
3430 /* We don't need to fill in the .plt. The dynamic linker will
3431 fill it in. */
3432
3433 /* We may need to create a linkage function. */
3434 sglink = bfd_get_section_by_name (dynobj, ".glink");
3435 if (sglink != NULL && h->root.u.def.section == sglink)
3436 {
3437 bfd_byte *p;
3438 bfd_vma pltoff;
3439 const unsigned int *stub;
3440
3441 /* Where to write it. */
3442 p = h->root.u.def.section->contents + h->root.u.def.value;
3443
3444 /* The function descriptor is in the PLT. */
3445 pltoff = splt->output_section->vma
3446 + splt->output_section->output_offset
3447 + h->plt.offset
3448 - elf_gp (output_bfd) - TOC_BASE_OFF;
3449
3450 if (pltoff + 0x8000 > 0xffff)
3451 {
3452 (*_bfd_error_handler)
3453 (_("linkage table overflow against `%s'"),
3454 h->root.root.string);
3455 }
3456
3457 /* Write it out. */
3458 stub = ppc64_elf_glink_code;
3459 bfd_put_32 (output_bfd, *stub | (pltoff & 0xfffc), p);
3460 while (p += 4, ++stub < (ppc64_elf_glink_code
3461 + (sizeof (ppc64_elf_glink_code)
3462 / sizeof (*ppc64_elf_glink_code))));
3463 {
3464 bfd_put_32 (output_bfd, *stub, p);
3465 }
3466#ifdef DEBUG
3467 fprintf (stderr, ", linkage function");
3468#endif
3469 }
3470
3471 /* Create a JMP_SLOT reloc to inform the dynamic linker to fix
3472 the PLT entry. */
3473
3474 /* Save the PLT offset, since `h' may be changed below. */
3475 plt_offset = h->plt.offset;
3476
3477 /* If it's a function entry point, find its corresponding
3478 function descriptor. ppc64_elf_adjust_dynamic_symbol have
3479 already set it up for us. */
3480
3481 /* FIXME: Is it safe to assume that this symbol is a function? */
3482 BFD_ASSERT (h->root.root.string[0] == '.');
3483
3484 /* FIXME: Follow bfd_link_hash_indirect? */
3485 funcdesc_h = elf_link_hash_lookup (elf_hash_table (info),
3486 h->root.root.string + 1,
3487 false, false, false);
3488 BFD_ASSERT (funcdesc_h != NULL);
3489 BFD_ASSERT (funcdesc_h->dynindx != -1);
3490
3491 /* FIXME: Rename the symbol for the function entry point to
3492 `linkage_for_FUNC'? */
3493
3494 rela.r_offset = (splt->output_section->vma
3495 + splt->output_offset
3496 + plt_offset);
3497 rela.r_info = ELF64_R_INFO (funcdesc_h->dynindx, R_PPC64_JMP_SLOT);
3498 rela.r_addend = 0;
3499
3500 reloc_index = (plt_offset - PLT_INITIAL_ENTRY_SIZE) / PLT_ENTRY_SIZE;
3501 bfd_elf64_swap_reloca_out (output_bfd, &rela,
3502 ((Elf64_External_Rela *) srela->contents
3503 + reloc_index));
3504#ifdef DEBUG
3505 fprintf (stderr, ", JMP_SLOT for %s", funcdesc_h->root.root.string);
3506#endif
3507
3508#if 0
3509 /* FIXME: Really do this? */
3510 if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
3511 {
3512 /* Mark the symbol as undefined, rather than as defined in
3513 the .plt section. Leave the value alone. */
3514 sym->st_shndx = SHN_UNDEF;
3515 }
3516#endif
3517 }
3518
3519 if (h->got.offset != (bfd_vma) -1)
3520 {
3521 asection *sgot;
3522 asection *srela;
3523 Elf_Internal_Rela rela;
3524
3525#ifdef DEBUG
3526 fprintf (stderr, ", got.offset = %08lx", (unsigned long) h->got.offset);
3527#endif
3528
3529 /* This symbol has an entry in the global offset table. Set it
3530 up. */
3531
3532 sgot = bfd_get_section_by_name (dynobj, ".got");
3533 srela = bfd_get_section_by_name (dynobj, ".rela.got");
3534 BFD_ASSERT (sgot != NULL && srela != NULL);
3535
3536 rela.r_offset = (sgot->output_section->vma
3537 + sgot->output_offset
3538 + (h->got.offset &~ 1));
3539
3540 /* If this is a -Bsymbolic link, and the symbol is defined
3541 locally, we just want to emit a RELATIVE reloc. The entry in
3542 the global offset table will already have been initialized in
3543 the relocate_section function. */
3544 if (info->shared
3545 && (info->symbolic || h->dynindx == -1)
3546 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR))
3547 {
3548 rela.r_info = ELF64_R_INFO (0, R_PPC64_RELATIVE);
3549 rela.r_addend = (h->root.u.def.value
3550 + h->root.u.def.section->output_section->vma
3551 + h->root.u.def.section->output_offset);
3552 }
3553 else
3554 {
3555 BFD_ASSERT ((h->got.offset & 1) == 0);
3556 bfd_put_64 (output_bfd, (bfd_vma) 0, sgot->contents + h->got.offset);
3557 rela.r_info = ELF64_R_INFO (h->dynindx, R_PPC64_GLOB_DAT);
3558 rela.r_addend = 0;
3559 }
3560
3561 bfd_elf64_swap_reloca_out (output_bfd, &rela,
3562 ((Elf64_External_Rela *) srela->contents
3563 + srela->reloc_count));
3564 ++srela->reloc_count;
3565 }
3566
3567 if ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_COPY) != 0)
3568 {
3569 asection *s;
3570 Elf_Internal_Rela rela;
3571
3572 /* This symbols needs a copy reloc. Set it up. */
3573
3574#ifdef DEBUG
3575 fprintf (stderr, ", copy");
3576#endif
3577
3578 BFD_ASSERT (h->dynindx != -1);
3579
3580 s = bfd_get_section_by_name (h->root.u.def.section->owner,
3581 ".rela.bss");
3582 BFD_ASSERT (s != NULL);
3583
3584 rela.r_offset = (h->root.u.def.value
3585 + h->root.u.def.section->output_section->vma
3586 + h->root.u.def.section->output_offset);
3587 rela.r_info = ELF64_R_INFO (h->dynindx, R_PPC64_COPY);
3588 rela.r_addend = 0;
3589 bfd_elf64_swap_reloca_out (output_bfd, &rela,
3590 ((Elf64_External_Rela *) s->contents
3591 + s->reloc_count));
3592 ++s->reloc_count;
3593 }
3594
3595#ifdef DEBUG
3596 fprintf (stderr, "\n");
3597#endif
3598
3599 /* Mark some specially defined symbols as absolute. */
3600 if (strcmp (h->root.root.string, "_DYNAMIC") == 0)
3601 sym->st_shndx = SHN_ABS;
3602
3603 return true;
3604}
3605
3606/* Finish up the dynamic sections. */
3607
3608static boolean
3609ppc64_elf_finish_dynamic_sections (output_bfd, info)
3610 bfd *output_bfd;
3611 struct bfd_link_info *info;
3612{
3613 asection *sdyn;
3614 bfd *dynobj = elf_hash_table (info)->dynobj;
3615
3616#ifdef DEBUG
3617 fprintf (stderr, "ppc64_elf_finish_dynamic_sections called\n");
3618#endif
3619
3620 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
3621
3622 if (elf_hash_table (info)->dynamic_sections_created)
3623 {
3624 asection *splt;
3625 Elf64_External_Dyn *dyncon, *dynconend;
3626
3627 splt = bfd_get_section_by_name (dynobj, ".plt");
3628 BFD_ASSERT (splt != NULL && sdyn != NULL);
3629
3630 dyncon = (Elf64_External_Dyn *) sdyn->contents;
3631 dynconend = (Elf64_External_Dyn *) (sdyn->contents + sdyn->_raw_size);
3632 for (; dyncon < dynconend; dyncon++)
3633 {
3634 Elf_Internal_Dyn dyn;
3635 const char *name;
3636 boolean size;
3637
3638 bfd_elf64_swap_dyn_in (dynobj, dyncon, &dyn);
3639
3640 switch (dyn.d_tag)
3641 {
3642 case DT_PLTGOT: name = ".plt"; size = false; break;
3643 case DT_PLTRELSZ: name = ".rela.plt"; size = true; break;
3644 case DT_JMPREL: name = ".rela.plt"; size = false; break;
3645 default: name = NULL; size = false; break;
3646 }
3647
3648 if (name != NULL)
3649 {
3650 asection *s;
3651
3652 s = bfd_get_section_by_name (output_bfd, name);
3653 if (s == NULL)
3654 dyn.d_un.d_val = 0;
3655 else
3656 {
3657 if (! size)
3658 dyn.d_un.d_ptr = s->vma;
3659 else
3660 {
3661 if (s->_cooked_size != 0)
3662 dyn.d_un.d_val = s->_cooked_size;
3663 else
3664 dyn.d_un.d_val = s->_raw_size;
3665 }
3666 }
3667 bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon);
3668 }
3669 }
3670 }
3671
3672 if (info->shared)
3673 {
3674 asection *sdynsym;
3675 asection *s;
3676 Elf_Internal_Sym sym;
3677 int maxdindx = 0;
3678
3679 /* Set up the section symbols for the output sections. */
3680
3681 sdynsym = bfd_get_section_by_name (dynobj, ".dynsym");
3682 BFD_ASSERT (sdynsym != NULL);
3683
3684 sym.st_size = 0;
3685 sym.st_name = 0;
3686 sym.st_info = ELF_ST_INFO (STB_LOCAL, STT_SECTION);
3687 sym.st_other = 0;
3688
3689 for (s = output_bfd->sections; s != NULL; s = s->next)
3690 {
3691 int indx, dindx;
3692
3693 sym.st_value = s->vma;
3694
3695 indx = elf_section_data (s)->this_idx;
3696 dindx = elf_section_data (s)->dynindx;
3697 if (dindx != -1)
3698 {
3699 BFD_ASSERT (indx > 0);
3700 BFD_ASSERT (dindx > 0);
3701
3702 if (dindx > maxdindx)
3703 maxdindx = dindx;
3704
3705 sym.st_shndx = indx;
3706
3707 bfd_elf64_swap_symbol_out (output_bfd, &sym,
3708 (PTR) (((Elf64_External_Sym *)
3709 sdynsym->contents)
3710 + dindx));
3711 }
3712 }
3713
3714 /* Set the sh_info field of the output .dynsym section to the
3715 index of the first global symbol. */
3716 elf_section_data (sdynsym->output_section)->this_hdr.sh_info =
3717 maxdindx + 1;
3718 }
3719
3720 return true;
3721}
3722
3723#define TARGET_LITTLE_SYM bfd_elf64_powerpcle_vec
3724#define TARGET_LITTLE_NAME "elf64-powerpcle"
3725#define TARGET_BIG_SYM bfd_elf64_powerpc_vec
3726#define TARGET_BIG_NAME "elf64-powerpc"
3727#define ELF_ARCH bfd_arch_powerpc
3728#define ELF_MACHINE_CODE EM_PPC64
3729#define ELF_MAXPAGESIZE 0x10000
3730#define elf_info_to_howto ppc64_elf_info_to_howto
3731
3732#ifdef EM_CYGNUS_POWERPC
3733#define ELF_MACHINE_ALT1 EM_CYGNUS_POWERPC
3734#endif
3735
3736#ifdef EM_PPC_OLD
3737#define ELF_MACHINE_ALT2 EM_PPC_OLD
3738#endif
3739
3740#define elf_backend_want_got_sym 0
3741#define elf_backend_want_plt_sym 0
3742#define elf_backend_plt_alignment 3
3743#define elf_backend_plt_not_loaded 1
3744#define elf_backend_got_symbol_offset 0
3745#define elf_backend_got_header_size 0
3746#define elf_backend_can_gc_sections 1
3747
3748#define elf_backend_plt_header_size PLT_INITIAL_ENTRY_SIZE
3749
3750#define bfd_elf64_bfd_copy_private_bfd_data ppc64_elf_copy_private_bfd_data
3751#define bfd_elf64_bfd_merge_private_bfd_data ppc64_elf_merge_private_bfd_data
3752#define bfd_elf64_bfd_reloc_type_lookup ppc64_elf_reloc_type_lookup
3753#define bfd_elf64_bfd_set_private_flags ppc64_elf_set_private_flags
3754#define bfd_elf64_bfd_final_link ppc64_elf_final_link
3755
3756#define elf_backend_gc_mark_hook ppc64_elf_gc_mark_hook
3757#define elf_backend_gc_sweep_hook ppc64_elf_gc_sweep_hook
3758#define elf_backend_section_from_shdr ppc64_elf_section_from_shdr
3759#define elf_backend_relocate_section ppc64_elf_relocate_section
3760#define elf_backend_create_dynamic_sections ppc64_elf_create_dynamic_sections
3761#define elf_backend_check_relocs ppc64_elf_check_relocs
3762#define elf_backend_adjust_dynamic_symbol ppc64_elf_adjust_dynamic_symbol
3763#define elf_backend_size_dynamic_sections ppc64_elf_size_dynamic_sections
3764#define elf_backend_finish_dynamic_symbol ppc64_elf_finish_dynamic_symbol
3765#define elf_backend_finish_dynamic_sections ppc64_elf_finish_dynamic_sections
3766#define elf_backend_fake_sections ppc64_elf_fake_sections
3767
3768#include "elf64-target.h"
This page took 0.171714 seconds and 4 git commands to generate.