Skip to content

Conversation

jieyouxu
Copy link
Member

@jieyouxu jieyouxu commented Mar 9, 2025

Backup crude workaround for #138212 to unblock nightly macOS-to-iOS cross builds. This reintroduces the "hard-coded strip" workaround (but only for iOS) that was initially introduced in #130781.

Looks like LLVM 20's initial llvm-objcopy version that we ship as rust-objcopy may be producing stripped iOS binaries with invalid offsets that fail iOS platform consistency checks.

For the time being, use macOS system strip when cross-compiling from macOS -> iOS at /usr/bin/strip which should be available (unlike Linux -> macOS cross where this is not guaranteed to be available, partially why we are shipping llvm-objcopy in the first place1) that shouldn't have this offset problem.

Preferrably it should be addressed by syncing back the upstream llvm-objcopy fix, but this is opened in case the upstream fix takes some time to merge and be synced back.

Alternatives

Review and testing advice

I don't have access to either macOS or iOS platforms, and I can't really write a test for this. This will need to be tested manually.

r? @davidtwco (or reroll)
cc *-apple-ios target maintainers @badboy @deg4uss3r @madsmtm

try-job: dist-apple-various
try-job: dist-x86_64-apple
try-job: dist-aarch64-apple

Footnotes

  1. https://github.com/rust-lang/rust/issues/131206

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 9, 2025
@jieyouxu jieyouxu added O-macos Operating system: macOS O-ios Operating system: iOS labels Mar 9, 2025
@jieyouxu
Copy link
Member Author

jieyouxu commented Mar 9, 2025

@bors try

@jieyouxu jieyouxu added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 9, 2025
@bors
Copy link
Collaborator

bors commented Mar 9, 2025

⌛ Trying commit 908c5e4 with merge 06d1077...

bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 9, 2025
[WIP] Use `/usr/bin/strip` on macOS -> iOS cross as a temporary mitigation

Mitigation for <rust-lang#138212>. This reintroduces the "hard-coded strip" workaround (but only for iOS) that was initially introduced in rust-lang#130781.

Looks like LLVM 20's initial `llvm-objcopy` version that we ship as `rust-objcopy` may be producing stripped iOS binaries with invalid offsets that fail iOS platform consistency checks.

For the time being, use macOS system strip at `/usr/bin/strip` which should be available (unlike Linux -> macOS cross where this is not guaranteed to be available, partially why we are shipping `llvm-objcopy` in the first place[^linux-darwin-cross]) that shouldn't have this offset problem.

### Review and testing advice

I don't have access to either macOS or iOS platforms, and I can't really write a test for this. This will need to be tested manually.

r? `@davidtwco` (or reroll)
cc *-apple-ios target maintainers `@badboy` `@deg4uss3r` `@madsmtm`

try-job: dist-apple-various
try-job: dist-x86_64-apple

[^linux-darwin-cross]: rust-lang#131206
@bors
Copy link
Collaborator

bors commented Mar 9, 2025

☀️ Try build successful - checks-actions
Build commit: 06d1077 (06d1077d5ba6da9a0b3b6b84e6f919ec600dc1b6)

Copy link
Contributor

