1 /* PowerPC-specific support for 32-bit ELF
2 Copyright (C) 1994-2021 Free Software Foundation, Inc.
3 Written by Ian Lance Taylor, Cygnus Support.
5 This file is part of BFD, the Binary File Descriptor library.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the
19 Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
20 Boston, MA 02110-1301, USA. */
23 /* This file is based on a preliminary PowerPC ELF ABI. The
24 information may not match the final PowerPC ELF ABI. It includes
25 suggestions from the in-progress Embedded PowerPC ABI, and that
26 information may also not match. */
35 #include "elf32-ppc.h"
36 #include "elf-vxworks.h"
38 #include "opcode/ppc.h"
40 /* All users of this file have bfd_octets_per_byte (abfd, sec) == 1. */
41 #define OCTETS_PER_BYTE(ABFD, SEC) 1
43 typedef enum split16_format_type
50 /* RELA relocations are used here. */
52 static bfd_reloc_status_type ppc_elf_addr16_ha_reloc
53 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
54 static bfd_reloc_status_type ppc_elf_unhandled_reloc
55 (bfd
*, arelent
*, asymbol
*, void *, asection
*, bfd
*, char **);
57 /* Branch prediction bit for branch taken relocs. */
58 #define BRANCH_PREDICT_BIT 0x200000
59 /* Mask to set RA in memory instructions. */
60 #define RA_REGISTER_MASK 0x001f0000
61 /* Value to shift register by to insert RA. */
62 #define RA_REGISTER_SHIFT 16
64 /* The name of the dynamic interpreter. This is put in the .interp
66 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
68 /* For old-style PLT. */
69 /* The number of single-slot PLT entries (the rest use two slots). */
70 #define PLT_NUM_SINGLE_ENTRIES 8192
72 /* For new-style .glink and .plt. */
73 #define GLINK_PLTRESOLVE 16*4
74 #define GLINK_ENTRY_SIZE(htab, h) \
77 && h == htab->tls_get_addr \
78 && !htab->params->no_tls_get_addr_opt ? 8*4 : 0) \
79 + (1u << htab->params->plt_stub_align) - 1) \
80 & -(1u << htab->params->plt_stub_align))
82 /* VxWorks uses its own plt layout, filled in by the static linker. */
84 /* The standard VxWorks PLT entry. */
85 #define VXWORKS_PLT_ENTRY_SIZE 32
86 static const bfd_vma ppc_elf_vxworks_plt_entry
87 [VXWORKS_PLT_ENTRY_SIZE
/ 4] =
89 0x3d800000, /* lis r12,0 */
90 0x818c0000, /* lwz r12,0(r12) */
91 0x7d8903a6, /* mtctr r12 */
92 0x4e800420, /* bctr */
93 0x39600000, /* li r11,0 */
94 0x48000000, /* b 14 <.PLT0resolve+0x4> */
98 static const bfd_vma ppc_elf_vxworks_pic_plt_entry
99 [VXWORKS_PLT_ENTRY_SIZE
/ 4] =
101 0x3d9e0000, /* addis r12,r30,0 */
102 0x818c0000, /* lwz r12,0(r12) */
103 0x7d8903a6, /* mtctr r12 */
104 0x4e800420, /* bctr */
105 0x39600000, /* li r11,0 */
106 0x48000000, /* b 14 <.PLT0resolve+0x4> 14: R_PPC_REL24 .PLTresolve */
107 0x60000000, /* nop */
108 0x60000000, /* nop */
111 /* The initial VxWorks PLT entry. */
112 #define VXWORKS_PLT_INITIAL_ENTRY_SIZE 32
113 static const bfd_vma ppc_elf_vxworks_plt0_entry
114 [VXWORKS_PLT_INITIAL_ENTRY_SIZE
/ 4] =
116 0x3d800000, /* lis r12,0 */
117 0x398c0000, /* addi r12,r12,0 */
118 0x800c0008, /* lwz r0,8(r12) */
119 0x7c0903a6, /* mtctr r0 */
120 0x818c0004, /* lwz r12,4(r12) */
121 0x4e800420, /* bctr */
122 0x60000000, /* nop */
123 0x60000000, /* nop */
125 static const bfd_vma ppc_elf_vxworks_pic_plt0_entry
126 [VXWORKS_PLT_INITIAL_ENTRY_SIZE
/ 4] =
128 0x819e0008, /* lwz r12,8(r30) */
129 0x7d8903a6, /* mtctr r12 */
130 0x819e0004, /* lwz r12,4(r30) */
131 0x4e800420, /* bctr */
132 0x60000000, /* nop */
133 0x60000000, /* nop */
134 0x60000000, /* nop */
135 0x60000000, /* nop */
138 /* For executables, we have some additional relocations in
139 .rela.plt.unloaded, for the kernel loader. */
141 /* The number of non-JMP_SLOT relocations per PLT0 slot. */
142 #define VXWORKS_PLT_NON_JMP_SLOT_RELOCS 3
143 /* The number of relocations in the PLTResolve slot. */
144 #define VXWORKS_PLTRESOLVE_RELOCS 2
145 /* The number of relocations in the PLTResolve slot when creating
147 #define VXWORKS_PLTRESOLVE_RELOCS_SHLIB 0
149 /* Some instructions. */
150 #define ADDIS_11_11 0x3d6b0000
151 #define ADDIS_11_30 0x3d7e0000
152 #define ADDIS_12_12 0x3d8c0000
153 #define ADDI_11_11 0x396b0000
154 #define ADD_0_11_11 0x7c0b5a14
155 #define ADD_3_12_2 0x7c6c1214
156 #define ADD_11_0_11 0x7d605a14
158 #define BA 0x48000002
159 #define BCL_20_31 0x429f0005
160 #define BCTR 0x4e800420
161 #define BEQLR 0x4d820020
162 #define CMPWI_11_0 0x2c0b0000
163 #define LIS_11 0x3d600000
164 #define LIS_12 0x3d800000
165 #define LWZU_0_12 0x840c0000
166 #define LWZ_0_12 0x800c0000
167 #define LWZ_11_3 0x81630000
168 #define LWZ_11_11 0x816b0000
169 #define LWZ_11_30 0x817e0000
170 #define LWZ_12_3 0x81830000
171 #define LWZ_12_12 0x818c0000
172 #define MR_0_3 0x7c601b78
173 #define MR_3_0 0x7c030378
174 #define MFLR_0 0x7c0802a6
175 #define MFLR_12 0x7d8802a6
176 #define MTCTR_0 0x7c0903a6
177 #define MTCTR_11 0x7d6903a6
178 #define MTLR_0 0x7c0803a6
179 #define NOP 0x60000000
180 #define SUB_11_11_12 0x7d6c5850
182 /* Offset of tp and dtp pointers from start of TLS block. */
183 #define TP_OFFSET 0x7000
184 #define DTP_OFFSET 0x8000
186 /* The value of a defined global symbol. */
187 #define SYM_VAL(SYM) \
188 ((SYM)->root.u.def.section->output_section->vma \
189 + (SYM)->root.u.def.section->output_offset \
190 + (SYM)->root.u.def.value)
192 /* Relocation HOWTO's. */
193 /* Like other ELF RELA targets that don't apply multiple
194 field-altering relocations to the same localation, src_mask is
195 always zero and pcrel_offset is the same as pc_relative.
196 PowerPC can always use a zero bitpos, even when the field is not at
197 the LSB. For example, a REL24 could use rightshift=2, bisize=24
198 and bitpos=2 which matches the ABI description, or as we do here,
199 rightshift=0, bitsize=26 and bitpos=0. */
200 #define HOW(type, size, bitsize, mask, rightshift, pc_relative, \
201 complain, special_func) \
202 HOWTO (type, rightshift, size, bitsize, pc_relative, 0, \
203 complain_overflow_ ## complain, special_func, \
204 #type, FALSE, 0, mask, pc_relative)
206 static reloc_howto_type
*ppc_elf_howto_table
[R_PPC_max
];
208 static reloc_howto_type ppc_elf_howto_raw
[] = {
209 /* This reloc does nothing. */
210 HOW (R_PPC_NONE
, 3, 0, 0, 0, FALSE
, dont
,
211 bfd_elf_generic_reloc
),
213 /* A standard 32 bit relocation. */
214 HOW (R_PPC_ADDR32
, 2, 32, 0xffffffff, 0, FALSE
, dont
,
215 bfd_elf_generic_reloc
),
217 /* An absolute 26 bit branch; the lower two bits must be zero.
218 FIXME: we don't check that, we just clear them. */
219 HOW (R_PPC_ADDR24
, 2, 26, 0x3fffffc, 0, FALSE
, signed,
220 bfd_elf_generic_reloc
),
222 /* A standard 16 bit relocation. */
223 HOW (R_PPC_ADDR16
, 1, 16, 0xffff, 0, FALSE
, bitfield
,
224 bfd_elf_generic_reloc
),
226 /* A 16 bit relocation without overflow. */
227 HOW (R_PPC_ADDR16_LO
, 1, 16, 0xffff, 0, FALSE
, dont
,
228 bfd_elf_generic_reloc
),
230 /* The high order 16 bits of an address. */
231 HOW (R_PPC_ADDR16_HI
, 1, 16, 0xffff, 16, FALSE
, dont
,
232 bfd_elf_generic_reloc
),
234 /* The high order 16 bits of an address, plus 1 if the contents of
235 the low 16 bits, treated as a signed number, is negative. */
236 HOW (R_PPC_ADDR16_HA
, 1, 16, 0xffff, 16, FALSE
, dont
,
237 ppc_elf_addr16_ha_reloc
),
239 /* An absolute 16 bit branch; the lower two bits must be zero.
240 FIXME: we don't check that, we just clear them. */
241 HOW (R_PPC_ADDR14
, 2, 16, 0xfffc, 0, FALSE
, signed,
242 bfd_elf_generic_reloc
),
244 /* An absolute 16 bit branch, for which bit 10 should be set to
245 indicate that the branch is expected to be taken. The lower two
246 bits must be zero. */
247 HOW (R_PPC_ADDR14_BRTAKEN
, 2, 16, 0xfffc, 0, FALSE
, signed,
248 bfd_elf_generic_reloc
),
250 /* An absolute 16 bit branch, for which bit 10 should be set to
251 indicate that the branch is not expected to be taken. The lower
252 two bits must be zero. */
253 HOW (R_PPC_ADDR14_BRNTAKEN
, 2, 16, 0xfffc, 0, FALSE
, signed,
254 bfd_elf_generic_reloc
),
256 /* A relative 26 bit branch; the lower two bits must be zero. */
257 HOW (R_PPC_REL24
, 2, 26, 0x3fffffc, 0, TRUE
, signed,
258 bfd_elf_generic_reloc
),
260 /* A relative 16 bit branch; the lower two bits must be zero. */
261 HOW (R_PPC_REL14
, 2, 16, 0xfffc, 0, TRUE
, signed,
262 bfd_elf_generic_reloc
),
264 /* A relative 16 bit branch. Bit 10 should be set to indicate that
265 the branch is expected to be taken. The lower two bits must be
267 HOW (R_PPC_REL14_BRTAKEN
, 2, 16, 0xfffc, 0, TRUE
, signed,
268 bfd_elf_generic_reloc
),
270 /* A relative 16 bit branch. Bit 10 should be set to indicate that
271 the branch is not expected to be taken. The lower two bits must
273 HOW (R_PPC_REL14_BRNTAKEN
, 2, 16, 0xfffc, 0, TRUE
, signed,
274 bfd_elf_generic_reloc
),
276 /* Like R_PPC_ADDR16, but referring to the GOT table entry for the
278 HOW (R_PPC_GOT16
, 1, 16, 0xffff, 0, FALSE
, signed,
279 ppc_elf_unhandled_reloc
),
281 /* Like R_PPC_ADDR16_LO, but referring to the GOT table entry for
283 HOW (R_PPC_GOT16_LO
, 1, 16, 0xffff, 0, FALSE
, dont
,
284 ppc_elf_unhandled_reloc
),
286 /* Like R_PPC_ADDR16_HI, but referring to the GOT table entry for
288 HOW (R_PPC_GOT16_HI
, 1, 16, 0xffff, 16, FALSE
, dont
,
289 ppc_elf_unhandled_reloc
),
291 /* Like R_PPC_ADDR16_HA, but referring to the GOT table entry for
293 HOW (R_PPC_GOT16_HA
, 1, 16, 0xffff, 16, FALSE
, dont
,
294 ppc_elf_unhandled_reloc
),
296 /* Like R_PPC_REL24, but referring to the procedure linkage table
297 entry for the symbol. */
298 HOW (R_PPC_PLTREL24
, 2, 26, 0x3fffffc, 0, TRUE
, signed,
299 ppc_elf_unhandled_reloc
),
301 /* This is used only by the dynamic linker. The symbol should exist
302 both in the object being run and in some shared library. The
303 dynamic linker copies the data addressed by the symbol from the
304 shared library into the object, because the object being
305 run has to have the data at some particular address. */
306 HOW (R_PPC_COPY
, 2, 32, 0, 0, FALSE
, dont
,
307 ppc_elf_unhandled_reloc
),
309 /* Like R_PPC_ADDR32, but used when setting global offset table
311 HOW (R_PPC_GLOB_DAT
, 2, 32, 0xffffffff, 0, FALSE
, dont
,
312 ppc_elf_unhandled_reloc
),
314 /* Marks a procedure linkage table entry for a symbol. */
315 HOW (R_PPC_JMP_SLOT
, 2, 32, 0, 0, FALSE
, dont
,
316 ppc_elf_unhandled_reloc
),
318 /* Used only by the dynamic linker. When the object is run, this
319 longword is set to the load address of the object, plus the
321 HOW (R_PPC_RELATIVE
, 2, 32, 0xffffffff, 0, FALSE
, dont
,
322 bfd_elf_generic_reloc
),
324 /* Like R_PPC_REL24, but uses the value of the symbol within the
325 object rather than the final value. Normally used for
326 _GLOBAL_OFFSET_TABLE_. */
327 HOW (R_PPC_LOCAL24PC
, 2, 26, 0x3fffffc, 0, TRUE
, signed,
328 bfd_elf_generic_reloc
),
330 /* Like R_PPC_ADDR32, but may be unaligned. */
331 HOW (R_PPC_UADDR32
, 2, 32, 0xffffffff, 0, FALSE
, dont
,
332 bfd_elf_generic_reloc
),
334 /* Like R_PPC_ADDR16, but may be unaligned. */
335 HOW (R_PPC_UADDR16
, 1, 16, 0xffff, 0, FALSE
, bitfield
,
336 bfd_elf_generic_reloc
),
338 /* 32-bit PC relative */
339 HOW (R_PPC_REL32
, 2, 32, 0xffffffff, 0, TRUE
, dont
,
340 bfd_elf_generic_reloc
),
342 /* 32-bit relocation to the symbol's procedure linkage table.
343 FIXME: not supported. */
344 HOW (R_PPC_PLT32
, 2, 32, 0, 0, FALSE
, dont
,
345 ppc_elf_unhandled_reloc
),
347 /* 32-bit PC relative relocation to the symbol's procedure linkage table.
348 FIXME: not supported. */
349 HOW (R_PPC_PLTREL32
, 2, 32, 0, 0, TRUE
, dont
,
350 ppc_elf_unhandled_reloc
),
352 /* Like R_PPC_ADDR16_LO, but referring to the PLT table entry for
354 HOW (R_PPC_PLT16_LO
, 1, 16, 0xffff, 0, FALSE
, dont
,
355 ppc_elf_unhandled_reloc
),
357 /* Like R_PPC_ADDR16_HI, but referring to the PLT table entry for
359 HOW (R_PPC_PLT16_HI
, 1, 16, 0xffff, 16, FALSE
, dont
,
360 ppc_elf_unhandled_reloc
),
362 /* Like R_PPC_ADDR16_HA, but referring to the PLT table entry for
364 HOW (R_PPC_PLT16_HA
, 1, 16, 0xffff, 16, FALSE
, dont
,
365 ppc_elf_unhandled_reloc
),
367 /* A sign-extended 16 bit value relative to _SDA_BASE_, for use with
369 HOW (R_PPC_SDAREL16
, 1, 16, 0xffff, 0, FALSE
, signed,
370 ppc_elf_unhandled_reloc
),
372 /* 16-bit section relative relocation. */
373 HOW (R_PPC_SECTOFF
, 1, 16, 0xffff, 0, FALSE
, signed,
374 ppc_elf_unhandled_reloc
),
376 /* 16-bit lower half section relative relocation. */
377 HOW (R_PPC_SECTOFF_LO
, 1, 16, 0xffff, 0, FALSE
, dont
,
378 ppc_elf_unhandled_reloc
),
380 /* 16-bit upper half section relative relocation. */
381 HOW (R_PPC_SECTOFF_HI
, 1, 16, 0xffff, 16, FALSE
, dont
,
382 ppc_elf_unhandled_reloc
),
384 /* 16-bit upper half adjusted section relative relocation. */
385 HOW (R_PPC_SECTOFF_HA
, 1, 16, 0xffff, 16, FALSE
, dont
,
386 ppc_elf_unhandled_reloc
),
388 /* Marker relocs for TLS. */
389 HOW (R_PPC_TLS
, 2, 32, 0, 0, FALSE
, dont
,
390 bfd_elf_generic_reloc
),
392 HOW (R_PPC_TLSGD
, 2, 32, 0, 0, FALSE
, dont
,
393 bfd_elf_generic_reloc
),
395 HOW (R_PPC_TLSLD
, 2, 32, 0, 0, FALSE
, dont
,
396 bfd_elf_generic_reloc
),
398 /* Marker relocs on inline plt call instructions. */
399 HOW (R_PPC_PLTSEQ
, 2, 32, 0, 0, FALSE
, dont
,
400 bfd_elf_generic_reloc
),
402 HOW (R_PPC_PLTCALL
, 2, 32, 0, 0, FALSE
, dont
,
403 bfd_elf_generic_reloc
),
405 /* Computes the load module index of the load module that contains the
406 definition of its TLS sym. */
407 HOW (R_PPC_DTPMOD32
, 2, 32, 0xffffffff, 0, FALSE
, dont
,
408 ppc_elf_unhandled_reloc
),
410 /* Computes a dtv-relative displacement, the difference between the value
411 of sym+add and the base address of the thread-local storage block that
412 contains the definition of sym, minus 0x8000. */
413 HOW (R_PPC_DTPREL32
, 2, 32, 0xffffffff, 0, FALSE
, dont
,
414 ppc_elf_unhandled_reloc
),
416 /* A 16 bit dtprel reloc. */
417 HOW (R_PPC_DTPREL16
, 1, 16, 0xffff, 0, FALSE
, signed,
418 ppc_elf_unhandled_reloc
),
420 /* Like DTPREL16, but no overflow. */
421 HOW (R_PPC_DTPREL16_LO
, 1, 16, 0xffff, 0, FALSE
, dont
,
422 ppc_elf_unhandled_reloc
),
424 /* Like DTPREL16_LO, but next higher group of 16 bits. */
425 HOW (R_PPC_DTPREL16_HI
, 1, 16, 0xffff, 16, FALSE
, dont
,
426 ppc_elf_unhandled_reloc
),
428 /* Like DTPREL16_HI, but adjust for low 16 bits. */
429 HOW (R_PPC_DTPREL16_HA
, 1, 16, 0xffff, 16, FALSE
, dont
,
430 ppc_elf_unhandled_reloc
),
432 /* Computes a tp-relative displacement, the difference between the value of
433 sym+add and the value of the thread pointer (r13). */
434 HOW (R_PPC_TPREL32
, 2, 32, 0xffffffff, 0, FALSE
, dont
,
435 ppc_elf_unhandled_reloc
),
437 /* A 16 bit tprel reloc. */
438 HOW (R_PPC_TPREL16
, 1, 16, 0xffff, 0, FALSE
, signed,
439 ppc_elf_unhandled_reloc
),
441 /* Like TPREL16, but no overflow. */
442 HOW (R_PPC_TPREL16_LO
, 1, 16, 0xffff, 0, FALSE
, dont
,
443 ppc_elf_unhandled_reloc
),
445 /* Like TPREL16_LO, but next higher group of 16 bits. */
446 HOW (R_PPC_TPREL16_HI
, 1, 16, 0xffff, 16, FALSE
, dont
,
447 ppc_elf_unhandled_reloc
),
449 /* Like TPREL16_HI, but adjust for low 16 bits. */
450 HOW (R_PPC_TPREL16_HA
, 1, 16, 0xffff, 16, FALSE
, dont
,
451 ppc_elf_unhandled_reloc
),
453 /* Allocates two contiguous entries in the GOT to hold a tls_index structure,
454 with values (sym+add)@dtpmod and (sym+add)@dtprel, and computes the offset
455 to the first entry. */
456 HOW (R_PPC_GOT_TLSGD16
, 1, 16, 0xffff, 0, FALSE
, signed,
457 ppc_elf_unhandled_reloc
),
459 /* Like GOT_TLSGD16, but no overflow. */
460 HOW (R_PPC_GOT_TLSGD16_LO
, 1, 16, 0xffff, 0, FALSE
, dont
,
461 ppc_elf_unhandled_reloc
),
463 /* Like GOT_TLSGD16_LO, but next higher group of 16 bits. */
464 HOW (R_PPC_GOT_TLSGD16_HI
, 1, 16, 0xffff, 16, FALSE
, dont
,
465 ppc_elf_unhandled_reloc
),
467 /* Like GOT_TLSGD16_HI, but adjust for low 16 bits. */
468 HOW (R_PPC_GOT_TLSGD16_HA
, 1, 16, 0xffff, 16, FALSE
, dont
,
469 ppc_elf_unhandled_reloc
),
471 /* Allocates two contiguous entries in the GOT to hold a tls_index structure,
472 with values (sym+add)@dtpmod and zero, and computes the offset to the
474 HOW (R_PPC_GOT_TLSLD16
, 1, 16, 0xffff, 0, FALSE
, signed,
475 ppc_elf_unhandled_reloc
),
477 /* Like GOT_TLSLD16, but no overflow. */
478 HOW (R_PPC_GOT_TLSLD16_LO
, 1, 16, 0xffff, 0, FALSE
, dont
,
479 ppc_elf_unhandled_reloc
),
481 /* Like GOT_TLSLD16_LO, but next higher group of 16 bits. */
482 HOW (R_PPC_GOT_TLSLD16_HI
, 1, 16, 0xffff, 16, FALSE
, dont
,
483 ppc_elf_unhandled_reloc
),
485 /* Like GOT_TLSLD16_HI, but adjust for low 16 bits. */
486 HOW (R_PPC_GOT_TLSLD16_HA
, 1, 16, 0xffff, 16, FALSE
, dont
,
487 ppc_elf_unhandled_reloc
),
489 /* Allocates an entry in the GOT with value (sym+add)@dtprel, and computes
490 the offset to the entry. */
491 HOW (R_PPC_GOT_DTPREL16
, 1, 16, 0xffff, 0, FALSE
, signed,
492 ppc_elf_unhandled_reloc
),
494 /* Like GOT_DTPREL16, but no overflow. */
495 HOW (R_PPC_GOT_DTPREL16_LO
, 1, 16, 0xffff, 0, FALSE
, dont
,
496 ppc_elf_unhandled_reloc
),
498 /* Like GOT_DTPREL16_LO, but next higher group of 16 bits. */
499 HOW (R_PPC_GOT_DTPREL16_HI
, 1, 16, 0xffff, 16, FALSE
, dont
,
500 ppc_elf_unhandled_reloc
),
502 /* Like GOT_DTPREL16_HI, but adjust for low 16 bits. */
503 HOW (R_PPC_GOT_DTPREL16_HA
, 1, 16, 0xffff, 16, FALSE
, dont
,
504 ppc_elf_unhandled_reloc
),
506 /* Allocates an entry in the GOT with value (sym+add)@tprel, and computes the
507 offset to the entry. */
508 HOW (R_PPC_GOT_TPREL16
, 1, 16, 0xffff, 0, FALSE
, signed,
509 ppc_elf_unhandled_reloc
),
511 /* Like GOT_TPREL16, but no overflow. */
512 HOW (R_PPC_GOT_TPREL16_LO
, 1, 16, 0xffff, 0, FALSE
, dont
,
513 ppc_elf_unhandled_reloc
),
515 /* Like GOT_TPREL16_LO, but next higher group of 16 bits. */
516 HOW (R_PPC_GOT_TPREL16_HI
, 1, 16, 0xffff, 16, FALSE
, dont
,
517 ppc_elf_unhandled_reloc
),
519 /* Like GOT_TPREL16_HI, but adjust for low 16 bits. */
520 HOW (R_PPC_GOT_TPREL16_HA
, 1, 16, 0xffff, 16, FALSE
, dont
,
521 ppc_elf_unhandled_reloc
),
523 /* The remaining relocs are from the Embedded ELF ABI, and are not
524 in the SVR4 ELF ABI. */
526 /* 32 bit value resulting from the addend minus the symbol. */
527 HOW (R_PPC_EMB_NADDR32
, 2, 32, 0xffffffff, 0, FALSE
, dont
,
528 ppc_elf_unhandled_reloc
),
530 /* 16 bit value resulting from the addend minus the symbol. */
531 HOW (R_PPC_EMB_NADDR16
, 1, 16, 0xffff, 0, FALSE
, signed,
532 ppc_elf_unhandled_reloc
),
534 /* 16 bit value resulting from the addend minus the symbol. */
535 HOW (R_PPC_EMB_NADDR16_LO
, 1, 16, 0xffff, 0, FALSE
, dont
,
536 ppc_elf_unhandled_reloc
),
538 /* The high order 16 bits of the addend minus the symbol. */
539 HOW (R_PPC_EMB_NADDR16_HI
, 1, 16, 0xffff, 16, FALSE
, dont
,
540 ppc_elf_unhandled_reloc
),
542 /* The high order 16 bits of the result of the addend minus the address,
543 plus 1 if the contents of the low 16 bits, treated as a signed number,
545 HOW (R_PPC_EMB_NADDR16_HA
, 1, 16, 0xffff, 16, FALSE
, dont
,
546 ppc_elf_unhandled_reloc
),
548 /* 16 bit value resulting from allocating a 4 byte word to hold an
549 address in the .sdata section, and returning the offset from
550 _SDA_BASE_ for that relocation. */
551 HOW (R_PPC_EMB_SDAI16
, 1, 16, 0xffff, 0, FALSE
, signed,
552 ppc_elf_unhandled_reloc
),
554 /* 16 bit value resulting from allocating a 4 byte word to hold an
555 address in the .sdata2 section, and returning the offset from
556 _SDA2_BASE_ for that relocation. */
557 HOW (R_PPC_EMB_SDA2I16
, 1, 16, 0xffff, 0, FALSE
, signed,
558 ppc_elf_unhandled_reloc
),
560 /* A sign-extended 16 bit value relative to _SDA2_BASE_, for use with
562 HOW (R_PPC_EMB_SDA2REL
, 1, 16, 0xffff, 0, FALSE
, signed,
563 ppc_elf_unhandled_reloc
),
565 /* Relocate against either _SDA_BASE_ or _SDA2_BASE_, filling in the 16 bit
566 signed offset from the appropriate base, and filling in the register
567 field with the appropriate register (0, 2, or 13). */
568 HOW (R_PPC_EMB_SDA21
, 2, 16, 0xffff, 0, FALSE
, signed,
569 ppc_elf_unhandled_reloc
),
571 /* Relocation not handled: R_PPC_EMB_MRKREF */
572 /* Relocation not handled: R_PPC_EMB_RELSEC16 */
573 /* Relocation not handled: R_PPC_EMB_RELST_LO */
574 /* Relocation not handled: R_PPC_EMB_RELST_HI */
575 /* Relocation not handled: R_PPC_EMB_RELST_HA */
576 /* Relocation not handled: R_PPC_EMB_BIT_FLD */
578 /* PC relative relocation against either _SDA_BASE_ or _SDA2_BASE_, filling
579 in the 16 bit signed offset from the appropriate base, and filling in the
580 register field with the appropriate register (0, 2, or 13). */
581 HOW (R_PPC_EMB_RELSDA
, 1, 16, 0xffff, 0, FALSE
, signed,
582 ppc_elf_unhandled_reloc
),
584 /* A relative 8 bit branch. */
585 HOW (R_PPC_VLE_REL8
, 1, 8, 0xff, 1, TRUE
, signed,
586 bfd_elf_generic_reloc
),
588 /* A relative 15 bit branch. */
589 HOW (R_PPC_VLE_REL15
, 2, 16, 0xfffe, 0, TRUE
, signed,
590 bfd_elf_generic_reloc
),
592 /* A relative 24 bit branch. */
593 HOW (R_PPC_VLE_REL24
, 2, 25, 0x1fffffe, 0, TRUE
, signed,
594 bfd_elf_generic_reloc
),
596 /* The 16 LSBS in split16a format. */
597 HOW (R_PPC_VLE_LO16A
, 2, 16, 0x1f07ff, 0, FALSE
, dont
,
598 ppc_elf_unhandled_reloc
),
600 /* The 16 LSBS in split16d format. */
601 HOW (R_PPC_VLE_LO16D
, 2, 16, 0x3e007ff, 0, FALSE
, dont
,
602 ppc_elf_unhandled_reloc
),
604 /* Bits 16-31 split16a format. */
605 HOW (R_PPC_VLE_HI16A
, 2, 16, 0x1f07ff, 16, FALSE
, dont
,
606 ppc_elf_unhandled_reloc
),
608 /* Bits 16-31 split16d format. */
609 HOW (R_PPC_VLE_HI16D
, 2, 16, 0x3e007ff, 16, FALSE
, dont
,
610 ppc_elf_unhandled_reloc
),
612 /* Bits 16-31 (High Adjusted) in split16a format. */
613 HOW (R_PPC_VLE_HA16A
, 2, 16, 0x1f07ff, 16, FALSE
, dont
,
614 ppc_elf_unhandled_reloc
),
616 /* Bits 16-31 (High Adjusted) in split16d format. */
617 HOW (R_PPC_VLE_HA16D
, 2, 16, 0x3e007ff, 16, FALSE
, dont
,
618 ppc_elf_unhandled_reloc
),
620 /* This reloc is like R_PPC_EMB_SDA21 but only applies to e_add16i
621 instructions. If the register base is 0 then the linker changes
622 the e_add16i to an e_li instruction. */
623 HOW (R_PPC_VLE_SDA21
, 2, 16, 0xffff, 0, FALSE
, signed,
624 ppc_elf_unhandled_reloc
),
626 /* Like R_PPC_VLE_SDA21 but ignore overflow. */
627 HOW (R_PPC_VLE_SDA21_LO
, 2, 16, 0xffff, 0, FALSE
, dont
,
628 ppc_elf_unhandled_reloc
),
630 /* The 16 LSBS relative to _SDA_BASE_ in split16a format. */
631 HOW (R_PPC_VLE_SDAREL_LO16A
, 2, 16, 0x1f07ff, 0, FALSE
, dont
,
632 ppc_elf_unhandled_reloc
),
634 /* The 16 LSBS relative to _SDA_BASE_ in split16d format. */
635 HOW (R_PPC_VLE_SDAREL_LO16D
, 2, 16, 0x3e007ff, 0, FALSE
, dont
,
636 ppc_elf_unhandled_reloc
),
638 /* Bits 16-31 relative to _SDA_BASE_ in split16a format. */
639 HOW (R_PPC_VLE_SDAREL_HI16A
, 2, 16, 0x1f07ff, 16, FALSE
, dont
,
640 ppc_elf_unhandled_reloc
),
642 /* Bits 16-31 relative to _SDA_BASE_ in split16d format. */
643 HOW (R_PPC_VLE_SDAREL_HI16D
, 2, 16, 0x3e007ff, 16, FALSE
, dont
,
644 ppc_elf_unhandled_reloc
),
646 /* Bits 16-31 (HA) relative to _SDA_BASE split16a format. */
647 HOW (R_PPC_VLE_SDAREL_HA16A
, 2, 16, 0x1f07ff, 16, FALSE
, dont
,
648 ppc_elf_unhandled_reloc
),
650 /* Bits 16-31 (HA) relative to _SDA_BASE split16d format. */
651 HOW (R_PPC_VLE_SDAREL_HA16D
, 2, 16, 0x3e007ff, 16, FALSE
, dont
,
652 ppc_elf_unhandled_reloc
),
654 /* e_li split20 format. */
655 HOW (R_PPC_VLE_ADDR20
, 2, 20, 0x1f7fff, 0, FALSE
, dont
,
656 ppc_elf_unhandled_reloc
),
658 HOW (R_PPC_IRELATIVE
, 2, 32, 0xffffffff, 0, FALSE
, dont
,
659 ppc_elf_unhandled_reloc
),
661 /* A 16 bit relative relocation. */
662 HOW (R_PPC_REL16
, 1, 16, 0xffff, 0, TRUE
, signed,
663 bfd_elf_generic_reloc
),
665 /* A 16 bit relative relocation without overflow. */
666 HOW (R_PPC_REL16_LO
, 1, 16, 0xffff, 0, TRUE
, dont
,
667 bfd_elf_generic_reloc
),
669 /* The high order 16 bits of a relative address. */
670 HOW (R_PPC_REL16_HI
, 1, 16, 0xffff, 16, TRUE
, dont
,
671 bfd_elf_generic_reloc
),
673 /* The high order 16 bits of a relative address, plus 1 if the contents of
674 the low 16 bits, treated as a signed number, is negative. */
675 HOW (R_PPC_REL16_HA
, 1, 16, 0xffff, 16, TRUE
, dont
,
676 ppc_elf_addr16_ha_reloc
),
678 /* Like R_PPC_REL16_HA but for split field in addpcis. */
679 HOW (R_PPC_REL16DX_HA
, 2, 16, 0x1fffc1, 16, TRUE
, signed,
680 ppc_elf_addr16_ha_reloc
),
682 /* A split-field reloc for addpcis, non-relative (gas internal use only). */
683 HOW (R_PPC_16DX_HA
, 2, 16, 0x1fffc1, 16, FALSE
, signed,
684 ppc_elf_addr16_ha_reloc
),
686 /* GNU extension to record C++ vtable hierarchy. */
687 HOW (R_PPC_GNU_VTINHERIT
, 0, 0, 0, 0, FALSE
, dont
,
690 /* GNU extension to record C++ vtable member usage. */
691 HOW (R_PPC_GNU_VTENTRY
, 0, 0, 0, 0, FALSE
, dont
,
694 /* Phony reloc to handle AIX style TOC entries. */
695 HOW (R_PPC_TOC16
, 1, 16, 0xffff, 0, FALSE
, signed,
696 ppc_elf_unhandled_reloc
),
699 /* Initialize the ppc_elf_howto_table, so that linear accesses can be done. */
702 ppc_elf_howto_init (void)
704 unsigned int i
, type
;
707 i
< sizeof (ppc_elf_howto_raw
) / sizeof (ppc_elf_howto_raw
[0]);
710 type
= ppc_elf_howto_raw
[i
].type
;
711 if (type
>= (sizeof (ppc_elf_howto_table
)
712 / sizeof (ppc_elf_howto_table
[0])))
714 ppc_elf_howto_table
[type
] = &ppc_elf_howto_raw
[i
];
718 static reloc_howto_type
*
719 ppc_elf_reloc_type_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
720 bfd_reloc_code_real_type code
)
722 enum elf_ppc_reloc_type r
;
724 /* Initialize howto table if not already done. */
725 if (!ppc_elf_howto_table
[R_PPC_ADDR32
])
726 ppc_elf_howto_init ();
733 case BFD_RELOC_NONE
: r
= R_PPC_NONE
; break;
734 case BFD_RELOC_32
: r
= R_PPC_ADDR32
; break;
735 case BFD_RELOC_PPC_BA26
: r
= R_PPC_ADDR24
; break;
736 case BFD_RELOC_PPC64_ADDR16_DS
:
737 case BFD_RELOC_16
: r
= R_PPC_ADDR16
; break;
738 case BFD_RELOC_PPC64_ADDR16_LO_DS
:
739 case BFD_RELOC_LO16
: r
= R_PPC_ADDR16_LO
; break;
740 case BFD_RELOC_HI16
: r
= R_PPC_ADDR16_HI
; break;
741 case BFD_RELOC_HI16_S
: r
= R_PPC_ADDR16_HA
; break;
742 case BFD_RELOC_PPC_BA16
: r
= R_PPC_ADDR14
; break;
743 case BFD_RELOC_PPC_BA16_BRTAKEN
: r
= R_PPC_ADDR14_BRTAKEN
; break;
744 case BFD_RELOC_PPC_BA16_BRNTAKEN
: r
= R_PPC_ADDR14_BRNTAKEN
; break;
745 case BFD_RELOC_PPC_B26
: r
= R_PPC_REL24
; break;
746 case BFD_RELOC_PPC_B16
: r
= R_PPC_REL14
; break;
747 case BFD_RELOC_PPC_B16_BRTAKEN
: r
= R_PPC_REL14_BRTAKEN
; break;
748 case BFD_RELOC_PPC_B16_BRNTAKEN
: r
= R_PPC_REL14_BRNTAKEN
; break;
749 case BFD_RELOC_PPC64_GOT16_DS
:
750 case BFD_RELOC_16_GOTOFF
: r
= R_PPC_GOT16
; break;
751 case BFD_RELOC_PPC64_GOT16_LO_DS
:
752 case BFD_RELOC_LO16_GOTOFF
: r
= R_PPC_GOT16_LO
; break;
753 case BFD_RELOC_HI16_GOTOFF
: r
= R_PPC_GOT16_HI
; break;
754 case BFD_RELOC_HI16_S_GOTOFF
: r
= R_PPC_GOT16_HA
; break;
755 case BFD_RELOC_24_PLT_PCREL
: r
= R_PPC_PLTREL24
; break;
756 case BFD_RELOC_PPC_COPY
: r
= R_PPC_COPY
; break;
757 case BFD_RELOC_PPC_GLOB_DAT
: r
= R_PPC_GLOB_DAT
; break;
758 case BFD_RELOC_PPC_LOCAL24PC
: r
= R_PPC_LOCAL24PC
; break;
759 case BFD_RELOC_32_PCREL
: r
= R_PPC_REL32
; break;
760 case BFD_RELOC_32_PLTOFF
: r
= R_PPC_PLT32
; break;
761 case BFD_RELOC_32_PLT_PCREL
: r
= R_PPC_PLTREL32
; break;
762 case BFD_RELOC_PPC64_PLT16_LO_DS
:
763 case BFD_RELOC_LO16_PLTOFF
: r
= R_PPC_PLT16_LO
; break;
764 case BFD_RELOC_HI16_PLTOFF
: r
= R_PPC_PLT16_HI
; break;
765 case BFD_RELOC_HI16_S_PLTOFF
: r
= R_PPC_PLT16_HA
; break;
766 case BFD_RELOC_GPREL16
: r
= R_PPC_SDAREL16
; break;
767 case BFD_RELOC_PPC64_SECTOFF_DS
:
768 case BFD_RELOC_16_BASEREL
: r
= R_PPC_SECTOFF
; break;
769 case BFD_RELOC_PPC64_SECTOFF_LO_DS
:
770 case BFD_RELOC_LO16_BASEREL
: r
= R_PPC_SECTOFF_LO
; break;
771 case BFD_RELOC_HI16_BASEREL
: r
= R_PPC_SECTOFF_HI
; break;
772 case BFD_RELOC_HI16_S_BASEREL
: r
= R_PPC_SECTOFF_HA
; break;
773 case BFD_RELOC_CTOR
: r
= R_PPC_ADDR32
; break;
774 case BFD_RELOC_PPC64_TOC16_DS
:
775 case BFD_RELOC_PPC_TOC16
: r
= R_PPC_TOC16
; break;
776 case BFD_RELOC_PPC_TLS
: r
= R_PPC_TLS
; break;
777 case BFD_RELOC_PPC_TLSGD
: r
= R_PPC_TLSGD
; break;
778 case BFD_RELOC_PPC_TLSLD
: r
= R_PPC_TLSLD
; break;
779 case BFD_RELOC_PPC_DTPMOD
: r
= R_PPC_DTPMOD32
; break;
780 case BFD_RELOC_PPC64_TPREL16_DS
:
781 case BFD_RELOC_PPC_TPREL16
: r
= R_PPC_TPREL16
; break;
782 case BFD_RELOC_PPC64_TPREL16_LO_DS
:
783 case BFD_RELOC_PPC_TPREL16_LO
: r
= R_PPC_TPREL16_LO
; break;
784 case BFD_RELOC_PPC_TPREL16_HI
: r
= R_PPC_TPREL16_HI
; break;
785 case BFD_RELOC_PPC_TPREL16_HA
: r
= R_PPC_TPREL16_HA
; break;
786 case BFD_RELOC_PPC_TPREL
: r
= R_PPC_TPREL32
; break;
787 case BFD_RELOC_PPC64_DTPREL16_DS
:
788 case BFD_RELOC_PPC_DTPREL16
: r
= R_PPC_DTPREL16
; break;
789 case BFD_RELOC_PPC64_DTPREL16_LO_DS
:
790 case BFD_RELOC_PPC_DTPREL16_LO
: r
= R_PPC_DTPREL16_LO
; break;
791 case BFD_RELOC_PPC_DTPREL16_HI
: r
= R_PPC_DTPREL16_HI
; break;
792 case BFD_RELOC_PPC_DTPREL16_HA
: r
= R_PPC_DTPREL16_HA
; break;
793 case BFD_RELOC_PPC_DTPREL
: r
= R_PPC_DTPREL32
; break;
794 case BFD_RELOC_PPC_GOT_TLSGD16
: r
= R_PPC_GOT_TLSGD16
; break;
795 case BFD_RELOC_PPC_GOT_TLSGD16_LO
: r
= R_PPC_GOT_TLSGD16_LO
; break;
796 case BFD_RELOC_PPC_GOT_TLSGD16_HI
: r
= R_PPC_GOT_TLSGD16_HI
; break;
797 case BFD_RELOC_PPC_GOT_TLSGD16_HA
: r
= R_PPC_GOT_TLSGD16_HA
; break;
798 case BFD_RELOC_PPC_GOT_TLSLD16
: r
= R_PPC_GOT_TLSLD16
; break;
799 case BFD_RELOC_PPC_GOT_TLSLD16_LO
: r
= R_PPC_GOT_TLSLD16_LO
; break;
800 case BFD_RELOC_PPC_GOT_TLSLD16_HI
: r
= R_PPC_GOT_TLSLD16_HI
; break;
801 case BFD_RELOC_PPC_GOT_TLSLD16_HA
: r
= R_PPC_GOT_TLSLD16_HA
; break;
802 case BFD_RELOC_PPC_GOT_TPREL16
: r
= R_PPC_GOT_TPREL16
; break;
803 case BFD_RELOC_PPC_GOT_TPREL16_LO
: r
= R_PPC_GOT_TPREL16_LO
; break;
804 case BFD_RELOC_PPC_GOT_TPREL16_HI
: r
= R_PPC_GOT_TPREL16_HI
; break;
805 case BFD_RELOC_PPC_GOT_TPREL16_HA
: r
= R_PPC_GOT_TPREL16_HA
; break;
806 case BFD_RELOC_PPC_GOT_DTPREL16
: r
= R_PPC_GOT_DTPREL16
; break;
807 case BFD_RELOC_PPC_GOT_DTPREL16_LO
: r
= R_PPC_GOT_DTPREL16_LO
; break;
808 case BFD_RELOC_PPC_GOT_DTPREL16_HI
: r
= R_PPC_GOT_DTPREL16_HI
; break;
809 case BFD_RELOC_PPC_GOT_DTPREL16_HA
: r
= R_PPC_GOT_DTPREL16_HA
; break;
810 case BFD_RELOC_PPC_EMB_NADDR32
: r
= R_PPC_EMB_NADDR32
; break;
811 case BFD_RELOC_PPC_EMB_NADDR16
: r
= R_PPC_EMB_NADDR16
; break;
812 case BFD_RELOC_PPC_EMB_NADDR16_LO
: r
= R_PPC_EMB_NADDR16_LO
; break;
813 case BFD_RELOC_PPC_EMB_NADDR16_HI
: r
= R_PPC_EMB_NADDR16_HI
; break;
814 case BFD_RELOC_PPC_EMB_NADDR16_HA
: r
= R_PPC_EMB_NADDR16_HA
; break;
815 case BFD_RELOC_PPC_EMB_SDAI16
: r
= R_PPC_EMB_SDAI16
; break;
816 case BFD_RELOC_PPC_EMB_SDA2I16
: r
= R_PPC_EMB_SDA2I16
; break;
817 case BFD_RELOC_PPC_EMB_SDA2REL
: r
= R_PPC_EMB_SDA2REL
; break;
818 case BFD_RELOC_PPC_EMB_SDA21
: r
= R_PPC_EMB_SDA21
; break;
819 case BFD_RELOC_PPC_EMB_MRKREF
: r
= R_PPC_EMB_MRKREF
; break;
820 case BFD_RELOC_PPC_EMB_RELSEC16
: r
= R_PPC_EMB_RELSEC16
; break;
821 case BFD_RELOC_PPC_EMB_RELST_LO
: r
= R_PPC_EMB_RELST_LO
; break;
822 case BFD_RELOC_PPC_EMB_RELST_HI
: r
= R_PPC_EMB_RELST_HI
; break;
823 case BFD_RELOC_PPC_EMB_RELST_HA
: r
= R_PPC_EMB_RELST_HA
; break;
824 case BFD_RELOC_PPC_EMB_BIT_FLD
: r
= R_PPC_EMB_BIT_FLD
; break;
825 case BFD_RELOC_PPC_EMB_RELSDA
: r
= R_PPC_EMB_RELSDA
; break;
826 case BFD_RELOC_PPC_VLE_REL8
: r
= R_PPC_VLE_REL8
; break;
827 case BFD_RELOC_PPC_VLE_REL15
: r
= R_PPC_VLE_REL15
; break;
828 case BFD_RELOC_PPC_VLE_REL24
: r
= R_PPC_VLE_REL24
; break;
829 case BFD_RELOC_PPC_VLE_LO16A
: r
= R_PPC_VLE_LO16A
; break;
830 case BFD_RELOC_PPC_VLE_LO16D
: r
= R_PPC_VLE_LO16D
; break;
831 case BFD_RELOC_PPC_VLE_HI16A
: r
= R_PPC_VLE_HI16A
; break;
832 case BFD_RELOC_PPC_VLE_HI16D
: r
= R_PPC_VLE_HI16D
; break;
833 case BFD_RELOC_PPC_VLE_HA16A
: r
= R_PPC_VLE_HA16A
; break;
834 case BFD_RELOC_PPC_VLE_HA16D
: r
= R_PPC_VLE_HA16D
; break;
835 case BFD_RELOC_PPC_VLE_SDA21
: r
= R_PPC_VLE_SDA21
; break;
836 case BFD_RELOC_PPC_VLE_SDA21_LO
: r
= R_PPC_VLE_SDA21_LO
; break;
837 case BFD_RELOC_PPC_VLE_SDAREL_LO16A
:
838 r
= R_PPC_VLE_SDAREL_LO16A
;
840 case BFD_RELOC_PPC_VLE_SDAREL_LO16D
:
841 r
= R_PPC_VLE_SDAREL_LO16D
;
843 case BFD_RELOC_PPC_VLE_SDAREL_HI16A
:
844 r
= R_PPC_VLE_SDAREL_HI16A
;
846 case BFD_RELOC_PPC_VLE_SDAREL_HI16D
:
847 r
= R_PPC_VLE_SDAREL_HI16D
;
849 case BFD_RELOC_PPC_VLE_SDAREL_HA16A
:
850 r
= R_PPC_VLE_SDAREL_HA16A
;
852 case BFD_RELOC_PPC_VLE_SDAREL_HA16D
:
853 r
= R_PPC_VLE_SDAREL_HA16D
;
855 case BFD_RELOC_16_PCREL
: r
= R_PPC_REL16
; break;
856 case BFD_RELOC_LO16_PCREL
: r
= R_PPC_REL16_LO
; break;
857 case BFD_RELOC_HI16_PCREL
: r
= R_PPC_REL16_HI
; break;
858 case BFD_RELOC_HI16_S_PCREL
: r
= R_PPC_REL16_HA
; break;
859 case BFD_RELOC_PPC_16DX_HA
: r
= R_PPC_16DX_HA
; break;
860 case BFD_RELOC_PPC_REL16DX_HA
: r
= R_PPC_REL16DX_HA
; break;
861 case BFD_RELOC_VTABLE_INHERIT
: r
= R_PPC_GNU_VTINHERIT
; break;
862 case BFD_RELOC_VTABLE_ENTRY
: r
= R_PPC_GNU_VTENTRY
; break;
865 return ppc_elf_howto_table
[r
];
868 static reloc_howto_type
*
869 ppc_elf_reloc_name_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
875 i
< sizeof (ppc_elf_howto_raw
) / sizeof (ppc_elf_howto_raw
[0]);
877 if (ppc_elf_howto_raw
[i
].name
!= NULL
878 && strcasecmp (ppc_elf_howto_raw
[i
].name
, r_name
) == 0)
879 return &ppc_elf_howto_raw
[i
];
884 /* Set the howto pointer for a PowerPC ELF reloc. */
887 ppc_elf_info_to_howto (bfd
*abfd
,
889 Elf_Internal_Rela
*dst
)
893 /* Initialize howto table if not already done. */
894 if (!ppc_elf_howto_table
[R_PPC_ADDR32
])
895 ppc_elf_howto_init ();
897 r_type
= ELF32_R_TYPE (dst
->r_info
);
898 if (r_type
>= R_PPC_max
)
900 /* xgettext:c-format */
901 _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
903 bfd_set_error (bfd_error_bad_value
);
907 cache_ptr
->howto
= ppc_elf_howto_table
[r_type
];
909 /* Just because the above assert didn't trigger doesn't mean that
910 ELF32_R_TYPE (dst->r_info) is necessarily a valid relocation. */
911 if (cache_ptr
->howto
== NULL
)
913 /* xgettext:c-format */
914 _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
916 bfd_set_error (bfd_error_bad_value
);
924 /* Handle the R_PPC_ADDR16_HA and R_PPC_REL16_HA relocs. */
926 static bfd_reloc_status_type
927 ppc_elf_addr16_ha_reloc (bfd
*abfd
,
928 arelent
*reloc_entry
,
931 asection
*input_section
,
933 char **error_message ATTRIBUTE_UNUSED
)
935 enum elf_ppc_reloc_type r_type
;
937 bfd_size_type octets
;
940 if (output_bfd
!= NULL
)
942 reloc_entry
->address
+= input_section
->output_offset
;
946 reloc_entry
->addend
+= 0x8000;
947 r_type
= reloc_entry
->howto
->type
;
948 if (r_type
!= R_PPC_REL16DX_HA
)
949 return bfd_reloc_continue
;
952 if (!bfd_is_com_section (symbol
->section
))
953 value
= symbol
->value
;
954 value
+= (reloc_entry
->addend
955 + symbol
->section
->output_offset
956 + symbol
->section
->output_section
->vma
);
957 value
-= (reloc_entry
->address
958 + input_section
->output_offset
959 + input_section
->output_section
->vma
);
962 octets
= reloc_entry
->address
* OCTETS_PER_BYTE (abfd
, input_section
);
963 insn
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ octets
);
965 insn
|= (value
& 0xffc1) | ((value
& 0x3e) << 15);
966 bfd_put_32 (abfd
, insn
, (bfd_byte
*) data
+ octets
);
970 static bfd_reloc_status_type
971 ppc_elf_unhandled_reloc (bfd
*abfd
,
972 arelent
*reloc_entry
,
975 asection
*input_section
,
977 char **error_message
)
979 /* If this is a relocatable link (output_bfd test tells us), just
980 call the generic function. Any adjustment will be done at final
982 if (output_bfd
!= NULL
)
983 return bfd_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
984 input_section
, output_bfd
, error_message
);
986 if (error_message
!= NULL
)
988 static char *message
;
990 if (asprintf (&message
, _("generic linker can't handle %s"),
991 reloc_entry
->howto
->name
) < 0)
993 *error_message
= message
;
995 return bfd_reloc_dangerous
;
998 /* Sections created by the linker. */
1000 typedef struct elf_linker_section
1002 /* Pointer to the bfd section. */
1006 /* Associated bss section name. */
1007 const char *bss_name
;
1008 /* Associated symbol name. */
1009 const char *sym_name
;
1010 /* Associated symbol. */
1011 struct elf_link_hash_entry
*sym
;
1012 } elf_linker_section_t
;
1014 /* Linked list of allocated pointer entries. This hangs off of the
1015 symbol lists, and provides allows us to return different pointers,
1016 based on different addend's. */
1018 typedef struct elf_linker_section_pointers
1020 /* next allocated pointer for this symbol */
1021 struct elf_linker_section_pointers
*next
;
1022 /* offset of pointer from beginning of section */
1026 /* which linker section this is */
1027 elf_linker_section_t
*lsect
;
1028 } elf_linker_section_pointers_t
;
1030 struct ppc_elf_obj_tdata
1032 struct elf_obj_tdata elf
;
1034 /* A mapping from local symbols to offsets into the various linker
1035 sections added. This is index by the symbol index. */
1036 elf_linker_section_pointers_t
**linker_section_pointers
;
1038 /* Flags used to auto-detect plt type. */
1039 unsigned int makes_plt_call
: 1;
1040 unsigned int has_rel16
: 1;
1043 #define ppc_elf_tdata(bfd) \
1044 ((struct ppc_elf_obj_tdata *) (bfd)->tdata.any)
1046 #define elf_local_ptr_offsets(bfd) \
1047 (ppc_elf_tdata (bfd)->linker_section_pointers)
1049 #define is_ppc_elf(bfd) \
1050 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
1051 && elf_object_id (bfd) == PPC32_ELF_DATA)
1053 /* Override the generic function because we store some extras. */
1056 ppc_elf_mkobject (bfd
*abfd
)
1058 return bfd_elf_allocate_object (abfd
, sizeof (struct ppc_elf_obj_tdata
),
1062 /* When defaulting arch/mach, decode apuinfo to find a better match. */
1065 _bfd_elf_ppc_set_arch (bfd
*abfd
)
1067 unsigned long mach
= 0;
1069 unsigned char *contents
;
1071 if (abfd
->arch_info
->bits_per_word
== 32
1072 && bfd_big_endian (abfd
))
1075 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
1076 if ((elf_section_data (s
)->this_hdr
.sh_flags
& SHF_PPC_VLE
) != 0)
1079 mach
= bfd_mach_ppc_vle
;
1084 s
= bfd_get_section_by_name (abfd
, APUINFO_SECTION_NAME
);
1087 && bfd_malloc_and_get_section (abfd
, s
, &contents
))
1089 unsigned int apuinfo_size
= bfd_get_32 (abfd
, contents
+ 4);
1092 for (i
= 20; i
< apuinfo_size
+ 20 && i
+ 4 <= s
->size
; i
+= 4)
1094 unsigned int val
= bfd_get_32 (abfd
, contents
+ i
);
1097 case PPC_APUINFO_PMR
:
1098 case PPC_APUINFO_RFMCI
:
1100 mach
= bfd_mach_ppc_titan
;
1103 case PPC_APUINFO_ISEL
:
1104 case PPC_APUINFO_CACHELCK
:
1105 if (mach
== bfd_mach_ppc_titan
)
1106 mach
= bfd_mach_ppc_e500mc
;
1109 case PPC_APUINFO_SPE
:
1110 case PPC_APUINFO_EFS
:
1111 case PPC_APUINFO_BRLOCK
:
1112 if (mach
!= bfd_mach_ppc_vle
)
1113 mach
= bfd_mach_ppc_e500
;
1116 case PPC_APUINFO_VLE
:
1117 mach
= bfd_mach_ppc_vle
;
1128 if (mach
!= 0 && mach
!= -1ul)
1130 const bfd_arch_info_type
*arch
;
1132 for (arch
= abfd
->arch_info
->next
; arch
; arch
= arch
->next
)
1133 if (arch
->mach
== mach
)
1135 abfd
->arch_info
= arch
;
1142 /* Fix bad default arch selected for a 32 bit input bfd when the
1143 default is 64 bit. Also select arch based on apuinfo. */
1146 ppc_elf_object_p (bfd
*abfd
)
1148 if (!abfd
->arch_info
->the_default
)
1151 if (abfd
->arch_info
->bits_per_word
== 64)
1153 Elf_Internal_Ehdr
*i_ehdr
= elf_elfheader (abfd
);
1155 if (i_ehdr
->e_ident
[EI_CLASS
] == ELFCLASS32
)
1157 /* Relies on arch after 64 bit default being 32 bit default. */
1158 abfd
->arch_info
= abfd
->arch_info
->next
;
1159 BFD_ASSERT (abfd
->arch_info
->bits_per_word
== 32);
1162 return _bfd_elf_ppc_set_arch (abfd
);
1165 /* Function to set whether a module needs the -mrelocatable bit set. */
1168 ppc_elf_set_private_flags (bfd
*abfd
, flagword flags
)
1170 BFD_ASSERT (!elf_flags_init (abfd
)
1171 || elf_elfheader (abfd
)->e_flags
== flags
);
1173 elf_elfheader (abfd
)->e_flags
= flags
;
1174 elf_flags_init (abfd
) = TRUE
;
1178 /* Support for core dump NOTE sections. */
1181 ppc_elf_grok_prstatus (bfd
*abfd
, Elf_Internal_Note
*note
)
1186 switch (note
->descsz
)
1191 case 268: /* Linux/PPC. */
1193 elf_tdata (abfd
)->core
->signal
= bfd_get_16 (abfd
, note
->descdata
+ 12);
1196 elf_tdata (abfd
)->core
->lwpid
= bfd_get_32 (abfd
, note
->descdata
+ 24);
1205 /* Make a ".reg/999" section. */
1206 return _bfd_elfcore_make_pseudosection (abfd
, ".reg",
1207 size
, note
->descpos
+ offset
);
1211 ppc_elf_grok_psinfo (bfd
*abfd
, Elf_Internal_Note
*note
)
1213 switch (note
->descsz
)
1218 case 128: /* Linux/PPC elf_prpsinfo. */
1219 elf_tdata (abfd
)->core
->pid
1220 = bfd_get_32 (abfd
, note
->descdata
+ 16);
1221 elf_tdata (abfd
)->core
->program
1222 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 32, 16);
1223 elf_tdata (abfd
)->core
->command
1224 = _bfd_elfcore_strndup (abfd
, note
->descdata
+ 48, 80);
1227 /* Note that for some reason, a spurious space is tacked
1228 onto the end of the args in some (at least one anyway)
1229 implementations, so strip it off if it exists. */
1232 char *command
= elf_tdata (abfd
)->core
->command
;
1233 int n
= strlen (command
);
1235 if (0 < n
&& command
[n
- 1] == ' ')
1236 command
[n
- 1] = '\0';
1243 ppc_elf_write_core_note (bfd
*abfd
, char *buf
, int *bufsiz
, int note_type
, ...)
1252 char data
[128] ATTRIBUTE_NONSTRING
;
1255 va_start (ap
, note_type
);
1256 memset (data
, 0, sizeof (data
));
1257 strncpy (data
+ 32, va_arg (ap
, const char *), 16);
1258 #if GCC_VERSION == 8000 || GCC_VERSION == 8001
1260 /* GCC 8.0 and 8.1 warn about 80 equals destination size with
1261 -Wstringop-truncation:
1262 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85643
1264 DIAGNOSTIC_IGNORE_STRINGOP_TRUNCATION
;
1266 strncpy (data
+ 48, va_arg (ap
, const char *), 80);
1267 #if GCC_VERSION == 8000 || GCC_VERSION == 8001
1271 return elfcore_write_note (abfd
, buf
, bufsiz
,
1272 "CORE", note_type
, data
, sizeof (data
));
1283 va_start (ap
, note_type
);
1284 memset (data
, 0, 72);
1285 pid
= va_arg (ap
, long);
1286 bfd_put_32 (abfd
, pid
, data
+ 24);
1287 cursig
= va_arg (ap
, int);
1288 bfd_put_16 (abfd
, cursig
, data
+ 12);
1289 greg
= va_arg (ap
, const void *);
1290 memcpy (data
+ 72, greg
, 192);
1291 memset (data
+ 264, 0, 4);
1293 return elfcore_write_note (abfd
, buf
, bufsiz
,
1294 "CORE", note_type
, data
, sizeof (data
));
1300 ppc_elf_lookup_section_flags (char *flag_name
)
1303 if (!strcmp (flag_name
, "SHF_PPC_VLE"))
1309 /* Return address for Ith PLT stub in section PLT, for relocation REL
1310 or (bfd_vma) -1 if it should not be included. */
1313 ppc_elf_plt_sym_val (bfd_vma i ATTRIBUTE_UNUSED
,
1314 const asection
*plt ATTRIBUTE_UNUSED
,
1317 return rel
->address
;
1320 /* Handle a PowerPC specific section when reading an object file. This
1321 is called when bfd_section_from_shdr finds a section with an unknown
1325 ppc_elf_section_from_shdr (bfd
*abfd
,
1326 Elf_Internal_Shdr
*hdr
,
1333 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
, shindex
))
1336 newsect
= hdr
->bfd_section
;
1338 if (hdr
->sh_flags
& SHF_EXCLUDE
)
1339 flags
|= SEC_EXCLUDE
;
1341 if (hdr
->sh_type
== SHT_ORDERED
)
1342 flags
|= SEC_SORT_ENTRIES
;
1344 if (strncmp (name
, ".PPC.EMB", 8) == 0)
1346 if (strncmp (name
, ".sbss", 5) == 0
1347 || strncmp (name
, ".sdata", 6) == 0)
1348 flags
|= SEC_SMALL_DATA
;
1351 || bfd_set_section_flags (newsect
, newsect
->flags
| flags
));
1354 /* Set up any other section flags and such that may be necessary. */
1357 ppc_elf_fake_sections (bfd
*abfd ATTRIBUTE_UNUSED
,
1358 Elf_Internal_Shdr
*shdr
,
1361 if ((asect
->flags
& SEC_SORT_ENTRIES
) != 0)
1362 shdr
->sh_type
= SHT_ORDERED
;
1367 /* If we have .sbss2 or .PPC.EMB.sbss0 output sections, we
1368 need to bump up the number of section headers. */
1371 ppc_elf_additional_program_headers (bfd
*abfd
,
1372 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
1377 s
= bfd_get_section_by_name (abfd
, ".sbss2");
1378 if (s
!= NULL
&& (s
->flags
& SEC_ALLOC
) != 0)
1381 s
= bfd_get_section_by_name (abfd
, ".PPC.EMB.sbss0");
1382 if (s
!= NULL
&& (s
->flags
& SEC_ALLOC
) != 0)
1388 /* Modify the segment map for VLE executables. */
1391 ppc_elf_modify_segment_map (bfd
*abfd
,
1392 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
1394 struct elf_segment_map
*m
;
1396 /* At this point in the link, output sections have already been sorted by
1397 LMA and assigned to segments. All that is left to do is to ensure
1398 there is no mixing of VLE & non-VLE sections in a text segment.
1399 If we find that case, we split the segment.
1400 We maintain the original output section order. */
1402 for (m
= elf_seg_map (abfd
); m
!= NULL
; m
= m
->next
)
1404 struct elf_segment_map
*n
;
1407 unsigned int p_flags
;
1409 if (m
->p_type
!= PT_LOAD
|| m
->count
== 0)
1412 for (p_flags
= PF_R
, j
= 0; j
!= m
->count
; ++j
)
1414 if ((m
->sections
[j
]->flags
& SEC_READONLY
) == 0)
1416 if ((m
->sections
[j
]->flags
& SEC_CODE
) != 0)
1419 if ((elf_section_flags (m
->sections
[j
]) & SHF_PPC_VLE
) != 0)
1420 p_flags
|= PF_PPC_VLE
;
1425 while (++j
!= m
->count
)
1427 unsigned int p_flags1
= PF_R
;
1429 if ((m
->sections
[j
]->flags
& SEC_READONLY
) == 0)
1431 if ((m
->sections
[j
]->flags
& SEC_CODE
) != 0)
1434 if ((elf_section_flags (m
->sections
[j
]) & SHF_PPC_VLE
) != 0)
1435 p_flags1
|= PF_PPC_VLE
;
1436 if (((p_flags1
^ p_flags
) & PF_PPC_VLE
) != 0)
1439 p_flags
|= p_flags1
;
1441 /* If we're splitting a segment which originally contained rw
1442 sections then those sections might now only be in one of the
1443 two parts. So always set p_flags if splitting, even if we
1444 are being called for objcopy with p_flags_valid set. */
1445 if (j
!= m
->count
|| !m
->p_flags_valid
)
1447 m
->p_flags_valid
= 1;
1448 m
->p_flags
= p_flags
;
1453 /* Sections 0..j-1 stay in this (current) segment,
1454 the remainder are put in a new segment.
1455 The scan resumes with the new segment. */
1457 amt
= sizeof (struct elf_segment_map
);
1458 amt
+= (m
->count
- j
- 1) * sizeof (asection
*);
1459 n
= (struct elf_segment_map
*) bfd_zalloc (abfd
, amt
);
1463 n
->p_type
= PT_LOAD
;
1464 n
->count
= m
->count
- j
;
1465 for (k
= 0; k
< n
->count
; ++k
)
1466 n
->sections
[k
] = m
->sections
[j
+ k
];
1468 m
->p_size_valid
= 0;
1476 /* Add extra PPC sections -- Note, for now, make .sbss2 and
1477 .PPC.EMB.sbss0 a normal section, and not a bss section so
1478 that the linker doesn't crater when trying to make more than
1481 static const struct bfd_elf_special_section ppc_elf_special_sections
[] =
1483 { STRING_COMMA_LEN (".plt"), 0, SHT_NOBITS
, SHF_ALLOC
+ SHF_EXECINSTR
},
1484 { STRING_COMMA_LEN (".sbss"), -2, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
},
1485 { STRING_COMMA_LEN (".sbss2"), -2, SHT_PROGBITS
, SHF_ALLOC
},
1486 { STRING_COMMA_LEN (".sdata"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
},
1487 { STRING_COMMA_LEN (".sdata2"), -2, SHT_PROGBITS
, SHF_ALLOC
},
1488 { STRING_COMMA_LEN (".tags"), 0, SHT_ORDERED
, SHF_ALLOC
},
1489 { STRING_COMMA_LEN (APUINFO_SECTION_NAME
), 0, SHT_NOTE
, 0 },
1490 { STRING_COMMA_LEN (".PPC.EMB.sbss0"), 0, SHT_PROGBITS
, SHF_ALLOC
},
1491 { STRING_COMMA_LEN (".PPC.EMB.sdata0"), 0, SHT_PROGBITS
, SHF_ALLOC
},
1492 { NULL
, 0, 0, 0, 0 }
1495 /* This is what we want for new plt/got. */
1496 static const struct bfd_elf_special_section ppc_alt_plt
=
1497 { STRING_COMMA_LEN (".plt"), 0, SHT_PROGBITS
, SHF_ALLOC
};
1499 static const struct bfd_elf_special_section
*
1500 ppc_elf_get_sec_type_attr (bfd
*abfd
, asection
*sec
)
1502 const struct bfd_elf_special_section
*ssect
;
1504 /* See if this is one of the special sections. */
1505 if (sec
->name
== NULL
)
1508 ssect
= _bfd_elf_get_special_section (sec
->name
, ppc_elf_special_sections
,
1512 if (ssect
== ppc_elf_special_sections
&& (sec
->flags
& SEC_LOAD
) != 0)
1513 ssect
= &ppc_alt_plt
;
1517 return _bfd_elf_get_sec_type_attr (abfd
, sec
);
1520 /* Very simple linked list structure for recording apuinfo values. */
1521 typedef struct apuinfo_list
1523 struct apuinfo_list
*next
;
1524 unsigned long value
;
1528 static apuinfo_list
*head
;
1529 static bfd_boolean apuinfo_set
;
1532 apuinfo_list_init (void)
1535 apuinfo_set
= FALSE
;
1539 apuinfo_list_add (unsigned long value
)
1541 apuinfo_list
*entry
= head
;
1543 while (entry
!= NULL
)
1545 if (entry
->value
== value
)
1547 entry
= entry
->next
;
1550 entry
= bfd_malloc (sizeof (* entry
));
1554 entry
->value
= value
;
1560 apuinfo_list_length (void)
1562 apuinfo_list
*entry
;
1563 unsigned long count
;
1565 for (entry
= head
, count
= 0;
1567 entry
= entry
->next
)
1573 static inline unsigned long
1574 apuinfo_list_element (unsigned long number
)
1576 apuinfo_list
* entry
;
1580 entry
= entry
->next
)
1583 return entry
? entry
->value
: 0;
1587 apuinfo_list_finish (void)
1589 apuinfo_list
*entry
;
1591 for (entry
= head
; entry
;)
1593 apuinfo_list
*next
= entry
->next
;
1601 /* Scan the input BFDs and create a linked list of
1602 the APUinfo values that will need to be emitted. */
1605 ppc_elf_begin_write_processing (bfd
*abfd
, struct bfd_link_info
*link_info
)
1609 char *buffer
= NULL
;
1610 bfd_size_type largest_input_size
= 0;
1612 unsigned long length
;
1613 const char *error_message
= NULL
;
1615 if (link_info
== NULL
)
1618 apuinfo_list_init ();
1620 /* Read in the input sections contents. */
1621 for (ibfd
= link_info
->input_bfds
; ibfd
; ibfd
= ibfd
->link
.next
)
1623 unsigned long datum
;
1625 asec
= bfd_get_section_by_name (ibfd
, APUINFO_SECTION_NAME
);
1629 /* xgettext:c-format */
1630 error_message
= _("corrupt %s section in %pB");
1631 length
= asec
->size
;
1636 if (largest_input_size
< asec
->size
)
1639 largest_input_size
= asec
->size
;
1640 buffer
= bfd_malloc (largest_input_size
);
1645 if (bfd_seek (ibfd
, asec
->filepos
, SEEK_SET
) != 0
1646 || (bfd_bread (buffer
, length
, ibfd
) != length
))
1648 /* xgettext:c-format */
1649 error_message
= _("unable to read in %s section from %pB");
1653 /* Verify the contents of the header. Note - we have to
1654 extract the values this way in order to allow for a
1655 host whose endian-ness is different from the target. */
1656 datum
= bfd_get_32 (ibfd
, buffer
);
1657 if (datum
!= sizeof APUINFO_LABEL
)
1660 datum
= bfd_get_32 (ibfd
, buffer
+ 8);
1664 if (strcmp (buffer
+ 12, APUINFO_LABEL
) != 0)
1667 /* Get the number of bytes used for apuinfo entries. */
1668 datum
= bfd_get_32 (ibfd
, buffer
+ 4);
1669 if (datum
+ 20 != length
)
1672 /* Scan the apuinfo section, building a list of apuinfo numbers. */
1673 for (i
= 0; i
< datum
; i
+= 4)
1674 apuinfo_list_add (bfd_get_32 (ibfd
, buffer
+ 20 + i
));
1677 error_message
= NULL
;
1681 /* Compute the size of the output section. */
1682 unsigned num_entries
= apuinfo_list_length ();
1684 /* Set the output section size, if it exists. */
1685 asec
= bfd_get_section_by_name (abfd
, APUINFO_SECTION_NAME
);
1687 if (asec
&& !bfd_set_section_size (asec
, 20 + num_entries
* 4))
1690 /* xgettext:c-format */
1691 error_message
= _("warning: unable to set size of %s section in %pB");
1699 _bfd_error_handler (error_message
, APUINFO_SECTION_NAME
, ibfd
);
1702 /* Prevent the output section from accumulating the input sections'
1703 contents. We have already stored this in our linked list structure. */
1706 ppc_elf_write_section (bfd
*abfd ATTRIBUTE_UNUSED
,
1707 struct bfd_link_info
*link_info ATTRIBUTE_UNUSED
,
1709 bfd_byte
*contents ATTRIBUTE_UNUSED
)
1711 return apuinfo_set
&& strcmp (asec
->name
, APUINFO_SECTION_NAME
) == 0;
1714 /* Finally we can generate the output section. */
1717 ppc_final_write_processing (bfd
*abfd
)
1722 unsigned num_entries
;
1723 bfd_size_type length
;
1725 asec
= bfd_get_section_by_name (abfd
, APUINFO_SECTION_NAME
);
1732 length
= asec
->size
;
1736 buffer
= bfd_malloc (length
);
1740 (_("failed to allocate space for new APUinfo section"));
1744 /* Create the apuinfo header. */
1745 num_entries
= apuinfo_list_length ();
1746 bfd_put_32 (abfd
, sizeof APUINFO_LABEL
, buffer
);
1747 bfd_put_32 (abfd
, num_entries
* 4, buffer
+ 4);
1748 bfd_put_32 (abfd
, 0x2, buffer
+ 8);
1749 strcpy ((char *) buffer
+ 12, APUINFO_LABEL
);
1752 for (i
= 0; i
< num_entries
; i
++)
1754 bfd_put_32 (abfd
, apuinfo_list_element (i
), buffer
+ length
);
1758 if (length
!= asec
->size
)
1759 _bfd_error_handler (_("failed to compute new APUinfo section"));
1761 if (! bfd_set_section_contents (abfd
, asec
, buffer
, (file_ptr
) 0, length
))
1762 _bfd_error_handler (_("failed to install new APUinfo section"));
1766 apuinfo_list_finish ();
1770 ppc_elf_final_write_processing (bfd
*abfd
)
1772 ppc_final_write_processing (abfd
);
1773 return _bfd_elf_final_write_processing (abfd
);
1777 is_nonpic_glink_stub (bfd
*abfd
, asection
*glink
, bfd_vma off
)
1779 bfd_byte buf
[4 * 4];
1781 if (!bfd_get_section_contents (abfd
, glink
, buf
, off
, sizeof buf
))
1784 return ((bfd_get_32 (abfd
, buf
+ 0) & 0xffff0000) == LIS_11
1785 && (bfd_get_32 (abfd
, buf
+ 4) & 0xffff0000) == LWZ_11_11
1786 && bfd_get_32 (abfd
, buf
+ 8) == MTCTR_11
1787 && bfd_get_32 (abfd
, buf
+ 12) == BCTR
);
1791 section_covers_vma (bfd
*abfd ATTRIBUTE_UNUSED
, asection
*section
, void *ptr
)
1793 bfd_vma vma
= *(bfd_vma
*) ptr
;
1794 return ((section
->flags
& SEC_ALLOC
) != 0
1795 && section
->vma
<= vma
1796 && vma
< section
->vma
+ section
->size
);
1800 ppc_elf_get_synthetic_symtab (bfd
*abfd
, long symcount
, asymbol
**syms
,
1801 long dynsymcount
, asymbol
**dynsyms
,
1804 bfd_boolean (*slurp_relocs
) (bfd
*, asection
*, asymbol
**, bfd_boolean
);
1805 asection
*plt
, *relplt
, *dynamic
, *glink
;
1806 bfd_vma glink_vma
= 0;
1807 bfd_vma resolv_vma
= 0;
1811 size_t count
, i
, stub_delta
;
1818 if ((abfd
->flags
& (DYNAMIC
| EXEC_P
)) == 0)
1821 if (dynsymcount
<= 0)
1824 relplt
= bfd_get_section_by_name (abfd
, ".rela.plt");
1828 plt
= bfd_get_section_by_name (abfd
, ".plt");
1832 /* Call common code to handle old-style executable PLTs. */
1833 if (elf_section_flags (plt
) & SHF_EXECINSTR
)
1834 return _bfd_elf_get_synthetic_symtab (abfd
, symcount
, syms
,
1835 dynsymcount
, dynsyms
, ret
);
1837 /* If this object was prelinked, the prelinker stored the address
1838 of .glink at got[1]. If it wasn't prelinked, got[1] will be zero. */
1839 dynamic
= bfd_get_section_by_name (abfd
, ".dynamic");
1840 if (dynamic
!= NULL
)
1842 bfd_byte
*dynbuf
, *extdyn
, *extdynend
;
1844 void (*swap_dyn_in
) (bfd
*, const void *, Elf_Internal_Dyn
*);
1846 if (!bfd_malloc_and_get_section (abfd
, dynamic
, &dynbuf
))
1849 extdynsize
= get_elf_backend_data (abfd
)->s
->sizeof_dyn
;
1850 swap_dyn_in
= get_elf_backend_data (abfd
)->s
->swap_dyn_in
;
1853 extdynend
= extdyn
+ dynamic
->size
;
1854 for (; extdyn
< extdynend
; extdyn
+= extdynsize
)
1856 Elf_Internal_Dyn dyn
;
1857 (*swap_dyn_in
) (abfd
, extdyn
, &dyn
);
1859 if (dyn
.d_tag
== DT_NULL
)
1862 if (dyn
.d_tag
== DT_PPC_GOT
)
1864 unsigned int g_o_t
= dyn
.d_un
.d_val
;
1865 asection
*got
= bfd_get_section_by_name (abfd
, ".got");
1867 && bfd_get_section_contents (abfd
, got
, buf
,
1868 g_o_t
- got
->vma
+ 4, 4))
1869 glink_vma
= bfd_get_32 (abfd
, buf
);
1876 /* Otherwise we read the first plt entry. */
1879 if (bfd_get_section_contents (abfd
, plt
, buf
, 0, 4))
1880 glink_vma
= bfd_get_32 (abfd
, buf
);
1886 /* The .glink section usually does not survive the final
1887 link; search for the section (usually .text) where the
1888 glink stubs now reside. */
1889 glink
= bfd_sections_find_if (abfd
, section_covers_vma
, &glink_vma
);
1893 /* Determine glink PLT resolver by reading the relative branch
1894 from the first glink stub. */
1895 if (bfd_get_section_contents (abfd
, glink
, buf
,
1896 glink_vma
- glink
->vma
, 4))
1898 unsigned int insn
= bfd_get_32 (abfd
, buf
);
1900 /* The first glink stub may either branch to the resolver ... */
1902 if ((insn
& ~0x3fffffc) == 0)
1903 resolv_vma
= glink_vma
+ (insn
^ 0x2000000) - 0x2000000;
1905 /* ... or fall through a bunch of NOPs. */
1906 else if ((insn
^ B
^ NOP
) == 0)
1908 bfd_get_section_contents (abfd
, glink
, buf
,
1909 glink_vma
- glink
->vma
+ i
, 4);
1911 if (bfd_get_32 (abfd
, buf
) != NOP
)
1913 resolv_vma
= glink_vma
+ i
;
1918 count
= relplt
->size
/ sizeof (Elf32_External_Rela
);
1919 /* If the stubs are those for -shared/-pie then we might have
1920 multiple stubs for each plt entry. If that is the case then
1921 there is no way to associate stubs with their plt entries short
1922 of figuring out the GOT pointer value used in the stub.
1923 The offsets tested here need to cover all possible values of
1924 GLINK_ENTRY_SIZE for other than __tls_get_addr_opt. */
1925 stub_off
= glink_vma
- glink
->vma
;
1926 for (stub_delta
= 16; stub_delta
<= 32; stub_delta
+= 8)
1927 if (is_nonpic_glink_stub (abfd
, glink
, stub_off
- stub_delta
))
1929 if (stub_delta
> 32)
1932 slurp_relocs
= get_elf_backend_data (abfd
)->s
->slurp_reloc_table
;
1933 if (! (*slurp_relocs
) (abfd
, relplt
, dynsyms
, TRUE
))
1936 size
= count
* sizeof (asymbol
);
1937 p
= relplt
->relocation
;
1938 for (i
= 0; i
< count
; i
++, p
++)
1940 size
+= strlen ((*p
->sym_ptr_ptr
)->name
) + sizeof ("@plt");
1942 size
+= sizeof ("+0x") - 1 + 8;
1945 size
+= sizeof (asymbol
) + sizeof ("__glink");
1948 size
+= sizeof (asymbol
) + sizeof ("__glink_PLTresolve");
1950 s
= *ret
= bfd_malloc (size
);
1954 stub_off
= glink_vma
- glink
->vma
;
1955 names
= (char *) (s
+ count
+ 1 + (resolv_vma
!= 0));
1956 p
= relplt
->relocation
+ count
- 1;
1957 for (i
= 0; i
< count
; i
++)
1961 stub_off
-= stub_delta
;
1962 if (strcmp ((*p
->sym_ptr_ptr
)->name
, "__tls_get_addr_opt") == 0)
1964 *s
= **p
->sym_ptr_ptr
;
1965 /* Undefined syms won't have BSF_LOCAL or BSF_GLOBAL set. Since
1966 we are defining a symbol, ensure one of them is set. */
1967 if ((s
->flags
& BSF_LOCAL
) == 0)
1968 s
->flags
|= BSF_GLOBAL
;
1969 s
->flags
|= BSF_SYNTHETIC
;
1971 s
->value
= stub_off
;
1974 len
= strlen ((*p
->sym_ptr_ptr
)->name
);
1975 memcpy (names
, (*p
->sym_ptr_ptr
)->name
, len
);
1979 memcpy (names
, "+0x", sizeof ("+0x") - 1);
1980 names
+= sizeof ("+0x") - 1;
1981 bfd_sprintf_vma (abfd
, names
, p
->addend
);
1982 names
+= strlen (names
);
1984 memcpy (names
, "@plt", sizeof ("@plt"));
1985 names
+= sizeof ("@plt");
1990 /* Add a symbol at the start of the glink branch table. */
1991 memset (s
, 0, sizeof *s
);
1993 s
->flags
= BSF_GLOBAL
| BSF_SYNTHETIC
;
1995 s
->value
= glink_vma
- glink
->vma
;
1997 memcpy (names
, "__glink", sizeof ("__glink"));
1998 names
+= sizeof ("__glink");
2004 /* Add a symbol for the glink PLT resolver. */
2005 memset (s
, 0, sizeof *s
);
2007 s
->flags
= BSF_GLOBAL
| BSF_SYNTHETIC
;
2009 s
->value
= resolv_vma
- glink
->vma
;
2011 memcpy (names
, "__glink_PLTresolve", sizeof ("__glink_PLTresolve"));
2012 names
+= sizeof ("__glink_PLTresolve");
2020 /* The following functions are specific to the ELF linker, while
2021 functions above are used generally. They appear in this file more
2022 or less in the order in which they are called. eg.
2023 ppc_elf_check_relocs is called early in the link process,
2024 ppc_elf_finish_dynamic_sections is one of the last functions
2027 /* Track PLT entries needed for a given symbol. We might need more
2028 than one glink entry per symbol when generating a pic binary. */
2031 struct plt_entry
*next
;
2033 /* -fPIC uses multiple GOT sections, one per file, called ".got2".
2034 This field stores the offset into .got2 used to initialise the
2035 GOT pointer reg. It will always be at least 32768. (Current
2036 gcc always uses an offset of 32768, but ld -r will pack .got2
2037 sections together resulting in larger offsets). */
2040 /* The .got2 section. */
2043 /* PLT refcount or offset. */
2046 bfd_signed_vma refcount
;
2050 /* .glink stub offset. */
2051 bfd_vma glink_offset
;
2054 /* Of those relocs that might be copied as dynamic relocs, this
2055 function selects those that must be copied when linking a shared
2056 library or PIE, even when the symbol is local. */
2059 must_be_dyn_reloc (struct bfd_link_info
*info
,
2060 enum elf_ppc_reloc_type r_type
)
2065 /* Only relative relocs can be resolved when the object load
2066 address isn't fixed. DTPREL32 is excluded because the
2067 dynamic linker needs to differentiate global dynamic from
2068 local dynamic __tls_index pairs when PPC_OPT_TLS is set. */
2073 case R_PPC_REL14_BRTAKEN
:
2074 case R_PPC_REL14_BRNTAKEN
:
2080 case R_PPC_TPREL16_LO
:
2081 case R_PPC_TPREL16_HI
:
2082 case R_PPC_TPREL16_HA
:
2083 /* These relocations are relative but in a shared library the
2084 linker doesn't know the thread pointer base. */
2085 return bfd_link_dll (info
);
2089 /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
2090 copying dynamic variables from a shared lib into an app's dynbss
2091 section, and instead use a dynamic relocation to point into the
2093 #define ELIMINATE_COPY_RELOCS 1
2095 /* Used to track dynamic relocations for local symbols. */
2096 struct ppc_dyn_relocs
2098 struct ppc_dyn_relocs
*next
;
2100 /* The input section of the reloc. */
2103 /* Total number of relocs copied for the input section. */
2104 unsigned int count
: 31;
2106 /* Whether this entry is for STT_GNU_IFUNC symbols. */
2107 unsigned int ifunc
: 1;
2110 /* PPC ELF linker hash entry. */
2112 struct ppc_elf_link_hash_entry
2114 struct elf_link_hash_entry elf
;
2116 /* If this symbol is used in the linker created sections, the processor
2117 specific backend uses this field to map the field into the offset
2118 from the beginning of the section. */
2119 elf_linker_section_pointers_t
*linker_section_pointer
;
2121 /* Contexts in which symbol is used in the GOT.
2122 Bits are or'd into the mask as the corresponding relocs are
2123 encountered during check_relocs, with TLS_TLS being set when any
2124 of the other TLS bits are set. tls_optimize clears bits when
2125 optimizing to indicate the corresponding GOT entry type is not
2126 needed. If set, TLS_TLS is never cleared. tls_optimize may also
2127 set TLS_GDIE when a GD reloc turns into an IE one.
2128 These flags are also kept for local symbols. */
2129 #define TLS_TLS 1 /* Any TLS reloc. */
2130 #define TLS_GD 2 /* GD reloc. */
2131 #define TLS_LD 4 /* LD reloc. */
2132 #define TLS_TPREL 8 /* TPREL reloc, => IE. */
2133 #define TLS_DTPREL 16 /* DTPREL reloc, => LD. */
2134 #define TLS_MARK 32 /* __tls_get_addr call marked. */
2135 #define TLS_GDIE 64 /* GOT TPREL reloc resulting from GD->IE. */
2136 unsigned char tls_mask
;
2138 /* The above field is also used to mark function symbols. In which
2139 case TLS_TLS will be 0. */
2140 #define PLT_IFUNC 2 /* STT_GNU_IFUNC. */
2141 #define PLT_KEEP 4 /* inline plt call requires plt entry. */
2142 #define NON_GOT 256 /* local symbol plt, not stored. */
2144 /* Nonzero if we have seen a small data relocation referring to this
2146 unsigned char has_sda_refs
: 1;
2148 /* Flag use of given relocations. */
2149 unsigned char has_addr16_ha
: 1;
2150 unsigned char has_addr16_lo
: 1;
2153 #define ppc_elf_hash_entry(ent) ((struct ppc_elf_link_hash_entry *) (ent))
2155 /* PPC ELF linker hash table. */
2157 struct ppc_elf_link_hash_table
2159 struct elf_link_hash_table elf
;
2161 /* Various options passed from the linker. */
2162 struct ppc_elf_params
*params
;
2164 /* Short-cuts to get to dynamic linker sections. */
2168 elf_linker_section_t sdata
[2];
2170 asection
*glink_eh_frame
;
2172 asection
*relpltlocal
;
2174 /* The (unloaded but important) .rela.plt.unloaded on VxWorks. */
2177 /* Shortcut to __tls_get_addr. */
2178 struct elf_link_hash_entry
*tls_get_addr
;
2180 /* The bfd that forced an old-style PLT. */
2183 /* TLS local dynamic got entry handling. */
2185 bfd_signed_vma refcount
;
2189 /* Offset of branch table to PltResolve function in glink. */
2190 bfd_vma glink_pltresolve
;
2192 /* Size of reserved GOT entries. */
2193 unsigned int got_header_size
;
2194 /* Non-zero if allocating the header left a gap. */
2195 unsigned int got_gap
;
2197 /* The type of PLT we have chosen to use. */
2198 enum ppc_elf_plt_type plt_type
;
2200 /* Whether there exist local gnu indirect function resolvers,
2201 referenced by dynamic relocations. */
2202 unsigned int local_ifunc_resolver
:1;
2203 unsigned int maybe_local_ifunc_resolver
:1;
2205 /* Set if tls optimization is enabled. */
2206 unsigned int do_tls_opt
:1;
2208 /* Set if inline plt calls should be converted to direct calls. */
2209 unsigned int can_convert_all_inline_plt
:1;
2211 /* The size of PLT entries. */
2213 /* The distance between adjacent PLT slots. */
2215 /* The size of the first PLT entry. */
2216 int plt_initial_entry_size
;
2219 /* Rename some of the generic section flags to better document how they
2220 are used for ppc32. The flags are only valid for ppc32 elf objects. */
2222 /* Nonzero if this section has TLS related relocations. */
2223 #define has_tls_reloc sec_flg0
2225 /* Nonzero if this section has a call to __tls_get_addr lacking marker
2227 #define nomark_tls_get_addr sec_flg1
2229 /* Flag set when PLTCALL relocs are detected. */
2230 #define has_pltcall sec_flg2
2232 /* Get the PPC ELF linker hash table from a link_info structure. */
2234 #define ppc_elf_hash_table(p) \
2235 ((is_elf_hash_table ((p)->hash) \
2236 && elf_hash_table_id (elf_hash_table (p)) == PPC32_ELF_DATA) \
2237 ? (struct ppc_elf_link_hash_table *) (p)->hash : NULL)
2239 /* Create an entry in a PPC ELF linker hash table. */
2241 static struct bfd_hash_entry
*
2242 ppc_elf_link_hash_newfunc (struct bfd_hash_entry
*entry
,
2243 struct bfd_hash_table
*table
,
2246 /* Allocate the structure if it has not already been allocated by a
2250 entry
= bfd_hash_allocate (table
,
2251 sizeof (struct ppc_elf_link_hash_entry
));
2256 /* Call the allocation method of the superclass. */
2257 entry
= _bfd_elf_link_hash_newfunc (entry
, table
, string
);
2260 ppc_elf_hash_entry (entry
)->linker_section_pointer
= NULL
;
2261 ppc_elf_hash_entry (entry
)->tls_mask
= 0;
2262 ppc_elf_hash_entry (entry
)->has_sda_refs
= 0;
2268 /* Create a PPC ELF linker hash table. */
2270 static struct bfd_link_hash_table
*
2271 ppc_elf_link_hash_table_create (bfd
*abfd
)
2273 struct ppc_elf_link_hash_table
*ret
;
2274 static struct ppc_elf_params default_params
2275 = { PLT_OLD
, 0, 0, 1, 0, 0, 12, 0, 0, 0 };
2277 ret
= bfd_zmalloc (sizeof (struct ppc_elf_link_hash_table
));
2281 if (!_bfd_elf_link_hash_table_init (&ret
->elf
, abfd
,
2282 ppc_elf_link_hash_newfunc
,
2283 sizeof (struct ppc_elf_link_hash_entry
),
2290 ret
->elf
.init_plt_refcount
.refcount
= 0;
2291 ret
->elf
.init_plt_refcount
.glist
= NULL
;
2292 ret
->elf
.init_plt_offset
.offset
= 0;
2293 ret
->elf
.init_plt_offset
.glist
= NULL
;
2295 ret
->params
= &default_params
;
2297 ret
->sdata
[0].name
= ".sdata";
2298 ret
->sdata
[0].sym_name
= "_SDA_BASE_";
2299 ret
->sdata
[0].bss_name
= ".sbss";
2301 ret
->sdata
[1].name
= ".sdata2";
2302 ret
->sdata
[1].sym_name
= "_SDA2_BASE_";
2303 ret
->sdata
[1].bss_name
= ".sbss2";
2305 ret
->plt_entry_size
= 12;
2306 ret
->plt_slot_size
= 8;
2307 ret
->plt_initial_entry_size
= 72;
2309 return &ret
->elf
.root
;
2312 /* Hook linker params into hash table. */
2315 ppc_elf_link_params (struct bfd_link_info
*info
, struct ppc_elf_params
*params
)
2317 struct ppc_elf_link_hash_table
*htab
= ppc_elf_hash_table (info
);
2320 htab
->params
= params
;
2321 params
->pagesize_p2
= bfd_log2 (params
->pagesize
);
2324 /* Create .got and the related sections. */
2327 ppc_elf_create_got (bfd
*abfd
, struct bfd_link_info
*info
)
2329 struct ppc_elf_link_hash_table
*htab
;
2331 if (!_bfd_elf_create_got_section (abfd
, info
))
2334 htab
= ppc_elf_hash_table (info
);
2335 if (htab
->elf
.target_os
!= is_vxworks
)
2337 /* The powerpc .got has a blrl instruction in it. Mark it
2339 flagword flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_CODE
| SEC_HAS_CONTENTS
2340 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
2341 if (!bfd_set_section_flags (htab
->elf
.sgot
, flags
))
2348 /* Create a special linker section, used for R_PPC_EMB_SDAI16 and
2349 R_PPC_EMB_SDA2I16 pointers. These sections become part of .sdata
2350 and .sdata2. Create _SDA_BASE_ and _SDA2_BASE too. */
2353 ppc_elf_create_linker_section (bfd
*abfd
,
2354 struct bfd_link_info
*info
,
2356 elf_linker_section_t
*lsect
)
2360 flags
|= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
2361 | SEC_LINKER_CREATED
);
2363 s
= bfd_make_section_anyway_with_flags (abfd
, lsect
->name
, flags
);
2368 /* Define the sym on the first section of this name. */
2369 s
= bfd_get_section_by_name (abfd
, lsect
->name
);
2371 lsect
->sym
= _bfd_elf_define_linkage_sym (abfd
, info
, s
, lsect
->sym_name
);
2372 if (lsect
->sym
== NULL
)
2374 lsect
->sym
->root
.u
.def
.value
= 0x8000;
2379 ppc_elf_create_glink (bfd
*abfd
, struct bfd_link_info
*info
)
2381 struct ppc_elf_link_hash_table
*htab
= ppc_elf_hash_table (info
);
2386 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_CODE
| SEC_READONLY
| SEC_HAS_CONTENTS
2387 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
2388 s
= bfd_make_section_anyway_with_flags (abfd
, ".glink", flags
);
2390 p2align
= htab
->params
->ppc476_workaround
? 6 : 4;
2391 if (p2align
< htab
->params
->plt_stub_align
)
2392 p2align
= htab
->params
->plt_stub_align
;
2394 || !bfd_set_section_alignment (s
, p2align
))
2397 if (!info
->no_ld_generated_unwind_info
)
2399 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
| SEC_HAS_CONTENTS
2400 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
2401 s
= bfd_make_section_anyway_with_flags (abfd
, ".eh_frame", flags
);
2402 htab
->glink_eh_frame
= s
;
2404 || !bfd_set_section_alignment (s
, 2))
2408 flags
= SEC_ALLOC
| SEC_LINKER_CREATED
;
2409 s
= bfd_make_section_anyway_with_flags (abfd
, ".iplt", flags
);
2412 || !bfd_set_section_alignment (s
, 4))
2415 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
| SEC_HAS_CONTENTS
2416 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
2417 s
= bfd_make_section_anyway_with_flags (abfd
, ".rela.iplt", flags
);
2418 htab
->elf
.irelplt
= s
;
2420 || ! bfd_set_section_alignment (s
, 2))
2423 /* Local plt entries. */
2424 flags
= (SEC_ALLOC
| SEC_LOAD
2425 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
2426 htab
->pltlocal
= bfd_make_section_anyway_with_flags (abfd
, ".branch_lt",
2428 if (htab
->pltlocal
== NULL
2429 || !bfd_set_section_alignment (htab
->pltlocal
, 2))
2432 if (bfd_link_pic (info
))
2434 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
2435 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
2437 = bfd_make_section_anyway_with_flags (abfd
, ".rela.branch_lt", flags
);
2438 if (htab
->relpltlocal
== NULL
2439 || !bfd_set_section_alignment (htab
->relpltlocal
, 2))
2443 if (!ppc_elf_create_linker_section (abfd
, info
, 0,
2447 if (!ppc_elf_create_linker_section (abfd
, info
, SEC_READONLY
,
2454 /* We have to create .dynsbss and .rela.sbss here so that they get mapped
2455 to output sections (just like _bfd_elf_create_dynamic_sections has
2456 to create .dynbss and .rela.bss). */
2459 ppc_elf_create_dynamic_sections (bfd
*abfd
, struct bfd_link_info
*info
)
2461 struct ppc_elf_link_hash_table
*htab
;
2465 htab
= ppc_elf_hash_table (info
);
2467 if (htab
->elf
.sgot
== NULL
2468 && !ppc_elf_create_got (abfd
, info
))
2471 if (!_bfd_elf_create_dynamic_sections (abfd
, info
))
2474 if (htab
->glink
== NULL
2475 && !ppc_elf_create_glink (abfd
, info
))
2478 s
= bfd_make_section_anyway_with_flags (abfd
, ".dynsbss",
2479 SEC_ALLOC
| SEC_LINKER_CREATED
);
2484 if (! bfd_link_pic (info
))
2486 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
| SEC_HAS_CONTENTS
2487 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
2488 s
= bfd_make_section_anyway_with_flags (abfd
, ".rela.sbss", flags
);
2491 || !bfd_set_section_alignment (s
, 2))
2495 if (htab
->elf
.target_os
== is_vxworks
2496 && !elf_vxworks_create_dynamic_sections (abfd
, info
, &htab
->srelplt2
))
2500 flags
= SEC_ALLOC
| SEC_CODE
| SEC_LINKER_CREATED
;
2501 if (htab
->plt_type
== PLT_VXWORKS
)
2502 /* The VxWorks PLT is a loaded section with contents. */
2503 flags
|= SEC_HAS_CONTENTS
| SEC_LOAD
| SEC_READONLY
;
2504 return bfd_set_section_flags (s
, flags
);
2507 /* Copy the extra info we tack onto an elf_link_hash_entry. */
2510 ppc_elf_copy_indirect_symbol (struct bfd_link_info
*info
,
2511 struct elf_link_hash_entry
*dir
,
2512 struct elf_link_hash_entry
*ind
)
2514 struct ppc_elf_link_hash_entry
*edir
, *eind
;
2516 edir
= (struct ppc_elf_link_hash_entry
*) dir
;
2517 eind
= (struct ppc_elf_link_hash_entry
*) ind
;
2519 edir
->tls_mask
|= eind
->tls_mask
;
2520 edir
->has_sda_refs
|= eind
->has_sda_refs
;
2522 if (edir
->elf
.versioned
!= versioned_hidden
)
2523 edir
->elf
.ref_dynamic
|= eind
->elf
.ref_dynamic
;
2524 edir
->elf
.ref_regular
|= eind
->elf
.ref_regular
;
2525 edir
->elf
.ref_regular_nonweak
|= eind
->elf
.ref_regular_nonweak
;
2526 edir
->elf
.non_got_ref
|= eind
->elf
.non_got_ref
;
2527 edir
->elf
.needs_plt
|= eind
->elf
.needs_plt
;
2528 edir
->elf
.pointer_equality_needed
|= eind
->elf
.pointer_equality_needed
;
2530 /* If we were called to copy over info for a weak sym, that's all. */
2531 if (eind
->elf
.root
.type
!= bfd_link_hash_indirect
)
2534 if (ind
->dyn_relocs
!= NULL
)
2536 if (dir
->dyn_relocs
!= NULL
)
2538 struct elf_dyn_relocs
**pp
;
2539 struct elf_dyn_relocs
*p
;
2541 /* Add reloc counts against the indirect sym to the direct sym
2542 list. Merge any entries against the same section. */
2543 for (pp
= &ind
->dyn_relocs
; (p
= *pp
) != NULL
; )
2545 struct elf_dyn_relocs
*q
;
2547 for (q
= dir
->dyn_relocs
; q
!= NULL
; q
= q
->next
)
2548 if (q
->sec
== p
->sec
)
2550 q
->pc_count
+= p
->pc_count
;
2551 q
->count
+= p
->count
;
2558 *pp
= dir
->dyn_relocs
;
2561 dir
->dyn_relocs
= ind
->dyn_relocs
;
2562 ind
->dyn_relocs
= NULL
;
2565 /* Copy over the GOT refcount entries that we may have already seen to
2566 the symbol which just became indirect. */
2567 edir
->elf
.got
.refcount
+= eind
->elf
.got
.refcount
;
2568 eind
->elf
.got
.refcount
= 0;
2570 /* And plt entries. */
2571 if (eind
->elf
.plt
.plist
!= NULL
)
2573 if (edir
->elf
.plt
.plist
!= NULL
)
2575 struct plt_entry
**entp
;
2576 struct plt_entry
*ent
;
2578 for (entp
= &eind
->elf
.plt
.plist
; (ent
= *entp
) != NULL
; )
2580 struct plt_entry
*dent
;
2582 for (dent
= edir
->elf
.plt
.plist
; dent
!= NULL
; dent
= dent
->next
)
2583 if (dent
->sec
== ent
->sec
&& dent
->addend
== ent
->addend
)
2585 dent
->plt
.refcount
+= ent
->plt
.refcount
;
2592 *entp
= edir
->elf
.plt
.plist
;
2595 edir
->elf
.plt
.plist
= eind
->elf
.plt
.plist
;
2596 eind
->elf
.plt
.plist
= NULL
;
2599 if (eind
->elf
.dynindx
!= -1)
2601 if (edir
->elf
.dynindx
!= -1)
2602 _bfd_elf_strtab_delref (elf_hash_table (info
)->dynstr
,
2603 edir
->elf
.dynstr_index
);
2604 edir
->elf
.dynindx
= eind
->elf
.dynindx
;
2605 edir
->elf
.dynstr_index
= eind
->elf
.dynstr_index
;
2606 eind
->elf
.dynindx
= -1;
2607 eind
->elf
.dynstr_index
= 0;
2611 /* Hook called by the linker routine which adds symbols from an object
2612 file. We use it to put .comm items in .sbss, and not .bss. */
2615 ppc_elf_add_symbol_hook (bfd
*abfd
,
2616 struct bfd_link_info
*info
,
2617 Elf_Internal_Sym
*sym
,
2618 const char **namep ATTRIBUTE_UNUSED
,
2619 flagword
*flagsp ATTRIBUTE_UNUSED
,
2623 if (sym
->st_shndx
== SHN_COMMON
2624 && !bfd_link_relocatable (info
)
2625 && is_ppc_elf (info
->output_bfd
)
2626 && sym
->st_size
<= elf_gp_size (abfd
))
2628 /* Common symbols less than or equal to -G nn bytes are automatically
2630 struct ppc_elf_link_hash_table
*htab
;
2632 htab
= ppc_elf_hash_table (info
);
2633 if (htab
->sbss
== NULL
)
2635 flagword flags
= SEC_IS_COMMON
| SEC_SMALL_DATA
| SEC_LINKER_CREATED
;
2637 if (!htab
->elf
.dynobj
)
2638 htab
->elf
.dynobj
= abfd
;
2640 htab
->sbss
= bfd_make_section_anyway_with_flags (htab
->elf
.dynobj
,
2643 if (htab
->sbss
== NULL
)
2648 *valp
= sym
->st_size
;
2654 /* Find a linker generated pointer with a given addend and type. */
2656 static elf_linker_section_pointers_t
*
2657 elf_find_pointer_linker_section
2658 (elf_linker_section_pointers_t
*linker_pointers
,
2660 elf_linker_section_t
*lsect
)
2662 for ( ; linker_pointers
!= NULL
; linker_pointers
= linker_pointers
->next
)
2663 if (lsect
== linker_pointers
->lsect
&& addend
== linker_pointers
->addend
)
2664 return linker_pointers
;
2669 /* Allocate a pointer to live in a linker created section. */
2672 elf_allocate_pointer_linker_section (bfd
*abfd
,
2673 elf_linker_section_t
*lsect
,
2674 struct elf_link_hash_entry
*h
,
2675 const Elf_Internal_Rela
*rel
)
2677 elf_linker_section_pointers_t
**ptr_linker_section_ptr
= NULL
;
2678 elf_linker_section_pointers_t
*linker_section_ptr
;
2679 unsigned long r_symndx
= ELF32_R_SYM (rel
->r_info
);
2682 BFD_ASSERT (lsect
!= NULL
);
2684 /* Is this a global symbol? */
2687 struct ppc_elf_link_hash_entry
*eh
;
2689 /* Has this symbol already been allocated? If so, our work is done. */
2690 eh
= (struct ppc_elf_link_hash_entry
*) h
;
2691 if (elf_find_pointer_linker_section (eh
->linker_section_pointer
,
2696 ptr_linker_section_ptr
= &eh
->linker_section_pointer
;
2700 BFD_ASSERT (is_ppc_elf (abfd
));
2702 /* Allocation of a pointer to a local symbol. */
2703 elf_linker_section_pointers_t
**ptr
= elf_local_ptr_offsets (abfd
);
2705 /* Allocate a table to hold the local symbols if first time. */
2708 unsigned int num_symbols
= elf_symtab_hdr (abfd
).sh_info
;
2711 amt
*= sizeof (elf_linker_section_pointers_t
*);
2712 ptr
= bfd_zalloc (abfd
, amt
);
2717 elf_local_ptr_offsets (abfd
) = ptr
;
2720 /* Has this symbol already been allocated? If so, our work is done. */
2721 if (elf_find_pointer_linker_section (ptr
[r_symndx
],
2726 ptr_linker_section_ptr
= &ptr
[r_symndx
];
2729 /* Allocate space for a pointer in the linker section, and allocate
2730 a new pointer record from internal memory. */
2731 BFD_ASSERT (ptr_linker_section_ptr
!= NULL
);
2732 amt
= sizeof (elf_linker_section_pointers_t
);
2733 linker_section_ptr
= bfd_alloc (abfd
, amt
);
2735 if (!linker_section_ptr
)
2738 linker_section_ptr
->next
= *ptr_linker_section_ptr
;
2739 linker_section_ptr
->addend
= rel
->r_addend
;
2740 linker_section_ptr
->lsect
= lsect
;
2741 *ptr_linker_section_ptr
= linker_section_ptr
;
2743 if (!bfd_set_section_alignment (lsect
->section
, 2))
2745 linker_section_ptr
->offset
= lsect
->section
->size
;
2746 lsect
->section
->size
+= 4;
2750 "Create pointer in linker section %s, offset = %ld, section size = %ld\n",
2751 lsect
->name
, (long) linker_section_ptr
->offset
,
2752 (long) lsect
->section
->size
);
2758 static struct plt_entry
**
2759 update_local_sym_info (bfd
*abfd
,
2760 Elf_Internal_Shdr
*symtab_hdr
,
2761 unsigned long r_symndx
,
2764 bfd_signed_vma
*local_got_refcounts
= elf_local_got_refcounts (abfd
);
2765 struct plt_entry
**local_plt
;
2766 unsigned char *local_got_tls_masks
;
2768 if (local_got_refcounts
== NULL
)
2770 bfd_size_type size
= symtab_hdr
->sh_info
;
2772 size
*= (sizeof (*local_got_refcounts
)
2773 + sizeof (*local_plt
)
2774 + sizeof (*local_got_tls_masks
));
2775 local_got_refcounts
= bfd_zalloc (abfd
, size
);
2776 if (local_got_refcounts
== NULL
)
2778 elf_local_got_refcounts (abfd
) = local_got_refcounts
;
2781 local_plt
= (struct plt_entry
**) (local_got_refcounts
+ symtab_hdr
->sh_info
);
2782 local_got_tls_masks
= (unsigned char *) (local_plt
+ symtab_hdr
->sh_info
);
2783 local_got_tls_masks
[r_symndx
] |= tls_type
& 0xff;
2784 if ((tls_type
& NON_GOT
) == 0)
2785 local_got_refcounts
[r_symndx
] += 1;
2786 return local_plt
+ r_symndx
;
2790 update_plt_info (bfd
*abfd
, struct plt_entry
**plist
,
2791 asection
*sec
, bfd_vma addend
)
2793 struct plt_entry
*ent
;
2797 for (ent
= *plist
; ent
!= NULL
; ent
= ent
->next
)
2798 if (ent
->sec
== sec
&& ent
->addend
== addend
)
2802 size_t amt
= sizeof (*ent
);
2803 ent
= bfd_alloc (abfd
, amt
);
2808 ent
->addend
= addend
;
2809 ent
->plt
.refcount
= 0;
2812 ent
->plt
.refcount
+= 1;
2816 static struct plt_entry
*
2817 find_plt_ent (struct plt_entry
**plist
, asection
*sec
, bfd_vma addend
)
2819 struct plt_entry
*ent
;
2823 for (ent
= *plist
; ent
!= NULL
; ent
= ent
->next
)
2824 if (ent
->sec
== sec
&& ent
->addend
== addend
)
2830 is_branch_reloc (enum elf_ppc_reloc_type r_type
)
2832 return (r_type
== R_PPC_PLTREL24
2833 || r_type
== R_PPC_LOCAL24PC
2834 || r_type
== R_PPC_REL24
2835 || r_type
== R_PPC_REL14
2836 || r_type
== R_PPC_REL14_BRTAKEN
2837 || r_type
== R_PPC_REL14_BRNTAKEN
2838 || r_type
== R_PPC_ADDR24
2839 || r_type
== R_PPC_ADDR14
2840 || r_type
== R_PPC_ADDR14_BRTAKEN
2841 || r_type
== R_PPC_ADDR14_BRNTAKEN
2842 || r_type
== R_PPC_VLE_REL24
);
2845 /* Relocs on inline plt call sequence insns prior to the call. */
2848 is_plt_seq_reloc (enum elf_ppc_reloc_type r_type
)
2850 return (r_type
== R_PPC_PLT16_HA
2851 || r_type
== R_PPC_PLT16_HI
2852 || r_type
== R_PPC_PLT16_LO
2853 || r_type
== R_PPC_PLTSEQ
);
2857 bad_shared_reloc (bfd
*abfd
, enum elf_ppc_reloc_type r_type
)
2860 /* xgettext:c-format */
2861 (_("%pB: relocation %s cannot be used when making a shared object"),
2863 ppc_elf_howto_table
[r_type
]->name
);
2864 bfd_set_error (bfd_error_bad_value
);
2867 /* Look through the relocs for a section during the first phase, and
2868 allocate space in the global offset table or procedure linkage
2872 ppc_elf_check_relocs (bfd
*abfd
,
2873 struct bfd_link_info
*info
,
2875 const Elf_Internal_Rela
*relocs
)
2877 struct ppc_elf_link_hash_table
*htab
;
2878 Elf_Internal_Shdr
*symtab_hdr
;
2879 struct elf_link_hash_entry
**sym_hashes
;
2880 const Elf_Internal_Rela
*rel
;
2881 const Elf_Internal_Rela
*rel_end
;
2882 asection
*got2
, *sreloc
;
2883 struct elf_link_hash_entry
*tga
;
2885 if (bfd_link_relocatable (info
))
2889 _bfd_error_handler ("ppc_elf_check_relocs called for section %pA in %pB",
2893 BFD_ASSERT (is_ppc_elf (abfd
));
2895 /* Initialize howto table if not already done. */
2896 if (!ppc_elf_howto_table
[R_PPC_ADDR32
])
2897 ppc_elf_howto_init ();
2899 htab
= ppc_elf_hash_table (info
);
2900 if (htab
->glink
== NULL
)
2902 if (htab
->elf
.dynobj
== NULL
)
2903 htab
->elf
.dynobj
= abfd
;
2904 if (!ppc_elf_create_glink (htab
->elf
.dynobj
, info
))
2907 tga
= elf_link_hash_lookup (&htab
->elf
, "__tls_get_addr",
2908 FALSE
, FALSE
, TRUE
);
2909 symtab_hdr
= &elf_symtab_hdr (abfd
);
2910 sym_hashes
= elf_sym_hashes (abfd
);
2911 got2
= bfd_get_section_by_name (abfd
, ".got2");
2914 rel_end
= relocs
+ sec
->reloc_count
;
2915 for (rel
= relocs
; rel
< rel_end
; rel
++)
2917 unsigned long r_symndx
;
2918 enum elf_ppc_reloc_type r_type
;
2919 struct elf_link_hash_entry
*h
;
2921 struct plt_entry
**ifunc
;
2922 struct plt_entry
**pltent
;
2925 r_symndx
= ELF32_R_SYM (rel
->r_info
);
2926 if (r_symndx
< symtab_hdr
->sh_info
)
2930 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
2931 while (h
->root
.type
== bfd_link_hash_indirect
2932 || h
->root
.type
== bfd_link_hash_warning
)
2933 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2936 /* If a relocation refers to _GLOBAL_OFFSET_TABLE_, create the .got.
2937 This shows up in particular in an R_PPC_ADDR32 in the eabi
2940 && htab
->elf
.sgot
== NULL
2941 && strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
2943 if (htab
->elf
.dynobj
== NULL
)
2944 htab
->elf
.dynobj
= abfd
;
2945 if (!ppc_elf_create_got (htab
->elf
.dynobj
, info
))
2947 BFD_ASSERT (h
== htab
->elf
.hgot
);
2951 r_type
= ELF32_R_TYPE (rel
->r_info
);
2953 if (h
== NULL
&& htab
->elf
.target_os
!= is_vxworks
)
2955 Elf_Internal_Sym
*isym
= bfd_sym_from_r_symndx (&htab
->elf
.sym_cache
,
2960 if (ELF_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
2962 /* Set PLT_IFUNC flag for this sym, no GOT entry yet. */
2963 ifunc
= update_local_sym_info (abfd
, symtab_hdr
, r_symndx
,
2964 NON_GOT
| PLT_IFUNC
);
2968 /* STT_GNU_IFUNC symbols must have a PLT entry;
2969 In a non-pie executable even when there are
2971 if (!bfd_link_pic (info
)
2972 || is_branch_reloc (r_type
)
2973 || r_type
== R_PPC_PLT16_LO
2974 || r_type
== R_PPC_PLT16_HI
2975 || r_type
== R_PPC_PLT16_HA
)
2978 if (r_type
== R_PPC_PLTREL24
)
2979 ppc_elf_tdata (abfd
)->makes_plt_call
= 1;
2980 if (bfd_link_pic (info
)
2981 && (r_type
== R_PPC_PLTREL24
2982 || r_type
== R_PPC_PLT16_LO
2983 || r_type
== R_PPC_PLT16_HI
2984 || r_type
== R_PPC_PLT16_HA
))
2985 addend
= rel
->r_addend
;
2986 if (!update_plt_info (abfd
, ifunc
, got2
, addend
))
2992 if (htab
->elf
.target_os
!= is_vxworks
2993 && is_branch_reloc (r_type
)
2998 && (ELF32_R_TYPE (rel
[-1].r_info
) == R_PPC_TLSGD
2999 || ELF32_R_TYPE (rel
[-1].r_info
) == R_PPC_TLSLD
))
3000 /* We have a new-style __tls_get_addr call with a marker
3004 /* Mark this section as having an old-style call. */
3005 sec
->nomark_tls_get_addr
= 1;
3012 /* These special tls relocs tie a call to __tls_get_addr with
3013 its parameter symbol. */
3015 ppc_elf_hash_entry (h
)->tls_mask
|= TLS_TLS
| TLS_MARK
;
3017 if (!update_local_sym_info (abfd
, symtab_hdr
, r_symndx
,
3018 NON_GOT
| TLS_TLS
| TLS_MARK
))
3025 case R_PPC_GOT_TLSLD16
:
3026 case R_PPC_GOT_TLSLD16_LO
:
3027 case R_PPC_GOT_TLSLD16_HI
:
3028 case R_PPC_GOT_TLSLD16_HA
:
3029 tls_type
= TLS_TLS
| TLS_LD
;
3032 case R_PPC_GOT_TLSGD16
:
3033 case R_PPC_GOT_TLSGD16_LO
:
3034 case R_PPC_GOT_TLSGD16_HI
:
3035 case R_PPC_GOT_TLSGD16_HA
:
3036 tls_type
= TLS_TLS
| TLS_GD
;
3039 case R_PPC_GOT_TPREL16
:
3040 case R_PPC_GOT_TPREL16_LO
:
3041 case R_PPC_GOT_TPREL16_HI
:
3042 case R_PPC_GOT_TPREL16_HA
:
3043 if (bfd_link_dll (info
))
3044 info
->flags
|= DF_STATIC_TLS
;
3045 tls_type
= TLS_TLS
| TLS_TPREL
;
3048 case R_PPC_GOT_DTPREL16
:
3049 case R_PPC_GOT_DTPREL16_LO
:
3050 case R_PPC_GOT_DTPREL16_HI
:
3051 case R_PPC_GOT_DTPREL16_HA
:
3052 tls_type
= TLS_TLS
| TLS_DTPREL
;
3054 sec
->has_tls_reloc
= 1;
3057 /* GOT16 relocations */
3059 case R_PPC_GOT16_LO
:
3060 case R_PPC_GOT16_HI
:
3061 case R_PPC_GOT16_HA
:
3062 /* This symbol requires a global offset table entry. */
3063 if (htab
->elf
.sgot
== NULL
)
3065 if (htab
->elf
.dynobj
== NULL
)
3066 htab
->elf
.dynobj
= abfd
;
3067 if (!ppc_elf_create_got (htab
->elf
.dynobj
, info
))
3072 h
->got
.refcount
+= 1;
3073 ppc_elf_hash_entry (h
)->tls_mask
|= tls_type
;
3076 /* This is a global offset table entry for a local symbol. */
3077 if (!update_local_sym_info (abfd
, symtab_hdr
, r_symndx
, tls_type
))
3080 /* We may also need a plt entry if the symbol turns out to be
3082 if (h
!= NULL
&& !bfd_link_pic (info
))
3084 if (!update_plt_info (abfd
, &h
->plt
.plist
, NULL
, 0))
3089 /* Indirect .sdata relocation. */
3090 case R_PPC_EMB_SDAI16
:
3091 htab
->sdata
[0].sym
->ref_regular
= 1;
3092 if (!elf_allocate_pointer_linker_section (abfd
, &htab
->sdata
[0],
3097 ppc_elf_hash_entry (h
)->has_sda_refs
= TRUE
;
3098 h
->non_got_ref
= TRUE
;
3102 /* Indirect .sdata2 relocation. */
3103 case R_PPC_EMB_SDA2I16
:
3104 if (!bfd_link_executable (info
))
3106 bad_shared_reloc (abfd
, r_type
);
3109 htab
->sdata
[1].sym
->ref_regular
= 1;
3110 if (!elf_allocate_pointer_linker_section (abfd
, &htab
->sdata
[1],
3115 ppc_elf_hash_entry (h
)->has_sda_refs
= TRUE
;
3116 h
->non_got_ref
= TRUE
;
3120 case R_PPC_SDAREL16
:
3121 htab
->sdata
[0].sym
->ref_regular
= 1;
3124 case R_PPC_VLE_SDAREL_LO16A
:
3125 case R_PPC_VLE_SDAREL_LO16D
:
3126 case R_PPC_VLE_SDAREL_HI16A
:
3127 case R_PPC_VLE_SDAREL_HI16D
:
3128 case R_PPC_VLE_SDAREL_HA16A
:
3129 case R_PPC_VLE_SDAREL_HA16D
:
3132 ppc_elf_hash_entry (h
)->has_sda_refs
= TRUE
;
3133 h
->non_got_ref
= TRUE
;
3137 case R_PPC_VLE_REL8
:
3138 case R_PPC_VLE_REL15
:
3139 case R_PPC_VLE_REL24
:
3140 case R_PPC_VLE_LO16A
:
3141 case R_PPC_VLE_LO16D
:
3142 case R_PPC_VLE_HI16A
:
3143 case R_PPC_VLE_HI16D
:
3144 case R_PPC_VLE_HA16A
:
3145 case R_PPC_VLE_HA16D
:
3146 case R_PPC_VLE_ADDR20
:
3149 case R_PPC_EMB_SDA2REL
:
3150 if (!bfd_link_executable (info
))
3152 bad_shared_reloc (abfd
, r_type
);
3155 htab
->sdata
[1].sym
->ref_regular
= 1;
3158 ppc_elf_hash_entry (h
)->has_sda_refs
= TRUE
;
3159 h
->non_got_ref
= TRUE
;
3163 case R_PPC_VLE_SDA21_LO
:
3164 case R_PPC_VLE_SDA21
:
3165 case R_PPC_EMB_SDA21
:
3166 case R_PPC_EMB_RELSDA
:
3169 ppc_elf_hash_entry (h
)->has_sda_refs
= TRUE
;
3170 h
->non_got_ref
= TRUE
;
3174 case R_PPC_EMB_NADDR32
:
3175 case R_PPC_EMB_NADDR16
:
3176 case R_PPC_EMB_NADDR16_LO
:
3177 case R_PPC_EMB_NADDR16_HI
:
3178 case R_PPC_EMB_NADDR16_HA
:
3180 h
->non_got_ref
= TRUE
;
3183 case R_PPC_PLTREL24
:
3186 ppc_elf_tdata (abfd
)->makes_plt_call
= 1;
3190 sec
->has_pltcall
= 1;
3194 case R_PPC_PLTREL32
:
3195 case R_PPC_PLT16_LO
:
3196 case R_PPC_PLT16_HI
:
3197 case R_PPC_PLT16_HA
:
3200 fprintf (stderr
, "Reloc requires a PLT entry\n");
3202 /* This symbol requires a procedure linkage table entry. */
3205 pltent
= update_local_sym_info (abfd
, symtab_hdr
, r_symndx
,
3206 NON_GOT
| PLT_KEEP
);
3212 if (r_type
!= R_PPC_PLTREL24
)
3213 ppc_elf_hash_entry (h
)->tls_mask
|= PLT_KEEP
;
3215 pltent
= &h
->plt
.plist
;
3218 if (bfd_link_pic (info
)
3219 && (r_type
== R_PPC_PLTREL24
3220 || r_type
== R_PPC_PLT16_LO
3221 || r_type
== R_PPC_PLT16_HI
3222 || r_type
== R_PPC_PLT16_HA
))
3223 addend
= rel
->r_addend
;
3224 if (!update_plt_info (abfd
, pltent
, got2
, addend
))
3228 /* The following relocations don't need to propagate the
3229 relocation if linking a shared object since they are
3230 section relative. */
3232 case R_PPC_SECTOFF_LO
:
3233 case R_PPC_SECTOFF_HI
:
3234 case R_PPC_SECTOFF_HA
:
3235 case R_PPC_DTPREL16
:
3236 case R_PPC_DTPREL16_LO
:
3237 case R_PPC_DTPREL16_HI
:
3238 case R_PPC_DTPREL16_HA
:
3243 case R_PPC_REL16_LO
:
3244 case R_PPC_REL16_HI
:
3245 case R_PPC_REL16_HA
:
3246 case R_PPC_REL16DX_HA
:
3247 ppc_elf_tdata (abfd
)->has_rel16
= 1;
3250 /* These are just markers. */
3252 case R_PPC_EMB_MRKREF
:
3256 case R_PPC_RELAX_PLT
:
3257 case R_PPC_RELAX_PLTREL24
:
3261 /* These should only appear in dynamic objects. */
3263 case R_PPC_GLOB_DAT
:
3264 case R_PPC_JMP_SLOT
:
3265 case R_PPC_RELATIVE
:
3266 case R_PPC_IRELATIVE
:
3269 /* These aren't handled yet. We'll report an error later. */
3271 case R_PPC_EMB_RELSEC16
:
3272 case R_PPC_EMB_RELST_LO
:
3273 case R_PPC_EMB_RELST_HI
:
3274 case R_PPC_EMB_RELST_HA
:
3275 case R_PPC_EMB_BIT_FLD
:
3278 /* This refers only to functions defined in the shared library. */
3279 case R_PPC_LOCAL24PC
:
3280 if (h
!= NULL
&& h
== htab
->elf
.hgot
&& htab
->plt_type
== PLT_UNSET
)
3282 htab
->plt_type
= PLT_OLD
;
3283 htab
->old_bfd
= abfd
;
3285 if (h
!= NULL
&& h
->type
== STT_GNU_IFUNC
)
3288 if (!update_plt_info (abfd
, &h
->plt
.plist
, NULL
, 0))
3293 /* This relocation describes the C++ object vtable hierarchy.
3294 Reconstruct it for later use during GC. */
3295 case R_PPC_GNU_VTINHERIT
:
3296 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
3300 /* This relocation describes which C++ vtable entries are actually
3301 used. Record for later use during GC. */
3302 case R_PPC_GNU_VTENTRY
:
3303 if (!bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_addend
))
3307 case R_PPC_TPREL16_HI
:
3308 case R_PPC_TPREL16_HA
:
3309 sec
->has_tls_reloc
= 1;
3311 /* We shouldn't really be seeing TPREL32. */
3314 case R_PPC_TPREL16_LO
:
3315 if (bfd_link_dll (info
))
3316 info
->flags
|= DF_STATIC_TLS
;
3320 case R_PPC_DTPMOD32
:
3321 case R_PPC_DTPREL32
:
3327 && (sec
->flags
& SEC_CODE
) != 0
3328 && bfd_link_pic (info
)
3329 && htab
->plt_type
== PLT_UNSET
)
3331 /* Old -fPIC gcc code has .long LCTOC1-LCFx just before
3332 the start of a function, which assembles to a REL32
3333 reference to .got2. If we detect one of these, then
3334 force the old PLT layout because the linker cannot
3335 reliably deduce the GOT pointer value needed for
3338 Elf_Internal_Sym
*isym
;
3340 isym
= bfd_sym_from_r_symndx (&htab
->elf
.sym_cache
,
3345 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
3348 htab
->plt_type
= PLT_OLD
;
3349 htab
->old_bfd
= abfd
;
3352 if (h
== NULL
|| h
== htab
->elf
.hgot
)
3358 case R_PPC_ADDR16_LO
:
3359 case R_PPC_ADDR16_HI
:
3360 case R_PPC_ADDR16_HA
:
3363 if (h
!= NULL
&& !bfd_link_pic (info
))
3365 /* We may need a plt entry if the symbol turns out to be
3366 a function defined in a dynamic object. */
3367 if (!update_plt_info (abfd
, &h
->plt
.plist
, NULL
, 0))
3370 /* We may need a copy reloc too. */
3372 h
->pointer_equality_needed
= 1;
3373 if (r_type
== R_PPC_ADDR16_HA
)
3374 ppc_elf_hash_entry (h
)->has_addr16_ha
= 1;
3375 if (r_type
== R_PPC_ADDR16_LO
)
3376 ppc_elf_hash_entry (h
)->has_addr16_lo
= 1;
3382 case R_PPC_REL14_BRTAKEN
:
3383 case R_PPC_REL14_BRNTAKEN
:
3386 if (h
== htab
->elf
.hgot
)
3388 if (htab
->plt_type
== PLT_UNSET
)
3390 htab
->plt_type
= PLT_OLD
;
3391 htab
->old_bfd
= abfd
;
3399 case R_PPC_ADDR14_BRTAKEN
:
3400 case R_PPC_ADDR14_BRNTAKEN
:
3401 if (h
!= NULL
&& !bfd_link_pic (info
))
3403 /* We may need a plt entry if the symbol turns out to be
3404 a function defined in a dynamic object. */
3406 if (!update_plt_info (abfd
, &h
->plt
.plist
, NULL
, 0))
3412 /* If we are creating a shared library, and this is a reloc
3413 against a global symbol, or a non PC relative reloc
3414 against a local symbol, then we need to copy the reloc
3415 into the shared library. However, if we are linking with
3416 -Bsymbolic, we do not need to copy a reloc against a
3417 global symbol which is defined in an object we are
3418 including in the link (i.e., DEF_REGULAR is set). At
3419 this point we have not seen all the input files, so it is
3420 possible that DEF_REGULAR is not set now but will be set
3421 later (it is never cleared). In case of a weak definition,
3422 DEF_REGULAR may be cleared later by a strong definition in
3423 a shared library. We account for that possibility below by
3424 storing information in the dyn_relocs field of the hash
3425 table entry. A similar situation occurs when creating
3426 shared libraries and symbol visibility changes render the
3429 If on the other hand, we are creating an executable, we
3430 may need to keep relocations for symbols satisfied by a
3431 dynamic library if we manage to avoid copy relocs for the
3433 if ((bfd_link_pic (info
)
3434 && (must_be_dyn_reloc (info
, r_type
)
3436 && (!SYMBOLIC_BIND (info
, h
)
3437 || h
->root
.type
== bfd_link_hash_defweak
3438 || !h
->def_regular
))))
3439 || (ELIMINATE_COPY_RELOCS
3440 && !bfd_link_pic (info
)
3442 && (h
->root
.type
== bfd_link_hash_defweak
3443 || !h
->def_regular
)))
3447 "ppc_elf_check_relocs needs to "
3448 "create relocation for %s\n",
3449 (h
&& h
->root
.root
.string
3450 ? h
->root
.root
.string
: "<unknown>"));
3454 if (htab
->elf
.dynobj
== NULL
)
3455 htab
->elf
.dynobj
= abfd
;
3457 sreloc
= _bfd_elf_make_dynamic_reloc_section
3458 (sec
, htab
->elf
.dynobj
, 2, abfd
, /*rela?*/ TRUE
);
3464 /* If this is a global symbol, we count the number of
3465 relocations we need for this symbol. */
3468 struct elf_dyn_relocs
*p
;
3469 struct elf_dyn_relocs
**rel_head
;
3471 rel_head
= &h
->dyn_relocs
;
3473 if (p
== NULL
|| p
->sec
!= sec
)
3475 p
= bfd_alloc (htab
->elf
.dynobj
, sizeof *p
);
3478 p
->next
= *rel_head
;
3485 if (!must_be_dyn_reloc (info
, r_type
))
3490 /* Track dynamic relocs needed for local syms too.
3491 We really need local syms available to do this
3493 struct ppc_dyn_relocs
*p
;
3494 struct ppc_dyn_relocs
**rel_head
;
3495 bfd_boolean is_ifunc
;
3498 Elf_Internal_Sym
*isym
;
3500 isym
= bfd_sym_from_r_symndx (&htab
->elf
.sym_cache
,
3505 s
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
3509 vpp
= &elf_section_data (s
)->local_dynrel
;
3510 rel_head
= (struct ppc_dyn_relocs
**) vpp
;
3511 is_ifunc
= ELF_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
;
3513 if (p
!= NULL
&& p
->sec
== sec
&& p
->ifunc
!= is_ifunc
)
3515 if (p
== NULL
|| p
->sec
!= sec
|| p
->ifunc
!= is_ifunc
)
3517 p
= bfd_alloc (htab
->elf
.dynobj
, sizeof *p
);
3520 p
->next
= *rel_head
;
3523 p
->ifunc
= is_ifunc
;
3537 /* Warn for conflicting Tag_GNU_Power_ABI_FP attributes between IBFD
3538 and OBFD, and merge non-conflicting ones. */
3540 _bfd_elf_ppc_merge_fp_attributes (bfd
*ibfd
, struct bfd_link_info
*info
)
3542 bfd
*obfd
= info
->output_bfd
;
3543 obj_attribute
*in_attr
, *in_attrs
;
3544 obj_attribute
*out_attr
, *out_attrs
;
3545 bfd_boolean ret
= TRUE
;
3546 bfd_boolean warn_only
;
3548 /* We only warn about shared library mismatches, because common
3549 libraries advertise support for a particular long double variant
3550 but actually support more than one variant. For example, glibc
3551 typically supports 128-bit IBM long double in the shared library
3552 but has a compatibility static archive for 64-bit long double.
3553 The linker doesn't have the smarts to see that an app using
3554 object files marked as 64-bit long double call the compatibility
3555 layer objects and only from there call into the shared library. */
3556 warn_only
= (ibfd
->flags
& DYNAMIC
) != 0;
3558 in_attrs
= elf_known_obj_attributes (ibfd
)[OBJ_ATTR_GNU
];
3559 out_attrs
= elf_known_obj_attributes (obfd
)[OBJ_ATTR_GNU
];
3561 in_attr
= &in_attrs
[Tag_GNU_Power_ABI_FP
];
3562 out_attr
= &out_attrs
[Tag_GNU_Power_ABI_FP
];
3564 if (in_attr
->i
!= out_attr
->i
)
3566 int in_fp
= in_attr
->i
& 3;
3567 int out_fp
= out_attr
->i
& 3;
3568 static bfd
*last_fp
, *last_ld
;
3572 else if (out_fp
== 0)
3576 out_attr
->type
= ATTR_TYPE_FLAG_INT_VAL
;
3577 out_attr
->i
^= in_fp
;
3581 else if (out_fp
!= 2 && in_fp
== 2)
3584 /* xgettext:c-format */
3585 (_("%pB uses hard float, %pB uses soft float"),
3589 else if (out_fp
== 2 && in_fp
!= 2)
3592 /* xgettext:c-format */
3593 (_("%pB uses hard float, %pB uses soft float"),
3597 else if (out_fp
== 1 && in_fp
== 3)
3600 /* xgettext:c-format */
3601 (_("%pB uses double-precision hard float, "
3602 "%pB uses single-precision hard float"), last_fp
, ibfd
);
3605 else if (out_fp
== 3 && in_fp
== 1)
3608 /* xgettext:c-format */
3609 (_("%pB uses double-precision hard float, "
3610 "%pB uses single-precision hard float"), ibfd
, last_fp
);
3614 in_fp
= in_attr
->i
& 0xc;
3615 out_fp
= out_attr
->i
& 0xc;
3618 else if (out_fp
== 0)
3622 out_attr
->type
= ATTR_TYPE_FLAG_INT_VAL
;
3623 out_attr
->i
^= in_fp
;
3627 else if (out_fp
!= 2 * 4 && in_fp
== 2 * 4)
3630 /* xgettext:c-format */
3631 (_("%pB uses 64-bit long double, "
3632 "%pB uses 128-bit long double"), ibfd
, last_ld
);
3635 else if (in_fp
!= 2 * 4 && out_fp
== 2 * 4)
3638 /* xgettext:c-format */
3639 (_("%pB uses 64-bit long double, "
3640 "%pB uses 128-bit long double"), last_ld
, ibfd
);
3643 else if (out_fp
== 1 * 4 && in_fp
== 3 * 4)
3646 /* xgettext:c-format */
3647 (_("%pB uses IBM long double, "
3648 "%pB uses IEEE long double"), last_ld
, ibfd
);
3651 else if (out_fp
== 3 * 4 && in_fp
== 1 * 4)
3654 /* xgettext:c-format */
3655 (_("%pB uses IBM long double, "
3656 "%pB uses IEEE long double"), ibfd
, last_ld
);
3663 out_attr
->type
= ATTR_TYPE_FLAG_INT_VAL
| ATTR_TYPE_FLAG_ERROR
;
3664 bfd_set_error (bfd_error_bad_value
);
3669 /* Merge object attributes from IBFD into OBFD. Warn if
3670 there are conflicting attributes. */
3672 ppc_elf_merge_obj_attributes (bfd
*ibfd
, struct bfd_link_info
*info
)
3675 obj_attribute
*in_attr
, *in_attrs
;
3676 obj_attribute
*out_attr
, *out_attrs
;
3679 if (!_bfd_elf_ppc_merge_fp_attributes (ibfd
, info
))
3682 obfd
= info
->output_bfd
;
3683 in_attrs
= elf_known_obj_attributes (ibfd
)[OBJ_ATTR_GNU
];
3684 out_attrs
= elf_known_obj_attributes (obfd
)[OBJ_ATTR_GNU
];
3686 /* Check for conflicting Tag_GNU_Power_ABI_Vector attributes and
3687 merge non-conflicting ones. */
3688 in_attr
= &in_attrs
[Tag_GNU_Power_ABI_Vector
];
3689 out_attr
= &out_attrs
[Tag_GNU_Power_ABI_Vector
];
3691 if (in_attr
->i
!= out_attr
->i
)
3693 int in_vec
= in_attr
->i
& 3;
3694 int out_vec
= out_attr
->i
& 3;
3695 static bfd
*last_vec
;
3699 else if (out_vec
== 0)
3701 out_attr
->type
= ATTR_TYPE_FLAG_INT_VAL
;
3702 out_attr
->i
= in_vec
;
3705 /* For now, allow generic to transition to AltiVec or SPE
3706 without a warning. If GCC marked files with their stack
3707 alignment and used don't-care markings for files which are
3708 not affected by the vector ABI, we could warn about this
3710 else if (in_vec
== 1)
3712 else if (out_vec
== 1)
3714 out_attr
->type
= ATTR_TYPE_FLAG_INT_VAL
;
3715 out_attr
->i
= in_vec
;
3718 else if (out_vec
< in_vec
)
3721 /* xgettext:c-format */
3722 (_("%pB uses AltiVec vector ABI, %pB uses SPE vector ABI"),
3724 out_attr
->type
= ATTR_TYPE_FLAG_INT_VAL
| ATTR_TYPE_FLAG_ERROR
;
3727 else if (out_vec
> in_vec
)
3730 /* xgettext:c-format */
3731 (_("%pB uses AltiVec vector ABI, %pB uses SPE vector ABI"),
3733 out_attr
->type
= ATTR_TYPE_FLAG_INT_VAL
| ATTR_TYPE_FLAG_ERROR
;
3738 /* Check for conflicting Tag_GNU_Power_ABI_Struct_Return attributes
3739 and merge non-conflicting ones. */
3740 in_attr
= &in_attrs
[Tag_GNU_Power_ABI_Struct_Return
];
3741 out_attr
= &out_attrs
[Tag_GNU_Power_ABI_Struct_Return
];
3742 if (in_attr
->i
!= out_attr
->i
)
3744 int in_struct
= in_attr
->i
& 3;
3745 int out_struct
= out_attr
->i
& 3;
3746 static bfd
*last_struct
;
3748 if (in_struct
== 0 || in_struct
== 3)
3750 else if (out_struct
== 0)
3752 out_attr
->type
= ATTR_TYPE_FLAG_INT_VAL
;
3753 out_attr
->i
= in_struct
;
3756 else if (out_struct
< in_struct
)
3759 /* xgettext:c-format */
3760 (_("%pB uses r3/r4 for small structure returns, "
3761 "%pB uses memory"), last_struct
, ibfd
);
3762 out_attr
->type
= ATTR_TYPE_FLAG_INT_VAL
| ATTR_TYPE_FLAG_ERROR
;
3765 else if (out_struct
> in_struct
)
3768 /* xgettext:c-format */
3769 (_("%pB uses r3/r4 for small structure returns, "
3770 "%pB uses memory"), ibfd
, last_struct
);
3771 out_attr
->type
= ATTR_TYPE_FLAG_INT_VAL
| ATTR_TYPE_FLAG_ERROR
;
3777 bfd_set_error (bfd_error_bad_value
);
3781 /* Merge Tag_compatibility attributes and any common GNU ones. */
3782 return _bfd_elf_merge_object_attributes (ibfd
, info
);
3785 /* Merge backend specific data from an object file to the output
3786 object file when linking. */
3789 ppc_elf_merge_private_bfd_data (bfd
*ibfd
, struct bfd_link_info
*info
)
3791 bfd
*obfd
= info
->output_bfd
;
3796 if (!is_ppc_elf (ibfd
) || !is_ppc_elf (obfd
))
3799 /* Check if we have the same endianness. */
3800 if (! _bfd_generic_verify_endian_match (ibfd
, info
))
3803 if (!ppc_elf_merge_obj_attributes (ibfd
, info
))
3806 if ((ibfd
->flags
& DYNAMIC
) != 0)
3809 new_flags
= elf_elfheader (ibfd
)->e_flags
;
3810 old_flags
= elf_elfheader (obfd
)->e_flags
;
3811 if (!elf_flags_init (obfd
))
3813 /* First call, no flags set. */
3814 elf_flags_init (obfd
) = TRUE
;
3815 elf_elfheader (obfd
)->e_flags
= new_flags
;
3818 /* Compatible flags are ok. */
3819 else if (new_flags
== old_flags
)
3822 /* Incompatible flags. */
3825 /* Warn about -mrelocatable mismatch. Allow -mrelocatable-lib
3826 to be linked with either. */
3828 if ((new_flags
& EF_PPC_RELOCATABLE
) != 0
3829 && (old_flags
& (EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
)) == 0)
3833 (_("%pB: compiled with -mrelocatable and linked with "
3834 "modules compiled normally"), ibfd
);
3836 else if ((new_flags
& (EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
)) == 0
3837 && (old_flags
& EF_PPC_RELOCATABLE
) != 0)
3841 (_("%pB: compiled normally and linked with "
3842 "modules compiled with -mrelocatable"), ibfd
);
3845 /* The output is -mrelocatable-lib iff both the input files are. */
3846 if (! (new_flags
& EF_PPC_RELOCATABLE_LIB
))
3847 elf_elfheader (obfd
)->e_flags
&= ~EF_PPC_RELOCATABLE_LIB
;
3849 /* The output is -mrelocatable iff it can't be -mrelocatable-lib,
3850 but each input file is either -mrelocatable or -mrelocatable-lib. */
3851 if (! (elf_elfheader (obfd
)->e_flags
& EF_PPC_RELOCATABLE_LIB
)
3852 && (new_flags
& (EF_PPC_RELOCATABLE_LIB
| EF_PPC_RELOCATABLE
))
3853 && (old_flags
& (EF_PPC_RELOCATABLE_LIB
| EF_PPC_RELOCATABLE
)))
3854 elf_elfheader (obfd
)->e_flags
|= EF_PPC_RELOCATABLE
;
3856 /* Do not warn about eabi vs. V.4 mismatch, just or in the bit if
3857 any module uses it. */
3858 elf_elfheader (obfd
)->e_flags
|= (new_flags
& EF_PPC_EMB
);
3860 new_flags
&= ~(EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
| EF_PPC_EMB
);
3861 old_flags
&= ~(EF_PPC_RELOCATABLE
| EF_PPC_RELOCATABLE_LIB
| EF_PPC_EMB
);
3863 /* Warn about any other mismatches. */
3864 if (new_flags
!= old_flags
)
3868 /* xgettext:c-format */
3869 (_("%pB: uses different e_flags (%#x) fields "
3870 "than previous modules (%#x)"),
3871 ibfd
, new_flags
, old_flags
);
3876 bfd_set_error (bfd_error_bad_value
);
3885 ppc_elf_vle_split16 (bfd
*input_bfd
,
3886 asection
*input_section
,
3887 unsigned long offset
,
3890 split16_format_type split16_format
,
3893 unsigned int insn
, opcode
;
3895 insn
= bfd_get_32 (input_bfd
, loc
);
3896 opcode
= insn
& E_OPCODE_MASK
;
3897 if (opcode
== E_OR2I_INSN
3898 || opcode
== E_AND2I_DOT_INSN
3899 || opcode
== E_OR2IS_INSN
3900 || opcode
== E_LIS_INSN
3901 || opcode
== E_AND2IS_DOT_INSN
)
3903 if (split16_format
!= split16a_type
)
3906 split16_format
= split16a_type
;
3909 /* xgettext:c-format */
3910 (_("%pB(%pA+0x%lx): expected 16A style relocation on 0x%08x insn"),
3911 input_bfd
, input_section
, offset
, opcode
);
3914 else if (opcode
== E_ADD2I_DOT_INSN
3915 || opcode
== E_ADD2IS_INSN
3916 || opcode
== E_CMP16I_INSN
3917 || opcode
== E_MULL2I_INSN
3918 || opcode
== E_CMPL16I_INSN
3919 || opcode
== E_CMPH16I_INSN
3920 || opcode
== E_CMPHL16I_INSN
)
3922 if (split16_format
!= split16d_type
)
3925 split16_format
= split16d_type
;
3928 /* xgettext:c-format */
3929 (_("%pB(%pA+0x%lx): expected 16D style relocation on 0x%08x insn"),
3930 input_bfd
, input_section
, offset
, opcode
);
3933 if (split16_format
== split16a_type
)
3935 insn
&= ~((0xf800 << 5) | 0x7ff);
3936 insn
|= (value
& 0xf800) << 5;
3937 if ((insn
& E_LI_MASK
) == E_LI_INSN
)
3939 /* Hack for e_li. Extend sign. */
3940 insn
&= ~(0xf0000 >> 5);
3941 insn
|= (-(value
& 0x8000) & 0xf0000) >> 5;
3946 insn
&= ~((0xf800 << 10) | 0x7ff);
3947 insn
|= (value
& 0xf800) << 10;
3949 insn
|= value
& 0x7ff;
3950 bfd_put_32 (input_bfd
, insn
, loc
);
3954 ppc_elf_vle_split20 (bfd
*output_bfd
, bfd_byte
*loc
, bfd_vma value
)
3958 insn
= bfd_get_32 (output_bfd
, loc
);
3959 /* We have an li20 field, bits 17..20, 11..15, 21..31. */
3960 /* Top 4 bits of value to 17..20. */
3961 insn
|= (value
& 0xf0000) >> 5;
3962 /* Next 5 bits of the value to 11..15. */
3963 insn
|= (value
& 0xf800) << 5;
3964 /* And the final 11 bits of the value to bits 21 to 31. */
3965 insn
|= value
& 0x7ff;
3966 bfd_put_32 (output_bfd
, insn
, loc
);
3970 /* Choose which PLT scheme to use, and set .plt flags appropriately.
3971 Returns -1 on error, 0 for old PLT, 1 for new PLT. */
3973 ppc_elf_select_plt_layout (bfd
*output_bfd ATTRIBUTE_UNUSED
,
3974 struct bfd_link_info
*info
)
3976 struct ppc_elf_link_hash_table
*htab
;
3979 htab
= ppc_elf_hash_table (info
);
3981 if (htab
->plt_type
== PLT_UNSET
)
3983 struct elf_link_hash_entry
*h
;
3985 if (htab
->params
->plt_style
== PLT_OLD
)
3986 htab
->plt_type
= PLT_OLD
;
3987 else if (bfd_link_pic (info
)
3988 && htab
->elf
.dynamic_sections_created
3989 && (h
= elf_link_hash_lookup (&htab
->elf
, "_mcount",
3990 FALSE
, FALSE
, TRUE
)) != NULL
3991 && (h
->type
== STT_FUNC
3994 && !(SYMBOL_CALLS_LOCAL (info
, h
)
3995 || UNDEFWEAK_NO_DYNAMIC_RELOC (info
, h
)))
3997 /* Profiling of shared libs (and pies) is not supported with
3998 secure plt, because ppc32 does profiling before a
3999 function prologue and a secure plt pic call stubs needs
4000 r30 to be set up. */
4001 htab
->plt_type
= PLT_OLD
;
4006 enum ppc_elf_plt_type plt_type
= htab
->params
->plt_style
;
4008 /* Look through the reloc flags left by ppc_elf_check_relocs.
4009 Use the old style bss plt if a file makes plt calls
4010 without using the new relocs, and if ld isn't given
4011 --secure-plt and we never see REL16 relocs. */
4012 if (plt_type
== PLT_UNSET
)
4014 for (ibfd
= info
->input_bfds
; ibfd
; ibfd
= ibfd
->link
.next
)
4015 if (is_ppc_elf (ibfd
))
4017 if (ppc_elf_tdata (ibfd
)->has_rel16
)
4019 else if (ppc_elf_tdata (ibfd
)->makes_plt_call
)
4022 htab
->old_bfd
= ibfd
;
4026 htab
->plt_type
= plt_type
;
4029 if (htab
->plt_type
== PLT_OLD
&& htab
->params
->plt_style
== PLT_NEW
)
4031 if (htab
->old_bfd
!= NULL
)
4032 _bfd_error_handler (_("bss-plt forced due to %pB"), htab
->old_bfd
);
4034 _bfd_error_handler (_("bss-plt forced by profiling"));
4037 BFD_ASSERT (htab
->plt_type
!= PLT_VXWORKS
);
4039 if (htab
->plt_type
== PLT_NEW
)
4041 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
4042 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
4044 /* The new PLT is a loaded section. */
4045 if (htab
->elf
.splt
!= NULL
4046 && !bfd_set_section_flags (htab
->elf
.splt
, flags
))
4049 /* The new GOT is not executable. */
4050 if (htab
->elf
.sgot
!= NULL
4051 && !bfd_set_section_flags (htab
->elf
.sgot
, flags
))
4056 /* Stop an unused .glink section from affecting .text alignment. */
4057 if (htab
->glink
!= NULL
4058 && !bfd_set_section_alignment (htab
->glink
, 0))
4061 return htab
->plt_type
== PLT_NEW
;
4064 /* Return the section that should be marked against GC for a given
4068 ppc_elf_gc_mark_hook (asection
*sec
,
4069 struct bfd_link_info
*info
,
4070 Elf_Internal_Rela
*rel
,
4071 struct elf_link_hash_entry
*h
,
4072 Elf_Internal_Sym
*sym
)
4075 switch (ELF32_R_TYPE (rel
->r_info
))
4077 case R_PPC_GNU_VTINHERIT
:
4078 case R_PPC_GNU_VTENTRY
:
4082 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
4086 get_sym_h (struct elf_link_hash_entry
**hp
,
4087 Elf_Internal_Sym
**symp
,
4089 unsigned char **tls_maskp
,
4090 Elf_Internal_Sym
**locsymsp
,
4091 unsigned long r_symndx
,
4094 Elf_Internal_Shdr
*symtab_hdr
= &elf_symtab_hdr (ibfd
);
4096 if (r_symndx
>= symtab_hdr
->sh_info
)
4098 struct elf_link_hash_entry
**sym_hashes
= elf_sym_hashes (ibfd
);
4099 struct elf_link_hash_entry
*h
;
4101 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
4102 while (h
->root
.type
== bfd_link_hash_indirect
4103 || h
->root
.type
== bfd_link_hash_warning
)
4104 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
4112 if (symsecp
!= NULL
)
4114 asection
*symsec
= NULL
;
4115 if (h
->root
.type
== bfd_link_hash_defined
4116 || h
->root
.type
== bfd_link_hash_defweak
)
4117 symsec
= h
->root
.u
.def
.section
;
4121 if (tls_maskp
!= NULL
)
4122 *tls_maskp
= &ppc_elf_hash_entry (h
)->tls_mask
;
4126 Elf_Internal_Sym
*sym
;
4127 Elf_Internal_Sym
*locsyms
= *locsymsp
;
4129 if (locsyms
== NULL
)
4131 locsyms
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
4132 if (locsyms
== NULL
)
4133 locsyms
= bfd_elf_get_elf_syms (ibfd
, symtab_hdr
,
4134 symtab_hdr
->sh_info
,
4135 0, NULL
, NULL
, NULL
);
4136 if (locsyms
== NULL
)
4138 *locsymsp
= locsyms
;
4140 sym
= locsyms
+ r_symndx
;
4148 if (symsecp
!= NULL
)
4149 *symsecp
= bfd_section_from_elf_index (ibfd
, sym
->st_shndx
);
4151 if (tls_maskp
!= NULL
)
4153 bfd_signed_vma
*local_got
;
4154 unsigned char *tls_mask
;
4157 local_got
= elf_local_got_refcounts (ibfd
);
4158 if (local_got
!= NULL
)
4160 struct plt_entry
**local_plt
= (struct plt_entry
**)
4161 (local_got
+ symtab_hdr
->sh_info
);
4162 unsigned char *lgot_masks
= (unsigned char *)
4163 (local_plt
+ symtab_hdr
->sh_info
);
4164 tls_mask
= &lgot_masks
[r_symndx
];
4166 *tls_maskp
= tls_mask
;
4172 /* Analyze inline PLT call relocations to see whether calls to locally
4173 defined functions can be converted to direct calls. */
4176 ppc_elf_inline_plt (struct bfd_link_info
*info
)
4178 struct ppc_elf_link_hash_table
*htab
;
4181 bfd_vma low_vma
, high_vma
, limit
;
4183 htab
= ppc_elf_hash_table (info
);
4187 /* A bl insn can reach -0x2000000 to 0x1fffffc. The limit is
4188 reduced somewhat to cater for possible stubs that might be added
4189 between the call and its destination. */
4193 for (sec
= info
->output_bfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
4194 if ((sec
->flags
& (SEC_ALLOC
| SEC_CODE
)) == (SEC_ALLOC
| SEC_CODE
))
4196 if (low_vma
> sec
->vma
)
4198 if (high_vma
< sec
->vma
+ sec
->size
)
4199 high_vma
= sec
->vma
+ sec
->size
;
4202 /* If a "bl" can reach anywhere in local code sections, then we can
4203 convert all inline PLT sequences to direct calls when the symbol
4205 if (high_vma
- low_vma
< limit
)
4207 htab
->can_convert_all_inline_plt
= 1;
4211 /* Otherwise, go looking through relocs for cases where a direct
4212 call won't reach. Mark the symbol on any such reloc to disable
4213 the optimization and keep the PLT entry as it seems likely that
4214 this will be better than creating trampolines. Note that this
4215 will disable the optimization for all inline PLT calls to a
4216 particular symbol, not just those that won't reach. The
4217 difficulty in doing a more precise optimization is that the
4218 linker needs to make a decision depending on whether a
4219 particular R_PPC_PLTCALL insn can be turned into a direct
4220 call, for each of the R_PPC_PLTSEQ and R_PPC_PLT16* insns in
4221 the sequence, and there is nothing that ties those relocs
4222 together except their symbol. */
4224 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
4226 Elf_Internal_Shdr
*symtab_hdr
;
4227 Elf_Internal_Sym
*local_syms
;
4229 if (!is_ppc_elf (ibfd
))
4233 symtab_hdr
= &elf_symtab_hdr (ibfd
);
4235 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
4236 if (sec
->has_pltcall
4237 && !bfd_is_abs_section (sec
->output_section
))
4239 Elf_Internal_Rela
*relstart
, *rel
, *relend
;
4241 /* Read the relocations. */
4242 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
4244 if (relstart
== NULL
)
4247 relend
= relstart
+ sec
->reloc_count
;
4248 for (rel
= relstart
; rel
< relend
; )
4250 enum elf_ppc_reloc_type r_type
;
4251 unsigned long r_symndx
;
4253 struct elf_link_hash_entry
*h
;
4254 Elf_Internal_Sym
*sym
;
4255 unsigned char *tls_maskp
;
4257 r_type
= ELF32_R_TYPE (rel
->r_info
);
4258 if (r_type
!= R_PPC_PLTCALL
)
4261 r_symndx
= ELF32_R_SYM (rel
->r_info
);
4262 if (!get_sym_h (&h
, &sym
, &sym_sec
, &tls_maskp
, &local_syms
,
4265 if (elf_section_data (sec
)->relocs
!= relstart
)
4267 if (symtab_hdr
->contents
!= (unsigned char *) local_syms
)
4272 if (sym_sec
!= NULL
&& sym_sec
->output_section
!= NULL
)
4276 to
= h
->root
.u
.def
.value
;
4279 to
+= (rel
->r_addend
4280 + sym_sec
->output_offset
4281 + sym_sec
->output_section
->vma
);
4282 from
= (rel
->r_offset
4283 + sec
->output_offset
4284 + sec
->output_section
->vma
);
4285 if (to
- from
+ limit
< 2 * limit
)
4286 *tls_maskp
&= ~PLT_KEEP
;
4289 if (elf_section_data (sec
)->relocs
!= relstart
)
4293 if (local_syms
!= NULL
4294 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
4296 if (!info
->keep_memory
)
4299 symtab_hdr
->contents
= (unsigned char *) local_syms
;
4306 /* Set plt output section type, htab->tls_get_addr, and call the
4307 generic ELF tls_setup function. */
4310 ppc_elf_tls_setup (bfd
*obfd
, struct bfd_link_info
*info
)
4312 struct ppc_elf_link_hash_table
*htab
;
4314 htab
= ppc_elf_hash_table (info
);
4315 htab
->tls_get_addr
= elf_link_hash_lookup (&htab
->elf
, "__tls_get_addr",
4316 FALSE
, FALSE
, TRUE
);
4317 if (htab
->plt_type
!= PLT_NEW
)
4318 htab
->params
->no_tls_get_addr_opt
= TRUE
;
4320 if (!htab
->params
->no_tls_get_addr_opt
)
4322 struct elf_link_hash_entry
*opt
, *tga
;
4323 opt
= elf_link_hash_lookup (&htab
->elf
, "__tls_get_addr_opt",
4324 FALSE
, FALSE
, TRUE
);
4326 && (opt
->root
.type
== bfd_link_hash_defined
4327 || opt
->root
.type
== bfd_link_hash_defweak
))
4329 /* If glibc supports an optimized __tls_get_addr call stub,
4330 signalled by the presence of __tls_get_addr_opt, and we'll
4331 be calling __tls_get_addr via a plt call stub, then
4332 make __tls_get_addr point to __tls_get_addr_opt. */
4333 tga
= htab
->tls_get_addr
;
4334 if (htab
->elf
.dynamic_sections_created
4336 && (tga
->type
== STT_FUNC
4338 && !(SYMBOL_CALLS_LOCAL (info
, tga
)
4339 || UNDEFWEAK_NO_DYNAMIC_RELOC (info
, tga
)))
4341 struct plt_entry
*ent
;
4342 for (ent
= tga
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
4343 if (ent
->plt
.refcount
> 0)
4347 tga
->root
.type
= bfd_link_hash_indirect
;
4348 tga
->root
.u
.i
.link
= &opt
->root
;
4349 ppc_elf_copy_indirect_symbol (info
, opt
, tga
);
4351 if (opt
->dynindx
!= -1)
4353 /* Use __tls_get_addr_opt in dynamic relocations. */
4355 _bfd_elf_strtab_delref (elf_hash_table (info
)->dynstr
,
4357 if (!bfd_elf_link_record_dynamic_symbol (info
, opt
))
4360 htab
->tls_get_addr
= opt
;
4365 htab
->params
->no_tls_get_addr_opt
= TRUE
;
4367 if (htab
->plt_type
== PLT_NEW
4368 && htab
->elf
.splt
!= NULL
4369 && htab
->elf
.splt
->output_section
!= NULL
)
4371 elf_section_type (htab
->elf
.splt
->output_section
) = SHT_PROGBITS
;
4372 elf_section_flags (htab
->elf
.splt
->output_section
) = SHF_ALLOC
+ SHF_WRITE
;
4375 return _bfd_elf_tls_setup (obfd
, info
);
4378 /* Return TRUE iff REL is a branch reloc with a global symbol matching
4382 branch_reloc_hash_match (const bfd
*ibfd
,
4383 const Elf_Internal_Rela
*rel
,
4384 const struct elf_link_hash_entry
*hash
)
4386 Elf_Internal_Shdr
*symtab_hdr
= &elf_symtab_hdr (ibfd
);
4387 enum elf_ppc_reloc_type r_type
= ELF32_R_TYPE (rel
->r_info
);
4388 unsigned int r_symndx
= ELF32_R_SYM (rel
->r_info
);
4390 if (r_symndx
>= symtab_hdr
->sh_info
&& is_branch_reloc (r_type
))
4392 struct elf_link_hash_entry
**sym_hashes
= elf_sym_hashes (ibfd
);
4393 struct elf_link_hash_entry
*h
;
4395 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
4396 while (h
->root
.type
== bfd_link_hash_indirect
4397 || h
->root
.type
== bfd_link_hash_warning
)
4398 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
4405 /* Run through all the TLS relocs looking for optimization
4409 ppc_elf_tls_optimize (bfd
*obfd ATTRIBUTE_UNUSED
,
4410 struct bfd_link_info
*info
)
4414 struct ppc_elf_link_hash_table
*htab
;
4417 if (!bfd_link_executable (info
))
4420 htab
= ppc_elf_hash_table (info
);
4424 htab
->do_tls_opt
= 1;
4426 /* Make two passes through the relocs. First time check that tls
4427 relocs involved in setting up a tls_get_addr call are indeed
4428 followed by such a call. If they are not, don't do any tls
4429 optimization. On the second pass twiddle tls_mask flags to
4430 notify relocate_section that optimization can be done, and
4431 adjust got and plt refcounts. */
4432 for (pass
= 0; pass
< 2; ++pass
)
4433 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
4435 Elf_Internal_Shdr
*symtab_hdr
= &elf_symtab_hdr (ibfd
);
4436 asection
*got2
= bfd_get_section_by_name (ibfd
, ".got2");
4438 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
4439 if (sec
->has_tls_reloc
&& !bfd_is_abs_section (sec
->output_section
))
4441 Elf_Internal_Rela
*relstart
, *rel
, *relend
;
4442 int expecting_tls_get_addr
= 0;
4444 /* Read the relocations. */
4445 relstart
= _bfd_elf_link_read_relocs (ibfd
, sec
, NULL
, NULL
,
4447 if (relstart
== NULL
)
4450 relend
= relstart
+ sec
->reloc_count
;
4451 for (rel
= relstart
; rel
< relend
; rel
++)
4453 enum elf_ppc_reloc_type r_type
;
4454 unsigned long r_symndx
;
4455 struct elf_link_hash_entry
*h
= NULL
;
4456 unsigned char *tls_mask
;
4457 unsigned char tls_set
, tls_clear
;
4458 bfd_boolean is_local
;
4459 bfd_signed_vma
*got_count
;
4461 r_symndx
= ELF32_R_SYM (rel
->r_info
);
4462 if (r_symndx
>= symtab_hdr
->sh_info
)
4464 struct elf_link_hash_entry
**sym_hashes
;
4466 sym_hashes
= elf_sym_hashes (ibfd
);
4467 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
4468 while (h
->root
.type
== bfd_link_hash_indirect
4469 || h
->root
.type
== bfd_link_hash_warning
)
4470 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
4473 is_local
= SYMBOL_REFERENCES_LOCAL (info
, h
);
4474 r_type
= ELF32_R_TYPE (rel
->r_info
);
4475 /* If this section has old-style __tls_get_addr calls
4476 without marker relocs, then check that each
4477 __tls_get_addr call reloc is preceded by a reloc
4478 that conceivably belongs to the __tls_get_addr arg
4479 setup insn. If we don't find matching arg setup
4480 relocs, don't do any tls optimization. */
4482 && sec
->nomark_tls_get_addr
4484 && h
== htab
->tls_get_addr
4485 && !expecting_tls_get_addr
4486 && is_branch_reloc (r_type
))
4488 info
->callbacks
->minfo ("%H __tls_get_addr lost arg, "
4489 "TLS optimization disabled\n",
4490 ibfd
, sec
, rel
->r_offset
);
4491 if (elf_section_data (sec
)->relocs
!= relstart
)
4496 expecting_tls_get_addr
= 0;
4499 case R_PPC_GOT_TLSLD16
:
4500 case R_PPC_GOT_TLSLD16_LO
:
4501 expecting_tls_get_addr
= 1;
4504 case R_PPC_GOT_TLSLD16_HI
:
4505 case R_PPC_GOT_TLSLD16_HA
:
4506 /* These relocs should never be against a symbol
4507 defined in a shared lib. Leave them alone if
4508 that turns out to be the case. */
4517 case R_PPC_GOT_TLSGD16
:
4518 case R_PPC_GOT_TLSGD16_LO
:
4519 expecting_tls_get_addr
= 1;
4522 case R_PPC_GOT_TLSGD16_HI
:
4523 case R_PPC_GOT_TLSGD16_HA
:
4529 tls_set
= TLS_TLS
| TLS_GDIE
;
4533 case R_PPC_GOT_TPREL16
:
4534 case R_PPC_GOT_TPREL16_LO
:
4535 case R_PPC_GOT_TPREL16_HI
:
4536 case R_PPC_GOT_TPREL16_HA
:
4541 tls_clear
= TLS_TPREL
;
4552 if (rel
+ 1 < relend
4553 && is_plt_seq_reloc (ELF32_R_TYPE (rel
[1].r_info
)))
4556 && ELF32_R_TYPE (rel
[1].r_info
) != R_PPC_PLTSEQ
)
4558 r_type
= ELF32_R_TYPE (rel
[1].r_info
);
4559 r_symndx
= ELF32_R_SYM (rel
[1].r_info
);
4560 if (r_symndx
>= symtab_hdr
->sh_info
)
4562 struct elf_link_hash_entry
**sym_hashes
;
4564 sym_hashes
= elf_sym_hashes (ibfd
);
4565 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
4566 while (h
->root
.type
== bfd_link_hash_indirect
4567 || h
->root
.type
== bfd_link_hash_warning
)
4568 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
4571 struct plt_entry
*ent
= NULL
;
4574 if (bfd_link_pic (info
))
4575 addend
= rel
->r_addend
;
4576 ent
= find_plt_ent (&h
->plt
.plist
,
4579 && ent
->plt
.refcount
> 0)
4580 ent
->plt
.refcount
-= 1;
4586 expecting_tls_get_addr
= 2;
4591 case R_PPC_TPREL16_HA
:
4594 unsigned char buf
[4];
4596 bfd_vma off
= rel
->r_offset
& ~3;
4597 if (!bfd_get_section_contents (ibfd
, sec
, buf
,
4600 if (elf_section_data (sec
)->relocs
!= relstart
)
4604 insn
= bfd_get_32 (ibfd
, buf
);
4605 /* addis rt,2,imm */
4606 if ((insn
& ((0x3fu
<< 26) | 0x1f << 16))
4607 != ((15u << 26) | (2 << 16)))
4609 /* xgettext:c-format */
4610 info
->callbacks
->minfo
4611 (_("%H: warning: %s unexpected insn %#x.\n"),
4612 ibfd
, sec
, off
, "R_PPC_TPREL16_HA", insn
);
4613 htab
->do_tls_opt
= 0;
4618 case R_PPC_TPREL16_HI
:
4619 htab
->do_tls_opt
= 0;
4628 if (!expecting_tls_get_addr
4629 || !sec
->nomark_tls_get_addr
)
4632 if (rel
+ 1 < relend
4633 && branch_reloc_hash_match (ibfd
, rel
+ 1,
4634 htab
->tls_get_addr
))
4637 /* Uh oh, we didn't find the expected call. We
4638 could just mark this symbol to exclude it
4639 from tls optimization but it's safer to skip
4640 the entire optimization. */
4641 info
->callbacks
->minfo (_("%H arg lost __tls_get_addr, "
4642 "TLS optimization disabled\n"),
4643 ibfd
, sec
, rel
->r_offset
);
4644 if (elf_section_data (sec
)->relocs
!= relstart
)
4651 tls_mask
= &ppc_elf_hash_entry (h
)->tls_mask
;
4652 got_count
= &h
->got
.refcount
;
4656 bfd_signed_vma
*lgot_refs
;
4657 struct plt_entry
**local_plt
;
4658 unsigned char *lgot_masks
;
4660 lgot_refs
= elf_local_got_refcounts (ibfd
);
4661 if (lgot_refs
== NULL
)
4663 local_plt
= (struct plt_entry
**)
4664 (lgot_refs
+ symtab_hdr
->sh_info
);
4665 lgot_masks
= (unsigned char *)
4666 (local_plt
+ symtab_hdr
->sh_info
);
4667 tls_mask
= &lgot_masks
[r_symndx
];
4668 got_count
= &lgot_refs
[r_symndx
];
4671 /* If we don't have old-style __tls_get_addr calls
4672 without TLSGD/TLSLD marker relocs, and we haven't
4673 found a new-style __tls_get_addr call with a
4674 marker for this symbol, then we either have a
4675 broken object file or an -mlongcall style
4676 indirect call to __tls_get_addr without a marker.
4677 Disable optimization in this case. */
4678 if ((tls_clear
& (TLS_GD
| TLS_LD
)) != 0
4679 && !sec
->nomark_tls_get_addr
4680 && ((*tls_mask
& (TLS_TLS
| TLS_MARK
))
4681 != (TLS_TLS
| TLS_MARK
)))
4684 if (expecting_tls_get_addr
== 1 + !sec
->nomark_tls_get_addr
)
4686 struct plt_entry
*ent
;
4689 if (bfd_link_pic (info
)
4690 && (ELF32_R_TYPE (rel
[1].r_info
) == R_PPC_PLTREL24
4691 || ELF32_R_TYPE (rel
[1].r_info
) == R_PPC_PLTCALL
))
4692 addend
= rel
[1].r_addend
;
4693 ent
= find_plt_ent (&htab
->tls_get_addr
->plt
.plist
,
4695 if (ent
!= NULL
&& ent
->plt
.refcount
> 0)
4696 ent
->plt
.refcount
-= 1;
4703 /* We managed to get rid of a got entry. */
4708 *tls_mask
|= tls_set
;
4709 *tls_mask
&= ~tls_clear
;
4712 if (elf_section_data (sec
)->relocs
!= relstart
)
4719 /* Return true if we have dynamic relocs against H or any of its weak
4720 aliases, that apply to read-only sections. Cannot be used after
4721 size_dynamic_sections. */
4724 alias_readonly_dynrelocs (struct elf_link_hash_entry
*h
)
4726 struct ppc_elf_link_hash_entry
*eh
= ppc_elf_hash_entry (h
);
4729 if (_bfd_elf_readonly_dynrelocs (&eh
->elf
))
4731 eh
= ppc_elf_hash_entry (eh
->elf
.u
.alias
);
4732 } while (eh
!= NULL
&& &eh
->elf
!= h
);
4737 /* Return whether H has pc-relative dynamic relocs. */
4740 pc_dynrelocs (struct elf_link_hash_entry
*h
)
4742 struct elf_dyn_relocs
*p
;
4744 for (p
= h
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
4745 if (p
->pc_count
!= 0)
4750 /* Adjust a symbol defined by a dynamic object and referenced by a
4751 regular object. The current definition is in some section of the
4752 dynamic object, but we're not including those sections. We have to
4753 change the definition to something the rest of the link can
4757 ppc_elf_adjust_dynamic_symbol (struct bfd_link_info
*info
,
4758 struct elf_link_hash_entry
*h
)
4760 struct ppc_elf_link_hash_table
*htab
;
4764 fprintf (stderr
, "ppc_elf_adjust_dynamic_symbol called for %s\n",
4765 h
->root
.root
.string
);
4768 /* Make sure we know what is going on here. */
4769 htab
= ppc_elf_hash_table (info
);
4770 BFD_ASSERT (htab
->elf
.dynobj
!= NULL
4772 || h
->type
== STT_GNU_IFUNC
4776 && !h
->def_regular
)));
4778 /* Deal with function syms. */
4779 if (h
->type
== STT_FUNC
4780 || h
->type
== STT_GNU_IFUNC
4783 bfd_boolean local
= (SYMBOL_CALLS_LOCAL (info
, h
)
4784 || UNDEFWEAK_NO_DYNAMIC_RELOC (info
, h
));
4785 /* Discard dyn_relocs when non-pic if we've decided that a
4786 function symbol is local. */
4787 if (!bfd_link_pic (info
) && local
)
4788 h
->dyn_relocs
= NULL
;
4790 /* Clear procedure linkage table information for any symbol that
4791 won't need a .plt entry. */
4792 struct plt_entry
*ent
;
4793 for (ent
= h
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
4794 if (ent
->plt
.refcount
> 0)
4797 || (h
->type
!= STT_GNU_IFUNC
4799 && (htab
->can_convert_all_inline_plt
4800 || (ppc_elf_hash_entry (h
)->tls_mask
4801 & (TLS_TLS
| PLT_KEEP
)) != PLT_KEEP
)))
4803 /* A PLT entry is not required/allowed when:
4805 1. We are not using ld.so; because then the PLT entry
4806 can't be set up, so we can't use one. In this case,
4807 ppc_elf_adjust_dynamic_symbol won't even be called.
4809 2. GC has rendered the entry unused.
4811 3. We know for certain that a call to this symbol
4812 will go to this object, or will remain undefined. */
4813 h
->plt
.plist
= NULL
;
4815 h
->pointer_equality_needed
= 0;
4819 /* Taking a function's address in a read/write section
4820 doesn't require us to define the function symbol in the
4821 executable on a plt call stub. A dynamic reloc can
4822 be used instead, giving better runtime performance.
4823 (Calls via that function pointer don't need to bounce
4824 through the plt call stub.) Similarly, use a dynamic
4825 reloc for a weak reference when possible, allowing the
4826 resolution of the symbol to be set at load time rather
4828 if ((h
->pointer_equality_needed
4830 && !h
->ref_regular_nonweak
4831 && !UNDEFWEAK_NO_DYNAMIC_RELOC (info
, h
)))
4832 && htab
->elf
.target_os
!= is_vxworks
4833 && !ppc_elf_hash_entry (h
)->has_sda_refs
4834 && !_bfd_elf_readonly_dynrelocs (h
))
4836 h
->pointer_equality_needed
= 0;
4837 /* If we haven't seen a branch reloc and the symbol
4838 isn't an ifunc then we don't need a plt entry. */
4839 if (!h
->needs_plt
&& h
->type
!= STT_GNU_IFUNC
)
4840 h
->plt
.plist
= NULL
;
4842 else if (!bfd_link_pic (info
))
4843 /* We are going to be defining the function symbol on the
4844 plt stub, so no dyn_relocs needed when non-pic. */
4845 h
->dyn_relocs
= NULL
;
4847 h
->protected_def
= 0;
4848 /* Function symbols can't have copy relocs. */
4852 h
->plt
.plist
= NULL
;
4854 /* If this is a weak symbol, and there is a real definition, the
4855 processor independent code will have arranged for us to see the
4856 real definition first, and we can just use the same value. */
4857 if (h
->is_weakalias
)
4859 struct elf_link_hash_entry
*def
= weakdef (h
);
4860 BFD_ASSERT (def
->root
.type
== bfd_link_hash_defined
);
4861 h
->root
.u
.def
.section
= def
->root
.u
.def
.section
;
4862 h
->root
.u
.def
.value
= def
->root
.u
.def
.value
;
4863 if (def
->root
.u
.def
.section
== htab
->elf
.sdynbss
4864 || def
->root
.u
.def
.section
== htab
->elf
.sdynrelro
4865 || def
->root
.u
.def
.section
== htab
->dynsbss
)
4866 h
->dyn_relocs
= NULL
;
4870 /* This is a reference to a symbol defined by a dynamic object which
4871 is not a function. */
4873 /* If we are creating a shared library, we must presume that the
4874 only references to the symbol are via the global offset table.
4875 For such cases we need not do anything here; the relocations will
4876 be handled correctly by relocate_section. */
4877 if (bfd_link_pic (info
))
4879 h
->protected_def
= 0;
4883 /* If there are no references to this symbol that do not use the
4884 GOT, we don't need to generate a copy reloc. */
4885 if (!h
->non_got_ref
)
4887 h
->protected_def
= 0;
4891 /* Protected variables do not work with .dynbss. The copy in
4892 .dynbss won't be used by the shared library with the protected
4893 definition for the variable. Editing to PIC, or text relocations
4894 are preferable to an incorrect program. */
4895 if (h
->protected_def
)
4897 if (ELIMINATE_COPY_RELOCS
4898 && ppc_elf_hash_entry (h
)->has_addr16_ha
4899 && ppc_elf_hash_entry (h
)->has_addr16_lo
4900 && htab
->params
->pic_fixup
== 0
4901 && info
->disable_target_specific_optimizations
<= 1)
4902 htab
->params
->pic_fixup
= 1;
4906 /* If -z nocopyreloc was given, we won't generate them either. */
4907 if (info
->nocopyreloc
)
4910 /* If we don't find any dynamic relocs in read-only sections, then
4911 we'll be keeping the dynamic relocs and avoiding the copy reloc.
4912 We can't do this if there are any small data relocations. This
4913 doesn't work on VxWorks, where we can not have dynamic
4914 relocations (other than copy and jump slot relocations) in an
4916 if (ELIMINATE_COPY_RELOCS
4917 && !ppc_elf_hash_entry (h
)->has_sda_refs
4918 && htab
->elf
.target_os
!= is_vxworks
4920 && !alias_readonly_dynrelocs (h
))
4923 /* We must allocate the symbol in our .dynbss section, which will
4924 become part of the .bss section of the executable. There will be
4925 an entry for this symbol in the .dynsym section. The dynamic
4926 object will contain position independent code, so all references
4927 from the dynamic object to this symbol will go through the global
4928 offset table. The dynamic linker will use the .dynsym entry to
4929 determine the address it must put in the global offset table, so
4930 both the dynamic object and the regular object will refer to the
4931 same memory location for the variable.
4933 Of course, if the symbol is referenced using SDAREL relocs, we
4934 must instead allocate it in .sbss. */
4935 if (ppc_elf_hash_entry (h
)->has_sda_refs
)
4937 else if ((h
->root
.u
.def
.section
->flags
& SEC_READONLY
) != 0)
4938 s
= htab
->elf
.sdynrelro
;
4940 s
= htab
->elf
.sdynbss
;
4941 BFD_ASSERT (s
!= NULL
);
4943 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0 && h
->size
!= 0)
4947 /* We must generate a R_PPC_COPY reloc to tell the dynamic
4948 linker to copy the initial value out of the dynamic object
4949 and into the runtime process image. */
4950 if (ppc_elf_hash_entry (h
)->has_sda_refs
)
4951 srel
= htab
->relsbss
;
4952 else if ((h
->root
.u
.def
.section
->flags
& SEC_READONLY
) != 0)
4953 srel
= htab
->elf
.sreldynrelro
;
4955 srel
= htab
->elf
.srelbss
;
4956 BFD_ASSERT (srel
!= NULL
);
4957 srel
->size
+= sizeof (Elf32_External_Rela
);
4961 /* We no longer want dyn_relocs. */
4962 h
->dyn_relocs
= NULL
;
4963 return _bfd_elf_adjust_dynamic_copy (info
, h
, s
);
4966 /* Generate a symbol to mark plt call stubs. For non-PIC code the sym is
4967 xxxxxxxx.plt_call32.<callee> where xxxxxxxx is a hex number, usually 0,
4968 specifying the addend on the plt relocation. For -fpic code, the sym
4969 is xxxxxxxx.plt_pic32.<callee>, and for -fPIC
4970 xxxxxxxx.got2.plt_pic32.<callee>. */
4973 add_stub_sym (struct plt_entry
*ent
,
4974 struct elf_link_hash_entry
*h
,
4975 struct bfd_link_info
*info
)
4977 struct elf_link_hash_entry
*sh
;
4978 size_t len1
, len2
, len3
;
4981 struct ppc_elf_link_hash_table
*htab
= ppc_elf_hash_table (info
);
4983 if (bfd_link_pic (info
))
4984 stub
= ".plt_pic32.";
4986 stub
= ".plt_call32.";
4988 len1
= strlen (h
->root
.root
.string
);
4989 len2
= strlen (stub
);
4992 len3
= strlen (ent
->sec
->name
);
4993 name
= bfd_malloc (len1
+ len2
+ len3
+ 9);
4996 sprintf (name
, "%08x", (unsigned) ent
->addend
& 0xffffffff);
4998 memcpy (name
+ 8, ent
->sec
->name
, len3
);
4999 memcpy (name
+ 8 + len3
, stub
, len2
);
5000 memcpy (name
+ 8 + len3
+ len2
, h
->root
.root
.string
, len1
+ 1);
5001 sh
= elf_link_hash_lookup (&htab
->elf
, name
, TRUE
, FALSE
, FALSE
);
5004 if (sh
->root
.type
== bfd_link_hash_new
)
5006 sh
->root
.type
= bfd_link_hash_defined
;
5007 sh
->root
.u
.def
.section
= htab
->glink
;
5008 sh
->root
.u
.def
.value
= ent
->glink_offset
;
5009 sh
->ref_regular
= 1;
5010 sh
->def_regular
= 1;
5011 sh
->ref_regular_nonweak
= 1;
5012 sh
->forced_local
= 1;
5014 sh
->root
.linker_def
= 1;
5019 /* Allocate NEED contiguous space in .got, and return the offset.
5020 Handles allocation of the got header when crossing 32k. */
5023 allocate_got (struct ppc_elf_link_hash_table
*htab
, unsigned int need
)
5026 unsigned int max_before_header
;
5028 if (htab
->plt_type
== PLT_VXWORKS
)
5030 where
= htab
->elf
.sgot
->size
;
5031 htab
->elf
.sgot
->size
+= need
;
5035 max_before_header
= htab
->plt_type
== PLT_NEW
? 32768 : 32764;
5036 if (need
<= htab
->got_gap
)
5038 where
= max_before_header
- htab
->got_gap
;
5039 htab
->got_gap
-= need
;
5043 if (htab
->elf
.sgot
->size
+ need
> max_before_header
5044 && htab
->elf
.sgot
->size
<= max_before_header
)
5046 htab
->got_gap
= max_before_header
- htab
->elf
.sgot
->size
;
5047 htab
->elf
.sgot
->size
= max_before_header
+ htab
->got_header_size
;
5049 where
= htab
->elf
.sgot
->size
;
5050 htab
->elf
.sgot
->size
+= need
;
5056 /* Calculate size of GOT entries for symbol given its TLS_MASK.
5057 TLS_LD is excluded because those go in a special GOT slot. */
5059 static inline unsigned int
5060 got_entries_needed (int tls_mask
)
5063 if ((tls_mask
& TLS_TLS
) == 0)
5068 if ((tls_mask
& TLS_GD
) != 0)
5070 if ((tls_mask
& (TLS_TPREL
| TLS_GDIE
)) != 0)
5072 if ((tls_mask
& TLS_DTPREL
) != 0)
5078 /* If H is undefined, make it dynamic if that makes sense. */
5081 ensure_undef_dynamic (struct bfd_link_info
*info
,
5082 struct elf_link_hash_entry
*h
)
5084 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
5086 if (htab
->dynamic_sections_created
5087 && ((info
->dynamic_undefined_weak
!= 0
5088 && h
->root
.type
== bfd_link_hash_undefweak
)
5089 || h
->root
.type
== bfd_link_hash_undefined
)
5092 && ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
)
5093 return bfd_elf_link_record_dynamic_symbol (info
, h
);
5097 /* Choose whether to use htab->iplt or htab->pltlocal rather than the
5098 usual htab->elf.splt section for a PLT entry. */
5101 bfd_boolean
use_local_plt (struct bfd_link_info
*info
,
5102 struct elf_link_hash_entry
*h
)
5106 || !elf_hash_table (info
)->dynamic_sections_created
);
5109 /* Allocate space in associated reloc sections for dynamic relocs. */
5112 allocate_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
5114 struct bfd_link_info
*info
= inf
;
5115 struct ppc_elf_link_hash_entry
*eh
;
5116 struct ppc_elf_link_hash_table
*htab
;
5117 struct elf_dyn_relocs
*p
;
5119 if (h
->root
.type
== bfd_link_hash_indirect
)
5122 htab
= ppc_elf_hash_table (info
);
5123 eh
= (struct ppc_elf_link_hash_entry
*) h
;
5124 if (eh
->elf
.got
.refcount
> 0
5125 || (ELIMINATE_COPY_RELOCS
5126 && !eh
->elf
.def_regular
5127 && eh
->elf
.protected_def
5128 && eh
->has_addr16_ha
5129 && eh
->has_addr16_lo
5130 && htab
->params
->pic_fixup
> 0))
5134 /* Make sure this symbol is output as a dynamic symbol. */
5135 if (!ensure_undef_dynamic (info
, &eh
->elf
))
5139 if ((eh
->tls_mask
& (TLS_TLS
| TLS_LD
)) == (TLS_TLS
| TLS_LD
))
5141 if (SYMBOL_REFERENCES_LOCAL (info
, &eh
->elf
))
5142 /* We'll just use htab->tlsld_got.offset. This should
5143 always be the case. It's a little odd if we have
5144 a local dynamic reloc against a non-local symbol. */
5145 htab
->tlsld_got
.refcount
+= 1;
5149 need
+= got_entries_needed (eh
->tls_mask
);
5151 eh
->elf
.got
.offset
= (bfd_vma
) -1;
5154 eh
->elf
.got
.offset
= allocate_got (htab
, need
);
5155 if (((bfd_link_pic (info
)
5156 && !((eh
->tls_mask
& TLS_TLS
) != 0
5157 && bfd_link_executable (info
)
5158 && SYMBOL_REFERENCES_LOCAL (info
, &eh
->elf
)))
5159 || (htab
->elf
.dynamic_sections_created
5160 && eh
->elf
.dynindx
!= -1
5161 && !SYMBOL_REFERENCES_LOCAL (info
, &eh
->elf
)))
5162 && !UNDEFWEAK_NO_DYNAMIC_RELOC (info
, &eh
->elf
))
5166 need
*= sizeof (Elf32_External_Rela
) / 4;
5167 if ((eh
->tls_mask
& (TLS_TLS
| TLS_LD
)) == (TLS_TLS
| TLS_LD
))
5168 need
-= sizeof (Elf32_External_Rela
);
5169 rsec
= htab
->elf
.srelgot
;
5170 if (eh
->elf
.type
== STT_GNU_IFUNC
)
5171 rsec
= htab
->elf
.irelplt
;
5177 eh
->elf
.got
.offset
= (bfd_vma
) -1;
5179 /* If no dynamic sections we can't have dynamic relocs, except for
5180 IFUNCs which are handled even in static executables. */
5181 if (!htab
->elf
.dynamic_sections_created
5182 && h
->type
!= STT_GNU_IFUNC
)
5183 h
->dyn_relocs
= NULL
;
5185 /* Discard relocs on undefined symbols that must be local. */
5186 else if (h
->root
.type
== bfd_link_hash_undefined
5187 && ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
5188 h
->dyn_relocs
= NULL
;
5190 /* Also discard relocs on undefined weak syms with non-default
5191 visibility, or when dynamic_undefined_weak says so. */
5192 else if (UNDEFWEAK_NO_DYNAMIC_RELOC (info
, h
))
5193 h
->dyn_relocs
= NULL
;
5195 if (h
->dyn_relocs
== NULL
)
5198 /* In the shared -Bsymbolic case, discard space allocated for
5199 dynamic pc-relative relocs against symbols which turn out to be
5200 defined in regular objects. For the normal shared case, discard
5201 space for relocs that have become local due to symbol visibility
5203 else if (bfd_link_pic (info
))
5205 /* Relocs that use pc_count are those that appear on a call insn,
5206 or certain REL relocs (see must_be_dyn_reloc) that can be
5207 generated via assembly. We want calls to protected symbols to
5208 resolve directly to the function rather than going via the plt.
5209 If people want function pointer comparisons to work as expected
5210 then they should avoid writing weird assembly. */
5211 if (SYMBOL_CALLS_LOCAL (info
, h
))
5213 struct elf_dyn_relocs
**pp
;
5215 for (pp
= &h
->dyn_relocs
; (p
= *pp
) != NULL
; )
5217 p
->count
-= p
->pc_count
;
5226 if (htab
->elf
.target_os
== is_vxworks
)
5228 struct elf_dyn_relocs
**pp
;
5230 for (pp
= &h
->dyn_relocs
; (p
= *pp
) != NULL
; )
5232 if (strcmp (p
->sec
->output_section
->name
, ".tls_vars") == 0)
5239 if (h
->dyn_relocs
!= NULL
)
5241 /* Make sure this symbol is output as a dynamic symbol. */
5242 if (!ensure_undef_dynamic (info
, h
))
5246 else if (ELIMINATE_COPY_RELOCS
)
5248 /* For the non-pic case, discard space for relocs against
5249 symbols which turn out to need copy relocs or are not
5251 if (h
->dynamic_adjusted
5253 && !ELF_COMMON_DEF_P (h
)
5254 && !(h
->protected_def
5255 && eh
->has_addr16_ha
5256 && eh
->has_addr16_lo
5257 && htab
->params
->pic_fixup
> 0))
5259 /* Make sure this symbol is output as a dynamic symbol. */
5260 if (!ensure_undef_dynamic (info
, h
))
5263 if (h
->dynindx
== -1)
5264 h
->dyn_relocs
= NULL
;
5267 h
->dyn_relocs
= NULL
;
5270 /* Allocate space. */
5271 for (p
= h
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
5273 asection
*sreloc
= elf_section_data (p
->sec
)->sreloc
;
5274 if (eh
->elf
.type
== STT_GNU_IFUNC
)
5275 sreloc
= htab
->elf
.irelplt
;
5276 sreloc
->size
+= p
->count
* sizeof (Elf32_External_Rela
);
5279 /* Handle PLT relocs. Done last, after dynindx has settled.
5280 We might need a PLT entry when the symbol
5283 c) has plt16 relocs and has been processed by adjust_dynamic_symbol, or
5284 d) has plt16 relocs and we are linking statically. */
5285 if ((htab
->elf
.dynamic_sections_created
&& h
->dynindx
!= -1)
5286 || h
->type
== STT_GNU_IFUNC
5287 || (h
->needs_plt
&& h
->dynamic_adjusted
)
5290 && !htab
->elf
.dynamic_sections_created
5291 && !htab
->can_convert_all_inline_plt
5292 && (ppc_elf_hash_entry (h
)->tls_mask
5293 & (TLS_TLS
| PLT_KEEP
)) == PLT_KEEP
))
5295 struct plt_entry
*ent
;
5296 bfd_boolean doneone
= FALSE
;
5297 bfd_vma plt_offset
= 0, glink_offset
= (bfd_vma
) -1;
5299 for (ent
= h
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
5300 if (ent
->plt
.refcount
> 0)
5302 asection
*s
= htab
->elf
.splt
;
5303 bfd_boolean dyn
= !use_local_plt (info
, h
);
5307 if (h
->type
== STT_GNU_IFUNC
)
5313 if (htab
->plt_type
== PLT_NEW
|| !dyn
)
5317 plt_offset
= s
->size
;
5320 ent
->plt
.offset
= plt_offset
;
5322 if (s
== htab
->pltlocal
)
5323 ent
->glink_offset
= glink_offset
;
5327 if (!doneone
|| bfd_link_pic (info
))
5329 glink_offset
= s
->size
;
5330 s
->size
+= GLINK_ENTRY_SIZE (htab
, h
);
5333 && !bfd_link_pic (info
)
5337 h
->root
.u
.def
.section
= s
;
5338 h
->root
.u
.def
.value
= glink_offset
;
5340 ent
->glink_offset
= glink_offset
;
5342 if (htab
->params
->emit_stub_syms
5343 && !add_stub_sym (ent
, h
, info
))
5351 /* If this is the first .plt entry, make room
5352 for the special first entry. */
5354 s
->size
+= htab
->plt_initial_entry_size
;
5356 /* The PowerPC PLT is actually composed of two
5357 parts, the first part is 2 words (for a load
5358 and a jump), and then there is a remaining
5359 word available at the end. */
5360 plt_offset
= (htab
->plt_initial_entry_size
5361 + (htab
->plt_slot_size
5363 - htab
->plt_initial_entry_size
)
5364 / htab
->plt_entry_size
)));
5366 /* If this symbol is not defined in a regular
5367 file, and we are not generating a shared
5368 library, then set the symbol to this location
5369 in the .plt. This is to avoid text
5370 relocations, and is required to make
5371 function pointers compare as equal between
5372 the normal executable and the shared library. */
5373 if (! bfd_link_pic (info
)
5377 h
->root
.u
.def
.section
= s
;
5378 h
->root
.u
.def
.value
= plt_offset
;
5381 /* Make room for this entry. */
5382 s
->size
+= htab
->plt_entry_size
;
5383 /* After the 8192nd entry, room for two entries
5385 if (htab
->plt_type
== PLT_OLD
5386 && (s
->size
- htab
->plt_initial_entry_size
)
5387 / htab
->plt_entry_size
5388 > PLT_NUM_SINGLE_ENTRIES
)
5389 s
->size
+= htab
->plt_entry_size
;
5391 ent
->plt
.offset
= plt_offset
;
5394 /* We also need to make an entry in the .rela.plt section. */
5399 if (h
->type
== STT_GNU_IFUNC
)
5401 s
= htab
->elf
.irelplt
;
5402 s
->size
+= sizeof (Elf32_External_Rela
);
5404 else if (bfd_link_pic (info
))
5406 s
= htab
->relpltlocal
;
5407 s
->size
+= sizeof (Elf32_External_Rela
);
5412 htab
->elf
.srelplt
->size
+= sizeof (Elf32_External_Rela
);
5414 if (htab
->plt_type
== PLT_VXWORKS
)
5416 /* Allocate space for the unloaded relocations. */
5417 if (!bfd_link_pic (info
)
5418 && htab
->elf
.dynamic_sections_created
)
5421 == (bfd_vma
) htab
->plt_initial_entry_size
)
5423 htab
->srelplt2
->size
5424 += (sizeof (Elf32_External_Rela
)
5425 * VXWORKS_PLTRESOLVE_RELOCS
);
5428 htab
->srelplt2
->size
5429 += (sizeof (Elf32_External_Rela
)
5430 * VXWORKS_PLT_NON_JMP_SLOT_RELOCS
);
5433 /* Every PLT entry has an associated GOT entry in
5435 htab
->elf
.sgotplt
->size
+= 4;
5442 ent
->plt
.offset
= (bfd_vma
) -1;
5446 h
->plt
.plist
= NULL
;
5452 h
->plt
.plist
= NULL
;
5459 static const unsigned char glink_eh_frame_cie
[] =
5461 0, 0, 0, 16, /* length. */
5462 0, 0, 0, 0, /* id. */
5463 1, /* CIE version. */
5464 'z', 'R', 0, /* Augmentation string. */
5465 4, /* Code alignment. */
5466 0x7c, /* Data alignment. */
5468 1, /* Augmentation size. */
5469 DW_EH_PE_pcrel
| DW_EH_PE_sdata4
, /* FDE encoding. */
5470 DW_CFA_def_cfa
, 1, 0 /* def_cfa: r1 offset 0. */
5473 /* Set the sizes of the dynamic sections. */
5476 ppc_elf_size_dynamic_sections (bfd
*output_bfd
,
5477 struct bfd_link_info
*info
)
5479 struct ppc_elf_link_hash_table
*htab
;
5485 fprintf (stderr
, "ppc_elf_size_dynamic_sections called\n");
5488 htab
= ppc_elf_hash_table (info
);
5489 BFD_ASSERT (htab
->elf
.dynobj
!= NULL
);
5491 if (elf_hash_table (info
)->dynamic_sections_created
)
5493 /* Set the contents of the .interp section to the interpreter. */
5494 if (bfd_link_executable (info
) && !info
->nointerp
)
5496 s
= bfd_get_linker_section (htab
->elf
.dynobj
, ".interp");
5497 BFD_ASSERT (s
!= NULL
);
5498 s
->size
= sizeof ELF_DYNAMIC_INTERPRETER
;
5499 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
5503 if (htab
->plt_type
== PLT_OLD
)
5504 htab
->got_header_size
= 16;
5505 else if (htab
->plt_type
== PLT_NEW
)
5506 htab
->got_header_size
= 12;
5508 /* Set up .got offsets for local syms, and space for local dynamic
5510 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
5512 bfd_signed_vma
*local_got
;
5513 bfd_signed_vma
*end_local_got
;
5514 struct plt_entry
**local_plt
;
5515 struct plt_entry
**end_local_plt
;
5517 bfd_size_type locsymcount
;
5518 Elf_Internal_Shdr
*symtab_hdr
;
5520 if (!is_ppc_elf (ibfd
))
5523 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
5525 struct ppc_dyn_relocs
*p
;
5527 for (p
= ((struct ppc_dyn_relocs
*)
5528 elf_section_data (s
)->local_dynrel
);
5532 if (!bfd_is_abs_section (p
->sec
)
5533 && bfd_is_abs_section (p
->sec
->output_section
))
5535 /* Input section has been discarded, either because
5536 it is a copy of a linkonce section or due to
5537 linker script /DISCARD/, so we'll be discarding
5540 else if (htab
->elf
.target_os
== is_vxworks
5541 && strcmp (p
->sec
->output_section
->name
,
5544 /* Relocations in vxworks .tls_vars sections are
5545 handled specially by the loader. */
5547 else if (p
->count
!= 0)
5549 asection
*sreloc
= elf_section_data (p
->sec
)->sreloc
;
5551 sreloc
= htab
->elf
.irelplt
;
5552 sreloc
->size
+= p
->count
* sizeof (Elf32_External_Rela
);
5553 if ((p
->sec
->output_section
->flags
5554 & (SEC_READONLY
| SEC_ALLOC
))
5555 == (SEC_READONLY
| SEC_ALLOC
))
5557 info
->flags
|= DF_TEXTREL
;
5558 info
->callbacks
->minfo (_("%pB: dynamic relocation in read-only section `%pA'\n"),
5559 p
->sec
->owner
, p
->sec
);
5565 local_got
= elf_local_got_refcounts (ibfd
);
5569 symtab_hdr
= &elf_symtab_hdr (ibfd
);
5570 locsymcount
= symtab_hdr
->sh_info
;
5571 end_local_got
= local_got
+ locsymcount
;
5572 local_plt
= (struct plt_entry
**) end_local_got
;
5573 end_local_plt
= local_plt
+ locsymcount
;
5574 lgot_masks
= (char *) end_local_plt
;
5576 for (; local_got
< end_local_got
; ++local_got
, ++lgot_masks
)
5580 if ((*lgot_masks
& (TLS_TLS
| TLS_LD
)) == (TLS_TLS
| TLS_LD
))
5581 htab
->tlsld_got
.refcount
+= 1;
5582 need
= got_entries_needed (*lgot_masks
);
5584 *local_got
= (bfd_vma
) -1;
5587 *local_got
= allocate_got (htab
, need
);
5588 if (bfd_link_pic (info
)
5589 && !((*lgot_masks
& TLS_TLS
) != 0
5590 && bfd_link_executable (info
)))
5594 need
*= sizeof (Elf32_External_Rela
) / 4;
5595 srel
= htab
->elf
.srelgot
;
5596 if ((*lgot_masks
& (TLS_TLS
| PLT_IFUNC
)) == PLT_IFUNC
)
5597 srel
= htab
->elf
.irelplt
;
5603 *local_got
= (bfd_vma
) -1;
5605 if (htab
->elf
.target_os
== is_vxworks
)
5608 /* Allocate space for calls to local STT_GNU_IFUNC syms in .iplt. */
5609 lgot_masks
= (char *) end_local_plt
;
5610 for (; local_plt
< end_local_plt
; ++local_plt
, ++lgot_masks
)
5612 struct plt_entry
*ent
;
5613 bfd_boolean doneone
= FALSE
;
5614 bfd_vma plt_offset
= 0, glink_offset
= (bfd_vma
) -1;
5616 for (ent
= *local_plt
; ent
!= NULL
; ent
= ent
->next
)
5617 if (ent
->plt
.refcount
> 0)
5619 if ((*lgot_masks
& (TLS_TLS
| PLT_IFUNC
)) == PLT_IFUNC
)
5621 else if (htab
->can_convert_all_inline_plt
5622 || (*lgot_masks
& (TLS_TLS
| PLT_KEEP
)) != PLT_KEEP
)
5624 ent
->plt
.offset
= (bfd_vma
) -1;
5632 plt_offset
= s
->size
;
5635 ent
->plt
.offset
= plt_offset
;
5637 if (s
!= htab
->pltlocal
&& (!doneone
|| bfd_link_pic (info
)))
5640 glink_offset
= s
->size
;
5641 s
->size
+= GLINK_ENTRY_SIZE (htab
, NULL
);
5643 ent
->glink_offset
= glink_offset
;
5647 if ((*lgot_masks
& (TLS_TLS
| PLT_IFUNC
)) == PLT_IFUNC
)
5649 s
= htab
->elf
.irelplt
;
5650 s
->size
+= sizeof (Elf32_External_Rela
);
5652 else if (bfd_link_pic (info
))
5654 s
= htab
->relpltlocal
;
5655 s
->size
+= sizeof (Elf32_External_Rela
);
5661 ent
->plt
.offset
= (bfd_vma
) -1;
5665 /* Allocate space for global sym dynamic relocs. */
5666 elf_link_hash_traverse (elf_hash_table (info
), allocate_dynrelocs
, info
);
5668 if (htab
->tlsld_got
.refcount
> 0)
5670 htab
->tlsld_got
.offset
= allocate_got (htab
, 8);
5671 if (bfd_link_dll (info
))
5672 htab
->elf
.srelgot
->size
+= sizeof (Elf32_External_Rela
);
5675 htab
->tlsld_got
.offset
= (bfd_vma
) -1;
5677 if (htab
->elf
.sgot
!= NULL
&& htab
->plt_type
!= PLT_VXWORKS
)
5679 unsigned int g_o_t
= 32768;
5681 /* If we haven't allocated the header, do so now. When we get here,
5682 for old plt/got the got size will be 0 to 32764 (not allocated),
5683 or 32780 to 65536 (header allocated). For new plt/got, the
5684 corresponding ranges are 0 to 32768 and 32780 to 65536. */
5685 if (htab
->elf
.sgot
->size
<= 32768)
5687 g_o_t
= htab
->elf
.sgot
->size
;
5688 if (htab
->plt_type
== PLT_OLD
)
5690 htab
->elf
.sgot
->size
+= htab
->got_header_size
;
5693 htab
->elf
.hgot
->root
.u
.def
.value
= g_o_t
;
5695 if (bfd_link_pic (info
))
5697 struct elf_link_hash_entry
*sda
= htab
->sdata
[0].sym
;
5699 sda
->root
.u
.def
.section
= htab
->elf
.hgot
->root
.u
.def
.section
;
5700 sda
->root
.u
.def
.value
= htab
->elf
.hgot
->root
.u
.def
.value
;
5702 if (info
->emitrelocations
)
5704 struct elf_link_hash_entry
*sda
= htab
->sdata
[0].sym
;
5706 if (sda
!= NULL
&& sda
->ref_regular
)
5707 sda
->root
.u
.def
.section
->flags
|= SEC_KEEP
;
5708 sda
= htab
->sdata
[1].sym
;
5709 if (sda
!= NULL
&& sda
->ref_regular
)
5710 sda
->root
.u
.def
.section
->flags
|= SEC_KEEP
;
5713 if (htab
->glink
!= NULL
5714 && htab
->glink
->size
!= 0
5715 && htab
->elf
.dynamic_sections_created
)
5717 htab
->glink_pltresolve
= htab
->glink
->size
;
5718 /* Space for the branch table. */
5720 += htab
->elf
.srelplt
->size
/ (sizeof (Elf32_External_Rela
) / 4) - 4;
5721 /* Pad out to align the start of PLTresolve. */
5722 htab
->glink
->size
+= -htab
->glink
->size
& (htab
->params
->ppc476_workaround
5724 htab
->glink
->size
+= GLINK_PLTRESOLVE
;
5726 if (htab
->params
->emit_stub_syms
)
5728 struct elf_link_hash_entry
*sh
;
5729 sh
= elf_link_hash_lookup (&htab
->elf
, "__glink",
5730 TRUE
, FALSE
, FALSE
);
5733 if (sh
->root
.type
== bfd_link_hash_new
)
5735 sh
->root
.type
= bfd_link_hash_defined
;
5736 sh
->root
.u
.def
.section
= htab
->glink
;
5737 sh
->root
.u
.def
.value
= htab
->glink_pltresolve
;
5738 sh
->ref_regular
= 1;
5739 sh
->def_regular
= 1;
5740 sh
->ref_regular_nonweak
= 1;
5741 sh
->forced_local
= 1;
5743 sh
->root
.linker_def
= 1;
5745 sh
= elf_link_hash_lookup (&htab
->elf
, "__glink_PLTresolve",
5746 TRUE
, FALSE
, FALSE
);
5749 if (sh
->root
.type
== bfd_link_hash_new
)
5751 sh
->root
.type
= bfd_link_hash_defined
;
5752 sh
->root
.u
.def
.section
= htab
->glink
;
5753 sh
->root
.u
.def
.value
= htab
->glink
->size
- GLINK_PLTRESOLVE
;
5754 sh
->ref_regular
= 1;
5755 sh
->def_regular
= 1;
5756 sh
->ref_regular_nonweak
= 1;
5757 sh
->forced_local
= 1;
5759 sh
->root
.linker_def
= 1;
5764 if (htab
->glink
!= NULL
5765 && htab
->glink
->size
!= 0
5766 && htab
->glink_eh_frame
!= NULL
5767 && !bfd_is_abs_section (htab
->glink_eh_frame
->output_section
)
5768 && _bfd_elf_eh_frame_present (info
))
5770 s
= htab
->glink_eh_frame
;
5771 s
->size
= sizeof (glink_eh_frame_cie
) + 20;
5772 if (bfd_link_pic (info
))
5775 if (htab
->glink
->size
- GLINK_PLTRESOLVE
+ 8 >= 256)
5780 /* We've now determined the sizes of the various dynamic sections.
5781 Allocate memory for them. */
5783 for (s
= htab
->elf
.dynobj
->sections
; s
!= NULL
; s
= s
->next
)
5785 bfd_boolean strip_section
= TRUE
;
5787 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
5790 if (s
== htab
->elf
.splt
5791 || s
== htab
->elf
.sgot
)
5793 /* We'd like to strip these sections if they aren't needed, but if
5794 we've exported dynamic symbols from them we must leave them.
5795 It's too late to tell BFD to get rid of the symbols. */
5796 if (htab
->elf
.hplt
!= NULL
)
5797 strip_section
= FALSE
;
5798 /* Strip this section if we don't need it; see the
5801 else if (s
== htab
->elf
.iplt
5802 || s
== htab
->pltlocal
5804 || s
== htab
->glink_eh_frame
5805 || s
== htab
->elf
.sgotplt
5807 || s
== htab
->elf
.sdynbss
5808 || s
== htab
->elf
.sdynrelro
5809 || s
== htab
->dynsbss
)
5811 /* Strip these too. */
5813 else if (s
== htab
->sdata
[0].section
5814 || s
== htab
->sdata
[1].section
)
5816 strip_section
= (s
->flags
& SEC_KEEP
) == 0;
5818 else if (CONST_STRNEQ (bfd_section_name (s
), ".rela"))
5822 /* Remember whether there are any relocation sections. */
5825 /* We use the reloc_count field as a counter if we need
5826 to copy relocs into the output file. */
5832 /* It's not one of our sections, so don't allocate space. */
5836 if (s
->size
== 0 && strip_section
)
5838 /* If we don't need this section, strip it from the
5839 output file. This is mostly to handle .rela.bss and
5840 .rela.plt. We must create both sections in
5841 create_dynamic_sections, because they must be created
5842 before the linker maps input sections to output
5843 sections. The linker does that before
5844 adjust_dynamic_symbol is called, and it is that
5845 function which decides whether anything needs to go
5846 into these sections. */
5847 s
->flags
|= SEC_EXCLUDE
;
5851 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
5854 /* Allocate memory for the section contents. */
5855 s
->contents
= bfd_zalloc (htab
->elf
.dynobj
, s
->size
);
5856 if (s
->contents
== NULL
)
5860 if (htab
->elf
.dynamic_sections_created
)
5862 /* Add some entries to the .dynamic section. We fill in the
5863 values later, in ppc_elf_finish_dynamic_sections, but we
5864 must add the entries now so that we get the correct size for
5865 the .dynamic section. The DT_DEBUG entry is filled in by the
5866 dynamic linker and used by the debugger. */
5867 #define add_dynamic_entry(TAG, VAL) \
5868 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
5870 if (!_bfd_elf_maybe_vxworks_add_dynamic_tags (output_bfd
, info
,
5874 if (htab
->plt_type
== PLT_NEW
5875 && htab
->glink
!= NULL
5876 && htab
->glink
->size
!= 0)
5878 if (!add_dynamic_entry (DT_PPC_GOT
, 0))
5880 if (!htab
->params
->no_tls_get_addr_opt
5881 && htab
->tls_get_addr
!= NULL
5882 && htab
->tls_get_addr
->plt
.plist
!= NULL
5883 && !add_dynamic_entry (DT_PPC_OPT
, PPC_OPT_TLS
))
5887 #undef add_dynamic_entry
5889 if (htab
->glink_eh_frame
!= NULL
5890 && htab
->glink_eh_frame
->contents
!= NULL
)
5892 unsigned char *p
= htab
->glink_eh_frame
->contents
;
5895 memcpy (p
, glink_eh_frame_cie
, sizeof (glink_eh_frame_cie
));
5896 /* CIE length (rewrite in case little-endian). */
5897 bfd_put_32 (htab
->elf
.dynobj
, sizeof (glink_eh_frame_cie
) - 4, p
);
5898 p
+= sizeof (glink_eh_frame_cie
);
5900 val
= htab
->glink_eh_frame
->size
- 4 - sizeof (glink_eh_frame_cie
);
5901 bfd_put_32 (htab
->elf
.dynobj
, val
, p
);
5904 val
= p
- htab
->glink_eh_frame
->contents
;
5905 bfd_put_32 (htab
->elf
.dynobj
, val
, p
);
5907 /* Offset to .glink. Set later. */
5910 bfd_put_32 (htab
->elf
.dynobj
, htab
->glink
->size
, p
);
5915 if (bfd_link_pic (info
)
5916 && htab
->elf
.dynamic_sections_created
)
5918 bfd_vma adv
= (htab
->glink
->size
- GLINK_PLTRESOLVE
+ 8) >> 2;
5920 *p
++ = DW_CFA_advance_loc
+ adv
;
5923 *p
++ = DW_CFA_advance_loc1
;
5926 else if (adv
< 65536)
5928 *p
++ = DW_CFA_advance_loc2
;
5929 bfd_put_16 (htab
->elf
.dynobj
, adv
, p
);
5934 *p
++ = DW_CFA_advance_loc4
;
5935 bfd_put_32 (htab
->elf
.dynobj
, adv
, p
);
5938 *p
++ = DW_CFA_register
;
5941 *p
++ = DW_CFA_advance_loc
+ 4;
5942 *p
++ = DW_CFA_restore_extended
;
5945 BFD_ASSERT ((bfd_vma
) ((p
+ 3 - htab
->glink_eh_frame
->contents
) & -4)
5946 == htab
->glink_eh_frame
->size
);
5952 /* Arrange to have _SDA_BASE_ or _SDA2_BASE_ stripped from the output
5953 if it looks like nothing is using them. */
5956 maybe_strip_sdasym (bfd
*output_bfd
, elf_linker_section_t
*lsect
)
5958 struct elf_link_hash_entry
*sda
= lsect
->sym
;
5960 if (sda
!= NULL
&& !sda
->ref_regular
&& sda
->dynindx
== -1)
5964 s
= bfd_get_section_by_name (output_bfd
, lsect
->name
);
5965 if (s
== NULL
|| bfd_section_removed_from_list (output_bfd
, s
))
5967 s
= bfd_get_section_by_name (output_bfd
, lsect
->bss_name
);
5968 if (s
== NULL
|| bfd_section_removed_from_list (output_bfd
, s
))
5970 sda
->def_regular
= 0;
5971 /* This is somewhat magic. See elf_link_output_extsym. */
5972 sda
->ref_dynamic
= 1;
5973 sda
->forced_local
= 0;
5980 ppc_elf_maybe_strip_sdata_syms (struct bfd_link_info
*info
)
5982 struct ppc_elf_link_hash_table
*htab
= ppc_elf_hash_table (info
);
5986 maybe_strip_sdasym (info
->output_bfd
, &htab
->sdata
[0]);
5987 maybe_strip_sdasym (info
->output_bfd
, &htab
->sdata
[1]);
5992 /* Return TRUE if symbol should be hashed in the `.gnu.hash' section. */
5995 ppc_elf_hash_symbol (struct elf_link_hash_entry
*h
)
5997 if (h
->plt
.plist
!= NULL
5999 && (!h
->pointer_equality_needed
6000 || !h
->ref_regular_nonweak
))
6003 return _bfd_elf_hash_symbol (h
);
6006 #define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
6008 /* Relaxation trampolines. r12 is available for clobbering (r11, is
6009 used for some functions that are allowed to break the ABI). */
6010 static const int shared_stub_entry
[] =
6012 0x7c0802a6, /* mflr 0 */
6013 0x429f0005, /* bcl 20, 31, .Lxxx */
6014 0x7d8802a6, /* mflr 12 */
6015 0x3d8c0000, /* addis 12, 12, (xxx-.Lxxx)@ha */
6016 0x398c0000, /* addi 12, 12, (xxx-.Lxxx)@l */
6017 0x7c0803a6, /* mtlr 0 */
6018 0x7d8903a6, /* mtctr 12 */
6019 0x4e800420, /* bctr */
6022 static const int stub_entry
[] =
6024 0x3d800000, /* lis 12,xxx@ha */
6025 0x398c0000, /* addi 12,12,xxx@l */
6026 0x7d8903a6, /* mtctr 12 */
6027 0x4e800420, /* bctr */
6030 struct ppc_elf_relax_info
6032 unsigned int workaround_size
;
6033 unsigned int picfixup_size
;
6036 /* This function implements long branch trampolines, and the ppc476
6037 icache bug workaround. Any section needing trampolines or patch
6038 space for the workaround has its size extended so that we can
6039 add trampolines at the end of the section. */
6042 ppc_elf_relax_section (bfd
*abfd
,
6044 struct bfd_link_info
*link_info
,
6047 struct one_branch_fixup
6049 struct one_branch_fixup
*next
;
6051 /* Final link, can use the symbol offset. For a
6052 relocatable link we use the symbol's index. */
6057 Elf_Internal_Shdr
*symtab_hdr
;
6058 bfd_byte
*contents
= NULL
;
6059 Elf_Internal_Sym
*isymbuf
= NULL
;
6060 Elf_Internal_Rela
*internal_relocs
= NULL
;
6061 Elf_Internal_Rela
*irel
, *irelend
= NULL
;
6062 struct one_branch_fixup
*branch_fixups
= NULL
;
6063 struct ppc_elf_relax_info
*relax_info
= NULL
;
6064 unsigned changes
= 0;
6065 bfd_boolean workaround_change
;
6066 struct ppc_elf_link_hash_table
*htab
;
6067 bfd_size_type trampbase
, trampoff
, newsize
, picfixup_size
;
6069 bfd_boolean maybe_pasted
;
6073 /* No need to do anything with non-alloc or non-code sections. */
6074 if ((isec
->flags
& SEC_ALLOC
) == 0
6075 || (isec
->flags
& SEC_CODE
) == 0
6076 || (isec
->flags
& SEC_LINKER_CREATED
) != 0
6080 /* We cannot represent the required PIC relocs in the output, so don't
6081 do anything. The linker doesn't support mixing -shared and -r
6083 if (bfd_link_relocatable (link_info
) && bfd_link_pic (link_info
))
6086 htab
= ppc_elf_hash_table (link_info
);
6090 isec
->size
= (isec
->size
+ 3) & -4;
6091 if (isec
->rawsize
== 0)
6092 isec
->rawsize
= isec
->size
;
6093 trampbase
= isec
->size
;
6095 BFD_ASSERT (isec
->sec_info_type
== SEC_INFO_TYPE_NONE
6096 || isec
->sec_info_type
== SEC_INFO_TYPE_TARGET
);
6097 isec
->sec_info_type
= SEC_INFO_TYPE_TARGET
;
6099 if (htab
->params
->ppc476_workaround
6100 || htab
->params
->pic_fixup
> 0)
6102 if (elf_section_data (isec
)->sec_info
== NULL
)
6104 elf_section_data (isec
)->sec_info
6105 = bfd_zalloc (abfd
, sizeof (struct ppc_elf_relax_info
));
6106 if (elf_section_data (isec
)->sec_info
== NULL
)
6109 relax_info
= elf_section_data (isec
)->sec_info
;
6110 trampbase
-= relax_info
->workaround_size
;
6113 maybe_pasted
= (strcmp (isec
->output_section
->name
, ".init") == 0
6114 || strcmp (isec
->output_section
->name
, ".fini") == 0);
6115 /* Space for a branch around any trampolines. */
6116 trampoff
= trampbase
;
6117 if (maybe_pasted
&& trampbase
== isec
->rawsize
)
6120 symtab_hdr
= &elf_symtab_hdr (abfd
);
6122 if (htab
->params
->branch_trampolines
6123 || htab
->params
->pic_fixup
> 0)
6125 /* Get a copy of the native relocations. */
6126 if (isec
->reloc_count
!= 0)
6128 internal_relocs
= _bfd_elf_link_read_relocs (abfd
, isec
, NULL
, NULL
,
6129 link_info
->keep_memory
);
6130 if (internal_relocs
== NULL
)
6134 got2
= bfd_get_section_by_name (abfd
, ".got2");
6136 irelend
= internal_relocs
+ isec
->reloc_count
;
6137 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
6139 unsigned long r_type
= ELF32_R_TYPE (irel
->r_info
);
6142 struct one_branch_fixup
*f
;
6143 size_t insn_offset
= 0;
6144 bfd_vma max_branch_offset
= 0, val
;
6147 struct elf_link_hash_entry
*h
;
6148 Elf_Internal_Sym
*isym
;
6149 struct plt_entry
**plist
;
6150 unsigned char sym_type
;
6155 case R_PPC_LOCAL24PC
:
6156 case R_PPC_PLTREL24
:
6158 max_branch_offset
= 1 << 25;
6162 case R_PPC_REL14_BRTAKEN
:
6163 case R_PPC_REL14_BRNTAKEN
:
6164 max_branch_offset
= 1 << 15;
6167 case R_PPC_ADDR16_HA
:
6168 if (htab
->params
->pic_fixup
> 0)
6176 /* Get the value of the symbol referred to by the reloc. */
6177 if (!get_sym_h (&h
, &isym
, &tsec
, NULL
, &isymbuf
,
6178 ELF32_R_SYM (irel
->r_info
), abfd
))
6185 else if (isym
->st_shndx
== SHN_ABS
)
6186 tsec
= bfd_abs_section_ptr
;
6190 toff
= isym
->st_value
;
6191 sym_type
= ELF_ST_TYPE (isym
->st_info
);
6196 toff
= h
->root
.u
.def
.value
;
6197 else if (h
->root
.type
== bfd_link_hash_undefined
6198 || h
->root
.type
== bfd_link_hash_undefweak
)
6202 indx
= ELF32_R_SYM (irel
->r_info
) - symtab_hdr
->sh_info
;
6203 tsec
= bfd_und_section_ptr
;
6204 toff
= bfd_link_relocatable (link_info
) ? indx
: 0;
6209 /* If this branch is to __tls_get_addr then we may later
6210 optimise away the call. We won't be needing a long-
6211 branch stub in that case. */
6212 if (bfd_link_executable (link_info
)
6213 && h
== htab
->tls_get_addr
6214 && irel
!= internal_relocs
)
6216 unsigned long t_symndx
= ELF32_R_SYM (irel
[-1].r_info
);
6217 unsigned long t_rtype
= ELF32_R_TYPE (irel
[-1].r_info
);
6218 unsigned int tls_mask
= 0;
6220 /* The previous reloc should be one of R_PPC_TLSGD or
6221 R_PPC_TLSLD, or for older object files, a reloc
6222 on the __tls_get_addr arg setup insn. Get tls
6223 mask bits from the symbol on that reloc. */
6224 if (t_symndx
< symtab_hdr
->sh_info
)
6226 bfd_vma
*local_got_offsets
= elf_local_got_offsets (abfd
);
6228 if (local_got_offsets
!= NULL
)
6230 struct plt_entry
**local_plt
= (struct plt_entry
**)
6231 (local_got_offsets
+ symtab_hdr
->sh_info
);
6232 char *lgot_masks
= (char *)
6233 (local_plt
+ symtab_hdr
->sh_info
);
6234 tls_mask
= lgot_masks
[t_symndx
];
6239 struct elf_link_hash_entry
*th
6240 = elf_sym_hashes (abfd
)[t_symndx
- symtab_hdr
->sh_info
];
6242 while (th
->root
.type
== bfd_link_hash_indirect
6243 || th
->root
.type
== bfd_link_hash_warning
)
6244 th
= (struct elf_link_hash_entry
*) th
->root
.u
.i
.link
;
6247 = ((struct ppc_elf_link_hash_entry
*) th
)->tls_mask
;
6250 /* The mask bits tell us if the call will be
6252 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_GD
) == 0
6253 && (t_rtype
== R_PPC_TLSGD
6254 || t_rtype
== R_PPC_GOT_TLSGD16
6255 || t_rtype
== R_PPC_GOT_TLSGD16_LO
))
6257 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_LD
) == 0
6258 && (t_rtype
== R_PPC_TLSLD
6259 || t_rtype
== R_PPC_GOT_TLSLD16
6260 || t_rtype
== R_PPC_GOT_TLSLD16_LO
))
6267 if (r_type
== R_PPC_ADDR16_HA
)
6272 && ppc_elf_hash_entry (h
)->has_addr16_ha
6273 && ppc_elf_hash_entry (h
)->has_addr16_lo
)
6274 picfixup_size
+= 12;
6278 /* The condition here under which we call find_plt_ent must
6279 match that in relocate_section. If we call find_plt_ent here
6280 but not in relocate_section, or vice versa, then the branch
6281 destination used here may be incorrect. */
6285 /* We know is_branch_reloc (r_type) is true. */
6286 if (h
->type
== STT_GNU_IFUNC
6287 || r_type
== R_PPC_PLTREL24
)
6288 plist
= &h
->plt
.plist
;
6290 else if (sym_type
== STT_GNU_IFUNC
6291 && elf_local_got_offsets (abfd
) != NULL
)
6293 bfd_vma
*local_got_offsets
= elf_local_got_offsets (abfd
);
6294 struct plt_entry
**local_plt
= (struct plt_entry
**)
6295 (local_got_offsets
+ symtab_hdr
->sh_info
);
6296 plist
= local_plt
+ ELF32_R_SYM (irel
->r_info
);
6301 struct plt_entry
*ent
;
6303 if (r_type
== R_PPC_PLTREL24
&& bfd_link_pic (link_info
))
6304 addend
= irel
->r_addend
;
6305 ent
= find_plt_ent (plist
, got2
, addend
);
6308 if (htab
->plt_type
== PLT_NEW
6310 || !htab
->elf
.dynamic_sections_created
6311 || h
->dynindx
== -1)
6314 toff
= ent
->glink_offset
;
6318 tsec
= htab
->elf
.splt
;
6319 toff
= ent
->plt
.offset
;
6324 /* If the branch and target are in the same section, you have
6325 no hope of adding stubs. We'll error out later should the
6330 /* toff is used for the symbol index when the symbol is
6331 undefined and we're doing a relocatable link, so we can't
6332 support addends. It would be possible to do so by
6333 putting the addend in one_branch_fixup but addends on
6334 branches are rare so it hardly seems worth supporting. */
6335 if (bfd_link_relocatable (link_info
)
6336 && tsec
== bfd_und_section_ptr
6337 && r_type
!= R_PPC_PLTREL24
6338 && irel
->r_addend
!= 0)
6341 /* There probably isn't any reason to handle symbols in
6342 SEC_MERGE sections; SEC_MERGE doesn't seem a likely
6343 attribute for a code section, and we are only looking at
6344 branches. However, implement it correctly here as a
6345 reference for other target relax_section functions. */
6346 if (0 && tsec
->sec_info_type
== SEC_INFO_TYPE_MERGE
)
6348 /* At this stage in linking, no SEC_MERGE symbol has been
6349 adjusted, so all references to such symbols need to be
6350 passed through _bfd_merged_section_offset. (Later, in
6351 relocate_section, all SEC_MERGE symbols *except* for
6352 section symbols have been adjusted.)
6354 gas may reduce relocations against symbols in SEC_MERGE
6355 sections to a relocation against the section symbol when
6356 the original addend was zero. When the reloc is against
6357 a section symbol we should include the addend in the
6358 offset passed to _bfd_merged_section_offset, since the
6359 location of interest is the original symbol. On the
6360 other hand, an access to "sym+addend" where "sym" is not
6361 a section symbol should not include the addend; Such an
6362 access is presumed to be an offset from "sym"; The
6363 location of interest is just "sym". */
6364 if (sym_type
== STT_SECTION
6365 && r_type
!= R_PPC_PLTREL24
)
6366 toff
+= irel
->r_addend
;
6369 = _bfd_merged_section_offset (abfd
, &tsec
,
6370 elf_section_data (tsec
)->sec_info
,
6373 if (sym_type
!= STT_SECTION
6374 && r_type
!= R_PPC_PLTREL24
)
6375 toff
+= irel
->r_addend
;
6377 /* PLTREL24 addends are special. */
6378 else if (r_type
!= R_PPC_PLTREL24
)
6379 toff
+= irel
->r_addend
;
6381 /* Attempted -shared link of non-pic code loses. */
6382 if ((!bfd_link_relocatable (link_info
)
6383 && tsec
== bfd_und_section_ptr
)
6384 || tsec
->output_section
== NULL
6385 || (tsec
->owner
!= NULL
6386 && (tsec
->owner
->flags
& BFD_PLUGIN
) != 0))
6389 roff
= irel
->r_offset
;
6391 /* Avoid creating a lot of unnecessary fixups when
6392 relocatable if the output section size is such that a
6393 fixup can be created at final link.
6394 The max_branch_offset adjustment allows for some number
6395 of other fixups being needed at final link. */
6396 if (bfd_link_relocatable (link_info
)
6397 && (isec
->output_section
->rawsize
- (isec
->output_offset
+ roff
)
6398 < max_branch_offset
- (max_branch_offset
>> 4)))
6401 /* If the branch is in range, no need to do anything. */
6402 if (tsec
!= bfd_und_section_ptr
6403 && (!bfd_link_relocatable (link_info
)
6404 /* A relocatable link may have sections moved during
6405 final link, so do not presume they remain in range. */
6406 || tsec
->output_section
== isec
->output_section
))
6408 bfd_vma symaddr
, reladdr
;
6410 symaddr
= tsec
->output_section
->vma
+ tsec
->output_offset
+ toff
;
6411 reladdr
= isec
->output_section
->vma
+ isec
->output_offset
+ roff
;
6412 if (symaddr
- reladdr
+ max_branch_offset
6413 < 2 * max_branch_offset
)
6417 /* Look for an existing fixup to this address. */
6418 for (f
= branch_fixups
; f
; f
= f
->next
)
6419 if (f
->tsec
== tsec
&& f
->toff
== toff
)
6425 unsigned long stub_rtype
;
6427 val
= trampoff
- roff
;
6428 if (val
>= max_branch_offset
)
6429 /* Oh dear, we can't reach a trampoline. Don't try to add
6430 one. We'll report an error later. */
6433 if (bfd_link_pic (link_info
))
6435 size
= 4 * ARRAY_SIZE (shared_stub_entry
);
6440 size
= 4 * ARRAY_SIZE (stub_entry
);
6443 stub_rtype
= R_PPC_RELAX
;
6444 if (tsec
== htab
->elf
.splt
6445 || tsec
== htab
->glink
)
6447 stub_rtype
= R_PPC_RELAX_PLT
;
6448 if (r_type
== R_PPC_PLTREL24
)
6449 stub_rtype
= R_PPC_RELAX_PLTREL24
;
6452 /* Hijack the old relocation. Since we need two
6453 relocations for this use a "composite" reloc. */
6454 irel
->r_info
= ELF32_R_INFO (ELF32_R_SYM (irel
->r_info
),
6456 irel
->r_offset
= trampoff
+ insn_offset
;
6457 if (r_type
== R_PPC_PLTREL24
6458 && stub_rtype
!= R_PPC_RELAX_PLTREL24
)
6461 /* Record the fixup so we don't do it again this section. */
6462 f
= bfd_malloc (sizeof (*f
));
6463 f
->next
= branch_fixups
;
6466 f
->trampoff
= trampoff
;
6474 val
= f
->trampoff
- roff
;
6475 if (val
>= max_branch_offset
)
6478 /* Nop out the reloc, since we're finalizing things here. */
6479 irel
->r_info
= ELF32_R_INFO (0, R_PPC_NONE
);
6482 /* Get the section contents. */
6483 if (contents
== NULL
)
6485 /* Get cached copy if it exists. */
6486 if (elf_section_data (isec
)->this_hdr
.contents
!= NULL
)
6487 contents
= elf_section_data (isec
)->this_hdr
.contents
;
6488 /* Go get them off disk. */
6489 else if (!bfd_malloc_and_get_section (abfd
, isec
, &contents
))
6493 /* Fix up the existing branch to hit the trampoline. */
6494 hit_addr
= contents
+ roff
;
6498 case R_PPC_LOCAL24PC
:
6499 case R_PPC_PLTREL24
:
6500 t0
= bfd_get_32 (abfd
, hit_addr
);
6502 t0
|= val
& 0x3fffffc;
6503 bfd_put_32 (abfd
, t0
, hit_addr
);
6507 case R_PPC_REL14_BRTAKEN
:
6508 case R_PPC_REL14_BRNTAKEN
:
6509 t0
= bfd_get_32 (abfd
, hit_addr
);
6512 bfd_put_32 (abfd
, t0
, hit_addr
);
6517 while (branch_fixups
!= NULL
)
6519 struct one_branch_fixup
*f
= branch_fixups
;
6520 branch_fixups
= branch_fixups
->next
;
6525 workaround_change
= FALSE
;
6527 if (htab
->params
->ppc476_workaround
6528 && (!bfd_link_relocatable (link_info
)
6529 || isec
->output_section
->alignment_power
>= htab
->params
->pagesize_p2
))
6531 bfd_vma addr
, end_addr
;
6532 unsigned int crossings
;
6533 bfd_vma pagesize
= (bfd_vma
) 1 << htab
->params
->pagesize_p2
;
6535 addr
= isec
->output_section
->vma
+ isec
->output_offset
;
6536 end_addr
= addr
+ trampoff
;
6538 crossings
= ((end_addr
& -pagesize
) - addr
) >> htab
->params
->pagesize_p2
;
6541 /* Keep space aligned, to ensure the patch code itself does
6542 not cross a page. Don't decrease size calculated on a
6543 previous pass as otherwise we might never settle on a layout. */
6544 newsize
= 15 - ((end_addr
- 1) & 15);
6545 newsize
+= crossings
* 16;
6546 if (relax_info
->workaround_size
< newsize
)
6548 relax_info
->workaround_size
= newsize
;
6549 workaround_change
= TRUE
;
6551 /* Ensure relocate_section is called. */
6552 isec
->flags
|= SEC_RELOC
;
6554 newsize
= trampoff
+ relax_info
->workaround_size
;
6557 if (htab
->params
->pic_fixup
> 0)
6559 picfixup_size
-= relax_info
->picfixup_size
;
6560 if (picfixup_size
!= 0)
6561 relax_info
->picfixup_size
+= picfixup_size
;
6562 newsize
+= relax_info
->picfixup_size
;
6565 if (changes
!= 0 || picfixup_size
!= 0 || workaround_change
)
6566 isec
->size
= newsize
;
6569 && symtab_hdr
->contents
!= (unsigned char *) isymbuf
)
6571 if (! link_info
->keep_memory
)
6575 /* Cache the symbols for elf_link_input_bfd. */
6576 symtab_hdr
->contents
= (unsigned char *) isymbuf
;
6580 if (contents
!= NULL
6581 && elf_section_data (isec
)->this_hdr
.contents
!= contents
)
6583 if (!changes
&& !link_info
->keep_memory
)
6587 /* Cache the section contents for elf_link_input_bfd. */
6588 elf_section_data (isec
)->this_hdr
.contents
= contents
;
6592 changes
+= picfixup_size
;
6595 /* Append sufficient NOP relocs so we can write out relocation
6596 information for the trampolines. */
6597 Elf_Internal_Shdr
*rel_hdr
;
6598 Elf_Internal_Rela
*new_relocs
= bfd_malloc ((changes
+ isec
->reloc_count
)
6599 * sizeof (*new_relocs
));
6604 memcpy (new_relocs
, internal_relocs
,
6605 isec
->reloc_count
* sizeof (*new_relocs
));
6606 for (ix
= changes
; ix
--;)
6608 irel
= new_relocs
+ ix
+ isec
->reloc_count
;
6610 irel
->r_info
= ELF32_R_INFO (0, R_PPC_NONE
);
6612 if (internal_relocs
!= elf_section_data (isec
)->relocs
)
6613 free (internal_relocs
);
6614 elf_section_data (isec
)->relocs
= new_relocs
;
6615 isec
->reloc_count
+= changes
;
6616 rel_hdr
= _bfd_elf_single_rel_hdr (isec
);
6617 rel_hdr
->sh_size
+= changes
* rel_hdr
->sh_entsize
;
6619 else if (elf_section_data (isec
)->relocs
!= internal_relocs
)
6620 free (internal_relocs
);
6622 *again
= changes
!= 0 || workaround_change
;
6626 while (branch_fixups
!= NULL
)
6628 struct one_branch_fixup
*f
= branch_fixups
;
6629 branch_fixups
= branch_fixups
->next
;
6632 if ((unsigned char *) isymbuf
!= symtab_hdr
->contents
)
6634 if (elf_section_data (isec
)->this_hdr
.contents
!= contents
)
6636 if (elf_section_data (isec
)->relocs
!= internal_relocs
)
6637 free (internal_relocs
);
6641 /* What to do when ld finds relocations against symbols defined in
6642 discarded sections. */
6645 ppc_elf_action_discarded (asection
*sec
)
6647 if (strcmp (".fixup", sec
->name
) == 0)
6650 if (strcmp (".got2", sec
->name
) == 0)
6653 return _bfd_elf_default_action_discarded (sec
);
6656 /* Fill in the address for a pointer generated in a linker section. */
6659 elf_finish_pointer_linker_section (bfd
*input_bfd
,
6660 elf_linker_section_t
*lsect
,
6661 struct elf_link_hash_entry
*h
,
6663 const Elf_Internal_Rela
*rel
)
6665 elf_linker_section_pointers_t
*linker_section_ptr
;
6667 BFD_ASSERT (lsect
!= NULL
);
6671 /* Handle global symbol. */
6672 struct ppc_elf_link_hash_entry
*eh
;
6674 eh
= (struct ppc_elf_link_hash_entry
*) h
;
6675 BFD_ASSERT (eh
->elf
.def_regular
);
6676 linker_section_ptr
= eh
->linker_section_pointer
;
6680 /* Handle local symbol. */
6681 unsigned long r_symndx
= ELF32_R_SYM (rel
->r_info
);
6683 BFD_ASSERT (is_ppc_elf (input_bfd
));
6684 BFD_ASSERT (elf_local_ptr_offsets (input_bfd
) != NULL
);
6685 linker_section_ptr
= elf_local_ptr_offsets (input_bfd
)[r_symndx
];
6688 linker_section_ptr
= elf_find_pointer_linker_section (linker_section_ptr
,
6691 BFD_ASSERT (linker_section_ptr
!= NULL
);
6693 /* Offset will always be a multiple of four, so use the bottom bit
6694 as a "written" flag. */
6695 if ((linker_section_ptr
->offset
& 1) == 0)
6697 bfd_put_32 (lsect
->section
->owner
,
6698 relocation
+ linker_section_ptr
->addend
,
6699 lsect
->section
->contents
+ linker_section_ptr
->offset
);
6700 linker_section_ptr
->offset
+= 1;
6703 relocation
= (lsect
->section
->output_section
->vma
6704 + lsect
->section
->output_offset
6705 + linker_section_ptr
->offset
- 1
6706 - SYM_VAL (lsect
->sym
));
6710 "Finish pointer in linker section %s, offset = %ld (0x%lx)\n",
6711 lsect
->name
, (long) relocation
, (long) relocation
);
6717 #define PPC_LO(v) ((v) & 0xffff)
6718 #define PPC_HI(v) (((v) >> 16) & 0xffff)
6719 #define PPC_HA(v) PPC_HI ((v) + 0x8000)
6722 write_glink_stub (struct elf_link_hash_entry
*h
, struct plt_entry
*ent
,
6723 asection
*plt_sec
, unsigned char *p
,
6724 struct bfd_link_info
*info
)
6726 struct ppc_elf_link_hash_table
*htab
= ppc_elf_hash_table (info
);
6727 bfd
*output_bfd
= info
->output_bfd
;
6729 unsigned char *end
= p
+ GLINK_ENTRY_SIZE (htab
, h
);
6732 && h
== htab
->tls_get_addr
6733 && !htab
->params
->no_tls_get_addr_opt
)
6735 bfd_put_32 (output_bfd
, LWZ_11_3
, p
);
6737 bfd_put_32 (output_bfd
, LWZ_12_3
+ 4, p
);
6739 bfd_put_32 (output_bfd
, MR_0_3
, p
);
6741 bfd_put_32 (output_bfd
, CMPWI_11_0
, p
);
6743 bfd_put_32 (output_bfd
, ADD_3_12_2
, p
);
6745 bfd_put_32 (output_bfd
, BEQLR
, p
);
6747 bfd_put_32 (output_bfd
, MR_3_0
, p
);
6749 bfd_put_32 (output_bfd
, NOP
, p
);
6753 plt
= ((ent
->plt
.offset
& ~1)
6754 + plt_sec
->output_section
->vma
6755 + plt_sec
->output_offset
);
6757 if (bfd_link_pic (info
))
6761 if (ent
->addend
>= 32768)
6763 + ent
->sec
->output_section
->vma
6764 + ent
->sec
->output_offset
);
6765 else if (htab
->elf
.hgot
!= NULL
)
6766 got
= SYM_VAL (htab
->elf
.hgot
);
6770 if (plt
+ 0x8000 < 0x10000)
6771 bfd_put_32 (output_bfd
, LWZ_11_30
+ PPC_LO (plt
), p
);
6774 bfd_put_32 (output_bfd
, ADDIS_11_30
+ PPC_HA (plt
), p
);
6776 bfd_put_32 (output_bfd
, LWZ_11_11
+ PPC_LO (plt
), p
);
6781 bfd_put_32 (output_bfd
, LIS_11
+ PPC_HA (plt
), p
);
6783 bfd_put_32 (output_bfd
, LWZ_11_11
+ PPC_LO (plt
), p
);
6786 bfd_put_32 (output_bfd
, MTCTR_11
, p
);
6788 bfd_put_32 (output_bfd
, BCTR
, p
);
6792 bfd_put_32 (output_bfd
, htab
->params
->ppc476_workaround
? BA
: NOP
, p
);
6797 /* Return true if symbol is defined statically. */
6800 is_static_defined (struct elf_link_hash_entry
*h
)
6802 return ((h
->root
.type
== bfd_link_hash_defined
6803 || h
->root
.type
== bfd_link_hash_defweak
)
6804 && h
->root
.u
.def
.section
!= NULL
6805 && h
->root
.u
.def
.section
->output_section
!= NULL
);
6808 /* If INSN is an opcode that may be used with an @tls operand, return
6809 the transformed insn for TLS optimisation, otherwise return 0. If
6810 REG is non-zero only match an insn with RB or RA equal to REG. */
6813 _bfd_elf_ppc_at_tls_transform (unsigned int insn
, unsigned int reg
)
6817 if ((insn
& (0x3fu
<< 26)) != 31 << 26)
6820 if (reg
== 0 || ((insn
>> 11) & 0x1f) == reg
)
6821 rtra
= insn
& ((1 << 26) - (1 << 16));
6822 else if (((insn
>> 16) & 0x1f) == reg
)
6823 rtra
= (insn
& (0x1f << 21)) | ((insn
& (0x1f << 11)) << 5);
6827 if ((insn
& (0x3ff << 1)) == 266 << 1)
6830 else if ((insn
& (0x1f << 1)) == 23 << 1
6831 && ((insn
& (0x1f << 6)) < 14 << 6
6832 || ((insn
& (0x1f << 6)) >= 16 << 6
6833 && (insn
& (0x1f << 6)) < 24 << 6)))
6834 /* load and store indexed -> dform. */
6835 insn
= (32u | ((insn
>> 6) & 0x1f)) << 26;
6836 else if ((insn
& (((0x1a << 5) | 0x1f) << 1)) == 21 << 1)
6837 /* ldx, ldux, stdx, stdux -> ld, ldu, std, stdu. */
6838 insn
= ((58u | ((insn
>> 6) & 4)) << 26) | ((insn
>> 6) & 1);
6839 else if ((insn
& (((0x1f << 5) | 0x1f) << 1)) == 341 << 1)
6841 insn
= (58u << 26) | 2;
6848 /* If INSN is an opcode that may be used with an @tprel operand, return
6849 the transformed insn for an undefined weak symbol, ie. with the
6850 thread pointer REG operand removed. Otherwise return 0. */
6853 _bfd_elf_ppc_at_tprel_transform (unsigned int insn
, unsigned int reg
)
6855 if ((insn
& (0x1f << 16)) == reg
<< 16
6856 && ((insn
& (0x3fu
<< 26)) == 14u << 26 /* addi */
6857 || (insn
& (0x3fu
<< 26)) == 15u << 26 /* addis */
6858 || (insn
& (0x3fu
<< 26)) == 32u << 26 /* lwz */
6859 || (insn
& (0x3fu
<< 26)) == 34u << 26 /* lbz */
6860 || (insn
& (0x3fu
<< 26)) == 36u << 26 /* stw */
6861 || (insn
& (0x3fu
<< 26)) == 38u << 26 /* stb */
6862 || (insn
& (0x3fu
<< 26)) == 40u << 26 /* lhz */
6863 || (insn
& (0x3fu
<< 26)) == 42u << 26 /* lha */
6864 || (insn
& (0x3fu
<< 26)) == 44u << 26 /* sth */
6865 || (insn
& (0x3fu
<< 26)) == 46u << 26 /* lmw */
6866 || (insn
& (0x3fu
<< 26)) == 47u << 26 /* stmw */
6867 || (insn
& (0x3fu
<< 26)) == 48u << 26 /* lfs */
6868 || (insn
& (0x3fu
<< 26)) == 50u << 26 /* lfd */
6869 || (insn
& (0x3fu
<< 26)) == 52u << 26 /* stfs */
6870 || (insn
& (0x3fu
<< 26)) == 54u << 26 /* stfd */
6871 || ((insn
& (0x3fu
<< 26)) == 58u << 26 /* lwa,ld,lmd */
6873 || ((insn
& (0x3fu
<< 26)) == 62u << 26 /* std, stmd */
6874 && ((insn
& 3) == 0 || (insn
& 3) == 3))))
6876 insn
&= ~(0x1f << 16);
6878 else if ((insn
& (0x1f << 21)) == reg
<< 21
6879 && ((insn
& (0x3eu
<< 26)) == 24u << 26 /* ori, oris */
6880 || (insn
& (0x3eu
<< 26)) == 26u << 26 /* xori,xoris */
6881 || (insn
& (0x3eu
<< 26)) == 28u << 26 /* andi,andis */))
6883 insn
&= ~(0x1f << 21);
6884 insn
|= (insn
& (0x1f << 16)) << 5;
6885 if ((insn
& (0x3eu
<< 26)) == 26u << 26 /* xori,xoris */)
6886 insn
-= 2 >> 26; /* convert to ori,oris */
6894 is_insn_ds_form (unsigned int insn
)
6896 return ((insn
& (0x3fu
<< 26)) == 58u << 26 /* ld,ldu,lwa */
6897 || (insn
& (0x3fu
<< 26)) == 62u << 26 /* std,stdu,stq */
6898 || (insn
& (0x3fu
<< 26)) == 57u << 26 /* lfdp */
6899 || (insn
& (0x3fu
<< 26)) == 61u << 26 /* stfdp */);
6903 is_insn_dq_form (unsigned int insn
)
6905 return ((insn
& (0x3fu
<< 26)) == 56u << 26 /* lq */
6906 || ((insn
& (0x3fu
<< 26)) == (61u << 26) /* lxv, stxv */
6907 && (insn
& 3) == 1));
6910 /* The RELOCATE_SECTION function is called by the ELF backend linker
6911 to handle the relocations for a section.
6913 The relocs are always passed as Rela structures; if the section
6914 actually uses Rel structures, the r_addend field will always be
6917 This function is responsible for adjust the section contents as
6918 necessary, and (if using Rela relocs and generating a
6919 relocatable output file) adjusting the reloc addend as
6922 This function does not have to worry about setting the reloc
6923 address or the reloc symbol index.
6925 LOCAL_SYMS is a pointer to the swapped in local symbols.
6927 LOCAL_SECTIONS is an array giving the section in the input file
6928 corresponding to the st_shndx field of each local symbol.
6930 The global hash table entry for the global symbols can be found
6931 via elf_sym_hashes (input_bfd).
6933 When generating relocatable output, this function must handle
6934 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
6935 going to be the section symbol corresponding to the output
6936 section, which means that the addend must be adjusted
6940 ppc_elf_relocate_section (bfd
*output_bfd
,
6941 struct bfd_link_info
*info
,
6943 asection
*input_section
,
6945 Elf_Internal_Rela
*relocs
,
6946 Elf_Internal_Sym
*local_syms
,
6947 asection
**local_sections
)
6949 Elf_Internal_Shdr
*symtab_hdr
;
6950 struct elf_link_hash_entry
**sym_hashes
;
6951 struct ppc_elf_link_hash_table
*htab
;
6952 Elf_Internal_Rela
*rel
;
6953 Elf_Internal_Rela
*wrel
;
6954 Elf_Internal_Rela
*relend
;
6955 Elf_Internal_Rela outrel
;
6957 bfd_vma
*local_got_offsets
;
6958 bfd_boolean ret
= TRUE
;
6959 bfd_vma d_offset
= (bfd_big_endian (input_bfd
) ? 2 : 0);
6960 bfd_boolean is_vxworks_tls
;
6961 unsigned int picfixup_size
= 0;
6962 struct ppc_elf_relax_info
*relax_info
= NULL
;
6965 _bfd_error_handler ("ppc_elf_relocate_section called for %pB section %pA, "
6966 "%ld relocations%s",
6967 input_bfd
, input_section
,
6968 (long) input_section
->reloc_count
,
6969 (bfd_link_relocatable (info
)) ? " (relocatable)" : "");
6972 if (!is_ppc_elf (input_bfd
))
6974 bfd_set_error (bfd_error_wrong_format
);
6978 got2
= bfd_get_section_by_name (input_bfd
, ".got2");
6980 /* Initialize howto table if not already done. */
6981 if (!ppc_elf_howto_table
[R_PPC_ADDR32
])
6982 ppc_elf_howto_init ();
6984 htab
= ppc_elf_hash_table (info
);
6985 local_got_offsets
= elf_local_got_offsets (input_bfd
);
6986 symtab_hdr
= &elf_symtab_hdr (input_bfd
);
6987 sym_hashes
= elf_sym_hashes (input_bfd
);
6988 /* We have to handle relocations in vxworks .tls_vars sections
6989 specially, because the dynamic loader is 'weird'. */
6990 is_vxworks_tls
= (htab
->elf
.target_os
== is_vxworks
&& bfd_link_pic (info
)
6991 && !strcmp (input_section
->output_section
->name
,
6993 if (input_section
->sec_info_type
== SEC_INFO_TYPE_TARGET
)
6994 relax_info
= elf_section_data (input_section
)->sec_info
;
6995 rel
= wrel
= relocs
;
6996 relend
= relocs
+ input_section
->reloc_count
;
6997 for (; rel
< relend
; wrel
++, rel
++)
6999 enum elf_ppc_reloc_type r_type
;
7001 bfd_reloc_status_type r
;
7002 Elf_Internal_Sym
*sym
;
7004 struct elf_link_hash_entry
*h
;
7005 const char *sym_name
;
7006 reloc_howto_type
*howto
;
7007 unsigned long r_symndx
;
7009 bfd_vma branch_bit
, from
;
7010 bfd_boolean unresolved_reloc
, save_unresolved_reloc
;
7012 unsigned int tls_type
, tls_mask
, tls_gd
;
7013 struct plt_entry
**ifunc
, **plt_list
;
7014 struct reloc_howto_struct alt_howto
;
7017 r_type
= ELF32_R_TYPE (rel
->r_info
);
7021 unresolved_reloc
= FALSE
;
7023 r_symndx
= ELF32_R_SYM (rel
->r_info
);
7025 if (r_symndx
< symtab_hdr
->sh_info
)
7027 sym
= local_syms
+ r_symndx
;
7028 sec
= local_sections
[r_symndx
];
7029 sym_name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
, sym
, sec
);
7031 relocation
= _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
7035 bfd_boolean ignored
;
7037 RELOC_FOR_GLOBAL_SYMBOL (info
, input_bfd
, input_section
, rel
,
7038 r_symndx
, symtab_hdr
, sym_hashes
,
7040 unresolved_reloc
, warned
, ignored
);
7042 sym_name
= h
->root
.root
.string
;
7045 if (sec
!= NULL
&& discarded_section (sec
))
7047 /* For relocs against symbols from removed linkonce sections,
7048 or sections discarded by a linker script, we just want the
7049 section contents zeroed. Avoid any special processing. */
7051 if (r_type
< R_PPC_max
)
7052 howto
= ppc_elf_howto_table
[r_type
];
7054 _bfd_clear_contents (howto
, input_bfd
, input_section
,
7055 contents
, rel
->r_offset
);
7056 wrel
->r_offset
= rel
->r_offset
;
7060 /* For ld -r, remove relocations in debug sections against
7061 symbols defined in discarded sections. Not done for
7062 non-debug to preserve relocs in .eh_frame which the
7063 eh_frame editing code expects to be present. */
7064 if (bfd_link_relocatable (info
)
7065 && (input_section
->flags
& SEC_DEBUGGING
))
7071 if (bfd_link_relocatable (info
))
7074 && r_type
== R_PPC_PLTREL24
7075 && rel
->r_addend
!= 0)
7077 /* R_PPC_PLTREL24 is rather special. If non-zero, the
7078 addend specifies the GOT pointer offset within .got2. */
7079 rel
->r_addend
+= got2
->output_offset
;
7081 if (r_type
!= R_PPC_RELAX_PLT
7082 && r_type
!= R_PPC_RELAX_PLTREL24
7083 && r_type
!= R_PPC_RELAX
)
7087 /* TLS optimizations. Replace instruction sequences and relocs
7088 based on information we collected in tls_optimize. We edit
7089 RELOCS so that --emit-relocs will output something sensible
7090 for the final instruction stream. */
7094 tls_mask
= ((struct ppc_elf_link_hash_entry
*) h
)->tls_mask
;
7095 else if (local_got_offsets
!= NULL
)
7097 struct plt_entry
**local_plt
;
7100 = (struct plt_entry
**) (local_got_offsets
+ symtab_hdr
->sh_info
);
7101 lgot_masks
= (char *) (local_plt
+ symtab_hdr
->sh_info
);
7102 tls_mask
= lgot_masks
[r_symndx
];
7105 /* Ensure reloc mapping code below stays sane. */
7106 if ((R_PPC_GOT_TLSLD16
& 3) != (R_PPC_GOT_TLSGD16
& 3)
7107 || (R_PPC_GOT_TLSLD16_LO
& 3) != (R_PPC_GOT_TLSGD16_LO
& 3)
7108 || (R_PPC_GOT_TLSLD16_HI
& 3) != (R_PPC_GOT_TLSGD16_HI
& 3)
7109 || (R_PPC_GOT_TLSLD16_HA
& 3) != (R_PPC_GOT_TLSGD16_HA
& 3)
7110 || (R_PPC_GOT_TLSLD16
& 3) != (R_PPC_GOT_TPREL16
& 3)
7111 || (R_PPC_GOT_TLSLD16_LO
& 3) != (R_PPC_GOT_TPREL16_LO
& 3)
7112 || (R_PPC_GOT_TLSLD16_HI
& 3) != (R_PPC_GOT_TPREL16_HI
& 3)
7113 || (R_PPC_GOT_TLSLD16_HA
& 3) != (R_PPC_GOT_TPREL16_HA
& 3))
7120 case R_PPC_GOT_TPREL16
:
7121 case R_PPC_GOT_TPREL16_LO
:
7122 if ((tls_mask
& TLS_TLS
) != 0
7123 && (tls_mask
& TLS_TPREL
) == 0)
7127 insn
= bfd_get_32 (input_bfd
,
7128 contents
+ rel
->r_offset
- d_offset
);
7130 insn
|= 0x3c020000; /* addis 0,2,0 */
7131 bfd_put_32 (input_bfd
, insn
,
7132 contents
+ rel
->r_offset
- d_offset
);
7133 r_type
= R_PPC_TPREL16_HA
;
7134 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
7139 if ((tls_mask
& TLS_TLS
) != 0
7140 && (tls_mask
& TLS_TPREL
) == 0)
7144 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
7145 insn
= _bfd_elf_ppc_at_tls_transform (insn
, 2);
7148 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
7149 r_type
= R_PPC_TPREL16_LO
;
7150 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
7152 /* Was PPC_TLS which sits on insn boundary, now
7153 PPC_TPREL16_LO which is at low-order half-word. */
7154 rel
->r_offset
+= d_offset
;
7158 case R_PPC_GOT_TLSGD16_HI
:
7159 case R_PPC_GOT_TLSGD16_HA
:
7161 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_GD
) == 0)
7165 case R_PPC_GOT_TLSLD16_HI
:
7166 case R_PPC_GOT_TLSLD16_HA
:
7167 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_LD
) == 0)
7170 if ((tls_mask
& tls_gd
) != 0)
7171 r_type
= (((r_type
- (R_PPC_GOT_TLSGD16
& 3)) & 3)
7172 + R_PPC_GOT_TPREL16
);
7175 rel
->r_offset
-= d_offset
;
7176 bfd_put_32 (input_bfd
, NOP
, contents
+ rel
->r_offset
);
7177 r_type
= R_PPC_NONE
;
7179 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
7183 case R_PPC_GOT_TLSGD16
:
7184 case R_PPC_GOT_TLSGD16_LO
:
7186 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_GD
) == 0)
7190 case R_PPC_GOT_TLSLD16
:
7191 case R_PPC_GOT_TLSLD16_LO
:
7192 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_LD
) == 0)
7194 unsigned int insn1
, insn2
;
7198 offset
= (bfd_vma
) -1;
7199 /* If not using the newer R_PPC_TLSGD/LD to mark
7200 __tls_get_addr calls, we must trust that the call
7201 stays with its arg setup insns, ie. that the next
7202 reloc is the __tls_get_addr call associated with
7203 the current reloc. Edit both insns. */
7204 if (input_section
->nomark_tls_get_addr
7206 && branch_reloc_hash_match (input_bfd
, rel
+ 1,
7207 htab
->tls_get_addr
))
7208 offset
= rel
[1].r_offset
;
7209 /* We read the low GOT_TLS insn because we need to keep
7210 the destination reg. It may be something other than
7211 the usual r3, and moved to r3 before the call by
7212 intervening code. */
7213 insn1
= bfd_get_32 (input_bfd
,
7214 contents
+ rel
->r_offset
- d_offset
);
7215 if ((tls_mask
& tls_gd
) != 0)
7218 insn1
&= (0x1f << 21) | (0x1f << 16);
7219 insn1
|= 32u << 26; /* lwz */
7220 if (offset
!= (bfd_vma
) -1)
7222 rel
[1].r_info
= ELF32_R_INFO (STN_UNDEF
, R_PPC_NONE
);
7223 insn2
= 0x7c631214; /* add 3,3,2 */
7224 bfd_put_32 (input_bfd
, insn2
, contents
+ offset
);
7226 r_type
= (((r_type
- (R_PPC_GOT_TLSGD16
& 3)) & 3)
7227 + R_PPC_GOT_TPREL16
);
7228 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
7233 insn1
&= 0x1f << 21;
7234 insn1
|= 0x3c020000; /* addis r,2,0 */
7237 /* Was an LD reloc. */
7239 r_symndx
< symtab_hdr
->sh_info
;
7241 if (local_sections
[r_symndx
] == sec
)
7243 if (r_symndx
>= symtab_hdr
->sh_info
)
7244 r_symndx
= STN_UNDEF
;
7245 rel
->r_addend
= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
7246 if (r_symndx
!= STN_UNDEF
)
7247 rel
->r_addend
-= (local_syms
[r_symndx
].st_value
7248 + sec
->output_offset
7249 + sec
->output_section
->vma
);
7251 r_type
= R_PPC_TPREL16_HA
;
7252 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
7253 if (offset
!= (bfd_vma
) -1)
7255 rel
[1].r_info
= ELF32_R_INFO (r_symndx
, R_PPC_TPREL16_LO
);
7256 rel
[1].r_offset
= offset
+ d_offset
;
7257 rel
[1].r_addend
= rel
->r_addend
;
7258 insn2
= 0x38630000; /* addi 3,3,0 */
7259 bfd_put_32 (input_bfd
, insn2
, contents
+ offset
);
7262 bfd_put_32 (input_bfd
, insn1
,
7263 contents
+ rel
->r_offset
- d_offset
);
7266 /* We changed the symbol on an LD reloc. Start over
7267 in order to get h, sym, sec etc. right. */
7274 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_GD
) == 0
7275 && rel
+ 1 < relend
)
7278 bfd_vma offset
= rel
->r_offset
;
7280 if (is_plt_seq_reloc (ELF32_R_TYPE (rel
[1].r_info
)))
7282 bfd_put_32 (input_bfd
, NOP
, contents
+ offset
);
7283 rel
[1].r_info
= ELF32_R_INFO (STN_UNDEF
, R_PPC_NONE
);
7287 if ((tls_mask
& TLS_GDIE
) != 0)
7290 r_type
= R_PPC_NONE
;
7291 insn2
= 0x7c631214; /* add 3,3,2 */
7296 r_type
= R_PPC_TPREL16_LO
;
7297 rel
->r_offset
+= d_offset
;
7298 insn2
= 0x38630000; /* addi 3,3,0 */
7300 rel
->r_info
= ELF32_R_INFO (r_symndx
, r_type
);
7301 bfd_put_32 (input_bfd
, insn2
, contents
+ offset
);
7302 /* Zap the reloc on the _tls_get_addr call too. */
7303 BFD_ASSERT (offset
== rel
[1].r_offset
);
7304 rel
[1].r_info
= ELF32_R_INFO (STN_UNDEF
, R_PPC_NONE
);
7309 if ((tls_mask
& TLS_TLS
) != 0 && (tls_mask
& TLS_LD
) == 0
7310 && rel
+ 1 < relend
)
7314 if (is_plt_seq_reloc (ELF32_R_TYPE (rel
[1].r_info
)))
7316 bfd_put_32 (input_bfd
, NOP
, contents
+ rel
->r_offset
);
7317 rel
[1].r_info
= ELF32_R_INFO (STN_UNDEF
, R_PPC_NONE
);
7322 r_symndx
< symtab_hdr
->sh_info
;
7324 if (local_sections
[r_symndx
] == sec
)
7326 if (r_symndx
>= symtab_hdr
->sh_info
)
7327 r_symndx
= STN_UNDEF
;
7328 rel
->r_addend
= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
7329 if (r_symndx
!= STN_UNDEF
)
7330 rel
->r_addend
-= (local_syms
[r_symndx
].st_value
7331 + sec
->output_offset
7332 + sec
->output_section
->vma
);
7334 rel
->r_info
= ELF32_R_INFO (r_symndx
, R_PPC_TPREL16_LO
);
7335 rel
->r_offset
+= d_offset
;
7336 insn2
= 0x38630000; /* addi 3,3,0 */
7337 bfd_put_32 (input_bfd
, insn2
,
7338 contents
+ rel
->r_offset
- d_offset
);
7339 /* Zap the reloc on the _tls_get_addr call too. */
7340 BFD_ASSERT (rel
->r_offset
- d_offset
== rel
[1].r_offset
);
7341 rel
[1].r_info
= ELF32_R_INFO (STN_UNDEF
, R_PPC_NONE
);
7347 /* Handle other relocations that tweak non-addend part of insn. */
7354 /* Branch taken prediction relocations. */
7355 case R_PPC_ADDR14_BRTAKEN
:
7356 case R_PPC_REL14_BRTAKEN
:
7357 branch_bit
= BRANCH_PREDICT_BIT
;
7360 /* Branch not taken prediction relocations. */
7361 case R_PPC_ADDR14_BRNTAKEN
:
7362 case R_PPC_REL14_BRNTAKEN
:
7366 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
7367 insn
&= ~BRANCH_PREDICT_BIT
;
7370 from
= (rel
->r_offset
7371 + input_section
->output_offset
7372 + input_section
->output_section
->vma
);
7374 /* Invert 'y' bit if not the default. */
7375 if ((bfd_signed_vma
) (relocation
+ rel
->r_addend
- from
) < 0)
7376 insn
^= BRANCH_PREDICT_BIT
;
7378 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
7382 case R_PPC_PLT16_HA
:
7386 insn
= bfd_get_32 (input_bfd
,
7387 contents
+ rel
->r_offset
- d_offset
);
7388 if ((insn
& (0x3fu
<< 26)) == 15u << 26
7389 && (insn
& (0x1f << 16)) != 0)
7391 if (!bfd_link_pic (info
))
7393 /* Convert addis to lis. */
7394 insn
&= ~(0x1f << 16);
7395 bfd_put_32 (input_bfd
, insn
,
7396 contents
+ rel
->r_offset
- d_offset
);
7399 else if (bfd_link_pic (info
))
7400 info
->callbacks
->einfo
7401 (_("%P: %H: error: %s with unexpected instruction %x\n"),
7402 input_bfd
, input_section
, rel
->r_offset
,
7403 "R_PPC_PLT16_HA", insn
);
7408 if (ELIMINATE_COPY_RELOCS
7412 && ppc_elf_hash_entry (h
)->has_addr16_ha
7413 && ppc_elf_hash_entry (h
)->has_addr16_lo
7414 && htab
->params
->pic_fixup
> 0)
7416 /* Convert lis;addi or lis;load/store accessing a protected
7417 variable defined in a shared library to PIC. */
7420 if (r_type
== R_PPC_ADDR16_HA
)
7422 insn
= bfd_get_32 (input_bfd
,
7423 contents
+ rel
->r_offset
- d_offset
);
7424 if ((insn
& (0x3fu
<< 26)) == (15u << 26)
7425 && (insn
& (0x1f << 16)) == 0 /* lis */)
7431 p
= (contents
+ input_section
->size
7432 - relax_info
->workaround_size
7433 - relax_info
->picfixup_size
7435 off
= (p
- contents
) - (rel
->r_offset
- d_offset
);
7436 if (off
> 0x1fffffc || (off
& 3) != 0)
7437 info
->callbacks
->einfo
7438 (_("%H: fixup branch overflow\n"),
7439 input_bfd
, input_section
, rel
->r_offset
);
7441 bfd_put_32 (input_bfd
, B
| off
,
7442 contents
+ rel
->r_offset
- d_offset
);
7443 got_addr
= (htab
->elf
.sgot
->output_section
->vma
7444 + htab
->elf
.sgot
->output_offset
7445 + (h
->got
.offset
& ~1));
7446 wrel
->r_offset
= (p
- contents
) + d_offset
;
7447 wrel
->r_info
= ELF32_R_INFO (0, R_PPC_ADDR16_HA
);
7448 wrel
->r_addend
= got_addr
;
7450 insn
|= ((unsigned int) (got_addr
+ 0x8000) >> 16) & 0xffff;
7451 bfd_put_32 (input_bfd
, insn
, p
);
7453 /* Convert lis to lwz, loading address from GOT. */
7455 insn
^= (32u ^ 15u) << 26;
7456 insn
|= (insn
& (0x1f << 21)) >> 5;
7457 insn
|= got_addr
& 0xffff;
7458 bfd_put_32 (input_bfd
, insn
, p
+ 4);
7460 bfd_put_32 (input_bfd
, B
| ((-4 - off
) & 0x3ffffff), p
+ 8);
7461 picfixup_size
+= 12;
7463 /* Use one of the spare relocs, so --emit-relocs
7464 output is reasonable. */
7465 memmove (rel
+ 1, rel
, (relend
- rel
- 1) * sizeof (*rel
));
7467 rel
->r_offset
= wrel
[-1].r_offset
+ 4;
7468 rel
->r_info
= ELF32_R_INFO (0, R_PPC_ADDR16_LO
);
7469 rel
->r_addend
= wrel
[-1].r_addend
;
7471 /* Continue on as if we had a got reloc, to output
7473 r_type
= R_PPC_GOT16_LO
;
7477 /* xgettext:c-format */
7478 (_("%pB(%pA+%#" PRIx64
"): error: "
7479 "%s with unexpected instruction %#x"),
7480 input_bfd
, input_section
, (uint64_t) rel
->r_offset
,
7481 "R_PPC_ADDR16_HA", insn
);
7483 else if (r_type
== R_PPC_ADDR16_LO
)
7485 insn
= bfd_get_32 (input_bfd
,
7486 contents
+ rel
->r_offset
- d_offset
);
7487 if ((insn
& (0x3fu
<< 26)) == 14u << 26 /* addi */
7488 || (insn
& (0x3fu
<< 26)) == 32u << 26 /* lwz */
7489 || (insn
& (0x3fu
<< 26)) == 34u << 26 /* lbz */
7490 || (insn
& (0x3fu
<< 26)) == 36u << 26 /* stw */
7491 || (insn
& (0x3fu
<< 26)) == 38u << 26 /* stb */
7492 || (insn
& (0x3fu
<< 26)) == 40u << 26 /* lhz */
7493 || (insn
& (0x3fu
<< 26)) == 42u << 26 /* lha */
7494 || (insn
& (0x3fu
<< 26)) == 44u << 26 /* sth */
7495 || (insn
& (0x3fu
<< 26)) == 46u << 26 /* lmw */
7496 || (insn
& (0x3fu
<< 26)) == 47u << 26 /* stmw */
7497 || (insn
& (0x3fu
<< 26)) == 48u << 26 /* lfs */
7498 || (insn
& (0x3fu
<< 26)) == 50u << 26 /* lfd */
7499 || (insn
& (0x3fu
<< 26)) == 52u << 26 /* stfs */
7500 || (insn
& (0x3fu
<< 26)) == 54u << 26 /* stfd */
7501 || ((insn
& (0x3fu
<< 26)) == 58u << 26 /* lwa,ld,lmd */
7503 || ((insn
& (0x3fu
<< 26)) == 62u << 26 /* std, stmd */
7504 && ((insn
& 3) == 0 || (insn
& 3) == 3)))
7506 /* Arrange to apply the reloc addend, if any. */
7508 unresolved_reloc
= FALSE
;
7509 rel
->r_info
= ELF32_R_INFO (0, r_type
);
7513 /* xgettext:c-format */
7514 (_("%pB(%pA+%#" PRIx64
"): error: "
7515 "%s with unexpected instruction %#x"),
7516 input_bfd
, input_section
, (uint64_t) rel
->r_offset
,
7517 "R_PPC_ADDR16_LO", insn
);
7522 if (htab
->elf
.target_os
!= is_vxworks
)
7524 struct plt_entry
*ent
;
7528 if (h
->type
== STT_GNU_IFUNC
)
7529 ifunc
= &h
->plt
.plist
;
7531 else if (local_got_offsets
!= NULL
7532 && ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
7534 struct plt_entry
**local_plt
;
7536 local_plt
= (struct plt_entry
**) (local_got_offsets
7537 + symtab_hdr
->sh_info
);
7538 ifunc
= local_plt
+ r_symndx
;
7543 && (!bfd_link_pic (info
)
7544 || is_branch_reloc (r_type
)
7545 || r_type
== R_PPC_PLT16_LO
7546 || r_type
== R_PPC_PLT16_HI
7547 || r_type
== R_PPC_PLT16_HA
))
7550 if (bfd_link_pic (info
)
7551 && (r_type
== R_PPC_PLTREL24
7552 || r_type
== R_PPC_PLT16_LO
7553 || r_type
== R_PPC_PLT16_HI
7554 || r_type
== R_PPC_PLT16_HA
))
7555 addend
= rel
->r_addend
;
7556 ent
= find_plt_ent (ifunc
, got2
, addend
);
7560 if (bfd_link_pic (info
)
7562 && htab
->plt_type
!= PLT_NEW
7563 && (!htab
->elf
.dynamic_sections_created
7565 || h
->dynindx
== -1))
7567 /* Uh oh, we are going to create a pic glink stub
7568 for an ifunc (here for h == NULL and later in
7569 finish_dynamic_symbol for h != NULL), and
7570 apparently are using code compiled with
7571 -mbss-plt. The difficulty is that -mbss-plt code
7572 gives no indication via a magic PLTREL24 addend
7573 whether r30 is equal to _GLOBAL_OFFSET_TABLE_ or
7574 is pointing into a .got2 section (and how far
7576 info
->callbacks
->einfo
7577 /* xgettext:c-format */
7578 (_("%X%H: unsupported bss-plt -fPIC ifunc %s\n"),
7579 input_bfd
, input_section
, rel
->r_offset
, sym_name
);
7582 unresolved_reloc
= FALSE
;
7583 if (htab
->plt_type
== PLT_NEW
7584 || !htab
->elf
.dynamic_sections_created
7586 || h
->dynindx
== -1)
7587 relocation
= (htab
->glink
->output_section
->vma
7588 + htab
->glink
->output_offset
7589 + (ent
->glink_offset
& ~1));
7591 relocation
= (htab
->elf
.splt
->output_section
->vma
7592 + htab
->elf
.splt
->output_offset
7597 addend
= rel
->r_addend
;
7598 save_unresolved_reloc
= unresolved_reloc
;
7600 if (r_type
< R_PPC_max
)
7601 howto
= ppc_elf_howto_table
[r_type
];
7607 /* xgettext:c-format */
7608 _bfd_error_handler (_("%pB: %s unsupported"),
7609 input_bfd
, howto
->name
);
7611 bfd_set_error (bfd_error_bad_value
);
7619 case R_PPC_EMB_MRKREF
:
7620 case R_PPC_GNU_VTINHERIT
:
7621 case R_PPC_GNU_VTENTRY
:
7624 /* GOT16 relocations. Like an ADDR16 using the symbol's
7625 address in the GOT as relocation value instead of the
7626 symbol's value itself. Also, create a GOT entry for the
7627 symbol and put the symbol value there. */
7628 case R_PPC_GOT_TLSGD16
:
7629 case R_PPC_GOT_TLSGD16_LO
:
7630 case R_PPC_GOT_TLSGD16_HI
:
7631 case R_PPC_GOT_TLSGD16_HA
:
7632 tls_type
= TLS_TLS
| TLS_GD
;
7635 case R_PPC_GOT_TLSLD16
:
7636 case R_PPC_GOT_TLSLD16_LO
:
7637 case R_PPC_GOT_TLSLD16_HI
:
7638 case R_PPC_GOT_TLSLD16_HA
:
7639 tls_type
= TLS_TLS
| TLS_LD
;
7642 case R_PPC_GOT_TPREL16
:
7643 case R_PPC_GOT_TPREL16_LO
:
7644 case R_PPC_GOT_TPREL16_HI
:
7645 case R_PPC_GOT_TPREL16_HA
:
7646 tls_type
= TLS_TLS
| TLS_TPREL
;
7649 case R_PPC_GOT_DTPREL16
:
7650 case R_PPC_GOT_DTPREL16_LO
:
7651 case R_PPC_GOT_DTPREL16_HI
:
7652 case R_PPC_GOT_DTPREL16_HA
:
7653 tls_type
= TLS_TLS
| TLS_DTPREL
;
7657 case R_PPC_GOT16_LO
:
7658 case R_PPC_GOT16_HI
:
7659 case R_PPC_GOT16_HA
:
7663 /* Relocation is to the entry for this symbol in the global
7669 if (htab
->elf
.sgot
== NULL
)
7673 if (tls_type
== (TLS_TLS
| TLS_LD
)
7674 && SYMBOL_REFERENCES_LOCAL (info
, h
))
7675 offp
= &htab
->tlsld_got
.offset
;
7678 if (!htab
->elf
.dynamic_sections_created
7680 || SYMBOL_REFERENCES_LOCAL (info
, h
)
7681 || UNDEFWEAK_NO_DYNAMIC_RELOC (info
, h
))
7682 /* This is actually a static link, or it is a
7683 -Bsymbolic link and the symbol is defined
7684 locally, or the symbol was forced to be local
7685 because of a version file. */
7690 unresolved_reloc
= FALSE
;
7692 offp
= &h
->got
.offset
;
7696 if (local_got_offsets
== NULL
)
7698 offp
= &local_got_offsets
[r_symndx
];
7701 /* The offset must always be a multiple of 4. We use the
7702 least significant bit to record whether we have already
7703 processed this entry. */
7709 unsigned int tls_m
= ((tls_mask
& TLS_TLS
) != 0
7710 ? tls_mask
& (TLS_LD
| TLS_GD
| TLS_DTPREL
7711 | TLS_TPREL
| TLS_GDIE
)
7714 if (offp
== &htab
->tlsld_got
.offset
)
7716 else if ((tls_m
& TLS_LD
) != 0
7717 && SYMBOL_REFERENCES_LOCAL (info
, h
))
7720 /* We might have multiple got entries for this sym.
7721 Initialize them all. */
7726 if ((tls_m
& TLS_LD
) != 0)
7728 tls_ty
= TLS_TLS
| TLS_LD
;
7731 else if ((tls_m
& TLS_GD
) != 0)
7733 tls_ty
= TLS_TLS
| TLS_GD
;
7736 else if ((tls_m
& TLS_DTPREL
) != 0)
7738 tls_ty
= TLS_TLS
| TLS_DTPREL
;
7739 tls_m
&= ~TLS_DTPREL
;
7741 else if ((tls_m
& (TLS_TPREL
| TLS_GDIE
)) != 0)
7743 tls_ty
= TLS_TLS
| TLS_TPREL
;
7747 /* Generate relocs for the dynamic linker. */
7749 || (bfd_link_pic (info
)
7751 || !UNDEFWEAK_NO_DYNAMIC_RELOC (info
, h
))
7753 && bfd_link_executable (info
)
7754 && SYMBOL_REFERENCES_LOCAL (info
, h
))))
7756 asection
*rsec
= htab
->elf
.srelgot
;
7761 rsec
= htab
->elf
.irelplt
;
7763 htab
->local_ifunc_resolver
= 1;
7764 else if (is_static_defined (h
))
7765 htab
->maybe_local_ifunc_resolver
= 1;
7767 outrel
.r_offset
= (htab
->elf
.sgot
->output_section
->vma
7768 + htab
->elf
.sgot
->output_offset
7770 outrel
.r_addend
= 0;
7771 if (tls_ty
& (TLS_LD
| TLS_GD
))
7773 outrel
.r_info
= ELF32_R_INFO (indx
, R_PPC_DTPMOD32
);
7774 if (tls_ty
== (TLS_TLS
| TLS_GD
))
7776 loc
= rsec
->contents
;
7777 loc
+= (rsec
->reloc_count
++
7778 * sizeof (Elf32_External_Rela
));
7779 bfd_elf32_swap_reloca_out (output_bfd
,
7781 outrel
.r_offset
+= 4;
7783 = ELF32_R_INFO (indx
, R_PPC_DTPREL32
);
7786 else if (tls_ty
== (TLS_TLS
| TLS_DTPREL
))
7787 outrel
.r_info
= ELF32_R_INFO (indx
, R_PPC_DTPREL32
);
7788 else if (tls_ty
== (TLS_TLS
| TLS_TPREL
))
7789 outrel
.r_info
= ELF32_R_INFO (indx
, R_PPC_TPREL32
);
7791 outrel
.r_info
= ELF32_R_INFO (indx
, R_PPC_GLOB_DAT
);
7792 else if (ifunc
!= NULL
)
7793 outrel
.r_info
= ELF32_R_INFO (0, R_PPC_IRELATIVE
);
7795 outrel
.r_info
= ELF32_R_INFO (0, R_PPC_RELATIVE
);
7796 if (indx
== 0 && tls_ty
!= (TLS_TLS
| TLS_LD
))
7798 outrel
.r_addend
+= relocation
;
7799 if (tls_ty
& (TLS_GD
| TLS_DTPREL
| TLS_TPREL
))
7801 if (htab
->elf
.tls_sec
== NULL
)
7802 outrel
.r_addend
= 0;
7804 outrel
.r_addend
-= htab
->elf
.tls_sec
->vma
;
7807 loc
= rsec
->contents
;
7808 loc
+= (rsec
->reloc_count
++
7809 * sizeof (Elf32_External_Rela
));
7810 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
7813 /* Init the .got section contents if we're not
7814 emitting a reloc. */
7817 bfd_vma value
= relocation
;
7821 if (htab
->elf
.tls_sec
== NULL
)
7825 if (tls_ty
& TLS_LD
)
7828 value
-= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
7829 if (tls_ty
& TLS_TPREL
)
7830 value
+= DTP_OFFSET
- TP_OFFSET
;
7833 if (tls_ty
& (TLS_LD
| TLS_GD
))
7835 bfd_put_32 (input_bfd
, value
,
7836 htab
->elf
.sgot
->contents
+ off
+ 4);
7840 bfd_put_32 (input_bfd
, value
,
7841 htab
->elf
.sgot
->contents
+ off
);
7845 if (tls_ty
& (TLS_LD
| TLS_GD
))
7854 if (off
>= (bfd_vma
) -2)
7857 if ((tls_type
& TLS_TLS
) != 0)
7859 if (tls_type
!= (TLS_TLS
| TLS_LD
))
7861 if ((tls_mask
& TLS_LD
) != 0
7862 && !SYMBOL_REFERENCES_LOCAL (info
, h
))
7864 if (tls_type
!= (TLS_TLS
| TLS_GD
))
7866 if ((tls_mask
& TLS_GD
) != 0)
7868 if (tls_type
!= (TLS_TLS
| TLS_DTPREL
))
7870 if ((tls_mask
& TLS_DTPREL
) != 0)
7877 /* If here for a picfixup, we're done. */
7878 if (r_type
!= ELF32_R_TYPE (rel
->r_info
))
7881 relocation
= (htab
->elf
.sgot
->output_section
->vma
7882 + htab
->elf
.sgot
->output_offset
7884 - SYM_VAL (htab
->elf
.hgot
));
7886 /* Addends on got relocations don't make much sense.
7887 x+off@got is actually x@got+off, and since the got is
7888 generated by a hash table traversal, the value in the
7889 got at entry m+n bears little relation to the entry m. */
7891 info
->callbacks
->einfo
7892 /* xgettext:c-format */
7893 (_("%H: non-zero addend on %s reloc against `%s'\n"),
7894 input_bfd
, input_section
, rel
->r_offset
,
7900 /* Relocations that need no special processing. */
7901 case R_PPC_LOCAL24PC
:
7902 /* It makes no sense to point a local relocation
7903 at a symbol not in this object. */
7904 if (unresolved_reloc
)
7906 (*info
->callbacks
->undefined_symbol
) (info
,
7907 h
->root
.root
.string
,
7914 if (h
!= NULL
&& h
->type
== STT_GNU_IFUNC
&& bfd_link_pic (info
))
7916 /* @local on an ifunc does not really make sense since
7917 the ifunc resolver can take you anywhere. More
7918 seriously, calls to ifuncs must go through a plt call
7919 stub, and for pic the plt call stubs uses r30 to
7920 access the PLT. The problem is that a call that is
7921 local won't have the +32k reloc addend trick marking
7922 -fPIC code, so the linker won't know whether r30 is
7923 _GLOBAL_OFFSET_TABLE_ or pointing into a .got2 section. */
7924 /* xgettext:c-format */
7925 info
->callbacks
->einfo (_("%X%H: @local call to ifunc %s\n"),
7926 input_bfd
, input_section
, rel
->r_offset
,
7927 h
->root
.root
.string
);
7931 case R_PPC_DTPREL16
:
7932 case R_PPC_DTPREL16_LO
:
7933 case R_PPC_DTPREL16_HI
:
7934 case R_PPC_DTPREL16_HA
:
7935 if (htab
->elf
.tls_sec
!= NULL
)
7936 addend
-= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
7939 /* Relocations that may need to be propagated if this is a shared
7942 case R_PPC_TPREL16_LO
:
7943 case R_PPC_TPREL16_HI
:
7944 case R_PPC_TPREL16_HA
:
7946 && h
->root
.type
== bfd_link_hash_undefweak
7947 && h
->dynindx
== -1)
7949 /* Make this relocation against an undefined weak symbol
7950 resolve to zero. This is really just a tweak, since
7951 code using weak externs ought to check that they are
7952 defined before using them. */
7953 bfd_byte
*p
= contents
+ rel
->r_offset
- d_offset
;
7954 unsigned int insn
= bfd_get_32 (input_bfd
, p
);
7955 insn
= _bfd_elf_ppc_at_tprel_transform (insn
, 2);
7957 bfd_put_32 (input_bfd
, insn
, p
);
7960 if (htab
->elf
.tls_sec
!= NULL
)
7961 addend
-= htab
->elf
.tls_sec
->vma
+ TP_OFFSET
;
7962 /* The TPREL16 relocs shouldn't really be used in shared
7963 libs or with non-local symbols as that will result in
7964 DT_TEXTREL being set, but support them anyway. */
7968 if (htab
->elf
.tls_sec
!= NULL
)
7969 addend
-= htab
->elf
.tls_sec
->vma
+ TP_OFFSET
;
7972 case R_PPC_DTPREL32
:
7973 if (htab
->elf
.tls_sec
!= NULL
)
7974 addend
-= htab
->elf
.tls_sec
->vma
+ DTP_OFFSET
;
7977 case R_PPC_DTPMOD32
:
7983 case R_PPC_REL16_LO
:
7984 case R_PPC_REL16_HI
:
7985 case R_PPC_REL16_HA
:
7986 case R_PPC_REL16DX_HA
:
7990 if (h
== NULL
|| h
== htab
->elf
.hgot
)
7996 case R_PPC_ADDR16_LO
:
7997 case R_PPC_ADDR16_HI
:
7998 case R_PPC_ADDR16_HA
:
8003 case R_PPC_VLE_REL8
:
8004 case R_PPC_VLE_REL15
:
8005 case R_PPC_VLE_REL24
:
8008 case R_PPC_REL14_BRTAKEN
:
8009 case R_PPC_REL14_BRNTAKEN
:
8010 /* If these relocations are not to a named symbol, they can be
8011 handled right here, no need to bother the dynamic linker. */
8012 if (SYMBOL_CALLS_LOCAL (info
, h
)
8013 || h
== htab
->elf
.hgot
)
8019 case R_PPC_ADDR14_BRTAKEN
:
8020 case R_PPC_ADDR14_BRNTAKEN
:
8021 if (h
!= NULL
&& !bfd_link_pic (info
))
8026 if ((input_section
->flags
& SEC_ALLOC
) == 0
8030 if (bfd_link_pic (info
)
8032 || h
->dyn_relocs
!= NULL
)
8033 && ((h
!= NULL
&& pc_dynrelocs (h
))
8034 || must_be_dyn_reloc (info
, r_type
)))
8036 && h
->dyn_relocs
!= NULL
))
8044 fprintf (stderr
, "ppc_elf_relocate_section needs to "
8045 "create relocation for %s\n",
8046 (h
&& h
->root
.root
.string
8047 ? h
->root
.root
.string
: "<unknown>"));
8050 /* When generating a shared object, these relocations
8051 are copied into the output file to be resolved at run
8054 outrel
.r_offset
= _bfd_elf_section_offset (output_bfd
, info
,
8057 if (outrel
.r_offset
== (bfd_vma
) -1
8058 || outrel
.r_offset
== (bfd_vma
) -2)
8059 skip
= (int) outrel
.r_offset
;
8060 outrel
.r_offset
+= (input_section
->output_section
->vma
8061 + input_section
->output_offset
);
8063 /* Optimize unaligned reloc use. */
8064 if ((r_type
== R_PPC_ADDR32
&& (outrel
.r_offset
& 3) != 0)
8065 || (r_type
== R_PPC_UADDR32
&& (outrel
.r_offset
& 3) == 0))
8066 r_type
^= R_PPC_ADDR32
^ R_PPC_UADDR32
;
8067 if ((r_type
== R_PPC_ADDR16
&& (outrel
.r_offset
& 1) != 0)
8068 || (r_type
== R_PPC_UADDR16
&& (outrel
.r_offset
& 1) == 0))
8069 r_type
^= R_PPC_ADDR16
^ R_PPC_UADDR16
;
8072 memset (&outrel
, 0, sizeof outrel
);
8073 else if (!SYMBOL_REFERENCES_LOCAL (info
, h
))
8076 BFD_ASSERT (indx
!= -1);
8077 unresolved_reloc
= FALSE
;
8078 outrel
.r_info
= ELF32_R_INFO (indx
, r_type
);
8079 outrel
.r_addend
= rel
->r_addend
;
8083 outrel
.r_addend
= relocation
+ rel
->r_addend
;
8085 if (r_type
!= R_PPC_ADDR32
)
8089 /* If we get here when building a static
8090 executable, then the libc startup function
8091 responsible for applying indirect function
8092 relocations is going to complain about
8094 If we get here when building a dynamic
8095 executable, it will be because we have
8096 a text relocation. The dynamic loader
8097 will set the text segment writable and
8098 non-executable to apply text relocations.
8099 So we'll segfault when trying to run the
8100 indirection function to resolve the reloc. */
8101 info
->callbacks
->einfo
8102 /* xgettext:c-format */
8103 (_("%H: relocation %s for indirect "
8104 "function %s unsupported\n"),
8105 input_bfd
, input_section
, rel
->r_offset
,
8110 else if (r_symndx
== STN_UNDEF
|| bfd_is_abs_section (sec
))
8112 else if (sec
== NULL
|| sec
->owner
== NULL
)
8114 bfd_set_error (bfd_error_bad_value
);
8121 /* We are turning this relocation into one
8122 against a section symbol. It would be
8123 proper to subtract the symbol's value,
8124 osec->vma, from the emitted reloc addend,
8125 but ld.so expects buggy relocs.
8126 FIXME: Why not always use a zero index? */
8127 osec
= sec
->output_section
;
8128 if ((osec
->flags
& SEC_THREAD_LOCAL
) != 0)
8130 osec
= htab
->elf
.tls_sec
;
8135 indx
= elf_section_data (osec
)->dynindx
;
8138 osec
= htab
->elf
.text_index_section
;
8139 indx
= elf_section_data (osec
)->dynindx
;
8141 BFD_ASSERT (indx
!= 0);
8144 /* ld.so doesn't expect buggy TLS relocs.
8145 Don't leave the symbol value in the
8147 if (IS_PPC_TLS_RELOC (r_type
))
8148 outrel
.r_addend
-= osec
->vma
;
8151 outrel
.r_info
= ELF32_R_INFO (indx
, r_type
);
8153 else if (ifunc
!= NULL
)
8154 outrel
.r_info
= ELF32_R_INFO (0, R_PPC_IRELATIVE
);
8156 outrel
.r_info
= ELF32_R_INFO (0, R_PPC_RELATIVE
);
8159 sreloc
= elf_section_data (input_section
)->sreloc
;
8162 sreloc
= htab
->elf
.irelplt
;
8164 htab
->local_ifunc_resolver
= 1;
8165 else if (is_static_defined (h
))
8166 htab
->maybe_local_ifunc_resolver
= 1;
8171 loc
= sreloc
->contents
;
8172 loc
+= sreloc
->reloc_count
++ * sizeof (Elf32_External_Rela
);
8173 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
, loc
);
8178 /* This reloc will be computed at runtime. Clear the memory
8179 so that it contains a predictable value for prelink. */
8182 relocation
= howto
->pc_relative
? outrel
.r_offset
: 0;
8189 case R_PPC_RELAX_PLT
:
8190 case R_PPC_RELAX_PLTREL24
:
8193 struct plt_entry
*ent
;
8194 bfd_vma got2_addend
= 0;
8196 if (r_type
== R_PPC_RELAX_PLTREL24
)
8198 if (bfd_link_pic (info
))
8199 got2_addend
= addend
;
8202 ent
= find_plt_ent (&h
->plt
.plist
, got2
, got2_addend
);
8203 if (htab
->plt_type
== PLT_NEW
)
8204 relocation
= (htab
->glink
->output_section
->vma
8205 + htab
->glink
->output_offset
8206 + ent
->glink_offset
);
8208 relocation
= (htab
->elf
.splt
->output_section
->vma
8209 + htab
->elf
.splt
->output_offset
8218 size_t insn_offset
= rel
->r_offset
;
8221 if (bfd_link_pic (info
))
8223 relocation
-= (input_section
->output_section
->vma
8224 + input_section
->output_offset
8225 + rel
->r_offset
- 4);
8226 stub
= shared_stub_entry
;
8227 bfd_put_32 (input_bfd
, stub
[0], contents
+ insn_offset
- 12);
8228 bfd_put_32 (input_bfd
, stub
[1], contents
+ insn_offset
- 8);
8229 bfd_put_32 (input_bfd
, stub
[2], contents
+ insn_offset
- 4);
8231 size
= ARRAY_SIZE (shared_stub_entry
) - 3;
8236 size
= ARRAY_SIZE (stub_entry
);
8239 relocation
+= addend
;
8240 if (bfd_link_relocatable (info
))
8243 /* First insn is HA, second is LO. */
8245 insn
|= ((relocation
+ 0x8000) >> 16) & 0xffff;
8246 bfd_put_32 (input_bfd
, insn
, contents
+ insn_offset
);
8250 insn
|= relocation
& 0xffff;
8251 bfd_put_32 (input_bfd
, insn
, contents
+ insn_offset
);
8259 bfd_put_32 (input_bfd
, insn
, contents
+ insn_offset
);
8263 /* Rewrite the reloc and convert one of the trailing nop
8264 relocs to describe this relocation. */
8265 BFD_ASSERT (ELF32_R_TYPE (relend
[-1].r_info
) == R_PPC_NONE
);
8266 /* The relocs are at the bottom 2 bytes */
8267 wrel
->r_offset
= rel
->r_offset
+ d_offset
;
8268 wrel
->r_info
= ELF32_R_INFO (r_symndx
, R_PPC_ADDR16_HA
);
8269 wrel
->r_addend
= rel
->r_addend
;
8270 memmove (wrel
+ 1, wrel
, (relend
- wrel
- 1) * sizeof (*wrel
));
8272 wrel
->r_offset
+= 4;
8273 wrel
->r_info
= ELF32_R_INFO (r_symndx
, R_PPC_ADDR16_LO
);
8277 /* Indirect .sdata relocation. */
8278 case R_PPC_EMB_SDAI16
:
8279 BFD_ASSERT (htab
->sdata
[0].section
!= NULL
);
8280 if (!is_static_defined (htab
->sdata
[0].sym
))
8282 unresolved_reloc
= TRUE
;
8286 = elf_finish_pointer_linker_section (input_bfd
, &htab
->sdata
[0],
8287 h
, relocation
, rel
);
8291 /* Indirect .sdata2 relocation. */
8292 case R_PPC_EMB_SDA2I16
:
8293 BFD_ASSERT (htab
->sdata
[1].section
!= NULL
);
8294 if (!is_static_defined (htab
->sdata
[1].sym
))
8296 unresolved_reloc
= TRUE
;
8300 = elf_finish_pointer_linker_section (input_bfd
, &htab
->sdata
[1],
8301 h
, relocation
, rel
);
8305 /* Handle the TOC16 reloc. We want to use the offset within the .got
8306 section, not the actual VMA. This is appropriate when generating
8307 an embedded ELF object, for which the .got section acts like the
8308 AIX .toc section. */
8309 case R_PPC_TOC16
: /* phony GOT16 relocations */
8310 if (sec
== NULL
|| sec
->output_section
== NULL
)
8312 unresolved_reloc
= TRUE
;
8315 BFD_ASSERT (strcmp (bfd_section_name (sec
), ".got") == 0
8316 || strcmp (bfd_section_name (sec
), ".cgot") == 0);
8318 addend
-= sec
->output_section
->vma
+ sec
->output_offset
+ 0x8000;
8321 case R_PPC_PLTREL24
:
8322 if (h
!= NULL
&& ifunc
== NULL
)
8324 struct plt_entry
*ent
;
8326 ent
= find_plt_ent (&h
->plt
.plist
, got2
,
8327 bfd_link_pic (info
) ? addend
: 0);
8329 || htab
->elf
.splt
== NULL
)
8331 /* We didn't make a PLT entry for this symbol. This
8332 happens when statically linking PIC code, or when
8333 using -Bsymbolic. */
8337 /* Relocation is to the entry for this symbol in the
8338 procedure linkage table. */
8339 unresolved_reloc
= FALSE
;
8340 if (htab
->plt_type
== PLT_NEW
)
8341 relocation
= (htab
->glink
->output_section
->vma
8342 + htab
->glink
->output_offset
8343 + ent
->glink_offset
);
8345 relocation
= (htab
->elf
.splt
->output_section
->vma
8346 + htab
->elf
.splt
->output_offset
8351 /* R_PPC_PLTREL24 is rather special. If non-zero, the
8352 addend specifies the GOT pointer offset within .got2.
8353 Don't apply it to the relocation field. */
8359 case R_PPC_PLT16_LO
:
8360 case R_PPC_PLT16_HI
:
8361 case R_PPC_PLT16_HA
:
8364 plt_list
= &h
->plt
.plist
;
8365 else if (ifunc
!= NULL
)
8367 else if (local_got_offsets
!= NULL
)
8369 struct plt_entry
**local_plt
;
8370 local_plt
= (struct plt_entry
**) (local_got_offsets
8371 + symtab_hdr
->sh_info
);
8372 plt_list
= local_plt
+ r_symndx
;
8374 unresolved_reloc
= TRUE
;
8375 if (plt_list
!= NULL
)
8377 struct plt_entry
*ent
;
8379 ent
= find_plt_ent (plt_list
, got2
,
8380 bfd_link_pic (info
) ? addend
: 0);
8381 if (ent
!= NULL
&& ent
->plt
.offset
!= (bfd_vma
) -1)
8385 unresolved_reloc
= FALSE
;
8386 plt
= htab
->elf
.splt
;
8387 if (use_local_plt (info
, h
))
8390 plt
= htab
->elf
.iplt
;
8392 plt
= htab
->pltlocal
;
8394 relocation
= (plt
->output_section
->vma
8395 + plt
->output_offset
8397 if (bfd_link_pic (info
))
8401 if (ent
->addend
>= 32768)
8403 + ent
->sec
->output_section
->vma
8404 + ent
->sec
->output_offset
);
8406 got
= SYM_VAL (htab
->elf
.hgot
);
8414 /* Relocate against _SDA_BASE_. */
8415 case R_PPC_SDAREL16
:
8418 struct elf_link_hash_entry
*sda
= htab
->sdata
[0].sym
;
8421 || sec
->output_section
== NULL
8422 || !is_static_defined (sda
))
8424 unresolved_reloc
= TRUE
;
8427 addend
-= SYM_VAL (sda
);
8429 name
= bfd_section_name (sec
->output_section
);
8430 if (!(strcmp (name
, ".sdata") == 0
8431 || strcmp (name
, ".sbss") == 0))
8434 /* xgettext:c-format */
8435 (_("%pB: the target (%s) of a %s relocation is "
8436 "in the wrong output section (%s)"),
8445 /* Relocate against _SDA2_BASE_. */
8446 case R_PPC_EMB_SDA2REL
:
8449 struct elf_link_hash_entry
*sda
= htab
->sdata
[1].sym
;
8452 || sec
->output_section
== NULL
8453 || !is_static_defined (sda
))
8455 unresolved_reloc
= TRUE
;
8458 addend
-= SYM_VAL (sda
);
8460 name
= bfd_section_name (sec
->output_section
);
8461 if (!(strcmp (name
, ".sdata2") == 0
8462 || strcmp (name
, ".sbss2") == 0))
8465 /* xgettext:c-format */
8466 (_("%pB: the target (%s) of a %s relocation is "
8467 "in the wrong output section (%s)"),
8476 case R_PPC_VLE_LO16A
:
8477 relocation
= relocation
+ addend
;
8478 ppc_elf_vle_split16 (input_bfd
, input_section
, rel
->r_offset
,
8479 contents
+ rel
->r_offset
, relocation
,
8480 split16a_type
, htab
->params
->vle_reloc_fixup
);
8483 case R_PPC_VLE_LO16D
:
8484 relocation
= relocation
+ addend
;
8485 ppc_elf_vle_split16 (input_bfd
, input_section
, rel
->r_offset
,
8486 contents
+ rel
->r_offset
, relocation
,
8487 split16d_type
, htab
->params
->vle_reloc_fixup
);
8490 case R_PPC_VLE_HI16A
:
8491 relocation
= (relocation
+ addend
) >> 16;
8492 ppc_elf_vle_split16 (input_bfd
, input_section
, rel
->r_offset
,
8493 contents
+ rel
->r_offset
, relocation
,
8494 split16a_type
, htab
->params
->vle_reloc_fixup
);
8497 case R_PPC_VLE_HI16D
:
8498 relocation
= (relocation
+ addend
) >> 16;
8499 ppc_elf_vle_split16 (input_bfd
, input_section
, rel
->r_offset
,
8500 contents
+ rel
->r_offset
, relocation
,
8501 split16d_type
, htab
->params
->vle_reloc_fixup
);
8504 case R_PPC_VLE_HA16A
:
8505 relocation
= (relocation
+ addend
+ 0x8000) >> 16;
8506 ppc_elf_vle_split16 (input_bfd
, input_section
, rel
->r_offset
,
8507 contents
+ rel
->r_offset
, relocation
,
8508 split16a_type
, htab
->params
->vle_reloc_fixup
);
8511 case R_PPC_VLE_HA16D
:
8512 relocation
= (relocation
+ addend
+ 0x8000) >> 16;
8513 ppc_elf_vle_split16 (input_bfd
, input_section
, rel
->r_offset
,
8514 contents
+ rel
->r_offset
, relocation
,
8515 split16d_type
, htab
->params
->vle_reloc_fixup
);
8518 /* Relocate against either _SDA_BASE_, _SDA2_BASE_, or 0. */
8519 case R_PPC_EMB_SDA21
:
8520 case R_PPC_VLE_SDA21
:
8521 case R_PPC_EMB_RELSDA
:
8522 case R_PPC_VLE_SDA21_LO
:
8527 struct elf_link_hash_entry
*sda
= NULL
;
8529 if (sec
== NULL
|| sec
->output_section
== NULL
)
8531 unresolved_reloc
= TRUE
;
8535 name
= bfd_section_name (sec
->output_section
);
8536 if (strcmp (name
, ".sdata") == 0
8537 || strcmp (name
, ".sbss") == 0)
8540 sda
= htab
->sdata
[0].sym
;
8542 else if (strcmp (name
, ".sdata2") == 0
8543 || strcmp (name
, ".sbss2") == 0)
8546 sda
= htab
->sdata
[1].sym
;
8548 else if (strcmp (name
, ".PPC.EMB.sdata0") == 0
8549 || strcmp (name
, ".PPC.EMB.sbss0") == 0)
8556 /* xgettext:c-format */
8557 (_("%pB: the target (%s) of a %s relocation is "
8558 "in the wrong output section (%s)"),
8564 bfd_set_error (bfd_error_bad_value
);
8571 if (!is_static_defined (sda
))
8573 unresolved_reloc
= TRUE
;
8576 addend
-= SYM_VAL (sda
);
8579 if (r_type
== R_PPC_EMB_RELSDA
)
8582 /* The PowerPC Embedded Application Binary Interface
8583 version 1.0 insanely chose to specify R_PPC_EMB_SDA21
8584 operating on a 24-bit field at r_offset. GNU as and
8585 GNU ld have always assumed R_PPC_EMB_SDA21 operates on
8586 a 32-bit bit insn at r_offset. Cope with object file
8587 producers that possibly comply with the EABI in
8588 generating an odd r_offset for big-endian objects. */
8589 if (r_type
== R_PPC_EMB_SDA21
)
8590 rel
->r_offset
&= ~1;
8592 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
8594 && (r_type
== R_PPC_VLE_SDA21
8595 || r_type
== R_PPC_VLE_SDA21_LO
))
8597 relocation
= relocation
+ addend
;
8600 /* Force e_li insn, keeping RT from original insn. */
8604 /* We have an li20 field, bits 17..20, 11..15, 21..31. */
8605 /* Top 4 bits of value to 17..20. */
8606 insn
|= (relocation
& 0xf0000) >> 5;
8607 /* Next 5 bits of the value to 11..15. */
8608 insn
|= (relocation
& 0xf800) << 5;
8609 /* And the final 11 bits of the value to bits 21 to 31. */
8610 insn
|= relocation
& 0x7ff;
8612 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
8614 if (r_type
== R_PPC_VLE_SDA21
8615 && ((relocation
+ 0x80000) & 0xffffffff) > 0x100000)
8619 /* Fill in register field. */
8620 insn
= (insn
& ~RA_REGISTER_MASK
) | (reg
<< RA_REGISTER_SHIFT
);
8621 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
8625 case R_PPC_VLE_SDAREL_LO16A
:
8626 case R_PPC_VLE_SDAREL_LO16D
:
8627 case R_PPC_VLE_SDAREL_HI16A
:
8628 case R_PPC_VLE_SDAREL_HI16D
:
8629 case R_PPC_VLE_SDAREL_HA16A
:
8630 case R_PPC_VLE_SDAREL_HA16D
:
8634 struct elf_link_hash_entry
*sda
= NULL
;
8636 if (sec
== NULL
|| sec
->output_section
== NULL
)
8638 unresolved_reloc
= TRUE
;
8642 name
= bfd_section_name (sec
->output_section
);
8643 if (strcmp (name
, ".sdata") == 0
8644 || strcmp (name
, ".sbss") == 0)
8645 sda
= htab
->sdata
[0].sym
;
8646 else if (strcmp (name
, ".sdata2") == 0
8647 || strcmp (name
, ".sbss2") == 0)
8648 sda
= htab
->sdata
[1].sym
;
8652 /* xgettext:c-format */
8653 (_("%pB: the target (%s) of a %s relocation is "
8654 "in the wrong output section (%s)"),
8660 bfd_set_error (bfd_error_bad_value
);
8665 if (sda
== NULL
|| !is_static_defined (sda
))
8667 unresolved_reloc
= TRUE
;
8670 value
= relocation
+ addend
- SYM_VAL (sda
);
8672 if (r_type
== R_PPC_VLE_SDAREL_LO16A
)
8673 ppc_elf_vle_split16 (input_bfd
, input_section
, rel
->r_offset
,
8674 contents
+ rel
->r_offset
, value
,
8676 htab
->params
->vle_reloc_fixup
);
8677 else if (r_type
== R_PPC_VLE_SDAREL_LO16D
)
8678 ppc_elf_vle_split16 (input_bfd
, input_section
, rel
->r_offset
,
8679 contents
+ rel
->r_offset
, value
,
8681 htab
->params
->vle_reloc_fixup
);
8682 else if (r_type
== R_PPC_VLE_SDAREL_HI16A
)
8684 value
= value
>> 16;
8685 ppc_elf_vle_split16 (input_bfd
, input_section
, rel
->r_offset
,
8686 contents
+ rel
->r_offset
, value
,
8688 htab
->params
->vle_reloc_fixup
);
8690 else if (r_type
== R_PPC_VLE_SDAREL_HI16D
)
8692 value
= value
>> 16;
8693 ppc_elf_vle_split16 (input_bfd
, input_section
, rel
->r_offset
,
8694 contents
+ rel
->r_offset
, value
,
8696 htab
->params
->vle_reloc_fixup
);
8698 else if (r_type
== R_PPC_VLE_SDAREL_HA16A
)
8700 value
= (value
+ 0x8000) >> 16;
8701 ppc_elf_vle_split16 (input_bfd
, input_section
, rel
->r_offset
,
8702 contents
+ rel
->r_offset
, value
,
8704 htab
->params
->vle_reloc_fixup
);
8706 else if (r_type
== R_PPC_VLE_SDAREL_HA16D
)
8708 value
= (value
+ 0x8000) >> 16;
8709 ppc_elf_vle_split16 (input_bfd
, input_section
, rel
->r_offset
,
8710 contents
+ rel
->r_offset
, value
,
8712 htab
->params
->vle_reloc_fixup
);
8717 case R_PPC_VLE_ADDR20
:
8718 ppc_elf_vle_split20 (output_bfd
, contents
+ rel
->r_offset
, relocation
);
8721 /* Relocate against the beginning of the section. */
8723 case R_PPC_SECTOFF_LO
:
8724 case R_PPC_SECTOFF_HI
:
8725 case R_PPC_SECTOFF_HA
:
8726 if (sec
== NULL
|| sec
->output_section
== NULL
)
8728 unresolved_reloc
= TRUE
;
8731 addend
-= sec
->output_section
->vma
;
8734 /* Negative relocations. */
8735 case R_PPC_EMB_NADDR32
:
8736 case R_PPC_EMB_NADDR16
:
8737 case R_PPC_EMB_NADDR16_LO
:
8738 case R_PPC_EMB_NADDR16_HI
:
8739 case R_PPC_EMB_NADDR16_HA
:
8740 addend
-= 2 * relocation
;
8744 case R_PPC_GLOB_DAT
:
8745 case R_PPC_JMP_SLOT
:
8746 case R_PPC_RELATIVE
:
8747 case R_PPC_IRELATIVE
:
8749 case R_PPC_PLTREL32
:
8751 case R_PPC_EMB_RELSEC16
:
8752 case R_PPC_EMB_RELST_LO
:
8753 case R_PPC_EMB_RELST_HI
:
8754 case R_PPC_EMB_RELST_HA
:
8755 case R_PPC_EMB_BIT_FLD
:
8756 /* xgettext:c-format */
8757 _bfd_error_handler (_("%pB: %s unsupported"),
8758 input_bfd
, howto
->name
);
8760 bfd_set_error (bfd_error_invalid_operation
);
8770 case R_PPC_TPREL16_HA
:
8771 if (htab
->do_tls_opt
&& relocation
+ addend
+ 0x8000 < 0x10000)
8773 bfd_byte
*p
= contents
+ (rel
->r_offset
& ~3);
8774 bfd_put_32 (input_bfd
, NOP
, p
);
8778 case R_PPC_TPREL16_LO
:
8779 if (htab
->do_tls_opt
&& relocation
+ addend
+ 0x8000 < 0x10000)
8781 bfd_byte
*p
= contents
+ (rel
->r_offset
& ~3);
8782 unsigned int insn
= bfd_get_32 (input_bfd
, p
);
8783 insn
&= ~(0x1f << 16);
8785 bfd_put_32 (input_bfd
, insn
, p
);
8796 if (unresolved_reloc
)
8798 bfd_byte
*p
= contents
+ rel
->r_offset
;
8799 unsigned int insn
= bfd_get_32 (input_bfd
, p
);
8801 bfd_put_32 (input_bfd
, B
| insn
, p
);
8802 unresolved_reloc
= save_unresolved_reloc
;
8803 r_type
= R_PPC_REL24
;
8804 howto
= ppc_elf_howto_table
[r_type
];
8806 else if (htab
->plt_type
!= PLT_NEW
)
8807 info
->callbacks
->einfo
8808 (_("%X%P: %H: %s relocation unsupported for bss-plt\n"),
8809 input_bfd
, input_section
, rel
->r_offset
,
8814 case R_PPC_PLT16_HA
:
8815 case R_PPC_PLT16_LO
:
8816 if (unresolved_reloc
)
8818 bfd_byte
*p
= contents
+ (rel
->r_offset
& ~3);
8819 bfd_put_32 (input_bfd
, NOP
, p
);
8820 unresolved_reloc
= FALSE
;
8821 r_type
= R_PPC_NONE
;
8822 howto
= ppc_elf_howto_table
[r_type
];
8824 else if (htab
->plt_type
!= PLT_NEW
)
8825 info
->callbacks
->einfo
8826 (_("%X%P: %H: %s relocation unsupported for bss-plt\n"),
8827 input_bfd
, input_section
, rel
->r_offset
,
8832 /* Do any further special processing. */
8838 case R_PPC_ADDR16_HA
:
8839 case R_PPC_REL16_HA
:
8840 case R_PPC_REL16DX_HA
:
8841 case R_PPC_SECTOFF_HA
:
8842 case R_PPC_TPREL16_HA
:
8843 case R_PPC_DTPREL16_HA
:
8844 case R_PPC_EMB_NADDR16_HA
:
8845 case R_PPC_EMB_RELST_HA
:
8846 /* It's just possible that this symbol is a weak symbol
8847 that's not actually defined anywhere. In that case,
8848 'sec' would be NULL, and we should leave the symbol
8849 alone (it will be set to zero elsewhere in the link). */
8854 case R_PPC_PLT16_HA
:
8855 case R_PPC_GOT16_HA
:
8856 case R_PPC_GOT_TLSGD16_HA
:
8857 case R_PPC_GOT_TLSLD16_HA
:
8858 case R_PPC_GOT_TPREL16_HA
:
8859 case R_PPC_GOT_DTPREL16_HA
:
8860 /* Add 0x10000 if sign bit in 0:15 is set.
8861 Bits 0:15 are not used. */
8866 case R_PPC_ADDR16_LO
:
8868 case R_PPC_GOT16_LO
:
8869 case R_PPC_SDAREL16
:
8871 case R_PPC_SECTOFF_LO
:
8872 case R_PPC_DTPREL16
:
8873 case R_PPC_DTPREL16_LO
:
8875 case R_PPC_TPREL16_LO
:
8876 case R_PPC_GOT_TLSGD16
:
8877 case R_PPC_GOT_TLSGD16_LO
:
8878 case R_PPC_GOT_TLSLD16
:
8879 case R_PPC_GOT_TLSLD16_LO
:
8880 case R_PPC_GOT_DTPREL16
:
8881 case R_PPC_GOT_DTPREL16_LO
:
8882 case R_PPC_GOT_TPREL16
:
8883 case R_PPC_GOT_TPREL16_LO
:
8885 /* The 32-bit ABI lacks proper relocations to deal with
8886 certain 64-bit instructions. Prevent damage to bits
8887 that make up part of the insn opcode. */
8888 unsigned int insn
, mask
, lobit
;
8890 insn
= bfd_get_32 (input_bfd
,
8891 contents
+ rel
->r_offset
- d_offset
);
8893 if (is_insn_ds_form (insn
))
8895 else if (is_insn_dq_form (insn
))
8899 relocation
+= addend
;
8900 addend
= insn
& mask
;
8901 lobit
= mask
& relocation
;
8904 relocation
^= lobit
;
8905 info
->callbacks
->einfo
8906 /* xgettext:c-format */
8907 (_("%H: error: %s against `%s' not a multiple of %u\n"),
8908 input_bfd
, input_section
, rel
->r_offset
,
8909 howto
->name
, sym_name
, mask
+ 1);
8910 bfd_set_error (bfd_error_bad_value
);
8918 fprintf (stderr
, "\ttype = %s (%d), name = %s, symbol index = %ld, "
8919 "offset = %ld, addend = %ld\n",
8924 (long) rel
->r_offset
,
8928 if (unresolved_reloc
8929 && !((input_section
->flags
& SEC_DEBUGGING
) != 0
8931 && _bfd_elf_section_offset (output_bfd
, info
, input_section
,
8932 rel
->r_offset
) != (bfd_vma
) -1)
8934 info
->callbacks
->einfo
8935 /* xgettext:c-format */
8936 (_("%H: unresolvable %s relocation against symbol `%s'\n"),
8937 input_bfd
, input_section
, rel
->r_offset
,
8943 /* 16-bit fields in insns mostly have signed values, but a
8944 few insns have 16-bit unsigned values. Really, we should
8945 have different reloc types. */
8946 if (howto
->complain_on_overflow
!= complain_overflow_dont
8947 && howto
->dst_mask
== 0xffff
8948 && (input_section
->flags
& SEC_CODE
) != 0)
8950 enum complain_overflow complain
= complain_overflow_signed
;
8952 if ((elf_section_flags (input_section
) & SHF_PPC_VLE
) == 0)
8956 insn
= bfd_get_32 (input_bfd
, contents
+ (rel
->r_offset
& ~3));
8957 if ((insn
& (0x3fu
<< 26)) == 10u << 26 /* cmpli */)
8958 complain
= complain_overflow_bitfield
;
8959 else if ((insn
& (0x3fu
<< 26)) == 28u << 26 /* andi */
8960 || (insn
& (0x3fu
<< 26)) == 24u << 26 /* ori */
8961 || (insn
& (0x3fu
<< 26)) == 26u << 26 /* xori */)
8962 complain
= complain_overflow_unsigned
;
8964 if (howto
->complain_on_overflow
!= complain
)
8967 alt_howto
.complain_on_overflow
= complain
;
8972 if (r_type
== R_PPC_REL16DX_HA
)
8974 /* Split field reloc isn't handled by _bfd_final_link_relocate. */
8975 if (rel
->r_offset
+ 4 > input_section
->size
)
8976 r
= bfd_reloc_outofrange
;
8981 relocation
+= addend
;
8982 relocation
-= (rel
->r_offset
8983 + input_section
->output_offset
8984 + input_section
->output_section
->vma
);
8986 insn
= bfd_get_32 (input_bfd
, contents
+ rel
->r_offset
);
8988 insn
|= (relocation
& 0xffc1) | ((relocation
& 0x3e) << 15);
8989 bfd_put_32 (input_bfd
, insn
, contents
+ rel
->r_offset
);
8994 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
, contents
,
8995 rel
->r_offset
, relocation
, addend
);
8997 if (r
!= bfd_reloc_ok
)
8999 if (r
== bfd_reloc_overflow
)
9002 /* On code like "if (foo) foo();" don't report overflow
9003 on a branch to zero when foo is undefined. */
9006 && (h
->root
.type
== bfd_link_hash_undefweak
9007 || h
->root
.type
== bfd_link_hash_undefined
)
9008 && is_branch_reloc (r_type
)))
9009 info
->callbacks
->reloc_overflow
9010 (info
, (h
? &h
->root
: NULL
), sym_name
, howto
->name
,
9011 rel
->r_addend
, input_bfd
, input_section
, rel
->r_offset
);
9015 info
->callbacks
->einfo
9016 /* xgettext:c-format */
9017 (_("%H: %s reloc against `%s': error %d\n"),
9018 input_bfd
, input_section
, rel
->r_offset
,
9019 howto
->name
, sym_name
, (int) r
);
9030 Elf_Internal_Shdr
*rel_hdr
;
9031 size_t deleted
= rel
- wrel
;
9033 rel_hdr
= _bfd_elf_single_rel_hdr (input_section
->output_section
);
9034 rel_hdr
->sh_size
-= rel_hdr
->sh_entsize
* deleted
;
9035 if (rel_hdr
->sh_size
== 0)
9037 /* It is too late to remove an empty reloc section. Leave
9039 ??? What is wrong with an empty section??? */
9040 rel_hdr
->sh_size
= rel_hdr
->sh_entsize
;
9045 rel_hdr
= _bfd_elf_single_rel_hdr (input_section
);
9046 rel_hdr
->sh_size
-= rel_hdr
->sh_entsize
* deleted
;
9047 input_section
->reloc_count
-= deleted
;
9051 fprintf (stderr
, "\n");
9054 if (input_section
->sec_info_type
== SEC_INFO_TYPE_TARGET
9055 && input_section
->size
!= input_section
->rawsize
9056 && (strcmp (input_section
->output_section
->name
, ".init") == 0
9057 || strcmp (input_section
->output_section
->name
, ".fini") == 0))
9059 /* Branch around the trampolines. */
9060 unsigned int insn
= B
+ input_section
->size
- input_section
->rawsize
;
9061 bfd_put_32 (input_bfd
, insn
, contents
+ input_section
->rawsize
);
9064 if (htab
->params
->ppc476_workaround
9065 && input_section
->sec_info_type
== SEC_INFO_TYPE_TARGET
9066 && (!bfd_link_relocatable (info
)
9067 || (input_section
->output_section
->alignment_power
9068 >= htab
->params
->pagesize_p2
)))
9070 bfd_vma start_addr
, end_addr
, addr
;
9071 bfd_vma pagesize
= (bfd_vma
) 1 << htab
->params
->pagesize_p2
;
9073 if (relax_info
->workaround_size
!= 0)
9079 bfd_put_32 (input_bfd
, BA
, fill
);
9080 p
= contents
+ input_section
->size
- relax_info
->workaround_size
;
9081 n
= relax_info
->workaround_size
>> 2;
9084 memcpy (p
, fill
, 4);
9089 /* The idea is: Replace the last instruction on a page with a
9090 branch to a patch area. Put the insn there followed by a
9091 branch back to the next page. Complicated a little by
9092 needing to handle moved conditional branches, and by not
9093 wanting to touch data-in-text. */
9095 start_addr
= (input_section
->output_section
->vma
9096 + input_section
->output_offset
);
9097 end_addr
= (start_addr
+ input_section
->size
9098 - relax_info
->workaround_size
);
9099 for (addr
= ((start_addr
& -pagesize
) + pagesize
- 4);
9103 bfd_vma offset
= addr
- start_addr
;
9104 Elf_Internal_Rela
*lo
, *hi
;
9105 bfd_boolean is_data
;
9106 bfd_vma patch_off
, patch_addr
;
9109 /* Do we have a data reloc at this offset? If so, leave
9117 rel
= lo
+ (hi
- lo
) / 2;
9118 if (rel
->r_offset
< offset
)
9120 else if (rel
->r_offset
> offset
+ 3)
9124 switch (ELF32_R_TYPE (rel
->r_info
))
9141 /* Some instructions can be left alone too. Unconditional
9142 branches, except for bcctr with BO=0x14 (bctr, bctrl),
9143 avoid the icache failure.
9145 The problem occurs due to prefetch across a page boundary
9146 where stale instructions can be fetched from the next
9147 page, and the mechanism for flushing these bad
9148 instructions fails under certain circumstances. The
9149 unconditional branches:
9150 1) Branch: b, bl, ba, bla,
9151 2) Branch Conditional: bc, bca, bcl, bcla,
9152 3) Branch Conditional to Link Register: bclr, bclrl,
9153 where (2) and (3) have BO=0x14 making them unconditional,
9154 prevent the bad prefetch because the prefetch itself is
9155 affected by these instructions. This happens even if the
9156 instruction is not executed.
9161 . addi 9,9,new_page@l
9168 The bctr is not predicted taken due to ctr not being
9169 ready, so prefetch continues on past the bctr into the
9170 new page which might have stale instructions. If they
9171 fail to be flushed, then they will be executed after the
9172 bctr executes. Either of the following modifications
9173 prevent the bad prefetch from happening in the first
9176 . lis 9,new_page@ha lis 9,new_page@ha
9177 . addi 9,9,new_page@l addi 9,9,new_page@l
9180 . nop b somewhere_else
9181 . b somewhere_else nop
9182 . new_page: new_page:
9184 insn
= bfd_get_32 (input_bfd
, contents
+ offset
);
9185 if ((insn
& (0x3fu
<< 26)) == (18u << 26) /* b,bl,ba,bla */
9186 || ((insn
& (0x3fu
<< 26)) == (16u << 26) /* bc,bcl,bca,bcla*/
9187 && (insn
& (0x14 << 21)) == (0x14 << 21)) /* with BO=0x14 */
9188 || ((insn
& (0x3fu
<< 26)) == (19u << 26)
9189 && (insn
& (0x3ff << 1)) == (16u << 1) /* bclr,bclrl */
9190 && (insn
& (0x14 << 21)) == (0x14 << 21)))/* with BO=0x14 */
9193 patch_addr
= (start_addr
+ input_section
->size
9194 - relax_info
->workaround_size
);
9195 patch_addr
= (patch_addr
+ 15) & -16;
9196 patch_off
= patch_addr
- start_addr
;
9197 bfd_put_32 (input_bfd
, B
+ patch_off
- offset
, contents
+ offset
);
9200 && rel
->r_offset
>= offset
9201 && rel
->r_offset
< offset
+ 4)
9205 /* If the insn we are patching had a reloc, adjust the
9206 reloc r_offset so that the reloc applies to the moved
9207 location. This matters for -r and --emit-relocs. */
9208 if (rel
+ 1 != relend
)
9210 Elf_Internal_Rela tmp
= *rel
;
9212 /* Keep the relocs sorted by r_offset. */
9213 memmove (rel
, rel
+ 1, (relend
- (rel
+ 1)) * sizeof (*rel
));
9216 relend
[-1].r_offset
+= patch_off
- offset
;
9218 /* Adjust REL16 addends too. */
9219 switch (ELF32_R_TYPE (relend
[-1].r_info
))
9222 case R_PPC_REL16_LO
:
9223 case R_PPC_REL16_HI
:
9224 case R_PPC_REL16_HA
:
9225 relend
[-1].r_addend
+= patch_off
- offset
;
9231 /* If we are building a PIE or shared library with
9232 non-PIC objects, perhaps we had a dynamic reloc too?
9233 If so, the dynamic reloc must move with the insn. */
9234 sreloc
= elf_section_data (input_section
)->sreloc
;
9237 Elf32_External_Rela
*slo
, *shi
, *srelend
;
9240 slo
= (Elf32_External_Rela
*) sreloc
->contents
;
9241 shi
= srelend
= slo
+ sreloc
->reloc_count
;
9242 soffset
= (offset
+ input_section
->output_section
->vma
9243 + input_section
->output_offset
);
9246 Elf32_External_Rela
*srel
= slo
+ (shi
- slo
) / 2;
9247 bfd_elf32_swap_reloca_in (output_bfd
, (bfd_byte
*) srel
,
9249 if (outrel
.r_offset
< soffset
)
9251 else if (outrel
.r_offset
> soffset
+ 3)
9255 if (srel
+ 1 != srelend
)
9257 memmove (srel
, srel
+ 1,
9258 (srelend
- (srel
+ 1)) * sizeof (*srel
));
9261 outrel
.r_offset
+= patch_off
- offset
;
9262 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
,
9272 if ((insn
& (0x3fu
<< 26)) == (16u << 26) /* bc */
9273 && (insn
& 2) == 0 /* relative */)
9275 bfd_vma delta
= ((insn
& 0xfffc) ^ 0x8000) - 0x8000;
9277 delta
+= offset
- patch_off
;
9278 if (bfd_link_relocatable (info
) && rel
!= NULL
)
9280 if (!bfd_link_relocatable (info
) && rel
!= NULL
)
9282 enum elf_ppc_reloc_type r_type
;
9284 r_type
= ELF32_R_TYPE (relend
[-1].r_info
);
9285 if (r_type
== R_PPC_REL14_BRTAKEN
)
9286 insn
|= BRANCH_PREDICT_BIT
;
9287 else if (r_type
== R_PPC_REL14_BRNTAKEN
)
9288 insn
&= ~BRANCH_PREDICT_BIT
;
9290 BFD_ASSERT (r_type
== R_PPC_REL14
);
9292 if ((r_type
== R_PPC_REL14_BRTAKEN
9293 || r_type
== R_PPC_REL14_BRNTAKEN
)
9294 && delta
+ 0x8000 < 0x10000
9295 && (bfd_signed_vma
) delta
< 0)
9296 insn
^= BRANCH_PREDICT_BIT
;
9298 if (delta
+ 0x8000 < 0x10000)
9300 bfd_put_32 (input_bfd
,
9301 (insn
& ~0xfffc) | (delta
& 0xfffc),
9302 contents
+ patch_off
);
9304 bfd_put_32 (input_bfd
,
9305 B
| ((offset
+ 4 - patch_off
) & 0x3fffffc),
9306 contents
+ patch_off
);
9313 unsigned int r_sym
= ELF32_R_SYM (relend
[-1].r_info
);
9315 relend
[-1].r_offset
+= 8;
9316 relend
[-1].r_info
= ELF32_R_INFO (r_sym
, R_PPC_REL24
);
9318 bfd_put_32 (input_bfd
,
9319 (insn
& ~0xfffc) | 8,
9320 contents
+ patch_off
);
9322 bfd_put_32 (input_bfd
,
9323 B
| ((offset
+ 4 - patch_off
) & 0x3fffffc),
9324 contents
+ patch_off
);
9326 bfd_put_32 (input_bfd
,
9327 B
| ((delta
- 8) & 0x3fffffc),
9328 contents
+ patch_off
);
9334 bfd_put_32 (input_bfd
, insn
, contents
+ patch_off
);
9336 bfd_put_32 (input_bfd
,
9337 B
| ((offset
+ 4 - patch_off
) & 0x3fffffc),
9338 contents
+ patch_off
);
9341 BFD_ASSERT (patch_off
<= input_section
->size
);
9342 relax_info
->workaround_size
= input_section
->size
- patch_off
;
9349 /* Write out the PLT relocs and entries for H. */
9352 write_global_sym_plt (struct elf_link_hash_entry
*h
, void *inf
)
9354 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
9355 struct ppc_elf_link_hash_table
*htab
= ppc_elf_hash_table (info
);
9356 struct plt_entry
*ent
;
9357 bfd_boolean doneone
;
9360 for (ent
= h
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
9361 if (ent
->plt
.offset
!= (bfd_vma
) -1)
9363 bfd_boolean dyn
= !use_local_plt (info
, h
);
9367 Elf_Internal_Rela rela
;
9369 bfd_vma reloc_index
;
9370 asection
*plt
= htab
->elf
.splt
;
9371 asection
*relplt
= htab
->elf
.srelplt
;
9373 if (htab
->plt_type
== PLT_NEW
|| !dyn
)
9374 reloc_index
= ent
->plt
.offset
/ 4;
9377 reloc_index
= ((ent
->plt
.offset
- htab
->plt_initial_entry_size
)
9378 / htab
->plt_slot_size
);
9379 if (reloc_index
> PLT_NUM_SINGLE_ENTRIES
9380 && htab
->plt_type
== PLT_OLD
)
9381 reloc_index
-= (reloc_index
- PLT_NUM_SINGLE_ENTRIES
) / 2;
9384 /* This symbol has an entry in the procedure linkage table.
9386 if (htab
->plt_type
== PLT_VXWORKS
&& dyn
)
9389 const bfd_vma
*plt_entry
;
9391 /* The first three entries in .got.plt are reserved. */
9392 got_offset
= (reloc_index
+ 3) * 4;
9394 /* Use the right PLT. */
9395 plt_entry
= bfd_link_pic (info
) ? ppc_elf_vxworks_pic_plt_entry
9396 : ppc_elf_vxworks_plt_entry
;
9398 /* Fill in the .plt on VxWorks. */
9399 if (bfd_link_pic (info
))
9401 bfd_put_32 (info
->output_bfd
,
9402 plt_entry
[0] | PPC_HA (got_offset
),
9403 plt
->contents
+ ent
->plt
.offset
+ 0);
9404 bfd_put_32 (info
->output_bfd
,
9405 plt_entry
[1] | PPC_LO (got_offset
),
9406 plt
->contents
+ ent
->plt
.offset
+ 4);
9410 bfd_vma got_loc
= got_offset
+ SYM_VAL (htab
->elf
.hgot
);
9412 bfd_put_32 (info
->output_bfd
,
9413 plt_entry
[0] | PPC_HA (got_loc
),
9414 plt
->contents
+ ent
->plt
.offset
+ 0);
9415 bfd_put_32 (info
->output_bfd
,
9416 plt_entry
[1] | PPC_LO (got_loc
),
9417 plt
->contents
+ ent
->plt
.offset
+ 4);
9420 bfd_put_32 (info
->output_bfd
, plt_entry
[2],
9421 plt
->contents
+ ent
->plt
.offset
+ 8);
9422 bfd_put_32 (info
->output_bfd
, plt_entry
[3],
9423 plt
->contents
+ ent
->plt
.offset
+ 12);
9425 /* This instruction is an immediate load. The value loaded is
9426 the byte offset of the R_PPC_JMP_SLOT relocation from the
9427 start of the .rela.plt section. The value is stored in the
9428 low-order 16 bits of the load instruction. */
9429 /* NOTE: It appears that this is now an index rather than a
9430 prescaled offset. */
9431 bfd_put_32 (info
->output_bfd
,
9432 plt_entry
[4] | reloc_index
,
9433 plt
->contents
+ ent
->plt
.offset
+ 16);
9434 /* This instruction is a PC-relative branch whose target is
9435 the start of the PLT section. The address of this branch
9436 instruction is 20 bytes beyond the start of this PLT entry.
9437 The address is encoded in bits 6-29, inclusive. The value
9438 stored is right-shifted by two bits, permitting a 26-bit
9440 bfd_put_32 (info
->output_bfd
,
9442 | (-(ent
->plt
.offset
+ 20) & 0x03fffffc)),
9443 plt
->contents
+ ent
->plt
.offset
+ 20);
9444 bfd_put_32 (info
->output_bfd
, plt_entry
[6],
9445 plt
->contents
+ ent
->plt
.offset
+ 24);
9446 bfd_put_32 (info
->output_bfd
, plt_entry
[7],
9447 plt
->contents
+ ent
->plt
.offset
+ 28);
9449 /* Fill in the GOT entry corresponding to this PLT slot with
9450 the address immediately after the "bctr" instruction
9451 in this PLT entry. */
9452 bfd_put_32 (info
->output_bfd
, (plt
->output_section
->vma
9453 + plt
->output_offset
9454 + ent
->plt
.offset
+ 16),
9455 htab
->elf
.sgotplt
->contents
+ got_offset
);
9457 if (!bfd_link_pic (info
))
9459 /* Fill in a couple of entries in .rela.plt.unloaded. */
9460 loc
= htab
->srelplt2
->contents
9461 + ((VXWORKS_PLTRESOLVE_RELOCS
+ reloc_index
9462 * VXWORKS_PLT_NON_JMP_SLOT_RELOCS
)
9463 * sizeof (Elf32_External_Rela
));
9465 /* Provide the @ha relocation for the first instruction. */
9466 rela
.r_offset
= (plt
->output_section
->vma
9467 + plt
->output_offset
9468 + ent
->plt
.offset
+ 2);
9469 rela
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
,
9471 rela
.r_addend
= got_offset
;
9472 bfd_elf32_swap_reloca_out (info
->output_bfd
, &rela
, loc
);
9473 loc
+= sizeof (Elf32_External_Rela
);
9475 /* Provide the @l relocation for the second instruction. */
9476 rela
.r_offset
= (plt
->output_section
->vma
9477 + plt
->output_offset
9478 + ent
->plt
.offset
+ 6);
9479 rela
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
,
9481 rela
.r_addend
= got_offset
;
9482 bfd_elf32_swap_reloca_out (info
->output_bfd
, &rela
, loc
);
9483 loc
+= sizeof (Elf32_External_Rela
);
9485 /* Provide a relocation for the GOT entry corresponding to this
9486 PLT slot. Point it at the middle of the .plt entry. */
9487 rela
.r_offset
= (htab
->elf
.sgotplt
->output_section
->vma
9488 + htab
->elf
.sgotplt
->output_offset
9490 rela
.r_info
= ELF32_R_INFO (htab
->elf
.hplt
->indx
,
9492 rela
.r_addend
= ent
->plt
.offset
+ 16;
9493 bfd_elf32_swap_reloca_out (info
->output_bfd
, &rela
, loc
);
9496 /* VxWorks uses non-standard semantics for R_PPC_JMP_SLOT.
9497 In particular, the offset for the relocation is not the
9498 address of the PLT entry for this function, as specified
9499 by the ABI. Instead, the offset is set to the address of
9500 the GOT slot for this function. See EABI 4.4.4.1. */
9501 rela
.r_offset
= (htab
->elf
.sgotplt
->output_section
->vma
9502 + htab
->elf
.sgotplt
->output_offset
9511 if (h
->type
== STT_GNU_IFUNC
)
9513 plt
= htab
->elf
.iplt
;
9514 relplt
= htab
->elf
.irelplt
;
9518 plt
= htab
->pltlocal
;
9519 relplt
= bfd_link_pic (info
) ? htab
->relpltlocal
: NULL
;
9522 && (h
->root
.type
== bfd_link_hash_defined
9523 || h
->root
.type
== bfd_link_hash_defweak
))
9524 rela
.r_addend
= SYM_VAL (h
);
9529 loc
= plt
->contents
+ ent
->plt
.offset
;
9530 bfd_put_32 (info
->output_bfd
, rela
.r_addend
, loc
);
9534 rela
.r_offset
= (plt
->output_section
->vma
9535 + plt
->output_offset
9538 if (htab
->plt_type
== PLT_OLD
|| !dyn
)
9540 /* We don't need to fill in the .plt. The ppc dynamic
9541 linker will fill it in. */
9545 bfd_vma val
= (htab
->glink_pltresolve
+ ent
->plt
.offset
9546 + htab
->glink
->output_section
->vma
9547 + htab
->glink
->output_offset
);
9548 bfd_put_32 (info
->output_bfd
, val
,
9549 plt
->contents
+ ent
->plt
.offset
);
9556 /* Fill in the entry in the .rela.plt section. */
9559 if (h
->type
== STT_GNU_IFUNC
)
9560 rela
.r_info
= ELF32_R_INFO (0, R_PPC_IRELATIVE
);
9562 rela
.r_info
= ELF32_R_INFO (0, R_PPC_RELATIVE
);
9563 loc
= relplt
->contents
+ (relplt
->reloc_count
++
9564 * sizeof (Elf32_External_Rela
));
9565 htab
->local_ifunc_resolver
= 1;
9569 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_PPC_JMP_SLOT
);
9570 loc
= relplt
->contents
+ (reloc_index
9571 * sizeof (Elf32_External_Rela
));
9572 if (h
->type
== STT_GNU_IFUNC
&& is_static_defined (h
))
9573 htab
->maybe_local_ifunc_resolver
= 1;
9575 bfd_elf32_swap_reloca_out (info
->output_bfd
, &rela
, loc
);
9580 if (htab
->plt_type
== PLT_NEW
|| !dyn
)
9583 asection
*plt
= htab
->elf
.splt
;
9587 if (h
->type
== STT_GNU_IFUNC
)
9588 plt
= htab
->elf
.iplt
;
9593 p
= (unsigned char *) htab
->glink
->contents
+ ent
->glink_offset
;
9594 write_glink_stub (h
, ent
, plt
, p
, info
);
9596 if (!bfd_link_pic (info
))
9597 /* We only need one non-PIC glink stub. */
9606 /* Finish up PLT handling. */
9609 ppc_finish_symbols (struct bfd_link_info
*info
)
9611 struct ppc_elf_link_hash_table
*htab
= ppc_elf_hash_table (info
);
9617 elf_link_hash_traverse (&htab
->elf
, write_global_sym_plt
, info
);
9619 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
9621 bfd_vma
*local_got
, *end_local_got
;
9622 struct plt_entry
**local_plt
, **lplt
, **end_local_plt
;
9623 Elf_Internal_Shdr
*symtab_hdr
;
9624 bfd_size_type locsymcount
;
9625 Elf_Internal_Sym
*local_syms
= NULL
;
9626 struct plt_entry
*ent
;
9628 if (!is_ppc_elf (ibfd
))
9631 local_got
= elf_local_got_offsets (ibfd
);
9635 symtab_hdr
= &elf_symtab_hdr (ibfd
);
9636 locsymcount
= symtab_hdr
->sh_info
;
9637 end_local_got
= local_got
+ locsymcount
;
9638 local_plt
= (struct plt_entry
**) end_local_got
;
9639 end_local_plt
= local_plt
+ locsymcount
;
9640 for (lplt
= local_plt
; lplt
< end_local_plt
; ++lplt
)
9641 for (ent
= *lplt
; ent
!= NULL
; ent
= ent
->next
)
9643 if (ent
->plt
.offset
!= (bfd_vma
) -1)
9645 Elf_Internal_Sym
*sym
;
9647 asection
*plt
, *relplt
;
9650 Elf_Internal_Rela rela
;
9653 if (!get_sym_h (NULL
, &sym
, &sym_sec
, NULL
, &local_syms
,
9654 lplt
- local_plt
, ibfd
))
9656 if (symtab_hdr
->contents
!= (unsigned char *) local_syms
)
9661 val
= sym
->st_value
;
9662 if (sym_sec
!= NULL
&& sym_sec
->output_section
!= NULL
)
9663 val
+= sym_sec
->output_offset
+ sym_sec
->output_section
->vma
;
9665 if (ELF_ST_TYPE (sym
->st_info
) == STT_GNU_IFUNC
)
9667 htab
->local_ifunc_resolver
= 1;
9668 plt
= htab
->elf
.iplt
;
9669 relplt
= htab
->elf
.irelplt
;
9670 rela
.r_info
= ELF32_R_INFO (0, R_PPC_IRELATIVE
);
9674 plt
= htab
->pltlocal
;
9675 if (bfd_link_pic (info
))
9677 relplt
= htab
->relpltlocal
;
9678 rela
.r_info
= ELF32_R_INFO (0, R_PPC_RELATIVE
);
9682 loc
= plt
->contents
+ ent
->plt
.offset
;
9683 bfd_put_32 (info
->output_bfd
, val
, loc
);
9688 rela
.r_offset
= (ent
->plt
.offset
9689 + plt
->output_offset
9690 + plt
->output_section
->vma
);
9691 rela
.r_addend
= val
;
9692 loc
= relplt
->contents
+ (relplt
->reloc_count
++
9693 * sizeof (Elf32_External_Rela
));
9694 bfd_elf32_swap_reloca_out (info
->output_bfd
, &rela
, loc
);
9696 p
= (unsigned char *) htab
->glink
->contents
+ ent
->glink_offset
;
9697 write_glink_stub (NULL
, ent
, htab
->elf
.iplt
, p
, info
);
9701 if (local_syms
!= NULL
9702 && symtab_hdr
->contents
!= (unsigned char *) local_syms
)
9704 if (!info
->keep_memory
)
9707 symtab_hdr
->contents
= (unsigned char *) local_syms
;
9713 /* Finish up dynamic symbol handling. We set the contents of various
9714 dynamic sections here. */
9717 ppc_elf_finish_dynamic_symbol (bfd
*output_bfd
,
9718 struct bfd_link_info
*info
,
9719 struct elf_link_hash_entry
*h
,
9720 Elf_Internal_Sym
*sym
)
9722 struct ppc_elf_link_hash_table
*htab
= ppc_elf_hash_table (info
);
9723 struct plt_entry
*ent
;
9726 fprintf (stderr
, "ppc_elf_finish_dynamic_symbol called for %s",
9727 h
->root
.root
.string
);
9731 || (h
->type
== STT_GNU_IFUNC
&& !bfd_link_pic (info
)))
9732 for (ent
= h
->plt
.plist
; ent
!= NULL
; ent
= ent
->next
)
9733 if (ent
->plt
.offset
!= (bfd_vma
) -1)
9735 if (!h
->def_regular
)
9737 /* Mark the symbol as undefined, rather than as
9738 defined in the .plt section. Leave the value if
9739 there were any relocations where pointer equality
9740 matters (this is a clue for the dynamic linker, to
9741 make function pointer comparisons work between an
9742 application and shared library), otherwise set it
9744 sym
->st_shndx
= SHN_UNDEF
;
9745 if (!h
->pointer_equality_needed
)
9747 else if (!h
->ref_regular_nonweak
)
9749 /* This breaks function pointer comparisons, but
9750 that is better than breaking tests for a NULL
9751 function pointer. */
9757 /* Set the value of ifunc symbols in a non-pie
9758 executable to the glink entry. This is to avoid
9759 text relocations. We can't do this for ifunc in
9760 allocate_dynrelocs, as we do for normal dynamic
9761 function symbols with plt entries, because we need
9762 to keep the original value around for the ifunc
9765 = (_bfd_elf_section_from_bfd_section
9766 (info
->output_bfd
, htab
->glink
->output_section
));
9767 sym
->st_value
= (ent
->glink_offset
9768 + htab
->glink
->output_offset
9769 + htab
->glink
->output_section
->vma
);
9777 Elf_Internal_Rela rela
;
9780 /* This symbols needs a copy reloc. Set it up. */
9783 fprintf (stderr
, ", copy");
9786 BFD_ASSERT (h
->dynindx
!= -1);
9788 if (ppc_elf_hash_entry (h
)->has_sda_refs
)
9790 else if (h
->root
.u
.def
.section
== htab
->elf
.sdynrelro
)
9791 s
= htab
->elf
.sreldynrelro
;
9793 s
= htab
->elf
.srelbss
;
9794 BFD_ASSERT (s
!= NULL
);
9796 rela
.r_offset
= SYM_VAL (h
);
9797 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_PPC_COPY
);
9799 loc
= s
->contents
+ s
->reloc_count
++ * sizeof (Elf32_External_Rela
);
9800 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
9804 fprintf (stderr
, "\n");
9810 static enum elf_reloc_type_class
9811 ppc_elf_reloc_type_class (const struct bfd_link_info
*info
,
9812 const asection
*rel_sec
,
9813 const Elf_Internal_Rela
*rela
)
9815 struct ppc_elf_link_hash_table
*htab
= ppc_elf_hash_table (info
);
9817 if (rel_sec
== htab
->elf
.irelplt
)
9818 return reloc_class_ifunc
;
9820 switch (ELF32_R_TYPE (rela
->r_info
))
9822 case R_PPC_RELATIVE
:
9823 return reloc_class_relative
;
9824 case R_PPC_JMP_SLOT
:
9825 return reloc_class_plt
;
9827 return reloc_class_copy
;
9829 return reloc_class_normal
;
9833 /* Finish up the dynamic sections. */
9836 ppc_elf_finish_dynamic_sections (bfd
*output_bfd
,
9837 struct bfd_link_info
*info
)
9840 struct ppc_elf_link_hash_table
*htab
;
9843 bfd_boolean ret
= TRUE
;
9846 fprintf (stderr
, "ppc_elf_finish_dynamic_sections called\n");
9849 htab
= ppc_elf_hash_table (info
);
9850 dynobj
= htab
->elf
.dynobj
;
9851 sdyn
= bfd_get_linker_section (dynobj
, ".dynamic");
9854 if (htab
->elf
.hgot
!= NULL
)
9855 got
= SYM_VAL (htab
->elf
.hgot
);
9857 if (htab
->elf
.dynamic_sections_created
)
9859 Elf32_External_Dyn
*dyncon
, *dynconend
;
9861 BFD_ASSERT (htab
->elf
.splt
!= NULL
&& sdyn
!= NULL
);
9863 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
9864 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->size
);
9865 for (; dyncon
< dynconend
; dyncon
++)
9867 Elf_Internal_Dyn dyn
;
9870 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
9875 if (htab
->elf
.target_os
== is_vxworks
)
9876 s
= htab
->elf
.sgotplt
;
9879 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
9883 dyn
.d_un
.d_val
= htab
->elf
.srelplt
->size
;
9887 s
= htab
->elf
.srelplt
;
9888 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
9892 dyn
.d_un
.d_ptr
= got
;
9896 if (htab
->local_ifunc_resolver
)
9897 info
->callbacks
->einfo
9898 (_("%X%P: text relocations and GNU indirect "
9899 "functions will result in a segfault at runtime\n"));
9900 else if (htab
->maybe_local_ifunc_resolver
)
9901 info
->callbacks
->einfo
9902 (_("%P: warning: text relocations and GNU indirect "
9903 "functions may result in a segfault at runtime\n"));
9907 if (htab
->elf
.target_os
== is_vxworks
9908 && elf_vxworks_finish_dynamic_entry (output_bfd
, &dyn
))
9913 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
9917 if (htab
->elf
.sgot
!= NULL
9918 && htab
->elf
.sgot
->output_section
!= bfd_abs_section_ptr
)
9920 if (htab
->elf
.hgot
->root
.u
.def
.section
== htab
->elf
.sgot
9921 || htab
->elf
.hgot
->root
.u
.def
.section
== htab
->elf
.sgotplt
)
9923 unsigned char *p
= htab
->elf
.hgot
->root
.u
.def
.section
->contents
;
9925 p
+= htab
->elf
.hgot
->root
.u
.def
.value
;
9926 if (htab
->plt_type
== PLT_OLD
)
9928 /* Add a blrl instruction at _GLOBAL_OFFSET_TABLE_-4
9929 so that a function can easily find the address of
9930 _GLOBAL_OFFSET_TABLE_. */
9931 BFD_ASSERT (htab
->elf
.hgot
->root
.u
.def
.value
- 4
9932 < htab
->elf
.hgot
->root
.u
.def
.section
->size
);
9933 bfd_put_32 (output_bfd
, 0x4e800021, p
- 4);
9938 bfd_vma val
= sdyn
->output_section
->vma
+ sdyn
->output_offset
;
9939 BFD_ASSERT (htab
->elf
.hgot
->root
.u
.def
.value
9940 < htab
->elf
.hgot
->root
.u
.def
.section
->size
);
9941 bfd_put_32 (output_bfd
, val
, p
);
9946 /* xgettext:c-format */
9947 _bfd_error_handler (_("%s not defined in linker created %pA"),
9948 htab
->elf
.hgot
->root
.root
.string
,
9949 (htab
->elf
.sgotplt
!= NULL
9950 ? htab
->elf
.sgotplt
: htab
->elf
.sgot
));
9951 bfd_set_error (bfd_error_bad_value
);
9955 elf_section_data (htab
->elf
.sgot
->output_section
)->this_hdr
.sh_entsize
= 4;
9958 /* Fill in the first entry in the VxWorks procedure linkage table. */
9959 if (htab
->elf
.target_os
== is_vxworks
9960 && htab
->elf
.splt
!= NULL
9961 && htab
->elf
.splt
->size
!= 0
9962 && htab
->elf
.splt
->output_section
!= bfd_abs_section_ptr
)
9964 asection
*splt
= htab
->elf
.splt
;
9965 /* Use the right PLT. */
9966 const bfd_vma
*plt_entry
= (bfd_link_pic (info
)
9967 ? ppc_elf_vxworks_pic_plt0_entry
9968 : ppc_elf_vxworks_plt0_entry
);
9970 if (!bfd_link_pic (info
))
9972 bfd_vma got_value
= SYM_VAL (htab
->elf
.hgot
);
9974 bfd_put_32 (output_bfd
, plt_entry
[0] | PPC_HA (got_value
),
9975 splt
->contents
+ 0);
9976 bfd_put_32 (output_bfd
, plt_entry
[1] | PPC_LO (got_value
),
9977 splt
->contents
+ 4);
9981 bfd_put_32 (output_bfd
, plt_entry
[0], splt
->contents
+ 0);
9982 bfd_put_32 (output_bfd
, plt_entry
[1], splt
->contents
+ 4);
9984 bfd_put_32 (output_bfd
, plt_entry
[2], splt
->contents
+ 8);
9985 bfd_put_32 (output_bfd
, plt_entry
[3], splt
->contents
+ 12);
9986 bfd_put_32 (output_bfd
, plt_entry
[4], splt
->contents
+ 16);
9987 bfd_put_32 (output_bfd
, plt_entry
[5], splt
->contents
+ 20);
9988 bfd_put_32 (output_bfd
, plt_entry
[6], splt
->contents
+ 24);
9989 bfd_put_32 (output_bfd
, plt_entry
[7], splt
->contents
+ 28);
9991 if (! bfd_link_pic (info
))
9993 Elf_Internal_Rela rela
;
9996 loc
= htab
->srelplt2
->contents
;
9998 /* Output the @ha relocation for the first instruction. */
9999 rela
.r_offset
= (htab
->elf
.splt
->output_section
->vma
10000 + htab
->elf
.splt
->output_offset
10002 rela
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
, R_PPC_ADDR16_HA
);
10004 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
10005 loc
+= sizeof (Elf32_External_Rela
);
10007 /* Output the @l relocation for the second instruction. */
10008 rela
.r_offset
= (htab
->elf
.splt
->output_section
->vma
10009 + htab
->elf
.splt
->output_offset
10011 rela
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
, R_PPC_ADDR16_LO
);
10013 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
10014 loc
+= sizeof (Elf32_External_Rela
);
10016 /* Fix up the remaining relocations. They may have the wrong
10017 symbol index for _G_O_T_ or _P_L_T_ depending on the order
10018 in which symbols were output. */
10019 while (loc
< htab
->srelplt2
->contents
+ htab
->srelplt2
->size
)
10021 Elf_Internal_Rela rel
;
10023 bfd_elf32_swap_reloc_in (output_bfd
, loc
, &rel
);
10024 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
, R_PPC_ADDR16_HA
);
10025 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
10026 loc
+= sizeof (Elf32_External_Rela
);
10028 bfd_elf32_swap_reloc_in (output_bfd
, loc
, &rel
);
10029 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hgot
->indx
, R_PPC_ADDR16_LO
);
10030 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
10031 loc
+= sizeof (Elf32_External_Rela
);
10033 bfd_elf32_swap_reloc_in (output_bfd
, loc
, &rel
);
10034 rel
.r_info
= ELF32_R_INFO (htab
->elf
.hplt
->indx
, R_PPC_ADDR32
);
10035 bfd_elf32_swap_reloc_out (output_bfd
, &rel
, loc
);
10036 loc
+= sizeof (Elf32_External_Rela
);
10041 if (htab
->glink
!= NULL
10042 && htab
->glink
->contents
!= NULL
10043 && htab
->elf
.dynamic_sections_created
)
10046 unsigned char *endp
;
10050 * PIC glink code is the following:
10052 * # ith PLT code stub.
10053 * addis 11,30,(plt+(i-1)*4-got)@ha
10054 * lwz 11,(plt+(i-1)*4-got)@l(11)
10058 * # A table of branches, one for each plt entry.
10059 * # The idea is that the plt call stub loads ctr and r11 with these
10060 * # addresses, so (r11 - res_0) gives the plt index * 4.
10061 * res_0: b PLTresolve
10062 * res_1: b PLTresolve
10064 * # Some number of entries towards the end can be nops
10070 * addis 11,11,(1f-res_0)@ha
10073 * 1: addi 11,11,(1b-res_0)@l
10076 * sub 11,11,12 # r11 = index * 4
10077 * addis 12,12,(got+4-1b)@ha
10078 * lwz 0,(got+4-1b)@l(12) # got[1] address of dl_runtime_resolve
10079 * lwz 12,(got+8-1b)@l(12) # got[2] contains the map address
10082 * add 11,0,11 # r11 = index * 12 = reloc offset.
10085 * Non-PIC glink code is a little simpler.
10087 * # ith PLT code stub.
10088 * lis 11,(plt+(i-1)*4)@ha
10089 * lwz 11,(plt+(i-1)*4)@l(11)
10093 * The branch table is the same, then comes
10096 * lis 12,(got+4)@ha
10097 * addis 11,11,(-res_0)@ha
10098 * lwz 0,(got+4)@l(12) # got[1] address of dl_runtime_resolve
10099 * addi 11,11,(-res_0)@l # r11 = index * 4
10102 * lwz 12,(got+8)@l(12) # got[2] contains the map address
10103 * add 11,0,11 # r11 = index * 12 = reloc offset.
10107 /* Build the branch table, one for each plt entry (less one),
10108 and perhaps some padding. */
10109 p
= htab
->glink
->contents
;
10110 p
+= htab
->glink_pltresolve
;
10111 endp
= htab
->glink
->contents
;
10112 endp
+= htab
->glink
->size
- GLINK_PLTRESOLVE
;
10113 while (p
< endp
- (htab
->params
->ppc476_workaround
? 0 : 8 * 4))
10115 bfd_put_32 (output_bfd
, B
+ endp
- p
, p
);
10120 bfd_put_32 (output_bfd
, NOP
, p
);
10124 res0
= (htab
->glink_pltresolve
10125 + htab
->glink
->output_section
->vma
10126 + htab
->glink
->output_offset
);
10128 if (htab
->params
->ppc476_workaround
)
10130 /* Ensure that a call stub at the end of a page doesn't
10131 result in prefetch over the end of the page into the
10132 glink branch table. */
10133 bfd_vma pagesize
= (bfd_vma
) 1 << htab
->params
->pagesize_p2
;
10135 bfd_vma glink_start
= (htab
->glink
->output_section
->vma
10136 + htab
->glink
->output_offset
);
10138 for (page_addr
= res0
& -pagesize
;
10139 page_addr
> glink_start
;
10140 page_addr
-= pagesize
)
10142 /* We have a plt call stub that may need fixing. */
10146 loc
= htab
->glink
->contents
+ page_addr
- 4 - glink_start
;
10147 insn
= bfd_get_32 (output_bfd
, loc
);
10150 /* By alignment, we know that there must be at least
10151 one other call stub before this one. */
10152 insn
= bfd_get_32 (output_bfd
, loc
- 16);
10154 bfd_put_32 (output_bfd
, B
| (-16 & 0x3fffffc), loc
);
10156 bfd_put_32 (output_bfd
, B
| (-20 & 0x3fffffc), loc
);
10161 /* Last comes the PLTresolve stub. */
10162 endp
= p
+ GLINK_PLTRESOLVE
;
10163 if (bfd_link_pic (info
))
10167 bcl
= (htab
->glink
->size
- GLINK_PLTRESOLVE
+ 3*4
10168 + htab
->glink
->output_section
->vma
10169 + htab
->glink
->output_offset
);
10171 bfd_put_32 (output_bfd
, ADDIS_11_11
+ PPC_HA (bcl
- res0
), p
);
10173 bfd_put_32 (output_bfd
, MFLR_0
, p
);
10175 bfd_put_32 (output_bfd
, BCL_20_31
, p
);
10177 bfd_put_32 (output_bfd
, ADDI_11_11
+ PPC_LO (bcl
- res0
), p
);
10179 bfd_put_32 (output_bfd
, MFLR_12
, p
);
10181 bfd_put_32 (output_bfd
, MTLR_0
, p
);
10183 bfd_put_32 (output_bfd
, SUB_11_11_12
, p
);
10185 bfd_put_32 (output_bfd
, ADDIS_12_12
+ PPC_HA (got
+ 4 - bcl
), p
);
10187 if (PPC_HA (got
+ 4 - bcl
) == PPC_HA (got
+ 8 - bcl
))
10189 bfd_put_32 (output_bfd
, LWZ_0_12
+ PPC_LO (got
+ 4 - bcl
), p
);
10191 bfd_put_32 (output_bfd
, LWZ_12_12
+ PPC_LO (got
+ 8 - bcl
), p
);
10196 bfd_put_32 (output_bfd
, LWZU_0_12
+ PPC_LO (got
+ 4 - bcl
), p
);
10198 bfd_put_32 (output_bfd
, LWZ_12_12
+ 4, p
);
10201 bfd_put_32 (output_bfd
, MTCTR_0
, p
);
10203 bfd_put_32 (output_bfd
, ADD_0_11_11
, p
);
10207 bfd_put_32 (output_bfd
, LIS_12
+ PPC_HA (got
+ 4), p
);
10209 bfd_put_32 (output_bfd
, ADDIS_11_11
+ PPC_HA (-res0
), p
);
10211 if (PPC_HA (got
+ 4) == PPC_HA (got
+ 8))
10212 bfd_put_32 (output_bfd
, LWZ_0_12
+ PPC_LO (got
+ 4), p
);
10214 bfd_put_32 (output_bfd
, LWZU_0_12
+ PPC_LO (got
+ 4), p
);
10216 bfd_put_32 (output_bfd
, ADDI_11_11
+ PPC_LO (-res0
), p
);
10218 bfd_put_32 (output_bfd
, MTCTR_0
, p
);
10220 bfd_put_32 (output_bfd
, ADD_0_11_11
, p
);
10222 if (PPC_HA (got
+ 4) == PPC_HA (got
+ 8))
10223 bfd_put_32 (output_bfd
, LWZ_12_12
+ PPC_LO (got
+ 8), p
);
10225 bfd_put_32 (output_bfd
, LWZ_12_12
+ 4, p
);
10228 bfd_put_32 (output_bfd
, ADD_11_0_11
, p
);
10230 bfd_put_32 (output_bfd
, BCTR
, p
);
10234 bfd_put_32 (output_bfd
,
10235 htab
->params
->ppc476_workaround
? BA
: NOP
, p
);
10238 BFD_ASSERT (p
== endp
);
10241 if (htab
->glink_eh_frame
!= NULL
10242 && htab
->glink_eh_frame
->contents
!= NULL
)
10244 unsigned char *p
= htab
->glink_eh_frame
->contents
;
10247 p
+= sizeof (glink_eh_frame_cie
);
10252 /* Offset to .glink. */
10253 val
= (htab
->glink
->output_section
->vma
10254 + htab
->glink
->output_offset
);
10255 val
-= (htab
->glink_eh_frame
->output_section
->vma
10256 + htab
->glink_eh_frame
->output_offset
);
10257 val
-= p
- htab
->glink_eh_frame
->contents
;
10258 bfd_put_32 (htab
->elf
.dynobj
, val
, p
);
10260 if (htab
->glink_eh_frame
->sec_info_type
== SEC_INFO_TYPE_EH_FRAME
10261 && !_bfd_elf_write_section_eh_frame (output_bfd
, info
,
10262 htab
->glink_eh_frame
,
10263 htab
->glink_eh_frame
->contents
))
10270 #define TARGET_LITTLE_SYM powerpc_elf32_le_vec
10271 #define TARGET_LITTLE_NAME "elf32-powerpcle"
10272 #define TARGET_BIG_SYM powerpc_elf32_vec
10273 #define TARGET_BIG_NAME "elf32-powerpc"
10274 #define ELF_ARCH bfd_arch_powerpc
10275 #define ELF_TARGET_ID PPC32_ELF_DATA
10276 #define ELF_MACHINE_CODE EM_PPC
10277 #define ELF_MAXPAGESIZE 0x10000
10278 #define ELF_COMMONPAGESIZE 0x1000
10279 #define ELF_RELROPAGESIZE ELF_MAXPAGESIZE
10280 #define elf_info_to_howto ppc_elf_info_to_howto
10282 #ifdef EM_CYGNUS_POWERPC
10283 #define ELF_MACHINE_ALT1 EM_CYGNUS_POWERPC
10287 #define ELF_MACHINE_ALT2 EM_PPC_OLD
10290 #define elf_backend_plt_not_loaded 1
10291 #define elf_backend_want_dynrelro 1
10292 #define elf_backend_can_gc_sections 1
10293 #define elf_backend_can_refcount 1
10294 #define elf_backend_rela_normal 1
10295 #define elf_backend_caches_rawsize 1
10297 #define bfd_elf32_mkobject ppc_elf_mkobject
10298 #define bfd_elf32_bfd_merge_private_bfd_data ppc_elf_merge_private_bfd_data
10299 #define bfd_elf32_bfd_relax_section ppc_elf_relax_section
10300 #define bfd_elf32_bfd_reloc_type_lookup ppc_elf_reloc_type_lookup
10301 #define bfd_elf32_bfd_reloc_name_lookup ppc_elf_reloc_name_lookup
10302 #define bfd_elf32_bfd_set_private_flags ppc_elf_set_private_flags
10303 #define bfd_elf32_bfd_link_hash_table_create ppc_elf_link_hash_table_create
10304 #define bfd_elf32_get_synthetic_symtab ppc_elf_get_synthetic_symtab
10306 #define elf_backend_object_p ppc_elf_object_p
10307 #define elf_backend_gc_mark_hook ppc_elf_gc_mark_hook
10308 #define elf_backend_section_from_shdr ppc_elf_section_from_shdr
10309 #define elf_backend_relocate_section ppc_elf_relocate_section
10310 #define elf_backend_create_dynamic_sections ppc_elf_create_dynamic_sections
10311 #define elf_backend_check_relocs ppc_elf_check_relocs
10312 #define elf_backend_relocs_compatible _bfd_elf_relocs_compatible
10313 #define elf_backend_copy_indirect_symbol ppc_elf_copy_indirect_symbol
10314 #define elf_backend_adjust_dynamic_symbol ppc_elf_adjust_dynamic_symbol
10315 #define elf_backend_add_symbol_hook ppc_elf_add_symbol_hook
10316 #define elf_backend_size_dynamic_sections ppc_elf_size_dynamic_sections
10317 #define elf_backend_hash_symbol ppc_elf_hash_symbol
10318 #define elf_backend_finish_dynamic_symbol ppc_elf_finish_dynamic_symbol
10319 #define elf_backend_finish_dynamic_sections ppc_elf_finish_dynamic_sections
10320 #define elf_backend_fake_sections ppc_elf_fake_sections
10321 #define elf_backend_additional_program_headers ppc_elf_additional_program_headers
10322 #define elf_backend_modify_segment_map ppc_elf_modify_segment_map
10323 #define elf_backend_grok_prstatus ppc_elf_grok_prstatus
10324 #define elf_backend_grok_psinfo ppc_elf_grok_psinfo
10325 #define elf_backend_write_core_note ppc_elf_write_core_note
10326 #define elf_backend_reloc_type_class ppc_elf_reloc_type_class
10327 #define elf_backend_begin_write_processing ppc_elf_begin_write_processing
10328 #define elf_backend_final_write_processing ppc_elf_final_write_processing
10329 #define elf_backend_write_section ppc_elf_write_section
10330 #define elf_backend_get_sec_type_attr ppc_elf_get_sec_type_attr
10331 #define elf_backend_plt_sym_val ppc_elf_plt_sym_val
10332 #define elf_backend_action_discarded ppc_elf_action_discarded
10333 #define elf_backend_init_index_section _bfd_elf_init_1_index_section
10334 #define elf_backend_lookup_section_flags_hook ppc_elf_lookup_section_flags
10336 #include "elf32-target.h"
10338 /* FreeBSD Target */
10340 #undef TARGET_LITTLE_SYM
10341 #undef TARGET_LITTLE_NAME
10343 #undef TARGET_BIG_SYM
10344 #define TARGET_BIG_SYM powerpc_elf32_fbsd_vec
10345 #undef TARGET_BIG_NAME
10346 #define TARGET_BIG_NAME "elf32-powerpc-freebsd"
10349 #define ELF_OSABI ELFOSABI_FREEBSD
10352 #define elf32_bed elf32_powerpc_fbsd_bed
10354 #include "elf32-target.h"
10356 /* VxWorks Target */
10358 #undef TARGET_LITTLE_SYM
10359 #undef TARGET_LITTLE_NAME
10361 #undef TARGET_BIG_SYM
10362 #define TARGET_BIG_SYM powerpc_elf32_vxworks_vec
10363 #undef TARGET_BIG_NAME
10364 #define TARGET_BIG_NAME "elf32-powerpc-vxworks"
10368 #undef ELF_TARGET_OS
10369 #define ELF_TARGET_OS is_vxworks
10371 /* VxWorks uses the elf default section flags for .plt. */
10372 static const struct bfd_elf_special_section
*
10373 ppc_elf_vxworks_get_sec_type_attr (bfd
*abfd
, asection
*sec
)
10375 if (sec
->name
== NULL
)
10378 if (strcmp (sec
->name
, ".plt") == 0)
10379 return _bfd_elf_get_sec_type_attr (abfd
, sec
);
10381 return ppc_elf_get_sec_type_attr (abfd
, sec
);
10384 /* Like ppc_elf_link_hash_table_create, but overrides
10385 appropriately for VxWorks. */
10386 static struct bfd_link_hash_table
*
10387 ppc_elf_vxworks_link_hash_table_create (bfd
*abfd
)
10389 struct bfd_link_hash_table
*ret
;
10391 ret
= ppc_elf_link_hash_table_create (abfd
);
10394 struct ppc_elf_link_hash_table
*htab
10395 = (struct ppc_elf_link_hash_table
*)ret
;
10396 htab
->plt_type
= PLT_VXWORKS
;
10397 htab
->plt_entry_size
= VXWORKS_PLT_ENTRY_SIZE
;
10398 htab
->plt_slot_size
= VXWORKS_PLT_ENTRY_SIZE
;
10399 htab
->plt_initial_entry_size
= VXWORKS_PLT_INITIAL_ENTRY_SIZE
;
10404 /* Tweak magic VxWorks symbols as they are loaded. */
10406 ppc_elf_vxworks_add_symbol_hook (bfd
*abfd
,
10407 struct bfd_link_info
*info
,
10408 Elf_Internal_Sym
*sym
,
10409 const char **namep
,
10414 if (!elf_vxworks_add_symbol_hook (abfd
, info
, sym
, namep
, flagsp
, secp
,
10418 return ppc_elf_add_symbol_hook (abfd
, info
, sym
, namep
, flagsp
, secp
, valp
);
10422 ppc_elf_vxworks_final_write_processing (bfd
*abfd
)
10424 ppc_final_write_processing (abfd
);
10425 return elf_vxworks_final_write_processing (abfd
);
10428 /* On VxWorks, we emit relocations against _PROCEDURE_LINKAGE_TABLE_, so
10430 #undef elf_backend_want_plt_sym
10431 #define elf_backend_want_plt_sym 1
10432 #undef elf_backend_want_got_plt
10433 #define elf_backend_want_got_plt 1
10434 #undef elf_backend_got_symbol_offset
10435 #define elf_backend_got_symbol_offset 0
10436 #undef elf_backend_plt_not_loaded
10437 #define elf_backend_plt_not_loaded 0
10438 #undef elf_backend_plt_readonly
10439 #define elf_backend_plt_readonly 1
10440 #undef elf_backend_got_header_size
10441 #define elf_backend_got_header_size 12
10442 #undef elf_backend_dtrel_excludes_plt
10443 #define elf_backend_dtrel_excludes_plt 1
10445 #undef bfd_elf32_get_synthetic_symtab
10447 #undef bfd_elf32_bfd_link_hash_table_create
10448 #define bfd_elf32_bfd_link_hash_table_create \
10449 ppc_elf_vxworks_link_hash_table_create
10450 #undef elf_backend_add_symbol_hook
10451 #define elf_backend_add_symbol_hook \
10452 ppc_elf_vxworks_add_symbol_hook
10453 #undef elf_backend_link_output_symbol_hook
10454 #define elf_backend_link_output_symbol_hook \
10455 elf_vxworks_link_output_symbol_hook
10456 #undef elf_backend_final_write_processing
10457 #define elf_backend_final_write_processing \
10458 ppc_elf_vxworks_final_write_processing
10459 #undef elf_backend_get_sec_type_attr
10460 #define elf_backend_get_sec_type_attr \
10461 ppc_elf_vxworks_get_sec_type_attr
10462 #undef elf_backend_emit_relocs
10463 #define elf_backend_emit_relocs \
10464 elf_vxworks_emit_relocs
10467 #define elf32_bed ppc_elf_vxworks_bed
10469 #include "elf32-target.h"