diff mbox

[CHKP] Fix cdtor merge for instrumented functions

Message ID 20150402151419.GB6244@msticlxl57.ims.intel.com
State New
Headers show

Commit Message

Ilya Enkovich April 2, 2015, 3:14 p.m. UTC
Hi,

This patch doesn't allow instrumentation thunks calls while merging constructors and destructors.  Not isntrumented code is not affeceted.  Bootstrapped and tested on x86_64-unknown-linux-gnu.  OK for trunk?

Thanks,
Ilya
--
gcc/

2015-04-02  Ilya Enkovich  <ilya.enkovich@intel.com>

	* ipa.c (ipa_cdtor_merge): Skip instrumentation thunks.

gcc/testsuite/

2015-04-02  Ilya Enkovich  <ilya.enkovich@intel.com>

	* gcc.dg/lto/chkp-ctor-merge_0.c: New.

Comments

Jan Hubicka April 2, 2015, 8:21 p.m. UTC | #1
> Hi,
> 
> This patch doesn't allow instrumentation thunks calls while merging constructors and destructors.  Not isntrumented code is not affeceted.  Bootstrapped and tested on x86_64-unknown-linux-gnu.  OK for trunk?
> 
> Thanks,
> Ilya
> --
> gcc/
> 
> 2015-04-02  Ilya Enkovich  <ilya.enkovich@intel.com>
> 
> 	* ipa.c (ipa_cdtor_merge): Skip instrumentation thunks.

So the problem here is that you do have two names for the function, one that
is not instrumented and other that is instrumented?  I am bit surprised we get
instrumentation on ctors that should not take or return pointer parameter,
but I see one can trigger that at least by manually adding constructor attribute.

I think what you need is to drop DECL_STATIC_CONSTRUCTOR/DESTRUCTURO flags when
producing the transparent alias.

Honza
diff mbox

Patch

diff --git a/gcc/ipa.c b/gcc/ipa.c
index b3752de..84ab542 100644
--- a/gcc/ipa.c
+++ b/gcc/ipa.c
@@ -1159,8 +1159,10 @@  ipa_cdtor_merge (void)
 {
   struct cgraph_node *node;
   FOR_EACH_DEFINED_FUNCTION (node)
-    if (DECL_STATIC_CONSTRUCTOR (node->decl)
-	|| DECL_STATIC_DESTRUCTOR (node->decl))
+    if ((DECL_STATIC_CONSTRUCTOR (node->decl)
+	 || DECL_STATIC_DESTRUCTOR (node->decl))
+	&& !(node->thunk.thunk_p
+	     && node->thunk.add_pointer_bounds_args))
        record_cdtor_fn (node);
   build_cdtor_fns ();
   static_ctors.release ();
diff --git a/gcc/testsuite/gcc.dg/lto/chkp-ctor-merge_0.c b/gcc/testsuite/gcc.dg/lto/chkp-ctor-merge_0.c
new file mode 100644
index 0000000..ac4095b
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/lto/chkp-ctor-merge_0.c
@@ -0,0 +1,23 @@ 
+/* { dg-lto-do run } */
+/* { dg-require-effective-target mpx } */
+/* { dg-lto-options { { -O2 -flto -fcheck-pointer-bounds -mmpx -nodefaultlibs -lc } } } */
+
+int glob = 1;
+
+void __attribute__((constructor))
+ctor1 ()
+{
+  glob += 1;
+}
+
+
+void __attribute__((constructor))
+ctor2 ()
+{
+  glob -= 2;
+}
+
+int main (int argc, const char **argv)
+{
+  return glob;
+}