]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
godump: Fix -fdump-go-spec= reproduceability issue [PR101407]
authorJakub Jelinek <jakub@redhat.com>
Wed, 14 Jul 2021 08:22:50 +0000 (10:22 +0200)
committerJakub Jelinek <jakub@redhat.com>
Wed, 14 Jul 2021 08:22:50 +0000 (10:22 +0200)
pot_dummy_types is a hash_set from whose traversal the code prints some type
lines.  hash_set normally uses default_hash_traits which for pointer types
(the hash set hashes const char *) uses pointer_hash which hashes the
addresses of the pointers except of the least significant 3 bits.
With address space randomization, that results in non-determinism in the
-fdump-go-specs= generated file, each invocation can have different order of
the lines emitted from pot_dummy_types traversal.

This patch fixes it by hashing the string contents instead to make the
hashes reproduceable.

2021-07-14  Jakub Jelinek  <jakub@redhat.com>

PR go/101407
* godump.c (godump_str_hash): New type.
(godump_container::pot_dummy_types): Use string_hash instead of
ptr_hash in the hash_set.

gcc/godump.c

index cf9989490356856e01559f7b3a9398fc1a9b6bba..a50aef1f5fa0a85f06ae591d4bfeca8fc417607b 100644 (file)
@@ -56,6 +56,8 @@ static FILE *go_dump_file;
 
 static GTY(()) vec<tree, va_gc> *queue;
 
+struct godump_str_hash : string_hash, ggc_remove <const char *> {};
+
 /* A hash table of macros we have seen.  */
 
 static htab_t macro_hash;
@@ -535,7 +537,7 @@ public:
 
   /* Types which may potentially have to be defined as dummy
      types.  */
-  hash_set<const char *> pot_dummy_types;
+  hash_set<const char *, false, godump_str_hash> pot_dummy_types;
 
   /* Go keywords.  */
   htab_t keyword_hash;