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