Skip to content

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

Open
Luthaf opened this issue Jul 5, 2016 · 4 comments
Open

Demangle functions/type name in LLVM IR and ASM #15

Luthaf opened this issue Jul 5, 2016 · 4 comments
Labels
enhancement Something new the playground could do

Comments

@Luthaf
Copy link

Luthaf commented Jul 5, 2016

An option to demangle names from the LLVM IR/ASM output would be nice, and make it more readable.

@carols10cents carols10cents added the enhancement Something new the playground could do label Jul 5, 2016
@shepmaster
Copy link
Member

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.

@Luthaf
Copy link
Author

Luthaf commented Jul 5, 2016

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 c++filt works for some identifiers too, that is what I use sometimes.

@shepmaster
Copy link
Member

@stepancheg Thank you so much! That's a wonderful solution that seems more reusable for lots of people!

@stepancheg
Copy link

@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.

stepancheg added a commit to stepancheg/rust that referenced this issue Jul 1, 2017
`--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
bors added a commit to rust-lang/rust that referenced this issue Jul 1, 2017
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
stepancheg added a commit to stepancheg/rust that referenced this issue Jul 1, 2017
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Something new the playground could do
Projects
None yet
Development

No branches or pull requests

4 participants