terminate called after throwing an exception from a shared library

John (Eljay) Love-Jensen eljay@adobe.com
Tue May 18 12:21:00 GMT 2010


Hi Dallas,

> In other words how does "typeinfo for" differ from "typeinfo name for"?

The class type_info object has a char const* member called name.

Type "typeinfo name for" is the nul-terminated C string referenced by that
typeinfo.

You can access that name by:

#include <typeinfo>
char const* name = typeid<Foo_t>.name();

The name generated varies from C++ compiler by vendor, and sometimes even by
version.  If anonymous namespaces are involved, may vary by compile too.

> I'm assuming this because the type is only defined in DSO A and should
> be undefined in DSO B as well as the executable.  Is this
> understanding correct?

That is a C++ compiler/linker implementation detail.

For GCC, the RTTI uses vague linkage:

http://gcc.gnu.org/onlinedocs/gcc/Vague-Linkage.html

It is possible to get ODR violations under certain circumstances.  :-(

Visibility may bollix up the RTTI mechanism.  In particular, if the typeinfo
data is hidden, then the vague linkage mechanism may not work as desired.
Resulting in typeid's not matching, and exceptions not being caught across
packages (.so) and/or with the main executable.

Also with a shared library, you may need to pay attention to exception
handling through a C barrier.  If C routines or OS calls (with callbacks)
are sandwiched on the stack, stack unwinding during exception handling may
fail, resulting in a terminate call.

HTH,
--Eljay



More information about the Gcc-help mailing list