diff mbox series

PR target/96307: Fix KASAN option checking.

Message ID 20201005094953.57824-1-kito.cheng@sifive.com
State New
Headers show
Series PR target/96307: Fix KASAN option checking. | expand

Commit Message

Kito Cheng Oct. 5, 2020, 9:49 a.m. UTC
- Disable kasan if target is unsupported and -fasan-shadow-offset= is not
   given, no matter `--param asan-stack=1` is given or not.

 - Moving KASAN option checking testcase to gcc.dg, those testcase could be
   useful for all other target which not support asan.

 - Verifed on riscv and x86.

gcc/ChangeLog:

	PR target/96307
	* toplev.c (process_options): Remove param_asan_stack checking for kasan
	option checking.

gcc/testsuite/ChangeLog:

	PR target/96307
	* gcc.dg/pr96307.c: New.
	* gcc.target/riscv/pr96260.c: Move this test case from here to ...
	* gcc.dg/pr96260.c: ... here.
	* gcc.target/riscv/pr91441.c: Move this test case from here to ...
	* gcc.dg/pr91441.c: ... here.
	* lib/target-supports.exp (check_effective_target_no_fsanitize_address):
	New proc.
---
 .../{gcc.target/riscv => gcc.dg}/pr91441.c    |  1 +
 .../{gcc.target/riscv => gcc.dg}/pr96260.c    |  1 +
 gcc/testsuite/gcc.dg/pr96307.c                | 25 +++++++++++++++++++
 gcc/testsuite/lib/target-supports.exp         | 11 ++++++++
 gcc/toplev.c                                  |  1 -
 5 files changed, 38 insertions(+), 1 deletion(-)
 rename gcc/testsuite/{gcc.target/riscv => gcc.dg}/pr91441.c (85%)
 rename gcc/testsuite/{gcc.target/riscv => gcc.dg}/pr96260.c (77%)
 create mode 100644 gcc/testsuite/gcc.dg/pr96307.c

Comments

Kito Cheng Oct. 13, 2020, 9:02 a.m. UTC | #1
ping

On Mon, Oct 5, 2020 at 5:49 PM Kito Cheng <kito.cheng@sifive.com> wrote:

