Open
Description
I am compiling a dylib targeting arm64e for macos and ios. I am using the ctor crate (https://crates.io/crates/ctor) but also ruled that out by just using the expanded code (cargo expand).
my .cargo/config.toml (using xcode14 clang to allow linking arm64e):
[target.arm64e-apple-darwin]
rustflags = ["-C",
"linker=xcode14/test/CLTools_Executables.pkg/Library/Developer/CommandLineTools/usr/bin/gcc",
"-C",
"link-arg=-fuse-ld=xcode14/test/CLTools_Executables.pkg/Library/Developer/CommandLineTools/usr/bin/ld",
]
[target.arm64e-apple-ios]
rustflags = ["-C",
"linker=xcode14/test/CLTools_Executables.pkg/Library/Developer/CommandLineTools/usr/bin/gcc",
"-C",
"link-arg=-fuse-ld=xcode14/test/CLTools_Executables.pkg/Library/Developer/CommandLineTools/usr/bin/ld",
]
my lib.rs:
#[allow(unused)]
fn constructor() {
#[allow(unsafe_code)]
{
#[unsafe(link_section = "__DATA,__mod_init_func")]
#[used]
#[allow(non_upper_case_globals, non_snake_case)]
#[doc(hidden)]
static f: extern "C" fn() -> usize = {
#[allow(non_snake_case)]
extern "C" fn f() -> usize {
unsafe {
constructor();
0
}
}
f
};
}
{
println!("Hello from {}", "Rust");
hooks::init_hooks();
}
}
for macos i use: cargo +nightly build -Z build-std --target arm64e-apple-darwin
for ios i use: SDKROOT=~/Documents/ios_sdks/iPhoneOS16.0.sdk cargo +nightly build -Z build-std --target arm64e-apple-ios
when compiling this code for ios i get the error with a clean build:
clang: warning: using sysroot for 'iPhoneOS' but targeting 'MacOSX' [-Wincompatible-sysroot]
ld: building for 'macOS', but linking in dylib (iPhoneOS16.0.sdk/usr/lib/libiconv.2.tbd) built for 'iOS'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
This error seems like something is confused and wants to build macos?
building macos then ios:
= note: some arguments are omitted. use `--verbose` to show all linker arguments
= note: ld: warning: object file built with an incompatible arm64e ABI: '/var/folders/9w/ghpc5vj54l3684jktj8vtkm00000gn/T/rustcnBeHtH/symbols.o'
ld: warning: object file built with an incompatible arm64e ABI: 'Documents/repos/alloc_tracker/target/arm64e-apple-ios/debug/deps/alloc_tracker.5gd9524b65p18ksle2rao8sny.rcgu.rmeta'
ld: reference to symbol (which has not been assigned an address) __ZN13alloc_tracker11constructor1f17hf2d8c9917faf02bfE for architecture arm64e
clang: error: linker command failed with exit code 1 (use -v to see invocation)
This error just seems like the symbol for the constructor is getting removed
Meta
rustc --version --verbose
:
cargo 1.88.0-nightly (a6c604d1b 2025-03-26)
release: 1.88.0-nightly
commit-hash: a6c604d1b8a2f2a8ff1f3ba6092f9fda42f4b7e9
commit-date: 2025-03-26
host: aarch64-apple-darwin
libgit2: 1.9.0 (sys:0.20.0 vendored)
libcurl: 8.7.1 (sys:0.4.80+curl-8.12.1 system ssl:(SecureTransport) LibreSSL/3.3.6)
ssl: OpenSSL 3.4.1 11 Feb 2025
os: Mac OS 15.3.1 [64-bit]
Metadata
Metadata
Assignees
Labels
Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.Area: linking into static, shared libraries and binariesCategory: This is a bug.Armv8-A or later processors in AArch64 modeOperating system: Apple (macOS, iOS, tvOS, visionOS, watchOS)Operating system: iOS