Patchwork [MPX,2/X] Pointers Checker [8/25] Languages support

login
register
mail settings
Submitter Ilya Enkovich
Date Nov. 8, 2013, 9:02 a.m.
Message ID <20131108090256.GA21297@msticlxl57.ims.intel.com>
Download mbox | patch
Permalink /patch/289722/
State New
Headers show

Comments

Ilya Enkovich - Nov. 8, 2013, 9:02 a.m.
Hi,

Here is an updated patch version with no langhook.

Regarding TLS objects issue - I do not think compiler should compensate the absence of instrumentation in libraries.  Compiler should be responsible for initialization of Bounds Tables for .tdata section.  Correct data copy is a responsibility of library.  User should use either instrumented library or wrapper calls if he needs this functionality.

Thanks,
Ilya
--
gcc/

2013-11-06  Ilya Enkovich  <ilya.enkovich@intel.com>

	* c/c-parser.c: Include tree-chkp.h.
	(c_parser_declaration_or_fndef): Register statically
	initialized decls in Pointer Bounds Checker.
	* cp/decl.c: Include tree-chkp.h.
	(cp_finish_decl): Register statically
	initialized decls in Pointer Bounds Checker.
	* gimplify.c: Include tree-chkp.h.
	(gimplify_init_constructor): Register statically
	initialized decls in Pointer Bounds Checker.
Ilya Enkovich - Nov. 18, 2013, 9:21 a.m.
Ping

