From patchwork Wed Oct 30 10:37:40 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Enkovich X-Patchwork-Id: 287185 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 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 69C322C0376 for ; Wed, 30 Oct 2013 21:38:35 +1100 (EST) 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:references:mime-version :content-type:in-reply-to; q=dns; s=default; b=WEbSjQOXp2jSEVdzq 03tqvcI2rQFT6I+Fyv25JkFGATYQPn1eJrAOB31r6ixr1y7eCG8ASixIHoyDyi2e qdkz7vocBnjnkx4ERHUp93sSD+Otuw7NfLpGNSfvqVSk6DUY9Yx0Y0UQYBSFk4Ht MEPIMFEkPIwQsch2GZiFiM08aI= 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:references:mime-version :content-type:in-reply-to; s=default; bh=J4JwWIj9ypV325DEsKF2d7G /Mcs=; b=AqAjdjIJkjeUsK+q0jBaQICgGUvhWQwk6VLkA+nXME5wnvO0tiFTMck +5JvNhOmkskmeR2nrzhW6v9D6WikA+DwGYPkAs+bvJDEFIIy9xZVYOc1yk404gIg oDr0OA8qO5umz3yrm2BGmKb0wIP/hNOdz57IuyVWnn9b8NL8Gq2U= Received: (qmail 10915 invoked by alias); 30 Oct 2013 10:38:25 -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 10904 invoked by uid 89); 30 Oct 2013 10:38:24 -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, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-pd0-f180.google.com Received: from mail-pd0-f180.google.com (HELO mail-pd0-f180.google.com) (209.85.192.180) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Wed, 30 Oct 2013 10:38:23 +0000 Received: by mail-pd0-f180.google.com with SMTP id p10so776868pdj.25 for ; Wed, 30 Oct 2013 03:38:21 -0700 (PDT) X-Received: by 10.66.149.231 with SMTP id ud7mr2508753pab.8.1383129499819; Wed, 30 Oct 2013 03:38:19 -0700 (PDT) Received: from msticlxl57.ims.intel.com (fmdmzpr04-ext.fm.intel.com. [192.55.55.39]) by mx.google.com with ESMTPSA id at4sm40523977pbc.30.2013.10.30.03.38.17 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 30 Oct 2013 03:38:19 -0700 (PDT) Date: Wed, 30 Oct 2013 14:37:40 +0400 From: Ilya Enkovich To: Jeff Law Cc: gcc-patches@gcc.gnu.org Subject: Re: [PATCH, MPX, 2/X] Pointers Checker [3/25] Attributes Message-ID: <20131030103740.GC46971@msticlxl57.ims.intel.com> References: <20131021115918.GC37888@msticlxl57.ims.intel.com> <526A02F8.8040107@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <526A02F8.8040107@redhat.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes On 24 Oct 23:34, Jeff Law wrote: > On 10/21/13 05:59, Ilya Enkovich wrote: > >Hi, > > > >This patch adds attributes 'bnd_variable_size' and 'bnd_legacy' used by Pointers Checker. > > > >Bootstrapped and tested on linux-x86_64. > > > >Thanks, > >Ilya > >-- > > > >gcc/ > > > >2013-10-21 Ilya Enkovich > > > > * c-family/c-common.c (handle_bnd_variable_size_attribute): New. > > (handle_bnd_legacy): New. > > (c_common_attribute_table): Add bnd_variable_size and bnd_legacy. > > * doc/extend.texi: Document bnd_variable_size and bnd_legacy > > attributes. > OK with the same terminology changes from the 2/25 Builtins patch. > > jeff > Thanks! Below is the installed version. Ilya diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c index b20fdd6..f519489 100644 --- a/gcc/c-family/c-common.c +++ b/gcc/c-family/c-common.c @@ -375,6 +375,8 @@ static tree handle_omp_declare_simd_attribute (tree *, tree, tree, int, bool *); static tree handle_omp_declare_target_attribute (tree *, tree, tree, int, bool *); +static tree handle_bnd_variable_size_attribute (tree *, tree, tree, int, bool *); +static tree handle_bnd_legacy (tree *, tree, tree, int, bool *); static void check_function_nonnull (tree, int, tree *); static void check_nonnull_arg (void *, tree, unsigned HOST_WIDE_INT); @@ -757,6 +759,10 @@ const struct attribute_spec c_common_attribute_table[] = handle_omp_declare_simd_attribute, false }, { "omp declare target", 0, 0, true, false, false, handle_omp_declare_target_attribute, false }, + { "bnd_variable_size", 0, 0, true, false, false, + handle_bnd_variable_size_attribute, false }, + { "bnd_legacy", 0, 0, true, false, false, + handle_bnd_legacy, false }, { NULL, 0, 0, false, false, false, NULL, false } }; @@ -8013,6 +8019,38 @@ handle_fnspec_attribute (tree *node ATTRIBUTE_UNUSED, tree ARG_UNUSED (name), return NULL_TREE; } +/* Handle a "bnd_variable_size" attribute; arguments as in + struct attribute_spec.handler. */ + +static tree +handle_bnd_variable_size_attribute (tree *node, tree name, tree ARG_UNUSED (args), + int ARG_UNUSED (flags), bool *no_add_attrs) +{ + if (TREE_CODE (*node) != FIELD_DECL) + { + warning (OPT_Wattributes, "%qE attribute ignored", name); + *no_add_attrs = true; + } + + return NULL_TREE; +} + +/* Handle a "bnd_legacy" attribute; arguments as in + struct attribute_spec.handler. */ + +static tree +handle_bnd_legacy (tree *node, tree name, tree ARG_UNUSED (args), + int ARG_UNUSED (flags), bool *no_add_attrs) +{ + if (TREE_CODE (*node) != FUNCTION_DECL) + { + warning (OPT_Wattributes, "%qE attribute ignored", name); + *no_add_attrs = true; + } + + return NULL_TREE; +} + /* Handle a "warn_unused" attribute; arguments as in struct attribute_spec.handler. */ diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi index 8ca3137..1d52e42 100644 --- a/gcc/doc/extend.texi +++ b/gcc/doc/extend.texi @@ -2138,7 +2138,7 @@ attributes are currently defined for functions on all targets: @code{returns_nonnull}, @code{gnu_inline}, @code{externally_visible}, @code{hot}, @code{cold}, @code{artificial}, @code{no_sanitize_address}, @code{no_address_safety_analysis}, -@code{no_sanitize_undefined}, +@code{no_sanitize_undefined}, @code{bnd_legacy}, @code{error} and @code{warning}. Several other attributes are defined for functions on particular target systems. Other attributes, including @code{section} are @@ -3549,6 +3549,12 @@ The @code{no_sanitize_undefined} attribute on functions is used to inform the compiler that it should not check for undefined behavior in the function when compiling with the @option{-fsanitize=undefined} option. +@item bnd_legacy +@cindex @code{bnd_legacy} function attribute +The @code{bnd_legacy} attribute on functions is used to inform +compiler that function should not be instrumented when compiled +with @option{-fcheck-pointers} option. + @item regparm (@var{number}) @cindex @code{regparm} attribute @cindex functions that are passed arguments in registers on the 386 @@ -5321,12 +5327,12 @@ placed in either the @code{.bss_below100} section or the The keyword @code{__attribute__} allows you to specify special attributes of @code{struct} and @code{union} types when you define such types. This keyword is followed by an attribute specification -inside double parentheses. Seven attributes are currently defined for +inside double parentheses. Eight attributes are currently defined for types: @code{aligned}, @code{packed}, @code{transparent_union}, -@code{unused}, @code{deprecated}, @code{visibility}, and -@code{may_alias}. Other attributes are defined for functions -(@pxref{Function Attributes}) and for variables (@pxref{Variable -Attributes}). +@code{unused}, @code{deprecated}, @code{visibility}, @code{may_alias} +and @code{bnd_variable_size}. Other attributes are defined for +functions (@pxref{Function Attributes}) and for variables +(@pxref{Variable Attributes}). You may also specify any one of these attributes with @samp{__} preceding and following its keyword. This allows you to use these @@ -5618,6 +5624,35 @@ and caught in another, the class must have default visibility. Otherwise the two shared objects are unable to use the same typeinfo node and exception handling will break. +@item bnd_variable_size +When applied to a structure field, this attribute tells Pointer +Bounds Checker that the size of this field should not be computed +using static type information. It may be used to mark variable +sized static array fields placed at the end of a structure. + +@smallexample +struct S +@{ + int size; + char data[1]; +@} +S *p = (S *)malloc (sizeof(S) + 100); +p->data[10] = 0; //Bounds violation +@end smallexample + +By using an attribute for a field we may avoid bound violation +we most probably do not want to see: + +@smallexample +struct S +@{ + int size; + char data[1] __attribute__((bnd_variable_size)); +@} +S *p = (S *)malloc (sizeof(S) + 100); +p->data[10] = 0; //OK +@end smallexample + @end table To specify multiple attributes, separate them by commas within the