LTO-object-file-layout.html 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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: LTO object file layout</title>
  20. <meta name="description" content="GNU Compiler Collection (GCC) Internals: LTO object file layout">
  21. <meta name="keywords" content="GNU Compiler Collection (GCC) Internals: LTO object file layout">
  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="LTO.html#LTO" rel="up" title="LTO">
  30. <link href="IPA.html#IPA" rel="next" title="IPA">
  31. <link href="LTO-Overview.html#LTO-Overview" rel="prev" title="LTO Overview">
  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="LTO-object-file-layout"></a>
  63. <div class="header">
  64. <p>
  65. Next: <a href="IPA.html#IPA" accesskey="n" rel="next">IPA</a>, Previous: <a href="LTO-Overview.html#LTO-Overview" accesskey="p" rel="prev">LTO Overview</a>, Up: <a href="LTO.html#LTO" accesskey="u" rel="up">LTO</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="LTO-file-sections"></a>
  69. <h3 class="section">24.2 LTO file sections</h3>
  70. <p>LTO information is stored in several ELF sections inside object files.
  71. Data structures and enum codes for sections are defined in
  72. <samp>lto-streamer.h</samp>.
  73. </p>
  74. <p>These sections are emitted from <samp>lto-streamer-out.c</samp> and mapped
  75. in all at once from <samp>lto/lto.c</samp>:<code>lto_file_read</code>. The
  76. individual functions dealing with the reading/writing of each section
  77. are described below.
  78. </p>
  79. <ul>
  80. <li> Command line options (<code>.gnu.lto_.opts</code>)
  81. <p>This section contains the command line options used to generate the
  82. object files. This is used at link time to determine the optimization
  83. level and other settings when they are not explicitly specified at the
  84. linker command line.
  85. </p>
  86. <p>Currently, GCC does not support combining LTO object files compiled
  87. with different set of the command line options into a single binary.
  88. At link time, the options given on the command line and the options
  89. saved on all the files in a link-time set are applied globally. No
  90. attempt is made at validating the combination of flags (other than the
  91. usual validation done by option processing). This is implemented in
  92. <samp>lto/lto.c</samp>:<code>lto_read_all_file_options</code>.
  93. </p>
  94. </li><li> Symbol table (<code>.gnu.lto_.symtab</code>)
  95. <p>This table replaces the ELF symbol table for functions and variables
  96. represented in the LTO IL. Symbols used and exported by the optimized
  97. assembly code of &ldquo;fat&rdquo; objects might not match the ones used and
  98. exported by the intermediate code. This table is necessary because
  99. the intermediate code is less optimized and thus requires a separate
  100. symbol table.
  101. </p>
  102. <p>Additionally, the binary code in the &ldquo;fat&rdquo; object will lack a call
  103. to a function, since the call was optimized out at compilation time
  104. after the intermediate language was streamed out. In some special
  105. cases, the same optimization may not happen during link-time
  106. optimization. This would lead to an undefined symbol if only one
  107. symbol table was used.
  108. </p>
  109. <p>The symbol table is emitted in
  110. <samp>lto-streamer-out.c</samp>:<code>produce_symtab</code>.
  111. </p>
  112. </li><li> Global declarations and types (<code>.gnu.lto_.decls</code>)
  113. <p>This section contains an intermediate language dump of all
  114. declarations and types required to represent the callgraph, static
  115. variables and top-level debug info.
  116. </p>
  117. <p>The contents of this section are emitted in
  118. <samp>lto-streamer-out.c</samp>:<code>produce_asm_for_decls</code>. Types and
  119. symbols are emitted in a topological order that preserves the sharing
  120. of pointers when the file is read back in
  121. (<samp>lto.c</samp>:<code>read_cgraph_and_symbols</code>).
  122. </p>
  123. </li><li> The callgraph (<code>.gnu.lto_.cgraph</code>)
  124. <p>This section contains the basic data structure used by the GCC
  125. inter-procedural optimization infrastructure. This section stores an
  126. annotated multi-graph which represents the functions and call sites as
  127. well as the variables, aliases and top-level <code>asm</code> statements.
  128. </p>
  129. <p>This section is emitted in
  130. <samp>lto-streamer-out.c</samp>:<code>output_cgraph</code> and read in
  131. <samp>lto-cgraph.c</samp>:<code>input_cgraph</code>.
  132. </p>
  133. </li><li> IPA references (<code>.gnu.lto_.refs</code>)
  134. <p>This section contains references between function and static
  135. variables. It is emitted by <samp>lto-cgraph.c</samp>:<code>output_refs</code>
  136. and read by <samp>lto-cgraph.c</samp>:<code>input_refs</code>.
  137. </p>
  138. </li><li> Function bodies (<code>.gnu.lto_.function_body.&lt;name&gt;</code>)
  139. <p>This section contains function bodies in the intermediate language
  140. representation. Every function body is in a separate section to allow
  141. copying of the section independently to different object files or
  142. reading the function on demand.
  143. </p>
  144. <p>Functions are emitted in
  145. <samp>lto-streamer-out.c</samp>:<code>output_function</code> and read in
  146. <samp>lto-streamer-in.c</samp>:<code>input_function</code>.
  147. </p>
  148. </li><li> Static variable initializers (<code>.gnu.lto_.vars</code>)
  149. <p>This section contains all the symbols in the global variable pool. It
  150. is emitted by <samp>lto-cgraph.c</samp>:<code>output_varpool</code> and read in
  151. <samp>lto-cgraph.c</samp>:<code>input_cgraph</code>.
  152. </p>
  153. </li><li> Summaries and optimization summaries used by IPA passes
  154. (<code>.gnu.lto_.&lt;xxx&gt;</code>, where <code>&lt;xxx&gt;</code> is one of <code>jmpfuncs</code>,
  155. <code>pureconst</code> or <code>reference</code>)
  156. <p>These sections are used by IPA passes that need to emit summary
  157. information during LTO generation to be read and aggregated at
  158. link time. Each pass is responsible for implementing two pass manager
  159. hooks: one for writing the summary and another for reading it in. The
  160. format of these sections is entirely up to each individual pass. The
  161. only requirement is that the writer and reader hooks agree on the
  162. format.
  163. </p></li></ul>
  164. <hr>
  165. <div class="header">
  166. <p>
  167. Next: <a href="IPA.html#IPA" accesskey="n" rel="next">IPA</a>, Previous: <a href="LTO-Overview.html#LTO-Overview" accesskey="p" rel="prev">LTO Overview</a>, Up: <a href="LTO.html#LTO" accesskey="u" rel="up">LTO</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>
  168. </div>
  169. </body>
  170. </html>