+
+/* 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. */
+
+static const char *
+compare_debug_dump_opt_spec_function (int arg,
+ const char **argv ATTRIBUTE_UNUSED)
+{
+ 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");
+
+ do_spec_2 ("%{fdump-final-insns=*:%*}");
+ do_spec_1 (" ", 0, NULL);
+
+ if (argbuf_index > 0 && strcmp (argv[argbuf_index - 1], "."))
+ {
+ if (!compare_debug)
+ return NULL;
+
+ name = xstrdup (argv[argbuf_index - 1]);
+ ret = NULL;
+ }
+ else
+ {
+ const char *ext = NULL;
+
+ if (argbuf_index > 0)
+ {
+ do_spec_2 ("%{o*:%*}%{!o:%{!S:%b%O}%{S:%b.s}}");
+ ext = ".gkd";
+ }
+ else if (!compare_debug)
+ return NULL;
+ else
+ do_spec_2 ("%g.gkd");
+
+ do_spec_1 (" ", 0, NULL);
+
+ gcc_assert (argbuf_index > 0);
+
+ name = concat (argbuf[argbuf_index - 1], ext, NULL);
+
+ ret = concat ("-fdump-final-insns=", name, NULL);
+ }
+
+ which = compare_debug < 0;
+ debug_check_temp_file[which] = name;
+
+ 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;
+}
+
+static const char *debug_auxbase_opt;
+
+/* %:compare-debug-self-opt spec function. Expands to the options
+ that are to be passed in the second compilation of
+ compare-debug. */
+
+static const char *
+compare_debug_self_opt_spec_function (int arg,
+ const char **argv ATTRIBUTE_UNUSED)
+{
+ if (arg != 0)
+ fatal ("too many arguments to %%:compare-debug-self-opt");
+
+ if (compare_debug >= 0)
+ return NULL;
+
+ do_spec_2 ("%{c|S:%{o*:%*}}");
+ do_spec_1 (" ", 0, NULL);
+
+ if (argbuf_index > 0)
+ debug_auxbase_opt = concat ("-auxbase-strip ",
+ argbuf[argbuf_index - 1],
+ NULL);
+ else
+ debug_auxbase_opt = NULL;
+
+ return concat ("\
+%<o %<MD %<MMD %<MF* %<MG %<MP %<MQ* %<MT* \
+%<fdump-final-insns=* -w -S -o %j \
+%{!fcompare-debug-second:-fcompare-debug-second} \
+", compare_debug_opt, NULL);
+}
+
+/* %:compare-debug-auxbase-opt spec function. Expands to the auxbase
+ options that are to be passed in the second compilation of
+ compare-debug. It expects, as an argument, the basename of the
+ current input file name, with the .gk suffix appended to it. */
+
+static const char *
+compare_debug_auxbase_opt_spec_function (int arg,
+ const char **argv)
+{
+ char *name;
+ int len;
+
+ if (arg == 0)
+ fatal ("too few arguments to %%:compare-debug-auxbase-opt");
+
+ if (arg != 1)
+ fatal ("too many arguments to %%:compare-debug-auxbase-opt");
+
+ if (compare_debug >= 0)
+ return NULL;
+
+ len = strlen (argv[0]);
+ if (len < 3 || strcmp (argv[0] + len - 3, ".gk") != 0)
+ fatal ("argument to %%:compare-debug-auxbase-opt does not end in .gk");
+
+ if (debug_auxbase_opt)
+ return debug_auxbase_opt;
+
+#define OPT "-auxbase "
+
+ len -= 3;
+ name = (char*) xmalloc (sizeof (OPT) + len);
+ memcpy (name, OPT, sizeof (OPT) - 1);
+ memcpy (name + sizeof (OPT) - 1, argv[0], len);
+ name[sizeof (OPT) - 1 + len] = '\0';
+
+#undef OPT
+
+ return name;
+}