2008-05-07 Paul Pluzhnikov * elfcore.h (elf_core_file_p): Warn about core truncation. --- bfd/elfcore.h.orig 2008-05-07 13:48:55.000000000 -0700 +++ bfd/elfcore.h 2008-05-07 15:18:43.659348000 -0700 @@ -227,6 +227,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, high, statbuf.st_size); + } + } + } + /* Save the entry point from the ELF header. */ bfd_get_start_address (abfd) = i_ehdrp->e_entry;