Re: g++ and dynamic_cast

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Mihai Donțu,

> Assuming I have a program that loads two shared objects (liba.so and libb.so),
> is there any way that I can make dynamic_cast work in libb.so for an object
> obtained from liba.so, without loading liba.so and libb.so with dlopen(...|
> RTLD_GLOBAL)?

How do you obtain an object from liba.so without loading liba.so?

Isn't libb.so bound to liba.so as a DSO (so that liba.so is loaded
implicitly by ld when libb.so is dlopen()'d)?

> Currently, dynamic_cast returns NULL if the shared object (plugin) is loaded
> with dlopen("liba.so", RTLD_LAZY) (some rtti nastiness).

The dynamic_cast facility relies on the RTTI information.

One way that can be an issue is if the RTTI information is prebound, or if
it is hidden, or if "vague linkage" is in some other way confounding RTTI.

Because even though the RTTI structure may contain the same data in liba.so
and libb.so, it will be at different addresses.

The "are these two objects the same" compares the pointer to the RTTI,
rather than a comparing the value of the RTTI structure.

You should be able to use 'nm' to view whether or not the RTTI structures
are external or local.  The RTTI structures are affected by the visibility
flags and the __attribute__((visibility("hidden"))) annotations.

Since I compile my code with -fvisibility=hidden which otherwise causes the
RTTI information to be local to the "package" (such as libfoo.so), in my
declaration of my classes, I make sure I do this to expose the RTTI
information when/where I need to:

class __attribute__((visibility("default"))) Foo
{
//...
};

HTH,
--Eljay



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux