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