Does -fomit-frame-pointer *always* omit the fp?

社会主义新天地 提交于 2019-12-11 00:47:50

问题


Does -fomit-frame-pointer always omit the frame pointer? Is there ever a situation where both the pc and fp need to be setup? Does dynamic stack growth force the fp to be setup? Asking specifically for MIPS32. Thanks!


回答1:


The frame pointer is not really needed for correct execution, except sometimes for exception unwind. Dynamic stack growth usually requires some kind of a frame pointer, but it is not tied to a particular register, but rather allocated through normal data flow analysis.

Basically, -fomit-frame-pointer demotes the FP from a fixed register assignment to a pseudo register and makes initialisation subject to dead store elimination. So the answer to the first question is no, it doesn't omit it always.




回答2:


No, the frame pointer is not normally needed. The compiler may access local variables relative to the stack pointer and does not need a special frame pointer.

Nevertheless, the standard frame pointer setup sequence can help when debugging a crashed program (even when not compiled with -g), because the debugger can use the frame pointer information to reconstruct the call stack. With no frame pointer it has no information to figure out where one stack frame starts and the next ends.

So, when using -fomit-frame-pointer you are trading performance for much more difficult debugging in case of a crash. If your code's performance critical parts are smallish loops and don't call any functions, then omitting the frame pointer will bring little advantage, either.




回答3:


Not a mips person, but something that should apply to any system: If the stack needs to be aligned at any point, a frame would need to be used to store the original pointer(as the stack address and alignment may not be know)



来源:https://stackoverflow.com/questions/5016282/does-fomit-frame-pointer-always-omit-the-fp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!