Two binaries were compiled. One is on a 32-bit Windows 7 machine and other is on a 64-bit Windows 10. All the source files and dependencies are the same; however, after compilation the checksum was compared and they are different. Could someone provide an explanation as to why?
-
6Are you comparing a 32-bit build and a 64-bit build and wondering why the binaries are different? If the checksums were the same you'd have a problem. The machine instructions are going to be vastly different. – tadman Jul 09 '20 at 18:56
-
7Why would you expect them to be the same? I feel like you're making an assumption that doesn't hold. – Siguza Jul 09 '20 at 18:58
-
4Unless you've taken specific measures to achieve [reproducible builds](https://stackoverflow.com/q/1180852/11683), they are going to be different even on the same machine. – GSerg Jul 09 '20 at 19:02
-
4Even compiling twice on the same machine might not give the same checksum, since some compilers have the annoying habit of putting a time stamp into the executable. – user3386109 Jul 09 '20 at 19:02
-
@Siguza I would like to know why, the science behind it. I never said I expected them to be the same, I said "after compilation the checksum was compared and they are different". Please help with the science behind this outcome. – Jul 09 '20 at 19:12
-
@Siguza If you read the post correctly you probably wouldn't have had that feeling. – Jul 09 '20 at 19:21
-
3@VictorS Asking why they differ implies that you expect them not to be. – dbush Jul 09 '20 at 19:24
-
@dbush it was merely an observation not implying. – Jul 09 '20 at 19:43
2 Answers
If you're comparing a 32-bit build and a 64-bit build you'll need to keep in mind that the compiled code will be almost completely different. 64-bit x86_64 and 32-bit x86 machine code will not only vary considerably, but even if that was not the case, remember that pointers are twice the size in 64-bit code, so a lot of code will be structured differently and addresses in the code will be expressed as bigger pointers.
The technical reason is the machine code is not the same between different architectures. Intel x86, and x86_64 have considerable variation in how the opcodes are expressed, and in how programs are structured internally. If you want to read up on the differences there's a lot of published material that can explain, like Intel's own references.
As others have pointed out building twice on the same machine may not even produce a byte-for-byte matching binary. There will be slight differences in it, especially if there's a code-signing step.
In short, you can't do this and expect them to match.

- 208,517
- 23
- 234
- 262
All the source files and dependencies are the same; however, after compilation the checksum was compared and they are different.
The checksum is calculated from the binary code that the compiler produces, not the source code. If anything is different, you should get a different checksum. Changes in the source code will change the binary, so a different checksum. But using a different compiler will also produce a different binary. Using the same compiler with different options will produce a different binary. Compiling the same program with the same compiler and the same compiler options on a different machine might produce a different binary. Compiling the same program for different processor architectures will definitely produce a different binary.

- 124,013
- 19
- 183
- 272