You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Stack-Checking.html 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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-2020 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 6.5, http://www.gnu.org/software/texinfo/ -->
  18. <head>
  19. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  20. <title>Stack Checking (GNU Compiler Collection (GCC) Internals)</title>
  21. <meta name="description" content="Stack Checking (GNU Compiler Collection (GCC) Internals)">
  22. <meta name="keywords" content="Stack Checking (GNU Compiler Collection (GCC) Internals)">
  23. <meta name="resource-type" content="document">
  24. <meta name="distribution" content="global">
  25. <meta name="Generator" content="makeinfo">
  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.indentedblock {margin-right: 0em}
  36. blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
  37. blockquote.smallquotation {font-size: smaller}
  38. div.display {margin-left: 3.2em}
  39. div.example {margin-left: 3.2em}
  40. div.lisp {margin-left: 3.2em}
  41. div.smalldisplay {margin-left: 3.2em}
  42. div.smallexample {margin-left: 3.2em}
  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.nolinebreak {white-space: nowrap}
  54. span.roman {font-family: initial; font-weight: normal}
  55. span.sansserif {font-family: sans-serif; font-weight: normal}
  56. ul.no-bullet {list-style: none}
  57. -->
  58. </style>
  59. </head>
  60. <body lang="en">
  61. <a name="Stack-Checking"></a>
  62. <div class="header">
  63. <p>
  64. 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>
  65. </div>
  66. <hr>
  67. <a name="Specifying-How-Stack-Checking-is-Done"></a>
  68. <h4 class="subsection">18.9.3 Specifying How Stack Checking is Done</h4>
  69. <p>GCC will check that stack references are within the boundaries of the
  70. stack, if the option <samp>-fstack-check</samp> is specified, in one of
  71. three ways:
  72. </p>
  73. <ol>
  74. <li> If the value of the <code>STACK_CHECK_BUILTIN</code> macro is nonzero, GCC
  75. will assume that you have arranged for full stack checking to be done
  76. at appropriate places in the configuration files. GCC will not do
  77. other special processing.
  78. </li><li> If <code>STACK_CHECK_BUILTIN</code> is zero and the value of the
  79. <code>STACK_CHECK_STATIC_BUILTIN</code> macro is nonzero, GCC will assume
  80. that you have arranged for static stack checking (checking of the
  81. static stack frame of functions) to be done at appropriate places
  82. in the configuration files. GCC will only emit code to do dynamic
  83. stack checking (checking on dynamic stack allocations) using the third
  84. approach below.
  85. </li><li> If neither of the above are true, GCC will generate code to periodically
  86. &ldquo;probe&rdquo; the stack pointer using the values of the macros defined below.
  87. </li></ol>
  88. <p>If neither STACK_CHECK_BUILTIN nor STACK_CHECK_STATIC_BUILTIN is defined,
  89. GCC will change its allocation strategy for large objects if the option
  90. <samp>-fstack-check</samp> is specified: they will always be allocated
  91. dynamically if their size exceeds <code>STACK_CHECK_MAX_VAR_SIZE</code> bytes.
  92. </p>
  93. <dl>
  94. <dt><a name="index-STACK_005fCHECK_005fBUILTIN"></a>Macro: <strong>STACK_CHECK_BUILTIN</strong></dt>
  95. <dd><p>A nonzero value if stack checking is done by the configuration files in a
  96. machine-dependent manner. You should define this macro if stack checking
  97. is required by the ABI of your machine or if you would like to do stack
  98. checking in some more efficient way than the generic approach. The default
  99. value of this macro is zero.
  100. </p></dd></dl>
  101. <dl>
  102. <dt><a name="index-STACK_005fCHECK_005fSTATIC_005fBUILTIN"></a>Macro: <strong>STACK_CHECK_STATIC_BUILTIN</strong></dt>
  103. <dd><p>A nonzero value if static stack checking is done by the configuration files
  104. in a machine-dependent manner. You should define this macro if you would
  105. like to do static stack checking in some more efficient way than the generic
  106. approach. The default value of this macro is zero.
  107. </p></dd></dl>
  108. <dl>
  109. <dt><a name="index-STACK_005fCHECK_005fPROBE_005fINTERVAL_005fEXP"></a>Macro: <strong>STACK_CHECK_PROBE_INTERVAL_EXP</strong></dt>
  110. <dd><p>An integer specifying the interval at which GCC must generate stack probe
  111. instructions, defined as 2 raised to this integer. You will normally
  112. define this macro so that the interval be no larger than the size of
  113. the &ldquo;guard pages&rdquo; at the end of a stack area. The default value
  114. of 12 (4096-byte interval) is suitable for most systems.
  115. </p></dd></dl>
  116. <dl>
  117. <dt><a name="index-STACK_005fCHECK_005fMOVING_005fSP"></a>Macro: <strong>STACK_CHECK_MOVING_SP</strong></dt>
  118. <dd><p>An integer which is nonzero if GCC should move the stack pointer page by page
  119. when doing probes. This can be necessary on systems where the stack pointer
  120. contains the bottom address of the memory area accessible to the executing
  121. thread at any point in time. In this situation an alternate signal stack
  122. is required in order to be able to recover from a stack overflow. The
  123. default value of this macro is zero.
  124. </p></dd></dl>
  125. <dl>
  126. <dt><a name="index-STACK_005fCHECK_005fPROTECT"></a>Macro: <strong>STACK_CHECK_PROTECT</strong></dt>
  127. <dd><p>The number of bytes of stack needed to recover from a stack overflow, for
  128. languages where such a recovery is supported. The default value of 4KB/8KB
  129. with the <code>setjmp</code>/<code>longjmp</code>-based exception handling mechanism and
  130. 8KB/12KB with other exception handling mechanisms should be adequate for most
  131. architectures and operating systems.
  132. </p></dd></dl>
  133. <p>The following macros are relevant only if neither STACK_CHECK_BUILTIN
  134. nor STACK_CHECK_STATIC_BUILTIN is defined; you can omit them altogether
  135. in the opposite case.
  136. </p>
  137. <dl>
  138. <dt><a name="index-STACK_005fCHECK_005fMAX_005fFRAME_005fSIZE"></a>Macro: <strong>STACK_CHECK_MAX_FRAME_SIZE</strong></dt>
  139. <dd><p>The maximum size of a stack frame, in bytes. GCC will generate probe
  140. instructions in non-leaf functions to ensure at least this many bytes of
  141. stack are available. If a stack frame is larger than this size, stack
  142. checking will not be reliable and GCC will issue a warning. The
  143. default is chosen so that GCC only generates one instruction on most
  144. systems. You should normally not change the default value of this macro.
  145. </p></dd></dl>
  146. <dl>
  147. <dt><a name="index-STACK_005fCHECK_005fFIXED_005fFRAME_005fSIZE"></a>Macro: <strong>STACK_CHECK_FIXED_FRAME_SIZE</strong></dt>
  148. <dd><p>GCC uses this value to generate the above warning message. It
  149. represents the amount of fixed frame used by a function, not including
  150. space for any callee-saved registers, temporaries and user variables.
  151. You need only specify an upper bound for this amount and will normally
  152. use the default of four words.
  153. </p></dd></dl>
  154. <dl>
  155. <dt><a name="index-STACK_005fCHECK_005fMAX_005fVAR_005fSIZE"></a>Macro: <strong>STACK_CHECK_MAX_VAR_SIZE</strong></dt>
  156. <dd><p>The maximum size, in bytes, of an object that GCC will place in the
  157. fixed area of the stack frame when the user specifies
  158. <samp>-fstack-check</samp>.
  159. GCC computed the default from the values of the above macros and you will
  160. normally not need to override that default.
  161. </p></dd></dl>
  162. <dl>
  163. <dt><a name="index-TARGET_005fSTACK_005fCLASH_005fPROTECTION_005fALLOCA_005fPROBE_005fRANGE"></a>Target Hook: <em>HOST_WIDE_INT</em> <strong>TARGET_STACK_CLASH_PROTECTION_ALLOCA_PROBE_RANGE</strong> <em>(void)</em></dt>
  164. <dd><p>Some targets have an ABI defined interval for which no probing needs to be done.
  165. When a probe does need to be done this same interval is used as the probe distance up when doing stack clash protection for alloca.
  166. On such targets this value can be set to override the default probing up interval.
  167. Define this variable to return nonzero if such a probe range is required or zero otherwise. Defining this hook also requires your functions which make use of alloca to have at least 8 byesof outgoing arguments. If this is not the case the stack will be corrupted.
  168. You need not define this macro if it would always have the value zero.
  169. </p></dd></dl>
  170. <hr>
  171. <div class="header">
  172. <p>
  173. 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>
  174. </div>
  175. </body>
  176. </html>