From 2afc0229b5a4414c455511d02f9fc9ce0bb08a93 Mon Sep 17 00:00:00 2001 From: Khem Raj Date: Sat, 1 Aug 2020 22:58:41 -0700 Subject: libcxx: Fix linking based upon chosen compiler runtime libcxx can use either libgcc_s or llvm libunwind for unwinder functionality, the defaults are platform dependent, therefore with this patch we make intentional choice based on RUNTIME settings chosen, e.g. when using GNU runtime we use libgcc and also ensure that it add right compiler options to build as well, since libcxx build looks C runtime by calling $($CC --print-libgcc-file-name) to build libc++abi.so unless we use right -rtlib option it will result in linking wrong library Enable RTTI as well do not enable llvm unwinder unless we chose llvm runtime, even that might not work since libpthread from glibc explicitly dlopens libgcc_s.so to enable unwinding https://github.com/bminor/glibc/blob/5f72f9800b250410cad3abfeeb09469ef12b2438/sysdeps/nptl/unwind-forcedunwind.c#L53...L58 Fixes Issue #332 Signed-off-by: Khem Raj --- recipes-devtools/clang/libcxx_git.bb | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/recipes-devtools/clang/libcxx_git.bb b/recipes-devtools/clang/libcxx_git.bb index 5bc864c..789da5b 100644 --- a/recipes-devtools/clang/libcxx_git.bb +++ b/recipes-devtools/clang/libcxx_git.bb @@ -10,7 +10,7 @@ require common-source.inc inherit cmake python3native -PACKAGECONFIG ??= "compiler-rt unwind exceptions" +PACKAGECONFIG ??= "compiler-rt exceptions ${@bb.utils.contains("RUNTIME", "llvm", "unwind", "", d)}" PACKAGECONFIG_riscv32 = "exceptions" PACKAGECONFIG_riscv64 = "exceptions" PACKAGECONFIG_append_armv5 = " no-atomics" @@ -18,12 +18,14 @@ PACKAGECONFIG_append_armv5 = " no-atomics" PACKAGECONFIG[unwind] = "-DLIBCXXABI_USE_LLVM_UNWINDER=ON -DLIBCXXABI_ENABLE_STATIC_UNWINDER=ON -DLIBCXXABI_STATICALLY_LINK_UNWINDER_IN_SHARED_LIBRARY=ON -DLIBCXXABI_STATICALLY_LINK_UNWINDER_IN_STATIC_LIBRARY=ON,-DLIBCXXABI_USE_LLVM_UNWINDER=OFF,," PACKAGECONFIG[exceptions] = "-DLIBCXXABI_ENABLE_EXCEPTIONS=ON -DDLIBCXX_ENABLE_EXCEPTIONS=ON,-DLIBCXXABI_ENABLE_EXCEPTIONS=OFF -DLIBCXX_ENABLE_EXCEPTIONS=OFF -DCMAKE_REQUIRED_FLAGS='-fno-exceptions'," PACKAGECONFIG[no-atomics] = "-D_LIBCXXABI_HAS_ATOMIC_BUILTINS=OFF -DCMAKE_SHARED_LINKER_FLAGS='-latomic',," -PACKAGECONFIG[compiler-rt] = "-DLIBCXXABI_USE_COMPILER_RT=ON -DLIBCXX_USE_COMPILER_RT=ON,-DLIBCXXABI_USE_COMPILER_RT=OFF -DLIBCXX_USE_COMPILER_RT=OFF,compiler-rt" +PACKAGECONFIG[compiler-rt] = ",,compiler-rt" DEPENDS += "ninja-native" -DEPENDS_append_class-target = " compiler-rt clang-cross-${TARGET_ARCH} virtual/${MLPREFIX}libc virtual/${TARGET_PREFIX}compilerlibs" +DEPENDS_append_class-target = " clang-cross-${TARGET_ARCH} virtual/${MLPREFIX}libc virtual/${TARGET_PREFIX}compilerlibs" LIBCPLUSPLUS = "" +COMPILER_RT ?= "-rtlib=compiler-rt ${UNWINDLIB}" +UNWINDLIB ?= "${@bb.utils.contains("RUNTIME", "gnu", "--unwindlib=libgcc", "", d)}" INHIBIT_DEFAULT_DEPS = "1" @@ -40,16 +42,15 @@ OECMAKE_SOURCEPATH = "${S}/llvm" EXTRA_OECMAKE += "\ -DCMAKE_CROSSCOMPILING=ON \ -DLLVM_TEMPORARILY_ALLOW_OLD_TOOLCHAIN=ON \ + -DLLVM_ENABLE_RTTI=ON \ -DLIBUNWIND_ENABLE_SHARED=OFF \ -DLIBUNWIND_ENABLE_THREADS=OFF \ -DLIBUNWIND_WEAK_PTHREAD_LIB=ON \ -DLIBUNWIND_ENABLE_CROSS_UNWINDING=ON \ -DLIBCXXABI_INCLUDE_TESTS=OFF \ -DLIBCXXABI_ENABLE_SHARED=ON \ - -DLIBCXXABI_USE_COMPILER_RT=ON \ -DLIBCXXABI_LIBCXX_INCLUDES=${S}/libcxx/include \ -DLIBCXX_CXX_ABI=libcxxabi \ - -DLIBCXX_USE_COMPILER_RT=ON \ -DLIBCXX_CXX_ABI_INCLUDE_PATHS=${S}/libcxxabi/include \ -DLIBCXX_CXX_ABI_LIBRARY_PATH=${B}/lib${LLVM_LIBDIR_SUFFIX} \ -DCMAKE_AR=${STAGING_BINDIR_TOOLCHAIN}/${AR} \ -- cgit v1.2.3-54-g00ecf