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