Exception-Handling.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <!-- Copyright (C) 1988-2017 Free Software Foundation, Inc.
  4. Permission is granted to copy, distribute and/or modify this document
  5. under the terms of the GNU Free Documentation License, Version 1.3 or
  6. any later version published by the Free Software Foundation; with the
  7. Invariant Sections being "Funding Free Software", the Front-Cover
  8. Texts being (a) (see below), and with the Back-Cover Texts being (b)
  9. (see below). A copy of the license is included in the section entitled
  10. "GNU Free Documentation License".
  11. (a) The FSF's Front-Cover Text is:
  12. A GNU Manual
  13. (b) The FSF's Back-Cover Text is:
  14. You have freedom to copy and modify this GNU Manual, like GNU
  15. software. Copies published by the Free Software Foundation raise
  16. funds for GNU development. -->
  17. <!-- Created by GNU Texinfo 5.2, http://www.gnu.org/software/texinfo/ -->
  18. <head>
  19. <title>GNU Compiler Collection (GCC) Internals: Exception Handling</title>
  20. <meta name="description" content="GNU Compiler Collection (GCC) Internals: Exception Handling">
  21. <meta name="keywords" content="GNU Compiler Collection (GCC) Internals: Exception Handling">
  22. <meta name="resource-type" content="document">
  23. <meta name="distribution" content="global">
  24. <meta name="Generator" content="makeinfo">
  25. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  26. <link href="index.html#Top" rel="start" title="Top">
  27. <link href="Option-Index.html#Option-Index" rel="index" title="Option Index">
  28. <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
  29. <link href="Stack-and-Calling.html#Stack-and-Calling" rel="up" title="Stack and Calling">
  30. <link href="Stack-Checking.html#Stack-Checking" rel="next" title="Stack Checking">
  31. <link href="Frame-Layout.html#Frame-Layout" rel="prev" title="Frame Layout">
  32. <style type="text/css">
  33. <!--
  34. a.summary-letter {text-decoration: none}
  35. blockquote.smallquotation {font-size: smaller}
  36. div.display {margin-left: 3.2em}
  37. div.example {margin-left: 3.2em}
  38. div.indentedblock {margin-left: 3.2em}
  39. div.lisp {margin-left: 3.2em}
  40. div.smalldisplay {margin-left: 3.2em}
  41. div.smallexample {margin-left: 3.2em}
  42. div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
  43. div.smalllisp {margin-left: 3.2em}
  44. kbd {font-style:oblique}
  45. pre.display {font-family: inherit}
  46. pre.format {font-family: inherit}
  47. pre.menu-comment {font-family: serif}
  48. pre.menu-preformatted {font-family: serif}
  49. pre.smalldisplay {font-family: inherit; font-size: smaller}
  50. pre.smallexample {font-size: smaller}
  51. pre.smallformat {font-family: inherit; font-size: smaller}
  52. pre.smalllisp {font-size: smaller}
  53. span.nocodebreak {white-space:nowrap}
  54. span.nolinebreak {white-space:nowrap}
  55. span.roman {font-family:serif; font-weight:normal}
  56. span.sansserif {font-family:sans-serif; font-weight:normal}
  57. ul.no-bullet {list-style: none}
  58. -->
  59. </style>
  60. </head>
  61. <body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
  62. <a name="Exception-Handling"></a>
  63. <div class="header">
  64. <p>
  65. Next: <a href="Stack-Checking.html#Stack-Checking" accesskey="n" rel="next">Stack Checking</a>, Previous: <a href="Frame-Layout.html#Frame-Layout" accesskey="p" rel="prev">Frame Layout</a>, Up: <a href="Stack-and-Calling.html#Stack-and-Calling" accesskey="u" rel="up">Stack and Calling</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html#Option-Index" title="Index" rel="index">Index</a>]</p>
  66. </div>
  67. <hr>
  68. <a name="Exception-Handling-Support"></a>
  69. <h4 class="subsection">17.9.2 Exception Handling Support</h4>
  70. <a name="index-exception-handling-1"></a>
  71. <dl>
  72. <dt><a name="index-EH_005fRETURN_005fDATA_005fREGNO"></a>Macro: <strong>EH_RETURN_DATA_REGNO</strong> <em>(<var>N</var>)</em></dt>
  73. <dd><p>A C expression whose value is the <var>N</var>th register number used for
  74. data by exception handlers, or <code>INVALID_REGNUM</code> if fewer than
  75. <var>N</var> registers are usable.
  76. </p>
  77. <p>The exception handling library routines communicate with the exception
  78. handlers via a set of agreed upon registers. Ideally these registers
  79. should be call-clobbered; it is possible to use call-saved registers,
  80. but may negatively impact code size. The target must support at least
  81. 2 data registers, but should define 4 if there are enough free registers.
  82. </p>
  83. <p>You must define this macro if you want to support call frame exception
  84. handling like that provided by DWARF 2.
  85. </p></dd></dl>
  86. <dl>
  87. <dt><a name="index-EH_005fRETURN_005fSTACKADJ_005fRTX"></a>Macro: <strong>EH_RETURN_STACKADJ_RTX</strong></dt>
  88. <dd><p>A C expression whose value is RTL representing a location in which
  89. to store a stack adjustment to be applied before function return.
  90. This is used to unwind the stack to an exception handler&rsquo;s call frame.
  91. It will be assigned zero on code paths that return normally.
  92. </p>
  93. <p>Typically this is a call-clobbered hard register that is otherwise
  94. untouched by the epilogue, but could also be a stack slot.
  95. </p>
  96. <p>Do not define this macro if the stack pointer is saved and restored
  97. by the regular prolog and epilog code in the call frame itself; in
  98. this case, the exception handling library routines will update the
  99. stack location to be restored in place. Otherwise, you must define
  100. this macro if you want to support call frame exception handling like
  101. that provided by DWARF 2.
  102. </p></dd></dl>
  103. <dl>
  104. <dt><a name="index-EH_005fRETURN_005fHANDLER_005fRTX"></a>Macro: <strong>EH_RETURN_HANDLER_RTX</strong></dt>
  105. <dd><p>A C expression whose value is RTL representing a location in which
  106. to store the address of an exception handler to which we should
  107. return. It will not be assigned on code paths that return normally.
  108. </p>
  109. <p>Typically this is the location in the call frame at which the normal
  110. return address is stored. For targets that return by popping an
  111. address off the stack, this might be a memory address just below
  112. the <em>target</em> call frame rather than inside the current call
  113. frame. If defined, <code>EH_RETURN_STACKADJ_RTX</code> will have already
  114. been assigned, so it may be used to calculate the location of the
  115. target call frame.
  116. </p>
  117. <p>Some targets have more complex requirements than storing to an
  118. address calculable during initial code generation. In that case
  119. the <code>eh_return</code> instruction pattern should be used instead.
  120. </p>
  121. <p>If you want to support call frame exception handling, you must
  122. define either this macro or the <code>eh_return</code> instruction pattern.
  123. </p></dd></dl>
  124. <dl>
  125. <dt><a name="index-RETURN_005fADDR_005fOFFSET"></a>Macro: <strong>RETURN_ADDR_OFFSET</strong></dt>
  126. <dd><p>If defined, an integer-valued C expression for which rtl will be generated
  127. to add it to the exception handler address before it is searched in the
  128. exception handling tables, and to subtract it again from the address before
  129. using it to return to the exception handler.
  130. </p></dd></dl>
  131. <dl>
  132. <dt><a name="index-ASM_005fPREFERRED_005fEH_005fDATA_005fFORMAT"></a>Macro: <strong>ASM_PREFERRED_EH_DATA_FORMAT</strong> <em>(<var>code</var>, <var>global</var>)</em></dt>
  133. <dd><p>This macro chooses the encoding of pointers embedded in the exception
  134. handling sections. If at all possible, this should be defined such
  135. that the exception handling section will not require dynamic relocations,
  136. and so may be read-only.
  137. </p>
  138. <p><var>code</var> is 0 for data, 1 for code labels, 2 for function pointers.
  139. <var>global</var> is true if the symbol may be affected by dynamic relocations.
  140. The macro should return a combination of the <code>DW_EH_PE_*</code> defines
  141. as found in <samp>dwarf2.h</samp>.
  142. </p>
  143. <p>If this macro is not defined, pointers will not be encoded but
  144. represented directly.
  145. </p></dd></dl>
  146. <dl>
  147. <dt><a name="index-ASM_005fMAYBE_005fOUTPUT_005fENCODED_005fADDR_005fRTX"></a>Macro: <strong>ASM_MAYBE_OUTPUT_ENCODED_ADDR_RTX</strong> <em>(<var>file</var>, <var>encoding</var>, <var>size</var>, <var>addr</var>, <var>done</var>)</em></dt>
  148. <dd><p>This macro allows the target to emit whatever special magic is required
  149. to represent the encoding chosen by <code>ASM_PREFERRED_EH_DATA_FORMAT</code>.
  150. Generic code takes care of pc-relative and indirect encodings; this must
  151. be defined if the target uses text-relative or data-relative encodings.
  152. </p>
  153. <p>This is a C statement that branches to <var>done</var> if the format was
  154. handled. <var>encoding</var> is the format chosen, <var>size</var> is the number
  155. of bytes that the format occupies, <var>addr</var> is the <code>SYMBOL_REF</code>
  156. to be emitted.
  157. </p></dd></dl>
  158. <dl>
  159. <dt><a name="index-MD_005fFALLBACK_005fFRAME_005fSTATE_005fFOR"></a>Macro: <strong>MD_FALLBACK_FRAME_STATE_FOR</strong> <em>(<var>context</var>, <var>fs</var>)</em></dt>
  160. <dd><p>This macro allows the target to add CPU and operating system specific
  161. code to the call-frame unwinder for use when there is no unwind data
  162. available. The most common reason to implement this macro is to unwind
  163. through signal frames.
  164. </p>
  165. <p>This macro is called from <code>uw_frame_state_for</code> in
  166. <samp>unwind-dw2.c</samp>, <samp>unwind-dw2-xtensa.c</samp> and
  167. <samp>unwind-ia64.c</samp>. <var>context</var> is an <code>_Unwind_Context</code>;
  168. <var>fs</var> is an <code>_Unwind_FrameState</code>. Examine <code>context-&gt;ra</code>
  169. for the address of the code being executed and <code>context-&gt;cfa</code> for
  170. the stack pointer value. If the frame can be decoded, the register
  171. save addresses should be updated in <var>fs</var> and the macro should
  172. evaluate to <code>_URC_NO_REASON</code>. If the frame cannot be decoded,
  173. the macro should evaluate to <code>_URC_END_OF_STACK</code>.
  174. </p>
  175. <p>For proper signal handling in Java this macro is accompanied by
  176. <code>MAKE_THROW_FRAME</code>, defined in <samp>libjava/include/*-signal.h</samp> headers.
  177. </p></dd></dl>
  178. <dl>
  179. <dt><a name="index-MD_005fHANDLE_005fUNWABI"></a>Macro: <strong>MD_HANDLE_UNWABI</strong> <em>(<var>context</var>, <var>fs</var>)</em></dt>
  180. <dd><p>This macro allows the target to add operating system specific code to the
  181. call-frame unwinder to handle the IA-64 <code>.unwabi</code> unwinding directive,
  182. usually used for signal or interrupt frames.
  183. </p>
  184. <p>This macro is called from <code>uw_update_context</code> in libgcc&rsquo;s
  185. <samp>unwind-ia64.c</samp>. <var>context</var> is an <code>_Unwind_Context</code>;
  186. <var>fs</var> is an <code>_Unwind_FrameState</code>. Examine <code>fs-&gt;unwabi</code>
  187. for the abi and context in the <code>.unwabi</code> directive. If the
  188. <code>.unwabi</code> directive can be handled, the register save addresses should
  189. be updated in <var>fs</var>.
  190. </p></dd></dl>
  191. <dl>
  192. <dt><a name="index-TARGET_005fUSES_005fWEAK_005fUNWIND_005fINFO"></a>Macro: <strong>TARGET_USES_WEAK_UNWIND_INFO</strong></dt>
  193. <dd><p>A C expression that evaluates to true if the target requires unwind
  194. info to be given comdat linkage. Define it to be <code>1</code> if comdat
  195. linkage is necessary. The default is <code>0</code>.
  196. </p></dd></dl>
  197. <hr>
  198. <div class="header">
  199. <p>
  200. Next: <a href="Stack-Checking.html#Stack-Checking" accesskey="n" rel="next">Stack Checking</a>, Previous: <a href="Frame-Layout.html#Frame-Layout" accesskey="p" rel="prev">Frame Layout</a>, Up: <a href="Stack-and-Calling.html#Stack-and-Calling" accesskey="u" rel="up">Stack and Calling</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html#Option-Index" title="Index" rel="index">Index</a>]</p>
  201. </div>
  202. </body>
  203. </html>