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

后端 未结 3 1892
悲&欢浪女
悲&欢浪女 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:40

    The most common reason are file names and time stamps added by the compiler (usually in the debug info part of the ELF sections).

    Try running

     $ strings -a program > x
     ...recompile program...
     $ strings -a program > y
     $ diff x y
    

    and you might see the reason. I once used this to find why the same source would cause different code when compiled in different directories. The finding was that the __FILE__ macro expanded to an absolute file name, different in both trees.

提交回复
热议问题