public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom de Vries <tdevries@suse.de>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [PATCH][gdb/symtab] Fix data race in cooked_index_functions::expand_symtabs_matching
Date: Thu, 14 Jul 2022 09:06:38 +0200	[thread overview]
Message-ID: <20220714070637.GA22594@delia.home> (raw)

Hi,

When building gdb with -fsanitize-threads and running test-case
gdb.ada/char_enum_unicode.exp, I run into:
...
WARNING: ThreadSanitizer: data race (pid=21301)^M
  Write of size 8 at 0x7b2000008080 by main thread:^M
    #0 free <null> (libtsan.so.2+0x4c5e2)^M
    #1 _dl_close_worker <null> (ld-linux-x86-64.so.2+0x4b7b)^M
    #2 convert_between_encodings() charset.c:584^M
  ...
    #21 cooked_index_functions::expand_symtabs_matching() read.c:18606
...

This is fixed by making cooked_index_functions::expand_symtabs_matching wait
for the cooked index finalization to be done.

Tested on x86_64-linux.

https://sourceware.org/bugzilla/show_bug.cgi?id=29311
https://sourceware.org/bugzilla/show_bug.cgi?id=29286

Any comments?

Thanks,
- Tom

[gdb/symtab] Fix data race in cooked_index_functions::expand_symtabs_matching

---
 gdb/dwarf2/cooked-index.h | 9 +++++++--
 gdb/dwarf2/read.c         | 8 +++++---
 2 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/gdb/dwarf2/cooked-index.h b/gdb/dwarf2/cooked-index.h
index 439cbb19fa7..787ead30abe 100644
--- a/gdb/dwarf2/cooked-index.h
+++ b/gdb/dwarf2/cooked-index.h
@@ -295,6 +295,12 @@ class cooked_index_vector : public dwarf_scanner_base
   explicit cooked_index_vector (vec_type &&vec);
   DISABLE_COPY_AND_ASSIGN (cooked_index_vector);
 
+  void wait ()
+  {
+    for (auto &item : m_vector)
+      item->wait ();
+  }
+
   ~cooked_index_vector ()
   {
     /* The 'finalize' methods may be run in a different thread.  If
@@ -303,8 +309,7 @@ class cooked_index_vector : public dwarf_scanner_base
        complete avoids this problem; and the cost seems ignorable
        because creating and immediately destroying the debug info is a
        relatively rare thing to do.  */
-    for (auto &item : m_vector)
-      item->wait ();
+    wait ();
   }
 
   /* A range over a vector of subranges.  */
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 5ca787cc095..bcd01107377 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -18569,6 +18569,11 @@ cooked_index_functions::expand_symtabs_matching
   if (per_objfile->per_bfd->index_table == nullptr)
     return true;
 
+  cooked_index_vector *table
+    = (static_cast<cooked_index_vector *>
+       (per_objfile->per_bfd->index_table.get ()));
+  table->wait ();
+
   dw_expand_symtabs_matching_file_matcher (per_objfile, file_matcher);
 
   /* This invariant is documented in quick-functions.h.  */
@@ -18604,9 +18609,6 @@ cooked_index_functions::expand_symtabs_matching
     language_ada
   };
 
-  cooked_index_vector *table
-    = (static_cast<cooked_index_vector *>
-       (per_objfile->per_bfd->index_table.get ()));
   for (enum language lang : unique_styles)
     {
       std::vector<gdb::string_view> name_vec

             reply	other threads:[~2022-07-14  7:06 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-14  7:06 Tom de Vries [this message]
2022-07-14 17:32 ` Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220714070637.GA22594@delia.home \
    --to=tdevries@suse.de \
    --cc=gdb-patches@sourceware.org \
    --cc=tom@tromey.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).