I have been looking around for an ABI cross-check tool. Now I have met some of the tools suggested in other questions, such as in these questions:
How to test binary compatibility automatically?
Static analysis tool to detect ABI breaks in C++
Now, this is not exactly what I am trying to do - as these track ABI changes between versions.
I was wondering that given project source files + library header file and library .so file, as well as a compiler version (which is used for compiling both the library and the project), is it possible to cross check that the output of the ABI matches the compiled library?
So, the situation that it would apply to, is if an upstream library shipped libfoo.so and libfood.so. Where food is a slightly different ABI, (say doubles instead of float), but not so far that it wont compile.
- Is it possible to come up with a test (possibly not bulletproof) that says that the compiled executable has linked against the correct lib?
- Are there tools that do this?
If you assume you have only
libfoo.so
coded in C (without having its header files, which you should also have), there is no way to know e.g. the signature of the functions inside, because the symbol table of a shared object don't contain any typing information (e.g. nothing except conventional wisdom prevent a library to contain amalloc
function which adds two integers and return their sum, instead of doing the usual heap allocation).So the
libfoo.so
can be abused. However, there are usually versions associated with symbols in some shared libraries (and you can query that programmatically thru dlvsym if youdlopen
-ed a library). There is some way to generate the versions.If the library is pure C++, then symbols are mangled so their encoding contain their signature.
The best practice is to have some functions inside your library which return the version of the library. Look at glib version information functions for a good example.