* dwarf2read.c (dwarf2_add_field): Constify.
[deliverable/binutils-gdb.git] / bfd / elf32-ppc.c
CommitLineData
252b5132 1/* PowerPC-specific support for 32-bit ELF
051d5130 2 Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
766bc656 3 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
252b5132
RH
4 Written by Ian Lance Taylor, Cygnus Support.
5
ae9a127f 6 This file is part of BFD, the Binary File Descriptor library.
252b5132 7
ae9a127f
NC
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
cd123cb7 10 the Free Software Foundation; either version 3 of the License, or
ae9a127f 11 (at your option) any later version.
252b5132 12
ae9a127f
NC
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
252b5132 17
ae9a127f 18 You should have received a copy of the GNU General Public License
fc0bffd6 19 along with this program; if not, write to the
3e110533 20 Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
53e09e0a 21 Boston, MA 02110-1301, USA. */
252b5132 22
cd123cb7 23
252b5132
RH
24/* This file is based on a preliminary PowerPC ELF ABI. The
25 information may not match the final PowerPC ELF ABI. It includes
26 suggestions from the in-progress Embedded PowerPC ABI, and that
27 information may also not match. */
28
3db64b00 29#include "sysdep.h"
183e98be 30#include <stdarg.h>
252b5132 31#include "bfd.h"
252b5132
RH
32#include "bfdlink.h"
33#include "libbfd.h"
34#include "elf-bfd.h"
35#include "elf/ppc.h"
7619e7c7 36#include "elf32-ppc.h"
9d8504b1 37#include "elf-vxworks.h"
252b5132 38
f0fe0e16 39/* RELA relocations are used here. */
252b5132 40
252b5132 41static bfd_reloc_status_type ppc_elf_addr16_ha_reloc
55fd94b0 42 (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
7619e7c7 43static bfd_reloc_status_type ppc_elf_unhandled_reloc
55fd94b0 44 (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
252b5132 45
70bccea4
AM
46/* Branch prediction bit for branch taken relocs. */
47#define BRANCH_PREDICT_BIT 0x200000
48/* Mask to set RA in memory instructions. */
49#define RA_REGISTER_MASK 0x001f0000
50/* Value to shift register by to insert RA. */
51#define RA_REGISTER_SHIFT 16
252b5132
RH
52
53/* The name of the dynamic interpreter. This is put in the .interp
54 section. */
252b5132
RH
55#define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
56
d7128ce4 57/* For old-style PLT. */
252b5132
RH
58/* The number of single-slot PLT entries (the rest use two slots). */
59#define PLT_NUM_SINGLE_ENTRIES 8192
60
d7128ce4 61/* For new-style .glink and .plt. */
a6aa5195 62#define GLINK_PLTRESOLVE 16*4
d7128ce4 63#define GLINK_ENTRY_SIZE 4*4
a7f2871e 64#define TLS_GET_ADDR_GLINK_SIZE 12*4
d7128ce4 65
9d8504b1
PB
66/* VxWorks uses its own plt layout, filled in by the static linker. */
67
68/* The standard VxWorks PLT entry. */
69#define VXWORKS_PLT_ENTRY_SIZE 32
70static const bfd_vma ppc_elf_vxworks_plt_entry
71 [VXWORKS_PLT_ENTRY_SIZE / 4] =
72 {
73 0x3d800000, /* lis r12,0 */
74 0x818c0000, /* lwz r12,0(r12) */
75 0x7d8903a6, /* mtctr r12 */
76 0x4e800420, /* bctr */
77 0x39600000, /* li r11,0 */
78 0x48000000, /* b 14 <.PLT0resolve+0x4> */
79 0x60000000, /* nop */
80 0x60000000, /* nop */
81 };
82static const bfd_vma ppc_elf_vxworks_pic_plt_entry
83 [VXWORKS_PLT_ENTRY_SIZE / 4] =
84 {
85 0x3d9e0000, /* addis r12,r30,0 */
86 0x818c0000, /* lwz r12,0(r12) */
87 0x7d8903a6, /* mtctr r12 */
88 0x4e800420, /* bctr */
89 0x39600000, /* li r11,0 */
90 0x48000000, /* b 14 <.PLT0resolve+0x4> 14: R_PPC_REL24 .PLTresolve */
91 0x60000000, /* nop */
92 0x60000000, /* nop */
93 };
94
95/* The initial VxWorks PLT entry. */
96#define VXWORKS_PLT_INITIAL_ENTRY_SIZE 32
97static const bfd_vma ppc_elf_vxworks_plt0_entry
98 [VXWORKS_PLT_INITIAL_ENTRY_SIZE / 4] =
99 {
100 0x3d800000, /* lis r12,0 */
101 0x398c0000, /* addi r12,r12,0 */
102 0x800c0008, /* lwz r0,8(r12) */
103 0x7c0903a6, /* mtctr r0 */
104 0x818c0004, /* lwz r12,4(r12) */
105 0x4e800420, /* bctr */
106 0x60000000, /* nop */
107 0x60000000, /* nop */
108 };
109static const bfd_vma ppc_elf_vxworks_pic_plt0_entry
110 [VXWORKS_PLT_INITIAL_ENTRY_SIZE / 4] =
111 {
112 0x819e0008, /* lwz r12,8(r30) */
113 0x7d8903a6, /* mtctr r12 */
114 0x819e0004, /* lwz r12,4(r30) */
115 0x4e800420, /* bctr */
116 0x60000000, /* nop */
117 0x60000000, /* nop */
118 0x60000000, /* nop */
119 0x60000000, /* nop */
120 };
121
122/* For executables, we have some additional relocations in
123 .rela.plt.unloaded, for the kernel loader. */
124
125/* The number of non-JMP_SLOT relocations per PLT0 slot. */
126#define VXWORKS_PLT_NON_JMP_SLOT_RELOCS 3
127/* The number of relocations in the PLTResolve slot. */
128#define VXWORKS_PLTRESOLVE_RELOCS 2
129/* The number of relocations in the PLTResolve slot when when creating
130 a shared library. */
131#define VXWORKS_PLTRESOLVE_RELOCS_SHLIB 0
132
d7128ce4 133/* Some instructions. */
d7128ce4 134#define ADDIS_11_11 0x3d6b0000
a6aa5195
AM
135#define ADDIS_11_30 0x3d7e0000
136#define ADDIS_12_12 0x3d8c0000
d7128ce4 137#define ADDI_11_11 0x396b0000
d7128ce4 138#define ADD_0_11_11 0x7c0b5a14
a7f2871e 139#define ADD_3_12_2 0x7c6c1214
d7128ce4 140#define ADD_11_0_11 0x7d605a14
a6aa5195
AM
141#define B 0x48000000
142#define BCL_20_31 0x429f0005
d7128ce4 143#define BCTR 0x4e800420
a7f2871e
AM
144#define BEQLR 0x4d820020
145#define CMPWI_11_0 0x2c0b0000
7e8aeb9a
AM
146#define LIS_11 0x3d600000
147#define LIS_12 0x3d800000
a6aa5195
AM
148#define LWZU_0_12 0x840c0000
149#define LWZ_0_12 0x800c0000
a7f2871e 150#define LWZ_11_3 0x81630000
a6aa5195
AM
151#define LWZ_11_11 0x816b0000
152#define LWZ_11_30 0x817e0000
a7f2871e 153#define LWZ_12_3 0x81830000
a6aa5195 154#define LWZ_12_12 0x818c0000
a7f2871e
AM
155#define MR_0_3 0x7c601b78
156#define MR_3_0 0x7c030378
a6aa5195
AM
157#define MFLR_0 0x7c0802a6
158#define MFLR_12 0x7d8802a6
159#define MTCTR_0 0x7c0903a6
160#define MTCTR_11 0x7d6903a6
161#define MTLR_0 0x7c0803a6
162#define NOP 0x60000000
163#define SUB_11_11_12 0x7d6c5850
7619e7c7
AM
164
165/* Offset of tp and dtp pointers from start of TLS block. */
166#define TP_OFFSET 0x7000
167#define DTP_OFFSET 0x8000
e87d4038
AM
168
169/* The value of a defined global symbol. */
170#define SYM_VAL(SYM) \
171 ((SYM)->root.u.def.section->output_section->vma \
172 + (SYM)->root.u.def.section->output_offset \
173 + (SYM)->root.u.def.value)
7fce784e 174\f
e47cd125 175static reloc_howto_type *ppc_elf_howto_table[R_PPC_max];
252b5132 176
8da6118f 177static reloc_howto_type ppc_elf_howto_raw[] = {
252b5132
RH
178 /* This reloc does nothing. */
179 HOWTO (R_PPC_NONE, /* type */
180 0, /* rightshift */
181 2, /* size (0 = byte, 1 = short, 2 = long) */
182 32, /* bitsize */
b34976b6 183 FALSE, /* pc_relative */
252b5132
RH
184 0, /* bitpos */
185 complain_overflow_bitfield, /* complain_on_overflow */
186 bfd_elf_generic_reloc, /* special_function */
187 "R_PPC_NONE", /* name */
b34976b6 188 FALSE, /* partial_inplace */
252b5132
RH
189 0, /* src_mask */
190 0, /* dst_mask */
b34976b6 191 FALSE), /* pcrel_offset */
252b5132
RH
192
193 /* A standard 32 bit relocation. */
194 HOWTO (R_PPC_ADDR32, /* type */
195 0, /* rightshift */
196 2, /* size (0 = byte, 1 = short, 2 = long) */
197 32, /* bitsize */
b34976b6 198 FALSE, /* pc_relative */
252b5132
RH
199 0, /* bitpos */
200 complain_overflow_bitfield, /* complain_on_overflow */
201 bfd_elf_generic_reloc, /* special_function */
202 "R_PPC_ADDR32", /* name */
b34976b6 203 FALSE, /* partial_inplace */
252b5132
RH
204 0, /* src_mask */
205 0xffffffff, /* dst_mask */
b34976b6 206 FALSE), /* pcrel_offset */
252b5132
RH
207
208 /* An absolute 26 bit branch; the lower two bits must be zero.
209 FIXME: we don't check that, we just clear them. */
210 HOWTO (R_PPC_ADDR24, /* type */
211 0, /* rightshift */
212 2, /* size (0 = byte, 1 = short, 2 = long) */
213 26, /* bitsize */
b34976b6 214 FALSE, /* pc_relative */
252b5132
RH
215 0, /* bitpos */
216 complain_overflow_bitfield, /* complain_on_overflow */
217 bfd_elf_generic_reloc, /* special_function */
218 "R_PPC_ADDR24", /* name */
b34976b6 219 FALSE, /* partial_inplace */
252b5132
RH
220 0, /* src_mask */
221 0x3fffffc, /* dst_mask */
b34976b6 222 FALSE), /* pcrel_offset */
252b5132
RH
223
224 /* A standard 16 bit relocation. */
225 HOWTO (R_PPC_ADDR16, /* type */
226 0, /* rightshift */
227 1, /* size (0 = byte, 1 = short, 2 = long) */
228 16, /* bitsize */
b34976b6 229 FALSE, /* pc_relative */
252b5132
RH
230 0, /* bitpos */
231 complain_overflow_bitfield, /* complain_on_overflow */
232 bfd_elf_generic_reloc, /* special_function */
233 "R_PPC_ADDR16", /* name */
b34976b6 234 FALSE, /* partial_inplace */
252b5132
RH
235 0, /* src_mask */
236 0xffff, /* dst_mask */
b34976b6 237 FALSE), /* pcrel_offset */
252b5132
RH
238
239 /* A 16 bit relocation without overflow. */
240 HOWTO (R_PPC_ADDR16_LO, /* type */
241 0, /* rightshift */
242 1, /* size (0 = byte, 1 = short, 2 = long) */
243 16, /* bitsize */
b34976b6 244 FALSE, /* pc_relative */
252b5132
RH
245 0, /* bitpos */
246 complain_overflow_dont,/* complain_on_overflow */
247 bfd_elf_generic_reloc, /* special_function */
248 "R_PPC_ADDR16_LO", /* name */
b34976b6 249 FALSE, /* partial_inplace */
252b5132
RH
250 0, /* src_mask */
251 0xffff, /* dst_mask */
b34976b6 252 FALSE), /* pcrel_offset */
252b5132
RH
253
254 /* The high order 16 bits of an address. */
255 HOWTO (R_PPC_ADDR16_HI, /* type */
256 16, /* rightshift */
257 1, /* size (0 = byte, 1 = short, 2 = long) */
258 16, /* bitsize */
b34976b6 259 FALSE, /* pc_relative */
252b5132
RH
260 0, /* bitpos */
261 complain_overflow_dont, /* complain_on_overflow */
262 bfd_elf_generic_reloc, /* special_function */
263 "R_PPC_ADDR16_HI", /* name */
b34976b6 264 FALSE, /* partial_inplace */
252b5132
RH
265 0, /* src_mask */
266 0xffff, /* dst_mask */
b34976b6 267 FALSE), /* pcrel_offset */
252b5132
RH
268
269 /* The high order 16 bits of an address, plus 1 if the contents of
8da6118f 270 the low 16 bits, treated as a signed number, is negative. */
252b5132
RH
271 HOWTO (R_PPC_ADDR16_HA, /* type */
272 16, /* rightshift */
273 1, /* size (0 = byte, 1 = short, 2 = long) */
274 16, /* bitsize */
b34976b6 275 FALSE, /* pc_relative */
252b5132
RH
276 0, /* bitpos */
277 complain_overflow_dont, /* complain_on_overflow */
278 ppc_elf_addr16_ha_reloc, /* special_function */
279 "R_PPC_ADDR16_HA", /* name */
b34976b6 280 FALSE, /* partial_inplace */
252b5132
RH
281 0, /* src_mask */
282 0xffff, /* dst_mask */
b34976b6 283 FALSE), /* pcrel_offset */
252b5132
RH
284
285 /* An absolute 16 bit branch; the lower two bits must be zero.
286 FIXME: we don't check that, we just clear them. */
287 HOWTO (R_PPC_ADDR14, /* type */
288 0, /* rightshift */
289 2, /* size (0 = byte, 1 = short, 2 = long) */
290 16, /* bitsize */
b34976b6 291 FALSE, /* pc_relative */
252b5132
RH
292 0, /* bitpos */
293 complain_overflow_bitfield, /* complain_on_overflow */
294 bfd_elf_generic_reloc, /* special_function */
295 "R_PPC_ADDR14", /* name */
b34976b6 296 FALSE, /* partial_inplace */
252b5132
RH
297 0, /* src_mask */
298 0xfffc, /* dst_mask */
b34976b6 299 FALSE), /* pcrel_offset */
252b5132
RH
300
301 /* An absolute 16 bit branch, for which bit 10 should be set to
302 indicate that the branch is expected to be taken. The lower two
8da6118f 303 bits must be zero. */
252b5132
RH
304 HOWTO (R_PPC_ADDR14_BRTAKEN, /* type */
305 0, /* rightshift */
306 2, /* size (0 = byte, 1 = short, 2 = long) */
307 16, /* bitsize */
b34976b6 308 FALSE, /* pc_relative */
252b5132
RH
309 0, /* bitpos */
310 complain_overflow_bitfield, /* complain_on_overflow */
311 bfd_elf_generic_reloc, /* special_function */
312 "R_PPC_ADDR14_BRTAKEN",/* name */
b34976b6 313 FALSE, /* partial_inplace */
252b5132
RH
314 0, /* src_mask */
315 0xfffc, /* dst_mask */
b34976b6 316 FALSE), /* pcrel_offset */
252b5132
RH
317
318 /* An absolute 16 bit branch, for which bit 10 should be set to
319 indicate that the branch is not expected to be taken. The lower
320 two bits must be zero. */
321 HOWTO (R_PPC_ADDR14_BRNTAKEN, /* type */
322 0, /* rightshift */
323 2, /* size (0 = byte, 1 = short, 2 = long) */
324 16, /* bitsize */
b34976b6 325 FALSE, /* pc_relative */
252b5132
RH
326 0, /* bitpos */
327 complain_overflow_bitfield, /* complain_on_overflow */
328 bfd_elf_generic_reloc, /* special_function */
329 "R_PPC_ADDR14_BRNTAKEN",/* name */
b34976b6 330 FALSE, /* partial_inplace */
252b5132
RH
331 0, /* src_mask */
332 0xfffc, /* dst_mask */
b34976b6 333 FALSE), /* pcrel_offset */
252b5132 334
8da6118f 335 /* A relative 26 bit branch; the lower two bits must be zero. */
252b5132
RH
336 HOWTO (R_PPC_REL24, /* type */
337 0, /* rightshift */
338 2, /* size (0 = byte, 1 = short, 2 = long) */
339 26, /* bitsize */
b34976b6 340 TRUE, /* pc_relative */
252b5132
RH
341 0, /* bitpos */
342 complain_overflow_signed, /* complain_on_overflow */
343 bfd_elf_generic_reloc, /* special_function */
344 "R_PPC_REL24", /* name */
b34976b6 345 FALSE, /* partial_inplace */
252b5132
RH
346 0, /* src_mask */
347 0x3fffffc, /* dst_mask */
b34976b6 348 TRUE), /* pcrel_offset */
252b5132 349
8da6118f 350 /* A relative 16 bit branch; the lower two bits must be zero. */
252b5132
RH
351 HOWTO (R_PPC_REL14, /* type */
352 0, /* rightshift */
353 2, /* size (0 = byte, 1 = short, 2 = long) */
354 16, /* bitsize */
b34976b6 355 TRUE, /* pc_relative */
252b5132
RH
356 0, /* bitpos */
357 complain_overflow_signed, /* complain_on_overflow */
358 bfd_elf_generic_reloc, /* special_function */
359 "R_PPC_REL14", /* name */
b34976b6 360 FALSE, /* partial_inplace */
252b5132
RH
361 0, /* src_mask */
362 0xfffc, /* dst_mask */
b34976b6 363 TRUE), /* pcrel_offset */
252b5132 364
8da6118f 365 /* A relative 16 bit branch. Bit 10 should be set to indicate that
252b5132
RH
366 the branch is expected to be taken. The lower two bits must be
367 zero. */
368 HOWTO (R_PPC_REL14_BRTAKEN, /* type */
369 0, /* rightshift */
370 2, /* size (0 = byte, 1 = short, 2 = long) */
371 16, /* bitsize */
b34976b6 372 TRUE, /* pc_relative */
252b5132
RH
373 0, /* bitpos */
374 complain_overflow_signed, /* complain_on_overflow */
375 bfd_elf_generic_reloc, /* special_function */
376 "R_PPC_REL14_BRTAKEN", /* name */
b34976b6 377 FALSE, /* partial_inplace */
252b5132
RH
378 0, /* src_mask */
379 0xfffc, /* dst_mask */
b34976b6 380 TRUE), /* pcrel_offset */
252b5132 381
8da6118f 382 /* A relative 16 bit branch. Bit 10 should be set to indicate that
252b5132
RH
383 the branch is not expected to be taken. The lower two bits must
384 be zero. */
385 HOWTO (R_PPC_REL14_BRNTAKEN, /* type */
386 0, /* rightshift */
387 2, /* size (0 = byte, 1 = short, 2 = long) */
388 16, /* bitsize */
b34976b6 389 TRUE, /* pc_relative */
252b5132
RH
390 0, /* bitpos */
391 complain_overflow_signed, /* complain_on_overflow */
392 bfd_elf_generic_reloc, /* special_function */
393 "R_PPC_REL14_BRNTAKEN",/* name */
b34976b6 394 FALSE, /* partial_inplace */
252b5132
RH
395 0, /* src_mask */
396 0xfffc, /* dst_mask */
b34976b6 397 TRUE), /* pcrel_offset */
252b5132
RH
398
399 /* Like R_PPC_ADDR16, but referring to the GOT table entry for the
400 symbol. */
401 HOWTO (R_PPC_GOT16, /* type */
402 0, /* rightshift */
403 1, /* size (0 = byte, 1 = short, 2 = long) */
404 16, /* bitsize */
b34976b6 405 FALSE, /* pc_relative */
252b5132
RH
406 0, /* bitpos */
407 complain_overflow_signed, /* complain_on_overflow */
408 bfd_elf_generic_reloc, /* special_function */
409 "R_PPC_GOT16", /* name */
b34976b6 410 FALSE, /* partial_inplace */
252b5132
RH
411 0, /* src_mask */
412 0xffff, /* dst_mask */
b34976b6 413 FALSE), /* pcrel_offset */
252b5132
RH
414
415 /* Like R_PPC_ADDR16_LO, but referring to the GOT table entry for
416 the symbol. */
417 HOWTO (R_PPC_GOT16_LO, /* type */
418 0, /* rightshift */
419 1, /* size (0 = byte, 1 = short, 2 = long) */
420 16, /* bitsize */
b34976b6 421 FALSE, /* pc_relative */
252b5132
RH
422 0, /* bitpos */
423 complain_overflow_dont, /* complain_on_overflow */
424 bfd_elf_generic_reloc, /* special_function */
425 "R_PPC_GOT16_LO", /* name */
b34976b6 426 FALSE, /* partial_inplace */
252b5132
RH
427 0, /* src_mask */
428 0xffff, /* dst_mask */
b34976b6 429 FALSE), /* pcrel_offset */
252b5132
RH
430
431 /* Like R_PPC_ADDR16_HI, but referring to the GOT table entry for
432 the symbol. */
433 HOWTO (R_PPC_GOT16_HI, /* type */
434 16, /* rightshift */
435 1, /* size (0 = byte, 1 = short, 2 = long) */
436 16, /* bitsize */
b34976b6 437 FALSE, /* pc_relative */
252b5132
RH
438 0, /* bitpos */
439 complain_overflow_bitfield, /* complain_on_overflow */
440 bfd_elf_generic_reloc, /* special_function */
441 "R_PPC_GOT16_HI", /* name */
b34976b6 442 FALSE, /* partial_inplace */
252b5132
RH
443 0, /* src_mask */
444 0xffff, /* dst_mask */
b34976b6 445 FALSE), /* pcrel_offset */
252b5132
RH
446
447 /* Like R_PPC_ADDR16_HA, but referring to the GOT table entry for
448 the symbol. */
449 HOWTO (R_PPC_GOT16_HA, /* type */
450 16, /* rightshift */
451 1, /* size (0 = byte, 1 = short, 2 = long) */
452 16, /* bitsize */
b34976b6 453 FALSE, /* pc_relative */
252b5132
RH
454 0, /* bitpos */
455 complain_overflow_bitfield, /* complain_on_overflow */
456 ppc_elf_addr16_ha_reloc, /* special_function */
457 "R_PPC_GOT16_HA", /* name */
b34976b6 458 FALSE, /* partial_inplace */
252b5132
RH
459 0, /* src_mask */
460 0xffff, /* dst_mask */
b34976b6 461 FALSE), /* pcrel_offset */
252b5132
RH
462
463 /* Like R_PPC_REL24, but referring to the procedure linkage table
464 entry for the symbol. */
465 HOWTO (R_PPC_PLTREL24, /* type */
466 0, /* rightshift */
467 2, /* size (0 = byte, 1 = short, 2 = long) */
468 26, /* bitsize */
b34976b6 469 TRUE, /* pc_relative */
252b5132
RH
470 0, /* bitpos */
471 complain_overflow_signed, /* complain_on_overflow */
472 bfd_elf_generic_reloc, /* special_function */
473 "R_PPC_PLTREL24", /* name */
b34976b6 474 FALSE, /* partial_inplace */
252b5132
RH
475 0, /* src_mask */
476 0x3fffffc, /* dst_mask */
b34976b6 477 TRUE), /* pcrel_offset */
252b5132
RH
478
479 /* This is used only by the dynamic linker. The symbol should exist
480 both in the object being run and in some shared library. The
481 dynamic linker copies the data addressed by the symbol from the
482 shared library into the object, because the object being
483 run has to have the data at some particular address. */
484 HOWTO (R_PPC_COPY, /* type */
485 0, /* rightshift */
486 2, /* size (0 = byte, 1 = short, 2 = long) */
487 32, /* bitsize */
b34976b6 488 FALSE, /* pc_relative */
252b5132
RH
489 0, /* bitpos */
490 complain_overflow_bitfield, /* complain_on_overflow */
491 bfd_elf_generic_reloc, /* special_function */
492 "R_PPC_COPY", /* name */
b34976b6 493 FALSE, /* partial_inplace */
252b5132
RH
494 0, /* src_mask */
495 0, /* dst_mask */
b34976b6 496 FALSE), /* pcrel_offset */
252b5132
RH
497
498 /* Like R_PPC_ADDR32, but used when setting global offset table
499 entries. */
500 HOWTO (R_PPC_GLOB_DAT, /* type */
501 0, /* rightshift */
502 2, /* size (0 = byte, 1 = short, 2 = long) */
503 32, /* bitsize */
b34976b6 504 FALSE, /* pc_relative */
252b5132
RH
505 0, /* bitpos */
506 complain_overflow_bitfield, /* complain_on_overflow */
507 bfd_elf_generic_reloc, /* special_function */
508 "R_PPC_GLOB_DAT", /* name */
b34976b6 509 FALSE, /* partial_inplace */
252b5132
RH
510 0, /* src_mask */
511 0xffffffff, /* dst_mask */
b34976b6 512 FALSE), /* pcrel_offset */
252b5132
RH
513
514 /* Marks a procedure linkage table entry for a symbol. */
515 HOWTO (R_PPC_JMP_SLOT, /* type */
516 0, /* rightshift */
517 2, /* size (0 = byte, 1 = short, 2 = long) */
518 32, /* bitsize */
b34976b6 519 FALSE, /* pc_relative */
252b5132
RH
520 0, /* bitpos */
521 complain_overflow_bitfield, /* complain_on_overflow */
522 bfd_elf_generic_reloc, /* special_function */
523 "R_PPC_JMP_SLOT", /* name */
b34976b6 524 FALSE, /* partial_inplace */
252b5132
RH
525 0, /* src_mask */
526 0, /* dst_mask */
b34976b6 527 FALSE), /* pcrel_offset */
252b5132
RH
528
529 /* Used only by the dynamic linker. When the object is run, this
530 longword is set to the load address of the object, plus the
531 addend. */
532 HOWTO (R_PPC_RELATIVE, /* type */
533 0, /* rightshift */
534 2, /* size (0 = byte, 1 = short, 2 = long) */
535 32, /* bitsize */
b34976b6 536 FALSE, /* pc_relative */
252b5132
RH
537 0, /* bitpos */
538 complain_overflow_bitfield, /* complain_on_overflow */
539 bfd_elf_generic_reloc, /* special_function */
540 "R_PPC_RELATIVE", /* name */
b34976b6 541 FALSE, /* partial_inplace */
252b5132
RH
542 0, /* src_mask */
543 0xffffffff, /* dst_mask */
b34976b6 544 FALSE), /* pcrel_offset */
252b5132
RH
545
546 /* Like R_PPC_REL24, but uses the value of the symbol within the
547 object rather than the final value. Normally used for
548 _GLOBAL_OFFSET_TABLE_. */
549 HOWTO (R_PPC_LOCAL24PC, /* type */
550 0, /* rightshift */
551 2, /* size (0 = byte, 1 = short, 2 = long) */
552 26, /* bitsize */
b34976b6 553 TRUE, /* pc_relative */
252b5132
RH
554 0, /* bitpos */
555 complain_overflow_signed, /* complain_on_overflow */
556 bfd_elf_generic_reloc, /* special_function */
557 "R_PPC_LOCAL24PC", /* name */
b34976b6 558 FALSE, /* partial_inplace */
252b5132
RH
559 0, /* src_mask */
560 0x3fffffc, /* dst_mask */
b34976b6 561 TRUE), /* pcrel_offset */
252b5132
RH
562
563 /* Like R_PPC_ADDR32, but may be unaligned. */
564 HOWTO (R_PPC_UADDR32, /* type */
565 0, /* rightshift */
566 2, /* size (0 = byte, 1 = short, 2 = long) */
567 32, /* bitsize */
b34976b6 568 FALSE, /* pc_relative */
252b5132
RH
569 0, /* bitpos */
570 complain_overflow_bitfield, /* complain_on_overflow */
571 bfd_elf_generic_reloc, /* special_function */
572 "R_PPC_UADDR32", /* name */
b34976b6 573 FALSE, /* partial_inplace */
252b5132
RH
574 0, /* src_mask */
575 0xffffffff, /* dst_mask */
b34976b6 576 FALSE), /* pcrel_offset */
252b5132
RH
577
578 /* Like R_PPC_ADDR16, but may be unaligned. */
579 HOWTO (R_PPC_UADDR16, /* type */
580 0, /* rightshift */
581 1, /* size (0 = byte, 1 = short, 2 = long) */
582 16, /* bitsize */
b34976b6 583 FALSE, /* pc_relative */
252b5132
RH
584 0, /* bitpos */
585 complain_overflow_bitfield, /* complain_on_overflow */
586 bfd_elf_generic_reloc, /* special_function */
587 "R_PPC_UADDR16", /* name */
b34976b6 588 FALSE, /* partial_inplace */
252b5132
RH
589 0, /* src_mask */
590 0xffff, /* dst_mask */
b34976b6 591 FALSE), /* pcrel_offset */
252b5132
RH
592
593 /* 32-bit PC relative */
594 HOWTO (R_PPC_REL32, /* type */
595 0, /* rightshift */
596 2, /* size (0 = byte, 1 = short, 2 = long) */
597 32, /* bitsize */
b34976b6 598 TRUE, /* pc_relative */
252b5132
RH
599 0, /* bitpos */
600 complain_overflow_bitfield, /* complain_on_overflow */
601 bfd_elf_generic_reloc, /* special_function */
602 "R_PPC_REL32", /* name */
b34976b6 603 FALSE, /* partial_inplace */
252b5132
RH
604 0, /* src_mask */
605 0xffffffff, /* dst_mask */
b34976b6 606 TRUE), /* pcrel_offset */
252b5132
RH
607
608 /* 32-bit relocation to the symbol's procedure linkage table.
c3668558 609 FIXME: not supported. */
252b5132
RH
610 HOWTO (R_PPC_PLT32, /* type */
611 0, /* rightshift */
612 2, /* size (0 = byte, 1 = short, 2 = long) */
613 32, /* bitsize */
b34976b6 614 FALSE, /* pc_relative */
252b5132
RH
615 0, /* bitpos */
616 complain_overflow_bitfield, /* complain_on_overflow */
617 bfd_elf_generic_reloc, /* special_function */
618 "R_PPC_PLT32", /* name */
b34976b6 619 FALSE, /* partial_inplace */
252b5132
RH
620 0, /* src_mask */
621 0, /* dst_mask */
b34976b6 622 FALSE), /* pcrel_offset */
252b5132
RH
623
624 /* 32-bit PC relative relocation to the symbol's procedure linkage table.
c3668558 625 FIXME: not supported. */
252b5132
RH
626 HOWTO (R_PPC_PLTREL32, /* type */
627 0, /* rightshift */
628 2, /* size (0 = byte, 1 = short, 2 = long) */
629 32, /* bitsize */
b34976b6 630 TRUE, /* pc_relative */
252b5132
RH
631 0, /* bitpos */
632 complain_overflow_bitfield, /* complain_on_overflow */
633 bfd_elf_generic_reloc, /* special_function */
634 "R_PPC_PLTREL32", /* name */
b34976b6 635 FALSE, /* partial_inplace */
252b5132
RH
636 0, /* src_mask */
637 0, /* dst_mask */
b34976b6 638 TRUE), /* pcrel_offset */
252b5132
RH
639
640 /* Like R_PPC_ADDR16_LO, but referring to the PLT table entry for
641 the symbol. */
642 HOWTO (R_PPC_PLT16_LO, /* type */
643 0, /* rightshift */
644 1, /* size (0 = byte, 1 = short, 2 = long) */
645 16, /* bitsize */
b34976b6 646 FALSE, /* pc_relative */
252b5132
RH
647 0, /* bitpos */
648 complain_overflow_dont, /* complain_on_overflow */
649 bfd_elf_generic_reloc, /* special_function */
650 "R_PPC_PLT16_LO", /* name */
b34976b6 651 FALSE, /* partial_inplace */
252b5132
RH
652 0, /* src_mask */
653 0xffff, /* dst_mask */
b34976b6 654 FALSE), /* pcrel_offset */
252b5132
RH
655
656 /* Like R_PPC_ADDR16_HI, but referring to the PLT table entry for
657 the symbol. */
658 HOWTO (R_PPC_PLT16_HI, /* type */
659 16, /* rightshift */
660 1, /* size (0 = byte, 1 = short, 2 = long) */
661 16, /* bitsize */
b34976b6 662 FALSE, /* pc_relative */
252b5132
RH
663 0, /* bitpos */
664 complain_overflow_bitfield, /* complain_on_overflow */
665 bfd_elf_generic_reloc, /* special_function */
666 "R_PPC_PLT16_HI", /* name */
b34976b6 667 FALSE, /* partial_inplace */
252b5132
RH
668 0, /* src_mask */
669 0xffff, /* dst_mask */
b34976b6 670 FALSE), /* pcrel_offset */
252b5132
RH
671
672 /* Like R_PPC_ADDR16_HA, but referring to the PLT table entry for
673 the symbol. */
674 HOWTO (R_PPC_PLT16_HA, /* type */
675 16, /* rightshift */
676 1, /* size (0 = byte, 1 = short, 2 = long) */
677 16, /* bitsize */
b34976b6 678 FALSE, /* pc_relative */
252b5132
RH
679 0, /* bitpos */
680 complain_overflow_bitfield, /* complain_on_overflow */
681 ppc_elf_addr16_ha_reloc, /* special_function */
682 "R_PPC_PLT16_HA", /* name */
b34976b6 683 FALSE, /* partial_inplace */
252b5132
RH
684 0, /* src_mask */
685 0xffff, /* dst_mask */
b34976b6 686 FALSE), /* pcrel_offset */
252b5132
RH
687
688 /* A sign-extended 16 bit value relative to _SDA_BASE_, for use with
689 small data items. */
690 HOWTO (R_PPC_SDAREL16, /* type */
691 0, /* rightshift */
692 1, /* size (0 = byte, 1 = short, 2 = long) */
693 16, /* bitsize */
b34976b6 694 FALSE, /* pc_relative */
252b5132
RH
695 0, /* bitpos */
696 complain_overflow_signed, /* complain_on_overflow */
697 bfd_elf_generic_reloc, /* special_function */
698 "R_PPC_SDAREL16", /* name */
b34976b6 699 FALSE, /* partial_inplace */
252b5132
RH
700 0, /* src_mask */
701 0xffff, /* dst_mask */
b34976b6 702 FALSE), /* pcrel_offset */
252b5132 703
c061c2d8 704 /* 16-bit section relative relocation. */
252b5132
RH
705 HOWTO (R_PPC_SECTOFF, /* type */
706 0, /* rightshift */
c061c2d8
AM
707 1, /* size (0 = byte, 1 = short, 2 = long) */
708 16, /* bitsize */
b34976b6 709 FALSE, /* pc_relative */
252b5132
RH
710 0, /* bitpos */
711 complain_overflow_bitfield, /* complain_on_overflow */
712 bfd_elf_generic_reloc, /* special_function */
713 "R_PPC_SECTOFF", /* name */
b34976b6 714 FALSE, /* partial_inplace */
252b5132 715 0, /* src_mask */
c061c2d8 716 0xffff, /* dst_mask */
b34976b6 717 FALSE), /* pcrel_offset */
252b5132 718
c3668558 719 /* 16-bit lower half section relative relocation. */
252b5132
RH
720 HOWTO (R_PPC_SECTOFF_LO, /* type */
721 0, /* rightshift */
722 1, /* size (0 = byte, 1 = short, 2 = long) */
723 16, /* bitsize */
b34976b6 724 FALSE, /* pc_relative */
252b5132
RH
725 0, /* bitpos */
726 complain_overflow_dont, /* complain_on_overflow */
727 bfd_elf_generic_reloc, /* special_function */
728 "R_PPC_SECTOFF_LO", /* name */
b34976b6 729 FALSE, /* partial_inplace */
252b5132
RH
730 0, /* src_mask */
731 0xffff, /* dst_mask */
b34976b6 732 FALSE), /* pcrel_offset */
252b5132 733
c3668558 734 /* 16-bit upper half section relative relocation. */
252b5132
RH
735 HOWTO (R_PPC_SECTOFF_HI, /* type */
736 16, /* rightshift */
737 1, /* size (0 = byte, 1 = short, 2 = long) */
738 16, /* bitsize */
b34976b6 739 FALSE, /* pc_relative */
252b5132
RH
740 0, /* bitpos */
741 complain_overflow_bitfield, /* complain_on_overflow */
742 bfd_elf_generic_reloc, /* special_function */
743 "R_PPC_SECTOFF_HI", /* name */
b34976b6 744 FALSE, /* partial_inplace */
252b5132
RH
745 0, /* src_mask */
746 0xffff, /* dst_mask */
b34976b6 747 FALSE), /* pcrel_offset */
252b5132 748
c3668558 749 /* 16-bit upper half adjusted section relative relocation. */
252b5132
RH
750 HOWTO (R_PPC_SECTOFF_HA, /* type */
751 16, /* rightshift */
752 1, /* size (0 = byte, 1 = short, 2 = long) */
753 16, /* bitsize */
b34976b6 754 FALSE, /* pc_relative */
252b5132
RH
755 0, /* bitpos */
756 complain_overflow_bitfield, /* complain_on_overflow */
757 ppc_elf_addr16_ha_reloc, /* special_function */
758 "R_PPC_SECTOFF_HA", /* name */
b34976b6 759 FALSE, /* partial_inplace */
252b5132
RH
760 0, /* src_mask */
761 0xffff, /* dst_mask */
b34976b6 762 FALSE), /* pcrel_offset */
252b5132 763
727fc41e 764 /* Marker relocs for TLS. */
7619e7c7 765 HOWTO (R_PPC_TLS,
252b5132
RH
766 0, /* rightshift */
767 2, /* size (0 = byte, 1 = short, 2 = long) */
768 32, /* bitsize */
b34976b6 769 FALSE, /* pc_relative */
252b5132 770 0, /* bitpos */
7619e7c7 771 complain_overflow_dont, /* complain_on_overflow */
252b5132 772 bfd_elf_generic_reloc, /* special_function */
7619e7c7
AM
773 "R_PPC_TLS", /* name */
774 FALSE, /* partial_inplace */
775 0, /* src_mask */
776 0, /* dst_mask */
777 FALSE), /* pcrel_offset */
778
727fc41e
AM
779 HOWTO (R_PPC_TLSGD,
780 0, /* rightshift */
781 2, /* size (0 = byte, 1 = short, 2 = long) */
782 32, /* bitsize */
783 FALSE, /* pc_relative */
784 0, /* bitpos */
785 complain_overflow_dont, /* complain_on_overflow */
786 bfd_elf_generic_reloc, /* special_function */
787 "R_PPC_TLSGD", /* name */
788 FALSE, /* partial_inplace */
789 0, /* src_mask */
790 0, /* dst_mask */
791 FALSE), /* pcrel_offset */
792
793 HOWTO (R_PPC_TLSLD,
794 0, /* rightshift */
795 2, /* size (0 = byte, 1 = short, 2 = long) */
796 32, /* bitsize */
797 FALSE, /* pc_relative */
798 0, /* bitpos */
799 complain_overflow_dont, /* complain_on_overflow */
800 bfd_elf_generic_reloc, /* special_function */
801 "R_PPC_TLSLD", /* name */
802 FALSE, /* partial_inplace */
803 0, /* src_mask */
804 0, /* dst_mask */
805 FALSE), /* pcrel_offset */
806
7619e7c7
AM
807 /* Computes the load module index of the load module that contains the
808 definition of its TLS sym. */
809 HOWTO (R_PPC_DTPMOD32,
810 0, /* rightshift */
811 2, /* size (0 = byte, 1 = short, 2 = long) */
812 32, /* bitsize */
813 FALSE, /* pc_relative */
814 0, /* bitpos */
815 complain_overflow_dont, /* complain_on_overflow */
816 ppc_elf_unhandled_reloc, /* special_function */
817 "R_PPC_DTPMOD32", /* name */
b34976b6 818 FALSE, /* partial_inplace */
252b5132
RH
819 0, /* src_mask */
820 0xffffffff, /* dst_mask */
b34976b6 821 FALSE), /* pcrel_offset */
252b5132 822
7619e7c7
AM
823 /* Computes a dtv-relative displacement, the difference between the value
824 of sym+add and the base address of the thread-local storage block that
825 contains the definition of sym, minus 0x8000. */
826 HOWTO (R_PPC_DTPREL32,
827 0, /* rightshift */
828 2, /* size (0 = byte, 1 = short, 2 = long) */
829 32, /* bitsize */
830 FALSE, /* pc_relative */
831 0, /* bitpos */
832 complain_overflow_dont, /* complain_on_overflow */
833 ppc_elf_unhandled_reloc, /* special_function */
834 "R_PPC_DTPREL32", /* name */
835 FALSE, /* partial_inplace */
836 0, /* src_mask */
837 0xffffffff, /* dst_mask */
838 FALSE), /* pcrel_offset */
839
840 /* A 16 bit dtprel reloc. */
841 HOWTO (R_PPC_DTPREL16,
252b5132
RH
842 0, /* rightshift */
843 1, /* size (0 = byte, 1 = short, 2 = long) */
844 16, /* bitsize */
b34976b6 845 FALSE, /* pc_relative */
252b5132 846 0, /* bitpos */
7619e7c7
AM
847 complain_overflow_signed, /* complain_on_overflow */
848 ppc_elf_unhandled_reloc, /* special_function */
849 "R_PPC_DTPREL16", /* name */
b34976b6 850 FALSE, /* partial_inplace */
252b5132
RH
851 0, /* src_mask */
852 0xffff, /* dst_mask */
b34976b6 853 FALSE), /* pcrel_offset */
252b5132 854
7619e7c7
AM
855 /* Like DTPREL16, but no overflow. */
856 HOWTO (R_PPC_DTPREL16_LO,
252b5132
RH
857 0, /* rightshift */
858 1, /* size (0 = byte, 1 = short, 2 = long) */
859 16, /* bitsize */
b34976b6 860 FALSE, /* pc_relative */
252b5132 861 0, /* bitpos */
7619e7c7
AM
862 complain_overflow_dont, /* complain_on_overflow */
863 ppc_elf_unhandled_reloc, /* special_function */
864 "R_PPC_DTPREL16_LO", /* name */
b34976b6 865 FALSE, /* partial_inplace */
252b5132
RH
866 0, /* src_mask */
867 0xffff, /* dst_mask */
b34976b6 868 FALSE), /* pcrel_offset */
252b5132 869
7619e7c7
AM
870 /* Like DTPREL16_LO, but next higher group of 16 bits. */
871 HOWTO (R_PPC_DTPREL16_HI,
252b5132
RH
872 16, /* rightshift */
873 1, /* size (0 = byte, 1 = short, 2 = long) */
874 16, /* bitsize */
b34976b6 875 FALSE, /* pc_relative */
252b5132
RH
876 0, /* bitpos */
877 complain_overflow_dont, /* complain_on_overflow */
7619e7c7
AM
878 ppc_elf_unhandled_reloc, /* special_function */
879 "R_PPC_DTPREL16_HI", /* name */
b34976b6 880 FALSE, /* partial_inplace */
252b5132
RH
881 0, /* src_mask */
882 0xffff, /* dst_mask */
b34976b6 883 FALSE), /* pcrel_offset */
252b5132 884
7619e7c7
AM
885 /* Like DTPREL16_HI, but adjust for low 16 bits. */
886 HOWTO (R_PPC_DTPREL16_HA,
252b5132
RH
887 16, /* rightshift */
888 1, /* size (0 = byte, 1 = short, 2 = long) */
889 16, /* bitsize */
b34976b6 890 FALSE, /* pc_relative */
252b5132
RH
891 0, /* bitpos */
892 complain_overflow_dont, /* complain_on_overflow */
7619e7c7
AM
893 ppc_elf_unhandled_reloc, /* special_function */
894 "R_PPC_DTPREL16_HA", /* name */
b34976b6 895 FALSE, /* partial_inplace */
252b5132
RH
896 0, /* src_mask */
897 0xffff, /* dst_mask */
b34976b6 898 FALSE), /* pcrel_offset */
252b5132 899
7619e7c7
AM
900 /* Computes a tp-relative displacement, the difference between the value of
901 sym+add and the value of the thread pointer (r13). */
902 HOWTO (R_PPC_TPREL32,
903 0, /* rightshift */
904 2, /* size (0 = byte, 1 = short, 2 = long) */
905 32, /* bitsize */
906 FALSE, /* pc_relative */
907 0, /* bitpos */
908 complain_overflow_dont, /* complain_on_overflow */
909 ppc_elf_unhandled_reloc, /* special_function */
910 "R_PPC_TPREL32", /* name */
911 FALSE, /* partial_inplace */
912 0, /* src_mask */
913 0xffffffff, /* dst_mask */
914 FALSE), /* pcrel_offset */
915
916 /* A 16 bit tprel reloc. */
917 HOWTO (R_PPC_TPREL16,
252b5132
RH
918 0, /* rightshift */
919 1, /* size (0 = byte, 1 = short, 2 = long) */
920 16, /* bitsize */
b34976b6 921 FALSE, /* pc_relative */
252b5132 922 0, /* bitpos */
7619e7c7
AM
923 complain_overflow_signed, /* complain_on_overflow */
924 ppc_elf_unhandled_reloc, /* special_function */
925 "R_PPC_TPREL16", /* name */
b34976b6 926 FALSE, /* partial_inplace */
252b5132
RH
927 0, /* src_mask */
928 0xffff, /* dst_mask */
b34976b6 929 FALSE), /* pcrel_offset */
252b5132 930
7619e7c7
AM
931 /* Like TPREL16, but no overflow. */
932 HOWTO (R_PPC_TPREL16_LO,
252b5132
RH
933 0, /* rightshift */
934 1, /* size (0 = byte, 1 = short, 2 = long) */
935 16, /* bitsize */
b34976b6 936 FALSE, /* pc_relative */
252b5132 937 0, /* bitpos */
7619e7c7
AM
938 complain_overflow_dont, /* complain_on_overflow */
939 ppc_elf_unhandled_reloc, /* special_function */
940 "R_PPC_TPREL16_LO", /* name */
b34976b6 941 FALSE, /* partial_inplace */
252b5132
RH
942 0, /* src_mask */
943 0xffff, /* dst_mask */
b34976b6 944 FALSE), /* pcrel_offset */
252b5132 945
7619e7c7
AM
946 /* Like TPREL16_LO, but next higher group of 16 bits. */
947 HOWTO (R_PPC_TPREL16_HI,
948 16, /* rightshift */
949 1, /* size (0 = byte, 1 = short, 2 = long) */
950 16, /* bitsize */
951 FALSE, /* pc_relative */
952 0, /* bitpos */
953 complain_overflow_dont, /* complain_on_overflow */
954 ppc_elf_unhandled_reloc, /* special_function */
955 "R_PPC_TPREL16_HI", /* name */
956 FALSE, /* partial_inplace */
957 0, /* src_mask */
958 0xffff, /* dst_mask */
959 FALSE), /* pcrel_offset */
960
961 /* Like TPREL16_HI, but adjust for low 16 bits. */
962 HOWTO (R_PPC_TPREL16_HA,
963 16, /* rightshift */
964 1, /* size (0 = byte, 1 = short, 2 = long) */
965 16, /* bitsize */
966 FALSE, /* pc_relative */
967 0, /* bitpos */
968 complain_overflow_dont, /* complain_on_overflow */
969 ppc_elf_unhandled_reloc, /* special_function */
970 "R_PPC_TPREL16_HA", /* name */
971 FALSE, /* partial_inplace */
972 0, /* src_mask */
973 0xffff, /* dst_mask */
974 FALSE), /* pcrel_offset */
975
976 /* Allocates two contiguous entries in the GOT to hold a tls_index structure,
977 with values (sym+add)@dtpmod and (sym+add)@dtprel, and computes the offset
978 to the first entry. */
979 HOWTO (R_PPC_GOT_TLSGD16,
252b5132
RH
980 0, /* rightshift */
981 1, /* size (0 = byte, 1 = short, 2 = long) */
982 16, /* bitsize */
b34976b6 983 FALSE, /* pc_relative */
252b5132
RH
984 0, /* bitpos */
985 complain_overflow_signed, /* complain_on_overflow */
7619e7c7
AM
986 ppc_elf_unhandled_reloc, /* special_function */
987 "R_PPC_GOT_TLSGD16", /* name */
b34976b6 988 FALSE, /* partial_inplace */
252b5132
RH
989 0, /* src_mask */
990 0xffff, /* dst_mask */
b34976b6 991 FALSE), /* pcrel_offset */
252b5132 992
7619e7c7
AM
993 /* Like GOT_TLSGD16, but no overflow. */
994 HOWTO (R_PPC_GOT_TLSGD16_LO,
252b5132 995 0, /* rightshift */
7619e7c7 996 1, /* size (0 = byte, 1 = short, 2 = long) */
252b5132 997 16, /* bitsize */
b34976b6 998 FALSE, /* pc_relative */
252b5132 999 0, /* bitpos */
7619e7c7
AM
1000 complain_overflow_dont, /* complain_on_overflow */
1001 ppc_elf_unhandled_reloc, /* special_function */
1002 "R_PPC_GOT_TLSGD16_LO", /* name */
b34976b6 1003 FALSE, /* partial_inplace */
252b5132
RH
1004 0, /* src_mask */
1005 0xffff, /* dst_mask */
b34976b6 1006 FALSE), /* pcrel_offset */
252b5132 1007
7619e7c7
AM
1008 /* Like GOT_TLSGD16_LO, but next higher group of 16 bits. */
1009 HOWTO (R_PPC_GOT_TLSGD16_HI,
1010 16, /* rightshift */
1011 1, /* size (0 = byte, 1 = short, 2 = long) */
1012 16, /* bitsize */
1013 FALSE, /* pc_relative */
1014 0, /* bitpos */
1015 complain_overflow_dont, /* complain_on_overflow */
1016 ppc_elf_unhandled_reloc, /* special_function */
1017 "R_PPC_GOT_TLSGD16_HI", /* name */
1018 FALSE, /* partial_inplace */
1019 0, /* src_mask */
1020 0xffff, /* dst_mask */
1021 FALSE), /* pcrel_offset */
252b5132 1022
7619e7c7
AM
1023 /* Like GOT_TLSGD16_HI, but adjust for low 16 bits. */
1024 HOWTO (R_PPC_GOT_TLSGD16_HA,
1025 16, /* rightshift */
1026 1, /* size (0 = byte, 1 = short, 2 = long) */
1027 16, /* bitsize */
1028 FALSE, /* pc_relative */
1029 0, /* bitpos */
1030 complain_overflow_dont, /* complain_on_overflow */
1031 ppc_elf_unhandled_reloc, /* special_function */
1032 "R_PPC_GOT_TLSGD16_HA", /* name */
1033 FALSE, /* partial_inplace */
1034 0, /* src_mask */
1035 0xffff, /* dst_mask */
1036 FALSE), /* pcrel_offset */
1037
1038 /* Allocates two contiguous entries in the GOT to hold a tls_index structure,
1039 with values (sym+add)@dtpmod and zero, and computes the offset to the
1040 first entry. */
1041 HOWTO (R_PPC_GOT_TLSLD16,
252b5132
RH
1042 0, /* rightshift */
1043 1, /* size (0 = byte, 1 = short, 2 = long) */
1044 16, /* bitsize */
7619e7c7 1045 FALSE, /* pc_relative */
252b5132
RH
1046 0, /* bitpos */
1047 complain_overflow_signed, /* complain_on_overflow */
7619e7c7
AM
1048 ppc_elf_unhandled_reloc, /* special_function */
1049 "R_PPC_GOT_TLSLD16", /* name */
b34976b6 1050 FALSE, /* partial_inplace */
252b5132
RH
1051 0, /* src_mask */
1052 0xffff, /* dst_mask */
b34976b6 1053 FALSE), /* pcrel_offset */
252b5132 1054
7619e7c7
AM
1055 /* Like GOT_TLSLD16, but no overflow. */
1056 HOWTO (R_PPC_GOT_TLSLD16_LO,
252b5132 1057 0, /* rightshift */
7619e7c7
AM
1058 1, /* size (0 = byte, 1 = short, 2 = long) */
1059 16, /* bitsize */
b34976b6 1060 FALSE, /* pc_relative */
252b5132
RH
1061 0, /* bitpos */
1062 complain_overflow_dont, /* complain_on_overflow */
7619e7c7
AM
1063 ppc_elf_unhandled_reloc, /* special_function */
1064 "R_PPC_GOT_TLSLD16_LO", /* name */
b34976b6 1065 FALSE, /* partial_inplace */
252b5132 1066 0, /* src_mask */
7619e7c7 1067 0xffff, /* dst_mask */
b34976b6 1068 FALSE), /* pcrel_offset */
252b5132 1069
7619e7c7
AM
1070 /* Like GOT_TLSLD16_LO, but next higher group of 16 bits. */
1071 HOWTO (R_PPC_GOT_TLSLD16_HI,
1072 16, /* rightshift */
1073 1, /* size (0 = byte, 1 = short, 2 = long) */
1074 16, /* bitsize */
b34976b6 1075 FALSE, /* pc_relative */
252b5132
RH
1076 0, /* bitpos */
1077 complain_overflow_dont, /* complain_on_overflow */
7619e7c7
AM
1078 ppc_elf_unhandled_reloc, /* special_function */
1079 "R_PPC_GOT_TLSLD16_HI", /* name */
b34976b6 1080 FALSE, /* partial_inplace */
252b5132 1081 0, /* src_mask */
7619e7c7 1082 0xffff, /* dst_mask */
b34976b6 1083 FALSE), /* pcrel_offset */
252b5132 1084
7619e7c7
AM
1085 /* Like GOT_TLSLD16_HI, but adjust for low 16 bits. */
1086 HOWTO (R_PPC_GOT_TLSLD16_HA,
1087 16, /* rightshift */
1088 1, /* size (0 = byte, 1 = short, 2 = long) */
1089 16, /* bitsize */
1090 FALSE, /* pc_relative */
1091 0, /* bitpos */
1092 complain_overflow_dont, /* complain_on_overflow */
1093 ppc_elf_unhandled_reloc, /* special_function */
1094 "R_PPC_GOT_TLSLD16_HA", /* name */
1095 FALSE, /* partial_inplace */
1096 0, /* src_mask */
1097 0xffff, /* dst_mask */
1098 FALSE), /* pcrel_offset */
1099
1100 /* Allocates an entry in the GOT with value (sym+add)@dtprel, and computes
1101 the offset to the entry. */
1102 HOWTO (R_PPC_GOT_DTPREL16,
252b5132
RH
1103 0, /* rightshift */
1104 1, /* size (0 = byte, 1 = short, 2 = long) */
1105 16, /* bitsize */
b34976b6 1106 FALSE, /* pc_relative */
252b5132
RH
1107 0, /* bitpos */
1108 complain_overflow_signed, /* complain_on_overflow */
7619e7c7
AM
1109 ppc_elf_unhandled_reloc, /* special_function */
1110 "R_PPC_GOT_DTPREL16", /* name */
b34976b6 1111 FALSE, /* partial_inplace */
252b5132
RH
1112 0, /* src_mask */
1113 0xffff, /* dst_mask */
b34976b6 1114 FALSE), /* pcrel_offset */
252b5132 1115
7619e7c7
AM
1116 /* Like GOT_DTPREL16, but no overflow. */
1117 HOWTO (R_PPC_GOT_DTPREL16_LO,
1118 0, /* rightshift */
1119 1, /* size (0 = byte, 1 = short, 2 = long) */
1120 16, /* bitsize */
1121 FALSE, /* pc_relative */
1122 0, /* bitpos */
1123 complain_overflow_dont, /* complain_on_overflow */
1124 ppc_elf_unhandled_reloc, /* special_function */
1125 "R_PPC_GOT_DTPREL16_LO", /* name */
1126 FALSE, /* partial_inplace */
1127 0, /* src_mask */
1128 0xffff, /* dst_mask */
1129 FALSE), /* pcrel_offset */
252b5132 1130
7619e7c7
AM
1131 /* Like GOT_DTPREL16_LO, but next higher group of 16 bits. */
1132 HOWTO (R_PPC_GOT_DTPREL16_HI,
1133 16, /* rightshift */
1134 1, /* size (0 = byte, 1 = short, 2 = long) */
1135 16, /* bitsize */
1136 FALSE, /* pc_relative */
1137 0, /* bitpos */
1138 complain_overflow_dont, /* complain_on_overflow */
1139 ppc_elf_unhandled_reloc, /* special_function */
1140 "R_PPC_GOT_DTPREL16_HI", /* name */
1141 FALSE, /* partial_inplace */
1142 0, /* src_mask */
1143 0xffff, /* dst_mask */
1144 FALSE), /* pcrel_offset */
252b5132 1145
7619e7c7
AM
1146 /* Like GOT_DTPREL16_HI, but adjust for low 16 bits. */
1147 HOWTO (R_PPC_GOT_DTPREL16_HA,
1148 16, /* rightshift */
1149 1, /* size (0 = byte, 1 = short, 2 = long) */
1150 16, /* bitsize */
1151 FALSE, /* pc_relative */
1152 0, /* bitpos */
1153 complain_overflow_dont, /* complain_on_overflow */
1154 ppc_elf_unhandled_reloc, /* special_function */
1155 "R_PPC_GOT_DTPREL16_HA", /* name */
1156 FALSE, /* partial_inplace */
1157 0, /* src_mask */
1158 0xffff, /* dst_mask */
1159 FALSE), /* pcrel_offset */
c3668558 1160
7619e7c7
AM
1161 /* Allocates an entry in the GOT with value (sym+add)@tprel, and computes the
1162 offset to the entry. */
1163 HOWTO (R_PPC_GOT_TPREL16,
1164 0, /* rightshift */
1165 1, /* size (0 = byte, 1 = short, 2 = long) */
1166 16, /* bitsize */
1167 FALSE, /* pc_relative */
1168 0, /* bitpos */
1169 complain_overflow_signed, /* complain_on_overflow */
1170 ppc_elf_unhandled_reloc, /* special_function */
1171 "R_PPC_GOT_TPREL16", /* name */
1172 FALSE, /* partial_inplace */
1173 0, /* src_mask */
1174 0xffff, /* dst_mask */
1175 FALSE), /* pcrel_offset */
1176
1177 /* Like GOT_TPREL16, but no overflow. */
1178 HOWTO (R_PPC_GOT_TPREL16_LO,
1179 0, /* rightshift */
1180 1, /* size (0 = byte, 1 = short, 2 = long) */
1181 16, /* bitsize */
1182 FALSE, /* pc_relative */
1183 0, /* bitpos */
1184 complain_overflow_dont, /* complain_on_overflow */
1185 ppc_elf_unhandled_reloc, /* special_function */
1186 "R_PPC_GOT_TPREL16_LO", /* name */
1187 FALSE, /* partial_inplace */
1188 0, /* src_mask */
1189 0xffff, /* dst_mask */
1190 FALSE), /* pcrel_offset */
1191
1192 /* Like GOT_TPREL16_LO, but next higher group of 16 bits. */
1193 HOWTO (R_PPC_GOT_TPREL16_HI,
1194 16, /* rightshift */
1195 1, /* size (0 = byte, 1 = short, 2 = long) */
1196 16, /* bitsize */
1197 FALSE, /* pc_relative */
1198 0, /* bitpos */
1199 complain_overflow_dont, /* complain_on_overflow */
1200 ppc_elf_unhandled_reloc, /* special_function */
1201 "R_PPC_GOT_TPREL16_HI", /* name */
1202 FALSE, /* partial_inplace */
1203 0, /* src_mask */
1204 0xffff, /* dst_mask */
1205 FALSE), /* pcrel_offset */
1206
1207 /* Like GOT_TPREL16_HI, but adjust for low 16 bits. */
1208 HOWTO (R_PPC_GOT_TPREL16_HA,
1209 16, /* rightshift */
1210 1, /* size (0 = byte, 1 = short, 2 = long) */
1211 16, /* bitsize */
1212 FALSE, /* pc_relative */
1213 0, /* bitpos */
1214 complain_overflow_dont, /* complain_on_overflow */
1215 ppc_elf_unhandled_reloc, /* special_function */
1216 "R_PPC_GOT_TPREL16_HA", /* name */
1217 FALSE, /* partial_inplace */
1218 0, /* src_mask */
1219 0xffff, /* dst_mask */
1220 FALSE), /* pcrel_offset */
1221
1222 /* The remaining relocs are from the Embedded ELF ABI, and are not
1223 in the SVR4 ELF ABI. */
1224
1225 /* 32 bit value resulting from the addend minus the symbol. */
1226 HOWTO (R_PPC_EMB_NADDR32, /* type */
1227 0, /* rightshift */
1228 2, /* size (0 = byte, 1 = short, 2 = long) */
1229 32, /* bitsize */
1230 FALSE, /* pc_relative */
1231 0, /* bitpos */
1232 complain_overflow_bitfield, /* complain_on_overflow */
1233 bfd_elf_generic_reloc, /* special_function */
1234 "R_PPC_EMB_NADDR32", /* name */
1235 FALSE, /* partial_inplace */
1236 0, /* src_mask */
1237 0xffffffff, /* dst_mask */
1238 FALSE), /* pcrel_offset */
1239
1240 /* 16 bit value resulting from the addend minus the symbol. */
1241 HOWTO (R_PPC_EMB_NADDR16, /* type */
1242 0, /* rightshift */
1243 1, /* size (0 = byte, 1 = short, 2 = long) */
1244 16, /* bitsize */
1245 FALSE, /* pc_relative */
1246 0, /* bitpos */
1247 complain_overflow_bitfield, /* complain_on_overflow */
1248 bfd_elf_generic_reloc, /* special_function */
1249 "R_PPC_EMB_NADDR16", /* name */
1250 FALSE, /* partial_inplace */
1251 0, /* src_mask */
1252 0xffff, /* dst_mask */
1253 FALSE), /* pcrel_offset */
1254
1255 /* 16 bit value resulting from the addend minus the symbol. */
1256 HOWTO (R_PPC_EMB_NADDR16_LO, /* type */
1257 0, /* rightshift */
1258 1, /* size (0 = byte, 1 = short, 2 = long) */
1259 16, /* bitsize */
1260 FALSE, /* pc_relative */
1261 0, /* bitpos */
1262 complain_overflow_dont,/* complain_on_overflow */
1263 bfd_elf_generic_reloc, /* special_function */
1264 "R_PPC_EMB_ADDR16_LO", /* name */
1265 FALSE, /* partial_inplace */
1266 0, /* src_mask */
1267 0xffff, /* dst_mask */
1268 FALSE), /* pcrel_offset */
1269
1270 /* The high order 16 bits of the addend minus the symbol. */
1271 HOWTO (R_PPC_EMB_NADDR16_HI, /* type */
1272 16, /* rightshift */
1273 1, /* size (0 = byte, 1 = short, 2 = long) */
1274 16, /* bitsize */
1275 FALSE, /* pc_relative */
1276 0, /* bitpos */
1277 complain_overflow_dont, /* complain_on_overflow */
1278 bfd_elf_generic_reloc, /* special_function */
1279 "R_PPC_EMB_NADDR16_HI", /* name */
1280 FALSE, /* partial_inplace */
1281 0, /* src_mask */
1282 0xffff, /* dst_mask */
1283 FALSE), /* pcrel_offset */
1284
1285 /* The high order 16 bits of the result of the addend minus the address,
1286 plus 1 if the contents of the low 16 bits, treated as a signed number,
1287 is negative. */
1288 HOWTO (R_PPC_EMB_NADDR16_HA, /* type */
1289 16, /* rightshift */
1290 1, /* size (0 = byte, 1 = short, 2 = long) */
1291 16, /* bitsize */
1292 FALSE, /* pc_relative */
1293 0, /* bitpos */
1294 complain_overflow_dont, /* complain_on_overflow */
25dbc73a
AM
1295 ppc_elf_addr16_ha_reloc, /* special_function */
1296 "R_PPC_EMB_NADDR16_HA", /* name */
1297 FALSE, /* partial_inplace */
1298 0, /* src_mask */
1299 0xffff, /* dst_mask */
1300 FALSE), /* pcrel_offset */
1301
1302 /* 16 bit value resulting from allocating a 4 byte word to hold an
1303 address in the .sdata section, and returning the offset from
1304 _SDA_BASE_ for that relocation. */
1305 HOWTO (R_PPC_EMB_SDAI16, /* type */
1306 0, /* rightshift */
1307 1, /* size (0 = byte, 1 = short, 2 = long) */
1308 16, /* bitsize */
1309 FALSE, /* pc_relative */
1310 0, /* bitpos */
bd6c6e2b 1311 complain_overflow_signed, /* complain_on_overflow */
25dbc73a
AM
1312 bfd_elf_generic_reloc, /* special_function */
1313 "R_PPC_EMB_SDAI16", /* name */
1314 FALSE, /* partial_inplace */
1315 0, /* src_mask */
1316 0xffff, /* dst_mask */
1317 FALSE), /* pcrel_offset */
1318
1319 /* 16 bit value resulting from allocating a 4 byte word to hold an
1320 address in the .sdata2 section, and returning the offset from
1321 _SDA2_BASE_ for that relocation. */
1322 HOWTO (R_PPC_EMB_SDA2I16, /* type */
1323 0, /* rightshift */
1324 1, /* size (0 = byte, 1 = short, 2 = long) */
1325 16, /* bitsize */
1326 FALSE, /* pc_relative */
1327 0, /* bitpos */
bd6c6e2b 1328 complain_overflow_signed, /* complain_on_overflow */
25dbc73a
AM
1329 bfd_elf_generic_reloc, /* special_function */
1330 "R_PPC_EMB_SDA2I16", /* name */
1331 FALSE, /* partial_inplace */
1332 0, /* src_mask */
1333 0xffff, /* dst_mask */
1334 FALSE), /* pcrel_offset */
1335
1336 /* A sign-extended 16 bit value relative to _SDA2_BASE_, for use with
1337 small data items. */
1338 HOWTO (R_PPC_EMB_SDA2REL, /* type */
1339 0, /* rightshift */
1340 1, /* size (0 = byte, 1 = short, 2 = long) */
1341 16, /* bitsize */
1342 FALSE, /* pc_relative */
1343 0, /* bitpos */
1344 complain_overflow_signed, /* complain_on_overflow */
1345 bfd_elf_generic_reloc, /* special_function */
1346 "R_PPC_EMB_SDA2REL", /* name */
1347 FALSE, /* partial_inplace */
1348 0, /* src_mask */
1349 0xffff, /* dst_mask */
1350 FALSE), /* pcrel_offset */
1351
1352 /* Relocate against either _SDA_BASE_ or _SDA2_BASE_, filling in the 16 bit
1353 signed offset from the appropriate base, and filling in the register
1354 field with the appropriate register (0, 2, or 13). */
1355 HOWTO (R_PPC_EMB_SDA21, /* type */
1356 0, /* rightshift */
1357 2, /* size (0 = byte, 1 = short, 2 = long) */
1358 16, /* bitsize */
1359 FALSE, /* pc_relative */
1360 0, /* bitpos */
1361 complain_overflow_signed, /* complain_on_overflow */
1362 bfd_elf_generic_reloc, /* special_function */
1363 "R_PPC_EMB_SDA21", /* name */
1364 FALSE, /* partial_inplace */
1365 0, /* src_mask */
1366 0xffff, /* dst_mask */
1367 FALSE), /* pcrel_offset */
1368
1369 /* Relocation not handled: R_PPC_EMB_MRKREF */
1370 /* Relocation not handled: R_PPC_EMB_RELSEC16 */
1371 /* Relocation not handled: R_PPC_EMB_RELST_LO */
1372 /* Relocation not handled: R_PPC_EMB_RELST_HI */
1373 /* Relocation not handled: R_PPC_EMB_RELST_HA */
1374 /* Relocation not handled: R_PPC_EMB_BIT_FLD */
1375
1376 /* PC relative relocation against either _SDA_BASE_ or _SDA2_BASE_, filling
1377 in the 16 bit signed offset from the appropriate base, and filling in the
1378 register field with the appropriate register (0, 2, or 13). */
1379 HOWTO (R_PPC_EMB_RELSDA, /* type */
1380 0, /* rightshift */
1381 1, /* size (0 = byte, 1 = short, 2 = long) */
1382 16, /* bitsize */
ddfd6795 1383 FALSE, /* pc_relative */
25dbc73a
AM
1384 0, /* bitpos */
1385 complain_overflow_signed, /* complain_on_overflow */
1386 bfd_elf_generic_reloc, /* special_function */
1387 "R_PPC_EMB_RELSDA", /* name */
1388 FALSE, /* partial_inplace */
1389 0, /* src_mask */
1390 0xffff, /* dst_mask */
1391 FALSE), /* pcrel_offset */
1392
e054468f
AM
1393 HOWTO (R_PPC_IRELATIVE, /* type */
1394 0, /* rightshift */
1395 2, /* size (0 = byte, 1 = short, 2 = long) */
1396 32, /* bitsize */
1397 FALSE, /* pc_relative */
1398 0, /* bitpos */
1399 complain_overflow_bitfield, /* complain_on_overflow */
1400 bfd_elf_generic_reloc, /* special_function */
1401 "R_PPC_IRELATIVE", /* name */
1402 FALSE, /* partial_inplace */
1403 0, /* src_mask */
1404 0xffffffff, /* dst_mask */
1405 FALSE), /* pcrel_offset */
1406
d7128ce4
AM
1407 /* A 16 bit relative relocation. */
1408 HOWTO (R_PPC_REL16, /* type */
1409 0, /* rightshift */
1410 1, /* size (0 = byte, 1 = short, 2 = long) */
1411 16, /* bitsize */
1412 TRUE, /* pc_relative */
1413 0, /* bitpos */
1414 complain_overflow_bitfield, /* complain_on_overflow */
1415 bfd_elf_generic_reloc, /* special_function */
1416 "R_PPC_REL16", /* name */
1417 FALSE, /* partial_inplace */
1418 0, /* src_mask */
1419 0xffff, /* dst_mask */
1420 TRUE), /* pcrel_offset */
1421
1422 /* A 16 bit relative relocation without overflow. */
1423 HOWTO (R_PPC_REL16_LO, /* type */
1424 0, /* rightshift */
1425 1, /* size (0 = byte, 1 = short, 2 = long) */
1426 16, /* bitsize */
1427 TRUE, /* pc_relative */
1428 0, /* bitpos */
1429 complain_overflow_dont,/* complain_on_overflow */
1430 bfd_elf_generic_reloc, /* special_function */
1431 "R_PPC_REL16_LO", /* name */
1432 FALSE, /* partial_inplace */
1433 0, /* src_mask */
1434 0xffff, /* dst_mask */
1435 TRUE), /* pcrel_offset */
1436
1437 /* The high order 16 bits of a relative address. */
1438 HOWTO (R_PPC_REL16_HI, /* type */
1439 16, /* rightshift */
1440 1, /* size (0 = byte, 1 = short, 2 = long) */
1441 16, /* bitsize */
1442 TRUE, /* pc_relative */
1443 0, /* bitpos */
1444 complain_overflow_dont, /* complain_on_overflow */
1445 bfd_elf_generic_reloc, /* special_function */
1446 "R_PPC_REL16_HI", /* name */
1447 FALSE, /* partial_inplace */
1448 0, /* src_mask */
1449 0xffff, /* dst_mask */
1450 TRUE), /* pcrel_offset */
1451
1452 /* The high order 16 bits of a relative address, plus 1 if the contents of
1453 the low 16 bits, treated as a signed number, is negative. */
1454 HOWTO (R_PPC_REL16_HA, /* type */
1455 16, /* rightshift */
1456 1, /* size (0 = byte, 1 = short, 2 = long) */
1457 16, /* bitsize */
1458 TRUE, /* pc_relative */
1459 0, /* bitpos */
1460 complain_overflow_dont, /* complain_on_overflow */
1461 ppc_elf_addr16_ha_reloc, /* special_function */
1462 "R_PPC_REL16_HA", /* name */
1463 FALSE, /* partial_inplace */
1464 0, /* src_mask */
1465 0xffff, /* dst_mask */
1466 TRUE), /* pcrel_offset */
1467
25dbc73a
AM
1468 /* GNU extension to record C++ vtable hierarchy. */
1469 HOWTO (R_PPC_GNU_VTINHERIT, /* type */
1470 0, /* rightshift */
1471 0, /* size (0 = byte, 1 = short, 2 = long) */
1472 0, /* bitsize */
1473 FALSE, /* pc_relative */
1474 0, /* bitpos */
1475 complain_overflow_dont, /* complain_on_overflow */
1476 NULL, /* special_function */
1477 "R_PPC_GNU_VTINHERIT", /* name */
1478 FALSE, /* partial_inplace */
1479 0, /* src_mask */
1480 0, /* dst_mask */
1481 FALSE), /* pcrel_offset */
1482
1483 /* GNU extension to record C++ vtable member usage. */
1484 HOWTO (R_PPC_GNU_VTENTRY, /* type */
1485 0, /* rightshift */
1486 0, /* size (0 = byte, 1 = short, 2 = long) */
1487 0, /* bitsize */
1488 FALSE, /* pc_relative */
1489 0, /* bitpos */
1490 complain_overflow_dont, /* complain_on_overflow */
1491 NULL, /* special_function */
1492 "R_PPC_GNU_VTENTRY", /* name */
7619e7c7
AM
1493 FALSE, /* partial_inplace */
1494 0, /* src_mask */
25dbc73a 1495 0, /* dst_mask */
7619e7c7
AM
1496 FALSE), /* pcrel_offset */
1497
25dbc73a
AM
1498 /* Phony reloc to handle AIX style TOC entries. */
1499 HOWTO (R_PPC_TOC16, /* type */
7619e7c7
AM
1500 0, /* rightshift */
1501 1, /* size (0 = byte, 1 = short, 2 = long) */
1502 16, /* bitsize */
1503 FALSE, /* pc_relative */
1504 0, /* bitpos */
25dbc73a 1505 complain_overflow_signed, /* complain_on_overflow */
7619e7c7 1506 bfd_elf_generic_reloc, /* special_function */
25dbc73a 1507 "R_PPC_TOC16", /* name */
7619e7c7
AM
1508 FALSE, /* partial_inplace */
1509 0, /* src_mask */
1510 0xffff, /* dst_mask */
1511 FALSE), /* pcrel_offset */
25dbc73a
AM
1512};
1513\f
1514/* Initialize the ppc_elf_howto_table, so that linear accesses can be done. */
1515
1516static void
1517ppc_elf_howto_init (void)
1518{
1519 unsigned int i, type;
1520
1521 for (i = 0;
1522 i < sizeof (ppc_elf_howto_raw) / sizeof (ppc_elf_howto_raw[0]);
1523 i++)
1524 {
1525 type = ppc_elf_howto_raw[i].type;
1526 if (type >= (sizeof (ppc_elf_howto_table)
1527 / sizeof (ppc_elf_howto_table[0])))
1528 abort ();
1529 ppc_elf_howto_table[type] = &ppc_elf_howto_raw[i];
1530 }
1531}
1532
1533static reloc_howto_type *
1534ppc_elf_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
1535 bfd_reloc_code_real_type code)
1536{
1537 enum elf_ppc_reloc_type r;
1538
1539 /* Initialize howto table if not already done. */
1540 if (!ppc_elf_howto_table[R_PPC_ADDR32])
1541 ppc_elf_howto_init ();
1542
1543 switch (code)
1544 {
1545 default:
1546 return NULL;
1547
1548 case BFD_RELOC_NONE: r = R_PPC_NONE; break;
1549 case BFD_RELOC_32: r = R_PPC_ADDR32; break;
1550 case BFD_RELOC_PPC_BA26: r = R_PPC_ADDR24; break;
1551 case BFD_RELOC_16: r = R_PPC_ADDR16; break;
1552 case BFD_RELOC_LO16: r = R_PPC_ADDR16_LO; break;
1553 case BFD_RELOC_HI16: r = R_PPC_ADDR16_HI; break;
1554 case BFD_RELOC_HI16_S: r = R_PPC_ADDR16_HA; break;
1555 case BFD_RELOC_PPC_BA16: r = R_PPC_ADDR14; break;
1556 case BFD_RELOC_PPC_BA16_BRTAKEN: r = R_PPC_ADDR14_BRTAKEN; break;
1557 case BFD_RELOC_PPC_BA16_BRNTAKEN: r = R_PPC_ADDR14_BRNTAKEN; break;
1558 case BFD_RELOC_PPC_B26: r = R_PPC_REL24; break;
1559 case BFD_RELOC_PPC_B16: r = R_PPC_REL14; break;
1560 case BFD_RELOC_PPC_B16_BRTAKEN: r = R_PPC_REL14_BRTAKEN; break;
1561 case BFD_RELOC_PPC_B16_BRNTAKEN: r = R_PPC_REL14_BRNTAKEN; break;
1562 case BFD_RELOC_16_GOTOFF: r = R_PPC_GOT16; break;
1563 case BFD_RELOC_LO16_GOTOFF: r = R_PPC_GOT16_LO; break;
1564 case BFD_RELOC_HI16_GOTOFF: r = R_PPC_GOT16_HI; break;
1565 case BFD_RELOC_HI16_S_GOTOFF: r = R_PPC_GOT16_HA; break;
1566 case BFD_RELOC_24_PLT_PCREL: r = R_PPC_PLTREL24; break;
1567 case BFD_RELOC_PPC_COPY: r = R_PPC_COPY; break;
1568 case BFD_RELOC_PPC_GLOB_DAT: r = R_PPC_GLOB_DAT; break;
1569 case BFD_RELOC_PPC_LOCAL24PC: r = R_PPC_LOCAL24PC; break;
1570 case BFD_RELOC_32_PCREL: r = R_PPC_REL32; break;
1571 case BFD_RELOC_32_PLTOFF: r = R_PPC_PLT32; break;
1572 case BFD_RELOC_32_PLT_PCREL: r = R_PPC_PLTREL32; break;
1573 case BFD_RELOC_LO16_PLTOFF: r = R_PPC_PLT16_LO; break;
1574 case BFD_RELOC_HI16_PLTOFF: r = R_PPC_PLT16_HI; break;
1575 case BFD_RELOC_HI16_S_PLTOFF: r = R_PPC_PLT16_HA; break;
1576 case BFD_RELOC_GPREL16: r = R_PPC_SDAREL16; break;
1577 case BFD_RELOC_16_BASEREL: r = R_PPC_SECTOFF; break;
1578 case BFD_RELOC_LO16_BASEREL: r = R_PPC_SECTOFF_LO; break;
1579 case BFD_RELOC_HI16_BASEREL: r = R_PPC_SECTOFF_HI; break;
1580 case BFD_RELOC_HI16_S_BASEREL: r = R_PPC_SECTOFF_HA; break;
1581 case BFD_RELOC_CTOR: r = R_PPC_ADDR32; break;
1582 case BFD_RELOC_PPC_TOC16: r = R_PPC_TOC16; break;
1583 case BFD_RELOC_PPC_TLS: r = R_PPC_TLS; break;
727fc41e
AM
1584 case BFD_RELOC_PPC_TLSGD: r = R_PPC_TLSGD; break;
1585 case BFD_RELOC_PPC_TLSLD: r = R_PPC_TLSLD; break;
25dbc73a
AM
1586 case BFD_RELOC_PPC_DTPMOD: r = R_PPC_DTPMOD32; break;
1587 case BFD_RELOC_PPC_TPREL16: r = R_PPC_TPREL16; break;
1588 case BFD_RELOC_PPC_TPREL16_LO: r = R_PPC_TPREL16_LO; break;
1589 case BFD_RELOC_PPC_TPREL16_HI: r = R_PPC_TPREL16_HI; break;
1590 case BFD_RELOC_PPC_TPREL16_HA: r = R_PPC_TPREL16_HA; break;
1591 case BFD_RELOC_PPC_TPREL: r = R_PPC_TPREL32; break;
1592 case BFD_RELOC_PPC_DTPREL16: r = R_PPC_DTPREL16; break;
1593 case BFD_RELOC_PPC_DTPREL16_LO: r = R_PPC_DTPREL16_LO; break;
1594 case BFD_RELOC_PPC_DTPREL16_HI: r = R_PPC_DTPREL16_HI; break;
1595 case BFD_RELOC_PPC_DTPREL16_HA: r = R_PPC_DTPREL16_HA; break;
1596 case BFD_RELOC_PPC_DTPREL: r = R_PPC_DTPREL32; break;
1597 case BFD_RELOC_PPC_GOT_TLSGD16: r = R_PPC_GOT_TLSGD16; break;
1598 case BFD_RELOC_PPC_GOT_TLSGD16_LO: r = R_PPC_GOT_TLSGD16_LO; break;
1599 case BFD_RELOC_PPC_GOT_TLSGD16_HI: r = R_PPC_GOT_TLSGD16_HI; break;
1600 case BFD_RELOC_PPC_GOT_TLSGD16_HA: r = R_PPC_GOT_TLSGD16_HA; break;
1601 case BFD_RELOC_PPC_GOT_TLSLD16: r = R_PPC_GOT_TLSLD16; break;
1602 case BFD_RELOC_PPC_GOT_TLSLD16_LO: r = R_PPC_GOT_TLSLD16_LO; break;
1603 case BFD_RELOC_PPC_GOT_TLSLD16_HI: r = R_PPC_GOT_TLSLD16_HI; break;
1604 case BFD_RELOC_PPC_GOT_TLSLD16_HA: r = R_PPC_GOT_TLSLD16_HA; break;
1605 case BFD_RELOC_PPC_GOT_TPREL16: r = R_PPC_GOT_TPREL16; break;
1606 case BFD_RELOC_PPC_GOT_TPREL16_LO: r = R_PPC_GOT_TPREL16_LO; break;
1607 case BFD_RELOC_PPC_GOT_TPREL16_HI: r = R_PPC_GOT_TPREL16_HI; break;
1608 case BFD_RELOC_PPC_GOT_TPREL16_HA: r = R_PPC_GOT_TPREL16_HA; break;
1609 case BFD_RELOC_PPC_GOT_DTPREL16: r = R_PPC_GOT_DTPREL16; break;
1610 case BFD_RELOC_PPC_GOT_DTPREL16_LO: r = R_PPC_GOT_DTPREL16_LO; break;
1611 case BFD_RELOC_PPC_GOT_DTPREL16_HI: r = R_PPC_GOT_DTPREL16_HI; break;
1612 case BFD_RELOC_PPC_GOT_DTPREL16_HA: r = R_PPC_GOT_DTPREL16_HA; break;
1613 case BFD_RELOC_PPC_EMB_NADDR32: r = R_PPC_EMB_NADDR32; break;
1614 case BFD_RELOC_PPC_EMB_NADDR16: r = R_PPC_EMB_NADDR16; break;
1615 case BFD_RELOC_PPC_EMB_NADDR16_LO: r = R_PPC_EMB_NADDR16_LO; break;
1616 case BFD_RELOC_PPC_EMB_NADDR16_HI: r = R_PPC_EMB_NADDR16_HI; break;
1617 case BFD_RELOC_PPC_EMB_NADDR16_HA: r = R_PPC_EMB_NADDR16_HA; break;
1618 case BFD_RELOC_PPC_EMB_SDAI16: r = R_PPC_EMB_SDAI16; break;
1619 case BFD_RELOC_PPC_EMB_SDA2I16: r = R_PPC_EMB_SDA2I16; break;
1620 case BFD_RELOC_PPC_EMB_SDA2REL: r = R_PPC_EMB_SDA2REL; break;
1621 case BFD_RELOC_PPC_EMB_SDA21: r = R_PPC_EMB_SDA21; break;
1622 case BFD_RELOC_PPC_EMB_MRKREF: r = R_PPC_EMB_MRKREF; break;
1623 case BFD_RELOC_PPC_EMB_RELSEC16: r = R_PPC_EMB_RELSEC16; break;
1624 case BFD_RELOC_PPC_EMB_RELST_LO: r = R_PPC_EMB_RELST_LO; break;
1625 case BFD_RELOC_PPC_EMB_RELST_HI: r = R_PPC_EMB_RELST_HI; break;
1626 case BFD_RELOC_PPC_EMB_RELST_HA: r = R_PPC_EMB_RELST_HA; break;
1627 case BFD_RELOC_PPC_EMB_BIT_FLD: r = R_PPC_EMB_BIT_FLD; break;
1628 case BFD_RELOC_PPC_EMB_RELSDA: r = R_PPC_EMB_RELSDA; break;
d7128ce4
AM
1629 case BFD_RELOC_16_PCREL: r = R_PPC_REL16; break;
1630 case BFD_RELOC_LO16_PCREL: r = R_PPC_REL16_LO; break;
1631 case BFD_RELOC_HI16_PCREL: r = R_PPC_REL16_HI; break;
1632 case BFD_RELOC_HI16_S_PCREL: r = R_PPC_REL16_HA; break;
25dbc73a
AM
1633 case BFD_RELOC_VTABLE_INHERIT: r = R_PPC_GNU_VTINHERIT; break;
1634 case BFD_RELOC_VTABLE_ENTRY: r = R_PPC_GNU_VTENTRY; break;
1635 }
1636
1637 return ppc_elf_howto_table[r];
1638};
1639
157090f7
AM
1640static reloc_howto_type *
1641ppc_elf_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
1642 const char *r_name)
1643{
1644 unsigned int i;
1645
1646 for (i = 0;
1647 i < sizeof (ppc_elf_howto_raw) / sizeof (ppc_elf_howto_raw[0]);
1648 i++)
1649 if (ppc_elf_howto_raw[i].name != NULL
1650 && strcasecmp (ppc_elf_howto_raw[i].name, r_name) == 0)
1651 return &ppc_elf_howto_raw[i];
1652
1653 return NULL;
1654}
1655
25dbc73a
AM
1656/* Set the howto pointer for a PowerPC ELF reloc. */
1657
1658static void
1659ppc_elf_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED,
1660 arelent *cache_ptr,
1661 Elf_Internal_Rela *dst)
1662{
1663 /* Initialize howto table if not already done. */
1664 if (!ppc_elf_howto_table[R_PPC_ADDR32])
1665 ppc_elf_howto_init ();
1666
1667 BFD_ASSERT (ELF32_R_TYPE (dst->r_info) < (unsigned int) R_PPC_max);
1668 cache_ptr->howto = ppc_elf_howto_table[ELF32_R_TYPE (dst->r_info)];
375de94a
AM
1669
1670 /* Just because the above assert didn't trigger doesn't mean that
1671 ELF32_R_TYPE (dst->r_info) is necessarily a valid relocation. */
1672 if (!cache_ptr->howto)
1673 {
1674 (*_bfd_error_handler) (_("%B: invalid relocation type %d"),
1675 abfd, ELF32_R_TYPE (dst->r_info));
1676 bfd_set_error (bfd_error_bad_value);
1677
1678 cache_ptr->howto = ppc_elf_howto_table[R_PPC_NONE];
1679 }
25dbc73a
AM
1680}
1681
d7128ce4 1682/* Handle the R_PPC_ADDR16_HA and R_PPC_REL16_HA relocs. */
25dbc73a
AM
1683
1684static bfd_reloc_status_type
1685ppc_elf_addr16_ha_reloc (bfd *abfd ATTRIBUTE_UNUSED,
1686 arelent *reloc_entry,
1687 asymbol *symbol,
1688 void *data ATTRIBUTE_UNUSED,
1689 asection *input_section,
1690 bfd *output_bfd,
1691 char **error_message ATTRIBUTE_UNUSED)
1692{
1693 bfd_vma relocation;
1694
1695 if (output_bfd != NULL)
1696 {
1697 reloc_entry->address += input_section->output_offset;
1698 return bfd_reloc_ok;
1699 }
1700
1701 if (reloc_entry->address > bfd_get_section_limit (abfd, input_section))
1702 return bfd_reloc_outofrange;
1703
1704 if (bfd_is_com_section (symbol->section))
1705 relocation = 0;
1706 else
1707 relocation = symbol->value;
1708
1709 relocation += symbol->section->output_section->vma;
1710 relocation += symbol->section->output_offset;
1711 relocation += reloc_entry->addend;
d7128ce4
AM
1712 if (reloc_entry->howto->pc_relative)
1713 relocation -= reloc_entry->address;
25dbc73a
AM
1714
1715 reloc_entry->addend += (relocation & 0x8000) << 1;
1716
1717 return bfd_reloc_continue;
1718}
1719
1720static bfd_reloc_status_type
1721ppc_elf_unhandled_reloc (bfd *abfd,
1722 arelent *reloc_entry,
1723 asymbol *symbol,
1724 void *data,
1725 asection *input_section,
1726 bfd *output_bfd,
1727 char **error_message)
1728{
1729 /* If this is a relocatable link (output_bfd test tells us), just
1730 call the generic function. Any adjustment will be done at final
1731 link time. */
1732 if (output_bfd != NULL)
1733 return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
1734 input_section, output_bfd, error_message);
1735
1736 if (error_message != NULL)
1737 {
1738 static char buf[60];
1739 sprintf (buf, _("generic linker can't handle %s"),
1740 reloc_entry->howto->name);
1741 *error_message = buf;
1742 }
1743 return bfd_reloc_dangerous;
1744}
1745\f
1746/* Sections created by the linker. */
1747
1748typedef struct elf_linker_section
1749{
c9a2f333 1750 /* Pointer to the bfd section. */
25dbc73a 1751 asection *section;
c9a2f333
AM
1752 /* Section name. */
1753 const char *name;
1754 /* Associated bss section name. */
1755 const char *bss_name;
1756 /* Associated symbol name. */
1757 const char *sym_name;
046183de
AM
1758 /* Associated symbol. */
1759 struct elf_link_hash_entry *sym;
25dbc73a
AM
1760} elf_linker_section_t;
1761
1762/* Linked list of allocated pointer entries. This hangs off of the
1763 symbol lists, and provides allows us to return different pointers,
1764 based on different addend's. */
1765
1766typedef struct elf_linker_section_pointers
1767{
1768 /* next allocated pointer for this symbol */
1769 struct elf_linker_section_pointers *next;
1770 /* offset of pointer from beginning of section */
1771 bfd_vma offset;
1772 /* addend used */
1773 bfd_vma addend;
1774 /* which linker section this is */
1775 elf_linker_section_t *lsect;
25dbc73a
AM
1776} elf_linker_section_pointers_t;
1777
1778struct ppc_elf_obj_tdata
1779{
1780 struct elf_obj_tdata elf;
1781
1782 /* A mapping from local symbols to offsets into the various linker
1783 sections added. This is index by the symbol index. */
1784 elf_linker_section_pointers_t **linker_section_pointers;
016687f8
AM
1785
1786 /* Flags used to auto-detect plt type. */
1787 unsigned int makes_plt_call : 1;
1788 unsigned int has_rel16 : 1;
25dbc73a
AM
1789};
1790
1791#define ppc_elf_tdata(bfd) \
1792 ((struct ppc_elf_obj_tdata *) (bfd)->tdata.any)
7619e7c7 1793
25dbc73a
AM
1794#define elf_local_ptr_offsets(bfd) \
1795 (ppc_elf_tdata (bfd)->linker_section_pointers)
7619e7c7 1796
0c8d6e5c
AM
1797#define is_ppc_elf(bfd) \
1798 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
4dfe6ac6 1799 && elf_object_id (bfd) == PPC32_ELF_DATA)
0c8d6e5c 1800
25dbc73a 1801/* Override the generic function because we store some extras. */
7619e7c7 1802
25dbc73a
AM
1803static bfd_boolean
1804ppc_elf_mkobject (bfd *abfd)
1805{
0ffa91dd 1806 return bfd_elf_allocate_object (abfd, sizeof (struct ppc_elf_obj_tdata),
4dfe6ac6 1807 PPC32_ELF_DATA);
25dbc73a 1808}
7619e7c7 1809
25dbc73a
AM
1810/* Fix bad default arch selected for a 32 bit input bfd when the
1811 default is 64 bit. */
7619e7c7 1812
25dbc73a
AM
1813static bfd_boolean
1814ppc_elf_object_p (bfd *abfd)
1815{
1816 if (abfd->arch_info->the_default && abfd->arch_info->bits_per_word == 64)
1817 {
1818 Elf_Internal_Ehdr *i_ehdr = elf_elfheader (abfd);
7619e7c7 1819
25dbc73a
AM
1820 if (i_ehdr->e_ident[EI_CLASS] == ELFCLASS32)
1821 {
1822 /* Relies on arch after 64 bit default being 32 bit default. */
1823 abfd->arch_info = abfd->arch_info->next;
1824 BFD_ASSERT (abfd->arch_info->bits_per_word == 32);
1825 }
1826 }
1827 return TRUE;
1828}
7619e7c7 1829
25dbc73a 1830/* Function to set whether a module needs the -mrelocatable bit set. */
7619e7c7 1831
25dbc73a
AM
1832static bfd_boolean
1833ppc_elf_set_private_flags (bfd *abfd, flagword flags)
1834{
1835 BFD_ASSERT (!elf_flags_init (abfd)
1836 || elf_elfheader (abfd)->e_flags == flags);
7619e7c7 1837
25dbc73a
AM
1838 elf_elfheader (abfd)->e_flags = flags;
1839 elf_flags_init (abfd) = TRUE;
1840 return TRUE;
1841}
1842
25dbc73a 1843/* Support for core dump NOTE sections. */
deaaf2f3 1844
b34976b6 1845static bfd_boolean
25dbc73a 1846ppc_elf_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
252b5132 1847{
25dbc73a
AM
1848 int offset;
1849 unsigned int size;
252b5132 1850
25dbc73a
AM
1851 switch (note->descsz)
1852 {
1853 default:
1854 return FALSE;
252b5132 1855
25dbc73a
AM
1856 case 268: /* Linux/PPC. */
1857 /* pr_cursig */
1858 elf_tdata (abfd)->core_signal = bfd_get_16 (abfd, note->descdata + 12);
deaaf2f3 1859
25dbc73a 1860 /* pr_pid */
261b8d08 1861 elf_tdata (abfd)->core_lwpid = bfd_get_32 (abfd, note->descdata + 24);
9abc968f 1862
25dbc73a
AM
1863 /* pr_reg */
1864 offset = 72;
1865 size = 192;
deaaf2f3 1866
25dbc73a
AM
1867 break;
1868 }
deaaf2f3 1869
25dbc73a
AM
1870 /* Make a ".reg/999" section. */
1871 return _bfd_elfcore_make_pseudosection (abfd, ".reg",
1872 size, note->descpos + offset);
1873}
252b5132 1874
25dbc73a
AM
1875static bfd_boolean
1876ppc_elf_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
1877{
1878 switch (note->descsz)
deaaf2f3 1879 {
25dbc73a
AM
1880 default:
1881 return FALSE;
deaaf2f3 1882
25dbc73a 1883 case 128: /* Linux/PPC elf_prpsinfo. */
bc989cdc
JK
1884 elf_tdata (abfd)->core_pid
1885 = bfd_get_32 (abfd, note->descdata + 16);
25dbc73a
AM
1886 elf_tdata (abfd)->core_program
1887 = _bfd_elfcore_strndup (abfd, note->descdata + 32, 16);
1888 elf_tdata (abfd)->core_command
1889 = _bfd_elfcore_strndup (abfd, note->descdata + 48, 80);
1890 }
9abc968f 1891
25dbc73a
AM
1892 /* Note that for some reason, a spurious space is tacked
1893 onto the end of the args in some (at least one anyway)
1894 implementations, so strip it off if it exists. */
70bccea4 1895
25dbc73a
AM
1896 {
1897 char *command = elf_tdata (abfd)->core_command;
1898 int n = strlen (command);
70bccea4 1899
25dbc73a
AM
1900 if (0 < n && command[n - 1] == ' ')
1901 command[n - 1] = '\0';
1902 }
deaaf2f3 1903
25dbc73a
AM
1904 return TRUE;
1905}
deaaf2f3 1906
183e98be
AM
1907static char *
1908ppc_elf_write_core_note (bfd *abfd, char *buf, int *bufsiz, int note_type, ...)
1909{
1910 switch (note_type)
1911 {
1912 default:
1913 return NULL;
1914
1915 case NT_PRPSINFO:
1916 {
1917 char data[128];
1918 va_list ap;
1919
1920 va_start (ap, note_type);
1921 memset (data, 0, 32);
1922 strncpy (data + 32, va_arg (ap, const char *), 16);
1923 strncpy (data + 48, va_arg (ap, const char *), 80);
1924 va_end (ap);
1925 return elfcore_write_note (abfd, buf, bufsiz,
1926 "CORE", note_type, data, sizeof (data));
1927 }
1928
1929 case NT_PRSTATUS:
1930 {
1931 char data[268];
1932 va_list ap;
1933 long pid;
1934 int cursig;
1935 const void *greg;
1936
1937 va_start (ap, note_type);
1938 memset (data, 0, 72);
1939 pid = va_arg (ap, long);
1940 bfd_put_32 (abfd, pid, data + 24);
1941 cursig = va_arg (ap, int);
1942 bfd_put_16 (abfd, cursig, data + 12);
1943 greg = va_arg (ap, const void *);
1944 memcpy (data + 72, greg, 192);
1945 memset (data + 264, 0, 4);
1946 va_end (ap);
1947 return elfcore_write_note (abfd, buf, bufsiz,
1948 "CORE", note_type, data, sizeof (data));
1949 }
1950 }
1951}
1952
25dbc73a
AM
1953/* Return address for Ith PLT stub in section PLT, for relocation REL
1954 or (bfd_vma) -1 if it should not be included. */
deaaf2f3 1955
25dbc73a
AM
1956static bfd_vma
1957ppc_elf_plt_sym_val (bfd_vma i ATTRIBUTE_UNUSED,
1958 const asection *plt ATTRIBUTE_UNUSED,
1959 const arelent *rel)
1960{
1961 return rel->address;
1962}
deaaf2f3 1963
25dbc73a 1964/* Handle a PowerPC specific section when reading an object file. This
6dc132d9
L
1965 is called when bfd_section_from_shdr finds a section with an unknown
1966 type. */
deaaf2f3 1967
25dbc73a 1968static bfd_boolean
6dc132d9
L
1969ppc_elf_section_from_shdr (bfd *abfd,
1970 Elf_Internal_Shdr *hdr,
1971 const char *name,
1972 int shindex)
25dbc73a
AM
1973{
1974 asection *newsect;
1975 flagword flags;
d1c6de6f 1976
6dc132d9 1977 if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex))
25dbc73a 1978 return FALSE;
deaaf2f3 1979
25dbc73a
AM
1980 newsect = hdr->bfd_section;
1981 flags = bfd_get_section_flags (abfd, newsect);
1982 if (hdr->sh_flags & SHF_EXCLUDE)
1983 flags |= SEC_EXCLUDE;
9abc968f 1984
25dbc73a
AM
1985 if (hdr->sh_type == SHT_ORDERED)
1986 flags |= SEC_SORT_ENTRIES;
d1c6de6f 1987
25dbc73a
AM
1988 bfd_set_section_flags (abfd, newsect, flags);
1989 return TRUE;
1990}
1991
1992/* Set up any other section flags and such that may be necessary. */
1993
1994static bfd_boolean
1995ppc_elf_fake_sections (bfd *abfd ATTRIBUTE_UNUSED,
1996 Elf_Internal_Shdr *shdr,
1997 asection *asect)
1998{
25dbc73a
AM
1999 if ((asect->flags & SEC_SORT_ENTRIES) != 0)
2000 shdr->sh_type = SHT_ORDERED;
2001
2002 return TRUE;
2003}
2004
2005/* If we have .sbss2 or .PPC.EMB.sbss0 output sections, we
2006 need to bump up the number of section headers. */
2007
2008static int
a6b96beb
AM
2009ppc_elf_additional_program_headers (bfd *abfd,
2010 struct bfd_link_info *info ATTRIBUTE_UNUSED)
25dbc73a
AM
2011{
2012 asection *s;
2013 int ret = 0;
d1c6de6f 2014
25dbc73a
AM
2015 s = bfd_get_section_by_name (abfd, ".sbss2");
2016 if (s != NULL && (s->flags & SEC_ALLOC) != 0)
2017 ++ret;
d1c6de6f 2018
25dbc73a
AM
2019 s = bfd_get_section_by_name (abfd, ".PPC.EMB.sbss0");
2020 if (s != NULL && (s->flags & SEC_ALLOC) != 0)
2021 ++ret;
deaaf2f3 2022
25dbc73a
AM
2023 return ret;
2024}
deaaf2f3 2025
25dbc73a
AM
2026/* Add extra PPC sections -- Note, for now, make .sbss2 and
2027 .PPC.EMB.sbss0 a normal section, and not a bss section so
2028 that the linker doesn't crater when trying to make more than
2029 2 sections. */
e656e369 2030
b35d266b 2031static const struct bfd_elf_special_section ppc_elf_special_sections[] =
7f4d3958 2032{
0112cd26
NC
2033 { STRING_COMMA_LEN (".plt"), 0, SHT_NOBITS, SHF_ALLOC + SHF_EXECINSTR },
2034 { STRING_COMMA_LEN (".sbss"), -2, SHT_NOBITS, SHF_ALLOC + SHF_WRITE },
2035 { STRING_COMMA_LEN (".sbss2"), -2, SHT_PROGBITS, SHF_ALLOC },
2036 { STRING_COMMA_LEN (".sdata"), -2, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE },
2037 { STRING_COMMA_LEN (".sdata2"), -2, SHT_PROGBITS, SHF_ALLOC },
2038 { STRING_COMMA_LEN (".tags"), 0, SHT_ORDERED, SHF_ALLOC },
2039 { STRING_COMMA_LEN (".PPC.EMB.apuinfo"), 0, SHT_NOTE, 0 },
2040 { STRING_COMMA_LEN (".PPC.EMB.sbss0"), 0, SHT_PROGBITS, SHF_ALLOC },
2041 { STRING_COMMA_LEN (".PPC.EMB.sdata0"), 0, SHT_PROGBITS, SHF_ALLOC },
2042 { NULL, 0, 0, 0, 0 }
7f4d3958
L
2043};
2044
551b43fd
AM
2045/* This is what we want for new plt/got. */
2046static struct bfd_elf_special_section ppc_alt_plt =
0112cd26 2047 { STRING_COMMA_LEN (".plt"), 0, SHT_PROGBITS, SHF_ALLOC };
551b43fd
AM
2048
2049static const struct bfd_elf_special_section *
2050ppc_elf_get_sec_type_attr (bfd *abfd ATTRIBUTE_UNUSED, asection *sec)
7f4d3958 2051{
b35d266b 2052 const struct bfd_elf_special_section *ssect;
551b43fd
AM
2053
2054 /* See if this is one of the special sections. */
2055 if (sec->name == NULL)
2056 return NULL;
2057
2058 ssect = _bfd_elf_get_special_section (sec->name, ppc_elf_special_sections,
2059 sec->use_rela_p);
2060 if (ssect != NULL)
2061 {
2062 if (ssect == ppc_elf_special_sections && (sec->flags & SEC_LOAD) != 0)
2063 ssect = &ppc_alt_plt;
2064 return ssect;
2065 }
2066
2067 return _bfd_elf_get_sec_type_attr (abfd, sec);
2068}
25dbc73a
AM
2069\f
2070/* Very simple linked list structure for recording apuinfo values. */
2071typedef struct apuinfo_list
2072{
2073 struct apuinfo_list *next;
2074 unsigned long value;
2075}
2076apuinfo_list;
e656e369 2077
25dbc73a 2078static apuinfo_list *head;
f2faa800 2079static bfd_boolean apuinfo_set;
deaaf2f3 2080
25dbc73a
AM
2081static void
2082apuinfo_list_init (void)
2083{
2084 head = NULL;
f2faa800 2085 apuinfo_set = FALSE;
25dbc73a 2086}
9abc968f 2087
25dbc73a
AM
2088static void
2089apuinfo_list_add (unsigned long value)
2090{
2091 apuinfo_list *entry = head;
deaaf2f3 2092
25dbc73a
AM
2093 while (entry != NULL)
2094 {
2095 if (entry->value == value)
2096 return;
2097 entry = entry->next;
2098 }
b4a38de6 2099
25dbc73a
AM
2100 entry = bfd_malloc (sizeof (* entry));
2101 if (entry == NULL)
2102 return;
e656e369 2103
25dbc73a
AM
2104 entry->value = value;
2105 entry->next = head;
2106 head = entry;
2107}
9abc968f 2108
25dbc73a
AM
2109static unsigned
2110apuinfo_list_length (void)
2111{
2112 apuinfo_list *entry;
2113 unsigned long count;
9abc968f 2114
25dbc73a
AM
2115 for (entry = head, count = 0;
2116 entry;
2117 entry = entry->next)
2118 ++ count;
e656e369 2119
25dbc73a
AM
2120 return count;
2121}
eea6121a 2122
25dbc73a
AM
2123static inline unsigned long
2124apuinfo_list_element (unsigned long number)
2125{
2126 apuinfo_list * entry;
e656e369 2127
25dbc73a
AM
2128 for (entry = head;
2129 entry && number --;
2130 entry = entry->next)
2131 ;
252b5132 2132
25dbc73a
AM
2133 return entry ? entry->value : 0;
2134}
2135
2136static void
2137apuinfo_list_finish (void)
2138{
2139 apuinfo_list *entry;
2140
2141 for (entry = head; entry;)
252b5132 2142 {
25dbc73a
AM
2143 apuinfo_list *next = entry->next;
2144 free (entry);
2145 entry = next;
2146 }
9abc968f 2147
25dbc73a
AM
2148 head = NULL;
2149}
9abc968f 2150
25dbc73a
AM
2151#define APUINFO_SECTION_NAME ".PPC.EMB.apuinfo"
2152#define APUINFO_LABEL "APUinfo"
9abc968f 2153
25dbc73a
AM
2154/* Scan the input BFDs and create a linked list of
2155 the APUinfo values that will need to be emitted. */
9abc968f 2156
25dbc73a
AM
2157static void
2158ppc_elf_begin_write_processing (bfd *abfd, struct bfd_link_info *link_info)
2159{
2160 bfd *ibfd;
2161 asection *asec;
deddc40b
NS
2162 char *buffer = NULL;
2163 bfd_size_type largest_input_size = 0;
25dbc73a 2164 unsigned i;
25dbc73a
AM
2165 unsigned long length;
2166 const char *error_message = NULL;
9abc968f 2167
25dbc73a
AM
2168 if (link_info == NULL)
2169 return;
9abc968f 2170
25dbc73a 2171 apuinfo_list_init ();
252b5132 2172
25dbc73a
AM
2173 /* Read in the input sections contents. */
2174 for (ibfd = link_info->input_bfds; ibfd; ibfd = ibfd->link_next)
252b5132 2175 {
25dbc73a 2176 unsigned long datum;
252b5132 2177
25dbc73a
AM
2178 asec = bfd_get_section_by_name (ibfd, APUINFO_SECTION_NAME);
2179 if (asec == NULL)
2180 continue;
252b5132 2181
deddc40b 2182 error_message = _("corrupt %s section in %B");
25dbc73a 2183 length = asec->size;
deddc40b
NS
2184 if (length < 20)
2185 goto fail;
2186
f2faa800 2187 apuinfo_set = TRUE;
deddc40b 2188 if (largest_input_size < asec->size)
25dbc73a 2189 {
deddc40b
NS
2190 if (buffer)
2191 free (buffer);
2192 largest_input_size = asec->size;
2193 buffer = bfd_malloc (largest_input_size);
2194 if (!buffer)
2195 return;
25dbc73a 2196 }
5b914448 2197
25dbc73a 2198 if (bfd_seek (ibfd, asec->filepos, SEEK_SET) != 0
deddc40b 2199 || (bfd_bread (buffer, length, ibfd) != length))
25dbc73a
AM
2200 {
2201 error_message = _("unable to read in %s section from %B");
2202 goto fail;
2203 }
252b5132 2204
25dbc73a
AM
2205 /* Verify the contents of the header. Note - we have to
2206 extract the values this way in order to allow for a
2207 host whose endian-ness is different from the target. */
deddc40b 2208 datum = bfd_get_32 (ibfd, buffer);
25dbc73a
AM
2209 if (datum != sizeof APUINFO_LABEL)
2210 goto fail;
252b5132 2211
deddc40b 2212 datum = bfd_get_32 (ibfd, buffer + 8);
25dbc73a
AM
2213 if (datum != 0x2)
2214 goto fail;
252b5132 2215
deddc40b 2216 if (strcmp (buffer + 12, APUINFO_LABEL) != 0)
25dbc73a 2217 goto fail;
252b5132 2218
25dbc73a 2219 /* Get the number of bytes used for apuinfo entries. */
deddc40b 2220 datum = bfd_get_32 (ibfd, buffer + 4);
25dbc73a
AM
2221 if (datum + 20 != length)
2222 goto fail;
2223
25dbc73a
AM
2224 /* Scan the apuinfo section, building a list of apuinfo numbers. */
2225 for (i = 0; i < datum; i += 4)
deddc40b 2226 apuinfo_list_add (bfd_get_32 (ibfd, buffer + 20 + i));
252b5132
RH
2227 }
2228
25dbc73a 2229 error_message = NULL;
252b5132 2230
f2faa800 2231 if (apuinfo_set)
deddc40b 2232 {
f2faa800
NS
2233 /* Compute the size of the output section. */
2234 unsigned num_entries = apuinfo_list_length ();
5b914448 2235
deddc40b
NS
2236 /* Set the output section size, if it exists. */
2237 asec = bfd_get_section_by_name (abfd, APUINFO_SECTION_NAME);
f2faa800 2238
deddc40b
NS
2239 if (asec && ! bfd_set_section_size (abfd, asec, 20 + num_entries * 4))
2240 {
2241 ibfd = abfd;
2242 error_message = _("warning: unable to set size of %s section in %B");
2243 }
2244 }
25dbc73a
AM
2245
2246 fail:
deddc40b
NS
2247 if (buffer)
2248 free (buffer);
25dbc73a
AM
2249
2250 if (error_message)
2251 (*_bfd_error_handler) (error_message, ibfd, APUINFO_SECTION_NAME);
2252}
252b5132 2253
25dbc73a
AM
2254/* Prevent the output section from accumulating the input sections'
2255 contents. We have already stored this in our linked list structure. */
252b5132 2256
25dbc73a
AM
2257static bfd_boolean
2258ppc_elf_write_section (bfd *abfd ATTRIBUTE_UNUSED,
c7b8f16e 2259 struct bfd_link_info *link_info ATTRIBUTE_UNUSED,
25dbc73a
AM
2260 asection *asec,
2261 bfd_byte *contents ATTRIBUTE_UNUSED)
2262{
f2faa800 2263 return apuinfo_set && strcmp (asec->name, APUINFO_SECTION_NAME) == 0;
252b5132
RH
2264}
2265
25dbc73a
AM
2266/* Finally we can generate the output section. */
2267
2268static void
2269ppc_elf_final_write_processing (bfd *abfd, bfd_boolean linker ATTRIBUTE_UNUSED)
7619e7c7 2270{
25dbc73a
AM
2271 bfd_byte *buffer;
2272 asection *asec;
2273 unsigned i;
2274 unsigned num_entries;
2275 bfd_size_type length;
7619e7c7 2276
25dbc73a
AM
2277 asec = bfd_get_section_by_name (abfd, APUINFO_SECTION_NAME);
2278 if (asec == NULL)
2279 return;
2280
f2faa800 2281 if (!apuinfo_set)
25dbc73a
AM
2282 return;
2283
2284 length = asec->size;
2285 if (length < 20)
2286 return;
2287
2288 buffer = bfd_malloc (length);
2289 if (buffer == NULL)
7619e7c7 2290 {
25dbc73a
AM
2291 (*_bfd_error_handler)
2292 (_("failed to allocate space for new APUinfo section."));
2293 return;
7619e7c7 2294 }
7619e7c7 2295
25dbc73a
AM
2296 /* Create the apuinfo header. */
2297 num_entries = apuinfo_list_length ();
2298 bfd_put_32 (abfd, sizeof APUINFO_LABEL, buffer);
2299 bfd_put_32 (abfd, num_entries * 4, buffer + 4);
2300 bfd_put_32 (abfd, 0x2, buffer + 8);
2301 strcpy ((char *) buffer + 12, APUINFO_LABEL);
feee612b 2302
25dbc73a
AM
2303 length = 20;
2304 for (i = 0; i < num_entries; i++)
feee612b 2305 {
25dbc73a
AM
2306 bfd_put_32 (abfd, apuinfo_list_element (i), buffer + length);
2307 length += 4;
feee612b 2308 }
feee612b 2309
25dbc73a
AM
2310 if (length != asec->size)
2311 (*_bfd_error_handler) (_("failed to compute new APUinfo section."));
252b5132 2312
25dbc73a
AM
2313 if (! bfd_set_section_contents (abfd, asec, buffer, (file_ptr) 0, length))
2314 (*_bfd_error_handler) (_("failed to install new APUinfo section."));
252b5132 2315
25dbc73a
AM
2316 free (buffer);
2317
2318 apuinfo_list_finish ();
252b5132 2319}
25dbc73a 2320\f
7382d32a 2321static bfd_boolean
c6dd29ce 2322is_nonpic_glink_stub (bfd *abfd, asection *glink, bfd_vma off)
7382d32a 2323{
c6dd29ce 2324 bfd_byte buf[GLINK_ENTRY_SIZE];
7382d32a 2325
c6dd29ce 2326 if (!bfd_get_section_contents (abfd, glink, buf, off, GLINK_ENTRY_SIZE))
7382d32a
AM
2327 return FALSE;
2328
c6dd29ce
AM
2329 return ((bfd_get_32 (abfd, buf + 0) & 0xffff0000) == LIS_11
2330 && (bfd_get_32 (abfd, buf + 4) & 0xffff0000) == LWZ_11_11
2331 && bfd_get_32 (abfd, buf + 8) == MTCTR_11
2332 && bfd_get_32 (abfd, buf + 12) == BCTR);
7382d32a
AM
2333}
2334
468392fb
AM
2335static bfd_boolean
2336section_covers_vma (bfd *abfd ATTRIBUTE_UNUSED, asection *section, void *ptr)
2337{
2338 bfd_vma vma = *(bfd_vma *) ptr;
2339 return ((section->flags & SEC_ALLOC) != 0
2340 && section->vma <= vma
2341 && vma < section->vma + section->size);
2342}
2343
2344static long
2345ppc_elf_get_synthetic_symtab (bfd *abfd, long symcount, asymbol **syms,
2346 long dynsymcount, asymbol **dynsyms,
2347 asymbol **ret)
2348{
2349 bfd_boolean (*slurp_relocs) (bfd *, asection *, asymbol **, bfd_boolean);
2350 asection *plt, *relplt, *dynamic, *glink;
2351 bfd_vma glink_vma = 0;
2352 bfd_vma resolv_vma = 0;
2353 bfd_vma stub_vma;
2354 asymbol *s;
2355 arelent *p;
2356 long count, i;
2357 size_t size;
2358 char *names;
2359 bfd_byte buf[4];
2360
2361 *ret = NULL;
2362
2363 if ((abfd->flags & (DYNAMIC | EXEC_P)) == 0)
2364 return 0;
2365
2366 if (dynsymcount <= 0)
2367 return 0;
2368
2369 relplt = bfd_get_section_by_name (abfd, ".rela.plt");
2370 if (relplt == NULL)
2371 return 0;
2372
2373 plt = bfd_get_section_by_name (abfd, ".plt");
2374 if (plt == NULL)
2375 return 0;
2376
2377 /* Call common code to handle old-style executable PLTs. */
2378 if (elf_section_flags (plt) & SHF_EXECINSTR)
2379 return _bfd_elf_get_synthetic_symtab (abfd, symcount, syms,
2380 dynsymcount, dynsyms, ret);
2381
2382 /* If this object was prelinked, the prelinker stored the address
2383 of .glink at got[1]. If it wasn't prelinked, got[1] will be zero. */
2384 dynamic = bfd_get_section_by_name (abfd, ".dynamic");
2385 if (dynamic != NULL)
2386 {
2387 bfd_byte *dynbuf, *extdyn, *extdynend;
2388 size_t extdynsize;
2389 void (*swap_dyn_in) (bfd *, const void *, Elf_Internal_Dyn *);
2390
2391 if (!bfd_malloc_and_get_section (abfd, dynamic, &dynbuf))
2392 return -1;
2393
2394 extdynsize = get_elf_backend_data (abfd)->s->sizeof_dyn;
2395 swap_dyn_in = get_elf_backend_data (abfd)->s->swap_dyn_in;
2396
2397 extdyn = dynbuf;
2398 extdynend = extdyn + dynamic->size;
2399 for (; extdyn < extdynend; extdyn += extdynsize)
2400 {
2401 Elf_Internal_Dyn dyn;
2402 (*swap_dyn_in) (abfd, extdyn, &dyn);
2403
2404 if (dyn.d_tag == DT_NULL)
2405 break;
2406
2407 if (dyn.d_tag == DT_PPC_GOT)
2408 {
2409 unsigned int g_o_t = dyn.d_un.d_val;
2410 asection *got = bfd_get_section_by_name (abfd, ".got");
2411 if (got != NULL
2412 && bfd_get_section_contents (abfd, got, buf,
2413 g_o_t - got->vma + 4, 4))
2414 glink_vma = bfd_get_32 (abfd, buf);
2415 break;
2416 }
2417 }
2418 free (dynbuf);
2419 }
2420
2421 /* Otherwise we read the first plt entry. */
2422 if (glink_vma == 0)
2423 {
2424 if (bfd_get_section_contents (abfd, plt, buf, 0, 4))
2425 glink_vma = bfd_get_32 (abfd, buf);
2426 }
2427
2428 if (glink_vma == 0)
2429 return 0;
2430
2431 /* The .glink section usually does not survive the final
2432 link; search for the section (usually .text) where the
2433 glink stubs now reside. */
2434 glink = bfd_sections_find_if (abfd, section_covers_vma, &glink_vma);
2435 if (glink == NULL)
2436 return 0;
2437
2438 /* Determine glink PLT resolver by reading the relative branch
2439 from the first glink stub. */
2440 if (bfd_get_section_contents (abfd, glink, buf,
2441 glink_vma - glink->vma, 4))
2442 {
2443 unsigned int insn = bfd_get_32 (abfd, buf);
2444
2445 /* The first glink stub may either branch to the resolver ... */
2446 insn ^= B;
2447 if ((insn & ~0x3fffffc) == 0)
2448 resolv_vma = glink_vma + (insn ^ 0x2000000) - 0x2000000;
2449
2450 /* ... or fall through a bunch of NOPs. */
2451 else if ((insn ^ B ^ NOP) == 0)
2452 for (i = 4;
2453 bfd_get_section_contents (abfd, glink, buf,
2454 glink_vma - glink->vma + i, 4);
2455 i += 4)
2456 if (bfd_get_32 (abfd, buf) != NOP)
2457 {
2458 resolv_vma = glink_vma + i;
2459 break;
2460 }
2461 }
2462
7382d32a
AM
2463 count = relplt->size / sizeof (Elf32_External_Rela);
2464 stub_vma = glink_vma - (bfd_vma) count * 16;
2465 /* If the stubs are those for -shared/-pie then we might have
2466 multiple stubs for each plt entry. If that is the case then
2467 there is no way to associate stubs with their plt entries short
2468 of figuring out the GOT pointer value used in the stub. */
c6dd29ce
AM
2469 if (!is_nonpic_glink_stub (abfd, glink,
2470 glink_vma - GLINK_ENTRY_SIZE - glink->vma))
7382d32a
AM
2471 return 0;
2472
468392fb
AM
2473 slurp_relocs = get_elf_backend_data (abfd)->s->slurp_reloc_table;
2474 if (! (*slurp_relocs) (abfd, relplt, dynsyms, TRUE))
2475 return -1;
2476
468392fb
AM
2477 size = count * sizeof (asymbol);
2478 p = relplt->relocation;
2479 for (i = 0; i < count; i++, p++)
e054468f
AM
2480 {
2481 size += strlen ((*p->sym_ptr_ptr)->name) + sizeof ("@plt");
2482 if (p->addend != 0)
2483 size += sizeof ("+0x") - 1 + 8;
2484 }
468392fb
AM
2485
2486 size += sizeof (asymbol) + sizeof ("__glink");
2487
2488 if (resolv_vma)
2489 size += sizeof (asymbol) + sizeof ("__glink_PLTresolve");
2490
2491 s = *ret = bfd_malloc (size);
2492 if (s == NULL)
2493 return -1;
2494
2495 names = (char *) (s + count + 1 + (resolv_vma != 0));
2496 p = relplt->relocation;
2497 for (i = 0; i < count; i++, p++)
2498 {
2499 size_t len;
2500
2501 *s = **p->sym_ptr_ptr;
2502 /* Undefined syms won't have BSF_LOCAL or BSF_GLOBAL set. Since
2503 we are defining a symbol, ensure one of them is set. */
2504 if ((s->flags & BSF_LOCAL) == 0)
2505 s->flags |= BSF_GLOBAL;
6ba2a415 2506 s->flags |= BSF_SYNTHETIC;
468392fb
AM
2507 s->section = glink;
2508 s->value = stub_vma - glink->vma;
2509 s->name = names;
2510 s->udata.p = NULL;
2511 len = strlen ((*p->sym_ptr_ptr)->name);
2512 memcpy (names, (*p->sym_ptr_ptr)->name, len);
2513 names += len;
e054468f
AM
2514 if (p->addend != 0)
2515 {
2516 memcpy (names, "+0x", sizeof ("+0x") - 1);
2517 names += sizeof ("+0x") - 1;
2518 bfd_sprintf_vma (abfd, names, p->addend);
2519 names += strlen (names);
2520 }
468392fb
AM
2521 memcpy (names, "@plt", sizeof ("@plt"));
2522 names += sizeof ("@plt");
2523 ++s;
2524 stub_vma += 16;
2525 }
2526
2527 /* Add a symbol at the start of the glink branch table. */
86a4952b 2528 memset (s, 0, sizeof *s);
468392fb 2529 s->the_bfd = abfd;
6ba2a415 2530 s->flags = BSF_GLOBAL | BSF_SYNTHETIC;
468392fb
AM
2531 s->section = glink;
2532 s->value = glink_vma - glink->vma;
2533 s->name = names;
2534 memcpy (names, "__glink", sizeof ("__glink"));
2535 names += sizeof ("__glink");
2536 s++;
2537 count++;
2538
2539 if (resolv_vma)
2540 {
2541 /* Add a symbol for the glink PLT resolver. */
86a4952b 2542 memset (s, 0, sizeof *s);
468392fb 2543 s->the_bfd = abfd;
6ba2a415 2544 s->flags = BSF_GLOBAL | BSF_SYNTHETIC;
468392fb
AM
2545 s->section = glink;
2546 s->value = resolv_vma - glink->vma;
2547 s->name = names;
2548 memcpy (names, "__glink_PLTresolve", sizeof ("__glink_PLTresolve"));
2549 names += sizeof ("__glink_PLTresolve");
2550 s++;
2551 count++;
2552 }
2553
2554 return count;
2555}
2556\f
25dbc73a
AM
2557/* The following functions are specific to the ELF linker, while
2558 functions above are used generally. They appear in this file more
2559 or less in the order in which they are called. eg.
2560 ppc_elf_check_relocs is called early in the link process,
2561 ppc_elf_finish_dynamic_sections is one of the last functions
2562 called. */
252b5132 2563
25dbc73a
AM
2564/* The PPC linker needs to keep track of the number of relocs that it
2565 decides to copy as dynamic relocs in check_relocs for each symbol.
2566 This is so that it can later discard them if they are found to be
2567 unnecessary. We store the information in a field extending the
2568 regular ELF linker hash table. */
ae9a127f 2569
25dbc73a 2570struct ppc_elf_dyn_relocs
252b5132 2571{
25dbc73a 2572 struct ppc_elf_dyn_relocs *next;
252b5132 2573
25dbc73a
AM
2574 /* The input section of the reloc. */
2575 asection *sec;
252b5132 2576
25dbc73a
AM
2577 /* Total number of relocs copied for the input section. */
2578 bfd_size_type count;
252b5132 2579
25dbc73a
AM
2580 /* Number of pc-relative relocs copied for the input section. */
2581 bfd_size_type pc_count;
2582};
252b5132 2583
a6aa5195 2584/* Track PLT entries needed for a given symbol. We might need more
a877a2b6 2585 than one glink entry per symbol when generating a pic binary. */
a6aa5195
AM
2586struct plt_entry
2587{
2588 struct plt_entry *next;
2589
2590 /* -fPIC uses multiple GOT sections, one per file, called ".got2".
2591 This field stores the offset into .got2 used to initialise the
a877a2b6
AM
2592 GOT pointer reg. It will always be at least 32768. (Current
2593 gcc always uses an offset of 32768, but ld -r will pack .got2
2594 sections together resulting in larger offsets). */
a6aa5195
AM
2595 bfd_vma addend;
2596
2597 /* The .got2 section. */
2598 asection *sec;
2599
2600 /* PLT refcount or offset. */
2601 union
2602 {
2603 bfd_signed_vma refcount;
2604 bfd_vma offset;
2605 } plt;
2606
2607 /* .glink stub offset. */
2608 bfd_vma glink_offset;
2609};
2610
1d483afe 2611/* Of those relocs that might be copied as dynamic relocs, this function
25dbc73a
AM
2612 selects those that must be copied when linking a shared library,
2613 even when the symbol is local. */
252b5132 2614
1d483afe
AM
2615static int
2616must_be_dyn_reloc (struct bfd_link_info *info,
2617 enum elf_ppc_reloc_type r_type)
2618{
2619 switch (r_type)
2620 {
2621 default:
2622 return 1;
2623
2624 case R_PPC_REL24:
2625 case R_PPC_REL14:
2626 case R_PPC_REL14_BRTAKEN:
2627 case R_PPC_REL14_BRNTAKEN:
2628 case R_PPC_REL32:
2629 return 0;
2630
2631 case R_PPC_TPREL32:
2632 case R_PPC_TPREL16:
2633 case R_PPC_TPREL16_LO:
2634 case R_PPC_TPREL16_HI:
2635 case R_PPC_TPREL16_HA:
2636 return !info->executable;
2637 }
2638}
252b5132 2639
25dbc73a
AM
2640/* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
2641 copying dynamic variables from a shared lib into an app's dynbss
2642 section, and instead use a dynamic relocation to point into the
2643 shared lib. */
2644#define ELIMINATE_COPY_RELOCS 1
252b5132 2645
25dbc73a 2646/* PPC ELF linker hash entry. */
252b5132 2647
25dbc73a
AM
2648struct ppc_elf_link_hash_entry
2649{
2650 struct elf_link_hash_entry elf;
252b5132 2651
25dbc73a
AM
2652 /* If this symbol is used in the linker created sections, the processor
2653 specific backend uses this field to map the field into the offset
2654 from the beginning of the section. */
2655 elf_linker_section_pointers_t *linker_section_pointer;
252b5132 2656
25dbc73a
AM
2657 /* Track dynamic relocs copied for this symbol. */
2658 struct ppc_elf_dyn_relocs *dyn_relocs;
252b5132 2659
25dbc73a
AM
2660 /* Contexts in which symbol is used in the GOT (or TOC).
2661 TLS_GD .. TLS_TLS bits are or'd into the mask as the
2662 corresponding relocs are encountered during check_relocs.
2663 tls_optimize clears TLS_GD .. TLS_TPREL when optimizing to
2664 indicate the corresponding GOT entry type is not needed. */
2665#define TLS_GD 1 /* GD reloc. */
2666#define TLS_LD 2 /* LD reloc. */
2667#define TLS_TPREL 4 /* TPREL reloc, => IE. */
2668#define TLS_DTPREL 8 /* DTPREL reloc, => LD. */
2669#define TLS_TLS 16 /* Any TLS reloc. */
2670#define TLS_TPRELGD 32 /* TPREL reloc resulting from GD->IE. */
e054468f 2671#define PLT_IFUNC 64 /* STT_GNU_IFUNC. */
25dbc73a 2672 char tls_mask;
4dc4a9a5
DJ
2673
2674 /* Nonzero if we have seen a small data relocation referring to this
2675 symbol. */
2676 unsigned char has_sda_refs;
25dbc73a 2677};
252b5132 2678
25dbc73a
AM
2679#define ppc_elf_hash_entry(ent) ((struct ppc_elf_link_hash_entry *) (ent))
2680
2681/* PPC ELF linker hash table. */
2682
2683struct ppc_elf_link_hash_table
2684{
2685 struct elf_link_hash_table elf;
2686
2687 /* Short-cuts to get to dynamic linker sections. */
2688 asection *got;
2689 asection *relgot;
d7128ce4 2690 asection *glink;
25dbc73a
AM
2691 asection *plt;
2692 asection *relplt;
e054468f
AM
2693 asection *iplt;
2694 asection *reliplt;
25dbc73a
AM
2695 asection *dynbss;
2696 asection *relbss;
2697 asection *dynsbss;
2698 asection *relsbss;
c9a2f333 2699 elf_linker_section_t sdata[2];
25dbc73a
AM
2700 asection *sbss;
2701
016687f8
AM
2702 /* The (unloaded but important) .rela.plt.unloaded on VxWorks. */
2703 asection *srelplt2;
2704
2705 /* The .got.plt section (VxWorks only)*/
2706 asection *sgotplt;
2707
1d483afe 2708 /* Shortcut to __tls_get_addr. */
25dbc73a 2709 struct elf_link_hash_entry *tls_get_addr;
252b5132 2710
016687f8
AM
2711 /* The bfd that forced an old-style PLT. */
2712 bfd *old_bfd;
5b914448 2713
25dbc73a
AM
2714 /* TLS local dynamic got entry handling. */
2715 union {
2716 bfd_signed_vma refcount;
2717 bfd_vma offset;
2718 } tlsld_got;
252b5132 2719
c6dd29ce 2720 /* Offset of branch table to PltResolve function in glink. */
d7128ce4
AM
2721 bfd_vma glink_pltresolve;
2722
3b36f7e6
AM
2723 /* Size of reserved GOT entries. */
2724 unsigned int got_header_size;
2725 /* Non-zero if allocating the header left a gap. */
2726 unsigned int got_gap;
2727
4a3dc543
RS
2728 /* The type of PLT we have chosen to use. */
2729 enum ppc_elf_plt_type plt_type;
2730
0ba07910
AM
2731 /* Set if we should emit symbols for stubs. */
2732 unsigned int emit_stub_syms:1;
2733
a7f2871e
AM
2734 /* Set if __tls_get_addr optimization should not be done. */
2735 unsigned int no_tls_get_addr_opt:1;
2736
9d8504b1 2737 /* True if the target system is VxWorks. */
016687f8 2738 unsigned int is_vxworks:1;
9d8504b1
PB
2739
2740 /* The size of PLT entries. */
2741 int plt_entry_size;
2742 /* The distance between adjacent PLT slots. */
2743 int plt_slot_size;
2744 /* The size of the first PLT entry. */
2745 int plt_initial_entry_size;
016687f8 2746
87d72d41
AM
2747 /* Small local sym cache. */
2748 struct sym_cache sym_cache;
25dbc73a 2749};
252b5132 2750
b0dddeec
AM
2751/* Rename some of the generic section flags to better document how they
2752 are used here. */
2753
2754/* Nonzero if this section has TLS related relocations. */
2755#define has_tls_reloc sec_flg0
2756
2757/* Nonzero if this section has a call to __tls_get_addr. */
2758#define has_tls_get_addr_call sec_flg1
2759
25dbc73a 2760/* Get the PPC ELF linker hash table from a link_info structure. */
252b5132 2761
25dbc73a 2762#define ppc_elf_hash_table(p) \
4dfe6ac6
NC
2763 (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
2764 == PPC32_ELF_DATA ? ((struct ppc_elf_link_hash_table *) ((p)->hash)) : NULL)
252b5132 2765
25dbc73a 2766/* Create an entry in a PPC ELF linker hash table. */
252b5132 2767
25dbc73a
AM
2768static struct bfd_hash_entry *
2769ppc_elf_link_hash_newfunc (struct bfd_hash_entry *entry,
2770 struct bfd_hash_table *table,
2771 const char *string)
252b5132 2772{
25dbc73a
AM
2773 /* Allocate the structure if it has not already been allocated by a
2774 subclass. */
2775 if (entry == NULL)
2776 {
2777 entry = bfd_hash_allocate (table,
2778 sizeof (struct ppc_elf_link_hash_entry));
2779 if (entry == NULL)
2780 return entry;
2781 }
252b5132 2782
25dbc73a
AM
2783 /* Call the allocation method of the superclass. */
2784 entry = _bfd_elf_link_hash_newfunc (entry, table, string);
2785 if (entry != NULL)
2786 {
2787 ppc_elf_hash_entry (entry)->linker_section_pointer = NULL;
2788 ppc_elf_hash_entry (entry)->dyn_relocs = NULL;
2789 ppc_elf_hash_entry (entry)->tls_mask = 0;
5240d94d 2790 ppc_elf_hash_entry (entry)->has_sda_refs = 0;
25dbc73a 2791 }
252b5132 2792
25dbc73a 2793 return entry;
252b5132 2794}
3dab13f6 2795
25dbc73a 2796/* Create a PPC ELF linker hash table. */
3dab13f6 2797
25dbc73a
AM
2798static struct bfd_link_hash_table *
2799ppc_elf_link_hash_table_create (bfd *abfd)
3dab13f6 2800{
25dbc73a 2801 struct ppc_elf_link_hash_table *ret;
3dab13f6 2802
25dbc73a
AM
2803 ret = bfd_zmalloc (sizeof (struct ppc_elf_link_hash_table));
2804 if (ret == NULL)
2805 return NULL;
3dab13f6 2806
66eb6687
AM
2807 if (!_bfd_elf_link_hash_table_init (&ret->elf, abfd,
2808 ppc_elf_link_hash_newfunc,
4dfe6ac6
NC
2809 sizeof (struct ppc_elf_link_hash_entry),
2810 PPC32_ELF_DATA))
3dab13f6 2811 {
25dbc73a
AM
2812 free (ret);
2813 return NULL;
2814 }
58111eb7 2815
a6aa5195
AM
2816 ret->elf.init_plt_refcount.refcount = 0;
2817 ret->elf.init_plt_refcount.glist = NULL;
2818 ret->elf.init_plt_offset.offset = 0;
2819 ret->elf.init_plt_offset.glist = NULL;
2820
c9a2f333
AM
2821 ret->sdata[0].name = ".sdata";
2822 ret->sdata[0].sym_name = "_SDA_BASE_";
2823 ret->sdata[0].bss_name = ".sbss";
2824
2825 ret->sdata[1].name = ".sdata2";
2826 ret->sdata[1].sym_name = "_SDA2_BASE_";
2827 ret->sdata[1].bss_name = ".sbss2";
2828
9d8504b1
PB
2829 ret->plt_entry_size = 12;
2830 ret->plt_slot_size = 8;
2831 ret->plt_initial_entry_size = 72;
9d8504b1 2832
25dbc73a
AM
2833 return &ret->elf.root;
2834}
3dab13f6 2835
9d8504b1 2836/* Create .got and the related sections. */
3dab13f6 2837
25dbc73a
AM
2838static bfd_boolean
2839ppc_elf_create_got (bfd *abfd, struct bfd_link_info *info)
2840{
2841 struct ppc_elf_link_hash_table *htab;
2842 asection *s;
2843 flagword flags;
3dab13f6 2844
25dbc73a
AM
2845 if (!_bfd_elf_create_got_section (abfd, info))
2846 return FALSE;
3dab13f6 2847
25dbc73a
AM
2848 htab = ppc_elf_hash_table (info);
2849 htab->got = s = bfd_get_section_by_name (abfd, ".got");
2850 if (s == NULL)
2851 abort ();
3dab13f6 2852
9d8504b1
PB
2853 if (htab->is_vxworks)
2854 {
2855 htab->sgotplt = bfd_get_section_by_name (abfd, ".got.plt");
2856 if (!htab->sgotplt)
2857 abort ();
2858 }
2859 else
2860 {
2861 /* The powerpc .got has a blrl instruction in it. Mark it
2862 executable. */
2863 flags = (SEC_ALLOC | SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS
2864 | SEC_IN_MEMORY | SEC_LINKER_CREATED);
2865 if (!bfd_set_section_flags (abfd, s, flags))
2866 return FALSE;
2867 }
3dab13f6 2868
64e77c6d
L
2869 htab->relgot = bfd_get_section_by_name (abfd, ".rela.got");
2870 if (!htab->relgot)
2871 abort ();
3dab13f6 2872
25dbc73a
AM
2873 return TRUE;
2874}
3dab13f6 2875
e054468f
AM
2876static bfd_boolean
2877ppc_elf_create_glink (bfd *abfd, struct bfd_link_info *info)
2878{
2879 struct ppc_elf_link_hash_table *htab = ppc_elf_hash_table (info);
2880 asection *s;
2881 flagword flags;
2882
2883 flags = (SEC_ALLOC | SEC_LOAD | SEC_CODE | SEC_READONLY | SEC_HAS_CONTENTS
2884 | SEC_IN_MEMORY | SEC_LINKER_CREATED);
2885 s = bfd_make_section_anyway_with_flags (abfd, ".glink", flags);
2886 htab->glink = s;
2887 if (s == NULL
2888 || !bfd_set_section_alignment (abfd, s, 4))
2889 return FALSE;
2890
2891 flags = SEC_ALLOC | SEC_LINKER_CREATED;
2892 s = bfd_make_section_anyway_with_flags (abfd, ".iplt", flags);
2893 htab->iplt = s;
2894 if (s == NULL
2895 || !bfd_set_section_alignment (abfd, s, 4))
2896 return FALSE;
2897
2898 flags = (SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_HAS_CONTENTS
2899 | SEC_IN_MEMORY | SEC_LINKER_CREATED);
2900 s = bfd_make_section_with_flags (abfd, ".rela.iplt", flags);
2901 htab->reliplt = s;
2902 if (s == NULL
2903 || ! bfd_set_section_alignment (abfd, s, 2))
2904 return FALSE;
2905 return TRUE;
2906}
2907
25dbc73a
AM
2908/* We have to create .dynsbss and .rela.sbss here so that they get mapped
2909 to output sections (just like _bfd_elf_create_dynamic_sections has
2910 to create .dynbss and .rela.bss). */
3dab13f6 2911
25dbc73a
AM
2912static bfd_boolean
2913ppc_elf_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info)
2914{
2915 struct ppc_elf_link_hash_table *htab;
2916 asection *s;
2917 flagword flags;
3dab13f6 2918
25dbc73a 2919 htab = ppc_elf_hash_table (info);
3dab13f6 2920
25dbc73a
AM
2921 if (htab->got == NULL
2922 && !ppc_elf_create_got (abfd, info))
3dab13f6
AM
2923 return FALSE;
2924
25dbc73a
AM
2925 if (!_bfd_elf_create_dynamic_sections (abfd, info))
2926 return FALSE;
3dab13f6 2927
e054468f
AM
2928 if (htab->glink == NULL
2929 && !ppc_elf_create_glink (abfd, info))
d7128ce4 2930 return FALSE;
3dab13f6 2931
25dbc73a 2932 htab->dynbss = bfd_get_section_by_name (abfd, ".dynbss");
3b36f7e6
AM
2933 s = bfd_make_section_with_flags (abfd, ".dynsbss",
2934 SEC_ALLOC | SEC_LINKER_CREATED);
2935 htab->dynsbss = s;
3496cb2a 2936 if (s == NULL)
25dbc73a 2937 return FALSE;
3dab13f6 2938
25dbc73a
AM
2939 if (! info->shared)
2940 {
2941 htab->relbss = bfd_get_section_by_name (abfd, ".rela.bss");
e054468f
AM
2942 flags = (SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_HAS_CONTENTS
2943 | SEC_IN_MEMORY | SEC_LINKER_CREATED);
d7128ce4 2944 s = bfd_make_section_with_flags (abfd, ".rela.sbss", flags);
3b36f7e6 2945 htab->relsbss = s;
25dbc73a 2946 if (s == NULL
25dbc73a
AM
2947 || ! bfd_set_section_alignment (abfd, s, 2))
2948 return FALSE;
2949 }
3dab13f6 2950
711de32c
RS
2951 if (htab->is_vxworks
2952 && !elf_vxworks_create_dynamic_sections (abfd, info, &htab->srelplt2))
2953 return FALSE;
9d8504b1 2954
25dbc73a
AM
2955 htab->relplt = bfd_get_section_by_name (abfd, ".rela.plt");
2956 htab->plt = s = bfd_get_section_by_name (abfd, ".plt");
2957 if (s == NULL)
2958 abort ();
3dab13f6 2959
3b36f7e6 2960 flags = SEC_ALLOC | SEC_CODE | SEC_LINKER_CREATED;
4a3dc543
RS
2961 if (htab->plt_type == PLT_VXWORKS)
2962 /* The VxWorks PLT is a loaded section with contents. */
2963 flags |= SEC_HAS_CONTENTS | SEC_LOAD | SEC_READONLY;
25dbc73a
AM
2964 return bfd_set_section_flags (abfd, s, flags);
2965}
3dab13f6 2966
25dbc73a 2967/* Copy the extra info we tack onto an elf_link_hash_entry. */
58111eb7 2968
25dbc73a 2969static void
fcfa13d2 2970ppc_elf_copy_indirect_symbol (struct bfd_link_info *info,
25dbc73a
AM
2971 struct elf_link_hash_entry *dir,
2972 struct elf_link_hash_entry *ind)
2973{
2974 struct ppc_elf_link_hash_entry *edir, *eind;
3dab13f6 2975
25dbc73a
AM
2976 edir = (struct ppc_elf_link_hash_entry *) dir;
2977 eind = (struct ppc_elf_link_hash_entry *) ind;
3dab13f6 2978
25dbc73a
AM
2979 if (eind->dyn_relocs != NULL)
2980 {
2981 if (edir->dyn_relocs != NULL)
3dab13f6 2982 {
25dbc73a
AM
2983 struct ppc_elf_dyn_relocs **pp;
2984 struct ppc_elf_dyn_relocs *p;
3dab13f6 2985
fcfa13d2 2986 /* Add reloc counts against the indirect sym to the direct sym
25dbc73a
AM
2987 list. Merge any entries against the same section. */
2988 for (pp = &eind->dyn_relocs; (p = *pp) != NULL; )
3dab13f6 2989 {
25dbc73a
AM
2990 struct ppc_elf_dyn_relocs *q;
2991
2992 for (q = edir->dyn_relocs; q != NULL; q = q->next)
2993 if (q->sec == p->sec)
2994 {
2995 q->pc_count += p->pc_count;
2996 q->count += p->count;
2997 *pp = p->next;
2998 break;
2999 }
3000 if (q == NULL)
3001 pp = &p->next;
3dab13f6 3002 }
25dbc73a 3003 *pp = edir->dyn_relocs;
3dab13f6 3004 }
25dbc73a
AM
3005
3006 edir->dyn_relocs = eind->dyn_relocs;
3007 eind->dyn_relocs = NULL;
3dab13f6 3008 }
3dab13f6 3009
25dbc73a 3010 edir->tls_mask |= eind->tls_mask;
4dc4a9a5 3011 edir->has_sda_refs |= eind->has_sda_refs;
3dab13f6 3012
a6aa5195
AM
3013 /* If called to transfer flags for a weakdef during processing
3014 of elf_adjust_dynamic_symbol, don't copy non_got_ref.
3015 We clear it ourselves for ELIMINATE_COPY_RELOCS. */
3016 if (!(ELIMINATE_COPY_RELOCS
3017 && eind->elf.root.type != bfd_link_hash_indirect
3018 && edir->elf.dynamic_adjusted))
3019 edir->elf.non_got_ref |= eind->elf.non_got_ref;
3020
3021 edir->elf.ref_dynamic |= eind->elf.ref_dynamic;
3022 edir->elf.ref_regular |= eind->elf.ref_regular;
3023 edir->elf.ref_regular_nonweak |= eind->elf.ref_regular_nonweak;
3024 edir->elf.needs_plt |= eind->elf.needs_plt;
0eb4a168 3025 edir->elf.pointer_equality_needed |= eind->elf.pointer_equality_needed;
a6aa5195
AM
3026
3027 /* If we were called to copy over info for a weak sym, that's all. */
3028 if (eind->elf.root.type != bfd_link_hash_indirect)
3029 return;
3030
3031 /* Copy over the GOT refcount entries that we may have already seen to
3032 the symbol which just became indirect. */
fcfa13d2
AM
3033 edir->elf.got.refcount += eind->elf.got.refcount;
3034 eind->elf.got.refcount = 0;
a6aa5195
AM
3035
3036 /* And plt entries. */
3037 if (eind->elf.plt.plist != NULL)
3038 {
3039 if (edir->elf.plt.plist != NULL)
3040 {
3041 struct plt_entry **entp;
3042 struct plt_entry *ent;
3043
3044 for (entp = &eind->elf.plt.plist; (ent = *entp) != NULL; )
3045 {
3046 struct plt_entry *dent;
3047
3048 for (dent = edir->elf.plt.plist; dent != NULL; dent = dent->next)
3049 if (dent->sec == ent->sec && dent->addend == ent->addend)
3050 {
3051 dent->plt.refcount += ent->plt.refcount;
3052 *entp = ent->next;
3053 break;
3054 }
3055 if (dent == NULL)
3056 entp = &ent->next;
3057 }
3058 *entp = edir->elf.plt.plist;
3059 }
3060
3061 edir->elf.plt.plist = eind->elf.plt.plist;
3062 eind->elf.plt.plist = NULL;
3063 }
3064
fcfa13d2 3065 if (eind->elf.dynindx != -1)
25dbc73a 3066 {
fcfa13d2
AM
3067 if (edir->elf.dynindx != -1)
3068 _bfd_elf_strtab_delref (elf_hash_table (info)->dynstr,
3069 edir->elf.dynstr_index);
a6aa5195
AM
3070 edir->elf.dynindx = eind->elf.dynindx;
3071 edir->elf.dynstr_index = eind->elf.dynstr_index;
3072 eind->elf.dynindx = -1;
3073 eind->elf.dynstr_index = 0;
25dbc73a 3074 }
25dbc73a 3075}
3dab13f6 3076
25dbc73a
AM
3077/* Hook called by the linker routine which adds symbols from an object
3078 file. We use it to put .comm items in .sbss, and not .bss. */
58111eb7 3079
25dbc73a
AM
3080static bfd_boolean
3081ppc_elf_add_symbol_hook (bfd *abfd,
3082 struct bfd_link_info *info,
3083 Elf_Internal_Sym *sym,
3084 const char **namep ATTRIBUTE_UNUSED,
3085 flagword *flagsp ATTRIBUTE_UNUSED,
3086 asection **secp,
3087 bfd_vma *valp)
3088{
3089 if (sym->st_shndx == SHN_COMMON
3090 && !info->relocatable
0c8d6e5c
AM
3091 && is_ppc_elf (info->output_bfd)
3092 && sym->st_size <= elf_gp_size (abfd))
25dbc73a
AM
3093 {
3094 /* Common symbols less than or equal to -G nn bytes are automatically
3095 put into .sbss. */
3096 struct ppc_elf_link_hash_table *htab;
3dab13f6 3097
25dbc73a
AM
3098 htab = ppc_elf_hash_table (info);
3099 if (htab->sbss == NULL)
3100 {
644285ef 3101 flagword flags = SEC_IS_COMMON | SEC_LINKER_CREATED;
3dab13f6 3102
644285ef
AM
3103 if (!htab->elf.dynobj)
3104 htab->elf.dynobj = abfd;
3105
3496cb2a
L
3106 htab->sbss = bfd_make_section_anyway_with_flags (htab->elf.dynobj,
3107 ".sbss",
3108 flags);
3109 if (htab->sbss == NULL)
25dbc73a 3110 return FALSE;
3dab13f6 3111 }
3dab13f6 3112
25dbc73a
AM
3113 *secp = htab->sbss;
3114 *valp = sym->st_size;
3115 }
3dab13f6 3116
c16153ae 3117 if ((abfd->flags & DYNAMIC) == 0
f64b2e8d
NC
3118 && (ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC
3119 || ELF_ST_BIND (sym->st_info) == STB_GNU_UNIQUE))
3120 elf_tdata (info->output_bfd)->has_gnu_symbols = TRUE;
e054468f 3121
25dbc73a 3122 return TRUE;
3dab13f6
AM
3123}
3124\f
046183de 3125static bfd_boolean
bd6c6e2b 3126create_sdata_sym (struct bfd_link_info *info, elf_linker_section_t *lsect)
046183de 3127{
bd6c6e2b
AM
3128 struct ppc_elf_link_hash_table *htab = ppc_elf_hash_table (info);
3129
046183de
AM
3130 lsect->sym = elf_link_hash_lookup (&htab->elf, lsect->sym_name,
3131 TRUE, FALSE, TRUE);
3132 if (lsect->sym == NULL)
3133 return FALSE;
3134 if (lsect->sym->root.type == bfd_link_hash_new)
3135 lsect->sym->non_elf = 0;
3136 lsect->sym->ref_regular = 1;
bd6c6e2b 3137 _bfd_elf_link_hash_hide_symbol (info, lsect->sym, TRUE);
046183de
AM
3138 return TRUE;
3139}
3140
c9a2f333 3141/* Create a special linker section. */
25dbc73a 3142
c9a2f333 3143static bfd_boolean
55fd94b0
AM
3144ppc_elf_create_linker_section (bfd *abfd,
3145 struct bfd_link_info *info,
c9a2f333
AM
3146 flagword flags,
3147 elf_linker_section_t *lsect)
252b5132 3148{
58111eb7 3149 struct ppc_elf_link_hash_table *htab = ppc_elf_hash_table (info);
c9a2f333 3150 asection *s;
58111eb7 3151
c9a2f333
AM
3152 flags |= (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
3153 | SEC_LINKER_CREATED);
58111eb7
AM
3154
3155 /* Record the first bfd that needs the special sections. */
3156 if (!htab->elf.dynobj)
3157 htab->elf.dynobj = abfd;
3158
3496cb2a
L
3159 s = bfd_make_section_anyway_with_flags (htab->elf.dynobj,
3160 lsect->name,
3161 flags);
76750a2f 3162 if (s == NULL
76750a2f 3163 || !bfd_set_section_alignment (htab->elf.dynobj, s, 2))
c9a2f333 3164 return FALSE;
76750a2f 3165 lsect->section = s;
58111eb7 3166
bd6c6e2b 3167 return create_sdata_sym (info, lsect);
252b5132 3168}
252b5132 3169
25dbc73a
AM
3170/* Find a linker generated pointer with a given addend and type. */
3171
3172static elf_linker_section_pointers_t *
3173elf_find_pointer_linker_section
3174 (elf_linker_section_pointers_t *linker_pointers,
3175 bfd_vma addend,
3176 elf_linker_section_t *lsect)
252b5132 3177{
25dbc73a
AM
3178 for ( ; linker_pointers != NULL; linker_pointers = linker_pointers->next)
3179 if (lsect == linker_pointers->lsect && addend == linker_pointers->addend)
3180 return linker_pointers;
252b5132 3181
25dbc73a
AM
3182 return NULL;
3183}
3184
3185/* Allocate a pointer to live in a linker created section. */
3186
3187static bfd_boolean
3188elf_create_pointer_linker_section (bfd *abfd,
25dbc73a
AM
3189 elf_linker_section_t *lsect,
3190 struct elf_link_hash_entry *h,
3191 const Elf_Internal_Rela *rel)
3192{
3193 elf_linker_section_pointers_t **ptr_linker_section_ptr = NULL;
3194 elf_linker_section_pointers_t *linker_section_ptr;
3195 unsigned long r_symndx = ELF32_R_SYM (rel->r_info);
3196 bfd_size_type amt;
3197
3198 BFD_ASSERT (lsect != NULL);
3199
3200 /* Is this a global symbol? */
3201 if (h != NULL)
3202 {
3203 struct ppc_elf_link_hash_entry *eh;
3204
3205 /* Has this symbol already been allocated? If so, our work is done. */
3206 eh = (struct ppc_elf_link_hash_entry *) h;
3207 if (elf_find_pointer_linker_section (eh->linker_section_pointer,
3208 rel->r_addend,
3209 lsect))
3210 return TRUE;
3211
3212 ptr_linker_section_ptr = &eh->linker_section_pointer;
25dbc73a
AM
3213 }
3214 else
3215 {
0c8d6e5c 3216 BFD_ASSERT (is_ppc_elf (abfd));
0ffa91dd 3217
25dbc73a
AM
3218 /* Allocation of a pointer to a local symbol. */
3219 elf_linker_section_pointers_t **ptr = elf_local_ptr_offsets (abfd);
3220
3221 /* Allocate a table to hold the local symbols if first time. */
3222 if (!ptr)
3223 {
0ffa91dd 3224 unsigned int num_symbols = elf_symtab_hdr (abfd).sh_info;
25dbc73a
AM
3225
3226 amt = num_symbols;
3227 amt *= sizeof (elf_linker_section_pointers_t *);
3228 ptr = bfd_zalloc (abfd, amt);
3229
3230 if (!ptr)
3231 return FALSE;
3232
3233 elf_local_ptr_offsets (abfd) = ptr;
3234 }
3235
3236 /* Has this symbol already been allocated? If so, our work is done. */
3237 if (elf_find_pointer_linker_section (ptr[r_symndx],
3238 rel->r_addend,
3239 lsect))
3240 return TRUE;
252b5132 3241
25dbc73a 3242 ptr_linker_section_ptr = &ptr[r_symndx];
25dbc73a 3243 }
41fcb14e 3244
25dbc73a
AM
3245 /* Allocate space for a pointer in the linker section, and allocate
3246 a new pointer record from internal memory. */
3247 BFD_ASSERT (ptr_linker_section_ptr != NULL);
3248 amt = sizeof (elf_linker_section_pointers_t);
3249 linker_section_ptr = bfd_alloc (abfd, amt);
41fcb14e 3250
25dbc73a 3251 if (!linker_section_ptr)
7619e7c7 3252 return FALSE;
41fcb14e 3253
25dbc73a
AM
3254 linker_section_ptr->next = *ptr_linker_section_ptr;
3255 linker_section_ptr->addend = rel->r_addend;
3256 linker_section_ptr->lsect = lsect;
25dbc73a 3257 *ptr_linker_section_ptr = linker_section_ptr;
41fcb14e 3258
25dbc73a
AM
3259 linker_section_ptr->offset = lsect->section->size;
3260 lsect->section->size += 4;
7619e7c7 3261
25dbc73a
AM
3262#ifdef DEBUG
3263 fprintf (stderr,
3264 "Create pointer in linker section %s, offset = %ld, section size = %ld\n",
3265 lsect->name, (long) linker_section_ptr->offset,
3266 (long) lsect->section->size);
3267#endif
7619e7c7
AM
3268
3269 return TRUE;
41fcb14e
AM
3270}
3271
e054468f 3272static struct plt_entry **
25dbc73a
AM
3273update_local_sym_info (bfd *abfd,
3274 Elf_Internal_Shdr *symtab_hdr,
3275 unsigned long r_symndx,
3276 int tls_type)
252b5132 3277{
25dbc73a 3278 bfd_signed_vma *local_got_refcounts = elf_local_got_refcounts (abfd);
e054468f 3279 struct plt_entry **local_plt;
25dbc73a 3280 char *local_got_tls_masks;
252b5132 3281
25dbc73a 3282 if (local_got_refcounts == NULL)
252b5132 3283 {
25dbc73a
AM
3284 bfd_size_type size = symtab_hdr->sh_info;
3285
e054468f
AM
3286 size *= (sizeof (*local_got_refcounts)
3287 + sizeof (*local_plt)
3288 + sizeof (*local_got_tls_masks));
25dbc73a
AM
3289 local_got_refcounts = bfd_zalloc (abfd, size);
3290 if (local_got_refcounts == NULL)
e054468f 3291 return NULL;
25dbc73a 3292 elf_local_got_refcounts (abfd) = local_got_refcounts;
252b5132 3293 }
41fcb14e 3294
e054468f
AM
3295 local_plt = (struct plt_entry **) (local_got_refcounts + symtab_hdr->sh_info);
3296 local_got_tls_masks = (char *) (local_plt + symtab_hdr->sh_info);
25dbc73a 3297 local_got_tls_masks[r_symndx] |= tls_type;
e054468f
AM
3298 if (tls_type != PLT_IFUNC)
3299 local_got_refcounts[r_symndx] += 1;
3300 return local_plt + r_symndx;
25dbc73a 3301}
41fcb14e 3302
a6aa5195 3303static bfd_boolean
3ec01793 3304update_plt_info (bfd *abfd, struct plt_entry **plist,
a6aa5195
AM
3305 asection *sec, bfd_vma addend)
3306{
3307 struct plt_entry *ent;
3308
32af9f6e
AM
3309 if (addend < 32768)
3310 sec = NULL;
3ec01793 3311 for (ent = *plist; ent != NULL; ent = ent->next)
a6aa5195
AM
3312 if (ent->sec == sec && ent->addend == addend)
3313 break;
3314 if (ent == NULL)
3315 {
3316 bfd_size_type amt = sizeof (*ent);
3317 ent = bfd_alloc (abfd, amt);
3318 if (ent == NULL)
3319 return FALSE;
3ec01793 3320 ent->next = *plist;
a6aa5195
AM
3321 ent->sec = sec;
3322 ent->addend = addend;
3323 ent->plt.refcount = 0;
3ec01793 3324 *plist = ent;
a6aa5195
AM
3325 }
3326 ent->plt.refcount += 1;
3327 return TRUE;
3328}
3329
3330static struct plt_entry *
3ec01793 3331find_plt_ent (struct plt_entry **plist, asection *sec, bfd_vma addend)
a6aa5195
AM
3332{
3333 struct plt_entry *ent;
3334
3335 if (addend < 32768)
3336 sec = NULL;
3ec01793 3337 for (ent = *plist; ent != NULL; ent = ent->next)
a6aa5195
AM
3338 if (ent->sec == sec && ent->addend == addend)
3339 break;
3340 return ent;
3341}
3342
e054468f
AM
3343static bfd_boolean
3344is_branch_reloc (enum elf_ppc_reloc_type r_type)
3345{
3346 return (r_type == R_PPC_PLTREL24
3347 || r_type == R_PPC_LOCAL24PC
3348 || r_type == R_PPC_REL24
3349 || r_type == R_PPC_REL14
3350 || r_type == R_PPC_REL14_BRTAKEN
3351 || r_type == R_PPC_REL14_BRNTAKEN
3352 || r_type == R_PPC_ADDR24
3353 || r_type == R_PPC_ADDR14
3354 || r_type == R_PPC_ADDR14_BRTAKEN
3355 || r_type == R_PPC_ADDR14_BRNTAKEN);
3356}
3357
25dbc73a
AM
3358static void
3359bad_shared_reloc (bfd *abfd, enum elf_ppc_reloc_type r_type)
3360{
3361 (*_bfd_error_handler)
3362 (_("%B: relocation %s cannot be used when making a shared object"),
3363 abfd,
3364 ppc_elf_howto_table[r_type]->name);
3365 bfd_set_error (bfd_error_bad_value);
252b5132
RH
3366}
3367
25dbc73a
AM
3368/* Look through the relocs for a section during the first phase, and
3369 allocate space in the global offset table or procedure linkage
3370 table. */
252b5132 3371
b34976b6 3372static bfd_boolean
25dbc73a
AM
3373ppc_elf_check_relocs (bfd *abfd,
3374 struct bfd_link_info *info,
3375 asection *sec,
3376 const Elf_Internal_Rela *relocs)
252b5132 3377{
7619e7c7 3378 struct ppc_elf_link_hash_table *htab;
25dbc73a
AM
3379 Elf_Internal_Shdr *symtab_hdr;
3380 struct elf_link_hash_entry **sym_hashes;
3381 const Elf_Internal_Rela *rel;
3382 const Elf_Internal_Rela *rel_end;
a6aa5195 3383 asection *got2, *sreloc;
727fc41e 3384 struct elf_link_hash_entry *tga;
25dbc73a
AM
3385
3386 if (info->relocatable)
3387 return TRUE;
252b5132 3388
c87b5a93
AM
3389 /* Don't do anything special with non-loaded, non-alloced sections.
3390 In particular, any relocs in such sections should not affect GOT
3391 and PLT reference counting (ie. we don't allow them to create GOT
3392 or PLT entries), there's no possibility or desire to optimize TLS
3393 relocs, and there's not much point in propagating relocs to shared
3394 libs that the dynamic linker won't relocate. */
3395 if ((sec->flags & SEC_ALLOC) == 0)
3396 return TRUE;
3397
252b5132 3398#ifdef DEBUG
25dbc73a
AM
3399 _bfd_error_handler ("ppc_elf_check_relocs called for section %A in %B",
3400 sec, abfd);
252b5132
RH
3401#endif
3402
0c8d6e5c 3403 BFD_ASSERT (is_ppc_elf (abfd));
0ffa91dd 3404
25dbc73a
AM
3405 /* Initialize howto table if not already done. */
3406 if (!ppc_elf_howto_table[R_PPC_ADDR32])
3407 ppc_elf_howto_init ();
3408
7619e7c7 3409 htab = ppc_elf_hash_table (info);
25f23106
AM
3410 if (htab->glink == NULL)
3411 {
3412 if (htab->elf.dynobj == NULL)
3413 htab->elf.dynobj = abfd;
3414 if (!ppc_elf_create_glink (htab->elf.dynobj, info))
3415 return FALSE;
3416 }
727fc41e
AM
3417 tga = elf_link_hash_lookup (&htab->elf, "__tls_get_addr",
3418 FALSE, FALSE, TRUE);
0ffa91dd 3419 symtab_hdr = &elf_symtab_hdr (abfd);
25dbc73a 3420 sym_hashes = elf_sym_hashes (abfd);
a6aa5195 3421 got2 = bfd_get_section_by_name (abfd, ".got2");
25dbc73a
AM
3422 sreloc = NULL;
3423
3424 rel_end = relocs + sec->reloc_count;
3425 for (rel = relocs; rel < rel_end; rel++)
3426 {
3427 unsigned long r_symndx;
3428 enum elf_ppc_reloc_type r_type;
3429 struct elf_link_hash_entry *h;
727fc41e 3430 int tls_type;
25dbc73a
AM
3431
3432 r_symndx = ELF32_R_SYM (rel->r_info);
3433 if (r_symndx < symtab_hdr->sh_info)
3434 h = NULL;
3435 else
973a3492
L
3436 {
3437 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
3438 while (h->root.type == bfd_link_hash_indirect
3439 || h->root.type == bfd_link_hash_warning)
3440 h = (struct elf_link_hash_entry *) h->root.u.i.link;
3441 }
25dbc73a
AM
3442
3443 /* If a relocation refers to _GLOBAL_OFFSET_TABLE_, create the .got.
3444 This shows up in particular in an R_PPC_ADDR32 in the eabi
3445 startup code. */
3b36f7e6
AM
3446 if (h != NULL
3447 && htab->got == NULL
3448 && strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
252b5132 3449 {
3b36f7e6
AM
3450 if (htab->elf.dynobj == NULL)
3451 htab->elf.dynobj = abfd;
3452 if (!ppc_elf_create_got (htab->elf.dynobj, info))
3453 return FALSE;
3454 BFD_ASSERT (h == htab->elf.hgot);
25dbc73a 3455 }
252b5132 3456
727fc41e 3457 tls_type = 0;
de972ffa 3458 r_type = ELF32_R_TYPE (rel->r_info);
06a162cf 3459 if (h == NULL && !htab->is_vxworks)
e054468f 3460 {
06a162cf
AM
3461 Elf_Internal_Sym *isym = bfd_sym_from_r_symndx (&htab->sym_cache,
3462 abfd, r_symndx);
3463 if (isym == NULL)
3464 return FALSE;
3465
3466 if (ELF_ST_TYPE (isym->st_info) == STT_GNU_IFUNC
3467 && (!info->shared
3468 || is_branch_reloc (r_type)))
e054468f 3469 {
06a162cf
AM
3470 struct plt_entry **ifunc;
3471 bfd_vma addend;
3472
3473 ifunc = update_local_sym_info (abfd, symtab_hdr, r_symndx,
3474 PLT_IFUNC);
3475 if (ifunc == NULL)
e054468f
AM
3476 return FALSE;
3477
06a162cf
AM
3478 /* STT_GNU_IFUNC symbols must have a PLT entry;
3479 In a non-pie executable even when there are
3480 no plt calls. */
3481 addend = 0;
3482 if (r_type == R_PPC_PLTREL24)
e054468f 3483 {
06a162cf
AM
3484 ppc_elf_tdata (abfd)->makes_plt_call = 1;
3485 if (info->shared)
3486 addend = rel->r_addend;
e054468f 3487 }
06a162cf
AM
3488 if (!update_plt_info (abfd, ifunc, got2, addend))
3489 return FALSE;
e054468f 3490 }
25f23106
AM
3491 }
3492
de972ffa
AM
3493 if (!htab->is_vxworks
3494 && is_branch_reloc (r_type)
3495 && h != NULL
3496 && h == tga)
25f23106 3497 {
de972ffa
AM
3498 if (rel != relocs
3499 && (ELF32_R_TYPE (rel[-1].r_info) == R_PPC_TLSGD
3500 || ELF32_R_TYPE (rel[-1].r_info) == R_PPC_TLSLD))
3501 /* We have a new-style __tls_get_addr call with a marker
3502 reloc. */
3503 ;
3504 else
3505 /* Mark this section as having an old-style call. */
3506 sec->has_tls_get_addr_call = 1;
e054468f 3507 }
727fc41e 3508
25dbc73a
AM
3509 switch (r_type)
3510 {
727fc41e
AM
3511 case R_PPC_TLSGD:
3512 case R_PPC_TLSLD:
3513 /* These special tls relocs tie a call to __tls_get_addr with
3514 its parameter symbol. */
3515 break;
3516
25dbc73a
AM
3517 case R_PPC_GOT_TLSLD16:
3518 case R_PPC_GOT_TLSLD16_LO:
3519 case R_PPC_GOT_TLSLD16_HI:
3520 case R_PPC_GOT_TLSLD16_HA:
25dbc73a
AM
3521 tls_type = TLS_TLS | TLS_LD;
3522 goto dogottls;
252b5132 3523
25dbc73a
AM
3524 case R_PPC_GOT_TLSGD16:
3525 case R_PPC_GOT_TLSGD16_LO:
3526 case R_PPC_GOT_TLSGD16_HI:
3527 case R_PPC_GOT_TLSGD16_HA:
3528 tls_type = TLS_TLS | TLS_GD;
3529 goto dogottls;
3530
3531 case R_PPC_GOT_TPREL16:
3532 case R_PPC_GOT_TPREL16_LO:
3533 case R_PPC_GOT_TPREL16_HI:
3534 case R_PPC_GOT_TPREL16_HA:
1d483afe 3535 if (!info->executable)
25dbc73a
AM
3536 info->flags |= DF_STATIC_TLS;
3537 tls_type = TLS_TLS | TLS_TPREL;
3538 goto dogottls;
3539
3540 case R_PPC_GOT_DTPREL16:
3541 case R_PPC_GOT_DTPREL16_LO:
3542 case R_PPC_GOT_DTPREL16_HI:
3543 case R_PPC_GOT_DTPREL16_HA:
3544 tls_type = TLS_TLS | TLS_DTPREL;
3545 dogottls:
3546 sec->has_tls_reloc = 1;
3547 /* Fall thru */
252b5132 3548
25dbc73a
AM
3549 /* GOT16 relocations */
3550 case R_PPC_GOT16:
3551 case R_PPC_GOT16_LO:
3552 case R_PPC_GOT16_HI:
3553 case R_PPC_GOT16_HA:
3554 /* This symbol requires a global offset table entry. */
3555 if (htab->got == NULL)
3556 {
3557 if (htab->elf.dynobj == NULL)
3558 htab->elf.dynobj = abfd;
3559 if (!ppc_elf_create_got (htab->elf.dynobj, info))
3560 return FALSE;
3561 }
3562 if (h != NULL)
3563 {
3564 h->got.refcount += 1;
3565 ppc_elf_hash_entry (h)->tls_mask |= tls_type;
3566 }
3567 else
3568 /* This is a global offset table entry for a local symbol. */
3569 if (!update_local_sym_info (abfd, symtab_hdr, r_symndx, tls_type))
3570 return FALSE;
91e21fb7
AM
3571
3572 /* We may also need a plt entry if the symbol turns out to be
3573 an ifunc. */
3574 if (h != NULL && !info->shared)
3575 {
3576 if (!update_plt_info (abfd, &h->plt.plist, NULL, 0))
3577 return FALSE;
3578 }
25dbc73a 3579 break;
252b5132 3580
25dbc73a
AM
3581 /* Indirect .sdata relocation. */
3582 case R_PPC_EMB_SDAI16:
3583 if (info->shared)
3584 {
3585 bad_shared_reloc (abfd, r_type);
3586 return FALSE;
3587 }
c9a2f333
AM
3588 if (htab->sdata[0].section == NULL
3589 && !ppc_elf_create_linker_section (abfd, info, 0,
3590 &htab->sdata[0]))
3591 return FALSE;
76750a2f
AM
3592 if (!elf_create_pointer_linker_section (abfd, &htab->sdata[0],
3593 h, rel))
25dbc73a 3594 return FALSE;
046183de
AM
3595 if (h != NULL)
3596 {
3597 ppc_elf_hash_entry (h)->has_sda_refs = TRUE;
3598 h->non_got_ref = TRUE;
3599 }
25dbc73a 3600 break;
252b5132 3601
25dbc73a
AM
3602 /* Indirect .sdata2 relocation. */
3603 case R_PPC_EMB_SDA2I16:
3604 if (info->shared)
3605 {
3606 bad_shared_reloc (abfd, r_type);
3607 return FALSE;
3608 }
c9a2f333
AM
3609 if (htab->sdata[1].section == NULL
3610 && !ppc_elf_create_linker_section (abfd, info, SEC_READONLY,
3611 &htab->sdata[1]))
3612 return FALSE;
76750a2f
AM
3613 if (!elf_create_pointer_linker_section (abfd, &htab->sdata[1],
3614 h, rel))
25dbc73a 3615 return FALSE;
046183de
AM
3616 if (h != NULL)
3617 {
3618 ppc_elf_hash_entry (h)->has_sda_refs = TRUE;
3619 h->non_got_ref = TRUE;
3620 }
25dbc73a 3621 break;
252b5132 3622
25dbc73a 3623 case R_PPC_SDAREL16:
046183de 3624 if (htab->sdata[0].sym == NULL
bd6c6e2b 3625 && !create_sdata_sym (info, &htab->sdata[0]))
046183de
AM
3626 return FALSE;
3627 if (h != NULL)
3628 {
3629 ppc_elf_hash_entry (h)->has_sda_refs = TRUE;
3630 h->non_got_ref = TRUE;
3631 }
3632 break;
3633
25dbc73a 3634 case R_PPC_EMB_SDA2REL:
046183de
AM
3635 if (info->shared)
3636 {
3637 bad_shared_reloc (abfd, r_type);
3638 return FALSE;
3639 }
3640 if (htab->sdata[1].sym == NULL
bd6c6e2b 3641 && !create_sdata_sym (info, &htab->sdata[1]))
046183de
AM
3642 return FALSE;
3643 if (h != NULL)
3644 {
3645 ppc_elf_hash_entry (h)->has_sda_refs = TRUE;
3646 h->non_got_ref = TRUE;
3647 }
3648 break;
3649
25dbc73a
AM
3650 case R_PPC_EMB_SDA21:
3651 case R_PPC_EMB_RELSDA:
046183de
AM
3652 if (info->shared)
3653 {
3654 bad_shared_reloc (abfd, r_type);
3655 return FALSE;
3656 }
3657 if (htab->sdata[0].sym == NULL
bd6c6e2b 3658 && !create_sdata_sym (info, &htab->sdata[0]))
046183de
AM
3659 return FALSE;
3660 if (htab->sdata[1].sym == NULL
bd6c6e2b 3661 && !create_sdata_sym (info, &htab->sdata[1]))
046183de
AM
3662 return FALSE;
3663 if (h != NULL)
3664 {
3665 ppc_elf_hash_entry (h)->has_sda_refs = TRUE;
3666 h->non_got_ref = TRUE;
3667 }
3668 break;
3669
25dbc73a
AM
3670 case R_PPC_EMB_NADDR32:
3671 case R_PPC_EMB_NADDR16:
3672 case R_PPC_EMB_NADDR16_LO:
3673 case R_PPC_EMB_NADDR16_HI:
3674 case R_PPC_EMB_NADDR16_HA:
3675 if (info->shared)
3676 {
3677 bad_shared_reloc (abfd, r_type);
3678 return FALSE;
3679 }
4dc4a9a5 3680 if (h != NULL)
046183de 3681 h->non_got_ref = TRUE;
25dbc73a 3682 break;
252b5132 3683
25dbc73a 3684 case R_PPC_PLTREL24:
de972ffa 3685 if (h == NULL)
6d78d0b9
AM
3686 break;
3687 /* Fall through */
3688 case R_PPC_PLT32:
25dbc73a
AM
3689 case R_PPC_PLTREL32:
3690 case R_PPC_PLT16_LO:
3691 case R_PPC_PLT16_HI:
3692 case R_PPC_PLT16_HA:
3693#ifdef DEBUG
3694 fprintf (stderr, "Reloc requires a PLT entry\n");
3695#endif
3696 /* This symbol requires a procedure linkage table entry. We
3697 actually build the entry in finish_dynamic_symbol,
3698 because this might be a case of linking PIC code without
3699 linking in any dynamic objects, in which case we don't
3700 need to generate a procedure linkage table after all. */
7619e7c7 3701
25dbc73a
AM
3702 if (h == NULL)
3703 {
3704 /* It does not make sense to have a procedure linkage
3705 table entry for a local symbol. */
3706 (*_bfd_error_handler) (_("%B(%A+0x%lx): %s reloc against "
3707 "local symbol"),
3708 abfd,
3709 sec,
3710 (long) rel->r_offset,
3711 ppc_elf_howto_table[r_type]->name);
3712 bfd_set_error (bfd_error_bad_value);
3713 return FALSE;
3714 }
a6aa5195
AM
3715 else
3716 {
016687f8 3717 bfd_vma addend = 0;
ee05f2fe 3718
016687f8
AM
3719 if (r_type == R_PPC_PLTREL24)
3720 {
3721 ppc_elf_tdata (abfd)->makes_plt_call = 1;
a877a2b6
AM
3722 if (info->shared)
3723 addend = rel->r_addend;
016687f8 3724 }
a6aa5195 3725 h->needs_plt = 1;
32af9f6e 3726 if (!update_plt_info (abfd, &h->plt.plist, got2, addend))
a6aa5195
AM
3727 return FALSE;
3728 }
25dbc73a 3729 break;
ee05f2fe 3730
25dbc73a
AM
3731 /* The following relocations don't need to propagate the
3732 relocation if linking a shared object since they are
3733 section relative. */
3734 case R_PPC_SECTOFF:
3735 case R_PPC_SECTOFF_LO:
3736 case R_PPC_SECTOFF_HI:
3737 case R_PPC_SECTOFF_HA:
3738 case R_PPC_DTPREL16:
3739 case R_PPC_DTPREL16_LO:
3740 case R_PPC_DTPREL16_HI:
3741 case R_PPC_DTPREL16_HA:
3742 case R_PPC_TOC16:
3743 break;
252b5132 3744
d7128ce4
AM
3745 case R_PPC_REL16:
3746 case R_PPC_REL16_LO:
3747 case R_PPC_REL16_HI:
3748 case R_PPC_REL16_HA:
016687f8 3749 ppc_elf_tdata (abfd)->has_rel16 = 1;
d7128ce4
AM
3750 break;
3751
a6aa5195 3752 /* These are just markers. */
25dbc73a
AM
3753 case R_PPC_TLS:
3754 case R_PPC_EMB_MRKREF:
3755 case R_PPC_NONE:
3756 case R_PPC_max:
32af9f6e
AM
3757 case R_PPC_RELAX:
3758 case R_PPC_RELAX_PLT:
3759 case R_PPC_RELAX_PLTREL24:
25dbc73a 3760 break;
252b5132 3761
25dbc73a
AM
3762 /* These should only appear in dynamic objects. */
3763 case R_PPC_COPY:
3764 case R_PPC_GLOB_DAT:
3765 case R_PPC_JMP_SLOT:
3766 case R_PPC_RELATIVE:
e054468f 3767 case R_PPC_IRELATIVE:
25dbc73a 3768 break;
252b5132 3769
25dbc73a
AM
3770 /* These aren't handled yet. We'll report an error later. */
3771 case R_PPC_ADDR30:
3772 case R_PPC_EMB_RELSEC16:
3773 case R_PPC_EMB_RELST_LO:
3774 case R_PPC_EMB_RELST_HI:
3775 case R_PPC_EMB_RELST_HA:
3776 case R_PPC_EMB_BIT_FLD:
3777 break;
252b5132 3778
25dbc73a
AM
3779 /* This refers only to functions defined in the shared library. */
3780 case R_PPC_LOCAL24PC:
727fc41e 3781 if (h != NULL && h == htab->elf.hgot && htab->plt_type == PLT_UNSET)
016687f8
AM
3782 {
3783 htab->plt_type = PLT_OLD;
3784 htab->old_bfd = abfd;
3785 }
25dbc73a 3786 break;
252b5132 3787
25dbc73a
AM
3788 /* This relocation describes the C++ object vtable hierarchy.
3789 Reconstruct it for later use during GC. */
3790 case R_PPC_GNU_VTINHERIT:
3791 if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
3792 return FALSE;
3793 break;
252b5132 3794
25dbc73a
AM
3795 /* This relocation describes which C++ vtable entries are actually
3796 used. Record for later use during GC. */
3797 case R_PPC_GNU_VTENTRY:
d17e0c6e
JB
3798 BFD_ASSERT (h != NULL);
3799 if (h != NULL
3800 && !bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
25dbc73a
AM
3801 return FALSE;
3802 break;
252b5132 3803
25dbc73a
AM
3804 /* We shouldn't really be seeing these. */
3805 case R_PPC_TPREL32:
1d483afe
AM
3806 case R_PPC_TPREL16:
3807 case R_PPC_TPREL16_LO:
3808 case R_PPC_TPREL16_HI:
3809 case R_PPC_TPREL16_HA:
3810 if (!info->executable)
25dbc73a
AM
3811 info->flags |= DF_STATIC_TLS;
3812 goto dodyn;
252b5132 3813
25dbc73a
AM
3814 /* Nor these. */
3815 case R_PPC_DTPMOD32:
3816 case R_PPC_DTPREL32:
3817 goto dodyn;
252b5132 3818
9edfd1af
AM
3819 case R_PPC_REL32:
3820 if (h == NULL
3821 && got2 != NULL
3822 && (sec->flags & SEC_CODE) != 0
a877a2b6 3823 && info->shared
4a3dc543 3824 && htab->plt_type == PLT_UNSET)
9edfd1af
AM
3825 {
3826 /* Old -fPIC gcc code has .long LCTOC1-LCFx just before
3827 the start of a function, which assembles to a REL32
3828 reference to .got2. If we detect one of these, then
3829 force the old PLT layout because the linker cannot
3830 reliably deduce the GOT pointer value needed for
3831 PLT call stubs. */
3832 asection *s;
87d72d41 3833 Elf_Internal_Sym *isym;
9edfd1af 3834
87d72d41
AM
3835 isym = bfd_sym_from_r_symndx (&htab->sym_cache,
3836 abfd, r_symndx);
3837 if (isym == NULL)
3838 return FALSE;
3839
3840 s = bfd_section_from_elf_index (abfd, isym->st_shndx);
9edfd1af 3841 if (s == got2)
016687f8
AM
3842 {
3843 htab->plt_type = PLT_OLD;
3844 htab->old_bfd = abfd;
3845 }
9edfd1af 3846 }
7123df0e 3847 if (h == NULL || h == htab->elf.hgot)
fd38b44c 3848 break;
625af618
AM
3849 /* fall through */
3850
3851 case R_PPC_ADDR32:
3852 case R_PPC_ADDR16:
3853 case R_PPC_ADDR16_LO:
3854 case R_PPC_ADDR16_HI:
3855 case R_PPC_ADDR16_HA:
3856 case R_PPC_UADDR32:
3857 case R_PPC_UADDR16:
3858 if (h != NULL && !info->shared)
3859 {
3860 /* We may need a plt entry if the symbol turns out to be
3861 a function defined in a dynamic object. */
3ec01793 3862 if (!update_plt_info (abfd, &h->plt.plist, NULL, 0))
625af618
AM
3863 return FALSE;
3864
3865 /* We may need a copy reloc too. */
3866 h->non_got_ref = 1;
3867 h->pointer_equality_needed = 1;
3868 }
3869 goto dodyn;
9edfd1af 3870
25dbc73a
AM
3871 case R_PPC_REL24:
3872 case R_PPC_REL14:
3873 case R_PPC_REL14_BRTAKEN:
3874 case R_PPC_REL14_BRNTAKEN:
d7128ce4 3875 if (h == NULL)
25dbc73a 3876 break;
7123df0e 3877 if (h == htab->elf.hgot)
d7128ce4 3878 {
7123df0e 3879 if (htab->plt_type == PLT_UNSET)
016687f8
AM
3880 {
3881 htab->plt_type = PLT_OLD;
3882 htab->old_bfd = abfd;
3883 }
d7128ce4
AM
3884 break;
3885 }
25dbc73a 3886 /* fall through */
ee05f2fe 3887
25dbc73a 3888 case R_PPC_ADDR24:
25dbc73a
AM
3889 case R_PPC_ADDR14:
3890 case R_PPC_ADDR14_BRTAKEN:
3891 case R_PPC_ADDR14_BRNTAKEN:
25dbc73a
AM
3892 if (h != NULL && !info->shared)
3893 {
3894 /* We may need a plt entry if the symbol turns out to be
3895 a function defined in a dynamic object. */
e054468f 3896 h->needs_plt = 1;
de972ffa 3897 if (!update_plt_info (abfd, &h->plt.plist, NULL, 0))
a6aa5195 3898 return FALSE;
625af618 3899 break;
25dbc73a 3900 }
7619e7c7 3901
25dbc73a
AM
3902 dodyn:
3903 /* If we are creating a shared library, and this is a reloc
3904 against a global symbol, or a non PC relative reloc
3905 against a local symbol, then we need to copy the reloc
3906 into the shared library. However, if we are linking with
3907 -Bsymbolic, we do not need to copy a reloc against a
3908 global symbol which is defined in an object we are
3909 including in the link (i.e., DEF_REGULAR is set). At
3910 this point we have not seen all the input files, so it is
3911 possible that DEF_REGULAR is not set now but will be set
3912 later (it is never cleared). In case of a weak definition,
3913 DEF_REGULAR may be cleared later by a strong definition in
3914 a shared library. We account for that possibility below by
3915 storing information in the dyn_relocs field of the hash
3916 table entry. A similar situation occurs when creating
3917 shared libraries and symbol visibility changes render the
3918 symbol local.
7619e7c7 3919
25dbc73a
AM
3920 If on the other hand, we are creating an executable, we
3921 may need to keep relocations for symbols satisfied by a
3922 dynamic library if we manage to avoid copy relocs for the
3923 symbol. */
3924 if ((info->shared
1d483afe 3925 && (must_be_dyn_reloc (info, r_type)
25dbc73a
AM
3926 || (h != NULL
3927 && (! info->symbolic
3928 || h->root.type == bfd_link_hash_defweak
3929 || !h->def_regular))))
3930 || (ELIMINATE_COPY_RELOCS
3931 && !info->shared
25dbc73a
AM
3932 && h != NULL
3933 && (h->root.type == bfd_link_hash_defweak
de972ffa 3934 || !h->def_regular)))
25dbc73a
AM
3935 {
3936 struct ppc_elf_dyn_relocs *p;
91d6fa6a 3937 struct ppc_elf_dyn_relocs **rel_head;
7619e7c7 3938
25dbc73a
AM
3939#ifdef DEBUG
3940 fprintf (stderr,
3941 "ppc_elf_check_relocs needs to "
3942 "create relocation for %s\n",
3943 (h && h->root.root.string
3944 ? h->root.root.string : "<unknown>"));
3945#endif
3946 if (sreloc == NULL)
3947 {
c9a2f333
AM
3948 if (htab->elf.dynobj == NULL)
3949 htab->elf.dynobj = abfd;
83bac4b0
NC
3950
3951 sreloc = _bfd_elf_make_dynamic_reloc_section
3952 (sec, htab->elf.dynobj, 2, abfd, /*rela?*/ TRUE);
3953
25dbc73a 3954 if (sreloc == NULL)
83bac4b0 3955 return FALSE;
25dbc73a 3956 }
7619e7c7 3957
25dbc73a
AM
3958 /* If this is a global symbol, we count the number of
3959 relocations we need for this symbol. */
3960 if (h != NULL)
3961 {
91d6fa6a 3962 rel_head = &ppc_elf_hash_entry (h)->dyn_relocs;
25dbc73a
AM
3963 }
3964 else
3965 {
3966 /* Track dynamic relocs needed for local syms too.
3967 We really need local syms available to do this
3968 easily. Oh well. */
25dbc73a 3969 asection *s;
6edfbbad 3970 void *vpp;
87d72d41 3971 Elf_Internal_Sym *isym;
6edfbbad 3972
87d72d41
AM
3973 isym = bfd_sym_from_r_symndx (&htab->sym_cache,
3974 abfd, r_symndx);
3975 if (isym == NULL)
25dbc73a 3976 return FALSE;
7fce784e 3977
87d72d41
AM
3978 s = bfd_section_from_elf_index (abfd, isym->st_shndx);
3979 if (s == NULL)
3980 s = sec;
3981
6edfbbad 3982 vpp = &elf_section_data (s)->local_dynrel;
91d6fa6a 3983 rel_head = (struct ppc_elf_dyn_relocs **) vpp;
25dbc73a 3984 }
7fce784e 3985
91d6fa6a 3986 p = *rel_head;
25dbc73a
AM
3987 if (p == NULL || p->sec != sec)
3988 {
3989 p = bfd_alloc (htab->elf.dynobj, sizeof *p);
3990 if (p == NULL)
3991 return FALSE;
91d6fa6a
NC
3992 p->next = *rel_head;
3993 *rel_head = p;
25dbc73a
AM
3994 p->sec = sec;
3995 p->count = 0;
3996 p->pc_count = 0;
3997 }
3998
3999 p->count += 1;
1d483afe 4000 if (!must_be_dyn_reloc (info, r_type))
25dbc73a 4001 p->pc_count += 1;
7619e7c7 4002 }
25dbc73a
AM
4003
4004 break;
7619e7c7
AM
4005 }
4006 }
ee05f2fe 4007
25dbc73a
AM
4008 return TRUE;
4009}
4010\f
34c8bcba
JM
4011
4012/* Merge object attributes from IBFD into OBFD. Raise an error if
4013 there are conflicting attributes. */
4014static bfd_boolean
4015ppc_elf_merge_obj_attributes (bfd *ibfd, bfd *obfd)
4016{
c6e65352
DJ
4017 obj_attribute *in_attr, *in_attrs;
4018 obj_attribute *out_attr, *out_attrs;
34c8bcba
JM
4019
4020 if (!elf_known_obj_attributes_proc (obfd)[0].i)
4021 {
4022 /* This is the first object. Copy the attributes. */
4023 _bfd_elf_copy_obj_attributes (ibfd, obfd);
4024
4025 /* Use the Tag_null value to indicate the attributes have been
4026 initialized. */
4027 elf_known_obj_attributes_proc (obfd)[0].i = 1;
4028
4029 return TRUE;
4030 }
4031
c6e65352
DJ
4032 in_attrs = elf_known_obj_attributes (ibfd)[OBJ_ATTR_GNU];
4033 out_attrs = elf_known_obj_attributes (obfd)[OBJ_ATTR_GNU];
4034
34c8bcba
JM
4035 /* Check for conflicting Tag_GNU_Power_ABI_FP attributes and merge
4036 non-conflicting ones. */
c6e65352
DJ
4037 in_attr = &in_attrs[Tag_GNU_Power_ABI_FP];
4038 out_attr = &out_attrs[Tag_GNU_Power_ABI_FP];
4039 if (in_attr->i != out_attr->i)
34c8bcba 4040 {
c6e65352
DJ
4041 out_attr->type = 1;
4042 if (out_attr->i == 0)
4043 out_attr->i = in_attr->i;
4044 else if (in_attr->i == 0)
34c8bcba 4045 ;
c6e65352 4046 else if (out_attr->i == 1 && in_attr->i == 2)
34c8bcba
JM
4047 _bfd_error_handler
4048 (_("Warning: %B uses hard float, %B uses soft float"), obfd, ibfd);
3c7b9897
AM
4049 else if (out_attr->i == 1 && in_attr->i == 3)
4050 _bfd_error_handler
5b914448 4051 (_("Warning: %B uses double-precision hard float, %B uses single-precision hard float"),
3c7b9897
AM
4052 obfd, ibfd);
4053 else if (out_attr->i == 3 && in_attr->i == 1)
4054 _bfd_error_handler
5b914448 4055 (_("Warning: %B uses double-precision hard float, %B uses single-precision hard float"),
3c7b9897
AM
4056 ibfd, obfd);
4057 else if (out_attr->i == 3 && in_attr->i == 2)
4058 _bfd_error_handler
5b914448 4059 (_("Warning: %B uses soft float, %B uses single-precision hard float"),
3c7b9897
AM
4060 ibfd, obfd);
4061 else if (out_attr->i == 2 && (in_attr->i == 1 || in_attr->i == 3))
34c8bcba
JM
4062 _bfd_error_handler
4063 (_("Warning: %B uses hard float, %B uses soft float"), ibfd, obfd);
3c7b9897 4064 else if (in_attr->i > 3)
34c8bcba
JM
4065 _bfd_error_handler
4066 (_("Warning: %B uses unknown floating point ABI %d"), ibfd,
c6e65352 4067 in_attr->i);
34c8bcba
JM
4068 else
4069 _bfd_error_handler
4070 (_("Warning: %B uses unknown floating point ABI %d"), obfd,
c6e65352
DJ
4071 out_attr->i);
4072 }
4073
4074 /* Check for conflicting Tag_GNU_Power_ABI_Vector attributes and
4075 merge non-conflicting ones. */
4076 in_attr = &in_attrs[Tag_GNU_Power_ABI_Vector];
4077 out_attr = &out_attrs[Tag_GNU_Power_ABI_Vector];
4078 if (in_attr->i != out_attr->i)
4079 {
4080 const char *in_abi = NULL, *out_abi = NULL;
4081
4082 switch (in_attr->i)
4083 {
4084 case 1: in_abi = "generic"; break;
4085 case 2: in_abi = "AltiVec"; break;
4086 case 3: in_abi = "SPE"; break;
4087 }
4088
4089 switch (out_attr->i)
4090 {
4091 case 1: out_abi = "generic"; break;
4092 case 2: out_abi = "AltiVec"; break;
4093 case 3: out_abi = "SPE"; break;
4094 }
4095
4096 out_attr->type = 1;
4097 if (out_attr->i == 0)
4098 out_attr->i = in_attr->i;
4099 else if (in_attr->i == 0)
4100 ;
4101 /* For now, allow generic to transition to AltiVec or SPE
4102 without a warning. If GCC marked files with their stack
4103 alignment and used don't-care markings for files which are
4104 not affected by the vector ABI, we could warn about this
4105 case too. */
4106 else if (out_attr->i == 1)
4107 out_attr->i = in_attr->i;
4108 else if (in_attr->i == 1)
4109 ;
4110 else if (in_abi == NULL)
4111 _bfd_error_handler
4112 (_("Warning: %B uses unknown vector ABI %d"), ibfd,
4113 in_attr->i);
4114 else if (out_abi == NULL)
4115 _bfd_error_handler
4116 (_("Warning: %B uses unknown vector ABI %d"), obfd,
4117 in_attr->i);
4118 else
4119 _bfd_error_handler
4120 (_("Warning: %B uses vector ABI \"%s\", %B uses \"%s\""),
4121 ibfd, obfd, in_abi, out_abi);
34c8bcba
JM
4122 }
4123
f82e0623
NF
4124 /* Check for conflicting Tag_GNU_Power_ABI_Struct_Return attributes
4125 and merge non-conflicting ones. */
4126 in_attr = &in_attrs[Tag_GNU_Power_ABI_Struct_Return];
4127 out_attr = &out_attrs[Tag_GNU_Power_ABI_Struct_Return];
4128 if (in_attr->i != out_attr->i)
4129 {
4130 out_attr->type = 1;
4131 if (out_attr->i == 0)
4132 out_attr->i = in_attr->i;
4133 else if (in_attr->i == 0)
4134 ;
4135 else if (out_attr->i == 1 && in_attr->i == 2)
4136 _bfd_error_handler
4137 (_("Warning: %B uses r3/r4 for small structure returns, %B uses memory"), obfd, ibfd);
4138 else if (out_attr->i == 2 && in_attr->i == 1)
4139 _bfd_error_handler
4140 (_("Warning: %B uses r3/r4 for small structure returns, %B uses memory"), ibfd, obfd);
4141 else if (in_attr->i > 2)
4142 _bfd_error_handler
4143 (_("Warning: %B uses unknown small structure return convention %d"), ibfd,
4144 in_attr->i);
4145 else
4146 _bfd_error_handler
4147 (_("Warning: %B uses unknown small structure return convention %d"), obfd,
4148 out_attr->i);
4149 }
4150
34c8bcba
JM
4151 /* Merge Tag_compatibility attributes and any common GNU ones. */
4152 _bfd_elf_merge_object_attributes (ibfd, obfd);
4153
4154 return TRUE;
4155}
4156
8853c3d3
AM
4157/* Merge backend specific data from an object file to the output
4158 object file when linking. */
4159
4160static bfd_boolean
4161ppc_elf_merge_private_bfd_data (bfd *ibfd, bfd *obfd)
4162{
4163 flagword old_flags;
4164 flagword new_flags;
4165 bfd_boolean error;
4166
0c8d6e5c 4167 if (!is_ppc_elf (ibfd) || !is_ppc_elf (obfd))
8853c3d3
AM
4168 return TRUE;
4169
4170 /* Check if we have the same endianess. */
4171 if (! _bfd_generic_verify_endian_match (ibfd, obfd))
4172 return FALSE;
4173
34c8bcba
JM
4174 if (!ppc_elf_merge_obj_attributes (ibfd, obfd))
4175 return FALSE;
4176
8853c3d3
AM
4177 new_flags = elf_elfheader (ibfd)->e_flags;
4178 old_flags = elf_elfheader (obfd)->e_flags;
4179 if (!elf_flags_init (obfd))
4180 {
4181 /* First call, no flags set. */
4182 elf_flags_init (obfd) = TRUE;
4183 elf_elfheader (obfd)->e_flags = new_flags;
4184 }
4185
4186 /* Compatible flags are ok. */
4187 else if (new_flags == old_flags)
4188 ;
4189
4190 /* Incompatible flags. */
4191 else
4192 {
4193 /* Warn about -mrelocatable mismatch. Allow -mrelocatable-lib
4194 to be linked with either. */
4195 error = FALSE;
4196 if ((new_flags & EF_PPC_RELOCATABLE) != 0
4197 && (old_flags & (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB)) == 0)
4198 {
4199 error = TRUE;
4200 (*_bfd_error_handler)
4201 (_("%B: compiled with -mrelocatable and linked with "
4202 "modules compiled normally"), ibfd);
4203 }
4204 else if ((new_flags & (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB)) == 0
4205 && (old_flags & EF_PPC_RELOCATABLE) != 0)
4206 {
4207 error = TRUE;
4208 (*_bfd_error_handler)
4209 (_("%B: compiled normally and linked with "
4210 "modules compiled with -mrelocatable"), ibfd);
4211 }
4212
4213 /* The output is -mrelocatable-lib iff both the input files are. */
4214 if (! (new_flags & EF_PPC_RELOCATABLE_LIB))
4215 elf_elfheader (obfd)->e_flags &= ~EF_PPC_RELOCATABLE_LIB;
4216
4217 /* The output is -mrelocatable iff it can't be -mrelocatable-lib,
4218 but each input file is either -mrelocatable or -mrelocatable-lib. */
4219 if (! (elf_elfheader (obfd)->e_flags & EF_PPC_RELOCATABLE_LIB)
4220 && (new_flags & (EF_PPC_RELOCATABLE_LIB | EF_PPC_RELOCATABLE))
4221 && (old_flags & (EF_PPC_RELOCATABLE_LIB | EF_PPC_RELOCATABLE)))
4222 elf_elfheader (obfd)->e_flags |= EF_PPC_RELOCATABLE;
4223
4224 /* Do not warn about eabi vs. V.4 mismatch, just or in the bit if
4225 any module uses it. */
4226 elf_elfheader (obfd)->e_flags |= (new_flags & EF_PPC_EMB);
4227
4228 new_flags &= ~(EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB | EF_PPC_EMB);
4229 old_flags &= ~(EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB | EF_PPC_EMB);
4230
4231 /* Warn about any other mismatches. */
4232 if (new_flags != old_flags)
4233 {
4234 error = TRUE;
4235 (*_bfd_error_handler)
4236 (_("%B: uses different e_flags (0x%lx) fields "
4237 "than previous modules (0x%lx)"),
4238 ibfd, (long) new_flags, (long) old_flags);
4239 }
4240
4241 if (error)
4242 {
4243 bfd_set_error (bfd_error_bad_value);
4244 return FALSE;
4245 }
4246 }
4247
4248 return TRUE;
4249}
4250\f
d7128ce4
AM
4251/* Choose which PLT scheme to use, and set .plt flags appropriately.
4252 Returns -1 on error, 0 for old PLT, 1 for new PLT. */
4253int
4254ppc_elf_select_plt_layout (bfd *output_bfd ATTRIBUTE_UNUSED,
4255 struct bfd_link_info *info,
016687f8 4256 enum ppc_elf_plt_type plt_style,
0ba07910 4257 int emit_stub_syms)
d7128ce4
AM
4258{
4259 struct ppc_elf_link_hash_table *htab;
9d8504b1 4260 flagword flags;
d7128ce4
AM
4261
4262 htab = ppc_elf_hash_table (info);
4a3dc543 4263
a7f2871e
AM
4264 htab->emit_stub_syms = emit_stub_syms;
4265
4a3dc543 4266 if (htab->plt_type == PLT_UNSET)
016687f8
AM
4267 {
4268 if (plt_style == PLT_OLD)
4269 htab->plt_type = PLT_OLD;
4270 else
4271 {
4272 bfd *ibfd;
4273 enum ppc_elf_plt_type plt_type = plt_style;
4274
4275 /* Look through the reloc flags left by ppc_elf_check_relocs.
4276 Use the old style bss plt if a file makes plt calls
4277 without using the new relocs, and if ld isn't given
4278 --secure-plt and we never see REL16 relocs. */
4279 if (plt_type == PLT_UNSET)
4280 plt_type = PLT_OLD;
60b31e8d 4281 for (ibfd = info->input_bfds; ibfd; ibfd = ibfd->link_next)
0c8d6e5c 4282 if (is_ppc_elf (ibfd))
016687f8
AM
4283 {
4284 if (ppc_elf_tdata (ibfd)->has_rel16)
4285 plt_type = PLT_NEW;
4286 else if (ppc_elf_tdata (ibfd)->makes_plt_call)
4287 {
4288 plt_type = PLT_OLD;
4289 htab->old_bfd = ibfd;
4290 break;
4291 }
4292 }
4293 htab->plt_type = plt_type;
4294 }
4295 }
4296 if (htab->plt_type == PLT_OLD && plt_style == PLT_NEW)
4297 info->callbacks->info (_("Using bss-plt due to %B"), htab->old_bfd);
d7128ce4 4298
4a3dc543 4299 BFD_ASSERT (htab->plt_type != PLT_VXWORKS);
9d8504b1 4300
4a3dc543 4301 if (htab->plt_type == PLT_NEW)
9d8504b1
PB
4302 {
4303 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS
4304 | SEC_IN_MEMORY | SEC_LINKER_CREATED);
86b9da88
AM
4305
4306 /* The new PLT is a loaded section. */
4307 if (htab->plt != NULL
4308 && !bfd_set_section_flags (htab->elf.dynobj, htab->plt, flags))
4309 return -1;
4310
4311 /* The new GOT is not executable. */
4312 if (htab->got != NULL
4313 && !bfd_set_section_flags (htab->elf.dynobj, htab->got, flags))
4314 return -1;
d7128ce4
AM
4315 }
4316 else
4317 {
4318 /* Stop an unused .glink section from affecting .text alignment. */
86b9da88
AM
4319 if (htab->glink != NULL
4320 && !bfd_set_section_alignment (htab->elf.dynobj, htab->glink, 0))
4321 return -1;
d7128ce4 4322 }
4a3dc543 4323 return htab->plt_type == PLT_NEW;
d7128ce4
AM
4324}
4325\f
25dbc73a
AM
4326/* Return the section that should be marked against GC for a given
4327 relocation. */
586119b3 4328
25dbc73a
AM
4329static asection *
4330ppc_elf_gc_mark_hook (asection *sec,
07adf181 4331 struct bfd_link_info *info,
25dbc73a
AM
4332 Elf_Internal_Rela *rel,
4333 struct elf_link_hash_entry *h,
4334 Elf_Internal_Sym *sym)
4335{
4336 if (h != NULL)
07adf181
AM
4337 switch (ELF32_R_TYPE (rel->r_info))
4338 {
4339 case R_PPC_GNU_VTINHERIT:
4340 case R_PPC_GNU_VTENTRY:
4341 return NULL;
4342 }
4343
4344 return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
25dbc73a 4345}
a876ecf9 4346
25dbc73a
AM
4347/* Update the got, plt and dynamic reloc reference counts for the
4348 section being removed. */
4349
4350static bfd_boolean
4351ppc_elf_gc_sweep_hook (bfd *abfd,
4352 struct bfd_link_info *info,
4353 asection *sec,
4354 const Elf_Internal_Rela *relocs)
4355{
4356 struct ppc_elf_link_hash_table *htab;
4357 Elf_Internal_Shdr *symtab_hdr;
4358 struct elf_link_hash_entry **sym_hashes;
4359 bfd_signed_vma *local_got_refcounts;
4360 const Elf_Internal_Rela *rel, *relend;
a6aa5195 4361 asection *got2;
25dbc73a 4362
7dda2462
TG
4363 if (info->relocatable)
4364 return TRUE;
4365
c87b5a93
AM
4366 if ((sec->flags & SEC_ALLOC) == 0)
4367 return TRUE;
4368
25dbc73a
AM
4369 elf_section_data (sec)->local_dynrel = NULL;
4370
4371 htab = ppc_elf_hash_table (info);
0ffa91dd 4372 symtab_hdr = &elf_symtab_hdr (abfd);
25dbc73a
AM
4373 sym_hashes = elf_sym_hashes (abfd);
4374 local_got_refcounts = elf_local_got_refcounts (abfd);
a6aa5195 4375 got2 = bfd_get_section_by_name (abfd, ".got2");
25dbc73a
AM
4376
4377 relend = relocs + sec->reloc_count;
4378 for (rel = relocs; rel < relend; rel++)
4379 {
4380 unsigned long r_symndx;
4381 enum elf_ppc_reloc_type r_type;
4382 struct elf_link_hash_entry *h = NULL;
4383
4384 r_symndx = ELF32_R_SYM (rel->r_info);
4385 if (r_symndx >= symtab_hdr->sh_info)
a876ecf9 4386 {
25dbc73a
AM
4387 struct ppc_elf_dyn_relocs **pp, *p;
4388 struct ppc_elf_link_hash_entry *eh;
4389
4390 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
4391 while (h->root.type == bfd_link_hash_indirect
4392 || h->root.type == bfd_link_hash_warning)
4393 h = (struct elf_link_hash_entry *) h->root.u.i.link;
4394 eh = (struct ppc_elf_link_hash_entry *) h;
4395
4396 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next)
4397 if (p->sec == sec)
4398 {
4399 /* Everything must go for SEC. */
4400 *pp = p->next;
4401 break;
4402 }
a876ecf9 4403 }
ee05f2fe 4404
25dbc73a 4405 r_type = ELF32_R_TYPE (rel->r_info);
de972ffa
AM
4406 if (!htab->is_vxworks
4407 && h == NULL
4408 && local_got_refcounts != NULL
4409 && (!info->shared
4410 || is_branch_reloc (r_type)))
e054468f 4411 {
de972ffa
AM
4412 struct plt_entry **local_plt = (struct plt_entry **)
4413 (local_got_refcounts + symtab_hdr->sh_info);
4414 char *local_got_tls_masks = (char *)
4415 (local_plt + symtab_hdr->sh_info);
4416 if ((local_got_tls_masks[r_symndx] & PLT_IFUNC) != 0)
e054468f 4417 {
de972ffa 4418 struct plt_entry **ifunc = local_plt + r_symndx;
a877a2b6
AM
4419 bfd_vma addend = 0;
4420 struct plt_entry *ent;
4421
4422 if (r_type == R_PPC_PLTREL24 && info->shared)
4423 addend = rel->r_addend;
4424 ent = find_plt_ent (ifunc, got2, addend);
e054468f
AM
4425 if (ent->plt.refcount > 0)
4426 ent->plt.refcount -= 1;
4427 continue;
4428 }
4429 }
4430
25dbc73a 4431 switch (r_type)
ee05f2fe 4432 {
25dbc73a
AM
4433 case R_PPC_GOT_TLSLD16:
4434 case R_PPC_GOT_TLSLD16_LO:
4435 case R_PPC_GOT_TLSLD16_HI:
4436 case R_PPC_GOT_TLSLD16_HA:
25dbc73a
AM
4437 case R_PPC_GOT_TLSGD16:
4438 case R_PPC_GOT_TLSGD16_LO:
4439 case R_PPC_GOT_TLSGD16_HI:
4440 case R_PPC_GOT_TLSGD16_HA:
4441 case R_PPC_GOT_TPREL16:
4442 case R_PPC_GOT_TPREL16_LO:
4443 case R_PPC_GOT_TPREL16_HI:
4444 case R_PPC_GOT_TPREL16_HA:
4445 case R_PPC_GOT_DTPREL16:
4446 case R_PPC_GOT_DTPREL16_LO:
4447 case R_PPC_GOT_DTPREL16_HI:
4448 case R_PPC_GOT_DTPREL16_HA:
4449 case R_PPC_GOT16:
4450 case R_PPC_GOT16_LO:
4451 case R_PPC_GOT16_HI:
4452 case R_PPC_GOT16_HA:
4453 if (h != NULL)
ee05f2fe 4454 {
25dbc73a
AM
4455 if (h->got.refcount > 0)
4456 h->got.refcount--;
91e21fb7
AM
4457 if (!info->shared)
4458 {
4459 struct plt_entry *ent;
4460
4461 ent = find_plt_ent (&h->plt.plist, NULL, 0);
32af9f6e 4462 if (ent != NULL && ent->plt.refcount > 0)
91e21fb7
AM
4463 ent->plt.refcount -= 1;
4464 }
ee05f2fe 4465 }
25dbc73a
AM
4466 else if (local_got_refcounts != NULL)
4467 {
4468 if (local_got_refcounts[r_symndx] > 0)
4469 local_got_refcounts[r_symndx]--;
4470 }
4471 break;
ee05f2fe 4472
25dbc73a
AM
4473 case R_PPC_REL24:
4474 case R_PPC_REL14:
4475 case R_PPC_REL14_BRTAKEN:
4476 case R_PPC_REL14_BRNTAKEN:
4477 case R_PPC_REL32:
3b36f7e6 4478 if (h == NULL || h == htab->elf.hgot)
25dbc73a
AM
4479 break;
4480 /* Fall thru */
ee05f2fe 4481
25dbc73a
AM
4482 case R_PPC_ADDR32:
4483 case R_PPC_ADDR24:
4484 case R_PPC_ADDR16:
4485 case R_PPC_ADDR16_LO:
4486 case R_PPC_ADDR16_HI:
4487 case R_PPC_ADDR16_HA:
4488 case R_PPC_ADDR14:
4489 case R_PPC_ADDR14_BRTAKEN:
4490 case R_PPC_ADDR14_BRNTAKEN:
4491 case R_PPC_UADDR32:
4492 case R_PPC_UADDR16:
87538722
AM
4493 if (info->shared)
4494 break;
4495
25dbc73a
AM
4496 case R_PPC_PLT32:
4497 case R_PPC_PLTREL24:
87538722 4498 case R_PPC_PLTREL32:
25dbc73a
AM
4499 case R_PPC_PLT16_LO:
4500 case R_PPC_PLT16_HI:
4501 case R_PPC_PLT16_HA:
4502 if (h != NULL)
4503 {
a877a2b6
AM
4504 bfd_vma addend = 0;
4505 struct plt_entry *ent;
4506
4507 if (r_type == R_PPC_PLTREL24 && info->shared)
4508 addend = rel->r_addend;
4509 ent = find_plt_ent (&h->plt.plist, got2, addend);
32af9f6e 4510 if (ent != NULL && ent->plt.refcount > 0)
a6aa5195 4511 ent->plt.refcount -= 1;
25dbc73a
AM
4512 }
4513 break;
ee05f2fe 4514
25dbc73a
AM
4515 default:
4516 break;
4517 }
7fce784e 4518 }
7fce784e
AS
4519 return TRUE;
4520}
25dbc73a 4521\f
3a71aa26
AM
4522/* Set plt output section type, htab->tls_get_addr, and call the
4523 generic ELF tls_setup function. */
7fce784e 4524
25dbc73a 4525asection *
a7f2871e
AM
4526ppc_elf_tls_setup (bfd *obfd,
4527 struct bfd_link_info *info,
4528 int no_tls_get_addr_opt)
7fce784e 4529{
25dbc73a 4530 struct ppc_elf_link_hash_table *htab;
7fce784e 4531
25dbc73a 4532 htab = ppc_elf_hash_table (info);
a7f2871e
AM
4533 htab->tls_get_addr = elf_link_hash_lookup (&htab->elf, "__tls_get_addr",
4534 FALSE, FALSE, TRUE);
4535 if (!no_tls_get_addr_opt)
4536 {
4537 struct elf_link_hash_entry *opt, *tga;
4538 opt = elf_link_hash_lookup (&htab->elf, "__tls_get_addr_opt",
4539 FALSE, FALSE, TRUE);
4540 if (opt != NULL
4541 && (opt->root.type == bfd_link_hash_defined
4542 || opt->root.type == bfd_link_hash_defweak))
4543 {
4544 /* If glibc supports an optimized __tls_get_addr call stub,
4545 signalled by the presence of __tls_get_addr_opt, and we'll
4546 be calling __tls_get_addr via a plt call stub, then
4547 make __tls_get_addr point to __tls_get_addr_opt. */
4548 tga = htab->tls_get_addr;
4549 if (htab->elf.dynamic_sections_created
4550 && tga != NULL
4551 && (tga->type == STT_FUNC
4552 || tga->needs_plt)
4553 && !(SYMBOL_CALLS_LOCAL (info, tga)
4554 || (ELF_ST_VISIBILITY (tga->other) != STV_DEFAULT
4555 && tga->root.type == bfd_link_hash_undefweak)))
4556 {
4557 struct plt_entry *ent;
32af9f6e
AM
4558 for (ent = tga->plt.plist; ent != NULL; ent = ent->next)
4559 if (ent->plt.refcount > 0)
4560 break;
4561 if (ent != NULL)
a7f2871e
AM
4562 {
4563 tga->root.type = bfd_link_hash_indirect;
4564 tga->root.u.i.link = &opt->root;
4565 ppc_elf_copy_indirect_symbol (info, opt, tga);
4566 if (opt->dynindx != -1)
4567 {
4568 /* Use __tls_get_addr_opt in dynamic relocations. */
4569 opt->dynindx = -1;
4570 _bfd_elf_strtab_delref (elf_hash_table (info)->dynstr,
4571 opt->dynstr_index);
4572 if (!bfd_elf_link_record_dynamic_symbol (info, opt))
4573 return FALSE;
4574 }
4575 htab->tls_get_addr = opt;
4576 }
4577 }
4578 }
4579 else
4580 no_tls_get_addr_opt = TRUE;
4581 }
4582 htab->no_tls_get_addr_opt = no_tls_get_addr_opt;
4a3dc543 4583 if (htab->plt_type == PLT_NEW
d7128ce4
AM
4584 && htab->plt != NULL
4585 && htab->plt->output_section != NULL)
4586 {
4587 elf_section_type (htab->plt->output_section) = SHT_PROGBITS;
4588 elf_section_flags (htab->plt->output_section) = SHF_ALLOC + SHF_WRITE;
4589 }
4590
25dbc73a 4591 return _bfd_elf_tls_setup (obfd, info);
7fce784e
AS
4592}
4593
3a71aa26
AM
4594/* Return TRUE iff REL is a branch reloc with a global symbol matching
4595 HASH. */
4596
4597static bfd_boolean
4598branch_reloc_hash_match (const bfd *ibfd,
4599 const Elf_Internal_Rela *rel,
4600 const struct elf_link_hash_entry *hash)
4601{
4602 Elf_Internal_Shdr *symtab_hdr = &elf_symtab_hdr (ibfd);
4603 enum elf_ppc_reloc_type r_type = ELF32_R_TYPE (rel->r_info);
4604 unsigned int r_symndx = ELF32_R_SYM (rel->r_info);
4605
e054468f 4606 if (r_symndx >= symtab_hdr->sh_info && is_branch_reloc (r_type))
3a71aa26
AM
4607 {
4608 struct elf_link_hash_entry **sym_hashes = elf_sym_hashes (ibfd);
4609 struct elf_link_hash_entry *h;
4610
4611 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
4612 while (h->root.type == bfd_link_hash_indirect
4613 || h->root.type == bfd_link_hash_warning)
4614 h = (struct elf_link_hash_entry *) h->root.u.i.link;
4615 if (h == hash)
4616 return TRUE;
4617 }
4618 return FALSE;
4619}
4620
25dbc73a
AM
4621/* Run through all the TLS relocs looking for optimization
4622 opportunities. */
252b5132 4623
25dbc73a
AM
4624bfd_boolean
4625ppc_elf_tls_optimize (bfd *obfd ATTRIBUTE_UNUSED,
4626 struct bfd_link_info *info)
252b5132 4627{
7fce784e 4628 bfd *ibfd;
25dbc73a
AM
4629 asection *sec;
4630 struct ppc_elf_link_hash_table *htab;
b7fcf6f6 4631 int pass;
252b5132 4632
1d483afe 4633 if (info->relocatable || !info->executable)
25dbc73a 4634 return TRUE;
252b5132 4635
7619e7c7 4636 htab = ppc_elf_hash_table (info);
663a1470
AM
4637 if (htab == NULL)
4638 return FALSE;
4639
b7fcf6f6
AM
4640 /* Make two passes through the relocs. First time check that tls
4641 relocs involved in setting up a tls_get_addr call are indeed
663a1470
AM
4642 followed by such a call. If they are not, don't do any tls
4643 optimization. On the second pass twiddle tls_mask flags to
4644 notify relocate_section that optimization can be done, and
4645 adjust got and plt refcounts. */
b7fcf6f6
AM
4646 for (pass = 0; pass < 2; ++pass)
4647 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
4648 {
4649 Elf_Internal_Sym *locsyms = NULL;
0ffa91dd 4650 Elf_Internal_Shdr *symtab_hdr = &elf_symtab_hdr (ibfd);
32af9f6e 4651 asection *got2 = bfd_get_section_by_name (ibfd, ".got2");
7619e7c7 4652
b7fcf6f6
AM
4653 for (sec = ibfd->sections; sec != NULL; sec = sec->next)
4654 if (sec->has_tls_reloc && !bfd_is_abs_section (sec->output_section))
4655 {
4656 Elf_Internal_Rela *relstart, *rel, *relend;
663a1470 4657 int expecting_tls_get_addr = 0;
252b5132 4658
b7fcf6f6
AM
4659 /* Read the relocations. */
4660 relstart = _bfd_elf_link_read_relocs (ibfd, sec, NULL, NULL,
4661 info->keep_memory);
4662 if (relstart == NULL)
4663 return FALSE;
7619e7c7 4664
b7fcf6f6
AM
4665 relend = relstart + sec->reloc_count;
4666 for (rel = relstart; rel < relend; rel++)
4667 {
4668 enum elf_ppc_reloc_type r_type;
4669 unsigned long r_symndx;
4670 struct elf_link_hash_entry *h = NULL;
4671 char *tls_mask;
4672 char tls_set, tls_clear;
4673 bfd_boolean is_local;
b7fcf6f6
AM
4674 bfd_signed_vma *got_count;
4675
4676 r_symndx = ELF32_R_SYM (rel->r_info);
4677 if (r_symndx >= symtab_hdr->sh_info)
4678 {
4679 struct elf_link_hash_entry **sym_hashes;
7fce784e 4680
b7fcf6f6
AM
4681 sym_hashes = elf_sym_hashes (ibfd);
4682 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
4683 while (h->root.type == bfd_link_hash_indirect
4684 || h->root.type == bfd_link_hash_warning)
4685 h = (struct elf_link_hash_entry *) h->root.u.i.link;
4686 }
7619e7c7 4687
b7fcf6f6
AM
4688 is_local = FALSE;
4689 if (h == NULL
4690 || !h->def_dynamic)
4691 is_local = TRUE;
7619e7c7 4692
b7fcf6f6 4693 r_type = ELF32_R_TYPE (rel->r_info);
663a1470
AM
4694 /* If this section has old-style __tls_get_addr calls
4695 without marker relocs, then check that each
4696 __tls_get_addr call reloc is preceded by a reloc
4697 that conceivably belongs to the __tls_get_addr arg
4698 setup insn. If we don't find matching arg setup
4699 relocs, don't do any tls optimization. */
4700 if (pass == 0
4701 && sec->has_tls_get_addr_call
4702 && h != NULL
4703 && h == htab->tls_get_addr
4704 && !expecting_tls_get_addr
4705 && is_branch_reloc (r_type))
4706 {
4707 info->callbacks->minfo ("%C __tls_get_addr lost arg, "
4708 "TLS optimization disabled\n",
4709 ibfd, sec, rel->r_offset);
4710 if (elf_section_data (sec)->relocs != relstart)
4711 free (relstart);
4712 return TRUE;
4713 }
4714
4715 expecting_tls_get_addr = 0;
b7fcf6f6
AM
4716 switch (r_type)
4717 {
4718 case R_PPC_GOT_TLSLD16:
4719 case R_PPC_GOT_TLSLD16_LO:
4720 expecting_tls_get_addr = 1;
4721 /* Fall thru */
4722
4723 case R_PPC_GOT_TLSLD16_HI:
4724 case R_PPC_GOT_TLSLD16_HA:
4725 /* These relocs should never be against a symbol
4726 defined in a shared lib. Leave them alone if
4727 that turns out to be the case. */
4728 if (!is_local)
4729 continue;
4730
4731 /* LD -> LE */
4732 tls_set = 0;
4733 tls_clear = TLS_LD;
4734 break;
4735
4736 case R_PPC_GOT_TLSGD16:
4737 case R_PPC_GOT_TLSGD16_LO:
4738 expecting_tls_get_addr = 1;
4739 /* Fall thru */
4740
4741 case R_PPC_GOT_TLSGD16_HI:
4742 case R_PPC_GOT_TLSGD16_HA:
4743 if (is_local)
4744 /* GD -> LE */
4745 tls_set = 0;
4746 else
4747 /* GD -> IE */
4748 tls_set = TLS_TLS | TLS_TPRELGD;
4749 tls_clear = TLS_GD;
4750 break;
4751
4752 case R_PPC_GOT_TPREL16:
4753 case R_PPC_GOT_TPREL16_LO:
4754 case R_PPC_GOT_TPREL16_HI:
4755 case R_PPC_GOT_TPREL16_HA:
4756 if (is_local)
4757 {
4758 /* IE -> LE */
4759 tls_set = 0;
4760 tls_clear = TLS_TPREL;
4761 break;
4762 }
4763 else
4764 continue;
4765
32af9f6e
AM
4766 case R_PPC_TLSGD:
4767 case R_PPC_TLSLD:
4768 expecting_tls_get_addr = 2;
4769 tls_set = 0;
4770 tls_clear = 0;
4771 break;
4772
b7fcf6f6 4773 default:
25dbc73a 4774 continue;
b7fcf6f6 4775 }
25dbc73a 4776
b7fcf6f6
AM
4777 if (pass == 0)
4778 {
727fc41e 4779 if (!expecting_tls_get_addr
32af9f6e
AM
4780 || (expecting_tls_get_addr == 1
4781 && !sec->has_tls_get_addr_call))
b7fcf6f6 4782 continue;
25dbc73a 4783
3a71aa26
AM
4784 if (rel + 1 < relend
4785 && branch_reloc_hash_match (ibfd, rel + 1,
4786 htab->tls_get_addr))
4787 continue;
25dbc73a 4788
b7fcf6f6
AM
4789 /* Uh oh, we didn't find the expected call. We
4790 could just mark this symbol to exclude it
4791 from tls optimization but it's safer to skip
663a1470
AM
4792 the entire optimization. */
4793 info->callbacks->minfo (_("%C arg lost __tls_get_addr, "
4794 "TLS optimization disabled\n"),
4795 ibfd, sec, rel->r_offset);
4796 if (elf_section_data (sec)->relocs != relstart)
4797 free (relstart);
4798 return TRUE;
b7fcf6f6 4799 }
25dbc73a 4800
32af9f6e
AM
4801 if (expecting_tls_get_addr)
4802 {
4803 struct plt_entry *ent;
4804 bfd_vma addend = 0;
4805
4806 if (info->shared
4807 && ELF32_R_TYPE (rel[1].r_info) == R_PPC_PLTREL24)
4808 addend = rel[1].r_addend;
4809 ent = find_plt_ent (&htab->tls_get_addr->plt.plist,
4810 got2, addend);
4811 if (ent != NULL && ent->plt.refcount > 0)
4812 ent->plt.refcount -= 1;
4813
4814 if (expecting_tls_get_addr == 2)
4815 continue;
4816 }
4817
b7fcf6f6
AM
4818 if (h != NULL)
4819 {
4820 tls_mask = &ppc_elf_hash_entry (h)->tls_mask;
4821 got_count = &h->got.refcount;
4822 }
4823 else
4824 {
b7fcf6f6 4825 bfd_signed_vma *lgot_refs;
e054468f 4826 struct plt_entry **local_plt;
b7fcf6f6 4827 char *lgot_masks;
25dbc73a 4828
b7fcf6f6
AM
4829 if (locsyms == NULL)
4830 {
4831 locsyms = (Elf_Internal_Sym *) symtab_hdr->contents;
4832 if (locsyms == NULL)
4833 locsyms = bfd_elf_get_elf_syms (ibfd, symtab_hdr,
4834 symtab_hdr->sh_info,
4835 0, NULL, NULL, NULL);
4836 if (locsyms == NULL)
4837 {
4838 if (elf_section_data (sec)->relocs != relstart)
4839 free (relstart);
4840 return FALSE;
4841 }
4842 }
b7fcf6f6
AM
4843 lgot_refs = elf_local_got_refcounts (ibfd);
4844 if (lgot_refs == NULL)
4845 abort ();
e054468f
AM
4846 local_plt = (struct plt_entry **)
4847 (lgot_refs + symtab_hdr->sh_info);
4848 lgot_masks = (char *) (local_plt + symtab_hdr->sh_info);
b7fcf6f6
AM
4849 tls_mask = &lgot_masks[r_symndx];
4850 got_count = &lgot_refs[r_symndx];
4851 }
25dbc73a 4852
b7fcf6f6
AM
4853 if (tls_set == 0)
4854 {
4855 /* We managed to get rid of a got entry. */
4856 if (*got_count > 0)
4857 *got_count -= 1;
4858 }
25dbc73a 4859
b7fcf6f6
AM
4860 *tls_mask |= tls_set;
4861 *tls_mask &= ~tls_clear;
4862 }
25dbc73a 4863
b7fcf6f6
AM
4864 if (elf_section_data (sec)->relocs != relstart)
4865 free (relstart);
4866 }
4867
4868 if (locsyms != NULL
4869 && (symtab_hdr->contents != (unsigned char *) locsyms))
4870 {
4871 if (!info->keep_memory)
4872 free (locsyms);
4873 else
4874 symtab_hdr->contents = (unsigned char *) locsyms;
4875 }
4876 }
25dbc73a
AM
4877 return TRUE;
4878}
4879\f
625af618
AM
4880/* Return true if we have dynamic relocs that apply to read-only sections. */
4881
4882static bfd_boolean
4883readonly_dynrelocs (struct elf_link_hash_entry *h)
4884{
4885 struct ppc_elf_dyn_relocs *p;
4886
4887 for (p = ppc_elf_hash_entry (h)->dyn_relocs; p != NULL; p = p->next)
4888 {
4889 asection *s = p->sec->output_section;
4890
4891 if (s != NULL
4892 && ((s->flags & (SEC_READONLY | SEC_ALLOC))
4893 == (SEC_READONLY | SEC_ALLOC)))
4894 return TRUE;
4895 }
4896 return FALSE;
4897}
4898
25dbc73a
AM
4899/* Adjust a symbol defined by a dynamic object and referenced by a
4900 regular object. The current definition is in some section of the
4901 dynamic object, but we're not including those sections. We have to
4902 change the definition to something the rest of the link can
4903 understand. */
7fce784e 4904
25dbc73a
AM
4905static bfd_boolean
4906ppc_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
4907 struct elf_link_hash_entry *h)
4908{
4909 struct ppc_elf_link_hash_table *htab;
4910 asection *s;
7fce784e 4911
25dbc73a
AM
4912#ifdef DEBUG
4913 fprintf (stderr, "ppc_elf_adjust_dynamic_symbol called for %s\n",
4914 h->root.root.string);
4915#endif
252b5132 4916
25dbc73a
AM
4917 /* Make sure we know what is going on here. */
4918 htab = ppc_elf_hash_table (info);
4919 BFD_ASSERT (htab->elf.dynobj != NULL
4920 && (h->needs_plt
91e21fb7 4921 || h->type == STT_GNU_IFUNC
25dbc73a
AM
4922 || h->u.weakdef != NULL
4923 || (h->def_dynamic
4924 && h->ref_regular
4925 && !h->def_regular)));
252b5132 4926
25dbc73a
AM
4927 /* Deal with function syms. */
4928 if (h->type == STT_FUNC
e054468f 4929 || h->type == STT_GNU_IFUNC
25dbc73a
AM
4930 || h->needs_plt)
4931 {
4932 /* Clear procedure linkage table information for any symbol that
4933 won't need a .plt entry. */
a6aa5195
AM
4934 struct plt_entry *ent;
4935 for (ent = h->plt.plist; ent != NULL; ent = ent->next)
4936 if (ent->plt.refcount > 0)
4937 break;
4938 if (ent == NULL
e054468f
AM
4939 || (h->type != STT_GNU_IFUNC
4940 && (SYMBOL_CALLS_LOCAL (info, h)
4941 || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
4942 && h->root.type == bfd_link_hash_undefweak))))
252b5132 4943 {
25dbc73a 4944 /* A PLT entry is not required/allowed when:
252b5132 4945
25dbc73a
AM
4946 1. We are not using ld.so; because then the PLT entry
4947 can't be set up, so we can't use one. In this case,
4948 ppc_elf_adjust_dynamic_symbol won't even be called.
252b5132 4949
25dbc73a
AM
4950 2. GC has rendered the entry unused.
4951
4952 3. We know for certain that a call to this symbol
4953 will go to this object, or will remain undefined. */
a6aa5195 4954 h->plt.plist = NULL;
25dbc73a
AM
4955 h->needs_plt = 0;
4956 }
625af618
AM
4957 else
4958 {
25f23106
AM
4959 /* After adjust_dynamic_symbol, non_got_ref set in the
4960 non-shared case means that we have allocated space in
4961 .dynbss for the symbol and thus dyn_relocs for this
4962 symbol should be discarded.
625af618
AM
4963 If we get here we know we are making a PLT entry for this
4964 symbol, and in an executable we'd normally resolve
4965 relocations against this symbol to the PLT entry. Allow
4966 dynamic relocs if the reference is weak, and the dynamic
4967 relocs will not cause text relocation. */
4968 if (!h->ref_regular_nonweak
4969 && h->non_got_ref
25f23106 4970 && h->type != STT_GNU_IFUNC
625af618
AM
4971 && !htab->is_vxworks
4972 && !ppc_elf_hash_entry (h)->has_sda_refs
4973 && !readonly_dynrelocs (h))
4974 h->non_got_ref = 0;
4975 }
25dbc73a 4976 return TRUE;
252b5132 4977 }
25dbc73a 4978 else
a6aa5195 4979 h->plt.plist = NULL;
252b5132 4980
25dbc73a
AM
4981 /* If this is a weak symbol, and there is a real definition, the
4982 processor independent code will have arranged for us to see the
4983 real definition first, and we can just use the same value. */
4984 if (h->u.weakdef != NULL)
252b5132 4985 {
25dbc73a
AM
4986 BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
4987 || h->u.weakdef->root.type == bfd_link_hash_defweak);
4988 h->root.u.def.section = h->u.weakdef->root.u.def.section;
4989 h->root.u.def.value = h->u.weakdef->root.u.def.value;
4990 if (ELIMINATE_COPY_RELOCS)
4991 h->non_got_ref = h->u.weakdef->non_got_ref;
4992 return TRUE;
4993 }
dc810e39 4994
25dbc73a
AM
4995 /* This is a reference to a symbol defined by a dynamic object which
4996 is not a function. */
252b5132 4997
25dbc73a
AM
4998 /* If we are creating a shared library, we must presume that the
4999 only references to the symbol are via the global offset table.
5000 For such cases we need not do anything here; the relocations will
5001 be handled correctly by relocate_section. */
5002 if (info->shared)
5003 return TRUE;
252b5132 5004
25dbc73a
AM
5005 /* If there are no references to this symbol that do not use the
5006 GOT, we don't need to generate a copy reloc. */
5007 if (!h->non_got_ref)
5008 return TRUE;
5009
cfd2c773
NS
5010 /* If we didn't find any dynamic relocs in read-only sections, then
5011 we'll be keeping the dynamic relocs and avoiding the copy reloc.
5012 We can't do this if there are any small data relocations. This
5013 doesn't work on VxWorks, where we can not have dynamic
5014 relocations (other than copy and jump slot relocations) in an
5015 executable. */
4dc4a9a5 5016 if (ELIMINATE_COPY_RELOCS
cfd2c773 5017 && !ppc_elf_hash_entry (h)->has_sda_refs
625af618
AM
5018 && !htab->is_vxworks
5019 && !h->def_regular
5020 && !readonly_dynrelocs (h))
25dbc73a 5021 {
625af618
AM
5022 h->non_got_ref = 0;
5023 return TRUE;
252b5132
RH
5024 }
5025
909272ee
AM
5026 if (h->size == 0)
5027 {
5028 (*_bfd_error_handler) (_("dynamic variable `%s' is zero size"),
5029 h->root.root.string);
5030 return TRUE;
5031 }
5032
25dbc73a
AM
5033 /* We must allocate the symbol in our .dynbss section, which will
5034 become part of the .bss section of the executable. There will be
5035 an entry for this symbol in the .dynsym section. The dynamic
5036 object will contain position independent code, so all references
5037 from the dynamic object to this symbol will go through the global
5038 offset table. The dynamic linker will use the .dynsym entry to
5039 determine the address it must put in the global offset table, so
5040 both the dynamic object and the regular object will refer to the
5041 same memory location for the variable.
5042
4dc4a9a5
DJ
5043 Of course, if the symbol is referenced using SDAREL relocs, we
5044 must instead allocate it in .sbss. */
25dbc73a 5045
4dc4a9a5 5046 if (ppc_elf_hash_entry (h)->has_sda_refs)
25dbc73a
AM
5047 s = htab->dynsbss;
5048 else
5049 s = htab->dynbss;
5050 BFD_ASSERT (s != NULL);
5051
5052 /* We must generate a R_PPC_COPY reloc to tell the dynamic linker to
5053 copy the initial value out of the dynamic object and into the
5054 runtime process image. We need to remember the offset into the
5055 .rela.bss section we are going to use. */
5056 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
5057 {
5058 asection *srel;
5059
4dc4a9a5 5060 if (ppc_elf_hash_entry (h)->has_sda_refs)
25dbc73a
AM
5061 srel = htab->relsbss;
5062 else
5063 srel = htab->relbss;
5064 BFD_ASSERT (srel != NULL);
5065 srel->size += sizeof (Elf32_External_Rela);
5066 h->needs_copy = 1;
5067 }
7619e7c7 5068
027297b7 5069 return _bfd_elf_adjust_dynamic_copy (h, s);
25dbc73a
AM
5070}
5071\f
ac39eb42
AM
5072/* Generate a symbol to mark plt call stubs. For non-PIC code the sym is
5073 xxxxxxxx.plt_call32.<callee> where xxxxxxxx is a hex number, usually 0,
5074 specifying the addend on the plt relocation. For -fpic code, the sym
5075 is xxxxxxxx.plt_pic32.<callee>, and for -fPIC
5076 xxxxxxxx.got2.plt_pic32.<callee>. */
0ba07910
AM
5077
5078static bfd_boolean
5079add_stub_sym (struct plt_entry *ent,
5080 struct elf_link_hash_entry *h,
ac39eb42 5081 struct bfd_link_info *info)
0ba07910
AM
5082{
5083 struct elf_link_hash_entry *sh;
5084 size_t len1, len2, len3;
5085 char *name;
ac39eb42
AM
5086 const char *stub;
5087 struct ppc_elf_link_hash_table *htab = ppc_elf_hash_table (info);
5088
a877a2b6 5089 if (info->shared)
ac39eb42
AM
5090 stub = ".plt_pic32.";
5091 else
5092 stub = ".plt_call32.";
0ba07910
AM
5093
5094 len1 = strlen (h->root.root.string);
ac39eb42 5095 len2 = strlen (stub);
0ba07910
AM
5096 len3 = 0;
5097 if (ent->sec)
5098 len3 = strlen (ent->sec->name);
ac39eb42 5099 name = bfd_malloc (len1 + len2 + len3 + 9);
0ba07910
AM
5100 if (name == NULL)
5101 return FALSE;
5102 sprintf (name, "%08x", (unsigned) ent->addend & 0xffffffff);
5103 if (ent->sec)
5104 memcpy (name + 8, ent->sec->name, len3);
ac39eb42
AM
5105 memcpy (name + 8 + len3, stub, len2);
5106 memcpy (name + 8 + len3 + len2, h->root.root.string, len1 + 1);
0ba07910
AM
5107 sh = elf_link_hash_lookup (&htab->elf, name, TRUE, FALSE, FALSE);
5108 if (sh == NULL)
5109 return FALSE;
5110 if (sh->root.type == bfd_link_hash_new)
5111 {
5112 sh->root.type = bfd_link_hash_defined;
5113 sh->root.u.def.section = htab->glink;
5114 sh->root.u.def.value = ent->glink_offset;
5115 sh->ref_regular = 1;
5116 sh->def_regular = 1;
5117 sh->ref_regular_nonweak = 1;
5118 sh->forced_local = 1;
5119 sh->non_elf = 0;
5120 }
5121 return TRUE;
5122}
5123
3b36f7e6
AM
5124/* Allocate NEED contiguous space in .got, and return the offset.
5125 Handles allocation of the got header when crossing 32k. */
5126
5127static bfd_vma
5128allocate_got (struct ppc_elf_link_hash_table *htab, unsigned int need)
5129{
5130 bfd_vma where;
4a3dc543 5131 unsigned int max_before_header;
3b36f7e6 5132
4a3dc543 5133 if (htab->plt_type == PLT_VXWORKS)
9d8504b1
PB
5134 {
5135 where = htab->got->size;
5136 htab->got->size += need;
5137 }
3b36f7e6
AM
5138 else
5139 {
4a3dc543
RS
5140 max_before_header = htab->plt_type == PLT_NEW ? 32768 : 32764;
5141 if (need <= htab->got_gap)
3b36f7e6 5142 {
4a3dc543
RS
5143 where = max_before_header - htab->got_gap;
5144 htab->got_gap -= need;
5145 }
5146 else
5147 {
5148 if (htab->got->size + need > max_before_header
5149 && htab->got->size <= max_before_header)
5150 {
5151 htab->got_gap = max_before_header - htab->got->size;
5152 htab->got->size = max_before_header + htab->got_header_size;
5153 }
5154 where = htab->got->size;
5155 htab->got->size += need;
3b36f7e6 5156 }
3b36f7e6
AM
5157 }
5158 return where;
5159}
5160
25dbc73a 5161/* Allocate space in associated reloc sections for dynamic relocs. */
252b5132 5162
b34976b6 5163static bfd_boolean
25dbc73a 5164allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
252b5132 5165{
25dbc73a
AM
5166 struct bfd_link_info *info = inf;
5167 struct ppc_elf_link_hash_entry *eh;
7619e7c7 5168 struct ppc_elf_link_hash_table *htab;
25dbc73a 5169 struct ppc_elf_dyn_relocs *p;
252b5132 5170
25dbc73a 5171 if (h->root.type == bfd_link_hash_indirect)
b34976b6 5172 return TRUE;
252b5132 5173
25dbc73a
AM
5174 if (h->root.type == bfd_link_hash_warning)
5175 /* When warning symbols are created, they **replace** the "real"
5176 entry in the hash table, thus we never get to see the real
5177 symbol in a hash traversal. So look at it now. */
5178 h = (struct elf_link_hash_entry *) h->root.u.i.link;
e47cd125 5179
7619e7c7 5180 htab = ppc_elf_hash_table (info);
e054468f
AM
5181 if (htab->elf.dynamic_sections_created
5182 || h->type == STT_GNU_IFUNC)
252b5132 5183 {
a6aa5195
AM
5184 struct plt_entry *ent;
5185 bfd_boolean doneone = FALSE;
28e99bb6 5186 bfd_vma plt_offset = 0, glink_offset = 0;
e054468f 5187 bfd_boolean dyn;
28e99bb6 5188
a6aa5195
AM
5189 for (ent = h->plt.plist; ent != NULL; ent = ent->next)
5190 if (ent->plt.refcount > 0)
5191 {
5192 /* Make sure this symbol is output as a dynamic symbol. */
5193 if (h->dynindx == -1
e054468f
AM
5194 && !h->forced_local
5195 && !h->def_regular
5196 && htab->elf.dynamic_sections_created)
a6aa5195
AM
5197 {
5198 if (! bfd_elf_link_record_dynamic_symbol (info, h))
5199 return FALSE;
5200 }
252b5132 5201
e054468f 5202 dyn = htab->elf.dynamic_sections_created;
a6aa5195 5203 if (info->shared
e054468f
AM
5204 || h->type == STT_GNU_IFUNC
5205 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h))
a6aa5195
AM
5206 {
5207 asection *s = htab->plt;
25f23106 5208 if (!dyn || h->dynindx == -1)
e054468f 5209 s = htab->iplt;
7619e7c7 5210
25f23106 5211 if (htab->plt_type == PLT_NEW || !dyn || h->dynindx == -1)
a6aa5195 5212 {
a6aa5195 5213 if (!doneone)
28e99bb6
AM
5214 {
5215 plt_offset = s->size;
5216 s->size += 4;
5217 }
5218 ent->plt.offset = plt_offset;
d7128ce4 5219
a6aa5195 5220 s = htab->glink;
a877a2b6 5221 if (!doneone || info->shared)
28e99bb6
AM
5222 {
5223 glink_offset = s->size;
5224 s->size += GLINK_ENTRY_SIZE;
a7f2871e
AM
5225 if (h == htab->tls_get_addr
5226 && !htab->no_tls_get_addr_opt)
5227 s->size += TLS_GET_ADDR_GLINK_SIZE - GLINK_ENTRY_SIZE;
28e99bb6
AM
5228 }
5229 if (!doneone
5230 && !info->shared
625af618 5231 && h->def_dynamic
a6aa5195
AM
5232 && !h->def_regular)
5233 {
5234 h->root.u.def.section = s;
28e99bb6 5235 h->root.u.def.value = glink_offset;
a6aa5195 5236 }
28e99bb6 5237 ent->glink_offset = glink_offset;
0ba07910
AM
5238
5239 if (htab->emit_stub_syms
ac39eb42 5240 && !add_stub_sym (ent, h, info))
0ba07910 5241 return FALSE;
a6aa5195
AM
5242 }
5243 else
5244 {
a6aa5195
AM
5245 if (!doneone)
5246 {
28e99bb6
AM
5247 /* If this is the first .plt entry, make room
5248 for the special first entry. */
5249 if (s->size == 0)
9d8504b1 5250 s->size += htab->plt_initial_entry_size;
28e99bb6
AM
5251
5252 /* The PowerPC PLT is actually composed of two
5253 parts, the first part is 2 words (for a load
5254 and a jump), and then there is a remaining
5255 word available at the end. */
9d8504b1
PB
5256 plt_offset = (htab->plt_initial_entry_size
5257 + (htab->plt_slot_size
5258 * ((s->size
5259 - htab->plt_initial_entry_size)
5260 / htab->plt_entry_size)));
28e99bb6
AM
5261
5262 /* If this symbol is not defined in a regular
5263 file, and we are not generating a shared
5b914448 5264 library, then set the symbol to this location
de972ffa
AM
5265 in the .plt. This is to avoid text
5266 relocations, and is required to make
28e99bb6
AM
5267 function pointers compare as equal between
5268 the normal executable and the shared library. */
5269 if (! info->shared
625af618 5270 && h->def_dynamic
28e99bb6
AM
5271 && !h->def_regular)
5272 {
5273 h->root.u.def.section = s;
5274 h->root.u.def.value = plt_offset;
5275 }
5276
9d8504b1
PB
5277 /* Make room for this entry. */
5278 s->size += htab->plt_entry_size;
5279 /* After the 8192nd entry, room for two entries
5280 is allocated. */
4a3dc543 5281 if (htab->plt_type == PLT_OLD
9d8504b1
PB
5282 && (s->size - htab->plt_initial_entry_size)
5283 / htab->plt_entry_size
5284 > PLT_NUM_SINGLE_ENTRIES)
5285 s->size += htab->plt_entry_size;
a6aa5195 5286 }
28e99bb6 5287 ent->plt.offset = plt_offset;
a6aa5195 5288 }
25dbc73a 5289
a6aa5195
AM
5290 /* We also need to make an entry in the .rela.plt section. */
5291 if (!doneone)
5292 {
25f23106
AM
5293 if (!htab->elf.dynamic_sections_created
5294 || h->dynindx == -1)
e054468f
AM
5295 htab->reliplt->size += sizeof (Elf32_External_Rela);
5296 else
9d8504b1 5297 {
e054468f
AM
5298 htab->relplt->size += sizeof (Elf32_External_Rela);
5299
5300 if (htab->plt_type == PLT_VXWORKS)
9d8504b1 5301 {
e054468f
AM
5302 /* Allocate space for the unloaded relocations. */
5303 if (!info->shared
5304 && htab->elf.dynamic_sections_created)
9d8504b1 5305 {
e054468f
AM
5306 if (ent->plt.offset
5307 == (bfd_vma) htab->plt_initial_entry_size)
5308 {
5309 htab->srelplt2->size
5310 += (sizeof (Elf32_External_Rela)
5311 * VXWORKS_PLTRESOLVE_RELOCS);
5312 }
5313
9d8504b1 5314 htab->srelplt2->size
e054468f
AM
5315 += (sizeof (Elf32_External_Rela)
5316 * VXWORKS_PLT_NON_JMP_SLOT_RELOCS);
9d8504b1
PB
5317 }
5318
e054468f
AM
5319 /* Every PLT entry has an associated GOT entry in
5320 .got.plt. */
5321 htab->sgotplt->size += 4;
9d8504b1 5322 }
9d8504b1 5323 }
a6aa5195
AM
5324 doneone = TRUE;
5325 }
5326 }
5327 else
5328 ent->plt.offset = (bfd_vma) -1;
a6aa5195 5329 }
2ce859a1
AM
5330 else
5331 ent->plt.offset = (bfd_vma) -1;
5332
5333 if (!doneone)
5334 {
5335 h->plt.plist = NULL;
5336 h->needs_plt = 0;
5337 }
25dbc73a
AM
5338 }
5339 else
5340 {
a6aa5195 5341 h->plt.plist = NULL;
25dbc73a
AM
5342 h->needs_plt = 0;
5343 }
5344
5345 eh = (struct ppc_elf_link_hash_entry *) h;
5346 if (eh->elf.got.refcount > 0)
5347 {
d6e14abc
AM
5348 bfd_boolean dyn;
5349 unsigned int need;
5350
25dbc73a
AM
5351 /* Make sure this symbol is output as a dynamic symbol. */
5352 if (eh->elf.dynindx == -1
b099ab9f 5353 && !eh->elf.forced_local
25f23106 5354 && eh->elf.type != STT_GNU_IFUNC
b099ab9f 5355 && htab->elf.dynamic_sections_created)
25dbc73a
AM
5356 {
5357 if (!bfd_elf_link_record_dynamic_symbol (info, &eh->elf))
b34976b6 5358 return FALSE;
25dbc73a 5359 }
252b5132 5360
d6e14abc
AM
5361 need = 0;
5362 if ((eh->tls_mask & TLS_TLS) != 0)
25dbc73a 5363 {
d6e14abc 5364 if ((eh->tls_mask & TLS_LD) != 0)
252b5132 5365 {
d6e14abc
AM
5366 if (!eh->elf.def_dynamic)
5367 /* We'll just use htab->tlsld_got.offset. This should
5368 always be the case. It's a little odd if we have
5369 a local dynamic reloc against a non-local symbol. */
5370 htab->tlsld_got.refcount += 1;
5371 else
3b36f7e6 5372 need += 8;
252b5132 5373 }
d6e14abc
AM
5374 if ((eh->tls_mask & TLS_GD) != 0)
5375 need += 8;
5376 if ((eh->tls_mask & (TLS_TPREL | TLS_TPRELGD)) != 0)
5377 need += 4;
5378 if ((eh->tls_mask & TLS_DTPREL) != 0)
3b36f7e6 5379 need += 4;
d6e14abc
AM
5380 }
5381 else
5382 need += 4;
5383 if (need == 0)
5384 eh->elf.got.offset = (bfd_vma) -1;
5385 else
5386 {
3b36f7e6 5387 eh->elf.got.offset = allocate_got (htab, need);
25dbc73a
AM
5388 dyn = htab->elf.dynamic_sections_created;
5389 if ((info->shared
5390 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, &eh->elf))
5391 && (ELF_ST_VISIBILITY (eh->elf.other) == STV_DEFAULT
5392 || eh->elf.root.type != bfd_link_hash_undefweak))
252b5132 5393 {
91e21fb7 5394 asection *rsec = htab->relgot;
3b36f7e6
AM
5395 /* All the entries we allocated need relocs.
5396 Except LD only needs one. */
d6e14abc
AM
5397 if ((eh->tls_mask & TLS_LD) != 0
5398 && eh->elf.def_dynamic)
3b36f7e6 5399 need -= 4;
25f23106 5400 rsec->size += need * (sizeof (Elf32_External_Rela) / 4);
252b5132 5401 }
25dbc73a
AM
5402 }
5403 }
5404 else
5405 eh->elf.got.offset = (bfd_vma) -1;
252b5132 5406
b099ab9f 5407 if (eh->dyn_relocs == NULL
de972ffa 5408 || !htab->elf.dynamic_sections_created)
25dbc73a 5409 return TRUE;
252b5132 5410
25dbc73a
AM
5411 /* In the shared -Bsymbolic case, discard space allocated for
5412 dynamic pc-relative relocs against symbols which turn out to be
5413 defined in regular objects. For the normal shared case, discard
5414 space for relocs that have become local due to symbol visibility
5415 changes. */
5416
5417 if (info->shared)
5418 {
5419 /* Relocs that use pc_count are those that appear on a call insn,
1d483afe 5420 or certain REL relocs (see must_be_dyn_reloc) that can be
25dbc73a
AM
5421 generated via assembly. We want calls to protected symbols to
5422 resolve directly to the function rather than going via the plt.
5423 If people want function pointer comparisons to work as expected
5424 then they should avoid writing weird assembly. */
5425 if (SYMBOL_CALLS_LOCAL (info, h))
5426 {
5427 struct ppc_elf_dyn_relocs **pp;
5428
5429 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; )
252b5132 5430 {
25dbc73a
AM
5431 p->count -= p->pc_count;
5432 p->pc_count = 0;
5433 if (p->count == 0)
5434 *pp = p->next;
5435 else
5436 pp = &p->next;
252b5132 5437 }
25dbc73a 5438 }
252b5132 5439
3348747a
NS
5440 if (htab->is_vxworks)
5441 {
5442 struct ppc_elf_dyn_relocs **pp;
5443
5444 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; )
5445 {
5446 if (strcmp (p->sec->output_section->name, ".tls_vars") == 0)
5447 *pp = p->next;
5448 else
5449 pp = &p->next;
5450 }
5451 }
5452
89200bf8
AM
5453 /* Discard relocs on undefined symbols that must be local. */
5454 if (eh->dyn_relocs != NULL
5455 && h->root.type == bfd_link_hash_undefined
5456 && (ELF_ST_VISIBILITY (h->other) == STV_HIDDEN
5457 || ELF_ST_VISIBILITY (h->other) == STV_INTERNAL))
5458 eh->dyn_relocs = NULL;
5459
25dbc73a
AM
5460 /* Also discard relocs on undefined weak syms with non-default
5461 visibility. */
cab87ef9
AM
5462 if (eh->dyn_relocs != NULL
5463 && h->root.type == bfd_link_hash_undefweak)
25dbc73a 5464 {
dfbb6ac9
AM
5465 if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
5466 eh->dyn_relocs = NULL;
5467
5468 /* Make sure undefined weak symbols are output as a dynamic
5469 symbol in PIEs. */
5470 else if (h->dynindx == -1
e054468f
AM
5471 && !h->forced_local
5472 && !h->def_regular)
dfbb6ac9
AM
5473 {
5474 if (! bfd_elf_link_record_dynamic_symbol (info, h))
5475 return FALSE;
5476 }
25dbc73a
AM
5477 }
5478 }
5479 else if (ELIMINATE_COPY_RELOCS)
5480 {
5481 /* For the non-shared case, discard space for relocs against
5482 symbols which turn out to need copy relocs or are not
5483 dynamic. */
7619e7c7 5484
25dbc73a 5485 if (!h->non_got_ref
25dbc73a
AM
5486 && !h->def_regular)
5487 {
5488 /* Make sure this symbol is output as a dynamic symbol.
5489 Undefined weak syms won't yet be marked as dynamic. */
5490 if (h->dynindx == -1
25f23106 5491 && !h->forced_local)
25dbc73a
AM
5492 {
5493 if (! bfd_elf_link_record_dynamic_symbol (info, h))
5494 return FALSE;
5495 }
7619e7c7 5496
25dbc73a
AM
5497 /* If that succeeded, we know we'll be keeping all the
5498 relocs. */
5499 if (h->dynindx != -1)
5500 goto keep;
5501 }
252b5132 5502
25dbc73a 5503 eh->dyn_relocs = NULL;
252b5132 5504
25dbc73a
AM
5505 keep: ;
5506 }
252b5132 5507
25dbc73a
AM
5508 /* Finally, allocate space. */
5509 for (p = eh->dyn_relocs; p != NULL; p = p->next)
5510 {
5511 asection *sreloc = elf_section_data (p->sec)->sreloc;
25f23106
AM
5512 if (!htab->elf.dynamic_sections_created)
5513 sreloc = htab->reliplt;
25dbc73a
AM
5514 sreloc->size += p->count * sizeof (Elf32_External_Rela);
5515 }
252b5132 5516
25dbc73a
AM
5517 return TRUE;
5518}
7619e7c7 5519
625af618
AM
5520/* Set DF_TEXTREL if we find any dynamic relocs that apply to
5521 read-only sections. */
7619e7c7 5522
25dbc73a 5523static bfd_boolean
625af618 5524maybe_set_textrel (struct elf_link_hash_entry *h, void *info)
25dbc73a 5525{
25dbc73a
AM
5526 if (h->root.type == bfd_link_hash_indirect)
5527 return TRUE;
252b5132 5528
25dbc73a
AM
5529 if (h->root.type == bfd_link_hash_warning)
5530 h = (struct elf_link_hash_entry *) h->root.u.i.link;
7619e7c7 5531
625af618 5532 if (readonly_dynrelocs (h))
25dbc73a 5533 {
625af618 5534 ((struct bfd_link_info *) info)->flags |= DF_TEXTREL;
ee05f2fe 5535
625af618
AM
5536 /* Not an error, just cut short the traversal. */
5537 return FALSE;
25dbc73a
AM
5538 }
5539 return TRUE;
5540}
5541
5542/* Set the sizes of the dynamic sections. */
5543
5544static bfd_boolean
5545ppc_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
5546 struct bfd_link_info *info)
5547{
5548 struct ppc_elf_link_hash_table *htab;
5549 asection *s;
5550 bfd_boolean relocs;
5551 bfd *ibfd;
7fce784e 5552
252b5132 5553#ifdef DEBUG
25dbc73a 5554 fprintf (stderr, "ppc_elf_size_dynamic_sections called\n");
252b5132 5555#endif
252b5132 5556
25dbc73a
AM
5557 htab = ppc_elf_hash_table (info);
5558 BFD_ASSERT (htab->elf.dynobj != NULL);
252b5132 5559
25dbc73a
AM
5560 if (elf_hash_table (info)->dynamic_sections_created)
5561 {
5562 /* Set the contents of the .interp section to the interpreter. */
5563 if (info->executable)
5564 {
5565 s = bfd_get_section_by_name (htab->elf.dynobj, ".interp");
5566 BFD_ASSERT (s != NULL);
5567 s->size = sizeof ELF_DYNAMIC_INTERPRETER;
5568 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
5569 }
5570 }
252b5132 5571
4a3dc543 5572 if (htab->plt_type == PLT_OLD)
d7128ce4 5573 htab->got_header_size = 16;
4a3dc543 5574 else if (htab->plt_type == PLT_NEW)
d7128ce4 5575 htab->got_header_size = 12;
252b5132 5576
25dbc73a
AM
5577 /* Set up .got offsets for local syms, and space for local dynamic
5578 relocs. */
5579 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
5580 {
5581 bfd_signed_vma *local_got;
5582 bfd_signed_vma *end_local_got;
e054468f
AM
5583 struct plt_entry **local_plt;
5584 struct plt_entry **end_local_plt;
25dbc73a
AM
5585 char *lgot_masks;
5586 bfd_size_type locsymcount;
5587 Elf_Internal_Shdr *symtab_hdr;
7fce784e 5588
0c8d6e5c 5589 if (!is_ppc_elf (ibfd))
25dbc73a 5590 continue;
7fce784e 5591
25dbc73a
AM
5592 for (s = ibfd->sections; s != NULL; s = s->next)
5593 {
5594 struct ppc_elf_dyn_relocs *p;
252b5132 5595
25dbc73a
AM
5596 for (p = ((struct ppc_elf_dyn_relocs *)
5597 elf_section_data (s)->local_dynrel);
5598 p != NULL;
5599 p = p->next)
5600 {
5601 if (!bfd_is_abs_section (p->sec)
5602 && bfd_is_abs_section (p->sec->output_section))
5603 {
5604 /* Input section has been discarded, either because
5605 it is a copy of a linkonce section or due to
5606 linker script /DISCARD/, so we'll be discarding
5607 the relocs too. */
7fce784e 5608 }
3348747a
NS
5609 else if (htab->is_vxworks
5610 && strcmp (p->sec->output_section->name,
5611 ".tls_vars") == 0)
5612 {
5613 /* Relocations in vxworks .tls_vars sections are
5614 handled specially by the loader. */
5615 }
25dbc73a 5616 else if (p->count != 0)
7fce784e 5617 {
25f23106
AM
5618 asection *sreloc = elf_section_data (p->sec)->sreloc;
5619 if (!htab->elf.dynamic_sections_created)
5620 sreloc = htab->reliplt;
5621 sreloc->size += p->count * sizeof (Elf32_External_Rela);
25dbc73a
AM
5622 if ((p->sec->output_section->flags
5623 & (SEC_READONLY | SEC_ALLOC))
5624 == (SEC_READONLY | SEC_ALLOC))
5625 info->flags |= DF_TEXTREL;
7fce784e 5626 }
252b5132 5627 }
252b5132 5628 }
252b5132 5629
25dbc73a
AM
5630 local_got = elf_local_got_refcounts (ibfd);
5631 if (!local_got)
5632 continue;
252b5132 5633
0ffa91dd 5634 symtab_hdr = &elf_symtab_hdr (ibfd);
25dbc73a
AM
5635 locsymcount = symtab_hdr->sh_info;
5636 end_local_got = local_got + locsymcount;
e054468f
AM
5637 local_plt = (struct plt_entry **) end_local_got;
5638 end_local_plt = local_plt + locsymcount;
5639 lgot_masks = (char *) end_local_plt;
91d6fa6a 5640
25dbc73a
AM
5641 for (; local_got < end_local_got; ++local_got, ++lgot_masks)
5642 if (*local_got > 0)
5643 {
d6e14abc
AM
5644 unsigned int need = 0;
5645 if ((*lgot_masks & TLS_TLS) != 0)
25dbc73a 5646 {
d6e14abc
AM
5647 if ((*lgot_masks & TLS_GD) != 0)
5648 need += 8;
5649 if ((*lgot_masks & TLS_LD) != 0)
5650 htab->tlsld_got.refcount += 1;
5651 if ((*lgot_masks & (TLS_TPREL | TLS_TPRELGD)) != 0)
5652 need += 4;
5653 if ((*lgot_masks & TLS_DTPREL) != 0)
5654 need += 4;
25dbc73a 5655 }
d6e14abc
AM
5656 else
5657 need += 4;
5658 if (need == 0)
5659 *local_got = (bfd_vma) -1;
25dbc73a
AM
5660 else
5661 {
3b36f7e6 5662 *local_got = allocate_got (htab, need);
25dbc73a 5663 if (info->shared)
3b36f7e6
AM
5664 htab->relgot->size += (need
5665 * (sizeof (Elf32_External_Rela) / 4));
25dbc73a
AM
5666 }
5667 }
5668 else
5669 *local_got = (bfd_vma) -1;
e054468f
AM
5670
5671 if (htab->is_vxworks)
5672 continue;
5673
5674 /* Allocate space for calls to local STT_GNU_IFUNC syms in .iplt. */
5675 for (; local_plt < end_local_plt; ++local_plt)
5676 {
5677 struct plt_entry *ent;
5678 bfd_boolean doneone = FALSE;
5679 bfd_vma plt_offset = 0, glink_offset = 0;
5680
5681 for (ent = *local_plt; ent != NULL; ent = ent->next)
5682 if (ent->plt.refcount > 0)
5683 {
91d6fa6a 5684 s = htab->iplt;
e054468f
AM
5685
5686 if (!doneone)
5687 {
5688 plt_offset = s->size;
5689 s->size += 4;
5690 }
5691 ent->plt.offset = plt_offset;
5692
5693 s = htab->glink;
a877a2b6 5694 if (!doneone || info->shared)
e054468f
AM
5695 {
5696 glink_offset = s->size;
5697 s->size += GLINK_ENTRY_SIZE;
5698 }
5699 ent->glink_offset = glink_offset;
5700
5701 if (!doneone)
5702 {
25f23106 5703 htab->reliplt->size += sizeof (Elf32_External_Rela);
e054468f
AM
5704 doneone = TRUE;
5705 }
5706 }
5707 else
5708 ent->plt.offset = (bfd_vma) -1;
5709 }
25dbc73a 5710 }
252b5132 5711
b7fcf6f6
AM
5712 /* Allocate space for global sym dynamic relocs. */
5713 elf_link_hash_traverse (elf_hash_table (info), allocate_dynrelocs, info);
5714
3b36f7e6
AM
5715 if (htab->tlsld_got.refcount > 0)
5716 {
5717 htab->tlsld_got.offset = allocate_got (htab, 8);
5718 if (info->shared)
5719 htab->relgot->size += sizeof (Elf32_External_Rela);
5720 }
5721 else
5722 htab->tlsld_got.offset = (bfd_vma) -1;
5723
4a3dc543 5724 if (htab->got != NULL && htab->plt_type != PLT_VXWORKS)
3b36f7e6
AM
5725 {
5726 unsigned int g_o_t = 32768;
5727
4d962050
AM
5728 /* If we haven't allocated the header, do so now. When we get here,
5729 for old plt/got the got size will be 0 to 32764 (not allocated),
5730 or 32780 to 65536 (header allocated). For new plt/got, the
5731 corresponding ranges are 0 to 32768 and 32780 to 65536. */
3b36f7e6
AM
5732 if (htab->got->size <= 32768)
5733 {
5734 g_o_t = htab->got->size;
4a3dc543 5735 if (htab->plt_type == PLT_OLD)
4d962050 5736 g_o_t += 4;
3b36f7e6
AM
5737 htab->got->size += htab->got_header_size;
5738 }
3b36f7e6
AM
5739
5740 htab->elf.hgot->root.u.def.value = g_o_t;
5741 }
bd6c6e2b
AM
5742 if (info->shared)
5743 {
5744 struct elf_link_hash_entry *sda = htab->sdata[0].sym;
5745 if (sda != NULL
5746 && !(sda->root.type == bfd_link_hash_defined
5747 || sda->root.type == bfd_link_hash_defweak))
5748 {
5749 sda->root.type = bfd_link_hash_defined;
5750 sda->root.u.def.section = htab->elf.hgot->root.u.def.section;
5751 sda->root.u.def.value = htab->elf.hgot->root.u.def.value;
5752 }
5753 }
3b36f7e6 5754
e054468f
AM
5755 if (htab->glink != NULL
5756 && htab->glink->size != 0
5757 && htab->elf.dynamic_sections_created)
d7128ce4
AM
5758 {
5759 htab->glink_pltresolve = htab->glink->size;
86b9da88
AM
5760 /* Space for the branch table. */
5761 htab->glink->size += htab->glink->size / (GLINK_ENTRY_SIZE / 4) - 4;
5762 /* Pad out to align the start of PLTresolve. */
5763 htab->glink->size += -htab->glink->size & 15;
d7128ce4 5764 htab->glink->size += GLINK_PLTRESOLVE;
0ba07910
AM
5765
5766 if (htab->emit_stub_syms)
5767 {
5768 struct elf_link_hash_entry *sh;
5769 sh = elf_link_hash_lookup (&htab->elf, "__glink",
5770 TRUE, FALSE, FALSE);
5771 if (sh == NULL)
5772 return FALSE;
5773 if (sh->root.type == bfd_link_hash_new)
5774 {
5775 sh->root.type = bfd_link_hash_defined;
5776 sh->root.u.def.section = htab->glink;
5777 sh->root.u.def.value = htab->glink_pltresolve;
5778 sh->ref_regular = 1;
5779 sh->def_regular = 1;
5780 sh->ref_regular_nonweak = 1;
5781 sh->forced_local = 1;
5782 sh->non_elf = 0;
5783 }
5784 sh = elf_link_hash_lookup (&htab->elf, "__glink_PLTresolve",
5785 TRUE, FALSE, FALSE);
5786 if (sh == NULL)
5787 return FALSE;
5788 if (sh->root.type == bfd_link_hash_new)
5789 {
5790 sh->root.type = bfd_link_hash_defined;
5791 sh->root.u.def.section = htab->glink;
5792 sh->root.u.def.value = htab->glink->size - GLINK_PLTRESOLVE;
5793 sh->ref_regular = 1;
5794 sh->def_regular = 1;
5795 sh->ref_regular_nonweak = 1;
5796 sh->forced_local = 1;
5797 sh->non_elf = 0;
5798 }
5799 }
d7128ce4
AM
5800 }
5801
25dbc73a
AM
5802 /* We've now determined the sizes of the various dynamic sections.
5803 Allocate memory for them. */
5804 relocs = FALSE;
5805 for (s = htab->elf.dynobj->sections; s != NULL; s = s->next)
252b5132 5806 {
9d8504b1
PB
5807 bfd_boolean strip_section = TRUE;
5808
25dbc73a
AM
5809 if ((s->flags & SEC_LINKER_CREATED) == 0)
5810 continue;
252b5132 5811
25dbc73a 5812 if (s == htab->plt
e054468f 5813 || s == htab->got)
25dbc73a 5814 {
9d8504b1
PB
5815 /* We'd like to strip these sections if they aren't needed, but if
5816 we've exported dynamic symbols from them we must leave them.
5817 It's too late to tell BFD to get rid of the symbols. */
e054468f 5818 if (htab->elf.hplt != NULL)
9d8504b1 5819 strip_section = FALSE;
25dbc73a
AM
5820 /* Strip this section if we don't need it; see the
5821 comment below. */
5822 }
e054468f
AM
5823 else if (s == htab->iplt
5824 || s == htab->glink
5825 || s == htab->sgotplt
5826 || s == htab->sbss
5827 || s == htab->dynbss
5828 || s == htab->dynsbss
5829 || s == htab->sdata[0].section
c9a2f333 5830 || s == htab->sdata[1].section)
25dbc73a 5831 {
c9a2f333 5832 /* Strip these too. */
25dbc73a 5833 }
0112cd26 5834 else if (CONST_STRNEQ (bfd_get_section_name (dynobj, s), ".rela"))
25dbc73a 5835 {
c456f082 5836 if (s->size != 0)
25dbc73a
AM
5837 {
5838 /* Remember whether there are any relocation sections. */
5839 relocs = TRUE;
252b5132 5840
25dbc73a
AM
5841 /* We use the reloc_count field as a counter if we need
5842 to copy relocs into the output file. */
5843 s->reloc_count = 0;
252b5132
RH
5844 }
5845 }
25dbc73a
AM
5846 else
5847 {
5848 /* It's not one of our sections, so don't allocate space. */
5849 continue;
5850 }
252b5132 5851
9d8504b1 5852 if (s->size == 0 && strip_section)
25dbc73a 5853 {
c456f082
AM
5854 /* If we don't need this section, strip it from the
5855 output file. This is mostly to handle .rela.bss and
5856 .rela.plt. We must create both sections in
5857 create_dynamic_sections, because they must be created
5858 before the linker maps input sections to output
5859 sections. The linker does that before
5860 adjust_dynamic_symbol is called, and it is that
5861 function which decides whether anything needs to go
5862 into these sections. */
8423293d 5863 s->flags |= SEC_EXCLUDE;
25dbc73a
AM
5864 continue;
5865 }
7fce784e 5866
d7128ce4 5867 if ((s->flags & SEC_HAS_CONTENTS) == 0)
644285ef
AM
5868 continue;
5869
25dbc73a
AM
5870 /* Allocate memory for the section contents. */
5871 s->contents = bfd_zalloc (htab->elf.dynobj, s->size);
5872 if (s->contents == NULL)
5873 return FALSE;
5874 }
252b5132 5875
25dbc73a 5876 if (htab->elf.dynamic_sections_created)
7619e7c7 5877 {
25dbc73a
AM
5878 /* Add some entries to the .dynamic section. We fill in the
5879 values later, in ppc_elf_finish_dynamic_sections, but we
5880 must add the entries now so that we get the correct size for
5881 the .dynamic section. The DT_DEBUG entry is filled in by the
5882 dynamic linker and used by the debugger. */
5883#define add_dynamic_entry(TAG, VAL) \
5884 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
252b5132 5885
25dbc73a 5886 if (info->executable)
7619e7c7 5887 {
25dbc73a
AM
5888 if (!add_dynamic_entry (DT_DEBUG, 0))
5889 return FALSE;
7619e7c7
AM
5890 }
5891
25dbc73a 5892 if (htab->plt != NULL && htab->plt->size != 0)
7619e7c7 5893 {
25dbc73a
AM
5894 if (!add_dynamic_entry (DT_PLTGOT, 0)
5895 || !add_dynamic_entry (DT_PLTRELSZ, 0)
5896 || !add_dynamic_entry (DT_PLTREL, DT_RELA)
5897 || !add_dynamic_entry (DT_JMPREL, 0))
5898 return FALSE;
5899 }
7619e7c7 5900
d7128ce4
AM
5901 if (htab->glink != NULL && htab->glink->size != 0)
5902 {
1fe44d79 5903 if (!add_dynamic_entry (DT_PPC_GOT, 0))
d7128ce4 5904 return FALSE;
a7f2871e
AM
5905 if (!htab->no_tls_get_addr_opt
5906 && htab->tls_get_addr != NULL
5907 && htab->tls_get_addr->plt.plist != NULL
5908 && !add_dynamic_entry (DT_PPC_TLSOPT, 0))
5909 return FALSE;
d7128ce4
AM
5910 }
5911
25dbc73a
AM
5912 if (relocs)
5913 {
5914 if (!add_dynamic_entry (DT_RELA, 0)
5915 || !add_dynamic_entry (DT_RELASZ, 0)
5916 || !add_dynamic_entry (DT_RELAENT, sizeof (Elf32_External_Rela)))
5917 return FALSE;
5918 }
7619e7c7 5919
25dbc73a
AM
5920 /* If any dynamic relocs apply to a read-only section, then we
5921 need a DT_TEXTREL entry. */
5922 if ((info->flags & DF_TEXTREL) == 0)
625af618 5923 elf_link_hash_traverse (elf_hash_table (info), maybe_set_textrel,
25dbc73a 5924 info);
7619e7c7 5925
25dbc73a
AM
5926 if ((info->flags & DF_TEXTREL) != 0)
5927 {
5928 if (!add_dynamic_entry (DT_TEXTREL, 0))
5929 return FALSE;
7619e7c7 5930 }
7a2b07ff
NS
5931 if (htab->is_vxworks
5932 && !elf_vxworks_add_dynamic_entries (output_bfd, info))
5933 return FALSE;
5934 }
25dbc73a
AM
5935#undef add_dynamic_entry
5936
7619e7c7
AM
5937 return TRUE;
5938}
0eb4a168
AM
5939
5940/* Return TRUE if symbol should be hashed in the `.gnu.hash' section. */
5941
5942static bfd_boolean
5943ppc_elf_hash_symbol (struct elf_link_hash_entry *h)
5944{
5945 if (h->plt.plist != NULL
5946 && !h->def_regular
5947 && (!h->pointer_equality_needed
5948 || !h->ref_regular_nonweak))
5949 return FALSE;
5950
5951 return _bfd_elf_hash_symbol (h);
5952}
25dbc73a
AM
5953\f
5954#define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
5955
01017ef8
NS
5956/* Relaxation trampolines. r12 is available for clobbering (r11, is
5957 used for some functions that are allowed to break the ABI). */
25dbc73a
AM
5958static const int shared_stub_entry[] =
5959 {
5960 0x7c0802a6, /* mflr 0 */
5961 0x429f0005, /* bcl 20, 31, .Lxxx */
01017ef8
NS
5962 0x7d8802a6, /* mflr 12 */
5963 0x3d8c0000, /* addis 12, 12, (xxx-.Lxxx)@ha */
5964 0x398c0008, /* addi 12, 12, (xxx-.Lxxx)@l */
25dbc73a 5965 0x7c0803a6, /* mtlr 0 */
01017ef8 5966 0x7d8903a6, /* mtctr 12 */
25dbc73a
AM
5967 0x4e800420, /* bctr */
5968 };
5969
5970static const int stub_entry[] =
5971 {
01017ef8
NS
5972 0x3d800000, /* lis 12,xxx@ha */
5973 0x398c0000, /* addi 12,12,xxx@l */
5974 0x7d8903a6, /* mtctr 12 */
25dbc73a
AM
5975 0x4e800420, /* bctr */
5976 };
5977
5978static bfd_boolean
5979ppc_elf_relax_section (bfd *abfd,
5980 asection *isec,
5981 struct bfd_link_info *link_info,
5982 bfd_boolean *again)
5983{
5984 struct one_fixup
5985 {
5986 struct one_fixup *next;
5987 asection *tsec;
01017ef8
NS
5988 /* Final link, can use the symbol offset. For a
5989 relocatable link we use the symbol's index. */
25dbc73a
AM
5990 bfd_vma toff;
5991 bfd_vma trampoff;
5992 };
7619e7c7 5993
25dbc73a
AM
5994 Elf_Internal_Shdr *symtab_hdr;
5995 bfd_byte *contents = NULL;
5996 Elf_Internal_Sym *isymbuf = NULL;
5997 Elf_Internal_Rela *internal_relocs = NULL;
5998 Elf_Internal_Rela *irel, *irelend;
5999 struct one_fixup *fixups = NULL;
9bc4e62b 6000 unsigned changes = 0;
d7128ce4 6001 struct ppc_elf_link_hash_table *htab;
25dbc73a 6002 bfd_size_type trampoff;
a6aa5195 6003 asection *got2;
50248c89 6004 bfd_boolean maybe_pasted;
7619e7c7 6005
25dbc73a 6006 *again = FALSE;
7619e7c7 6007
c87b5a93 6008 /* Nothing to do if there are no relocations, and no need to do
a8ad78a7 6009 anything with non-alloc or non-code sections. */
c87b5a93 6010 if ((isec->flags & SEC_ALLOC) == 0
a8ad78a7 6011 || (isec->flags & SEC_CODE) == 0
c87b5a93
AM
6012 || (isec->flags & SEC_RELOC) == 0
6013 || isec->reloc_count == 0)
25dbc73a 6014 return TRUE;
7619e7c7 6015
c8a1f254
NS
6016 /* We cannot represent the required PIC relocs in the output, so don't
6017 do anything. The linker doesn't support mixing -shared and -r
6018 anyway. */
6019 if (link_info->relocatable && link_info->shared)
6020 return TRUE;
5b914448 6021
25dbc73a 6022 trampoff = (isec->size + 3) & (bfd_vma) -4;
50248c89
AM
6023 maybe_pasted = (strcmp (isec->output_section->name, ".init") == 0
6024 || strcmp (isec->output_section->name, ".fini") == 0);
25dbc73a 6025 /* Space for a branch around any trampolines. */
50248c89
AM
6026 if (maybe_pasted)
6027 trampoff += 4;
7619e7c7 6028
0ffa91dd 6029 symtab_hdr = &elf_symtab_hdr (abfd);
7619e7c7 6030
25dbc73a
AM
6031 /* Get a copy of the native relocations. */
6032 internal_relocs = _bfd_elf_link_read_relocs (abfd, isec, NULL, NULL,
6033 link_info->keep_memory);
6034 if (internal_relocs == NULL)
6035 goto error_return;
7619e7c7 6036
d7128ce4 6037 htab = ppc_elf_hash_table (link_info);
a6aa5195 6038 got2 = bfd_get_section_by_name (abfd, ".got2");
7619e7c7 6039
a6aa5195 6040 irelend = internal_relocs + isec->reloc_count;
25dbc73a 6041 for (irel = internal_relocs; irel < irelend; irel++)
7619e7c7 6042 {
25dbc73a 6043 unsigned long r_type = ELF32_R_TYPE (irel->r_info);
91d6fa6a 6044 bfd_vma toff, roff;
25dbc73a
AM
6045 asection *tsec;
6046 struct one_fixup *f;
6047 size_t insn_offset = 0;
6048 bfd_vma max_branch_offset, val;
6049 bfd_byte *hit_addr;
6050 unsigned long t0;
de972ffa 6051 struct elf_link_hash_entry *h;
a9585d22 6052 struct plt_entry **plist;
25dbc73a 6053 unsigned char sym_type;
7619e7c7 6054
25dbc73a
AM
6055 switch (r_type)
6056 {
6057 case R_PPC_REL24:
6058 case R_PPC_LOCAL24PC:
6059 case R_PPC_PLTREL24:
6060 max_branch_offset = 1 << 25;
6061 break;
7619e7c7 6062
25dbc73a
AM
6063 case R_PPC_REL14:
6064 case R_PPC_REL14_BRTAKEN:
6065 case R_PPC_REL14_BRNTAKEN:
6066 max_branch_offset = 1 << 15;
6067 break;
7619e7c7 6068
25dbc73a
AM
6069 default:
6070 continue;
6071 }
7619e7c7 6072
25dbc73a 6073 /* Get the value of the symbol referred to by the reloc. */
de972ffa 6074 h = NULL;
25dbc73a
AM
6075 if (ELF32_R_SYM (irel->r_info) < symtab_hdr->sh_info)
6076 {
6077 /* A local symbol. */
6078 Elf_Internal_Sym *isym;
7fce784e 6079
25dbc73a
AM
6080 /* Read this BFD's local symbols. */
6081 if (isymbuf == NULL)
6082 {
6083 isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
6084 if (isymbuf == NULL)
6085 isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
6086 symtab_hdr->sh_info, 0,
6087 NULL, NULL, NULL);
6088 if (isymbuf == 0)
6089 goto error_return;
6090 }
6091 isym = isymbuf + ELF32_R_SYM (irel->r_info);
6092 if (isym->st_shndx == SHN_UNDEF)
c8a1f254 6093 tsec = bfd_und_section_ptr;
25dbc73a
AM
6094 else if (isym->st_shndx == SHN_ABS)
6095 tsec = bfd_abs_section_ptr;
6096 else if (isym->st_shndx == SHN_COMMON)
6097 tsec = bfd_com_section_ptr;
6098 else
6099 tsec = bfd_section_from_elf_index (abfd, isym->st_shndx);
7fce784e 6100
25dbc73a
AM
6101 toff = isym->st_value;
6102 sym_type = ELF_ST_TYPE (isym->st_info);
6103 }
6104 else
6105 {
6106 /* Global symbol handling. */
6107 unsigned long indx;
7619e7c7 6108
25dbc73a
AM
6109 indx = ELF32_R_SYM (irel->r_info) - symtab_hdr->sh_info;
6110 h = elf_sym_hashes (abfd)[indx];
7619e7c7 6111
25dbc73a
AM
6112 while (h->root.type == bfd_link_hash_indirect
6113 || h->root.type == bfd_link_hash_warning)
6114 h = (struct elf_link_hash_entry *) h->root.u.i.link;
7619e7c7 6115
a9585d22
AM
6116 if (h->root.type == bfd_link_hash_defined
6117 || h->root.type == bfd_link_hash_defweak)
25dbc73a
AM
6118 {
6119 tsec = h->root.u.def.section;
6120 toff = h->root.u.def.value;
6121 }
c8a1f254
NS
6122 else if (h->root.type == bfd_link_hash_undefined
6123 || h->root.type == bfd_link_hash_undefweak)
6124 {
6125 tsec = bfd_und_section_ptr;
01017ef8 6126 toff = link_info->relocatable ? indx : 0;
c8a1f254 6127 }
25dbc73a
AM
6128 else
6129 continue;
7619e7c7 6130
25dbc73a
AM
6131 sym_type = h->type;
6132 }
7619e7c7 6133
a9585d22
AM
6134 /* The condition here under which we call find_plt_ent must
6135 match that in relocate_section. If we call find_plt_ent here
6136 but not in relocate_section, or vice versa, then the branch
6137 destination used here may be incorrect. */
6138 plist = NULL;
6139 if (h != NULL)
de972ffa 6140 {
a9585d22
AM
6141 /* We know is_branch_reloc (r_type) is true. */
6142 if (h->type == STT_GNU_IFUNC
6143 || r_type == R_PPC_PLTREL24)
de972ffa 6144 plist = &h->plt.plist;
a9585d22
AM
6145 }
6146 else if (sym_type == STT_GNU_IFUNC
6147 && elf_local_got_offsets (abfd) != NULL)
6148 {
6149 bfd_vma *local_got_offsets = elf_local_got_offsets (abfd);
6150 struct plt_entry **local_plt = (struct plt_entry **)
6151 (local_got_offsets + symtab_hdr->sh_info);
6152 plist = local_plt + ELF32_R_SYM (irel->r_info);
6153 }
6154 if (plist != NULL)
6155 {
6156 bfd_vma addend = 0;
6157 struct plt_entry *ent;
de972ffa 6158
a9585d22
AM
6159 if (r_type == R_PPC_PLTREL24 && link_info->shared)
6160 addend = irel->r_addend;
6161 ent = find_plt_ent (plist, got2, addend);
6162 if (ent != NULL)
6163 {
6164 if (htab->plt_type == PLT_NEW
6165 || h == NULL
6166 || !htab->elf.dynamic_sections_created
6167 || h->dynindx == -1)
de972ffa 6168 {
a9585d22
AM
6169 tsec = htab->glink;
6170 toff = ent->glink_offset;
6171 }
6172 else
6173 {
6174 tsec = htab->plt;
6175 toff = ent->plt.offset;
de972ffa
AM
6176 }
6177 }
6178 }
6179
25dbc73a
AM
6180 /* If the branch and target are in the same section, you have
6181 no hope of adding stubs. We'll error out later should the
6182 branch overflow. */
6183 if (tsec == isec)
6184 continue;
6185
6186 /* There probably isn't any reason to handle symbols in
6187 SEC_MERGE sections; SEC_MERGE doesn't seem a likely
6188 attribute for a code section, and we are only looking at
6189 branches. However, implement it correctly here as a
6190 reference for other target relax_section functions. */
6191 if (0 && tsec->sec_info_type == ELF_INFO_TYPE_MERGE)
6192 {
6193 /* At this stage in linking, no SEC_MERGE symbol has been
6194 adjusted, so all references to such symbols need to be
6195 passed through _bfd_merged_section_offset. (Later, in
6196 relocate_section, all SEC_MERGE symbols *except* for
6197 section symbols have been adjusted.)
6198
6199 gas may reduce relocations against symbols in SEC_MERGE
6200 sections to a relocation against the section symbol when
6201 the original addend was zero. When the reloc is against
6202 a section symbol we should include the addend in the
6203 offset passed to _bfd_merged_section_offset, since the
6204 location of interest is the original symbol. On the
6205 other hand, an access to "sym+addend" where "sym" is not
6206 a section symbol should not include the addend; Such an
6207 access is presumed to be an offset from "sym"; The
6208 location of interest is just "sym". */
6209 if (sym_type == STT_SECTION)
6210 toff += irel->r_addend;
7619e7c7 6211
25dbc73a
AM
6212 toff = _bfd_merged_section_offset (abfd, &tsec,
6213 elf_section_data (tsec)->sec_info,
6214 toff);
7619e7c7 6215
25dbc73a
AM
6216 if (sym_type != STT_SECTION)
6217 toff += irel->r_addend;
6218 }
a6aa5195
AM
6219 /* PLTREL24 addends are special. */
6220 else if (r_type != R_PPC_PLTREL24)
25dbc73a 6221 toff += irel->r_addend;
7619e7c7 6222
7de713b9
AM
6223 /* Attempted -shared link of non-pic code loses. */
6224 if (tsec->output_section == NULL)
6225 continue;
6226
25dbc73a 6227 roff = irel->r_offset;
7619e7c7 6228
25dbc73a 6229 /* If the branch is in range, no need to do anything. */
c8a1f254
NS
6230 if (tsec != bfd_und_section_ptr
6231 && (!link_info->relocatable
6232 /* A relocatable link may have sections moved during
6233 final link, so do not presume they remain in range. */
01017ef8
NS
6234 || tsec->output_section == isec->output_section))
6235 {
6236 bfd_vma symaddr, reladdr;
6237
6238 symaddr = tsec->output_section->vma + tsec->output_offset + toff;
6239 reladdr = isec->output_section->vma + isec->output_offset + roff;
6240 if (symaddr - reladdr + max_branch_offset < 2 * max_branch_offset)
6241 continue;
6242 }
252b5132 6243
25dbc73a
AM
6244 /* Look for an existing fixup to this address. */
6245 for (f = fixups; f ; f = f->next)
6246 if (f->tsec == tsec && f->toff == toff)
6247 break;
6248
6249 if (f == NULL)
7619e7c7 6250 {
25dbc73a
AM
6251 size_t size;
6252 unsigned long stub_rtype;
252b5132 6253
25dbc73a
AM
6254 val = trampoff - roff;
6255 if (val >= max_branch_offset)
6256 /* Oh dear, we can't reach a trampoline. Don't try to add
6257 one. We'll report an error later. */
6258 continue;
252b5132 6259
25dbc73a
AM
6260 if (link_info->shared)
6261 {
6262 size = 4 * ARRAY_SIZE (shared_stub_entry);
6263 insn_offset = 12;
25dbc73a
AM
6264 }
6265 else
6266 {
6267 size = 4 * ARRAY_SIZE (stub_entry);
6268 insn_offset = 0;
25dbc73a 6269 }
32af9f6e 6270 stub_rtype = R_PPC_RELAX;
d7128ce4
AM
6271 if (tsec == htab->plt
6272 || tsec == htab->glink)
32af9f6e
AM
6273 {
6274 stub_rtype = R_PPC_RELAX_PLT;
6275 if (r_type == R_PPC_PLTREL24)
6276 stub_rtype = R_PPC_RELAX_PLTREL24;
6277 }
252b5132 6278
25dbc73a
AM
6279 /* Hijack the old relocation. Since we need two
6280 relocations for this use a "composite" reloc. */
6281 irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
6282 stub_rtype);
6283 irel->r_offset = trampoff + insn_offset;
32af9f6e
AM
6284 if (r_type == R_PPC_PLTREL24
6285 && stub_rtype != R_PPC_RELAX_PLTREL24)
e7d92e2e 6286 irel->r_addend = 0;
252b5132 6287
25dbc73a
AM
6288 /* Record the fixup so we don't do it again this section. */
6289 f = bfd_malloc (sizeof (*f));
6290 f->next = fixups;
6291 f->tsec = tsec;
6292 f->toff = toff;
6293 f->trampoff = trampoff;
6294 fixups = f;
252b5132 6295
25dbc73a 6296 trampoff += size;
9bc4e62b 6297 changes++;
25dbc73a
AM
6298 }
6299 else
6300 {
6301 val = f->trampoff - roff;
6302 if (val >= max_branch_offset)
6303 continue;
252b5132 6304
25dbc73a
AM
6305 /* Nop out the reloc, since we're finalizing things here. */
6306 irel->r_info = ELF32_R_INFO (0, R_PPC_NONE);
6307 }
252b5132 6308
25dbc73a
AM
6309 /* Get the section contents. */
6310 if (contents == NULL)
6311 {
6312 /* Get cached copy if it exists. */
6313 if (elf_section_data (isec)->this_hdr.contents != NULL)
6314 contents = elf_section_data (isec)->this_hdr.contents;
6315 else
6316 {
6317 /* Go get them off disk. */
6318 if (!bfd_malloc_and_get_section (abfd, isec, &contents))
6319 goto error_return;
6320 }
6321 }
252b5132 6322
25dbc73a
AM
6323 /* Fix up the existing branch to hit the trampoline. */
6324 hit_addr = contents + roff;
6325 switch (r_type)
6326 {
6327 case R_PPC_REL24:
6328 case R_PPC_LOCAL24PC:
6329 case R_PPC_PLTREL24:
6330 t0 = bfd_get_32 (abfd, hit_addr);
6331 t0 &= ~0x3fffffc;
6332 t0 |= val & 0x3fffffc;
6333 bfd_put_32 (abfd, t0, hit_addr);
6334 break;
252b5132 6335
25dbc73a
AM
6336 case R_PPC_REL14:
6337 case R_PPC_REL14_BRTAKEN:
6338 case R_PPC_REL14_BRNTAKEN:
6339 t0 = bfd_get_32 (abfd, hit_addr);
6340 t0 &= ~0xfffc;
6341 t0 |= val & 0xfffc;
6342 bfd_put_32 (abfd, t0, hit_addr);
6343 break;
6344 }
6345 }
252b5132 6346
25dbc73a 6347 /* Write out the trampolines. */
25dbc73a
AM
6348 if (fixups != NULL)
6349 {
6350 const int *stub;
6351 bfd_byte *dest;
25dbc73a 6352 int i, size;
252b5132 6353
25dbc73a
AM
6354 do
6355 {
6356 struct one_fixup *f = fixups;
6357 fixups = fixups->next;
6358 free (f);
6359 }
6360 while (fixups);
252b5132 6361
515ef31d 6362 contents = bfd_realloc_or_free (contents, trampoff);
25dbc73a
AM
6363 if (contents == NULL)
6364 goto error_return;
252b5132 6365
25dbc73a 6366 isec->size = (isec->size + 3) & (bfd_vma) -4;
25dbc73a 6367 dest = contents + isec->size;
50248c89
AM
6368 /* Branch around the trampolines. */
6369 if (maybe_pasted)
6370 {
6371 bfd_vma val = B + trampoff - isec->size;
6372 bfd_put_32 (abfd, val, dest);
6373 dest += 4;
6374 }
25dbc73a 6375 isec->size = trampoff;
252b5132 6376
25dbc73a
AM
6377 if (link_info->shared)
6378 {
6379 stub = shared_stub_entry;
6380 size = ARRAY_SIZE (shared_stub_entry);
6381 }
6382 else
6383 {
6384 stub = stub_entry;
6385 size = ARRAY_SIZE (stub_entry);
6386 }
252b5132 6387
25dbc73a
AM
6388 i = 0;
6389 while (dest < contents + trampoff)
252b5132 6390 {
25dbc73a
AM
6391 bfd_put_32 (abfd, stub[i], dest);
6392 i++;
6393 if (i == size)
6394 i = 0;
6395 dest += 4;
252b5132 6396 }
25dbc73a 6397 BFD_ASSERT (i == 0);
252b5132
RH
6398 }
6399
25dbc73a
AM
6400 if (isymbuf != NULL
6401 && symtab_hdr->contents != (unsigned char *) isymbuf)
252b5132 6402 {
25dbc73a
AM
6403 if (! link_info->keep_memory)
6404 free (isymbuf);
252b5132 6405 else
25dbc73a
AM
6406 {
6407 /* Cache the symbols for elf_link_input_bfd. */
6408 symtab_hdr->contents = (unsigned char *) isymbuf;
6409 }
252b5132
RH
6410 }
6411
25dbc73a
AM
6412 if (contents != NULL
6413 && elf_section_data (isec)->this_hdr.contents != contents)
6414 {
9bc4e62b 6415 if (!changes && !link_info->keep_memory)
25dbc73a
AM
6416 free (contents);
6417 else
6418 {
6419 /* Cache the section contents for elf_link_input_bfd. */
6420 elf_section_data (isec)->this_hdr.contents = contents;
6421 }
6422 }
252b5132 6423
9bc4e62b 6424 if (changes != 0)
25dbc73a 6425 {
9bc4e62b
NS
6426 /* Append sufficient NOP relocs so we can write out relocation
6427 information for the trampolines. */
d4730f92 6428 Elf_Internal_Shdr *rel_hdr;
9bc4e62b
NS
6429 Elf_Internal_Rela *new_relocs = bfd_malloc ((changes + isec->reloc_count)
6430 * sizeof (*new_relocs));
6431 unsigned ix;
5b914448 6432
9bc4e62b
NS
6433 if (!new_relocs)
6434 goto error_return;
6435 memcpy (new_relocs, internal_relocs,
6436 isec->reloc_count * sizeof (*new_relocs));
6437 for (ix = changes; ix--;)
6438 {
6439 irel = new_relocs + ix + isec->reloc_count;
6440
6441 irel->r_info = ELF32_R_INFO (0, R_PPC_NONE);
6442 }
6443 if (internal_relocs != elf_section_data (isec)->relocs)
25dbc73a 6444 free (internal_relocs);
9bc4e62b
NS
6445 elf_section_data (isec)->relocs = new_relocs;
6446 isec->reloc_count += changes;
d4730f92
BS
6447 rel_hdr = _bfd_elf_single_rel_hdr (isec);
6448 rel_hdr->sh_size += changes * rel_hdr->sh_entsize;
25dbc73a 6449 }
9bc4e62b
NS
6450 else if (elf_section_data (isec)->relocs != internal_relocs)
6451 free (internal_relocs);
252b5132 6452
9bc4e62b 6453 *again = changes != 0;
c8a1f254
NS
6454 if (!*again && link_info->relocatable)
6455 {
6456 /* Convert the internal relax relocs to external form. */
6457 for (irel = internal_relocs; irel < irelend; irel++)
32af9f6e 6458 if (ELF32_R_TYPE (irel->r_info) == R_PPC_RELAX)
c8a1f254
NS
6459 {
6460 unsigned long r_symndx = ELF32_R_SYM (irel->r_info);
6461
6462 /* Rewrite the reloc and convert one of the trailing nop
6463 relocs to describe this relocation. */
6464 BFD_ASSERT (ELF32_R_TYPE (irelend[-1].r_info) == R_PPC_NONE);
6465 /* The relocs are at the bottom 2 bytes */
6466 irel[0].r_offset += 2;
6467 memmove (irel + 1, irel, (irelend - irel - 1) * sizeof (*irel));
6468 irel[0].r_info = ELF32_R_INFO (r_symndx, R_PPC_ADDR16_HA);
6469 irel[1].r_offset += 4;
6470 irel[1].r_info = ELF32_R_INFO (r_symndx, R_PPC_ADDR16_LO);
6471 irel++;
6472 }
6473 }
5b914448 6474
b34976b6 6475 return TRUE;
25dbc73a
AM
6476
6477 error_return:
6478 if (isymbuf != NULL && (unsigned char *) isymbuf != symtab_hdr->contents)
6479 free (isymbuf);
6480 if (contents != NULL
6481 && elf_section_data (isec)->this_hdr.contents != contents)
6482 free (contents);
6483 if (internal_relocs != NULL
6484 && elf_section_data (isec)->relocs != internal_relocs)
6485 free (internal_relocs);
6486 return FALSE;
252b5132 6487}
252b5132 6488\f
8a696751
AM
6489/* What to do when ld finds relocations against symbols defined in
6490 discarded sections. */
6491
6492static unsigned int
6493ppc_elf_action_discarded (asection *sec)
6494{
6495 if (strcmp (".fixup", sec->name) == 0)
6496 return 0;
6497
6498 if (strcmp (".got2", sec->name) == 0)
6499 return 0;
6500
6501 return _bfd_elf_default_action_discarded (sec);
6502}
c9a2f333 6503\f
25dbc73a 6504/* Fill in the address for a pointer generated in a linker section. */
252b5132 6505
25dbc73a 6506static bfd_vma
76750a2f 6507elf_finish_pointer_linker_section (bfd *input_bfd,
25dbc73a
AM
6508 elf_linker_section_t *lsect,
6509 struct elf_link_hash_entry *h,
6510 bfd_vma relocation,
2bb04cf2 6511 const Elf_Internal_Rela *rel)
25dbc73a
AM
6512{
6513 elf_linker_section_pointers_t *linker_section_ptr;
252b5132 6514
25dbc73a 6515 BFD_ASSERT (lsect != NULL);
252b5132 6516
25dbc73a 6517 if (h != NULL)
252b5132 6518 {
25dbc73a
AM
6519 /* Handle global symbol. */
6520 struct ppc_elf_link_hash_entry *eh;
252b5132 6521
25dbc73a 6522 eh = (struct ppc_elf_link_hash_entry *) h;
76750a2f
AM
6523 BFD_ASSERT (eh->elf.def_regular);
6524 linker_section_ptr = eh->linker_section_pointer;
25dbc73a
AM
6525 }
6526 else
6527 {
6528 /* Handle local symbol. */
6529 unsigned long r_symndx = ELF32_R_SYM (rel->r_info);
76750a2f 6530
0c8d6e5c 6531 BFD_ASSERT (is_ppc_elf (input_bfd));
25dbc73a 6532 BFD_ASSERT (elf_local_ptr_offsets (input_bfd) != NULL);
76750a2f
AM
6533 linker_section_ptr = elf_local_ptr_offsets (input_bfd)[r_symndx];
6534 }
252b5132 6535
76750a2f
AM
6536 linker_section_ptr = elf_find_pointer_linker_section (linker_section_ptr,
6537 rel->r_addend,
6538 lsect);
6539 BFD_ASSERT (linker_section_ptr != NULL);
25dbc73a 6540
76750a2f
AM
6541 /* Offset will always be a multiple of four, so use the bottom bit
6542 as a "written" flag. */
6543 if ((linker_section_ptr->offset & 1) == 0)
6544 {
6545 bfd_put_32 (lsect->section->owner,
6546 relocation + linker_section_ptr->addend,
6547 lsect->section->contents + linker_section_ptr->offset);
6548 linker_section_ptr->offset += 1;
252b5132
RH
6549 }
6550
bd6c6e2b
AM
6551 relocation = (lsect->section->output_section->vma
6552 + lsect->section->output_offset
76750a2f 6553 + linker_section_ptr->offset - 1
bd6c6e2b 6554 - SYM_VAL (lsect->sym));
252b5132 6555
25dbc73a
AM
6556#ifdef DEBUG
6557 fprintf (stderr,
6558 "Finish pointer in linker section %s, offset = %ld (0x%lx)\n",
6559 lsect->name, (long) relocation, (long) relocation);
6560#endif
252b5132 6561
bd6c6e2b 6562 return relocation;
252b5132 6563}
25dbc73a 6564
e054468f
AM
6565#define PPC_LO(v) ((v) & 0xffff)
6566#define PPC_HI(v) (((v) >> 16) & 0xffff)
6567#define PPC_HA(v) PPC_HI ((v) + 0x8000)
6568
6569static void
a7f2871e 6570write_glink_stub (struct plt_entry *ent, asection *plt_sec, unsigned char *p,
e054468f
AM
6571 struct bfd_link_info *info)
6572{
6573 struct ppc_elf_link_hash_table *htab = ppc_elf_hash_table (info);
6574 bfd *output_bfd = info->output_bfd;
6575 bfd_vma plt;
e054468f
AM
6576
6577 plt = ((ent->plt.offset & ~1)
6578 + plt_sec->output_section->vma
6579 + plt_sec->output_offset);
e054468f 6580
a877a2b6 6581 if (info->shared)
e054468f
AM
6582 {
6583 bfd_vma got = 0;
6584
6585 if (ent->addend >= 32768)
6586 got = (ent->addend
6587 + ent->sec->output_section->vma
6588 + ent->sec->output_offset);
6589 else if (htab->elf.hgot != NULL)
6590 got = SYM_VAL (htab->elf.hgot);
6591
6592 plt -= got;
6593
6594 if (plt + 0x8000 < 0x10000)
6595 {
6596 bfd_put_32 (output_bfd, LWZ_11_30 + PPC_LO (plt), p);
6597 p += 4;
6598 bfd_put_32 (output_bfd, MTCTR_11, p);
6599 p += 4;
6600 bfd_put_32 (output_bfd, BCTR, p);
6601 p += 4;
6602 bfd_put_32 (output_bfd, NOP, p);
6603 p += 4;
6604 }
6605 else
6606 {
6607 bfd_put_32 (output_bfd, ADDIS_11_30 + PPC_HA (plt), p);
6608 p += 4;
6609 bfd_put_32 (output_bfd, LWZ_11_11 + PPC_LO (plt), p);
6610 p += 4;
6611 bfd_put_32 (output_bfd, MTCTR_11, p);
6612 p += 4;
6613 bfd_put_32 (output_bfd, BCTR, p);
6614 p += 4;
6615 }
6616 }
6617 else
6618 {
6619 bfd_put_32 (output_bfd, LIS_11 + PPC_HA (plt), p);
6620 p += 4;
6621 bfd_put_32 (output_bfd, LWZ_11_11 + PPC_LO (plt), p);
6622 p += 4;
6623 bfd_put_32 (output_bfd, MTCTR_11, p);
6624 p += 4;
6625 bfd_put_32 (output_bfd, BCTR, p);
6626 p += 4;
6627 }
6628}
6629
bd6c6e2b
AM
6630/* Return true if symbol is defined statically. */
6631
6632static bfd_boolean
6633is_static_defined (struct elf_link_hash_entry *h)
6634{
6635 return ((h->root.type == bfd_link_hash_defined
6636 || h->root.type == bfd_link_hash_defweak)
6637 && h->root.u.def.section != NULL
6638 && h->root.u.def.section->output_section != NULL);
6639}
6640
2d0f3896
AM
6641/* If INSN is an opcode that may be used with an @tls operand, return
6642 the transformed insn for TLS optimisation, otherwise return 0. If
6643 REG is non-zero only match an insn with RB or RA equal to REG. */
6644
6645unsigned int
6646_bfd_elf_ppc_at_tls_transform (unsigned int insn, unsigned int reg)
6647{
6648 unsigned int rtra;
6649
6650 if ((insn & (0x3f << 26)) != 31 << 26)
6651 return 0;
6652
6653 if (reg == 0 || ((insn >> 11) & 0x1f) == reg)
6654 rtra = insn & ((1 << 26) - (1 << 16));
6655 else if (((insn >> 16) & 0x1f) == reg)
6656 rtra = (insn & (0x1f << 21)) | ((insn & (0x1f << 11)) << 5);
6657 else
6658 return 0;
6659
6660 if ((insn & (0x3ff << 1)) == 266 << 1)
6661 /* add -> addi. */
6662 insn = 14 << 26;
6663 else if ((insn & (0x1f << 1)) == 23 << 1
6664 && ((insn & (0x1f << 6)) < 14 << 6
6665 || ((insn & (0x1f << 6)) >= 16 << 6
6666 && (insn & (0x1f << 6)) < 24 << 6)))
6667 /* load and store indexed -> dform. */
6668 insn = (32 | ((insn >> 6) & 0x1f)) << 26;
6669 else if ((insn & (((0x1a << 5) | 0x1f) << 1)) == 21 << 1)
6670 /* ldx, ldux, stdx, stdux -> ld, ldu, std, stdu. */
6671 insn = ((58 | ((insn >> 6) & 4)) << 26) | ((insn >> 6) & 1);
6672 else if ((insn & (((0x1f << 5) | 0x1f) << 1)) == 341 << 1)
6673 /* lwax -> lwa. */
6674 insn = (58 << 26) | 2;
6675 else
6676 return 0;
6677 insn |= rtra;
6678 return insn;
6679}
6680
766bc656
AM
6681/* If INSN is an opcode that may be used with an @tprel operand, return
6682 the transformed insn for an undefined weak symbol, ie. with the
6683 thread pointer REG operand removed. Otherwise return 0. */
6684
6685unsigned int
6686_bfd_elf_ppc_at_tprel_transform (unsigned int insn, unsigned int reg)
6687{
6688 if ((insn & (0x1f << 16)) == reg << 16
6689 && ((insn & (0x3f << 26)) == 14u << 26 /* addi */
6690 || (insn & (0x3f << 26)) == 15u << 26 /* addis */
6691 || (insn & (0x3f << 26)) == 32u << 26 /* lwz */
6692 || (insn & (0x3f << 26)) == 34u << 26 /* lbz */
6693 || (insn & (0x3f << 26)) == 36u << 26 /* stw */
6694 || (insn & (0x3f << 26)) == 38u << 26 /* stb */
6695 || (insn & (0x3f << 26)) == 40u << 26 /* lhz */
6696 || (insn & (0x3f << 26)) == 42u << 26 /* lha */
6697 || (insn & (0x3f << 26)) == 44u << 26 /* sth */
6698 || (insn & (0x3f << 26)) == 46u << 26 /* lmw */
6699 || (insn & (0x3f << 26)) == 47u << 26 /* stmw */
6700 || (insn & (0x3f << 26)) == 48u << 26 /* lfs */
6701 || (insn & (0x3f << 26)) == 50u << 26 /* lfd */
6702 || (insn & (0x3f << 26)) == 52u << 26 /* stfs */
6703 || (insn & (0x3f << 26)) == 54u << 26 /* stfd */
6704 || ((insn & (0x3f << 26)) == 58u << 26 /* lwa,ld,lmd */
6705 && (insn & 3) != 1)
6706 || ((insn & (0x3f << 26)) == 62u << 26 /* std, stmd */
6707 && ((insn & 3) == 0 || (insn & 3) == 3))))
6708 {
6709 insn &= ~(0x1f << 16);
6710 }
6711 else if ((insn & (0x1f << 21)) == reg << 21
6712 && ((insn & (0x3e << 26)) == 24u << 26 /* ori, oris */
6713 || (insn & (0x3e << 26)) == 26u << 26 /* xori,xoris */
6714 || (insn & (0x3e << 26)) == 28u << 26 /* andi,andis */))
6715 {
6716 insn &= ~(0x1f << 21);
6717 insn |= (insn & (0x1f << 16)) << 5;
6718 if ((insn & (0x3e << 26)) == 26 << 26 /* xori,xoris */)
6719 insn -= 2 >> 26; /* convert to ori,oris */
6720 }
6721 else
6722 insn = 0;
6723 return insn;
6724}
6725
252b5132
RH
6726/* The RELOCATE_SECTION function is called by the ELF backend linker
6727 to handle the relocations for a section.
6728
6729 The relocs are always passed as Rela structures; if the section
6730 actually uses Rel structures, the r_addend field will always be
6731 zero.
6732
6733 This function is responsible for adjust the section contents as
6734 necessary, and (if using Rela relocs and generating a
1049f94e 6735 relocatable output file) adjusting the reloc addend as
252b5132
RH
6736 necessary.
6737
6738 This function does not have to worry about setting the reloc
6739 address or the reloc symbol index.
6740
6741 LOCAL_SYMS is a pointer to the swapped in local symbols.
6742
6743 LOCAL_SECTIONS is an array giving the section in the input file
6744 corresponding to the st_shndx field of each local symbol.
6745
6746 The global hash table entry for the global symbols can be found
6747 via elf_sym_hashes (input_bfd).
6748
1049f94e 6749 When generating relocatable output, this function must handle
252b5132
RH
6750 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
6751 going to be the section symbol corresponding to the output
6752 section, which means that the addend must be adjusted
6753 accordingly. */
6754
b34976b6 6755static bfd_boolean
55fd94b0
AM
6756ppc_elf_relocate_section (bfd *output_bfd,
6757 struct bfd_link_info *info,
6758 bfd *input_bfd,
6759 asection *input_section,
6760 bfd_byte *contents,
6761 Elf_Internal_Rela *relocs,
6762 Elf_Internal_Sym *local_syms,
6763 asection **local_sections)
252b5132 6764{
7619e7c7
AM
6765 Elf_Internal_Shdr *symtab_hdr;
6766 struct elf_link_hash_entry **sym_hashes;
6767 struct ppc_elf_link_hash_table *htab;
6768 Elf_Internal_Rela *rel;
6769 Elf_Internal_Rela *relend;
6770 Elf_Internal_Rela outrel;
a6aa5195 6771 asection *got2, *sreloc = NULL;
252b5132 6772 bfd_vma *local_got_offsets;
b34976b6 6773 bfd_boolean ret = TRUE;
4fe5ca5b 6774 bfd_vma d_offset = (bfd_big_endian (output_bfd) ? 2 : 0);
3348747a 6775 bfd_boolean is_vxworks_tls;
b34976b6 6776
252b5132 6777#ifdef DEBUG
d003868e
AM
6778 _bfd_error_handler ("ppc_elf_relocate_section called for %B section %A, "
6779 "%ld relocations%s",
6780 input_bfd, input_section,
6781 (long) input_section->reloc_count,
6782 (info->relocatable) ? " (relocatable)" : "");
252b5132
RH
6783#endif
6784
a6aa5195
AM
6785 got2 = bfd_get_section_by_name (input_bfd, ".got2");
6786
e47cd125 6787 /* Initialize howto table if not already done. */
8da6118f 6788 if (!ppc_elf_howto_table[R_PPC_ADDR32])
252b5132
RH
6789 ppc_elf_howto_init ();
6790
7619e7c7 6791 htab = ppc_elf_hash_table (info);
252b5132 6792 local_got_offsets = elf_local_got_offsets (input_bfd);
0ffa91dd 6793 symtab_hdr = &elf_symtab_hdr (input_bfd);
7619e7c7 6794 sym_hashes = elf_sym_hashes (input_bfd);
3348747a
NS
6795 /* We have to handle relocations in vxworks .tls_vars sections
6796 specially, because the dynamic loader is 'weird'. */
6797 is_vxworks_tls = (htab->is_vxworks && info->shared
6798 && !strcmp (input_section->output_section->name,
6799 ".tls_vars"));
7619e7c7
AM
6800 rel = relocs;
6801 relend = relocs + input_section->reloc_count;
252b5132
RH
6802 for (; rel < relend; rel++)
6803 {
7619e7c7
AM
6804 enum elf_ppc_reloc_type r_type;
6805 bfd_vma addend;
6806 bfd_reloc_status_type r;
6807 Elf_Internal_Sym *sym;
6808 asection *sec;
6809 struct elf_link_hash_entry *h;
6810 const char *sym_name;
252b5132
RH
6811 reloc_howto_type *howto;
6812 unsigned long r_symndx;
6813 bfd_vma relocation;
91d6fa6a 6814 bfd_vma branch_bit, from;
7619e7c7
AM
6815 bfd_boolean unresolved_reloc;
6816 bfd_boolean warned;
6817 unsigned int tls_type, tls_mask, tls_gd;
e054468f 6818 struct plt_entry **ifunc;
7619e7c7 6819
55fd94b0
AM
6820 r_type = ELF32_R_TYPE (rel->r_info);
6821 sym = NULL;
6822 sec = NULL;
6823 h = NULL;
7619e7c7
AM
6824 unresolved_reloc = FALSE;
6825 warned = FALSE;
252b5132 6826 r_symndx = ELF32_R_SYM (rel->r_info);
560e09e9 6827
252b5132
RH
6828 if (r_symndx < symtab_hdr->sh_info)
6829 {
6830 sym = local_syms + r_symndx;
6831 sec = local_sections[r_symndx];
26c61ae5 6832 sym_name = bfd_elf_sym_name (input_bfd, symtab_hdr, sym, sec);
252b5132 6833
8517fae7 6834 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
252b5132
RH
6835 }
6836 else
6837 {
b2a8e766
AM
6838 RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
6839 r_symndx, symtab_hdr, sym_hashes,
6840 h, sec, relocation,
6841 unresolved_reloc, warned);
9abc968f 6842
252b5132 6843 sym_name = h->root.root.string;
7619e7c7
AM
6844 }
6845
ab96bf03
AM
6846 if (sec != NULL && elf_discarded_section (sec))
6847 {
6848 /* For relocs against symbols from removed linkonce sections,
6849 or sections discarded by a linker script, we just want the
6850 section contents zeroed. Avoid any special processing. */
6851 howto = NULL;
6852 if (r_type < R_PPC_max)
6853 howto = ppc_elf_howto_table[r_type];
e4067dbb
DJ
6854 RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section,
6855 rel, relend, howto, contents);
ab96bf03
AM
6856 }
6857
6858 if (info->relocatable)
6859 {
6860 if (got2 != NULL
6861 && r_type == R_PPC_PLTREL24
6862 && rel->r_addend >= 32768)
6863 {
6864 /* R_PPC_PLTREL24 is rather special. If non-zero, the
6865 addend specifies the GOT pointer offset within .got2. */
6866 rel->r_addend += got2->output_offset;
6867 }
6868 continue;
6869 }
6870
7619e7c7
AM
6871 /* TLS optimizations. Replace instruction sequences and relocs
6872 based on information we collected in tls_optimize. We edit
6873 RELOCS so that --emit-relocs will output something sensible
6874 for the final instruction stream. */
6875 tls_mask = 0;
6876 tls_gd = 0;
727fc41e
AM
6877 if (h != NULL)
6878 tls_mask = ((struct ppc_elf_link_hash_entry *) h)->tls_mask;
6879 else if (local_got_offsets != NULL)
7619e7c7 6880 {
e054468f 6881 struct plt_entry **local_plt;
727fc41e 6882 char *lgot_masks;
e054468f
AM
6883 local_plt
6884 = (struct plt_entry **) (local_got_offsets + symtab_hdr->sh_info);
6885 lgot_masks = (char *) (local_plt + symtab_hdr->sh_info);
727fc41e 6886 tls_mask = lgot_masks[r_symndx];
7619e7c7
AM
6887 }
6888
6889 /* Ensure reloc mapping code below stays sane. */
6890 if ((R_PPC_GOT_TLSLD16 & 3) != (R_PPC_GOT_TLSGD16 & 3)
6891 || (R_PPC_GOT_TLSLD16_LO & 3) != (R_PPC_GOT_TLSGD16_LO & 3)
6892 || (R_PPC_GOT_TLSLD16_HI & 3) != (R_PPC_GOT_TLSGD16_HI & 3)
6893 || (R_PPC_GOT_TLSLD16_HA & 3) != (R_PPC_GOT_TLSGD16_HA & 3)
6894 || (R_PPC_GOT_TLSLD16 & 3) != (R_PPC_GOT_TPREL16 & 3)
6895 || (R_PPC_GOT_TLSLD16_LO & 3) != (R_PPC_GOT_TPREL16_LO & 3)
6896 || (R_PPC_GOT_TLSLD16_HI & 3) != (R_PPC_GOT_TPREL16_HI & 3)
6897 || (R_PPC_GOT_TLSLD16_HA & 3) != (R_PPC_GOT_TPREL16_HA & 3))
6898 abort ();
6899 switch (r_type)
6900 {
6901 default:
6902 break;
6903
6904 case R_PPC_GOT_TPREL16:
6905 case R_PPC_GOT_TPREL16_LO:
e054468f 6906 if ((tls_mask & TLS_TLS) != 0
7619e7c7
AM
6907 && (tls_mask & TLS_TPREL) == 0)
6908 {
6909 bfd_vma insn;
91d6fa6a 6910
4fe5ca5b 6911 insn = bfd_get_32 (output_bfd, contents + rel->r_offset - d_offset);
7619e7c7
AM
6912 insn &= 31 << 21;
6913 insn |= 0x3c020000; /* addis 0,2,0 */
4fe5ca5b 6914 bfd_put_32 (output_bfd, insn, contents + rel->r_offset - d_offset);
7619e7c7
AM
6915 r_type = R_PPC_TPREL16_HA;
6916 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
6917 }
6918 break;
6919
6920 case R_PPC_TLS:
e054468f 6921 if ((tls_mask & TLS_TLS) != 0
7619e7c7
AM
6922 && (tls_mask & TLS_TPREL) == 0)
6923 {
2d0f3896
AM
6924 bfd_vma insn;
6925
7619e7c7 6926 insn = bfd_get_32 (output_bfd, contents + rel->r_offset);
2d0f3896
AM
6927 insn = _bfd_elf_ppc_at_tls_transform (insn, 2);
6928 if (insn == 0)
7619e7c7 6929 abort ();
7619e7c7
AM
6930 bfd_put_32 (output_bfd, insn, contents + rel->r_offset);
6931 r_type = R_PPC_TPREL16_LO;
6932 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
4fe5ca5b 6933
7619e7c7 6934 /* Was PPC_TLS which sits on insn boundary, now
4fe5ca5b
GM
6935 PPC_TPREL16_LO which is at low-order half-word. */
6936 rel->r_offset += d_offset;
7619e7c7
AM
6937 }
6938 break;
6939
6940 case R_PPC_GOT_TLSGD16_HI:
6941 case R_PPC_GOT_TLSGD16_HA:
6942 tls_gd = TLS_TPRELGD;
e054468f 6943 if ((tls_mask & TLS_TLS) != 0 && (tls_mask & TLS_GD) == 0)
7619e7c7
AM
6944 goto tls_gdld_hi;
6945 break;
6946
6947 case R_PPC_GOT_TLSLD16_HI:
6948 case R_PPC_GOT_TLSLD16_HA:
e054468f 6949 if ((tls_mask & TLS_TLS) != 0 && (tls_mask & TLS_LD) == 0)
7619e7c7
AM
6950 {
6951 tls_gdld_hi:
6952 if ((tls_mask & tls_gd) != 0)
6953 r_type = (((r_type - (R_PPC_GOT_TLSGD16 & 3)) & 3)
6954 + R_PPC_GOT_TPREL16);
6955 else
6956 {
6957 bfd_put_32 (output_bfd, NOP, contents + rel->r_offset);
4fe5ca5b 6958 rel->r_offset -= d_offset;
7619e7c7
AM
6959 r_type = R_PPC_NONE;
6960 }
6961 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
6962 }
6963 break;
6964
6965 case R_PPC_GOT_TLSGD16:
6966 case R_PPC_GOT_TLSGD16_LO:
6967 tls_gd = TLS_TPRELGD;
e054468f 6968 if ((tls_mask & TLS_TLS) != 0 && (tls_mask & TLS_GD) == 0)
b7fcf6f6 6969 goto tls_ldgd_opt;
7619e7c7
AM
6970 break;
6971
6972 case R_PPC_GOT_TLSLD16:
6973 case R_PPC_GOT_TLSLD16_LO:
e054468f 6974 if ((tls_mask & TLS_TLS) != 0 && (tls_mask & TLS_LD) == 0)
7619e7c7 6975 {
3a71aa26 6976 unsigned int insn1, insn2;
b7fcf6f6 6977 bfd_vma offset;
7619e7c7 6978
b7fcf6f6 6979 tls_ldgd_opt:
727fc41e
AM
6980 offset = (bfd_vma) -1;
6981 /* If not using the newer R_PPC_TLSGD/LD to mark
6982 __tls_get_addr calls, we must trust that the call
6983 stays with its arg setup insns, ie. that the next
6984 reloc is the __tls_get_addr call associated with
6985 the current reloc. Edit both insns. */
6986 if (input_section->has_tls_get_addr_call
6987 && rel + 1 < relend
6988 && branch_reloc_hash_match (input_bfd, rel + 1,
6989 htab->tls_get_addr))
6990 offset = rel[1].r_offset;
b7fcf6f6
AM
6991 if ((tls_mask & tls_gd) != 0)
6992 {
6993 /* IE */
3a71aa26
AM
6994 insn1 = bfd_get_32 (output_bfd,
6995 contents + rel->r_offset - d_offset);
b7fcf6f6
AM
6996 insn1 &= (1 << 26) - 1;
6997 insn1 |= 32 << 26; /* lwz */
727fc41e
AM
6998 if (offset != (bfd_vma) -1)
6999 {
f58d5a2d 7000 rel[1].r_info = ELF32_R_INFO (STN_UNDEF, R_PPC_NONE);
727fc41e
AM
7001 insn2 = 0x7c631214; /* add 3,3,2 */
7002 bfd_put_32 (output_bfd, insn2, contents + offset);
7003 }
b7fcf6f6
AM
7004 r_type = (((r_type - (R_PPC_GOT_TLSGD16 & 3)) & 3)
7005 + R_PPC_GOT_TPREL16);
7006 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
7007 }
7008 else
7009 {
7010 /* LE */
7011 insn1 = 0x3c620000; /* addis 3,2,0 */
7619e7c7
AM
7012 if (tls_gd == 0)
7013 {
b7fcf6f6 7014 /* Was an LD reloc. */
1d483afe
AM
7015 for (r_symndx = 0;
7016 r_symndx < symtab_hdr->sh_info;
7017 r_symndx++)
7018 if (local_sections[r_symndx] == sec)
7019 break;
7020 if (r_symndx >= symtab_hdr->sh_info)
cf35638d 7021 r_symndx = STN_UNDEF;
b7fcf6f6 7022 rel->r_addend = htab->elf.tls_sec->vma + DTP_OFFSET;
cf35638d 7023 if (r_symndx != STN_UNDEF)
1d483afe
AM
7024 rel->r_addend -= (local_syms[r_symndx].st_value
7025 + sec->output_offset
7026 + sec->output_section->vma);
7619e7c7 7027 }
b7fcf6f6
AM
7028 r_type = R_PPC_TPREL16_HA;
7029 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
727fc41e
AM
7030 if (offset != (bfd_vma) -1)
7031 {
7032 rel[1].r_info = ELF32_R_INFO (r_symndx, R_PPC_TPREL16_LO);
7033 rel[1].r_offset = offset + d_offset;
7034 rel[1].r_addend = rel->r_addend;
7035 insn2 = 0x38630000; /* addi 3,3,0 */
7036 bfd_put_32 (output_bfd, insn2, contents + offset);
7037 }
b7fcf6f6
AM
7038 }
7039 bfd_put_32 (output_bfd, insn1,
7040 contents + rel->r_offset - d_offset);
b7fcf6f6
AM
7041 if (tls_gd == 0)
7042 {
7043 /* We changed the symbol on an LD reloc. Start over
7044 in order to get h, sym, sec etc. right. */
7045 rel--;
7046 continue;
7619e7c7 7047 }
252b5132 7048 }
7619e7c7 7049 break;
727fc41e
AM
7050
7051 case R_PPC_TLSGD:
e054468f 7052 if ((tls_mask & TLS_TLS) != 0 && (tls_mask & TLS_GD) == 0)
727fc41e
AM
7053 {
7054 unsigned int insn2;
7055 bfd_vma offset = rel->r_offset;
7056
7057 if ((tls_mask & TLS_TPRELGD) != 0)
7058 {
7059 /* IE */
7060 r_type = R_PPC_NONE;
7061 insn2 = 0x7c631214; /* add 3,3,2 */
7062 }
7063 else
7064 {
7065 /* LE */
7066 r_type = R_PPC_TPREL16_LO;
7067 rel->r_offset += d_offset;
7068 insn2 = 0x38630000; /* addi 3,3,0 */
7069 }
7070 rel->r_info = ELF32_R_INFO (r_symndx, r_type);
7071 bfd_put_32 (output_bfd, insn2, contents + offset);
7072 /* Zap the reloc on the _tls_get_addr call too. */
7073 BFD_ASSERT (offset == rel[1].r_offset);
f58d5a2d 7074 rel[1].r_info = ELF32_R_INFO (STN_UNDEF, R_PPC_NONE);
727fc41e
AM
7075 }
7076 break;
7077
7078 case R_PPC_TLSLD:
e054468f 7079 if ((tls_mask & TLS_TLS) != 0 && (tls_mask & TLS_LD) == 0)
727fc41e
AM
7080 {
7081 unsigned int insn2;
7082
7083 for (r_symndx = 0;
7084 r_symndx < symtab_hdr->sh_info;
7085 r_symndx++)
7086 if (local_sections[r_symndx] == sec)
7087 break;
7088 if (r_symndx >= symtab_hdr->sh_info)
cf35638d 7089 r_symndx = STN_UNDEF;
727fc41e 7090 rel->r_addend = htab->elf.tls_sec->vma + DTP_OFFSET;
cf35638d 7091 if (r_symndx != STN_UNDEF)
727fc41e
AM
7092 rel->r_addend -= (local_syms[r_symndx].st_value
7093 + sec->output_offset
7094 + sec->output_section->vma);
7095
7096 rel->r_info = ELF32_R_INFO (r_symndx, R_PPC_TPREL16_LO);
7097 rel->r_offset += d_offset;
7098 insn2 = 0x38630000; /* addi 3,3,0 */
7099 bfd_put_32 (output_bfd, insn2,
7100 contents + rel->r_offset - d_offset);
7101 /* Zap the reloc on the _tls_get_addr call too. */
7102 BFD_ASSERT (rel->r_offset - d_offset == rel[1].r_offset);
f58d5a2d 7103 rel[1].r_info = ELF32_R_INFO (STN_UNDEF, R_PPC_NONE);
727fc41e
AM
7104 rel--;
7105 continue;
7106 }
7107 break;
7619e7c7
AM
7108 }
7109
7110 /* Handle other relocations that tweak non-addend part of insn. */
7111 branch_bit = 0;
7112 switch (r_type)
7113 {
7114 default:
7115 break;
7116
7117 /* Branch taken prediction relocations. */
7118 case R_PPC_ADDR14_BRTAKEN:
7119 case R_PPC_REL14_BRTAKEN:
7120 branch_bit = BRANCH_PREDICT_BIT;
7121 /* Fall thru */
7122
4cc11e76 7123 /* Branch not taken prediction relocations. */
7619e7c7
AM
7124 case R_PPC_ADDR14_BRNTAKEN:
7125 case R_PPC_REL14_BRNTAKEN:
91d6fa6a
NC
7126 {
7127 bfd_vma insn;
7619e7c7 7128
91d6fa6a
NC
7129 insn = bfd_get_32 (output_bfd, contents + rel->r_offset);
7130 insn &= ~BRANCH_PREDICT_BIT;
7131 insn |= branch_bit;
7619e7c7 7132
91d6fa6a
NC
7133 from = (rel->r_offset
7134 + input_section->output_offset
7135 + input_section->output_section->vma);
7619e7c7 7136
91d6fa6a
NC
7137 /* Invert 'y' bit if not the default. */
7138 if ((bfd_signed_vma) (relocation + rel->r_addend - from) < 0)
7139 insn ^= BRANCH_PREDICT_BIT;
7140
7141 bfd_put_32 (output_bfd, insn, contents + rel->r_offset);
7142 break;
7143 }
252b5132
RH
7144 }
7145
e054468f 7146 ifunc = NULL;
25f23106 7147 if (!htab->is_vxworks)
e054468f 7148 {
de972ffa
AM
7149 struct plt_entry *ent;
7150
e054468f
AM
7151 if (h != NULL)
7152 {
7153 if (h->type == STT_GNU_IFUNC)
7154 ifunc = &h->plt.plist;
7155 }
de972ffa
AM
7156 else if (local_got_offsets != NULL
7157 && ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC)
e054468f 7158 {
de972ffa 7159 struct plt_entry **local_plt;
e054468f 7160
de972ffa
AM
7161 local_plt = (struct plt_entry **) (local_got_offsets
7162 + symtab_hdr->sh_info);
7163 ifunc = local_plt + r_symndx;
e054468f 7164 }
e054468f 7165
de972ffa
AM
7166 ent = NULL;
7167 if (ifunc != NULL
7168 && (!info->shared
7169 || is_branch_reloc (r_type)))
7170 {
7171 addend = 0;
a877a2b6 7172 if (r_type == R_PPC_PLTREL24 && info->shared)
de972ffa
AM
7173 addend = rel->r_addend;
7174 ent = find_plt_ent (ifunc, got2, addend);
7175 }
7176 if (ent != NULL)
7177 {
e054468f
AM
7178 if (h == NULL && (ent->plt.offset & 1) == 0)
7179 {
7180 Elf_Internal_Rela rela;
7181 bfd_byte *loc;
7182
7183 rela.r_offset = (htab->iplt->output_section->vma
7184 + htab->iplt->output_offset
7185 + ent->plt.offset);
7186 rela.r_info = ELF32_R_INFO (0, R_PPC_IRELATIVE);
7187 rela.r_addend = relocation;
25f23106
AM
7188 loc = htab->reliplt->contents;
7189 loc += (htab->reliplt->reloc_count++
7190 * sizeof (Elf32_External_Rela));
e054468f
AM
7191 bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
7192
7193 ent->plt.offset |= 1;
7194 }
7195 if (h == NULL && (ent->glink_offset & 1) == 0)
7196 {
a7f2871e
AM
7197 unsigned char *p = ((unsigned char *) htab->glink->contents
7198 + ent->glink_offset);
7199 write_glink_stub (ent, htab->iplt, p, info);
e054468f
AM
7200 ent->glink_offset |= 1;
7201 }
7202
7203 unresolved_reloc = FALSE;
7204 if (htab->plt_type == PLT_NEW
7205 || !htab->elf.dynamic_sections_created
7206 || h == NULL)
7207 relocation = (htab->glink->output_section->vma
7208 + htab->glink->output_offset
7209 + (ent->glink_offset & ~1));
7210 else
7211 relocation = (htab->plt->output_section->vma
7212 + htab->plt->output_offset
7213 + ent->plt.offset);
7214 }
7215 }
7216
7619e7c7
AM
7217 addend = rel->r_addend;
7218 tls_type = 0;
7219 howto = NULL;
55fd94b0
AM
7220 if (r_type < R_PPC_max)
7221 howto = ppc_elf_howto_table[r_type];
7619e7c7 7222 switch (r_type)
252b5132
RH
7223 {
7224 default:
7619e7c7 7225 (*_bfd_error_handler)
d003868e
AM
7226 (_("%B: unknown relocation type %d for symbol %s"),
7227 input_bfd, (int) r_type, sym_name);
252b5132
RH
7228
7229 bfd_set_error (bfd_error_bad_value);
b34976b6 7230 ret = FALSE;
252b5132
RH
7231 continue;
7232
7619e7c7
AM
7233 case R_PPC_NONE:
7234 case R_PPC_TLS:
727fc41e
AM
7235 case R_PPC_TLSGD:
7236 case R_PPC_TLSLD:
7619e7c7
AM
7237 case R_PPC_EMB_MRKREF:
7238 case R_PPC_GNU_VTINHERIT:
7239 case R_PPC_GNU_VTENTRY:
7595d193
L
7240 continue;
7241
7619e7c7
AM
7242 /* GOT16 relocations. Like an ADDR16 using the symbol's
7243 address in the GOT as relocation value instead of the
7244 symbol's value itself. Also, create a GOT entry for the
7245 symbol and put the symbol value there. */
7246 case R_PPC_GOT_TLSGD16:
7247 case R_PPC_GOT_TLSGD16_LO:
7248 case R_PPC_GOT_TLSGD16_HI:
7249 case R_PPC_GOT_TLSGD16_HA:
7250 tls_type = TLS_TLS | TLS_GD;
7251 goto dogot;
7252
7253 case R_PPC_GOT_TLSLD16:
7254 case R_PPC_GOT_TLSLD16_LO:
7255 case R_PPC_GOT_TLSLD16_HI:
7256 case R_PPC_GOT_TLSLD16_HA:
7257 tls_type = TLS_TLS | TLS_LD;
7258 goto dogot;
7259
7260 case R_PPC_GOT_TPREL16:
7261 case R_PPC_GOT_TPREL16_LO:
7262 case R_PPC_GOT_TPREL16_HI:
7263 case R_PPC_GOT_TPREL16_HA:
7264 tls_type = TLS_TLS | TLS_TPREL;
7265 goto dogot;
7266
7267 case R_PPC_GOT_DTPREL16:
7268 case R_PPC_GOT_DTPREL16_LO:
7269 case R_PPC_GOT_DTPREL16_HI:
7270 case R_PPC_GOT_DTPREL16_HA:
7271 tls_type = TLS_TLS | TLS_DTPREL;
7272 goto dogot;
7273
7274 case R_PPC_GOT16:
7275 case R_PPC_GOT16_LO:
7276 case R_PPC_GOT16_HI:
7277 case R_PPC_GOT16_HA:
727fc41e 7278 tls_mask = 0;
7619e7c7
AM
7279 dogot:
7280 {
7281 /* Relocation is to the entry for this symbol in the global
7282 offset table. */
7283 bfd_vma off;
7284 bfd_vma *offp;
7285 unsigned long indx;
7286
7287 if (htab->got == NULL)
7288 abort ();
7289
7290 indx = 0;
7291 if (tls_type == (TLS_TLS | TLS_LD)
d881513a 7292 && (h == NULL
f5385ebf 7293 || !h->def_dynamic))
7619e7c7
AM
7294 offp = &htab->tlsld_got.offset;
7295 else if (h != NULL)
7296 {
7297 bfd_boolean dyn;
7298 dyn = htab->elf.dynamic_sections_created;
ee05f2fe 7299 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
7619e7c7
AM
7300 || (info->shared
7301 && SYMBOL_REFERENCES_LOCAL (info, h)))
7302 /* This is actually a static link, or it is a
7303 -Bsymbolic link and the symbol is defined
7304 locally, or the symbol was forced to be local
7305 because of a version file. */
7306 ;
7307 else
7308 {
7309 indx = h->dynindx;
7310 unresolved_reloc = FALSE;
7311 }
7312 offp = &h->got.offset;
7313 }
7314 else
7315 {
7316 if (local_got_offsets == NULL)
7317 abort ();
7318 offp = &local_got_offsets[r_symndx];
7319 }
7320
7321 /* The offset must always be a multiple of 4. We use the
7322 least significant bit to record whether we have already
7323 processed this entry. */
7324 off = *offp;
7325 if ((off & 1) != 0)
7326 off &= ~1;
7327 else
7328 {
70bccea4
AM
7329 unsigned int tls_m = (tls_mask
7330 & (TLS_LD | TLS_GD | TLS_DTPREL
7331 | TLS_TPREL | TLS_TPRELGD));
7332
7333 if (offp == &htab->tlsld_got.offset)
7334 tls_m = TLS_LD;
7335 else if (h == NULL
f5385ebf 7336 || !h->def_dynamic)
70bccea4
AM
7337 tls_m &= ~TLS_LD;
7338
7339 /* We might have multiple got entries for this sym.
7340 Initialize them all. */
7341 do
7619e7c7 7342 {
70bccea4
AM
7343 int tls_ty = 0;
7344
7345 if ((tls_m & TLS_LD) != 0)
7619e7c7 7346 {
70bccea4
AM
7347 tls_ty = TLS_TLS | TLS_LD;
7348 tls_m &= ~TLS_LD;
7349 }
7350 else if ((tls_m & TLS_GD) != 0)
7351 {
7352 tls_ty = TLS_TLS | TLS_GD;
7353 tls_m &= ~TLS_GD;
7354 }
7355 else if ((tls_m & TLS_DTPREL) != 0)
7356 {
7357 tls_ty = TLS_TLS | TLS_DTPREL;
7358 tls_m &= ~TLS_DTPREL;
7359 }
7360 else if ((tls_m & (TLS_TPREL | TLS_TPRELGD)) != 0)
7361 {
7362 tls_ty = TLS_TLS | TLS_TPREL;
7363 tls_m = 0;
7619e7c7 7364 }
7619e7c7 7365
70bccea4 7366 /* Generate relocs for the dynamic linker. */
4e795f50 7367 if ((info->shared || indx != 0)
d6e14abc
AM
7368 && (offp == &htab->tlsld_got.offset
7369 || h == NULL
4e795f50
AM
7370 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
7371 || h->root.type != bfd_link_hash_undefweak))
7619e7c7 7372 {
91e21fb7 7373 asection *rsec = htab->relgot;
91d6fa6a 7374 bfd_byte * loc;
91e21fb7 7375
70bccea4
AM
7376 outrel.r_offset = (htab->got->output_section->vma
7377 + htab->got->output_offset
7378 + off);
e515b051 7379 outrel.r_addend = 0;
70bccea4
AM
7380 if (tls_ty & (TLS_LD | TLS_GD))
7381 {
7382 outrel.r_info = ELF32_R_INFO (indx, R_PPC_DTPMOD32);
70bccea4
AM
7383 if (tls_ty == (TLS_TLS | TLS_GD))
7384 {
25f23106
AM
7385 loc = rsec->contents;
7386 loc += (rsec->reloc_count++
70bccea4
AM
7387 * sizeof (Elf32_External_Rela));
7388 bfd_elf32_swap_reloca_out (output_bfd,
7389 &outrel, loc);
e515b051 7390 outrel.r_offset += 4;
70bccea4
AM
7391 outrel.r_info
7392 = ELF32_R_INFO (indx, R_PPC_DTPREL32);
70bccea4
AM
7393 }
7394 }
7395 else if (tls_ty == (TLS_TLS | TLS_DTPREL))
7396 outrel.r_info = ELF32_R_INFO (indx, R_PPC_DTPREL32);
7397 else if (tls_ty == (TLS_TLS | TLS_TPREL))
7398 outrel.r_info = ELF32_R_INFO (indx, R_PPC_TPREL32);
25f23106 7399 else if (indx != 0)
70bccea4 7400 outrel.r_info = ELF32_R_INFO (indx, R_PPC_GLOB_DAT);
25f23106
AM
7401 else if (ifunc != NULL)
7402 outrel.r_info = ELF32_R_INFO (0, R_PPC_IRELATIVE);
7403 else
7404 outrel.r_info = ELF32_R_INFO (0, R_PPC_RELATIVE);
d6e14abc 7405 if (indx == 0 && tls_ty != (TLS_TLS | TLS_LD))
e515b051
AM
7406 {
7407 outrel.r_addend += relocation;
7408 if (tls_ty & (TLS_GD | TLS_DTPREL | TLS_TPREL))
e1918d23 7409 outrel.r_addend -= htab->elf.tls_sec->vma;
e515b051 7410 }
25f23106
AM
7411 loc = rsec->contents;
7412 loc += (rsec->reloc_count++
70bccea4
AM
7413 * sizeof (Elf32_External_Rela));
7414 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
7619e7c7
AM
7415 }
7416
70bccea4
AM
7417 /* Init the .got section contents if we're not
7418 emitting a reloc. */
7419 else
7619e7c7 7420 {
70bccea4
AM
7421 bfd_vma value = relocation;
7422
7b609f53
AM
7423 if (tls_ty == (TLS_TLS | TLS_LD))
7424 value = 1;
7425 else if (tls_ty != 0)
70bccea4 7426 {
e1918d23 7427 value -= htab->elf.tls_sec->vma + DTP_OFFSET;
7b609f53 7428 if (tls_ty == (TLS_TLS | TLS_TPREL))
70bccea4 7429 value += DTP_OFFSET - TP_OFFSET;
70bccea4 7430
7b609f53
AM
7431 if (tls_ty == (TLS_TLS | TLS_GD))
7432 {
7433 bfd_put_32 (output_bfd, value,
7434 htab->got->contents + off + 4);
7435 value = 1;
7436 }
70bccea4 7437 }
70bccea4
AM
7438 bfd_put_32 (output_bfd, value,
7439 htab->got->contents + off);
7619e7c7 7440 }
70bccea4
AM
7441
7442 off += 4;
7443 if (tls_ty & (TLS_LD | TLS_GD))
7444 off += 4;
7619e7c7 7445 }
70bccea4
AM
7446 while (tls_m != 0);
7447
7448 off = *offp;
7449 *offp = off | 1;
7619e7c7
AM
7450 }
7451
7452 if (off >= (bfd_vma) -2)
7453 abort ();
7454
70bccea4
AM
7455 if ((tls_type & TLS_TLS) != 0)
7456 {
7457 if (tls_type != (TLS_TLS | TLS_LD))
7458 {
7459 if ((tls_mask & TLS_LD) != 0
7460 && !(h == NULL
f5385ebf 7461 || !h->def_dynamic))
70bccea4
AM
7462 off += 8;
7463 if (tls_type != (TLS_TLS | TLS_GD))
7464 {
7465 if ((tls_mask & TLS_GD) != 0)
7466 off += 8;
7467 if (tls_type != (TLS_TLS | TLS_DTPREL))
7468 {
7469 if ((tls_mask & TLS_DTPREL) != 0)
7470 off += 4;
7471 }
7472 }
7473 }
7474 }
7475
e87d4038
AM
7476 relocation = (htab->got->output_section->vma
7477 + htab->got->output_offset
7478 + off
7479 - SYM_VAL (htab->elf.hgot));
7619e7c7
AM
7480
7481 /* Addends on got relocations don't make much sense.
7482 x+off@got is actually x@got+off, and since the got is
7483 generated by a hash table traversal, the value in the
7484 got at entry m+n bears little relation to the entry m. */
7485 if (addend != 0)
7486 (*_bfd_error_handler)
d003868e
AM
7487 (_("%B(%A+0x%lx): non-zero addend on %s reloc against `%s'"),
7488 input_bfd,
7489 input_section,
7619e7c7 7490 (long) rel->r_offset,
7b609f53 7491 howto->name,
7619e7c7
AM
7492 sym_name);
7493 }
70bccea4 7494 break;
7619e7c7 7495
252b5132 7496 /* Relocations that need no special processing. */
7619e7c7 7497 case R_PPC_LOCAL24PC:
252b5132
RH
7498 /* It makes no sense to point a local relocation
7499 at a symbol not in this object. */
7b609f53 7500 if (unresolved_reloc)
252b5132 7501 {
464e1740
ILT
7502 if (! (*info->callbacks->undefined_symbol) (info,
7503 h->root.root.string,
7504 input_bfd,
7505 input_section,
5cc7c785 7506 rel->r_offset,
b34976b6
AM
7507 TRUE))
7508 return FALSE;
252b5132
RH
7509 continue;
7510 }
7511 break;
7512
7619e7c7
AM
7513 case R_PPC_DTPREL16:
7514 case R_PPC_DTPREL16_LO:
7515 case R_PPC_DTPREL16_HI:
7516 case R_PPC_DTPREL16_HA:
e1918d23 7517 addend -= htab->elf.tls_sec->vma + DTP_OFFSET;
7619e7c7
AM
7518 break;
7519
70bccea4
AM
7520 /* Relocations that may need to be propagated if this is a shared
7521 object. */
7619e7c7
AM
7522 case R_PPC_TPREL16:
7523 case R_PPC_TPREL16_LO:
7524 case R_PPC_TPREL16_HI:
7525 case R_PPC_TPREL16_HA:
766bc656
AM
7526 if (h != NULL
7527 && h->root.type == bfd_link_hash_undefweak
7528 && h->dynindx == -1)
7529 {
7530 /* Make this relocation against an undefined weak symbol
7531 resolve to zero. This is really just a tweak, since
7532 code using weak externs ought to check that they are
7533 defined before using them. */
7534 bfd_byte *p = contents + rel->r_offset - d_offset;
7535 unsigned int insn = bfd_get_32 (output_bfd, p);
7536 insn = _bfd_elf_ppc_at_tprel_transform (insn, 2);
7537 if (insn != 0)
7538 bfd_put_32 (output_bfd, insn, p);
7539 break;
7540 }
e1918d23 7541 addend -= htab->elf.tls_sec->vma + TP_OFFSET;
7619e7c7
AM
7542 /* The TPREL16 relocs shouldn't really be used in shared
7543 libs as they will result in DT_TEXTREL being set, but
7544 support them anyway. */
7545 goto dodyn;
7546
7547 case R_PPC_TPREL32:
e1918d23 7548 addend -= htab->elf.tls_sec->vma + TP_OFFSET;
7619e7c7
AM
7549 goto dodyn;
7550
7551 case R_PPC_DTPREL32:
e1918d23 7552 addend -= htab->elf.tls_sec->vma + DTP_OFFSET;
7619e7c7
AM
7553 goto dodyn;
7554
e515b051
AM
7555 case R_PPC_DTPMOD32:
7556 relocation = 1;
7557 addend = 0;
7558 goto dodyn;
7559
d7128ce4
AM
7560 case R_PPC_REL16:
7561 case R_PPC_REL16_LO:
7562 case R_PPC_REL16_HI:
7563 case R_PPC_REL16_HA:
7564 break;
7565
7619e7c7 7566 case R_PPC_REL32:
625af618
AM
7567 if (h == NULL || h == htab->elf.hgot)
7568 break;
7569 /* fall through */
7570
7571 case R_PPC_ADDR32:
7572 case R_PPC_ADDR16:
7573 case R_PPC_ADDR16_LO:
7574 case R_PPC_ADDR16_HI:
7575 case R_PPC_ADDR16_HA:
7576 case R_PPC_UADDR32:
7577 case R_PPC_UADDR16:
7578 goto dodyn;
7579
7580 case R_PPC_REL24:
7619e7c7
AM
7581 case R_PPC_REL14:
7582 case R_PPC_REL14_BRTAKEN:
7583 case R_PPC_REL14_BRNTAKEN:
252b5132
RH
7584 /* If these relocations are not to a named symbol, they can be
7585 handled right here, no need to bother the dynamic linker. */
89200bf8 7586 if (SYMBOL_CALLS_LOCAL (info, h)
3b36f7e6 7587 || h == htab->elf.hgot)
252b5132 7588 break;
70bccea4 7589 /* fall through */
252b5132 7590
7619e7c7 7591 case R_PPC_ADDR24:
7619e7c7
AM
7592 case R_PPC_ADDR14:
7593 case R_PPC_ADDR14_BRTAKEN:
7594 case R_PPC_ADDR14_BRNTAKEN:
625af618
AM
7595 if (h != NULL && !info->shared)
7596 break;
7597 /* fall through */
7598
7619e7c7 7599 dodyn:
3348747a
NS
7600 if ((input_section->flags & SEC_ALLOC) == 0
7601 || is_vxworks_tls)
c87b5a93 7602 break;
c87b5a93 7603
ee05f2fe 7604 if ((info->shared
89200bf8
AM
7605 && !(h != NULL
7606 && ((h->root.type == bfd_link_hash_undefined
7607 && (ELF_ST_VISIBILITY (h->other) == STV_HIDDEN
7608 || ELF_ST_VISIBILITY (h->other) == STV_INTERNAL))
7609 || (h->root.type == bfd_link_hash_undefweak
7610 && ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)))
1d483afe 7611 && (must_be_dyn_reloc (info, r_type)
f6c52c13 7612 || !SYMBOL_CALLS_LOCAL (info, h)))
ee05f2fe
AM
7613 || (ELIMINATE_COPY_RELOCS
7614 && !info->shared
ee05f2fe
AM
7615 && h != NULL
7616 && h->dynindx != -1
f5385ebf 7617 && !h->non_got_ref
de972ffa 7618 && !h->def_regular))
252b5132 7619 {
0bb2d96a 7620 int skip;
91d6fa6a 7621 bfd_byte * loc;
252b5132 7622#ifdef DEBUG
55fd94b0
AM
7623 fprintf (stderr, "ppc_elf_relocate_section needs to "
7624 "create relocation for %s\n",
70bccea4
AM
7625 (h && h->root.root.string
7626 ? h->root.root.string : "<unknown>"));
252b5132
RH
7627#endif
7628
7629 /* When generating a shared object, these relocations
70bccea4
AM
7630 are copied into the output file to be resolved at run
7631 time. */
252b5132
RH
7632 if (sreloc == NULL)
7633 {
25f23106
AM
7634 sreloc = elf_section_data (input_section)->sreloc;
7635 if (!htab->elf.dynamic_sections_created)
7636 sreloc = htab->reliplt;
83bac4b0 7637 if (sreloc == NULL)
b34976b6 7638 return FALSE;
252b5132
RH
7639 }
7640
0bb2d96a 7641 skip = 0;
5b914448
AM
7642 outrel.r_offset = _bfd_elf_section_offset (output_bfd, info,
7643 input_section,
7644 rel->r_offset);
0bb2d96a
JJ
7645 if (outrel.r_offset == (bfd_vma) -1
7646 || outrel.r_offset == (bfd_vma) -2)
7647 skip = (int) outrel.r_offset;
252b5132
RH
7648 outrel.r_offset += (input_section->output_section->vma
7649 + input_section->output_offset);
7650
7651 if (skip)
7652 memset (&outrel, 0, sizeof outrel);
89200bf8
AM
7653 else if ((h != NULL
7654 && (h->root.type == bfd_link_hash_undefined
7655 || h->root.type == bfd_link_hash_undefweak))
7656 || !SYMBOL_REFERENCES_LOCAL (info, h))
252b5132 7657 {
7619e7c7 7658 unresolved_reloc = FALSE;
252b5132
RH
7659 outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
7660 outrel.r_addend = rel->r_addend;
7661 }
7662 else
7663 {
47388f4c
AM
7664 outrel.r_addend = relocation + rel->r_addend;
7665
25f23106 7666 if (r_type != R_PPC_ADDR32)
252b5132 7667 {
89200bf8 7668 long indx = 0;
252b5132 7669
25f23106
AM
7670 if (ifunc != NULL)
7671 {
7672 /* If we get here when building a static
7673 executable, then the libc startup function
7674 responsible for applying indirect function
7675 relocations is going to complain about
7676 the reloc type.
7677 If we get here when building a dynamic
7678 executable, it will be because we have
7679 a text relocation. The dynamic loader
7680 will set the text segment writable and
7681 non-executable to apply text relocations.
7682 So we'll segfault when trying to run the
7683 indirection function to resolve the reloc. */
7684 (*_bfd_error_handler)
7685 (_("%B(%A+0x%lx): relocation %s for indirect "
7686 "function %s unsupported"),
7687 input_bfd,
7688 input_section,
7689 (long) rel->r_offset,
7690 howto->name,
7691 sym_name);
7692 ret = FALSE;
7693 }
cf35638d 7694 else if (r_symndx == STN_UNDEF || bfd_is_abs_section (sec))
89200bf8 7695 ;
252b5132
RH
7696 else if (sec == NULL || sec->owner == NULL)
7697 {
7698 bfd_set_error (bfd_error_bad_value);
89200bf8 7699 ret = FALSE;
252b5132
RH
7700 }
7701 else
7702 {
7703 asection *osec;
7704
47388f4c
AM
7705 /* We are turning this relocation into one
7706 against a section symbol. It would be
7707 proper to subtract the symbol's value,
7708 osec->vma, from the emitted reloc addend,
25f23106
AM
7709 but ld.so expects buggy relocs.
7710 FIXME: Why not always use a zero index? */
252b5132
RH
7711 osec = sec->output_section;
7712 indx = elf_section_data (osec)->dynindx;
74541ad4
AM
7713 if (indx == 0)
7714 {
7715 osec = htab->elf.text_index_section;
7716 indx = elf_section_data (osec)->dynindx;
7717 }
7718 BFD_ASSERT (indx != 0);
252b5132 7719#ifdef DEBUG
74541ad4 7720 if (indx == 0)
e460dd0d 7721 printf ("indx=%ld section=%s flags=%08x name=%s\n",
55fd94b0
AM
7722 indx, osec->name, osec->flags,
7723 h->root.root.string);
252b5132
RH
7724#endif
7725 }
7726
7727 outrel.r_info = ELF32_R_INFO (indx, r_type);
252b5132 7728 }
25f23106
AM
7729 else if (ifunc != NULL)
7730 outrel.r_info = ELF32_R_INFO (0, R_PPC_IRELATIVE);
7731 else
7732 outrel.r_info = ELF32_R_INFO (0, R_PPC_RELATIVE);
252b5132
RH
7733 }
7734
947216bf
AM
7735 loc = sreloc->contents;
7736 loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rela);
7737 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
252b5132 7738
2243deae 7739 if (skip == -1)
252b5132 7740 continue;
2243deae
L
7741
7742 /* This reloc will be computed at runtime. We clear the memory
7743 so that it contains predictable value. */
7744 if (! skip
7745 && ((input_section->flags & SEC_ALLOC) != 0
7746 || ELF32_R_TYPE (outrel.r_info) != R_PPC_RELATIVE))
7747 {
7748 relocation = howto->pc_relative ? outrel.r_offset : 0;
7749 addend = 0;
7750 break;
7751 }
252b5132 7752 }
252b5132
RH
7753 break;
7754
32af9f6e
AM
7755 case R_PPC_RELAX_PLT:
7756 case R_PPC_RELAX_PLTREL24:
de972ffa
AM
7757 if (h != NULL)
7758 {
32af9f6e
AM
7759 struct plt_entry *ent;
7760 bfd_vma got2_addend = 0;
7761
7762 if (r_type == R_PPC_RELAX_PLTREL24)
7763 {
7764 if (info->shared)
7765 got2_addend = addend;
7766 addend = 0;
7767 }
7768 ent = find_plt_ent (&h->plt.plist, got2, got2_addend);
de972ffa
AM
7769 if (htab->plt_type == PLT_NEW)
7770 relocation = (htab->glink->output_section->vma
7771 + htab->glink->output_offset
7772 + ent->glink_offset);
7773 else
7774 relocation = (htab->plt->output_section->vma
7775 + htab->plt->output_offset
7776 + ent->plt.offset);
7777 }
b4a38de6
AM
7778 /* Fall thru */
7779
32af9f6e
AM
7780 case R_PPC_RELAX:
7781 if (info->shared)
7782 relocation -= (input_section->output_section->vma
7783 + input_section->output_offset
7784 + rel->r_offset - 4);
b4a38de6 7785
9abc968f
AM
7786 {
7787 unsigned long t0;
7788 unsigned long t1;
7789
7790 t0 = bfd_get_32 (output_bfd, contents + rel->r_offset);
7791 t1 = bfd_get_32 (output_bfd, contents + rel->r_offset + 4);
7792
7793 /* We're clearing the bits for R_PPC_ADDR16_HA
7794 and R_PPC_ADDR16_LO here. */
7795 t0 &= ~0xffff;
7796 t1 &= ~0xffff;
7797
7798 /* t0 is HA, t1 is LO */
7799 relocation += addend;
7800 t0 |= ((relocation + 0x8000) >> 16) & 0xffff;
7801 t1 |= relocation & 0xffff;
7802
7803 bfd_put_32 (output_bfd, t0, contents + rel->r_offset);
7804 bfd_put_32 (output_bfd, t1, contents + rel->r_offset + 4);
9bc4e62b
NS
7805
7806 /* Rewrite the reloc and convert one of the trailing nop
7807 relocs to describe this relocation. */
7808 BFD_ASSERT (ELF32_R_TYPE (relend[-1].r_info) == R_PPC_NONE);
7809 /* The relocs are at the bottom 2 bytes */
7810 rel[0].r_offset += 2;
7811 memmove (rel + 1, rel, (relend - rel - 1) * sizeof (*rel));
7812 rel[0].r_info = ELF32_R_INFO (r_symndx, R_PPC_ADDR16_HA);
7813 rel[1].r_offset += 4;
7814 rel[1].r_info = ELF32_R_INFO (r_symndx, R_PPC_ADDR16_LO);
7815 rel++;
9abc968f 7816 }
8517fae7 7817 continue;
deaaf2f3 7818
70bccea4 7819 /* Indirect .sdata relocation. */
7619e7c7 7820 case R_PPC_EMB_SDAI16:
c9a2f333 7821 BFD_ASSERT (htab->sdata[0].section != NULL);
bd6c6e2b
AM
7822 if (!is_static_defined (htab->sdata[0].sym))
7823 {
7824 unresolved_reloc = TRUE;
7825 break;
7826 }
7619e7c7 7827 relocation
76750a2f
AM
7828 = elf_finish_pointer_linker_section (input_bfd, &htab->sdata[0],
7829 h, relocation, rel);
bd6c6e2b 7830 addend = 0;
252b5132
RH
7831 break;
7832
70bccea4 7833 /* Indirect .sdata2 relocation. */
7619e7c7 7834 case R_PPC_EMB_SDA2I16:
c9a2f333 7835 BFD_ASSERT (htab->sdata[1].section != NULL);
bd6c6e2b
AM
7836 if (!is_static_defined (htab->sdata[1].sym))
7837 {
7838 unresolved_reloc = TRUE;
7839 break;
7840 }
7619e7c7 7841 relocation
76750a2f
AM
7842 = elf_finish_pointer_linker_section (input_bfd, &htab->sdata[1],
7843 h, relocation, rel);
bd6c6e2b 7844 addend = 0;
252b5132
RH
7845 break;
7846
70bccea4
AM
7847 /* Handle the TOC16 reloc. We want to use the offset within the .got
7848 section, not the actual VMA. This is appropriate when generating
7849 an embedded ELF object, for which the .got section acts like the
7850 AIX .toc section. */
7619e7c7 7851 case R_PPC_TOC16: /* phony GOT16 relocations */
3b4f3a11
AM
7852 if (sec == NULL || sec->output_section == NULL)
7853 {
7854 unresolved_reloc = TRUE;
7855 break;
7856 }
7857 BFD_ASSERT (strcmp (bfd_get_section_name (abfd, sec), ".got") == 0
f12123c0 7858 || strcmp (bfd_get_section_name (abfd, sec), ".cgot") == 0);
252b5132 7859
3b4f3a11 7860 addend -= sec->output_section->vma + sec->output_offset + 0x8000;
252b5132
RH
7861 break;
7862
7619e7c7 7863 case R_PPC_PLTREL24:
e054468f 7864 if (h == NULL || ifunc != NULL)
6d78d0b9 7865 break;
252b5132 7866 /* Relocation is to the entry for this symbol in the
70bccea4 7867 procedure linkage table. */
a6aa5195 7868 {
a877a2b6
AM
7869 struct plt_entry *ent = find_plt_ent (&h->plt.plist, got2,
7870 info->shared ? addend : 0);
a6aa5195
AM
7871 addend = 0;
7872 if (ent == NULL
7873 || htab->plt == NULL)
7874 {
7875 /* We didn't make a PLT entry for this symbol. This
7876 happens when statically linking PIC code, or when
7877 using -Bsymbolic. */
7878 break;
7879 }
252b5132 7880
a6aa5195 7881 unresolved_reloc = FALSE;
4a3dc543 7882 if (htab->plt_type == PLT_NEW)
a6aa5195
AM
7883 relocation = (htab->glink->output_section->vma
7884 + htab->glink->output_offset
7885 + ent->glink_offset);
7886 else
7887 relocation = (htab->plt->output_section->vma
7888 + htab->plt->output_offset
7889 + ent->plt.offset);
7890 }
8da6118f 7891 break;
252b5132 7892
70bccea4 7893 /* Relocate against _SDA_BASE_. */
7619e7c7 7894 case R_PPC_SDAREL16:
252b5132
RH
7895 {
7896 const char *name;
bd6c6e2b 7897 struct elf_link_hash_entry *sda = htab->sdata[0].sym;
252b5132 7898
bd6c6e2b
AM
7899 if (sec == NULL
7900 || sec->output_section == NULL
7901 || !is_static_defined (sda))
3b4f3a11
AM
7902 {
7903 unresolved_reloc = TRUE;
7904 break;
7905 }
bd6c6e2b 7906 addend -= SYM_VAL (sda);
3b4f3a11 7907
252b5132 7908 name = bfd_get_section_name (abfd, sec->output_section);
0112cd26 7909 if (! ((CONST_STRNEQ (name, ".sdata")
5f819128 7910 && (name[6] == 0 || name[6] == '.'))
0112cd26 7911 || (CONST_STRNEQ (name, ".sbss")
5f819128 7912 && (name[5] == 0 || name[5] == '.'))))
252b5132 7913 {
55fd94b0 7914 (*_bfd_error_handler)
d003868e 7915 (_("%B: the target (%s) of a %s relocation is "
55fd94b0 7916 "in the wrong output section (%s)"),
d003868e 7917 input_bfd,
55fd94b0
AM
7918 sym_name,
7919 howto->name,
7920 name);
252b5132 7921 }
252b5132
RH
7922 }
7923 break;
7924
70bccea4 7925 /* Relocate against _SDA2_BASE_. */
7619e7c7 7926 case R_PPC_EMB_SDA2REL:
252b5132
RH
7927 {
7928 const char *name;
bd6c6e2b 7929 struct elf_link_hash_entry *sda = htab->sdata[1].sym;
252b5132 7930
bd6c6e2b
AM
7931 if (sec == NULL
7932 || sec->output_section == NULL
7933 || !is_static_defined (sda))
3b4f3a11
AM
7934 {
7935 unresolved_reloc = TRUE;
7936 break;
7937 }
bd6c6e2b 7938 addend -= SYM_VAL (sda);
3b4f3a11 7939
252b5132 7940 name = bfd_get_section_name (abfd, sec->output_section);
0112cd26
NC
7941 if (! (CONST_STRNEQ (name, ".sdata2")
7942 || CONST_STRNEQ (name, ".sbss2")))
252b5132 7943 {
55fd94b0 7944 (*_bfd_error_handler)
d003868e 7945 (_("%B: the target (%s) of a %s relocation is "
55fd94b0 7946 "in the wrong output section (%s)"),
d003868e 7947 input_bfd,
55fd94b0
AM
7948 sym_name,
7949 howto->name,
7950 name);
252b5132 7951 }
252b5132
RH
7952 }
7953 break;
7954
70bccea4 7955 /* Relocate against either _SDA_BASE_, _SDA2_BASE_, or 0. */
7619e7c7
AM
7956 case R_PPC_EMB_SDA21:
7957 case R_PPC_EMB_RELSDA:
252b5132
RH
7958 {
7959 const char *name;
7960 int reg;
bd6c6e2b 7961 struct elf_link_hash_entry *sda = NULL;
252b5132 7962
3b4f3a11
AM
7963 if (sec == NULL || sec->output_section == NULL)
7964 {
7965 unresolved_reloc = TRUE;
7966 break;
7967 }
7968
252b5132 7969 name = bfd_get_section_name (abfd, sec->output_section);
0112cd26 7970 if (((CONST_STRNEQ (name, ".sdata")
5f819128 7971 && (name[6] == 0 || name[6] == '.'))
0112cd26 7972 || (CONST_STRNEQ (name, ".sbss")
5f819128 7973 && (name[5] == 0 || name[5] == '.'))))
252b5132
RH
7974 {
7975 reg = 13;
bd6c6e2b 7976 sda = htab->sdata[0].sym;
252b5132 7977 }
0112cd26
NC
7978 else if (CONST_STRNEQ (name, ".sdata2")
7979 || CONST_STRNEQ (name, ".sbss2"))
252b5132
RH
7980 {
7981 reg = 2;
bd6c6e2b 7982 sda = htab->sdata[1].sym;
252b5132 7983 }
8da6118f
KH
7984 else if (strcmp (name, ".PPC.EMB.sdata0") == 0
7985 || strcmp (name, ".PPC.EMB.sbss0") == 0)
252b5132
RH
7986 {
7987 reg = 0;
7988 }
252b5132
RH
7989 else
7990 {
55fd94b0 7991 (*_bfd_error_handler)
d003868e 7992 (_("%B: the target (%s) of a %s relocation is "
55fd94b0 7993 "in the wrong output section (%s)"),
d003868e 7994 input_bfd,
55fd94b0
AM
7995 sym_name,
7996 howto->name,
7997 name);
252b5132
RH
7998
7999 bfd_set_error (bfd_error_bad_value);
b34976b6 8000 ret = FALSE;
252b5132
RH
8001 continue;
8002 }
8003
bd6c6e2b
AM
8004 if (sda != NULL)
8005 {
8006 if (!is_static_defined (sda))
8007 {
8008 unresolved_reloc = TRUE;
8009 break;
8010 }
8011 addend -= SYM_VAL (sda);
8012 }
8013
252b5132 8014 if (r_type == R_PPC_EMB_SDA21)
91d6fa6a
NC
8015 {
8016 bfd_vma insn; /* Fill in register field. */
8017
7619e7c7 8018 insn = bfd_get_32 (output_bfd, contents + rel->r_offset);
252b5132 8019 insn = (insn & ~RA_REGISTER_MASK) | (reg << RA_REGISTER_SHIFT);
7619e7c7 8020 bfd_put_32 (output_bfd, insn, contents + rel->r_offset);
252b5132
RH
8021 }
8022 }
8023 break;
8024
70bccea4 8025 /* Relocate against the beginning of the section. */
7619e7c7
AM
8026 case R_PPC_SECTOFF:
8027 case R_PPC_SECTOFF_LO:
8028 case R_PPC_SECTOFF_HI:
8029 case R_PPC_SECTOFF_HA:
3b4f3a11
AM
8030 if (sec == NULL || sec->output_section == NULL)
8031 {
8032 unresolved_reloc = TRUE;
8033 break;
8034 }
252b5132 8035 addend -= sec->output_section->vma;
252b5132
RH
8036 break;
8037
70bccea4 8038 /* Negative relocations. */
7619e7c7
AM
8039 case R_PPC_EMB_NADDR32:
8040 case R_PPC_EMB_NADDR16:
8041 case R_PPC_EMB_NADDR16_LO:
8042 case R_PPC_EMB_NADDR16_HI:
8043 case R_PPC_EMB_NADDR16_HA:
8da6118f 8044 addend -= 2 * relocation;
252b5132
RH
8045 break;
8046
7619e7c7
AM
8047 case R_PPC_COPY:
8048 case R_PPC_GLOB_DAT:
8049 case R_PPC_JMP_SLOT:
8050 case R_PPC_RELATIVE:
e054468f 8051 case R_PPC_IRELATIVE:
7619e7c7
AM
8052 case R_PPC_PLT32:
8053 case R_PPC_PLTREL32:
8054 case R_PPC_PLT16_LO:
8055 case R_PPC_PLT16_HI:
8056 case R_PPC_PLT16_HA:
8057 case R_PPC_ADDR30:
8058 case R_PPC_EMB_RELSEC16:
8059 case R_PPC_EMB_RELST_LO:
8060 case R_PPC_EMB_RELST_HI:
8061 case R_PPC_EMB_RELST_HA:
8062 case R_PPC_EMB_BIT_FLD:
8063 (*_bfd_error_handler)
d003868e
AM
8064 (_("%B: relocation %s is not yet supported for symbol %s."),
8065 input_bfd,
7619e7c7
AM
8066 howto->name,
8067 sym_name);
252b5132
RH
8068
8069 bfd_set_error (bfd_error_invalid_operation);
b34976b6 8070 ret = FALSE;
252b5132 8071 continue;
7619e7c7 8072 }
252b5132 8073
7619e7c7
AM
8074 /* Do any further special processing. */
8075 switch (r_type)
8076 {
8077 default:
8078 break;
8079
8080 case R_PPC_ADDR16_HA:
d7128ce4 8081 case R_PPC_REL16_HA:
7619e7c7
AM
8082 case R_PPC_SECTOFF_HA:
8083 case R_PPC_TPREL16_HA:
8084 case R_PPC_DTPREL16_HA:
7619e7c7
AM
8085 case R_PPC_EMB_NADDR16_HA:
8086 case R_PPC_EMB_RELST_HA:
8087 /* It's just possible that this symbol is a weak symbol
7b609f53 8088 that's not actually defined anywhere. In that case,
7619e7c7
AM
8089 'sec' would be NULL, and we should leave the symbol
8090 alone (it will be set to zero elsewhere in the link). */
5c5f6e17
AM
8091 if (sec == NULL)
8092 break;
8093 /* Fall thru */
8094
8095 case R_PPC_PLT16_HA:
8096 case R_PPC_GOT16_HA:
8097 case R_PPC_GOT_TLSGD16_HA:
8098 case R_PPC_GOT_TLSLD16_HA:
8099 case R_PPC_GOT_TPREL16_HA:
8100 case R_PPC_GOT_DTPREL16_HA:
8101 /* Add 0x10000 if sign bit in 0:15 is set.
8102 Bits 0:15 are not used. */
8103 addend += 0x8000;
7619e7c7 8104 break;
252b5132
RH
8105 }
8106
252b5132 8107#ifdef DEBUG
55fd94b0
AM
8108 fprintf (stderr, "\ttype = %s (%d), name = %s, symbol index = %ld, "
8109 "offset = %ld, addend = %ld\n",
252b5132 8110 howto->name,
8da6118f 8111 (int) r_type,
252b5132
RH
8112 sym_name,
8113 r_symndx,
7619e7c7 8114 (long) rel->r_offset,
8da6118f 8115 (long) addend);
252b5132
RH
8116#endif
8117
7619e7c7
AM
8118 if (unresolved_reloc
8119 && !((input_section->flags & SEC_DEBUGGING) != 0
f5385ebf 8120 && h->def_dynamic))
7619e7c7
AM
8121 {
8122 (*_bfd_error_handler)
d003868e
AM
8123 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
8124 input_bfd,
8125 input_section,
7619e7c7 8126 (long) rel->r_offset,
7b609f53 8127 howto->name,
7619e7c7
AM
8128 sym_name);
8129 ret = FALSE;
8130 }
8131
252b5132
RH
8132 r = _bfd_final_link_relocate (howto,
8133 input_bfd,
8134 input_section,
8135 contents,
7619e7c7 8136 rel->r_offset,
252b5132
RH
8137 relocation,
8138 addend);
8139
7619e7c7 8140 if (r != bfd_reloc_ok)
252b5132 8141 {
7619e7c7 8142 if (r == bfd_reloc_overflow)
252b5132 8143 {
7619e7c7
AM
8144 if (warned)
8145 continue;
8146 if (h != NULL
8147 && h->root.type == bfd_link_hash_undefweak
dc1bc0c9
RH
8148 && howto->pc_relative)
8149 {
8150 /* Assume this is a call protected by other code that
8151 detect the symbol is undefined. If this is the case,
8152 we can safely ignore the overflow. If not, the
8153 program is hosed anyway, and a little warning isn't
8154 going to help. */
252b5132 8155
dc1bc0c9
RH
8156 continue;
8157 }
252b5132 8158
7619e7c7 8159 if (! (*info->callbacks->reloc_overflow) (info,
dfeffb9f 8160 (h ? &h->root : NULL),
7619e7c7
AM
8161 sym_name,
8162 howto->name,
8163 rel->r_addend,
8164 input_bfd,
8165 input_section,
8166 rel->r_offset))
8167 return FALSE;
dc1bc0c9
RH
8168 }
8169 else
8170 {
7619e7c7 8171 (*_bfd_error_handler)
d003868e
AM
8172 (_("%B(%A+0x%lx): %s reloc against `%s': error %d"),
8173 input_bfd, input_section,
7b609f53 8174 (long) rel->r_offset, howto->name, sym_name, (int) r);
7619e7c7 8175 ret = FALSE;
252b5132
RH
8176 }
8177 }
8178 }
8179
252b5132
RH
8180#ifdef DEBUG
8181 fprintf (stderr, "\n");
8182#endif
8183
8184 return ret;
8185}
252b5132 8186\f
25dbc73a
AM
8187/* Finish up dynamic symbol handling. We set the contents of various
8188 dynamic sections here. */
c5fccbec 8189
b34976b6 8190static bfd_boolean
25dbc73a
AM
8191ppc_elf_finish_dynamic_symbol (bfd *output_bfd,
8192 struct bfd_link_info *info,
8193 struct elf_link_hash_entry *h,
8194 Elf_Internal_Sym *sym)
e1a9cb8e 8195{
25dbc73a 8196 struct ppc_elf_link_hash_table *htab;
a6aa5195
AM
8197 struct plt_entry *ent;
8198 bfd_boolean doneone;
e1a9cb8e 8199
25dbc73a
AM
8200#ifdef DEBUG
8201 fprintf (stderr, "ppc_elf_finish_dynamic_symbol called for %s",
8202 h->root.root.string);
8203#endif
e1a9cb8e 8204
25dbc73a
AM
8205 htab = ppc_elf_hash_table (info);
8206 BFD_ASSERT (htab->elf.dynobj != NULL);
e1a9cb8e 8207
a6aa5195
AM
8208 doneone = FALSE;
8209 for (ent = h->plt.plist; ent != NULL; ent = ent->next)
8210 if (ent->plt.offset != (bfd_vma) -1)
8211 {
8212 if (!doneone)
8213 {
8214 Elf_Internal_Rela rela;
8215 bfd_byte *loc;
8216 bfd_vma reloc_index;
e1a9cb8e 8217
e054468f 8218 if (htab->plt_type == PLT_NEW
25f23106
AM
8219 || !htab->elf.dynamic_sections_created
8220 || h->dynindx == -1)
9d8504b1
PB
8221 reloc_index = ent->plt.offset / 4;
8222 else
8223 {
8224 reloc_index = ((ent->plt.offset - htab->plt_initial_entry_size)
8225 / htab->plt_slot_size);
8226 if (reloc_index > PLT_NUM_SINGLE_ENTRIES
4a3dc543 8227 && htab->plt_type == PLT_OLD)
9d8504b1
PB
8228 reloc_index -= (reloc_index - PLT_NUM_SINGLE_ENTRIES) / 2;
8229 }
8230
a6aa5195
AM
8231 /* This symbol has an entry in the procedure linkage table.
8232 Set it up. */
e054468f 8233 if (htab->plt_type == PLT_VXWORKS
25f23106
AM
8234 && htab->elf.dynamic_sections_created
8235 && h->dynindx != -1)
a6aa5195 8236 {
9d8504b1
PB
8237 bfd_vma got_offset;
8238 const bfd_vma *plt_entry;
5b914448 8239
9d8504b1
PB
8240 /* The first three entries in .got.plt are reserved. */
8241 got_offset = (reloc_index + 3) * 4;
8242
8243 /* Use the right PLT. */
8244 plt_entry = info->shared ? ppc_elf_vxworks_pic_plt_entry
8245 : ppc_elf_vxworks_plt_entry;
8246
8247 /* Fill in the .plt on VxWorks. */
8248 if (info->shared)
8249 {
9d8504b1 8250 bfd_put_32 (output_bfd,
e87d4038 8251 plt_entry[0] | PPC_HA (got_offset),
9d8504b1
PB
8252 htab->plt->contents + ent->plt.offset + 0);
8253 bfd_put_32 (output_bfd,
e87d4038 8254 plt_entry[1] | PPC_LO (got_offset),
9d8504b1
PB
8255 htab->plt->contents + ent->plt.offset + 4);
8256 }
8257 else
8258 {
e87d4038 8259 bfd_vma got_loc = got_offset + SYM_VAL (htab->elf.hgot);
9d8504b1
PB
8260
8261 bfd_put_32 (output_bfd,
e87d4038 8262 plt_entry[0] | PPC_HA (got_loc),
9d8504b1
PB
8263 htab->plt->contents + ent->plt.offset + 0);
8264 bfd_put_32 (output_bfd,
e87d4038 8265 plt_entry[1] | PPC_LO (got_loc),
9d8504b1
PB
8266 htab->plt->contents + ent->plt.offset + 4);
8267 }
8268
8269 bfd_put_32 (output_bfd, plt_entry[2],
8270 htab->plt->contents + ent->plt.offset + 8);
8271 bfd_put_32 (output_bfd, plt_entry[3],
8272 htab->plt->contents + ent->plt.offset + 12);
8273
8274 /* This instruction is an immediate load. The value loaded is
8275 the byte offset of the R_PPC_JMP_SLOT relocation from the
8276 start of the .rela.plt section. The value is stored in the
8277 low-order 16 bits of the load instruction. */
8278 /* NOTE: It appears that this is now an index rather than a
8279 prescaled offset. */
5b914448 8280 bfd_put_32 (output_bfd,
9d8504b1
PB
8281 plt_entry[4] | reloc_index,
8282 htab->plt->contents + ent->plt.offset + 16);
8283 /* This instruction is a PC-relative branch whose target is
8284 the start of the PLT section. The address of this branch
8285 instruction is 20 bytes beyond the start of this PLT entry.
8286 The address is encoded in bits 6-29, inclusive. The value
8287 stored is right-shifted by two bits, permitting a 26-bit
8288 offset. */
5b914448
AM
8289 bfd_put_32 (output_bfd,
8290 (plt_entry[5]
9d8504b1
PB
8291 | (-(ent->plt.offset + 20) & 0x03fffffc)),
8292 htab->plt->contents + ent->plt.offset + 20);
8293 bfd_put_32 (output_bfd, plt_entry[6],
8294 htab->plt->contents + ent->plt.offset + 24);
8295 bfd_put_32 (output_bfd, plt_entry[7],
8296 htab->plt->contents + ent->plt.offset + 28);
8297
8298 /* Fill in the GOT entry corresponding to this PLT slot with
8299 the address immediately after the the "bctr" instruction
8300 in this PLT entry. */
8301 bfd_put_32 (output_bfd, (htab->plt->output_section->vma
8302 + htab->plt->output_offset
8303 + ent->plt.offset + 16),
8304 htab->sgotplt->contents + got_offset);
8305
8306 if (!info->shared)
8307 {
8308 /* Fill in a couple of entries in .rela.plt.unloaded. */
8309 loc = htab->srelplt2->contents
8310 + ((VXWORKS_PLTRESOLVE_RELOCS + reloc_index
8311 * VXWORKS_PLT_NON_JMP_SLOT_RELOCS)
8312 * sizeof (Elf32_External_Rela));
8313
8314 /* Provide the @ha relocation for the first instruction. */
8315 rela.r_offset = (htab->plt->output_section->vma
8316 + htab->plt->output_offset
8317 + ent->plt.offset + 2);
636ce3f5 8318 rela.r_info = ELF32_R_INFO (htab->elf.hgot->indx,
9d8504b1
PB
8319 R_PPC_ADDR16_HA);
8320 rela.r_addend = got_offset;
8321 bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
8322 loc += sizeof (Elf32_External_Rela);
8323
8324 /* Provide the @l relocation for the second instruction. */
8325 rela.r_offset = (htab->plt->output_section->vma
8326 + htab->plt->output_offset
8327 + ent->plt.offset + 6);
636ce3f5 8328 rela.r_info = ELF32_R_INFO (htab->elf.hgot->indx,
9d8504b1
PB
8329 R_PPC_ADDR16_LO);
8330 rela.r_addend = got_offset;
8331 bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
8332 loc += sizeof (Elf32_External_Rela);
8333
8334 /* Provide a relocation for the GOT entry corresponding to this
8335 PLT slot. Point it at the middle of the .plt entry. */
8336 rela.r_offset = (htab->sgotplt->output_section->vma
8337 + htab->sgotplt->output_offset
8338 + got_offset);
7325306f 8339 rela.r_info = ELF32_R_INFO (htab->elf.hplt->indx,
9d8504b1
PB
8340 R_PPC_ADDR32);
8341 rela.r_addend = ent->plt.offset + 16;
8342 bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
8343 }
8344
8345 /* VxWorks uses non-standard semantics for R_PPC_JMP_SLOT.
8346 In particular, the offset for the relocation is not the
8347 address of the PLT entry for this function, as specified
8348 by the ABI. Instead, the offset is set to the address of
8349 the GOT slot for this function. See EABI 4.4.4.1. */
8350 rela.r_offset = (htab->sgotplt->output_section->vma
8351 + htab->sgotplt->output_offset
8352 + got_offset);
8353
a6aa5195
AM
8354 }
8355 else
8356 {
e054468f 8357 asection *splt = htab->plt;
25f23106
AM
8358 if (!htab->elf.dynamic_sections_created
8359 || h->dynindx == -1)
e054468f
AM
8360 splt = htab->iplt;
8361
8362 rela.r_offset = (splt->output_section->vma
8363 + splt->output_offset
9d8504b1 8364 + ent->plt.offset);
e054468f 8365 if (htab->plt_type == PLT_OLD
25f23106
AM
8366 || !htab->elf.dynamic_sections_created
8367 || h->dynindx == -1)
9d8504b1
PB
8368 {
8369 /* We don't need to fill in the .plt. The ppc dynamic
8370 linker will fill it in. */
8371 }
8372 else
8373 {
8374 bfd_vma val = (htab->glink_pltresolve + ent->plt.offset
8375 + htab->glink->output_section->vma
8376 + htab->glink->output_offset);
8377 bfd_put_32 (output_bfd, val,
e054468f 8378 splt->contents + ent->plt.offset);
9d8504b1 8379 }
a6aa5195 8380 }
e1a9cb8e 8381
a6aa5195 8382 /* Fill in the entry in the .rela.plt section. */
a6aa5195 8383 rela.r_addend = 0;
e054468f
AM
8384 if (!htab->elf.dynamic_sections_created
8385 || h->dynindx == -1)
8386 {
8387 BFD_ASSERT (h->type == STT_GNU_IFUNC
8388 && h->def_regular
8389 && (h->root.type == bfd_link_hash_defined
8390 || h->root.type == bfd_link_hash_defweak));
8391 rela.r_info = ELF32_R_INFO (0, R_PPC_IRELATIVE);
8392 rela.r_addend = SYM_VAL (h);
8393 }
8394 else
8395 rela.r_info = ELF32_R_INFO (h->dynindx, R_PPC_JMP_SLOT);
e1a9cb8e 8396
25f23106
AM
8397 if (!htab->elf.dynamic_sections_created
8398 || h->dynindx == -1)
8399 loc = (htab->reliplt->contents
8400 + (htab->reliplt->reloc_count++
8401 * sizeof (Elf32_External_Rela)));
e054468f 8402 else
25f23106
AM
8403 loc = (htab->relplt->contents
8404 + reloc_index * sizeof (Elf32_External_Rela));
a6aa5195 8405 bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
e1a9cb8e 8406
a6aa5195
AM
8407 if (!h->def_regular)
8408 {
0eb4a168
AM
8409 /* Mark the symbol as undefined, rather than as
8410 defined in the .plt section. Leave the value if
8411 there were any relocations where pointer equality
8412 matters (this is a clue for the dynamic linker, to
8413 make function pointer comparisons work between an
8414 application and shared library), otherwise set it
8415 to zero. */
a6aa5195 8416 sym->st_shndx = SHN_UNDEF;
0eb4a168 8417 if (!h->pointer_equality_needed)
a6aa5195 8418 sym->st_value = 0;
0eb4a168
AM
8419 else if (!h->ref_regular_nonweak)
8420 {
625af618
AM
8421 /* This breaks function pointer comparisons, but
8422 that is better than breaking tests for a NULL
0eb4a168 8423 function pointer. */
0eb4a168
AM
8424 sym->st_value = 0;
8425 }
a6aa5195 8426 }
de972ffa
AM
8427 else if (h->type == STT_GNU_IFUNC
8428 && !info->shared)
8429 {
8430 /* Set the value of ifunc symbols in a non-pie
8431 executable to the glink entry. This is to avoid
8432 text relocations. We can't do this for ifunc in
8433 allocate_dynrelocs, as we do for normal dynamic
8434 function symbols with plt entries, because we need
8435 to keep the original value around for the ifunc
8436 relocation. */
8437 sym->st_shndx = (_bfd_elf_section_from_bfd_section
8438 (output_bfd, htab->glink->output_section));
5b914448
AM
8439 sym->st_value = (ent->glink_offset
8440 + htab->glink->output_offset
de972ffa
AM
8441 + htab->glink->output_section->vma);
8442 }
a6aa5195
AM
8443 doneone = TRUE;
8444 }
e1a9cb8e 8445
e054468f 8446 if (htab->plt_type == PLT_NEW
25f23106
AM
8447 || !htab->elf.dynamic_sections_created
8448 || h->dynindx == -1)
a6aa5195 8449 {
a7f2871e 8450 unsigned char *p;
e054468f 8451 asection *splt = htab->plt;
25f23106
AM
8452 if (!htab->elf.dynamic_sections_created
8453 || h->dynindx == -1)
e054468f 8454 splt = htab->iplt;
e1a9cb8e 8455
a7f2871e
AM
8456 p = (unsigned char *) htab->glink->contents + ent->glink_offset;
8457
8458 if (h == htab->tls_get_addr && !htab->no_tls_get_addr_opt)
8459 {
8460 bfd_put_32 (output_bfd, LWZ_11_3, p);
8461 p += 4;
8462 bfd_put_32 (output_bfd, LWZ_12_3 + 4, p);
8463 p += 4;
8464 bfd_put_32 (output_bfd, MR_0_3, p);
8465 p += 4;
8466 bfd_put_32 (output_bfd, CMPWI_11_0, p);
8467 p += 4;
8468 bfd_put_32 (output_bfd, ADD_3_12_2, p);
8469 p += 4;
8470 bfd_put_32 (output_bfd, BEQLR, p);
8471 p += 4;
8472 bfd_put_32 (output_bfd, MR_3_0, p);
8473 p += 4;
8474 bfd_put_32 (output_bfd, NOP, p);
8475 p += 4;
8476 }
8477
8478 write_glink_stub (ent, splt, p, info);
e1a9cb8e 8479
a877a2b6 8480 if (!info->shared)
e054468f
AM
8481 /* We only need one non-PIC glink stub. */
8482 break;
a6aa5195
AM
8483 }
8484 else
8485 break;
8486 }
e1a9cb8e 8487
25dbc73a
AM
8488 if (h->needs_copy)
8489 {
8490 asection *s;
8491 Elf_Internal_Rela rela;
8492 bfd_byte *loc;
e1a9cb8e 8493
25dbc73a 8494 /* This symbols needs a copy reloc. Set it up. */
e1a9cb8e 8495
25dbc73a
AM
8496#ifdef DEBUG
8497 fprintf (stderr, ", copy");
8498#endif
e1a9cb8e 8499
25dbc73a 8500 BFD_ASSERT (h->dynindx != -1);
86bbe32f 8501
4dc4a9a5 8502 if (ppc_elf_hash_entry (h)->has_sda_refs)
25dbc73a
AM
8503 s = htab->relsbss;
8504 else
8505 s = htab->relbss;
8506 BFD_ASSERT (s != NULL);
e1a9cb8e 8507
e87d4038 8508 rela.r_offset = SYM_VAL (h);
25dbc73a
AM
8509 rela.r_info = ELF32_R_INFO (h->dynindx, R_PPC_COPY);
8510 rela.r_addend = 0;
8511 loc = s->contents + s->reloc_count++ * sizeof (Elf32_External_Rela);
8512 bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
8513 }
e1a9cb8e 8514
25dbc73a
AM
8515#ifdef DEBUG
8516 fprintf (stderr, "\n");
8517#endif
e1a9cb8e 8518
25dbc73a 8519 /* Mark some specially defined symbols as absolute. */
9d8504b1
PB
8520 if (strcmp (h->root.root.string, "_DYNAMIC") == 0
8521 || (!htab->is_vxworks
8522 && (h == htab->elf.hgot
8523 || strcmp (h->root.root.string,
8524 "_PROCEDURE_LINKAGE_TABLE_") == 0)))
25dbc73a 8525 sym->st_shndx = SHN_ABS;
e1a9cb8e 8526
25dbc73a
AM
8527 return TRUE;
8528}
8529\f
8530static enum elf_reloc_type_class
8531ppc_elf_reloc_type_class (const Elf_Internal_Rela *rela)
e1a9cb8e 8532{
25dbc73a
AM
8533 switch (ELF32_R_TYPE (rela->r_info))
8534 {
8535 case R_PPC_RELATIVE:
8536 return reloc_class_relative;
8537 case R_PPC_REL24:
8538 case R_PPC_ADDR24:
8539 case R_PPC_JMP_SLOT:
8540 return reloc_class_plt;
8541 case R_PPC_COPY:
8542 return reloc_class_copy;
8543 default:
8544 return reloc_class_normal;
8545 }
e1a9cb8e 8546}
25dbc73a
AM
8547\f
8548/* Finish up the dynamic sections. */
e1a9cb8e 8549
25dbc73a
AM
8550static bfd_boolean
8551ppc_elf_finish_dynamic_sections (bfd *output_bfd,
8552 struct bfd_link_info *info)
e1a9cb8e 8553{
25dbc73a 8554 asection *sdyn;
9d8504b1 8555 asection *splt;
25dbc73a 8556 struct ppc_elf_link_hash_table *htab;
1fe44d79 8557 bfd_vma got;
e87d4038
AM
8558 bfd *dynobj;
8559 bfd_boolean ret = TRUE;
e1a9cb8e 8560
25dbc73a
AM
8561#ifdef DEBUG
8562 fprintf (stderr, "ppc_elf_finish_dynamic_sections called\n");
8563#endif
6b0817e5 8564
25dbc73a 8565 htab = ppc_elf_hash_table (info);
9d8504b1
PB
8566 dynobj = elf_hash_table (info)->dynobj;
8567 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
8568 if (htab->is_vxworks)
5b914448 8569 splt = bfd_get_section_by_name (dynobj, ".plt");
9d8504b1
PB
8570 else
8571 splt = NULL;
e1a9cb8e 8572
1fe44d79
AM
8573 got = 0;
8574 if (htab->elf.hgot != NULL)
e87d4038 8575 got = SYM_VAL (htab->elf.hgot);
1fe44d79 8576
25dbc73a 8577 if (htab->elf.dynamic_sections_created)
e1a9cb8e 8578 {
25dbc73a 8579 Elf32_External_Dyn *dyncon, *dynconend;
e1a9cb8e 8580
25dbc73a 8581 BFD_ASSERT (htab->plt != NULL && sdyn != NULL);
86bbe32f 8582
25dbc73a
AM
8583 dyncon = (Elf32_External_Dyn *) sdyn->contents;
8584 dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size);
8585 for (; dyncon < dynconend; dyncon++)
8586 {
8587 Elf_Internal_Dyn dyn;
8588 asection *s;
e1a9cb8e 8589
9d8504b1 8590 bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
86bbe32f 8591
25dbc73a
AM
8592 switch (dyn.d_tag)
8593 {
8594 case DT_PLTGOT:
9d8504b1
PB
8595 if (htab->is_vxworks)
8596 s = htab->sgotplt;
8597 else
8598 s = htab->plt;
25dbc73a
AM
8599 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
8600 break;
86bbe32f 8601
25dbc73a
AM
8602 case DT_PLTRELSZ:
8603 dyn.d_un.d_val = htab->relplt->size;
8604 break;
e1a9cb8e 8605
25dbc73a
AM
8606 case DT_JMPREL:
8607 s = htab->relplt;
8608 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
8609 break;
2f89ff8d 8610
1fe44d79
AM
8611 case DT_PPC_GOT:
8612 dyn.d_un.d_ptr = got;
d7128ce4
AM
8613 break;
8614
9d8504b1
PB
8615 case DT_RELASZ:
8616 if (htab->is_vxworks)
8617 {
8618 if (htab->relplt)
8619 dyn.d_un.d_ptr -= htab->relplt->size;
8620 break;
8621 }
8622 continue;
8623
25dbc73a 8624 default:
7a2b07ff
NS
8625 if (htab->is_vxworks
8626 && elf_vxworks_finish_dynamic_entry (output_bfd, &dyn))
8627 break;
25dbc73a
AM
8628 continue;
8629 }
4c45e5c9 8630
25dbc73a
AM
8631 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
8632 }
8633 }
4c45e5c9 8634
3b36f7e6 8635 if (htab->got != NULL)
25dbc73a 8636 {
e79f5955
AM
8637 if (htab->elf.hgot->root.u.def.section == htab->got
8638 || htab->elf.hgot->root.u.def.section == htab->sgotplt)
e87d4038 8639 {
e79f5955 8640 unsigned char *p = htab->elf.hgot->root.u.def.section->contents;
2f89ff8d 8641
e87d4038
AM
8642 p += htab->elf.hgot->root.u.def.value;
8643 if (htab->plt_type == PLT_OLD)
e79f5955
AM
8644 {
8645 /* Add a blrl instruction at _GLOBAL_OFFSET_TABLE_-4
8646 so that a function can easily find the address of
8647 _GLOBAL_OFFSET_TABLE_. */
8648 BFD_ASSERT (htab->elf.hgot->root.u.def.value - 4
8649 < htab->elf.hgot->root.u.def.section->size);
8650 bfd_put_32 (output_bfd, 0x4e800021, p - 4);
8651 }
3b36f7e6 8652
e87d4038 8653 if (sdyn != NULL)
e79f5955
AM
8654 {
8655 bfd_vma val = sdyn->output_section->vma + sdyn->output_offset;
8656 BFD_ASSERT (htab->elf.hgot->root.u.def.value
8657 < htab->elf.hgot->root.u.def.section->size);
8658 bfd_put_32 (output_bfd, val, p);
8659 }
e87d4038
AM
8660 }
8661 else
8662 {
8663 (*_bfd_error_handler) (_("%s not defined in linker created %s"),
8664 htab->elf.hgot->root.root.string,
e79f5955
AM
8665 (htab->sgotplt != NULL
8666 ? htab->sgotplt->name : htab->got->name));
e87d4038
AM
8667 bfd_set_error (bfd_error_bad_value);
8668 ret = FALSE;
8669 }
25dbc73a
AM
8670
8671 elf_section_data (htab->got->output_section)->this_hdr.sh_entsize = 4;
8672 }
8673
9d8504b1
PB
8674 /* Fill in the first entry in the VxWorks procedure linkage table. */
8675 if (splt && splt->size > 0)
8676 {
8677 /* Use the right PLT. */
5b914448
AM
8678 const bfd_vma *plt_entry = (info->shared
8679 ? ppc_elf_vxworks_pic_plt0_entry
8680 : ppc_elf_vxworks_plt0_entry);
9d8504b1
PB
8681
8682 if (!info->shared)
8683 {
e87d4038 8684 bfd_vma got_value = SYM_VAL (htab->elf.hgot);
9d8504b1 8685
e87d4038 8686 bfd_put_32 (output_bfd, plt_entry[0] | PPC_HA (got_value),
9d8504b1 8687 splt->contents + 0);
e87d4038 8688 bfd_put_32 (output_bfd, plt_entry[1] | PPC_LO (got_value),
9d8504b1
PB
8689 splt->contents + 4);
8690 }
8691 else
8692 {
8693 bfd_put_32 (output_bfd, plt_entry[0], splt->contents + 0);
8694 bfd_put_32 (output_bfd, plt_entry[1], splt->contents + 4);
8695 }
8696 bfd_put_32 (output_bfd, plt_entry[2], splt->contents + 8);
8697 bfd_put_32 (output_bfd, plt_entry[3], splt->contents + 12);
8698 bfd_put_32 (output_bfd, plt_entry[4], splt->contents + 16);
8699 bfd_put_32 (output_bfd, plt_entry[5], splt->contents + 20);
8700 bfd_put_32 (output_bfd, plt_entry[6], splt->contents + 24);
8701 bfd_put_32 (output_bfd, plt_entry[7], splt->contents + 28);
8702
8703 if (! info->shared)
8704 {
8705 Elf_Internal_Rela rela;
8706 bfd_byte *loc;
8707
8708 loc = htab->srelplt2->contents;
8709
8710 /* Output the @ha relocation for the first instruction. */
8711 rela.r_offset = (htab->plt->output_section->vma
8712 + htab->plt->output_offset
8713 + 2);
636ce3f5 8714 rela.r_info = ELF32_R_INFO (htab->elf.hgot->indx, R_PPC_ADDR16_HA);
9d8504b1
PB
8715 rela.r_addend = 0;
8716 bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
8717 loc += sizeof (Elf32_External_Rela);
5b914448 8718
9d8504b1
PB
8719 /* Output the @l relocation for the second instruction. */
8720 rela.r_offset = (htab->plt->output_section->vma
8721 + htab->plt->output_offset
8722 + 6);
636ce3f5 8723 rela.r_info = ELF32_R_INFO (htab->elf.hgot->indx, R_PPC_ADDR16_LO);
9d8504b1
PB
8724 rela.r_addend = 0;
8725 bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
8726 loc += sizeof (Elf32_External_Rela);
8727
8728 /* Fix up the remaining relocations. They may have the wrong
8729 symbol index for _G_O_T_ or _P_L_T_ depending on the order
8730 in which symbols were output. */
8731 while (loc < htab->srelplt2->contents + htab->srelplt2->size)
8732 {
8733 Elf_Internal_Rela rel;
8734
8735 bfd_elf32_swap_reloc_in (output_bfd, loc, &rel);
636ce3f5 8736 rel.r_info = ELF32_R_INFO (htab->elf.hgot->indx, R_PPC_ADDR16_HA);
9d8504b1
PB
8737 bfd_elf32_swap_reloc_out (output_bfd, &rel, loc);
8738 loc += sizeof (Elf32_External_Rela);
8739
8740 bfd_elf32_swap_reloc_in (output_bfd, loc, &rel);
636ce3f5 8741 rel.r_info = ELF32_R_INFO (htab->elf.hgot->indx, R_PPC_ADDR16_LO);
9d8504b1
PB
8742 bfd_elf32_swap_reloc_out (output_bfd, &rel, loc);
8743 loc += sizeof (Elf32_External_Rela);
8744
8745 bfd_elf32_swap_reloc_in (output_bfd, loc, &rel);
7325306f 8746 rel.r_info = ELF32_R_INFO (htab->elf.hplt->indx, R_PPC_ADDR32);
9d8504b1
PB
8747 bfd_elf32_swap_reloc_out (output_bfd, &rel, loc);
8748 loc += sizeof (Elf32_External_Rela);
8749 }
8750 }
8751 }
8752
e054468f
AM
8753 if (htab->glink != NULL
8754 && htab->glink->contents != NULL
8755 && htab->elf.dynamic_sections_created)
d7128ce4
AM
8756 {
8757 unsigned char *p;
8758 unsigned char *endp;
a6aa5195 8759 bfd_vma res0;
d7128ce4 8760 unsigned int i;
a6aa5195
AM
8761
8762 /*
8763 * PIC glink code is the following:
8764 *
8765 * # ith PLT code stub.
8766 * addis 11,30,(plt+(i-1)*4-got)@ha
8767 * lwz 11,(plt+(i-1)*4-got)@l(11)
8768 * mtctr 11
8769 * bctr
8770 *
8771 * # A table of branches, one for each plt entry.
176a0d42 8772 * # The idea is that the plt call stub loads ctr and r11 with these
a6aa5195
AM
8773 * # addresses, so (r11 - res_0) gives the plt index * 4.
8774 * res_0: b PLTresolve
8775 * res_1: b PLTresolve
8776 * .
8777 * # Some number of entries towards the end can be nops
8778 * res_n_m3: nop
8779 * res_n_m2: nop
8780 * res_n_m1:
8781 *
8782 * PLTresolve:
8783 * addis 11,11,(1f-res_0)@ha
8784 * mflr 0
8785 * bcl 20,31,1f
8786 * 1: addi 11,11,(1b-res_0)@l
8787 * mflr 12
8788 * mtlr 0
8789 * sub 11,11,12 # r11 = index * 4
8790 * addis 12,12,(got+4-1b)@ha
8791 * lwz 0,(got+4-1b)@l(12) # got[1] address of dl_runtime_resolve
8792 * lwz 12,(got+8-1b)@l(12) # got[2] contains the map address
8793 * mtctr 0
8794 * add 0,11,11
8795 * add 11,0,11 # r11 = index * 12 = reloc offset.
8796 * bctr
8797 */
8798 static const unsigned int pic_plt_resolve[] =
8799 {
8800 ADDIS_11_11,
8801 MFLR_0,
8802 BCL_20_31,
8803 ADDI_11_11,
8804 MFLR_12,
8805 MTLR_0,
8806 SUB_11_11_12,
8807 ADDIS_12_12,
8808 LWZ_0_12,
8809 LWZ_12_12,
8810 MTCTR_0,
8811 ADD_0_11_11,
8812 ADD_11_0_11,
8813 BCTR,
8814 NOP,
8815 NOP
8816 };
8817
176a0d42
AM
8818 /*
8819 * Non-PIC glink code is a little simpler.
8820 *
8821 * # ith PLT code stub.
8822 * lis 11,(plt+(i-1)*4)@ha
8823 * lwz 11,(plt+(i-1)*4)@l(11)
8824 * mtctr 11
8825 * bctr
8826 *
8827 * The branch table is the same, then comes
8828 *
8829 * PLTresolve:
8830 * lis 12,(got+4)@ha
8831 * addis 11,11,(-res_0)@ha
8832 * lwz 0,(got+4)@l(12) # got[1] address of dl_runtime_resolve
8833 * addi 11,11,(-res_0)@l # r11 = index * 4
8834 * mtctr 0
8835 * add 0,11,11
8836 * lwz 12,(got+8)@l(12) # got[2] contains the map address
8837 * add 11,0,11 # r11 = index * 12 = reloc offset.
8838 * bctr
8839 */
d7128ce4
AM
8840 static const unsigned int plt_resolve[] =
8841 {
a6aa5195
AM
8842 LIS_12,
8843 ADDIS_11_11,
8844 LWZ_0_12,
8845 ADDI_11_11,
d7128ce4 8846 MTCTR_0,
7e8aeb9a 8847 ADD_0_11_11,
a6aa5195 8848 LWZ_12_12,
7e8aeb9a 8849 ADD_11_0_11,
d7128ce4
AM
8850 BCTR,
8851 NOP,
8852 NOP,
a6aa5195
AM
8853 NOP,
8854 NOP,
8855 NOP,
8856 NOP,
d7128ce4
AM
8857 NOP
8858 };
8859
a6aa5195
AM
8860 if (ARRAY_SIZE (pic_plt_resolve) != GLINK_PLTRESOLVE / 4)
8861 abort ();
8862 if (ARRAY_SIZE (plt_resolve) != GLINK_PLTRESOLVE / 4)
7e8aeb9a
AM
8863 abort ();
8864
a6aa5195 8865 /* Build the branch table, one for each plt entry (less one),
86b9da88 8866 and perhaps some padding. */
a6aa5195
AM
8867 p = htab->glink->contents;
8868 p += htab->glink_pltresolve;
86b9da88
AM
8869 endp = htab->glink->contents;
8870 endp += htab->glink->size - GLINK_PLTRESOLVE;
8871 while (p < endp - 8 * 4)
8872 {
8873 bfd_put_32 (output_bfd, B + endp - p, p);
8874 p += 4;
8875 }
8876 while (p < endp)
8877 {
8878 bfd_put_32 (output_bfd, NOP, p);
8879 p += 4;
8880 }
8881
7e8aeb9a 8882 res0 = (htab->glink_pltresolve
86b9da88
AM
8883 + htab->glink->output_section->vma
8884 + htab->glink->output_offset);
8885
8886 /* Last comes the PLTresolve stub. */
a877a2b6 8887 if (info->shared)
7e8aeb9a 8888 {
a6aa5195 8889 bfd_vma bcl;
d7128ce4 8890
a6aa5195 8891 for (i = 0; i < ARRAY_SIZE (pic_plt_resolve); i++)
7e8aeb9a 8892 {
a6aa5195 8893 bfd_put_32 (output_bfd, pic_plt_resolve[i], p);
7e8aeb9a
AM
8894 p += 4;
8895 }
a6aa5195
AM
8896 p -= 4 * ARRAY_SIZE (pic_plt_resolve);
8897
8898 bcl = (htab->glink->size - GLINK_PLTRESOLVE + 3*4
8899 + htab->glink->output_section->vma
8900 + htab->glink->output_offset);
8901
8902 bfd_put_32 (output_bfd,
8903 ADDIS_11_11 + PPC_HA (bcl - res0), p + 0*4);
8904 bfd_put_32 (output_bfd,
8905 ADDI_11_11 + PPC_LO (bcl - res0), p + 3*4);
8906 bfd_put_32 (output_bfd,
8907 ADDIS_12_12 + PPC_HA (got + 4 - bcl), p + 7*4);
8908 if (PPC_HA (got + 4 - bcl) == PPC_HA (got + 8 - bcl))
8909 {
8910 bfd_put_32 (output_bfd,
8911 LWZ_0_12 + PPC_LO (got + 4 - bcl), p + 8*4);
8912 bfd_put_32 (output_bfd,
8913 LWZ_12_12 + PPC_LO (got + 8 - bcl), p + 9*4);
8914 }
8915 else
8916 {
8917 bfd_put_32 (output_bfd,
8918 LWZU_0_12 + PPC_LO (got + 4 - bcl), p + 8*4);
8919 bfd_put_32 (output_bfd,
8920 LWZ_12_12 + 4, p + 9*4);
8921 }
7e8aeb9a
AM
8922 }
8923 else
d7128ce4 8924 {
a6aa5195 8925 for (i = 0; i < ARRAY_SIZE (plt_resolve); i++)
7e8aeb9a
AM
8926 {
8927 bfd_put_32 (output_bfd, plt_resolve[i], p);
8928 p += 4;
8929 }
a6aa5195
AM
8930 p -= 4 * ARRAY_SIZE (plt_resolve);
8931
8932 bfd_put_32 (output_bfd,
8933 LIS_12 + PPC_HA (got + 4), p + 0*4);
8934 bfd_put_32 (output_bfd,
8935 ADDIS_11_11 + PPC_HA (-res0), p + 1*4);
8936 bfd_put_32 (output_bfd,
8937 ADDI_11_11 + PPC_LO (-res0), p + 3*4);
8938 if (PPC_HA (got + 4) == PPC_HA (got + 8))
8939 {
8940 bfd_put_32 (output_bfd,
8941 LWZ_0_12 + PPC_LO (got + 4), p + 2*4);
8942 bfd_put_32 (output_bfd,
8943 LWZ_12_12 + PPC_LO (got + 8), p + 6*4);
8944 }
8945 else
8946 {
8947 bfd_put_32 (output_bfd,
8948 LWZU_0_12 + PPC_LO (got + 4), p + 2*4);
8949 bfd_put_32 (output_bfd,
8950 LWZ_12_12 + 4, p + 6*4);
8951 }
d7128ce4 8952 }
d7128ce4
AM
8953 }
8954
e87d4038 8955 return ret;
25dbc73a 8956}
e1a9cb8e 8957\f
252b5132
RH
8958#define TARGET_LITTLE_SYM bfd_elf32_powerpcle_vec
8959#define TARGET_LITTLE_NAME "elf32-powerpcle"
8960#define TARGET_BIG_SYM bfd_elf32_powerpc_vec
8961#define TARGET_BIG_NAME "elf32-powerpc"
8962#define ELF_ARCH bfd_arch_powerpc
ae95ffa6 8963#define ELF_TARGET_ID PPC32_ELF_DATA
252b5132 8964#define ELF_MACHINE_CODE EM_PPC
d0facd1b
NC
8965#ifdef __QNXTARGET__
8966#define ELF_MAXPAGESIZE 0x1000
8967#else
252b5132 8968#define ELF_MAXPAGESIZE 0x10000
d0facd1b 8969#endif
b1342370 8970#define ELF_MINPAGESIZE 0x1000
24718e3b 8971#define ELF_COMMONPAGESIZE 0x1000
252b5132
RH
8972#define elf_info_to_howto ppc_elf_info_to_howto
8973
8974#ifdef EM_CYGNUS_POWERPC
8975#define ELF_MACHINE_ALT1 EM_CYGNUS_POWERPC
8976#endif
8977
8978#ifdef EM_PPC_OLD
8979#define ELF_MACHINE_ALT2 EM_PPC_OLD
8980#endif
8981
8982#define elf_backend_plt_not_loaded 1
252b5132 8983#define elf_backend_can_gc_sections 1
51b64d56 8984#define elf_backend_can_refcount 1
b491616a 8985#define elf_backend_rela_normal 1
252b5132 8986
43c40ab2 8987#define bfd_elf32_mkobject ppc_elf_mkobject
252b5132 8988#define bfd_elf32_bfd_merge_private_bfd_data ppc_elf_merge_private_bfd_data
70bccea4 8989#define bfd_elf32_bfd_relax_section ppc_elf_relax_section
252b5132 8990#define bfd_elf32_bfd_reloc_type_lookup ppc_elf_reloc_type_lookup
157090f7 8991#define bfd_elf32_bfd_reloc_name_lookup ppc_elf_reloc_name_lookup
252b5132 8992#define bfd_elf32_bfd_set_private_flags ppc_elf_set_private_flags
70bccea4 8993#define bfd_elf32_bfd_link_hash_table_create ppc_elf_link_hash_table_create
468392fb 8994#define bfd_elf32_get_synthetic_symtab ppc_elf_get_synthetic_symtab
252b5132 8995
feee612b 8996#define elf_backend_object_p ppc_elf_object_p
252b5132
RH
8997#define elf_backend_gc_mark_hook ppc_elf_gc_mark_hook
8998#define elf_backend_gc_sweep_hook ppc_elf_gc_sweep_hook
8999#define elf_backend_section_from_shdr ppc_elf_section_from_shdr
9000#define elf_backend_relocate_section ppc_elf_relocate_section
9001#define elf_backend_create_dynamic_sections ppc_elf_create_dynamic_sections
9002#define elf_backend_check_relocs ppc_elf_check_relocs
7fce784e 9003#define elf_backend_copy_indirect_symbol ppc_elf_copy_indirect_symbol
252b5132
RH
9004#define elf_backend_adjust_dynamic_symbol ppc_elf_adjust_dynamic_symbol
9005#define elf_backend_add_symbol_hook ppc_elf_add_symbol_hook
9006#define elf_backend_size_dynamic_sections ppc_elf_size_dynamic_sections
0eb4a168 9007#define elf_backend_hash_symbol ppc_elf_hash_symbol
252b5132
RH
9008#define elf_backend_finish_dynamic_symbol ppc_elf_finish_dynamic_symbol
9009#define elf_backend_finish_dynamic_sections ppc_elf_finish_dynamic_sections
9010#define elf_backend_fake_sections ppc_elf_fake_sections
9011#define elf_backend_additional_program_headers ppc_elf_additional_program_headers
c5fccbec
DJ
9012#define elf_backend_grok_prstatus ppc_elf_grok_prstatus
9013#define elf_backend_grok_psinfo ppc_elf_grok_psinfo
183e98be 9014#define elf_backend_write_core_note ppc_elf_write_core_note
29c2fb7c 9015#define elf_backend_reloc_type_class ppc_elf_reloc_type_class
70bccea4
AM
9016#define elf_backend_begin_write_processing ppc_elf_begin_write_processing
9017#define elf_backend_final_write_processing ppc_elf_final_write_processing
9018#define elf_backend_write_section ppc_elf_write_section
551b43fd 9019#define elf_backend_get_sec_type_attr ppc_elf_get_sec_type_attr
4c45e5c9 9020#define elf_backend_plt_sym_val ppc_elf_plt_sym_val
8a696751 9021#define elf_backend_action_discarded ppc_elf_action_discarded
74541ad4 9022#define elf_backend_init_index_section _bfd_elf_init_1_index_section
e054468f 9023#define elf_backend_post_process_headers _bfd_elf_set_osabi
252b5132
RH
9024
9025#include "elf32-target.h"
9d8504b1
PB
9026
9027/* VxWorks Target */
9028
9029#undef TARGET_LITTLE_SYM
9030#undef TARGET_LITTLE_NAME
9031
9032#undef TARGET_BIG_SYM
9033#define TARGET_BIG_SYM bfd_elf32_powerpc_vxworks_vec
9034#undef TARGET_BIG_NAME
9035#define TARGET_BIG_NAME "elf32-powerpc-vxworks"
9036
d5e3d971
PB
9037/* VxWorks uses the elf default section flags for .plt. */
9038static const struct bfd_elf_special_section *
9039ppc_elf_vxworks_get_sec_type_attr (bfd *abfd ATTRIBUTE_UNUSED, asection *sec)
9d8504b1 9040{
d5e3d971
PB
9041 if (sec->name == NULL)
9042 return NULL;
9043
9044 if (strcmp (sec->name, ".plt") == 0)
9045 return _bfd_elf_get_sec_type_attr (abfd, sec);
9046
9047 return ppc_elf_get_sec_type_attr (abfd, sec);
9048}
9d8504b1
PB
9049
9050/* Like ppc_elf_link_hash_table_create, but overrides
9051 appropriately for VxWorks. */
9052static struct bfd_link_hash_table *
9053ppc_elf_vxworks_link_hash_table_create (bfd *abfd)
9054{
9055 struct bfd_link_hash_table *ret;
9056
9057 ret = ppc_elf_link_hash_table_create (abfd);
9058 if (ret)
9059 {
9060 struct ppc_elf_link_hash_table *htab
9061 = (struct ppc_elf_link_hash_table *)ret;
9062 htab->is_vxworks = 1;
4a3dc543 9063 htab->plt_type = PLT_VXWORKS;
9d8504b1
PB
9064 htab->plt_entry_size = VXWORKS_PLT_ENTRY_SIZE;
9065 htab->plt_slot_size = VXWORKS_PLT_ENTRY_SIZE;
9066 htab->plt_initial_entry_size = VXWORKS_PLT_INITIAL_ENTRY_SIZE;
9067 }
9068 return ret;
9069}
9070
9071/* Tweak magic VxWorks symbols as they are loaded. */
9072static bfd_boolean
9073ppc_elf_vxworks_add_symbol_hook (bfd *abfd,
9074 struct bfd_link_info *info,
9075 Elf_Internal_Sym *sym,
9076 const char **namep ATTRIBUTE_UNUSED,
9077 flagword *flagsp ATTRIBUTE_UNUSED,
9078 asection **secp,
9079 bfd_vma *valp)
9080{
9081 if (!elf_vxworks_add_symbol_hook(abfd, info, sym,namep, flagsp, secp,
9082 valp))
9083 return FALSE;
9084
9085 return ppc_elf_add_symbol_hook(abfd, info, sym,namep, flagsp, secp, valp);
9086}
9087
9d8504b1
PB
9088static void
9089ppc_elf_vxworks_final_write_processing (bfd *abfd, bfd_boolean linker)
9090{
9091 ppc_elf_final_write_processing(abfd, linker);
9092 elf_vxworks_final_write_processing(abfd, linker);
9093}
9094
9095/* On VxWorks, we emit relocations against _PROCEDURE_LINKAGE_TABLE_, so
9096 define it. */
9097#undef elf_backend_want_plt_sym
9098#define elf_backend_want_plt_sym 1
9099#undef elf_backend_want_got_plt
9100#define elf_backend_want_got_plt 1
9101#undef elf_backend_got_symbol_offset
9102#define elf_backend_got_symbol_offset 0
9103#undef elf_backend_plt_not_loaded
9104#define elf_backend_plt_not_loaded 0
9105#undef elf_backend_plt_readonly
9106#define elf_backend_plt_readonly 1
9107#undef elf_backend_got_header_size
9108#define elf_backend_got_header_size 12
9109
468392fb
AM
9110#undef bfd_elf32_get_synthetic_symtab
9111
9d8504b1
PB
9112#undef bfd_elf32_bfd_link_hash_table_create
9113#define bfd_elf32_bfd_link_hash_table_create \
9114 ppc_elf_vxworks_link_hash_table_create
9d8504b1
PB
9115#undef elf_backend_add_symbol_hook
9116#define elf_backend_add_symbol_hook \
9117 ppc_elf_vxworks_add_symbol_hook
9118#undef elf_backend_link_output_symbol_hook
9119#define elf_backend_link_output_symbol_hook \
9c72ff84 9120 elf_vxworks_link_output_symbol_hook
9d8504b1
PB
9121#undef elf_backend_final_write_processing
9122#define elf_backend_final_write_processing \
9123 ppc_elf_vxworks_final_write_processing
d5e3d971
PB
9124#undef elf_backend_get_sec_type_attr
9125#define elf_backend_get_sec_type_attr \
9126 ppc_elf_vxworks_get_sec_type_attr
9d8504b1
PB
9127#undef elf_backend_emit_relocs
9128#define elf_backend_emit_relocs \
9129 elf_vxworks_emit_relocs
9130
9131#undef elf32_bed
9132#define elf32_bed ppc_elf_vxworks_bed
e054468f 9133#undef elf_backend_post_process_headers
9d8504b1
PB
9134
9135#include "elf32-target.h"
This page took 1.212225 seconds and 4 git commands to generate.