Gentoo Archives: gentoo-commits

From: "Michał Górny" <mgorny@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] repo/gentoo:master commit in: sys-libs/compiler-rt-sanitizers/
Date: Sun, 06 Feb 2022 15:35:15
Message-Id: 1644161666.25666d46b7ab2ff7495ed2cd5c76cb69fc26844d.mgorny@gentoo
1 commit: 25666d46b7ab2ff7495ed2cd5c76cb69fc26844d
2 Author: Michał Górny <mgorny <AT> gentoo <DOT> org>
3 AuthorDate: Sun Feb 6 15:16:47 2022 +0000
4 Commit: Michał Górny <mgorny <AT> gentoo <DOT> org>
5 CommitDate: Sun Feb 6 15:34:26 2022 +0000
6 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=25666d46
7
8 sys-libs/compiler-rt-sanitizers: Add 15.x live ebuild
9
10 Signed-off-by: Michał Górny <mgorny <AT> gentoo.org>
11
12 .../compiler-rt-sanitizers-15.0.0.9999.ebuild | 215 +++++++++++++++++++++
13 1 file changed, 215 insertions(+)
14
15 diff --git a/sys-libs/compiler-rt-sanitizers/compiler-rt-sanitizers-15.0.0.9999.ebuild b/sys-libs/compiler-rt-sanitizers/compiler-rt-sanitizers-15.0.0.9999.ebuild
16 new file mode 100644
17 index 000000000000..12e5eb2d01e7
18 --- /dev/null
19 +++ b/sys-libs/compiler-rt-sanitizers/compiler-rt-sanitizers-15.0.0.9999.ebuild
20 @@ -0,0 +1,215 @@
21 +# Copyright 1999-2022 Gentoo Authors
22 +# Distributed under the terms of the GNU General Public License v2
23 +
24 +EAPI=7
25 +
26 +PYTHON_COMPAT=( python3_{8..10} )
27 +inherit check-reqs cmake flag-o-matic llvm llvm.org python-any-r1
28 +
29 +DESCRIPTION="Compiler runtime libraries for clang (sanitizers & xray)"
30 +HOMEPAGE="https://llvm.org/"
31 +
32 +LICENSE="Apache-2.0-with-LLVM-exceptions || ( UoI-NCSA MIT )"
33 +SLOT="$(ver_cut 1-3)"
34 +KEYWORDS=""
35 +IUSE="+abi_x86_32 abi_x86_64 +clang debug test"
36 +# base targets
37 +IUSE+=" +libfuzzer +memprof +orc +profile +xray"
38 +# sanitizer targets, keep in sync with config-ix.cmake
39 +# NB: ubsan, scudo deliberately match two entries
40 +SANITIZER_FLAGS=(
41 + asan dfsan lsan msan hwasan tsan ubsan safestack cfi scudo
42 + shadowcallstack gwp-asan
43 +)
44 +IUSE+=" ${SANITIZER_FLAGS[@]/#/+}"
45 +REQUIRED_USE="
46 + || ( ${SANITIZER_FLAGS[*]} libfuzzer orc profile xray )
47 + test? (
48 + cfi? ( ubsan )
49 + gwp-asan? ( scudo )
50 + )"
51 +RESTRICT="!test? ( test ) !clang? ( test )"
52 +
53 +CLANG_SLOT=${SLOT%%.*}
54 +# llvm-6 for new lit options
55 +DEPEND="
56 + >=sys-devel/llvm-6
57 + virtual/libcrypt[abi_x86_32(-)?,abi_x86_64(-)?]"
58 +BDEPEND="
59 + >=dev-util/cmake-3.16
60 + clang? ( sys-devel/clang )
61 + elibc_glibc? ( net-libs/libtirpc )
62 + test? (
63 + !<sys-apps/sandbox-2.13
64 + $(python_gen_any_dep ">=dev-python/lit-5[\${PYTHON_USEDEP}]")
65 + =sys-devel/clang-${PV%_*}*:${CLANG_SLOT}
66 + sys-libs/compiler-rt:${SLOT}
67 + )
68 + !test? (
69 + ${PYTHON_DEPS}
70 + )"
71 +
72 +LLVM_COMPONENTS=( compiler-rt cmake )
73 +LLVM_TEST_COMPONENTS=( llvm/lib/Testing/Support llvm/utils/unittest )
74 +LLVM_PATCHSET=9999-1
75 +llvm.org_set_globals
76 +
77 +python_check_deps() {
78 + use test || return 0
79 + has_version "dev-python/lit[${PYTHON_USEDEP}]"
80 +}
81 +
82 +check_space() {
83 + if use test; then
84 + local CHECKREQS_DISK_BUILD=11G
85 + check-reqs_pkg_pretend
86 + fi
87 +}
88 +
89 +pkg_pretend() {
90 + check_space
91 +}
92 +
93 +pkg_setup() {
94 + check_space
95 + llvm_pkg_setup
96 + python-any-r1_pkg_setup
97 +}
98 +
99 +src_prepare() {
100 + sed -i -e 's:-Werror::' lib/tsan/go/buildgo.sh || die
101 +
102 + local flag
103 + for flag in "${SANITIZER_FLAGS[@]}"; do
104 + if ! use "${flag}"; then
105 + local cmake_flag=${flag/-/_}
106 + sed -i -e "/COMPILER_RT_HAS_${cmake_flag^^}/s:TRUE:FALSE:" \
107 + cmake/config-ix.cmake || die
108 + fi
109 + done
110 +
111 + # TODO: fix these tests to be skipped upstream
112 + if use asan && ! use profile; then
113 + rm test/asan/TestCases/asan_and_llvm_coverage_test.cpp || die
114 + fi
115 + if use ubsan && ! use cfi; then
116 + > test/cfi/CMakeLists.txt || die
117 + fi
118 +
119 + llvm.org_src_prepare
120 +}
121 +
122 +src_configure() {
123 + # LLVM_ENABLE_ASSERTIONS=NO does not guarantee this for us, #614844
124 + use debug || local -x CPPFLAGS="${CPPFLAGS} -DNDEBUG"
125 +
126 + # pre-set since we need to pass it to cmake
127 + BUILD_DIR=${WORKDIR}/compiler-rt_build
128 +
129 + if use clang; then
130 + local -x CC=${CHOST}-clang
131 + local -x CXX=${CHOST}-clang++
132 + strip-unsupported-flags
133 + fi
134 +
135 + local flag want_sanitizer=OFF
136 + for flag in "${SANITIZER_FLAGS[@]}"; do
137 + if use "${flag}"; then
138 + want_sanitizer=ON
139 + break
140 + fi
141 + done
142 +
143 + local mycmakeargs=(
144 + -DCOMPILER_RT_INSTALL_PATH="${EPREFIX}/usr/lib/clang/${SLOT}"
145 + # use a build dir structure consistent with install
146 + # this makes it possible to easily deploy test-friendly clang
147 + -DCOMPILER_RT_OUTPUT_DIR="${BUILD_DIR}/lib/clang/${SLOT}"
148 +
149 + -DCOMPILER_RT_INCLUDE_TESTS=$(usex test)
150 + # builtins & crt installed by sys-libs/compiler-rt
151 + -DCOMPILER_RT_BUILD_BUILTINS=OFF
152 + -DCOMPILER_RT_BUILD_CRT=OFF
153 + -DCOMPILER_RT_BUILD_LIBFUZZER=$(usex libfuzzer)
154 + -DCOMPILER_RT_BUILD_MEMPROF=$(usex memprof)
155 + -DCOMPILER_RT_BUILD_ORC=$(usex orc)
156 + -DCOMPILER_RT_BUILD_PROFILE=$(usex profile)
157 + -DCOMPILER_RT_BUILD_SANITIZERS="${want_sanitizer}"
158 + -DCOMPILER_RT_BUILD_XRAY=$(usex xray)
159 +
160 + -DPython3_EXECUTABLE="${PYTHON}"
161 + )
162 +
163 + if use amd64; then
164 + mycmakeargs+=(
165 + -DCAN_TARGET_i386=$(usex abi_x86_32)
166 + -DCAN_TARGET_x86_64=$(usex abi_x86_64)
167 + )
168 + fi
169 +
170 + if use test; then
171 + mycmakeargs+=(
172 + -DLLVM_MAIN_SRC_DIR="${WORKDIR}/llvm"
173 + -DLLVM_EXTERNAL_LIT="${EPREFIX}/usr/bin/lit"
174 + -DLLVM_LIT_ARGS="$(get_lit_flags)"
175 +
176 + # they are created during src_test()
177 + -DCOMPILER_RT_TEST_COMPILER="${BUILD_DIR}/lib/llvm/${CLANG_SLOT}/bin/clang"
178 + -DCOMPILER_RT_TEST_CXX_COMPILER="${BUILD_DIR}/lib/llvm/${CLANG_SLOT}/bin/clang++"
179 + )
180 +
181 + # same flags are passed for build & tests, so we need to strip
182 + # them down to a subset supported by clang
183 + CC=${EPREFIX}/usr/lib/llvm/${CLANG_SLOT}/bin/clang \
184 + CXX=${EPREFIX}/usr/lib/llvm/${CLANG_SLOT}/bin/clang++ \
185 + strip-unsupported-flags
186 + fi
187 +
188 + if use prefix && [[ "${CHOST}" == *-darwin* ]] ; then
189 + mycmakeargs+=(
190 + # setting -isysroot is disabled with compiler-rt-prefix-paths.patch
191 + # this allows adding arm64 support using SDK in EPREFIX
192 + -DDARWIN_macosx_CACHED_SYSROOT="${EPREFIX}/MacOSX.sdk"
193 + # Set version based on the SDK in EPREFIX
194 + # This disables i386 for SDK >= 10.15
195 + # Will error if has_use tsan and SDK < 10.12
196 + -DDARWIN_macosx_OVERRIDE_SDK_VERSION="$(realpath ${EPREFIX}/MacOSX.sdk | sed -e 's/.*MacOSX\(.*\)\.sdk/\1/')"
197 + # Use our libtool instead of looking it up with xcrun
198 + -DCMAKE_LIBTOOL="${EPREFIX}/usr/bin/${CHOST}-libtool"
199 + )
200 + fi
201 +
202 + cmake_src_configure
203 +
204 + if use test; then
205 + local sys_dir=( "${EPREFIX}"/usr/lib/clang/${SLOT}/lib/* )
206 + [[ -e ${sys_dir} ]] || die "Unable to find ${sys_dir}"
207 + [[ ${#sys_dir[@]} -eq 1 ]] || die "Non-deterministic compiler-rt install: ${sys_dir[*]}"
208 +
209 + # copy clang over since resource_dir is located relatively to binary
210 + # therefore, we can put our new libraries in it
211 + mkdir -p "${BUILD_DIR}"/lib/{llvm/${CLANG_SLOT}/{bin,$(get_libdir)},clang/${SLOT}/include} || die
212 + cp "${EPREFIX}"/usr/lib/llvm/${CLANG_SLOT}/bin/clang{,++} \
213 + "${BUILD_DIR}"/lib/llvm/${CLANG_SLOT}/bin/ || die
214 + cp "${EPREFIX}"/usr/lib/clang/${SLOT}/include/*.h \
215 + "${BUILD_DIR}"/lib/clang/${SLOT}/include/ || die
216 + cp "${sys_dir}"/*builtins*.a \
217 + "${BUILD_DIR}/lib/clang/${SLOT}/lib/${sys_dir##*/}/" || die
218 + # we also need LLVMgold.so for gold-based tests
219 + if [[ -f ${EPREFIX}/usr/lib/llvm/${CLANG_SLOT}/$(get_libdir)/LLVMgold.so ]]; then
220 + ln -s "${EPREFIX}"/usr/lib/llvm/${CLANG_SLOT}/$(get_libdir)/LLVMgold.so \
221 + "${BUILD_DIR}"/lib/llvm/${CLANG_SLOT}/$(get_libdir)/ || die
222 + fi
223 + fi
224 +}
225 +
226 +src_test() {
227 + # respect TMPDIR!
228 + local -x LIT_PRESERVES_TMP=1
229 + # disable sandbox to have it stop clobbering LD_PRELOAD
230 + local -x SANDBOX_ON=0
231 + # wipe LD_PRELOAD to make ASAN happy
232 + local -x LD_PRELOAD=
233 +
234 + cmake_build check-all
235 +}