[问题] 呼叫gets前的sub $0xc,%esp

楼主: GNUGCC (-std=c++14)   2016-07-28 14:50:28
小弟最近在练习看组语,遇到问题想来请教各位
这是source code
#include <stdlib.h>
#include <stdio.h>
void print(){
char buf[5];
gets(buf);
}
int main(){
print();
}
这是在
ubuntu 16.04 amd64

gcc -fno-stack-protector -m32 -O0 test.c
编译出来的结果
0804840b <print>:
804840b: 55 push %ebp
804840c: 89 e5 mov %esp,%ebp
804840e: 83 ec 18 sub $0x18,%esp <=为啥预留24 bytes
8048411: 83 ec 0c sub $0xc,%esp <=为啥要减12
8048414: 8d 45 f3 lea -0xd(%ebp),%eax
8048417: 50 push %eax
8048418: e8 c3 fe ff ff call 80482e0 <[email protected]/*
楼主: GNUGCC (-std=c++14)   2016-07-28 15:53:00
在C_and_CPP得到解答了 原因是gcc的stack boundaryhttp://goo.gl/vNJXig
继续阅读

Links booklink

Contact Us: admin [ a t ] ucptt.com