This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: [PATCH] Call _close_and_cleanup in bfd_close_all_done
- From: "H.J. Lu" <hjl dot tools at gmail dot com>
- To: Alan Modra <amodra at gmail dot com>
- Cc: Binutils <binutils at sourceware dot org>
- Date: Wed, 30 Aug 2017 05:46:14 -0700
- Subject: Re: [PATCH] Call _close_and_cleanup in bfd_close_all_done
- Authentication-results: sourceware.org; auth=none
- References: <20170829190531.GA2862@intel.com> <20170830064928.GI3368@bubble.grove.modra.org>
On Tue, Aug 29, 2017 at 11:49 PM, Alan Modra <amodra@gmail.com> wrote:
> On Tue, Aug 29, 2017 at 12:05:31PM -0700, H.J. Lu wrote:
>> OK for master?
>>
>> H.J.
>> ---
>> PR binutils/22032
>> * opncls.c (bfd_close_all_done): Call _close_and_cleanup.
>
> Please have a look at archive.c:_bfd_archive_close_and_cleanup and
> convince yourself that this change is safe. archive_close_worker
> calls bfd_close_all_done. I think it is OK, but I'd like to make sure
> you have put eyes on that code too.
>
We have
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;
}
}
It is similar to
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, _bfd_archive_close_and_cleanup, NULL);
htab_delete (htab);
bfd_ardata (abfd)->cache = NULL;
}
}
Since an archive member can never be the archive which it is in,
it is safe.
--
H.J.