-
Notifications
You must be signed in to change notification settings - Fork 347
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
Rust symbol demangling #110
Comments
Shifting the discussion to this issue..
That would be indeed nicer, but I'm not sure if it is easily achievable, because Rust and C++ manglings are so similar. I'm not expert on this, so do not take my word on this, but testing shortsymbols/fullsymbols on a Rust executable results partial demangling:
|
An annoying user-visible piece of this is that Rust symbols have a hash suffix on them (to allow linking multiple major versions of the same crate into the same binary, if desired), you can see the n.b. the current in-use Rust mangling scheme is backwards-compatible with Itanium C++ name mangling for compatibility reasons. However, there's a Rust Symbol Mangling (v0) RFC which has not yet stabilized that specifies a Rust-specific mangling that is unambiguous. |
Are there any further updates on this? |
WorkaroundAs a workaround until this is solved you can use $ cargo install rustfilt
$ bloaty target/release/hello-world -d symbols --demangle=none | rustfilt
FILE SIZE VM SIZE
-------------- --------------
69.9% 286Ki 67.8% 226Ki [541 Others]
4.0% 16.3Ki 4.8% 16.2Ki std::backtrace_rs::symbolize::gimli::resolve
3.4% 13.8Ki 4.1% 13.7Ki std::backtrace_rs::symbolize::gimli::Context::new
2.5% 10.1Ki 3.0% 10.1Ki gimli::read::dwarf::Unit<R>::new
2.5% 10.1Ki 3.0% 10.0Ki miniz_oxide::inflate::core::decompress
1.9% 7.68Ki 2.3% 7.55Ki addr2line::ResUnit<R>::find_function_or_location::{{closure}}
1.7% 6.92Ki 2.0% 6.86Ki addr2line::Lines::parse Improved SymbolsI recommend building with $ RUSTFLAGS="-Csymbol-mangling-version=v0" cargo +nightly build -Zbuild-std=std --release
$ bloaty target/release/hello-world -d symbols --demangle=none | rustfilt
FILE SIZE VM SIZE
-------------- --------------
77.9% 415Ki 76.6% 300Ki [821 Others]
2.0% 10.6Ki 2.7% 10.5Ki miniz_oxide::inflate::core::decompress
1.4% 7.54Ki 1.9% 7.45Ki std::backtrace_rs::symbolize::gimli::resolve
1.1% 5.86Ki 1.5% 5.70Ki gimli::read::unit::parse_attribute::<gimli::read::endian_slice::EndianSlice<gimli::endianity::LittleEndian>>
1.0% 5.58Ki 1.4% 5.39Ki <addr2line::Context<gimli::read::endian_slice::EndianSlice<gimli::endianity::LittleEndian>>>::parse_units
1.0% 5.41Ki 1.3% 5.21Ki <addr2line::function::Function<gimli::read::endian_slice::EndianSlice<gimli::endianity::LittleEndian>>>::parse_children Common Source of Rust Binary BloatI'd like to serve one important insight when it comes to the binary size of a Rust program. In particular a small "hello world" program. Around 83% of the binary size of a Rust hello world program comes from code to support the nice default Rust backtraces upon panics (both for $ RUSTFLAGS="-Csymbol-mangling-version=v0" cargo +nightly build --release --config profile.release.codegen-units=1 --config profile.release.lto=true --config profile.release.strip=true -Zbuild-std -Zbuild-std-features=
$ ls -l target/release/hello-world
-rwxr-xr-x 2 martin martin 55552 Jan 4 21:31 target/release/hello-world In the above command we enable no standard library features by using the "empty" features directive You can reduce binary size even further by using more of the tricks from https://github.com/johnthagen/min-sized-rust than I used in the above example command. Note that with debug symbols and e.g. |
This came up in HN discussion that Bloaty does not have currently demangling for Rust symbols, and such feature would be useful.
There are at least two different libraries that implement Rust demangling:
GNU libiberty: https://github.com/gcc-mirror/gcc/blob/master/libiberty/rust-demangle.c
rustc-demangle: https://github.com/alexcrichton/rustc-demangle
The latter has the downside of being implemented in Rust, so a small wrapper is needed to make it work with C++ code. Might need bit of work to make it play with CMake nicely.
I have made a quick proof of concept version based on rustc-demangle here: https://github.com/zokier/bloaty/tree/rust_demangle
The text was updated successfully, but these errors were encountered: