diff options
author | Marek Polacek <polacek@redhat.com> | 2024-04-05 12:37:19 -0400 |
---|---|---|
committer | Marek Polacek <polacek@redhat.com> | 2024-04-10 17:27:38 -0400 |
commit | b8b148bc22673689fda19711b428b544462be2e4 (patch) | |
tree | 8fd7381dbafde56ad43fefc10215cfae3eb8bb7c | |
parent | 4a94551d7eaaf7a75c5195fc0bf4af94185a04c7 (diff) | |
download | gcc-b8b148bc22673689fda19711b428b544462be2e4.zip gcc-b8b148bc22673689fda19711b428b544462be2e4.tar.gz gcc-b8b148bc22673689fda19711b428b544462be2e4.tar.bz2 |
target: missing -Whardened with -fcf-protection=none [PR114606]
-Whardened warns when -fhardened couldn't enable a hardening option
because that option was disabled on the command line, e.g.:
$ ./cc1plus -quiet g.C -fhardened -O2 -fstack-protector
cc1plus: warning: '-fstack-protector-strong' is not enabled by '-fhardened' because it was specified on the command line [-Whardened]
but it doesn't work as expected with -fcf-protection=none:
$ ./cc1plus -quiet g.C -fhardened -O2 -fcf-protection=none
because we're checking == CF_NONE which doesn't distinguish between nothing
and -fcf-protection=none. I should have used opts_set, like below.
PR target/114606
gcc/ChangeLog:
* config/i386/i386-options.cc (ix86_option_override_internal): Use
opts_set rather than checking == CF_NONE.
gcc/testsuite/ChangeLog:
* gcc.target/i386/fhardened-1.c: New test.
* gcc.target/i386/fhardened-2.c: New test.
Reviewed-by: Jakub Jelinek <jakub@redhat.com>
-rw-r--r-- | gcc/config/i386/i386-options.cc | 2 | ||||
-rw-r--r-- | gcc/testsuite/gcc.target/i386/fhardened-1.c | 8 | ||||
-rw-r--r-- | gcc/testsuite/gcc.target/i386/fhardened-2.c | 8 |
3 files changed, 17 insertions, 1 deletions
diff --git a/gcc/config/i386/i386-options.cc b/gcc/config/i386/i386-options.cc index 7896d57..68a2e1c 100644 --- a/gcc/config/i386/i386-options.cc +++ b/gcc/config/i386/i386-options.cc @@ -3242,7 +3242,7 @@ ix86_option_override_internal (bool main_args_p, on the command line. */ if (opts->x_flag_hardened && cf_okay_p) { - if (opts->x_flag_cf_protection == CF_NONE) + if (!opts_set->x_flag_cf_protection) opts->x_flag_cf_protection = CF_FULL; else if (opts->x_flag_cf_protection != CF_FULL) warning_at (UNKNOWN_LOCATION, OPT_Whardened, diff --git a/gcc/testsuite/gcc.target/i386/fhardened-1.c b/gcc/testsuite/gcc.target/i386/fhardened-1.c new file mode 100644 index 0000000..55d1718 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/fhardened-1.c @@ -0,0 +1,8 @@ +/* PR target/114606 */ +/* { dg-options "-fhardened -O2 -fcf-protection=none" } */ + +#ifdef __CET__ +# error "-fcf-protection enabled when it should not be" +#endif + +/* { dg-warning ".-fcf-protection=full. is not enabled by .-fhardened. because it was specified" "" { target *-*-* } 0 } */ diff --git a/gcc/testsuite/gcc.target/i386/fhardened-2.c b/gcc/testsuite/gcc.target/i386/fhardened-2.c new file mode 100644 index 0000000..9b8c138 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/fhardened-2.c @@ -0,0 +1,8 @@ +/* PR target/114606 */ +/* { dg-options "-fhardened -O2" } */ + +#if __CET__ != 3 +# error "-fcf-protection not enabled" +#endif + +/* { dg-bogus ".-fcf-protection=full. is not enabled by .-fhardened. because it was specified" "" { target *-*-* } 0 } */ |