public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Fix ice on comdat groups with -check-pointer-bounds
@ 2015-03-27 15:23 Jan Hubicka
  2015-03-30  9:59 ` Ilya Enkovich
  2015-03-30 11:05 ` Ilya Enkovich
  0 siblings, 2 replies; 6+ messages in thread
From: Jan Hubicka @ 2015-03-27 15:23 UTC (permalink / raw)
  To: gcc-patches, ilya.enkovich

Hi,
this patch fixes bug in symtab_node::verify_symtab_nodes pointed out by Ilya.
The loop checking that there all comdats are linked by same_comdat_group was
completely bogus.  In addition it checked also external symbols that are
currently not kept in groups.  This bug was in mainline for months but
apparently bounds checking is first code producing interesting comdat groups to
trigger it.

Ilya, can you please mind comitting the testcase? I am not quite sure where
bounds checking should go offhand.

Also concerning linking the comdat groups, currently all non-DECL_EXTERNAL symbols
are linked and all !DECL_EXTERNAL symbols are non-linked.  Bounds checking should
follow this scheme.  It may be cleaner to keep links for DECL_EXTERNAL, but lets
deffer that for next stage1.

Bootstrapped/regtested x86_64-linux. Committed.

Honza

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 221735)
+++ ChangeLog	(working copy)
@@ -1,5 +1,11 @@
 2015-03-27  Jan Hubicka  <hubicka@ucw.cz>
 
+	PR target/65531
+	* symtab.c (symtab_node::verify_symtab_nodes): Fix verification of
+	comdat groups.
+
+2015-03-27  Jan Hubicka  <hubicka@ucw.cz>
+
 	PR ipa/65600
 	* cgraph.c (cgraph_update_edges_for_call_stmt_node): Fix the case
 	of optimized out indirect call.
Index: symtab.c
===================================================================
--- symtab.c	(revision 221734)
+++ symtab.c	(working copy)
@@ -1130,15 +1130,20 @@ symtab_node::verify_symtab_nodes (void)
 						  &existed);
 	  if (!existed)
 	    *entry = node;
-	  else
-	    for (s = (*entry)->same_comdat_group; s != NULL && s != node; s = s->same_comdat_group)
+	  else if (!DECL_EXTERNAL (node->decl))
+	    {
+	      for (s = (*entry)->same_comdat_group; s != NULL && s != node;
+		   s = s->same_comdat_group)
+		;
 	      if (!s || s == *entry)
 		{
-		  error ("Two symbols with same comdat_group are not linked by the same_comdat_group list.");
+		  error ("Two symbols with same comdat_group are not linked by "
+			 "the same_comdat_group list.");
 		  (*entry)->debug ();
 		  node->debug ();
 		  internal_error ("symtab_node::verify failed");
 		}
+	    }
 	}
     }
 }

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Fix ice on comdat groups with -check-pointer-bounds
  2015-03-27 15:23 Fix ice on comdat groups with -check-pointer-bounds Jan Hubicka
@ 2015-03-30  9:59 ` Ilya Enkovich
  2015-03-30 11:05 ` Ilya Enkovich
  1 sibling, 0 replies; 6+ messages in thread
From: Ilya Enkovich @ 2015-03-30  9:59 UTC (permalink / raw)
  To: Jan Hubicka; +Cc: gcc-patches

2015-03-27 18:23 GMT+03:00 Jan Hubicka <hubicka@ucw.cz>:
> Hi,
> this patch fixes bug in symtab_node::verify_symtab_nodes pointed out by Ilya.
> The loop checking that there all comdats are linked by same_comdat_group was
> completely bogus.  In addition it checked also external symbols that are
> currently not kept in groups.  This bug was in mainline for months but
> apparently bounds checking is first code producing interesting comdat groups to
> trigger it.
>
> Ilya, can you please mind comitting the testcase? I am not quite sure where
> bounds checking should go offhand.
>
> Also concerning linking the comdat groups, currently all non-DECL_EXTERNAL symbols
> are linked and all !DECL_EXTERNAL symbols are non-linked.  Bounds checking should
> follow this scheme.  It may be cleaner to keep links for DECL_EXTERNAL, but lets
> deffer that for next stage1.

