bfd/
[binutils-gdb.git] / bfd / elfcore.h
index 865edcd0650de7bc06baa979706cc0b71f13d4f5..63ede275606dc2ae0cb256e1f9098c3898c63003 100644 (file)
@@ -1,5 +1,5 @@
 /* ELF core file support for BFD.
-   Copyright 1995, 1996, 1997, 1998, 2000, 2001, 2002, 2003
+   Copyright 1995, 1996, 1997, 1998, 2000, 2001, 2002, 2003, 2005
    Free Software Foundation, Inc.
 
    This file is part of BFD, the Binary File Descriptor library.
@@ -16,7 +16,7 @@
 
    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 02111-1307, USA.  */
+   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02110-1301, USA.  */
 
 char*
 elf_core_file_failing_command (bfd *abfd)
@@ -76,7 +76,7 @@ elf_core_file_p (bfd *abfd)
   Elf_Internal_Ehdr *i_ehdrp;  /* Elf file header, internal form.  */
   Elf_Internal_Phdr *i_phdrp;  /* Elf program header, internal form.  */
   unsigned int phindex;
-  struct elf_backend_data *ebd;
+  const struct elf_backend_data *ebd;
   struct bfd_preserve preserve;
   bfd_size_type amt;
 
@@ -153,11 +153,11 @@ elf_core_file_p (bfd *abfd)
 
       for (target_ptr = bfd_target_vector; *target_ptr != NULL; target_ptr++)
        {
-         struct elf_backend_data *back;
+         const struct elf_backend_data *back;
 
          if ((*target_ptr)->flavour != bfd_target_elf_flavour)
            continue;
-         back = (struct elf_backend_data *) (*target_ptr)->backend_data;
+         back = (const struct elf_backend_data *) (*target_ptr)->backend_data;
          if (back->elf_machine_code == i_ehdrp->e_machine
              || (back->elf_machine_alt1 != 0
                  && i_ehdrp->e_machine == back->elf_machine_alt1)
@@ -207,12 +207,19 @@ elf_core_file_p (bfd *abfd)
   /* Set the machine architecture.  Do this before processing the
      program headers since we need to know the architecture type
      when processing the notes of some systems' core files.  */
-  if (! bfd_default_set_arch_mach (abfd, ebd->arch, 0))
-    {
+  if (! bfd_default_set_arch_mach (abfd, ebd->arch, 0)
       /* It's OK if this fails for the generic target.  */
-      if (ebd->elf_machine_code != EM_NONE)
-       goto fail;
-    }
+      && ebd->elf_machine_code != EM_NONE)
+    goto fail;
+
+  /* Let the backend double check the format and override global
+     information.  We do this before processing the program headers
+     to allow the correct machine (as opposed to just the default
+     machine) to be set, making it possible for grok_prstatus and
+     grok_psinfo to rely on the mach setting.  */
+  if (ebd->elf_backend_object_p != NULL
+      && ! ebd->elf_backend_object_p (abfd))
+    goto wrong;
 
   /* Process each program header.  */
   for (phindex = 0; phindex < i_ehdrp->e_phnum; ++phindex)
@@ -222,12 +229,6 @@ elf_core_file_p (bfd *abfd)
   /* Save the entry point from the ELF header.  */
   bfd_get_start_address (abfd) = i_ehdrp->e_entry;
 
-  /* Let the backend double check the format and override global
-     information.  */
-  if (ebd->elf_backend_object_p
-      && (! (*ebd->elf_backend_object_p) (abfd)))
-    goto wrong;
-
   bfd_preserve_finish (abfd, &preserve);
   return abfd->xvec;