+
+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_set_error (bfd_error_wrong_format);
+
+fail:
+ abfd->arch_info = preserve.arch_info;
+ if (new_tdata != NULL)
+ {
+ /* bfd_release frees all memory more recently bfd_alloc'd than
+ its arg, as well as its arg. */
+ bfd_release (abfd, new_tdata);
+ elf_tdata (abfd) = preserve.tdata;
+ abfd->section_htab = preserve.section_htab;
+ abfd->sections = preserve.sections;
+ abfd->section_tail = preserve.section_tail;
+ abfd->section_count = preserve.section_count;
+ }
+ return NULL;