| Jim Laskey | 6956773 | 2007-03-14 19:29:42 +0000 | [diff] [blame] | 1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" | 
|  | 2 | "http://www.w3.org/TR/html4/strict.dtd"> | 
|  | 3 | <html> | 
|  | 4 | <head> | 
|  | 5 | <title>Exception Handling in LLVM</title> | 
| Bill Wendling | 365ab60 | 2009-08-15 08:56:09 +0000 | [diff] [blame] | 6 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> | 
| Eric Christopher | 98e0a59 | 2009-09-09 01:44:53 +0000 | [diff] [blame] | 7 | <meta name="description" | 
| Bill Wendling | 365ab60 | 2009-08-15 08:56:09 +0000 | [diff] [blame] | 8 | content="Exception Handling in LLVM."> | 
| Jim Laskey | 6956773 | 2007-03-14 19:29:42 +0000 | [diff] [blame] | 9 | <link rel="stylesheet" href="llvm.css" type="text/css"> | 
|  | 10 | </head> | 
| Bill Wendling | 365ab60 | 2009-08-15 08:56:09 +0000 | [diff] [blame] | 11 |  | 
| Jim Laskey | 6956773 | 2007-03-14 19:29:42 +0000 | [diff] [blame] | 12 | <body> | 
|  | 13 |  | 
| NAKAMURA Takumi | fc8d930 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 14 | <h1>Exception Handling in LLVM</h1> | 
| Jim Laskey | 6956773 | 2007-03-14 19:29:42 +0000 | [diff] [blame] | 15 |  | 
|  | 16 | <table class="layout" style="width:100%"> | 
|  | 17 | <tr class="layout"> | 
|  | 18 | <td class="left"> | 
|  | 19 | <ul> | 
|  | 20 | <li><a href="#introduction">Introduction</a> | 
|  | 21 | <ol> | 
|  | 22 | <li><a href="#itanium">Itanium ABI Zero-cost Exception Handling</a></li> | 
| Jim Grosbach | 8a2cfcb | 2009-08-22 01:42:39 +0000 | [diff] [blame] | 23 | <li><a href="#sjlj">Setjmp/Longjmp Exception Handling</a></li> | 
| Jim Laskey | 6956773 | 2007-03-14 19:29:42 +0000 | [diff] [blame] | 24 | <li><a href="#overview">Overview</a></li> | 
|  | 25 | </ol></li> | 
|  | 26 | <li><a href="#codegen">LLVM Code Generation</a> | 
|  | 27 | <ol> | 
|  | 28 | <li><a href="#throw">Throw</a></li> | 
|  | 29 | <li><a href="#try_catch">Try/Catch</a></li> | 
| Duncan Sands | ef5a654 | 2007-08-27 15:47:50 +0000 | [diff] [blame] | 30 | <li><a href="#cleanups">Cleanups</a></li> | 
| Jim Laskey | 6956773 | 2007-03-14 19:29:42 +0000 | [diff] [blame] | 31 | <li><a href="#throw_filters">Throw Filters</a></li> | 
| Duncan Sands | ef5a654 | 2007-08-27 15:47:50 +0000 | [diff] [blame] | 32 | <li><a href="#restrictions">Restrictions</a></li> | 
| Jim Laskey | 6956773 | 2007-03-14 19:29:42 +0000 | [diff] [blame] | 33 | </ol></li> | 
| Duncan Sands | 16f122e | 2007-03-30 12:22:09 +0000 | [diff] [blame] | 34 | <li><a href="#format_common_intrinsics">Exception Handling Intrinsics</a> | 
| Jim Laskey | 6956773 | 2007-03-14 19:29:42 +0000 | [diff] [blame] | 35 | <ol> | 
| Jim Laskey | 6956773 | 2007-03-14 19:29:42 +0000 | [diff] [blame] | 36 | <li><a href="#llvm_eh_typeid_for"><tt>llvm.eh.typeid.for</tt></a></li> | 
| Jim Grosbach | 0692819 | 2009-05-14 00:46:35 +0000 | [diff] [blame] | 37 | <li><a href="#llvm_eh_sjlj_setjmp"><tt>llvm.eh.sjlj.setjmp</tt></a></li> | 
|  | 38 | <li><a href="#llvm_eh_sjlj_longjmp"><tt>llvm.eh.sjlj.longjmp</tt></a></li> | 
| Jim Grosbach | 693e36a | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 39 | <li><a href="#llvm_eh_sjlj_lsda"><tt>llvm.eh.sjlj.lsda</tt></a></li> | 
| Jim Grosbach | 54c0530 | 2010-01-28 01:45:32 +0000 | [diff] [blame] | 40 | <li><a href="#llvm_eh_sjlj_callsite"><tt>llvm.eh.sjlj.callsite</tt></a></li> | 
| Jim Grosbach | bbdc5d2 | 2010-10-19 23:27:08 +0000 | [diff] [blame] | 41 | <li><a href="#llvm_eh_sjlj_dispatchsetup"><tt>llvm.eh.sjlj.dispatchsetup</tt></a></li> | 
| Jim Laskey | 6956773 | 2007-03-14 19:29:42 +0000 | [diff] [blame] | 42 | </ol></li> | 
|  | 43 | <li><a href="#asm">Asm Table Formats</a> | 
|  | 44 | <ol> | 
|  | 45 | <li><a href="#unwind_tables">Exception Handling Frame</a></li> | 
|  | 46 | <li><a href="#exception_tables">Exception Tables</a></li> | 
|  | 47 | </ol></li> | 
| Jim Laskey | 6956773 | 2007-03-14 19:29:42 +0000 | [diff] [blame] | 48 | </ul> | 
|  | 49 | </td> | 
|  | 50 | </tr></table> | 
|  | 51 |  | 
|  | 52 | <div class="doc_author"> | 
|  | 53 | <p>Written by <a href="mailto:jlaskey@mac.com">Jim Laskey</a></p> | 
|  | 54 | </div> | 
|  | 55 |  | 
|  | 56 |  | 
|  | 57 | <!-- *********************************************************************** --> | 
| NAKAMURA Takumi | fc8d930 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 58 | <h2><a name="introduction">Introduction</a></h2> | 
| Jim Laskey | 6956773 | 2007-03-14 19:29:42 +0000 | [diff] [blame] | 59 | <!-- *********************************************************************** --> | 
|  | 60 |  | 
| NAKAMURA Takumi | aa3d624 | 2011-04-23 00:30:22 +0000 | [diff] [blame] | 61 | <div> | 
| Jim Laskey | 6956773 | 2007-03-14 19:29:42 +0000 | [diff] [blame] | 62 |  | 
|  | 63 | <p>This document is the central repository for all information pertaining to | 
| Bill Wendling | 365ab60 | 2009-08-15 08:56:09 +0000 | [diff] [blame] | 64 | exception handling in LLVM.  It describes the format that LLVM exception | 
|  | 65 | handling information takes, which is useful for those interested in creating | 
|  | 66 | front-ends or dealing directly with the information.  Further, this document | 
|  | 67 | provides specific examples of what exception handling information is used for | 
| Bill Wendling | 58c80f8 | 2011-09-26 21:06:33 +0000 | [diff] [blame] | 68 | in C and C++.</p> | 
| Jim Laskey | 6956773 | 2007-03-14 19:29:42 +0000 | [diff] [blame] | 69 |  | 
| Jim Laskey | 6956773 | 2007-03-14 19:29:42 +0000 | [diff] [blame] | 70 | <!-- ======================================================================= --> | 
| NAKAMURA Takumi | fc8d930 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 71 | <h3> | 
| Jim Laskey | 6956773 | 2007-03-14 19:29:42 +0000 | [diff] [blame] | 72 | <a name="itanium">Itanium ABI Zero-cost Exception Handling</a> | 
| NAKAMURA Takumi | fc8d930 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 73 | </h3> | 
| Jim Laskey | 6956773 | 2007-03-14 19:29:42 +0000 | [diff] [blame] | 74 |  | 
| NAKAMURA Takumi | aa3d624 | 2011-04-23 00:30:22 +0000 | [diff] [blame] | 75 | <div> | 
| Jim Laskey | 6956773 | 2007-03-14 19:29:42 +0000 | [diff] [blame] | 76 |  | 
|  | 77 | <p>Exception handling for most programming languages is designed to recover from | 
| Bill Wendling | 365ab60 | 2009-08-15 08:56:09 +0000 | [diff] [blame] | 78 | conditions that rarely occur during general use of an application.  To that | 
|  | 79 | end, exception handling should not interfere with the main flow of an | 
|  | 80 | application's algorithm by performing checkpointing tasks, such as saving the | 
|  | 81 | current pc or register state.</p> | 
| Jim Laskey | 6956773 | 2007-03-14 19:29:42 +0000 | [diff] [blame] | 82 |  | 
|  | 83 | <p>The Itanium ABI Exception Handling Specification defines a methodology for | 
| Bill Wendling | 365ab60 | 2009-08-15 08:56:09 +0000 | [diff] [blame] | 84 | providing outlying data in the form of exception tables without inlining | 
|  | 85 | speculative exception handling code in the flow of an application's main | 
|  | 86 | algorithm.  Thus, the specification is said to add "zero-cost" to the normal | 
|  | 87 | execution of an application.</p> | 
| Jim Laskey | 6956773 | 2007-03-14 19:29:42 +0000 | [diff] [blame] | 88 |  | 
|  | 89 | <p>A more complete description of the Itanium ABI exception handling runtime | 
| Bill Wendling | 365ab60 | 2009-08-15 08:56:09 +0000 | [diff] [blame] | 90 | support of can be found at | 
|  | 91 | <a href="http://www.codesourcery.com/cxx-abi/abi-eh.html">Itanium C++ ABI: | 
|  | 92 | Exception Handling</a>. A description of the exception frame format can be | 
|  | 93 | found at | 
|  | 94 | <a href="http://refspecs.freestandards.org/LSB_3.0.0/LSB-Core-generic/LSB-Core-generic/ehframechpt.html">Exception | 
| Bill Wendling | 0116184 | 2011-09-20 01:08:53 +0000 | [diff] [blame] | 95 | Frames</a>, with details of the DWARF 4 specification at | 
|  | 96 | <a href="http://dwarfstd.org/Dwarf4Std.php">DWARF 4 Standard</a>. | 
| Bill Wendling | 365ab60 | 2009-08-15 08:56:09 +0000 | [diff] [blame] | 97 | A description for the C++ exception table formats can be found at | 
|  | 98 | <a href="http://www.codesourcery.com/cxx-abi/exceptions.pdf">Exception Handling | 
|  | 99 | Tables</a>.</p> | 
| Jim Laskey | 6956773 | 2007-03-14 19:29:42 +0000 | [diff] [blame] | 100 |  | 
|  | 101 | </div> | 
|  | 102 |  | 
|  | 103 | <!-- ======================================================================= --> | 
| NAKAMURA Takumi | fc8d930 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 104 | <h3> | 
| Jim Grosbach | 8a2cfcb | 2009-08-22 01:42:39 +0000 | [diff] [blame] | 105 | <a name="sjlj">Setjmp/Longjmp Exception Handling</a> | 
| NAKAMURA Takumi | fc8d930 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 106 | </h3> | 
| Jim Grosbach | 8a2cfcb | 2009-08-22 01:42:39 +0000 | [diff] [blame] | 107 |  | 
| NAKAMURA Takumi | aa3d624 | 2011-04-23 00:30:22 +0000 | [diff] [blame] | 108 | <div> | 
| Jim Grosbach | 8a2cfcb | 2009-08-22 01:42:39 +0000 | [diff] [blame] | 109 |  | 
|  | 110 | <p>Setjmp/Longjmp (SJLJ) based exception handling uses LLVM intrinsics | 
|  | 111 | <a href="#llvm_eh_sjlj_setjmp"><tt>llvm.eh.sjlj.setjmp</tt></a> and | 
|  | 112 | <a href="#llvm_eh_sjlj_longjmp"><tt>llvm.eh.sjlj.longjmp</tt></a> to | 
|  | 113 | handle control flow for exception handling.</p> | 
|  | 114 |  | 
| Bill Wendling | 0116184 | 2011-09-20 01:08:53 +0000 | [diff] [blame] | 115 | <p>For each function which does exception processing — be | 
|  | 116 | it <tt>try</tt>/<tt>catch</tt> blocks or cleanups — that function | 
|  | 117 | registers itself on a global frame list. When exceptions are unwinding, the | 
|  | 118 | runtime uses this list to identify which functions need processing.<p> | 
| Jim Grosbach | 8a2cfcb | 2009-08-22 01:42:39 +0000 | [diff] [blame] | 119 |  | 
|  | 120 | <p>Landing pad selection is encoded in the call site entry of the function | 
|  | 121 | context. The runtime returns to the function via | 
|  | 122 | <a href="#llvm_eh_sjlj_longjmp"><tt>llvm.eh.sjlj.longjmp</tt></a>, where | 
|  | 123 | a switch table transfers control to the appropriate landing pad based on | 
|  | 124 | the index stored in the function context.</p> | 
|  | 125 |  | 
|  | 126 | <p>In contrast to DWARF exception handling, which encodes exception regions | 
|  | 127 | and frame information in out-of-line tables, SJLJ exception handling | 
|  | 128 | builds and removes the unwind frame context at runtime. This results in | 
|  | 129 | faster exception handling at the expense of slower execution when no | 
|  | 130 | exceptions are thrown. As exceptions are, by their nature, intended for | 
|  | 131 | uncommon code paths, DWARF exception handling is generally preferred to | 
|  | 132 | SJLJ.</p> | 
| Bill Wendling | 0116184 | 2011-09-20 01:08:53 +0000 | [diff] [blame] | 133 |  | 
| Jim Grosbach | 8a2cfcb | 2009-08-22 01:42:39 +0000 | [diff] [blame] | 134 | </div> | 
|  | 135 |  | 
|  | 136 | <!-- ======================================================================= --> | 
| NAKAMURA Takumi | fc8d930 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 137 | <h3> | 
| Jim Laskey | 6956773 | 2007-03-14 19:29:42 +0000 | [diff] [blame] | 138 | <a name="overview">Overview</a> | 
| NAKAMURA Takumi | fc8d930 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 139 | </h3> | 
| Jim Laskey | 6956773 | 2007-03-14 19:29:42 +0000 | [diff] [blame] | 140 |  | 
| NAKAMURA Takumi | aa3d624 | 2011-04-23 00:30:22 +0000 | [diff] [blame] | 141 | <div> | 
| Jim Laskey | 6956773 | 2007-03-14 19:29:42 +0000 | [diff] [blame] | 142 |  | 
| Bill Wendling | 365ab60 | 2009-08-15 08:56:09 +0000 | [diff] [blame] | 143 | <p>When an exception is thrown in LLVM code, the runtime does its best to find a | 
|  | 144 | handler suited to processing the circumstance.</p> | 
| Jim Laskey | 6956773 | 2007-03-14 19:29:42 +0000 | [diff] [blame] | 145 |  | 
|  | 146 | <p>The runtime first attempts to find an <i>exception frame</i> corresponding to | 
| Bill Wendling | 365ab60 | 2009-08-15 08:56:09 +0000 | [diff] [blame] | 147 | the function where the exception was thrown.  If the programming language | 
| Bill Wendling | 58c80f8 | 2011-09-26 21:06:33 +0000 | [diff] [blame] | 148 | supports exception handling (e.g. C++), the exception frame contains a | 
| Bill Wendling | 365ab60 | 2009-08-15 08:56:09 +0000 | [diff] [blame] | 149 | reference to an exception table describing how to process the exception.  If | 
| Bill Wendling | 58c80f8 | 2011-09-26 21:06:33 +0000 | [diff] [blame] | 150 | the language does not support exception handling (e.g. C), or if the | 
| Bill Wendling | 365ab60 | 2009-08-15 08:56:09 +0000 | [diff] [blame] | 151 | exception needs to be forwarded to a prior activation, the exception frame | 
|  | 152 | contains information about how to unwind the current activation and restore | 
|  | 153 | the state of the prior activation.  This process is repeated until the | 
| Bill Wendling | 58c80f8 | 2011-09-26 21:06:33 +0000 | [diff] [blame] | 154 | exception is handled. If the exception is not handled and no activations | 
| Bill Wendling | 365ab60 | 2009-08-15 08:56:09 +0000 | [diff] [blame] | 155 | remain, then the application is terminated with an appropriate error | 
|  | 156 | message.</p> | 
| Jim Laskey | 6956773 | 2007-03-14 19:29:42 +0000 | [diff] [blame] | 157 |  | 
| Bill Wendling | 365ab60 | 2009-08-15 08:56:09 +0000 | [diff] [blame] | 158 | <p>Because different programming languages have different behaviors when | 
|  | 159 | handling exceptions, the exception handling ABI provides a mechanism for | 
| Bill Wendling | 58c80f8 | 2011-09-26 21:06:33 +0000 | [diff] [blame] | 160 | supplying <i>personalities</i>. An exception handling personality is defined | 
| Bill Wendling | 365ab60 | 2009-08-15 08:56:09 +0000 | [diff] [blame] | 161 | by way of a <i>personality function</i> (e.g. <tt>__gxx_personality_v0</tt> | 
|  | 162 | in C++), which receives the context of the exception, an <i>exception | 
|  | 163 | structure</i> containing the exception object type and value, and a reference | 
|  | 164 | to the exception table for the current function.  The personality function | 
|  | 165 | for the current compile unit is specified in a <i>common exception | 
|  | 166 | frame</i>.</p> | 
| Jim Laskey | 6956773 | 2007-03-14 19:29:42 +0000 | [diff] [blame] | 167 |  | 
| Bill Wendling | 58c80f8 | 2011-09-26 21:06:33 +0000 | [diff] [blame] | 168 | <p>The organization of an exception table is language dependent. For C++, an | 
| Bill Wendling | 365ab60 | 2009-08-15 08:56:09 +0000 | [diff] [blame] | 169 | exception table is organized as a series of code ranges defining what to do | 
| Bill Wendling | 58c80f8 | 2011-09-26 21:06:33 +0000 | [diff] [blame] | 170 | if an exception occurs in that range. Typically, the information associated | 
| Bill Wendling | 365ab60 | 2009-08-15 08:56:09 +0000 | [diff] [blame] | 171 | with a range defines which types of exception objects (using C++ <i>type | 
|  | 172 | info</i>) that are handled in that range, and an associated action that | 
| Bill Wendling | 58c80f8 | 2011-09-26 21:06:33 +0000 | [diff] [blame] | 173 | should take place. Actions typically pass control to a <i>landing | 
| Bill Wendling | 365ab60 | 2009-08-15 08:56:09 +0000 | [diff] [blame] | 174 | pad</i>.</p> | 
| Jim Laskey | 6956773 | 2007-03-14 19:29:42 +0000 | [diff] [blame] | 175 |  | 
| Bill Wendling | 58c80f8 | 2011-09-26 21:06:33 +0000 | [diff] [blame] | 176 | <p>A landing pad corresponds roughly to the code found in the <tt>catch</tt> | 
|  | 177 | portion of a <tt>try</tt>/<tt>catch</tt> sequence. When execution resumes at | 
|  | 178 | a landing pad, it receives an <i>exception structure</i> and a | 
|  | 179 | <i>selector value</i> corresponding to the <i>type</i> of exception | 
|  | 180 | thrown. The selector is then used to determine which <i>catch</i> should | 
|  | 181 | actually process the exception.</p> | 
| Jim Laskey | 6956773 | 2007-03-14 19:29:42 +0000 | [diff] [blame] | 182 |  | 
|  | 183 | </div> | 
|  | 184 |  | 
| NAKAMURA Takumi | aa3d624 | 2011-04-23 00:30:22 +0000 | [diff] [blame] | 185 | </div> | 
|  | 186 |  | 
| Jim Laskey | 6956773 | 2007-03-14 19:29:42 +0000 | [diff] [blame] | 187 | <!-- ======================================================================= --> | 
| NAKAMURA Takumi | fc8d930 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 188 | <h2> | 
| Jim Laskey | 6956773 | 2007-03-14 19:29:42 +0000 | [diff] [blame] | 189 | <a name="codegen">LLVM Code Generation</a> | 
| NAKAMURA Takumi | fc8d930 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 190 | </h2> | 
| Jim Laskey | 6956773 | 2007-03-14 19:29:42 +0000 | [diff] [blame] | 191 |  | 
| NAKAMURA Takumi | aa3d624 | 2011-04-23 00:30:22 +0000 | [diff] [blame] | 192 | <div> | 
| Jim Laskey | 6956773 | 2007-03-14 19:29:42 +0000 | [diff] [blame] | 193 |  | 
| Bill Wendling | 58c80f8 | 2011-09-26 21:06:33 +0000 | [diff] [blame] | 194 | <p>From a C++ developer's perspective, exceptions are defined in terms of the | 
| Bill Wendling | 0116184 | 2011-09-20 01:08:53 +0000 | [diff] [blame] | 195 | <tt>throw</tt> and <tt>try</tt>/<tt>catch</tt> statements. In this section | 
| Bill Wendling | 365ab60 | 2009-08-15 08:56:09 +0000 | [diff] [blame] | 196 | we will describe the implementation of LLVM exception handling in terms of | 
|  | 197 | C++ examples.</p> | 
| Jim Laskey | 6956773 | 2007-03-14 19:29:42 +0000 | [diff] [blame] | 198 |  | 
| Jim Laskey | 6956773 | 2007-03-14 19:29:42 +0000 | [diff] [blame] | 199 | <!-- ======================================================================= --> | 
| NAKAMURA Takumi | fc8d930 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 200 | <h3> | 
| Jim Laskey | 6956773 | 2007-03-14 19:29:42 +0000 | [diff] [blame] | 201 | <a name="throw">Throw</a> | 
| NAKAMURA Takumi | fc8d930 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 202 | </h3> | 
| Jim Laskey | 6956773 | 2007-03-14 19:29:42 +0000 | [diff] [blame] | 203 |  | 
| NAKAMURA Takumi | aa3d624 | 2011-04-23 00:30:22 +0000 | [diff] [blame] | 204 | <div> | 
| Jim Laskey | 6956773 | 2007-03-14 19:29:42 +0000 | [diff] [blame] | 205 |  | 
|  | 206 | <p>Languages that support exception handling typically provide a <tt>throw</tt> | 
| Bill Wendling | 58c80f8 | 2011-09-26 21:06:33 +0000 | [diff] [blame] | 207 | operation to initiate the exception process. Internally, a <tt>throw</tt> | 
|  | 208 | operation breaks down into two steps.</p> | 
|  | 209 |  | 
| Bill Wendling | 0116184 | 2011-09-20 01:08:53 +0000 | [diff] [blame] | 210 | <ol> | 
|  | 211 | <li>A request is made to allocate exception space for an exception structure. | 
|  | 212 | This structure needs to survive beyond the current activation. This | 
|  | 213 | structure will contain the type and value of the object being thrown.</li> | 
| Bill Wendling | 58c80f8 | 2011-09-26 21:06:33 +0000 | [diff] [blame] | 214 |  | 
| Bill Wendling | 0116184 | 2011-09-20 01:08:53 +0000 | [diff] [blame] | 215 | <li>A call is made to the runtime to raise the exception, passing the | 
|  | 216 | exception structure as an argument.</li> | 
|  | 217 | </ol> | 
| Jim Laskey | 6956773 | 2007-03-14 19:29:42 +0000 | [diff] [blame] | 218 |  | 
| Bill Wendling | 58c80f8 | 2011-09-26 21:06:33 +0000 | [diff] [blame] | 219 | <p>In C++, the allocation of the exception structure is done by the | 
| Bill Wendling | 0116184 | 2011-09-20 01:08:53 +0000 | [diff] [blame] | 220 | <tt>__cxa_allocate_exception</tt> runtime function. The exception raising is | 
|  | 221 | handled by <tt>__cxa_throw</tt>. The type of the exception is represented | 
|  | 222 | using a C++ RTTI structure.</p> | 
| Jim Laskey | 6956773 | 2007-03-14 19:29:42 +0000 | [diff] [blame] | 223 |  | 
|  | 224 | </div> | 
|  | 225 |  | 
|  | 226 | <!-- ======================================================================= --> | 
| NAKAMURA Takumi | fc8d930 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 227 | <h3> | 
| Jim Laskey | 6956773 | 2007-03-14 19:29:42 +0000 | [diff] [blame] | 228 | <a name="try_catch">Try/Catch</a> | 
| NAKAMURA Takumi | fc8d930 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 229 | </h3> | 
| Jim Laskey | 6956773 | 2007-03-14 19:29:42 +0000 | [diff] [blame] | 230 |  | 
| NAKAMURA Takumi | aa3d624 | 2011-04-23 00:30:22 +0000 | [diff] [blame] | 231 | <div> | 
| Jim Laskey | 6956773 | 2007-03-14 19:29:42 +0000 | [diff] [blame] | 232 |  | 
| Bill Wendling | 365ab60 | 2009-08-15 08:56:09 +0000 | [diff] [blame] | 233 | <p>A call within the scope of a <i>try</i> statement can potentially raise an | 
| Bill Wendling | 58c80f8 | 2011-09-26 21:06:33 +0000 | [diff] [blame] | 234 | exception. In those circumstances, the LLVM C++ front-end replaces the call | 
|  | 235 | with an <tt>invoke</tt> instruction. Unlike a call, the <tt>invoke</tt> has | 
|  | 236 | two potential continuation points:</p> | 
|  | 237 |  | 
|  | 238 | <ol> | 
|  | 239 | <li>where to continue when the call succeeds as per normal, and</li> | 
|  | 240 |  | 
|  | 241 | <li>where to continue if the call raises an exception, either by a throw or | 
|  | 242 | the unwinding of a throw</li> | 
|  | 243 | </ol> | 
| Jim Laskey | 6956773 | 2007-03-14 19:29:42 +0000 | [diff] [blame] | 244 |  | 
| Bill Wendling | 365ab60 | 2009-08-15 08:56:09 +0000 | [diff] [blame] | 245 | <p>The term used to define a the place where an <tt>invoke</tt> continues after | 
| Bill Wendling | 58c80f8 | 2011-09-26 21:06:33 +0000 | [diff] [blame] | 246 | an exception is called a <i>landing pad</i>. LLVM landing pads are | 
| Bill Wendling | 365ab60 | 2009-08-15 08:56:09 +0000 | [diff] [blame] | 247 | conceptually alternative function entry points where an exception structure | 
| Bill Wendling | 58c80f8 | 2011-09-26 21:06:33 +0000 | [diff] [blame] | 248 | reference and a type info index are passed in as arguments. The landing pad | 
| Bill Wendling | 365ab60 | 2009-08-15 08:56:09 +0000 | [diff] [blame] | 249 | saves the exception structure reference and then proceeds to select the catch | 
|  | 250 | block that corresponds to the type info of the exception object.</p> | 
| Jim Laskey | 6956773 | 2007-03-14 19:29:42 +0000 | [diff] [blame] | 251 |  | 
| Bill Wendling | 0116184 | 2011-09-20 01:08:53 +0000 | [diff] [blame] | 252 | <p>The LLVM <a href="LangRef.html#i_landingpad"><tt>landingpad</tt> | 
|  | 253 | instruction</a> is used to convey information about the landing pad to the | 
|  | 254 | back end. For C++, the <tt>landingpad</tt> instruction returns a pointer and | 
| Bill Wendling | 58c80f8 | 2011-09-26 21:06:33 +0000 | [diff] [blame] | 255 | integer pair corresponding to the pointer to the <i>exception structure</i> | 
|  | 256 | and the <i>selector value</i> respectively.</p> | 
| Jim Laskey | 6956773 | 2007-03-14 19:29:42 +0000 | [diff] [blame] | 257 |  | 
| Bill Wendling | 0116184 | 2011-09-20 01:08:53 +0000 | [diff] [blame] | 258 | <p>The <tt>landingpad</tt> instruction takes a reference to the personality | 
|  | 259 | function to be used for this <tt>try</tt>/<tt>catch</tt> sequence. The | 
| Bill Wendling | 58c80f8 | 2011-09-26 21:06:33 +0000 | [diff] [blame] | 260 | remainder of the instruction is a list of <i>cleanup</i>, <i>catch</i>, | 
|  | 261 | and <i>filter</i> clauses. The exception is tested against the clauses | 
|  | 262 | sequentially from first to last. The selector value is a positive number if | 
|  | 263 | the exception matched a type info, a negative number if it matched a filter, | 
| Bill Wendling | 614c8e5 | 2011-09-27 10:37:28 +0000 | [diff] [blame] | 264 | and zero if it matched a cleanup. If nothing is matched, the behavior of | 
| Bill Wendling | 878a673 | 2011-09-26 21:10:31 +0000 | [diff] [blame] | 265 | the program is <a href="#restrictions">undefined</a>. If a type info matched, | 
| Bill Wendling | 58c80f8 | 2011-09-26 21:06:33 +0000 | [diff] [blame] | 266 | then the selector value is the index of the type info in the exception table, | 
|  | 267 | which can be obtained using the | 
| Bill Wendling | 0116184 | 2011-09-20 01:08:53 +0000 | [diff] [blame] | 268 | <a href="#llvm_eh_typeid_for"><tt>llvm.eh.typeid.for</tt></a> intrinsic.</p> | 
| Jim Laskey | 6956773 | 2007-03-14 19:29:42 +0000 | [diff] [blame] | 269 |  | 
|  | 270 | <p>Once the landing pad has the type info selector, the code branches to the | 
| Bill Wendling | 0116184 | 2011-09-20 01:08:53 +0000 | [diff] [blame] | 271 | code for the first catch. The catch then checks the value of the type info | 
| Bill Wendling | 365ab60 | 2009-08-15 08:56:09 +0000 | [diff] [blame] | 272 | selector against the index of type info for that catch.  Since the type info | 
| Bill Wendling | 58c80f8 | 2011-09-26 21:06:33 +0000 | [diff] [blame] | 273 | index is not known until all the type infos have been gathered in the | 
|  | 274 | backend, the catch code must call the | 
| Bill Wendling | 0116184 | 2011-09-20 01:08:53 +0000 | [diff] [blame] | 275 | <a href="#llvm_eh_typeid_for"><tt>llvm.eh.typeid.for</tt></a> intrinsic to | 
|  | 276 | determine the index for a given type info. If the catch fails to match the | 
| Bill Wendling | 58c80f8 | 2011-09-26 21:06:33 +0000 | [diff] [blame] | 277 | selector then control is passed on to the next catch.</p> | 
| Jim Laskey | 6956773 | 2007-03-14 19:29:42 +0000 | [diff] [blame] | 278 |  | 
| Bill Wendling | 58c80f8 | 2011-09-26 21:06:33 +0000 | [diff] [blame] | 279 | <p>Finally, the entry and exit of catch code is bracketed with calls to | 
|  | 280 | <tt>__cxa_begin_catch</tt> and <tt>__cxa_end_catch</tt>.</p> | 
| Bill Wendling | 365ab60 | 2009-08-15 08:56:09 +0000 | [diff] [blame] | 281 |  | 
|  | 282 | <ul> | 
| Bill Wendling | 58c80f8 | 2011-09-26 21:06:33 +0000 | [diff] [blame] | 283 | <li><tt>__cxa_begin_catch</tt> takes an exception structure reference as an | 
| Bill Wendling | 365ab60 | 2009-08-15 08:56:09 +0000 | [diff] [blame] | 284 | argument and returns the value of the exception object.</li> | 
|  | 285 |  | 
| Bill Wendling | fd27201 | 2009-09-10 22:14:16 +0000 | [diff] [blame] | 286 | <li><tt>__cxa_end_catch</tt> takes no arguments. This function:<br><br> | 
|  | 287 | <ol> | 
| Bill Wendling | 33b693f | 2009-09-10 22:12:50 +0000 | [diff] [blame] | 288 | <li>Locates the most recently caught exception and decrements its handler | 
|  | 289 | count,</li> | 
| Bill Wendling | 58c80f8 | 2011-09-26 21:06:33 +0000 | [diff] [blame] | 290 | <li>Removes the exception from the <i>caught</i> stack if the handler | 
|  | 291 | count goes to zero, and</li> | 
|  | 292 | <li>Destroys the exception if the handler count goes to zero and the | 
| Bill Wendling | 33b693f | 2009-09-10 22:12:50 +0000 | [diff] [blame] | 293 | exception was not re-thrown by throw.</li> | 
| Bill Wendling | fd27201 | 2009-09-10 22:14:16 +0000 | [diff] [blame] | 294 | </ol> | 
| Bill Wendling | 58c80f8 | 2011-09-26 21:06:33 +0000 | [diff] [blame] | 295 | <p><b>Note:</b> a rethrow from within the catch may replace this call with | 
| Bill Wendling | 33b693f | 2009-09-10 22:12:50 +0000 | [diff] [blame] | 296 | a <tt>__cxa_rethrow</tt>.</p></li> | 
| Bill Wendling | 365ab60 | 2009-08-15 08:56:09 +0000 | [diff] [blame] | 297 | </ul> | 
| Jim Laskey | 6956773 | 2007-03-14 19:29:42 +0000 | [diff] [blame] | 298 |  | 
|  | 299 | </div> | 
|  | 300 |  | 
|  | 301 | <!-- ======================================================================= --> | 
| NAKAMURA Takumi | fc8d930 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 302 | <h3> | 
| Duncan Sands | ef5a654 | 2007-08-27 15:47:50 +0000 | [diff] [blame] | 303 | <a name="cleanups">Cleanups</a> | 
| NAKAMURA Takumi | fc8d930 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 304 | </h3> | 
| Jim Laskey | 6956773 | 2007-03-14 19:29:42 +0000 | [diff] [blame] | 305 |  | 
| NAKAMURA Takumi | aa3d624 | 2011-04-23 00:30:22 +0000 | [diff] [blame] | 306 | <div> | 
| Jim Laskey | 6956773 | 2007-03-14 19:29:42 +0000 | [diff] [blame] | 307 |  | 
| Bill Wendling | 0116184 | 2011-09-20 01:08:53 +0000 | [diff] [blame] | 308 | <p>A cleanup is extra code which needs to be run as part of unwinding a scope. | 
| Bill Wendling | 58c80f8 | 2011-09-26 21:06:33 +0000 | [diff] [blame] | 309 | C++ destructors are a typical example, but other languages and language | 
|  | 310 | extensions provide a variety of different kinds of cleanups. In general, a | 
| Bill Wendling | 0116184 | 2011-09-20 01:08:53 +0000 | [diff] [blame] | 311 | landing pad may need to run arbitrary amounts of cleanup code before actually | 
| Bill Wendling | 58c80f8 | 2011-09-26 21:06:33 +0000 | [diff] [blame] | 312 | entering a catch block. To indicate the presence of cleanups, a | 
| Bill Wendling | 0116184 | 2011-09-20 01:08:53 +0000 | [diff] [blame] | 313 | <a href="LangRef.html#i_landingpad"><tt>landingpad</tt> instruction</a> | 
|  | 314 | should have a <i>cleanup</i> clause. Otherwise, the unwinder will not stop at | 
|  | 315 | the landing pad if there are no catches or filters that require it to.</p> | 
| John McCall | 046c47e | 2011-05-28 07:45:59 +0000 | [diff] [blame] | 316 |  | 
| Bill Wendling | 58c80f8 | 2011-09-26 21:06:33 +0000 | [diff] [blame] | 317 | <p><b>Note:</b> Do not allow a new exception to propagate out of the execution | 
|  | 318 | of a cleanup. This can corrupt the internal state of the unwinder. | 
|  | 319 | Different languages describe different high-level semantics for these | 
|  | 320 | situations: for example, C++ requires that the process be terminated, whereas | 
|  | 321 | Ada cancels both exceptions and throws a third.</p> | 
| John McCall | 046c47e | 2011-05-28 07:45:59 +0000 | [diff] [blame] | 322 |  | 
| Bill Wendling | 58c80f8 | 2011-09-26 21:06:33 +0000 | [diff] [blame] | 323 | <p>When all cleanups are finished, if the exception is not handled by the | 
|  | 324 | current function, resume unwinding by calling the | 
| Bill Wendling | 0116184 | 2011-09-20 01:08:53 +0000 | [diff] [blame] | 325 | <a href="LangRef.html#i_resume"><tt>resume</tt> instruction</a>, passing in | 
| Bill Wendling | 58c80f8 | 2011-09-26 21:06:33 +0000 | [diff] [blame] | 326 | the result of the <tt>landingpad</tt> instruction for the original landing | 
| Bill Wendling | 0116184 | 2011-09-20 01:08:53 +0000 | [diff] [blame] | 327 | pad.</p> | 
| Jim Laskey | 6956773 | 2007-03-14 19:29:42 +0000 | [diff] [blame] | 328 |  | 
|  | 329 | </div> | 
|  | 330 |  | 
|  | 331 | <!-- ======================================================================= --> | 
| NAKAMURA Takumi | fc8d930 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 332 | <h3> | 
| Jim Laskey | 6956773 | 2007-03-14 19:29:42 +0000 | [diff] [blame] | 333 | <a name="throw_filters">Throw Filters</a> | 
| NAKAMURA Takumi | fc8d930 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 334 | </h3> | 
| Jim Laskey | 6956773 | 2007-03-14 19:29:42 +0000 | [diff] [blame] | 335 |  | 
| NAKAMURA Takumi | aa3d624 | 2011-04-23 00:30:22 +0000 | [diff] [blame] | 336 | <div> | 
| Jim Laskey | 6956773 | 2007-03-14 19:29:42 +0000 | [diff] [blame] | 337 |  | 
| Bill Wendling | 58c80f8 | 2011-09-26 21:06:33 +0000 | [diff] [blame] | 338 | <p>C++ allows the specification of which exception types may be thrown from a | 
|  | 339 | function. To represent this, a top level landing pad may exist to filter out | 
|  | 340 | invalid types. To express this in LLVM code the | 
| Bill Wendling | 0116184 | 2011-09-20 01:08:53 +0000 | [diff] [blame] | 341 | <a href="LangRef.html#i_landingpad"><tt>landingpad</tt> instruction</a> will | 
|  | 342 | have a filter clause. The clause consists of an array of type infos. | 
|  | 343 | <tt>landingpad</tt> will return a negative value if the exception does not | 
|  | 344 | match any of the type infos. If no match is found then a call | 
|  | 345 | to <tt>__cxa_call_unexpected</tt> should be made, otherwise | 
|  | 346 | <tt>_Unwind_Resume</tt>.  Each of these functions requires a reference to the | 
|  | 347 | exception structure.  Note that the most general form of a | 
|  | 348 | <a href="LangRef.html#i_landingpad"><tt>landingpad</tt> instruction</a> can | 
|  | 349 | have any number of catch, cleanup, and filter clauses (though having more | 
|  | 350 | than one cleanup is pointless). The LLVM C++ front-end can generate such | 
|  | 351 | <a href="LangRef.html#i_landingpad"><tt>landingpad</tt> instructions</a> due | 
|  | 352 | to inlining creating nested exception handling scopes.</p> | 
| Jim Laskey | 6956773 | 2007-03-14 19:29:42 +0000 | [diff] [blame] | 353 |  | 
|  | 354 | </div> | 
|  | 355 |  | 
|  | 356 | <!-- ======================================================================= --> | 
| NAKAMURA Takumi | fc8d930 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 357 | <h3> | 
| Duncan Sands | ef5a654 | 2007-08-27 15:47:50 +0000 | [diff] [blame] | 358 | <a name="restrictions">Restrictions</a> | 
| NAKAMURA Takumi | fc8d930 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 359 | </h3> | 
| Duncan Sands | ef5a654 | 2007-08-27 15:47:50 +0000 | [diff] [blame] | 360 |  | 
| NAKAMURA Takumi | aa3d624 | 2011-04-23 00:30:22 +0000 | [diff] [blame] | 361 | <div> | 
| Duncan Sands | ef5a654 | 2007-08-27 15:47:50 +0000 | [diff] [blame] | 362 |  | 
| Bill Wendling | 0116184 | 2011-09-20 01:08:53 +0000 | [diff] [blame] | 363 | <p>The unwinder delegates the decision of whether to stop in a call frame to | 
| Bill Wendling | b762df5 | 2011-09-27 20:16:57 +0000 | [diff] [blame] | 364 | that call frame's language-specific personality function. Not all unwinders | 
|  | 365 | guarantee that they will stop to perform cleanups. For example, the GNU C++ | 
|  | 366 | unwinder doesn't do so unless the exception is actually caught somewhere | 
|  | 367 | further up the stack.</p> | 
| John McCall | 046c47e | 2011-05-28 07:45:59 +0000 | [diff] [blame] | 368 |  | 
| Bill Wendling | 0116184 | 2011-09-20 01:08:53 +0000 | [diff] [blame] | 369 | <p>In order for inlining to behave correctly, landing pads must be prepared to | 
| Bill Wendling | 58c80f8 | 2011-09-26 21:06:33 +0000 | [diff] [blame] | 370 | handle selector results that they did not originally advertise. Suppose that | 
| Bill Wendling | 0116184 | 2011-09-20 01:08:53 +0000 | [diff] [blame] | 371 | a function catches exceptions of type <tt>A</tt>, and it's inlined into a | 
| Bill Wendling | 58c80f8 | 2011-09-26 21:06:33 +0000 | [diff] [blame] | 372 | function that catches exceptions of type <tt>B</tt>. The inliner will update | 
| Bill Wendling | 0116184 | 2011-09-20 01:08:53 +0000 | [diff] [blame] | 373 | the <tt>landingpad</tt> instruction for the inlined landing pad to include | 
| Bill Wendling | 58c80f8 | 2011-09-26 21:06:33 +0000 | [diff] [blame] | 374 | the fact that <tt>B</tt> is also caught. If that landing pad assumes that it | 
|  | 375 | will only be entered to catch an <tt>A</tt>, it's in for a rude awakening. | 
| Bill Wendling | 0116184 | 2011-09-20 01:08:53 +0000 | [diff] [blame] | 376 | Consequently, landing pads must test for the selector results they understand | 
|  | 377 | and then resume exception propagation with the | 
|  | 378 | <a href="LangRef.html#i_resume"><tt>resume</tt> instruction</a> if none of | 
|  | 379 | the conditions match.</p> | 
| Duncan Sands | ef5a654 | 2007-08-27 15:47:50 +0000 | [diff] [blame] | 380 |  | 
|  | 381 | </div> | 
|  | 382 |  | 
| NAKAMURA Takumi | aa3d624 | 2011-04-23 00:30:22 +0000 | [diff] [blame] | 383 | </div> | 
|  | 384 |  | 
| Duncan Sands | ef5a654 | 2007-08-27 15:47:50 +0000 | [diff] [blame] | 385 | <!-- ======================================================================= --> | 
| NAKAMURA Takumi | fc8d930 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 386 | <h2> | 
| Duncan Sands | 16f122e | 2007-03-30 12:22:09 +0000 | [diff] [blame] | 387 | <a name="format_common_intrinsics">Exception Handling Intrinsics</a> | 
| NAKAMURA Takumi | fc8d930 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 388 | </h2> | 
| Jim Laskey | 6956773 | 2007-03-14 19:29:42 +0000 | [diff] [blame] | 389 |  | 
| NAKAMURA Takumi | aa3d624 | 2011-04-23 00:30:22 +0000 | [diff] [blame] | 390 | <div> | 
| Jim Laskey | 6956773 | 2007-03-14 19:29:42 +0000 | [diff] [blame] | 391 |  | 
| Bill Wendling | 0116184 | 2011-09-20 01:08:53 +0000 | [diff] [blame] | 392 | <p>In addition to the | 
|  | 393 | <a href="LangRef.html#i_landingpad"><tt>landingpad</tt></a> and | 
|  | 394 | <a href="LangRef.html#i_resume"><tt>resume</tt></a> instructions, LLVM uses | 
| Bill Wendling | 58c80f8 | 2011-09-26 21:06:33 +0000 | [diff] [blame] | 395 | several intrinsic functions (name prefixed with <i><tt>llvm.eh</tt></i>) to | 
| Bill Wendling | 365ab60 | 2009-08-15 08:56:09 +0000 | [diff] [blame] | 396 | provide exception handling information at various points in generated | 
|  | 397 | code.</p> | 
| Jim Laskey | 6956773 | 2007-03-14 19:29:42 +0000 | [diff] [blame] | 398 |  | 
| Jim Laskey | 6956773 | 2007-03-14 19:29:42 +0000 | [diff] [blame] | 399 | <!-- ======================================================================= --> | 
| NAKAMURA Takumi | fc8d930 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 400 | <h4> | 
| Jim Laskey | 6956773 | 2007-03-14 19:29:42 +0000 | [diff] [blame] | 401 | <a name="llvm_eh_typeid_for">llvm.eh.typeid.for</a> | 
| NAKAMURA Takumi | fc8d930 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 402 | </h4> | 
| Jim Laskey | 6956773 | 2007-03-14 19:29:42 +0000 | [diff] [blame] | 403 |  | 
| NAKAMURA Takumi | aa3d624 | 2011-04-23 00:30:22 +0000 | [diff] [blame] | 404 | <div> | 
| Bill Wendling | 4c1b9b0 | 2009-08-15 20:08:04 +0000 | [diff] [blame] | 405 |  | 
| Jim Laskey | 6956773 | 2007-03-14 19:29:42 +0000 | [diff] [blame] | 406 | <pre> | 
| Bill Wendling | 58c80f8 | 2011-09-26 21:06:33 +0000 | [diff] [blame] | 407 | i32 @llvm.eh.typeid.for(i8* %type_info) | 
| Jim Laskey | 6956773 | 2007-03-14 19:29:42 +0000 | [diff] [blame] | 408 | </pre> | 
|  | 409 |  | 
|  | 410 | <p>This intrinsic returns the type info index in the exception table of the | 
| Bill Wendling | 365ab60 | 2009-08-15 08:56:09 +0000 | [diff] [blame] | 411 | current function.  This value can be used to compare against the result | 
| Bill Wendling | 12e58f9 | 2011-09-20 01:14:54 +0000 | [diff] [blame] | 412 | of <a href="LangRef.html#i_landingpad"><tt>landingpad</tt> instruction</a>. | 
|  | 413 | The single argument is a reference to a type info.</p> | 
| Jim Laskey | 6956773 | 2007-03-14 19:29:42 +0000 | [diff] [blame] | 414 |  | 
|  | 415 | </div> | 
|  | 416 |  | 
|  | 417 | <!-- ======================================================================= --> | 
| NAKAMURA Takumi | fc8d930 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 418 | <h4> | 
| Jim Grosbach | 0692819 | 2009-05-14 00:46:35 +0000 | [diff] [blame] | 419 | <a name="llvm_eh_sjlj_setjmp">llvm.eh.sjlj.setjmp</a> | 
| NAKAMURA Takumi | fc8d930 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 420 | </h4> | 
| Jim Grosbach | 0692819 | 2009-05-14 00:46:35 +0000 | [diff] [blame] | 421 |  | 
| NAKAMURA Takumi | aa3d624 | 2011-04-23 00:30:22 +0000 | [diff] [blame] | 422 | <div> | 
| Bill Wendling | 527241b | 2009-08-15 20:07:42 +0000 | [diff] [blame] | 423 |  | 
| Jim Grosbach | 0692819 | 2009-05-14 00:46:35 +0000 | [diff] [blame] | 424 | <pre> | 
| Bill Wendling | 58c80f8 | 2011-09-26 21:06:33 +0000 | [diff] [blame] | 425 | i32 @llvm.eh.sjlj.setjmp(i8* %setjmp_buf) | 
| Jim Grosbach | 0692819 | 2009-05-14 00:46:35 +0000 | [diff] [blame] | 426 | </pre> | 
|  | 427 |  | 
| Bill Wendling | 58c80f8 | 2011-09-26 21:06:33 +0000 | [diff] [blame] | 428 | <p>For SJLJ based exception handling, this intrinsic forces register saving for | 
|  | 429 | the current function and stores the address of the following instruction for | 
|  | 430 | use as a destination address | 
|  | 431 | by <a href="#llvm_eh_sjlj_longjmp"><tt>llvm.eh.sjlj.longjmp</tt></a>. The | 
|  | 432 | buffer format and the overall functioning of this intrinsic is compatible | 
|  | 433 | with the GCC <tt>__builtin_setjmp</tt> implementation allowing code built | 
|  | 434 | with the clang and GCC to interoperate.</p> | 
| Jim Grosbach | 0692819 | 2009-05-14 00:46:35 +0000 | [diff] [blame] | 435 |  | 
| Bill Wendling | 365ab60 | 2009-08-15 08:56:09 +0000 | [diff] [blame] | 436 | <p>The single parameter is a pointer to a five word buffer in which the calling | 
|  | 437 | context is saved. The front end places the frame pointer in the first word, | 
|  | 438 | and the target implementation of this intrinsic should place the destination | 
|  | 439 | address for a | 
|  | 440 | <a href="#llvm_eh_sjlj_longjmp"><tt>llvm.eh.sjlj.longjmp</tt></a> in the | 
|  | 441 | second word. The following three words are available for use in a | 
|  | 442 | target-specific manner.</p> | 
| Jim Grosbach | 0692819 | 2009-05-14 00:46:35 +0000 | [diff] [blame] | 443 |  | 
| Benjamin Kramer | eaccdd3 | 2009-08-05 15:42:44 +0000 | [diff] [blame] | 444 | </div> | 
|  | 445 |  | 
| Jim Grosbach | 0692819 | 2009-05-14 00:46:35 +0000 | [diff] [blame] | 446 | <!-- ======================================================================= --> | 
| NAKAMURA Takumi | fc8d930 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 447 | <h4> | 
| Jim Grosbach | 172aaad | 2010-05-26 16:21:41 +0000 | [diff] [blame] | 448 | <a name="llvm_eh_sjlj_longjmp">llvm.eh.sjlj.longjmp</a> | 
| NAKAMURA Takumi | fc8d930 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 449 | </h4> | 
| Jim Grosbach | 172aaad | 2010-05-26 16:21:41 +0000 | [diff] [blame] | 450 |  | 
| NAKAMURA Takumi | aa3d624 | 2011-04-23 00:30:22 +0000 | [diff] [blame] | 451 | <div> | 
| Jim Grosbach | 172aaad | 2010-05-26 16:21:41 +0000 | [diff] [blame] | 452 |  | 
|  | 453 | <pre> | 
| Bill Wendling | 58c80f8 | 2011-09-26 21:06:33 +0000 | [diff] [blame] | 454 | void @llvm.eh.sjlj.longjmp(i8* %setjmp_buf) | 
| Jim Grosbach | 172aaad | 2010-05-26 16:21:41 +0000 | [diff] [blame] | 455 | </pre> | 
|  | 456 |  | 
| Bill Wendling | 58c80f8 | 2011-09-26 21:06:33 +0000 | [diff] [blame] | 457 | <p>For SJLJ based exception handling, the <tt>llvm.eh.sjlj.longjmp</tt> | 
|  | 458 | intrinsic is used to implement <tt>__builtin_longjmp()</tt>. The single | 
|  | 459 | parameter is a pointer to a buffer populated | 
|  | 460 | by <a href="#llvm_eh_sjlj_setjmp"><tt>llvm.eh.sjlj.setjmp</tt></a>. The frame | 
|  | 461 | pointer and stack pointer are restored from the buffer, then control is | 
|  | 462 | transferred to the destination address.</p> | 
| Jim Grosbach | 172aaad | 2010-05-26 16:21:41 +0000 | [diff] [blame] | 463 |  | 
|  | 464 | </div> | 
|  | 465 | <!-- ======================================================================= --> | 
| NAKAMURA Takumi | fc8d930 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 466 | <h4> | 
| Jim Grosbach | 693e36a | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 467 | <a name="llvm_eh_sjlj_lsda">llvm.eh.sjlj.lsda</a> | 
| NAKAMURA Takumi | fc8d930 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 468 | </h4> | 
| Jim Grosbach | 693e36a | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 469 |  | 
| NAKAMURA Takumi | aa3d624 | 2011-04-23 00:30:22 +0000 | [diff] [blame] | 470 | <div> | 
| Bill Wendling | 527241b | 2009-08-15 20:07:42 +0000 | [diff] [blame] | 471 |  | 
| Jim Grosbach | 693e36a | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 472 | <pre> | 
| Bill Wendling | 58c80f8 | 2011-09-26 21:06:33 +0000 | [diff] [blame] | 473 | i8* @llvm.eh.sjlj.lsda() | 
| Jim Grosbach | 693e36a | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 474 | </pre> | 
|  | 475 |  | 
| Bill Wendling | 58c80f8 | 2011-09-26 21:06:33 +0000 | [diff] [blame] | 476 | <p>For SJLJ based exception handling, the <tt>llvm.eh.sjlj.lsda</tt> intrinsic | 
|  | 477 | returns the address of the Language Specific Data Area (LSDA) for the current | 
|  | 478 | function. The SJLJ front-end code stores this address in the exception | 
|  | 479 | handling function context for use by the runtime.</p> | 
| Jim Grosbach | 693e36a | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 480 |  | 
|  | 481 | </div> | 
|  | 482 |  | 
|  | 483 | <!-- ======================================================================= --> | 
| NAKAMURA Takumi | fc8d930 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 484 | <h4> | 
| Jim Grosbach | 54c0530 | 2010-01-28 01:45:32 +0000 | [diff] [blame] | 485 | <a name="llvm_eh_sjlj_callsite">llvm.eh.sjlj.callsite</a> | 
| NAKAMURA Takumi | fc8d930 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 486 | </h4> | 
| Jim Grosbach | 54c0530 | 2010-01-28 01:45:32 +0000 | [diff] [blame] | 487 |  | 
| NAKAMURA Takumi | aa3d624 | 2011-04-23 00:30:22 +0000 | [diff] [blame] | 488 | <div> | 
| Jim Grosbach | 54c0530 | 2010-01-28 01:45:32 +0000 | [diff] [blame] | 489 |  | 
|  | 490 | <pre> | 
| Bill Wendling | 58c80f8 | 2011-09-26 21:06:33 +0000 | [diff] [blame] | 491 | void @llvm.eh.sjlj.callsite(i32 %call_site_num) | 
| Jim Grosbach | 54c0530 | 2010-01-28 01:45:32 +0000 | [diff] [blame] | 492 | </pre> | 
|  | 493 |  | 
| Bill Wendling | 58c80f8 | 2011-09-26 21:06:33 +0000 | [diff] [blame] | 494 | <p>For SJLJ based exception handling, the <tt>llvm.eh.sjlj.callsite</tt> | 
|  | 495 | intrinsic identifies the callsite value associated with the | 
|  | 496 | following <tt>invoke</tt> instruction. This is used to ensure that landing | 
|  | 497 | pad entries in the LSDA are generated in matching order.</p> | 
| Jim Grosbach | 54c0530 | 2010-01-28 01:45:32 +0000 | [diff] [blame] | 498 |  | 
|  | 499 | </div> | 
|  | 500 |  | 
|  | 501 | <!-- ======================================================================= --> | 
| NAKAMURA Takumi | fc8d930 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 502 | <h4> | 
| Jim Grosbach | bbdc5d2 | 2010-10-19 23:27:08 +0000 | [diff] [blame] | 503 | <a name="llvm_eh_sjlj_dispatchsetup">llvm.eh.sjlj.dispatchsetup</a> | 
| NAKAMURA Takumi | fc8d930 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 504 | </h4> | 
| Jim Grosbach | bbdc5d2 | 2010-10-19 23:27:08 +0000 | [diff] [blame] | 505 |  | 
| NAKAMURA Takumi | aa3d624 | 2011-04-23 00:30:22 +0000 | [diff] [blame] | 506 | <div> | 
| Jim Grosbach | bbdc5d2 | 2010-10-19 23:27:08 +0000 | [diff] [blame] | 507 |  | 
|  | 508 | <pre> | 
| Bill Wendling | 58c80f8 | 2011-09-26 21:06:33 +0000 | [diff] [blame] | 509 | void @llvm.eh.sjlj.dispatchsetup(i32 %dispatch_value) | 
| Jim Grosbach | bbdc5d2 | 2010-10-19 23:27:08 +0000 | [diff] [blame] | 510 | </pre> | 
|  | 511 |  | 
| Bill Wendling | 58c80f8 | 2011-09-26 21:06:33 +0000 | [diff] [blame] | 512 | <p>For SJLJ based exception handling, the <tt>llvm.eh.sjlj.dispatchsetup</tt> | 
|  | 513 | intrinsic is used by targets to do any unwind edge setup they need. By | 
|  | 514 | default, no action is taken.</p> | 
| Jim Grosbach | bbdc5d2 | 2010-10-19 23:27:08 +0000 | [diff] [blame] | 515 |  | 
|  | 516 | </div> | 
|  | 517 |  | 
| NAKAMURA Takumi | aa3d624 | 2011-04-23 00:30:22 +0000 | [diff] [blame] | 518 | </div> | 
|  | 519 |  | 
| Jim Grosbach | bbdc5d2 | 2010-10-19 23:27:08 +0000 | [diff] [blame] | 520 | <!-- ======================================================================= --> | 
| NAKAMURA Takumi | fc8d930 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 521 | <h2> | 
| Jim Laskey | 6956773 | 2007-03-14 19:29:42 +0000 | [diff] [blame] | 522 | <a name="asm">Asm Table Formats</a> | 
| NAKAMURA Takumi | fc8d930 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 523 | </h2> | 
| Jim Laskey | 6956773 | 2007-03-14 19:29:42 +0000 | [diff] [blame] | 524 |  | 
| NAKAMURA Takumi | aa3d624 | 2011-04-23 00:30:22 +0000 | [diff] [blame] | 525 | <div> | 
| Jim Laskey | 6956773 | 2007-03-14 19:29:42 +0000 | [diff] [blame] | 526 |  | 
|  | 527 | <p>There are two tables that are used by the exception handling runtime to | 
| Bill Wendling | 58c80f8 | 2011-09-26 21:06:33 +0000 | [diff] [blame] | 528 | determine which actions should be taken when an exception is thrown.</p> | 
| Jim Laskey | 6956773 | 2007-03-14 19:29:42 +0000 | [diff] [blame] | 529 |  | 
| Jim Laskey | 6956773 | 2007-03-14 19:29:42 +0000 | [diff] [blame] | 530 | <!-- ======================================================================= --> | 
| NAKAMURA Takumi | fc8d930 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 531 | <h3> | 
| Jim Laskey | 6956773 | 2007-03-14 19:29:42 +0000 | [diff] [blame] | 532 | <a name="unwind_tables">Exception Handling Frame</a> | 
| NAKAMURA Takumi | fc8d930 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 533 | </h3> | 
| Jim Laskey | 6956773 | 2007-03-14 19:29:42 +0000 | [diff] [blame] | 534 |  | 
| NAKAMURA Takumi | aa3d624 | 2011-04-23 00:30:22 +0000 | [diff] [blame] | 535 | <div> | 
| Jim Laskey | 6956773 | 2007-03-14 19:29:42 +0000 | [diff] [blame] | 536 |  | 
|  | 537 | <p>An exception handling frame <tt>eh_frame</tt> is very similar to the unwind | 
| Bill Wendling | 58c80f8 | 2011-09-26 21:06:33 +0000 | [diff] [blame] | 538 | frame used by DWARF debug info. The frame contains all the information | 
| Bill Wendling | 365ab60 | 2009-08-15 08:56:09 +0000 | [diff] [blame] | 539 | necessary to tear down the current frame and restore the state of the prior | 
| Bill Wendling | 58c80f8 | 2011-09-26 21:06:33 +0000 | [diff] [blame] | 540 | frame. There is an exception handling frame for each function in a compile | 
| Bill Wendling | 365ab60 | 2009-08-15 08:56:09 +0000 | [diff] [blame] | 541 | unit, plus a common exception handling frame that defines information common | 
|  | 542 | to all functions in the unit.</p> | 
| Jim Laskey | 6956773 | 2007-03-14 19:29:42 +0000 | [diff] [blame] | 543 |  | 
| Bill Wendling | 58c80f8 | 2011-09-26 21:06:33 +0000 | [diff] [blame] | 544 | <!-- Todo - Table details here. --> | 
| Jim Laskey | 6956773 | 2007-03-14 19:29:42 +0000 | [diff] [blame] | 545 |  | 
|  | 546 | </div> | 
|  | 547 |  | 
|  | 548 | <!-- ======================================================================= --> | 
| NAKAMURA Takumi | fc8d930 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 549 | <h3> | 
| Jim Laskey | 6956773 | 2007-03-14 19:29:42 +0000 | [diff] [blame] | 550 | <a name="exception_tables">Exception Tables</a> | 
| NAKAMURA Takumi | fc8d930 | 2011-04-18 23:59:50 +0000 | [diff] [blame] | 551 | </h3> | 
| Jim Laskey | 6956773 | 2007-03-14 19:29:42 +0000 | [diff] [blame] | 552 |  | 
| NAKAMURA Takumi | aa3d624 | 2011-04-23 00:30:22 +0000 | [diff] [blame] | 553 | <div> | 
| Jim Laskey | 6956773 | 2007-03-14 19:29:42 +0000 | [diff] [blame] | 554 |  | 
|  | 555 | <p>An exception table contains information about what actions to take when an | 
| Bill Wendling | 58c80f8 | 2011-09-26 21:06:33 +0000 | [diff] [blame] | 556 | exception is thrown in a particular part of a function's code. There is one | 
|  | 557 | exception table per function, except leaf functions and functions that have | 
|  | 558 | calls only to non-throwing functions. They do not need an exception | 
|  | 559 | table.</p> | 
| Jim Laskey | 6956773 | 2007-03-14 19:29:42 +0000 | [diff] [blame] | 560 |  | 
| Bill Wendling | 58c80f8 | 2011-09-26 21:06:33 +0000 | [diff] [blame] | 561 | <!-- Todo - Table details here. --> | 
| Jim Laskey | 6956773 | 2007-03-14 19:29:42 +0000 | [diff] [blame] | 562 |  | 
|  | 563 | </div> | 
|  | 564 |  | 
| NAKAMURA Takumi | aa3d624 | 2011-04-23 00:30:22 +0000 | [diff] [blame] | 565 | </div> | 
|  | 566 |  | 
| Jim Laskey | 6956773 | 2007-03-14 19:29:42 +0000 | [diff] [blame] | 567 | <!-- *********************************************************************** --> | 
|  | 568 |  | 
|  | 569 | <hr> | 
|  | 570 | <address> | 
|  | 571 | <a href="http://jigsaw.w3.org/css-validator/check/referer"><img | 
| Misha Brukman | 86242e1 | 2008-12-11 17:34:48 +0000 | [diff] [blame] | 572 | src="http://jigsaw.w3.org/css-validator/images/vcss-blue" alt="Valid CSS"></a> | 
| Jim Laskey | 6956773 | 2007-03-14 19:29:42 +0000 | [diff] [blame] | 573 | <a href="http://validator.w3.org/check/referer"><img | 
| Misha Brukman | 86242e1 | 2008-12-11 17:34:48 +0000 | [diff] [blame] | 574 | src="http://www.w3.org/Icons/valid-html401-blue" alt="Valid HTML 4.01"></a> | 
| Jim Laskey | 6956773 | 2007-03-14 19:29:42 +0000 | [diff] [blame] | 575 |  | 
|  | 576 | <a href="mailto:sabre@nondot.org">Chris Lattner</a><br> | 
| NAKAMURA Takumi | ca46f5a | 2011-04-09 02:13:37 +0000 | [diff] [blame] | 577 | <a href="http://llvm.org/">LLVM Compiler Infrastructure</a><br> | 
| Jim Laskey | 6956773 | 2007-03-14 19:29:42 +0000 | [diff] [blame] | 578 | Last modified: $Date$ | 
|  | 579 | </address> | 
|  | 580 |  | 
|  | 581 | </body> | 
|  | 582 | </html> |