141

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.

2

4 Answers 4

153

To disable these, use the gcc option

-fno-asynchronous-unwind-tables

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

3
  • 14
    -fno-dwarf2-cfi-asm may be needed also Commented Mar 11, 2016 at 18:55
  • 1
    If you're disabling it for human-readable asm output, see How to remove "noise" from GCC/clang assembly output? for other useful options and tricks. Commented Jan 11, 2020 at 4:17
  • 7
    Interesting to note that the answer how to disable them got more upvotes than those which describe what are they :)
    – mathway
    Commented Oct 19, 2021 at 23:27
81

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.

2
38

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)

4
  • 2
    But exception handling usage of cfi should be more frequent than debugging, I think.
    – osgx
    Commented May 8, 2014 at 23:12
  • 6
    Actually CFA stands for "canonical frame address". See here.
    – Cameron
    Commented Jun 3, 2014 at 16:38
  • - ImperialViolet - CFI directives in assembly files
    – Mark Simon
    Commented Sep 19, 2017 at 5:24
  • 1
    CFI directives allow stack-unwinding even for code compiled with -fomit-frame-pointer, as an alternative to RBP (which is on by default with gcc or clang -O1 and higher). It's used by C++ exception handling as well as debuggers / profilers. In code with traditional RBP frame pointers, the current RBP value always points at a saved RBP value, and that points at the previous one forming a linked list. There's no need for CFI in that case. (Although in functions that use a frame pointer, CFI cfa_register avoids needing more metadata for every RSP change, like you're showing.) Commented Jan 11, 2020 at 4:22
4

To disable these, g++ needs -fno-exceptions along with the previously mentioned -fno-asynchronous-unwind-tables, provided that you don't use exceptions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.