[PATCH] D96070: [clang] [driver] Enable static linking to libc++

Timm Bäder via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Feb 5 00:22:57 PST 2021


tbaeder added a comment.

In D96070#2543172 <https://reviews.llvm.org/D96070#2543172>, @mstorsjo wrote:

> In particular, if libcxx is built with `LIBCXX_ENABLE_STATIC_ABI_LIBRARY` enabled, the libcxxabi static library is merged into libc++.a, making static linking work just fine.

I can't test this right now, but it is manually specifying pthread not needed in that case?

In D96070#2543334 <https://reviews.llvm.org/D96070#2543334>, @MaskRay wrote:

> Persoanlly (https://maskray.me/blog/2020-12-12-c++-exception-handling-abi#use-libc-and-libcabi) I use:
>
> `clang++ -stdlib=libc++ -static-libstdc++ -nostdlib++ a.cc -Wl,--push-state,-Bstatic -lc++ -lc++abi -Wl,--pop-state -pthread`
>
> This is still a bit inferior because there is a duplicate -lc++ passed by the driver.
>
> Dynamically link against libc++.so (which depends on libc++abi.so) (additionally specify -pthread if threads are used):
> `clang++ -stdlib=libc++ -nostdlib++ a.cc -lc++ -lc++abi` (clang -stdlib=libc++ a.cc -lc++ -lc++abi does not pass -lm to the linker.)
> Omitting `-lc++abi` most works, but can fail if your program reference some definitions in `<exception> <stdexcept>` directly and you are using gold or LLD.

Are you suggesting clang should do the same?

Or should clang just not do anything here and people should be aware they need to pass additional flags when using libc++ (on Linux)?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D96070/new/

https://reviews.llvm.org/D96070



More information about the cfe-commits mailing list