Flaws in spec for __cxa_begin_catch
Cary Coutant
cary at cup.hp.com
Thu Nov 18 19:40:15 UTC 2004
The attached message from Richard H. in August '03 mentions a problem
in the ABI spec regarding __cxa_begin_catch. As Richard says, we also
implemented __cxa_begin_catch to return the adjusted pointer to the
exception object, as determined by the personality routine. I haven't
seen any further conversation on this topic since then.
There's one other problem with __cxa_begin_catch that we ought to
address at the same time. This one was raised by Martin Sebor just this
past August. When a thrown object has a copy constructor, the exception
isn't supposed to be considered caught until the copy constructor has
finished. The best we can do as we've implemented the ABI is to run the
copy constructor after calling __cxa_begin_catch. Since the exception
is marked as caught once __cxa_begin_catch is called,
uncaught_exception() will return false while the copy constructor is
running. There's a discussion on this topic in the Bugzilla database:
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=10606
It seems to me that the ABI spec for __cxa_begin_catch() may have been
OK after all, but we really needed another interface to get the
adjusted pointer prior to calling __cxa_begin_catch(). In the Bugzilla
discussion, Richard suggests "__cxa_begin_catch_part1" and
"__cxa_begin_catch_part2", but I'd suggest leaving __cxa_begin_catch()
as specified (with a void return), and adding a new interface
void *__cxa_get_exception_ptr(void *exceptionObject);
The generated code can call this interface, run the copy constructor,
and then call __cxa_begin_catch().
Perhaps an improvement on this would be to have __cxa_begin_catch()
also return the adjusted pointer, so that we can avoid the extra call
in cases where we don't have a copy constructor.
-cary
Begin forwarded message:
> From: Richard Henderson <rth at redhat.com>
> Date: August 25, 2003 3:41:31 PM PDT
> To: Chris Lattner <sabre at nondot.org>
> Cc: Nathan Sidwell <nathan at codesourcery.com>,
> cxx-abi-dev at codesourcery.com, gcc at gcc.gnu.org
> Subject: [cxx-abi-dev] Re: G++ ABI mismatches
>
> On Mon, Aug 25, 2003 at 05:37:42PM -0500, Chris Lattner wrote:
>> But how does cxa_begin catch know what the requested type is for
>> the object? I thought that was the job of the personality routine?
>
> It is. The personality routine computes the transformed pointer
> as part of the type matching phase. It stores this pointer in a
> c++ language private superclass of _Unwind_Exception. Which is
> then returned by __cxa_begin_catch.
>
>> Regardless, if G++ does not meet the ABI spec,
>> either G++ or the ABI should be fixed. Which one? :)
>
> The ABI. IIRC when I implemented this, I talked to one of the
> HP guys and they do the same thing.
>
>
> r~
>
More information about the cxx-abi-dev
mailing list