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.

381 lines
19KB

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