Convert to ISO C90 formatting
[deliverable/binutils-gdb.git] / bfd / elf64-sparc.c
index dbaa954b413d0c1137049727d5dda09409630565..ab96be5b02f41b8eeb027488d9019ef2d4ebbbd8 100644 (file)
@@ -1,6 +1,6 @@
 /* SPARC-specific support for 64-bit ELF
    Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
-   2003 Free Software Foundation, Inc.
+   2003, 2004, 2005 Free Software Foundation, Inc.
 
    This file is part of BFD, the Binary File Descriptor library.
 
 
 static struct bfd_link_hash_table * sparc64_elf_bfd_link_hash_table_create
   PARAMS ((bfd *));
+static bfd_boolean create_got_section
+  PARAMS ((bfd *, struct bfd_link_info *));
+static bfd_boolean sparc64_elf_create_dynamic_sections
+  PARAMS ((bfd *, struct bfd_link_info *));
 static bfd_reloc_status_type init_insn_reloc
   PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *,
           bfd *, bfd_vma *, bfd_vma *));
@@ -56,16 +60,19 @@ static bfd_boolean sparc64_elf_check_relocs
           const Elf_Internal_Rela *));
 static bfd_boolean sparc64_elf_adjust_dynamic_symbol
   PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *));
+static bfd_boolean sparc64_elf_omit_section_dynsym
+  PARAMS ((bfd *, struct bfd_link_info *, asection *));
 static bfd_boolean sparc64_elf_size_dynamic_sections
   PARAMS ((bfd *, struct bfd_link_info *));
 static int sparc64_elf_get_symbol_type
   PARAMS (( Elf_Internal_Sym *, int));
 static bfd_boolean sparc64_elf_add_symbol_hook
-  PARAMS ((bfd *, struct bfd_link_info *, const Elf_Internal_Sym *,
+  PARAMS ((bfd *, struct bfd_link_info *, Elf_Internal_Sym *,
           const char **, flagword *, asection **, bfd_vma *));
 static bfd_boolean sparc64_elf_output_arch_syms
   PARAMS ((bfd *, struct bfd_link_info *, PTR,
-          bfd_boolean (*) (PTR, const char *, Elf_Internal_Sym *, asection *)));
+          bfd_boolean (*) (PTR, const char *, Elf_Internal_Sym *,
+                           asection *, struct elf_link_hash_entry *)));
 static void sparc64_elf_symbol_processing
   PARAMS ((bfd *, asymbol *));
 
@@ -477,7 +484,7 @@ sparc64_elf_slurp_reloc_table (abfd, asect, symbols, dynamic)
         case because relocations against this section may use the
         dynamic symbol table, and in that case bfd_section_from_shdr
         in elf.c does not update the RELOC_COUNT.  */
-      if (asect->_raw_size == 0)
+      if (asect->size == 0)
        return TRUE;
 
       rel_hdr = &d->this_hdr;
@@ -518,7 +525,7 @@ sparc64_elf_canonicalize_reloc (abfd, section, relptr, symbols)
 {
   arelent *tblptr;
   unsigned int i;
-  struct elf_backend_data *bed = get_elf_backend_data (abfd);
+  const struct elf_backend_data *bed = get_elf_backend_data (abfd);
 
   if (! bed->s->slurp_reloc_table (abfd, section, symbols, FALSE))
     return -1;
@@ -735,6 +742,10 @@ struct sparc64_elf_link_hash_table
 {
   struct elf_link_hash_table root;
 
+  /* Short-cuts to get to dynamic linker sections.  */
+  asection *sgot;
+  asection *srelgot;
+
   struct sparc64_elf_app_reg app_regs [4];
 };
 
@@ -765,6 +776,57 @@ sparc64_elf_bfd_link_hash_table_create (abfd)
 
   return &ret->root.root;
 }
