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

Add compiler option to strip symbols from generated binaries #71757

Closed
GabrielMajeri opened this issue May 1, 2020 · 3 comments · Fixed by #71825
Closed

Add compiler option to strip symbols from generated binaries #71757

GabrielMajeri opened this issue May 1, 2020 · 3 comments · Fixed by #71825
Labels
A-debuginfo Area: Debugging information in compiled programs (DWARF, PDB, etc.) A-linkage Area: linking into static, shared libraries and binaries C-feature-request Category: A feature request, i.e: not implemented / a PR. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@GabrielMajeri
Copy link
Contributor

There's a long standing Cargo issue, requesting the ability to strip symbols from built Rust binaries.

@alexcrichton suggested here that

This might be best done as a rust-lang/rust PR first which has access to target information to know what flag should be passed to the linker. For example this could be added as -C strip or something like that. We could then add a profile setting for Cargo to configure that on the Cargo side of things afterwards.

I'm opening this issue to discuss adding such a -C strip flag and to track its implementation in the compiler.

Right now, it could be a simple boolean flag, which passes an additional option to the linker (since, AFAIK, most linkers have some sort of flag for stripping symbols from the final binaries).

@jonas-schievink jonas-schievink added A-debuginfo Area: Debugging information in compiled programs (DWARF, PDB, etc.) A-linkage Area: linking into static, shared libraries and binaries C-feature-request Category: A feature request, i.e: not implemented / a PR. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels May 1, 2020
@ehuss
Copy link
Contributor

ehuss commented May 1, 2020

I'm uncertain, but isn't -Zstrip-debuginfo-if-disabled essentially the same?

@GabrielMajeri
Copy link
Contributor Author

GabrielMajeri commented May 1, 2020

I'm uncertain, but isn't -Zstrip-debuginfo-if-disabled essentially the same?

As far as I understand, this will only remove debug symbols, while the issue is about striping all symbol information (this means removing all symbols from an executable, and non-exported symbols for a dynamic library). What I am proposing would affect the size of release builds too.

This is analogous to the --strip-all and --strip-debug linker flags (and I believe this will only be achievable by configuring the linker).

@petrochenkov
Copy link
Contributor

#71825 (comment) suggests introducing -Z strip=[none|debuginfo|symbols].

@bors bors closed this as completed in aeb4738 May 11, 2020
bors added a commit to rust-lang/cargo that referenced this issue May 19, 2020
Add option to strip binaries

This PR adds a Cargo option for stripping symbols from generated binaries.

This is based on the `-Z strip` flag for `rustc`, which has been [recently implemented](rust-lang/rust#71757).

Notes for reviewers: I'm not entirely sure how we test this, I've created a crate locally and it seems to be working.

Supersedes my previous work in #8191.
Fixes #3483.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-debuginfo Area: Debugging information in compiled programs (DWARF, PDB, etc.) A-linkage Area: linking into static, shared libraries and binaries C-feature-request Category: A feature request, i.e: not implemented / a PR. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants