From patchwork Tue Jan 9 19:51:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 83682 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 902563857BAD for ; Tue, 9 Jan 2024 19:52:17 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from omta38.uswest2.a.cloudfilter.net (omta38.uswest2.a.cloudfilter.net [35.89.44.37]) by sourceware.org (Postfix) with ESMTPS id BBE1E3858C66 for ; Tue, 9 Jan 2024 19:51:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BBE1E3858C66 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 BBE1E3858C66 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=1704829914; cv=none; b=cWrBFZKvYAXMmtNEWWfTactnVlP5d1gwAA/5mRnnChYdMsGmzViwfIdfZ8GZB1FUmGjycVGOsjY1tUvn5h3hw8ln/ZB9eNNw+P5xlYHR6UQsjbL4ShPUW/BtLkIT7JWvnq6wyKs1j5RvsZaG5JrRVnHjd/ABG3TiSQxK3N4Z7A8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704829914; c=relaxed/simple; bh=dcH0aLJqGZtPCm0PxlZMFEw5fy7kqXaIUmj51MgEFJ8=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=hPIp1KLnmAhDdFexVUrArhF6umH+cmHUUk9yedr5tF0nX034PCg/PGcFz8bTy9A8oeu9LBPsX1UAt4yhaqVEqq2z/8VRSQ7sC6u4VZmLGJVSed5AZkZduE8PBn94bwIAk14QoNY0xTaRfA2And994ewYJXZbXy4UrWJUIpYSxQU= 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 NDfBrsKnfoMN9NI8dr2X9B; Tue, 09 Jan 2024 19:51:51 +0000 Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTPS id NI8drViGayxR5NI8drUNcV; Tue, 09 Jan 2024 19:51:51 +0000 X-Authority-Analysis: v=2.4 cv=JYOvEGGV c=1 sm=1 tr=0 ts=659da3d7 a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=OWjo9vPv0XrRhIrVQ50Ab3nP57M=:19 a=dLZJa+xiwSxG16/P+YVxDGlgEgI=:19 a=dEuoMetlWLkA:10 a=Qbun_eYptAEA:10 a=tPfos8ISzE28W29P3iwA:9 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=ODeXHpC2uH3djAX8Xhu38u/nH2+ELN5PAN0/a/N/UZg=; b=mg5qyN7d8sWSluX1lTh6piwWU8 wvM8JbL2QL4TgXxoik3NratyFfXsr5+6mUhkIeyvN3MgBMJ5dZ6FZv4OIwWaDy1Mu0CDvw8piVi78 tHpbx6XcRcRf4kVlFHeWeI+tz; Received: from 97-122-68-157.hlrn.qwest.net ([97.122.68.157]:59614 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 1rNI8c-002a8p-37; Tue, 09 Jan 2024 12:51:51 -0700 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH] Fix ASAN failure in DWO code Date: Tue, 9 Jan 2024 12:51:43 -0700 Message-ID: <20240109195143.291756-1-tom@tromey.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 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: 1rNI8c-002a8p-37 X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-122-68-157.hlrn.qwest.net (localhost.localdomain) [97.122.68.157]:59614 X-Source-Auth: tom+tromey.com X-Email-Count: 16 X-Org: HG=bhshared;ORG=bluehost; X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-CMAE-Envelope: MS4xfMRG/MRxUB5hzwNmMj+aoSeTGvL7uELy/ZuNCBJsLXe/Hw9jJJnPZwlb5yzQMvsey0WBlVf3MPv9FXfrF7XJhQQXDh63MwDOJSjNGTvMEwQCJ9qjp+fd TVtZlVftrTkJMZUN+bfUKidlD9B4+yMdXiB1fpXWY1p52RuDI9TeuUOrBpBCgcruOv7ke1MU4wKBr+CdytpugBU+LfLGmMcGo/U= X-Spam-Status: No, score=-3022.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 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+patchwork=sourceware.org@sourceware.org Simon pointed out that my recent change to the DWO code caused a failure in ASAN testing. The bug here was I updated the code to use a different search type in the hash table; but then did not change the search code to use htab_find_slot_with_hash. Note that this bug would not be possible with my type-safe hash table series, hint, hint. --- gdb/dwarf2/read.c | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index e055371dc6a..ca4dda5aea1 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -7783,16 +7783,24 @@ read_type_unit_scope (struct die_info *die, struct dwarf2_cu *cu) and DWP files (a file with the DWOs packaged up into one file), we treat DWP files as having a collection of virtual DWO files. */ +/* A helper function to hash two file names. This is a separate + function because the hash table uses a search with a different + type. The second file may be NULL. */ + +static hashval_t +hash_two_files (const char *one, const char *two) +{ + hashval_t hash = htab_hash_string (one); + if (two != nullptr) + hash += htab_hash_string (two); + return hash; +} + static hashval_t 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.c_str ()); - if (dwo_file->comp_dir != NULL) - hash += htab_hash_string (dwo_file->comp_dir); - return hash; + return hash_two_files (dwo_file->dwo_name.c_str (), dwo_file->comp_dir); } /* This is used when looking up entries in the DWO hash table. */ @@ -7803,6 +7811,12 @@ struct dwo_file_search const char *dwo_name; /* Compilation directory to look for. */ const char *comp_dir; + + /* Return a hash value compatible with the table. */ + hashval_t hash () const + { + return hash_two_files (dwo_name, comp_dir); + } }; static int @@ -7846,8 +7860,9 @@ lookup_dwo_file_slot (dwarf2_per_objfile *per_objfile, find_entry.dwo_name = dwo_name; find_entry.comp_dir = comp_dir; - slot = htab_find_slot (per_objfile->per_bfd->dwo_files.get (), &find_entry, - INSERT); + slot = htab_find_slot_with_hash (per_objfile->per_bfd->dwo_files.get (), + &find_entry, find_entry.hash (), + INSERT); return slot; }