]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit
Fix races involving _bfd_section_id
authorTom Tromey <tom@tromey.com>
Fri, 1 Nov 2024 23:19:20 +0000 (17:19 -0600)
committerTom Tromey <tom@tromey.com>
Thu, 12 Dec 2024 20:13:04 +0000 (13:13 -0700)
commite1093de6a0feeb44a6a2f3bb4509d35eb28bcb66
treef46a2d7fd4516a6bf8965b56aa338dc393aac24c
parentcf11692c90b93a23f5c22b78a116287664e36a04
Fix races involving _bfd_section_id

BFD's threading approach is that global variables are guarded by a
lock.  However, while implementing this, I missed _bfd_section_id.  A
user pointed out, via Thread Sanitizier, that this causes a data race
when gdb's background DWARF reader is enabled.

This patch fixes the problem by using the BFD lock in most of the
appropriate spots.  However, in ppc64_elf_setup_section_lists I chose
to simply assert that multiple threads are not in use instead.  (Not
totally sure if this is good, but I don't think this can be called by
gdb.)

I chose locking in bfd_check_format_matches, even though it is a
relatively big hammer, because it seemed like the most principled
approach, and anyway if this causes severe contention we can always
revisit the decision.  Also this approach means we don't need to add
configury to check for _Atomic, or figure out whether bfd_section_init
can be reworded to make "rollback" unnecessary.

I couldn't reproduce these data races but the original reporter tested
the patch and confirms that it helps.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31713
bfd/bfd.c
bfd/elf64-ppc.c
bfd/format.c
bfd/libbfd.h
bfd/section.c