Support the use of the STT_COMMON type. (In source and object files only at the...
[deliverable/binutils-gdb.git] / bfd / elf32-ppc.c
index 09a59b486ae9fb0fdc3cf89baeb212bb162babbf..68804ad806c56b1063160638d122b79b103c10d5 100644 (file)
@@ -1,13 +1,13 @@
 /* PowerPC-specific support for 32-bit ELF
    Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
-   2004, 2005 Free Software Foundation, Inc.
+   2004, 2005, 2006, 2007 Free Software Foundation, Inc.
    Written by Ian Lance Taylor, Cygnus Support.
 
    This file is part of BFD, the Binary File Descriptor library.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
+   the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
 
    This program is distributed in the hope that it will be useful,
    Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
    Boston, MA 02110-1301, USA.  */
 
+
 /* This file is based on a preliminary PowerPC ELF ABI.  The
    information may not match the final PowerPC ELF ABI.  It includes
    suggestions from the in-progress Embedded PowerPC ABI, and that
    information may also not match.  */
 
-#include "bfd.h"
 #include "sysdep.h"
+#include <stdarg.h>
+#include "bfd.h"
 #include "bfdlink.h"
 #include "libbfd.h"
 #include "elf-bfd.h"
@@ -1577,6 +1579,22 @@ ppc_elf_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
   return ppc_elf_howto_table[r];
 };
 
+static reloc_howto_type *
+ppc_elf_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
+                          const char *r_name)
+{
+  unsigned int i;
+
+  for (i = 0;
+       i < sizeof (ppc_elf_howto_raw) / sizeof (ppc_elf_howto_raw[0]);
+       i++)
+    if (ppc_elf_howto_raw[i].name != NULL
+       && strcasecmp (ppc_elf_howto_raw[i].name, r_name) == 0)
+      return &ppc_elf_howto_raw[i];
+
+  return NULL;
+}
+
 /* Set the howto pointer for a PowerPC ELF reloc.  */
 
 static void
@@ -1590,6 +1608,17 @@ ppc_elf_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED,
 
   BFD_ASSERT (ELF32_R_TYPE (dst->r_info) < (unsigned int) R_PPC_max);
   cache_ptr->howto = ppc_elf_howto_table[ELF32_R_TYPE (dst->r_info)];
+
+  /* Just because the above assert didn't trigger doesn't mean that
+     ELF32_R_TYPE (dst->r_info) is necessarily a valid relocation.  */
+  if (!cache_ptr->howto)
+    {
+      (*_bfd_error_handler) (_("%B: invalid relocation type %d"),
+                             abfd, ELF32_R_TYPE (dst->r_info));
+      bfd_set_error (bfd_error_bad_value);
+
+      cache_ptr->howto = ppc_elf_howto_table[R_PPC_NONE];
+    }
 }
 
 /* Handle the R_PPC_ADDR16_HA and R_PPC_REL16_HA relocs.  */
@@ -1668,8 +1697,8 @@ typedef struct elf_linker_section
   const char *bss_name;
   /* Associated symbol name.  */
   const char *sym_name;
-  /* Value of symbol.  */
-  bfd_vma sym_val;
+  /* Associated symbol.  */
+  struct elf_link_hash_entry *sym;
 } elf_linker_section_t;
 
 /* Linked list of allocated pointer entries.  This hangs off of the
@@ -1695,6 +1724,10 @@ struct ppc_elf_obj_tdata
   /* A mapping from local symbols to offsets into the various linker
      sections added.  This is index by the symbol index.  */
   elf_linker_section_pointers_t **linker_section_pointers;
+
+  /* Flags used to auto-detect plt type.  */
+  unsigned int makes_plt_call : 1;
+  unsigned int has_rel16 : 1;
 };
 
 #define ppc_elf_tdata(bfd) \
@@ -1708,11 +1741,14 @@ struct ppc_elf_obj_tdata
 static bfd_boolean
 ppc_elf_mkobject (bfd *abfd)
 {
-  bfd_size_type amt = sizeof (struct ppc_elf_obj_tdata);
-  abfd->tdata.any = bfd_zalloc (abfd, amt);
   if (abfd->tdata.any == NULL)
-    return FALSE;
-  return TRUE;
+    {
+      bfd_size_type amt = sizeof (struct ppc_elf_obj_tdata);
+      abfd->tdata.any = bfd_zalloc (abfd, amt);
+      if (abfd->tdata.any == NULL)
+       return FALSE;
+    }
+  return bfd_elf_mkobject (abfd);
 }
 
 /* Fix bad default arch selected for a 32 bit input bfd when the
@@ -1810,6 +1846,52 @@ ppc_elf_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
   return TRUE;
 }
 
+static char *
+ppc_elf_write_core_note (bfd *abfd, char *buf, int *bufsiz, int note_type, ...)
+{
+  switch (note_type)
+    {
+    default:
+      return NULL;
+
+    case NT_PRPSINFO:
+      {
+       char data[128];
+       va_list ap;
+
+       va_start (ap, note_type);
+       memset (data, 0, 32);
+       strncpy (data + 32, va_arg (ap, const char *), 16);
+       strncpy (data + 48, va_arg (ap, const char *), 80);
+       va_end (ap);
+       return elfcore_write_note (abfd, buf, bufsiz,
+                                  "CORE", note_type, data, sizeof (data));
+      }
+
+    case NT_PRSTATUS:
+      {
+       char data[268];
+       va_list ap;
+       long pid;
+       int cursig;
+       const void *greg;
+
+       va_start (ap, note_type);
+       memset (data, 0, 72);
+       pid = va_arg (ap, long);
+       bfd_put_32 (abfd, pid, data + 24);
+       cursig = va_arg (ap, int);
+       bfd_put_16 (abfd, cursig, data + 12);
+       greg = va_arg (ap, const void *);
+       memcpy (data + 72, greg, 192);
+       memset (data + 264, 0, 4);
+       va_end (ap);
+       return elfcore_write_note (abfd, buf, bufsiz,
+                                  "CORE", note_type, data, sizeof (data));
+      }
+    }
+}
+
 /* Return address for Ith PLT stub in section PLT, for relocation REL
    or (bfd_vma) -1 if it should not be included.  */
 
