2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / libstdc++-v3 / docs / html / abi.txt
blob430108885f9dd988018f2707c25b7507fa7dfada
2 2002-10-14 Benjamin Kosnik
4 Description of the libstdc++ ABI.
6 I. What is an ABI? What's covered? What's not?
8 - scope of document, of use to system integrators.
10 - What's the deal with C++? Why can't different compiler's object
11   files link with each other? Bug? Feature?
13 - compilation includes and linked library binary must match up..
15 - shared library only, static is immutable.
17 - What's an ABI?
19 - library ABI, compiler ABI different issues, (but related)
21 - GNU C++ does not have a compiler command line option to switch
22   between various different C++ ABIs. For instance, there is no way to
23   switch between the gcc-3.0.x ABI, gcc-3.1.x ABI, and the gcc-3.2.x
24   ABI during compilation. Other C++ compilers do allow this, and some
25   g++ command line options may change the ABI (-fno-exceptions, see
26   the complete list), but there is no version switch. Sorry. 
28   To use a specific C++ABI, one must use the corresponding GNU C++
29   toolchain. 
31 - How can this complexity be managed? What does C++ versioning mean?
32   Because library and compiler changes often make binaries compiled
33   with one version of the GNU tools incompatible with binaries
34   compiled with other (either newer or older) versions of the same GNU
35   tools, specific techniques are used to make managing this complexity
36   easier.
38   The following techniques are used:
40   - Release versioning on the libgcc_s.so binary.
42     It is versioned as follows:
43     gcc-3.0.0: libgcc_s.so.1
44     gcc-3.0.1: libgcc_s.so.1
45     gcc-3.0.2: libgcc_s.so.1
46     gcc-3.0.3: libgcc_s.so.1
47     gcc-3.0.4: libgcc_s.so.1
48     gcc-3.1.0: libgcc_s.so.1
49     gcc-3.1.1: libgcc_s.so.1
50     gcc-3.2.0: libgcc_s.so.1
53   - Release versioning on the libstdc++.so binary.
55     It is versioned as follows:
56     gcc-3.0.0: libstdc++.so.3.0.0
57     gcc-3.0.1: libstdc++.so.3.0.1
58     gcc-3.0.2: libstdc++.so.3.0.2
59     gcc-3.0.3: libstdc++.so.3.0.2 (Error, should be libstdc++.so.3.0.3)
60     gcc-3.0.4: libstdc++.so.3.0.4
61     gcc-3.1.0: libstdc++.so.4.0.0
62     gcc-3.1.1: libstdc++.so.4.0.1
63     gcc-3.2.0: libstdc++.so.5.0.0
66   - Symbol versioning on the libgcc_s.so binary.
67   
68     file: gcc/libgcc-std.ver
70     It is versioned as follows:
71     gcc-3.0.0: GCC_3.0
72     gcc-3.0.1: GCC_3.0
73     gcc-3.0.2: GCC_3.0
74     gcc-3.0.3: GCC_3.0
75     gcc-3.0.4: GCC_3.0
76     gcc-3.1.0: GCC_3.0
77     gcc-3.1.1: GCC_3.0
78     gcc-3.2.0: GCC_3.0
81   - Symbol versioning on the libstdc++.so binary.
82   
83     It is versioned as follows:
84     gcc-3.0.0: (Error, unversioned)
85     gcc-3.0.1: (Error, unversioned)
86     gcc-3.0.2: (Error, unversioned)
87     gcc-3.0.3: (Error, unversioned)
88     gcc-3.0.4: (Error, unversioned)
89     gcc-3.1.0: GLIBCPP_3.1, CXXABI_1
90     gcc-3.1.1: GLIBCPP_3.1, CXXABI_1
91     gcc-3.2.0: GLIBCPP_3.2, CXXABI_1.2
92     
93     file: libstdc++-v3/config/linker-map.gnu
94   
96   - Incremental bumping of a compiler pre-defined macro,
97     __GXX_ABI_VERSION. This macro is defined as the version of the
98     compiler v3 ABI, with g++ 3.0.x being version 100. This macro will
99     be automatically defined whenever g++ is used (the curious can
100     test this by invoking g++ with the '-v' flag.)
101     
102     This macro is defined in the file "lang-specs.h" in the gcc/cp directory.
103     Later versions define it in "c-common.c" in the gcc directory.
105     It is versioned as follows:
106     gcc-3.0.x: 100
107     gcc-3.1.x: 100 (Error, should be 101)
108     gcc-3.2.x: 102
111   - Incremental bumping of a library pre-defined macro, __GLIBCPP__ or
112     __GLIBCXX__.  This macro is defined as the date the library was
113     released, in compressed ISO date format, as an unsigned long.
115     This macro is defined in the file "c++config" in the
116     "libstdc++-v3/include/bits" directory and is changed every night
117     by an automated script.
119     It is versioned as follows:
120     gcc-3.0.0: 20010615
121     gcc-3.0.1: 20010819
122     gcc-3.0.2: 20011023
123     gcc-3.0.3: 20011220
124     gcc-3.0.4: 20020220
125     gcc-3.1.0: 20020514
126     gcc-3.1.1: 20020725
127     gcc-3.2.0: 20020814
130   - Incremental bumping of a library pre-defined macro,
131     _GLIBCPP_VERSION. This macro is defined as the released version of
132     the library, as a string literal. This is only implemented in
133     gcc-3.1.0 releases and higher, and changed to _GLIBCXX_VERSION in 3.4.
135     This macro is defined in the file "c++config" in the
136     "libstdc++-v3/include/bits" directory and is generated
137     automatically by autoconf as part of the configure-time generation
138     of config.h.
140     It is versioned as follows:
141     gcc-3.0.0: "3.0.0"
142     gcc-3.0.1: "3.0.0" (Error, should be "3.0.1")
143     gcc-3.0.2: "3.0.0" (Error, should be "3.0.2")
144     gcc-3.0.3: "3.0.0" (Error, should be "3.0.3")
145     gcc-3.0.4: "3.0.0" (Error, should be "3.0.4")
146     gcc-3.1.0: "3.1.0"
147     gcc-3.1.1: "3.1.1"
148     gcc-3.2.0: "3.2"
151   - Matching each specific C++ compiler release to a specific set of
152     C++ include files. This is only implemented in gcc-3.1.1 releases
153     and higher.
155     All C++ includes are installed in include/c++, then nest in a
156     directory hierarchy corresponding to the C++ compiler's released
157     version. This version corresponds to the variable "gcc_version" in
158     "libstdc++-v3/acinclude.m4," and more details can be found in that
159     file's macro GLIBCPP_CONFIGURE.
161     C++ includes are versioned as follows:
162     gcc-3.0.0: include/g++-v3
163     gcc-3.0.1: include/g++-v3
164     gcc-3.0.2: include/g++-v3
165     gcc-3.0.3: include/g++-v3
166     gcc-3.0.4: include/g++-v3
167     gcc-3.1.0: include/g++-v3
168     gcc-3.1.1: include/c++/3.1.1
169     gcc-3.2.0: include/c++/3.2
171   Taken together, these techniques can accurately specify interface
172   and implementation changes in the GNU C++ tools themselves. Used
173   properly, they allow both the GNU C++ tools implementation, and
174   programs using them, an evolving yet controlled development that
175   maintains backward compatibility.
177 - Minimum environment that supports a versioned ABI: what's needed?  A
178   supported dynamic linker, a GNU linker of sufficient vintage to
179   understand demangled C++ name globbing (ld), a shared executable
180   compiled with g++, and shared libraries (libgcc_s, libstdc++-v3)
181   compiled by a compiler (g++) with a compatible ABI. Phew.
183   On top of all that, an additional constraint: libstdc++ did not
184   attempt to version symbols (or age gracefully, really) until version
185   3.1.0. 
187   Most modern Linux and BSD versions, particularly ones using
188   gcc-3.1.x tools, will meet the requirements above.
190 - What configure options impact symbol versioning?
192   It turns out that most of the configure options that change default
193   behavior will impact the mangled names of exported symbols, and thus
194   impact versioning and compatibility.
196   For more information on configure options, including ABI impacts, see:
197   http://gcc.gnu.org/onlinedocs/libstdc++/configopts.html
199   There is one flag that explicitly deals with symbol versioning:
200   --enable-symvers. 
202   In particular, libstdc++-v3/acinclude.m4 has a macro called
203   GLIBCXX_ENABLE_SYMVERS that defaults to yes (or the argument passed
204   in via --enable-symvers=foo). At that point, the macro attempts to
205   make sure that all the requirement for symbol versioning are in
206   place. For more information, please consult acinclude.m4. 
208 - How can I tell if symbol versioning is, indeed, active? 
210   When the GNU C++ library is being built with symbol versioning on,
211   you should see the following at configure time for libstdc++-v3:
213   checking versioning on shared library symbols... gnu
215   If you don't see this line in the configure output, or if this line
216   appears but the last word is 'no', then you are out of luck.
218   If the compiler is pre-installed, a quick way to test is to compile
219   the following (or any) simple C++ file:
221 #include <iostream>
223 int main()
224 { std::cout << "hello" << std::endl; return 0; }
226 %g++ hello.cc -o hello.out
227 %nm hello.out
229 If you see symbols in the resulting output with "GLIBCPP_3.x" as part
230 of the name, then the executable is versioned. Here's an example:
232          U _ZNSt8ios_base4InitC1Ev@@GLIBCPP_3.1
235 II. Library ABI changes
237 The following will cause the library major version number to
238 increase, say from "libstdc++.so.3.0.4" to "libstdc++.so.4.0.0".
240 - (anything) changing in the gcc/g++ compiler ABI
242 - (anything) changing size of an exported symbol
244 - (anything) changing alignment of an exported symbol
246 - (anything) changing the layout of an exported symbol
248 - (anything) changing mangling on an exported symbol
250 - (anything) deleting an exported symbol
252 - (anything) changing the size, alignment, or layout of types
253   specified in the C++ standard. These may not necessarily be
254   instantiated or otherwise exported in the library binary, and
255   include all the required locale facets, as well as things like
256   std::basic_streambuf, et al.
258 Note: adding an exported symbol, if it's in a new and dependent
259 interface name, is ok.
261 The following will cause the library revision version number to
262 increase, say from "libstdc++.so.5.0.0" to "libstdc++.so.5.0.1".
264 - any release of the gcc toolchain.
267 III. Versioning
269 - include files
271   - versioning headers with version, why necessary
272     (need to control member/non-member functions, add delete files)
274 - shared library binaries
276   - release versions
278   - libtool versions
280   - when does so version get a bump? what are the options?
282   - how is the link map used?  
284   - in an non-abi breaking minor release, how are symbols added?
285     removed?
287   - in an abi-breaking major release, what happens? symbol fall back
290 IV. Testing ABI changes
292 Testing for GNU C++ ABI changes is composed of two distinct areas:
293 testing the C++ compiler (g++) for compiler changes, and testing the
294 C++ library (libstdc++) for library changes.
296 Testing the C++ compiler ABI can be done various ways.
298 One. 
299 Intel ABI checker. More information can be obtained
300 <a href="http://developer.intel.com/software/products/opensource/">here.</a>
302 Two.
303 The second is yet unreleased, but has been announced on the gcc
304 mailing list. It is yet unspecified if these tools will be freely
305 available, and able to be included in a GNU project. Please contact
306 Mark Mitchell (mark@codesourcery.com) for more details, and current
307 status.
309 Three.
310 Involves using the vlad.consistency test framework. This has also been
311 discussed on the gcc mailing lists.
313 Testing the C++ library ABI can also be done various ways.
315 One. 
316 (Brendan Kehoe, Jeff Law suggestion to run 'make check-c++' two ways, 
317 one with a new compiler and an old library, and the other with an old
318 compiler and a new library, and look for testsuite regressions)
320 Details on how to set this kind of test up can be found here:
321 http://gcc.gnu.org/ml/gcc/2002-08/msg00142.html
323 Two.  
324 Use the 'make check-abi' rule in the libstdc++-v3 Makefile. 
326 This is a proactive check the library ABI. Currently, exported symbol
327 names that are either weak or defined are checked against a last known
328 good baseline. Currently, this baseline is keyed off of 3.2.0
329 binaries, as this was the last time the .so number was incremented. In
330 addition, all exported names are demangled, and the exported objects
331 are checked to make sure they are the same size as the same object in
332 the baseline.
334 This dataset is insufficient, yet a start. Also needed is a
335 comprehensive check for all user-visible types part of the standard
336 library for sizeof() and alignof() changes. 
338 Verifying compatible layouts of objects is not even attempted.  It
339 should be possible to use sizeof, alignof, and offsetof to compute
340 offsets for each structure and type in the standard library, saving to
341 another datafile. Then, compute this in a similar way for new
342 binaries, and look for differences.
344 Another approach might be to use the -fdump-class-hierarchy flag to
345 get information. However, currently this approach gives insufficient
346 data for use in library testing, as class data members, their offsets,
347 and other detailed data is not displayed with this flag.
348 (See g++/7470 on how this was used to find bugs.)
350 Perhaps there are other C++ ABI checkers. If so, please notify
351 us. We'd like to know about them!
354 V. Issues not directly addressed, and possible suggestions
356 - what to do about multi-ABI systems (nathan scenario)?
358   - compatibility libs
360   --enable-version-specific-runtime-libs
362   - Alexandre Oliva proposal to have extended name attributes, modify ld
364   - directory-level versioning
366 - wrapping C++ API's in "C" to use the C ABI.
369 V. References
371 ABIcheck, a vague idea of checking ABI compatibility
372 http://abicheck.sourceforge.net/
374 C++ ABI reference
375 http://www.codesourcery.com/cxx-abi/
377 Intel ABI documentation
378 "IntelĀ® Compilers for Linux* -Compatibility with the GNU Compilers"
379 (included in icc 6.0)
381 Sun Solaris 2.9 docs
382 Linker and Libraries Guide (document 816-1386)
383 C++ Migration Guide (document 816-2459)
384 http://docs.sun.com/db/prod/solaris.9
385 http://docs.sun.com/?p=/doc/816-1386&a=load
387 Ulrich Drepper, "ELF Symbol Versioning"
388 http://people.redhat.com/drepper/symbol-versioning