* bfd.c (bfd_archive_filename): New function.
[deliverable/binutils-gdb.git] / bfd / elf64-x86-64.c
index 7b37d9644338a86afc19e4bcca290cb7f1dc2d2d..c86a50f1aa56dd18184a01cdc6a96d811e776811 100644 (file)
@@ -98,7 +98,7 @@ struct elf_reloc_map
   unsigned char elf_reloc_val;
 };
 
-static CONST struct elf_reloc_map x86_64_reloc_map[] =
+static const struct elf_reloc_map x86_64_reloc_map[] =
 {
   { BFD_RELOC_NONE,            R_X86_64_NONE, },
   { BFD_RELOC_64,              R_X86_64_64,   },
@@ -126,6 +126,17 @@ static void elf64_x86_64_info_to_howto
   PARAMS ((bfd *, arelent *, Elf64_Internal_Rela *));
 static struct bfd_link_hash_table *elf64_x86_64_link_hash_table_create
   PARAMS ((bfd *));
+static boolean elf64_x86_64_elf_object_p PARAMS ((bfd *abfd));
+static boolean elf64_x86_64_check_relocs
+  PARAMS ((bfd *, struct bfd_link_info *, asection *sec,
+          const Elf_Internal_Rela *));
+static asection *elf64_x86_64_gc_mark_hook
+  PARAMS ((bfd *, struct bfd_link_info *, Elf_Internal_Rela *,
+          struct elf_link_hash_entry *, Elf_Internal_Sym *));
+
+static boolean elf64_x86_64_gc_sweep_hook
+  PARAMS ((bfd *, struct bfd_link_info *, asection *,
+          const Elf_Internal_Rela *));
 
 static struct bfd_hash_entry *elf64_x86_64_link_hash_newfunc
   PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *));
@@ -142,6 +153,7 @@ static boolean elf64_x86_64_finish_dynamic_symbol
           Elf_Internal_Sym *sym));
 static boolean elf64_x86_64_finish_dynamic_sections
   PARAMS ((bfd *, struct bfd_link_info *));
+static enum elf_reloc_type_class elf64_x86_64_reloc_type_class PARAMS ((int));
 
 /* Given a BFD reloc type, return a HOWTO structure.  */
 static reloc_howto_type *
@@ -315,9 +327,9 @@ elf64_x86_64_link_hash_table_create (abfd)
      bfd *abfd;
 {
   struct elf64_x86_64_link_hash_table *ret;
+  bfd_size_type amt = sizeof (struct elf64_x86_64_link_hash_table);
 
-  ret = ((struct elf64_x86_64_link_hash_table *)
-        bfd_alloc (abfd, sizeof (struct elf64_x86_64_link_hash_table)));
+  ret = ((struct elf64_x86_64_link_hash_table *) bfd_alloc (abfd, amt));
   if (ret == (struct elf64_x86_64_link_hash_table *) NULL)
     return NULL;
 
@@ -331,7 +343,7 @@ elf64_x86_64_link_hash_table_create (abfd)
   return &ret->root.root;
 }
 
-boolean
+static boolean
 elf64_x86_64_elf_object_p (abfd)
      bfd *abfd;
 {
@@ -451,15 +463,16 @@ elf64_x86_64_check_relocs (abfd, info, sec, relocs)
              /* This is a global offset table entry for a local symbol.  */
              if (local_got_refcounts == NULL)
                {
-                 size_t size;
+                 bfd_size_type size;
 
-                 size = symtab_hdr->sh_info * sizeof (bfd_signed_vma);
+                 size = symtab_hdr->sh_info;
+                 size *= sizeof (bfd_signed_vma);
                  local_got_refcounts = ((bfd_signed_vma *)
                                         bfd_alloc (abfd, size));
                  if (local_got_refcounts == NULL)
                    return false;
                  elf_local_got_refcounts (abfd) = local_got_refcounts;
-                 memset (local_got_refcounts, -1, size);
+                 memset (local_got_refcounts, -1, (size_t) size);
                }
              if (local_got_refcounts[r_symndx] == -1)
                {
@@ -565,6 +578,8 @@ elf64_x86_64_check_relocs (abfd, info, sec, relocs)
                          || ! bfd_set_section_alignment (dynobj, sreloc, 3))
                        return false;
                    }
+                 if (sec->flags & SEC_READONLY)
+                   info->flags |= DF_TEXTREL;
                }
 
              sreloc->_raw_size += sizeof (Elf64_External_Rela);
