1 # Copyright 1999-2020 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
6 PYTHON_COMPAT=( python{2_7,3_{6,7}} )
7 inherit check-reqs cmake-utils flag-o-matic llvm llvm.org \
8 multiprocessing python-any-r1
10 DESCRIPTION="Compiler runtime libraries for clang (sanitizers & xray)"
11 HOMEPAGE="https://llvm.org/"
12 LLVM_COMPONENTS=( compiler-rt )
13 LLVM_TEST_COMPONENTS=( llvm/lib/Testing/Support llvm/utils/unittest )
16 LICENSE="Apache-2.0-with-LLVM-exceptions || ( UoI-NCSA MIT )"
19 IUSE="+clang +libfuzzer +profile +sanitize test +xray elibc_glibc"
20 # FIXME: libfuzzer does not enable all its necessary dependencies
21 REQUIRED_USE="libfuzzer? ( || ( sanitize xray ) )"
22 RESTRICT="!test? ( test ) !clang? ( test )"
24 CLANG_SLOT=${SLOT%%.*}
25 # llvm-6 for new lit options
29 clang? ( sys-devel/clang )
30 elibc_glibc? ( net-libs/libtirpc )
32 !<sys-apps/sandbox-2.13
33 $(python_gen_any_dep ">=dev-python/lit-5[\${PYTHON_USEDEP}]")
34 =sys-devel/clang-${PV%_*}*:${CLANG_SLOT}
35 sys-libs/compiler-rt:${SLOT} )
38 # least intrusive of all
39 CMAKE_BUILD_TYPE=RelWithDebInfo
43 local CHECKREQS_DISK_BUILD=11G
44 check-reqs_pkg_pretend
55 python-any-r1_pkg_setup
59 cmake-utils_src_prepare
62 # remove tests that are (still) broken by new glibc
63 # https://bugs.llvm.org/show_bug.cgi?id=36065
64 if use elibc_glibc && has_version '>=sys-libs/glibc-2.25'; then
65 rm test/lsan/TestCases/Linux/fork_and_leak.cpp || die
71 # pre-set since we need to pass it to cmake
72 BUILD_DIR=${WORKDIR}/compiler-rt_build
75 local -x CC=${CHOST}-clang
76 local -x CXX=${CHOST}-clang++
77 strip-unsupported-flags
81 -DCOMPILER_RT_INSTALL_PATH="${EPREFIX}/usr/lib/clang/${SLOT}"
82 # use a build dir structure consistent with install
83 # this makes it possible to easily deploy test-friendly clang
84 -DCOMPILER_RT_OUTPUT_DIR="${BUILD_DIR}/lib/clang/${SLOT}"
86 -DCOMPILER_RT_INCLUDE_TESTS=$(usex test)
87 # builtins & crt installed by sys-libs/compiler-rt
88 -DCOMPILER_RT_BUILD_BUILTINS=OFF
89 -DCOMPILER_RT_BUILD_CRT=OFF
90 -DCOMPILER_RT_BUILD_LIBFUZZER=$(usex libfuzzer)
91 -DCOMPILER_RT_BUILD_PROFILE=$(usex profile)
92 -DCOMPILER_RT_BUILD_SANITIZERS=$(usex sanitize)
93 -DCOMPILER_RT_BUILD_XRAY=$(usex xray)
97 -DLLVM_MAIN_SRC_DIR="${WORKDIR}/llvm"
98 -DLLVM_EXTERNAL_LIT="${EPREFIX}/usr/bin/lit"
99 -DLLVM_LIT_ARGS="-vv;-j;${LIT_JOBS:-$(makeopts_jobs "${MAKEOPTS}" "$(get_nproc)")}"
101 # they are created during src_test()
102 -DCOMPILER_RT_TEST_COMPILER="${BUILD_DIR}/lib/llvm/${CLANG_SLOT}/bin/clang"
103 -DCOMPILER_RT_TEST_CXX_COMPILER="${BUILD_DIR}/lib/llvm/${CLANG_SLOT}/bin/clang++"
106 # same flags are passed for build & tests, so we need to strip
107 # them down to a subset supported by clang
108 CC=${EPREFIX}/usr/lib/llvm/${CLANG_SLOT}/bin/clang \
109 CXX=${EPREFIX}/usr/lib/llvm/${CLANG_SLOT}/bin/clang++ \
110 strip-unsupported-flags
113 if use prefix && [[ "${CHOST}" == *-darwin* ]] ; then
115 # disable use of SDK for the system itself
116 -DDARWIN_macosx_CACHED_SYSROOT=/
120 cmake-utils_src_configure
123 local sys_dir=( "${EPREFIX}"/usr/lib/clang/${SLOT}/lib/* )
124 [[ -e ${sys_dir} ]] || die "Unable to find ${sys_dir}"
125 [[ ${#sys_dir[@]} -eq 1 ]] || die "Non-deterministic compiler-rt install: ${sys_dir[*]}"
127 # copy clang over since resource_dir is located relatively to binary
128 # therefore, we can put our new libraries in it
129 mkdir -p "${BUILD_DIR}"/lib/{llvm/${CLANG_SLOT}/{bin,$(get_libdir)},clang/${SLOT}/include} || die
130 cp "${EPREFIX}"/usr/lib/llvm/${CLANG_SLOT}/bin/clang{,++} \
131 "${BUILD_DIR}"/lib/llvm/${CLANG_SLOT}/bin/ || die
132 cp "${EPREFIX}"/usr/lib/clang/${SLOT}/include/*.h \
133 "${BUILD_DIR}"/lib/clang/${SLOT}/include/ || die
134 cp "${sys_dir}"/*builtins*.a \
135 "${BUILD_DIR}/lib/clang/${SLOT}/lib/${sys_dir##*/}/" || die
136 # we also need LLVMgold.so for gold-based tests
137 if [[ -f ${EPREFIX}/usr/lib/llvm/${CLANG_SLOT}/$(get_libdir)/LLVMgold.so ]]; then
138 ln -s "${EPREFIX}"/usr/lib/llvm/${CLANG_SLOT}/$(get_libdir)/LLVMgold.so \
139 "${BUILD_DIR}"/lib/llvm/${CLANG_SLOT}/$(get_libdir)/ || die
146 local -x LIT_PRESERVES_TMP=1
147 # disable sandbox to have it stop clobbering LD_PRELOAD
148 local -x SANDBOX_ON=0
149 # wipe LD_PRELOAD to make ASAN happy
152 cmake-utils_src_make check-all