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