daily update
[deliverable/binutils-gdb.git] / bfd / elfcode.h
index fdfeee9b2785a35998507e8d4d78296dd52eb82f..032874823ba23425218c6510be65bb29da747a02 100644 (file)
@@ -1,7 +1,5 @@
 /* ELF executable support for BFD.
-   Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
-   2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
-   Free Software Foundation, Inc.
+   Copyright 1991-2013 Free Software Foundation, Inc.
 
    Written by Fred Fish @ Cygnus Support, from information published
    in "UNIX System V Release 4, Programmers Guide: ANSI C and
@@ -73,6 +71,7 @@
 #include "bfdlink.h"
 #include "libbfd.h"
 #include "elf-bfd.h"
+#include "libiberty.h"
 
 /* Renaming structures, typedefs, macros and functions to be size-specific.  */
 #define Elf_External_Ehdr      NAME(Elf,External_Ehdr)
@@ -495,13 +494,9 @@ elf_object_p (bfd *abfd)
   Elf_Internal_Shdr *i_shdrp;  /* Section header table, internal form */
   unsigned int shindex;
   const struct elf_backend_data *ebd;
-  struct bfd_preserve preserve;
   asection *s;
   bfd_size_type amt;
   const bfd_target *target;
-  const bfd_target * const *target_ptr;
-
-  preserve.marker = NULL;
 
   /* Read in the ELF header in external format.  */
 
@@ -540,9 +535,6 @@ elf_object_p (bfd *abfd)
       goto got_wrong_format_error;
     }
 
-  if (!bfd_preserve_save (abfd, &preserve))
-    goto got_no_match;
-
   target = abfd->xvec;
 
   /* Allocate an instance of the elf_obj_tdata structure and hook it up to
@@ -550,7 +542,6 @@ elf_object_p (bfd *abfd)
 
   if (! (*target->_bfd_set_format[bfd_object]) (abfd))
     goto got_no_match;
-  preserve.marker = elf_tdata (abfd);
 
   /* Now that we know the byte order, swap in the rest of the header */
   i_ehdrp = elf_elfheader (abfd);
@@ -588,35 +579,9 @@ elf_object_p (bfd *abfd)
       && (ebd->elf_machine_alt1 == 0
          || i_ehdrp->e_machine != ebd->elf_machine_alt1)
       && (ebd->elf_machine_alt2 == 0
-         || i_ehdrp->e_machine != ebd->elf_machine_alt2))
-    {
-      if (ebd->elf_machine_code != EM_NONE)
-       goto got_wrong_format_error;
-
-      /* This is the generic ELF target.  Let it match any ELF target
-        for which we do not have a specific backend.  */
-      if (abfd->target_defaulted)
-       for (target_ptr = bfd_target_vector; *target_ptr != NULL; target_ptr++)
-         {
-           const struct elf_backend_data *back;
-
-           if ((*target_ptr)->flavour != bfd_target_elf_flavour)
-             continue;
-           back = xvec_get_elf_backend_data (*target_ptr);
-           if (back->s->arch_size != ARCH_SIZE)
-             continue;
-           if (back->elf_machine_code == i_ehdrp->e_machine
-               || (back->elf_machine_alt1 != 0
-                   && back->elf_machine_alt1 == i_ehdrp->e_machine)
-               || (back->elf_machine_alt2 != 0
-                   && back->elf_machine_alt2 == i_ehdrp->e_machine))
-             {
-               /* target_ptr is an ELF backend which matches this
-                  object file, so reject the generic ELF target.  */
-               goto got_wrong_format_error;
-             }
-         }
-    }
+         || i_ehdrp->e_machine != ebd->elf_machine_alt2)
+      && ebd->elf_machine_code != EM_NONE)
+    goto got_wrong_format_error;
 
   if (i_ehdrp->e_type == ET_EXEC)
     abfd->flags |= EXEC_P;
@@ -634,43 +599,9 @@ elf_object_p (bfd *abfd)
     }
 
   if (ebd->elf_machine_code != EM_NONE
-      && i_ehdrp->e_ident[EI_OSABI] != ebd->elf_osabi)
-    {
-      if (ebd->elf_osabi != ELFOSABI_NONE)
-       goto got_wrong_format_error;
-
-      /* This is an ELFOSABI_NONE ELF target.  Let it match any ELF
-        target of the compatible machine for which we do not have a
-        backend with matching ELFOSABI.  */
-      for (target_ptr = bfd_target_vector;
-          *target_ptr != NULL;
-          target_ptr++)
-       {
-         const struct elf_backend_data *back;
-
-         /* Skip this target and targets with incompatible byte
-            order.  */
-         if (*target_ptr == target
-             || (*target_ptr)->flavour != bfd_target_elf_flavour
-             || (*target_ptr)->byteorder != target->byteorder
-             || ((*target_ptr)->header_byteorder
-                 != target->header_byteorder))
-           continue;
-
-         back = xvec_get_elf_backend_data (*target_ptr);
-         if (back->elf_osabi == i_ehdrp->e_ident[EI_OSABI]
-             && (back->elf_machine_code == i_ehdrp->e_machine
-                 || (back->elf_machine_alt1 != 0
-                     && back->elf_machine_alt1 == i_ehdrp->e_machine)
-                 || (back->elf_machine_alt2 != 0
-                     && back->elf_machine_alt2 == i_ehdrp->e_machine)))
-           {
-             /* target_ptr is an ELF backend which matches this
-                object file, so reject the ELFOSABI_NONE ELF target.  */
-             goto got_wrong_format_error;
-           }
-       }
-    }
+      && i_ehdrp->e_ident[EI_OSABI] != ebd->elf_osabi
+      && ebd->elf_osabi != ELFOSABI_NONE)
+    goto got_wrong_format_error;
 
   if (i_ehdrp->e_shoff != 0)
     {
@@ -694,8 +625,9 @@ elf_object_p (bfd *abfd)
       if (i_ehdrp->e_shnum == SHN_UNDEF)
        {
          i_ehdrp->e_shnum = i_shdr.sh_size;
-         if (i_ehdrp->e_shnum != i_shdr.sh_size
-             || i_ehdrp->e_shnum == 0)
+         if (i_ehdrp->e_shnum >= SHN_LORESERVE
+             || i_ehdrp->e_shnum != i_shdr.sh_size
+             || i_ehdrp->e_shnum  == 0)
            goto got_wrong_format_error;
        }
 
@@ -902,25 +834,12 @@ elf_object_p (bfd *abfd)
            s->flags |= SEC_DEBUGGING;
        }
     }
