From 333d407393541c078d7c539f3c3907728c5556f7 Mon Sep 17 00:00:00 2001 From: Tom de Vries Date: Fri, 15 Jul 2022 19:10:42 +0200 Subject: [gdb/symtab] Fix data race on objfile->template_symbols Data race between: ... Read of size 8 at 0x7b4000006dd8 by thread T4: #0 new_symbol gdb/dwarf2/read.c:21085 (gdb+0x868212) #1 handle_struct_member_die gdb/dwarf2/read.c:14828 (gdb+0x851be8) #2 process_structure_scope gdb/dwarf2/read.c:14865 (gdb+0x851e70) #3 process_die gdb/dwarf2/read.c:8649 (gdb+0x83a048) #4 read_namespace gdb/dwarf2/read.c:16026 (gdb+0x857a32) #5 process_die gdb/dwarf2/read.c:8689 (gdb+0x83a100) #6 read_file_scope gdb/dwarf2/read.c:9616 (gdb+0x83cb81) #7 process_die gdb/dwarf2/read.c:8620 (gdb+0x839f43) #8 process_full_comp_unit gdb/dwarf2/read.c:8383 (gdb+0x839509) #9 process_queue_item gdb/dwarf2/read.c:7592 (gdb+0x8359f5) ... and: ... Previous write of size 8 at 0x7b4000006dd8 by main thread: #0 new_symbol gdb/dwarf2/read.c:21086 (gdb+0x868247) #1 handle_struct_member_die gdb/dwarf2/read.c:14828 (gdb+0x851be8) #2 process_structure_scope gdb/dwarf2/read.c:14865 (gdb+0x851e70) #3 process_die gdb/dwarf2/read.c:8649 (gdb+0x83a048) #4 read_namespace gdb/dwarf2/read.c:16026 (gdb+0x857a32) #5 process_die gdb/dwarf2/read.c:8689 (gdb+0x83a100) #6 read_file_scope gdb/dwarf2/read.c:9616 (gdb+0x83cb81) #7 process_die gdb/dwarf2/read.c:8620 (gdb+0x839f43) #8 process_full_comp_unit gdb/dwarf2/read.c:8383 (gdb+0x839509) #9 process_queue_item gdb/dwarf2/read.c:7592 (gdb+0x8359f5) ... Fix this by adding a lock in new_symbol for adding to objfile->template_symbols. --- gdb/dwarf2/read.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 66f3ca0..d0452ab 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -21098,6 +21098,10 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu, if (suppress_add) { +#if CXX_STD_THREAD + static std::mutex template_symbols_lock; + std::lock_guard guard (template_symbols_lock); +#endif sym->hash_next = objfile->template_symbols; objfile->template_symbols = sym; list_to_add = NULL; -- cgit v1.1