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