i386: Check -mindirect-branch/-mfunction-return with -fcf-protection
authorH.J. Lu <hongjiu.lu@intel.com>
Thu, 21 Feb 2019 13:41:53 +0000 (13:41 +0000)
committerH.J. Lu <hjl@gcc.gnu.org>
Thu, 21 Feb 2019 13:41:53 +0000 (05:41 -0800)
Issue an error when -mindirect-branch or -mfunction-return are used
with incompatible -fcf-protection.

gcc/

PR target/87412
* config/i386/i386.c (ix86_set_indirect_branch_type): Issue an
error for -mindirect-branch/-mfunction-return with incompatible
-fcf-protection.

gcc/testsuite/

PR target/87412
* gcc.target/i386/pr87412-1.c: New file.
* gcc.target/i386/pr87412-2.c: Likewise.
* gcc.target/i386/pr87412-3.c: Likewise.
* gcc.target/i386/pr87412-4.c: Likewise.

From-SVN: r269068

gcc/ChangeLog
gcc/config/i386/i386.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.target/i386/pr87412-1.c [new file with mode: 0644]
gcc/testsuite/gcc.target/i386/pr87412-2.c [new file with mode: 0644]
gcc/testsuite/gcc.target/i386/pr87412-3.c [new file with mode: 0644]
gcc/testsuite/gcc.target/i386/pr87412-4.c [new file with mode: 0644]

index 46c918b166667ebda84c853d67e0dce7c9e584c3..82890730e1c75fb46ec942afd8a73bff9df93578 100644 (file)
@@ -1,3 +1,10 @@
+2019-02-21  H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR target/87412
+       * config/i386/i386.c (ix86_set_indirect_branch_type): Issue an
+       error for -mindirect-branch/-mfunction-return with incompatible
+       -fcf-protection.
+
 2019-02-21  Jakub Jelinek  <jakub@redhat.com>
 
        PR bootstrap/88714
index a58ddca3fab1189a8c8b79afa041236d06dacdf0..81dfed128379a444c9e9afb22adea426293c59d1 100644 (file)
@@ -5667,6 +5667,11 @@ ix86_set_indirect_branch_type (tree fndecl)
               ((cfun->machine->indirect_branch_type
                 == indirect_branch_thunk_extern)
                ? "thunk-extern" : "thunk"));
+
+      if (cfun->machine->indirect_branch_type != indirect_branch_keep
+         && (flag_cf_protection & CF_RETURN))
+       error ("%<-mindirect-branch%> and %<-fcf-protection%> are not "
+              "compatible");
     }
 
   if (cfun->machine->function_return_type == indirect_branch_unset)
@@ -5705,6 +5710,11 @@ ix86_set_indirect_branch_type (tree fndecl)
               ((cfun->machine->function_return_type
                 == indirect_branch_thunk_extern)
                ? "thunk-extern" : "thunk"));
+
+      if (cfun->machine->function_return_type != indirect_branch_keep
+         && (flag_cf_protection & CF_RETURN))
+       error ("%<-mfunction-return%> and %<-fcf-protection%> are not "
+              "compatible");
     }
 }
 
index 2068a41ed7f4748da58eff7ebd2a6672df5ee56b..138d6034f499a90fa6ed52db3ec458ce5c06788d 100644 (file)
@@ -1,3 +1,11 @@
+2019-02-21  H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR target/87412
+       * gcc.target/i386/pr87412-1.c: New file.
+       * gcc.target/i386/pr87412-2.c: Likewise.
+       * gcc.target/i386/pr87412-3.c: Likewise.
+       * gcc.target/i386/pr87412-4.c: Likewise.
+
 2019-02-20  Jakub Jelinek  <jakub@redhat.com>
 
        PR c++/89403
diff --git a/gcc/testsuite/gcc.target/i386/pr87412-1.c b/gcc/testsuite/gcc.target/i386/pr87412-1.c
new file mode 100644 (file)
index 0000000..e04f1fb
--- /dev/null
@@ -0,0 +1,9 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fcf-protection -mfunction-return=thunk -mindirect-branch=thunk" } */
+
+void
+bar (void)
+{
+/* { dg-error "'-mindirect-branch' and '-fcf-protection' are not compatible" "" { target *-*-* } .-1 } */
+/* { dg-error "'-mfunction-return' and '-fcf-protection' are not compatible" "" { target *-*-* } .-2 } */
+}
diff --git a/gcc/testsuite/gcc.target/i386/pr87412-2.c b/gcc/testsuite/gcc.target/i386/pr87412-2.c
new file mode 100644 (file)
index 0000000..33a9e8a
--- /dev/null
@@ -0,0 +1,10 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fcf-protection -mfunction-return=keep -mindirect-branch=keep" } */
+
+void
+ __attribute__ ((indirect_branch("thunk"), function_return("thunk")))
+bar (void)
+{
+/* { dg-error "'-mindirect-branch' and '-fcf-protection' are not compatible" "" { target *-*-* } .-1 } */
+/* { dg-error "'-mfunction-return' and '-fcf-protection' are not compatible" "" { target *-*-* } .-2 } */
+}
diff --git a/gcc/testsuite/gcc.target/i386/pr87412-3.c b/gcc/testsuite/gcc.target/i386/pr87412-3.c
new file mode 100644 (file)
index 0000000..e67d727
--- /dev/null
@@ -0,0 +1,9 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fcf-protection=return -mfunction-return=thunk -mindirect-branch=thunk" } */
+
+void
+bar (void)
+{
+/* { dg-error "'-mindirect-branch' and '-fcf-protection' are not compatible" "" { target *-*-* } .-1 } */
+/* { dg-error "'-mfunction-return' and '-fcf-protection' are not compatible" "" { target *-*-* } .-2 } */
+}
diff --git a/gcc/testsuite/gcc.target/i386/pr87412-4.c b/gcc/testsuite/gcc.target/i386/pr87412-4.c
new file mode 100644 (file)
index 0000000..f90d2f2
--- /dev/null
@@ -0,0 +1,7 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fcf-protection=branch -mfunction-return=thunk -mindirect-branch=thunk" } */
+
+void
+bar (void)
+{
+}