Would you trade 0.1% in performance for a better debugging experience?

Marco Leise via Digitalmars-d digitalmars-d at puremagic.com
Tue Nov 18 09:00:42 PST 2014


Am Mon, 17 Nov 2014 23:14:31 +0000
schrieb "Vladimir Panteleev" <vladimir at thecybershadow.net>:

[…]

From
http://eli.thegreenplace.net/2011/09/06/stack-frame-layout-on-x86-64/

-------------------------------------------------------------

Preserving the base pointer

The base pointer rbp (and its predecessor ebp on x86), being a
stable "anchor" to the beginning of the stack frame throughout
the execution of a function, is very convenient for manual
assembly coding and for debugging [5]. However, some time ago
it was noticed that compiler-generated code doesn't really
need it (the compiler can easily keep track of offsets from
rsp), and the DWARF debugging format provides means (CFI) to
access stack frames without the base pointer.

This is why some compilers started omitting the base pointer
for aggressive optimizations, thus shortening the function
prologue and epilogue, and providing an additional register
for general-purpose use (which, recall, is quite useful on x86
with its limited set of GPRs).

gcc keeps the base pointer by default on x86, but allows the
optimization with the -fomit-frame-pointer compilation flag.
How recommended it is to use this flag is a debated issue -
you may do some googling if this interests you.

Anyhow, one other "novelty" the AMD64 ABI introduced is making
the base pointer explicitly optional, stating:

»The conventional use of %rbp as a frame pointer for the stack
 frame may be avoided by using %rsp (the stack pointer) to
 index into the stack frame. This technique saves two
 instructions in the prologue and epilogue and makes one
 additional general-purpose register (%rbp) available.«

gcc adheres to this recommendation and by default omits the
frame pointer on x64, when compiling with optimizations. It
gives an option to preserve it by providing the
-fno-omit-frame-pointer flag. For clarity's sake, the stack
frames showed above were produced without omitting the frame
pointer.

-------------------------------------------------------------

Without fully understanding the issue, omitting the frame
pointer on GNU amd64 systems is the default and is supposed to
work using DWARF debug information. So there should be no need
for a stack frame pointer, right?

Are you mostly concerned with Windows then?

-- 
Marco



More information about the Digitalmars-d mailing list