Category Archives: libcxxrt

The New C++ Stack in 9.1

If you read the release announcement, then you’ll have seen that there is a new C++ stack in 9.1, but that it is marked optional and is not part of the default binary install. If you’re a C++ developer, you may want to play with it for a few reasons:

  • It supports C++11 (which is new, shiny, and buzzwordy)
  • It will be the only one shipped by default in 10.0, so if you care about forward compatibility then you will need to test with it or make sure that your code works with it, or depend on GNU libstdc++ from ports.

The new stack uses libcxxrt, which I originally wrote for PathScale and was since open sourced (funded by the FreeBSD and NetBSD Foundations).  This implements the low-level part of the C++ standard library, providing things like support for RTTI, dynamic_cast, exceptions, thread-safe initialisation of statics, and so on. In the old stack, libsupc++ does this.

On top of this sits the STL implementation. In the old stack, this was GNU libstdc++, in the new one it’s LLVM’s libc++. To make interoperability easier, in 9.1 we have made libstdc++ dynamically link against libsupc++. You can use libmap.conf(5) to tell it to link against libcxxrt instead, and then you can mix libraries that use libc++ with ones that use libstdc++ in the same program.

The new stack isn’t installed by default, but building and installing it is very easy:

# cd /usr/src/lib/libcxxrt
# make
# make install
# cd ../libc++
# make CXX=clang++
# make install

You should now have libc++.so installed in /usr/lib and the headers installed in /usr/include/c++/v1. You are now ready to compile C++ code with the new stack. You use them, clang has a command-line switch for selecting the stack to use. By default, it will still use the old stack:

$ clang++ hello.cc 
$ ./a.out 
Hello C++ World
$ ldd ./a.out 
./a.out:
    libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x800819000)
    libm.so.5 => /lib/libm.so.5 (0x800b29000)
    libc.so.7 => /lib/libc.so.7 (0x800d4a000)
    libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x80109d000)

To enable the new stack, you must add -stdlib=libc++ to your CXXFLAGS and also to your LDFLAGS. The first ensures that we get the libc++ headers, the second that we link to libc++:

$ clang++ -stdlib=libc++ -std=c++11 hello.cc 
$ ./a.out 
Hello C++ World
$ ldd ./a.out 
./a.out:
    libc++.so.1 => /usr/lib/libc++.so.1 (0x80081a000)
    libm.so.5 => /lib/libm.so.5 (0x800ac9000)
    libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x800cea000)
    libc.so.7 => /lib/libc.so.7 (0x800ef7000)
    libcxxrt.so.1 => /lib/libcxxrt.so.1 (0x80124a000)

Unfortunately, in 9.1 there is a small bug that prevents you from compiling in C++98 mode with libc++. The C11 quick_exit() and at_quick_exit() functions are exposed in our stdlib.h only in C11 and C++11 modes, but are referenced in libc++’s cstdlib in any mode.

Most code should work out-of-the-box in C++11 mode though, so there’s little reason not to try it. And, because of the availability of move semantics, some code using STL classes will be more efficient when compiled in C++11 mode.

If you want to test with a newer version, but don’t want to install -CURRENT, I’m putting x86-64 binaries of libc++ back-ported to 9.1 online for testing. I’ll update this whenever I pull a new version into -CURRENT.

libcxxrt C++ Runtime Now Available Under BSD License

The FreeBSD Foundation and the NetBSD Foundation announced today that they have acquired a non-exclusive copyright license to the libcxxrt C++ runtime software from PathScale, a leader in high performance Fortran, C and C++ compiler products for AMD64, Intel64 and MIPS. The press release, available from the FreeBSD Foundation, Pathscale, and PRWeb websites, is as follows:

The FreeBSD Foundation and the NetBSD Foundation announced today that they have acquired a non-exclusive copyright license to the libcxxrt C++ runtime software from PathScale, a leader in high performance Fortran, C, and C++ compiler products for AMD64, Intel64, and MIPS. This software is an implementation of the C++ Application Binary Interface originally developed for Itanium and now used for the x86 family by BSD operating systems. Libcxxrt will be available under the 2-clause BSD license.

This implementation is a full replacement for the GNU libsupc++ library for platforms that use the Itanium C++ ABI, including i386 and x86-64, and will replace portions of the C++ stack previously only available under the GPL. It provides implementations of the dynamic features of C++, including dynamic casting, exception handling, and thread-safe static initializers, and will continue the gradual replacement of GNU toolchain and runtime components, furthering the aim of a purely BSD-licensed system.

"This work complements other work done in the community and is a further step in letting us adopt alternative toolchains in FreeBSD," said Robert Watson, a FreeBSD committer and Director at the FreeBSD Foundation.

"There are already a number of STL implementations with other licenses, but libcxxrt is the missing link for a BSD licensed C++ compiler and the C++ runtime," said NetBSD developer Joerg Sonnenberger.

