This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH 4/5] fix archive cache for thin archives


The previous archive cache fix did not account for thin archives.

Currently, when a member of a thin archive is opened, there is no
back-link to the parent archive.  This patch adds such a link, so that
the BFD archive code can clean up the thin archive cache when a member
is closed.

I took this approach rather than overload my_archive, because it
seemed simpler than fixing all the users of my_archive to have a
special case for thin archives.  However, if that is preferred, I can
attempt it.

In the case of flattened thin archives -- where a thin archive refers
to an ordinary archive -- the intermediate archive BFD is not
available to the BFD user.  So, no change needs to be done there, it
is already handled properly.

	* archive.c (_bfd_delete_archive_data): Handle thin archives.
	(_bfd_get_elt_at_filepos): Set 'thin_archive' field.
	* bfd-in2.h: Rebuild.
	* bfd.c (bfd) <thin_archive>: New field.
---
 bfd/archive.c |    8 +++++++-
 bfd/bfd-in2.h |    1 +
 bfd/bfd.c     |    3 ++-
 3 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/bfd/archive.c b/bfd/archive.c
index f84a8fc..8407745 100644
--- a/bfd/archive.c
+++ b/bfd/archive.c
@@ -317,13 +317,18 @@ void
 _bfd_delete_archive_data (bfd *abfd)
 {
   struct artdata *ardata = bfd_ardata (abfd);
+  bfd *archive = NULL;
 
   if (ardata && ardata->cache)
     htab_delete (ardata->cache);
 
   if (abfd->my_archive)
+    archive = abfd->my_archive;
+  else if (abfd->thin_archive)
+    archive = abfd->thin_archive;
+  if (archive)
     {
-      ardata = bfd_ardata (abfd->my_archive);
+      ardata = bfd_ardata (archive);
       if (ardata && ardata->cache)
 	{
 	  /* We have to traverse the hash table because there is no
@@ -705,6 +710,7 @@ _bfd_get_elt_at_filepos (bfd *archive, file_ptr filepos)
       n_nfd = bfd_openr (filename, target);
       if (n_nfd == NULL)
 	bfd_set_error (bfd_error_malformed_archive);
+      n_nfd->thin_archive = archive;
     }
   else
     {
diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h
index c7ce4cc..dcfdfdf 100644
--- a/bfd/bfd-in2.h
+++ b/bfd/bfd-in2.h
@@ -5618,6 +5618,7 @@ struct bfd
   struct bfd *archive_head;    /* The first BFD in the archive.  */
   struct bfd *nested_archives; /* List of nested archive in a flattened
                                   thin archive.  */
+  struct bfd *thin_archive;    /* The containing thin archive.  */
 
   /* A chain of BFD structures involved in a link.  */
   struct bfd *link_next;
diff --git a/bfd/bfd.c b/bfd/bfd.c
index eed1896..480f2f6 100644
--- a/bfd/bfd.c
+++ b/bfd/bfd.c
@@ -1,6 +1,6 @@
 /* Generic BFD library interface and support routines.
    Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
-   2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
+   2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
    Free Software Foundation, Inc.
    Written by Cygnus Support.
 
@@ -217,6 +217,7 @@ CODE_FRAGMENT
 .  struct bfd *archive_head;    {* The first BFD in the archive.  *}
 .  struct bfd *nested_archives; {* List of nested archive in a flattened
 .                                  thin archive.  *}
+.  struct bfd *thin_archive;    {* The containing thin archive.  *}
 .
 .  {* A chain of BFD structures involved in a link.  *}
 .  struct bfd *link_next;
-- 
1.7.7.6


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]