views:

259

answers:

5

It's not very hard to break binary backwards-compatibility of a DSO with a C++ interface. That said, is there a static analysis tool, which can help detecting such ABI breaks, if it's given two different sets of header files: those of an earlier state of the DSO and those of the current state (and maybe DSOs as well)? Both free and commercial product suggestions are welcome.

If it could also warn about bad practices, e.g. inline functions and defaulted function parameters in DSO interfaces, it would be great.

+1  A: 

ABI - Application Binary Interface comes down to the way the compiler translates the source code into the machine recognizable instructions. the same source line can be translated to different stream of bytes, in the final program.

a static analyzer running over the source code will not be able to predict how the compiler will translate it. that decision is made in the compiler coding or settings. so I don't believe a static analyzer will be of help to you in this case.

Alon
A static analysis tool can detect changing the return type of a function, adding virtual keyword to an existing member function, changing the types of function parameters, adding members to a class which is instantiable to the stack. All these break the binary backwards-compatibility. So, I disagree. A static analyzer can help to detect ABI breaks.
okun
I have to disagree: for example , a static analyzer will detect that a function return value is a structure say with integer elements a,b. while examining the source code the static analyzer cannot possible know if the compiler will set the structure in memory as {a , b} or {b, a} , its still the same structure but different ABI schemes
Alon
I *think* the OP refers to giving this theoretical tool an older and newer version of the same header file, and the tool would say whether or not changes in the newer version would mean that the library compiled with the older version is no longer good to use with the newer header.
Jim Buck
You are correct, a static analysis tool has not enough information to detect all breaks, but it can detect, if the return value has been changed e.g. from char to int. And I prefer finding out these obvious errors already during compile-time rather than later.
okun
@Jim Exactly, thank you. :)
okun
I don't know of such a tool, but it sounds like it would be immensely useful for library/dll writers. If the tool doesn't exist, perhaps there is a business opportunity for someone. :)
Jim Buck
If your ABI changes, you have to recompile the app. If the headers didn't change, the recompiled app would be identical. Hence, if your ABI breaks, your headers definitely changed.
Nicolás
A: 

The only safe way to do this is to export your library using a C interface. A C++ library is only compatible with the one compiler you use to compile it.

jmucchiello
The clients are well aware of the compiler requirements. The DSO is an indoor project and has a wide range of clients throughout the company, but obtaining the very same compiler version is no problem.
okun
+1  A: 

I remember at work they used GCC XML for testing binary compatibility. Basically what it does is generate an xml representation of the compiler object tree. The theory goes that if the xml is equivalent, they binary compatibility has been maintained.

doron
+2  A: 

I assume that you are familiar with this tutorial: http://techbase.kde.org/Policies/Binary_Compatibility_Issues_With_C%2B%2B, if not read it!

I've heard about this tool: http://ispras.linuxfoundation.org/index.php/ABI_compliance_checker, however never tested or used one, so have no opinion.

Also this may interest you: http://stackoverflow.com/questions/836875/creating-library-with-backward-compatible-abi-that-uses-boost

Artyom
Yes, I'm aware of the dos and don'ts, which was also my motivation to ask if there was any tool to automate the obvious checks. ABI compliance checker does look helpful. I will give it a try. Cheers!
okun
+1  A: 

CppDepend provides a useful feature to comapre 2 versions , and detect breaking changes, and added classes , methods, namespaces,..;

Issam
Thanks. I'll check out its trial.
okun