aboutsummaryrefslogtreecommitdiff
path: root/gdb/gdb_bfd.c
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2024-11-09 13:45:50 -0700
committerTom Tromey <tom@tromey.com>2024-12-12 15:17:39 -0700
commita357defdfe2af758d5ec9f0040949bf1db4cbe53 (patch)
tree083ad517656fad650c0c582fe09ea7f589187bec /gdb/gdb_bfd.c
parente1093de6a0feeb44a6a2f3bb4509d35eb28bcb66 (diff)
downloadbinutils-a357defdfe2af758d5ec9f0040949bf1db4cbe53.zip
binutils-a357defdfe2af758d5ec9f0040949bf1db4cbe53.tar.gz
binutils-a357defdfe2af758d5ec9f0040949bf1db4cbe53.tar.bz2
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 <aburgess@redhat.com>
Diffstat (limited to 'gdb/gdb_bfd.c')
-rw-r--r--gdb/gdb_bfd.c26
1 files changed, 26 insertions, 0 deletions
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<std::mutex> 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<std::mutex> 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."