* netbsd-core.c (netbsd_core_file_p): Make `i' unsigned.
[deliverable/binutils-gdb.git] / bfd / elf32-sparc.c
index dcdce31aef3f0926ed0cae46fbc1e6ed46e874a3..378f14db4ba08e8f7a32d57cf29e0fd14af72208 100644 (file)
@@ -1,22 +1,22 @@
 /* SPARC-specific support for 32-bit ELF
    Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
-   2003 Free Software Foundation, Inc.
+   2003, 2004 Free Software Foundation, Inc.
 
-This file is part of BFD, the Binary File Descriptor library.
+   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
-(at your option) any later version.
+   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
+   (at your option) any later version.
 
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
 
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 
 #include "bfd.h"
 #include "sysdep.h"
@@ -63,12 +63,12 @@ static struct bfd_hash_entry *link_hash_newfunc
   PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *));
 static struct bfd_link_hash_table *elf32_sparc_link_hash_table_create
   PARAMS ((bfd *));
-static bfd_boolean create_got_section PARAMS ((bfd *,
-                                              struct bfd_link_info *));
+static bfd_boolean create_got_section
+  PARAMS ((bfd *, struct bfd_link_info *));
 static bfd_boolean elf32_sparc_create_dynamic_sections
   PARAMS ((bfd *, struct bfd_link_info *));
 static void elf32_sparc_copy_indirect_symbol
-  PARAMS ((struct elf_backend_data *, struct elf_link_hash_entry *,
+  PARAMS ((const struct elf_backend_data *, struct elf_link_hash_entry *,
          struct elf_link_hash_entry *));
 static int elf32_sparc_tls_transition
   PARAMS ((struct bfd_link_info *, bfd *, int, int));
@@ -291,11 +291,14 @@ elf32_sparc_reloc_type_lookup (abfd, code)
       return &elf32_sparc_rev32_howto;
 
     default:
-      for (i = 0; i < sizeof (sparc_reloc_map) / sizeof (struct elf_reloc_map); i++)
-        {
-          if (sparc_reloc_map[i].bfd_reloc_val == code)
-           return &_bfd_sparc_elf_howto_table[(int) sparc_reloc_map[i].elf_reloc_val];
-        }
+      for (i = 0;
+          i < sizeof (sparc_reloc_map) / sizeof (struct elf_reloc_map);
+          i++)
+       {
+         if (sparc_reloc_map[i].bfd_reloc_val == code)
+           return (_bfd_sparc_elf_howto_table
+                   + (int) sparc_reloc_map[i].elf_reloc_val);
+       }
     }
     bfd_set_error (bfd_error_bad_value);
     return NULL;
@@ -384,7 +387,7 @@ sparc_elf_wdisp16_reloc (abfd,
   if (output_bfd != NULL)
     return bfd_reloc_continue;
 
-  if (reloc_entry->address > input_section->_cooked_size)
+  if (reloc_entry->address > bfd_get_section_limit (abfd, input_section))
     return bfd_reloc_outofrange;
 
   relocation = (symbol->value
@@ -438,7 +441,7 @@ sparc_elf_hix22_reloc (abfd,
   if (output_bfd != NULL)
     return bfd_reloc_continue;
 
-  if (reloc_entry->address > input_section->_cooked_size)
+  if (reloc_entry->address > bfd_get_section_limit (abfd, input_section))
     return bfd_reloc_outofrange;
 
   relocation = (symbol->value
@@ -484,7 +487,7 @@ sparc_elf_lox10_reloc (abfd,
   if (output_bfd != NULL)
     return bfd_reloc_continue;
 
-  if (reloc_entry->address > input_section->_cooked_size)
+  if (reloc_entry->address > bfd_get_section_limit (abfd, input_section))
     return bfd_reloc_outofrange;
 
   relocation = (symbol->value
@@ -498,6 +501,35 @@ sparc_elf_lox10_reloc (abfd,
 
   return bfd_reloc_ok;
 }
+\f
+/* Support for core dump NOTE sections.  */
+
+static bfd_boolean
+elf32_sparc_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
+{
+  switch (note->descsz)
+    {
+    default:
+      return FALSE;
+
+    case 260:                  /* Solaris prpsinfo_t.  */
+      elf_tdata (abfd)->core_program
+       = _bfd_elfcore_strndup (abfd, note->descdata + 84, 16);
+      elf_tdata (abfd)->core_command
+       = _bfd_elfcore_strndup (abfd, note->descdata + 100, 80);
+      break;
+
+    case 336:                  /* Solaris psinfo_t.  */
+      elf_tdata (abfd)->core_program
+       = _bfd_elfcore_strndup (abfd, note->descdata + 88, 16);
+      elf_tdata (abfd)->core_command
+       = _bfd_elfcore_strndup (abfd, note->descdata + 104, 80);
+      break;
+    }
+
+  return TRUE;
+}
+
 \f
 /* Functions for the SPARC ELF linker.  */
 
@@ -633,9 +665,9 @@ link_hash_newfunc (entry, table, string)
   if (entry == NULL)
     {
       entry = bfd_hash_allocate (table,
-                                 sizeof (struct elf32_sparc_link_hash_entry));
+                                sizeof (struct elf32_sparc_link_hash_entry));
       if (entry == NULL)
-        return entry;
+       return entry;
     }
 
   /* Call the allocation method of the superclass.  */
@@ -747,7 +779,7 @@ elf32_sparc_create_dynamic_sections (dynobj, info)
 
 static void
 elf32_sparc_copy_indirect_symbol (bed, dir, ind)
-     struct elf_backend_data *bed;
+     const struct elf_backend_data *bed;
      struct elf_link_hash_entry *dir, *ind;
 {
   struct elf32_sparc_link_hash_entry *edir, *eind;
@@ -758,32 +790,32 @@ elf32_sparc_copy_indirect_symbol (bed, dir, ind)
   if (eind->dyn_relocs != NULL)
     {
       if (edir->dyn_relocs != NULL)
-        {
-          struct elf32_sparc_dyn_relocs **pp;
-          struct elf32_sparc_dyn_relocs *p;
-
-          if (ind->root.type == bfd_link_hash_indirect)
-            abort ();
-
-          /* Add reloc counts against the weak sym to the strong sym
-             list.  Merge any entries against the same section.  */
-          for (pp = &eind->dyn_relocs; (p = *pp) != NULL; )
-            {
-              struct elf32_sparc_dyn_relocs *q;
-
-              for (q = edir->dyn_relocs; q != NULL; q = q->next)
-                if (q->sec == p->sec)
-                  {
-                    q->pc_count += p->pc_count;
-                    q->count += p->count;
-                    *pp = p->next;
-                    break;
-                  }
-              if (q == NULL)
-                pp = &p->next;
-            }
-          *pp = edir->dyn_relocs;
-        }
+       {
+         struct elf32_sparc_dyn_relocs **pp;
+         struct elf32_sparc_dyn_relocs *p;
+
+         if (ind->root.type == bfd_link_hash_indirect)
+           abort ();
+
+         /* Add reloc counts against the weak sym to the strong sym
+            list.  Merge any entries against the same section.  */
+         for (pp = &eind->dyn_relocs; (p = *pp) != NULL; )
+           {
+             struct elf32_sparc_dyn_relocs *q;
+
+             for (q = edir->dyn_relocs; q != NULL; q = q->next)
+               if (q->sec == p->sec)
+                 {
+                   q->pc_count += p->pc_count;
+                   q->count += p->count;
+                   *pp = p->next;
+                   break;
+                 }
+             if (q == NULL)
+               pp = &p->next;
+           }
+         *pp = edir->dyn_relocs;
+       }
 
       edir->dyn_relocs = eind->dyn_relocs;
       eind->dyn_relocs = NULL;
@@ -820,15 +852,15 @@ elf32_sparc_tls_transition (info, abfd, r_type, is_local)
       return R_SPARC_TLS_IE_HI22;
     case R_SPARC_TLS_GD_LO10:
       if (is_local)
-        return R_SPARC_TLS_LE_LOX10;
+       return R_SPARC_TLS_LE_LOX10;
       return R_SPARC_TLS_IE_LO10;
     case R_SPARC_TLS_IE_HI22:
       if (is_local)
-        return R_SPARC_TLS_LE_HIX22;
+       return R_SPARC_TLS_LE_HIX22;
       return r_type;
     case R_SPARC_TLS_IE_LO10:
       if (is_local)
-        return R_SPARC_TLS_LE_LOX10;
+       return R_SPARC_TLS_LE_LOX10;
       return r_type;
     case R_SPARC_TLS_LDM_HI22:
       return R_SPARC_TLS_LE_HIX22;
@@ -859,7 +891,7 @@ elf32_sparc_check_relocs (abfd, info, sec, relocs)
   asection *sreloc;
   bfd_boolean checked_tlsgd = FALSE;
 
-  if (info->relocateable)
+  if (info->relocatable)
     return TRUE;
 
   htab = elf32_sparc_hash_table (info);
@@ -880,12 +912,11 @@ elf32_sparc_check_relocs (abfd, info, sec, relocs)
       r_type = ELF32_R_TYPE (rel->r_info);
 
       if (r_symndx >= NUM_SHDR_ENTRIES (symtab_hdr))
-        {
-          (*_bfd_error_handler) (_("%s: bad symbol index: %d"),
-                                 bfd_archive_filename (abfd),
-                                 r_symndx);
-          return FALSE;
-        }
+       {
+         (*_bfd_error_handler) (_("%B: bad symbol index: %d"),
+                                abfd, r_symndx);
+         return FALSE;
+       }
 
       if (r_symndx < symtab_hdr->sh_info)
        h = NULL;
@@ -1005,9 +1036,8 @@ elf32_sparc_check_relocs (abfd, info, sec, relocs)
                else
                  {
                    (*_bfd_error_handler)
-                     (_("%s: `%s' accessed both as normal and thread local symbol"),
-                      bfd_archive_filename (abfd),
-                      h ? h->root.root.string : "<local>");
+                     (_("%B: `%s' accessed both as normal and thread local symbol"),
+                      abfd, h ? h->root.root.string : "<local>");
                    return FALSE;
                  }
              }
