Stack-Checking.html 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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: Stack Checking</title>
  20. <meta name="description" content="GNU Compiler Collection (GCC) Internals: Stack Checking">
  21. <meta name="keywords" content="GNU Compiler Collection (GCC) Internals: Stack Checking">
  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="Frame-Registers.html#Frame-Registers" rel="next" title="Frame Registers">
  31. <link href="Exception-Handling.html#Exception-Handling" rel="prev" title="Exception Handling">
  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="Stack-Checking"></a>
  63. <div class="header">
  64. <p>
  65. Next: <a href="Frame-Registers.html#Frame-Registers" accesskey="n" rel="next">Frame Registers</a>, Previous: <a href="Exception-Handling.html#Exception-Handling" accesskey="p" rel="prev">Exception Handling</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="Specifying-How-Stack-Checking-is-Done"></a>
  69. <h4 class="subsection">17.9.3 Specifying How Stack Checking is Done</h4>
  70. <p>GCC will check that stack references are within the boundaries of the
  71. stack, if the option <samp>-fstack-check</samp> is specified, in one of
  72. three ways:
  73. </p>
  74. <ol>
  75. <li> If the value of the <code>STACK_CHECK_BUILTIN</code> macro is nonzero, GCC
  76. will assume that you have arranged for full stack checking to be done
  77. at appropriate places in the configuration files. GCC will not do
  78. other special processing.
  79. </li><li> If <code>STACK_CHECK_BUILTIN</code> is zero and the value of the
  80. <code>STACK_CHECK_STATIC_BUILTIN</code> macro is nonzero, GCC will assume
  81. that you have arranged for static stack checking (checking of the
  82. static stack frame of functions) to be done at appropriate places
  83. in the configuration files. GCC will only emit code to do dynamic
  84. stack checking (checking on dynamic stack allocations) using the third
  85. approach below.
  86. </li><li> If neither of the above are true, GCC will generate code to periodically
  87. &ldquo;probe&rdquo; the stack pointer using the values of the macros defined below.
  88. </li></ol>
  89. <p>If neither STACK_CHECK_BUILTIN nor STACK_CHECK_STATIC_BUILTIN is defined,
  90. GCC will change its allocation strategy for large objects if the option
  91. <samp>-fstack-check</samp> is specified: they will always be allocated
  92. dynamically if their size exceeds <code>STACK_CHECK_MAX_VAR_SIZE</code> bytes.
  93. </p>
  94. <dl>
  95. <dt><a name="index-STACK_005fCHECK_005fBUILTIN"></a>Macro: <strong>STACK_CHECK_BUILTIN</strong></dt>
  96. <dd><p>A nonzero value if stack checking is done by the configuration files in a
  97. machine-dependent manner. You should define this macro if stack checking
  98. is required by the ABI of your machine or if you would like to do stack
  99. checking in some more efficient way than the generic approach. The default
  100. value of this macro is zero.
  101. </p></dd></dl>
  102. <dl>
  103. <dt><a name="index-STACK_005fCHECK_005fSTATIC_005fBUILTIN"></a>Macro: <strong>STACK_CHECK_STATIC_BUILTIN</strong></dt>
  104. <dd><p>A nonzero value if static stack checking is done by the configuration files
  105. in a machine-dependent manner. You should define this macro if you would
  106. like to do static stack checking in some more efficient way than the generic
  107. approach. The default value of this macro is zero.
  108. </p></dd></dl>
  109. <dl>
  110. <dt><a name="index-STACK_005fCHECK_005fPROBE_005fINTERVAL_005fEXP"></a>Macro: <strong>STACK_CHECK_PROBE_INTERVAL_EXP</strong></dt>
  111. <dd><p>An integer specifying the interval at which GCC must generate stack probe
  112. instructions, defined as 2 raised to this integer. You will normally
  113. define this macro so that the interval be no larger than the size of
  114. the &ldquo;guard pages&rdquo; at the end of a stack area. The default value
  115. of 12 (4096-byte interval) is suitable for most systems.
  116. </p></dd></dl>
  117. <dl>
  118. <dt><a name="index-STACK_005fCHECK_005fMOVING_005fSP"></a>Macro: <strong>STACK_CHECK_MOVING_SP</strong></dt>
  119. <dd><p>An integer which is nonzero if GCC should move the stack pointer page by page
  120. when doing probes. This can be necessary on systems where the stack pointer
  121. contains the bottom address of the memory area accessible to the executing
  122. thread at any point in time. In this situation an alternate signal stack
  123. is required in order to be able to recover from a stack overflow. The
  124. default value of this macro is zero.
  125. </p></dd></dl>
  126. <dl>
  127. <dt><a name="index-STACK_005fCHECK_005fPROTECT"></a>Macro: <strong>STACK_CHECK_PROTECT</strong></dt>
  128. <dd><p>The number of bytes of stack needed to recover from a stack overflow, for
  129. languages where such a recovery is supported. The default value of 4KB/8KB
  130. with the <code>setjmp</code>/<code>longjmp</code>-based exception handling mechanism and
  131. 8KB/12KB with other exception handling mechanisms should be adequate for most
  132. architectures and operating systems.
  133. </p></dd></dl>
  134. <p>The following macros are relevant only if neither STACK_CHECK_BUILTIN
  135. nor STACK_CHECK_STATIC_BUILTIN is defined; you can omit them altogether
  136. in the opposite case.
  137. </p>
  138. <dl>
  139. <dt><a name="index-STACK_005fCHECK_005fMAX_005fFRAME_005fSIZE"></a>Macro: <strong>STACK_CHECK_MAX_FRAME_SIZE</strong></dt>
  140. <dd><p>The maximum size of a stack frame, in bytes. GCC will generate probe
  141. instructions in non-leaf functions to ensure at least this many bytes of
  142. stack are available. If a stack frame is larger than this size, stack
  143. checking will not be reliable and GCC will issue a warning. The
  144. default is chosen so that GCC only generates one instruction on most
  145. systems. You should normally not change the default value of this macro.
  146. </p></dd></dl>
  147. <dl>
  148. <dt><a name="index-STACK_005fCHECK_005fFIXED_005fFRAME_005fSIZE"></a>Macro: <strong>STACK_CHECK_FIXED_FRAME_SIZE</strong></dt>
  149. <dd><p>GCC uses this value to generate the above warning message. It
  150. represents the amount of fixed frame used by a function, not including
  151. space for any callee-saved registers, temporaries and user variables.
  152. You need only specify an upper bound for this amount and will normally
  153. use the default of four words.
  154. </p></dd></dl>
  155. <dl>
  156. <dt><a name="index-STACK_005fCHECK_005fMAX_005fVAR_005fSIZE"></a>Macro: <strong>STACK_CHECK_MAX_VAR_SIZE</strong></dt>
  157. <dd><p>The maximum size, in bytes, of an object that GCC will place in the
  158. fixed area of the stack frame when the user specifies
  159. <samp>-fstack-check</samp>.
  160. GCC computed the default from the values of the above macros and you will
  161. normally not need to override that default.
  162. </p></dd></dl>
  163. <hr>
  164. <div class="header">
  165. <p>
  166. Next: <a href="Frame-Registers.html#Frame-Registers" accesskey="n" rel="next">Frame Registers</a>, Previous: <a href="Exception-Handling.html#Exception-Handling" accesskey="p" rel="prev">Exception Handling</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>
  167. </div>
  168. </body>
  169. </html>