From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id zwWeBZXAz2JPjRIAWB0awg (envelope-from ) for ; Thu, 14 Jul 2022 03:07:01 -0400 Received: by simark.ca (Postfix, from userid 112) id 046111E5EA; Thu, 14 Jul 2022 03:07:01 -0400 (EDT) Authentication-Results: simark.ca; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=ITUwSCEe; dkim-atps=neutral X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RDNS_DYNAMIC,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 953601E13B for ; Thu, 14 Jul 2022 03:07:00 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D18B0385700F for ; Thu, 14 Jul 2022 07:06:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D18B0385700F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1657782419; bh=qiv0IxRNmmxrF4C3YLLV4xpRf1B3IuWZ+y+v0TwcO/I=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=ITUwSCEeZIZR9s7dMWO0CMH1HEcZgzGbFc8ieKozp6smriwLei+vidRfr12EvmK6e tc6+qA56hyajuv0v7m94njJFLOFEe7oLhnKAfDufl7UTA1IS6AV1pimGYiaY+cVVfU 57CEbJ4tMWdlnnSxmoZL0sG+CzZvsrqrFpY8lwTs= Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by sourceware.org (Postfix) with ESMTPS id E0DF6385781F for ; Thu, 14 Jul 2022 07:06:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E0DF6385781F Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 208F434A5D; Thu, 14 Jul 2022 07:06:40 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 06FD513A23; Thu, 14 Jul 2022 07:06:40 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id ZqOGAIDAz2LjOAAAMHmgww (envelope-from ); Thu, 14 Jul 2022 07:06:40 +0000 Date: Thu, 14 Jul 2022 09:06:38 +0200 To: gdb-patches@sourceware.org Subject: [PATCH][gdb/symtab] Fix data race in cooked_index_functions::expand_symtabs_matching Message-ID: <20220714070637.GA22594@delia.home> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Tom de Vries via Gdb-patches Reply-To: Tom de Vries Cc: Tom Tromey Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" 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 (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 ... 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 + (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 - (per_objfile->per_bfd->index_table.get ())); for (enum language lang : unique_styles) { std::vector name_vec