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