Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

-fomit-frame-pointer, is it safe to use it?

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.

like image 916
Mick Seng Avatar asked Feb 25 '10 13:02

Mick Seng


2 Answers

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).

like image 78
Thomas Pornin Avatar answered Sep 19 '22 01:09

Thomas Pornin


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.

like image 33
Billy ONeal Avatar answered Sep 18 '22 01:09

Billy ONeal