From patchwork Mon Oct 21 11:35:52 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Enkovich X-Patchwork-Id: 285173 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 0C0102C00C5 for ; Mon, 21 Oct 2013 22:37:15 +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=pKd+UHvt3KbvqECeNrUNzIROqN88I4i6OORSyudNA4+U6SViqCha6 16I0Lt+n8UIsAoIU1/oBC7r7x32NHnt7g4FNPsx6B0G9euplU1s+QQbT/5x8apv8 HlQzrZhjCUOS3AHmN1c3PG78jsT4KnlFN9uwhng91itsbVwwp3g2qI= 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=yEiWATBfhuH5yIa8AHn54pCL4L8=; b=VrBMFg5KfMiHSH9hVUqS f9ZnxDJ0TLHIU4MDE431rv+dsaTig2u1aAm0BBso1PbW9WLU3PwRLmIqmjJQybMW jXGP3KPiHj5SFoc8knz+f/9JZ0TDZDF67OIZM0FZLQGplt8LGjeSQP3YQq8o2krS sQZ1sDvQXeEPIXaa9TzeDoY= Received: (qmail 27396 invoked by alias); 21 Oct 2013 11:37:07 -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 27383 invoked by uid 89); 21 Oct 2013 11:37:06 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.6 required=5.0 tests=BAYES_00, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-pa0-f53.google.com Received: from mail-pa0-f53.google.com (HELO mail-pa0-f53.google.com) (209.85.220.53) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Mon, 21 Oct 2013 11:36:38 +0000 Received: by mail-pa0-f53.google.com with SMTP id kq14so7903860pab.12 for ; Mon, 21 Oct 2013 04:36:37 -0700 (PDT) X-Received: by 10.66.230.138 with SMTP id sy10mr17839983pac.103.1382355396747; Mon, 21 Oct 2013 04:36:36 -0700 (PDT) Received: from msticlxl57.ims.intel.com (fmdmzpr01-ext.fm.intel.com. [192.55.54.36]) by mx.google.com with ESMTPSA id vz4sm25125977pab.11.2013.10.21.04.36.34 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 21 Oct 2013 04:36:36 -0700 (PDT) Date: Mon, 21 Oct 2013 15:35:52 +0400 From: Ilya Enkovich To: gcc-patches@gcc.gnu.org Subject: [PATCH, MPX, 2/X] Pointers Checker [1/25] Hooks Message-ID: <20131021113552.GA37888@msticlxl57.ims.intel.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes Hi, This patch starts the series which introduces Pointers Checker and its support in i386 via Intel MPX. Pointers Checker is described on Wiki page - http://gcc.gnu.org/wiki/Intel%20MPX%20support%20in%20the%20GCC%20compiler. This series actually replaces previously sent patch (http://gcc.gnu.org/ml/gcc-patches/2013-08/msg01167.html) which seems too inconvenient for review. The first patch in a series introduces new target and language hooks used by Pointers Checker. Bootstrapped and tested on linux-x86_64. Thanks, Ilya --- gcc/ 2013-10-21 Ilya Enkovich * target.def (builtin_chkp_function): New. (chkp_bound_type): New. (chkp_bound_mode): New. (fn_abi_va_list_bounds_size): New. (load_bounds_for_arg): New. (store_bounds_for_arg): New. * targhooks.h (default_load_bounds_for_arg): New. (default_store_bounds_for_arg): New. (default_fn_abi_va_list_bounds_size): New. (default_chkp_bound_type): New. (default_chkp_bound_mode): New. (default_builtin_chkp_function): New. * targhooks.c (default_load_bounds_for_arg): New. (default_store_bounds_for_arg): New. (default_fn_abi_va_list_bounds_size): New. (default_chkp_bound_type): New. (default_chkp_bound_mode); New. (default_builtin_chkp_function): New. * doc/tm.texi.in (TARGET_FN_ABI_VA_LIST_BOUNDS_SIZE): New. (TARGET_LOAD_BOUNDS_FOR_ARG): New. (TARGET_STORE_BOUNDS_FOR_ARG): New. (TARGET_BUILTIN_CHKP_FUNCTION): New. (TARGET_CHKP_BOUND_TYPE): New. (TARGET_CHKP_BOUND_MODE): New. * doc/tm.texi: Regenerated. * langhooks.h (lang_hooks): Add chkp_supported field. * langhooks-def.h (LANG_HOOKS_CHKP_SUPPORTED): New. (LANG_HOOKS_INITIALIZER); Add LANG_HOOKS_CHKP_SUPPORTED. diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi index 8d220f3..01462a2 100644 --- a/gcc/doc/tm.texi +++ b/gcc/doc/tm.texi @@ -4334,6 +4334,11 @@ This hook returns the va_list type of the calling convention specified by The default version of this hook returns @code{va_list_type_node}. @end deftypefn +@deftypefn {Target Hook} tree TARGET_FN_ABI_VA_LIST_BOUNDS_SIZE (tree @var{fndecl}) +This hook returns size for va_list object or integer_zero_node if +it does not have any (e.g. is scalar pointer to the stack). +@end deftypefn + @deftypefn {Target Hook} tree TARGET_CANONICAL_VA_LIST_TYPE (tree @var{type}) This hook returns the va_list type of the calling convention specified by the type of @var{type}. If @var{type} is not a valid va_list type, it returns @@ -5151,6 +5156,16 @@ defined, then define this hook to return @code{true} if Otherwise, you should not define this hook. @end deftypefn +@deftypefn {Target Hook} rtx TARGET_LOAD_BOUNDS_FOR_ARG (rtx, @var{rtx}, @var{rtx}) +This hook is used to emit insn to load arg's bounds +in case bounds are not passed on register. Return loaded bounds +@end deftypefn + +@deftypefn {Target Hook} void TARGET_STORE_BOUNDS_FOR_ARG (rtx, @var{rtx}, @var{rtx}, @var{rtx}) +This hook is used to emit insn to store arg's bounds +in case bounds are not passed on register. +@end deftypefn + @node Trampolines @section Trampolines for Nested Functions @cindex trampolines for nested functions @@ -10907,6 +10922,18 @@ ignored. This function should return the result of the call to the built-in function. @end deftypefn +@deftypefn {Target Hook} tree TARGET_BUILTIN_CHKP_FUNCTION (unsigned @var{fcode}) +Pointers checker instrumentation pass uses this hook to obtain +target-specific functions which implement specified generic checker +builtins. +@end deftypefn +@deftypefn {Target Hook} tree TARGET_CHKP_BOUND_TYPE (void) +Return type to be used for bounds +@end deftypefn +@deftypefn {Target Hook} {enum machine_mode} TARGET_CHKP_BOUND_MODE (void) +Return mode to be used for bounds. +@end deftypefn + @deftypefn {Target Hook} tree TARGET_RESOLVE_OVERLOADED_BUILTIN (unsigned int @var{loc}, tree @var{fndecl}, void *@var{arglist}) Select a replacement for a machine specific built-in function that was set up by @samp{TARGET_INIT_BUILTINS}. This is done diff --git a/gcc/doc/tm.texi.in b/gcc/doc/tm.texi.in index 863e843a..2828361 100644 --- a/gcc/doc/tm.texi.in +++ b/gcc/doc/tm.texi.in @@ -3694,6 +3694,8 @@ stack. @hook TARGET_FN_ABI_VA_LIST +@hook TARGET_FN_ABI_VA_LIST_BOUNDS_SIZE + @hook TARGET_CANONICAL_VA_LIST_TYPE @hook TARGET_GIMPLIFY_VA_ARG_EXPR @@ -4064,6 +4066,10 @@ These machine description macros help implement varargs: @hook TARGET_PRETEND_OUTGOING_VARARGS_NAMED +@hook TARGET_LOAD_BOUNDS_FOR_ARG + +@hook TARGET_STORE_BOUNDS_FOR_ARG + @node Trampolines @section Trampolines for Nested Functions @cindex trampolines for nested functions @@ -8184,6 +8190,10 @@ to by @var{ce_info}. @hook TARGET_EXPAND_BUILTIN +@hook TARGET_BUILTIN_CHKP_FUNCTION +@hook TARGET_CHKP_BOUND_TYPE +@hook TARGET_CHKP_BOUND_MODE + @hook TARGET_RESOLVE_OVERLOADED_BUILTIN @hook TARGET_FOLD_BUILTIN diff --git a/gcc/langhooks-def.h b/gcc/langhooks-def.h index 7bd2e99..542c3d7 100644 --- a/gcc/langhooks-def.h +++ b/gcc/langhooks-def.h @@ -117,6 +117,7 @@ extern void lhd_omp_firstprivatize_type_sizes (struct gimplify_omp_ctx *, #define LANG_HOOKS_BLOCK_MAY_FALLTHRU hook_bool_const_tree_true #define LANG_HOOKS_EH_USE_CXA_END_CLEANUP false #define LANG_HOOKS_DEEP_UNSHARING false +#define LANG_HOOKS_CHKP_SUPPORTED false /* Attribute hooks. */ #define LANG_HOOKS_ATTRIBUTE_TABLE NULL @@ -302,7 +303,8 @@ extern void lhd_end_section (void); LANG_HOOKS_EH_PROTECT_CLEANUP_ACTIONS, \ LANG_HOOKS_BLOCK_MAY_FALLTHRU, \ LANG_HOOKS_EH_USE_CXA_END_CLEANUP, \ - LANG_HOOKS_DEEP_UNSHARING \ + LANG_HOOKS_DEEP_UNSHARING, \ + LANG_HOOKS_CHKP_SUPPORTED \ } #endif /* GCC_LANG_HOOKS_DEF_H */ diff --git a/gcc/langhooks.h b/gcc/langhooks.h index 80d4ef3..a4a8764 100644 --- a/gcc/langhooks.h +++ b/gcc/langhooks.h @@ -469,6 +469,9 @@ struct lang_hooks gimplification. */ bool deep_unsharing; + /* True if this language allows pointers checker instrumentation. */ + bool chkp_supported; + /* Whenever you add entries here, make sure you adjust langhooks-def.h and langhooks.c accordingly. */ }; diff --git a/gcc/target.def b/gcc/target.def index 6de513f..0f5ddc1 100644 --- a/gcc/target.def +++ b/gcc/target.def @@ -2023,6 +2023,26 @@ built-in function.", (tree exp, rtx target, rtx subtarget, enum machine_mode mode, int ignore), default_expand_builtin) +DEFHOOK +(builtin_chkp_function, + "Pointers checker instrumentation pass uses this hook to obtain\n\ +target-specific functions which implement specified generic checker\n\ +builtins.", + tree, (unsigned fcode), + default_builtin_chkp_function) + +DEFHOOK +(chkp_bound_type, + "Return type to be used for bounds", + tree, (void), + default_chkp_bound_type) + +DEFHOOK +(chkp_bound_mode, + "Return mode to be used for bounds.", + enum machine_mode, (void), + default_chkp_bound_mode) + /* Select a replacement for a target-specific builtin. This is done *before* regular type checking, and so allows the target to implement a crude form of function overloading. The result is a @@ -3273,6 +3293,13 @@ The default version of this hook returns @code{va_list_type_node}.", tree, (tree fndecl), std_fn_abi_va_list) +DEFHOOK +(fn_abi_va_list_bounds_size, + "This hook returns size for va_list object or integer_zero_node if\n\ +it does not have any (e.g. is scalar pointer to the stack).", + tree, (tree fndecl), + default_fn_abi_va_list_bounds_size) + /* Get the __builtin_va_list type dependent on input type. */ DEFHOOK (canonical_va_list_type, @@ -3704,6 +3731,20 @@ not generate any instructions in this case.", default_setup_incoming_varargs) DEFHOOK +(load_bounds_for_arg, + "This hook is used to emit insn to load arg's bounds\n\ +in case bounds are not passed on register. Return loaded bounds", + rtx, (rtx, rtx, rtx), + default_load_bounds_for_arg) + +DEFHOOK +(store_bounds_for_arg, + "This hook is used to emit insn to store arg's bounds\n\ +in case bounds are not passed on register.", + void, (rtx, rtx, rtx, rtx), + default_store_bounds_for_arg) + +DEFHOOK (strict_argument_naming, "Define this hook to return @code{true} if the location where a function\n\ argument is passed depends on whether or not it is a named argument.\n\ diff --git a/gcc/targhooks.c b/gcc/targhooks.c index ec73a64..b912eb8 100644 --- a/gcc/targhooks.c +++ b/gcc/targhooks.c @@ -1556,6 +1556,28 @@ default_member_type_forces_blk (const_tree, enum machine_mode) { return false; } +rtx +default_load_bounds_for_arg (rtx addr ATTRIBUTE_UNUSED, + rtx ptr ATTRIBUTE_UNUSED, + rtx bnd ATTRIBUTE_UNUSED) +{ + gcc_unreachable (); +} + +void +default_store_bounds_for_arg (rtx val ATTRIBUTE_UNUSED, + rtx addr ATTRIBUTE_UNUSED, + rtx bounds ATTRIBUTE_UNUSED, + rtx to ATTRIBUTE_UNUSED) +{ + gcc_unreachable (); +} + +tree +default_fn_abi_va_list_bounds_size (tree fndecl ATTRIBUTE_UNUSED) +{ + return integer_zero_node; +} /* Default version of canonicalize_comparison. */ @@ -1564,4 +1586,25 @@ default_canonicalize_comparison (int *, rtx *, rtx *, bool) { } +tree +default_chkp_bound_type (void) +{ + tree res = make_node (BOUND_TYPE); + TYPE_PRECISION (res) = TYPE_PRECISION (size_type_node) * 2; + layout_type (res); + return res; +} + +enum machine_mode +default_chkp_bound_mode (void) +{ + return VOIDmode; +} + +tree +default_builtin_chkp_function (unsigned int fcode ATTRIBUTE_UNUSED) +{ + return NULL_TREE; +} + #include "gt-targhooks.h" diff --git a/gcc/targhooks.h b/gcc/targhooks.h index b3bd155..184b9c3 100644 --- a/gcc/targhooks.h +++ b/gcc/targhooks.h @@ -202,3 +202,10 @@ extern void default_asm_output_ident_directive (const char*); extern enum machine_mode default_cstore_mode (enum insn_code); extern bool default_member_type_forces_blk (const_tree, enum machine_mode); + +extern rtx default_load_bounds_for_arg (rtx, rtx, rtx); +extern void default_store_bounds_for_arg (rtx, rtx, rtx, rtx); +extern tree default_fn_abi_va_list_bounds_size (tree); +extern tree default_chkp_bound_type (void); +extern enum machine_mode default_chkp_bound_mode (void); +extern tree default_builtin_chkp_function (unsigned int);