Skip to content

strip = "symbols" doesn't work when cross-compiling from linux to macOS #114411

Open
@roblabla

Description

@roblabla

Currently, when compiling for macOS with -C strip=symbols, rustc will try to invoke strip on the output binary to remove its symbols. This, unfortunately, fails when cross-compiling from linux, as the strip binary on linux only understands ELF files and will choke on the mach-o. This results in the following warnings in the build logs, and an unstripped binary output:

warning: stripping debug info with `strip` failed: exit status: 1
  |
  = note: /usr/bin/strip: /home/roblabla/repro/target/x86_64-apple-darwin/release/deps/repro-19371802bd981e48: file format not recognized

Ideally, rustc should either:

  1. Use a cross-target stripper, such as llvm-strip (which is currently packaged in rustup as part of llvm-tools-preview, CC Tracking Issue for llvm-tools-preview #85658)
  2. Allow the user to configure which strip utility it will use (which could then end up in .cargo/config) to use one provided by osxcross or llvm.

Reproduction steps:

cargo new testing
cd testing
curl -L https://github.com/roblabla/MacOSX-SDKs/releases/download/13.3/MacOSX13.3.sdk.tar.xz | tar xJ
echo '[profile.release]' >> Cargo.toml
echo 'strip = "symbols"' >> Cargo.toml
SDKROOT=$PWD/MacOSX13.3.sdk CARGO_TARGET_X86_64_APPLE_DARWIN_LINKER=rust-lld cargo build --target=x86_64-apple-darwin --release

Meta

rustc --version --verbose:

rustc 1.71.0 (8ede3aae2 2023-07-12)
binary: rustc
commit-hash: 8ede3aae28fe6e4d52b38157d7bfe0d3bceef225
commit-date: 2023-07-12
host: aarch64-apple-darwin
release: 1.71.0
LLVM version: 16.0.5

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-crossArea: Cross compilationA-linkageArea: linking into static, shared libraries and binariesC-bugCategory: This is a bug.O-macosOperating system: macOST-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