From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by sourceware.org (Postfix) with ESMTPS id 99C453857403 for ; Thu, 14 Jul 2022 06:20:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 99C453857403 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 BB886349B3 for ; Thu, 14 Jul 2022 06:20:05 +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 A802213A23 for ; Thu, 14 Jul 2022 06:20:05 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id IqnaJ5W1z2L6JQAAMHmgww (envelope-from ) for ; Thu, 14 Jul 2022 06:20:05 +0000 Date: Thu, 14 Jul 2022 08:20:04 +0200 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [committed][gdb/symtab] Make per_cu->m_lang atomic Message-ID: <20220714062002.GA609@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-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org 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: , X-List-Received-Date: Thu, 14 Jul 2022 06:20:08 -0000 Hi, When building gdb with -fsanitize=thread and running test-case gdb.dwarf2/inlined_subroutine-inheritance.exp, we run into a data race between: ... Read of size 1 at 0x7b2000003010 by thread T4: #0 packed::operator language() const packed.h:54 #1 dwarf2_per_cu_data::set_lang(language) read.h:363 ... and: ... Previous write of size 1 at 0x7b2000003010 by main thread: #0 dwarf2_per_cu_data::set_lang(language) read.h:365 ... Fix this by making per_cu->m_lang atomic. Tested on x86_64-linux. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29286 Committed to trunk. Thanks, - Tom [gdb/symtab] Make per_cu->m_lang atomic --- gdb/dwarf2/read.h | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/gdb/dwarf2/read.h b/gdb/dwarf2/read.h index acbe298b310..c2f86a9d367 100644 --- a/gdb/dwarf2/read.h +++ b/gdb/dwarf2/read.h @@ -181,7 +181,7 @@ struct dwarf2_per_cu_data std::atomic> m_unit_type {(dwarf_unit_type)0}; /* The language of this CU. */ - packed m_lang = language_unknown; + std::atomic> m_lang {language_unknown}; public: /* True if this CU has been scanned by the indexer; false if @@ -351,21 +351,25 @@ struct dwarf2_per_cu_data enum language lang (bool strict_p = true) const { + enum language l = m_lang.load (); if (strict_p) - gdb_assert (m_lang != language_unknown); - return m_lang; + gdb_assert (l != language_unknown); + return l; } void set_lang (enum language lang) { if (unit_type () == DW_UT_partial) return; - if (m_lang == language_unknown) - /* Set if not set already. */ - m_lang = lang; - else - /* If already set, verify that it's the same value. */ - gdb_assert (m_lang == lang); + /* Set if not set already. */ + packed nope = language_unknown; + if (m_lang.compare_exchange_strong (nope, lang)) + return; + /* If already set, verify that it's the same value. */ + nope = lang; + if (m_lang.compare_exchange_strong (nope, lang)) + return; + gdb_assert_not_reached (); } /* Free any cached file names. */