From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by sourceware.org (Postfix) with ESMTPS id 1848C3857403 for ; Thu, 14 Jul 2022 06:19:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1848C3857403 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-out2.suse.de (Postfix) with ESMTPS id 4EF4C206A5 for ; Thu, 14 Jul 2022 06:19:43 +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 3BEBF13A23 for ; Thu, 14 Jul 2022 06:19:43 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id Un6CDX+1z2LXJQAAMHmgww (envelope-from ) for ; Thu, 14 Jul 2022 06:19:43 +0000 Date: Thu, 14 Jul 2022 08:19:41 +0200 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [committed][gdb/symtab] Make per_cu->unit_type atomic Message-ID: <20220714061940.GA575@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.6 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:19:45 -0000 Hi, With gdb with -fsanitize=thread and test-case gdb.ada/array_bounds.exp, I run into a data race between: ... Read of size 1 at 0x7b2000025f0f by main thread: #0 packed::operator dwarf_unit_type() const packed.h:54 #1 dwarf2_per_cu_data::set_unit_type(dwarf_unit_type) read.h:339 ... and: ... Previous write of size 1 at 0x7b2000025f0f by thread T3: #0 dwarf2_per_cu_data::set_unit_type(dwarf_unit_type) read.h:341 ... Fix this by making per_cu->unit_type 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->unit_type atomic --- gdb/dwarf2/read.h | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/gdb/dwarf2/read.h b/gdb/dwarf2/read.h index fcf0cd70530..acbe298b310 100644 --- a/gdb/dwarf2/read.h +++ b/gdb/dwarf2/read.h @@ -178,7 +178,7 @@ struct dwarf2_per_cu_data private: /* The unit type of this CU. */ - packed m_unit_type = (dwarf_unit_type) 0; + std::atomic> m_unit_type {(dwarf_unit_type)0}; /* The language of this CU. */ packed m_lang = language_unknown; @@ -329,19 +329,24 @@ struct dwarf2_per_cu_data dwarf_unit_type unit_type (bool strict_p = true) const { + dwarf_unit_type ut = m_unit_type.load (); if (strict_p) - gdb_assert (m_unit_type != 0); - return m_unit_type; + gdb_assert (ut != 0); + return ut; } void set_unit_type (dwarf_unit_type unit_type) { - if (m_unit_type == 0) - /* Set if not set already. */ - m_unit_type = unit_type; - else - /* If already set, verify that it's the same value. */ - gdb_assert (m_unit_type == unit_type); + /* Set if not set already. */ + packed nope = (dwarf_unit_type)0; + if (m_unit_type.compare_exchange_strong (nope, unit_type)) + return; + + /* If already set, verify that it's the same value. */ + nope = unit_type; + if (m_unit_type.compare_exchange_strong (nope, unit_type)) + return; + gdb_assert_not_reached (); } enum language lang (bool strict_p = true) const