4.5 Static or shared runtimes: one copy of libstdc++, or two

Source references in this chapter are to GCC 15.2.0 (releases/gcc-15.2.0).

You build a plugin with -static-libstdc++, so that it loads into hosts that have an older libstdc++.so.6. A colleague builds a second plugin the same way. Code in the first plugin throws a std::runtime_error, and a handler in the second plugin catches it. That part works. Then the handler calls back into the first plugin to rethrow, and the process aborts with terminate called without an active exception. An exception is active. It is active in the other copy of the C++ runtime.

The folklore says that a static libstdc++ in two shared objects "breaks catch". At the pin the catch works, and the rethrow fails. A static runtime is a private copy of its code and of its state. libstdc++ compares exception types by name, so a catch matches across copies, but the per-thread exception stack is state, and each copy reads only its own.

This chapter closes Part IV, and it pays off Chapter 1.11, which showed how -static-libstdc++ becomes a -Wl,-Bstatic wrap around one -l. It also assumes Chapter 4.2 for the split between libgcc.a, libgcc_eh.a and libgcc_s.so, Chapter 4.3 for the unwinder and the personality routine, and Chapter 4.4 for symbol versioning.

-static, -static-pie, -static-libgcc, -static-libstdc++: four mechanisms

The GCC manual documents each of these options under Link Options: -static "prevents linking with the shared libraries", -static-libgcc forces the static libgcc, and -static-libstdc++ links libstdc++ statically "without necessarily linking other libraries statically". The names suggest one switch with three strengths. The source has four separate mechanisms:

OptionWhat it changesWhere
-staticthe whole link: -static to ld, crt1.o and crtbeginT.o, -lgcc -lgcc_eh, no --eh-frame-hdrtarget specs, such as gnu-user64.h:67 and gnu-user.h:51-61
-static-pie-static -pie --no-dynamic-linker to ld, rcrt1.o and crtbeginS.o, -lgcc -lgcc_eh, and --eh-frame-hdrthe same target specs
-static-libgccthe libgcc spec only: -lgcc -lgcc_eh instead of libgcc_sthe rewritten libgcc spec, Chapter 4.2
-static-libstdc++one library: -Wl,-Bstatic -lstdc++ -Wl,-Bdynamicg++spec.cc, Chapter 1.11

The four do not compose the way their names suggest. -static-libstdc++ does not touch libgcc. g++ starts with shared_libgcc = 1 (g++spec.cc:136-138). -static-libgcc clears it (:231-232), a compiler without a shared libgcc clears it (:297-301), and -static suppresses it (:227-228). Otherwise the driver adds -shared-libgcc:

  if (shared_libgcc && !static_link)
    generate_option (OPT_shared_libgcc, NULL, 1, CL_DRIVER,
		     &new_decoded_options[j++]);

Listing 4.5-1: g++ adds -shared-libgcc unless told otherwise (gcc/cp/g++spec.cc:444-446).

So g++ -shared -static-libstdc++ links a private copy of libstdc++ and the shared libgcc_s. The objects in the process then share one unwinder, and each object that used -static-libstdc++ has its own libsupc++, the part of libstdc++ that implements throw and catch. Chapter 4.2 explains why g++ wants the shared libgcc. This chapter is about the second copy of libsupc++.

-static does one more thing on GNU/Linux that is easy to miss. The target passes --eh-frame-hdr to the linker only when the link is not static:

#if defined(HAVE_LD_EH_FRAME_HDR)
#define LINK_EH_SPEC "%{!static|static-pie:--eh-frame-hdr} "
#endif

Listing 4.5-2: no --eh-frame-hdr under -static (gcc/config/gnu-user.h:108-110).

The static start file changes to match. crtbeginT.o is crtstuff.c compiled with -DCRTSTUFFT_O (libgcc/Makefile.in:1053-1054). That macro removes USE_PT_GNU_EH_FRAME on glibc (crtstuff.c:106-119), so USE_EH_FRAME_REGISTRY takes its place (:139-141), and the start file calls __register_frame_info on the executable's .eh_frame at startup (:468-493). A static executable registers its own unwind tables. In a dynamic one the unwinder walks the loaded objects with dl_iterate_phdr (unwind-dw2-fde-dip.c:569). Chapter 4.3 covers both lookups.

What libstdc++.a holds: the same PIC objects, without versions