"It's great to work with the BSD community and help provide these core parts of the toolchain," said Christopher Bergström, CTO at PathScale. "This is a first step to PathScale offering first class support for both NetBSD and FreeBSD."

About The FreeBSD Foundation

The FreeBSD Foundation is a 501(c)(3) non-profit organization dedicated to supporting the FreeBSD Project and community. The Foundation gratefully accepts donations from individuals and businesses, using them to fund and manage projects, sponsor FreeBSD events, Developer Summits and provide travel grants to FreeBSD developers. In addition, the Foundation represents the FreeBSD Project in executing contracts, license agreements, and other legal arrangements that require a recognized legal entity. The FreeBSD Foundation is entirely supported by donations. More information about The FreeBSD Foundation is available on the web.

About The NetBSD Foundation

The NetBSD Foundation is a 501(c)(3) non-profit organization dedicated to supporting the NetBSD Project and community. Under its education and research mandate, it supports development of the NetBSD operating system which supports over fifty different computer architectures from a single, unified set of kernel and userland source files. The NetBSD codebase is used by commercial embedded developers, educational institutions, and individual end-users. Through donations received from individuals and corporations the Foundation is able to fund substantial work undertaken by developers. More information about The NetBSD Foundation is available on the web.

About PathScale

PathScale Inc. has developed industry leading high performance Fortran, C and C++ compiler products for AMD64, Intel® 64, MIPS processors and provides support to users desiring the highest level of performance from their applications. The PathScale EKOPath Compiler Suite has the world's most advanced optimization infrastructure and can fully exploit the potentials of many-core architectures. The company’s goal is to deliver robust and high performance compilers tailored to clustered, GPGPU and multi-core computing environments. More information about PathScale is available on the web.

libcxxrt C++ Runtime Now Available Under BSD License

The FreeBSD Foundation and the NetBSD Foundation announced today that they have acquired a non-exclusive copyright license to the libcxxrt C++ runtime software from PathScale, a leader in high performance Fortran, C and C++ compiler products for AMD64, Intel64 and MIPS. The press release, available from the FreeBSD Foundation, Pathscale, and PRWeb websites, is as follows:

The FreeBSD Foundation and the NetBSD Foundation announced today that they have acquired a non-exclusive copyright license to the libcxxrt C++ runtime software from PathScale, a leader in high performance Fortran, C, and C++ compiler products for AMD64, Intel64, and MIPS. This software is an implementation of the C++ Application Binary Interface originally developed for Itanium and now used for the x86 family by BSD operating systems. Libcxxrt will be available under the 2-clause BSD license.

This implementation is a full replacement for the GNU libsupc++ library for platforms that use the Itanium C++ ABI, including i386 and x86-64, and will replace portions of the C++ stack previously only available under the GPL. It provides implementations of the dynamic features of C++, including dynamic casting, exception handling, and thread-safe static initializers, and will continue the gradual replacement of GNU toolchain and runtime components, furthering the aim of a purely BSD-licensed system.

"This work complements other work done in the community and is a further step in letting us adopt alternative toolchains in FreeBSD," said Robert Watson, a FreeBSD committer and Director at the FreeBSD Foundation.

"There are already a number of STL implementations with other licenses, but libcxxrt is the missing link for a BSD licensed C++ compiler and the C++ runtime," said NetBSD developer Joerg Sonnenberger.

"It's great to work with the BSD community and help provide these core parts of the toolchain," said Christopher Bergström, CTO at PathScale. "This is a first step to PathScale offering first class support for both NetBSD and FreeBSD."

About The FreeBSD Foundation

The FreeBSD Foundation is a 501(c)(3) non-profit organization dedicated to supporting the FreeBSD Project and community. The Foundation gratefully accepts donations from individuals and businesses, using them to fund and manage projects, sponsor FreeBSD events, Developer Summits and provide travel grants to FreeBSD developers. In addition, the Foundation represents the FreeBSD Project in executing contracts, license agreements, and other legal arrangements that require a recognized legal entity. The FreeBSD Foundation is entirely supported by donations. More information about The FreeBSD Foundation is available on the web.

About The NetBSD Foundation

The NetBSD Foundation is a 501(c)(3) non-profit organization dedicated to supporting the NetBSD Project and community. Under its education and research mandate, it supports development of the NetBSD operating system which supports over fifty different computer architectures from a single, unified set of kernel and userland source files. The NetBSD codebase is used by commercial embedded developers, educational institutions, and individual end-users. Through donations received from individuals and corporations the Foundation is able to fund substantial work undertaken by developers. More information about The NetBSD Foundation is available on the web.

About PathScale

PathScale Inc. has developed industry leading high performance Fortran, C and C++ compiler products for AMD64, Intel® 64, MIPS processors and provides support to users desiring the highest level of performance from their applications. The PathScale EKOPath Compiler Suite has the world's most advanced optimization infrastructure and can fully exploit the potentials of many-core architectures. The company’s goal is to deliver robust and high performance compilers tailored to clustered, GPGPU and multi-core computing environments. More information about PathScale is available on the web.