Why don't two binaries of programs with only comments changed exactly match in gcc?

后端 未结 3 1895
悲&欢浪女
悲&欢浪女 2020-12-23 12:51

I created two C programs

  1. Program 1

    int main()
    {
    }
    
  2. Program 2

    int main()
    {
    //Some Harmless comments
             
    
    
            
3条回答
  •  爱一瞬间的悲伤
    2020-12-23 13:25

    Note: remember that the source file name goes into the unstripped binary, so two programs coming from differently named source files will have different hashes.

    In similar situations, should the above not apply, you can try:

    • running strip against the binary to remove some fat. If the stripped binaries are the same then it was some metadata that isn't essential to the program operation.
    • generating an assembly intermediate output to verify that the difference is not in the actual CPU instructions (or, however, to better pinpoint where the difference actually is)
    • use strings, or dump both programs to hex and run a diff on the two hex dumps. Once located the difference(s), you might try and see whether there's some rhyme or reason to them (PID, timestamps, source file timestamp...). For example you might have a routine storing the timestamp at compile time for diagnostic purposes.

提交回复
热议问题