Skip to content
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

Strip debug symbols in release #208

Closed
savchenko opened this issue Apr 25, 2021 · 7 comments
Closed

Strip debug symbols in release #208

savchenko opened this issue Apr 25, 2021 · 7 comments
Labels
enhancement New feature or request

Comments

@savchenko
Copy link
Collaborator

When building via cargo build --release, symbols are still present:

checksec --file=$HOME/.local/bin/ta
RELRO           STACK CANARY      NX            PIE             RPATH      RUNPATH        Symbols         FORTIFY Fortified       Fortifiable     FILE
Full RELRO      Canary found      NX enabled    PIE enabled     No RPATH   No RUNPATH   19684) Symbols      No    0   12

Perhaps good ol' RUSTFLAGS='-C link-arg=-s' cargo build --release will do as default release step?

@djmitche
Copy link
Collaborator

Could this be accomplished in Cargo.toml? https://doc.rust-lang.org/cargo/reference/profiles.html

Aside from binary size, what's the issue with including symbols?

@savchenko
Copy link
Collaborator Author

Aside from binary size, what's the issue with including symbols?

None. But the difference is ~4.2 vs 17.3 Mb.

@savchenko
Copy link
Collaborator Author

Could this be accomplished in Cargo.toml?

"It depends". This should eventually work:

cargo-features = ["strip"]

[workspace]
members = [
    "taskchampion",
    "cli",
    "sync-server"
]

[profile.release]
strip = "symbols"

At present this requires nightly rustc. With rustc 1.48.0 that is shipped in Debian 11 the feature returns an error:

error: the option `Z` is only accepted on the nightly compiler

@savchenko
Copy link
Collaborator Author

Tried upx to see if executable with debug symbols can be efficiently packed and it somewhat surprisingly fails on TC:

        File size         Ratio      Format      Name
   --------------------   ------   -----------   -----------
upx: task: CantPackException: bad DT_GNU_HASH n_bucket=0x3a  n_bitmask=0x4  len=0x198

@dbr
Copy link
Collaborator

dbr commented Apr 27, 2021

rust-lang/rust#72110 is the tracking issue for stripping debug info etc from Cargo.toml. It being stabilized seems to be largely blocked by macOS support, rust-lang/rust#82037

This seems like a good thing to aim for in a "1.0" release, by which point this feature will hopefully be in Rust stable

@savchenko savchenko added this to the v1.0.0 milestone Apr 27, 2021
@savchenko savchenko added the enhancement New feature or request label Apr 27, 2021
@dbr
Copy link
Collaborator

dbr commented Oct 25, 2021

The option for this seems like it'll be stablized in the next month or so
rust-lang/rust#90058

@dbr
Copy link
Collaborator

dbr commented Jan 26, 2022

rustc -C strip now stable as of Rust toolchain 1.58, and the strip option is available in cargo as of 1.59,

https://github.com/rust-lang/cargo/blob/master/CHANGELOG.md#cargo-159-2022-02-24

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants