From 3ca8e91f0e4452f618dbdc82090ecf47d1bd984c Mon Sep 17 00:00:00 2001 From: Igor Tsimbalist Date: Tue, 6 Feb 2018 16:25:31 +0100 Subject: [PATCH] Fix checking -mibt and -mshstk options for control flow protection 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 | 7 +++ gcc/config/i386/i386.c | 43 ++++++++++++------- gcc/doc/invoke.texi | 4 +- gcc/testsuite/ChangeLog | 10 +++++ gcc/testsuite/c-c++-common/fcf-protection-1.c | 2 +- gcc/testsuite/c-c++-common/fcf-protection-2.c | 2 +- gcc/testsuite/c-c++-common/fcf-protection-3.c | 2 +- gcc/testsuite/c-c++-common/fcf-protection-5.c | 2 +- gcc/testsuite/c-c++-common/fcf-protection-6.c | 4 ++ gcc/testsuite/c-c++-common/fcf-protection-7.c | 4 ++ 10 files changed, 59 insertions(+), 21 deletions(-) create mode 100644 gcc/testsuite/c-c++-common/fcf-protection-6.c create mode 100644 gcc/testsuite/c-c++-common/fcf-protection-7.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index c4d8c959ff5..56d891734f8 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2018-02-06 Igor Tsimbalist + + 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 PR tree-optimization/84228 diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c index 70b6775c4a1..6c612c77987 100644 --- a/gcc/config/i386/i386.c +++ b/gcc/config/i386/i386.c @@ -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); } diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index cf6d3ae5b99..befebed54bc 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -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 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index e8b123dbb37..2e279b4dea0 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,13 @@ +2018-02-06 Igor Tsimbalist + + 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 PR tree-optimization/84228 diff --git a/gcc/testsuite/c-c++-common/fcf-protection-1.c b/gcc/testsuite/c-c++-common/fcf-protection-1.c index 2e9337c3051..8e71f47dde0 100644 --- a/gcc/testsuite/c-c++-common/fcf-protection-1.c +++ b/gcc/testsuite/c-c++-common/fcf-protection-1.c @@ -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 } */ diff --git a/gcc/testsuite/c-c++-common/fcf-protection-2.c b/gcc/testsuite/c-c++-common/fcf-protection-2.c index aa0d2a04645..d7d6db0e95d 100644 --- a/gcc/testsuite/c-c++-common/fcf-protection-2.c +++ b/gcc/testsuite/c-c++-common/fcf-protection-2.c @@ -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 } */ diff --git a/gcc/testsuite/c-c++-common/fcf-protection-3.c b/gcc/testsuite/c-c++-common/fcf-protection-3.c index 028775adc35..5b903c5fa51 100644 --- a/gcc/testsuite/c-c++-common/fcf-protection-3.c +++ b/gcc/testsuite/c-c++-common/fcf-protection-3.c @@ -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 } */ diff --git a/gcc/testsuite/c-c++-common/fcf-protection-5.c b/gcc/testsuite/c-c++-common/fcf-protection-5.c index a5f8e116992..d7a67801e2e 100644 --- a/gcc/testsuite/c-c++-common/fcf-protection-5.c +++ b/gcc/testsuite/c-c++-common/fcf-protection-5.c @@ -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 index 00000000000..084983e4498 --- /dev/null +++ b/gcc/testsuite/c-c++-common/fcf-protection-6.c @@ -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 index 00000000000..9baedf5991a --- /dev/null +++ b/gcc/testsuite/c-c++-common/fcf-protection-7.c @@ -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 } */ -- 2.30.2