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-devel/llvm/files/, sys-devel/llvm/
Date: Sun, 27 Dec 2015 22:52:19
Message-Id: 1451256719.4ea0768355d83631d0baf5c7de9b712ea2ebe12a.mgorny@gentoo
1 commit: 4ea0768355d83631d0baf5c7de9b712ea2ebe12a
2 Author: Michał Górny <mgorny <AT> gentoo <DOT> org>
3 AuthorDate: Sun Dec 27 22:47:38 2015 +0000
4 Commit: Michał Górny <mgorny <AT> gentoo <DOT> org>
5 CommitDate: Sun Dec 27 22:51:59 2015 +0000
6 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=4ea07683
7
8 sys-devel/llvm: Backport msan fix for 4.1+ kernels, bug #569894
9
10 .../llvm/files/compiler-rt-3.7-msan-fix.patch | 86 ++++
11 sys-devel/llvm/files/llvm-3.7-msan-fix.patch | 79 +++
12 sys-devel/llvm/llvm-3.7.0-r5.ebuild | 540 +++++++++++++++++++++
13 3 files changed, 705 insertions(+)
14
15 diff --git a/sys-devel/llvm/files/compiler-rt-3.7-msan-fix.patch b/sys-devel/llvm/files/compiler-rt-3.7-msan-fix.patch
16 new file mode 100644
17 index 0000000..3854a18
18 --- /dev/null
19 +++ b/sys-devel/llvm/files/compiler-rt-3.7-msan-fix.patch
20 @@ -0,0 +1,86 @@
21 +From 5dad120f9c9bc74c73edadb0467d8df81ae46066 Mon Sep 17 00:00:00 2001
22 +From: "H.J. Lu" <hjl.tools@×××××.com>
23 +Date: Wed, 5 Aug 2015 05:34:27 -0700
24 +Subject: [PATCH 08/13] Apply split-layout-compiler-rt.patch
25 +
26 +https://llvm.org/bugs/show_bug.cgi?id=24155
27 +---
28 + lib/msan/msan.h | 30 ++++++++++++++++++++----------
29 + lib/msan/msan_allocator.cc | 12 +++++++++++-
30 + 2 files changed, 31 insertions(+), 11 deletions(-)
31 +
32 +diff --git a/lib/msan/msan.h b/lib/msan/msan.h
33 +index cd8bc19..6251b38 100644
34 +--- a/lib/msan/msan.h
35 ++++ b/lib/msan/msan.h
36 +@@ -94,17 +94,27 @@ const MappingDesc kMemoryLayout[] = {
37 +
38 + #elif SANITIZER_LINUX && SANITIZER_WORDSIZE == 64
39 +
40 +-// Requries PIE binary and ASLR enabled.
41 +-// Main thread stack and DSOs at 0x7f0000000000 (sometimes 0x7e0000000000).
42 +-// Heap at 0x600000000000.
43 ++// All of the following configurations are supported.
44 ++// ASLR disabled: main executable and DSOs at 0x555550000000
45 ++// PIE and ASLR: main executable and DSOs at 0x7f0000000000
46 ++// non-PIE: main executable below 0x100000000, DSOs at 0x7f0000000000
47 ++// Heap at 0x700000000000.
48 + const MappingDesc kMemoryLayout[] = {
49 +- {0x000000000000ULL, 0x200000000000ULL, MappingDesc::INVALID, "invalid"},
50 +- {0x200000000000ULL, 0x400000000000ULL, MappingDesc::SHADOW, "shadow"},
51 +- {0x400000000000ULL, 0x600000000000ULL, MappingDesc::ORIGIN, "origin"},
52 +- {0x600000000000ULL, 0x800000000000ULL, MappingDesc::APP, "app"}};
53 +-
54 +-#define MEM_TO_SHADOW(mem) (((uptr)(mem)) & ~0x400000000000ULL)
55 +-#define SHADOW_TO_ORIGIN(mem) (((uptr)(mem)) + 0x200000000000ULL)
56 ++ {0x000000000000ULL, 0x050000000000ULL, MappingDesc::APP, "app-1"},
57 ++ {0x050000000000ULL, 0x100000000000ULL, MappingDesc::SHADOW, "shadow-2"},
58 ++ {0x100000000000ULL, 0x150000000000ULL, MappingDesc::INVALID, "invalid"},
59 ++ {0x150000000000ULL, 0x200000000000ULL, MappingDesc::ORIGIN, "origin-2"},
60 ++ {0x200000000000ULL, 0x300000000000ULL, MappingDesc::SHADOW, "shadow-3"},
61 ++ {0x300000000000ULL, 0x400000000000ULL, MappingDesc::ORIGIN, "origin-3"},
62 ++ {0x400000000000ULL, 0x500000000000ULL, MappingDesc::INVALID, "invalid"},
63 ++ {0x500000000000ULL, 0x550000000000ULL, MappingDesc::SHADOW, "shadow-1"},
64 ++ {0x550000000000ULL, 0x600000000000ULL, MappingDesc::APP, "app-2"},
65 ++ {0x600000000000ULL, 0x650000000000ULL, MappingDesc::ORIGIN, "origin-1"},
66 ++ {0x650000000000ULL, 0x700000000000ULL, MappingDesc::INVALID, "invalid"},
67 ++ {0x700000000000ULL, 0x800000000000ULL, MappingDesc::APP, "app-3"}};
68 ++
69 ++#define MEM_TO_SHADOW(mem) (((uptr)(mem)) ^ 0x500000000000ULL)
70 ++#define SHADOW_TO_ORIGIN(mem) (((uptr)(mem)) + 0x100000000000ULL)
71 +
72 + #else
73 + #error "Unsupported platform"
74 +diff --git a/lib/msan/msan_allocator.cc b/lib/msan/msan_allocator.cc
75 +index 6df3566..e588bf8 100644
76 +--- a/lib/msan/msan_allocator.cc
77 ++++ b/lib/msan/msan_allocator.cc
78 +@@ -49,7 +49,8 @@ struct MsanMapUnmapCallback {
79 + typedef SizeClassAllocator32<0, SANITIZER_MMAP_RANGE_SIZE, sizeof(Metadata),
80 + SizeClassMap, kRegionSizeLog, ByteMap,
81 + MsanMapUnmapCallback> PrimaryAllocator;
82 +-#elif defined(__x86_64__)
83 ++
84 ++#elif SANITIZER_FREEBSD && SANITIZER_WORDSIZE == 64
85 + static const uptr kAllocatorSpace = 0x600000000000ULL;
86 + static const uptr kAllocatorSize = 0x80000000000; // 8T.
87 + static const uptr kMetadataSize = sizeof(Metadata);
88 +@@ -67,6 +68,15 @@ struct MsanMapUnmapCallback {
89 + typedef SizeClassAllocator64<kAllocatorSpace, kAllocatorSize, kMetadataSize,
90 + DefaultSizeClassMap,
91 + MsanMapUnmapCallback> PrimaryAllocator;
92 ++#elif SANITIZER_LINUX && SANITIZER_WORDSIZE == 64
93 ++ static const uptr kAllocatorSpace = 0x700000000000ULL;
94 ++ static const uptr kAllocatorSize = 0x80000000000; // 8T.
95 ++ static const uptr kMetadataSize = sizeof(Metadata);
96 ++ static const uptr kMaxAllowedMallocSize = 8UL << 30;
97 ++
98 ++ typedef SizeClassAllocator64<kAllocatorSpace, kAllocatorSize, kMetadataSize,
99 ++ DefaultSizeClassMap,
100 ++ MsanMapUnmapCallback> PrimaryAllocator;
101 + #endif
102 + typedef SizeClassAllocatorLocalCache<PrimaryAllocator> AllocatorCache;
103 + typedef LargeMmapAllocator<MsanMapUnmapCallback> SecondaryAllocator;
104 +--
105 +2.6.4
106 +
107
108 diff --git a/sys-devel/llvm/files/llvm-3.7-msan-fix.patch b/sys-devel/llvm/files/llvm-3.7-msan-fix.patch
109 new file mode 100644
110 index 0000000..e44baa8
111 --- /dev/null
112 +++ b/sys-devel/llvm/files/llvm-3.7-msan-fix.patch
113 @@ -0,0 +1,79 @@
114 +From 8b0f2fff6e080c053e4fd94d44a694768b8c156e Mon Sep 17 00:00:00 2001
115 +From: "H.J. Lu" <hjl.tools@×××××.com>
116 +Date: Wed, 5 Aug 2015 05:35:26 -0700
117 +Subject: [PATCH 78/84] Apply split-layout-llvm.patch
118 +
119 +https://llvm.org/bugs/show_bug.cgi?id=24155
120 +---
121 + lib/Transforms/Instrumentation/MemorySanitizer.cpp | 31 ++++++++++++++++------
122 + 1 file changed, 23 insertions(+), 8 deletions(-)
123 +
124 +diff --git a/lib/Transforms/Instrumentation/MemorySanitizer.cpp b/lib/Transforms/Instrumentation/MemorySanitizer.cpp
125 +index 286a563..2ab8bfc 100644
126 +--- a/lib/Transforms/Instrumentation/MemorySanitizer.cpp
127 ++++ b/lib/Transforms/Instrumentation/MemorySanitizer.cpp
128 +@@ -194,6 +194,12 @@ static cl::opt<bool> ClCheckConstantShadow("msan-check-constant-shadow",
129 + static const char *const kMsanModuleCtorName = "msan.module_ctor";
130 + static const char *const kMsanInitName = "__msan_init";
131 +
132 ++static cl::opt<bool> ClSplitLayout(
133 ++ "msan-split-layout", cl::desc(
134 ++ "use experimental memory layout compatible with "
135 ++ "non-pie and non-aslr execution"),
136 ++ cl::Hidden, cl::init(true));
137 ++
138 + namespace {
139 +
140 + // Memory map parameters used in application-to-shadow address calculation.
141 +@@ -228,6 +234,13 @@ static const MemoryMapParams Linux_X86_64_MemoryMapParams = {
142 + 0x200000000000, // OriginBase
143 + };
144 +
145 ++static const MemoryMapParams Linux_X86_64_Split_MemoryMapParams = {
146 ++ 0, // AndMask (not used)
147 ++ 0x500000000000, // XorMask
148 ++ 0, // ShadowBase (not used)
149 ++ 0x100000000000, // OriginBase
150 ++};
151 ++
152 + // mips64 Linux
153 + static const MemoryMapParams Linux_MIPS64_MemoryMapParams = {
154 + 0x004000000000, // AndMask
155 +@@ -483,7 +496,8 @@ bool MemorySanitizer::doInitialization(Module &M) {
156 + case Triple::Linux:
157 + switch (TargetTriple.getArch()) {
158 + case Triple::x86_64:
159 +- MapParams = Linux_X86_MemoryMapParams.bits64;
160 ++ MapParams = ClSplitLayout ? &Linux_X86_64_Split_MemoryMapParams
161 ++ : Linux_X86_MemoryMapParams.bits64;
162 + break;
163 + case Triple::x86:
164 + MapParams = Linux_X86_MemoryMapParams.bits32;
165 +@@ -893,16 +907,17 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
166 + ///
167 + /// Offset = (Addr & ~AndMask) ^ XorMask
168 + Value *getShadowPtrOffset(Value *Addr, IRBuilder<> &IRB) {
169 ++ Value *OffsetLong = IRB.CreatePointerCast(Addr, MS.IntptrTy);
170 ++
171 + uint64_t AndMask = MS.MapParams->AndMask;
172 +- assert(AndMask != 0 && "AndMask shall be specified");
173 +- Value *OffsetLong =
174 +- IRB.CreateAnd(IRB.CreatePointerCast(Addr, MS.IntptrTy),
175 +- ConstantInt::get(MS.IntptrTy, ~AndMask));
176 ++ if (AndMask)
177 ++ OffsetLong =
178 ++ IRB.CreateAnd(OffsetLong, ConstantInt::get(MS.IntptrTy, ~AndMask));
179 +
180 + uint64_t XorMask = MS.MapParams->XorMask;
181 +- if (XorMask != 0)
182 +- OffsetLong = IRB.CreateXor(OffsetLong,
183 +- ConstantInt::get(MS.IntptrTy, XorMask));
184 ++ if (XorMask)
185 ++ OffsetLong =
186 ++ IRB.CreateXor(OffsetLong, ConstantInt::get(MS.IntptrTy, XorMask));
187 + return OffsetLong;
188 + }
189 +
190 +--
191 +2.6.4
192 +
193
194 diff --git a/sys-devel/llvm/llvm-3.7.0-r5.ebuild b/sys-devel/llvm/llvm-3.7.0-r5.ebuild
195 new file mode 100644
196 index 0000000..cc86192
197 --- /dev/null
198 +++ b/sys-devel/llvm/llvm-3.7.0-r5.ebuild
199 @@ -0,0 +1,540 @@
200 +# Copyright 1999-2015 Gentoo Foundation
201 +# Distributed under the terms of the GNU General Public License v2
202 +# $Id$
203 +
204 +EAPI=5
205 +
206 +: ${CMAKE_MAKEFILE_GENERATOR:=ninja}
207 +PYTHON_COMPAT=( python2_7 )
208 +
209 +inherit check-reqs cmake-utils eutils flag-o-matic multilib \
210 + multilib-minimal python-single-r1 toolchain-funcs pax-utils
211 +
212 +DESCRIPTION="Low Level Virtual Machine"
213 +HOMEPAGE="http://llvm.org/"
214 +SRC_URI="http://llvm.org/releases/${PV}/${P}.src.tar.xz
215 + clang? ( http://llvm.org/releases/${PV}/compiler-rt-${PV}.src.tar.xz
216 + http://llvm.org/releases/${PV}/cfe-${PV}.src.tar.xz
217 + http://llvm.org/releases/${PV}/clang-tools-extra-${PV}.src.tar.xz )
218 + lldb? ( http://llvm.org/releases/${PV}/lldb-${PV}.src.tar.xz )
219 + !doc? ( http://dev.gentoo.org/~voyageur/distfiles/${P}-manpages.tar.bz2 )"
220 +
221 +LICENSE="UoI-NCSA"
222 +SLOT="0/${PV}"
223 +KEYWORDS="~amd64 ~arm ~arm64 ~ppc ~ppc64 ~sparc ~x86 ~amd64-fbsd ~x86-fbsd ~x64-freebsd ~amd64-linux ~arm-linux ~x86-linux ~ppc-macos ~x64-macos ~x86-macos"
224 +IUSE="clang debug doc gold libedit +libffi lldb multitarget ncurses ocaml
225 + python +static-analyzer test xml video_cards_radeon kernel_Darwin"
226 +
227 +COMMON_DEPEND="
228 + sys-libs/zlib:0=
229 + clang? (
230 + python? ( ${PYTHON_DEPS} )
231 + static-analyzer? (
232 + dev-lang/perl:*
233 + ${PYTHON_DEPS}
234 + )
235 + xml? ( dev-libs/libxml2:2=[${MULTILIB_USEDEP}] )
236 + )
237 + gold? ( >=sys-devel/binutils-2.22:*[cxx] )
238 + libedit? ( dev-libs/libedit:0=[${MULTILIB_USEDEP}] )
239 + libffi? ( >=virtual/libffi-3.0.13-r1:0=[${MULTILIB_USEDEP}] )
240 + ncurses? ( >=sys-libs/ncurses-5.9-r3:0=[${MULTILIB_USEDEP}] )
241 + ocaml? (
242 + >=dev-lang/ocaml-4.00.0:0=
243 + dev-ml/findlib
244 + dev-ml/ocaml-ctypes
245 + !!<=sys-devel/llvm-3.7.0-r1[ocaml] )"
246 +# configparser-3.2 breaks the build (3.3 or none at all are fine)
247 +DEPEND="${COMMON_DEPEND}
248 + dev-lang/perl
249 + >=sys-devel/make-3.81
250 + >=sys-devel/flex-2.5.4
251 + >=sys-devel/bison-1.875d
252 + || ( >=sys-devel/gcc-3.0 >=sys-devel/llvm-3.5
253 + ( >=sys-freebsd/freebsd-lib-9.1-r10 sys-libs/libcxx )
254 + )
255 + || ( >=sys-devel/binutils-2.18 >=sys-devel/binutils-apple-5.1 )
256 + kernel_Darwin? ( sys-libs/libcxx )
257 + clang? ( xml? ( virtual/pkgconfig ) )
258 + doc? ( dev-python/sphinx )
259 + gold? ( sys-libs/binutils-libs )
260 + libffi? ( virtual/pkgconfig )
261 + lldb? ( dev-lang/swig )
262 + !!<dev-python/configparser-3.3.0.2
263 + ocaml? ( test? ( dev-ml/ounit ) )
264 + ${PYTHON_DEPS}"
265 +RDEPEND="${COMMON_DEPEND}
266 + clang? ( !<=sys-devel/clang-${PV}-r99 )
267 + abi_x86_32? ( !<=app-emulation/emul-linux-x86-baselibs-20130224-r2
268 + !app-emulation/emul-linux-x86-baselibs[-abi_x86_32(-)] )"
269 +PDEPEND="clang? ( =sys-devel/clang-${PV}-r100 )"
270 +
271 +# pypy gives me around 1700 unresolved tests due to open file limit
272 +# being exceeded. probably GC does not close them fast enough.
273 +REQUIRED_USE="${PYTHON_REQUIRED_USE}
274 + lldb? ( clang xml )"
275 +
276 +S=${WORKDIR}/${P/_}.src
277 +
278 +pkg_pretend() {
279 + # in megs
280 + # !clang !debug !multitarget -O2 400
281 + # !clang !debug multitarget -O2 550
282 + # clang !debug !multitarget -O2 950
283 + # clang !debug multitarget -O2 1200
284 + # !clang debug multitarget -O2 5G
285 + # clang !debug multitarget -O0 -g 12G
286 + # clang debug multitarget -O2 16G
287 + # clang debug multitarget -O0 -g 14G
288 +
289 + local build_size=550
290 + use clang && build_size=1200
291 +
292 + if use debug; then
293 + ewarn "USE=debug is known to increase the size of package considerably"
294 + ewarn "and cause the tests to fail."
295 + ewarn
296 +
297 + (( build_size *= 14 ))
298 + elif is-flagq '-g?(gdb)?([1-9])'; then
299 + ewarn "The C++ compiler -g option is known to increase the size of the package"
300 + ewarn "considerably. If you run out of space, please consider removing it."
301 + ewarn
302 +
303 + (( build_size *= 10 ))
304 + fi
305 +
306 + # Multiply by number of ABIs :).
307 + local abis=( $(multilib_get_enabled_abis) )
308 + (( build_size *= ${#abis[@]} ))
309 +
310 + local CHECKREQS_DISK_BUILD=${build_size}M
311 + check-reqs_pkg_pretend
312 +
313 + if [[ ${MERGE_TYPE} != binary ]]; then
314 + echo 'int main() {return 0;}' > "${T}"/test.cxx || die
315 + ebegin "Trying to build a C++11 test program"
316 + if ! $(tc-getCXX) -std=c++11 -o /dev/null "${T}"/test.cxx; then
317 + eerror "LLVM-${PV} requires C++11-capable C++ compiler. Your current compiler"
318 + eerror "does not seem to support -std=c++11 option. Please upgrade your compiler"
319 + eerror "to gcc-4.7 or an equivalent version supporting C++11."
320 + die "Currently active compiler does not support -std=c++11"
321 + fi
322 + eend ${?}
323 + fi
324 +}
325 +
326 +pkg_setup() {
327 + pkg_pretend
328 +}
329 +
330 +src_unpack() {
331 + default
332 +
333 + if use clang; then
334 + mv "${WORKDIR}"/cfe-${PV/_}.src "${S}"/tools/clang \
335 + || die "clang source directory move failed"
336 + mv "${WORKDIR}"/compiler-rt-${PV/_}.src "${S}"/projects/compiler-rt \
337 + || die "compiler-rt source directory move failed"
338 + mv "${WORKDIR}"/clang-tools-extra-${PV/_}.src "${S}"/tools/clang/tools/extra \
339 + || die "clang-tools-extra source directory move failed"
340 + fi
341 +
342 + if use lldb; then
343 + mv "${WORKDIR}"/lldb-${PV/_}.src "${S}"/tools/lldb \
344 + || die "lldb source directory move failed"
345 + fi
346 +}
347 +
348 +src_prepare() {
349 + # Make ocaml warnings non-fatal, bug #537308
350 + sed -e "/RUN/s/-warn-error A//" -i test/Bindings/OCaml/*ml || die
351 + # Fix libdir for ocaml bindings install, bug #559134
352 + epatch "${FILESDIR}"/cmake/${P}-ocaml-multilib.patch
353 + # Do not build/install ocaml docs with USE=-doc, bug #562008
354 + epatch "${FILESDIR}"/cmake/${P}-ocaml-build_doc.patch
355 +
356 + # Make it possible to override Sphinx HTML install dirs
357 + # https://llvm.org/bugs/show_bug.cgi?id=23780
358 + epatch "${FILESDIR}"/cmake/0002-cmake-Support-overriding-Sphinx-HTML-doc-install-dir.patch
359 +
360 + # Prevent race conditions with parallel Sphinx runs
361 + # https://llvm.org/bugs/show_bug.cgi?id=23781
362 + epatch "${FILESDIR}"/cmake/0003-cmake-Add-an-ordering-dep-between-HTML-man-Sphinx-ta.patch
363 +
364 + # Prevent installing libgtest
365 + # https://llvm.org/bugs/show_bug.cgi?id=18341
366 + epatch "${FILESDIR}"/cmake/0004-cmake-Do-not-install-libgtest.patch
367 +
368 + # Fix llvm-config for shared linking and sane flags
369 + # https://bugs.gentoo.org/show_bug.cgi?id=565358
370 + epatch "${FILESDIR}"/llvm-3.7-llvm-config.patch
371 +
372 + # Fix msan with newer kernels, #569894
373 + epatch "${FILESDIR}"/llvm-3.7-msan-fix.patch
374 +
375 + if use clang; then
376 + # Automatically select active system GCC's libraries, bugs #406163 and #417913
377 + epatch "${FILESDIR}"/clang-3.5-gentoo-runtime-gcc-detection-v3.patch
378 +
379 + epatch "${FILESDIR}"/clang-3.6-gentoo-install.patch
380 +
381 + sed -i -e "s^@EPREFIX@^${EPREFIX}^" \
382 + tools/clang/tools/scan-build/scan-build || die
383 +
384 + # Install clang runtime into /usr/lib/clang
385 + # https://llvm.org/bugs/show_bug.cgi?id=23792
386 + epatch "${FILESDIR}"/cmake/clang-0001-Install-clang-runtime-into-usr-lib-without-suffix.patch
387 + epatch "${FILESDIR}"/cmake/compiler-rt-0001-cmake-Install-compiler-rt-into-usr-lib-without-suffi.patch
388 +
389 + # Do not force -march flags on arm platforms
390 + # https://bugs.gentoo.org/show_bug.cgi?id=562706
391 + epatch "${FILESDIR}"/cmake/${P}-compiler_rt_arm_march_flags.patch
392 +
393 + # Make it possible to override CLANG_LIBDIR_SUFFIX
394 + # (that is used only to find LLVMgold.so)
395 + # https://llvm.org/bugs/show_bug.cgi?id=23793
396 + epatch "${FILESDIR}"/cmake/clang-0002-cmake-Make-CLANG_LIBDIR_SUFFIX-overridable.patch
397 +
398 + pushd projects/compiler-rt >/dev/null || die
399 +
400 + # Fix msan with newer kernels, compiler-rt part, #569894
401 + epatch "${FILESDIR}"/compiler-rt-3.7-msan-fix.patch
402 +
403 + # Fix WX sections, bug #421527
404 + find lib/builtins -type f -name '*.S' -exec sed \
405 + -e '$a\\n#if defined(__linux__) && defined(__ELF__)\n.section .note.GNU-stack,"",%progbits\n#endif' \
406 + -i {} + || die
407 +
408 + popd >/dev/null || die
409 + fi
410 +
411 + if use lldb; then
412 + # Do not install dummy readline.so module from
413 + # https://llvm.org/bugs/show_bug.cgi?id=18841
414 + sed -e 's/add_subdirectory(readline)/#&/' \
415 + -i tools/lldb/scripts/Python/modules/CMakeLists.txt || die
416 +
417 + # Fix Python paths, bugs #562436 and #562438
418 + epatch "${FILESDIR}"/${PN}-3.7-lldb_python.patch
419 + sed -e "s/GENTOO_LIBDIR/$(get_libdir)/" \
420 + -i tools/lldb/scripts/Python/finishSwigPythonLLDB.py || die
421 +
422 + # Fix build with ncurses[tinfo], #560474
423 + # http://llvm.org/viewvc/llvm-project?view=revision&revision=247842
424 + epatch "${FILESDIR}"/cmake/${P}-lldb_tinfo.patch
425 + fi
426 +
427 + # User patches
428 + epatch_user
429 +
430 + python_setup
431 +
432 + # Native libdir is used to hold LLVMgold.so
433 + NATIVE_LIBDIR=$(get_libdir)
434 +}
435 +
436 +multilib_src_configure() {
437 + local targets
438 + if use multitarget; then
439 + targets=all
440 + else
441 + targets='host;BPF;CppBackend'
442 + use video_cards_radeon && targets+=';AMDGPU'
443 + fi
444 +
445 + local ffi_cflags ffi_ldflags
446 + if use libffi; then
447 + ffi_cflags=$(pkg-config --cflags-only-I libffi)
448 + ffi_ldflags=$(pkg-config --libs-only-L libffi)
449 + fi
450 +
451 + local libdir=$(get_libdir)
452 + local mycmakeargs=(
453 + "${mycmakeargs[@]}"
454 + -DLLVM_LIBDIR_SUFFIX=${libdir#lib}
455 +
456 + -DBUILD_SHARED_LIBS=ON
457 + -DLLVM_ENABLE_TIMESTAMPS=OFF
458 + -DLLVM_TARGETS_TO_BUILD="${targets}"
459 + -DLLVM_BUILD_TESTS=$(usex test)
460 +
461 + -DLLVM_ENABLE_FFI=$(usex libffi)
462 + -DLLVM_ENABLE_TERMINFO=$(usex ncurses)
463 + -DLLVM_ENABLE_ASSERTIONS=$(usex debug)
464 + -DLLVM_ENABLE_EH=ON
465 + -DLLVM_ENABLE_RTTI=ON
466 +
467 + -DWITH_POLLY=OFF # TODO
468 +
469 + -DLLVM_HOST_TRIPLE="${CHOST}"
470 +
471 + -DFFI_INCLUDE_DIR="${ffi_cflags#-I}"
472 + -DFFI_LIBRARY_DIR="${ffi_ldflags#-L}"
473 +
474 + -DHAVE_HISTEDIT_H=$(usex libedit)
475 + )
476 +
477 + if use clang; then
478 + mycmakeargs+=(
479 + -DCMAKE_DISABLE_FIND_PACKAGE_LibXml2=$(usex !xml)
480 + # libgomp support fails to find headers without explicit -I
481 + # furthermore, it provides only syntax checking
482 + -DCLANG_DEFAULT_OPENMP_RUNTIME=libomp
483 + )
484 + fi
485 +
486 + if use lldb; then
487 + mycmakeargs+=(
488 + -DLLDB_DISABLE_LIBEDIT=$(usex !libedit)
489 + -DLLDB_DISABLE_CURSES=$(usex !ncurses)
490 + -DLLDB_ENABLE_TERMINFO=$(usex ncurses)
491 + )
492 + fi
493 +
494 + if ! multilib_is_native_abi || ! use ocaml; then
495 + mycmakeargs+=(
496 + -DOCAMLFIND=NO
497 + )
498 + fi
499 +# Note: go bindings have no CMake rules at the moment
500 +# but let's kill the check in case they are introduced
501 +# if ! multilib_is_native_abi || ! use go; then
502 + mycmakeargs+=(
503 + -DGO_EXECUTABLE=GO_EXECUTABLE-NOTFOUND
504 + )
505 +# fi
506 +
507 + if multilib_is_native_abi; then
508 + mycmakeargs+=(
509 + -DLLVM_BUILD_DOCS=$(usex doc)
510 + -DLLVM_ENABLE_SPHINX=$(usex doc)
511 + -DLLVM_ENABLE_DOXYGEN=OFF
512 + -DLLVM_INSTALL_HTML="${EPREFIX}/usr/share/doc/${PF}/html"
513 + -DSPHINX_WARNINGS_AS_ERRORS=OFF
514 + -DLLVM_INSTALL_UTILS=ON
515 + )
516 +
517 + if use clang; then
518 + mycmakeargs+=(
519 + -DCLANG_INSTALL_HTML="${EPREFIX}/usr/share/doc/${PF}/clang"
520 + )
521 + fi
522 +
523 + if use gold; then
524 + mycmakeargs+=(
525 + -DLLVM_BINUTILS_INCDIR="${EPREFIX}"/usr/include
526 + )
527 + fi
528 +
529 + if use lldb; then
530 + mycmakeargs+=(
531 + -DLLDB_DISABLE_PYTHON=$(usex !python)
532 + )
533 + fi
534 +
535 + else
536 + if use clang; then
537 + mycmakeargs+=(
538 + # disable compiler-rt on non-native ABI because:
539 + # 1. it fails to configure because of -m32
540 + # 2. it is shared between ABIs so no point building
541 + # it multiple times
542 + -DLLVM_EXTERNAL_COMPILER_RT_BUILD=OFF
543 + -DLLVM_EXTERNAL_CLANG_TOOLS_EXTRA_BUILD=OFF
544 + )
545 + fi
546 + if use lldb; then
547 + mycmakeargs+=(
548 + # only run swig on native abi
549 + -DLLDB_DISABLE_PYTHON=ON
550 + )
551 + fi
552 + fi
553 +
554 + if use clang; then
555 + mycmakeargs+=(
556 + -DCLANG_ENABLE_ARCMT=$(usex static-analyzer)
557 + -DCLANG_ENABLE_STATIC_ANALYZER=$(usex static-analyzer)
558 + -DCLANG_LIBDIR_SUFFIX="${NATIVE_LIBDIR#lib}"
559 + )
560 +
561 + # -- not needed when compiler-rt is built with host compiler --
562 + # cmake passes host C*FLAGS to compiler-rt build
563 + # which is performed using clang, so we need to filter out
564 + # some flags clang does not support
565 + # (if you know some more flags that don't work, let us know)
566 + #filter-flags -msahf -frecord-gcc-switches
567 + fi
568 +
569 + cmake-utils_src_configure
570 +}
571 +
572 +multilib_src_compile() {
573 + cmake-utils_src_compile
574 + # TODO: not sure why this target is not correctly called
575 + multilib_is_native_abi && use doc && use ocaml && cmake-utils_src_make docs/ocaml_doc
576 +
577 + pax-mark m "${BUILD_DIR}"/bin/llvm-rtdyld
578 + pax-mark m "${BUILD_DIR}"/bin/lli
579 + pax-mark m "${BUILD_DIR}"/bin/lli-child-target
580 +
581 + if use test; then
582 + pax-mark m "${BUILD_DIR}"/unittests/ExecutionEngine/Orc/OrcJITTests
583 + pax-mark m "${BUILD_DIR}"/unittests/ExecutionEngine/MCJIT/MCJITTests
584 + pax-mark m "${BUILD_DIR}"/unittests/Support/SupportTests
585 + fi
586 +}
587 +
588 +multilib_src_test() {
589 + # respect TMPDIR!
590 + local -x LIT_PRESERVES_TMP=1
591 + local test_targets=( check )
592 + # clang tests won't work on non-native ABI because we skip compiler-rt
593 + multilib_is_native_abi && use clang && test_targets+=( check-clang )
594 + cmake-utils_src_make "${test_targets[@]}"
595 +}
596 +
597 +src_install() {
598 + local MULTILIB_CHOST_TOOLS=(
599 + /usr/bin/llvm-config
600 + )
601 +
602 + local MULTILIB_WRAPPED_HEADERS=(
603 + /usr/include/llvm/Config/config.h
604 + /usr/include/llvm/Config/llvm-config.h
605 + )
606 +
607 + if use clang; then
608 + # note: magic applied in multilib_src_install()!
609 + CLANG_VERSION=${PV%.*}
610 +
611 + MULTILIB_CHOST_TOOLS+=(
612 + /usr/bin/clang
613 + /usr/bin/clang++
614 + /usr/bin/clang-cl
615 + /usr/bin/clang-${CLANG_VERSION}
616 + /usr/bin/clang++-${CLANG_VERSION}
617 + /usr/bin/clang-cl-${CLANG_VERSION}
618 + )
619 +
620 + MULTILIB_WRAPPED_HEADERS+=(
621 + /usr/include/clang/Config/config.h
622 + )
623 + fi
624 +
625 + multilib-minimal_src_install
626 +}
627 +
628 +multilib_src_install() {
629 + cmake-utils_src_install
630 +
631 + if multilib_is_native_abi; then
632 + # Install man pages.
633 + use doc || doman "${WORKDIR}"/${P}-manpages/*.1
634 +
635 + # Symlink the gold plugin.
636 + if use gold; then
637 + dodir "/usr/${CHOST}/binutils-bin/lib/bfd-plugins"
638 + dosym "../../../../$(get_libdir)/LLVMgold.so" \
639 + "/usr/${CHOST}/binutils-bin/lib/bfd-plugins/LLVMgold.so"
640 + fi
641 + fi
642 +
643 + # apply CHOST and CLANG_VERSION to clang executables
644 + # they're statically linked so we don't have to worry about the lib
645 + if use clang; then
646 + local clang_tools=( clang clang++ clang-cl )
647 + local i
648 +
649 + # cmake gives us:
650 + # - clang-X.Y
651 + # - clang -> clang-X.Y
652 + # - clang++, clang-cl -> clang
653 + # we want to have:
654 + # - clang-X.Y
655 + # - clang++-X.Y, clang-cl-X.Y -> clang-X.Y
656 + # - clang, clang++, clang-cl -> clang*-X.Y
657 + # so we need to fix the two tools
658 + for i in "${clang_tools[@]:1}"; do
659 + rm "${ED%/}/usr/bin/${i}" || die
660 + dosym "clang-${CLANG_VERSION}" "/usr/bin/${i}-${CLANG_VERSION}"
661 + dosym "${i}-${CLANG_VERSION}" "/usr/bin/${i}"
662 + done
663 +
664 + # now prepend ${CHOST} and let the multilib-build.eclass symlink it
665 + if ! multilib_is_native_abi; then
666 + # non-native? let's replace it with a simple wrapper
667 + for i in "${clang_tools[@]}"; do
668 + rm "${ED%/}/usr/bin/${i}-${CLANG_VERSION}" || die
669 + cat > "${T}"/wrapper.tmp <<-_EOF_
670 + #!${EPREFIX}/bin/sh
671 + exec "${i}-${CLANG_VERSION}" $(get_abi_CFLAGS) "\${@}"
672 + _EOF_
673 + newbin "${T}"/wrapper.tmp "${i}-${CLANG_VERSION}"
674 + done
675 + fi
676 + fi
677 +}
678 +
679 +multilib_src_install_all() {
680 + insinto /usr/share/vim/vimfiles
681 + doins -r utils/vim/*/.
682 + # some users may find it useful
683 + dodoc utils/vim/vimrc
684 +
685 + if use clang; then
686 + pushd tools/clang >/dev/null || die
687 +
688 + if use static-analyzer ; then
689 + pushd tools/scan-build >/dev/null || die
690 +
691 + dobin ccc-analyzer scan-build
692 + dosym ccc-analyzer /usr/bin/c++-analyzer
693 + doman scan-build.1
694 +
695 + insinto /usr/share/llvm
696 + doins scanview.css sorttable.js
697 +
698 + popd >/dev/null || die
699 + fi
700 +
701 + if use static-analyzer ; then
702 + pushd tools/scan-view >/dev/null || die
703 +
704 + python_doscript scan-view
705 +
706 + touch __init__.py || die
707 + python_moduleinto clang
708 + python_domodule *.py Resources
709 +
710 + popd >/dev/null || die
711 + fi
712 +
713 + if use python ; then
714 + pushd bindings/python/clang >/dev/null || die
715 +
716 + python_moduleinto clang
717 + python_domodule *.py
718 +
719 + popd >/dev/null || die
720 + fi
721 +
722 + # AddressSanitizer symbolizer (currently separate)
723 + dobin "${S}"/projects/compiler-rt/lib/asan/scripts/asan_symbolize.py
724 +
725 + popd >/dev/null || die
726 +
727 + python_fix_shebang "${ED}"
728 + if use lldb && use python; then
729 + python_optimize
730 + fi
731 + fi
732 +}
733 +
734 +pkg_postinst() {
735 + if use clang; then
736 + elog "To enable OpenMP support in clang, install sys-libs/libomp"
737 + elog "and use the '-fopenmp=libomp' command line option"
738 + fi
739 +}