From patchwork Thu Feb 28 20:15:51 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 224180 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]) by ozlabs.org (Postfix) with SMTP id 433652C02A9 for ; Fri, 1 Mar 2013 07:16:28 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1362687388; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Received:Date:From:To:Cc:Subject:Message-ID:Reply-To: MIME-Version:Content-Type:Content-Disposition:User-Agent: Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:Sender:Delivered-To; bh=dbJj3HTEwserl20gr/2n 5MYfzO8=; b=ZZSnqv54JYaaj2FuGK+UQx5Uqxe91rzF4qADV8UEusWZVBAnEJPM /Y8ASDsDL83obfho2yUOCxiJcXnhvB+B9R7xoHZVdOqMMHx3A9J1X9jbY4/OqGgY GLA8mX8Tl33GKrZ0Hdva1fUg3SkAwGNBBzODIFH+QjODBKtm6oZADaI= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Received:Received:Date:From:To:Cc:Subject:Message-ID:Reply-To:MIME-Version:Content-Type:Content-Disposition:User-Agent:X-IsSubscribed:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=wRVSXsyF1sGpHCTqJA/oLrImP8TrF1Bq6LLlQlOK52nhpXP9xvocrJT5V7Zyar k8t9nDCv0EyZJIatfJku/BlqhwA9w5MRkzw50183GejUVbfo0TeGUWqjs31DLqHz 8epOdXcp/Moppyd1GccR9sYjiyTysdGexgXLQit9BnUZs=; Received: (qmail 23928 invoked by alias); 28 Feb 2013 20:16:16 -0000 Received: (qmail 23883 invoked by uid 22791); 28 Feb 2013 20:16:07 -0000 X-SWARE-Spam-Status: No, hits=-6.6 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, KHOP_SPAMHAUS_DROP, RCVD_IN_DNSWL_HI, RCVD_IN_HOSTKARMA_W, RP_MATCHES_RCVD, SPF_HELO_PASS X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 28 Feb 2013 20:15:54 +0000 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r1SKFrub025261 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 28 Feb 2013 15:15:54 -0500 Received: from zalov.cz (vpn1-4-4.ams2.redhat.com [10.36.4.4]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r1SKFq6Q031573 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 28 Feb 2013 15:15:53 -0500 Received: from zalov.cz (localhost [127.0.0.1]) by zalov.cz (8.14.5/8.14.5) with ESMTP id r1SKFpFa025023; Thu, 28 Feb 2013 21:15:51 +0100 Received: (from jakub@localhost) by zalov.cz (8.14.5/8.14.5/Submit) id r1SKFpWe025022; Thu, 28 Feb 2013 21:15:51 +0100 Date: Thu, 28 Feb 2013 21:15:51 +0100 From: Jakub Jelinek To: Konstantin Serebryany , Dodji Seketeli Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] Add no_sanitize_address attribute (PR sanitizer/56454) Message-ID: <20130228201551.GZ12913@tucnak.redhat.com> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes 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 Hi! I'm not very happy about the renaming of the attribute, but it happened in clang already, so here is a patch to do the same in gcc too. The old name of the attribute is recognized too for compatibility e.g. with code written for clang 3.[12] sanitizer, and during attribute parsing changed into no_sanitize_address attribute which asan.c later tests. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2013-02-28 Konstantin Serebryany Jakub Jelinek PR sanitizer/56454 * asan.c (gate_asan): Lookup no_sanitize_address instead of no_address_safety_analysis attribute. * doc/extend.texi (no_address_safety_attribute): Rename to no_sanitize_address attribute, mention no_address_safety_analysis attribute as deprecated alias. * c-common.c (handle_no_sanitize_address_attribute): New function. (c_common_attribute_table): Add no_sanitize_address attribute. (handle_no_address_safety_analysis_attribute): Add no_sanitize_address attribute, not no_address_safety_analysis attribute. * g++.dg/asan/default-options-1.C (__asan_default_options): Use no_sanitize_address attribute rather than no_address_safety_analysis. * g++.dg/asan/sanitizer_test_utils.h (ATTRIBUTE_NO_ADDRESS_SAFETY_ANALYSIS): Likewise. * c-c++-common/asan/attrib-1.c: Test no_sanitize_address attribute in addition to no_address_safety_analysis. Jakub --- gcc/asan.c.jj 2013-02-18 16:39:55.600894178 +0100 +++ gcc/asan.c 2013-02-28 17:29:07.520363403 +0100 @@ -2278,6 +2278,6 @@ gate_asan (void) { return flag_asan != 0 - && !lookup_attribute ("no_address_safety_analysis", + && !lookup_attribute ("no_sanitize_address", DECL_ATTRIBUTES (current_function_decl)); } --- gcc/c-family/c-common.c.jj 2013-02-19 07:40:00.348377798 +0100 +++ gcc/c-family/c-common.c 2013-02-28 18:01:59.549869867 +0100 @@ -307,8 +307,10 @@ static tree handle_common_attribute (tre static tree handle_noreturn_attribute (tree *, tree, tree, int, bool *); static tree handle_hot_attribute (tree *, tree, tree, int, bool *); static tree handle_cold_attribute (tree *, tree, tree, int, bool *); +static tree handle_no_sanitize_address_attribute (tree *, tree, tree, + int, bool *); static tree handle_no_address_safety_analysis_attribute (tree *, tree, tree, int, bool *); static tree handle_noinline_attribute (tree *, tree, tree, int, bool *); static tree handle_noclone_attribute (tree *, tree, tree, int, bool *); static tree handle_leaf_attribute (tree *, tree, tree, int, bool *); @@ -715,6 +717,9 @@ const struct attribute_spec c_common_att 0, 0, true, false, false, handle_no_address_safety_analysis_attribute, false }, + { "no_sanitize_address", 0, 0, true, false, false, + handle_no_sanitize_address_attribute, + false }, { "warning", 1, 1, true, false, false, handle_error_attribute, false }, { "error", 1, 1, true, false, false, @@ -6505,12 +6510,12 @@ handle_cold_attribute (tree *node, tree return NULL_TREE; } -/* Handle a "no_address_safety_analysis" attribute; arguments as in +/* Handle a "no_sanitize_address" attribute; arguments as in struct attribute_spec.handler. */ static tree -handle_no_address_safety_analysis_attribute (tree *node, tree name, tree, int, - bool *no_add_attrs) +handle_no_sanitize_address_attribute (tree *node, tree name, tree, int, + bool *no_add_attrs) { if (TREE_CODE (*node) != FUNCTION_DECL) { @@ -6521,6 +6526,23 @@ handle_no_address_safety_analysis_attrib return NULL_TREE; } +/* Handle a "no_address_safety_analysis" attribute; arguments as in + struct attribute_spec.handler. */ + +static tree +handle_no_address_safety_analysis_attribute (tree *node, tree name, tree, int, + bool *no_add_attrs) +{ + if (TREE_CODE (*node) != FUNCTION_DECL) + warning (OPT_Wattributes, "%qE attribute ignored", name); + else if (!lookup_attribute ("no_sanitize_address", DECL_ATTRIBUTES (*node))) + DECL_ATTRIBUTES (*node) + = tree_cons (get_identifier ("no_sanitize_address"), + NULL_TREE, DECL_ATTRIBUTES (*node)); + *no_add_attrs = true; + return NULL_TREE; +} + /* Handle a "noinline" attribute; arguments as in struct attribute_spec.handler. */ --- gcc/doc/extend.texi.jj 2013-02-25 15:25:43.897463673 +0100 +++ gcc/doc/extend.texi 2013-02-28 17:31:40.789468660 +0100 @@ -2133,7 +2133,8 @@ attributes are currently defined for fun @code{weak}, @code{malloc}, @code{alias}, @code{ifunc}, @code{warn_unused_result}, @code{nonnull}, @code{gnu_inline}, @code{externally_visible}, @code{hot}, @code{cold}, @code{artificial}, -@code{no_address_safety_analysis}, @code{error} and @code{warning}. +@code{no_sanitize_address}, @code{no_address_safety_analysis}, +@code{error} and @code{warning}. Several other attributes are defined for functions on particular target systems. Other attributes, including @code{section} are supported for variables declarations (@pxref{Variable Attributes}) @@ -3432,11 +3433,15 @@ with computed goto or @code{asm goto}. The @code{cold} attribute on labels is not implemented in GCC versions earlier than 4.8. -@item no_address_safety_analysis -@cindex @code{no_address_safety_analysis} function attribute -The @code{no_address_safety_analysis} attribute on functions is used +@item no_sanitize_address +@itemx no_address_safety_analysis +@cindex @code{no_sanitize_address} function attribute +The @code{no_sanitize_address} attribute on functions is used to inform the compiler that it should not instrument memory accesses in the function when compiling with the @option{-fsanitize=address} option. +The @code{no_address_safety_analysis} is a deprecated alias of the +@code{no_sanitize_address} attribute, new code should use +@code{no_sanitize_address}. @item regparm (@var{number}) @cindex @code{regparm} attribute --- gcc/testsuite/g++.dg/asan/default-options-1.C.jj 2012-12-13 00:02:50.644073632 +0100 +++ gcc/testsuite/g++.dg/asan/default-options-1.C 2013-02-28 17:29:07.591362989 +0100 @@ -3,7 +3,7 @@ const char *kAsanDefaultOptions="verbosity=1 foo=bar"; extern "C" -__attribute__((no_address_safety_analysis)) +__attribute__((no_sanitize_address)) const char *__asan_default_options() { return kAsanDefaultOptions; } --- gcc/testsuite/g++.dg/asan/sanitizer_test_utils.h.jj 2013-02-14 09:38:05.744773391 +0100 +++ gcc/testsuite/g++.dg/asan/sanitizer_test_utils.h 2013-02-28 17:29:07.596362955 +0100 @@ -36,7 +36,7 @@ typedef __int64 int64_t; #if __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__) # define ATTRIBUTE_NO_ADDRESS_SAFETY_ANALYSIS \ - __attribute__((no_address_safety_analysis)) + __attribute__((no_sanitize_address)) #else # define ATTRIBUTE_NO_ADDRESS_SAFETY_ANALYSIS #endif --- gcc/testsuite/c-c++-common/asan/attrib-1.c.jj 2012-11-23 10:00:37.015136497 +0100 +++ gcc/testsuite/c-c++-common/asan/attrib-1.c 2013-02-28 18:04:32.121980030 +0100 @@ -1,7 +1,7 @@ /* PR sanitizer/55435 */ /* { dg-do compile } */ -__attribute__((no_address_safety_analysis)) int +__attribute__((no_sanitize_address)) int f1 (int *p, int *q) { *p = 42; @@ -9,8 +9,8 @@ f1 (int *p, int *q) } void f2 (char *); -void f2 (char *) __attribute__((no_address_safety_analysis)); -void f2 (char *) __attribute__((no_address_safety_analysis)); +void f2 (char *) __attribute__((no_sanitize_address)); +void f2 (char *) __attribute__((no_sanitize_address)); void f2 (char *); void @@ -20,7 +20,7 @@ f2 (char *p) } void f3 (short *); -__typeof (f3) f3 __attribute__((__no_address_safety_analysis__)); +__typeof (f3) f3 __attribute__((__no_sanitize_address__)); void f3 (short *p) @@ -28,7 +28,35 @@ f3 (short *p) *p = 42; } -int v __attribute__((no_address_safety_analysis)); /* { dg-warning "attribute ignored" } */ +__attribute__((no_sanitize_address)) int +f4 (int *p, int *q) +{ + *p = 42; + return *q; +} + +void f5 (char *); +void f5 (char *) __attribute__((no_sanitize_address)); +void f5 (char *) __attribute__((no_sanitize_address)); +void f5 (char *); + +void +f5 (char *p) +{ + *p = 42; +} + +void f6 (short *); +__typeof (f6) f6 __attribute__((__no_address_safety_analysis__)); + +void +f6 (short *p) +{ + *p = 42; +} + +int v __attribute__((no_sanitize_address)); /* { dg-warning "attribute ignored" } */ +int v2 __attribute__((no_address_safety_analysis)); /* { dg-warning "attribute ignored" } */ /* { dg-final { scan-assembler-not "__asan_report_store" } } */ /* { dg-final { scan-assembler-not "__asan_report_load" } } */