aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom de Vries <tdevries@suse.de>2022-07-15 18:46:03 +0200
committerTom de Vries <tdevries@suse.de>2022-07-21 15:06:40 +0200
commitc2ae16cc58b64e21a6b993544943fb9612e904a2 (patch)
treeb8ed3af6ef76ed5b0983a9eeeb39132c60de5579
parenta4f4bbc3530f68e615ac5614224bdcb7c21d68dc (diff)
downloadgdb-c2ae16cc58b64e21a6b993544943fb9612e904a2.zip
gdb-c2ae16cc58b64e21a6b993544943fb9612e904a2.tar.gz
gdb-c2ae16cc58b64e21a6b993544943fb9612e904a2.tar.bz2
[gdb/symtab] Fix race condition in just_read_cus
Race condition between: ... Read of size 8 at 0x7b640001f2c8 by thread T1: #0 std::vector<dwarf2_per_cu_data*, std::allocator<dwarf2_per_cu_data*> >::push_back(dwarf2_per_cu_data* const&) /usr/include/c++/12/bits/stl_vector.h:1278 (gdb+0x888ad6) #1 process_full_comp_unit gdb/dwarf2/read.c:8451 (gdb+0x8397d0) #2 process_queue_item gdb/dwarf2/read.c:7592 (gdb+0x8359f5) ... and: ... Previous write of size 8 at 0x7b640001f2c8 by main thread: #0 std::vector<dwarf2_per_cu_data*, std::allocator<dwarf2_per_cu_data*> >::push_back(dwarf2_per_cu_data* const&) /usr/include/c++/12/bits/stl_vector.h:1283 (gdb+0x888b52) #1 process_full_comp_unit gdb/dwarf2/read.c:8451 (gdb+0x8397d0) #2 process_queue_item gdb/dwarf2/read.c:7592 (gdb+0x8359f5) ... Fix this by doing the just_read_cus push_back in a lock.
-rw-r--r--gdb/dwarf2/read.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 11ba01c..66f3ca0 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -8463,8 +8463,14 @@ process_full_comp_unit (dwarf2_cu *cu, enum language pretend_language)
per_objfile->set_symtab (cu->per_cu, cust);
- /* Push it for inclusion processing later. */
- per_objfile->per_bfd->just_read_cus.push_back (cu->per_cu);
+#if CXX_STD_THREAD
+ {
+ static std::mutex just_read_cus_lock;
+ std::lock_guard<std::mutex> guard (just_read_cus_lock);
+#endif
+ /* Push it for inclusion processing later. */
+ per_objfile->per_bfd->just_read_cus.push_back (cu->per_cu);
+ }
/* Not needed any more. */
cu->reset_builder ();