[cxx-abi-dev] ABI modification for exception propagation

David Vandevoorde daveed at edg.com
Tue May 27 18:29:09 UTC 2008


On May 27, 2008, at 4:39 AM, Sebastian Redl wrote:
> David Vandevoorde wrote:
>>
>> Note that it doesn't have to copy the thrown object: It can  
>> essentially return a smartptr<__cxa_exception> (which is what  
>> std::exception_ptr would be) for the top exception.  The  
>> constructor for this smart pointer must behave a bit like  
>> __cxa_rethrow() in that it must avoid having __cxa_end_catch  
>> destroy the exception.  Instead, that destruction must now be  
>> handled by the destructor of smartptr<__cxa_exception> (when the  
>> reference count goes to zero).
> I have tried that. It doesn't work. Yes, I can make an exception_ptr  
> that refers to an existing __cxa_exception, but I can't rethrow it.  
> That would mean allowing a single __cxa_exception to be in multiple  
> throws at once, and _Unwind_Exception cannot handle that. Also,  
> __cxa_exception cannot handle having been caught by several threads  
> at once. It would mess up the nextException chain.
> I HAVE to duplicate the __cxa_exception, and as long as the  
> __cxa_exception and the exception object are in the same memory  
> block, that means copying the exception object too.
>
> You can read my rationale in the thread at the libstdc++ mailing list.
> http://gcc.gnu.org/ml/libstdc++/2008-05/msg00079.html


Thanks -- that's a nice write-up!


> Although, thinking about it some more, there might be a way. There  
> could be essentially two kinds of __cxa_exception. One looks like  
> the old one, with an added reference count. The other holds a  
> pointer to the first kind instead. All exception_ptrs refer to the  
> primary __cxa_exception, but on rethrow they allocate a secondary  
> that also refers to the first.


That's an interesting idea.


> This might work. But *only* if all modules link to the support  
> library dynamically, of course. If any of them links statically, it  
> would keep the old implementation, which would wreak havoc.


What sort of failure modes would we expect.  Could the  
"__cxa_exception by reference" be made to look like std::bad_exception  
to an old runtime support library?

> I'll look into implementing that.


FWIW, I've contacted Peter Dimov about this issue, and he seems  
agreeable to prohibit rethrowing an exception captured with  
current_exception() using "throw;" (until it has been rethrown with  
rethrow_exception, at which point it can be caught/rethrown the usual  
way).

Note that we're still dealing with a working paper, not a frozen draft  
or standard.  So if this kind of tricky issues arise, there may be  
wiggle room left to fix the spec.  (But not for long.)

	Daveed




More information about the cxx-abi-dev mailing list