public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [patch] Fix non-deterministic output order for type stubs in DWARF output
@ 2013-04-25  8:04 Cary Coutant
  2013-06-10 23:50 ` Cary Coutant
  0 siblings, 1 reply; 2+ messages in thread
From: Cary Coutant @ 2013-04-25  8:04 UTC (permalink / raw)
  To: Jason Merrill, gcc-patches

Jason, would you like to take a look at this patch before I commit it?

If I turn on -fdebug-types-section, I get a random failure in
g++.dg/pch/system-2.C. This failure is being caused by
non-deterministic order of the type stubs emitted by
optimize_external_refs, because it's using the address of the DIE as a
hash for the extern_map hash table. This patch makes the output order
deterministic by using either the die_symbol (as a string) or the type
signature for the hash value.

Bootstrapped on x86_64 with no regressions.

(I'm not planning to turn on -fdebug-types-section by default; I'm
just trying to make sure the test suite is clean with it on so that I
can turn it on in the google branches.)

-cary


2013-04-24  Cary Coutant  <ccoutant@google.com>

gcc/
        * dwarf2out.c (hash_external_ref): Use die_symbol or signature
        for hash so that hash table traversal order is deterministic.


Index: gcc/dwarf2out.c
===================================================================
--- gcc/dwarf2out.c     (revision 198260)
+++ gcc/dwarf2out.c     (working copy)
@@ -7385,7 +7385,22 @@ static hashval_t
 hash_external_ref (const void *p)
 {
   const struct external_ref *r = (const struct external_ref *)p;
-  return htab_hash_pointer (r->type);
+  dw_die_ref die = r->type;
+  hashval_t h = 0;
+
+  /* We can't use the address of the DIE for hashing, because
+     that will make the order of the stub DIEs non-deterministic.  */
+  if (! die->comdat_type_p)
+    /* We have a symbol; use it to compute a hash.  */
+    h = htab_hash_string (die->die_id.die_symbol);
+  else
+    {
+      /* We have a type signature; use a subset of the bits as the hash.
+         The 8-byte signature is at least as large as hashval_t.  */
+      comdat_type_node_ref type_node = die->die_id.die_type_node;
+      memcpy (&h, type_node->signature, sizeof (h));
+    }
+  return h;
 }

 /* Compare external_refs.  */

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

* Re: [patch] Fix non-deterministic output order for type stubs in DWARF output
  2013-04-25  8:04 [patch] Fix non-deterministic output order for type stubs in DWARF output Cary Coutant
@ 2013-06-10 23:50 ` Cary Coutant
  0 siblings, 0 replies; 2+ messages in thread
From: Cary Coutant @ 2013-06-10 23:50 UTC (permalink / raw)
  To: Jason Merrill, gcc-patches

I've committed this patch.

-cary


2013-06-10  Cary Coutant  <ccoutant@google.com>

gcc/
        * dwarf2out.c (hash_external_ref): Use die_symbol or signature
        for hash so that hash table traversal order is deterministic.



> Index: gcc/dwarf2out.c
> ===================================================================
> --- gcc/dwarf2out.c     (revision 198260)
> +++ gcc/dwarf2out.c     (working copy)
> @@ -7385,7 +7385,22 @@ static hashval_t
>  hash_external_ref (const void *p)
>  {
>    const struct external_ref *r = (const struct external_ref *)p;
> -  return htab_hash_pointer (r->type);
> +  dw_die_ref die = r->type;
> +  hashval_t h = 0;
> +
> +  /* We can't use the address of the DIE for hashing, because
> +     that will make the order of the stub DIEs non-deterministic.  */
> +  if (! die->comdat_type_p)
> +    /* We have a symbol; use it to compute a hash.  */
> +    h = htab_hash_string (die->die_id.die_symbol);
> +  else
> +    {
> +      /* We have a type signature; use a subset of the bits as the hash.
> +         The 8-byte signature is at least as large as hashval_t.  */
> +      comdat_type_node_ref type_node = die->die_id.die_type_node;
> +      memcpy (&h, type_node->signature, sizeof (h));
> +    }
> +  return h;
>  }
>
>  /* Compare external_refs.  */

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

end of thread, other threads:[~2013-06-10 23:50 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-04-25  8:04 [patch] Fix non-deterministic output order for type stubs in DWARF output Cary Coutant
2013-06-10 23:50 ` Cary Coutant

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).