]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
[gdb] Fix data race in cleanup_undefined_stabs_types
authorTom de Vries <tdevries@suse.de>
Fri, 15 Jul 2022 16:54:04 +0000 (18:54 +0200)
committerTom de Vries <tdevries@suse.de>
Thu, 21 Jul 2022 13:06:40 +0000 (15:06 +0200)
Data race for:
...
  Read of size 4 at 0x00000324db04 by thread T1:
    #0 cleanup_undefined_types_1 /home/vries/gdb_versions/devel/src/gdb/stabsread.c:4437 (gdb+0xe60bdd)
    #1 cleanup_undefined_stabs_types(objfile*) /home/vries/gdb_versions/devel/src/gdb/stabsread.c:4500 (gdb+0xe60c48)
    #2 buildsym_compunit::end_compunit_symtab_get_static_block(unsigned long, int, int) /home/vries/gdb_versions/devel/src/gdb/buildsym.c:837 (gdb+0x63dbba)
    #3 process_full_comp_unit /home/vries/gdb_versions/devel/src/gdb/dwarf2/read.c:8404 (gdb+0x8395f4)
    #4 process_queue_item /home/vries/gdb_versions/devel/src/gdb/dwarf2/read.c:7592 (gdb+0x8359f5)
...
and location:
...
  Location is global 'undef_types_length' of size 4 at 0x00000324db04
...

Likewise for:
...
WARNING: ThreadSanitizer: data race (pid=12737)
  Read of size 4 at 0x00000324db1c by thread T4:
    #0 cleanup_undefined_types_noname /home/vries/gdb_versions/devel/src/gdb/stabsread.c:4383 (gdb+0xe608b2)
    #1 cleanup_undefined_stabs_types(objfile*) /home/vries/gdb_versions/devel/src/gdb/stabsread.c:4501 (gdb+0xe60c54)
    #2 buildsym_compunit::end_compunit_symtab_get_static_block(unsigned long, int, int) /home/vries/gdb_versions/devel/src/gdb/buildsym.c:837 (gdb+0x63dbba)
    #3 process_full_comp_unit /home/vries/gdb_versions/devel/src/gdb/dwarf2/read.c:8404 (gdb+0x8395f4)
    #4 process_queue_item /home/vries/gdb_versions/devel/src/gdb/dwarf2/read.c:7592 (gdb+0x8359f5)
...
and location:
...
  Location is global 'noname_undefs_length' of size 4 at 0x00000324db1c
...

Fix this by adding a lock in cleanup_undefined_stabs_types.

gdb/stabsread.c

index 98ea59de50b8400351b7f2d98ca341989c3d16f6..79e8aa1b586e7c04b51fe34fc54eb6d6775c521e 100644 (file)
@@ -4497,6 +4497,11 @@ cleanup_undefined_types_1 (void)
 void
 cleanup_undefined_stabs_types (struct objfile *objfile)
 {
+#if CXX_STD_THREAD
+  static std::mutex cleanup_undefined_stabs_types_lock;
+  std::lock_guard<std::mutex> guard (cleanup_undefined_stabs_types_lock);
+#endif
+
   cleanup_undefined_types_1 ();
   cleanup_undefined_types_noname (objfile);
 }