From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id +eILADz6xGpT0wQAWB0awg (envelope-from ) for ; Tue, 06 Oct 2026 09:40:12 -0400 Authentication-Results: simark.ca; dkim=pass (2048-bit key; unprotected) header.d=polymtl.ca header.i=@polymtl.ca header.a=rsa-sha256 header.s=oct2025 header.b=n2ndaThd; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id DB0111E051; Tue, 06 Oct 2026 09:40:11 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_VALIDITY_CERTIFIED_BLOCKED, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [38.145.34.32]) (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 93C981E04E for ; Tue, 06 Oct 2026 09:40:09 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 62A0E4B920A8 for ; Tue, 6 Oct 2026 13:40:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 62A0E4B920A8 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=polymtl.ca header.i=@polymtl.ca header.a=rsa-sha256 header.s=oct2025 header.b=n2ndaThd Received: from smtp.polymtl.ca (smtp.polymtl.ca [132.207.4.11]) by sourceware.org (Postfix) with ESMTPS id BD56B4BB591E for ; Tue, 6 Oct 2026 13:39:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BD56B4BB591E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=polymtl.ca Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=polymtl.ca ARC-Filter: OpenARC Filter v1.0.0 sourceware.org BD56B4BB591E Authentication-Results: sourceware.org; arc=none smtp.remote-ip=132.207.4.11 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1791293983; cv=none; b=qGzHBNKXGdKkQz9vTKuJcKSuPgJqw//B/ijoo/5/xIAi4vVApMRIKRgo96grw4C53S/36VHFS6+4QDOWkck858xWuWPJiHJem3RcbqbAgEWW5mJ/yvedsa6axzu0lROzf8Bk7G9vYwwy45PBb+A+LM7zR+SvMIyEdyBL015Jqt0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1791293983; c=relaxed/simple; bh=4m28XPRMwkEITSxgN0lBbSsPZcKRqbu5QDlUoznHuvE=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=UphyGnDftvBPTRoiZE56tMnPyFZR79iQMsa6abAs4Ga22DK4KQNckyYxYf2AwqyfG8EF2u+tjwQwMEtnT76LLa7mfWINKwI09jOS9Q2JGgIuZ8zvbCvjVf1p66Gh1Uy3j95VBJbXuQmCsOKp8TyTM+APa+g4sEt1IaEVbxvlY3g= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=polymtl.ca header.i=@polymtl.ca header.a=rsa-sha256 header.s=oct2025 header.b=n2ndaThd DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BD56B4BB591E Received: from simark.ca (simark.ca [158.69.221.121]) (authenticated bits=0) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id 696Dda3p147968 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 6 Oct 2026 09:39:41 -0400 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp.polymtl.ca 696Dda3p147968 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=polymtl.ca; s=oct2025; t=1791293982; bh=aGAG/ifGK/NDMucYdMm6b2d0+Mdw5y6Tc74AJIEigCA=; h=Date:Subject:To:From:In-Reply-To:From; b=n2ndaThdtH11mwEUwoUb4S09CSpYHMecA7Ic4Mck3KYexVMDdYdOsuCy2fPUkvZV7 BsN1S9jEO24Bov3q40qQwkHHvD6tTekb5e4PtIIwWeoAqwhupHyzv8J95VLJBdbwEV MkO62WzQTcRhsjGum3022tXwpEp8zLpQUpunS8jCqmV/O9u960GAJ9vv3yYexoltBX 0G7FHFXjKtVfKp3WXaee30e5+YVMuyHa7nL3u44dEWFhHlKeQKyOQyJaaCrl5/nB8K Z1zk91yHjudZDXmpLQ1LnzYSxPT3GhjuSyclsNjF3ePQNlosIVehxCiRH5YbW/F5ok FKvJOM4rD7HuA== Received: by simark.ca (Postfix) id 651F01E04E; Tue, 06 Oct 2026 09:39:36 -0400 (EDT) Message-ID: <1309dff4-c7a7-42cd-84ae-24610a8a8284@polymtl.ca> Date: Tue, 6 Oct 2026 09:39:35 -0400 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 3/3] gdb/dwarf: fix crash when .gdb_index contains Rust legacy mangled names To: Andrew Burgess , gdb-patches@sourceware.org References: <20261005052602.1288766-1-simon.marchi@polymtl.ca> <20261005052602.1288766-3-simon.marchi@polymtl.ca> <8733ujum7p.fsf@redhat.com> Content-Language: fr From: Simon Marchi In-Reply-To: <8733ujum7p.fsf@redhat.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Poly-FromMTA: (simark.ca [158.69.221.121]) at Tue, 6 Oct 2026 13:39:36 +0000 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 On 10/6/26 7:01 AM, Andrew Burgess wrote: > simon.marchi@polymtl.ca writes: > >> From: Simon Marchi >> >> PR 34707 reports that loading the separate debug file of >> /usr/lib/libglycin-2.so from Arch Linux crashes GDB (when built with >> -D_GLIBCXX_DEBUG): >> >> $ ./gdb -q -nx --data-directory data-directory $(DEBUGINFOD_URLS=https://debuginfod.archlinux.org debuginfod-find debuginfo /usr/lib/libglycin-2.so) >> /usr/include/c++/16/string_view:291: ... Assertion 'this->_M_len > 0' failed. >> >> This catches a case of calling string_view::back() when the string_view is >> empty. >> >> The file in question contains a .gdb_index with some Rust symbol names that are >> mangled with the legacy mangling style. >> >> The legacy mangling style was the default one until the Rust 1.97 release >> in July 2026, so it's still very much in use, even though it's called >> "legacy". >> >> Source: https://blog.rust-lang.org/2026/07/09/Rust-1.97.0/ >> >> An example of a problematic symbol is: >> >> _ZN4core3ptr271drop_in_place$LT$core..iter..adapters..filter..Filter$LT$alloc..vec..into_iter..IntoIter$LT$core..net..socket_addr..SocketAddr$GT$$C$zbus..address..transport..tcp..Tcp..connect..$u7b$$u7b$closure$u7d$$u7d$..$u7b$$u7b$closure$u7d$$u7d$..$u7b$$u7b$closure$u7d$$u7d$$GT$$GT$17h57c03bb201e55682E >> >> Method mapped_gdb_index::build_name_components attempts to split the >> demangled fully-qualified symbol names into parts (it does not know in >> advance whether a symbol name is a mangled (linkage) name or a demangled >> one). >> >> Since this name does not match the C++ and Ada special cases, it falls into >> the DOT_STYLE else: >> >> components = split_name (name, split_style::DOT_STYLE); >> >> Because of the consecutive dots in the symbol name, `components` (an >> std::vector) contains some empty components. Some code >> later calls .back() on one of those empty string_views, which is invalid. >> >> It seems like it's only caught when gdb is built with _GLIBCXX_DEBUG / >> _GLIBCXX_ASSERTIONS, which apparently is the case for the official Arch >> Linux packages. >> >> I can't think of a pretty way to fix this. Since we don't have a flag that >> tells us whether a name is a linkage name or not, we can only make some >> educated guesses. >> >> This patch fixes the problem by looking for empty components in the vector. >> If there are, we assume that we are probably looking at a Rust legacy >> mangled symbol name, or at the very least not a fully qualified demangled >> Go (or whatever) symbol. The name is then treated like other names without >> separators (a single component with an unknown language). >> >> This is a regression introduced by commit 486bc5ac812f ("Rewrite the >> .gdb_index reader"). Before that, the reader only split names on "::" and >> "__". This is new in the GDB 18.1 release, so this patch would be a >> candidate for the gdb-18-branch. >> >> Add a gdb.dwarf2 test that builds a Rust CU with such a linkage name, adds >> an index using gdb-add-index, and verifies that GDB can load it and find >> the function. The test is done with both .gdb_index and .debug_names, >> although only the .gdb_index reader was affected. Like the original >> crash, the test only fails without the fix if GDB is built with libstdc++ >> assertions. >> >> One last thing, I don't know if it's expected for Rust mangled names to >> appear in the index. For C++, index-write.c does not write them: >> >> else if (entry->lang == language_cplus >> && (entry->flags & IS_LINKAGE) != 0) >> { >> /* GDB never put C++ linkage names into .gdb_index. The >> theory here is that a linkage name will normally be in >> the minimal symbols anyway, so including it in the index >> is usually redundant -- and the cases where it would not >> be redundant are rare and not worth supporting. */ >> continue; >> } >> >> Perhaps this is the real root of the problem: maybe those names should not >> have been in the index in the first place, if the same rationale applies to >> Rust. We could make that change, but even if we do, there are already >> indexes out there with those mangled names, so we have to handle them. > > I agree being defensive on the read side is a good idea. Even if these > names were not intended to be in the index, and GDB had never emitted > them, there's nothing to stop some other tool generating an index, and > that tool might emit these names. Conclusion: GDB should treat the > index as untrusted input. > > I actually started looking at making some fixes in this area -- not this > particular fix, but others in this area -- the fixes were easy, but > writing tests was taking some time. It's a work in progress. > > I agree that this could be merged to master and gdb-18-branch. > > Approved-By: Andrew Burgess Thanks a lot for the reviews. I will give Tom Tromey some time if he wants to look at this, since DWARF and Rust are some of his areas of expertise. Simon