@@ -592,7 +607,7 @@ elf64_x86_64_check_relocs (abfd, info, sec, relocs)
                  if (p == NULL)
                    {
                      p = ((struct elf64_x86_64_pcrel_relocs_copied *)
-                          bfd_alloc (dynobj, sizeof *p));
+                          bfd_alloc (dynobj, (bfd_size_type) sizeof *p));
                      if (p == NULL)
                        return false;
                      p->next = eh->pcrel_relocs_copied;
@@ -935,14 +950,13 @@ elf64_x86_64_adjust_dynamic_symbol (info, h)
 
 static boolean
 elf64_x86_64_size_dynamic_sections (output_bfd, info)
-     bfd *output_bfd;
+     bfd *output_bfd ATTRIBUTE_UNUSED;
      struct bfd_link_info *info;
 {
   bfd *dynobj;
   asection *s;
   boolean plt;
   boolean relocs;
-  boolean reltext;
 
   dynobj = elf_hash_table (info)->dynobj;
   BFD_ASSERT (dynobj != NULL);
@@ -982,7 +996,7 @@ elf64_x86_64_size_dynamic_sections (output_bfd, info)
   /* The check_relocs and adjust_dynamic_symbol entry points have
      determined the sizes of the various dynamic sections.  Allocate
      memory for them.  */
-  plt = relocs = reltext = false;
+  plt = relocs = false;
   for (s = dynobj->sections; s != NULL; s = s->next)
     {
       const char *name;
@@ -1027,29 +1041,8 @@ elf64_x86_64_size_dynamic_sections (output_bfd, info)
            }
          else
            {
-             asection *target;
-
-             /* Remember whether there are any reloc sections other
-                than .rela.plt.  */
              if (strcmp (name, ".rela.plt") != 0)
-               {
-                 const char *outname;
-
-                 relocs = true;
-
-                 /* If this relocation section applies to a read only
-                    section, then we probably need a DT_TEXTREL
-                    entry.  The entries in the .rela.plt section
-                    really apply to the .got section, which we
-                    created ourselves and so know is not readonly.  */
-                 outname = bfd_get_section_name (output_bfd,
-                                                 s->output_section);
-                 target = bfd_get_section_by_name (output_bfd, outname + 5);
-                 if (target != NULL
-                     && (target->flags & SEC_READONLY) != 0
-                     && (target->flags & SEC_ALLOC) != 0)
-                   reltext = true;
-               }
+               relocs = true;
 
              /* We use the reloc_count field as a counter if we need
                 to copy relocs into the output file.  */
@@ -1085,37 +1078,39 @@ elf64_x86_64_size_dynamic_sections (output_bfd, info)
         must add the entries now so that we get the correct size for
         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))
+
       if (! info->shared)
        {
-         if (! bfd_elf64_add_dynamic_entry (info, DT_DEBUG, 0))
+         if (!add_dynamic_entry (DT_DEBUG, 0))
            return false;
        }
 
       if (plt)
        {
-         if (! bfd_elf64_add_dynamic_entry (info, DT_PLTGOT, 0)
-             || ! bfd_elf64_add_dynamic_entry (info, DT_PLTRELSZ, 0)
-             || ! bfd_elf64_add_dynamic_entry (info, DT_PLTREL, DT_RELA)
-             || ! bfd_elf64_add_dynamic_entry (info, DT_JMPREL, 0))
+         if (!add_dynamic_entry (DT_PLTGOT, 0)
+             || !add_dynamic_entry (DT_PLTRELSZ, 0)
+             || !add_dynamic_entry (DT_PLTREL, DT_RELA)
+             || !add_dynamic_entry (DT_JMPREL, 0))
            return false;
        }
 
       if (relocs)
        {
-         if (! bfd_elf64_add_dynamic_entry (info, DT_RELA, 0)
-             || ! bfd_elf64_add_dynamic_entry (info, DT_RELASZ, 0)
-             || ! bfd_elf64_add_dynamic_entry (info, DT_RELAENT,
-                                               sizeof (Elf64_External_Rela)))
+         if (!add_dynamic_entry (DT_RELA, 0)
+             || !add_dynamic_entry (DT_RELASZ, 0)
+             || !add_dynamic_entry (DT_RELAENT, sizeof (Elf64_External_Rela)))
            return false;
        }
 
