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