xref: /dflybsd-src/contrib/gcc-4.7/gcc/doc/compat.texi (revision 04febcfb30580676d3e95f58a16c5137ee478b32)
1*e4b17023SJohn Marino@c Copyright (C) 2002, 2004 Free Software Foundation, Inc.
2*e4b17023SJohn Marino@c This is part of the GCC manual.
3*e4b17023SJohn Marino@c For copying conditions, see the file gcc.texi.
4*e4b17023SJohn Marino
5*e4b17023SJohn Marino@node Compatibility
6*e4b17023SJohn Marino@chapter Binary Compatibility
7*e4b17023SJohn Marino@cindex binary compatibility
8*e4b17023SJohn Marino@cindex ABI
9*e4b17023SJohn Marino@cindex application binary interface
10*e4b17023SJohn Marino
11*e4b17023SJohn MarinoBinary compatibility encompasses several related concepts:
12*e4b17023SJohn Marino
13*e4b17023SJohn Marino@table @dfn
14*e4b17023SJohn Marino@item application binary interface (ABI)
15*e4b17023SJohn MarinoThe set of runtime conventions followed by all of the tools that deal
16*e4b17023SJohn Marinowith binary representations of a program, including compilers, assemblers,
17*e4b17023SJohn Marinolinkers, and language runtime support.
18*e4b17023SJohn MarinoSome ABIs are formal with a written specification, possibly designed
19*e4b17023SJohn Marinoby multiple interested parties.  Others are simply the way things are
20*e4b17023SJohn Marinoactually done by a particular set of tools.
21*e4b17023SJohn Marino
22*e4b17023SJohn Marino@item ABI conformance
23*e4b17023SJohn MarinoA compiler conforms to an ABI if it generates code that follows all of
24*e4b17023SJohn Marinothe specifications enumerated by that ABI@.
25*e4b17023SJohn MarinoA library conforms to an ABI if it is implemented according to that ABI@.
26*e4b17023SJohn MarinoAn application conforms to an ABI if it is built using tools that conform
27*e4b17023SJohn Marinoto that ABI and does not contain source code that specifically changes
28*e4b17023SJohn Marinobehavior specified by the ABI@.
29*e4b17023SJohn Marino
30*e4b17023SJohn Marino@item calling conventions
31*e4b17023SJohn MarinoCalling conventions are a subset of an ABI that specify of how arguments
32*e4b17023SJohn Marinoare passed and function results are returned.
33*e4b17023SJohn Marino
34*e4b17023SJohn Marino@item interoperability
35*e4b17023SJohn MarinoDifferent sets of tools are interoperable if they generate files that
36*e4b17023SJohn Marinocan be used in the same program.  The set of tools includes compilers,
37*e4b17023SJohn Marinoassemblers, linkers, libraries, header files, startup files, and debuggers.
38*e4b17023SJohn MarinoBinaries produced by different sets of tools are not interoperable unless
39*e4b17023SJohn Marinothey implement the same ABI@.  This applies to different versions of the
40*e4b17023SJohn Marinosame tools as well as tools from different vendors.
41*e4b17023SJohn Marino
42*e4b17023SJohn Marino@item intercallability
43*e4b17023SJohn MarinoWhether a function in a binary built by one set of tools can call a
44*e4b17023SJohn Marinofunction in a binary built by a different set of tools is a subset
45*e4b17023SJohn Marinoof interoperability.
46*e4b17023SJohn Marino
47*e4b17023SJohn Marino@item implementation-defined features
48*e4b17023SJohn MarinoLanguage standards include lists of implementation-defined features whose
49*e4b17023SJohn Marinobehavior can vary from one implementation to another.  Some of these
50*e4b17023SJohn Marinofeatures are normally covered by a platform's ABI and others are not.
51*e4b17023SJohn MarinoThe features that are not covered by an ABI generally affect how a
52*e4b17023SJohn Marinoprogram behaves, but not intercallability.
53*e4b17023SJohn Marino
54*e4b17023SJohn Marino@item compatibility
55*e4b17023SJohn MarinoConformance to the same ABI and the same behavior of implementation-defined
56*e4b17023SJohn Marinofeatures are both relevant for compatibility.
57*e4b17023SJohn Marino@end table
58*e4b17023SJohn Marino
59*e4b17023SJohn MarinoThe application binary interface implemented by a C or C++ compiler
60*e4b17023SJohn Marinoaffects code generation and runtime support for:
61*e4b17023SJohn Marino
62*e4b17023SJohn Marino@itemize @bullet
63*e4b17023SJohn Marino@item
64*e4b17023SJohn Marinosize and alignment of data types
65*e4b17023SJohn Marino@item
66*e4b17023SJohn Marinolayout of structured types
67*e4b17023SJohn Marino@item
68*e4b17023SJohn Marinocalling conventions
69*e4b17023SJohn Marino@item
70*e4b17023SJohn Marinoregister usage conventions
71*e4b17023SJohn Marino@item
72*e4b17023SJohn Marinointerfaces for runtime arithmetic support
73*e4b17023SJohn Marino@item
74*e4b17023SJohn Marinoobject file formats
75*e4b17023SJohn Marino@end itemize
76*e4b17023SJohn Marino
77*e4b17023SJohn MarinoIn addition, the application binary interface implemented by a C++ compiler
78*e4b17023SJohn Marinoaffects code generation and runtime support for:
79*e4b17023SJohn Marino@itemize @bullet
80*e4b17023SJohn Marino@item
81*e4b17023SJohn Marinoname mangling
82*e4b17023SJohn Marino@item
83*e4b17023SJohn Marinoexception handling
84*e4b17023SJohn Marino@item
85*e4b17023SJohn Marinoinvoking constructors and destructors
86*e4b17023SJohn Marino@item
87*e4b17023SJohn Marinolayout, alignment, and padding of classes
88*e4b17023SJohn Marino@item
89*e4b17023SJohn Marinolayout and alignment of virtual tables
90*e4b17023SJohn Marino@end itemize
91*e4b17023SJohn Marino
92*e4b17023SJohn MarinoSome GCC compilation options cause the compiler to generate code that
93*e4b17023SJohn Marinodoes not conform to the platform's default ABI@.  Other options cause
94*e4b17023SJohn Marinodifferent program behavior for implementation-defined features that are
95*e4b17023SJohn Marinonot covered by an ABI@.  These options are provided for consistency with
96*e4b17023SJohn Marinoother compilers that do not follow the platform's default ABI or the
97*e4b17023SJohn Marinousual behavior of implementation-defined features for the platform.
98*e4b17023SJohn MarinoBe very careful about using such options.
99*e4b17023SJohn Marino
100*e4b17023SJohn MarinoMost platforms have a well-defined ABI that covers C code, but ABIs
101*e4b17023SJohn Marinothat cover C++ functionality are not yet common.
102*e4b17023SJohn Marino
103*e4b17023SJohn MarinoStarting with GCC 3.2, GCC binary conventions for C++ are based on a
104*e4b17023SJohn Marinowritten, vendor-neutral C++ ABI that was designed to be specific to
105*e4b17023SJohn Marino64-bit Itanium but also includes generic specifications that apply to
106*e4b17023SJohn Marinoany platform.
107*e4b17023SJohn MarinoThis C++ ABI is also implemented by other compiler vendors on some
108*e4b17023SJohn Marinoplatforms, notably GNU/Linux and BSD systems.
109*e4b17023SJohn MarinoWe have tried hard to provide a stable ABI that will be compatible with
110*e4b17023SJohn Marinofuture GCC releases, but it is possible that we will encounter problems
111*e4b17023SJohn Marinothat make this difficult.  Such problems could include different
112*e4b17023SJohn Marinointerpretations of the C++ ABI by different vendors, bugs in the ABI, or
113*e4b17023SJohn Marinobugs in the implementation of the ABI in different compilers.
114*e4b17023SJohn MarinoGCC's @option{-Wabi} switch warns when G++ generates code that is
115*e4b17023SJohn Marinoprobably not compatible with the C++ ABI@.
116*e4b17023SJohn Marino
117*e4b17023SJohn MarinoThe C++ library used with a C++ compiler includes the Standard C++
118*e4b17023SJohn MarinoLibrary, with functionality defined in the C++ Standard, plus language
119*e4b17023SJohn Marinoruntime support.  The runtime support is included in a C++ ABI, but there
120*e4b17023SJohn Marinois no formal ABI for the Standard C++ Library.  Two implementations
121*e4b17023SJohn Marinoof that library are interoperable if one follows the de-facto ABI of the
122*e4b17023SJohn Marinoother and if they are both built with the same compiler, or with compilers
123*e4b17023SJohn Marinothat conform to the same ABI for C++ compiler and runtime support.
124*e4b17023SJohn Marino
125*e4b17023SJohn MarinoWhen G++ and another C++ compiler conform to the same C++ ABI, but the
126*e4b17023SJohn Marinoimplementations of the Standard C++ Library that they normally use do not
127*e4b17023SJohn Marinofollow the same ABI for the Standard C++ Library, object files built with
128*e4b17023SJohn Marinothose compilers can be used in the same program only if they use the same
129*e4b17023SJohn MarinoC++ library.  This requires specifying the location of the C++ library
130*e4b17023SJohn Marinoheader files when invoking the compiler whose usual library is not being
131*e4b17023SJohn Marinoused.  The location of GCC's C++ header files depends on how the GCC
132*e4b17023SJohn Marinobuild was configured, but can be seen by using the G++ @option{-v} option.
133*e4b17023SJohn MarinoWith default configuration options for G++ 3.3 the compile line for a
134*e4b17023SJohn Marinodifferent C++ compiler needs to include
135*e4b17023SJohn Marino
136*e4b17023SJohn Marino@smallexample
137*e4b17023SJohn Marino    -I@var{gcc_install_directory}/include/c++/3.3
138*e4b17023SJohn Marino@end smallexample
139*e4b17023SJohn Marino
140*e4b17023SJohn MarinoSimilarly, compiling code with G++ that must use a C++ library other
141*e4b17023SJohn Marinothan the GNU C++ library requires specifying the location of the header
142*e4b17023SJohn Marinofiles for that other library.
143*e4b17023SJohn Marino
144*e4b17023SJohn MarinoThe most straightforward way to link a program to use a particular
145*e4b17023SJohn MarinoC++ library is to use a C++ driver that specifies that C++ library by
146*e4b17023SJohn Marinodefault.  The @command{g++} driver, for example, tells the linker where
147*e4b17023SJohn Marinoto find GCC's C++ library (@file{libstdc++}) plus the other libraries
148*e4b17023SJohn Marinoand startup files it needs, in the proper order.
149*e4b17023SJohn Marino
150*e4b17023SJohn MarinoIf a program must use a different C++ library and it's not possible
151*e4b17023SJohn Marinoto do the final link using a C++ driver that uses that library by default,
152*e4b17023SJohn Marinoit is necessary to tell @command{g++} the location and name of that
153*e4b17023SJohn Marinolibrary.  It might also be necessary to specify different startup files
154*e4b17023SJohn Marinoand other runtime support libraries, and to suppress the use of GCC's
155*e4b17023SJohn Marinosupport libraries with one or more of the options @option{-nostdlib},
156*e4b17023SJohn Marino@option{-nostartfiles}, and @option{-nodefaultlibs}.
157