-static-libstdc++ -shared works only if the archive members are position-independent. libstdc++ makes sure of that. When shared libraries are enabled, its configure sets -prefer-pic and -D_GLIBCXX_SHARED for libtool (libstdc++-v3/configure.ac:137-146). The libsupc++ and src/c++* directories compile each source once, with both flags, into convenience libraries (src/Makefile.am:235-237, libsupc++/Makefile.am:148-151). Both libstdc++.a and libstdc++.so are made from those libraries (src/Makefile.am:142-148). The reason for the PIC objects is in a comment:

# Why are objects destined for libstdc++.a compiled with -fPIC? First,
# because -fPIC is not harmful to use for objects destined for static
# libraries. In addition, using -fPIC will allow the use of static
# libstdc++.a in the creation of other C++ shared libraries.

Listing 4.5-3: libstdc++.a is built for shared objects on purpose (libstdc++-v3/src/Makefile.am:245-248).

Two things differ between the archive and the shared object. The compatibility sources in src/ are compiled a second time for the archive, without -D_GLIBCXX_SHARED (src/Makefile.am:239-243), and the code that keeps old symbol versions is inside #if ... defined(_GLIBCXX_SHARED) (src/c++98/compatibility.cc:28-30). The comment says why:

# static lib == linked against only this version, should not need compat
# shared lib == linked against potentially all compat versions

Listing 4.5-4: compatibility symbols are for the shared library only (libstdc++-v3/src/Makefile.am:229-230).

The version script is also a link option of libstdc++.so only (src/Makefile.am:163-164, :337). An archive member has no symbol versions. Chapter 4.4 covers what those versions buy the shared library.

Default visibility: why a plugin exports the libstdc++ it copied

The more important difference is visibility. libsupc++ declares its ABI functions inside #pragma GCC visibility push(default) (libsupc++/cxxabi.h:48), and <typeinfo> does the same (typeinfo:44). A shared object that links members of libstdc++.a gets them as global symbols with default visibility, so the linker exports them from that shared object with the rest of its API.

libgcc does the opposite. Its configure sets vis_hide='-fvisibility=hidden -DHIDE_EXPORTS' when the compiler supports hidden visibility (libgcc/configure.ac:549-555), and the C objects for libgcc.a and libgcc_eh.a are compiled with it (libgcc/Makefile.in:510-512, static-object.mk:16-17). The libgcc_s objects are not (shared-object.mk:17). A shared object that links libgcc.a keeps the copy to itself. A shared object that links libstdc++.a exports it.

Two copies in one process: -shared -static-libstdc++ and --exclude-libs

Link two shared objects with -static-libstdc++, and each gets its own copy of every member it uses: __cxa_begin_catch, the personality routine __gxx_personality_v0, and typeinfo for std::runtime_error. That type_info lives in libstdc++ because the class's first virtual function, its destructor (<stdexcept>:246), is defined there (src/c++98/stdexcept.cc:70). Whether a call in one object reaches that object's own copy depends on how the symbols were bound, and there are two cases.

In the default case both objects export the same names. The dynamic loader then decides, when the program runs, which definition each reference reaches. Run time is outside this book. Chapter 4.4 is its one deliberate excursion there, and the <typeinfo> comment in the next section names one loader setting, RTLD_LOCAL, under which it says type names are not merged.

The second case is decided at link time. GNU ld's --exclude-libs option takes a list of archives, or ALL, and for ELF targets "symbols affected by this option will be treated as hidden" (the ld manual, binutils 2.45 ld/ld.texi:538-547). GCC never passes it. A plugin build that adds -Wl,--exclude-libs,ALL binds every reference to libstdc++ inside the plugin to the plugin's own copy, and exports none of it. Two such plugins hold two copies for certain. The rest of this chapter reads what each copy does with an exception that the other copy made.

What a catch compares: type_info::operator==

Chapter 4.3 describes how the personality routine scans a frame's handlers. For each catch clause it calls get_adjusted_ptr, which asks the type of the clause whether it accepts the thrown type (eh_personality.cc:223-243). The thrown type comes from the exception header, which __cxa_throw in the thrower's copy filled in (eh_throw.cc:64). The catch type comes from the catching frame's tables, so it is the catcher's copy. For a class, the test starts with one comparison:

  if (*this == *thr_type)
    return true;

Listing 4.5-5: __class_type_info::__do_catch begins with operator== (libstdc++-v3/libsupc++/class_type_info.cc:37-38).

So the whole question is what operator== does with two type_info objects at different addresses. The Itanium C++ ABI expects them never to exist: "After linking and loading, only one std::type_info structure is accessible via the external name defined by this ABI for any particular complete type symbol", and so "two type_info structures describe the same type if and only if they are the same structure (at the same address)" (Itanium C++ ABI, §2.9.3). Two private copies of libstdc++ break that premise, and libstdc++ does not rely on it. Its header explains:

// Determine whether typeinfo names for the same type are merged (in which
// case comparison can just compare pointers) or not (in which case strings
// must be compared), and whether comparison is to be implemented inline or
// not.  We used to do inline pointer comparison by default if weak symbols
// are available, but even with weak symbols sometimes names are not merged
// when objects are loaded with RTLD_LOCAL, so now we always use strcmp by
// default.  For ABI compatibility, we do the strcmp inline if weak symbols
// are available, and out-of-line if not.  Out-of-line pointer comparison

Listing 4.5-6: why the names are compared as strings (libstdc++-v3/libsupc++/typeinfo:53-60). The default, __GXX_MERGED_TYPEINFO_NAMES 0, follows at :71-74.

The comparison itself:

  type_info::operator==(const type_info& __arg) const _GLIBCXX_NOEXCEPT
  {
    if (std::__is_constant_evaluated())
      return this == &__arg;

    if (__name == __arg.__name)
      return true;

#if !__GXX_TYPEINFO_EQUALITY_INLINE
    // ABI requires comparisons to be non-inline.
    return __equal(__arg);
#elif !__GXX_MERGED_TYPEINFO_NAMES
    // Need to do string comparison.
    return __name[0] != '*' && __builtin_strcmp (__name, __arg.name()) == 0;
#else
    return false;
#endif
  }

Listing 4.5-7: type_info::operator== (libstdc++-v3/libsupc++/typeinfo:197-214).

The same name pointer is a fast match. Otherwise the two mangled names are compared with strcmp, so typeinfo for std::runtime_error from one copy equals the one from the other copy. The Arm EABI moves the comparison out of line (gcc/config/arm/bpabi.h:96-101), and the out-of-line version in tinfo.cc does the same strcmp (tinfo.cc:39-52).

The one exception is a name that starts with *. The C++ front end adds that prefix when the type's name declaration is not public, "so that comparisons will be done by pointer rather than string comparison" (gcc/cp/rtti.cc:385-409, called at :958). Those are types with internal linkage, which no other object can name in a catch anyway.

Before GCC 4.5, two copies of a type_info did not compare equal on ELF targets. At releases/gcc-4.4.0, __GXX_MERGED_TYPEINFO_NAMES was 1 whenever the target had weak symbols (typeinfo:61-69), and the inline operator== compared only the name pointers (:120-121). releases/gcc-4.5.0 made 0 the default (typeinfo:65-68). The folklore that a second libstdc++ breaks catch describes GCC 4.4 and older.

What a second copy splits: __cxa_get_globals

The type test needs no shared state. Other parts of exception handling do. The C++ ABI defines one record per thread, with the stack of exceptions currently caught and the count of exceptions in flight (unwind-cxx.h:155-162). libstdc++ stores it in a thread-local variable:

namespace
{
  abi::__cxa_eh_globals*
  get_global() _GLIBCXX_NOTHROW
  {
    static __thread abi::__cxa_eh_globals global;
    return &global;
  }
} // anonymous namespace

extern "C" __cxa_eh_globals*
__cxxabiv1::__cxa_get_globals_fast() _GLIBCXX_NOTHROW
{ return get_global(); }

extern "C" __cxa_eh_globals*
__cxxabiv1::__cxa_get_globals() _GLIBCXX_NOTHROW
{ return get_global(); }

Listing 4.5-8: one record per thread, and per copy (libstdc++-v3/libsupc++/eh_globals.cc:46-62).

A static variable in a function is one object per copy of the code. Two copies of eh_globals.o give each thread two records. Follow the plugin case through them, with plugin A throwing and rethrowing, and plugin B catching:

  1. A's __cxa_throw adds 1 to A's count of exceptions in flight (eh_throw.cc:83-84).
  2. B's personality routine matches the type, as the previous section showed. B's __cxa_begin_catch pushes the exception onto B's stack and subtracts 1 from B's count (eh_catch.cc:44, :74-80).
  3. A's code runs throw;, which calls A's __cxa_rethrow. A's stack is empty.
extern "C" void
__cxxabiv1::__cxa_rethrow ()
{
  __cxa_eh_globals *globals = __cxa_get_globals ();
  __cxa_exception *header = globals->caughtExceptions;

  globals->uncaughtExceptions += 1;

  // Watch for luser rethrowing with no active exception.
  if (header)
    {
      ...
    }
  std::terminate ();
}

Listing 4.5-9: __cxa_rethrow, abridged (libstdc++-v3/libsupc++/eh_throw.cc:101-137).

  1. std::terminate in A's copy calls A's handler (eh_terminate.cc:56-59). The default is the verbose handler. It asks A's copy for the current exception, which reads A's empty stack (eh_type.cc:36-50), and prints the message for "an attempt to rethrow when there is no suitable exception":
    else
      fputs("terminate called without an active exception\n", stderr);

Listing 4.5-10: the message from the opening of this chapter (libstdc++-v3/libsupc++/vterminate.cc:92-93. The comment that names the rethrow case is at :54-56.)

The same split reaches every function that reads the record. std::current_exception() in A returns an empty exception_ptr while B is handling the exception (eh_ptr.cc:145-151). std::uncaught_exceptions() in A still returns 1 after B's handler has finished, because A added 1 and only B subtracted (eh_catch.cc:147-156).

Freeing the exception survives the split. The thrower stores function pointers in the exception object: the destructor, the terminate handler that was current at the throw, and the cleanup function (eh_throw.cc:65-72). When B finishes its handler, __cxa_end_catch calls _Unwind_DeleteException (eh_catch.cc:121-126), which calls the stored cleanup (libgcc/unwind.inc:281-285). So A's copy frees what A's copy allocated. The terminate handlers stay split: a std::set_terminate call in B sets B's copy only, and A's std::terminate reads A's.

Watching it: two shared objects, one rethrow

Three small files reproduce the opening. Nobody ran these commands for this book at the pin. The results described below are what the source cited above predicts.

// a.cc
#include <stdexcept>
void a_throw () { throw std::runtime_error ("from a"); }
void a_rethrow () { throw; }

// b.cc
#include <cstdio>
#include <stdexcept>
void a_throw ();
void a_rethrow ();
extern "C" void b_run ()
{
  try
    {
      try { a_throw (); }
      catch (const std::runtime_error &)
        {
          std::fputs ("caught in b\n", stderr);
          a_rethrow ();
        }
    }
  catch (const std::runtime_error &e)
    {
      std::fprintf (stderr, "caught again: %s\n", e.what ());
    }
}

/* main.c */
void b_run (void);
int main (void) { b_run (); return 0; }

Listing 4.5-11: a thrower, a catcher, and a C main with no C++ runtime of its own.

First with one copy, the g++ default:

$ g++ -shared -fPIC -o liba.so a.cc
$ g++ -shared -fPIC -o libb.so b.cc -L. -la
$ gcc -o main main.c -L. -lb -la
$ LD_LIBRARY_PATH=. ./main

Listing 4.5-12: the control, with the shared libstdc++.

Both handlers run. The rethrow finds the exception on the one stack, and the outer handler prints caught again: from a. LD_LIBRARY_PATH only lets the loader find the two libraries in the current directory.

Then with two private copies:

$ g++ -shared -fPIC -static-libstdc++ -Wl,--exclude-libs,ALL -o liba.so a.cc
$ g++ -shared -fPIC -static-libstdc++ -Wl,--exclude-libs,ALL -o libb.so b.cc -L. -la
$ LD_LIBRARY_PATH=. ./main
$ nm -D --defined-only libb.so | grep -c __cxa_begin_catch

Listing 4.5-13: the same program, with a hidden libstdc++ in each object.

caught in b still prints, because B's catch matched A's type by name (Listing 4.5-7). Then A's __cxa_rethrow finds A's stack empty, and the process aborts with terminate called without an active exception (Listings 4.5-9 and 4.5-10). If the inner catch had not matched, the message would name the type instead: "terminate called after throwing an instance of" (vterminate.cc:67). So the message tells you which test failed. The nm count is 0 with --exclude-libs and at least 1 without it, which shows the export difference from the previous section.

Two variations are worth a run. Drop -Wl,--exclude-libs,ALL, and the result depends on the dynamic loader, which is outside this book. Add -static-libgcc, and each object also gets a hidden unwinder from libgcc_eh.a. The manual asks for the shared libgcc in every object that throws or catches across libraries, and Chapter 4.2 explains that rule.

