Gnu 汇编器 (GAS) 中的 CFI 指令有何用途?
每行后面似乎都有一个 .CFI 指令,而且还有各种各样的指令,例如 .cfi_startproc
、 .cfi_endproc
等。 更多信息。
.file "temp.c"
.text
.globl main
.type main, @function
main:
.LFB0:
.cfi_startproc
pushq %rbp
.cfi_def_cfa_offset 16
movq %rsp, %rbp
.cfi_offset 6, -16
.cfi_def_cfa_register 6
movl $0, %eax
leave
ret
.cfi_endproc
.LFE0:
.size main, .-main
.globl func
.type func, @function
func:
.LFB1:
.cfi_startproc
pushq %rbp
.cfi_def_cfa_offset 16
movq %rsp, %rbp
.cfi_offset 6, -16
.cfi_def_cfa_register 6
movl %edi, -4(%rbp)
movl %esi, %eax
movb %al, -8(%rbp)
leave
ret
.cfi_endproc
.LFE1:
.size func, .-func
.ident "GCC: (Ubuntu 4.4.1-4ubuntu9) 4.4.1"
.section .note.GNU-stack,"",@progbits
我没明白这些的目的。
There seem to be a .CFI directive after every line and also there are wide varieties of these ex.,.cfi_startproc
, .cfi_endproc
etc.. more here.
.file "temp.c"
.text
.globl main
.type main, @function
main:
.LFB0:
.cfi_startproc
pushq %rbp
.cfi_def_cfa_offset 16
movq %rsp, %rbp
.cfi_offset 6, -16
.cfi_def_cfa_register 6
movl $0, %eax
leave
ret
.cfi_endproc
.LFE0:
.size main, .-main
.globl func
.type func, @function
func:
.LFB1:
.cfi_startproc
pushq %rbp
.cfi_def_cfa_offset 16
movq %rsp, %rbp
.cfi_offset 6, -16
.cfi_def_cfa_register 6
movl %edi, -4(%rbp)
movl %esi, %eax
movb %al, -8(%rbp)
leave
ret
.cfi_endproc
.LFE1:
.size func, .-func
.ident "GCC: (Ubuntu 4.4.1-4ubuntu9) 4.4.1"
.section .note.GNU-stack,"",@progbits
I didn't get the purpose of these.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
使用 gcc 选项-fno-dwarf2-cfi-asm 。
要禁用这些,可能还需要
To disable these, use the gcc option
-fno-dwarf2-cfi-asm
may be needed also.我有一种感觉它代表 Call Frame Information 并且是一个 GNU AS 扩展管理呼叫帧。来自 DeveloperWorks< /a>:
看起来这些是在某些平台上根据异常处理的需要生成的。
如果您想禁用这些功能,请参阅David 的回答。
I've got a feeling it stands for Call Frame Information and is a GNU AS extension to manage call frames. From DeveloperWorks:
It looks like these are generated on some platforms depending on need for exception handling.
If you are looking to disable these, please see David's answer.
CFI 指令用于调试。它允许调试器展开堆栈。例如:如果过程 A 调用过程 B,然后过程 B 又调用公共过程 C。过程 C 失败。您现在想知道谁实际调用了 C,然后您可能想知道谁调用了 B。
调试器可以通过使用堆栈指针 (%rsp) 展开此堆栈并注册 %rbp,但它需要知道如何找到它们。这就是 CFI 指令的用武之地。
所以这里的最后一行告诉它“调用帧地址”现在位于寄存器 6 (%rbp) 中
The CFI directives are used for debugging. It allows the debugger to unwind a stack. For example: if procedure A calls procedure B which then calls a common procedure C. Procedure C fails. You now want to know who actually called C and then you may want to know who called B.
A debugger can unwind this stack by using the stack pointer (%rsp) and register %rbp, however it needs to know how to find them. That is where the CFI directives come in.
so the last line here tell it that the "Call frame address" is now in register 6 (%rbp)
要禁用这些,g++ 需要
-fno-exceptions
以及前面提到的-fno-asynchronous-unwind-tables
,前提是您不使用异常。To disable these, g++ needs
-fno-exceptions
along with the previously mentioned-fno-asynchronous-unwind-tables
, provided that you don't use exceptions.