Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

3 anos atrás
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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>Vague Linkage (Using the GNU Compiler Collection (GCC))</title>
  21. <meta name="description" content="Vague Linkage (Using the GNU Compiler Collection (GCC))">
  22. <meta name="keywords" content="Vague Linkage (Using the GNU Compiler Collection (GCC))">
  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="C_002b_002b-Extensions.html#C_002b_002b-Extensions" rel="up" title="C++ Extensions">
  30. <link href="C_002b_002b-Interface.html#C_002b_002b-Interface" rel="next" title="C++ Interface">
  31. <link href="Restricted-Pointers.html#Restricted-Pointers" rel="prev" title="Restricted Pointers">
  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="Vague-Linkage"></a>
  62. <div class="header">
  63. <p>
  64. Next: <a href="C_002b_002b-Interface.html#C_002b_002b-Interface" accesskey="n" rel="next">C++ Interface</a>, Previous: <a href="Restricted-Pointers.html#Restricted-Pointers" accesskey="p" rel="prev">Restricted Pointers</a>, Up: <a href="C_002b_002b-Extensions.html#C_002b_002b-Extensions" accesskey="u" rel="up">C++ Extensions</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="Vague-Linkage-1"></a>
  68. <h3 class="section">7.3 Vague Linkage</h3>
  69. <a name="index-vague-linkage"></a>
  70. <p>There are several constructs in C++ that require space in the object
  71. file but are not clearly tied to a single translation unit. We say that
  72. these constructs have &ldquo;vague linkage&rdquo;. Typically such constructs are
  73. emitted wherever they are needed, though sometimes we can be more
  74. clever.
  75. </p>
  76. <dl compact="compact">
  77. <dt>Inline Functions</dt>
  78. <dd><p>Inline functions are typically defined in a header file which can be
  79. included in many different compilations. Hopefully they can usually be
  80. inlined, but sometimes an out-of-line copy is necessary, if the address
  81. of the function is taken or if inlining fails. In general, we emit an
  82. out-of-line copy in all translation units where one is needed. As an
  83. exception, we only emit inline virtual functions with the vtable, since
  84. it always requires a copy.
  85. </p>
  86. <p>Local static variables and string constants used in an inline function
  87. are also considered to have vague linkage, since they must be shared
  88. between all inlined and out-of-line instances of the function.
  89. </p>
  90. </dd>
  91. <dt>VTables</dt>
  92. <dd><a name="index-vtable"></a>
  93. <p>C++ virtual functions are implemented in most compilers using a lookup
  94. table, known as a vtable. The vtable contains pointers to the virtual
  95. functions provided by a class, and each object of the class contains a
  96. pointer to its vtable (or vtables, in some multiple-inheritance
  97. situations). If the class declares any non-inline, non-pure virtual
  98. functions, the first one is chosen as the &ldquo;key method&rdquo; for the class,
  99. and the vtable is only emitted in the translation unit where the key
  100. method is defined.
  101. </p>
  102. <p><em>Note:</em> If the chosen key method is later defined as inline, the
  103. vtable is still emitted in every translation unit that defines it.
  104. Make sure that any inline virtuals are declared inline in the class
  105. body, even if they are not defined there.
  106. </p>
  107. </dd>
  108. <dt><code>type_info</code> objects</dt>
  109. <dd><a name="index-type_005finfo"></a>
  110. <a name="index-RTTI"></a>
  111. <p>C++ requires information about types to be written out in order to
  112. implement &lsquo;<samp>dynamic_cast</samp>&rsquo;, &lsquo;<samp>typeid</samp>&rsquo; and exception handling.
  113. For polymorphic classes (classes with virtual functions), the &lsquo;<samp>type_info</samp>&rsquo;
  114. object is written out along with the vtable so that &lsquo;<samp>dynamic_cast</samp>&rsquo;
  115. can determine the dynamic type of a class object at run time. For all
  116. other types, we write out the &lsquo;<samp>type_info</samp>&rsquo; object when it is used: when
  117. applying &lsquo;<samp>typeid</samp>&rsquo; to an expression, throwing an object, or
  118. referring to a type in a catch clause or exception specification.
  119. </p>
  120. </dd>
  121. <dt>Template Instantiations</dt>
  122. <dd><p>Most everything in this section also applies to template instantiations,
  123. but there are other options as well.
  124. See <a href="Template-Instantiation.html#Template-Instantiation">Where&rsquo;s the Template?</a>.
  125. </p>
  126. </dd>
  127. </dl>
  128. <p>When used with GNU ld version 2.8 or later on an ELF system such as
  129. GNU/Linux or Solaris 2, or on Microsoft Windows, duplicate copies of
  130. these constructs will be discarded at link time. This is known as
  131. COMDAT support.
  132. </p>
  133. <p>On targets that don&rsquo;t support COMDAT, but do support weak symbols, GCC
  134. uses them. This way one copy overrides all the others, but
  135. the unused copies still take up space in the executable.
  136. </p>
  137. <p>For targets that do not support either COMDAT or weak symbols,
  138. most entities with vague linkage are emitted as local symbols to
  139. avoid duplicate definition errors from the linker. This does not happen
  140. for local statics in inlines, however, as having multiple copies
  141. almost certainly breaks things.
  142. </p>
  143. <p>See <a href="C_002b_002b-Interface.html#C_002b_002b-Interface">Declarations and Definitions in One Header</a>, for
  144. another way to control placement of these constructs.
  145. </p>
  146. <hr>
  147. <div class="header">
  148. <p>
  149. Next: <a href="C_002b_002b-Interface.html#C_002b_002b-Interface" accesskey="n" rel="next">C++ Interface</a>, Previous: <a href="Restricted-Pointers.html#Restricted-Pointers" accesskey="p" rel="prev">Restricted Pointers</a>, Up: <a href="C_002b_002b-Extensions.html#C_002b_002b-Extensions" accesskey="u" rel="up">C++ Extensions</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>
  150. </div>
  151. </body>
  152. </html>