Signal handlers and _Unwind_IsSignalFrame

Ian Lance Taylor iant@google.com
Wed Sep 10 05:19:00 GMT 2008


Martin Bouzek <martin.bouzek@radas-atc.cz> writes:

> I have a problem. I want to handle signals like SIGSEGV in non-main
> threads of C++ program and terminate thread by pthread_exit call. Of
> course I need all destructors of objects on stack to be called (eg.
> mutex unlocking).
>
> When compiling with -fnon-call-exceptios everything almost works but:
>
> In context is saved address of failing instruction, not adress of
> instruction after the failing one. Thus decrementing of this address in
> __gxx_personality_v0 sometimes leads to calling of terminate(), because
> no suitable entry in call-site table (?is it the right name?) is found
> in .gcc_except_table. 
>
> It is clearly supposed to be handled by SIGNAL_FRAME_BIT in flagss in
> struct _Unwind_Context. But this bit is not set in my context. That is
> why __gxx_personality misses proper handler by one byte, and calls
> terminate instead. If I put one simple pointer dereference before my
> failing instruction, decremented address is now inside the range
> described in call-site table and everything works fine.
>
> I am not sure I understand well how the SIGNAL_FRAME_BIT flag is
> supposed to be set. Shall there be a CIE with "S" augmentation
> in .eh_frame for signal handler? Threre is not such one in my program.
> How can I make gcc to create one? Or am I completely wrong?

In ordinary use the signal_frame and SIGNAL_FRAME_BIT flags is set by
machine dependent code which recognizes a symbol frame.  In the gcc
source code for x86_64 GNU/Linux this is in the file
gcc/config/i386/linux-unwind.h.  Perhaps that code is not working for
you, but I have no idea why not.

Note that you can have this sort of problem when using some versions
of libunwind instead of the unwind code which comes with gcc.  You
would know if you are doing that, though; you need to configure gcc
with --with-system-libunwind.

Ian



More information about the Gcc-help mailing list