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