@@ -1856,7 +1938,7 @@ ppc_elf_fake_sections (bfd *abfd ATTRIBUTE_UNUSED,
                       Elf_Internal_Shdr *shdr,
                       asection *asect)
 {
-  if ((asect->flags & SEC_EXCLUDE) != 0)
+  if ((asect->flags & (SEC_GROUP | SEC_EXCLUDE)) == SEC_EXCLUDE)
     shdr->sh_flags |= SHF_EXCLUDE;
 
   if ((asect->flags & SEC_SORT_ENTRIES) != 0)
@@ -1869,7 +1951,8 @@ ppc_elf_fake_sections (bfd *abfd ATTRIBUTE_UNUSED,
    need to bump up the number of section headers.  */
 
 static int
-ppc_elf_additional_program_headers (bfd *abfd)
+ppc_elf_additional_program_headers (bfd *abfd,
+                                   struct bfd_link_info *info ATTRIBUTE_UNUSED)
 {
   asection *s;
   int ret = 0;
@@ -1892,21 +1975,21 @@ ppc_elf_additional_program_headers (bfd *abfd)
 
 static const struct bfd_elf_special_section ppc_elf_special_sections[] =
 {
-  { ".plt",              4,  0, SHT_NOBITS,   SHF_ALLOC + SHF_EXECINSTR },
-  { ".sbss",             5, -2, SHT_NOBITS,   SHF_ALLOC + SHF_WRITE },
-  { ".sbss2",            6, -2, SHT_PROGBITS, SHF_ALLOC },
-  { ".sdata",            6, -2, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE },
-  { ".sdata2",           7, -2, SHT_PROGBITS, SHF_ALLOC },
-  { ".tags",             5,  0, SHT_ORDERED,  SHF_ALLOC },
-  { ".PPC.EMB.apuinfo", 16,  0, SHT_NOTE,     0 },
-  { ".PPC.EMB.sbss0",   14,  0, SHT_PROGBITS, SHF_ALLOC },
-  { ".PPC.EMB.sdata0",  15,  0, SHT_PROGBITS, SHF_ALLOC },
-  { NULL,                0,  0, 0,            0 }
+  { STRING_COMMA_LEN (".plt"),             0, SHT_NOBITS,   SHF_ALLOC + SHF_EXECINSTR },
+  { STRING_COMMA_LEN (".sbss"),           -2, SHT_NOBITS,   SHF_ALLOC + SHF_WRITE },
+  { STRING_COMMA_LEN (".sbss2"),          -2, SHT_PROGBITS, SHF_ALLOC },
+  { STRING_COMMA_LEN (".sdata"),          -2, SHT_PROGBITS, SHF_ALLOC + SHF_WRITE },
+  { STRING_COMMA_LEN (".sdata2"),         -2, SHT_PROGBITS, SHF_ALLOC },
+  { STRING_COMMA_LEN (".tags"),            0, SHT_ORDERED,  SHF_ALLOC },
+  { STRING_COMMA_LEN (".PPC.EMB.apuinfo"), 0, SHT_NOTE,     0 },
+  { STRING_COMMA_LEN (".PPC.EMB.sbss0"),   0, SHT_PROGBITS, SHF_ALLOC },
+  { STRING_COMMA_LEN (".PPC.EMB.sdata0"),  0, SHT_PROGBITS, SHF_ALLOC },
+  { NULL,                              0,  0, 0,            0 }
 };
 
 /* This is what we want for new plt/got.  */
 static struct bfd_elf_special_section ppc_alt_plt =
-  { ".plt",              4,  0, SHT_PROGBITS, SHF_ALLOC };
+  { STRING_COMMA_LEN (".plt"),             0, SHT_PROGBITS, SHF_ALLOC };
 
 static const struct bfd_elf_special_section *
 ppc_elf_get_sec_type_attr (bfd *abfd ATTRIBUTE_UNUSED, asection *sec)
@@ -2147,6 +2230,7 @@ ppc_elf_begin_write_processing (bfd *abfd, struct bfd_link_info *link_info)
 
 static bfd_boolean
 ppc_elf_write_section (bfd *abfd ATTRIBUTE_UNUSED,
+                      struct bfd_link_info *link_info ATTRIBUTE_UNUSED,
                       asection *asec,
                       bfd_byte *contents ATTRIBUTE_UNUSED)
 {
@@ -2332,9 +2416,18 @@ struct ppc_elf_link_hash_table
   elf_linker_section_t sdata[2];
   asection *sbss;
 
+  /* The (unloaded but important) .rela.plt.unloaded on VxWorks.  */
+  asection *srelplt2;
+
+  /* The .got.plt section (VxWorks only)*/
+  asection *sgotplt;
+
   /* Shortcut to .__tls_get_addr.  */
   struct elf_link_hash_entry *tls_get_addr;
 
+  /* The bfd that forced an old-style PLT.  */
+  bfd *old_bfd;
   /* TLS local dynamic got entry handling.  */
   union {
     bfd_signed_vma refcount;
@@ -2349,24 +2442,14 @@ struct ppc_elf_link_hash_table
   /* Non-zero if allocating the header left a gap.  */
   unsigned int got_gap;
 
-  /* Whether to use new plt/got layout or not.  */
-  unsigned int new_plt:1;
-  unsigned int old_plt:1;
-
-  /* Small local sym to section mapping cache.  */
-  struct sym_sec_cache sym_sec;
+  /* The type of PLT we have chosen to use.  */
+  enum ppc_elf_plt_type plt_type;
 
-  /* The (unloaded but important) .rela.plt.unloaded on VxWorks.  */
-  asection *srelplt2;
-
-  /* The .got.plt section (VxWorks only)*/
-  asection *sgotplt;
-
-  /* Short-cuts to frequently used symbols on VxWorks targets.  */
-  struct elf_link_hash_entry *hgot, *hplt;
+  /* Set if we should emit symbols for stubs.  */
+  unsigned int emit_stub_syms:1;
 
   /* True if the target system is VxWorks.  */
-  int is_vxworks;
+  unsigned int is_vxworks:1;
 
   /* The size of PLT entries.  */
   int plt_entry_size;
@@ -2374,6 +2457,9 @@ struct ppc_elf_link_hash_table
   int plt_slot_size;
   /* The size of the first PLT entry.  */
   int plt_initial_entry_size;
+
+  /* Small local sym to section mapping cache.  */
+  struct sym_sec_cache sym_sec;
 };
 
 /* Get the PPC ELF linker hash table from a link_info structure.  */
@@ -2421,8 +2507,9 @@ ppc_elf_link_hash_table_create (bfd *abfd)
   if (ret == NULL)
     return NULL;
 
-  if (! _bfd_elf_link_hash_table_init (&ret->elf, abfd,
-                                      ppc_elf_link_hash_newfunc))
+  if (!_bfd_elf_link_hash_table_init (&ret->elf, abfd,
+                                     ppc_elf_link_hash_newfunc,
+                                     sizeof (struct ppc_elf_link_hash_entry)))
     {
       free (ret);
       return NULL;
@@ -2444,8 +2531,6 @@ ppc_elf_link_hash_table_create (bfd *abfd)
   ret->plt_entry_size = 12;
   ret->plt_slot_size = 8;
   ret->plt_initial_entry_size = 72;
-  
-  ret->is_vxworks = 0;
 
   return &ret->elf.root;
 }
@@ -2539,19 +2624,9 @@ ppc_elf_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info)
        return FALSE;
     }
 
-  /* Create the section for VxWorks static plt relocations.  */
-  if (htab->is_vxworks && !info->shared)
-    {
-      s = bfd_make_section (abfd, ".rela.plt.unloaded");
-      flags = (SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_READONLY
-              | SEC_LINKER_CREATED);
-      if (s == NULL
-         || ! bfd_set_section_flags (abfd, s, flags)
-         || ! bfd_set_section_alignment (abfd, s,
-                 get_elf_backend_data (abfd)->s->log_file_align))
-       return FALSE;
-      htab->srelplt2 = s;
-    }
+  if (htab->is_vxworks
+      && !elf_vxworks_create_dynamic_sections (abfd, info, &htab->srelplt2))
+    return FALSE;
 
   htab->relplt = bfd_get_section_by_name (abfd, ".rela.plt");
   htab->plt = s = bfd_get_section_by_name (abfd, ".plt");
@@ -2559,18 +2634,20 @@ ppc_elf_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info)
     abort ();
 
   flags = SEC_ALLOC | SEC_CODE | SEC_LINKER_CREATED;
+  if (htab->plt_type == PLT_VXWORKS)
+    /* The VxWorks PLT is a loaded section with contents.  */
+    flags |= SEC_HAS_CONTENTS | SEC_LOAD | SEC_READONLY;
   return bfd_set_section_flags (abfd, s, flags);
 }
 
 /* Copy the extra info we tack onto an elf_link_hash_entry.  */
 
 static void