+
+/* Create .got and .rela.got sections in DYNOBJ and set up
+   shortcuts to them in our hash table.  */
+
+static bfd_boolean
+create_got_section (dynobj, info)
+     bfd *dynobj;
+     struct bfd_link_info *info;
+{
+  struct sparc64_elf_link_hash_table *htab;
+
+  if (! _bfd_elf_create_got_section (dynobj, info))
+    return FALSE;
+
+  htab = sparc64_elf_hash_table (info);
+  htab->sgot = bfd_get_section_by_name (dynobj, ".got");
+  BFD_ASSERT (htab->sgot != NULL);
+
+  htab->srelgot = bfd_make_section (dynobj, ".rela.got");
+  if (htab->srelgot == NULL
+      || ! bfd_set_section_flags (dynobj, htab->srelgot, SEC_ALLOC
+                                                        | SEC_LOAD
+                                                        | SEC_HAS_CONTENTS
+                                                        | SEC_IN_MEMORY
+                                                        | SEC_LINKER_CREATED
+                                                        | SEC_READONLY)
+      || ! bfd_set_section_alignment (dynobj, htab->srelgot, 3))
+    return FALSE;
+  return TRUE;
+}
+
+/* Create .plt, .rela.plt, .got, .rela.got, .dynbss, and
+   .rela.bss sections in DYNOBJ, and set up shortcuts to them in our
+   hash table.  */
+
+static bfd_boolean
+sparc64_elf_create_dynamic_sections (dynobj, info)
+     bfd *dynobj;
+     struct bfd_link_info *info;
+{
+  struct sparc64_elf_link_hash_table *htab;
+
+  htab = sparc64_elf_hash_table (info);
+  if (!htab->sgot && !create_got_section (dynobj, info))
+    return FALSE;
+
+  if (!_bfd_elf_create_dynamic_sections (dynobj, info))
+    return FALSE;
+
+  return TRUE;
+}
 \f
 /* Utility for performing the standard initial work of an instruction
    relocation.
@@ -808,7 +870,7 @@ init_insn_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
@@ -1134,35 +1196,22 @@ sparc64_elf_check_relocs (abfd, info, sec, relocs)
 
          if (dynobj == NULL)
            {
-             /* Create the .got section.  */
+             /* Create the .got and .rela.got sections.  */
              elf_hash_table (info)->dynobj = dynobj = abfd;
-             if (! _bfd_elf_create_got_section (dynobj, info))
+             if (! create_got_section (dynobj, info))
                return FALSE;
            }
 
          if (sgot == NULL)
            {
-             sgot = bfd_get_section_by_name (dynobj, ".got");
+             sgot = sparc64_elf_hash_table (info)->sgot;
              BFD_ASSERT (sgot != NULL);
            }
 
          if (srelgot == NULL && (h != NULL || info->shared))
            {
-             srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
-             if (srelgot == NULL)
-               {
-                 srelgot = bfd_make_section (dynobj, ".rela.got");
-                 if (srelgot == NULL
-                     || ! bfd_set_section_flags (dynobj, srelgot,
-                                                 (SEC_ALLOC
-                                                  | SEC_LOAD
-                                                  | SEC_HAS_CONTENTS
-                                                  | SEC_IN_MEMORY
-                                                  | SEC_LINKER_CREATED
-                                                  | SEC_READONLY))
-                     || ! bfd_set_section_alignment (dynobj, srelgot, 3))
-                   return FALSE;
-               }
+             srelgot = sparc64_elf_hash_table (info)->srelgot;
+             BFD_ASSERT (srelgot != NULL);
            }
 
          if (h != NULL)
@@ -1172,16 +1221,16 @@ sparc64_elf_check_relocs (abfd, info, sec, relocs)
                  /* We have already allocated space in the .got.  */
                  break;
                }
-             h->got.offset = sgot->_raw_size;
+             h->got.offset = sgot->size;
 
              /* Make sure this symbol is output as a dynamic symbol.  */
              if (h->dynindx == -1)
                {
-                 if (! bfd_elf64_link_record_dynamic_symbol (info, h))
+                 if (! bfd_elf_link_record_dynamic_symbol (info, h))
                    return FALSE;
                }
 
-             srelgot->_raw_size += sizeof (Elf64_External_Rela);
+             srelgot->size += sizeof (Elf64_External_Rela);
            }
          else
            {
@@ -1206,20 +1255,19 @@ sparc64_elf_check_relocs (abfd, info, sec, relocs)
                  /* We have already allocated space in the .got.  */
                  break;
                }
