From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 0PzSLZW1z2J4hxIAWB0awg (envelope-from ) for ; Thu, 14 Jul 2022 02:20:05 -0400 Received: by simark.ca (Postfix, from userid 112) id B7DEF1E5EA; Thu, 14 Jul 2022 02:20:05 -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=k5WfsUSH; 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=-3.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from sourceware.org (server2.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 7369C1E13B for ; Thu, 14 Jul 2022 02:20:04 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E68C43857004 for ; Thu, 14 Jul 2022 06:20:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E68C43857004 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1657779603; bh=56P2VU1eWmfE3B5VhkANZwV87jKxirHv5TpTN4MDM/c=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=k5WfsUSHqPwVyFggbkCfp+zsP9b0nO/nz/cSPZROchQ9rtKH0OppOap28lT6HbWQe S/2dOwnaKq1Q/lK8/UhvDbiskRWvQkaQIht3B0Svyy4IHE16CXsu4h1TanaSoSBx5N mi8+/5krVhEJ3nmvQom3NB3Csz3sJk1grzJBAIOo= 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 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-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 Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" 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