* write.c (relax_frag): Make non-static.
[deliverable/binutils-gdb.git] / bfd / elf32-ppc.c
1 /* PowerPC-specific support for 32-bit ELF
2 Copyright 1994, 1995, 1996, 1997 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 bfd_reloc_status_type ppc_elf_addr16_ha_reloc
108 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
109 static boolean ppc_elf_set_private_flags PARAMS ((bfd *, flagword));
110 static boolean ppc_elf_copy_private_bfd_data PARAMS ((bfd *, bfd *));
111 static boolean ppc_elf_merge_private_bfd_data PARAMS ((bfd *, bfd *));
112
113 static int ppc_elf_additional_program_headers PARAMS ((bfd *));
114 static boolean ppc_elf_modify_segment_map PARAMS ((bfd *));
115
116 static boolean ppc_elf_section_from_shdr PARAMS ((bfd *,
117 Elf32_Internal_Shdr *,
118 char *));
119 static boolean ppc_elf_fake_sections
120 PARAMS ((bfd *, Elf32_Internal_Shdr *, asection *));
121
122 static elf_linker_section_t *ppc_elf_create_linker_section
123 PARAMS ((bfd *abfd,
124 struct bfd_link_info *info,
125 enum elf_linker_section_enum));
126
127 static boolean ppc_elf_check_relocs PARAMS ((bfd *,
128 struct bfd_link_info *,
129 asection *,
130 const Elf_Internal_Rela *));
131
132 static boolean ppc_elf_adjust_dynamic_symbol PARAMS ((struct bfd_link_info *,
133 struct elf_link_hash_entry *));
134
135 static boolean ppc_elf_adjust_dynindx PARAMS ((struct elf_link_hash_entry *, PTR));
136
137 static boolean ppc_elf_size_dynamic_sections PARAMS ((bfd *, struct bfd_link_info *));
138
139 static boolean ppc_elf_relocate_section PARAMS ((bfd *,
140 struct bfd_link_info *info,
141 bfd *,
142 asection *,
143 bfd_byte *,
144 Elf_Internal_Rela *relocs,
145 Elf_Internal_Sym *local_syms,
146 asection **));
147
148 static boolean ppc_elf_add_symbol_hook PARAMS ((bfd *,
149 struct bfd_link_info *,
150 const Elf_Internal_Sym *,
151 const char **,
152 flagword *,
153 asection **,
154 bfd_vma *));
155
156 static boolean ppc_elf_finish_dynamic_symbol PARAMS ((bfd *,
157 struct bfd_link_info *,
158 struct elf_link_hash_entry *,
159 Elf_Internal_Sym *));
160
161 static boolean ppc_elf_finish_dynamic_sections PARAMS ((bfd *, struct bfd_link_info *));
162
163 #define BRANCH_PREDICT_BIT 0x200000 /* branch prediction bit for branch taken relocs */
164 #define RA_REGISTER_MASK 0x001f0000 /* mask to set RA in memory instructions */
165 #define RA_REGISTER_SHIFT 16 /* value to shift register by to insert RA */
166
167 /* The name of the dynamic interpreter. This is put in the .interp
168 section. */
169
170 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
171
172 /* The size in bytes of an entry in the procedure linkage table, and of the initial size
173 of the plt reserved for the dynamic linker. */
174
175 #define PLT_ENTRY_SIZE 12
176 #define PLT_INITIAL_ENTRY_SIZE 72
177
178 \f
179 static reloc_howto_type *ppc_elf_howto_table[ (int)R_PPC_max ];
180
181 static reloc_howto_type ppc_elf_howto_raw[] =
182 {
183 /* This reloc does nothing. */
184 HOWTO (R_PPC_NONE, /* type */
185 0, /* rightshift */
186 2, /* size (0 = byte, 1 = short, 2 = long) */
187 32, /* bitsize */
188 false, /* pc_relative */
189 0, /* bitpos */
190 complain_overflow_bitfield, /* complain_on_overflow */
191 bfd_elf_generic_reloc, /* special_function */
192 "R_PPC_NONE", /* name */
193 false, /* partial_inplace */
194 0, /* src_mask */
195 0, /* dst_mask */
196 false), /* pcrel_offset */
197
198 /* A standard 32 bit relocation. */
199 HOWTO (R_PPC_ADDR32, /* type */
200 0, /* rightshift */
201 2, /* size (0 = byte, 1 = short, 2 = long) */
202 32, /* bitsize */
203 false, /* pc_relative */
204 0, /* bitpos */
205 complain_overflow_bitfield, /* complain_on_overflow */
206 bfd_elf_generic_reloc, /* special_function */
207 "R_PPC_ADDR32", /* name */
208 false, /* partial_inplace */
209 0, /* src_mask */
210 0xffffffff, /* dst_mask */
211 false), /* pcrel_offset */
212
213 /* An absolute 26 bit branch; the lower two bits must be zero.
214 FIXME: we don't check that, we just clear them. */
215 HOWTO (R_PPC_ADDR24, /* type */
216 0, /* rightshift */
217 2, /* size (0 = byte, 1 = short, 2 = long) */
218 26, /* bitsize */
219 false, /* pc_relative */
220 0, /* bitpos */
221 complain_overflow_bitfield, /* complain_on_overflow */
222 bfd_elf_generic_reloc, /* special_function */
223 "R_PPC_ADDR24", /* name */
224 false, /* partial_inplace */
225 0, /* src_mask */
226 0x3fffffc, /* dst_mask */
227 false), /* pcrel_offset */
228
229 /* A standard 16 bit relocation. */
230 HOWTO (R_PPC_ADDR16, /* type */
231 0, /* rightshift */
232 1, /* size (0 = byte, 1 = short, 2 = long) */
233 16, /* bitsize */
234 false, /* pc_relative */
235 0, /* bitpos */
236 complain_overflow_bitfield, /* complain_on_overflow */
237 bfd_elf_generic_reloc, /* special_function */
238 "R_PPC_ADDR16", /* name */
239 false, /* partial_inplace */
240 0, /* src_mask */
241 0xffff, /* dst_mask */
242 false), /* pcrel_offset */
243
244 /* A 16 bit relocation without overflow. */
245 HOWTO (R_PPC_ADDR16_LO, /* type */
246 0, /* rightshift */
247 1, /* size (0 = byte, 1 = short, 2 = long) */
248 16, /* bitsize */
249 false, /* pc_relative */
250 0, /* bitpos */
251 complain_overflow_dont,/* complain_on_overflow */
252 bfd_elf_generic_reloc, /* special_function */
253 "R_PPC_ADDR16_LO", /* name */
254 false, /* partial_inplace */
255 0, /* src_mask */
256 0xffff, /* dst_mask */
257 false), /* pcrel_offset */
258
259 /* The high order 16 bits of an address. */
260 HOWTO (R_PPC_ADDR16_HI, /* type */
261 16, /* rightshift */
262 1, /* size (0 = byte, 1 = short, 2 = long) */
263 16, /* bitsize */
264 false, /* pc_relative */
265 0, /* bitpos */
266 complain_overflow_dont, /* complain_on_overflow */
267 bfd_elf_generic_reloc, /* special_function */
268 "R_PPC_ADDR16_HI", /* name */
269 false, /* partial_inplace */
270 0, /* src_mask */
271 0xffff, /* dst_mask */
272 false), /* pcrel_offset */
273
274 /* The high order 16 bits of an address, plus 1 if the contents of
275 the low 16 bits, treated as a signed number, is negative. */
276 HOWTO (R_PPC_ADDR16_HA, /* type */
277 16, /* rightshift */
278 1, /* size (0 = byte, 1 = short, 2 = long) */
279 16, /* bitsize */
280 false, /* pc_relative */
281 0, /* bitpos */
282 complain_overflow_dont, /* complain_on_overflow */
283 ppc_elf_addr16_ha_reloc, /* special_function */
284 "R_PPC_ADDR16_HA", /* name */
285 false, /* partial_inplace */
286 0, /* src_mask */
287 0xffff, /* dst_mask */
288 false), /* pcrel_offset */
289
290 /* An absolute 16 bit branch; the lower two bits must be zero.
291 FIXME: we don't check that, we just clear them. */
292 HOWTO (R_PPC_ADDR14, /* type */
293 0, /* rightshift */
294 2, /* size (0 = byte, 1 = short, 2 = long) */
295 16, /* bitsize */
296 false, /* pc_relative */
297 0, /* bitpos */
298 complain_overflow_bitfield, /* complain_on_overflow */
299 bfd_elf_generic_reloc, /* special_function */
300 "R_PPC_ADDR14", /* name */
301 false, /* partial_inplace */
302 0, /* src_mask */
303 0xfffc, /* dst_mask */
304 false), /* pcrel_offset */
305
306 /* An absolute 16 bit branch, for which bit 10 should be set to
307 indicate that the branch is expected to be taken. The lower two
308 bits must be zero. */
309 HOWTO (R_PPC_ADDR14_BRTAKEN, /* type */
310 0, /* rightshift */
311 2, /* size (0 = byte, 1 = short, 2 = long) */
312 16, /* bitsize */
313 false, /* pc_relative */
314 0, /* bitpos */
315 complain_overflow_bitfield, /* complain_on_overflow */
316 bfd_elf_generic_reloc, /* special_function */
317 "R_PPC_ADDR14_BRTAKEN",/* name */
318 false, /* partial_inplace */
319 0, /* src_mask */
320 0xfffc, /* dst_mask */
321 false), /* pcrel_offset */
322
323 /* An absolute 16 bit branch, for which bit 10 should be set to
324 indicate that the branch is not expected to be taken. The lower
325 two bits must be zero. */
326 HOWTO (R_PPC_ADDR14_BRNTAKEN, /* type */
327 0, /* rightshift */
328 2, /* size (0 = byte, 1 = short, 2 = long) */
329 16, /* bitsize */
330 false, /* pc_relative */
331 0, /* bitpos */
332 complain_overflow_bitfield, /* complain_on_overflow */
333 bfd_elf_generic_reloc, /* special_function */
334 "R_PPC_ADDR14_BRNTAKEN",/* name */
335 false, /* partial_inplace */
336 0, /* src_mask */
337 0xfffc, /* dst_mask */
338 false), /* pcrel_offset */
339
340 /* A relative 26 bit branch; the lower two bits must be zero. */
341 HOWTO (R_PPC_REL24, /* type */
342 0, /* rightshift */
343 2, /* size (0 = byte, 1 = short, 2 = long) */
344 26, /* bitsize */
345 true, /* pc_relative */
346 0, /* bitpos */
347 complain_overflow_signed, /* complain_on_overflow */
348 bfd_elf_generic_reloc, /* special_function */
349 "R_PPC_REL24", /* name */
350 false, /* partial_inplace */
351 0, /* src_mask */
352 0x3fffffc, /* dst_mask */
353 true), /* pcrel_offset */
354
355 /* A relative 16 bit branch; the lower two bits must be zero. */
356 HOWTO (R_PPC_REL14, /* type */
357 0, /* rightshift */
358 2, /* size (0 = byte, 1 = short, 2 = long) */
359 16, /* bitsize */
360 true, /* pc_relative */
361 0, /* bitpos */
362 complain_overflow_signed, /* complain_on_overflow */
363 bfd_elf_generic_reloc, /* special_function */
364 "R_PPC_REL14", /* name */
365 false, /* partial_inplace */
366 0, /* src_mask */
367 0xfffc, /* dst_mask */
368 true), /* pcrel_offset */
369
370 /* A relative 16 bit branch. Bit 10 should be set to indicate that
371 the branch is expected to be taken. The lower two bits must be
372 zero. */
373 HOWTO (R_PPC_REL14_BRTAKEN, /* type */
374 0, /* rightshift */
375 2, /* size (0 = byte, 1 = short, 2 = long) */
376 16, /* bitsize */
377 true, /* pc_relative */
378 0, /* bitpos */
379 complain_overflow_signed, /* complain_on_overflow */
380 bfd_elf_generic_reloc, /* special_function */
381 "R_PPC_REL14_BRTAKEN", /* name */
382 false, /* partial_inplace */
383 0, /* src_mask */
384 0xfffc, /* dst_mask */
385 true), /* pcrel_offset */
386
387 /* A relative 16 bit branch. Bit 10 should be set to indicate that
388 the branch is not expected to be taken. The lower two bits must
389 be zero. */
390 HOWTO (R_PPC_REL14_BRNTAKEN, /* type */
391 0, /* rightshift */
392 2, /* size (0 = byte, 1 = short, 2 = long) */
393 16, /* bitsize */
394 true, /* pc_relative */
395 0, /* bitpos */
396 complain_overflow_signed, /* complain_on_overflow */
397 bfd_elf_generic_reloc, /* special_function */
398 "R_PPC_REL14_BRNTAKEN",/* name */
399 false, /* partial_inplace */
400 0, /* src_mask */
401 0xfffc, /* dst_mask */
402 true), /* pcrel_offset */
403
404 /* Like R_PPC_ADDR16, but referring to the GOT table entry for the
405 symbol. */
406 HOWTO (R_PPC_GOT16, /* type */
407 0, /* rightshift */
408 1, /* size (0 = byte, 1 = short, 2 = long) */
409 16, /* bitsize */
410 false, /* pc_relative */
411 0, /* bitpos */
412 complain_overflow_signed, /* complain_on_overflow */
413 bfd_elf_generic_reloc, /* special_function */
414 "R_PPC_GOT16", /* name */
415 false, /* partial_inplace */
416 0, /* src_mask */
417 0xffff, /* dst_mask */
418 false), /* pcrel_offset */
419
420 /* Like R_PPC_ADDR16_LO, but referring to the GOT table entry for
421 the symbol. */
422 HOWTO (R_PPC_GOT16_LO, /* type */
423 0, /* rightshift */
424 1, /* size (0 = byte, 1 = short, 2 = long) */
425 16, /* bitsize */
426 false, /* pc_relative */
427 0, /* bitpos */
428 complain_overflow_bitfield, /* complain_on_overflow */
429 bfd_elf_generic_reloc, /* special_function */
430 "R_PPC_GOT16_LO", /* name */
431 false, /* partial_inplace */
432 0, /* src_mask */
433 0xffff, /* dst_mask */
434 false), /* pcrel_offset */
435
436 /* Like R_PPC_ADDR16_HI, but referring to the GOT table entry for
437 the symbol. */
438 HOWTO (R_PPC_GOT16_HI, /* type */
439 16, /* rightshift */
440 1, /* size (0 = byte, 1 = short, 2 = long) */
441 16, /* bitsize */
442 false, /* pc_relative */
443 0, /* bitpos */
444 complain_overflow_bitfield, /* complain_on_overflow */
445 bfd_elf_generic_reloc, /* special_function */
446 "R_PPC_GOT16_HI", /* name */
447 false, /* partial_inplace */
448 0, /* src_mask */
449 0xffff, /* dst_mask */
450 false), /* pcrel_offset */
451
452 /* Like R_PPC_ADDR16_HA, but referring to the GOT table entry for
453 the symbol. */
454 HOWTO (R_PPC_GOT16_HA, /* type */
455 0, /* rightshift */
456 1, /* size (0 = byte, 1 = short, 2 = long) */
457 16, /* bitsize */
458 false, /* pc_relative */
459 0, /* bitpos */
460 complain_overflow_bitfield, /* complain_on_overflow */
461 bfd_elf_generic_reloc, /* special_function */
462 "R_PPC_GOT16_HA", /* name */
463 false, /* partial_inplace */
464 0, /* src_mask */
465 0xffff, /* dst_mask */
466 false), /* pcrel_offset */
467
468 /* Like R_PPC_REL24, but referring to the procedure linkage table
469 entry for the symbol. FIXME: Not supported. */
470 HOWTO (R_PPC_PLTREL24, /* type */
471 0, /* rightshift */
472 2, /* size (0 = byte, 1 = short, 2 = long) */
473 26, /* bitsize */
474 true, /* pc_relative */
475 0, /* bitpos */
476 complain_overflow_signed, /* complain_on_overflow */
477 bfd_elf_generic_reloc, /* special_function */
478 "R_PPC_PLTREL24", /* name */
479 false, /* partial_inplace */
480 0, /* src_mask */
481 0x3fffffc, /* dst_mask */
482 true), /* pcrel_offset */
483
484 /* This is used only by the dynamic linker. The symbol should exist
485 both in the object being run and in some shared library. The
486 dynamic linker copies the data addressed by the symbol from the
487 shared library into the object. I have no idea what the purpose
488 of this is. */
489 HOWTO (R_PPC_COPY, /* type */
490 0, /* rightshift */
491 2, /* size (0 = byte, 1 = short, 2 = long) */
492 32, /* bitsize */
493 false, /* pc_relative */
494 0, /* bitpos */
495 complain_overflow_bitfield, /* complain_on_overflow */
496 bfd_elf_generic_reloc, /* special_function */
497 "R_PPC_COPY", /* name */
498 false, /* partial_inplace */
499 0, /* src_mask */
500 0, /* dst_mask */
501 false), /* pcrel_offset */
502
503 /* Like R_PPC_ADDR32, but used when setting global offset table
504 entries. */
505 HOWTO (R_PPC_GLOB_DAT, /* type */
506 0, /* rightshift */
507 2, /* size (0 = byte, 1 = short, 2 = long) */
508 32, /* bitsize */
509 false, /* pc_relative */
510 0, /* bitpos */
511 complain_overflow_bitfield, /* complain_on_overflow */
512 bfd_elf_generic_reloc, /* special_function */
513 "R_PPC_GLOB_DAT", /* name */
514 false, /* partial_inplace */
515 0, /* src_mask */
516 0xffffffff, /* dst_mask */
517 false), /* pcrel_offset */
518
519 /* Marks a procedure linkage table entry for a symbol. */
520 HOWTO (R_PPC_JMP_SLOT, /* type */
521 0, /* rightshift */
522 2, /* size (0 = byte, 1 = short, 2 = long) */
523 32, /* bitsize */
524 false, /* pc_relative */
525 0, /* bitpos */
526 complain_overflow_bitfield, /* complain_on_overflow */
527 bfd_elf_generic_reloc, /* special_function */
528 "R_PPC_JMP_SLOT", /* name */
529 false, /* partial_inplace */
530 0, /* src_mask */
531 0, /* dst_mask */
532 false), /* pcrel_offset */
533
534 /* Used only by the dynamic linker. When the object is run, this
535 longword is set to the load address of the object, plus the
536 addend. */
537 HOWTO (R_PPC_RELATIVE, /* type */
538 0, /* rightshift */
539 2, /* size (0 = byte, 1 = short, 2 = long) */
540 32, /* bitsize */
541 false, /* pc_relative */
542 0, /* bitpos */
543 complain_overflow_bitfield, /* complain_on_overflow */
544 bfd_elf_generic_reloc, /* special_function */
545 "R_PPC_RELATIVE", /* name */
546 false, /* partial_inplace */
547 0, /* src_mask */
548 0xffffffff, /* dst_mask */
549 false), /* pcrel_offset */
550
551 /* Like R_PPC_REL24, but uses the value of the symbol within the
552 object rather than the final value. Normally used for
553 _GLOBAL_OFFSET_TABLE_. FIXME: Not supported. */
554 HOWTO (R_PPC_LOCAL24PC, /* type */
555 0, /* rightshift */
556 2, /* size (0 = byte, 1 = short, 2 = long) */
557 26, /* bitsize */
558 true, /* pc_relative */
559 0, /* bitpos */
560 complain_overflow_signed, /* complain_on_overflow */
561 bfd_elf_generic_reloc, /* special_function */
562 "R_PPC_LOCAL24PC", /* name */
563 false, /* partial_inplace */
564 0, /* src_mask */
565 0x3fffffc, /* dst_mask */
566 true), /* pcrel_offset */
567
568 /* Like R_PPC_ADDR32, but may be unaligned. */
569 HOWTO (R_PPC_UADDR32, /* type */
570 0, /* rightshift */
571 2, /* size (0 = byte, 1 = short, 2 = long) */
572 32, /* bitsize */
573 false, /* pc_relative */
574 0, /* bitpos */
575 complain_overflow_bitfield, /* complain_on_overflow */
576 bfd_elf_generic_reloc, /* special_function */
577 "R_PPC_UADDR32", /* name */
578 false, /* partial_inplace */
579 0, /* src_mask */
580 0xffffffff, /* dst_mask */
581 false), /* pcrel_offset */
582
583 /* Like R_PPC_ADDR16, but may be unaligned. */
584 HOWTO (R_PPC_UADDR16, /* type */
585 0, /* rightshift */
586 1, /* size (0 = byte, 1 = short, 2 = long) */
587 16, /* bitsize */
588 false, /* pc_relative */
589 0, /* bitpos */
590 complain_overflow_bitfield, /* complain_on_overflow */
591 bfd_elf_generic_reloc, /* special_function */
592 "R_PPC_UADDR16", /* name */
593 false, /* partial_inplace */
594 0, /* src_mask */
595 0xffff, /* dst_mask */
596 false), /* pcrel_offset */
597
598 /* 32-bit PC relative */
599 HOWTO (R_PPC_REL32, /* type */
600 0, /* rightshift */
601 2, /* size (0 = byte, 1 = short, 2 = long) */
602 32, /* bitsize */
603 true, /* pc_relative */
604 0, /* bitpos */
605 complain_overflow_bitfield, /* complain_on_overflow */
606 bfd_elf_generic_reloc, /* special_function */
607 "R_PPC_REL32", /* name */
608 false, /* partial_inplace */
609 0, /* src_mask */
610 0xffffffff, /* dst_mask */
611 true), /* pcrel_offset */
612
613 /* 32-bit relocation to the symbol's procedure linkage table.
614 FIXEME: not supported. */
615 HOWTO (R_PPC_PLT32, /* type */
616 0, /* rightshift */
617 2, /* size (0 = byte, 1 = short, 2 = long) */
618 32, /* bitsize */
619 false, /* pc_relative */
620 0, /* bitpos */
621 complain_overflow_bitfield, /* complain_on_overflow */
622 bfd_elf_generic_reloc, /* special_function */
623 "R_PPC_PLT32", /* name */
624 false, /* partial_inplace */
625 0, /* src_mask */
626 0, /* dst_mask */
627 false), /* pcrel_offset */
628
629 /* 32-bit PC relative relocation to the symbol's procedure linkage table.
630 FIXEME: not supported. */
631 HOWTO (R_PPC_PLTREL32, /* type */
632 0, /* rightshift */
633 2, /* size (0 = byte, 1 = short, 2 = long) */
634 32, /* bitsize */
635 true, /* pc_relative */
636 0, /* bitpos */
637 complain_overflow_bitfield, /* complain_on_overflow */
638 bfd_elf_generic_reloc, /* special_function */
639 "R_PPC_PLTREL32", /* name */
640 false, /* partial_inplace */
641 0, /* src_mask */
642 0, /* dst_mask */
643 true), /* pcrel_offset */
644
645 /* Like R_PPC_ADDR16_LO, but referring to the PLT table entry for
646 the symbol. */
647 HOWTO (R_PPC_PLT16_LO, /* type */
648 0, /* rightshift */
649 1, /* size (0 = byte, 1 = short, 2 = long) */
650 16, /* bitsize */
651 false, /* pc_relative */
652 0, /* bitpos */
653 complain_overflow_bitfield, /* complain_on_overflow */
654 bfd_elf_generic_reloc, /* special_function */
655 "R_PPC_PLT16_LO", /* name */
656 false, /* partial_inplace */
657 0, /* src_mask */
658 0xffff, /* dst_mask */
659 false), /* pcrel_offset */
660
661 /* Like R_PPC_ADDR16_HI, but referring to the PLT table entry for
662 the symbol. */
663 HOWTO (R_PPC_PLT16_HI, /* type */
664 16, /* rightshift */
665 1, /* size (0 = byte, 1 = short, 2 = long) */
666 16, /* bitsize */
667 false, /* pc_relative */
668 0, /* bitpos */
669 complain_overflow_bitfield, /* complain_on_overflow */
670 bfd_elf_generic_reloc, /* special_function */
671 "R_PPC_PLT16_HI", /* name */
672 false, /* partial_inplace */
673 0, /* src_mask */
674 0xffff, /* dst_mask */
675 false), /* pcrel_offset */
676
677 /* Like R_PPC_ADDR16_HA, but referring to the PLT table entry for
678 the symbol. FIXME: Not supported. */
679 HOWTO (R_PPC_PLT16_HA, /* type */
680 0, /* rightshift */
681 1, /* size (0 = byte, 1 = short, 2 = long) */
682 16, /* bitsize */
683 false, /* pc_relative */
684 0, /* bitpos */
685 complain_overflow_bitfield, /* complain_on_overflow */
686 bfd_elf_generic_reloc, /* special_function */
687 "R_PPC_PLT16_HA", /* name */
688 false, /* partial_inplace */
689 0, /* src_mask */
690 0xffff, /* dst_mask */
691 false), /* pcrel_offset */
692
693 /* A sign-extended 16 bit value relative to _SDA_BASE_, for use with
694 small data items. */
695 HOWTO (R_PPC_SDAREL16, /* type */
696 0, /* rightshift */
697 1, /* size (0 = byte, 1 = short, 2 = long) */
698 16, /* bitsize */
699 false, /* pc_relative */
700 0, /* bitpos */
701 complain_overflow_signed, /* complain_on_overflow */
702 bfd_elf_generic_reloc, /* special_function */
703 "R_PPC_SDAREL16", /* name */
704 false, /* partial_inplace */
705 0, /* src_mask */
706 0xffff, /* dst_mask */
707 false), /* pcrel_offset */
708
709 /* 32-bit section relative relocation. */
710 HOWTO (R_PPC_SECTOFF, /* type */
711 0, /* rightshift */
712 2, /* size (0 = byte, 1 = short, 2 = long) */
713 32, /* bitsize */
714 true, /* pc_relative */
715 0, /* bitpos */
716 complain_overflow_bitfield, /* complain_on_overflow */
717 bfd_elf_generic_reloc, /* special_function */
718 "R_PPC_SECTOFF", /* name */
719 false, /* partial_inplace */
720 0, /* src_mask */
721 0, /* dst_mask */
722 true), /* pcrel_offset */
723
724 /* 16-bit lower half section relative relocation. */
725 HOWTO (R_PPC_SECTOFF_LO, /* type */
726 0, /* rightshift */
727 1, /* size (0 = byte, 1 = short, 2 = long) */
728 16, /* bitsize */
729 false, /* pc_relative */
730 0, /* bitpos */
731 complain_overflow_bitfield, /* complain_on_overflow */
732 bfd_elf_generic_reloc, /* special_function */
733 "R_PPC_SECTOFF_LO", /* name */
734 false, /* partial_inplace */
735 0, /* src_mask */
736 0xffff, /* dst_mask */
737 false), /* pcrel_offset */
738
739 /* 16-bit upper half section relative relocation. */
740 HOWTO (R_PPC_SECTOFF_HI, /* type */
741 16, /* rightshift */
742 1, /* size (0 = byte, 1 = short, 2 = long) */
743 16, /* bitsize */
744 false, /* pc_relative */
745 0, /* bitpos */
746 complain_overflow_bitfield, /* complain_on_overflow */
747 bfd_elf_generic_reloc, /* special_function */
748 "R_PPC_SECTOFF_HI", /* name */
749 false, /* partial_inplace */
750 0, /* src_mask */
751 0xffff, /* dst_mask */
752 false), /* pcrel_offset */
753
754 /* 16-bit upper half adjusted section relative relocation. */
755 HOWTO (R_PPC_SECTOFF_HA, /* type */
756 0, /* rightshift */
757 1, /* size (0 = byte, 1 = short, 2 = long) */
758 16, /* bitsize */
759 false, /* pc_relative */
760 0, /* bitpos */
761 complain_overflow_bitfield, /* complain_on_overflow */
762 bfd_elf_generic_reloc, /* special_function */
763 "R_PPC_SECTOFF_HA", /* name */
764 false, /* partial_inplace */
765 0, /* src_mask */
766 0xffff, /* dst_mask */
767 false), /* pcrel_offset */
768
769 /* The remaining relocs are from the Embedded ELF ABI, and are not
770 in the SVR4 ELF ABI. */
771
772 /* 32 bit value resulting from the addend minus the symbol */
773 HOWTO (R_PPC_EMB_NADDR32, /* type */
774 0, /* rightshift */
775 2, /* size (0 = byte, 1 = short, 2 = long) */
776 32, /* bitsize */
777 false, /* pc_relative */
778 0, /* bitpos */
779 complain_overflow_bitfield, /* complain_on_overflow */
780 bfd_elf_generic_reloc, /* special_function */
781 "R_PPC_EMB_NADDR32", /* name */
782 false, /* partial_inplace */
783 0, /* src_mask */
784 0xffffffff, /* dst_mask */
785 false), /* pcrel_offset */
786
787 /* 16 bit value resulting from the addend minus the symbol */
788 HOWTO (R_PPC_EMB_NADDR16, /* type */
789 0, /* rightshift */
790 1, /* size (0 = byte, 1 = short, 2 = long) */
791 16, /* bitsize */
792 false, /* pc_relative */
793 0, /* bitpos */
794 complain_overflow_bitfield, /* complain_on_overflow */
795 bfd_elf_generic_reloc, /* special_function */
796 "R_PPC_EMB_NADDR16", /* name */
797 false, /* partial_inplace */
798 0, /* src_mask */
799 0xffff, /* dst_mask */
800 false), /* pcrel_offset */
801
802 /* 16 bit value resulting from the addend minus the symbol */
803 HOWTO (R_PPC_EMB_NADDR16_LO, /* type */
804 0, /* rightshift */
805 1, /* size (0 = byte, 1 = short, 2 = long) */
806 16, /* bitsize */
807 false, /* pc_relative */
808 0, /* bitpos */
809 complain_overflow_dont,/* complain_on_overflow */
810 bfd_elf_generic_reloc, /* special_function */
811 "R_PPC_EMB_ADDR16_LO", /* name */
812 false, /* partial_inplace */
813 0, /* src_mask */
814 0xffff, /* dst_mask */
815 false), /* pcrel_offset */
816
817 /* The high order 16 bits of the addend minus the symbol */
818 HOWTO (R_PPC_EMB_NADDR16_HI, /* type */
819 16, /* rightshift */
820 1, /* size (0 = byte, 1 = short, 2 = long) */
821 16, /* bitsize */
822 false, /* pc_relative */
823 0, /* bitpos */
824 complain_overflow_dont, /* complain_on_overflow */
825 bfd_elf_generic_reloc, /* special_function */
826 "R_PPC_EMB_NADDR16_HI", /* name */
827 false, /* partial_inplace */
828 0, /* src_mask */
829 0xffff, /* dst_mask */
830 false), /* pcrel_offset */
831
832 /* The high order 16 bits of the result of the addend minus the address,
833 plus 1 if the contents of the low 16 bits, treated as a signed number,
834 is negative. */
835 HOWTO (R_PPC_EMB_NADDR16_HA, /* type */
836 16, /* rightshift */
837 1, /* size (0 = byte, 1 = short, 2 = long) */
838 16, /* bitsize */
839 false, /* pc_relative */
840 0, /* bitpos */
841 complain_overflow_dont, /* complain_on_overflow */
842 bfd_elf_generic_reloc, /* special_function */
843 "R_PPC_EMB_NADDR16_HA", /* name */
844 false, /* partial_inplace */
845 0, /* src_mask */
846 0xffff, /* dst_mask */
847 false), /* pcrel_offset */
848
849 /* 16 bit value resulting from allocating a 4 byte word to hold an
850 address in the .sdata section, and returning the offset from
851 _SDA_BASE_ for that relocation */
852 HOWTO (R_PPC_EMB_SDAI16, /* type */
853 0, /* rightshift */
854 1, /* size (0 = byte, 1 = short, 2 = long) */
855 16, /* bitsize */
856 false, /* pc_relative */
857 0, /* bitpos */
858 complain_overflow_bitfield, /* complain_on_overflow */
859 bfd_elf_generic_reloc, /* special_function */
860 "R_PPC_EMB_SDAI16", /* name */
861 false, /* partial_inplace */
862 0, /* src_mask */
863 0xffff, /* dst_mask */
864 false), /* pcrel_offset */
865
866 /* 16 bit value resulting from allocating a 4 byte word to hold an
867 address in the .sdata2 section, and returning the offset from
868 _SDA2_BASE_ for that relocation */
869 HOWTO (R_PPC_EMB_SDA2I16, /* type */
870 0, /* rightshift */
871 1, /* size (0 = byte, 1 = short, 2 = long) */
872 16, /* bitsize */
873 false, /* pc_relative */
874 0, /* bitpos */
875 complain_overflow_bitfield, /* complain_on_overflow */
876 bfd_elf_generic_reloc, /* special_function */
877 "R_PPC_EMB_SDA2I16", /* name */
878 false, /* partial_inplace */
879 0, /* src_mask */
880 0xffff, /* dst_mask */
881 false), /* pcrel_offset */
882
883 /* A sign-extended 16 bit value relative to _SDA2_BASE_, for use with
884 small data items. */
885 HOWTO (R_PPC_EMB_SDA2REL, /* type */
886 0, /* rightshift */
887 1, /* size (0 = byte, 1 = short, 2 = long) */
888 16, /* bitsize */
889 false, /* pc_relative */
890 0, /* bitpos */
891 complain_overflow_signed, /* complain_on_overflow */
892 bfd_elf_generic_reloc, /* special_function */
893 "R_PPC_EMB_SDA2REL", /* name */
894 false, /* partial_inplace */
895 0, /* src_mask */
896 0xffff, /* dst_mask */
897 false), /* pcrel_offset */
898
899 /* Relocate against either _SDA_BASE_ or _SDA2_BASE_, filling in the 16 bit
900 signed offset from the appropriate base, and filling in the register
901 field with the appropriate register (0, 2, or 13). */
902 HOWTO (R_PPC_EMB_SDA21, /* type */
903 0, /* rightshift */
904 2, /* size (0 = byte, 1 = short, 2 = long) */
905 16, /* bitsize */
906 false, /* pc_relative */
907 0, /* bitpos */
908 complain_overflow_signed, /* complain_on_overflow */
909 bfd_elf_generic_reloc, /* special_function */
910 "R_PPC_EMB_SDA21", /* name */
911 false, /* partial_inplace */
912 0, /* src_mask */
913 0xffff, /* dst_mask */
914 false), /* pcrel_offset */
915
916 /* Relocation not handled: R_PPC_EMB_MRKREF */
917 /* Relocation not handled: R_PPC_EMB_RELSEC16 */
918 /* Relocation not handled: R_PPC_EMB_RELST_LO */
919 /* Relocation not handled: R_PPC_EMB_RELST_HI */
920 /* Relocation not handled: R_PPC_EMB_RELST_HA */
921 /* Relocation not handled: R_PPC_EMB_BIT_FLD */
922
923 /* PC relative relocation against either _SDA_BASE_ or _SDA2_BASE_, filling
924 in the 16 bit signed offset from the appropriate base, and filling in the
925 register field with the appropriate register (0, 2, or 13). */
926 HOWTO (R_PPC_EMB_RELSDA, /* type */
927 0, /* rightshift */
928 1, /* size (0 = byte, 1 = short, 2 = long) */
929 16, /* bitsize */
930 true, /* pc_relative */
931 0, /* bitpos */
932 complain_overflow_signed, /* complain_on_overflow */
933 bfd_elf_generic_reloc, /* special_function */
934 "R_PPC_EMB_RELSDA", /* name */
935 false, /* partial_inplace */
936 0, /* src_mask */
937 0xffff, /* dst_mask */
938 false), /* pcrel_offset */
939
940 /* Phony reloc to handle AIX style TOC entries */
941 HOWTO (R_PPC_TOC16, /* type */
942 0, /* rightshift */
943 1, /* size (0 = byte, 1 = short, 2 = long) */
944 16, /* bitsize */
945 false, /* pc_relative */
946 0, /* bitpos */
947 complain_overflow_signed, /* complain_on_overflow */
948 bfd_elf_generic_reloc, /* special_function */
949 "R_PPC_TOC16", /* name */
950 false, /* partial_inplace */
951 0, /* src_mask */
952 0xffff, /* dst_mask */
953 false), /* pcrel_offset */
954 };
955
956 \f
957 /* Initialize the ppc_elf_howto_table, so that linear accesses can be done. */
958
959 static void
960 ppc_elf_howto_init ()
961 {
962 unsigned int i, type;
963
964 for (i = 0; i < sizeof (ppc_elf_howto_raw) / sizeof (ppc_elf_howto_raw[0]); i++)
965 {
966 type = ppc_elf_howto_raw[i].type;
967 BFD_ASSERT (type < sizeof(ppc_elf_howto_table) / sizeof(ppc_elf_howto_table[0]));
968 ppc_elf_howto_table[type] = &ppc_elf_howto_raw[i];
969 }
970 }
971
972 \f
973 static reloc_howto_type *
974 ppc_elf_reloc_type_lookup (abfd, code)
975 bfd *abfd;
976 bfd_reloc_code_real_type code;
977 {
978 enum ppc_reloc_type ppc_reloc = R_PPC_NONE;
979
980 if (!ppc_elf_howto_table[ R_PPC_ADDR32 ]) /* Initialize howto table if needed */
981 ppc_elf_howto_init ();
982
983 switch ((int)code)
984 {
985 default:
986 return (reloc_howto_type *)NULL;
987
988 case BFD_RELOC_NONE: ppc_reloc = R_PPC_NONE; break;
989 case BFD_RELOC_32: ppc_reloc = R_PPC_ADDR32; break;
990 case BFD_RELOC_PPC_BA26: ppc_reloc = R_PPC_ADDR24; break;
991 case BFD_RELOC_16: ppc_reloc = R_PPC_ADDR16; break;
992 case BFD_RELOC_LO16: ppc_reloc = R_PPC_ADDR16_LO; break;
993 case BFD_RELOC_HI16: ppc_reloc = R_PPC_ADDR16_HI; break;
994 case BFD_RELOC_HI16_S: ppc_reloc = R_PPC_ADDR16_HA; break;
995 case BFD_RELOC_PPC_BA16: ppc_reloc = R_PPC_ADDR14; break;
996 case BFD_RELOC_PPC_BA16_BRTAKEN: ppc_reloc = R_PPC_ADDR14_BRTAKEN; break;
997 case BFD_RELOC_PPC_BA16_BRNTAKEN: ppc_reloc = R_PPC_ADDR14_BRNTAKEN; break;
998 case BFD_RELOC_PPC_B26: ppc_reloc = R_PPC_REL24; break;
999 case BFD_RELOC_PPC_B16: ppc_reloc = R_PPC_REL14; break;
1000 case BFD_RELOC_PPC_B16_BRTAKEN: ppc_reloc = R_PPC_REL14_BRTAKEN; break;
1001 case BFD_RELOC_PPC_B16_BRNTAKEN: ppc_reloc = R_PPC_REL14_BRNTAKEN; break;
1002 case BFD_RELOC_16_GOTOFF: ppc_reloc = R_PPC_GOT16; break;
1003 case BFD_RELOC_LO16_GOTOFF: ppc_reloc = R_PPC_GOT16_LO; break;
1004 case BFD_RELOC_HI16_GOTOFF: ppc_reloc = R_PPC_GOT16_HI; break;
1005 case BFD_RELOC_HI16_S_GOTOFF: ppc_reloc = R_PPC_GOT16_HA; break;
1006 case BFD_RELOC_24_PLT_PCREL: ppc_reloc = R_PPC_PLTREL24; break;
1007 case BFD_RELOC_PPC_COPY: ppc_reloc = R_PPC_COPY; break;
1008 case BFD_RELOC_PPC_GLOB_DAT: ppc_reloc = R_PPC_GLOB_DAT; break;
1009 case BFD_RELOC_PPC_LOCAL24PC: ppc_reloc = R_PPC_LOCAL24PC; break;
1010 case BFD_RELOC_32_PCREL: ppc_reloc = R_PPC_REL32; break;
1011 case BFD_RELOC_32_PLTOFF: ppc_reloc = R_PPC_PLT32; break;
1012 case BFD_RELOC_32_PLT_PCREL: ppc_reloc = R_PPC_PLTREL32; break;
1013 case BFD_RELOC_LO16_PLTOFF: ppc_reloc = R_PPC_PLT16_LO; break;
1014 case BFD_RELOC_HI16_PLTOFF: ppc_reloc = R_PPC_PLT16_HI; break;
1015 case BFD_RELOC_HI16_S_PLTOFF: ppc_reloc = R_PPC_PLT16_HA; break;
1016 case BFD_RELOC_GPREL16: ppc_reloc = R_PPC_SDAREL16; break;
1017 case BFD_RELOC_32_BASEREL: ppc_reloc = R_PPC_SECTOFF; break;
1018 case BFD_RELOC_LO16_BASEREL: ppc_reloc = R_PPC_SECTOFF_LO; break;
1019 case BFD_RELOC_HI16_BASEREL: ppc_reloc = R_PPC_SECTOFF_HI; break;
1020 case BFD_RELOC_HI16_S_BASEREL: ppc_reloc = R_PPC_SECTOFF_HA; break;
1021 case BFD_RELOC_CTOR: ppc_reloc = R_PPC_ADDR32; break;
1022 case BFD_RELOC_PPC_TOC16: ppc_reloc = R_PPC_TOC16; break;
1023 case BFD_RELOC_PPC_EMB_NADDR32: ppc_reloc = R_PPC_EMB_NADDR32; break;
1024 case BFD_RELOC_PPC_EMB_NADDR16: ppc_reloc = R_PPC_EMB_NADDR16; break;
1025 case BFD_RELOC_PPC_EMB_NADDR16_LO: ppc_reloc = R_PPC_EMB_NADDR16_LO; break;
1026 case BFD_RELOC_PPC_EMB_NADDR16_HI: ppc_reloc = R_PPC_EMB_NADDR16_HI; break;
1027 case BFD_RELOC_PPC_EMB_NADDR16_HA: ppc_reloc = R_PPC_EMB_NADDR16_HA; break;
1028 case BFD_RELOC_PPC_EMB_SDAI16: ppc_reloc = R_PPC_EMB_SDAI16; break;
1029 case BFD_RELOC_PPC_EMB_SDA2I16: ppc_reloc = R_PPC_EMB_SDA2I16; break;
1030 case BFD_RELOC_PPC_EMB_SDA2REL: ppc_reloc = R_PPC_EMB_SDA2REL; break;
1031 case BFD_RELOC_PPC_EMB_SDA21: ppc_reloc = R_PPC_EMB_SDA21; break;
1032 case BFD_RELOC_PPC_EMB_MRKREF: ppc_reloc = R_PPC_EMB_MRKREF; break;
1033 case BFD_RELOC_PPC_EMB_RELSEC16: ppc_reloc = R_PPC_EMB_RELSEC16; break;
1034 case BFD_RELOC_PPC_EMB_RELST_LO: ppc_reloc = R_PPC_EMB_RELST_LO; break;
1035 case BFD_RELOC_PPC_EMB_RELST_HI: ppc_reloc = R_PPC_EMB_RELST_HI; break;
1036 case BFD_RELOC_PPC_EMB_RELST_HA: ppc_reloc = R_PPC_EMB_RELST_HA; break;
1037 case BFD_RELOC_PPC_EMB_BIT_FLD: ppc_reloc = R_PPC_EMB_BIT_FLD; break;
1038 case BFD_RELOC_PPC_EMB_RELSDA: ppc_reloc = R_PPC_EMB_RELSDA; break;
1039 }
1040
1041 return ppc_elf_howto_table[ (int)ppc_reloc ];
1042 };
1043
1044 /* Set the howto pointer for a PowerPC ELF reloc. */
1045
1046 static void
1047 ppc_elf_info_to_howto (abfd, cache_ptr, dst)
1048 bfd *abfd;
1049 arelent *cache_ptr;
1050 Elf32_Internal_Rela *dst;
1051 {
1052 if (!ppc_elf_howto_table[ R_PPC_ADDR32 ]) /* Initialize howto table if needed */
1053 ppc_elf_howto_init ();
1054
1055 BFD_ASSERT (ELF32_R_TYPE (dst->r_info) < (unsigned int) R_PPC_max);
1056 cache_ptr->howto = ppc_elf_howto_table[ELF32_R_TYPE (dst->r_info)];
1057 }
1058
1059 /* Handle the R_PPC_ADDR16_HA reloc. */
1060
1061 static bfd_reloc_status_type
1062 ppc_elf_addr16_ha_reloc (abfd, reloc_entry, symbol, data, input_section,
1063 output_bfd, error_message)
1064 bfd *abfd;
1065 arelent *reloc_entry;
1066 asymbol *symbol;
1067 PTR data;
1068 asection *input_section;
1069 bfd *output_bfd;
1070 char **error_message;
1071 {
1072 bfd_vma relocation;
1073
1074 if (output_bfd != NULL)
1075 {
1076 reloc_entry->address += input_section->output_offset;
1077 return bfd_reloc_ok;
1078 }
1079
1080 if (reloc_entry->address > input_section->_cooked_size)
1081 return bfd_reloc_outofrange;
1082
1083 if (bfd_is_com_section (symbol->section))
1084 relocation = 0;
1085 else
1086 relocation = symbol->value;
1087
1088 relocation += symbol->section->output_section->vma;
1089 relocation += symbol->section->output_offset;
1090 relocation += reloc_entry->addend;
1091
1092 reloc_entry->addend += (relocation & 0x8000) << 1;
1093
1094 return bfd_reloc_continue;
1095 }
1096
1097 /* Function to set whether a module needs the -mrelocatable bit set. */
1098
1099 static boolean
1100 ppc_elf_set_private_flags (abfd, flags)
1101 bfd *abfd;
1102 flagword flags;
1103 {
1104 BFD_ASSERT (!elf_flags_init (abfd)
1105 || elf_elfheader (abfd)->e_flags == flags);
1106
1107 elf_elfheader (abfd)->e_flags = flags;
1108 elf_flags_init (abfd) = true;
1109 return true;
1110 }
1111
1112 /* Copy backend specific data from one object module to another */
1113 static boolean
1114 ppc_elf_copy_private_bfd_data (ibfd, obfd)
1115 bfd *ibfd;
1116 bfd *obfd;
1117 {
1118 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
1119 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
1120 return true;
1121
1122 BFD_ASSERT (!elf_flags_init (obfd)
1123 || elf_elfheader (obfd)->e_flags == elf_elfheader (ibfd)->e_flags);
1124
1125 elf_elfheader (obfd)->e_flags = elf_elfheader (ibfd)->e_flags;
1126 elf_flags_init (obfd) = true;
1127 return true;
1128 }
1129
1130 /* Merge backend specific data from an object file to the output
1131 object file when linking */
1132 static boolean
1133 ppc_elf_merge_private_bfd_data (ibfd, obfd)
1134 bfd *ibfd;
1135 bfd *obfd;
1136 {
1137 flagword old_flags;
1138 flagword new_flags;
1139 boolean error;
1140
1141 /* Check if we have the same endianess */
1142 if (ibfd->xvec->byteorder != obfd->xvec->byteorder
1143 && obfd->xvec->byteorder != BFD_ENDIAN_UNKNOWN)
1144 {
1145 (*_bfd_error_handler)
1146 ("%s: compiled for a %s endian system and target is %s endian",
1147 bfd_get_filename (ibfd),
1148 bfd_big_endian (ibfd) ? "big" : "little",
1149 bfd_big_endian (obfd) ? "big" : "little");
1150
1151 bfd_set_error (bfd_error_wrong_format);
1152 return false;
1153 }
1154
1155 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
1156 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
1157 return true;
1158
1159 new_flags = elf_elfheader (ibfd)->e_flags;
1160 old_flags = elf_elfheader (obfd)->e_flags;
1161 if (!elf_flags_init (obfd)) /* First call, no flags set */
1162 {
1163 elf_flags_init (obfd) = true;
1164 elf_elfheader (obfd)->e_flags = new_flags;
1165 }
1166
1167 else if (new_flags == old_flags) /* Compatible flags are ok */
1168 ;
1169
1170 else /* Incompatible flags */
1171 {
1172 /* Warn about -mrelocatable mismatch. Allow -mrelocatable-lib to be linked
1173 with either. */
1174 error = false;
1175 if ((new_flags & EF_PPC_RELOCATABLE) != 0
1176 && (old_flags & (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB)) == 0)
1177 {
1178 error = true;
1179 (*_bfd_error_handler)
1180 ("%s: compiled with -mrelocatable and linked with modules compiled normally",
1181 bfd_get_filename (ibfd));
1182 }
1183 else if ((new_flags & (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB)) == 0
1184 && (old_flags & EF_PPC_RELOCATABLE) != 0)
1185 {
1186 error = true;
1187 (*_bfd_error_handler)
1188 ("%s: compiled normally and linked with modules compiled with -mrelocatable",
1189 bfd_get_filename (ibfd));
1190 }
1191 /* If -mrelocatable-lib is linked with an object without -mrelocatable-lib, turn off
1192 the -mrelocatable-lib, since at least one module isn't relocatable. */
1193 else if ((old_flags & EF_PPC_RELOCATABLE_LIB) != 0
1194 && (new_flags & EF_PPC_RELOCATABLE_LIB) == 0)
1195 elf_elfheader (obfd)->e_flags &= ~EF_PPC_RELOCATABLE_LIB;
1196
1197
1198 /* Do not warn about eabi vs. V.4 mismatch, just or in the bit if any module uses it */
1199 elf_elfheader (obfd)->e_flags |= (new_flags & EF_PPC_EMB);
1200
1201 new_flags &= ~ (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB | EF_PPC_EMB);
1202 old_flags &= ~ (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB | EF_PPC_EMB);
1203
1204 /* Warn about any other mismatches */
1205 if (new_flags != old_flags)
1206 {
1207 error = true;
1208 (*_bfd_error_handler)
1209 ("%s: uses different e_flags (0x%lx) fields than previous modules (0x%lx)",
1210 bfd_get_filename (ibfd), (long)new_flags, (long)old_flags);
1211 }
1212
1213 if (error)
1214 {
1215 bfd_set_error (bfd_error_bad_value);
1216 return false;
1217 }
1218 }
1219
1220 return true;
1221 }
1222
1223 \f
1224 /* Handle a PowerPC specific section when reading an object file. This
1225 is called when elfcode.h finds a section with an unknown type. */
1226
1227 static boolean
1228 ppc_elf_section_from_shdr (abfd, hdr, name)
1229 bfd *abfd;
1230 Elf32_Internal_Shdr *hdr;
1231 char *name;
1232 {
1233 asection *newsect;
1234 flagword flags;
1235
1236 if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name))
1237 return false;
1238
1239 newsect = hdr->bfd_section;
1240 flags = bfd_get_section_flags (abfd, newsect);
1241 if (hdr->sh_flags & SHF_EXCLUDE)
1242 flags |= SEC_EXCLUDE;
1243
1244 if (hdr->sh_type == SHT_ORDERED)
1245 flags |= SEC_SORT_ENTRIES;
1246
1247 bfd_set_section_flags (abfd, newsect, flags);
1248 return true;
1249 }
1250
1251 \f
1252 /* Set up any other section flags and such that may be necessary. */
1253
1254 static boolean
1255 ppc_elf_fake_sections (abfd, shdr, asect)
1256 bfd *abfd;
1257 Elf32_Internal_Shdr *shdr;
1258 asection *asect;
1259 {
1260 if ((asect->flags & SEC_EXCLUDE) != 0)
1261 shdr->sh_flags |= SHF_EXCLUDE;
1262
1263 if ((asect->flags & SEC_SORT_ENTRIES) != 0)
1264 shdr->sh_type = SHT_ORDERED;
1265
1266 return true;
1267 }
1268
1269 \f
1270 /* Create a special linker section */
1271 static elf_linker_section_t *
1272 ppc_elf_create_linker_section (abfd, info, which)
1273 bfd *abfd;
1274 struct bfd_link_info *info;
1275 enum elf_linker_section_enum which;
1276 {
1277 bfd *dynobj = elf_hash_table (info)->dynobj;
1278 elf_linker_section_t *lsect;
1279
1280 /* Record the first bfd section that needs the special section */
1281 if (!dynobj)
1282 dynobj = elf_hash_table (info)->dynobj = abfd;
1283
1284 /* If this is the first time, create the section */
1285 lsect = elf_linker_section (dynobj, which);
1286 if (!lsect)
1287 {
1288 elf_linker_section_t defaults;
1289 static elf_linker_section_t zero_section;
1290
1291 defaults = zero_section;
1292 defaults.which = which;
1293 defaults.hole_written_p = false;
1294 defaults.alignment = 2;
1295 defaults.flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS
1296 | SEC_IN_MEMORY | SEC_LINKER_CREATED);
1297
1298 switch (which)
1299 {
1300 default:
1301 (*_bfd_error_handler) ("%s: Unknown special linker type %d",
1302 bfd_get_filename (abfd),
1303 (int)which);
1304
1305 bfd_set_error (bfd_error_bad_value);
1306 return (elf_linker_section_t *)0;
1307
1308 case LINKER_SECTION_GOT: /* .got section */
1309 defaults.name = ".got";
1310 defaults.rel_name = ".rela.got";
1311 defaults.sym_name = "_GLOBAL_OFFSET_TABLE_";
1312 defaults.max_hole_offset = 32764;
1313 defaults.hole_size = 16;
1314 defaults.sym_offset = 4;
1315 break;
1316
1317 case LINKER_SECTION_PLT: /* .plt section */
1318 defaults.name = ".plt";
1319 defaults.rel_name = ".rela.plt";
1320 defaults.sym_name = (char *)0;
1321 defaults.max_hole_offset = 0;
1322 defaults.hole_size = 0;
1323 defaults.sym_offset = 0;
1324 defaults.flags &= ~SEC_LOAD;
1325 break;
1326
1327 case LINKER_SECTION_SDATA: /* .sdata/.sbss section */
1328 defaults.name = ".sdata";
1329 defaults.rel_name = ".rela.sdata";
1330 defaults.bss_name = ".sbss";
1331 defaults.sym_name = "_SDA_BASE_";
1332 defaults.sym_offset = 32768;
1333 break;
1334
1335 case LINKER_SECTION_SDATA2: /* .sdata2/.sbss2 section */
1336 defaults.name = ".sdata2";
1337 defaults.rel_name = ".rela.sdata2";
1338 defaults.bss_name = ".sbss2";
1339 defaults.sym_name = "_SDA2_BASE_";
1340 defaults.sym_offset = 32768;
1341 defaults.flags |= SEC_READONLY;
1342 break;
1343 }
1344
1345 lsect = _bfd_elf_create_linker_section (abfd, info, which, &defaults);
1346 }
1347
1348 return lsect;
1349 }
1350
1351 \f
1352 /* If we have a non-zero sized .sbss2 or .PPC.EMB.sbss0 sections, we need to bump up
1353 the number of section headers. */
1354
1355 static int
1356 ppc_elf_additional_program_headers (abfd)
1357 bfd *abfd;
1358 {
1359 asection *s;
1360 int ret;
1361
1362 ret = 0;
1363
1364 s = bfd_get_section_by_name (abfd, ".interp");
1365 if (s != NULL)
1366 ++ret;
1367
1368 s = bfd_get_section_by_name (abfd, ".sbss2");
1369 if (s != NULL && (s->flags & SEC_LOAD) != 0 && s->_raw_size > 0)
1370 ++ret;
1371
1372 s = bfd_get_section_by_name (abfd, ".PPC.EMB.sbss0");
1373 if (s != NULL && (s->flags & SEC_LOAD) != 0 && s->_raw_size > 0)
1374 ++ret;
1375
1376 return ret;
1377 }
1378
1379 /* Modify the segment map if needed */
1380
1381 static boolean
1382 ppc_elf_modify_segment_map (abfd)
1383 bfd *abfd;
1384 {
1385 return true;
1386 }
1387 \f
1388 /* Adjust a symbol defined by a dynamic object and referenced by a
1389 regular object. The current definition is in some section of the
1390 dynamic object, but we're not including those sections. We have to
1391 change the definition to something the rest of the link can
1392 understand. */
1393
1394 static boolean
1395 ppc_elf_adjust_dynamic_symbol (info, h)
1396 struct bfd_link_info *info;
1397 struct elf_link_hash_entry *h;
1398 {
1399 bfd *dynobj = elf_hash_table (info)->dynobj;
1400 asection *s;
1401 unsigned int power_of_two;
1402 bfd_vma plt_offset;
1403
1404 #ifdef DEBUG
1405 fprintf (stderr, "ppc_elf_adjust_dynamic_symbol called for %s\n", h->root.root.string);
1406 #endif
1407
1408 /* Make sure we know what is going on here. */
1409 BFD_ASSERT (dynobj != NULL
1410 && ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT)
1411 || h->weakdef != NULL
1412 || ((h->elf_link_hash_flags
1413 & ELF_LINK_HASH_DEF_DYNAMIC) != 0
1414 && (h->elf_link_hash_flags
1415 & ELF_LINK_HASH_REF_REGULAR) != 0
1416 && (h->elf_link_hash_flags
1417 & ELF_LINK_HASH_DEF_REGULAR) == 0)));
1418
1419
1420 /* If this is a function, put it in the procedure linkage table. We
1421 will fill in the contents of the procedure linkage table later,
1422 when we know the address of the .got section. */
1423 if (h->type == STT_FUNC
1424 || (h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0)
1425 {
1426 if (! info->shared
1427 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) == 0
1428 && (h->elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) == 0)
1429 {
1430 /* This case can occur if we saw a PLT32 reloc in an input
1431 file, but the symbol was never referred to by a dynamic
1432 object. In such a case, we don't actually need to build
1433 a procedure linkage table, and we can just do a PC32
1434 reloc instead. */
1435 BFD_ASSERT ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0);
1436 return true;
1437 }
1438
1439 /* Make sure this symbol is output as a dynamic symbol. */
1440 if (h->dynindx == -1)
1441 {
1442 if (! bfd_elf32_link_record_dynamic_symbol (info, h))
1443 return false;
1444 }
1445
1446 s = bfd_get_section_by_name (dynobj, ".plt");
1447 BFD_ASSERT (s != NULL);
1448
1449 /* If this is the first .plt entry, make room for the special
1450 first entry. */
1451 if (s->_raw_size == 0)
1452 s->_raw_size += PLT_INITIAL_ENTRY_SIZE;
1453
1454 /* The PowerPC PLT is actually composed of two parts, the first part
1455 is 2 words (for a load and a jump), and then there is a remaining
1456 word available at the end. */
1457 plt_offset = (PLT_INITIAL_ENTRY_SIZE
1458 + 8 * ((s->_raw_size - PLT_INITIAL_ENTRY_SIZE) / PLT_ENTRY_SIZE));
1459
1460 /* If this symbol is not defined in a regular file, and we are
1461 not generating a shared library, then set the symbol to this
1462 location in the .plt. This is required to make function
1463 pointers compare as equal between the normal executable and
1464 the shared library. */
1465 if (! info->shared
1466 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
1467 {
1468 h->root.u.def.section = s;
1469 h->root.u.def.value = plt_offset;
1470 }
1471
1472 h->plt_offset = plt_offset;
1473
1474 /* Make room for this entry. */
1475 s->_raw_size += PLT_ENTRY_SIZE;
1476
1477 #if 0
1478 /* We also need to make an entry in the .got.plt section, which
1479 will be placed in the .got section by the linker script. */
1480
1481 s = bfd_get_section_by_name (dynobj, ".got.plt");
1482 BFD_ASSERT (s != NULL);
1483 s->_raw_size += 4;
1484 #endif
1485
1486 /* We also need to make an entry in the .rela.plt section. */
1487
1488 s = bfd_get_section_by_name (dynobj, ".rela.plt");
1489 BFD_ASSERT (s != NULL);
1490 s->_raw_size += sizeof (Elf32_External_Rela);
1491
1492 return true;
1493 }
1494
1495 /* If this is a weak symbol, and there is a real definition, the
1496 processor independent code will have arranged for us to see the
1497 real definition first, and we can just use the same value. */
1498 if (h->weakdef != NULL)
1499 {
1500 BFD_ASSERT (h->weakdef->root.type == bfd_link_hash_defined
1501 || h->weakdef->root.type == bfd_link_hash_defweak);
1502 h->root.u.def.section = h->weakdef->root.u.def.section;
1503 h->root.u.def.value = h->weakdef->root.u.def.value;
1504 return true;
1505 }
1506
1507 /* This is a reference to a symbol defined by a dynamic object which
1508 is not a function. */
1509
1510 /* If we are creating a shared library, we must presume that the
1511 only references to the symbol are via the global offset table.
1512 For such cases we need not do anything here; the relocations will
1513 be handled correctly by relocate_section. */
1514 if (info->shared)
1515 return true;
1516
1517 /* We must allocate the symbol in our .dynbss section, which will
1518 become part of the .bss section of the executable. There will be
1519 an entry for this symbol in the .dynsym section. The dynamic
1520 object will contain position independent code, so all references
1521 from the dynamic object to this symbol will go through the global
1522 offset table. The dynamic linker will use the .dynsym entry to
1523 determine the address it must put in the global offset table, so
1524 both the dynamic object and the regular object will refer to the
1525 same memory location for the variable. */
1526
1527 s = bfd_get_section_by_name (dynobj, ".dynbss");
1528 BFD_ASSERT (s != NULL);
1529
1530 /* We must generate a R_PPC_COPY reloc to tell the dynamic linker to
1531 copy the initial value out of the dynamic object and into the
1532 runtime process image. We need to remember the offset into the
1533 .rela.bss section we are going to use. */
1534 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
1535 {
1536 asection *srel;
1537
1538 srel = bfd_get_section_by_name (dynobj, ".rela.bss");
1539 BFD_ASSERT (srel != NULL);
1540 srel->_raw_size += sizeof (Elf32_External_Rel);
1541 h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_COPY;
1542 }
1543
1544 /* We need to figure out the alignment required for this symbol. I
1545 have no idea how ELF linkers handle this. */
1546 power_of_two = bfd_log2 (h->size);
1547 if (power_of_two > 3)
1548 power_of_two = 3;
1549
1550 /* Apply the required alignment. */
1551 s->_raw_size = BFD_ALIGN (s->_raw_size,
1552 (bfd_size_type) (1 << power_of_two));
1553 if (power_of_two > bfd_get_section_alignment (dynobj, s))
1554 {
1555 if (! bfd_set_section_alignment (dynobj, s, power_of_two))
1556 return false;
1557 }
1558
1559 /* Define the symbol as being at this point in the section. */
1560 h->root.u.def.section = s;
1561 h->root.u.def.value = s->_raw_size;
1562
1563 /* Increment the section size to make room for the symbol. */
1564 s->_raw_size += h->size;
1565
1566 return true;
1567 }
1568
1569 \f
1570 /* Increment the index of a dynamic symbol by a given amount. Called
1571 via elf_link_hash_traverse. */
1572
1573 static boolean
1574 ppc_elf_adjust_dynindx (h, cparg)
1575 struct elf_link_hash_entry *h;
1576 PTR cparg;
1577 {
1578 int *cp = (int *) cparg;
1579
1580 #ifdef DEBUG
1581 fprintf (stderr, "ppc_elf_adjust_dynindx called, h->dynindx = %d, *cp = %d\n", h->dynindx, *cp);
1582 #endif
1583
1584 if (h->dynindx != -1)
1585 h->dynindx += *cp;
1586
1587 return true;
1588 }
1589
1590 \f
1591 /* Set the sizes of the dynamic sections. */
1592
1593 static boolean
1594 ppc_elf_size_dynamic_sections (output_bfd, info)
1595 bfd *output_bfd;
1596 struct bfd_link_info *info;
1597 {
1598 bfd *dynobj;
1599 asection *s;
1600 boolean plt;
1601 boolean relocs;
1602 boolean reltext;
1603
1604 #ifdef DEBUG
1605 fprintf (stderr, "ppc_elf_size_dynamic_sections called\n");
1606 #endif
1607
1608 dynobj = elf_hash_table (info)->dynobj;
1609 BFD_ASSERT (dynobj != NULL);
1610
1611 if (elf_hash_table (info)->dynamic_sections_created)
1612 {
1613 /* Set the contents of the .interp section to the interpreter. */
1614 if (! info->shared)
1615 {
1616 s = bfd_get_section_by_name (dynobj, ".interp");
1617 BFD_ASSERT (s != NULL);
1618 s->_raw_size = sizeof ELF_DYNAMIC_INTERPRETER;
1619 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
1620 }
1621 }
1622 else
1623 {
1624 /* We may have created entries in the .rela.got, .rela.sdata, and
1625 .rela.sdata2 sections. However, if we are not creating the
1626 dynamic sections, we will not actually use these entries. Reset
1627 the size of .rela.got, et al, which will cause it to get
1628 stripped from the output file below. */
1629 static char *rela_sections[] = { ".rela.got", ".rela.sdata", ".rela.sdata", (char *)0 };
1630 char **p;
1631
1632 for (p = rela_sections; *p != (char *)0; p++)
1633 {
1634 s = bfd_get_section_by_name (dynobj, *p);
1635 if (s != NULL)
1636 s->_raw_size = 0;
1637 }
1638 }
1639
1640 /* The check_relocs and adjust_dynamic_symbol entry points have
1641 determined the sizes of the various dynamic sections. Allocate
1642 memory for them. */
1643 plt = false;
1644 relocs = false;
1645 reltext = false;
1646 for (s = dynobj->sections; s != NULL; s = s->next)
1647 {
1648 const char *name;
1649 boolean strip;
1650
1651 if ((s->flags & SEC_LINKER_CREATED) == 0)
1652 continue;
1653
1654 /* It's OK to base decisions on the section name, because none
1655 of the dynobj section names depend upon the input files. */
1656 name = bfd_get_section_name (dynobj, s);
1657
1658 strip = false;
1659
1660 if (strcmp (name, ".plt") == 0)
1661 {
1662 if (s->_raw_size == 0)
1663 {
1664 /* Strip this section if we don't need it; see the
1665 comment below. */
1666 strip = true;
1667 }
1668 else
1669 {
1670 /* Remember whether there is a PLT. */
1671 plt = true;
1672 }
1673 }
1674 else if (strncmp (name, ".rela", 5) == 0)
1675 {
1676 if (s->_raw_size == 0)
1677 {
1678 /* If we don't need this section, strip it from the
1679 output file. This is mostly to handle .rela.bss and
1680 .rela.plt. We must create both sections in
1681 create_dynamic_sections, because they must be created
1682 before the linker maps input sections to output
1683 sections. The linker does that before
1684 adjust_dynamic_symbol is called, and it is that
1685 function which decides whether anything needs to go
1686 into these sections. */
1687 strip = true;
1688 }
1689 else
1690 {
1691 asection *target;
1692
1693 /* Remember whether there are any reloc sections other
1694 than .rel.plt. */
1695 if (strcmp (name, ".rela.plt") != 0)
1696 {
1697 const char *outname;
1698
1699 relocs = true;
1700
1701 /* If this relocation section applies to a read only
1702 section, then we probably need a DT_TEXTREL
1703 entry. The entries in the .rel.plt section
1704 really apply to the .got section, which we
1705 created ourselves and so know is not readonly. */
1706 outname = bfd_get_section_name (output_bfd,
1707 s->output_section);
1708 target = bfd_get_section_by_name (output_bfd, outname + 4);
1709 if (target != NULL
1710 && (target->flags & SEC_READONLY) != 0)
1711 reltext = true;
1712 }
1713
1714 /* We use the reloc_count field as a counter if we need
1715 to copy relocs into the output file. */
1716 s->reloc_count = 0;
1717 }
1718 }
1719 else if (strcmp (name, ".got") != 0
1720 && strcmp (name, ".sdata") != 0
1721 && strcmp (name, ".sdata2") != 0)
1722 {
1723 /* It's not one of our sections, so don't allocate space. */
1724 continue;
1725 }
1726
1727 if (strip)
1728 {
1729 asection **spp;
1730
1731 for (spp = &s->output_section->owner->sections;
1732 *spp != s->output_section;
1733 spp = &(*spp)->next)
1734 ;
1735 *spp = s->output_section->next;
1736 --s->output_section->owner->section_count;
1737
1738 continue;
1739 }
1740
1741 /* Allocate memory for the section contents. */
1742 s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->_raw_size);
1743 if (s->contents == NULL && s->_raw_size != 0)
1744 return false;
1745 }
1746
1747 if (elf_hash_table (info)->dynamic_sections_created)
1748 {
1749 /* Add some entries to the .dynamic section. We fill in the
1750 values later, in ppc_elf_finish_dynamic_sections, but we
1751 must add the entries now so that we get the correct size for
1752 the .dynamic section. The DT_DEBUG entry is filled in by the
1753 dynamic linker and used by the debugger. */
1754 if (! info->shared)
1755 {
1756 if (! bfd_elf32_add_dynamic_entry (info, DT_DEBUG, 0))
1757 return false;
1758 }
1759
1760 if (plt)
1761 {
1762 if (! bfd_elf32_add_dynamic_entry (info, DT_PLTGOT, 0)
1763 || ! bfd_elf32_add_dynamic_entry (info, DT_PLTRELSZ, 0)
1764 || ! bfd_elf32_add_dynamic_entry (info, DT_PLTREL, DT_REL)
1765 || ! bfd_elf32_add_dynamic_entry (info, DT_JMPREL, 0))
1766 return false;
1767 }
1768
1769 if (relocs)
1770 {
1771 if (! bfd_elf32_add_dynamic_entry (info, DT_RELA, 0)
1772 || ! bfd_elf32_add_dynamic_entry (info, DT_RELASZ, DT_RELA)
1773 || ! bfd_elf32_add_dynamic_entry (info, DT_RELENT,
1774 sizeof (Elf32_External_Rela)))
1775 return false;
1776 }
1777
1778 if (reltext)
1779 {
1780 if (! bfd_elf32_add_dynamic_entry (info, DT_TEXTREL, 0))
1781 return false;
1782 }
1783 }
1784
1785 /* If we are generating a shared library, we generate a section
1786 symbol for each output section. These are local symbols, which
1787 means that they must come first in the dynamic symbol table.
1788 That means we must increment the dynamic symbol index of every
1789 other dynamic symbol. */
1790 if (info->shared)
1791 {
1792 int c, i;
1793
1794 c = bfd_count_sections (output_bfd);
1795 elf_link_hash_traverse (elf_hash_table (info),
1796 ppc_elf_adjust_dynindx,
1797 (PTR) &c);
1798 elf_hash_table (info)->dynsymcount += c;
1799
1800 for (i = 1, s = output_bfd->sections; s != NULL; s = s->next, i++)
1801 {
1802 elf_section_data (s)->dynindx = i;
1803 /* These symbols will have no names, so we don't need to
1804 fiddle with dynstr_index. */
1805 }
1806 }
1807
1808 return true;
1809 }
1810
1811 \f
1812 /* Look through the relocs for a section during the first phase, and
1813 allocate space in the global offset table or procedure linkage
1814 table. */
1815
1816 static boolean
1817 ppc_elf_check_relocs (abfd, info, sec, relocs)
1818 bfd *abfd;
1819 struct bfd_link_info *info;
1820 asection *sec;
1821 const Elf_Internal_Rela *relocs;
1822 {
1823 boolean ret = true;
1824 bfd *dynobj;
1825 Elf_Internal_Shdr *symtab_hdr;
1826 struct elf_link_hash_entry **sym_hashes;
1827 const Elf_Internal_Rela *rel;
1828 const Elf_Internal_Rela *rel_end;
1829 bfd_vma *local_got_offsets;
1830 elf_linker_section_t *got;
1831 elf_linker_section_t *sdata;
1832 elf_linker_section_t *sdata2;
1833 asection *sreloc;
1834
1835 if (info->relocateable)
1836 return true;
1837
1838 #ifdef DEBUG
1839 fprintf (stderr, "ppc_elf_check_relocs called for section %s in %s\n",
1840 bfd_get_section_name (abfd, sec),
1841 bfd_get_filename (abfd));
1842 #endif
1843
1844 /* Create the linker generated sections all the time so that the
1845 special symbols are created. The .got section is an exception,
1846 so that we don't waste space allocating it when it is not needed. */
1847
1848 #if 0
1849 if ((plt = elf_linker_section (abfd, LINKER_SECTION_PLT)) == NULL)
1850 {
1851 plt = ppc_elf_create_linker_section (abfd, info, LINKER_SECTION_PLT);
1852 if (!plt)
1853 ret = false;
1854 }
1855 #endif
1856
1857 if ((sdata = elf_linker_section (abfd, LINKER_SECTION_SDATA)) == NULL)
1858 {
1859 sdata = ppc_elf_create_linker_section (abfd, info, LINKER_SECTION_SDATA);
1860 if (!sdata)
1861 ret = false;
1862 }
1863
1864
1865 if ((sdata2 = elf_linker_section (abfd, LINKER_SECTION_SDATA2)) == NULL)
1866 {
1867 sdata2 = ppc_elf_create_linker_section (abfd, info, LINKER_SECTION_SDATA2);
1868 if (!sdata2)
1869 ret = false;
1870 }
1871
1872 if ((got = elf_linker_section (abfd, LINKER_SECTION_GOT)) == NULL)
1873 {
1874 got = ppc_elf_create_linker_section (abfd, info, LINKER_SECTION_GOT);
1875 if (!got)
1876 ret = false;
1877 }
1878
1879 dynobj = elf_hash_table (info)->dynobj;
1880 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
1881 sym_hashes = elf_sym_hashes (abfd);
1882 local_got_offsets = elf_local_got_offsets (abfd);
1883
1884 sreloc = NULL;
1885
1886 rel_end = relocs + sec->reloc_count;
1887 for (rel = relocs; rel < rel_end; rel++)
1888 {
1889 unsigned long r_symndx;
1890 struct elf_link_hash_entry *h;
1891
1892 r_symndx = ELF32_R_SYM (rel->r_info);
1893 if (r_symndx < symtab_hdr->sh_info)
1894 h = NULL;
1895 else
1896 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
1897
1898 switch (ELF32_R_TYPE (rel->r_info))
1899 {
1900 /* GOT16 relocations */
1901 case R_PPC_GOT16:
1902 case R_PPC_GOT16_LO:
1903 case R_PPC_GOT16_HI:
1904 case R_PPC_GOT16_HA:
1905 if (got->rel_section == NULL
1906 && (h != NULL || info->shared)
1907 && !_bfd_elf_make_linker_section_rela (dynobj, got, 2))
1908 {
1909 ret = false;
1910 break;
1911 }
1912
1913 if (!bfd_elf32_create_pointer_linker_section (abfd, info, got, h, rel))
1914 ret = false;
1915
1916 break;
1917
1918 /* Indirect .sdata relocation */
1919 case R_PPC_EMB_SDAI16:
1920 if (info->shared)
1921 {
1922 (*_bfd_error_handler) ("%s: relocation %s cannot be used when making a shared object",
1923 bfd_get_filename (abfd),
1924 "R_PPC_EMB_SDAI16");
1925 ret = false;
1926 break;
1927 }
1928
1929 if (got == NULL
1930 && (got = elf_linker_section (abfd, LINKER_SECTION_GOT)) == NULL)
1931 {
1932 got = ppc_elf_create_linker_section (abfd, info,
1933 LINKER_SECTION_GOT);
1934 if (!got)
1935 {
1936 ret = false;
1937 break;
1938 }
1939 }
1940
1941 if (got->rel_section == NULL
1942 && (h != NULL || info->shared)
1943 && !_bfd_elf_make_linker_section_rela (dynobj, got, 2))
1944 {
1945 ret = false;
1946 break;
1947 }
1948
1949 if (!bfd_elf32_create_pointer_linker_section (abfd, info, sdata, h, rel))
1950 ret = false;
1951
1952 break;
1953
1954 /* Indirect .sdata2 relocation */
1955 case R_PPC_EMB_SDA2I16:
1956 if (info->shared)
1957 {
1958 (*_bfd_error_handler) ("%s: relocation %s cannot be used when making a shared object",
1959 bfd_get_filename (abfd),
1960 "R_PPC_EMB_SDA2I16");
1961 ret = false;
1962 break;
1963 }
1964
1965 if (got == NULL
1966 && (got = elf_linker_section (abfd, LINKER_SECTION_GOT)) == NULL)
1967 {
1968 got = ppc_elf_create_linker_section (abfd, info,
1969 LINKER_SECTION_GOT);
1970 if (!got)
1971 {
1972 ret = false;
1973 break;
1974 }
1975 }
1976
1977 if (got->rel_section == NULL
1978 && (h != NULL || info->shared)
1979 && !_bfd_elf_make_linker_section_rela (dynobj, got, 2))
1980 return false;
1981
1982 if (!bfd_elf32_create_pointer_linker_section (abfd, info, sdata2, h, rel))
1983 return false;
1984
1985 break;
1986
1987 case R_PPC_SDAREL16:
1988 case R_PPC_EMB_SDA2REL:
1989 case R_PPC_EMB_SDA21:
1990 if (info->shared)
1991 {
1992 (*_bfd_error_handler) ("%s: relocation %s cannot be used when making a shared object",
1993 bfd_get_filename (abfd),
1994 ppc_elf_howto_table[(int)ELF32_R_TYPE (rel->r_info)]->name);
1995 ret = false;
1996 }
1997 break;
1998
1999 case R_PPC_PLT32:
2000 case R_PPC_PLTREL24:
2001 case R_PPC_PLT16_LO:
2002 case R_PPC_PLT16_HI:
2003 case R_PPC_PLT16_HA:
2004 #ifdef DEBUG
2005 fprintf (stderr, "Reloc requires a PLT entry\n");
2006 #endif
2007 /* This symbol requires a procedure linkage table entry. We
2008 actually build the entry in adjust_dynamic_symbol,
2009 because this might be a case of linking PIC code without
2010 linking in any dynamic objects, in which case we don't
2011 need to generate a procedure linkage table after all. */
2012
2013 if (h == NULL)
2014 {
2015 /* It does not make sense to have a procedure linkage
2016 table entry for a local symbol. */
2017 bfd_set_error (bfd_error_bad_value);
2018 ret = false;
2019 break;
2020 }
2021
2022 /* Make sure this symbol is output as a dynamic symbol. */
2023 if (h->dynindx == -1)
2024 {
2025 if (! bfd_elf32_link_record_dynamic_symbol (info, h))
2026 {
2027 ret = false;
2028 break;
2029 }
2030 }
2031
2032 h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
2033 break;
2034
2035 /* the following relocations don't need to propigate the relocation if
2036 linking a shared object since they are section relative. */
2037 case R_PPC_SECTOFF:
2038 case R_PPC_SECTOFF_LO:
2039 case R_PPC_SECTOFF_HI:
2040 case R_PPC_SECTOFF_HA:
2041 break;
2042
2043 /* This refers only to functions defined in the shared library */
2044 case R_PPC_LOCAL24PC:
2045 break;
2046
2047 /* When creating a shared object, we must copy these
2048 relocs into the output file. We create a reloc
2049 section in dynobj and make room for the reloc. */
2050 case R_PPC_REL24:
2051 if (h != NULL
2052 && strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
2053 break;
2054 /* fall through */
2055
2056 case R_PPC_REL14:
2057 case R_PPC_REL14_BRTAKEN:
2058 case R_PPC_REL14_BRNTAKEN:
2059 if (h == NULL)
2060 break;
2061 /* fall through */
2062
2063 default:
2064 if (info->shared
2065 && (sec->flags & SEC_ALLOC) != 0)
2066 {
2067 #ifdef DEBUG
2068 fprintf (stderr, "ppc_elf_check_relocs need to create relocation for %s\n",
2069 (h && h->root.root.string) ? h->root.root.string : "<unknown>");
2070 #endif
2071 if (sreloc == NULL)
2072 {
2073 const char *name;
2074
2075 name = (bfd_elf_string_from_elf_section
2076 (abfd,
2077 elf_elfheader (abfd)->e_shstrndx,
2078 elf_section_data (sec)->rel_hdr.sh_name));
2079 if (name == NULL)
2080 {
2081 ret = false;
2082 break;
2083 }
2084
2085 BFD_ASSERT (strncmp (name, ".rela", 5) == 0
2086 && strcmp (bfd_get_section_name (abfd, sec),
2087 name + 5) == 0);
2088
2089 sreloc = bfd_get_section_by_name (dynobj, name);
2090 if (sreloc == NULL)
2091 {
2092 sreloc = bfd_make_section (dynobj, name);
2093 if (sreloc == NULL
2094 || ! bfd_set_section_flags (dynobj, sreloc,
2095 (SEC_ALLOC
2096 | SEC_LOAD
2097 | SEC_HAS_CONTENTS
2098 | SEC_IN_MEMORY
2099 | SEC_LINKER_CREATED
2100 | SEC_READONLY))
2101 || ! bfd_set_section_alignment (dynobj, sreloc, 2))
2102 {
2103 ret = false;
2104 break;
2105 }
2106 }
2107 }
2108
2109 sreloc->_raw_size += sizeof (Elf32_External_Rela);
2110 }
2111
2112 break;
2113 }
2114 }
2115
2116 return ret;
2117 }
2118
2119 \f
2120 /* Hook called by the linker routine which adds symbols from an object
2121 file. We use it to put .comm items in .sbss, and not .bss. */
2122
2123 /*ARGSUSED*/
2124 static boolean
2125 ppc_elf_add_symbol_hook (abfd, info, sym, namep, flagsp, secp, valp)
2126 bfd *abfd;
2127 struct bfd_link_info *info;
2128 const Elf_Internal_Sym *sym;
2129 const char **namep;
2130 flagword *flagsp;
2131 asection **secp;
2132 bfd_vma *valp;
2133 {
2134 if (sym->st_shndx == SHN_COMMON && !info->relocateable && sym->st_size <= bfd_get_gp_size (abfd))
2135 {
2136 /* Common symbols less than or equal to -G nn bytes are automatically
2137 put into .sdata. */
2138 elf_linker_section_t *sdata = ppc_elf_create_linker_section (abfd, info, LINKER_SECTION_SDATA);
2139 if (!sdata->bss_section)
2140 {
2141 /* We don't go through bfd_make_section, because we don't
2142 want to attach this common section to DYNOBJ. The linker
2143 will move the symbols to the appropriate output section
2144 when it defines common symbols. */
2145 sdata->bss_section = ((asection *)
2146 bfd_zalloc (abfd, sizeof (asection)));
2147 if (sdata->bss_section == NULL)
2148 return false;
2149 sdata->bss_section->name = sdata->bss_name;
2150 sdata->bss_section->flags = SEC_IS_COMMON;
2151 sdata->bss_section->output_section = sdata->bss_section;
2152 sdata->bss_section->symbol =
2153 (asymbol *) bfd_zalloc (abfd, sizeof (asymbol));
2154 sdata->bss_section->symbol_ptr_ptr =
2155 (asymbol **) bfd_zalloc (abfd, sizeof (asymbol *));
2156 if (sdata->bss_section->symbol == NULL
2157 || sdata->bss_section->symbol_ptr_ptr == NULL)
2158 return false;
2159 sdata->bss_section->symbol->name = sdata->bss_name;
2160 sdata->bss_section->symbol->flags = BSF_SECTION_SYM;
2161 sdata->bss_section->symbol->section = sdata->bss_section;
2162 *sdata->bss_section->symbol_ptr_ptr = sdata->bss_section->symbol;
2163 }
2164
2165 *secp = sdata->bss_section;
2166 *valp = sym->st_size;
2167 }
2168
2169 return true;
2170 }
2171
2172 \f
2173 /* Finish up dynamic symbol handling. We set the contents of various
2174 dynamic sections here. */
2175
2176 static boolean
2177 ppc_elf_finish_dynamic_symbol (output_bfd, info, h, sym)
2178 bfd *output_bfd;
2179 struct bfd_link_info *info;
2180 struct elf_link_hash_entry *h;
2181 Elf_Internal_Sym *sym;
2182 {
2183 bfd *dynobj;
2184
2185 #ifdef DEBUG
2186 fprintf (stderr, "ppc_elf_finish_dynamic_symbol called for %s", h->root.root.string);
2187 #endif
2188
2189 dynobj = elf_hash_table (info)->dynobj;
2190 BFD_ASSERT (dynobj != NULL);
2191
2192 if (h->plt_offset != (bfd_vma) -1)
2193 {
2194 asection *splt;
2195 asection *srela;
2196 Elf_Internal_Rela rela;
2197
2198 #ifdef DEBUG
2199 fprintf (stderr, ", plt_offset = %d", h->plt_offset);
2200 #endif
2201
2202 /* This symbol has an entry in the procedure linkage table. Set
2203 it up. */
2204
2205 BFD_ASSERT (h->dynindx != -1);
2206
2207 splt = bfd_get_section_by_name (dynobj, ".plt");
2208 srela = bfd_get_section_by_name (dynobj, ".rela.plt");
2209 BFD_ASSERT (splt != NULL && srela != NULL);
2210
2211 /* We don't need to fill in the .plt. The solaris dynamic linker will
2212 fill it in. */
2213
2214 /* Fill in the entry in the .rela.plt section. */
2215 rela.r_offset = (splt->output_section->vma
2216 + splt->output_offset
2217 + h->plt_offset);
2218 rela.r_info = ELF32_R_INFO (h->dynindx, R_PPC_JMP_SLOT);
2219 rela.r_addend = 0;
2220 bfd_elf32_swap_reloca_out (output_bfd, &rela,
2221 ((Elf32_External_Rela *) srela->contents
2222 + ((h->plt_offset - PLT_INITIAL_ENTRY_SIZE) / 8)));
2223
2224 if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
2225 {
2226 /* Mark the symbol as undefined, rather than as defined in
2227 the .plt section. Leave the value alone. */
2228 sym->st_shndx = SHN_UNDEF;
2229 }
2230 }
2231
2232 if ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_COPY) != 0)
2233 {
2234 asection *s;
2235 Elf_Internal_Rela rela;
2236
2237 /* This symbols needs a copy reloc. Set it up. */
2238
2239 #ifdef DEBUG
2240 fprintf (stderr, ", copy");
2241 #endif
2242
2243 BFD_ASSERT (h->dynindx != -1);
2244
2245 s = bfd_get_section_by_name (h->root.u.def.section->owner,
2246 ".rela.bss");
2247 BFD_ASSERT (s != NULL);
2248
2249 rela.r_offset = (h->root.u.def.value
2250 + h->root.u.def.section->output_section->vma
2251 + h->root.u.def.section->output_offset);
2252 rela.r_info = ELF32_R_INFO (h->dynindx, R_PPC_COPY);
2253 rela.r_addend = 0;
2254 bfd_elf32_swap_reloca_out (output_bfd, &rela,
2255 ((Elf32_External_Rela *) s->contents
2256 + s->reloc_count));
2257 ++s->reloc_count;
2258 }
2259
2260 #ifdef DEBUG
2261 fprintf (stderr, "\n");
2262 #endif
2263
2264 /* Mark some specially defined symbols as absolute. */
2265 if (strcmp (h->root.root.string, "_DYNAMIC") == 0
2266 || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0
2267 || strcmp (h->root.root.string, "_PROCEDURE_LINKAGE_TABLE_") == 0)
2268 sym->st_shndx = SHN_ABS;
2269
2270 return true;
2271 }
2272
2273 \f
2274 /* Finish up the dynamic sections. */
2275
2276 static boolean
2277 ppc_elf_finish_dynamic_sections (output_bfd, info)
2278 bfd *output_bfd;
2279 struct bfd_link_info *info;
2280 {
2281 asection *sdyn;
2282 bfd *dynobj = elf_hash_table (info)->dynobj;
2283 elf_linker_section_t *got = elf_linker_section (dynobj, LINKER_SECTION_GOT);
2284
2285 #ifdef DEBUG
2286 fprintf (stderr, "ppc_elf_finish_dynamic_sections called\n");
2287 #endif
2288
2289 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
2290
2291 if (elf_hash_table (info)->dynamic_sections_created)
2292 {
2293 asection *splt;
2294 Elf32_External_Dyn *dyncon, *dynconend;
2295
2296 splt = bfd_get_section_by_name (dynobj, ".plt");
2297 BFD_ASSERT (splt != NULL && sdyn != NULL);
2298
2299 dyncon = (Elf32_External_Dyn *) sdyn->contents;
2300 dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->_raw_size);
2301 for (; dyncon < dynconend; dyncon++)
2302 {
2303 Elf_Internal_Dyn dyn;
2304 const char *name;
2305 boolean size;
2306
2307 bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
2308
2309 switch (dyn.d_tag)
2310 {
2311 case DT_PLTGOT: name = ".plt"; size = false; break;
2312 case DT_PLTRELSZ: name = ".rela.plt"; size = true; break;
2313 case DT_JMPREL: name = ".rela.plt"; size = false; break;
2314 default: name = NULL; size = false; break;
2315 }
2316
2317 if (name != NULL)
2318 {
2319 asection *s;
2320
2321 s = bfd_get_section_by_name (output_bfd, name);
2322 if (s == NULL)
2323 dyn.d_un.d_val = 0;
2324 else
2325 {
2326 if (! size)
2327 dyn.d_un.d_ptr = s->vma;
2328 else
2329 {
2330 if (s->_cooked_size != 0)
2331 dyn.d_un.d_val = s->_cooked_size;
2332 else
2333 dyn.d_un.d_val = s->_raw_size;
2334 }
2335 }
2336 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
2337 }
2338 }
2339 }
2340
2341 /* Add a blrl instruction at _GLOBAL_OFFSET_TABLE_-4 so that a function can
2342 easily find the address of the _GLOBAL_OFFSET_TABLE_. */
2343 if (got)
2344 {
2345 unsigned char *contents = got->section->contents + got->hole_offset;
2346 bfd_put_32 (output_bfd, 0x4e800021 /* blrl */, contents);
2347
2348 if (sdyn == NULL)
2349 bfd_put_32 (output_bfd, (bfd_vma) 0, contents+4);
2350 else
2351 bfd_put_32 (output_bfd,
2352 sdyn->output_section->vma + sdyn->output_offset,
2353 contents+4);
2354
2355 elf_section_data (got->section->output_section)->this_hdr.sh_entsize = 4;
2356 }
2357
2358 if (info->shared)
2359 {
2360 asection *sdynsym;
2361 asection *s;
2362 Elf_Internal_Sym sym;
2363
2364 /* Set up the section symbols for the output sections. */
2365
2366 sdynsym = bfd_get_section_by_name (dynobj, ".dynsym");
2367 BFD_ASSERT (sdynsym != NULL);
2368
2369 sym.st_size = 0;
2370 sym.st_name = 0;
2371 sym.st_info = ELF_ST_INFO (STB_LOCAL, STT_SECTION);
2372 sym.st_other = 0;
2373
2374 for (s = output_bfd->sections; s != NULL; s = s->next)
2375 {
2376 int indx;
2377
2378 sym.st_value = s->vma;
2379
2380 indx = elf_section_data (s)->this_idx;
2381 BFD_ASSERT (indx > 0);
2382 sym.st_shndx = indx;
2383
2384 bfd_elf32_swap_symbol_out (output_bfd, &sym,
2385 (PTR) (((Elf32_External_Sym *)
2386 sdynsym->contents)
2387 + elf_section_data (s)->dynindx));
2388 }
2389
2390 /* Set the sh_info field of the output .dynsym section to the
2391 index of the first global symbol. */
2392 elf_section_data (sdynsym->output_section)->this_hdr.sh_info =
2393 bfd_count_sections (output_bfd) + 1;
2394 }
2395
2396 return true;
2397 }
2398
2399 \f
2400 /* The RELOCATE_SECTION function is called by the ELF backend linker
2401 to handle the relocations for a section.
2402
2403 The relocs are always passed as Rela structures; if the section
2404 actually uses Rel structures, the r_addend field will always be
2405 zero.
2406
2407 This function is responsible for adjust the section contents as
2408 necessary, and (if using Rela relocs and generating a
2409 relocateable output file) adjusting the reloc addend as
2410 necessary.
2411
2412 This function does not have to worry about setting the reloc
2413 address or the reloc symbol index.
2414
2415 LOCAL_SYMS is a pointer to the swapped in local symbols.
2416
2417 LOCAL_SECTIONS is an array giving the section in the input file
2418 corresponding to the st_shndx field of each local symbol.
2419
2420 The global hash table entry for the global symbols can be found
2421 via elf_sym_hashes (input_bfd).
2422
2423 When generating relocateable output, this function must handle
2424 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
2425 going to be the section symbol corresponding to the output
2426 section, which means that the addend must be adjusted
2427 accordingly. */
2428
2429 static boolean
2430 ppc_elf_relocate_section (output_bfd, info, input_bfd, input_section,
2431 contents, relocs, local_syms, local_sections)
2432 bfd *output_bfd;
2433 struct bfd_link_info *info;
2434 bfd *input_bfd;
2435 asection *input_section;
2436 bfd_byte *contents;
2437 Elf_Internal_Rela *relocs;
2438 Elf_Internal_Sym *local_syms;
2439 asection **local_sections;
2440 {
2441 Elf_Internal_Shdr *symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
2442 struct elf_link_hash_entry **sym_hashes = elf_sym_hashes (input_bfd);
2443 bfd *dynobj = elf_hash_table (info)->dynobj;
2444 elf_linker_section_t *got = (dynobj) ? elf_linker_section (dynobj, LINKER_SECTION_GOT) : NULL;
2445 elf_linker_section_t *sdata = (dynobj) ? elf_linker_section (dynobj, LINKER_SECTION_SDATA) : NULL;
2446 elf_linker_section_t *sdata2 = (dynobj) ? elf_linker_section (dynobj, LINKER_SECTION_SDATA2) : NULL;
2447 Elf_Internal_Rela *rel = relocs;
2448 Elf_Internal_Rela *relend = relocs + input_section->reloc_count;
2449 asection *sreloc = NULL;
2450 boolean ret = true;
2451 long insn;
2452
2453 #ifdef DEBUG
2454 fprintf (stderr, "ppc_elf_relocate_section called for %s section %s, %ld relocations%s\n",
2455 bfd_get_filename (input_bfd),
2456 bfd_section_name(input_bfd, input_section),
2457 (long)input_section->reloc_count,
2458 (info->relocateable) ? " (relocatable)" : "");
2459 #endif
2460
2461 if (!ppc_elf_howto_table[ R_PPC_ADDR32 ]) /* Initialize howto table if needed */
2462 ppc_elf_howto_init ();
2463
2464 for (; rel < relend; rel++)
2465 {
2466 enum ppc_reloc_type r_type = (enum ppc_reloc_type)ELF32_R_TYPE (rel->r_info);
2467 bfd_vma offset = rel->r_offset;
2468 bfd_vma addend = rel->r_addend;
2469 bfd_reloc_status_type r = bfd_reloc_other;
2470 Elf_Internal_Sym *sym = (Elf_Internal_Sym *)0;
2471 asection *sec = (asection *)0;
2472 struct elf_link_hash_entry *h = (struct elf_link_hash_entry *)0;
2473 const char *sym_name = (const char *)0;
2474 reloc_howto_type *howto;
2475 unsigned long r_symndx;
2476 bfd_vma relocation;
2477
2478 /* Unknown relocation handling */
2479 if ((unsigned)r_type >= (unsigned)R_PPC_max || !ppc_elf_howto_table[(int)r_type])
2480 {
2481 (*_bfd_error_handler) ("%s: unknown relocation type %d",
2482 bfd_get_filename (input_bfd),
2483 (int)r_type);
2484
2485 bfd_set_error (bfd_error_bad_value);
2486 ret = false;
2487 continue;
2488 }
2489
2490 howto = ppc_elf_howto_table[(int)r_type];
2491 r_symndx = ELF32_R_SYM (rel->r_info);
2492
2493 if (info->relocateable)
2494 {
2495 /* This is a relocateable link. We don't have to change
2496 anything, unless the reloc is against a section symbol,
2497 in which case we have to adjust according to where the
2498 section symbol winds up in the output section. */
2499 if (r_symndx < symtab_hdr->sh_info)
2500 {
2501 sym = local_syms + r_symndx;
2502 if ((unsigned)ELF_ST_TYPE (sym->st_info) == STT_SECTION)
2503 {
2504 sec = local_sections[r_symndx];
2505 addend = rel->r_addend += sec->output_offset + sym->st_value;
2506 }
2507 }
2508
2509 #ifdef DEBUG
2510 fprintf (stderr, "\ttype = %s (%d), symbol index = %ld, offset = %ld, addend = %ld\n",
2511 howto->name,
2512 (int)r_type,
2513 r_symndx,
2514 (long)offset,
2515 (long)addend);
2516 #endif
2517 continue;
2518 }
2519
2520 /* This is a final link. */
2521 if (r_symndx < symtab_hdr->sh_info)
2522 {
2523 sym = local_syms + r_symndx;
2524 sec = local_sections[r_symndx];
2525 sym_name = "<local symbol>";
2526
2527 relocation = (sec->output_section->vma
2528 + sec->output_offset
2529 + sym->st_value);
2530 }
2531 else
2532 {
2533 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
2534 while (h->root.type == bfd_link_hash_indirect
2535 || h->root.type == bfd_link_hash_warning)
2536 h = (struct elf_link_hash_entry *) h->root.u.i.link;
2537 sym_name = h->root.root.string;
2538 if (h->root.type == bfd_link_hash_defined
2539 || h->root.type == bfd_link_hash_defweak)
2540 {
2541 sec = h->root.u.def.section;
2542 if ((r_type == R_PPC_PLT32
2543 && h->plt_offset != (bfd_vma) -1)
2544 || ((r_type == R_PPC_GOT16
2545 || r_type == R_PPC_GOT16_LO
2546 || r_type == R_PPC_GOT16_HI
2547 || r_type == R_PPC_GOT16_HA)
2548 && elf_hash_table (info)->dynamic_sections_created
2549 && (! info->shared
2550 || ! info->symbolic
2551 || (h->elf_link_hash_flags
2552 & ELF_LINK_HASH_DEF_REGULAR) == 0))
2553 || (info->shared
2554 && (! info->symbolic
2555 || (h->elf_link_hash_flags
2556 & ELF_LINK_HASH_DEF_REGULAR) == 0)
2557 && (input_section->flags & SEC_ALLOC) != 0
2558 && (r_type == R_PPC_ADDR32
2559 || r_type == R_PPC_ADDR24
2560 || r_type == R_PPC_ADDR16
2561 || r_type == R_PPC_ADDR16_LO
2562 || r_type == R_PPC_ADDR16_HI
2563 || r_type == R_PPC_ADDR16_HA
2564 || r_type == R_PPC_ADDR14
2565 || r_type == R_PPC_ADDR14_BRTAKEN
2566 || r_type == R_PPC_ADDR14_BRNTAKEN
2567 || r_type == R_PPC_PLTREL24
2568 || r_type == R_PPC_COPY
2569 || r_type == R_PPC_GLOB_DAT
2570 || r_type == R_PPC_JMP_SLOT
2571 || r_type == R_PPC_UADDR32
2572 || r_type == R_PPC_UADDR16
2573 || r_type == R_PPC_REL32
2574 || r_type == R_PPC_SDAREL16
2575 || r_type == R_PPC_EMB_NADDR32
2576 || r_type == R_PPC_EMB_NADDR16
2577 || r_type == R_PPC_EMB_NADDR16_LO
2578 || r_type == R_PPC_EMB_NADDR16_HI
2579 || r_type == R_PPC_EMB_NADDR16_HA
2580 || r_type == R_PPC_EMB_SDAI16
2581 || r_type == R_PPC_EMB_SDA2I16
2582 || r_type == R_PPC_EMB_SDA2REL
2583 || r_type == R_PPC_EMB_SDA21
2584 || r_type == R_PPC_EMB_MRKREF
2585 || r_type == R_PPC_EMB_BIT_FLD
2586 || r_type == R_PPC_EMB_RELSDA
2587 || ((r_type == R_PPC_REL24
2588 || r_type == R_PPC_REL14
2589 || r_type == R_PPC_REL14_BRTAKEN
2590 || r_type == R_PPC_REL14_BRNTAKEN
2591 || r_type == R_PPC_RELATIVE)
2592 && strcmp (h->root.root.string,
2593 "_GLOBAL_OFFSET_TABLE_") != 0))))
2594 {
2595 /* In these cases, we don't need the relocation
2596 value. We check specially because in some
2597 obscure cases sec->output_section will be NULL. */
2598 relocation = 0;
2599 }
2600 else
2601 relocation = (h->root.u.def.value
2602 + sec->output_section->vma
2603 + sec->output_offset);
2604 }
2605 else if (h->root.type == bfd_link_hash_undefweak)
2606 relocation = 0;
2607 else if (info->shared)
2608 relocation = 0;
2609 else
2610 {
2611 (*info->callbacks->undefined_symbol)(info,
2612 h->root.root.string,
2613 input_bfd,
2614 input_section,
2615 rel->r_offset);
2616 ret = false;
2617 continue;
2618 }
2619 }
2620
2621 switch ((int)r_type)
2622 {
2623 default:
2624 (*_bfd_error_handler) ("%s: unknown relocation type %d for symbol %s",
2625 bfd_get_filename (input_bfd),
2626 (int)r_type, sym_name);
2627
2628 bfd_set_error (bfd_error_bad_value);
2629 ret = false;
2630 continue;
2631
2632 /* relocations that need no special processing */
2633 case (int)R_PPC_LOCAL24PC:
2634 break;
2635
2636 case (int)R_PPC_REL24:
2637 case (int)R_PPC_REL14:
2638 if (h != NULL
2639 && strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
2640 break;
2641 /* fall through */
2642
2643 /* Relocations that need to be propigated if this is a shared object */
2644 case (int)R_PPC_NONE:
2645 case (int)R_PPC_ADDR32:
2646 case (int)R_PPC_ADDR24:
2647 case (int)R_PPC_ADDR16:
2648 case (int)R_PPC_ADDR16_LO:
2649 case (int)R_PPC_ADDR16_HI:
2650 case (int)R_PPC_ADDR14:
2651 case (int)R_PPC_UADDR32:
2652 case (int)R_PPC_UADDR16:
2653 case (int)R_PPC_REL32:
2654 case (int)R_PPC_PLTREL24:
2655 if (info->shared
2656 && (input_section->flags & SEC_ALLOC) != 0)
2657 {
2658 Elf_Internal_Rela outrel;
2659 boolean skip;
2660
2661 #ifdef DEBUG
2662 fprintf (stderr, "ppc_elf_relocate_section need to create relocation for %s\n",
2663 (h && h->root.root.string) ? h->root.root.string : "<unknown>");
2664 #endif
2665
2666 /* When generating a shared object, these relocations
2667 are copied into the output file to be resolved at run
2668 time. */
2669
2670 if (sreloc == NULL)
2671 {
2672 const char *name;
2673
2674 name = (bfd_elf_string_from_elf_section
2675 (input_bfd,
2676 elf_elfheader (input_bfd)->e_shstrndx,
2677 elf_section_data (input_section)->rel_hdr.sh_name));
2678 if (name == NULL)
2679 return false;
2680
2681 BFD_ASSERT (strncmp (name, ".rela", 5) == 0
2682 && strcmp (bfd_get_section_name (input_bfd,
2683 input_section),
2684 name + 5) == 0);
2685
2686 sreloc = bfd_get_section_by_name (dynobj, name);
2687 BFD_ASSERT (sreloc != NULL);
2688 }
2689
2690 skip = false;
2691
2692 if (elf_section_data (input_section)->stab_info == NULL)
2693 outrel.r_offset = rel->r_offset;
2694 else
2695 {
2696 bfd_vma off;
2697
2698 off = (_bfd_stab_section_offset
2699 (output_bfd, &elf_hash_table (info)->stab_info,
2700 input_section,
2701 &elf_section_data (input_section)->stab_info,
2702 rel->r_offset));
2703 if (off == (bfd_vma) -1)
2704 skip = true;
2705 outrel.r_offset = off;
2706 }
2707
2708 outrel.r_offset += (input_section->output_section->vma
2709 + input_section->output_offset);
2710
2711 if (skip)
2712 memset (&outrel, 0, sizeof outrel);
2713 /* h->dynindx may be -1 if this symbol was marked to
2714 become local. */
2715 else if (h != NULL
2716 && ((! info->symbolic && h->dynindx != -1)
2717 || (h->elf_link_hash_flags
2718 & ELF_LINK_HASH_DEF_REGULAR) == 0))
2719 {
2720 BFD_ASSERT (h->dynindx != -1);
2721 outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
2722 outrel.r_addend = rel->r_addend;
2723 }
2724 else
2725 {
2726 if (r_type == R_PPC_ADDR32)
2727 {
2728 outrel.r_info = ELF32_R_INFO (0, R_PPC_RELATIVE);
2729 outrel.r_addend = relocation + rel->r_addend;
2730 }
2731 else
2732 {
2733 long indx;
2734
2735 if (h == NULL)
2736 sec = local_sections[r_symndx];
2737 else
2738 {
2739 BFD_ASSERT (h->root.type == bfd_link_hash_defined
2740 || (h->root.type
2741 == bfd_link_hash_defweak));
2742 sec = h->root.u.def.section;
2743 }
2744 if (sec != NULL && bfd_is_abs_section (sec))
2745 indx = 0;
2746 else if (sec == NULL || sec->owner == NULL)
2747 {
2748 bfd_set_error (bfd_error_bad_value);
2749 return false;
2750 }
2751 else
2752 {
2753 asection *osec;
2754
2755 osec = sec->output_section;
2756 indx = elf_section_data (osec)->dynindx;
2757 if (indx == 0)
2758 abort ();
2759 }
2760
2761 outrel.r_info = ELF32_R_INFO (indx, r_type);
2762 outrel.r_addend = relocation + rel->r_addend;
2763 }
2764 }
2765
2766 bfd_elf32_swap_reloca_out (output_bfd, &outrel,
2767 (((Elf32_External_Rela *)
2768 sreloc->contents)
2769 + sreloc->reloc_count));
2770 ++sreloc->reloc_count;
2771
2772 /* This reloc will be computed at runtime, so there's no
2773 need to do anything now. */
2774 continue;
2775 }
2776 break;
2777
2778 /* branch taken prediction relocations */
2779 case (int)R_PPC_ADDR14_BRTAKEN:
2780 case (int)R_PPC_REL14_BRTAKEN:
2781 insn = bfd_get_32 (output_bfd, contents + offset);
2782 if ((relocation - offset) & 0x8000)
2783 insn &= ~BRANCH_PREDICT_BIT;
2784 else
2785 insn |= BRANCH_PREDICT_BIT;
2786 bfd_put_32 (output_bfd, insn, contents + offset);
2787 break;
2788
2789 /* branch not taken predicition relocations */
2790 case (int)R_PPC_ADDR14_BRNTAKEN:
2791 case (int)R_PPC_REL14_BRNTAKEN:
2792 insn = bfd_get_32 (output_bfd, contents + offset);
2793 if ((relocation - offset) & 0x8000)
2794 insn |= BRANCH_PREDICT_BIT;
2795 else
2796 insn &= ~BRANCH_PREDICT_BIT;
2797 bfd_put_32 (output_bfd, insn, contents + offset);
2798 break;
2799
2800 /* GOT16 relocations */
2801 case (int)R_PPC_GOT16:
2802 case (int)R_PPC_GOT16_LO:
2803 case (int)R_PPC_GOT16_HI:
2804 case (int)R_PPC_GOT16_HA:
2805 relocation = bfd_elf32_finish_pointer_linker_section (output_bfd, input_bfd, info,
2806 got, h, relocation, rel,
2807 R_PPC_RELATIVE);
2808 break;
2809
2810 /* Indirect .sdata relocation */
2811 case (int)R_PPC_EMB_SDAI16:
2812 BFD_ASSERT (sdata != NULL);
2813 relocation = bfd_elf32_finish_pointer_linker_section (output_bfd, input_bfd, info,
2814 sdata, h, relocation, rel,
2815 R_PPC_RELATIVE);
2816 break;
2817
2818 /* Indirect .sdata2 relocation */
2819 case (int)R_PPC_EMB_SDA2I16:
2820 BFD_ASSERT (sdata2 != NULL);
2821 relocation = bfd_elf32_finish_pointer_linker_section (output_bfd, input_bfd, info,
2822 sdata2, h, relocation, rel,
2823 R_PPC_RELATIVE);
2824 break;
2825
2826 /* Handle the TOC16 reloc. We want to use the offset within the .got
2827 section, not the actual VMA. This is appropriate when generating
2828 an embedded ELF object, for which the .got section acts like the
2829 AIX .toc section. */
2830 case (int)R_PPC_TOC16: /* phony GOT16 relocations */
2831 BFD_ASSERT (sec != (asection *)0);
2832 BFD_ASSERT (bfd_is_und_section (sec)
2833 || strcmp (bfd_get_section_name (abfd, sec), ".got") == 0
2834 || strcmp (bfd_get_section_name (abfd, sec), ".cgot") == 0)
2835
2836 addend -= sec->output_section->vma + sec->output_offset + 0x8000;
2837 break;
2838
2839 /* arithmetic adjust relocations */
2840 case (int)R_PPC_ADDR16_HA:
2841 BFD_ASSERT (sec != (asection *)0);
2842 addend += ((relocation + addend) & 0x8000) << 1;
2843 break;
2844
2845 /* relocate against _SDA_BASE_ */
2846 case (int)R_PPC_SDAREL16:
2847 BFD_ASSERT (sec != (asection *)0);
2848 if (strcmp (bfd_get_section_name (abfd, sec), ".sdata") != 0
2849 && strcmp (bfd_get_section_name (abfd, sec), ".sbss") != 0)
2850 {
2851 (*_bfd_error_handler) ("%s: The target (%s) of a %s relocation is in the wrong section (%s)",
2852 bfd_get_filename (input_bfd),
2853 sym_name,
2854 ppc_elf_howto_table[ (int)r_type ]->name,
2855 bfd_get_section_name (abfd, sec));
2856
2857 bfd_set_error (bfd_error_bad_value);
2858 ret = false;
2859 continue;
2860 }
2861 addend -= (sdata->sym_hash->root.u.def.value
2862 + sdata->sym_hash->root.u.def.section->output_section->vma
2863 + sdata->sym_hash->root.u.def.section->output_offset);
2864 break;
2865
2866
2867 /* relocate against _SDA2_BASE_ */
2868 case (int)R_PPC_EMB_SDA2REL:
2869 BFD_ASSERT (sec != (asection *)0);
2870 if (strcmp (bfd_get_section_name (abfd, sec), ".sdata2") != 0
2871 && strcmp (bfd_get_section_name (abfd, sec), ".sbss2") != 0)
2872 {
2873 (*_bfd_error_handler) ("%s: The target (%s) of a %s relocation is in the wrong section (%s)",
2874 bfd_get_filename (input_bfd),
2875 sym_name,
2876 ppc_elf_howto_table[ (int)r_type ]->name,
2877 bfd_get_section_name (abfd, sec));
2878
2879 bfd_set_error (bfd_error_bad_value);
2880 ret = false;
2881 continue;
2882 }
2883 addend -= (sdata2->sym_hash->root.u.def.value
2884 + sdata2->sym_hash->root.u.def.section->output_section->vma
2885 + sdata2->sym_hash->root.u.def.section->output_offset);
2886 break;
2887
2888
2889 /* relocate against either _SDA_BASE_, _SDA2_BASE_, or 0 */
2890 case (int)R_PPC_EMB_SDA21:
2891 case (int)R_PPC_EMB_RELSDA:
2892 {
2893 const char *name = bfd_get_section_name (abfd, sec);
2894 int reg;
2895
2896 BFD_ASSERT (sec != (asection *)0);
2897 if (strcmp (name, ".sdata") == 0 || strcmp (name, ".sbss") == 0)
2898 {
2899 reg = 13;
2900 addend -= (sdata->sym_hash->root.u.def.value
2901 + sdata->sym_hash->root.u.def.section->output_section->vma
2902 + sdata->sym_hash->root.u.def.section->output_offset);
2903 }
2904
2905 else if (strcmp (name, ".sdata2") == 0 || strcmp (name, ".sbss2") == 0)
2906 {
2907 reg = 2;
2908 addend -= (sdata2->sym_hash->root.u.def.value
2909 + sdata2->sym_hash->root.u.def.section->output_section->vma
2910 + sdata2->sym_hash->root.u.def.section->output_offset);
2911 }
2912
2913 else if (strcmp (name, ".PPC.EMB.sdata0") == 0 || strcmp (name, ".PPC.EMB.sbss0") == 0)
2914 {
2915 reg = 0;
2916 }
2917
2918 else
2919 {
2920 (*_bfd_error_handler) ("%s: The target (%s) of a %s relocation is in the wrong section (%s)",
2921 bfd_get_filename (input_bfd),
2922 sym_name,
2923 ppc_elf_howto_table[ (int)r_type ]->name,
2924 bfd_get_section_name (abfd, sec));
2925
2926 bfd_set_error (bfd_error_bad_value);
2927 ret = false;
2928 continue;
2929 }
2930
2931 if (r_type == R_PPC_EMB_SDA21)
2932 { /* fill in register field */
2933 insn = bfd_get_32 (output_bfd, contents + offset);
2934 insn = (insn & ~RA_REGISTER_MASK) | (reg << RA_REGISTER_SHIFT);
2935 bfd_put_32 (output_bfd, insn, contents + offset);
2936 }
2937 }
2938 break;
2939
2940 /* Relocate against the beginning of the section */
2941 case (int)R_PPC_SECTOFF:
2942 case (int)R_PPC_SECTOFF_LO:
2943 case (int)R_PPC_SECTOFF_HI:
2944 BFD_ASSERT (sec != (asection *)0);
2945 addend -= sec->output_section->vma;
2946 break;
2947
2948 case (int)R_PPC_SECTOFF_HA:
2949 BFD_ASSERT (sec != (asection *)0);
2950 addend -= sec->output_section->vma;
2951 addend += ((relocation + addend) & 0x8000) << 1;
2952 break;
2953
2954 /* Negative relocations */
2955 case (int)R_PPC_EMB_NADDR32:
2956 case (int)R_PPC_EMB_NADDR16:
2957 case (int)R_PPC_EMB_NADDR16_LO:
2958 case (int)R_PPC_EMB_NADDR16_HI:
2959 addend -= 2*relocation;
2960 break;
2961
2962 case (int)R_PPC_EMB_NADDR16_HA:
2963 addend -= 2*relocation;
2964 addend += ((relocation + addend) & 0x8000) << 1;
2965 break;
2966
2967 /* NOP relocation that prevents garbage collecting linkers from omitting a
2968 reference. */
2969 case (int)R_PPC_EMB_MRKREF:
2970 continue;
2971
2972 case (int)R_PPC_COPY:
2973 case (int)R_PPC_GLOB_DAT:
2974 case (int)R_PPC_JMP_SLOT:
2975 case (int)R_PPC_RELATIVE:
2976 case (int)R_PPC_PLT32:
2977 case (int)R_PPC_PLTREL32:
2978 case (int)R_PPC_PLT16_LO:
2979 case (int)R_PPC_PLT16_HI:
2980 case (int)R_PPC_PLT16_HA:
2981 case (int)R_PPC_EMB_RELSEC16:
2982 case (int)R_PPC_EMB_RELST_LO:
2983 case (int)R_PPC_EMB_RELST_HI:
2984 case (int)R_PPC_EMB_RELST_HA:
2985 case (int)R_PPC_EMB_BIT_FLD:
2986 (*_bfd_error_handler) ("%s: Relocation %s is not yet supported for symbol %s.",
2987 bfd_get_filename (input_bfd),
2988 ppc_elf_howto_table[ (int)r_type ]->name,
2989 sym_name);
2990
2991 bfd_set_error (bfd_error_invalid_operation);
2992 ret = false;
2993 continue;
2994 }
2995
2996
2997 #ifdef DEBUG
2998 fprintf (stderr, "\ttype = %s (%d), name = %s, symbol index = %ld, offset = %ld, addend = %ld\n",
2999 howto->name,
3000 (int)r_type,
3001 sym_name,
3002 r_symndx,
3003 (long)offset,
3004 (long)addend);
3005 #endif
3006
3007 r = _bfd_final_link_relocate (howto,
3008 input_bfd,
3009 input_section,
3010 contents,
3011 offset,
3012 relocation,
3013 addend);
3014
3015 if (r != bfd_reloc_ok)
3016 {
3017 ret = false;
3018 switch (r)
3019 {
3020 default:
3021 break;
3022
3023 case bfd_reloc_overflow:
3024 {
3025 const char *name;
3026
3027 if (h != NULL)
3028 name = h->root.root.string;
3029 else
3030 {
3031 name = bfd_elf_string_from_elf_section (input_bfd,
3032 symtab_hdr->sh_link,
3033 sym->st_name);
3034 if (name == NULL)
3035 break;
3036
3037 if (*name == '\0')
3038 name = bfd_section_name (input_bfd, sec);
3039 }
3040
3041 (*info->callbacks->reloc_overflow)(info,
3042 name,
3043 howto->name,
3044 (bfd_vma) 0,
3045 input_bfd,
3046 input_section,
3047 offset);
3048 }
3049 break;
3050
3051 }
3052 }
3053 }
3054
3055
3056 #ifdef DEBUG
3057 fprintf (stderr, "\n");
3058 #endif
3059
3060 return ret;
3061 }
3062
3063 \f
3064 #define TARGET_LITTLE_SYM bfd_elf32_powerpcle_vec
3065 #define TARGET_LITTLE_NAME "elf32-powerpcle"
3066 #define TARGET_BIG_SYM bfd_elf32_powerpc_vec
3067 #define TARGET_BIG_NAME "elf32-powerpc"
3068 #define ELF_ARCH bfd_arch_powerpc
3069 #define ELF_MACHINE_CODE EM_PPC
3070 #define ELF_MAXPAGESIZE 0x10000
3071 #define elf_info_to_howto ppc_elf_info_to_howto
3072
3073 #ifdef EM_CYGNUS_POWERPC
3074 #define ELF_MACHINE_ALT1 EM_CYGNUS_POWERPC
3075 #endif
3076
3077 #ifdef EM_PPC_OLD
3078 #define ELF_MACHINE_ALT2 EM_PPC_OLD
3079 #endif
3080
3081 #define bfd_elf32_bfd_copy_private_bfd_data ppc_elf_copy_private_bfd_data
3082 #define bfd_elf32_bfd_merge_private_bfd_data ppc_elf_merge_private_bfd_data
3083 #define bfd_elf32_bfd_set_private_flags ppc_elf_set_private_flags
3084 #define bfd_elf32_bfd_reloc_type_lookup ppc_elf_reloc_type_lookup
3085 #define elf_backend_section_from_shdr ppc_elf_section_from_shdr
3086 #define elf_backend_relocate_section ppc_elf_relocate_section
3087 #define elf_backend_create_dynamic_sections _bfd_elf_create_dynamic_sections
3088 #define elf_backend_check_relocs ppc_elf_check_relocs
3089 #define elf_backend_adjust_dynamic_symbol ppc_elf_adjust_dynamic_symbol
3090 #define elf_backend_add_symbol_hook ppc_elf_add_symbol_hook
3091 #define elf_backend_size_dynamic_sections ppc_elf_size_dynamic_sections
3092 #define elf_backend_finish_dynamic_symbol ppc_elf_finish_dynamic_symbol
3093 #define elf_backend_finish_dynamic_sections ppc_elf_finish_dynamic_sections
3094 #define elf_backend_fake_sections ppc_elf_fake_sections
3095 #define elf_backend_additional_program_headers ppc_elf_additional_program_headers
3096 #define elf_backend_modify_segment_map ppc_elf_modify_segment_map
3097
3098 #include "elf32-target.h"
This page took 0.116886 seconds and 4 git commands to generate.