public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] PR target/96307: Fix KASAN option checking.
@ 2020-10-05  9:49 Kito Cheng
  2020-10-13  9:02 ` Kito Cheng
  0 siblings, 1 reply; 8+ messages in thread
From: Kito Cheng @ 2020-10-05  9:49 UTC (permalink / raw)
  To: gcc-patches, kito.cheng; +Cc: Kito Cheng

 - 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


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] PR target/96307: Fix KASAN option checking.
  2020-10-05  9:49 [PATCH] PR target/96307: Fix KASAN option checking Kito Cheng
@ 2020-10-13  9:02 ` Kito Cheng
  2020-10-16  7:34   ` Martin Liška
  0 siblings, 1 reply; 8+ messages in thread
From: Kito Cheng @ 2020-10-13  9:02 UTC (permalink / raw)
  To: GCC Patches, Kito Cheng

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
>
>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] PR target/96307: Fix KASAN option checking.
  2020-10-13  9:02 ` Kito Cheng
@ 2020-10-16  7:34   ` Martin Liška
  2020-10-16  7:41     ` Kito Cheng
  0 siblings, 1 reply; 8+ messages in thread
From: Martin Liška @ 2020-10-16  7:34 UTC (permalink / raw)
  To: Kito Cheng, GCC Patches, Kito Cheng

Hello.

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

Thanks,
Martin

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] PR target/96307: Fix KASAN option checking.
  2020-10-16  7:34   ` Martin Liška
@ 2020-10-16  7:41     ` Kito Cheng
  2020-10-16  9:01       ` Martin Liška
  0 siblings, 1 reply; 8+ messages in thread
From: Kito Cheng @ 2020-10-16  7:41 UTC (permalink / raw)
  To: Martin Liška; +Cc: GCC Patches, Kito Cheng

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
>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] PR target/96307: Fix KASAN option checking.
  2020-10-16  7:41     ` Kito Cheng
@ 2020-10-16  9:01       ` Martin Liška
  2020-11-05 22:21         ` Jeff Law
  0 siblings, 1 reply; 8+ messages in thread
From: Martin Liška @ 2020-10-16  9:01 UTC (permalink / raw)
  To: Kito Cheng; +Cc: GCC Patches, Kito Cheng

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] PR target/96307: Fix KASAN option checking.
  2020-10-16  9:01       ` Martin Liška
@ 2020-11-05 22:21         ` Jeff Law
  2020-11-06  3:23           ` Kito Cheng
  0 siblings, 1 reply; 8+ messages in thread
From: Jeff Law @ 2020-11-05 22:21 UTC (permalink / raw)
  To: Martin Liška, Kito Cheng; +Cc: GCC Patches, Kito Cheng


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



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] PR target/96307: Fix KASAN option checking.
  2020-11-05 22:21         ` Jeff Law
@ 2020-11-06  3:23           ` Kito Cheng
  2021-01-14  9:21             ` Kito Cheng
  0 siblings, 1 reply; 8+ messages in thread
From: Kito Cheng @ 2020-11-06  3:23 UTC (permalink / raw)
  To: Jeff Law; +Cc: Martin Liška, GCC Patches, Kito Cheng

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
>
>
>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] PR target/96307: Fix KASAN option checking.
  2020-11-06  3:23           ` Kito Cheng
@ 2021-01-14  9:21             ` Kito Cheng
  0 siblings, 0 replies; 8+ messages in thread
From: Kito Cheng @ 2021-01-14  9:21 UTC (permalink / raw)
  To: Kito Cheng; +Cc: Jeff Law, GCC Patches

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
> >
> >
> >

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2021-01-14  9:21 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-05  9:49 [PATCH] PR target/96307: Fix KASAN option checking Kito Cheng
2020-10-13  9:02 ` Kito Cheng
2020-10-16  7:34   ` Martin Liška
2020-10-16  7:41     ` Kito Cheng
2020-10-16  9:01       ` Martin Liška
2020-11-05 22:21         ` Jeff Law
2020-11-06  3:23           ` Kito Cheng
2021-01-14  9:21             ` Kito Cheng

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).