From 12e1f53eb884b6fb15f11b47b61cff90626ca8f6 Mon Sep 17 00:00:00 2001 From: Hans-Peter Nilsson Date: Fri, 2 Nov 2001 13:12:56 +0000 Subject: [PATCH] * elfcore.h (elf_core_file_p): Preserve and clear abfd section information. Save bfd arch and mach values. Restore on error. --- bfd/ChangeLog | 5 +++++ bfd/elfcore.h | 21 +++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 9d0fce70a39..f18998c0903 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,8 @@ +2001-11-02 Hans-Peter Nilsson + + * 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 * elf32-hppa.c (hppa_handle_PIC_calls): Rename to mark_PIC_calls. diff --git a/bfd/elfcore.h b/bfd/elfcore.h index 3155e5207be..4142c52b397 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; } -- 2.30.2