简体   繁体   中英

gcc generates different results for different filenames

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

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).

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM