简体   繁体   English

为什么GCC会分配不使用的堆栈空间?

[英]Why does GCC allocate stack space that it does not use?

In many functions the function prologue starts with sub $0x1c,%esp , which is later removed by add $0x1c,%esp . 在许多函数中,函数序言sub $0x1c,%esp开头,随后通过add $0x1c,%esp删除。 The function can be as simple as doing virtually nothing. 该功能几乎可以像什么都不做一样简单。 This space is never used however, and has become an annoyance to work with as I need full control over the stack of my functions. 但是,这个空间从未使用过,并且由于我需要完全控制我的函数堆栈而变得烦恼。 Any idea what causes this, and how can I remove it? 知道是什么原因造成的,如何删除? I'm compiling with -O2 -Wall -c -m32 -fno-stack-protector -fno-defer-pop -fno-builtin -march=i386 . 我正在使用-O2 -Wall -c -m32 -fno-stack-protector -fno-defer-pop -fno-builtin -march=i386编译。

It would help to see more code but it's to do with stack alignment. 这将有助于查看更多代码,但这与堆栈对齐有关。 You can mess around with this in GCC using -mpreferred-stack-boundary. 您可以在GCC中使用-mpreferred-stack-boundary解决这个问题。 The default on my machine is 4 so things are aligned to 16 bytes. 我的机器上的默认值为4,因此所有内容都对齐为16个字节。 I'm pretty confident this has nothing to do with stack protection. 我非常有信心,这与堆栈保护无关。 To see what happens with stack protection compile the program with -fno-stack-check and -fstack-check and diff the results. 要查看堆栈保护的情况,请使用-fno-stack-check和-fstack-check编译程序并比较结果。 You'll see something like 您会看到类似

>   orl $0, -12300(%esp)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM