blob: cf6a467bf0b2a546d4ecdefc118915b2adc42101 [file] [log] [blame]
Jim Laskeyd0d39b62007-03-14 19:29:42 +00001<!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 Wendlingc4f661e2009-08-15 08:56:09 +00006 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
7 <meta name="description"
8 content="Exception Handling in LLVM.">
Jim Laskeyd0d39b62007-03-14 19:29:42 +00009 <link rel="stylesheet" href="llvm.css" type="text/css">
10</head>
Bill Wendlingc4f661e2009-08-15 08:56:09 +000011
Jim Laskeyd0d39b62007-03-14 19:29:42 +000012<body>
13
14<div class="doc_title">Exception Handling in LLVM</div>
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>
23 <li><a href="#overview">Overview</a></li>
24 </ol></li>
25 <li><a href="#codegen">LLVM Code Generation</a>
26 <ol>
27 <li><a href="#throw">Throw</a></li>
28 <li><a href="#try_catch">Try/Catch</a></li>
Duncan Sands6590b042007-08-27 15:47:50 +000029 <li><a href="#cleanups">Cleanups</a></li>
Jim Laskeyd0d39b62007-03-14 19:29:42 +000030 <li><a href="#throw_filters">Throw Filters</a></li>
Duncan Sands6590b042007-08-27 15:47:50 +000031 <li><a href="#restrictions">Restrictions</a></li>
Jim Laskeyd0d39b62007-03-14 19:29:42 +000032 </ol></li>
Duncan Sands8036ca42007-03-30 12:22:09 +000033 <li><a href="#format_common_intrinsics">Exception Handling Intrinsics</a>
Jim Laskeyd0d39b62007-03-14 19:29:42 +000034 <ol>
35 <li><a href="#llvm_eh_exception"><tt>llvm.eh.exception</tt></a></li>
36 <li><a href="#llvm_eh_selector"><tt>llvm.eh.selector</tt></a></li>
Jim Laskeyd0d39b62007-03-14 19:29:42 +000037 <li><a href="#llvm_eh_typeid_for"><tt>llvm.eh.typeid.for</tt></a></li>
Jim Grosbachf9570122009-05-14 00:46:35 +000038 <li><a href="#llvm_eh_sjlj_setjmp"><tt>llvm.eh.sjlj.setjmp</tt></a></li>
39 <li><a href="#llvm_eh_sjlj_longjmp"><tt>llvm.eh.sjlj.longjmp</tt></a></li>
Jim Grosbach1b747ad2009-08-11 00:09:57 +000040 <li><a href="#llvm_eh_sjlj_lsda"><tt>llvm.eh.sjlj.lsda</tt></a></li>
41 <li><a href="#llvm_eh_sjlj_callsite"><tt>llvm.eh.sjlj.callsite</tt></a></li>
Jim Laskeyd0d39b62007-03-14 19:29:42 +000042 </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>
48 <li><a href="#todo">ToDo</a></li>
49</ul>
50</td>
51</tr></table>
52
53<div class="doc_author">
54 <p>Written by <a href="mailto:jlaskey@mac.com">Jim Laskey</a></p>
55</div>
56
57
58<!-- *********************************************************************** -->
59<div class="doc_section"><a name="introduction">Introduction</a></div>
60<!-- *********************************************************************** -->
61
62<div class="doc_text">
63
64<p>This document is the central repository for all information pertaining to
Bill Wendlingc4f661e2009-08-15 08:56:09 +000065 exception handling in LLVM. It describes the format that LLVM exception
66 handling information takes, which is useful for those interested in creating
67 front-ends or dealing directly with the information. Further, this document
68 provides specific examples of what exception handling information is used for
69 in C/C++.</p>
Jim Laskeyd0d39b62007-03-14 19:29:42 +000070
71</div>
72
73<!-- ======================================================================= -->
74<div class="doc_subsection">
75 <a name="itanium">Itanium ABI Zero-cost Exception Handling</a>
76</div>
77
78<div class="doc_text">
79
80<p>Exception handling for most programming languages is designed to recover from
Bill Wendlingc4f661e2009-08-15 08:56:09 +000081 conditions that rarely occur during general use of an application. To that
82 end, exception handling should not interfere with the main flow of an
83 application's algorithm by performing checkpointing tasks, such as saving the
84 current pc or register state.</p>
Jim Laskeyd0d39b62007-03-14 19:29:42 +000085
86<p>The Itanium ABI Exception Handling Specification defines a methodology for
Bill Wendlingc4f661e2009-08-15 08:56:09 +000087 providing outlying data in the form of exception tables without inlining
88 speculative exception handling code in the flow of an application's main
89 algorithm. Thus, the specification is said to add "zero-cost" to the normal
90 execution of an application.</p>
Jim Laskeyd0d39b62007-03-14 19:29:42 +000091
92<p>A more complete description of the Itanium ABI exception handling runtime
Bill Wendlingc4f661e2009-08-15 08:56:09 +000093 support of can be found at
94 <a href="http://www.codesourcery.com/cxx-abi/abi-eh.html">Itanium C++ ABI:
95 Exception Handling</a>. A description of the exception frame format can be
96 found at
97 <a href="http://refspecs.freestandards.org/LSB_3.0.0/LSB-Core-generic/LSB-Core-generic/ehframechpt.html">Exception
98 Frames</a>, with details of the DWARF 3 specification at
99 <a href="http://www.eagercon.com/dwarf/dwarf3std.htm">DWARF 3 Standard</a>.
100 A description for the C++ exception table formats can be found at
101 <a href="http://www.codesourcery.com/cxx-abi/exceptions.pdf">Exception Handling
102 Tables</a>.</p>
Jim Laskeyd0d39b62007-03-14 19:29:42 +0000103
104</div>
105
106<!-- ======================================================================= -->
107<div class="doc_subsection">
108 <a name="overview">Overview</a>
109</div>
110
111<div class="doc_text">
112
Bill Wendlingc4f661e2009-08-15 08:56:09 +0000113<p>When an exception is thrown in LLVM code, the runtime does its best to find a
114 handler suited to processing the circumstance.</p>
Jim Laskeyd0d39b62007-03-14 19:29:42 +0000115
116<p>The runtime first attempts to find an <i>exception frame</i> corresponding to
Bill Wendlingc4f661e2009-08-15 08:56:09 +0000117 the function where the exception was thrown. If the programming language
118 (e.g. C++) supports exception handling, the exception frame contains a
119 reference to an exception table describing how to process the exception. If
120 the language (e.g. C) does not support exception handling, or if the
121 exception needs to be forwarded to a prior activation, the exception frame
122 contains information about how to unwind the current activation and restore
123 the state of the prior activation. This process is repeated until the
124 exception is handled. If the exception is not handled and no activations
125 remain, then the application is terminated with an appropriate error
126 message.</p>
Jim Laskeyd0d39b62007-03-14 19:29:42 +0000127
Bill Wendlingc4f661e2009-08-15 08:56:09 +0000128<p>Because different programming languages have different behaviors when
129 handling exceptions, the exception handling ABI provides a mechanism for
130 supplying <i>personalities.</i> An exception handling personality is defined
131 by way of a <i>personality function</i> (e.g. <tt>__gxx_personality_v0</tt>
132 in C++), which receives the context of the exception, an <i>exception
133 structure</i> containing the exception object type and value, and a reference
134 to the exception table for the current function. The personality function
135 for the current compile unit is specified in a <i>common exception
136 frame</i>.</p>
Jim Laskeyd0d39b62007-03-14 19:29:42 +0000137
138<p>The organization of an exception table is language dependent. For C++, an
Bill Wendlingc4f661e2009-08-15 08:56:09 +0000139 exception table is organized as a series of code ranges defining what to do
140 if an exception occurs in that range. Typically, the information associated
141 with a range defines which types of exception objects (using C++ <i>type
142 info</i>) that are handled in that range, and an associated action that
143 should take place. Actions typically pass control to a <i>landing
144 pad</i>.</p>
Jim Laskeyd0d39b62007-03-14 19:29:42 +0000145
Bill Wendlingc4f661e2009-08-15 08:56:09 +0000146<p>A landing pad corresponds to the code found in the <i>catch</i> portion of
147 a <i>try</i>/<i>catch</i> sequence. When execution resumes at a landing
148 pad, it receives the exception structure and a selector corresponding to
149 the <i>type</i> of exception thrown. The selector is then used to determine
150 which <i>catch</i> should actually process the exception.</p>
Jim Laskeyd0d39b62007-03-14 19:29:42 +0000151
152</div>
153
154<!-- ======================================================================= -->
155<div class="doc_section">
156 <a name="codegen">LLVM Code Generation</a>
157</div>
158
159<div class="doc_text">
160
161<p>At the time of this writing, only C++ exception handling support is available
Bill Wendlingc4f661e2009-08-15 08:56:09 +0000162 in LLVM. So the remainder of this document will be somewhat C++-centric.</p>
Jim Laskeyd0d39b62007-03-14 19:29:42 +0000163
164<p>From the C++ developers perspective, exceptions are defined in terms of the
Bill Wendlingc4f661e2009-08-15 08:56:09 +0000165 <tt>throw</tt> and <tt>try</tt>/<tt>catch</tt> statements. In this section
166 we will describe the implementation of LLVM exception handling in terms of
167 C++ examples.</p>
Jim Laskeyd0d39b62007-03-14 19:29:42 +0000168
169</div>
170
171<!-- ======================================================================= -->
172<div class="doc_subsection">
173 <a name="throw">Throw</a>
174</div>
175
176<div class="doc_text">
177
178<p>Languages that support exception handling typically provide a <tt>throw</tt>
Bill Wendlingc4f661e2009-08-15 08:56:09 +0000179 operation to initiate the exception process. Internally, a throw operation
180 breaks down into two steps. First, a request is made to allocate exception
181 space for an exception structure. This structure needs to survive beyond the
182 current activation. This structure will contain the type and value of the
183 object being thrown. Second, a call is made to the runtime to raise the
184 exception, passing the exception structure as an argument.</p>
Jim Laskeyd0d39b62007-03-14 19:29:42 +0000185
Bill Wendlingc4f661e2009-08-15 08:56:09 +0000186<p>In C++, the allocation of the exception structure is done by
187 the <tt>__cxa_allocate_exception</tt> runtime function. The exception
188 raising is handled by <tt>__cxa_throw</tt>. The type of the exception is
189 represented using a C++ RTTI structure.</p>
Jim Laskeyd0d39b62007-03-14 19:29:42 +0000190
191</div>
192
193<!-- ======================================================================= -->
194<div class="doc_subsection">
195 <a name="try_catch">Try/Catch</a>
196</div>
197
198<div class="doc_text">
199
Bill Wendlingc4f661e2009-08-15 08:56:09 +0000200<p>A call within the scope of a <i>try</i> statement can potentially raise an
201 exception. In those circumstances, the LLVM C++ front-end replaces the call
202 with an <tt>invoke</tt> instruction. Unlike a call, the <tt>invoke</tt> has
203 two potential continuation points: where to continue when the call succeeds
204 as per normal; and where to continue if the call raises an exception, either
205 by a throw or the unwinding of a throw.</p>
Jim Laskeyd0d39b62007-03-14 19:29:42 +0000206
Bill Wendlingc4f661e2009-08-15 08:56:09 +0000207<p>The term used to define a the place where an <tt>invoke</tt> continues after
208 an exception is called a <i>landing pad</i>. LLVM landing pads are
209 conceptually alternative function entry points where an exception structure
210 reference and a type info index are passed in as arguments. The landing pad
211 saves the exception structure reference and then proceeds to select the catch
212 block that corresponds to the type info of the exception object.</p>
Jim Laskeyd0d39b62007-03-14 19:29:42 +0000213
Bill Wendlingc4f661e2009-08-15 08:56:09 +0000214<p>Two LLVM intrinsic functions are used to convey information about the landing
215 pad to the back end.</p>
Jim Laskeyd0d39b62007-03-14 19:29:42 +0000216
Bill Wendlingc4f661e2009-08-15 08:56:09 +0000217<ol>
218 <li><a href="#llvm_eh_exception"><tt>llvm.eh.exception</tt></a> takes no
219 arguments and returns a pointer to the exception structure. This only
220 returns a sensible value if called after an <tt>invoke</tt> has branched
221 to a landing pad. Due to code generation limitations, it must currently
222 be called in the landing pad itself.</li>
Jim Laskeyd0d39b62007-03-14 19:29:42 +0000223
Bill Wendlingc4f661e2009-08-15 08:56:09 +0000224 <li><a href="#llvm_eh_selector"><tt>llvm.eh.selector</tt></a> takes a minimum
225 of three arguments. The first argument is the reference to the exception
226 structure. The second argument is a reference to the personality function
227 to be used for this <tt>try</tt>/<tt>catch</tt> sequence. Each of the
228 remaining arguments is either a reference to the type info for
229 a <tt>catch</tt> statement, a <a href="#throw_filters">filter</a>
230 expression, or the number zero (<tt>0</tt>) representing
231 a <a href="#cleanups">cleanup</a>. The exception is tested against the
232 arguments sequentially from first to last. The result of
233 the <a href="#llvm_eh_selector"><tt>llvm.eh.selector</tt></a> is a
234 positive number if the exception matched a type info, a negative number if
235 it matched a filter, and zero if it matched a cleanup. If nothing is
236 matched, the behaviour of the program
237 is <a href="#restrictions">undefined</a>. This only returns a sensible
238 value if called after an <tt>invoke</tt> has branched to a landing pad.
239 Due to codegen limitations, it must currently be called in the landing pad
240 itself. If a type info matched, then the selector value is the index of
241 the type info in the exception table, which can be obtained using the
242 <a href="#llvm_eh_typeid_for"><tt>llvm.eh.typeid.for</tt></a>
243 intrinsic.</li>
244</ol>
Jim Laskeyd0d39b62007-03-14 19:29:42 +0000245
246<p>Once the landing pad has the type info selector, the code branches to the
Bill Wendlingc4f661e2009-08-15 08:56:09 +0000247 code for the first catch. The catch then checks the value of the type info
248 selector against the index of type info for that catch. Since the type info
249 index is not known until all the type info have been gathered in the backend,
250 the catch code will call the
251 <a href="#llvm_eh_typeid_for"><tt>llvm.eh.typeid.for</tt></a> intrinsic
252 to determine the index for a given type info. If the catch fails to match
253 the selector then control is passed on to the next catch. Note: Since the
254 landing pad will not be used if there is no match in the list of type info on
255 the call to <a href="#llvm_eh_selector"><tt>llvm.eh.selector</tt></a>, then
256 neither the last catch nor <i>catch all</i> need to perform the check
257 against the selector.</p>
Jim Laskeyd0d39b62007-03-14 19:29:42 +0000258
Bill Wendlingc4f661e2009-08-15 08:56:09 +0000259<p>Finally, the entry and exit of catch code is bracketed with calls
260 to <tt>__cxa_begin_catch</tt> and <tt>__cxa_end_catch</tt>.</p>
261
262<ul>
263 <li><tt>__cxa_begin_catch</tt> takes a exception structure reference as an
264 argument and returns the value of the exception object.</li>
265
266 <li><tt>__cxa_end_catch</tt> takes a exception structure reference as an
267 argument. This function clears the exception from the exception space.
268 Note: a rethrow from within the catch may replace this call with
269 a <tt>__cxa_rethrow</tt>.</li>
270</ul>
Jim Laskeyd0d39b62007-03-14 19:29:42 +0000271
272</div>
273
274<!-- ======================================================================= -->
275<div class="doc_subsection">
Duncan Sands6590b042007-08-27 15:47:50 +0000276 <a name="cleanups">Cleanups</a>
Jim Laskeyd0d39b62007-03-14 19:29:42 +0000277</div>
278
279<div class="doc_text">
280
Bill Wendlingc4f661e2009-08-15 08:56:09 +0000281<p>To handle destructors and cleanups in <tt>try</tt> code, control may not run
282 directly from a landing pad to the first catch. Control may actually flow
283 from the landing pad to clean up code and then to the first catch. Since the
284 required clean up for each <tt>invoke</tt> in a <tt>try</tt> may be different
285 (e.g. intervening constructor), there may be several landing pads for a given
286 try. If cleanups need to be run, the number zero should be passed as the
287 last <a href="#llvm_eh_selector"><tt>llvm.eh.selector</tt></a> argument.
288 However for C++ a <tt>null i8*</tt> <b><a href="#restrictions">must</a></b>
289 be passed instead.</p>
Jim Laskeyd0d39b62007-03-14 19:29:42 +0000290
291</div>
292
293<!-- ======================================================================= -->
294<div class="doc_subsection">
295 <a name="throw_filters">Throw Filters</a>
296</div>
297
298<div class="doc_text">
299
Bill Wendlingc4f661e2009-08-15 08:56:09 +0000300<p>C++ allows the specification of which exception types can be thrown from a
301 function. To represent this a top level landing pad may exist to filter out
302 invalid types. To express this in LLVM code the landing pad will
303 call <a href="#llvm_eh_selector"><tt>llvm.eh.selector</tt></a>. The
304 arguments are a reference to the exception structure, a reference to the
305 personality function, the length of the filter expression (the number of type
306 infos plus one), followed by the type infos themselves.
307 <a href="#llvm_eh_selector"><tt>llvm.eh.selector</tt></a> will return a
308 negative value if the exception does not match any of the type infos. If no
309 match is found then a call to <tt>__cxa_call_unexpected</tt> should be made,
310 otherwise <tt>_Unwind_Resume</tt>. Each of these functions requires a
311 reference to the exception structure. Note that the most general form of an
312 <a href="#llvm_eh_selector"><tt>llvm.eh.selector</tt></a> call can contain
313 any number of type infos, filter expressions and cleanups (though having more
314 than one cleanup is pointless). The LLVM C++ front-end can generate such
315 <a href="#llvm_eh_selector"><tt>llvm.eh.selector</tt></a> calls due to
316 inlining creating nested exception handling scopes.</p>
Jim Laskeyd0d39b62007-03-14 19:29:42 +0000317
318</div>
319
320<!-- ======================================================================= -->
Duncan Sands6590b042007-08-27 15:47:50 +0000321<div class="doc_subsection">
322 <a name="restrictions">Restrictions</a>
323</div>
324
325<div class="doc_text">
326
327<p>The semantics of the invoke instruction require that any exception that
Bill Wendlingc4f661e2009-08-15 08:56:09 +0000328 unwinds through an invoke call should result in a branch to the invoke's
329 unwind label. However such a branch will only happen if the
330 <a href="#llvm_eh_selector"><tt>llvm.eh.selector</tt></a> matches. Thus in
331 order to ensure correct operation, the front-end must only generate
332 <a href="#llvm_eh_selector"><tt>llvm.eh.selector</tt></a> calls that are
333 guaranteed to always match whatever exception unwinds through the invoke.
334 For most languages it is enough to pass zero, indicating the presence of
335 a <a href="#cleanups">cleanup</a>, as the
336 last <a href="#llvm_eh_selector"><tt>llvm.eh.selector</tt></a> argument.
337 However for C++ this is not sufficient, because the C++ personality function
338 will terminate the program if it detects that unwinding the exception only
339 results in matches with cleanups. For C++ a <tt>null i8*</tt> should be
340 passed as the last <a href="#llvm_eh_selector"><tt>llvm.eh.selector</tt></a>
341 argument instead. This is interpreted as a catch-all by the C++ personality
342 function, and will always match.</p>
Duncan Sands6590b042007-08-27 15:47:50 +0000343
344</div>
345
346<!-- ======================================================================= -->
Jim Laskeyd0d39b62007-03-14 19:29:42 +0000347<div class="doc_section">
Duncan Sands8036ca42007-03-30 12:22:09 +0000348 <a name="format_common_intrinsics">Exception Handling Intrinsics</a>
Jim Laskeyd0d39b62007-03-14 19:29:42 +0000349</div>
350
351<div class="doc_text">
352
353<p>LLVM uses several intrinsic functions (name prefixed with "llvm.eh") to
Bill Wendlingc4f661e2009-08-15 08:56:09 +0000354 provide exception handling information at various points in generated
355 code.</p>
Jim Laskeyd0d39b62007-03-14 19:29:42 +0000356
357</div>
358
359<!-- ======================================================================= -->
360<div class="doc_subsubsection">
361 <a name="llvm_eh_exception">llvm.eh.exception</a>
362</div>
363
364<div class="doc_text">
Bill Wendling3cf4ffd2009-08-15 20:07:42 +0000365
Jim Laskeyd0d39b62007-03-14 19:29:42 +0000366<pre>
Bill Wendling3cf4ffd2009-08-15 20:07:42 +0000367 i8* %<a href="#llvm_eh_exception">llvm.eh.exception</a>( )
Jim Laskeyd0d39b62007-03-14 19:29:42 +0000368</pre>
369
Duncan Sands6531d472008-12-29 15:27:32 +0000370<p>This intrinsic returns a pointer to the exception structure.</p>
Jim Laskeyd0d39b62007-03-14 19:29:42 +0000371
372</div>
373
374<!-- ======================================================================= -->
375<div class="doc_subsubsection">
376 <a name="llvm_eh_selector">llvm.eh.selector</a>
377</div>
378
379<div class="doc_text">
Bill Wendling3cf4ffd2009-08-15 20:07:42 +0000380
Jim Laskeyd0d39b62007-03-14 19:29:42 +0000381<pre>
Bill Wendling3cf4ffd2009-08-15 20:07:42 +0000382 i32 %<a href="#llvm_eh_selector">llvm.eh.selector.i32</a>(i8*, i8*, i8*, ...)
383 i64 %<a href="#llvm_eh_selector">llvm.eh.selector.i64</a>(i8*, i8*, i8*, ...)
Jim Laskeyd0d39b62007-03-14 19:29:42 +0000384</pre>
385
Duncan Sands6531d472008-12-29 15:27:32 +0000386<p>This intrinsic is used to compare the exception with the given type infos,
Bill Wendlingc4f661e2009-08-15 08:56:09 +0000387 filters and cleanups.</p>
Jim Laskeyd0d39b62007-03-14 19:29:42 +0000388
389<p><a href="#llvm_eh_selector"><tt>llvm.eh.selector</tt></a> takes a minimum of
Bill Wendlingc4f661e2009-08-15 08:56:09 +0000390 three arguments. The first argument is the reference to the exception
391 structure. The second argument is a reference to the personality function to
392 be used for this try catch sequence. Each of the remaining arguments is
393 either a reference to the type info for a catch statement,
394 a <a href="#throw_filters">filter</a> expression, or the number zero
395 representing a <a href="#cleanups">cleanup</a>. The exception is tested
396 against the arguments sequentially from first to last. The result of
397 the <a href="#llvm_eh_selector"><tt>llvm.eh.selector</tt></a> is a positive
398 number if the exception matched a type info, a negative number if it matched
399 a filter, and zero if it matched a cleanup. If nothing is matched, the
400 behaviour of the program is <a href="#restrictions">undefined</a>. If a type
401 info matched then the selector value is the index of the type info in the
402 exception table, which can be obtained using the
403 <a href="#llvm_eh_typeid_for"><tt>llvm.eh.typeid.for</tt></a> intrinsic.</p>
Jim Laskeyd0d39b62007-03-14 19:29:42 +0000404
405</div>
406
407<!-- ======================================================================= -->
408<div class="doc_subsubsection">
409 <a name="llvm_eh_typeid_for">llvm.eh.typeid.for</a>
410</div>
411
412<div class="doc_text">
413<pre>
Bill Wendlingc4f661e2009-08-15 08:56:09 +0000414i32 %<a href="#llvm_eh_typeid_for">llvm.eh.typeid.for.i32</a>(i8*)
415i64 %<a href="#llvm_eh_typeid_for">llvm.eh.typeid.for.i64</a>(i8*)
Jim Laskeyd0d39b62007-03-14 19:29:42 +0000416</pre>
Bill Wendlingc4f661e2009-08-15 08:56:09 +0000417</div>
Jim Laskeyd0d39b62007-03-14 19:29:42 +0000418
419<p>This intrinsic returns the type info index in the exception table of the
Bill Wendlingc4f661e2009-08-15 08:56:09 +0000420 current function. This value can be used to compare against the result
421 of <a href="#llvm_eh_selector"><tt>llvm.eh.selector</tt></a>. The single
422 argument is a reference to a type info.</p>
Jim Laskeyd0d39b62007-03-14 19:29:42 +0000423
424</div>
425
426<!-- ======================================================================= -->
Jim Grosbachf9570122009-05-14 00:46:35 +0000427<div class="doc_subsubsection">
428 <a name="llvm_eh_sjlj_setjmp">llvm.eh.sjlj.setjmp</a>
429</div>
430
431<div class="doc_text">
Bill Wendling3cf4ffd2009-08-15 20:07:42 +0000432
Jim Grosbachf9570122009-05-14 00:46:35 +0000433<pre>
Bill Wendling3cf4ffd2009-08-15 20:07:42 +0000434 i32 %<a href="#llvm_eh_sjlj_setjmp">llvm.eh.sjlj.setjmp</a>(i8*)
Jim Grosbachf9570122009-05-14 00:46:35 +0000435</pre>
436
Bill Wendlingc4f661e2009-08-15 08:56:09 +0000437<p>The SJLJ exception handling uses this intrinsic to force register saving for
438 the current function and to store the address of the following instruction
439 for use as a destination address by <a href="#llvm_eh_sjlj_longjmp">
440 <tt>llvm.eh.sjlj.longjmp</tt></a>. The buffer format and the overall
441 functioning of this intrinsic is compatible with the GCC
442 <tt>__builtin_setjmp</tt> implementation, allowing code built with the
443 two compilers to interoperate.</p>
Jim Grosbachf9570122009-05-14 00:46:35 +0000444
Bill Wendlingc4f661e2009-08-15 08:56:09 +0000445<p>The single parameter is a pointer to a five word buffer in which the calling
446 context is saved. The front end places the frame pointer in the first word,
447 and the target implementation of this intrinsic should place the destination
448 address for a
449 <a href="#llvm_eh_sjlj_longjmp"><tt>llvm.eh.sjlj.longjmp</tt></a> in the
450 second word. The following three words are available for use in a
451 target-specific manner.</p>
Jim Grosbachf9570122009-05-14 00:46:35 +0000452
Benjamin Kramere15192b2009-08-05 15:42:44 +0000453</div>
454
Jim Grosbachf9570122009-05-14 00:46:35 +0000455<!-- ======================================================================= -->
Jim Grosbach1b747ad2009-08-11 00:09:57 +0000456<div class="doc_subsubsection">
457 <a name="llvm_eh_sjlj_lsda">llvm.eh.sjlj.lsda</a>
458</div>
459
460<div class="doc_text">
Bill Wendling3cf4ffd2009-08-15 20:07:42 +0000461
Jim Grosbach1b747ad2009-08-11 00:09:57 +0000462<pre>
Bill Wendling3cf4ffd2009-08-15 20:07:42 +0000463 i8* %<a href="#llvm_eh_sjlj_lsda">llvm.eh.sjlj.lsda</a>( )
Jim Grosbach1b747ad2009-08-11 00:09:57 +0000464</pre>
465
466<p>Used for SJLJ based exception handling, the <a href="#llvm_eh_sjlj_lsda">
Bill Wendlingc4f661e2009-08-15 08:56:09 +0000467 <tt>llvm.eh.sjlj.lsda</tt></a> intrinsic returns the address of the Language
468 Specific Data Area (LSDA) for the current function. The SJLJ front-end code
469 stores this address in the exception handling function context for use by the
470 runtime.</p>
Jim Grosbach1b747ad2009-08-11 00:09:57 +0000471
472</div>
473
474<!-- ======================================================================= -->
475<div class="doc_subsubsection">
476 <a name="llvm_eh_sjlj_callsite">llvm.eh.sjlj.callsite</a>
477</div>
478
479<div class="doc_text">
Bill Wendling3cf4ffd2009-08-15 20:07:42 +0000480
Jim Grosbach1b747ad2009-08-11 00:09:57 +0000481<pre>
Bill Wendling3cf4ffd2009-08-15 20:07:42 +0000482 void %<a href="#llvm_eh_sjlj_callsite">llvm.eh.sjlj.callsite</a>(i32)
Jim Grosbach1b747ad2009-08-11 00:09:57 +0000483</pre>
484
Bill Wendlingc4f661e2009-08-15 08:56:09 +0000485<p>The SJLJ front-end allocates call site indices for invoke instrucitons.
486 These values are passed to the back-end via the
487 <a href="#llvm_eh_sjlj_callsite"><tt>llvm.eh.sjlj.callsite</tt></a>
488 intrinsic, where they are used to build the LSDA call-site table.</p>
Jim Grosbach1b747ad2009-08-11 00:09:57 +0000489
490</div>
491
492<!-- ======================================================================= -->
Jim Laskeyd0d39b62007-03-14 19:29:42 +0000493<div class="doc_section">
494 <a name="asm">Asm Table Formats</a>
495</div>
496
497<div class="doc_text">
498
499<p>There are two tables that are used by the exception handling runtime to
Bill Wendlingc4f661e2009-08-15 08:56:09 +0000500 determine which actions should take place when an exception is thrown.</p>
Jim Laskeyd0d39b62007-03-14 19:29:42 +0000501
502</div>
503
504<!-- ======================================================================= -->
505<div class="doc_subsection">
506 <a name="unwind_tables">Exception Handling Frame</a>
507</div>
508
509<div class="doc_text">
510
511<p>An exception handling frame <tt>eh_frame</tt> is very similar to the unwind
Bill Wendlingc4f661e2009-08-15 08:56:09 +0000512 frame used by dwarf debug info. The frame contains all the information
513 necessary to tear down the current frame and restore the state of the prior
514 frame. There is an exception handling frame for each function in a compile
515 unit, plus a common exception handling frame that defines information common
516 to all functions in the unit.</p>
Jim Laskeyd0d39b62007-03-14 19:29:42 +0000517
518<p>Todo - Table details here.</p>
519
520</div>
521
522<!-- ======================================================================= -->
523<div class="doc_subsection">
524 <a name="exception_tables">Exception Tables</a>
525</div>
526
527<div class="doc_text">
528
529<p>An exception table contains information about what actions to take when an
Bill Wendlingc4f661e2009-08-15 08:56:09 +0000530 exception is thrown in a particular part of a function's code. There is one
531 exception table per function except leaf routines and functions that have
532 only calls to non-throwing functions will not need an exception table.</p>
Jim Laskeyd0d39b62007-03-14 19:29:42 +0000533
534<p>Todo - Table details here.</p>
535
536</div>
537
538<!-- ======================================================================= -->
539<div class="doc_section">
540 <a name="todo">ToDo</a>
541</div>
542
543<div class="doc_text">
544
545<ol>
546
Bill Wendlingc4f661e2009-08-15 08:56:09 +0000547 <li>Testing/Testing/Testing.</li>
Jim Laskeyd0d39b62007-03-14 19:29:42 +0000548
549</ol>
550
551</div>
552
553<!-- *********************************************************************** -->
554
555<hr>
556<address>
557 <a href="http://jigsaw.w3.org/css-validator/check/referer"><img
Misha Brukman44408702008-12-11 17:34:48 +0000558 src="http://jigsaw.w3.org/css-validator/images/vcss-blue" alt="Valid CSS"></a>
Jim Laskeyd0d39b62007-03-14 19:29:42 +0000559 <a href="http://validator.w3.org/check/referer"><img
Misha Brukman44408702008-12-11 17:34:48 +0000560 src="http://www.w3.org/Icons/valid-html401-blue" alt="Valid HTML 4.01"></a>
Jim Laskeyd0d39b62007-03-14 19:29:42 +0000561
562 <a href="mailto:sabre@nondot.org">Chris Lattner</a><br>
563 <a href="http://llvm.org">LLVM Compiler Infrastructure</a><br>
564 Last modified: $Date$
565</address>
566
567</body>
568</html>