1
/* PowerPC64-specific support for 64-bit ELF.
2
Copyright 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
3
Written by Linus Nordberg, Swox AB <info@swox.com>,
4
based on elf32-ppc.c by Ian Lance Taylor.
6
This file is part of BFD, the Binary File Descriptor library.
8
This program is free software; you can redistribute it and/or modify
9
it under the terms of the GNU General Public License as published by
10
the Free Software Foundation; either version 2 of the License, or
11
(at your option) any later version.
13
This program is distributed in the hope that it will be useful,
14
but WITHOUT ANY WARRANTY; without even the implied warranty of
15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
GNU General Public License for more details.
18
You should have received a copy of the GNU General Public License
19
along with this program; if not, write to the Free Software
20
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
22
/* This file is based on the 64-bit PowerPC ELF ABI. It is also based
23
on the file elf32-ppc.c. */
31
#include "elf64-ppc.h"
33
#define USE_RELA /* we want RELA relocations, not REL. */
36
static void ppc_howto_init
38
static reloc_howto_type *ppc64_elf_reloc_type_lookup
39
PARAMS ((bfd *abfd, bfd_reloc_code_real_type code));
40
static void ppc64_elf_info_to_howto
41
PARAMS ((bfd *abfd, arelent *cache_ptr, Elf64_Internal_Rela *dst));
42
static bfd_reloc_status_type ppc64_elf_ha_reloc
43
PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
44
static bfd_reloc_status_type ppc64_elf_brtaken_reloc
45
PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
46
static bfd_reloc_status_type ppc64_elf_sectoff_reloc
47
PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
48
static bfd_reloc_status_type ppc64_elf_sectoff_ha_reloc
49
PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
50
static bfd_reloc_status_type ppc64_elf_toc_reloc
51
PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
52
static bfd_reloc_status_type ppc64_elf_toc_ha_reloc
53
PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
54
static bfd_reloc_status_type ppc64_elf_toc64_reloc
55
PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
56
static bfd_reloc_status_type ppc64_elf_unhandled_reloc
57
PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
58
static boolean ppc64_elf_object_p
60
static boolean ppc64_elf_merge_private_bfd_data
61
PARAMS ((bfd *, bfd *));
64
/* The name of the dynamic interpreter. This is put in the .interp
66
#define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
68
/* The size in bytes of an entry in the procedure linkage table. */
69
#define PLT_ENTRY_SIZE 24
71
/* The initial size of the plt reserved for the dynamic linker. */
72
#define PLT_INITIAL_ENTRY_SIZE PLT_ENTRY_SIZE
74
/* TOC base pointers offset from start of TOC. */
75
#define TOC_BASE_OFF (0x8000)
77
/* .plt call stub instructions. */
78
#define ADDIS_R12_R2 0x3d820000 /* addis %r12,%r2,xxx@ha */
79
#define STD_R2_40R1 0xf8410028 /* std %r2,40(%r1) */
80
#define LD_R11_0R12 0xe96c0000 /* ld %r11,xxx+0@l(%r12) */
81
#define LD_R2_0R12 0xe84c0000 /* ld %r2,xxx+8@l(%r12) */
82
#define MTCTR_R11 0x7d6903a6 /* mtctr %r11 */
83
/* ld %r11,xxx+16@l(%r12) */
84
#define BCTR 0x4e800420 /* bctr */
86
/* The normal stub is this size. */
87
#define PLT_CALL_STUB_SIZE (7*4)
89
/* But sometimes the .plt entry crosses a 64k boundary, and we need
90
to adjust the high word with this insn. */
91
#define ADDIS_R12_R12_1 0x3d8c0001 /* addis %r12,%r12,1 */
93
/* The .glink fixup call stub is the same as the .plt call stub, but
94
the first instruction restores r2, and the std is omitted. */
95
#define LD_R2_40R1 0xe8410028 /* ld %r2,40(%r1) */
97
/* Always allow this much space. */
98
#define GLINK_CALL_STUB_SIZE (8*4)
101
#define NOP 0x60000000
103
/* Some other nops. */
104
#define CROR_151515 0x4def7b82
105
#define CROR_313131 0x4ffffb82
107
/* .glink entries for the first 32k functions are two instructions. */
108
#define LI_R0_0 0x38000000 /* li %r0,0 */
109
#define B_DOT 0x48000000 /* b . */
111
/* After that, we need two instructions to load the index, followed by
113
#define LIS_R0_0 0x3c000000 /* lis %r0,0 */
114
#define ORI_R0_R0_0 0x60000000 /* ori %r0,%r0,0 */
116
/* Instructions to save and restore floating point regs. */
117
#define STFD_FR0_0R1 0xd8010000 /* stfd %fr0,0(%r1) */
118
#define LFD_FR0_0R1 0xc8010000 /* lfd %fr0,0(%r1) */
119
#define BLR 0x4e800020 /* blr */
121
/* Since .opd is an array of descriptors and each entry will end up
122
with identical R_PPC64_RELATIVE relocs, there is really no need to
123
propagate .opd relocs; The dynamic linker should be taught to
124
relocate .opd without reloc entries. */
125
#ifndef NO_OPD_RELOCS
126
#define NO_OPD_RELOCS 0
129
#define ONES(n) (((bfd_vma) 1 << ((n) - 1) << 1) - 1)
131
/* Relocation HOWTO's. */
132
static reloc_howto_type *ppc64_elf_howto_table[(int) R_PPC_max];
134
static reloc_howto_type ppc64_elf_howto_raw[] = {
135
/* This reloc does nothing. */
136
HOWTO (R_PPC64_NONE, /* type */
138
0, /* size (0 = byte, 1 = short, 2 = long) */
140
false, /* pc_relative */
142
complain_overflow_dont, /* complain_on_overflow */
143
bfd_elf_generic_reloc, /* special_function */
144
"R_PPC64_NONE", /* name */
145
false, /* partial_inplace */
148
false), /* pcrel_offset */
150
/* A standard 32 bit relocation. */
151
HOWTO (R_PPC64_ADDR32, /* type */
153
2, /* size (0 = byte, 1 = short, 2 = long) */
155
false, /* pc_relative */
157
complain_overflow_bitfield, /* complain_on_overflow */
158
bfd_elf_generic_reloc, /* special_function */
159
"R_PPC64_ADDR32", /* name */
160
false, /* partial_inplace */
162
0xffffffff, /* dst_mask */
163
false), /* pcrel_offset */
165
/* An absolute 26 bit branch; the lower two bits must be zero.
166
FIXME: we don't check that, we just clear them. */
167
HOWTO (R_PPC64_ADDR24, /* type */
169
2, /* size (0 = byte, 1 = short, 2 = long) */
171
false, /* pc_relative */
173
complain_overflow_bitfield, /* complain_on_overflow */
174
bfd_elf_generic_reloc, /* special_function */
175
"R_PPC64_ADDR24", /* name */
176
false, /* partial_inplace */
177
0xfc000003, /* src_mask */
178
0x03fffffc, /* dst_mask */
179
false), /* pcrel_offset */
181
/* A standard 16 bit relocation. */
182
HOWTO (R_PPC64_ADDR16, /* type */
184
1, /* size (0 = byte, 1 = short, 2 = long) */
186
false, /* pc_relative */
188
complain_overflow_bitfield, /* complain_on_overflow */
189
bfd_elf_generic_reloc, /* special_function */
190
"R_PPC64_ADDR16", /* name */
191
false, /* partial_inplace */
193
0xffff, /* dst_mask */
194
false), /* pcrel_offset */
196
/* A 16 bit relocation without overflow. */
197
HOWTO (R_PPC64_ADDR16_LO, /* type */
199
1, /* size (0 = byte, 1 = short, 2 = long) */
201
false, /* pc_relative */
203
complain_overflow_dont,/* complain_on_overflow */
204
bfd_elf_generic_reloc, /* special_function */
205
"R_PPC64_ADDR16_LO", /* name */
206
false, /* partial_inplace */
208
0xffff, /* dst_mask */
209
false), /* pcrel_offset */
211
/* Bits 16-31 of an address. */
212
HOWTO (R_PPC64_ADDR16_HI, /* type */
214
1, /* size (0 = byte, 1 = short, 2 = long) */
216
false, /* pc_relative */
218
complain_overflow_dont, /* complain_on_overflow */
219
bfd_elf_generic_reloc, /* special_function */
220
"R_PPC64_ADDR16_HI", /* name */
221
false, /* partial_inplace */
223
0xffff, /* dst_mask */
224
false), /* pcrel_offset */
226
/* Bits 16-31 of an address, plus 1 if the contents of the low 16
227
bits, treated as a signed number, is negative. */
228
HOWTO (R_PPC64_ADDR16_HA, /* type */
230
1, /* size (0 = byte, 1 = short, 2 = long) */
232
false, /* pc_relative */
234
complain_overflow_dont, /* complain_on_overflow */
235
ppc64_elf_ha_reloc, /* special_function */
236
"R_PPC64_ADDR16_HA", /* name */
237
false, /* partial_inplace */
239
0xffff, /* dst_mask */
240
false), /* pcrel_offset */
242
/* An absolute 16 bit branch; the lower two bits must be zero.
243
FIXME: we don't check that, we just clear them. */
244
HOWTO (R_PPC64_ADDR14, /* type */
246
2, /* size (0 = byte, 1 = short, 2 = long) */
248
false, /* pc_relative */
250
complain_overflow_bitfield, /* complain_on_overflow */
251
bfd_elf_generic_reloc, /* special_function */
252
"R_PPC64_ADDR14", /* name */
253
false, /* partial_inplace */
254
0xffff0003, /* src_mask */
255
0x0000fffc, /* dst_mask */
256
false), /* pcrel_offset */
258
/* An absolute 16 bit branch, for which bit 10 should be set to
259
indicate that the branch is expected to be taken. The lower two
260
bits must be zero. */
261
HOWTO (R_PPC64_ADDR14_BRTAKEN, /* type */
263
2, /* size (0 = byte, 1 = short, 2 = long) */
265
false, /* pc_relative */
267
complain_overflow_bitfield, /* complain_on_overflow */
268
ppc64_elf_brtaken_reloc, /* special_function */
269
"R_PPC64_ADDR14_BRTAKEN",/* name */
270
false, /* partial_inplace */
271
0xffff0003, /* src_mask */
272
0x0000fffc, /* dst_mask */
273
false), /* pcrel_offset */
275
/* An absolute 16 bit branch, for which bit 10 should be set to
276
indicate that the branch is not expected to be taken. The lower
277
two bits must be zero. */
278
HOWTO (R_PPC64_ADDR14_BRNTAKEN, /* type */
280
2, /* size (0 = byte, 1 = short, 2 = long) */
282
false, /* pc_relative */
284
complain_overflow_bitfield, /* complain_on_overflow */
285
ppc64_elf_brtaken_reloc, /* special_function */
286
"R_PPC64_ADDR14_BRNTAKEN",/* name */
287
false, /* partial_inplace */
288
0xffff0003, /* src_mask */
289
0x0000fffc, /* dst_mask */
290
false), /* pcrel_offset */
292
/* A relative 26 bit branch; the lower two bits must be zero. */
293
HOWTO (R_PPC64_REL24, /* type */
295
2, /* size (0 = byte, 1 = short, 2 = long) */
297
true, /* pc_relative */
299
complain_overflow_signed, /* complain_on_overflow */
300
bfd_elf_generic_reloc, /* special_function */
301
"R_PPC64_REL24", /* name */
302
false, /* partial_inplace */
303
0xfc000003, /* src_mask */
304
0x03fffffc, /* dst_mask */
305
true), /* pcrel_offset */
307
/* A relative 16 bit branch; the lower two bits must be zero. */
308
HOWTO (R_PPC64_REL14, /* type */
310
2, /* size (0 = byte, 1 = short, 2 = long) */
312
true, /* pc_relative */
314
complain_overflow_signed, /* complain_on_overflow */
315
bfd_elf_generic_reloc, /* special_function */
316
"R_PPC64_REL14", /* name */
317
false, /* partial_inplace */
318
0xffff0003, /* src_mask */
319
0x0000fffc, /* dst_mask */
320
true), /* pcrel_offset */
322
/* A relative 16 bit branch. Bit 10 should be set to indicate that
323
the branch is expected to be taken. The lower two bits must be
325
HOWTO (R_PPC64_REL14_BRTAKEN, /* type */
327
2, /* size (0 = byte, 1 = short, 2 = long) */
329
true, /* pc_relative */
331
complain_overflow_signed, /* complain_on_overflow */
332
ppc64_elf_brtaken_reloc, /* special_function */
333
"R_PPC64_REL14_BRTAKEN", /* name */
334
false, /* partial_inplace */
335
0xffff0003, /* src_mask */
336
0x0000fffc, /* dst_mask */
337
true), /* pcrel_offset */
339
/* A relative 16 bit branch. Bit 10 should be set to indicate that
340
the branch is not expected to be taken. The lower two bits must
342
HOWTO (R_PPC64_REL14_BRNTAKEN, /* type */
344
2, /* size (0 = byte, 1 = short, 2 = long) */
346
true, /* pc_relative */
348
complain_overflow_signed, /* complain_on_overflow */
349
ppc64_elf_brtaken_reloc, /* special_function */
350
"R_PPC64_REL14_BRNTAKEN",/* name */
351
false, /* partial_inplace */
352
0xffff0003, /* src_mask */
353
0x0000fffc, /* dst_mask */
354
true), /* pcrel_offset */
356
/* Like R_PPC64_ADDR16, but referring to the GOT table entry for the
358
HOWTO (R_PPC64_GOT16, /* type */
360
1, /* size (0 = byte, 1 = short, 2 = long) */
362
false, /* pc_relative */
364
complain_overflow_signed, /* complain_on_overflow */
365
ppc64_elf_unhandled_reloc, /* special_function */
366
"R_PPC64_GOT16", /* name */
367
false, /* partial_inplace */
369
0xffff, /* dst_mask */
370
false), /* pcrel_offset */
372
/* Like R_PPC64_ADDR16_LO, but referring to the GOT table entry for
374
HOWTO (R_PPC64_GOT16_LO, /* type */
376
1, /* size (0 = byte, 1 = short, 2 = long) */
378
false, /* pc_relative */
380
complain_overflow_dont, /* complain_on_overflow */
381
ppc64_elf_unhandled_reloc, /* special_function */
382
"R_PPC64_GOT16_LO", /* name */
383
false, /* partial_inplace */
385
0xffff, /* dst_mask */
386
false), /* pcrel_offset */
388
/* Like R_PPC64_ADDR16_HI, but referring to the GOT table entry for
390
HOWTO (R_PPC64_GOT16_HI, /* type */
392
1, /* size (0 = byte, 1 = short, 2 = long) */
394
false, /* pc_relative */
396
complain_overflow_dont,/* complain_on_overflow */
397
ppc64_elf_unhandled_reloc, /* special_function */
398
"R_PPC64_GOT16_HI", /* name */
399
false, /* partial_inplace */
401
0xffff, /* dst_mask */
402
false), /* pcrel_offset */
404
/* Like R_PPC64_ADDR16_HA, but referring to the GOT table entry for
406
HOWTO (R_PPC64_GOT16_HA, /* type */
408
1, /* size (0 = byte, 1 = short, 2 = long) */
410
false, /* pc_relative */
412
complain_overflow_dont,/* complain_on_overflow */
413
ppc64_elf_unhandled_reloc, /* special_function */
414
"R_PPC64_GOT16_HA", /* name */
415
false, /* partial_inplace */
417
0xffff, /* dst_mask */
418
false), /* pcrel_offset */
420
/* This is used only by the dynamic linker. The symbol should exist
421
both in the object being run and in some shared library. The
422
dynamic linker copies the data addressed by the symbol from the
423
shared library into the object, because the object being
424
run has to have the data at some particular address. */
425
HOWTO (R_PPC64_COPY, /* type */
427
0, /* this one is variable size */
429
false, /* pc_relative */
431
complain_overflow_dont, /* complain_on_overflow */
432
ppc64_elf_unhandled_reloc, /* special_function */
433
"R_PPC64_COPY", /* name */
434
false, /* partial_inplace */
437
false), /* pcrel_offset */
439
/* Like R_PPC64_ADDR64, but used when setting global offset table
441
HOWTO (R_PPC64_GLOB_DAT, /* type */
443
4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
445
false, /* pc_relative */
447
complain_overflow_dont, /* complain_on_overflow */
448
ppc64_elf_unhandled_reloc, /* special_function */
449
"R_PPC64_GLOB_DAT", /* name */
450
false, /* partial_inplace */
452
ONES (64), /* dst_mask */
453
false), /* pcrel_offset */
455
/* Created by the link editor. Marks a procedure linkage table
456
entry for a symbol. */
457
HOWTO (R_PPC64_JMP_SLOT, /* type */
459
0, /* size (0 = byte, 1 = short, 2 = long) */
461
false, /* pc_relative */
463
complain_overflow_dont, /* complain_on_overflow */
464
ppc64_elf_unhandled_reloc, /* special_function */
465
"R_PPC64_JMP_SLOT", /* name */
466
false, /* partial_inplace */
469
false), /* pcrel_offset */
471
/* Used only by the dynamic linker. When the object is run, this
472
doubleword64 is set to the load address of the object, plus the
474
HOWTO (R_PPC64_RELATIVE, /* type */
476
4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
478
false, /* pc_relative */
480
complain_overflow_dont, /* complain_on_overflow */
481
bfd_elf_generic_reloc, /* special_function */
482
"R_PPC64_RELATIVE", /* name */
483
false, /* partial_inplace */
485
ONES (64), /* dst_mask */
486
false), /* pcrel_offset */
488
/* Like R_PPC64_ADDR32, but may be unaligned. */
489
HOWTO (R_PPC64_UADDR32, /* type */
491
2, /* size (0 = byte, 1 = short, 2 = long) */
493
false, /* pc_relative */
495
complain_overflow_bitfield, /* complain_on_overflow */
496
bfd_elf_generic_reloc, /* special_function */
497
"R_PPC64_UADDR32", /* name */
498
false, /* partial_inplace */
500
0xffffffff, /* dst_mask */
501
false), /* pcrel_offset */
503
/* Like R_PPC64_ADDR16, but may be unaligned. */
504
HOWTO (R_PPC64_UADDR16, /* type */
506
1, /* size (0 = byte, 1 = short, 2 = long) */
508
false, /* pc_relative */
510
complain_overflow_bitfield, /* complain_on_overflow */
511
bfd_elf_generic_reloc, /* special_function */
512
"R_PPC64_UADDR16", /* name */
513
false, /* partial_inplace */
515
0xffff, /* dst_mask */
516
false), /* pcrel_offset */
518
/* 32-bit PC relative. */
519
HOWTO (R_PPC64_REL32, /* type */
521
2, /* size (0 = byte, 1 = short, 2 = long) */
523
true, /* pc_relative */
525
/* FIXME: Verify. Was complain_overflow_bitfield. */
526
complain_overflow_signed, /* complain_on_overflow */
527
bfd_elf_generic_reloc, /* special_function */
528
"R_PPC64_REL32", /* name */
529
false, /* partial_inplace */
531
0xffffffff, /* dst_mask */
532
true), /* pcrel_offset */
534
/* 32-bit relocation to the symbol's procedure linkage table. */
535
HOWTO (R_PPC64_PLT32, /* type */
537
2, /* size (0 = byte, 1 = short, 2 = long) */
539
false, /* pc_relative */
541
complain_overflow_bitfield, /* complain_on_overflow */
542
ppc64_elf_unhandled_reloc, /* special_function */
543
"R_PPC64_PLT32", /* name */
544
false, /* partial_inplace */
546
0xffffffff, /* dst_mask */
547
false), /* pcrel_offset */
549
/* 32-bit PC relative relocation to the symbol's procedure linkage table.
550
FIXME: R_PPC64_PLTREL32 not supported. */
551
HOWTO (R_PPC64_PLTREL32, /* type */
553
2, /* size (0 = byte, 1 = short, 2 = long) */
555
true, /* pc_relative */
557
complain_overflow_signed, /* complain_on_overflow */
558
bfd_elf_generic_reloc, /* special_function */
559
"R_PPC64_PLTREL32", /* name */
560
false, /* partial_inplace */
562
0xffffffff, /* dst_mask */
563
true), /* pcrel_offset */
565
/* Like R_PPC64_ADDR16_LO, but referring to the PLT table entry for
567
HOWTO (R_PPC64_PLT16_LO, /* type */
569
1, /* size (0 = byte, 1 = short, 2 = long) */
571
false, /* pc_relative */
573
complain_overflow_dont, /* complain_on_overflow */
574
ppc64_elf_unhandled_reloc, /* special_function */
575
"R_PPC64_PLT16_LO", /* name */
576
false, /* partial_inplace */
578
0xffff, /* dst_mask */
579
false), /* pcrel_offset */
581
/* Like R_PPC64_ADDR16_HI, but referring to the PLT table entry for
583
HOWTO (R_PPC64_PLT16_HI, /* type */
585
1, /* size (0 = byte, 1 = short, 2 = long) */
587
false, /* pc_relative */
589
complain_overflow_dont, /* complain_on_overflow */
590
ppc64_elf_unhandled_reloc, /* special_function */
591
"R_PPC64_PLT16_HI", /* name */
592
false, /* partial_inplace */
594
0xffff, /* dst_mask */
595
false), /* pcrel_offset */
597
/* Like R_PPC64_ADDR16_HA, but referring to the PLT table entry for
599
HOWTO (R_PPC64_PLT16_HA, /* type */
601
1, /* size (0 = byte, 1 = short, 2 = long) */
603
false, /* pc_relative */
605
complain_overflow_dont, /* complain_on_overflow */
606
ppc64_elf_unhandled_reloc, /* special_function */
607
"R_PPC64_PLT16_HA", /* name */
608
false, /* partial_inplace */
610
0xffff, /* dst_mask */
611
false), /* pcrel_offset */
613
/* 16-bit section relative relocation. */
614
HOWTO (R_PPC64_SECTOFF, /* type */
616
1, /* size (0 = byte, 1 = short, 2 = long) */
618
false, /* pc_relative */
620
complain_overflow_bitfield, /* complain_on_overflow */
621
ppc64_elf_sectoff_reloc, /* special_function */
622
"R_PPC64_SECTOFF", /* name */
623
false, /* partial_inplace */
625
0xffff, /* dst_mask */
626
false), /* pcrel_offset */
628
/* Like R_PPC64_SECTOFF, but no overflow warning. */
629
HOWTO (R_PPC64_SECTOFF_LO, /* type */
631
1, /* size (0 = byte, 1 = short, 2 = long) */
633
false, /* pc_relative */
635
complain_overflow_dont, /* complain_on_overflow */
636
ppc64_elf_sectoff_reloc, /* special_function */
637
"R_PPC64_SECTOFF_LO", /* name */
638
false, /* partial_inplace */
640
0xffff, /* dst_mask */
641
false), /* pcrel_offset */
643
/* 16-bit upper half section relative relocation. */
644
HOWTO (R_PPC64_SECTOFF_HI, /* type */
646
1, /* size (0 = byte, 1 = short, 2 = long) */
648
false, /* pc_relative */
650
complain_overflow_dont, /* complain_on_overflow */
651
ppc64_elf_sectoff_reloc, /* special_function */
652
"R_PPC64_SECTOFF_HI", /* name */
653
false, /* partial_inplace */
655
0xffff, /* dst_mask */
656
false), /* pcrel_offset */
658
/* 16-bit upper half adjusted section relative relocation. */
659
HOWTO (R_PPC64_SECTOFF_HA, /* type */
661
1, /* size (0 = byte, 1 = short, 2 = long) */
663
false, /* pc_relative */
665
complain_overflow_dont, /* complain_on_overflow */
666
ppc64_elf_sectoff_ha_reloc, /* special_function */
667
"R_PPC64_SECTOFF_HA", /* name */
668
false, /* partial_inplace */
670
0xffff, /* dst_mask */
671
false), /* pcrel_offset */
673
/* Like R_PPC64_REL24 without touching the two least significant
674
bits. Should have been named R_PPC64_REL30! */
675
HOWTO (R_PPC64_ADDR30, /* type */
677
2, /* size (0 = byte, 1 = short, 2 = long) */
679
true, /* pc_relative */
681
complain_overflow_dont, /* complain_on_overflow */
682
bfd_elf_generic_reloc, /* special_function */
683
"R_PPC64_ADDR30", /* name */
684
false, /* partial_inplace */
685
0x00000003, /* src_mask */
686
0xfffffffc, /* dst_mask */
687
true), /* pcrel_offset */
689
/* Relocs in the 64-bit PowerPC ELF ABI, not in the 32-bit ABI. */
691
/* A standard 64-bit relocation. */
692
HOWTO (R_PPC64_ADDR64, /* type */
694
4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
696
false, /* pc_relative */
698
complain_overflow_dont, /* complain_on_overflow */
699
bfd_elf_generic_reloc, /* special_function */
700
"R_PPC64_ADDR64", /* name */
701
false, /* partial_inplace */
703
ONES (64), /* dst_mask */
704
false), /* pcrel_offset */
706
/* The bits 32-47 of an address. */
707
HOWTO (R_PPC64_ADDR16_HIGHER, /* type */
709
1, /* size (0 = byte, 1 = short, 2 = long) */
711
false, /* pc_relative */
713
complain_overflow_dont, /* complain_on_overflow */
714
bfd_elf_generic_reloc, /* special_function */
715
"R_PPC64_ADDR16_HIGHER", /* name */
716
false, /* partial_inplace */
718
0xffff, /* dst_mask */
719
false), /* pcrel_offset */
721
/* The bits 32-47 of an address, plus 1 if the contents of the low
722
16 bits, treated as a signed number, is negative. */
723
HOWTO (R_PPC64_ADDR16_HIGHERA, /* type */
725
1, /* size (0 = byte, 1 = short, 2 = long) */
727
false, /* pc_relative */
729
complain_overflow_dont, /* complain_on_overflow */
730
ppc64_elf_ha_reloc, /* special_function */
731
"R_PPC64_ADDR16_HIGHERA", /* name */
732
false, /* partial_inplace */
734
0xffff, /* dst_mask */
735
false), /* pcrel_offset */
737
/* The bits 48-63 of an address. */
738
HOWTO (R_PPC64_ADDR16_HIGHEST,/* type */
740
1, /* size (0 = byte, 1 = short, 2 = long) */
742
false, /* pc_relative */
744
complain_overflow_dont, /* complain_on_overflow */
745
bfd_elf_generic_reloc, /* special_function */
746
"R_PPC64_ADDR16_HIGHEST", /* name */
747
false, /* partial_inplace */
749
0xffff, /* dst_mask */
750
false), /* pcrel_offset */
752
/* The bits 48-63 of an address, plus 1 if the contents of the low
753
16 bits, treated as a signed number, is negative. */
754
HOWTO (R_PPC64_ADDR16_HIGHESTA,/* type */
756
1, /* size (0 = byte, 1 = short, 2 = long) */
758
false, /* pc_relative */
760
complain_overflow_dont, /* complain_on_overflow */
761
ppc64_elf_ha_reloc, /* special_function */
762
"R_PPC64_ADDR16_HIGHESTA", /* name */
763
false, /* partial_inplace */
765
0xffff, /* dst_mask */
766
false), /* pcrel_offset */
768
/* Like ADDR64, but may be unaligned. */
769
HOWTO (R_PPC64_UADDR64, /* type */
771
4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
773
false, /* pc_relative */
775
complain_overflow_dont, /* complain_on_overflow */
776
bfd_elf_generic_reloc, /* special_function */
777
"R_PPC64_UADDR64", /* name */
778
false, /* partial_inplace */
780
ONES (64), /* dst_mask */
781
false), /* pcrel_offset */
783
/* 64-bit relative relocation. */
784
HOWTO (R_PPC64_REL64, /* type */
786
4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
788
true, /* pc_relative */
790
complain_overflow_dont, /* complain_on_overflow */
791
bfd_elf_generic_reloc, /* special_function */
792
"R_PPC64_REL64", /* name */
793
false, /* partial_inplace */
795
ONES (64), /* dst_mask */
796
true), /* pcrel_offset */
798
/* 64-bit relocation to the symbol's procedure linkage table. */
799
HOWTO (R_PPC64_PLT64, /* type */
801
4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
803
false, /* pc_relative */
805
complain_overflow_dont, /* complain_on_overflow */
806
ppc64_elf_unhandled_reloc, /* special_function */
807
"R_PPC64_PLT64", /* name */
808
false, /* partial_inplace */
810
ONES (64), /* dst_mask */
811
false), /* pcrel_offset */
813
/* 64-bit PC relative relocation to the symbol's procedure linkage
815
/* FIXME: R_PPC64_PLTREL64 not supported. */
816
HOWTO (R_PPC64_PLTREL64, /* type */
818
4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
820
true, /* pc_relative */
822
complain_overflow_dont, /* complain_on_overflow */
823
ppc64_elf_unhandled_reloc, /* special_function */
824
"R_PPC64_PLTREL64", /* name */
825
false, /* partial_inplace */
827
ONES (64), /* dst_mask */
828
true), /* pcrel_offset */
830
/* 16 bit TOC-relative relocation. */
832
/* R_PPC64_TOC16 47 half16* S + A - .TOC. */
833
HOWTO (R_PPC64_TOC16, /* type */
835
1, /* size (0 = byte, 1 = short, 2 = long) */
837
false, /* pc_relative */
839
complain_overflow_signed, /* complain_on_overflow */
840
ppc64_elf_toc_reloc, /* special_function */
841
"R_PPC64_TOC16", /* name */
842
false, /* partial_inplace */
844
0xffff, /* dst_mask */
845
false), /* pcrel_offset */
847
/* 16 bit TOC-relative relocation without overflow. */
849
/* R_PPC64_TOC16_LO 48 half16 #lo (S + A - .TOC.) */
850
HOWTO (R_PPC64_TOC16_LO, /* type */
852
1, /* size (0 = byte, 1 = short, 2 = long) */
854
false, /* pc_relative */
856
complain_overflow_dont, /* complain_on_overflow */
857
ppc64_elf_toc_reloc, /* special_function */
858
"R_PPC64_TOC16_LO", /* name */
859
false, /* partial_inplace */
861
0xffff, /* dst_mask */
862
false), /* pcrel_offset */
864
/* 16 bit TOC-relative relocation, high 16 bits. */
866
/* R_PPC64_TOC16_HI 49 half16 #hi (S + A - .TOC.) */
867
HOWTO (R_PPC64_TOC16_HI, /* type */
869
1, /* size (0 = byte, 1 = short, 2 = long) */
871
false, /* pc_relative */
873
complain_overflow_dont, /* complain_on_overflow */
874
ppc64_elf_toc_reloc, /* special_function */
875
"R_PPC64_TOC16_HI", /* name */
876
false, /* partial_inplace */
878
0xffff, /* dst_mask */
879
false), /* pcrel_offset */
881
/* 16 bit TOC-relative relocation, high 16 bits, plus 1 if the
882
contents of the low 16 bits, treated as a signed number, is
885
/* R_PPC64_TOC16_HA 50 half16 #ha (S + A - .TOC.) */
886
HOWTO (R_PPC64_TOC16_HA, /* type */
888
1, /* size (0 = byte, 1 = short, 2 = long) */
890
false, /* pc_relative */
892
complain_overflow_dont, /* complain_on_overflow */
893
ppc64_elf_toc_ha_reloc, /* special_function */
894
"R_PPC64_TOC16_HA", /* name */
895
false, /* partial_inplace */
897
0xffff, /* dst_mask */
898
false), /* pcrel_offset */
900
/* 64-bit relocation; insert value of TOC base (.TOC.). */
902
/* R_PPC64_TOC 51 doubleword64 .TOC. */
903
HOWTO (R_PPC64_TOC, /* type */
905
4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
907
false, /* pc_relative */
909
complain_overflow_bitfield, /* complain_on_overflow */
910
ppc64_elf_toc64_reloc, /* special_function */
911
"R_PPC64_TOC", /* name */
912
false, /* partial_inplace */
914
ONES (64), /* dst_mask */
915
false), /* pcrel_offset */
917
/* Like R_PPC64_GOT16, but also informs the link editor that the
918
value to relocate may (!) refer to a PLT entry which the link
919
editor (a) may replace with the symbol value. If the link editor
920
is unable to fully resolve the symbol, it may (b) create a PLT
921
entry and store the address to the new PLT entry in the GOT.
922
This permits lazy resolution of function symbols at run time.
923
The link editor may also skip all of this and just (c) emit a
924
R_PPC64_GLOB_DAT to tie the symbol to the GOT entry. */
925
/* FIXME: R_PPC64_PLTGOT16 not implemented. */
926
HOWTO (R_PPC64_PLTGOT16, /* type */
928
1, /* size (0 = byte, 1 = short, 2 = long) */
930
false, /* pc_relative */
932
complain_overflow_signed, /* complain_on_overflow */
933
ppc64_elf_unhandled_reloc, /* special_function */
934
"R_PPC64_PLTGOT16", /* name */
935
false, /* partial_inplace */
937
0xffff, /* dst_mask */
938
false), /* pcrel_offset */
940
/* Like R_PPC64_PLTGOT16, but without overflow. */
941
/* FIXME: R_PPC64_PLTGOT16_LO not implemented. */
942
HOWTO (R_PPC64_PLTGOT16_LO, /* type */
944
1, /* size (0 = byte, 1 = short, 2 = long) */
946
false, /* pc_relative */
948
complain_overflow_dont, /* complain_on_overflow */
949
ppc64_elf_unhandled_reloc, /* special_function */
950
"R_PPC64_PLTGOT16_LO", /* name */
951
false, /* partial_inplace */
953
0xffff, /* dst_mask */
954
false), /* pcrel_offset */
956
/* Like R_PPC64_PLT_GOT16, but using bits 16-31 of the address. */
957
/* FIXME: R_PPC64_PLTGOT16_HI not implemented. */
958
HOWTO (R_PPC64_PLTGOT16_HI, /* type */
960
1, /* size (0 = byte, 1 = short, 2 = long) */
962
false, /* pc_relative */
964
complain_overflow_dont, /* complain_on_overflow */
965
ppc64_elf_unhandled_reloc, /* special_function */
966
"R_PPC64_PLTGOT16_HI", /* name */
967
false, /* partial_inplace */
969
0xffff, /* dst_mask */
970
false), /* pcrel_offset */
972
/* Like R_PPC64_PLT_GOT16, but using bits 16-31 of the address, plus
973
1 if the contents of the low 16 bits, treated as a signed number,
975
/* FIXME: R_PPC64_PLTGOT16_HA not implemented. */
976
HOWTO (R_PPC64_PLTGOT16_HA, /* type */
978
1, /* size (0 = byte, 1 = short, 2 = long) */
980
false, /* pc_relative */
982
complain_overflow_dont,/* complain_on_overflow */
983
ppc64_elf_unhandled_reloc, /* special_function */
984
"R_PPC64_PLTGOT16_HA", /* name */
985
false, /* partial_inplace */
987
0xffff, /* dst_mask */
988
false), /* pcrel_offset */
990
/* Like R_PPC64_ADDR16, but for instructions with a DS field. */
991
HOWTO (R_PPC64_ADDR16_DS, /* type */
993
1, /* size (0 = byte, 1 = short, 2 = long) */
995
false, /* pc_relative */
997
complain_overflow_bitfield, /* complain_on_overflow */
998
bfd_elf_generic_reloc, /* special_function */
999
"R_PPC64_ADDR16_DS", /* name */
1000
false, /* partial_inplace */
1001
0x0003, /* src_mask */
1002
0xfffc, /* dst_mask */
1003
false), /* pcrel_offset */
1005
/* Like R_PPC64_ADDR16_LO, but for instructions with a DS field. */
1006
HOWTO (R_PPC64_ADDR16_LO_DS, /* type */
1008
1, /* size (0 = byte, 1 = short, 2 = long) */
1010
false, /* pc_relative */
1012
complain_overflow_dont,/* complain_on_overflow */
1013
bfd_elf_generic_reloc, /* special_function */
1014
"R_PPC64_ADDR16_LO_DS",/* name */
1015
false, /* partial_inplace */
1016
0x0003, /* src_mask */
1017
0xfffc, /* dst_mask */
1018
false), /* pcrel_offset */
1020
/* Like R_PPC64_GOT16, but for instructions with a DS field. */
1021
HOWTO (R_PPC64_GOT16_DS, /* type */
1023
1, /* size (0 = byte, 1 = short, 2 = long) */
1025
false, /* pc_relative */
1027
complain_overflow_signed, /* complain_on_overflow */
1028
ppc64_elf_unhandled_reloc, /* special_function */
1029
"R_PPC64_GOT16_DS", /* name */
1030
false, /* partial_inplace */
1031
0x0003, /* src_mask */
1032
0xfffc, /* dst_mask */
1033
false), /* pcrel_offset */
1035
/* Like R_PPC64_GOT16_LO, but for instructions with a DS field. */
1036
HOWTO (R_PPC64_GOT16_LO_DS, /* type */
1038
1, /* size (0 = byte, 1 = short, 2 = long) */
1040
false, /* pc_relative */
1042
complain_overflow_dont, /* complain_on_overflow */
1043
ppc64_elf_unhandled_reloc, /* special_function */
1044
"R_PPC64_GOT16_LO_DS", /* name */
1045
false, /* partial_inplace */
1046
0x0003, /* src_mask */
1047
0xfffc, /* dst_mask */
1048
false), /* pcrel_offset */
1050
/* Like R_PPC64_PLT16_LO, but for instructions with a DS field. */
1051
HOWTO (R_PPC64_PLT16_LO_DS, /* type */
1053
1, /* size (0 = byte, 1 = short, 2 = long) */
1055
false, /* pc_relative */
1057
complain_overflow_dont, /* complain_on_overflow */
1058
ppc64_elf_unhandled_reloc, /* special_function */
1059
"R_PPC64_PLT16_LO_DS", /* name */
1060
false, /* partial_inplace */
1061
0x0003, /* src_mask */
1062
0xfffc, /* dst_mask */
1063
false), /* pcrel_offset */
1065
/* Like R_PPC64_SECTOFF, but for instructions with a DS field. */
1066
HOWTO (R_PPC64_SECTOFF_DS, /* type */
1068
1, /* size (0 = byte, 1 = short, 2 = long) */
1070
false, /* pc_relative */
1072
complain_overflow_bitfield, /* complain_on_overflow */
1073
ppc64_elf_sectoff_reloc, /* special_function */
1074
"R_PPC64_SECTOFF_DS", /* name */
1075
false, /* partial_inplace */
1076
0x0003, /* src_mask */
1077
0xfffc, /* dst_mask */
1078
false), /* pcrel_offset */
1080
/* Like R_PPC64_SECTOFF_LO, but for instructions with a DS field. */
1081
HOWTO (R_PPC64_SECTOFF_LO_DS, /* type */
1083
1, /* size (0 = byte, 1 = short, 2 = long) */
1085
false, /* pc_relative */
1087
complain_overflow_dont, /* complain_on_overflow */
1088
ppc64_elf_sectoff_reloc, /* special_function */
1089
"R_PPC64_SECTOFF_LO_DS",/* name */
1090
false, /* partial_inplace */
1091
0x0003, /* src_mask */
1092
0xfffc, /* dst_mask */
1093
false), /* pcrel_offset */
1095
/* Like R_PPC64_TOC16, but for instructions with a DS field. */
1096
HOWTO (R_PPC64_TOC16_DS, /* type */
1098
1, /* size (0 = byte, 1 = short, 2 = long) */
1100
false, /* pc_relative */
1102
complain_overflow_signed, /* complain_on_overflow */
1103
ppc64_elf_toc_reloc, /* special_function */
1104
"R_PPC64_TOC16_DS", /* name */
1105
false, /* partial_inplace */
1106
0x0003, /* src_mask */
1107
0xfffc, /* dst_mask */
1108
false), /* pcrel_offset */
1110
/* Like R_PPC64_TOC16_LO, but for instructions with a DS field. */
1111
HOWTO (R_PPC64_TOC16_LO_DS, /* type */
1113
1, /* size (0 = byte, 1 = short, 2 = long) */
1115
false, /* pc_relative */
1117
complain_overflow_dont, /* complain_on_overflow */
1118
ppc64_elf_toc_reloc, /* special_function */
1119
"R_PPC64_TOC16_LO_DS", /* name */
1120
false, /* partial_inplace */
1121
0x0003, /* src_mask */
1122
0xfffc, /* dst_mask */
1123
false), /* pcrel_offset */
1125
/* Like R_PPC64_PLTGOT16, but for instructions with a DS field. */
1126
/* FIXME: R_PPC64_PLTGOT16_DS not implemented. */
1127
HOWTO (R_PPC64_PLTGOT16_DS, /* type */
1129
1, /* size (0 = byte, 1 = short, 2 = long) */
1131
false, /* pc_relative */
1133
complain_overflow_signed, /* complain_on_overflow */
1134
ppc64_elf_unhandled_reloc, /* special_function */
1135
"R_PPC64_PLTGOT16_DS", /* name */
1136
false, /* partial_inplace */
1137
0x0003, /* src_mask */
1138
0xfffc, /* dst_mask */
1139
false), /* pcrel_offset */
1141
/* Like R_PPC64_PLTGOT16_LO, but for instructions with a DS field. */
1142
/* FIXME: R_PPC64_PLTGOT16_LO not implemented. */
1143
HOWTO (R_PPC64_PLTGOT16_LO_DS,/* type */
1145
1, /* size (0 = byte, 1 = short, 2 = long) */
1147
false, /* pc_relative */
1149
complain_overflow_dont, /* complain_on_overflow */
1150
ppc64_elf_unhandled_reloc, /* special_function */
1151
"R_PPC64_PLTGOT16_LO_DS",/* name */
1152
false, /* partial_inplace */
1153
0x0003, /* src_mask */
1154
0xfffc, /* dst_mask */
1155
false), /* pcrel_offset */
1157
/* GNU extension to record C++ vtable hierarchy. */
1158
HOWTO (R_PPC64_GNU_VTINHERIT, /* type */
1160
0, /* size (0 = byte, 1 = short, 2 = long) */
1162
false, /* pc_relative */
1164
complain_overflow_dont, /* complain_on_overflow */
1165
NULL, /* special_function */
1166
"R_PPC64_GNU_VTINHERIT", /* name */
1167
false, /* partial_inplace */
1170
false), /* pcrel_offset */
1172
/* GNU extension to record C++ vtable member usage. */
1173
HOWTO (R_PPC64_GNU_VTENTRY, /* type */
1175
0, /* size (0 = byte, 1 = short, 2 = long) */
1177
false, /* pc_relative */
1179
complain_overflow_dont, /* complain_on_overflow */
1180
NULL, /* special_function */
1181
"R_PPC64_GNU_VTENTRY", /* name */
1182
false, /* partial_inplace */
1185
false), /* pcrel_offset */
1189
/* Initialize the ppc64_elf_howto_table, so that linear accesses can
1195
unsigned int i, type;
1198
i < sizeof (ppc64_elf_howto_raw) / sizeof (ppc64_elf_howto_raw[0]);
1201
type = ppc64_elf_howto_raw[i].type;
1202
BFD_ASSERT (type < (sizeof (ppc64_elf_howto_table)
1203
/ sizeof (ppc64_elf_howto_table[0])));
1204
ppc64_elf_howto_table[type] = &ppc64_elf_howto_raw[i];
1208
static reloc_howto_type *
1209
ppc64_elf_reloc_type_lookup (abfd, code)
1210
bfd *abfd ATTRIBUTE_UNUSED;
1211
bfd_reloc_code_real_type code;
1213
enum elf_ppc_reloc_type ppc_reloc = R_PPC_NONE;
1215
if (!ppc64_elf_howto_table[R_PPC64_ADDR32])
1216
/* Initialize howto table if needed. */
1222
return (reloc_howto_type *) NULL;
1224
case BFD_RELOC_NONE: ppc_reloc = R_PPC64_NONE;
1226
case BFD_RELOC_32: ppc_reloc = R_PPC64_ADDR32;
1228
case BFD_RELOC_PPC_BA26: ppc_reloc = R_PPC64_ADDR24;
1230
case BFD_RELOC_16: ppc_reloc = R_PPC64_ADDR16;
1232
case BFD_RELOC_LO16: ppc_reloc = R_PPC64_ADDR16_LO;
1234
case BFD_RELOC_HI16: ppc_reloc = R_PPC64_ADDR16_HI;
1236
case BFD_RELOC_HI16_S: ppc_reloc = R_PPC64_ADDR16_HA;
1238
case BFD_RELOC_PPC_BA16: ppc_reloc = R_PPC64_ADDR14;
1240
case BFD_RELOC_PPC_BA16_BRTAKEN: ppc_reloc = R_PPC64_ADDR14_BRTAKEN;
1242
case BFD_RELOC_PPC_BA16_BRNTAKEN: ppc_reloc = R_PPC64_ADDR14_BRNTAKEN;
1244
case BFD_RELOC_PPC_B26: ppc_reloc = R_PPC64_REL24;
1246
case BFD_RELOC_PPC_B16: ppc_reloc = R_PPC64_REL14;
1248
case BFD_RELOC_PPC_B16_BRTAKEN: ppc_reloc = R_PPC64_REL14_BRTAKEN;
1250
case BFD_RELOC_PPC_B16_BRNTAKEN: ppc_reloc = R_PPC64_REL14_BRNTAKEN;
1252
case BFD_RELOC_16_GOTOFF: ppc_reloc = R_PPC64_GOT16;
1254
case BFD_RELOC_LO16_GOTOFF: ppc_reloc = R_PPC64_GOT16_LO;
1256
case BFD_RELOC_HI16_GOTOFF: ppc_reloc = R_PPC64_GOT16_HI;
1258
case BFD_RELOC_HI16_S_GOTOFF: ppc_reloc = R_PPC64_GOT16_HA;
1260
case BFD_RELOC_PPC_COPY: ppc_reloc = R_PPC64_COPY;
1262
case BFD_RELOC_PPC_GLOB_DAT: ppc_reloc = R_PPC64_GLOB_DAT;
1264
case BFD_RELOC_32_PCREL: ppc_reloc = R_PPC64_REL32;
1266
case BFD_RELOC_32_PLTOFF: ppc_reloc = R_PPC64_PLT32;
1268
case BFD_RELOC_32_PLT_PCREL: ppc_reloc = R_PPC64_PLTREL32;
1270
case BFD_RELOC_LO16_PLTOFF: ppc_reloc = R_PPC64_PLT16_LO;
1272
case BFD_RELOC_HI16_PLTOFF: ppc_reloc = R_PPC64_PLT16_HI;
1274
case BFD_RELOC_HI16_S_PLTOFF: ppc_reloc = R_PPC64_PLT16_HA;
1276
case BFD_RELOC_16_BASEREL: ppc_reloc = R_PPC64_SECTOFF;
1278
case BFD_RELOC_LO16_BASEREL: ppc_reloc = R_PPC64_SECTOFF_LO;
1280
case BFD_RELOC_HI16_BASEREL: ppc_reloc = R_PPC64_SECTOFF_HI;
1282
case BFD_RELOC_HI16_S_BASEREL: ppc_reloc = R_PPC64_SECTOFF_HA;
1284
case BFD_RELOC_CTOR: ppc_reloc = R_PPC64_ADDR64;
1286
case BFD_RELOC_64: ppc_reloc = R_PPC64_ADDR64;
1288
case BFD_RELOC_PPC64_HIGHER: ppc_reloc = R_PPC64_ADDR16_HIGHER;
1290
case BFD_RELOC_PPC64_HIGHER_S: ppc_reloc = R_PPC64_ADDR16_HIGHERA;
1292
case BFD_RELOC_PPC64_HIGHEST: ppc_reloc = R_PPC64_ADDR16_HIGHEST;
1294
case BFD_RELOC_PPC64_HIGHEST_S: ppc_reloc = R_PPC64_ADDR16_HIGHESTA;
1296
case BFD_RELOC_64_PCREL: ppc_reloc = R_PPC64_REL64;
1298
case BFD_RELOC_64_PLTOFF: ppc_reloc = R_PPC64_PLT64;
1300
case BFD_RELOC_64_PLT_PCREL: ppc_reloc = R_PPC64_PLTREL64;
1302
case BFD_RELOC_PPC_TOC16: ppc_reloc = R_PPC64_TOC16;
1304
case BFD_RELOC_PPC64_TOC16_LO: ppc_reloc = R_PPC64_TOC16_LO;
1306
case BFD_RELOC_PPC64_TOC16_HI: ppc_reloc = R_PPC64_TOC16_HI;
1308
case BFD_RELOC_PPC64_TOC16_HA: ppc_reloc = R_PPC64_TOC16_HA;
1310
case BFD_RELOC_PPC64_TOC: ppc_reloc = R_PPC64_TOC;
1312
case BFD_RELOC_PPC64_PLTGOT16: ppc_reloc = R_PPC64_PLTGOT16;
1314
case BFD_RELOC_PPC64_PLTGOT16_LO: ppc_reloc = R_PPC64_PLTGOT16_LO;
1316
case BFD_RELOC_PPC64_PLTGOT16_HI: ppc_reloc = R_PPC64_PLTGOT16_HI;
1318
case BFD_RELOC_PPC64_PLTGOT16_HA: ppc_reloc = R_PPC64_PLTGOT16_HA;
1320
case BFD_RELOC_PPC64_ADDR16_DS: ppc_reloc = R_PPC64_ADDR16_DS;
1322
case BFD_RELOC_PPC64_ADDR16_LO_DS: ppc_reloc = R_PPC64_ADDR16_LO_DS;
1324
case BFD_RELOC_PPC64_GOT16_DS: ppc_reloc = R_PPC64_GOT16_DS;
1326
case BFD_RELOC_PPC64_GOT16_LO_DS: ppc_reloc = R_PPC64_GOT16_LO_DS;
1328
case BFD_RELOC_PPC64_PLT16_LO_DS: ppc_reloc = R_PPC64_PLT16_LO_DS;
1330
case BFD_RELOC_PPC64_SECTOFF_DS: ppc_reloc = R_PPC64_SECTOFF_DS;
1332
case BFD_RELOC_PPC64_SECTOFF_LO_DS: ppc_reloc = R_PPC64_SECTOFF_LO_DS;
1334
case BFD_RELOC_PPC64_TOC16_DS: ppc_reloc = R_PPC64_TOC16_DS;
1336
case BFD_RELOC_PPC64_TOC16_LO_DS: ppc_reloc = R_PPC64_TOC16_LO_DS;
1338
case BFD_RELOC_PPC64_PLTGOT16_DS: ppc_reloc = R_PPC64_PLTGOT16_DS;
1340
case BFD_RELOC_PPC64_PLTGOT16_LO_DS: ppc_reloc = R_PPC64_PLTGOT16_LO_DS;
1342
case BFD_RELOC_VTABLE_INHERIT: ppc_reloc = R_PPC64_GNU_VTINHERIT;
1344
case BFD_RELOC_VTABLE_ENTRY: ppc_reloc = R_PPC64_GNU_VTENTRY;
1348
return ppc64_elf_howto_table[(int) ppc_reloc];
1351
/* Set the howto pointer for a PowerPC ELF reloc. */
1354
ppc64_elf_info_to_howto (abfd, cache_ptr, dst)
1355
bfd *abfd ATTRIBUTE_UNUSED;
1357
Elf64_Internal_Rela *dst;
1361
/* Initialize howto table if needed. */
1362
if (!ppc64_elf_howto_table[R_PPC64_ADDR32])
1365
type = ELF64_R_TYPE (dst->r_info);
1366
BFD_ASSERT (type < (sizeof (ppc64_elf_howto_table)
1367
/ sizeof (ppc64_elf_howto_table[0])));
1368
cache_ptr->howto = ppc64_elf_howto_table[type];
1371
/* Handle the R_PPC_ADDR16_HA and similar relocs. */
1373
static bfd_reloc_status_type
1374
ppc64_elf_ha_reloc (abfd, reloc_entry, symbol, data,
1375
input_section, output_bfd, error_message)
1377
arelent *reloc_entry;
1380
asection *input_section;
1382
char **error_message;
1384
/* If this is a relocatable link (output_bfd test tells us), just
1385
call the generic function. Any adjustment will be done at final
1387
if (output_bfd != NULL)
1388
return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
1389
input_section, output_bfd, error_message);
1391
/* Adjust the addend for sign extension of the low 16 bits.
1392
We won't actually be using the low 16 bits, so trashing them
1394
reloc_entry->addend += 0x8000;
1395
return bfd_reloc_continue;
1398
static bfd_reloc_status_type
1399
ppc64_elf_brtaken_reloc (abfd, reloc_entry, symbol, data,
1400
input_section, output_bfd, error_message)
1402
arelent *reloc_entry;
1405
asection *input_section;
1407
char **error_message;
1410
enum elf_ppc_reloc_type r_type;
1411
bfd_size_type octets;
1412
/* Disabled until we sort out how ld should choose 'y' vs 'at'. */
1413
boolean is_power4 = false;
1415
/* If this is a relocatable link (output_bfd test tells us), just
1416
call the generic function. Any adjustment will be done at final
1418
if (output_bfd != NULL)
1419
return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
1420
input_section, output_bfd, error_message);
1422
octets = reloc_entry->address * bfd_octets_per_byte (abfd);
1423
insn = bfd_get_32 (abfd, (bfd_byte *) data + octets);
1424
insn &= ~(0x01 << 21);
1425
r_type = (enum elf_ppc_reloc_type) reloc_entry->howto->type;
1426
if (r_type == R_PPC64_ADDR14_BRTAKEN
1427
|| r_type == R_PPC64_REL14_BRTAKEN)
1428
insn |= 0x01 << 21; /* 'y' or 't' bit, lowest bit of BO field. */
1432
/* Set 'a' bit. This is 0b00010 in BO field for branch
1433
on CR(BI) insns (BO == 001at or 011at), and 0b01000
1434
for branch on CTR insns (BO == 1a00t or 1a01t). */
1435
if ((insn & (0x14 << 21)) == (0x04 << 21))
1437
else if ((insn & (0x14 << 21)) == (0x10 << 21))
1440
return bfd_reloc_continue;
1447
if (!bfd_is_com_section (symbol->section))
1448
target = symbol->value;
1449
target += symbol->section->output_section->vma;
1450
target += symbol->section->output_offset;
1451
target += reloc_entry->addend;
1453
from = (reloc_entry->address
1454
+ input_section->output_offset
1455
+ input_section->output_section->vma);
1457
/* Invert 'y' bit if not the default. */
1458
if ((bfd_signed_vma) (target - from) < 0)
1461
bfd_put_32 (abfd, (bfd_vma) insn, (bfd_byte *) data + octets);
1462
return bfd_reloc_continue;
1465
static bfd_reloc_status_type
1466
ppc64_elf_sectoff_reloc (abfd, reloc_entry, symbol, data,
1467
input_section, output_bfd, error_message)
1469
arelent *reloc_entry;
1472
asection *input_section;
1474
char **error_message;
1476
/* If this is a relocatable link (output_bfd test tells us), just
1477
call the generic function. Any adjustment will be done at final
1479
if (output_bfd != NULL)
1480
return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
1481
input_section, output_bfd, error_message);
1483
/* Subtract the symbol section base address. */
1484
reloc_entry->addend -= symbol->section->output_section->vma;
1485
return bfd_reloc_continue;
1488
static bfd_reloc_status_type
1489
ppc64_elf_sectoff_ha_reloc (abfd, reloc_entry, symbol, data,
1490
input_section, output_bfd, error_message)
1492
arelent *reloc_entry;
1495
asection *input_section;
1497
char **error_message;
1499
/* If this is a relocatable link (output_bfd test tells us), just
1500
call the generic function. Any adjustment will be done at final
1502
if (output_bfd != NULL)
1503
return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
1504
input_section, output_bfd, error_message);
1506
/* Subtract the symbol section base address. */
1507
reloc_entry->addend -= symbol->section->output_section->vma;
1509
/* Adjust the addend for sign extension of the low 16 bits. */
1510
reloc_entry->addend += 0x8000;
1511
return bfd_reloc_continue;
1514
static bfd_reloc_status_type
1515
ppc64_elf_toc_reloc (abfd, reloc_entry, symbol, data,
1516
input_section, output_bfd, error_message)
1518
arelent *reloc_entry;
1521
asection *input_section;
1523
char **error_message;
1527
/* If this is a relocatable link (output_bfd test tells us), just
1528
call the generic function. Any adjustment will be done at final
1530
if (output_bfd != NULL)
1531
return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
1532
input_section, output_bfd, error_message);
1534
TOCstart = _bfd_get_gp_value (input_section->output_section->owner);
1536
TOCstart = ppc64_elf_toc (input_section->output_section->owner);
1538
/* Subtract the TOC base address. */
1539
reloc_entry->addend -= TOCstart + TOC_BASE_OFF;
1540
return bfd_reloc_continue;
1543
static bfd_reloc_status_type
1544
ppc64_elf_toc_ha_reloc (abfd, reloc_entry, symbol, data,
1545
input_section, output_bfd, error_message)
1547
arelent *reloc_entry;
1550
asection *input_section;
1552
char **error_message;
1556
/* If this is a relocatable link (output_bfd test tells us), just
1557
call the generic function. Any adjustment will be done at final
1559
if (output_bfd != NULL)
1560
return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
1561
input_section, output_bfd, error_message);
1563
TOCstart = _bfd_get_gp_value (input_section->output_section->owner);
1565
TOCstart = ppc64_elf_toc (input_section->output_section->owner);
1567
/* Subtract the TOC base address. */
1568
reloc_entry->addend -= TOCstart + TOC_BASE_OFF;
1570
/* Adjust the addend for sign extension of the low 16 bits. */
1571
reloc_entry->addend += 0x8000;
1572
return bfd_reloc_continue;
1575
static bfd_reloc_status_type
1576
ppc64_elf_toc64_reloc (abfd, reloc_entry, symbol, data,
1577
input_section, output_bfd, error_message)
1579
arelent *reloc_entry;
1582
asection *input_section;
1584
char **error_message;
1587
bfd_size_type octets;
1589
/* If this is a relocatable link (output_bfd test tells us), just
1590
call the generic function. Any adjustment will be done at final
1592
if (output_bfd != NULL)
1593
return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
1594
input_section, output_bfd, error_message);
1596
TOCstart = _bfd_get_gp_value (input_section->output_section->owner);
1598
TOCstart = ppc64_elf_toc (input_section->output_section->owner);
1600
octets = reloc_entry->address * bfd_octets_per_byte (abfd);
1601
bfd_put_64 (abfd, TOCstart + TOC_BASE_OFF, (bfd_byte *) data + octets);
1602
return bfd_reloc_ok;
1605
static bfd_reloc_status_type
1606
ppc64_elf_unhandled_reloc (abfd, reloc_entry, symbol, data,
1607
input_section, output_bfd, error_message)
1609
arelent *reloc_entry;
1612
asection *input_section;
1614
char **error_message;
1616
/* If this is a relocatable link (output_bfd test tells us), just
1617
call the generic function. Any adjustment will be done at final
1619
if (output_bfd != NULL)
1620
return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
1621
input_section, output_bfd, error_message);
1623
if (error_message != NULL)
1625
static char buf[60];
1626
sprintf (buf, "generic linker can't handle %s",
1627
reloc_entry->howto->name);
1628
*error_message = buf;
1630
return bfd_reloc_dangerous;
1633
/* Fix bad default arch selected for a 64 bit input bfd when the
1634
default is 32 bit. */
1637
ppc64_elf_object_p (abfd)
1640
if (abfd->arch_info->the_default && abfd->arch_info->bits_per_word == 32)
1642
Elf_Internal_Ehdr *i_ehdr = elf_elfheader (abfd);
1644
if (i_ehdr->e_ident[EI_CLASS] == ELFCLASS64)
1646
/* Relies on arch after 32 bit default being 64 bit default. */
1647
abfd->arch_info = abfd->arch_info->next;
1648
BFD_ASSERT (abfd->arch_info->bits_per_word == 64);
1654
/* Merge backend specific data from an object file to the output
1655
object file when linking. */
1658
ppc64_elf_merge_private_bfd_data (ibfd, obfd)
1662
/* Check if we have the same endianess. */
1663
if (ibfd->xvec->byteorder != obfd->xvec->byteorder
1664
&& obfd->xvec->byteorder != BFD_ENDIAN_UNKNOWN)
1668
if (bfd_big_endian (ibfd))
1669
msg = _("%s: compiled for a big endian system and target is little endian");
1671
msg = _("%s: compiled for a little endian system and target is big endian");
1673
(*_bfd_error_handler) (msg, bfd_archive_filename (ibfd));
1675
bfd_set_error (bfd_error_wrong_format);
1682
/* The following functions are specific to the ELF linker, while
1683
functions above are used generally. Those named ppc64_elf_* are
1684
called by the main ELF linker code. They appear in this file more
1685
or less in the order in which they are called. eg.
1686
ppc64_elf_check_relocs is called early in the link process,
1687
ppc64_elf_finish_dynamic_sections is one of the last functions
1690
PowerPC64-ELF uses a similar scheme to PowerPC64-XCOFF in that
1691
functions have both a function code symbol and a function descriptor
1692
symbol. A call to foo in a relocatable object file looks like:
1699
The function definition in another object file might be:
1703
. .quad .TOC.@tocbase
1709
When the linker resolves the call during a static link, the branch
1710
unsurprisingly just goes to .foo and the .opd information is unused.
1711
If the function definition is in a shared library, things are a little
1712
different: The call goes via a plt call stub, the opd information gets
1713
copied to the plt, and the linker patches the nop.
1721
. addis 12,2,Lfoo@toc@ha # in practice, the call stub
1722
. addi 12,12,Lfoo@toc@l # is slightly optimised, but
1723
. std 2,40(1) # this is the general idea
1731
. Lfoo: reloc (R_PPC64_JMP_SLOT, foo)
1733
The "reloc ()" notation is supposed to indicate that the linker emits
1734
an R_PPC64_JMP_SLOT reloc against foo. The dynamic linker does the opd
1737
What are the difficulties here? Well, firstly, the relocations
1738
examined by the linker in check_relocs are against the function code
1739
sym .foo, while the dynamic relocation in the plt is emitted against
1740
the function descriptor symbol, foo. Somewhere along the line, we need
1741
to carefully copy dynamic link information from one symbol to the other.
1742
Secondly, the generic part of the elf linker will make .foo a dynamic
1743
symbol as is normal for most other backends. We need foo dynamic
1744
instead, at least for an application final link. However, when
1745
creating a shared library containing foo, we need to have both symbols
1746
dynamic so that references to .foo are satisfied during the early
1747
stages of linking. Otherwise the linker might decide to pull in a
1748
definition from some other object, eg. a static library. */
1750
/* The linker needs to keep track of the number of relocs that it
1751
decides to copy as dynamic relocs in check_relocs for each symbol.
1752
This is so that it can later discard them if they are found to be
1753
unnecessary. We store the information in a field extending the
1754
regular ELF linker hash table. */
1756
struct ppc_dyn_relocs
1758
struct ppc_dyn_relocs *next;
1760
/* The input section of the reloc. */
1763
/* Total number of relocs copied for the input section. */
1764
bfd_size_type count;
1766
/* Number of pc-relative relocs copied for the input section. */
1767
bfd_size_type pc_count;
1770
/* Of those relocs that might be copied as dynamic relocs, this macro
1771
selects between relative and absolute types. */
1773
#define IS_ABSOLUTE_RELOC(RTYPE) \
1774
((RTYPE) != R_PPC64_REL32 \
1775
&& (RTYPE) != R_PPC64_REL64 \
1776
&& (RTYPE) != R_PPC64_ADDR30)
1778
/* Section name for stubs is the associated section name plus this
1780
#define STUB_SUFFIX ".stub"
1783
ppc_stub_long_branch:
1784
Used when a 14 bit branch (or even a 24 bit branch) can't reach its
1785
destination, but a 24 bit branch in a stub section will reach.
1788
ppc_stub_plt_branch:
1789
Similar to the above, but a 24 bit branch in the stub section won't
1790
reach its destination.
1791
. addis %r12,%r2,xxx@ha
1792
. ld %r11,xxx@l(%r12)
1797
Used to call a function in a shared library.
1798
. addis %r12,%r2,xxx@ha
1800
. ld %r11,xxx+0@l(%r12)
1801
. ld %r2,xxx+8@l(%r12)
1803
. ld %r11,xxx+16@l(%r12)
1807
enum ppc_stub_type {
1809
ppc_stub_long_branch,
1810
ppc_stub_plt_branch,
1814
struct ppc_stub_hash_entry {
1816
/* Base hash table entry structure. */
1817
struct bfd_hash_entry root;
1819
/* The stub section. */
1822
/* Offset within stub_sec of the beginning of this stub. */
1823
bfd_vma stub_offset;
1825
/* Given the symbol's value and its section we can determine its final
1826
value when building the stubs (so the stub knows where to jump. */
1827
bfd_vma target_value;
1828
asection *target_section;
1830
enum ppc_stub_type stub_type;
1832
/* The symbol table entry, if any, that this was derived from. */
1833
struct ppc_link_hash_entry *h;
1835
/* Where this stub is being called from, or, in the case of combined
1836
stub sections, the first input section in the group. */
1840
struct ppc_branch_hash_entry {
1842
/* Base hash table entry structure. */
1843
struct bfd_hash_entry root;
1845
/* Offset within .branch_lt. */
1846
unsigned int offset;
1848
/* Generation marker. */
1852
struct ppc_link_hash_entry
1854
struct elf_link_hash_entry elf;
1856
/* A pointer to the most recently used stub hash entry against this
1858
struct ppc_stub_hash_entry *stub_cache;
1860
/* Track dynamic relocs copied for this symbol. */
1861
struct ppc_dyn_relocs *dyn_relocs;
1863
/* Link between function code and descriptor symbols. */
1864
struct elf_link_hash_entry *oh;
1866
/* Flag function code and descriptor symbols. */
1867
unsigned int is_func:1;
1868
unsigned int is_func_descriptor:1;
1869
unsigned int is_entry:1;
1872
/* ppc64 ELF linker hash table. */
1874
struct ppc_link_hash_table
1876
struct elf_link_hash_table elf;
1878
/* The stub hash table. */
1879
struct bfd_hash_table stub_hash_table;
1881
/* Another hash table for plt_branch stubs. */
1882
struct bfd_hash_table branch_hash_table;
1884
/* Linker stub bfd. */
1887
/* Linker call-backs. */
1888
asection * (*add_stub_section) PARAMS ((const char *, asection *));
1889
void (*layout_sections_again) PARAMS ((void));
1891
/* Array to keep track of which stub sections have been created, and
1892
information on stub grouping. */
1894
/* This is the section to which stubs in the group will be attached. */
1896
/* The stub section. */
1900
/* Assorted information used by ppc64_elf_size_stubs. */
1902
asection **input_list;
1904
/* Short-cuts to get to dynamic linker sections. */
1917
unsigned int stub_error;
1919
/* Flag set when small branches are detected. Used to
1920
select suitable defaults for the stub group size. */
1921
unsigned int has_14bit_branch;
1923
/* Set if we detect a reference undefined weak symbol. */
1924
unsigned int have_undefweak;
1926
/* Incremented every time we size stubs. */
1927
unsigned int stub_iteration;
1929
/* Small local sym to section mapping cache. */
1930
struct sym_sec_cache sym_sec;
1933
static struct bfd_hash_entry *stub_hash_newfunc
1934
PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *));
1935
static struct bfd_hash_entry *branch_hash_newfunc
1936
PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *));
1937
static struct bfd_hash_entry *link_hash_newfunc
1938
PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *));
1939
static struct bfd_link_hash_table *ppc64_elf_link_hash_table_create
1941
static void ppc64_elf_link_hash_table_free
1942
PARAMS ((struct bfd_link_hash_table *));
1943
static char *ppc_stub_name
1944
PARAMS ((const asection *, const asection *,
1945
const struct ppc_link_hash_entry *, const Elf_Internal_Rela *));
1946
static struct ppc_stub_hash_entry *ppc_get_stub_entry
1947
PARAMS ((const asection *, const asection *, struct elf_link_hash_entry *,
1948
const Elf_Internal_Rela *, struct ppc_link_hash_table *));
1949
static struct ppc_stub_hash_entry *ppc_add_stub
1950
PARAMS ((const char *, asection *, struct ppc_link_hash_table *));
1951
static boolean create_linkage_sections
1952
PARAMS ((bfd *, struct bfd_link_info *));
1953
static boolean create_got_section
1954
PARAMS ((bfd *, struct bfd_link_info *));
1955
static boolean ppc64_elf_create_dynamic_sections
1956
PARAMS ((bfd *, struct bfd_link_info *));
1957
static void ppc64_elf_copy_indirect_symbol
1958
PARAMS ((struct elf_link_hash_entry *, struct elf_link_hash_entry *));
1959
static boolean ppc64_elf_check_relocs
1960
PARAMS ((bfd *, struct bfd_link_info *, asection *,
1961
const Elf_Internal_Rela *));
1962
static asection * ppc64_elf_gc_mark_hook
1963
PARAMS ((asection *, struct bfd_link_info *, Elf_Internal_Rela *,
1964
struct elf_link_hash_entry *, Elf_Internal_Sym *));
1965
static boolean ppc64_elf_gc_sweep_hook
1966
PARAMS ((bfd *, struct bfd_link_info *, asection *,
1967
const Elf_Internal_Rela *));
1968
static boolean func_desc_adjust
1969
PARAMS ((struct elf_link_hash_entry *, PTR));
1970
static boolean ppc64_elf_func_desc_adjust
1971
PARAMS ((bfd *, struct bfd_link_info *));
1972
static boolean ppc64_elf_adjust_dynamic_symbol
1973
PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *));
1974
static void ppc64_elf_hide_symbol
1975
PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *, boolean));
1976
static boolean edit_opd
1977
PARAMS ((bfd *, struct bfd_link_info *));
1978
static boolean allocate_dynrelocs
1979
PARAMS ((struct elf_link_hash_entry *, PTR));
1980
static boolean readonly_dynrelocs
1981
PARAMS ((struct elf_link_hash_entry *, PTR));
1982
static enum elf_reloc_type_class ppc64_elf_reloc_type_class
1983
PARAMS ((const Elf_Internal_Rela *));
1984
static boolean ppc64_elf_size_dynamic_sections
1985
PARAMS ((bfd *, struct bfd_link_info *));
1986
static INLINE enum ppc_stub_type ppc_type_of_stub
1987
PARAMS ((asection *, const Elf_Internal_Rela *,
1988
struct ppc_link_hash_entry **, bfd_vma));
1989
static bfd_byte *build_plt_stub
1990
PARAMS ((bfd *, bfd_byte *, int, int));
1991
static boolean ppc_build_one_stub
1992
PARAMS ((struct bfd_hash_entry *, PTR));
1993
static boolean ppc_size_one_stub
1994
PARAMS ((struct bfd_hash_entry *, PTR));
1995
static void group_sections
1996
PARAMS ((struct ppc_link_hash_table *, bfd_size_type, boolean));
1997
static boolean ppc64_elf_relocate_section
1998
PARAMS ((bfd *, struct bfd_link_info *info, bfd *, asection *, bfd_byte *,
1999
Elf_Internal_Rela *relocs, Elf_Internal_Sym *local_syms,
2001
static boolean ppc64_elf_finish_dynamic_symbol
2002
PARAMS ((bfd *, struct bfd_link_info *, struct elf_link_hash_entry *,
2003
Elf_Internal_Sym *));
2004
static boolean ppc64_elf_finish_dynamic_sections
2005
PARAMS ((bfd *, struct bfd_link_info *));
2007
/* Get the ppc64 ELF linker hash table from a link_info structure. */
2009
#define ppc_hash_table(p) \
2010
((struct ppc_link_hash_table *) ((p)->hash))
2012
#define ppc_stub_hash_lookup(table, string, create, copy) \
2013
((struct ppc_stub_hash_entry *) \
2014
bfd_hash_lookup ((table), (string), (create), (copy)))
2016
#define ppc_branch_hash_lookup(table, string, create, copy) \
2017
((struct ppc_branch_hash_entry *) \
2018
bfd_hash_lookup ((table), (string), (create), (copy)))
2020
/* Create an entry in the stub hash table. */
2022
static struct bfd_hash_entry *
2023
stub_hash_newfunc (entry, table, string)
2024
struct bfd_hash_entry *entry;
2025
struct bfd_hash_table *table;
2028
/* Allocate the structure if it has not already been allocated by a
2032
entry = bfd_hash_allocate (table, sizeof (struct ppc_stub_hash_entry));
2037
/* Call the allocation method of the superclass. */
2038
entry = bfd_hash_newfunc (entry, table, string);
2041
struct ppc_stub_hash_entry *eh;
2043
/* Initialize the local fields. */
2044
eh = (struct ppc_stub_hash_entry *) entry;
2045
eh->stub_sec = NULL;
2046
eh->stub_offset = 0;
2047
eh->target_value = 0;
2048
eh->target_section = NULL;
2049
eh->stub_type = ppc_stub_none;
2057
/* Create an entry in the branch hash table. */
2059
static struct bfd_hash_entry *
2060
branch_hash_newfunc (entry, table, string)
2061
struct bfd_hash_entry *entry;
2062
struct bfd_hash_table *table;
2065
/* Allocate the structure if it has not already been allocated by a
2069
entry = bfd_hash_allocate (table, sizeof (struct ppc_branch_hash_entry));
2074
/* Call the allocation method of the superclass. */
2075
entry = bfd_hash_newfunc (entry, table, string);
2078
struct ppc_branch_hash_entry *eh;
2080
/* Initialize the local fields. */
2081
eh = (struct ppc_branch_hash_entry *) entry;
2089
/* Create an entry in a ppc64 ELF linker hash table. */
2091
static struct bfd_hash_entry *
2092
link_hash_newfunc (entry, table, string)
2093
struct bfd_hash_entry *entry;
2094
struct bfd_hash_table *table;
2097
/* Allocate the structure if it has not already been allocated by a
2101
entry = bfd_hash_allocate (table, sizeof (struct ppc_link_hash_entry));
2106
/* Call the allocation method of the superclass. */
2107
entry = _bfd_elf_link_hash_newfunc (entry, table, string);
2110
struct ppc_link_hash_entry *eh = (struct ppc_link_hash_entry *) entry;
2112
eh->stub_cache = NULL;
2113
eh->dyn_relocs = NULL;
2116
eh->is_func_descriptor = 0;
2123
/* Create a ppc64 ELF linker hash table. */
2125
static struct bfd_link_hash_table *
2126
ppc64_elf_link_hash_table_create (abfd)
2129
struct ppc_link_hash_table *htab;
2130
bfd_size_type amt = sizeof (struct ppc_link_hash_table);
2132
htab = (struct ppc_link_hash_table *) bfd_malloc (amt);
2136
if (! _bfd_elf_link_hash_table_init (&htab->elf, abfd, link_hash_newfunc))
2142
/* Init the stub hash table too. */
2143
if (!bfd_hash_table_init (&htab->stub_hash_table, stub_hash_newfunc))
2146
/* And the branch hash table. */
2147
if (!bfd_hash_table_init (&htab->branch_hash_table, branch_hash_newfunc))
2150
htab->stub_bfd = NULL;
2151
htab->add_stub_section = NULL;
2152
htab->layout_sections_again = NULL;
2153
htab->stub_group = NULL;
2155
htab->srelgot = NULL;
2157
htab->srelplt = NULL;
2158
htab->sdynbss = NULL;
2159
htab->srelbss = NULL;
2160
htab->sglink = NULL;
2163
htab->srelbrlt = NULL;
2164
htab->stub_error = 0;
2165
htab->has_14bit_branch = 0;
2166
htab->have_undefweak = 0;
2167
htab->stub_iteration = 0;
2168
htab->sym_sec.abfd = NULL;
2170
return &htab->elf.root;
2173
/* Free the derived linker hash table. */
2176
ppc64_elf_link_hash_table_free (hash)
2177
struct bfd_link_hash_table *hash;
2179
struct ppc_link_hash_table *ret = (struct ppc_link_hash_table *) hash;
2181
bfd_hash_table_free (&ret->stub_hash_table);
2182
bfd_hash_table_free (&ret->branch_hash_table);
2183
_bfd_generic_link_hash_table_free (hash);
2186
/* Build a name for an entry in the stub hash table. */
2189
ppc_stub_name (input_section, sym_sec, h, rel)
2190
const asection *input_section;
2191
const asection *sym_sec;
2192
const struct ppc_link_hash_entry *h;
2193
const Elf_Internal_Rela *rel;
2198
/* rel->r_addend is actually 64 bit, but who uses more than +/- 2^31
2199
offsets from a sym as a branch target? In fact, we could
2200
probably assume the addend is always zero. */
2201
BFD_ASSERT (((int) rel->r_addend & 0xffffffff) == rel->r_addend);
2205
len = 8 + 1 + strlen (h->elf.root.root.string) + 1 + 8 + 1;
2206
stub_name = bfd_malloc (len);
2207
if (stub_name != NULL)
2209
sprintf (stub_name, "%08x_%s+%x",
2210
input_section->id & 0xffffffff,
2211
h->elf.root.root.string,
2212
(int) rel->r_addend & 0xffffffff);
2217
len = 8 + 1 + 8 + 1 + 8 + 1 + 16 + 1;
2218
stub_name = bfd_malloc (len);
2219
if (stub_name != NULL)
2221
sprintf (stub_name, "%08x_%x:%x+%x",
2222
input_section->id & 0xffffffff,
2223
sym_sec->id & 0xffffffff,
2224
(int) ELF64_R_SYM (rel->r_info) & 0xffffffff,
2225
(int) rel->r_addend & 0xffffffff);
2231
/* Look up an entry in the stub hash. Stub entries are cached because
2232
creating the stub name takes a bit of time. */
2234
static struct ppc_stub_hash_entry *
2235
ppc_get_stub_entry (input_section, sym_sec, hash, rel, htab)
2236
const asection *input_section;
2237
const asection *sym_sec;
2238
struct elf_link_hash_entry *hash;
2239
const Elf_Internal_Rela *rel;
2240
struct ppc_link_hash_table *htab;
2242
struct ppc_stub_hash_entry *stub_entry;
2243
struct ppc_link_hash_entry *h = (struct ppc_link_hash_entry *) hash;
2244
const asection *id_sec;
2246
/* If this input section is part of a group of sections sharing one
2247
stub section, then use the id of the first section in the group.
2248
Stub names need to include a section id, as there may well be
2249
more than one stub used to reach say, printf, and we need to
2250
distinguish between them. */
2251
id_sec = htab->stub_group[input_section->id].link_sec;
2253
if (h != NULL && h->stub_cache != NULL
2254
&& h->stub_cache->h == h
2255
&& h->stub_cache->id_sec == id_sec)
2257
stub_entry = h->stub_cache;
2263
stub_name = ppc_stub_name (id_sec, sym_sec, h, rel);
2264
if (stub_name == NULL)
2267
stub_entry = ppc_stub_hash_lookup (&htab->stub_hash_table,
2268
stub_name, false, false);
2270
h->stub_cache = stub_entry;
2278
/* Add a new stub entry to the stub hash. Not all fields of the new
2279
stub entry are initialised. */
2281
static struct ppc_stub_hash_entry *
2282
ppc_add_stub (stub_name, section, htab)
2283
const char *stub_name;
2285
struct ppc_link_hash_table *htab;
2289
struct ppc_stub_hash_entry *stub_entry;
2291
link_sec = htab->stub_group[section->id].link_sec;
2292
stub_sec = htab->stub_group[section->id].stub_sec;
2293
if (stub_sec == NULL)
2295
stub_sec = htab->stub_group[link_sec->id].stub_sec;
2296
if (stub_sec == NULL)
2302
namelen = strlen (link_sec->name);
2303
len = namelen + sizeof (STUB_SUFFIX);
2304
s_name = bfd_alloc (htab->stub_bfd, len);
2308
memcpy (s_name, link_sec->name, namelen);
2309
memcpy (s_name + namelen, STUB_SUFFIX, sizeof (STUB_SUFFIX));
2310
stub_sec = (*htab->add_stub_section) (s_name, link_sec);
2311
if (stub_sec == NULL)
2313
htab->stub_group[link_sec->id].stub_sec = stub_sec;
2315
htab->stub_group[section->id].stub_sec = stub_sec;
2318
/* Enter this entry into the linker stub hash table. */
2319
stub_entry = ppc_stub_hash_lookup (&htab->stub_hash_table, stub_name,
2321
if (stub_entry == NULL)
2323
(*_bfd_error_handler) (_("%s: cannot create stub entry %s"),
2324
bfd_archive_filename (section->owner),
2329
stub_entry->stub_sec = stub_sec;
2330
stub_entry->stub_offset = 0;
2331
stub_entry->id_sec = link_sec;
2335
/* Create sections for linker generated code. */
2338
create_linkage_sections (dynobj, info)
2340
struct bfd_link_info *info;
2342
struct ppc_link_hash_table *htab;
2345
htab = ppc_hash_table (info);
2347
/* Create .sfpr for code to save and restore fp regs. */
2348
flags = (SEC_ALLOC | SEC_LOAD | SEC_CODE | SEC_READONLY
2349
| SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED);
2350
htab->sfpr = bfd_make_section_anyway (dynobj, ".sfpr");
2351
if (htab->sfpr == NULL
2352
|| ! bfd_set_section_flags (dynobj, htab->sfpr, flags)
2353
|| ! bfd_set_section_alignment (dynobj, htab->sfpr, 2))
2356
/* Create .glink for lazy dynamic linking support. */
2357
htab->sglink = bfd_make_section_anyway (dynobj, ".glink");
2358
if (htab->sglink == NULL
2359
|| ! bfd_set_section_flags (dynobj, htab->sglink, flags)
2360
|| ! bfd_set_section_alignment (dynobj, htab->sglink, 2))
2363
/* Create .branch_lt for plt_branch stubs. */
2364
flags = (SEC_ALLOC | SEC_LOAD
2365
| SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED);
2366
htab->sbrlt = bfd_make_section_anyway (dynobj, ".branch_lt");
2367
if (htab->sbrlt == NULL
2368
|| ! bfd_set_section_flags (dynobj, htab->sbrlt, flags)
2369
|| ! bfd_set_section_alignment (dynobj, htab->sbrlt, 3))
2374
flags = (SEC_ALLOC | SEC_LOAD | SEC_READONLY
2375
| SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED);
2376
htab->srelbrlt = bfd_make_section_anyway (dynobj, ".rela.branch_lt");
2378
|| ! bfd_set_section_flags (dynobj, htab->srelbrlt, flags)
2379
|| ! bfd_set_section_alignment (dynobj, htab->srelbrlt, 3))
2385
/* Create .got and .rela.got sections in DYNOBJ, and set up
2386
shortcuts to them in our hash table. */
2389
create_got_section (dynobj, info)
2391
struct bfd_link_info *info;
2393
struct ppc_link_hash_table *htab;
2395
if (! _bfd_elf_create_got_section (dynobj, info))
2398
htab = ppc_hash_table (info);
2399
htab->sgot = bfd_get_section_by_name (dynobj, ".got");
2403
htab->srelgot = bfd_make_section (dynobj, ".rela.got");
2405
|| ! bfd_set_section_flags (dynobj, htab->srelgot,
2406
(SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS
2407
| SEC_IN_MEMORY | SEC_LINKER_CREATED
2409
|| ! bfd_set_section_alignment (dynobj, htab->srelgot, 3))
2414
/* Create the dynamic sections, and set up shortcuts. */
2417
ppc64_elf_create_dynamic_sections (dynobj, info)
2419
struct bfd_link_info *info;
2421
struct ppc_link_hash_table *htab;
2423
htab = ppc_hash_table (info);
2424
if (!htab->sgot && !create_got_section (dynobj, info))
2427
if (!_bfd_elf_create_dynamic_sections (dynobj, info))
2430
htab->splt = bfd_get_section_by_name (dynobj, ".plt");
2431
htab->srelplt = bfd_get_section_by_name (dynobj, ".rela.plt");
2432
htab->sdynbss = bfd_get_section_by_name (dynobj, ".dynbss");
2434
htab->srelbss = bfd_get_section_by_name (dynobj, ".rela.bss");
2436
if (!htab->splt || !htab->srelplt || !htab->sdynbss
2437
|| (!info->shared && !htab->srelbss))
2443
/* Copy the extra info we tack onto an elf_link_hash_entry. */
2446
ppc64_elf_copy_indirect_symbol (dir, ind)
2447
struct elf_link_hash_entry *dir, *ind;
2449
struct ppc_link_hash_entry *edir, *eind;
2451
edir = (struct ppc_link_hash_entry *) dir;
2452
eind = (struct ppc_link_hash_entry *) ind;
2454
if (eind->dyn_relocs != NULL)
2456
if (edir->dyn_relocs != NULL)
2458
struct ppc_dyn_relocs **pp;
2459
struct ppc_dyn_relocs *p;
2461
if (ind->root.type == bfd_link_hash_indirect)
2464
/* Add reloc counts against the weak sym to the strong sym
2465
list. Merge any entries against the same section. */
2466
for (pp = &eind->dyn_relocs; (p = *pp) != NULL; )
2468
struct ppc_dyn_relocs *q;
2470
for (q = edir->dyn_relocs; q != NULL; q = q->next)
2471
if (q->sec == p->sec)
2473
q->pc_count += p->pc_count;
2474
q->count += p->count;
2481
*pp = edir->dyn_relocs;
2484
edir->dyn_relocs = eind->dyn_relocs;
2485
eind->dyn_relocs = NULL;
2488
edir->is_func |= eind->is_func;
2489
edir->is_func_descriptor |= eind->is_func_descriptor;
2490
edir->is_entry |= eind->is_entry;
2492
_bfd_elf_link_hash_copy_indirect (dir, ind);
2495
/* Set a flag, used by ppc64_elf_gc_mark_hook, on the entry symbol and
2496
symbols undefined on the command-line. */
2499
ppc64_elf_mark_entry_syms (info)
2500
struct bfd_link_info *info;
2502
struct ppc_link_hash_table *htab;
2503
struct bfd_sym_chain *sym;
2505
htab = ppc_hash_table (info);
2506
for (sym = info->gc_sym_list; sym; sym = sym->next)
2508
struct elf_link_hash_entry *h;
2510
h = elf_link_hash_lookup (&htab->elf, sym->name, false, false, false);
2512
((struct ppc_link_hash_entry *) h)->is_entry = 1;
2517
/* Look through the relocs for a section during the first phase, and
2518
calculate needed space in the global offset table, procedure
2519
linkage table, and dynamic reloc sections. */
2522
ppc64_elf_check_relocs (abfd, info, sec, relocs)
2524
struct bfd_link_info *info;
2526
const Elf_Internal_Rela *relocs;
2528
struct ppc_link_hash_table *htab;
2529
Elf_Internal_Shdr *symtab_hdr;
2530
struct elf_link_hash_entry **sym_hashes, **sym_hashes_end;
2531
const Elf_Internal_Rela *rel;
2532
const Elf_Internal_Rela *rel_end;
2534
asection **opd_sym_map;
2536
if (info->relocateable)
2539
htab = ppc_hash_table (info);
2540
symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
2542
sym_hashes = elf_sym_hashes (abfd);
2543
sym_hashes_end = (sym_hashes
2544
+ symtab_hdr->sh_size / sizeof (Elf64_External_Sym)
2545
- symtab_hdr->sh_info);
2549
if (strcmp (bfd_get_section_name (abfd, sec), ".opd") == 0)
2551
/* Garbage collection needs some extra help with .opd sections.
2552
We don't want to necessarily keep everything referenced by
2553
relocs in .opd, as that would keep all functions. Instead,
2554
if we reference an .opd symbol (a function descriptor), we
2555
want to keep the function code symbol's section. This is
2556
easy for global symbols, but for local syms we need to keep
2557
information about the associated function section. Later, if
2558
edit_opd deletes entries, we'll use this array to adjust
2559
local syms in .opd. */
2561
asection *func_section;
2566
amt = sec->_raw_size * sizeof (union opd_info) / 24;
2567
opd_sym_map = (asection **) bfd_zalloc (abfd, amt);
2568
if (opd_sym_map == NULL)
2570
elf_section_data (sec)->tdata = opd_sym_map;
2573
if (htab->elf.dynobj == NULL)
2574
htab->elf.dynobj = abfd;
2575
if (htab->sfpr == NULL
2576
&& !create_linkage_sections (htab->elf.dynobj, info))
2579
rel_end = relocs + sec->reloc_count;
2580
for (rel = relocs; rel < rel_end; rel++)
2582
unsigned long r_symndx;
2583
struct elf_link_hash_entry *h;
2584
enum elf_ppc_reloc_type r_type;
2586
r_symndx = ELF64_R_SYM (rel->r_info);
2587
if (r_symndx < symtab_hdr->sh_info)
2590
h = sym_hashes[r_symndx - symtab_hdr->sh_info];
2592
r_type = (enum elf_ppc_reloc_type) ELF64_R_TYPE (rel->r_info);
2595
/* GOT16 relocations */
2597
case R_PPC64_GOT16_DS:
2598
case R_PPC64_GOT16_HA:
2599
case R_PPC64_GOT16_HI:
2600
case R_PPC64_GOT16_LO:
2601
case R_PPC64_GOT16_LO_DS:
2603
/* This symbol requires a global offset table entry. */
2604
if (htab->sgot == NULL
2605
&& !create_got_section (htab->elf.dynobj, info))
2610
h->got.refcount += 1;
2614
bfd_signed_vma *local_got_refcounts;
2616
/* This is a global offset table entry for a local symbol. */
2617
local_got_refcounts = elf_local_got_refcounts (abfd);
2618
if (local_got_refcounts == NULL)
2622
size = symtab_hdr->sh_info;
2623
size *= sizeof (bfd_signed_vma);
2624
local_got_refcounts = ((bfd_signed_vma *)
2625
bfd_zalloc (abfd, size));
2626
if (local_got_refcounts == NULL)
2628
elf_local_got_refcounts (abfd) = local_got_refcounts;
2630
local_got_refcounts[r_symndx] += 1;
2634
case R_PPC64_PLT16_HA:
2635
case R_PPC64_PLT16_HI:
2636
case R_PPC64_PLT16_LO:
2639
/* This symbol requires a procedure linkage table entry. We
2640
actually build the entry in adjust_dynamic_symbol,
2641
because this might be a case of linking PIC code without
2642
linking in any dynamic objects, in which case we don't
2643
need to generate a procedure linkage table after all. */
2646
/* It does not make sense to have a procedure linkage
2647
table entry for a local symbol. */
2648
bfd_set_error (bfd_error_bad_value);
2652
h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
2653
h->plt.refcount += 1;
2654
((struct ppc_link_hash_entry *) h)->is_func = 1;
2657
/* The following relocations don't need to propagate the
2658
relocation if linking a shared object since they are
2659
section relative. */
2660
case R_PPC64_SECTOFF:
2661
case R_PPC64_SECTOFF_LO:
2662
case R_PPC64_SECTOFF_HI:
2663
case R_PPC64_SECTOFF_HA:
2664
case R_PPC64_SECTOFF_DS:
2665
case R_PPC64_SECTOFF_LO_DS:
2667
case R_PPC64_TOC16_LO:
2668
case R_PPC64_TOC16_HI:
2669
case R_PPC64_TOC16_HA:
2670
case R_PPC64_TOC16_DS:
2671
case R_PPC64_TOC16_LO_DS:
2674
/* This relocation describes the C++ object vtable hierarchy.
2675
Reconstruct it for later use during GC. */
2676
case R_PPC64_GNU_VTINHERIT:
2677
if (!_bfd_elf64_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
2681
/* This relocation describes which C++ vtable entries are actually
2682
used. Record for later use during GC. */
2683
case R_PPC64_GNU_VTENTRY:
2684
if (!_bfd_elf64_gc_record_vtentry (abfd, sec, h, rel->r_addend))
2689
case R_PPC64_REL14_BRTAKEN:
2690
case R_PPC64_REL14_BRNTAKEN:
2691
htab->has_14bit_branch = 1;
2696
&& h->root.root.string[0] == '.'
2697
&& h->root.root.string[1] != 0)
2699
/* We may need a .plt entry if the function this reloc
2700
refers to is in a shared lib. */
2701
h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
2702
h->plt.refcount += 1;
2703
((struct ppc_link_hash_entry *) h)->is_func = 1;
2707
case R_PPC64_ADDR64:
2708
if (opd_sym_map != NULL
2710
&& h->root.root.string[0] == '.'
2711
&& h->root.root.string[1] != 0)
2713
struct elf_link_hash_entry *fdh;
2715
fdh = elf_link_hash_lookup (&htab->elf, h->root.root.string + 1,
2716
false, false, false);
2719
((struct ppc_link_hash_entry *) fdh)->is_func_descriptor = 1;
2720
((struct ppc_link_hash_entry *) fdh)->oh = h;
2721
((struct ppc_link_hash_entry *) h)->is_func = 1;
2722
((struct ppc_link_hash_entry *) h)->oh = fdh;
2725
if (opd_sym_map != NULL
2727
&& rel + 1 < rel_end
2728
&& ((enum elf_ppc_reloc_type) ELF64_R_TYPE ((rel + 1)->r_info)
2733
s = bfd_section_from_r_symndx (abfd, &htab->sym_sec, sec,
2738
opd_sym_map[rel->r_offset / 24] = s;
2744
case R_PPC64_ADDR14:
2745
case R_PPC64_ADDR14_BRNTAKEN:
2746
case R_PPC64_ADDR14_BRTAKEN:
2747
case R_PPC64_ADDR16:
2748
case R_PPC64_ADDR16_DS:
2749
case R_PPC64_ADDR16_HA:
2750
case R_PPC64_ADDR16_HI:
2751
case R_PPC64_ADDR16_HIGHER:
2752
case R_PPC64_ADDR16_HIGHERA:
2753
case R_PPC64_ADDR16_HIGHEST:
2754
case R_PPC64_ADDR16_HIGHESTA:
2755
case R_PPC64_ADDR16_LO:
2756
case R_PPC64_ADDR16_LO_DS:
2757
case R_PPC64_ADDR24:
2758
case R_PPC64_ADDR30:
2759
case R_PPC64_ADDR32:
2760
case R_PPC64_UADDR16:
2761
case R_PPC64_UADDR32:
2762
case R_PPC64_UADDR64:
2764
/* Don't propagate .opd relocs. */
2765
if (NO_OPD_RELOCS && opd_sym_map != NULL)
2768
/* If we are creating a shared library, and this is a reloc
2769
against a global symbol, or a non PC relative reloc
2770
against a local symbol, then we need to copy the reloc
2771
into the shared library. However, if we are linking with
2772
-Bsymbolic, we do not need to copy a reloc against a
2773
global symbol which is defined in an object we are
2774
including in the link (i.e., DEF_REGULAR is set). At
2775
this point we have not seen all the input files, so it is
2776
possible that DEF_REGULAR is not set now but will be set
2777
later (it is never cleared). In case of a weak definition,
2778
DEF_REGULAR may be cleared later by a strong definition in
2779
a shared library. We account for that possibility below by
2780
storing information in the relocs_copied field of the hash
2781
table entry. A similar situation occurs when creating
2782
shared libraries and symbol visibility changes render the
2785
If on the other hand, we are creating an executable, we
2786
may need to keep relocations for symbols satisfied by a
2787
dynamic library if we manage to avoid copy relocs for the
2790
&& (sec->flags & SEC_ALLOC) != 0
2791
&& (IS_ABSOLUTE_RELOC (r_type)
2793
&& (! info->symbolic
2794
|| h->root.type == bfd_link_hash_defweak
2795
|| (h->elf_link_hash_flags
2796
& ELF_LINK_HASH_DEF_REGULAR) == 0))))
2798
&& (sec->flags & SEC_ALLOC) != 0
2800
&& (h->root.type == bfd_link_hash_defweak
2801
|| (h->elf_link_hash_flags
2802
& ELF_LINK_HASH_DEF_REGULAR) == 0)))
2804
struct ppc_dyn_relocs *p;
2805
struct ppc_dyn_relocs **head;
2807
/* We must copy these reloc types into the output file.
2808
Create a reloc section in dynobj and make room for
2815
name = (bfd_elf_string_from_elf_section
2817
elf_elfheader (abfd)->e_shstrndx,
2818
elf_section_data (sec)->rel_hdr.sh_name));
2822
if (strncmp (name, ".rela", 5) != 0
2823
|| strcmp (bfd_get_section_name (abfd, sec),
2826
(*_bfd_error_handler)
2827
(_("%s: bad relocation section name `%s\'"),
2828
bfd_archive_filename (abfd), name);
2829
bfd_set_error (bfd_error_bad_value);
2832
dynobj = htab->elf.dynobj;
2833
sreloc = bfd_get_section_by_name (dynobj, name);
2838
sreloc = bfd_make_section (dynobj, name);
2839
flags = (SEC_HAS_CONTENTS | SEC_READONLY
2840
| SEC_IN_MEMORY | SEC_LINKER_CREATED);
2841
if ((sec->flags & SEC_ALLOC) != 0)
2842
flags |= SEC_ALLOC | SEC_LOAD;
2844
|| ! bfd_set_section_flags (dynobj, sreloc, flags)
2845
|| ! bfd_set_section_alignment (dynobj, sreloc, 3))
2848
elf_section_data (sec)->sreloc = sreloc;
2851
/* If this is a global symbol, we count the number of
2852
relocations we need for this symbol. */
2855
head = &((struct ppc_link_hash_entry *) h)->dyn_relocs;
2859
/* Track dynamic relocs needed for local syms too.
2860
We really need local syms available to do this
2864
s = bfd_section_from_r_symndx (abfd, &htab->sym_sec,
2869
head = ((struct ppc_dyn_relocs **)
2870
&elf_section_data (s)->local_dynrel);
2874
if (p == NULL || p->sec != sec)
2876
p = ((struct ppc_dyn_relocs *)
2877
bfd_alloc (htab->elf.dynobj,
2878
(bfd_size_type) sizeof *p));
2889
if (!IS_ABSOLUTE_RELOC (r_type))
2902
/* Return the section that should be marked against GC for a given
2906
ppc64_elf_gc_mark_hook (sec, info, rel, h, sym)
2908
struct bfd_link_info *info ATTRIBUTE_UNUSED;
2909
Elf_Internal_Rela *rel;
2910
struct elf_link_hash_entry *h;
2911
Elf_Internal_Sym *sym;
2913
asection *rsec = NULL;
2917
enum elf_ppc_reloc_type r_type;
2918
struct ppc_link_hash_entry *fdh;
2920
r_type = (enum elf_ppc_reloc_type) ELF64_R_TYPE (rel->r_info);
2923
case R_PPC64_GNU_VTINHERIT:
2924
case R_PPC64_GNU_VTENTRY:
2928
switch (h->root.type)
2930
case bfd_link_hash_defined:
2931
case bfd_link_hash_defweak:
2932
fdh = (struct ppc_link_hash_entry *) h;
2934
/* Function descriptor syms cause the associated
2935
function code sym section to be marked. */
2936
if (fdh->is_func_descriptor)
2937
rsec = fdh->oh->root.u.def.section;
2939
/* Function entry syms return NULL if they are in .opd
2940
and are not ._start (or others undefined on the ld
2941
command line). Thus we avoid marking all function
2942
sections, as all functions are referenced in .opd. */
2943
else if ((fdh->oh != NULL
2944
&& ((struct ppc_link_hash_entry *) fdh->oh)->is_entry)
2945
|| elf_section_data (sec)->tdata == NULL)
2946
rsec = h->root.u.def.section;
2949
case bfd_link_hash_common:
2950
rsec = h->root.u.c.p->section;
2960
asection **opd_sym_section;
2962
rsec = bfd_section_from_elf_index (sec->owner, sym->st_shndx);
2963
opd_sym_section = (asection **) elf_section_data (rsec)->tdata;
2964
if (opd_sym_section != NULL)
2965
rsec = opd_sym_section[sym->st_value / 24];
2966
else if (elf_section_data (sec)->tdata != NULL)
2973
/* Update the .got, .plt. and dynamic reloc reference counts for the
2974
section being removed. */
2977
ppc64_elf_gc_sweep_hook (abfd, info, sec, relocs)
2979
struct bfd_link_info *info ATTRIBUTE_UNUSED;
2981
const Elf_Internal_Rela *relocs;
2983
Elf_Internal_Shdr *symtab_hdr;
2984
struct elf_link_hash_entry **sym_hashes;
2985
bfd_signed_vma *local_got_refcounts;
2986
const Elf_Internal_Rela *rel, *relend;
2988
elf_section_data (sec)->local_dynrel = NULL;
2990
symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
2991
sym_hashes = elf_sym_hashes (abfd);
2992
local_got_refcounts = elf_local_got_refcounts (abfd);
2994
relend = relocs + sec->reloc_count;
2995
for (rel = relocs; rel < relend; rel++)
2997
unsigned long r_symndx;
2998
enum elf_ppc_reloc_type r_type;
2999
struct elf_link_hash_entry *h;
3001
r_symndx = ELF64_R_SYM (rel->r_info);
3002
r_type = (enum elf_ppc_reloc_type) ELF64_R_TYPE (rel->r_info);
3006
case R_PPC64_GOT16_DS:
3007
case R_PPC64_GOT16_HA:
3008
case R_PPC64_GOT16_HI:
3009
case R_PPC64_GOT16_LO:
3010
case R_PPC64_GOT16_LO_DS:
3011
if (r_symndx >= symtab_hdr->sh_info)
3013
h = sym_hashes[r_symndx - symtab_hdr->sh_info];
3014
if (h->got.refcount > 0)
3019
if (local_got_refcounts[r_symndx] > 0)
3020
local_got_refcounts[r_symndx]--;
3024
case R_PPC64_PLT16_HA:
3025
case R_PPC64_PLT16_HI:
3026
case R_PPC64_PLT16_LO:
3029
if (r_symndx >= symtab_hdr->sh_info)
3031
h = sym_hashes[r_symndx - symtab_hdr->sh_info];
3032
if (h->plt.refcount > 0)
3038
case R_PPC64_REL14_BRNTAKEN:
3039
case R_PPC64_REL14_BRTAKEN:
3041
if (r_symndx >= symtab_hdr->sh_info)
3043
h = sym_hashes[r_symndx - symtab_hdr->sh_info];
3044
if (h->plt.refcount > 0)
3051
if (r_symndx >= symtab_hdr->sh_info)
3053
struct ppc_link_hash_entry *eh;
3054
struct ppc_dyn_relocs **pp;
3055
struct ppc_dyn_relocs *p;
3057
h = sym_hashes[r_symndx - symtab_hdr->sh_info];
3058
eh = (struct ppc_link_hash_entry *) h;
3060
for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next)
3072
case R_PPC64_ADDR14:
3073
case R_PPC64_ADDR14_BRNTAKEN:
3074
case R_PPC64_ADDR14_BRTAKEN:
3075
case R_PPC64_ADDR16:
3076
case R_PPC64_ADDR16_DS:
3077
case R_PPC64_ADDR16_HA:
3078
case R_PPC64_ADDR16_HI:
3079
case R_PPC64_ADDR16_HIGHER:
3080
case R_PPC64_ADDR16_HIGHERA:
3081
case R_PPC64_ADDR16_HIGHEST:
3082
case R_PPC64_ADDR16_HIGHESTA:
3083
case R_PPC64_ADDR16_LO:
3084
case R_PPC64_ADDR16_LO_DS:
3085
case R_PPC64_ADDR24:
3086
case R_PPC64_ADDR30:
3087
case R_PPC64_ADDR32:
3088
case R_PPC64_ADDR64:
3089
case R_PPC64_UADDR16:
3090
case R_PPC64_UADDR32:
3091
case R_PPC64_UADDR64:
3093
if (r_symndx >= symtab_hdr->sh_info)
3095
struct ppc_link_hash_entry *eh;
3096
struct ppc_dyn_relocs **pp;
3097
struct ppc_dyn_relocs *p;
3099
h = sym_hashes[r_symndx - symtab_hdr->sh_info];
3100
eh = (struct ppc_link_hash_entry *) h;
3102
for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next)
3120
/* Called via elf_link_hash_traverse to transfer dynamic linking
3121
information on function code symbol entries to their corresponding
3122
function descriptor symbol entries. */
3124
func_desc_adjust (h, inf)
3125
struct elf_link_hash_entry *h;
3128
struct bfd_link_info *info;
3129
struct ppc_link_hash_table *htab;
3131
if (h->root.type == bfd_link_hash_indirect)
3134
if (h->root.type == bfd_link_hash_warning)
3135
h = (struct elf_link_hash_entry *) h->root.u.i.link;
3137
info = (struct bfd_link_info *) inf;
3138
htab = ppc_hash_table (info);
3140
/* If this is a function code symbol, transfer dynamic linking
3141
information to the function descriptor symbol. */
3142
if (!((struct ppc_link_hash_entry *) h)->is_func)
3145
if (h->root.type == bfd_link_hash_undefweak
3146
&& (h->elf_link_hash_flags & ELF_LINK_HASH_REF_REGULAR))
3147
htab->have_undefweak = true;
3149
if (h->plt.refcount > 0
3150
&& h->root.root.string[0] == '.'
3151
&& h->root.root.string[1] != '\0')
3153
struct elf_link_hash_entry *fdh = ((struct ppc_link_hash_entry *) h)->oh;
3154
boolean force_local;
3156
/* Find the corresponding function descriptor symbol. Create it
3157
as undefined if necessary. */
3160
fdh = elf_link_hash_lookup (&htab->elf, h->root.root.string + 1,
3161
false, false, true);
3165
&& (h->root.type == bfd_link_hash_undefined
3166
|| h->root.type == bfd_link_hash_undefweak))
3171
abfd = h->root.u.undef.abfd;
3172
newsym = bfd_make_empty_symbol (abfd);
3173
newsym->name = h->root.root.string + 1;
3174
newsym->section = bfd_und_section_ptr;
3176
newsym->flags = BSF_OBJECT;
3177
if (h->root.type == bfd_link_hash_undefweak)
3178
newsym->flags |= BSF_WEAK;
3180
if ( !(_bfd_generic_link_add_one_symbol
3181
(info, abfd, newsym->name, newsym->flags,
3182
newsym->section, newsym->value, NULL, false, false,
3183
(struct bfd_link_hash_entry **) &fdh)))
3187
fdh->elf_link_hash_flags &= ~ELF_LINK_NON_ELF;
3191
&& (fdh->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0
3193
|| (fdh->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0
3194
|| (fdh->elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) != 0))
3196
if (fdh->dynindx == -1)
3197
if (! bfd_elf64_link_record_dynamic_symbol (info, fdh))
3199
fdh->elf_link_hash_flags |= (h->elf_link_hash_flags
3200
& (ELF_LINK_HASH_REF_REGULAR
3201
| ELF_LINK_HASH_REF_DYNAMIC
3202
| ELF_LINK_HASH_REF_REGULAR_NONWEAK
3203
| ELF_LINK_NON_GOT_REF));
3204
if (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
3206
fdh->plt.refcount = h->plt.refcount;
3207
fdh->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
3209
((struct ppc_link_hash_entry *) fdh)->is_func_descriptor = 1;
3210
((struct ppc_link_hash_entry *) fdh)->oh = h;
3211
((struct ppc_link_hash_entry *) h)->oh = fdh;
3214
/* Now that the info is on the function descriptor, clear the
3215
function code sym info. Any function code syms for which we
3216
don't have a definition in a regular file, we force local.
3217
This prevents a shared library from exporting syms that have
3218
been imported from another library. Function code syms that
3219
are really in the library we must leave global to prevent the
3220
linker dragging in a definition from a static library. */
3221
force_local = (info->shared
3222
&& ((h->elf_link_hash_flags
3223
& ELF_LINK_HASH_DEF_REGULAR) == 0
3225
|| (fdh->elf_link_hash_flags
3226
& ELF_LINK_HASH_DEF_REGULAR) == 0
3227
|| (fdh->elf_link_hash_flags
3228
& ELF_LINK_FORCED_LOCAL) != 0));
3229
_bfd_elf_link_hash_hide_symbol (info, h, force_local);
3235
#define MIN_SAVE_FPR 14
3236
#define MAX_SAVE_FPR 31
3238
/* Called near the start of bfd_elf_size_dynamic_sections. We use
3239
this hook to a) provide some gcc support functions, and b) transfer
3240
dynamic linking information gathered so far on function code symbol
3241
entries, to their corresponding function descriptor symbol entries. */
3243
ppc64_elf_func_desc_adjust (obfd, info)
3244
bfd *obfd ATTRIBUTE_UNUSED;
3245
struct bfd_link_info *info;
3247
struct ppc_link_hash_table *htab;
3248
unsigned int lowest_savef = MAX_SAVE_FPR + 2;
3249
unsigned int lowest_restf = MAX_SAVE_FPR + 2;
3251
struct elf_link_hash_entry *h;
3255
htab = ppc_hash_table (info);
3257
if (htab->sfpr == NULL)
3258
/* We don't have any relocs. */
3261
/* First provide any missing ._savef* and ._restf* functions. */
3262
memcpy (sym, "._savef14", 10);
3263
for (i = MIN_SAVE_FPR; i <= MAX_SAVE_FPR; i++)
3265
sym[7] = i / 10 + '0';
3266
sym[8] = i % 10 + '0';
3267
h = elf_link_hash_lookup (&htab->elf, sym, false, false, true);
3269
&& h->root.type == bfd_link_hash_undefined)
3271
if (lowest_savef > i)
3273
h->root.type = bfd_link_hash_defined;
3274
h->root.u.def.section = htab->sfpr;
3275
h->root.u.def.value = (i - lowest_savef) * 4;
3277
h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
3278
_bfd_elf_link_hash_hide_symbol (info, h, info->shared);
3282
memcpy (sym, "._restf14", 10);
3283
for (i = MIN_SAVE_FPR; i <= MAX_SAVE_FPR; i++)
3285
sym[7] = i / 10 + '0';
3286
sym[8] = i % 10 + '0';
3287
h = elf_link_hash_lookup (&htab->elf, sym, false, false, true);
3289
&& h->root.type == bfd_link_hash_undefined)
3291
if (lowest_restf > i)
3293
h->root.type = bfd_link_hash_defined;
3294
h->root.u.def.section = htab->sfpr;
3295
h->root.u.def.value = ((MAX_SAVE_FPR + 2 - lowest_savef) * 4
3296
+ (i - lowest_restf) * 4);
3298
h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
3299
_bfd_elf_link_hash_hide_symbol (info, h, info->shared);
3303
elf_link_hash_traverse (&htab->elf, func_desc_adjust, (PTR) info);
3305
htab->sfpr->_raw_size = ((MAX_SAVE_FPR + 2 - lowest_savef) * 4
3306
+ (MAX_SAVE_FPR + 2 - lowest_restf) * 4);
3308
if (htab->sfpr->_raw_size == 0)
3310
if (!htab->have_undefweak)
3312
_bfd_strip_section_from_output (info, htab->sfpr);
3316
htab->sfpr->_raw_size = 4;
3319
p = (bfd_byte *) bfd_alloc (htab->elf.dynobj, htab->sfpr->_raw_size);
3322
htab->sfpr->contents = p;
3324
for (i = lowest_savef; i <= MAX_SAVE_FPR; i++)
3326
unsigned int fpr = i << 21;
3327
unsigned int stackoff = (1 << 16) - (MAX_SAVE_FPR + 1 - i) * 8;
3328
bfd_put_32 (htab->elf.dynobj, STFD_FR0_0R1 + fpr + stackoff, p);
3331
if (lowest_savef <= MAX_SAVE_FPR)
3333
bfd_put_32 (htab->elf.dynobj, BLR, p);
3337
for (i = lowest_restf; i <= MAX_SAVE_FPR; i++)
3339
unsigned int fpr = i << 21;
3340
unsigned int stackoff = (1 << 16) - (MAX_SAVE_FPR + 1 - i) * 8;
3341
bfd_put_32 (htab->elf.dynobj, LFD_FR0_0R1 + fpr + stackoff, p);
3344
if (lowest_restf <= MAX_SAVE_FPR
3345
|| htab->sfpr->_raw_size == 4)
3347
bfd_put_32 (htab->elf.dynobj, BLR, p);
3353
/* Adjust a symbol defined by a dynamic object and referenced by a
3354
regular object. The current definition is in some section of the
3355
dynamic object, but we're not including those sections. We have to
3356
change the definition to something the rest of the link can
3360
ppc64_elf_adjust_dynamic_symbol (info, h)
3361
struct bfd_link_info *info;
3362
struct elf_link_hash_entry *h;
3364
struct ppc_link_hash_table *htab;
3365
struct ppc_link_hash_entry * eh;
3366
struct ppc_dyn_relocs *p;
3368
unsigned int power_of_two;
3370
htab = ppc_hash_table (info);
3372
/* Deal with function syms. */
3373
if (h->type == STT_FUNC
3374
|| (h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0)
3376
/* Clear procedure linkage table information for any symbol that
3377
won't need a .plt entry. */
3378
if (!((struct ppc_link_hash_entry *) h)->is_func_descriptor
3379
|| h->plt.refcount <= 0
3380
|| (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0
3382
&& (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) == 0
3383
&& (h->elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) == 0))
3385
h->plt.offset = (bfd_vma) -1;
3386
h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
3391
h->plt.offset = (bfd_vma) -1;
3393
/* If this is a weak symbol, and there is a real definition, the
3394
processor independent code will have arranged for us to see the
3395
real definition first, and we can just use the same value. */
3396
if (h->weakdef != NULL)
3398
BFD_ASSERT (h->weakdef->root.type == bfd_link_hash_defined
3399
|| h->weakdef->root.type == bfd_link_hash_defweak);
3400
h->root.u.def.section = h->weakdef->root.u.def.section;
3401
h->root.u.def.value = h->weakdef->root.u.def.value;
3405
/* This is a reference to a symbol defined by a dynamic object which
3406
is not a function. */
3408
/* If we are creating a shared library, we must presume that the
3409
only references to the symbol are via the global offset table.
3410
For such cases we need not do anything here; the relocations will
3411
be handled correctly by relocate_section. */
3415
/* If there are no references to this symbol that do not use the
3416
GOT, we don't need to generate a copy reloc. */
3417
if ((h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0)
3420
eh = (struct ppc_link_hash_entry *) h;
3421
for (p = eh->dyn_relocs; p != NULL; p = p->next)
3423
s = p->sec->output_section;
3424
if (s != NULL && (s->flags & SEC_READONLY) != 0)
3428
/* If we didn't find any dynamic relocs in read-only sections, then
3429
we'll be keeping the dynamic relocs and avoiding the copy reloc. */
3432
h->elf_link_hash_flags &= ~ELF_LINK_NON_GOT_REF;
3436
/* We must allocate the symbol in our .dynbss section, which will
3437
become part of the .bss section of the executable. There will be
3438
an entry for this symbol in the .dynsym section. The dynamic
3439
object will contain position independent code, so all references
3440
from the dynamic object to this symbol will go through the global
3441
offset table. The dynamic linker will use the .dynsym entry to
3442
determine the address it must put in the global offset table, so
3443
both the dynamic object and the regular object will refer to the
3444
same memory location for the variable. */
3446
/* We must generate a R_PPC_COPY reloc to tell the dynamic linker to
3447
copy the initial value out of the dynamic object and into the
3448
runtime process image. We need to remember the offset into the
3449
.rela.bss section we are going to use. */
3450
if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
3452
htab->srelbss->_raw_size += sizeof (Elf64_External_Rela);
3453
h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_COPY;
3456
/* We need to figure out the alignment required for this symbol. I
3457
have no idea how ELF linkers handle this. */
3458
power_of_two = bfd_log2 (h->size);
3459
if (power_of_two > 4)
3462
/* Apply the required alignment. */
3464
s->_raw_size = BFD_ALIGN (s->_raw_size, (bfd_size_type) (1 << power_of_two));
3465
if (power_of_two > bfd_get_section_alignment (htab->elf.dynobj, s))
3467
if (! bfd_set_section_alignment (htab->elf.dynobj, s, power_of_two))
3471
/* Define the symbol as being at this point in the section. */
3472
h->root.u.def.section = s;
3473
h->root.u.def.value = s->_raw_size;
3475
/* Increment the section size to make room for the symbol. */
3476
s->_raw_size += h->size;
3481
/* If given a function descriptor symbol, hide both the function code
3482
sym and the descriptor. */
3484
ppc64_elf_hide_symbol (info, h, force_local)
3485
struct bfd_link_info *info;
3486
struct elf_link_hash_entry *h;
3487
boolean force_local;
3489
_bfd_elf_link_hash_hide_symbol (info, h, force_local);
3491
if (((struct ppc_link_hash_entry *) h)->is_func_descriptor)
3493
struct elf_link_hash_entry *fh = ((struct ppc_link_hash_entry *) h)->oh;
3498
struct ppc_link_hash_table *htab;
3501
/* We aren't supposed to use alloca in BFD because on
3502
systems which do not have alloca the version in libiberty
3503
calls xmalloc, which might cause the program to crash
3504
when it runs out of memory. This function doesn't have a
3505
return status, so there's no way to gracefully return an
3506
error. So cheat. We know that string[-1] can be safely
3507
dereferenced; It's either a string in an ELF string
3508
table, or allocated in an objalloc structure. */
3510
p = h->root.root.string - 1;
3513
htab = ppc_hash_table (info);
3514
fh = elf_link_hash_lookup (&htab->elf, p, false, false, false);
3517
/* Unfortunately, if it so happens that the string we were
3518
looking for was allocated immediately before this string,
3519
then we overwrote the string terminator. That's the only
3520
reason the lookup should fail. */
3523
q = h->root.root.string + strlen (h->root.root.string);
3524
while (q >= h->root.root.string && *q == *p)
3526
if (q < h->root.root.string && *p == '.')
3527
fh = elf_link_hash_lookup (&htab->elf, p, false, false, false);
3531
((struct ppc_link_hash_entry *) h)->oh = fh;
3532
((struct ppc_link_hash_entry *) fh)->oh = h;
3536
_bfd_elf_link_hash_hide_symbol (info, fh, force_local);
3541
edit_opd (obfd, info)
3543
struct bfd_link_info *info;
3546
unsigned int bfd_indx;
3548
for (bfd_indx = 0, ibfd = info->input_bfds;
3550
ibfd = ibfd->link_next, bfd_indx++)
3553
Elf_Internal_Rela *relstart, *rel, *relend;
3554
Elf_Internal_Shdr *symtab_hdr;
3555
Elf_Internal_Sym *local_syms;
3556
struct elf_link_hash_entry **sym_hashes;
3561
sec = bfd_get_section_by_name (ibfd, ".opd");
3565
adjust = (long *) elf_section_data (sec)->tdata;
3566
BFD_ASSERT (adjust != NULL);
3567
memset (adjust, 0, (size_t) sec->_raw_size * sizeof (long) / 24);
3569
if (sec->output_section == bfd_abs_section_ptr)
3572
/* Look through the section relocs. */
3573
if ((sec->flags & SEC_RELOC) == 0 || sec->reloc_count == 0)
3577
symtab_hdr = &elf_tdata (ibfd)->symtab_hdr;
3578
sym_hashes = elf_sym_hashes (ibfd);
3580
/* Read the relocations. */
3581
relstart = _bfd_elf64_link_read_relocs (obfd, sec, (PTR) NULL,
3582
(Elf_Internal_Rela *) NULL,
3584
if (relstart == NULL)
3587
/* First run through the relocs to check they are sane, and to
3588
determine whether we need to edit this opd section. */
3591
relend = relstart + sec->reloc_count;
3592
for (rel = relstart; rel < relend; rel++)
3594
enum elf_ppc_reloc_type r_type;
3595
unsigned long r_symndx;
3597
struct elf_link_hash_entry *h;
3598
Elf_Internal_Sym *sym;
3600
/* .opd contains a regular array of 24 byte entries. We're
3601
only interested in the reloc pointing to a function entry
3603
r_type = (enum elf_ppc_reloc_type) ELF64_R_TYPE (rel->r_info);
3604
if (r_type == R_PPC64_TOC)
3607
if (r_type != R_PPC64_ADDR64)
3609
(*_bfd_error_handler)
3610
(_("%s: unexpected reloc type %u in .opd section"),
3611
bfd_archive_filename (ibfd), r_type);
3616
if (rel + 1 >= relend)
3618
r_type = (enum elf_ppc_reloc_type) ELF64_R_TYPE ((rel + 1)->r_info);
3619
if (r_type != R_PPC64_TOC)
3622
if (rel->r_offset != offset)
3624
/* If someone messes with .opd alignment then after a
3625
"ld -r" we might have padding in the middle of .opd.
3626
Also, there's nothing to prevent someone putting
3627
something silly in .opd with the assembler. No .opd
3628
optimization for them! */
3629
(*_bfd_error_handler)
3630
(_("%s: .opd is not a regular array of opd entries"),
3631
bfd_archive_filename (ibfd));
3636
r_symndx = ELF64_R_SYM (rel->r_info);
3640
if (r_symndx >= symtab_hdr->sh_info)
3642
h = sym_hashes[r_symndx - symtab_hdr->sh_info];
3643
while (h->root.type == bfd_link_hash_indirect
3644
|| h->root.type == bfd_link_hash_warning)
3645
h = (struct elf_link_hash_entry *) h->root.u.i.link;
3646
if (h->root.type == bfd_link_hash_defined
3647
|| h->root.type == bfd_link_hash_defweak)
3648
sym_sec = h->root.u.def.section;
3652
if (local_syms == NULL)
3654
local_syms = (Elf_Internal_Sym *) symtab_hdr->contents;
3655
if (local_syms == NULL)
3656
local_syms = bfd_elf_get_elf_syms (ibfd, symtab_hdr,
3657
symtab_hdr->sh_info, 0,
3659
if (local_syms == NULL)
3660
goto error_free_rel;
3662
sym = local_syms + r_symndx;
3663
if ((sym->st_shndx != SHN_UNDEF
3664
&& sym->st_shndx < SHN_LORESERVE)
3665
|| sym->st_shndx > SHN_HIRESERVE)
3666
sym_sec = bfd_section_from_elf_index (ibfd, sym->st_shndx);
3669
if (sym_sec == NULL || sym_sec->owner == NULL)
3671
(*_bfd_error_handler)
3672
(_("%s: undefined sym `%s' in .opd section"),
3673
bfd_archive_filename (ibfd),
3674
h != NULL ? h->root.root.string : "<local symbol>");
3679
if (sym_sec->output_section == bfd_abs_section_ptr)
3681
/* OK, we've found a function that's excluded from the
3691
Elf_Internal_Rela *write_rel;
3692
bfd_byte *rptr, *wptr;
3695
/* This seems a waste of time as input .opd sections are all
3696
zeros as generated by gcc, but I suppose there's no reason
3697
this will always be so. We might start putting something in
3698
the third word of .opd entries. */
3699
if ((sec->flags & SEC_IN_MEMORY) == 0)
3701
bfd_byte *loc = bfd_alloc (ibfd, sec->_raw_size);
3703
|| !bfd_get_section_contents (ibfd, sec, loc, (bfd_vma) 0,
3706
if (local_syms != NULL
3707
&& symtab_hdr->contents != (unsigned char *) local_syms)
3710
if (elf_section_data (sec)->relocs != relstart)
3714
sec->contents = loc;
3715
sec->flags |= (SEC_IN_MEMORY | SEC_HAS_CONTENTS);
3718
elf_section_data (sec)->relocs = relstart;
3720
wptr = sec->contents;
3721
rptr = sec->contents;
3722
write_rel = relstart;
3725
for (rel = relstart; rel < relend; rel++)
3727
if (rel->r_offset == offset)
3729
unsigned long r_symndx;
3731
struct elf_link_hash_entry *h;
3732
Elf_Internal_Sym *sym;
3734
r_symndx = ELF64_R_SYM (rel->r_info);
3738
if (r_symndx >= symtab_hdr->sh_info)
3740
h = sym_hashes[r_symndx - symtab_hdr->sh_info];
3741
while (h->root.type == bfd_link_hash_indirect
3742
|| h->root.type == bfd_link_hash_warning)
3743
h = (struct elf_link_hash_entry *) h->root.u.i.link;
3744
if (h->root.type == bfd_link_hash_defined
3745
|| h->root.type == bfd_link_hash_defweak)
3746
sym_sec = h->root.u.def.section;
3750
sym = local_syms + r_symndx;
3751
if ((sym->st_shndx != SHN_UNDEF
3752
&& sym->st_shndx < SHN_LORESERVE)
3753
|| sym->st_shndx > SHN_HIRESERVE)
3754
sym_sec = bfd_section_from_elf_index (ibfd,
3758
skip = sym_sec->output_section == bfd_abs_section_ptr;
3761
/* We'll be keeping this opd entry. */
3765
/* Redefine the function descriptor symbol
3766
to this location in the opd section.
3767
We've checked above that opd relocs are
3769
struct elf_link_hash_entry *fdh;
3770
struct ppc_link_hash_entry *fh;
3772
fh = (struct ppc_link_hash_entry *) h;
3773
BFD_ASSERT (fh->is_func);
3775
fdh->root.u.def.value = wptr - sec->contents;
3779
/* Local syms are a bit tricky. We could
3780
tweak them as they can be cached, but
3781
we'd need to look through the local syms
3782
for the function descriptor sym which we
3783
don't have at the moment. So keep an
3784
array of adjustments. */
3785
adjust[(rel->r_offset + wptr - rptr) / 24]
3790
memcpy (wptr, rptr, 24);
3797
/* We need to adjust any reloc offsets to point to the
3798
new opd entries. While we're at it, we may as well
3799
remove redundant relocs. */
3802
rel->r_offset += wptr - rptr;
3803
if (write_rel != rel)
3804
memcpy (write_rel, rel, sizeof (*rel));
3809
sec->_cooked_size = wptr - sec->contents;
3810
sec->reloc_count = write_rel - relstart;
3812
else if (elf_section_data (sec)->relocs != relstart)
3815
if (local_syms != NULL
3816
&& symtab_hdr->contents != (unsigned char *) local_syms)
3818
if (!info->keep_memory)
3821
symtab_hdr->contents = (unsigned char *) local_syms;
3828
/* This is the condition under which ppc64_elf_finish_dynamic_symbol
3829
will be called from elflink.h. If elflink.h doesn't call our
3830
finish_dynamic_symbol routine, we'll need to do something about
3831
initializing any .plt and .got entries in ppc64_elf_relocate_section. */
3832
#define WILL_CALL_FINISH_DYNAMIC_SYMBOL(DYN, INFO, H) \
3834
&& ((INFO)->shared \
3835
|| ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) \
3836
&& ((H)->dynindx != -1 \
3837
|| ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0))
3839
/* Allocate space in .plt, .got and associated reloc sections for
3843
allocate_dynrelocs (h, inf)
3844
struct elf_link_hash_entry *h;
3847
struct bfd_link_info *info;
3848
struct ppc_link_hash_table *htab;
3850
struct ppc_link_hash_entry *eh;
3851
struct ppc_dyn_relocs *p;
3853
if (h->root.type == bfd_link_hash_indirect)
3856
if (h->root.type == bfd_link_hash_warning)
3857
h = (struct elf_link_hash_entry *) h->root.u.i.link;
3859
info = (struct bfd_link_info *) inf;
3860
htab = ppc_hash_table (info);
3862
if (htab->elf.dynamic_sections_created
3863
&& h->plt.refcount > 0
3864
&& h->dynindx != -1)
3866
BFD_ASSERT (((struct ppc_link_hash_entry *) h)->is_func_descriptor);
3868
if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, info, h))
3870
/* If this is the first .plt entry, make room for the special
3873
if (s->_raw_size == 0)
3874
s->_raw_size += PLT_INITIAL_ENTRY_SIZE;
3876
h->plt.offset = s->_raw_size;
3878
/* Make room for this entry. */
3879
s->_raw_size += PLT_ENTRY_SIZE;
3881
/* Make room for the .glink code. */
3883
if (s->_raw_size == 0)
3884
s->_raw_size += GLINK_CALL_STUB_SIZE;
3885
/* We need bigger stubs past index 32767. */
3886
if (s->_raw_size >= GLINK_CALL_STUB_SIZE + 32768*2*4)
3888
s->_raw_size += 2*4;
3890
/* We also need to make an entry in the .rela.plt section. */
3892
s->_raw_size += sizeof (Elf64_External_Rela);
3896
h->plt.offset = (bfd_vma) -1;
3897
h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
3902
h->plt.offset = (bfd_vma) -1;
3903
h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
3906
if (h->got.refcount > 0)
3910
/* Make sure this symbol is output as a dynamic symbol.
3911
Undefined weak syms won't yet be marked as dynamic. */
3912
if (h->dynindx == -1
3913
&& (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0)
3915
if (! bfd_elf64_link_record_dynamic_symbol (info, h))
3920
h->got.offset = s->_raw_size;
3922
dyn = htab->elf.dynamic_sections_created;
3923
if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info, h))
3924
htab->srelgot->_raw_size += sizeof (Elf64_External_Rela);
3927
h->got.offset = (bfd_vma) -1;
3929
eh = (struct ppc_link_hash_entry *) h;
3930
if (eh->dyn_relocs == NULL)
3933
/* In the shared -Bsymbolic case, discard space allocated for
3934
dynamic pc-relative relocs against symbols which turn out to be
3935
defined in regular objects. For the normal shared case, discard
3936
space for relocs that have become local due to symbol visibility
3941
if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) != 0
3942
&& ((h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0
3945
struct ppc_dyn_relocs **pp;
3947
for (pp = &eh->dyn_relocs; (p = *pp) != NULL; )
3949
p->count -= p->pc_count;
3960
/* For the non-shared case, discard space for relocs against
3961
symbols which turn out to need copy relocs or are not
3964
if ((h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0
3965
&& (((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0
3966
&& (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
3967
|| (htab->elf.dynamic_sections_created
3968
&& (h->root.type == bfd_link_hash_undefweak
3969
|| h->root.type == bfd_link_hash_undefined))))
3971
/* Make sure this symbol is output as a dynamic symbol.
3972
Undefined weak syms won't yet be marked as dynamic. */
3973
if (h->dynindx == -1
3974
&& (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0)
3976
if (! bfd_elf64_link_record_dynamic_symbol (info, h))
3980
/* If that succeeded, we know we'll be keeping all the
3982
if (h->dynindx != -1)
3986
eh->dyn_relocs = NULL;
3991
/* Finally, allocate space. */
3992
for (p = eh->dyn_relocs; p != NULL; p = p->next)
3994
asection *sreloc = elf_section_data (p->sec)->sreloc;
3995
sreloc->_raw_size += p->count * sizeof (Elf64_External_Rela);
4001
/* Find any dynamic relocs that apply to read-only sections. */
4004
readonly_dynrelocs (h, inf)
4005
struct elf_link_hash_entry *h;
4008
struct ppc_link_hash_entry *eh;
4009
struct ppc_dyn_relocs *p;
4011
if (h->root.type == bfd_link_hash_warning)
4012
h = (struct elf_link_hash_entry *) h->root.u.i.link;
4014
eh = (struct ppc_link_hash_entry *) h;
4015
for (p = eh->dyn_relocs; p != NULL; p = p->next)
4017
asection *s = p->sec->output_section;
4019
if (s != NULL && (s->flags & SEC_READONLY) != 0)
4021
struct bfd_link_info *info = (struct bfd_link_info *) inf;
4023
info->flags |= DF_TEXTREL;
4025
/* Not an error, just cut short the traversal. */
4032
/* Set the sizes of the dynamic sections. */
4035
ppc64_elf_size_dynamic_sections (output_bfd, info)
4036
bfd *output_bfd ATTRIBUTE_UNUSED;
4037
struct bfd_link_info *info;
4039
struct ppc_link_hash_table *htab;
4045
htab = ppc_hash_table (info);
4046
dynobj = htab->elf.dynobj;
4050
if (htab->elf.dynamic_sections_created)
4052
/* Set the contents of the .interp section to the interpreter. */
4055
s = bfd_get_section_by_name (dynobj, ".interp");
4058
s->_raw_size = sizeof ELF_DYNAMIC_INTERPRETER;
4059
s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
4063
/* Set up .got offsets for local syms, and space for local dynamic
4065
for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
4067
bfd_signed_vma *local_got;
4068
bfd_signed_vma *end_local_got;
4069
bfd_size_type locsymcount;
4070
Elf_Internal_Shdr *symtab_hdr;
4073
if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour)
4076
for (s = ibfd->sections; s != NULL; s = s->next)
4078
struct ppc_dyn_relocs *p;
4080
for (p = *((struct ppc_dyn_relocs **)
4081
&elf_section_data (s)->local_dynrel);
4085
if (!bfd_is_abs_section (p->sec)
4086
&& bfd_is_abs_section (p->sec->output_section))
4088
/* Input section has been discarded, either because
4089
it is a copy of a linkonce section or due to
4090
linker script /DISCARD/, so we'll be discarding
4093
else if (p->count != 0)
4095
srel = elf_section_data (p->sec)->sreloc;
4096
srel->_raw_size += p->count * sizeof (Elf64_External_Rela);
4097
if ((p->sec->output_section->flags & SEC_READONLY) != 0)
4098
info->flags |= DF_TEXTREL;
4103
local_got = elf_local_got_refcounts (ibfd);
4107
symtab_hdr = &elf_tdata (ibfd)->symtab_hdr;
4108
locsymcount = symtab_hdr->sh_info;
4109
end_local_got = local_got + locsymcount;
4111
srel = htab->srelgot;
4112
for (; local_got < end_local_got; ++local_got)
4116
*local_got = s->_raw_size;
4119
srel->_raw_size += sizeof (Elf64_External_Rela);
4122
*local_got = (bfd_vma) -1;
4126
if (!edit_opd (output_bfd, info))
4129
/* Allocate global sym .plt and .got entries, and space for global
4130
sym dynamic relocs. */
4131
elf_link_hash_traverse (&htab->elf, allocate_dynrelocs, (PTR) info);
4133
/* We now have determined the sizes of the various dynamic sections.
4134
Allocate memory for them. */
4136
for (s = dynobj->sections; s != NULL; s = s->next)
4138
if ((s->flags & SEC_LINKER_CREATED) == 0)
4141
if (s == htab->sbrlt || s == htab->srelbrlt)
4142
/* These haven't been allocated yet; don't strip. */
4144
else if (s == htab->splt
4146
|| s == htab->sglink)
4148
/* Strip this section if we don't need it; see the
4151
else if (strncmp (bfd_get_section_name (dynobj, s), ".rela", 5) == 0)
4153
if (s->_raw_size == 0)
4155
/* If we don't need this section, strip it from the
4156
output file. This is mostly to handle .rela.bss and
4157
.rela.plt. We must create both sections in
4158
create_dynamic_sections, because they must be created
4159
before the linker maps input sections to output
4160
sections. The linker does that before
4161
adjust_dynamic_symbol is called, and it is that
4162
function which decides whether anything needs to go
4163
into these sections. */
4167
if (s != htab->srelplt)
4170
/* We use the reloc_count field as a counter if we need
4171
to copy relocs into the output file. */
4177
/* It's not one of our sections, so don't allocate space. */
4181
if (s->_raw_size == 0)
4183
_bfd_strip_section_from_output (info, s);
4187
/* .plt is in the bss section. We don't initialise it. */
4188
if ((s->flags & SEC_LOAD) == 0)
4191
/* Allocate memory for the section contents. We use bfd_zalloc
4192
here in case unused entries are not reclaimed before the
4193
section's contents are written out. This should not happen,
4194
but this way if it does, we get a R_PPC64_NONE reloc instead
4196
s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->_raw_size);
4197
if (s->contents == NULL)
4201
if (htab->elf.dynamic_sections_created)
4203
/* Add some entries to the .dynamic section. We fill in the
4204
values later, in ppc64_elf_finish_dynamic_sections, but we
4205
must add the entries now so that we get the correct size for
4206
the .dynamic section. The DT_DEBUG entry is filled in by the
4207
dynamic linker and used by the debugger. */
4208
#define add_dynamic_entry(TAG, VAL) \
4209
bfd_elf64_add_dynamic_entry (info, (bfd_vma) (TAG), (bfd_vma) (VAL))
4213
if (!add_dynamic_entry (DT_DEBUG, 0))
4217
if (htab->splt != NULL && htab->splt->_raw_size != 0)
4219
if (!add_dynamic_entry (DT_PLTGOT, 0)
4220
|| !add_dynamic_entry (DT_PLTRELSZ, 0)
4221
|| !add_dynamic_entry (DT_PLTREL, DT_RELA)
4222
|| !add_dynamic_entry (DT_JMPREL, 0)
4223
|| !add_dynamic_entry (DT_PPC64_GLINK, 0))
4229
if (!add_dynamic_entry (DT_PPC64_OPD, 0)
4230
|| !add_dynamic_entry (DT_PPC64_OPDSZ, 0))
4236
if (!add_dynamic_entry (DT_RELA, 0)
4237
|| !add_dynamic_entry (DT_RELASZ, 0)
4238
|| !add_dynamic_entry (DT_RELAENT, sizeof (Elf64_External_Rela)))
4241
/* If any dynamic relocs apply to a read-only section,
4242
then we need a DT_TEXTREL entry. */
4243
if ((info->flags & DF_TEXTREL) == 0)
4244
elf_link_hash_traverse (&htab->elf, readonly_dynrelocs,
4247
if ((info->flags & DF_TEXTREL) != 0)
4249
if (!add_dynamic_entry (DT_TEXTREL, 0))
4254
#undef add_dynamic_entry
4259
/* Determine the type of stub needed, if any, for a call. */
4261
static INLINE enum ppc_stub_type
4262
ppc_type_of_stub (input_sec, rel, hash, destination)
4263
asection *input_sec;
4264
const Elf_Internal_Rela *rel;
4265
struct ppc_link_hash_entry **hash;
4266
bfd_vma destination;
4268
struct ppc_link_hash_entry *h = *hash;
4270
bfd_vma branch_offset;
4271
bfd_vma max_branch_offset;
4272
unsigned int r_type;
4277
&& h->oh->plt.offset != (bfd_vma) -1
4278
&& h->oh->dynindx != -1)
4280
*hash = (struct ppc_link_hash_entry *) h->oh;
4281
return ppc_stub_plt_call;
4284
if (h->elf.root.type == bfd_link_hash_undefweak
4285
|| h->elf.root.type == bfd_link_hash_undefined)
4286
return ppc_stub_none;
4289
/* Determine where the call point is. */
4290
location = (input_sec->output_offset
4291
+ input_sec->output_section->vma
4294
branch_offset = destination - location;
4295
r_type = ELF64_R_TYPE (rel->r_info);
4297
/* Determine if a long branch stub is needed. */
4298
max_branch_offset = 1 << 25;
4299
if (r_type != (unsigned int) R_PPC64_REL24)
4300
max_branch_offset = 1 << 15;
4302
if (branch_offset + max_branch_offset >= 2 * max_branch_offset)
4303
/* We need a stub. Figure out whether a long_branch or plt_branch
4305
return ppc_stub_long_branch;
4307
return ppc_stub_none;
4310
/* Build a .plt call stub. */
4313
build_plt_stub (obfd, p, offset, glink)
4319
#define PPC_LO(v) ((v) & 0xffff)
4320
#define PPC_HI(v) (((v) >> 16) & 0xffff)
4321
#define PPC_HA(v) PPC_HI ((v) + 0x8000)
4324
bfd_put_32 (obfd, LD_R2_40R1, p), p += 4;
4325
bfd_put_32 (obfd, ADDIS_R12_R2 | PPC_HA (offset), p), p += 4;
4327
bfd_put_32 (obfd, STD_R2_40R1, p), p += 4;
4328
bfd_put_32 (obfd, LD_R11_0R12 | PPC_LO (offset), p), p += 4;
4329
if (PPC_HA (offset + 8) != PPC_HA (offset))
4330
bfd_put_32 (obfd, ADDIS_R12_R12_1, p), p += 4;
4332
bfd_put_32 (obfd, LD_R2_0R12 | PPC_LO (offset), p), p += 4;
4333
if (PPC_HA (offset + 8) != PPC_HA (offset))
4334
bfd_put_32 (obfd, ADDIS_R12_R12_1, p), p += 4;
4336
bfd_put_32 (obfd, MTCTR_R11, p), p += 4;
4337
bfd_put_32 (obfd, LD_R11_0R12 | PPC_LO (offset), p), p += 4;
4338
bfd_put_32 (obfd, BCTR, p), p += 4;
4343
ppc_build_one_stub (gen_entry, in_arg)
4344
struct bfd_hash_entry *gen_entry;
4347
struct ppc_stub_hash_entry *stub_entry;
4348
struct ppc_branch_hash_entry *br_entry;
4349
struct bfd_link_info *info;
4350
struct ppc_link_hash_table *htab;
4359
/* Massage our args to the form they really have. */
4360
stub_entry = (struct ppc_stub_hash_entry *) gen_entry;
4361
info = (struct bfd_link_info *) in_arg;
4363
htab = ppc_hash_table (info);
4364
stub_sec = stub_entry->stub_sec;
4366
/* Make a note of the offset within the stubs for this entry. */
4367
stub_entry->stub_offset = stub_sec->_cooked_size;
4368
loc = stub_sec->contents + stub_entry->stub_offset;
4370
stub_bfd = stub_sec->owner;
4372
switch (stub_entry->stub_type)
4374
case ppc_stub_long_branch:
4375
/* Branches are relative. This is where we are going to. */
4376
off = (stub_entry->target_value
4377
+ stub_entry->target_section->output_offset
4378
+ stub_entry->target_section->output_section->vma);
4380
/* And this is where we are coming from. */
4381
off -= (stub_entry->stub_offset
4382
+ stub_sec->output_offset
4383
+ stub_sec->output_section->vma);
4385
BFD_ASSERT (off + (1 << 25) < (bfd_vma) (1 << 26));
4387
bfd_put_32 (stub_bfd, (bfd_vma) B_DOT | (off & 0x3fffffc), loc);
4391
case ppc_stub_plt_branch:
4392
br_entry = ppc_branch_hash_lookup (&htab->branch_hash_table,
4393
stub_entry->root.string + 9,
4395
if (br_entry == NULL)
4397
(*_bfd_error_handler) (_("can't find branch stub `%s'"),
4398
stub_entry->root.string + 9);
4399
htab->stub_error = true;
4403
off = (stub_entry->target_value
4404
+ stub_entry->target_section->output_offset
4405
+ stub_entry->target_section->output_section->vma);
4407
bfd_put_64 (htab->sbrlt->owner, off,
4408
htab->sbrlt->contents + br_entry->offset);
4412
/* Create a reloc for the branch lookup table entry. */
4413
Elf_Internal_Rela rela;
4414
Elf64_External_Rela *r;
4416
rela.r_offset = (br_entry->offset
4417
+ htab->sbrlt->output_offset
4418
+ htab->sbrlt->output_section->vma);
4419
rela.r_info = ELF64_R_INFO (0, R_PPC64_RELATIVE);
4420
rela.r_addend = off;
4422
r = (Elf64_External_Rela *) htab->srelbrlt->contents;
4423
r += htab->srelbrlt->reloc_count++;
4424
bfd_elf64_swap_reloca_out (htab->srelbrlt->owner, &rela, r);
4427
off = (br_entry->offset
4428
+ htab->sbrlt->output_offset
4429
+ htab->sbrlt->output_section->vma
4430
- elf_gp (htab->sbrlt->output_section->owner)
4433
if (off + 0x80000000 > 0xffffffff || (off & 7) != 0)
4435
(*_bfd_error_handler)
4436
(_("linkage table error against `%s'"),
4437
stub_entry->root.string);
4438
bfd_set_error (bfd_error_bad_value);
4439
htab->stub_error = true;
4444
bfd_put_32 (stub_bfd, (bfd_vma) ADDIS_R12_R2 | PPC_HA (indx), loc);
4445
bfd_put_32 (stub_bfd, (bfd_vma) LD_R11_0R12 | PPC_LO (indx), loc + 4);
4446
bfd_put_32 (stub_bfd, (bfd_vma) MTCTR_R11, loc + 8);
4447
bfd_put_32 (stub_bfd, (bfd_vma) BCTR, loc + 12);
4451
case ppc_stub_plt_call:
4452
/* Build the .glink lazy link call stub. */
4453
p = htab->sglink->contents + htab->sglink->_cooked_size;
4454
indx = htab->sglink->reloc_count;
4457
bfd_put_32 (htab->sglink->owner, LI_R0_0 | indx, p);
4462
bfd_put_32 (htab->sglink->owner, LIS_R0_0 | PPC_HI (indx), p);
4464
bfd_put_32 (htab->sglink->owner, ORI_R0_R0_0 | PPC_LO (indx), p);
4467
bfd_put_32 (htab->sglink->owner,
4468
B_DOT | ((htab->sglink->contents - p) & 0x3fffffc), p);
4470
htab->sglink->_cooked_size = p - htab->sglink->contents;
4471
htab->sglink->reloc_count += 1;
4473
/* Do the best we can for shared libraries built without
4474
exporting ".foo" for each "foo". This can happen when symbol
4475
versioning scripts strip all bar a subset of symbols. */
4476
if (stub_entry->h->oh->root.type != bfd_link_hash_defined
4477
&& stub_entry->h->oh->root.type != bfd_link_hash_defweak)
4479
/* Point the symbol at the stub. There may be multiple stubs,
4480
we don't really care; The main thing is to make this sym
4481
defined somewhere. */
4482
stub_entry->h->oh->root.type = bfd_link_hash_defined;
4483
stub_entry->h->oh->root.u.def.section = stub_entry->stub_sec;
4484
stub_entry->h->oh->root.u.def.value = stub_entry->stub_offset;
4487
/* Now build the stub. */
4488
off = stub_entry->h->elf.plt.offset;
4489
if (off >= (bfd_vma) -2)
4492
off &= ~ (bfd_vma) 1;
4493
off += (htab->splt->output_offset
4494
+ htab->splt->output_section->vma
4495
- elf_gp (htab->splt->output_section->owner)
4498
if (off + 0x80000000 > 0xffffffff || (off & 7) != 0)
4500
(*_bfd_error_handler)
4501
(_("linkage table error against `%s'"),
4502
stub_entry->h->elf.root.root.string);
4503
bfd_set_error (bfd_error_bad_value);
4504
htab->stub_error = true;
4508
p = build_plt_stub (stub_bfd, loc, (int) off, 0);
4517
stub_sec->_cooked_size += size;
4521
/* As above, but don't actually build the stub. Just bump offset so
4522
we know stub section sizes, and select plt_branch stubs where
4523
long_branch stubs won't do. */
4526
ppc_size_one_stub (gen_entry, in_arg)
4527
struct bfd_hash_entry *gen_entry;
4530
struct ppc_stub_hash_entry *stub_entry;
4531
struct ppc_link_hash_table *htab;
4535
/* Massage our args to the form they really have. */
4536
stub_entry = (struct ppc_stub_hash_entry *) gen_entry;
4537
htab = (struct ppc_link_hash_table *) in_arg;
4539
if (stub_entry->stub_type == ppc_stub_plt_call)
4541
off = stub_entry->h->elf.plt.offset & ~(bfd_vma) 1;
4542
off += (htab->splt->output_offset
4543
+ htab->splt->output_section->vma
4544
- elf_gp (htab->splt->output_section->owner)
4548
if (PPC_HA ((int) off + 16) != PPC_HA ((int) off))
4553
/* ppc_stub_long_branch or ppc_stub_plt_branch. */
4554
stub_entry->stub_type = ppc_stub_long_branch;
4557
off = (stub_entry->target_value
4558
+ stub_entry->target_section->output_offset
4559
+ stub_entry->target_section->output_section->vma);
4560
off -= (stub_entry->stub_sec->_raw_size
4561
+ stub_entry->stub_sec->output_offset
4562
+ stub_entry->stub_sec->output_section->vma);
4564
if (off + (1 << 25) >= (bfd_vma) (1 << 26))
4566
struct ppc_branch_hash_entry *br_entry;
4568
br_entry = ppc_branch_hash_lookup (&htab->branch_hash_table,
4569
stub_entry->root.string + 9,
4571
if (br_entry == NULL)
4573
(*_bfd_error_handler) (_("can't build branch stub `%s'"),
4574
stub_entry->root.string + 9);
4575
htab->stub_error = true;
4579
if (br_entry->iter != htab->stub_iteration)
4581
br_entry->iter = htab->stub_iteration;
4582
br_entry->offset = htab->sbrlt->_raw_size;
4583
htab->sbrlt->_raw_size += 8;
4585
stub_entry->stub_type = ppc_stub_plt_branch;
4590
stub_entry->stub_sec->_raw_size += size;
4594
/* Set up various things so that we can make a list of input sections
4595
for each output section included in the link. Returns -1 on error,
4596
0 when no stubs will be needed, and 1 on success. */
4599
ppc64_elf_setup_section_lists (output_bfd, info)
4601
struct bfd_link_info *info;
4604
int top_id, top_index;
4606
asection **input_list, **list;
4608
struct ppc_link_hash_table *htab = ppc_hash_table (info);
4610
if (htab->elf.root.creator->flavour != bfd_target_elf_flavour
4611
|| htab->sbrlt == NULL)
4614
/* Find the top input section id. */
4615
for (input_bfd = info->input_bfds, top_id = 0;
4617
input_bfd = input_bfd->link_next)
4619
for (section = input_bfd->sections;
4621
section = section->next)
4623
if (top_id < section->id)
4624
top_id = section->id;
4628
amt = sizeof (struct map_stub) * (top_id + 1);
4629
htab->stub_group = (struct map_stub *) bfd_zmalloc (amt);
4630
if (htab->stub_group == NULL)
4633
/* We can't use output_bfd->section_count here to find the top output
4634
section index as some sections may have been removed, and
4635
_bfd_strip_section_from_output doesn't renumber the indices. */
4636
for (section = output_bfd->sections, top_index = 0;
4638
section = section->next)
4640
if (top_index < section->index)
4641
top_index = section->index;
4644
htab->top_index = top_index;
4645
amt = sizeof (asection *) * (top_index + 1);
4646
input_list = (asection **) bfd_malloc (amt);
4647
htab->input_list = input_list;
4648
if (input_list == NULL)
4651
/* For sections we aren't interested in, mark their entries with a
4652
value we can check later. */
4653
list = input_list + top_index;
4655
*list = bfd_abs_section_ptr;
4656
while (list-- != input_list);
4658
for (section = output_bfd->sections;
4660
section = section->next)
4662
if ((section->flags & SEC_CODE) != 0)
4663
input_list[section->index] = NULL;
4669
/* The linker repeatedly calls this function for each input section,
4670
in the order that input sections are linked into output sections.
4671
Build lists of input sections to determine groupings between which
4672
we may insert linker stubs. */
4675
ppc64_elf_next_input_section (info, isec)
4676
struct bfd_link_info *info;
4679
struct ppc_link_hash_table *htab = ppc_hash_table (info);
4681
if (isec->output_section->index <= htab->top_index)
4683
asection **list = htab->input_list + isec->output_section->index;
4684
if (*list != bfd_abs_section_ptr)
4686
/* Steal the link_sec pointer for our list. */
4687
#define PREV_SEC(sec) (htab->stub_group[(sec)->id].link_sec)
4688
/* This happens to make the list in reverse order,
4689
which is what we want. */
4690
PREV_SEC (isec) = *list;
4696
/* See whether we can group stub sections together. Grouping stub
4697
sections may result in fewer stubs. More importantly, we need to
4698
put all .init* and .fini* stubs at the beginning of the .init or
4699
.fini output sections respectively, because glibc splits the
4700
_init and _fini functions into multiple parts. Putting a stub in
4701
the middle of a function is not a good idea. */
4704
group_sections (htab, stub_group_size, stubs_always_before_branch)
4705
struct ppc_link_hash_table *htab;
4706
bfd_size_type stub_group_size;
4707
boolean stubs_always_before_branch;
4709
asection **list = htab->input_list + htab->top_index;
4712
asection *tail = *list;
4713
if (tail == bfd_abs_section_ptr)
4715
while (tail != NULL)
4719
bfd_size_type total;
4722
if (tail->_cooked_size)
4723
total = tail->_cooked_size;
4725
total = tail->_raw_size;
4726
while ((prev = PREV_SEC (curr)) != NULL
4727
&& ((total += curr->output_offset - prev->output_offset)
4731
/* OK, the size from the start of CURR to the end is less
4732
than stub_group_size and thus can be handled by one stub
4733
section. (or the tail section is itself larger than
4734
stub_group_size, in which case we may be toast.) We
4735
should really be keeping track of the total size of stubs
4736
added here, as stubs contribute to the final output
4737
section size. That's a little tricky, and this way will
4738
only break if stubs added make the total size more than
4739
2^25, ie. for the default stub_group_size, if stubs total
4740
more than 2834432 bytes, or over 100000 plt call stubs. */
4743
prev = PREV_SEC (tail);
4744
/* Set up this stub group. */
4745
htab->stub_group[tail->id].link_sec = curr;
4747
while (tail != curr && (tail = prev) != NULL);
4749
/* But wait, there's more! Input sections up to stub_group_size
4750
bytes before the stub section can be handled by it too. */
4751
if (!stubs_always_before_branch)
4755
&& ((total += tail->output_offset - prev->output_offset)
4759
prev = PREV_SEC (tail);
4760
htab->stub_group[tail->id].link_sec = curr;
4766
while (list-- != htab->input_list);
4767
free (htab->input_list);
4771
/* Determine and set the size of the stub section for a final link.
4773
The basic idea here is to examine all the relocations looking for
4774
PC-relative calls to a target that is unreachable with a "bl"
4778
ppc64_elf_size_stubs (output_bfd, stub_bfd, info, group_size,
4779
add_stub_section, layout_sections_again)
4782
struct bfd_link_info *info;
4783
bfd_signed_vma group_size;
4784
asection * (*add_stub_section) PARAMS ((const char *, asection *));
4785
void (*layout_sections_again) PARAMS ((void));
4787
bfd_size_type stub_group_size;
4788
boolean stubs_always_before_branch;
4789
struct ppc_link_hash_table *htab = ppc_hash_table (info);
4791
/* Stash our params away. */
4792
htab->stub_bfd = stub_bfd;
4793
htab->add_stub_section = add_stub_section;
4794
htab->layout_sections_again = layout_sections_again;
4795
stubs_always_before_branch = group_size < 0;
4797
stub_group_size = -group_size;
4799
stub_group_size = group_size;
4800
if (stub_group_size == 1)
4802
/* Default values. */
4803
stub_group_size = 30720000;
4804
if (htab->has_14bit_branch)
4805
stub_group_size = 30000;
4808
group_sections (htab, stub_group_size, stubs_always_before_branch);
4813
unsigned int bfd_indx;
4815
boolean stub_changed;
4817
htab->stub_iteration += 1;
4818
stub_changed = false;
4820
for (input_bfd = info->input_bfds, bfd_indx = 0;
4822
input_bfd = input_bfd->link_next, bfd_indx++)
4824
Elf_Internal_Shdr *symtab_hdr;
4826
Elf_Internal_Sym *local_syms = NULL;
4828
/* We'll need the symbol table in a second. */
4829
symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
4830
if (symtab_hdr->sh_info == 0)
4833
/* Walk over each section attached to the input bfd. */
4834
for (section = input_bfd->sections;
4836
section = section->next)
4838
Elf_Internal_Rela *internal_relocs, *irelaend, *irela;
4840
/* If there aren't any relocs, then there's nothing more
4842
if ((section->flags & SEC_RELOC) == 0
4843
|| section->reloc_count == 0)
4846
/* If this section is a link-once section that will be
4847
discarded, then don't create any stubs. */
4848
if (section->output_section == NULL
4849
|| section->output_section->owner != output_bfd)
4852
/* Get the relocs. */
4854
= _bfd_elf64_link_read_relocs (input_bfd, section, NULL,
4855
(Elf_Internal_Rela *) NULL,
4857
if (internal_relocs == NULL)
4858
goto error_ret_free_local;
4860
/* Now examine each relocation. */
4861
irela = internal_relocs;
4862
irelaend = irela + section->reloc_count;
4863
for (; irela < irelaend; irela++)
4865
unsigned int r_type, r_indx;
4866
enum ppc_stub_type stub_type;
4867
struct ppc_stub_hash_entry *stub_entry;
4870
bfd_vma destination;
4871
struct ppc_link_hash_entry *hash;
4873
const asection *id_sec;
4875
r_type = ELF64_R_TYPE (irela->r_info);
4876
r_indx = ELF64_R_SYM (irela->r_info);
4878
if (r_type >= (unsigned int) R_PPC_max)
4880
bfd_set_error (bfd_error_bad_value);
4881
goto error_ret_free_internal;
4884
/* Only look for stubs on branch instructions. */
4885
if (r_type != (unsigned int) R_PPC64_REL24
4886
&& r_type != (unsigned int) R_PPC64_REL14
4887
&& r_type != (unsigned int) R_PPC64_REL14_BRTAKEN
4888
&& r_type != (unsigned int) R_PPC64_REL14_BRNTAKEN)
4891
/* Now determine the call target, its name, value,
4897
if (r_indx < symtab_hdr->sh_info)
4899
/* It's a local symbol. */
4900
Elf_Internal_Sym *sym;
4901
Elf_Internal_Shdr *hdr;
4903
if (local_syms == NULL)
4906
= (Elf_Internal_Sym *) symtab_hdr->contents;
4907
if (local_syms == NULL)
4909
= bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
4910
symtab_hdr->sh_info, 0,
4912
if (local_syms == NULL)
4913
goto error_ret_free_internal;
4915
sym = local_syms + r_indx;
4916
hdr = elf_elfsections (input_bfd)[sym->st_shndx];
4917
sym_sec = hdr->bfd_section;
4918
if (ELF_ST_TYPE (sym->st_info) != STT_SECTION)
4919
sym_value = sym->st_value;
4920
destination = (sym_value + irela->r_addend
4921
+ sym_sec->output_offset
4922
+ sym_sec->output_section->vma);
4926
/* It's an external symbol. */
4929
e_indx = r_indx - symtab_hdr->sh_info;
4930
hash = ((struct ppc_link_hash_entry *)
4931
elf_sym_hashes (input_bfd)[e_indx]);
4933
while (hash->elf.root.type == bfd_link_hash_indirect
4934
|| hash->elf.root.type == bfd_link_hash_warning)
4935
hash = ((struct ppc_link_hash_entry *)
4936
hash->elf.root.u.i.link);
4938
if (hash->elf.root.type == bfd_link_hash_defined
4939
|| hash->elf.root.type == bfd_link_hash_defweak)
4941
sym_sec = hash->elf.root.u.def.section;
4942
sym_value = hash->elf.root.u.def.value;
4943
if (sym_sec->output_section != NULL)
4944
destination = (sym_value + irela->r_addend
4945
+ sym_sec->output_offset
4946
+ sym_sec->output_section->vma);
4948
else if (hash->elf.root.type == bfd_link_hash_undefweak)
4950
else if (hash->elf.root.type == bfd_link_hash_undefined)
4954
bfd_set_error (bfd_error_bad_value);
4955
goto error_ret_free_internal;
4959
/* Determine what (if any) linker stub is needed. */
4960
stub_type = ppc_type_of_stub (section, irela, &hash,
4962
if (stub_type == ppc_stub_none)
4965
/* Support for grouping stub sections. */
4966
id_sec = htab->stub_group[section->id].link_sec;
4968
/* Get the name of this stub. */
4969
stub_name = ppc_stub_name (id_sec, sym_sec, hash, irela);
4971
goto error_ret_free_internal;
4973
stub_entry = ppc_stub_hash_lookup (&htab->stub_hash_table,
4974
stub_name, false, false);
4975
if (stub_entry != NULL)
4977
/* The proper stub has already been created. */
4982
stub_entry = ppc_add_stub (stub_name, section, htab);
4983
if (stub_entry == NULL)
4986
error_ret_free_internal:
4987
if (elf_section_data (section)->relocs == NULL)
4988
free (internal_relocs);
4989
error_ret_free_local:
4990
if (local_syms != NULL
4991
&& (symtab_hdr->contents
4992
!= (unsigned char *) local_syms))
4997
stub_entry->target_value = sym_value;
4998
stub_entry->target_section = sym_sec;
4999
stub_entry->stub_type = stub_type;
5000
stub_entry->h = hash;
5001
stub_changed = true;
5004
/* We're done with the internal relocs, free them. */
5005
if (elf_section_data (section)->relocs != internal_relocs)
5006
free (internal_relocs);
5009
if (local_syms != NULL
5010
&& symtab_hdr->contents != (unsigned char *) local_syms)
5012
if (!info->keep_memory)
5015
symtab_hdr->contents = (unsigned char *) local_syms;
5022
/* OK, we've added some stubs. Find out the new size of the
5024
for (stub_sec = htab->stub_bfd->sections;
5026
stub_sec = stub_sec->next)
5028
stub_sec->_raw_size = 0;
5029
stub_sec->_cooked_size = 0;
5031
htab->sbrlt->_raw_size = 0;
5032
htab->sbrlt->_cooked_size = 0;
5034
bfd_hash_traverse (&htab->stub_hash_table, ppc_size_one_stub, htab);
5036
/* Ask the linker to do its stuff. */
5037
(*htab->layout_sections_again) ();
5040
/* It would be nice to strip .branch_lt from the output if the
5041
section is empty, but it's too late. If we strip sections here,
5042
the dynamic symbol table is corrupted since the section symbol
5043
for the stripped section isn't written. */
5048
/* Called after we have determined section placement. If sections
5049
move, we'll be called again. Provide a value for TOCstart. */
5052
ppc64_elf_toc (obfd)
5058
/* The TOC consists of sections .got, .toc, .tocbss, .plt in that
5059
order. The TOC starts where the first of these sections starts. */
5060
s = bfd_get_section_by_name (obfd, ".got");
5062
s = bfd_get_section_by_name (obfd, ".toc");
5064
s = bfd_get_section_by_name (obfd, ".tocbss");
5066
s = bfd_get_section_by_name (obfd, ".plt");
5069
/* This may happen for
5070
o references to TOC base (SYM@toc / TOC[tc0]) without a
5073
o --gc-sections and empty TOC sections
5075
FIXME: Warn user? */
5077
/* Look for a likely section. We probably won't even be
5079
for (s = obfd->sections; s != NULL; s = s->next)
5080
if ((s->flags & (SEC_ALLOC | SEC_SMALL_DATA | SEC_READONLY))
5081
== (SEC_ALLOC | SEC_SMALL_DATA))
5084
for (s = obfd->sections; s != NULL; s = s->next)
5085
if ((s->flags & (SEC_ALLOC | SEC_SMALL_DATA))
5086
== (SEC_ALLOC | SEC_SMALL_DATA))
5089
for (s = obfd->sections; s != NULL; s = s->next)
5090
if ((s->flags & (SEC_ALLOC | SEC_READONLY)) == SEC_ALLOC)
5093
for (s = obfd->sections; s != NULL; s = s->next)
5094
if ((s->flags & SEC_ALLOC) == SEC_ALLOC)
5100
TOCstart = s->output_section->vma + s->output_offset;
5105
/* Build all the stubs associated with the current output file.
5106
The stubs are kept in a hash table attached to the main linker
5107
hash table. This function is called via gldelf64ppc_finish. */
5110
ppc64_elf_build_stubs (info)
5111
struct bfd_link_info *info;
5113
struct ppc_link_hash_table *htab = ppc_hash_table (info);
5118
for (stub_sec = htab->stub_bfd->sections;
5120
stub_sec = stub_sec->next)
5124
/* Allocate memory to hold the linker stubs. */
5125
size = stub_sec->_raw_size;
5128
stub_sec->contents = (bfd_byte *) bfd_zalloc (htab->stub_bfd, size);
5129
if (stub_sec->contents == NULL)
5132
stub_sec->_cooked_size = 0;
5135
if (htab->splt != NULL)
5137
/* Build the .glink plt call stub. */
5138
plt_r2 = (htab->splt->output_offset
5139
+ htab->splt->output_section->vma
5140
- elf_gp (htab->splt->output_section->owner)
5142
p = htab->sglink->contents;
5143
p = build_plt_stub (htab->sglink->owner, p, (int) plt_r2, 1);
5144
while (p - htab->sglink->contents < GLINK_CALL_STUB_SIZE)
5146
bfd_put_32 (htab->sglink->owner, NOP, p);
5149
htab->sglink->_cooked_size = p - htab->sglink->contents;
5151
/* Use reloc_count to count entries. */
5152
htab->sglink->reloc_count = 0;
5155
if (htab->sbrlt->_raw_size != 0)
5157
htab->sbrlt->contents = (bfd_byte *) bfd_zalloc (htab->sbrlt->owner,
5158
htab->sbrlt->_raw_size);
5159
if (htab->sbrlt->contents == NULL)
5163
/* Build the stubs as directed by the stub hash table. */
5164
bfd_hash_traverse (&htab->stub_hash_table, ppc_build_one_stub, info);
5165
htab->sglink->reloc_count = 0;
5167
for (stub_sec = htab->stub_bfd->sections;
5169
stub_sec = stub_sec->next)
5171
if (stub_sec->_raw_size != stub_sec->_cooked_size)
5175
if (stub_sec != NULL
5176
|| htab->sglink->_raw_size != htab->sglink->_cooked_size)
5178
htab->stub_error = true;
5179
(*_bfd_error_handler) (_("stubs don't match calculated size"));
5182
return !htab->stub_error;
5185
/* The RELOCATE_SECTION function is called by the ELF backend linker
5186
to handle the relocations for a section.
5188
The relocs are always passed as Rela structures; if the section
5189
actually uses Rel structures, the r_addend field will always be
5192
This function is responsible for adjust the section contents as
5193
necessary, and (if using Rela relocs and generating a
5194
relocateable output file) adjusting the reloc addend as
5197
This function does not have to worry about setting the reloc
5198
address or the reloc symbol index.
5200
LOCAL_SYMS is a pointer to the swapped in local symbols.
5202
LOCAL_SECTIONS is an array giving the section in the input file
5203
corresponding to the st_shndx field of each local symbol.
5205
The global hash table entry for the global symbols can be found
5206
via elf_sym_hashes (input_bfd).
5208
When generating relocateable output, this function must handle
5209
STB_LOCAL/STT_SECTION symbols specially. The output symbol is
5210
going to be the section symbol corresponding to the output
5211
section, which means that the addend must be adjusted
5215
ppc64_elf_relocate_section (output_bfd, info, input_bfd, input_section,
5216
contents, relocs, local_syms, local_sections)
5218
struct bfd_link_info *info;
5220
asection *input_section;
5222
Elf_Internal_Rela *relocs;
5223
Elf_Internal_Sym *local_syms;
5224
asection **local_sections;
5226
struct ppc_link_hash_table *htab;
5227
Elf_Internal_Shdr *symtab_hdr;
5228
struct elf_link_hash_entry **sym_hashes;
5229
Elf_Internal_Rela *rel;
5230
Elf_Internal_Rela *relend;
5231
bfd_vma *local_got_offsets;
5235
/* Disabled until we sort out how ld should choose 'y' vs 'at'. */
5236
boolean is_power4 = false;
5238
if (info->relocateable)
5241
/* Initialize howto table if needed. */
5242
if (!ppc64_elf_howto_table[R_PPC64_ADDR32])
5245
htab = ppc_hash_table (info);
5246
local_got_offsets = elf_local_got_offsets (input_bfd);
5247
TOCstart = elf_gp (output_bfd);
5248
symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
5249
sym_hashes = elf_sym_hashes (input_bfd);
5250
is_opd = elf_section_data (input_section)->tdata != NULL;
5253
relend = relocs + input_section->reloc_count;
5254
for (; rel < relend; rel++)
5256
enum elf_ppc_reloc_type r_type;
5259
bfd_reloc_status_type r;
5260
Elf_Internal_Sym *sym;
5262
struct elf_link_hash_entry *h;
5263
struct elf_link_hash_entry *fdh;
5264
const char *sym_name;
5265
unsigned long r_symndx;
5267
boolean unresolved_reloc;
5270
struct ppc_stub_hash_entry *stub_entry;
5271
bfd_vma max_br_offset;
5274
r_type = (enum elf_ppc_reloc_type) ELF64_R_TYPE (rel->r_info);
5275
r_symndx = ELF64_R_SYM (rel->r_info);
5276
offset = rel->r_offset;
5277
addend = rel->r_addend;
5278
r = bfd_reloc_other;
5279
sym = (Elf_Internal_Sym *) 0;
5280
sec = (asection *) 0;
5281
h = (struct elf_link_hash_entry *) 0;
5282
sym_name = (const char *) 0;
5283
unresolved_reloc = false;
5286
if (r_type == R_PPC64_TOC)
5288
/* Relocation value is TOC base. Symbol is ignored. */
5289
relocation = TOCstart + TOC_BASE_OFF;
5291
else if (r_symndx < symtab_hdr->sh_info)
5293
/* It's a local symbol. */
5294
sym = local_syms + r_symndx;
5295
sec = local_sections[r_symndx];
5296
sym_name = "<local symbol>";
5298
relocation = _bfd_elf_rela_local_sym (output_bfd, sym, sec, rel);
5299
/* rel may have changed, update our copy of addend. */
5300
addend = rel->r_addend;
5302
if (elf_section_data (sec) != NULL)
5304
long *opd_sym_adjust;
5306
opd_sym_adjust = (long *) elf_section_data (sec)->tdata;
5307
if (opd_sym_adjust != NULL && sym->st_value % 24 == 0)
5308
relocation += opd_sym_adjust[sym->st_value / 24];
5313
/* It's a global symbol. */
5314
h = sym_hashes[r_symndx - symtab_hdr->sh_info];
5315
while (h->root.type == bfd_link_hash_indirect
5316
|| h->root.type == bfd_link_hash_warning)
5317
h = (struct elf_link_hash_entry *) h->root.u.i.link;
5318
sym_name = h->root.root.string;
5320
if (h->root.type == bfd_link_hash_defined
5321
|| h->root.type == bfd_link_hash_defweak)
5323
sec = h->root.u.def.section;
5324
if (sec->output_section == NULL)
5325
/* Set a flag that will be cleared later if we find a
5326
relocation value for this symbol. output_section
5327
is typically NULL for symbols satisfied by a shared
5329
unresolved_reloc = true;
5331
relocation = (h->root.u.def.value
5332
+ sec->output_section->vma
5333
+ sec->output_offset);
5335
else if (h->root.type == bfd_link_hash_undefweak)
5337
else if (info->shared
5338
&& (!info->symbolic || info->allow_shlib_undefined)
5339
&& !info->no_undefined
5340
&& ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
5344
if (! ((*info->callbacks->undefined_symbol)
5345
(info, h->root.root.string, input_bfd, input_section,
5346
offset, (!info->shared
5347
|| info->no_undefined
5348
|| ELF_ST_VISIBILITY (h->other)))))
5354
/* First handle relocations that tweak non-addend part of insn. */
5361
/* Branch taken prediction relocations. */
5362
case R_PPC64_ADDR14_BRTAKEN:
5363
case R_PPC64_REL14_BRTAKEN:
5364
insn = 0x01 << 21; /* 'y' or 't' bit, lowest bit of BO field. */
5367
/* Branch not taken prediction relocations. */
5368
case R_PPC64_ADDR14_BRNTAKEN:
5369
case R_PPC64_REL14_BRNTAKEN:
5370
insn |= bfd_get_32 (output_bfd, contents + offset) & ~(0x01 << 21);
5373
/* Set 'a' bit. This is 0b00010 in BO field for branch
5374
on CR(BI) insns (BO == 001at or 011at), and 0b01000
5375
for branch on CTR insns (BO == 1a00t or 1a01t). */
5376
if ((insn & (0x14 << 21)) == (0x04 << 21))
5378
else if ((insn & (0x14 << 21)) == (0x10 << 21))
5386
+ input_section->output_offset
5387
+ input_section->output_section->vma);
5389
/* Invert 'y' bit if not the default. */
5390
if ((bfd_signed_vma) (relocation + addend - from) < 0)
5394
bfd_put_32 (output_bfd, (bfd_vma) insn, contents + offset);
5398
/* A REL24 branching to a linkage function is followed by a
5399
nop. We replace the nop with a ld in order to restore
5400
the TOC base pointer. Only calls to shared objects need
5401
to alter the TOC base. These are recognized by their
5402
need for a PLT entry. */
5404
&& (fdh = ((struct ppc_link_hash_entry *) h)->oh) != NULL
5405
&& fdh->plt.offset != (bfd_vma) -1
5406
&& (stub_entry = ppc_get_stub_entry (input_section, sec, fdh,
5407
rel, htab)) != NULL)
5409
boolean can_plt_call = 0;
5411
if (offset + 8 <= input_section->_cooked_size)
5413
insn = bfd_get_32 (input_bfd, contents + offset + 4);
5415
|| insn == CROR_151515 || insn == CROR_313131)
5417
bfd_put_32 (input_bfd, (bfd_vma) LD_R2_40R1,
5418
contents + offset + 4);
5425
/* If this is a plain branch rather than a branch
5426
and link, don't require a nop. */
5427
insn = bfd_get_32 (input_bfd, contents + offset);
5428
if ((insn & 1) == 0)
5434
relocation = (stub_entry->stub_offset
5435
+ stub_entry->stub_sec->output_offset
5436
+ stub_entry->stub_sec->output_section->vma);
5438
unresolved_reloc = false;
5443
&& h->root.type == bfd_link_hash_undefweak
5447
/* Tweak calls to undefined weak functions to point at a
5448
blr. We can thus call a weak function without first
5449
checking whether the function is defined. We have a
5450
blr at the end of .sfpr. */
5451
BFD_ASSERT (htab->sfpr->_raw_size != 0);
5452
relocation = (htab->sfpr->_raw_size - 4
5453
+ htab->sfpr->output_offset
5454
+ htab->sfpr->output_section->vma);
5456
+ input_section->output_offset
5457
+ input_section->output_section->vma);
5459
/* But let's not be silly about it. If the blr isn't in
5460
reach, just go to the next instruction. */
5461
if (relocation - from + (1 << 25) >= (1 << 26)
5462
|| htab->sfpr->_raw_size == 0)
5463
relocation = from + 4;
5472
(*_bfd_error_handler)
5473
(_("%s: unknown relocation type %d for symbol %s"),
5474
bfd_archive_filename (input_bfd), (int) r_type, sym_name);
5476
bfd_set_error (bfd_error_bad_value);
5481
case R_PPC_GNU_VTINHERIT:
5482
case R_PPC_GNU_VTENTRY:
5485
/* GOT16 relocations. Like an ADDR16 using the symbol's
5486
address in the GOT as relocation value instead of the
5487
symbols value itself. Also, create a GOT entry for the
5488
symbol and put the symbol value there. */
5490
case R_PPC64_GOT16_LO:
5491
case R_PPC64_GOT16_HI:
5492
case R_PPC64_GOT16_HA:
5493
case R_PPC64_GOT16_DS:
5494
case R_PPC64_GOT16_LO_DS:
5496
/* Relocation is to the entry for this symbol in the global
5500
if (htab->sgot == NULL)
5507
off = h->got.offset;
5508
dyn = htab->elf.dynamic_sections_created;
5509
if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info, h)
5513
|| (h->elf_link_hash_flags
5514
& ELF_LINK_FORCED_LOCAL))
5515
&& (h->elf_link_hash_flags
5516
& ELF_LINK_HASH_DEF_REGULAR)))
5518
/* This is actually a static link, or it is a
5519
-Bsymbolic link and the symbol is defined
5520
locally, or the symbol was forced to be local
5521
because of a version file. We must initialize
5522
this entry in the global offset table. Since the
5523
offset must always be a multiple of 8, we use the
5524
least significant bit to record whether we have
5525
initialized it already.
5527
When doing a dynamic link, we create a .rel.got
5528
relocation entry to initialize the value. This
5529
is done in the finish_dynamic_symbol routine. */
5534
bfd_put_64 (output_bfd, relocation,
5535
htab->sgot->contents + off);
5540
unresolved_reloc = false;
5544
if (local_got_offsets == NULL)
5547
off = local_got_offsets[r_symndx];
5549
/* The offset must always be a multiple of 8. We use
5550
the least significant bit to record whether we have
5551
already processed this entry. */
5556
bfd_put_64 (output_bfd, relocation,
5557
htab->sgot->contents + off);
5561
Elf_Internal_Rela outrel;
5562
Elf64_External_Rela *loc;
5564
/* We need to generate a R_PPC64_RELATIVE reloc
5565
for the dynamic linker. */
5566
outrel.r_offset = (htab->sgot->output_section->vma
5567
+ htab->sgot->output_offset
5569
outrel.r_info = ELF64_R_INFO (0, R_PPC64_RELATIVE);
5570
outrel.r_addend = relocation;
5571
loc = (Elf64_External_Rela *) htab->srelgot->contents;
5572
loc += htab->srelgot->reloc_count++;
5573
bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc);
5576
local_got_offsets[r_symndx] |= 1;
5580
if (off >= (bfd_vma) -2)
5583
relocation = htab->sgot->output_offset + off;
5585
/* TOC base (r2) is TOC start plus 0x8000. */
5586
addend -= TOC_BASE_OFF;
5590
case R_PPC64_PLT16_HA:
5591
case R_PPC64_PLT16_HI:
5592
case R_PPC64_PLT16_LO:
5595
/* Relocation is to the entry for this symbol in the
5596
procedure linkage table. */
5598
/* Resolve a PLT reloc against a local symbol directly,
5599
without using the procedure linkage table. */
5603
if (h->plt.offset == (bfd_vma) -1
5604
|| htab->splt == NULL)
5606
/* We didn't make a PLT entry for this symbol. This
5607
happens when statically linking PIC code, or when
5608
using -Bsymbolic. */
5612
relocation = (htab->splt->output_section->vma
5613
+ htab->splt->output_offset
5615
unresolved_reloc = false;
5618
/* TOC16 relocs. We want the offset relative to the TOC base,
5619
which is the address of the start of the TOC plus 0x8000.
5620
The TOC consists of sections .got, .toc, .tocbss, and .plt,
5623
case R_PPC64_TOC16_LO:
5624
case R_PPC64_TOC16_HI:
5625
case R_PPC64_TOC16_DS:
5626
case R_PPC64_TOC16_LO_DS:
5627
case R_PPC64_TOC16_HA:
5628
addend -= TOCstart + TOC_BASE_OFF;
5631
/* Relocate against the beginning of the section. */
5632
case R_PPC64_SECTOFF:
5633
case R_PPC64_SECTOFF_LO:
5634
case R_PPC64_SECTOFF_HI:
5635
case R_PPC64_SECTOFF_DS:
5636
case R_PPC64_SECTOFF_LO_DS:
5637
case R_PPC64_SECTOFF_HA:
5638
if (sec != (asection *) 0)
5639
addend -= sec->output_section->vma;
5643
case R_PPC64_REL14_BRNTAKEN:
5644
case R_PPC64_REL14_BRTAKEN:
5648
/* Relocations that may need to be propagated if this is a
5652
case R_PPC64_ADDR14:
5653
case R_PPC64_ADDR14_BRNTAKEN:
5654
case R_PPC64_ADDR14_BRTAKEN:
5655
case R_PPC64_ADDR16:
5656
case R_PPC64_ADDR16_DS:
5657
case R_PPC64_ADDR16_HA:
5658
case R_PPC64_ADDR16_HI:
5659
case R_PPC64_ADDR16_HIGHER:
5660
case R_PPC64_ADDR16_HIGHERA:
5661
case R_PPC64_ADDR16_HIGHEST:
5662
case R_PPC64_ADDR16_HIGHESTA:
5663
case R_PPC64_ADDR16_LO:
5664
case R_PPC64_ADDR16_LO_DS:
5665
case R_PPC64_ADDR24:
5666
case R_PPC64_ADDR30:
5667
case R_PPC64_ADDR32:
5668
case R_PPC64_ADDR64:
5669
case R_PPC64_UADDR16:
5670
case R_PPC64_UADDR32:
5671
case R_PPC64_UADDR64:
5672
/* r_symndx will be zero only for relocs against symbols
5673
from removed linkonce sections, or sections discarded by
5680
if ((input_section->flags & SEC_ALLOC) == 0)
5683
if (NO_OPD_RELOCS && is_opd)
5687
&& (IS_ABSOLUTE_RELOC (r_type)
5690
&& (! info->symbolic
5691
|| (h->elf_link_hash_flags
5692
& ELF_LINK_HASH_DEF_REGULAR) == 0))))
5696
&& (h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0
5697
&& (((h->elf_link_hash_flags
5698
& ELF_LINK_HASH_DEF_DYNAMIC) != 0
5699
&& (h->elf_link_hash_flags
5700
& ELF_LINK_HASH_DEF_REGULAR) == 0)
5701
|| h->root.type == bfd_link_hash_undefweak
5702
|| h->root.type == bfd_link_hash_undefined)))
5704
Elf_Internal_Rela outrel;
5705
boolean skip, relocate;
5707
Elf64_External_Rela *loc;
5709
/* When generating a dynamic object, these relocations
5710
are copied into the output file to be resolved at run
5717
_bfd_elf_section_offset (output_bfd, info, input_section,
5719
if (outrel.r_offset == (bfd_vma) -1)
5721
else if (outrel.r_offset == (bfd_vma) -2)
5722
skip = true, relocate = true;
5723
outrel.r_offset += (input_section->output_section->vma
5724
+ input_section->output_offset);
5725
outrel.r_addend = addend;
5728
memset (&outrel, 0, sizeof outrel);
5732
&& (!IS_ABSOLUTE_RELOC (r_type)
5735
|| (h->elf_link_hash_flags
5736
& ELF_LINK_HASH_DEF_REGULAR) == 0))
5737
outrel.r_info = ELF64_R_INFO (h->dynindx, r_type);
5740
/* This symbol is local, or marked to become local,
5741
or this is an opd section reloc which must point
5742
at a local function. */
5743
outrel.r_addend += relocation;
5745
if (r_type == R_PPC64_ADDR64 || r_type == R_PPC64_TOC)
5747
if (is_opd && h != NULL)
5749
/* Lie about opd entries. This case occurs
5750
when building shared libraries and we
5751
reference a function in another shared
5752
lib. The same thing happens for a weak
5753
definition in an application that's
5754
overridden by a strong definition in a
5755
shared lib. (I believe this is a generic
5756
bug in binutils handling of weak syms.)
5757
In these cases we won't use the opd
5758
entry in this lib. */
5759
unresolved_reloc = false;
5761
outrel.r_info = ELF64_R_INFO (0, R_PPC64_RELATIVE);
5767
if (bfd_is_abs_section (sec))
5769
else if (sec == NULL || sec->owner == NULL)
5771
bfd_set_error (bfd_error_bad_value);
5778
osec = sec->output_section;
5779
indx = elf_section_data (osec)->dynindx;
5781
/* We are turning this relocation into one
5782
against a section symbol, so subtract out
5783
the output section's address but not the
5784
offset of the input section in the output
5786
outrel.r_addend -= osec->vma;
5789
outrel.r_info = ELF64_R_INFO (indx, r_type);
5793
sreloc = elf_section_data (input_section)->sreloc;
5797
loc = (Elf64_External_Rela *) sreloc->contents;
5798
loc += sreloc->reloc_count++;
5799
bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc);
5801
/* If this reloc is against an external symbol, it will
5802
be computed at runtime, so there's no need to do
5810
case R_PPC64_GLOB_DAT:
5811
case R_PPC64_JMP_SLOT:
5812
case R_PPC64_RELATIVE:
5813
/* We shouldn't ever see these dynamic relocs in relocatable
5817
case R_PPC64_PLTGOT16:
5818
case R_PPC64_PLTGOT16_DS:
5819
case R_PPC64_PLTGOT16_HA:
5820
case R_PPC64_PLTGOT16_HI:
5821
case R_PPC64_PLTGOT16_LO:
5822
case R_PPC64_PLTGOT16_LO_DS:
5823
case R_PPC64_PLTREL32:
5824
case R_PPC64_PLTREL64:
5825
/* These ones haven't been implemented yet. */
5827
(*_bfd_error_handler)
5828
(_("%s: Relocation %s is not supported for symbol %s."),
5829
bfd_archive_filename (input_bfd),
5830
ppc64_elf_howto_table[(int) r_type]->name, sym_name);
5832
bfd_set_error (bfd_error_invalid_operation);
5837
/* Do any further special processing. */
5843
case R_PPC64_ADDR16_HA:
5844
case R_PPC64_ADDR16_HIGHERA:
5845
case R_PPC64_ADDR16_HIGHESTA:
5846
case R_PPC64_PLT16_HA:
5847
case R_PPC64_TOC16_HA:
5848
case R_PPC64_SECTOFF_HA:
5849
/* It's just possible that this symbol is a weak symbol
5850
that's not actually defined anywhere. In that case,
5851
'sec' would be NULL, and we should leave the symbol
5852
alone (it will be set to zero elsewhere in the link). */
5854
/* Add 0x10000 if sign bit in 0:15 is set. */
5855
addend += ((relocation + addend) & 0x8000) << 1;
5858
case R_PPC64_ADDR16_DS:
5859
case R_PPC64_ADDR16_LO_DS:
5860
case R_PPC64_GOT16_DS:
5861
case R_PPC64_GOT16_LO_DS:
5862
case R_PPC64_PLT16_LO_DS:
5863
case R_PPC64_SECTOFF_DS:
5864
case R_PPC64_SECTOFF_LO_DS:
5865
case R_PPC64_TOC16_DS:
5866
case R_PPC64_TOC16_LO_DS:
5867
case R_PPC64_PLTGOT16_DS:
5868
case R_PPC64_PLTGOT16_LO_DS:
5869
if (((relocation + addend) & 3) != 0)
5871
(*_bfd_error_handler)
5872
(_("%s: error: relocation %s not a multiple of 4"),
5873
bfd_archive_filename (input_bfd),
5874
ppc64_elf_howto_table[(int) r_type]->name);
5875
bfd_set_error (bfd_error_bad_value);
5882
case R_PPC64_REL14_BRNTAKEN:
5883
case R_PPC64_REL14_BRTAKEN:
5884
max_br_offset = 1 << 15;
5888
max_br_offset = 1 << 25;
5891
/* If the branch is out of reach, then redirect the
5892
call to the local stub for this function. */
5894
+ input_section->output_offset
5895
+ input_section->output_section->vma);
5896
if (relocation + addend - from + max_br_offset >= 2 * max_br_offset
5897
&& (stub_entry = ppc_get_stub_entry (input_section, sec, h,
5898
rel, htab)) != NULL)
5900
/* Munge up the value and addend so that we call the stub
5901
rather than the procedure directly. */
5902
relocation = (stub_entry->stub_offset
5903
+ stub_entry->stub_sec->output_offset
5904
+ stub_entry->stub_sec->output_section->vma);
5910
/* Dynamic relocs are not propagated for SEC_DEBUGGING sections
5911
because such sections are not SEC_ALLOC and thus ld.so will
5912
not process them. */
5913
if (unresolved_reloc
5914
&& !((input_section->flags & SEC_DEBUGGING) != 0
5915
&& (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0))
5917
(*_bfd_error_handler)
5918
(_("%s(%s+0x%lx): unresolvable relocation against symbol `%s'"),
5919
bfd_archive_filename (input_bfd),
5920
bfd_get_section_name (input_bfd, input_section),
5921
(long) rel->r_offset,
5922
h->root.root.string);
5926
r = _bfd_final_link_relocate (ppc64_elf_howto_table[(int) r_type],
5934
if (r != bfd_reloc_ok)
5940
if (h->root.type == bfd_link_hash_undefweak
5941
&& ppc64_elf_howto_table[(int) r_type]->pc_relative)
5943
/* Assume this is a call protected by other code that
5944
detects the symbol is undefined. If this is the case,
5945
we can safely ignore the overflow. If not, the
5946
program is hosed anyway, and a little warning isn't
5952
name = h->root.root.string;
5956
name = bfd_elf_string_from_elf_section (input_bfd,
5957
symtab_hdr->sh_link,
5962
name = bfd_section_name (input_bfd, sec);
5965
if (r == bfd_reloc_overflow)
5969
if (!((*info->callbacks->reloc_overflow)
5970
(info, name, ppc64_elf_howto_table[(int) r_type]->name,
5971
rel->r_addend, input_bfd, input_section, offset)))
5976
(*_bfd_error_handler)
5977
(_("%s(%s+0x%lx): reloc against `%s': error %d"),
5978
bfd_archive_filename (input_bfd),
5979
bfd_get_section_name (input_bfd, input_section),
5980
(long) rel->r_offset, name, (int) r);
5989
/* Finish up dynamic symbol handling. We set the contents of various
5990
dynamic sections here. */
5993
ppc64_elf_finish_dynamic_symbol (output_bfd, info, h, sym)
5995
struct bfd_link_info *info;
5996
struct elf_link_hash_entry *h;
5997
Elf_Internal_Sym *sym;
5999
struct ppc_link_hash_table *htab;
6002
htab = ppc_hash_table (info);
6003
dynobj = htab->elf.dynobj;
6005
if (h->plt.offset != (bfd_vma) -1
6006
&& ((struct ppc_link_hash_entry *) h)->is_func_descriptor)
6008
Elf_Internal_Rela rela;
6009
Elf64_External_Rela *loc;
6011
/* This symbol has an entry in the procedure linkage table. Set
6014
if (htab->splt == NULL
6015
|| htab->srelplt == NULL
6016
|| htab->sglink == NULL)
6019
/* Create a JMP_SLOT reloc to inform the dynamic linker to
6020
fill in the PLT entry. */
6022
rela.r_offset = (htab->splt->output_section->vma
6023
+ htab->splt->output_offset
6025
rela.r_info = ELF64_R_INFO (h->dynindx, R_PPC64_JMP_SLOT);
6028
loc = (Elf64_External_Rela *) htab->srelplt->contents;
6029
loc += (h->plt.offset - PLT_INITIAL_ENTRY_SIZE) / PLT_ENTRY_SIZE;
6030
bfd_elf64_swap_reloca_out (output_bfd, &rela, loc);
6033
if (h->got.offset != (bfd_vma) -1)
6035
Elf_Internal_Rela rela;
6036
Elf64_External_Rela *loc;
6038
/* This symbol has an entry in the global offset table. Set it
6041
if (htab->sgot == NULL || htab->srelgot == NULL)
6044
rela.r_offset = (htab->sgot->output_section->vma
6045
+ htab->sgot->output_offset
6046
+ (h->got.offset &~ (bfd_vma) 1));
6048
/* If this is a static link, or it is a -Bsymbolic link and the
6049
symbol is defined locally or was forced to be local because
6050
of a version file, we just want to emit a RELATIVE reloc.
6051
The entry in the global offset table will already have been
6052
initialized in the relocate_section function. */
6056
|| (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL))
6057
&& (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR))
6059
BFD_ASSERT((h->got.offset & 1) != 0);
6060
rela.r_info = ELF64_R_INFO (0, R_PPC64_RELATIVE);
6061
rela.r_addend = (h->root.u.def.value
6062
+ h->root.u.def.section->output_section->vma
6063
+ h->root.u.def.section->output_offset);
6067
BFD_ASSERT ((h->got.offset & 1) == 0);
6068
bfd_put_64 (output_bfd, (bfd_vma) 0,
6069
htab->sgot->contents + h->got.offset);
6070
rela.r_info = ELF64_R_INFO (h->dynindx, R_PPC64_GLOB_DAT);
6074
loc = (Elf64_External_Rela *) htab->srelgot->contents;
6075
loc += htab->srelgot->reloc_count++;
6076
bfd_elf64_swap_reloca_out (output_bfd, &rela, loc);
6079
if ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_COPY) != 0)
6081
Elf_Internal_Rela rela;
6082
Elf64_External_Rela *loc;
6084
/* This symbol needs a copy reloc. Set it up. */
6086
if (h->dynindx == -1
6087
|| (h->root.type != bfd_link_hash_defined
6088
&& h->root.type != bfd_link_hash_defweak)
6089
|| htab->srelbss == NULL)
6092
rela.r_offset = (h->root.u.def.value
6093
+ h->root.u.def.section->output_section->vma
6094
+ h->root.u.def.section->output_offset);
6095
rela.r_info = ELF64_R_INFO (h->dynindx, R_PPC64_COPY);
6097
loc = (Elf64_External_Rela *) htab->srelbss->contents;
6098
loc += htab->srelbss->reloc_count++;
6099
bfd_elf64_swap_reloca_out (output_bfd, &rela, loc);
6102
/* Mark some specially defined symbols as absolute. */
6103
if (strcmp (h->root.root.string, "_DYNAMIC") == 0)
6104
sym->st_shndx = SHN_ABS;
6109
/* Used to decide how to sort relocs in an optimal manner for the
6110
dynamic linker, before writing them out. */
6112
static enum elf_reloc_type_class
6113
ppc64_elf_reloc_type_class (rela)
6114
const Elf_Internal_Rela *rela;
6116
enum elf_ppc_reloc_type r_type;
6118
r_type = (enum elf_ppc_reloc_type) ELF64_R_TYPE (rela->r_info);
6121
case R_PPC64_RELATIVE:
6122
return reloc_class_relative;
6123
case R_PPC64_JMP_SLOT:
6124
return reloc_class_plt;
6126
return reloc_class_copy;
6128
return reloc_class_normal;
6132
/* Finish up the dynamic sections. */
6135
ppc64_elf_finish_dynamic_sections (output_bfd, info)
6137
struct bfd_link_info *info;
6139
struct ppc_link_hash_table *htab;
6143
htab = ppc_hash_table (info);
6144
dynobj = htab->elf.dynobj;
6145
sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
6147
if (htab->elf.dynamic_sections_created)
6149
Elf64_External_Dyn *dyncon, *dynconend;
6151
if (sdyn == NULL || htab->sgot == NULL)
6154
dyncon = (Elf64_External_Dyn *) sdyn->contents;
6155
dynconend = (Elf64_External_Dyn *) (sdyn->contents + sdyn->_raw_size);
6156
for (; dyncon < dynconend; dyncon++)
6158
Elf_Internal_Dyn dyn;
6161
bfd_elf64_swap_dyn_in (dynobj, dyncon, &dyn);
6168
case DT_PPC64_GLINK:
6169
dyn.d_un.d_ptr = (htab->sglink->output_section->vma
6170
+ htab->sglink->output_offset);
6174
s = bfd_get_section_by_name (output_bfd, ".opd");
6176
dyn.d_un.d_ptr = s->vma;
6179
case DT_PPC64_OPDSZ:
6180
s = bfd_get_section_by_name (output_bfd, ".opd");
6182
dyn.d_un.d_val = s->_raw_size;
6186
dyn.d_un.d_ptr = (htab->splt->output_section->vma
6187
+ htab->splt->output_offset);
6191
dyn.d_un.d_ptr = (htab->srelplt->output_section->vma
6192
+ htab->srelplt->output_offset);
6196
dyn.d_un.d_val = htab->srelplt->_raw_size;
6200
/* Don't count procedure linkage table relocs in the
6201
overall reloc count. */
6202
if (htab->srelplt != NULL)
6203
dyn.d_un.d_val -= htab->srelplt->_raw_size;
6207
bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon);
6211
if (htab->sgot != NULL && htab->sgot->_raw_size != 0)
6213
/* Fill in the first entry in the global offset table.
6214
We use it to hold the link-time TOCbase. */
6215
bfd_put_64 (output_bfd,
6216
elf_gp (output_bfd) + TOC_BASE_OFF,
6217
htab->sgot->contents);
6219
/* Set .got entry size. */
6220
elf_section_data (htab->sgot->output_section)->this_hdr.sh_entsize = 8;
6223
if (htab->splt != NULL && htab->splt->_raw_size != 0)
6225
/* Set .plt entry size. */
6226
elf_section_data (htab->splt->output_section)->this_hdr.sh_entsize
6233
#define TARGET_LITTLE_SYM bfd_elf64_powerpcle_vec
6234
#define TARGET_LITTLE_NAME "elf64-powerpcle"
6235
#define TARGET_BIG_SYM bfd_elf64_powerpc_vec
6236
#define TARGET_BIG_NAME "elf64-powerpc"
6237
#define ELF_ARCH bfd_arch_powerpc
6238
#define ELF_MACHINE_CODE EM_PPC64
6239
#define ELF_MAXPAGESIZE 0x10000
6240
#define elf_info_to_howto ppc64_elf_info_to_howto
6242
#ifdef EM_CYGNUS_POWERPC
6243
#define ELF_MACHINE_ALT1 EM_CYGNUS_POWERPC
6247
#define ELF_MACHINE_ALT2 EM_PPC_OLD
6250
#define elf_backend_want_got_sym 0
6251
#define elf_backend_want_plt_sym 0
6252
#define elf_backend_plt_alignment 3
6253
#define elf_backend_plt_not_loaded 1
6254
#define elf_backend_got_symbol_offset 0
6255
#define elf_backend_got_header_size 8
6256
#define elf_backend_plt_header_size PLT_INITIAL_ENTRY_SIZE
6257
#define elf_backend_can_gc_sections 1
6258
#define elf_backend_can_refcount 1
6259
#define elf_backend_rela_normal 1
6261
#define bfd_elf64_bfd_reloc_type_lookup ppc64_elf_reloc_type_lookup
6262
#define bfd_elf64_bfd_merge_private_bfd_data ppc64_elf_merge_private_bfd_data
6263
#define bfd_elf64_bfd_link_hash_table_create ppc64_elf_link_hash_table_create
6264
#define bfd_elf64_bfd_link_hash_table_free ppc64_elf_link_hash_table_free
6266
#define elf_backend_object_p ppc64_elf_object_p
6267
#define elf_backend_create_dynamic_sections ppc64_elf_create_dynamic_sections
6268
#define elf_backend_copy_indirect_symbol ppc64_elf_copy_indirect_symbol
6269
#define elf_backend_check_relocs ppc64_elf_check_relocs
6270
#define elf_backend_gc_mark_hook ppc64_elf_gc_mark_hook
6271
#define elf_backend_gc_sweep_hook ppc64_elf_gc_sweep_hook
6272
#define elf_backend_adjust_dynamic_symbol ppc64_elf_adjust_dynamic_symbol
6273
#define elf_backend_hide_symbol ppc64_elf_hide_symbol
6274
#define elf_backend_always_size_sections ppc64_elf_func_desc_adjust
6275
#define elf_backend_size_dynamic_sections ppc64_elf_size_dynamic_sections
6276
#define elf_backend_relocate_section ppc64_elf_relocate_section
6277
#define elf_backend_finish_dynamic_symbol ppc64_elf_finish_dynamic_symbol
6278
#define elf_backend_reloc_type_class ppc64_elf_reloc_type_class
6279
#define elf_backend_finish_dynamic_sections ppc64_elf_finish_dynamic_sections
6281
#include "elf64-target.h"