[cfe-dev] LLVM/Clang and setjmp/longjmp exception handling on MinGW

David Chisnall theraven at sucs.org
Tue Nov 1 06:41:15 PDT 2011


On 1 Nov 2011, at 13:06, Ruben Van Boxem wrote:

> What about associated stack unwinding?

The generic stack unwinding part is provided by standard Windows libraries.  They walk the stack and invoke the personality function for each frame.  On other platforms this is done by libunwind or libgcc_s.

> I'm not quite familiar with all this, and am kind of going half-blind on anything Google pops up. I did take a look at the Win64 EH specification, but couldn't find the link to what's happening in libcxxrt.

An exception implementation is typically split into two parts.  One part is generic, one is language-specific.  Most platforms use the CodeSourcery Itanium exception ABI (except ARM, which is just different to be difficult).  This defines a set of DWARF tables for generic frame unwinding.  Each table contains a pointer to a personality function and a pointer to a language-specific data area (LSDA).  The contents of the LSDA are not specified in detail and can be anything that the compiler and personality function agree on.  

The generic code walks the language-agnostic tables, unwinds the stack (on ARM, the personality function does this, because someone at ARM thought it was really clever to make every language reinvent the wheel), and invokes any personality function.  This typically runs as a two-stage process, first just scanning the stack to find if the exception can be caught, and then doing the unwinding.  The personality function is responsible for parsing the LSDA, working out whether there are any cleanups or catches that match this exception, and telling the generic part of the code how to install the stack frame to handle them.

> And libcxxrt depends on libunwind or similar, so that needs to be handled appropriately as well.

libcxxrt provides the C++ language-specific part of the implementation.   It requires a generic unwind library.  It has been tested with libgcc_s and libunwind for this on platforms that use DWARF unwind tables.  On Windows, it would need a new personality function, but (if the LSDA layout is the same) it would be able to reuse all of the helper functions, so the personality function itself would only be a few dozen lines of new code.

> I would very much appreciate if you could make those changes to libcxxrt, although I'm unsure if I'm able to do anything sensible here...

There's no point making those changes without compiler support, because I can't test them, but ping me when there is compiler support (either in LLVM or Path64) and I'll see what I can do...

David

-- Sent from my Difference Engine




More information about the cfe-dev mailing list