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 | ||
ae9a127f | 6 | This file is part of BFD, the Binary File Descriptor library. |
252b5132 | 7 | |
ae9a127f NC |
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. | |
252b5132 | 12 | |
ae9a127f NC |
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. | |
252b5132 | 17 | |
ae9a127f NC |
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. */ | |
252b5132 RH |
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" | |
7619e7c7 | 33 | #include "elf32-ppc.h" |
252b5132 | 34 | |
f0fe0e16 | 35 | /* RELA relocations are used here. */ |
252b5132 | 36 | |
7fce784e AS |
37 | static struct bfd_hash_entry *ppc_elf_link_hash_newfunc |
38 | PARAMS ((struct bfd_hash_entry *entry, struct bfd_hash_table *table, | |
39 | const char *string)); | |
40 | static struct bfd_link_hash_table *ppc_elf_link_hash_table_create | |
41 | PARAMS ((bfd *abfd)); | |
42 | static void ppc_elf_copy_indirect_symbol | |
43 | PARAMS ((struct elf_backend_data *bed, struct elf_link_hash_entry *dir, | |
44 | struct elf_link_hash_entry *ind)); | |
252b5132 RH |
45 | static reloc_howto_type *ppc_elf_reloc_type_lookup |
46 | PARAMS ((bfd *abfd, bfd_reloc_code_real_type code)); | |
47 | static void ppc_elf_info_to_howto | |
947216bf | 48 | PARAMS ((bfd *abfd, arelent *cache_ptr, Elf_Internal_Rela *dst)); |
b34976b6 AM |
49 | static void ppc_elf_howto_init |
50 | PARAMS ((void)); | |
51 | static int ppc_elf_sort_rela | |
52 | PARAMS ((const PTR, const PTR)); | |
53 | static bfd_boolean ppc_elf_relax_section | |
54 | PARAMS ((bfd *, asection *, struct bfd_link_info *, bfd_boolean *)); | |
252b5132 RH |
55 | static bfd_reloc_status_type ppc_elf_addr16_ha_reloc |
56 | PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **)); | |
7619e7c7 AM |
57 | static bfd_reloc_status_type ppc_elf_unhandled_reloc |
58 | PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **)); | |
b34976b6 AM |
59 | static bfd_boolean ppc_elf_object_p |
60 | PARAMS ((bfd *)); | |
61 | static bfd_boolean ppc_elf_set_private_flags | |
62 | PARAMS ((bfd *, flagword)); | |
63 | static bfd_boolean ppc_elf_merge_private_bfd_data | |
64 | PARAMS ((bfd *, bfd *)); | |
65 | static int ppc_elf_additional_program_headers | |
66 | PARAMS ((bfd *)); | |
67 | static bfd_boolean ppc_elf_modify_segment_map | |
68 | PARAMS ((bfd *)); | |
7619e7c7 | 69 | static bfd_boolean ppc_elf_create_got |
41fcb14e | 70 | PARAMS ((bfd *, struct bfd_link_info *)); |
b34976b6 | 71 | static bfd_boolean ppc_elf_create_dynamic_sections |
252b5132 | 72 | PARAMS ((bfd *, struct bfd_link_info *)); |
b34976b6 AM |
73 | static bfd_boolean ppc_elf_section_from_shdr |
74 | PARAMS ((bfd *, Elf_Internal_Shdr *, const char *)); | |
75 | static bfd_boolean ppc_elf_fake_sections | |
947216bf | 76 | PARAMS ((bfd *, Elf_Internal_Shdr *, asection *)); |
252b5132 | 77 | static elf_linker_section_t *ppc_elf_create_linker_section |
b34976b6 | 78 | PARAMS ((bfd *abfd, struct bfd_link_info *info, |
252b5132 | 79 | enum elf_linker_section_enum)); |
7619e7c7 AM |
80 | static bfd_boolean update_local_sym_info |
81 | PARAMS ((bfd *, Elf_Internal_Shdr *, unsigned long, int)); | |
82 | static void bad_shared_reloc | |
83 | PARAMS ((bfd *, enum elf_ppc_reloc_type)); | |
b34976b6 AM |
84 | static bfd_boolean ppc_elf_check_relocs |
85 | PARAMS ((bfd *, struct bfd_link_info *, asection *, | |
86 | const Elf_Internal_Rela *)); | |
70bccea4 | 87 | static asection *ppc_elf_gc_mark_hook |
b34976b6 AM |
88 | PARAMS ((asection *sec, struct bfd_link_info *info, Elf_Internal_Rela *rel, |
89 | struct elf_link_hash_entry *h, Elf_Internal_Sym *sym)); | |
90 | static bfd_boolean ppc_elf_gc_sweep_hook | |
91 | PARAMS ((bfd *abfd, struct bfd_link_info *info, asection *sec, | |
92 | const Elf_Internal_Rela *relocs)); | |
93 | static bfd_boolean ppc_elf_adjust_dynamic_symbol | |
94 | PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *)); | |
7fce784e AS |
95 | static bfd_boolean allocate_dynrelocs |
96 | PARAMS ((struct elf_link_hash_entry *, PTR)); | |
97 | static bfd_boolean readonly_dynrelocs | |
98 | PARAMS ((struct elf_link_hash_entry *, PTR)); | |
b34976b6 AM |
99 | static bfd_boolean ppc_elf_size_dynamic_sections |
100 | PARAMS ((bfd *, struct bfd_link_info *)); | |
101 | static bfd_boolean ppc_elf_relocate_section | |
102 | PARAMS ((bfd *, struct bfd_link_info *info, bfd *, asection *, bfd_byte *, | |
103 | Elf_Internal_Rela *relocs, Elf_Internal_Sym *local_syms, | |
104 | asection **)); | |
105 | static bfd_boolean ppc_elf_add_symbol_hook | |
106 | PARAMS ((bfd *, struct bfd_link_info *, const Elf_Internal_Sym *, | |
107 | const char **, flagword *, asection **, bfd_vma *)); | |
108 | static bfd_boolean ppc_elf_finish_dynamic_symbol | |
109 | PARAMS ((bfd *, struct bfd_link_info *, struct elf_link_hash_entry *, | |
110 | Elf_Internal_Sym *)); | |
111 | static bfd_boolean ppc_elf_finish_dynamic_sections | |
112 | PARAMS ((bfd *, struct bfd_link_info *)); | |
f51e552e AM |
113 | static enum elf_reloc_type_class ppc_elf_reloc_type_class |
114 | PARAMS ((const Elf_Internal_Rela *)); | |
b34976b6 | 115 | static bfd_boolean ppc_elf_grok_prstatus |
2e67030c | 116 | PARAMS ((bfd *abfd, Elf_Internal_Note *note)); |
b34976b6 | 117 | static bfd_boolean ppc_elf_grok_psinfo |
2e67030c | 118 | PARAMS ((bfd *abfd, Elf_Internal_Note *note)); |
252b5132 | 119 | |
70bccea4 AM |
120 | /* Branch prediction bit for branch taken relocs. */ |
121 | #define BRANCH_PREDICT_BIT 0x200000 | |
122 | /* Mask to set RA in memory instructions. */ | |
123 | #define RA_REGISTER_MASK 0x001f0000 | |
124 | /* Value to shift register by to insert RA. */ | |
125 | #define RA_REGISTER_SHIFT 16 | |
252b5132 RH |
126 | |
127 | /* The name of the dynamic interpreter. This is put in the .interp | |
128 | section. */ | |
252b5132 RH |
129 | #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1" |
130 | ||
131 | /* The size in bytes of an entry in the procedure linkage table. */ | |
132 | #define PLT_ENTRY_SIZE 12 | |
133 | /* The initial size of the plt reserved for the dynamic linker. */ | |
134 | #define PLT_INITIAL_ENTRY_SIZE 72 | |
135 | /* The size of the gap between entries in the PLT. */ | |
136 | #define PLT_SLOT_SIZE 8 | |
137 | /* The number of single-slot PLT entries (the rest use two slots). */ | |
138 | #define PLT_NUM_SINGLE_ENTRIES 8192 | |
139 | ||
7619e7c7 AM |
140 | /* Some nop instructions. */ |
141 | #define NOP 0x60000000 | |
142 | #define CROR_151515 0x4def7b82 | |
143 | #define CROR_313131 0x4ffffb82 | |
144 | ||
145 | /* Offset of tp and dtp pointers from start of TLS block. */ | |
146 | #define TP_OFFSET 0x7000 | |
147 | #define DTP_OFFSET 0x8000 | |
148 | ||
e1e0340b GK |
149 | /* Will references to this symbol always reference the symbol |
150 | in this object? */ | |
151 | #define SYMBOL_REFERENCES_LOCAL(INFO, H) \ | |
152 | ((! INFO->shared \ | |
153 | || INFO->symbolic \ | |
154 | || H->dynindx == -1 \ | |
155 | || ELF_ST_VISIBILITY (H->other) == STV_INTERNAL \ | |
156 | || ELF_ST_VISIBILITY (H->other) == STV_HIDDEN) \ | |
157 | && (H->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) != 0) | |
158 | ||
159 | /* Will _calls_ to this symbol always call the version in this object? */ | |
160 | #define SYMBOL_CALLS_LOCAL(INFO, H) \ | |
161 | ((! INFO->shared \ | |
162 | || INFO->symbolic \ | |
163 | || H->dynindx == -1 \ | |
164 | || ELF_ST_VISIBILITY (H->other) != STV_DEFAULT) \ | |
165 | && (H->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) != 0) | |
252b5132 | 166 | \f |
7fce784e AS |
167 | /* The PPC linker needs to keep track of the number of relocs that it |
168 | decides to copy as dynamic relocs in check_relocs for each symbol. | |
169 | This is so that it can later discard them if they are found to be | |
170 | unnecessary. We store the information in a field extending the | |
171 | regular ELF linker hash table. */ | |
172 | ||
173 | struct ppc_elf_dyn_relocs | |
174 | { | |
175 | struct ppc_elf_dyn_relocs *next; | |
176 | ||
177 | /* The input section of the reloc. */ | |
178 | asection *sec; | |
179 | ||
180 | /* Total number of relocs copied for the input section. */ | |
181 | bfd_size_type count; | |
ee05f2fe AM |
182 | |
183 | /* Number of pc-relative relocs copied for the input section. */ | |
184 | bfd_size_type pc_count; | |
7fce784e AS |
185 | }; |
186 | ||
187 | /* PPC ELF linker hash entry. */ | |
188 | ||
189 | struct ppc_elf_link_hash_entry | |
190 | { | |
7619e7c7 | 191 | struct elf_link_hash_entry elf; |
7fce784e AS |
192 | |
193 | /* Track dynamic relocs copied for this symbol. */ | |
194 | struct ppc_elf_dyn_relocs *dyn_relocs; | |
7619e7c7 AM |
195 | |
196 | /* Contexts in which symbol is used in the GOT (or TOC). | |
197 | TLS_GD .. TLS_EXPLICIT bits are or'd into the mask as the | |
198 | corresponding relocs are encountered during check_relocs. | |
199 | tls_optimize clears TLS_GD .. TLS_TPREL when optimizing to | |
200 | indicate the corresponding GOT entry type is not needed. */ | |
201 | #define TLS_GD 1 /* GD reloc. */ | |
202 | #define TLS_LD 2 /* LD reloc. */ | |
203 | #define TLS_TPREL 4 /* TPREL reloc, => IE. */ | |
204 | #define TLS_DTPREL 8 /* DTPREL reloc, => LD. */ | |
205 | #define TLS_TLS 16 /* Any TLS reloc. */ | |
206 | #define TLS_TPRELGD 32 /* TPREL reloc resulting from GD->IE. */ | |
207 | char tls_mask; | |
7fce784e AS |
208 | }; |
209 | ||
210 | #define ppc_elf_hash_entry(ent) ((struct ppc_elf_link_hash_entry *) (ent)) | |
211 | ||
212 | /* PPC ELF linker hash table. */ | |
213 | ||
214 | struct ppc_elf_link_hash_table | |
215 | { | |
7619e7c7 AM |
216 | struct elf_link_hash_table elf; |
217 | ||
218 | /* Short-cuts to get to dynamic linker sections. */ | |
219 | asection *got; | |
220 | asection *relgot; | |
221 | asection *plt; | |
222 | asection *relplt; | |
223 | asection *dynbss; | |
224 | asection *relbss; | |
225 | asection *dynsbss; | |
226 | asection *relsbss; | |
227 | elf_linker_section_t *sdata; | |
228 | elf_linker_section_t *sdata2; | |
229 | ||
230 | /* Short-cut to first output tls section. */ | |
231 | asection *tls_sec; | |
232 | ||
233 | /* Shortcut to .__tls_get_addr. */ | |
234 | struct elf_link_hash_entry *tls_get_addr; | |
235 | ||
236 | /* TLS local dynamic got entry handling. */ | |
237 | union { | |
238 | bfd_signed_vma refcount; | |
239 | bfd_vma offset; | |
240 | } tlsld_got; | |
7fce784e AS |
241 | |
242 | /* Small local sym to section mapping cache. */ | |
243 | struct sym_sec_cache sym_sec; | |
244 | }; | |
245 | ||
246 | /* Get the PPC ELF linker hash table from a link_info structure. */ | |
247 | ||
248 | #define ppc_elf_hash_table(p) \ | |
249 | ((struct ppc_elf_link_hash_table *) (p)->hash) | |
250 | ||
251 | /* Create an entry in a PPC ELF linker hash table. */ | |
252 | ||
253 | static struct bfd_hash_entry * | |
254 | ppc_elf_link_hash_newfunc (entry, table, string) | |
255 | struct bfd_hash_entry *entry; | |
256 | struct bfd_hash_table *table; | |
257 | const char *string; | |
258 | { | |
259 | /* Allocate the structure if it has not already been allocated by a | |
260 | subclass. */ | |
261 | if (entry == NULL) | |
262 | { | |
263 | entry = bfd_hash_allocate (table, | |
264 | sizeof (struct ppc_elf_link_hash_entry)); | |
265 | if (entry == NULL) | |
266 | return entry; | |
267 | } | |
268 | ||
269 | /* Call the allocation method of the superclass. */ | |
270 | entry = _bfd_elf_link_hash_newfunc (entry, table, string); | |
271 | if (entry != NULL) | |
7619e7c7 AM |
272 | { |
273 | ppc_elf_hash_entry (entry)->dyn_relocs = NULL; | |
274 | ppc_elf_hash_entry (entry)->tls_mask = 0; | |
275 | } | |
7fce784e AS |
276 | |
277 | return entry; | |
278 | } | |
279 | ||
280 | /* Create a PPC ELF linker hash table. */ | |
281 | ||
282 | static struct bfd_link_hash_table * | |
283 | ppc_elf_link_hash_table_create (abfd) | |
284 | bfd *abfd; | |
285 | { | |
286 | struct ppc_elf_link_hash_table *ret; | |
287 | ||
288 | ret = ((struct ppc_elf_link_hash_table *) | |
289 | bfd_malloc (sizeof (struct ppc_elf_link_hash_table))); | |
290 | if (ret == NULL) | |
291 | return NULL; | |
292 | ||
7619e7c7 | 293 | if (! _bfd_elf_link_hash_table_init (&ret->elf, abfd, |
7fce784e AS |
294 | ppc_elf_link_hash_newfunc)) |
295 | { | |
296 | free (ret); | |
297 | return NULL; | |
298 | } | |
299 | ||
7619e7c7 AM |
300 | ret->got = NULL; |
301 | ret->relgot = NULL; | |
302 | ret->plt = NULL; | |
303 | ret->relplt = NULL; | |
304 | ret->dynbss = NULL; | |
305 | ret->relbss = NULL; | |
306 | ret->dynsbss = NULL; | |
307 | ret->relsbss = NULL; | |
308 | ret->sdata = NULL; | |
309 | ret->sdata2 = NULL; | |
310 | ret->tls_sec = NULL; | |
311 | ret->tls_get_addr = NULL; | |
312 | ret->tlsld_got.refcount = 0; | |
7fce784e AS |
313 | ret->sym_sec.abfd = NULL; |
314 | ||
7619e7c7 | 315 | return &ret->elf.root; |
7fce784e AS |
316 | } |
317 | ||
318 | /* Copy the extra info we tack onto an elf_link_hash_entry. */ | |
319 | ||
320 | static void | |
321 | ppc_elf_copy_indirect_symbol (bed, dir, ind) | |
322 | struct elf_backend_data *bed; | |
323 | struct elf_link_hash_entry *dir, *ind; | |
324 | { | |
325 | struct ppc_elf_link_hash_entry *edir, *eind; | |
326 | ||
327 | edir = (struct ppc_elf_link_hash_entry *) dir; | |
328 | eind = (struct ppc_elf_link_hash_entry *) ind; | |
329 | ||
330 | if (eind->dyn_relocs != NULL) | |
331 | { | |
332 | if (edir->dyn_relocs != NULL) | |
333 | { | |
334 | struct ppc_elf_dyn_relocs **pp; | |
335 | struct ppc_elf_dyn_relocs *p; | |
336 | ||
337 | if (ind->root.type == bfd_link_hash_indirect) | |
338 | abort (); | |
339 | ||
340 | /* Add reloc counts against the weak sym to the strong sym | |
341 | list. Merge any entries against the same section. */ | |
342 | for (pp = &eind->dyn_relocs; (p = *pp) != NULL; ) | |
343 | { | |
344 | struct ppc_elf_dyn_relocs *q; | |
345 | ||
346 | for (q = edir->dyn_relocs; q != NULL; q = q->next) | |
347 | if (q->sec == p->sec) | |
348 | { | |
ee05f2fe | 349 | q->pc_count += p->pc_count; |
7fce784e AS |
350 | q->count += p->count; |
351 | *pp = p->next; | |
352 | break; | |
353 | } | |
354 | if (q == NULL) | |
355 | pp = &p->next; | |
356 | } | |
357 | *pp = edir->dyn_relocs; | |
358 | } | |
359 | ||
360 | edir->dyn_relocs = eind->dyn_relocs; | |
361 | eind->dyn_relocs = NULL; | |
362 | } | |
363 | ||
7619e7c7 AM |
364 | edir->tls_mask |= eind->tls_mask; |
365 | ||
7fce784e AS |
366 | _bfd_elf_link_hash_copy_indirect (bed, dir, ind); |
367 | } | |
368 | \f | |
8da6118f | 369 | static reloc_howto_type *ppc_elf_howto_table[(int) R_PPC_max]; |
252b5132 | 370 | |
8da6118f | 371 | static reloc_howto_type ppc_elf_howto_raw[] = { |
252b5132 RH |
372 | /* This reloc does nothing. */ |
373 | HOWTO (R_PPC_NONE, /* type */ | |
374 | 0, /* rightshift */ | |
375 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
376 | 32, /* bitsize */ | |
b34976b6 | 377 | FALSE, /* pc_relative */ |
252b5132 RH |
378 | 0, /* bitpos */ |
379 | complain_overflow_bitfield, /* complain_on_overflow */ | |
380 | bfd_elf_generic_reloc, /* special_function */ | |
381 | "R_PPC_NONE", /* name */ | |
b34976b6 | 382 | FALSE, /* partial_inplace */ |
252b5132 RH |
383 | 0, /* src_mask */ |
384 | 0, /* dst_mask */ | |
b34976b6 | 385 | FALSE), /* pcrel_offset */ |
252b5132 RH |
386 | |
387 | /* A standard 32 bit relocation. */ | |
388 | HOWTO (R_PPC_ADDR32, /* type */ | |
389 | 0, /* rightshift */ | |
390 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
391 | 32, /* bitsize */ | |
b34976b6 | 392 | FALSE, /* pc_relative */ |
252b5132 RH |
393 | 0, /* bitpos */ |
394 | complain_overflow_bitfield, /* complain_on_overflow */ | |
395 | bfd_elf_generic_reloc, /* special_function */ | |
396 | "R_PPC_ADDR32", /* name */ | |
b34976b6 | 397 | FALSE, /* partial_inplace */ |
252b5132 RH |
398 | 0, /* src_mask */ |
399 | 0xffffffff, /* dst_mask */ | |
b34976b6 | 400 | FALSE), /* pcrel_offset */ |
252b5132 RH |
401 | |
402 | /* An absolute 26 bit branch; the lower two bits must be zero. | |
403 | FIXME: we don't check that, we just clear them. */ | |
404 | HOWTO (R_PPC_ADDR24, /* type */ | |
405 | 0, /* rightshift */ | |
406 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
407 | 26, /* 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_ADDR24", /* name */ | |
b34976b6 | 413 | FALSE, /* partial_inplace */ |
252b5132 RH |
414 | 0, /* src_mask */ |
415 | 0x3fffffc, /* dst_mask */ | |
b34976b6 | 416 | FALSE), /* pcrel_offset */ |
252b5132 RH |
417 | |
418 | /* A standard 16 bit relocation. */ | |
419 | HOWTO (R_PPC_ADDR16, /* type */ | |
420 | 0, /* rightshift */ | |
421 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
422 | 16, /* bitsize */ | |
b34976b6 | 423 | FALSE, /* pc_relative */ |
252b5132 RH |
424 | 0, /* bitpos */ |
425 | complain_overflow_bitfield, /* complain_on_overflow */ | |
426 | bfd_elf_generic_reloc, /* special_function */ | |
427 | "R_PPC_ADDR16", /* name */ | |
b34976b6 | 428 | FALSE, /* partial_inplace */ |
252b5132 RH |
429 | 0, /* src_mask */ |
430 | 0xffff, /* dst_mask */ | |
b34976b6 | 431 | FALSE), /* pcrel_offset */ |
252b5132 RH |
432 | |
433 | /* A 16 bit relocation without overflow. */ | |
434 | HOWTO (R_PPC_ADDR16_LO, /* type */ | |
435 | 0, /* rightshift */ | |
436 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
437 | 16, /* bitsize */ | |
b34976b6 | 438 | FALSE, /* pc_relative */ |
252b5132 RH |
439 | 0, /* bitpos */ |
440 | complain_overflow_dont,/* complain_on_overflow */ | |
441 | bfd_elf_generic_reloc, /* special_function */ | |
442 | "R_PPC_ADDR16_LO", /* name */ | |
b34976b6 | 443 | FALSE, /* partial_inplace */ |
252b5132 RH |
444 | 0, /* src_mask */ |
445 | 0xffff, /* dst_mask */ | |
b34976b6 | 446 | FALSE), /* pcrel_offset */ |
252b5132 RH |
447 | |
448 | /* The high order 16 bits of an address. */ | |
449 | HOWTO (R_PPC_ADDR16_HI, /* type */ | |
450 | 16, /* rightshift */ | |
451 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
452 | 16, /* bitsize */ | |
b34976b6 | 453 | FALSE, /* pc_relative */ |
252b5132 RH |
454 | 0, /* bitpos */ |
455 | complain_overflow_dont, /* complain_on_overflow */ | |
456 | bfd_elf_generic_reloc, /* special_function */ | |
457 | "R_PPC_ADDR16_HI", /* name */ | |
b34976b6 | 458 | FALSE, /* partial_inplace */ |
252b5132 RH |
459 | 0, /* src_mask */ |
460 | 0xffff, /* dst_mask */ | |
b34976b6 | 461 | FALSE), /* pcrel_offset */ |
252b5132 RH |
462 | |
463 | /* The high order 16 bits of an address, plus 1 if the contents of | |
8da6118f | 464 | the low 16 bits, treated as a signed number, is negative. */ |
252b5132 RH |
465 | HOWTO (R_PPC_ADDR16_HA, /* type */ |
466 | 16, /* rightshift */ | |
467 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
468 | 16, /* bitsize */ | |
b34976b6 | 469 | FALSE, /* pc_relative */ |
252b5132 RH |
470 | 0, /* bitpos */ |
471 | complain_overflow_dont, /* complain_on_overflow */ | |
472 | ppc_elf_addr16_ha_reloc, /* special_function */ | |
473 | "R_PPC_ADDR16_HA", /* name */ | |
b34976b6 | 474 | FALSE, /* partial_inplace */ |
252b5132 RH |
475 | 0, /* src_mask */ |
476 | 0xffff, /* dst_mask */ | |
b34976b6 | 477 | FALSE), /* pcrel_offset */ |
252b5132 RH |
478 | |
479 | /* An absolute 16 bit branch; the lower two bits must be zero. | |
480 | FIXME: we don't check that, we just clear them. */ | |
481 | HOWTO (R_PPC_ADDR14, /* type */ | |
482 | 0, /* rightshift */ | |
483 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
484 | 16, /* bitsize */ | |
b34976b6 | 485 | FALSE, /* pc_relative */ |
252b5132 RH |
486 | 0, /* bitpos */ |
487 | complain_overflow_bitfield, /* complain_on_overflow */ | |
488 | bfd_elf_generic_reloc, /* special_function */ | |
489 | "R_PPC_ADDR14", /* name */ | |
b34976b6 | 490 | FALSE, /* partial_inplace */ |
252b5132 RH |
491 | 0, /* src_mask */ |
492 | 0xfffc, /* dst_mask */ | |
b34976b6 | 493 | FALSE), /* pcrel_offset */ |
252b5132 RH |
494 | |
495 | /* An absolute 16 bit branch, for which bit 10 should be set to | |
496 | indicate that the branch is expected to be taken. The lower two | |
8da6118f | 497 | bits must be zero. */ |
252b5132 RH |
498 | HOWTO (R_PPC_ADDR14_BRTAKEN, /* type */ |
499 | 0, /* rightshift */ | |
500 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
501 | 16, /* bitsize */ | |
b34976b6 | 502 | FALSE, /* pc_relative */ |
252b5132 RH |
503 | 0, /* bitpos */ |
504 | complain_overflow_bitfield, /* complain_on_overflow */ | |
505 | bfd_elf_generic_reloc, /* special_function */ | |
506 | "R_PPC_ADDR14_BRTAKEN",/* name */ | |
b34976b6 | 507 | FALSE, /* partial_inplace */ |
252b5132 RH |
508 | 0, /* src_mask */ |
509 | 0xfffc, /* dst_mask */ | |
b34976b6 | 510 | FALSE), /* pcrel_offset */ |
252b5132 RH |
511 | |
512 | /* An absolute 16 bit branch, for which bit 10 should be set to | |
513 | indicate that the branch is not expected to be taken. The lower | |
514 | two bits must be zero. */ | |
515 | HOWTO (R_PPC_ADDR14_BRNTAKEN, /* type */ | |
516 | 0, /* rightshift */ | |
517 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
518 | 16, /* bitsize */ | |
b34976b6 | 519 | FALSE, /* pc_relative */ |
252b5132 RH |
520 | 0, /* bitpos */ |
521 | complain_overflow_bitfield, /* complain_on_overflow */ | |
522 | bfd_elf_generic_reloc, /* special_function */ | |
523 | "R_PPC_ADDR14_BRNTAKEN",/* name */ | |
b34976b6 | 524 | FALSE, /* partial_inplace */ |
252b5132 RH |
525 | 0, /* src_mask */ |
526 | 0xfffc, /* dst_mask */ | |
b34976b6 | 527 | FALSE), /* pcrel_offset */ |
252b5132 | 528 | |
8da6118f | 529 | /* A relative 26 bit branch; the lower two bits must be zero. */ |
252b5132 RH |
530 | HOWTO (R_PPC_REL24, /* type */ |
531 | 0, /* rightshift */ | |
532 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
533 | 26, /* bitsize */ | |
b34976b6 | 534 | TRUE, /* pc_relative */ |
252b5132 RH |
535 | 0, /* bitpos */ |
536 | complain_overflow_signed, /* complain_on_overflow */ | |
537 | bfd_elf_generic_reloc, /* special_function */ | |
538 | "R_PPC_REL24", /* name */ | |
b34976b6 | 539 | FALSE, /* partial_inplace */ |
252b5132 RH |
540 | 0, /* src_mask */ |
541 | 0x3fffffc, /* dst_mask */ | |
b34976b6 | 542 | TRUE), /* pcrel_offset */ |
252b5132 | 543 | |
8da6118f | 544 | /* A relative 16 bit branch; the lower two bits must be zero. */ |
252b5132 RH |
545 | HOWTO (R_PPC_REL14, /* type */ |
546 | 0, /* rightshift */ | |
547 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
548 | 16, /* bitsize */ | |
b34976b6 | 549 | TRUE, /* pc_relative */ |
252b5132 RH |
550 | 0, /* bitpos */ |
551 | complain_overflow_signed, /* complain_on_overflow */ | |
552 | bfd_elf_generic_reloc, /* special_function */ | |
553 | "R_PPC_REL14", /* name */ | |
b34976b6 | 554 | FALSE, /* partial_inplace */ |
252b5132 RH |
555 | 0, /* src_mask */ |
556 | 0xfffc, /* dst_mask */ | |
b34976b6 | 557 | TRUE), /* pcrel_offset */ |
252b5132 | 558 | |
8da6118f | 559 | /* A relative 16 bit branch. Bit 10 should be set to indicate that |
252b5132 RH |
560 | the branch is expected to be taken. The lower two bits must be |
561 | zero. */ | |
562 | HOWTO (R_PPC_REL14_BRTAKEN, /* type */ | |
563 | 0, /* rightshift */ | |
564 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
565 | 16, /* bitsize */ | |
b34976b6 | 566 | TRUE, /* pc_relative */ |
252b5132 RH |
567 | 0, /* bitpos */ |
568 | complain_overflow_signed, /* complain_on_overflow */ | |
569 | bfd_elf_generic_reloc, /* special_function */ | |
570 | "R_PPC_REL14_BRTAKEN", /* name */ | |
b34976b6 | 571 | FALSE, /* partial_inplace */ |
252b5132 RH |
572 | 0, /* src_mask */ |
573 | 0xfffc, /* dst_mask */ | |
b34976b6 | 574 | TRUE), /* pcrel_offset */ |
252b5132 | 575 | |
8da6118f | 576 | /* A relative 16 bit branch. Bit 10 should be set to indicate that |
252b5132 RH |
577 | the branch is not expected to be taken. The lower two bits must |
578 | be zero. */ | |
579 | HOWTO (R_PPC_REL14_BRNTAKEN, /* type */ | |
580 | 0, /* rightshift */ | |
581 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
582 | 16, /* bitsize */ | |
b34976b6 | 583 | TRUE, /* pc_relative */ |
252b5132 RH |
584 | 0, /* bitpos */ |
585 | complain_overflow_signed, /* complain_on_overflow */ | |
586 | bfd_elf_generic_reloc, /* special_function */ | |
587 | "R_PPC_REL14_BRNTAKEN",/* name */ | |
b34976b6 | 588 | FALSE, /* partial_inplace */ |
252b5132 RH |
589 | 0, /* src_mask */ |
590 | 0xfffc, /* dst_mask */ | |
b34976b6 | 591 | TRUE), /* pcrel_offset */ |
252b5132 RH |
592 | |
593 | /* Like R_PPC_ADDR16, but referring to the GOT table entry for the | |
594 | symbol. */ | |
595 | HOWTO (R_PPC_GOT16, /* type */ | |
596 | 0, /* rightshift */ | |
597 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
598 | 16, /* bitsize */ | |
b34976b6 | 599 | FALSE, /* pc_relative */ |
252b5132 RH |
600 | 0, /* bitpos */ |
601 | complain_overflow_signed, /* complain_on_overflow */ | |
602 | bfd_elf_generic_reloc, /* special_function */ | |
603 | "R_PPC_GOT16", /* name */ | |
b34976b6 | 604 | FALSE, /* partial_inplace */ |
252b5132 RH |
605 | 0, /* src_mask */ |
606 | 0xffff, /* dst_mask */ | |
b34976b6 | 607 | FALSE), /* pcrel_offset */ |
252b5132 RH |
608 | |
609 | /* Like R_PPC_ADDR16_LO, but referring to the GOT table entry for | |
610 | the symbol. */ | |
611 | HOWTO (R_PPC_GOT16_LO, /* type */ | |
612 | 0, /* rightshift */ | |
613 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
614 | 16, /* bitsize */ | |
b34976b6 | 615 | FALSE, /* pc_relative */ |
252b5132 RH |
616 | 0, /* bitpos */ |
617 | complain_overflow_dont, /* complain_on_overflow */ | |
618 | bfd_elf_generic_reloc, /* special_function */ | |
619 | "R_PPC_GOT16_LO", /* name */ | |
b34976b6 | 620 | FALSE, /* partial_inplace */ |
252b5132 RH |
621 | 0, /* src_mask */ |
622 | 0xffff, /* dst_mask */ | |
b34976b6 | 623 | FALSE), /* pcrel_offset */ |
252b5132 RH |
624 | |
625 | /* Like R_PPC_ADDR16_HI, but referring to the GOT table entry for | |
626 | the symbol. */ | |
627 | HOWTO (R_PPC_GOT16_HI, /* type */ | |
628 | 16, /* rightshift */ | |
629 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
630 | 16, /* bitsize */ | |
b34976b6 | 631 | FALSE, /* pc_relative */ |
252b5132 RH |
632 | 0, /* bitpos */ |
633 | complain_overflow_bitfield, /* complain_on_overflow */ | |
634 | bfd_elf_generic_reloc, /* special_function */ | |
635 | "R_PPC_GOT16_HI", /* name */ | |
b34976b6 | 636 | FALSE, /* partial_inplace */ |
252b5132 RH |
637 | 0, /* src_mask */ |
638 | 0xffff, /* dst_mask */ | |
b34976b6 | 639 | FALSE), /* pcrel_offset */ |
252b5132 RH |
640 | |
641 | /* Like R_PPC_ADDR16_HA, but referring to the GOT table entry for | |
642 | the symbol. */ | |
643 | HOWTO (R_PPC_GOT16_HA, /* type */ | |
644 | 16, /* rightshift */ | |
645 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
646 | 16, /* bitsize */ | |
b34976b6 | 647 | FALSE, /* pc_relative */ |
252b5132 RH |
648 | 0, /* bitpos */ |
649 | complain_overflow_bitfield, /* complain_on_overflow */ | |
650 | ppc_elf_addr16_ha_reloc, /* special_function */ | |
651 | "R_PPC_GOT16_HA", /* name */ | |
b34976b6 | 652 | FALSE, /* partial_inplace */ |
252b5132 RH |
653 | 0, /* src_mask */ |
654 | 0xffff, /* dst_mask */ | |
b34976b6 | 655 | FALSE), /* pcrel_offset */ |
252b5132 RH |
656 | |
657 | /* Like R_PPC_REL24, but referring to the procedure linkage table | |
658 | entry for the symbol. */ | |
659 | HOWTO (R_PPC_PLTREL24, /* type */ | |
660 | 0, /* rightshift */ | |
661 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
662 | 26, /* bitsize */ | |
b34976b6 | 663 | TRUE, /* pc_relative */ |
252b5132 RH |
664 | 0, /* bitpos */ |
665 | complain_overflow_signed, /* complain_on_overflow */ | |
666 | bfd_elf_generic_reloc, /* special_function */ | |
667 | "R_PPC_PLTREL24", /* name */ | |
b34976b6 | 668 | FALSE, /* partial_inplace */ |
252b5132 RH |
669 | 0, /* src_mask */ |
670 | 0x3fffffc, /* dst_mask */ | |
b34976b6 | 671 | TRUE), /* pcrel_offset */ |
252b5132 RH |
672 | |
673 | /* This is used only by the dynamic linker. The symbol should exist | |
674 | both in the object being run and in some shared library. The | |
675 | dynamic linker copies the data addressed by the symbol from the | |
676 | shared library into the object, because the object being | |
677 | run has to have the data at some particular address. */ | |
678 | HOWTO (R_PPC_COPY, /* type */ | |
679 | 0, /* rightshift */ | |
680 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
681 | 32, /* bitsize */ | |
b34976b6 | 682 | FALSE, /* pc_relative */ |
252b5132 RH |
683 | 0, /* bitpos */ |
684 | complain_overflow_bitfield, /* complain_on_overflow */ | |
685 | bfd_elf_generic_reloc, /* special_function */ | |
686 | "R_PPC_COPY", /* name */ | |
b34976b6 | 687 | FALSE, /* partial_inplace */ |
252b5132 RH |
688 | 0, /* src_mask */ |
689 | 0, /* dst_mask */ | |
b34976b6 | 690 | FALSE), /* pcrel_offset */ |
252b5132 RH |
691 | |
692 | /* Like R_PPC_ADDR32, but used when setting global offset table | |
693 | entries. */ | |
694 | HOWTO (R_PPC_GLOB_DAT, /* type */ | |
695 | 0, /* rightshift */ | |
696 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
697 | 32, /* bitsize */ | |
b34976b6 | 698 | FALSE, /* pc_relative */ |
252b5132 RH |
699 | 0, /* bitpos */ |
700 | complain_overflow_bitfield, /* complain_on_overflow */ | |
701 | bfd_elf_generic_reloc, /* special_function */ | |
702 | "R_PPC_GLOB_DAT", /* name */ | |
b34976b6 | 703 | FALSE, /* partial_inplace */ |
252b5132 RH |
704 | 0, /* src_mask */ |
705 | 0xffffffff, /* dst_mask */ | |
b34976b6 | 706 | FALSE), /* pcrel_offset */ |
252b5132 RH |
707 | |
708 | /* Marks a procedure linkage table entry for a symbol. */ | |
709 | HOWTO (R_PPC_JMP_SLOT, /* type */ | |
710 | 0, /* rightshift */ | |
711 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
712 | 32, /* bitsize */ | |
b34976b6 | 713 | FALSE, /* pc_relative */ |
252b5132 RH |
714 | 0, /* bitpos */ |
715 | complain_overflow_bitfield, /* complain_on_overflow */ | |
716 | bfd_elf_generic_reloc, /* special_function */ | |
717 | "R_PPC_JMP_SLOT", /* name */ | |
b34976b6 | 718 | FALSE, /* partial_inplace */ |
252b5132 RH |
719 | 0, /* src_mask */ |
720 | 0, /* dst_mask */ | |
b34976b6 | 721 | FALSE), /* pcrel_offset */ |
252b5132 RH |
722 | |
723 | /* Used only by the dynamic linker. When the object is run, this | |
724 | longword is set to the load address of the object, plus the | |
725 | addend. */ | |
726 | HOWTO (R_PPC_RELATIVE, /* type */ | |
727 | 0, /* rightshift */ | |
728 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
729 | 32, /* bitsize */ | |
b34976b6 | 730 | FALSE, /* pc_relative */ |
252b5132 RH |
731 | 0, /* bitpos */ |
732 | complain_overflow_bitfield, /* complain_on_overflow */ | |
733 | bfd_elf_generic_reloc, /* special_function */ | |
734 | "R_PPC_RELATIVE", /* name */ | |
b34976b6 | 735 | FALSE, /* partial_inplace */ |
252b5132 RH |
736 | 0, /* src_mask */ |
737 | 0xffffffff, /* dst_mask */ | |
b34976b6 | 738 | FALSE), /* pcrel_offset */ |
252b5132 RH |
739 | |
740 | /* Like R_PPC_REL24, but uses the value of the symbol within the | |
741 | object rather than the final value. Normally used for | |
742 | _GLOBAL_OFFSET_TABLE_. */ | |
743 | HOWTO (R_PPC_LOCAL24PC, /* type */ | |
744 | 0, /* rightshift */ | |
745 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
746 | 26, /* bitsize */ | |
b34976b6 | 747 | TRUE, /* pc_relative */ |
252b5132 RH |
748 | 0, /* bitpos */ |
749 | complain_overflow_signed, /* complain_on_overflow */ | |
750 | bfd_elf_generic_reloc, /* special_function */ | |
751 | "R_PPC_LOCAL24PC", /* name */ | |
b34976b6 | 752 | FALSE, /* partial_inplace */ |
252b5132 RH |
753 | 0, /* src_mask */ |
754 | 0x3fffffc, /* dst_mask */ | |
b34976b6 | 755 | TRUE), /* pcrel_offset */ |
252b5132 RH |
756 | |
757 | /* Like R_PPC_ADDR32, but may be unaligned. */ | |
758 | HOWTO (R_PPC_UADDR32, /* type */ | |
759 | 0, /* rightshift */ | |
760 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
761 | 32, /* bitsize */ | |
b34976b6 | 762 | FALSE, /* pc_relative */ |
252b5132 RH |
763 | 0, /* bitpos */ |
764 | complain_overflow_bitfield, /* complain_on_overflow */ | |
765 | bfd_elf_generic_reloc, /* special_function */ | |
766 | "R_PPC_UADDR32", /* name */ | |
b34976b6 | 767 | FALSE, /* partial_inplace */ |
252b5132 RH |
768 | 0, /* src_mask */ |
769 | 0xffffffff, /* dst_mask */ | |
b34976b6 | 770 | FALSE), /* pcrel_offset */ |
252b5132 RH |
771 | |
772 | /* Like R_PPC_ADDR16, but may be unaligned. */ | |
773 | HOWTO (R_PPC_UADDR16, /* type */ | |
774 | 0, /* rightshift */ | |
775 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
776 | 16, /* bitsize */ | |
b34976b6 | 777 | FALSE, /* pc_relative */ |
252b5132 RH |
778 | 0, /* bitpos */ |
779 | complain_overflow_bitfield, /* complain_on_overflow */ | |
780 | bfd_elf_generic_reloc, /* special_function */ | |
781 | "R_PPC_UADDR16", /* name */ | |
b34976b6 | 782 | FALSE, /* partial_inplace */ |
252b5132 RH |
783 | 0, /* src_mask */ |
784 | 0xffff, /* dst_mask */ | |
b34976b6 | 785 | FALSE), /* pcrel_offset */ |
252b5132 RH |
786 | |
787 | /* 32-bit PC relative */ | |
788 | HOWTO (R_PPC_REL32, /* type */ | |
789 | 0, /* rightshift */ | |
790 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
791 | 32, /* bitsize */ | |
b34976b6 | 792 | TRUE, /* pc_relative */ |
252b5132 RH |
793 | 0, /* bitpos */ |
794 | complain_overflow_bitfield, /* complain_on_overflow */ | |
795 | bfd_elf_generic_reloc, /* special_function */ | |
796 | "R_PPC_REL32", /* name */ | |
b34976b6 | 797 | FALSE, /* partial_inplace */ |
252b5132 RH |
798 | 0, /* src_mask */ |
799 | 0xffffffff, /* dst_mask */ | |
b34976b6 | 800 | TRUE), /* pcrel_offset */ |
252b5132 RH |
801 | |
802 | /* 32-bit relocation to the symbol's procedure linkage table. | |
c3668558 | 803 | FIXME: not supported. */ |
252b5132 RH |
804 | HOWTO (R_PPC_PLT32, /* type */ |
805 | 0, /* rightshift */ | |
806 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
807 | 32, /* bitsize */ | |
b34976b6 | 808 | FALSE, /* pc_relative */ |
252b5132 RH |
809 | 0, /* bitpos */ |
810 | complain_overflow_bitfield, /* complain_on_overflow */ | |
811 | bfd_elf_generic_reloc, /* special_function */ | |
812 | "R_PPC_PLT32", /* name */ | |
b34976b6 | 813 | FALSE, /* partial_inplace */ |
252b5132 RH |
814 | 0, /* src_mask */ |
815 | 0, /* dst_mask */ | |
b34976b6 | 816 | FALSE), /* pcrel_offset */ |
252b5132 RH |
817 | |
818 | /* 32-bit PC relative relocation to the symbol's procedure linkage table. | |
c3668558 | 819 | FIXME: not supported. */ |
252b5132 RH |
820 | HOWTO (R_PPC_PLTREL32, /* type */ |
821 | 0, /* rightshift */ | |
822 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
823 | 32, /* bitsize */ | |
b34976b6 | 824 | TRUE, /* pc_relative */ |
252b5132 RH |
825 | 0, /* bitpos */ |
826 | complain_overflow_bitfield, /* complain_on_overflow */ | |
827 | bfd_elf_generic_reloc, /* special_function */ | |
828 | "R_PPC_PLTREL32", /* name */ | |
b34976b6 | 829 | FALSE, /* partial_inplace */ |
252b5132 RH |
830 | 0, /* src_mask */ |
831 | 0, /* dst_mask */ | |
b34976b6 | 832 | TRUE), /* pcrel_offset */ |
252b5132 RH |
833 | |
834 | /* Like R_PPC_ADDR16_LO, but referring to the PLT table entry for | |
835 | the symbol. */ | |
836 | HOWTO (R_PPC_PLT16_LO, /* type */ | |
837 | 0, /* rightshift */ | |
838 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
839 | 16, /* bitsize */ | |
b34976b6 | 840 | FALSE, /* pc_relative */ |
252b5132 RH |
841 | 0, /* bitpos */ |
842 | complain_overflow_dont, /* complain_on_overflow */ | |
843 | bfd_elf_generic_reloc, /* special_function */ | |
844 | "R_PPC_PLT16_LO", /* name */ | |
b34976b6 | 845 | FALSE, /* partial_inplace */ |
252b5132 RH |
846 | 0, /* src_mask */ |
847 | 0xffff, /* dst_mask */ | |
b34976b6 | 848 | FALSE), /* pcrel_offset */ |
252b5132 RH |
849 | |
850 | /* Like R_PPC_ADDR16_HI, but referring to the PLT table entry for | |
851 | the symbol. */ | |
852 | HOWTO (R_PPC_PLT16_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_PLT16_HI", /* name */ | |
b34976b6 | 861 | FALSE, /* partial_inplace */ |
252b5132 RH |
862 | 0, /* src_mask */ |
863 | 0xffff, /* dst_mask */ | |
b34976b6 | 864 | FALSE), /* pcrel_offset */ |
252b5132 RH |
865 | |
866 | /* Like R_PPC_ADDR16_HA, but referring to the PLT table entry for | |
867 | the symbol. */ | |
868 | HOWTO (R_PPC_PLT16_HA, /* type */ | |
869 | 16, /* rightshift */ | |
870 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
871 | 16, /* bitsize */ | |
b34976b6 | 872 | FALSE, /* pc_relative */ |
252b5132 RH |
873 | 0, /* bitpos */ |
874 | complain_overflow_bitfield, /* complain_on_overflow */ | |
875 | ppc_elf_addr16_ha_reloc, /* special_function */ | |
876 | "R_PPC_PLT16_HA", /* name */ | |
b34976b6 | 877 | FALSE, /* partial_inplace */ |
252b5132 RH |
878 | 0, /* src_mask */ |
879 | 0xffff, /* dst_mask */ | |
b34976b6 | 880 | FALSE), /* pcrel_offset */ |
252b5132 RH |
881 | |
882 | /* A sign-extended 16 bit value relative to _SDA_BASE_, for use with | |
883 | small data items. */ | |
884 | HOWTO (R_PPC_SDAREL16, /* type */ | |
885 | 0, /* rightshift */ | |
886 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
887 | 16, /* bitsize */ | |
b34976b6 | 888 | FALSE, /* pc_relative */ |
252b5132 RH |
889 | 0, /* bitpos */ |
890 | complain_overflow_signed, /* complain_on_overflow */ | |
891 | bfd_elf_generic_reloc, /* special_function */ | |
892 | "R_PPC_SDAREL16", /* name */ | |
b34976b6 | 893 | FALSE, /* partial_inplace */ |
252b5132 RH |
894 | 0, /* src_mask */ |
895 | 0xffff, /* dst_mask */ | |
b34976b6 | 896 | FALSE), /* pcrel_offset */ |
252b5132 | 897 | |
c061c2d8 | 898 | /* 16-bit section relative relocation. */ |
252b5132 RH |
899 | HOWTO (R_PPC_SECTOFF, /* type */ |
900 | 0, /* rightshift */ | |
c061c2d8 AM |
901 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
902 | 16, /* bitsize */ | |
b34976b6 | 903 | FALSE, /* pc_relative */ |
252b5132 RH |
904 | 0, /* bitpos */ |
905 | complain_overflow_bitfield, /* complain_on_overflow */ | |
906 | bfd_elf_generic_reloc, /* special_function */ | |
907 | "R_PPC_SECTOFF", /* name */ | |
b34976b6 | 908 | FALSE, /* partial_inplace */ |
252b5132 | 909 | 0, /* src_mask */ |
c061c2d8 | 910 | 0xffff, /* dst_mask */ |
b34976b6 | 911 | FALSE), /* pcrel_offset */ |
252b5132 | 912 | |
c3668558 | 913 | /* 16-bit lower half section relative relocation. */ |
252b5132 RH |
914 | HOWTO (R_PPC_SECTOFF_LO, /* type */ |
915 | 0, /* rightshift */ | |
916 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
917 | 16, /* bitsize */ | |
b34976b6 | 918 | FALSE, /* pc_relative */ |
252b5132 RH |
919 | 0, /* bitpos */ |
920 | complain_overflow_dont, /* complain_on_overflow */ | |
921 | bfd_elf_generic_reloc, /* special_function */ | |
922 | "R_PPC_SECTOFF_LO", /* name */ | |
b34976b6 | 923 | FALSE, /* partial_inplace */ |
252b5132 RH |
924 | 0, /* src_mask */ |
925 | 0xffff, /* dst_mask */ | |
b34976b6 | 926 | FALSE), /* pcrel_offset */ |
252b5132 | 927 | |
c3668558 | 928 | /* 16-bit upper half section relative relocation. */ |
252b5132 RH |
929 | HOWTO (R_PPC_SECTOFF_HI, /* type */ |
930 | 16, /* rightshift */ | |
931 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
932 | 16, /* bitsize */ | |
b34976b6 | 933 | FALSE, /* pc_relative */ |
252b5132 RH |
934 | 0, /* bitpos */ |
935 | complain_overflow_bitfield, /* complain_on_overflow */ | |
936 | bfd_elf_generic_reloc, /* special_function */ | |
937 | "R_PPC_SECTOFF_HI", /* name */ | |
b34976b6 | 938 | FALSE, /* partial_inplace */ |
252b5132 RH |
939 | 0, /* src_mask */ |
940 | 0xffff, /* dst_mask */ | |
b34976b6 | 941 | FALSE), /* pcrel_offset */ |
252b5132 | 942 | |
c3668558 | 943 | /* 16-bit upper half adjusted section relative relocation. */ |
252b5132 RH |
944 | HOWTO (R_PPC_SECTOFF_HA, /* type */ |
945 | 16, /* rightshift */ | |
946 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
947 | 16, /* bitsize */ | |
b34976b6 | 948 | FALSE, /* pc_relative */ |
252b5132 RH |
949 | 0, /* bitpos */ |
950 | complain_overflow_bitfield, /* complain_on_overflow */ | |
951 | ppc_elf_addr16_ha_reloc, /* special_function */ | |
952 | "R_PPC_SECTOFF_HA", /* name */ | |
b34976b6 | 953 | FALSE, /* partial_inplace */ |
252b5132 RH |
954 | 0, /* src_mask */ |
955 | 0xffff, /* dst_mask */ | |
b34976b6 | 956 | FALSE), /* pcrel_offset */ |
252b5132 | 957 | |
7619e7c7 AM |
958 | /* Marker reloc for TLS. */ |
959 | HOWTO (R_PPC_TLS, | |
252b5132 RH |
960 | 0, /* rightshift */ |
961 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
962 | 32, /* bitsize */ | |
b34976b6 | 963 | FALSE, /* pc_relative */ |
252b5132 | 964 | 0, /* bitpos */ |
7619e7c7 | 965 | complain_overflow_dont, /* complain_on_overflow */ |
252b5132 | 966 | bfd_elf_generic_reloc, /* special_function */ |
7619e7c7 AM |
967 | "R_PPC_TLS", /* name */ |
968 | FALSE, /* partial_inplace */ | |
969 | 0, /* src_mask */ | |
970 | 0, /* dst_mask */ | |
971 | FALSE), /* pcrel_offset */ | |
972 | ||
973 | /* Computes the load module index of the load module that contains the | |
974 | definition of its TLS sym. */ | |
975 | HOWTO (R_PPC_DTPMOD32, | |
976 | 0, /* rightshift */ | |
977 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
978 | 32, /* bitsize */ | |
979 | FALSE, /* pc_relative */ | |
980 | 0, /* bitpos */ | |
981 | complain_overflow_dont, /* complain_on_overflow */ | |
982 | ppc_elf_unhandled_reloc, /* special_function */ | |
983 | "R_PPC_DTPMOD32", /* name */ | |
b34976b6 | 984 | FALSE, /* partial_inplace */ |
252b5132 RH |
985 | 0, /* src_mask */ |
986 | 0xffffffff, /* dst_mask */ | |
b34976b6 | 987 | FALSE), /* pcrel_offset */ |
252b5132 | 988 | |
7619e7c7 AM |
989 | /* Computes a dtv-relative displacement, the difference between the value |
990 | of sym+add and the base address of the thread-local storage block that | |
991 | contains the definition of sym, minus 0x8000. */ | |
992 | HOWTO (R_PPC_DTPREL32, | |
993 | 0, /* rightshift */ | |
994 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
995 | 32, /* bitsize */ | |
996 | FALSE, /* pc_relative */ | |
997 | 0, /* bitpos */ | |
998 | complain_overflow_dont, /* complain_on_overflow */ | |
999 | ppc_elf_unhandled_reloc, /* special_function */ | |
1000 | "R_PPC_DTPREL32", /* name */ | |
1001 | FALSE, /* partial_inplace */ | |
1002 | 0, /* src_mask */ | |
1003 | 0xffffffff, /* dst_mask */ | |
1004 | FALSE), /* pcrel_offset */ | |
1005 | ||
1006 | /* A 16 bit dtprel reloc. */ | |
1007 | HOWTO (R_PPC_DTPREL16, | |
252b5132 RH |
1008 | 0, /* rightshift */ |
1009 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1010 | 16, /* bitsize */ | |
b34976b6 | 1011 | FALSE, /* pc_relative */ |
252b5132 | 1012 | 0, /* bitpos */ |
7619e7c7 AM |
1013 | complain_overflow_signed, /* complain_on_overflow */ |
1014 | ppc_elf_unhandled_reloc, /* special_function */ | |
1015 | "R_PPC_DTPREL16", /* name */ | |
b34976b6 | 1016 | FALSE, /* partial_inplace */ |
252b5132 RH |
1017 | 0, /* src_mask */ |
1018 | 0xffff, /* dst_mask */ | |
b34976b6 | 1019 | FALSE), /* pcrel_offset */ |
252b5132 | 1020 | |
7619e7c7 AM |
1021 | /* Like DTPREL16, but no overflow. */ |
1022 | HOWTO (R_PPC_DTPREL16_LO, | |
252b5132 RH |
1023 | 0, /* rightshift */ |
1024 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1025 | 16, /* bitsize */ | |
b34976b6 | 1026 | FALSE, /* pc_relative */ |
252b5132 | 1027 | 0, /* bitpos */ |
7619e7c7 AM |
1028 | complain_overflow_dont, /* complain_on_overflow */ |
1029 | ppc_elf_unhandled_reloc, /* special_function */ | |
1030 | "R_PPC_DTPREL16_LO", /* name */ | |
b34976b6 | 1031 | FALSE, /* partial_inplace */ |
252b5132 RH |
1032 | 0, /* src_mask */ |
1033 | 0xffff, /* dst_mask */ | |
b34976b6 | 1034 | FALSE), /* pcrel_offset */ |
252b5132 | 1035 | |
7619e7c7 AM |
1036 | /* Like DTPREL16_LO, but next higher group of 16 bits. */ |
1037 | HOWTO (R_PPC_DTPREL16_HI, | |
252b5132 RH |
1038 | 16, /* rightshift */ |
1039 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1040 | 16, /* bitsize */ | |
b34976b6 | 1041 | FALSE, /* pc_relative */ |
252b5132 RH |
1042 | 0, /* bitpos */ |
1043 | complain_overflow_dont, /* complain_on_overflow */ | |
7619e7c7 AM |
1044 | ppc_elf_unhandled_reloc, /* special_function */ |
1045 | "R_PPC_DTPREL16_HI", /* name */ | |
b34976b6 | 1046 | FALSE, /* partial_inplace */ |
252b5132 RH |
1047 | 0, /* src_mask */ |
1048 | 0xffff, /* dst_mask */ | |
b34976b6 | 1049 | FALSE), /* pcrel_offset */ |
252b5132 | 1050 | |
7619e7c7 AM |
1051 | /* Like DTPREL16_HI, but adjust for low 16 bits. */ |
1052 | HOWTO (R_PPC_DTPREL16_HA, | |
252b5132 RH |
1053 | 16, /* rightshift */ |
1054 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1055 | 16, /* bitsize */ | |
b34976b6 | 1056 | FALSE, /* pc_relative */ |
252b5132 RH |
1057 | 0, /* bitpos */ |
1058 | complain_overflow_dont, /* complain_on_overflow */ | |
7619e7c7 AM |
1059 | ppc_elf_unhandled_reloc, /* special_function */ |
1060 | "R_PPC_DTPREL16_HA", /* name */ | |
b34976b6 | 1061 | FALSE, /* partial_inplace */ |
252b5132 RH |
1062 | 0, /* src_mask */ |
1063 | 0xffff, /* dst_mask */ | |
b34976b6 | 1064 | FALSE), /* pcrel_offset */ |
252b5132 | 1065 | |
7619e7c7 AM |
1066 | /* Computes a tp-relative displacement, the difference between the value of |
1067 | sym+add and the value of the thread pointer (r13). */ | |
1068 | HOWTO (R_PPC_TPREL32, | |
1069 | 0, /* rightshift */ | |
1070 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1071 | 32, /* bitsize */ | |
1072 | FALSE, /* pc_relative */ | |
1073 | 0, /* bitpos */ | |
1074 | complain_overflow_dont, /* complain_on_overflow */ | |
1075 | ppc_elf_unhandled_reloc, /* special_function */ | |
1076 | "R_PPC_TPREL32", /* name */ | |
1077 | FALSE, /* partial_inplace */ | |
1078 | 0, /* src_mask */ | |
1079 | 0xffffffff, /* dst_mask */ | |
1080 | FALSE), /* pcrel_offset */ | |
1081 | ||
1082 | /* A 16 bit tprel reloc. */ | |
1083 | HOWTO (R_PPC_TPREL16, | |
252b5132 RH |
1084 | 0, /* rightshift */ |
1085 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1086 | 16, /* bitsize */ | |
b34976b6 | 1087 | FALSE, /* pc_relative */ |
252b5132 | 1088 | 0, /* bitpos */ |
7619e7c7 AM |
1089 | complain_overflow_signed, /* complain_on_overflow */ |
1090 | ppc_elf_unhandled_reloc, /* special_function */ | |
1091 | "R_PPC_TPREL16", /* name */ | |
b34976b6 | 1092 | FALSE, /* partial_inplace */ |
252b5132 RH |
1093 | 0, /* src_mask */ |
1094 | 0xffff, /* dst_mask */ | |
b34976b6 | 1095 | FALSE), /* pcrel_offset */ |
252b5132 | 1096 | |
7619e7c7 AM |
1097 | /* Like TPREL16, but no overflow. */ |
1098 | HOWTO (R_PPC_TPREL16_LO, | |
252b5132 RH |
1099 | 0, /* rightshift */ |
1100 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1101 | 16, /* bitsize */ | |
b34976b6 | 1102 | FALSE, /* pc_relative */ |
252b5132 | 1103 | 0, /* bitpos */ |
7619e7c7 AM |
1104 | complain_overflow_dont, /* complain_on_overflow */ |
1105 | ppc_elf_unhandled_reloc, /* special_function */ | |
1106 | "R_PPC_TPREL16_LO", /* name */ | |
b34976b6 | 1107 | FALSE, /* partial_inplace */ |
252b5132 RH |
1108 | 0, /* src_mask */ |
1109 | 0xffff, /* dst_mask */ | |
b34976b6 | 1110 | FALSE), /* pcrel_offset */ |
252b5132 | 1111 | |
7619e7c7 AM |
1112 | /* Like TPREL16_LO, but next higher group of 16 bits. */ |
1113 | HOWTO (R_PPC_TPREL16_HI, | |
1114 | 16, /* rightshift */ | |
1115 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1116 | 16, /* bitsize */ | |
1117 | FALSE, /* pc_relative */ | |
1118 | 0, /* bitpos */ | |
1119 | complain_overflow_dont, /* complain_on_overflow */ | |
1120 | ppc_elf_unhandled_reloc, /* special_function */ | |
1121 | "R_PPC_TPREL16_HI", /* name */ | |
1122 | FALSE, /* partial_inplace */ | |
1123 | 0, /* src_mask */ | |
1124 | 0xffff, /* dst_mask */ | |
1125 | FALSE), /* pcrel_offset */ | |
1126 | ||
1127 | /* Like TPREL16_HI, but adjust for low 16 bits. */ | |
1128 | HOWTO (R_PPC_TPREL16_HA, | |
1129 | 16, /* rightshift */ | |
1130 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1131 | 16, /* bitsize */ | |
1132 | FALSE, /* pc_relative */ | |
1133 | 0, /* bitpos */ | |
1134 | complain_overflow_dont, /* complain_on_overflow */ | |
1135 | ppc_elf_unhandled_reloc, /* special_function */ | |
1136 | "R_PPC_TPREL16_HA", /* name */ | |
1137 | FALSE, /* partial_inplace */ | |
1138 | 0, /* src_mask */ | |
1139 | 0xffff, /* dst_mask */ | |
1140 | FALSE), /* pcrel_offset */ | |
1141 | ||
1142 | /* Allocates two contiguous entries in the GOT to hold a tls_index structure, | |
1143 | with values (sym+add)@dtpmod and (sym+add)@dtprel, and computes the offset | |
1144 | to the first entry. */ | |
1145 | HOWTO (R_PPC_GOT_TLSGD16, | |
252b5132 RH |
1146 | 0, /* rightshift */ |
1147 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1148 | 16, /* bitsize */ | |
b34976b6 | 1149 | FALSE, /* pc_relative */ |
252b5132 RH |
1150 | 0, /* bitpos */ |
1151 | complain_overflow_signed, /* complain_on_overflow */ | |
7619e7c7 AM |
1152 | ppc_elf_unhandled_reloc, /* special_function */ |
1153 | "R_PPC_GOT_TLSGD16", /* name */ | |
b34976b6 | 1154 | FALSE, /* partial_inplace */ |
252b5132 RH |
1155 | 0, /* src_mask */ |
1156 | 0xffff, /* dst_mask */ | |
b34976b6 | 1157 | FALSE), /* pcrel_offset */ |
252b5132 | 1158 | |
7619e7c7 AM |
1159 | /* Like GOT_TLSGD16, but no overflow. */ |
1160 | HOWTO (R_PPC_GOT_TLSGD16_LO, | |
252b5132 | 1161 | 0, /* rightshift */ |
7619e7c7 | 1162 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
252b5132 | 1163 | 16, /* bitsize */ |
b34976b6 | 1164 | FALSE, /* pc_relative */ |
252b5132 | 1165 | 0, /* bitpos */ |
7619e7c7 AM |
1166 | complain_overflow_dont, /* complain_on_overflow */ |
1167 | ppc_elf_unhandled_reloc, /* special_function */ | |
1168 | "R_PPC_GOT_TLSGD16_LO", /* name */ | |
b34976b6 | 1169 | FALSE, /* partial_inplace */ |
252b5132 RH |
1170 | 0, /* src_mask */ |
1171 | 0xffff, /* dst_mask */ | |
b34976b6 | 1172 | FALSE), /* pcrel_offset */ |
252b5132 | 1173 | |
7619e7c7 AM |
1174 | /* Like GOT_TLSGD16_LO, but next higher group of 16 bits. */ |
1175 | HOWTO (R_PPC_GOT_TLSGD16_HI, | |
1176 | 16, /* rightshift */ | |
1177 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1178 | 16, /* bitsize */ | |
1179 | FALSE, /* pc_relative */ | |
1180 | 0, /* bitpos */ | |
1181 | complain_overflow_dont, /* complain_on_overflow */ | |
1182 | ppc_elf_unhandled_reloc, /* special_function */ | |
1183 | "R_PPC_GOT_TLSGD16_HI", /* name */ | |
1184 | FALSE, /* partial_inplace */ | |
1185 | 0, /* src_mask */ | |
1186 | 0xffff, /* dst_mask */ | |
1187 | FALSE), /* pcrel_offset */ | |
252b5132 | 1188 | |
7619e7c7 AM |
1189 | /* Like GOT_TLSGD16_HI, but adjust for low 16 bits. */ |
1190 | HOWTO (R_PPC_GOT_TLSGD16_HA, | |
1191 | 16, /* rightshift */ | |
1192 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1193 | 16, /* bitsize */ | |
1194 | FALSE, /* pc_relative */ | |
1195 | 0, /* bitpos */ | |
1196 | complain_overflow_dont, /* complain_on_overflow */ | |
1197 | ppc_elf_unhandled_reloc, /* special_function */ | |
1198 | "R_PPC_GOT_TLSGD16_HA", /* name */ | |
1199 | FALSE, /* partial_inplace */ | |
1200 | 0, /* src_mask */ | |
1201 | 0xffff, /* dst_mask */ | |
1202 | FALSE), /* pcrel_offset */ | |
1203 | ||
1204 | /* Allocates two contiguous entries in the GOT to hold a tls_index structure, | |
1205 | with values (sym+add)@dtpmod and zero, and computes the offset to the | |
1206 | first entry. */ | |
1207 | HOWTO (R_PPC_GOT_TLSLD16, | |
252b5132 RH |
1208 | 0, /* rightshift */ |
1209 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1210 | 16, /* bitsize */ | |
7619e7c7 | 1211 | FALSE, /* pc_relative */ |
252b5132 RH |
1212 | 0, /* bitpos */ |
1213 | complain_overflow_signed, /* complain_on_overflow */ | |
7619e7c7 AM |
1214 | ppc_elf_unhandled_reloc, /* special_function */ |
1215 | "R_PPC_GOT_TLSLD16", /* name */ | |
b34976b6 | 1216 | FALSE, /* partial_inplace */ |
252b5132 RH |
1217 | 0, /* src_mask */ |
1218 | 0xffff, /* dst_mask */ | |
b34976b6 | 1219 | FALSE), /* pcrel_offset */ |
252b5132 | 1220 | |
7619e7c7 AM |
1221 | /* Like GOT_TLSLD16, but no overflow. */ |
1222 | HOWTO (R_PPC_GOT_TLSLD16_LO, | |
252b5132 | 1223 | 0, /* rightshift */ |
7619e7c7 AM |
1224 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
1225 | 16, /* bitsize */ | |
b34976b6 | 1226 | FALSE, /* pc_relative */ |
252b5132 RH |
1227 | 0, /* bitpos */ |
1228 | complain_overflow_dont, /* complain_on_overflow */ | |
7619e7c7 AM |
1229 | ppc_elf_unhandled_reloc, /* special_function */ |
1230 | "R_PPC_GOT_TLSLD16_LO", /* name */ | |
b34976b6 | 1231 | FALSE, /* partial_inplace */ |
252b5132 | 1232 | 0, /* src_mask */ |
7619e7c7 | 1233 | 0xffff, /* dst_mask */ |
b34976b6 | 1234 | FALSE), /* pcrel_offset */ |
252b5132 | 1235 | |
7619e7c7 AM |
1236 | /* Like GOT_TLSLD16_LO, but next higher group of 16 bits. */ |
1237 | HOWTO (R_PPC_GOT_TLSLD16_HI, | |
1238 | 16, /* rightshift */ | |
1239 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1240 | 16, /* bitsize */ | |
b34976b6 | 1241 | FALSE, /* pc_relative */ |
252b5132 RH |
1242 | 0, /* bitpos */ |
1243 | complain_overflow_dont, /* complain_on_overflow */ | |
7619e7c7 AM |
1244 | ppc_elf_unhandled_reloc, /* special_function */ |
1245 | "R_PPC_GOT_TLSLD16_HI", /* name */ | |
b34976b6 | 1246 | FALSE, /* partial_inplace */ |
252b5132 | 1247 | 0, /* src_mask */ |
7619e7c7 | 1248 | 0xffff, /* dst_mask */ |
b34976b6 | 1249 | FALSE), /* pcrel_offset */ |
252b5132 | 1250 | |
7619e7c7 AM |
1251 | /* Like GOT_TLSLD16_HI, but adjust for low 16 bits. */ |
1252 | HOWTO (R_PPC_GOT_TLSLD16_HA, | |
1253 | 16, /* rightshift */ | |
1254 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1255 | 16, /* bitsize */ | |
1256 | FALSE, /* pc_relative */ | |
1257 | 0, /* bitpos */ | |
1258 | complain_overflow_dont, /* complain_on_overflow */ | |
1259 | ppc_elf_unhandled_reloc, /* special_function */ | |
1260 | "R_PPC_GOT_TLSLD16_HA", /* name */ | |
1261 | FALSE, /* partial_inplace */ | |
1262 | 0, /* src_mask */ | |
1263 | 0xffff, /* dst_mask */ | |
1264 | FALSE), /* pcrel_offset */ | |
1265 | ||
1266 | /* Allocates an entry in the GOT with value (sym+add)@dtprel, and computes | |
1267 | the offset to the entry. */ | |
1268 | HOWTO (R_PPC_GOT_DTPREL16, | |
252b5132 RH |
1269 | 0, /* rightshift */ |
1270 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1271 | 16, /* bitsize */ | |
b34976b6 | 1272 | FALSE, /* pc_relative */ |
252b5132 RH |
1273 | 0, /* bitpos */ |
1274 | complain_overflow_signed, /* complain_on_overflow */ | |
7619e7c7 AM |
1275 | ppc_elf_unhandled_reloc, /* special_function */ |
1276 | "R_PPC_GOT_DTPREL16", /* name */ | |
b34976b6 | 1277 | FALSE, /* partial_inplace */ |
252b5132 RH |
1278 | 0, /* src_mask */ |
1279 | 0xffff, /* dst_mask */ | |
b34976b6 | 1280 | FALSE), /* pcrel_offset */ |
252b5132 | 1281 | |
7619e7c7 AM |
1282 | /* Like GOT_DTPREL16, but no overflow. */ |
1283 | HOWTO (R_PPC_GOT_DTPREL16_LO, | |
1284 | 0, /* rightshift */ | |
1285 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1286 | 16, /* bitsize */ | |
1287 | FALSE, /* pc_relative */ | |
1288 | 0, /* bitpos */ | |
1289 | complain_overflow_dont, /* complain_on_overflow */ | |
1290 | ppc_elf_unhandled_reloc, /* special_function */ | |
1291 | "R_PPC_GOT_DTPREL16_LO", /* name */ | |
1292 | FALSE, /* partial_inplace */ | |
1293 | 0, /* src_mask */ | |
1294 | 0xffff, /* dst_mask */ | |
1295 | FALSE), /* pcrel_offset */ | |
252b5132 | 1296 | |
7619e7c7 AM |
1297 | /* Like GOT_DTPREL16_LO, but next higher group of 16 bits. */ |
1298 | HOWTO (R_PPC_GOT_DTPREL16_HI, | |
1299 | 16, /* rightshift */ | |
1300 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1301 | 16, /* bitsize */ | |
1302 | FALSE, /* pc_relative */ | |
1303 | 0, /* bitpos */ | |
1304 | complain_overflow_dont, /* complain_on_overflow */ | |
1305 | ppc_elf_unhandled_reloc, /* special_function */ | |
1306 | "R_PPC_GOT_DTPREL16_HI", /* name */ | |
1307 | FALSE, /* partial_inplace */ | |
1308 | 0, /* src_mask */ | |
1309 | 0xffff, /* dst_mask */ | |
1310 | FALSE), /* pcrel_offset */ | |
252b5132 | 1311 | |
7619e7c7 AM |
1312 | /* Like GOT_DTPREL16_HI, but adjust for low 16 bits. */ |
1313 | HOWTO (R_PPC_GOT_DTPREL16_HA, | |
1314 | 16, /* rightshift */ | |
1315 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1316 | 16, /* bitsize */ | |
1317 | FALSE, /* pc_relative */ | |
1318 | 0, /* bitpos */ | |
1319 | complain_overflow_dont, /* complain_on_overflow */ | |
1320 | ppc_elf_unhandled_reloc, /* special_function */ | |
1321 | "R_PPC_GOT_DTPREL16_HA", /* name */ | |
1322 | FALSE, /* partial_inplace */ | |
1323 | 0, /* src_mask */ | |
1324 | 0xffff, /* dst_mask */ | |
1325 | FALSE), /* pcrel_offset */ | |
c3668558 | 1326 | |
7619e7c7 AM |
1327 | /* Allocates an entry in the GOT with value (sym+add)@tprel, and computes the |
1328 | offset to the entry. */ | |
1329 | HOWTO (R_PPC_GOT_TPREL16, | |
1330 | 0, /* rightshift */ | |
1331 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1332 | 16, /* bitsize */ | |
1333 | FALSE, /* pc_relative */ | |
1334 | 0, /* bitpos */ | |
1335 | complain_overflow_signed, /* complain_on_overflow */ | |
1336 | ppc_elf_unhandled_reloc, /* special_function */ | |
1337 | "R_PPC_GOT_TPREL16", /* name */ | |
1338 | FALSE, /* partial_inplace */ | |
1339 | 0, /* src_mask */ | |
1340 | 0xffff, /* dst_mask */ | |
1341 | FALSE), /* pcrel_offset */ | |
1342 | ||
1343 | /* Like GOT_TPREL16, but no overflow. */ | |
1344 | HOWTO (R_PPC_GOT_TPREL16_LO, | |
1345 | 0, /* rightshift */ | |
1346 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1347 | 16, /* bitsize */ | |
1348 | FALSE, /* pc_relative */ | |
1349 | 0, /* bitpos */ | |
1350 | complain_overflow_dont, /* complain_on_overflow */ | |
1351 | ppc_elf_unhandled_reloc, /* special_function */ | |
1352 | "R_PPC_GOT_TPREL16_LO", /* name */ | |
1353 | FALSE, /* partial_inplace */ | |
1354 | 0, /* src_mask */ | |
1355 | 0xffff, /* dst_mask */ | |
1356 | FALSE), /* pcrel_offset */ | |
1357 | ||
1358 | /* Like GOT_TPREL16_LO, but next higher group of 16 bits. */ | |
1359 | HOWTO (R_PPC_GOT_TPREL16_HI, | |
1360 | 16, /* rightshift */ | |
1361 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1362 | 16, /* bitsize */ | |
1363 | FALSE, /* pc_relative */ | |
1364 | 0, /* bitpos */ | |
1365 | complain_overflow_dont, /* complain_on_overflow */ | |
1366 | ppc_elf_unhandled_reloc, /* special_function */ | |
1367 | "R_PPC_GOT_TPREL16_HI", /* name */ | |
1368 | FALSE, /* partial_inplace */ | |
1369 | 0, /* src_mask */ | |
1370 | 0xffff, /* dst_mask */ | |
1371 | FALSE), /* pcrel_offset */ | |
1372 | ||
1373 | /* Like GOT_TPREL16_HI, but adjust for low 16 bits. */ | |
1374 | HOWTO (R_PPC_GOT_TPREL16_HA, | |
1375 | 16, /* rightshift */ | |
1376 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1377 | 16, /* bitsize */ | |
1378 | FALSE, /* pc_relative */ | |
1379 | 0, /* bitpos */ | |
1380 | complain_overflow_dont, /* complain_on_overflow */ | |
1381 | ppc_elf_unhandled_reloc, /* special_function */ | |
1382 | "R_PPC_GOT_TPREL16_HA", /* name */ | |
1383 | FALSE, /* partial_inplace */ | |
1384 | 0, /* src_mask */ | |
1385 | 0xffff, /* dst_mask */ | |
1386 | FALSE), /* pcrel_offset */ | |
1387 | ||
1388 | /* The remaining relocs are from the Embedded ELF ABI, and are not | |
1389 | in the SVR4 ELF ABI. */ | |
1390 | ||
1391 | /* 32 bit value resulting from the addend minus the symbol. */ | |
1392 | HOWTO (R_PPC_EMB_NADDR32, /* type */ | |
1393 | 0, /* rightshift */ | |
1394 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1395 | 32, /* bitsize */ | |
1396 | FALSE, /* pc_relative */ | |
1397 | 0, /* bitpos */ | |
1398 | complain_overflow_bitfield, /* complain_on_overflow */ | |
1399 | bfd_elf_generic_reloc, /* special_function */ | |
1400 | "R_PPC_EMB_NADDR32", /* name */ | |
1401 | FALSE, /* partial_inplace */ | |
1402 | 0, /* src_mask */ | |
1403 | 0xffffffff, /* dst_mask */ | |
1404 | FALSE), /* pcrel_offset */ | |
1405 | ||
1406 | /* 16 bit value resulting from the addend minus the symbol. */ | |
1407 | HOWTO (R_PPC_EMB_NADDR16, /* type */ | |
1408 | 0, /* rightshift */ | |
1409 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1410 | 16, /* bitsize */ | |
1411 | FALSE, /* pc_relative */ | |
1412 | 0, /* bitpos */ | |
1413 | complain_overflow_bitfield, /* complain_on_overflow */ | |
1414 | bfd_elf_generic_reloc, /* special_function */ | |
1415 | "R_PPC_EMB_NADDR16", /* name */ | |
1416 | FALSE, /* partial_inplace */ | |
1417 | 0, /* src_mask */ | |
1418 | 0xffff, /* dst_mask */ | |
1419 | FALSE), /* pcrel_offset */ | |
1420 | ||
1421 | /* 16 bit value resulting from the addend minus the symbol. */ | |
1422 | HOWTO (R_PPC_EMB_NADDR16_LO, /* type */ | |
1423 | 0, /* rightshift */ | |
1424 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1425 | 16, /* bitsize */ | |
1426 | FALSE, /* pc_relative */ | |
1427 | 0, /* bitpos */ | |
1428 | complain_overflow_dont,/* complain_on_overflow */ | |
1429 | bfd_elf_generic_reloc, /* special_function */ | |
1430 | "R_PPC_EMB_ADDR16_LO", /* name */ | |
1431 | FALSE, /* partial_inplace */ | |
1432 | 0, /* src_mask */ | |
1433 | 0xffff, /* dst_mask */ | |
1434 | FALSE), /* pcrel_offset */ | |
1435 | ||
1436 | /* The high order 16 bits of the addend minus the symbol. */ | |
1437 | HOWTO (R_PPC_EMB_NADDR16_HI, /* type */ | |
1438 | 16, /* rightshift */ | |
1439 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1440 | 16, /* bitsize */ | |
1441 | FALSE, /* pc_relative */ | |
1442 | 0, /* bitpos */ | |
1443 | complain_overflow_dont, /* complain_on_overflow */ | |
1444 | bfd_elf_generic_reloc, /* special_function */ | |
1445 | "R_PPC_EMB_NADDR16_HI", /* name */ | |
1446 | FALSE, /* partial_inplace */ | |
1447 | 0, /* src_mask */ | |
1448 | 0xffff, /* dst_mask */ | |
1449 | FALSE), /* pcrel_offset */ | |
1450 | ||
1451 | /* The high order 16 bits of the result of the addend minus the address, | |
1452 | plus 1 if the contents of the low 16 bits, treated as a signed number, | |
1453 | is negative. */ | |
1454 | HOWTO (R_PPC_EMB_NADDR16_HA, /* type */ | |
1455 | 16, /* rightshift */ | |
1456 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1457 | 16, /* bitsize */ | |
1458 | FALSE, /* pc_relative */ | |
1459 | 0, /* bitpos */ | |
1460 | complain_overflow_dont, /* complain_on_overflow */ | |
1461 | ppc_elf_addr16_ha_reloc, /* special_function */ | |
1462 | "R_PPC_EMB_NADDR16_HA", /* name */ | |
1463 | FALSE, /* partial_inplace */ | |
1464 | 0, /* src_mask */ | |
1465 | 0xffff, /* dst_mask */ | |
1466 | FALSE), /* pcrel_offset */ | |
1467 | ||
1468 | /* 16 bit value resulting from allocating a 4 byte word to hold an | |
1469 | address in the .sdata section, and returning the offset from | |
1470 | _SDA_BASE_ for that relocation. */ | |
1471 | HOWTO (R_PPC_EMB_SDAI16, /* type */ | |
1472 | 0, /* rightshift */ | |
1473 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1474 | 16, /* bitsize */ | |
1475 | FALSE, /* pc_relative */ | |
1476 | 0, /* bitpos */ | |
1477 | complain_overflow_bitfield, /* complain_on_overflow */ | |
1478 | bfd_elf_generic_reloc, /* special_function */ | |
1479 | "R_PPC_EMB_SDAI16", /* name */ | |
1480 | FALSE, /* partial_inplace */ | |
1481 | 0, /* src_mask */ | |
1482 | 0xffff, /* dst_mask */ | |
1483 | FALSE), /* pcrel_offset */ | |
1484 | ||
1485 | /* 16 bit value resulting from allocating a 4 byte word to hold an | |
1486 | address in the .sdata2 section, and returning the offset from | |
1487 | _SDA2_BASE_ for that relocation. */ | |
1488 | HOWTO (R_PPC_EMB_SDA2I16, /* type */ | |
1489 | 0, /* rightshift */ | |
1490 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1491 | 16, /* bitsize */ | |
1492 | FALSE, /* pc_relative */ | |
1493 | 0, /* bitpos */ | |
1494 | complain_overflow_bitfield, /* complain_on_overflow */ | |
1495 | bfd_elf_generic_reloc, /* special_function */ | |
1496 | "R_PPC_EMB_SDA2I16", /* name */ | |
1497 | FALSE, /* partial_inplace */ | |
1498 | 0, /* src_mask */ | |
1499 | 0xffff, /* dst_mask */ | |
1500 | FALSE), /* pcrel_offset */ | |
1501 | ||
1502 | /* A sign-extended 16 bit value relative to _SDA2_BASE_, for use with | |
1503 | small data items. */ | |
1504 | HOWTO (R_PPC_EMB_SDA2REL, /* type */ | |
1505 | 0, /* rightshift */ | |
1506 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1507 | 16, /* bitsize */ | |
1508 | FALSE, /* pc_relative */ | |
1509 | 0, /* bitpos */ | |
1510 | complain_overflow_signed, /* complain_on_overflow */ | |
1511 | bfd_elf_generic_reloc, /* special_function */ | |
1512 | "R_PPC_EMB_SDA2REL", /* name */ | |
1513 | FALSE, /* partial_inplace */ | |
1514 | 0, /* src_mask */ | |
1515 | 0xffff, /* dst_mask */ | |
1516 | FALSE), /* pcrel_offset */ | |
1517 | ||
1518 | /* Relocate against either _SDA_BASE_ or _SDA2_BASE_, filling in the 16 bit | |
1519 | signed offset from the appropriate base, and filling in the register | |
1520 | field with the appropriate register (0, 2, or 13). */ | |
1521 | HOWTO (R_PPC_EMB_SDA21, /* type */ | |
1522 | 0, /* rightshift */ | |
1523 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1524 | 16, /* bitsize */ | |
1525 | FALSE, /* pc_relative */ | |
1526 | 0, /* bitpos */ | |
1527 | complain_overflow_signed, /* complain_on_overflow */ | |
1528 | bfd_elf_generic_reloc, /* special_function */ | |
1529 | "R_PPC_EMB_SDA21", /* name */ | |
1530 | FALSE, /* partial_inplace */ | |
1531 | 0, /* src_mask */ | |
1532 | 0xffff, /* dst_mask */ | |
1533 | FALSE), /* pcrel_offset */ | |
1534 | ||
1535 | /* Relocation not handled: R_PPC_EMB_MRKREF */ | |
1536 | /* Relocation not handled: R_PPC_EMB_RELSEC16 */ | |
1537 | /* Relocation not handled: R_PPC_EMB_RELST_LO */ | |
1538 | /* Relocation not handled: R_PPC_EMB_RELST_HI */ | |
1539 | /* Relocation not handled: R_PPC_EMB_RELST_HA */ | |
1540 | /* Relocation not handled: R_PPC_EMB_BIT_FLD */ | |
1541 | ||
1542 | /* PC relative relocation against either _SDA_BASE_ or _SDA2_BASE_, filling | |
1543 | in the 16 bit signed offset from the appropriate base, and filling in the | |
1544 | register field with the appropriate register (0, 2, or 13). */ | |
1545 | HOWTO (R_PPC_EMB_RELSDA, /* type */ | |
1546 | 0, /* rightshift */ | |
1547 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1548 | 16, /* bitsize */ | |
1549 | TRUE, /* pc_relative */ | |
1550 | 0, /* bitpos */ | |
1551 | complain_overflow_signed, /* complain_on_overflow */ | |
1552 | bfd_elf_generic_reloc, /* special_function */ | |
1553 | "R_PPC_EMB_RELSDA", /* name */ | |
1554 | FALSE, /* partial_inplace */ | |
1555 | 0, /* src_mask */ | |
1556 | 0xffff, /* dst_mask */ | |
1557 | FALSE), /* pcrel_offset */ | |
1558 | ||
1559 | /* GNU extension to record C++ vtable hierarchy. */ | |
1560 | HOWTO (R_PPC_GNU_VTINHERIT, /* type */ | |
1561 | 0, /* rightshift */ | |
1562 | 0, /* size (0 = byte, 1 = short, 2 = long) */ | |
1563 | 0, /* bitsize */ | |
1564 | FALSE, /* pc_relative */ | |
1565 | 0, /* bitpos */ | |
1566 | complain_overflow_dont, /* complain_on_overflow */ | |
1567 | NULL, /* special_function */ | |
1568 | "R_PPC_GNU_VTINHERIT", /* name */ | |
1569 | FALSE, /* partial_inplace */ | |
1570 | 0, /* src_mask */ | |
1571 | 0, /* dst_mask */ | |
1572 | FALSE), /* pcrel_offset */ | |
1573 | ||
1574 | /* GNU extension to record C++ vtable member usage. */ | |
1575 | HOWTO (R_PPC_GNU_VTENTRY, /* type */ | |
1576 | 0, /* rightshift */ | |
1577 | 0, /* size (0 = byte, 1 = short, 2 = long) */ | |
1578 | 0, /* bitsize */ | |
1579 | FALSE, /* pc_relative */ | |
1580 | 0, /* bitpos */ | |
1581 | complain_overflow_dont, /* complain_on_overflow */ | |
1582 | NULL, /* special_function */ | |
1583 | "R_PPC_GNU_VTENTRY", /* name */ | |
1584 | FALSE, /* partial_inplace */ | |
1585 | 0, /* src_mask */ | |
1586 | 0, /* dst_mask */ | |
1587 | FALSE), /* pcrel_offset */ | |
1588 | ||
1589 | /* Phony reloc to handle AIX style TOC entries. */ | |
1590 | HOWTO (R_PPC_TOC16, /* type */ | |
1591 | 0, /* rightshift */ | |
1592 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1593 | 16, /* bitsize */ | |
1594 | FALSE, /* pc_relative */ | |
1595 | 0, /* bitpos */ | |
1596 | complain_overflow_signed, /* complain_on_overflow */ | |
1597 | bfd_elf_generic_reloc, /* special_function */ | |
1598 | "R_PPC_TOC16", /* name */ | |
1599 | FALSE, /* partial_inplace */ | |
1600 | 0, /* src_mask */ | |
1601 | 0xffff, /* dst_mask */ | |
1602 | FALSE), /* pcrel_offset */ | |
1603 | }; | |
1604 | \f | |
1605 | /* Initialize the ppc_elf_howto_table, so that linear accesses can be done. */ | |
1606 | ||
1607 | static void | |
1608 | ppc_elf_howto_init () | |
1609 | { | |
1610 | unsigned int i, type; | |
1611 | ||
1612 | for (i = 0; i < sizeof (ppc_elf_howto_raw) / sizeof (ppc_elf_howto_raw[0]); i++) | |
1613 | { | |
1614 | type = ppc_elf_howto_raw[i].type; | |
1615 | BFD_ASSERT (type < sizeof (ppc_elf_howto_table) / sizeof (ppc_elf_howto_table[0])); | |
1616 | ppc_elf_howto_table[type] = &ppc_elf_howto_raw[i]; | |
1617 | } | |
1618 | } | |
1619 | \f | |
1620 | /* This function handles relaxing for the PPC with option --mpc860c0[=<n>]. | |
1621 | ||
1622 | The MPC860, revision C0 or earlier contains a bug in the die. | |
1623 | If all of the following conditions are true, the next instruction | |
1624 | to be executed *may* be treated as a no-op. | |
1625 | 1/ A forward branch is executed. | |
1626 | 2/ The branch is predicted as not taken. | |
1627 | 3/ The branch is taken. | |
1628 | 4/ The branch is located in the last 5 words of a page. | |
1629 | (The EOP limit is 5 by default but may be specified as any value from 1-10.) | |
1630 | ||
1631 | Our software solution is to detect these problematic branches in a | |
1632 | linker pass and modify them as follows: | |
1633 | 1/ Unconditional branches - Since these are always predicted taken, | |
252b5132 RH |
1634 | there is no problem and no action is required. |
1635 | 2/ Conditional backward branches - No problem, no action required. | |
1636 | 3/ Conditional forward branches - Ensure that the "inverse prediction | |
1637 | bit" is set (ensure it is predicted taken). | |
1638 | 4/ Conditional register branches - Ensure that the "y bit" is set | |
ae9a127f | 1639 | (ensure it is predicted taken). */ |
252b5132 RH |
1640 | |
1641 | /* Sort sections by address. */ | |
1642 | ||
1643 | static int | |
1644 | ppc_elf_sort_rela (arg1, arg2) | |
a7b97311 AM |
1645 | const PTR arg1; |
1646 | const PTR arg2; | |
252b5132 RH |
1647 | { |
1648 | const Elf_Internal_Rela **rela1 = (const Elf_Internal_Rela**) arg1; | |
1649 | const Elf_Internal_Rela **rela2 = (const Elf_Internal_Rela**) arg2; | |
1650 | ||
c3668558 | 1651 | /* Sort by offset. */ |
252b5132 RH |
1652 | return ((*rela1)->r_offset - (*rela2)->r_offset); |
1653 | } | |
1654 | ||
b34976b6 | 1655 | static bfd_boolean |
252b5132 | 1656 | ppc_elf_relax_section (abfd, isec, link_info, again) |
8da6118f KH |
1657 | bfd *abfd; |
1658 | asection *isec; | |
1659 | struct bfd_link_info *link_info; | |
b34976b6 | 1660 | bfd_boolean *again; |
252b5132 RH |
1661 | { |
1662 | #define PAGESIZE 0x1000 | |
1663 | ||
1664 | bfd_byte *contents = NULL; | |
1665 | bfd_byte *free_contents = NULL; | |
1666 | Elf_Internal_Rela *internal_relocs = NULL; | |
1667 | Elf_Internal_Rela *free_relocs = NULL; | |
1668 | Elf_Internal_Rela **rela_comb = NULL; | |
1669 | int comb_curr, comb_count; | |
1670 | ||
c3668558 | 1671 | /* We never have to do this more than once per input section. */ |
b34976b6 | 1672 | *again = FALSE; |
252b5132 RH |
1673 | |
1674 | /* If needed, initialize this section's cooked size. */ | |
1675 | if (isec->_cooked_size == 0) | |
70bccea4 | 1676 | isec->_cooked_size = isec->_raw_size; |
252b5132 RH |
1677 | |
1678 | /* We're only interested in text sections which overlap the | |
8da6118f | 1679 | troublesome area at the end of a page. */ |
252b5132 RH |
1680 | if (link_info->mpc860c0 && (isec->flags & SEC_CODE) && isec->_cooked_size) |
1681 | { | |
1682 | bfd_vma dot, end_page, end_section; | |
b34976b6 | 1683 | bfd_boolean section_modified; |
252b5132 | 1684 | |
c3668558 | 1685 | /* Get the section contents. */ |
252b5132 RH |
1686 | /* Get cached copy if it exists. */ |
1687 | if (elf_section_data (isec)->this_hdr.contents != NULL) | |
70bccea4 | 1688 | contents = elf_section_data (isec)->this_hdr.contents; |
252b5132 RH |
1689 | else |
1690 | { | |
1691 | /* Go get them off disk. */ | |
1692 | contents = (bfd_byte *) bfd_malloc (isec->_raw_size); | |
1693 | if (contents == NULL) | |
8da6118f | 1694 | goto error_return; |
252b5132 RH |
1695 | free_contents = contents; |
1696 | ||
1697 | if (! bfd_get_section_contents (abfd, isec, contents, | |
1698 | (file_ptr) 0, isec->_raw_size)) | |
8da6118f | 1699 | goto error_return; |
252b5132 RH |
1700 | } |
1701 | ||
1702 | comb_curr = 0; | |
1703 | comb_count = 0; | |
1704 | if (isec->reloc_count) | |
8da6118f | 1705 | { |
70bccea4 | 1706 | unsigned n; |
dc810e39 | 1707 | bfd_size_type amt; |
252b5132 | 1708 | |
70bccea4 AM |
1709 | /* Get a copy of the native relocations. */ |
1710 | internal_relocs | |
1711 | = _bfd_elf32_link_read_relocs (abfd, isec, (PTR) NULL, | |
1712 | (Elf_Internal_Rela *) NULL, | |
1713 | link_info->keep_memory); | |
1714 | if (internal_relocs == NULL) | |
1715 | goto error_return; | |
1716 | if (! link_info->keep_memory) | |
1717 | free_relocs = internal_relocs; | |
c3668558 | 1718 | |
70bccea4 | 1719 | /* Setup a faster access method for the reloc info we need. */ |
dc810e39 AM |
1720 | amt = isec->reloc_count; |
1721 | amt *= sizeof (Elf_Internal_Rela*); | |
70bccea4 AM |
1722 | rela_comb = (Elf_Internal_Rela**) bfd_malloc (amt); |
1723 | if (rela_comb == NULL) | |
1724 | goto error_return; | |
1725 | for (n = 0; n < isec->reloc_count; ++n) | |
1726 | { | |
1727 | long r_type; | |
1728 | ||
1729 | r_type = ELF32_R_TYPE (internal_relocs[n].r_info); | |
1730 | if (r_type < 0 || r_type >= (int) R_PPC_max) | |
1731 | goto error_return; | |
1732 | ||
1733 | /* Prologue constants are sometimes present in the ".text" | |
1734 | sections and they can be identified by their associated | |
1735 | relocation. We don't want to process those words and | |
1736 | some others which can also be identified by their | |
1737 | relocations. However, not all conditional branches will | |
1738 | have a relocation so we will only ignore words that | |
1739 | 1) have a reloc, and 2) the reloc is not applicable to a | |
1740 | conditional branch. The array rela_comb is built here | |
1741 | for use in the EOP scan loop. */ | |
1742 | switch (r_type) | |
1743 | { | |
1744 | case R_PPC_ADDR14_BRNTAKEN: | |
1745 | case R_PPC_REL14: | |
1746 | case R_PPC_REL14_BRNTAKEN: | |
1747 | /* We should check the instruction. */ | |
1748 | break; | |
1749 | default: | |
1750 | /* The word is not a conditional branch - ignore it. */ | |
1751 | rela_comb[comb_count++] = &internal_relocs[n]; | |
1752 | break; | |
1753 | } | |
1754 | } | |
1755 | if (comb_count > 1) | |
1756 | qsort (rela_comb, (size_t) comb_count, sizeof (int), | |
1757 | ppc_elf_sort_rela); | |
8da6118f | 1758 | } |
252b5132 | 1759 | |
c3668558 | 1760 | /* Enumerate each EOP region that overlaps this section. */ |
252b5132 RH |
1761 | end_section = isec->vma + isec->_cooked_size; |
1762 | dot = end_page = (isec->vma | (PAGESIZE - 1)) + 1; | |
1763 | dot -= link_info->mpc860c0; | |
b34976b6 | 1764 | section_modified = FALSE; |
70bccea4 AM |
1765 | /* Increment the start position if this section begins in the |
1766 | middle of its first EOP region. */ | |
1767 | if (dot < isec->vma) | |
1768 | dot = isec->vma; | |
252b5132 | 1769 | for (; |
70bccea4 AM |
1770 | dot < end_section; |
1771 | dot += PAGESIZE, end_page += PAGESIZE) | |
1772 | { | |
1773 | /* Check each word in this EOP region. */ | |
1774 | for (; dot < end_page; dot += 4) | |
1775 | { | |
1776 | bfd_vma isec_offset; | |
1777 | unsigned long insn; | |
1778 | bfd_boolean skip, modified; | |
1779 | ||
1780 | /* Don't process this word if there is a relocation for it | |
1781 | and the relocation indicates the word is not a | |
1782 | conditional branch. */ | |
1783 | skip = FALSE; | |
1784 | isec_offset = dot - isec->vma; | |
1785 | for (; comb_curr<comb_count; ++comb_curr) | |
1786 | { | |
1787 | bfd_vma r_offset; | |
1788 | ||
1789 | r_offset = rela_comb[comb_curr]->r_offset; | |
1790 | if (r_offset >= isec_offset) | |
1791 | { | |
1792 | if (r_offset == isec_offset) skip = TRUE; | |
1793 | break; | |
1794 | } | |
1795 | } | |
1796 | if (skip) continue; | |
1797 | ||
1798 | /* Check the current word for a problematic conditional | |
1799 | branch. */ | |
252b5132 RH |
1800 | #define BO0(insn) ((insn) & 0x02000000) |
1801 | #define BO2(insn) ((insn) & 0x00800000) | |
1802 | #define BO4(insn) ((insn) & 0x00200000) | |
70bccea4 AM |
1803 | insn = (unsigned long) bfd_get_32 (abfd, contents + isec_offset); |
1804 | modified = FALSE; | |
1805 | if ((insn & 0xFc000000) == 0x40000000) | |
1806 | { | |
1807 | /* Instruction is BCx */ | |
1808 | if ((!BO0(insn) || !BO2(insn)) && !BO4(insn)) | |
1809 | { | |
1810 | bfd_vma target; | |
252b5132 | 1811 | |
70bccea4 AM |
1812 | /* This branch is predicted as "normal". |
1813 | If this is a forward branch, it is problematic. */ | |
1814 | target = insn & 0x0000Fffc; | |
1815 | target = (target ^ 0x8000) - 0x8000; | |
1816 | if ((insn & 0x00000002) == 0) | |
1817 | /* Convert to abs. */ | |
1818 | target += dot; | |
1819 | if (target > dot) | |
1820 | { | |
1821 | /* Set the prediction bit. */ | |
1822 | insn |= 0x00200000; | |
1823 | modified = TRUE; | |
1824 | } | |
1825 | } | |
1826 | } | |
1827 | else if ((insn & 0xFc00Fffe) == 0x4c000420) | |
1828 | { | |
1829 | /* Instruction is BCCTRx. */ | |
1830 | if ((!BO0(insn) || !BO2(insn)) && !BO4(insn)) | |
252b5132 RH |
1831 | { |
1832 | /* This branch is predicted as not-taken. | |
ae9a127f | 1833 | If this is a forward branch, it is problematic. |
70bccea4 AM |
1834 | Since we can't tell statically if it will branch |
1835 | forward, always set the prediction bit. */ | |
1836 | insn |= 0x00200000; | |
1837 | modified = TRUE; | |
252b5132 | 1838 | } |
70bccea4 AM |
1839 | } |
1840 | else if ((insn & 0xFc00Fffe) == 0x4c000020) | |
1841 | { | |
1842 | /* Instruction is BCLRx */ | |
1843 | if ((!BO0(insn) || !BO2(insn)) && !BO4(insn)) | |
252b5132 RH |
1844 | { |
1845 | /* This branch is predicted as not-taken. | |
ae9a127f | 1846 | If this is a forward branch, it is problematic. |
70bccea4 AM |
1847 | Since we can't tell statically if it will branch |
1848 | forward, always set the prediction bit. */ | |
1849 | insn |= 0x00200000; | |
1850 | modified = TRUE; | |
252b5132 | 1851 | } |
70bccea4 | 1852 | } |
252b5132 RH |
1853 | #undef BO0 |
1854 | #undef BO2 | |
1855 | #undef BO4 | |
70bccea4 AM |
1856 | if (modified) |
1857 | { | |
1858 | bfd_put_32 (abfd, (bfd_vma) insn, contents + isec_offset); | |
b34976b6 | 1859 | section_modified = TRUE; |
70bccea4 AM |
1860 | } |
1861 | } | |
1862 | } | |
252b5132 RH |
1863 | if (section_modified) |
1864 | { | |
1865 | elf_section_data (isec)->this_hdr.contents = contents; | |
1866 | free_contents = NULL; | |
1867 | } | |
1868 | } | |
1869 | ||
1870 | if (rela_comb != NULL) | |
1871 | { | |
1872 | free (rela_comb); | |
1873 | rela_comb = NULL; | |
1874 | } | |
1875 | ||
1876 | if (free_relocs != NULL) | |
1877 | { | |
1878 | free (free_relocs); | |
1879 | free_relocs = NULL; | |
1880 | } | |
1881 | ||
1882 | if (free_contents != NULL) | |
1883 | { | |
1884 | if (! link_info->keep_memory) | |
1885 | free (free_contents); | |
1886 | else | |
1887 | { | |
1888 | /* Cache the section contents for elf_link_input_bfd. */ | |
1889 | elf_section_data (isec)->this_hdr.contents = contents; | |
1890 | } | |
1891 | free_contents = NULL; | |
1892 | } | |
1893 | ||
b34976b6 | 1894 | return TRUE; |
252b5132 | 1895 | |
70bccea4 | 1896 | error_return: |
252b5132 RH |
1897 | if (rela_comb != NULL) |
1898 | free (rela_comb); | |
1899 | if (free_relocs != NULL) | |
1900 | free (free_relocs); | |
1901 | if (free_contents != NULL) | |
1902 | free (free_contents); | |
b34976b6 | 1903 | return FALSE; |
252b5132 | 1904 | } |
252b5132 RH |
1905 | \f |
1906 | static reloc_howto_type * | |
1907 | ppc_elf_reloc_type_lookup (abfd, code) | |
5f771d47 | 1908 | bfd *abfd ATTRIBUTE_UNUSED; |
252b5132 RH |
1909 | bfd_reloc_code_real_type code; |
1910 | { | |
7619e7c7 | 1911 | enum elf_ppc_reloc_type r; |
252b5132 RH |
1912 | |
1913 | if (!ppc_elf_howto_table[R_PPC_ADDR32]) | |
8da6118f | 1914 | /* Initialize howto table if needed. */ |
252b5132 RH |
1915 | ppc_elf_howto_init (); |
1916 | ||
8da6118f | 1917 | switch ((int) code) |
252b5132 RH |
1918 | { |
1919 | default: | |
8da6118f | 1920 | return (reloc_howto_type *) NULL; |
252b5132 | 1921 | |
7619e7c7 AM |
1922 | case BFD_RELOC_NONE: r = R_PPC_NONE; break; |
1923 | case BFD_RELOC_32: r = R_PPC_ADDR32; break; | |
1924 | case BFD_RELOC_PPC_BA26: r = R_PPC_ADDR24; break; | |
1925 | case BFD_RELOC_16: r = R_PPC_ADDR16; break; | |
1926 | case BFD_RELOC_LO16: r = R_PPC_ADDR16_LO; break; | |
1927 | case BFD_RELOC_HI16: r = R_PPC_ADDR16_HI; break; | |
1928 | case BFD_RELOC_HI16_S: r = R_PPC_ADDR16_HA; break; | |
1929 | case BFD_RELOC_PPC_BA16: r = R_PPC_ADDR14; break; | |
1930 | case BFD_RELOC_PPC_BA16_BRTAKEN: r = R_PPC_ADDR14_BRTAKEN; break; | |
1931 | case BFD_RELOC_PPC_BA16_BRNTAKEN: r = R_PPC_ADDR14_BRNTAKEN; break; | |
1932 | case BFD_RELOC_PPC_B26: r = R_PPC_REL24; break; | |
1933 | case BFD_RELOC_PPC_B16: r = R_PPC_REL14; break; | |
1934 | case BFD_RELOC_PPC_B16_BRTAKEN: r = R_PPC_REL14_BRTAKEN; break; | |
1935 | case BFD_RELOC_PPC_B16_BRNTAKEN: r = R_PPC_REL14_BRNTAKEN; break; | |
1936 | case BFD_RELOC_16_GOTOFF: r = R_PPC_GOT16; break; | |
1937 | case BFD_RELOC_LO16_GOTOFF: r = R_PPC_GOT16_LO; break; | |
1938 | case BFD_RELOC_HI16_GOTOFF: r = R_PPC_GOT16_HI; break; | |
1939 | case BFD_RELOC_HI16_S_GOTOFF: r = R_PPC_GOT16_HA; break; | |
1940 | case BFD_RELOC_24_PLT_PCREL: r = R_PPC_PLTREL24; break; | |
1941 | case BFD_RELOC_PPC_COPY: r = R_PPC_COPY; break; | |
1942 | case BFD_RELOC_PPC_GLOB_DAT: r = R_PPC_GLOB_DAT; break; | |
1943 | case BFD_RELOC_PPC_LOCAL24PC: r = R_PPC_LOCAL24PC; break; | |
1944 | case BFD_RELOC_32_PCREL: r = R_PPC_REL32; break; | |
1945 | case BFD_RELOC_32_PLTOFF: r = R_PPC_PLT32; break; | |
1946 | case BFD_RELOC_32_PLT_PCREL: r = R_PPC_PLTREL32; break; | |
1947 | case BFD_RELOC_LO16_PLTOFF: r = R_PPC_PLT16_LO; break; | |
1948 | case BFD_RELOC_HI16_PLTOFF: r = R_PPC_PLT16_HI; break; | |
1949 | case BFD_RELOC_HI16_S_PLTOFF: r = R_PPC_PLT16_HA; break; | |
1950 | case BFD_RELOC_GPREL16: r = R_PPC_SDAREL16; break; | |
1951 | case BFD_RELOC_16_BASEREL: r = R_PPC_SECTOFF; break; | |
1952 | case BFD_RELOC_LO16_BASEREL: r = R_PPC_SECTOFF_LO; break; | |
1953 | case BFD_RELOC_HI16_BASEREL: r = R_PPC_SECTOFF_HI; break; | |
1954 | case BFD_RELOC_HI16_S_BASEREL: r = R_PPC_SECTOFF_HA; break; | |
1955 | case BFD_RELOC_CTOR: r = R_PPC_ADDR32; break; | |
1956 | case BFD_RELOC_PPC_TOC16: r = R_PPC_TOC16; break; | |
1957 | case BFD_RELOC_PPC_TLS: r = R_PPC_TLS; break; | |
1958 | case BFD_RELOC_PPC_DTPMOD: r = R_PPC_DTPMOD32; break; | |
1959 | case BFD_RELOC_PPC_TPREL16: r = R_PPC_TPREL16; break; | |
1960 | case BFD_RELOC_PPC_TPREL16_LO: r = R_PPC_TPREL16_LO; break; | |
1961 | case BFD_RELOC_PPC_TPREL16_HI: r = R_PPC_TPREL16_HI; break; | |
1962 | case BFD_RELOC_PPC_TPREL16_HA: r = R_PPC_TPREL16_HA; break; | |
1963 | case BFD_RELOC_PPC_TPREL: r = R_PPC_TPREL32; break; | |
1964 | case BFD_RELOC_PPC_DTPREL16: r = R_PPC_DTPREL16; break; | |
1965 | case BFD_RELOC_PPC_DTPREL16_LO: r = R_PPC_DTPREL16_LO; break; | |
1966 | case BFD_RELOC_PPC_DTPREL16_HI: r = R_PPC_DTPREL16_HI; break; | |
1967 | case BFD_RELOC_PPC_DTPREL16_HA: r = R_PPC_DTPREL16_HA; break; | |
1968 | case BFD_RELOC_PPC_DTPREL: r = R_PPC_DTPREL32; break; | |
1969 | case BFD_RELOC_PPC_GOT_TLSGD16: r = R_PPC_GOT_TLSGD16; break; | |
1970 | case BFD_RELOC_PPC_GOT_TLSGD16_LO: r = R_PPC_GOT_TLSGD16_LO; break; | |
1971 | case BFD_RELOC_PPC_GOT_TLSGD16_HI: r = R_PPC_GOT_TLSGD16_HI; break; | |
1972 | case BFD_RELOC_PPC_GOT_TLSGD16_HA: r = R_PPC_GOT_TLSGD16_HA; break; | |
1973 | case BFD_RELOC_PPC_GOT_TLSLD16: r = R_PPC_GOT_TLSLD16; break; | |
1974 | case BFD_RELOC_PPC_GOT_TLSLD16_LO: r = R_PPC_GOT_TLSLD16_LO; break; | |
1975 | case BFD_RELOC_PPC_GOT_TLSLD16_HI: r = R_PPC_GOT_TLSLD16_HI; break; | |
1976 | case BFD_RELOC_PPC_GOT_TLSLD16_HA: r = R_PPC_GOT_TLSLD16_HA; break; | |
1977 | case BFD_RELOC_PPC_GOT_TPREL16: r = R_PPC_GOT_TPREL16; break; | |
1978 | case BFD_RELOC_PPC_GOT_TPREL16_LO: r = R_PPC_GOT_TPREL16_LO; break; | |
1979 | case BFD_RELOC_PPC_GOT_TPREL16_HI: r = R_PPC_GOT_TPREL16_HI; break; | |
1980 | case BFD_RELOC_PPC_GOT_TPREL16_HA: r = R_PPC_GOT_TPREL16_HA; break; | |
1981 | case BFD_RELOC_PPC_GOT_DTPREL16: r = R_PPC_GOT_DTPREL16; break; | |
1982 | case BFD_RELOC_PPC_GOT_DTPREL16_LO: r = R_PPC_GOT_DTPREL16_LO; break; | |
1983 | case BFD_RELOC_PPC_GOT_DTPREL16_HI: r = R_PPC_GOT_DTPREL16_HI; break; | |
1984 | case BFD_RELOC_PPC_GOT_DTPREL16_HA: r = R_PPC_GOT_DTPREL16_HA; break; | |
1985 | case BFD_RELOC_PPC_EMB_NADDR32: r = R_PPC_EMB_NADDR32; break; | |
1986 | case BFD_RELOC_PPC_EMB_NADDR16: r = R_PPC_EMB_NADDR16; break; | |
1987 | case BFD_RELOC_PPC_EMB_NADDR16_LO: r = R_PPC_EMB_NADDR16_LO; break; | |
1988 | case BFD_RELOC_PPC_EMB_NADDR16_HI: r = R_PPC_EMB_NADDR16_HI; break; | |
1989 | case BFD_RELOC_PPC_EMB_NADDR16_HA: r = R_PPC_EMB_NADDR16_HA; break; | |
1990 | case BFD_RELOC_PPC_EMB_SDAI16: r = R_PPC_EMB_SDAI16; break; | |
1991 | case BFD_RELOC_PPC_EMB_SDA2I16: r = R_PPC_EMB_SDA2I16; break; | |
1992 | case BFD_RELOC_PPC_EMB_SDA2REL: r = R_PPC_EMB_SDA2REL; break; | |
1993 | case BFD_RELOC_PPC_EMB_SDA21: r = R_PPC_EMB_SDA21; break; | |
1994 | case BFD_RELOC_PPC_EMB_MRKREF: r = R_PPC_EMB_MRKREF; break; | |
1995 | case BFD_RELOC_PPC_EMB_RELSEC16: r = R_PPC_EMB_RELSEC16; break; | |
1996 | case BFD_RELOC_PPC_EMB_RELST_LO: r = R_PPC_EMB_RELST_LO; break; | |
1997 | case BFD_RELOC_PPC_EMB_RELST_HI: r = R_PPC_EMB_RELST_HI; break; | |
1998 | case BFD_RELOC_PPC_EMB_RELST_HA: r = R_PPC_EMB_RELST_HA; break; | |
1999 | case BFD_RELOC_PPC_EMB_BIT_FLD: r = R_PPC_EMB_BIT_FLD; break; | |
2000 | case BFD_RELOC_PPC_EMB_RELSDA: r = R_PPC_EMB_RELSDA; break; | |
2001 | case BFD_RELOC_VTABLE_INHERIT: r = R_PPC_GNU_VTINHERIT; break; | |
2002 | case BFD_RELOC_VTABLE_ENTRY: r = R_PPC_GNU_VTENTRY; break; | |
252b5132 RH |
2003 | } |
2004 | ||
7619e7c7 | 2005 | return ppc_elf_howto_table[(int) r]; |
252b5132 RH |
2006 | }; |
2007 | ||
2008 | /* Set the howto pointer for a PowerPC ELF reloc. */ | |
2009 | ||
2010 | static void | |
2011 | ppc_elf_info_to_howto (abfd, cache_ptr, dst) | |
5f771d47 | 2012 | bfd *abfd ATTRIBUTE_UNUSED; |
252b5132 | 2013 | arelent *cache_ptr; |
947216bf | 2014 | Elf_Internal_Rela *dst; |
252b5132 | 2015 | { |
8da6118f KH |
2016 | if (!ppc_elf_howto_table[R_PPC_ADDR32]) |
2017 | /* Initialize howto table if needed. */ | |
252b5132 RH |
2018 | ppc_elf_howto_init (); |
2019 | ||
2020 | BFD_ASSERT (ELF32_R_TYPE (dst->r_info) < (unsigned int) R_PPC_max); | |
2021 | cache_ptr->howto = ppc_elf_howto_table[ELF32_R_TYPE (dst->r_info)]; | |
2022 | } | |
2023 | ||
2024 | /* Handle the R_PPC_ADDR16_HA reloc. */ | |
2025 | ||
2026 | static bfd_reloc_status_type | |
2027 | ppc_elf_addr16_ha_reloc (abfd, reloc_entry, symbol, data, input_section, | |
2028 | output_bfd, error_message) | |
5f771d47 | 2029 | bfd *abfd ATTRIBUTE_UNUSED; |
252b5132 RH |
2030 | arelent *reloc_entry; |
2031 | asymbol *symbol; | |
5f771d47 | 2032 | PTR data ATTRIBUTE_UNUSED; |
252b5132 RH |
2033 | asection *input_section; |
2034 | bfd *output_bfd; | |
5f771d47 | 2035 | char **error_message ATTRIBUTE_UNUSED; |
252b5132 RH |
2036 | { |
2037 | bfd_vma relocation; | |
2038 | ||
2039 | if (output_bfd != NULL) | |
2040 | { | |
2041 | reloc_entry->address += input_section->output_offset; | |
2042 | return bfd_reloc_ok; | |
2043 | } | |
2044 | ||
2045 | if (reloc_entry->address > input_section->_cooked_size) | |
2046 | return bfd_reloc_outofrange; | |
2047 | ||
2048 | if (bfd_is_com_section (symbol->section)) | |
2049 | relocation = 0; | |
2050 | else | |
2051 | relocation = symbol->value; | |
2052 | ||
2053 | relocation += symbol->section->output_section->vma; | |
2054 | relocation += symbol->section->output_offset; | |
2055 | relocation += reloc_entry->addend; | |
2056 | ||
2057 | reloc_entry->addend += (relocation & 0x8000) << 1; | |
2058 | ||
2059 | return bfd_reloc_continue; | |
2060 | } | |
2061 | ||
7619e7c7 AM |
2062 | static bfd_reloc_status_type |
2063 | ppc_elf_unhandled_reloc (abfd, reloc_entry, symbol, data, | |
2064 | input_section, output_bfd, error_message) | |
2065 | bfd *abfd; | |
2066 | arelent *reloc_entry; | |
2067 | asymbol *symbol; | |
2068 | PTR data; | |
2069 | asection *input_section; | |
2070 | bfd *output_bfd; | |
2071 | char **error_message; | |
2072 | { | |
2073 | /* If this is a relocatable link (output_bfd test tells us), just | |
2074 | call the generic function. Any adjustment will be done at final | |
2075 | link time. */ | |
2076 | if (output_bfd != NULL) | |
2077 | return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data, | |
2078 | input_section, output_bfd, error_message); | |
2079 | ||
2080 | if (error_message != NULL) | |
2081 | { | |
2082 | static char buf[60]; | |
2083 | sprintf (buf, "generic linker can't handle %s", | |
2084 | reloc_entry->howto->name); | |
2085 | *error_message = buf; | |
2086 | } | |
2087 | return bfd_reloc_dangerous; | |
2088 | } | |
2089 | ||
feee612b AM |
2090 | /* Fix bad default arch selected for a 32 bit input bfd when the |
2091 | default is 64 bit. */ | |
2092 | ||
b34976b6 | 2093 | static bfd_boolean |
feee612b AM |
2094 | ppc_elf_object_p (abfd) |
2095 | bfd *abfd; | |
2096 | { | |
2097 | if (abfd->arch_info->the_default && abfd->arch_info->bits_per_word == 64) | |
2098 | { | |
2099 | Elf_Internal_Ehdr *i_ehdr = elf_elfheader (abfd); | |
2100 | ||
2101 | if (i_ehdr->e_ident[EI_CLASS] == ELFCLASS32) | |
2102 | { | |
2103 | /* Relies on arch after 64 bit default being 32 bit default. */ | |
2104 | abfd->arch_info = abfd->arch_info->next; | |
2105 | BFD_ASSERT (abfd->arch_info->bits_per_word == 32); | |
2106 | } | |
2107 | } | |
b34976b6 | 2108 | return TRUE; |
feee612b AM |
2109 | } |
2110 | ||
c3668558 | 2111 | /* Function to set whether a module needs the -mrelocatable bit set. */ |
252b5132 | 2112 | |
b34976b6 | 2113 | static bfd_boolean |
252b5132 RH |
2114 | ppc_elf_set_private_flags (abfd, flags) |
2115 | bfd *abfd; | |
2116 | flagword flags; | |
2117 | { | |
2118 | BFD_ASSERT (!elf_flags_init (abfd) | |
2119 | || elf_elfheader (abfd)->e_flags == flags); | |
2120 | ||
2121 | elf_elfheader (abfd)->e_flags = flags; | |
b34976b6 AM |
2122 | elf_flags_init (abfd) = TRUE; |
2123 | return TRUE; | |
252b5132 RH |
2124 | } |
2125 | ||
252b5132 | 2126 | /* Merge backend specific data from an object file to the output |
ae9a127f NC |
2127 | object file when linking. */ |
2128 | ||
b34976b6 | 2129 | static bfd_boolean |
252b5132 RH |
2130 | ppc_elf_merge_private_bfd_data (ibfd, obfd) |
2131 | bfd *ibfd; | |
2132 | bfd *obfd; | |
2133 | { | |
2134 | flagword old_flags; | |
2135 | flagword new_flags; | |
b34976b6 | 2136 | bfd_boolean error; |
252b5132 | 2137 | |
ae9a127f | 2138 | /* Check if we have the same endianess. */ |
82e51918 | 2139 | if (! _bfd_generic_verify_endian_match (ibfd, obfd)) |
b34976b6 | 2140 | return FALSE; |
252b5132 RH |
2141 | |
2142 | if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour | |
2143 | || bfd_get_flavour (obfd) != bfd_target_elf_flavour) | |
b34976b6 | 2144 | return TRUE; |
252b5132 RH |
2145 | |
2146 | new_flags = elf_elfheader (ibfd)->e_flags; | |
2147 | old_flags = elf_elfheader (obfd)->e_flags; | |
70bccea4 | 2148 | if (!elf_flags_init (obfd)) |
252b5132 | 2149 | { |
70bccea4 | 2150 | /* First call, no flags set. */ |
b34976b6 | 2151 | elf_flags_init (obfd) = TRUE; |
252b5132 RH |
2152 | elf_elfheader (obfd)->e_flags = new_flags; |
2153 | } | |
2154 | ||
70bccea4 AM |
2155 | /* Compatible flags are ok. */ |
2156 | else if (new_flags == old_flags) | |
252b5132 RH |
2157 | ; |
2158 | ||
70bccea4 AM |
2159 | /* Incompatible flags. */ |
2160 | else | |
252b5132 | 2161 | { |
70bccea4 AM |
2162 | /* Warn about -mrelocatable mismatch. Allow -mrelocatable-lib |
2163 | to be linked with either. */ | |
b34976b6 | 2164 | error = FALSE; |
252b5132 RH |
2165 | if ((new_flags & EF_PPC_RELOCATABLE) != 0 |
2166 | && (old_flags & (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB)) == 0) | |
2167 | { | |
b34976b6 | 2168 | error = TRUE; |
252b5132 RH |
2169 | (*_bfd_error_handler) |
2170 | (_("%s: compiled with -mrelocatable and linked with modules compiled normally"), | |
8f615d07 | 2171 | bfd_archive_filename (ibfd)); |
252b5132 RH |
2172 | } |
2173 | else if ((new_flags & (EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB)) == 0 | |
2174 | && (old_flags & EF_PPC_RELOCATABLE) != 0) | |
2175 | { | |
b34976b6 | 2176 | error = TRUE; |
252b5132 RH |
2177 | (*_bfd_error_handler) |
2178 | (_("%s: compiled normally and linked with modules compiled with -mrelocatable"), | |
8f615d07 | 2179 | bfd_archive_filename (ibfd)); |
252b5132 RH |
2180 | } |
2181 | ||
2182 | /* The output is -mrelocatable-lib iff both the input files are. */ | |
2183 | if (! (new_flags & EF_PPC_RELOCATABLE_LIB)) | |
2184 | elf_elfheader (obfd)->e_flags &= ~EF_PPC_RELOCATABLE_LIB; | |
2185 | ||
2186 | /* The output is -mrelocatable iff it can't be -mrelocatable-lib, | |
70bccea4 | 2187 | but each input file is either -mrelocatable or -mrelocatable-lib. */ |
252b5132 RH |
2188 | if (! (elf_elfheader (obfd)->e_flags & EF_PPC_RELOCATABLE_LIB) |
2189 | && (new_flags & (EF_PPC_RELOCATABLE_LIB | EF_PPC_RELOCATABLE)) | |
2190 | && (old_flags & (EF_PPC_RELOCATABLE_LIB | EF_PPC_RELOCATABLE))) | |
2191 | elf_elfheader (obfd)->e_flags |= EF_PPC_RELOCATABLE; | |
2192 | ||
70bccea4 AM |
2193 | /* Do not warn about eabi vs. V.4 mismatch, just or in the bit if |
2194 | any module uses it. */ | |
252b5132 RH |
2195 | elf_elfheader (obfd)->e_flags |= (new_flags & EF_PPC_EMB); |
2196 | ||
70bccea4 AM |
2197 | new_flags &= ~(EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB | EF_PPC_EMB); |
2198 | old_flags &= ~(EF_PPC_RELOCATABLE | EF_PPC_RELOCATABLE_LIB | EF_PPC_EMB); | |
252b5132 | 2199 | |
ae9a127f | 2200 | /* Warn about any other mismatches. */ |
252b5132 RH |
2201 | if (new_flags != old_flags) |
2202 | { | |
b34976b6 | 2203 | error = TRUE; |
252b5132 RH |
2204 | (*_bfd_error_handler) |
2205 | (_("%s: uses different e_flags (0x%lx) fields than previous modules (0x%lx)"), | |
8f615d07 | 2206 | bfd_archive_filename (ibfd), (long) new_flags, (long) old_flags); |
252b5132 RH |
2207 | } |
2208 | ||
2209 | if (error) | |
2210 | { | |
2211 | bfd_set_error (bfd_error_bad_value); | |
b34976b6 | 2212 | return FALSE; |
252b5132 RH |
2213 | } |
2214 | } | |
2215 | ||
b34976b6 | 2216 | return TRUE; |
252b5132 | 2217 | } |
252b5132 RH |
2218 | \f |
2219 | /* Handle a PowerPC specific section when reading an object file. This | |
2220 | is called when elfcode.h finds a section with an unknown type. */ | |
2221 | ||
b34976b6 | 2222 | static bfd_boolean |
252b5132 RH |
2223 | ppc_elf_section_from_shdr (abfd, hdr, name) |
2224 | bfd *abfd; | |
947216bf | 2225 | Elf_Internal_Shdr *hdr; |
90937f86 | 2226 | const char *name; |
252b5132 RH |
2227 | { |
2228 | asection *newsect; | |
2229 | flagword flags; | |
2230 | ||
2231 | if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name)) | |
b34976b6 | 2232 | return FALSE; |
252b5132 RH |
2233 | |
2234 | newsect = hdr->bfd_section; | |
2235 | flags = bfd_get_section_flags (abfd, newsect); | |
2236 | if (hdr->sh_flags & SHF_EXCLUDE) | |
2237 | flags |= SEC_EXCLUDE; | |
2238 | ||
2239 | if (hdr->sh_type == SHT_ORDERED) | |
2240 | flags |= SEC_SORT_ENTRIES; | |
2241 | ||
2242 | bfd_set_section_flags (abfd, newsect, flags); | |
b34976b6 | 2243 | return TRUE; |
252b5132 | 2244 | } |
252b5132 RH |
2245 | \f |
2246 | /* Set up any other section flags and such that may be necessary. */ | |
2247 | ||
b34976b6 | 2248 | static bfd_boolean |
252b5132 | 2249 | ppc_elf_fake_sections (abfd, shdr, asect) |
5f771d47 | 2250 | bfd *abfd ATTRIBUTE_UNUSED; |
947216bf | 2251 | Elf_Internal_Shdr *shdr; |
252b5132 RH |
2252 | asection *asect; |
2253 | { | |
2254 | if ((asect->flags & SEC_EXCLUDE) != 0) | |
2255 | shdr->sh_flags |= SHF_EXCLUDE; | |
2256 | ||
2257 | if ((asect->flags & SEC_SORT_ENTRIES) != 0) | |
2258 | shdr->sh_type = SHT_ORDERED; | |
2259 | ||
b34976b6 | 2260 | return TRUE; |
252b5132 | 2261 | } |
252b5132 RH |
2262 | \f |
2263 | /* Create a special linker section */ | |
2264 | static elf_linker_section_t * | |
2265 | ppc_elf_create_linker_section (abfd, info, which) | |
2266 | bfd *abfd; | |
2267 | struct bfd_link_info *info; | |
2268 | enum elf_linker_section_enum which; | |
2269 | { | |
2270 | bfd *dynobj = elf_hash_table (info)->dynobj; | |
2271 | elf_linker_section_t *lsect; | |
2272 | ||
ae9a127f | 2273 | /* Record the first bfd section that needs the special section. */ |
252b5132 RH |
2274 | if (!dynobj) |
2275 | dynobj = elf_hash_table (info)->dynobj = abfd; | |
2276 | ||
ae9a127f | 2277 | /* If this is the first time, create the section. */ |
252b5132 RH |
2278 | lsect = elf_linker_section (dynobj, which); |
2279 | if (!lsect) | |
2280 | { | |
2281 | elf_linker_section_t defaults; | |
2282 | static elf_linker_section_t zero_section; | |
2283 | ||
2284 | defaults = zero_section; | |
2285 | defaults.which = which; | |
b34976b6 | 2286 | defaults.hole_written_p = FALSE; |
252b5132 RH |
2287 | defaults.alignment = 2; |
2288 | ||
2289 | /* Both of these sections are (technically) created by the user | |
2290 | putting data in them, so they shouldn't be marked | |
2291 | SEC_LINKER_CREATED. | |
2292 | ||
2293 | The linker creates them so it has somewhere to attach their | |
2294 | respective symbols. In fact, if they were empty it would | |
2295 | be OK to leave the symbol set to 0 (or any random number), because | |
2296 | the appropriate register should never be used. */ | |
2297 | defaults.flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | |
2298 | | SEC_IN_MEMORY); | |
2299 | ||
2300 | switch (which) | |
2301 | { | |
2302 | default: | |
7b609f53 | 2303 | (*_bfd_error_handler) (_("%s: unknown special linker type %d"), |
252b5132 | 2304 | bfd_get_filename (abfd), |
8da6118f | 2305 | (int) which); |
252b5132 RH |
2306 | |
2307 | bfd_set_error (bfd_error_bad_value); | |
8da6118f | 2308 | return (elf_linker_section_t *) 0; |
252b5132 RH |
2309 | |
2310 | case LINKER_SECTION_SDATA: /* .sdata/.sbss section */ | |
2311 | defaults.name = ".sdata"; | |
2312 | defaults.rel_name = ".rela.sdata"; | |
2313 | defaults.bss_name = ".sbss"; | |
2314 | defaults.sym_name = "_SDA_BASE_"; | |
2315 | defaults.sym_offset = 32768; | |
2316 | break; | |
2317 | ||
2318 | case LINKER_SECTION_SDATA2: /* .sdata2/.sbss2 section */ | |
2319 | defaults.name = ".sdata2"; | |
2320 | defaults.rel_name = ".rela.sdata2"; | |
2321 | defaults.bss_name = ".sbss2"; | |
2322 | defaults.sym_name = "_SDA2_BASE_"; | |
2323 | defaults.sym_offset = 32768; | |
2324 | defaults.flags |= SEC_READONLY; | |
2325 | break; | |
2326 | } | |
2327 | ||
2328 | lsect = _bfd_elf_create_linker_section (abfd, info, which, &defaults); | |
2329 | } | |
2330 | ||
2331 | return lsect; | |
2332 | } | |
252b5132 | 2333 | \f |
8da6118f KH |
2334 | /* If we have a non-zero sized .sbss2 or .PPC.EMB.sbss0 sections, we |
2335 | need to bump up the number of section headers. */ | |
252b5132 RH |
2336 | |
2337 | static int | |
2338 | ppc_elf_additional_program_headers (abfd) | |
2339 | bfd *abfd; | |
2340 | { | |
2341 | asection *s; | |
2342 | int ret; | |
2343 | ||
2344 | ret = 0; | |
2345 | ||
2346 | s = bfd_get_section_by_name (abfd, ".interp"); | |
2347 | if (s != NULL) | |
2348 | ++ret; | |
2349 | ||
2350 | s = bfd_get_section_by_name (abfd, ".sbss2"); | |
2351 | if (s != NULL && (s->flags & SEC_LOAD) != 0 && s->_raw_size > 0) | |
2352 | ++ret; | |
2353 | ||
2354 | s = bfd_get_section_by_name (abfd, ".PPC.EMB.sbss0"); | |
2355 | if (s != NULL && (s->flags & SEC_LOAD) != 0 && s->_raw_size > 0) | |
2356 | ++ret; | |
2357 | ||
2358 | return ret; | |
2359 | } | |
2360 | ||
8da6118f | 2361 | /* Modify the segment map if needed. */ |
252b5132 | 2362 | |
b34976b6 | 2363 | static bfd_boolean |
252b5132 | 2364 | ppc_elf_modify_segment_map (abfd) |
5f771d47 | 2365 | bfd *abfd ATTRIBUTE_UNUSED; |
252b5132 | 2366 | { |
b34976b6 | 2367 | return TRUE; |
252b5132 RH |
2368 | } |
2369 | \f | |
41fcb14e AM |
2370 | /* The powerpc .got has a blrl instruction in it. Mark it executable. */ |
2371 | ||
7619e7c7 | 2372 | static bfd_boolean |
41fcb14e AM |
2373 | ppc_elf_create_got (abfd, info) |
2374 | bfd *abfd; | |
2375 | struct bfd_link_info *info; | |
2376 | { | |
7619e7c7 AM |
2377 | struct ppc_elf_link_hash_table *htab; |
2378 | asection *s; | |
41fcb14e AM |
2379 | flagword flags; |
2380 | ||
2381 | if (!_bfd_elf_create_got_section (abfd, info)) | |
7619e7c7 | 2382 | return FALSE; |
41fcb14e | 2383 | |
7619e7c7 AM |
2384 | htab = ppc_elf_hash_table (info); |
2385 | htab->got = s = bfd_get_section_by_name (abfd, ".got"); | |
41fcb14e AM |
2386 | if (s == NULL) |
2387 | abort (); | |
2388 | ||
2389 | flags = (SEC_ALLOC | SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS | SEC_IN_MEMORY | |
2390 | | SEC_LINKER_CREATED); | |
2391 | if (!bfd_set_section_flags (abfd, s, flags)) | |
7619e7c7 AM |
2392 | return FALSE; |
2393 | ||
2394 | htab->relgot = bfd_make_section (abfd, ".rela.got"); | |
2395 | if (!htab->relgot | |
2396 | || ! bfd_set_section_flags (abfd, htab->relgot, | |
2397 | (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | |
2398 | | SEC_IN_MEMORY | SEC_LINKER_CREATED | |
2399 | | SEC_READONLY)) | |
2400 | || ! bfd_set_section_alignment (abfd, htab->relgot, 2)) | |
2401 | return FALSE; | |
2402 | ||
2403 | return TRUE; | |
41fcb14e AM |
2404 | } |
2405 | ||
252b5132 RH |
2406 | /* We have to create .dynsbss and .rela.sbss here so that they get mapped |
2407 | to output sections (just like _bfd_elf_create_dynamic_sections has | |
2408 | to create .dynbss and .rela.bss). */ | |
2409 | ||
b34976b6 | 2410 | static bfd_boolean |
252b5132 RH |
2411 | ppc_elf_create_dynamic_sections (abfd, info) |
2412 | bfd *abfd; | |
2413 | struct bfd_link_info *info; | |
2414 | { | |
7619e7c7 AM |
2415 | struct ppc_elf_link_hash_table *htab; |
2416 | asection *s; | |
252b5132 RH |
2417 | flagword flags; |
2418 | ||
41fcb14e | 2419 | if (!ppc_elf_create_got (abfd, info)) |
b34976b6 | 2420 | return FALSE; |
41fcb14e | 2421 | |
8da6118f | 2422 | if (!_bfd_elf_create_dynamic_sections (abfd, info)) |
b34976b6 | 2423 | return FALSE; |
252b5132 RH |
2424 | |
2425 | flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY | |
2426 | | SEC_LINKER_CREATED); | |
2427 | ||
7619e7c7 AM |
2428 | htab = ppc_elf_hash_table (info); |
2429 | htab->dynbss = bfd_get_section_by_name (abfd, ".dynbss"); | |
2430 | htab->dynsbss = s = bfd_make_section (abfd, ".dynsbss"); | |
252b5132 RH |
2431 | if (s == NULL |
2432 | || ! bfd_set_section_flags (abfd, s, SEC_ALLOC)) | |
b34976b6 | 2433 | return FALSE; |
252b5132 RH |
2434 | |
2435 | if (! info->shared) | |
2436 | { | |
7619e7c7 AM |
2437 | htab->relbss = bfd_get_section_by_name (abfd, ".rela.bss"); |
2438 | htab->relsbss = s = bfd_make_section (abfd, ".rela.sbss"); | |
252b5132 RH |
2439 | if (s == NULL |
2440 | || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY) | |
2441 | || ! bfd_set_section_alignment (abfd, s, 2)) | |
b34976b6 | 2442 | return FALSE; |
252b5132 | 2443 | } |
41fcb14e | 2444 | |
7619e7c7 AM |
2445 | htab->relplt = bfd_get_section_by_name (abfd, ".rela.plt"); |
2446 | htab->plt = s = bfd_get_section_by_name (abfd, ".plt"); | |
41fcb14e AM |
2447 | if (s == NULL) |
2448 | abort (); | |
2449 | ||
2450 | flags = SEC_ALLOC | SEC_CODE | SEC_IN_MEMORY | SEC_LINKER_CREATED; | |
2451 | return bfd_set_section_flags (abfd, s, flags); | |
252b5132 RH |
2452 | } |
2453 | ||
ee05f2fe AM |
2454 | /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid |
2455 | copying dynamic variables from a shared lib into an app's dynbss | |
2456 | section, and instead use a dynamic relocation to point into the | |
2457 | shared lib. */ | |
a23b6845 | 2458 | #define ELIMINATE_COPY_RELOCS 1 |
ee05f2fe | 2459 | |
252b5132 RH |
2460 | /* Adjust a symbol defined by a dynamic object and referenced by a |
2461 | regular object. The current definition is in some section of the | |
2462 | dynamic object, but we're not including those sections. We have to | |
2463 | change the definition to something the rest of the link can | |
2464 | understand. */ | |
2465 | ||
b34976b6 | 2466 | static bfd_boolean |
252b5132 RH |
2467 | ppc_elf_adjust_dynamic_symbol (info, h) |
2468 | struct bfd_link_info *info; | |
2469 | struct elf_link_hash_entry *h; | |
2470 | { | |
7619e7c7 | 2471 | struct ppc_elf_link_hash_table *htab; |
252b5132 RH |
2472 | asection *s; |
2473 | unsigned int power_of_two; | |
252b5132 RH |
2474 | |
2475 | #ifdef DEBUG | |
70bccea4 AM |
2476 | fprintf (stderr, "ppc_elf_adjust_dynamic_symbol called for %s\n", |
2477 | h->root.root.string); | |
252b5132 RH |
2478 | #endif |
2479 | ||
2480 | /* Make sure we know what is going on here. */ | |
7619e7c7 AM |
2481 | htab = ppc_elf_hash_table (info); |
2482 | BFD_ASSERT (htab->elf.dynobj != NULL | |
252b5132 RH |
2483 | && ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) |
2484 | || h->weakdef != NULL | |
2485 | || ((h->elf_link_hash_flags | |
2486 | & ELF_LINK_HASH_DEF_DYNAMIC) != 0 | |
2487 | && (h->elf_link_hash_flags | |
2488 | & ELF_LINK_HASH_REF_REGULAR) != 0 | |
2489 | && (h->elf_link_hash_flags | |
2490 | & ELF_LINK_HASH_DEF_REGULAR) == 0))); | |
2491 | ||
7619e7c7 | 2492 | /* Deal with function syms. */ |
252b5132 RH |
2493 | if (h->type == STT_FUNC |
2494 | || (h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0) | |
2495 | { | |
7619e7c7 AM |
2496 | /* Clear procedure linkage table information for any symbol that |
2497 | won't need a .plt entry. */ | |
2498 | if (! htab->elf.dynamic_sections_created | |
e1e0340b | 2499 | || SYMBOL_CALLS_LOCAL (info, h) |
7619e7c7 | 2500 | || h->plt.refcount <= 0) |
252b5132 RH |
2501 | { |
2502 | /* A PLT entry is not required/allowed when: | |
2503 | ||
70bccea4 AM |
2504 | 1. We are not using ld.so; because then the PLT entry |
2505 | can't be set up, so we can't use one. | |
252b5132 | 2506 | |
70bccea4 AM |
2507 | 2. We know for certain that a call to this symbol |
2508 | will go to this object. | |
252b5132 | 2509 | |
70bccea4 | 2510 | 3. GC has rendered the entry unused. */ |
252b5132 RH |
2511 | h->plt.offset = (bfd_vma) -1; |
2512 | h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT; | |
252b5132 | 2513 | } |
b34976b6 | 2514 | return TRUE; |
252b5132 | 2515 | } |
bbd7ec4a AM |
2516 | else |
2517 | h->plt.offset = (bfd_vma) -1; | |
252b5132 RH |
2518 | |
2519 | /* If this is a weak symbol, and there is a real definition, the | |
2520 | processor independent code will have arranged for us to see the | |
2521 | real definition first, and we can just use the same value. */ | |
2522 | if (h->weakdef != NULL) | |
2523 | { | |
2524 | BFD_ASSERT (h->weakdef->root.type == bfd_link_hash_defined | |
2525 | || h->weakdef->root.type == bfd_link_hash_defweak); | |
2526 | h->root.u.def.section = h->weakdef->root.u.def.section; | |
2527 | h->root.u.def.value = h->weakdef->root.u.def.value; | |
a23b6845 AM |
2528 | if (ELIMINATE_COPY_RELOCS) |
2529 | h->elf_link_hash_flags | |
2530 | = ((h->elf_link_hash_flags & ~ELF_LINK_NON_GOT_REF) | |
2531 | | (h->weakdef->elf_link_hash_flags & ELF_LINK_NON_GOT_REF)); | |
b34976b6 | 2532 | return TRUE; |
252b5132 RH |
2533 | } |
2534 | ||
2535 | /* This is a reference to a symbol defined by a dynamic object which | |
2536 | is not a function. */ | |
2537 | ||
2538 | /* If we are creating a shared library, we must presume that the | |
2539 | only references to the symbol are via the global offset table. | |
2540 | For such cases we need not do anything here; the relocations will | |
2541 | be handled correctly by relocate_section. */ | |
2542 | if (info->shared) | |
b34976b6 | 2543 | return TRUE; |
252b5132 | 2544 | |
7619e7c7 AM |
2545 | /* If there are no references to this symbol that do not use the |
2546 | GOT, we don't need to generate a copy reloc. */ | |
2547 | if ((h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0) | |
2548 | return TRUE; | |
2549 | ||
ee05f2fe AM |
2550 | if (ELIMINATE_COPY_RELOCS) |
2551 | { | |
2552 | struct ppc_elf_dyn_relocs *p; | |
2553 | for (p = ppc_elf_hash_entry (h)->dyn_relocs; p != NULL; p = p->next) | |
2554 | { | |
2555 | s = p->sec->output_section; | |
2556 | if (s != NULL && (s->flags & SEC_READONLY) != 0) | |
2557 | break; | |
2558 | } | |
2559 | ||
2560 | /* If we didn't find any dynamic relocs in read-only sections, then | |
2561 | we'll be keeping the dynamic relocs and avoiding the copy reloc. */ | |
2562 | if (p == NULL) | |
2563 | { | |
2564 | h->elf_link_hash_flags &= ~ELF_LINK_NON_GOT_REF; | |
2565 | return TRUE; | |
2566 | } | |
2567 | } | |
2568 | ||
252b5132 RH |
2569 | /* We must allocate the symbol in our .dynbss section, which will |
2570 | become part of the .bss section of the executable. There will be | |
2571 | an entry for this symbol in the .dynsym section. The dynamic | |
2572 | object will contain position independent code, so all references | |
2573 | from the dynamic object to this symbol will go through the global | |
2574 | offset table. The dynamic linker will use the .dynsym entry to | |
2575 | determine the address it must put in the global offset table, so | |
2576 | both the dynamic object and the regular object will refer to the | |
2577 | same memory location for the variable. | |
2578 | ||
2579 | Of course, if the symbol is sufficiently small, we must instead | |
2580 | allocate it in .sbss. FIXME: It would be better to do this if and | |
2581 | only if there were actually SDAREL relocs for that symbol. */ | |
2582 | ||
7619e7c7 AM |
2583 | if (h->size <= elf_gp_size (htab->elf.dynobj)) |
2584 | s = htab->dynsbss; | |
252b5132 | 2585 | else |
7619e7c7 | 2586 | s = htab->dynbss; |
252b5132 RH |
2587 | BFD_ASSERT (s != NULL); |
2588 | ||
2589 | /* We must generate a R_PPC_COPY reloc to tell the dynamic linker to | |
2590 | copy the initial value out of the dynamic object and into the | |
2591 | runtime process image. We need to remember the offset into the | |
2592 | .rela.bss section we are going to use. */ | |
2593 | if ((h->root.u.def.section->flags & SEC_ALLOC) != 0) | |
2594 | { | |
2595 | asection *srel; | |
2596 | ||
7619e7c7 AM |
2597 | if (h->size <= elf_gp_size (htab->elf.dynobj)) |
2598 | srel = htab->relsbss; | |
252b5132 | 2599 | else |
7619e7c7 | 2600 | srel = htab->relbss; |
252b5132 RH |
2601 | BFD_ASSERT (srel != NULL); |
2602 | srel->_raw_size += sizeof (Elf32_External_Rela); | |
2603 | h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_COPY; | |
2604 | } | |
2605 | ||
2606 | /* We need to figure out the alignment required for this symbol. I | |
2607 | have no idea how ELF linkers handle this. */ | |
2608 | power_of_two = bfd_log2 (h->size); | |
2609 | if (power_of_two > 4) | |
2610 | power_of_two = 4; | |
2611 | ||
2612 | /* Apply the required alignment. */ | |
2613 | s->_raw_size = BFD_ALIGN (s->_raw_size, | |
2614 | (bfd_size_type) (1 << power_of_two)); | |
7619e7c7 | 2615 | if (power_of_two > bfd_get_section_alignment (htab->elf.dynobj, s)) |
252b5132 | 2616 | { |
7619e7c7 | 2617 | if (! bfd_set_section_alignment (htab->elf.dynobj, s, power_of_two)) |
b34976b6 | 2618 | return FALSE; |
252b5132 RH |
2619 | } |
2620 | ||
2621 | /* Define the symbol as being at this point in the section. */ | |
2622 | h->root.u.def.section = s; | |
2623 | h->root.u.def.value = s->_raw_size; | |
2624 | ||
2625 | /* Increment the section size to make room for the symbol. */ | |
2626 | s->_raw_size += h->size; | |
2627 | ||
b34976b6 | 2628 | return TRUE; |
252b5132 | 2629 | } |
252b5132 | 2630 | \f |
7619e7c7 AM |
2631 | /* This is the condition under which finish_dynamic_symbol will be |
2632 | called from elflink.h. If elflink.h doesn't call our | |
2633 | finish_dynamic_symbol routine, we'll need to do something about | |
2634 | initializing any .plt and .got entries in relocate_section. */ | |
ee05f2fe | 2635 | #define WILL_CALL_FINISH_DYNAMIC_SYMBOL(DYN, SHARED, H) \ |
7619e7c7 | 2636 | ((DYN) \ |
ee05f2fe | 2637 | && ((SHARED) \ |
7619e7c7 AM |
2638 | || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) \ |
2639 | && ((H)->dynindx != -1 \ | |
2640 | || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0)) | |
2641 | ||
ee05f2fe AM |
2642 | /* Of those relocs that might be copied as dynamic relocs, this macro |
2643 | selects those that must be copied when linking a shared library, | |
2644 | even when the symbol is local. */ | |
2645 | ||
2646 | #define MUST_BE_DYN_RELOC(RTYPE) \ | |
2647 | ((RTYPE) != R_PPC_REL24 \ | |
2648 | && (RTYPE) != R_PPC_REL14 \ | |
2649 | && (RTYPE) != R_PPC_REL14_BRTAKEN \ | |
2650 | && (RTYPE) != R_PPC_REL14_BRNTAKEN \ | |
2651 | && (RTYPE) != R_PPC_REL32) | |
2652 | ||
7fce784e AS |
2653 | /* Allocate space in associated reloc sections for dynamic relocs. */ |
2654 | ||
7619e7c7 AM |
2655 | static bfd_boolean |
2656 | allocate_dynrelocs (h, inf) | |
2657 | struct elf_link_hash_entry *h; | |
2658 | PTR inf; | |
2659 | { | |
2660 | struct bfd_link_info *info = (struct bfd_link_info *) inf; | |
2661 | struct ppc_elf_link_hash_entry *eh; | |
2662 | struct ppc_elf_link_hash_table *htab; | |
2663 | struct ppc_elf_dyn_relocs *p; | |
2664 | ||
2665 | if (h->root.type == bfd_link_hash_indirect) | |
2666 | return TRUE; | |
2667 | ||
2668 | if (h->root.type == bfd_link_hash_warning) | |
2669 | /* When warning symbols are created, they **replace** the "real" | |
2670 | entry in the hash table, thus we never get to see the real | |
2671 | symbol in a hash traversal. So look at it now. */ | |
2672 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
2673 | ||
2674 | htab = ppc_elf_hash_table (info); | |
2675 | if (htab->elf.dynamic_sections_created | |
2676 | && h->plt.refcount > 0) | |
2677 | { | |
2678 | /* Make sure this symbol is output as a dynamic symbol. */ | |
2679 | if (h->dynindx == -1 | |
2680 | && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) | |
2681 | { | |
2682 | if (! bfd_elf32_link_record_dynamic_symbol (info, h)) | |
2683 | return FALSE; | |
2684 | } | |
2685 | ||
ee05f2fe AM |
2686 | if (info->shared |
2687 | || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h)) | |
7619e7c7 AM |
2688 | { |
2689 | asection *s = htab->plt; | |
2690 | ||
2691 | /* If this is the first .plt entry, make room for the special | |
2692 | first entry. */ | |
2693 | if (s->_raw_size == 0) | |
2694 | s->_raw_size += PLT_INITIAL_ENTRY_SIZE; | |
2695 | ||
2696 | /* The PowerPC PLT is actually composed of two parts, the | |
2697 | first part is 2 words (for a load and a jump), and then | |
2698 | there is a remaining word available at the end. */ | |
2699 | h->plt.offset = (PLT_INITIAL_ENTRY_SIZE | |
2700 | + (PLT_SLOT_SIZE | |
2701 | * ((s->_raw_size - PLT_INITIAL_ENTRY_SIZE) | |
2702 | / PLT_ENTRY_SIZE))); | |
2703 | ||
2704 | /* If this symbol is not defined in a regular file, and we | |
2705 | are not generating a shared library, then set the symbol | |
2706 | to this location in the .plt. This is required to make | |
2707 | function pointers compare as equal between the normal | |
2708 | executable and the shared library. */ | |
2709 | if (! info->shared | |
2710 | && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0) | |
2711 | { | |
2712 | h->root.u.def.section = s; | |
2713 | h->root.u.def.value = h->plt.offset; | |
2714 | } | |
2715 | ||
2716 | /* Make room for this entry. After the 8192nd entry, room | |
2717 | for two entries is allocated. */ | |
2718 | s->_raw_size += PLT_ENTRY_SIZE; | |
2719 | if ((s->_raw_size - PLT_INITIAL_ENTRY_SIZE) / PLT_ENTRY_SIZE | |
2720 | >= PLT_NUM_SINGLE_ENTRIES) | |
2721 | s->_raw_size += PLT_ENTRY_SIZE; | |
2722 | ||
2723 | /* We also need to make an entry in the .rela.plt section. */ | |
2724 | htab->relplt->_raw_size += sizeof (Elf32_External_Rela); | |
2725 | } | |
2726 | else | |
2727 | { | |
2728 | h->plt.offset = (bfd_vma) -1; | |
2729 | h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT; | |
2730 | } | |
2731 | } | |
2732 | else | |
2733 | { | |
2734 | h->plt.offset = (bfd_vma) -1; | |
2735 | h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT; | |
2736 | } | |
7fce784e | 2737 | |
7619e7c7 AM |
2738 | eh = (struct ppc_elf_link_hash_entry *) h; |
2739 | if (eh->elf.got.refcount > 0) | |
2740 | { | |
2741 | /* Make sure this symbol is output as a dynamic symbol. */ | |
2742 | if (eh->elf.dynindx == -1 | |
2743 | && (eh->elf.elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) | |
2744 | { | |
2745 | if (!bfd_elf32_link_record_dynamic_symbol (info, &eh->elf)) | |
2746 | return FALSE; | |
2747 | } | |
7fce784e | 2748 | |
7619e7c7 AM |
2749 | if (eh->tls_mask == (TLS_TLS | TLS_LD) |
2750 | && !(eh->elf.elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC)) | |
2751 | /* If just an LD reloc, we'll just use htab->tlsld_got.offset. */ | |
2752 | eh->elf.got.offset = (bfd_vma) -1; | |
2753 | else | |
2754 | { | |
2755 | bfd_boolean dyn; | |
2756 | eh->elf.got.offset = htab->got->_raw_size; | |
2757 | if ((eh->tls_mask & TLS_TLS) != 0) | |
2758 | { | |
70bccea4 AM |
2759 | if ((eh->tls_mask & TLS_LD) != 0) |
2760 | htab->got->_raw_size += 8; | |
2761 | if ((eh->tls_mask & TLS_GD) != 0) | |
7619e7c7 AM |
2762 | htab->got->_raw_size += 8; |
2763 | if ((eh->tls_mask & (TLS_TPREL | TLS_TPRELGD)) != 0) | |
2764 | htab->got->_raw_size += 4; | |
2765 | if ((eh->tls_mask & TLS_DTPREL) != 0) | |
2766 | htab->got->_raw_size += 4; | |
2767 | } | |
2768 | else | |
2769 | htab->got->_raw_size += 4; | |
2770 | dyn = htab->elf.dynamic_sections_created; | |
ee05f2fe AM |
2771 | if (info->shared |
2772 | || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, &eh->elf)) | |
7619e7c7 AM |
2773 | { |
2774 | /* All the entries we allocated need relocs. */ | |
2775 | htab->relgot->_raw_size | |
2776 | += ((htab->got->_raw_size - eh->elf.got.offset) / 4 | |
2777 | * sizeof (Elf32_External_Rela)); | |
2778 | /* Except LD only needs one. */ | |
2779 | if ((eh->tls_mask & TLS_LD) != 0) | |
2780 | htab->relgot->_raw_size -= sizeof (Elf32_External_Rela); | |
2781 | } | |
2782 | } | |
2783 | } | |
2784 | else | |
2785 | eh->elf.got.offset = (bfd_vma) -1; | |
7fce784e | 2786 | |
ee05f2fe AM |
2787 | if (eh->dyn_relocs == NULL) |
2788 | return TRUE; | |
2789 | ||
2790 | /* In the shared -Bsymbolic case, discard space allocated for | |
2791 | dynamic pc-relative relocs against symbols which turn out to be | |
2792 | defined in regular objects. For the normal shared case, discard | |
2793 | space for relocs that have become local due to symbol visibility | |
2794 | changes. */ | |
2795 | if (info->shared) | |
2796 | { | |
2797 | if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) != 0 | |
2798 | && ((h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0 | |
2799 | || info->symbolic)) | |
2800 | { | |
2801 | struct ppc_elf_dyn_relocs **pp; | |
2802 | ||
2803 | for (pp = &eh->dyn_relocs; (p = *pp) != NULL; ) | |
2804 | { | |
2805 | p->count -= p->pc_count; | |
2806 | p->pc_count = 0; | |
2807 | if (p->count == 0) | |
2808 | *pp = p->next; | |
2809 | else | |
2810 | pp = &p->next; | |
2811 | } | |
2812 | } | |
2813 | } | |
2814 | else if (ELIMINATE_COPY_RELOCS) | |
2815 | { | |
2816 | /* For the non-shared case, discard space for relocs against | |
2817 | symbols which turn out to need copy relocs or are not | |
2818 | dynamic. */ | |
2819 | ||
2820 | if ((h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0 | |
2821 | && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0 | |
2822 | && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0) | |
2823 | { | |
2824 | /* Make sure this symbol is output as a dynamic symbol. | |
2825 | Undefined weak syms won't yet be marked as dynamic. */ | |
2826 | if (h->dynindx == -1 | |
2827 | && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) | |
2828 | { | |
2829 | if (! bfd_elf64_link_record_dynamic_symbol (info, h)) | |
2830 | return FALSE; | |
2831 | } | |
2832 | ||
2833 | /* If that succeeded, we know we'll be keeping all the | |
2834 | relocs. */ | |
2835 | if (h->dynindx != -1) | |
2836 | goto keep; | |
2837 | } | |
2838 | ||
2839 | eh->dyn_relocs = NULL; | |
2840 | ||
2841 | keep: ; | |
2842 | } | |
2843 | ||
2844 | /* Finally, allocate space. */ | |
7619e7c7 | 2845 | for (p = eh->dyn_relocs; p != NULL; p = p->next) |
7fce784e AS |
2846 | { |
2847 | asection *sreloc = elf_section_data (p->sec)->sreloc; | |
2848 | sreloc->_raw_size += p->count * sizeof (Elf32_External_Rela); | |
2849 | } | |
2850 | ||
2851 | return TRUE; | |
2852 | } | |
2853 | ||
2854 | /* Find any dynamic relocs that apply to read-only sections. */ | |
2855 | ||
2856 | static bfd_boolean | |
2857 | readonly_dynrelocs (h, info) | |
2858 | struct elf_link_hash_entry *h; | |
2859 | PTR info; | |
2860 | { | |
2861 | struct ppc_elf_dyn_relocs *p; | |
2862 | ||
2863 | if (h->root.type == bfd_link_hash_indirect) | |
2864 | return TRUE; | |
2865 | ||
2866 | if (h->root.type == bfd_link_hash_warning) | |
2867 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
2868 | ||
2869 | for (p = ppc_elf_hash_entry (h)->dyn_relocs; p != NULL; p = p->next) | |
2870 | { | |
2871 | asection *s = p->sec->output_section; | |
2872 | ||
2873 | if (s != NULL | |
2874 | && ((s->flags & (SEC_READONLY | SEC_ALLOC)) | |
2875 | == (SEC_READONLY | SEC_ALLOC))) | |
2876 | { | |
2877 | ((struct bfd_link_info *) info)->flags |= DF_TEXTREL; | |
2878 | ||
2879 | /* Not an error, just cut short the traversal. */ | |
2880 | return FALSE; | |
2881 | } | |
2882 | } | |
2883 | return TRUE; | |
2884 | } | |
2885 | ||
252b5132 RH |
2886 | /* Set the sizes of the dynamic sections. */ |
2887 | ||
b34976b6 | 2888 | static bfd_boolean |
252b5132 | 2889 | ppc_elf_size_dynamic_sections (output_bfd, info) |
29c2fb7c | 2890 | bfd *output_bfd ATTRIBUTE_UNUSED; |
252b5132 RH |
2891 | struct bfd_link_info *info; |
2892 | { | |
7619e7c7 | 2893 | struct ppc_elf_link_hash_table *htab; |
252b5132 | 2894 | asection *s; |
b34976b6 | 2895 | bfd_boolean relocs; |
7fce784e | 2896 | bfd *ibfd; |
252b5132 RH |
2897 | |
2898 | #ifdef DEBUG | |
2899 | fprintf (stderr, "ppc_elf_size_dynamic_sections called\n"); | |
2900 | #endif | |
2901 | ||
7619e7c7 AM |
2902 | htab = ppc_elf_hash_table (info); |
2903 | BFD_ASSERT (htab->elf.dynobj != NULL); | |
252b5132 RH |
2904 | |
2905 | if (elf_hash_table (info)->dynamic_sections_created) | |
2906 | { | |
2907 | /* Set the contents of the .interp section to the interpreter. */ | |
2908 | if (! info->shared) | |
2909 | { | |
7619e7c7 | 2910 | s = bfd_get_section_by_name (htab->elf.dynobj, ".interp"); |
252b5132 RH |
2911 | BFD_ASSERT (s != NULL); |
2912 | s->_raw_size = sizeof ELF_DYNAMIC_INTERPRETER; | |
2913 | s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER; | |
2914 | } | |
2915 | } | |
7619e7c7 AM |
2916 | |
2917 | if (htab->tlsld_got.refcount > 0) | |
252b5132 | 2918 | { |
7619e7c7 AM |
2919 | htab->tlsld_got.offset = htab->got->_raw_size; |
2920 | htab->got->_raw_size += 8; | |
2921 | if (info->shared) | |
2922 | htab->relgot->_raw_size += sizeof (Elf32_External_Rela); | |
252b5132 | 2923 | } |
7619e7c7 AM |
2924 | else |
2925 | htab->tlsld_got.offset = (bfd_vma) -1; | |
252b5132 | 2926 | |
7619e7c7 AM |
2927 | /* Set up .got offsets for local syms, and space for local dynamic |
2928 | relocs. */ | |
7fce784e AS |
2929 | for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next) |
2930 | { | |
7619e7c7 AM |
2931 | bfd_signed_vma *local_got; |
2932 | bfd_signed_vma *end_local_got; | |
2933 | char *lgot_masks; | |
2934 | bfd_size_type locsymcount; | |
2935 | Elf_Internal_Shdr *symtab_hdr; | |
2936 | asection *srel; | |
2937 | ||
7fce784e AS |
2938 | if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour) |
2939 | continue; | |
2940 | ||
2941 | for (s = ibfd->sections; s != NULL; s = s->next) | |
2942 | { | |
2943 | struct ppc_elf_dyn_relocs *p; | |
2944 | ||
2945 | for (p = ((struct ppc_elf_dyn_relocs *) | |
70bccea4 AM |
2946 | elf_section_data (s)->local_dynrel); |
2947 | p != NULL; | |
2948 | p = p->next) | |
7fce784e AS |
2949 | { |
2950 | if (!bfd_is_abs_section (p->sec) | |
2951 | && bfd_is_abs_section (p->sec->output_section)) | |
2952 | { | |
2953 | /* Input section has been discarded, either because | |
2954 | it is a copy of a linkonce section or due to | |
2955 | linker script /DISCARD/, so we'll be discarding | |
2956 | the relocs too. */ | |
2957 | } | |
2958 | else if (p->count != 0) | |
2959 | { | |
2960 | elf_section_data (p->sec)->sreloc->_raw_size | |
2961 | += p->count * sizeof (Elf32_External_Rela); | |
2962 | if ((p->sec->output_section->flags | |
2963 | & (SEC_READONLY | SEC_ALLOC)) | |
2964 | == (SEC_READONLY | SEC_ALLOC)) | |
2965 | info->flags |= DF_TEXTREL; | |
2966 | } | |
2967 | } | |
2968 | } | |
7619e7c7 AM |
2969 | |
2970 | local_got = elf_local_got_refcounts (ibfd); | |
2971 | if (!local_got) | |
2972 | continue; | |
2973 | ||
2974 | symtab_hdr = &elf_tdata (ibfd)->symtab_hdr; | |
2975 | locsymcount = symtab_hdr->sh_info; | |
2976 | end_local_got = local_got + locsymcount; | |
2977 | lgot_masks = (char *) end_local_got; | |
2978 | s = htab->got; | |
2979 | srel = htab->relgot; | |
2980 | for (; local_got < end_local_got; ++local_got, ++lgot_masks) | |
2981 | if (*local_got > 0) | |
2982 | { | |
2983 | if (*lgot_masks == (TLS_TLS | TLS_LD)) | |
2984 | { | |
2985 | /* If just an LD reloc, we'll just use | |
2986 | htab->tlsld_got.offset. */ | |
2987 | if (htab->tlsld_got.offset == (bfd_vma) -1) | |
2988 | { | |
2989 | htab->tlsld_got.offset = s->_raw_size; | |
2990 | s->_raw_size += 8; | |
2991 | if (info->shared) | |
2992 | srel->_raw_size += sizeof (Elf32_External_Rela); | |
2993 | } | |
2994 | *local_got = (bfd_vma) -1; | |
2995 | } | |
2996 | else | |
2997 | { | |
2998 | *local_got = s->_raw_size; | |
2999 | if ((*lgot_masks & TLS_TLS) != 0) | |
3000 | { | |
3001 | if ((*lgot_masks & TLS_GD) != 0) | |
3002 | s->_raw_size += 8; | |
3003 | if ((*lgot_masks & (TLS_TPREL | TLS_TPRELGD)) != 0) | |
3004 | s->_raw_size += 4; | |
3005 | if ((*lgot_masks & TLS_DTPREL) != 0) | |
3006 | s->_raw_size += 4; | |
3007 | } | |
3008 | else | |
3009 | s->_raw_size += 4; | |
3010 | if (info->shared) | |
3011 | srel->_raw_size += ((s->_raw_size - *local_got) / 4 | |
3012 | * sizeof (Elf32_External_Rela)); | |
3013 | } | |
3014 | } | |
3015 | else | |
3016 | *local_got = (bfd_vma) -1; | |
7fce784e AS |
3017 | } |
3018 | ||
3019 | /* Allocate space for global sym dynamic relocs. */ | |
7619e7c7 | 3020 | elf_link_hash_traverse (elf_hash_table (info), allocate_dynrelocs, info); |
7fce784e | 3021 | |
7619e7c7 AM |
3022 | /* We've now determined the sizes of the various dynamic sections. |
3023 | Allocate memory for them. */ | |
b34976b6 | 3024 | relocs = FALSE; |
7619e7c7 | 3025 | for (s = htab->elf.dynobj->sections; s != NULL; s = s->next) |
252b5132 | 3026 | { |
252b5132 RH |
3027 | if ((s->flags & SEC_LINKER_CREATED) == 0) |
3028 | continue; | |
3029 | ||
7619e7c7 AM |
3030 | if (s == htab->plt |
3031 | || s == htab->got | |
3032 | || (htab->sdata != NULL && s == htab->sdata->section) | |
3033 | || (htab->sdata2 != NULL && s == htab->sdata2->section)) | |
252b5132 | 3034 | { |
7619e7c7 AM |
3035 | /* Strip this section if we don't need it; see the |
3036 | comment below. */ | |
252b5132 | 3037 | } |
7619e7c7 | 3038 | else if (strncmp (bfd_get_section_name (dynobj, s), ".rela", 5) == 0) |
252b5132 RH |
3039 | { |
3040 | if (s->_raw_size == 0) | |
3041 | { | |
3042 | /* If we don't need this section, strip it from the | |
3043 | output file. This is mostly to handle .rela.bss and | |
3044 | .rela.plt. We must create both sections in | |
3045 | create_dynamic_sections, because they must be created | |
3046 | before the linker maps input sections to output | |
3047 | sections. The linker does that before | |
3048 | adjust_dynamic_symbol is called, and it is that | |
3049 | function which decides whether anything needs to go | |
3050 | into these sections. */ | |
252b5132 RH |
3051 | } |
3052 | else | |
3053 | { | |
c3668558 | 3054 | /* Remember whether there are any relocation sections. */ |
b34976b6 | 3055 | relocs = TRUE; |
252b5132 | 3056 | |
252b5132 RH |
3057 | /* We use the reloc_count field as a counter if we need |
3058 | to copy relocs into the output file. */ | |
3059 | s->reloc_count = 0; | |
3060 | } | |
3061 | } | |
7619e7c7 | 3062 | else |
252b5132 RH |
3063 | { |
3064 | /* It's not one of our sections, so don't allocate space. */ | |
3065 | continue; | |
3066 | } | |
3067 | ||
7619e7c7 | 3068 | if (s->_raw_size == 0) |
252b5132 | 3069 | { |
7f8d5fc9 | 3070 | _bfd_strip_section_from_output (info, s); |
252b5132 RH |
3071 | continue; |
3072 | } | |
3073 | ||
3074 | /* Allocate memory for the section contents. */ | |
7619e7c7 AM |
3075 | s->contents = (bfd_byte *) bfd_zalloc (htab->elf.dynobj, s->_raw_size); |
3076 | if (s->contents == NULL) | |
b34976b6 | 3077 | return FALSE; |
252b5132 RH |
3078 | } |
3079 | ||
7619e7c7 | 3080 | if (htab->elf.dynamic_sections_created) |
252b5132 RH |
3081 | { |
3082 | /* Add some entries to the .dynamic section. We fill in the | |
3083 | values later, in ppc_elf_finish_dynamic_sections, but we | |
3084 | must add the entries now so that we get the correct size for | |
3085 | the .dynamic section. The DT_DEBUG entry is filled in by the | |
3086 | dynamic linker and used by the debugger. */ | |
dc810e39 AM |
3087 | #define add_dynamic_entry(TAG, VAL) \ |
3088 | bfd_elf32_add_dynamic_entry (info, (bfd_vma) (TAG), (bfd_vma) (VAL)) | |
3089 | ||
3090 | if (!info->shared) | |
252b5132 | 3091 | { |
dc810e39 | 3092 | if (!add_dynamic_entry (DT_DEBUG, 0)) |
b34976b6 | 3093 | return FALSE; |
252b5132 RH |
3094 | } |
3095 | ||
7619e7c7 | 3096 | if (htab->plt != NULL && htab->plt->_raw_size != 0) |
252b5132 | 3097 | { |
dc810e39 AM |
3098 | if (!add_dynamic_entry (DT_PLTGOT, 0) |
3099 | || !add_dynamic_entry (DT_PLTRELSZ, 0) | |
3100 | || !add_dynamic_entry (DT_PLTREL, DT_RELA) | |
3101 | || !add_dynamic_entry (DT_JMPREL, 0)) | |
b34976b6 | 3102 | return FALSE; |
252b5132 RH |
3103 | } |
3104 | ||
3105 | if (relocs) | |
3106 | { | |
dc810e39 AM |
3107 | if (!add_dynamic_entry (DT_RELA, 0) |
3108 | || !add_dynamic_entry (DT_RELASZ, 0) | |
3109 | || !add_dynamic_entry (DT_RELAENT, sizeof (Elf32_External_Rela))) | |
b34976b6 | 3110 | return FALSE; |
252b5132 RH |
3111 | } |
3112 | ||
7fce784e AS |
3113 | /* If any dynamic relocs apply to a read-only section, then we |
3114 | need a DT_TEXTREL entry. */ | |
3115 | if ((info->flags & DF_TEXTREL) == 0) | |
3116 | elf_link_hash_traverse (elf_hash_table (info), readonly_dynrelocs, | |
3117 | (PTR) info); | |
3118 | ||
29c2fb7c | 3119 | if ((info->flags & DF_TEXTREL) != 0) |
252b5132 | 3120 | { |
dc810e39 | 3121 | if (!add_dynamic_entry (DT_TEXTREL, 0)) |
b34976b6 | 3122 | return FALSE; |
252b5132 RH |
3123 | } |
3124 | } | |
dc810e39 | 3125 | #undef add_dynamic_entry |
252b5132 | 3126 | |
b34976b6 | 3127 | return TRUE; |
252b5132 | 3128 | } |
252b5132 | 3129 | \f |
7619e7c7 AM |
3130 | static bfd_boolean |
3131 | update_local_sym_info (abfd, symtab_hdr, r_symndx, tls_type) | |
3132 | bfd *abfd; | |
3133 | Elf_Internal_Shdr *symtab_hdr; | |
3134 | unsigned long r_symndx; | |
3135 | int tls_type; | |
3136 | { | |
3137 | bfd_signed_vma *local_got_refcounts = elf_local_got_refcounts (abfd); | |
3138 | char *local_got_tls_masks; | |
3139 | ||
3140 | if (local_got_refcounts == NULL) | |
3141 | { | |
3142 | bfd_size_type size = symtab_hdr->sh_info; | |
3143 | ||
3144 | size *= sizeof (*local_got_refcounts) + sizeof (*local_got_tls_masks); | |
3145 | local_got_refcounts = (bfd_signed_vma *) bfd_zalloc (abfd, size); | |
3146 | if (local_got_refcounts == NULL) | |
3147 | return FALSE; | |
3148 | elf_local_got_refcounts (abfd) = local_got_refcounts; | |
3149 | } | |
3150 | ||
3151 | local_got_refcounts[r_symndx] += 1; | |
3152 | local_got_tls_masks = (char *) (local_got_refcounts + symtab_hdr->sh_info); | |
3153 | local_got_tls_masks[r_symndx] |= tls_type; | |
3154 | return TRUE; | |
3155 | } | |
3156 | ||
3157 | static void | |
3158 | bad_shared_reloc (abfd, r_type) | |
3159 | bfd *abfd; | |
3160 | enum elf_ppc_reloc_type r_type; | |
3161 | { | |
3162 | (*_bfd_error_handler) | |
3163 | (_("%s: relocation %s cannot be used when making a shared object"), | |
3164 | bfd_archive_filename (abfd), | |
3165 | ppc_elf_howto_table[(int) r_type]->name); | |
3166 | bfd_set_error (bfd_error_bad_value); | |
3167 | } | |
3168 | ||
252b5132 RH |
3169 | /* Look through the relocs for a section during the first phase, and |
3170 | allocate space in the global offset table or procedure linkage | |
3171 | table. */ | |
3172 | ||
b34976b6 | 3173 | static bfd_boolean |
252b5132 RH |
3174 | ppc_elf_check_relocs (abfd, info, sec, relocs) |
3175 | bfd *abfd; | |
3176 | struct bfd_link_info *info; | |
3177 | asection *sec; | |
3178 | const Elf_Internal_Rela *relocs; | |
3179 | { | |
7619e7c7 | 3180 | struct ppc_elf_link_hash_table *htab; |
252b5132 | 3181 | Elf_Internal_Shdr *symtab_hdr; |
7619e7c7 | 3182 | struct elf_link_hash_entry **sym_hashes; |
252b5132 RH |
3183 | const Elf_Internal_Rela *rel; |
3184 | const Elf_Internal_Rela *rel_end; | |
252b5132 | 3185 | asection *sreloc; |
252b5132 RH |
3186 | |
3187 | if (info->relocateable) | |
b34976b6 | 3188 | return TRUE; |
252b5132 RH |
3189 | |
3190 | #ifdef DEBUG | |
3191 | fprintf (stderr, "ppc_elf_check_relocs called for section %s in %s\n", | |
3192 | bfd_get_section_name (abfd, sec), | |
8f615d07 | 3193 | bfd_archive_filename (abfd)); |
252b5132 RH |
3194 | #endif |
3195 | ||
3196 | /* Create the linker generated sections all the time so that the | |
3197 | special symbols are created. */ | |
3198 | ||
7619e7c7 AM |
3199 | htab = ppc_elf_hash_table (info); |
3200 | if (htab->sdata == NULL) | |
252b5132 | 3201 | { |
7619e7c7 AM |
3202 | htab->sdata = elf_linker_section (abfd, LINKER_SECTION_SDATA); |
3203 | if (htab->sdata == NULL) | |
3204 | htab->sdata = ppc_elf_create_linker_section (abfd, info, | |
3205 | LINKER_SECTION_SDATA); | |
3206 | if (htab->sdata == NULL) | |
b34976b6 | 3207 | return FALSE; |
252b5132 RH |
3208 | } |
3209 | ||
7619e7c7 | 3210 | if (htab->sdata2 == NULL) |
252b5132 | 3211 | { |
7619e7c7 AM |
3212 | htab->sdata2 = elf_linker_section (abfd, LINKER_SECTION_SDATA2); |
3213 | if (htab->sdata2 == NULL) | |
3214 | htab->sdata2 = ppc_elf_create_linker_section (abfd, info, | |
3215 | LINKER_SECTION_SDATA2); | |
3216 | if (htab->sdata2 == NULL) | |
b34976b6 | 3217 | return FALSE; |
252b5132 RH |
3218 | } |
3219 | ||
252b5132 | 3220 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr; |
252b5132 | 3221 | sym_hashes = elf_sym_hashes (abfd); |
252b5132 RH |
3222 | sreloc = NULL; |
3223 | ||
3224 | rel_end = relocs + sec->reloc_count; | |
3225 | for (rel = relocs; rel < rel_end; rel++) | |
3226 | { | |
3227 | unsigned long r_symndx; | |
7619e7c7 | 3228 | enum elf_ppc_reloc_type r_type; |
252b5132 | 3229 | struct elf_link_hash_entry *h; |
7619e7c7 | 3230 | int tls_type = 0; |
252b5132 RH |
3231 | |
3232 | r_symndx = ELF32_R_SYM (rel->r_info); | |
3233 | if (r_symndx < symtab_hdr->sh_info) | |
3234 | h = NULL; | |
3235 | else | |
3236 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | |
3237 | ||
3238 | /* If a relocation refers to _GLOBAL_OFFSET_TABLE_, create the .got. | |
3239 | This shows up in particular in an R_PPC_ADDR32 in the eabi | |
3240 | startup code. */ | |
3241 | if (h && strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0) | |
3242 | { | |
7619e7c7 | 3243 | if (htab->got == NULL) |
252b5132 | 3244 | { |
7619e7c7 AM |
3245 | if (htab->elf.dynobj == NULL) |
3246 | htab->elf.dynobj = abfd; | |
3247 | if (!ppc_elf_create_got (htab->elf.dynobj, info)) | |
b34976b6 | 3248 | return FALSE; |
252b5132 RH |
3249 | } |
3250 | } | |
3251 | ||
7619e7c7 AM |
3252 | r_type = (enum elf_ppc_reloc_type) ELF32_R_TYPE (rel->r_info); |
3253 | switch (r_type) | |
252b5132 | 3254 | { |
7619e7c7 AM |
3255 | case R_PPC_GOT_TLSLD16: |
3256 | case R_PPC_GOT_TLSLD16_LO: | |
3257 | case R_PPC_GOT_TLSLD16_HI: | |
3258 | case R_PPC_GOT_TLSLD16_HA: | |
3259 | htab->tlsld_got.refcount += 1; | |
3260 | tls_type = TLS_TLS | TLS_LD; | |
3261 | goto dogottls; | |
3262 | ||
3263 | case R_PPC_GOT_TLSGD16: | |
3264 | case R_PPC_GOT_TLSGD16_LO: | |
3265 | case R_PPC_GOT_TLSGD16_HI: | |
3266 | case R_PPC_GOT_TLSGD16_HA: | |
3267 | tls_type = TLS_TLS | TLS_GD; | |
3268 | goto dogottls; | |
3269 | ||
3270 | case R_PPC_GOT_TPREL16: | |
3271 | case R_PPC_GOT_TPREL16_LO: | |
3272 | case R_PPC_GOT_TPREL16_HI: | |
3273 | case R_PPC_GOT_TPREL16_HA: | |
3274 | if (info->shared) | |
3275 | info->flags |= DF_STATIC_TLS; | |
3276 | tls_type = TLS_TLS | TLS_TPREL; | |
3277 | goto dogottls; | |
3278 | ||
3279 | case R_PPC_GOT_DTPREL16: | |
3280 | case R_PPC_GOT_DTPREL16_LO: | |
3281 | case R_PPC_GOT_DTPREL16_HI: | |
3282 | case R_PPC_GOT_DTPREL16_HA: | |
3283 | tls_type = TLS_TLS | TLS_DTPREL; | |
3284 | dogottls: | |
3285 | sec->has_tls_reloc = 1; | |
3286 | /* Fall thru */ | |
3287 | ||
70bccea4 | 3288 | /* GOT16 relocations */ |
252b5132 RH |
3289 | case R_PPC_GOT16: |
3290 | case R_PPC_GOT16_LO: | |
3291 | case R_PPC_GOT16_HI: | |
3292 | case R_PPC_GOT16_HA: | |
3293 | /* This symbol requires a global offset table entry. */ | |
7619e7c7 | 3294 | if (htab->got == NULL) |
252b5132 | 3295 | { |
7619e7c7 AM |
3296 | if (htab->elf.dynobj == NULL) |
3297 | htab->elf.dynobj = abfd; | |
3298 | if (!ppc_elf_create_got (htab->elf.dynobj, info)) | |
b34976b6 | 3299 | return FALSE; |
252b5132 | 3300 | } |
252b5132 RH |
3301 | if (h != NULL) |
3302 | { | |
7619e7c7 AM |
3303 | h->got.refcount += 1; |
3304 | ppc_elf_hash_entry (h)->tls_mask |= tls_type; | |
252b5132 RH |
3305 | } |
3306 | else | |
7619e7c7 AM |
3307 | /* This is a global offset table entry for a local symbol. */ |
3308 | if (!update_local_sym_info (abfd, symtab_hdr, r_symndx, tls_type)) | |
3309 | return FALSE; | |
252b5132 RH |
3310 | break; |
3311 | ||
70bccea4 | 3312 | /* Indirect .sdata relocation. */ |
252b5132 RH |
3313 | case R_PPC_EMB_SDAI16: |
3314 | if (info->shared) | |
3315 | { | |
7619e7c7 | 3316 | bad_shared_reloc (abfd, r_type); |
b34976b6 | 3317 | return FALSE; |
252b5132 | 3318 | } |
7619e7c7 AM |
3319 | if (!bfd_elf32_create_pointer_linker_section (abfd, info, |
3320 | htab->sdata, h, rel)) | |
b34976b6 | 3321 | return FALSE; |
252b5132 RH |
3322 | break; |
3323 | ||
70bccea4 | 3324 | /* Indirect .sdata2 relocation. */ |
252b5132 RH |
3325 | case R_PPC_EMB_SDA2I16: |
3326 | if (info->shared) | |
3327 | { | |
7619e7c7 | 3328 | bad_shared_reloc (abfd, r_type); |
b34976b6 | 3329 | return FALSE; |
252b5132 | 3330 | } |
7619e7c7 AM |
3331 | if (!bfd_elf32_create_pointer_linker_section (abfd, info, |
3332 | htab->sdata2, h, rel)) | |
b34976b6 | 3333 | return FALSE; |
252b5132 RH |
3334 | break; |
3335 | ||
3336 | case R_PPC_SDAREL16: | |
3337 | case R_PPC_EMB_SDA2REL: | |
3338 | case R_PPC_EMB_SDA21: | |
7619e7c7 AM |
3339 | case R_PPC_EMB_RELSDA: |
3340 | case R_PPC_EMB_NADDR32: | |
3341 | case R_PPC_EMB_NADDR16: | |
3342 | case R_PPC_EMB_NADDR16_LO: | |
3343 | case R_PPC_EMB_NADDR16_HI: | |
3344 | case R_PPC_EMB_NADDR16_HA: | |
252b5132 RH |
3345 | if (info->shared) |
3346 | { | |
7619e7c7 | 3347 | bad_shared_reloc (abfd, r_type); |
b34976b6 | 3348 | return FALSE; |
252b5132 RH |
3349 | } |
3350 | break; | |
3351 | ||
3352 | case R_PPC_PLT32: | |
3353 | case R_PPC_PLTREL24: | |
7619e7c7 | 3354 | case R_PPC_PLTREL32: |
252b5132 RH |
3355 | case R_PPC_PLT16_LO: |
3356 | case R_PPC_PLT16_HI: | |
3357 | case R_PPC_PLT16_HA: | |
3358 | #ifdef DEBUG | |
3359 | fprintf (stderr, "Reloc requires a PLT entry\n"); | |
3360 | #endif | |
3361 | /* This symbol requires a procedure linkage table entry. We | |
70bccea4 AM |
3362 | actually build the entry in finish_dynamic_symbol, |
3363 | because this might be a case of linking PIC code without | |
3364 | linking in any dynamic objects, in which case we don't | |
3365 | need to generate a procedure linkage table after all. */ | |
252b5132 RH |
3366 | |
3367 | if (h == NULL) | |
3368 | { | |
3369 | /* It does not make sense to have a procedure linkage | |
70bccea4 | 3370 | table entry for a local symbol. */ |
252b5132 | 3371 | bfd_set_error (bfd_error_bad_value); |
b34976b6 | 3372 | return FALSE; |
252b5132 RH |
3373 | } |
3374 | ||
51b64d56 AM |
3375 | h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT; |
3376 | h->plt.refcount++; | |
252b5132 RH |
3377 | break; |
3378 | ||
3379 | /* The following relocations don't need to propagate the | |
3380 | relocation if linking a shared object since they are | |
3381 | section relative. */ | |
3382 | case R_PPC_SECTOFF: | |
3383 | case R_PPC_SECTOFF_LO: | |
3384 | case R_PPC_SECTOFF_HI: | |
3385 | case R_PPC_SECTOFF_HA: | |
7619e7c7 AM |
3386 | case R_PPC_DTPREL16: |
3387 | case R_PPC_DTPREL16_LO: | |
3388 | case R_PPC_DTPREL16_HI: | |
3389 | case R_PPC_DTPREL16_HA: | |
3390 | case R_PPC_TOC16: | |
3391 | break; | |
3392 | ||
3393 | /* This are just markers. */ | |
3394 | case R_PPC_TLS: | |
3395 | case R_PPC_EMB_MRKREF: | |
3396 | case R_PPC_NONE: | |
3397 | case R_PPC_max: | |
3398 | break; | |
3399 | ||
3400 | /* These should only appear in dynamic objects. */ | |
3401 | case R_PPC_COPY: | |
3402 | case R_PPC_GLOB_DAT: | |
3403 | case R_PPC_JMP_SLOT: | |
3404 | case R_PPC_RELATIVE: | |
3405 | break; | |
3406 | ||
3407 | /* These aren't handled yet. We'll report an error later. */ | |
3408 | case R_PPC_ADDR30: | |
3409 | case R_PPC_EMB_RELSEC16: | |
3410 | case R_PPC_EMB_RELST_LO: | |
3411 | case R_PPC_EMB_RELST_HI: | |
3412 | case R_PPC_EMB_RELST_HA: | |
3413 | case R_PPC_EMB_BIT_FLD: | |
252b5132 RH |
3414 | break; |
3415 | ||
ae9a127f | 3416 | /* This refers only to functions defined in the shared library. */ |
252b5132 RH |
3417 | case R_PPC_LOCAL24PC: |
3418 | break; | |
3419 | ||
3420 | /* This relocation describes the C++ object vtable hierarchy. | |
3421 | Reconstruct it for later use during GC. */ | |
3422 | case R_PPC_GNU_VTINHERIT: | |
3423 | if (!_bfd_elf32_gc_record_vtinherit (abfd, sec, h, rel->r_offset)) | |
b34976b6 | 3424 | return FALSE; |
252b5132 RH |
3425 | break; |
3426 | ||
3427 | /* This relocation describes which C++ vtable entries are actually | |
3428 | used. Record for later use during GC. */ | |
3429 | case R_PPC_GNU_VTENTRY: | |
3430 | if (!_bfd_elf32_gc_record_vtentry (abfd, sec, h, rel->r_addend)) | |
b34976b6 | 3431 | return FALSE; |
252b5132 RH |
3432 | break; |
3433 | ||
7619e7c7 AM |
3434 | /* We shouldn't really be seeing these. */ |
3435 | case R_PPC_TPREL32: | |
3436 | if (info->shared) | |
3437 | info->flags |= DF_STATIC_TLS; | |
3438 | goto dodyn; | |
3439 | ||
3440 | /* Nor these. */ | |
3441 | case R_PPC_DTPMOD32: | |
3442 | case R_PPC_DTPREL32: | |
3443 | goto dodyn; | |
3444 | ||
3445 | case R_PPC_TPREL16: | |
3446 | case R_PPC_TPREL16_LO: | |
3447 | case R_PPC_TPREL16_HI: | |
3448 | case R_PPC_TPREL16_HA: | |
3449 | if (info->shared) | |
3450 | info->flags |= DF_STATIC_TLS; | |
3451 | goto dodyn; | |
3452 | ||
252b5132 RH |
3453 | /* When creating a shared object, we must copy these |
3454 | relocs into the output file. We create a reloc | |
3455 | section in dynobj and make room for the reloc. */ | |
3456 | case R_PPC_REL24: | |
3457 | case R_PPC_REL14: | |
3458 | case R_PPC_REL14_BRTAKEN: | |
3459 | case R_PPC_REL14_BRNTAKEN: | |
3460 | case R_PPC_REL32: | |
3461 | if (h == NULL | |
2b98e6c0 | 3462 | || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0) |
252b5132 RH |
3463 | break; |
3464 | /* fall through */ | |
3465 | ||
7619e7c7 AM |
3466 | case R_PPC_ADDR32: |
3467 | case R_PPC_ADDR24: | |
3468 | case R_PPC_ADDR16: | |
3469 | case R_PPC_ADDR16_LO: | |
3470 | case R_PPC_ADDR16_HI: | |
3471 | case R_PPC_ADDR16_HA: | |
3472 | case R_PPC_ADDR14: | |
3473 | case R_PPC_ADDR14_BRTAKEN: | |
3474 | case R_PPC_ADDR14_BRNTAKEN: | |
3475 | case R_PPC_UADDR32: | |
3476 | case R_PPC_UADDR16: | |
3477 | if (h != NULL && !info->shared) | |
3478 | { | |
3479 | /* We may need a plt entry if the symbol turns out to be | |
3480 | a function defined in a dynamic object. */ | |
3481 | h->plt.refcount++; | |
3482 | ||
3483 | /* We may need a copy reloc too. */ | |
3484 | h->elf_link_hash_flags |= ELF_LINK_NON_GOT_REF; | |
3485 | } | |
ee05f2fe | 3486 | |
7619e7c7 | 3487 | dodyn: |
ee05f2fe AM |
3488 | /* If we are creating a shared library, and this is a reloc |
3489 | against a global symbol, or a non PC relative reloc | |
3490 | against a local symbol, then we need to copy the reloc | |
3491 | into the shared library. However, if we are linking with | |
3492 | -Bsymbolic, we do not need to copy a reloc against a | |
3493 | global symbol which is defined in an object we are | |
3494 | including in the link (i.e., DEF_REGULAR is set). At | |
3495 | this point we have not seen all the input files, so it is | |
3496 | possible that DEF_REGULAR is not set now but will be set | |
3497 | later (it is never cleared). In case of a weak definition, | |
3498 | DEF_REGULAR may be cleared later by a strong definition in | |
3499 | a shared library. We account for that possibility below by | |
3500 | storing information in the dyn_relocs field of the hash | |
3501 | table entry. A similar situation occurs when creating | |
3502 | shared libraries and symbol visibility changes render the | |
3503 | symbol local. | |
3504 | ||
3505 | If on the other hand, we are creating an executable, we | |
3506 | may need to keep relocations for symbols satisfied by a | |
3507 | dynamic library if we manage to avoid copy relocs for the | |
3508 | symbol. */ | |
3509 | if ((info->shared | |
3510 | && (MUST_BE_DYN_RELOC (r_type) | |
3511 | || (h != NULL | |
3512 | && (! info->symbolic | |
3513 | || h->root.type == bfd_link_hash_defweak | |
3514 | || (h->elf_link_hash_flags | |
3515 | & ELF_LINK_HASH_DEF_REGULAR) == 0)))) | |
3516 | || (ELIMINATE_COPY_RELOCS | |
3517 | && !info->shared | |
3518 | && (sec->flags & SEC_ALLOC) != 0 | |
3519 | && h != NULL | |
3520 | && (h->root.type == bfd_link_hash_defweak | |
3521 | || (h->elf_link_hash_flags | |
3522 | & ELF_LINK_HASH_DEF_REGULAR) == 0))) | |
252b5132 | 3523 | { |
7fce784e AS |
3524 | struct ppc_elf_dyn_relocs *p; |
3525 | struct ppc_elf_dyn_relocs **head; | |
3526 | ||
252b5132 RH |
3527 | #ifdef DEBUG |
3528 | fprintf (stderr, "ppc_elf_check_relocs need to create relocation for %s\n", | |
70bccea4 AM |
3529 | (h && h->root.root.string |
3530 | ? h->root.root.string : "<unknown>")); | |
252b5132 RH |
3531 | #endif |
3532 | if (sreloc == NULL) | |
3533 | { | |
3534 | const char *name; | |
3535 | ||
3536 | name = (bfd_elf_string_from_elf_section | |
3537 | (abfd, | |
3538 | elf_elfheader (abfd)->e_shstrndx, | |
3539 | elf_section_data (sec)->rel_hdr.sh_name)); | |
3540 | if (name == NULL) | |
b34976b6 | 3541 | return FALSE; |
252b5132 RH |
3542 | |
3543 | BFD_ASSERT (strncmp (name, ".rela", 5) == 0 | |
3544 | && strcmp (bfd_get_section_name (abfd, sec), | |
3545 | name + 5) == 0); | |
3546 | ||
7619e7c7 | 3547 | sreloc = bfd_get_section_by_name (htab->elf.dynobj, name); |
252b5132 RH |
3548 | if (sreloc == NULL) |
3549 | { | |
3550 | flagword flags; | |
3551 | ||
7619e7c7 | 3552 | sreloc = bfd_make_section (htab->elf.dynobj, name); |
252b5132 RH |
3553 | flags = (SEC_HAS_CONTENTS | SEC_READONLY |
3554 | | SEC_IN_MEMORY | SEC_LINKER_CREATED); | |
3555 | if ((sec->flags & SEC_ALLOC) != 0) | |
3556 | flags |= SEC_ALLOC | SEC_LOAD; | |
3557 | if (sreloc == NULL | |
7619e7c7 AM |
3558 | || ! bfd_set_section_flags (htab->elf.dynobj, |
3559 | sreloc, flags) | |
3560 | || ! bfd_set_section_alignment (htab->elf.dynobj, | |
3561 | sreloc, 2)) | |
b34976b6 | 3562 | return FALSE; |
252b5132 | 3563 | } |
7fce784e AS |
3564 | elf_section_data (sec)->sreloc = sreloc; |
3565 | } | |
3566 | ||
3567 | /* If this is a global symbol, we count the number of | |
3568 | relocations we need for this symbol. */ | |
3569 | if (h != NULL) | |
3570 | { | |
3571 | head = &ppc_elf_hash_entry (h)->dyn_relocs; | |
252b5132 | 3572 | } |
7fce784e AS |
3573 | else |
3574 | { | |
3575 | /* Track dynamic relocs needed for local syms too. | |
3576 | We really need local syms available to do this | |
3577 | easily. Oh well. */ | |
3578 | ||
3579 | asection *s; | |
ee05f2fe AM |
3580 | s = bfd_section_from_r_symndx (abfd, &htab->sym_sec, |
3581 | sec, r_symndx); | |
7fce784e AS |
3582 | if (s == NULL) |
3583 | return FALSE; | |
252b5132 | 3584 | |
7fce784e AS |
3585 | head = ((struct ppc_elf_dyn_relocs **) |
3586 | &elf_section_data (s)->local_dynrel); | |
3587 | } | |
252b5132 | 3588 | |
7fce784e AS |
3589 | p = *head; |
3590 | if (p == NULL || p->sec != sec) | |
3591 | { | |
3592 | p = ((struct ppc_elf_dyn_relocs *) | |
7619e7c7 | 3593 | bfd_alloc (htab->elf.dynobj, sizeof *p)); |
7fce784e AS |
3594 | if (p == NULL) |
3595 | return FALSE; | |
3596 | p->next = *head; | |
3597 | *head = p; | |
3598 | p->sec = sec; | |
3599 | p->count = 0; | |
ee05f2fe | 3600 | p->pc_count = 0; |
7fce784e AS |
3601 | } |
3602 | ||
ee05f2fe AM |
3603 | p->count += 1; |
3604 | if (!MUST_BE_DYN_RELOC (r_type)) | |
3605 | p->pc_count += 1; | |
252b5132 RH |
3606 | } |
3607 | ||
3608 | break; | |
3609 | } | |
3610 | } | |
3611 | ||
b34976b6 | 3612 | return TRUE; |
252b5132 RH |
3613 | } |
3614 | ||
3615 | /* Return the section that should be marked against GC for a given | |
3616 | relocation. */ | |
3617 | ||
3618 | static asection * | |
1e2f5b6e AM |
3619 | ppc_elf_gc_mark_hook (sec, info, rel, h, sym) |
3620 | asection *sec; | |
5f771d47 | 3621 | struct bfd_link_info *info ATTRIBUTE_UNUSED; |
252b5132 RH |
3622 | Elf_Internal_Rela *rel; |
3623 | struct elf_link_hash_entry *h; | |
3624 | Elf_Internal_Sym *sym; | |
3625 | { | |
3626 | if (h != NULL) | |
3627 | { | |
3628 | switch (ELF32_R_TYPE (rel->r_info)) | |
3629 | { | |
3630 | case R_PPC_GNU_VTINHERIT: | |
3631 | case R_PPC_GNU_VTENTRY: | |
3632 | break; | |
3633 | ||
3634 | default: | |
3635 | switch (h->root.type) | |
3636 | { | |
3637 | case bfd_link_hash_defined: | |
3638 | case bfd_link_hash_defweak: | |
3639 | return h->root.u.def.section; | |
3640 | ||
3641 | case bfd_link_hash_common: | |
3642 | return h->root.u.c.p->section; | |
3643 | ||
3644 | default: | |
3645 | break; | |
3646 | } | |
3647 | } | |
3648 | } | |
3649 | else | |
1e2f5b6e | 3650 | return bfd_section_from_elf_index (sec->owner, sym->st_shndx); |
252b5132 RH |
3651 | |
3652 | return NULL; | |
3653 | } | |
3654 | ||
7619e7c7 AM |
3655 | /* Update the got, plt and dynamic reloc reference counts for the |
3656 | section being removed. */ | |
252b5132 | 3657 | |
b34976b6 | 3658 | static bfd_boolean |
252b5132 RH |
3659 | ppc_elf_gc_sweep_hook (abfd, info, sec, relocs) |
3660 | bfd *abfd; | |
7619e7c7 | 3661 | struct bfd_link_info *info; |
252b5132 RH |
3662 | asection *sec; |
3663 | const Elf_Internal_Rela *relocs; | |
3664 | { | |
7619e7c7 | 3665 | struct ppc_elf_link_hash_table *htab; |
252b5132 RH |
3666 | Elf_Internal_Shdr *symtab_hdr; |
3667 | struct elf_link_hash_entry **sym_hashes; | |
3668 | bfd_signed_vma *local_got_refcounts; | |
3669 | const Elf_Internal_Rela *rel, *relend; | |
252b5132 | 3670 | |
7fce784e AS |
3671 | elf_section_data (sec)->local_dynrel = NULL; |
3672 | ||
7619e7c7 | 3673 | htab = ppc_elf_hash_table (info); |
252b5132 RH |
3674 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr; |
3675 | sym_hashes = elf_sym_hashes (abfd); | |
3676 | local_got_refcounts = elf_local_got_refcounts (abfd); | |
3677 | ||
3678 | relend = relocs + sec->reloc_count; | |
3679 | for (rel = relocs; rel < relend; rel++) | |
7619e7c7 AM |
3680 | { |
3681 | unsigned long r_symndx; | |
3682 | enum elf_ppc_reloc_type r_type; | |
3683 | struct elf_link_hash_entry *h = NULL; | |
252b5132 | 3684 | |
7619e7c7 AM |
3685 | r_symndx = ELF32_R_SYM (rel->r_info); |
3686 | if (r_symndx >= symtab_hdr->sh_info) | |
3687 | { | |
3688 | struct ppc_elf_dyn_relocs **pp, *p; | |
3689 | struct ppc_elf_link_hash_entry *eh; | |
3690 | ||
3691 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | |
3692 | eh = (struct ppc_elf_link_hash_entry *) h; | |
3693 | ||
3694 | for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next) | |
3695 | if (p->sec == sec) | |
3696 | { | |
3697 | /* Everything must go for SEC. */ | |
3698 | *pp = p->next; | |
3699 | break; | |
3700 | } | |
3701 | } | |
3702 | ||
3703 | r_type = (enum elf_ppc_reloc_type) ELF32_R_TYPE (rel->r_info); | |
3704 | switch (r_type) | |
3705 | { | |
3706 | case R_PPC_GOT_TLSLD16: | |
3707 | case R_PPC_GOT_TLSLD16_LO: | |
3708 | case R_PPC_GOT_TLSLD16_HI: | |
3709 | case R_PPC_GOT_TLSLD16_HA: | |
3710 | htab->tlsld_got.refcount -= 1; | |
3711 | /* Fall thru */ | |
3712 | ||
3713 | case R_PPC_GOT_TLSGD16: | |
3714 | case R_PPC_GOT_TLSGD16_LO: | |
3715 | case R_PPC_GOT_TLSGD16_HI: | |
3716 | case R_PPC_GOT_TLSGD16_HA: | |
3717 | case R_PPC_GOT_TPREL16: | |
3718 | case R_PPC_GOT_TPREL16_LO: | |
3719 | case R_PPC_GOT_TPREL16_HI: | |
3720 | case R_PPC_GOT_TPREL16_HA: | |
3721 | case R_PPC_GOT_DTPREL16: | |
3722 | case R_PPC_GOT_DTPREL16_LO: | |
3723 | case R_PPC_GOT_DTPREL16_HI: | |
3724 | case R_PPC_GOT_DTPREL16_HA: | |
3725 | case R_PPC_GOT16: | |
3726 | case R_PPC_GOT16_LO: | |
3727 | case R_PPC_GOT16_HI: | |
3728 | case R_PPC_GOT16_HA: | |
3729 | if (h != NULL) | |
3730 | { | |
3731 | if (h->got.refcount > 0) | |
3732 | h->got.refcount--; | |
3733 | } | |
3734 | else if (local_got_refcounts != NULL) | |
3735 | { | |
3736 | if (local_got_refcounts[r_symndx] > 0) | |
3737 | local_got_refcounts[r_symndx]--; | |
3738 | } | |
3739 | break; | |
3740 | ||
3741 | case R_PPC_REL24: | |
3742 | case R_PPC_REL14: | |
3743 | case R_PPC_REL14_BRTAKEN: | |
3744 | case R_PPC_REL14_BRNTAKEN: | |
3745 | case R_PPC_REL32: | |
3746 | if (h == NULL | |
2b98e6c0 | 3747 | || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0) |
7619e7c7 AM |
3748 | break; |
3749 | /* Fall thru */ | |
3750 | ||
3751 | case R_PPC_ADDR32: | |
3752 | case R_PPC_ADDR24: | |
3753 | case R_PPC_ADDR16: | |
3754 | case R_PPC_ADDR16_LO: | |
3755 | case R_PPC_ADDR16_HI: | |
3756 | case R_PPC_ADDR16_HA: | |
3757 | case R_PPC_ADDR14: | |
3758 | case R_PPC_ADDR14_BRTAKEN: | |
3759 | case R_PPC_ADDR14_BRNTAKEN: | |
3760 | case R_PPC_UADDR32: | |
3761 | case R_PPC_UADDR16: | |
3762 | case R_PPC_PLT32: | |
3763 | case R_PPC_PLTREL24: | |
3764 | case R_PPC_PLT16_LO: | |
3765 | case R_PPC_PLT16_HI: | |
3766 | case R_PPC_PLT16_HA: | |
3767 | if (h != NULL) | |
3768 | { | |
3769 | if (h->plt.refcount > 0) | |
3770 | h->plt.refcount--; | |
3771 | } | |
3772 | break; | |
3773 | ||
3774 | default: | |
3775 | break; | |
3776 | } | |
3777 | } | |
3778 | return TRUE; | |
3779 | } | |
3780 | ||
3781 | /* Set htab->tls_sec and htab->tls_get_addr. */ | |
3782 | ||
3783 | bfd_boolean | |
3784 | ppc_elf_tls_setup (obfd, info) | |
3785 | bfd *obfd; | |
3786 | struct bfd_link_info *info; | |
3787 | { | |
3788 | asection *tls; | |
3789 | struct ppc_elf_link_hash_table *htab; | |
3790 | ||
3791 | htab = ppc_elf_hash_table (info); | |
3792 | htab->tls_get_addr = elf_link_hash_lookup (&htab->elf, "__tls_get_addr", | |
3793 | FALSE, FALSE, TRUE); | |
3794 | ||
3795 | for (tls = obfd->sections; tls != NULL; tls = tls->next) | |
3796 | if ((tls->flags & (SEC_THREAD_LOCAL | SEC_LOAD)) | |
3797 | == (SEC_THREAD_LOCAL | SEC_LOAD)) | |
3798 | break; | |
3799 | htab->tls_sec = tls; | |
3800 | ||
3801 | return tls != NULL; | |
3802 | } | |
3803 | ||
3804 | /* Run through all the TLS relocs looking for optimization | |
3805 | opportunities. */ | |
3806 | ||
3807 | bfd_boolean | |
3808 | ppc_elf_tls_optimize (obfd, info) | |
3809 | bfd *obfd ATTRIBUTE_UNUSED; | |
3810 | struct bfd_link_info *info; | |
3811 | { | |
3812 | bfd *ibfd; | |
3813 | asection *sec; | |
3814 | struct ppc_elf_link_hash_table *htab; | |
3815 | ||
3816 | if (info->relocateable || info->shared) | |
3817 | return TRUE; | |
3818 | ||
3819 | htab = ppc_elf_hash_table (info); | |
3820 | for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next) | |
3821 | { | |
3822 | Elf_Internal_Sym *locsyms = NULL; | |
3823 | Elf_Internal_Shdr *symtab_hdr = &elf_tdata (ibfd)->symtab_hdr; | |
3824 | ||
3825 | for (sec = ibfd->sections; sec != NULL; sec = sec->next) | |
3826 | if (sec->has_tls_reloc && !bfd_is_abs_section (sec->output_section)) | |
7fce784e | 3827 | { |
7619e7c7 AM |
3828 | Elf_Internal_Rela *relstart, *rel, *relend; |
3829 | int expecting_tls_get_addr; | |
3830 | ||
3831 | /* Read the relocations. */ | |
3832 | relstart = _bfd_elf32_link_read_relocs (ibfd, sec, (PTR) NULL, | |
3833 | (Elf_Internal_Rela *) NULL, | |
3834 | info->keep_memory); | |
3835 | if (relstart == NULL) | |
3836 | return FALSE; | |
3837 | ||
3838 | expecting_tls_get_addr = 0; | |
3839 | relend = relstart + sec->reloc_count; | |
3840 | for (rel = relstart; rel < relend; rel++) | |
3841 | { | |
3842 | enum elf_ppc_reloc_type r_type; | |
3843 | unsigned long r_symndx; | |
3844 | struct elf_link_hash_entry *h = NULL; | |
3845 | char *tls_mask; | |
3846 | char tls_set, tls_clear; | |
3847 | bfd_boolean is_local; | |
3848 | ||
3849 | r_symndx = ELF32_R_SYM (rel->r_info); | |
3850 | if (r_symndx >= symtab_hdr->sh_info) | |
3851 | { | |
3852 | struct elf_link_hash_entry **sym_hashes; | |
7fce784e | 3853 | |
7619e7c7 AM |
3854 | sym_hashes = elf_sym_hashes (ibfd); |
3855 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | |
3856 | while (h->root.type == bfd_link_hash_indirect | |
3857 | || h->root.type == bfd_link_hash_warning) | |
3858 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
3859 | } | |
7fce784e | 3860 | |
7619e7c7 AM |
3861 | is_local = FALSE; |
3862 | if (h == NULL | |
3863 | || !(h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC)) | |
3864 | is_local = TRUE; | |
3865 | ||
3866 | r_type = (enum elf_ppc_reloc_type) ELF32_R_TYPE (rel->r_info); | |
3867 | switch (r_type) | |
3868 | { | |
3869 | case R_PPC_GOT_TLSLD16: | |
3870 | case R_PPC_GOT_TLSLD16_LO: | |
3871 | case R_PPC_GOT_TLSLD16_HI: | |
3872 | case R_PPC_GOT_TLSLD16_HA: | |
3873 | /* These relocs should never be against a symbol | |
3874 | defined in a shared lib. Leave them alone if | |
3875 | that turns out to be the case. */ | |
3876 | expecting_tls_get_addr = 0; | |
3877 | htab->tlsld_got.refcount -= 1; | |
3878 | if (!is_local) | |
3879 | continue; | |
3880 | ||
3881 | /* LD -> LE */ | |
3882 | tls_set = 0; | |
3883 | tls_clear = TLS_LD; | |
3884 | expecting_tls_get_addr = 1; | |
3885 | break; | |
3886 | ||
3887 | case R_PPC_GOT_TLSGD16: | |
3888 | case R_PPC_GOT_TLSGD16_LO: | |
3889 | case R_PPC_GOT_TLSGD16_HI: | |
3890 | case R_PPC_GOT_TLSGD16_HA: | |
3891 | if (is_local) | |
3892 | /* GD -> LE */ | |
3893 | tls_set = 0; | |
3894 | else | |
3895 | /* GD -> IE */ | |
3896 | tls_set = TLS_TLS | TLS_TPRELGD; | |
3897 | tls_clear = TLS_GD; | |
3898 | expecting_tls_get_addr = 1; | |
3899 | break; | |
3900 | ||
3901 | case R_PPC_GOT_TPREL16: | |
3902 | case R_PPC_GOT_TPREL16_LO: | |
3903 | case R_PPC_GOT_TPREL16_HI: | |
3904 | case R_PPC_GOT_TPREL16_HA: | |
3905 | expecting_tls_get_addr = 0; | |
3906 | if (is_local) | |
3907 | { | |
3908 | /* IE -> LE */ | |
3909 | tls_set = 0; | |
3910 | tls_clear = TLS_TPREL; | |
3911 | break; | |
3912 | } | |
3913 | else | |
3914 | continue; | |
3915 | ||
3916 | case R_PPC_REL14: | |
3917 | case R_PPC_REL14_BRTAKEN: | |
3918 | case R_PPC_REL14_BRNTAKEN: | |
3919 | case R_PPC_REL24: | |
3920 | if (expecting_tls_get_addr | |
3921 | && h != NULL | |
3922 | && h == htab->tls_get_addr) | |
3923 | { | |
3924 | if (h->plt.refcount > 0) | |
3925 | h->plt.refcount -= 1; | |
3926 | } | |
3927 | expecting_tls_get_addr = 0; | |
3928 | continue; | |
3929 | ||
3930 | default: | |
3931 | expecting_tls_get_addr = 0; | |
3932 | continue; | |
3933 | } | |
3934 | ||
3935 | if (h != NULL) | |
3936 | { | |
3937 | if (tls_set == 0) | |
3938 | { | |
3939 | /* We managed to get rid of a got entry. */ | |
3940 | if (h->got.refcount > 0) | |
3941 | h->got.refcount -= 1; | |
3942 | } | |
3943 | tls_mask = &ppc_elf_hash_entry (h)->tls_mask; | |
3944 | } | |
3945 | else | |
3946 | { | |
3947 | Elf_Internal_Sym *sym; | |
3948 | bfd_signed_vma *lgot_refs; | |
3949 | char *lgot_masks; | |
3950 | ||
3951 | if (locsyms == NULL) | |
3952 | { | |
3953 | locsyms = (Elf_Internal_Sym *) symtab_hdr->contents; | |
3954 | if (locsyms == NULL) | |
3955 | locsyms = bfd_elf_get_elf_syms (ibfd, symtab_hdr, | |
3956 | symtab_hdr->sh_info, | |
3957 | 0, NULL, NULL, NULL); | |
3958 | if (locsyms == NULL) | |
3959 | { | |
3960 | if (elf_section_data (sec)->relocs != relstart) | |
3961 | free (relstart); | |
3962 | return FALSE; | |
3963 | } | |
3964 | } | |
3965 | sym = locsyms + r_symndx; | |
3966 | lgot_refs = elf_local_got_refcounts (ibfd); | |
3967 | if (lgot_refs == NULL) | |
3968 | abort (); | |
3969 | if (tls_set == 0) | |
3970 | { | |
3971 | /* We managed to get rid of a got entry. */ | |
3972 | if (lgot_refs[r_symndx] > 0) | |
3973 | lgot_refs[r_symndx] -= 1; | |
3974 | } | |
3975 | lgot_masks = (char *) (lgot_refs + symtab_hdr->sh_info); | |
3976 | tls_mask = &lgot_masks[r_symndx]; | |
3977 | } | |
3978 | ||
3979 | *tls_mask |= tls_set; | |
3980 | *tls_mask &= ~tls_clear; | |
3981 | } | |
3982 | ||
3983 | if (elf_section_data (sec)->relocs != relstart) | |
3984 | free (relstart); | |
7fce784e | 3985 | } |
252b5132 | 3986 | |
7619e7c7 AM |
3987 | if (locsyms != NULL |
3988 | && (symtab_hdr->contents != (unsigned char *) locsyms)) | |
3989 | { | |
3990 | if (!info->keep_memory) | |
3991 | free (locsyms); | |
3992 | else | |
3993 | symtab_hdr->contents = (unsigned char *) locsyms; | |
3994 | } | |
3995 | } | |
b34976b6 | 3996 | return TRUE; |
252b5132 RH |
3997 | } |
3998 | \f | |
3999 | /* Hook called by the linker routine which adds symbols from an object | |
4000 | file. We use it to put .comm items in .sbss, and not .bss. */ | |
4001 | ||
b34976b6 | 4002 | static bfd_boolean |
252b5132 RH |
4003 | ppc_elf_add_symbol_hook (abfd, info, sym, namep, flagsp, secp, valp) |
4004 | bfd *abfd; | |
4005 | struct bfd_link_info *info; | |
4006 | const Elf_Internal_Sym *sym; | |
5f771d47 ILT |
4007 | const char **namep ATTRIBUTE_UNUSED; |
4008 | flagword *flagsp ATTRIBUTE_UNUSED; | |
252b5132 RH |
4009 | asection **secp; |
4010 | bfd_vma *valp; | |
4011 | { | |
4012 | if (sym->st_shndx == SHN_COMMON | |
4013 | && !info->relocateable | |
27242387 AM |
4014 | && sym->st_size <= elf_gp_size (abfd) |
4015 | && info->hash->creator->flavour == bfd_target_elf_flavour) | |
252b5132 RH |
4016 | { |
4017 | /* Common symbols less than or equal to -G nn bytes are automatically | |
4018 | put into .sdata. */ | |
4019 | elf_linker_section_t *sdata | |
4020 | = ppc_elf_create_linker_section (abfd, info, LINKER_SECTION_SDATA); | |
4021 | ||
4022 | if (!sdata->bss_section) | |
4023 | { | |
dc810e39 AM |
4024 | bfd_size_type amt; |
4025 | ||
252b5132 | 4026 | /* We don't go through bfd_make_section, because we don't |
70bccea4 AM |
4027 | want to attach this common section to DYNOBJ. The linker |
4028 | will move the symbols to the appropriate output section | |
4029 | when it defines common symbols. */ | |
dc810e39 AM |
4030 | amt = sizeof (asection); |
4031 | sdata->bss_section = (asection *) bfd_zalloc (abfd, amt); | |
252b5132 | 4032 | if (sdata->bss_section == NULL) |
b34976b6 | 4033 | return FALSE; |
252b5132 RH |
4034 | sdata->bss_section->name = sdata->bss_name; |
4035 | sdata->bss_section->flags = SEC_IS_COMMON; | |
4036 | sdata->bss_section->output_section = sdata->bss_section; | |
dc810e39 AM |
4037 | amt = sizeof (asymbol); |
4038 | sdata->bss_section->symbol = (asymbol *) bfd_zalloc (abfd, amt); | |
4039 | amt = sizeof (asymbol *); | |
252b5132 | 4040 | sdata->bss_section->symbol_ptr_ptr = |
dc810e39 | 4041 | (asymbol **) bfd_zalloc (abfd, amt); |
252b5132 RH |
4042 | if (sdata->bss_section->symbol == NULL |
4043 | || sdata->bss_section->symbol_ptr_ptr == NULL) | |
b34976b6 | 4044 | return FALSE; |
252b5132 RH |
4045 | sdata->bss_section->symbol->name = sdata->bss_name; |
4046 | sdata->bss_section->symbol->flags = BSF_SECTION_SYM; | |
4047 | sdata->bss_section->symbol->section = sdata->bss_section; | |
4048 | *sdata->bss_section->symbol_ptr_ptr = sdata->bss_section->symbol; | |
4049 | } | |
4050 | ||
4051 | *secp = sdata->bss_section; | |
4052 | *valp = sym->st_size; | |
4053 | } | |
4054 | ||
b34976b6 | 4055 | return TRUE; |
252b5132 | 4056 | } |
252b5132 RH |
4057 | \f |
4058 | /* Finish up dynamic symbol handling. We set the contents of various | |
4059 | dynamic sections here. */ | |
4060 | ||
b34976b6 | 4061 | static bfd_boolean |
252b5132 RH |
4062 | ppc_elf_finish_dynamic_symbol (output_bfd, info, h, sym) |
4063 | bfd *output_bfd; | |
4064 | struct bfd_link_info *info; | |
4065 | struct elf_link_hash_entry *h; | |
4066 | Elf_Internal_Sym *sym; | |
4067 | { | |
7619e7c7 | 4068 | struct ppc_elf_link_hash_table *htab; |
252b5132 RH |
4069 | |
4070 | #ifdef DEBUG | |
4071 | fprintf (stderr, "ppc_elf_finish_dynamic_symbol called for %s", | |
4072 | h->root.root.string); | |
4073 | #endif | |
4074 | ||
7619e7c7 AM |
4075 | htab = ppc_elf_hash_table (info); |
4076 | BFD_ASSERT (htab->elf.dynobj != NULL); | |
252b5132 RH |
4077 | |
4078 | if (h->plt.offset != (bfd_vma) -1) | |
4079 | { | |
252b5132 | 4080 | Elf_Internal_Rela rela; |
947216bf | 4081 | bfd_byte *loc; |
252b5132 RH |
4082 | bfd_vma reloc_index; |
4083 | ||
4084 | #ifdef DEBUG | |
4085 | fprintf (stderr, ", plt_offset = %d", h->plt.offset); | |
4086 | #endif | |
4087 | ||
4088 | /* This symbol has an entry in the procedure linkage table. Set | |
70bccea4 | 4089 | it up. */ |
252b5132 RH |
4090 | |
4091 | BFD_ASSERT (h->dynindx != -1); | |
7619e7c7 | 4092 | BFD_ASSERT (htab->plt != NULL && htab->relplt != NULL); |
252b5132 RH |
4093 | |
4094 | /* We don't need to fill in the .plt. The ppc dynamic linker | |
4095 | will fill it in. */ | |
4096 | ||
4097 | /* Fill in the entry in the .rela.plt section. */ | |
7619e7c7 AM |
4098 | rela.r_offset = (htab->plt->output_section->vma |
4099 | + htab->plt->output_offset | |
252b5132 RH |
4100 | + h->plt.offset); |
4101 | rela.r_info = ELF32_R_INFO (h->dynindx, R_PPC_JMP_SLOT); | |
4102 | rela.r_addend = 0; | |
4103 | ||
4104 | reloc_index = (h->plt.offset - PLT_INITIAL_ENTRY_SIZE) / PLT_SLOT_SIZE; | |
4105 | if (reloc_index > PLT_NUM_SINGLE_ENTRIES) | |
4106 | reloc_index -= (reloc_index - PLT_NUM_SINGLE_ENTRIES) / 2; | |
7619e7c7 AM |
4107 | loc = (htab->relplt->contents |
4108 | + reloc_index * sizeof (Elf32_External_Rela)); | |
947216bf | 4109 | bfd_elf32_swap_reloca_out (output_bfd, &rela, loc); |
252b5132 RH |
4110 | |
4111 | if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0) | |
4112 | { | |
4113 | /* Mark the symbol as undefined, rather than as defined in | |
4114 | the .plt section. Leave the value alone. */ | |
4115 | sym->st_shndx = SHN_UNDEF; | |
a4b120e1 GK |
4116 | /* If the symbol is weak, we do need to clear the value. |
4117 | Otherwise, the PLT entry would provide a definition for | |
4118 | the symbol even if the symbol wasn't defined anywhere, | |
4119 | and so the symbol would never be NULL. */ | |
c3668558 | 4120 | if ((h->elf_link_hash_flags & ELF_LINK_HASH_REF_REGULAR_NONWEAK) |
a4b120e1 GK |
4121 | == 0) |
4122 | sym->st_value = 0; | |
252b5132 RH |
4123 | } |
4124 | } | |
4125 | ||
252b5132 RH |
4126 | if ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_COPY) != 0) |
4127 | { | |
4128 | asection *s; | |
4129 | Elf_Internal_Rela rela; | |
947216bf | 4130 | bfd_byte *loc; |
252b5132 RH |
4131 | |
4132 | /* This symbols needs a copy reloc. Set it up. */ | |
4133 | ||
4134 | #ifdef DEBUG | |
4135 | fprintf (stderr, ", copy"); | |
4136 | #endif | |
4137 | ||
4138 | BFD_ASSERT (h->dynindx != -1); | |
4139 | ||
7619e7c7 AM |
4140 | if (h->size <= elf_gp_size (htab->elf.dynobj)) |
4141 | s = htab->relsbss; | |
252b5132 | 4142 | else |
7619e7c7 | 4143 | s = htab->relbss; |
252b5132 RH |
4144 | BFD_ASSERT (s != NULL); |
4145 | ||
4146 | rela.r_offset = (h->root.u.def.value | |
4147 | + h->root.u.def.section->output_section->vma | |
4148 | + h->root.u.def.section->output_offset); | |
4149 | rela.r_info = ELF32_R_INFO (h->dynindx, R_PPC_COPY); | |
4150 | rela.r_addend = 0; | |
947216bf AM |
4151 | loc = s->contents + s->reloc_count++ * sizeof (Elf32_External_Rela); |
4152 | bfd_elf32_swap_reloca_out (output_bfd, &rela, loc); | |
252b5132 RH |
4153 | } |
4154 | ||
4155 | #ifdef DEBUG | |
4156 | fprintf (stderr, "\n"); | |
4157 | #endif | |
4158 | ||
4159 | /* Mark some specially defined symbols as absolute. */ | |
4160 | if (strcmp (h->root.root.string, "_DYNAMIC") == 0 | |
4161 | || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0 | |
4162 | || strcmp (h->root.root.string, "_PROCEDURE_LINKAGE_TABLE_") == 0) | |
4163 | sym->st_shndx = SHN_ABS; | |
4164 | ||
b34976b6 | 4165 | return TRUE; |
252b5132 | 4166 | } |
252b5132 RH |
4167 | \f |
4168 | /* Finish up the dynamic sections. */ | |
4169 | ||
b34976b6 | 4170 | static bfd_boolean |
252b5132 RH |
4171 | ppc_elf_finish_dynamic_sections (output_bfd, info) |
4172 | bfd *output_bfd; | |
4173 | struct bfd_link_info *info; | |
4174 | { | |
4175 | asection *sdyn; | |
7619e7c7 | 4176 | struct ppc_elf_link_hash_table *htab; |
252b5132 RH |
4177 | |
4178 | #ifdef DEBUG | |
4179 | fprintf (stderr, "ppc_elf_finish_dynamic_sections called\n"); | |
4180 | #endif | |
4181 | ||
7619e7c7 AM |
4182 | htab = ppc_elf_hash_table (info); |
4183 | sdyn = bfd_get_section_by_name (htab->elf.dynobj, ".dynamic"); | |
252b5132 | 4184 | |
7619e7c7 | 4185 | if (htab->elf.dynamic_sections_created) |
252b5132 | 4186 | { |
252b5132 RH |
4187 | Elf32_External_Dyn *dyncon, *dynconend; |
4188 | ||
7619e7c7 | 4189 | BFD_ASSERT (htab->plt != NULL && sdyn != NULL); |
252b5132 RH |
4190 | |
4191 | dyncon = (Elf32_External_Dyn *) sdyn->contents; | |
4192 | dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->_raw_size); | |
4193 | for (; dyncon < dynconend; dyncon++) | |
4194 | { | |
4195 | Elf_Internal_Dyn dyn; | |
7619e7c7 | 4196 | asection *s; |
252b5132 | 4197 | |
7619e7c7 | 4198 | bfd_elf32_swap_dyn_in (htab->elf.dynobj, dyncon, &dyn); |
252b5132 RH |
4199 | |
4200 | switch (dyn.d_tag) | |
4201 | { | |
7619e7c7 AM |
4202 | case DT_PLTGOT: |
4203 | s = htab->plt; | |
4204 | dyn.d_un.d_ptr = s->output_section->vma + s->output_offset; | |
4205 | break; | |
252b5132 | 4206 | |
7619e7c7 AM |
4207 | case DT_PLTRELSZ: |
4208 | dyn.d_un.d_val = htab->relplt->_raw_size; | |
4209 | break; | |
252b5132 | 4210 | |
7619e7c7 AM |
4211 | case DT_JMPREL: |
4212 | s = htab->relplt; | |
4213 | dyn.d_un.d_ptr = s->output_section->vma + s->output_offset; | |
4214 | break; | |
4215 | ||
4216 | default: | |
4217 | continue; | |
252b5132 | 4218 | } |
7619e7c7 AM |
4219 | |
4220 | bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); | |
252b5132 RH |
4221 | } |
4222 | } | |
4223 | ||
4224 | /* Add a blrl instruction at _GLOBAL_OFFSET_TABLE_-4 so that a function can | |
4225 | easily find the address of the _GLOBAL_OFFSET_TABLE_. */ | |
7619e7c7 | 4226 | if (htab->got) |
252b5132 | 4227 | { |
7619e7c7 | 4228 | unsigned char *contents = htab->got->contents; |
dc810e39 | 4229 | bfd_put_32 (output_bfd, (bfd_vma) 0x4e800021 /* blrl */, contents); |
252b5132 RH |
4230 | |
4231 | if (sdyn == NULL) | |
7619e7c7 | 4232 | bfd_put_32 (output_bfd, (bfd_vma) 0, contents + 4); |
252b5132 RH |
4233 | else |
4234 | bfd_put_32 (output_bfd, | |
4235 | sdyn->output_section->vma + sdyn->output_offset, | |
7619e7c7 | 4236 | contents + 4); |
252b5132 | 4237 | |
7619e7c7 | 4238 | elf_section_data (htab->got->output_section)->this_hdr.sh_entsize = 4; |
252b5132 RH |
4239 | } |
4240 | ||
b34976b6 | 4241 | return TRUE; |
252b5132 | 4242 | } |
252b5132 RH |
4243 | \f |
4244 | /* The RELOCATE_SECTION function is called by the ELF backend linker | |
4245 | to handle the relocations for a section. | |
4246 | ||
4247 | The relocs are always passed as Rela structures; if the section | |
4248 | actually uses Rel structures, the r_addend field will always be | |
4249 | zero. | |
4250 | ||
4251 | This function is responsible for adjust the section contents as | |
4252 | necessary, and (if using Rela relocs and generating a | |
4253 | relocateable output file) adjusting the reloc addend as | |
4254 | necessary. | |
4255 | ||
4256 | This function does not have to worry about setting the reloc | |
4257 | address or the reloc symbol index. | |
4258 | ||
4259 | LOCAL_SYMS is a pointer to the swapped in local symbols. | |
4260 | ||
4261 | LOCAL_SECTIONS is an array giving the section in the input file | |
4262 | corresponding to the st_shndx field of each local symbol. | |
4263 | ||
4264 | The global hash table entry for the global symbols can be found | |
4265 | via elf_sym_hashes (input_bfd). | |
4266 | ||
4267 | When generating relocateable output, this function must handle | |
4268 | STB_LOCAL/STT_SECTION symbols specially. The output symbol is | |
4269 | going to be the section symbol corresponding to the output | |
4270 | section, which means that the addend must be adjusted | |
4271 | accordingly. */ | |
4272 | ||
b34976b6 | 4273 | static bfd_boolean |
252b5132 RH |
4274 | ppc_elf_relocate_section (output_bfd, info, input_bfd, input_section, |
4275 | contents, relocs, local_syms, local_sections) | |
4276 | bfd *output_bfd; | |
4277 | struct bfd_link_info *info; | |
4278 | bfd *input_bfd; | |
4279 | asection *input_section; | |
4280 | bfd_byte *contents; | |
4281 | Elf_Internal_Rela *relocs; | |
4282 | Elf_Internal_Sym *local_syms; | |
4283 | asection **local_sections; | |
4284 | { | |
7619e7c7 AM |
4285 | Elf_Internal_Shdr *symtab_hdr; |
4286 | struct elf_link_hash_entry **sym_hashes; | |
4287 | struct ppc_elf_link_hash_table *htab; | |
4288 | Elf_Internal_Rela *rel; | |
4289 | Elf_Internal_Rela *relend; | |
4290 | Elf_Internal_Rela outrel; | |
4291 | bfd_byte *loc; | |
b34976b6 | 4292 | asection *sreloc = NULL; |
252b5132 | 4293 | bfd_vma *local_got_offsets; |
b34976b6 | 4294 | bfd_boolean ret = TRUE; |
b34976b6 | 4295 | |
252b5132 RH |
4296 | #ifdef DEBUG |
4297 | fprintf (stderr, "ppc_elf_relocate_section called for %s section %s, %ld relocations%s\n", | |
8f615d07 | 4298 | bfd_archive_filename (input_bfd), |
252b5132 | 4299 | bfd_section_name(input_bfd, input_section), |
8da6118f | 4300 | (long) input_section->reloc_count, |
252b5132 RH |
4301 | (info->relocateable) ? " (relocatable)" : ""); |
4302 | #endif | |
4303 | ||
b491616a | 4304 | if (info->relocateable) |
b34976b6 | 4305 | return TRUE; |
b491616a | 4306 | |
8da6118f KH |
4307 | if (!ppc_elf_howto_table[R_PPC_ADDR32]) |
4308 | /* Initialize howto table if needed. */ | |
252b5132 RH |
4309 | ppc_elf_howto_init (); |
4310 | ||
7619e7c7 | 4311 | htab = ppc_elf_hash_table (info); |
252b5132 | 4312 | local_got_offsets = elf_local_got_offsets (input_bfd); |
7619e7c7 AM |
4313 | symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; |
4314 | sym_hashes = elf_sym_hashes (input_bfd); | |
4315 | rel = relocs; | |
4316 | relend = relocs + input_section->reloc_count; | |
252b5132 RH |
4317 | for (; rel < relend; rel++) |
4318 | { | |
7619e7c7 AM |
4319 | enum elf_ppc_reloc_type r_type; |
4320 | bfd_vma addend; | |
4321 | bfd_reloc_status_type r; | |
4322 | Elf_Internal_Sym *sym; | |
4323 | asection *sec; | |
4324 | struct elf_link_hash_entry *h; | |
4325 | const char *sym_name; | |
252b5132 RH |
4326 | reloc_howto_type *howto; |
4327 | unsigned long r_symndx; | |
4328 | bfd_vma relocation; | |
7619e7c7 | 4329 | bfd_vma branch_bit, insn, from; |
7619e7c7 AM |
4330 | bfd_boolean unresolved_reloc; |
4331 | bfd_boolean warned; | |
4332 | unsigned int tls_type, tls_mask, tls_gd; | |
4333 | ||
4334 | r_type = (enum elf_ppc_reloc_type)ELF32_R_TYPE (rel->r_info); | |
4335 | sym = (Elf_Internal_Sym *) 0; | |
4336 | sec = (asection *) 0; | |
4337 | h = (struct elf_link_hash_entry *) 0; | |
4338 | unresolved_reloc = FALSE; | |
4339 | warned = FALSE; | |
252b5132 | 4340 | r_symndx = ELF32_R_SYM (rel->r_info); |
252b5132 RH |
4341 | if (r_symndx < symtab_hdr->sh_info) |
4342 | { | |
4343 | sym = local_syms + r_symndx; | |
4344 | sec = local_sections[r_symndx]; | |
7619e7c7 | 4345 | sym_name = bfd_elf_local_sym_name (input_bfd, sym); |
252b5132 | 4346 | |
f8df10f4 | 4347 | relocation = _bfd_elf_rela_local_sym (output_bfd, sym, sec, rel); |
252b5132 RH |
4348 | } |
4349 | else | |
4350 | { | |
4351 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | |
4352 | while (h->root.type == bfd_link_hash_indirect | |
4353 | || h->root.type == bfd_link_hash_warning) | |
4354 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
4355 | sym_name = h->root.root.string; | |
e1e0340b | 4356 | |
7619e7c7 | 4357 | relocation = 0; |
252b5132 RH |
4358 | if (h->root.type == bfd_link_hash_defined |
4359 | || h->root.type == bfd_link_hash_defweak) | |
4360 | { | |
4361 | sec = h->root.u.def.section; | |
70bccea4 AM |
4362 | /* Set a flag that will be cleared later if we find a |
4363 | relocation value for this symbol. output_section | |
4364 | is typically NULL for symbols satisfied by a shared | |
4365 | library. */ | |
7619e7c7 AM |
4366 | if (sec->output_section == NULL) |
4367 | unresolved_reloc = TRUE; | |
252b5132 RH |
4368 | else |
4369 | relocation = (h->root.u.def.value | |
4370 | + sec->output_section->vma | |
4371 | + sec->output_offset); | |
4372 | } | |
4373 | else if (h->root.type == bfd_link_hash_undefweak) | |
7619e7c7 | 4374 | ; |
671bae9c | 4375 | else if (info->shared |
671bae9c | 4376 | && !info->no_undefined |
3a27a730 | 4377 | && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT) |
7619e7c7 | 4378 | ; |
252b5132 RH |
4379 | else |
4380 | { | |
7619e7c7 AM |
4381 | if (! ((*info->callbacks->undefined_symbol) |
4382 | (info, h->root.root.string, input_bfd, input_section, | |
4383 | rel->r_offset, (!info->shared | |
4384 | || info->no_undefined | |
4385 | || ELF_ST_VISIBILITY (h->other))))) | |
b34976b6 | 4386 | return FALSE; |
7619e7c7 AM |
4387 | warned = TRUE; |
4388 | } | |
4389 | } | |
4390 | ||
4391 | /* TLS optimizations. Replace instruction sequences and relocs | |
4392 | based on information we collected in tls_optimize. We edit | |
4393 | RELOCS so that --emit-relocs will output something sensible | |
4394 | for the final instruction stream. */ | |
4395 | tls_mask = 0; | |
4396 | tls_gd = 0; | |
4397 | if (IS_PPC_TLS_RELOC (r_type)) | |
4398 | { | |
4399 | if (h != NULL) | |
4400 | tls_mask = ((struct ppc_elf_link_hash_entry *) h)->tls_mask; | |
4401 | else if (local_got_offsets != NULL) | |
4402 | { | |
4403 | char *lgot_masks; | |
4404 | lgot_masks = (char *) (local_got_offsets + symtab_hdr->sh_info); | |
4405 | tls_mask = lgot_masks[r_symndx]; | |
4406 | } | |
4407 | } | |
4408 | ||
4409 | /* Ensure reloc mapping code below stays sane. */ | |
4410 | if ((R_PPC_GOT_TLSLD16 & 3) != (R_PPC_GOT_TLSGD16 & 3) | |
4411 | || (R_PPC_GOT_TLSLD16_LO & 3) != (R_PPC_GOT_TLSGD16_LO & 3) | |
4412 | || (R_PPC_GOT_TLSLD16_HI & 3) != (R_PPC_GOT_TLSGD16_HI & 3) | |
4413 | || (R_PPC_GOT_TLSLD16_HA & 3) != (R_PPC_GOT_TLSGD16_HA & 3) | |
4414 | || (R_PPC_GOT_TLSLD16 & 3) != (R_PPC_GOT_TPREL16 & 3) | |
4415 | || (R_PPC_GOT_TLSLD16_LO & 3) != (R_PPC_GOT_TPREL16_LO & 3) | |
4416 | || (R_PPC_GOT_TLSLD16_HI & 3) != (R_PPC_GOT_TPREL16_HI & 3) | |
4417 | || (R_PPC_GOT_TLSLD16_HA & 3) != (R_PPC_GOT_TPREL16_HA & 3)) | |
4418 | abort (); | |
4419 | switch (r_type) | |
4420 | { | |
4421 | default: | |
4422 | break; | |
4423 | ||
4424 | case R_PPC_GOT_TPREL16: | |
4425 | case R_PPC_GOT_TPREL16_LO: | |
4426 | if (tls_mask != 0 | |
4427 | && (tls_mask & TLS_TPREL) == 0) | |
4428 | { | |
4429 | bfd_vma insn; | |
4430 | insn = bfd_get_32 (output_bfd, contents + rel->r_offset - 2); | |
4431 | insn &= 31 << 21; | |
4432 | insn |= 0x3c020000; /* addis 0,2,0 */ | |
4433 | bfd_put_32 (output_bfd, insn, contents + rel->r_offset - 2); | |
4434 | r_type = R_PPC_TPREL16_HA; | |
4435 | rel->r_info = ELF32_R_INFO (r_symndx, r_type); | |
4436 | } | |
4437 | break; | |
4438 | ||
4439 | case R_PPC_TLS: | |
4440 | if (tls_mask != 0 | |
4441 | && (tls_mask & TLS_TPREL) == 0) | |
4442 | { | |
4443 | bfd_vma insn, rtra; | |
4444 | insn = bfd_get_32 (output_bfd, contents + rel->r_offset); | |
4445 | if ((insn & ((31 << 26) | (31 << 11))) | |
4446 | == ((31 << 26) | (2 << 11))) | |
4447 | rtra = insn & ((1 << 26) - (1 << 16)); | |
4448 | else if ((insn & ((31 << 26) | (31 << 16))) | |
4449 | == ((31 << 26) | (2 << 16))) | |
4450 | rtra = (insn & (31 << 21)) | ((insn & (31 << 11)) << 5); | |
4451 | else | |
4452 | abort (); | |
4453 | if ((insn & ((1 << 11) - (1 << 1))) == 266 << 1) | |
4454 | /* add -> addi. */ | |
4455 | insn = 14 << 26; | |
4456 | else if ((insn & (31 << 1)) == 23 << 1 | |
4457 | && ((insn & (31 << 6)) < 14 << 6 | |
4458 | || ((insn & (31 << 6)) >= 16 << 6 | |
4459 | && (insn & (31 << 6)) < 24 << 6))) | |
4460 | /* load and store indexed -> dform. */ | |
4461 | insn = (32 | ((insn >> 6) & 31)) << 26; | |
4462 | else if ((insn & (31 << 1)) == 21 << 1 | |
4463 | && (insn & (0x1a << 6)) == 0) | |
4464 | /* ldx, ldux, stdx, stdux -> ld, ldu, std, stdu. */ | |
4465 | insn = (((58 | ((insn >> 6) & 4)) << 26) | |
4466 | | ((insn >> 6) & 1)); | |
4467 | else if ((insn & (31 << 1)) == 21 << 1 | |
4468 | && (insn & ((1 << 11) - (1 << 1))) == 341 << 1) | |
4469 | /* lwax -> lwa. */ | |
4470 | insn = (58 << 26) | 2; | |
4471 | else | |
4472 | abort (); | |
4473 | insn |= rtra; | |
4474 | bfd_put_32 (output_bfd, insn, contents + rel->r_offset); | |
4475 | r_type = R_PPC_TPREL16_LO; | |
4476 | rel->r_info = ELF32_R_INFO (r_symndx, r_type); | |
4477 | /* Was PPC_TLS which sits on insn boundary, now | |
4478 | PPC_TPREL16_LO which is at insn+2. */ | |
4479 | rel->r_offset += 2; | |
4480 | } | |
4481 | break; | |
4482 | ||
4483 | case R_PPC_GOT_TLSGD16_HI: | |
4484 | case R_PPC_GOT_TLSGD16_HA: | |
4485 | tls_gd = TLS_TPRELGD; | |
4486 | if (tls_mask != 0 && (tls_mask & TLS_GD) == 0) | |
4487 | goto tls_gdld_hi; | |
4488 | break; | |
4489 | ||
4490 | case R_PPC_GOT_TLSLD16_HI: | |
4491 | case R_PPC_GOT_TLSLD16_HA: | |
4492 | if (tls_mask != 0 && (tls_mask & TLS_LD) == 0) | |
4493 | { | |
4494 | tls_gdld_hi: | |
4495 | if ((tls_mask & tls_gd) != 0) | |
4496 | r_type = (((r_type - (R_PPC_GOT_TLSGD16 & 3)) & 3) | |
4497 | + R_PPC_GOT_TPREL16); | |
4498 | else | |
4499 | { | |
4500 | bfd_put_32 (output_bfd, NOP, contents + rel->r_offset); | |
4501 | rel->r_offset -= 2; | |
4502 | r_type = R_PPC_NONE; | |
4503 | } | |
4504 | rel->r_info = ELF32_R_INFO (r_symndx, r_type); | |
4505 | } | |
4506 | break; | |
4507 | ||
4508 | case R_PPC_GOT_TLSGD16: | |
4509 | case R_PPC_GOT_TLSGD16_LO: | |
4510 | tls_gd = TLS_TPRELGD; | |
4511 | if (tls_mask != 0 && (tls_mask & TLS_GD) == 0) | |
4512 | goto tls_get_addr_check; | |
4513 | break; | |
4514 | ||
4515 | case R_PPC_GOT_TLSLD16: | |
4516 | case R_PPC_GOT_TLSLD16_LO: | |
4517 | if (tls_mask != 0 && (tls_mask & TLS_LD) == 0) | |
4518 | { | |
4519 | tls_get_addr_check: | |
4520 | if (rel + 1 < relend) | |
4521 | { | |
4522 | enum elf_ppc_reloc_type r_type2; | |
4523 | unsigned long r_symndx2; | |
4524 | struct elf_link_hash_entry *h2; | |
87d243f1 | 4525 | bfd_vma insn1, insn2; |
7619e7c7 AM |
4526 | bfd_vma offset; |
4527 | ||
4528 | /* The next instruction should be a call to | |
4529 | __tls_get_addr. Peek at the reloc to be sure. */ | |
4530 | r_type2 | |
4531 | = (enum elf_ppc_reloc_type) ELF32_R_TYPE (rel[1].r_info); | |
4532 | r_symndx2 = ELF32_R_SYM (rel[1].r_info); | |
4533 | if (r_symndx2 < symtab_hdr->sh_info | |
4534 | || (r_type2 != R_PPC_REL14 | |
4535 | && r_type2 != R_PPC_REL14_BRTAKEN | |
4536 | && r_type2 != R_PPC_REL14_BRNTAKEN | |
4537 | && r_type2 != R_PPC_REL24 | |
4538 | && r_type2 != R_PPC_PLTREL24)) | |
4539 | break; | |
4540 | ||
4541 | h2 = sym_hashes[r_symndx2 - symtab_hdr->sh_info]; | |
4542 | while (h2->root.type == bfd_link_hash_indirect | |
4543 | || h2->root.type == bfd_link_hash_warning) | |
4544 | h2 = (struct elf_link_hash_entry *) h2->root.u.i.link; | |
4545 | if (h2 == NULL || h2 != htab->tls_get_addr) | |
4546 | break; | |
4547 | ||
4548 | /* OK, it checks out. Replace the call. */ | |
4549 | offset = rel[1].r_offset; | |
4550 | insn1 = bfd_get_32 (output_bfd, | |
4551 | contents + rel->r_offset - 2); | |
7619e7c7 AM |
4552 | if ((tls_mask & tls_gd) != 0) |
4553 | { | |
4554 | /* IE */ | |
4555 | insn1 &= (1 << 26) - 1; | |
4556 | insn1 |= 32 << 26; /* lwz */ | |
4557 | insn2 = 0x7c631214; /* add 3,3,2 */ | |
4558 | rel[1].r_info = ELF32_R_INFO (r_symndx2, R_PPC_NONE); | |
4559 | r_type = (((r_type - (R_PPC_GOT_TLSGD16 & 3)) & 3) | |
4560 | + R_PPC_GOT_TPREL16); | |
4561 | rel->r_info = ELF32_R_INFO (r_symndx, r_type); | |
4562 | } | |
4563 | else | |
4564 | { | |
4565 | /* LE */ | |
4566 | insn1 = 0x3c620000; /* addis 3,2,0 */ | |
4567 | insn2 = 0x38630000; /* addi 3,3,0 */ | |
4568 | if (tls_gd == 0) | |
4569 | { | |
4570 | /* Was an LD reloc. */ | |
4571 | r_symndx = 0; | |
4572 | rel->r_addend = htab->tls_sec->vma + DTP_OFFSET; | |
4573 | rel[1].r_addend = htab->tls_sec->vma + DTP_OFFSET; | |
4574 | } | |
4575 | r_type = R_PPC_TPREL16_HA; | |
4576 | rel->r_info = ELF32_R_INFO (r_symndx, r_type); | |
4577 | rel[1].r_info = ELF32_R_INFO (r_symndx, | |
4578 | R_PPC_TPREL16_LO); | |
4579 | rel[1].r_offset += 2; | |
4580 | } | |
7619e7c7 AM |
4581 | bfd_put_32 (output_bfd, insn1, contents + rel->r_offset - 2); |
4582 | bfd_put_32 (output_bfd, insn2, contents + offset); | |
7619e7c7 AM |
4583 | if (tls_gd == 0) |
4584 | { | |
4585 | /* We changed the symbol on an LD reloc. Start over | |
70bccea4 | 4586 | in order to get h, sym, sec etc. right. */ |
7619e7c7 AM |
4587 | rel--; |
4588 | continue; | |
4589 | } | |
4590 | } | |
252b5132 | 4591 | } |
7619e7c7 AM |
4592 | break; |
4593 | } | |
4594 | ||
4595 | /* Handle other relocations that tweak non-addend part of insn. */ | |
4596 | branch_bit = 0; | |
4597 | switch (r_type) | |
4598 | { | |
4599 | default: | |
4600 | break; | |
4601 | ||
4602 | /* Branch taken prediction relocations. */ | |
4603 | case R_PPC_ADDR14_BRTAKEN: | |
4604 | case R_PPC_REL14_BRTAKEN: | |
4605 | branch_bit = BRANCH_PREDICT_BIT; | |
4606 | /* Fall thru */ | |
4607 | ||
4608 | /* Branch not taken predicition relocations. */ | |
4609 | case R_PPC_ADDR14_BRNTAKEN: | |
4610 | case R_PPC_REL14_BRNTAKEN: | |
4611 | insn = bfd_get_32 (output_bfd, contents + rel->r_offset); | |
4612 | insn &= ~BRANCH_PREDICT_BIT; | |
4613 | insn |= branch_bit; | |
4614 | ||
4615 | from = (rel->r_offset | |
4616 | + input_section->output_offset | |
4617 | + input_section->output_section->vma); | |
4618 | ||
4619 | /* Invert 'y' bit if not the default. */ | |
4620 | if ((bfd_signed_vma) (relocation + rel->r_addend - from) < 0) | |
4621 | insn ^= BRANCH_PREDICT_BIT; | |
4622 | ||
4623 | bfd_put_32 (output_bfd, insn, contents + rel->r_offset); | |
4624 | break; | |
252b5132 RH |
4625 | } |
4626 | ||
7619e7c7 AM |
4627 | addend = rel->r_addend; |
4628 | tls_type = 0; | |
4629 | howto = NULL; | |
4630 | if ((unsigned) r_type < (unsigned) R_PPC_max) | |
4631 | howto = ppc_elf_howto_table[(int) r_type]; | |
4632 | switch (r_type) | |
252b5132 RH |
4633 | { |
4634 | default: | |
7619e7c7 AM |
4635 | (*_bfd_error_handler) |
4636 | (_("%s: unknown relocation type %d for symbol %s"), | |
4637 | bfd_archive_filename (input_bfd), (int) r_type, sym_name); | |
252b5132 RH |
4638 | |
4639 | bfd_set_error (bfd_error_bad_value); | |
b34976b6 | 4640 | ret = FALSE; |
252b5132 RH |
4641 | continue; |
4642 | ||
7619e7c7 AM |
4643 | case R_PPC_NONE: |
4644 | case R_PPC_TLS: | |
4645 | case R_PPC_EMB_MRKREF: | |
4646 | case R_PPC_GNU_VTINHERIT: | |
4647 | case R_PPC_GNU_VTENTRY: | |
7595d193 L |
4648 | continue; |
4649 | ||
7619e7c7 AM |
4650 | /* GOT16 relocations. Like an ADDR16 using the symbol's |
4651 | address in the GOT as relocation value instead of the | |
4652 | symbol's value itself. Also, create a GOT entry for the | |
4653 | symbol and put the symbol value there. */ | |
4654 | case R_PPC_GOT_TLSGD16: | |
4655 | case R_PPC_GOT_TLSGD16_LO: | |
4656 | case R_PPC_GOT_TLSGD16_HI: | |
4657 | case R_PPC_GOT_TLSGD16_HA: | |
4658 | tls_type = TLS_TLS | TLS_GD; | |
4659 | goto dogot; | |
4660 | ||
4661 | case R_PPC_GOT_TLSLD16: | |
4662 | case R_PPC_GOT_TLSLD16_LO: | |
4663 | case R_PPC_GOT_TLSLD16_HI: | |
4664 | case R_PPC_GOT_TLSLD16_HA: | |
4665 | tls_type = TLS_TLS | TLS_LD; | |
4666 | goto dogot; | |
4667 | ||
4668 | case R_PPC_GOT_TPREL16: | |
4669 | case R_PPC_GOT_TPREL16_LO: | |
4670 | case R_PPC_GOT_TPREL16_HI: | |
4671 | case R_PPC_GOT_TPREL16_HA: | |
4672 | tls_type = TLS_TLS | TLS_TPREL; | |
4673 | goto dogot; | |
4674 | ||
4675 | case R_PPC_GOT_DTPREL16: | |
4676 | case R_PPC_GOT_DTPREL16_LO: | |
4677 | case R_PPC_GOT_DTPREL16_HI: | |
4678 | case R_PPC_GOT_DTPREL16_HA: | |
4679 | tls_type = TLS_TLS | TLS_DTPREL; | |
4680 | goto dogot; | |
4681 | ||
4682 | case R_PPC_GOT16: | |
4683 | case R_PPC_GOT16_LO: | |
4684 | case R_PPC_GOT16_HI: | |
4685 | case R_PPC_GOT16_HA: | |
4686 | dogot: | |
4687 | { | |
4688 | /* Relocation is to the entry for this symbol in the global | |
4689 | offset table. */ | |
4690 | bfd_vma off; | |
4691 | bfd_vma *offp; | |
4692 | unsigned long indx; | |
4693 | ||
4694 | if (htab->got == NULL) | |
4695 | abort (); | |
4696 | ||
4697 | indx = 0; | |
4698 | if (tls_type == (TLS_TLS | TLS_LD) | |
d881513a | 4699 | && (h == NULL |
7619e7c7 AM |
4700 | || !(h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC))) |
4701 | offp = &htab->tlsld_got.offset; | |
4702 | else if (h != NULL) | |
4703 | { | |
4704 | bfd_boolean dyn; | |
4705 | dyn = htab->elf.dynamic_sections_created; | |
ee05f2fe | 4706 | if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h) |
7619e7c7 AM |
4707 | || (info->shared |
4708 | && SYMBOL_REFERENCES_LOCAL (info, h))) | |
4709 | /* This is actually a static link, or it is a | |
4710 | -Bsymbolic link and the symbol is defined | |
4711 | locally, or the symbol was forced to be local | |
4712 | because of a version file. */ | |
4713 | ; | |
4714 | else | |
4715 | { | |
4716 | indx = h->dynindx; | |
4717 | unresolved_reloc = FALSE; | |
4718 | } | |
4719 | offp = &h->got.offset; | |
4720 | } | |
4721 | else | |
4722 | { | |
4723 | if (local_got_offsets == NULL) | |
4724 | abort (); | |
4725 | offp = &local_got_offsets[r_symndx]; | |
4726 | } | |
4727 | ||
4728 | /* The offset must always be a multiple of 4. We use the | |
4729 | least significant bit to record whether we have already | |
4730 | processed this entry. */ | |
4731 | off = *offp; | |
4732 | if ((off & 1) != 0) | |
4733 | off &= ~1; | |
4734 | else | |
4735 | { | |
70bccea4 AM |
4736 | unsigned int tls_m = (tls_mask |
4737 | & (TLS_LD | TLS_GD | TLS_DTPREL | |
4738 | | TLS_TPREL | TLS_TPRELGD)); | |
4739 | ||
4740 | if (offp == &htab->tlsld_got.offset) | |
4741 | tls_m = TLS_LD; | |
4742 | else if (h == NULL | |
4743 | || !(h->elf_link_hash_flags | |
4744 | & ELF_LINK_HASH_DEF_DYNAMIC)) | |
4745 | tls_m &= ~TLS_LD; | |
4746 | ||
4747 | /* We might have multiple got entries for this sym. | |
4748 | Initialize them all. */ | |
4749 | do | |
7619e7c7 | 4750 | { |
70bccea4 AM |
4751 | int tls_ty = 0; |
4752 | ||
4753 | if ((tls_m & TLS_LD) != 0) | |
7619e7c7 | 4754 | { |
70bccea4 AM |
4755 | tls_ty = TLS_TLS | TLS_LD; |
4756 | tls_m &= ~TLS_LD; | |
4757 | } | |
4758 | else if ((tls_m & TLS_GD) != 0) | |
4759 | { | |
4760 | tls_ty = TLS_TLS | TLS_GD; | |
4761 | tls_m &= ~TLS_GD; | |
4762 | } | |
4763 | else if ((tls_m & TLS_DTPREL) != 0) | |
4764 | { | |
4765 | tls_ty = TLS_TLS | TLS_DTPREL; | |
4766 | tls_m &= ~TLS_DTPREL; | |
4767 | } | |
4768 | else if ((tls_m & (TLS_TPREL | TLS_TPRELGD)) != 0) | |
4769 | { | |
4770 | tls_ty = TLS_TLS | TLS_TPREL; | |
4771 | tls_m = 0; | |
7619e7c7 | 4772 | } |
7619e7c7 | 4773 | |
70bccea4 AM |
4774 | /* Generate relocs for the dynamic linker. */ |
4775 | if (info->shared || indx != 0) | |
7619e7c7 | 4776 | { |
70bccea4 AM |
4777 | outrel.r_offset = (htab->got->output_section->vma |
4778 | + htab->got->output_offset | |
4779 | + off); | |
e515b051 | 4780 | outrel.r_addend = 0; |
70bccea4 AM |
4781 | if (tls_ty & (TLS_LD | TLS_GD)) |
4782 | { | |
4783 | outrel.r_info = ELF32_R_INFO (indx, R_PPC_DTPMOD32); | |
70bccea4 AM |
4784 | if (tls_ty == (TLS_TLS | TLS_GD)) |
4785 | { | |
4786 | loc = htab->relgot->contents; | |
4787 | loc += (htab->relgot->reloc_count++ | |
4788 | * sizeof (Elf32_External_Rela)); | |
4789 | bfd_elf32_swap_reloca_out (output_bfd, | |
4790 | &outrel, loc); | |
e515b051 | 4791 | outrel.r_offset += 4; |
70bccea4 AM |
4792 | outrel.r_info |
4793 | = ELF32_R_INFO (indx, R_PPC_DTPREL32); | |
70bccea4 AM |
4794 | } |
4795 | } | |
4796 | else if (tls_ty == (TLS_TLS | TLS_DTPREL)) | |
4797 | outrel.r_info = ELF32_R_INFO (indx, R_PPC_DTPREL32); | |
4798 | else if (tls_ty == (TLS_TLS | TLS_TPREL)) | |
4799 | outrel.r_info = ELF32_R_INFO (indx, R_PPC_TPREL32); | |
4800 | else if (indx == 0) | |
4801 | outrel.r_info = ELF32_R_INFO (indx, R_PPC_RELATIVE); | |
4802 | else | |
4803 | outrel.r_info = ELF32_R_INFO (indx, R_PPC_GLOB_DAT); | |
70bccea4 | 4804 | if (indx == 0) |
e515b051 AM |
4805 | { |
4806 | outrel.r_addend += relocation; | |
4807 | if (tls_ty & (TLS_GD | TLS_DTPREL | TLS_TPREL)) | |
4808 | outrel.r_addend -= htab->tls_sec->vma; | |
4809 | } | |
70bccea4 AM |
4810 | loc = htab->relgot->contents; |
4811 | loc += (htab->relgot->reloc_count++ | |
4812 | * sizeof (Elf32_External_Rela)); | |
4813 | bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc); | |
7619e7c7 AM |
4814 | } |
4815 | ||
70bccea4 AM |
4816 | /* Init the .got section contents if we're not |
4817 | emitting a reloc. */ | |
4818 | else | |
7619e7c7 | 4819 | { |
70bccea4 AM |
4820 | bfd_vma value = relocation; |
4821 | ||
7b609f53 AM |
4822 | if (tls_ty == (TLS_TLS | TLS_LD)) |
4823 | value = 1; | |
4824 | else if (tls_ty != 0) | |
70bccea4 AM |
4825 | { |
4826 | value -= htab->tls_sec->vma + DTP_OFFSET; | |
7b609f53 | 4827 | if (tls_ty == (TLS_TLS | TLS_TPREL)) |
70bccea4 | 4828 | value += DTP_OFFSET - TP_OFFSET; |
70bccea4 | 4829 | |
7b609f53 AM |
4830 | if (tls_ty == (TLS_TLS | TLS_GD)) |
4831 | { | |
4832 | bfd_put_32 (output_bfd, value, | |
4833 | htab->got->contents + off + 4); | |
4834 | value = 1; | |
4835 | } | |
70bccea4 | 4836 | } |
70bccea4 AM |
4837 | bfd_put_32 (output_bfd, value, |
4838 | htab->got->contents + off); | |
7619e7c7 | 4839 | } |
70bccea4 AM |
4840 | |
4841 | off += 4; | |
4842 | if (tls_ty & (TLS_LD | TLS_GD)) | |
4843 | off += 4; | |
7619e7c7 | 4844 | } |
70bccea4 AM |
4845 | while (tls_m != 0); |
4846 | ||
4847 | off = *offp; | |
4848 | *offp = off | 1; | |
7619e7c7 AM |
4849 | } |
4850 | ||
4851 | if (off >= (bfd_vma) -2) | |
4852 | abort (); | |
4853 | ||
70bccea4 AM |
4854 | if ((tls_type & TLS_TLS) != 0) |
4855 | { | |
4856 | if (tls_type != (TLS_TLS | TLS_LD)) | |
4857 | { | |
4858 | if ((tls_mask & TLS_LD) != 0 | |
4859 | && !(h == NULL | |
4860 | || !(h->elf_link_hash_flags | |
4861 | & ELF_LINK_HASH_DEF_DYNAMIC))) | |
4862 | off += 8; | |
4863 | if (tls_type != (TLS_TLS | TLS_GD)) | |
4864 | { | |
4865 | if ((tls_mask & TLS_GD) != 0) | |
4866 | off += 8; | |
4867 | if (tls_type != (TLS_TLS | TLS_DTPREL)) | |
4868 | { | |
4869 | if ((tls_mask & TLS_DTPREL) != 0) | |
4870 | off += 4; | |
4871 | } | |
4872 | } | |
4873 | } | |
4874 | } | |
4875 | ||
7619e7c7 AM |
4876 | relocation = htab->got->output_offset + off - 4; |
4877 | ||
4878 | /* Addends on got relocations don't make much sense. | |
4879 | x+off@got is actually x@got+off, and since the got is | |
4880 | generated by a hash table traversal, the value in the | |
4881 | got at entry m+n bears little relation to the entry m. */ | |
4882 | if (addend != 0) | |
4883 | (*_bfd_error_handler) | |
7b609f53 | 4884 | (_("%s(%s+0x%lx): non-zero addend on %s reloc against `%s'"), |
7619e7c7 AM |
4885 | bfd_archive_filename (input_bfd), |
4886 | bfd_get_section_name (input_bfd, input_section), | |
4887 | (long) rel->r_offset, | |
7b609f53 | 4888 | howto->name, |
7619e7c7 AM |
4889 | sym_name); |
4890 | } | |
70bccea4 | 4891 | break; |
7619e7c7 | 4892 | |
252b5132 | 4893 | /* Relocations that need no special processing. */ |
7619e7c7 | 4894 | case R_PPC_LOCAL24PC: |
252b5132 RH |
4895 | /* It makes no sense to point a local relocation |
4896 | at a symbol not in this object. */ | |
7b609f53 | 4897 | if (unresolved_reloc) |
252b5132 | 4898 | { |
464e1740 ILT |
4899 | if (! (*info->callbacks->undefined_symbol) (info, |
4900 | h->root.root.string, | |
4901 | input_bfd, | |
4902 | input_section, | |
5cc7c785 | 4903 | rel->r_offset, |
b34976b6 AM |
4904 | TRUE)) |
4905 | return FALSE; | |
252b5132 RH |
4906 | continue; |
4907 | } | |
4908 | break; | |
4909 | ||
7619e7c7 AM |
4910 | case R_PPC_DTPREL16: |
4911 | case R_PPC_DTPREL16_LO: | |
4912 | case R_PPC_DTPREL16_HI: | |
4913 | case R_PPC_DTPREL16_HA: | |
4914 | addend -= htab->tls_sec->vma + DTP_OFFSET; | |
4915 | break; | |
4916 | ||
70bccea4 AM |
4917 | /* Relocations that may need to be propagated if this is a shared |
4918 | object. */ | |
7619e7c7 AM |
4919 | case R_PPC_TPREL16: |
4920 | case R_PPC_TPREL16_LO: | |
4921 | case R_PPC_TPREL16_HI: | |
4922 | case R_PPC_TPREL16_HA: | |
4923 | addend -= htab->tls_sec->vma + TP_OFFSET; | |
4924 | /* The TPREL16 relocs shouldn't really be used in shared | |
4925 | libs as they will result in DT_TEXTREL being set, but | |
4926 | support them anyway. */ | |
4927 | goto dodyn; | |
4928 | ||
4929 | case R_PPC_TPREL32: | |
4930 | addend -= htab->tls_sec->vma + TP_OFFSET; | |
4931 | goto dodyn; | |
4932 | ||
4933 | case R_PPC_DTPREL32: | |
4934 | addend -= htab->tls_sec->vma + DTP_OFFSET; | |
4935 | goto dodyn; | |
4936 | ||
e515b051 AM |
4937 | case R_PPC_DTPMOD32: |
4938 | relocation = 1; | |
4939 | addend = 0; | |
4940 | goto dodyn; | |
4941 | ||
7619e7c7 AM |
4942 | case R_PPC_REL24: |
4943 | case R_PPC_REL32: | |
4944 | case R_PPC_REL14: | |
4945 | case R_PPC_REL14_BRTAKEN: | |
4946 | case R_PPC_REL14_BRNTAKEN: | |
252b5132 RH |
4947 | /* If these relocations are not to a named symbol, they can be |
4948 | handled right here, no need to bother the dynamic linker. */ | |
4949 | if (h == NULL | |
e1e0340b GK |
4950 | || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0 |
4951 | || SYMBOL_REFERENCES_LOCAL (info, h)) | |
252b5132 | 4952 | break; |
70bccea4 | 4953 | /* fall through */ |
252b5132 | 4954 | |
70bccea4 AM |
4955 | /* Relocations that always need to be propagated if this is a shared |
4956 | object. */ | |
7619e7c7 AM |
4957 | case R_PPC_ADDR32: |
4958 | case R_PPC_ADDR24: | |
4959 | case R_PPC_ADDR16: | |
4960 | case R_PPC_ADDR16_LO: | |
4961 | case R_PPC_ADDR16_HI: | |
4962 | case R_PPC_ADDR16_HA: | |
4963 | case R_PPC_ADDR14: | |
4964 | case R_PPC_ADDR14_BRTAKEN: | |
4965 | case R_PPC_ADDR14_BRNTAKEN: | |
4966 | case R_PPC_UADDR32: | |
4967 | case R_PPC_UADDR16: | |
ee05f2fe AM |
4968 | /* r_symndx will be zero only for relocs against symbols |
4969 | from removed linkonce sections, or sections discarded by | |
4970 | a linker script. */ | |
7619e7c7 | 4971 | dodyn: |
ee05f2fe AM |
4972 | if (r_symndx == 0) |
4973 | break; | |
4974 | /* Fall thru. */ | |
4975 | ||
4976 | if ((info->shared | |
4977 | && (MUST_BE_DYN_RELOC (r_type) | |
4978 | || (h != NULL | |
4979 | && h->dynindx != -1 | |
4980 | && (!info->symbolic | |
4981 | || (h->elf_link_hash_flags | |
4982 | & ELF_LINK_HASH_DEF_REGULAR) == 0)))) | |
4983 | || (ELIMINATE_COPY_RELOCS | |
4984 | && !info->shared | |
4985 | && (input_section->flags & SEC_ALLOC) != 0 | |
4986 | && h != NULL | |
4987 | && h->dynindx != -1 | |
4988 | && (h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0 | |
4989 | && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0 | |
4990 | && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)) | |
252b5132 | 4991 | { |
0bb2d96a | 4992 | int skip; |
252b5132 RH |
4993 | |
4994 | #ifdef DEBUG | |
4995 | fprintf (stderr, "ppc_elf_relocate_section need to create relocation for %s\n", | |
70bccea4 AM |
4996 | (h && h->root.root.string |
4997 | ? h->root.root.string : "<unknown>")); | |
252b5132 RH |
4998 | #endif |
4999 | ||
5000 | /* When generating a shared object, these relocations | |
70bccea4 AM |
5001 | are copied into the output file to be resolved at run |
5002 | time. */ | |
252b5132 RH |
5003 | if (sreloc == NULL) |
5004 | { | |
5005 | const char *name; | |
5006 | ||
5007 | name = (bfd_elf_string_from_elf_section | |
5008 | (input_bfd, | |
5009 | elf_elfheader (input_bfd)->e_shstrndx, | |
5010 | elf_section_data (input_section)->rel_hdr.sh_name)); | |
5011 | if (name == NULL) | |
b34976b6 | 5012 | return FALSE; |
252b5132 RH |
5013 | |
5014 | BFD_ASSERT (strncmp (name, ".rela", 5) == 0 | |
5015 | && strcmp (bfd_get_section_name (input_bfd, | |
5016 | input_section), | |
5017 | name + 5) == 0); | |
5018 | ||
7619e7c7 | 5019 | sreloc = bfd_get_section_by_name (htab->elf.dynobj, name); |
252b5132 RH |
5020 | BFD_ASSERT (sreloc != NULL); |
5021 | } | |
5022 | ||
0bb2d96a | 5023 | skip = 0; |
252b5132 | 5024 | |
c629eae0 JJ |
5025 | outrel.r_offset = |
5026 | _bfd_elf_section_offset (output_bfd, info, input_section, | |
5027 | rel->r_offset); | |
0bb2d96a JJ |
5028 | if (outrel.r_offset == (bfd_vma) -1 |
5029 | || outrel.r_offset == (bfd_vma) -2) | |
5030 | skip = (int) outrel.r_offset; | |
252b5132 RH |
5031 | outrel.r_offset += (input_section->output_section->vma |
5032 | + input_section->output_offset); | |
5033 | ||
5034 | if (skip) | |
5035 | memset (&outrel, 0, sizeof outrel); | |
ee05f2fe AM |
5036 | else if (h != NULL |
5037 | && !SYMBOL_REFERENCES_LOCAL (info, h)) | |
252b5132 | 5038 | { |
7619e7c7 | 5039 | unresolved_reloc = FALSE; |
252b5132 RH |
5040 | outrel.r_info = ELF32_R_INFO (h->dynindx, r_type); |
5041 | outrel.r_addend = rel->r_addend; | |
5042 | } | |
5043 | else | |
5044 | { | |
47388f4c AM |
5045 | outrel.r_addend = relocation + rel->r_addend; |
5046 | ||
252b5132 | 5047 | if (r_type == R_PPC_ADDR32) |
47388f4c | 5048 | outrel.r_info = ELF32_R_INFO (0, R_PPC_RELATIVE); |
252b5132 RH |
5049 | else |
5050 | { | |
5051 | long indx; | |
5052 | ||
47388f4c | 5053 | if (bfd_is_abs_section (sec)) |
252b5132 RH |
5054 | indx = 0; |
5055 | else if (sec == NULL || sec->owner == NULL) | |
5056 | { | |
5057 | bfd_set_error (bfd_error_bad_value); | |
b34976b6 | 5058 | return FALSE; |
252b5132 RH |
5059 | } |
5060 | else | |
5061 | { | |
5062 | asection *osec; | |
5063 | ||
47388f4c AM |
5064 | /* We are turning this relocation into one |
5065 | against a section symbol. It would be | |
5066 | proper to subtract the symbol's value, | |
5067 | osec->vma, from the emitted reloc addend, | |
5068 | but ld.so expects buggy relocs. */ | |
252b5132 RH |
5069 | osec = sec->output_section; |
5070 | indx = elf_section_data (osec)->dynindx; | |
8da6118f | 5071 | BFD_ASSERT (indx > 0); |
252b5132 RH |
5072 | #ifdef DEBUG |
5073 | if (indx <= 0) | |
5074 | { | |
c3668558 | 5075 | printf ("indx=%d section=%s flags=%08x name=%s\n", |
70bccea4 AM |
5076 | indx, osec->name, osec->flags, |
5077 | h->root.root.string); | |
252b5132 RH |
5078 | } |
5079 | #endif | |
5080 | } | |
5081 | ||
5082 | outrel.r_info = ELF32_R_INFO (indx, r_type); | |
252b5132 RH |
5083 | } |
5084 | } | |
5085 | ||
947216bf AM |
5086 | loc = sreloc->contents; |
5087 | loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rela); | |
5088 | bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc); | |
252b5132 | 5089 | |
2243deae | 5090 | if (skip == -1) |
252b5132 | 5091 | continue; |
2243deae L |
5092 | |
5093 | /* This reloc will be computed at runtime. We clear the memory | |
5094 | so that it contains predictable value. */ | |
5095 | if (! skip | |
5096 | && ((input_section->flags & SEC_ALLOC) != 0 | |
5097 | || ELF32_R_TYPE (outrel.r_info) != R_PPC_RELATIVE)) | |
5098 | { | |
5099 | relocation = howto->pc_relative ? outrel.r_offset : 0; | |
5100 | addend = 0; | |
5101 | break; | |
5102 | } | |
252b5132 | 5103 | } |
252b5132 RH |
5104 | break; |
5105 | ||
70bccea4 | 5106 | /* Indirect .sdata relocation. */ |
7619e7c7 AM |
5107 | case R_PPC_EMB_SDAI16: |
5108 | BFD_ASSERT (htab->sdata != NULL); | |
5109 | relocation | |
5110 | = bfd_elf32_finish_pointer_linker_section (output_bfd, input_bfd, | |
5111 | info, htab->sdata, h, | |
5112 | relocation, rel, | |
5113 | R_PPC_RELATIVE); | |
252b5132 RH |
5114 | break; |
5115 | ||
70bccea4 | 5116 | /* Indirect .sdata2 relocation. */ |
7619e7c7 AM |
5117 | case R_PPC_EMB_SDA2I16: |
5118 | BFD_ASSERT (htab->sdata2 != NULL); | |
5119 | relocation | |
5120 | = bfd_elf32_finish_pointer_linker_section (output_bfd, input_bfd, | |
5121 | info, htab->sdata2, h, | |
5122 | relocation, rel, | |
5123 | R_PPC_RELATIVE); | |
252b5132 RH |
5124 | break; |
5125 | ||
70bccea4 AM |
5126 | /* Handle the TOC16 reloc. We want to use the offset within the .got |
5127 | section, not the actual VMA. This is appropriate when generating | |
5128 | an embedded ELF object, for which the .got section acts like the | |
5129 | AIX .toc section. */ | |
7619e7c7 | 5130 | case R_PPC_TOC16: /* phony GOT16 relocations */ |
8da6118f | 5131 | BFD_ASSERT (sec != (asection *) 0); |
252b5132 RH |
5132 | BFD_ASSERT (bfd_is_und_section (sec) |
5133 | || strcmp (bfd_get_section_name (abfd, sec), ".got") == 0 | |
5134 | || strcmp (bfd_get_section_name (abfd, sec), ".cgot") == 0) | |
5135 | ||
70bccea4 | 5136 | addend -= sec->output_section->vma + sec->output_offset + 0x8000; |
252b5132 RH |
5137 | break; |
5138 | ||
7619e7c7 | 5139 | case R_PPC_PLTREL24: |
252b5132 | 5140 | /* Relocation is to the entry for this symbol in the |
70bccea4 | 5141 | procedure linkage table. */ |
252b5132 RH |
5142 | BFD_ASSERT (h != NULL); |
5143 | ||
5144 | if (h->plt.offset == (bfd_vma) -1 | |
7619e7c7 | 5145 | || htab->plt == NULL) |
252b5132 RH |
5146 | { |
5147 | /* We didn't make a PLT entry for this symbol. This | |
70bccea4 AM |
5148 | happens when statically linking PIC code, or when |
5149 | using -Bsymbolic. */ | |
252b5132 RH |
5150 | break; |
5151 | } | |
5152 | ||
7619e7c7 AM |
5153 | unresolved_reloc = FALSE; |
5154 | relocation = (htab->plt->output_section->vma | |
5155 | + htab->plt->output_offset | |
252b5132 | 5156 | + h->plt.offset); |
8da6118f | 5157 | break; |
252b5132 | 5158 | |
70bccea4 | 5159 | /* Relocate against _SDA_BASE_. */ |
7619e7c7 | 5160 | case R_PPC_SDAREL16: |
252b5132 RH |
5161 | { |
5162 | const char *name; | |
7619e7c7 | 5163 | const struct elf_link_hash_entry *sh; |
252b5132 | 5164 | |
8da6118f | 5165 | BFD_ASSERT (sec != (asection *) 0); |
252b5132 | 5166 | name = bfd_get_section_name (abfd, sec->output_section); |
5f819128 AM |
5167 | if (! ((strncmp (name, ".sdata", 6) == 0 |
5168 | && (name[6] == 0 || name[6] == '.')) | |
5169 | || (strncmp (name, ".sbss", 5) == 0 | |
5170 | && (name[5] == 0 || name[5] == '.')))) | |
252b5132 | 5171 | { |
7b609f53 | 5172 | (*_bfd_error_handler) (_("%s: the target (%s) of a %s relocation is in the wrong output section (%s)"), |
8f615d07 | 5173 | bfd_archive_filename (input_bfd), |
252b5132 | 5174 | sym_name, |
7619e7c7 | 5175 | howto->name, |
252b5132 RH |
5176 | name); |
5177 | } | |
7619e7c7 AM |
5178 | sh = htab->sdata->sym_hash; |
5179 | addend -= (sh->root.u.def.value | |
5180 | + sh->root.u.def.section->output_section->vma | |
5181 | + sh->root.u.def.section->output_offset); | |
252b5132 RH |
5182 | } |
5183 | break; | |
5184 | ||
70bccea4 | 5185 | /* Relocate against _SDA2_BASE_. */ |
7619e7c7 | 5186 | case R_PPC_EMB_SDA2REL: |
252b5132 RH |
5187 | { |
5188 | const char *name; | |
7619e7c7 | 5189 | const struct elf_link_hash_entry *sh; |
252b5132 | 5190 | |
8da6118f | 5191 | BFD_ASSERT (sec != (asection *) 0); |
252b5132 | 5192 | name = bfd_get_section_name (abfd, sec->output_section); |
5f819128 AM |
5193 | if (! (strncmp (name, ".sdata2", 7) == 0 |
5194 | || strncmp (name, ".sbss2", 6) == 0)) | |
252b5132 | 5195 | { |
7b609f53 | 5196 | (*_bfd_error_handler) (_("%s: the target (%s) of a %s relocation is in the wrong output section (%s)"), |
8f615d07 | 5197 | bfd_archive_filename (input_bfd), |
252b5132 | 5198 | sym_name, |
7619e7c7 | 5199 | howto->name, |
252b5132 | 5200 | name); |
c3668558 | 5201 | |
252b5132 | 5202 | bfd_set_error (bfd_error_bad_value); |
b34976b6 | 5203 | ret = FALSE; |
252b5132 RH |
5204 | continue; |
5205 | } | |
7619e7c7 AM |
5206 | sh = htab->sdata2->sym_hash; |
5207 | addend -= (sh->root.u.def.value | |
5208 | + sh->root.u.def.section->output_section->vma | |
5209 | + sh->root.u.def.section->output_offset); | |
252b5132 RH |
5210 | } |
5211 | break; | |
5212 | ||
70bccea4 | 5213 | /* Relocate against either _SDA_BASE_, _SDA2_BASE_, or 0. */ |
7619e7c7 AM |
5214 | case R_PPC_EMB_SDA21: |
5215 | case R_PPC_EMB_RELSDA: | |
252b5132 RH |
5216 | { |
5217 | const char *name; | |
7619e7c7 | 5218 | const struct elf_link_hash_entry *sh; |
252b5132 RH |
5219 | int reg; |
5220 | ||
8da6118f | 5221 | BFD_ASSERT (sec != (asection *) 0); |
252b5132 | 5222 | name = bfd_get_section_name (abfd, sec->output_section); |
b34976b6 | 5223 | if (((strncmp (name, ".sdata", 6) == 0 |
5f819128 AM |
5224 | && (name[6] == 0 || name[6] == '.')) |
5225 | || (strncmp (name, ".sbss", 5) == 0 | |
5226 | && (name[5] == 0 || name[5] == '.')))) | |
252b5132 RH |
5227 | { |
5228 | reg = 13; | |
7619e7c7 AM |
5229 | sh = htab->sdata->sym_hash; |
5230 | addend -= (sh->root.u.def.value | |
5231 | + sh->root.u.def.section->output_section->vma | |
5232 | + sh->root.u.def.section->output_offset); | |
252b5132 RH |
5233 | } |
5234 | ||
5f819128 AM |
5235 | else if (strncmp (name, ".sdata2", 7) == 0 |
5236 | || strncmp (name, ".sbss2", 6) == 0) | |
252b5132 RH |
5237 | { |
5238 | reg = 2; | |
7619e7c7 AM |
5239 | sh = htab->sdata2->sym_hash; |
5240 | addend -= (sh->root.u.def.value | |
5241 | + sh->root.u.def.section->output_section->vma | |
5242 | + sh->root.u.def.section->output_offset); | |
252b5132 RH |
5243 | } |
5244 | ||
8da6118f KH |
5245 | else if (strcmp (name, ".PPC.EMB.sdata0") == 0 |
5246 | || strcmp (name, ".PPC.EMB.sbss0") == 0) | |
252b5132 RH |
5247 | { |
5248 | reg = 0; | |
5249 | } | |
5250 | ||
5251 | else | |
5252 | { | |
7b609f53 | 5253 | (*_bfd_error_handler) (_("%s: the target (%s) of a %s relocation is in the wrong output section (%s)"), |
8f615d07 | 5254 | bfd_archive_filename (input_bfd), |
252b5132 | 5255 | sym_name, |
7619e7c7 | 5256 | howto->name, |
252b5132 RH |
5257 | name); |
5258 | ||
5259 | bfd_set_error (bfd_error_bad_value); | |
b34976b6 | 5260 | ret = FALSE; |
252b5132 RH |
5261 | continue; |
5262 | } | |
5263 | ||
5264 | if (r_type == R_PPC_EMB_SDA21) | |
5265 | { /* fill in register field */ | |
7619e7c7 | 5266 | insn = bfd_get_32 (output_bfd, contents + rel->r_offset); |
252b5132 | 5267 | insn = (insn & ~RA_REGISTER_MASK) | (reg << RA_REGISTER_SHIFT); |
7619e7c7 | 5268 | bfd_put_32 (output_bfd, insn, contents + rel->r_offset); |
252b5132 RH |
5269 | } |
5270 | } | |
5271 | break; | |
5272 | ||
70bccea4 | 5273 | /* Relocate against the beginning of the section. */ |
7619e7c7 AM |
5274 | case R_PPC_SECTOFF: |
5275 | case R_PPC_SECTOFF_LO: | |
5276 | case R_PPC_SECTOFF_HI: | |
5277 | case R_PPC_SECTOFF_HA: | |
8da6118f | 5278 | BFD_ASSERT (sec != (asection *) 0); |
252b5132 | 5279 | addend -= sec->output_section->vma; |
252b5132 RH |
5280 | break; |
5281 | ||
70bccea4 | 5282 | /* Negative relocations. */ |
7619e7c7 AM |
5283 | case R_PPC_EMB_NADDR32: |
5284 | case R_PPC_EMB_NADDR16: | |
5285 | case R_PPC_EMB_NADDR16_LO: | |
5286 | case R_PPC_EMB_NADDR16_HI: | |
5287 | case R_PPC_EMB_NADDR16_HA: | |
8da6118f | 5288 | addend -= 2 * relocation; |
252b5132 RH |
5289 | break; |
5290 | ||
7619e7c7 AM |
5291 | case R_PPC_COPY: |
5292 | case R_PPC_GLOB_DAT: | |
5293 | case R_PPC_JMP_SLOT: | |
5294 | case R_PPC_RELATIVE: | |
5295 | case R_PPC_PLT32: | |
5296 | case R_PPC_PLTREL32: | |
5297 | case R_PPC_PLT16_LO: | |
5298 | case R_PPC_PLT16_HI: | |
5299 | case R_PPC_PLT16_HA: | |
5300 | case R_PPC_ADDR30: | |
5301 | case R_PPC_EMB_RELSEC16: | |
5302 | case R_PPC_EMB_RELST_LO: | |
5303 | case R_PPC_EMB_RELST_HI: | |
5304 | case R_PPC_EMB_RELST_HA: | |
5305 | case R_PPC_EMB_BIT_FLD: | |
5306 | (*_bfd_error_handler) | |
7b609f53 | 5307 | (_("%s: relocation %s is not yet supported for symbol %s."), |
7619e7c7 AM |
5308 | bfd_archive_filename (input_bfd), |
5309 | howto->name, | |
5310 | sym_name); | |
252b5132 RH |
5311 | |
5312 | bfd_set_error (bfd_error_invalid_operation); | |
b34976b6 | 5313 | ret = FALSE; |
252b5132 | 5314 | continue; |
7619e7c7 | 5315 | } |
252b5132 | 5316 | |
7619e7c7 AM |
5317 | /* Do any further special processing. */ |
5318 | switch (r_type) | |
5319 | { | |
5320 | default: | |
5321 | break; | |
5322 | ||
5323 | case R_PPC_ADDR16_HA: | |
5324 | case R_PPC_GOT16_HA: | |
5325 | case R_PPC_PLT16_HA: | |
5326 | case R_PPC_SECTOFF_HA: | |
5327 | case R_PPC_TPREL16_HA: | |
5328 | case R_PPC_DTPREL16_HA: | |
5329 | case R_PPC_GOT_TLSGD16_HA: | |
5330 | case R_PPC_GOT_TLSLD16_HA: | |
5331 | case R_PPC_GOT_TPREL16_HA: | |
5332 | case R_PPC_GOT_DTPREL16_HA: | |
5333 | case R_PPC_EMB_NADDR16_HA: | |
5334 | case R_PPC_EMB_RELST_HA: | |
5335 | /* It's just possible that this symbol is a weak symbol | |
7b609f53 | 5336 | that's not actually defined anywhere. In that case, |
7619e7c7 AM |
5337 | 'sec' would be NULL, and we should leave the symbol |
5338 | alone (it will be set to zero elsewhere in the link). */ | |
5339 | if (sec != NULL) | |
e515b051 AM |
5340 | /* Add 0x10000 if sign bit in 0:15 is set. |
5341 | Bits 0:15 are not used. */ | |
5342 | addend += 0x8000; | |
7619e7c7 | 5343 | break; |
252b5132 RH |
5344 | } |
5345 | ||
252b5132 RH |
5346 | #ifdef DEBUG |
5347 | fprintf (stderr, "\ttype = %s (%d), name = %s, symbol index = %ld, offset = %ld, addend = %ld\n", | |
5348 | howto->name, | |
8da6118f | 5349 | (int) r_type, |
252b5132 RH |
5350 | sym_name, |
5351 | r_symndx, | |
7619e7c7 | 5352 | (long) rel->r_offset, |
8da6118f | 5353 | (long) addend); |
252b5132 RH |
5354 | #endif |
5355 | ||
7619e7c7 AM |
5356 | if (unresolved_reloc |
5357 | && !((input_section->flags & SEC_DEBUGGING) != 0 | |
5358 | && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0)) | |
5359 | { | |
5360 | (*_bfd_error_handler) | |
7b609f53 | 5361 | (_("%s(%s+0x%lx): unresolvable %s relocation against symbol `%s'"), |
7619e7c7 AM |
5362 | bfd_archive_filename (input_bfd), |
5363 | bfd_get_section_name (input_bfd, input_section), | |
5364 | (long) rel->r_offset, | |
7b609f53 | 5365 | howto->name, |
7619e7c7 AM |
5366 | sym_name); |
5367 | ret = FALSE; | |
5368 | } | |
5369 | ||
252b5132 RH |
5370 | r = _bfd_final_link_relocate (howto, |
5371 | input_bfd, | |
5372 | input_section, | |
5373 | contents, | |
7619e7c7 | 5374 | rel->r_offset, |
252b5132 RH |
5375 | relocation, |
5376 | addend); | |
5377 | ||
7619e7c7 | 5378 | if (r != bfd_reloc_ok) |
252b5132 | 5379 | { |
7619e7c7 AM |
5380 | if (sym_name == NULL) |
5381 | sym_name = "(null)"; | |
5382 | if (r == bfd_reloc_overflow) | |
252b5132 | 5383 | { |
7619e7c7 AM |
5384 | if (warned) |
5385 | continue; | |
5386 | if (h != NULL | |
5387 | && h->root.type == bfd_link_hash_undefweak | |
dc1bc0c9 RH |
5388 | && howto->pc_relative) |
5389 | { | |
5390 | /* Assume this is a call protected by other code that | |
5391 | detect the symbol is undefined. If this is the case, | |
5392 | we can safely ignore the overflow. If not, the | |
5393 | program is hosed anyway, and a little warning isn't | |
5394 | going to help. */ | |
252b5132 | 5395 | |
dc1bc0c9 RH |
5396 | continue; |
5397 | } | |
252b5132 | 5398 | |
7619e7c7 AM |
5399 | if (! (*info->callbacks->reloc_overflow) (info, |
5400 | sym_name, | |
5401 | howto->name, | |
5402 | rel->r_addend, | |
5403 | input_bfd, | |
5404 | input_section, | |
5405 | rel->r_offset)) | |
5406 | return FALSE; | |
dc1bc0c9 RH |
5407 | } |
5408 | else | |
5409 | { | |
7619e7c7 | 5410 | (*_bfd_error_handler) |
7b609f53 | 5411 | (_("%s(%s+0x%lx): %s reloc against `%s': error %d"), |
7619e7c7 AM |
5412 | bfd_archive_filename (input_bfd), |
5413 | bfd_get_section_name (input_bfd, input_section), | |
7b609f53 | 5414 | (long) rel->r_offset, howto->name, sym_name, (int) r); |
7619e7c7 | 5415 | ret = FALSE; |
252b5132 RH |
5416 | } |
5417 | } | |
5418 | } | |
5419 | ||
252b5132 RH |
5420 | #ifdef DEBUG |
5421 | fprintf (stderr, "\n"); | |
5422 | #endif | |
5423 | ||
5424 | return ret; | |
5425 | } | |
29c2fb7c AJ |
5426 | |
5427 | static enum elf_reloc_type_class | |
f51e552e AM |
5428 | ppc_elf_reloc_type_class (rela) |
5429 | const Elf_Internal_Rela *rela; | |
29c2fb7c | 5430 | { |
f51e552e | 5431 | switch ((int) ELF32_R_TYPE (rela->r_info)) |
29c2fb7c AJ |
5432 | { |
5433 | case R_PPC_RELATIVE: | |
5434 | return reloc_class_relative; | |
5435 | case R_PPC_REL24: | |
5436 | case R_PPC_ADDR24: | |
5437 | case R_PPC_JMP_SLOT: | |
5438 | return reloc_class_plt; | |
5439 | case R_PPC_COPY: | |
5440 | return reloc_class_copy; | |
5441 | default: | |
5442 | return reloc_class_normal; | |
5443 | } | |
5444 | } | |
252b5132 | 5445 | \f |
ae9a127f NC |
5446 | /* Support for core dump NOTE sections. */ |
5447 | ||
b34976b6 | 5448 | static bfd_boolean |
c5fccbec DJ |
5449 | ppc_elf_grok_prstatus (abfd, note) |
5450 | bfd *abfd; | |
5451 | Elf_Internal_Note *note; | |
5452 | { | |
5453 | int offset; | |
dc810e39 | 5454 | unsigned int raw_size; |
c5fccbec DJ |
5455 | |
5456 | switch (note->descsz) | |
5457 | { | |
70bccea4 AM |
5458 | default: |
5459 | return FALSE; | |
c5fccbec | 5460 | |
70bccea4 AM |
5461 | case 268: /* Linux/PPC. */ |
5462 | /* pr_cursig */ | |
5463 | elf_tdata (abfd)->core_signal = bfd_get_16 (abfd, note->descdata + 12); | |
c5fccbec | 5464 | |
70bccea4 AM |
5465 | /* pr_pid */ |
5466 | elf_tdata (abfd)->core_pid = bfd_get_32 (abfd, note->descdata + 24); | |
c5fccbec | 5467 | |
70bccea4 AM |
5468 | /* pr_reg */ |
5469 | offset = 72; | |
5470 | raw_size = 192; | |
c5fccbec | 5471 | |
70bccea4 | 5472 | break; |
c5fccbec DJ |
5473 | } |
5474 | ||
5475 | /* Make a ".reg/999" section. */ | |
5476 | return _bfd_elfcore_make_pseudosection (abfd, ".reg", | |
5477 | raw_size, note->descpos + offset); | |
5478 | } | |
5479 | ||
b34976b6 | 5480 | static bfd_boolean |
c5fccbec DJ |
5481 | ppc_elf_grok_psinfo (abfd, note) |
5482 | bfd *abfd; | |
5483 | Elf_Internal_Note *note; | |
5484 | { | |
5485 | switch (note->descsz) | |
5486 | { | |
70bccea4 AM |
5487 | default: |
5488 | return FALSE; | |
c5fccbec | 5489 | |
70bccea4 AM |
5490 | case 128: /* Linux/PPC elf_prpsinfo. */ |
5491 | elf_tdata (abfd)->core_program | |
5492 | = _bfd_elfcore_strndup (abfd, note->descdata + 32, 16); | |
5493 | elf_tdata (abfd)->core_command | |
5494 | = _bfd_elfcore_strndup (abfd, note->descdata + 48, 80); | |
c5fccbec DJ |
5495 | } |
5496 | ||
5497 | /* Note that for some reason, a spurious space is tacked | |
5498 | onto the end of the args in some (at least one anyway) | |
5499 | implementations, so strip it off if it exists. */ | |
5500 | ||
5501 | { | |
5502 | char *command = elf_tdata (abfd)->core_command; | |
5503 | int n = strlen (command); | |
5504 | ||
5505 | if (0 < n && command[n - 1] == ' ') | |
5506 | command[n - 1] = '\0'; | |
5507 | } | |
5508 | ||
b34976b6 | 5509 | return TRUE; |
c5fccbec DJ |
5510 | } |
5511 | \f | |
e1a9cb8e NC |
5512 | /* Very simple linked list structure for recording apuinfo values. */ |
5513 | typedef struct apuinfo_list | |
5514 | { | |
70bccea4 AM |
5515 | struct apuinfo_list *next; |
5516 | unsigned long value; | |
e1a9cb8e NC |
5517 | } |
5518 | apuinfo_list; | |
5519 | ||
5520 | static apuinfo_list * head; | |
5521 | ||
70bccea4 AM |
5522 | static void apuinfo_list_init PARAMS ((void)); |
5523 | static void apuinfo_list_add PARAMS ((unsigned long)); | |
5524 | static unsigned apuinfo_list_length PARAMS ((void)); | |
e1a9cb8e | 5525 | static unsigned long apuinfo_list_element PARAMS ((unsigned long)); |
70bccea4 | 5526 | static void apuinfo_list_finish PARAMS ((void)); |
e1a9cb8e | 5527 | |
70bccea4 | 5528 | extern void ppc_elf_begin_write_processing |
e1a9cb8e | 5529 | PARAMS ((bfd *, struct bfd_link_info *)); |
70bccea4 | 5530 | extern void ppc_elf_final_write_processing |
e1a9cb8e | 5531 | PARAMS ((bfd *, bfd_boolean)); |
70bccea4 | 5532 | extern bfd_boolean ppc_elf_write_section |
e1a9cb8e NC |
5533 | PARAMS ((bfd *, asection *, bfd_byte *)); |
5534 | ||
5535 | ||
e1a9cb8e NC |
5536 | static void |
5537 | apuinfo_list_init PARAMS ((void)) | |
5538 | { | |
5539 | head = NULL; | |
5540 | } | |
5541 | ||
5542 | static void | |
5543 | apuinfo_list_add (value) | |
5544 | unsigned long value; | |
5545 | { | |
70bccea4 | 5546 | apuinfo_list *entry = head; |
e1a9cb8e NC |
5547 | |
5548 | while (entry != NULL) | |
5549 | { | |
5550 | if (entry->value == value) | |
5551 | return; | |
5552 | entry = entry->next; | |
5553 | } | |
5554 | ||
5555 | entry = bfd_malloc (sizeof (* entry)); | |
5556 | if (entry == NULL) | |
5557 | return; | |
5558 | ||
5559 | entry->value = value; | |
5560 | entry->next = head; | |
5561 | head = entry; | |
5562 | } | |
5563 | ||
5564 | static unsigned | |
5565 | apuinfo_list_length PARAMS ((void)) | |
5566 | { | |
70bccea4 | 5567 | apuinfo_list *entry; |
e1a9cb8e NC |
5568 | unsigned long count; |
5569 | ||
5570 | for (entry = head, count = 0; | |
5571 | entry; | |
5572 | entry = entry->next) | |
5573 | ++ count; | |
5574 | ||
5575 | return count; | |
5576 | } | |
5577 | ||
5578 | static inline unsigned long | |
5579 | apuinfo_list_element (number) | |
5580 | unsigned long number; | |
5581 | { | |
5582 | apuinfo_list * entry; | |
5583 | ||
5584 | for (entry = head; | |
5585 | entry && number --; | |
5586 | entry = entry->next) | |
5587 | ; | |
5588 | ||
5589 | return entry ? entry->value : 0; | |
5590 | } | |
5591 | ||
5592 | static void | |
5593 | apuinfo_list_finish PARAMS ((void)) | |
5594 | { | |
70bccea4 | 5595 | apuinfo_list *entry; |
e1a9cb8e NC |
5596 | |
5597 | for (entry = head; entry;) | |
5598 | { | |
70bccea4 | 5599 | apuinfo_list *next = entry->next; |
e1a9cb8e NC |
5600 | free (entry); |
5601 | entry = next; | |
5602 | } | |
5603 | ||
5604 | head = NULL; | |
5605 | } | |
5606 | ||
70bccea4 AM |
5607 | #define APUINFO_SECTION_NAME ".PPC.EMB.apuinfo" |
5608 | #define APUINFO_LABEL "APUinfo" | |
e1a9cb8e NC |
5609 | |
5610 | /* Scan the input BFDs and create a linked list of | |
5611 | the APUinfo values that will need to be emitted. */ | |
5612 | ||
5613 | void | |
5614 | ppc_elf_begin_write_processing (abfd, link_info) | |
5615 | bfd *abfd; | |
5616 | struct bfd_link_info *link_info; | |
5617 | { | |
70bccea4 AM |
5618 | bfd *ibfd; |
5619 | asection *asec; | |
5620 | char *buffer; | |
5621 | unsigned num_input_sections; | |
e1a9cb8e | 5622 | bfd_size_type output_section_size; |
70bccea4 AM |
5623 | unsigned i; |
5624 | unsigned num_entries; | |
e1a9cb8e NC |
5625 | unsigned long offset; |
5626 | unsigned long length; | |
70bccea4 | 5627 | const char *error_message = NULL; |
e1a9cb8e | 5628 | |
6b0817e5 NC |
5629 | if (link_info == NULL) |
5630 | return; | |
5631 | ||
e1a9cb8e NC |
5632 | /* Scan the input bfds, looking for apuinfo sections. */ |
5633 | num_input_sections = 0; | |
5634 | output_section_size = 0; | |
5635 | ||
5636 | for (ibfd = link_info->input_bfds; ibfd; ibfd = ibfd->link_next) | |
5637 | { | |
5638 | asec = bfd_get_section_by_name (ibfd, APUINFO_SECTION_NAME); | |
5639 | if (asec) | |
5640 | { | |
5641 | ++ num_input_sections; | |
5642 | output_section_size += asec->_raw_size; | |
5643 | } | |
5644 | } | |
5645 | ||
5646 | /* We need at least one input sections | |
5647 | in order to make merging worthwhile. */ | |
5648 | if (num_input_sections < 1) | |
5649 | return; | |
5650 | ||
5651 | /* Just make sure that the output section exists as well. */ | |
5652 | asec = bfd_get_section_by_name (abfd, APUINFO_SECTION_NAME); | |
5653 | if (asec == NULL) | |
5654 | return; | |
5655 | ||
5656 | /* Allocate a buffer for the contents of the input sections. */ | |
5657 | buffer = bfd_malloc (output_section_size); | |
5658 | if (buffer == NULL) | |
5659 | return; | |
5660 | ||
5661 | offset = 0; | |
5662 | apuinfo_list_init (); | |
5663 | ||
5664 | /* Read in the input sections contents. */ | |
5665 | for (ibfd = link_info->input_bfds; ibfd; ibfd = ibfd->link_next) | |
5666 | { | |
70bccea4 AM |
5667 | unsigned long datum; |
5668 | char *ptr; | |
86bbe32f | 5669 | |
e1a9cb8e NC |
5670 | asec = bfd_get_section_by_name (ibfd, APUINFO_SECTION_NAME); |
5671 | if (asec == NULL) | |
5672 | continue; | |
5673 | ||
5674 | length = asec->_raw_size; | |
5675 | if (length < 24) | |
5676 | { | |
5677 | error_message = _("corrupt or empty %s section in %s"); | |
5678 | goto fail; | |
5679 | } | |
86bbe32f | 5680 | |
e1a9cb8e NC |
5681 | if (bfd_seek (ibfd, asec->filepos, SEEK_SET) != 0 |
5682 | || (bfd_bread (buffer + offset, length, ibfd) != length)) | |
5683 | { | |
5684 | error_message = _("unable to read in %s section from %s"); | |
5685 | goto fail; | |
5686 | } | |
5687 | ||
5688 | /* Process the contents of the section. */ | |
5689 | ptr = buffer + offset; | |
5690 | error_message = _("corrupt %s section in %s"); | |
5691 | ||
5692 | /* Verify the contents of the header. Note - we have to | |
5693 | extract the values this way in order to allow for a | |
5694 | host whose endian-ness is different from the target. */ | |
5695 | datum = bfd_get_32 (ibfd, ptr); | |
5696 | if (datum != sizeof APUINFO_LABEL) | |
5697 | goto fail; | |
5698 | ||
5699 | datum = bfd_get_32 (ibfd, ptr + 8); | |
5700 | if (datum != 0x2) | |
5701 | goto fail; | |
5702 | ||
5703 | if (strcmp (ptr + 12, APUINFO_LABEL) != 0) | |
5704 | goto fail; | |
5705 | ||
5706 | /* Get the number of apuinfo entries. */ | |
5707 | datum = bfd_get_32 (ibfd, ptr + 4); | |
5708 | if ((datum * 4 + 20) != length) | |
5709 | goto fail; | |
5710 | ||
5711 | /* Make sure that we do not run off the end of the section. */ | |
5712 | if (offset + length > output_section_size) | |
5713 | goto fail; | |
5714 | ||
5715 | /* Scan the apuinfo section, building a list of apuinfo numbers. */ | |
5716 | for (i = 0; i < datum; i++) | |
5717 | apuinfo_list_add (bfd_get_32 (ibfd, ptr + 20 + (i * 4))); | |
5718 | ||
5719 | /* Update the offset. */ | |
5720 | offset += length; | |
5721 | } | |
5722 | ||
5723 | error_message = NULL; | |
5724 | ||
5725 | /* Compute the size of the output section. */ | |
5726 | num_entries = apuinfo_list_length (); | |
5727 | output_section_size = 20 + num_entries * 4; | |
5728 | ||
5729 | asec = bfd_get_section_by_name (abfd, APUINFO_SECTION_NAME); | |
5730 | ||
70bccea4 | 5731 | if (! bfd_set_section_size (abfd, asec, output_section_size)) |
e1a9cb8e NC |
5732 | ibfd = abfd, |
5733 | error_message = _("warning: unable to set size of %s section in %s"); | |
86bbe32f | 5734 | |
e1a9cb8e NC |
5735 | fail: |
5736 | free (buffer); | |
5737 | ||
5738 | if (error_message) | |
70bccea4 AM |
5739 | (*_bfd_error_handler) (error_message, APUINFO_SECTION_NAME, |
5740 | bfd_archive_filename (ibfd)); | |
e1a9cb8e NC |
5741 | } |
5742 | ||
5743 | ||
5744 | /* Prevent the output section from accumulating the input sections' | |
5745 | contents. We have already stored this in our linked list structure. */ | |
5746 | ||
5747 | bfd_boolean | |
5748 | ppc_elf_write_section (abfd, asec, contents) | |
70bccea4 AM |
5749 | bfd *abfd ATTRIBUTE_UNUSED; |
5750 | asection *asec; | |
5751 | bfd_byte *contents ATTRIBUTE_UNUSED; | |
e1a9cb8e | 5752 | { |
70bccea4 AM |
5753 | return (apuinfo_list_length () |
5754 | && strcmp (asec->name, APUINFO_SECTION_NAME) == 0); | |
e1a9cb8e NC |
5755 | } |
5756 | ||
5757 | ||
5758 | /* Finally we can generate the output section. */ | |
5759 | ||
5760 | void | |
5761 | ppc_elf_final_write_processing (abfd, linker) | |
70bccea4 | 5762 | bfd *abfd; |
e1a9cb8e NC |
5763 | bfd_boolean linker ATTRIBUTE_UNUSED; |
5764 | { | |
70bccea4 AM |
5765 | bfd_byte *buffer; |
5766 | asection *asec; | |
5767 | unsigned i; | |
5768 | unsigned num_entries; | |
e1a9cb8e NC |
5769 | bfd_size_type length; |
5770 | ||
5771 | asec = bfd_get_section_by_name (abfd, APUINFO_SECTION_NAME); | |
5772 | if (asec == NULL) | |
5773 | return; | |
5774 | ||
6b0817e5 NC |
5775 | if (apuinfo_list_length () == 0) |
5776 | return; | |
5777 | ||
e1a9cb8e NC |
5778 | length = asec->_raw_size; |
5779 | if (length < 20) | |
5780 | return; | |
5781 | ||
5782 | buffer = bfd_malloc (length); | |
5783 | if (buffer == NULL) | |
5784 | { | |
70bccea4 AM |
5785 | (*_bfd_error_handler) |
5786 | (_("failed to allocate space for new APUinfo section.")); | |
e1a9cb8e NC |
5787 | return; |
5788 | } | |
5789 | ||
5790 | /* Create the apuinfo header. */ | |
5791 | num_entries = apuinfo_list_length (); | |
5792 | bfd_put_32 (abfd, sizeof APUINFO_LABEL, buffer); | |
5793 | bfd_put_32 (abfd, num_entries, buffer + 4); | |
5794 | bfd_put_32 (abfd, 0x2, buffer + 8); | |
5795 | strcpy (buffer + 12, APUINFO_LABEL); | |
86bbe32f | 5796 | |
e1a9cb8e NC |
5797 | length = 20; |
5798 | for (i = 0; i < num_entries; i++) | |
5799 | { | |
5800 | bfd_put_32 (abfd, apuinfo_list_element (i), buffer + length); | |
5801 | length += 4; | |
5802 | } | |
5803 | ||
5804 | if (length != asec->_raw_size) | |
70bccea4 | 5805 | (*_bfd_error_handler) (_("failed to compute new APUinfo section.")); |
86bbe32f | 5806 | |
e1a9cb8e | 5807 | if (! bfd_set_section_contents (abfd, asec, buffer, (file_ptr) 0, length)) |
70bccea4 | 5808 | (*_bfd_error_handler) (_("failed to install new APUinfo section.")); |
86bbe32f | 5809 | |
e1a9cb8e NC |
5810 | free (buffer); |
5811 | ||
5812 | apuinfo_list_finish (); | |
5813 | } | |
5814 | \f | |
252b5132 RH |
5815 | #define TARGET_LITTLE_SYM bfd_elf32_powerpcle_vec |
5816 | #define TARGET_LITTLE_NAME "elf32-powerpcle" | |
5817 | #define TARGET_BIG_SYM bfd_elf32_powerpc_vec | |
5818 | #define TARGET_BIG_NAME "elf32-powerpc" | |
5819 | #define ELF_ARCH bfd_arch_powerpc | |
5820 | #define ELF_MACHINE_CODE EM_PPC | |
5821 | #define ELF_MAXPAGESIZE 0x10000 | |
5822 | #define elf_info_to_howto ppc_elf_info_to_howto | |
5823 | ||
5824 | #ifdef EM_CYGNUS_POWERPC | |
5825 | #define ELF_MACHINE_ALT1 EM_CYGNUS_POWERPC | |
5826 | #endif | |
5827 | ||
5828 | #ifdef EM_PPC_OLD | |
5829 | #define ELF_MACHINE_ALT2 EM_PPC_OLD | |
5830 | #endif | |
5831 | ||
5832 | #define elf_backend_plt_not_loaded 1 | |
5833 | #define elf_backend_got_symbol_offset 4 | |
5834 | #define elf_backend_can_gc_sections 1 | |
51b64d56 | 5835 | #define elf_backend_can_refcount 1 |
252b5132 RH |
5836 | #define elf_backend_got_header_size 12 |
5837 | #define elf_backend_plt_header_size PLT_INITIAL_ENTRY_SIZE | |
b491616a | 5838 | #define elf_backend_rela_normal 1 |
252b5132 | 5839 | |
252b5132 | 5840 | #define bfd_elf32_bfd_merge_private_bfd_data ppc_elf_merge_private_bfd_data |
70bccea4 | 5841 | #define bfd_elf32_bfd_relax_section ppc_elf_relax_section |
252b5132 RH |
5842 | #define bfd_elf32_bfd_reloc_type_lookup ppc_elf_reloc_type_lookup |
5843 | #define bfd_elf32_bfd_set_private_flags ppc_elf_set_private_flags | |
70bccea4 | 5844 | #define bfd_elf32_bfd_link_hash_table_create ppc_elf_link_hash_table_create |
252b5132 | 5845 | |
feee612b | 5846 | #define elf_backend_object_p ppc_elf_object_p |
252b5132 RH |
5847 | #define elf_backend_gc_mark_hook ppc_elf_gc_mark_hook |
5848 | #define elf_backend_gc_sweep_hook ppc_elf_gc_sweep_hook | |
5849 | #define elf_backend_section_from_shdr ppc_elf_section_from_shdr | |
5850 | #define elf_backend_relocate_section ppc_elf_relocate_section | |
5851 | #define elf_backend_create_dynamic_sections ppc_elf_create_dynamic_sections | |
5852 | #define elf_backend_check_relocs ppc_elf_check_relocs | |
7fce784e | 5853 | #define elf_backend_copy_indirect_symbol ppc_elf_copy_indirect_symbol |
252b5132 RH |
5854 | #define elf_backend_adjust_dynamic_symbol ppc_elf_adjust_dynamic_symbol |
5855 | #define elf_backend_add_symbol_hook ppc_elf_add_symbol_hook | |
5856 | #define elf_backend_size_dynamic_sections ppc_elf_size_dynamic_sections | |
5857 | #define elf_backend_finish_dynamic_symbol ppc_elf_finish_dynamic_symbol | |
5858 | #define elf_backend_finish_dynamic_sections ppc_elf_finish_dynamic_sections | |
5859 | #define elf_backend_fake_sections ppc_elf_fake_sections | |
5860 | #define elf_backend_additional_program_headers ppc_elf_additional_program_headers | |
5861 | #define elf_backend_modify_segment_map ppc_elf_modify_segment_map | |
c5fccbec DJ |
5862 | #define elf_backend_grok_prstatus ppc_elf_grok_prstatus |
5863 | #define elf_backend_grok_psinfo ppc_elf_grok_psinfo | |
29c2fb7c | 5864 | #define elf_backend_reloc_type_class ppc_elf_reloc_type_class |
70bccea4 AM |
5865 | #define elf_backend_begin_write_processing ppc_elf_begin_write_processing |
5866 | #define elf_backend_final_write_processing ppc_elf_final_write_processing | |
5867 | #define elf_backend_write_section ppc_elf_write_section | |
252b5132 RH |
5868 | |
5869 | #include "elf32-target.h" |