On 2021-02-19, Fangrui Song wrote:
On 2021-02-19, Jim Wilson wrote:
On Wed, Feb 17, 2021 at 9:22 PM Fangrui Song <i@xxxxxxxxxx> wrote:
g++ -fno-exceptions -fno-asynchronous-unwind-tables -S a.cc => no
.cfi_* directive
g++ -fno-exceptions -fno-asynchronous-unwind-tables -g -S a.cc =>
there are .cfi_* directive
The intent is that -g produces .debug_frame sections, because the compiler
is supposed to, and we can't know in advance whether the debugger will want
them. EH produces .eh_frame sections. If we need to produce an eh_frame
section, then we don't bother to produce a debug_frame section because they
are basically the same, except that eh_frame has extra alignment padding to
make it friendlier to non-dwarf2 systems, and gdb can use either section.
The .cfi_* directives are used for both the debug_frame and eh_frame
sections.
When using -g with exceptions off, you should see a
.cfi_sections .debug_frame
directive which tells the assembler to produce a debug_frame section. If
no .cfi_sections directive the assembler will produce a eh_frame section by
default.
If a toolchain produces debug info by default, you can turn it off with
-g0, preferably at the end of the command in case there is a -g option
somewhere earlier in the command.
Exact behavior will depend on gcc version and target, since cfi_sections
was added about 10 years ago, and some targets enable debug and/or
exceptions by default, and some targets don't use dwarf2 exceptions.
Thanks for the information. I have a follow-up question.
How should we make the following code work with both
-fno-asynchronous-unwind-tables and -fasynchronous-unwind-tables?
int main() {
asm(".cfi_undefined %rip");
}
The example is minimalistic. The idea is that if inline asm does stack
push/pop and wants to manually add .cfi_* directives, the current
error behavior is undesired.
Currently gcc -fno-asynchronous-unwind-tables -c a.c reports an error:
a.c:2: Error: CFI instruction used without previous .cfi_startproc