* m68klinux-nat.c: Include "gdb_proc_service.h".
[deliverable/binutils-gdb.git] / bfd / elf32-vax.c
index 919bcf601e80c5b56a0aa418d40b554e925aaea0..643381c5c43b8311f232c272df395e8610c727a1 100644 (file)
@@ -1,13 +1,14 @@
 /* VAX series support for 32-bit ELF
    Copyright 1993, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
-   2004, 2005 Free Software Foundation, Inc.
+   2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
+   Free Software Foundation, Inc.
    Contributed by Matt Thomas <matt@3am-software.com>.
 
    This file is part of BFD, the Binary File Descriptor library.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
+   the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
 
    This program is distributed in the hope that it will be useful,
 
    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 02110-1301, USA.  */
+   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
+   MA 02110-1301, USA.  */
 
-#include "bfd.h"
 #include "sysdep.h"
+#include "bfd.h"
 #include "bfdlink.h"
 #include "libbfd.h"
 #include "elf-bfd.h"
 #include "elf/vax.h"
 
-static reloc_howto_type *reloc_type_lookup
-  PARAMS ((bfd *, bfd_reloc_code_real_type));
-static void rtype_to_howto
-  PARAMS ((bfd *, arelent *, Elf_Internal_Rela *));
-static struct bfd_hash_entry *elf_vax_link_hash_newfunc
-  PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *));
-static struct bfd_link_hash_table *elf_vax_link_hash_table_create
-  PARAMS ((bfd *));
-static bfd_boolean elf_vax_check_relocs
-  PARAMS ((bfd *, struct bfd_link_info *, asection *,
-          const Elf_Internal_Rela *));
-static asection *elf_vax_gc_mark_hook
-  PARAMS ((asection *, struct bfd_link_info *, Elf_Internal_Rela *,
-          struct elf_link_hash_entry *, Elf_Internal_Sym *));
-static bfd_boolean elf_vax_gc_sweep_hook
-  PARAMS ((bfd *, struct bfd_link_info *, asection *,
-          const Elf_Internal_Rela *));
-static bfd_boolean elf_vax_adjust_dynamic_symbol
-  PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *));
-static bfd_boolean elf_vax_size_dynamic_sections
-  PARAMS ((bfd *, struct bfd_link_info *));
-static bfd_boolean elf_vax_relocate_section
-  PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
-          Elf_Internal_Rela *, Elf_Internal_Sym *, asection **));
-static bfd_boolean elf_vax_finish_dynamic_symbol
-  PARAMS ((bfd *, struct bfd_link_info *, struct elf_link_hash_entry *,
-          Elf_Internal_Sym *));
-static bfd_boolean elf_vax_finish_dynamic_sections
-  PARAMS ((bfd *, struct bfd_link_info *));
-
-static bfd_boolean elf32_vax_set_private_flags
-  PARAMS ((bfd *, flagword));
-static bfd_boolean elf32_vax_merge_private_bfd_data
-  PARAMS ((bfd *, bfd *));
-static bfd_boolean elf32_vax_print_private_bfd_data
-  PARAMS ((bfd *, PTR));
+static reloc_howto_type *reloc_type_lookup (bfd *, bfd_reloc_code_real_type);
+static void rtype_to_howto (bfd *, arelent *, Elf_Internal_Rela *);
+static struct bfd_hash_entry *elf_vax_link_hash_newfunc (struct bfd_hash_entry *,
+                                                        struct bfd_hash_table *,
+                                                        const char *);
+static struct bfd_link_hash_table *elf_vax_link_hash_table_create (bfd *);
+static bfd_boolean elf_vax_check_relocs (bfd *, struct bfd_link_info *,
+                                        asection *, const Elf_Internal_Rela *);
+static bfd_boolean elf_vax_adjust_dynamic_symbol (struct bfd_link_info *,
+                                                 struct elf_link_hash_entry *);
+static bfd_boolean elf_vax_size_dynamic_sections (bfd *, struct bfd_link_info *);
+static bfd_boolean elf_vax_relocate_section (bfd *, struct bfd_link_info *,
+                                            bfd *, asection *, bfd_byte *,
+                                            Elf_Internal_Rela *,
+                                            Elf_Internal_Sym *, asection **);
+static bfd_boolean elf_vax_finish_dynamic_symbol (bfd *, struct bfd_link_info *,
+                                                 struct elf_link_hash_entry *,
+                                                 Elf_Internal_Sym *);
+static bfd_boolean elf_vax_finish_dynamic_sections (bfd *,
+                                                   struct bfd_link_info *);
+static bfd_vma elf_vax_plt_sym_val (bfd_vma, const asection *,
+                                   const arelent *);
+
+static bfd_boolean elf32_vax_set_private_flags (bfd *, flagword);
+static bfd_boolean elf32_vax_merge_private_bfd_data (bfd *, bfd *);
+static bfd_boolean elf32_vax_print_private_bfd_data (bfd *, PTR);
 
 static reloc_howto_type howto_table[] = {
   HOWTO (R_VAX_NONE,           /* type */
@@ -290,10 +282,8 @@ static reloc_howto_type howto_table[] = {
 };
 
 static void
-rtype_to_howto (abfd, cache_ptr, dst)
-     bfd *abfd ATTRIBUTE_UNUSED;
-     arelent *cache_ptr;
-     Elf_Internal_Rela *dst;
+rtype_to_howto (bfd *abfd ATTRIBUTE_UNUSED, arelent *cache_ptr,
+               Elf_Internal_Rela *dst)
 {
   BFD_ASSERT (ELF32_R_TYPE(dst->r_info) < (unsigned int) R_VAX_max);
   cache_ptr->howto = &howto_table[ELF32_R_TYPE(dst->r_info)];
@@ -325,9 +315,7 @@ static const struct
 };
 
 static reloc_howto_type *
-reloc_type_lookup (abfd, code)
-     bfd *abfd ATTRIBUTE_UNUSED;
-     bfd_reloc_code_real_type code;
+reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED, bfd_reloc_code_real_type code)
 {
   unsigned int i;
   for (i = 0; i < sizeof (reloc_map) / sizeof (reloc_map[0]); i++)
@@ -338,7 +326,22 @@ reloc_type_lookup (abfd, code)
   return 0;
 }
 
+static reloc_howto_type *
+reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
+                  const char *r_name)
+{
+  unsigned int i;
+
+  for (i = 0; i < sizeof (howto_table) / sizeof (howto_table[0]); i++)
+    if (howto_table[i].name != NULL
+       && strcasecmp (howto_table[i].name, r_name) == 0)
+      return &howto_table[i];
+
+  return NULL;
+}
+
 #define bfd_elf32_bfd_reloc_type_lookup reloc_type_lookup
+#define bfd_elf32_bfd_reloc_name_lookup reloc_name_lookup
 #define ELF_ARCH bfd_arch_vax
 /* end code generated by elf.el */
 \f
@@ -368,8 +371,8 @@ static const bfd_byte elf_vax_plt0_entry[PLT_ENTRY_SIZE] =
 
 static const bfd_byte elf_vax_plt_entry[PLT_ENTRY_SIZE] =
 {
-  0x40, 0x00,          /* .word ^M<r6> */
-  0x16,        0xef,           /* jsb L^(pc) */
+  0xfc, 0x0f,          /* .word ^M<r11:r2> */
+  0x16, 0xef,          /* jsb L^(pc) */
   0, 0, 0, 0,          /* replaced with offset to start of .plt  */
   0, 0, 0, 0,          /* index into .rela.plt */
 };
@@ -405,61 +408,48 @@ struct elf_vax_link_hash_entry
   bfd_vma got_addend;
 };
 
-/* VAX ELF linker hash table.  */
-
-struct elf_vax_link_hash_table
-{
-  struct elf_link_hash_table root;
-};
-
 /* Declare this now that the above structures are defined.  */
 
-static bfd_boolean elf_vax_discard_copies
-  PARAMS ((struct elf_vax_link_hash_entry *, PTR));
+static bfd_boolean elf_vax_discard_copies (struct elf_vax_link_hash_entry *,
+                                          void *);
 
 /* Declare this now that the above structures are defined.  */
 
