This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Comparing binaries automatically


Hi.

We’ve got a situation were we’re refactoring Makefiles, headers, etc. and want to make sure that the resultant code is still what we’re expecting.

The easiest way to do this would be to compare the binaries with “cmp” or something like that, but unfortunately it would be easy and wrong.

Program is we have things in our build automation like:

REVISION := $(shell git log -1 --pretty=format:%h .)

CPPFLAGS += -DREVISION=‘“$(REVISION)”'

And there are programs that build __DATE__ and __USAGE__ into their help, etc.

Obviously these will change with successive compilations.

Is there an easy way to say, in high-level terms, “compare a.out and b.out ignoring section .xyzzy or the contents of memory occupied by variables ‘foo’ and ‘bar’”?

Then I could do:

const char __date[] = __DATE__;

and then interpolate “__date” into printf-format arguments instead of __DATE__… but say “ignore the symbol ‘__date’ when comparing executables".

Or alternately:

const char __date[] __attribute__((section(“xyzzy”))) = __DATE__;

and then say “ignore section .xyzzy when comparing executables”.

I thought about using objcopy and deleting the “.xyzzy” section (objcopy -R xyzzy ...) and using that for comparison, but that would result in undefined symbols.

I doubt I’m the first to need to do this, and indeed when I was at Cisco and we needed to validate a new compiler or toolchain, we’d swap out tools but do a sophisticated comparison of the binaries to see if they were identical… and then when they weren’t, we’d have to sift through disassembly listings trying to figure out what changed, why, and if the new code was equivalent or better (and correct, obviously).

Just wish I had asked some questions about what the methodology was for the validation.

Equally, I wish that binutils included a “objcmp” utility for comparing executables, module symbols and sections you might want to ignore.

Come to thing of it, such a utility would be very useful for validating changes to gcc, ld, gas, etc.

Anyone know of a way to do a “smart” comparison of executables (or relocatable objections, or shared libraries, or…)?

Thanks,

-Philip


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]