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