Reputation: 255
Why does gcc generate different executables for different sourcefilenames?
to test I have this c-programm called test.c and test2.c:
int main(){}
"gcc test.c -o test" and "gcc test2.c -o test2" generate different output files. Using a hex-editor I can see that there still is its source-filename hidden in it. Stripping the files still results in different results (the source-filename is gone). Why does gcc operate this way? I tested clang and tcc as well. Clang behaves the like gcc does, whereas tcc generates the same results for different filenames?
gcc version 4.9.1 (Debian 4.9.1-1)
clang 3.4.2-4
tcc version 0.9.25
Upvotes: 4
Views: 131
Reputation: 1669
The -o option of gcc is to specify the output file. If you give him different -o targets, it will generate different files.
gcc test.c -o foo
And you have a foo
executable.
Also, note that without a -o option, gcc will output a a.out
executable.
Upvotes: -1
Reputation: 11706
Doing a diff
on the hexdump of both binaries shows a small difference at around offset 0x0280
. Looking through the sections (via objdump -x
), the differences appear in the .note.gnu.build-id
section. My guess is that this provides some sort of UUID for distinguishing different builds of otherwise similar code, as well as validate debug info (referenced here, about a third of the way down).
Upvotes: 4