-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Description
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- explicitly specifying this is unstable-only and also requires
-Z unstable-options
(to allow for eventual removal afterv0
becomes the default)
- explicitly specifying this is unstable-only and also requires
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 change rustflags
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
and rustfilt
should work out of the box with either mangling version.
Steps:
- Upstream C implementation of the demangler to:
binutils
/gdb
(GNUlibiberty
)To pick up a draggable item, press the space bar. While dragging, use the arrow keys to move the item. Press space again to drop the item in its new position, or press escape to cancel.- Linux
perf
(throughbinutils 2.36
and/orlibiberty 11.0
, or later versions - may vary between distros) valgrind
To pick up a draggable item, press the space bar. While dragging, use the arrow keys to move the item. Press space again to drop the item in its new position, or press escape to cancel.Implement demangling support in LLVM, including lldb, lld, llvm-objdump, llvm-nm, llvm-symbolizer, llvm-cxxfiltResolve issue around rustc generating invalid symbol names (v0 mangled symbol doesn't match specification nor can it be demangled with rustfilt or c++filt #83611)Adjust documentation (see instructions on rustc-guide)Stabilization PR (see instructions on rustc-guide)To pick up a draggable item, press the space bar. While dragging, use the arrow keys to move the item. Press space again to drop the item in its new position, or press escape to cancel.
Unresolved questions:
- Punycode vs UTF-8, some prior discussion in Ident mangling and unicode. #7539To pick up a draggable item, press the space bar. While dragging, use the arrow keys to move the item. Press space again to drop the item in its new position, or press escape to cancel.
Desired availability of tooling:
Linux:
- Tools: binutils, gdb, lldb, perf, valgrind
Distro | Has versions of all tools with support? |
---|---|
Debian (latest stable) | ? |
Arch | ? |
Ubuntu (latest release) | ? |
Ubuntu (latest LTS) | ? |
Fedora (latest release) | ? |
Alpine (latest release) | ? |
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.
Activity
eddyb commentedon May 13, 2019
michaelwoerister commentedon May 13, 2019
eddyb commentedon May 14, 2019
robinmoussu commentedon Dec 27, 2019
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?
142 remaining items
rust.new-symbol-mangling
totrue
universally #133998danobi commentedon Jan 29, 2025
As a heads up,
perf
is about to drop support for libbfd/libiberty for license incompatibility reasons. I think someone needs to go and teach perf how to demangle v0 symbols. More details here: https://lore.kernel.org/bpf/gnwmibvjtwboisw7uv32bdo4ziw4qzgwzvndqg2czpa6vp4olv@44n36ndbwobc/captain5050 commentedon Jan 29, 2025
I sent:
https://lore.kernel.org/lkml/20250129193037.573431-1-irogers@google.com/
for this. There are some TODOs in it and it is only lightly tested.
bjorn3 commentedon Jan 29, 2025
Have you seen https://github.com/rust-lang/rustc-demangle/blob/main/crates/native-c/src/demangle.c? It is a C port of the official demangler with both v0 and legacy support.
captain5050 commentedon Jan 30, 2025
I hadn't seen it. Given the official nature, legacy support and lack of TODOs compared to my version, I would say it was very much superior :-). Perhaps @arielb1 could contribute it to Linux perf? I'd be happy to try to co-develop if useful.
Wrt licenses, MIT is explicitly compatible and Apache 2 is compatible if combined with a compatible license under an OR license which I believe agrees with the wording here and is already in use by other files.
So outside of formatting things, I think the code can be added as is with the addition of a "SPDX-License-Identifier: Apache-2.0 OR MIT" comment at the top. There is a Linux kernel code contribution tool that will warn on formatting issues called checkpatch.pl.
captain5050 commentedon Feb 10, 2025
Hi, wondered if there is any update? On the LKML thread it seems preferred to pull the code into the Linux tree rather than depend on a library (at least initially). If I did this I'm happy to add co-authored tags - I'm also happy to guide others to do the work. What's best? I'm happy to do the fairly trivial glue code. I worry given the need to stand up and make a decisions there's the potential for this issue to sit unresolved. Would love @arielb1's input given they wrote the code.
lolbinarycat commentedon Apr 10, 2025
I un-checked the box for
perf
since it uses its own demangler (https://github.com/torvalds/linux/blob/master/tools/perf/util/demangle-rust.c) instead of deferring to a library as previously stated.as bjorn mentioned, there is a C version of the demangler, it just needs someone to write up a patch to integrate it into perf.
perf demangle-rust: Add rustc-demangle C demangler
captain5050 commentedon Apr 29, 2025
I wrote the patches and sent them to LKML, thanks to all and @arielb1 that the work builds from. Please let me know how I can improve the patches on the Linux mailing list:
https://lore.kernel.org/lkml/20250429185839.1807005-1-irogers@google.com/
For example, when adding the v0 demangling tests I switched to the alternate=true encoding as that better matched:
https://lore.kernel.org/lkml/20250429185839.1807005-5-irogers@google.com/
Thanks.
perf demangle-rust: Add rustc-demangle C demangler
perf demangle-rust: Add rustc-demangle C demangler
arielb1 commentedon Jul 9, 2025
Just noticed the issue now, sorry. Is there any help that is still needed?
If the question is about the alternate vs. non-alternate format - do whatever fits your case better. The alternate format is more verbose but preserves more information.
captain5050 commentedon Jul 9, 2025
The patches have been included into Linux v6.16:
https://lore.kernel.org/lkml/20250603203501.1961487-1-acme@kernel.org/
I was trying to go with the flow wrt licenses on tests and the like, hopefully the code, notes, attribution, tests.. all look good. You can see the source in Linus' tree here:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/tools/perf/util/demangle-rust-v0.c
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/tools/perf/util/demangle-rust-v0.h
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/tools/perf/tests/demangle-rust-v0-test.c
Thanks!