Macros-for-Initialization.html 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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: Macros for Initialization</title>
  20. <meta name="description" content="GNU Compiler Collection (GCC) Internals: Macros for Initialization">
  21. <meta name="keywords" content="GNU Compiler Collection (GCC) Internals: Macros for Initialization">
  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="Assembler-Format.html#Assembler-Format" rel="up" title="Assembler Format">
  30. <link href="Instruction-Output.html#Instruction-Output" rel="next" title="Instruction Output">
  31. <link href="Initialization.html#Initialization" rel="prev" title="Initialization">
  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="Macros-for-Initialization"></a>
  63. <div class="header">
  64. <p>
  65. Next: <a href="Instruction-Output.html#Instruction-Output" accesskey="n" rel="next">Instruction Output</a>, Previous: <a href="Initialization.html#Initialization" accesskey="p" rel="prev">Initialization</a>, Up: <a href="Assembler-Format.html#Assembler-Format" accesskey="u" rel="up">Assembler Format</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="Macros-Controlling-Initialization-Routines"></a>
  69. <h4 class="subsection">17.20.6 Macros Controlling Initialization Routines</h4>
  70. <p>Here are the macros that control how the compiler handles initialization
  71. and termination functions:
  72. </p>
  73. <dl>
  74. <dt><a name="index-INIT_005fSECTION_005fASM_005fOP-1"></a>Macro: <strong>INIT_SECTION_ASM_OP</strong></dt>
  75. <dd><p>If defined, a C string constant, including spacing, for the assembler
  76. operation to identify the following data as initialization code. If not
  77. defined, GCC will assume such a section does not exist. When you are
  78. using special sections for initialization and termination functions, this
  79. macro also controls how <samp>crtstuff.c</samp> and <samp>libgcc2.c</samp> arrange to
  80. run the initialization functions.
  81. </p></dd></dl>
  82. <dl>
  83. <dt><a name="index-HAS_005fINIT_005fSECTION"></a>Macro: <strong>HAS_INIT_SECTION</strong></dt>
  84. <dd><p>If defined, <code>main</code> will not call <code>__main</code> as described above.
  85. This macro should be defined for systems that control start-up code
  86. on a symbol-by-symbol basis, such as OSF/1, and should not
  87. be defined explicitly for systems that support <code>INIT_SECTION_ASM_OP</code>.
  88. </p></dd></dl>
  89. <dl>
  90. <dt><a name="index-LD_005fINIT_005fSWITCH"></a>Macro: <strong>LD_INIT_SWITCH</strong></dt>
  91. <dd><p>If defined, a C string constant for a switch that tells the linker that
  92. the following symbol is an initialization routine.
  93. </p></dd></dl>
  94. <dl>
  95. <dt><a name="index-LD_005fFINI_005fSWITCH"></a>Macro: <strong>LD_FINI_SWITCH</strong></dt>
  96. <dd><p>If defined, a C string constant for a switch that tells the linker that
  97. the following symbol is a finalization routine.
  98. </p></dd></dl>
  99. <dl>
  100. <dt><a name="index-COLLECT_005fSHARED_005fINIT_005fFUNC"></a>Macro: <strong>COLLECT_SHARED_INIT_FUNC</strong> <em>(<var>stream</var>, <var>func</var>)</em></dt>
  101. <dd><p>If defined, a C statement that will write a function that can be
  102. automatically called when a shared library is loaded. The function
  103. should call <var>func</var>, which takes no arguments. If not defined, and
  104. the object format requires an explicit initialization function, then a
  105. function called <code>_GLOBAL__DI</code> will be generated.
  106. </p>
  107. <p>This function and the following one are used by collect2 when linking a
  108. shared library that needs constructors or destructors, or has DWARF2
  109. exception tables embedded in the code.
  110. </p></dd></dl>
  111. <dl>
  112. <dt><a name="index-COLLECT_005fSHARED_005fFINI_005fFUNC"></a>Macro: <strong>COLLECT_SHARED_FINI_FUNC</strong> <em>(<var>stream</var>, <var>func</var>)</em></dt>
  113. <dd><p>If defined, a C statement that will write a function that can be
  114. automatically called when a shared library is unloaded. The function
  115. should call <var>func</var>, which takes no arguments. If not defined, and
  116. the object format requires an explicit finalization function, then a
  117. function called <code>_GLOBAL__DD</code> will be generated.
  118. </p></dd></dl>
  119. <dl>
  120. <dt><a name="index-INVOKE_005f_005fmain"></a>Macro: <strong>INVOKE__main</strong></dt>
  121. <dd><p>If defined, <code>main</code> will call <code>__main</code> despite the presence of
  122. <code>INIT_SECTION_ASM_OP</code>. This macro should be defined for systems
  123. where the init section is not actually run automatically, but is still
  124. useful for collecting the lists of constructors and destructors.
  125. </p></dd></dl>
  126. <dl>
  127. <dt><a name="index-SUPPORTS_005fINIT_005fPRIORITY"></a>Macro: <strong>SUPPORTS_INIT_PRIORITY</strong></dt>
  128. <dd><p>If nonzero, the C++ <code>init_priority</code> attribute is supported and the
  129. compiler should emit instructions to control the order of initialization
  130. of objects. If zero, the compiler will issue an error message upon
  131. encountering an <code>init_priority</code> attribute.
  132. </p></dd></dl>
  133. <dl>
  134. <dt><a name="index-TARGET_005fHAVE_005fCTORS_005fDTORS"></a>Target Hook: <em>bool</em> <strong>TARGET_HAVE_CTORS_DTORS</strong></dt>
  135. <dd><p>This value is true if the target supports some &ldquo;native&rdquo; method of
  136. collecting constructors and destructors to be run at startup and exit.
  137. It is false if we must use <code>collect2</code>.
  138. </p></dd></dl>
  139. <dl>
  140. <dt><a name="index-TARGET_005fASM_005fCONSTRUCTOR"></a>Target Hook: <em>void</em> <strong>TARGET_ASM_CONSTRUCTOR</strong> <em>(rtx <var>symbol</var>, int <var>priority</var>)</em></dt>
  141. <dd><p>If defined, a function that outputs assembler code to arrange to call
  142. the function referenced by <var>symbol</var> at initialization time.
  143. </p>
  144. <p>Assume that <var>symbol</var> is a <code>SYMBOL_REF</code> for a function taking
  145. no arguments and with no return value. If the target supports initialization
  146. priorities, <var>priority</var> is a value between 0 and <code>MAX_INIT_PRIORITY</code>;
  147. otherwise it must be <code>DEFAULT_INIT_PRIORITY</code>.
  148. </p>
  149. <p>If this macro is not defined by the target, a suitable default will
  150. be chosen if (1) the target supports arbitrary section names, (2) the
  151. target defines <code>CTORS_SECTION_ASM_OP</code>, or (3) <code>USE_COLLECT2</code>
  152. is not defined.
  153. </p></dd></dl>
  154. <dl>
  155. <dt><a name="index-TARGET_005fASM_005fDESTRUCTOR"></a>Target Hook: <em>void</em> <strong>TARGET_ASM_DESTRUCTOR</strong> <em>(rtx <var>symbol</var>, int <var>priority</var>)</em></dt>
  156. <dd><p>This is like <code>TARGET_ASM_CONSTRUCTOR</code> but used for termination
  157. functions rather than initialization functions.
  158. </p></dd></dl>
  159. <p>If <code>TARGET_HAVE_CTORS_DTORS</code> is true, the initialization routine
  160. generated for the generated object file will have static linkage.
  161. </p>
  162. <p>If your system uses <code>collect2</code> as the means of processing
  163. constructors, then that program normally uses <code>nm</code> to scan
  164. an object file for constructor functions to be called.
  165. </p>
  166. <p>On certain kinds of systems, you can define this macro to make
  167. <code>collect2</code> work faster (and, in some cases, make it work at all):
  168. </p>
  169. <dl>
  170. <dt><a name="index-OBJECT_005fFORMAT_005fCOFF"></a>Macro: <strong>OBJECT_FORMAT_COFF</strong></dt>
  171. <dd><p>Define this macro if the system uses COFF (Common Object File Format)
  172. object files, so that <code>collect2</code> can assume this format and scan
  173. object files directly for dynamic constructor/destructor functions.
  174. </p>
  175. <p>This macro is effective only in a native compiler; <code>collect2</code> as
  176. part of a cross compiler always uses <code>nm</code> for the target machine.
  177. </p></dd></dl>
  178. <dl>
  179. <dt><a name="index-REAL_005fNM_005fFILE_005fNAME"></a>Macro: <strong>REAL_NM_FILE_NAME</strong></dt>
  180. <dd><p>Define this macro as a C string constant containing the file name to use
  181. to execute <code>nm</code>. The default is to search the path normally for
  182. <code>nm</code>.
  183. </p></dd></dl>
  184. <dl>
  185. <dt><a name="index-NM_005fFLAGS"></a>Macro: <strong>NM_FLAGS</strong></dt>
  186. <dd><p><code>collect2</code> calls <code>nm</code> to scan object files for static
  187. constructors and destructors and LTO info. By default, <samp>-n</samp> is
  188. passed. Define <code>NM_FLAGS</code> to a C string constant if other options
  189. are needed to get the same output format as GNU <code>nm -n</code>
  190. produces.
  191. </p></dd></dl>
  192. <p>If your system supports shared libraries and has a program to list the
  193. dynamic dependencies of a given library or executable, you can define
  194. these macros to enable support for running initialization and
  195. termination functions in shared libraries:
  196. </p>
  197. <dl>
  198. <dt><a name="index-LDD_005fSUFFIX"></a>Macro: <strong>LDD_SUFFIX</strong></dt>
  199. <dd><p>Define this macro to a C string constant containing the name of the program
  200. which lists dynamic dependencies, like <code>ldd</code> under SunOS 4.
  201. </p></dd></dl>
  202. <dl>
  203. <dt><a name="index-PARSE_005fLDD_005fOUTPUT"></a>Macro: <strong>PARSE_LDD_OUTPUT</strong> <em>(<var>ptr</var>)</em></dt>
  204. <dd><p>Define this macro to be C code that extracts filenames from the output
  205. of the program denoted by <code>LDD_SUFFIX</code>. <var>ptr</var> is a variable
  206. of type <code>char *</code> that points to the beginning of a line of output
  207. from <code>LDD_SUFFIX</code>. If the line lists a dynamic dependency, the
  208. code must advance <var>ptr</var> to the beginning of the filename on that
  209. line. Otherwise, it must set <var>ptr</var> to <code>NULL</code>.
  210. </p></dd></dl>
  211. <dl>
  212. <dt><a name="index-SHLIB_005fSUFFIX"></a>Macro: <strong>SHLIB_SUFFIX</strong></dt>
  213. <dd><p>Define this macro to a C string constant containing the default shared
  214. library extension of the target (e.g., &lsquo;<samp>&quot;.so&quot;</samp>&rsquo;). <code>collect2</code>
  215. strips version information after this suffix when generating global
  216. constructor and destructor names. This define is only needed on targets
  217. that use <code>collect2</code> to process constructors and destructors.
  218. </p></dd></dl>
  219. <hr>
  220. <div class="header">
  221. <p>
  222. Next: <a href="Instruction-Output.html#Instruction-Output" accesskey="n" rel="next">Instruction Output</a>, Previous: <a href="Initialization.html#Initialization" accesskey="p" rel="prev">Initialization</a>, Up: <a href="Assembler-Format.html#Assembler-Format" accesskey="u" rel="up">Assembler Format</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>
  223. </div>
  224. </body>
  225. </html>