Non-deterministic builds

Hello LLVM'ers

I have noticed that two consecutive builds of clang, clang++ and tblgen don't produce identical binaries (as in md5 sums) on identical source code (I'm on FreeBSD). I ran strings(1) on the two clang binaries, and I get the following:

248400,248403c248400,248403
< N128_GLOBAL__N__usr_home_erik_freebsd_head_src_lib_clang_libllvmcore_.._.._.._contrib_llvm_lib_VMCore_Verifier.cpp_00000000_36FAEB5D11PreVerifierE
< N128_GLOBAL__N__usr_home_erik_freebsd_head_src_lib_clang_libllvmcore_.._.._.._contrib_llvm_lib_VMCore_Verifier.cpp_00000000_36FAEB5D8VerifierE
< N4llvm11InstVisitorIN128_GLOBAL__N__usr_home_erik_freebsd_head_src_lib_clang_libllvmcore_.._.._.._contrib_llvm_lib_VMCore_Verifier.cpp_00000000_36FAEB5D8VerifierEvEE
< N128_GLOBAL__N__usr_home_erik_freebsd_head_src_lib_clang_libllvmcore_.._.._.._contrib_llvm_lib_VMCore_Verifier.cpp_00000000_36FAEB5D7TypeSetE

Urgh, are we using random elements in the unnamed namespace symbol generation?

Sebastian

I've seen compiler bugs + ASLR resulting in non-deterministic builds, could that be the culprit?

John Regehr

Yes, this is controlled by the -frandom-seed flag. Sadly, it is expected behavior.

-Chris

Oh, I should point out that using randomness is the unfortunate part, but you can get deterministic builds by passing -frandom-seed=0 to clang and/or gcc.

-Chris

Oh, I should point out that using randomness is the unfortunate part, but you can get deterministic builds by passing -frandom-seed=0 to clang and/or gcc.

One thing I have seen done with gcc is "gcc -c foo.c -o foo.o
-frandom-seed=foo.o". That way you still get a different seed for
different output files.

-Chris

Cheers,
Rafael

This is definitely not the direct output of clang. We mangle anonymous namespaces the same way that GCC does, i.e. 12_GLOBAL__N_1. If there's a compiler that mangles filenames into anonymous namespace names — or anything later in the toolchain which does it — I'm not aware of it.

Erik, what compiler are you using?

John.

Woah, this -frandom-seed business is new to me, nevermind.

John.

I'll try that. I assume that the randomness has a purpose, so what are the negative implications of setting -frandom-seed=0? Will i still have a functioning compiler? :slight_smile:

Thanks,
Erik

I'll try that. I assume that the randomness has a purpose, so what are the negative implications of setting -frandom-seed=0? Will i still have a functioning compiler? :slight_smile:

The compiler being gcc? The manual says:

The STRING should be different for every file you compile.

Thanks,
Erik

Cheers,
Rafael

Yes, the compiler being GCC in my case. I'll try your suggestion of using -frandom-seed=foo.o

Erik