compiler-rt-sanitizers-8.0.1.ebuild (5349B)
1 # Copyright 1999-2020 Gentoo Authors 2 # Distributed under the terms of the GNU General Public License v2 3 4 EAPI=6 5 6 : ${CMAKE_MAKEFILE_GENERATOR:=ninja} 7 # (needed due to CMAKE_BUILD_TYPE != Gentoo) 8 CMAKE_MIN_VERSION=3.7.0-r1 9 PYTHON_COMPAT=( python2_7 ) 10 11 inherit check-reqs cmake-utils flag-o-matic llvm \ 12 multiprocessing python-any-r1 13 14 MY_P=compiler-rt-${PV/_/}.src 15 LLVM_P=llvm-${PV/_/}.src 16 17 DESCRIPTION="Compiler runtime libraries for clang (sanitizers & xray)" 18 HOMEPAGE="https://llvm.org/" 19 SRC_URI="https://github.com/llvm/llvm-project/releases/download/llvmorg-${PV}/${MY_P}.tar.xz 20 test? ( https://github.com/llvm/llvm-project/releases/download/llvmorg-${PV}/${LLVM_P}.tar.xz )" 21 22 LICENSE="|| ( UoI-NCSA MIT )" 23 SLOT="${PV%_*}" 24 KEYWORDS="amd64 arm arm64 ppc64 x86 ~amd64-linux ~ppc-macos ~x64-macos ~x86-macos" 25 IUSE="+clang +libfuzzer +profile +sanitize test +xray elibc_glibc" 26 # FIXME: libfuzzer does not enable all its necessary dependencies 27 REQUIRED_USE="libfuzzer? ( || ( sanitize xray ) )" 28 RESTRICT="!test? ( test ) !clang? ( test )" 29 30 CLANG_SLOT=${SLOT%%.*} 31 # llvm-6 for new lit options 32 DEPEND=" 33 >=sys-devel/llvm-6 34 clang? ( sys-devel/clang ) 35 elibc_glibc? ( net-libs/libtirpc ) 36 test? ( 37 !<sys-apps/sandbox-2.13 38 $(python_gen_any_dep ">=dev-python/lit-5[\${PYTHON_USEDEP}]") 39 =sys-devel/clang-${PV%_*}*:${CLANG_SLOT} 40 sys-libs/compiler-rt:${SLOT} ) 41 ${PYTHON_DEPS}" 42 43 S=${WORKDIR}/${MY_P} 44 45 PATCHES=("${FILESDIR}/${P}-fix-__sanitizer_ipc_perm-layout.patch") 46 47 # least intrusive of all 48 CMAKE_BUILD_TYPE=RelWithDebInfo 49 50 python_check_deps() { 51 use test || return 0 52 has_version "dev-python/lit[${PYTHON_USEDEP}]" 53 } 54 55 check_space() { 56 if use test; then 57 local CHECKREQS_DISK_BUILD=11G 58 check-reqs_pkg_pretend 59 fi 60 } 61 62 pkg_pretend() { 63 check_space 64 } 65 66 pkg_setup() { 67 check_space 68 llvm_pkg_setup 69 python-any-r1_pkg_setup 70 } 71 72 src_unpack() { 73 einfo "Unpacking ${MY_P}.tar.xz ..." 74 tar -xf "${DISTDIR}/${MY_P}.tar.xz" || die 75 76 if use test; then 77 einfo "Unpacking parts of ${LLVM_P}.tar.xz ..." 78 tar -xf "${DISTDIR}/${LLVM_P}.tar.xz" \ 79 "${LLVM_P}"/utils/unittest || die 80 mv "${LLVM_P}" llvm || die 81 fi 82 } 83 84 src_prepare() { 85 cmake-utils_src_prepare 86 87 if use test; then 88 # remove tests that are (still) broken by new glibc 89 # https://bugs.llvm.org/show_bug.cgi?id=36065 90 if use elibc_glibc && has_version '>=sys-libs/glibc-2.25'; then 91 rm test/lsan/TestCases/Linux/fork_and_leak.cc || die 92 fi 93 fi 94 } 95 96 src_configure() { 97 # pre-set since we need to pass it to cmake 98 BUILD_DIR=${WORKDIR}/${P}_build 99 100 if use clang; then 101 local -x CC=${CHOST}-clang 102 local -x CXX=${CHOST}-clang++ 103 strip-unsupported-flags 104 fi 105 106 local mycmakeargs=( 107 -DCOMPILER_RT_INSTALL_PATH="${EPREFIX}/usr/lib/clang/${SLOT}" 108 # use a build dir structure consistent with install 109 # this makes it possible to easily deploy test-friendly clang 110 -DCOMPILER_RT_OUTPUT_DIR="${BUILD_DIR}/lib/clang/${SLOT}" 111 112 -DCOMPILER_RT_INCLUDE_TESTS=$(usex test) 113 # built-ins installed by sys-libs/compiler-rt 114 -DCOMPILER_RT_BUILD_BUILTINS=OFF 115 -DCOMPILER_RT_BUILD_LIBFUZZER=$(usex libfuzzer) 116 -DCOMPILER_RT_BUILD_PROFILE=$(usex profile) 117 -DCOMPILER_RT_BUILD_SANITIZERS=$(usex sanitize) 118 -DCOMPILER_RT_BUILD_XRAY=$(usex xray) 119 ) 120 if use test; then 121 mycmakeargs+=( 122 -DLLVM_MAIN_SRC_DIR="${WORKDIR}/llvm" 123 -DLLVM_EXTERNAL_LIT="${EPREFIX}/usr/bin/lit" 124 -DLLVM_LIT_ARGS="-vv;-j;${LIT_JOBS:-$(makeopts_jobs "${MAKEOPTS}" "$(get_nproc)")}" 125 126 # they are created during src_test() 127 -DCOMPILER_RT_TEST_COMPILER="${BUILD_DIR}/lib/llvm/${CLANG_SLOT}/bin/clang" 128 -DCOMPILER_RT_TEST_CXX_COMPILER="${BUILD_DIR}/lib/llvm/${CLANG_SLOT}/bin/clang++" 129 ) 130 131 # same flags are passed for build & tests, so we need to strip 132 # them down to a subset supported by clang 133 CC=${EPREFIX}/usr/lib/llvm/${CLANG_SLOT}/bin/clang \ 134 CXX=${EPREFIX}/usr/lib/llvm/${CLANG_SLOT}/bin/clang++ \ 135 strip-unsupported-flags 136 fi 137 138 if use prefix && [[ "${CHOST}" == *-darwin* ]] ; then 139 mycmakeargs+=( 140 # disable use of SDK for the system itself 141 -DDARWIN_macosx_CACHED_SYSROOT=/ 142 ) 143 fi 144 145 cmake-utils_src_configure 146 147 if use test; then 148 local sys_dir=( "${EPREFIX}"/usr/lib/clang/${SLOT}/lib/* ) 149 [[ -e ${sys_dir} ]] || die "Unable to find ${sys_dir}" 150 [[ ${#sys_dir[@]} -eq 1 ]] || die "Non-deterministic compiler-rt install: ${sys_dir[*]}" 151 152 # copy clang over since resource_dir is located relatively to binary 153 # therefore, we can put our new libraries in it 154 mkdir -p "${BUILD_DIR}"/lib/{llvm/${CLANG_SLOT}/{bin,$(get_libdir)},clang/${SLOT}/include} || die 155 cp "${EPREFIX}"/usr/lib/llvm/${CLANG_SLOT}/bin/clang{,++} \ 156 "${BUILD_DIR}"/lib/llvm/${CLANG_SLOT}/bin/ || die 157 cp "${EPREFIX}"/usr/lib/clang/${SLOT}/include/*.h \ 158 "${BUILD_DIR}"/lib/clang/${SLOT}/include/ || die 159 cp "${sys_dir}"/*builtins*.a \ 160 "${BUILD_DIR}/lib/clang/${SLOT}/lib/${sys_dir##*/}/" || die 161 # we also need LLVMgold.so for gold-based tests 162 if [[ -f ${EPREFIX}/usr/lib/llvm/${CLANG_SLOT}/$(get_libdir)/LLVMgold.so ]]; then 163 ln -s "${EPREFIX}"/usr/lib/llvm/${CLANG_SLOT}/$(get_libdir)/LLVMgold.so \ 164 "${BUILD_DIR}"/lib/llvm/${CLANG_SLOT}/$(get_libdir)/ || die 165 fi 166 fi 167 } 168 169 src_test() { 170 # respect TMPDIR! 171 local -x LIT_PRESERVES_TMP=1 172 # disable sandbox to have it stop clobbering LD_PRELOAD 173 local -x SANDBOX_ON=0 174 # wipe LD_PRELOAD to make ASAN happy 175 local -x LD_PRELOAD= 176 177 cmake-utils_src_make check-all 178 }