@madsmtm madsmtm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine with this workaround (depending on how long llvm/llvm-project#130472 takes).

@TimNN
Copy link
Contributor

TimNN commented Mar 9, 2025

I can't really write a test for this. This will need to be tested manually.

Does CI run "macOS host, iOS target" run-make tests on CI? If so, we could check that dyld_info correctly parses the produced output files.

(Though I don't know if we actually want such a test, ideally we should be able to rely on strip / llvm-objcopy doing the right thing).

@jieyouxu jieyouxu changed the title [WIP] Use /usr/bin/strip on macOS -> iOS cross as a temporary mitigation [WIP] Use /usr/bin/strip on macOS -> iOS cross as a temporary workaround Mar 9, 2025
@jieyouxu
Copy link
Member Author

jieyouxu commented Mar 9, 2025

Does CI run "macOS host, iOS target" run-make tests on CI? If so, we could check that dyld_info correctly parses the produced output files.

(Though I don't know if we actually want such a test, ideally we should be able to rely on strip / llvm-objcopy doing the right thing).

I think we do run run-make tests on macOS-to-iOS, but I think we probably don't want to maintain our own strip test.

@jieyouxu jieyouxu changed the title [WIP] Use /usr/bin/strip on macOS -> iOS cross as a temporary workaround Use /usr/bin/strip on macOS -> iOS cross as a temporary workaround Mar 9, 2025
For <rust-lang#138212>.

Looks like LLVM 20's initial `llvm-objcopy` version that we
ship as `rust-objcopy` may be producing stripped iOS binaries with
invalid offsets that fail iOS platform consistency checks.

For the time being, use macOS system strip at `/usr/bin/strip` which
should be available (unlike Linux -> macOS cross where this is not
guaranteed to be available, partially why we are shipping `llvm-objcopy`
in the first place) that shouldn't have this offset problem.
@jieyouxu
Copy link
Member Author

jieyouxu commented Mar 9, 2025

This probably still needs someone with access to the native envs to try an end-to-end test to see if the resulting rustc can produce an iOS binary that doesn't immediately crash.

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Mar 9, 2025
@jieyouxu jieyouxu marked this pull request as ready for review March 9, 2025 17:03
@rustbot
Copy link
Collaborator

rustbot commented Mar 9, 2025

Some changes occurred in compiler/rustc_codegen_ssa

cc @WaffleLapkin

@jieyouxu
Copy link
Member Author

jieyouxu commented Mar 9, 2025

@bors try

bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 9, 2025
Use `/usr/bin/strip` on macOS -> iOS cross as a temporary workaround

Crude workaround for <rust-lang#138212> to unblock nightly macOS-to-iOS cross builds. This reintroduces the "hard-coded strip" workaround (but only for iOS) that was initially introduced in rust-lang#130781.

Looks like LLVM 20's initial `llvm-objcopy` version that we ship as `rust-objcopy` may be producing stripped iOS binaries with invalid offsets that fail iOS platform consistency checks.

For the time being, use macOS system strip when cross-compiling from macOS -> iOS at `/usr/bin/strip` which should be available (unlike Linux -> macOS cross where this is not guaranteed to be available, partially why we are shipping `llvm-objcopy` in the first place[^linux-darwin-cross]) that shouldn't have this offset problem.

### Alternatives

- We *could* also try to use a `strip` from PATH. *However*, that can regress iOS users if they have broken homebrew binutils strip in their PATH that take precedence over a "good" strip.
- We could also wait for upstream `llvm-objcopy` fixes.

### Review and testing advice

I don't have access to either macOS or iOS platforms, and I can't really write a test for this. This will need to be tested manually.

r? `@davidtwco` (or reroll)
cc *-apple-ios target maintainers `@badboy` `@deg4uss3r` `@madsmtm`

try-job: dist-apple-various
try-job: dist-x86_64-apple
try-job: dist-aarch64-apple

[^linux-darwin-cross]: rust-lang#131206
@bors
Copy link
Collaborator

bors commented Mar 9, 2025

⌛ Trying commit d88636f with merge d1f7fb3...

@bors
Copy link
Collaborator

bors commented Mar 9, 2025

☀️ Try build successful - checks-actions
Build commit: d1f7fb3 (d1f7fb3751190d6b1c8642ea402d066147d01e28)

@badboy
Copy link
Member

badboy commented Mar 9, 2025

This probably still needs someone with access to the native envs to try an end-to-end test to see if the resulting rustc can produce an iOS binary that doesn't immediately crash.

@rustbot ready

I'm back at work tomorrow and can probably take some time and get me a Rust build to try this.

@badboy
Copy link
Member

badboy commented Mar 10, 2025

I did build rustc with this patch. And dyld_info does now report things about compiled libraries for that target.
Unfortunately I have not been able to actually deploy that on an actual iOS device (between Xcode, my test phone and codesigning things just ... break). Our own app uses a static lib, so that wasn't affected to begin with.

@jieyouxu
Copy link
Member Author

No worries, thanks for trying anyway :D

@jieyouxu
Copy link
Member Author

Closing in favor of proper upstream fix #138695

@jieyouxu jieyouxu closed this Mar 19, 2025
@jieyouxu jieyouxu deleted the ios-mitigation branch March 19, 2025 09:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
O-ios Operating system: iOS O-macos Operating system: macOS S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants