Detecting ABI compatibility issues with GCC

Recently, I spent quite a considerable amount of time fixing a problem that turned out to be caused by compiling the library with -D_GLIBCXX_DEBUG (which tells libstdC ++ to use the debug version of the standard library with additional checks), but compiling the client program without. This caused an ABI compatibility issue.

Is there any way to automatically detect such problems with GCC? Visual Studio provides a detect_mismatch pragma that I think would serve this purpose, but I don't know about any GCC equivalent. GCC does something with GLIBCXX_3.4.9 symbol name (e.g. GLIBCXX_3.4.9 ), and I can imagine schemes that will result in a binding error due to an undefined symbol if the corresponding symbol (e.g. mylib_debug_stl ) was not present, but the only ways that I can think of to use this symbol, really hacked.

Alternatively, how do other people avoid this problem? Build a verified version of the library with a different name or something like that?

+8
gcc debugging abi glibc g ++
source share
2 answers

Is there a way to automatically detect such problems using GCC?

Only the linker can detect if you are linking incompatible code, not the compiler.

An alternative gold linker may detect some problems with the --detect-odr-violations option.

Alternatively, how do other people avoid this problem? Build a verified version of the library with a different name or something like that?

I just guarantee that I will rebuild everything when I want to use debug mode, I do not think that I ever wanted to save a library around it that was built in debug mode. This is for debugging, not for normal use.

In any case, I rarely use -D_GLIBCXX_DEBUG , I often do something like:

 #if 0 # include <debug/vector> namespace my_class_stl = __gnu_debug; #else #include <vector> namespace my_class_stl = std; #endif struct my_class { typedef my_class_stl::vector<int> container; typedef container::iterator iterator; // ... }; 

Then I change the preprocessor condition when I want to use the debug mode vector for this particular class without affecting each container in the program. Since the change includes writing to the file (and therefore updating its timestamp), everything that depends on this header will be restored using make , and there are two different types: std::vector<int> and __gnu_debug::vector<int> , which have different characters and may not be confused with a linker.

A simple definition of _GLIBCXX_DEBUG does not rebuild all the dependencies and silently changes the definition of std::vector globally, instead of changing specific containers to another type with a different name __gnu_debug::vector

+4
source share

it turned out to be caused by compiling the library with -D_GLIBCXX_DEBUG (which tells libstdC ++ to use the debug version of the standard library with additional checks), but compiling the client program without.

This is a clear design idea for the libsdc++ debugging libsdc++ to support such a configuration, and I have little doubt that this was the actual cause of your problem.

The problem may disappear after you restored the library without -D_GLIBCXX_DEBUG , but this does not prove that ABI incompatibility was the main reason.

0
source share

All Articles