This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH, Pointer Bounds Checker 14/x] Passes [5/n] Replace function pointers


Hi,

This patch add function pointers replacement into instrumentation pass.

Thanks,
Ilya
--
2014-10-08  Ilya Enkovich  <ilya.enkovich@intel.com>

	* tree-chkp.c: Include ipa-chkp.h.
	(chkp_replace_function_pointer): New.
	(chkp_replace_function_pointers): New.
	(chkp_instrument_function): Call replace function pointers
	in all statements with instrumented ones.


diff --git a/gcc/tree-chkp.c b/gcc/tree-chkp.c
index d297171..bbb6459 100644
--- a/gcc/tree-chkp.c
+++ b/gcc/tree-chkp.c
@@ -64,6 +64,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "gimple-walk.h"
 #include "rtl.h" /* For MEM_P, assign_temp.  */
 #include "tree-dfa.h"
+#include "ipa-chkp.h"
 
 /*  Pointer Bounds Checker instruments code with memory checks to find
     out-of-bounds memory accesses.  Checks are performed by computing
@@ -3270,6 +3271,49 @@ chkp_fix_cfg ()
       }
 }
 
+/* Walker callback for chkp_replace_function_pointers.  Replaces
+   function pointer in the specified operand with pointer to the
+   instrumented function version.  */
+static tree
+chkp_replace_function_pointer (tree *op, int *walk_subtrees,
+			       void *data ATTRIBUTE_UNUSED)
+{
+  if (TREE_CODE (*op) == FUNCTION_DECL
+      && !lookup_attribute ("bnd_legacy", DECL_ATTRIBUTES (*op))
+      /* Do not replace builtins for now.  */
+      && DECL_BUILT_IN_CLASS (*op) == NOT_BUILT_IN)
+    {
+      struct cgraph_node *node = cgraph_node::get_create (*op);
+
+      if (!node->instrumentation_clone)
+	chkp_maybe_create_clone (*op);
+
+      *op = node->instrumented_version->decl;
+      *walk_subtrees = 0;
+    }
+
+  return NULL;
+}
+
+/* This function searches for function pointers in statement
+   pointed by GSI and replaces them with pointers to instrumented
+   function versions.  */
+static void
+chkp_replace_function_pointers (gimple_stmt_iterator *gsi)
+{
+  gimple stmt = gsi_stmt (*gsi);
+  /* For calls we want to walk call args only.  */
+  if (gimple_code (stmt) == GIMPLE_CALL)
+    {
+      unsigned i;
+      for (i = 0; i < gimple_call_num_args (stmt); i++)
+	walk_tree (gimple_call_arg_ptr (stmt, i),
+		   chkp_replace_function_pointer, NULL, NULL);
+    }
+  else
+    walk_gimple_stmt (gsi, NULL, chkp_replace_function_pointer, NULL);
+}
+
 /* This function instruments all statements working with memory.  */
 static void
 chkp_instrument_function (void)
@@ -3294,6 +3338,8 @@ chkp_instrument_function (void)
 	      continue;
 	    }
 
+	  chkp_replace_function_pointers (&i);
+
           switch (gimple_code (s))
             {
             case GIMPLE_ASSIGN:


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]