i386: Update INCOMING_FRAME_SP_OFFSET for exception handler
commitbd5b8bcedebafe08dc17d0cbfbfada53d5ed25b5
authorhjl <hjl@138bc75d-0d04-0410-961f-82ee72b054a4>
Sun, 30 Jul 2017 14:10:32 +0000 (30 14:10 +0000)
committerhjl <hjl@138bc75d-0d04-0410-961f-82ee72b054a4>
Sun, 30 Jul 2017 14:10:32 +0000 (30 14:10 +0000)
tree7e4bfdd02ae4e0f45f56c368d05e2b0299cc39a0
parent34b38a09b61efae34647085447817b3d195a4b99
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.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@250721 138bc75d-0d04-0410-961f-82ee72b054a4
gcc/ChangeLog
gcc/config/i386/i386.c
gcc/config/i386/i386.h
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/guality/pr68037-1.c
gcc/testsuite/gcc.target/i386/interrupt-5.c
gcc/testsuite/gcc.target/i386/pr79793-1.c [new file with mode: 0644]
gcc/testsuite/gcc.target/i386/pr79793-2.c [new file with mode: 0644]