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.

3 yıl önce
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  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>Varargs (GNU Compiler Collection (GCC) Internals)</title>
  21. <meta name="description" content="Varargs (GNU Compiler Collection (GCC) Internals)">
  22. <meta name="keywords" content="Varargs (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="Target-Macros.html#Target-Macros" rel="up" title="Target Macros">
  30. <link href="Trampolines.html#Trampolines" rel="next" title="Trampolines">
  31. <link href="Miscellaneous-Register-Hooks.html#Miscellaneous-Register-Hooks" rel="prev" title="Miscellaneous Register Hooks">
  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="Varargs"></a>
  62. <div class="header">
  63. <p>
  64. Next: <a href="Trampolines.html#Trampolines" accesskey="n" rel="next">Trampolines</a>, Previous: <a href="Stack-and-Calling.html#Stack-and-Calling" accesskey="p" rel="prev">Stack and Calling</a>, Up: <a href="Target-Macros.html#Target-Macros" accesskey="u" rel="up">Target Macros</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="Implementing-the-Varargs-Macros"></a>
  68. <h3 class="section">18.10 Implementing the Varargs Macros</h3>
  69. <a name="index-varargs-implementation"></a>
  70. <p>GCC comes with an implementation of <code>&lt;varargs.h&gt;</code> and
  71. <code>&lt;stdarg.h&gt;</code> that work without change on machines that pass arguments
  72. on the stack. Other machines require their own implementations of
  73. varargs, and the two machine independent header files must have
  74. conditionals to include it.
  75. </p>
  76. <p>ISO <code>&lt;stdarg.h&gt;</code> differs from traditional <code>&lt;varargs.h&gt;</code> mainly in
  77. the calling convention for <code>va_start</code>. The traditional
  78. implementation takes just one argument, which is the variable in which
  79. to store the argument pointer. The ISO implementation of
  80. <code>va_start</code> takes an additional second argument. The user is
  81. supposed to write the last named argument of the function here.
  82. </p>
  83. <p>However, <code>va_start</code> should not use this argument. The way to find
  84. the end of the named arguments is with the built-in functions described
  85. below.
  86. </p>
  87. <dl>
  88. <dt><a name="index-_005f_005fbuiltin_005fsaveregs"></a>Macro: <strong>__builtin_saveregs</strong> <em>()</em></dt>
  89. <dd><p>Use this built-in function to save the argument registers in memory so
  90. that the varargs mechanism can access them. Both ISO and traditional
  91. versions of <code>va_start</code> must use <code>__builtin_saveregs</code>, unless
  92. you use <code>TARGET_SETUP_INCOMING_VARARGS</code> (see below) instead.
  93. </p>
  94. <p>On some machines, <code>__builtin_saveregs</code> is open-coded under the
  95. control of the target hook <code>TARGET_EXPAND_BUILTIN_SAVEREGS</code>. On
  96. other machines, it calls a routine written in assembler language,
  97. found in <samp>libgcc2.c</samp>.
  98. </p>
  99. <p>Code generated for the call to <code>__builtin_saveregs</code> appears at the
  100. beginning of the function, as opposed to where the call to
  101. <code>__builtin_saveregs</code> is written, regardless of what the code is.
  102. This is because the registers must be saved before the function starts
  103. to use them for its own purposes.
  104. </p></dd></dl>
  105. <dl>
  106. <dt><a name="index-_005f_005fbuiltin_005fnext_005farg"></a>Macro: <strong>__builtin_next_arg</strong> <em>(<var>lastarg</var>)</em></dt>
  107. <dd><p>This builtin returns the address of the first anonymous stack
  108. argument, as type <code>void *</code>. If <code>ARGS_GROW_DOWNWARD</code>, it
  109. returns the address of the location above the first anonymous stack
  110. argument. Use it in <code>va_start</code> to initialize the pointer for
  111. fetching arguments from the stack. Also use it in <code>va_start</code> to
  112. verify that the second parameter <var>lastarg</var> is the last named argument
  113. of the current function.
  114. </p></dd></dl>
  115. <dl>
  116. <dt><a name="index-_005f_005fbuiltin_005fclassify_005ftype"></a>Macro: <strong>__builtin_classify_type</strong> <em>(<var>object</var>)</em></dt>
  117. <dd><p>Since each machine has its own conventions for which data types are
  118. passed in which kind of register, your implementation of <code>va_arg</code>
  119. has to embody these conventions. The easiest way to categorize the
  120. specified data type is to use <code>__builtin_classify_type</code> together
  121. with <code>sizeof</code> and <code>__alignof__</code>.
  122. </p>
  123. <p><code>__builtin_classify_type</code> ignores the value of <var>object</var>,
  124. considering only its data type. It returns an integer describing what
  125. kind of type that is&mdash;integer, floating, pointer, structure, and so on.
  126. </p>
  127. <p>The file <samp>typeclass.h</samp> defines an enumeration that you can use to
  128. interpret the values of <code>__builtin_classify_type</code>.
  129. </p></dd></dl>
  130. <p>These machine description macros help implement varargs:
  131. </p>
  132. <dl>
  133. <dt><a name="index-TARGET_005fEXPAND_005fBUILTIN_005fSAVEREGS"></a>Target Hook: <em>rtx</em> <strong>TARGET_EXPAND_BUILTIN_SAVEREGS</strong> <em>(void)</em></dt>
  134. <dd><p>If defined, this hook produces the machine-specific code for a call to
  135. <code>__builtin_saveregs</code>. This code will be moved to the very
  136. beginning of the function, before any parameter access are made. The
  137. return value of this function should be an RTX that contains the value
  138. to use as the return of <code>__builtin_saveregs</code>.
  139. </p></dd></dl>
  140. <dl>
  141. <dt><a name="index-TARGET_005fSETUP_005fINCOMING_005fVARARGS"></a>Target Hook: <em>void</em> <strong>TARGET_SETUP_INCOMING_VARARGS</strong> <em>(cumulative_args_t <var>args_so_far</var>, const function_arg_info <var>&amp;arg</var>, int *<var>pretend_args_size</var>, int <var>second_time</var>)</em></dt>
  142. <dd><p>This target hook offers an alternative to using
  143. <code>__builtin_saveregs</code> and defining the hook
  144. <code>TARGET_EXPAND_BUILTIN_SAVEREGS</code>. Use it to store the anonymous
  145. register arguments into the stack so that all the arguments appear to
  146. have been passed consecutively on the stack. Once this is done, you can
  147. use the standard implementation of varargs that works for machines that
  148. pass all their arguments on the stack.
  149. </p>
  150. <p>The argument <var>args_so_far</var> points to the <code>CUMULATIVE_ARGS</code> data
  151. structure, containing the values that are obtained after processing the
  152. named arguments. The argument <var>arg</var> describes the last of these named
  153. arguments.
  154. </p>
  155. <p>The target hook should do two things: first, push onto the stack all the
  156. argument registers <em>not</em> used for the named arguments, and second,
  157. store the size of the data thus pushed into the <code>int</code>-valued
  158. variable pointed to by <var>pretend_args_size</var>. The value that you
  159. store here will serve as additional offset for setting up the stack
  160. frame.
  161. </p>
  162. <p>Because you must generate code to push the anonymous arguments at
  163. compile time without knowing their data types,
  164. <code>TARGET_SETUP_INCOMING_VARARGS</code> is only useful on machines that
  165. have just a single category of argument register and use it uniformly
  166. for all data types.
  167. </p>
  168. <p>If the argument <var>second_time</var> is nonzero, it means that the
  169. arguments of the function are being analyzed for the second time. This
  170. happens for an inline function, which is not actually compiled until the
  171. end of the source file. The hook <code>TARGET_SETUP_INCOMING_VARARGS</code> should
  172. not generate any instructions in this case.
  173. </p></dd></dl>
  174. <dl>
  175. <dt><a name="index-TARGET_005fSTRICT_005fARGUMENT_005fNAMING"></a>Target Hook: <em>bool</em> <strong>TARGET_STRICT_ARGUMENT_NAMING</strong> <em>(cumulative_args_t <var>ca</var>)</em></dt>
  176. <dd><p>Define this hook to return <code>true</code> if the location where a function
  177. argument is passed depends on whether or not it is a named argument.
  178. </p>
  179. <p>This hook controls how the <var>named</var> argument to <code>TARGET_FUNCTION_ARG</code>
  180. is set for varargs and stdarg functions. If this hook returns
  181. <code>true</code>, the <var>named</var> argument is always true for named
  182. arguments, and false for unnamed arguments. If it returns <code>false</code>,
  183. but <code>TARGET_PRETEND_OUTGOING_VARARGS_NAMED</code> returns <code>true</code>,
  184. then all arguments are treated as named. Otherwise, all named arguments
  185. except the last are treated as named.
  186. </p>
  187. <p>You need not define this hook if it always returns <code>false</code>.
  188. </p></dd></dl>
  189. <dl>
  190. <dt><a name="index-TARGET_005fCALL_005fARGS"></a>Target Hook: <em>void</em> <strong>TARGET_CALL_ARGS</strong> <em>(rtx, <var>tree</var>)</em></dt>
  191. <dd><p>While generating RTL for a function call, this target hook is invoked once
  192. for each argument passed to the function, either a register returned by
  193. <code>TARGET_FUNCTION_ARG</code> or a memory location. It is called just
  194. before the point where argument registers are stored. The type of the
  195. function to be called is also passed as the second argument; it is
  196. <code>NULL_TREE</code> for libcalls. The <code>TARGET_END_CALL_ARGS</code> hook is
  197. invoked just after the code to copy the return reg has been emitted.
  198. This functionality can be used to perform special setup of call argument
  199. registers if a target needs it.
  200. For functions without arguments, the hook is called once with <code>pc_rtx</code>
  201. passed instead of an argument register.
  202. Most ports do not need to implement anything for this hook.
  203. </p></dd></dl>
  204. <dl>
  205. <dt><a name="index-TARGET_005fEND_005fCALL_005fARGS"></a>Target Hook: <em>void</em> <strong>TARGET_END_CALL_ARGS</strong> <em>(void)</em></dt>
  206. <dd><p>This target hook is invoked while generating RTL for a function call,
  207. just after the point where the return reg is copied into a pseudo. It
  208. signals that all the call argument and return registers for the just
  209. emitted call are now no longer in use.
  210. Most ports do not need to implement anything for this hook.
  211. </p></dd></dl>
  212. <dl>
  213. <dt><a name="index-TARGET_005fPRETEND_005fOUTGOING_005fVARARGS_005fNAMED"></a>Target Hook: <em>bool</em> <strong>TARGET_PRETEND_OUTGOING_VARARGS_NAMED</strong> <em>(cumulative_args_t <var>ca</var>)</em></dt>
  214. <dd><p>If you need to conditionally change ABIs so that one works with
  215. <code>TARGET_SETUP_INCOMING_VARARGS</code>, but the other works like neither
  216. <code>TARGET_SETUP_INCOMING_VARARGS</code> nor <code>TARGET_STRICT_ARGUMENT_NAMING</code> was
  217. defined, then define this hook to return <code>true</code> if
  218. <code>TARGET_SETUP_INCOMING_VARARGS</code> is used, <code>false</code> otherwise.
  219. Otherwise, you should not define this hook.
  220. </p></dd></dl>
  221. <dl>
  222. <dt><a name="index-TARGET_005fLOAD_005fBOUNDS_005fFOR_005fARG"></a>Target Hook: <em>rtx</em> <strong>TARGET_LOAD_BOUNDS_FOR_ARG</strong> <em>(rtx <var>slot</var>, rtx <var>arg</var>, rtx <var>slot_no</var>)</em></dt>
  223. <dd><p>This hook is used by expand pass to emit insn to load bounds of
  224. <var>arg</var> passed in <var>slot</var>. Expand pass uses this hook in case
  225. bounds of <var>arg</var> are not passed in register. If <var>slot</var> is a
  226. memory, then bounds are loaded as for regular pointer loaded from
  227. memory. If <var>slot</var> is not a memory then <var>slot_no</var> is an integer
  228. constant holding number of the target dependent special slot which
  229. should be used to obtain bounds. Hook returns RTX holding loaded bounds.
  230. </p></dd></dl>
  231. <dl>
  232. <dt><a name="index-TARGET_005fSTORE_005fBOUNDS_005fFOR_005fARG"></a>Target Hook: <em>void</em> <strong>TARGET_STORE_BOUNDS_FOR_ARG</strong> <em>(rtx <var>arg</var>, rtx <var>slot</var>, rtx <var>bounds</var>, rtx <var>slot_no</var>)</em></dt>
  233. <dd><p>This hook is used by expand pass to emit insns to store <var>bounds</var> of
  234. <var>arg</var> passed in <var>slot</var>. Expand pass uses this hook in case
  235. <var>bounds</var> of <var>arg</var> are not passed in register. If <var>slot</var> is a
  236. memory, then <var>bounds</var> are stored as for regular pointer stored in
  237. memory. If <var>slot</var> is not a memory then <var>slot_no</var> is an integer
  238. constant holding number of the target dependent special slot which
  239. should be used to store <var>bounds</var>.
  240. </p></dd></dl>
  241. <dl>
  242. <dt><a name="index-TARGET_005fLOAD_005fRETURNED_005fBOUNDS"></a>Target Hook: <em>rtx</em> <strong>TARGET_LOAD_RETURNED_BOUNDS</strong> <em>(rtx <var>slot</var>)</em></dt>
  243. <dd><p>This hook is used by expand pass to emit insn to load bounds
  244. returned by function call in <var>slot</var>. Hook returns RTX holding
  245. loaded bounds.
  246. </p></dd></dl>
  247. <dl>
  248. <dt><a name="index-TARGET_005fSTORE_005fRETURNED_005fBOUNDS"></a>Target Hook: <em>void</em> <strong>TARGET_STORE_RETURNED_BOUNDS</strong> <em>(rtx <var>slot</var>, rtx <var>bounds</var>)</em></dt>
  249. <dd><p>This hook is used by expand pass to emit insn to store <var>bounds</var>
  250. returned by function call into <var>slot</var>.
  251. </p></dd></dl>
  252. <hr>
  253. <div class="header">
  254. <p>
  255. Next: <a href="Trampolines.html#Trampolines" accesskey="n" rel="next">Trampolines</a>, Previous: <a href="Stack-and-Calling.html#Stack-and-Calling" accesskey="p" rel="prev">Stack and Calling</a>, Up: <a href="Target-Macros.html#Target-Macros" accesskey="u" rel="up">Target Macros</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>
  256. </div>
  257. </body>
  258. </html>