This is an old revision of the document!


The New C++11 Stack

FreeBSD 10 aims to ship with a new C++ stack, replacing the old GNU one. Hopefully a preview of this will appear somewhere along the 9.x series.

Why do we need a new C++ stack? There are two main reasons: functionality and licensing. FreeBSD 9.0 includes the last GPLv2 (+ linking exemption) release of GNU libstdc++. GPLv2 isn't ideal for FreeBSD and GPLv3 (the license of the newer versions) is considered unacceptable, so a replacement is desirable.

This year, a new version of the C++ standard was introduced. C++11 is not supported at all by the 2007 version of libstdc++ that we currently ship, yet is going to be important moving forward.

A C++ implementation requires several components. The major ones are:

  • The compiler.
  • The Standard Template Library (STL) implementation.
  • The ABI library.

The STL implementation sits on top of the ABI library, which provides things like guards for initialising static variables, exceptions, and so on. The new stack uses the following components:

These components have all been imported into the base system in -CURRENT.

Because libc++ uses a number of C++11 features, it needs to be built with a compiler that supports C++11. Currently, the base system defaults to building with gcc. You need to follow the instructions for building with clang to switch to a more modern compiler. You also need to add this line to /etc/make.conf:

WITH_LIBCPLUSPLUS=yes

To use the new stack, you will need to use clang++ as your C++ compiler and linker-driver. Add -stdlib=libc++ to your compile and link flags and, in theory, it will Just Work™. In practice, please report any problems that you encounter to theraven@.

This new stack contains all of the parts of the system that are specific to C++. The ABI library implements the C++ parts of the unwinder, but not the generic parts. These are currently provided by libgcc_s. This can be replaced by libunwind, but that is not done. It probably requires some ARM-specific functions to be implemented on top of libunwind too.

Currently, libstdc++ statically links against libsupc++, which implements the same specification as libcxxrt. This means that code that links the two is going to end up with two definitions of these symbols and stuff is likely to break. Unfortunately, the symbols in libsupc++ are not versioned. To be able to mix code between the two, we need to make libstdc++ link against libcxxrt instead of libsupc++. In theory, this is trivial, but there may be unforeseen complications.

Finally, the libstdc++ shipped with FreeBSD 9 and earlier, modified to use libcxxrt, needs moving into a port so that it can be installed for ABI compatibility.

  • newc_stack.1322398531.txt.gz
  • Last modified: 2011/11/27 12:55
  • by theraven