[PATCH] PR target/96260 - KASAN should work even back-end not porting anything.

Jakub Jelinek jakub@redhat.com
Wed Jul 22 10:13:36 GMT 2020


On Wed, Jul 22, 2020 at 04:53:00PM +0800, Kito Cheng wrote:
> --- a/gcc/asan.c
> +++ b/gcc/asan.c
> @@ -344,6 +344,12 @@ asan_shadow_offset ()
>    return asan_shadow_offset_value;
>  }
>  
> +/* Returns Asan shadow offset has been set.  */
> +bool asan_shadow_offset_set_p ()

Formatting.  Should be
bool
asan_shadow_offset_set_p ()

> +{
> +  return asan_shadow_offset_computed;
> +}
> +
>  alias_set_type asan_shadow_set = -1;
>  
>  /* Pointer types to 1, 2 or 4 byte integers in shadow memory.  A separate

> -/* { dg-warning ".'-fsanitize=address' and '-fsanitize=kernel-address' are not supported for this target" "" { target *-*-* } 0 } */
> +/* { dg-warning ".'-fsanitize=kernel-address' with stack protection is not supported without '-fasan-shadow-offset=' for this target." "" { target *-*-* } 0 } */

Please adjust, see below.
> index 95eea63380f6..48f13d282c52 100644
> --- a/gcc/toplev.c
> +++ b/gcc/toplev.c
> @@ -1835,7 +1835,7 @@ process_options (void)
>    /* Address Sanitizer needs porting to each target architecture.  */
>  
>    if ((flag_sanitize & SANITIZE_ADDRESS)
> -      && (!FRAME_GROWS_DOWNWARD || targetm.asan_shadow_offset == NULL))
> +      && !FRAME_GROWS_DOWNWARD)
>      {
>        warning_at (UNKNOWN_LOCATION, 0,
>  		  "%<-fsanitize=address%> and %<-fsanitize=kernel-address%> "
> @@ -1843,6 +1843,25 @@ process_options (void)
>        flag_sanitize &= ~SANITIZE_ADDRESS;
>      }
>  
> +  if ((flag_sanitize & SANITIZE_USER_ADDRESS)
> +      && targetm.asan_shadow_offset == NULL)
> +    {
> +      warning_at (UNKNOWN_LOCATION, 0,
> +		  "%<-fsanitize=address%> not supported for this target");
> +      flag_sanitize &= ~SANITIZE_ADDRESS;
> +    }
> +
> +  if ((flag_sanitize & SANITIZE_KERNEL_ADDRESS)
> +      && (targetm.asan_shadow_offset == NULL && param_asan_stack
> +	  && !asan_shadow_offset_set_p ()))

Formatting.  If there are several &&s (or ||s) and it doesn't fit on one
line, each of them should be on a separate line, so there should be a
newline and indentation instead of space before "&& param_asan_stack".
> +    {
> +      warning_at (UNKNOWN_LOCATION, 0,
> +		  "%<-fsanitize=kernel-address%> with stack protection "
> +		  "is not supported without %<-fasan-shadow-offset=%> "
> +		  "for this target.");

No full stop at the end of diagnostics (plus adjust testcase for it).

Otherwise LGTM for trunk and 10.3 (see Richi's mail).

	Jakub



More information about the Gcc-patches mailing list