@@ -80,7 +80,25 @@ pub struct Demangle<'a> {
80
80
// Note that this demangler isn't quite as fancy as it could be. We have lots
81
81
// of other information in our symbols like hashes, version, type information,
82
82
// 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
+
84
102
// First validate the symbol. If it doesn't look like anything we're
85
103
// expecting, we just print it literally. Note that we must handle non-rust
86
104
// symbols because we could have any function in the backtrace.
@@ -358,4 +376,11 @@ mod tests {
358
376
// Not a valid hash, has a non-hex-digit.
359
377
t_nohash ! ( "_ZN3foo17hg5af221e174051e9E" , "foo::hg5af221e174051e9" ) ;
360
378
}
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
+ }
361
386
}
0 commit comments