[gcc(refs/vendors/ibm/heads/gcc-9-branch)] x86: Allow -fcf-protection with external thunk
Peter Bergner
bergner@gcc.gnu.org
Fri Sep 4 19:07:23 GMT 2020
https://gcc.gnu.org/g:a03efb266fcbf4a01285fff871a5bfe5caac4944
commit a03efb266fcbf4a01285fff871a5bfe5caac4944
Author: H.J. Lu <hjl.tools@gmail.com>
Date: Wed Apr 29 04:52:46 2020 -0700
x86: Allow -fcf-protection with external thunk
Allow -fcf-protection with external thunk since the external thunk can be
made compatible with -fcf-protection.
gcc/
Backport from master
PR target/93654
* config/i386/i386-options.c (ix86_set_indirect_branch_type):
Allow -fcf-protection with -mindirect-branch=thunk-extern and
-mfunction-return=thunk-extern.
* doc/invoke.texi: Update notes for -fcf-protection=branch with
-mindirect-branch=thunk-extern and -mindirect-return=thunk-extern.
gcc/testsuite/
Backport from master
PR target/93654
* gcc.target/i386/pr93654.c: New test.
(cherry picked from commit 9be3bb2c0a258fd6a7d3d05d232a21930c757d3c)
Diff:
---
gcc/ChangeLog | 12 ++++++++++++
gcc/config/i386/i386.c | 4 ++++
gcc/doc/invoke.texi | 10 +++++++---
gcc/testsuite/ChangeLog | 8 ++++++++
gcc/testsuite/gcc.target/i386/pr93654.c | 9 +++++++++
5 files changed, 40 insertions(+), 3 deletions(-)
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 4cb1497a61f..c0d72cbbdf5 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,15 @@
+2020-04-29 H.J. Lu <hongjiu.lu@intel.com>
+
+ Backport from master
+ 2020-04-29 H.J. Lu <hongjiu.lu@intel.com>
+
+ PR target/93654
+ * config/i386/i386.c (ix86_set_indirect_branch_type): Allow
+ -fcf-protection with -mindirect-branch=thunk-extern and
+ -mfunction-return=thunk-extern.
+ * doc/invoke.texi: Update notes for -fcf-protection=branch with
+ -mindirect-branch=thunk-extern and -mindirect-return=thunk-extern.
+
2020-04-21 Martin Jambor <mjambor@suse.cz>
Backport from master
diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
index efe32f3975e..ae5046ee6a0 100644
--- a/gcc/config/i386/i386.c
+++ b/gcc/config/i386/i386.c
@@ -5807,6 +5807,8 @@ ix86_set_indirect_branch_type (tree fndecl)
? "thunk-extern" : "thunk"));
if (cfun->machine->indirect_branch_type != indirect_branch_keep
+ && (cfun->machine->indirect_branch_type
+ != indirect_branch_thunk_extern)
&& (flag_cf_protection & CF_RETURN))
error ("%<-mindirect-branch%> and %<-fcf-protection%> are not "
"compatible");
@@ -5850,6 +5852,8 @@ ix86_set_indirect_branch_type (tree fndecl)
? "thunk-extern" : "thunk"));
if (cfun->machine->function_return_type != indirect_branch_keep
+ && (cfun->machine->function_return_type
+ != indirect_branch_thunk_extern)
&& (flag_cf_protection & CF_RETURN))
error ("%<-mfunction-return%> and %<-fcf-protection%> are not "
"compatible");
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index b18e9124b4e..5e6d240dc5d 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -28735,9 +28735,9 @@ Note that @option{-mcmodel=large} is incompatible with
@option{-mindirect-branch=thunk-extern} since the thunk function may
not be reachable in the large code model.
-Note that @option{-mindirect-branch=thunk-extern} is incompatible with
-@option{-fcf-protection=branch} since the external thunk cannot be modified
-to disable control-flow check.
+Note that @option{-mindirect-branch=thunk-extern} is compatible with
+@option{-fcf-protection=branch} since the external thunk can be made
+to enable control-flow check.
@item -mfunction-return=@var{choice}
@opindex mfunction-return
@@ -28750,6 +28750,10 @@ object file. You can control this behavior for a specific function by
using the function attribute @code{function_return}.
@xref{Function Attributes}.
+Note that @option{-mindirect-return=thunk-extern} is compatible with
+@option{-fcf-protection=branch} since the external thunk can be made
+to enable control-flow check.
+
Note that @option{-mcmodel=large} is incompatible with
@option{-mfunction-return=thunk} and
@option{-mfunction-return=thunk-extern} since the thunk function may
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index ec3b39c1dbd..49e8d899e5e 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,11 @@
+2020-04-29 H.J. Lu <hongjiu.lu@intel.com>
+
+ Backport from master
+ 2020-04-29 H.J. Lu <hongjiu.lu@intel.com>
+
+ PR target/93654
+ * gcc.target/i386/pr93654.c: New test.
+
2020-04-24 Thomas Koenig <tkoenig@gcc.gnu.org>
Backport from trunk
diff --git a/gcc/testsuite/gcc.target/i386/pr93654.c b/gcc/testsuite/gcc.target/i386/pr93654.c
new file mode 100644
index 00000000000..ec5bdce86a6
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr93654.c
@@ -0,0 +1,9 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fcf-protection -mfunction-return=thunk-extern -mindirect-branch=thunk-extern" } */
+
+int
+bar (void (*foo) (void))
+{
+ foo ();
+ return 0;
+}
More information about the Gcc-cvs
mailing list