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