* Makefile.in (TE_OBJS): Add empty definition.
[deliverable/binutils-gdb.git] / bfd / elf32-ppc.c
CommitLineData
bcbe2c71
MM
1/* PowerPC-specific support for 32-bit ELF
2 Copyright 1994, 1995 Free Software Foundation, Inc.
3 Written by Ian Lance Taylor, Cygnus Support.
4
5This file is part of BFD, the Binary File Descriptor library.
6
7This program is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2 of the License, or
10(at your option) any later version.
11
12This program is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with this program; if not, write to the Free Software
19Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, 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"
ede4eed4 28#include "bfdlink.h"
bcbe2c71
MM
29#include "libbfd.h"
30#include "libelf.h"
ede4eed4 31#include "elf/ppc.h"
bcbe2c71
MM
32
33static bfd_reloc_status_type ppc_elf_unsupported_reloc
34 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
ede4eed4
KR
35static bfd_reloc_status_type ppc_elf_std_reloc
36 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
37
38static bfd_vma ppc_elf_addr16_ha_inner PARAMS ((asection *, bfd_vma, bfd_vma));
bcbe2c71
MM
39static bfd_reloc_status_type ppc_elf_addr16_ha_reloc
40 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
ede4eed4 41static bfd_vma ppc_elf_got16_inner PARAMS ((asection *sec));
bcbe2c71
MM
42static bfd_reloc_status_type ppc_elf_got16_reloc
43 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
ede4eed4 44static reloc_howto_type *ppc_elf_reloc_type_lookup
bcbe2c71 45 PARAMS ((bfd *abfd, bfd_reloc_code_real_type code));
ede4eed4 46static void ppc_elf_info_to_howto
bcbe2c71 47 PARAMS ((bfd *abfd, arelent *cache_ptr, Elf32_Internal_Rela *dst));
ede4eed4
KR
48static void ppc_elf_howto_init PARAMS ((void));
49static boolean ppc_elf_set_private_flags PARAMS ((bfd *, flagword));
50static boolean ppc_elf_copy_private_bfd_data PARAMS ((bfd *, bfd *));
51static boolean ppc_elf_merge_private_bfd_data PARAMS ((bfd *, bfd *));
52
53static boolean ppc_elf_relocate_section PARAMS ((bfd *,
54 struct bfd_link_info *info,
55 bfd *,
56 asection *,
57 bfd_byte *,
58 Elf_Internal_Rela *relocs,
59 Elf_Internal_Sym *local_syms,
60 asection **));
bcbe2c71
MM
61
62#define USE_RELA
63
64enum reloc_type
65{
66 R_PPC_NONE = 0, /* 0 */
67 R_PPC_ADDR32, /* 1 */
68 R_PPC_ADDR24, /* 2 */
69 R_PPC_ADDR16, /* 3 */
70 R_PPC_ADDR16_LO, /* 4 */
71 R_PPC_ADDR16_HI, /* 5 */
72 R_PPC_ADDR16_HA, /* 6 */
73 R_PPC_ADDR14, /* 7 */
74 R_PPC_ADDR14_BRTAKEN, /* 8 */
75 R_PPC_ADDR14_BRNTAKEN, /* 9 */
76 R_PPC_REL24, /* 10 */
77 R_PPC_REL14, /* 11 */
78 R_PPC_REL14_BRTAKEN, /* 12 */
79 R_PPC_REL14_BRNTAKEN, /* 13 */
80 R_PPC_GOT16, /* 14 */
81 R_PPC_GOT16_LO, /* 15 */
82 R_PPC_GOT16_HI, /* 16 */
83 R_PPC_GOT16_HA, /* 17 */
84 R_PPC_PLT24, /* 18 */
85 R_PPC_COPY, /* 19 */
86 R_PPC_GLOB_DAT, /* 20 -- not in final System V spec */
87 R_PPC_JMP_SLOT, /* 21 */
88 R_PPC_RELATIVE, /* 22 */
89 R_PPC_LOCAL24PC, /* 23 */
90 R_PPC_UADDR32, /* 24 */
91 R_PPC_UADDR16, /* 25 */
92 R_PPC_REL32, /* 26 */
93 R_PPC_PLT32, /* 27 */
94 R_PPC_PLTREL32, /* 28 */
95 R_PPC_PLT16_LO, /* 29 */
96 R_PPC_PLT16_HI, /* 30 */
97 R_PPC_PLT16_HA, /* 31 */
98 R_PPC_SDAREL, /* 32 */
99
100 /* Relocations added by Sun. */
101 R_PPC_SECTOFF, /* 33 */
102 R_PPC_SECTOFF_LO, /* 34 */
103 R_PPC_SECTOFF_HI, /* 35 */
104 R_PPC_SECTOFF_HA, /* 36 */
105
106 /* The remaining relocs are from the Embedded ELF ABI, and are not
107 in the SVR4 ELF ABI. */
108 R_PPC_EMB_NADDR32 = 101, /* 101 */
109 R_PPC_EMB_NADDR16, /* 102 */
110 R_PPC_EMB_NADDR16_LO, /* 103 */
111 R_PPC_EMB_NADDR16_HI, /* 104 */
112 R_PPC_EMB_NADDR16_HA, /* 105 */
113 R_PPC_EMB_SDAI16, /* 106 */
114 R_PPC_EMB_SDA2I16, /* 107 */
115 R_PPC_EMB_SDA2REL, /* 108 */
116 R_PPC_EMB_SDA21, /* 109 */
117 R_PPC_EMB_MRKREF, /* 110 */
118 R_PPC_EMB_RELSEC16, /* 111 */
119 R_PPC_EMB_RELST_LO, /* 112 */
120 R_PPC_EMB_RELST_HI, /* 113 */
121 R_PPC_EMB_RELST_HA, /* 114 */
122 R_PPC_EMB_BIT_FLD, /* 115 */
123 R_PPC_EMB_RELSDA, /* 116 */
124 R_PPC_max
125};
126
ede4eed4
KR
127\f
128static reloc_howto_type *ppc_elf_howto_table[ (int)R_PPC_max ];
129
130static reloc_howto_type ppc_elf_howto_raw[] =
bcbe2c71
MM
131{
132 /* This reloc does nothing. */
133 HOWTO (R_PPC_NONE, /* type */
134 0, /* rightshift */
135 2, /* size (0 = byte, 1 = short, 2 = long) */
136 32, /* bitsize */
137 false, /* pc_relative */
138 0, /* bitpos */
139 complain_overflow_bitfield, /* complain_on_overflow */
ede4eed4 140 ppc_elf_std_reloc, /* special_function */
bcbe2c71
MM
141 "R_PPC_NONE", /* name */
142 false, /* partial_inplace */
143 0, /* src_mask */
144 0, /* dst_mask */
145 false), /* pcrel_offset */
146
147 /* A standard 32 bit relocation. */
148 HOWTO (R_PPC_ADDR32, /* type */
149 0, /* rightshift */
150 2, /* size (0 = byte, 1 = short, 2 = long) */
151 32, /* bitsize */
152 false, /* pc_relative */
153 0, /* bitpos */
154 complain_overflow_bitfield, /* complain_on_overflow */
ede4eed4 155 ppc_elf_std_reloc, /* special_function */
bcbe2c71
MM
156 "R_PPC_ADDR32", /* name */
157 false, /* partial_inplace */
158 0, /* src_mask */
159 0xffffffff, /* dst_mask */
160 false), /* pcrel_offset */
161
162 /* An absolute 26 bit branch; the lower two bits must be zero.
163 FIXME: we don't check that, we just clear them. */
164 HOWTO (R_PPC_ADDR24, /* type */
165 0, /* rightshift */
166 2, /* size (0 = byte, 1 = short, 2 = long) */
167 26, /* bitsize */
168 false, /* pc_relative */
169 0, /* bitpos */
170 complain_overflow_bitfield, /* complain_on_overflow */
ede4eed4 171 ppc_elf_std_reloc, /* special_function */
bcbe2c71
MM
172 "R_PPC_ADDR24", /* name */
173 false, /* partial_inplace */
174 0, /* src_mask */
175 0x3fffffc, /* dst_mask */
176 false), /* pcrel_offset */
177
178 /* A standard 16 bit relocation. */
179 HOWTO (R_PPC_ADDR16, /* type */
180 0, /* rightshift */
181 1, /* size (0 = byte, 1 = short, 2 = long) */
182 16, /* bitsize */
183 false, /* pc_relative */
184 0, /* bitpos */
185 complain_overflow_bitfield, /* complain_on_overflow */
ede4eed4 186 ppc_elf_std_reloc, /* special_function */
bcbe2c71
MM
187 "R_PPC_ADDR16", /* name */
188 false, /* partial_inplace */
189 0, /* src_mask */
190 0xffff, /* dst_mask */
191 false), /* pcrel_offset */
192
193 /* A 16 bit relocation without overflow. */
194 HOWTO (R_PPC_ADDR16_LO, /* type */
195 0, /* rightshift */
196 1, /* size (0 = byte, 1 = short, 2 = long) */
197 16, /* bitsize */
198 false, /* pc_relative */
199 0, /* bitpos */
200 complain_overflow_dont,/* complain_on_overflow */
ede4eed4 201 ppc_elf_std_reloc, /* special_function */
bcbe2c71
MM
202 "R_PPC_ADDR16_LO", /* name */
203 false, /* partial_inplace */
204 0, /* src_mask */
205 0xffff, /* dst_mask */
206 false), /* pcrel_offset */
207
208 /* The high order 16 bits of an address. */
209 HOWTO (R_PPC_ADDR16_HI, /* type */
210 16, /* rightshift */
211 1, /* size (0 = byte, 1 = short, 2 = long) */
212 16, /* bitsize */
213 false, /* pc_relative */
214 0, /* bitpos */
215 complain_overflow_dont, /* complain_on_overflow */
ede4eed4 216 ppc_elf_std_reloc, /* special_function */
bcbe2c71
MM
217 "R_PPC_ADDR16_HI", /* name */
218 false, /* partial_inplace */
219 0, /* src_mask */
220 0xffff, /* dst_mask */
221 false), /* pcrel_offset */
222
223 /* The high order 16 bits of an address, plus 1 if the contents of
224 the low 16 bits, treated as a signed number, is negative. */
225 HOWTO (R_PPC_ADDR16_HA, /* type */
226 16, /* rightshift */
227 1, /* size (0 = byte, 1 = short, 2 = long) */
228 16, /* bitsize */
229 false, /* pc_relative */
230 0, /* bitpos */
231 complain_overflow_dont, /* complain_on_overflow */
232 ppc_elf_addr16_ha_reloc, /* special_function */
233 "R_PPC_ADDR16_HA", /* name */
234 false, /* partial_inplace */
235 0, /* src_mask */
236 0xffff, /* dst_mask */
237 false), /* pcrel_offset */
238
239 /* An absolute 16 bit branch; the lower two bits must be zero.
240 FIXME: we don't check that, we just clear them. */
241 HOWTO (R_PPC_ADDR14, /* type */
242 0, /* rightshift */
243 2, /* size (0 = byte, 1 = short, 2 = long) */
244 16, /* bitsize */
245 false, /* pc_relative */
246 0, /* bitpos */
247 complain_overflow_bitfield, /* complain_on_overflow */
ede4eed4 248 ppc_elf_std_reloc, /* special_function */
bcbe2c71
MM
249 "R_PPC_ADDR14", /* name */
250 false, /* partial_inplace */
251 0, /* src_mask */
252 0xfffc, /* dst_mask */
253 false), /* pcrel_offset */
254
255 /* An absolute 16 bit branch, for which bit 10 should be set to
256 indicate that the branch is expected to be taken. The lower two
257 bits must be zero. */
258 HOWTO (R_PPC_ADDR14_BRTAKEN, /* type */
259 0, /* rightshift */
260 2, /* size (0 = byte, 1 = short, 2 = long) */
261 16, /* bitsize */
262 false, /* pc_relative */
263 0, /* bitpos */
264 complain_overflow_bitfield, /* complain_on_overflow */
265 ppc_elf_unsupported_reloc, /* special_function */
266 "R_PPC_ADDR14_BRTAKEN",/* name */
267 false, /* partial_inplace */
268 0, /* src_mask */
269 0xfffc, /* dst_mask */
270 false), /* pcrel_offset */
271
272 /* An absolute 16 bit branch, for which bit 10 should be set to
273 indicate that the branch is not expected to be taken. The lower
274 two bits must be zero. */
275 HOWTO (R_PPC_ADDR14_BRNTAKEN, /* type */
276 0, /* rightshift */
277 2, /* size (0 = byte, 1 = short, 2 = long) */
278 16, /* bitsize */
279 false, /* pc_relative */
280 0, /* bitpos */
281 complain_overflow_bitfield, /* complain_on_overflow */
282 ppc_elf_unsupported_reloc, /* special_function */
283 "R_PPC_ADDR14_BRNTAKEN",/* name */
284 false, /* partial_inplace */
285 0, /* src_mask */
286 0xfffc, /* dst_mask */
287 false), /* pcrel_offset */
288
289 /* A relative 26 bit branch; the lower two bits must be zero. */
290 HOWTO (R_PPC_REL24, /* type */
291 0, /* rightshift */
292 2, /* size (0 = byte, 1 = short, 2 = long) */
293 26, /* bitsize */
294 true, /* pc_relative */
295 0, /* bitpos */
296 complain_overflow_signed, /* complain_on_overflow */
ede4eed4 297 ppc_elf_std_reloc, /* special_function */
bcbe2c71
MM
298 "R_PPC_REL24", /* name */
299 false, /* partial_inplace */
300 0, /* src_mask */
301 0x3fffffc, /* dst_mask */
302 true), /* pcrel_offset */
303
304 /* A relative 16 bit branch; the lower two bits must be zero. */
305 HOWTO (R_PPC_REL14, /* type */
306 0, /* rightshift */
307 2, /* size (0 = byte, 1 = short, 2 = long) */
308 16, /* bitsize */
309 true, /* pc_relative */
310 0, /* bitpos */
311 complain_overflow_signed, /* complain_on_overflow */
ede4eed4 312 ppc_elf_std_reloc, /* special_function */
bcbe2c71
MM
313 "R_PPC_REL14", /* name */
314 false, /* partial_inplace */
315 0, /* src_mask */
316 0xfffc, /* dst_mask */
317 true), /* pcrel_offset */
318
319 /* A relative 16 bit branch. Bit 10 should be set to indicate that
320 the branch is expected to be taken. The lower two bits must be
321 zero. */
322 HOWTO (R_PPC_REL14_BRTAKEN, /* type */
323 0, /* rightshift */
324 2, /* size (0 = byte, 1 = short, 2 = long) */
325 16, /* bitsize */
326 false, /* pc_relative */
327 0, /* bitpos */
328 complain_overflow_signed, /* complain_on_overflow */
329 ppc_elf_unsupported_reloc, /* special_function */
330 "R_PPC_REL14_BRTAKEN", /* name */
331 false, /* partial_inplace */
332 0, /* src_mask */
333 0xfffc, /* dst_mask */
334 true), /* pcrel_offset */
335
336 /* A relative 16 bit branch. Bit 10 should be set to indicate that
337 the branch is not expected to be taken. The lower two bits must
338 be zero. */
339 HOWTO (R_PPC_REL14_BRNTAKEN, /* type */
340 0, /* rightshift */
341 2, /* size (0 = byte, 1 = short, 2 = long) */
342 16, /* bitsize */
343 false, /* pc_relative */
344 0, /* bitpos */
345 complain_overflow_signed, /* complain_on_overflow */
346 ppc_elf_unsupported_reloc, /* special_function */
347 "R_PPC_REL14_BRNTAKEN",/* name */
348 false, /* partial_inplace */
349 0, /* src_mask */
350 0xfffc, /* dst_mask */
351 true), /* pcrel_offset */
352
353 /* Like R_PPC_ADDR16, but referring to the GOT table entry for the
354 symbol. */
355 HOWTO (R_PPC_GOT16, /* type */
356 0, /* rightshift */
357 1, /* size (0 = byte, 1 = short, 2 = long) */
358 16, /* bitsize */
359 false, /* pc_relative */
360 0, /* bitpos */
ede4eed4 361 complain_overflow_signed, /* complain_on_overflow */
bcbe2c71
MM
362 ppc_elf_got16_reloc, /* special_function */
363 "R_PPC_GOT16", /* name */
364 false, /* partial_inplace */
365 0, /* src_mask */
366 0xffff, /* dst_mask */
367 false), /* pcrel_offset */
368
369 /* Like R_PPC_ADDR16_LO, but referring to the GOT table entry for
370 the symbol. */
371 HOWTO (R_PPC_GOT16_LO, /* type */
372 0, /* rightshift */
373 1, /* size (0 = byte, 1 = short, 2 = long) */
374 16, /* bitsize */
375 false, /* pc_relative */
376 0, /* bitpos */
377 complain_overflow_bitfield, /* complain_on_overflow */
378 ppc_elf_got16_reloc, /* special_function */
379 "R_PPC_GOT16_LO", /* name */
380 false, /* partial_inplace */
381 0, /* src_mask */
382 0xffff, /* dst_mask */
383 false), /* pcrel_offset */
384
385 /* Like R_PPC_ADDR16_HI, but referring to the GOT table entry for
386 the symbol. */
387 HOWTO (R_PPC_GOT16_HI, /* type */
388 16, /* rightshift */
389 1, /* size (0 = byte, 1 = short, 2 = long) */
390 16, /* bitsize */
391 false, /* pc_relative */
392 0, /* bitpos */
393 complain_overflow_bitfield, /* complain_on_overflow */
394 ppc_elf_got16_reloc, /* special_function */
395 "R_PPC_GOT16_HI", /* name */
396 false, /* partial_inplace */
397 0, /* src_mask */
398 0xffff, /* dst_mask */
399 false), /* pcrel_offset */
400
401 /* Like R_PPC_ADDR16_HA, but referring to the GOT table entry for
402 the symbol. FIXME: Not supported. */
403 HOWTO (R_PPC_GOT16_HA, /* type */
404 0, /* rightshift */
405 1, /* size (0 = byte, 1 = short, 2 = long) */
406 16, /* bitsize */
407 false, /* pc_relative */
408 0, /* bitpos */
409 complain_overflow_bitfield, /* complain_on_overflow */
410 ppc_elf_unsupported_reloc, /* special_function */
411 "R_PPC_GOT16_HA", /* name */
412 false, /* partial_inplace */
413 0, /* src_mask */
414 0xffff, /* dst_mask */
415 false), /* pcrel_offset */
416
417 /* Like R_PPC_REL24, but referring to the procedure linkage table
418 entry for the symbol. FIXME: Not supported. */
419 HOWTO (R_PPC_PLT24, /* type */
420 0, /* rightshift */
421 2, /* size (0 = byte, 1 = short, 2 = long) */
422 26, /* bitsize */
423 true, /* pc_relative */
424 0, /* bitpos */
425 complain_overflow_signed, /* complain_on_overflow */
ede4eed4 426 ppc_elf_std_reloc, /* special_function */
bcbe2c71
MM
427 "R_PPC_PLT24", /* name */
428 false, /* partial_inplace */
429 0, /* src_mask */
430 0x3fffffc, /* dst_mask */
431 true), /* pcrel_offset */
432
433 /* This is used only by the dynamic linker. The symbol should exist
434 both in the object being run and in some shared library. The
435 dynamic linker copies the data addressed by the symbol from the
436 shared library into the object. I have no idea what the purpose
437 of this is. */
438 HOWTO (R_PPC_COPY, /* type */
439 0, /* rightshift */
440 2, /* size (0 = byte, 1 = short, 2 = long) */
441 32, /* bitsize */
442 false, /* pc_relative */
443 0, /* bitpos */
444 complain_overflow_bitfield, /* complain_on_overflow */
ede4eed4 445 ppc_elf_std_reloc, /* special_function */
bcbe2c71
MM
446 "R_PPC_COPY", /* name */
447 false, /* partial_inplace */
448 0, /* src_mask */
449 0, /* dst_mask */
450 false), /* pcrel_offset */
451
452 /* Like R_PPC_ADDR32, but used when setting global offset table
453 entries. */
454 HOWTO (R_PPC_GLOB_DAT, /* type */
455 0, /* rightshift */
456 2, /* size (0 = byte, 1 = short, 2 = long) */
457 32, /* bitsize */
458 false, /* pc_relative */
459 0, /* bitpos */
460 complain_overflow_bitfield, /* complain_on_overflow */
ede4eed4 461 ppc_elf_std_reloc, /* special_function */
bcbe2c71
MM
462 "R_PPC_GLOB_DAT", /* name */
463 false, /* partial_inplace */
464 0, /* src_mask */
465 0xffffffff, /* dst_mask */
466 false), /* pcrel_offset */
467
468 /* Marks a procedure linkage table entry for a symbol. */
469 HOWTO (R_PPC_JMP_SLOT, /* type */
470 0, /* rightshift */
471 2, /* size (0 = byte, 1 = short, 2 = long) */
472 32, /* bitsize */
473 false, /* pc_relative */
474 0, /* bitpos */
475 complain_overflow_bitfield, /* complain_on_overflow */
ede4eed4 476 ppc_elf_std_reloc, /* special_function */
bcbe2c71
MM
477 "R_PPC_JMP_SLOT", /* name */
478 false, /* partial_inplace */
479 0, /* src_mask */
480 0, /* dst_mask */
481 false), /* pcrel_offset */
482
483 /* Used only by the dynamic linker. When the object is run, this
484 longword is set to the load address of the object, plus the
485 addend. */
486 HOWTO (R_PPC_RELATIVE, /* type */
487 0, /* rightshift */
488 2, /* size (0 = byte, 1 = short, 2 = long) */
489 32, /* bitsize */
490 false, /* pc_relative */
491 0, /* bitpos */
492 complain_overflow_bitfield, /* complain_on_overflow */
ede4eed4 493 ppc_elf_std_reloc, /* special_function */
bcbe2c71
MM
494 "R_PPC_RELATIVE", /* name */
495 false, /* partial_inplace */
496 0, /* src_mask */
497 0xffffffff, /* dst_mask */
498 false), /* pcrel_offset */
499
500 /* Like R_PPC_REL24, but uses the value of the symbol within the
501 object rather than the final value. Normally used for
502 _GLOBAL_OFFSET_TABLE_. FIXME: Not supported. */
503 HOWTO (R_PPC_LOCAL24PC, /* type */
504 0, /* rightshift */
505 2, /* size (0 = byte, 1 = short, 2 = long) */
506 26, /* bitsize */
507 true, /* pc_relative */
508 0, /* bitpos */
509 complain_overflow_signed, /* complain_on_overflow */
510 ppc_elf_unsupported_reloc, /* special_function */
511 "R_PPC_LOCAL24PC", /* name */
512 false, /* partial_inplace */
513 0, /* src_mask */
514 0x3fffffc, /* dst_mask */
515 true), /* pcrel_offset */
516
517 /* Like R_PPC_ADDR32, but may be unaligned. */
518 HOWTO (R_PPC_UADDR32, /* type */
519 0, /* rightshift */
520 2, /* size (0 = byte, 1 = short, 2 = long) */
521 32, /* bitsize */
522 false, /* pc_relative */
523 0, /* bitpos */
524 complain_overflow_bitfield, /* complain_on_overflow */
ede4eed4 525 ppc_elf_std_reloc, /* special_function */
bcbe2c71
MM
526 "R_PPC_UADDR32", /* name */
527 false, /* partial_inplace */
528 0, /* src_mask */
529 0xffffffff, /* dst_mask */
530 false), /* pcrel_offset */
531
532 /* Like R_PPC_ADDR16, but may be unaligned. */
533 HOWTO (R_PPC_UADDR16, /* type */
534 0, /* rightshift */
535 1, /* size (0 = byte, 1 = short, 2 = long) */
536 16, /* bitsize */
537 false, /* pc_relative */
538 0, /* bitpos */
539 complain_overflow_bitfield, /* complain_on_overflow */
ede4eed4 540 ppc_elf_std_reloc, /* special_function */
bcbe2c71
MM
541 "R_PPC_UADDR16", /* name */
542 false, /* partial_inplace */
543 0, /* src_mask */
544 0xffff, /* dst_mask */
545 false), /* pcrel_offset */
546
547 /* 32-bit PC relative */
548 HOWTO (R_PPC_REL32, /* type */
549 0, /* rightshift */
550 2, /* size (0 = byte, 1 = short, 2 = long) */
551 32, /* bitsize */
552 true, /* pc_relative */
553 0, /* bitpos */
554 complain_overflow_bitfield, /* complain_on_overflow */
ede4eed4 555 ppc_elf_std_reloc, /* special_function */
bcbe2c71
MM
556 "R_PPC_REL32", /* name */
557 false, /* partial_inplace */
558 0, /* src_mask */
559 0xffffffff, /* dst_mask */
560 true), /* pcrel_offset */
561
562 /* 32-bit relocation to the symbol's procedure linkage table.
563 FIXEME: not supported. */
564 HOWTO (R_PPC_PLT32, /* type */
565 0, /* rightshift */
566 2, /* size (0 = byte, 1 = short, 2 = long) */
567 32, /* bitsize */
568 false, /* pc_relative */
569 0, /* bitpos */
570 complain_overflow_bitfield, /* complain_on_overflow */
571 ppc_elf_unsupported_reloc, /* special_function */
572 "R_PPC_PLT32", /* name */
573 false, /* partial_inplace */
574 0, /* src_mask */
575 0, /* dst_mask */
576 false), /* pcrel_offset */
577
578 /* 32-bit PC relative relocation to the symbol's procedure linkage table.
579 FIXEME: not supported. */
580 HOWTO (R_PPC_PLTREL32, /* type */
581 0, /* rightshift */
582 2, /* size (0 = byte, 1 = short, 2 = long) */
583 32, /* bitsize */
584 true, /* pc_relative */
585 0, /* bitpos */
586 complain_overflow_bitfield, /* complain_on_overflow */
587 ppc_elf_unsupported_reloc, /* special_function */
588 "R_PPC_PLTREL32", /* name */
589 false, /* partial_inplace */
590 0, /* src_mask */
591 0, /* dst_mask */
592 true), /* pcrel_offset */
593
594 /* Like R_PPC_ADDR16_LO, but referring to the PLT table entry for
595 the symbol. */
596 HOWTO (R_PPC_PLT16_LO, /* type */
597 0, /* rightshift */
598 1, /* size (0 = byte, 1 = short, 2 = long) */
599 16, /* bitsize */
600 false, /* pc_relative */
601 0, /* bitpos */
602 complain_overflow_bitfield, /* complain_on_overflow */
603 ppc_elf_unsupported_reloc, /* special_function */
604 "R_PPC_PLT16_LO", /* name */
605 false, /* partial_inplace */
606 0, /* src_mask */
607 0xffff, /* dst_mask */
608 false), /* pcrel_offset */
609
610 /* Like R_PPC_ADDR16_HI, but referring to the PLT table entry for
611 the symbol. */
612 HOWTO (R_PPC_PLT16_HI, /* type */
613 16, /* rightshift */
614 1, /* size (0 = byte, 1 = short, 2 = long) */
615 16, /* bitsize */
616 false, /* pc_relative */
617 0, /* bitpos */
618 complain_overflow_bitfield, /* complain_on_overflow */
619 ppc_elf_unsupported_reloc, /* special_function */
620 "R_PPC_PLT16_HI", /* name */
621 false, /* partial_inplace */
622 0, /* src_mask */
623 0xffff, /* dst_mask */
624 false), /* pcrel_offset */
625
626 /* Like R_PPC_ADDR16_HA, but referring to the PLT table entry for
627 the symbol. FIXME: Not supported. */
628 HOWTO (R_PPC_PLT16_HA, /* type */
629 0, /* rightshift */
630 1, /* size (0 = byte, 1 = short, 2 = long) */
631 16, /* bitsize */
632 false, /* pc_relative */
633 0, /* bitpos */
634 complain_overflow_bitfield, /* complain_on_overflow */
635 ppc_elf_unsupported_reloc, /* special_function */
636 "R_PPC_PLT16_HA", /* name */
637 false, /* partial_inplace */
638 0, /* src_mask */
639 0xffff, /* dst_mask */
640 false), /* pcrel_offset */
641
642 /* A sign-extended 16 bit value relative to _SDA_BASE, for use with
643 small data items. */
644 HOWTO (R_PPC_SDAREL, /* type */
645 0, /* rightshift */
646 2, /* size (0 = byte, 1 = short, 2 = long) */
647 16, /* bitsize */
648 false, /* pc_relative */
649 0, /* bitpos */
650 complain_overflow_bitfield, /* complain_on_overflow */
651 ppc_elf_unsupported_reloc, /* special_function */
652 "R_PPC_SDAREL", /* name */
653 false, /* partial_inplace */
654 0, /* src_mask */
655 0xffff, /* dst_mask */
656 false), /* pcrel_offset */
657
658 /* These next 4 relocations were added by Sun. */
659 /* 32-bit section relative relocation. FIXME: not supported. */
660 HOWTO (R_PPC_SECTOFF, /* type */
661 0, /* rightshift */
662 2, /* size (0 = byte, 1 = short, 2 = long) */
663 32, /* bitsize */
664 true, /* pc_relative */
665 0, /* bitpos */
666 complain_overflow_bitfield, /* complain_on_overflow */
667 ppc_elf_unsupported_reloc, /* special_function */
668 "R_PPC_SECTOFF", /* name */
669 false, /* partial_inplace */
670 0, /* src_mask */
671 0, /* dst_mask */
672 true), /* pcrel_offset */
673
674 /* 16-bit lower half section relative relocation. FIXME: not supported. */
675 HOWTO (R_PPC_SECTOFF_LO, /* type */
676 0, /* rightshift */
677 1, /* size (0 = byte, 1 = short, 2 = long) */
678 16, /* bitsize */
679 false, /* pc_relative */
680 0, /* bitpos */
681 complain_overflow_bitfield, /* complain_on_overflow */
682 ppc_elf_unsupported_reloc, /* special_function */
683 "R_PPC_SECTOFF_LO", /* name */
684 false, /* partial_inplace */
685 0, /* src_mask */
686 0xffff, /* dst_mask */
687 false), /* pcrel_offset */
688
689 /* 16-bit upper half section relative relocation. FIXME: not supported. */
690 HOWTO (R_PPC_SECTOFF_HI, /* type */
691 16, /* rightshift */
692 1, /* size (0 = byte, 1 = short, 2 = long) */
693 16, /* bitsize */
694 false, /* pc_relative */
695 0, /* bitpos */
696 complain_overflow_bitfield, /* complain_on_overflow */
697 ppc_elf_unsupported_reloc, /* special_function */
698 "R_PPC_SECTOFF_HI", /* name */
699 false, /* partial_inplace */
700 0, /* src_mask */
701 0xffff, /* dst_mask */
702 false), /* pcrel_offset */
703
704 /* 16-bit upper half adjusted section relative relocation. FIXME: not supported. */
705 HOWTO (R_PPC_SECTOFF_HA, /* type */
706 0, /* rightshift */
707 1, /* size (0 = byte, 1 = short, 2 = long) */
708 16, /* bitsize */
709 false, /* pc_relative */
710 0, /* bitpos */
711 complain_overflow_bitfield, /* complain_on_overflow */
712 ppc_elf_unsupported_reloc, /* special_function */
713 "R_PPC_SECTOFF_HA", /* name */
714 false, /* partial_inplace */
715 0, /* src_mask */
716 0xffff, /* dst_mask */
717 false), /* pcrel_offset */
718
719 /* The remaining relocs are from the Embedded ELF ABI, and are not
720 in the SVR4 ELF ABI. */
721
722 /* 32 bit value resulting from the addend minus the symbol */
723 HOWTO (R_PPC_EMB_NADDR32, /* type */
724 0, /* rightshift */
725 2, /* size (0 = byte, 1 = short, 2 = long) */
726 32, /* bitsize */
727 false, /* pc_relative */
728 0, /* bitpos */
729 complain_overflow_bitfield, /* complain_on_overflow */
730 ppc_elf_unsupported_reloc, /* special_function */
731 "R_PPC_EMB_NADDR32", /* name */
732 false, /* partial_inplace */
733 0, /* src_mask */
734 0xffffffff, /* dst_mask */
735 false), /* pcrel_offset */
736
737 /* 16 bit value resulting from the addend minus the symbol */
738 HOWTO (R_PPC_EMB_NADDR16, /* type */
739 0, /* rightshift */
740 1, /* size (0 = byte, 1 = short, 2 = long) */
741 16, /* bitsize */
742 false, /* pc_relative */
743 0, /* bitpos */
744 complain_overflow_bitfield, /* complain_on_overflow */
745 ppc_elf_unsupported_reloc, /* special_function */
746 "R_PPC_EMB_NADDR16", /* name */
747 false, /* partial_inplace */
748 0, /* src_mask */
749 0xffff, /* dst_mask */
750 false), /* pcrel_offset */
751
752 /* 16 bit value resulting from the addend minus the symbol */
753 HOWTO (R_PPC_EMB_NADDR16_LO, /* type */
754 0, /* rightshift */
755 1, /* size (0 = byte, 1 = short, 2 = long) */
756 16, /* bitsize */
757 false, /* pc_relative */
758 0, /* bitpos */
759 complain_overflow_dont,/* complain_on_overflow */
760 ppc_elf_unsupported_reloc, /* special_function */
761 "R_PPC_EMB_ADDR16_LO", /* name */
762 false, /* partial_inplace */
763 0, /* src_mask */
764 0xffff, /* dst_mask */
765 false), /* pcrel_offset */
766
767 /* The high order 16 bits of the addend minus the symbol */
768 HOWTO (R_PPC_EMB_NADDR16_HI, /* type */
769 16, /* rightshift */
770 1, /* size (0 = byte, 1 = short, 2 = long) */
771 16, /* bitsize */
772 false, /* pc_relative */
773 0, /* bitpos */
774 complain_overflow_dont, /* complain_on_overflow */
775 ppc_elf_unsupported_reloc, /* special_function */
776 "R_PPC_EMB_NADDR16_HI", /* name */
777 false, /* partial_inplace */
778 0, /* src_mask */
779 0xffff, /* dst_mask */
780 false), /* pcrel_offset */
781
782 /* The high order 16 bits of the result of the addend minus the address,
783 plus 1 if the contents of the low 16 bits, treated as a signed number,
784 is negative. */
785 HOWTO (R_PPC_EMB_NADDR16_HA, /* type */
786 16, /* rightshift */
787 1, /* size (0 = byte, 1 = short, 2 = long) */
788 16, /* bitsize */
789 false, /* pc_relative */
790 0, /* bitpos */
791 complain_overflow_dont, /* complain_on_overflow */
792 ppc_elf_unsupported_reloc, /* special_function */
793 "R_PPC_EMB_NADDR16_HA", /* name */
794 false, /* partial_inplace */
795 0, /* src_mask */
796 0xffff, /* dst_mask */
797 false), /* pcrel_offset */
798};
799
ede4eed4
KR
800\f
801/* Initialize the ppc_elf_howto_table, so that linear accesses can be done. */
802
803static void
804ppc_elf_howto_init ()
805{
806 unsigned int i, type;
807
808 for (i = 0; i < sizeof (ppc_elf_howto_raw) / sizeof (ppc_elf_howto_raw[0]); i++)
809 {
810 type = ppc_elf_howto_raw[i].type;
811 BFD_ASSERT (type < sizeof(ppc_elf_howto_table) / sizeof(ppc_elf_howto_table[0]));
812 ppc_elf_howto_table[type] = &ppc_elf_howto_raw[i];
813 }
814}
815
816\f
817static reloc_howto_type *
818ppc_elf_reloc_type_lookup (abfd, code)
819 bfd *abfd;
820 bfd_reloc_code_real_type code;
821{
822 if (!ppc_elf_howto_table[ R_PPC_ADDR32 ]) /* Initialize howto table if needed */
823 ppc_elf_howto_init ();
824
825 switch ((int)code)
826 {
827 case BFD_RELOC_NONE: return ppc_elf_howto_table[ (int) R_PPC_NONE ];
828 case BFD_RELOC_32: return ppc_elf_howto_table[ (int) R_PPC_ADDR32 ];
829 case BFD_RELOC_32_PCREL: return ppc_elf_howto_table[ (int) R_PPC_REL32 ];
830 case BFD_RELOC_CTOR: return ppc_elf_howto_table[ (int) R_PPC_ADDR32 ];
831 case BFD_RELOC_PPC_B26: return ppc_elf_howto_table[ (int) R_PPC_REL24 ];
832 case BFD_RELOC_PPC_BA26: return ppc_elf_howto_table[ (int) R_PPC_ADDR24 ];
833 case BFD_RELOC_PPC_TOC16: return ppc_elf_howto_table[ (int) R_PPC_GOT16 ];
834 case BFD_RELOC_LO16: return ppc_elf_howto_table[ (int) R_PPC_ADDR16_LO ];
835 case BFD_RELOC_HI16: return ppc_elf_howto_table[ (int) R_PPC_ADDR16_HI ];
836 case BFD_RELOC_HI16_S: return ppc_elf_howto_table[ (int) R_PPC_ADDR16_HA ];
837 }
838
839 return (reloc_howto_type *)NULL;
840};
841
842/* Set the howto pointer for a PowerPC ELF reloc. */
843
844static void
845ppc_elf_info_to_howto (abfd, cache_ptr, dst)
846 bfd *abfd;
847 arelent *cache_ptr;
848 Elf32_Internal_Rela *dst;
849{
850 if (!ppc_elf_howto_table[ R_PPC_ADDR32 ]) /* Initialize howto table if needed */
851 ppc_elf_howto_init ();
852
853 BFD_ASSERT (ELF32_R_TYPE (dst->r_info) < (unsigned int) R_PPC_max);
854 cache_ptr->howto = ppc_elf_howto_table[ELF32_R_TYPE (dst->r_info)];
855}
856
857/* Function to set whether a module needs the -mrelocatable bit set. */
858
859static boolean
860ppc_elf_set_private_flags (abfd, flags)
861 bfd *abfd;
862 flagword flags;
863{
864 BFD_ASSERT (!elf_ppc_flags_init (abfd)
865 || elf_elfheader (abfd)->e_flags == flags);
866
867 elf_elfheader (abfd)->e_flags = flags;
868 elf_ppc_flags_init (abfd) = true;
869 return true;
870}
871
872/* Copy backend specific data from one object module to another */
873static boolean
874ppc_elf_copy_private_bfd_data (ibfd, obfd)
875 bfd *ibfd;
876 bfd *obfd;
877{
878 /* This function is selected based on the input vector. We only
879 want to copy information over if the output BFD also uses Elf
880 format. */
881 if (bfd_get_flavour (obfd) != bfd_target_elf_flavour)
882 return true;
883
884 BFD_ASSERT (!elf_ppc_flags_init (obfd)
885 || elf_elfheader (obfd)->e_flags == elf_elfheader (ibfd)->e_flags);
886
887 elf_elfheader (obfd)->e_flags = elf_elfheader (ibfd)->e_flags;
888 elf_ppc_flags_init (obfd) = true;
889 return true;
890}
891
892/* Merge backend specific data from an object file to the output
893 object file when linking */
894static boolean
895ppc_elf_merge_private_bfd_data (ibfd, obfd)
896 bfd *ibfd;
897 bfd *obfd;
898{
899 flagword old_flags;
900 flagword new_flags;
901
902 /* Check if we have the same endianess */
903 if (ibfd->xvec->byteorder_big_p != obfd->xvec->byteorder_big_p)
904 {
905 fprintf (stderr,
906 "%s: compiled for a %s endian system and target is %s endian.\n",
907 bfd_get_filename (ibfd),
908 (ibfd->xvec->byteorder_big_p) ? "big" : "little",
909 (obfd->xvec->byteorder_big_p) ? "big" : "little");
910
911 bfd_set_error (bfd_error_wrong_format);
912 return false;
913 }
914
915 /* This function is selected based on the input vector. We only
916 want to copy information over if the output BFD also uses Elf
917 format. */
918 if (bfd_get_flavour (obfd) != bfd_target_elf_flavour)
919 return true;
920
921 new_flags = elf_elfheader (ibfd)->e_flags;
922 old_flags = elf_elfheader (obfd)->e_flags;
923 if (!elf_ppc_flags_init (obfd)) /* First call, no flags set */
924 {
925 elf_ppc_flags_init (obfd) = true;
926 elf_elfheader (obfd)->e_flags = new_flags;
927 }
928
929 else if (new_flags == old_flags) /* Compatible flags are ok */
930 ;
931
932 else /* Incompatible flags */
933 {
934 /* Warn about -mrelocatable mismatch */
935 if ((new_flags & EF_PPC_RELOCATABLE) != 0 && (old_flags & EF_PPC_RELOCATABLE) == 0)
936 {
937 new_flags &= ~EF_PPC_RELOCATABLE;
938 fprintf (stderr,
939 "%s: compiled with -mrelocatable and linked with modules compiled normally\n",
940 bfd_get_filename (ibfd));
941 }
942 else if ((new_flags & EF_PPC_RELOCATABLE) == 0 && (old_flags & EF_PPC_RELOCATABLE) != 0)
943 {
944 old_flags &= ~EF_PPC_RELOCATABLE;
945 fprintf (stderr,
946 "%s: compiled normally and linked with modules compiled with -mrelocatable\n",
947 bfd_get_filename (ibfd));
948 }
949
950 /* Warn about eabi vs. V.4 mismatch */
951 if ((new_flags & EF_PPC_EMB) != 0 && (old_flags & EF_PPC_EMB) == 0)
952 {
953 new_flags &= ~EF_PPC_EMB;
954 fprintf (stderr,
955 "%s: compiled for the eabi and linked with modules compiled for System V\n",
956 bfd_get_filename (ibfd));
957 }
958 else if ((new_flags & EF_PPC_EMB) == 0 && (old_flags & EF_PPC_EMB) != 0)
959 {
960 old_flags &= ~EF_PPC_EMB;
961 fprintf (stderr,
962 "%s: compiled for System V and linked with modules compiled for eabi\n",
963 bfd_get_filename (ibfd));
964 }
965
966 /* Warn about any other mismatches */
967 if (new_flags != old_flags)
968 fprintf (stderr,
969 "%s: uses different e_flags (0x%lx) fields than previous modules (0x%lx)\n",
970 bfd_get_filename (ibfd), (long)new_flags, (long)old_flags);
971
972 bfd_set_error (bfd_error_bad_value);
973 return false;
974 }
975
976 return true;
977}
978
979\f
980/* ELF relocs are against symbols. If we are producing relocateable
981 output, and the reloc is against an external symbol, and nothing
982 has given us any additional addend, the resulting reloc will also
983 be against the same symbol. In such a case, we don't want to
984 change anything about the way the reloc is handled, since it will
985 all be done at final link time. Rather than put special case code
986 into bfd_perform_relocation, all the reloc types use this howto
987 function. It just short circuits the reloc if producing
988 relocateable output against an external symbol. */
989
990/*ARGSUSED*/
991static bfd_reloc_status_type
992ppc_elf_std_reloc (abfd,
993 reloc_entry,
994 symbol,
995 data,
996 input_section,
997 output_bfd,
998 error_message)
999 bfd *abfd;
1000 arelent *reloc_entry;
1001 asymbol *symbol;
1002 PTR data;
1003 asection *input_section;
1004 bfd *output_bfd;
1005 char **error_message;
1006{
1007 if (output_bfd != (bfd *) NULL
1008 && (symbol->flags & BSF_SECTION_SYM) == 0
1009 && (! reloc_entry->howto->partial_inplace || reloc_entry->addend == 0))
1010 {
1011 reloc_entry->address += input_section->output_offset;
1012 return bfd_reloc_ok;
1013 }
1014
1015 return bfd_reloc_continue;
1016}
1017
bcbe2c71
MM
1018/* Don't pretend we can deal with unsupported relocs. */
1019
1020/*ARGSUSED*/
1021static bfd_reloc_status_type
1022ppc_elf_unsupported_reloc (abfd, reloc_entry, symbol, data, input_section,
1023 output_bfd, error_message)
1024 bfd *abfd;
1025 arelent *reloc_entry;
1026 asymbol *symbol;
1027 PTR data;
1028 asection *input_section;
1029 bfd *output_bfd;
1030 char **error_message;
1031{
ede4eed4
KR
1032 BFD_ASSERT (reloc_entry->howto != (reloc_howto_type *)0);
1033 fprintf (stderr,
1034 "%s: Relocation %s (%d) is not currently supported.\n",
1035 bfd_get_filename (abfd),
1036 reloc_entry->howto->name,
1037 reloc_entry->howto->type);
1038
1039 return bfd_reloc_notsupported;
1040}
1041
1042/* Internal function to return the adjustment to the addend for relocations
1043 that return the upper 16 bits after sign extending the lower 16 bits, ie
1044 for use with a ORIS instruction followed by a memory reference using the
1045 bottom 16 bits. */
1046
1047INLINE
1048static bfd_vma
1049ppc_elf_addr16_ha_inner (sec, value, addend)
1050 asection *sec;
1051 bfd_vma value;
1052 bfd_vma addend;
1053{
1054 bfd_vma relocation = (value
1055 + sec->output_section->vma
1056 + sec->output_offset
1057 + addend);
1058
1059 return (relocation & 0x8000) << 1;
bcbe2c71
MM
1060}
1061
1062/* Handle the ADDR16_HA reloc by adjusting the reloc addend. */
1063
ede4eed4 1064/*ARGSUSED*/
bcbe2c71
MM
1065static bfd_reloc_status_type
1066ppc_elf_addr16_ha_reloc (abfd, reloc_entry, symbol, data, input_section,
1067 output_bfd, error_message)
1068 bfd *abfd;
1069 arelent *reloc_entry;
1070 asymbol *symbol;
1071 PTR data;
1072 asection *input_section;
1073 bfd *output_bfd;
1074 char **error_message;
1075{
bcbe2c71 1076 if (output_bfd != (bfd *) NULL)
ede4eed4
KR
1077 return ppc_elf_std_reloc (abfd, reloc_entry, symbol, data,
1078 input_section, output_bfd, error_message);
bcbe2c71 1079
ede4eed4
KR
1080 reloc_entry->addend += ppc_elf_addr16_ha_inner (symbol->section,
1081 (bfd_is_com_section (symbol->section)) ? 0 : symbol->value,
1082 reloc_entry->addend);
1083 return bfd_reloc_continue;
1084}
bcbe2c71 1085
ede4eed4
KR
1086/* Internal function to return the addjustment to the addend for GOT16
1087 entries */
bcbe2c71 1088
ede4eed4
KR
1089INLINE
1090static bfd_vma
1091ppc_elf_got16_inner (sec)
1092 asection *sec;
1093{
1094 BFD_ASSERT (bfd_is_und_section (sec)
1095 || strcmp (bfd_get_section_name (abfd, sec), ".got") == 0
1096 || strcmp (bfd_get_section_name (abfd, sec), ".cgot") == 0);
bcbe2c71 1097
ede4eed4 1098 return -(sec->output_section->vma + 0x8000);
bcbe2c71
MM
1099}
1100
1101/* Handle the GOT16 reloc. We want to use the offset within the .got
1102 section, not the actual VMA. This is appropriate when generating
1103 an embedded ELF object, for which the .got section acts like the
1104 AIX .toc section. When and if we support PIC code, we will have to
1105 change this, perhaps by switching off on the e_type field. */
1106
ede4eed4 1107/*ARGSUSED*/
bcbe2c71
MM
1108static bfd_reloc_status_type
1109ppc_elf_got16_reloc (abfd, reloc_entry, symbol, data, input_section,
1110 output_bfd, error_message)
1111 bfd *abfd;
1112 arelent *reloc_entry;
1113 asymbol *symbol;
1114 PTR data;
1115 asection *input_section;
1116 bfd *output_bfd;
1117 char **error_message;
1118{
bcbe2c71 1119 if (output_bfd != (bfd *) NULL)
ede4eed4
KR
1120 return ppc_elf_std_reloc (abfd, reloc_entry, symbol, data,
1121 input_section, output_bfd, error_message);
bcbe2c71 1122
ede4eed4 1123 reloc_entry->addend += ppc_elf_got16_inner (bfd_get_section (*reloc_entry->sym_ptr_ptr));
bcbe2c71
MM
1124 return bfd_reloc_continue;
1125}
1126
ede4eed4
KR
1127\f
1128/* The RELOCATE_SECTION function is called by the ELF backend linker
1129 to handle the relocations for a section.
bcbe2c71 1130
ede4eed4
KR
1131 The relocs are always passed as Rela structures; if the section
1132 actually uses Rel structures, the r_addend field will always be
1133 zero.
bcbe2c71 1134
ede4eed4
KR
1135 This function is responsible for adjust the section contents as
1136 necessary, and (if using Rela relocs and generating a
1137 relocateable output file) adjusting the reloc addend as
1138 necessary.
bcbe2c71 1139
ede4eed4
KR
1140 This function does not have to worry about setting the reloc
1141 address or the reloc symbol index.
1142
1143 LOCAL_SYMS is a pointer to the swapped in local symbols.
1144
1145 LOCAL_SECTIONS is an array giving the section in the input file
1146 corresponding to the st_shndx field of each local symbol.
1147
1148 The global hash table entry for the global symbols can be found
1149 via elf_sym_hashes (input_bfd).
1150
1151 When generating relocateable output, this function must handle
1152 STB_LOCAL/STT_SECTION symbols specially. The output symbol is
1153 going to be the section symbol corresponding to the output
1154 section, which means that the addend must be adjusted
1155 accordingly. */
1156
1157static boolean
1158ppc_elf_relocate_section (output_bfd, info, input_bfd, input_section,
1159 contents, relocs, local_syms, local_sections)
1160 bfd *output_bfd;
1161 struct bfd_link_info *info;
1162 bfd *input_bfd;
1163 asection *input_section;
1164 bfd_byte *contents;
1165 Elf_Internal_Rela *relocs;
1166 Elf_Internal_Sym *local_syms;
1167 asection **local_sections;
bcbe2c71 1168{
ede4eed4
KR
1169 Elf_Internal_Shdr *symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
1170 struct elf_link_hash_entry **sym_hashes = elf_sym_hashes (input_bfd);
1171 Elf_Internal_Rela *rel = relocs;
1172 Elf_Internal_Rela *relend = relocs + input_section->reloc_count;
1173 boolean ret = true;
1174
1175#ifdef DEBUG
1176 fprintf (stderr, "ppc_elf_relocate_section called for %s section %s, %ld relocations%s\n",
1177 bfd_get_filename (input_bfd),
1178 bfd_section_name(input_bfd, input_section),
1179 (long)input_section->reloc_count,
1180 (info->relocateable) ? " (relocatable)" : "");
1181#endif
1182
1183 if (!ppc_elf_howto_table[ R_PPC_ADDR32 ]) /* Initialize howto table if needed */
1184 ppc_elf_howto_init ();
bcbe2c71 1185
ede4eed4 1186 for (; rel < relend; rel++)
bcbe2c71 1187 {
ede4eed4
KR
1188 enum reloc_type r_type = (enum reloc_type)ELF32_R_TYPE (rel->r_info);
1189 bfd_vma offset = rel->r_offset;
1190 bfd_vma addend = rel->r_addend;
1191 bfd_reloc_status_type r = bfd_reloc_other;
1192 Elf_Internal_Sym *sym = (Elf_Internal_Sym *)0;
1193 asection *sec = (asection *)0;
1194 struct elf_link_hash_entry *h = (struct elf_link_hash_entry *)0;
1195 reloc_howto_type *howto;
1196 unsigned long r_symndx;
1197 bfd_vma relocation;
1198
1199 /* Unknown relocation handling */
1200 if ((unsigned)r_type >= (unsigned)R_PPC_max || !ppc_elf_howto_table[(int)r_type])
1201 {
1202 fprintf (stderr,
1203 "%s: Unknown relocation type %d\n",
1204 bfd_get_filename (input_bfd),
1205 (int)r_type);
1206
1207 bfd_set_error (bfd_error_bad_value);
1208 ret = false;
1209 continue;
1210 }
1211
1212 howto = ppc_elf_howto_table[(int)r_type];
1213 r_symndx = ELF32_R_SYM (rel->r_info);
1214
1215 if (info->relocateable)
1216 {
1217 /* This is a relocateable link. We don't have to change
1218 anything, unless the reloc is against a section symbol,
1219 in which case we have to adjust according to where the
1220 section symbol winds up in the output section. */
1221 if (r_symndx < symtab_hdr->sh_info)
1222 {
1223 sym = local_syms + r_symndx;
1224 if ((unsigned)ELF_ST_TYPE (sym->st_info) == STT_SECTION)
1225 {
1226 sec = local_sections[r_symndx];
1227 addend = rel->r_addend += sec->output_offset + sym->st_value;
1228 }
1229 }
1230
1231#ifdef DEBUG
1232 fprintf (stderr, "\ttype = %s (%d), symbol index = %ld, offset = %ld, addend = %ld\n",
1233 howto->name,
1234 (int)r_type,
1235 r_symndx,
1236 (long)offset,
1237 (long)addend);
1238#endif
1239 continue;
1240 }
1241
1242 /* This is a final link. */
1243
1244 /* Complain about known relocation that are not yet supported */
1245 if (howto->special_function == ppc_elf_unsupported_reloc)
1246 {
1247 fprintf (stderr,
1248 "%s: Relocation %s (%d) is not currently supported.\n",
1249 bfd_get_filename (input_bfd),
1250 howto->name,
1251 (int)r_type);
1252
1253 bfd_set_error (bfd_error_bad_value);
1254 ret = false;
1255 continue;
1256 }
1257
1258 if (r_symndx < symtab_hdr->sh_info)
1259 {
1260 sym = local_syms + r_symndx;
1261 sec = local_sections[r_symndx];
1262 relocation = (sec->output_section->vma
1263 + sec->output_offset
1264 + sym->st_value);
1265 }
1266 else
1267 {
1268 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
1269 if (h->root.type == bfd_link_hash_defined
1270 || h->root.type == bfd_link_hash_defweak)
1271 {
1272 sec = h->root.u.def.section;
1273 relocation = (h->root.u.def.value
1274 + sec->output_section->vma
1275 + sec->output_offset);
1276 }
1277 else if (h->root.type == bfd_link_hash_undefweak)
1278 relocation = 0;
1279 else if (info->shared)
1280 relocation = 0;
1281 else
1282 {
1283 (*info->callbacks->undefined_symbol)(info,
1284 h->root.root.string,
1285 input_bfd,
1286 input_section,
1287 rel->r_offset);
1288 ret = false;
1289 continue;
1290 }
1291 }
1292
1293 switch ((int)r_type)
1294 {
1295 default:
1296 break;
1297
1298 case (int)R_PPC_GOT16: /* GOT16 relocations */
1299 case (int)R_PPC_GOT16_LO:
1300 case (int)R_PPC_GOT16_HI:
1301 BFD_ASSERT (sec != (asection *)0);
1302 addend += ppc_elf_got16_inner (sec);
1303 break;
1304
1305 case (int)R_PPC_ADDR16_HA: /* arithmetic adjust relocations */
1306 BFD_ASSERT (sec != (asection *)0);
1307 addend += ppc_elf_addr16_ha_inner (sec, relocation, addend);
1308 break;
1309 }
1310
1311
1312#ifdef DEBUG
1313 fprintf (stderr, "\ttype = %s (%d), symbol index = %ld, offset = %ld, addend = %ld\n",
1314 howto->name,
1315 (int)r_type,
1316 r_symndx,
1317 (long)offset,
1318 (long)addend);
1319#endif
1320
1321 r = _bfd_final_link_relocate (howto,
1322 input_bfd,
1323 input_section,
1324 contents,
1325 offset,
1326 relocation,
1327 addend);
1328
1329 if (r != bfd_reloc_ok)
1330 {
1331 ret = false;
1332 switch (r)
1333 {
1334 default:
1335 break;
1336
1337 case bfd_reloc_overflow:
1338 {
1339 const char *name;
1340
1341 if (h != NULL)
1342 name = h->root.root.string;
1343 else
1344 {
1345 name = bfd_elf_string_from_elf_section (input_bfd,
1346 symtab_hdr->sh_link,
1347 sym->st_name);
1348 if (name == NULL)
1349 break;
1350
1351 if (*name == '\0')
1352 name = bfd_section_name (input_bfd, sec);
1353 }
1354
1355 (*info->callbacks->reloc_overflow)(info,
1356 name,
1357 howto->name,
1358 (bfd_vma) 0,
1359 input_bfd,
1360 input_section,
1361 offset);
1362 }
1363 break;
1364
1365 }
1366 }
bcbe2c71
MM
1367 }
1368
bcbe2c71 1369
ede4eed4
KR
1370#ifdef DEBUG
1371 fprintf (stderr, "\n");
1372#endif
bcbe2c71 1373
ede4eed4 1374 return ret;
bcbe2c71
MM
1375}
1376
ede4eed4
KR
1377#define TARGET_LITTLE_SYM bfd_elf32_powerpcle_vec
1378#define TARGET_LITTLE_NAME "elf32-powerpcle"
bcbe2c71
MM
1379#define TARGET_BIG_SYM bfd_elf32_powerpc_vec
1380#define TARGET_BIG_NAME "elf32-powerpc"
1381#define ELF_ARCH bfd_arch_powerpc
1382#define ELF_MACHINE_CODE EM_PPC
1383#define ELF_MAXPAGESIZE 0x10000
ede4eed4 1384#define elf_info_to_howto ppc_elf_info_to_howto
bcbe2c71
MM
1385
1386#ifdef EM_CYGNUS_POWERPC
1387#define ELF_MACHINE_ALT1 EM_CYGNUS_POWERPC
1388#endif
1389
1390#ifdef EM_PPC_OLD
1391#define ELF_MACHINE_ALT2 EM_PPC_OLD
1392#endif
1393
ede4eed4
KR
1394#define bfd_elf32_bfd_copy_private_bfd_data ppc_elf_copy_private_bfd_data
1395#define bfd_elf32_bfd_merge_private_bfd_data ppc_elf_merge_private_bfd_data
1396#define bfd_elf32_bfd_set_private_flags ppc_elf_set_private_flags
1397#define bfd_elf32_bfd_reloc_type_lookup ppc_elf_reloc_type_lookup
1398#define elf_backend_relocate_section ppc_elf_relocate_section
1399
bcbe2c71 1400#include "elf32-target.h"
This page took 0.087904 seconds and 4 git commands to generate.