Skip to content

Commit 48646c6

Browse files
committed
Demangle ThinLTO-generated symbols as well
1 parent 6c94e7f commit 48646c6

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

src/lib.rs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,25 @@ pub struct Demangle<'a> {
8080
// Note that this demangler isn't quite as fancy as it could be. We have lots
8181
// of other information in our symbols like hashes, version, type information,
8282
// etc. Additionally, this doesn't handle glue symbols at all.
83-
pub fn demangle(s: &str) -> Demangle {
83+
pub fn demangle(mut s: &str) -> Demangle {
84+
// During ThinLTO LLVM may import and rename internal symbols, so strip out
85+
// those endings first as they're on of the last manglings applied to symbol
86+
// names.
87+
let llvm = ".llvm.";
88+
if let Some(i) = s.find(llvm) {
89+
let candidate = &s[i + llvm.len()..];
90+
let all_hex = candidate.chars().all(|c| {
91+
match c {
92+
'A' ... 'F' | '0' ... '9' => true,
93+
_ => false,
94+
}
95+
});
96+
97+
if all_hex {
98+
s = &s[..i];
99+
}
100+
}
101+
84102
// First validate the symbol. If it doesn't look like anything we're
85103
// expecting, we just print it literally. Note that we must handle non-rust
86104
// symbols because we could have any function in the backtrace.
@@ -358,4 +376,11 @@ mod tests {
358376
// Not a valid hash, has a non-hex-digit.
359377
t_nohash!("_ZN3foo17hg5af221e174051e9E", "foo::hg5af221e174051e9");
360378
}
379+
380+
#[test]
381+
fn demangle_thinlto() {
382+
// One element, no hash.
383+
t!("_ZN3fooE.llvm.9D1C9369", "foo");
384+
t_nohash!("_ZN9backtrace3foo17hbb467fcdaea5d79bE.llvm.A5310EB9", "backtrace::foo");
385+
}
361386
}

0 commit comments

Comments
 (0)