From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2205) id 93B833858D1E; Thu, 14 Jul 2022 18:47:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 93B833858D1E Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Tom de Vries To: gdb-cvs@sourceware.org Subject: [binutils-gdb] [gdb/symtab] Fix data race in cooked_index_functions::expand_symtabs_matching X-Act-Checkin: binutils-gdb X-Git-Author: Tom de Vries X-Git-Refname: refs/heads/master X-Git-Oldrev: 18a5766d09c262878018af26ecbada38d7262b4d X-Git-Newrev: 7d1a572d6b5194d36a96f36b3d28ce591341deb6 Message-Id: <20220714184757.93B833858D1E@sourceware.org> Date: Thu, 14 Jul 2022 18:47:57 +0000 (GMT) X-BeenThere: gdb-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 14 Jul 2022 18:47:57 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D7d1a572d6b51= 94d36a96f36b3d28ce591341deb6 commit 7d1a572d6b5194d36a96f36b3d28ce591341deb6 Author: Tom de Vries Date: Thu Jul 14 20:47:54 2022 +0200 [gdb/symtab] Fix data race in cooked_index_functions::expand_symtabs_ma= tching =20 When building gdb with -fsanitize-threads and running test-case gdb.ada/char_enum_unicode.exp, I run into: ... WARNING: ThreadSanitizer: data race (pid=3D21301)^M Write of size 8 at 0x7b2000008080 by main thread:^M #0 free (libtsan.so.2+0x4c5e2)^M #1 _dl_close_worker (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 ... =20 This is fixed by making cooked_index_functions::expand_symtabs_matching= wait for the cooked index finalization to be done. =20 Tested on x86_64-linux. =20 https://sourceware.org/bugzilla/show_bug.cgi?id=3D29311 https://sourceware.org/bugzilla/show_bug.cgi?id=3D29286 Diff: --- gdb/dwarf2/cooked-index.h | 11 +++++++++-- gdb/dwarf2/read.c | 8 +++++--- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/gdb/dwarf2/cooked-index.h b/gdb/dwarf2/cooked-index.h index 439cbb19fa7..f3c26480a81 100644 --- a/gdb/dwarf2/cooked-index.h +++ b/gdb/dwarf2/cooked-index.h @@ -295,6 +295,14 @@ public: explicit cooked_index_vector (vec_type &&vec); DISABLE_COPY_AND_ASSIGN (cooked_index_vector); =20 + /* Wait until the finalization of the entire cooked_index_vector is + done. */ + 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 +311,7 @@ public: 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 (); } =20 /* 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 =3D=3D nullptr) return true; =20 + cooked_index_vector *table + =3D (static_cast + (per_objfile->per_bfd->index_table.get ())); + table->wait (); + dw_expand_symtabs_matching_file_matcher (per_objfile, file_matcher); =20 /* This invariant is documented in quick-functions.h. */ @@ -18604,9 +18609,6 @@ cooked_index_functions::expand_symtabs_matching language_ada }; =20 - cooked_index_vector *table - =3D (static_cast - (per_objfile->per_bfd->index_table.get ())); for (enum language lang : unique_styles) { std::vector name_vec