Clang and -frandom-seed

Erik Cederstrand erik at cederstrand.dk
Fri Nov 19 15:51:32 UTC 2010


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

> 
> Den 15/11/2010 kl. 00.10 skrev Dimitry Andric:
> 
>> 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.
>>> 
>> [...]
>> So this is all on purpose, and I think it would be a bad idea to disable
>> it, unless we fully understand the consequences.
>> 
>> 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"?
>> 
>> 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.
> 
> 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.
> 
> Where in the build scripts would I need to add this flag? Something like:
> 
> CXXFLAGS += -frandom-seed=${.TARGET}
> 
> in src.conf?

Poking around, I decided to add this patch:

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

and added "WITH_DETERMINISTIC=true" to /etc/src.conf. The "random-seed=0" 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


More information about the freebsd-toolchain mailing list