-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Mac Catalyst (macabi) target objects fail to link #106021
Comments
Thanks for the report, I can probably take this over (but not until after the new year). |
Hello @thomcc ! Any hint on this bug? I'm pretty new to LLVM/Rust compiler. If I could have some hint, I may start a draft PR in https://github.com/gimli-rs/object first. |
I see the same error when build for both
If I change it to |
I got a workaround for this problem using I was not able to update my my Catalyst app due to this issue for over half a year. Going to use it. brew install mold
which mold
[target.aarch64-apple-ios-macabi]
linker = "/usr/bin/clang"
rustflags = ["-C", "link-arg=--ld-path=/opt/homebrew/bin/mold"] Background:
|
Please note that mold linker does not work for iOS or macOS. We need a commercial license for that. When build my app end-to-end, there's still a linker error: Sorry, but I decided to stop working for the Mac Catalyst platform. |
For those of us wishing to ship Rust code in Mac Catalyst apps, this thread remains very interesting and relevant :) I would encourage you to keep pulling on the thread, but if you've determined it's not worth the effort, I'd appreciate someone else experienced in the Dark Arts picking this up. |
Sorry for the delay here. |
It's unclear if it's related or not but in LaurentMazare/tch-rs#660 when doing a clean build for
In this case, |
This might be a separate issue looking at timing but since after the nightly 2023-02-02 I can't build Catalyst output and bundle it into xcframework. |
Hello @thomcc, thanks for your help to kick off the first step. Last night, I was trying to patch the Rust compiler according to @ara4n's GH gist. However, I found we could not initialize
--- a/compiler/rustc_codegen_ssa/src/back/metadata.rs
+++ b/compiler/rustc_codegen_ssa/src/back/metadata.rs
@@ -140,6 +140,14 @@ pub(crate) fn create_object_file(sess: &Session) -> Option<write::Object<'static
};
let mut file = write::Object::new(binary_format, architecture, endianness);
+ if sess.target.llvm_target.ends_with("-macabi") {
+ let version = write::MachOBuildVersion {
+ platform: object::macho::PLATFORM_MACCATALYST,
+ minos: 0x000E0000,
+ sdk: 0x00100200,
+ };
+ file.set_macho_build_version(version);
+ }
let e_flags = match architecture {
Architecture::Mips => {
let arch = match sess.target.options.cpu.as_ref() { May I have some hints about how to initialize a I was just trying it on my own. Please feel free to do it if you have the bandwidth. Thanks! |
You should be able use |
@philipc thanks! updated the lib
https://github.com/imWildCat/rust/pull/1/files Not sure about how to fix it. May I have some hint please? Thanks! |
That's due to mixing different versions of the |
Issue rust-lang#106021 Apple LD requires build versions in object files for Catalyst
…henkov Fix linking Mac Catalyst by including LC_BUILD_VERSION in object files Hello. My first rustc PR! Issue rust-lang#106021 prevents Rust code from being linked into Mac Catalyst applications. Apple's LD has started requiring object files to contain version information about the platform they were built for, such as: * the "deployment target" (minimum supported OS version), * the SDK version * the type of the platform (macOS/iOS/catalyst/tvOS/watchOS all have a different number). This is currently only enforced when building for Mac Catalyst. Rust uses the `object` crate which added support for including this information starting with `0.31.0`. ~~I upgraded it along with `thorin-dwp` so that everything depends on 0.31. Apparently 0.31 [pulls in](gimli-rs/object#463) `ruzstd` due to a [new ELF standard](https://maskray.me/blog/2022-09-09-zstd-compressed-debug-sections) because its `compression` feature is enabled by thorin. If you find this objectionable, let me know what the best way to avoid pulling in those dependencies might be.~~ **(`object` upgraded in rust-lang#111413 I then added two commits: * The first one adds very basic, hard-coded support for calling `set_macho_build_version` for `-macabi` (Catalyst) targets, where it claims deployment target of Catalyst 14.0 and SDK of 16.2. * The second weaves the versioning through `rust_target::spec::TargetOptions`, so that we can stick to specifying all target-related info in one place. Kudos to `@ara4n` for writing [this gist](https://gist.github.com/ara4n/320a53ea768aba51afad4c9ed2168536).
…henkov Fix linking Mac Catalyst by including LC_BUILD_VERSION in object files Hello. My first rustc PR! Issue rust-lang#106021 prevents Rust code from being linked into Mac Catalyst applications. Apple's LD has started requiring object files to contain version information about the platform they were built for, such as: * the "deployment target" (minimum supported OS version), * the SDK version * the type of the platform (macOS/iOS/catalyst/tvOS/watchOS all have a different number). This is currently only enforced when building for Mac Catalyst. Rust uses the `object` crate which added support for including this information starting with `0.31.0`. ~~I upgraded it along with `thorin-dwp` so that everything depends on 0.31. Apparently 0.31 [pulls in](gimli-rs/object#463) `ruzstd` due to a [new ELF standard](https://maskray.me/blog/2022-09-09-zstd-compressed-debug-sections) because its `compression` feature is enabled by thorin. If you find this objectionable, let me know what the best way to avoid pulling in those dependencies might be.~~ **(`object` upgraded in rust-lang#111413 I then added two commits: * The first one adds very basic, hard-coded support for calling `set_macho_build_version` for `-macabi` (Catalyst) targets, where it claims deployment target of Catalyst 14.0 and SDK of 16.2. * The second weaves the versioning through `rust_target::spec::TargetOptions`, so that we can stick to specifying all target-related info in one place. Kudos to `@ara4n` for writing [this gist](https://gist.github.com/ara4n/320a53ea768aba51afad4c9ed2168536).
…henkov Fix linking Mac Catalyst by including LC_BUILD_VERSION in object files Hello. My first rustc PR! Issue rust-lang#106021 prevents Rust code from being linked into Mac Catalyst applications. Apple's LD has started requiring object files to contain version information about the platform they were built for, such as: * the "deployment target" (minimum supported OS version), * the SDK version * the type of the platform (macOS/iOS/catalyst/tvOS/watchOS all have a different number). This is currently only enforced when building for Mac Catalyst. Rust uses the `object` crate which added support for including this information starting with `0.31.0`. ~~I upgraded it along with `thorin-dwp` so that everything depends on 0.31. Apparently 0.31 [pulls in](gimli-rs/object#463) `ruzstd` due to a [new ELF standard](https://maskray.me/blog/2022-09-09-zstd-compressed-debug-sections) because its `compression` feature is enabled by thorin. If you find this objectionable, let me know what the best way to avoid pulling in those dependencies might be.~~ **(`object` upgraded in rust-lang#111413 I then added two commits: * The first one adds very basic, hard-coded support for calling `set_macho_build_version` for `-macabi` (Catalyst) targets, where it claims deployment target of Catalyst 14.0 and SDK of 16.2. * The second weaves the versioning through `rust_target::spec::TargetOptions`, so that we can stick to specifying all target-related info in one place. Kudos to ``@ara4n`` for writing [this gist](https://gist.github.com/ara4n/320a53ea768aba51afad4c9ed2168536).
This worked for me. Hopefully we can get this fixed in latest Rust. |
Should be fixed since #111384 is merged and released with Rust 1.71. Okay to close? |
Agreed. |
If you attempt to build a library for Mac Catalyst (target
aarch64-apple-ios-macabi
) on current nightly on Ventura (13.1), it fails to link with errors like:ld: in /Users/matthew/workspace/matrix-rust-sdk/target/aarch64-apple-ios-macabi/dbg/deps/libstatic_assertions-fdafb4b8ba800a8a.rlib(lib.rmeta), building for Mac Catalyst, but linking in object file built for , file '/Users/matthew/workspace/matrix-rust-sdk/target/aarch64-apple-ios-macabi/dbg/deps/libstatic_assertions-fdafb4b8ba800a8a.rlib' for architecture arm64
This is because the synthetic Mach-O object files (symbols.o and lib.rmeta) emitted by
object
lack LC_BUILD_VERSION load commands to identify them as compatible with Catalyst, so ld complains they have a blank platform: "linking in object file built for ,".rustc uses gimli's
object
to write these object files, soobject
needs to be extended to support writing LC_BUILD_VERSION, and then rustc needs to be fixed to write it when building for Catalyst.I hacked this together as per https://gist.github.com/ara4n/320a53ea768aba51afad4c9ed2168536, but a) this is the first time i've written any rust, b) turns out i don't need Catalyst after all, c) i'm not sure the changes to
object
have the right abstractions, d) I don't have bandwidth to land it. So am opening this issue as a breadcrumb trail in the hope someone else finds it useful and can finish it off.The text was updated successfully, but these errors were encountered: