aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom de Vries <tdevries@suse.de>2022-07-15 19:02:26 +0200
committerTom de Vries <tdevries@suse.de>2022-07-21 15:06:40 +0200
commit4f005db8e084bc9825145f048b3b48b35673b2fb (patch)
tree28bb2b29a7634ddfdafbf40be14502bbfbe40457
parentb4303a08c2569e64c193656eae9e097170eb756a (diff)
downloadgdb-4f005db8e084bc9825145f048b3b48b35673b2fb.zip
gdb-4f005db8e084bc9825145f048b3b48b35673b2fb.tar.gz
gdb-4f005db8e084bc9825145f048b3b48b35673b2fb.tar.bz2
[gdb/symtab] Fix data race in add_compunit_symtab_to_objfile
Data race bewteen: ... Read of size 8 at 0x7b4000006d20 by thread T3: #0 add_compunit_symtab_to_objfile(compunit_symtab*) gdb/symfile.c:2852 (gdb+0xe89cff) #1 buildsym_compunit::end_compunit_symtab_with_blockvector(block*, int, int) gdb/buildsym.c:1018 (gdb+0x63e857) #2 buildsym_compunit::end_compunit_symtab_from_static_block(block*, int, int) gdb/buildsym.c:1052 (gdb+0x63e8cd) #3 process_full_comp_unit gdb/dwarf2/read.c:8414 (gdb+0x8396b6) #4 process_queue_item gdb/dwarf2/read.c:7592 (gdb+0x8359f5) ... and: ... Previous write of size 8 at 0x7b4000006d20 by thread T4: #0 add_compunit_symtab_to_objfile(compunit_symtab*) gdb/symfile.c:2853 (gdb+0xe89d35) #1 buildsym_compunit::end_compunit_symtab_with_blockvector(block*, int, int) gdb/buildsym.c:1018 (gdb+0x63e857) #2 buildsym_compunit::end_compunit_symtab_from_static_block(block*, int, int) gdb/buildsym.c:1052 (gdb+0x63e8cd) #3 process_full_comp_unit gdb/dwarf2/read.c:8414 (gdb+0x8396b6) #4 process_queue_item gdb/dwarf2/read.c:7592 (gdb+0x8359f5) ... Fix this by adding a lock in add_compunit_symtab_to_objfile.
-rw-r--r--gdb/symfile.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/gdb/symfile.c b/gdb/symfile.c
index d2fd08c..649b4bf 100644
--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -2849,6 +2849,10 @@ allocate_compunit_symtab (struct objfile *objfile, const char *name)
void
add_compunit_symtab_to_objfile (struct compunit_symtab *cu)
{
+#if CXX_STD_THREAD
+ static std::mutex add_compunit_symtab_to_objfile_lock;
+ std::lock_guard<std::mutex> guard (add_compunit_symtab_to_objfile_lock);
+#endif
cu->next = cu->objfile ()->compunit_symtabs;
cu->objfile ()->compunit_symtabs = cu;
}