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

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

问题描述

默认情况下在 64 位架构上丢弃帧指针的基本原理是什么?我很清楚它可以启用,但是为什么 GCC 在启用 32 位时首先禁用它?毕竟,64 位 CPU 比 32 位 CPU 拥有更多的寄存器.

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.

当使用更新的 GCC 版本时,看起来 x86 的帧指针也会被丢弃.来自手册:

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

从 GCC 4.6 版开始,32 位 Linux x86 和 32 位 Darwin x86 目标的默认设置(未优化大小时)已更改为 -fomit-frame-pointer.通过使用 --enable-frame-pointer 配置选项配置 GCC,可以将默认值恢复为 -fno-omit-frame-pointer.

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.

为什么?

推荐答案

对于 x86-64,ABI (PDF) 鼓励没有框架指针.其基本原理或多或少是我们现在有了 DWARF,因此不需要调试或异常展开;如果我们从一开始就将其设为可选,那么任何软件都不会依赖于它的存在."

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 确实比 x86-32 有更多的寄存器,但它仍然不够.从编译器的角度来看,释放更多的通用寄存器总是一件好事.需要堆栈爬行的操作较慢,是的,但它们是罕见的事件,因此对于每个子例程调用减少几个周期以及减少堆栈溢出,这是一个很好的权衡.

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天全站免登陆