Skip to content
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

[BUG] [Rust] all monomorphisation of a given function demangle to the same name #1754

Closed
robinmoussu opened this issue Dec 27, 2019 · 8 comments · Fixed by #6265
Closed

[BUG] [Rust] all monomorphisation of a given function demangle to the same name #1754

robinmoussu opened this issue Dec 27, 2019 · 8 comments · Fixed by #6265
Labels
bug lang-rust waiting Waiting for something

Comments

@robinmoussu
Copy link

Describe the bug

When a function is monomorphized in rust, the demangled name is the same for all demangled monomorphisation of that function. If someone wants to know witch monomorphised version is called where, it needs to look are the non-demangled assembly.

To Reproduce

If you look in the assembly, the function sum_print_and_skip can be found two times. It also looks like both caller and caller2 calls the same function (they don't). If you untick the demangle option, you can see that the full name are different for both monomorphisation.

Expected behavior

It should display the generic type in the demangled name, just like what is done in C++ with template: https://rust.godbolt.org/z/YahqGR

@robinmoussu
Copy link
Author

Note: as bandage, it could be possible to just include the hash in the demangled name, like what the --hash option of rustfilt does.

@AbrilRBS
Copy link
Member

For reference, this is code that handles Rust demangling https://github.com/mattgodbolt/compiler-explorer-tools/blob/master/rust/src/main.rs afaik

@robinmoussu
Copy link
Author

I tried to understand how the current rust-ABI and mangling works. I think that currently there is not enough information in the mangled name, and the RFC 2603 is trying to solve that (among other issue). If it's the case, the best we can do until that RFC is accepted is to display the hash.

I also noticed that when using the nightly compiler with the option -Zsymbol-mangling-version=v0, the demangled names are correct: https://godbolt.org/z/bbYIux

@eddyb
Copy link

eddyb commented Jan 16, 2020

@robinmoussu The RFC was accepted, and implemented, with -Zsymbol-mangling-version=v0 turning it on (although I regret not getting @michaelwoerister to replace v2 with v0 in the RFC title).

The new mangling will remain behind an unstable flag until we can finish upstreaming the demangler to GNU toolchain (which has taken me an unreasonable amount of time, despite the C implementation being ready since late January 2019 - it didn't help that this was my first contribution to a GNU project - most of the patches so far have tweaked the old demangler in several steps, to allow merging the two).

@eddyb
Copy link

eddyb commented Mar 13, 2020

I added the upstreaming effort status to rust-lang/rust#60705, and I'll post updates as comments on there, so you can subscribe to it if you want to track my progress.

@AbrilRBS
Copy link
Member

Thanks for keeping us updated on the issue, we really appreciate it :)

@partouf partouf added the waiting Waiting for something label Oct 1, 2020
@jeremy-rifkin
Copy link
Member

Is there anything we can do on our end to move this forward?

@narpfel
Copy link
Contributor

narpfel commented Mar 20, 2024

I tried to implement a solution to this in #6265: A checkbox that lets the user chose whether to show hashes or not.

mattgodbolt pushed a commit that referenced this issue Apr 2, 2024
…6265)

Demangled Rust identifiers under the `legacy` name mangling scheme rely
on a hash to disambiguate items with the same name, such as different
monomorphisations of the same function or different closures’
`call_once` methods.

In the `v0` mangling scheme, this is no longer a problem. However,
configuring the demangler to show hashes in `legacy` names will include
crate-id hashes in `v0` names, which are [mostly
unneeded](https://rust-lang.github.io/rfcs/2603-rust-symbol-name-mangling-v0.html#appendix-a---suggested-demangling).

This PR introduces a new checkbox *Options...* → *Verbose demangling*
that lets the user select if they want to include disambiguating hashes
in demangled identifiers.

This checkbox is only shown for compilers that support verbose
demangling, and deactivated when the *Demangle identifiers* checkbox is
unchecked.

Resolves #1754.
Resolves #6255.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug lang-rust waiting Waiting for something
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants