Add support for the AAPCS64 calling convention#1468
Add support for the AAPCS64 calling convention#1468bakpakin merged 1 commit intojanet-lang:masterfrom SyrupThinker:st/aarch64_ffi
Conversation
|
Wow, thanks so much @SyrupThinker , I had been procastinating on adding AARCH64 support to FFI for a while, this is very helpful! By my naive understanding, aarch64 ABIs are much more uniform than the x86 world, with macos only slightly different than linux and windows. I have an old raspberry pi 2 or 3 somewhere that I should be able to test on "real" hardware, although I think QEMU should be fairly representative for this use. |
@bakpakin's understanding matches mine, sans one blind spot: the register that holds the syscall number. I don't recall seeing this specified in the Arm ABI docs. I know Linux uses x8, but I have a vague idea that FreeBSD uses something different? I'd check but it's buried in the source and I can't recall what file it's in. Then again, maybe FFI doesn't touch it, so it doesn't matter. |
FreeBSD (and iirc, all BSD that has support for aarch64) uses |
|
May be this line in the mentioned file is of interest. |
This change adds support for the AAPCS64 calling convention, targeting Linux and macOS AARCH64 systems.
This was developed on a macOS target, which has "looser", Apple specific, alignment requirements than the base standard used by Linux.
Support for the latter has only been tested against a QEMU VM running Arch Linux ARM, so tests against actual hardware would be appreciated.
In general my use-case is pretty simple, so there might be bugs with more complex function signatures. I've added two tests for stack spilling and alignment differences to at least catch rudimentary errors here, but again, tests against more complex libraries would be appreciated.
Reading over the Windows Overview of ARM64 ABI conventions suggests, that there are no relevant modifications to the base convention as with Linux. Thus this change might be compatible with Windows as well. I did not enable it for Windows as I could not test this.
Small example of a Raylib binding running on macOS (M1)
main.janet
stav/ffi/raylib.janet