The mess that is handling structure arguments and returns in LLVM

submited by
Style Pass
2025-01-16 02:00:06

A feature scheduled to be released in Inko 0.18.0 is the ability to define types to allocate on the stack instead of on the heap:

This also meant adding support for passing such values as arguments, capturing them in closures, and returning them. This turned out to be a lot more complicated than anticipated, as the way LLVM handles structure arguments and returns in regards to the system ABI is surprising at best, and downright terrible at worst. Let's take a look at why that is.

Within the context of this article, "ABI" refers to the system ABI (Application Binary Interface). In essence, the ABI is a specification that states how values should be passed around (i.e. what registers to place the data in), how to call functions, who (the caller or callee) is supposed to clean up certain registers when returning from a function, and so on.

Two examples of an ABI are the SystemV AMD64 ABI and the ARM ABI (well technically there are many ARM ABIs, but you get the point).

Leave a Comment