rfcs icon indicating copy to clipboard operation
rfcs copied to clipboard

Allow backtrace information to be optional

Open Earlz opened this issue 9 years ago • 13 comments

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

Earlz avatar Dec 18 '15 22:12 Earlz

:+1: Always bothered me.

ticki avatar Dec 21 '15 20:12 ticki

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).

eddyb avatar Dec 23 '15 18:12 eddyb

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 avatar Dec 23 '15 19:12 ticki

@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?

eddyb avatar Dec 23 '15 19:12 eddyb

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.

ticki avatar Dec 23 '15 19:12 ticki

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).

eddyb avatar Dec 23 '15 19:12 eddyb

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.

eddyb avatar Dec 23 '15 19:12 eddyb

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).

ticki avatar Dec 23 '15 19:12 ticki

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 avatar Jul 24 '16 03:07 japaric

@japaric https://github.com/rust-lang/rfcs/pull/1133 while not completely solving the problems you mention is a big step in that direction.

Ericson2314 avatar Jul 24 '16 07:07 Ericson2314

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

japaric avatar Jul 26 '16 20:07 japaric

What's the current status of this?

Owez avatar Oct 10 '21 14:10 Owez

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.

Avamander avatar May 09 '22 10:05 Avamander

You can use a panic hook to disable that message, right?

bjorn3 avatar Aug 17 '23 17:08 bjorn3

Panic hook won't remove the unwanted data from the executable.

kornelski avatar Aug 19 '23 12:08 kornelski