Bug 77455 - [AArch64] eh_return implementation fails
Summary: [AArch64] eh_return implementation fails
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 4.8.4
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
: 71989 (view as bug list)
Depends on:
Blocks:
 
Reported: 2016-09-02 11:25 UTC by Wilco
Modified: 2017-07-13 06:45 UTC (History)
2 users (show)

See Also:
Host:
Target: AArch64
Build:
Known to work:
Known to fail: 4.8.4
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Wilco 2016-09-02 11:25:01 UTC
The __builtin_eh_return implementation on AArch64 generates incorrect code for many cases due to using an incorrect offset/pointer when writing the new return address to the stack. Also optimizations may remove the write due to a missing scheduling barrier. As a result in most cases eh_return does not work properly.
Comment 1 Wilco 2016-09-02 11:33:13 UTC
See https://gcc.gnu.org/ml/gcc-patches/2016-09/msg00077.html for more details, a simpler reimplementation and a testcase.
Comment 2 Wilco 2017-01-19 17:42:59 UTC
Fixed on trunk in r244547:

This patch simplifies the handling of EH return.  We force the use of the
frame pointer so the return location is always at FP + 8.  This means we
can emit a simple volatile access in EH_RETURN_HANDLER_RTX without needing md
patterns, splitters and frame offset calculations.  The new implementation also
fixes various bugs in aarch64_final_eh_return_addr, which does not work with
-fomit-frame-pointer, alloca or outgoing arguments.

    gcc/
	* config/aarch64/aarch64.md (eh_return): Remove pattern and splitter.
	* config/aarch64/aarch64.h (AARCH64_EH_STACKADJ_REGNUM): Remove.
	(EH_RETURN_HANDLER_RTX): New define.
	* config/aarch64/aarch64.c (aarch64_frame_pointer_required):
	Force frame pointer in EH return functions.
	(aarch64_expand_epilogue): Add barrier for eh_return.
	(aarch64_final_eh_return_addr): Remove.
	(aarch64_eh_return_handler_rtx): New function.
	* config/aarch64/aarch64-protos.h (aarch64_final_eh_return_addr):
	Remove.
	(aarch64_eh_return_handler_rtx): New prototype.

    testsuite/
	* gcc.target/aarch64/eh_return.c: New test.
Comment 3 Wilco 2017-01-20 15:35:14 UTC
Author: wilco
Date: Fri Jan 20 15:34:41 2017
New Revision: 244724

URL: https://gcc.gnu.org/viewcvs?rev=244724&root=gcc&view=rev
Log:
This patch simplifies the handling of EH return.  We force the use of the
frame pointer so the return location is always at FP + 8.  This means we
can emit a simple volatile access in EH_RETURN_HANDLER_RTX without needing md
patterns, splitters and frame offset calculations.  The new implementation also
fixes various bugs in aarch64_final_eh_return_addr, which does not work with
-fomit-frame-pointer, alloca or outgoing arguments.

	Backport from mainline
    gcc/
	PR target/77455
	* config/aarch64/aarch64.md (eh_return): Remove pattern and splitter.
	* config/aarch64/aarch64.h (AARCH64_EH_STACKADJ_REGNUM): Remove.
	(EH_RETURN_HANDLER_RTX): New define.
	* config/aarch64/aarch64.c (aarch64_frame_pointer_required):
	Force frame pointer in EH return functions.
	(aarch64_expand_epilogue): Add barrier for eh_return.
	(aarch64_final_eh_return_addr): Remove.
	(aarch64_eh_return_handler_rtx): New function.
	* config/aarch64/aarch64-protos.h (aarch64_final_eh_return_addr):
	Remove.
	(aarch64_eh_return_handler_rtx): New prototype.

    testsuite/
	PR target/77455
	* gcc.target/aarch64/eh_return.c: New test.

Added:
    branches/gcc-6-branch/gcc/testsuite/gcc.target/aarch64/eh_return.c
Modified:
    branches/gcc-6-branch/gcc/ChangeLog
    branches/gcc-6-branch/gcc/config/aarch64/aarch64-protos.h
    branches/gcc-6-branch/gcc/config/aarch64/aarch64.c
    branches/gcc-6-branch/gcc/config/aarch64/aarch64.h
    branches/gcc-6-branch/gcc/config/aarch64/aarch64.md
    branches/gcc-6-branch/gcc/testsuite/ChangeLog
Comment 4 Wilco 2017-01-20 15:55:15 UTC
Fixed in GCC6 and GCC7
Comment 5 Timo Teräs 2017-07-13 06:44:29 UTC
*** Bug 71951 has been marked as a duplicate of this bug. ***
Comment 6 Timo Teräs 2017-07-13 06:45:41 UTC
*** Bug 71989 has been marked as a duplicate of this bug. ***