I'll send a corresponding fix in a checker with a testcase.  Please
let me know when you introduce comdat links for external symbols to
keep the checker in sync.

Thanks,
Ilya

>
> Bootstrapped/regtested x86_64-linux. Committed.
>
> Honza
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Fix ice on comdat groups with -check-pointer-bounds
  2015-03-27 15:23 Fix ice on comdat groups with -check-pointer-bounds Jan Hubicka
  2015-03-30  9:59 ` Ilya Enkovich
@ 2015-03-30 11:05 ` Ilya Enkovich
  2015-03-30 11:31   ` Ilya Enkovich
  1 sibling, 1 reply; 6+ messages in thread
From: Ilya Enkovich @ 2015-03-30 11:05 UTC (permalink / raw)
  To: Jan Hubicka; +Cc: gcc-patches, Enkovich, Ilya

2015-03-27 18:23 GMT+03:00 Jan Hubicka <hubicka@ucw.cz>:
> Hi,
> this patch fixes bug in symtab_node::verify_symtab_nodes pointed out by Ilya.
> The loop checking that there all comdats are linked by same_comdat_group was
> completely bogus.  In addition it checked also external symbols that are
> currently not kept in groups.  This bug was in mainline for months but
> apparently bounds checking is first code producing interesting comdat groups to
> trigger it.
>
> Ilya, can you please mind comitting the testcase? I am not quite sure where
> bounds checking should go offhand.
>
> Also concerning linking the comdat groups, currently all non-DECL_EXTERNAL symbols
> are linked and all !DECL_EXTERNAL symbols are non-linked.  Bounds checking should
> follow this scheme.  It may be cleaner to keep links for DECL_EXTERNAL, but lets
> deffer that for next stage1.
>
> Bootstrapped/regtested x86_64-linux. Committed.
>
> Honza
>
> Index: ChangeLog
> ===================================================================
> --- ChangeLog   (revision 221735)
> +++ ChangeLog   (working copy)
> @@ -1,5 +1,11 @@
>  2015-03-27  Jan Hubicka  <hubicka@ucw.cz>
>
> +       PR target/65531
> +       * symtab.c (symtab_node::verify_symtab_nodes): Fix verification of
> +       comdat groups.
> +
> +2015-03-27  Jan Hubicka  <hubicka@ucw.cz>
> +
>         PR ipa/65600
>         * cgraph.c (cgraph_update_edges_for_call_stmt_node): Fix the case
>         of optimized out indirect call.
> Index: symtab.c
> ===================================================================
> --- symtab.c    (revision 221734)
> +++ symtab.c    (working copy)
> @@ -1130,15 +1130,20 @@ symtab_node::verify_symtab_nodes (void)
>                                                   &existed);
>           if (!existed)
>             *entry = node;
> -         else
> -           for (s = (*entry)->same_comdat_group; s != NULL && s != node; s = s->same_comdat_group)
> +         else if (!DECL_EXTERNAL (node->decl))
> +           {
> +             for (s = (*entry)->same_comdat_group; s != NULL && s != node;
> +                  s = s->same_comdat_group)
> +               ;

With no if-statement in the loop body you need an additional exit
condition for a case when you reach the entry.

Thanks,
Ilya

>               if (!s || s == *entry)
>                 {
> -                 error ("Two symbols with same comdat_group are not linked by the same_comdat_group list.");
> +                 error ("Two symbols with same comdat_group are not linked by "
> +                        "the same_comdat_group list.");
>                   (*entry)->debug ();
>                   node->debug ();
>                   internal_error ("symtab_node::verify failed");
>                 }
> +           }
>         }
>      }
>  }

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Fix ice on comdat groups with -check-pointer-bounds
  2015-03-30 11:05 ` Ilya Enkovich
@ 2015-03-30 11:31   ` Ilya Enkovich
  2015-03-30 17:20     ` Jan Hubicka
  0 siblings, 1 reply; 6+ messages in thread
