From 24a6c5ae36d0ceb0eb77a8b8e40f63ebbbbb052c Mon Sep 17 00:00:00 2001 From: Alan Modra Date: Thu, 13 Apr 2023 15:03:16 +0930 Subject: [PATCH] Preserve a few more bfd fields in check_format_matches AOUT and COFF targets set symcount and start_address in their object_p functions. If these are used anywhere then it would pay to save and restore them so that a successful match gets the values expected rather than that for a later unsuccessful target match. * format.c (struct bfd_preserve): Move some fields. Add symcount, read_only and start_address. (bfd_preserve_save): Save.. (bfd_preserve_restore): ..and restore.. (bfd_reinit): ..and zero new fields. --- bfd/format.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/bfd/format.c b/bfd/format.c index 66b45ae1979..c790f86d202 100644 --- a/bfd/format.c +++ b/bfd/format.c @@ -102,13 +102,16 @@ struct bfd_preserve const struct bfd_iovec *iovec; void *iostream; const struct bfd_arch_info *arch_info; + const struct bfd_build_id *build_id; + bfd_cleanup cleanup; struct bfd_section *sections; struct bfd_section *section_last; unsigned int section_count; unsigned int section_id; + unsigned int symcount; + bool read_only; + bfd_vma start_address; struct bfd_hash_table section_htab; - const struct bfd_build_id *build_id; - bfd_cleanup cleanup; }; /* When testing an object for compatibility with a particular target @@ -133,6 +136,9 @@ bfd_preserve_save (bfd *abfd, struct bfd_preserve *preserve, preserve->section_last = abfd->section_last; preserve->section_count = abfd->section_count; preserve->section_id = _bfd_section_id; + preserve->symcount = abfd->symcount; + preserve->read_only = abfd->read_only; + preserve->start_address = abfd->start_address; preserve->section_htab = abfd->section_htab; preserve->marker = bfd_alloc (abfd, 1); preserve->build_id = abfd->build_id; @@ -183,6 +189,9 @@ bfd_reinit (bfd *abfd, unsigned int section_id, abfd->tdata.any = NULL; abfd->arch_info = &bfd_default_arch_struct; io_reinit (abfd, preserve); + abfd->symcount = 0; + abfd->read_only = 0; + abfd->start_address = 0; abfd->build_id = NULL; bfd_section_list_clear (abfd); } @@ -202,6 +211,9 @@ bfd_preserve_restore (bfd *abfd, struct bfd_preserve *preserve) abfd->section_last = preserve->section_last; abfd->section_count = preserve->section_count; _bfd_section_id = preserve->section_id; + abfd->symcount = preserve->symcount; + abfd->read_only = preserve->read_only; + abfd->start_address = preserve->start_address; abfd->build_id = preserve->build_id; /* bfd_release frees all memory more recently bfd_alloc'd than -- 2.30.2