This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: who owns a BFD coming from an archive?
- From: Alan Modra <amodra at gmail dot com>
- To: Tom Tromey <tromey at redhat dot com>
- Cc: Binutils Development <binutils at sourceware dot org>
- Date: Wed, 1 Aug 2012 17:32:56 +0930
- Subject: Re: who owns a BFD coming from an archive?
- References: <87liiap79m.fsf@fleche.redhat.com>
On Mon, Jul 23, 2012 at 02:11:33PM -0600, Tom Tromey wrote:
> * For a thin archive, again according to valgrind and my reading, the
> opposite is true: the archive owns the BFDs, and if you close each
> one, you will see crashes.
Thin archives support nesting. I think the BFDs opened to access
nested archives are owned by the archive, BFDs returned for objects
are owned by you. However it is all quite nasty due to the archive
cache. Some binutils and ld don't bother with closing archive member
BFDs, trusting that when the process exits all sins will be forgiven.
See for example this comment in ld/plugin.c
/* BFD archive handling caches elements so we can't call
bfd_close for archives. */
I think you'll see crashes due to the cache with normal archives too,
eg. call get_elt_at_index, close the returned bfd, then call
get_elt_at_index with the same position again. You can also easily
crash with openr_next_archived_file if you close the current member
bfd before opening the next one..
--
Alan Modra
Australia Development Lab, IBM