>  - Disable kasan if target is unsupported and -fasan-shadow-offset= is not
>    given, no matter `--param asan-stack=1` is given or not.
>
>  - Moving KASAN option checking testcase to gcc.dg, those testcase could be
>    useful for all other target which not support asan.
>
>  - Verifed on riscv and x86.
>
> gcc/ChangeLog:
>
>         PR target/96307
>         * toplev.c (process_options): Remove param_asan_stack checking for
> kasan
>         option checking.
>
> gcc/testsuite/ChangeLog:
>
>         PR target/96307
>         * gcc.dg/pr96307.c: New.
>         * gcc.target/riscv/pr96260.c: Move this test case from here to ...
>         * gcc.dg/pr96260.c: ... here.
>         * gcc.target/riscv/pr91441.c: Move this test case from here to ...
>         * gcc.dg/pr91441.c: ... here.
>         * lib/target-supports.exp
> (check_effective_target_no_fsanitize_address):
>         New proc.
> ---
>  .../{gcc.target/riscv => gcc.dg}/pr91441.c    |  1 +
>  .../{gcc.target/riscv => gcc.dg}/pr96260.c    |  1 +
>  gcc/testsuite/gcc.dg/pr96307.c                | 25 +++++++++++++++++++
>  gcc/testsuite/lib/target-supports.exp         | 11 ++++++++
>  gcc/toplev.c                                  |  1 -
>  5 files changed, 38 insertions(+), 1 deletion(-)
>  rename gcc/testsuite/{gcc.target/riscv => gcc.dg}/pr91441.c (85%)
>  rename gcc/testsuite/{gcc.target/riscv => gcc.dg}/pr96260.c (77%)
>  create mode 100644 gcc/testsuite/gcc.dg/pr96307.c
>
> diff --git a/gcc/testsuite/gcc.target/riscv/pr91441.c
> b/gcc/testsuite/gcc.dg/pr91441.c
> similarity index 85%
> rename from gcc/testsuite/gcc.target/riscv/pr91441.c
> rename to gcc/testsuite/gcc.dg/pr91441.c
> index b55df5e7f00c..4f7a8fbec5e9 100644
> --- a/gcc/testsuite/gcc.target/riscv/pr91441.c
> +++ b/gcc/testsuite/gcc.dg/pr91441.c
> @@ -1,5 +1,6 @@
>  /* PR target/91441 */
>  /* { dg-do compile  } */
> +/* { dg-require-effective-target no_fsanitize_address }*/
>  /* { dg-options "--param asan-stack=1 -fsanitize=kernel-address" } */
>
>  int *bar(int *);
> diff --git a/gcc/testsuite/gcc.target/riscv/pr96260.c
> b/gcc/testsuite/gcc.dg/pr96260.c
> similarity index 77%
> rename from gcc/testsuite/gcc.target/riscv/pr96260.c
> rename to gcc/testsuite/gcc.dg/pr96260.c
> index 229997f877b7..734832f021e3 100644
> --- a/gcc/testsuite/gcc.target/riscv/pr96260.c
> +++ b/gcc/testsuite/gcc.dg/pr96260.c
> @@ -1,5 +1,6 @@
>  /* PR target/96260 */
>  /* { dg-do compile } */
> +/* { dg-require-effective-target no_fsanitize_address }*/
>  /* { dg-options "--param asan-stack=1 -fsanitize=kernel-address
> -fasan-shadow-offset=0x100000" } */
>
>  int *bar(int *);
> diff --git a/gcc/testsuite/gcc.dg/pr96307.c
> b/gcc/testsuite/gcc.dg/pr96307.c
> new file mode 100644
> index 000000000000..cd1c17c9661b
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/pr96307.c
> @@ -0,0 +1,25 @@
> +/* PR target/96307 */
> +/* { dg-do compile } */
> +/* { dg-require-effective-target no_fsanitize_address }*/
> +/* { dg-additional-options "-fsanitize=kernel-address
> --param=asan-instrumentation-with-call-threshold=8" } */
> +
> +#include <limits.h>
> +enum a {test1, test2, test3=INT_MAX};
> +enum a a;
> +enum a *b;
> +
> +void reset (void);
> +
> +void
> +t()
> +{
> +  if (a != test2)
> +    __builtin_abort ();
> +  if (*b != test2)
> +    __builtin_abort ();
> +  reset ();
> +  if (a != test1)
> +    __builtin_abort ();
> +  if (*b != test1)
> +    __builtin_abort ();
> +}
> diff --git a/gcc/testsuite/lib/target-supports.exp
> b/gcc/testsuite/lib/target-supports.exp
> index 8314e443c437..e80b71a2110c 100644
> --- a/gcc/testsuite/lib/target-supports.exp
> +++ b/gcc/testsuite/lib/target-supports.exp
> @@ -10552,3 +10552,14 @@ proc check_effective_target_ident_directive {} {
>         int i;
>      }]
>  }
> +
> +# Return 1 if target is not support address sanitize, 1 otherwise.
> +
> +proc check_effective_target_no_fsanitize_address {} {
> +    if ![check_no_compiler_messages fsanitize_address executable {
> +       int main (void) { return 0; }
> +    }] {
> +       return 1;
> +    }
> +    return 0;
> +}
> diff --git a/gcc/toplev.c b/gcc/toplev.c
> index a4cb8bb262ed..540e131d963d 100644
> --- a/gcc/toplev.c
> +++ b/gcc/toplev.c
> @@ -1842,7 +1842,6 @@ process_options (void)
>
>    if ((flag_sanitize & SANITIZE_KERNEL_ADDRESS)
>        && (targetm.asan_shadow_offset == NULL
> -         && param_asan_stack
>           && !asan_shadow_offset_set_p ()))
>      {
>        warning_at (UNKNOWN_LOCATION, 0,
> --
> 2.28.0
>
>
Martin Liška Oct. 16, 2020, 7:34 a.m. UTC | #2
Hello.

I'm expecting a support for libsanitizer for RISC-V happening soon.
Having that, will we still need this patch?

Thanks,
Martin
Kito Cheng Oct. 16, 2020, 7:41 a.m. UTC | #3
Hi Martin:

I think it is still useful for other targets which are not supporting
libsanitizer yet, so in this patch I also moved related testcases from
gcc.target to gcc.dg.

On Fri, Oct 16, 2020 at 3:34 PM Martin Liška <mliska@suse.cz> wrote:

> Hello.
>
> I'm expecting a support for libsanitizer for RISC-V happening soon.
> Having that, will we still need this patch?
>
> Thanks,
> Martin
>
Martin Liška Oct. 16, 2020, 9:01 a.m. UTC | #4
On 10/16/20 9:41 AM, Kito Cheng wrote:
> I think it is still useful for other targets which are not supporting libsanitizer yet, so in this patch I also moved related testcases from gcc.target to gcc.dg.

All right, I can't approve the patch, but I support it.

Martin
Jeff Law Nov. 5, 2020, 10:21 p.m. UTC | #5
On 10/16/20 3:01 AM, Martin Liška wrote:
> On 10/16/20 9:41 AM, Kito Cheng wrote:
>> I think it is still useful for other targets which are not supporting
>> libsanitizer yet, so in this patch I also moved related testcases
>> from gcc.target to gcc.dg.
>
> All right, I can't approve the patch, but I support it.

Well, that's good enough for me :-)  Approved.


jeff
Kito Cheng Nov. 6, 2020, 3:23 a.m. UTC | #6
Committed, thanks :)

On Fri, Nov 6, 2020 at 6:21 AM Jeff Law <law@redhat.com> wrote:

>
> On 10/16/20 3:01 AM, Martin Liška wrote:
> > On 10/16/20 9:41 AM, Kito Cheng wrote:
> >> I think it is still useful for other targets which are not supporting
> >> libsanitizer yet, so in this patch I also moved related testcases
> >> from gcc.target to gcc.dg.
> >
> > All right, I can't approve the patch, but I support it.
>
> Well, that's good enough for me :-)  Approved.
>
>
> jeff
>
>
>
Kito Cheng Jan. 14, 2021, 9:21 a.m. UTC | #7
It's OK for gcc 10? I just forgot to backport that...

On Fri, Nov 6, 2020 at 11:24 AM Kito Cheng <kito.cheng@sifive.com> wrote:
>
> Committed, thanks :)
>
> On Fri, Nov 6, 2020 at 6:21 AM Jeff Law <law@redhat.com> wrote:
>
> >
> > On 10/16/20 3:01 AM, Martin Liška wrote:
> > > On 10/16/20 9:41 AM, Kito Cheng wrote:
> > >> I think it is still useful for other targets which are not supporting
> > >> libsanitizer yet, so in this patch I also moved related testcases
> > >> from gcc.target to gcc.dg.
> > >
> > > All right, I can't approve the patch, but I support it.
> >
> > Well, that's good enough for me :-)  Approved.
> >
> >
> > jeff
> >
> >
> >
diff mbox series

