diff options
-rw-r--r-- | bfd/ChangeLog | 5 | ||||
-rw-r--r-- | bfd/elfcore.h | 21 |
2 files changed, 26 insertions, 0 deletions
diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 9d0fce7..f18998c 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,8 @@ +2001-11-02 Hans-Peter Nilsson <hp@axis.com> + + * elfcore.h (elf_core_file_p): Preserve and clear abfd section + information. Save bfd arch and mach values. Restore on error. + 2001-11-02 Alan Modra <amodra@bigpond.net.au> * elf32-hppa.c (hppa_handle_PIC_calls): Rename to mark_PIC_calls. diff --git a/bfd/elfcore.h b/bfd/elfcore.h index 3155e52..4142c52 100644 --- a/bfd/elfcore.h +++ b/bfd/elfcore.h @@ -85,9 +85,18 @@ elf_core_file_p (abfd) unsigned int phindex; struct elf_backend_data *ebd; struct elf_obj_tdata *preserved_tdata = elf_tdata (abfd); + struct sec *preserved_sections = abfd->sections; + unsigned int preserved_section_count = abfd->section_count; + enum bfd_architecture previous_arch = bfd_get_arch (abfd); + unsigned long previous_mach = bfd_get_mach (abfd); struct elf_obj_tdata *new_tdata = NULL; bfd_size_type amt; + /* Clear section information, since there might be a recognized bfd that + we now check if we can replace, and we don't want to append to it. */ + abfd->sections = NULL; + abfd->section_count = 0; + /* Read in the ELF header in external format. */ if (bfd_bread ((PTR) &x_ehdr, (bfd_size_type) sizeof (x_ehdr), abfd) != sizeof (x_ehdr)) @@ -234,6 +243,16 @@ elf_core_file_p (abfd) return abfd->xvec; wrong: + /* 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_default_set_arch_mach (abfd, previous_arch, previous_mach); bfd_set_error (bfd_error_wrong_format); fail: if (i_phdrp != NULL) @@ -241,5 +260,7 @@ fail: if (new_tdata != NULL) bfd_release (abfd, new_tdata); elf_tdata (abfd) = preserved_tdata; + abfd->sections = preserved_sections; + abfd->section_count = preserved_section_count; return NULL; } |