-
-  bfd_preserve_finish (abfd, &preserve);
   return target;
 
  got_wrong_format_error:
-  /* There is way too much undoing of half-known state here.  The caller,
-     bfd_check_format_matches, really shouldn't iterate on live bfd's to
-     check match/no-match like it does.  We have to rely on that a call to
-     bfd_default_set_arch_mach with the previously known mach, undoes what
-     was done by the first bfd_default_set_arch_mach (with mach 0) here.
-     For this to work, only elf-data and the mach may be changed by the
-     target-specific elf_backend_object_p function.  Note that saving the
-     whole bfd here and restoring it would be even worse; the first thing
-     you notice is that the cached bfd file position gets out of sync.  */
   bfd_set_error (bfd_error_wrong_format);
 
  got_no_match:
-  if (preserve.marker != NULL)
-    bfd_preserve_restore (abfd, &preserve);
   return NULL;
 }
 \f
@@ -1151,6 +1070,7 @@ elf_checksum_contents (bfd *abfd,
     {
       Elf_Internal_Shdr i_shdr;
       Elf_External_Shdr x_shdr;
+      bfd_byte *contents, *free_contents;
 
       i_shdr = *i_shdrp[count];
       i_shdr.sh_offset = 0;
@@ -1158,8 +1078,36 @@ elf_checksum_contents (bfd *abfd,
       elf_swap_shdr_out (abfd, &i_shdr, &x_shdr);
       (*process) (&x_shdr, sizeof x_shdr, arg);
 
-      if (i_shdr.contents)
-       (*process) (i_shdr.contents, i_shdr.sh_size, arg);
+      /* Process the section's contents, if it has some.
+        PR ld/12451: Read them in if necessary.  */
+      if (i_shdr.sh_type == SHT_NOBITS)
+       continue;
+      free_contents = NULL;
+      contents = i_shdr.contents;
+      if (contents == NULL)
+       {
+         asection *sec;
+
+         sec = bfd_section_from_elf_index (abfd, count);
+         if (sec != NULL)
+           {
+             contents = sec->contents;
+             if (contents == NULL)
+               {
+                 /* Force rereading from file.  */
+                 sec->flags &= ~SEC_IN_MEMORY;
+                 if (!bfd_malloc_and_get_section (abfd, sec, &free_contents))
+                   continue;
+                 contents = free_contents;
+               }
+           }
+       }
+      if (contents != NULL)
+       {
+         (*process) (contents, i_shdr.sh_size, arg);
+         if (free_contents != NULL)
+           free (free_contents);
+       }
     }
 
   return TRUE;
@@ -1203,9 +1151,9 @@ elf_slurp_symbol_table (bfd *abfd, asymbol **symptrs, bfd_boolean dynamic)
        verhdr = NULL;
       else
        verhdr = &elf_tdata (abfd)->dynversym_hdr;
-      if ((elf_tdata (abfd)->dynverdef_section != 0
+      if ((elf_dynverdef (abfd) != 0
           && elf_tdata (abfd)->verdef == NULL)
-         || (elf_tdata (abfd)->dynverref_section != 0
+         || (elf_dynverref (abfd) != 0
              && elf_tdata (abfd)->verref == NULL))
        {
          if (!_bfd_elf_slurp_version_tables (abfd, FALSE))
@@ -1491,7 +1439,7 @@ elf_slurp_reloc_table_from_section (bfd *abfd,
          (*_bfd_error_handler)
            (_("%s(%s): relocation %d has invalid symbol index %ld"),
             abfd->filename, asect->name, i, ELF_R_SYM (rela.r_info));
-         relent->sym_ptr_ptr = bfd_abs_section.symbol_ptr_ptr;
+         relent->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
        }
       else
        {
@@ -1656,7 +1604,7 @@ NAME(_bfd_elf,bfd_from_remote_memory)
   (bfd *templ,
    bfd_vma ehdr_vma,
    bfd_vma *loadbasep,
-   int (*target_read_memory) (bfd_vma, bfd_byte *, int))
+   int (*target_read_memory) (bfd_vma, bfd_byte *, bfd_size_type))
 {
   Elf_External_Ehdr x_ehdr;    /* Elf file header, external form */
   Elf_Internal_Ehdr i_ehdr;    /* Elf file header, internal form */
@@ -1855,7 +1803,7 @@ NAME(_bfd_elf,bfd_from_remote_memory)
       bfd_set_error (bfd_error_no_memory);
       return NULL;
     }
-  nbfd->filename = "<in-memory>";
+  nbfd->filename = xstrdup ("<in-memory>");
   nbfd->xvec = templ->xvec;
   bim->size = contents_size;
   bim->buffer = contents;
This page took 0.057465 seconds and 4 git commands to generate.