2013/11/8 Ilya Enkovich <enkovich.gnu@gmail.com>:
> Hi,
>
> Here is an updated patch version with no langhook.
>
> Regarding TLS objects issue - I do not think compiler should compensate the absence of instrumentation in libraries.  Compiler should be responsible for initialization of Bounds Tables for .tdata section.  Correct data copy is a responsibility of library.  User should use either instrumented library or wrapper calls if he needs this functionality.
>
> Thanks,
> Ilya
> --
> gcc/
>
> 2013-11-06  Ilya Enkovich  <ilya.enkovich@intel.com>
>
>         * c/c-parser.c: Include tree-chkp.h.
>         (c_parser_declaration_or_fndef): Register statically
>         initialized decls in Pointer Bounds Checker.
>         * cp/decl.c: Include tree-chkp.h.
>         (cp_finish_decl): Register statically
>         initialized decls in Pointer Bounds Checker.
>         * gimplify.c: Include tree-chkp.h.
>         (gimplify_init_constructor): Register statically
>         initialized decls in Pointer Bounds Checker.
>
>
> diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c
> index 9ccae3b..397b323 100644
> --- a/gcc/c/c-parser.c
> +++ b/gcc/c/c-parser.c
> @@ -56,6 +56,7 @@ along with GCC; see the file COPYING3.  If not see
>  #include "cgraph.h"
>  #include "plugin.h"
>  #include "omp-low.h"
> +#include "tree-chkp.h"
>
>
>  /* Initialization routine for this file.  */
> @@ -1682,6 +1683,12 @@ c_parser_declaration_or_fndef (c_parser *parser, bool fndef_ok,
>                   maybe_warn_string_init (TREE_TYPE (d), init);
>                   finish_decl (d, init_loc, init.value,
>                                init.original_type, asm_name);
> +
> +                 /* Register all decls with initializers in Pointer
> +                    Bounds Checker to generate required static bounds
> +                    initializers.  */
> +                 if (DECL_INITIAL (d) != error_mark_node)
> +                   chkp_register_var_initializer (d);
>                 }
>             }
>           else
> diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
> index 1e92f2a..74df02f 100644
> --- a/gcc/cp/decl.c
> +++ b/gcc/cp/decl.c
> @@ -53,6 +53,7 @@ along with GCC; see the file COPYING3.  If not see
>  #include "splay-tree.h"
>  #include "plugin.h"
>  #include "cgraph.h"
> +#include "tree-chkp.h"
>
>  /* Possible cases of bad specifiers type used by bad_specifiers. */
>  enum bad_spec_place {
> @@ -6379,6 +6380,12 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p,
>              the class specifier.  */
>           if (!DECL_EXTERNAL (decl))
>             var_definition_p = true;
> +
> +         /* If var has initilizer then we need to register it in
> +            Pointer Bounds Checker to generate static bounds initilizer
> +            if required.  */
> +         if (DECL_INITIAL (decl) && DECL_INITIAL (decl) != error_mark_node)
> +           chkp_register_var_initializer (decl);
>         }
>        /* If the variable has an array type, lay out the type, even if
>          there is no initializer.  It is valid to index through the
> diff --git a/gcc/gimplify.c b/gcc/gimplify.c
> index 4f52c27..7aaac15 100644
> --- a/gcc/gimplify.c
> +++ b/gcc/gimplify.c
> @@ -48,6 +48,7 @@ along with GCC; see the file COPYING3.  If not see
>  #include "vec.h"
>  #include "omp-low.h"
>  #include "gimple-low.h"
> +#include "tree-chkp.h"
>
>  #include "langhooks-def.h"     /* FIXME: for lhd_set_decl_assembler_name */
>  #include "tree-pass.h"         /* FIXME: only for PROP_gimple_any */
> @@ -4111,6 +4112,11 @@ gimplify_init_constructor (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p,
>
>                 walk_tree (&ctor, force_labels_r, NULL, NULL);
>                 ctor = tree_output_constant_def (ctor);
> +
> +               /* We need to register created constant object to
> +                  initialize bounds for pointers in it.  */
> +               chkp_register_var_initializer (ctor);
> +
>                 if (!useless_type_conversion_p (type, TREE_TYPE (ctor)))
>                   ctor = build1 (VIEW_CONVERT_EXPR, type, ctor);
>                 TREE_OPERAND (*expr_p, 1) = ctor;
Jeff Law - Nov. 18, 2013, 4:45 p.m.
On 11/08/13 02:02, Ilya Enkovich wrote:
> Hi,
>
> Here is an updated patch version with no langhook.
>
> Regarding TLS objects issue - I do not think compiler should compensate the absence of instrumentation in libraries.  Compiler should be responsible for initialization of Bounds Tables for .tdata section.  Correct data copy is a responsibility of library.  User should use either instrumented library or wrapper calls if he needs this functionality.
>
> Thanks,
> Ilya
> --
> gcc/
>
> 2013-11-06  Ilya Enkovich  <ilya.enkovich@intel.com>
>
> 	* c/c-parser.c: Include tree-chkp.h.
> 	(c_parser_declaration_or_fndef): Register statically
> 	initialized decls in Pointer Bounds Checker.
> 	* cp/decl.c: Include tree-chkp.h.
> 	(cp_finish_decl): Register statically
> 	initialized decls in Pointer Bounds Checker.
> 	* gimplify.c: Include tree-chkp.h.
> 	(gimplify_init_constructor): Register statically
> 	initialized decls in Pointer Bounds Checker.
Is parsing really the right time to register these things with the 
checking framework?  Doesn't all this stuff flow through the gimplifier? 
  If so wouldn't that be a better place?

If it can be done in the gimplifier, which seems good from the 
standpoint of simplifying the long term maintenance of the checking code.

If there's a good reason to have this front-end, please explain it.

Thanks,
Jeff
Richard Guenther - Nov. 19, 2013, noon
On Mon, Nov 18, 2013 at 5:45 PM, Jeff Law <law@redhat.com> wrote:
> On 11/08/13 02:02, Ilya Enkovich wrote:
>>
>> Hi,
>>
>> Here is an updated patch version with no langhook.
>>
>> Regarding TLS objects issue - I do not think compiler should compensate
>> the absence of instrumentation in libraries.  Compiler should be responsible
>> for initialization of Bounds Tables for .tdata section.  Correct data copy
>> is a responsibility of library.  User should use either instrumented library
>> or wrapper calls if he needs this functionality.
>>
>> Thanks,
>> Ilya
>> --
>> gcc/
>>
>> 2013-11-06  Ilya Enkovich  <ilya.enkovich@intel.com>
>>
>>         * c/c-parser.c: Include tree-chkp.h.
>>         (c_parser_declaration_or_fndef): Register statically
>>         initialized decls in Pointer Bounds Checker.
>>         * cp/decl.c: Include tree-chkp.h.
>>         (cp_finish_decl): Register statically
>>         initialized decls in Pointer Bounds Checker.
>>         * gimplify.c: Include tree-chkp.h.
>>         (gimplify_init_constructor): Register statically
>>         initialized decls in Pointer Bounds Checker.
>
> Is parsing really the right time to register these things with the checking
> framework?  Doesn't all this stuff flow through the gimplifier?  If so
> wouldn't that be a better place?
>
> If it can be done in the gimplifier, which seems good from the standpoint of
> simplifying the long term maintenance of the checking code.
>
> If there's a good reason to have this front-end, please explain it.

I'd say not in the gimplifier either but in varpool (symbol table) code
where the symbols are ultimatively registered with?

Richard.

> Thanks,
> Jeff
>
Jeff Law - Nov. 19, 2013, 7:32 p.m.
On 11/19/13 05:00, Richard Biener wrote:
> On Mon, Nov 18, 2013 at 5:45 PM, Jeff Law <law@redhat.com> wrote:
>> On 11/08/13 02:02, Ilya Enkovich wrote:
>>>
>>> Hi,
>>>
>>> Here is an updated patch version with no langhook.
>>>
>>> Regarding TLS objects issue - I do not think compiler should compensate
>>> the absence of instrumentation in libraries.  Compiler should be responsible
>>> for initialization of Bounds Tables for .tdata section.  Correct data copy
>>> is a responsibility of library.  User should use either instrumented library
>>> or wrapper calls if he needs this functionality.
>>>
>>> Thanks,
>>> Ilya
>>> --
>>> gcc/
>>>
>>> 2013-11-06  Ilya Enkovich  <ilya.enkovich@intel.com>
>>>
>>>          * c/c-parser.c: Include tree-chkp.h.
>>>          (c_parser_declaration_or_fndef): Register statically
>>>          initialized decls in Pointer Bounds Checker.
>>>          * cp/decl.c: Include tree-chkp.h.
>>>          (cp_finish_decl): Register statically
>>>          initialized decls in Pointer Bounds Checker.
>>>          * gimplify.c: Include tree-chkp.h.
>>>          (gimplify_init_constructor): Register statically
>>>          initialized decls in Pointer Bounds Checker.
>>
>> Is parsing really the right time to register these things with the checking
>> framework?  Doesn't all this stuff flow through the gimplifier?  If so
>> wouldn't that be a better place?
>>
>> If it can be done in the gimplifier, which seems good from the standpoint of
>> simplifying the long term maintenance of the checking code.
>>
>> If there's a good reason to have this front-end, please explain it.
>
> I'd say not in the gimplifier either but in varpool (symbol table) code
> where the symbols are ultimatively registered with?
That'd work for me.

jeff

Patch

diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c
index 9ccae3b..397b323 100644
--- a/gcc/c/c-parser.c
+++ b/gcc/c/c-parser.c
@@ -56,6 +56,7 @@  along with GCC; see the file COPYING3.  If not see
 #include "cgraph.h"
 #include "plugin.h"
 #include "omp-low.h"
+#include "tree-chkp.h"
 
 
 /* Initialization routine for this file.  */
@@ -1682,6 +1683,12 @@  c_parser_declaration_or_fndef (c_parser *parser, bool fndef_ok,
 		  maybe_warn_string_init (TREE_TYPE (d), init);
 		  finish_decl (d, init_loc, init.value,
 		      	       init.original_type, asm_name);
+
+		  /* Register all decls with initializers in Pointer
+		     Bounds Checker to generate required static bounds
+		     initializers.  */
+		  if (DECL_INITIAL (d) != error_mark_node)
+		    chkp_register_var_initializer (d);
 		}
 	    }
 	  else
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 1e92f2a..74df02f 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -53,6 +53,7 @@  along with GCC; see the file COPYING3.  If not see
 #include "splay-tree.h"
 #include "plugin.h"
 #include "cgraph.h"