Why the defaults are what they are: g++ and --with-boot-ldflags

The g++ default is the shared libstdc++ and the shared libgcc. In that configuration every object in the process uses one libsupc++ and one unwinder, so every piece of state in this chapter exists once, and no object needs a special link option.

-static-libstdc++ fits where no exception and no throw; crosses into another copy: an executable that loads no C++ plugins, or a plugin with a plain C API that catches all its own exceptions. The manual's reason for the option is to "freeze the version of libstdc++ used by the program without going all the way to a fully static link" (invoke.texi:19415-19426).

GCC uses that choice for itself. In stages 2 and 3 of a bootstrap, the default linker flags are -static-libstdc++ -static-libgcc (configure.ac:1947-1962). Stage 1 uses the same pair when the build compiler supports it (:1918-1934). The install manual documents both defaults, under --with-stage1-ldflags and --with-boot-ldflags, on its Configuration page (gcc/doc/install.texi:2516-2532). GCC's own sources are compiled with -fno-exceptions -fno-rtti (gcc/configure.ac:641-644), and its programs are executables, so none of the state in this chapter has a second copy to disagree with. Chapter 2.5 covers the bootstrap itself.

The switch behind both defaults records the opposite case. It is on only when the tree contains gcc/configure (configure.ac:1526-1530), and its comment says why:

# Whether or not to use -static-libstdc++ and -static-libgcc.  The
# default is yes if gcc is being built; no otherwise.  The reason for
# this default is that gdb is sometimes linked against GNU Source
# Highlight, which is a shared library that uses C++ exceptions.  In
# this case, -static-libstdc++ will cause crashes.

Listing 4.5-14: the static runtime, switched off for a program that shares exceptions with a library (configure.ac:1905-1909).

The comment names the symptom and not the mechanism. The option it introduces, --with-static-standard-libraries, has a --help string (configure.ac:1910-1916) and no entry in the install manual.

Bare metal: no libgcc_s, and --disable-libstdcxx-verbose

On a bare-metal target the choice is already made. t-slibgcc is the fragment that sets SHLIB = true (gcc/config/t-slibgcc:1-2), and the driver defines ENABLE_SHARED_LIBGCC only when SHLIB is set and shared libraries are enabled (gcc/Makefile.in:2611). *-*-linux* adds the fragment (config.gcc:888-895). arm*-*-eabi* builds its fragment list from arm/t-arm, arm/t-arm-elf and arm/t-bpabi, without it (config.gcc:1497-1511). So an arm-none-eabi driver keeps the plain -lgcc spec that Chapter 1.3 showed before the rewrite, g++ never adds -shared-libgcc (g++spec.cc:297-301), and -static-libgcc changes nothing. The manual says the same: "If no shared version of libgcc was built when the compiler was configured, these options have no effect" (invoke.texi:19340-19347).

With no dynamic loader, every runtime is an archive, and the linker copies each member into the one image at most once. The second-copy problem cannot happen. The question becomes size: which members the image pulls in, and how much of each it keeps. Two libstdc++ build settings decide most of it.

libstdc++ compiles every source with -ffunction-sections -fdata-sections when the compiler accepts them (acinclude.m4:131-159, used in CONFIG_CXXFLAGS at Makefile.in:413-415). A link with the linker's --gc-sections can then drop unused functions inside a member, and not only whole members.

The default terminate handler is the other setting, and its comment states the cost:

/* We default to the talkative, informative handler in a normal hosted
   library.  This pulls in the demangler, the dyn-string utilities, and
   elements of the I/O library.  For a low-memory environment, you can return
   to the earlier "silent death" handler by configuring GCC with
   --disable-libstdcxx-verbose and rebuilding the library.
   In a freestanding environment, we default to this latter approach.  */

Listing 4.5-15: what the verbose handler costs (libstdc++-v3/libsupc++/eh_term_handler.h:27-32).

The libstdc++ manual documents --disable-libstdcxx-verbose on its Configure page (libstdc++-v3/doc/xml/manual/configure.xml:382-392). The option sets _GLIBCXX_VERBOSE to 0 (acinclude.m4:3425-3438), and the handler becomes std::abort (eh_term_handler.h:34-39). A toolchain configured --with-newlib builds a hosted libstdc++ by default (acinclude.m4:3368-3377), so it gets the verbose handler unless you configure it away. Whether to compile with -fno-exceptions at all is Chapter 4.3's question.

