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