From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id gL06GdXM7WeujSQAWB0awg (envelope-from ) for ; Wed, 02 Apr 2025 19:48:37 -0400 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=S0C1uId6; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 62E8B1E0C3; Wed, 2 Apr 2025 19:48:37 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-5.1 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_INVALID,DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=4.0.1 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 E153C1E0C0 for ; Wed, 2 Apr 2025 19:48:36 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8EEFE385AC3A for ; Wed, 2 Apr 2025 23:48:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8EEFE385AC3A Authentication-Results: sourceware.org; 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=S0C1uId6 Received: from omta34.uswest2.a.cloudfilter.net (omta34.uswest2.a.cloudfilter.net [35.89.44.33]) by sourceware.org (Postfix) with ESMTPS id C22F43857B8C for ; Wed, 2 Apr 2025 23:45:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C22F43857B8C 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 C22F43857B8C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=35.89.44.33 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1743637513; cv=none; b=bTSgDqVYurVAqMMK9u2gouw+Rx5xoUQ+4cuqtjylsVUZElkEDlFaDniJ0GQxBI8zumH8C6c/u3Z7yZAKwzxGONG/m2GmpGfxjZyPYs4FzJ9bkcCVnlFX7LP5fhFNyXWYvjMCO1iNO9fVQB9w3OJPVkgW79NN5WWqFTdM3R9wSMg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1743637513; c=relaxed/simple; bh=wNf5LSQyMupSMIgoi3HWWsxfFYmvjjIp+KWdMLqwaH0=; h=DKIM-Signature:From:Date:Subject:MIME-Version:Message-Id:To; b=yBLWOhrheJblNXq7KVLHqiVMarAOq1o+gKbZs8f5z2VVF7C1OGP6KajV86Ff/a6ByDm0uaKljngYhK7VgVnLaUOWY7Oj36mDs8L3+AGSTz0V96LxKi+qy1PpGPHuiNyDuLiAGFCHoo2Cq4/tWBmFh6et369+9hC+mIt5CoNgK0U= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C22F43857B8C Received: from eig-obgw-5008a.ext.cloudfilter.net ([10.0.29.246]) by cmsmtp with ESMTPS id 03mmuJqPAWuHK07lguzjxJ; Wed, 02 Apr 2025 23:45:13 +0000 Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTPS id 07lfuMBnwoAm007lguOb9a; Wed, 02 Apr 2025 23:45:12 +0000 X-Authority-Analysis: v=2.4 cv=A/FqPbWG c=1 sm=1 tr=0 ts=67edcc08 a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=IkcTkHD0fZMA:10 a=XR8D0OoHHMoA:10 a=ItBw4LHWJt0A:10 a=NFM902X7C-yTB1EVzFYA:9 a=QEXdDO2ut3YA:10 a=6Ogn3jAGHLSNbaov7Orx:22 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Cc:To:In-Reply-To:References:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From:Sender: Reply-To: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=yyy33SAFoLy9wvyKfD+Z6fxpllOfgXjkfdATwAVf/pc=; b=S0C1uId6rETdAigLy9zjV+6AqG FG9CrfHHGa98q4UfY94fQIJcc38E2Rs2RE5qfCJ9fuqqFEf8SOkJpa6npAegTwJQ8UkpI7lJ+oTa5 oCdiFOKrOSJDi0epV1LNtEodn; Received: from 97-122-123-18.hlrn.qwest.net ([97.122.123.18]:56394 helo=prentzel.local) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.1) (envelope-from ) id 1u07lf-000000014hd-2W1K; Wed, 02 Apr 2025 17:45:11 -0600 From: Tom Tromey Date: Wed, 02 Apr 2025 17:45:02 -0600 Subject: [PATCH v2 03/28] Emit some type declarations in .gdb_index MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20250402-search-in-psyms-v2-3-ea91704487cb@tromey.com> References: <20250402-search-in-psyms-v2-0-ea91704487cb@tromey.com> In-Reply-To: <20250402-search-in-psyms-v2-0-ea91704487cb@tromey.com> To: gdb-patches@sourceware.org Cc: Tom Tromey X-Mailer: b4 0.14.2 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.123.18 X-Source-L: No X-Exim-ID: 1u07lf-000000014hd-2W1K X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-122-123-18.hlrn.qwest.net (prentzel.local) [97.122.123.18]:56394 X-Source-Auth: tom+tromey.com X-Email-Count: 4 X-Org: HG=bhshared;ORG=bluehost; X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-CMAE-Envelope: MS4xfM0QmhF+EJGcPWx662Jfb+pFGhX87OZgFRAd4Ze+Tekj9+lmkRS8CteJgl44cvidsPLKn8myYKh/tyAWQSQwydWGE6bNsoXWhw66zU7e2S3t6qjfS0ZU YTq9ZgViao+u/dE2A45GH70/4i1ZguVZj48rrOLfJIxy5OOLIt6TEBXZZw8CThSBmThDOabbOJCMS6Mew8VqA02RsCtTmt2h2Pc= 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 If you run struct-decl.exp with the .gdb_index board, you will see that "the_type" is not emitted in the index. This would cause a failure in this series. The fix is to ensure that certain necessary type declarations are emitted. However, a naive fix here will regress stub-array-size.exp, where a type declaration and a type definition are both seen -- but the declaration is seen first and causes a failure. This is handled by adding some code (including a mild hack) to filter out type declarations when a corresponding type definition is seen. --- gdb/dwarf2/index-write.c | 79 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 74 insertions(+), 5 deletions(-) diff --git a/gdb/dwarf2/index-write.c b/gdb/dwarf2/index-write.c index da1f6cd1e0869620a99959639718a554882bab2c..389fcaa727ce15706a735ce82c047374fbc57d2b 100644 --- a/gdb/dwarf2/index-write.c +++ b/gdb/dwarf2/index-write.c @@ -55,7 +55,7 @@ #define DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE(cu_index, value) \ do { \ gdb_assert ((value) >= GDB_INDEX_SYMBOL_KIND_TYPE \ - && (value) <= GDB_INDEX_SYMBOL_KIND_OTHER); \ + && (value) <= GDB_INDEX_SYMBOL_KIND_UNUSED5); \ GDB_INDEX_SYMBOL_KIND_SET_VALUE((cu_index), (value)); \ } while (0) @@ -422,10 +422,53 @@ symtab_index_entry::minimize () if (name == nullptr || cu_indices.empty ()) return; - std::sort (cu_indices.begin (), cu_indices.end ()); + /* We sort the indexes in a funny way: GDB_INDEX_SYMBOL_KIND_UNUSED5 + is always sorted last; then otherwise we sort by numeric value. + This ensures that we prefer the definition when both a definition + and a declaration (stub type) are seen. */ + std::sort (cu_indices.begin (), cu_indices.end (), + [] (offset_type vala, offset_type valb) + { + gdb_index_symbol_kind kinda + = GDB_INDEX_SYMBOL_KIND_VALUE (vala); + gdb_index_symbol_kind kindb + = GDB_INDEX_SYMBOL_KIND_VALUE (valb); + if (kinda == GDB_INDEX_SYMBOL_KIND_UNUSED5) + { + if (kindb == GDB_INDEX_SYMBOL_KIND_UNUSED5) + return vala < valb; + /* Declaration sorts last. */ + return false; + } + else if (kindb == GDB_INDEX_SYMBOL_KIND_UNUSED5) + { + /* Declaration sorts last. */ + return true; + } + return vala < valb; + }); auto from = std::unique (cu_indices.begin (), cu_indices.end ()); cu_indices.erase (from, cu_indices.end ()); + /* Rewrite GDB_INDEX_SYMBOL_KIND_UNUSED5. This ensures that a type + declaration will be deleted by the subsequent squashing step, if + warranted. */ + for (auto &val : cu_indices) + { + gdb_index_symbol_kind kind = GDB_INDEX_SYMBOL_KIND_VALUE (val); + if (kind != GDB_INDEX_SYMBOL_KIND_UNUSED5) + continue; + + offset_type newval = 0; + DW2_GDB_INDEX_CU_SET_VALUE (newval, GDB_INDEX_CU_VALUE (val)); + DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE + (newval, GDB_INDEX_SYMBOL_STATIC_VALUE (val)); + DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE (newval, + GDB_INDEX_SYMBOL_KIND_TYPE); + + val = newval; + } + /* We don't want to enter a type more than once, so remove any such duplicates from the list as well. When doing this, we want to keep the entry from the first CU -- but this is @@ -1212,6 +1255,22 @@ write_cooked_index (cooked_index *table, const cu_index_map &cu_index_htab, struct mapped_symtab *symtab) { + /* A type declaration that is used as a (non-trivial) parent entry + must be written out. */ + gdb::unordered_set required_entries; + for (const cooked_index_entry *entry : table->all_entries ()) + { + if ((entry->flags & IS_TYPE_DECLARATION) == 0 + && entry->get_parent () != nullptr) + { + for (const cooked_index_entry *parent = entry->get_parent (); + parent != nullptr; + parent = parent->get_parent ()) + if ((parent->flags & IS_TYPE_DECLARATION) != 0) + required_entries.insert (parent); + } + } + for (const cooked_index_entry *entry : table->all_entries ()) { const auto it = cu_index_htab.find (entry->per_cu); @@ -1239,8 +1298,9 @@ write_cooked_index (cooked_index *table, } else if ((entry->flags & IS_TYPE_DECLARATION) != 0) { - /* Don't add type declarations to the index. */ - continue; + /* Don't add most type declarations to the index. */ + if (!required_entries.contains (entry)) + continue; } gdb_index_symbol_kind kind; @@ -1252,7 +1312,16 @@ write_cooked_index (cooked_index *table, || entry->tag == DW_TAG_enumerator) kind = GDB_INDEX_SYMBOL_KIND_VARIABLE; else if (tag_is_type (entry->tag)) - kind = GDB_INDEX_SYMBOL_KIND_TYPE; + { + /* If we added a type declaration, we want to note this + fact for later, because we don't want a type declaration + to cause the real definition to be omitted from the + index. GDB_INDEX_SYMBOL_KIND_UNUSED5 is used here, but + rewritten later before the index is written. */ + kind = ((entry->flags & IS_TYPE_DECLARATION) == 0 + ? GDB_INDEX_SYMBOL_KIND_TYPE + : GDB_INDEX_SYMBOL_KIND_UNUSED5); + } else kind = GDB_INDEX_SYMBOL_KIND_OTHER; -- 2.46.1