Gnu 汇编器 (GAS) 中的 CFI 指令有何用途?

发布于 2024-08-26 23:40:47 字数 991 浏览 5 评论 0原文

每行后面似乎都有一个 .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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

小镇女孩 2024-09-02 23:40:47

使用 gcc 选项-fno-dwarf2-cfi-asm 。

-fno-asynchronous-unwind-tables

要禁用这些,可能还需要

To disable these, use the gcc option

-fno-asynchronous-unwind-tables

-fno-dwarf2-cfi-asm may be needed also.

初吻给了烟 2024-09-02 23:40:47

我有一种感觉它代表 Call Frame Information 并且是一个 GNU AS 扩展管理呼叫帧。来自 DeveloperWorks< /a>:

在某些架构上,例外
处理必须通过 Call 来管理
框架信息指令。这些
指令在汇编中用于
直接异常处理。这些
指令可在 Linux 上使用
POWER,如果出于任何原因(便携性
例如,代码库的
GCC 生成的异常处理
信息不充分。

看起来这些是在某些平台上根据异常处理的需要生成的。

如果您想禁用这些功能,请参阅David 的回答

I've got a feeling it stands for Call Frame Information and is a GNU AS extension to manage call frames. From DeveloperWorks:

On some architectures, exception
handling must be managed with Call
Frame Information directives. These
directives are used in the assembly to
direct exception handling. These
directives are available on Linux on
POWER, if, for any reason (portability
of the code base, for example), the
GCC generated exception handling
information is not sufficient.

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.

落花随流水 2024-09-02 23:40:47

CFI 指令用于调试。它允许调试器展开堆栈。例如:如果过程 A 调用过程 B,然后过程 B 又调用公共过程 C。过程 C 失败。您现在想知道谁实际调用了 C,然后您可能想知道谁调用了 B。

调试器可以通过使用堆栈指针 (%rsp) 展开此堆栈并注册 %rbp,但它需要知道如何找到它们。这就是 CFI 指令的用武之地。

movq    %rsp, %rbp
.cfi_def_cfa_register 6

所以这里的最后一行告诉它“调用帧地址”现在位于寄存器 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.

movq    %rsp, %rbp
.cfi_def_cfa_register 6

so the last line here tell it that the "Call frame address" is now in register 6 (%rbp)

乞讨 2024-09-02 23:40:47

要禁用这些,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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文