Bug 27472 - gas: Suppress "CFI instruction used without previous .cfi_startproc" if .cfi_sections is empty
Summary: gas: Suppress "CFI instruction used without previous .cfi_startproc" if .cfi_...
Status: UNCONFIRMED
Alias: None
Product: binutils
Classification: Unclassified
Component: gas (show other bugs)
Version: unspecified
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-02-26 05:45 UTC by Fangrui Song
Modified: 2022-03-13 22:49 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Fangrui Song 2021-02-26 05:45:34 UTC
% cat a.c
int main() {
  asm("pushl 0\n.cfi_adjust_cfa_offset 4\npop %%eax\n.cfi_adjust_cfa_offset -4" ::: "eax");
}
% gcc -m32 -c -fomit-frame-pointer -fno-asynchronous-unwind-tables a.c
a.c: Assembler messages:
a.c:3: Error: CFI instruction used without previous .cfi_startproc
a.c:5: Error: CFI instruction used without previous .cfi_startproc

-fasynchronous-unwind-tables & -fno-asynchronous-unwind-tables do not have a predefined macro, so it is difficult for the inline asm to know whether CFI directives should be used. For ergonomics, users just want to write CFI directives and hope they will be silently ignored in -fno-asynchronous-unwind-tables mode. However, GNU as errors for .cfi_* without .cfi_startproc .

I suggest that (1) GCC emits ".cfi_sections" (no value) at the beginning, (2) GNU as suppresses the error if no .eh_frame/.debug_frame is needed.

The place to patch is gas/dw2gencfi.c:dot_cfi and a few other functions.