Skip to content

Commit

Permalink
[gdb/symtab] Fix data race on objfile->template_symbols
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
vries committed Jul 21, 2022
1 parent 4f005db commit 333d407
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions gdb/dwarf2/read.c
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::mutex> guard (template_symbols_lock);
#endif
sym->hash_next = objfile->template_symbols;
objfile->template_symbols = sym;
list_to_add = NULL;
Expand Down

0 comments on commit 333d407

Please sign in to comment.