This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

DWARF2 CFI in absence of a frame pointer


It seems there is a serious problem with the DWARF2 CFI generated by
GCC on architectures without a frame pointer.  The problem arises when
GCC emits code similar to:

	# basic block 0
        prologue
        ...
        jmp .L2
.L1:
	# basic block 1
	epilogue
	ret
.L2:
	# basic block 2
	...
	jmp .L1

where "prologue" and "epilogue" typically are bits of code that adjust
the stack pointer.  Since, in the absence of a frame pointer, the CFA
is calculated relative to the stack pointer, GCC generates CFI for the
prologue and the epilogue.  In particular, GCC will generate CFI for
the epilogue that takes into account the adjustments that are made to
the stack pointer to restore it to its state on entry of the function.
Unfortunately, the way DWARF2 CFI works, this means that that same
state will be used for the code in "basic block 2" too.  This of
course is wrong, and makes unwinding within that bit of code fail
miserably.  This can be seen on x86-64, and also on i386 with
-fomit-frame-pointer.

For architectures with a frame pointer there usually is no problem
since GCC doesn't generated CFI for the epilogue in that case.

I assume this has some serious impact on exception handling too.

Are there any ideas for solving this?  GCC should probably emit
DW_CFA_remember_state and DW_CFA_restore_state at the appropriate
locations, but I don't immediately see how to do this.

Meanwhile, this means that GDB is not quite so usable on x86-64 with
recent GCC's.  Is there an easy way to make sure GCC always emits the
epilogue at the end of a function?

Mark


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]