From: Ilya Enkovich @ 2015-03-30 11:31 UTC (permalink / raw)
  To: Jan Hubicka; +Cc: gcc-patches

On 30 Mar 14:05, Ilya Enkovich wrote:
> 2015-03-27 18:23 GMT+03:00 Jan Hubicka <hubicka@ucw.cz>:
> > Index: symtab.c
> > ===================================================================
> > --- symtab.c    (revision 221734)
> > +++ symtab.c    (working copy)
> > @@ -1130,15 +1130,20 @@ symtab_node::verify_symtab_nodes (void)
> >                                                   &existed);
> >           if (!existed)
> >             *entry = node;
> > -         else
> > -           for (s = (*entry)->same_comdat_group; s != NULL && s != node; s = s->same_comdat_group)
> > +         else if (!DECL_EXTERNAL (node->decl))
> > +           {
> > +             for (s = (*entry)->same_comdat_group; s != NULL && s != node;
> > +                  s = s->same_comdat_group)
> > +               ;
> 
> With no if-statement in the loop body you need an additional exit
> condition for a case when you reach the entry.
> 
> Thanks,
> Ilya
> 

Here is a patch to add a testcase, fix the loop and avoid same_comdat_group for instrumented external symbols.  Does it look OK?

BTW should we check same_comdat_group is NULL for external symbols?

Thanks,
Ilya
--
gcc/

2015-03-30  Ilya Enkovich  <ilya.enkovich@intel.com>

	PR target/65531
	* ipa-chkp.c (chkp_maybe_create_clone): Don't set
	same_comdat_group for external symbols.
	* symtab.c (symtab_node::verify_symtab_nodes): Avoid
	infinite same_comdat_group traversal loop.

gcc/testsuite/

2015-03-30  Ilya Enkovich  <ilya.enkovich@intel.com>

	PR target/65531
	* gcc.target/i386/mpx/pr65531.cc: New.


diff --git a/gcc/ipa-chkp.c b/gcc/ipa-chkp.c
index a9933e2..3218d42 100644
--- a/gcc/ipa-chkp.c
+++ b/gcc/ipa-chkp.c
@@ -574,7 +574,8 @@ chkp_maybe_create_clone (tree fndecl)
 
       /* Clones have the same comdat group as originals.  */
       if (node->same_comdat_group
-	  || DECL_ONE_ONLY (node->decl))
+	  || (DECL_ONE_ONLY (node->decl)
+	      && !DECL_EXTERNAL (node->decl)))
 	clone->add_to_same_comdat_group (node);
 
       if (gimple_has_body_p (fndecl))
diff --git a/gcc/symtab.c b/gcc/symtab.c
index eb41d62..156fa3d 100644
--- a/gcc/symtab.c
+++ b/gcc/symtab.c
@@ -1132,7 +1132,8 @@ symtab_node::verify_symtab_nodes (void)
 	    *entry = node;
 	  else if (!DECL_EXTERNAL (node->decl))
 	    {
-	      for (s = (*entry)->same_comdat_group; s != NULL && s != node;
+	      for (s = (*entry)->same_comdat_group;
+		   s != NULL && s != node && s != *entry;
 		   s = s->same_comdat_group)
 		;
 	      if (!s || s == *entry)
diff --git a/gcc/testsuite/gcc.target/i386/mpx/pr65531.cc b/gcc/testsuite/gcc.target/i386/mpx/pr65531.cc
new file mode 100644
index 0000000..049569c
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/mpx/pr65531.cc
@@ -0,0 +1,13 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fcheck-pointer-bounds -mmpx" } */
+
+#pragma interface
+
+struct S
+{
+  ~S ()
+  {
+  }
+};
+
+S s;

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Fix ice on comdat groups with -check-pointer-bounds
  2015-03-30 11:31   ` Ilya Enkovich
@ 2015-03-30 17:20     ` Jan Hubicka
  2015-03-31 11:43       ` Ilya Enkovich
  0 siblings, 1 reply; 6+ messages in thread
From: Jan Hubicka @ 2015-03-30 17:20 UTC (permalink / raw)
  To: Ilya Enkovich; +Cc: Jan Hubicka, gcc-patches

> On 30 Mar 14:05, Ilya Enkovich wrote:
> > 2015-03-27 18:23 GMT+03:00 Jan Hubicka <hubicka@ucw.cz>:
> > > Index: symtab.c
> > > ===================================================================
> > > --- symtab.c    (revision 221734)
> > > +++ symtab.c    (working copy)
> > > @@ -1130,15 +1130,20 @@ symtab_node::verify_symtab_nodes (void)
> > >                                                   &existed);
> > >           if (!existed)
> > >             *entry = node;
> > > -         else
> > > -           for (s = (*entry)->same_comdat_group; s != NULL && s != node; s = s->same_comdat_group)
> > > +         else if (!DECL_EXTERNAL (node->decl))
> > > +           {
> > > +             for (s = (*entry)->same_comdat_group; s != NULL && s != node;
> > > +                  s = s->same_comdat_group)
> > > +               ;
> > 
> > With no if-statement in the loop body you need an additional exit
> > condition for a case when you reach the entry.
> > 
> > Thanks,
> > Ilya
> > 
> 
> Here is a patch to add a testcase, fix the loop and avoid same_comdat_group for instrumented external symbols.  Does it look OK?

OK
> 
> BTW should we check same_comdat_group is NULL for external symbols?

We could do that, yes.  If you can come with a patch, it is OK for next stage1.

Honza

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Fix ice on comdat groups with -check-pointer-bounds
  2015-03-30 17:20     ` Jan Hubicka
@ 2015-03-31 11:43       ` Ilya Enkovich
  0 siblings, 0 replies; 6+ messages in thread
From: Ilya Enkovich @ 2015-03-31 11:43 UTC (permalink / raw)
  To: Jan Hubicka; +Cc: gcc-patches

2015-03-30 20:20 GMT+03:00 Jan Hubicka <hubicka@ucw.cz>:
>> On 30 Mar 14:05, Ilya Enkovich wrote:
>> > 2015-03-27 18:23 GMT+03:00 Jan Hubicka <hubicka@ucw.cz>:
>> > > Index: symtab.c
>> > > ===================================================================
>> > > --- symtab.c    (revision 221734)
>> > > +++ symtab.c    (working copy)
>> > > @@ -1130,15 +1130,20 @@ symtab_node::verify_symtab_nodes (void)
>> > >                                                   &existed);
>> > >           if (!existed)
>> > >             *entry = node;
>> > > -         else
>> > > -           for (s = (*entry)->same_comdat_group; s != NULL && s != node; s = s->same_comdat_group)
>> > > +         else if (!DECL_EXTERNAL (node->decl))
>> > > +           {
>> > > +             for (s = (*entry)->same_comdat_group; s != NULL && s != node;
>> > > +                  s = s->same_comdat_group)
>> > > +               ;
>> >
>> > With no if-statement in the loop body you need an additional exit
>> > condition for a case when you reach the entry.
>> >
>> > Thanks,
>> > Ilya
>> >
>>
>> Here is a patch to add a testcase, fix the loop and avoid same_comdat_group for instrumented external symbols.  Does it look OK?
>
> OK
>>
>> BTW should we check same_comdat_group is NULL for external symbols?
>
> We could do that, yes.  If you can come with a patch, it is OK for next stage1.

Bootstrap fails with such check. Seems we may have same_comdat_group
for external symbols with body.

Ilya

>
> Honza

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2015-03-31 11:43 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-27 15:23 Fix ice on comdat groups with -check-pointer-bounds Jan Hubicka
2015-03-30  9:59 ` Ilya Enkovich
2015-03-30 11:05 ` Ilya Enkovich
2015-03-30 11:31   ` Ilya Enkovich
2015-03-30 17:20     ` Jan Hubicka
2015-03-31 11:43       ` Ilya Enkovich

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).