+#include "tree-chkp.h"
 
 /* Possible cases of bad specifiers type used by bad_specifiers. */
 enum bad_spec_place {
@@ -6379,6 +6380,12 @@  cp_finish_decl (tree decl, tree init, bool init_const_expr_p,
 	     the class specifier.  */
 	  if (!DECL_EXTERNAL (decl))
 	    var_definition_p = true;
+
+	  /* If var has initilizer then we need to register it in
+	     Pointer Bounds Checker to generate static bounds initilizer
+	     if required.  */
+	  if (DECL_INITIAL (decl) && DECL_INITIAL (decl) != error_mark_node)
+	    chkp_register_var_initializer (decl);
 	}
       /* If the variable has an array type, lay out the type, even if
 	 there is no initializer.  It is valid to index through the
diff --git a/gcc/gimplify.c b/gcc/gimplify.c
index 4f52c27..7aaac15 100644
--- a/gcc/gimplify.c
+++ b/gcc/gimplify.c
@@ -48,6 +48,7 @@  along with GCC; see the file COPYING3.  If not see
 #include "vec.h"
 #include "omp-low.h"
 #include "gimple-low.h"
+#include "tree-chkp.h"
 
 #include "langhooks-def.h"	/* FIXME: for lhd_set_decl_assembler_name */
 #include "tree-pass.h"		/* FIXME: only for PROP_gimple_any */
@@ -4111,6 +4112,11 @@  gimplify_init_constructor (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p,
 
 		walk_tree (&ctor, force_labels_r, NULL, NULL);
 		ctor = tree_output_constant_def (ctor);
+
+		/* We need to register created constant object to
+		   initialize bounds for pointers in it.  */
+		chkp_register_var_initializer (ctor);
+
 		if (!useless_type_conversion_p (type, TREE_TYPE (ctor)))
 		  ctor = build1 (VIEW_CONVERT_EXPR, type, ctor);
 		TREE_OPERAND (*expr_p, 1) = ctor;