Continuation of the discussion from https://github.com/rust-lang/cargo/issues/5198
My question was wether there would be any genuine issues / behabiour changes caused by stripping all release binaries by default?
IIRC, you might get worse stack traces?
Debuginfo isn’t on by default for release targets. C compilers don’t strip by default either.
With the important caveat that debug infor for stdlib is always there (because the same release+debuginfo build of stdlib is used for both debug and release).
Are you sure you get from 25MB to 3MB after strip on the release build?
axos88
March 19, 2018, 7:09am
#2
Sorry that size reduction was for a debug build. For a release build 6.5MB -> 1.6MB (with rocket, serde, wiringpi and pam-auth)
$ rm -f target/arm-unknown-linux-gnueabihf/release/rpitest; \
cargo build --target arm-unknown-linux-gnueabihf --release; \
mv target/arm-unknown-linux-gnueabihf/release/rpitest ./strip.off; \
rm -f target/arm-unknown-linux-gnueabihf/release/rpitest; \
cargo build --target arm-unknown-linux-gnueabihf --release; \
mv target/arm-unknown-linux-gnueabihf/release/rpitest ./strip.on; \
arm-none-eabi-strip strip.on; \
ls -lh strip.on strip.off
Compiling rpitest v0.1.0 (file:///Users/akos/projects/rust/tutorial)
Finished release [optimized] target(s) in 4.65 secs
Compiling rpitest v0.1.0 (file:///Users/akos/projects/rust/tutorial)
Finished release [optimized] target(s) in 4.44 secs
-rwxr-xr-x 1 akos staff 6.5M Mar 19 08:09 strip.off
-rwxr-xr-x 2 akos staff 1.6M Mar 19 08:09 strip.on
axos88
March 19, 2018, 7:15am
#3
Seems like LTO doesn’t makes a difference only in the unstripped binary in this particular case:
-rwxr-xr-x 1 akos staff 4.7M Mar 19 08:13 strip.off
-rwxr-xr-x 2 akos staff 1.6M Mar 19 08:13 strip.on
Oh, very interesting! I think this is https://github.com/rust-lang/rust/issues/46034 , that is, the bloat comes from debug symbols in stdlib.
kyrias
March 27, 2018, 7:33am
#5
Latest nightly now has -Zstrip-debuginfo-if-disabled
, which when set to yes
will tell the linker to strip debuginfo during linking if debuginfo hasn’t been enabled.
kyrias
March 27, 2018, 7:40am
#6
$ rustc --version
rustc 1.26.0-nightly (188e693b3 2018-03-26)
$ cargo new hello && cd hello
$ cargo build --release && ls -lah target/release/hello
Compiling hello v0.1.0 (file:///home/remmy/code/hello)
Finished release [optimized] target(s) in 0.33 secs
-rwxr-xr-x 2 remmy remmy 5.2M Mar 27 09:39 target/release/hello
$ RUSTFLAGS='-Zstrip-debuginfo-if-disabled=yes' cargo build --release && ls -lah target/release/hello
Compiling hello v0.1.0 (file:///home/remmy/code/hello)
Finished release [optimized] target(s) in 0.27 secs
-rwxr-xr-x 2 remmy remmy 540K Mar 27 09:39 target/release/hello
1 Like