@@ -1021,10 +1051,13 @@ elf32_sparc_check_relocs (abfd, info, sec, relocs)
              }
          }
 
-         if (htab->elf.dynobj == NULL)
-           htab->elf.dynobj = abfd;
-         if (!create_got_section (htab->elf.dynobj, info))
-           return FALSE;
+         if (htab->sgot == NULL)
+           {
+             if (htab->elf.dynobj == NULL)
+               htab->elf.dynobj = abfd;
+             if (!create_got_section (htab->elf.dynobj, info))
+               return FALSE;
+           }
          break;
 
        case R_SPARC_TLS_GD_CALL:
@@ -1049,23 +1082,23 @@ elf32_sparc_check_relocs (abfd, info, sec, relocs)
        case R_SPARC_PLT32:
        case R_SPARC_WPLT30:
          /* This symbol requires a procedure linkage table entry.  We
-             actually build the entry in adjust_dynamic_symbol,
-             because this might be a case of linking PIC code without
-             linking in any dynamic objects, in which case we don't
-             need to generate a procedure linkage table after all.  */
+            actually build the entry in adjust_dynamic_symbol,
+            because this might be a case of linking PIC code without
+            linking in any dynamic objects, in which case we don't
+            need to generate a procedure linkage table after all.  */
 
          if (h == NULL)
            {
              /* The Solaris native assembler will generate a WPLT30
-                 reloc for a local symbol if you assemble a call from
-                 one section to another when using -K pic.  We treat
-                 it as WDISP30.  */
+                reloc for a local symbol if you assemble a call from
+                one section to another when using -K pic.  We treat
+                it as WDISP30.  */
              if (ELF32_R_TYPE (rel->r_info) == R_SPARC_PLT32)
                goto r_sparc_plt32;
              break;
            }
 
-         h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
+         h->needs_plt = 1;
 
          if (ELF32_R_TYPE (rel->r_info) == R_SPARC_PLT32)
            goto r_sparc_plt32;
@@ -1075,7 +1108,7 @@ elf32_sparc_check_relocs (abfd, info, sec, relocs)
        case R_SPARC_PC10:
        case R_SPARC_PC22:
          if (h != NULL)
-           h->elf_link_hash_flags |= ELF_LINK_NON_GOT_REF;
+           h->non_got_ref = 1;
 
          if (h != NULL
              && strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
@@ -1099,7 +1132,7 @@ elf32_sparc_check_relocs (abfd, info, sec, relocs)
        case R_SPARC_UA16:
        case R_SPARC_UA32:
          if (h != NULL)
-           h->elf_link_hash_flags |= ELF_LINK_NON_GOT_REF;
+           h->non_got_ref = 1;
 
        r_sparc_plt32:
          if (h != NULL && !info->shared)
@@ -1136,21 +1169,19 @@ elf32_sparc_check_relocs (abfd, info, sec, relocs)
                   || (h != NULL
                       && (! info->symbolic
                           || h->root.type == bfd_link_hash_defweak
-                          || (h->elf_link_hash_flags
-                              & ELF_LINK_HASH_DEF_REGULAR) == 0))))
+                          || !h->def_regular))))
              || (!info->shared
                  && (sec->flags & SEC_ALLOC) != 0
                  && h != NULL
                  && (h->root.type == bfd_link_hash_defweak
-                     || (h->elf_link_hash_flags
-                         & ELF_LINK_HASH_DEF_REGULAR) == 0)))
+                     || !h->def_regular)))
            {
              struct elf32_sparc_dyn_relocs *p;
              struct elf32_sparc_dyn_relocs **head;
 
              /* When creating a shared object, we must copy these
-                 relocs into the output file.  We create a reloc
-                 section in dynobj and make room for the reloc.  */
+                relocs into the output file.  We create a reloc
+                section in dynobj and make room for the reloc.  */
              if (sreloc == NULL)
                {
                  const char *name;
@@ -1231,15 +1262,15 @@ elf32_sparc_check_relocs (abfd, info, sec, relocs)
 
          break;
 
-        case R_SPARC_GNU_VTINHERIT:
-          if (!_bfd_elf32_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
-            return FALSE;
-          break;
+       case R_SPARC_GNU_VTINHERIT:
+         if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
+           return FALSE;
+         break;
 
-        case R_SPARC_GNU_VTENTRY:
-          if (!_bfd_elf32_gc_record_vtentry (abfd, sec, h, rel->r_addend))
-            return FALSE;
-          break;
+       case R_SPARC_GNU_VTENTRY:
+         if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
+           return FALSE;
+         break;
 
        default:
          break;
@@ -1263,21 +1294,21 @@ elf32_sparc_gc_mark_hook (sec, info, rel, h, sym)
       {
       case R_SPARC_GNU_VTINHERIT:
       case R_SPARC_GNU_VTENTRY:
-        break;
+       break;
 
       default:
-        switch (h->root.type)
-          {
-          case bfd_link_hash_defined:
-          case bfd_link_hash_defweak:
-            return h->root.u.def.section;
+       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;
+         case bfd_link_hash_common:
+           return h->root.u.c.p->section;
 
          default:
            break;
-          }
+         }
        }
      }
    else
@@ -1294,14 +1325,12 @@ elf32_sparc_gc_sweep_hook (abfd, info, sec, relocs)
      asection *sec;
      const Elf_Internal_Rela *relocs;
 {
-
   Elf_Internal_Shdr *symtab_hdr;
   struct elf_link_hash_entry **sym_hashes;
   bfd_signed_vma *local_got_refcounts;
   const Elf_Internal_Rela *rel, *relend;
-  unsigned long r_symndx;
-  int r_type;
-  struct elf_link_hash_entry *h;
+
+  elf_section_data (sec)->local_dynrel = NULL;
 
   symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
   sym_hashes = elf_sym_hashes (abfd);
@@ -1309,116 +1338,98 @@ elf32_sparc_gc_sweep_hook (abfd, info, sec, relocs)
 
   relend = relocs + sec->reloc_count;
   for (rel = relocs; rel < relend; rel++)
-    switch ((r_type = elf32_sparc_tls_transition (info, abfd,
-                                                 ELF32_R_TYPE (rel->r_info),
-                                                 ELF32_R_SYM (rel->r_info)
-                                                 >= symtab_hdr->sh_info)))
-      {
-      case R_SPARC_TLS_LDM_HI22:
-      case R_SPARC_TLS_LDM_LO10:
-       if (elf32_sparc_hash_table (info)->tls_ldm_got.refcount > 0)
-         elf32_sparc_hash_table (info)->tls_ldm_got.refcount -= 1;
-       break;
-
-      case R_SPARC_TLS_LE_HIX22:
-      case R_SPARC_TLS_LE_LOX10:
-       if (info->shared)
-         goto r_sparc_plt32;
-       break;
+    {
+      unsigned long r_symndx;
+      unsigned int r_type;
+      struct elf_link_hash_entry *h = NULL;
 
-      case R_SPARC_PC10:
-      case R_SPARC_PC22:
-         if ((r_symndx = ELF32_R_SYM (rel->r_info)) >= symtab_hdr->sh_info
-             && strcmp (sym_hashes[r_symndx
-                                   - symtab_hdr->sh_info]->root.root.string,
-                                   "_GLOBAL_OFFSET_TABLE_") == 0)
-           break;
-         /* Fall through.  */
+      r_symndx = ELF32_R_SYM (rel->r_info);
+      if (r_symndx >= symtab_hdr->sh_info)
+       {
+         struct elf32_sparc_link_hash_entry *eh;
+         struct elf32_sparc_dyn_relocs **pp;
+         struct elf32_sparc_dyn_relocs *p;
 
-      case R_SPARC_DISP8:
-      case R_SPARC_DISP16:
-      case R_SPARC_DISP32:
-      case R_SPARC_WDISP30:
-      case R_SPARC_WDISP22:
-      case R_SPARC_WDISP19:
-      case R_SPARC_WDISP16:
-      case R_SPARC_8:
-      case R_SPARC_16:
-      case R_SPARC_32:
-      case R_SPARC_HI22:
-      case R_SPARC_22:
-      case R_SPARC_13:
-      case R_SPARC_LO10:
-      case R_SPARC_UA16:
-      case R_SPARC_UA32:
-      r_sparc_plt32:
-       r_symndx = ELF32_R_SYM (rel->r_info);
-       if (r_symndx >= symtab_hdr->sh_info)
-         {
-           struct elf32_sparc_link_hash_entry *eh;
-           struct elf32_sparc_dyn_relocs **pp;
-           struct elf32_sparc_dyn_relocs *p;
+         h = sym_hashes[r_symndx - symtab_hdr->sh_info];
+         eh = (struct elf32_sparc_link_hash_entry *) h;
+         for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next)
+           if (p->sec == sec)
+             {
+               /* Everything must go for SEC.  */
+               *pp = p->next;
+               break;
+             }
+       }
 
-           h = sym_hashes[r_symndx - symtab_hdr->sh_info];
+      r_type = ELF32_R_TYPE (rel->r_info);
+      r_type = elf32_sparc_tls_transition (info, abfd, r_type, h != NULL);
+      switch (r_type)
+       {
+       case R_SPARC_TLS_LDM_HI22:
+       case R_SPARC_TLS_LDM_LO10:
+         if (elf32_sparc_hash_table (info)->tls_ldm_got.refcount > 0)
+           elf32_sparc_hash_table (info)->tls_ldm_got.refcount -= 1;
+         break;
 
-           if (! info->shared)
-             --h->plt.refcount;
+       case R_SPARC_TLS_GD_HI22:
+       case R_SPARC_TLS_GD_LO10:
+       case R_SPARC_TLS_IE_HI22:
+       case R_SPARC_TLS_IE_LO10:
+       case R_SPARC_GOT10:
+       case R_SPARC_GOT13:
+       case R_SPARC_GOT22:
+         if (h != NULL)
+           {
+             if (h->got.refcount > 0)
+               h->got.refcount--;
+           }
+         else
+           {
+             if (local_got_refcounts[r_symndx] > 0)
+               local_got_refcounts[r_symndx]--;
+           }
+         break;
 
-           eh = (struct elf32_sparc_link_hash_entry *) h;
+       case R_SPARC_PC10:
+       case R_SPARC_PC22:
+         if (h != NULL
+             && strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
+           break;
+         /* Fall through.  */
 
-           for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next)
-             if (p->sec == sec)
-               {
-                 if (_bfd_sparc_elf_howto_table[r_type].pc_relative)
-                   p->pc_count -= 1;
-                 p->count -= 1;
-                 if (p->count == 0)
-                   *pp = p->next;
-                 break;
-               }
-         }
-       break;
+       case R_SPARC_DISP8:
+       case R_SPARC_DISP16:
+       case R_SPARC_DISP32:
+       case R_SPARC_WDISP30:
+       case R_SPARC_WDISP22:
+       case R_SPARC_WDISP19:
+       case R_SPARC_WDISP16:
+       case R_SPARC_8:
+       case R_SPARC_16:
+       case R_SPARC_32:
+       case R_SPARC_HI22:
+       case R_SPARC_22:
+       case R_SPARC_13:
+       case R_SPARC_LO10:
+       case R_SPARC_UA16:
+       case R_SPARC_UA32:
+       case R_SPARC_PLT32:
+         if (info->shared)
+           break;
+         /* Fall through.  */
 
-      case R_SPARC_TLS_GD_HI22:
-      case R_SPARC_TLS_GD_LO10:
-      case R_SPARC_TLS_IE_HI22:
-      case R_SPARC_TLS_IE_LO10:
-      case R_SPARC_GOT10:
-      case R_SPARC_GOT13:
-      case R_SPARC_GOT22:
-       r_symndx = ELF32_R_SYM (rel->r_info);
-       if (r_symndx >= symtab_hdr->sh_info)
-         {
-           h = sym_hashes[r_symndx - symtab_hdr->sh_info];
-           if (h->got.refcount > 0)
-             h->got.refcount--;
-         }
-       else
-         {
-           if (local_got_refcounts[r_symndx] > 0)
-             local_got_refcounts[r_symndx]--;
-         }
-        break;
-
-      case R_SPARC_PLT32:
-      case R_SPARC_HIPLT22:
-      case R_SPARC_LOPLT10:
-      case R_SPARC_PCPLT32:
-      case R_SPARC_PCPLT10:
-       r_symndx = ELF32_R_SYM (rel->r_info);
-       if (r_symndx >= symtab_hdr->sh_info)
-         {
-           h = sym_hashes[r_symndx - symtab_hdr->sh_info];
-           if (h->plt.refcount > 0)
-             h->plt.refcount--;
-         }
-       if (r_type == R_SPARC_PLT32)
-         goto r_sparc_plt32;
-       break;
+       case R_SPARC_WPLT30:
+         if (h != NULL)
+           {
+             if (h->plt.refcount > 0)
+               h->plt.refcount--;
+           }
+         break;
 
-      default:
-       break;
-      }
+       default:
+         break;
+       }
+    }
 
   return TRUE;
 }
@@ -1444,14 +1455,11 @@ elf32_sparc_adjust_dynamic_symbol (info, h)
 
   /* Make sure we know what is going on here.  */
   BFD_ASSERT (htab->elf.dynobj != NULL
-             && ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT)
-                 || h->weakdef != NULL
-                 || ((h->elf_link_hash_flags
-                      & ELF_LINK_HASH_DEF_DYNAMIC) != 0
-                     && (h->elf_link_hash_flags
-                         & ELF_LINK_HASH_REF_REGULAR) != 0
-                     && (h->elf_link_hash_flags
-                         & ELF_LINK_HASH_DEF_REGULAR) == 0)));
+             && (h->needs_plt
+                 || h->u.weakdef != NULL
+                 || (h->def_dynamic
+                     && h->ref_regular
+                     && !h->def_regular)));
 
   /* If this is a function, put it in the procedure linkage table.  We
      will fill in the contents of the procedure linkage table later
@@ -1461,7 +1469,7 @@ elf32_sparc_adjust_dynamic_symbol (info, h)
      some of their functions as STT_NOTYPE when they really should be
      STT_FUNC.  */
   if (h->type == STT_FUNC
-      || (h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0
+      || h->needs_plt
       || (h->type == STT_NOTYPE
          && (h->root.type == bfd_link_hash_defined
              || h->root.type == bfd_link_hash_defweak)
@@ -1469,8 +1477,8 @@ elf32_sparc_adjust_dynamic_symbol (info, h)
     {
       if (h->plt.refcount <= 0
          || (! info->shared
-             && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) == 0
-             && (h->elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) == 0
+             && !h->def_dynamic
+             && !h->ref_dynamic
              && h->root.type != bfd_link_hash_undefweak
              && h->root.type != bfd_link_hash_undefined))
        {
@@ -1480,7 +1488,7 @@ elf32_sparc_adjust_dynamic_symbol (info, h)
             such a case, we don't actually need to build a procedure
             linkage table, and we can just do a WDISP30 reloc instead.  */
          h->plt.offset = (bfd_vma) -1;
-         h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
+         h->needs_plt = 0;
        }
 
       return TRUE;
@@ -1491,12 +1499,12 @@ elf32_sparc_adjust_dynamic_symbol (info, h)
   /* If this is a weak symbol, and there is a real definition, the
      processor independent code will have arranged for us to see the
      real definition first, and we can just use the same value.  */
-  if (h->weakdef != NULL)
+  if (h->u.weakdef != NULL)
     {
-      BFD_ASSERT (h->weakdef->root.type == bfd_link_hash_defined
-                 || h->weakdef->root.type == bfd_link_hash_defweak);
-      h->root.u.def.section = h->weakdef->root.u.def.section;
-      h->root.u.def.value = h->weakdef->root.u.def.value;
+      BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
+                 || h->u.weakdef->root.type == bfd_link_hash_defweak);
+      h->root.u.def.section = h->u.weakdef->root.u.def.section;
+      h->root.u.def.value = h->u.weakdef->root.u.def.value;
       return TRUE;
     }
 
@@ -1512,7 +1520,7 @@ elf32_sparc_adjust_dynamic_symbol (info, h)
 
   /* If there are no references to this symbol that do not use the
      GOT, we don't need to generate a copy reloc.  */
-  if ((h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0)
+  if (!h->non_got_ref)
     return TRUE;
 
   eh = (struct elf32_sparc_link_hash_entry *) h;
@@ -1527,7 +1535,7 @@ elf32_sparc_adjust_dynamic_symbol (info, h)
      we'll be keeping the dynamic relocs and avoiding the copy reloc.  */
   if (p == NULL)
     {
-      h->elf_link_hash_flags &= ~ELF_LINK_NON_GOT_REF;
+      h->non_got_ref = 0;
       return TRUE;
     }
 
@@ -1547,8 +1555,8 @@ elf32_sparc_adjust_dynamic_symbol (info, h)
      .rel.bss section we are going to use.  */
   if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
     {
-      htab->srelbss->_raw_size += sizeof (Elf32_External_Rela);
-      h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_COPY;
+      htab->srelbss->size += sizeof (Elf32_External_Rela);
+      h->needs_copy = 1;
     }
 
   /* We need to figure out the alignment required for this symbol.  I
@@ -1559,8 +1567,7 @@ elf32_sparc_adjust_dynamic_symbol (info, h)
 
   /* Apply the required alignment.  */
   s = htab->sdynbss;
-  s->_raw_size = BFD_ALIGN (s->_raw_size,
-                           (bfd_size_type) (1 << power_of_two));
+  s->size = BFD_ALIGN (s->size, (bfd_size_type) (1 << power_of_two));
   if (power_of_two > bfd_get_section_alignment (dynobj, s))
     {
       if (! bfd_set_section_alignment (dynobj, s, power_of_two))
@@ -1569,25 +1576,14 @@ elf32_sparc_adjust_dynamic_symbol (info, h)
 
   /* Define the symbol as being at this point in the section.  */
   h->root.u.def.section = s;
-  h->root.u.def.value = s->_raw_size;
+  h->root.u.def.value = s->size;
 
   /* Increment the section size to make room for the symbol.  */
-  s->_raw_size += h->size;
+  s->size += h->size;
 
   return TRUE;
 }
 
-/* This is the condition under which finish_dynamic_symbol will be called
-   from elflink.h.  If elflink.h doesn't call our finish_dynamic_symbol
-   routine, we'll need to do something about initializing any .plt and .got
-   entries in relocate_section.  */
-#define WILL_CALL_FINISH_DYNAMIC_SYMBOL(DYN, INFO, H)                  \
-  ((DYN)                                                               \
-   && ((INFO)->shared                                                  \
-       || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0)     \
-   && ((H)->dynindx != -1                                              \
-       || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0))
-
 /* Allocate space in .plt, .got and associated reloc sections for
    dynamic relocs.  */
 
@@ -1619,28 +1615,28 @@ allocate_dynrelocs (h, inf)
       /* Make sure this symbol is output as a dynamic symbol.
         Undefined weak syms won't yet be marked as dynamic.  */
       if (h->dynindx == -1
-         && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0)
+         && !h->forced_local)
        {
-         if (! bfd_elf32_link_record_dynamic_symbol (info, h))
+         if (! bfd_elf_link_record_dynamic_symbol (info, h))
            return FALSE;
        }
 
-      if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, info, h))
+      if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, info->shared, h))
        {
          asection *s = htab->splt;
 
          /* The first four entries in .plt are reserved.  */
-         if (s->_raw_size == 0)
-           s->_raw_size = 4 * PLT_ENTRY_SIZE;
-                    
+         if (s->size == 0)
+           s->size = 4 * PLT_ENTRY_SIZE;
+
          /* The procedure linkage table has a maximum size.  */
-         if (s->_raw_size >= 0x400000)
+         if (s->size >= 0x400000)
            {
              bfd_set_error (bfd_error_bad_value);
              return FALSE;
            }
 
-         h->plt.offset = s->_raw_size;
+         h->plt.offset = s->size;
 
          /* If this symbol is not defined in a regular file, and we are
             not generating a shared library, then set the symbol to this
@@ -1648,28 +1644,28 @@ allocate_dynrelocs (h, inf)
             pointers compare as equal between the normal executable and
             the shared library.  */
          if (! info->shared
-             && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
+             && !h->def_regular)
            {
              h->root.u.def.section = s;
              h->root.u.def.value = h->plt.offset;
            }
 
          /* Make room for this entry.  */
-         s->_raw_size += PLT_ENTRY_SIZE;
+         s->size += PLT_ENTRY_SIZE;
 
          /* We also need to make an entry in the .rela.plt section.  */
-         htab->srelplt->_raw_size += sizeof (Elf32_External_Rela);
+         htab->srelplt->size += sizeof (Elf32_External_Rela);
        }
       else
        {
          h->plt.offset = (bfd_vma) -1;
-         h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
+         h->needs_plt = 0;
        }
     }
   else
     {
       h->plt.offset = (bfd_vma) -1;
-      h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
+      h->needs_plt = 0;
     }
 
   /* If R_SPARC_TLS_IE_{HI22,LO10} symbol is now local to the binary,
@@ -1688,29 +1684,29 @@ allocate_dynrelocs (h, inf)
       /* Make sure this symbol is output as a dynamic symbol.
         Undefined weak syms won't yet be marked as dynamic.  */
       if (h->dynindx == -1
-         && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0)
+         && !h->forced_local)
        {
-         if (! bfd_elf32_link_record_dynamic_symbol (info, h))
+         if (! bfd_elf_link_record_dynamic_symbol (info, h))
            return FALSE;
        }
 
       s = htab->sgot;
-      h->got.offset = s->_raw_size;
-      s->_raw_size += 4;
+      h->got.offset = s->size;
+      s->size += 4;
       /* R_SPARC_TLS_GD_HI{22,LO10} needs 2 consecutive GOT slots.  */
       if (tls_type == GOT_TLS_GD)
