From bfb3547bb10d190d2d8e0358a0ab69fe7e2fdc46 Mon Sep 17 00:00:00 2001 From: Sludge Date: Tue, 26 Aug 2025 14:36:39 +0200 Subject: [PATCH] Discard `$` suffixes without invalidation the demangling --- src/lib.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index cafec2f..b113813 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -131,6 +131,11 @@ pub fn demangle(mut s: &str) -> Demangle { if !suffix.is_empty() { if suffix.starts_with('.') && is_symbol_like(suffix) { // Keep the suffix. + } else if suffix.starts_with('$') { + // Some platforms add $-delimited suffixes (eg. `$tlv$init` for TLS on Linux). + // Discard those suffixes, as suggested by the specification: + // https://doc.rust-lang.org/rustc/symbol-mangling/v0.html#vendor-specific-suffix + suffix = ""; } else { // Reset the suffix and invalidate the demangling. suffix = ""; @@ -491,6 +496,14 @@ mod tests { ); } + #[test] + fn demangle_dollar_suffix() { + t!( + "_RNvNvNvCs7qp2U7fqm6G_7mycrate7EXAMPLE7___getit5___KEY$tlv$init", + "mycrate[567e63b0a19c5b38]::EXAMPLE::__getit::__KEY" + ); + } + #[test] fn demangle_llvm_ir_branch_labels() { t!("_ZN4core5slice77_$LT$impl$u20$core..ops..index..IndexMut$LT$I$GT$$u20$for$u20$$u5b$T$u5d$$GT$9index_mut17haf9727c2edfbc47bE.exit.i.i", "core::slice:: for [T]>::index_mut::haf9727c2edfbc47b.exit.i.i");