Skip to content

Add compiler option to strip symbols from generated binaries #71757

Closed

Description

@GabrielMajeri

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

Activity

  1. added
    A-debuginfoArea: Debugging information in compiled programs (DWARF, PDB, etc.)
    A-linkageArea: linking into static, shared libraries and binaries
    C-feature-requestCategory: A feature request, i.e: not implemented / a PR.
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on May 1, 2020
  2. ehuss commented on May 1, 2020

    @ehuss
    Contributor

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

  3. GabrielMajeri commented on May 1, 2020

    @GabrielMajeri
    ContributorAuthor

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

  4. petrochenkov commented on May 8, 2020

    @petrochenkov
    Contributor

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

  5. added a commit that references this issue on May 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-debuginfoArea: Debugging information in compiled programs (DWARF, PDB, etc.)A-linkageArea: linking into static, shared libraries and binariesC-feature-requestCategory: A feature request, i.e: not implemented / a PR.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions