diff options
-rw-r--r-- | gcc/ChangeLog | 17 | ||||
-rw-r--r-- | gcc/config.in | 5 | ||||
-rw-r--r-- | gcc/config/alpha/t-crtfm | 3 | ||||
-rwxr-xr-x | gcc/configure | 2 | ||||
-rw-r--r-- | gcc/configure.in | 2 | ||||
-rw-r--r-- | gcc/doc/invoke.texi | 14 | ||||
-rw-r--r-- | gcc/flags.h | 5 | ||||
-rw-r--r-- | gcc/toplev.c | 14 | ||||
-rw-r--r-- | gcc/tree.c | 68 | ||||
-rw-r--r-- | gcc/tree.h | 1 |
10 files changed, 96 insertions, 35 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 1e7e836..4b8241d 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,5 +1,22 @@ 2003-04-11 Geoffrey Keating <geoffk@apple.com> + PR c++/9393 + * doc/invoke.texi (Debugging Options): Document -frandom-seed. + * configure.in: Check for gettimeofday. + * tree.c (flag_random_seed): Define. + (default_flag_random_seed): New. + (append_random_chars): Use flag_random_seed rather than trying + to acquire randomness here. + * tree.h (default_flag_random_seed): Declare. + * toplev.c (display_help): Add -frandom-seed and -fstack-limit-* + descriptions. + (decode_f_option): Handle -frandom-seed. + (print_switch_values): Call default_flag_random_seed. + * flags.h (flag_random_seed): Declare. + * configure: Regenerate. + * config.in: Regenerate. + * config/alpha/t-crtfm: Use -frandom-seed. + * doc/extend.texi (Empty Structures): New. * c-pch.c: Include flags.h. Add comments to routines. diff --git a/gcc/config.in b/gcc/config.in index f0d4c3c..1f190e2 100644 --- a/gcc/config.in +++ b/gcc/config.in @@ -1,4 +1,4 @@ -/* config.in. Generated automatically from configure.in by autoheader 2.13. */ +/* config.in. Generated automatically from configure.in by autoheader. */ /* Define if using alloca.c. */ #undef C_ALLOCA @@ -150,6 +150,9 @@ /* Define if you have the getrusage function. */ #undef HAVE_GETRUSAGE +/* Define if you have the gettimeofday function. */ +#undef HAVE_GETTIMEOFDAY + /* Define if you have the getuid function. */ #undef HAVE_GETUID diff --git a/gcc/config/alpha/t-crtfm b/gcc/config/alpha/t-crtfm index 7076b51..5ca8c3f 100644 --- a/gcc/config/alpha/t-crtfm +++ b/gcc/config/alpha/t-crtfm @@ -1,4 +1,5 @@ EXTRA_PARTS += crtfastmath.o crtfastmath.o: $(srcdir)/config/alpha/crtfastmath.c $(GCC_PASSES) - $(GCC_FOR_TARGET) $(LIBGCC2_CFLAGS) -c -o crtfastmath.o $(srcdir)/config/alpha/crtfastmath.c + $(GCC_FOR_TARGET) $(LIBGCC2_CFLAGS) -frandom-seed=gcc-crtfastmath -c \ + -o crtfastmath.o $(srcdir)/config/alpha/crtfastmath.c diff --git a/gcc/configure b/gcc/configure index e42c97d..63063d9 100755 --- a/gcc/configure +++ b/gcc/configure @@ -3714,7 +3714,7 @@ fi for ac_func in times clock dup2 kill getrlimit setrlimit atoll atoq \ sysconf strsignal putc_unlocked fputc_unlocked fputs_unlocked \ fwrite_unlocked fprintf_unlocked getrusage nl_langinfo lstat \ - scandir alphasort + scandir alphasort gettimeofday do echo $ac_n "checking for $ac_func""... $ac_c" 1>&6 echo "configure:3721: checking for $ac_func" >&5 diff --git a/gcc/configure.in b/gcc/configure.in index ebbe37f..2a1fbdd 100644 --- a/gcc/configure.in +++ b/gcc/configure.in @@ -787,7 +787,7 @@ dnl gcc_AC_C_ENUM_BF_UNSIGNED AC_CHECK_FUNCS(times clock dup2 kill getrlimit setrlimit atoll atoq \ sysconf strsignal putc_unlocked fputc_unlocked fputs_unlocked \ fwrite_unlocked fprintf_unlocked getrusage nl_langinfo lstat \ - scandir alphasort) + scandir alphasort gettimeofday) AC_CHECK_TYPE(ssize_t, int) diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index f899830..384d631 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -242,15 +242,15 @@ in the following sections. -fdump-tree-original@r{[}-@var{n}@r{]} @gol -fdump-tree-optimized@r{[}-@var{n}@r{]} @gol -fdump-tree-inlined@r{[}-@var{n}@r{]} @gol --feliminate-dwarf2-dups -fmem-report @gol --fprofile-arcs -fsched-verbose=@var{n} @gol +-feliminate-dwarf2-dups -feliminate-unused-debug-types @gol +-fmem-report -fprofile-arcs @gol +-frandom-seed=@var{string} -fsched-verbose=@var{n} @gol -ftest-coverage -ftime-report @gol -g -g@var{level} -gcoff -gdwarf -gdwarf-1 -gdwarf-1+ -gdwarf-2 @gol -ggdb -gstabs -gstabs+ -gvms -gxcoff -gxcoff+ @gol -p -pg -print-file-name=@var{library} -print-libgcc-file-name @gol -print-multi-directory -print-multi-lib @gol -print-prog-name=@var{program} -print-search-dirs -Q @gol --feliminate-unused-debug-types @gol -save-temps -time} @item Optimization Options @@ -3280,6 +3280,14 @@ Dump after all tree based optimization, to @file{@var{file}.optimized}. Dump after function inlining, to @file{@var{file}.inlined}. @end table +@item -frandom-seed=@var{string} +@opindex frandom-string +This option provides a seed that GCC uses when it would otherwise use +random numbers. At present, this is used to generate certain symbol names +that have to be different in every compiled file. + +The @var{string} should be different for every file you compile. + @item -fsched-verbose=@var{n} @opindex fsched-verbose On targets that use instruction scheduling, this option controls the diff --git a/gcc/flags.h b/gcc/flags.h index 1ca9de2..e02c3de 100644 --- a/gcc/flags.h +++ b/gcc/flags.h @@ -671,6 +671,11 @@ extern int flag_signaling_nans; extern int flag_unit_at_a_time; +/* A string that's used when a random name is required. NULL means + to make it really random. */ + +extern const char *flag_random_seed; + /* True if the given mode has a NaN representation and the treatment of NaN operands is important. Certain optimizations, such as folding x * 0 into x, are not correct for NaN operands, and are normally diff --git a/gcc/toplev.c b/gcc/toplev.c index 25a6905..3af0bd8 100644 --- a/gcc/toplev.c +++ b/gcc/toplev.c @@ -3842,6 +3842,10 @@ display_help () printf (_(" -fmessage-length=<number> Limits diagnostics messages lengths to <number> characters per line. 0 suppresses line-wrapping\n")); printf (_(" -fdiagnostics-show-location=[once | every-line] Indicates how often source location information should be emitted, as prefix, at the beginning of diagnostics when line-wrapping\n")); printf (_(" -ftls-model=[global-dynamic | local-dynamic | initial-exec | local-exec] Indicates the default thread-local storage code generation model\n")); + printf (_(" -fstack-limit-register=<register> Trap if the stack goes past <register>\n")); + printf (_(" -fstack-limit-symbol=<name> Trap if the stack goes past symbol <name>\n")); + printf (_(" -frandom-seed=<string> Make compile reproducible using <string>\n")); + for (i = ARRAY_SIZE (f_options); i--;) { @@ -4199,6 +4203,10 @@ decode_f_option (arg) } else if (!strcmp (arg, "no-stack-limit")) stack_limit_rtx = NULL_RTX; + else if ((option_value = skip_leading_substring (arg, "random-seed="))) + flag_random_seed = option_value; + else if (!strcmp (arg, "no-random-seed")) + flag_random_seed = NULL; else if (!strcmp (arg, "preprocessed")) /* Recognize this switch but do nothing. This prevents warnings about an unrecognized switch if cpplib has not been linked in. */ @@ -4759,6 +4767,12 @@ print_switch_values (file, pos, max, indent, sep, term) size_t j; 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 (); + /* Print the options as passed. */ pos = print_single_switch (file, pos, max, indent, *indent ? " " : "", term, @@ -4294,6 +4294,38 @@ dump_tree_statistics () #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; +} + /* Appends 6 random characters to TEMPLATE to (hopefully) avoid name clashes in cases where we can't reliably choose a unique name. @@ -4305,40 +4337,20 @@ append_random_chars (template) { static const char letters[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; - static unsigned HOST_WIDE_INT value; unsigned HOST_WIDE_INT v; + size_t i; - if (! value) - { - struct stat st; + default_flag_random_seed (); - /* VALUE should be unique for each file and must not change between - compiles since this can cause bootstrap comparison errors. */ - - if (stat (main_input_filename, &st) < 0) - { - /* This can happen when preprocessed text is shipped between - machines, e.g. with bug reports. Assume that uniqueness - isn't actually an issue. */ - value = 1; - } - else - { - /* In VMS, ino is an array, so we have to use both values. We - conditionalize that. */ -#ifdef VMS -#define INO_TO_INT(INO) ((int) (INO)[1] << 16 ^ (int) (INO)[2]) -#else -#define INO_TO_INT(INO) INO -#endif - value = st.st_dev ^ INO_TO_INT (st.st_ino) ^ st.st_mtime; - } - } + /* 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); - v = value; - /* Fill in the random bits. */ template[0] = letters[v % 62]; v /= 62; @@ -3122,6 +3122,7 @@ extern void expand_start_case_dummy PARAMS ((void)); extern HOST_WIDE_INT all_cases_count PARAMS ((tree, int *)); extern void check_for_full_enumeration_handling PARAMS ((tree)); extern void declare_nonlocal_label PARAMS ((tree)); +extern void default_flag_random_seed PARAMS ((void)); /* If KIND=='I', return a suitable global initializer (constructor) name. If KIND=='D', return a suitable global clean-up (destructor) name. */ |