Compatibility.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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>Using the GNU Compiler Collection (GCC): Compatibility</title>
  20. <meta name="description" content="Using the GNU Compiler Collection (GCC): Compatibility">
  21. <meta name="keywords" content="Using the GNU Compiler Collection (GCC): Compatibility">
  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="index.html#Top" rel="up" title="Top">
  30. <link href="Gcov.html#Gcov" rel="next" title="Gcov">
  31. <link href="Forwarding-hook.html#Forwarding-hook" rel="prev" title="Forwarding hook">
  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="Compatibility"></a>
  63. <div class="header">
  64. <p>
  65. Next: <a href="Gcov.html#Gcov" accesskey="n" rel="next">Gcov</a>, Previous: <a href="Objective_002dC.html#Objective_002dC" accesskey="p" rel="prev">Objective-C</a>, Up: <a href="index.html#Top" accesskey="u" rel="up">Top</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="Binary-Compatibility"></a>
  69. <h2 class="chapter">9 Binary Compatibility</h2>
  70. <a name="index-binary-compatibility"></a>
  71. <a name="index-ABI"></a>
  72. <a name="index-application-binary-interface"></a>
  73. <p>Binary compatibility encompasses several related concepts:
  74. </p>
  75. <dl compact="compact">
  76. <dt><em>application binary interface (ABI)</em></dt>
  77. <dd><p>The set of runtime conventions followed by all of the tools that deal
  78. with binary representations of a program, including compilers, assemblers,
  79. linkers, and language runtime support.
  80. Some ABIs are formal with a written specification, possibly designed
  81. by multiple interested parties. Others are simply the way things are
  82. actually done by a particular set of tools.
  83. </p>
  84. </dd>
  85. <dt><em>ABI conformance</em></dt>
  86. <dd><p>A compiler conforms to an ABI if it generates code that follows all of
  87. the specifications enumerated by that ABI.
  88. A library conforms to an ABI if it is implemented according to that ABI.
  89. An application conforms to an ABI if it is built using tools that conform
  90. to that ABI and does not contain source code that specifically changes
  91. behavior specified by the ABI.
  92. </p>
  93. </dd>
  94. <dt><em>calling conventions</em></dt>
  95. <dd><p>Calling conventions are a subset of an ABI that specify of how arguments
  96. are passed and function results are returned.
  97. </p>
  98. </dd>
  99. <dt><em>interoperability</em></dt>
  100. <dd><p>Different sets of tools are interoperable if they generate files that
  101. can be used in the same program. The set of tools includes compilers,
  102. assemblers, linkers, libraries, header files, startup files, and debuggers.
  103. Binaries produced by different sets of tools are not interoperable unless
  104. they implement the same ABI. This applies to different versions of the
  105. same tools as well as tools from different vendors.
  106. </p>
  107. </dd>
  108. <dt><em>intercallability</em></dt>
  109. <dd><p>Whether a function in a binary built by one set of tools can call a
  110. function in a binary built by a different set of tools is a subset
  111. of interoperability.
  112. </p>
  113. </dd>
  114. <dt><em>implementation-defined features</em></dt>
  115. <dd><p>Language standards include lists of implementation-defined features whose
  116. behavior can vary from one implementation to another. Some of these
  117. features are normally covered by a platform&rsquo;s ABI and others are not.
  118. The features that are not covered by an ABI generally affect how a
  119. program behaves, but not intercallability.
  120. </p>
  121. </dd>
  122. <dt><em>compatibility</em></dt>
  123. <dd><p>Conformance to the same ABI and the same behavior of implementation-defined
  124. features are both relevant for compatibility.
  125. </p></dd>
  126. </dl>
  127. <p>The application binary interface implemented by a C or C++ compiler
  128. affects code generation and runtime support for:
  129. </p>
  130. <ul>
  131. <li> size and alignment of data types
  132. </li><li> layout of structured types
  133. </li><li> calling conventions
  134. </li><li> register usage conventions
  135. </li><li> interfaces for runtime arithmetic support
  136. </li><li> object file formats
  137. </li></ul>
  138. <p>In addition, the application binary interface implemented by a C++ compiler
  139. affects code generation and runtime support for:
  140. </p><ul>
  141. <li> name mangling
  142. </li><li> exception handling
  143. </li><li> invoking constructors and destructors
  144. </li><li> layout, alignment, and padding of classes
  145. </li><li> layout and alignment of virtual tables
  146. </li></ul>
  147. <p>Some GCC compilation options cause the compiler to generate code that
  148. does not conform to the platform&rsquo;s default ABI. Other options cause
  149. different program behavior for implementation-defined features that are
  150. not covered by an ABI. These options are provided for consistency with
  151. other compilers that do not follow the platform&rsquo;s default ABI or the
  152. usual behavior of implementation-defined features for the platform.
  153. Be very careful about using such options.
  154. </p>
  155. <p>Most platforms have a well-defined ABI that covers C code, but ABIs
  156. that cover C++ functionality are not yet common.
  157. </p>
  158. <p>Starting with GCC 3.2, GCC binary conventions for C++ are based on a
  159. written, vendor-neutral C++ ABI that was designed to be specific to
  160. 64-bit Itanium but also includes generic specifications that apply to
  161. any platform.
  162. This C++ ABI is also implemented by other compiler vendors on some
  163. platforms, notably GNU/Linux and BSD systems.
  164. We have tried hard to provide a stable ABI that will be compatible with
  165. future GCC releases, but it is possible that we will encounter problems
  166. that make this difficult. Such problems could include different
  167. interpretations of the C++ ABI by different vendors, bugs in the ABI, or
  168. bugs in the implementation of the ABI in different compilers.
  169. GCC&rsquo;s <samp>-Wabi</samp> switch warns when G++ generates code that is
  170. probably not compatible with the C++ ABI.
  171. </p>
  172. <p>The C++ library used with a C++ compiler includes the Standard C++
  173. Library, with functionality defined in the C++ Standard, plus language
  174. runtime support. The runtime support is included in a C++ ABI, but there
  175. is no formal ABI for the Standard C++ Library. Two implementations
  176. of that library are interoperable if one follows the de-facto ABI of the
  177. other and if they are both built with the same compiler, or with compilers
  178. that conform to the same ABI for C++ compiler and runtime support.
  179. </p>
  180. <p>When G++ and another C++ compiler conform to the same C++ ABI, but the
  181. implementations of the Standard C++ Library that they normally use do not
  182. follow the same ABI for the Standard C++ Library, object files built with
  183. those compilers can be used in the same program only if they use the same
  184. C++ library. This requires specifying the location of the C++ library
  185. header files when invoking the compiler whose usual library is not being
  186. used. The location of GCC&rsquo;s C++ header files depends on how the GCC
  187. build was configured, but can be seen by using the G++ <samp>-v</samp> option.
  188. With default configuration options for G++ 3.3 the compile line for a
  189. different C++ compiler needs to include
  190. </p>
  191. <div class="smallexample">
  192. <pre class="smallexample"> -I<var>gcc_install_directory</var>/include/c++/3.3
  193. </pre></div>
  194. <p>Similarly, compiling code with G++ that must use a C++ library other
  195. than the GNU C++ library requires specifying the location of the header
  196. files for that other library.
  197. </p>
  198. <p>The most straightforward way to link a program to use a particular
  199. C++ library is to use a C++ driver that specifies that C++ library by
  200. default. The <code>g++</code> driver, for example, tells the linker where
  201. to find GCC&rsquo;s C++ library (<samp>libstdc++</samp>) plus the other libraries
  202. and startup files it needs, in the proper order.
  203. </p>
  204. <p>If a program must use a different C++ library and it&rsquo;s not possible
  205. to do the final link using a C++ driver that uses that library by default,
  206. it is necessary to tell <code>g++</code> the location and name of that
  207. library. It might also be necessary to specify different startup files
  208. and other runtime support libraries, and to suppress the use of GCC&rsquo;s
  209. support libraries with one or more of the options <samp>-nostdlib</samp>,
  210. <samp>-nostartfiles</samp>, and <samp>-nodefaultlibs</samp>.
  211. </p>
  212. <hr>
  213. <div class="header">
  214. <p>
  215. Next: <a href="Gcov.html#Gcov" accesskey="n" rel="next">Gcov</a>, Previous: <a href="Objective_002dC.html#Objective_002dC" accesskey="p" rel="prev">Objective-C</a>, Up: <a href="index.html#Top" accesskey="u" rel="up">Top</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>
  216. </div>
  217. </body>
  218. </html>