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