I compared two C functions returning a structure. We know that at the ABI level, large structures will follow the pointer as the first argument to the function.
struct S { int words[8]; }; struct S fsret() { struct S s; s.words[0] = 1; return s; } void fout(struct S* s) { s->words[0] = 1; }
For these functions, I checked the build for x86_64 Linux and Windows. fsret
declared as void @fsret(%struct.S* sret %s)
.
Comparing these two options, there is no difference on the side of the called party. However, inside functions, fsret
additionally copies its first argument (a pointer to a structure) into the RAX register. Why?
source share