RFR: 8263512: [macos_aarch64] issues with calling va_args functions from invoke_native

Maurizio Cimadamore mcimadamore at openjdk.java.net
Mon Apr 26 14:33:27 UTC 2021

On Thu, 22 Apr 2021 08:19:53 GMT, Nick Gasson <ngasson at openjdk.org> wrote:

> macOS on Apple silicon uses slightly different ABI conventions to the
> standard AArch64 ABI.  The differences are outlined in [1].  In
> particular in the standard (AAPCS) ABI, variadic arguments may be passed
> in either registers or on the stack following the normal calling
> convention.  To handle this, va_list is a struct containing separate
> pointers for arguments located in integer registers, floating point
> registers, and on the stack.  Apple's ABI simplifies this by passing all
> variadic arguments on the stack and the va_list type becomes a simple
> char* pointer.
> This patch adds a new MacOsAArch64 CABI type and MacOsAArch64Linker to
> represent the new ABI variant on macOS.  StackVaList is based on
> WinVaList lightly modified to handle the different TypeClasses on
> AArch64.  The original AArch64Linker is renamed to AapcsLinker and is
> currently used for all non-Mac platforms.  I think we also need to add a
> WinAArch64 CABI but I haven't yet been able to test on a Windows system
> so will do that later.
> The macOS ABI also uses a different method of spilling arguments to the
> stack (the standard ABI pads each argument to a multiple of 8 byte stack
> slots, but the Mac ABI packs arguments according to their natural
> alignment).  None of the existing tests exercise this so I'll open a new
> JBS issue and work on that separately.
> Tested jdk_foreign on macOS AArch64, Linux AArch64, and Linux X86_64.
> [1] https://developer.apple.com/documentation/xcode/writing_arm64_code_for_apple_platforms

I'll leave fine details to @JornVernee  - high level bits seem correct. I think we should be more transparent in e.g. enum constant on the fact that AArch64 really means linux - and perhaps use Arm64 instead of AArch64.

src/jdk.incubator.foreign/share/classes/jdk/internal/foreign/CABI.java line 35:

> 33:     SysV,
> 34:     Win64,
> 35:     AArch64,

This should be Linux AArch64. Btw, should we use Arm64 instead, which seems to be the more common name to refer to the platform?

src/jdk.incubator.foreign/share/classes/jdk/internal/foreign/abi/aarch64/aapcs/AapcsLinker.java line 50:

> 48:  * the ARM 64-bit Architecture".
> 49:  */
> 50: public class AapcsLinker implements CLinker {

I see why it's called like that - but this is really either AArch64Linker or Arm64Linker. E.g. the platform standard one.

src/jdk.incubator.foreign/share/classes/jdk/internal/foreign/abi/aarch64/aapcs/AapcsVaList.java line 54:

> 52:  * Linux. Variadic parameters may be passed in registers or on the stack.
> 53:  */
> 54: public class AapcsVaList implements VaList {

Same here - not sure I like Aapcs much


PR: https://git.openjdk.java.net/jdk/pull/3617

More information about the core-libs-dev mailing list