summaryrefslogtreecommitdiff
path: root/gcc/gcc.c
diff options
context:
space:
mode:
authorak <ak@138bc75d-0d04-0410-961f-82ee72b054a4>2011-09-29 13:15:29 +0000
committerak <ak@138bc75d-0d04-0410-961f-82ee72b054a4>2011-09-29 13:15:29 +0000
commit0f41df2b6ba9f39951b13926e429090034b4ebb9 (patch)
tree73e1b598941a7e65ca0952e6d3da7a8f1ab89fe9 /gcc/gcc.c
parentad7665738cceb89b25315d45f22612510fb6acd2 (diff)
downloadgcc-0f41df2b6ba9f39951b13926e429090034b4ebb9.tar.gz
Use urandom in gcc.c too
gcc also takes generates a random number in some special circumstances, so teach it about /dev/urandom too. gcc/: 2011-09-27 Andi Kleen <ak@linux.intel.com> * gcc.c (get_local_tick). Rename to get_random_number. Read from /dev/urandom. Add getpid call. (compare_debug_dump_opt_spec_function): Drop getpid call. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@179349 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/gcc.c')
-rw-r--r--gcc/gcc.c22
1 files changed, 16 insertions, 6 deletions
diff --git a/gcc/gcc.c b/gcc/gcc.c
index ddec8db706b..3bfdf77b401 100644
--- a/gcc/gcc.c
+++ b/gcc/gcc.c
@@ -8062,12 +8062,22 @@ print_asm_header_spec_function (int arg ATTRIBUTE_UNUSED,
return NULL;
}
-/* Compute a timestamp to initialize flag_random_seed. */
+/* Get a random number for -frandom-seed */
-static unsigned
-get_local_tick (void)
+static unsigned HOST_WIDE_INT
+get_random_number (void)
{
- unsigned ret = 0;
+ unsigned HOST_WIDE_INT ret = 0;
+ int fd;
+
+ fd = open ("/dev/urandom", O_RDONLY);
+ if (fd >= 0)
+ {
+ read (fd, &ret, sizeof (HOST_WIDE_INT));
+ close (fd);
+ if (ret)
+ return ret;
+ }
/* Get some more or less random data. */
#ifdef HAVE_GETTIMEOFDAY
@@ -8086,7 +8096,7 @@ get_local_tick (void)
}
#endif
- return ret;
+ return ret ^ getpid();
}
/* %:compare-debug-dump-opt spec function. Save the last argument,
@@ -8145,7 +8155,7 @@ compare_debug_dump_opt_spec_function (int arg,
if (!which)
{
- unsigned HOST_WIDE_INT value = get_local_tick () ^ getpid ();
+ unsigned HOST_WIDE_INT value = get_random_number ();
sprintf (random_seed, HOST_WIDE_INT_PRINT_HEX, value);
}