aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathan Sidwell <nathan@codesourcery.com>2003-07-06 14:48:56 +0000
committerNathan Sidwell <nathan@gcc.gnu.org>2003-07-06 14:48:56 +0000
commitc07e547752171cafffdbae0c46f90251d266141b (patch)
tree5ea18708dd25d839ae29066b52fc180c8a8e697e
parent2aab7ceb8b58b89e48e99c3e5af119cc2f50b81c (diff)
downloadgcc-c07e547752171cafffdbae0c46f90251d266141b.zip
gcc-c07e547752171cafffdbae0c46f90251d266141b.tar.gz
gcc-c07e547752171cafffdbae0c46f90251d266141b.tar.bz2
tree.h (default_flag_random_seed): Remove.
* tree.h (default_flag_random_seed): Remove. * toplev.h (local_tick): Declare. * tree.c (flag_random_seed, default_flag_random_seed): Move to toplev.c. (append_random_chars): Don't call default_flag_random_seed. * toplev.c (flag_random_seed): Define here. Set local_tick. (local_tick): Define. (randomize): New, moved from tree.c. (print_switch_values): Adjust. (toplev_main): Call randomize. From-SVN: r69005
-rw-r--r--gcc/ChangeLog13
-rw-r--r--gcc/toplev.c54
-rw-r--r--gcc/toplev.h3
-rw-r--r--gcc/tree.c33
-rw-r--r--gcc/tree.h1
5 files changed, 65 insertions, 39 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 54bc84f..da3621f 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,5 +1,18 @@
2003-07-06 Nathan Sidwell <nathan@codesourcery.com>
+ * tree.h (default_flag_random_seed): Remove.
+ * toplev.h (local_tick): Declare.
+ * tree.c (flag_random_seed, default_flag_random_seed): Move to
+ toplev.c.
+ (append_random_chars): Don't call default_flag_random_seed.
+ * toplev.c (flag_random_seed): Define here. Set local_tick.
+ (local_tick): Define.
+ (randomize): New, moved from tree.c.
+ (print_switch_values): Adjust.
+ (toplev_main): Call randomize.
+
+2003-07-06 Nathan Sidwell <nathan@codesourcery.com>
+
* tree.h (crc32_string): Declare.
* tree.c (append_random_chars): Remove.
(crc32_string): New.
diff --git a/gcc/toplev.c b/gcc/toplev.c
index 3337467..6351b69 100644
--- a/gcc/toplev.c
+++ b/gcc/toplev.c
@@ -463,6 +463,14 @@ int mem_report = 0;
and to print them when we are done. */
int flag_detailed_statistics = 0;
+/* A random sequence of characters, unless overridden by user. */
+const char *flag_random_seed;
+
+/* A local time stamp derived from the time of compilation. It will be
+ zero if the system cannot provide a time. It will be -1u, if the
+ user has specified a particular random seed. */
+unsigned local_tick;
+
/* -f flags. */
/* Nonzero means `char' should be signed. */
@@ -1560,6 +1568,43 @@ FILE *asm_out_file;
FILE *aux_info_file;
FILE *rtl_dump_file = NULL;
+/* Set up a default flag_random_seed and local_tick, unless the user
+ already specified one. */
+
+static void
+randomize (void)
+{
+ if (!flag_random_seed)
+ {
+ unsigned HOST_WIDE_INT value;
+ static char random_seed[HOST_BITS_PER_WIDE_INT / 4 + 3];
+
+ /* Get some more or less random data. */
+#ifdef HAVE_GETTIMEOFDAY
+ {
+ struct timeval tv;
+
+ gettimeofday (&tv, NULL);
+ local_tick = tv.tv_sec * 1000 + tv.tv_usec / 1000;
+ }
+#else
+ {
+ time_t now = time ();
+
+ if (now != (time_t)-1)
+ local_tick = (unsigned) now;
+ }
+#endif
+ value = local_tick ^ getpid ();
+
+ sprintf (random_seed, HOST_WIDE_INT_PRINT_HEX, value);
+ flag_random_seed = random_seed;
+ }
+ else
+ local_tick = -1;
+}
+
+
/* Decode the string P as an integral parameter.
If the string is indeed an integer return its numeric value else
issue an Invalid Option error for the option PNAME and return DEFVAL.
@@ -4394,13 +4439,10 @@ print_switch_values (FILE *file, int pos, int max,
const char **p;
/* Fill in the -frandom-seed option, if the user didn't pass it, so
- that it can be printed below. This helps reproducibility. Of
- course, the string may never be used, but we can't tell that at
- this point in the compile. */
- default_flag_random_seed ();
+ that it can be printed below. This helps reproducibility. */
+ randomize ();
/* Print the options as passed. */
-
pos = print_single_switch (file, pos, max, indent, *indent ? " " : "", term,
_("options passed: "), "");
@@ -4969,6 +5011,8 @@ toplev_main (unsigned int argc, const char **argv)
enough to default flags appropriately. */
decode_options (argc, argv);
+ randomize ();
+
/* Exit early if we can (e.g. -help). */
if (!exit_after_options)
do_compile ();
diff --git a/gcc/toplev.h b/gcc/toplev.h
index e750207..e9c7e0d 100644
--- a/gcc/toplev.h
+++ b/gcc/toplev.h
@@ -104,6 +104,9 @@ extern void fnotice (FILE *, const char *, ...)
extern int wrapup_global_declarations (union tree_node **, int);
extern void check_global_declarations (union tree_node **, int);
+/* A unique local time stamp, might be zero if none is available. */
+extern unsigned local_tick;
+
extern const char *progname;
extern const char *dump_base_name;
extern const char *aux_base_name;
diff --git a/gcc/tree.c b/gcc/tree.c
index a0f5414..b61a70b 100644
--- a/gcc/tree.c
+++ b/gcc/tree.c
@@ -4464,38 +4464,6 @@ dump_tree_statistics (void)
#define FILE_FUNCTION_FORMAT "_GLOBAL__%s_%s"
-const char *flag_random_seed;
-
-/* Set up a default flag_random_seed value, if there wasn't one already. */
-
-void
-default_flag_random_seed (void)
-{
- unsigned HOST_WIDE_INT value;
- char *new_random_seed;
-
- if (flag_random_seed != NULL)
- return;
-
- /* Get some more or less random data. */
-#ifdef HAVE_GETTIMEOFDAY
- {
- struct timeval tv;
-
- gettimeofday (&tv, NULL);
- value = (((unsigned HOST_WIDE_INT) tv.tv_usec << 16)
- ^ tv.tv_sec ^ getpid ());
- }
-#else
- value = getpid ();
-#endif
-
- /* This slightly overestimates the space required. */
- new_random_seed = xmalloc (HOST_BITS_PER_WIDE_INT / 3 + 2);
- sprintf (new_random_seed, HOST_WIDE_INT_PRINT_UNSIGNED, value);
- flag_random_seed = new_random_seed;
-}
-
/* Generate a crc32 of a string. */
unsigned
@@ -4568,7 +4536,6 @@ get_file_function_name_long (const char *type)
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));
diff --git a/gcc/tree.h b/gcc/tree.h
index 9be6532..a11a7e5 100644
--- a/gcc/tree.h
+++ b/gcc/tree.h
@@ -2931,7 +2931,6 @@ extern void expand_start_case_dummy (void);
extern HOST_WIDE_INT all_cases_count (tree, int *);
extern void check_for_full_enumeration_handling (tree);
extern void declare_nonlocal_label (tree);
-extern void default_flag_random_seed (void);
/* If KIND=='I', return a suitable global initializer (constructor) name.
If KIND=='D', return a suitable global clean-up (destructor) name. */