summaryrefslogtreecommitdiff
path: root/bfd/elfcore.h
diff options
context:
space:
mode:
authorHans-Peter Nilsson <hp@axis.com>2001-11-02 13:12:56 +0000
committerHans-Peter Nilsson <hp@axis.com>2001-11-02 13:12:56 +0000
commita707f2cc8d33be1d6b7d531778fe9cd9ba22bbc3 (patch)
treed5e1c651b50189f291c4bf3b2d9cd298ab0f3e0d /bfd/elfcore.h
parentff2b2e2e24c3c54824bbe4a457906edd6f9b418b (diff)
downloadbinutils-redhat-a707f2cc8d33be1d6b7d531778fe9cd9ba22bbc3.tar.gz
* 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.h21
1 files changed, 21 insertions, 0 deletions
diff --git a/bfd/elfcore.h b/bfd/elfcore.h
index 3155e5207b..4142c52b39 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;
}