rfcs
rfcs copied to clipboard
Allow backtrace information to be optional
There appears to be no way to disable backtrace information embedding into a program. There are some cases where bundling filenames and other information needed for backtraces is not desired. Two cases I can think of immediately is wanting to provide as little information as possible in proprietary products. The other case is where you need the final binary to be as small as possible.
There is an old set of patches that added this that seem to be stale now.. Maybe they can be used as a starting point? https://github.com/japaric/std-with-cargo And there was also some discussion about this on the rust-internals IRC, but nothing seemed to come out of it: https://botbot.me/mozilla/rust-internals/2015-08-20/?msg=47709853&page=4
:+1: Always bothered me.
What backtrace information? We use the symbol names or debug info, just like C and C++. If you're compiling an executable in release mode, all you have to do is strip symbols (the same as a proprietary C or C++ project would have to do).
What backtrace information? We use the symbol names or debug info, just like C and C++. If you're compiling an executable in release mode, all you have to do is strip symbols (the same as a proprietary C or C++ project would have to do).
It would make sense to provide a way to compile it without the symbol names & debug info. Futhermore, panics will show file name and line number (though this is not rustc, but libstd).
@Ticki To compile without debug info: remove -g. Cargo.toml has a way to turn it off even for debug mode, while release mode doesn't come with debug info.
Compiling without symbol names doesn't make sense: they're certainly mandatory for libraries, and executables cannot drop symbol names until linking has finished.
EDIT: gcc appears to have an -s option for stripping the symbol names after linking. I guess we could add that?
To compile without debug info: remove -g. Cargo.toml has a way to turn it off even for debug mode, while release mode doesn't come with debug info.
That'll still show line number and file name when panicking.
gcc appears to have an -s option for stripping the symbol names after linking. I guess we could add that?
Yeah, that was what I thought of. It -s often comes very handy.
Panics are not "backtrace information", they're file!() and line!() macros - having a way to obscure those would be useful, but you'd have to recompile the entire libstd in that mode if you want to get rid of all of them (they're just string literals as far as the post-expansion compiler is concerned).
Also, if you want a solution now for the "strip symbols part", you can use strip instead of having it built-in like gcc -s.
Panics are not "backtrace information", they're file!() and line!() macros - having a way to obscure those would be useful, but you'd have to recompile the entire libstd in that mode if you want to get rid of all of them
Yes, you're right. They're not backtrace information, they're debug information. These could be removed in release mode (by using #[cfg(build = "debug")] in libstd).
Update: The crates in rust-lang/rust has been Cargo-ified.
I have a lightly tested fork of rust-lang/rust that makes the backtraces (RUST_BACKTRACE / libbacktrace) optional via a Cargo feature (only usable with the newer "rustbuild" build system). But even if that lands upstream, it won't be super easy to use because (a) our binary releases would still ship with backtraces enabled, (b) even if you are OK with bootstrapping rustc along with the std crate, rustbuild doesn't expose (AFAIK cc @alexcrichton) an easy way to customize the Cargo features of the std crate and (c) trying to directly build the std crate using Cargo (as in cd src/libstd && cargo build) doesn't work for some combination of Cargo features like enabling jemalloc. Also (c) is annoying because you have to package the Cargo output into a sysroot before you can use it.
TL;DR To implement this we have to decide how to expose this (optional) feature to end users.
@japaric https://github.com/rust-lang/rfcs/pull/1133 while not completely solving the problems you mention is a big step in that direction.
rustbuild doesn't expose an easy way to customize the Cargo features of the std crate
Actually, there is a config.toml that rustbuild can use. I've send a PR implementing optional backtraces and exposing them via that config.toml: rust-lang/rust#35051
What's the current status of this?
There's one more good reason for this, that hasn't been mentioned yet. I want to disable the message because re-running the panicking binary is not always a good thing to suggest to end-users.
You can use a panic hook to disable that message, right?
Panic hook won't remove the unwanted data from the executable.