Through debug,I found that when func called in main,RSP is decreased by 8 from 0x7fffffffe960 to 0x7fffffffe958:
(gdb) disas func
Dump of assembler code for function func:
0x0000000000400448 <func+0>: push %rbp
0x0000000000400449 <func+1>: mov %rsp,%rbp
0x000000000040044c <func+4>: mov $0x1,%eax
0x0000000000400451 <func+9>: leaveq
0x0000000000400452 <func+10>: retq
End of assembler dump.
(gdb) disas main
Dump of assembler code for function main:
0x0000000000400453 <main+0>: push %rbp
0x0000000000400454 <main+1>: mov %rsp,%rbp
0x0000000000400457 <main+4>: callq 0x400448 <func>
0x000000000040045c <main+9>: mov $0x6,%eax
0x0000000000400461 <main+14>: leaveq
0x0000000000400462 <main+15>: retq
Why calla func will make rsp decrease by 8?
UPDATE
(gdb) x/4x 0x7fffffffe960
0x7fffffffe960: 0x00000000 0x00000000 0xf401d994 0x00000034
It's because the return addresses are also 64 bits in size (eg. 0x0000000000400457). When you call func, that value is placed onto the stack and the stack pointer decremented by that amount.
User contributions licensed under CC BY-SA 3.0