views:

55

answers:

2

G'day,

This has been asked before for VC++ but I am interested in the answer for Solaris.

I'm compiling and linking the following trivial C code:

#include <stdio.h>

int main() {
    printf("Hello world!\n");
    return 0;
}

using the command:

cc -o hello1 hello.c

and doing this a couple of times to get executables hello2 and hello3. This is being done on the same machine with the same compiler and in the same directory just at different times.

The sizes of the executables are the same but diff reports the binaries as differing and cmp -l goes crazy with a long list of differing locations.

Anyone know what cc is embedding in the executables to make them differ? Timestamps?

Edit: Stripping the executables as Chris suggested below makes diff report the two executables as identical.

cheers,

+1  A: 

If you use "od -c" on the two binaries, and then use a side-by-side diff program, you can get an idea what the differences are. In the past when I have investigated the Sun compilers, it's usually a date string. You can also try stripping the executable to see if that removes the ELF section that has the difference in it.

Chris Quenelle
@Chris, cheers. I'll try stripping the executables.
Rob Wells
@Chris, thanks. I've updated the question to say that stripping the executables made a difference.
Rob Wells
+1  A: 

If you take the exact same source code and compile it twice with Sun's compiler you will not get two exact-binary-duplicate files. There will be minor differences. As far as I know, it mostly just comes down to date/time issues.

Russell Newquist