1 <?xml version="1.0" encoding="ISO-8859-1"?>
3 PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
6 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
8 <meta name="AUTHOR" content="bkoz@gcc.gnu.org (Benjamin Kosnik)" />
9 <meta name="KEYWORDS" content="C++, libstdc++, dynamic, shared, library, ABI, version" />
10 <meta name="DESCRIPTION" content="C++ Standard Library ABI" />
11 <meta name="GENERATOR" content="emacs and ten fingers" />
12 <title>Standard C++ Library ABI</title>
13 <link rel="StyleSheet" href="lib3styles.css" type="text/css" />
14 <link rel="Start" href="documentation.html" type="text/html"
15 title="GNU C++ Standard Library" />
16 <link rel="Copyright" href="17_intro/license.html" type="text/html" />
20 <h1 class="centered"><a name="top">C++ Standard Library ABI</a></h1>
22 <p class="fineprint"><em>
23 The latest version of this document is always available at
24 <a href="http://gcc.gnu.org/onlinedocs/libstdc++/abi.html">
25 http://gcc.gnu.org/onlinedocs/libstdc++/abi.html</a>.
29 To the <a href="http://gcc.gnu.org/libstdc++/">libstdc++-v3 homepage</a>.
32 <!-- ####################################################### -->
35 <a name="CXXinterface">The C++ interface</a>
38 <p> C++ applications often dependent on specific language support
39 routines, say for throwing exceptions, or catching exceptions, and
40 perhaps also dependent on features in the C++ Standard Library.
43 <p> The C++ Standard Library has many include files, types defined in
44 those include files, specific named functions, and other behavior. The
45 text of these behaviors, as written in source include files, is called
46 the Application Programing Interface, or API.
49 <p> Furthermore, C++ source that is compiled into object files is
50 transformed by the compiler: it arranges objects with specific
51 alignment and in a particular layout, mangling names according to a
52 well-defined algorithm, has specific arrangements for the support of
53 virtual functions, etc. These details are defined as the compiler
54 Application Binary Interface, or ABI. The GNU C++ compiler uses an
55 industry-standard C++ ABI starting with version 3. Details can be
56 found in the <a href="http://www.codesourcery.com/cxx-abi/abi.html">
57 ABI specification</a>.
61 The GNU C++ compiler, g++, has a compiler command line option to
62 switch between various different C++ ABIs. This explicit version
63 switch is the flag <code> -fabi-version</code>. In addition, some
64 g++ command line options may change the ABI as a side-effect of
65 use. Such flags include <code>-fpack-struct</code> and
66 <code>-fno-exceptions</code>, but include others: see the complete
67 list in the GCC manual under the heading <a
68 href="http://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code%20Gen%20Options">Options
69 for Code Generation Conventions</a>.
72 <p> The configure options used when building a specific libstdc++
73 version may also impact the resulting library ABI. The available
74 configure options, and their impact on the library ABI, are documented
75 <a href="http://gcc.gnu.org/onlinedocs/libstdc++/configopts.html">
79 <p> Putting all of these ideas together results in the C++ Standard
80 library ABI, which is the compilation of a given library API by a
81 given compiler ABI. In a nutshell:
84 <code> library API + compiler ABI = library ABI</code>
87 The library ABI is mostly of interest for end-users who have
88 unresolved symbols and are linking dynamically to the C++ Standard
89 library, and who thus must be careful to compile their application
90 with a compiler that is compatible with the available C++ Standard
91 library binary. In this case, compatible is defined with the equation
92 above: given an application compiled with a given compiler ABI and
93 library API, it will work correctly with a Standard C++ Library
94 created with the same constraints.
98 To use a specific version of the C++ ABI, one must use a
99 corresponding GNU C++ toolchain (Ie, g++ and libstdc++) that
100 implements the C++ ABI in question.
104 <a name="ABI_versioning">Versioning</a>
107 <p> The C++ interface has evolved throughout the history of the GNU
108 C++ toolchain. With each release, various details have been changed so
109 as to give distinct versions to the C++ interface.
113 <a name="goals">Goals of versioning</a>
116 <p>Extending existing, stable ABIs. Versioning gives subsequent stable
117 releases series libraries the ability to add new symbols and add
118 functionality, all the while retaining backwards compatibility with
119 the previous releases in the series. Note: the reverse is not true. It
120 is not possible to take binaries linked with the latest version of a
121 release series (if symbols have been added) and expect the initial
122 release of the series to remain link compatible.
125 <p>Allows multiple, incompatible ABIs to coexist at the same time.
132 <a name="details"> Version History </a>
135 How can this complexity be managed? What does C++ versioning mean?
136 Because library and compiler changes often make binaries compiled
137 with one version of the GNU tools incompatible with binaries
138 compiled with other (either newer or older) versions of the same GNU
139 tools, specific techniques are used to make managing this complexity
144 The following techniques are used:
149 <li> <p>Release versioning on the libgcc_s.so binary. This is
150 implemented via file names and the ELF DT_SONAME mechanism (at least
153 <p>It is versioned as follows:
156 <li>gcc-3.0.0: libgcc_s.so.1</li>
157 <li>gcc-3.0.1: libgcc_s.so.1</li>
158 <li>gcc-3.0.2: libgcc_s.so.1</li>
159 <li>gcc-3.0.3: libgcc_s.so.1</li>
160 <li>gcc-3.0.4: libgcc_s.so.1</li>
161 <li>gcc-3.1.0: libgcc_s.so.1</li>
162 <li>gcc-3.1.1: libgcc_s.so.1</li>
163 <li>gcc-3.2.0: libgcc_s.so.1</li>
164 <li>gcc-3.2.1: libgcc_s.so.1</li>
165 <li>gcc-3.2.2: libgcc_s.so.1</li>
166 <li>gcc-3.2.3: libgcc_s.so.1</li>
167 <li>gcc-3.3.0: libgcc_s.so.1</li>
168 <li>gcc-3.3.1: libgcc_s.so.1</li>
169 <li>gcc-3.3.2: libgcc_s.so.1</li>
170 <li>gcc-3.3.3: libgcc_s.so.1</li>
171 <li>gcc-3.4.x, gcc-4.0.x, gcc-4.1.x, gcc-4.2.x: on m68k-linux and
172 hppa-linux this is either libgcc_s.so.1 (when configuring
173 <code>--with-sjlj-exceptions</code>) or libgcc_s.so.2. For all
174 others, this is libgcc_s.so.1. </li> </ul>
178 <li>Symbol versioning on the libgcc_s.so binary.
179 <p>mapfile: gcc/libgcc-std.ver</p>
181 <p>It is versioned with the following labels and version
182 definitions, where the version definition is the maximum for a
183 particular release. Labels are cumulative. If a particular release
184 is not listed, it has the same version labels as the preceeding
187 <li>gcc-3.0.0: GCC_3.0</li>
188 <li>gcc-3.3.0: GCC_3.3</li>
189 <li>gcc-3.3.1: GCC_3.3.1</li>
190 <li>gcc-3.3.2: GCC_3.3.2</li>
191 <li>gcc-3.3.4: GCC_3.3.4</li>
192 <li>gcc-3.4.0: GCC_3.4</li>
193 <li>gcc-3.4.2: GCC_3.4.2</li>
194 <li>gcc-3.4.4: GCC_3.4.4</li>
195 <li>gcc-4.0.0: GCC_4.0.0</li>
196 <li>gcc-4.1.0: GCC_4.1.0</li>
197 <li>gcc-4.2.0: GCC_4.2.0</li>
202 <li>Release versioning on the libstdc++.so binary, implemented in the same was as the libgcc_s.so binary, above.
204 <p>It is versioned as follows:
207 <li>gcc-3.0.0: libstdc++.so.3.0.0</li>
208 <li>gcc-3.0.1: libstdc++.so.3.0.1</li>
209 <li>gcc-3.0.2: libstdc++.so.3.0.2</li>
210 <li>gcc-3.0.3: libstdc++.so.3.0.2 (Error should be libstdc++.so.3.0.3)</li>
211 <li>gcc-3.0.4: libstdc++.so.3.0.4</li>
212 <li>gcc-3.1.0: libstdc++.so.4.0.0</li>
213 <li>gcc-3.1.1: libstdc++.so.4.0.1</li>
214 <li>gcc-3.2.0: libstdc++.so.5.0.0</li>
215 <li>gcc-3.2.1: libstdc++.so.5.0.1</li>
216 <li>gcc-3.2.2: libstdc++.so.5.0.2</li>
217 <li>gcc-3.2.3: libstdc++.so.5.0.3 (Not strictly required)</li>
218 <li>gcc-3.3.0: libstdc++.so.5.0.4</li>
219 <li>gcc-3.3.1: libstdc++.so.5.0.5</li>
220 <li>gcc-3.3.2: libstdc++.so.5.0.5</li>
221 <li>gcc-3.3.3: libstdc++.so.5.0.5</li>
222 <li>gcc-3.4.0: libstdc++.so.6.0.0</li>
223 <li>gcc-3.4.1: libstdc++.so.6.0.1</li>
224 <li>gcc-3.4.2: libstdc++.so.6.0.2</li>
225 <li>gcc-3.4.3: libstdc++.so.6.0.3</li>
226 <li>gcc-3.4.4: libstdc++.so.6.0.3</li>
227 <li>gcc-3.4.5: libstdc++.so.6.0.3</li>
228 <li>gcc-3.4.6: libstdc++.so.6.0.3</li>
229 <li>gcc-4.0.0: libstdc++.so.6.0.4</li>
230 <li>gcc-4.0.1: libstdc++.so.6.0.5</li>
231 <li>gcc-4.0.2: libstdc++.so.6.0.6</li>
232 <li>gcc-4.0.3: libstdc++.so.6.0.7</li>
233 <li>gcc-4.1.0: libstdc++.so.6.0.7</li>
234 <li>gcc-4.1.1: libstdc++.so.6.0.8</li>
235 <li>gcc-4.1.2: libstdc++.so.6.0.8</li>
236 <li>gcc-4.2.0: libstdc++.so.6.0.9</li>
241 <li>Symbol versioning on the libstdc++.so binary.
243 <p>mapfile: libstdc++-v3/config/linker-map.gnu</p>
244 <p>It is versioned with the following labels and version
245 definitions, where the version definition is the maximum for a
246 particular release. Note, only symbol which are newly introduced
247 will use the maximum version definition. Thus, for release series
248 with the same label, but incremented version definitions, the later
249 release has both versions. (An example of this would be the
250 gcc-3.2.1 release, which has GLIBCPP_3.2.1 for new symbols and
251 GLIBCPP_3.2 for symbols that were introduced in the gcc-3.2.0
252 release.) If a particular release is not listed, it has the same
253 version labels as the preceeding release.
256 <li>gcc-3.0.0: (Error, not versioned)</li>
257 <li>gcc-3.0.1: (Error, not versioned)</li>
258 <li>gcc-3.0.2: (Error, not versioned)</li>
259 <li>gcc-3.0.3: (Error, not versioned)</li>
260 <li>gcc-3.0.4: (Error, not versioned)</li>
261 <li>gcc-3.1.0: GLIBCPP_3.1, CXXABI_1</li>
262 <li>gcc-3.1.1: GLIBCPP_3.1, CXXABI_1</li>
263 <li>gcc-3.2.0: GLIBCPP_3.2, CXXABI_1.2</li>
264 <li>gcc-3.2.1: GLIBCPP_3.2.1, CXXABI_1.2</li>
265 <li>gcc-3.2.2: GLIBCPP_3.2.2, CXXABI_1.2</li>
266 <li>gcc-3.2.3: GLIBCPP_3.2.2, CXXABI_1.2</li>
267 <li>gcc-3.3.0: GLIBCPP_3.2.2, CXXABI_1.2.1</li>
268 <li>gcc-3.3.1: GLIBCPP_3.2.3, CXXABI_1.2.1</li>
269 <li>gcc-3.3.2: GLIBCPP_3.2.3, CXXABI_1.2.1</li>
270 <li>gcc-3.3.3: GLIBCPP_3.2.3, CXXABI_1.2.1</li>
271 <li>gcc-3.4.0: GLIBCXX_3.4, CXXABI_1.3</li>
272 <li>gcc-3.4.1: GLIBCXX_3.4.1, CXXABI_1.3</li>
273 <li>gcc-3.4.2: GLIBCXX_3.4.2</li>
274 <li>gcc-3.4.3: GLIBCXX_3.4.3</li>
275 <li>gcc-4.0.0: GLIBCXX_3.4.4, CXXABI_1.3.1</li>
276 <li>gcc-4.0.1: GLIBCXX_3.4.5</li>
277 <li>gcc-4.0.2: GLIBCXX_3.4.6</li>
278 <li>gcc-4.0.3: GLIBCXX_3.4.7</li>
279 <li>gcc-4.1.1: GLIBCXX_3.4.8</li>
280 <li>gcc-4.2.0: GLIBCXX_3.4.9</li>
286 <p>Incremental bumping of a compiler pre-defined macro,
287 __GXX_ABI_VERSION. This macro is defined as the version of the
288 compiler v3 ABI, with g++ 3.0.x being version 100. This macro will
289 be automatically defined whenever g++ is used (the curious can
290 test this by invoking g++ with the '-v' flag.)
294 This macro was defined in the file "lang-specs.h" in the gcc/cp directory.
295 Later versions defined it in "c-common.c" in the gcc directory, and from
296 G++ 3.4 it is defined in c-cppbuiltin.c and its value determined by the
297 '-fabi-version' command line option.
301 It is versioned as follows, where 'n' is given by '-fabi-version=n':
304 <li>gcc-3.0.x: 100</li>
305 <li>gcc-3.1.x: 100 (Error, should be 101)</li>
306 <li>gcc-3.2.x: 102</li>
307 <li>gcc-3.3.x: 102</li>
308 <li>gcc-3.4.x, gcc-4.0.x, gcc-4.1.x, gcc-4.2.x: 102 (when n=1)</li>
309 <li>gcc-3.4.x, gcc-4.0.x, gcc-4.1.x, gcc-4.2.x: 1000 + n (when n>1)</li>
310 <li>gcc-3.4.x, gcc-4.0.x, gcc-4.1.x, gcc-4.2.x: 999999 (when n=0)</li>
316 <p>Changes to the default compiler option for
317 <code>-fabi-version</code>.
320 It is versioned as follows:
323 <li>gcc-3.0.x: (Error, not versioned) </li>
324 <li>gcc-3.1.x: (Error, not versioned) </li>
325 <li>gcc-3.2.x: <code>-fabi-version=1</code></li>
326 <li>gcc-3.3.x: <code>-fabi-version=1</code></li>
327 <li>gcc-3.4.x, gcc-4.0.x, gcc-4.1.x, gcc-4.2.x: <code>-fabi-version=2</code></li>
333 <p>Incremental bumping of a library pre-defined macro. For releases
334 before 3.4.0, the macro is __GLIBCPP__. For later releases, it's
335 __GLIBCXX__. (The libstdc++ project generously changed from CPP to
336 CXX throughout its source to allow the "C" pre-processor the CPP
337 macro namespace.) These macros are defined as the date the library
338 was released, in compressed ISO date format, as an unsigned long.
342 This macro is defined in the file "c++config" in the
343 "libstdc++-v3/include/bits" directory. (Up to gcc-4.1.0, it was
344 changed every night by an automated script. Since gcc-4.1.0, it is
345 the same value as gcc/DATESTAMP.)
348 It is versioned as follows:
351 <li>gcc-3.0.0: 20010615</li>
352 <li>gcc-3.0.1: 20010819</li>
353 <li>gcc-3.0.2: 20011023</li>
354 <li>gcc-3.0.3: 20011220</li>
355 <li>gcc-3.0.4: 20020220</li>
356 <li>gcc-3.1.0: 20020514</li>
357 <li>gcc-3.1.1: 20020725</li>
358 <li>gcc-3.2.0: 20020814</li>
359 <li>gcc-3.2.1: 20021119</li>
360 <li>gcc-3.2.2: 20030205</li>
361 <li>gcc-3.2.3: 20030422</li>
362 <li>gcc-3.3.0: 20030513</li>
363 <li>gcc-3.3.1: 20030804</li>
364 <li>gcc-3.3.2: 20031016</li>
365 <li>gcc-3.3.3: 20040214</li>
366 <li>gcc-3.4.0: 20040419</li>
367 <li>gcc-3.4.1: 20040701</li>
368 <li>gcc-3.4.2: 20040906</li>
369 <li>gcc-3.4.3: 20041105</li>
370 <li>gcc-3.4.4: 20050519</li>
371 <li>gcc-3.4.5: 20051201</li>
372 <li>gcc-3.4.6: 20060306</li>
373 <li>gcc-4.0.0: 20050421</li>
374 <li>gcc-4.0.1: 20050707</li>
375 <li>gcc-4.0.2: 20050921</li>
376 <li>gcc-4.0.3: 20060309</li>
377 <li>gcc-4.1.0: 20060228</li>
378 <li>gcc-4.1.1: 20060524</li>
379 <li>gcc-4.1.2: 20070214</li>
380 <li>gcc-4.2.0: 20070514</li>
387 Incremental bumping of a library pre-defined macro,
388 _GLIBCPP_VERSION. This macro is defined as the released version of
389 the library, as a string literal. This is only implemented in
390 gcc-3.1.0 releases and higher, and is deprecated in 3.4 (where it
391 is called _GLIBCXX_VERSION).
395 This macro is defined in the file "c++config" in the
396 "libstdc++-v3/include/bits" directory and is generated
397 automatically by autoconf as part of the configure-time generation
402 It is versioned as follows:
405 <li>gcc-3.0.0: "3.0.0"</li>
406 <li>gcc-3.0.1: "3.0.0" (Error, should be "3.0.1")</li>
407 <li>gcc-3.0.2: "3.0.0" (Error, should be "3.0.2")</li>
408 <li>gcc-3.0.3: "3.0.0" (Error, should be "3.0.3")</li>
409 <li>gcc-3.0.4: "3.0.0" (Error, should be "3.0.4")</li>
410 <li>gcc-3.1.0: "3.1.0"</li>
411 <li>gcc-3.1.1: "3.1.1"</li>
412 <li>gcc-3.2.0: "3.2"</li>
413 <li>gcc-3.2.1: "3.2.1"</li>
414 <li>gcc-3.2.2: "3.2.2"</li>
415 <li>gcc-3.2.3: "3.2.3"</li>
416 <li>gcc-3.3.0: "3.3"</li>
417 <li>gcc-3.3.1: "3.3.1"</li>
418 <li>gcc-3.3.2: "3.3.2"</li>
419 <li>gcc-3.3.3: "3.3.3"</li>
420 <li>gcc-3.4.x: "version-unused"</li>
421 <li>gcc-4.0.x: "version-unused"</li>
422 <li>gcc-4.1.x: "version-unused"</li>
423 <li>gcc-4.2.x: "version-unused"</li>
430 Matching each specific C++ compiler release to a specific set of
431 C++ include files. This is only implemented in gcc-3.1.1 releases
435 All C++ includes are installed in include/c++, then nest in a
436 directory hierarchy corresponding to the C++ compiler's released
437 version. This version corresponds to the variable "gcc_version" in
438 "libstdc++-v3/acinclude.m4," and more details can be found in that
439 file's macro GLIBCXX_CONFIGURE (GLIBCPP_CONFIGURE before gcc-3.4.0).
442 C++ includes are versioned as follows:
445 <li>gcc-3.0.0: include/g++-v3</li>
446 <li>gcc-3.0.1: include/g++-v3</li>
447 <li>gcc-3.0.2: include/g++-v3</li>
448 <li>gcc-3.0.3: include/g++-v3</li>
449 <li>gcc-3.0.4: include/g++-v3</li>
450 <li>gcc-3.1.0: include/g++-v3</li>
451 <li>gcc-3.1.1: include/c++/3.1.1</li>
452 <li>gcc-3.2.0: include/c++/3.2</li>
453 <li>gcc-3.2.1: include/c++/3.2.1</li>
454 <li>gcc-3.2.2: include/c++/3.2.2</li>
455 <li>gcc-3.2.3: include/c++/3.2.3</li>
456 <li>gcc-3.3.0: include/c++/3.3</li>
457 <li>gcc-3.3.1: include/c++/3.3.1</li>
458 <li>gcc-3.3.2: include/c++/3.3.2</li>
459 <li>gcc-3.3.3: include/c++/3.3.3</li>
460 <li>gcc-3.4.0: include/c++/3.4.0</li>
461 <li>gcc-3.4.1: include/c++/3.4.1</li>
462 <li>gcc-3.4.2: include/c++/3.4.2</li>
463 <li>gcc-3.4.3: include/c++/3.4.3</li>
464 <li>gcc-3.4.4: include/c++/3.4.4</li>
465 <li>gcc-3.4.5: include/c++/3.4.5</li>
466 <li>gcc-3.4.6: include/c++/3.4.6</li>
467 <li>gcc-4.0.0: include/c++/4.0.0</li>
468 <li>gcc-4.0.1: include/c++/4.0.1</li>
469 <li>gcc-4.0.2: include/c++/4.0.2</li>
470 <li>gcc-4.0.3: include/c++/4.0.3</li>
471 <li>gcc-4.1.0: include/c++/4.1.0</li>
472 <li>gcc-4.1.1: include/c++/4.1.1</li>
473 <li>gcc-4.1.2: include/c++/4.1.2</li>
474 <li>gcc-4.2.0: include/c++/4.2.0</li>
480 Taken together, these techniques can accurately specify interface
481 and implementation changes in the GNU C++ tools themselves. Used
482 properly, they allow both the GNU C++ tools implementation, and
483 programs using them, an evolving yet controlled development that
484 maintains backward compatibility.
490 <a name="requirements"> Minimum requirements for a versioned ABI </a>
493 Minimum environment that supports a versioned ABI: A supported
494 dynamic linker, a GNU linker of sufficient vintage to understand
495 demangled C++ name globbing (ld), a shared executable compiled with
496 g++, and shared libraries (libgcc_s, libstdc++-v3) compiled by a
497 compiler (g++) with a compatible ABI. Phew.
501 On top of all that, an additional constraint: libstdc++ did not
502 attempt to version symbols (or age gracefully, really) until version
507 Most modern Linux and BSD versions, particularly ones using
508 gcc-3.1.x tools and more recent vintages, will meet the requirements above.
513 <a name="config"> What configure options impact symbol versioning? </a>
516 It turns out that most of the configure options that change default
517 behavior will impact the mangled names of exported symbols, and thus
518 impact versioning and compatibility.
522 For more information on configure options, including ABI impacts, see:
523 http://gcc.gnu.org/onlinedocs/libstdc++/configopts.html
527 There is one flag that explicitly deals with symbol versioning:
532 In particular, libstdc++-v3/acinclude.m4 has a macro called
533 GLIBCXX_ENABLE_SYMVERS that defaults to yes (or the argument passed
534 in via --enable-symvers=foo). At that point, the macro attempts to
535 make sure that all the requirement for symbol versioning are in
536 place. For more information, please consult acinclude.m4.
541 <a name="active"> How to tell if symbol versioning is, indeed, active? </a>
544 When the GNU C++ library is being built with symbol versioning on,
545 you should see the following at configure time for libstdc++-v3:
549 <code> checking versioning on shared library symbols... gnu</code>
552 If you don't see this line in the configure output, or if this line
553 appears but the last word is 'no', then you are out of luck.
557 If the compiler is pre-installed, a quick way to test is to compile
558 the following (or any) simple C++ file and link it to the shared
563 #include <iostream>
566 { std::cout << "hello" << std::endl; return 0; }
568 %g++ hello.cc -o hello.out
571 libstdc++.so.5 => /usr/lib/libstdc++.so.5 (0x00764000)
572 libm.so.6 => /lib/tls/libm.so.6 (0x004a8000)
573 libgcc_s.so.1 => /mnt/hd/bld/gcc/gcc/libgcc_s.so.1 (0x40016000)
574 libc.so.6 => /lib/tls/libc.so.6 (0x0036d000)
575 /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x00355000)
581 If you see symbols in the resulting output with "GLIBCXX_3" as part
582 of the name, then the executable is versioned. Here's an example:
585 <code> U _ZNSt8ios_base4InitC1Ev@@GLIBCXX_3.4 </code>
588 <a name="ABI_allowed">Library allowed ABI changes</a>
591 The following will cause the library minor version number to
592 increase, say from "libstdc++.so.3.0.4" to "libstdc++.so.3.0.5".
595 <li>adding an exported global or static data member</li>
596 <li>adding an exported function, static or non-virtual member function</li>
597 <li>adding an exported symbol or symbols by additional instantiations</li>
602 Other allowed changes are possible.
607 <a name="ABI_disallowed">Library disallowed ABI changes</a>
611 The following non-exhaustive list will cause the library major version
612 number to increase, say from "libstdc++.so.3.0.4" to
613 "libstdc++.so.4.0.0".
616 <li>changes in the gcc/g++ compiler ABI</li>
617 <li>changing size of an exported symbol</li>
618 <li>changing alignment of an exported symbol</li>
619 <li>changing the layout of an exported symbol</li>
620 <li>changing mangling on an exported symbol</li>
621 <li>deleting an exported symbol</li>
622 <li>changing the inheritance properties of a type by adding or removing
625 changing the size, alignment, or layout of types
626 specified in the C++ standard. These may not necessarily be
627 instantiated or otherwise exported in the library binary, and
628 include all the required locale facets, as well as things like
629 std::basic_streambuf, et al.
632 <li> adding an explicit copy constructor or destructor to a
633 class that would otherwise have implicit versions. This will change
634 the way the compiler deals with this class in by-value return
635 statements or parameters: instead of being passing instances of this
636 class in registers, the compiler will be forced to use memory. See <a
637 href="http://www.codesourcery.com/cxx-abi/abi.html#calls"> this part</a>
638 of the C++ ABI documentation for further details.
644 <a name="implementation">Library implementation strategy</a> </h3>
647 <li>Separation of interface and implementation
648 <p>This is accomplished by two techniques that separate the API from
649 the ABI: forcing undefined references to link against a library binary
654 <dt>Include files have declarations, source files have defines</dt>
656 <dd> For non-templatized types, such as much of <code>class
657 locale</code>, the appropriate standard C++ include, say
658 <code>locale</code>, can contain full declarations, while various
659 source files (say <code> locale.cc, locale_init.cc,
660 localename.cc</code>) contain definitions.</dd>
662 <dt>Extern template on required types</dt>
664 <dd>For parts of the standard that have an explicit list of required
665 instantiations, the GNU extension syntax <code> extern template
666 </code> can be used to control where template definitions
667 reside. By marking required instantiations as <code> extern
668 template </code> in include files, and providing explicit
669 instantiations in the appropriate instantiation files, non-inlined
670 template functions can be versioned. This technique is mostly used
671 on parts of the standard that require <code> char</code> and <code>
672 wchar_t</code> instantiations, and includes <code>
673 basic_string</code>, the locale facets, and the types in <code>
674 iostreams</code>.</dd>
677 <p> In addition, these techniques have the additional benefit that
678 they reduce binary size, which can increase runtime performance.
682 <li>Namespaces linking symbol definitions to export mapfiles
684 <p>All symbols in the shared library binary are processed by a linker
685 script at build time that either allows or disallows external
686 linkage. Because of this, some symbols, regardless of normal C/C++
687 linkage, are not visible. Symbols that are internal have several
688 appealing characteristics: by not exporting the symbols, there are no
689 relocations when the shared library is started and thus this makes for
690 faster runtime loading performance by the underlying dynamic loading
691 mechanism. In addition, they have the possibility of changing without
692 impacting ABI compatibility.
695 <p>The following namespaces are transformed by the mapfile:</p>
698 <dt><code>namespace std</code></dt>
699 <dd> Defaults to exporting all symbols in label
700 <code>GLIBCXX</code> that do not begin with an underscore, ie
701 <code>__test_func</code> would not be exported by default. Select
702 exceptional symbols are allowed to be visible.</dd>
704 <dt><code>namespace __gnu_cxx</code></dt>
705 <dd> Defaults to not exporting any symbols in label
706 <code>GLIBCXX</code>, select items are allowed to be visible.</dd>
708 <dt><code>namespace __gnu_internal</code></dt>
709 <dd> Defaults to not exported, no items are allowed to be visible.</dd>
711 <dt><code>namespace __cxxabiv1</code>, aliased to <code> namespace abi</code></dt>
712 <dd> Defaults to not exporting any symbols in label
713 <code>CXXABI</code>, select items are allowed to be visible.</dd>
720 <p>Disallowed changes, as above, are not made on a stable release
721 branch. Enforcement tends to be less strict with GNU extensions that
722 standard includes.</p>
727 <a name="ABI_testing">Testing ABI changes</a>
731 Testing for GNU C++ ABI changes is composed of two distinct areas:
732 testing the C++ compiler (g++) for compiler changes, and testing the
733 C++ library (libstdc++) for library changes.
737 Testing the C++ compiler ABI can be done various ways.
742 Intel ABI checker. More information can be obtained
743 <a href="http://developer.intel.com/software/products/opensource/">here.</a>
748 The second is yet unreleased, but has been announced on the gcc
749 mailing list. It is yet unspecified if these tools will be freely
750 available, and able to be included in a GNU project. Please contact
751 Mark Mitchell (mark@codesourcery.com) for more details, and current
757 Involves using the vlad.consistency test framework. This has also been
758 discussed on the gcc mailing lists.
762 Testing the C++ library ABI can also be done various ways.
767 (Brendan Kehoe, Jeff Law suggestion to run 'make check-c++' two ways,
768 one with a new compiler and an old library, and the other with an old
769 compiler and a new library, and look for testsuite regressions)
773 Details on how to set this kind of test up can be found here:
774 http://gcc.gnu.org/ml/gcc/2002-08/msg00142.html
779 Use the 'make check-abi' rule in the libstdc++-v3 Makefile.
783 This is a proactive check the library ABI. Currently, exported symbol
784 names that are either weak or defined are checked against a last known
785 good baseline. Currently, this baseline is keyed off of 3.4.0
786 binaries, as this was the last time the .so number was incremented. In
787 addition, all exported names are demangled, and the exported objects
788 are checked to make sure they are the same size as the same object in
791 Notice that each baseline is relative to a <strong>default</strong>
792 configured library and compiler: in particular, if options such as
793 --enable-clocale, or --with-cpu, in case of multilibs, are used at
794 configure time, the check may fail, either because of substantive
795 differences or because of limitations of the current checking
800 This dataset is insufficient, yet a start. Also needed is a
801 comprehensive check for all user-visible types part of the standard
802 library for sizeof() and alignof() changes.
806 Verifying compatible layouts of objects is not even attempted. It
807 should be possible to use sizeof, alignof, and offsetof to compute
808 offsets for each structure and type in the standard library, saving to
809 another datafile. Then, compute this in a similar way for new
810 binaries, and look for differences.
814 Another approach might be to use the -fdump-class-hierarchy flag to
815 get information. However, currently this approach gives insufficient
816 data for use in library testing, as class data members, their offsets,
817 and other detailed data is not displayed with this flag.
818 (See g++/7470 on how this was used to find bugs.)
822 Perhaps there are other C++ ABI checkers. If so, please notify
823 us. We'd like to know about them!
827 <a name="ABI_multi_testing">Testing Multi-ABI binaries</a>
831 A "C" application, dynamically linked to two shared libraries, liba,
832 libb. The dependent library liba is C++ shared library compiled with
833 gcc-3.3.x, and uses io, exceptions, locale, etc. The dependent library
834 libb is a C++ shared library compiled with gcc-3.4.x, and also uses io,
835 exceptions, locale, etc.
838 <p> As above, libone is constructed as follows: </p>
840 %$bld/H-x86-gcc-3.4.0/bin/g++ -fPIC -DPIC -c a.cc
842 %$bld/H-x86-gcc-3.4.0/bin/g++ -shared -Wl,-soname -Wl,libone.so.1 -Wl,-O1 -Wl,-z,defs a.o -o libone.so.1.0.0
844 %ln -s libone.so.1.0.0 libone.so
846 %$bld/H-x86-gcc-3.4.0/bin/g++ -c a.cc
851 <p> And, libtwo is constructed as follows: </p>
854 %$bld/H-x86-gcc-3.3.3/bin/g++ -fPIC -DPIC -c b.cc
856 %$bld/H-x86-gcc-3.3.3/bin/g++ -shared -Wl,-soname -Wl,libtwo.so.1 -Wl,-O1 -Wl,-z,defs b.o -o libtwo.so.1.0.0
858 %ln -s libtwo.so.1.0.0 libtwo.so
860 %$bld/H-x86-gcc-3.3.3/bin/g++ -c b.cc
865 <p> ...with the resulting libraries looking like </p>
868 libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x40016000)
869 libm.so.6 => /lib/tls/libm.so.6 (0x400fa000)
870 libgcc_s.so.1 => /mnt/hd/bld/gcc/gcc/libgcc_s.so.1 (0x4011c000)
871 libc.so.6 => /lib/tls/libc.so.6 (0x40125000)
872 /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x00355000)
875 libstdc++.so.5 => /usr/lib/libstdc++.so.5 (0x40027000)
876 libm.so.6 => /lib/tls/libm.so.6 (0x400e1000)
877 libgcc_s.so.1 => /mnt/hd/bld/gcc/gcc/libgcc_s.so.1 (0x40103000)
878 libc.so.6 => /lib/tls/libc.so.6 (0x4010c000)
879 /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x00355000)
883 <p> Then, the "C" compiler is used to compile a source file that uses
884 functions from each library.</p>
886 gcc test.c -g -O2 -L. -lone -ltwo /usr/lib/libstdc++.so.5 /usr/lib/libstdc++.so.6
890 Which gives the expected:
894 libstdc++.so.5 => /usr/lib/libstdc++.so.5 (0x00764000)
895 libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x40015000)
896 libc.so.6 => /lib/tls/libc.so.6 (0x0036d000)
897 libm.so.6 => /lib/tls/libm.so.6 (0x004a8000)
898 libgcc_s.so.1 => /mnt/hd/bld/gcc/gcc/libgcc_s.so.1 (0x400e5000)
899 /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x00355000)
903 This resulting binary, when executed, will be able to safely use code
904 from both liba, and the dependent libstdc++.so.6, and libb, with the
905 dependent libstdc++.so.5.
910 <a name="Outstanding Issues">Outstanding Issues</a>
913 <p> Some features in the C++ language make versioning especially
914 difficult. In particular, compiler generated constructs such as
915 implicit instantiations for templates, typeinfo information, and
916 virtual tables all may cause ABI leakage across shared library
917 boundaries. Because of this, mixing C++ ABI's is not recommended at
921 <p>For more background on this issue, see these bugzilla entries:</p>
924 <a href="http://gcc.gnu.org/PR24660">24660: versioning weak symbols in libstdc++</a>
928 <a href="http://gcc.gnu.org/PR19664">19664: libstdc++ headers should have pop/push of the visibility around the declarations</a>
932 <a name="references">Bibliography / Further Reading</a>
936 ABIcheck, a vague idea of checking ABI compatibility
938 <a href="http://abicheck.sourceforge.net/">http://abicheck.sourceforge.net/</a>
944 <a href="http://www.codesourcery.com/cxx-abi/">http://www.codesourcery.com/cxx-abi/</a>
948 Intel ABI documentation, "IntelĀ® Compilers for Linux* -Compatibility with the GNU Compilers"
950 <a href="http://developer.intel.com/software/products/compilers/techtopics/LinuxCompilersCompatibility.htm">http://developer.intel.com/software/products/compilers/techtopics/LinuxCompilersCompatibility.htm</a>
956 Linker and Libraries Guide (document 816-1386)
958 C++ Migration Guide (document 816-2459)
960 <a href="http://docs.sun.com/db/prod/solaris.9">http://docs.sun.com/db/prod/solaris.9</a>
962 <a href="http://docs.sun.com/?p=/doc/816-1386&a=load">http://docs.sun.com/?p=/doc/816-1386&a=load</a>
966 Ulrich Drepper, "ELF Symbol Versioning"
968 <a href="http://people.redhat.com/drepper/symbol-versioning">http://people.redhat.com/drepper/symbol-versioning</a>
972 C++ ABI for the ARM Architecture
974 <a href="http://www.arm.com/miscPDFs/8033.pdf">http://www.arm.com/miscPDFs/8033.pdf</a>
978 Benjamin Kosnik, ISO C++ J16/06-0046
980 <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n1976.html">Dynamic Shared Objects: Survey and Issues</a>
984 Benjamin Kosnik, ISO C++ J16/06-0083
986 <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2013.html">Versioning With Namespaces</a>