From patchwork Mon Jan 5 16:58:53 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 425396 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 075D914009B for ; Tue, 6 Jan 2015 04:40:58 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:reply-to:references:mime-version :content-type:in-reply-to; q=dns; s=default; b=BnjFMFu+eSrCcfVBW xqB2At7xuag7KEAdHY19VuSKxxO0ZPSv/eN4atYSumRUzeJIClGKDHXuJo0x++vF BIH6ci1xRGVIUNdbNyYzGuoGL6BC6EAfZ9pD1GlAjVuH38hwpLgM73NYMKVmrt3A MJ02r07D/9xiANCmsN92Ky/2oA= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:reply-to:references:mime-version :content-type:in-reply-to; s=default; bh=2lZLC0cTeGaIXF/+YebK6L5 NEW4=; b=S8lNb1EcJ7UFrIf477IHuF0u18Tp4KVRU+hvX56Bf7xFII0aswOGRXE fdbYcZQ4DlAD8kIYX9OfzGB8ybkWRWuk9yLak8hisDQ6sMkL405gWRsCEZnepCMC 64XF2Ed62ZEmmoVOnvx6btZtuxuTY73DHpea387eBEREV7tbqDt8= Received: (qmail 5440 invoked by alias); 5 Jan 2015 17:40:51 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 5430 invoked by uid 89); 5 Jan 2015 17:40:51 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.1 required=5.0 tests=AWL, BAYES_00, SPF_HELO_PASS, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Mon, 05 Jan 2015 17:40:49 +0000 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t05Gx0nc025670 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 5 Jan 2015 11:59:01 -0500 Received: from tucnak.zalov.cz (ovpn-116-64.ams2.redhat.com [10.36.116.64]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t05GwwRR012612 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=NO); Mon, 5 Jan 2015 11:59:00 -0500 Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.14.9/8.14.9) with ESMTP id t05Gwug9029961; Mon, 5 Jan 2015 17:58:56 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.14.9/8.14.9/Submit) id t05GwrdZ029960; Mon, 5 Jan 2015 17:58:53 +0100 Date: Mon, 5 Jan 2015 17:58:53 +0100 From: Jakub Jelinek To: Richard Biener , Dodji Seketeli Cc: Alexey Samsonov , Yury Gribov , Marek Polacek , GCC Patches , Dmitry Vyukov , Konstantin Serebryany Subject: [PATCH] -f{no-sanitize,{,no-}sanitize-recover}=all support Message-ID: <20150105165853.GT1667@tucnak.redhat.com> Reply-To: Jakub Jelinek References: <543BADAB.4090000@samsung.com> <20141017161334.GF10376@tucnak.redhat.com> <20141118064740.GE1745@tucnak.redhat.com> <20141118075317.GF1745@tucnak.redhat.com> <20141219080718.GS1667@tucnak.redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) X-IsSubscribed: yes On Tue, Dec 23, 2014 at 04:47:06PM -0800, Alexey Samsonov wrote: > Right, -fsanitize=all produces an error, while -fsanitize-recover=all > enables recovery for all > sanitizers, -fno-sanitize-recover=all disables recovery for everything. Ok, here is a GCC patch for that. -fno-sanitize=all is supported as a way to turn off all the sanitizers, -f{,no-}sanitize-recover=all is supported too, and one can mix all with other sanitizer names. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2015-01-05 Jakub Jelinek * opts.c (common_handle_option): Add support for -fno-sanitize=all and -f{,no-}sanitize-recover=all. * c-c++-common/asan/sanitize-all-1.c: New test. * c-c++-common/ubsan/sanitize-all-1.c: New test. * c-c++-common/ubsan/sanitize-all-2.c: New test. * c-c++-common/ubsan/sanitize-all-3.c: New test. * c-c++-common/ubsan/sanitize-all-4.c: New test. Jakub --- gcc/opts.c.jj 2015-01-05 15:37:15.155023474 +0100 +++ gcc/opts.c 2015-01-05 16:05:18.659760976 +0100 @@ -1588,6 +1588,7 @@ common_handle_option (struct gcc_options sizeof "returns-nonnull-attribute" - 1 }, { "object-size", SANITIZE_OBJECT_SIZE, sizeof "object-size" - 1 }, + { "all", ~0, sizeof "all" - 1 }, { NULL, 0, 0 } }; const char *comma; @@ -1611,7 +1612,15 @@ common_handle_option (struct gcc_options && memcmp (p, spec[i].name, len) == 0) { /* Handle both -fsanitize and -fno-sanitize cases. */ - if (value) + if (value && spec[i].flag == ~0U) + { + if (code == OPT_fsanitize_) + error_at (loc, "-fsanitize=all option is not valid"); + else + *flag |= ~(SANITIZE_USER_ADDRESS | SANITIZE_THREAD + | SANITIZE_LEAK); + } + else if (value) *flag |= spec[i].flag; else *flag &= ~spec[i].flag; --- gcc/testsuite/c-c++-common/asan/sanitize-all-1.c.jj 2015-01-05 15:41:43.515357551 +0100 +++ gcc/testsuite/c-c++-common/asan/sanitize-all-1.c 2015-01-05 15:41:43.515357551 +0100 @@ -0,0 +1,12 @@ +/* { dg-do compile } */ +/* { dg-options "-fno-sanitize=all" } */ + +volatile int ten = 10; + +int main() { + volatile char x[10]; + x[ten]; + return 0; +} + +/* { dg-final { scan-assembler-not "__asan_load" } } */ --- gcc/testsuite/c-c++-common/ubsan/sanitize-all-1.c.jj 2015-01-05 15:41:43.515357551 +0100 +++ gcc/testsuite/c-c++-common/ubsan/sanitize-all-1.c 2015-01-05 15:41:43.515357551 +0100 @@ -0,0 +1,8 @@ +/* Test -f*sanitize*=all */ +/* { dg-do compile } */ +/* { dg-skip-if "" { *-*-* } { "*" } { "-O2" } } */ +/* { dg-options "-fsanitize=all" } */ + +int i; + +/* { dg-error "-fsanitize=all option is not valid" "" { target *-*-* } 0 } */ --- gcc/testsuite/c-c++-common/ubsan/sanitize-all-2.c.jj 2015-01-05 15:41:43.516357533 +0100 +++ gcc/testsuite/c-c++-common/ubsan/sanitize-all-2.c 2015-01-05 17:46:57.634523012 +0100 @@ -0,0 +1,41 @@ +/* Test -f*sanitize*=all */ +/* { dg-do run } */ +/* { dg-skip-if "" { *-*-* } { "*" } { "-O2" } } */ +/* { dg-skip-if "" { *-*-* } { "-flto -fno-fat-lto-objects" } } */ +/* { dg-options "-fsanitize=undefined,float-cast-overflow,float-divide-by-zero -fno-sanitize=all -fdump-tree-optimized" } */ + +int a[4]; + +int +f1 (int x, int y, int z) +{ + return a[x] + (1 << y) + (100 / z); +} + +char * +f2 (int x) +{ + char *p = (char *) __builtin_calloc (64, 1); + p[x] = 3; + return p; +} + +int +f3 (int x, int *y, double z, double w) +{ + int a[*y]; + if (x) + __builtin_unreachable (); + asm volatile ("" : : "r" (&a[0])); + return z / w; +} + +int +main () +{ + return 0; +} + +/* { dg-final { scan-tree-dump-not "__ubsan_" "optimized" } } */ +/* { dg-final { scan-tree-dump-not "UBSAN_CHECK_" "optimized" } } */ +/* { dg-final { cleanup-tree-dump "optimized" } } */ --- gcc/testsuite/c-c++-common/ubsan/sanitize-all-3.c.jj 2015-01-05 15:41:43.516357533 +0100 +++ gcc/testsuite/c-c++-common/ubsan/sanitize-all-3.c 2015-01-05 17:47:03.768418951 +0100 @@ -0,0 +1,42 @@ +/* Test -f*sanitize*=all */ +/* { dg-do run } */ +/* { dg-skip-if "" { *-*-* } { "*" } { "-O2" } } */ +/* { dg-skip-if "" { *-*-* } { "-flto -fno-fat-lto-objects" } } */ +/* { dg-options "-fsanitize=undefined -fsanitize-recover=all -fdump-tree-optimized" } */ + +int a[4]; + +int +f1 (int x, int y, int z) +{ + return a[x] + (1 << y) + (100 / z); +} + +char * +f2 (int x) +{ + char *p = (char *) __builtin_calloc (64, 1); + p[x] = 3; + return p; +} + +int +f3 (int x, int *y, double z, double w) +{ + int a[*y]; + if (x) + __builtin_unreachable (); + asm volatile ("" : : "r" (&a[0])); + return z / w; +} + +int +main () +{ + return 0; +} + +/* { dg-final { scan-tree-dump "__ubsan_" "optimized" } } */ +/* { dg-final { scan-tree-dump-not "__ubsan_\[a-z_\]*_abort" "optimized" } } */ +/* { dg-final { scan-tree-dump "UBSAN_CHECK_" "optimized" } } */ +/* { dg-final { cleanup-tree-dump "optimized" } } */ --- gcc/testsuite/c-c++-common/ubsan/sanitize-all-4.c.jj 2015-01-05 15:41:43.516357533 +0100 +++ gcc/testsuite/c-c++-common/ubsan/sanitize-all-4.c 2015-01-05 17:47:09.969313754 +0100 @@ -0,0 +1,42 @@ +/* Test -f*sanitize*=all */ +/* { dg-do run } */ +/* { dg-skip-if "" { *-*-* } { "*" } { "-O2" } } */ +/* { dg-skip-if "" { *-*-* } { "-flto -fno-fat-lto-objects" } } */ +/* { dg-options "-fsanitize=undefined -fno-sanitize-recover=all -fdump-tree-optimized" } */ + +int a[4]; + +int +f1 (int x, int y, int z) +{ + return a[x] + (1 << y) + (100 / z); +} + +char * +f2 (int x) +{ + char *p = (char *) __builtin_calloc (64, 1); + p[x] = 3; + return p; +} + +int +f3 (int x, int *y, double z, double w) +{ + int a[*y]; + if (x) + __builtin_unreachable (); + asm volatile ("" : : "r" (&a[0])); + return z / w; +} + +int +main () +{ + return 0; +} + +/* { dg-final { scan-tree-dump "__ubsan_\[a-z_\]*_abort" "optimized" } } */ +/* { dg-final { scan-tree-dump-not "__ubsan_\[a-z_\]*\[^et\] " "optimized" } } */ +/* { dg-final { scan-tree-dump "UBSAN_CHECK_" "optimized" } } */ +/* { dg-final { cleanup-tree-dump "optimized" } } */