rust-lang / rust

Empowering everyone to build reliable and efficient software.

Home Page:https://www.rust-lang.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support for ARMv8.3+ targets

Absolucy opened this issue · comments

commented

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)

commented

In addition, arm64e support important due to the upcoming Mac desktops running Bionic processors (such as an A12Z).

commented

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.

commented

@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.

commented

ARMv8.5 support would also be good, considering that there's a high likelihood than ARM Macs will run on ARMv8.5.

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.

commented

@glandium my bad.

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)?

commented

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.

commented

@19h aarch64e would be ENTIRELY inaccurate of a name.

@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?

commented

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.

commented

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?

commented

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:

  1. thread_set_state might fail with (os/kern) protection failure if we try to call it from arm64 process to arm64e process.
  2. The returning value of dlsym is PAC signed on arm64e, while left untouched on arm64
  3. Some function like pthread_create_from_mach_thread requires a PAC signed function pointer on arm64e, which is not required on arm64.

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.

commented

I believe that we may see proper PAC support soon, with #88354

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.