Resync config/ from GCC.
[deliverable/binutils-gdb.git] / bfd / elf32-vax.c
index 93cb1cb09c09b2dff4371aa214995cc946fb7e18..5b86329f1929aa2e4c2129cda768986a81651328 100644 (file)
@@ -1,6 +1,7 @@
 /* VAX series support for 32-bit ELF
    Copyright 1993, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
-   2004, 2005, 2006, 2007, 2008  Free Software Foundation, Inc.
+   2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
+   Free Software Foundation, Inc.
    Contributed by Matt Thomas <matt@3am-software.com>.
 
    This file is part of BFD, the Binary File Descriptor library.
@@ -47,6 +48,8 @@ static bfd_boolean elf_vax_finish_dynamic_symbol (bfd *, struct bfd_link_info *,
                                                  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 *);
@@ -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,35 +408,24 @@ 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 (struct elf_vax_link_hash_entry *,
-                                          PTR);
+                                          void *);
 
 /* Declare this now that the above structures are defined.  */
 
 static bfd_boolean elf_vax_instantiate_got_entries (struct elf_link_hash_entry *,
-                                                   PTR);
+                                                   void *);
 
 /* Traverse an VAX ELF linker hash table.  */
 
 #define elf_vax_link_hash_traverse(table, func, info)                  \
   (elf_link_hash_traverse                                              \
-   (&(table)->root,                                                    \
+   ((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 *
@@ -470,22 +462,23 @@ elf_vax_link_hash_newfunc (struct bfd_hash_entry *entry,
 static struct bfd_link_hash_table *
 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 = bfd_malloc (amt);
   if (ret == NULL)
     return NULL;
 
-  if (!_bfd_elf_link_hash_table_init (&ret->root, abfd,
+  if (!_bfd_elf_link_hash_table_init (ret, abfd,
                                      elf_vax_link_hash_newfunc,
-                                     sizeof (struct elf_vax_link_hash_entry)))
+                                     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 */
@@ -502,7 +495,6 @@ elf32_vax_set_private_flags (bfd *abfd, flagword flags)
 static bfd_boolean
 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
@@ -510,7 +502,6 @@ elf32_vax_merge_private_bfd_data (bfd *ibfd, bfd *obfd)
     return TRUE;
 
   in_flags  = elf_elfheader (ibfd)->e_flags;
-  out_flags = elf_elfheader (obfd)->e_flags;
 
   if (!elf_flags_init (obfd))
     {
@@ -1045,13 +1036,6 @@ 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
@@ -1069,7 +1053,7 @@ elf_vax_adjust_dynamic_symbol (info, h)
      copy the initial value out of the dynamic object and into the
      runtime process image.  We need to remember the offset into the
      .rela.bss section we are going to use.  */
-  if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
+  if ((h->root.u.def.section->flags & SEC_ALLOC) != 0 && h->size != 0)
     {
       asection *srel;
 
@@ -1130,7 +1114,7 @@ elf_vax_size_dynamic_sections (bfd *output_bfd, struct bfd_link_info *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,
                                NULL);
 
@@ -1282,9 +1266,6 @@ elf_vax_discard_copies (struct elf_vax_link_hash_entry *h,
 {
   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;
@@ -1332,6 +1313,8 @@ elf_vax_instantiate_got_entries (struct elf_link_hash_entry *h, PTR infoptr)
     }
   else if (h->got.refcount > 0)
     {
+      bfd_boolean dyn;
+
       /* Make sure this symbol is output as a dynamic symbol.  */
       if (h->dynindx == -1)
        {
@@ -1339,9 +1322,15 @@ elf_vax_instantiate_got_entries (struct elf_link_hash_entry *h, PTR 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;
@@ -1362,7 +1351,6 @@ elf_vax_relocate_section (bfd *output_bfd,
   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;
@@ -1375,7 +1363,6 @@ elf_vax_relocate_section (bfd *output_bfd,
   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;
@@ -1456,16 +1443,9 @@ elf_vax_relocate_section (bfd *output_bfd,
            relocation = 0;
        }
 
-      if (sec != NULL && elf_discarded_section (sec))
-       {
-         /* For relocs against symbols from removed linkonce sections,
-            or sections discarded by a linker script, we just want the
-            section contents zeroed.  Avoid any special processing.  */
-         _bfd_clear_contents (howto, input_bfd, contents + rel->r_offset);
-         rel->r_info = 0;
-         rel->r_addend = 0;
-         continue;
-       }
+      if (sec != NULL && discarded_section (sec))
+       RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section,
+                                        rel, 1, relend, howto, 0, contents);
 
       if (info->relocatable)
        continue;
@@ -1485,6 +1465,7 @@ elf_vax_relocate_section (bfd *output_bfd,
             the global offset table.  */
 
          {
+           bfd_boolean dyn;
            bfd_vma off;
 
            if (sgot == NULL)
@@ -1498,9 +1479,10 @@ elf_vax_relocate_section (bfd *output_bfd,
            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
@@ -1534,6 +1516,14 @@ elf_vax_relocate_section (bfd *output_bfd,
          }
          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.  */
@@ -1563,7 +1553,7 @@ elf_vax_relocate_section (bfd *output_bfd,
          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;
@@ -1573,7 +1563,7 @@ elf_vax_relocate_section (bfd *output_bfd,
             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
@@ -1595,7 +1585,7 @@ elf_vax_relocate_section (bfd *output_bfd,
 
        case R_VAX_PC8:
        case R_VAX_PC16:
-       case R_VAX_PC32:
+       r_vax_pc32_shared:
          if (h == NULL
              || ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
              || h->forced_local)
@@ -1605,7 +1595,7 @@ elf_vax_relocate_section (bfd *output_bfd,
        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
@@ -1701,14 +1691,12 @@ elf_vax_relocate_section (bfd *output_bfd,
                    }
                }
 
-             if (!strcmp (bfd_get_section_name (input_bfd, input_section),
-                          ".text") != 0 ||
-                 (info->shared
-                  && ELF32_R_TYPE(outrel.r_info) != R_VAX_32
-                  && ELF32_R_TYPE(outrel.r_info) != R_VAX_RELATIVE
-                  && ELF32_R_TYPE(outrel.r_info) != R_VAX_COPY
-                  && ELF32_R_TYPE(outrel.r_info) != R_VAX_JMP_SLOT
-                  && ELF32_R_TYPE(outrel.r_info) != R_VAX_GLOB_DAT))
+             if ((input_section->flags & SEC_CODE) != 0
+                 || (ELF32_R_TYPE (outrel.r_info) != R_VAX_32
+                     && ELF32_R_TYPE (outrel.r_info) != R_VAX_RELATIVE
+                     && ELF32_R_TYPE (outrel.r_info) != R_VAX_COPY
+                     && ELF32_R_TYPE (outrel.r_info) != R_VAX_JMP_SLOT
+                     && ELF32_R_TYPE (outrel.r_info) != R_VAX_GLOB_DAT))
                {
                  if (h != NULL)
                    (*_bfd_error_handler)
@@ -2057,6 +2045,29 @@ elf_vax_finish_dynamic_sections (bfd *output_bfd, struct bfd_link_info *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
@@ -2079,8 +2090,10 @@ elf_vax_finish_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info)
                                        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.02797 seconds and 4 git commands to generate.