I have a program compiled using AVR-GCC. I'm getting a small difference in the HEX files generated on two different computers that are ostensibly set up with the same environments. I also have an ELF file for one of them. So reading the HEX file I know the precise addresses where the differences occur. How do I figure out what is causing this difference? Can you describe a process that can identify what data or function these addresses are associated with in terms of the C/C++ source code? I've ASCII-ified the HEX files to see if they are somehow simple differences in readable string data, but that is not the case. I assume this can be done using something like avr-binutils...
2 Answers
Look at the list file (generate it if you are not already doing so) and match up the source code with the addresses where the emitted code differs.

- 376,485
- 21
- 320
- 842
-
Thanks @SpehroPethany, it's actually compiled using Arduino, and I'm not seeing any lst files in the build folder. Just a HEX file and an ELF really. Maybe I can get back to a lst file from the ELF? – vicatcu Jul 16 '20 at 18:59
-
Going to try avr-objdump -d -S -j .text /path/to/my.elf > disassembly.txt based on https://forum.arduino.cc/index.php?topic=465324.0 – vicatcu Jul 16 '20 at 19:01
-
[This](https://forum.arduino.cc/index.php?topic=116132.0) topic may help? – Spehro Pefhany Jul 16 '20 at 19:03
-
I run the same exact avr-objdump command against both ELF files, and one of them outputs snippets of c-code interspersed in the assembly listing in place the other does not (making it hard to see the 'real' differences). When I look for the discrepancy by address observed in HEX diff, the listing suggests there is no difference there... I'm obviously doing something wrong, any pointers? – vicatcu Jul 17 '20 at 13:55
-
Can’t you match the assembly listing with the physical address where the difference is? – Spehro Pefhany Jul 17 '20 at 13:59
-
Yea, that's exactly what I just tried to do and I don't notice a difference there (using meld on the two listing outputs) ... puzzling. – vicatcu Jul 17 '20 at 14:05
I think best way for identifying real difference in compiled binaries is to disassemble them with avr-objdump
. This is really helpful in determining of the real difference in code and also helps in other situations such as comparing different compiler versions output and/or how compiler optimizes some things. Even if you don't know asm well enough this would be more convenient to look through it instead of just raw binary.
Since you have ELF file you can even get an output of intermix assembly output with C code. Providing you have enabled debug (-g) option in your compiler. With optimization levels above -O1 and -Og it might mess C source lines in intermix as this is how optimizer works. But still it leaves useful hints sometimes.
Try running avr-objdump -d -S file.elf
and see it's output.

- 1,889
- 12
- 23
-
Yea I ran that command on both ELFs and diffed the outputs, for some reason one of them has a lot more output than the other which makes it hard to compare them, and the addresses I see in the output don't seem to correspond to the HEX file addresses to me. – vicatcu Jul 17 '20 at 17:11
-
I've re-read your question and now can see that you have only one ELF output. ELF stores much more information (like debugging symbols, etc) than HEX file. If you can get 2nd environment to produce ELF it would be more convenient to compare two ELFs instead of HEXes. There is also a tool called elf_diff which might help to compare those and get more readable output: https://github.com/CapeLeidokos/elf_diff – NStorm Jul 20 '20 at 06:33