[PATCH v4 03/14] BFD: Unset the format on releasing a BFD's objalloc memory

Maciej W. Rozycki macro@orcam.me.uk
Tue Jan 13 01:44:22 GMT 2026


From: Maciej W. Rozycki <macro@redhat.com>

Make a BFD reusable after a `_bfd_free_cached_info' call to release its 
objalloc memory, by unsetting the format so that a subsequent call to 
`bfd_check_format_matches' will re-retrieve data previously discarded. 
Otherwise accesses to discarded data will be attempted where the BFD 
continues being used.  Found with a crash in `bfd_set_gp_size' when 
building archive symbol maps on the fly in a subsequent change.
---
Changes from v3 (10/18), 
<https://inbox.sourceware.org/binutils/alpine.DEB.2.21.2511192133300.57987@angie.orcam.me.uk/>:

- Remove format unsetting from `bfd_make_readable'.

No change from v2 (09/16), 
<https://inbox.sourceware.org/binutils/alpine.DEB.2.21.2511060348460.25436@angie.orcam.me.uk/>.

No change from v1 (6/8), 
<https://inbox.sourceware.org/binutils/alpine.DEB.2.21.2509262051431.63399@angie.orcam.me.uk/>.
---
 bfd/opncls.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

binutils-bfd-free-cached-info-format.diff
Index: binutils-gdb/bfd/opncls.c
===================================================================
--- binutils-gdb.orig/bfd/opncls.c
+++ binutils-gdb/bfd/opncls.c
@@ -193,6 +193,7 @@ _bfd_free_cached_info (bfd *abfd)
   abfd->outsymbols = NULL;
   abfd->tdata.any = NULL;
   abfd->usrdata = NULL;
+  abfd->format = bfd_unknown;
 
   return true;
 }
@@ -1027,7 +1028,6 @@ bfd_make_readable (bfd *abfd)
   abfd->arch_info = &bfd_default_arch_struct;
 
   abfd->where = 0;
-  abfd->format = bfd_unknown;
   abfd->my_archive = NULL;
   abfd->origin = 0;
   abfd->opened_once = false;


More information about the Binutils mailing list