-             local_got_offsets[r_symndx] = sgot->_raw_size;
+             local_got_offsets[r_symndx] = sgot->size;
 
              if (info->shared)
                {
                  /* If we are generating a shared object, we need to
                      output a R_SPARC_RELATIVE reloc so that the
                      dynamic linker can adjust this GOT entry.  */
-                 srelgot->_raw_size += sizeof (Elf64_External_Rela);
+                 srelgot->size += sizeof (Elf64_External_Rela);
                }
            }
 
-         sgot->_raw_size += 8;
+         sgot->size += 8;
 
-#if 0
          /* Doesn't work for 64-bit -fPIC, since sethi/or builds
             unsigned numbers.  If we permit ourselves to modify
             code so we get sethi/xor, this could work.
@@ -1228,10 +1276,11 @@ sparc64_elf_check_relocs (abfd, info, sec, relocs)
          /* 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 (sgot->_raw_size >= 0x1000
+         /*
+         if (sgot->size >= 0x1000
              && elf_hash_table (info)->hgot->root.u.def.value == 0)
            elf_hash_table (info)->hgot->root.u.def.value = 0x1000;
-#endif
+         */
 
          break;
 
@@ -1260,11 +1309,11 @@ sparc64_elf_check_relocs (abfd, info, sec, relocs)
          /* Make sure this symbol is output as a dynamic symbol.  */
          if (h->dynindx == -1)
            {
-             if (! bfd_elf64_link_record_dynamic_symbol (info, h))
+             if (! bfd_elf_link_record_dynamic_symbol (info, h))
                return FALSE;
            }
 
-         h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
+         h->needs_plt = 1;
          if (ELF64_R_TYPE_ID (rel->r_info) != R_SPARC_PLT32
              && ELF64_R_TYPE_ID (rel->r_info) != R_SPARC_PLT64)
            break;
@@ -1358,7 +1407,7 @@ sparc64_elf_check_relocs (abfd, info, sec, relocs)
                    info->flags |= DF_TEXTREL;
                }
 
-             sreloc->_raw_size += sizeof (Elf64_External_Rela);
+             sreloc->size += sizeof (Elf64_External_Rela);
            }
          break;
 
@@ -1367,9 +1416,8 @@ sparc64_elf_check_relocs (abfd, info, sec, relocs)
          break;
 
        default:
-         (*_bfd_error_handler) (_("%s: check_relocs: unhandled reloc type %d"),
-                               bfd_archive_filename (abfd),
-                               ELF64_R_TYPE_ID (rel->r_info));
+         (*_bfd_error_handler) (_("%B: check_relocs: unhandled reloc type %d"),
+                               abfd, ELF64_R_TYPE_ID (rel->r_info));
          return FALSE;
        }
     }
@@ -1384,7 +1432,7 @@ static bfd_boolean
 sparc64_elf_add_symbol_hook (abfd, info, sym, namep, flagsp, secp, valp)
      bfd *abfd;
      struct bfd_link_info *info;
-     const Elf_Internal_Sym *sym;
+     Elf_Internal_Sym *sym;
      const char **namep;
      flagword *flagsp ATTRIBUTE_UNUSED;
      asection **secp ATTRIBUTE_UNUSED;
@@ -1404,8 +1452,8 @@ sparc64_elf_add_symbol_hook (abfd, info, sym, namep, flagsp, secp, valp)
        case 6: reg -= 4; break;
        default:
           (*_bfd_error_handler)
-            (_("%s: Only registers %%g[2367] can be declared using STT_REGISTER"),
-             bfd_archive_filename (abfd));
+            (_("%B: Only registers %%g[2367] can be declared using STT_REGISTER"),
+             abfd);
          return FALSE;
        }
 
@@ -1424,10 +1472,10 @@ sparc64_elf_add_symbol_hook (abfd, info, sym, namep, flagsp, secp, valp)
       if (p->name != NULL && strcmp (p->name, *namep))
        {
           (*_bfd_error_handler)
-            (_("Register %%g%d used incompatibly: %s in %s, previously %s in %s"),
-             (int) sym->st_value,
-             **namep ? *namep : "#scratch", bfd_archive_filename (abfd),
-             *p->name ? p->name : "#scratch", bfd_archive_filename (p->abfd));
+            (_("Register %%g%d used incompatibly: %s in %B, previously %s in %B"),
+             abfd, p->abfd, (int) sym->st_value,
+             **namep ? *namep : "#scratch",
+             *p->name ? p->name : "#scratch");
          return FALSE;
        }
 
