From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 4yb5LIRnsmVCkgcAWB0awg (envelope-from ) for ; Thu, 25 Jan 2024 08:52:04 -0500 Authentication-Results: simark.ca; dkim=fail reason="signature verification failed" (768-bit key; unprotected) header.d=tromey.com header.i=@tromey.com header.a=rsa-sha256 header.s=default header.b=dprRNwfA; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id AA5DF1E0C3; Thu, 25 Jan 2024 08:52:04 -0500 (EST) Received: from server2.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 ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 757541E092 for ; Thu, 25 Jan 2024 08:52:02 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 130803857C4A for ; Thu, 25 Jan 2024 13:52:02 +0000 (GMT) Received: from omta38.uswest2.a.cloudfilter.net (omta38.uswest2.a.cloudfilter.net [35.89.44.37]) by sourceware.org (Postfix) with ESMTPS id 8CF243858C29 for ; Thu, 25 Jan 2024 13:51:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8CF243858C29 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 8CF243858C29 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=35.89.44.37 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706190701; cv=none; b=LM3oj3/r5QB2aJ9n6NJ8gpJ7hDlrGz2gJkdgXLIODHGNbQ1uFowV+jqSFqGNlJVBc1wPZX7E/031t44xANDddZOoRKxnHHFvJSrvMDVzqgXCkkHAZ2uZrR4rE+AQ60SWdJ+EEot5tq0ABlEVrbbYozHu9x0wzSo7RbDNFgMHDmU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706190701; c=relaxed/simple; bh=5X6bt7qq43UiS9pp6A1Yw4FEUZjZraoqd9qSL7LaP7I=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=H2pb9qkol0duNS3wiu6fwdBcVDTShOgjycfqV/8cNhg2ELyz7p1HubEwd7EcoVIzrat1h3V7E5tF+wVPakLOk5ZZXEmo9ZeR/whbFfgrDGikDx9ZvmU8wkVCkiPEEcSoniKB4mEvwK5u3sXWgzCoZfh11iKNSvjZJnsu7x2kd6c= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from eig-obgw-6007a.ext.cloudfilter.net ([10.0.30.247]) by cmsmtp with ESMTPS id Szf4rImEKoMN9T08nrN2CI; Thu, 25 Jan 2024 13:51:37 +0000 Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTPS id T08mrgInlyxR5T08mr611N; Thu, 25 Jan 2024 13:51:36 +0000 X-Authority-Analysis: v=2.4 cv=JYOvEGGV c=1 sm=1 tr=0 ts=65b26768 a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=dEuoMetlWLkA:10 a=Qbun_eYptAEA:10 a=CCpqsmhAAAAA:8 a=bUsNEMq01XhKxhKeYxUA:9 a=ul9cdbp4aOFLsgKbc677:22 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Content-Transfer-Encoding:MIME-Version:Message-ID:Date:Subject: Cc:To:From:Sender:Reply-To:Content-Type:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=yR1Gy0p6gLtPspSOfuCtebZAwhGzyiExFh5fSw5URIo=; b=dprRNwfATQOuvshuyA7vwjZdNm gDvSShbP5NJSihCSQ+k4NUn8U13X7fuGLsF/vN+ADBcjsl1b5nwkoPbUsVCu2i1uyqkwRYj4/jx94 VMOuhFwhGuLceHiHZBc/3jW7w; Received: from 97-122-68-157.hlrn.qwest.net ([97.122.68.157]:59808 helo=localhost.localdomain) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96.2) (envelope-from ) id 1rT08l-000lmX-2d; Thu, 25 Jan 2024 06:51:35 -0700 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH] Avoid race when reading dwz file Date: Thu, 25 Jan 2024 06:51:29 -0700 Message-ID: <20240125135129.977108-1-tom@tromey.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5379.bluehost.com X-AntiAbuse: Original Domain - sourceware.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 97.122.68.157 X-Source-L: No X-Exim-ID: 1rT08l-000lmX-2d X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-122-68-157.hlrn.qwest.net (localhost.localdomain) [97.122.68.157]:59808 X-Source-Auth: tom+tromey.com X-Email-Count: 1 X-Org: HG=bhshared;ORG=bluehost; X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-CMAE-Envelope: MS4xfHAZukSz7864xY+AUzI1vsc7Ze/jBhQwIsgn6Gpo+yZMjOFct2GBa8rISgHO6a49M4rvB5Bt8mqPE5U4oM0sagIsSVidht6WTNou4wWZ3qdaoobexWiW su4JkFO5P9hUNuOcMSJPN7uSd2veXy4dZWjqIuCay7ILg3h0nZ8BmFH5wwP7gIlEjY5HPFHBN/6Fjlf4DoHHgX8mQMhHhPm5h84= X-Spam-Status: No, score=-3022.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, RCVD_IN_MSPIKE_H2, 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.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org PR gdb/31260 points out a race introduced by the background reading changes. If a given objfile is re-opened when it is already being read, dwarf2_initialize_objfile will call dwarf2_read_dwz_file again, causing the 'dwz_file' to be reset. This patch fixes the problem by arranging to open the dwz just once: when the dwarf2_per_bfd object is created. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31260 --- gdb/dwarf2/dwz.c | 15 ++++++--------- gdb/dwarf2/read.c | 29 ++++++++++++++++++----------- 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/gdb/dwarf2/dwz.c b/gdb/dwarf2/dwz.c index 5c855f4c265..f53a5b64c4a 100644 --- a/gdb/dwarf2/dwz.c +++ b/gdb/dwarf2/dwz.c @@ -188,6 +188,8 @@ dwarf2_read_dwz_file (dwarf2_per_objfile *per_objfile) only be run in the main thread. */ gdb_assert (is_main_thread ()); + /* This should only be called once. */ + gdb_assert (!per_bfd->dwz_file.has_value ()); /* Set this early, so that on error it remains NULL. */ per_bfd->dwz_file.emplace (nullptr); @@ -281,14 +283,9 @@ dwarf2_read_dwz_file (dwarf2_per_objfile *per_objfile) struct dwz_file * dwarf2_get_dwz_file (dwarf2_per_bfd *per_bfd, bool require) { - gdb_assert (!require || per_bfd->dwz_file.has_value ()); - - dwz_file *result = nullptr; - if (per_bfd->dwz_file.has_value ()) - { - result = per_bfd->dwz_file->get (); - if (require && result == nullptr) - error (_("could not read '.gnu_debugaltlink' section")); - } + gdb_assert (per_bfd->dwz_file.has_value ()); + dwz_file *result = per_bfd->dwz_file->get (); + if (require && result == nullptr) + error (_("could not read '.gnu_debugaltlink' section")); return result; } diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 925a5ea4a5b..d37d392c90b 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -1367,6 +1367,7 @@ dwarf2_has_info (struct objfile *objfile, if (per_objfile == NULL) { dwarf2_per_bfd *per_bfd; + bool just_created = false; /* We can share a "dwarf2_per_bfd" with other objfiles if the BFD doesn't require relocations. @@ -1386,6 +1387,7 @@ dwarf2_has_info (struct objfile *objfile, per_bfd = new dwarf2_per_bfd (objfile->obfd.get (), names, can_copy); dwarf2_per_bfd_bfd_data_key.set (objfile->obfd.get (), per_bfd); + just_created = true; } } else @@ -1393,9 +1395,25 @@ dwarf2_has_info (struct objfile *objfile, /* No sharing possible, create one specifically for this objfile. */ per_bfd = new dwarf2_per_bfd (objfile->obfd.get (), names, can_copy); dwarf2_per_bfd_objfile_data_key.set (objfile, per_bfd); + just_created = true; } per_objfile = dwarf2_objfile_data_key.emplace (objfile, objfile, per_bfd); + + if (just_created) + { + /* Try to fetch any potential dwz file early, while still on + the main thread. Also, be sure to do it just once per + BFD, to avoid races. */ + try + { + dwarf2_read_dwz_file (per_objfile); + } + catch (const gdb_exception_error &err) + { + warning (_("%s"), err.what ()); + } + } } return (!per_objfile->per_bfd->info.is_virtual @@ -3204,17 +3222,6 @@ dwarf2_initialize_objfile (struct objfile *objfile, dwarf_read_debug_printf ("called"); - /* Try to fetch any potential dwz file early, while still on the - main thread. */ - try - { - dwarf2_read_dwz_file (per_objfile); - } - catch (const gdb_exception_error &err) - { - warning (_("%s"), err.what ()); - } - /* If we're about to read full symbols, don't bother with the indices. In this case we also don't care if some other debug format is making psymtabs, because they are all about to be -- 2.43.0