Windows ARM64EC support

Hi Rust team,

Microsoft has just announced ARM64EC - a new binary format that carries ARM64 native code but has x64 ABI, thus allowing ARM64 native binaries reference x64 emulated ones. (that's my understanding :grimacing:)

I'd like to ask, does rustc need a new toolchain to support ARM64EC, or is it possible to use the existing aarch64-pc-windows-msvc toolchain?

If it needs a new toolchain, I would like to help build it. Are there any resources on adding a new toolchain to the compiler?


In theory, it'd be possible to have an extern "arm64ec" fn the same way we have extern "stdcall" fn. We don't have to have a separate target for calling functions differently.

However, if this changes the required signature of extern "C", or the required signature or calling convention of the program entry point, or the sizes or alignments of types, it'd probably be easiest to use a new target.

I would guess it does. As far as I understand ARM64EC is basically the x86_64 abi for windows changed to use aarch64 registers instead. It uses the same type and stack layouts.

It may also be necessary to mark the object files as targeting the ARM64EC abi to allow windows to link it (statically or dynamically) with x86_64 code.

I don't know much about how it's implemented but from my understanding there is no new calling convention (please pardon my ignorance):

Specifically, the ARM64EC ABI follows x64 software conventions including calling convention, stack usage, and data alignment, making ARM64EC and x64 interoperable.

This is implemented, apparently, by a single compiler flag which is /MACHINE:ARM64EC. I don't know the specifics of this magic but it's aimed at developers who would like to gradually migrate their code to support arm64, thus allowing them (us) to keep using x64 libraries from arm64 code without changing those x64 libraries (as far as I understand).

Thus I don't think there is a need for a new calling convention in Rust but rather a toolchain that passes necessary flags to the compiler. The question is - is there a need for a new toolchain at all? :thinking:

There is. On AArch64 normally the AArch64 calling convention is used. What ARM64EC does is instead take the calling convention from x86_64 and remap it onto AArch64 registers. This is fundamentally incompatible with the AArch64 calling convention, but makes translation of x86_64 code to this calling convention trivial.

The compiler flag causes a different calling convention to be used and likely a different object file architecture specification or something like that. The latter prevents ARM64 and ARM64EC code from being linked against each other, so it has to be a new target triple.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.