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