]> oss.titaniummirror.com Git - msp430-binutils.git/blobdiff - bfd/elfcore.h
Merge commit 'upstream/2.20'
[msp430-binutils.git] / bfd / elfcore.h
index dbf939757283a13ad3afb9588e5b63c1f5c2e8db..c51c575606d7db86a1b456d2c3d23b2014a36e95 100644 (file)
@@ -1,6 +1,6 @@
 /* ELF core file support for BFD.
-   Copyright 1995, 1996, 1997, 1998, 2000, 2001, 2002, 2003, 2005, 2007
-   Free Software Foundation, Inc.
+   Copyright 1995, 1996, 1997, 1998, 2000, 2001, 2002, 2003, 2005, 2007,
+   2008 Free Software Foundation, Inc.
 
    This file is part of BFD, the Binary File Descriptor library.
 
@@ -159,6 +159,8 @@ elf_core_file_p (bfd *abfd)
          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
                  && i_ehdrp->e_machine == back->elf_machine_alt1)
@@ -188,7 +190,7 @@ elf_core_file_p (bfd *abfd)
 
   /* Allocate space for the program headers.  */
   amt = sizeof (*i_phdrp) * i_ehdrp->e_phnum;
-  i_phdrp = bfd_alloc (abfd, amt);
+  i_phdrp = (Elf_Internal_Phdr *) bfd_alloc (abfd, amt);
   if (!i_phdrp)
     goto fail;
 
@@ -227,6 +229,32 @@ elf_core_file_p (bfd *abfd)
     if (! bfd_section_from_phdr (abfd, i_phdrp + phindex, (int) phindex))
       goto fail;
 
+  /* Check for core truncation.  */
+  {
+    bfd_size_type high = 0;
+    struct stat statbuf;
+    for (phindex = 0; phindex < i_ehdrp->e_phnum; ++phindex) 
+      {
+       Elf_Internal_Phdr *p = i_phdrp + phindex;
+       if (p->p_filesz)
+         {
+           bfd_size_type current = p->p_offset + p->p_filesz;
+           if (high < current)
+             high = current;
+         }
+      }
+    if (bfd_stat (abfd, &statbuf) == 0)
+      {
+       if ((bfd_size_type) statbuf.st_size < high)
+         {
+           (*_bfd_error_handler)
+             (_("Warning: %B is truncated: expected core file "
+                "size >= %lu, found: %lu."),
+              abfd, (unsigned long) high, (unsigned long) statbuf.st_size);
+         }
+      }
+  }
+  
   /* Save the entry point from the ELF header.  */
   bfd_get_start_address (abfd) = i_ehdrp->e_entry;