svn commit: r241373 - head/lib/libc/stdlib

David Chisnall theraven at FreeBSD.org
Tue Oct 9 17:17:02 UTC 2012


On 9 Oct 2012, at 17:33, Andrey Chernov wrote:

> Do you check assembler output for _both_ cases?
> In my testing clang and gcc xor's 'junk' properly in case it have
> 'volatile' keyword (as in srandomdev()) and elide it without 'volatile'.
> IMHO this change should be backed out for srandomdev() and adding
> 'volatile' for sranddev() instead.

In it's original form, it is very dangerous - the whole expression reduces to undefined and so the LLVM IR for the call is:

call void @srand(i32 undef)

The back end is then free to use any value for the call argument, including any register value or 0.  Since the value is passed in a register, it will probably just use whatever the last value there is, which may or may not be anything sensible.  On MIPS, for example, this is most likely to be &tv, and so is 100% deterministic.

Adding the volatile means that we are doing an XOR with a value left on the stack.  If this is early on in the application, then it is most likely to be 0.  If it's later on, then there may be a value here, but it's still not very likely to be something particularly unpredictable.  

David


More information about the svn-src-all mailing list