Skip to content

Rustc strips all symbols on MacOS when strip = "debuginfo" is specified, but not when strip = "symbols" is specified #135028

Description

@orlp

Consider this basic example:

fn main() {
    std::thread::sleep(std::time::Duration::from_secs_f64(1.0));
}

When compiled with cargo build and the following Cargo.toml:

[profile.dev]
debug = false
strip = "symbols"

we see the following profile with samply record:

Image

That is, all symbols are still there. However, when we instead build with

[profile.dev]
debug = false
strip = "debuginfo"

we see the following profile:

Image

I believe this is a bug, as the documentation for strip specifies that symbols is supposed to be a more aggressive stripping than debuginfo, which is supposed to leave backtrace information mostly intact. We see the opposite behavior.


The following lines of code are suspect:

if sess.target.is_like_osx {
let stripcmd = "rust-objcopy";
match (strip, crate_type) {
(Strip::Debuginfo, _) => {
strip_symbols_with_external_utility(sess, stripcmd, out_filename, &["-S"])
}
// Per the manpage, `-x` is the maximum safe strip level for dynamic libraries. (#93988)
(Strip::Symbols, CrateType::Dylib | CrateType::Cdylib | CrateType::ProcMacro) => {
strip_symbols_with_external_utility(sess, stripcmd, out_filename, &["-x"])
}
(Strip::Symbols, _) => {
strip_symbols_with_external_utility(sess, stripcmd, out_filename, &[])
}
(Strip::None, _) => {}
}
}

-S on rust-objcopy is documented as such:

  -S                      Alias for --strip-all

It does not seem appropriate to be used in the Debuginfo branch, but omitted in the Symbols branch.

Activity

  1. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Jan 2, 2025
  2. added
    O-macosOperating system: macOS
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    and removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Jan 2, 2025
  3. orlp commented on Jan 2, 2025

    @orlp
    ContributorAuthor

    What made it extra annoying to debug this issue is that the cargo docs lie about the default for strip. It says strip = "none" is the default, but this is not true. The default depends on whether or not debug = false is specified.

  4. orlp commented on Jan 2, 2025

    @orlp
    ContributorAuthor

    This is a regression from stable to nightly, tracked down to #131405.

  5. added
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    on Jan 2, 2025
  6. self-assigned this
    on Jan 2, 2025
  7. apiraino commented on Jan 2, 2025

    @apiraino
    Contributor

    @rustbot label +T-bootstrap

    cc @davidtwco @jieyouxu since #131405

  8. added
    T-bootstrapRelevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)
    on Jan 2, 2025
  9. removed
    T-bootstrapRelevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)
    on Jan 2, 2025
  10. jieyouxu commented on Jan 2, 2025

    @jieyouxu
    Member

    The regression is actually a T-compiler concern, because we used the wrong flags for rust-objcopy in cg_ssa.

  11. added a commit that references this issue on Jan 2, 2025
    cc677e6
  12. added and removed
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    on Jan 2, 2025
  13. added 5 commits that reference this issue on Jan 2, 2025
    efbd1f6
    3f1985a
    05ab192
    436ab06
    3f43b1a
  14. Noratrieb commented on Jan 3, 2025

    @Noratrieb
    Member

    Re-opening for the backport.

  15. wesleywiser commented on Jan 9, 2025

    @wesleywiser
    Member

    Backport occurred in #135163 so I'm closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

C-bugCategory: This is a bug.O-macosOperating system: macOSP-criticalCritical priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-betaPerformance or correctness regression from stable to beta.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions