From patchwork Fri Nov 15 13:19:48 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Enkovich X-Patchwork-Id: 291572 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)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 4D02C2C00C3 for ; Sat, 16 Nov 2013 00:20:52 +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:subject:message-id:mime-version:content-type; q=dns; s= default; b=ZTvMe28YZ7rEBcOzn1HRAxTETPFXcrK4HVoaq/tgfF7Czudho6+0h kt1K+6jtTWlo9r503mhE2LPEHYzaxGw1h9qKn/SnSZ7aCZBW7LvuZGzFDk1JSa1+ /RqHSqB+iDmqN+IJfa0P2irbkOwMeHdEEsQHH9YV6d2ogLb1MpNHmE= 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:subject:message-id:mime-version:content-type; s= default; bh=/cbPAMdPaiR1C0OAjm//OgSb99E=; b=EMdlvmscZYdJj7yYdwv3 RK0oiDq2YJbY7DpZqxnwSwQMRKWbSXPX7m45WBEU71Ci8sTHJo8vIz/T36MRM/g/ kzXvM8hPeqScz09lCVXmlodON3zx4Gp3kav065yVvG92DxWaDoWDQfm2fZdZjvn6 eW725ro6mZhpeWVFMJmq0cY= Received: (qmail 7988 invoked by alias); 15 Nov 2013 13:20:42 -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 7978 invoked by uid 89); 15 Nov 2013 13:20:41 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=0.6 required=5.0 tests=AWL, BAYES_50, FREEMAIL_FROM, RDNS_NONE, SPF_PASS, URIBL_BLOCKED autolearn=no version=3.3.2 X-HELO: mail-pd0-f179.google.com Received: from Unknown (HELO mail-pd0-f179.google.com) (209.85.192.179) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Fri, 15 Nov 2013 13:20:40 +0000 Received: by mail-pd0-f179.google.com with SMTP id r10so557407pdi.10 for ; Fri, 15 Nov 2013 05:20:32 -0800 (PST) X-Received: by 10.66.159.234 with SMTP id xf10mr6755756pab.139.1384521632387; Fri, 15 Nov 2013 05:20:32 -0800 (PST) Received: from msticlxl57.ims.intel.com (fmdmzpr03-ext.fm.intel.com. [192.55.54.38]) by mx.google.com with ESMTPSA id y9sm5065189pas.10.2013.11.15.05.20.30 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 15 Nov 2013 05:20:31 -0800 (PST) Date: Fri, 15 Nov 2013 17:19:48 +0400 From: Ilya Enkovich To: gcc-patches@gcc.gnu.org Subject: [PATCH, MPX, 2/X] Pointers Checker. Bounds binding builtin Message-ID: <20131115131948.GB21297@msticlxl57.ims.intel.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes Hi, Here is a patch to introduce builtin to bind bounds for call arguments as was discussed here (http://gcc.gnu.org/ml/gcc-patches/2013-11/msg00872.html). Patch also removes outdated gimple ifaces. Thanks, Ilya --- 2013-11-15 Ilya Enkovich * builtin-types.def (BT_FN_PTR_CONST_PTR_VAR): New. * chkp-builtins.def (BUILT_IN_CHKP_BIND_BOUNDS): New. * cfgexpand.c (expand_call_stmt): Expand BUILT_IN_CHKP_BIND_BOUNDS. * gimple.c (gimple_call_get_nobnd_arg_index): Remove. * gimple.h (gf_mask): Add GF_CALL_INSTRUMENTED. (gimple_call_instrumented_p): New. (gimple_call_set_instrumented): New. (gimple_call_num_nobnd_args): Remove. (gimple_call_nobnd_arg): Remove. * tree.h (CALL_INSTRUMENTED_P): New. * rtl.h (CALL_EXPR_INSTRUMENTED_P): New. diff --git a/gcc/builtin-types.def b/gcc/builtin-types.def index 1f9ae4e..e7bfaf9 100644 --- a/gcc/builtin-types.def +++ b/gcc/builtin-types.def @@ -542,6 +542,8 @@ DEF_FUNCTION_TYPE_VAR_1 (BT_FN_INT_CONST_STRING_VAR, BT_INT, BT_CONST_STRING) DEF_FUNCTION_TYPE_VAR_1 (BT_FN_UINT32_UINT32_VAR, BT_UINT32, BT_UINT32) +DEF_FUNCTION_TYPE_VAR_1 (BT_FN_PTR_CONST_PTR_VAR, + BT_PTR, BT_CONST_PTR) DEF_FUNCTION_TYPE_VAR_2 (BT_FN_INT_FILEPTR_CONST_STRING_VAR, BT_INT, BT_FILEPTR, BT_CONST_STRING) diff --git a/gcc/cfgexpand.c b/gcc/cfgexpand.c index 9705036..8a738d4 100644 --- a/gcc/cfgexpand.c +++ b/gcc/cfgexpand.c @@ -2121,12 +2121,22 @@ expand_call_stmt (gimple stmt) return; } - exp = build_vl_exp (CALL_EXPR, gimple_call_num_args (stmt) + 3); - - CALL_EXPR_FN (exp) = gimple_call_fn (stmt); decl = gimple_call_fndecl (stmt); builtin_p = decl && DECL_BUILT_IN (decl); + /* Bind bounds call is expanded as assignment. */ + if (builtin_p + && DECL_BUILT_IN_CLASS (decl) == BUILT_IN_NORMAL + && DECL_FUNCTION_CODE (decl) == BUILT_IN_CHKP_BIND_BOUNDS) + { + expand_assignment (gimple_call_lhs (stmt), + gimple_call_arg (stmt, 0), false); + return; + } + + exp = build_vl_exp (CALL_EXPR, gimple_call_num_args (stmt) + 3); + CALL_EXPR_FN (exp) = gimple_call_fn (stmt); + /* If this is not a builtin function, the function type through which the call is made may be different from the type of the function. */ if (!builtin_p) diff --git a/gcc/chkp-builtins.def b/gcc/chkp-builtins.def index d19b541..b920950 100644 --- a/gcc/chkp-builtins.def +++ b/gcc/chkp-builtins.def @@ -42,6 +42,9 @@ DEF_BUILTIN_STUB (BUILT_IN_CHKP_EXTRACT_LOWER, "__chkp_extract_lower") DEF_BUILTIN_STUB (BUILT_IN_CHKP_EXTRACT_UPPER, "__chkp_extract_upper") DEF_BUILTIN_STUB (BUILT_IN_CHKP_NARROW, "__chkp_narrow") +/* Builtins to bind bounds to call arguments. */ +DEF_CHKP_BUILTIN (BUILT_IN_CHKP_BIND_BOUNDS, "__chkp_bind_bounds", BT_FN_PTR_CONST_PTR_VAR, ATTR_CONST_NOTHROW_LEAF_LIST) + /* Pointer Bounds Checker builtins for users. Only BUILT_IN_CHKP_SET_PTR_BOUNDS may be redefined by target. Other builtins calls are expanded diff --git a/gcc/gimple.c b/gcc/gimple.c index 20f6010..72c10c0 100644 --- a/gcc/gimple.c +++ b/gcc/gimple.c @@ -366,26 +366,6 @@ gimple_build_call_from_tree (tree t) } -/* Return index of INDEX's non bound argument of the call. */ - -unsigned -gimple_call_get_nobnd_arg_index (const_gimple gs, unsigned index) -{ - unsigned num_args = gimple_call_num_args (gs); - for (unsigned n = 0; n < num_args; n++) - { - if (POINTER_BOUNDS_P (gimple_call_arg (gs, n))) - continue; - else if (index) - index--; - else - return n; - } - - gcc_unreachable (); -} - - /* Extract the operands and code for expression EXPR into *SUBCODE_P, *OP1_P, *OP2_P and *OP3_P respectively. */ diff --git a/gcc/gimple.h b/gcc/gimple.h index c7ce394..95d6589 100644 --- a/gcc/gimple.h +++ b/gcc/gimple.h @@ -101,6 +101,7 @@ enum gf_mask { GF_CALL_NOTHROW = 1 << 4, GF_CALL_ALLOCA_FOR_VAR = 1 << 5, GF_CALL_INTERNAL = 1 << 6, + GF_CALL_INSTRUMENTED = 1 << 7, GF_OMP_PARALLEL_COMBINED = 1 << 0, GF_OMP_FOR_KIND_MASK = 3 << 0, GF_OMP_FOR_KIND_FOR = 0 << 0, @@ -919,7 +920,6 @@ extern tree get_initialized_tmp_var (tree, gimple_seq *, gimple_seq *); extern tree get_formal_tmp_var (tree, gimple_seq *); extern void declare_vars (tree, gimple, bool); extern void annotate_all_with_location (gimple_seq, location_t); -extern unsigned gimple_call_get_nobnd_arg_index (const_gimple, unsigned); /* Validation of GIMPLE expressions. Note that these predicates only check the basic form of the expression, they don't recurse to make sure that @@ -2231,6 +2231,31 @@ gimple_call_internal_p (const_gimple gs) } +/* Return true if call GS is marked as instrumented by + Pointer Bounds Checker. */ + +static inline bool +gimple_call_instrumented_p (const_gimple gs) +{ + GIMPLE_CHECK (gs, GIMPLE_CALL); + return (gs->gsbase.subcode & GF_CALL_INSTRUMENTED) != 0; +} + + +/* If INSTRUMENTED_P is true, marm statement GS as instrumented by + Pointer Bounds Checker. */ + +static inline void +gimple_call_set_instrumented (gimple gs, bool instrumented_p) +{ + GIMPLE_CHECK (gs, GIMPLE_CALL); + if (instrumented_p) + gs->gsbase.subcode |= GF_CALL_INSTRUMENTED; + else + gs->gsbase.subcode &= ~GF_CALL_INSTRUMENTED; +} + + /* Return the target of internal call GS. */ static inline enum internal_fn @@ -2415,32 +2440,6 @@ gimple_call_arg (const_gimple gs, unsigned index) } -/* Return the number of arguments used by call statement GS - ignoring bound ones. */ - -static inline unsigned -gimple_call_num_nobnd_args (const_gimple gs) -{ - unsigned num_args = gimple_call_num_args (gs); - unsigned res = num_args; - for (unsigned n = 0; n < num_args; n++) - if (POINTER_BOUNDS_P (gimple_call_arg (gs, n))) - res--; - return res; -} - - -/* Return INDEX's call argument ignoring bound ones. */ -static inline tree -gimple_call_nobnd_arg (const_gimple gs, unsigned index) -{ - /* No bound args may exist if pointers checker is off. */ - if (!flag_check_pointer_bounds) - return gimple_call_arg (gs, index); - return gimple_call_arg (gs, gimple_call_get_nobnd_arg_index (gs, index)); -} - - /* Return a pointer to the argument at position INDEX for call statement GS. */ diff --git a/gcc/rtl.h b/gcc/rtl.h index 247a0d0..5254411 100644 --- a/gcc/rtl.h +++ b/gcc/rtl.h @@ -266,7 +266,8 @@ struct GTY((chain_next ("RTX_NEXT (&%h)"), In a CODE_LABEL, part of the two-bit alternate entry field. 1 in a CONCAT is VAL_EXPR_IS_COPIED in var-tracking.c. 1 in a VALUE is SP_BASED_VALUE_P in cselib.c. - 1 in a SUBREG generated by LRA for reload insns. */ + 1 in a SUBREG generated by LRA for reload insns. + 1 in CALL for instrumented calls. */ unsigned int jump : 1; /* In a CODE_LABEL, part of the two-bit alternate entry field. 1 in a MEM if it cannot trap. @@ -1420,6 +1421,10 @@ do { \ #define LRA_SUBREG_P(RTX) \ (RTL_FLAG_CHECK1 ("LRA_SUBREG_P", (RTX), SUBREG)->jump) +/* True if call is instrumented by Pointer Bounds Checker. */ +#define CALL_EXPR_INSTRUMENTED_P(RTX) \ + (RTL_FLAG_CHECK1 ("CALL_INSTRUMENTED_P", (RTX), CALL)->jump) + /* Access various components of an ASM_OPERANDS rtx. */ #define ASM_OPERANDS_TEMPLATE(RTX) XCSTR (RTX, 0, ASM_OPERANDS) diff --git a/gcc/tree.h b/gcc/tree.h index 3fe751e..5aaea5b 100644 --- a/gcc/tree.h +++ b/gcc/tree.h @@ -828,6 +828,9 @@ extern void omp_clause_range_check_failed (const_tree, const char *, int, #define CALL_ALLOCA_FOR_VAR_P(NODE) \ (CALL_EXPR_CHECK (NODE)->base.protected_flag) +/* In a CALL_EXPR, means call was instrumented by Pointer Bounds Checker. */ +#define CALL_INSTRUMENTED_P(NODE) (CALL_EXPR_CHECK (NODE)->base.deprecated_flag) + /* In a type, nonzero means that all objects of the type are guaranteed by the language or front-end to be properly aligned, so we can indicate that a MEM of this type is aligned at least to the alignment of the type, even if it