I've been having a look at the assembly code GCC generates when it finds a call to function that is supposed to return a C struct:
Code: Select all
struct st_foo function(void);
struct st_foo foo;
foo = function();
So far, so good. My question comes up when I observe how the stack is cleaned up:
The callee cleans up the stack by providing assembly instruction ret with an immediate operand which specifies the numbers of bytes to be removed from the stack before returning. However, I expected the caller to clean up the stack, not the callee.
Isn't GCC using the cdecl calling convention?
Isn't then the callee the one responsilbe for cleaning up the stack?
What wrong assumption am I making?
Thanks in advance