views:

144

answers:

2

I've seen in many places that people often use the option -fomit-frame-pointer when compiling C / C++ code and I wonder, is the use of that option safe? What is it used for?

Thank you very much, best regards.

+1  A: 

So long as your code does not rely on undefined behavior, then it's perfectly safe. It may cause undefined behavior bugs to show up though.

Billy ONeal
+8  A: 

The option is safe but makes debugging harder. Normally, the C compiler outputs code which stores in a conventional register (ebp on x86) a pointer to the stack frame for the function. Debuggers use that to print out local variable contents and other such information. The -fomit-frame-pointer flag instructs gcc not to bother with that register. In some situations, this can yield a slight performance increase, mostly due to reduced code footprint (that's better for cache) and to the extra available register (especially on x86 in 32-bit mode, which is notoriously starved on registers).

Thomas Pornin
@Thomas could you provide some links (if you know) about the register details as you mentioned.
Adil
See http://refspecs.freestandards.org/elf/ , in particular the "Application Binary Interface" documents for the specific processor architectures. In the ABI for i386, the standard stack frame format (with use of `ebp`) is described on page 36. The ELF format is common to many "modern" Unix-like systems (e.g. Linux and FreeBSD). On Windows systems, things are slightly different but use the same principles.
Thomas Pornin