i386: Add indirect_return function attribute
authorH.J. Lu <hongjiu.lu@intel.com>
Wed, 4 Jul 2018 03:01:33 +0000 (03:01 +0000)
committerH.J. Lu <hjl@gcc.gnu.org>
Wed, 4 Jul 2018 03:01:33 +0000 (20:01 -0700)
commitebaa4deaf9f3bec32443e60fe74fce14686b4706
treefb0135f43e72e4ffd528ad5806930aa0f186f804
parent7422f0ff39697b53ad599834647c56cb0cb3c3a3
i386: Add indirect_return function attribute

On x86, swapcontext may return via indirect branch when shadow stack
is enabled.  To support code instrumentation of control-flow transfers
with -fcf-protection, add indirect_return function attribute to inform
compiler that a function may return via indirect branch.

Note: Unlike setjmp, swapcontext only returns once.  Mark it return
twice will unnecessarily disable compiler optimization as shown in
the testcase here.

gcc/

PR target/85620
* config/i386/i386.c (rest_of_insert_endbranch): Also generate
ENDBRANCH for non-tail call which may return via indirect branch.
* doc/extend.texi: Document indirect_return attribute.

gcc/testsuite/

PR target/85620
* gcc.target/i386/pr85620-1.c: New test.
* gcc.target/i386/pr85620-2.c: Likewise.
* gcc.target/i386/pr85620-3.c: Likewise.
* gcc.target/i386/pr85620-4.c: Likewise.

From-SVN: r262370
gcc/ChangeLog
gcc/config/i386/i386.c
gcc/doc/extend.texi
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.target/i386/pr85620-1.c [new file with mode: 0644]
gcc/testsuite/gcc.target/i386/pr85620-2.c [new file with mode: 0644]
gcc/testsuite/gcc.target/i386/pr85620-3.c [new file with mode: 0644]
gcc/testsuite/gcc.target/i386/pr85620-4.c [new file with mode: 0644]