-
Notifications
You must be signed in to change notification settings - Fork 223
Demangle functions/type name in LLVM IR and ASM #15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
As I understand it, demangling is tough in general. Do you have any suggestions on how this could be accomplished? I'd assume the "best" solution would be to update Rust or LLVM itself to offer this functionality, otherwise anything we do would be unlikely to stay up to date. |
This would be the best solution, yes. Shelling out to |
@stepancheg Thank you so much! That's a wonderful solution that seems more reusable for lots of people! |
@shepmaster Welcome! I'm now thinking how to demangle symbols in assembly (not LLVM IR) output. Cannot think of anything better than postprocess generated assembly text. |
`--emit=llvm-ir` looks like this now: ``` ; <alloc::vec::Vec<T> as core::ops::index::IndexMut<core::ops::range::RangeFull>>::index_mut ; Function Attrs: inlinehint uwtable define internal { i8*, i64 } @"_ZN106_$LT$alloc..vec..Vec$LT$T$GT$$u20$as$u20$core..ops..index..IndexMut$LT$core..ops..range..RangeFull$GT$$GT$9index_mut17h7f7b576609f30262E"(%"alloc::vec::Vec<u8>"* dereferenceable(24)) unnamed_addr #0 { start: ... ``` cc rust-lang/rust-playground#15
When writing LLVM IR output demangled fn name in comments `--emit=llvm-ir` looks like this now: ``` ; <alloc::vec::Vec<T> as core::ops::index::IndexMut<core::ops::range::RangeFull>>::index_mut ; Function Attrs: inlinehint uwtable define internal { i8*, i64 } @"_ZN106_$LT$alloc..vec..Vec$LT$T$GT$$u20$as$u20$core..ops..index..IndexMut$LT$core..ops..range..RangeFull$GT$$GT$9index_mut17h7f7b576609f30262E"(%"alloc::vec::Vec<u8>"* dereferenceable(24)) unnamed_addr #0 { start: ... ``` cc rust-lang/rust-playground#15
With this patch `--emit=asm` looks like this: ``` ; <alloc::vec::Vec<T> as core::ops::index::IndexMut<core::ops::range::RangeFull>>::index_mut __ZN106_$LT$alloc..vec..Vec$LT$T$GT$$u20$as$u20$core..ops..index..IndexMut$LT$core..ops..range..RangeFull$GT$$GT$9index_mut17h8ecb05aacf724133E: ... Lcfi2: .cfi_def_cfa_register %rbp subq $16, %rsp ; <alloc::vec::Vec<T> as core::ops::deref::DerefMut>::deref_mut callq __ZN71_$LT$alloc..vec..Vec$LT$T$GT$$u20$as$u20$core..ops..deref..DerefMut$GT$9deref_mut17heae350c695265f00E ``` Unlike writing LLVM IR, it is hard to plug into LLVM to output comments without duplicating large amount of LLVM code (because LLVM doesn't have hooks, or at least I haven't found them). So it is implemented by post-processing assembly text. cc rust-lang/rust-playground#15 cc rust-lang#42971 r? nagisa
An option to demangle names from the LLVM IR/ASM output would be nice, and make it more readable.
The text was updated successfully, but these errors were encountered: