Fix checking -mibt and -mshstk options for control flow protection
authorIgor Tsimbalist <igor.v.tsimbalist@intel.com>
Tue, 6 Feb 2018 15:25:31 +0000 (16:25 +0100)
committerIgor Tsimbalist <itsimbal@gcc.gnu.org>
Tue, 6 Feb 2018 15:25:31 +0000 (16:25 +0100)
PR target/84145
* config/i386/i386.c: Reimplement the check of possible options
-mibt/-mshstk conbination. Change error messages.
* doc/invoke.texi: Fix a typo: remove extra '='.
* c-c++-common/fcf-protection-1.c: Change a compared message.
* c-c++-common/fcf-protection-2.c: Likewise.
* c-c++-common/fcf-protection-3.c: Likewise.
* c-c++-common/fcf-protection-5.c: Likewise.
* c-c++-common/fcf-protection-6.c: New test.
* c-c++-common/fcf-protection-7.c: Likewise.

From-SVN: r257414

gcc/ChangeLog
gcc/config/i386/i386.c
gcc/doc/invoke.texi
gcc/testsuite/ChangeLog
gcc/testsuite/c-c++-common/fcf-protection-1.c
gcc/testsuite/c-c++-common/fcf-protection-2.c
gcc/testsuite/c-c++-common/fcf-protection-3.c
gcc/testsuite/c-c++-common/fcf-protection-5.c
gcc/testsuite/c-c++-common/fcf-protection-6.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/fcf-protection-7.c [new file with mode: 0644]

index c4d8c959ff53415cafafd775ad07c016cb1131bb..56d891734f8b3fd3c005bb2ea7109a406d5fd8fe 100644 (file)
@@ -1,3 +1,10 @@
+2018-02-06  Igor Tsimbalist  <igor.v.tsimbalist@intel.com>
+
+       PR target/84145
+       * config/i386/i386.c: Reimplement the check of possible options
+       -mibt/-mshstk conbination. Change error messages.
+       * doc/invoke.texi: Fix a typo: remove extra '='.
+
 2018-02-06  Marek Polacek  <polacek@redhat.com>
 
        PR tree-optimization/84228
index 70b6775c4a1efeeae1587f36874fd1bfff21f34d..6c612c7798739a3d14a3cebc943aad5472b5833b 100644 (file)
@@ -4915,30 +4915,43 @@ ix86_option_override_internal (bool main_args_p,
   /* Do not support control flow instrumentation if CET is not enabled.  */
   if (opts->x_flag_cf_protection != CF_NONE)
     {
-      if (!(TARGET_IBT_P (opts->x_ix86_isa_flags2)
-           || TARGET_SHSTK_P (opts->x_ix86_isa_flags)))
+      switch (flag_cf_protection)
        {
-         if (flag_cf_protection == CF_FULL)
+       case CF_NONE:
+         break;
+       case CF_BRANCH:
+         if (! TARGET_IBT_P (opts->x_ix86_isa_flags2))
            {
-             error ("%<-fcf-protection=full%> requires CET support "
-                    "on this target. Use -mcet or one of -mibt, "
-                    "-mshstk options to enable CET");
+             error ("%<-fcf-protection=branch%> requires Intel CET "
+                    "support. Use -mcet or -mibt option to enable CET");
+             flag_cf_protection = CF_NONE;
+             return false;
            }
-         else if (flag_cf_protection == CF_BRANCH)
+         break;
+       case CF_RETURN:
+         if (! TARGET_SHSTK_P (opts->x_ix86_isa_flags))
            {
-             error ("%<-fcf-protection=branch%> requires CET support "
-                    "on this target. Use -mcet or one of -mibt, "
-                    "-mshstk options to enable CET");
+             error ("%<-fcf-protection=return%> requires Intel CET "
+                    "support. Use -mcet or -mshstk option to enable CET");
+             flag_cf_protection = CF_NONE;
+             return false;
            }
-         else if (flag_cf_protection == CF_RETURN)
+         break;
+       case CF_FULL:
+         if (   ! TARGET_IBT_P (opts->x_ix86_isa_flags2)
+                || ! TARGET_SHSTK_P (opts->x_ix86_isa_flags))
            {
-             error ("%<-fcf-protection=return%> requires CET support "
-                    "on this target. Use -mcet or one of -mibt, "
+             error ("%<-fcf-protection=full%> requires Intel CET "
+                    "support. Use -mcet or both of -mibt and "
                     "-mshstk options to enable CET");
+             flag_cf_protection = CF_NONE;
+             return false;
            }
-         flag_cf_protection = CF_NONE;
-         return false;
+         break;
+       default:
+         gcc_unreachable ();
        }
+
       opts->x_flag_cf_protection =
        (cf_protection_level) (opts->x_flag_cf_protection | CF_SET);
     }
index cf6d3ae5b990d32dcb97b82f4522f388c3217ea7..befebed54bcd60c81e441e696f7152abfd8056f3 100644 (file)
@@ -463,7 +463,7 @@ Objective-C and Objective-C++ Dialects}.
 -fchkp-check-read  -fchkp-check-write  -fchkp-store-bounds @gol
 -fchkp-instrument-calls  -fchkp-instrument-marked-only @gol
 -fchkp-use-wrappers  -fchkp-flexible-struct-trailing-arrays@gol
--fcf-protection==@r{[}full@r{|}branch@r{|}return@r{|}none@r{]} @gol
+-fcf-protection=@r{[}full@r{|}branch@r{|}return@r{|}none@r{]} @gol
 -fstack-protector  -fstack-protector-all  -fstack-protector-strong @gol
 -fstack-protector-explicit  -fstack-check @gol
 -fstack-limit-register=@var{reg}  -fstack-limit-symbol=@var{sym} @gol
@@ -11631,7 +11631,7 @@ is used to link a program, the GCC driver automatically links
 against @file{libmpxwrappers}.  See also @option{-static-libmpxwrappers}.
 Enabled by default.
 
-@item -fcf-protection==@r{[}full@r{|}branch@r{|}return@r{|}none@r{]}
+@item -fcf-protection=@r{[}full@r{|}branch@r{|}return@r{|}none@r{]}
 @opindex fcf-protection
 Enable code instrumentation of control-flow transfers to increase
 program security by checking that target addresses of control-flow
index e8b123dbb37486f5697c23054c584ae4509e80e1..2e279b4dea0e4ad9f4f66caa9eff5ce3cb8f5c91 100644 (file)
@@ -1,3 +1,13 @@
+2018-02-06  Igor Tsimbalist  <igor.v.tsimbalist@intel.com>
+
+       PR target/84145
+       * c-c++-common/fcf-protection-1.c: Change a compared message.
+       * c-c++-common/fcf-protection-2.c: Likewise.
+       * c-c++-common/fcf-protection-3.c: Likewise.
+       * c-c++-common/fcf-protection-5.c: Likewise.
+       * c-c++-common/fcf-protection-6.c: New test.
+       * c-c++-common/fcf-protection-7.c: Likewise.
+
 2018-02-06  Marek Polacek  <polacek@redhat.com>
 
        PR tree-optimization/84228
index 2e9337c30512950ed1105573d1859c3578059fe3..8e71f47dde037847e09f93eed592d0a986d1687b 100644 (file)
@@ -1,4 +1,4 @@
 /* { dg-do compile } */
 /* { dg-options "-fcf-protection=full" } */
-/* { dg-error "'-fcf-protection=full' requires CET support on this target" "" { target { "i?86-*-* x86_64-*-*" } } 0 } */
+/* { dg-error "'-fcf-protection=full' requires Intel CET.*-mcet.*-mibt and -mshstk option" "" { target { "i?86-*-* x86_64-*-*" } } 0 } */
 /* { dg-error "'-fcf-protection=full' is not supported for this target" "" { target { ! "i?86-*-* x86_64-*-*" } } 0 } */
index aa0d2a04645e8ef406e2967b54e8bbf532ec6f23..d7d6db0e95df529b07242642a6df232d32c9d6c6 100644 (file)
@@ -1,4 +1,4 @@
 /* { dg-do compile } */
 /* { dg-options "-fcf-protection=branch" } */
-/* { dg-error "'-fcf-protection=branch' requires CET support on this target" "" { target { "i?86-*-* x86_64-*-*" } } 0 } */
+/* { dg-error "'-fcf-protection=branch' requires Intel CET.*-mcet or -mibt option" "" { target { "i?86-*-* x86_64-*-*" } } 0 } */
 /* { dg-error "'-fcf-protection=branch' is not supported for this target" "" { target { ! "i?86-*-* x86_64-*-*" } } 0 } */
index 028775adc357137200de2a9b0505d52ef86bc36d..5b903c5fa518c2532889418331c17f33976eca1c 100644 (file)
@@ -1,4 +1,4 @@
 /* { dg-do compile } */
 /* { dg-options "-fcf-protection=return" } */
-/* { dg-error "'-fcf-protection=return' requires CET support on this target" "" { target { "i?86-*-* x86_64-*-*" } } 0 } */
+/* { dg-error "'-fcf-protection=return' requires Intel CET.*-mcet or -mshstk option" "" { target { "i?86-*-* x86_64-*-*" } } 0 } */
 /* { dg-error "'-fcf-protection=return' is not supported for this target" "" { target { ! "i?86-*-* x86_64-*-*" } } 0 } */
index a5f8e116992ffb404018782989f181e2b2d6e4a2..d7a67801e2effda8a774a10104ca873bb073bacb 100644 (file)
@@ -1,4 +1,4 @@
 /* { dg-do compile } */
 /* { dg-options "-fcf-protection" } */
-/* { dg-error "'-fcf-protection=full' requires CET support on this target" "" { target { "i?86-*-* x86_64-*-*" } } 0 } */
+/* { dg-error "'-fcf-protection=full' requires Intel CET.*-mcet.*-mibt and -mshstk option" "" { target { "i?86-*-* x86_64-*-*" } } 0 } */
 /* { dg-error "'-fcf-protection=full' is not supported for this target" "" { target { ! "i?86-*-* x86_64-*-*" } } 0 } */
diff --git a/gcc/testsuite/c-c++-common/fcf-protection-6.c b/gcc/testsuite/c-c++-common/fcf-protection-6.c
new file mode 100644 (file)
index 0000000..084983e
--- /dev/null
@@ -0,0 +1,4 @@
+/* { dg-do compile } */
+/* { dg-options "-fcf-protection=branch -mshstk" } */
+/* { dg-error "'-fcf-protection=branch' requires Intel CET.*-mcet or -mibt option" "" { target { "i?86-*-* x86_64-*-*" } } 0 } */
+/* { dg-error "'-fcf-protection=branch' is not supported for this target" "" { target { ! "i?86-*-* x86_64-*-*" } } 0 } */
diff --git a/gcc/testsuite/c-c++-common/fcf-protection-7.c b/gcc/testsuite/c-c++-common/fcf-protection-7.c
new file mode 100644 (file)
index 0000000..9baedf5
--- /dev/null
@@ -0,0 +1,4 @@
+/* { dg-do compile } */
+/* { dg-options "-fcf-protection=return -mibt" } */
+/* { dg-error "'-fcf-protection=return' requires Intel CET.*-mcet or -mshstk option" "" { target { "i?86-*-* x86_64-*-*" } } 0 } */
+/* { dg-error "'-fcf-protection=return' is not supported for this target" "" { target { ! "i?86-*-* x86_64-*-*" } } 0 } */