This is the mail archive of the 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]

Re: who owns a BFD coming from an archive?

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

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