egcs-1.1: exceptions don't work with C libraries

Andrew Macleod amacleod@cygnus.com
Wed Nov 25 07:38:00 GMT 1998


>> Just as a bit of a follow-up...
>> 
>> It appears that the exceptions problem isn't limited to the Tcl library
>> but rather any C library.  Instead of using a Tcl function, I did the
>> same test using the qsort callback function with the same results.
>> 
>> -------------------------------------------------------------------------------
>> dragon:~/tmp> g++ except-bug.cc && ./a.out
>> throwing 'sortcondition' exception
>> caught test-sortcondition exception
>> throwing 'sortcondition' exception
>> Abort
>> dragon:~/tmp> 
>> ===============================================================================
>> 
>> My guess is that the regular C compiler doesn't include some information on
>> the stack that the exception handling needs in order to work.  To counter
>> this, the regular C compiler would need to be modified or G++ needs to
>> recognize that information is missing and continue up the stack frame.  Of
>> course, it can't call destructors on the C stack frame, but then there are
>> no destructors to call.  Since this could lead to memory leaks and the like,
>> I'm not sure if it's a good fix or not.
>> 
>>                                           Brian
>>                                   ( bcwhite@pobox.com )
>> 
>>  */

When compiled with the table driven exception handling, exception can only
be thrown through functions which have been compiled with the table driven EH.
If a function isn't compiled that way, then we do not have the frame
unwinding information required to restore the registers when unwinding.

I beleive the setjmp/longjmp mechanism will throw through things like this, 
but its produces much messier code.  (-fsjlj-exceptions)

The C compiler does support exceptions, you just have to turn them on
with -fexceptions.

Your main options are to:
  a) Don't use callbacks, or at least don't throw through them.
  b) Get the source and compile the library with -fexceptions (You have to
     explicitly turn on exceptions in the C compiler)
  c) always use -fsjlj-exceptions (boo, bad choice :-)

Andrew




More information about the Gcc-bugs mailing list