This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
[PATCH 3/5] remove deleted BFDs from the archive cache
- From: Tom Tromey <tromey at redhat dot com>
- To: Binutils Development <binutils at sourceware dot org>
- Date: Fri, 03 Aug 2012 08:54:40 -0600
- Subject: [PATCH 3/5] remove deleted BFDs from the archive cache
Right now if you bfd_close a member BFD, the pointer to the BFD
remains in the parent archive's cache. This means that if you try to
re-open that member, BFD will return a stale pointer.
This patch fixes the problem by deleting the entry from the hash.
I could not find a way to look up the member BFD in its parent cache
directly, hence the iteration.
* archive.c (delete_bfd_from_htab): New function.
(_bfd_delete_archive_data): Iterate over the parent archive's
hash table.
---
bfd/archive.c | 29 +++++++++++++++++++++++++++++
1 files changed, 29 insertions(+), 0 deletions(-)
diff --git a/bfd/archive.c b/bfd/archive.c
index 8d02257..f84a8fc 100644
--- a/bfd/archive.c
+++ b/bfd/archive.c
@@ -293,6 +293,24 @@ bfd_set_archive_head (bfd *output_archive, bfd *new_head)
return TRUE;
}
+/* A callback for htab_traverse that finds and clears an entry
+ corresponding to a given BFD. */
+
+static int
+delete_bfd_from_htab (void **slot, void *arg)
+{
+ struct ar_cache *cache = *slot;
+ bfd *abfd = arg;
+
+ if (cache->arbfd == abfd)
+ {
+ *slot = HTAB_DELETED_ENTRY;
+ return 0;
+ }
+
+ return 1;
+}
+
/* Free the archive hash table, if it exists. */
void
@@ -302,6 +320,17 @@ _bfd_delete_archive_data (bfd *abfd)
if (ardata && ardata->cache)
htab_delete (ardata->cache);
+
+ if (abfd->my_archive)
+ {
+ ardata = bfd_ardata (abfd->my_archive);
+ if (ardata && ardata->cache)
+ {
+ /* We have to traverse the hash table because there is no
+ way to find ABFD in it directly. */
+ htab_traverse_noresize (ardata->cache, delete_bfd_from_htab, abfd);
+ }
+ }
}
bfd *
--
1.7.7.6