tags:

views:

279

answers:

2

diff fails as the assembly listing is filled with slightly different labels.

A: 

You could strip out the labels with a simple sed and replace them all with "label" or with spaces (and use "diff -w").

That won't account for places where different registers have been used but the operations are the same. This can be quite common, adding a variable to a function can cause registers to be reallocated throughout the code in places not directly related.

The only way to handle that is to write a program to specifically seek out and handle those cases. I don't think you will find any "simple" solution that will work under all conditions.

SoapBox
+4  A: 

Instead of directly comparing the assembly listings produced by the -S option, you could instead compile down to object files, disassemble the object files, and then compare those. (Or, you could just do a straight out diff of the hexdump of the compiled object code, but that's much more painful). This gets rid of most labels, so it should make it easier to compare with diff. For example:

g++ file1.cc -c -o file1.o
g++ file2.cc -c -o file2.o
objdump -d file1.o > file1.s
objdump -d file2.o > file2.s
diff file1.s file2.s
Adam Rosenfield