]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c++/9393 (Anonymous namespaces and compiling the same file twice)
authorGeoffrey Keating <geoffk@apple.com>
Sat, 12 Apr 2003 02:16:46 +0000 (02:16 +0000)
committerGeoffrey Keating <geoffk@gcc.gnu.org>
Sat, 12 Apr 2003 02:16:46 +0000 (02:16 +0000)
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.

From-SVN: r65500

gcc/ChangeLog
gcc/config.in
gcc/config/alpha/t-crtfm
gcc/configure
gcc/configure.in
gcc/doc/invoke.texi
gcc/flags.h
gcc/toplev.c
gcc/tree.c
gcc/tree.h

index 1e7e8362be7a6d86354a825822c598b64471faab..4b8241d11d83f106c5169f3d890f82d94a9426b9 100644 (file)
@@ -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.
index f0d4c3c94a8bf87d44450dcd913b1168c71b7721..1f190e2d3ed484f7a1b7f47a28ad5da5f5865ecb 100644 (file)
@@ -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
 /* 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
 
index 7076b5178610b0638686ff532ae9777623513bf8..5ca8c3f747da084d6771e0c0da3b9d969af2dd65 100644 (file)
@@ -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
index e42c97df27cf84a7b83a5d931d0252b896bfabf4..63063d9c7a5c5a7f14a1c278ca83d6813c990383 100755 (executable)
@@ -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
index ebbe37f658f40168f46622831e474302122a83df..2a1fbdd862bbcb7619c4d0e4797738084cc2c09d 100644 (file)
@@ -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)
 
index f89983070afbb16b442e8cd6ef1dbf1a5ec3cc79..384d6314acc2a4da45332c74985e321184e26622 100644 (file)
@@ -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
index 1ca9de2f196d2edbee0a3ec1564b689391d42c05..e02c3de6c26d2d711d984ee91ef0e743b82eb305 100644 (file)
@@ -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
index 25a6905095a646a132c70bd5a6dd6d68e733501b..3af0bd8bfe2db25ac3469e6f733a0f29a8d06114 100644 (file)
@@ -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,
index 57d76b46401f5be74a1afa65d13071990999de9d..fc4630f62f4db5b1dc0cfe4f84be7710e1c06981 100644 (file)
@@ -4294,6 +4294,38 @@ dump_tree_statistics ()
 \f
 #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;
index b4a6703b93270b9abdb8cf0188c163b064885d30..8dacb68da55de8e7973fa367bf57954367be961b 100644 (file)
@@ -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.  */