]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
[gdb] Fix data race in bcache::insert
authorTom de Vries <tdevries@suse.de>
Fri, 15 Jul 2022 15:45:53 +0000 (17:45 +0200)
committerTom de Vries <tdevries@suse.de>
Thu, 21 Jul 2022 13:06:40 +0000 (15:06 +0200)
Data race between:
...
  Read of size 8 at 0x7bb4000000d0 by thread T4:
    #0 gdb::bcache::insert(void const*, int, bool*) gdb/bcache.c:155
    #1 objfile_per_bfd_storage::intern(char const*) gdb/objfiles.h:250
    #2 objfile::intern(char const*) gdb/objfiles.h:475
    #3 dwarf2_canonicalize_name gdb/dwarf2/read.c:21904
    #4 dwarf2_name gdb/dwarf2/read.c:21999
    #5 read_base_type gdb/dwarf2/read.c:17092
    #6 read_type_die_1 gdb/dwarf2/read.c:21529
    #7 read_type_die gdb/dwarf2/read.c:21464
    #8 process_die gdb/dwarf2/read.c:8674
    #9 read_file_scope gdb/dwarf2/read.c:9610
    #10 process_die gdb/dwarf2/read.c:8614
    #11 process_full_comp_unit gdb/dwarf2/read.c:8383
    #12 process_queue_item gdb/dwarf2/read.c:7592
...
and:
...
  Previous write of size 8 at 0x7bb4000000d0 by main thread:
    #0 gdb::bcache::insert(void const*, int, bool*) gdb/bcache.c:167
    #1 objfile_per_bfd_storage::intern(std::__cxx11::basic_string<char,
    std::char_traits<char>, std::allocator<char> > const&) gdb/objfiles.h:257
    #2 objfile::intern(std::__cxx11::basic_string<char,
    std::char_traits<char>, std::allocator<char> > const&) <null>
    #3 dwarf2_compute_name gdb/dwarf2/read.c:9050
    #4 dwarf2_full_name gdb/dwarf2/read.c:9070
    #5 read_structure_type gdb/dwarf2/read.c:14558
    #6 process_structure_scope gdb/dwarf2/read.c:14847
    #7 process_die gdb/dwarf2/read.c:8643
    #8 read_file_scope gdb/dwarf2/read.c:9610
    #9 process_die gdb/dwarf2/read.c:8614
    #10 process_full_comp_unit gdb/dwarf2/read.c:8383
    #11 process_queue_item gdb/dwarf2/read.c:7592
...

gdb/bcache.c

index 80ba1f6b6ecc037fc430411ddf19ea7b8b56652c..a2b7ba11369c0141e163c481dfb1327379cd0657 100644 (file)
 #include "bcache.h"
 
 #include <algorithm>
+#include <mutex>
+
+#if CXX_STD_THREAD
+static std::mutex bcache_lock;
+#endif
 
 namespace gdb {
 
@@ -63,6 +68,9 @@ struct bstring
 void
 bcache::expand_hash_table ()
 {
+#if CXX_STD_THREAD
+  //std::lock_guard<std::mutex> guard (bcache_lock);
+#endif
   /* A table of good hash table sizes.  Whenever we grow, we pick the
      next larger size from this table.  sizes[i] is close to 1 << (i+10),
      so we roughly double the table size each time.  After we fall off 
@@ -142,6 +150,9 @@ bcache::expand_hash_table ()
 const void *
 bcache::insert (const void *addr, int length, bool *added)
 {
+#if CXX_STD_THREAD
+  std::lock_guard<std::mutex> guard (bcache_lock);
+#endif
   unsigned long full_hash;
   unsigned short half_hash;
   int hash_index;