-       s->_raw_size += 4;
+       s->size += 4;
       dyn = htab->elf.dynamic_sections_created;
       /* R_SPARC_TLS_IE_{HI22,LO10} needs one dynamic relocation,
         R_SPARC_TLS_GD_{HI22,LO10} needs one if local symbol and two if
         global.  */
       if ((tls_type == GOT_TLS_GD && h->dynindx == -1)
          || tls_type == GOT_TLS_IE)
-       htab->srelgot->_raw_size += sizeof (Elf32_External_Rela);
+       htab->srelgot->size += sizeof (Elf32_External_Rela);
       else if (tls_type == GOT_TLS_GD)
-       htab->srelgot->_raw_size += 2 * sizeof (Elf32_External_Rela);
-      else if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info, h))
-       htab->srelgot->_raw_size += sizeof (Elf32_External_Rela);
+       htab->srelgot->size += 2 * sizeof (Elf32_External_Rela);
+      else if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h))
+       htab->srelgot->size += sizeof (Elf32_External_Rela);
     }
   else
     h->got.offset = (bfd_vma) -1;
@@ -1727,8 +1723,8 @@ allocate_dynrelocs (h, inf)
 
   if (info->shared)
     {
-      if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) != 0
-         && ((h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0
+      if (h->def_regular
+         && (h->forced_local
              || info->symbolic))
        {
          struct elf32_sparc_dyn_relocs **pp;
@@ -1750,9 +1746,9 @@ allocate_dynrelocs (h, inf)
         symbols which turn out to need copy relocs or are not
         dynamic.  */
 
-      if ((h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0
-         && (((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0
-              && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
+      if (!h->non_got_ref
+         && ((h->def_dynamic
+              && !h->def_regular)
              || (htab->elf.dynamic_sections_created
                  && (h->root.type == bfd_link_hash_undefweak
                      || h->root.type == bfd_link_hash_undefined))))
@@ -1760,9 +1756,9 @@ allocate_dynrelocs (h, inf)
          /* Make sure this symbol is output as a dynamic symbol.
             Undefined weak syms won't yet be marked as dynamic.  */
          if (h->dynindx == -1
-             && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0)
+             && !h->forced_local)
            {
-             if (! bfd_elf32_link_record_dynamic_symbol (info, h))
+             if (! bfd_elf_link_record_dynamic_symbol (info, h))
                return FALSE;
            }
 
@@ -1781,7 +1777,7 @@ allocate_dynrelocs (h, inf)
   for (p = eh->dyn_relocs; p != NULL; p = p->next)
     {
       asection *sreloc = elf_section_data (p->sec)->sreloc;
-      sreloc->_raw_size += p->count * sizeof (Elf32_External_Rela);
+      sreloc->size += p->count * sizeof (Elf32_External_Rela);
     }
 
   return TRUE;
@@ -1837,11 +1833,11 @@ elf32_sparc_size_dynamic_sections (output_bfd, info)
   if (elf_hash_table (info)->dynamic_sections_created)
     {
       /* Set the contents of the .interp section to the interpreter.  */
-      if (! info->shared)
+      if (info->executable)
        {
          s = bfd_get_section_by_name (dynobj, ".interp");
          BFD_ASSERT (s != NULL);
-         s->_raw_size = sizeof ELF_DYNAMIC_INTERPRETER;
+         s->size = sizeof ELF_DYNAMIC_INTERPRETER;
          s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
        }
     }
@@ -1880,7 +1876,7 @@ elf32_sparc_size_dynamic_sections (output_bfd, info)
              else if (p->count != 0)
                {
                  srel = elf_section_data (p->sec)->sreloc;
-                 srel->_raw_size += p->count * sizeof (Elf32_External_Rela);
+                 srel->size += p->count * sizeof (Elf32_External_Rela);
                  if ((p->sec->output_section->flags & SEC_READONLY) != 0)
                    info->flags |= DF_TEXTREL;
                }
@@ -1901,14 +1897,14 @@ elf32_sparc_size_dynamic_sections (output_bfd, info)
        {
          if (*local_got > 0)
            {
-             *local_got = s->_raw_size;
-             s->_raw_size += 4;
+             *local_got = s->size;
+             s->size += 4;
              if (*local_tls_type == GOT_TLS_GD)
-               s->_raw_size += 4;
+               s->size += 4;
              if (info->shared
                  || *local_tls_type == GOT_TLS_GD
                  || *local_tls_type == GOT_TLS_IE)
-               srel->_raw_size += sizeof (Elf32_External_Rela);
+               srel->size += sizeof (Elf32_External_Rela);
            }
          else
            *local_got = (bfd_vma) -1;
@@ -1919,9 +1915,9 @@ elf32_sparc_size_dynamic_sections (output_bfd, info)
     {
       /* Allocate 2 got entries and 1 dynamic reloc for
         R_SPARC_TLS_LDM_{HI22,LO10} relocs.  */
-      htab->tls_ldm_got.offset = htab->sgot->_raw_size;
-      htab->sgot->_raw_size += 8;
-      htab->srelgot->_raw_size += sizeof (Elf32_External_Rela);
+      htab->tls_ldm_got.offset = htab->sgot->size;
+      htab->sgot->size += 8;
+      htab->srelgot->size += sizeof (Elf32_External_Rela);
     }
   else
     htab->tls_ldm_got.offset = -1;
@@ -1933,13 +1929,13 @@ elf32_sparc_size_dynamic_sections (output_bfd, info)
   if (elf_hash_table (info)->dynamic_sections_created)
     {
       /* Make space for the trailing nop in .plt.  */
-      if (htab->splt->_raw_size > 0)
-       htab->splt->_raw_size += 4;
+      if (htab->splt->size > 0)
+       htab->splt->size += 4;
 
       /* If the .got section is more than 0x1000 bytes, we add
         0x1000 to the value of _GLOBAL_OFFSET_TABLE_, so that 13
         bit relocations have a greater chance of working.  */
-      if (htab->sgot->_raw_size >= 0x1000
+      if (htab->sgot->size >= 0x1000
          && elf_hash_table (info)->hgot->root.u.def.value == 0)
        elf_hash_table (info)->hgot->root.u.def.value = 0x1000;
     }
@@ -1961,7 +1957,7 @@ elf32_sparc_size_dynamic_sections (output_bfd, info)
 
       if (strncmp (name, ".rela", 5) == 0)
        {
-         if (s->_raw_size == 0)
+         if (s->size == 0)
            {
              /* If we don't need this section, strip it from the
                 output file.  This is to handle .rela.bss and
@@ -1999,8 +1995,8 @@ elf32_sparc_size_dynamic_sections (output_bfd, info)
         are written out, but at the moment this does not happen.  Thus in
         order to prevent writing out garbage, we initialise the section's
         contents to zero.  */
-      s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->_raw_size);
-      if (s->contents == NULL && s->_raw_size != 0)
+      s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
+      if (s->contents == NULL && s->size != 0)
        return FALSE;
     }
 
@@ -2012,15 +2008,15 @@ elf32_sparc_size_dynamic_sections (output_bfd, info)
         the .dynamic section.  The DT_DEBUG entry is filled in by the
         dynamic linker and used by the debugger.  */
 #define add_dynamic_entry(TAG, VAL) \
-  bfd_elf32_add_dynamic_entry (info, (bfd_vma) (TAG), (bfd_vma) (VAL))
+  _bfd_elf_add_dynamic_entry (info, TAG, VAL)
 
-      if (!info->shared)
+      if (info->executable)
        {
          if (!add_dynamic_entry (DT_DEBUG, 0))
            return FALSE;
        }
 
-      if (htab->srelplt->_raw_size != 0)
+      if (htab->srelplt->size != 0)
        {
          if (!add_dynamic_entry (DT_PLTGOT, 0)
              || !add_dynamic_entry (DT_PLTRELSZ, 0)
@@ -2058,7 +2054,7 @@ struct elf32_sparc_section_data
 };
 
 #define sec_do_relax(sec) \
-  ((struct elf32_sparc_section_data *) (sec)->used_by_bfd)->do_relax
+  ((struct elf32_sparc_section_data *) elf_section_data (sec))->do_relax
 
 static bfd_boolean
 elf32_sparc_new_section_hook (abfd, sec)
@@ -2096,10 +2092,10 @@ static bfd_vma
 dtpoff_base (info)
      struct bfd_link_info *info;
 {
-  /* If tls_segment is NULL, we should have signalled an error already.  */
-  if (elf_hash_table (info)->tls_segment == NULL)
+  /* If tls_sec is NULL, we should have signalled an error already.  */
+  if (elf_hash_table (info)->tls_sec == NULL)
     return 0;
-  return elf_hash_table (info)->tls_segment->start;
+  return elf_hash_table (info)->tls_sec->vma;
 }
 
 /* Return the relocation value for @tpoff relocation
@@ -2110,14 +2106,12 @@ tpoff (info, address)
      struct bfd_link_info *info;
      bfd_vma address;
 {
-  struct elf_link_tls_segment *tls_segment
-    = elf_hash_table (info)->tls_segment;
+  struct elf_link_hash_table *htab = elf_hash_table (info);
 
-  /* If tls_segment is NULL, we should have signalled an error already.  */
-  if (tls_segment == NULL)
+  /* If tls_sec is NULL, we should have signalled an error already.  */
+  if (htab->tls_sec == NULL)
     return 0;
-  return -(align_power (tls_segment->size, tls_segment->align)
-          + tls_segment->start - address);
+  return address - htab->tls_size - htab->tls_sec->vma;
 }
 
 /* Relocate a SPARC ELF section.  */
@@ -2143,7 +2137,7 @@ elf32_sparc_relocate_section (output_bfd, info, input_bfd, input_section,
   Elf_Internal_Rela *rel;
   Elf_Internal_Rela *relend;
 
-  if (info->relocateable)
+  if (info->relocatable)
     return TRUE;
 
   htab = elf32_sparc_hash_table (info);
@@ -2176,8 +2170,8 @@ elf32_sparc_relocate_section (output_bfd, info, input_bfd, input_section,
       r_type = ELF32_R_TYPE (rel->r_info);
 
       if (r_type == R_SPARC_GNU_VTINHERIT
-          || r_type == R_SPARC_GNU_VTENTRY)
-        continue;
+         || r_type == R_SPARC_GNU_VTENTRY)
+       continue;
 
       if (r_type < 0 || r_type >= (int) R_SPARC_max_std)
        {
@@ -2196,47 +2190,16 @@ elf32_sparc_relocate_section (output_bfd, info, input_bfd, input_section,
        {
          sym = local_syms + r_symndx;
          sec = local_sections[r_symndx];
-         relocation = _bfd_elf_rela_local_sym (output_bfd, sym, sec, rel);
+         relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
        }
       else
        {
-         h = sym_hashes[r_symndx - symtab_hdr->sh_info];
-         while (h->root.type == bfd_link_hash_indirect
-                || h->root.type == bfd_link_hash_warning)
-           h = (struct elf_link_hash_entry *) h->root.u.i.link;
+         bfd_boolean warned ATTRIBUTE_UNUSED;
 
-         relocation = 0;
-         if (h->root.type == bfd_link_hash_defined
-             || h->root.type == bfd_link_hash_defweak)
-           {
-             sec = h->root.u.def.section;
-             if (sec->output_section == NULL)
-                /* Set a flag that will be cleared later if we find a
-                  relocation value for this symbol.  output_section
-                  is typically NULL for symbols satisfied by a shared
-                  library.  */
-               unresolved_reloc = TRUE;
-             else
-               relocation = (h->root.u.def.value
-                             + sec->output_section->vma
-                             + sec->output_offset);
-           }
-         else if (h->root.type == bfd_link_hash_undefweak)
-           ;
-         else if (info->shared
-                  && (!info->symbolic || info->allow_shlib_undefined)
-                  && !info->no_undefined
-                  && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
-           ;
-         else
-           {
-             if (! ((*info->callbacks->undefined_symbol)
-                    (info, h->root.root.string, input_bfd,
-                     input_section, rel->r_offset,
-                     (!info->shared || info->no_undefined
-                      || ELF_ST_VISIBILITY (h->other)))))
-               return FALSE;
-           }
+         RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
+                                  r_symndx, symtab_hdr, sym_hashes,
+                                  h, sec, relocation,
+                                  unresolved_reloc, warned);
        }
 
       switch (r_type)
@@ -2245,7 +2208,7 @@ elf32_sparc_relocate_section (output_bfd, info, input_bfd, input_section,
        case R_SPARC_GOT13:
        case R_SPARC_GOT22:
          /* Relocation is to the entry for this symbol in the global
-             offset table.  */
+            offset table.  */
          if (htab->sgot == NULL)
            abort ();
 
@@ -2257,21 +2220,21 @@ elf32_sparc_relocate_section (output_bfd, info, input_bfd, input_section,
              BFD_ASSERT (off != (bfd_vma) -1);
              dyn = elf_hash_table (info)->dynamic_sections_created;
 
-             if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info, h)
+             if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
                  || (info->shared
                      && (info->symbolic
                          || h->dynindx == -1
-                         || (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL))
-                     && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR)))
+                         || h->forced_local)
+                     && h->def_regular))
                {
                  /* This is actually a static link, or it is a
-                     -Bsymbolic link and the symbol is defined
-                     locally, or the symbol was forced to be local
-                     because of a version file.  We must initialize
-                     this entry in the global offset table.  Since the
-                     offset must always be a multiple of 4, we use the
-                     least significant bit to record whether we have
-                     initialized it already.
+                    -Bsymbolic link and the symbol is defined
+                    locally, or the symbol was forced to be local
+                    because of a version file.  We must initialize
+                    this entry in the global offset table.  Since the
+                    offset must always be a multiple of 4, we use the
+                    least significant bit to record whether we have
+                    initialized it already.
 
                     When doing a dynamic link, we create a .rela.got
                     relocation entry to initialize the value.  This
@@ -2343,7 +2306,7 @@ elf32_sparc_relocate_section (output_bfd, info, input_bfd, input_section,
        case R_SPARC_WPLT30:
        r_sparc_wplt30:
          /* Relocation is to the entry for this symbol in the
-             procedure linkage table.  */
+            procedure linkage table.  */
 
          /* The Solaris native assembler will generate a WPLT30 reloc
             for a local symbol if you assemble a call from one
@@ -2352,17 +2315,14 @@ elf32_sparc_relocate_section (output_bfd, info, input_bfd, input_section,
          if (h == NULL)
            break;
 
-         if (h->plt.offset == (bfd_vma) -1)
+         if (h->plt.offset == (bfd_vma) -1 || htab->splt == NULL)
            {
              /* We didn't make a PLT entry for this symbol.  This
-                 happens when statically linking PIC code, or when
-                 using -Bsymbolic.  */
+                happens when statically linking PIC code, or when
+                using -Bsymbolic.  */
              break;
            }
 
-         if (htab->splt == NULL)
-           abort ();
-
          relocation = (htab->splt->output_section->vma
                        + htab->splt->output_offset
                        + h->plt.offset);
@@ -2406,20 +2366,20 @@ elf32_sparc_relocate_section (output_bfd, info, input_bfd, input_section,
            break;
 
          if ((info->shared
+              && (h == NULL
+                  || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
+                  || h->root.type != bfd_link_hash_undefweak)
               && (! howto->pc_relative
                   || (h != NULL
                       && h->dynindx != -1
                       && (! info->symbolic
-                          || (h->elf_link_hash_flags
-                              & ELF_LINK_HASH_DEF_REGULAR) == 0))))
+                          || !h->def_regular))))
              || (!info->shared
                  && h != NULL
                  && h->dynindx != -1
-                 && (h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0
-                 && (((h->elf_link_hash_flags
-                       & ELF_LINK_HASH_DEF_DYNAMIC) != 0
-                      && (h->elf_link_hash_flags
-                          & ELF_LINK_HASH_DEF_REGULAR) == 0)
+                 && !h->non_got_ref
+                 && ((h->def_dynamic
+                      && !h->def_regular)
                      || h->root.type == bfd_link_hash_undefweak
                      || h->root.type == bfd_link_hash_undefined)))
            {
@@ -2428,8 +2388,8 @@ elf32_sparc_relocate_section (output_bfd, info, input_bfd, input_section,
              bfd_boolean skip, relocate = FALSE;
 
              /* When generating a shared object, these relocations
-                 are copied into the output file to be resolved at run
-                 time.  */
+                are copied into the output file to be resolved at run
+                time.  */
 
              BFD_ASSERT (sreloc != NULL);
 
@@ -2481,11 +2441,10 @@ elf32_sparc_relocate_section (output_bfd, info, input_bfd, input_section,
              if (skip)
                memset (&outrel, 0, sizeof outrel);
              /* h->dynindx may be -1 if the symbol was marked to
-                 become local.  */
+                become local.  */
              else if (h != NULL && ! is_plt
                       && ((! info->symbolic && h->dynindx != -1)
-                          || (h->elf_link_hash_flags
-                              & ELF_LINK_HASH_DEF_REGULAR) == 0))
+                          || !h->def_regular))
                {
                  BFD_ASSERT (h->dynindx != -1);
                  outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
@@ -2504,16 +2463,8 @@ elf32_sparc_relocate_section (output_bfd, info, input_bfd, input_section,
 
                      if (is_plt)
                        sec = htab->splt;
-                     else if (h == NULL)
-                       sec = local_sections[r_symndx];
-                     else
-                       {
-                         BFD_ASSERT (h->root.type == bfd_link_hash_defined
-                                     || (h->root.type
-                                         == bfd_link_hash_defweak));
-                         sec = h->root.u.def.section;
-                       }
-                     if (sec != NULL && bfd_is_abs_section (sec))
+
+                     if (bfd_is_abs_section (sec))
                        indx = 0;
                      else if (sec == NULL || sec->owner == NULL)
                        {
@@ -2533,8 +2484,8 @@ elf32_sparc_relocate_section (output_bfd, info, input_bfd, input_section,
                            {
                              BFD_FAIL ();
                              (*_bfd_error_handler)
-                               (_("%s: probably compiled without -fPIC?"),
-                                bfd_archive_filename (input_bfd));
+                               (_("%B: probably compiled without -fPIC?"),
+                                input_bfd);
                              bfd_set_error (bfd_error_bad_value);
                              return FALSE;
                            }
@@ -2550,7 +2501,7 @@ elf32_sparc_relocate_section (output_bfd, info, input_bfd, input_section,
              bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
 
              /* This reloc will be computed at runtime, so there's no
-                 need to do anything now.  */
+                need to do anything now.  */
              if (! relocate)
                continue;
            }
@@ -2615,7 +2566,7 @@ elf32_sparc_relocate_section (output_bfd, info, input_bfd, input_section,
              break;
            }
 
-          if (h != NULL)
+         if (h != NULL)
            {
              off = h->got.offset;
              h->got.offset |= 1;
@@ -2626,14 +2577,14 @@ elf32_sparc_relocate_section (output_bfd, info, input_bfd, input_section,
              off = local_got_offsets[r_symndx];
              local_got_offsets[r_symndx] |= 1;
            }
-           
+
        r_sparc_tlsldm:
          if (htab->sgot == NULL)
            abort ();
 
          if ((off & 1) != 0)
            off &= ~1;
-          else
+         else
            {
              Elf_Internal_Rela outrel;
              Elf32_External_Rela *loc;
@@ -2889,11 +2840,11 @@ elf32_sparc_relocate_section (output_bfd, info, input_bfd, input_section,
         not process them.  */
       if (unresolved_reloc
          && !((input_section->flags & SEC_DEBUGGING) != 0
-              && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0))
+              && h->def_dynamic))
        (*_bfd_error_handler)
-         (_("%s(%s+0x%lx): unresolvable relocation against symbol `%s'"),
-          bfd_archive_filename (input_bfd),
-          bfd_get_section_name (input_bfd, input_section),
+         (_("%B(%A+0x%lx): unresolvable relocation against symbol `%s'"),
+          input_bfd,
+          input_section,
           (long) rel->r_offset,
           h->root.root.string);
 
@@ -2958,7 +2909,7 @@ elf32_sparc_relocate_section (output_bfd, info, input_bfd, input_section,
        }
       else if ((r_type == R_SPARC_WDISP30 || r_type == R_SPARC_WPLT30)
               && sec_do_relax (input_section)
-              && rel->r_offset + 4 < input_section->_raw_size)
+              && rel->r_offset + 4 < input_section->size)
        {
 #define G0             0
 #define O7             15
@@ -3063,7 +3014,7 @@ elf32_sparc_relocate_section (output_bfd, info, input_bfd, input_section,
                const char *name;
 
                if (h != NULL)
-                 name = h->root.root.string;
+                 name = NULL;
                else
                  {
                    name = bfd_elf_string_from_elf_section (input_bfd,
@@ -3075,8 +3026,9 @@ elf32_sparc_relocate_section (output_bfd, info, input_bfd, input_section,
                      name = bfd_section_name (input_bfd, sec);
                  }
                if (! ((*info->callbacks->reloc_overflow)
-                      (info, name, howto->name, (bfd_vma) 0,
-                       input_bfd, input_section, rel->r_offset)))
+                      (info, (h ? &h->root : NULL), name, howto->name,
+                       (bfd_vma) 0, input_bfd, input_section,
+                       rel->r_offset)))
                  return FALSE;
              }
              break;
@@ -3099,7 +3051,7 @@ elf32_sparc_finish_dynamic_symbol (output_bfd, info, h, sym)
 {
   bfd *dynobj;
   struct elf32_sparc_link_hash_table *htab;
-        
+
   htab = elf32_sparc_hash_table (info);
   dynobj = htab->elf.dynobj;
 
@@ -3111,7 +3063,7 @@ elf32_sparc_finish_dynamic_symbol (output_bfd, info, h, sym)
       bfd_byte *loc;
 
       /* This symbol has an entry in the procedure linkage table.  Set
-         it up.  */
+        it up.  */
 
       BFD_ASSERT (h->dynindx != -1);
 
@@ -3140,7 +3092,7 @@ elf32_sparc_finish_dynamic_symbol (output_bfd, info, h, sym)
       loc += (h->plt.offset / PLT_ENTRY_SIZE - 4) * sizeof (Elf32_External_Rela);
       bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
 
-      if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
+      if (!h->def_regular)
        {
          /* Mark the symbol as undefined, rather than as defined in
             the .plt section.  Leave the value alone.  */
@@ -3149,8 +3101,7 @@ elf32_sparc_finish_dynamic_symbol (output_bfd, info, h, sym)
             Otherwise, the PLT entry would provide a definition for
             the symbol even if the symbol wasn't defined anywhere,
             and so the symbol would never be NULL.  */
-         if ((h->elf_link_hash_flags & ELF_LINK_HASH_REF_REGULAR_NONWEAK)
-             == 0)
+         if (!h->ref_regular_nonweak)
            sym->st_value = 0;
        }
     }
@@ -3165,7 +3116,7 @@ elf32_sparc_finish_dynamic_symbol (output_bfd, info, h, sym)
       bfd_byte *loc;
 
       /* This symbol has an entry in the global offset table.  Set it
-         up.  */
+        up.  */
 
       sgot = htab->sgot;
       srela = htab->srelgot;
@@ -3182,7 +3133,7 @@ elf32_sparc_finish_dynamic_symbol (output_bfd, info, h, sym)
         initialized in the relocate_section function.  */
       if (info->shared
          && (info->symbolic || h->dynindx == -1)
-         && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR))
+         && h->def_regular)
        {
          asection *sec = h->root.u.def.section;
          rela.r_info = ELF32_R_INFO (0, R_SPARC_RELATIVE);
@@ -3203,7 +3154,7 @@ elf32_sparc_finish_dynamic_symbol (output_bfd, info, h, sym)
       bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
     }
 
-  if ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_COPY) != 0)
+  if (h->needs_copy)
     {
       asection *s;
       Elf_Internal_Rela rela;
@@ -3245,7 +3196,7 @@ elf32_sparc_finish_dynamic_sections (output_bfd, info)
   bfd *dynobj;
   asection *sdyn;
   struct elf32_sparc_link_hash_table *htab;
-  
+
   htab = elf32_sparc_hash_table (info);
   dynobj = htab->elf.dynobj;
 
@@ -3260,7 +3211,7 @@ elf32_sparc_finish_dynamic_sections (output_bfd, info)
       BFD_ASSERT (splt != NULL && sdyn != NULL);
 
       dyncon = (Elf32_External_Dyn *) sdyn->contents;
-      dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->_raw_size);
+      dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size);
       for (; dyncon < dynconend; dyncon++)
        {
          Elf_Internal_Dyn dyn;
@@ -3289,12 +3240,7 @@ elf32_sparc_finish_dynamic_sections (output_bfd, info)
                  if (! size)
                    dyn.d_un.d_ptr = s->vma;
                  else
-                   {
-                     if (s->_cooked_size != 0)
-                       dyn.d_un.d_val = s->_cooked_size;
-                     else
-                       dyn.d_un.d_val = s->_raw_size;
-                   }
+                   dyn.d_un.d_val = s->size;
                }
              bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
            }
@@ -3302,20 +3248,19 @@ elf32_sparc_finish_dynamic_sections (output_bfd, info)
 
       /* Clear the first four entries in the procedure linkage table,
         and put a nop in the last four bytes.  */
-      if (splt->_raw_size > 0)
+      if (splt->size > 0)
        {
          memset (splt->contents, 0, 4 * PLT_ENTRY_SIZE);
          bfd_put_32 (output_bfd, (bfd_vma) SPARC_NOP,
-                     splt->contents + splt->_raw_size - 4);
+                     splt->contents + splt->size - 4);
        }
 
-      elf_section_data (splt->output_section)->this_hdr.sh_entsize =
-       PLT_ENTRY_SIZE;
+      elf_section_data (splt->output_section)->this_hdr.sh_entsize = 0;
     }
 
   /* Set the first entry in the global offset table to the address of
      the dynamic section.  */
-  if (htab->sgot && htab->sgot->_raw_size > 0)
+  if (htab->sgot && htab->sgot->size > 0)
     {
       if (sdyn == NULL)
        bfd_put_32 (output_bfd, (bfd_vma) 0, htab->sgot->contents);
@@ -3347,6 +3292,7 @@ elf32_sparc_merge_private_bfd_data (ibfd, obfd)
      bfd *obfd;
 {
   bfd_boolean error;
+  unsigned long ibfd_mach;
   /* FIXME: This should not be static.  */
   static unsigned long previous_ibfd_e_flags = (unsigned long) -1;
 
@@ -3356,17 +3302,17 @@ elf32_sparc_merge_private_bfd_data (ibfd, obfd)
 
   error = FALSE;
 
-  if (bfd_get_mach (ibfd) >= bfd_mach_sparc_v9)
+  ibfd_mach = bfd_get_mach (ibfd);
+  if (bfd_mach_sparc_64bit_p (ibfd_mach))
     {
       error = TRUE;
       (*_bfd_error_handler)
-       (_("%s: compiled for a 64 bit system and target is 32 bit"),
-        bfd_archive_filename (ibfd));
+       (_("%B: compiled for a 64 bit system and target is 32 bit"), ibfd);
     }
   else if ((ibfd->flags & DYNAMIC) == 0)
     {
-      if (bfd_get_mach (obfd) < bfd_get_mach (ibfd))
-       bfd_set_arch_mach (obfd, bfd_arch_sparc, bfd_get_mach (ibfd));
+      if (bfd_get_mach (obfd) < ibfd_mach)
+       bfd_set_arch_mach (obfd, bfd_arch_sparc, ibfd_mach);
     }
 
   if (((elf_elfheader (ibfd)->e_flags & EF_SPARC_LEDATA)
@@ -3374,8 +3320,7 @@ elf32_sparc_merge_private_bfd_data (ibfd, obfd)
       && previous_ibfd_e_flags != (unsigned long) -1)
     {
       (*_bfd_error_handler)
-       (_("%s: linking little endian files with big endian files"),
-        bfd_archive_filename (ibfd));
+       (_("%B: linking little endian files with big endian files"), ibfd);
       error = TRUE;
     }
   previous_ibfd_e_flags = elf_elfheader (ibfd)->e_flags & EF_SPARC_LEDATA;
@@ -3395,15 +3340,6 @@ static bfd_boolean
 elf32_sparc_object_p (abfd)
      bfd *abfd;
 {
-  /* Allocate our special target data.  */
-  struct elf32_sparc_obj_tdata *new_tdata;
-  bfd_size_type amt = sizeof (struct elf32_sparc_obj_tdata);
-  new_tdata = bfd_zalloc (abfd, amt);
-  if (new_tdata == NULL)
-    return FALSE;
-  new_tdata->root = *abfd->tdata.elf_obj_data;
-  abfd->tdata.any = new_tdata;
-
   if (elf_elfheader (abfd)->e_machine == EM_SPARC32PLUS)
     {
       if (elf_elfheader (abfd)->e_flags & EF_SPARC_SUN_US3)
@@ -3436,6 +3372,8 @@ elf32_sparc_final_write_processing (abfd, linker)
   switch (bfd_get_mach (abfd))
     {
     case bfd_mach_sparc :
+    case bfd_mach_sparc_sparclet :
+    case bfd_mach_sparc_sparclite :
       break; /* nothing to do */
     case bfd_mach_sparc_v8plus :
       elf_elfheader (abfd)->e_machine = EM_SPARC32PLUS;
@@ -3454,7 +3392,6 @@ elf32_sparc_final_write_processing (abfd, linker)
                                       | EF_SPARC_SUN_US3;
       break;
     case bfd_mach_sparc_sparclite_le :
-      elf_elfheader (abfd)->e_machine = EM_SPARC;
       elf_elfheader (abfd)->e_flags |= EF_SPARC_LEDATA;
       break;
     default :
@@ -3479,6 +3416,17 @@ elf32_sparc_reloc_type_class (rela)
       return reloc_class_normal;
     }
 }
+
+/* Return address for Ith PLT stub in section PLT, for relocation REL
+   or (bfd_vma) -1 if it should not be included.  */
+
+static bfd_vma
+elf32_sparc_plt_sym_val (bfd_vma i ATTRIBUTE_UNUSED,
+                        const asection *plt ATTRIBUTE_UNUSED,
+                        const arelent *rel)
+{
+  return rel->address;
+}
 \f
 #define TARGET_BIG_SYM bfd_elf32_sparc_vec
 #define TARGET_BIG_NAME        "elf32-sparc"
@@ -3513,9 +3461,11 @@ elf32_sparc_reloc_type_class (rela)
 #define elf_backend_object_p           elf32_sparc_object_p
 #define elf_backend_final_write_processing \
                                        elf32_sparc_final_write_processing
-#define elf_backend_gc_mark_hook        elf32_sparc_gc_mark_hook
+#define elf_backend_gc_mark_hook       elf32_sparc_gc_mark_hook
 #define elf_backend_gc_sweep_hook       elf32_sparc_gc_sweep_hook
+#define elf_backend_grok_psinfo                elf32_sparc_grok_psinfo
 #define elf_backend_reloc_type_class   elf32_sparc_reloc_type_class
+#define elf_backend_plt_sym_val                elf32_sparc_plt_sym_val
 
 #define elf_backend_can_gc_sections 1
 #define elf_backend_can_refcount 1
@@ -3523,7 +3473,6 @@ elf32_sparc_reloc_type_class (rela)
 #define elf_backend_plt_readonly 0
 #define elf_backend_want_plt_sym 1
 #define elf_backend_got_header_size 4
-#define elf_backend_plt_header_size (4*PLT_ENTRY_SIZE)
 #define elf_backend_rela_normal 1
 
 #include "elf32-target.h"
This page took 0.062916 seconds and 4 git commands to generate.