From a357defdfe2af758d5ec9f0040949bf1db4cbe53 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Sat, 9 Nov 2024 13:45:50 -0700 Subject: Lock bfd_stat and bfd_get_mtime PR gdb/31713 points out some races when using the background DWARF reader. This particular patch fixes some of these, namely the ones when using the sim. In this case, the 'load' command calls reopen_exec_file, which calls bfd_stat, which introduces a race. BFD only locks globals -- concurrent use of a single BFD must be handled by the application. To this end, this patch adds locked wrappers for bfd_stat and bfd_get_mtime. 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 Approved-By: Andrew Burgess --- gdb/gdb_bfd.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'gdb/gdb_bfd.c') diff --git a/gdb/gdb_bfd.c b/gdb/gdb_bfd.c index 3683eeb..c233551 100644 --- a/gdb/gdb_bfd.c +++ b/gdb/gdb_bfd.c @@ -1121,6 +1121,32 @@ gdb_bfd_get_full_section_contents (bfd *abfd, asection *section, section_size); } +/* See gdb_bfd.h. */ + +int +gdb_bfd_stat (bfd *abfd, struct stat *sbuf) +{ +#if CXX_STD_THREAD + gdb_bfd_data *gdata = (gdb_bfd_data *) bfd_usrdata (abfd); + std::lock_guard guard (gdata->per_bfd_mutex); +#endif + + return bfd_stat (abfd, sbuf); +} + +/* See gdb_bfd.h. */ + +long +gdb_bfd_get_mtime (bfd *abfd) +{ +#if CXX_STD_THREAD + gdb_bfd_data *gdata = (gdb_bfd_data *) bfd_usrdata (abfd); + std::lock_guard guard (gdata->per_bfd_mutex); +#endif + + return bfd_get_mtime (abfd); +} + #define AMBIGUOUS_MESS1 ".\nMatching formats:" #define AMBIGUOUS_MESS2 \ ".\nUse \"set gnutarget format-name\" to specify the format." -- cgit v1.1