]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
[gdb/symtab] Fix data race in objstats->n_syms
authorTom de Vries <tdevries@suse.de>
Fri, 15 Jul 2022 14:56:56 +0000 (16:56 +0200)
committerTom de Vries <tdevries@suse.de>
Thu, 21 Jul 2022 13:06:40 +0000 (15:06 +0200)
Data race between:
...
  Read of size 4 at 0x7b4000006dc8 by main thread:
    #0 new_symbol gdb/dwarf2/read.c:20704 (gdb+0x866f3e)
    #1 process_die gdb/dwarf2/read.c:8674 (gdb+0x839fa8)
    #2 read_file_scope gdb/dwarf2/read.c:9610 (gdb+0x83ca7f)
    #3 process_die gdb/dwarf2/read.c:8614 (gdb+0x839e41)
    #4 process_full_comp_unit gdb/dwarf2/read.c:8383 (gdb+0x839480)
    #5 process_queue_item gdb/dwarf2/read.c:7592 (gdb+0x83599f)
...
and:
...
  Previous write of size 4 at 0x7b4000006dc8 by thread T2:
    #0 new_symbol gdb/dwarf2/read.c:20704 (gdb+0x866f5d)
    #1 process_die gdb/dwarf2/read.c:8674 (gdb+0x839fa8)
    #2 read_file_scope gdb/dwarf2/read.c:9610 (gdb+0x83ca7f)
    #3 process_die gdb/dwarf2/read.c:8614 (gdb+0x839e41)
    #4 process_full_comp_unit gdb/dwarf2/read.c:8383 (gdb+0x839480)
    #5 process_queue_item gdb/dwarf2/read.c:7592 (gdb+0x83599f)
...

Fix by making objstats->n_syms atomic.  Likewise for n_types.

gdb/objfiles.h
gdb/symmisc.c

index a35aafb876e60570205467ddce6a7ec243accc87..7803ebbb74e1c55c4bea48a381e3beb0aa895e1e 100644 (file)
@@ -167,13 +167,13 @@ struct entry_info
 struct objstats
 {
   /* Number of full symbols read.  */
-  int n_syms = 0;
+  std::atomic<int> n_syms {0};
 
   /* Number of ".stabs" read (if applicable).  */
   int n_stabs = 0;
 
   /* Number of types.  */
-  int n_types = 0;
+  std::atomic<int> n_types {0};
 
   /* Size of stringtable, (if applicable).  */
   int sz_strtab = 0;
index e1d6b2064e7e50773b6562f2765aff567b54e53b..ad49245df9b6acdb3fcc2489877544725b9e703b 100644 (file)
@@ -66,10 +66,10 @@ print_objfile_statistics (void)
                      objfile->per_bfd->n_minsyms);
        if (OBJSTAT (objfile, n_syms) > 0)
          gdb_printf (_("  Number of \"full\" symbols read: %d\n"),
-                     OBJSTAT (objfile, n_syms));
+                     OBJSTAT (objfile, n_syms).load ());
        if (OBJSTAT (objfile, n_types) > 0)
          gdb_printf (_("  Number of \"types\" defined: %d\n"),
-                     OBJSTAT (objfile, n_types));
+                     OBJSTAT (objfile, n_types).load ());
 
        i = linetables = 0;
        for (compunit_symtab *cu : objfile->compunits ())