Re: Catching C++ exceptions thrown from a framework
Re: Catching C++ exceptions thrown from a framework
- Subject: Re: Catching C++ exceptions thrown from a framework
- From: "Chris Espinosa" <email@hidden>
- Date: Tue, 18 Jul 2006 09:16:35 PDT
It first compares by address then falls back to a string comparison. The gcc folk can tell you more.
Chris
--- Original Message ---
From: Steve Baxter <email@hidden>
Sent: Tue 7/18/06 7:23 am
To: Chris Espinosa <email@hidden>
Cc: Eric Slosser <email@hidden>, email@hidden
Subject: Re: Catching C++ exceptions thrown from a framework
Hi Chris,
Hmm, odd that DTS didn't mention this when I asked them specifically
about this problem!
Does -fvisibility-ms-compat force RTTI comparison to happen by type
name rather than type ID address (i.e. the same class implemented in
two different plugins will be considered to be the same for RTTI
even though the typeid for the types will have different addresses)?
How does it do this without changing the C++ runtime (I believe the
problem here is in the runtime as installed by the OS rather than in
Xcode)?
Cheers,
Steve.
On 18 Jul 2006, at 14:22, Chris Espinosa wrote:
> On Jul 18, 2006, at 2:03 AM, Steve Baxter wrote:
>
>> This has bitten a few people.
>>
>> The actual problem is that GCC 4 uses the *address* of typeids
>> when comparing for RTTI rather than the class name that is in the
>> typeid. This is arguably more efficient, but doesn't work
>> properly if your code doesn't obey the one definition rule:
>>
>> http://en.wikipedia.org/wiki/One_Definition_Rule
>>
>> Unfortunately it is very easy to accidentally not obey the ODR.
>> Inline code used in plugins will cause RTTI information to be
>> linked multiple times (once in each plugin). The compiler and
>> linker will not catch problems here - you have to deal with this
>> yourself.
>>
>> To fix the problem:
>>
>> - Your plugins need to export all their symbols
>>
>> - If you use CFBundle to load your plugins, it will not do the
>> right thing. You need to load your plugin with dlopen
>> ( RTLD_GLOBAL ) (you can then load it with CFBundle as well)
>>
>> - If you are supporting 10.3.9 you have an extra problem - there
>> is a bug in the C++ runtime which will still prevent RTTI from
>> working between modules. I hope Apple is going to release a fix
>> for this at some point (the fix is actually in the 10.3.9 and
>> 10.4u SDKs)
>>
>> Doing this allows the dynamic linker to merge symbols as each
>> plugin loads. Each symbol will then be loaded only once and ODR
>> will be obeyed.
>>
>> Personally I think it is a complete pain for GCC to have different
>> behaviour to CodeWarrior and VC++ in this respect. They have
>> extracted a little bit of performance (comparing the address of
>> typeids rather than doing a text compare is more efficient) but
>> caused an awful lot of pain. Apple could fix this - there is a
>> #define in the C++ runtime to switch back to string comparisons.
>> Unfortunately with 10.3.9 and upwards, this is part of the system
>> and Apple are refusing to change it.
>>
>> Cheers,
>>
>> Steve.
>>
>> On 14 Jul 2006, at 22:14, Eric Slosser wrote:
>>
>>> Sam, this is a semi-well-known problem.
>>>
>>> GCC decides to give an exception to a handler when the typeinfo
>>> of the exception matches that of the handler (or is a sub-
>>> class). But the comparsion isn't based on the munged name of the
>>> symbol, it's based on the equality of a integer constant that's
>>> handled out by the linker.
>>
_______________________________________________
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