9673e1b3f2c005b691e6d0bf16dc230168fc59c4
[binutils-gdb.git] / bfd / elf32-ppc.c
1 /* PowerPC-specific support for 32-bit ELF
2 Copyright 1994, 1995, 1996 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 2 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 Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
20
21 /* This file is based on a preliminary PowerPC ELF ABI. The
22 information may not match the final PowerPC ELF ABI. It includes
23 suggestions from the in-progress Embedded PowerPC ABI, and that
24 information may also not match. */
25
26 #include "bfd.h"
27 #include "sysdep.h"
28 #include "bfdlink.h"
29 #include "libbfd.h"
30 #include "elf-bfd.h"
31 #include "elf/ppc.h"
32
33 #define USE_RELA /* we want RELA relocations, not REL */
34
35 /* PowerPC relocations defined by the ABIs */
36 enum ppc_reloc_type
37 {
38 R_PPC_NONE = 0,
39 R_PPC_ADDR32 = 1,
40 R_PPC_ADDR24 = 2,
41 R_PPC_ADDR16 = 3,
42 R_PPC_ADDR16_LO = 4,
43 R_PPC_ADDR16_HI = 5,
44 R_PPC_ADDR16_HA = 6,
45 R_PPC_ADDR14 = 7,
46 R_PPC_ADDR14_BRTAKEN = 8,
47 R_PPC_ADDR14_BRNTAKEN = 9,
48 R_PPC_REL24 = 10,
49 R_PPC_REL14 = 11,
50 R_PPC_REL14_BRTAKEN = 12,
51 R_PPC_REL14_BRNTAKEN = 13,
52 R_PPC_GOT16 = 14,
53 R_PPC_GOT16_LO = 15,
54 R_PPC_GOT16_HI = 16,
55 R_PPC_GOT16_HA = 17,
56 R_PPC_PLTREL24 = 18,
57 R_PPC_COPY = 19,
58 R_PPC_GLOB_DAT = 20,
59 R_PPC_JMP_SLOT = 21,
60 R_PPC_RELATIVE = 22,
61 R_PPC_LOCAL24PC = 23,
62 R_PPC_UADDR32 = 24,
63 R_PPC_UADDR16 = 25,
64 R_PPC_REL32 = 26,
65 R_PPC_PLT32 = 27,
66 R_PPC_PLTREL32 = 28,
67 R_PPC_PLT16_LO = 29,
68 R_PPC_PLT16_HI = 30,
69 R_PPC_PLT16_HA = 31,
70 R_PPC_SDAREL16 = 32,
71 R_PPC_SECTOFF = 33,
72 R_PPC_SECTOFF_LO = 34,
73 R_PPC_SECTOFF_HI = 35,
74 R_PPC_SECTOFF_HA = 36,
75
76 /* The remaining relocs are from the Embedded ELF ABI, and are not
77 in the SVR4 ELF ABI. */
78 R_PPC_EMB_NADDR32 = 101,
79 R_PPC_EMB_NADDR16 = 102,
80 R_PPC_EMB_NADDR16_LO = 103,
81 R_PPC_EMB_NADDR16_HI = 104,
82 R_PPC_EMB_NADDR16_HA = 105,
83 R_PPC_EMB_SDAI16 = 106,
84 R_PPC_EMB_SDA2I16 = 107,
85 R_PPC_EMB_SDA2REL = 108,
86 R_PPC_EMB_SDA21 = 109,
87 R_PPC_EMB_MRKREF = 110,
88 R_PPC_EMB_RELSEC16 = 111,
89 R_PPC_EMB_RELST_LO = 112,
90 R_PPC_EMB_RELST_HI = 113,
91 R_PPC_EMB_RELST_HA = 114,
92 R_PPC_EMB_BIT_FLD = 115,
93 R_PPC_EMB_RELSDA = 116,
94
95 /* This is a phony reloc to handle any old fashioned TOC16 references
96 that may still be in object files. */
97 R_PPC_TOC16 = 255,
98
99 R_PPC_max
100 };
101
102 static bfd_reloc_status_type ppc_elf_unsupported_reloc
103 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
104 static bfd_reloc_status_type ppc_elf_std_reloc
105 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
106
107 static reloc_howto_type *ppc_elf_reloc_type_lookup
108 PARAMS ((bfd *abfd, bfd_reloc_code_real_type code));
109 static void ppc_elf_info_to_howto
110 PARAMS ((bfd *abfd, arelent *cache_ptr, Elf32_Internal_Rela *dst));
111 static void ppc_elf_howto_init PARAMS ((void));
112 static boolean ppc_elf_set_private_flags PARAMS ((bfd *, flagword));
113 static boolean ppc_elf_copy_private_bfd_data PARAMS ((bfd *, bfd *));
114 static boolean ppc_elf_merge_private_bfd_data PARAMS ((bfd *, bfd *));
115
116 static boolean ppc_elf_section_from_shdr PARAMS ((bfd *,
117 Elf32_Internal_Shdr *,
118 char *));
119
120 static bfd *ppc_elf_create_dynamic_sections PARAMS ((bfd *abfd,
121 struct bfd_link_info *info));
122
123 static boolean ppc_elf_check_relocs PARAMS ((bfd *,
124 struct bfd_link_info *,
125 asection *,
126 const Elf_Internal_Rela *));
127
128 static boolean ppc_elf_adjust_dynamic_symbol PARAMS ((struct bfd_link_info *,
129 struct elf_link_hash_entry *));
130
131 static boolean ppc_elf_adjust_dynindx PARAMS ((struct elf_link_hash_entry *, PTR));
132
133 static boolean ppc_elf_size_dynamic_sections PARAMS ((bfd *, struct bfd_link_info *));
134
135 static boolean ppc_elf_relocate_section PARAMS ((bfd *,
136 struct bfd_link_info *info,
137 bfd *,
138 asection *,
139 bfd_byte *,
140 Elf_Internal_Rela *relocs,
141 Elf_Internal_Sym *local_syms,
142 asection **));
143
144 static boolean ppc_elf_finish_dynamic_symbol PARAMS ((bfd *,
145 struct bfd_link_info *,
146 struct elf_link_hash_entry *,
147 Elf_Internal_Sym *));
148
149 static boolean ppc_elf_finish_dynamic_sections PARAMS ((bfd *, struct bfd_link_info *));
150
151 #define BRANCH_PREDICT_BIT 0x200000
152
153 /* The name of the dynamic interpreter. This is put in the .interp
154 section. */
155
156 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
157
158 \f
159 static reloc_howto_type *ppc_elf_howto_table[ (int)R_PPC_max ];
160
161 static reloc_howto_type ppc_elf_howto_raw[] =
162 {
163 /* This reloc does nothing. */
164 HOWTO (R_PPC_NONE, /* type */
165 0, /* rightshift */
166 2, /* size (0 = byte, 1 = short, 2 = long) */
167 32, /* bitsize */
168 false, /* pc_relative */
169 0, /* bitpos */
170 complain_overflow_bitfield, /* complain_on_overflow */
171 ppc_elf_std_reloc, /* special_function */
172 "R_PPC_NONE", /* name */
173 false, /* partial_inplace */
174 0, /* src_mask */
175 0, /* dst_mask */
176 false), /* pcrel_offset */
177
178 /* A standard 32 bit relocation. */
179 HOWTO (R_PPC_ADDR32, /* type */
180 0, /* rightshift */
181 2, /* size (0 = byte, 1 = short, 2 = long) */
182 32, /* bitsize */
183 false, /* pc_relative */
184 0, /* bitpos */
185 complain_overflow_bitfield, /* complain_on_overflow */
186 ppc_elf_std_reloc, /* special_function */
187 "R_PPC_ADDR32", /* name */
188 false, /* partial_inplace */
189 0, /* src_mask */
190 0xffffffff, /* dst_mask */
191 false), /* pcrel_offset */
192
193 /* An absolute 26 bit branch; the lower two bits must be zero.
194 FIXME: we don't check that, we just clear them. */
195 HOWTO (R_PPC_ADDR24, /* type */
196 0, /* rightshift */
197 2, /* size (0 = byte, 1 = short, 2 = long) */
198 26, /* bitsize */
199 false, /* pc_relative */
200 0, /* bitpos */
201 complain_overflow_bitfield, /* complain_on_overflow */
202 ppc_elf_std_reloc, /* special_function */
203 "R_PPC_ADDR24", /* name */
204 false, /* partial_inplace */
205 0, /* src_mask */
206 0x3fffffc, /* dst_mask */
207 false), /* pcrel_offset */
208
209 /* A standard 16 bit relocation. */
210 HOWTO (R_PPC_ADDR16, /* type */
211 0, /* rightshift */
212 1, /* size (0 = byte, 1 = short, 2 = long) */
213 16, /* bitsize */
214 false, /* pc_relative */
215 0, /* bitpos */
216 complain_overflow_bitfield, /* complain_on_overflow */
217 ppc_elf_std_reloc, /* special_function */
218 "R_PPC_ADDR16", /* name */
219 false, /* partial_inplace */
220 0, /* src_mask */
221 0xffff, /* dst_mask */
222 false), /* pcrel_offset */
223
224 /* A 16 bit relocation without overflow. */
225 HOWTO (R_PPC_ADDR16_LO, /* type */
226 0, /* rightshift */
227 1, /* size (0 = byte, 1 = short, 2 = long) */
228 16, /* bitsize */
229 false, /* pc_relative */
230 0, /* bitpos */
231 complain_overflow_dont,/* complain_on_overflow */
232 ppc_elf_std_reloc, /* special_function */
233 "R_PPC_ADDR16_LO", /* name */
234 false, /* partial_inplace */
235 0, /* src_mask */
236 0xffff, /* dst_mask */
237 false), /* pcrel_offset */
238
239 /* The high order 16 bits of an address. */
240 HOWTO (R_PPC_ADDR16_HI, /* type */
241 16, /* rightshift */
242 1, /* size (0 = byte, 1 = short, 2 = long) */
243 16, /* bitsize */
244 false, /* pc_relative */
245 0, /* bitpos */
246 complain_overflow_dont, /* complain_on_overflow */
247 ppc_elf_std_reloc, /* special_function */
248 "R_PPC_ADDR16_HI", /* name */
249 false, /* partial_inplace */
250 0, /* src_mask */
251 0xffff, /* dst_mask */
252 false), /* pcrel_offset */
253
254 /* The high order 16 bits of an address, plus 1 if the contents of
255 the low 16 bits, treated as a signed number, is negative. */
256 HOWTO (R_PPC_ADDR16_HA, /* type */
257 16, /* rightshift */
258 1, /* size (0 = byte, 1 = short, 2 = long) */
259 16, /* bitsize */
260 false, /* pc_relative */
261 0, /* bitpos */
262 complain_overflow_dont, /* complain_on_overflow */
263 bfd_elf_generic_reloc, /* special_function */
264 "R_PPC_ADDR16_HA", /* name */
265 false, /* partial_inplace */
266 0, /* src_mask */
267 0xffff, /* dst_mask */
268 false), /* pcrel_offset */
269
270 /* An absolute 16 bit branch; the lower two bits must be zero.
271 FIXME: we don't check that, we just clear them. */
272 HOWTO (R_PPC_ADDR14, /* type */
273 0, /* rightshift */
274 2, /* size (0 = byte, 1 = short, 2 = long) */
275 16, /* bitsize */
276 false, /* pc_relative */
277 0, /* bitpos */
278 complain_overflow_bitfield, /* complain_on_overflow */
279 ppc_elf_std_reloc, /* special_function */
280 "R_PPC_ADDR14", /* name */
281 false, /* partial_inplace */
282 0, /* src_mask */
283 0xfffc, /* dst_mask */
284 false), /* pcrel_offset */
285
286 /* An absolute 16 bit branch, for which bit 10 should be set to
287 indicate that the branch is expected to be taken. The lower two
288 bits must be zero. */
289 HOWTO (R_PPC_ADDR14_BRTAKEN, /* type */
290 0, /* rightshift */
291 2, /* size (0 = byte, 1 = short, 2 = long) */
292 16, /* bitsize */
293 false, /* pc_relative */
294 0, /* bitpos */
295 complain_overflow_bitfield, /* complain_on_overflow */
296 bfd_elf_generic_reloc, /* special_function */
297 "R_PPC_ADDR14_BRTAKEN",/* name */
298 false, /* partial_inplace */
299 0, /* src_mask */
300 0xfffc, /* dst_mask */
301 false), /* pcrel_offset */
302
303 /* An absolute 16 bit branch, for which bit 10 should be set to
304 indicate that the branch is not expected to be taken. The lower
305 two bits must be zero. */
306 HOWTO (R_PPC_ADDR14_BRNTAKEN, /* type */
307 0, /* rightshift */
308 2, /* size (0 = byte, 1 = short, 2 = long) */
309 16, /* bitsize */
310 false, /* pc_relative */
311 0, /* bitpos */
312 complain_overflow_bitfield, /* complain_on_overflow */
313 bfd_elf_generic_reloc, /* special_function */
314 "R_PPC_ADDR14_BRNTAKEN",/* name */
315 false, /* partial_inplace */
316 0, /* src_mask */
317 0xfffc, /* dst_mask */
318 false), /* pcrel_offset */
319
320 /* A relative 26 bit branch; the lower two bits must be zero. */
321 HOWTO (R_PPC_REL24, /* type */
322 0, /* rightshift */
323 2, /* size (0 = byte, 1 = short, 2 = long) */
324 26, /* bitsize */
325 true, /* pc_relative */
326 0, /* bitpos */
327 complain_overflow_signed, /* complain_on_overflow */
328 ppc_elf_std_reloc, /* special_function */
329 "R_PPC_REL24", /* name */
330 false, /* partial_inplace */
331 0, /* src_mask */
332 0x3fffffc, /* dst_mask */
333 true), /* pcrel_offset */
334
335 /* A relative 16 bit branch; the lower two bits must be zero. */
336 HOWTO (R_PPC_REL14, /* type */
337 0, /* rightshift */
338 2, /* size (0 = byte, 1 = short, 2 = long) */
339 16, /* bitsize */
340 true, /* pc_relative */
341 0, /* bitpos */
342 complain_overflow_signed, /* complain_on_overflow */
343 ppc_elf_std_reloc, /* special_function */
344 "R_PPC_REL14", /* name */
345 false, /* partial_inplace */
346 0, /* src_mask */
347 0xfffc, /* dst_mask */
348 true), /* pcrel_offset */
349
350 /* A relative 16 bit branch. Bit 10 should be set to indicate that
351 the branch is expected to be taken. The lower two bits must be
352 zero. */
353 HOWTO (R_PPC_REL14_BRTAKEN, /* type */
354 0, /* rightshift */
355 2, /* size (0 = byte, 1 = short, 2 = long) */
356 16, /* bitsize */
357 true, /* pc_relative */
358 0, /* bitpos */
359 complain_overflow_signed, /* complain_on_overflow */
360 bfd_elf_generic_reloc, /* special_function */
361 "R_PPC_REL14_BRTAKEN", /* name */
362 false, /* partial_inplace */
363 0, /* src_mask */
364 0xfffc, /* dst_mask */
365 true), /* pcrel_offset */
366
367 /* A relative 16 bit branch. Bit 10 should be set to indicate that
368 the branch is not expected to be taken. The lower two bits must
369 be zero. */
370 HOWTO (R_PPC_REL14_BRNTAKEN, /* type */
371 0, /* rightshift */
372 2, /* size (0 = byte, 1 = short, 2 = long) */
373 16, /* bitsize */
374 true, /* pc_relative */
375 0, /* bitpos */
376 complain_overflow_signed, /* complain_on_overflow */
377 bfd_elf_generic_reloc, /* special_function */
378 "R_PPC_REL14_BRNTAKEN",/* name */
379 false, /* partial_inplace */
380 0, /* src_mask */
381 0xfffc, /* dst_mask */
382 true), /* pcrel_offset */
383
384 /* Like R_PPC_ADDR16, but referring to the GOT table entry for the
385 symbol. */
386 HOWTO (R_PPC_GOT16, /* type */
387 0, /* rightshift */
388 1, /* size (0 = byte, 1 = short, 2 = long) */
389 16, /* bitsize */
390 false, /* pc_relative */
391 0, /* bitpos */
392 complain_overflow_signed, /* complain_on_overflow */
393 bfd_elf_generic_reloc, /* special_function */
394 "R_PPC_GOT16", /* name */
395 false, /* partial_inplace */
396 0, /* src_mask */
397 0xffff, /* dst_mask */
398 false), /* pcrel_offset */
399
400 /* Like R_PPC_ADDR16_LO, but referring to the GOT table entry for
401 the symbol. */
402 HOWTO (R_PPC_GOT16_LO, /* type */
403 0, /* rightshift */
404 1, /* size (0 = byte, 1 = short, 2 = long) */
405 16, /* bitsize */
406 false, /* pc_relative */
407 0, /* bitpos */
408 complain_overflow_bitfield, /* complain_on_overflow */
409 bfd_elf_generic_reloc, /* special_function */
410 "R_PPC_GOT16_LO", /* name */
411 false, /* partial_inplace */
412 0, /* src_mask */
413 0xffff, /* dst_mask */
414 false), /* pcrel_offset */
415
416 /* Like R_PPC_ADDR16_HI, but referring to the GOT table entry for
417 the symbol. */
418 HOWTO (R_PPC_GOT16_HI, /* type */
419 16, /* rightshift */
420 1, /* size (0 = byte, 1 = short, 2 = long) */
421 16, /* bitsize */
422 false, /* pc_relative */
423 0, /* bitpos */
424 complain_overflow_bitfield, /* complain_on_overflow */
425 bfd_elf_generic_reloc, /* special_function */
426 "R_PPC_GOT16_HI", /* name */
427 false, /* partial_inplace */
428 0, /* src_mask */
429 0xffff, /* dst_mask */
430 false), /* pcrel_offset */
431
432 /* Like R_PPC_ADDR16_HA, but referring to the GOT table entry for
433 the symbol. FIXME: Not supported. */
434 HOWTO (R_PPC_GOT16_HA, /* type */
435 0, /* rightshift */
436 1, /* size (0 = byte, 1 = short, 2 = long) */
437 16, /* bitsize */
438 false, /* pc_relative */
439 0, /* bitpos */
440 complain_overflow_bitfield, /* complain_on_overflow */
441 ppc_elf_unsupported_reloc, /* special_function */
442 "R_PPC_GOT16_HA", /* name */
443 false, /* partial_inplace */
444 0, /* src_mask */
445 0xffff, /* dst_mask */
446 false), /* pcrel_offset */
447
448 /* Like R_PPC_REL24, but referring to the procedure linkage table
449 entry for the symbol. FIXME: Not supported. */
450 HOWTO (R_PPC_PLTREL24, /* type */
451 0, /* rightshift */
452 2, /* size (0 = byte, 1 = short, 2 = long) */
453 26, /* bitsize */
454 true, /* pc_relative */
455 0, /* bitpos */
456 complain_overflow_signed, /* complain_on_overflow */
457 ppc_elf_unsupported_reloc, /* special_function */
458 "R_PPC_PLTREL24", /* name */
459 false, /* partial_inplace */
460 0, /* src_mask */
461 0x3fffffc, /* dst_mask */
462 true), /* pcrel_offset */
463
464 /* This is used only by the dynamic linker. The symbol should exist
465 both in the object being run and in some shared library. The
466 dynamic linker copies the data addressed by the symbol from the
467 shared library into the object. I have no idea what the purpose
468 of this is. */
469 HOWTO (R_PPC_COPY, /* type */
470 0, /* rightshift */
471 2, /* size (0 = byte, 1 = short, 2 = long) */
472 32, /* bitsize */
473 false, /* pc_relative */
474 0, /* bitpos */
475 complain_overflow_bitfield, /* complain_on_overflow */
476 ppc_elf_unsupported_reloc, /* special_function */
477 "R_PPC_COPY", /* name */
478 false, /* partial_inplace */
479 0, /* src_mask */
480 0, /* dst_mask */
481 false), /* pcrel_offset */
482
483 /* Like R_PPC_ADDR32, but used when setting global offset table
484 entries. */
485 HOWTO (R_PPC_GLOB_DAT, /* type */
486 0, /* rightshift */
487 2, /* size (0 = byte, 1 = short, 2 = long) */
488 32, /* bitsize */
489 false, /* pc_relative */
490 0, /* bitpos */
491 complain_overflow_bitfield, /* complain_on_overflow */
492 ppc_elf_unsupported_reloc, /* special_function */
493 "R_PPC_GLOB_DAT", /* name */
494 false, /* partial_inplace */
495 0, /* src_mask */
496 0xffffffff, /* dst_mask */
497 false), /* pcrel_offset */
498
499 /* Marks a procedure linkage table entry for a symbol. */
500 HOWTO (R_PPC_JMP_SLOT, /* type */
501 0, /* rightshift */
502 2, /* size (0 = byte, 1 = short, 2 = long) */
503 32, /* bitsize */
504 false, /* pc_relative */
505 0, /* bitpos */
506 complain_overflow_bitfield, /* complain_on_overflow */
507 ppc_elf_unsupported_reloc, /* special_function */
508 "R_PPC_JMP_SLOT", /* name */
509 false, /* partial_inplace */
510 0, /* src_mask */
511 0, /* dst_mask */
512 false), /* pcrel_offset */
513
514 /* Used only by the dynamic linker. When the object is run, this
515 longword is set to the load address of the object, plus the
516 addend. */
517 HOWTO (R_PPC_RELATIVE, /* type */
518 0, /* rightshift */
519 2, /* size (0 = byte, 1 = short, 2 = long) */
520 32, /* bitsize */
521 false, /* pc_relative */
522 0, /* bitpos */
523 complain_overflow_bitfield, /* complain_on_overflow */
524 ppc_elf_unsupported_reloc, /* special_function */
525 "R_PPC_RELATIVE", /* name */
526 false, /* partial_inplace */
527 0, /* src_mask */
528 0xffffffff, /* dst_mask */
529 false), /* pcrel_offset */
530
531 /* Like R_PPC_REL24, but uses the value of the symbol within the
532 object rather than the final value. Normally used for
533 _GLOBAL_OFFSET_TABLE_. FIXME: Not supported. */
534 HOWTO (R_PPC_LOCAL24PC, /* type */
535 0, /* rightshift */
536 2, /* size (0 = byte, 1 = short, 2 = long) */
537 26, /* bitsize */
538 true, /* pc_relative */
539 0, /* bitpos */
540 complain_overflow_signed, /* complain_on_overflow */
541 ppc_elf_unsupported_reloc, /* special_function */
542 "R_PPC_LOCAL24PC", /* name */
543 false, /* partial_inplace */
544 0, /* src_mask */
545 0x3fffffc, /* dst_mask */
546 true), /* pcrel_offset */
547
548 /* Like R_PPC_ADDR32, but may be unaligned. */
549 HOWTO (R_PPC_UADDR32, /* type */
550 0, /* rightshift */
551 2, /* size (0 = byte, 1 = short, 2 = long) */
552 32, /* bitsize */
553 false, /* pc_relative */
554 0, /* bitpos */
555 complain_overflow_bitfield, /* complain_on_overflow */
556 ppc_elf_std_reloc, /* special_function */
557 "R_PPC_UADDR32", /* name */
558 false, /* partial_inplace */
559 0, /* src_mask */
560 0xffffffff, /* dst_mask */
561 false), /* pcrel_offset */
562
563 /* Like R_PPC_ADDR16, but may be unaligned. */
564 HOWTO (R_PPC_UADDR16, /* type */
565 0, /* rightshift */
566 1, /* size (0 = byte, 1 = short, 2 = long) */
567 16, /* bitsize */
568 false, /* pc_relative */
569 0, /* bitpos */
570 complain_overflow_bitfield, /* complain_on_overflow */
571 ppc_elf_std_reloc, /* special_function */
572 "R_PPC_UADDR16", /* name */
573 false, /* partial_inplace */
574 0, /* src_mask */
575 0xffff, /* dst_mask */
576 false), /* pcrel_offset */
577
578 /* 32-bit PC relative */
579 HOWTO (R_PPC_REL32, /* type */
580 0, /* rightshift */
581 2, /* size (0 = byte, 1 = short, 2 = long) */
582 32, /* bitsize */
583 true, /* pc_relative */
584 0, /* bitpos */
585 complain_overflow_bitfield, /* complain_on_overflow */
586 ppc_elf_std_reloc, /* special_function */
587 "R_PPC_REL32", /* name */
588 false, /* partial_inplace */
589 0, /* src_mask */
590 0xffffffff, /* dst_mask */
591 true), /* pcrel_offset */
592
593 /* 32-bit relocation to the symbol's procedure linkage table.
594 FIXEME: not supported. */
595 HOWTO (R_PPC_PLT32, /* type */
596 0, /* rightshift */
597 2, /* size (0 = byte, 1 = short, 2 = long) */
598 32, /* bitsize */
599 false, /* pc_relative */
600 0, /* bitpos */
601 complain_overflow_bitfield, /* complain_on_overflow */
602 ppc_elf_unsupported_reloc, /* special_function */
603 "R_PPC_PLT32", /* name */
604 false, /* partial_inplace */
605 0, /* src_mask */
606 0, /* dst_mask */
607 false), /* pcrel_offset */
608
609 /* 32-bit PC relative relocation to the symbol's procedure linkage table.
610 FIXEME: not supported. */
611 HOWTO (R_PPC_PLTREL32, /* type */
612 0, /* rightshift */
613 2, /* size (0 = byte, 1 = short, 2 = long) */
614 32, /* bitsize */
615 true, /* pc_relative */
616 0, /* bitpos */
617 complain_overflow_bitfield, /* complain_on_overflow */
618 ppc_elf_unsupported_reloc, /* special_function */
619 "R_PPC_PLTREL32", /* name */
620 false, /* partial_inplace */
621 0, /* src_mask */
622 0, /* dst_mask */
623 true), /* pcrel_offset */
624
625 /* Like R_PPC_ADDR16_LO, but referring to the PLT table entry for
626 the symbol. */
627 HOWTO (R_PPC_PLT16_LO, /* type */
628 0, /* rightshift */
629 1, /* size (0 = byte, 1 = short, 2 = long) */
630 16, /* bitsize */
631 false, /* pc_relative */
632 0, /* bitpos */
633 complain_overflow_bitfield, /* complain_on_overflow */
634 ppc_elf_unsupported_reloc, /* special_function */
635 "R_PPC_PLT16_LO", /* name */
636 false, /* partial_inplace */
637 0, /* src_mask */
638 0xffff, /* dst_mask */
639 false), /* pcrel_offset */
640
641 /* Like R_PPC_ADDR16_HI, but referring to the PLT table entry for
642 the symbol. */
643 HOWTO (R_PPC_PLT16_HI, /* type */
644 16, /* rightshift */
645 1, /* size (0 = byte, 1 = short, 2 = long) */
646 16, /* bitsize */
647 false, /* pc_relative */
648 0, /* bitpos */
649 complain_overflow_bitfield, /* complain_on_overflow */
650 ppc_elf_unsupported_reloc, /* special_function */
651 "R_PPC_PLT16_HI", /* name */
652 false, /* partial_inplace */
653 0, /* src_mask */
654 0xffff, /* dst_mask */
655 false), /* pcrel_offset */
656
657 /* Like R_PPC_ADDR16_HA, but referring to the PLT table entry for
658 the symbol. FIXME: Not supported. */
659 HOWTO (R_PPC_PLT16_HA, /* type */
660 0, /* rightshift */
661 1, /* size (0 = byte, 1 = short, 2 = long) */
662 16, /* bitsize */
663 false, /* pc_relative */
664 0, /* bitpos */
665 complain_overflow_bitfield, /* complain_on_overflow */
666 ppc_elf_unsupported_reloc, /* special_function */
667 "R_PPC_PLT16_HA", /* name */
668 false, /* partial_inplace */
669 0, /* src_mask */
670 0xffff, /* dst_mask */
671 false), /* pcrel_offset */
672
673 /* A sign-extended 16 bit value relative to _SDA_BASE, for use with
674 small data items. */
675 HOWTO (R_PPC_SDAREL16, /* type */
676 0, /* rightshift */
677 1, /* size (0 = byte, 1 = short, 2 = long) */
678 16, /* bitsize */
679 false, /* pc_relative */
680 0, /* bitpos */
681 complain_overflow_signed, /* complain_on_overflow */
682 bfd_elf_generic_reloc, /* special_function */
683 "R_PPC_SDAREL16", /* name */
684 false, /* partial_inplace */
685 0, /* src_mask */
686 0xffff, /* dst_mask */
687 false), /* pcrel_offset */
688
689 /* These next 4 relocations were added by Sun. */
690 /* 32-bit section relative relocation. FIXME: not supported. */
691 HOWTO (R_PPC_SECTOFF, /* type */
692 0, /* rightshift */
693 2, /* size (0 = byte, 1 = short, 2 = long) */
694 32, /* bitsize */
695 true, /* pc_relative */
696 0, /* bitpos */
697 complain_overflow_bitfield, /* complain_on_overflow */
698 ppc_elf_unsupported_reloc, /* special_function */
699 "R_PPC_SECTOFF", /* name */
700 false, /* partial_inplace */
701 0, /* src_mask */
702 0, /* dst_mask */
703 true), /* pcrel_offset */
704
705 /* 16-bit lower half section relative relocation. FIXME: not supported. */
706 HOWTO (R_PPC_SECTOFF_LO, /* type */
707 0, /* rightshift */
708 1, /* size (0 = byte, 1 = short, 2 = long) */
709 16, /* bitsize */
710 false, /* pc_relative */
711 0, /* bitpos */
712 complain_overflow_bitfield, /* complain_on_overflow */
713 ppc_elf_unsupported_reloc, /* special_function */
714 "R_PPC_SECTOFF_LO", /* name */
715 false, /* partial_inplace */
716 0, /* src_mask */
717 0xffff, /* dst_mask */
718 false), /* pcrel_offset */
719
720 /* 16-bit upper half section relative relocation. FIXME: not supported. */
721 HOWTO (R_PPC_SECTOFF_HI, /* type */
722 16, /* rightshift */
723 1, /* size (0 = byte, 1 = short, 2 = long) */
724 16, /* bitsize */
725 false, /* pc_relative */
726 0, /* bitpos */
727 complain_overflow_bitfield, /* complain_on_overflow */
728 ppc_elf_unsupported_reloc, /* special_function */
729 "R_PPC_SECTOFF_HI", /* name */
730 false, /* partial_inplace */
731 0, /* src_mask */
732 0xffff, /* dst_mask */
733 false), /* pcrel_offset */
734
735 /* 16-bit upper half adjusted section relative relocation. FIXME: not supported. */
736 HOWTO (R_PPC_SECTOFF_HA, /* type */
737 0, /* rightshift */
738 1, /* size (0 = byte, 1 = short, 2 = long) */
739 16, /* bitsize */
740 false, /* pc_relative */
741 0, /* bitpos */
742 complain_overflow_bitfield, /* complain_on_overflow */
743 ppc_elf_unsupported_reloc, /* special_function */
744 "R_PPC_SECTOFF_HA", /* name */
745 false, /* partial_inplace */
746 0, /* src_mask */
747 0xffff, /* dst_mask */
748 false), /* pcrel_offset */
749
750 /* The remaining relocs are from the Embedded ELF ABI, and are not
751 in the SVR4 ELF ABI. */
752
753 /* 32 bit value resulting from the addend minus the symbol */
754 HOWTO (R_PPC_EMB_NADDR32, /* type */
755 0, /* rightshift */
756 2, /* size (0 = byte, 1 = short, 2 = long) */
757 32, /* bitsize */
758 false, /* pc_relative */
759 0, /* bitpos */
760 complain_overflow_bitfield, /* complain_on_overflow */
761 ppc_elf_unsupported_reloc, /* special_function */
762 "R_PPC_EMB_NADDR32", /* name */
763 false, /* partial_inplace */
764 0, /* src_mask */
765 0xffffffff, /* dst_mask */
766 false), /* pcrel_offset */
767
768 /* 16 bit value resulting from the addend minus the symbol */
769 HOWTO (R_PPC_EMB_NADDR16, /* type */
770 0, /* rightshift */
771 1, /* size (0 = byte, 1 = short, 2 = long) */
772 16, /* bitsize */
773 false, /* pc_relative */
774 0, /* bitpos */
775 complain_overflow_bitfield, /* complain_on_overflow */
776 ppc_elf_unsupported_reloc, /* special_function */
777 "R_PPC_EMB_NADDR16", /* name */
778 false, /* partial_inplace */
779 0, /* src_mask */
780 0xffff, /* dst_mask */
781 false), /* pcrel_offset */
782
783 /* 16 bit value resulting from the addend minus the symbol */
784 HOWTO (R_PPC_EMB_NADDR16_LO, /* type */
785 0, /* rightshift */
786 1, /* size (0 = byte, 1 = short, 2 = long) */
787 16, /* bitsize */
788 false, /* pc_relative */
789 0, /* bitpos */
790 complain_overflow_dont,/* complain_on_overflow */
791 ppc_elf_unsupported_reloc, /* special_function */
792 "R_PPC_EMB_ADDR16_LO", /* name */
793 false, /* partial_inplace */
794 0, /* src_mask */
795 0xffff, /* dst_mask */
796 false), /* pcrel_offset */
797
798 /* The high order 16 bits of the addend minus the symbol */
799 HOWTO (R_PPC_EMB_NADDR16_HI, /* type */
800 16, /* rightshift */
801 1, /* size (0 = byte, 1 = short, 2 = long) */
802 16, /* bitsize */
803 false, /* pc_relative */
804 0, /* bitpos */
805 complain_overflow_dont, /* complain_on_overflow */
806 ppc_elf_unsupported_reloc, /* special_function */
807 "R_PPC_EMB_NADDR16_HI", /* name */
808 false, /* partial_inplace */
809 0, /* src_mask */
810 0xffff, /* dst_mask */
811 false), /* pcrel_offset */
812
813 /* The high order 16 bits of the result of the addend minus the address,
814 plus 1 if the contents of the low 16 bits, treated as a signed number,
815 is negative. */
816 HOWTO (R_PPC_EMB_NADDR16_HA, /* type */
817 16, /* rightshift */
818 1, /* size (0 = byte, 1 = short, 2 = long) */
819 16, /* bitsize */
820 false, /* pc_relative */
821 0, /* bitpos */
822 complain_overflow_dont, /* complain_on_overflow */
823 ppc_elf_unsupported_reloc, /* special_function */
824 "R_PPC_EMB_NADDR16_HA", /* name */
825 false, /* partial_inplace */
826 0, /* src_mask */
827 0xffff, /* dst_mask */
828 false), /* pcrel_offset */
829
830 /* Phony reloc to handle AIX style TOC entries */
831 HOWTO (R_PPC_TOC16, /* type */
832 0, /* rightshift */
833 1, /* size (0 = byte, 1 = short, 2 = long) */
834 16, /* bitsize */
835 false, /* pc_relative */
836 0, /* bitpos */
837 complain_overflow_signed, /* complain_on_overflow */
838 bfd_elf_generic_reloc, /* special_function */
839 "R_PPC_TOC16", /* name */
840 false, /* partial_inplace */
841 0, /* src_mask */
842 0xffff, /* dst_mask */
843 false), /* pcrel_offset */
844 };
845
846 \f
847 /* Initialize the ppc_elf_howto_table, so that linear accesses can be done. */
848
849 static void
850 ppc_elf_howto_init ()
851 {
852 unsigned int i, type;
853
854 for (i = 0; i < sizeof (ppc_elf_howto_raw) / sizeof (ppc_elf_howto_raw[0]); i++)
855 {
856 type = ppc_elf_howto_raw[i].type;
857 BFD_ASSERT (type < sizeof(ppc_elf_howto_table) / sizeof(ppc_elf_howto_table[0]));
858 ppc_elf_howto_table[type] = &ppc_elf_howto_raw[i];
859 }
860 }
861
862 \f
863 static reloc_howto_type *
864 ppc_elf_reloc_type_lookup (abfd, code)
865 bfd *abfd;
866 bfd_reloc_code_real_type code;
867 {
868 enum ppc_reloc_type ppc_reloc = R_PPC_NONE;
869
870 if (!ppc_elf_howto_table[ R_PPC_ADDR32 ]) /* Initialize howto table if needed */
871 ppc_elf_howto_init ();
872
873 switch ((int)code)
874 {
875 default:
876 return (reloc_howto_type *)NULL;
877
878 case BFD_RELOC_NONE: ppc_reloc = R_PPC_NONE; break;
879 case BFD_RELOC_32: ppc_reloc = R_PPC_ADDR32; break;
880 case BFD_RELOC_PPC_BA26: ppc_reloc = R_PPC_ADDR24; break;
881 case BFD_RELOC_16: ppc_reloc = R_PPC_ADDR16; break;
882 case BFD_RELOC_LO16: ppc_reloc = R_PPC_ADDR16_LO; break;
883 case BFD_RELOC_HI16: ppc_reloc = R_PPC_ADDR16_HI; break;
884 case BFD_RELOC_HI16_S: ppc_reloc = R_PPC_ADDR16_HA; break;
885 case BFD_RELOC_PPC_BA16: ppc_reloc = R_PPC_ADDR14; break;
886 case BFD_RELOC_PPC_BA16_BRTAKEN: ppc_reloc = R_PPC_ADDR14_BRTAKEN; break;
887 case BFD_RELOC_PPC_BA16_BRNTAKEN: ppc_reloc = R_PPC_ADDR14_BRNTAKEN; break;
888 case BFD_RELOC_PPC_B26: ppc_reloc = R_PPC_REL24; break;
889 case BFD_RELOC_PPC_B16: ppc_reloc = R_PPC_REL14; break;
890 case BFD_RELOC_PPC_B16_BRTAKEN: ppc_reloc = R_PPC_REL14_BRTAKEN; break;
891 case BFD_RELOC_PPC_B16_BRNTAKEN: ppc_reloc = R_PPC_REL14_BRNTAKEN; break;
892 case BFD_RELOC_16_GOTOFF: ppc_reloc = R_PPC_GOT16; break;
893 case BFD_RELOC_LO16_GOTOFF: ppc_reloc = R_PPC_GOT16_LO; break;
894 case BFD_RELOC_HI16_GOTOFF: ppc_reloc = R_PPC_GOT16_HI; break;
895 case BFD_RELOC_HI16_S_GOTOFF: ppc_reloc = R_PPC_GOT16_HA; break;
896 case BFD_RELOC_24_PLT_PCREL: ppc_reloc = R_PPC_PLTREL24; break;
897 case BFD_RELOC_PPC_COPY: ppc_reloc = R_PPC_COPY; break;
898 case BFD_RELOC_PPC_GLOB_DAT: ppc_reloc = R_PPC_GLOB_DAT; break;
899 case BFD_RELOC_PPC_LOCAL24PC: ppc_reloc = R_PPC_LOCAL24PC; break;
900 case BFD_RELOC_32_PCREL: ppc_reloc = R_PPC_REL32; break;
901 case BFD_RELOC_32_PLTOFF: ppc_reloc = R_PPC_PLT32; break;
902 case BFD_RELOC_32_PLT_PCREL: ppc_reloc = R_PPC_PLTREL32; break;
903 case BFD_RELOC_LO16_PLTOFF: ppc_reloc = R_PPC_PLT16_LO; break;
904 case BFD_RELOC_HI16_PLTOFF: ppc_reloc = R_PPC_PLT16_HI; break;
905 case BFD_RELOC_HI16_S_PLTOFF: ppc_reloc = R_PPC_PLT16_HA; break;
906 case BFD_RELOC_GPREL16: ppc_reloc = R_PPC_SDAREL16; break;
907 case BFD_RELOC_32_BASEREL: ppc_reloc = R_PPC_SECTOFF; break;
908 case BFD_RELOC_LO16_BASEREL: ppc_reloc = R_PPC_SECTOFF_LO; break;
909 case BFD_RELOC_HI16_BASEREL: ppc_reloc = R_PPC_SECTOFF_HI; break;
910 case BFD_RELOC_HI16_S_BASEREL: ppc_reloc = R_PPC_SECTOFF_HA; break;
911 case BFD_RELOC_CTOR: ppc_reloc = R_PPC_ADDR32; break;
912 case BFD_RELOC_PPC_TOC16: ppc_reloc = R_PPC_TOC16; break;
913 }
914
915 return ppc_elf_howto_table[ (int)ppc_reloc ];
916 };
917
918 /* Set the howto pointer for a PowerPC ELF reloc. */
919
920 static void
921 ppc_elf_info_to_howto (abfd, cache_ptr, dst)
922 bfd *abfd;
923 arelent *cache_ptr;
924 Elf32_Internal_Rela *dst;
925 {
926 if (!ppc_elf_howto_table[ R_PPC_ADDR32 ]) /* Initialize howto table if needed */
927 ppc_elf_howto_init ();
928
929 BFD_ASSERT (ELF32_R_TYPE (dst->r_info) < (unsigned int) R_PPC_max);
930 cache_ptr->howto = ppc_elf_howto_table[ELF32_R_TYPE (dst->r_info)];
931 }
932
933 /* Function to set whether a module needs the -mrelocatable bit set. */
934
935 static boolean
936 ppc_elf_set_private_flags (abfd, flags)
937 bfd *abfd;
938 flagword flags;
939 {
940 BFD_ASSERT (!elf_flags_init (abfd)
941 || elf_elfheader (abfd)->e_flags == flags);
942
943 elf_elfheader (abfd)->e_flags = flags;
944 elf_flags_init (abfd) = true;
945 return true;
946 }
947
948 /* Copy backend specific data from one object module to another */
949 static boolean
950 ppc_elf_copy_private_bfd_data (ibfd, obfd)
951 bfd *ibfd;
952 bfd *obfd;
953 {
954 /* This function is selected based on the input vector. We only
955 want to copy information over if the output BFD also uses Elf
956 format. */
957 if (bfd_get_flavour (obfd) != bfd_target_elf_flavour)
958 return true;
959
960 BFD_ASSERT (!elf_flags_init (obfd)
961 || elf_elfheader (obfd)->e_flags == elf_elfheader (ibfd)->e_flags);
962
963 elf_elfheader (obfd)->e_flags = elf_elfheader (ibfd)->e_flags;
964 elf_flags_init (obfd) = true;
965 return true;
966 }
967
968 /* Merge backend specific data from an object file to the output
969 object file when linking */
970 static boolean
971 ppc_elf_merge_private_bfd_data (ibfd, obfd)
972 bfd *ibfd;
973 bfd *obfd;
974 {
975 flagword old_flags;
976 flagword new_flags;
977 boolean error;
978
979 /* Check if we have the same endianess */
980 if (ibfd->xvec->byteorder != obfd->xvec->byteorder
981 && obfd->xvec->byteorder != BFD_ENDIAN_UNKNOWN)
982 {
983 (*_bfd_error_handler)
984 ("%s: compiled for a %s endian system and target is %s endian",
985 bfd_get_filename (ibfd),
986 bfd_big_endian (ibfd) ? "big" : "little",
987 bfd_big_endian (obfd) ? "big" : "little");
988
989 bfd_set_error (bfd_error_wrong_format);
990 return false;
991 }
992
993 /* This function is selected based on the input vector. We only
994 want to copy information over if the output BFD also uses Elf
995 format. */
996 if (bfd_get_flavour (obfd) != bfd_target_elf_flavour)
997 return true;
998
999 new_flags = elf_elfheader (ibfd)->e_flags;
1000 old_flags = elf_elfheader (obfd)->e_flags;
1001 if (!elf_flags_init (obfd)) /* First call, no flags set */
1002 {
1003 elf_flags_init (obfd) = true;
1004 elf_elfheader (obfd)->e_flags = new_flags;
1005 }
1006
1007 else if (new_flags == old_flags) /* Compatible flags are ok */
1008 ;
1009
1010 else /* Incompatible flags */
1011 {
1012 /* Warn about -mrelocatable mismatch. Allow -mrelocatable-lib to be linked
1013 with either. */
1014 error = false;
1015 if ((new_flags & EF_PPC_RELOCATABLE) != 0
1016 && (old_flags & (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB)) == 0)
1017 {
1018 error = true;
1019 (*_bfd_error_handler)
1020 ("%s: compiled with -mrelocatable and linked with modules compiled normally",
1021 bfd_get_filename (ibfd));
1022 }
1023 else if ((new_flags & (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB)) == 0
1024 && (old_flags & EF_PPC_RELOCATABLE) != 0)
1025 {
1026 error = true;
1027 (*_bfd_error_handler)
1028 ("%s: compiled normally and linked with modules compiled with -mrelocatable",
1029 bfd_get_filename (ibfd));
1030 }
1031 else if ((new_flags & EF_PPC_RELOCATABLE_LIB) != 0)
1032 elf_elfheader (obfd)->e_flags |= EF_PPC_RELOCATABLE_LIB;
1033
1034 new_flags &= ~ (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB);
1035 old_flags &= ~ (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB);
1036
1037 /* Warn about eabi vs. V.4 mismatch */
1038 if ((new_flags & EF_PPC_EMB) != 0 && (old_flags & EF_PPC_EMB) == 0)
1039 {
1040 new_flags &= ~EF_PPC_EMB;
1041 error = true;
1042 (*_bfd_error_handler)
1043 ("%s: compiled for the eabi and linked with modules compiled for System V",
1044 bfd_get_filename (ibfd));
1045 }
1046 else if ((new_flags & EF_PPC_EMB) == 0 && (old_flags & EF_PPC_EMB) != 0)
1047 {
1048 old_flags &= ~EF_PPC_EMB;
1049 error = true;
1050 (*_bfd_error_handler)
1051 ("%s: compiled for System V and linked with modules compiled for eabi",
1052 bfd_get_filename (ibfd));
1053 }
1054
1055 /* Warn about any other mismatches */
1056 if (new_flags != old_flags)
1057 {
1058 error = true;
1059 (*_bfd_error_handler)
1060 ("%s: uses different e_flags (0x%lx) fields than previous modules (0x%lx)",
1061 bfd_get_filename (ibfd), (long)new_flags, (long)old_flags);
1062 }
1063
1064 if (error)
1065 {
1066 bfd_set_error (bfd_error_bad_value);
1067 return false;
1068 }
1069 }
1070
1071 return true;
1072 }
1073
1074 \f
1075 /* ELF relocs are against symbols. If we are producing relocateable
1076 output, and the reloc is against an external symbol, and nothing
1077 has given us any additional addend, the resulting reloc will also
1078 be against the same symbol. In such a case, we don't want to
1079 change anything about the way the reloc is handled, since it will
1080 all be done at final link time. Rather than put special case code
1081 into bfd_perform_relocation, all the reloc types use this howto
1082 function. It just short circuits the reloc if producing
1083 relocateable output against an external symbol. */
1084
1085 /*ARGSUSED*/
1086 static bfd_reloc_status_type
1087 ppc_elf_std_reloc (abfd,
1088 reloc_entry,
1089 symbol,
1090 data,
1091 input_section,
1092 output_bfd,
1093 error_message)
1094 bfd *abfd;
1095 arelent *reloc_entry;
1096 asymbol *symbol;
1097 PTR data;
1098 asection *input_section;
1099 bfd *output_bfd;
1100 char **error_message;
1101 {
1102 if (output_bfd != (bfd *) NULL
1103 && (symbol->flags & BSF_SECTION_SYM) == 0
1104 && (! reloc_entry->howto->partial_inplace || reloc_entry->addend == 0))
1105 {
1106 reloc_entry->address += input_section->output_offset;
1107 return bfd_reloc_ok;
1108 }
1109
1110 return bfd_reloc_continue;
1111 }
1112
1113 /* Don't pretend we can deal with unsupported relocs. */
1114
1115 /*ARGSUSED*/
1116 static bfd_reloc_status_type
1117 ppc_elf_unsupported_reloc (abfd, reloc_entry, symbol, data, input_section,
1118 output_bfd, error_message)
1119 bfd *abfd;
1120 arelent *reloc_entry;
1121 asymbol *symbol;
1122 PTR data;
1123 asection *input_section;
1124 bfd *output_bfd;
1125 char **error_message;
1126 {
1127 BFD_ASSERT (reloc_entry->howto != (reloc_howto_type *)0);
1128 (*_bfd_error_handler)
1129 ("%s: relocation %s (%d) is not currently supported",
1130 bfd_get_filename (abfd),
1131 reloc_entry->howto->name,
1132 reloc_entry->howto->type);
1133
1134 return bfd_reloc_notsupported;
1135 }
1136
1137 \f
1138 /* Handle a PowerPC specific section when reading an object file. This
1139 is called when elfcode.h finds a section with an unknown type. */
1140
1141 static boolean
1142 ppc_elf_section_from_shdr (abfd, hdr, name)
1143 bfd *abfd;
1144 Elf32_Internal_Shdr *hdr;
1145 char *name;
1146 {
1147 asection *newsect;
1148 flagword flags;
1149
1150 if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name))
1151 return false;
1152
1153 newsect = hdr->bfd_section;
1154 flags = bfd_get_section_flags (abfd, newsect);
1155 if (hdr->sh_flags & SHF_EXCLUDE)
1156 flags |= SEC_EXCLUDE;
1157
1158 if (hdr->sh_type == SHT_ORDERED)
1159 flags |= SEC_SORT_ENTRIES;
1160
1161 bfd_set_section_flags (abfd, newsect, flags);
1162 return true;
1163 }
1164
1165 \f
1166 /* Set up any other section flags and such that may be necessary. */
1167
1168 boolean
1169 ppc_elf_fake_sections (abfd, shdr, asect)
1170 bfd *abfd;
1171 Elf32_Internal_Shdr *shdr;
1172 asection *asect;
1173 {
1174 if ((asect->flags & SEC_EXCLUDE) != 0)
1175 shdr->sh_flags |= SHF_EXCLUDE;
1176
1177 if ((asect->flags & SEC_SORT_ENTRIES) != 0)
1178 shdr->sh_type = SHT_ORDERED;
1179 }
1180
1181 \f
1182 /* Create the PowerPC dynamic sections */
1183
1184 static bfd *
1185 ppc_elf_create_dynamic_sections (abfd, info)
1186 bfd *abfd;
1187 struct bfd_link_info *info;
1188 {
1189 struct elf_link_hash_entry *h;
1190 struct elf_backend_data *bed = get_elf_backend_data (abfd);
1191
1192 /* Create the .got section. */
1193 if (! _bfd_elf_create_got_section (abfd, info))
1194 return (bfd *)0;
1195
1196 /* Also create the .got.neg section where we put negative offsets */
1197 if (bfd_get_section_by_name (abfd, ".got.neg") == NULL)
1198 {
1199 asection *s = bfd_make_section (abfd, ".got.neg");
1200 if (s == NULL
1201 || !bfd_set_section_flags (abfd, s,
1202 SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY)
1203 || !bfd_set_section_alignment (abfd, s, 2))
1204 return (bfd *)0;
1205 }
1206
1207 elf_hash_table (info)->dynobj = abfd;
1208 return abfd;
1209 }
1210
1211 \f
1212 /* Adjust a symbol defined by a dynamic object and referenced by a
1213 regular object. The current definition is in some section of the
1214 dynamic object, but we're not including those sections. We have to
1215 change the definition to something the rest of the link can
1216 understand. */
1217
1218 static boolean
1219 ppc_elf_adjust_dynamic_symbol (info, h)
1220 struct bfd_link_info *info;
1221 struct elf_link_hash_entry *h;
1222 {
1223 #ifdef DEBUG
1224 fprintf (stderr, "ppc_elf_adjust_dynamic_symbol called\n");
1225 #endif
1226 return true;
1227 }
1228
1229 \f
1230 /* Increment the index of a dynamic symbol by a given amount. Called
1231 via elf_link_hash_traverse. */
1232
1233 static boolean
1234 ppc_elf_adjust_dynindx (h, cparg)
1235 struct elf_link_hash_entry *h;
1236 PTR cparg;
1237 {
1238 int *cp = (int *) cparg;
1239
1240 #ifdef DEBUG
1241 fprintf (stderr, "ppc_elf_adjust_dynindx called, h->dynindx = %d, *cp = %d\n", h->dynindx, *cp);
1242 #endif
1243
1244 if (h->dynindx != -1)
1245 h->dynindx += *cp;
1246
1247 return true;
1248 }
1249
1250 \f
1251 /* Set the sizes of the dynamic sections. */
1252
1253 static boolean
1254 ppc_elf_size_dynamic_sections (output_bfd, info)
1255 bfd *output_bfd;
1256 struct bfd_link_info *info;
1257 {
1258 bfd *dynobj;
1259 asection *s;
1260 boolean reltext;
1261 boolean relplt;
1262
1263 #ifdef DEBUG
1264 fprintf (stderr, "ppc_elf_size_dynamic_sections called\n");
1265 #endif
1266
1267 dynobj = elf_hash_table (info)->dynobj;
1268 BFD_ASSERT (dynobj != NULL);
1269
1270 if (elf_hash_table (info)->dynamic_sections_created)
1271 {
1272 /* Set the contents of the .interp section to the interpreter. */
1273 if (! info->shared)
1274 {
1275 s = bfd_get_section_by_name (dynobj, ".interp");
1276 BFD_ASSERT (s != NULL);
1277 s->_raw_size = sizeof ELF_DYNAMIC_INTERPRETER;
1278 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
1279 }
1280
1281 /* Make space for the trailing nop in .plt. */
1282 s = bfd_get_section_by_name (dynobj, ".plt");
1283 BFD_ASSERT (s != NULL);
1284 if (s->_raw_size > 0)
1285 s->_raw_size += 4;
1286 }
1287 else
1288 {
1289 /* We may have created entries in the .rela.got section.
1290 However, if we are not creating the dynamic sections, we will
1291 not actually use these entries. Reset the size of .rela.got,
1292 which will cause it to get stripped from the output file
1293 below. */
1294 s = bfd_get_section_by_name (dynobj, ".rela.got");
1295 if (s != NULL)
1296 s->_raw_size = 0;
1297
1298 /* Ditto for .rela.got.neg */
1299 s = bfd_get_section_by_name (dynobj, ".rela.got.neg");
1300 if (s != NULL)
1301 s->_raw_size = 0;
1302 }
1303
1304 /* The check_relocs and adjust_dynamic_symbol entry points have
1305 determined the sizes of the various dynamic sections. Allocate
1306 memory for them. */
1307 reltext = false;
1308 relplt = false;
1309 for (s = dynobj->sections; s != NULL; s = s->next)
1310 {
1311 const char *name;
1312 boolean strip;
1313
1314 if ((s->flags & SEC_IN_MEMORY) == 0)
1315 continue;
1316
1317 /* It's OK to base decisions on the section name, because none
1318 of the dynobj section names depend upon the input files. */
1319 name = bfd_get_section_name (dynobj, s);
1320
1321 strip = false;
1322
1323 if (strncmp (name, ".rela", 5) == 0)
1324 {
1325 if (s->_raw_size == 0)
1326 {
1327 /* If we don't need this section, strip it from the
1328 output file. This is to handle .rela.bss and
1329 .rel.plt. We must create it in
1330 create_dynamic_sections, because it must be created
1331 before the linker maps input sections to output
1332 sections. The linker does that before
1333 adjust_dynamic_symbol is called, and it is that
1334 function which decides whether anything needs to go
1335 into these sections. */
1336 strip = true;
1337 }
1338 else
1339 {
1340 asection *target;
1341
1342 /* If this relocation section applies to a read only
1343 section, then we probably need a DT_TEXTREL entry. */
1344 target = bfd_get_section_by_name (output_bfd, name + 5);
1345 if (target != NULL
1346 && (target->flags & SEC_READONLY) != 0)
1347 reltext = true;
1348
1349 if (strcmp (name, ".rela.plt") == 0)
1350 relplt = true;
1351
1352 /* We use the reloc_count field as a counter if we need
1353 to copy relocs into the output file. */
1354 s->reloc_count = 0;
1355 }
1356 }
1357 else if (strcmp (name, ".plt") != 0
1358 && strcmp (name, ".got") != 0
1359 && strcmp (name, ".got.neg") != 0)
1360 {
1361 /* It's not one of our sections, so don't allocate space. */
1362 continue;
1363 }
1364
1365 if (strip)
1366 {
1367 asection **spp;
1368
1369 for (spp = &s->output_section->owner->sections;
1370 *spp != s->output_section;
1371 spp = &(*spp)->next)
1372 ;
1373 *spp = s->output_section->next;
1374 --s->output_section->owner->section_count;
1375
1376 continue;
1377 }
1378
1379 /* Allocate memory for the section contents. */
1380 s->contents = (bfd_byte *) bfd_alloc (dynobj, s->_raw_size);
1381 if (s->contents == NULL && s->_raw_size != 0)
1382 return false;
1383 }
1384
1385 if (elf_hash_table (info)->dynamic_sections_created)
1386 {
1387 /* Add some entries to the .dynamic section. We fill in the
1388 values later, in ppc_elf_finish_dynamic_sections, but we
1389 must add the entries now so that we get the correct size for
1390 the .dynamic section. The DT_DEBUG entry is filled in by the
1391 dynamic linker and used by the debugger. */
1392 if (! info->shared)
1393 {
1394 if (! bfd_elf32_add_dynamic_entry (info, DT_DEBUG, 0))
1395 return false;
1396 }
1397
1398 if (! bfd_elf32_add_dynamic_entry (info, DT_PLTGOT, 0))
1399 return false;
1400
1401 if (relplt)
1402 {
1403 if (! bfd_elf32_add_dynamic_entry (info, DT_PLTRELSZ, 0)
1404 || ! bfd_elf32_add_dynamic_entry (info, DT_PLTREL, DT_RELA)
1405 || ! bfd_elf32_add_dynamic_entry (info, DT_JMPREL, 0))
1406 return false;
1407 }
1408
1409 if (! bfd_elf32_add_dynamic_entry (info, DT_RELA, 0)
1410 || ! bfd_elf32_add_dynamic_entry (info, DT_RELASZ, 0)
1411 || ! bfd_elf32_add_dynamic_entry (info, DT_RELAENT,
1412 sizeof (Elf32_External_Rela)))
1413 return false;
1414
1415 if (reltext)
1416 {
1417 if (! bfd_elf32_add_dynamic_entry (info, DT_TEXTREL, 0))
1418 return false;
1419 }
1420 }
1421
1422 /* If we are generating a shared library, we generate a section
1423 symbol for each output section. These are local symbols, which
1424 means that they must come first in the dynamic symbol table.
1425 That means we must increment the dynamic symbol index of every
1426 other dynamic symbol. */
1427 if (info->shared)
1428 {
1429 int c, i;
1430
1431 c = bfd_count_sections (output_bfd);
1432 elf_link_hash_traverse (elf_hash_table (info),
1433 ppc_elf_adjust_dynindx,
1434 (PTR) &c);
1435 elf_hash_table (info)->dynsymcount += c;
1436
1437 for (i = 1, s = output_bfd->sections; s != NULL; s = s->next, i++)
1438 {
1439 elf_section_data (s)->dynindx = i;
1440 /* These symbols will have no names, so we don't need to
1441 fiddle with dynstr_index. */
1442 }
1443 }
1444
1445 return true;
1446 }
1447
1448 \f
1449 /* Look through the relocs for a section during the first phase, and
1450 allocate space in the global offset table or procedure linkage
1451 table. */
1452
1453 static boolean
1454 ppc_elf_check_relocs (abfd, info, sec, relocs)
1455 bfd *abfd;
1456 struct bfd_link_info *info;
1457 asection *sec;
1458 const Elf_Internal_Rela *relocs;
1459 {
1460 bfd *dynobj;
1461 Elf_Internal_Shdr *symtab_hdr;
1462 struct elf_link_hash_entry **sym_hashes;
1463 bfd_vma *local_got_offsets;
1464 const Elf_Internal_Rela *rel;
1465 const Elf_Internal_Rela *rel_end;
1466 asection *sgot;
1467 asection *sgot_neg;
1468 asection *srelgot;
1469 asection *srelgot_neg;
1470 asection *sreloc;
1471
1472 if (info->relocateable)
1473 return true;
1474
1475 #ifdef DEBUG
1476 fprintf (stderr, "ppc_elf_check_relocs called for section %s\n", sec->name);
1477 #endif
1478
1479 dynobj = elf_hash_table (info)->dynobj;
1480 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
1481 sym_hashes = elf_sym_hashes (abfd);
1482 local_got_offsets = elf_local_got_offsets (abfd);
1483
1484 sgot = NULL;
1485 srelgot = NULL;
1486 sreloc = NULL;
1487
1488 rel_end = relocs + sec->reloc_count;
1489 for (rel = relocs; rel < rel_end; rel++)
1490 {
1491 unsigned long r_symndx;
1492 struct elf_link_hash_entry *h;
1493
1494 r_symndx = ELF32_R_SYM (rel->r_info);
1495 if (r_symndx < symtab_hdr->sh_info)
1496 h = NULL;
1497 else
1498 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
1499
1500 switch (ELF32_R_TYPE (rel->r_info))
1501 {
1502 case R_PPC_GOT16:
1503 case R_PPC_GOT16_LO:
1504 case R_PPC_GOT16_HI:
1505 case R_PPC_GOT16_HA:
1506 #ifdef DEBUG
1507 fprintf (stderr, "Reloc requires a GOT entry\n");
1508 #endif
1509 /* This symbol requires a global offset table entry. */
1510
1511 if (dynobj == NULL)
1512 {
1513 dynobj = ppc_elf_create_dynamic_sections (abfd, info);
1514 if (!dynobj)
1515 return false;
1516 }
1517
1518 if (sgot == NULL)
1519 {
1520 sgot = bfd_get_section_by_name (dynobj, ".got");
1521 sgot_neg = bfd_get_section_by_name (dynobj, ".got.neg");
1522 BFD_ASSERT (sgot != NULL && sgot_neg != NULL);
1523 }
1524
1525 if (srelgot == NULL
1526 && (h != NULL || info->shared))
1527 {
1528 srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
1529 if (srelgot == NULL)
1530 {
1531 srelgot = bfd_make_section (dynobj, ".rela.got");
1532 if (srelgot == NULL
1533 || ! bfd_set_section_flags (dynobj, srelgot,
1534 (SEC_ALLOC
1535 | SEC_LOAD
1536 | SEC_HAS_CONTENTS
1537 | SEC_IN_MEMORY
1538 | SEC_READONLY))
1539 || ! bfd_set_section_alignment (dynobj, srelgot, 2))
1540 return false;
1541 }
1542
1543 srelgot_neg = bfd_get_section_by_name (dynobj, ".rela.got.neg");
1544 if (srelgot_neg == NULL)
1545 {
1546 srelgot_neg = bfd_make_section (dynobj, ".rela.got.neg");
1547 if (srelgot == NULL
1548 || ! bfd_set_section_flags (dynobj, srelgot_neg,
1549 (SEC_ALLOC
1550 | SEC_LOAD
1551 | SEC_HAS_CONTENTS
1552 | SEC_IN_MEMORY
1553 | SEC_READONLY))
1554 || ! bfd_set_section_alignment (dynobj, srelgot, 2))
1555 return false;
1556 }
1557 }
1558
1559 if (h != NULL)
1560 {
1561 if (h->got_offset != (bfd_vma) -1)
1562 {
1563 /* We have already allocated space in the .got. */
1564 break;
1565 }
1566 h->got_offset = sgot->_raw_size;
1567
1568 /* Make sure this symbol is output as a dynamic symbol. */
1569 if (h->dynindx == -1)
1570 {
1571 if (! bfd_elf32_link_record_dynamic_symbol (info, h))
1572 return false;
1573 }
1574
1575 srelgot->_raw_size += sizeof (Elf32_External_Rela);
1576 }
1577 else
1578 {
1579 /* This is a global offset table entry for a local
1580 symbol. */
1581 if (local_got_offsets == NULL)
1582 {
1583 size_t size;
1584 register unsigned int i;
1585
1586 size = symtab_hdr->sh_info * sizeof (bfd_vma);
1587 local_got_offsets = (bfd_vma *) bfd_alloc (abfd, size);
1588 if (local_got_offsets == NULL)
1589 return false;
1590 elf_local_got_offsets (abfd) = local_got_offsets;
1591 for (i = 0; i < symtab_hdr->sh_info; i++)
1592 local_got_offsets[i] = (bfd_vma) -1;
1593 }
1594 if (local_got_offsets[r_symndx] != (bfd_vma) -1)
1595 {
1596 /* We have already allocated space in the .got. */
1597 break;
1598 }
1599 local_got_offsets[r_symndx] = sgot->_raw_size;
1600
1601 if (info->shared)
1602 {
1603 /* If we are generating a shared object, we need to
1604 output a R_PPC_RELATIVE reloc so that the
1605 dynamic linker can adjust this GOT entry. */
1606 srelgot->_raw_size += sizeof (Elf32_External_Rela);
1607 }
1608 }
1609
1610 sgot->_raw_size += 4;
1611
1612 break;
1613
1614 case R_PPC_PLT32:
1615 case R_PPC_PLTREL24:
1616 case R_PPC_PLT16_LO:
1617 case R_PPC_PLT16_HI:
1618 case R_PPC_PLT16_HA:
1619 #ifdef DEBUG
1620 fprintf (stderr, "Reloc requires a PLT entry\n");
1621 #endif
1622 /* This symbol requires a procedure linkage table entry. We
1623 actually build the entry in adjust_dynamic_symbol,
1624 because this might be a case of linking PIC code without
1625 linking in any dynamic objects, in which case we don't
1626 need to generate a procedure linkage table after all. */
1627
1628 if (h == NULL)
1629 {
1630 /* It does not make sense to have a procedure linkage
1631 table entry for a local symbol. */
1632 bfd_set_error (bfd_error_bad_value);
1633 return false;
1634 }
1635
1636 /* Make sure this symbol is output as a dynamic symbol. */
1637 if (h->dynindx == -1)
1638 {
1639 if (! bfd_elf32_link_record_dynamic_symbol (info, h))
1640 return false;
1641 }
1642
1643 h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
1644 break;
1645
1646 #if 0
1647 case R_SPARC_PC10:
1648 case R_SPARC_PC22:
1649 if (h != NULL
1650 && strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
1651 break;
1652 /* Fall through. */
1653 case R_SPARC_DISP8:
1654 case R_SPARC_DISP16:
1655 case R_SPARC_DISP32:
1656 case R_SPARC_WDISP30:
1657 case R_SPARC_WDISP22:
1658 if (h == NULL)
1659 break;
1660 /* Fall through. */
1661 case R_SPARC_8:
1662 case R_SPARC_16:
1663 case R_SPARC_32:
1664 case R_SPARC_HI22:
1665 case R_SPARC_22:
1666 case R_SPARC_13:
1667 case R_SPARC_LO10:
1668 case R_SPARC_UA32:
1669 if (info->shared
1670 && (sec->flags & SEC_ALLOC) != 0)
1671 {
1672 /* When creating a shared object, we must copy these
1673 relocs into the output file. We create a reloc
1674 section in dynobj and make room for the reloc. */
1675 if (sreloc == NULL)
1676 {
1677 const char *name;
1678
1679 name = (bfd_elf_string_from_elf_section
1680 (abfd,
1681 elf_elfheader (abfd)->e_shstrndx,
1682 elf_section_data (sec)->rel_hdr.sh_name));
1683 if (name == NULL)
1684 return false;
1685
1686 BFD_ASSERT (strncmp (name, ".rela", 5) == 0
1687 && strcmp (bfd_get_section_name (abfd, sec),
1688 name + 5) == 0);
1689
1690 sreloc = bfd_get_section_by_name (dynobj, name);
1691 if (sreloc == NULL)
1692 {
1693 sreloc = bfd_make_section (dynobj, name);
1694 if (sreloc == NULL
1695 || ! bfd_set_section_flags (dynobj, sreloc,
1696 (SEC_ALLOC
1697 | SEC_LOAD
1698 | SEC_HAS_CONTENTS
1699 | SEC_IN_MEMORY
1700 | SEC_READONLY))
1701 || ! bfd_set_section_alignment (dynobj, sreloc, 2))
1702 return false;
1703 }
1704 }
1705
1706 sreloc->_raw_size += sizeof (Elf32_External_Rela);
1707 }
1708
1709 break;
1710 #endif
1711
1712 default:
1713 break;
1714 }
1715 }
1716
1717 return true;
1718 }
1719
1720 \f
1721 /* Finish up dynamic symbol handling. We set the contents of various
1722 dynamic sections here. */
1723
1724 static boolean
1725 ppc_elf_finish_dynamic_symbol (output_bfd, info, h, sym)
1726 bfd *output_bfd;
1727 struct bfd_link_info *info;
1728 struct elf_link_hash_entry *h;
1729 Elf_Internal_Sym *sym;
1730 {
1731 bfd *dynobj;
1732
1733 #ifdef DEBUG
1734 fprintf (stderr, "ppc_elf_finish_dynamic_symbol called\n");
1735 #endif
1736
1737 dynobj = elf_hash_table (info)->dynobj;
1738
1739 if (h->plt_offset != (bfd_vma) -1)
1740 {
1741 asection *splt;
1742 asection *srela;
1743 Elf_Internal_Rela rela;
1744
1745 /* This symbol has an entry in the procedure linkage table. Set
1746 it up. */
1747
1748 BFD_ASSERT (h->dynindx != -1);
1749
1750 splt = bfd_get_section_by_name (dynobj, ".plt");
1751 srela = bfd_get_section_by_name (dynobj, ".rela.plt");
1752 BFD_ASSERT (splt != NULL && srela != NULL);
1753
1754 /* Fill in the entry in the procedure linkage table. */
1755 #if 0
1756 bfd_put_32 (output_bfd,
1757 PLT_ENTRY_WORD0 + h->plt_offset,
1758 splt->contents + h->plt_offset);
1759 bfd_put_32 (output_bfd,
1760 (PLT_ENTRY_WORD1
1761 + (((- (h->plt_offset + 4)) >> 2) & 0x3fffff)),
1762 splt->contents + h->plt_offset + 4);
1763 bfd_put_32 (output_bfd, PLT_ENTRY_WORD2,
1764 splt->contents + h->plt_offset + 8);
1765
1766 /* Fill in the entry in the .rela.plt section. */
1767 rela.r_offset = (splt->output_section->vma
1768 + splt->output_offset
1769 + h->plt_offset);
1770 rela.r_info = ELF32_R_INFO (h->dynindx, R_SPARC_JMP_SLOT);
1771 rela.r_addend = 0;
1772 bfd_elf32_swap_reloca_out (output_bfd, &rela,
1773 ((Elf32_External_Rela *) srela->contents
1774 + h->plt_offset / PLT_ENTRY_SIZE - 4));
1775 #endif
1776
1777 if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
1778 {
1779 /* Mark the symbol as undefined, rather than as defined in
1780 the .plt section. Leave the value alone. */
1781 sym->st_shndx = SHN_UNDEF;
1782 }
1783 }
1784
1785 if (h->got_offset != (bfd_vma) -1)
1786 {
1787 asection *sgot;
1788 asection *srela;
1789 Elf_Internal_Rela rela;
1790
1791 /* This symbol has an entry in the global offset table. Set it
1792 up. */
1793
1794 BFD_ASSERT (h->dynindx != -1);
1795
1796 sgot = bfd_get_section_by_name (dynobj, ".got");
1797 srela = bfd_get_section_by_name (dynobj, ".rela.got");
1798 BFD_ASSERT (sgot != NULL && srela != NULL);
1799
1800 rela.r_offset = (sgot->output_section->vma
1801 + sgot->output_offset
1802 + (h->got_offset &~ 1));
1803
1804 /* If this is a -Bsymbolic link, and the symbol is defined
1805 locally, we just want to emit a RELATIVE reloc. The entry in
1806 the global offset table will already have been initialized in
1807 the relocate_section function. */
1808 if (info->shared
1809 && info->symbolic
1810 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR))
1811 rela.r_info = ELF32_R_INFO (0, R_PPC_RELATIVE);
1812 else
1813 {
1814 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + h->got_offset);
1815 rela.r_info = ELF32_R_INFO (h->dynindx, R_PPC_GLOB_DAT);
1816 }
1817
1818 rela.r_addend = 0;
1819 bfd_elf32_swap_reloca_out (output_bfd, &rela,
1820 ((Elf32_External_Rela *) srela->contents
1821 + srela->reloc_count));
1822 ++srela->reloc_count;
1823 }
1824
1825 if ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_COPY) != 0)
1826 {
1827 asection *s;
1828 Elf_Internal_Rela rela;
1829
1830 /* This symbols needs a copy reloc. Set it up. */
1831
1832 BFD_ASSERT (h->dynindx != -1);
1833
1834 s = bfd_get_section_by_name (h->root.u.def.section->owner,
1835 ".rela.bss");
1836 BFD_ASSERT (s != NULL);
1837
1838 rela.r_offset = (h->root.u.def.value
1839 + h->root.u.def.section->output_section->vma
1840 + h->root.u.def.section->output_offset);
1841 rela.r_info = ELF32_R_INFO (h->dynindx, R_PPC_COPY);
1842 rela.r_addend = 0;
1843 bfd_elf32_swap_reloca_out (output_bfd, &rela,
1844 ((Elf32_External_Rela *) s->contents
1845 + s->reloc_count));
1846 ++s->reloc_count;
1847 }
1848
1849 /* Mark some specially defined symbols as absolute. */
1850 if (strcmp (h->root.root.string, "_DYNAMIC") == 0
1851 || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0
1852 || strcmp (h->root.root.string, "_PROCEDURE_LINKAGE_TABLE_") == 0)
1853 sym->st_shndx = SHN_ABS;
1854
1855 return true;
1856 }
1857
1858 \f
1859 /* Finish up the dynamic sections. */
1860
1861 static boolean
1862 ppc_elf_finish_dynamic_sections (output_bfd, info)
1863 bfd *output_bfd;
1864 struct bfd_link_info *info;
1865 {
1866 bfd *dynobj;
1867 asection *sdyn;
1868 asection *sgot;
1869
1870 #ifdef DEBUG
1871 fprintf (stderr, "ppc_elf_finish_dynamic_sections called\n");
1872 #endif
1873
1874 dynobj = elf_hash_table (info)->dynobj;
1875
1876 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
1877
1878 if (elf_hash_table (info)->dynamic_sections_created)
1879 {
1880 asection *splt;
1881 Elf32_External_Dyn *dyncon, *dynconend;
1882
1883 splt = bfd_get_section_by_name (dynobj, ".plt");
1884 BFD_ASSERT (splt != NULL && sdyn != NULL);
1885
1886 dyncon = (Elf32_External_Dyn *) sdyn->contents;
1887 dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->_raw_size);
1888 for (; dyncon < dynconend; dyncon++)
1889 {
1890 Elf_Internal_Dyn dyn;
1891 const char *name;
1892 boolean size;
1893
1894 bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
1895
1896 switch (dyn.d_tag)
1897 {
1898 case DT_PLTGOT: name = ".plt"; size = false; break;
1899 case DT_PLTRELSZ: name = ".rela.plt"; size = true; break;
1900 case DT_JMPREL: name = ".rela.plt"; size = false; break;
1901 default: name = NULL; size = false; break;
1902 }
1903
1904 if (name != NULL)
1905 {
1906 asection *s;
1907
1908 s = bfd_get_section_by_name (output_bfd, name);
1909 if (s == NULL)
1910 dyn.d_un.d_val = 0;
1911 else
1912 {
1913 if (! size)
1914 dyn.d_un.d_ptr = s->vma;
1915 else
1916 {
1917 if (s->_cooked_size != 0)
1918 dyn.d_un.d_val = s->_cooked_size;
1919 else
1920 dyn.d_un.d_val = s->_raw_size;
1921 }
1922 }
1923 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
1924 }
1925 }
1926
1927 /* Clear the first four entries in the procedure linkage table,
1928 and put a nop in the last four bytes. */
1929 #if 0
1930 if (splt->_raw_size > 0)
1931 {
1932 memset (splt->contents, 0, 4 * PLT_ENTRY_SIZE);
1933 bfd_put_32 (output_bfd, SPARC_NOP,
1934 splt->contents + splt->_raw_size - 4);
1935 }
1936
1937 elf_section_data (splt->output_section)->this_hdr.sh_entsize =
1938 PLT_ENTRY_SIZE;
1939 #endif
1940 }
1941
1942 /* Set the first entry in the global offset table to the address of
1943 the dynamic section. */
1944 sgot = bfd_get_section_by_name (dynobj, ".got");
1945 BFD_ASSERT (sgot != NULL);
1946 if (sgot->_raw_size > 0)
1947 {
1948 if (sdyn == NULL)
1949 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents);
1950 else
1951 bfd_put_32 (output_bfd,
1952 sdyn->output_section->vma + sdyn->output_offset,
1953 sgot->contents);
1954 }
1955
1956 elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4;
1957
1958 if (info->shared)
1959 {
1960 asection *sdynsym;
1961 asection *s;
1962 Elf_Internal_Sym sym;
1963
1964 /* Set up the section symbols for the output sections. */
1965
1966 sdynsym = bfd_get_section_by_name (dynobj, ".dynsym");
1967 BFD_ASSERT (sdynsym != NULL);
1968
1969 sym.st_size = 0;
1970 sym.st_name = 0;
1971 sym.st_info = ELF_ST_INFO (STB_LOCAL, STT_SECTION);
1972 sym.st_other = 0;
1973
1974 for (s = output_bfd->sections; s != NULL; s = s->next)
1975 {
1976 int indx;
1977
1978 sym.st_value = s->vma;
1979
1980 indx = elf_section_data (s)->this_idx;
1981 BFD_ASSERT (indx > 0);
1982 sym.st_shndx = indx;
1983
1984 bfd_elf32_swap_symbol_out (output_bfd, &sym,
1985 (PTR) (((Elf32_External_Sym *)
1986 sdynsym->contents)
1987 + elf_section_data (s)->dynindx));
1988 }
1989
1990 /* Set the sh_info field of the output .dynsym section to the
1991 index of the first global symbol. */
1992 elf_section_data (sdynsym->output_section)->this_hdr.sh_info =
1993 bfd_count_sections (output_bfd) + 1;
1994 }
1995
1996 return true;
1997 }
1998
1999 \f
2000 /* The RELOCATE_SECTION function is called by the ELF backend linker
2001 to handle the relocations for a section.
2002
2003 The relocs are always passed as Rela structures; if the section
2004 actually uses Rel structures, the r_addend field will always be
2005 zero.
2006
2007 This function is responsible for adjust the section contents as
2008 necessary, and (if using Rela relocs and generating a
2009 relocateable output file) adjusting the reloc addend as
2010 necessary.
2011
2012 This function does not have to worry about setting the reloc
2013 address or the reloc symbol index.
2014
2015 LOCAL_SYMS is a pointer to the swapped in local symbols.
2016
2017 LOCAL_SECTIONS is an array giving the section in the input file
2018 corresponding to the st_shndx field of each local symbol.
2019
2020 The global hash table entry for the global symbols can be found
2021 via elf_sym_hashes (input_bfd).
2022
2023 When generating relocateable output, this function must handle
2024 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
2025 going to be the section symbol corresponding to the output
2026 section, which means that the addend must be adjusted
2027 accordingly. */
2028
2029 static boolean
2030 ppc_elf_relocate_section (output_bfd, info, input_bfd, input_section,
2031 contents, relocs, local_syms, local_sections)
2032 bfd *output_bfd;
2033 struct bfd_link_info *info;
2034 bfd *input_bfd;
2035 asection *input_section;
2036 bfd_byte *contents;
2037 Elf_Internal_Rela *relocs;
2038 Elf_Internal_Sym *local_syms;
2039 asection **local_sections;
2040 {
2041 Elf_Internal_Shdr *symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
2042 struct elf_link_hash_entry **sym_hashes = elf_sym_hashes (input_bfd);
2043 bfd *dynobj = elf_hash_table (info)->dynobj;
2044 bfd_vma *local_got_offsets = elf_local_got_offsets (input_bfd);
2045 asection *sgot = (asection *)0;
2046 Elf_Internal_Rela *rel = relocs;
2047 Elf_Internal_Rela *relend = relocs + input_section->reloc_count;
2048 boolean ret = true;
2049 long insn;
2050
2051 #ifdef DEBUG
2052 fprintf (stderr, "ppc_elf_relocate_section called for %s section %s, %ld relocations%s\n",
2053 bfd_get_filename (input_bfd),
2054 bfd_section_name(input_bfd, input_section),
2055 (long)input_section->reloc_count,
2056 (info->relocateable) ? " (relocatable)" : "");
2057 #endif
2058
2059 if (!ppc_elf_howto_table[ R_PPC_ADDR32 ]) /* Initialize howto table if needed */
2060 ppc_elf_howto_init ();
2061
2062 for (; rel < relend; rel++)
2063 {
2064 enum ppc_reloc_type r_type = (enum ppc_reloc_type)ELF32_R_TYPE (rel->r_info);
2065 bfd_vma offset = rel->r_offset;
2066 bfd_vma addend = rel->r_addend;
2067 bfd_reloc_status_type r = bfd_reloc_other;
2068 Elf_Internal_Sym *sym = (Elf_Internal_Sym *)0;
2069 asection *sec = (asection *)0;
2070 struct elf_link_hash_entry *h = (struct elf_link_hash_entry *)0;
2071 reloc_howto_type *howto;
2072 unsigned long r_symndx;
2073 bfd_vma relocation;
2074
2075 /* Unknown relocation handling */
2076 if ((unsigned)r_type >= (unsigned)R_PPC_max || !ppc_elf_howto_table[(int)r_type])
2077 {
2078 (*_bfd_error_handler) ("%s: unknown relocation type %d",
2079 bfd_get_filename (input_bfd),
2080 (int)r_type);
2081
2082 bfd_set_error (bfd_error_bad_value);
2083 ret = false;
2084 continue;
2085 }
2086
2087 howto = ppc_elf_howto_table[(int)r_type];
2088 r_symndx = ELF32_R_SYM (rel->r_info);
2089
2090 if (info->relocateable)
2091 {
2092 /* This is a relocateable link. We don't have to change
2093 anything, unless the reloc is against a section symbol,
2094 in which case we have to adjust according to where the
2095 section symbol winds up in the output section. */
2096 if (r_symndx < symtab_hdr->sh_info)
2097 {
2098 sym = local_syms + r_symndx;
2099 if ((unsigned)ELF_ST_TYPE (sym->st_info) == STT_SECTION)
2100 {
2101 sec = local_sections[r_symndx];
2102 addend = rel->r_addend += sec->output_offset + sym->st_value;
2103 }
2104 }
2105
2106 #ifdef DEBUG
2107 fprintf (stderr, "\ttype = %s (%d), symbol index = %ld, offset = %ld, addend = %ld\n",
2108 howto->name,
2109 (int)r_type,
2110 r_symndx,
2111 (long)offset,
2112 (long)addend);
2113 #endif
2114 continue;
2115 }
2116
2117 /* This is a final link. */
2118
2119 /* Complain about known relocation that are not yet supported */
2120 if (howto->special_function == ppc_elf_unsupported_reloc)
2121 {
2122 (*_bfd_error_handler)
2123 ("%s: relocation %s (%d) is not currently supported",
2124 bfd_get_filename (input_bfd),
2125 howto->name,
2126 (int)r_type);
2127
2128 bfd_set_error (bfd_error_bad_value);
2129 ret = false;
2130 continue;
2131 }
2132
2133 if (r_symndx < symtab_hdr->sh_info)
2134 {
2135 sym = local_syms + r_symndx;
2136 sec = local_sections[r_symndx];
2137 relocation = (sec->output_section->vma
2138 + sec->output_offset
2139 + sym->st_value);
2140 }
2141 else
2142 {
2143 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
2144 if (h->root.type == bfd_link_hash_defined
2145 || h->root.type == bfd_link_hash_defweak)
2146 {
2147 sec = h->root.u.def.section;
2148 relocation = (h->root.u.def.value
2149 + sec->output_section->vma
2150 + sec->output_offset);
2151 }
2152 else if (h->root.type == bfd_link_hash_undefweak)
2153 relocation = 0;
2154 else if (info->shared)
2155 relocation = 0;
2156 else
2157 {
2158 (*info->callbacks->undefined_symbol)(info,
2159 h->root.root.string,
2160 input_bfd,
2161 input_section,
2162 rel->r_offset);
2163 ret = false;
2164 continue;
2165 }
2166 }
2167
2168 switch ((int)r_type)
2169 {
2170 default:
2171 (*_bfd_error_handler) ("%s: unknown relocation type %d",
2172 bfd_get_filename (input_bfd),
2173 (int)r_type);
2174
2175 bfd_set_error (bfd_error_bad_value);
2176 ret = false;
2177 continue;
2178
2179 case R_PPC_NONE: /* relocations that need no special processing */
2180 case R_PPC_ADDR32:
2181 case R_PPC_ADDR24:
2182 case R_PPC_ADDR16:
2183 case R_PPC_ADDR16_LO:
2184 case R_PPC_ADDR16_HI:
2185 case R_PPC_ADDR14:
2186 case R_PPC_REL24:
2187 case R_PPC_REL14:
2188 case R_PPC_UADDR32:
2189 case R_PPC_UADDR16:
2190 case R_PPC_REL32:
2191 break;
2192
2193 case (int)R_PPC_ADDR14_BRTAKEN: /* branch taken prediction relocations */
2194 case (int)R_PPC_REL14_BRTAKEN:
2195 insn = bfd_get_32 (output_bfd, contents + offset);
2196 if ((relocation - offset) & 0x8000)
2197 insn &= ~BRANCH_PREDICT_BIT;
2198 else
2199 insn |= BRANCH_PREDICT_BIT;
2200 bfd_put_32 (output_bfd, insn, contents + offset);
2201 break;
2202
2203 case (int)R_PPC_ADDR14_BRNTAKEN: /* branch not taken predicition relocations */
2204 case (int)R_PPC_REL14_BRNTAKEN:
2205 insn = bfd_get_32 (output_bfd, contents + offset);
2206 if ((relocation - offset) & 0x8000)
2207 insn |= BRANCH_PREDICT_BIT;
2208 else
2209 insn &= ~BRANCH_PREDICT_BIT;
2210 bfd_put_32 (output_bfd, insn, contents + offset);
2211 break;
2212
2213 case (int)R_PPC_GOT16: /* GOT16 relocations */
2214 case (int)R_PPC_GOT16_LO:
2215 case (int)R_PPC_GOT16_HI:
2216 case (int)R_PPC_GOT16_HA:
2217 #ifdef DEBUG
2218 fprintf (stderr, "GOT relocations in section %s from section %s\n", input_section->name, sec->name);
2219 #endif
2220 if (dynobj == NULL)
2221 {
2222 dynobj = ppc_elf_create_dynamic_sections (output_bfd, info);
2223 if (!dynobj)
2224 {
2225 ret = false;
2226 continue;
2227 }
2228 }
2229
2230 BFD_ASSERT (sec != (asection *)0);
2231 if (!sgot)
2232 {
2233 sgot = bfd_get_section_by_name (dynobj, ".got");
2234 BFD_ASSERT (sgot != NULL);
2235 }
2236
2237 if (h != NULL)
2238 {
2239 bfd_vma off;
2240
2241 off = h->got_offset;
2242 BFD_ASSERT (off != (bfd_vma) -1);
2243
2244 if (! elf_hash_table (info)->dynamic_sections_created
2245 || (info->shared
2246 && info->symbolic
2247 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR)))
2248 {
2249 /* This is actually a static link, or it is a
2250 -Bsymbolic link and the symbol is defined
2251 locally. We must initialize this entry in the
2252 global offset table. Since the offset must
2253 always be a multiple of 4, we use the least
2254 significant bit to record whether we have
2255 initialized it already.
2256
2257 When doing a dynamic link, we create a .rela.got
2258 relocation entry to initialize the value. This
2259 is done in the finish_dynamic_symbol routine. */
2260 if ((off & 1) != 0)
2261 off &= ~1;
2262 else
2263 {
2264 bfd_put_32 (output_bfd, relocation,
2265 sgot->contents + off);
2266 h->got_offset |= 1;
2267 }
2268 }
2269
2270 relocation = sgot->output_offset + off;
2271 }
2272 else
2273 {
2274 bfd_vma off;
2275
2276 BFD_ASSERT (local_got_offsets != NULL
2277 && local_got_offsets[r_symndx] != (bfd_vma) -1);
2278
2279 off = local_got_offsets[r_symndx];
2280
2281 /* The offset must always be a multiple of 4. We use
2282 the least significant bit to record whether we have
2283 already processed this entry. */
2284 if ((off & 1) != 0)
2285 off &= ~1;
2286 else
2287 {
2288 bfd_put_32 (output_bfd, relocation, sgot->contents + off);
2289
2290 if (info->shared)
2291 {
2292 asection *srelgot;
2293 Elf_Internal_Rela outrel;
2294
2295 /* We need to generate a R_PPC_RELATIVE reloc
2296 for the dynamic linker. */
2297 srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
2298 BFD_ASSERT (srelgot != NULL);
2299
2300 outrel.r_offset = (sgot->output_section->vma
2301 + sgot->output_offset
2302 + off);
2303 outrel.r_info = ELF32_R_INFO (0, R_PPC_RELATIVE);
2304 outrel.r_addend = 0;
2305 bfd_elf32_swap_reloca_out (output_bfd, &outrel,
2306 (((Elf32_External_Rela *)
2307 srelgot->contents)
2308 + srelgot->reloc_count));
2309 ++srelgot->reloc_count;
2310 }
2311
2312 local_got_offsets[r_symndx] |= 1;
2313 }
2314
2315 relocation = sgot->output_offset + off;
2316 }
2317
2318 break;
2319
2320 /* Handle the TOC16 reloc. We want to use the offset within the .got
2321 section, not the actual VMA. This is appropriate when generating
2322 an embedded ELF object, for which the .got section acts like the
2323 AIX .toc section. */
2324 case (int)R_PPC_TOC16: /* phony GOT16 relocations */
2325 BFD_ASSERT (sec != (asection *)0);
2326 BFD_ASSERT (bfd_is_und_section (sec)
2327 || strcmp (bfd_get_section_name (abfd, sec), ".got") == 0
2328 || strcmp (bfd_get_section_name (abfd, sec), ".cgot") == 0
2329 || strcmp (bfd_get_section_name (abfd, sec), ".sdata") == 0
2330 || strcmp (bfd_get_section_name (abfd, sec), ".sbss") == 0)
2331
2332 addend -= sec->output_section->vma + 0x8000;
2333 break;
2334
2335 case (int)R_PPC_ADDR16_HA: /* arithmetic adjust relocations */
2336 BFD_ASSERT (sec != (asection *)0);
2337 addend += ((relocation + addend) & 0x8000) << 1;
2338 break;
2339
2340 case R_PPC_PLTREL24:
2341 case R_PPC_COPY:
2342 case R_PPC_GLOB_DAT:
2343 case R_PPC_JMP_SLOT:
2344 case R_PPC_RELATIVE:
2345 case R_PPC_LOCAL24PC:
2346 case R_PPC_PLT32:
2347 case R_PPC_PLTREL32:
2348 case R_PPC_PLT16_LO:
2349 case R_PPC_PLT16_HI:
2350 case R_PPC_PLT16_HA:
2351 case R_PPC_SDAREL16:
2352 case R_PPC_SECTOFF:
2353 case R_PPC_SECTOFF_LO:
2354 case R_PPC_SECTOFF_HI:
2355 case R_PPC_SECTOFF_HA:
2356 case R_PPC_EMB_NADDR32:
2357 case R_PPC_EMB_NADDR16:
2358 case R_PPC_EMB_NADDR16_LO:
2359 case R_PPC_EMB_NADDR16_HI:
2360 case R_PPC_EMB_NADDR16_HA:
2361 case R_PPC_EMB_SDAI16:
2362 case R_PPC_EMB_SDA2I16:
2363 case R_PPC_EMB_SDA2REL:
2364 case R_PPC_EMB_SDA21:
2365 case R_PPC_EMB_MRKREF:
2366 case R_PPC_EMB_RELSEC16:
2367 case R_PPC_EMB_RELST_LO:
2368 case R_PPC_EMB_RELST_HI:
2369 case R_PPC_EMB_RELST_HA:
2370 case R_PPC_EMB_BIT_FLD:
2371 case R_PPC_EMB_RELSDA:
2372 (*_bfd_error_handler) ("%s: Relocation %s is not yet supported.",
2373 bfd_get_filename (input_bfd),
2374 ppc_elf_howto_table[ (int)r_type ]->name);
2375
2376 bfd_set_error (bfd_error_bad_value);
2377 ret = false;
2378 continue;
2379 }
2380
2381
2382 #ifdef DEBUG
2383 fprintf (stderr, "\ttype = %s (%d), symbol index = %ld, offset = %ld, addend = %ld\n",
2384 howto->name,
2385 (int)r_type,
2386 r_symndx,
2387 (long)offset,
2388 (long)addend);
2389 #endif
2390
2391 r = _bfd_final_link_relocate (howto,
2392 input_bfd,
2393 input_section,
2394 contents,
2395 offset,
2396 relocation,
2397 addend);
2398
2399 if (r != bfd_reloc_ok)
2400 {
2401 ret = false;
2402 switch (r)
2403 {
2404 default:
2405 break;
2406
2407 case bfd_reloc_overflow:
2408 {
2409 const char *name;
2410
2411 if (h != NULL)
2412 name = h->root.root.string;
2413 else
2414 {
2415 name = bfd_elf_string_from_elf_section (input_bfd,
2416 symtab_hdr->sh_link,
2417 sym->st_name);
2418 if (name == NULL)
2419 break;
2420
2421 if (*name == '\0')
2422 name = bfd_section_name (input_bfd, sec);
2423 }
2424
2425 (*info->callbacks->reloc_overflow)(info,
2426 name,
2427 howto->name,
2428 (bfd_vma) 0,
2429 input_bfd,
2430 input_section,
2431 offset);
2432 }
2433 break;
2434
2435 }
2436 }
2437 }
2438
2439
2440 #ifdef DEBUG
2441 fprintf (stderr, "\n");
2442 #endif
2443
2444 return ret;
2445 }
2446
2447 \f
2448 #define TARGET_LITTLE_SYM bfd_elf32_powerpcle_vec
2449 #define TARGET_LITTLE_NAME "elf32-powerpcle"
2450 #define TARGET_BIG_SYM bfd_elf32_powerpc_vec
2451 #define TARGET_BIG_NAME "elf32-powerpc"
2452 #define ELF_ARCH bfd_arch_powerpc
2453 #define ELF_MACHINE_CODE EM_PPC
2454 #define ELF_MAXPAGESIZE 0x10000
2455 #define elf_info_to_howto ppc_elf_info_to_howto
2456
2457 #ifdef EM_CYGNUS_POWERPC
2458 #define ELF_MACHINE_ALT1 EM_CYGNUS_POWERPC
2459 #endif
2460
2461 #ifdef EM_PPC_OLD
2462 #define ELF_MACHINE_ALT2 EM_PPC_OLD
2463 #endif
2464
2465 #define bfd_elf32_bfd_copy_private_bfd_data ppc_elf_copy_private_bfd_data
2466 #define bfd_elf32_bfd_merge_private_bfd_data ppc_elf_merge_private_bfd_data
2467 #define bfd_elf32_bfd_set_private_flags ppc_elf_set_private_flags
2468 #define bfd_elf32_bfd_reloc_type_lookup ppc_elf_reloc_type_lookup
2469 #define elf_backend_section_from_shdr ppc_elf_section_from_shdr
2470 #define elf_backend_relocate_section ppc_elf_relocate_section
2471 #define elf_backend_create_dynamic_sections _bfd_elf_create_dynamic_sections
2472 #define elf_backend_check_relocs ppc_elf_check_relocs
2473 #define elf_backend_adjust_dynamic_symbol ppc_elf_adjust_dynamic_symbol
2474 #define elf_backend_size_dynamic_sections ppc_elf_size_dynamic_sections
2475 #define elf_backend_finish_dynamic_symbol ppc_elf_finish_dynamic_symbol
2476 #define elf_backend_finish_dynamic_sections ppc_elf_finish_dynamic_sections
2477 #define elf_backend_fake_sections ppc_elf_fake_sections
2478
2479 #include "elf32-target.h"