This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[vta, vta4.4] stabilize random-seed to fix C++ -fcompare-debug failures
- From: Alexandre Oliva <aoliva at redhat dot com>
- To: gcc-patches at gcc dot gnu dot org, jason at redhat dot com
- Date: Tue, 18 Aug 2009 16:22:27 -0300
- Subject: [vta, vta4.4] stabilize random-seed to fix C++ -fcompare-debug failures
C++ uses the random seed in some cases of name mangling. This causes
some -fcompare-debug failures in libstdc++.
I've arranged for -fcompare-debug compiles to compute the random-seed
like cc1plus would, and pass the same seed to both compilations.
That fixed the problem. Now, I'm concerned that compilation of multiple
small C++ sources in a single command line may all get the same random
seed: time may not have changed, and the pid of gcc (unlike that of
cc1plus) won't change for sure.
Jason, could break something? Should I introduce some additional source
of variation (say, incrementing the seed between compilations, or some
such)?
Meanwhile, I'm installing this in VTA and VTA4.4.
for gcc/ChangeLog.vta
from Alexandre Oliva <aoliva@redhat.com>
* gcc.c (get_local_tick): New.
(compare_debug_dump_opt_spec_function): Use the same random-seed
for both -fcompare-debug compilations.
Index: gcc/gcc.c
===================================================================
--- gcc/gcc.c.orig 2009-07-29 23:35:40.000000000 -0300
+++ gcc/gcc.c 2009-08-18 03:13:33.000000000 -0300
@@ -8688,6 +8688,33 @@ print_asm_header_spec_function (int arg
return NULL;
}
+/* Compute a timestamp to initialize flag_random_seed. */
+
+static unsigned
+get_local_tick (void)
+{
+ unsigned ret = 0;
+
+ /* Get some more or less random data. */
+#ifdef HAVE_GETTIMEOFDAY
+ {
+ struct timeval tv;
+
+ gettimeofday (&tv, NULL);
+ ret = tv.tv_sec * 1000 + tv.tv_usec / 1000;
+ }
+#else
+ {
+ time_t now = time (NULL);
+
+ if (now != (time_t)-1)
+ ret = (unsigned) now;
+ }
+#endif
+
+ return ret;
+}
+
/* %:compare-debug-dump-opt spec function. Save the last argument,
expected to be the last -fdump-final-insns option, or generate a
temporary. */
@@ -8699,6 +8726,7 @@ compare_debug_dump_opt_spec_function (in
const char *ret;
char *name;
int which;
+ static char random_seed[HOST_BITS_PER_WIDE_INT / 4 + 3];
if (arg != 0)
fatal ("too many arguments to %%:compare-debug-dump-opt");
@@ -8740,9 +8768,19 @@ compare_debug_dump_opt_spec_function (in
which = compare_debug < 0;
debug_check_temp_file[which] = name;
-#if 0
- error ("compare-debug: [%i]=\"%s\", ret %s", which, name, ret);
-#endif
+ if (!which)
+ {
+ unsigned HOST_WIDE_INT value = get_local_tick () ^ getpid ();
+
+ sprintf (random_seed, HOST_WIDE_INT_PRINT_HEX, value);
+ }
+
+ if (*random_seed)
+ ret = concat ("%{!frandom-seed=*:-frandom-seed=", random_seed, "} ",
+ ret, NULL);
+
+ if (which)
+ *random_seed = 0;
return ret;
}
@@ -8816,5 +8854,7 @@ compare_debug_auxbase_opt_spec_function
memcpy (name + sizeof (OPT) - 1, argv[0], len);
name[sizeof (OPT) - 1 + len] = '\0';
+#undef OPT
+
return name;
}
--
Alexandre Oliva, freedom fighter http://FSFLA.org/~lxoliva/
You must be the change you wish to see in the world. -- Gandhi
Be Free! -- http://FSFLA.org/ FSF Latin America board member
Free Software Evangelist Red Hat Brazil Compiler Engineer