c++visual-studio-2012object-filesbinary-reproducibility

Reproducible builds with Visual Studio - object file difference


I am trying to ensure that two different machines produce identical builds. I have tried to make the environment as similar as possible but I still see some differences in the generated .obj and .exe files. I have been able to rule out embedded path differences and timestamps. I have also ensured that minimal code examples (like a hello world program in fact produce identical binaries).

Currently some object files are similar while others are not. If I look at the ones that differ using a diff of dumpbin /all I see differences like this:

> COMDAT; sym= "public: static int const std::numeric_limits<long double>::max_exponent" (?max_exponent@?$numeric_limits@O@std@@2HB)

< COMDAT; sym= "public: static int const std::_Locbase<int>::collate" (?collate@?$_Locbase@H@std@@2HB)

in many of the SECTION HEADER. Without having proved it 100% it seem to me that each difference is a line that occurs in another section in the dumped output from the other object file. So things seem to be in a different order. (But note that it's only my current assumption - I might be wrong.)

Any hints on how to move on from here and what the cause might be ? Build / link order ?

I have also seen that Microsoft writes this:

NOTE: There is no guarantee that Visual C++ will generate the same binary image when building the same source files on successive builds. However, you are guaranteed that the EXE (or DLL) will behave in precisely the same manner under execution, all other things being equal.

but I am still wondering what is happening in my specific case. In my case consecutive builds on the same machine provide identical builds.


Solution

  • So even though I can't explain exactly why the binary looked like it did I found one "unexpected" difference in the environment which was the root cause.

    The build log mentioned different versions for rc.exe (the resource compiler). It turns out that it's part of the Windows Kits which come with VS. However if you install two versions of visual studio they will share rc while the compiler and linker are separate.

    After making sure to install the other VS that I did not compile with the binary changed to match what I would expect.