Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 19 Nov 2010 16:51:30 +0100
From:      Erik Cederstrand <erik@cederstrand.dk>
Cc:        freebsd-toolchain@freebsd.org, Dimitry Andric <dim@FreeBSD.org>
Subject:   Re: Clang and -frandom-seed
Message-ID:  <68B6258D-6853-4FF0-BE09-13B8E99BC874@cederstrand.dk>
In-Reply-To: <FD61324A-1A22-4731-A563-B0BE8AB93069@cederstrand.dk>
References:  <E135940E-F79C-4DFA-811D-18CCBF3C609E@cederstrand.dk> <4CE06C4F.7000002@FreeBSD.org> <FD61324A-1A22-4731-A563-B0BE8AB93069@cederstrand.dk>

next in thread | previous in thread | raw e-mail | index | archive | help

--Apple-Mail-2606-489561436
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain;
	charset=us-ascii


Den 15/11/2010 kl. 11.10 skrev Erik Cederstrand:

>=20
> Den 15/11/2010 kl. 00.10 skrev Dimitry Andric:
>=20
>> On 2010-11-14 23:29, Erik Cederstrand wrote:
>>> I noticed that two consecutive builds of (GCC-built) Clang don't =
produce identical binaries. This is true for clang, clang++ and tblgen. =
I asked on the llvm-dev list yesterday, and it turns out it's because =
GCC uses a random seed on some symbols. Apparently, this can be =
controlled with the -frandom-seed flag. I haven't tested if this is also =
the case for Clang-built Clang.
>>>=20
>> [...]
>> So this is all on purpose, and I think it would be a bad idea to =
disable
>> it, unless we fully understand the consequences.
>>=20
>> On the other hand, the requirement "The string should be different =
for
>> every file you compile", could possibly be fulfilled.  Maybe by using
>> the filename, relative to $SRCDIR, that is being compiled as "seed"?
>>=20
>> This would be unique for each compiled file, but still give the same
>> result for each build, and also be independent of the particular =
machine
>> you are building on.
>=20
> I was thinking of something along the same lines. I think we agree =
that it only needs to be random across files, not across builds. Someone =
on llvm-dev also suggested using the path (either full or relative to =
src/) as a seed.
>=20
> Where in the build scripts would I need to add this flag? Something =
like:
>=20
> CXXFLAGS +=3D -frandom-seed=3D${.TARGET}
>=20
> in src.conf?

Poking around, I decided to add this patch:

# svn diff lib/clang/clang.build.mk
Index: lib/clang/clang.build.mk
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- lib/clang/clang.build.mk	(revision 215422)
+++ lib/clang/clang.build.mk	(working copy)
@@ -28,6 +28,13 @@
 CXXFLAGS+=3D-fno-rtti
 .endif
=20
+.ifdef WITH_DETERMINISTIC
+CXXFLAGS+=3D-frandom-seed=3D0
+.endif

and added "WITH_DETERMINISTIC=3Dtrue" to /etc/src.conf. The =
"random-seed=3D0" should ensure that the same random elements are =
generated every time.

I then ran two buildworlds with the same MAKEOBJDIRPREFIX but two =
different DESTDIRs, and compared the two clang binaries. The random-seed =
option does show up un the log, so it's getting picked up, but =
apparently it was not enough, as the random elements are still =
different.

Any hints on where in the build infrastructure I should add the flag, or =
what to grep for in the buildworld log to find out what's wrong?

Also, how can I compile just clang? I tried "cd src/usr.bin/clang; make" =
but it dies violently:

=
/usr/home/erik/freebsd/head/src/usr.bin/clang/clang/../../../contrib/llvm/=
tools/clang/include/clang/Basic/Diagnostic.h: At global scope:
=
/usr/home/erik/freebsd/head/src/usr.bin/clang/clang/../../../contrib/llvm/=
tools/clang/include/clang/Basic/Diagnostic.h:999: error: expected ',' or =
'...' before '&' token
=
/usr/home/erik/freebsd/head/src/usr.bin/clang/clang/../../../contrib/llvm/=
tools/clang/include/clang/Basic/Diagnostic.h:1000: error: ISO C++ =
forbids declaration of 'LangOptions' with no type
=
/usr/home/erik/freebsd/head/src/usr.bin/clang/clang/../../../contrib/llvm/=
tools/clang/include/clang/Basic/Diagnostic.h:1019: error: expected =
declaration before '}' token
*** Error code 1

Stop in /usr/home/erik/freebsd/head/src/usr.bin/clang/clang.
*** Error code 1

Stop in /usr/home/erik/freebsd/head/src/usr.bin/clang.


Thanks,
Erik=

--Apple-Mail-2606-489561436--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?68B6258D-6853-4FF0-BE09-13B8E99BC874>