• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1==========================
2Exception Handling in LLVM
3==========================
4
5.. contents::
6   :local:
7
8Introduction
9============
10
11This document is the central repository for all information pertaining to
12exception handling in LLVM.  It describes the format that LLVM exception
13handling information takes, which is useful for those interested in creating
14front-ends or dealing directly with the information.  Further, this document
15provides specific examples of what exception handling information is used for in
16C and C++.
17
18Itanium ABI Zero-cost Exception Handling
19----------------------------------------
20
21Exception handling for most programming languages is designed to recover from
22conditions that rarely occur during general use of an application.  To that end,
23exception handling should not interfere with the main flow of an application's
24algorithm by performing checkpointing tasks, such as saving the current pc or
25register state.
26
27The Itanium ABI Exception Handling Specification defines a methodology for
28providing outlying data in the form of exception tables without inlining
29speculative exception handling code in the flow of an application's main
30algorithm.  Thus, the specification is said to add "zero-cost" to the normal
31execution of an application.
32
33A more complete description of the Itanium ABI exception handling runtime
34support of can be found at `Itanium C++ ABI: Exception Handling
35<http://mentorembedded.github.com/cxx-abi/abi-eh.html>`_. A description of the
36exception frame format can be found at `Exception Frames
37<http://refspecs.linuxfoundation.org/LSB_3.0.0/LSB-Core-generic/LSB-Core-generic/ehframechpt.html>`_,
38with details of the DWARF 4 specification at `DWARF 4 Standard
39<http://dwarfstd.org/Dwarf4Std.php>`_.  A description for the C++ exception
40table formats can be found at `Exception Handling Tables
41<http://mentorembedded.github.com/cxx-abi/exceptions.pdf>`_.
42
43Setjmp/Longjmp Exception Handling
44---------------------------------
45
46Setjmp/Longjmp (SJLJ) based exception handling uses LLVM intrinsics
47`llvm.eh.sjlj.setjmp`_ and `llvm.eh.sjlj.longjmp`_ to handle control flow for
48exception handling.
49
50For each function which does exception processing --- be it ``try``/``catch``
51blocks or cleanups --- that function registers itself on a global frame
52list. When exceptions are unwinding, the runtime uses this list to identify
53which functions need processing.
54
55Landing pad selection is encoded in the call site entry of the function
56context. The runtime returns to the function via `llvm.eh.sjlj.longjmp`_, where
57a switch table transfers control to the appropriate landing pad based on the
58index stored in the function context.
59
60In contrast to DWARF exception handling, which encodes exception regions and
61frame information in out-of-line tables, SJLJ exception handling builds and
62removes the unwind frame context at runtime. This results in faster exception
63handling at the expense of slower execution when no exceptions are thrown. As
64exceptions are, by their nature, intended for uncommon code paths, DWARF
65exception handling is generally preferred to SJLJ.
66
67Windows Runtime Exception Handling
68-----------------------------------
69
70Windows runtime based exception handling uses the same basic IR structure as
71Itanium ABI based exception handling, but it relies on the personality
72functions provided by the native Windows runtime library, ``__CxxFrameHandler3``
73for C++ exceptions: ``__C_specific_handler`` for 64-bit SEH or
74``_frame_handler3/4`` for 32-bit SEH.  This results in a very different
75execution model and requires some minor modifications to the initial IR
76representation and a significant restructuring just before code generation.
77
78General information about the Windows x64 exception handling mechanism can be
79found at `MSDN Exception Handling (x64)
80<https://msdn.microsoft.com/en-us/library/1eyas8tf(v=vs.80).aspx>`_.
81
82Overview
83--------
84
85When an exception is thrown in LLVM code, the runtime does its best to find a
86handler suited to processing the circumstance.
87
88The runtime first attempts to find an *exception frame* corresponding to the
89function where the exception was thrown.  If the programming language supports
90exception handling (e.g. C++), the exception frame contains a reference to an
91exception table describing how to process the exception.  If the language does
92not support exception handling (e.g. C), or if the exception needs to be
93forwarded to a prior activation, the exception frame contains information about
94how to unwind the current activation and restore the state of the prior
95activation.  This process is repeated until the exception is handled. If the
96exception is not handled and no activations remain, then the application is
97terminated with an appropriate error message.
98
99Because different programming languages have different behaviors when handling
100exceptions, the exception handling ABI provides a mechanism for
101supplying *personalities*. An exception handling personality is defined by
102way of a *personality function* (e.g. ``__gxx_personality_v0`` in C++),
103which receives the context of the exception, an *exception structure*
104containing the exception object type and value, and a reference to the exception
105table for the current function.  The personality function for the current
106compile unit is specified in a *common exception frame*.
107
108The organization of an exception table is language dependent. For C++, an
109exception table is organized as a series of code ranges defining what to do if
110an exception occurs in that range. Typically, the information associated with a
111range defines which types of exception objects (using C++ *type info*) that are
112handled in that range, and an associated action that should take place. Actions
113typically pass control to a *landing pad*.
114
115A landing pad corresponds roughly to the code found in the ``catch`` portion of
116a ``try``/``catch`` sequence. When execution resumes at a landing pad, it
117receives an *exception structure* and a *selector value* corresponding to the
118*type* of exception thrown. The selector is then used to determine which *catch*
119should actually process the exception.
120
121LLVM Code Generation
122====================
123
124From a C++ developer's perspective, exceptions are defined in terms of the
125``throw`` and ``try``/``catch`` statements. In this section we will describe the
126implementation of LLVM exception handling in terms of C++ examples.
127
128Throw
129-----
130
131Languages that support exception handling typically provide a ``throw``
132operation to initiate the exception process. Internally, a ``throw`` operation
133breaks down into two steps.
134
135#. A request is made to allocate exception space for an exception structure.
136   This structure needs to survive beyond the current activation. This structure
137   will contain the type and value of the object being thrown.
138
139#. A call is made to the runtime to raise the exception, passing the exception
140   structure as an argument.
141
142In C++, the allocation of the exception structure is done by the
143``__cxa_allocate_exception`` runtime function. The exception raising is handled
144by ``__cxa_throw``. The type of the exception is represented using a C++ RTTI
145structure.
146
147Try/Catch
148---------
149
150A call within the scope of a *try* statement can potentially raise an
151exception. In those circumstances, the LLVM C++ front-end replaces the call with
152an ``invoke`` instruction. Unlike a call, the ``invoke`` has two potential
153continuation points:
154
155#. where to continue when the call succeeds as per normal, and
156
157#. where to continue if the call raises an exception, either by a throw or the
158   unwinding of a throw
159
160The term used to define the place where an ``invoke`` continues after an
161exception is called a *landing pad*. LLVM landing pads are conceptually
162alternative function entry points where an exception structure reference and a
163type info index are passed in as arguments. The landing pad saves the exception
164structure reference and then proceeds to select the catch block that corresponds
165to the type info of the exception object.
166
167The LLVM :ref:`i_landingpad` is used to convey information about the landing
168pad to the back end. For C++, the ``landingpad`` instruction returns a pointer
169and integer pair corresponding to the pointer to the *exception structure* and
170the *selector value* respectively.
171
172The ``landingpad`` instruction takes a reference to the personality function to
173be used for this ``try``/``catch`` sequence. The remainder of the instruction is
174a list of *cleanup*, *catch*, and *filter* clauses. The exception is tested
175against the clauses sequentially from first to last. The clauses have the
176following meanings:
177
178-  ``catch <type> @ExcType``
179
180   - This clause means that the landingpad block should be entered if the
181     exception being thrown is of type ``@ExcType`` or a subtype of
182     ``@ExcType``. For C++, ``@ExcType`` is a pointer to the ``std::type_info``
183     object (an RTTI object) representing the C++ exception type.
184
185   - If ``@ExcType`` is ``null``, any exception matches, so the landingpad
186     should always be entered. This is used for C++ catch-all blocks ("``catch
187     (...)``").
188
189   - When this clause is matched, the selector value will be equal to the value
190     returned by "``@llvm.eh.typeid.for(i8* @ExcType)``". This will always be a
191     positive value.
192
193-  ``filter <type> [<type> @ExcType1, ..., <type> @ExcTypeN]``
194
195   - This clause means that the landingpad should be entered if the exception
196     being thrown does *not* match any of the types in the list (which, for C++,
197     are again specified as ``std::type_info`` pointers).
198
199   - C++ front-ends use this to implement C++ exception specifications, such as
200     "``void foo() throw (ExcType1, ..., ExcTypeN) { ... }``".
201
202   - When this clause is matched, the selector value will be negative.
203
204   - The array argument to ``filter`` may be empty; for example, "``[0 x i8**]
205     undef``". This means that the landingpad should always be entered. (Note
206     that such a ``filter`` would not be equivalent to "``catch i8* null``",
207     because ``filter`` and ``catch`` produce negative and positive selector
208     values respectively.)
209
210-  ``cleanup``
211
212   - This clause means that the landingpad should always be entered.
213
214   - C++ front-ends use this for calling objects' destructors.
215
216   - When this clause is matched, the selector value will be zero.
217
218   - The runtime may treat "``cleanup``" differently from "``catch <type>
219     null``".
220
221     In C++, if an unhandled exception occurs, the language runtime will call
222     ``std::terminate()``, but it is implementation-defined whether the runtime
223     unwinds the stack and calls object destructors first. For example, the GNU
224     C++ unwinder does not call object destructors when an unhandled exception
225     occurs. The reason for this is to improve debuggability: it ensures that
226     ``std::terminate()`` is called from the context of the ``throw``, so that
227     this context is not lost by unwinding the stack. A runtime will typically
228     implement this by searching for a matching non-``cleanup`` clause, and
229     aborting if it does not find one, before entering any landingpad blocks.
230
231Once the landing pad has the type info selector, the code branches to the code
232for the first catch. The catch then checks the value of the type info selector
233against the index of type info for that catch.  Since the type info index is not
234known until all the type infos have been gathered in the backend, the catch code
235must call the `llvm.eh.typeid.for`_ intrinsic to determine the index for a given
236type info. If the catch fails to match the selector then control is passed on to
237the next catch.
238
239Finally, the entry and exit of catch code is bracketed with calls to
240``__cxa_begin_catch`` and ``__cxa_end_catch``.
241
242* ``__cxa_begin_catch`` takes an exception structure reference as an argument
243  and returns the value of the exception object.
244
245* ``__cxa_end_catch`` takes no arguments. This function:
246
247  #. Locates the most recently caught exception and decrements its handler
248     count,
249
250  #. Removes the exception from the *caught* stack if the handler count goes to
251     zero, and
252
253  #. Destroys the exception if the handler count goes to zero and the exception
254     was not re-thrown by throw.
255
256  .. note::
257
258    a rethrow from within the catch may replace this call with a
259    ``__cxa_rethrow``.
260
261Cleanups
262--------
263
264A cleanup is extra code which needs to be run as part of unwinding a scope.  C++
265destructors are a typical example, but other languages and language extensions
266provide a variety of different kinds of cleanups. In general, a landing pad may
267need to run arbitrary amounts of cleanup code before actually entering a catch
268block. To indicate the presence of cleanups, a :ref:`i_landingpad` should have
269a *cleanup* clause.  Otherwise, the unwinder will not stop at the landing pad if
270there are no catches or filters that require it to.
271
272.. note::
273
274  Do not allow a new exception to propagate out of the execution of a
275  cleanup. This can corrupt the internal state of the unwinder.  Different
276  languages describe different high-level semantics for these situations: for
277  example, C++ requires that the process be terminated, whereas Ada cancels both
278  exceptions and throws a third.
279
280When all cleanups are finished, if the exception is not handled by the current
281function, resume unwinding by calling the :ref:`resume instruction <i_resume>`,
282passing in the result of the ``landingpad`` instruction for the original
283landing pad.
284
285Throw Filters
286-------------
287
288C++ allows the specification of which exception types may be thrown from a
289function. To represent this, a top level landing pad may exist to filter out
290invalid types. To express this in LLVM code the :ref:`i_landingpad` will have a
291filter clause. The clause consists of an array of type infos.
292``landingpad`` will return a negative value
293if the exception does not match any of the type infos. If no match is found then
294a call to ``__cxa_call_unexpected`` should be made, otherwise
295``_Unwind_Resume``.  Each of these functions requires a reference to the
296exception structure.  Note that the most general form of a ``landingpad``
297instruction can have any number of catch, cleanup, and filter clauses (though
298having more than one cleanup is pointless). The LLVM C++ front-end can generate
299such ``landingpad`` instructions due to inlining creating nested exception
300handling scopes.
301
302.. _undefined:
303
304Restrictions
305------------
306
307The unwinder delegates the decision of whether to stop in a call frame to that
308call frame's language-specific personality function. Not all unwinders guarantee
309that they will stop to perform cleanups. For example, the GNU C++ unwinder
310doesn't do so unless the exception is actually caught somewhere further up the
311stack.
312
313In order for inlining to behave correctly, landing pads must be prepared to
314handle selector results that they did not originally advertise. Suppose that a
315function catches exceptions of type ``A``, and it's inlined into a function that
316catches exceptions of type ``B``. The inliner will update the ``landingpad``
317instruction for the inlined landing pad to include the fact that ``B`` is also
318caught. If that landing pad assumes that it will only be entered to catch an
319``A``, it's in for a rude awakening.  Consequently, landing pads must test for
320the selector results they understand and then resume exception propagation with
321the `resume instruction <LangRef.html#i_resume>`_ if none of the conditions
322match.
323
324C++ Exception Handling using the Windows Runtime
325=================================================
326
327(Note: Windows C++ exception handling support is a work in progress and is
328 not yet fully implemented.  The text below describes how it will work
329 when completed.)
330
331The Windows runtime function for C++ exception handling uses a multi-phase
332approach.  When an exception occurs it searches the current callstack for a
333frame that has a handler for the exception.  If a handler is found, it then
334calls the cleanup handler for each frame above the handler which has a
335cleanup handler before calling the catch handler.  These calls are all made
336from a stack context different from the original frame in which the handler
337is defined.  Therefore, it is necessary to outline these handlers from their
338original context before code generation.
339
340Catch handlers are called with a pointer to the handler itself as the first
341argument and a pointer to the parent function's stack frame as the second
342argument.  The catch handler uses the `llvm.recoverframe
343<LangRef.html#llvm-frameallocate-and-llvm-framerecover-intrinsics>`_ to get a
344pointer to a frame allocation block that is created in the parent frame using
345the `llvm.allocateframe
346<LangRef.html#llvm-frameallocate-and-llvm-framerecover-intrinsics>`_ intrinsic.
347The ``WinEHPrepare`` pass will have created a structure definition for the
348contents of this block.  The first two members of the structure will always be
349(1) a 32-bit integer that the runtime uses to track the exception state of the
350parent frame for the purposes of handling chained exceptions and (2) a pointer
351to the object associated with the exception (roughly, the parameter of the
352catch clause). These two members will be followed by any frame variables from
353the parent function which must be accessed in any of the functions unwind or
354catch handlers.  The catch handler returns the address at which execution
355should continue.
356
357Cleanup handlers perform any cleanup necessary as the frame goes out of scope,
358such as calling object destructors.  The runtime handles the actual unwinding
359of the stack.  If an exception occurs in a cleanup handler the runtime manages
360termination of the process. Cleanup handlers are called with the same arguments
361as catch handlers (a pointer to the handler and a pointer to the parent stack
362frame) and use the same mechanism described above to access frame variables
363in the parent function.  Cleanup handlers do not return a value.
364
365The IR generated for Windows runtime based C++ exception handling is initially
366very similar to the ``landingpad`` mechanism described above.  Calls to
367libc++abi functions (such as ``__cxa_begin_catch``/``__cxa_end_catch`` and
368``__cxa_throw_exception`` are replaced with calls to intrinsics or Windows
369runtime functions (such as ``llvm.eh.begincatch``/``llvm.eh.endcatch`` and
370``__CxxThrowException``).
371
372During the WinEHPrepare pass, the handler functions are outlined into handler
373functions and the original landing pad code is replaced with a call to the
374``llvm.eh.actions`` intrinsic that describes the order in which handlers will
375be processed from the logical location of the landing pad and an indirect
376branch to the return value of the ``llvm.eh.actions`` intrinsic. The
377``llvm.eh.actions`` intrinsic is defined as returning the address at which
378execution will continue.  This is a temporary construct which will be removed
379before code generation, but it allows for the accurate tracking of control
380flow until then.
381
382A typical landing pad will look like this after outlining:
383
384.. code-block:: llvm
385
386    lpad:
387      %vals = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*)
388	      cleanup
389          catch i8* bitcast (i8** @_ZTIi to i8*)
390          catch i8* bitcast (i8** @_ZTIf to i8*)
391      %recover = call i8* (...)* @llvm.eh.actions(
392          i32 3, i8* bitcast (i8** @_ZTIi to i8*), i8* (i8*, i8*)* @_Z4testb.catch.1)
393          i32 2, i8* null, void (i8*, i8*)* @_Z4testb.cleanup.1)
394          i32 1, i8* bitcast (i8** @_ZTIf to i8*), i8* (i8*, i8*)* @_Z4testb.catch.0)
395          i32 0, i8* null, void (i8*, i8*)* @_Z4testb.cleanup.0)
396      indirectbr i8* %recover, [label %try.cont1, label %try.cont2]
397
398In this example, the landing pad represents an exception handling context with
399two catch handlers and a cleanup handler that have been outlined.  If an
400exception is thrown with a type that matches ``_ZTIi``, the ``_Z4testb.catch.1``
401handler will be called an no clean-up is needed.  If an exception is thrown
402with a type that matches ``_ZTIf``, first the ``_Z4testb.cleanup.1`` handler
403will be called to perform unwind-related cleanup, then the ``_Z4testb.catch.1``
404handler will be called.  If an exception is throw which does not match either
405of these types and the exception is handled by another frame further up the
406call stack, first the ``_Z4testb.cleanup.1`` handler will be called, then the
407``_Z4testb.cleanup.0`` handler (which corresponds to a different scope) will be
408called, and exception handling will continue at the next frame in the call
409stack will be called.  One of the catch handlers will return the address of
410``%try.cont1`` in the parent function and the other will return the address of
411``%try.cont2``, meaning that execution continues at one of those blocks after
412an exception is caught.
413
414
415Exception Handling Intrinsics
416=============================
417
418In addition to the ``landingpad`` and ``resume`` instructions, LLVM uses several
419intrinsic functions (name prefixed with ``llvm.eh``) to provide exception
420handling information at various points in generated code.
421
422.. _llvm.eh.typeid.for:
423
424``llvm.eh.typeid.for``
425----------------------
426
427.. code-block:: llvm
428
429  i32 @llvm.eh.typeid.for(i8* %type_info)
430
431
432This intrinsic returns the type info index in the exception table of the current
433function.  This value can be used to compare against the result of
434``landingpad`` instruction.  The single argument is a reference to a type info.
435
436Uses of this intrinsic are generated by the C++ front-end.
437
438.. _llvm.eh.begincatch:
439
440``llvm.eh.begincatch``
441----------------------
442
443.. code-block:: llvm
444
445  void @llvm.eh.begincatch(i8* %ehptr, i8* %ehobj)
446
447
448This intrinsic marks the beginning of catch handling code within the blocks
449following a ``landingpad`` instruction.  The exact behavior of this function
450depends on the compilation target and the personality function associated
451with the ``landingpad`` instruction.
452
453The first argument to this intrinsic is a pointer that was previously extracted
454from the aggregate return value of the ``landingpad`` instruction.  The second
455argument to the intrinsic is a pointer to stack space where the exception object
456should be stored. The runtime handles the details of copying the exception
457object into the slot. If the second parameter is null, no copy occurs.
458
459Uses of this intrinsic are generated by the C++ front-end.  Many targets will
460use implementation-specific functions (such as ``__cxa_begin_catch``) instead
461of this intrinsic.  The intrinsic is provided for targets that require a more
462abstract interface.
463
464When used in the native Windows C++ exception handling implementation, this
465intrinsic serves as a placeholder to delimit code before a catch handler is
466outlined.  When the handler is is outlined, this intrinsic will be replaced
467by instructions that retrieve the exception object pointer from the frame
468allocation block.
469
470
471.. _llvm.eh.endcatch:
472
473``llvm.eh.endcatch``
474----------------------
475
476.. code-block:: llvm
477
478  void @llvm.eh.endcatch()
479
480
481This intrinsic marks the end of catch handling code within the current block,
482which will be a successor of a block which called ``llvm.eh.begincatch''.
483The exact behavior of this function depends on the compilation target and the
484personality function associated with the corresponding ``landingpad``
485instruction.
486
487There may be more than one call to ``llvm.eh.endcatch`` for any given call to
488``llvm.eh.begincatch`` with each ``llvm.eh.endcatch`` call corresponding to the
489end of a different control path.  All control paths following a call to
490``llvm.eh.begincatch`` must reach a call to ``llvm.eh.endcatch``.
491
492Uses of this intrinsic are generated by the C++ front-end.  Many targets will
493use implementation-specific functions (such as ``__cxa_begin_catch``) instead
494of this intrinsic.  The intrinsic is provided for targets that require a more
495abstract interface.
496
497When used in the native Windows C++ exception handling implementation, this
498intrinsic serves as a placeholder to delimit code before a catch handler is
499outlined.  After the handler is outlined, this intrinsic is simply removed.
500
501.. _llvm.eh.actions:
502
503``llvm.eh.actions``
504----------------------
505
506.. code-block:: llvm
507
508  void @llvm.eh.actions()
509
510This intrinsic represents the list of actions to take when an exception is
511thrown. It is typically used by Windows exception handling schemes where cleanup
512outlining is required by the runtime. The arguments are a sequence of ``i32``
513sentinels indicating the action type followed by some pre-determined number of
514arguments required to implement that action.
515
516A code of ``i32 0`` indicates a cleanup action, which expects one additional
517argument. The argument is a pointer to a function that implements the cleanup
518action.
519
520A code of ``i32 1`` indicates a catch action, which expects three additional
521arguments. Different EH schemes give different meanings to the three arguments,
522but the first argument indicates whether the catch should fire, the second is
523the frameescape index of the exception object, and the third is the code to run
524to catch the exception.
525
526For Windows C++ exception handling, the first argument for a catch handler is a
527pointer to the RTTI type descriptor for the object to catch. The second
528argument is an index into the argument list of the ``llvm.frameescape`` call in
529the main function. The exception object will be copied into the provided stack
530object. If the exception object is not required, this argument should be -1.
531The third argument is a pointer to a function implementing the catch.  This
532function returns the address of the basic block where execution should resume
533after handling the exception.
534
535For Windows SEH, the first argument is a pointer to the filter function, which
536indicates if the exception should be caught or not.  The second argument is
537typically negative one. The third argument is the address of a basic block
538where the exception will be handled. In other words, catch handlers are not
539outlined in SEH. After running cleanups, execution immediately resumes at this
540PC.
541
542In order to preserve the structure of the CFG, a call to '``llvm.eh.actions``'
543must be followed by an ':ref:`indirectbr <i_indirectbr>`' instruction that
544jumps to the result of the intrinsic call.
545
546
547SJLJ Intrinsics
548---------------
549
550The ``llvm.eh.sjlj`` intrinsics are used internally within LLVM's
551backend.  Uses of them are generated by the backend's
552``SjLjEHPrepare`` pass.
553
554.. _llvm.eh.sjlj.setjmp:
555
556``llvm.eh.sjlj.setjmp``
557~~~~~~~~~~~~~~~~~~~~~~~
558
559.. code-block:: llvm
560
561  i32 @llvm.eh.sjlj.setjmp(i8* %setjmp_buf)
562
563For SJLJ based exception handling, this intrinsic forces register saving for the
564current function and stores the address of the following instruction for use as
565a destination address by `llvm.eh.sjlj.longjmp`_. The buffer format and the
566overall functioning of this intrinsic is compatible with the GCC
567``__builtin_setjmp`` implementation allowing code built with the clang and GCC
568to interoperate.
569
570The single parameter is a pointer to a five word buffer in which the calling
571context is saved. The front end places the frame pointer in the first word, and
572the target implementation of this intrinsic should place the destination address
573for a `llvm.eh.sjlj.longjmp`_ in the second word. The following three words are
574available for use in a target-specific manner.
575
576.. _llvm.eh.sjlj.longjmp:
577
578``llvm.eh.sjlj.longjmp``
579~~~~~~~~~~~~~~~~~~~~~~~~
580
581.. code-block:: llvm
582
583  void @llvm.eh.sjlj.longjmp(i8* %setjmp_buf)
584
585For SJLJ based exception handling, the ``llvm.eh.sjlj.longjmp`` intrinsic is
586used to implement ``__builtin_longjmp()``. The single parameter is a pointer to
587a buffer populated by `llvm.eh.sjlj.setjmp`_. The frame pointer and stack
588pointer are restored from the buffer, then control is transferred to the
589destination address.
590
591``llvm.eh.sjlj.lsda``
592~~~~~~~~~~~~~~~~~~~~~
593
594.. code-block:: llvm
595
596  i8* @llvm.eh.sjlj.lsda()
597
598For SJLJ based exception handling, the ``llvm.eh.sjlj.lsda`` intrinsic returns
599the address of the Language Specific Data Area (LSDA) for the current
600function. The SJLJ front-end code stores this address in the exception handling
601function context for use by the runtime.
602
603``llvm.eh.sjlj.callsite``
604~~~~~~~~~~~~~~~~~~~~~~~~~
605
606.. code-block:: llvm
607
608  void @llvm.eh.sjlj.callsite(i32 %call_site_num)
609
610For SJLJ based exception handling, the ``llvm.eh.sjlj.callsite`` intrinsic
611identifies the callsite value associated with the following ``invoke``
612instruction. This is used to ensure that landing pad entries in the LSDA are
613generated in matching order.
614
615Asm Table Formats
616=================
617
618There are two tables that are used by the exception handling runtime to
619determine which actions should be taken when an exception is thrown.
620
621Exception Handling Frame
622------------------------
623
624An exception handling frame ``eh_frame`` is very similar to the unwind frame
625used by DWARF debug info. The frame contains all the information necessary to
626tear down the current frame and restore the state of the prior frame. There is
627an exception handling frame for each function in a compile unit, plus a common
628exception handling frame that defines information common to all functions in the
629unit.
630
631Exception Tables
632----------------
633
634An exception table contains information about what actions to take when an
635exception is thrown in a particular part of a function's code. There is one
636exception table per function, except leaf functions and functions that have
637calls only to non-throwing functions. They do not need an exception table.
638