-      if (reltext)
+      if ((info->flags & DF_TEXTREL) != 0)
        {
-         if (! bfd_elf64_add_dynamic_entry (info, DT_TEXTREL, 0))
+         if (!add_dynamic_entry (DT_TEXTREL, 0))
            return false;
-         info->flags |= DF_TEXTREL;
        }
     }
+#undef add_dynamic_entry
 
   return true;
 }
@@ -1294,7 +1289,7 @@ elf64_x86_64_relocate_section (output_bfd, info, input_bfd, input_section,
                {
                  (*_bfd_error_handler)
                    (_("%s: warning: unresolvable relocation against symbol `%s' from %s section"),
-                    bfd_get_filename (input_bfd), h->root.root.string,
+                    bfd_archive_filename (input_bfd), h->root.root.string,
                     bfd_get_section_name (input_bfd, input_section));
                  relocation = 0;
                }
@@ -1305,7 +1300,9 @@ elf64_x86_64_relocate_section (output_bfd, info, input_bfd, input_section,
            }
          else if (h->root.type == bfd_link_hash_undefweak)
            relocation = 0;
-         else if (info->shared && !info->symbolic && !info->no_undefined
+         else if (info->shared
+                  && (!info->symbolic || info->allow_shlib_undefined)
+                  && !info->no_undefined
                   && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
            relocation = 0;
          else
@@ -1530,7 +1527,7 @@ elf64_x86_64_relocate_section (output_bfd, info, input_bfd, input_section,
                    }
                  else
                    {
-                     long indx;
+                     long sindx;
 
                      if (h == NULL)
                        sec = local_sections[r_symndx];
@@ -1542,7 +1539,7 @@ elf64_x86_64_relocate_section (output_bfd, info, input_bfd, input_section,
                          sec = h->root.u.def.section;
                        }
                      if (sec != NULL && bfd_is_abs_section (sec))
-                       indx = 0;
+                       sindx = 0;
                      else if (sec == NULL || sec->owner == NULL)
                        {
                          bfd_set_error (bfd_error_bad_value);
@@ -1553,12 +1550,12 @@ elf64_x86_64_relocate_section (output_bfd, info, input_bfd, input_section,
                          asection *osec;
 
                          osec = sec->output_section;
-                         indx = elf_section_data (osec)->dynindx;
-                         BFD_ASSERT (indx > 0);
+                         sindx = elf_section_data (osec)->dynindx;
+                         BFD_ASSERT (sindx > 0);
                        }
 
                      relocate = false;
-                     outrel.r_info = ELF64_R_INFO (indx, r_type);
+                     outrel.r_info = ELF64_R_INFO (sindx, r_type);
                      outrel.r_addend = relocation + rela->r_addend;
                    }
 
@@ -1739,7 +1736,7 @@ elf64_x86_64_finish_dynamic_symbol (output_bfd, info, h, sym)
 
       rela.r_offset = (sgot->output_section->vma
                       + sgot->output_offset
-                      + (h->got.offset &~ 1));
+                      + (h->got.offset &~ (bfd_vma) 1));
 
       /* If this is a static link, or it is a -Bsymbolic link and the
         symbol is defined locally or was forced to be local because
@@ -1938,6 +1935,23 @@ elf64_x86_64_finish_dynamic_sections (output_bfd, info)
   return true;
 }
 
+static enum elf_reloc_type_class
+elf64_x86_64_reloc_type_class (type)
+     int type;
+{
+  switch (type)
+    {
+    case R_X86_64_RELATIVE:
+      return reloc_class_relative;
+    case R_X86_64_JUMP_SLOT:
+      return reloc_class_plt;
+    case R_X86_64_COPY:
+      return reloc_class_copy;
+    default:
+      return reloc_class_normal;
+    }
+}
+
 #define TARGET_LITTLE_SYM                  bfd_elf64_x86_64_vec
 #define TARGET_LITTLE_NAME                 "elf64-x86-64"
 #define ELF_ARCH                           bfd_arch_i386
@@ -1969,5 +1983,6 @@ elf64_x86_64_finish_dynamic_sections (output_bfd, info)
 #define elf_backend_relocate_section       elf64_x86_64_relocate_section
 #define elf_backend_size_dynamic_sections   elf64_x86_64_size_dynamic_sections
 #define elf_backend_object_p               elf64_x86_64_elf_object_p
+#define elf_backend_reloc_type_class       elf64_x86_64_reloc_type_class
 
 #include "elf64-target.h"
This page took 0.0379 seconds and 4 git commands to generate.