-fomit-frame-pointer *总是*省略 fp 吗?
-fomit-frame-pointer 是否总是忽略帧指针?是否存在pc和fp都需要设置的情况?动态堆栈增长是否会强制设置 fp?专门询问MIPS32。谢谢!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
正确执行并不真正需要帧指针,除非有时异常展开。动态堆栈增长通常需要某种帧指针,但它不绑定到特定寄存器,而是通过正常的数据流分析进行分配。
基本上,-fomit-frame-pointer 将 FP 从固定寄存器分配降级为伪寄存器,并使初始化服从死存储消除。所以第一个问题的答案是否定的,它并不总是省略它。
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.不,通常不需要帧指针。编译器可以访问相对于堆栈指针的局部变量,并且不需要特殊的帧指针。
尽管如此,标准帧指针设置序列在调试崩溃的程序时会有所帮助(即使未使用
-g
进行编译),因为调试器可以使用帧指针信息来重建调用堆栈。如果没有帧指针,它就没有信息来确定一个堆栈帧的开始位置和下一个堆栈帧的结束位置。因此,当使用 -fomit-frame-pointer 时,您会以性能为代价换取在崩溃时更加困难的调试。如果代码的性能关键部分是小循环并且不调用任何函数,那么省略帧指针也不会带来什么好处。
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.不是 mips 人员,但应该适用于任何系统:如果堆栈需要在任何点对齐,则需要使用帧来存储原始指针(因为堆栈地址和对齐方式可能不知道)
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)