The other runtimes: -static-libasan, -static-libgfortran, -static-libgo

libstdc++ is not the only runtime with a static switch. The other language runtimes and the sanitizers use the same -Bstatic and -Bdynamic wrap, written either in a language driver or in a spec. Two common runtimes have no switch at all:

LibraryPulled in byStatic switchImplemented in
libstdc++g++-static-libstdc++g++spec.cc:235-243
libgfortrangfortran-static-libgfortrangfortranspec.cc:163-178, :255-258
libgogccgo-static-libgogospec.cc:230-233, :370-391
libasan, libtsan, liblsan, libhwasan-fsanitize=-static-libasan and so ongcc.cc:771-841, on GNU/Linux gnu-user.h:129-155
libubsan-fsanitize=undefined-static-libubsangcc.cc:843-852
libgomp-fopenmp, -fopenaccnonegcc.cc:1171-1172
libssp-fstack-protector*, if the C library lacks itnonegcc.cc:994-1003

The manual documents the sanitizer switches next to -static-libgcc under Link Options (invoke.texi:19375-19414). Two rules in the specs are not in that text. On GNU/Linux, -static-libasan links the runtime with --whole-archive into an executable, and links no libasan at all into a shared object. The comment explains: "the executable should be compiled with -static-libasan in that case" (gnu-user.h:129-133). That is this chapter's rule written into a spec: a runtime with global state gets one copy, in the executable. And -static with -fsanitize=address is not a static ASan link. It is an error, "cannot specify -static with -fsanitize=address" (gcc.cc:1114-1119).

Three things to carry away

A static runtime is a private copy of its code and its state. libstdc++'s archive is built to go into shared objects, and its symbols are exported unless you hide them.

A catch matches across copies, because libstdc++ compares type names. Pointer comparison was the default on targets with weak symbols only up to GCC 4.4.

throw;, std::current_exception and std::uncaught_exceptions see only their own copy. The per-thread exception record is a static variable in eh_globals.cc.

Things that surprise people

-static-libstdc++ does not make libgcc static. g++ still adds -shared-libgcc, so the process keeps one unwinder.

A plugin built with -static-libstdc++ exports the libstdc++ functions it copied. libgcc's archive is hidden, and libstdc++'s is not. Add -Wl,--exclude-libs,ALL to hide them.

-static-libgcc does nothing on arm-none-eabi. No shared libgcc exists there, and the driver never rewrites the libgcc spec.

gcc -static -fsanitize=address is an error, and -shared -static-libasan links no ASan runtime into the shared object.

Documentation coverage

The GCC manual's Link Options node (gcc/doc/invoke.texi:19067) documents -static-pie (:19285), -static (:19319), -shared-libgcc and -static-libgcc with the exception rationale (:19340), the sanitizer switches (:19375-19414) and -static-libstdc++ (:19415). The install manual's Configuration page documents the static defaults of --with-stage1-ldflags and --with-boot-ldflags (gcc/doc/install.texi:2516 and :2528). The libstdc++ manual's Configure page documents --disable-libstdcxx-verbose (libstdc++-v3/doc/xml/manual/configure.xml:382). The Itanium C++ ABI specifies type_info equality as address equality (§2.9.3).

What is not documented:

  • What happens when two shared objects each link libstdc++.a. No manual covers it. The options are documented one by one, and the interaction is not.
  • That catch still matches across copies, because libstdc++ compares type_info names with strcmp. Only the <typeinfo> comment says so, and the Itanium ABI describes address comparison.
  • That throw;, std::current_exception() and std::uncaught_exceptions() read per-copy state, and that a rethrow in the wrong copy terminates with "without an active exception".
  • That libstdc++.a is position-independent on purpose, without compatibility symbols or symbol versions. Only Makefile.am comments say so.
  • That libgcc.a is compiled with hidden visibility and libstdc++.a is not, so only libstdc++ is re-exported by a shared object.
  • That -static on GNU/Linux drops --eh-frame-hdr, and that crtbeginT.o registers the unwind tables itself.
  • That -static-libasan links nothing into a -shared link on GNU/Linux.
  • --with-static-standard-libraries, which exists only as a configure --help string.

Next: Part V goes inside cc1, and starts with the three representations every function passes through, and why GCC needs all three.


All source references in this chapter are to GCC 15.2.0 (releases/gcc-15.2.0). Line numbers in other releases will differ; the surrounding code rarely does. Where behaviour itself changed across a major version, it is flagged inline.