Frame-Layout.html 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  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: Frame Layout</title>
  20. <meta name="description" content="GNU Compiler Collection (GCC) Internals: Frame Layout">
  21. <meta name="keywords" content="GNU Compiler Collection (GCC) Internals: Frame Layout">
  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="Exception-Handling.html#Exception-Handling" rel="next" title="Exception Handling">
  31. <link href="Stack-and-Calling.html#Stack-and-Calling" rel="prev" title="Stack and Calling">
  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="Frame-Layout"></a>
  63. <div class="header">
  64. <p>
  65. Next: <a href="Exception-Handling.html#Exception-Handling" accesskey="n" rel="next">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="Basic-Stack-Layout"></a>
  69. <h4 class="subsection">17.9.1 Basic Stack Layout</h4>
  70. <a name="index-stack-frame-layout"></a>
  71. <a name="index-frame-layout"></a>
  72. <p>Here is the basic stack layout.
  73. </p>
  74. <dl>
  75. <dt><a name="index-STACK_005fGROWS_005fDOWNWARD"></a>Macro: <strong>STACK_GROWS_DOWNWARD</strong></dt>
  76. <dd><p>Define this macro to be true if pushing a word onto the stack moves the stack
  77. pointer to a smaller address, and false otherwise.
  78. </p></dd></dl>
  79. <dl>
  80. <dt><a name="index-STACK_005fPUSH_005fCODE"></a>Macro: <strong>STACK_PUSH_CODE</strong></dt>
  81. <dd><p>This macro defines the operation used when something is pushed
  82. on the stack. In RTL, a push operation will be
  83. <code>(set (mem (STACK_PUSH_CODE (reg sp))) &hellip;)</code>
  84. </p>
  85. <p>The choices are <code>PRE_DEC</code>, <code>POST_DEC</code>, <code>PRE_INC</code>,
  86. and <code>POST_INC</code>. Which of these is correct depends on
  87. the stack direction and on whether the stack pointer points
  88. to the last item on the stack or whether it points to the
  89. space for the next item on the stack.
  90. </p>
  91. <p>The default is <code>PRE_DEC</code> when <code>STACK_GROWS_DOWNWARD</code> is
  92. true, which is almost always right, and <code>PRE_INC</code> otherwise,
  93. which is often wrong.
  94. </p></dd></dl>
  95. <dl>
  96. <dt><a name="index-FRAME_005fGROWS_005fDOWNWARD"></a>Macro: <strong>FRAME_GROWS_DOWNWARD</strong></dt>
  97. <dd><p>Define this macro to nonzero value if the addresses of local variable slots
  98. are at negative offsets from the frame pointer.
  99. </p></dd></dl>
  100. <dl>
  101. <dt><a name="index-ARGS_005fGROW_005fDOWNWARD"></a>Macro: <strong>ARGS_GROW_DOWNWARD</strong></dt>
  102. <dd><p>Define this macro if successive arguments to a function occupy decreasing
  103. addresses on the stack.
  104. </p></dd></dl>
  105. <dl>
  106. <dt><a name="index-STARTING_005fFRAME_005fOFFSET"></a>Macro: <strong>STARTING_FRAME_OFFSET</strong></dt>
  107. <dd><p>Offset from the frame pointer to the first local variable slot to be allocated.
  108. </p>
  109. <p>If <code>FRAME_GROWS_DOWNWARD</code>, find the next slot&rsquo;s offset by
  110. subtracting the first slot&rsquo;s length from <code>STARTING_FRAME_OFFSET</code>.
  111. Otherwise, it is found by adding the length of the first slot to the
  112. value <code>STARTING_FRAME_OFFSET</code>.
  113. </p></dd></dl>
  114. <dl>
  115. <dt><a name="index-STACK_005fALIGNMENT_005fNEEDED"></a>Macro: <strong>STACK_ALIGNMENT_NEEDED</strong></dt>
  116. <dd><p>Define to zero to disable final alignment of the stack during reload.
  117. The nonzero default for this macro is suitable for most ports.
  118. </p>
  119. <p>On ports where <code>STARTING_FRAME_OFFSET</code> is nonzero or where there
  120. is a register save block following the local block that doesn&rsquo;t require
  121. alignment to <code>STACK_BOUNDARY</code>, it may be beneficial to disable
  122. stack alignment and do it in the backend.
  123. </p></dd></dl>
  124. <dl>
  125. <dt><a name="index-STACK_005fPOINTER_005fOFFSET"></a>Macro: <strong>STACK_POINTER_OFFSET</strong></dt>
  126. <dd><p>Offset from the stack pointer register to the first location at which
  127. outgoing arguments are placed. If not specified, the default value of
  128. zero is used. This is the proper value for most machines.
  129. </p>
  130. <p>If <code>ARGS_GROW_DOWNWARD</code>, this is the offset to the location above
  131. the first location at which outgoing arguments are placed.
  132. </p></dd></dl>
  133. <dl>
  134. <dt><a name="index-FIRST_005fPARM_005fOFFSET"></a>Macro: <strong>FIRST_PARM_OFFSET</strong> <em>(<var>fundecl</var>)</em></dt>
  135. <dd><p>Offset from the argument pointer register to the first argument&rsquo;s
  136. address. On some machines it may depend on the data type of the
  137. function.
  138. </p>
  139. <p>If <code>ARGS_GROW_DOWNWARD</code>, this is the offset to the location above
  140. the first argument&rsquo;s address.
  141. </p></dd></dl>
  142. <dl>
  143. <dt><a name="index-STACK_005fDYNAMIC_005fOFFSET"></a>Macro: <strong>STACK_DYNAMIC_OFFSET</strong> <em>(<var>fundecl</var>)</em></dt>
  144. <dd><p>Offset from the stack pointer register to an item dynamically allocated
  145. on the stack, e.g., by <code>alloca</code>.
  146. </p>
  147. <p>The default value for this macro is <code>STACK_POINTER_OFFSET</code> plus the
  148. length of the outgoing arguments. The default is correct for most
  149. machines. See <samp>function.c</samp> for details.
  150. </p></dd></dl>
  151. <dl>
  152. <dt><a name="index-INITIAL_005fFRAME_005fADDRESS_005fRTX"></a>Macro: <strong>INITIAL_FRAME_ADDRESS_RTX</strong></dt>
  153. <dd><p>A C expression whose value is RTL representing the address of the initial
  154. stack frame. This address is passed to <code>RETURN_ADDR_RTX</code> and
  155. <code>DYNAMIC_CHAIN_ADDRESS</code>. If you don&rsquo;t define this macro, a reasonable
  156. default value will be used. Define this macro in order to make frame pointer
  157. elimination work in the presence of <code>__builtin_frame_address (count)</code> and
  158. <code>__builtin_return_address (count)</code> for <code>count</code> not equal to zero.
  159. </p></dd></dl>
  160. <dl>
  161. <dt><a name="index-DYNAMIC_005fCHAIN_005fADDRESS"></a>Macro: <strong>DYNAMIC_CHAIN_ADDRESS</strong> <em>(<var>frameaddr</var>)</em></dt>
  162. <dd><p>A C expression whose value is RTL representing the address in a stack
  163. frame where the pointer to the caller&rsquo;s frame is stored. Assume that
  164. <var>frameaddr</var> is an RTL expression for the address of the stack frame
  165. itself.
  166. </p>
  167. <p>If you don&rsquo;t define this macro, the default is to return the value
  168. of <var>frameaddr</var>&mdash;that is, the stack frame address is also the
  169. address of the stack word that points to the previous frame.
  170. </p></dd></dl>
  171. <dl>
  172. <dt><a name="index-SETUP_005fFRAME_005fADDRESSES"></a>Macro: <strong>SETUP_FRAME_ADDRESSES</strong></dt>
  173. <dd><p>A C expression that produces the machine-specific code to
  174. setup the stack so that arbitrary frames can be accessed. For example,
  175. on the SPARC, we must flush all of the register windows to the stack
  176. before we can access arbitrary stack frames. You will seldom need to
  177. define this macro. The default is to do nothing.
  178. </p></dd></dl>
  179. <dl>
  180. <dt><a name="index-TARGET_005fBUILTIN_005fSETJMP_005fFRAME_005fVALUE"></a>Target Hook: <em>rtx</em> <strong>TARGET_BUILTIN_SETJMP_FRAME_VALUE</strong> <em>(void)</em></dt>
  181. <dd><p>This target hook should return an rtx that is used to store
  182. the address of the current frame into the built in <code>setjmp</code> buffer.
  183. The default value, <code>virtual_stack_vars_rtx</code>, is correct for most
  184. machines. One reason you may need to define this target hook is if
  185. <code>hard_frame_pointer_rtx</code> is the appropriate value on your machine.
  186. </p></dd></dl>
  187. <dl>
  188. <dt><a name="index-FRAME_005fADDR_005fRTX"></a>Macro: <strong>FRAME_ADDR_RTX</strong> <em>(<var>frameaddr</var>)</em></dt>
  189. <dd><p>A C expression whose value is RTL representing the value of the frame
  190. address for the current frame. <var>frameaddr</var> is the frame pointer
  191. of the current frame. This is used for __builtin_frame_address.
  192. You need only define this macro if the frame address is not the same
  193. as the frame pointer. Most machines do not need to define it.
  194. </p></dd></dl>
  195. <dl>
  196. <dt><a name="index-RETURN_005fADDR_005fRTX"></a>Macro: <strong>RETURN_ADDR_RTX</strong> <em>(<var>count</var>, <var>frameaddr</var>)</em></dt>
  197. <dd><p>A C expression whose value is RTL representing the value of the return
  198. address for the frame <var>count</var> steps up from the current frame, after
  199. the prologue. <var>frameaddr</var> is the frame pointer of the <var>count</var>
  200. frame, or the frame pointer of the <var>count</var> - 1 frame if
  201. <code>RETURN_ADDR_IN_PREVIOUS_FRAME</code> is nonzero.
  202. </p>
  203. <p>The value of the expression must always be the correct address when
  204. <var>count</var> is zero, but may be <code>NULL_RTX</code> if there is no way to
  205. determine the return address of other frames.
  206. </p></dd></dl>
  207. <dl>
  208. <dt><a name="index-RETURN_005fADDR_005fIN_005fPREVIOUS_005fFRAME"></a>Macro: <strong>RETURN_ADDR_IN_PREVIOUS_FRAME</strong></dt>
  209. <dd><p>Define this macro to nonzero value if the return address of a particular
  210. stack frame is accessed from the frame pointer of the previous stack
  211. frame. The zero default for this macro is suitable for most ports.
  212. </p></dd></dl>
  213. <dl>
  214. <dt><a name="index-INCOMING_005fRETURN_005fADDR_005fRTX"></a>Macro: <strong>INCOMING_RETURN_ADDR_RTX</strong></dt>
  215. <dd><p>A C expression whose value is RTL representing the location of the
  216. incoming return address at the beginning of any function, before the
  217. prologue. This RTL is either a <code>REG</code>, indicating that the return
  218. value is saved in &lsquo;<samp>REG</samp>&rsquo;, or a <code>MEM</code> representing a location in
  219. the stack.
  220. </p>
  221. <p>You only need to define this macro if you want to support call frame
  222. debugging information like that provided by DWARF 2.
  223. </p>
  224. <p>If this RTL is a <code>REG</code>, you should also define
  225. <code>DWARF_FRAME_RETURN_COLUMN</code> to <code>DWARF_FRAME_REGNUM (REGNO)</code>.
  226. </p></dd></dl>
  227. <dl>
  228. <dt><a name="index-DWARF_005fALT_005fFRAME_005fRETURN_005fCOLUMN"></a>Macro: <strong>DWARF_ALT_FRAME_RETURN_COLUMN</strong></dt>
  229. <dd><p>A C expression whose value is an integer giving a DWARF 2 column
  230. number that may be used as an alternative return column. The column
  231. must not correspond to any gcc hard register (that is, it must not
  232. be in the range of <code>DWARF_FRAME_REGNUM</code>).
  233. </p>
  234. <p>This macro can be useful if <code>DWARF_FRAME_RETURN_COLUMN</code> is set to a
  235. general register, but an alternative column needs to be used for signal
  236. frames. Some targets have also used different frame return columns
  237. over time.
  238. </p></dd></dl>
  239. <dl>
  240. <dt><a name="index-DWARF_005fZERO_005fREG"></a>Macro: <strong>DWARF_ZERO_REG</strong></dt>
  241. <dd><p>A C expression whose value is an integer giving a DWARF 2 register
  242. number that is considered to always have the value zero. This should
  243. only be defined if the target has an architected zero register, and
  244. someone decided it was a good idea to use that register number to
  245. terminate the stack backtrace. New ports should avoid this.
  246. </p></dd></dl>
  247. <dl>
  248. <dt><a name="index-TARGET_005fDWARF_005fHANDLE_005fFRAME_005fUNSPEC"></a>Target Hook: <em>void</em> <strong>TARGET_DWARF_HANDLE_FRAME_UNSPEC</strong> <em>(const char *<var>label</var>, rtx <var>pattern</var>, int <var>index</var>)</em></dt>
  249. <dd><p>This target hook allows the backend to emit frame-related insns that
  250. contain UNSPECs or UNSPEC_VOLATILEs. The DWARF 2 call frame debugging
  251. info engine will invoke it on insns of the form
  252. </p><div class="smallexample">
  253. <pre class="smallexample">(set (reg) (unspec [&hellip;] UNSPEC_INDEX))
  254. </pre></div>
  255. <p>and
  256. </p><div class="smallexample">
  257. <pre class="smallexample">(set (reg) (unspec_volatile [&hellip;] UNSPECV_INDEX)).
  258. </pre></div>
  259. <p>to let the backend emit the call frame instructions. <var>label</var> is
  260. the CFI label attached to the insn, <var>pattern</var> is the pattern of
  261. the insn and <var>index</var> is <code>UNSPEC_INDEX</code> or <code>UNSPECV_INDEX</code>.
  262. </p></dd></dl>
  263. <dl>
  264. <dt><a name="index-INCOMING_005fFRAME_005fSP_005fOFFSET"></a>Macro: <strong>INCOMING_FRAME_SP_OFFSET</strong></dt>
  265. <dd><p>A C expression whose value is an integer giving the offset, in bytes,
  266. from the value of the stack pointer register to the top of the stack
  267. frame at the beginning of any function, before the prologue. The top of
  268. the frame is defined to be the value of the stack pointer in the
  269. previous frame, just before the call instruction.
  270. </p>
  271. <p>You only need to define this macro if you want to support call frame
  272. debugging information like that provided by DWARF 2.
  273. </p></dd></dl>
  274. <dl>
  275. <dt><a name="index-ARG_005fPOINTER_005fCFA_005fOFFSET"></a>Macro: <strong>ARG_POINTER_CFA_OFFSET</strong> <em>(<var>fundecl</var>)</em></dt>
  276. <dd><p>A C expression whose value is an integer giving the offset, in bytes,
  277. from the argument pointer to the canonical frame address (cfa). The
  278. final value should coincide with that calculated by
  279. <code>INCOMING_FRAME_SP_OFFSET</code>. Which is unfortunately not usable
  280. during virtual register instantiation.
  281. </p>
  282. <p>The default value for this macro is
  283. <code>FIRST_PARM_OFFSET (fundecl) + crtl-&gt;args.pretend_args_size</code>,
  284. which is correct for most machines; in general, the arguments are found
  285. immediately before the stack frame. Note that this is not the case on
  286. some targets that save registers into the caller&rsquo;s frame, such as SPARC
  287. and rs6000, and so such targets need to define this macro.
  288. </p>
  289. <p>You only need to define this macro if the default is incorrect, and you
  290. want to support call frame debugging information like that provided by
  291. DWARF 2.
  292. </p></dd></dl>
  293. <dl>
  294. <dt><a name="index-FRAME_005fPOINTER_005fCFA_005fOFFSET"></a>Macro: <strong>FRAME_POINTER_CFA_OFFSET</strong> <em>(<var>fundecl</var>)</em></dt>
  295. <dd><p>If defined, a C expression whose value is an integer giving the offset
  296. in bytes from the frame pointer to the canonical frame address (cfa).
  297. The final value should coincide with that calculated by
  298. <code>INCOMING_FRAME_SP_OFFSET</code>.
  299. </p>
  300. <p>Normally the CFA is calculated as an offset from the argument pointer,
  301. via <code>ARG_POINTER_CFA_OFFSET</code>, but if the argument pointer is
  302. variable due to the ABI, this may not be possible. If this macro is
  303. defined, it implies that the virtual register instantiation should be
  304. based on the frame pointer instead of the argument pointer. Only one
  305. of <code>FRAME_POINTER_CFA_OFFSET</code> and <code>ARG_POINTER_CFA_OFFSET</code>
  306. should be defined.
  307. </p></dd></dl>
  308. <dl>
  309. <dt><a name="index-CFA_005fFRAME_005fBASE_005fOFFSET"></a>Macro: <strong>CFA_FRAME_BASE_OFFSET</strong> <em>(<var>fundecl</var>)</em></dt>
  310. <dd><p>If defined, a C expression whose value is an integer giving the offset
  311. in bytes from the canonical frame address (cfa) to the frame base used
  312. in DWARF 2 debug information. The default is zero. A different value
  313. may reduce the size of debug information on some ports.
  314. </p></dd></dl>
  315. <hr>
  316. <div class="header">
  317. <p>
  318. Next: <a href="Exception-Handling.html#Exception-Handling" accesskey="n" rel="next">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>
  319. </div>
  320. </body>
  321. </html>