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 does not invoke ld with appropriate -target for linking a mac catalyst binary #80202

Closed
visigoth opened this issue Dec 19, 2020 · 1 comment · Fixed by #80215
Closed
Labels
A-linkage Area: linking into static, shared libraries and binaries C-bug Category: This is a bug. O-ios Operating system: iOS O-macos Operating system: macOS T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@visigoth
Copy link
Contributor

visigoth commented Dec 19, 2020

I am trying to build a Mac Catalyst binary with rust. The compiler supports the x86_64-apple-ios-macabi target, but rustc does not invoke ld correctly. Note that I am building with xargo because I need to cross-compile core and std for the target triple myself (as Mac Catalyst is tier 3 iirc).

I have the simplest possible project hosted here: https://github.com/visigoth/catalystsample

When running xargo build --target x86_64-apple-ios-macabi, rustc eventually invokes cc like this to link the binary. Note that the invocation of rustc has -target x86_64-apple-ios-macabi in it, while cc is invoked with -arch x86_64:

     Running `rustc --crate-name catalystsample --edition=2018 src/main.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type bin --emit=dep-info,link -C panic=abort -C embed-bitcode=no -C debuginfo=2 -C metadata=720d334a6f1e8087 --out-dir /Users/shaheen/code/catalystsample/target/x86_64-apple-ios-macabi/debug/deps --target x86_64-apple-ios-macabi -C incremental=/Users/shaheen/code/catalystsample/target/x86_64-apple-ios-macabi/debug/incremental -L dependency=/Users/shaheen/code/catalystsample/target/x86_64-apple-ios-macabi/debug/deps -L dependency=/Users/shaheen/code/catalystsample/target/debug/deps --sysroot /Users/shaheen/.xargo`
error: linking with `cc` failed: exit code: 1
  |
  = note: "cc" "-arch" "x86_64" "-isysroot" "/Applications/Xcode_12.2.0_beta_4_fb.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.0.sdk" "-Wl,-syslibroot" "/Applications/Xcode_12.2.0_beta_4_fb.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.0.sdk" "-L" "/Users/shaheen/.xargo/lib/rustlib/x86_64-apple-ios-macabi/lib" ...

The important part is how cc is invoked: cc -arch x86_64. This fails with ld: building for macOS, but linking in object file built for Mac Catalyst, file ....

If I simply change cc -arch x86_64 to cc -target x86_64-apple-ios-macabi and run the command manually, the binary links and runs successfully.

@camelid camelid added A-linkage Area: linking into static, shared libraries and binaries O-macos Operating system: macOS C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. O-ios Operating system: iOS labels Dec 20, 2020
@visigoth
Copy link
Contributor Author

I have simplified my sample repository. It no longer uses xargo to build. Instead, -Z build-std is used. The bug still repros.

Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Jan 28, 2021
Use -target when linking binaries for Mac Catalyst

When running `rustc` with `-target x86_64-apple-ios-macabi`, the linker
eventually gets run with `-arch x86_64`, because the linker back end splits the
LLVM target triple and uses the first token as the target architecture. However,
this does not work for the Mac Catalyst ABI, which is a separate target from
Darwin.

Specifying the full target triple with `-target` allows Mac Catalyst binaries to
link and run.

closes rust-lang#80202
@bors bors closed this as completed in a3c060c Jan 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-linkage Area: linking into static, shared libraries and binaries C-bug Category: This is a bug. O-ios Operating system: iOS O-macos Operating system: macOS 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.

2 participants