diff options
author | Hans-Peter Nilsson <hp@axis.com> | 2001-11-02 13:12:56 +0000 |
---|---|---|
committer | Hans-Peter Nilsson <hp@axis.com> | 2001-11-02 13:12:56 +0000 |
commit | 12e1f53eb884b6fb15f11b47b61cff90626ca8f6 (patch) | |
tree | f24d0af51a989e1861f522a676d095f3df959707 /bfd/elfcore.h | |
parent | a8d02d6673c0a108c77e03ac2789b5ed82d82038 (diff) | |
download | binutils-12e1f53eb884b6fb15f11b47b61cff90626ca8f6.tar.gz binutils-12e1f53eb884b6fb15f11b47b61cff90626ca8f6.tar.bz2 binutils-12e1f53eb884b6fb15f11b47b61cff90626ca8f6.zip |
* elfcore.h (elf_core_file_p): Preserve and clear abfd section
information. Save bfd arch and mach values. Restore on error.
Diffstat (limited to 'bfd/elfcore.h')
-rw-r--r-- | bfd/elfcore.h | 21 |
1 files changed, 21 insertions, 0 deletions
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; } |