i386: Update INCOMING_FRAME_SP_OFFSET for exception handler
Since there is an extra error code passed to the exception handler,
INCOMING_FRAME_SP_OFFSET is return address plus error code for the
exception handler. This patch updates INCOMING_FRAME_SP_OFFSET to
the correct value for the exception handler.
This patch exposed a bug in DWARF stack frame CFI generation, which
assumes that INCOMING_FRAME_SP_OFFSET is the same for all functions:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81570
It sets and caches the incoming stack frame offset with the same
INCOMING_FRAME_SP_OFFSET for all functions. When there are both
exception handler and normal function in the same input, the wrong
incoming stack frame offset is used for exception handler or normal
function, which leads to
FAIL: gcc.dg/guality/pr68037-1.c -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects line 33 error == 0x12345670
FAIL: gcc.dg/guality/pr68037-1.c -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects line 33 frame->ip == 0x12345671
FAIL: gcc.dg/guality/pr68037-1.c -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects line 33 frame->cs == 0x12345672
FAIL: gcc.dg/guality/pr68037-1.c -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects line 33 frame->flags == 0x12345673
FAIL: gcc.dg/guality/pr68037-1.c -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects line 33 frame->sp == 0x12345674
FAIL: gcc.dg/guality/pr68037-1.c -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects line 33 frame->ss == 0x12345675
With the patch for PR 81570:
https://gcc.gnu.org/ml/gcc-patches/2017-07/msg01851.html
applied, there are no regressions on i686 and x86-64.
gcc/
PR target/79793
* config/i386/i386.c (ix86_function_arg): Update arguments for
exception handler.
(ix86_compute_frame_layout): Set the initial stack offset to
INCOMING_FRAME_SP_OFFSET. Update red-zone offset with
INCOMING_FRAME_SP_OFFSET.
(ix86_expand_epilogue): Don't pop the 'ERROR_CODE' off the
stack before exception handler returns.
* config/i386/i386.h (INCOMING_FRAME_SP_OFFSET): Add the
the 'ERROR_CODE' for exception handler.
gcc/testsuite/
PR target/79793
* gcc.dg/guality/pr68037-1.c: Update gdb breakpoints.
* gcc.target/i386/interrupt-5.c (interrupt_frame): New struct.
(foo): Check the builtin return address against the return address
in interrupt frame.
* gcc.target/i386/pr79793-1.c: New test.
* gcc.target/i386/pr79793-2.c: Likewise.
From-SVN: r250721