]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
x86: Allow -fcf-protection with external thunk
authorH.J. Lu <hjl.tools@gmail.com>
Wed, 29 Apr 2020 11:52:46 +0000 (04:52 -0700)
committerH.J. Lu <hjl.tools@gmail.com>
Wed, 29 Apr 2020 12:11:06 +0000 (05:11 -0700)
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)

gcc/ChangeLog
gcc/config/i386/i386.c
gcc/doc/invoke.texi
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.target/i386/pr93654.c [new file with mode: 0644]

index 4cb1497a61f215bd91a8fd4ece06d64097a9d7fc..c0d72cbbdf52afdd3ad15632c1a04c3efc216e7d 100644 (file)
@@ -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
index efe32f3975e923eef2e2013cc995556fe66d485e..ae5046ee6a0a3311f23ca92be18c351fbfc8b37a 100644 (file)
@@ -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");
index b18e9124b4e6e4c7b0854a60e26012cbf0dc8f51..5e6d240dc5d332257a060c85b977cd4333e7cb80 100644 (file)
@@ -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
index ec3b39c1dbdd7151386ba7571735bd1eb2ebdfea..49e8d899e5e443ca33ffbda256a6e853360a0393 100644 (file)
@@ -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 (file)
index 0000000..ec5bdce
--- /dev/null
@@ -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;
+}