@@ -1447,9 +1495,8 @@ sparc64_elf_add_symbol_hook (abfd, info, sym, namep, flagsp, secp, valp)
                  if (type > STT_FUNC)
                    type = 0;
                  (*_bfd_error_handler)
-                   (_("Symbol `%s' has differing types: REGISTER in %s, previously %s in %s"),
-                    *namep, bfd_archive_filename (abfd),
-                    stt_types[type], bfd_archive_filename (p->abfd));
+                   (_("Symbol `%s' has differing types: REGISTER in %B, previously %s in %B"),
+                    abfd, p->abfd, *namep, stt_types[type]);
                  return FALSE;
                }
 
@@ -1493,16 +1540,15 @@ sparc64_elf_add_symbol_hook (abfd, info, sym, namep, flagsp, secp, valp)
            if (type > STT_FUNC)
              type = 0;
            (*_bfd_error_handler)
-             (_("Symbol `%s' has differing types: %s in %s, previously REGISTER in %s"),
-              *namep, stt_types[type], bfd_archive_filename (abfd),
-              bfd_archive_filename (p->abfd));
+             (_("Symbol `%s' has differing types: %s in %B, previously REGISTER in %B"),
+              abfd, p->abfd, *namep, stt_types[type]);
            return FALSE;
          }
     }
   return TRUE;
 }
 
-/* This function takes care of emiting STT_REGISTER symbols
+/* This function takes care of emitting STT_REGISTER symbols
    which we cannot easily keep in the symbol hash table.  */
 
 static bfd_boolean
@@ -1511,7 +1557,8 @@ sparc64_elf_output_arch_syms (output_bfd, info, finfo, func)
      struct bfd_link_info *info;
      PTR finfo;
      bfd_boolean (*func)
-       PARAMS ((PTR, const char *, Elf_Internal_Sym *, asection *));
+       PARAMS ((PTR, const char *, Elf_Internal_Sym *, asection *,
+               struct elf_link_hash_entry *));
 {
   int reg;
   struct sparc64_elf_app_reg *app_regs =
@@ -1557,7 +1604,8 @@ sparc64_elf_output_arch_syms (output_bfd, info, finfo, func)
        sym.st_shndx = app_regs [reg].shndx;
        if (! (*func) (finfo, app_regs [reg].name, &sym,
                       sym.st_shndx == SHN_ABS
-                        ? bfd_abs_section_ptr : bfd_und_section_ptr))
+                        ? bfd_abs_section_ptr : bfd_und_section_ptr,
+                      NULL))
          return FALSE;
       }
 
@@ -1612,14 +1660,11 @@ sparc64_elf_adjust_dynamic_symbol (info, h)
 
   /* Make sure we know what is going on here.  */
   BFD_ASSERT (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
@@ -1629,20 +1674,24 @@ sparc64_elf_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)
          && (h->root.u.def.section->flags & SEC_CODE) != 0))
     {
-      if (! elf_hash_table (info)->dynamic_sections_created)
+      if (! info->shared
+         && !h->def_dynamic
+         && !h->ref_dynamic
+         && h->root.type != bfd_link_hash_undefweak
+         && h->root.type != bfd_link_hash_undefined)
        {
          /* This case can occur if we saw a WPLT30 reloc in an input
              file, but none of the input files were dynamic objects.
              In such a case, we don't actually need to build a
              procedure linkage table, and we can just do a WDISP30
              reloc instead.  */
-         BFD_ASSERT ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0);
+         BFD_ASSERT (h->needs_plt);
          return TRUE;
        }
 
@@ -1650,11 +1699,11 @@ sparc64_elf_adjust_dynamic_symbol (info, h)
       BFD_ASSERT (s != NULL);
 
       /* The first four bit in .plt is reserved.  */
-      if (s->_raw_size == 0)
-       s->_raw_size = PLT_HEADER_SIZE;
+      if (s->size == 0)
+       s->size = PLT_HEADER_SIZE;
 
       /* To simplify matters later, just store the plt index here.  */
-      h->plt.offset = s->_raw_size / PLT_ENTRY_SIZE;
+      h->plt.offset = s->size / PLT_ENTRY_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
@@ -1662,25 +1711,25 @@ sparc64_elf_adjust_dynamic_symbol (info, h)
         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 = sparc64_elf_plt_entry_offset (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.  */
 
       s = bfd_get_section_by_name (dynobj, ".rela.plt");
       BFD_ASSERT (s != NULL);
 
-      s->_raw_size += sizeof (Elf64_External_Rela);
+      s->size += sizeof (Elf64_External_Rela);
 
       /* The procedure linkage table size is bounded by the magnitude
         of the offset we can describe in the entry.  */
-      if (s->_raw_size >= (bfd_vma)1 << 32)
+      if (s->size >= (bfd_vma)1 << 32)
        {
          bfd_set_error (bfd_error_bad_value);
          return FALSE;
@@ -1692,12 +1741,12 @@ sparc64_elf_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;
     }
 
@@ -1734,8 +1783,8 @@ sparc64_elf_adjust_dynamic_symbol (info, h)
 
       srel = bfd_get_section_by_name (dynobj, ".rela.bss");
       BFD_ASSERT (srel != NULL);
-      srel->_raw_size += sizeof (Elf64_External_Rela);
-      h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_COPY;
+      srel->size += sizeof (Elf64_External_Rela);
+      h->needs_copy = 1;
     }
 
   /* We need to figure out the alignment required for this symbol.  I
@@ -1746,8 +1795,7 @@ sparc64_elf_adjust_dynamic_symbol (info, h)
     power_of_two = 4;
 
   /* Apply the required alignment.  */
-  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))
@@ -1756,14 +1804,31 @@ sparc64_elf_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;
 }
 
+/* Return true if the dynamic symbol for a given section should be
+   omitted when creating a shared library.  */
+
+static bfd_boolean
+sparc64_elf_omit_section_dynsym (bfd *output_bfd,
+                                struct bfd_link_info *info,
+                                asection *p)
+{
+  /* We keep the .got section symbol so that explicit relocations
+     against the _GLOBAL_OFFSET_TABLE_ symbol emitted in PIC mode
+     can be turned into relocations against the .got symbol.  */
+  if (strcmp (p->name, ".got") == 0)
+    return FALSE;
+
+  return _bfd_elf_link_omit_section_dynsym (output_bfd, info, p);
+}
+
 /* Set the sizes of the dynamic sections.  */
 
 static bfd_boolean
@@ -1785,7 +1850,7 @@ sparc64_elf_size_dynamic_sections (output_bfd, info)
        {
          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;
        }
     }
@@ -1796,9 +1861,9 @@ sparc64_elf_size_dynamic_sections (output_bfd, info)
          not actually use these entries.  Reset the size of .rela.got,
          which will cause it to get stripped from the output file
          below.  */
-      s = bfd_get_section_by_name (dynobj, ".rela.got");
+      s = sparc64_elf_hash_table (info)->srelgot;
       if (s != NULL)
-       s->_raw_size = 0;
+       s->size = 0;
     }
 
   /* The check_relocs and adjust_dynamic_symbol entry points have
@@ -1821,7 +1886,7 @@ sparc64_elf_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
@@ -1860,8 +1925,8 @@ sparc64_elf_size_dynamic_sections (output_bfd, info)
       /* Allocate memory for the section contents.  Zero the memory
         for the benefit of .rela.plt, which has 4 unused entries
         at the beginning, and we don't want garbage.  */
-      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;
     }
 
@@ -1873,7 +1938,7 @@ sparc64_elf_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_elf64_add_dynamic_entry (info, (bfd_vma) (TAG), (bfd_vma) (VAL))
+  _bfd_elf_add_dynamic_entry (info, TAG, VAL)
 
       int reg;
       struct sparc64_elf_app_reg * app_regs;
@@ -1986,17 +2051,6 @@ sparc64_elf_relax_section (abfd, section, link_info, again)
   return TRUE;
 }
 \f
-/* 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))
-
 /* Relocate a SPARC64 ELF section.  */
 
 static bfd_boolean
