multiple type_info objects for same class in dynamic library

toon.knapen@femtown.org toon.knapen@femtown.org
Sun Oct 17 08:38:00 GMT 2004


Inside a dynamic library (which is actually an extension module of 
python and thus loaded by means of the import command in python), I have 
a Base and Derived class. In following code inside this library

1) Derived* d = new Derived ;
2) std::cout << &typeid(*d) << ":" << typid(*d).name()<<'\n';
3) std::cout << &typeid(Derived) << ":" << typid(Derived).name()<<'\n';

line 2 and 3 shows that the type_info objects obtained are different 
although the 'name()' member function provide the exact same name.

I'm using gcc 3.2 and python 2.3.3, the executable is linked with the 
'-E' option (although I'm not sure if this is relevant since the Derived 
class is only known in dynamic libraries but not to the executable), the 
-Bsymbolic option is not used when linking.

My question now is: how can I analyse what happens with the different 
weak symbols corresponding to the type_info object of the Derived class? 
Since line 2 and 3 print different addresses, there must be multiple 
type_info objects in the loaded program for the Derived class. In 
multiple libraries, I can see a weak symbol _ZTSDerived (using nm it has 
the symbol type 'V'). But all libraries have this same weak symbol so 
why does the loaded program end up with multiple of these symbols (since 
I obtain multiple addresses)?

Any idea would be very much appreciated. Thanks in advance.

Toon Knapen



More information about the Binutils mailing list