[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.
This commit is contained in:
Tom de Vries
2022-07-15 18:54:04 +02:00
parent c2ae16cc58
commit b4303a08c2

View File

@@ -4497,6 +4497,11 @@ cleanup_undefined_types_1 (void)
void void
cleanup_undefined_stabs_types (struct objfile *objfile) 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_1 ();
cleanup_undefined_types_noname (objfile); cleanup_undefined_types_noname (objfile);
} }