From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from omta40.uswest2.a.cloudfilter.net (omta40.uswest2.a.cloudfilter.net [35.89.44.39]) by sourceware.org (Postfix) with ESMTPS id ECBB43858D32 for ; Sun, 12 Nov 2023 20:25:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org ECBB43858D32 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 ECBB43858D32 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=35.89.44.39 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699820736; cv=none; b=soIbiYrZ7hCXBKU/8g6OaKoLVRPW/Ixsi7c02u/1ko9SBAP2YTCB2IKtHDiep6fkb92C5hLhYZlmHApesO5kRWmUul4YUwP9kE5P+bhxhm9DOwt+qeJuQ4YeLyRRbeDZChIwk5jrW9fTj6uiIEGKNBAf9m10RTwrkYNdIiTse9s= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699820736; c=relaxed/simple; bh=Pv7bHDObsP9QzvvVeiV6/NJUSiG7ox3xBUrXVJ6U4NM=; h=DKIM-Signature:From:Date:Subject:MIME-Version:Message-Id:To; b=jWIpCM5sKjo64PnUjjMDMgUb+RsBLBUnBp7nEOc+9PY9bBIvhXD/ikEPUxN+/IVLuzfaUh5OuBOEFWMJgeaTFrX4I4xC8hBJqBJMG4Yr3ia/gHNpgNCVGRoo6Hj2mgEqbc8iUyurQvpT1awag6BsEmJE8W9AYqDC5NBTb+UFEtA= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from eig-obgw-6004a.ext.cloudfilter.net ([10.0.30.197]) by cmsmtp with ESMTPS id 2EjZrulIJL9Ag2H1RrVwdO; Sun, 12 Nov 2023 20:25:33 +0000 Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTPS id 2H1PrRB8tRGmS2H1QrMpBq; Sun, 12 Nov 2023 20:25:32 +0000 X-Authority-Analysis: v=2.4 cv=efcuwpIH c=1 sm=1 tr=0 ts=655134bc a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=OWjo9vPv0XrRhIrVQ50Ab3nP57M=:19 a=dLZJa+xiwSxG16/P+YVxDGlgEgI=:19 a=IkcTkHD0fZMA:10 a=BNY50KLci1gA:10 a=Qbun_eYptAEA:10 a=4gSrmJ1YH20WjDTdAmEA:9 a=QEXdDO2ut3YA:10 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=To:In-Reply-To:References:Message-Id:Content-Transfer-Encoding: Content-Type:MIME-Version:Subject:Date:From:Sender:Reply-To:Cc:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=iDwOoAXFt1Uovtbpj9QmYdNGYaaLVwrPaws4cI0rOzI=; b=V+ZMOyYhXmkT0uqtbSrkYIG+Ox a/p54eYhdrtSqoa9U7ta22BlDt85YlmE24gLsRqNLoZIb9mv3mh9nTTbc/g8RuXY0hRDu2taqr5kj mEC3oPVq6cO3ht+NbImrhifDh; Received: from 97-122-77-73.hlrn.qwest.net ([97.122.77.73]:34540 helo=[192.168.0.21]) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96.2) (envelope-from ) id 1r2H1P-000cUU-2C for gdb-patches@sourceware.org; Sun, 12 Nov 2023 13:25:31 -0700 From: Tom Tromey Date: Sun, 12 Nov 2023 13:25:38 -0700 Subject: [PATCH v2 01/18] Don't use objfile::intern in DWO code MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20231112-t-bg-dwarf-reading-v2-1-70fb170012ba@tromey.com> References: <20231112-t-bg-dwarf-reading-v2-0-70fb170012ba@tromey.com> In-Reply-To: <20231112-t-bg-dwarf-reading-v2-0-70fb170012ba@tromey.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.4 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.77.73 X-Source-L: No X-Exim-ID: 1r2H1P-000cUU-2C X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-122-77-73.hlrn.qwest.net ([192.168.0.21]) [97.122.77.73]:34540 X-Source-Auth: tom+tromey.com X-Email-Count: 2 X-Org: HG=bhshared;ORG=bluehost; X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-CMAE-Envelope: MS4xfD5NJkmyw225G1XDs8kkB67pA4qzPv8wWi3gCUWJ3axwpxnJ9zaijyuZqmx/Fc2drcbaRPWSVYmTLKRaFGz7dIl6SqYa3T6sbeb1zWkMlnsM0rtWxSeu zCsIsEaqvlromGJt+oKCX9FbE3cjQ7MCOcaWqZjZ/dkjbPRGW2zhN+Uk+IwdZ4sdVMbSiVXbYtAz1VdMFcZjEHnV7ET5FAFuwck= X-Spam-Status: No, score=-3024.4 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 List-Id: The DWO code in the DWARF reader currently uses objfile::intern. This accesses a shared data structure and so would be racy when used from multiple threads. I don't believe this can happen right now, but background reading could provoke this, and in any case it's better to avoid this, just to be sure. This patch changes this code to just use a std::string. A new type is introduced to do hash table lookups, to avoid unnecessary copies. --- gdb/dwarf2/read.c | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 7a3b9c68279..f88e5023734 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -353,7 +353,7 @@ struct dwo_file For virtual DWO files the name is constructed from the section offsets of abbrev,line,loc,str_offsets so that we combine virtual DWO files from related CU+TUs. */ - const char *dwo_name = nullptr; + std::string dwo_name; /* The DW_AT_comp_dir attribute. */ const char *comp_dir = nullptr; @@ -7728,19 +7728,30 @@ hash_dwo_file (const void *item) const struct dwo_file *dwo_file = (const struct dwo_file *) item; hashval_t hash; - hash = htab_hash_string (dwo_file->dwo_name); + hash = htab_hash_string (dwo_file->dwo_name.c_str ()); if (dwo_file->comp_dir != NULL) hash += htab_hash_string (dwo_file->comp_dir); return hash; } +/* This is used when looking up entries in the DWO hash table. */ + +struct dwo_file_search +{ + /* Name of the DWO to look for. */ + const char *dwo_name; + /* Compilation directory to look for. */ + const char *comp_dir; +}; + static int eq_dwo_file (const void *item_lhs, const void *item_rhs) { const struct dwo_file *lhs = (const struct dwo_file *) item_lhs; - const struct dwo_file *rhs = (const struct dwo_file *) item_rhs; + const struct dwo_file_search *rhs + = (const struct dwo_file_search *) item_rhs; - if (strcmp (lhs->dwo_name, rhs->dwo_name) != 0) + if (lhs->dwo_name != rhs->dwo_name) return 0; if (lhs->comp_dir == NULL || rhs->comp_dir == NULL) return lhs->comp_dir == rhs->comp_dir; @@ -7766,7 +7777,7 @@ lookup_dwo_file_slot (dwarf2_per_objfile *per_objfile, const char *dwo_name, const char *comp_dir) { - struct dwo_file find_entry; + struct dwo_file_search find_entry; void **slot; if (per_objfile->per_bfd->dwo_files == NULL) @@ -7834,7 +7845,7 @@ create_dwo_cu_reader (const struct die_reader_specs *reader, { complaint (_("Dwarf Error: debug entry at offset %s is missing" " its dwo_id [in module %s]"), - sect_offset_str (sect_off), dwo_file->dwo_name); + sect_offset_str (sect_off), dwo_file->dwo_name.c_str ()); return; } @@ -8485,7 +8496,7 @@ create_dwo_unit_in_dwp_v1 (dwarf2_per_objfile *per_objfile, virtual_dwo_name.c_str ()); dwo_file = new struct dwo_file; - dwo_file->dwo_name = per_objfile->objfile->intern (virtual_dwo_name); + dwo_file->dwo_name = std::move (virtual_dwo_name); dwo_file->comp_dir = comp_dir; dwo_file->sections.abbrev = sections.abbrev; dwo_file->sections.line = sections.line; @@ -8670,7 +8681,7 @@ create_dwo_unit_in_dwp_v2 (dwarf2_per_objfile *per_objfile, virtual_dwo_name.c_str ()); dwo_file = new struct dwo_file; - dwo_file->dwo_name = per_objfile->objfile->intern (virtual_dwo_name); + dwo_file->dwo_name = std::move (virtual_dwo_name); dwo_file->comp_dir = comp_dir; dwo_file->sections.abbrev = create_dwp_v2_or_v5_section (per_objfile, &dwp_file->sections.abbrev, @@ -8842,7 +8853,7 @@ create_dwo_unit_in_dwp_v5 (dwarf2_per_objfile *per_objfile, virtual_dwo_name.c_str ()); dwo_file = new struct dwo_file; - dwo_file->dwo_name = per_objfile->objfile->intern (virtual_dwo_name); + dwo_file->dwo_name = std::move (virtual_dwo_name); dwo_file->comp_dir = comp_dir; dwo_file->sections.abbrev = create_dwp_v2_or_v5_section (per_objfile, @@ -17615,7 +17626,7 @@ read_dwo_str_index (const struct die_reader_specs *reader, ULONGEST str_index) least has a limit. */ complaint (_("Section .debug_str_offsets in %s has unsupported" " version %d, use empty string."), - reader->dwo_file->dwo_name, version); + reader->dwo_file->dwo_name.c_str (), version); return ""; } -- 2.41.0