Skip to content

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

Closed
@orlp

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.

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