Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 29 Aug 2013 09:52:52 -0600
From:      Eric Blake <eblake@redhat.com>
To:        svn-src-head@freebsd.org
Cc:        libvir-list <libvir-list@redhat.com>, Jason Helfman <jgh@freebsd.org>
Subject:   Re: [libvirt] FreeBSD, no gcc present libvirt build issue
Message-ID:  <521F6E54.1070104@redhat.com>
In-Reply-To: <521F6C0F.9060007@redhat.com>
References:  <CAMuy=%2BiG20hs9b%2BD210=TZ50weyaJoPK8NZ8Mgea8s1A2UDQhw@mail.gmail.com> <521F63F4.4020406@redhat.com> <CAMuy=%2BhO15c_0EdjnMQMtL5OGESfQkkvjZ5oUwRGv2%2B0VB6U0w@mail.gmail.com> <CAMuy=%2BhgHARZyAUgiVaf0hdOSpTQOGRubucCY%2BQ6-kzDN8a5Ng@mail.gmail.com> <521F6C0F.9060007@redhat.com>

next in thread | previous in thread | raw e-mail | index | archive | help
This is an OpenPGP/MIME signed message (RFC 4880 and 3156)
--AQ4mVn6r2NRDXmguch35K5SJvc5saQ51h
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

On 08/29/2013 09:43 AM, Eric Blake wrote:
> On 08/29/2013 09:35 AM, Jason Helfman wrote:
>=20
>>>>
>>> stdlib.h:#define        RAND_MAX        0x7fffffff
>=20
> Good.
>=20
>>>
>>> -jgh
>>>
>>
>> And on our current head release (10) it is this:
>>
>> #define RAND_MAX        0x7ffffffd
>=20
> Huh?  Why is this not 2**n-1?  That violates assumptions we have made,
> and is WHY your compile failed.  It has nothing to do with clang vs. gc=
c
> (both compilers would fail), it has to do with your changed system
> header resulting in violating assumptions that hold in ALL OTHER
> IMPLEMENTATIONS, that random numbers are evenly distributed within a
> range of a power of 2.
>=20

http://lists.freebsd.org/pipermail/svn-src-head/2013-July/049076.html

makes it look like the reduction in range was _intentional_?  Yuck.  A
non-power-of-2 random generator adds needless complexity to the user.

I think I can fix libvirt to work around the boneheaded decision;
basically, since we cannot trust the full range of random_r to be evenly
distributed, I will have to tweak libvirt's call to truncate every call
to random_r to a subset of bits that are more likely to be evenly
distributed (maybe by shifting off the most- and least-significant bits
returned, and only using 28 instead of 31 bits of randomness per call).
 But I would MUCH rather prefer that FreeBSD revisit their decision, and
guarantee that random output be evenly distributed across the full 31
bits to begin with.

I also intend to open a bug against POSIX to request that RAND_MAX be
required to be 2**n-1, rather than relying on the assumption that
everyone so far, until FreeBSD 10, has happened to meet that requirement.=


--=20
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


--AQ4mVn6r2NRDXmguch35K5SJvc5saQ51h
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: OpenPGP digital signature
Content-Disposition: attachment; filename="signature.asc"

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.14 (GNU/Linux)
Comment: Public key at http://people.redhat.com/eblake/eblake.gpg
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQEcBAEBCAAGBQJSH25UAAoJEKeha0olJ0Nq/DoIAJOHji6KrYBkyzj8zGaWaHCA
R+H1/LlJGYeTIVhdzuhEM1VTdRjU6Bw10ZFkpFadCJ8osGDUCwBmbIL8NPN88nq9
6uzXkmQKtCqieHPIPkT+crKvt0r08GF+H48jWBE+nuEtrum1ot1oB6D0zMXzgNOQ
WHJAhHWoJwn0CUpi1n5vm34K0oyzMAjyFv936DI7kB2u2tQOkJxkC702TNxN5py+
coImNWAI8pRljW69RP1VAB3DFf9vp6crLjaBdOpOjLWV/v0yq/e79iwd4oBS3lSX
DYU27jK/kZX+ypVR0Bh6WFq3RpgSk+f19aIwy7BZY8jj5AG34IYHD7qfyP5ueO8=
=sv6h
-----END PGP SIGNATURE-----

--AQ4mVn6r2NRDXmguch35K5SJvc5saQ51h--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?521F6E54.1070104>