Specifically in the context of the SysV x86-64 ABI
If I have a struct with only two fields, such as:
typedef struct {
void *foo;
void *bar;
} foobar_t;
And I pass it to a function with a definition like so:
foobar_t example_function(foobar_t example_param);
The ABI seems to say that each eightbyte field should be passed as INTEGER
to the function, therefore rdi == foo
and rsi == bar
. Similarly, when returning we should be able to use rax
and rdx
, since we don't need a memory pointer in rdi
. If example_function
is trivially defined as:
foobar_t example_function(foobar_t example_param) {
return example_param;
}
A valid assembly implementation, ignoring prologue and epilogue, would be:
example_function:
mov rax, rdi
mov rdx, rsi
ret
Conceivably, a mentally-deficient compiler could fill the struct with NO_CLASS
padding and make that assembly invalid somehow. I'm wondering if it's written down anywhere that a struct with only two eightbyte fields must be handled this way.
The larger context to my question is that I'm writing a simple C11 task switcher for my own edification. I'm basing it largely on boost.context and this is exactly how boost passes two-field structs around. I want to know if it's kosher under all circumstances or if boost is cheating a little.