Patch to get_file_function_name_long
Jason Merrill
jason@cygnus.com
Wed Oct 28 23:40:00 GMT 1998
If we don't have a known-unique key to generate file functions from, we
have to approximate one. This patch improves that approximation by adding
randomness.
Fixes g++.pt/instantiate5.C. Applied.
Wed Oct 28 22:58:35 1998 Jason Merrill <jason@yorick.cygnus.com>
* tree.c (append_random_chars): New fn.
(get_file_function_name_long): Use it.
Index: tree.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/tree.c,v
retrieving revision 1.47
diff -c -p -r1.47 tree.c
*** tree.c 1998/10/21 09:53:38 1.47
--- tree.c 1998/10/29 06:58:22
*************** int (*lang_get_alias_set) PROTO((tree));
*** 265,270 ****
--- 265,271 ----
#define TYPE_HASH(TYPE) ((unsigned long) (TYPE) & 0777777)
static void set_type_quals PROTO((tree, int));
+ static void append_random_chars PROTO((char *));
extern char *mode_name[];
*************** dump_tree_statistics ()
*** 4820,4828 ****
extern char * first_global_object_name;
extern char * weak_global_object_name;
! /* TYPE is some string to identify this function to the linker or
! collect2. */
tree
get_file_function_name_long (type)
char *type;
--- 4821,4876 ----
extern char * first_global_object_name;
extern char * weak_global_object_name;
! /* 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";
+ static unsigned HOST_WIDE_INT value;
+ unsigned HOST_WIDE_INT v;
+
+ #ifdef HAVE_GETTIMEOFDAY
+ struct timeval tv;
+ #endif
+
+ template += strlen (template);
+
+ #ifdef HAVE_GETTIMEOFDAY
+ /* Get some more or less random data. */
+ gettimeofday (&tv, NULL);
+ value += ((unsigned HOST_WIDE_INT) tv.tv_usec << 16) ^ tv.tv_sec ^ getpid ();
+ #else
+ value += getpid ();
+ #endif
+
+ v = value;
+
+ /* 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';
+ }
+
+ /* Generate a name for a function unique to this translation unit.
+ TYPE is some string to identify the purpose of this function to the
+ linker or collect2. */
+
tree
get_file_function_name_long (type)
char *type;
*************** get_file_function_name_long (type)
*** 4832,4843 ****
if (first_global_object_name)
p = first_global_object_name;
- else if (weak_global_object_name)
- p = weak_global_object_name;
- else if (main_input_filename)
- p = main_input_filename;
else
! p = input_filename;
buf = (char *) alloca (sizeof (FILE_FUNCTION_FORMAT) + strlen (p)
+ strlen (type));
--- 4880,4903 ----
if (first_global_object_name)
p = first_global_object_name;
else
! {
! /* 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. */
!
! char *name = weak_global_object_name;
! char *file = main_input_filename;
!
! if (! name)
! name = "";
! if (! file)
! file = input_filename;
!
! p = (char *) alloca (7 + strlen (name) + strlen (file));
!
! sprintf (p, "%s%s", name, file);
! append_random_chars (p);
! }
buf = (char *) alloca (sizeof (FILE_FUNCTION_FORMAT) + strlen (p)
+ strlen (type));
More information about the Gcc-patches
mailing list