xref: /openbsd/gnu/gcc/libstdc++-v3/docs/html/abi.html (revision d415bd75)
1<?xml version="1.0" encoding="ISO-8859-1"?>
2<!DOCTYPE html
3          PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
6<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
7<head>
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" />
17</head>
18<body>
19
20<h1 class="centered"><a name="top">C++ Standard Library ABI</a></h1>
21
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>.
26</em></p>
27
28<p><em>
29   To the <a href="http://gcc.gnu.org/libstdc++/">libstdc++-v3 homepage</a>.
30</em></p>
31
32<!-- ####################################################### -->
33<hr />
34<h3 class="left">
35  <a name="CXXinterface">The C++ interface</a>
36</h3>
37
38<p> C++ applications often dependent on specific language support
39routines, say for throwing exceptions, or catching exceptions, and
40perhaps also dependent on features in the C++ Standard Library.
41</p>
42
43<p> The C++ Standard Library has many include files, types defined in
44those include files, specific named functions, and other behavior. The
45text of these behaviors, as written in source include files, is called
46the Application Programing Interface, or API.
47</p>
48
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>.
58</p>
59
60<p>
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>.
70</p>
71
72<p> The configure options used when building a specific libstdc++
73version may also impact the resulting library ABI. The available
74configure options, and their impact on the library ABI, are documented
75<a href="http://gcc.gnu.org/onlinedocs/libstdc++/configopts.html">
76here</a>.
77</p>
78
79<p> Putting all of these ideas together results in the C++ Standard
80library ABI, which is the compilation of a given library API by a
81given compiler ABI. In a nutshell:
82</p>
83
84<code> library API + compiler ABI = library ABI</code>
85
86<p>
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.
95</p>
96
97<p>
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.
101</p>
102
103<h3 class="left">
104  <a name="ABI_versioning">Versioning</a>
105</h3>
106
107<p> The C++ interface has evolved throughout the history of the GNU
108C++ toolchain. With each release, various details have been changed so
109as to give distinct versions to the C++ interface.
110</p>
111
112<h5 class="left">
113  <a name="goals">Goals of versioning</a>
114</h5>
115
116<p>Extending existing, stable ABIs. Versioning gives subsequent stable
117releases series libraries the ability to add new symbols and add
118functionality, all the while retaining backwards compatibility with
119the previous releases in the series. Note: the reverse is not true. It
120is not possible to take binaries linked with the latest version of a
121release series (if symbols have been added) and expect the initial
122release of the series to remain link compatible.
123</p>
124
125<p>Allows multiple, incompatible ABIs to coexist at the same time.
126</p>
127
128<p>
129</p>
130
131<h5 class="left">
132  <a name="details"> Version History </a>
133</h5>
134<p>
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
140  easier.
141</p>
142
143<p>
144  The following techniques are used:
145</p>
146
147  <ul>
148
149    <li> <p>Release versioning on the libgcc_s.so binary. This is
150implemented via file names and the ELF DT_SONAME mechanism (at least
151on ELF systems).</p>
152
153    <p>It is versioned as follows:
154    </p>
155    <ul>
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: on m68k-linux and hppa-linux
172    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>
175    <p></p>
176    </li>
177
178    <li>Symbol versioning on the libgcc_s.so binary.
179    <p>mapfile: gcc/libgcc-std.ver</p>
180
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
185   release.</p>
186    <ul>
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    </ul>
198    <p></p>
199    </li>
200
201    <li>Release versioning on the libstdc++.so binary, implemented in the same was as the libgcc_s.so binary, above.
202
203    <p>It is versioned as follows:
204    </p>
205    <ul>
206    <li>gcc-3.0.0: libstdc++.so.3.0.0</li>
207    <li>gcc-3.0.1: libstdc++.so.3.0.1</li>
208    <li>gcc-3.0.2: libstdc++.so.3.0.2</li>
209    <li>gcc-3.0.3: libstdc++.so.3.0.2 (Error should be libstdc++.so.3.0.3)</li>
210    <li>gcc-3.0.4: libstdc++.so.3.0.4</li>
211    <li>gcc-3.1.0: libstdc++.so.4.0.0</li>
212    <li>gcc-3.1.1: libstdc++.so.4.0.1</li>
213    <li>gcc-3.2.0: libstdc++.so.5.0.0</li>
214    <li>gcc-3.2.1: libstdc++.so.5.0.1</li>
215    <li>gcc-3.2.2: libstdc++.so.5.0.2</li>
216    <li>gcc-3.2.3: libstdc++.so.5.0.3 (Not strictly required)</li>
217    <li>gcc-3.3.0: libstdc++.so.5.0.4</li>
218    <li>gcc-3.3.1: libstdc++.so.5.0.5</li>
219    <li>gcc-3.3.2: libstdc++.so.5.0.5</li>
220    <li>gcc-3.3.3: libstdc++.so.5.0.5</li>
221    <li>gcc-3.4.0: libstdc++.so.6.0.0</li>
222    <li>gcc-3.4.1: libstdc++.so.6.0.1</li>
223    <li>gcc-3.4.2: libstdc++.so.6.0.2</li>
224    <li>gcc-3.4.3: libstdc++.so.6.0.3</li>
225    <li>gcc-3.4.4: libstdc++.so.6.0.3</li>
226    <li>gcc-3.4.5: libstdc++.so.6.0.3</li>
227    <li>gcc-3.4.6: libstdc++.so.6.0.3</li>
228    <li>gcc-4.0.0: libstdc++.so.6.0.4</li>
229    <li>gcc-4.0.1: libstdc++.so.6.0.5</li>
230    <li>gcc-4.0.2: libstdc++.so.6.0.6</li>
231    <li>gcc-4.0.3: libstdc++.so.6.0.7</li>
232    <li>gcc-4.1.0: libstdc++.so.6.0.7</li>
233    <li>gcc-4.1.1: libstdc++.so.6.0.8</li>
234    </ul>
235    <p></p>
236    </li>
237
238    <li>Symbol versioning on the libstdc++.so binary.
239
240    <p>mapfile: libstdc++-v3/config/linker-map.gnu</p>
241    <p>It is versioned with the following labels and version
242   definitions, where the version definition is the maximum for a
243   particular release. Note, only symbol which are newly introduced
244   will use the maximum version definition. Thus, for release series
245   with the same label, but incremented version definitions, the later
246   release has both versions. (An example of this would be the
247   gcc-3.2.1 release, which has GLIBCPP_3.2.1 for new symbols and
248   GLIBCPP_3.2 for symbols that were introduced in the gcc-3.2.0
249   release.) If a particular release is not listed, it has the same
250   version labels as the preceeding release.
251   </p>
252    <ul>
253    <li>gcc-3.0.0: (Error, not versioned)</li>
254    <li>gcc-3.0.1: (Error, not versioned)</li>
255    <li>gcc-3.0.2: (Error, not versioned)</li>
256    <li>gcc-3.0.3: (Error, not versioned)</li>
257    <li>gcc-3.0.4: (Error, not versioned)</li>
258    <li>gcc-3.1.0: GLIBCPP_3.1, CXXABI_1</li>
259    <li>gcc-3.1.1: GLIBCPP_3.1, CXXABI_1</li>
260    <li>gcc-3.2.0: GLIBCPP_3.2, CXXABI_1.2</li>
261    <li>gcc-3.2.1: GLIBCPP_3.2.1, CXXABI_1.2</li>
262    <li>gcc-3.2.2: GLIBCPP_3.2.2, CXXABI_1.2</li>
263    <li>gcc-3.2.3: GLIBCPP_3.2.2, CXXABI_1.2</li>
264    <li>gcc-3.3.0: GLIBCPP_3.2.2, CXXABI_1.2.1</li>
265    <li>gcc-3.3.1: GLIBCPP_3.2.3, CXXABI_1.2.1</li>
266    <li>gcc-3.3.2: GLIBCPP_3.2.3, CXXABI_1.2.1</li>
267    <li>gcc-3.3.3: GLIBCPP_3.2.3, CXXABI_1.2.1</li>
268    <li>gcc-3.4.0: GLIBCXX_3.4, CXXABI_1.3</li>
269    <li>gcc-3.4.1: GLIBCXX_3.4.1, CXXABI_1.3</li>
270    <li>gcc-3.4.2: GLIBCXX_3.4.2</li>
271    <li>gcc-3.4.3: GLIBCXX_3.4.3</li>
272    <li>gcc-4.0.0: GLIBCXX_3.4.4, CXXABI_1.3.1</li>
273    <li>gcc-4.0.1: GLIBCXX_3.4.5</li>
274    <li>gcc-4.0.2: GLIBCXX_3.4.6</li>
275    <li>gcc-4.0.3: GLIBCXX_3.4.7</li>
276    <li>gcc-4.1.1: GLIBCXX_3.4.8</li>
277    </ul>
278    <p></p>
279    </li>
280
281    <li>
282    <p>Incremental bumping of a compiler pre-defined macro,
283    __GXX_ABI_VERSION. This macro is defined as the version of the
284    compiler v3 ABI, with g++ 3.0.x being version 100. This macro will
285    be automatically defined whenever g++ is used (the curious can
286    test this by invoking g++ with the '-v' flag.)
287    </p>
288
289    <p>
290    This macro was defined in the file "lang-specs.h" in the gcc/cp directory.
291    Later versions defined it in "c-common.c" in the gcc directory, and from
292    G++ 3.4 it is defined in c-cppbuiltin.c and its value determined by the
293    '-fabi-version' command line option.
294    </p>
295
296    <p>
297    It is versioned as follows, where 'n' is given by '-fabi-version=n':
298    </p>
299    <ul>
300    <li>gcc-3.0.x: 100</li>
301    <li>gcc-3.1.x: 100 (Error, should be 101)</li>
302    <li>gcc-3.2.x: 102</li>
303    <li>gcc-3.3.x: 102</li>
304    <li>gcc-3.4.x, gcc-4.0.x, gcc-4.1.x: 102 (when n=1)</li>
305    <li>gcc-3.4.x, gcc-4.0.x, gcc-4.1.x: 1000 + n (when n&gt;1)</li>
306    <li>gcc-3.4.x, gcc-4.0.x, gcc-4.1.x: 999999 (when n=0)</li>
307    </ul>
308    <p></p>
309    </li>
310
311    <li>
312    <p>Changes to the default compiler option for
313    <code>-fabi-version</code>.
314    </p>
315   <p>
316    It is versioned as follows:
317    </p>
318    <ul>
319    <li>gcc-3.0.x: (Error, not versioned) </li>
320    <li>gcc-3.1.x: (Error, not versioned) </li>
321    <li>gcc-3.2.x: <code>-fabi-version=1</code></li>
322    <li>gcc-3.3.x: <code>-fabi-version=1</code></li>
323    <li>gcc-3.4.x, gcc-4.0.x, gcc-4.1.x: <code>-fabi-version=2</code></li>
324    </ul>
325    <p></p>
326    </li>
327
328   <li>
329    <p>Incremental bumping of a library pre-defined macro. For releases
330    before 3.4.0, the macro is __GLIBCPP__. For later releases, it's
331    __GLIBCXX__. (The libstdc++ project generously changed from CPP to
332    CXX throughout its source to allow the "C" pre-processor the CPP
333    macro namespace.) These macros are defined as the date the library
334    was released, in compressed ISO date format, as an unsigned long.
335    </p>
336
337    <p>
338    This macro is defined in the file "c++config" in the
339    "libstdc++-v3/include/bits" directory. (Up to gcc-4.1.0, it was
340    changed every night by an automated script. Since gcc-4.1.0, it is
341    the same value as gcc/DATESTAMP.)
342    </p>
343    <p>
344    It is versioned as follows:
345    </p>
346    <ul>
347    <li>gcc-3.0.0: 20010615</li>
348    <li>gcc-3.0.1: 20010819</li>
349    <li>gcc-3.0.2: 20011023</li>
350    <li>gcc-3.0.3: 20011220</li>
351    <li>gcc-3.0.4: 20020220</li>
352    <li>gcc-3.1.0: 20020514</li>
353    <li>gcc-3.1.1: 20020725</li>
354    <li>gcc-3.2.0: 20020814</li>
355    <li>gcc-3.2.1: 20021119</li>
356    <li>gcc-3.2.2: 20030205</li>
357    <li>gcc-3.2.3: 20030422</li>
358    <li>gcc-3.3.0: 20030513</li>
359    <li>gcc-3.3.1: 20030804</li>
360    <li>gcc-3.3.2: 20031016</li>
361    <li>gcc-3.3.3: 20040214</li>
362    <li>gcc-3.4.0: 20040419</li>
363    <li>gcc-3.4.1: 20040701</li>
364    <li>gcc-3.4.2: 20040906</li>
365    <li>gcc-3.4.3: 20041105</li>
366    <li>gcc-3.4.4: 20050519</li>
367    <li>gcc-3.4.5: 20051201</li>
368    <li>gcc-3.4.6: 20060306</li>
369    <li>gcc-4.0.0: 20050421</li>
370    <li>gcc-4.0.1: 20050707</li>
371    <li>gcc-4.0.2: 20050921</li>
372    <li>gcc-4.0.3: 20060309</li>
373    <li>gcc-4.1.0: 20060228</li>
374    <li>gcc-4.1.1: 20060524</li>
375    </ul>
376    <p></p>
377    </li>
378
379    <li>
380    <p>
381    Incremental bumping of a library pre-defined macro,
382    _GLIBCPP_VERSION. This macro is defined as the released version of
383    the library, as a string literal. This is only implemented in
384    gcc-3.1.0 releases and higher, and is deprecated in 3.4 (where it
385    is called _GLIBCXX_VERSION).
386    </p>
387
388    <p>
389    This macro is defined in the file "c++config" in the
390    "libstdc++-v3/include/bits" directory and is generated
391    automatically by autoconf as part of the configure-time generation
392    of config.h.
393    </p>
394
395    <p>
396    It is versioned as follows:
397    </p>
398    <ul>
399    <li>gcc-3.0.0: "3.0.0"</li>
400    <li>gcc-3.0.1: "3.0.0" (Error, should be "3.0.1")</li>
401    <li>gcc-3.0.2: "3.0.0" (Error, should be "3.0.2")</li>
402    <li>gcc-3.0.3: "3.0.0" (Error, should be "3.0.3")</li>
403    <li>gcc-3.0.4: "3.0.0" (Error, should be "3.0.4")</li>
404    <li>gcc-3.1.0: "3.1.0"</li>
405    <li>gcc-3.1.1: "3.1.1"</li>
406    <li>gcc-3.2.0: "3.2"</li>
407    <li>gcc-3.2.1: "3.2.1"</li>
408    <li>gcc-3.2.2: "3.2.2"</li>
409    <li>gcc-3.2.3: "3.2.3"</li>
410    <li>gcc-3.3.0: "3.3"</li>
411    <li>gcc-3.3.1: "3.3.1"</li>
412    <li>gcc-3.3.2: "3.3.2"</li>
413    <li>gcc-3.3.3: "3.3.3"</li>
414    <li>gcc-3.4.x: "version-unused"</li>
415    <li>gcc-4.0.x: "version-unused"</li>
416    <li>gcc-4.1.x: "version-unused"</li>
417    </ul>
418    <p></p>
419    </li>
420
421    <li>
422    <p>
423    Matching each specific C++ compiler release to a specific set of
424    C++ include files. This is only implemented in gcc-3.1.1 releases
425    and higher.
426    </p>
427    <p>
428    All C++ includes are installed in include/c++, then nest in a
429    directory hierarchy corresponding to the C++ compiler's released
430    version. This version corresponds to the variable "gcc_version" in
431    "libstdc++-v3/acinclude.m4," and more details can be found in that
432    file's macro GLIBCXX_CONFIGURE (GLIBCPP_CONFIGURE before gcc-3.4.0).
433    </p>
434    <p>
435    C++ includes are versioned as follows:
436    </p>
437    <ul>
438    <li>gcc-3.0.0: include/g++-v3</li>
439    <li>gcc-3.0.1: include/g++-v3</li>
440    <li>gcc-3.0.2: include/g++-v3</li>
441    <li>gcc-3.0.3: include/g++-v3</li>
442    <li>gcc-3.0.4: include/g++-v3</li>
443    <li>gcc-3.1.0: include/g++-v3</li>
444    <li>gcc-3.1.1: include/c++/3.1.1</li>
445    <li>gcc-3.2.0: include/c++/3.2</li>
446    <li>gcc-3.2.1: include/c++/3.2.1</li>
447    <li>gcc-3.2.2: include/c++/3.2.2</li>
448    <li>gcc-3.2.3: include/c++/3.2.3</li>
449    <li>gcc-3.3.0: include/c++/3.3</li>
450    <li>gcc-3.3.1: include/c++/3.3.1</li>
451    <li>gcc-3.3.2: include/c++/3.3.2</li>
452    <li>gcc-3.3.3: include/c++/3.3.3</li>
453    <li>gcc-3.4.0: include/c++/3.4.0</li>
454    <li>gcc-3.4.1: include/c++/3.4.1</li>
455    <li>gcc-3.4.2: include/c++/3.4.2</li>
456    <li>gcc-3.4.3: include/c++/3.4.3</li>
457    <li>gcc-3.4.4: include/c++/3.4.4</li>
458    <li>gcc-3.4.5: include/c++/3.4.5</li>
459    <li>gcc-3.4.6: include/c++/3.4.6</li>
460    <li>gcc-4.0.0: include/c++/4.0.0</li>
461    <li>gcc-4.0.1: include/c++/4.0.1</li>
462    <li>gcc-4.0.2: include/c++/4.0.2</li>
463    <li>gcc-4.0.3: include/c++/4.0.3</li>
464    <li>gcc-4.1.0: include/c++/4.1.0</li>
465    <li>gcc-4.1.1: include/c++/4.1.1</li>
466    </ul>
467    <p></p>
468    </li>
469  </ul>
470<p>
471  Taken together, these techniques can accurately specify interface
472  and implementation changes in the GNU C++ tools themselves. Used
473  properly, they allow both the GNU C++ tools implementation, and
474  programs using them, an evolving yet controlled development that
475  maintains backward compatibility.
476</p>
477
478
479
480<h5 class="left">
481  <a name="requirements"> Minimum requirements for a versioned ABI </a>
482</h5>
483<p>
484  Minimum environment that supports a versioned ABI: A supported
485  dynamic linker, a GNU linker of sufficient vintage to understand
486  demangled C++ name globbing (ld), a shared executable compiled with
487  g++, and shared libraries (libgcc_s, libstdc++-v3) compiled by a
488  compiler (g++) with a compatible ABI. Phew.
489</p>
490
491<p>
492  On top of all that, an additional constraint: libstdc++ did not
493  attempt to version symbols (or age gracefully, really) until version
494  3.1.0.
495</p>
496
497<p>
498  Most modern Linux and BSD versions, particularly ones using
499  gcc-3.1.x tools and more recent vintages, will meet the requirements above.
500</p>
501
502
503<h5 class="left">
504  <a name="config"> What configure options impact symbol versioning? </a>
505</h5>
506<p>
507  It turns out that most of the configure options that change default
508  behavior will impact the mangled names of exported symbols, and thus
509  impact versioning and compatibility.
510</p>
511
512<p>
513  For more information on configure options, including ABI impacts, see:
514  http://gcc.gnu.org/onlinedocs/libstdc++/configopts.html
515</p>
516
517<p>
518  There is one flag that explicitly deals with symbol versioning:
519  --enable-symvers.
520</p>
521
522<p>
523  In particular, libstdc++-v3/acinclude.m4 has a macro called
524  GLIBCXX_ENABLE_SYMVERS that defaults to yes (or the argument passed
525  in via --enable-symvers=foo). At that point, the macro attempts to
526  make sure that all the requirement for symbol versioning are in
527  place. For more information, please consult acinclude.m4.
528</p>
529
530
531<h5 class="left">
532  <a name="active"> How to tell if symbol versioning is, indeed, active? </a>
533</h5>
534<p>
535  When the GNU C++ library is being built with symbol versioning on,
536  you should see the following at configure time for libstdc++-v3:
537</p>
538
539
540<code>  checking versioning on shared library symbols... gnu</code>
541
542<p>
543  If you don't see this line in the configure output, or if this line
544  appears but the last word is 'no', then you are out of luck.
545</p>
546
547<p>
548  If the compiler is pre-installed, a quick way to test is to compile
549  the following (or any) simple C++ file and link it to the shared
550  libstdc++ library:
551</p>
552
553<pre>
554#include &lt;iostream&gt;
555
556int main()
557{ std::cout &lt;&lt; "hello" &lt;&lt; std::endl; return 0; }
558
559%g++ hello.cc -o hello.out
560
561%ldd hello.out
562        libstdc++.so.5 =&gt; /usr/lib/libstdc++.so.5 (0x00764000)
563        libm.so.6 =&gt; /lib/tls/libm.so.6 (0x004a8000)
564        libgcc_s.so.1 =&gt; /mnt/hd/bld/gcc/gcc/libgcc_s.so.1 (0x40016000)
565        libc.so.6 =&gt; /lib/tls/libc.so.6 (0x0036d000)
566        /lib/ld-linux.so.2 =&gt; /lib/ld-linux.so.2 (0x00355000)
567
568%nm hello.out
569</pre>
570
571<p>
572If you see symbols in the resulting output with "GLIBCXX_3" as part
573of the name, then the executable is versioned. Here's an example:
574</p>
575
576   <code>      U _ZNSt8ios_base4InitC1Ev@@GLIBCXX_3.4 </code>
577
578<h3 class="left">
579  <a name="ABI_allowed">Library allowed ABI changes</a>
580</h3>
581<p>
582The following will cause the library minor version number to
583increase, say from "libstdc++.so.3.0.4" to "libstdc++.so.3.0.5".
584</p>
585<ul>
586 <li>adding an exported global or static data member</li>
587 <li>adding an exported function, static or non-virtual member function</li>
588 <li>adding an exported symbol or symbols by additional instantiations</li>
589</ul>
590<p>
591</p>
592<p>
593Other allowed changes are possible.
594</p>
595
596
597<h3 class="left">
598  <a name="ABI_disallowed">Library disallowed ABI changes</a>
599</h3>
600
601<p>
602The following non-exhaustive list will cause the library major version
603number to increase, say from "libstdc++.so.3.0.4" to
604"libstdc++.so.4.0.0".
605</p>
606<ul>
607 <li>changes in the gcc/g++ compiler ABI</li>
608<li>changing size of an exported symbol</li>
609<li>changing alignment of an exported symbol</li>
610<li>changing the layout of an exported symbol</li>
611<li>changing mangling on an exported symbol</li>
612<li>deleting an exported symbol</li>
613<li>changing the inheritance properties of a type by adding or removing
614    base classes</li>
615<li>
616  changing the size, alignment, or layout of types
617  specified in the C++ standard. These may not necessarily be
618  instantiated or otherwise exported in the library binary, and
619  include all the required locale facets, as well as things like
620  std::basic_streambuf, et al.
621</li>
622
623<li> adding an explicit copy constructor or destructor to a
624class that would otherwise have implicit versions. This will change
625the way the compiler deals with this class in by-value return
626statements or parameters: instead of being passing instances of this
627class in registers, the compiler will be forced to use memory. See <a
628href="http://www.codesourcery.com/cxx-abi/abi.html#calls"> this part</a>
629 of the C++ ABI documentation for further details.
630 </li>
631
632</ul>
633
634<h3 class="left">
635  <a name="implementation">Library implementation strategy</a> </h3>
636
637<ul>
638 <li>Separation of interface and implementation
639<p>This is accomplished by two techniques that separate the API from
640the ABI: forcing undefined references to link against a library binary
641for definitions.
642</p>
643
644 <dl>
645  <dt>Include files have declarations, source files have defines</dt>
646
647   <dd> For non-templatized types, such as much of <code>class
648   locale</code>, the appropriate standard C++ include, say
649   <code>locale</code>, can contain full declarations, while various
650   source files (say <code> locale.cc, locale_init.cc,
651   localename.cc</code>) contain definitions.</dd>
652
653  <dt>Extern template on required types</dt>
654
655   <dd>For parts of the standard that have an explicit list of required
656   instantiations, the GNU extension syntax <code> extern template
657   </code> can be used to control where template definitions
658   reside. By marking required instantiations as <code> extern
659   template </code> in include files, and providing explicit
660   instantiations in the appropriate instantiation files, non-inlined
661   template functions can be versioned. This technique is mostly used
662   on parts of the standard that require <code> char</code> and <code>
663   wchar_t</code> instantiations, and includes <code>
664   basic_string</code>, the locale facets, and the types in <code>
665   iostreams</code>.</dd>
666
667 </dl>
668 <p> In addition, these techniques have the additional benefit that
669 they reduce binary size, which can increase runtime performance.
670 </p>
671 </li>
672
673 <li>Namespaces linking symbol definitions to export mapfiles
674
675<p>All symbols in the shared library binary are processed by a linker
676script at build time that either allows or disallows external
677linkage. Because of this, some symbols, regardless of normal C/C++
678linkage, are not visible. Symbols that are internal have several
679appealing characteristics: by not exporting the symbols, there are no
680relocations when the shared library is started and thus this makes for
681faster runtime loading performance by the underlying dynamic loading
682mechanism. In addition, they have the possibility of changing without
683impacting ABI compatibility.
684</p>
685
686<p>The following namespaces are transformed by the mapfile:</p>
687
688<dl>
689<dt><code>namespace std</code></dt>
690<dd> Defaults to exporting all symbols in label
691<code>GLIBCXX</code> that do not begin with an underscore, ie
692<code>__test_func</code> would not be exported by default. Select
693exceptional symbols are allowed to be visible.</dd>
694
695<dt><code>namespace __gnu_cxx</code></dt>
696<dd> Defaults to not exporting any symbols in label
697<code>GLIBCXX</code>, select items are allowed to be visible.</dd>
698
699<dt><code>namespace __gnu_internal</code></dt>
700<dd> Defaults to not exported, no items are allowed to be visible.</dd>
701
702<dt><code>namespace __cxxabiv1</code>, aliased to <code> namespace abi</code></dt>
703<dd> Defaults to not exporting any symbols in label
704<code>CXXABI</code>, select items are allowed to be visible.</dd>
705</dl>
706<p>
707</p>
708</li>
709
710 <li>Freezing the API
711 <p>Disallowed changes, as above, are not made on a stable release
712branch. Enforcement tends to be less strict with GNU extensions that
713standard includes.</p>
714</li>
715</ul>
716
717<h3 class="left">
718  <a name="ABI_testing">Testing ABI changes</a>
719</h3>
720
721<p>
722Testing for GNU C++ ABI changes is composed of two distinct areas:
723testing the C++ compiler (g++) for compiler changes, and testing the
724C++ library (libstdc++) for library changes.
725</p>
726
727<p>
728Testing the C++ compiler ABI can be done various ways.
729</p>
730
731<p>
732One.
733Intel ABI checker. More information can be obtained
734<a href="http://developer.intel.com/software/products/opensource/">here.</a>
735</p>
736
737<p>
738Two.
739The second is yet unreleased, but has been announced on the gcc
740mailing list. It is yet unspecified if these tools will be freely
741available, and able to be included in a GNU project. Please contact
742Mark Mitchell (mark@codesourcery.com) for more details, and current
743status.
744</p>
745
746<p>
747Three.
748Involves using the vlad.consistency test framework. This has also been
749discussed on the gcc mailing lists.
750</p>
751
752<p>
753Testing the C++ library ABI can also be done various ways.
754</p>
755
756<p>
757One.
758(Brendan Kehoe, Jeff Law suggestion to run 'make check-c++' two ways,
759one with a new compiler and an old library, and the other with an old
760compiler and a new library, and look for testsuite regressions)
761</p>
762
763<p>
764Details on how to set this kind of test up can be found here:
765http://gcc.gnu.org/ml/gcc/2002-08/msg00142.html
766</p>
767
768<p>
769Two.
770Use the 'make check-abi' rule in the libstdc++-v3 Makefile.
771</p>
772
773<p>
774This is a proactive check the library ABI. Currently, exported symbol
775names that are either weak or defined are checked against a last known
776good baseline. Currently, this baseline is keyed off of 3.4.0
777binaries, as this was the last time the .so number was incremented. In
778addition, all exported names are demangled, and the exported objects
779are checked to make sure they are the same size as the same object in
780the baseline.
781
782Notice that each baseline is relative to a <strong>default</strong>
783configured library and compiler: in particular, if options such as
784--enable-clocale, or --with-cpu, in case of multilibs, are used at
785configure time, the check may fail, either because of substantive
786differences or because of limitations of the current checking
787machinery.
788</p>
789
790<p>
791This dataset is insufficient, yet a start. Also needed is a
792comprehensive check for all user-visible types part of the standard
793library for sizeof() and alignof() changes.
794</p>
795
796<p>
797Verifying compatible layouts of objects is not even attempted.  It
798should be possible to use sizeof, alignof, and offsetof to compute
799offsets for each structure and type in the standard library, saving to
800another datafile. Then, compute this in a similar way for new
801binaries, and look for differences.
802</p>
803
804<p>
805Another approach might be to use the -fdump-class-hierarchy flag to
806get information. However, currently this approach gives insufficient
807data for use in library testing, as class data members, their offsets,
808and other detailed data is not displayed with this flag.
809(See g++/7470 on how this was used to find bugs.)
810</p>
811
812<p>
813Perhaps there are other C++ ABI checkers. If so, please notify
814us. We'd like to know about them!
815</p>
816
817<h3 class="left">
818  <a name="ABI_multi_testing">Testing Multi-ABI binaries</a>
819</h3>
820
821<p>
822A "C" application, dynamically linked to two shared libraries, liba,
823libb. The dependent library liba is C++ shared library compiled with
824gcc-3.3.x, and uses io, exceptions, locale, etc. The dependent library
825libb is a C++ shared library compiled with gcc-3.4.x, and also uses io,
826exceptions, locale, etc.
827</p>
828
829<p> As above, libone is constructed as follows: </p>
830<pre>
831%$bld/H-x86-gcc-3.4.0/bin/g++ -fPIC -DPIC -c a.cc
832
833%$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
834
835%ln -s libone.so.1.0.0 libone.so
836
837%$bld/H-x86-gcc-3.4.0/bin/g++ -c a.cc
838
839%ar cru libone.a a.o
840</pre>
841
842<p> And, libtwo is constructed as follows: </p>
843
844<pre>
845%$bld/H-x86-gcc-3.3.3/bin/g++ -fPIC -DPIC -c b.cc
846
847%$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
848
849%ln -s libtwo.so.1.0.0 libtwo.so
850
851%$bld/H-x86-gcc-3.3.3/bin/g++ -c b.cc
852
853%ar cru libtwo.a b.o
854</pre>
855
856<p> ...with the resulting libraries looking like </p>
857<pre>
858%ldd libone.so.1.0.0
859        libstdc++.so.6 =&gt; /usr/lib/libstdc++.so.6 (0x40016000)
860        libm.so.6 =&gt; /lib/tls/libm.so.6 (0x400fa000)
861        libgcc_s.so.1 =&gt; /mnt/hd/bld/gcc/gcc/libgcc_s.so.1 (0x4011c000)
862        libc.so.6 =&gt; /lib/tls/libc.so.6 (0x40125000)
863        /lib/ld-linux.so.2 =&gt; /lib/ld-linux.so.2 (0x00355000)
864
865%ldd libtwo.so.1.0.0
866        libstdc++.so.5 =&gt; /usr/lib/libstdc++.so.5 (0x40027000)
867        libm.so.6 =&gt; /lib/tls/libm.so.6 (0x400e1000)
868        libgcc_s.so.1 =&gt; /mnt/hd/bld/gcc/gcc/libgcc_s.so.1 (0x40103000)
869        libc.so.6 =&gt; /lib/tls/libc.so.6 (0x4010c000)
870        /lib/ld-linux.so.2 =&gt; /lib/ld-linux.so.2 (0x00355000)
871
872</pre>
873
874<p> Then, the "C" compiler is used to compile a source file that uses
875functions from each library.</p>
876<pre>
877gcc test.c -g -O2 -L. -lone -ltwo /usr/lib/libstdc++.so.5 /usr/lib/libstdc++.so.6
878</pre>
879
880<p>
881Which gives the expected:
882</p>
883<pre>
884%ldd a.out
885        libstdc++.so.5 =&gt; /usr/lib/libstdc++.so.5 (0x00764000)
886        libstdc++.so.6 =&gt; /usr/lib/libstdc++.so.6 (0x40015000)
887        libc.so.6 =&gt; /lib/tls/libc.so.6 (0x0036d000)
888        libm.so.6 =&gt; /lib/tls/libm.so.6 (0x004a8000)
889        libgcc_s.so.1 =&gt; /mnt/hd/bld/gcc/gcc/libgcc_s.so.1 (0x400e5000)
890        /lib/ld-linux.so.2 =&gt; /lib/ld-linux.so.2 (0x00355000)
891</pre>
892
893<p>
894This resulting binary, when executed, will be able to safely use code
895from both liba, and the dependent libstdc++.so.6, and libb, with the
896dependent libstdc++.so.5.
897</p>
898
899
900<h3 class="left">
901  <a name="Outstanding Issues">Outstanding Issues</a>
902</h3>
903
904<p> Some features in the C++ language make versioning especially
905difficult. In particular, compiler generated constructs such as
906implicit instantiations for templates, typeinfo information, and
907virtual tables all may cause ABI leakage across shared library
908boundaries. Because of this, mixing C++ ABI's is not recommended at
909this time.
910</p>
911
912<p>For more background on this issue, see these bugzilla entries:</p>
913
914<p>
915<a href="http://gcc.gnu.org/PR24660">24660: versioning weak symbols in libstdc++</a>
916</p>
917
918<p>
919<a href="http://gcc.gnu.org/PR19664">19664: libstdc++ headers should have pop/push of the visibility around the declarations</a>
920</p>
921
922<h3 class="left">
923  <a name="references">Bibliography / Further Reading</a>
924</h3>
925
926<p>
927ABIcheck, a vague idea of checking ABI compatibility
928<br />
929<a href="http://abicheck.sourceforge.net/">http://abicheck.sourceforge.net/</a>
930</p>
931
932<p>
933C++ ABI reference
934<br />
935<a href="http://www.codesourcery.com/cxx-abi/">http://www.codesourcery.com/cxx-abi/</a>
936</p>
937
938<p>
939Intel ABI documentation, "Intel� Compilers for Linux* -Compatibility with the GNU Compilers"
940<br />
941<a href="http://developer.intel.com/software/products/compilers/techtopics/LinuxCompilersCompatibility.htm">http://developer.intel.com/software/products/compilers/techtopics/LinuxCompilersCompatibility.htm</a>
942</p>
943
944<p>
945Sun Solaris 2.9 docs
946<br />
947Linker and Libraries Guide (document 816-1386)
948<br />
949C++ Migration Guide (document 816-2459)
950<br />
951<a href="http://docs.sun.com/db/prod/solaris.9">http://docs.sun.com/db/prod/solaris.9</a>
952<br />
953<a href="http://docs.sun.com/?p=/doc/816-1386&amp;a=load">http://docs.sun.com/?p=/doc/816-1386&amp;a=load</a>
954</p>
955
956<p>
957Ulrich Drepper, "ELF Symbol Versioning"
958<br />
959<a href="http://people.redhat.com/drepper/symbol-versioning">http://people.redhat.com/drepper/symbol-versioning</a>
960</p>
961
962<p>
963C++ ABI for the ARM Architecture
964<br />
965<a href="http://www.arm.com/miscPDFs/8033.pdf">http://www.arm.com/miscPDFs/8033.pdf</a>
966</p>
967
968<p>
969Benjamin Kosnik, ISO C++ J16/06-0046
970<br />
971<a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n1976.html">Dynamic Shared Objects: Survey and Issues</a>
972</p>
973
974<p>
975Benjamin Kosnik, ISO C++ J16/06-0083
976<br />
977<a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2013.html">Versioning With Namespaces</a>
978</p>
979
980</body>
981</html>
982
983