From: Tom de Vries Date: Fri, 15 Jul 2022 16:54:04 +0000 (+0200) Subject: [gdb] Fix data race in cleanup_undefined_stabs_types X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b4303a08c2569e64c193656eae9e097170eb756a;p=thirdparty%2Fbinutils-gdb.git [gdb] Fix data race in cleanup_undefined_stabs_types 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. --- diff --git a/gdb/stabsread.c b/gdb/stabsread.c index 98ea59de50b..79e8aa1b586 100644 --- a/gdb/stabsread.c +++ b/gdb/stabsread.c @@ -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 guard (cleanup_undefined_stabs_types_lock); +#endif + cleanup_undefined_types_1 (); cleanup_undefined_types_noname (objfile); }