htab_t type_hash_table;
static void set_type_quals (tree, int);
-static void append_random_chars (char *);
static int type_hash_eq (const void *, const void *);
static hashval_t type_hash_hash (const void *);
static void print_type_hash_statistics (void);
flag_random_seed = new_random_seed;
}
-/* Appends 6 random characters to TEMPLATE to (hopefully) avoid name
- clashes in cases where we can't reliably choose a unique name.
+/* Generate a crc32 of a string. */
- Derived from mkstemp.c in libiberty. */
-
-static void
-append_random_chars (char *template)
+unsigned
+crc32_string (unsigned chksum, const char *string)
{
- static const char letters[]
- = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
- unsigned HOST_WIDE_INT v;
- size_t i;
-
- default_flag_random_seed ();
-
- /* This isn't a very good hash, but it does guarantee no collisions
- when the random string is generated by the code above and the time
- delta is small. */
- v = 0;
- for (i = 0; i < strlen (flag_random_seed); i++)
- v = (v << 4) ^ (v >> (HOST_BITS_PER_WIDE_INT - 4)) ^ flag_random_seed[i];
-
- template += strlen (template);
-
- /* Fill in the random bits. */
- template[0] = letters[v % 62];
- v /= 62;
- template[1] = letters[v % 62];
- v /= 62;
- template[2] = letters[v % 62];
- v /= 62;
- template[3] = letters[v % 62];
- v /= 62;
- template[4] = letters[v % 62];
- v /= 62;
- template[5] = letters[v % 62];
-
- template[6] = '\0';
+ do
+ {
+ unsigned value = *string << 24;
+ unsigned ix;
+
+ for (ix = 8; ix--; value <<= 1)
+ {
+ unsigned feedback;
+
+ feedback = (value ^ chksum) & 0x80000000 ? 0x04c11db7 : 0;
+ chksum <<= 1;
+ chksum ^= feedback;
+ }
+ }
+ while (*string++);
+ return chksum;
}
/* P is a string that will be used in a symbol. Mask out any characters
{
/* We don't have anything that we know to be unique to this translation
unit, so use what we do have and throw in some randomness. */
-
+ unsigned len;
const char *name = weak_global_object_name;
const char *file = main_input_filename;
if (! file)
file = input_filename;
- q = (char *) alloca (7 + strlen (name) + strlen (file));
+ len = strlen (file);
+ q = (char *) alloca (9 * 2 + len);
+ memcpy (q, file, len + 1);
+ clean_symbol_name (q);
+
+ default_flag_random_seed ();
+ sprintf (q + len, "_%08X_%08X", crc32_string (0, name),
+ crc32_string (0, flag_random_seed));
- sprintf (q, "%s%s", name, file);
- append_random_chars (q);
p = q;
}
constraints). */
sprintf (buf, FILE_FUNCTION_FORMAT, type, p);
- /* Don't need to pull weird characters out of global names. */
- if (p != first_global_object_name)
- clean_symbol_name (buf + 11);
-
return get_identifier (buf);
}