• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: frameworks, dynamic_cast and gcc 4.0
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: frameworks, dynamic_cast and gcc 4.0


  • Subject: Re: frameworks, dynamic_cast and gcc 4.0
  • From: Steve Baxter <email@hidden>
  • Date: Tue, 23 Aug 2005 12:39:02 +0100

Actually I think I have the answer to this. We need a copy of libstdc ++ compiled with __GXX_MERGED_TYPEINFO_NAMES defined to 0.

The GCC runtime appears to assume that if weak symbols are supported then it is safe to compare type_info by address, as the linker will always merge symbols. This may not be true in all cases however - if the object is defined in more than one DSO (e.g. because it is a template class) then each DSO will have its own type_info structure and dynamic_cast will break.

A simple fix for this would be to compile a static version of libstdc+ + with this switch set. The problem however is that currently Apple force use of the dynamic (system) version of libstdc++ - is there any way to switch back to a static version?

Cheers,

Steve.

On 22 Aug 2005, at 16:56, Steve Baxter wrote:

Hi Stephan,

I ran into a problem like this as well. The problem seems to be a difference in implementation between dynamic_cast in GCC 4.0 and in most other compilers (or at least CodeWarrior and VC++).

It seems that GCC 4.0 treats classes linked in different shared units as different, even if they have the same name. There is some good information here:

http://gcc.gnu.org/faq.html#dso

You will see this problem if the same source file is linked or included in more than one DSO (dynamic shared object). More irritatingly, you can run into this problem with fully-inline classes - if the class header is included in more than one DSO, it will end up with two type_info copies, one in each DSO (this can happen very commonly with template code).

These constructs are said to have "vague linkage":

http://developer.apple.com/documentation/DeveloperTools/gcc-4.0.0/ gcc/Vague-Linkage.html

The reason for the problem seems to be that the GCC writers changed GCC so that type_info was checked for equality by comparing addresses rather than really comparing for equality. Two type_infos with different addresses are always considered to be different even if they are in fact identical. This was done for performance reasons - a pointer comparison is (obviously) faster than a string compare.

I suspect this works OK within a single DSO - the linker discards duplicate copies of the type_info constructs so you end up with only one. I am not sure what you are supposed to do in multi-DSO applications where the same template or inline class might be used in several DSOs - I would want then to be treated as identical, but the GCC runtime would not do this. This is probably going to be a show-stopper for us - this works fine in VC++ and CodeWarrior though.

Does anyone know if there is a compiler switch or something to turn type_info comparisons by equality rather than by address back on?

Cheers,

Steve.

On 22 Aug 2005, at 13:42, Stephan Huber wrote:


Hi all,

I switched with my code to XCode 2.1 and gcc 4.0. Now most of my dynamic_casts are failing (they worked fine before XCode 2.1). And I don't know why, my knowledge of the inners of the compiler etc is limited.

To be precise: the dynamic_casts are working in the scope of the application, but If I call a method/function inside my custom framework which does a dynamic_cast, this dynamic_cast fails

To be more specific:

I declare a class inside my framework

class Foo : public osg::Object {...}

I create some objects inside the application and attach them to other objects (they have a property osg::Object (which is declared in another framework)) After a while I need to process the objects inside my custom framework and there the dynamic_cast to Foo fails.

I found the following message in the archives
<http://lists.apple.com/archives/Xcode-users/2005/May/ msg00315.html> which describes my problem in a more complicated way, doing some searches in the archives reveils some posts about similar problems, the solution was to *export* the class- definition, but I can't find any information how to do this, but maybe I'm dumb ;)


P.S. My code worked very well and reliable under gc 3.x and Panther...

Any help is greatly appreciated,

thanks in advance,
Stephan
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40improvision.com


This email sent to email@hidden


Stephen Baxter Software Development Manager Improvision email@hidden +44-2476-692229


_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40improvision.com


This email sent to email@hidden

Stephen Baxter Software Development Manager Improvision email@hidden +44-2476-692229


_______________________________________________ Do not post admin requests to the list. They will be ignored. Xcode-users mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
  • Follow-Ups:
    • Re: frameworks, dynamic_cast and gcc 4.0
      • From: Andreas Grosam <email@hidden>
References: 
 >frameworks, dynamic_cast and gcc 4.0 (From: Stephan Huber <email@hidden>)
 >Re: frameworks, dynamic_cast and gcc 4.0 (From: Steve Baxter <email@hidden>)

  • Prev by Date: Re: Static data member behaviour in release builds
  • Next by Date: Re: OT: I'm a Spammer!
  • Previous by thread: Re: frameworks, dynamic_cast and gcc 4.0
  • Next by thread: Re: frameworks, dynamic_cast and gcc 4.0
  • Index(es):
    • Date
    • Thread