commit:     f9dd98ec5f9aaf196319a0527d0312d18f2430a2
Author:     Michał Górny <mgorny <AT> gentoo <DOT> org>
AuthorDate: Thu Oct  6 16:27:40 2016 +0000
Commit:     Michał Górny <mgorny <AT> gentoo <DOT> org>
CommitDate: Fri Oct  7 08:41:24 2016 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=f9dd98ec

sys-libs/libcxx: Always pass compiler runtime libs

 sys-libs/libcxx/libcxx-3.9.0.ebuild | 27 +++++++++++++++++++++++++--
 sys-libs/libcxx/libcxx-9999.ebuild  | 27 +++++++++++++++++++++++++--
 2 files changed, 50 insertions(+), 4 deletions(-)

diff --git a/sys-libs/libcxx/libcxx-3.9.0.ebuild 
b/sys-libs/libcxx/libcxx-3.9.0.ebuild
index a92f0f8..7f16bd2 100644
--- a/sys-libs/libcxx/libcxx-3.9.0.ebuild
+++ b/sys-libs/libcxx/libcxx-3.9.0.ebuild
@@ -102,6 +102,28 @@ multilib_src_configure() {
                cxxabi_incs="${gcc_inc};${gcc_inc}/${CHOST}"
        fi
 
+       # we want -lgcc_s for unwinder, and for compiler runtime when using
+       # gcc, clang with gcc runtime (or any unknown compiler)
+       local extra_libs=() want_gcc_s=ON
+       if use libunwind; then
+               # work-around missing -lunwind upstream
+               extra_libs+=( -lunwind )
+               # if we're using libunwind and clang with compiler-rt, we want
+               # to link to compiler-rt instead of -lgcc_s
+               if tc-is-clang; then
+                       # get the full library list out of 'pretend mode'
+                       # and grep it for libclang_rt references
+                       local args=( $($(tc-getCC) -### -x c - 2>&1 | tail -n 
1) )
+                       local i
+                       for i in "${args[@]}"; do
+                               if [[ ${i} == *libclang_rt* ]]; then
+                                       want_gcc_s=OFF
+                                       extra_libs+=( "${i}" )
+                               fi
+                       done
+               fi
+       fi
+
        local libdir=$(get_libdir)
        local mycmakeargs=(
                # LLVM_LIBDIR_SUFFIX is used to find CMake files
@@ -115,10 +137,11 @@ multilib_src_configure() {
                # we're using our own mechanism for generating linker scripts
                -DLIBCXX_ENABLE_ABI_LINKER_SCRIPT=OFF
                -DLIBCXX_HAS_MUSL_LIBC=$(usex elibc_musl)
-               -DLIBCXX_HAS_GCC_S_LIB=$(usex !libunwind)
+               -DLIBCXX_HAS_GCC_S_LIB=${want_gcc_s}
                -DLIBCXX_INCLUDE_TESTS=$(usex test)
-               -DCMAKE_SHARED_LINKER_FLAGS=$(usex libunwind "-lunwind" "")
+               -DCMAKE_SHARED_LINKER_FLAGS="${extra_libs[*]} ${LDFLAGS}"
        )
+
        if use test; then
                mycmakeargs+=(
                        # this can be any directory, it just needs to exist...

diff --git a/sys-libs/libcxx/libcxx-9999.ebuild 
b/sys-libs/libcxx/libcxx-9999.ebuild
index bbc218b..3beacf0 100644
--- a/sys-libs/libcxx/libcxx-9999.ebuild
+++ b/sys-libs/libcxx/libcxx-9999.ebuild
@@ -98,6 +98,28 @@ multilib_src_configure() {
                cxxabi_incs="${gcc_inc};${gcc_inc}/${CHOST}"
        fi
 
+       # we want -lgcc_s for unwinder, and for compiler runtime when using
+       # gcc, clang with gcc runtime (or any unknown compiler)
+       local extra_libs=() want_gcc_s=ON
+       if use libunwind; then
+               # work-around missing -lunwind upstream
+               extra_libs+=( -lunwind )
+               # if we're using libunwind and clang with compiler-rt, we want
+               # to link to compiler-rt instead of -lgcc_s
+               if tc-is-clang; then
+                       # get the full library list out of 'pretend mode'
+                       # and grep it for libclang_rt references
+                       local args=( $($(tc-getCC) -### -x c - 2>&1 | tail -n 
1) )
+                       local i
+                       for i in "${args[@]}"; do
+                               if [[ ${i} == *libclang_rt* ]]; then
+                                       want_gcc_s=OFF
+                                       extra_libs+=( "${i}" )
+                               fi
+                       done
+               fi
+       fi
+
        local libdir=$(get_libdir)
        local mycmakeargs=(
                # LLVM_LIBDIR_SUFFIX is used to find CMake files
@@ -111,10 +133,11 @@ multilib_src_configure() {
                # we're using our own mechanism for generating linker scripts
                -DLIBCXX_ENABLE_ABI_LINKER_SCRIPT=OFF
                -DLIBCXX_HAS_MUSL_LIBC=$(usex elibc_musl)
-               -DLIBCXX_HAS_GCC_S_LIB=$(usex !libunwind)
+               -DLIBCXX_HAS_GCC_S_LIB=${want_gcc_s}
                -DLIBCXX_INCLUDE_TESTS=$(usex test)
-               -DCMAKE_SHARED_LINKER_FLAGS=$(usex libunwind "-lunwind" "")
+               -DCMAKE_SHARED_LINKER_FLAGS="${extra_libs[*]} ${LDFLAGS}"
        )
+
        if use test; then
                mycmakeargs+=(
                        # this can be any directory, it just needs to exist...

Reply via email to