[PATCH] D125412: [ARM64EC 2/?] Add target triple, and allow targeting it.

Daniel Paoliello via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue May 31 14:07:03 PDT 2022


dpaoliello added a comment.

> Veering slightly offtopic here, but - I'm curious - is it possible to link in regular aarch64 object files in an arm64ec executable (for functions where the calling convention doesn't differ from regular aarch64)? Those object files would only ever be called from arm64ec code (not from x86_64), so I wonder if it would work without all the thunks that are present in arm64ec object files. (In particular, the case I have in mind is cases with handwritten aarch64 assembly.) Would it be possible to mark such functions with a calling convention attribute on the C level, to let the compiler generate code for calling regular aarch64 functions?

Caveat: I'm not an expert in this area, but this is my understanding of the docs: https://docs.microsoft.com/en-us/windows/arm/arm64ec-abi.

It's not a good idea to mix Arm64EC and normal AArch64:

- The set of registers that Arm64EC uses is restricted to those that can be mapped to x86_64 <https://docs.microsoft.com/en-us/windows/arm/arm64ec-abi#register-mapping-and-blocked-registers>, this allows the Windows Kernel to capture them in an x86_64-compatible `CONTEXT` object (in case x86_64 code wants to inspect that context). So, if you are running normal AArch64 code and the kernel has to save off and then restore your context, the non-mapped registers' values may be lost.
- The variadic calling convention is different: https://docs.microsoft.com/en-us/windows/arm/arm64ec-abi#variadic-calling-convention.
- If your function accepts a function pointer, how does it know if it is an AArch64 or x86_64 function? Hence call checkers are mandatory: https://docs.microsoft.com/en-us/windows/arm/arm64ec-abi#call-checkers.
- There's also differences with the stack and security cookie checkers: https://docs.microsoft.com/en-us/windows/arm/arm64ec-abi#stack-checkers.

But, if you're hand-coding assembly, you could avoid the cases above (i.e., restrict the registers you use, avoid variadic functions, avoid indirect calls, avoid stack checks and avoid security cookie checks) to create assembly code that is usable in both Arm64EC and normal AArch64 contexts.

As for the thunks:

- You only require Exit Thunks for code that *might* be calling to x86_64 code. If you statically know that all of the functions that your code calls are AArch64, then Exit Thunks are not required.
- Same goes for the Entry Thunks: if you statically know that the only functions that call your code are AArch64, then Entry Thunks are not required.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D125412/new/

https://reviews.llvm.org/D125412



More information about the llvm-commits mailing list