开发者

Why does GCC drop the frame pointer on 64-bit?

开发者 https://www.devze.com 2023-03-08 00:53 出处:网络
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 enable

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 regi开发者_开发知识库sters 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消