Stack-Arguments.html 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  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 Arguments</title>
  20. <meta name="description" content="GNU Compiler Collection (GCC) Internals: Stack Arguments">
  21. <meta name="keywords" content="GNU Compiler Collection (GCC) Internals: Stack Arguments">
  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="Register-Arguments.html#Register-Arguments" rel="next" title="Register Arguments">
  31. <link href="Elimination.html#Elimination" rel="prev" title="Elimination">
  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-Arguments"></a>
  63. <div class="header">
  64. <p>
  65. Next: <a href="Register-Arguments.html#Register-Arguments" accesskey="n" rel="next">Register Arguments</a>, Previous: <a href="Elimination.html#Elimination" accesskey="p" rel="prev">Elimination</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="Passing-Function-Arguments-on-the-Stack"></a>
  69. <h4 class="subsection">17.9.6 Passing Function Arguments on the Stack</h4>
  70. <a name="index-arguments-on-stack"></a>
  71. <a name="index-stack-arguments"></a>
  72. <p>The macros in this section control how arguments are passed
  73. on the stack. See the following section for other macros that
  74. control passing certain arguments in registers.
  75. </p>
  76. <dl>
  77. <dt><a name="index-TARGET_005fPROMOTE_005fPROTOTYPES"></a>Target Hook: <em>bool</em> <strong>TARGET_PROMOTE_PROTOTYPES</strong> <em>(const_tree <var>fntype</var>)</em></dt>
  78. <dd><p>This target hook returns <code>true</code> if an argument declared in a
  79. prototype as an integral type smaller than <code>int</code> should actually be
  80. passed as an <code>int</code>. In addition to avoiding errors in certain
  81. cases of mismatch, it also makes for better code on certain machines.
  82. The default is to not promote prototypes.
  83. </p></dd></dl>
  84. <dl>
  85. <dt><a name="index-PUSH_005fARGS"></a>Macro: <strong>PUSH_ARGS</strong></dt>
  86. <dd><p>A C expression. If nonzero, push insns will be used to pass
  87. outgoing arguments.
  88. If the target machine does not have a push instruction, set it to zero.
  89. That directs GCC to use an alternate strategy: to
  90. allocate the entire argument block and then store the arguments into
  91. it. When <code>PUSH_ARGS</code> is nonzero, <code>PUSH_ROUNDING</code> must be defined too.
  92. </p></dd></dl>
  93. <dl>
  94. <dt><a name="index-PUSH_005fARGS_005fREVERSED"></a>Macro: <strong>PUSH_ARGS_REVERSED</strong></dt>
  95. <dd><p>A C expression. If nonzero, function arguments will be evaluated from
  96. last to first, rather than from first to last. If this macro is not
  97. defined, it defaults to <code>PUSH_ARGS</code> on targets where the stack
  98. and args grow in opposite directions, and 0 otherwise.
  99. </p></dd></dl>
  100. <dl>
  101. <dt><a name="index-PUSH_005fROUNDING"></a>Macro: <strong>PUSH_ROUNDING</strong> <em>(<var>npushed</var>)</em></dt>
  102. <dd><p>A C expression that is the number of bytes actually pushed onto the
  103. stack when an instruction attempts to push <var>npushed</var> bytes.
  104. </p>
  105. <p>On some machines, the definition
  106. </p>
  107. <div class="smallexample">
  108. <pre class="smallexample">#define PUSH_ROUNDING(BYTES) (BYTES)
  109. </pre></div>
  110. <p>will suffice. But on other machines, instructions that appear
  111. to push one byte actually push two bytes in an attempt to maintain
  112. alignment. Then the definition should be
  113. </p>
  114. <div class="smallexample">
  115. <pre class="smallexample">#define PUSH_ROUNDING(BYTES) (((BYTES) + 1) &amp; ~1)
  116. </pre></div>
  117. <p>If the value of this macro has a type, it should be an unsigned type.
  118. </p></dd></dl>
  119. <a name="index-outgoing_005fargs_005fsize"></a>
  120. <a name="index-crtl_002d_003eoutgoing_005fargs_005fsize"></a>
  121. <dl>
  122. <dt><a name="index-ACCUMULATE_005fOUTGOING_005fARGS"></a>Macro: <strong>ACCUMULATE_OUTGOING_ARGS</strong></dt>
  123. <dd><p>A C expression. If nonzero, the maximum amount of space required for outgoing arguments
  124. will be computed and placed into
  125. <code>crtl-&gt;outgoing_args_size</code>. No space will be pushed
  126. onto the stack for each call; instead, the function prologue should
  127. increase the stack frame size by this amount.
  128. </p>
  129. <p>Setting both <code>PUSH_ARGS</code> and <code>ACCUMULATE_OUTGOING_ARGS</code>
  130. is not proper.
  131. </p></dd></dl>
  132. <dl>
  133. <dt><a name="index-REG_005fPARM_005fSTACK_005fSPACE"></a>Macro: <strong>REG_PARM_STACK_SPACE</strong> <em>(<var>fndecl</var>)</em></dt>
  134. <dd><p>Define this macro if functions should assume that stack space has been
  135. allocated for arguments even when their values are passed in
  136. registers.
  137. </p>
  138. <p>The value of this macro is the size, in bytes, of the area reserved for
  139. arguments passed in registers for the function represented by <var>fndecl</var>,
  140. which can be zero if GCC is calling a library function.
  141. The argument <var>fndecl</var> can be the FUNCTION_DECL, or the type itself
  142. of the function.
  143. </p>
  144. <p>This space can be allocated by the caller, or be a part of the
  145. machine-dependent stack frame: <code>OUTGOING_REG_PARM_STACK_SPACE</code> says
  146. which.
  147. </p></dd></dl>
  148. <dl>
  149. <dt><a name="index-INCOMING_005fREG_005fPARM_005fSTACK_005fSPACE"></a>Macro: <strong>INCOMING_REG_PARM_STACK_SPACE</strong> <em>(<var>fndecl</var>)</em></dt>
  150. <dd><p>Like <code>REG_PARM_STACK_SPACE</code>, but for incoming register arguments.
  151. Define this macro if space guaranteed when compiling a function body
  152. is different to space required when making a call, a situation that
  153. can arise with K&amp;R style function definitions.
  154. </p></dd></dl>
  155. <dl>
  156. <dt><a name="index-OUTGOING_005fREG_005fPARM_005fSTACK_005fSPACE"></a>Macro: <strong>OUTGOING_REG_PARM_STACK_SPACE</strong> <em>(<var>fntype</var>)</em></dt>
  157. <dd><p>Define this to a nonzero value if it is the responsibility of the
  158. caller to allocate the area reserved for arguments passed in registers
  159. when calling a function of <var>fntype</var>. <var>fntype</var> may be NULL
  160. if the function called is a library function.
  161. </p>
  162. <p>If <code>ACCUMULATE_OUTGOING_ARGS</code> is defined, this macro controls
  163. whether the space for these arguments counts in the value of
  164. <code>crtl-&gt;outgoing_args_size</code>.
  165. </p></dd></dl>
  166. <dl>
  167. <dt><a name="index-STACK_005fPARMS_005fIN_005fREG_005fPARM_005fAREA"></a>Macro: <strong>STACK_PARMS_IN_REG_PARM_AREA</strong></dt>
  168. <dd><p>Define this macro if <code>REG_PARM_STACK_SPACE</code> is defined, but the
  169. stack parameters don&rsquo;t skip the area specified by it.
  170. </p>
  171. <p>Normally, when a parameter is not passed in registers, it is placed on the
  172. stack beyond the <code>REG_PARM_STACK_SPACE</code> area. Defining this macro
  173. suppresses this behavior and causes the parameter to be passed on the
  174. stack in its natural location.
  175. </p></dd></dl>
  176. <dl>
  177. <dt><a name="index-TARGET_005fRETURN_005fPOPS_005fARGS"></a>Target Hook: <em>int</em> <strong>TARGET_RETURN_POPS_ARGS</strong> <em>(tree <var>fundecl</var>, tree <var>funtype</var>, int <var>size</var>)</em></dt>
  178. <dd><p>This target hook returns the number of bytes of its own arguments that
  179. a function pops on returning, or 0 if the function pops no arguments
  180. and the caller must therefore pop them all after the function returns.
  181. </p>
  182. <p><var>fundecl</var> is a C variable whose value is a tree node that describes
  183. the function in question. Normally it is a node of type
  184. <code>FUNCTION_DECL</code> that describes the declaration of the function.
  185. From this you can obtain the <code>DECL_ATTRIBUTES</code> of the function.
  186. </p>
  187. <p><var>funtype</var> is a C variable whose value is a tree node that
  188. describes the function in question. Normally it is a node of type
  189. <code>FUNCTION_TYPE</code> that describes the data type of the function.
  190. From this it is possible to obtain the data types of the value and
  191. arguments (if known).
  192. </p>
  193. <p>When a call to a library function is being considered, <var>fundecl</var>
  194. will contain an identifier node for the library function. Thus, if
  195. you need to distinguish among various library functions, you can do so
  196. by their names. Note that &ldquo;library function&rdquo; in this context means
  197. a function used to perform arithmetic, whose name is known specially
  198. in the compiler and was not mentioned in the C code being compiled.
  199. </p>
  200. <p><var>size</var> is the number of bytes of arguments passed on the
  201. stack. If a variable number of bytes is passed, it is zero, and
  202. argument popping will always be the responsibility of the calling function.
  203. </p>
  204. <p>On the VAX, all functions always pop their arguments, so the definition
  205. of this macro is <var>size</var>. On the 68000, using the standard
  206. calling convention, no functions pop their arguments, so the value of
  207. the macro is always 0 in this case. But an alternative calling
  208. convention is available in which functions that take a fixed number of
  209. arguments pop them but other functions (such as <code>printf</code>) pop
  210. nothing (the caller pops all). When this convention is in use,
  211. <var>funtype</var> is examined to determine whether a function takes a fixed
  212. number of arguments.
  213. </p></dd></dl>
  214. <dl>
  215. <dt><a name="index-CALL_005fPOPS_005fARGS"></a>Macro: <strong>CALL_POPS_ARGS</strong> <em>(<var>cum</var>)</em></dt>
  216. <dd><p>A C expression that should indicate the number of bytes a call sequence
  217. pops off the stack. It is added to the value of <code>RETURN_POPS_ARGS</code>
  218. when compiling a function call.
  219. </p>
  220. <p><var>cum</var> is the variable in which all arguments to the called function
  221. have been accumulated.
  222. </p>
  223. <p>On certain architectures, such as the SH5, a call trampoline is used
  224. that pops certain registers off the stack, depending on the arguments
  225. that have been passed to the function. Since this is a property of the
  226. call site, not of the called function, <code>RETURN_POPS_ARGS</code> is not
  227. appropriate.
  228. </p></dd></dl>
  229. <hr>
  230. <div class="header">
  231. <p>
  232. Next: <a href="Register-Arguments.html#Register-Arguments" accesskey="n" rel="next">Register Arguments</a>, Previous: <a href="Elimination.html#Elimination" accesskey="p" rel="prev">Elimination</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>
  233. </div>
  234. </body>
  235. </html>