为什么GCC将帧指针放在64位上? [英] Why does GCC drop the frame pointer on 64-bit?

查看:98
本文介绍了为什么GCC将帧指针放在64位上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

默认情况下在64位体系结构上删除帧指针的依据是什么?我很清楚可以启用它,但是为什么在启用32位功能时,GCC首先要禁用它?毕竟64位比32位CPU拥有更多的寄存器。



编辑:



看起来像使用较新的GCC版本时,x86的帧指针也将被删除。从手册中:


从GCC 4.6版开始,这是32位Linux x86和32的默认设置(不优化大小时)位Darwin x86目标已更改为-fomit-frame-pointer。通过使用-enable-frame-pointer -fno-omit-frame-pointer c>配置选项。


但是为什么?

解决方案

对于x86-64, ABI (PDF)鼓励没有框架指针。基本原理是现在我们有了DWARF,因此没有必要进行调试或解除异常;如果从第一天开始就将其设为可选,那么将没有软件依赖于它的存在。



x86-64的寄存器比x86-32多,但是它仍然没有足够的。从编译器的角度来看,释放更多通用寄存器始终是一件好事。是的,需要堆栈爬网的操作较慢,是的,但是它们是罕见的事件,因此对于减少每个子例程调用的几个周期以及减少堆栈溢出来说,这是一个很好的权衡。

What's the rationale behind dropping the frame pointer on 64-bit architectures by default? I'm well aware that it can be enabled but why does GCC disable it in the first place while having it enabled for 32-bit? After all, 64-bit has more registers than 32-bit CPUs.

Edit:

Looks like the frame pointer will be also dropped for x86 when using a more recent GCC version. From the manual:

Starting with GCC version 4.6, the default setting (when not optimizing for size) for 32-bit Linux x86 and 32-bit Darwin x86 targets has been changed to -fomit-frame-pointer. The default can be reverted to -fno-omit-frame-pointer by configuring GCC with the --enable-frame-pointer configure option.

But why?

解决方案

For x86-64, the ABI (PDF) encourages the absence of a frame pointer. The rationale is more or less "we have DWARF now, so it's not necessary for debugging or exception unwinding; if we make it optional from day one, then no software will come to depend on its existence."

x86-64 does have more registers than x86-32, but it still doesn't have enough. Freeing up more general-purpose registers is always a Good Thing from a compiler's point of view. The operations that require a stack crawl are slower, yes, but they are rare events, so it's a good tradeoff for shaving a few cycles off every subroutine call plus fewer stack spills.

这篇关于为什么GCC将帧指针放在64位上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