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 C9EBA3851A82 for ; Wed, 29 Jun 2022 15:29:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C9EBA3851A82 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 B184A1F8EF; Wed, 29 Jun 2022 15:29:15 +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 9890013AF4; Wed, 29 Jun 2022 15:29:15 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id gAIsJMtvvGKNIQAAMHmgww (envelope-from ); Wed, 29 Jun 2022 15:29:15 +0000 From: Tom de Vries To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 4/5] [gdb/symtab] Work around fsanitize=address false positive for per_cu->unit_type Date: Wed, 29 Jun 2022 17:29:13 +0200 Message-Id: <20220629152914.13149-4-tdevries@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220629152914.13149-1-tdevries@suse.de> References: <20220629152914.13149-1-tdevries@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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: Wed, 29 Jun 2022 15:29:18 -0000 When building gdb with -fsanitize=thread and gcc 12, and running test-case gdb.dwarf2/dwz.exp, we run into a data race between: ... Write of size 1 at 0x7b200000300e by thread T4: #0 process_psymtab_comp_unit gdb/dwarf2/read.c:6789 (gdb+0x830720) ... and: ... Previous read of size 1 at 0x7b200000300e by main thread: #0 cutu_reader::cutu_reader(dwarf2_per_cu_data*, dwarf2_per_objfile*, \ abbrev_table*, dwarf2_cu*, bool, abbrev_cache*) gdb/dwarf2/read.c:6164 \ (gdb+0x82edab) ... In other words, between: ... this_cu->unit_type = DW_UT_partial; ... and: ... if (this_cu->reading_dwo_directly) ... Both fields are part of the same bitfield, and writing to one field while reading from another is not a problem, so this is a false positive. Fix this by moving the unit_type field out of the bitfield. Use type unsigned char instead of enum dwarf_unit_type to keep requiring only 8 bits. The size of struct dwarf2_per_cu_data remains the same (at least for -m64). Tested on x86_64-linux. --- gdb/dwarf2/read.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/gdb/dwarf2/read.h b/gdb/dwarf2/read.h index db300b19621..abce4f83f39 100644 --- a/gdb/dwarf2/read.h +++ b/gdb/dwarf2/read.h @@ -100,6 +100,7 @@ struct dwarf2_per_cu_data { dwarf2_per_cu_data () : lang (language_unknown), + unit_type {}, queued (false), is_debug_types (false), is_dwz (false), @@ -109,7 +110,6 @@ struct dwarf2_per_cu_data addresses_seen (false), mark (false), files_read (false), - unit_type {}, scanned (false) { } @@ -128,6 +128,10 @@ struct dwarf2_per_cu_data /* The language of this CU. */ language lang; + /* The unit type of this CU. We'd like to use dwarf_unit_type but that + requires 'int' storage. */ + unsigned char unit_type; + /* Flag indicating this compilation unit will be read in before any of the current compilation units are processed. */ unsigned int queued : 1; @@ -174,9 +178,6 @@ struct dwarf2_per_cu_data point in trying to read it again next time. */ bool files_read : 1; - /* The unit type of this CU. */ - ENUM_BITFIELD (dwarf_unit_type) unit_type : 8; - /* True if this CU has been scanned by the indexer; false if not. */ std::atomic scanned; -- 2.35.3