@@ -2036,6 +2090,8 @@ sparc64_elf_relocate_section (output_bfd, info, input_bfd, input_section,
     got_base = elf_hash_table (info)->hgot->root.u.def.value;
 
   sgot = splt = sreloc = NULL;
+  if (dynobj != NULL)
+    splt = bfd_get_section_by_name (dynobj, ".plt");
 
   rel = relocs;
   relend = relocs + NUM_SHDR_ENTRIES (& elf_section_data (input_section)->rel_hdr);
@@ -2070,46 +2126,18 @@ sparc64_elf_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;
 
-         relocation = 0;
-         if (h->root.type == bfd_link_hash_defined
-             || h->root.type == bfd_link_hash_defweak)
+         RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
+                                  r_symndx, symtab_hdr, sym_hashes,
+                                  h, sec, relocation,
+                                  unresolved_reloc, warned);
+         if (warned)
            {
-             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->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;
-
              /* To avoid generating warning messages about truncated
                 relocations, set the relocation's address to be the same as
                 the start of this section.  */
@@ -2247,14 +2275,20 @@ sparc64_elf_relocate_section (output_bfd, info, input_bfd, input_section,
                    break;
                  }
 
+               /* FIXME: Dynamic reloc handling really needs to be rewritten.  */
+               if (!skip
+                   && h != NULL
+                   && ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
+                   && h->root.type == bfd_link_hash_undefweak)
+                 skip = TRUE, relocate = TRUE;
+
                if (skip)
                  memset (&outrel, 0, sizeof outrel);
                /* h->dynindx may be -1 if the symbol was marked to
                   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
@@ -2275,16 +2309,8 @@ sparc64_elf_relocate_section (output_bfd, info, input_bfd, input_section,
 
                        if (is_plt)
                          sec = 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)
                          {
@@ -2311,8 +2337,8 @@ sparc64_elf_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;
                              }
@@ -2348,7 +2374,7 @@ sparc64_elf_relocate_section (output_bfd, info, input_bfd, input_section,
             offset table.  */
          if (sgot == NULL)
            {
-             sgot = bfd_get_section_by_name (dynobj, ".got");
+             sgot = sparc64_elf_hash_table (info)->sgot;
              BFD_ASSERT (sgot != NULL);
            }
 
@@ -2360,12 +2386,12 @@ sparc64_elf_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
@@ -2422,7 +2448,7 @@ sparc64_elf_relocate_section (output_bfd, info, input_bfd, input_section,
 
                      /* We need to generate a R_SPARC_RELATIVE reloc
                         for the dynamic linker.  */
-                     s = bfd_get_section_by_name(dynobj, ".rela.got");
+                     s = sparc64_elf_hash_table (info)->srelgot;
                      BFD_ASSERT (s != NULL);
 
                      outrel.r_offset = (sgot->output_section->vma
@@ -2453,7 +2479,7 @@ sparc64_elf_relocate_section (output_bfd, info, input_bfd, input_section,
              procedure linkage table.  */
          BFD_ASSERT (h != NULL);
 
-         if (h->plt.offset == (bfd_vma) -1)
+         if (h->plt.offset == (bfd_vma) -1 || splt == NULL)
            {
              /* We didn't make a PLT entry for this symbol.  This
                 happens when statically linking PIC code, or when
@@ -2461,12 +2487,6 @@ sparc64_elf_relocate_section (output_bfd, info, input_bfd, input_section,
              goto do_default;
            }
 
-         if (splt == NULL)
-           {
-             splt = bfd_get_section_by_name (dynobj, ".plt");
-             BFD_ASSERT (splt != NULL);
-           }
-
          relocation = (splt->output_section->vma
                        + splt->output_offset
                        + sparc64_elf_plt_entry_offset (h->plt.offset));
@@ -2558,7 +2578,7 @@ sparc64_elf_relocate_section (output_bfd, info, input_bfd, input_section,
        case R_SPARC_WDISP30:
        do_wplt30:
          if (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
@@ -2659,11 +2679,10 @@ sparc64_elf_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);
 
@@ -2683,10 +2702,14 @@ sparc64_elf_relocate_section (output_bfd, info, input_bfd, input_section,
            /* The Solaris native linker silently disregards
               overflows.  We don't, but this breaks stabs debugging
               info, whose relocations are only 32-bits wide.  Ignore
-              overflows for discarded entries.  */
+              overflows in this case and also for discarded entries.  */
            if ((r_type == R_SPARC_32 || r_type == R_SPARC_DISP32)
-               && _bfd_elf_section_offset (output_bfd, info, input_section,
-                                           rel->r_offset) == (bfd_vma) -1)
+               && (((input_section->flags & SEC_DEBUGGING) != 0
+                    && strcmp (bfd_section_name (input_bfd, input_section),
+                              ".stab") == 0)
+                   || _bfd_elf_section_offset (output_bfd, info,
+                                               input_section,
+                                               rel->r_offset) == (bfd_vma)-1))
              break;
 
            if (h != NULL)
@@ -2702,7 +2725,7 @@ sparc64_elf_relocate_section (output_bfd, info, input_bfd, input_section,
                    break;
                  }
 
-               name = h->root.root.string;
+               name = NULL;
              }
            else
              {
@@ -2716,8 +2739,9 @@ sparc64_elf_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;
@@ -2765,7 +2789,7 @@ sparc64_elf_finish_dynamic_symbol (output_bfd, info, h, sym)
        }
       else
        {
-         bfd_vma max = splt->_raw_size / PLT_ENTRY_SIZE;
+         bfd_vma max = splt->size / PLT_ENTRY_SIZE;
          rela.r_offset = sparc64_elf_plt_ptr_offset (h->plt.offset, max);
          rela.r_addend = -(sparc64_elf_plt_entry_offset (h->plt.offset) + 4)
                          -(splt->output_section->vma + splt->output_offset);
@@ -2782,7 +2806,7 @@ sparc64_elf_finish_dynamic_symbol (output_bfd, info, h, sym)
       loc += (h->plt.offset - 4) * sizeof (Elf64_External_Rela);
       bfd_elf64_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.  */
@@ -2791,8 +2815,7 @@ sparc64_elf_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;
        }
     }
@@ -2806,8 +2829,8 @@ sparc64_elf_finish_dynamic_symbol (output_bfd, info, h, sym)
 
       /* This symbol has an entry in the GOT.  Set it up.  */
 
-      sgot = bfd_get_section_by_name (dynobj, ".got");
-      srela = bfd_get_section_by_name (dynobj, ".rela.got");
+      sgot = sparc64_elf_hash_table (info)->sgot;
+      srela = sparc64_elf_hash_table (info)->srelgot;
       BFD_ASSERT (sgot != NULL && srela != NULL);
 
       rela.r_offset = (sgot->output_section->vma
@@ -2821,7 +2844,7 @@ sparc64_elf_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 = ELF64_R_INFO (0, R_SPARC_RELATIVE);
@@ -2842,7 +2865,7 @@ sparc64_elf_finish_dynamic_symbol (output_bfd, info, h, sym)
       bfd_elf64_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;
@@ -2898,7 +2921,7 @@ sparc64_elf_finish_dynamic_sections (output_bfd, info)
       BFD_ASSERT (splt != NULL && sdyn != NULL);
 
       dyncon = (Elf64_External_Dyn *) sdyn->contents;
-      dynconend = (Elf64_External_Dyn *) (sdyn->contents + sdyn->_raw_size);
+      dynconend = (Elf64_External_Dyn *) (sdyn->contents + sdyn->size);
       for (; dyncon < dynconend; dyncon++)
        {
          Elf_Internal_Dyn dyn;
@@ -2938,21 +2961,16 @@ sparc64_elf_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_elf64_swap_dyn_out (output_bfd, &dyn, dyncon);
            }
        }
 
       /* Initialize the contents of the .plt section.  */
-      if (splt->_raw_size > 0)
+      if (splt->size > 0)
        sparc64_elf_build_plt (output_bfd, splt->contents,
-                              (int) (splt->_raw_size / PLT_ENTRY_SIZE));
+                              (int) (splt->size / PLT_ENTRY_SIZE));
 
       elf_section_data (splt->output_section)->this_hdr.sh_entsize =
        PLT_ENTRY_SIZE;
@@ -2960,9 +2978,9 @@ sparc64_elf_finish_dynamic_sections (output_bfd, info)
 
   /* Set the first entry in the global offset table to the address of
      the dynamic section.  */
-  sgot = bfd_get_section_by_name (dynobj, ".got");
+  sgot = sparc64_elf_hash_table (info)->sgot;
   BFD_ASSERT (sgot != NULL);
-  if (sgot->_raw_size > 0)
+  if (sgot->size > 0)
     {
       if (sdyn == NULL)
        bfd_put_64 (output_bfd, (bfd_vma) 0, sgot->contents);
@@ -3050,8 +3068,8 @@ sparc64_elf_merge_private_bfd_data (ibfd, obfd)
            {
              error = TRUE;
              (*_bfd_error_handler)
-               (_("%s: linking UltraSPARC specific with HAL specific code"),
-                bfd_archive_filename (ibfd));
+               (_("%B: linking UltraSPARC specific with HAL specific code"),
+                ibfd);
            }
          /* Choose the most restrictive memory ordering.  */
          old_mm = (old_flags & EF_SPARCV9_MM);
@@ -3069,8 +3087,8 @@ sparc64_elf_merge_private_bfd_data (ibfd, obfd)
         {
           error = TRUE;
           (*_bfd_error_handler)
-            (_("%s: uses different e_flags (0x%lx) fields than previous modules (0x%lx)"),
-             bfd_archive_filename (ibfd), (long) new_flags, (long) old_flags);
+            (_("%B: uses different e_flags (0x%lx) fields than previous modules (0x%lx)"),
+             ibfd, (long) new_flags, (long) old_flags);
         }
 
       elf_elfheader (obfd)->e_flags = old_flags;
@@ -3148,6 +3166,24 @@ sparc64_elf_object_p (abfd)
   return bfd_default_set_arch_mach (abfd, bfd_arch_sparc, mach);
 }
 
+/* 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
+sparc64_elf_plt_sym_val (bfd_vma i, const asection *plt,
+                        const arelent *rel ATTRIBUTE_UNUSED)
+{
+  bfd_vma j;
+
+  i += PLT_HEADER_SIZE / PLT_ENTRY_SIZE;
+  if (i < LARGE_PLT_THRESHOLD)
+    return plt->vma + i * PLT_ENTRY_SIZE;
+
+  j = (i - LARGE_PLT_THRESHOLD) % 160;
+  i -= j;
+  return plt->vma + i * PLT_ENTRY_SIZE + j * 4 * 6;
+}
+
 /* Relocations in the 64 bit SPARC ELF ABI are more complex than in
    standard ELF, because R_SPARC_OLO10 has secondary addend in
    ELF64_R_TYPE_DATA field.  This structure is used to redirect the
@@ -3220,7 +3256,7 @@ const struct elf_size_info sparc64_elf_size_info =
   sparc64_elf_new_section_hook
 
 #define elf_backend_create_dynamic_sections \
-  _bfd_elf_create_dynamic_sections
+  sparc64_elf_create_dynamic_sections
 #define elf_backend_add_symbol_hook \
   sparc64_elf_add_symbol_hook
 #define elf_backend_get_symbol_type \
@@ -3231,6 +3267,8 @@ const struct elf_size_info sparc64_elf_size_info =
   sparc64_elf_check_relocs
 #define elf_backend_adjust_dynamic_symbol \
   sparc64_elf_adjust_dynamic_symbol
+#define elf_backend_omit_section_dynsym \
+  sparc64_elf_omit_section_dynsym
 #define elf_backend_size_dynamic_sections \
   sparc64_elf_size_dynamic_sections
 #define elf_backend_relocate_section \
@@ -3247,6 +3285,8 @@ const struct elf_size_info sparc64_elf_size_info =
   sparc64_elf_merge_private_bfd_data
 #define elf_backend_fake_sections \
   sparc64_elf_fake_sections
+#define elf_backend_plt_sym_val        \
+  sparc64_elf_plt_sym_val
 
 #define elf_backend_size_info \
   sparc64_elf_size_info
@@ -3264,6 +3304,5 @@ const struct elf_size_info sparc64_elf_size_info =
 #define elf_backend_plt_alignment 8
 
 #define elf_backend_got_header_size 8
-#define elf_backend_plt_header_size PLT_HEADER_SIZE
 
 #include "elf64-target.h"
This page took 0.038225 seconds and 4 git commands to generate.