Question about Darwin GCC and weak symbol tagging policy

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

 



Hello,

I am trying to use dynamic_cast to upcast object pointers generated by
object factories. Each factory belong to a separate dynamic shared object
(OSX bundles in this case), and GCC fails the cast in few cases (and
succeeds in the others). 

In order to understand the problem, I've created a factory that creates an
empty object (only a CTOR and a  virtual DTOR). When the destructor is
inline, everything works fine (the CTOR's definition is in a .cpp). However,
as soon as I move the destructor's definition to the .cpp, the dynamic_cast
fails.

I looked at the symbols in each case (nm -m <bundle-file>) and found that
the only differences were that the symbols associated with the empty class
are declared weak extern in the binary where the destructor is inline and
extern in the other binary.

Here is my understanding of the problem: dynamic_cast can only succeeds in
GCC if both object's typeinfo have the same address. If there are several
definitions of the same class in different DSOs, then some of the duplicated
symbols associated to those definitions have to be marked as weak in order
to be coalesced to enforce the one definition rule (ODR).

This is exactly what doesn't happen when my empty class has its constructor
defined in the .cpp. I've stumbled on a 
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15428#c0 bug report  relating to
GCC on Darwin which adjusted GCC's behavior regarding vtables to compensate
a restriction from the linker on Darwin.

Because of this change, each duplicated symbol related to an empty object is
marked as non-weak and will have its own typeinfo object (and its own
typeinfo pointer), which will cause dynamic_cast to fail on GCC.

In order to revert this behavior, I need to have a 'key function' in my
class.

So here are my two questions:

What qualifies as a key function (I've tried several dummy function
prototypes, but none solved my problem)?

Where can I find some guidelines about the way I should code my classes so
that gcc marks symbols as weak on Darwin?


I've looked for answers for both questions for several days with no success.
Your help will be greatly appreciated.
Thank you very much in advance,

Nicolas
-- 
View this message in context: http://old.nabble.com/Question-about-Darwin-GCC-and-weak-symbol-tagging-policy-tp30654362p30654362.html
Sent from the gcc - Help mailing list archive at Nabble.com.



[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