compat.texi 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. @c Copyright (C) 2002-2015 Free Software Foundation, Inc.
  2. @c This is part of the GCC manual.
  3. @c For copying conditions, see the file gcc.texi.
  4. @node Compatibility
  5. @chapter Binary Compatibility
  6. @cindex binary compatibility
  7. @cindex ABI
  8. @cindex application binary interface
  9. Binary compatibility encompasses several related concepts:
  10. @table @dfn
  11. @item application binary interface (ABI)
  12. The set of runtime conventions followed by all of the tools that deal
  13. with binary representations of a program, including compilers, assemblers,
  14. linkers, and language runtime support.
  15. Some ABIs are formal with a written specification, possibly designed
  16. by multiple interested parties. Others are simply the way things are
  17. actually done by a particular set of tools.
  18. @item ABI conformance
  19. A compiler conforms to an ABI if it generates code that follows all of
  20. the specifications enumerated by that ABI@.
  21. A library conforms to an ABI if it is implemented according to that ABI@.
  22. An application conforms to an ABI if it is built using tools that conform
  23. to that ABI and does not contain source code that specifically changes
  24. behavior specified by the ABI@.
  25. @item calling conventions
  26. Calling conventions are a subset of an ABI that specify of how arguments
  27. are passed and function results are returned.
  28. @item interoperability
  29. Different sets of tools are interoperable if they generate files that
  30. can be used in the same program. The set of tools includes compilers,
  31. assemblers, linkers, libraries, header files, startup files, and debuggers.
  32. Binaries produced by different sets of tools are not interoperable unless
  33. they implement the same ABI@. This applies to different versions of the
  34. same tools as well as tools from different vendors.
  35. @item intercallability
  36. Whether a function in a binary built by one set of tools can call a
  37. function in a binary built by a different set of tools is a subset
  38. of interoperability.
  39. @item implementation-defined features
  40. Language standards include lists of implementation-defined features whose
  41. behavior can vary from one implementation to another. Some of these
  42. features are normally covered by a platform's ABI and others are not.
  43. The features that are not covered by an ABI generally affect how a
  44. program behaves, but not intercallability.
  45. @item compatibility
  46. Conformance to the same ABI and the same behavior of implementation-defined
  47. features are both relevant for compatibility.
  48. @end table
  49. The application binary interface implemented by a C or C++ compiler
  50. affects code generation and runtime support for:
  51. @itemize @bullet
  52. @item
  53. size and alignment of data types
  54. @item
  55. layout of structured types
  56. @item
  57. calling conventions
  58. @item
  59. register usage conventions
  60. @item
  61. interfaces for runtime arithmetic support
  62. @item
  63. object file formats
  64. @end itemize
  65. In addition, the application binary interface implemented by a C++ compiler
  66. affects code generation and runtime support for:
  67. @itemize @bullet
  68. @item
  69. name mangling
  70. @item
  71. exception handling
  72. @item
  73. invoking constructors and destructors
  74. @item
  75. layout, alignment, and padding of classes
  76. @item
  77. layout and alignment of virtual tables
  78. @end itemize
  79. Some GCC compilation options cause the compiler to generate code that
  80. does not conform to the platform's default ABI@. Other options cause
  81. different program behavior for implementation-defined features that are
  82. not covered by an ABI@. These options are provided for consistency with
  83. other compilers that do not follow the platform's default ABI or the
  84. usual behavior of implementation-defined features for the platform.
  85. Be very careful about using such options.
  86. Most platforms have a well-defined ABI that covers C code, but ABIs
  87. that cover C++ functionality are not yet common.
  88. Starting with GCC 3.2, GCC binary conventions for C++ are based on a
  89. written, vendor-neutral C++ ABI that was designed to be specific to
  90. 64-bit Itanium but also includes generic specifications that apply to
  91. any platform.
  92. This C++ ABI is also implemented by other compiler vendors on some
  93. platforms, notably GNU/Linux and BSD systems.
  94. We have tried hard to provide a stable ABI that will be compatible with
  95. future GCC releases, but it is possible that we will encounter problems
  96. that make this difficult. Such problems could include different
  97. interpretations of the C++ ABI by different vendors, bugs in the ABI, or
  98. bugs in the implementation of the ABI in different compilers.
  99. GCC's @option{-Wabi} switch warns when G++ generates code that is
  100. probably not compatible with the C++ ABI@.
  101. The C++ library used with a C++ compiler includes the Standard C++
  102. Library, with functionality defined in the C++ Standard, plus language
  103. runtime support. The runtime support is included in a C++ ABI, but there
  104. is no formal ABI for the Standard C++ Library. Two implementations
  105. of that library are interoperable if one follows the de-facto ABI of the
  106. other and if they are both built with the same compiler, or with compilers
  107. that conform to the same ABI for C++ compiler and runtime support.
  108. When G++ and another C++ compiler conform to the same C++ ABI, but the
  109. implementations of the Standard C++ Library that they normally use do not
  110. follow the same ABI for the Standard C++ Library, object files built with
  111. those compilers can be used in the same program only if they use the same
  112. C++ library. This requires specifying the location of the C++ library
  113. header files when invoking the compiler whose usual library is not being
  114. used. The location of GCC's C++ header files depends on how the GCC
  115. build was configured, but can be seen by using the G++ @option{-v} option.
  116. With default configuration options for G++ 3.3 the compile line for a
  117. different C++ compiler needs to include
  118. @smallexample
  119. -I@var{gcc_install_directory}/include/c++/3.3
  120. @end smallexample
  121. Similarly, compiling code with G++ that must use a C++ library other
  122. than the GNU C++ library requires specifying the location of the header
  123. files for that other library.
  124. The most straightforward way to link a program to use a particular
  125. C++ library is to use a C++ driver that specifies that C++ library by
  126. default. The @command{g++} driver, for example, tells the linker where
  127. to find GCC's C++ library (@file{libstdc++}) plus the other libraries
  128. and startup files it needs, in the proper order.
  129. If a program must use a different C++ library and it's not possible
  130. to do the final link using a C++ driver that uses that library by default,
  131. it is necessary to tell @command{g++} the location and name of that
  132. library. It might also be necessary to specify different startup files
  133. and other runtime support libraries, and to suppress the use of GCC's
  134. support libraries with one or more of the options @option{-nostdlib},
  135. @option{-nostartfiles}, and @option{-nodefaultlibs}.