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