diff mbox series

i386: Mask out the CF_SET bit for -fcf-protection check

Message ID 20180206210927.GA238859@intel.com
State New
Headers show
Series i386: Mask out the CF_SET bit for -fcf-protection check | expand

Commit Message

H.J. Lu Feb. 6, 2018, 9:09 p.m. UTC
Since ix86_option_override_internal sets the CF_SET bit in
flag_cf_protection and it can be called more than once via pragma,
we need to mask out the CF_SET bit when checking flag_cf_protection.

OK for trunk if there is no regression?

H.J.
---
	PR target/84248
	* config/i386/i386.c (ix86_option_override_internal): Mask out
	the CF_SET bit when checking -fcf-protection.
---
 gcc/config/i386/i386.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

Comments

Tsimbalist, Igor V Feb. 6, 2018, 9:20 p.m. UTC | #1
> -----Original Message-----
> From: gcc-patches-owner@gcc.gnu.org [mailto:gcc-patches-
> owner@gcc.gnu.org] On Behalf Of H.J. Lu
> Sent: Tuesday, February 6, 2018 10:09 PM
> To: gcc-patches@gcc.gnu.org
> Cc: Uros Bizjak <ubizjak@gmail.com>; Tsimbalist, Igor V
> <igor.v.tsimbalist@intel.com>
> Subject: [PATCH] i386: Mask out the CF_SET bit for -fcf-protection check
> 
> Since ix86_option_override_internal sets the CF_SET bit in
> flag_cf_protection and it can be called more than once via pragma,
> we need to mask out the CF_SET bit when checking flag_cf_protection.
> 
> OK for trunk if there is no regression?

Ok from CET viewpoint.

Thanks,
Igor

> H.J.
> ---
> 	PR target/84248
> 	* config/i386/i386.c (ix86_option_override_internal): Mask out
> 	the CF_SET bit when checking -fcf-protection.
> ---
>  gcc/config/i386/i386.c | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
> index 6c612c77987..ef7ff89bcbb 100644
> --- a/gcc/config/i386/i386.c
> +++ b/gcc/config/i386/i386.c
> @@ -4913,12 +4913,12 @@ ix86_option_override_internal (bool
> main_args_p,
>        = build_target_option_node (opts);
> 
>    /* Do not support control flow instrumentation if CET is not enabled.  */
> -  if (opts->x_flag_cf_protection != CF_NONE)
> +  cf_protection_level cf_protection
> +    = (cf_protection_level) (opts->x_flag_cf_protection & ~CF_SET);
> +  if (cf_protection != CF_NONE)
>      {
> -      switch (flag_cf_protection)
> +      switch (cf_protection)
>  	{
> -	case CF_NONE:
> -	  break;
>  	case CF_BRANCH:
>  	  if (! TARGET_IBT_P (opts->x_ix86_isa_flags2))
>  	    {
> @@ -4953,7 +4953,7 @@ ix86_option_override_internal (bool main_args_p,
>  	}
> 
>        opts->x_flag_cf_protection =
> -	(cf_protection_level) (opts->x_flag_cf_protection | CF_SET);
> +	(cf_protection_level) (cf_protection | CF_SET);
>      }
> 
>    if (ix86_tune_features [X86_TUNE_AVOID_128FMA_CHAINS])
> --
> 2.14.3
Uros Bizjak Feb. 7, 2018, 8:52 a.m. UTC | #2
On Tue, Feb 6, 2018 at 10:20 PM, Tsimbalist, Igor V
<igor.v.tsimbalist@intel.com> wrote:
>> -----Original Message-----
>> From: gcc-patches-owner@gcc.gnu.org [mailto:gcc-patches-
>> owner@gcc.gnu.org] On Behalf Of H.J. Lu
>> Sent: Tuesday, February 6, 2018 10:09 PM
>> To: gcc-patches@gcc.gnu.org
>> Cc: Uros Bizjak <ubizjak@gmail.com>; Tsimbalist, Igor V
>> <igor.v.tsimbalist@intel.com>
>> Subject: [PATCH] i386: Mask out the CF_SET bit for -fcf-protection check
>>
>> Since ix86_option_override_internal sets the CF_SET bit in
>> flag_cf_protection and it can be called more than once via pragma,
>> we need to mask out the CF_SET bit when checking flag_cf_protection.
>>
>> OK for trunk if there is no regression?
>
> Ok from CET viewpoint.

OK.

Thanks,
Uros.

> Thanks,
> Igor
>
>> H.J.
>> ---
>>       PR target/84248
>>       * config/i386/i386.c (ix86_option_override_internal): Mask out
>>       the CF_SET bit when checking -fcf-protection.
>> ---
>>  gcc/config/i386/i386.c | 10 +++++-----
>>  1 file changed, 5 insertions(+), 5 deletions(-)
>>
>> diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
>> index 6c612c77987..ef7ff89bcbb 100644
>> --- a/gcc/config/i386/i386.c
>> +++ b/gcc/config/i386/i386.c
>> @@ -4913,12 +4913,12 @@ ix86_option_override_internal (bool
>> main_args_p,
>>        = build_target_option_node (opts);
>>
>>    /* Do not support control flow instrumentation if CET is not enabled.  */
>> -  if (opts->x_flag_cf_protection != CF_NONE)
>> +  cf_protection_level cf_protection
>> +    = (cf_protection_level) (opts->x_flag_cf_protection & ~CF_SET);
>> +  if (cf_protection != CF_NONE)
>>      {
>> -      switch (flag_cf_protection)
>> +      switch (cf_protection)
>>       {
>> -     case CF_NONE:
>> -       break;
>>       case CF_BRANCH:
>>         if (! TARGET_IBT_P (opts->x_ix86_isa_flags2))
>>           {
>> @@ -4953,7 +4953,7 @@ ix86_option_override_internal (bool main_args_p,
>>       }
>>
>>        opts->x_flag_cf_protection =
>> -     (cf_protection_level) (opts->x_flag_cf_protection | CF_SET);
>> +     (cf_protection_level) (cf_protection | CF_SET);
>>      }
>>
>>    if (ix86_tune_features [X86_TUNE_AVOID_128FMA_CHAINS])
>> --
>> 2.14.3
>
diff mbox series

Patch

diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
index 6c612c77987..ef7ff89bcbb 100644
--- a/gcc/config/i386/i386.c
+++ b/gcc/config/i386/i386.c
@@ -4913,12 +4913,12 @@  ix86_option_override_internal (bool main_args_p,
       = build_target_option_node (opts);
 
   /* Do not support control flow instrumentation if CET is not enabled.  */
-  if (opts->x_flag_cf_protection != CF_NONE)
+  cf_protection_level cf_protection
+    = (cf_protection_level) (opts->x_flag_cf_protection & ~CF_SET);
+  if (cf_protection != CF_NONE)
     {
-      switch (flag_cf_protection)
+      switch (cf_protection)
 	{
-	case CF_NONE:
-	  break;
 	case CF_BRANCH:
 	  if (! TARGET_IBT_P (opts->x_ix86_isa_flags2))
 	    {
@@ -4953,7 +4953,7 @@  ix86_option_override_internal (bool main_args_p,
 	}
 
       opts->x_flag_cf_protection =
-	(cf_protection_level) (opts->x_flag_cf_protection | CF_SET);
+	(cf_protection_level) (cf_protection | CF_SET);
     }
 
   if (ix86_tune_features [X86_TUNE_AVOID_128FMA_CHAINS])