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

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

Open
orlp opened this issue Jan 2, 2025 · 5 comments · Fixed by #135034
Assignees
Labels
C-bug Category: This is a bug. O-macos Operating system: macOS P-critical Critical priority regression-from-stable-to-beta Performance or correctness regression from stable to beta. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@orlp
Copy link
Contributor

orlp commented Jan 2, 2025

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.

@orlp orlp added the C-bug Category: This is a bug. label Jan 2, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jan 2, 2025
@Noratrieb Noratrieb added O-macos Operating system: macOS T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Jan 2, 2025
@orlp
Copy link
Contributor Author

orlp commented Jan 2, 2025

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.

@orlp
Copy link
Contributor Author

orlp commented Jan 2, 2025

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

@Noratrieb Noratrieb added the regression-from-stable-to-beta Performance or correctness regression from stable to beta. label Jan 2, 2025
@rustbot rustbot added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Jan 2, 2025
@Noratrieb Noratrieb self-assigned this Jan 2, 2025
@apiraino
Copy link
Contributor

apiraino commented Jan 2, 2025

@rustbot label +T-bootstrap

cc @davidtwco @jieyouxu since #131405

@rustbot rustbot added the T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) label Jan 2, 2025
@lqd lqd removed the T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) label Jan 2, 2025
@jieyouxu
Copy link
Member

jieyouxu commented Jan 2, 2025

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

bors added a commit to rust-lang-ci/rust that referenced this issue Jan 2, 2025
Pass objcopy args for stripping on OSX

When `-Cstrip` was changed in rust-lang#131405 to use the bundled rust-objcopy instead of /usr/bin/strip on OSX, strip-like arguments were preserved.

But strip and objcopy are, while being the same binary, different, they have different defaults depending on which binary they are. Notably, strip strips everything by default, and objcopy doesn't strip anything by default.

Additionally, `-S` actually means `--strip-all`, so debuginfo stripped everything and symbols didn't strip anything.

We now correctly pass `--strip-debug` and `--strip-all`.

fixes rust-lang#135028

try-jobs: aarch64-apple
@Noratrieb Noratrieb added P-critical Critical priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Jan 2, 2025
bors added a commit to rust-lang-ci/rust that referenced this issue Jan 2, 2025
Pass objcopy args for stripping on OSX

When `-Cstrip` was changed in rust-lang#131405 to use the bundled rust-objcopy instead of /usr/bin/strip on OSX, strip-like arguments were preserved.

But strip and objcopy are, while being the same binary, different, they have different defaults depending on which binary they are. Notably, strip strips everything by default, and objcopy doesn't strip anything by default.

Additionally, `-S` actually means `--strip-all`, so debuginfo stripped everything and symbols didn't strip anything.

We now correctly pass `--strip-debug` and `--strip-all`.

fixes rust-lang#135028

try-jobs: aarch64-apple
try-jobs: dist-aarch64-apple
bors added a commit to rust-lang-ci/rust that referenced this issue Jan 2, 2025
Pass objcopy args for stripping on OSX

When `-Cstrip` was changed in rust-lang#131405 to use the bundled rust-objcopy instead of /usr/bin/strip on OSX, strip-like arguments were preserved.

But strip and objcopy are, while being the same binary, different, they have different defaults depending on which binary they are. Notably, strip strips everything by default, and objcopy doesn't strip anything by default.

Additionally, `-S` actually means `--strip-all`, so debuginfo stripped everything and symbols didn't strip anything.

We now correctly pass `--strip-debug` and `--strip-all`.

fixes rust-lang#135028

try-job: aarch64-apple
try-job: dist-aarch64-apple
bors added a commit to rust-lang-ci/rust that referenced this issue Jan 2, 2025
Pass objcopy args for stripping on OSX

When `-Cstrip` was changed in rust-lang#131405 to use the bundled rust-objcopy instead of /usr/bin/strip on OSX, strip-like arguments were preserved.

But strip and objcopy are, while being the same binary, different, they have different defaults depending on which binary they are. Notably, strip strips everything by default, and objcopy doesn't strip anything by default.

Additionally, `-S` actually means `--strip-all`, so debuginfo stripped everything and symbols didn't strip anything.

We now correctly pass `--strip-debug` and `--strip-all`.

fixes rust-lang#135028

try-job: aarch64-apple
try-job: dist-aarch64-apple
bors added a commit to rust-lang-ci/rust that referenced this issue Jan 3, 2025
Pass objcopy args for stripping on OSX

When `-Cstrip` was changed in rust-lang#131405 to use the bundled rust-objcopy instead of /usr/bin/strip on OSX, strip-like arguments were preserved.

But strip and objcopy are, while being the same binary, different, they have different defaults depending on which binary they are. Notably, strip strips everything by default, and objcopy doesn't strip anything by default.

Additionally, `-S` actually means `--strip-all`, so debuginfo stripped everything and symbols didn't strip anything.

We now correctly pass `--strip-debug` and `--strip-all`.

fixes rust-lang#135028

try-job: aarch64-apple
try-job: dist-aarch64-apple
@bors bors closed this as completed in 3f43b1a Jan 3, 2025
@Noratrieb
Copy link
Member

Re-opening for the backport.

@Noratrieb Noratrieb reopened this Jan 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. O-macos Operating system: macOS P-critical Critical priority regression-from-stable-to-beta Performance or correctness regression from stable to beta. 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.

6 participants