-static bfd_boolean elf_vax_instantiate_got_entries
-  PARAMS ((struct elf_link_hash_entry *, PTR));
+static bfd_boolean elf_vax_instantiate_got_entries (struct elf_link_hash_entry *,
+                                                   void *);
 
 /* Traverse an VAX ELF linker hash table.  */
 
 #define elf_vax_link_hash_traverse(table, func, info)                  \
   (elf_link_hash_traverse                                              \
-   (&(table)->root,                                                    \
-    (bfd_boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \
+   ((table),                                                           \
+    (bfd_boolean (*) (struct elf_link_hash_entry *, PTR)) (func),      \
     (info)))
 
-/* Get the VAX ELF linker hash table from a link_info structure.  */
-
-#define elf_vax_hash_table(p) \
-  ((struct elf_vax_link_hash_table *) (p)->hash)
-
 /* Create an entry in an VAX ELF linker hash table.  */
 
 static struct bfd_hash_entry *
-elf_vax_link_hash_newfunc (entry, table, string)
-     struct bfd_hash_entry *entry;
-     struct bfd_hash_table *table;
-     const char *string;
+elf_vax_link_hash_newfunc (struct bfd_hash_entry *entry,
+                          struct bfd_hash_table *table,
+                          const char *string)
 {
   struct elf_vax_link_hash_entry *ret =
     (struct elf_vax_link_hash_entry *) entry;
 
   /* Allocate the structure if it has not already been allocated by a
      subclass.  */
-  if (ret == (struct elf_vax_link_hash_entry *) NULL)
+  if (ret == NULL)
     ret = ((struct elf_vax_link_hash_entry *)
           bfd_hash_allocate (table,
                              sizeof (struct elf_vax_link_hash_entry)));
-  if (ret == (struct elf_vax_link_hash_entry *) NULL)
+  if (ret == NULL)
     return (struct bfd_hash_entry *) ret;
 
   /* Call the allocation method of the superclass.  */
   ret = ((struct elf_vax_link_hash_entry *)
         _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret,
                                     table, string));
-  if (ret != (struct elf_vax_link_hash_entry *) NULL)
+  if (ret != NULL)
     {
       ret->pcrel_relocs_copied = NULL;
     }
@@ -470,31 +460,30 @@ elf_vax_link_hash_newfunc (entry, table, string)
 /* Create an VAX ELF linker hash table.  */
 
 static struct bfd_link_hash_table *
-elf_vax_link_hash_table_create (abfd)
-     bfd *abfd;
+elf_vax_link_hash_table_create (bfd *abfd)
 {
-  struct elf_vax_link_hash_table *ret;
-  bfd_size_type amt = sizeof (struct elf_vax_link_hash_table);
+  struct elf_link_hash_table *ret;
+  bfd_size_type amt = sizeof (struct elf_link_hash_table);
 
-  ret = (struct elf_vax_link_hash_table *) bfd_malloc (amt);
-  if (ret == (struct elf_vax_link_hash_table *) NULL)
+  ret = bfd_malloc (amt);
+  if (ret == NULL)
     return NULL;
 
-  if (! _bfd_elf_link_hash_table_init (&ret->root, abfd,
-                                      elf_vax_link_hash_newfunc))
+  if (!_bfd_elf_link_hash_table_init (ret, abfd,
+                                     elf_vax_link_hash_newfunc,
+                                     sizeof (struct elf_vax_link_hash_entry),
+                                     GENERIC_ELF_DATA))
     {
       free (ret);
       return NULL;
     }
 
-  return &ret->root.root;
+  return &ret->root;
 }
 
 /* Keep vax-specific flags in the ELF header */
 static bfd_boolean
-elf32_vax_set_private_flags (abfd, flags)
-     bfd *abfd;
-     flagword flags;
+elf32_vax_set_private_flags (bfd *abfd, flagword flags)
 {
   elf_elfheader (abfd)->e_flags = flags;
   elf_flags_init (abfd) = TRUE;
@@ -504,11 +493,8 @@ elf32_vax_set_private_flags (abfd, flags)
 /* Merge backend specific data from an object file to the output
    object file when linking.  */
 static bfd_boolean
-elf32_vax_merge_private_bfd_data (ibfd, obfd)
-     bfd *ibfd;
-     bfd *obfd;
+elf32_vax_merge_private_bfd_data (bfd *ibfd, bfd *obfd)
 {
-  flagword out_flags;
   flagword in_flags;
 
   if (   bfd_get_flavour (ibfd) != bfd_target_elf_flavour
@@ -516,7 +502,6 @@ elf32_vax_merge_private_bfd_data (ibfd, obfd)
     return TRUE;
 
   in_flags  = elf_elfheader (ibfd)->e_flags;
-  out_flags = elf_elfheader (obfd)->e_flags;
 
   if (!elf_flags_init (obfd))
     {
@@ -529,9 +514,7 @@ elf32_vax_merge_private_bfd_data (ibfd, obfd)
 
 /* Display the flags field */
 static bfd_boolean
-elf32_vax_print_private_bfd_data (abfd, ptr)
-     bfd *abfd;
-     PTR ptr;
+elf32_vax_print_private_bfd_data (bfd *abfd, PTR ptr)
 {
   FILE *file = (FILE *) ptr;
 
@@ -563,11 +546,8 @@ elf32_vax_print_private_bfd_data (abfd, ptr)
    table.  */
 
 static bfd_boolean
-elf_vax_check_relocs (abfd, info, sec, relocs)
-     bfd *abfd;
-     struct bfd_link_info *info;
-     asection *sec;
-     const Elf_Internal_Rela *relocs;
+elf_vax_check_relocs (bfd *abfd, struct bfd_link_info *info, asection *sec,
+                     const Elf_Internal_Rela *relocs)
 {
   bfd *dynobj;
   Elf_Internal_Shdr *symtab_hdr;
@@ -600,13 +580,25 @@ elf_vax_check_relocs (abfd, info, sec, relocs)
       if (r_symndx < symtab_hdr->sh_info)
        h = NULL;
       else
-       h = sym_hashes[r_symndx - symtab_hdr->sh_info];
+       {
+         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;
+       }
 
       switch (ELF32_R_TYPE (rel->r_info))
        {
        case R_VAX_GOT32:
-         if (h != NULL
-             && strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
+         BFD_ASSERT (h != NULL);
+         if (h->forced_local
+             || h == elf_hash_table (info)->hgot
+             || h == elf_hash_table (info)->hplt)
+           break;
+
+         /* If this is a local symbol, we resolve it directly without
+            creating a global offset table entry.  */
+         if (h == NULL || ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
            break;
 
          /* This symbol requires a global offset table entry.  */
@@ -631,15 +623,15 @@ elf_vax_check_relocs (abfd, info, sec, relocs)
              srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
              if (srelgot == NULL)
                {
-                 srelgot = bfd_make_section (dynobj, ".rela.got");
+                 srelgot = bfd_make_section_with_flags (dynobj,
+                                                        ".rela.got",
+                                                        (SEC_ALLOC
+                                                         | SEC_LOAD
+                                                         | SEC_HAS_CONTENTS
+                                                         | SEC_IN_MEMORY
+                                                         | SEC_LINKER_CREATED
+                                                         | SEC_READONLY));
                  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, 2))
                    return FALSE;
                }
@@ -660,10 +652,11 @@ elf_vax_check_relocs (abfd, info, sec, relocs)
                  h->got.refcount++;
                  if (eh->got_addend != (bfd_vma) rel->r_addend)
                    (*_bfd_error_handler)
-                     (_("%s: warning: GOT addend of %ld to `%s' does not match previous GOT addend of %ld"),
-                             bfd_get_filename (abfd), rel->r_addend,
-                             h->root.root.string,
-                             eh->got_addend);
+                     (_("%s: warning: GOT addend of %ld to `%s' does"
+                        " not match previous GOT addend of %ld"),
+                        bfd_get_filename (abfd), rel->r_addend,
+                        h->root.root.string,
+                        eh->got_addend);
 
                }
            }
@@ -679,8 +672,9 @@ elf_vax_check_relocs (abfd, info, sec, relocs)
 
          /* If this is a local symbol, we resolve it directly without
             creating a procedure linkage table entry.  */
-         if (h == NULL)
-           continue;
+         BFD_ASSERT (h != NULL);
+         if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT || h->forced_local)
+           break;
 
          h->needs_plt = 1;
          if (h->plt.refcount == -1)
@@ -708,7 +702,9 @@ elf_vax_check_relocs (abfd, info, sec, relocs)
                && (!info->symbolic
                    || !h->def_regular)))
            {
-             if (h != NULL)
+             if (h != NULL
+                 && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
+                 && !h->forced_local)
                {
                  /* Make sure a plt entry is created for this symbol if
                     it turns out to be a function defined by a dynamic
@@ -720,11 +716,17 @@ elf_vax_check_relocs (abfd, info, sec, relocs)
                }
              break;
            }
+         /* If this is a local symbol, we can resolve it directly.  */
+         if (h != NULL
+             && (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
+                 || h->forced_local))
+           break;
+
          /* Fall through.  */
        case R_VAX_8:
        case R_VAX_16:
        case R_VAX_32:
-         if (h != NULL)
+         if (h != NULL && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
            {
              /* Make sure a plt entry is created for this symbol if it
                 turns out to be a function defined by a dynamic object.  */
@@ -744,34 +746,12 @@ elf_vax_check_relocs (abfd, info, sec, relocs)
                 section in dynobj and make room for this reloc.  */
              if (sreloc == NULL)
                {
-                 const char *name;
+                 sreloc = _bfd_elf_make_dynamic_reloc_section
+                   (sec, dynobj, 2, abfd, /*rela?*/ TRUE);
 
-                 name = (bfd_elf_string_from_elf_section
-                         (abfd,
-                          elf_elfheader (abfd)->e_shstrndx,
-                          elf_section_data (sec)->rel_hdr.sh_name));
-                 if (name == NULL)
+                 if (sreloc == NULL)
                    return FALSE;
 
-                 BFD_ASSERT (strncmp (name, ".rela", 5) == 0
-                             && strcmp (bfd_get_section_name (abfd, sec),
-                                        name + 5) == 0);
-
-                 sreloc = bfd_get_section_by_name (dynobj, name);
-                 if (sreloc == NULL)
-                   {
-                     sreloc = bfd_make_section (dynobj, name);
-                     if (sreloc == NULL
-                         || !bfd_set_section_flags (dynobj, sreloc,
-                                                    (SEC_ALLOC
-                                                     | SEC_LOAD
-                                                     | SEC_HAS_CONTENTS
-                                                     | SEC_IN_MEMORY
-                                                     | SEC_LINKER_CREATED
-                                                     | SEC_READONLY))
-                         || !bfd_set_section_alignment (dynobj, sreloc, 2))
-                       return FALSE;
-                   }
                  if (sec->flags & SEC_READONLY)
                    info->flags |= DF_TEXTREL;
                }
@@ -786,8 +766,8 @@ elf_vax_check_relocs (abfd, info, sec, relocs)
                 which means that h is really a pointer to an
                 elf_vax_link_hash_entry.  */
              if ((ELF32_R_TYPE (rel->r_info) == R_VAX_PC8
-                  || ELF32_R_TYPE (rel->r_info) == R_VAX_PC16
-                  || ELF32_R_TYPE (rel->r_info) == R_VAX_PC32)
+                  || ELF32_R_TYPE (rel->r_info) == R_VAX_PC16
+                  || ELF32_R_TYPE (rel->r_info) == R_VAX_PC32)
                  && info->symbolic)
                {
                  struct elf_vax_link_hash_entry *eh;
@@ -827,7 +807,9 @@ elf_vax_check_relocs (abfd, info, sec, relocs)
          /* This relocation describes which C++ vtable entries are actually
             used.  Record for later use during GC.  */
        case R_VAX_GNU_VTENTRY:
-         if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
+         BFD_ASSERT (h != NULL);
+         if (h != NULL
+             && !bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
            return FALSE;
          break;
 
@@ -843,56 +825,37 @@ elf_vax_check_relocs (abfd, info, sec, relocs)
    relocation.  */
 
 static asection *
-elf_vax_gc_mark_hook (sec, info, rel, h, sym)
-     asection *sec;
-     struct bfd_link_info *info ATTRIBUTE_UNUSED;
-     Elf_Internal_Rela *rel;
-     struct elf_link_hash_entry *h;
-     Elf_Internal_Sym *sym;
+elf_vax_gc_mark_hook (asection *sec,
+                     struct bfd_link_info *info,
+                     Elf_Internal_Rela *rel,
+                     struct elf_link_hash_entry *h,
+                     Elf_Internal_Sym *sym)
 {
   if (h != NULL)
-    {
-      switch (ELF32_R_TYPE (rel->r_info))
-       {
-       case R_VAX_GNU_VTINHERIT:
-       case R_VAX_GNU_VTENTRY:
-         break;
-
-       default:
-         switch (h->root.type)
-           {
-           default:
-             break;
-
-           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;
-           }
-       }
-    }
-  else
-    return bfd_section_from_elf_index (sec->owner, sym->st_shndx);
-
-  return NULL;
+    switch (ELF32_R_TYPE (rel->r_info))
+      {
+      case R_VAX_GNU_VTINHERIT:
+      case R_VAX_GNU_VTENTRY:
+       return NULL;
+      }
+
+  return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
 }
 
 /* Update the got entry reference counts for the section being removed.  */
 
 static bfd_boolean
-elf_vax_gc_sweep_hook (abfd, info, sec, relocs)
-     bfd *abfd;
-     struct bfd_link_info *info;
-     asection *sec;
-     const Elf_Internal_Rela *relocs;
+elf_vax_gc_sweep_hook (bfd *abfd, struct bfd_link_info *info, asection *sec,
+                      const Elf_Internal_Rela *relocs)
 {
   Elf_Internal_Shdr *symtab_hdr;
   struct elf_link_hash_entry **sym_hashes;
   const Elf_Internal_Rela *rel, *relend;
   bfd *dynobj;
 
+  if (info->relocatable)
+    return TRUE;
+
   dynobj = elf_hash_table (info)->dynobj;
   if (dynobj == NULL)
     return TRUE;
@@ -954,7 +917,6 @@ elf_vax_adjust_dynamic_symbol (info, h)
 {
   bfd *dynobj;
   asection *s;
-  unsigned int power_of_two;
 
   dynobj = elf_hash_table (info)->dynobj;
 
@@ -1074,6 +1036,13 @@ elf_vax_adjust_dynamic_symbol (info, h)
   if (info->shared)
     return TRUE;
 
+  if (h->size == 0)
+    {
+      (*_bfd_error_handler) (_("dynamic variable `%s' is zero size"),
+                            h->root.root.string);
+      return TRUE;
+    }
+
   /* We must allocate the symbol in our .dynbss section, which will
      become part of the .bss section of the executable.  There will be
      an entry for this symbol in the .dynsym section.  The dynamic
@@ -1101,36 +1070,13 @@ elf_vax_adjust_dynamic_symbol (info, h)
       h->needs_copy = 1;
     }
 
-  /* We need to figure out the alignment required for this symbol.  I
-     have no idea how ELF linkers handle this.  */
-  power_of_two = bfd_log2 (h->size);
-  if (power_of_two > 3)
-    power_of_two = 3;
-
-  /* Apply the required alignment.  */
-  s->size = BFD_ALIGN (s->size, (bfd_size_type) (1 << power_of_two));
-  if (power_of_two > bfd_get_section_alignment (dynobj, s))
-    {
-      if (!bfd_set_section_alignment (dynobj, s, power_of_two))
-       return FALSE;
-    }
-
-  /* Define the symbol as being at this point in the section.  */
-  h->root.u.def.section = s;
-  h->root.u.def.value = s->size;
-
-  /* Increment the section size to make room for the symbol.  */
-  s->size += h->size;
-
-  return TRUE;
+  return _bfd_elf_adjust_dynamic_copy (h, s);
 }
 
 /* Set the sizes of the dynamic sections.  */
 
 static bfd_boolean
-elf_vax_size_dynamic_sections (output_bfd, info)
-     bfd *output_bfd;
-     struct bfd_link_info *info;
+elf_vax_size_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info)
 {
   bfd *dynobj;
   asection *s;
@@ -1175,9 +1121,9 @@ elf_vax_size_dynamic_sections (output_bfd, info)
      allocated space for them in the check_relocs routine, but we will not
      fill them in in the relocate_section routine.  */
   if (info->shared && info->symbolic)
-    elf_vax_link_hash_traverse (elf_vax_hash_table (info),
+    elf_vax_link_hash_traverse (elf_hash_table (info),
                                elf_vax_discard_copies,
-                               (PTR) NULL);
+                               NULL);
 
   /* If this is a -Bsymbolic shared link or a static link, we need to
      discard all the got entries we've recorded.  Otherwise, we need to
@@ -1195,7 +1141,6 @@ elf_vax_size_dynamic_sections (output_bfd, info)
   for (s = dynobj->sections; s != NULL; s = s->next)
     {
       const char *name;
-      bfd_boolean strip;
 
       if ((s->flags & SEC_LINKER_CREATED) == 0)
        continue;
@@ -1204,38 +1149,14 @@ elf_vax_size_dynamic_sections (output_bfd, info)
         of the dynobj section names depend upon the input files.  */
       name = bfd_get_section_name (dynobj, s);
 
-      strip = FALSE;
-
       if (strcmp (name, ".plt") == 0)
        {
-         if (s->size == 0)
-           {
-             /* Strip this section if we don't need it; see the
-                 comment below.  */
-             strip = TRUE;
-           }
-         else
-           {
-             /* Remember whether there is a PLT.  */
-             plt = TRUE;
-           }
+         /* Remember whether there is a PLT.  */
+         plt = s->size != 0;
        }
-      else if (strncmp (name, ".rela", 5) == 0)
+      else if (CONST_STRNEQ (name, ".rela"))
        {
-         if (s->size == 0)
-           {
-             /* If we don't need this section, strip it from the
-                output file.  This is mostly to handle .rela.bss and
-                .rela.plt.  We must create both sections in
-                create_dynamic_sections, because they must be created
-                before the linker maps input sections to output
-                sections.  The linker does that before
-                adjust_dynamic_symbol is called, and it is that
-                function which decides whether anything needs to go
-                into these sections.  */
-             strip = TRUE;
-           }
-         else
+         if (s->size != 0)
            {
              asection *target;
 
@@ -1265,21 +1186,34 @@ elf_vax_size_dynamic_sections (output_bfd, info)
              s->reloc_count = 0;
            }
        }
-      else if (strncmp (name, ".got", 4) != 0)
+      else if (! CONST_STRNEQ (name, ".got")
+              && strcmp (name, ".dynbss") != 0)
        {
          /* It's not one of our sections, so don't allocate space.  */
          continue;
        }
 
-      if (strip)
+      if (s->size == 0)
        {
+         /* If we don't need this section, strip it from the
+            output file.  This is mostly to handle .rela.bss and
+            .rela.plt.  We must create both sections in
+            create_dynamic_sections, because they must be created
+            before the linker maps input sections to output
+            sections.  The linker does that before
+            adjust_dynamic_symbol is called, and it is that
+            function which decides whether anything needs to go
+            into these sections.  */
          s->flags |= SEC_EXCLUDE;
          continue;
        }
 
+      if ((s->flags & SEC_HAS_CONTENTS) == 0)
+       continue;
+
       /* Allocate memory for the section contents.  */
       s->contents = (bfd_byte *) bfd_alloc (dynobj, s->size);
-      if (s->contents == NULL && s->size != 0)
+      if (s->contents == NULL)
        return FALSE;
     }
 
@@ -1334,15 +1268,11 @@ elf_vax_size_dynamic_sections (output_bfd, info)
    routine, but we won't fill them in in the relocate_section routine.  */
 
 static bfd_boolean
-elf_vax_discard_copies (h, ignore)
-     struct elf_vax_link_hash_entry *h;
-     PTR ignore ATTRIBUTE_UNUSED;
+elf_vax_discard_copies (struct elf_vax_link_hash_entry *h,
+                       PTR ignore ATTRIBUTE_UNUSED)
 {
   struct elf_vax_pcrel_relocs_copied *s;
 
-  if (h->root.root.type == bfd_link_hash_warning)
-    h = (struct elf_vax_link_hash_entry *) h->root.root.u.i.link;
-
   /* We only discard relocs for symbols defined in a regular object.  */
   if (!h->root.def_regular)
     return TRUE;
@@ -1361,9 +1291,7 @@ elf_vax_discard_copies (h, ignore)
    will be reserved for the symbol.  */
 
 static bfd_boolean
-elf_vax_instantiate_got_entries (h, infoptr)
-     struct elf_link_hash_entry *h;
-     PTR infoptr;
+elf_vax_instantiate_got_entries (struct elf_link_hash_entry *h, PTR infoptr)
 {
   struct bfd_link_info *info = (struct bfd_link_info *) infoptr;
   bfd *dynobj;
@@ -1382,7 +1310,8 @@ elf_vax_instantiate_got_entries (h, infoptr)
   srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
 
   if (!elf_hash_table (info)->dynamic_sections_created
-      || (info->shared && info->symbolic))
+      || (info->shared && info->symbolic)
+      || h->forced_local)
     {
       h->got.refcount = 0;
       h->got.offset = (bfd_vma) -1;
@@ -1391,6 +1320,8 @@ elf_vax_instantiate_got_entries (h, infoptr)
     }
   else if (h->got.refcount > 0)
     {
+      bfd_boolean dyn;
+
       /* Make sure this symbol is output as a dynamic symbol.  */
       if (h->dynindx == -1)
        {
@@ -1398,9 +1329,15 @@ elf_vax_instantiate_got_entries (h, infoptr)
            return FALSE;
        }
 
+      dyn = elf_hash_table (info)->dynamic_sections_created;
       /* Allocate space in the .got and .rela.got sections.  */
-      sgot->size += 4;
-      srelgot->size += sizeof (Elf32_External_Rela);
+      if (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
+         && (info->shared
+             || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h)))
+       {
+         sgot->size += 4;
+         srelgot->size += sizeof (Elf32_External_Rela);
+       }
     }
 
   return TRUE;
@@ -1409,21 +1346,18 @@ elf_vax_instantiate_got_entries (h, infoptr)
 /* Relocate an VAX ELF section.  */
 
 static bfd_boolean
-elf_vax_relocate_section (output_bfd, info, input_bfd, input_section,
-                          contents, relocs, local_syms, local_sections)
-     bfd *output_bfd;
-     struct bfd_link_info *info;
-     bfd *input_bfd;
-     asection *input_section;
-     bfd_byte *contents;
-     Elf_Internal_Rela *relocs;
-     Elf_Internal_Sym *local_syms;
-     asection **local_sections;
+elf_vax_relocate_section (bfd *output_bfd,
+                         struct bfd_link_info *info,
+                         bfd *input_bfd,
+                         asection *input_section,
+                         bfd_byte *contents,
+                         Elf_Internal_Rela *relocs,
+                         Elf_Internal_Sym *local_syms,
+                         asection **local_sections)
 {
   bfd *dynobj;
   Elf_Internal_Shdr *symtab_hdr;
   struct elf_link_hash_entry **sym_hashes;
-  bfd_vma *local_got_offsets;
   bfd_vma plt_index;
   bfd_vma got_offset;
   asection *sgot;
@@ -1433,13 +1367,9 @@ elf_vax_relocate_section (output_bfd, info, input_bfd, input_section,
   Elf_Internal_Rela *rel;
   Elf_Internal_Rela *relend;
 
-  if (info->relocatable)
-    return TRUE;
-
   dynobj = elf_hash_table (info)->dynobj;
   symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
   sym_hashes = elf_sym_hashes (input_bfd);
-  local_got_offsets = elf_local_got_offsets (input_bfd);
 
   sgot = NULL;
   splt = NULL;
@@ -1467,7 +1397,6 @@ elf_vax_relocate_section (output_bfd, info, input_bfd, input_section,
        }
       howto = howto_table + r_type;
 
-      /* This is a final link.  */
       r_symndx = ELF32_R_SYM (rel->r_info);
       h = NULL;
       sym = NULL;
@@ -1487,15 +1416,16 @@ elf_vax_relocate_section (output_bfd, info, input_bfd, input_section,
                                   r_symndx, symtab_hdr, sym_hashes,
                                   h, sec, relocation,
                                   unresolved_reloc, warned);
-          
+
          if ((h->root.type == bfd_link_hash_defined
              || h->root.type == bfd_link_hash_defweak)
              && ((r_type == R_VAX_PLT32
                   && h->plt.offset != (bfd_vma) -1
+                  && !h->forced_local
                   && elf_hash_table (info)->dynamic_sections_created)
                  || (r_type == R_VAX_GOT32
-                     && strcmp (h->root.root.string,
-                                "_GLOBAL_OFFSET_TABLE_") != 0
+                     && h->got.offset != (bfd_vma) -1
+                     && !h->forced_local
                      && elf_hash_table (info)->dynamic_sections_created
                      && (! info->shared
                          || (! info->symbolic && h->dynindx != -1)
@@ -1513,28 +1443,36 @@ elf_vax_relocate_section (output_bfd, info, input_bfd, input_section,
                              && h->def_dynamic))
                      && (r_type == R_VAX_8
                          || r_type == R_VAX_16
-                         || r_type == R_VAX_32
-                         || r_type == R_VAX_PC8
-                         || r_type == R_VAX_PC16
-                         || r_type == R_VAX_PC32))))
+                         || r_type == R_VAX_32))))
            /* In these cases, we don't need the relocation
               value.  We check specially because in some
               obscure cases sec->output_section will be NULL.  */
            relocation = 0;
        }
 
+      if (sec != NULL && elf_discarded_section (sec))
+       RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section,
+                                        rel, relend, howto, contents);
+
+      if (info->relocatable)
+       continue;
+
       switch (r_type)
        {
        case R_VAX_GOT32:
          /* Relocation is to the address of the entry for this symbol
             in the global offset table.  */
-         if (h == NULL || h->got.offset == (bfd_vma) -1)
+         if (h == NULL
+             || ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
+             || h->got.offset == (bfd_vma) -1
+             || h->forced_local)
            break;
 
          /* Relocation is the offset of the entry for this symbol in
             the global offset table.  */
 
          {
+           bfd_boolean dyn;
            bfd_vma off;
 
            if (sgot == NULL)
@@ -1548,9 +1486,10 @@ elf_vax_relocate_section (output_bfd, info, input_bfd, input_section,
            BFD_ASSERT (off != (bfd_vma) -1);
            BFD_ASSERT (off < sgot->size);
 
-           if (info->shared
-               && h->dynindx == -1
-               && h->def_regular)
+           dyn = elf_hash_table (info)->dynamic_sections_created;
+           if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
+               || (info->shared
+                   && SYMBOL_REFERENCES_LOCAL (info, h)))
              {
                /* The symbol was forced to be local
                   because of a version file..  We must initialize
@@ -1584,13 +1523,23 @@ elf_vax_relocate_section (output_bfd, info, input_bfd, input_section,
          }
          break;
 
+       case R_VAX_PC32:
+         /* If we are creating an executable and the function this
+            reloc refers to is in a shared lib, then we made a PLT
+            entry for this symbol and need to handle the reloc like
+            a PLT reloc.  */
+         if (info->shared)
+            goto r_vax_pc32_shared;
+         /* Fall through.  */
        case R_VAX_PLT32:
          /* Relocation is to the entry for this symbol in the
             procedure linkage table.  */
 
          /* Resolve a PLTxx reloc against a local symbol directly,
             without using the procedure linkage table.  */
-         if (h == NULL)
+         if (h == NULL
+             || ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
+             || h->forced_local)
            break;
 
          if (h->plt.offset == (bfd_vma) -1
@@ -1611,7 +1560,7 @@ elf_vax_relocate_section (output_bfd, info, input_bfd, input_section,
          if (sgotplt == NULL)
            {
              sgotplt = bfd_get_section_by_name (dynobj, ".got.plt");
-             BFD_ASSERT (splt != NULL);
+             BFD_ASSERT (sgotplt != NULL);
            }
 
          plt_index = h->plt.offset / PLT_ENTRY_SIZE - 1;
@@ -1621,7 +1570,7 @@ elf_vax_relocate_section (output_bfd, info, input_bfd, input_section,
             The first two are reserved.  */
          got_offset = (plt_index + 3) * 4;
 
-         /* We want the relocate to point into the .got.plt instead
+         /* We want the relocation to point into the .got.plt instead
             of the plt itself.  */
          relocation = (sgotplt->output_section->vma
                        + sgotplt->output_offset
@@ -1643,21 +1592,24 @@ elf_vax_relocate_section (output_bfd, info, input_bfd, input_section,
 
        case R_VAX_PC8:
        case R_VAX_PC16:
-       case R_VAX_PC32:
-         if (h == NULL)
+       r_vax_pc32_shared:
+         if (h == NULL
+             || ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
+             || h->forced_local)
            break;
          /* Fall through.  */
        case R_VAX_8:
        case R_VAX_16:
        case R_VAX_32:
          if (info->shared
-             && r_symndx != 0
+             && r_symndx != STN_UNDEF
              && (input_section->flags & SEC_ALLOC) != 0
              && ((r_type != R_VAX_PC8
                   && r_type != R_VAX_PC16
                   && r_type != R_VAX_PC32)
-                 || (!info->symbolic
-                     || !h->def_regular)))
+                 || ((input_section->flags & SEC_CODE)
+                     && (!info->symbolic
+                         || (!h->def_regular && h->type != STT_SECTION)))))
            {
              Elf_Internal_Rela outrel;
              bfd_byte *loc;
@@ -1668,22 +1620,10 @@ elf_vax_relocate_section (output_bfd, info, input_bfd, input_section,
                 time.  */
              if (sreloc == NULL)
                {
-                 const char *name;
-
-                 name = (bfd_elf_string_from_elf_section
-                         (input_bfd,
-                          elf_elfheader (input_bfd)->e_shstrndx,
-                          elf_section_data (input_section)->rel_hdr.sh_name));
-                 if (name == NULL)
+                 sreloc = _bfd_elf_get_dynamic_reloc_section
+                   (input_bfd, input_section, /*rela?*/ TRUE);
+                 if (sreloc == NULL)
                    return FALSE;
-
-                 BFD_ASSERT (strncmp (name, ".rela", 5) == 0
-                             && strcmp (bfd_get_section_name (input_bfd,
-                                                              input_section),
-                                        name + 5) == 0);
-
-                 sreloc = bfd_get_section_by_name (dynobj, name);
-                 BFD_ASSERT (sreloc != NULL);
                }
 
              skip = FALSE;
@@ -1736,9 +1676,21 @@ elf_vax_relocate_section (output_bfd, info, input_bfd, input_section,
                        {
                          asection *osec;
 
+                         /* We are turning this relocation into one
+                            against a section symbol.  It would be
+                            proper to subtract the symbol's value,
+                            osec->vma, from the emitted reloc addend,
+                            but ld.so expects buggy relocs.  */
                          osec = sec->output_section;
                          indx = elf_section_data (osec)->dynindx;
-                         BFD_ASSERT (indx > 0);
+                         if (indx == 0)
+                           {
+                             struct elf_link_hash_table *htab;
+                             htab = elf_hash_table (info);
+                             osec = htab->text_index_section;
+                             indx = elf_section_data (osec)->dynindx;
+                           }
+                         BFD_ASSERT (indx != 0);
                        }
 
                      outrel.r_info = ELF32_R_INFO (indx, r_type);
@@ -1842,11 +1794,9 @@ elf_vax_relocate_section (output_bfd, info, input_bfd, input_section,
    dynamic sections here.  */
 
 static bfd_boolean
-elf_vax_finish_dynamic_symbol (output_bfd, info, h, sym)
-     bfd *output_bfd;
-     struct bfd_link_info *info;
-     struct elf_link_hash_entry *h;
-     Elf_Internal_Sym *sym;
+elf_vax_finish_dynamic_symbol (bfd *output_bfd, struct bfd_link_info *info,
+                              struct elf_link_hash_entry *h,
+                              Elf_Internal_Sym *sym)
 {
   bfd *dynobj;
 
@@ -1988,7 +1938,7 @@ elf_vax_finish_dynamic_symbol (output_bfd, info, h, sym)
 
   /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute.  */
   if (strcmp (h->root.root.string, "_DYNAMIC") == 0
-      || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
+      || h == elf_hash_table (info)->hgot)
     sym->st_shndx = SHN_ABS;
 
   return TRUE;
@@ -1997,9 +1947,7 @@ elf_vax_finish_dynamic_symbol (output_bfd, info, h, sym)
 /* Finish up the dynamic sections.  */
 
 static bfd_boolean
-elf_vax_finish_dynamic_sections (output_bfd, info)
-     bfd *output_bfd;
-     struct bfd_link_info *info;
+elf_vax_finish_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info)
 {
   bfd *dynobj;
   asection *sgot;
@@ -2106,6 +2054,29 @@ elf_vax_finish_dynamic_sections (output_bfd, info)
   return TRUE;
 }
 
+static enum elf_reloc_type_class
+elf_vax_reloc_type_class (const Elf_Internal_Rela *rela)
+{
+  switch ((int) ELF32_R_TYPE (rela->r_info))
+    {
+    case R_VAX_RELATIVE:
+      return reloc_class_relative;
+    case R_VAX_JMP_SLOT:
+      return reloc_class_plt;
+    case R_VAX_COPY:
+      return reloc_class_copy;
+    default:
+      return reloc_class_normal;
+    }
+}
+
+static bfd_vma
+elf_vax_plt_sym_val (bfd_vma i, const asection *plt,
+                    const arelent *rel ATTRIBUTE_UNUSED)
+{
+  return plt->vma + (i + 1) * PLT_ENTRY_SIZE;
+}
+
 #define TARGET_LITTLE_SYM              bfd_elf32_vax_vec
 #define TARGET_LITTLE_NAME             "elf32-vax"
 #define ELF_MACHINE_CODE               EM_VAX
@@ -2122,13 +2093,16 @@ elf_vax_finish_dynamic_sections (output_bfd, info)
                                        elf_vax_adjust_dynamic_symbol
 #define elf_backend_size_dynamic_sections \
                                        elf_vax_size_dynamic_sections
+#define elf_backend_init_index_section _bfd_elf_init_1_index_section
 #define elf_backend_relocate_section   elf_vax_relocate_section
 #define elf_backend_finish_dynamic_symbol \
                                        elf_vax_finish_dynamic_symbol
 #define elf_backend_finish_dynamic_sections \
                                        elf_vax_finish_dynamic_sections
+#define elf_backend_reloc_type_class   elf_vax_reloc_type_class
 #define elf_backend_gc_mark_hook       elf_vax_gc_mark_hook
 #define elf_backend_gc_sweep_hook      elf_vax_gc_sweep_hook
+#define elf_backend_plt_sym_val                elf_vax_plt_sym_val
 #define bfd_elf32_bfd_merge_private_bfd_data \
                                         elf32_vax_merge_private_bfd_data
 #define bfd_elf32_bfd_set_private_flags \
This page took 0.037094 seconds and 4 git commands to generate.