diff mbox

[MPX,wrappers,2/3] Replace some function calls with wrapper calls during instrumentation

Message ID 20141114172932.GB20207@msticlxl57.ims.intel.com
State New
Headers show

Commit Message

Ilya Enkovich Nov. 14, 2014, 5:29 p.m. UTC
Hi,

This patch adds wrapper calls.  It's simply achieved by using proper name for builtin clones.  Patches apply over builtins instrumentation series.

Thanks,
Ilya
--
2014-11-14  Ilya Enkovich  <ilya.enkovich@intel.com>

	* c-family/c.opt (fchkp-use-wrappers): New.
	* ipa-chkp.c (CHKP_WRAPPER_SYMBOL_PREFIX): New.
	(chkp_wrap_function): New.
	(chkp_build_instrumented_fndecl): Support wrapped
	functions.

Comments

Joseph Myers Nov. 14, 2014, 7:01 p.m. UTC | #1
On Fri, 14 Nov 2014, Ilya Enkovich wrote:

> 	* c-family/c.opt (fchkp-use-wrappers): New.

Command-line options need documenting in invoke.texi.
Jeff Law Nov. 15, 2014, 7:16 a.m. UTC | #2
On 11/14/14 10:29, Ilya Enkovich wrote:
> Hi,
>
> This patch adds wrapper calls.  It's simply achieved by using proper name for builtin clones.  Patches apply over builtins instrumentation series.
>
> Thanks,
> Ilya
> --
> 2014-11-14  Ilya Enkovich  <ilya.enkovich@intel.com>
>
> 	* c-family/c.opt (fchkp-use-wrappers): New.
> 	* ipa-chkp.c (CHKP_WRAPPER_SYMBOL_PREFIX): New.
> 	(chkp_wrap_function): New.
> 	(chkp_build_instrumented_fndecl): Support wrapped
> 	functions.
invoke.texi documentation please.

OK with the invoke.texi doc work.  Patch #3 is OK.

Jeff
diff mbox

Patch

diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt
index 66c62fb..897a848 100644
--- a/gcc/c-family/c.opt
+++ b/gcc/c-family/c.opt
@@ -1032,6 +1032,10 @@  fchkp-instrument-marked-only
 C ObjC C++ ObjC++ LTO Report Var(flag_chkp_instrument_marked_only) Init(0)
 Instrument only functions marked with bnd_instrument attribute.
 
+fchkp-use-wrappers
+C ObjC C++ ObjC++ LTO Report Var(flag_chkp_use_wrappers) Init(1)
+Transform instrumented builtin calls into calls to wrappers.
+
 fcilkplus
 C ObjC C++ ObjC++ LTO Report Var(flag_cilkplus) Init(0)
 Enable Cilk Plus
diff --git a/gcc/ipa-chkp.c b/gcc/ipa-chkp.c
index ee7de48..36d592b 100644
--- a/gcc/ipa-chkp.c
+++ b/gcc/ipa-chkp.c
@@ -90,6 +90,44 @@  along with GCC; see the file COPYING3.  If not see
     removed.  */
 
 #define CHKP_BOUNDS_OF_SYMBOL_PREFIX "__chkp_bounds_of_"
+#define CHKP_WRAPPER_SYMBOL_PREFIX "__mpx_wrapper_"
+
+/* Return 1 calls to FNDECL should be replaced with
+   a call to wrapper function.  */
+static bool
+chkp_wrap_function (tree fndecl)
+{
+  if (!flag_chkp_use_wrappers)
+    return false;
+
+  if (DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL)
+    {
+      switch (DECL_FUNCTION_CODE (fndecl))
+	{
+	case BUILT_IN_STRLEN:
+	case BUILT_IN_STRCPY:
+	case BUILT_IN_STRNCPY:
+	case BUILT_IN_STPCPY:
+	case BUILT_IN_STPNCPY:
+	case BUILT_IN_STRCAT:
+	case BUILT_IN_STRNCAT:
+	case BUILT_IN_MEMCPY:
+	case BUILT_IN_MEMPCPY:
+	case BUILT_IN_MEMSET:
+	case BUILT_IN_MEMMOVE:
+	case BUILT_IN_BZERO:
+	case BUILT_IN_MALLOC:
+	case BUILT_IN_CALLOC:
+	case BUILT_IN_REALLOC:
+	  return 1;
+
+	default:
+	  return 0;
+	}
+    }
+
+  return false;
+}
 
 /* Build a clone of FNDECL with a modified name.  */
 
@@ -114,11 +152,20 @@  chkp_build_instrumented_fndecl (tree fndecl)
      because it conflicts with decl merging algorithms in LTO.
      Achieve the result by using transparent alias name for the
      instrumented version.  */
-  s = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (fndecl));
-  s += ".chkp";
-  new_name = get_identifier (s.c_str ());
-  IDENTIFIER_TRANSPARENT_ALIAS (new_name) = 1;
-  TREE_CHAIN (new_name) = DECL_ASSEMBLER_NAME (fndecl);
+  if (chkp_wrap_function(fndecl))
+    {
+      s = CHKP_WRAPPER_SYMBOL_PREFIX;
+      s += IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (fndecl));
+      new_name = get_identifier (s.c_str ());
+    }
+  else
+    {
+      s = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (fndecl));
+      s += ".chkp";
+      new_name = get_identifier (s.c_str ());
+      IDENTIFIER_TRANSPARENT_ALIAS (new_name) = 1;
+      TREE_CHAIN (new_name) = DECL_ASSEMBLER_NAME (fndecl);
+    }
   SET_DECL_ASSEMBLER_NAME (new_decl, new_name);
 
   /* For functions with body versioning will make a copy of arguments.