On Mon, Jan 29, 2024 at 2:08 AM Jakub Jelinek <ja...@redhat.com> wrote: > > On Sat, Jan 27, 2024 at 12:41:24PM -0800, H.J. Lu wrote: > > When assembler directives for DWARF frame unwind is enabled, generate > > the .cfi_undefined directive for unsaved callee-saved registers which > > have been used in the function. > > > > gcc/ > > > > PR target/38534 > > * config/i386/i386.cc (ix86_post_cfi_startproc): New. > > (TARGET_ASM_POST_CFI_STARTPROC): Likewise. > > > > gcc/testsuite/ > > > > PR target/38534 > > * gcc.target/i386/no-callee-saved-19.c: New test. > > * gcc.target/i386/no-callee-saved-20.c: Likewise. > > * gcc.target/i386/pr38534-7.c: Likewise. > > * gcc.target/i386/pr38534-8.c: Likewise. > > This only works for -fdwarf2-cfi-asm, but doesn't work for > -fno-dwarf2-cfi-asm. I think we need something that will work for both.
-fno-dwarf2-cfi-asm stops generating all CFI directives. > So, I'd say we want to add support for REG_CFA_UNDEFINED note, emit those > notes on some frame related insn in the prologue during prologue expansion > in pro_and_epilogue pass and handle that in dwarf2cfi.cc pass. It is a good idea. Here is the patch: https://patchwork.sourceware.org/project/gcc/list/?series=30314 > One question is where those should be emitted. Emitting them right > at the start of the function has an advantage that it can be emitted in > CIE for all FDEs of noreturn functions (or with the new attribute). But > disadvantage is of course that it will make e.g. debugging experience worse > even in the prologues of functions where the callee saved registers which > current function actually doesn't save aren't modified yet. > E.g. for the cases where callee saved registers are saved to memory or > registers I think dwarf2cfi.cc attempts to optimize and move the .cfi_* > directives or .eh_frame record later into the function as long as the > corresponding original register isn't modified yet. Perhaps that should > be done also for the undefined case, ideally by using the same dwarf2cfi.cc > code. So just perhaps at the start of the function read in the > REG_CFA_UNDEFINED notes for all the ever modified callee saved registers > which won't be actually saved and turn that into similar record like for > the saving into stack or other regs, just noting it is undefined instead > and have it pushed later as much as possible. My patch doesn't implement this optimization. -- H.J.