How to disable RBP frame pointer register optimization in GCC when using -O*?

1k views Asked by At

When I use gcc -O2 to optimize my program, gcc changes the value of register RBP. But I want to keep it as FRAME BASE REGISTER, how to do this?

Not the same question as: GCC: Prohibit use of some registers

1

There are 1 answers

4
phuclv On BEST ANSWER

-fomit-frame-pointer is enabled by default at optimization levels -O, -O2, -O3, -Os

You need to use -fno-omit-frame-pointer

However there are not much reasons to keep the frame pointer unless you're debugging and need to trace the stack frame. In that case, use -Og instead