ABI compatibility header/library cross check

馋奶兔 提交于 2019-12-21 06:22:04

问题


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?

回答1:


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 a malloc 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 you dlopen-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.




回答2:


It seems that the ABI compliance checker also supports checking an application for its exposure to any changes between two libraries.



来源:https://stackoverflow.com/questions/8794964/abi-compatibility-header-library-cross-check

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!