-ppc_elf_copy_indirect_symbol (const struct elf_backend_data *bed ATTRIBUTE_UNUSED,
+ppc_elf_copy_indirect_symbol (struct bfd_link_info *info,
                              struct elf_link_hash_entry *dir,
                              struct elf_link_hash_entry *ind)
 {
   struct ppc_elf_link_hash_entry *edir, *eind;
-  bfd_signed_vma tmp;
 
   edir = (struct ppc_elf_link_hash_entry *) dir;
   eind = (struct ppc_elf_link_hash_entry *) ind;
@@ -2582,10 +2659,7 @@ ppc_elf_copy_indirect_symbol (const struct elf_backend_data *bed ATTRIBUTE_UNUSE
          struct ppc_elf_dyn_relocs **pp;
          struct ppc_elf_dyn_relocs *p;
 
-         if (ind->root.type == bfd_link_hash_indirect)
-           abort ();
-
-         /* Add reloc counts against the weak sym to the strong sym
+         /* Add reloc counts against the indirect sym to the direct sym
             list.  Merge any entries against the same section.  */
          for (pp = &eind->dyn_relocs; (p = *pp) != NULL; )
            {
@@ -2631,14 +2705,8 @@ ppc_elf_copy_indirect_symbol (const struct elf_backend_data *bed ATTRIBUTE_UNUSE
 
   /* Copy over the GOT refcount entries that we may have already seen to
      the symbol which just became indirect.  */
-  tmp = edir->elf.got.refcount;
-  if (tmp < 1)
-    {
-      edir->elf.got.refcount = eind->elf.got.refcount;
-      eind->elf.got.refcount = tmp;
-    }
-  else
-    BFD_ASSERT (eind->elf.got.refcount < 1);
+  edir->elf.got.refcount += eind->elf.got.refcount;
+  eind->elf.got.refcount = 0;
 
   /* And plt entries.  */
   if (eind->elf.plt.plist != NULL)
@@ -2669,15 +2737,16 @@ ppc_elf_copy_indirect_symbol (const struct elf_backend_data *bed ATTRIBUTE_UNUSE
       eind->elf.plt.plist = NULL;
     }
 
-  if (edir->elf.dynindx == -1)
+  if (eind->elf.dynindx != -1)
     {
+      if (edir->elf.dynindx != -1)
+       _bfd_elf_strtab_delref (elf_hash_table (info)->dynstr,
+                               edir->elf.dynstr_index);
       edir->elf.dynindx = eind->elf.dynindx;
       edir->elf.dynstr_index = eind->elf.dynstr_index;
       eind->elf.dynindx = -1;
       eind->elf.dynstr_index = 0;
     }
-  else
-    BFD_ASSERT (eind->elf.dynindx == -1);
 }
 
 /* Return 1 if target is one of ours.  */
@@ -2686,9 +2755,12 @@ static bfd_boolean
 is_ppc_elf_target (const struct bfd_target *targ)
 {
   extern const bfd_target bfd_elf32_powerpc_vec;
+  extern const bfd_target bfd_elf32_powerpc_vxworks_vec;
   extern const bfd_target bfd_elf32_powerpcle_vec;
 
-  return targ == &bfd_elf32_powerpc_vec || targ == &bfd_elf32_powerpcle_vec;
+  return (targ == &bfd_elf32_powerpc_vec
+         || targ == &bfd_elf32_powerpc_vxworks_vec
+         || targ == &bfd_elf32_powerpcle_vec);
 }
 
 /* Hook called by the linker routine which adds symbols from an object
@@ -2734,6 +2806,20 @@ ppc_elf_add_symbol_hook (bfd *abfd,
   return TRUE;
 }
 \f
+static bfd_boolean
+create_sdata_sym (struct ppc_elf_link_hash_table *htab,
+                 elf_linker_section_t *lsect)
+{
+  lsect->sym = elf_link_hash_lookup (&htab->elf, lsect->sym_name,
+                                    TRUE, FALSE, TRUE);
+  if (lsect->sym == NULL)
+    return FALSE;
+  if (lsect->sym->root.type == bfd_link_hash_new)
+    lsect->sym->non_elf = 0;
+  lsect->sym->ref_regular = 1;
+  return TRUE;
+}
+
 /* Create a special linker section.  */
 
 static bfd_boolean
@@ -2760,7 +2846,7 @@ ppc_elf_create_linker_section (bfd *abfd,
     return FALSE;
   lsect->section = s;
 
-  return TRUE;
+  return create_sdata_sym (htab, lsect);
 }
 
 /* Find a linker generated pointer with a given addend and type.  */
@@ -3090,6 +3176,11 @@ ppc_elf_check_relocs (bfd *abfd,
          if (!elf_create_pointer_linker_section (abfd, &htab->sdata[0],
                                                  h, rel))
            return FALSE;
+         if (h != NULL)
+           {
+             ppc_elf_hash_entry (h)->has_sda_refs = TRUE;
+             h->non_got_ref = TRUE;
+           }
          break;
 
          /* Indirect .sdata2 relocation.  */
@@ -3106,12 +3197,65 @@ ppc_elf_check_relocs (bfd *abfd,
          if (!elf_create_pointer_linker_section (abfd, &htab->sdata[1],
                                                  h, rel))
            return FALSE;
+         if (h != NULL)
+           {
+             ppc_elf_hash_entry (h)->has_sda_refs = TRUE;
+             h->non_got_ref = TRUE;
+           }
          break;
 
        case R_PPC_SDAREL16:
+         if (info->shared)
+           {
+             bad_shared_reloc (abfd, r_type);
+             return FALSE;
+           }
+         if (htab->sdata[0].sym == NULL
+             && !create_sdata_sym (htab, &htab->sdata[0]))
+           return FALSE;
+         if (h != NULL)
+           {
+             ppc_elf_hash_entry (h)->has_sda_refs = TRUE;
+             h->non_got_ref = TRUE;
+           }
+         break;
+
        case R_PPC_EMB_SDA2REL:
+         if (info->shared)
+           {
+             bad_shared_reloc (abfd, r_type);
+             return FALSE;
+           }
+         if (htab->sdata[1].sym == NULL
+             && !create_sdata_sym (htab, &htab->sdata[1]))
+           return FALSE;
+         if (h != NULL)
+           {
+             ppc_elf_hash_entry (h)->has_sda_refs = TRUE;
+             h->non_got_ref = TRUE;
+           }
+         break;
+
        case R_PPC_EMB_SDA21:
        case R_PPC_EMB_RELSDA:
+         if (info->shared)
+           {
+             bad_shared_reloc (abfd, r_type);
+             return FALSE;
+           }
+         if (htab->sdata[0].sym == NULL
+             && !create_sdata_sym (htab, &htab->sdata[0]))
+           return FALSE;
+         if (htab->sdata[1].sym == NULL
+             && !create_sdata_sym (htab, &htab->sdata[1]))
+           return FALSE;
+         if (h != NULL)
+           {
+             ppc_elf_hash_entry (h)->has_sda_refs = TRUE;
+             h->non_got_ref = TRUE;
+           }
+         break;
+
        case R_PPC_EMB_NADDR32:
        case R_PPC_EMB_NADDR16:
        case R_PPC_EMB_NADDR16_LO:
@@ -3123,11 +3267,7 @@ ppc_elf_check_relocs (bfd *abfd,
              return FALSE;
            }
          if (h != NULL)
-           {
-             ppc_elf_hash_entry (h)->has_sda_refs = TRUE;
-             /* We may need a copy reloc.  */
-             h->non_got_ref = TRUE;
-           }
+           h->non_got_ref = TRUE;
          break;
 
        case R_PPC_PLT32:
@@ -3160,8 +3300,13 @@ ppc_elf_check_relocs (bfd *abfd,
            }
          else
            {
-             bfd_vma addend = r_type == R_PPC_PLTREL24 ? rel->r_addend : 0;
+             bfd_vma addend = 0;
 
+             if (r_type == R_PPC_PLTREL24)
+               {
+                 ppc_elf_tdata (abfd)->makes_plt_call = 1;
+                 addend = rel->r_addend;
+               }
              h->needs_plt = 1;
              if (!update_plt_info (abfd, h, got2, addend))
                return FALSE;
@@ -3186,7 +3331,7 @@ ppc_elf_check_relocs (bfd *abfd,
        case R_PPC_REL16_LO:
        case R_PPC_REL16_HI:
        case R_PPC_REL16_HA:
-         htab->new_plt = 1;
+         ppc_elf_tdata (abfd)->has_rel16 = 1;
          break;
 
          /* These are just markers.  */
@@ -3214,8 +3359,11 @@ ppc_elf_check_relocs (bfd *abfd,
 
          /* This refers only to functions defined in the shared library.  */
        case R_PPC_LOCAL24PC:
-         if (h && h == htab->elf.hgot)
-           htab->old_plt = 1;
+         if (h && h == htab->elf.hgot && htab->plt_type == PLT_UNSET)
+           {
+             htab->plt_type = PLT_OLD;
+             htab->old_bfd = abfd;
+           }
          break;
 
          /* This relocation describes the C++ object vtable hierarchy.
@@ -3228,7 +3376,9 @@ ppc_elf_check_relocs (bfd *abfd,
          /* This relocation describes which C++ vtable entries are actually
             used.  Record for later use during GC.  */
        case R_PPC_GNU_VTENTRY:
-         if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
+         BFD_ASSERT (h != NULL);
+         if (h != NULL
+             && !bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
            return FALSE;
          break;
 
@@ -3256,7 +3406,7 @@ ppc_elf_check_relocs (bfd *abfd,
              && got2 != NULL
              && (sec->flags & SEC_CODE) != 0
              && (info->shared || info->pie)
-             && !htab->old_plt)
+             && htab->plt_type == PLT_UNSET)
            {
              /* Old -fPIC gcc code has .long LCTOC1-LCFx just before
                 the start of a function, which assembles to a REL32
@@ -3269,9 +3419,14 @@ ppc_elf_check_relocs (bfd *abfd,
              s = bfd_section_from_r_symndx (abfd, &htab->sym_sec, sec,
                                             r_symndx);
              if (s == got2)
-               htab->old_plt = 1;
+               {
+                 htab->plt_type = PLT_OLD;
+                 htab->old_bfd = abfd;
+               }
            }
-         /* fall through */
+         if (h == NULL || h == htab->elf.hgot)
+           break;
+         goto dodyn1;
 
        case R_PPC_REL24:
        case R_PPC_REL14:
@@ -3281,7 +3436,11 @@ ppc_elf_check_relocs (bfd *abfd,
            break;
          if (h == htab->elf.hgot)
            {
-             htab->old_plt = 1;
+             if (htab->plt_type == PLT_UNSET)
+               {
+                 htab->plt_type = PLT_OLD;
+                 htab->old_bfd = abfd;
+               }
              break;
            }
          /* fall through */
@@ -3297,6 +3456,7 @@ ppc_elf_check_relocs (bfd *abfd,
        case R_PPC_ADDR14_BRNTAKEN:
        case R_PPC_UADDR32:
        case R_PPC_UADDR16:
+       dodyn1:
          if (h != NULL && !info->shared)
            {
              /* We may need a plt entry if the symbol turns out to be
@@ -3363,7 +3523,7 @@ ppc_elf_check_relocs (bfd *abfd,
                  if (name == NULL)
                    return FALSE;
 
-                 BFD_ASSERT (strncmp (name, ".rela", 5) == 0
+                 BFD_ASSERT (CONST_STRNEQ (name, ".rela")
                              && strcmp (bfd_get_section_name (abfd, sec),
                                         name + 5) == 0);
 
@@ -3401,13 +3561,15 @@ ppc_elf_check_relocs (bfd *abfd,
                     easily.  Oh well.  */
 
                  asection *s;
+                 void *vpp;
+
                  s = bfd_section_from_r_symndx (abfd, &htab->sym_sec,
                                                 sec, r_symndx);
                  if (s == NULL)
                    return FALSE;
 
-                 head = ((struct ppc_elf_dyn_relocs **)
-                         &elf_section_data (s)->local_dynrel);
+                 vpp = &elf_section_data (s)->local_dynrel;
+                 head = (struct ppc_elf_dyn_relocs **) vpp;
                }
 
              p = *head;
@@ -3435,6 +3597,62 @@ ppc_elf_check_relocs (bfd *abfd,
   return TRUE;
 }
 \f
+
+/* Merge object attributes from IBFD into OBFD.  Raise an error if
+   there are conflicting attributes.  */
+static bfd_boolean
+ppc_elf_merge_obj_attributes (bfd *ibfd, bfd *obfd)
+{
+  obj_attribute *in_attr;
+  obj_attribute *out_attr;
+
+  if (!elf_known_obj_attributes_proc (obfd)[0].i)
+    {
+      /* This is the first object.  Copy the attributes.  */
+      _bfd_elf_copy_obj_attributes (ibfd, obfd);
+
+      /* Use the Tag_null value to indicate the attributes have been
+        initialized.  */
+      elf_known_obj_attributes_proc (obfd)[0].i = 1;
+
+      return TRUE;
+    }
+
+  /* Check for conflicting Tag_GNU_Power_ABI_FP attributes and merge
+     non-conflicting ones.  */
+  in_attr = elf_known_obj_attributes (ibfd)[OBJ_ATTR_GNU];
+  out_attr = elf_known_obj_attributes (obfd)[OBJ_ATTR_GNU];
+  if (in_attr[Tag_GNU_Power_ABI_FP].i != out_attr[Tag_GNU_Power_ABI_FP].i)
+    {
+      out_attr[Tag_GNU_Power_ABI_FP].type = 1;
+      if (out_attr[Tag_GNU_Power_ABI_FP].i == 0)
+       out_attr[Tag_GNU_Power_ABI_FP].i = in_attr[Tag_GNU_Power_ABI_FP].i;
+      else if (in_attr[Tag_GNU_Power_ABI_FP].i == 0)
+       ;
+      else if (out_attr[Tag_GNU_Power_ABI_FP].i == 1
+              && in_attr[Tag_GNU_Power_ABI_FP].i == 2)
+       _bfd_error_handler
+         (_("Warning: %B uses hard float, %B uses soft float"), obfd, ibfd);
+      else if (out_attr[Tag_GNU_Power_ABI_FP].i == 2
+              && in_attr[Tag_GNU_Power_ABI_FP].i == 1)
+       _bfd_error_handler
+         (_("Warning: %B uses hard float, %B uses soft float"), ibfd, obfd);
+      else if (in_attr[Tag_GNU_Power_ABI_FP].i > 2)
+       _bfd_error_handler
+         (_("Warning: %B uses unknown floating point ABI %d"), ibfd,
+          in_attr[Tag_GNU_Power_ABI_FP].i);
+      else
+       _bfd_error_handler
+         (_("Warning: %B uses unknown floating point ABI %d"), obfd,
+          out_attr[Tag_GNU_Power_ABI_FP].i);
+    }
+
+  /* Merge Tag_compatibility attributes and any common GNU ones.  */
+  _bfd_elf_merge_object_attributes (ibfd, obfd);
+
+  return TRUE;
+}
+
 /* Merge backend specific data from an object file to the output
    object file when linking.  */
 
@@ -3453,6 +3671,9 @@ ppc_elf_merge_private_bfd_data (bfd *ibfd, bfd *obfd)
   if (! _bfd_generic_verify_endian_match (ibfd, obfd))
     return FALSE;
 
+  if (!ppc_elf_merge_obj_attributes (ibfd, obfd))
+    return FALSE;
+
   new_flags = elf_elfheader (ibfd)->e_flags;
   old_flags = elf_elfheader (obfd)->e_flags;
   if (!elf_flags_init (obfd))
@@ -3532,26 +3753,52 @@ ppc_elf_merge_private_bfd_data (bfd *ibfd, bfd *obfd)
 int
 ppc_elf_select_plt_layout (bfd *output_bfd ATTRIBUTE_UNUSED,
                           struct bfd_link_info *info,
-                          int force_old_plt)
+                          enum ppc_elf_plt_type plt_style,
+                          int emit_stub_syms)
 {
   struct ppc_elf_link_hash_table *htab;
   flagword flags;
 
   htab = ppc_elf_hash_table (info);
-  if (force_old_plt || !htab->new_plt)
-    htab->old_plt = 1;
 
-  if (htab->is_vxworks)
+  if (htab->plt_type == PLT_UNSET)
     {
-      /* The VxWorks PLT is a loaded section with contents.  */
-      flags = SEC_ALLOC | SEC_CODE | SEC_IN_MEMORY | SEC_LINKER_CREATED
-             | SEC_HAS_CONTENTS | SEC_LOAD | SEC_READONLY;
-
-      if (htab->plt != NULL
-         && !bfd_set_section_flags (htab->elf.dynobj, htab->plt, flags))
-       return -1;
+      if (plt_style == PLT_OLD)
+       htab->plt_type = PLT_OLD;
+      else
+       {
+         bfd *ibfd;
+         enum ppc_elf_plt_type plt_type = plt_style;
+
+         /* Look through the reloc flags left by ppc_elf_check_relocs.
+            Use the old style bss plt if a file makes plt calls
+            without using the new relocs, and if ld isn't given
+            --secure-plt and we never see REL16 relocs.  */
+         if (plt_type == PLT_UNSET)
+           plt_type = PLT_OLD;
+         for (ibfd = info->input_bfds; ibfd; ibfd = ibfd->link_next)
+           if (is_ppc_elf_target (ibfd->xvec))
+             {
+               if (ppc_elf_tdata (ibfd)->has_rel16)
+                 plt_type = PLT_NEW;
+               else if (ppc_elf_tdata (ibfd)->makes_plt_call)
+                 {
+                   plt_type = PLT_OLD;
+                   htab->old_bfd = ibfd;
+                   break;
+                 }
+             }
+         htab->plt_type = plt_type;
+       }
     }
-  else if (!htab->old_plt)
+  if (htab->plt_type == PLT_OLD && plt_style == PLT_NEW)
+    info->callbacks->info (_("Using bss-plt due to %B"), htab->old_bfd);
+
+  htab->emit_stub_syms = emit_stub_syms;
+
+  BFD_ASSERT (htab->plt_type != PLT_VXWORKS);
+
+  if (htab->plt_type == PLT_NEW)
     {
       flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS
               | SEC_IN_MEMORY | SEC_LINKER_CREATED);
@@ -3573,7 +3820,7 @@ ppc_elf_select_plt_layout (bfd *output_bfd ATTRIBUTE_UNUSED,
          && !bfd_set_section_alignment (htab->elf.dynobj, htab->glink, 0))
        return -1;
     }
-  return !htab->old_plt;
+  return htab->plt_type == PLT_NEW;
 }
 \f
 /* Return the section that should be marked against GC for a given
@@ -3581,38 +3828,20 @@ ppc_elf_select_plt_layout (bfd *output_bfd ATTRIBUTE_UNUSED,
 
 static asection *
 ppc_elf_gc_mark_hook (asection *sec,
-                     struct bfd_link_info *info ATTRIBUTE_UNUSED,
+                     struct bfd_link_info *info,
                      Elf_Internal_Rela *rel,
                      struct elf_link_hash_entry *h,
                      Elf_Internal_Sym *sym)
 {
   if (h != NULL)
-    {
-      switch (ELF32_R_TYPE (rel->r_info))
-       {
-       case R_PPC_GNU_VTINHERIT:
-       case R_PPC_GNU_VTENTRY:
-         break;
-
-       default:
-         switch (h->root.type)
-           {
-           case bfd_link_hash_defined:
-           case bfd_link_hash_defweak:
-             return h->root.u.def.section;
-
-           case bfd_link_hash_common:
-             return h->root.u.c.p->section;
-
-           default:
-             break;
-           }
-       }
-    }
-  else
-    return bfd_section_from_elf_index (sec->owner, sym->st_shndx);
+    switch (ELF32_R_TYPE (rel->r_info))
+      {
+      case R_PPC_GNU_VTINHERIT:
+      case R_PPC_GNU_VTENTRY:
+       return NULL;
+      }
 
-  return NULL;
+  return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
 }
 
 /* Update the got, plt and dynamic reloc reference counts for the
@@ -3728,8 +3957,12 @@ ppc_elf_gc_sweep_hook (bfd *abfd,
        case R_PPC_ADDR14_BRNTAKEN:
        case R_PPC_UADDR32:
        case R_PPC_UADDR16:
+         if (info->shared)
+           break;
+
        case R_PPC_PLT32:
        case R_PPC_PLTREL24:
+       case R_PPC_PLTREL32:
        case R_PPC_PLT16_LO:
        case R_PPC_PLT16_HI:
        case R_PPC_PLT16_HA:
@@ -3757,7 +3990,7 @@ ppc_elf_tls_setup (bfd *obfd, struct bfd_link_info *info)
   struct ppc_elf_link_hash_table *htab;
 
   htab = ppc_elf_hash_table (info);
-  if (!htab->old_plt
+  if (htab->plt_type == PLT_NEW
       && htab->plt != NULL
       && htab->plt->output_section != NULL)
     {
@@ -3976,7 +4209,6 @@ ppc_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
 {
   struct ppc_elf_link_hash_table *htab;
   asection *s;
-  unsigned int power_of_two;
 
 #ifdef DEBUG
   fprintf (stderr, "ppc_elf_adjust_dynamic_symbol called for %s\n",
@@ -4042,24 +4274,6 @@ ppc_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
   /* This is a reference to a symbol defined by a dynamic object which
      is not a function.  */
 
-  /* First, a fudge for old shared libs that export some symbols they
-     should not.  */
-  if (!h->def_regular
-      && (strcmp (h->root.root.string, "_SDA_BASE_") == 0
-         || strcmp (h->root.root.string, "_SDA2_BASE_") == 0))
-    {
-      /* These symbols will be defined later, as if they were defined in
-        a linker script.  We don't want to use a definition in a shared
-        object.  */
-      const struct elf_backend_data *bed;
-
-      bed = get_elf_backend_data (htab->elf.dynobj);
-      (*bed->elf_backend_hide_symbol) (info, h, TRUE);
-      h->root.type = bfd_link_hash_undefined;
-      h->root.u.undef.abfd = htab->elf.dynobj;
-      return TRUE;
-    }
-
   /* If we are creating a shared library, we must presume that the
      only references to the symbol are via the global offset table.
      For such cases we need not do anything here; the relocations will
@@ -4072,11 +4286,15 @@ ppc_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
   if (!h->non_got_ref)
     return TRUE;
 
-   /* If we didn't find any dynamic relocs in read-only sections, then we'll
-      be keeping the dynamic relocs and avoiding the copy reloc.  We can't
-      do this if there are any small data relocations.  */
+   /* If we didn't find any dynamic relocs in read-only sections, then
+      we'll be keeping the dynamic relocs and avoiding the copy reloc.
+      We can't do this if there are any small data relocations.  This
+      doesn't work on VxWorks, where we can not have dynamic
+      relocations (other than copy and jump slot relocations) in an
+      executable.  */
   if (ELIMINATE_COPY_RELOCS
-      && !ppc_elf_hash_entry (h)->has_sda_refs)
+      && !ppc_elf_hash_entry (h)->has_sda_refs
+      && !htab->is_vxworks)
     {
       struct ppc_elf_dyn_relocs *p;
       for (p = ppc_elf_hash_entry (h)->dyn_relocs; p != NULL; p = p->next)
@@ -4093,6 +4311,13 @@ ppc_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
        }
     }
 
+  if (h->size == 0)
+    {
+      (*_bfd_error_handler) (_("dynamic variable `%s' is zero size"),
+                            h->root.root.string);
+      return TRUE;
+    }
+
   /* We must allocate the symbol in our .dynbss section, which will
      become part of the .bss section of the executable.  There will be
      an entry for this symbol in the .dynsym section.  The dynamic
@@ -4129,30 +4354,61 @@ ppc_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
       h->needs_copy = 1;
     }
 
-  /* We need to figure out the alignment required for this symbol.  I
-     have no idea how ELF linkers handle this.  */
-  power_of_two = bfd_log2 (h->size);
-  if (power_of_two > 4)
-    power_of_two = 4;
+  return _bfd_elf_adjust_dynamic_copy (h, s);
+}
+\f
+/* Generate a symbol to mark plt call stubs.  For non-PIC code the sym is
+   xxxxxxxx.plt_call32.<callee> where xxxxxxxx is a hex number, usually 0,
+   specifying the addend on the plt relocation.  For -fpic code, the sym
+   is xxxxxxxx.plt_pic32.<callee>, and for -fPIC
+   xxxxxxxx.got2.plt_pic32.<callee>.  */
+
+static bfd_boolean
+add_stub_sym (struct plt_entry *ent,
+             struct elf_link_hash_entry *h,
+             struct bfd_link_info *info)
+{
+  struct elf_link_hash_entry *sh;
+  size_t len1, len2, len3;
+  char *name;
+  const char *stub;
+  struct ppc_elf_link_hash_table *htab = ppc_elf_hash_table (info);
 
-  /* Apply the required alignment.  */
-  s->size = BFD_ALIGN (s->size, (bfd_size_type) (1 << power_of_two));
-  if (power_of_two > bfd_get_section_alignment (htab->elf.dynobj, s))
+  if (info->shared || info->pie)
+    stub = ".plt_pic32.";
+  else
+    stub = ".plt_call32.";
+
+  len1 = strlen (h->root.root.string);
+  len2 = strlen (stub);
+  len3 = 0;
+  if (ent->sec)
+    len3 = strlen (ent->sec->name);
+  name = bfd_malloc (len1 + len2 + len3 + 9);
+  if (name == NULL)
+    return FALSE;
+  sprintf (name, "%08x", (unsigned) ent->addend & 0xffffffff);
+  if (ent->sec)
+    memcpy (name + 8, ent->sec->name, len3);
+  memcpy (name + 8 + len3, stub, len2);
+  memcpy (name + 8 + len3 + len2, h->root.root.string, len1 + 1);
+  sh = elf_link_hash_lookup (&htab->elf, name, TRUE, FALSE, FALSE);
+  if (sh == NULL)
+    return FALSE;
+  if (sh->root.type == bfd_link_hash_new)
     {
-      if (! bfd_set_section_alignment (htab->elf.dynobj, s, power_of_two))
-       return FALSE;
+      sh->root.type = bfd_link_hash_defined;
+      sh->root.u.def.section = htab->glink;
+      sh->root.u.def.value = ent->glink_offset;
+      sh->ref_regular = 1;
+      sh->def_regular = 1;
+      sh->ref_regular_nonweak = 1;
+      sh->forced_local = 1;
+      sh->non_elf = 0;
     }
-
-  /* Define the symbol as being at this point in the section.  */
-  h->root.u.def.section = s;
-  h->root.u.def.value = s->size;
-
-  /* Increment the section size to make room for the symbol.  */
-  s->size += h->size;
-
   return TRUE;
 }
-\f
+
 /* Allocate NEED contiguous space in .got, and return the offset.
    Handles allocation of the got header when crossing 32k.  */
 
@@ -4160,31 +4416,32 @@ static bfd_vma
 allocate_got (struct ppc_elf_link_hash_table *htab, unsigned int need)
 {
   bfd_vma where;
-  unsigned int max_before_header = 32768;
-
-  if (htab->old_plt)
-    max_before_header = 32764;
+  unsigned int max_before_header;
 
-  if (htab->is_vxworks)
+  if (htab->plt_type == PLT_VXWORKS)
     {
       where = htab->got->size;
       htab->got->size += need;
     }
-  else if (need <= htab->got_gap)
-    {
-      where = max_before_header - htab->got_gap;
-      htab->got_gap -= need;
-    }
   else
     {
-      if (htab->got->size + need > max_before_header
-         && htab->got->size <= max_before_header)
+      max_before_header = htab->plt_type == PLT_NEW ? 32768 : 32764;
+      if (need <= htab->got_gap)
        {
-         htab->got_gap = max_before_header - htab->got->size;
-         htab->got->size = max_before_header + htab->got_header_size;
+         where = max_before_header - htab->got_gap;
+         htab->got_gap -= need;
+       }
+      else
+       {
+         if (htab->got->size + need > max_before_header
+             && htab->got->size <= max_before_header)
+           {
+             htab->got_gap = max_before_header - htab->got->size;
+             htab->got->size = max_before_header + htab->got_header_size;
+           }
+         where = htab->got->size;
+         htab->got->size += need;
        }
-      where = htab->got->size;
-      htab->got->size += need;
     }
   return where;
 }
@@ -4231,7 +4488,7 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
              {
                asection *s = htab->plt;
 
-               if (!(htab->old_plt || htab->is_vxworks))
+               if (htab->plt_type == PLT_NEW)
                  {
                    if (!doneone)
                      {
@@ -4254,6 +4511,10 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
                        h->root.u.def.value = glink_offset;
                      }
                    ent->glink_offset = glink_offset;
+
+                   if (htab->emit_stub_syms
+                       && !add_stub_sym (ent, h, info))
+                     return FALSE;
                  }
                else
                  {
@@ -4291,7 +4552,7 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
                        s->size += htab->plt_entry_size;
                        /* After the 8192nd entry, room for two entries
                           is allocated.  */
-                       if (!htab->is_vxworks
+                       if (htab->plt_type == PLT_OLD
                            && (s->size - htab->plt_initial_entry_size)
                                / htab->plt_entry_size
                               > PLT_NUM_SINGLE_ENTRIES)
@@ -4305,7 +4566,7 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
                  {
                    htab->relplt->size += sizeof (Elf32_External_Rela);
 
-                   if (htab->is_vxworks)
+                   if (htab->plt_type == PLT_VXWORKS)
                      {
                        /* Allocate space for the unloaded relocations.  */
                        if (!info->shared)
@@ -4332,13 +4593,15 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
              }
            else
              ent->plt.offset = (bfd_vma) -1;
-
-           if (!doneone)
-             {
-               h->plt.plist = NULL;
-               h->needs_plt = 0;
-             }
          }
+       else
+         ent->plt.offset = (bfd_vma) -1;
+
+      if (!doneone)
+       {
+         h->plt.plist = NULL;
+         h->needs_plt = 0;
+       }
     }
   else
     {
@@ -4430,20 +4693,20 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
 
       /* Also discard relocs on undefined weak syms with non-default
         visibility.  */
-      if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
+      if (eh->dyn_relocs != NULL
          && h->root.type == bfd_link_hash_undefweak)
-       eh->dyn_relocs = NULL;
-
-      /* Make sure undefined weak symbols are output as a dynamic symbol
-        in PIEs.  */
-      if (info->pie
-         && eh->dyn_relocs != NULL
-         && h->dynindx == -1
-         && h->root.type == bfd_link_hash_undefweak
-         && !h->forced_local)
        {
-         if (! bfd_elf_link_record_dynamic_symbol (info, h))
-           return FALSE;
+         if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
+           eh->dyn_relocs = NULL;
+
+         /* Make sure undefined weak symbols are output as a dynamic
+            symbol in PIEs.  */
+         else if (h->dynindx == -1
+                  && !h->forced_local)
+           {
+             if (! bfd_elf_link_record_dynamic_symbol (info, h))
+               return FALSE;
+           }
        }
     }
   else if (ELIMINATE_COPY_RELOCS)
@@ -4546,9 +4809,9 @@ ppc_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
        }
     }
 
-  if (htab->old_plt)
+  if (htab->plt_type == PLT_OLD)
     htab->got_header_size = 16;
-  else
+  else if (htab->plt_type == PLT_NEW)
     htab->got_header_size = 12;
 
   /* Set up .got offsets for local syms, and space for local dynamic
@@ -4644,42 +4907,24 @@ ppc_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
   else
     htab->tlsld_got.offset = (bfd_vma) -1;
 
-  if (htab->is_vxworks)
-    {
-      /* Save the GOT and PLT symbols in the hash table for easy access.
-        Mark them as having relocations; they might not, but we won't
-        know for sure until we build the GOT in finish_dynamic_symbol.  */
-
-      htab->hgot = elf_link_hash_lookup (elf_hash_table (info),
-                                        "_GLOBAL_OFFSET_TABLE_",
-                                        FALSE, FALSE, FALSE);
-      if (htab->hgot)
-       htab->hgot->indx = -2;
-      htab->hplt = elf_link_hash_lookup (elf_hash_table (info),
-                                        "_PROCEDURE_LINKAGE_TABLE_",
-                                        FALSE, FALSE, FALSE);
-      if (htab->hplt)
-       htab->hplt->indx = -2;
-      /* If the PLT is executable then give the symbol function type.  */
-      if (htab->hplt && htab->plt->flags & SEC_CODE)
-       htab->hplt->type = STT_FUNC;
-    }
-
   /* Allocate space for global sym dynamic relocs.  */
   elf_link_hash_traverse (elf_hash_table (info), allocate_dynrelocs, info);
 
-  if (htab->got != NULL && !htab->is_vxworks)
+  if (htab->got != NULL && htab->plt_type != PLT_VXWORKS)
     {
       unsigned int g_o_t = 32768;
 
-      /* If we haven't allocated the header, do so now.  */
+      /* If we haven't allocated the header, do so now.  When we get here,
+        for old plt/got the got size will be 0 to 32764 (not allocated),
+        or 32780 to 65536 (header allocated).  For new plt/got, the
+        corresponding ranges are 0 to 32768 and 32780 to 65536.  */
       if (htab->got->size <= 32768)
        {
          g_o_t = htab->got->size;
+         if (htab->plt_type == PLT_OLD)
+           g_o_t += 4;
          htab->got->size += htab->got_header_size;
        }
-      if (htab->old_plt && !htab->is_vxworks)
-       g_o_t += 4;
 
       htab->elf.hgot->root.u.def.value = g_o_t;
     }
@@ -4692,6 +4937,41 @@ ppc_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
       /* Pad out to align the start of PLTresolve.  */
       htab->glink->size += -htab->glink->size & 15;
       htab->glink->size += GLINK_PLTRESOLVE;
+
+      if (htab->emit_stub_syms)
+       {
+         struct elf_link_hash_entry *sh;
+         sh = elf_link_hash_lookup (&htab->elf, "__glink",
+                                    TRUE, FALSE, FALSE);
+         if (sh == NULL)
+           return FALSE;
+         if (sh->root.type == bfd_link_hash_new)
+           {
+             sh->root.type = bfd_link_hash_defined;
+             sh->root.u.def.section = htab->glink;
+             sh->root.u.def.value = htab->glink_pltresolve;
+             sh->ref_regular = 1;
+             sh->def_regular = 1;
+             sh->ref_regular_nonweak = 1;
+             sh->forced_local = 1;
+             sh->non_elf = 0;
+           }
+         sh = elf_link_hash_lookup (&htab->elf, "__glink_PLTresolve",
+                                    TRUE, FALSE, FALSE);
+         if (sh == NULL)
+           return FALSE;
+         if (sh->root.type == bfd_link_hash_new)
+           {
+             sh->root.type = bfd_link_hash_defined;
+             sh->root.u.def.section = htab->glink;
+             sh->root.u.def.value = htab->glink->size - GLINK_PLTRESOLVE;
+             sh->ref_regular = 1;
+             sh->def_regular = 1;
+             sh->ref_regular_nonweak = 1;
+             sh->forced_local = 1;
+             sh->non_elf = 0;
+           }
+       }
     }
 
   /* We've now determined the sizes of the various dynamic sections.
@@ -4715,7 +4995,7 @@ ppc_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
          /* We'd like to strip these sections if they aren't needed, but if
             we've exported dynamic symbols from them we must leave them.
             It's too late to tell BFD to get rid of the symbols.  */
-         if ((s == htab->plt || s == htab->got) && htab->hplt != NULL)
+         if ((s == htab->plt || s == htab->got) && htab->elf.hplt != NULL)
            strip_section = FALSE;
          /* Strip this section if we don't need it; see the
             comment below.  */
@@ -4725,7 +5005,7 @@ ppc_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
        {
          /* Strip these too.  */
        }
-      else if (strncmp (bfd_get_section_name (dynobj, s), ".rela", 5) == 0)
+      else if (CONST_STRNEQ (bfd_get_section_name (dynobj, s), ".rela"))
        {
          if (s->size != 0)
            {
@@ -4977,7 +5257,7 @@ ppc_elf_relax_section (bfd *abfd,
 
              if (ent != NULL)
                {
-                 if (!htab->old_plt)
+                 if (htab->plt_type == PLT_NEW)
                    {
                      tsec = htab->glink;
                      toff = ent->glink_offset;
@@ -5046,6 +5326,10 @@ ppc_elf_relax_section (bfd *abfd,
       else if (r_type != R_PPC_PLTREL24)
        toff += irel->r_addend;
 
+      /* Attempted -shared link of non-pic code loses.  */
+      if (tsec->output_section == NULL)
+       continue;
+
       symaddr = tsec->output_section->vma + tsec->output_offset + toff;
 
       roff = irel->r_offset;
@@ -5254,68 +5538,19 @@ ppc_elf_relax_section (bfd *abfd,
   return FALSE;
 }
 \f
-/* Set _SDA_BASE_, _SDA2_BASE, and sbss start and end syms.  They are
-   set here rather than via PROVIDE in the default linker script,
-   because using PROVIDE inside an output section statement results in
-   unnecessary output sections.  Using PROVIDE outside an output section
-   statement runs the risk of section alignment affecting where the
-   section starts.  */
+/* What to do when ld finds relocations against symbols defined in
+   discarded sections.  */
 
-bfd_boolean
-ppc_elf_set_sdata_syms (bfd *obfd, struct bfd_link_info *info)
+static unsigned int
+ppc_elf_action_discarded (asection *sec)
 {
-  struct ppc_elf_link_hash_table *htab;
-  unsigned i;
-  asection *s;
-  bfd_vma val;
-
-  htab = ppc_elf_hash_table (info);
-
-  for (i = 0; i < 2; i++)
-    {
-      elf_linker_section_t *lsect = &htab->sdata[i];
+  if (strcmp (".fixup", sec->name) == 0)
+    return 0;
 
-      s = lsect->section;
-      if (s != NULL)
-       s = s->output_section;
-      if (s == NULL)
-       s = bfd_get_section_by_name (obfd, lsect->name);
-      if (s == NULL)
-       s = bfd_get_section_by_name (obfd, lsect->bss_name);
+  if (strcmp (".got2", sec->name) == 0)
+    return 0;
 
-      if (s)
-       {
-         /* VxWorks executables are relocatable, so the sdata base symbols
-            must be section-relative.  If the section is zero sized leave
-            them as absolute symbols to avoid creationg an unused
-            output section.  */
-         val = 32768;
-         lsect->sym_val = val + s->vma;
-         if (s->size == 0)
-           {
-             val += s->vma;
-             s = NULL;
-           }
-       }
-      else
-       {
-         val = 0;
-         lsect->sym_val = 0;
-       }
-
-      _bfd_elf_provide_symbol (info, lsect->sym_name, val, s);
-    }
-
-  s = bfd_get_section_by_name (obfd, ".sbss");
-  _bfd_elf_provide_symbol (info, "__sbss_start", 0, NULL);
-  _bfd_elf_provide_symbol (info, "___sbss_start", 0, NULL);
-  if (s != NULL)
-    val = s->size;
-  else
-    val = 0;
-  _bfd_elf_provide_symbol (info, "__sbss_end", val, s);
-  _bfd_elf_provide_symbol (info, "___sbss_end", val, s);
-  return TRUE;
+  return _bfd_elf_default_action_discarded (sec);
 }
 \f
 /* Fill in the address for a pointer generated in a linker section.  */
@@ -5428,6 +5663,7 @@ ppc_elf_relocate_section (bfd *output_bfd,
   asection *got2, *sreloc = NULL;
   bfd_vma *local_got_offsets;
   bfd_boolean ret = TRUE;
+  bfd_vma d_offset = (bfd_big_endian (output_bfd) ? 2 : 0);
 
 #ifdef DEBUG
   _bfd_error_handler ("ppc_elf_relocate_section called for %B section %A, "
@@ -5439,29 +5675,6 @@ ppc_elf_relocate_section (bfd *output_bfd,
 
   got2 = bfd_get_section_by_name (input_bfd, ".got2");
 
-  if (info->relocatable)
-    {
-      if (got2 == NULL)
-       return TRUE;
-
-      rel = relocs;
-      relend = relocs + input_section->reloc_count;
-      for (; rel < relend; rel++)
-       {
-         enum elf_ppc_reloc_type r_type;
-
-         r_type = ELF32_R_TYPE (rel->r_info);
-         if (r_type == R_PPC_PLTREL24
-             && rel->r_addend >= 32768)
-           {
-             /* R_PPC_PLTREL24 is rather special.  If non-zero, the
-                addend specifies the GOT pointer offset within .got2.  */
-             rel->r_addend += got2->output_offset;
-           }
-       }
-      return TRUE;
-    }
-
   /* Initialize howto table if not already done.  */
   if (!ppc_elf_howto_table[R_PPC_ADDR32])
     ppc_elf_howto_init ();
@@ -5515,6 +5728,33 @@ ppc_elf_relocate_section (bfd *output_bfd,
          sym_name = h->root.root.string;
        }
 
+      if (sec != NULL && elf_discarded_section (sec))
+       {
+         /* For relocs against symbols from removed linkonce sections,
+            or sections discarded by a linker script, we just want the
+            section contents zeroed.  Avoid any special processing.  */
+         howto = NULL;
+         if (r_type < R_PPC_max)
+           howto = ppc_elf_howto_table[r_type];
+         _bfd_clear_contents (howto, input_bfd, contents + rel->r_offset);
+         rel->r_info = 0;
+         rel->r_addend = 0;
+         continue;
+       }
+
+      if (info->relocatable)
+       {
+         if (got2 != NULL
+             && r_type == R_PPC_PLTREL24
+             && rel->r_addend >= 32768)
+           {
+             /* R_PPC_PLTREL24 is rather special.  If non-zero, the
+                addend specifies the GOT pointer offset within .got2.  */
+             rel->r_addend += got2->output_offset;
+           }
+         continue;
+       }
+
       /* TLS optimizations.  Replace instruction sequences and relocs
         based on information we collected in tls_optimize.  We edit
         RELOCS so that --emit-relocs will output something sensible
@@ -5554,10 +5794,10 @@ ppc_elf_relocate_section (bfd *output_bfd,
              && (tls_mask & TLS_TPREL) == 0)
            {
              bfd_vma insn;
-             insn = bfd_get_32 (output_bfd, contents + rel->r_offset - 2);
+             insn = bfd_get_32 (output_bfd, contents + rel->r_offset - d_offset);
              insn &= 31 << 21;
              insn |= 0x3c020000;       /* addis 0,2,0 */
-             bfd_put_32 (output_bfd, insn, contents + rel->r_offset - 2);
+             bfd_put_32 (output_bfd, insn, contents + rel->r_offset - d_offset);
              r_type = R_PPC_TPREL16_HA;
              rel->r_info = ELF32_R_INFO (r_symndx, r_type);
            }
@@ -5601,9 +5841,10 @@ ppc_elf_relocate_section (bfd *output_bfd,
              bfd_put_32 (output_bfd, insn, contents + rel->r_offset);
              r_type = R_PPC_TPREL16_LO;
              rel->r_info = ELF32_R_INFO (r_symndx, r_type);
+
              /* Was PPC_TLS which sits on insn boundary, now
-                PPC_TPREL16_LO which is at insn+2.  */
-             rel->r_offset += 2;
+                PPC_TPREL16_LO which is at low-order half-word.  */
+             rel->r_offset += d_offset;
            }
          break;
 
@@ -5625,7 +5866,7 @@ ppc_elf_relocate_section (bfd *output_bfd,
              else
                {
                  bfd_put_32 (output_bfd, NOP, contents + rel->r_offset);
-                 rel->r_offset -= 2;
+                 rel->r_offset -= d_offset;
                  r_type = R_PPC_NONE;
                }
              rel->r_info = ELF32_R_INFO (r_symndx, r_type);
@@ -5674,7 +5915,7 @@ ppc_elf_relocate_section (bfd *output_bfd,
                  /* OK, it checks out.  Replace the call.  */
                  offset = rel[1].r_offset;
                  insn1 = bfd_get_32 (output_bfd,
-                                     contents + rel->r_offset - 2);
+                                     contents + rel->r_offset - d_offset);
                  if ((tls_mask & tls_gd) != 0)
                    {
                      /* IE */
@@ -5682,6 +5923,7 @@ ppc_elf_relocate_section (bfd *output_bfd,
                      insn1 |= 32 << 26;        /* lwz */
                      insn2 = 0x7c631214;       /* add 3,3,2 */
                      rel[1].r_info = ELF32_R_INFO (r_symndx2, R_PPC_NONE);
+                     rel[1].r_addend = 0;
                      r_type = (((r_type - (R_PPC_GOT_TLSGD16 & 3)) & 3)
                                + R_PPC_GOT_TPREL16);
                      rel->r_info = ELF32_R_INFO (r_symndx, r_type);
@@ -5696,15 +5938,15 @@ ppc_elf_relocate_section (bfd *output_bfd,
                          /* Was an LD reloc.  */
                          r_symndx = 0;
                          rel->r_addend = htab->elf.tls_sec->vma + DTP_OFFSET;
-                         rel[1].r_addend = htab->elf.tls_sec->vma + DTP_OFFSET;
                        }
                      r_type = R_PPC_TPREL16_HA;
                      rel->r_info = ELF32_R_INFO (r_symndx, r_type);
                      rel[1].r_info = ELF32_R_INFO (r_symndx,
                                                    R_PPC_TPREL16_LO);
-                     rel[1].r_offset += 2;
+                     rel[1].r_offset += d_offset;
+                     rel[1].r_addend = rel->r_addend;
                    }
-                 bfd_put_32 (output_bfd, insn1, contents + rel->r_offset - 2);
+                 bfd_put_32 (output_bfd, insn1, contents + rel->r_offset - d_offset);
                  bfd_put_32 (output_bfd, insn2, contents + offset);
                  if (tls_gd == 0)
                    {
@@ -6098,14 +6340,7 @@ ppc_elf_relocate_section (bfd *output_bfd,
        case R_PPC_ADDR14_BRNTAKEN:
        case R_PPC_UADDR32:
        case R_PPC_UADDR16:
-         /* r_symndx will be zero only for relocs against symbols
-            from removed linkonce sections, or sections discarded by
-            a linker script.  */
        dodyn:
-         if (r_symndx == 0)
-           break;
-         /* Fall thru.  */
-
          if ((input_section->flags & SEC_ALLOC) == 0)
            break;
          /* Fall thru.  */
@@ -6147,7 +6382,7 @@ ppc_elf_relocate_section (bfd *output_bfd,
                  if (name == NULL)
                    return FALSE;
 
-                 BFD_ASSERT (strncmp (name, ".rela", 5) == 0
+                 BFD_ASSERT (CONST_STRNEQ (name, ".rela")
                              && strcmp (bfd_get_section_name (input_bfd,
                                                               input_section),
                                         name + 5) == 0);
@@ -6203,10 +6438,15 @@ ppc_elf_relocate_section (bfd *output_bfd,
                             but ld.so expects buggy relocs.  */
                          osec = sec->output_section;
                          indx = elf_section_data (osec)->dynindx;
-                         BFD_ASSERT (indx > 0);
+                         if (indx == 0)
+                           {
+                             osec = htab->elf.text_index_section;
+                             indx = elf_section_data (osec)->dynindx;
+                           }
+                         BFD_ASSERT (indx != 0);
 #ifdef DEBUG
-                         if (indx <= 0)
-                           printf ("indx=%d section=%s flags=%08x name=%s\n",
+                         if (indx == 0)
+                           printf ("indx=%ld section=%s flags=%08x name=%s\n",
                                    indx, osec->name, osec->flags,
                                    h->root.root.string);
 #endif
@@ -6241,7 +6481,7 @@ ppc_elf_relocate_section (bfd *output_bfd,
          {
            struct plt_entry *ent = find_plt_ent (h, got2, addend);
 
-           if (!htab->old_plt)
+           if (htab->plt_type == PLT_NEW)
              relocation = (htab->glink->output_section->vma
                            + htab->glink->output_offset
                            + ent->glink_offset);
@@ -6331,7 +6571,7 @@ ppc_elf_relocate_section (bfd *output_bfd,
              }
 
            unresolved_reloc = FALSE;
-           if (!htab->old_plt)
+           if (htab->plt_type == PLT_NEW)
              relocation = (htab->glink->output_section->vma
                            + htab->glink->output_offset
                            + ent->glink_offset);
@@ -6346,12 +6586,13 @@ ppc_elf_relocate_section (bfd *output_bfd,
        case R_PPC_SDAREL16:
          {
            const char *name;
+           struct elf_link_hash_entry *sh;
 
            BFD_ASSERT (sec != NULL);
            name = bfd_get_section_name (abfd, sec->output_section);
-           if (! ((strncmp (name, ".sdata", 6) == 0
+           if (! ((CONST_STRNEQ (name, ".sdata")
                    && (name[6] == 0 || name[6] == '.'))
-                  || (strncmp (name, ".sbss", 5) == 0
+                  || (CONST_STRNEQ (name, ".sbss")
                       && (name[5] == 0 || name[5] == '.'))))
              {
                (*_bfd_error_handler)
@@ -6362,7 +6603,10 @@ ppc_elf_relocate_section (bfd *output_bfd,
                   howto->name,
                   name);
              }
-           addend -= htab->sdata[0].sym_val;
+           sh = htab->sdata[0].sym;
+           addend -= (sh->root.u.def.value
+                      + sh->root.u.def.section->output_offset
+                      + sh->root.u.def.section->output_section->vma);
          }
          break;
 
@@ -6370,11 +6614,12 @@ ppc_elf_relocate_section (bfd *output_bfd,
        case R_PPC_EMB_SDA2REL:
          {
            const char *name;
+           struct elf_link_hash_entry *sh;
 
            BFD_ASSERT (sec != NULL);
            name = bfd_get_section_name (abfd, sec->output_section);
-           if (! (strncmp (name, ".sdata2", 7) == 0
-                  || strncmp (name, ".sbss2", 6) == 0))
+           if (! (CONST_STRNEQ (name, ".sdata2")
+                  || CONST_STRNEQ (name, ".sbss2")))
              {
                (*_bfd_error_handler)
                  (_("%B: the target (%s) of a %s relocation is "
@@ -6388,7 +6633,10 @@ ppc_elf_relocate_section (bfd *output_bfd,
                ret = FALSE;
                continue;
              }
-           addend -= htab->sdata[1].sym_val;
+           sh = htab->sdata[1].sym;
+           addend -= (sh->root.u.def.value
+                      + sh->root.u.def.section->output_offset
+                      + sh->root.u.def.section->output_section->vma);
          }
          break;
 
@@ -6398,23 +6646,30 @@ ppc_elf_relocate_section (bfd *output_bfd,
          {
            const char *name;
            int reg;
+           struct elf_link_hash_entry *sh;
 
            BFD_ASSERT (sec != NULL);
            name = bfd_get_section_name (abfd, sec->output_section);
-           if (((strncmp (name, ".sdata", 6) == 0
+           if (((CONST_STRNEQ (name, ".sdata")
                  && (name[6] == 0 || name[6] == '.'))
-                || (strncmp (name, ".sbss", 5) == 0
+                || (CONST_STRNEQ (name, ".sbss")
                     && (name[5] == 0 || name[5] == '.'))))
              {
                reg = 13;
-               addend -= htab->sdata[0].sym_val;
+               sh = htab->sdata[0].sym;
+               addend -= (sh->root.u.def.value
+                          + sh->root.u.def.section->output_offset
+                          + sh->root.u.def.section->output_section->vma);
              }
 
-           else if (strncmp (name, ".sdata2", 7) == 0
-                    || strncmp (name, ".sbss2", 6) == 0)
+           else if (CONST_STRNEQ (name, ".sdata2")
+                    || CONST_STRNEQ (name, ".sbss2"))
              {
                reg = 2;
-               addend -= htab->sdata[1].sym_val;
+               sh = htab->sdata[1].sym;
+               addend -= (sh->root.u.def.value
+                          + sh->root.u.def.section->output_offset
+                          + sh->root.u.def.section->output_section->vma);
              }
 
            else if (strcmp (name, ".PPC.EMB.sdata0") == 0
@@ -6499,25 +6754,28 @@ ppc_elf_relocate_section (bfd *output_bfd,
 
        case R_PPC_ADDR16_HA:
        case R_PPC_REL16_HA:
-       case R_PPC_GOT16_HA:
-       case R_PPC_PLT16_HA:
        case R_PPC_SECTOFF_HA:
        case R_PPC_TPREL16_HA:
        case R_PPC_DTPREL16_HA:
-       case R_PPC_GOT_TLSGD16_HA:
-       case R_PPC_GOT_TLSLD16_HA:
-       case R_PPC_GOT_TPREL16_HA:
-       case R_PPC_GOT_DTPREL16_HA:
        case R_PPC_EMB_NADDR16_HA:
        case R_PPC_EMB_RELST_HA:
          /* It's just possible that this symbol is a weak symbol
             that's not actually defined anywhere.  In that case,
             'sec' would be NULL, and we should leave the symbol
             alone (it will be set to zero elsewhere in the link).  */
-         if (sec != NULL)
-           /* Add 0x10000 if sign bit in 0:15 is set.
-              Bits 0:15 are not used.  */
-           addend += 0x8000;
+         if (sec == NULL)
+           break;
+         /* Fall thru */
+
+       case R_PPC_PLT16_HA:
+       case R_PPC_GOT16_HA:
+       case R_PPC_GOT_TLSGD16_HA:
+       case R_PPC_GOT_TLSLD16_HA:
+       case R_PPC_GOT_TPREL16_HA:
+       case R_PPC_GOT_DTPREL16_HA:
+         /* Add 0x10000 if sign bit in 0:15 is set.
+            Bits 0:15 are not used.  */
+         addend += 0x8000;
          break;
        }
 
@@ -6636,20 +6894,20 @@ ppc_elf_finish_dynamic_symbol (bfd *output_bfd,
            bfd_byte *loc;
            bfd_vma reloc_index;
 
-           if (!(htab->old_plt || htab->is_vxworks))
+           if (htab->plt_type == PLT_NEW)
              reloc_index = ent->plt.offset / 4;
            else
              {
                reloc_index = ((ent->plt.offset - htab->plt_initial_entry_size)
                               / htab->plt_slot_size);
                if (reloc_index > PLT_NUM_SINGLE_ENTRIES
-                   && !htab->is_vxworks)
+                   && htab->plt_type == PLT_OLD)
                  reloc_index -= (reloc_index - PLT_NUM_SINGLE_ENTRIES) / 2;
              }
 
            /* This symbol has an entry in the procedure linkage table.
               Set it up.  */
-           if (htab->is_vxworks)
+           if (htab->plt_type == PLT_VXWORKS)
              {
                bfd_vma got_offset;
                const bfd_vma *plt_entry;
@@ -6676,10 +6934,11 @@ ppc_elf_finish_dynamic_symbol (bfd *output_bfd,
                  }
                else
                  {
-                   bfd_vma got_loc = (got_offset
-                       + htab->hgot->root.u.def.value
-                       + htab->hgot->root.u.def.section->output_offset
-                       + htab->hgot->root.u.def.section->output_section->vma);
+                   bfd_vma got_loc
+                     = (got_offset
+                        + htab->elf.hgot->root.u.def.value
+                        + htab->elf.hgot->root.u.def.section->output_offset
+                        + htab->elf.hgot->root.u.def.section->output_section->vma);
                    bfd_vma got_loc_hi = (got_loc >> 16)
                                         + ((got_loc & 0x8000) >> 15);
 
@@ -6740,7 +6999,7 @@ ppc_elf_finish_dynamic_symbol (bfd *output_bfd,
                    rela.r_offset = (htab->plt->output_section->vma
                                     + htab->plt->output_offset
                                     + ent->plt.offset + 2);
-                   rela.r_info = ELF32_R_INFO (htab->hgot->indx,
+                   rela.r_info = ELF32_R_INFO (htab->elf.hgot->indx,
                                                R_PPC_ADDR16_HA);
                    rela.r_addend = got_offset;
                    bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
@@ -6750,7 +7009,7 @@ ppc_elf_finish_dynamic_symbol (bfd *output_bfd,
                    rela.r_offset = (htab->plt->output_section->vma
                                     + htab->plt->output_offset
                                     + ent->plt.offset + 6);
-                   rela.r_info = ELF32_R_INFO (htab->hgot->indx,
+                   rela.r_info = ELF32_R_INFO (htab->elf.hgot->indx,
                                                R_PPC_ADDR16_LO);
                    rela.r_addend = got_offset;
                    bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
@@ -6761,7 +7020,7 @@ ppc_elf_finish_dynamic_symbol (bfd *output_bfd,
                    rela.r_offset = (htab->sgotplt->output_section->vma
                                     + htab->sgotplt->output_offset
                                     + got_offset);
-                   rela.r_info = ELF32_R_INFO (htab->hplt->indx,
+                   rela.r_info = ELF32_R_INFO (htab->elf.hplt->indx,
                                                R_PPC_ADDR32);
                    rela.r_addend = ent->plt.offset + 16;
                    bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
@@ -6782,7 +7041,7 @@ ppc_elf_finish_dynamic_symbol (bfd *output_bfd,
                rela.r_offset = (htab->plt->output_section->vma
                                 + htab->plt->output_offset
                                 + ent->plt.offset);
-               if (htab->old_plt)
+               if (htab->plt_type == PLT_OLD)
                  {
                    /* We don't need to fill in the .plt.  The ppc dynamic
                       linker will fill it in.  */
@@ -6820,7 +7079,7 @@ ppc_elf_finish_dynamic_symbol (bfd *output_bfd,
            doneone = TRUE;
          }
 
-       if (!htab->old_plt)
+       if (htab->plt_type == PLT_NEW)
          {
            bfd_vma plt;
            unsigned char *p;
@@ -7041,8 +7300,8 @@ ppc_elf_finish_dynamic_sections (bfd *output_bfd,
       unsigned char *p = htab->got->contents;
       bfd_vma val;
 
-      p += elf_hash_table (info)->hgot->root.u.def.value;
-      if (htab->old_plt && !htab->is_vxworks)
+      p += htab->elf.hgot->root.u.def.value;
+      if (htab->plt_type == PLT_OLD)
        bfd_put_32 (output_bfd, 0x4e800021 /* blrl */, p - 4);
 
       val = 0;
@@ -7064,9 +7323,9 @@ ppc_elf_finish_dynamic_sections (bfd *output_bfd,
       if (!info->shared)
        {
          bfd_vma got_value =
-           (htab->hgot->root.u.def.section->output_section->vma
-            + htab->hgot->root.u.def.section->output_offset
-            + htab->hgot->root.u.def.value);
+           (htab->elf.hgot->root.u.def.section->output_section->vma
+            + htab->elf.hgot->root.u.def.section->output_offset
+            + htab->elf.hgot->root.u.def.value);
          bfd_vma got_hi = (got_value >> 16) + ((got_value & 0x8000) >> 15);
 
          bfd_put_32 (output_bfd, plt_entry[0] | (got_hi & 0xffff),
@@ -7097,7 +7356,7 @@ ppc_elf_finish_dynamic_sections (bfd *output_bfd,
          rela.r_offset = (htab->plt->output_section->vma
                           + htab->plt->output_offset
                           + 2);
-         rela.r_info = ELF32_R_INFO (htab->hgot->indx, R_PPC_ADDR16_HA);
+         rela.r_info = ELF32_R_INFO (htab->elf.hgot->indx, R_PPC_ADDR16_HA);
          rela.r_addend = 0;
          bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
          loc += sizeof (Elf32_External_Rela);
@@ -7106,7 +7365,7 @@ ppc_elf_finish_dynamic_sections (bfd *output_bfd,
          rela.r_offset = (htab->plt->output_section->vma
                           + htab->plt->output_offset
                           + 6);
-         rela.r_info = ELF32_R_INFO (htab->hgot->indx, R_PPC_ADDR16_LO);
+         rela.r_info = ELF32_R_INFO (htab->elf.hgot->indx, R_PPC_ADDR16_LO);
          rela.r_addend = 0;
          bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
          loc += sizeof (Elf32_External_Rela);
@@ -7119,17 +7378,17 @@ ppc_elf_finish_dynamic_sections (bfd *output_bfd,
              Elf_Internal_Rela rel;
 
              bfd_elf32_swap_reloc_in (output_bfd, loc, &rel);
-             rel.r_info = ELF32_R_INFO (htab->hgot->indx, R_PPC_ADDR16_HA);
+             rel.r_info = ELF32_R_INFO (htab->elf.hgot->indx, R_PPC_ADDR16_HA);
              bfd_elf32_swap_reloc_out (output_bfd, &rel, loc);
              loc += sizeof (Elf32_External_Rela);
 
              bfd_elf32_swap_reloc_in (output_bfd, loc, &rel);
-             rel.r_info = ELF32_R_INFO (htab->hgot->indx, R_PPC_ADDR16_LO);
+             rel.r_info = ELF32_R_INFO (htab->elf.hgot->indx, R_PPC_ADDR16_LO);
              bfd_elf32_swap_reloc_out (output_bfd, &rel, loc);
              loc += sizeof (Elf32_External_Rela);
 
              bfd_elf32_swap_reloc_in (output_bfd, loc, &rel);
-             rel.r_info = ELF32_R_INFO (htab->hplt->indx, R_PPC_ADDR32);
+             rel.r_info = ELF32_R_INFO (htab->elf.hplt->indx, R_PPC_ADDR32);
              bfd_elf32_swap_reloc_out (output_bfd, &rel, loc);
              loc += sizeof (Elf32_External_Rela);
            }
@@ -7329,6 +7588,7 @@ ppc_elf_finish_dynamic_sections (bfd *output_bfd,
 #define ELF_MAXPAGESIZE                0x10000
 #endif
 #define ELF_MINPAGESIZE                0x1000
+#define ELF_COMMONPAGESIZE     0x1000
 #define elf_info_to_howto      ppc_elf_info_to_howto
 
 #ifdef  EM_CYGNUS_POWERPC
@@ -7348,6 +7608,7 @@ ppc_elf_finish_dynamic_sections (bfd *output_bfd,
 #define bfd_elf32_bfd_merge_private_bfd_data   ppc_elf_merge_private_bfd_data
 #define bfd_elf32_bfd_relax_section            ppc_elf_relax_section
 #define bfd_elf32_bfd_reloc_type_lookup                ppc_elf_reloc_type_lookup
+#define bfd_elf32_bfd_reloc_name_lookup        ppc_elf_reloc_name_lookup
 #define bfd_elf32_bfd_set_private_flags                ppc_elf_set_private_flags
 #define bfd_elf32_bfd_link_hash_table_create   ppc_elf_link_hash_table_create
 
@@ -7368,12 +7629,15 @@ ppc_elf_finish_dynamic_sections (bfd *output_bfd,
 #define elf_backend_additional_program_headers ppc_elf_additional_program_headers
 #define elf_backend_grok_prstatus              ppc_elf_grok_prstatus
 #define elf_backend_grok_psinfo                        ppc_elf_grok_psinfo
+#define elf_backend_write_core_note            ppc_elf_write_core_note
 #define elf_backend_reloc_type_class           ppc_elf_reloc_type_class
 #define elf_backend_begin_write_processing     ppc_elf_begin_write_processing
 #define elf_backend_final_write_processing     ppc_elf_final_write_processing
 #define elf_backend_write_section              ppc_elf_write_section
 #define elf_backend_get_sec_type_attr          ppc_elf_get_sec_type_attr
 #define elf_backend_plt_sym_val                        ppc_elf_plt_sym_val
+#define elf_backend_action_discarded           ppc_elf_action_discarded
+#define elf_backend_init_index_section         _bfd_elf_init_1_index_section
 
 #include "elf32-target.h"
 
@@ -7413,6 +7677,7 @@ ppc_elf_vxworks_link_hash_table_create (bfd *abfd)
       struct ppc_elf_link_hash_table *htab
         = (struct ppc_elf_link_hash_table *)ret;
       htab->is_vxworks = 1;
+      htab->plt_type = PLT_VXWORKS;
       htab->plt_entry_size = VXWORKS_PLT_ENTRY_SIZE;
       htab->plt_slot_size = VXWORKS_PLT_ENTRY_SIZE;
       htab->plt_initial_entry_size = VXWORKS_PLT_INITIAL_ENTRY_SIZE;
@@ -7437,23 +7702,6 @@ ppc_elf_vxworks_add_symbol_hook (bfd *abfd,
   return ppc_elf_add_symbol_hook(abfd, info, sym,namep, flagsp, secp, valp);
 }
 
-/* Tweak magic VxWorks symbols as they are written to the output file.  */
-static bfd_boolean
-elf_i386_vxworks_link_output_symbol_hook (struct bfd_link_info *info
-                                          ATTRIBUTE_UNUSED,
-                                        const char *name,
-                                        Elf_Internal_Sym *sym,
-                                        asection *input_sec ATTRIBUTE_UNUSED,
-                                        struct elf_link_hash_entry *h
-                                          ATTRIBUTE_UNUSED)
-{
-  /* Ignore the first dummy symbol.  */
-  if (!name)
-    return TRUE;
-
-  return elf_vxworks_link_output_symbol_hook (name, sym);
-}
-
 static void
 ppc_elf_vxworks_final_write_processing (bfd *abfd, bfd_boolean linker)
 {
@@ -7484,7 +7732,7 @@ ppc_elf_vxworks_final_write_processing (bfd *abfd, bfd_boolean linker)
   ppc_elf_vxworks_add_symbol_hook
 #undef elf_backend_link_output_symbol_hook
 #define elf_backend_link_output_symbol_hook \
-  elf_i386_vxworks_link_output_symbol_hook
+  elf_vxworks_link_output_symbol_hook
 #undef elf_backend_final_write_processing
 #define elf_backend_final_write_processing \
   ppc_elf_vxworks_final_write_processing
This page took 0.060131 seconds and 4 git commands to generate.