Support for ARMv8.3+ targets
Absolucy opened this issue · comments
Currently, a blocker in a project of mine - Crabapple - is the lack of native arm64e support in Rust.
The aarch64-apple-ios
target only emits arm64 (ARMv8) code, which will not work within an arm64e (ARMv8.3+) environment due to it's lack of awareness of Pointer Authentication, leading to segfaults when trying to access a signed pointer.
It is currently possible to work around this, by using a backtrace=false rustc, compiling with --emit=llvm-ir -Clto
, and running the resulting IR through an arm64e-aware LLVM (such as apple/llvm-project). Pointer authentication may be worked around by linking to an FFI function that runs ptrauth_strip.
This may require LLVM changes if done, and quite possibly a new target (arm64e-apple-ios
, aarch64-apple-ios-armv83
, etc)
In addition, arm64e support important due to the upcoming Mac desktops running Bionic processors (such as an A12Z).
Upstream LLVM supports armv8.3, and most likely the Rust LLVM as well.
Upstream LLVM supports armv8.3, and most likely the Rust LLVM as well.
Weren't you working on building a custom LLVM since upstream doesn't support this yet? The link just goes to an RFC thread on the mailing list with no replies.
@jonas-schievink I was poorly attempting to jury-rig apple/llvm-project onto rustc. In short, I got arm64e and armv8.3 mixed up.
A quick grep and dig through rust-project/llvm reveals that it has the code for ARMv8.3 and Pointer Authentication support.
ARMv8.5 support would also be good, considering that there's a high likelihood than ARM Macs will run on ARMv8.5.
It is worth noting that the Rust LLVM branch has support for PAC (ARMv8.3) and BTI (ARMv8.5)
This isn't upstreamed, my bad.
Note that the macOS 11 SDK has both arm64-macos and arm64e-macos targets, although the arm64 variants don't have an uuid in the system library TBD files.
Upstream LLVM supports armv8.3, and most likely the Rust LLVM as well.
That's not merged in LLVM upstream.
I'm interested in this as well because of Apple Silicon (i.e arm64 on macOS)
Going forward it will be mandated by Apple that executable released (at least for the App Store) supports both x86_64
and amd64
target. On macOS there is "fat binary" support which makes it possible to have both targets in the same exe/obj/dylib etc file. Clang for example supports that you can have -arch x86_64
and -arch amd64
on the command line to generate the correct binary for this to work. Then the OS will load the correct version depending on the OS version running.
There is a command line tool called lipo
that can be used to combine two different compiles, but this (according to Apple) should only be used as a work-around and I think for Rust it would be better to support building for both targets at the same time.
We (Embark) are interested in it as well, should we track having a Darwin Mac on ARM target in this issue or file an additional one specifically for it (with some overlap with this)?
We'd need someone with a Developer Transition Kit to truly test any sort of support for this.
The aarch64-apple-ios
triple seems slightly ambiguous once there are arm64e targets as pointer-authentication would break unauthenticated environments. Given that arm64e-darwin is on its way, two new triples, aarch64e-apple-darwin
and aarch64e-apple-ios
, would probably make more sense?
Edit: sorry, this was a typo. I meant to write arm64e-apple-darwin
and arm64e-apple-ios
.
@Luxxxxy It's unfortunate that both arm64 and aarch64 refer to the same ISA, whereas the former was the result of proprietary work by Apple that only was open-sourced after other vendors published their work on the latter.
Aarch64 is an alias for the ARMv8-A ISA, and it would be confusing to have arm64e coexist with aarch64. But given that arm64e actually references a proprietary extension of the ARMv8-A ISA (it is actually an ABI), it might be reasonable to have it named in a way that clearly separates it from the other.
@Luxxxxy If one had such a device, would you be interested in testing something on it?
I have an arm64e phone (iPhone 11, iOS 13.5)
I'd be glad to test something on it, I've been using it to get rustc/cargo working on iOS.
I am currently adding PAC/arm64e to a fork using Apple's LLVM. Hopefully some of my work can be reused whenever PAC/arm64e support is upstreamed into LLVM.
that's work on jailbreak only?
that's work on jailbreak only?
That's how I'm testing it. However, most likely, this will also work on Apple Silicon (ARM) macs. Not sure if iOS lets you submit arm64e slice apps to the app store, though.
arm64e
is currently required when building kernel modules for macOS on Apple Silicon machines, but arm64e
binaries will not run in userspace (currently arm64
, or running x86_64
under Rosetta emulation is required).
@hjmallon Hello,
The arm64e ABI is currently not considered as final. To run arm64e binaries on macOS on Apple Silicon, add the -arm64e_preview_abi argument to boot-args.
Arm 64-bit macOS supports arm64 binaries, and that's the only supported configuration. Currently, arm64e is only for bundled in the OS applications and libraries, as you can load arm64e binaries in an arm64 process.
In some cases, the arm64e
arch might be "different". For example:
thread_set_state
might fail with(os/kern) protection failure
if we try to call it fromarm64
process toarm64e
process.- The returning value of
dlsym
is PAC signed onarm64e
, while left untouched onarm64
- Some function like
pthread_create_from_mach_thread
requires a PAC signed function pointer onarm64e
, which is not required onarm64
.
It seems that Apple just simply disables PAC on arm64 process to accomplish 2 and 3. However, case 1 can still not be covered if there is no arm64e target. I am not sure whether there is another case of ”cross arch“ interaction like case 1.
Any news on this?
Any progress on this issue?
What's missing after #115526 to have rustup target add arm64e-apple-ios
work out of the box? (IOW, what is missing for artifacts for these tier 3 targets to be available?)
@glandium It needs to be promoted to tier 2 AFAIK
I sent a MCP to do the promotion for arm64-darwin.
rust-lang/compiler-team#717
For what it's worth, LLVM doesn't support CPU_SUBTYPE_PTRAUTH_ABI yet, which is required by Xcode's linker to link arm64e code.