Reproducible builds

Hi!

I just added support for reproducible builds (-frandom-seed=) into the
qbs build system.

For a automated test case I'd like to have a small snippet of C/C++
code, which definitely leads to different object files if compiled
twice.

I wasn't able to write such a snippet, so any help would be very
appreciated.

Regards,

Stephan

You could try something like this:

template
class X{}

static X<SOME_INT> x;

// or

char str[SOME_INT];

then compile it like this:

clang++ -D$RANDOM -c file.cpp -o file.o

RANDOM is a bash thing, but basically you just need to generate a random number each time you compile and pass it in as a macro.

hth…
don

sorry, typo, should be -DSOME_INT=$RANDOM

Well,

that's not exactly what I meant. In gcc, if you use -flto a c file compiled twice leads to different binaries, if you don't add -frandom-seed=<something>.

clang also supports the switch -frandom-seed=<something>, but the object files produced by clang are always binary equal.

Meanwhile I think clang intorduced -frandom-seed only for gcc compatibility:

But thanks for the hint. :slight_smile:

Regards,

Stephan

Sorry, didn’t read closely enough. Looks like it’s currently ignored:

$ grep -n frandom_seed include/clang/Driver/Options.td
949:def frandom_seed_EQ : Joined<[“-”], “frandom-seed=”>, Group<clang_ignored_f_Group>;

http://reviews.llvm.org/D3391