This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH]: random global function name
- From: Nathan Sidwell <nathan at codesourcery dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Sat, 05 Jul 2003 16:51:16 +0100
- Subject: [PATCH]: random global function name
- Organization: Codesourcery LLC
Hi,
This patch replaces the append_random_chars function with a crc32, and
hence removes a use of clean_symbol_name -- it seems silly to generate
a random string in a complicated manner, and then strip it of bogus chars.
The crc32_string function will be used from elsewhere.
booted & tested on i686-pc-linux-gnu, ok?
nathan
--
Nathan Sidwell :: http://www.codesourcery.com :: CodeSourcery LLC
The voices in my head said this was stupid too
nathan@codesourcery.com :: http://www.planetfall.pwp.blueyonder.co.uk
2003-07-05 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.
Index: tree.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree.c,v
retrieving revision 1.310
diff -c -3 -p -r1.310 tree.c
*** tree.c 29 Jun 2003 11:28:00 -0000 1.310
--- tree.c 5 Jul 2003 15:36:08 -0000
*************** static GTY ((if_marked ("type_hash_marke
*** 119,125 ****
htab_t type_hash_table;
static void set_type_quals PARAMS ((tree, int));
- static void append_random_chars PARAMS ((char *));
static int type_hash_eq PARAMS ((const void *, const void *));
static hashval_t type_hash_hash PARAMS ((const void *));
static void print_type_hash_statistics PARAMS((void));
--- 119,124 ----
*************** default_flag_random_seed (void)
*** 4647,4691 ****
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.
!
! Derived from mkstemp.c in libiberty. */
!
! static void
! append_random_chars (template)
! char *template;
! {
! 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';
}
/* P is a string that will be used in a symbol. Mask out any characters
--- 4646,4674 ----
flag_random_seed = new_random_seed;
}
! /* Generate a crc32 of a string. */
!
! unsigned
! crc32_string (chksum, string)
! unsigned chksum;
! const char *string;
! {
! 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
*************** get_file_function_name_long (type)
*** 4725,4731 ****
{
/* 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. */
!
const char *name = weak_global_object_name;
const char *file = main_input_filename;
--- 4708,4714 ----
{
/* 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;
*************** get_file_function_name_long (type)
*** 4734,4743 ****
if (! file)
file = input_filename;
! q = (char *) alloca (7 + strlen (name) + strlen (file));
- sprintf (q, "%s%s", name, file);
- append_random_chars (q);
p = q;
}
--- 4717,4731 ----
if (! file)
file = input_filename;
! 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));
p = q;
}
*************** get_file_function_name_long (type)
*** 4749,4758 ****
the program) rather than the file name (which imposes extra
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);
}
--- 4737,4742 ----
Index: tree.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree.h,v
retrieving revision 1.418
diff -c -3 -p -r1.418 tree.h
*** tree.h 1 Jul 2003 02:04:11 -0000 1.418
--- tree.h 5 Jul 2003 15:36:16 -0000
*************** extern tree builtin_function PARAMS ((c
*** 2648,2653 ****
--- 2648,2654 ----
const char *, tree));
/* In tree.c */
+ extern unsigned crc32_string PARAMS ((unsigned, const char *));
extern void clean_symbol_name PARAMS ((char *));
extern tree get_file_function_name_long PARAMS ((const char *));
extern tree get_set_constructor_bits PARAMS ((tree, char *, int));