aboutsummaryrefslogtreecommitdiff
path: root/gcc/toplev.c
diff options
context:
space:
mode:
authorAndi Kleen <ak@linux.intel.com>2011-09-29 13:15:13 +0000
committerAndi Kleen <ak@linux.intel.com>2011-09-29 13:15:13 +0000
commit37ad400cf317c869551743a0acfbef928e422a6b (patch)
tree036cb4380d2a3505ae1768b759e006e030596b0d /gcc/toplev.c
parentf99b40cb2e6b839afb5b9330aa53fb6a7ef615b6 (diff)
Use urandom to get random seed
When available use /dev/urandom to get the random seem. This will lower the probability of collisions. On other systems it will fallback to the old methods. Passes bootstrap + testsuite on x86_64. Ok? gcc/: 2011-09-26 Andi Kleen <ak@linux.intel.com> * toplev.c (init_local_tick): Try reading random seed from /dev/urandom git-svn-id: https://gcc.gnu.org/svn/gcc/trunk@179348 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/toplev.c')
-rw-r--r--gcc/toplev.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/gcc/toplev.c b/gcc/toplev.c
index 78583fc52a6..ab6b5a41837 100644
--- a/gcc/toplev.c
+++ b/gcc/toplev.c
@@ -262,7 +262,17 @@ init_local_tick (void)
{
if (!flag_random_seed)
{
- /* Get some more or less random data. */
+ /* Try urandom first. Time of day is too likely to collide.
+ In case of any error we just use the local tick. */
+
+ int fd = open ("/dev/urandom", O_RDONLY);
+ if (fd >= 0)
+ {
+ read (fd, &random_seed, sizeof (random_seed));
+ close (fd);
+ }
+
+ /* Now get the tick anyways */
#ifdef HAVE_GETTIMEOFDAY
{
struct timeval tv;