Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

171 Zeilen
8.3KB

  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>WHOPR (GNU Compiler Collection (GCC) Internals)</title>
  21. <meta name="description" content="WHOPR (GNU Compiler Collection (GCC) Internals)">
  22. <meta name="keywords" content="WHOPR (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="LTO.html#LTO" rel="up" title="LTO">
  30. <link href="Internal-flags.html#Internal-flags" rel="next" title="Internal flags">
  31. <link href="IPA.html#IPA" rel="prev" title="IPA">
  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="WHOPR"></a>
  62. <div class="header">
  63. <p>
  64. Next: <a href="Internal-flags.html#Internal-flags" accesskey="n" rel="next">Internal flags</a>, Previous: <a href="IPA.html#IPA" accesskey="p" rel="prev">IPA</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>
  65. </div>
  66. <hr>
  67. <a name="Whole-program-assumptions_002c-linker-plugin-and-symbol-visibilities"></a>
  68. <h3 class="section">25.4 Whole program assumptions, linker plugin and symbol visibilities</h3>
  69. <p>Link-time optimization gives relatively minor benefits when used
  70. alone. The problem is that propagation of inter-procedural
  71. information does not work well across functions and variables
  72. that are called or referenced by other compilation units (such as
  73. from a dynamically linked library). We say that such functions
  74. and variables are <em>externally visible</em>.
  75. </p>
  76. <p>To make the situation even more difficult, many applications
  77. organize themselves as a set of shared libraries, and the default
  78. ELF visibility rules allow one to overwrite any externally
  79. visible symbol with a different symbol at runtime. This
  80. basically disables any optimizations across such functions and
  81. variables, because the compiler cannot be sure that the function
  82. body it is seeing is the same function body that will be used at
  83. runtime. Any function or variable not declared <code>static</code> in
  84. the sources degrades the quality of inter-procedural
  85. optimization.
  86. </p>
  87. <p>To avoid this problem the compiler must assume that it sees the
  88. whole program when doing link-time optimization. Strictly
  89. speaking, the whole program is rarely visible even at link-time.
  90. Standard system libraries are usually linked dynamically or not
  91. provided with the link-time information. In GCC, the whole
  92. program option (<samp>-fwhole-program</samp>) asserts that every
  93. function and variable defined in the current compilation
  94. unit is static, except for function <code>main</code> (note: at
  95. link time, the current unit is the union of all objects compiled
  96. with LTO). Since some functions and variables need to
  97. be referenced externally, for example by another DSO or from an
  98. assembler file, GCC also provides the function and variable
  99. attribute <code>externally_visible</code> which can be used to disable
  100. the effect of <samp>-fwhole-program</samp> on a specific symbol.
  101. </p>
  102. <p>The whole program mode assumptions are slightly more complex in
  103. C++, where inline functions in headers are put into <em>COMDAT</em>
  104. sections. COMDAT function and variables can be defined by
  105. multiple object files and their bodies are unified at link-time
  106. and dynamic link-time. COMDAT functions are changed to local only
  107. when their address is not taken and thus un-sharing them with a
  108. library is not harmful. COMDAT variables always remain externally
  109. visible, however for readonly variables it is assumed that their
  110. initializers cannot be overwritten by a different value.
  111. </p>
  112. <p>GCC provides the function and variable attribute
  113. <code>visibility</code> that can be used to specify the visibility of
  114. externally visible symbols (or alternatively an
  115. <samp>-fdefault-visibility</samp> command line option). ELF defines
  116. the <code>default</code>, <code>protected</code>, <code>hidden</code> and
  117. <code>internal</code> visibilities.
  118. </p>
  119. <p>The most commonly used is visibility is <code>hidden</code>. It
  120. specifies that the symbol cannot be referenced from outside of
  121. the current shared library. Unfortunately, this information
  122. cannot be used directly by the link-time optimization in the
  123. compiler since the whole shared library also might contain
  124. non-LTO objects and those are not visible to the compiler.
  125. </p>
  126. <p>GCC solves this problem using linker plugins. A <em>linker
  127. plugin</em> is an interface to the linker that allows an external
  128. program to claim the ownership of a given object file. The linker
  129. then performs the linking procedure by querying the plugin about
  130. the symbol table of the claimed objects and once the linking
  131. decisions are complete, the plugin is allowed to provide the
  132. final object file before the actual linking is made. The linker
  133. plugin obtains the symbol resolution information which specifies
  134. which symbols provided by the claimed objects are bound from the
  135. rest of a binary being linked.
  136. </p>
  137. <p>GCC is designed to be independent of the rest of the toolchain
  138. and aims to support linkers without plugin support. For this
  139. reason it does not use the linker plugin by default. Instead,
  140. the object files are examined by <code>collect2</code> before being
  141. passed to the linker and objects found to have LTO sections are
  142. passed to <code>lto1</code> first. This mode does not work for
  143. library archives. The decision on what object files from the
  144. archive are needed depends on the actual linking and thus GCC
  145. would have to implement the linker itself. The resolution
  146. information is missing too and thus GCC needs to make an educated
  147. guess based on <samp>-fwhole-program</samp>. Without the linker
  148. plugin GCC also assumes that symbols are declared <code>hidden</code>
  149. and not referred by non-LTO code by default.
  150. </p>
  151. <hr>
  152. <div class="header">
  153. <p>
  154. Next: <a href="Internal-flags.html#Internal-flags" accesskey="n" rel="next">Internal flags</a>, Previous: <a href="IPA.html#IPA" accesskey="p" rel="prev">IPA</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>
  155. </div>
  156. </body>
  157. </html>