Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

326 lines
17KB

  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>Function Entry (GNU Compiler Collection (GCC) Internals)</title>
  21. <meta name="description" content="Function Entry (GNU Compiler Collection (GCC) Internals)">
  22. <meta name="keywords" content="Function Entry (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="Profiling.html#Profiling" rel="next" title="Profiling">
  31. <link href="Caller-Saves.html#Caller-Saves" rel="prev" title="Caller Saves">
  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="Function-Entry"></a>
  62. <div class="header">
  63. <p>
  64. Next: <a href="Profiling.html#Profiling" accesskey="n" rel="next">Profiling</a>, Previous: <a href="Caller-Saves.html#Caller-Saves" accesskey="p" rel="prev">Caller Saves</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="Function-Entry-and-Exit"></a>
  68. <h4 class="subsection">18.9.11 Function Entry and Exit</h4>
  69. <a name="index-function-entry-and-exit"></a>
  70. <a name="index-prologue"></a>
  71. <a name="index-epilogue"></a>
  72. <p>This section describes the macros that output function entry
  73. (<em>prologue</em>) and exit (<em>epilogue</em>) code.
  74. </p>
  75. <dl>
  76. <dt><a name="index-TARGET_005fASM_005fPRINT_005fPATCHABLE_005fFUNCTION_005fENTRY"></a>Target Hook: <em>void</em> <strong>TARGET_ASM_PRINT_PATCHABLE_FUNCTION_ENTRY</strong> <em>(FILE *<var>file</var>, unsigned HOST_WIDE_INT <var>patch_area_size</var>, bool <var>record_p</var>)</em></dt>
  77. <dd><p>Generate a patchable area at the function start, consisting of
  78. <var>patch_area_size</var> NOP instructions. If the target supports named
  79. sections and if <var>record_p</var> is true, insert a pointer to the current
  80. location in the table of patchable functions. The default implementation
  81. of the hook places the table of pointers in the special section named
  82. <code>__patchable_function_entries</code>.
  83. </p></dd></dl>
  84. <dl>
  85. <dt><a name="index-TARGET_005fASM_005fFUNCTION_005fPROLOGUE"></a>Target Hook: <em>void</em> <strong>TARGET_ASM_FUNCTION_PROLOGUE</strong> <em>(FILE *<var>file</var>)</em></dt>
  86. <dd><p>If defined, a function that outputs the assembler code for entry to a
  87. function. The prologue is responsible for setting up the stack frame,
  88. initializing the frame pointer register, saving registers that must be
  89. saved, and allocating <var>size</var> additional bytes of storage for the
  90. local variables. <var>file</var> is a stdio stream to which the assembler
  91. code should be output.
  92. </p>
  93. <p>The label for the beginning of the function need not be output by this
  94. macro. That has already been done when the macro is run.
  95. </p>
  96. <a name="index-regs_005fever_005flive"></a>
  97. <p>To determine which registers to save, the macro can refer to the array
  98. <code>regs_ever_live</code>: element <var>r</var> is nonzero if hard register
  99. <var>r</var> is used anywhere within the function. This implies the function
  100. prologue should save register <var>r</var>, provided it is not one of the
  101. call-used registers. (<code>TARGET_ASM_FUNCTION_EPILOGUE</code> must likewise use
  102. <code>regs_ever_live</code>.)
  103. </p>
  104. <p>On machines that have &ldquo;register windows&rdquo;, the function entry code does
  105. not save on the stack the registers that are in the windows, even if
  106. they are supposed to be preserved by function calls; instead it takes
  107. appropriate steps to &ldquo;push&rdquo; the register stack, if any non-call-used
  108. registers are used in the function.
  109. </p>
  110. <a name="index-frame_005fpointer_005fneeded"></a>
  111. <p>On machines where functions may or may not have frame-pointers, the
  112. function entry code must vary accordingly; it must set up the frame
  113. pointer if one is wanted, and not otherwise. To determine whether a
  114. frame pointer is in wanted, the macro can refer to the variable
  115. <code>frame_pointer_needed</code>. The variable&rsquo;s value will be 1 at run
  116. time in a function that needs a frame pointer. See <a href="Elimination.html#Elimination">Elimination</a>.
  117. </p>
  118. <p>The function entry code is responsible for allocating any stack space
  119. required for the function. This stack space consists of the regions
  120. listed below. In most cases, these regions are allocated in the
  121. order listed, with the last listed region closest to the top of the
  122. stack (the lowest address if <code>STACK_GROWS_DOWNWARD</code> is defined, and
  123. the highest address if it is not defined). You can use a different order
  124. for a machine if doing so is more convenient or required for
  125. compatibility reasons. Except in cases where required by standard
  126. or by a debugger, there is no reason why the stack layout used by GCC
  127. need agree with that used by other compilers for a machine.
  128. </p></dd></dl>
  129. <dl>
  130. <dt><a name="index-TARGET_005fASM_005fFUNCTION_005fEND_005fPROLOGUE"></a>Target Hook: <em>void</em> <strong>TARGET_ASM_FUNCTION_END_PROLOGUE</strong> <em>(FILE *<var>file</var>)</em></dt>
  131. <dd><p>If defined, a function that outputs assembler code at the end of a
  132. prologue. This should be used when the function prologue is being
  133. emitted as RTL, and you have some extra assembler that needs to be
  134. emitted. See <a href="Standard-Names.html#prologue-instruction-pattern">prologue instruction pattern</a>.
  135. </p></dd></dl>
  136. <dl>
  137. <dt><a name="index-TARGET_005fASM_005fFUNCTION_005fBEGIN_005fEPILOGUE"></a>Target Hook: <em>void</em> <strong>TARGET_ASM_FUNCTION_BEGIN_EPILOGUE</strong> <em>(FILE *<var>file</var>)</em></dt>
  138. <dd><p>If defined, a function that outputs assembler code at the start of an
  139. epilogue. This should be used when the function epilogue is being
  140. emitted as RTL, and you have some extra assembler that needs to be
  141. emitted. See <a href="Standard-Names.html#epilogue-instruction-pattern">epilogue instruction pattern</a>.
  142. </p></dd></dl>
  143. <dl>
  144. <dt><a name="index-TARGET_005fASM_005fFUNCTION_005fEPILOGUE"></a>Target Hook: <em>void</em> <strong>TARGET_ASM_FUNCTION_EPILOGUE</strong> <em>(FILE *<var>file</var>)</em></dt>
  145. <dd><p>If defined, a function that outputs the assembler code for exit from a
  146. function. The epilogue is responsible for restoring the saved
  147. registers and stack pointer to their values when the function was
  148. called, and returning control to the caller. This macro takes the
  149. same argument as the macro <code>TARGET_ASM_FUNCTION_PROLOGUE</code>, and the
  150. registers to restore are determined from <code>regs_ever_live</code> and
  151. <code>CALL_USED_REGISTERS</code> in the same way.
  152. </p>
  153. <p>On some machines, there is a single instruction that does all the work
  154. of returning from the function. On these machines, give that
  155. instruction the name &lsquo;<samp>return</samp>&rsquo; and do not define the macro
  156. <code>TARGET_ASM_FUNCTION_EPILOGUE</code> at all.
  157. </p>
  158. <p>Do not define a pattern named &lsquo;<samp>return</samp>&rsquo; if you want the
  159. <code>TARGET_ASM_FUNCTION_EPILOGUE</code> to be used. If you want the target
  160. switches to control whether return instructions or epilogues are used,
  161. define a &lsquo;<samp>return</samp>&rsquo; pattern with a validity condition that tests the
  162. target switches appropriately. If the &lsquo;<samp>return</samp>&rsquo; pattern&rsquo;s validity
  163. condition is false, epilogues will be used.
  164. </p>
  165. <p>On machines where functions may or may not have frame-pointers, the
  166. function exit code must vary accordingly. Sometimes the code for these
  167. two cases is completely different. To determine whether a frame pointer
  168. is wanted, the macro can refer to the variable
  169. <code>frame_pointer_needed</code>. The variable&rsquo;s value will be 1 when compiling
  170. a function that needs a frame pointer.
  171. </p>
  172. <p>Normally, <code>TARGET_ASM_FUNCTION_PROLOGUE</code> and
  173. <code>TARGET_ASM_FUNCTION_EPILOGUE</code> must treat leaf functions specially.
  174. The C variable <code>current_function_is_leaf</code> is nonzero for such a
  175. function. See <a href="Leaf-Functions.html#Leaf-Functions">Leaf Functions</a>.
  176. </p>
  177. <p>On some machines, some functions pop their arguments on exit while
  178. others leave that for the caller to do. For example, the 68020 when
  179. given <samp>-mrtd</samp> pops arguments in functions that take a fixed
  180. number of arguments.
  181. </p>
  182. <a name="index-pops_005fargs"></a>
  183. <a name="index-crtl_002d_003eargs_002epops_005fargs"></a>
  184. <p>Your definition of the macro <code>RETURN_POPS_ARGS</code> decides which
  185. functions pop their own arguments. <code>TARGET_ASM_FUNCTION_EPILOGUE</code>
  186. needs to know what was decided. The number of bytes of the current
  187. function&rsquo;s arguments that this function should pop is available in
  188. <code>crtl-&gt;args.pops_args</code>. See <a href="Scalar-Return.html#Scalar-Return">Scalar Return</a>.
  189. </p></dd></dl>
  190. <ul>
  191. <li> <a name="index-pretend_005fargs_005fsize"></a>
  192. <a name="index-crtl_002d_003eargs_002epretend_005fargs_005fsize"></a>
  193. A region of <code>crtl-&gt;args.pretend_args_size</code> bytes of
  194. uninitialized space just underneath the first argument arriving on the
  195. stack. (This may not be at the very start of the allocated stack region
  196. if the calling sequence has pushed anything else since pushing the stack
  197. arguments. But usually, on such machines, nothing else has been pushed
  198. yet, because the function prologue itself does all the pushing.) This
  199. region is used on machines where an argument may be passed partly in
  200. registers and partly in memory, and, in some cases to support the
  201. features in <code>&lt;stdarg.h&gt;</code>.
  202. </li><li> An area of memory used to save certain registers used by the function.
  203. The size of this area, which may also include space for such things as
  204. the return address and pointers to previous stack frames, is
  205. machine-specific and usually depends on which registers have been used
  206. in the function. Machines with register windows often do not require
  207. a save area.
  208. </li><li> A region of at least <var>size</var> bytes, possibly rounded up to an allocation
  209. boundary, to contain the local variables of the function. On some machines,
  210. this region and the save area may occur in the opposite order, with the
  211. save area closer to the top of the stack.
  212. </li><li> <a name="index-ACCUMULATE_005fOUTGOING_005fARGS-and-stack-frames"></a>
  213. Optionally, when <code>ACCUMULATE_OUTGOING_ARGS</code> is defined, a region of
  214. <code>crtl-&gt;outgoing_args_size</code> bytes to be used for outgoing
  215. argument lists of the function. See <a href="Stack-Arguments.html#Stack-Arguments">Stack Arguments</a>.
  216. </li></ul>
  217. <dl>
  218. <dt><a name="index-EXIT_005fIGNORE_005fSTACK"></a>Macro: <strong>EXIT_IGNORE_STACK</strong></dt>
  219. <dd><p>Define this macro as a C expression that is nonzero if the return
  220. instruction or the function epilogue ignores the value of the stack
  221. pointer; in other words, if it is safe to delete an instruction to
  222. adjust the stack pointer before a return from the function. The
  223. default is 0.
  224. </p>
  225. <p>Note that this macro&rsquo;s value is relevant only for functions for which
  226. frame pointers are maintained. It is never safe to delete a final
  227. stack adjustment in a function that has no frame pointer, and the
  228. compiler knows this regardless of <code>EXIT_IGNORE_STACK</code>.
  229. </p></dd></dl>
  230. <dl>
  231. <dt><a name="index-EPILOGUE_005fUSES"></a>Macro: <strong>EPILOGUE_USES</strong> <em>(<var>regno</var>)</em></dt>
  232. <dd><p>Define this macro as a C expression that is nonzero for registers that are
  233. used by the epilogue or the &lsquo;<samp>return</samp>&rsquo; pattern. The stack and frame
  234. pointer registers are already assumed to be used as needed.
  235. </p></dd></dl>
  236. <dl>
  237. <dt><a name="index-EH_005fUSES"></a>Macro: <strong>EH_USES</strong> <em>(<var>regno</var>)</em></dt>
  238. <dd><p>Define this macro as a C expression that is nonzero for registers that are
  239. used by the exception handling mechanism, and so should be considered live
  240. on entry to an exception edge.
  241. </p></dd></dl>
  242. <dl>
  243. <dt><a name="index-TARGET_005fASM_005fOUTPUT_005fMI_005fTHUNK"></a>Target Hook: <em>void</em> <strong>TARGET_ASM_OUTPUT_MI_THUNK</strong> <em>(FILE *<var>file</var>, tree <var>thunk_fndecl</var>, HOST_WIDE_INT <var>delta</var>, HOST_WIDE_INT <var>vcall_offset</var>, tree <var>function</var>)</em></dt>
  244. <dd><p>A function that outputs the assembler code for a thunk
  245. function, used to implement C++ virtual function calls with multiple
  246. inheritance. The thunk acts as a wrapper around a virtual function,
  247. adjusting the implicit object parameter before handing control off to
  248. the real function.
  249. </p>
  250. <p>First, emit code to add the integer <var>delta</var> to the location that
  251. contains the incoming first argument. Assume that this argument
  252. contains a pointer, and is the one used to pass the <code>this</code> pointer
  253. in C++. This is the incoming argument <em>before</em> the function prologue,
  254. e.g. &lsquo;<samp>%o0</samp>&rsquo; on a sparc. The addition must preserve the values of
  255. all other incoming arguments.
  256. </p>
  257. <p>Then, if <var>vcall_offset</var> is nonzero, an additional adjustment should be
  258. made after adding <code>delta</code>. In particular, if <var>p</var> is the
  259. adjusted pointer, the following adjustment should be made:
  260. </p>
  261. <div class="smallexample">
  262. <pre class="smallexample">p += (*((ptrdiff_t **)p))[vcall_offset/sizeof(ptrdiff_t)]
  263. </pre></div>
  264. <p>After the additions, emit code to jump to <var>function</var>, which is a
  265. <code>FUNCTION_DECL</code>. This is a direct pure jump, not a call, and does
  266. not touch the return address. Hence returning from <var>FUNCTION</var> will
  267. return to whoever called the current &lsquo;<samp>thunk</samp>&rsquo;.
  268. </p>
  269. <p>The effect must be as if <var>function</var> had been called directly with
  270. the adjusted first argument. This macro is responsible for emitting all
  271. of the code for a thunk function; <code>TARGET_ASM_FUNCTION_PROLOGUE</code>
  272. and <code>TARGET_ASM_FUNCTION_EPILOGUE</code> are not invoked.
  273. </p>
  274. <p>The <var>thunk_fndecl</var> is redundant. (<var>delta</var> and <var>function</var>
  275. have already been extracted from it.) It might possibly be useful on
  276. some targets, but probably not.
  277. </p>
  278. <p>If you do not define this macro, the target-independent code in the C++
  279. front end will generate a less efficient heavyweight thunk that calls
  280. <var>function</var> instead of jumping to it. The generic approach does
  281. not support varargs.
  282. </p></dd></dl>
  283. <dl>
  284. <dt><a name="index-TARGET_005fASM_005fCAN_005fOUTPUT_005fMI_005fTHUNK"></a>Target Hook: <em>bool</em> <strong>TARGET_ASM_CAN_OUTPUT_MI_THUNK</strong> <em>(const_tree <var>thunk_fndecl</var>, HOST_WIDE_INT <var>delta</var>, HOST_WIDE_INT <var>vcall_offset</var>, const_tree <var>function</var>)</em></dt>
  285. <dd><p>A function that returns true if TARGET_ASM_OUTPUT_MI_THUNK would be able
  286. to output the assembler code for the thunk function specified by the
  287. arguments it is passed, and false otherwise. In the latter case, the
  288. generic approach will be used by the C++ front end, with the limitations
  289. previously exposed.
  290. </p></dd></dl>
  291. <hr>
  292. <div class="header">
  293. <p>
  294. Next: <a href="Profiling.html#Profiling" accesskey="n" rel="next">Profiling</a>, Previous: <a href="Caller-Saves.html#Caller-Saves" accesskey="p" rel="prev">Caller Saves</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>
  295. </div>
  296. </body>
  297. </html>