rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
97k stars 12.54k forks source link

Support for ARMv8.3+ targets #73628

Open Absolucy opened 4 years ago

Absolucy commented 4 years ago

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)

Absolucy commented 4 years ago

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

Absolucy commented 4 years ago

Upstream LLVM supports armv8.3, and most likely the Rust LLVM as well.

jonas-schievink commented 4 years ago

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.

Absolucy commented 4 years ago

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

Absolucy commented 4 years ago

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

Absolucy commented 4 years ago

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.

glandium commented 4 years ago

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.

glandium commented 4 years ago

Upstream LLVM supports armv8.3, and most likely the Rust LLVM as well.

That's not merged in LLVM upstream.

Absolucy commented 4 years ago

@glandium my bad.

emoon commented 4 years ago

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.

repi commented 4 years ago

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

Absolucy commented 4 years ago

We'd need someone with a Developer Transition Kit to truly test any sort of support for this.

19h commented 4 years ago

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.

Absolucy commented 4 years ago

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

19h commented 4 years ago

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

ttimpe commented 4 years ago

@luxxxxy If one had such a device, would you be interested in testing something on it?

Absolucy commented 4 years ago

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.

Absolucy commented 4 years ago

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.

ghost commented 4 years ago

that's work on jailbreak only?

Absolucy commented 4 years ago

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.

hjmallon commented 4 years ago

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

woachk commented 3 years ago

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

pwn0rz commented 3 years ago

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.

Absolucy commented 3 years ago

I believe that we may see proper PAC support soon, with https://github.com/rust-lang/rust/pull/88354

aviramha commented 2 years ago

Any news on this?

sierkb commented 1 year ago

Any progress on this issue?

glandium commented 8 months ago

What's missing after https://github.com/rust-lang/rust/pull/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?)

aviramha commented 7 months ago

@glandium It needs to be promoted to tier 2 AFAIK

aviramha commented 7 months ago

I sent a MCP to do the promotion for arm64-darwin. https://github.com/rust-lang/compiler-team/issues/717

glandium commented 7 months ago

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.