tree.h (crc32_string): Declare.

* tree.h (crc32_string): Declare.
	* tree.c (append_random_chars): Remove.
	(crc32_string): New.
	(get_file_function_name_long): Use crc32_string here.

From-SVN: r69004
This commit is contained in:
Nathan Sidwell 2003-07-06 14:40:49 +00:00 committed by Nathan Sidwell
parent 46c5ad278b
commit 2aab7ceb8b
3 changed files with 36 additions and 45 deletions

View File

@ -1,3 +1,10 @@
2003-07-06 Nathan Sidwell <nathan@codesourcery.com>
* tree.h (crc32_string): Declare.
* tree.c (append_random_chars): Remove.
(crc32_string): New.
(get_file_function_name_long): Use crc32_string here.
2003-07-06 Andreas Jaeger <aj@suse.de>
* gcc.c: Convert prototypes to ISO C90.

View File

@ -119,7 +119,6 @@ static GTY ((if_marked ("type_hash_marked_p"), param_is (struct type_hash)))
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);
@ -4497,44 +4496,27 @@ default_flag_random_seed (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
@ -4572,7 +4554,7 @@ get_file_function_name_long (const char *type)
{
/* 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;
@ -4581,10 +4563,15 @@ get_file_function_name_long (const char *type)
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;
}
@ -4597,10 +4584,6 @@ get_file_function_name_long (const char *type)
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);
}

View File

@ -2640,6 +2640,7 @@ extern tree builtin_function (const char *, tree, int, enum built_in_class,
const char *, tree);
/* In tree.c */
extern unsigned crc32_string (unsigned, const char *);
extern void clean_symbol_name (char *);
extern tree get_file_function_name_long (const char *);
extern tree get_set_constructor_bits (tree, char *, int);