aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorH.J. Lu <hjl.tools@gmail.com>2020-04-29 04:52:46 -0700
committerH.J. Lu <hjl.tools@gmail.com>2020-04-29 04:53:02 -0700
commit9be3bb2c0a258fd6a7d3d05d232a21930c757d3c (patch)
tree9ef8c3abbb149bc351e1b1f09038177c0240f003
parent668d8f3c0c61905bc69a1c73f16fa4fa6273db2a (diff)
downloadgcc-9be3bb2c0a258fd6a7d3d05d232a21930c757d3c.zip
gcc-9be3bb2c0a258fd6a7d3d05d232a21930c757d3c.tar.gz
gcc-9be3bb2c0a258fd6a7d3d05d232a21930c757d3c.tar.bz2
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/ 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/ PR target/93654 * gcc.target/i386/pr93654.c: New test.
-rw-r--r--gcc/ChangeLog9
-rw-r--r--gcc/config/i386/i386-options.c4
-rw-r--r--gcc/doc/invoke.texi10
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/gcc.target/i386/pr93654.c9
5 files changed, 34 insertions, 3 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 2287ff9..6741793 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,12 @@
+2020-04-29 H.J. Lu <hongjiu.lu@intel.com>
+
+ 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.
+
2020-04-29 Richard Sandiford <richard.sandiford@arm.com>
* doc/sourcebuild.texi: Add missing arm_arch_v8a_hard_ok anchor.
diff --git a/gcc/config/i386/i386-options.c b/gcc/config/i386/i386-options.c
index e0be493..5c21fce 100644
--- a/gcc/config/i386/i386-options.c
+++ b/gcc/config/i386/i386-options.c
@@ -3083,6 +3083,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");
@@ -3126,6 +3128,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 fed38e8..5bb7d94 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -30097,9 +30097,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
@@ -30112,6 +30112,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 b4d1ee2..b635ce1 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2020-04-29 H.J. Lu <hongjiu.lu@intel.com>
+
+ PR target/93654
+ * gcc.target/i386/pr93654.c: New test.
+
2020-04-29 Richard Sandiford <richard.sandiford@arm.com>
* lib/target-supports.exp: Add v8a_hard to the list of arm_arch_*
diff --git a/gcc/testsuite/gcc.target/i386/pr93654.c b/gcc/testsuite/gcc.target/i386/pr93654.c
new file mode 100644
index 0000000..ec5bdce
--- /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;
+}