From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from omta038.useast.a.cloudfilter.net (omta038.useast.a.cloudfilter.net [44.202.169.37]) by sourceware.org (Postfix) with ESMTPS id BC53A3857837 for ; Thu, 23 Nov 2023 05:32:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BC53A3857837 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 BC53A3857837 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=44.202.169.37 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700717526; cv=none; b=ULnG+5r/oSiAcfUpETf/ZPlIcMBWmduOktGPpZ3WlxPkh6DoDvHBehTW6GLRg8DMlLXAJNxu+hKnRxdyItqBGVXcvqN7BWhNWLSxKUV3PAiTTMbtzx1nV9GqzAxwjLsKBQ8prUGzsdFl543i21GKlu0m8P52+Y+CFH6FLgSZ8QM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700717526; c=relaxed/simple; bh=guA6hLXzG9+aZ4Nkn92n1qLiBg1kcaz37W+3SK9KOc0=; h=DKIM-Signature:From:Date:Subject:MIME-Version:Message-Id:To; b=JhoMQ9MMwn2uOZ2ceAHn8va4vwkvoRw+Nz2T6KNX4gRi5cLejqOdNAcrjqZ2Aod5K6BCBfTJhwD9XSZOCLGq5koPYvZc784gsu2/RJVYq7CNRMgu1Ep0Y/puf5RGRaPJ1zNu9DySvGocCFczBH2PevxkqMr+rsI4WWbE9DQHJQI= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from eig-obgw-5008a.ext.cloudfilter.net ([10.0.29.246]) by cmsmtp with ESMTPS id 61y4r0DGlWcCI62JnrvNX9; Thu, 23 Nov 2023 05:32:03 +0000 Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTPS id 62JmrjLw7kUbt62JmrvCcs; Thu, 23 Nov 2023 05:32:02 +0000 X-Authority-Analysis: v=2.4 cv=WpU4jPTv c=1 sm=1 tr=0 ts=655ee3d2 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=zv4jUeLQYibZvt2Apdig2OGVX6CjB7+rYL7RgJjQ1/k=; b=XdA4YUf5ekOJ0WeLkKQmbSh2Do /pAqhQ6eoG13NYHu3qrxYpM118frFx1I2AcfGrqUsVws8H2DwKbObVU6JidUbCppfVl/fpSAnv3oN CHeM9fp3gmCpZaxiWLSR3lqKs; Received: from 97-122-77-73.hlrn.qwest.net ([97.122.77.73]:46354 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 1r62Jm-003TGR-0P for gdb-patches@sourceware.org; Wed, 22 Nov 2023 22:32:02 -0700 From: Tom Tromey Date: Wed, 22 Nov 2023 22:32:10 -0700 Subject: [PATCH v3 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: <20231122-t-bg-dwarf-reading-v3-1-fc3180de63c4@tromey.com> References: <20231122-t-bg-dwarf-reading-v3-0-fc3180de63c4@tromey.com> In-Reply-To: <20231122-t-bg-dwarf-reading-v3-0-fc3180de63c4@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: 1r62Jm-003TGR-0P 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]:46354 X-Source-Auth: tom+tromey.com X-Email-Count: 3 X-Org: HG=bhshared;ORG=bluehost; X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-CMAE-Envelope: MS4xfLMiMR2zzEuraRtYE8klWmDrjo0kMQPWM4MYruFlfYLR7vQELDumAs7ml3UFH1AzfDv0QE/THLecrs4zV/+HvrfZBi17Psked9rn5lYkyb/SfUchrCoS y0mRwGucXFH7VmbNlKxuIwygA54X1zDWBIGnfVsstJl1h9KVWW1o+eDsWsjSQ+wSIgPwYLABS2oXLk4nd7tHGE76jKy5GLSE444= X-Spam-Status: No, score=-3024.0 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,GIT_PATCH_0,JMQ_SPF_NEUTRAL,RCVD_IN_DNSWL_NONE,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 9f3297a2d4e..5e9311f1437 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; @@ -7723,19 +7723,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; @@ -7761,7 +7772,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) @@ -7829,7 +7840,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; } @@ -8480,7 +8491,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; @@ -8665,7 +8676,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, @@ -8837,7 +8848,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, @@ -17561,7 +17572,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