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