Patch

diff --git a/gcc/testsuite/gcc.target/riscv/pr91441.c b/gcc/testsuite/gcc.dg/pr91441.c
similarity index 85%
rename from gcc/testsuite/gcc.target/riscv/pr91441.c
rename to gcc/testsuite/gcc.dg/pr91441.c
index b55df5e7f00c..4f7a8fbec5e9 100644
--- a/gcc/testsuite/gcc.target/riscv/pr91441.c
+++ b/gcc/testsuite/gcc.dg/pr91441.c
@@ -1,5 +1,6 @@ 
 /* PR target/91441 */
 /* { dg-do compile  } */
+/* { dg-require-effective-target no_fsanitize_address }*/
 /* { dg-options "--param asan-stack=1 -fsanitize=kernel-address" } */
 
 int *bar(int *);
diff --git a/gcc/testsuite/gcc.target/riscv/pr96260.c b/gcc/testsuite/gcc.dg/pr96260.c
similarity index 77%
rename from gcc/testsuite/gcc.target/riscv/pr96260.c
rename to gcc/testsuite/gcc.dg/pr96260.c
index 229997f877b7..734832f021e3 100644
--- a/gcc/testsuite/gcc.target/riscv/pr96260.c
+++ b/gcc/testsuite/gcc.dg/pr96260.c
@@ -1,5 +1,6 @@ 
 /* PR target/96260 */
 /* { dg-do compile } */
+/* { dg-require-effective-target no_fsanitize_address }*/
 /* { dg-options "--param asan-stack=1 -fsanitize=kernel-address -fasan-shadow-offset=0x100000" } */
 
 int *bar(int *);
diff --git a/gcc/testsuite/gcc.dg/pr96307.c b/gcc/testsuite/gcc.dg/pr96307.c
new file mode 100644
index 000000000000..cd1c17c9661b
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr96307.c
@@ -0,0 +1,25 @@ 
+/* PR target/96307 */
+/* { dg-do compile } */
+/* { dg-require-effective-target no_fsanitize_address }*/
+/* { dg-additional-options "-fsanitize=kernel-address --param=asan-instrumentation-with-call-threshold=8" } */
+
+#include <limits.h>
+enum a {test1, test2, test3=INT_MAX};
+enum a a;
+enum a *b;
+
+void reset (void);
+
+void
+t()
+{
+  if (a != test2)
+    __builtin_abort ();
+  if (*b != test2)
+    __builtin_abort ();
+  reset ();
+  if (a != test1)
+    __builtin_abort ();
+  if (*b != test1)
+    __builtin_abort ();
+}
diff --git a/gcc/testsuite/lib/target-supports.exp b/gcc/testsuite/lib/target-supports.exp
index 8314e443c437..e80b71a2110c 100644
--- a/gcc/testsuite/lib/target-supports.exp
+++ b/gcc/testsuite/lib/target-supports.exp
@@ -10552,3 +10552,14 @@  proc check_effective_target_ident_directive {} {
 	int i;
     }]
 }
+
+# Return 1 if target is not support address sanitize, 1 otherwise.
+
+proc check_effective_target_no_fsanitize_address {} {
+    if ![check_no_compiler_messages fsanitize_address executable {
+	int main (void) { return 0; }
+    }] {
+	return 1;
+    }
+    return 0;
+}
diff --git a/gcc/toplev.c b/gcc/toplev.c
index a4cb8bb262ed..540e131d963d 100644
--- a/gcc/toplev.c
+++ b/gcc/toplev.c
@@ -1842,7 +1842,6 @@  process_options (void)
 
   if ((flag_sanitize & SANITIZE_KERNEL_ADDRESS)
       && (targetm.asan_shadow_offset == NULL
-	  && param_asan_stack
 	  && !asan_shadow_offset_set_p ()))
     {
       warning_at (UNKNOWN_LOCATION, 0,