diff options
author | Andi Kleen <ak@linux.intel.com> | 2011-09-29 13:14:51 +0000 |
---|---|---|
committer | Andi Kleen <ak@gcc.gnu.org> | 2011-09-29 13:14:51 +0000 |
commit | dde8b3609b40a5e9073a7638d492b8c29af2e24c (patch) | |
tree | 572521c2983256f9fae580c8be83c1898f33a849 /gcc/toplev.c | |
parent | 4056cc1ba5e5590529b257a12f80270d552019b9 (diff) | |
download | gcc-dde8b3609b40a5e9073a7638d492b8c29af2e24c.zip gcc-dde8b3609b40a5e9073a7638d492b8c29af2e24c.tar.gz gcc-dde8b3609b40a5e9073a7638d492b8c29af2e24c.tar.bz2 |
Change random seeds to 64bit and drop re-crcing
I had some trouble with random build failures in a large LTO project
and it turned out to be random seed collisions in a highly parallel build
(thanks to Honza for suggesting that)
There were multiple problems:
- The way to generate the random seed is not very random (milliseconds time plus pid)
and prone to collisions on highly parallel builds
- It's only 32bit
- Several users take the existing ascii seed and re-CRC32 it again, which
doesn't exactly improve it.
This patch changes that to:
- Always use 64bit seeds as numbers (no re-crcing)
- Change all users to use HOST_WIDE_INT
- When the user specifies a random seed it's still crc32ed, but only in
this case.
Passes bootstrap + testsuite on x86_64-linux.
gcc/cp:
2011-09-26 Andi Kleen <ak@linux.intel.com>
* repo.c (finish_repo): Use HOST_WIDE_INT_PRINT_HEX_PURE.
gcc/:
2011-09-26 Andi Kleen <ak@linux.intel.com>
* hwint.h (HOST_WIDE_INT_PRINT_HEX_PURE): Add.
* lto-streamer.c (lto_get_section_name): Remove crc32_string.
Handle numerical random seed.
* lto-streamer.h (lto_file_decl_data): Change id to unsigned HOST_WIDE_INT.
* toplev.c (random_seed): Add.
(init_random_seed): Change for numerical random seed.
(get_random_seed): Return as HOST_WIDE_INT.
(set_random_seed): Crc32 existing string.
* toplev.h (get_random_seed): Change to numercal return.
* tree.c (get_file_function_name): Remove CRC. Handle numerical random seed.
gcc/lto/:
2011-09-26 Andi Kleen <ak@linux.intel.com>
* lto.c (lto_resolution_read): Remove id dumping.
(lto_section_with_id): Turn id HOST_WIDE_ID.
(create_subid_section_table): Dito.
From-SVN: r179347
Diffstat (limited to 'gcc/toplev.c')
-rw-r--r-- | gcc/toplev.c | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/gcc/toplev.c b/gcc/toplev.c index 3688c09..78583fc 100644 --- a/gcc/toplev.c +++ b/gcc/toplev.c @@ -141,6 +141,9 @@ static const char *flag_random_seed; user has specified a particular random seed. */ unsigned local_tick; +/* Random number for this compilation */ +HOST_WIDE_INT random_seed; + /* -f flags. */ /* Generate code for GNU or NeXT Objective-C runtime environment. */ @@ -251,7 +254,7 @@ announce_function (tree decl) } } -/* Initialize local_tick with the time of day, or -1 if +/* Initialize local_tick with a random number or -1 if flag_random_seed is set. */ static void @@ -286,24 +289,28 @@ init_local_tick (void) static void init_random_seed (void) { - unsigned HOST_WIDE_INT value; - static char random_seed[HOST_BITS_PER_WIDE_INT / 4 + 3]; - - value = local_tick ^ getpid (); + if (flag_random_seed) + { + char *endp; - sprintf (random_seed, HOST_WIDE_INT_PRINT_HEX, value); - flag_random_seed = random_seed; + /* When the driver passed in a hex number don't crc it again */ + random_seed = strtoul (flag_random_seed, &endp, 0); + if (!(endp > flag_random_seed && *endp == 0)) + random_seed = crc32_string (0, flag_random_seed); + } + else if (!random_seed) + random_seed = local_tick ^ getpid (); /* Old racey fallback method */ } -/* Obtain the random_seed string. Unless NOINIT, initialize it if +/* Obtain the random_seed. Unless NOINIT, initialize it if it's not provided in the command line. */ -const char * +HOST_WIDE_INT get_random_seed (bool noinit) { if (!flag_random_seed && !noinit) init_random_seed (); - return flag_random_seed; + return random_seed; } /* Modify the random_seed string to VAL. Return its previous |