[LLVMdev] Books/docs on exception handling

Bill Wendling
Thu, 22 Apr 2010 10:30:11 -0000

Hi Trevor,

DWARF exception handling is an amalgam of several different documents and code
tables, which all conspire to give us exception handling. :-) The documents you
should read are:

* Exception Handling Tables
(http://www.codesourcery.com/public/cxx-abi/exceptions.pdf)
  This explains in detail what the table in the
"__TEXT,__gcc_except_tab" section is all about.

* DWARF Debugging Information Format: Version 3 (or 4)
  This explains the "CIE" and "FDE" tables and what their
encodings means.

* http://www.codesourcery.com/public/cxx-abi/abi-eh.html
  As Eugene pointed out, this explains what the personality function and unwind
libraries do.

Well, "read" might be a bad way of putting it. You should definitely
familiarize yourself with each document. But I would look to understand why the
FDE looks like it does or what the format of the exception handling table means
(-fverbose-asm gives extra information to help with this).

For specifics on how LLVM generates this information, look at these files:

* lib/CodeGen/AsmPrinter/DwarfException.cpp
  This outputs the CIE, FDE, and exception handling tables.

* lib/Target/X86/X86RegisterInfo.cpp
  The "X86RegisterInfo::emitPrologue" method shows how it constructs
the "machine move" information that's used to create the FDE.

The front-end parses and generates the exception handlers and landing pads. The
implementation of the stack unwinder is normally in a separate library
(libunwind on Darwin). But the "abi-eh.html" document should give you
a good idea of how a typical unwinder and personality function should act.

Lastly, GCC has a different approach (in their IR) to generating the EH data.
They have many good people working on it. I tried to find a link to a document
that someone on the GCC mailing list wrote up describing the exception handling
table in detail, but couldn't find it. You may want to search that posting
out. :-)

-bw

On Apr 21, 2010, at 2:07 PM, Trevor Harmon wrote:

> Hi,
>
> I'm trying to learn all that I can about exception handling from the
> compiler's point of view. Although much has been written about
> compiler theory in general -- parsing, code generation, you name it --
> I can find almost nothing on the specific problem of exception
> handling support. In fact, the most informative document I've been
> able to find so far is "Bill's EH Proposal":
>
> http://markmail.org/message/5ezbpz75yxjje3or?q=thread:ghrak3dzcadxyf4x
>
> Are there any other books or articles that I should know about? I'm
> looking for almost anything that talks about how compilers (LLVM or
> otherwise) parse exception handlers, generate landing pads, implement
> stack unwinding, and so on.
>
> Thanks,
>
> Trevor
>
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev