Code: Select all
#include <stdint-gcc.h>
typedef struct {
uint32_t lolz;
uint32_t loler;
} teststruct;
teststruct returnval;
teststruct thetestfunction(void ) {
returnval.lolz = 4;
returnval.loler = 8;
return returnval;
};
Then disassembled it, so the thetestfunction looked like this:
Code: Select all
00000000 <thetestfunction>:
0: 8b 44 24 04 mov 0x4(%esp),%eax
4: c7 05 00 00 00 00 04 movl $0x4,0x0
b: 00 00 00
e: c7 05 04 00 00 00 08 movl $0x8,0x4
15: 00 00 00
18: 8b 15 00 00 00 00 mov 0x0,%edx
1e: 8b 0d 04 00 00 00 mov 0x4,%ecx
24: 89 10 mov %edx,(%eax)
26: 89 48 04 mov %ecx,0x4(%eax)
29: c2 04 00 ret $0x4
So apparently space is created on the stack right below the returning address. However, I am left scratching my head at the "ret $0x4" instruction; why does it need to clean up 32 bits on the stack? Is this even part of the "System V" ABI or is it just dependent on how GCC does it? I'm going to look.