-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
no way to not ship panic strings inside the compiled binary #60105
Comments
You can do this by using a custom panic implementation like panic-abort which doesn't use the strings. Also see RFC 2070 which introduced this feature and is currently the best source of information on how to use it. |
I've already tried that and doesn't work on the program that is using std... unless I'm missing something obvious |
Can you provide a reproduction for that? It definitely works on embedded |
|
Ah, I misunderstood what you meant. Looks like that RFC indeed only targets |
Linux has a |
@Julius-Beides actually, opt-level either Z or S does that, if you also pass maybe the default panic implementation should use Line 12 in 9ebf478
#[cfg(not(panic="abort"))] (but this doesn't work, of course) before the call to panic fn, since even assert_* macros panic with strings. I usually do that for debug strings, with a #[cfg(debug_assertions)]] println!() (when I actually do care about the information, during profile.dev / test)
|
You can do this by building your own std (xargo can help with this) with this Cargo feature enabled: https://github.com/rust-lang/rust/blob/master/src/libstd/Cargo.toml#L60 |
Did you ever solve this issue? It is easy to make the strings deterministic that are from the crate you are actually compiling. But there are strings that point to dependencies in I compile with
|
Duplicate of #54981. |
Already have
panic = "abort"
in cargo, and it doesn't seem to leave the panic!() strings out of the compiled binary, even on--release
build. I don't care about panic strings, I just want a slim generated exe that fails if something goes wrong.tokio
,crossbeam
andchrono
are adding a lot of useless strings in the.rdata
on Windows, for example. alsoopt-level = "s"
(and"z"
)tried to use
panic::set_hook
as well, it didn't do anything. tried to make the long path names usingremap-path-prefix
but it seemed to have no effect (the paths are still full absolute paths to current user folder/.cargo/registry). doesn't matter if I use windows paths (eg: C:\Users or Unix C:/Users) and besides the #40552 that's two years old, but a minor issue when you need to rely on std and size optimizations.also tried a lot of other stuff (like
link-arg=-s
,debuginfo=0
,no-landing-pads
, etc), while the generated exe is smaller than a full blowncargo build --release
, so it's really an unexpected output from the compilerThe text was updated successfully, but these errors were encountered: