This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: [PATCH 3/5] remove deleted BFDs from the archive cache
HJ> Do you have testcases for those problems?
Just running valgrind using a test program.
Tom> If you mean reverting the patches, I don't agree with it, but that is up
Tom> to you.
HJ> I don't think it is a bad idea.
Here's a reversion patch.
I couldn't find a ChangeLog for one of the patches, the one Nick
committed.
I'll open some bugs.
If you check this in, please let me know so I can revert the gdb patch.
Thanks.
Tom
2012-08-16 Tom Tromey <tromey@redhat.com>
* archive.c, libbfd-in.h, libbfd.h, opncls.c: Revert patches
relating to archive handling:
2012-08-16 Tom Tromey <tromey@redhat.com>
2012-08-09 Alan Modra <amodra@gmail.com>
Tom Tromey <tromey@redhat.com>
diff --git a/bfd/archive.c b/bfd/archive.c
index e0cb370..fe57755 100644
--- a/bfd/archive.c
+++ b/bfd/archive.c
@@ -42,17 +42,11 @@ DESCRIPTION
have to read the entire archive if you don't want
to! Read it until you find what you want.
- A BFD returned by <<bfd_openr_next_archived_file>> can be
- closed manually with <<bfd_close>>. If you do not close it,
- then a second iteration through the members of an archive may
- return the same BFD. If you close the archive BFD, then all
- the member BFDs will automatically be closed as well.
-
Archive contents of output BFDs are chained through the
- <<archive_next>> pointer in a BFD. The first one is findable
- through the <<archive_head>> slot of the archive. Set it with
- <<bfd_set_archive_head>> (q.v.). A given BFD may be in only
- one open output archive at a time.
+ <<next>> pointer in a BFD. The first one is findable through
+ the <<archive_head>> slot of the archive. Set it with
+ <<bfd_set_archive_head>> (q.v.). A given BFD may be in only one
+ open output archive at a time.
As expected, the BFD archive code is more general than the
archive code of any given environment. BFD archives may
@@ -368,10 +362,6 @@ _bfd_add_bfd_to_archive_cache (bfd *arch_bfd, file_ptr filepos, bfd *new_elt)
cache->arbfd = new_elt;
*htab_find_slot (hash_table, (const void *) cache, INSERT) = cache;
- /* Provide a means of accessing this from child. */
- arch_eltdata (new_elt)->parent_cache = hash_table;
- arch_eltdata (new_elt)->key = filepos;
-
return TRUE;
}
@@ -1896,7 +1886,7 @@ bfd_ar_hdr_from_filesystem (bfd *abfd, const char *filename, bfd *member)
}
amt = sizeof (struct ar_hdr) + sizeof (struct areltdata);
- ared = (struct areltdata *) bfd_zalloc (member, amt);
+ ared = (struct areltdata *) bfd_zalloc (abfd, amt);
if (ared == NULL)
return NULL;
hdr = (struct ar_hdr *) (((char *) ared) + sizeof (struct areltdata));
@@ -1927,7 +1917,10 @@ bfd_ar_hdr_from_filesystem (bfd *abfd, const char *filename, bfd *member)
_bfd_ar_spacepad (hdr->ar_mode, sizeof (hdr->ar_mode), "%-8lo",
status.st_mode);
if (!_bfd_ar_sizepad (hdr->ar_size, sizeof (hdr->ar_size), status.st_size))
- return NULL;
+ {
+ free (ared);
+ return NULL;
+ }
memcpy (hdr->ar_fmag, ARFMAG, 2);
ared->parsed_size = status.st_size;
ared->arch_header = (char *) hdr;
@@ -2689,58 +2682,3 @@ coff_write_armap (bfd *arch,
return TRUE;
}
-
-static int
-archive_close_worker (void **slot, void *inf ATTRIBUTE_UNUSED)
-{
- struct ar_cache *ent = (struct ar_cache *) *slot;
-
- bfd_close_all_done (ent->arbfd);
- return 1;
-}
-
-bfd_boolean
-_bfd_archive_close_and_cleanup (bfd *abfd)
-{
- if (bfd_read_p (abfd) && abfd->format == bfd_archive)
- {
- bfd *nbfd;
- bfd *next;
- htab_t htab;
-
- /* Close nested archives (if this bfd is a thin archive). */
- for (nbfd = abfd->nested_archives; nbfd; nbfd = next)
- {
- next = nbfd->archive_next;
- bfd_close (nbfd);
- }
-
- htab = bfd_ardata (abfd)->cache;
- if (htab)
- {
- htab_traverse_noresize (htab, archive_close_worker, NULL);
- htab_delete (htab);
- bfd_ardata (abfd)->cache = NULL;
- }
- }
- else if (arch_eltdata (abfd) != NULL)
- {
- struct areltdata *ared = arch_eltdata (abfd);
- htab_t htab = (htab_t) ared->parent_cache;
-
- if (htab)
- {
- struct ar_cache ent;
- void **slot;
-
- ent.ptr = ared->key;
- slot = htab_find_slot (htab, &ent, NO_INSERT);
- if (slot != NULL)
- {
- BFD_ASSERT (((struct ar_cache *) *slot)->arbfd == abfd);
- htab_clear_slot (htab, slot);
- }
- }
- }
- return TRUE;
-}
diff --git a/bfd/libbfd-in.h b/bfd/libbfd-in.h
index 80cb051..1495825 100644
--- a/bfd/libbfd-in.h
+++ b/bfd/libbfd-in.h
@@ -96,8 +96,6 @@ struct areltdata
bfd_size_type extra_size; /* BSD4.4: extra bytes after the header. */
char *filename; /* Null-terminated. */
file_ptr origin; /* For element of a thin archive. */
- void *parent_cache; /* Where and how to find this member. */
- file_ptr key;
};
#define arelt_size(bfd) (((struct areltdata *)((bfd)->arelt_data))->parsed_size)
@@ -232,9 +230,7 @@ int bfd_generic_stat_arch_elt
/* Generic routines to use for BFD_JUMP_TABLE_GENERIC. Use
BFD_JUMP_TABLE_GENERIC (_bfd_generic). */
-#define _bfd_generic_close_and_cleanup _bfd_archive_close_and_cleanup
-extern bfd_boolean _bfd_archive_close_and_cleanup
- (bfd *);
+#define _bfd_generic_close_and_cleanup bfd_true
#define _bfd_generic_bfd_free_cached_info bfd_true
extern bfd_boolean _bfd_generic_new_section_hook
(bfd *, asection *);
diff --git a/bfd/libbfd.h b/bfd/libbfd.h
index 88ff9c6..077f1fb 100644
--- a/bfd/libbfd.h
+++ b/bfd/libbfd.h
@@ -101,8 +101,6 @@ struct areltdata
bfd_size_type extra_size; /* BSD4.4: extra bytes after the header. */
char *filename; /* Null-terminated. */
file_ptr origin; /* For element of a thin archive. */
- void *parent_cache; /* Where and how to find this member. */
- file_ptr key;
};
#define arelt_size(bfd) (((struct areltdata *)((bfd)->arelt_data))->parsed_size)
@@ -237,9 +235,7 @@ int bfd_generic_stat_arch_elt
/* Generic routines to use for BFD_JUMP_TABLE_GENERIC. Use
BFD_JUMP_TABLE_GENERIC (_bfd_generic). */
-#define _bfd_generic_close_and_cleanup _bfd_archive_close_and_cleanup
-extern bfd_boolean _bfd_archive_close_and_cleanup
- (bfd *);
+#define _bfd_generic_close_and_cleanup bfd_true
#define _bfd_generic_bfd_free_cached_info bfd_true
extern bfd_boolean _bfd_generic_new_section_hook
(bfd *, asection *);
diff --git a/bfd/opncls.c b/bfd/opncls.c
index b2ed9be..0c02ee4 100644
--- a/bfd/opncls.c
+++ b/bfd/opncls.c
@@ -135,7 +135,6 @@ _bfd_delete_bfd (bfd *abfd)
bfd_hash_table_free (&abfd->section_htab);
objalloc_free ((struct objalloc *) abfd->memory);
}
-
free (abfd);
}
@@ -708,6 +707,8 @@ bfd_boolean
bfd_close (bfd *abfd)
{
bfd_boolean ret;
+ bfd *nbfd;
+ bfd *next;
if (bfd_write_p (abfd))
{
@@ -715,6 +716,13 @@ bfd_close (bfd *abfd)
return FALSE;
}
+ /* Close nested archives (if this bfd is a thin archive). */
+ for (nbfd = abfd->nested_archives; nbfd; nbfd = next)
+ {
+ next = nbfd->archive_next;
+ bfd_close (nbfd);
+ }
+
if (! BFD_SEND (abfd, _close_and_cleanup, (abfd)))
return FALSE;