From patchwork Mon Oct 5 09:49:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kito Cheng X-Patchwork-Id: 1376720 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=sifive.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=sifive.com header.i=@sifive.com header.a=rsa-sha256 header.s=google header.b=WMpL/Ynv; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4C4bRx6hgbz9sSn for ; Mon, 5 Oct 2020 20:50:05 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0A4F5386F030; Mon, 5 Oct 2020 09:50:04 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pf1-x441.google.com (mail-pf1-x441.google.com [IPv6:2607:f8b0:4864:20::441]) by sourceware.org (Postfix) with ESMTPS id 94E463850406 for ; Mon, 5 Oct 2020 09:50:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 94E463850406 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=sifive.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=kito.cheng@sifive.com Received: by mail-pf1-x441.google.com with SMTP id n14so6506218pff.6 for ; Mon, 05 Oct 2020 02:50:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=a4oW/mIAh05kLZ+xZgqWftXV2dj0RhY7crJVSAOlL9U=; b=WMpL/YnvTWANjXRQrFxISVyyWC4GkshyX+U1Qm4/YTlGVgG5RpXlx0k6up/kE8/2l/ aDBdRgzDrRih9c/N6tr6woMRCitGeytLboeusEUiMMOo5iYe1wChIHlcknfh/3X54LQi F6Fq6uTPYHlFem4uIX6NmOlCmLn3p0jpX9qKqFjl7XuBTzs3Xj/5xFZysgAguuUWKioA ur30MjIL70OfXK2wTOJJkwv5qEUANtVUXCXRVCFb/NlAGF9vu3T224UlEY7wCx/EsY6a +482GmYXCdftb6q7HE0eTVzDgVCf8RfV6bnfL5CtrPb3giJy+Bk81LpeT0aednm48VDo /Ccw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=a4oW/mIAh05kLZ+xZgqWftXV2dj0RhY7crJVSAOlL9U=; b=Wgv5erBu9zXGnMbJYZYeBMiQCir5mQn54znrmP0Nyts0XrF6t/6/HZwnbILV7RGWyD S33qvN0w3MdDpfyI1xd5MgF0yOnaG+DRdXDu2sYvkerHswQSOJdS/KWeajexl36zYhc8 Aekvv23EjUNCE14sCHTr/j6mHMW+1eQ0mJYEYEKDKTlORwnE9ZAcNgvn0Z5CQ8hZdyLW tRYbxTLA01ml8RbxCe54+HiU2ySKmeZhen8pTD1Llju/JjqRGNZ81nF5QQ6zNCEGZTon wunp2ufntaYXRNPC1iNAwKPkdInJ9+CuybFQjwVwp+/zeEUsbbiDnFtMxNO1tl9VCx6v Cf0w== X-Gm-Message-State: AOAM530Pt0/daCzuC6x+C2aa8sP6i0sJ4cZKPFuBso9TpqYYcfXrZNFR RzJfZIAEZRU433lVBTBZ4BYt9HkkJE1u07mW X-Google-Smtp-Source: ABdhPJyCpSa2LuOSU7twPcP2JRqm6mzUCATvaWVXckHqbuwWZSM2VnVv/0VuMdkGpOP/+E1jN7HG2A== X-Received: by 2002:a62:ee10:0:b029:142:2501:3972 with SMTP id e16-20020a62ee100000b029014225013972mr16001118pfi.55.1601891399201; Mon, 05 Oct 2020 02:49:59 -0700 (PDT) Received: from hsinchu02.internal.sifive.com (114-34-229-221.HINET-IP.hinet.net. [114.34.229.221]) by smtp.gmail.com with ESMTPSA id m20sm11790990pfa.115.2020.10.05.02.49.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Oct 2020 02:49:58 -0700 (PDT) From: Kito Cheng To: gcc-patches@gcc.gnu.org, kito.cheng@gmail.com Subject: [PATCH] PR target/96307: Fix KASAN option checking. Date: Mon, 5 Oct 2020 17:49:53 +0800 Message-Id: <20201005094953.57824-1-kito.cheng@sifive.com> X-Mailer: git-send-email 2.28.0 MIME-Version: 1.0 X-Spam-Status: No, score=-13.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kito Cheng Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" - 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 +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,