]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit
Avoid cache race in bfd_check_format_matches
authorTom Tromey <tom@tromey.com>
Sat, 23 Mar 2024 21:19:20 +0000 (15:19 -0600)
committerTom Tromey <tom@tromey.com>
Tue, 16 Apr 2024 20:02:15 +0000 (14:02 -0600)
commit20bf7711bce2188c1af985a87df23c4653c2cc7a
tree1694e1225dc42af7cd6b46d07e6323bd7bcd4a33
parentbacc61fd3e6fd61a59fb59bcc657be17a381520d
Avoid cache race in bfd_check_format_matches

Running the gdb test suite with the thread sanitizer enabled shows a
race when bfd_check_format_matches and bfd_cache_close_all are called
simultaneously on different threads.

This patch fixes this race by having bfd_check_format_matches
temporarily remove the BFD from the file descriptor cache -- leaving
it open while format-checking proceeds.

In this setup, the BFD client is responsible for closing the BFD again
on the "checking" thread, should that be desired.  gdb does this by
calling bfd_cache_close in the relevant worker thread.

An earlier version of this patch omitted the "possibly_cached" helper
function.  However, this ran into crashes in the binutils test suite
involving the archive-checking abort in bfd_cache_lookup_worker.  I do
not understand the purpose of this check, so I've simply had the new
function work around it.  I couldn't find any comments explaining this
situation, either.  I suspect that there may still be races related to
this case, but I don't think I have access to the platforms where gdb
deals with archives.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31264
bfd/bfd-in2.h
bfd/bfd.c
bfd/cache.c
bfd/format.c
bfd/libbfd.h