[llvm-dev] Calling conventions on x86

Christoffer Lernö via llvm-dev llvm-dev at lists.llvm.org
Mon Oct 26 07:23:02 PDT 2020


Implementing C ABI calling conventions turns out to be difficult – not that all platforms are hard, it’s just that it’s difficult making sure you’re actually covering all the cases.
I would love for it to be some good and concise reading on what I need to do in the frontend to lower the calls to conform to the C ABI (and variants). I’ve dug a bit into AARCH64 and System V AMD 64, but it’s really really hard to get some solid information. I was going to do x86, but then I discovered that unlike what the documentation on x85 tells me, Clang is actually lowering structs to its components – in certain cases – but if I understand correctly x86 would always place these things on the stack anyway, so there’s strictly no different to the x86 ABI if you pass a struct with two ints, or if you pass two int parameters. And yet Clang lowers them differently, which results in different LLVM IR and – without optimization – pretty different assembler, but with -O1 they’re identical.

In addition to that I’ve been looking at the alignment across platforms for various types. Some things seem odd and I’d like to know whether those are LLVM bugs or actually correct:

1. On AARCH64, all OS’s except Apples and Microsoft has a minimum preferred alignment of 32 bits. For Microsoft and Apple they instead match the ABI alignment
2. On AARCH64_32, all OS’s have 64 bit pointers, except for Apple & MS that has 32.
3. On 32 bit ARM, netbsd & Apple OS’s have a max required alignment of 32, for the rest it is the same as the type size, so 64 bit ints are 64 bit aligned and so on.
4. On 32 bit ARMEB, only netbsd has the behaviour mentioned in (3)
5. For PowerPC64, only the PS3 (Lv2) use 32 bit pointers.
6. For x64, elfiamcu surprisingly has a 32 bit alignment and preferred alignment of 128 bit floats. However, 64 bit floats are 64 bit aligned…
7. I was unable to find any working triple for a bunch of architectures: arc, avr, le32, le64 etc etc.

Are the above correct – or results of processor X not in use for other operating systems etc?

Christoffer
AEGIK / www.aegik.se



More information about the llvm-dev mailing list