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