Reputation: 563
I compile twice the same .c and .h files and get object files with the same size but different md5sums.
Here is the only difference from objdump -d
:
1) cpcidskephemerissegment.o: file format elf64-x86-64
Disassembly of section .text:
0000000000000000 <_ZN68_GLOBAL__N_sdk_segment_cpcidskephemerissegment.cpp_00000000_B8B9E66611MinFunctionEii>:
2) cpcidskephemerissegment.o: file format elf64-x86-64
Disassembly of section .text:
0000000000000000 <_ZN68_GLOBAL__N_sdk_segment_cpcidskephemerissegment.cpp_00000000_8B65537811MinFunctionEii>:
What can be the reason? Thanks!
Upvotes: 3
Views: 280
Reputation: 40832
The reasons can be many:
__DATE__
and __TIME__
.comments
ELF section. One example of a compiler that does this is the xlC compiler on AIX.To produce bit identical builds, you can use GCC's -frandom-seed
parameter. There were situations where it could break things before GCC 4.3, but GCC now turns functions defined in anonymous namespaces into static symbols. However, you will always be safe if you compile each file using a different value for -frandom-seed
, the simplest way being to use
the filename itself as the seed.
Upvotes: 2
Reputation: 213375
I guess, the compiler didn't know how to name this namespace and used path to the source file plus some random number.
The compiler must guarantee that a symbol in unnamed namespace does not conflict with any other symbol in your program. By default this is achieved by taking full filename of the source, and appending a random hash value to it (it's legal to compile the same source twice (e.g. with different macros) and link the two objects into a single program, and the unnamed namespace symbols must still be distinct, so using just the source filename without the seed is not enough).
If you know that you are not linking the same source file more than once, and want to have a bit-identical object file on re-compile, the solution is to add -frandom-seed="abcd"
to your compile line (replace "abcd" with anything you want; it's common to use the filename as the value of random seed). Documentation here.
Upvotes: 2
Reputation: 563
Finally I've found the answer!
c++filt
command gave the original name of the function:
{unnamed namespace}: MinFunction(int, int)
In the source was:
namespace
{
MinFunction(int a, int b) { ... }
}
I named the namespace and got stable checksum of object file! As I guess, the compiler didn't know how to name this namespace and used path to the source file plus some random number.
Upvotes: 1