0

I compiled my code using the make utility and got the binaries.

I compiled the code again with a few changes in makefile (-j inserted at some points) and got a slight difference in the binaries. The difference was reported by "beyond compare". To further check in, I compiled the code again without my changes in makefile and found that the binaries are still differing.

Why is it happening that the same code compiled at different times is resulting into slightly different (in size and content) binaries? How should if check if the changes i have made are legitimate and the binaries are the same logically?

Do ask me for any further explanation.

dmckee --- ex-moderator kitten
  • 98,632
  • 24
  • 142
  • 234
ankit
  • 77
  • 1
  • 4
  • 1
    Does your build system generate source code? Does it put time stamp or some sort of random string/number like UUID in that generated code? – Chen Levy Mar 07 '11 at 07:16

2 Answers2

1

You haven't said what you're building (C, C++ etc) but I wouldn't be surprised if it's a timestamp.

You could find out the format for the binary type you're building (which will depend on your operating system) and see whether it makes sense for there to be a timestamp in the place which is changing.

It's probably easiest to do this on a tiny sample program which will produce a very small binary, to make it easier to work out what everything means.

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
0

ELF object files contain a timestamp for when they are compiled. Thus, you can expect a different object file each time you compile (on Linux or Solaris). You may find the same with other systems of object files too.

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
  • hey !! thank you for the reply. Can u please guide me how to check whether the changes i have made are working or not !!! i compiled and checked the code with the change and there were no errors. But my mentor asked me to check if there is any difference in the binaries. I used -j at some places in the makefile and the execution is faster now !! – ankit Mar 07 '11 at 08:05
  • @ankit: The `-j` in the `make` process speeds up the build, but does not affect the object code except that the timestamps in the object files will be closer together than without it. (The option `-j` has no standard meaning with any C compiler I know of.) When you say 'whether the changes I made are working or not', what are you expecting to see? Is the output different - as expected? Then yes, they're working. Does the output appear more quickly than before (or more slowly)? Then the changes are having an effect. Are the file sizes and checksums different? Then the binaries changed. – Jonathan Leffler Mar 07 '11 at 08:14
  • @ankit: Also - which platform are you working on? It is often helpful to mention that in the question. – Jonathan Leffler Mar 07 '11 at 08:17
  • hey !! thank you for the reply. Can u please guide me how to check whether the changes i have made are working or not !!! i compiled and checked the code with the change and there were no errors. But my mentor asked me to check if there is any difference in the binaries. I used -j at some places in the makefile and the execution is faster now !! – ankit Mar 08 '11 at 02:39