[cfe-dev] [RFC][libcxx] Fixing "-stdlib=libc++ -lc++abi" on Linux -- Exporting libc++abi through libc++.so.

Eric Fiselier via cfe-dev cfe-dev at lists.llvm.org
Sun Oct 11 16:58:55 PDT 2015


Hi All,

As many of you know libc++ doesn't build correctly on Linux by
default. In particular the resulting library cannot be used with
"-stdlib=libc++" alone. This forces the user to manually link the
correct ABI library, usually by adding '-lc++abi' whenever they link a
program or library.

We need to fix the default libc++ build configuration so that
libc++.so just works. This fix cannot be done in clang. libc++
supports using 3+ different ABI libraries and even more ways to link
them. It's not feasible for clang to know how libc++ was built and
trying to teach it would limit the flexibility libc++ already has.

I would like to propose a solution to fix the default build
configuration. For simplicity I will explain it using libc++abi as the
example but any supported library will work.

Solution: Libc++ should use a linker script for libc++.so as opposed
to a symlink.
(See http://reviews.llvm.org/D12508)

The linker script would contain "INPUT(libc++.1.so -lc++abi)". This
instructs the linker to include libc++.1.so as if it were this file
and add '-lc++abi' to the link command. Currently libc++.so is a
symlink to libc++.so.1.

The most important part of this approach is that it allows us to use a
shared libc++abi.
We want to avoid using a static library because libc++abi contains
symbols which have to be unique within a process. These symbols
include exception handling globals, RTTI support, and definitions for
standard library exceptions. By keeping these symbols out of libc++ we
can allow different libc++ versions and even different standard
library implementations to coexist peacefully in the same process as
long as they share the same libc++abi.

This approach is how FreeBSD ships their systems libc++. OS X take a
slightly different approach which uses also uses a shared ABI library.
It works by re-exporting libc++abi's symbols into libc++.dylib at
build time using the "-reexported_symbols_list" linker flag.

Questions:

1. What Linux linkers, if any, don't support linker scripts? Does lld?
2. Would installing libc++.so as a linker script cause problems with ldconfig?
3. Does LD provide any way to reexport symbols lists comparable to how
"-reexported_symbols_list" on OS X?


I would love any and all input on this plan. Please correct me if I've
gotten any details wrong.
If nobody objects I would like to quickly move forward with this.

/Eric



More information about the cfe-dev mailing list