Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Understanding ELF file build ID

Tags:

build

elf

Im comparing two binary files generated by versions of same code that could or could not be equal. Meld showed a small difference between the binaries, but completely disassembling both binaries revealed that every function defined was identical.

Suspecting file metadata i did:

readelf -a my_file1.so > log1.txt
readelf -a my_file2.so > log2.txt
diff log1.txt log2.txt

Result is:

772c772
<     Build ID: 067b24a4b8afa6c823ffb5462d344c5021496b66
---
>     Build ID: 7925f5c881822348c17221fd1420e7df9fdb5633

I found no good explanation of what is elf-file build id, so my main question is:

My recompilations of the code generate identical build IDs. What could have caused a different build ID of the different compilation, aside from last person who compiled it explicitly using --build-id=something?

If it helps, build architecture is powerpc64le.

like image 592
Marco Montevechi Filho Avatar asked Dec 13 '25 13:12

Marco Montevechi Filho


1 Answers

I found no good explanation of what is elf-file build id

Copying from my comment on your other question: the build-id is a unique checksum added by the linker and computed over all "important" bits of the ELF file. Its primary use is to make sure that the core file matches the binary which produced it (build-id is located very near the start of the binary, and is included in the core for this purpose).

Build-id is also used to locate correct debug info -- the best practice is to build with -O2 -g, save this "full debug" binary, then run strip -g exe exe.stripped and use the exe.stripped in production. When you get a core dump from production, use the original exe to debug it.

What could have caused a different build ID of the different compilation

Your build is likely not bit-identical. Actually achieving bit-identical rebuilds requires some effort.

One common cause of non-bit-identical rebuilds is using __DATE__ and/or __TIME__ in some message.

If you build your shared library from the same sources twice, and get a non-bit-identical rebuild, you can compare contents of each ELF section (using readelf -x $section ...). Chances are you'll find differences in .rodata or .data.

like image 200
Employed Russian Avatar answered Dec 16 '25 21:12

Employed Russian