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

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

Thanks a lot, best regards.

+6
c ++ optimization c gcc
source share
2 answers

The option is safe, but makes debugging more difficult. Typically, the C compiler outputs code that stores in the regular register ( ebp on x86) a pointer to the stack stack for the function. Debuggers use this to print the local contents of a variable and other such information. The -fomit-frame-pointer flag tells gcc not to worry about this case. In some situations, this can lead to a small increase in performance, mainly due to a decrease in code length (which is better for the cache) and an additional available register (especially on x86 in 32-bit mode, which, as you know, is starving on registers).

+11
source share

As long as your code does not rely on undefined behavior, then it is completely safe. This can cause undefined behavior errors.

+2
source share

All Articles