-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Tracking issue for RFC 2603, "Rust Symbol Mangling (v0)" #60705
Comments
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
I just opened a bug in compiler-explorer because I noticed collision in the demangled name of different monomorphisation of the same function. As far as I understand, the current mangling scheme of rust still use the v1 witch doesn't contains the required information, while this proposed v2 would solved it? Did I correctly understood what the current situation is? |
@robinmoussu As per #57967, you can set |
@eddyb @michaelwoerister |
Could just rely on a |
Updating the RFC's "v2" to "v0" as per #57967 (comment) (should've done it back then). |
I've just submitted "[PATCH] Support the new ("v0") mangling scheme in rust-demangle.", to the If everything goes well, once that's merged we'll be able to also upstream the same implementation to |
Potential change we might want to make to const value mangling: #61486 (comment). The tricky aspect is whether we change the way EDIT: AFAIK, that situation can only be reached with EDIT2: just checked and my 1 million symbols dataset doesn't contain a single instance of |
Quick update: I haven't received a response on the final patch in 2.5 months. This means I can probably resubmit with the placeholder constant syntax removed (see my previous comment, i.e. #60705 (comment)), and/or maybe we can even implement some form of ADT mangling in the interim, since it doesn't seem to be that difficult (see #71232 for something similar). But this is disappointing and another delay in getting the new mangling scheme to be supported in native tooling, which would've ideally been all dealt with last year. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Oh, my bad @EFanZh, now that I'm looking at it, I'm pretty sure I've seen it before and just forgot :( |
Discussed in T-compiler backlog bonanza The v0 symbol mangling has been implemented. From #89917 we have considered making v0 the default, but we have held off on doing so in order to give external tools time to add support. In PR #90054 we did make v0 the default for builds of We need to figure out what criteria we will use in this and other cases to decide that "it is time" to switch the defaults. (We also considered opening a separate tracking issue for the question of "when to switch the default", but at this point I think we would only open such a tracking issue if we were ready to close this one, #60705, itself. @rustbot label: S-tracking-needs-to-bake |
The first thing to do would be to produce a list of tools that people want to support. For each tool, we should determine whether it supports v0, and, if so, the date of the first public release that features v0 support. Once each tool supports v0, and once each has supported v0 for long enough (precise criteria TBD), then stabilization should be unblocked. Obviously this list cannot guarantee that it will exhaustively mention every tool ever made, but the only alternative would be to never stabilize v0 for fear of overlooking some tool. In the meantime, we can use a blog post to put out a general call to tool developers to ask them to ensure that v0 works with their tools. |
Nominating to hopefully act as a forcing function to create this list. |
One problem with v0 mangling that hasn't been identified: it completely breaks the
And with v0 mangling:
Note the difference in the
This is probably a case where cc @dtolnay |
Is or will there be an official Rust name mangling library (functionality), rather than demangling? Sometimes, one needs to mangle Rust item paths to look into binaries, e.g. like |
Why would perf need to mangle names? There is no way to exactly reproduce symbol names outside of rustc itself given that they contain a crate disambiguator whose value depends on the |
Please re-read my sentence @bjorn3. I'm not claiming |
@bjorn3 Thanks for your explanation. I hope you didn't assume every commenter should know these details. I think the question is legitimate. It was asked before in the context of GCC C++. The information required I have available, but that's not important now. Even if just the algorithm were to be specified like in the GCC case, perhaps enough of the translation symbol to mangled symbol can be reconstructed to find the specific symbol in a binary for a given item path. That's my use case but I don't assume this would be the only solution of the only use case for a mangling spec or reference implementation. |
It should be possible to have something like an api where you specify in the input a wildcard for the crate disambiguator and then the name mangling library would output a wildcard where it would otherwise print the crate disambiguator. Would this work for your use case? |
A reference implementation does already exist, essentially, as part of rustc. That it's not a reusable library just reflects that the goal of a known mangling scheme is the ability for 3rd party non-rustc tooling to be able to turn mangled symbols back into the demangled human-meaningful form. Being able to mangle symbols is explicitly a non-goal.
For binary introspection, demangling is sufficient. Given an unmangled name, to find the corresponding mangled names1, you don't mangle the unmangled name to compare to the mangled symbols; instead, you demangle the symbols from the binary to compare to the unmangled symbol. Most of the time you'll want the full list of demangled symbols anyway, e.g. for display or otherwise. If you want fully predictable names (e.g. for linking manually ABI-stable interfaces), you should be specifying them explicitly. It would be interesting to be able to request v0 mangling (without the use of disambiguators) rather than having to manually apply a mangling scheme, but that's a completely separate feature request than the use for Rust-only names tracked here. Footnotes
|
When you need to step back to the same binary you demangled symbols of, and determine to what mangled symbol a demangled name refers, then you may want this functionality. Please also consider that binaries you have and even a build pipeline including source code, does not mean you are free to modify the source code to achieve predicable symbol names or whatever. By the way, it's bit of a semantic discussion what demangling entails, in response to my functional requirement at least. Third party tooling like perf \
probe \
--exec $(realpath "mycrate/target/debug/deps/binary-cfcd9bd03ac152c2") \
--add="uprobe123=mycrate\:\:tests\:\:test_1"
|
Yes, sure. And perhaps there are other, forensic cases and such. Please note, I'm not an expert or involved in this mangling work here or elsewhere, just chiming in as a user with a practical use case that I think will be relevant to a subgroup of real-world developers (not detailing it since it's part of a paper to be published). |
As far as I can tell gdb does not support suffixes using |
rust-lang/rust#60705 Due to modification of .cargo/config.toml your `cargo build` should pick this change up automatically. Use `legacy` instead of `v0` if you find yourself in need of old mangling scheme for whatever reason Release Notes: - Improved precision of backtraces in application crashes
@benpye Given that the only documented use of I wonder if the compiler team would like to use the upcoming 2024 edition as an excuse to finally ship v0 mangling? This would let us roll it out gradually and in a way that can be easily rolled back by users, and since it's an implementation detail we could make it the default for all editions someday in the future if we really wanted to. |
… r=<try> [perf] Test performance with v0 symbol mangling scheme being the default With the wider ecosystem getting close to support the v0 mangling scheme and LLD as the default linker addressing v0's main performance issue, it is getting more likely that we can soon make v0 the default. This PR's purpose is to collect current performance numbers and also to serve as a baseline for gauging the performance impact of [MCP 737](rust-lang/compiler-team#737). v0 symbol mangling tracking issue: rust-lang#60705 r? `@ghost`
This is a tracking issue for the RFC "Rust Symbol Mangling (v0)" (rust-lang/rfcs#2603).
Current status:
Since #90128, you can control the mangling scheme with
-C symbol-mangling-version
, which can be:legacy
: the older mangling version, still the default currently-Z unstable-options
(to allow for eventual removal after
v0
becomes the default)v0
: the new RFC mangling version, as implemented by Introduce Rust symbol mangling scheme. #57967(Before #90128, this flag was the nightly-only
-Z symbol-mangling-version
)To test the new mangling, set
RUSTFLAGS=-Csymbol-mangling-version=v0
(or changerustflags
in.cargo/config.toml
). Please note that only symbols from crates built with that flag will use the new mangling, and that tool support (e.g. debuggers) will be limited initially, until everything is upstreamed. However,RUST_BACKTRACE
andrustfilt
should work out of the box with either mangling version.Steps:
binutils
/gdb
(GNUlibiberty
)committed as gcc-mirror/gcc@979526c
committed as gcc-mirror/gcc@42bf58b
committed as gcc-mirror/gcc@e1cb00d
(original submission) committed as gcc-mirror/gcc@32fc371
(original submission) committed as gcc-mirror/gcc@8409649
perf
(throughbinutils 2.36
and/orlibiberty 11.0
, or later versions - may vary between distros)valgrind
Unresolved questions:
Desired availability of tooling:
Linux:
Windows:
Windows does not have support for demangling either legacy or v0 Rust symbols and requires debuginfo to load the appropriate function name. As such, no special support is required.
macOS:
More investigation is needed to determine to what extent macOS system tools already support Rust v0 mangling.
The text was updated successfully, but these errors were encountered: