-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Cross-compiling from x86_64-linux to aarch64-darwin produces a broken (stripped) dylib #141913
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
Comments
Hmm we had a few recent issues related to linking on macOS but they were something else (linking just failed for a number of reasons1). Another suspect I could think of is the LLVM update: does this reproduce right before we merged LLVM 20 in #135763? cc @nikic if this smells like an LLVM-related issue Footnotes
|
Might be llvm/llvm-project#141494? |
cc @dianqk |
Command I ran:
with |
Thw minimal reproduction on macOS: #![crate_type = "cdylib"]
#[unsafe(no_mangle)]
pub fn foo() {
panic!();
} rustc lib.rs -Clink-arg=-ld_classic --target aarch64-apple-ios -o repro.ios.out
llvm-objcopy repro.ios.out repro.ios.stripped.out
llvm-otool -l repro.ios.out | grep LC_ENCRYPTION_INFO
llvm-otool -l repro.ios.stripped.out | grep LC_ENCRYPTION_INFO
cmd LC_ENCRYPTION_INFO_64
llvm-otool: error: 'repro.ios.stripped.out': truncated or malformed object (section contents at offset 223704 with a size of 648, overlaps section contents at offset 32768 with a size of 203768) rustc lib.rs -Clink-arg=-ld_classic -Clink-arg=-Wl,-encryptable --target aarch64-apple-darwin -o repro.darwin.out
llvm-objcopy repro.darwin.out repro.darwin.stripped.out
llvm-otool -l repro.darwin.out | grep LC_ENCRYPTION_INFO
llvm-otool -l repro.darwin.stripped.out | grep LC_ENCRYPTION_INFO
cmd LC_ENCRYPTION_INFO_64
llvm-otool: error: 'repro.darwin.stripped.out': truncated or malformed object (section contents at offset 223624 with a size of 648, overlaps section contents at offset 32768 with a size of 203300) But I'm not sure why LC_ENCRYPTION_INFO is being submitted by default here for aarch64-apple-darwin. |
Perhaps we should revert all the relevant commits. |
|
But it did fix the iOS crash. And we probably don't want to regress that again. Thanks for the minimal reproduction. |
We can revert both llvm/llvm-project#120995 and llvm/llvm-project#130517. |
I am cross-compiling from a Linux
x86_64
host toaarch64-apple-darwin
.Since Rust 1.87.0 this results in a broken
dylib
file when it gets stripped.This worked ok until 1.86.0
Unfortunately I'm not able to reproduce that on a really small example, but a reproduction case is available in https://github.com/badboy/rocketscience/tree/broken-dylib
Note that this requires additional tooling:
The included
run.sh
downloads all requirements and setsRUSTFLAGS
accordingly.All that is required is:
RUSTFLAGS
is this:The final
dylib
attarget/aarch64-apple-darwin/release/librocketscience.dylib
should be inspectable byaarch64-apple-darwin-nm
.When it's not it will error out.
On Rust 1.87.0 and 1.89.0-nightly (99e7c15 2025-06-01) it fails:
On Rust 1.86.0 or when setting
strip = false
inCargo.toml
it works:This is all due to the bundled
rust-objcopy
.Manually running the
rust-objcopy
command on the not-broken dylib thatcargo
also runs produces the brokendylib
:This does NOT happen when building on my aarch64 macOS machine, only when cross-compiling.
This all sounds very similar to #138212.
Back then it was an upstream bug, so this might be another one.
Or is this due to mixing and matching the toolchains in an incompatible way?
Version it worked on
Version with regression
The text was updated successfully, but these errors were encountered: