File-Framework.html 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  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: File Framework</title>
  20. <meta name="description" content="GNU Compiler Collection (GCC) Internals: File Framework">
  21. <meta name="keywords" content="GNU Compiler Collection (GCC) Internals: File Framework">
  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="Data-Output.html#Data-Output" rel="next" title="Data Output">
  31. <link href="Assembler-Format.html#Assembler-Format" rel="prev" title="Assembler Format">
  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="File-Framework"></a>
  63. <div class="header">
  64. <p>
  65. Next: <a href="Data-Output.html#Data-Output" accesskey="n" rel="next">Data Output</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="The-Overall-Framework-of-an-Assembler-File"></a>
  69. <h4 class="subsection">17.20.1 The Overall Framework of an Assembler File</h4>
  70. <a name="index-assembler-format"></a>
  71. <a name="index-output-of-assembler-code"></a>
  72. <p>This describes the overall framework of an assembly file.
  73. </p>
  74. <a name="index-default_005ffile_005fstart"></a>
  75. <dl>
  76. <dt><a name="index-TARGET_005fASM_005fFILE_005fSTART"></a>Target Hook: <em>void</em> <strong>TARGET_ASM_FILE_START</strong> <em>(void)</em></dt>
  77. <dd><p>Output to <code>asm_out_file</code> any text which the assembler expects to
  78. find at the beginning of a file. The default behavior is controlled
  79. by two flags, documented below. Unless your target&rsquo;s assembler is
  80. quite unusual, if you override the default, you should call
  81. <code>default_file_start</code> at some point in your target hook. This
  82. lets other target files rely on these variables.
  83. </p></dd></dl>
  84. <dl>
  85. <dt><a name="index-TARGET_005fASM_005fFILE_005fSTART_005fAPP_005fOFF"></a>Target Hook: <em>bool</em> <strong>TARGET_ASM_FILE_START_APP_OFF</strong></dt>
  86. <dd><p>If this flag is true, the text of the macro <code>ASM_APP_OFF</code> will be
  87. printed as the very first line in the assembly file, unless
  88. <samp>-fverbose-asm</samp> is in effect. (If that macro has been defined
  89. to the empty string, this variable has no effect.) With the normal
  90. definition of <code>ASM_APP_OFF</code>, the effect is to notify the GNU
  91. assembler that it need not bother stripping comments or extra
  92. whitespace from its input. This allows it to work a bit faster.
  93. </p>
  94. <p>The default is false. You should not set it to true unless you have
  95. verified that your port does not generate any extra whitespace or
  96. comments that will cause GAS to issue errors in NO_APP mode.
  97. </p></dd></dl>
  98. <dl>
  99. <dt><a name="index-TARGET_005fASM_005fFILE_005fSTART_005fFILE_005fDIRECTIVE"></a>Target Hook: <em>bool</em> <strong>TARGET_ASM_FILE_START_FILE_DIRECTIVE</strong></dt>
  100. <dd><p>If this flag is true, <code>output_file_directive</code> will be called
  101. for the primary source file, immediately after printing
  102. <code>ASM_APP_OFF</code> (if that is enabled). Most ELF assemblers expect
  103. this to be done. The default is false.
  104. </p></dd></dl>
  105. <dl>
  106. <dt><a name="index-TARGET_005fASM_005fFILE_005fEND"></a>Target Hook: <em>void</em> <strong>TARGET_ASM_FILE_END</strong> <em>(void)</em></dt>
  107. <dd><p>Output to <code>asm_out_file</code> any text which the assembler expects
  108. to find at the end of a file. The default is to output nothing.
  109. </p></dd></dl>
  110. <dl>
  111. <dt><a name="index-file_005fend_005findicate_005fexec_005fstack"></a>Function: <em>void</em> <strong>file_end_indicate_exec_stack</strong> <em>()</em></dt>
  112. <dd><p>Some systems use a common convention, the &lsquo;<samp>.note.GNU-stack</samp>&rsquo;
  113. special section, to indicate whether or not an object file relies on
  114. the stack being executable. If your system uses this convention, you
  115. should define <code>TARGET_ASM_FILE_END</code> to this function. If you
  116. need to do other things in that hook, have your hook function call
  117. this function.
  118. </p></dd></dl>
  119. <dl>
  120. <dt><a name="index-TARGET_005fASM_005fLTO_005fSTART"></a>Target Hook: <em>void</em> <strong>TARGET_ASM_LTO_START</strong> <em>(void)</em></dt>
  121. <dd><p>Output to <code>asm_out_file</code> any text which the assembler expects
  122. to find at the start of an LTO section. The default is to output
  123. nothing.
  124. </p></dd></dl>
  125. <dl>
  126. <dt><a name="index-TARGET_005fASM_005fLTO_005fEND"></a>Target Hook: <em>void</em> <strong>TARGET_ASM_LTO_END</strong> <em>(void)</em></dt>
  127. <dd><p>Output to <code>asm_out_file</code> any text which the assembler expects
  128. to find at the end of an LTO section. The default is to output
  129. nothing.
  130. </p></dd></dl>
  131. <dl>
  132. <dt><a name="index-TARGET_005fASM_005fCODE_005fEND"></a>Target Hook: <em>void</em> <strong>TARGET_ASM_CODE_END</strong> <em>(void)</em></dt>
  133. <dd><p>Output to <code>asm_out_file</code> any text which is needed before emitting
  134. unwind info and debug info at the end of a file. Some targets emit
  135. here PIC setup thunks that cannot be emitted at the end of file,
  136. because they couldn&rsquo;t have unwind info then. The default is to output
  137. nothing.
  138. </p></dd></dl>
  139. <dl>
  140. <dt><a name="index-ASM_005fCOMMENT_005fSTART"></a>Macro: <strong>ASM_COMMENT_START</strong></dt>
  141. <dd><p>A C string constant describing how to begin a comment in the target
  142. assembler language. The compiler assumes that the comment will end at
  143. the end of the line.
  144. </p></dd></dl>
  145. <dl>
  146. <dt><a name="index-ASM_005fAPP_005fON"></a>Macro: <strong>ASM_APP_ON</strong></dt>
  147. <dd><p>A C string constant for text to be output before each <code>asm</code>
  148. statement or group of consecutive ones. Normally this is
  149. <code>&quot;#APP&quot;</code>, which is a comment that has no effect on most
  150. assemblers but tells the GNU assembler that it must check the lines
  151. that follow for all valid assembler constructs.
  152. </p></dd></dl>
  153. <dl>
  154. <dt><a name="index-ASM_005fAPP_005fOFF"></a>Macro: <strong>ASM_APP_OFF</strong></dt>
  155. <dd><p>A C string constant for text to be output after each <code>asm</code>
  156. statement or group of consecutive ones. Normally this is
  157. <code>&quot;#NO_APP&quot;</code>, which tells the GNU assembler to resume making the
  158. time-saving assumptions that are valid for ordinary compiler output.
  159. </p></dd></dl>
  160. <dl>
  161. <dt><a name="index-ASM_005fOUTPUT_005fSOURCE_005fFILENAME"></a>Macro: <strong>ASM_OUTPUT_SOURCE_FILENAME</strong> <em>(<var>stream</var>, <var>name</var>)</em></dt>
  162. <dd><p>A C statement to output COFF information or DWARF debugging information
  163. which indicates that filename <var>name</var> is the current source file to
  164. the stdio stream <var>stream</var>.
  165. </p>
  166. <p>This macro need not be defined if the standard form of output
  167. for the file format in use is appropriate.
  168. </p></dd></dl>
  169. <dl>
  170. <dt><a name="index-TARGET_005fASM_005fOUTPUT_005fSOURCE_005fFILENAME"></a>Target Hook: <em>void</em> <strong>TARGET_ASM_OUTPUT_SOURCE_FILENAME</strong> <em>(FILE *<var>file</var>, const char *<var>name</var>)</em></dt>
  171. <dd><p>Output COFF information or DWARF debugging information which indicates that filename <var>name</var> is the current source file to the stdio stream <var>file</var>.
  172. </p>
  173. <p>This target hook need not be defined if the standard form of output for the file format in use is appropriate.
  174. </p></dd></dl>
  175. <dl>
  176. <dt><a name="index-TARGET_005fASM_005fOUTPUT_005fIDENT"></a>Target Hook: <em>void</em> <strong>TARGET_ASM_OUTPUT_IDENT</strong> <em>(const char *<var>name</var>)</em></dt>
  177. <dd><p>Output a string based on <var>name</var>, suitable for the &lsquo;<samp>#ident</samp>&rsquo; directive, or the equivalent directive or pragma in non-C-family languages. If this hook is not defined, nothing is output for the &lsquo;<samp>#ident</samp>&rsquo; directive.
  178. </p></dd></dl>
  179. <dl>
  180. <dt><a name="index-OUTPUT_005fQUOTED_005fSTRING"></a>Macro: <strong>OUTPUT_QUOTED_STRING</strong> <em>(<var>stream</var>, <var>string</var>)</em></dt>
  181. <dd><p>A C statement to output the string <var>string</var> to the stdio stream
  182. <var>stream</var>. If you do not call the function <code>output_quoted_string</code>
  183. in your config files, GCC will only call it to output filenames to
  184. the assembler source. So you can use it to canonicalize the format
  185. of the filename using this macro.
  186. </p></dd></dl>
  187. <dl>
  188. <dt><a name="index-TARGET_005fASM_005fNAMED_005fSECTION"></a>Target Hook: <em>void</em> <strong>TARGET_ASM_NAMED_SECTION</strong> <em>(const char *<var>name</var>, unsigned int <var>flags</var>, tree <var>decl</var>)</em></dt>
  189. <dd><p>Output assembly directives to switch to section <var>name</var>. The section
  190. should have attributes as specified by <var>flags</var>, which is a bit mask
  191. of the <code>SECTION_*</code> flags defined in <samp>output.h</samp>. If <var>decl</var>
  192. is non-NULL, it is the <code>VAR_DECL</code> or <code>FUNCTION_DECL</code> with which
  193. this section is associated.
  194. </p></dd></dl>
  195. <dl>
  196. <dt><a name="index-TARGET_005fASM_005fELF_005fFLAGS_005fNUMERIC"></a>Target Hook: <em>bool</em> <strong>TARGET_ASM_ELF_FLAGS_NUMERIC</strong> <em>(unsigned int <var>flags</var>, unsigned int *<var>num</var>)</em></dt>
  197. <dd><p>This hook can be used to encode ELF section flags for which no letter
  198. code has been defined in the assembler. It is called by
  199. <code>default_asm_named_section</code> whenever the section flags need to be
  200. emitted in the assembler output. If the hook returns true, then the
  201. numerical value for ELF section flags should be calculated from
  202. <var>flags</var> and saved in <var>*num</var>; the value is printed out instead of the
  203. normal sequence of letter codes. If the hook is not defined, or if it
  204. returns false, then <var>num</var> is ignored and the traditional letter sequence
  205. is emitted.
  206. </p></dd></dl>
  207. <dl>
  208. <dt><a name="index-TARGET_005fASM_005fFUNCTION_005fSECTION"></a>Target Hook: <em>section *</em> <strong>TARGET_ASM_FUNCTION_SECTION</strong> <em>(tree <var>decl</var>, enum node_frequency <var>freq</var>, bool <var>startup</var>, bool <var>exit</var>)</em></dt>
  209. <dd><p>Return preferred text (sub)section for function <var>decl</var>.
  210. Main purpose of this function is to separate cold, normal and hot
  211. functions. <var>startup</var> is true when function is known to be used only
  212. at startup (from static constructors or it is <code>main()</code>).
  213. <var>exit</var> is true when function is known to be used only at exit
  214. (from static destructors).
  215. Return NULL if function should go to default text section.
  216. </p></dd></dl>
  217. <dl>
  218. <dt><a name="index-TARGET_005fASM_005fFUNCTION_005fSWITCHED_005fTEXT_005fSECTIONS"></a>Target Hook: <em>void</em> <strong>TARGET_ASM_FUNCTION_SWITCHED_TEXT_SECTIONS</strong> <em>(FILE *<var>file</var>, tree <var>decl</var>, bool <var>new_is_cold</var>)</em></dt>
  219. <dd><p>Used by the target to emit any assembler directives or additional labels needed when a function is partitioned between different sections. Output should be written to <var>file</var>. The function decl is available as <var>decl</var> and the new section is &lsquo;cold&rsquo; if <var>new_is_cold</var> is <code>true</code>.
  220. </p></dd></dl>
  221. <dl>
  222. <dt><a name="index-TARGET_005fHAVE_005fNAMED_005fSECTIONS"></a>Common Target Hook: <em>bool</em> <strong>TARGET_HAVE_NAMED_SECTIONS</strong></dt>
  223. <dd><p>This flag is true if the target supports <code>TARGET_ASM_NAMED_SECTION</code>.
  224. It must not be modified by command-line option processing.
  225. </p></dd></dl>
  226. <a name="TARGET_005fHAVE_005fSWITCHABLE_005fBSS_005fSECTIONS"></a><dl>
  227. <dt><a name="index-TARGET_005fHAVE_005fSWITCHABLE_005fBSS_005fSECTIONS"></a>Target Hook: <em>bool</em> <strong>TARGET_HAVE_SWITCHABLE_BSS_SECTIONS</strong></dt>
  228. <dd><p>This flag is true if we can create zeroed data by switching to a BSS
  229. section and then using <code>ASM_OUTPUT_SKIP</code> to allocate the space.
  230. This is true on most ELF targets.
  231. </p></dd></dl>
  232. <dl>
  233. <dt><a name="index-TARGET_005fSECTION_005fTYPE_005fFLAGS"></a>Target Hook: <em>unsigned int</em> <strong>TARGET_SECTION_TYPE_FLAGS</strong> <em>(tree <var>decl</var>, const char *<var>name</var>, int <var>reloc</var>)</em></dt>
  234. <dd><p>Choose a set of section attributes for use by <code>TARGET_ASM_NAMED_SECTION</code>
  235. based on a variable or function decl, a section name, and whether or not the
  236. declaration&rsquo;s initializer may contain runtime relocations. <var>decl</var> may be
  237. null, in which case read-write data should be assumed.
  238. </p>
  239. <p>The default version of this function handles choosing code vs data,
  240. read-only vs read-write data, and <code>flag_pic</code>. You should only
  241. need to override this if your target has special flags that might be
  242. set via <code>__attribute__</code>.
  243. </p></dd></dl>
  244. <dl>
  245. <dt><a name="index-TARGET_005fASM_005fRECORD_005fGCC_005fSWITCHES"></a>Target Hook: <em>int</em> <strong>TARGET_ASM_RECORD_GCC_SWITCHES</strong> <em>(print_switch_type <var>type</var>, const char *<var>text</var>)</em></dt>
  246. <dd><p>Provides the target with the ability to record the gcc command line
  247. switches that have been passed to the compiler, and options that are
  248. enabled. The <var>type</var> argument specifies what is being recorded.
  249. It can take the following values:
  250. </p>
  251. <dl compact="compact">
  252. <dt><code>SWITCH_TYPE_PASSED</code></dt>
  253. <dd><p><var>text</var> is a command line switch that has been set by the user.
  254. </p>
  255. </dd>
  256. <dt><code>SWITCH_TYPE_ENABLED</code></dt>
  257. <dd><p><var>text</var> is an option which has been enabled. This might be as a
  258. direct result of a command line switch, or because it is enabled by
  259. default or because it has been enabled as a side effect of a different
  260. command line switch. For example, the <samp>-O2</samp> switch enables
  261. various different individual optimization passes.
  262. </p>
  263. </dd>
  264. <dt><code>SWITCH_TYPE_DESCRIPTIVE</code></dt>
  265. <dd><p><var>text</var> is either NULL or some descriptive text which should be
  266. ignored. If <var>text</var> is NULL then it is being used to warn the
  267. target hook that either recording is starting or ending. The first
  268. time <var>type</var> is SWITCH_TYPE_DESCRIPTIVE and <var>text</var> is NULL, the
  269. warning is for start up and the second time the warning is for
  270. wind down. This feature is to allow the target hook to make any
  271. necessary preparations before it starts to record switches and to
  272. perform any necessary tidying up after it has finished recording
  273. switches.
  274. </p>
  275. </dd>
  276. <dt><code>SWITCH_TYPE_LINE_START</code></dt>
  277. <dd><p>This option can be ignored by this target hook.
  278. </p>
  279. </dd>
  280. <dt><code>SWITCH_TYPE_LINE_END</code></dt>
  281. <dd><p>This option can be ignored by this target hook.
  282. </p></dd>
  283. </dl>
  284. <p>The hook&rsquo;s return value must be zero. Other return values may be
  285. supported in the future.
  286. </p>
  287. <p>By default this hook is set to NULL, but an example implementation is
  288. provided for ELF based targets. Called <var>elf_record_gcc_switches</var>,
  289. it records the switches as ASCII text inside a new, string mergeable
  290. section in the assembler output file. The name of the new section is
  291. provided by the <code>TARGET_ASM_RECORD_GCC_SWITCHES_SECTION</code> target
  292. hook.
  293. </p></dd></dl>
  294. <dl>
  295. <dt><a name="index-TARGET_005fASM_005fRECORD_005fGCC_005fSWITCHES_005fSECTION"></a>Target Hook: <em>const char *</em> <strong>TARGET_ASM_RECORD_GCC_SWITCHES_SECTION</strong></dt>
  296. <dd><p>This is the name of the section that will be created by the example
  297. ELF implementation of the <code>TARGET_ASM_RECORD_GCC_SWITCHES</code> target
  298. hook.
  299. </p></dd></dl>
  300. <hr>
  301. <div class="header">
  302. <p>
  303. Next: <a href="Data-Output.html#Data-Output" accesskey="n" rel="next">Data Output</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>
  304. </div>
  305. </body>
  306. </html>