* [gentoo-commits] proj/musl:master commit in: sys-devel/clang/, sys-devel/clang/files/5.0.1/, ...
@ 2018-04-29 14:53 99% Anthony G. Basile
0 siblings, 0 replies; 1+ results
From: Anthony G. Basile @ 2018-04-29 14:53 UTC (permalink / raw
To: gentoo-commits
commit: e98887feeae412d2eb590c7e875fc681a8506ab4
Author: Milkey Mouse <milkeymouse <AT> meme <DOT> institute>
AuthorDate: Sat Apr 28 23:06:43 2018 +0000
Commit: Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Sun Apr 29 14:53:06 2018 +0000
URL: https://gitweb.gentoo.org/proj/musl.git/commit/?id=e98887fe
sys-devel/clang: add new package
Add clang with some musl fixes & hardened patches for a hardened/musl/clang
profile (hardened USE flag not upstreamed to main ebuild repository yet).
Package-Manager: Portage-2.3.31, Repoman-2.3.9
Manifest-Sign-Key: C6EF5A02F5647987
sys-devel/clang/Manifest | 31 ++
sys-devel/clang/clang-4.0.1.ebuild | 309 +++++++++++++++++++
sys-devel/clang/clang-5.0.1.ebuild | 333 ++++++++++++++++++++
sys-devel/clang/clang-6.0.0-r1.ebuild | 337 +++++++++++++++++++++
...rrect-values-of-ATOMIC_-_LOCK_FREE-to-mat.patch | 87 ++++++
...port-stand-alone-Sphinx-doxygen-doc-build.patch | 64 ++++
.../files/4.0.1/0003-Add-Gentoo-Linux-distro.patch | 32 ++
...st-dependencies-when-using-installed-tool.patch | 48 +++
...ang-library-dir-in-LD_LIBRARY_PATH-For-st.patch | 83 +++++
.../hardened/0001-Use-z-relro-on-Gentoo.patch | 11 +
.../0002-Enable-Stack-Protector-by-default.patch | 23 ++
.../hardened/0003-Enable-PIE-by-default.patch | 26 ++
...004-Link-with-z-now-by-default-for-Gentoo.patch | 14 +
...arch-type-to-find-compiler-rt-libraries-o.patch | 136 +++++++++
...est-Fix-clang-test-for-FreeBSD-and-NetBSD.patch | 76 +++++
.../files/5.0.1/0003-Add-Gentoo-Linux-distro.patch | 33 ++
.../files/5.0.1/darwin_prefix-include-paths.patch | 18 ++
...shared-library-path-variable-is-LD_LIBRAR.patch | 37 +++
.../hardened/0001-Use-z-relro-on-Gentoo.patch | 11 +
.../0002-Enable-Stack-Protector-by-default.patch | 25 ++
.../hardened/0003-Enable-PIE-by-default.patch | 24 ++
...04-Enable-FORTIFY_SOURCE-macro-by-default.patch | 35 +++
...005-Link-with-z-now-by-default-for-Gentoo.patch | 14 +
...d-invalidated-iterator-in-insertTargetAnd.patch | 55 ++++
...oss-DSO-CFI-Android-sanitizer-test-for-rt.patch | 30 ++
.../files/6.0.0/0003-Add-Gentoo-Linux-distro.patch | 33 ++
.../hardened/0001-Use-z-relro-on-Gentoo.patch | 11 +
.../0002-Enable-Stack-Protector-by-default.patch | 25 ++
.../hardened/0003-Enable-PIE-by-default.patch | 12 +
...04-Enable-FORTIFY_SOURCE-macro-by-default.patch | 35 +++
...005-Link-with-z-now-by-default-for-Gentoo.patch | 11 +
sys-devel/clang/metadata.xml | 35 +++
32 files changed, 2054 insertions(+)
diff --git a/sys-devel/clang/Manifest b/sys-devel/clang/Manifest
new file mode 100644
index 0000000..b6392eb
--- /dev/null
+++ b/sys-devel/clang/Manifest
@@ -0,0 +1,31 @@
+-----BEGIN PGP SIGNED MESSAGE-----
+Hash: SHA256
+
+DIST cfe-4.0.1.src.tar.xz 10933628 BLAKE2B bc1bb8875e83ccecd446a48cfa41f5c98a09d6ad24ff439a983f629711b4513b9c4bee4070f8df13b6b2a52d673b0706733a4c151ce5021a0233147debff14ac SHA512 936c9e1626b27e63a4fb11f3c0cb998eeaf9a520ad6e2bcd67cb4352e59e7781ecc700df79794f3fd70473d90b7e2ba418a39038eb0146b68e843f0705c1f964
+DIST cfe-5.0.1.src.tar.xz 11483036 BLAKE2B c4eb54cd8271b62cf7a2219db0b599b68c00b6e574d1946220efbd1633e841796e6717d6eeb35e84a6db32a731a3285b59cedeb3b1a8f3c3c502b799fdd0a720 SHA512 6619177a2ff9934fe8b15d6aa229abb8e34d0b1a75228d9efba9393daf71d6419a7256de57b31e2f9f829f71f842118556f996e86ee076f1e0a7cd394dfd31a2
+DIST cfe-6.0.0.src.tar.xz 11959224 BLAKE2B 257edbaedf72bd941b67b4aa2f152a96a37bbea72d21d22d4445152685efe40d75b9a7a39955545643e841ad6693ef12e52b207b9119098774f39e858b64bc09 SHA512 e886dd27448503bbfc7fd4f68eb089c19b2f2be4f0e5b26d3df253833f60b91d70b472a6b530063386e2252075b110ce9f5942800feddf6c34b94a75cf7bd5c6
+DIST clang-tools-extra-4.0.1.src.tar.xz 581788 BLAKE2B 52ca89eda6fe1e0fbbdc46e17f4067f03a9a9440dcdcc98811651087d0c9ab24dfe3eefb0b80a32ec41abe0766cb3e47031de61c4cff02b7d0e08c8fd03e3faa SHA512 ea26d926f428e62e76cf8a073e63ffe05645f6592e05d7717d5c257908870ae9217727d3e1578227b14eda5937085872463f1a8e99970256179c68b8a92e69e0
+DIST clang-tools-extra-5.0.1.src.tar.xz 646328 BLAKE2B 472eb1e73a17564790919ec392dddcd91f131c1cbf2a5f3cab09a9f7126d4d18ec6785ffcb3c3230eec6edc90acbe2bf859367c37f62ba77d7542f4c18b925f3 SHA512 2e6a811cccd22281f7567f5626ff0484ed1fefee4a9244a717e3ccb9516dce9e7ff315044fb10e505e91c3f1c6d2774558debb9559915d053886599bcb153d7b
+DIST clang-tools-extra-6.0.0.src.tar.xz 757680 BLAKE2B 708e21055a702c41a94f6b8673bab405f8b1339a75ec66f14c31565ef802245900bafc25e636c6e82f01e74060a6429a19442317f948011cae59af6825808343 SHA512 9c5720b8694c235ca988ef45da1d564ac06e31c0a40600b32c0b9df399693e4eba296ca43b077ed97adba085362ddb0fb94e0d28232afc3e7351820b1285061f
+DIST llvm-4.0.1.src.tar.xz 21065652 BLAKE2B 6327eed2d1feb108440f22d2581d1ff86c10a10c29793538d8d899c7e2dc83d3f7b147d3fd4bcce2bd2bf57c071b08c624aeafe40a3e7a3914506e7751727e6c SHA512 16adc39b34ddb628f81b171119a8e2a0e9138b25011e803ef0b688e2fbea116fc4953d3a1b61b90a98a75e33619f81566b7cb06a9a2ea4d04ac5e0eb303a2d1d
+DIST llvm-5.0.1-manpages.tar.bz2 94004 BLAKE2B 34eb29361ad7aa881e64d1dd2992fd89ce44adafd2521284c27b6ffe7082bc7e70458204e6f34d582b704bf7c5dad93c6a6dc41fc7abc41862aab8f5ec53ed07 SHA512 3444cc8e06009f5dd2669b92af662a1049d9294c8ca0dcf45486e1dc1aaf10160860b7856d30ad70bbe5864b21d1539316e89f5237549f5653954e23baf64334
+DIST llvm-5.0.1.src.tar.xz 23428720 BLAKE2B 3db4d33df21018d17eef0042c0d8d82a8412bd5daa99cfb5405a6ec83c5774178fa76b220e8731c2a9a64dabf898aa90fe29c685327bd63a4f078e8e94a9a77e SHA512 bee1d45fca15ce725b1f2b1339b13eb6f750a3a321cfd099075477ec25835a8ca55b5366172c4aad46592dfd8afe372349ecf264f581463d017f9cee2d63c1cb
+DIST llvm-6.0.0-manpages.tar.bz2 102668 BLAKE2B f458cbfcfdd6600f90f9bbe8cd9681de3dc11c62dbfcaa5ba7a281ad30d6367c33bebd5090c255e85a10b00b7bcb9c988d340b67f1db51982f55956acba109e9 SHA512 a7ed3e246e6488254f19dbb8484c079be39bc52f9b2fab3f736dd013683b7f46e8e036ee571dec5066c86ee7c25713608a2426555e8ad04b81891912314ee48e
+DIST llvm-6.0.0.src.tar.xz 25296048 BLAKE2B 7ea90bb63d6f26cfbc1c1ed2f243b0fcd8ad2ceb7963cf768d262cd55e9a0c71a9cfdea0333fb220faacf4540d924d2512532774dcfb52b52490ad74e38c09e0 SHA512 a71fdd5ddc46f01327ad891cfcc198febdbe10769c57f14d8a4fb7d514621ee4080e1a641200d3353c16a16731d390270499ec6cd3dc98fadc570f3eb6b52b8c
+DIST llvm-manpages-4.0.1.tar.bz2 87981 BLAKE2B 79ffd254ee5c6e09159c954913ef820f74107d4fcea5e3ed82592dc36af8fdfbf1e850547ba8bfc20aa9a5ecdd26c50329e6a6d558ae3aa5475a930789ce3e01 SHA512 d5b3213567c25db58ef364d272314a79c311a80fc21d98c09a5540af45a8190a38f489228663fe9a9b63bf0f2b952c460c4196a8fc8d6f221619f6e7ed2fc415
+-----BEGIN PGP SIGNATURE-----
+
+iQIzBAEBCAAdFiEE8JaD5QHaZGPThRiKxu9aAvVkeYcFAlrk/n0ACgkQxu9aAvVk
+eYfnng//Z+/QCuSsxtshLJLN8MkTvt64ONvg32NcKrg6Z/lfwCt6ckb30dMgsAQM
+yxBfGjWa/YhCx80ln35ic780ei4cBGebxVSxrzXvv1EgrI2MrtAw/wZJCTXf0JP2
+xMlJ+QNno6GloDjm+HTuOVt9H7PF4AUsSJPf4eIGJrzwn53JcYfGmF3p1+9xQW3z
+nPDFqApSnc9xhDeHCLqSAX0vXyQrkvWeY9AZ0hmdyM30andDS6ErdDk0wHjmq2au
+v76dh4rU2HgKqKwA0MPe9ZZsOl2KAw3QWAEHzaNrdQ8o6lopDW5TvEBBD76qhED8
+caW3bCnA318KU8el7P+Pv2+ZSTp/MdE0+wFzCCJqlHUZLFJLWVqRWMzRPVHtIUSm
+kPaW+XXz9JviD7E3dtUAtUBoTySlaSsarANpuV5Iy2hdNt4eyfTEtLUl79hTxmxw
+SUr6M1x7eRXfJiyKHOzUYrh153H2ViyaSuFpbI+99PdGN0tnYHUkJfLdw7uCkXUA
+gN+613b4xqIOHeienWbGg3Nh+qpStE+HWrwhlliYTquT4kag3eAcrBJO+Ww2ayg9
+oiRXgajWt3tRQpf8msASP8euGPwgj1kteZaUVcQ2MS+Fq9tGz4w+Vbzn2n/kU4u6
+VmArCo6oO8kudNaWcG5HisH/hRLb2U9rS7/geE2w63Z/m2ZypdU=
+=sz4o
+-----END PGP SIGNATURE-----
diff --git a/sys-devel/clang/clang-4.0.1.ebuild b/sys-devel/clang/clang-4.0.1.ebuild
new file mode 100644
index 0000000..edb31a7
--- /dev/null
+++ b/sys-devel/clang/clang-4.0.1.ebuild
@@ -0,0 +1,309 @@
+# Copyright 1999-2018 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=6
+
+: ${CMAKE_MAKEFILE_GENERATOR:=ninja}
+# (needed due to CMAKE_BUILD_TYPE != Gentoo)
+CMAKE_MIN_VERSION=3.7.0-r1
+PYTHON_COMPAT=( python2_7 )
+
+inherit cmake-utils flag-o-matic llvm multilib-minimal \
+ python-single-r1 toolchain-funcs pax-utils versionator
+
+DESCRIPTION="C language family frontend for LLVM"
+HOMEPAGE="https://llvm.org/"
+SRC_URI="https://releases.llvm.org/${PV/_//}/cfe-${PV/_/}.src.tar.xz
+ https://releases.llvm.org/${PV/_//}/clang-tools-extra-${PV/_/}.src.tar.xz
+ !doc? ( https://dev.gentoo.org/~mgorny/dist/llvm/llvm-manpages-${PV}.tar.bz2 )
+ test? ( https://releases.llvm.org/${PV/_//}/llvm-${PV/_/}.src.tar.xz )"
+
+# Keep in sync with sys-devel/llvm
+ALL_LLVM_TARGETS=( AArch64 AMDGPU ARM BPF Hexagon Lanai Mips MSP430
+ NVPTX PowerPC RISCV Sparc SystemZ X86 XCore )
+ALL_LLVM_TARGETS=( "${ALL_LLVM_TARGETS[@]/#/llvm_targets_}" )
+LLVM_TARGET_USEDEPS=${ALL_LLVM_TARGETS[@]/%/?}
+
+LICENSE="UoI-NCSA"
+SLOT="$(get_major_version)"
+KEYWORDS="amd64 ~arm64 x86"
+IUSE="debug default-compiler-rt default-libcxx doc hardened +static-analyzer
+ test xml elibc_musl kernel_FreeBSD ${ALL_LLVM_TARGETS[*]}"
+
+RDEPEND="
+ ~sys-devel/llvm-${PV}:${SLOT}=[debug=,${LLVM_TARGET_USEDEPS// /,},${MULTILIB_USEDEP}]
+ static-analyzer? ( dev-lang/perl:* )
+ xml? ( dev-libs/libxml2:2=[${MULTILIB_USEDEP}] )
+ ${PYTHON_DEPS}"
+# configparser-3.2 breaks the build (3.3 or none at all are fine)
+DEPEND="${RDEPEND}
+ doc? ( dev-python/sphinx )
+ xml? ( virtual/pkgconfig )
+ !!<dev-python/configparser-3.3.0.2
+ ${PYTHON_DEPS}"
+RDEPEND="${RDEPEND}
+ !<sys-devel/llvm-4.0.0_rc:0
+ !sys-devel/clang:0"
+PDEPEND="
+ ~sys-devel/clang-runtime-${PV}
+ default-compiler-rt? ( =sys-libs/compiler-rt-${PV%_*}* )
+ default-libcxx? ( >=sys-libs/libcxx-${PV} )"
+
+REQUIRED_USE="${PYTHON_REQUIRED_USE}
+ || ( ${ALL_LLVM_TARGETS[*]} )"
+
+# We need extra level of indirection for CLANG_RESOURCE_DIR
+S=${WORKDIR}/x/y/cfe-${PV/_/}.src
+
+# least intrusive of all
+CMAKE_BUILD_TYPE=RelWithDebInfo
+
+# Multilib notes:
+# 1. ABI_* flags control ABIs libclang* is built for only.
+# 2. clang is always capable of compiling code for all ABIs for enabled
+# target. However, you will need appropriate crt* files (installed
+# e.g. by sys-devel/gcc and sys-libs/glibc).
+# 3. ${CHOST}-clang wrappers are always installed for all ABIs included
+# in the current profile (i.e. alike supported by sys-devel/gcc).
+#
+# Therefore: use sys-devel/clang[${MULTILIB_USEDEP}] only if you need
+# multilib clang* libraries (not runtime, not wrappers).
+
+pkg_setup() {
+ LLVM_MAX_SLOT=${SLOT} llvm_pkg_setup
+ python-single-r1_pkg_setup
+}
+
+src_unpack() {
+ # create extra parent dirs for CLANG_RESOURCE_DIR
+ mkdir -p x/y || die
+ cd x/y || die
+
+ default
+
+ mv clang-tools-extra-*.src "${S}"/tools/extra || die
+ if use test; then
+ mv llvm-*.src "${WORKDIR}"/llvm || die
+ fi
+}
+
+src_prepare() {
+ # fix finding compiler-rt libs
+ eapply "${FILESDIR}"/5.0.1/0001-Driver-Use-arch-type-to-find-compiler-rt-libraries-o.patch
+
+ # fix stand-alone doc build
+ eapply "${FILESDIR}"/4.0.1/0002-cmake-Support-stand-alone-Sphinx-doxygen-doc-build.patch
+
+ # fix value of ATOMIC_*_LOCK_FREE
+ # (backport, temporary reverted upstream because of FreeBSD issues)
+ eapply "${FILESDIR}"/4.0.1/0001-Frontend-Correct-values-of-ATOMIC_-_LOCK_FREE-to-mat.patch
+
+ # only used in hardened patches at the moment
+ eapply "${FILESDIR}"/4.0.1/0003-Add-Gentoo-Linux-distro.patch
+
+ cd tools/extra || die
+ # fix stand-alone test build for extra tools
+ eapply "${FILESDIR}"/4.0.1/extra/0001-test-Fix-test-dependencies-when-using-installed-tool.patch
+ eapply "${FILESDIR}"/4.0.1/extra/0002-test-Fix-clang-library-dir-in-LD_LIBRARY_PATH-For-st.patch
+ cd - >/dev/null || die
+
+ if use hardened; then
+ eapply "${FILESDIR}"/4.0.1/hardened/0001-Use-z-relro-on-Gentoo.patch
+ eapply "${FILESDIR}"/4.0.1/hardened/0002-Enable-Stack-Protector-by-default.patch
+ eapply "${FILESDIR}"/4.0.1/hardened/0003-Enable-PIE-by-default.patch
+ eapply "${FILESDIR}"/4.0.1/hardened/0004-Link-with-z-now-by-default-for-Gentoo.patch
+ fi
+
+ # User patches
+ cmake-utils_src_prepare
+}
+
+multilib_src_configure() {
+ local llvm_version=$(llvm-config --version) || die
+ local clang_version=$(get_version_component_range 1-3 "${llvm_version}")
+
+ local mycmakeargs=(
+ # ensure that the correct llvm-config is used
+ -DLLVM_CONFIG="$(type -P "${CHOST}-llvm-config")"
+ -DCMAKE_INSTALL_PREFIX="${EPREFIX}/usr/lib/llvm/${SLOT}"
+ -DCMAKE_INSTALL_MANDIR="${EPREFIX}/usr/lib/llvm/${SLOT}/share/man"
+ # relative to bindir
+ -DCLANG_RESOURCE_DIR="../../../../lib/clang/${clang_version}"
+
+ -DBUILD_SHARED_LIBS=ON
+ -DLLVM_TARGETS_TO_BUILD="${LLVM_TARGETS// /;}"
+ -DLLVM_BUILD_TESTS=$(usex test)
+
+ # these are not propagated reliably, so redefine them
+ -DLLVM_ENABLE_EH=ON
+ -DLLVM_ENABLE_RTTI=ON
+
+ -DCMAKE_DISABLE_FIND_PACKAGE_LibXml2=$(usex !xml)
+ # libgomp support fails to find headers without explicit -I
+ # furthermore, it provides only syntax checking
+ -DCLANG_DEFAULT_OPENMP_RUNTIME=libomp
+
+ # override default stdlib and rtlib
+ -DCLANG_DEFAULT_CXX_STDLIB=$(usex default-libcxx libc++ "")
+ -DCLANG_DEFAULT_RTLIB=$(usex default-compiler-rt compiler-rt "")
+
+ -DCLANG_ENABLE_ARCMT=$(usex static-analyzer)
+ -DCLANG_ENABLE_STATIC_ANALYZER=$(usex static-analyzer)
+ )
+ use test && mycmakeargs+=(
+ -DLLVM_MAIN_SRC_DIR="${WORKDIR}/llvm"
+ )
+
+ if multilib_is_native_abi; then
+ mycmakeargs+=(
+ -DLLVM_BUILD_DOCS=$(usex doc)
+ -DLLVM_ENABLE_SPHINX=$(usex doc)
+ -DLLVM_ENABLE_DOXYGEN=OFF
+
+ # workaround pthread
+ -DPTHREAD_LIB=-pthread
+ )
+ use doc && mycmakeargs+=(
+ -DCLANG_INSTALL_SPHINX_HTML_DIR="${EPREFIX}/usr/share/doc/${PF}/html"
+ -DCLANG-TOOLS_INSTALL_SPHINX_HTML_DIR="${EPREFIX}/usr/share/doc/${PF}/tools-extra"
+ -DSPHINX_WARNINGS_AS_ERRORS=OFF
+ )
+ else
+ mycmakeargs+=(
+ -DLLVM_TOOL_CLANG_TOOLS_EXTRA_BUILD=OFF
+ )
+ fi
+
+ if [[ -n ${EPREFIX} ]]; then
+ mycmakeargs+=(
+ -DGCC_INSTALL_PREFIX="${EPREFIX}/usr"
+ )
+ fi
+
+ if tc-is-cross-compiler; then
+ [[ -x "/usr/bin/clang-tblgen" ]] \
+ || die "/usr/bin/clang-tblgen not found or usable"
+ mycmakeargs+=(
+ -DCMAKE_CROSSCOMPILING=ON
+ -DCLANG_TABLEGEN=/usr/bin/clang-tblgen
+ )
+ fi
+
+ # LLVM_ENABLE_ASSERTIONS=NO does not guarantee this for us, #614844
+ use debug || local -x CPPFLAGS="${CPPFLAGS} -DNDEBUG"
+ cmake-utils_src_configure
+}
+
+multilib_src_compile() {
+ cmake-utils_src_compile
+
+ # provide a symlink for tests
+ if [[ ! -L ${WORKDIR}/lib/clang ]]; then
+ mkdir -p "${WORKDIR}"/lib || die
+ ln -s "${BUILD_DIR}/$(get_libdir)/clang" "${WORKDIR}"/lib/clang || die
+ fi
+}
+
+multilib_src_test() {
+ # respect TMPDIR!
+ local -x LIT_PRESERVES_TMP=1
+ cmake-utils_src_make check-clang
+ # clang-tidy requires [static-analyzer] and tests are not split
+ # correctly, so they are all disabled when static-analyzer is off
+ if multilib_is_native_abi && use static-analyzer; then
+ cmake-utils_src_make check-clang-tools
+ fi
+}
+
+src_install() {
+ MULTILIB_WRAPPED_HEADERS=(
+ /usr/include/clang/Config/config.h
+ )
+
+ multilib-minimal_src_install
+
+ # Move runtime headers to /usr/lib/clang, where they belong
+ mv "${ED%/}"/usr/include/clangrt "${ED%/}"/usr/lib/clang || die
+ # move (remaining) wrapped headers back
+ mv "${ED%/}"/usr/include "${ED%/}"/usr/lib/llvm/${SLOT}/include || die
+
+ # Apply CHOST and version suffix to clang tools
+ # note: we use two version components here (vs 3 in runtime path)
+ local llvm_version=$(llvm-config --version) || die
+ local clang_version=$(get_version_component_range 1-2 "${llvm_version}")
+ local clang_full_version=$(get_version_component_range 1-3 "${llvm_version}")
+ local clang_tools=( clang clang++ clang-cl clang-cpp )
+ local abi i
+
+ # cmake gives us:
+ # - clang-X.Y
+ # - clang -> clang-X.Y
+ # - clang++, clang-cl, clang-cpp -> clang
+ # we want to have:
+ # - clang-X.Y
+ # - clang++-X.Y, clang-cl-X.Y, clang-cpp-X.Y -> clang-X.Y
+ # - clang, clang++, clang-cl, clang-cpp -> clang*-X.Y
+ # also in CHOST variant
+ for i in "${clang_tools[@]:1}"; do
+ rm "${ED%/}/usr/lib/llvm/${SLOT}/bin/${i}" || die
+ dosym "clang-${clang_version}" "/usr/lib/llvm/${SLOT}/bin/${i}-${clang_version}"
+ dosym "${i}-${clang_version}" "/usr/lib/llvm/${SLOT}/bin/${i}"
+ done
+
+ # now create target symlinks for all supported ABIs
+ for abi in $(get_all_abis); do
+ local abi_chost=$(get_abi_CHOST "${abi}")
+ for i in "${clang_tools[@]}"; do
+ dosym "${i}-${clang_version}" \
+ "/usr/lib/llvm/${SLOT}/bin/${abi_chost}-${i}-${clang_version}"
+ dosym "${abi_chost}-${i}-${clang_version}" \
+ "/usr/lib/llvm/${SLOT}/bin/${abi_chost}-${i}"
+ done
+ done
+
+ # Remove unnecessary headers on FreeBSD, bug #417171
+ if use kernel_FreeBSD; then
+ rm "${ED}"usr/lib/clang/${clang_full_version}/include/{std,float,iso,limits,tgmath,varargs}*.h || die
+ fi
+}
+
+multilib_src_install() {
+ cmake-utils_src_install
+
+ # move headers to /usr/include for wrapping & ABI mismatch checks
+ # (also drop the version suffix from runtime headers)
+ rm -rf "${ED%/}"/usr/include || die
+ mv "${ED%/}"/usr/lib/llvm/${SLOT}/include "${ED%/}"/usr/include || die
+ mv "${ED%/}"/usr/lib/llvm/${SLOT}/$(get_libdir)/clang "${ED%/}"/usr/include/clangrt || die
+}
+
+multilib_src_install_all() {
+ python_fix_shebang "${ED}"
+ if use static-analyzer; then
+ python_optimize "${ED}"usr/lib/llvm/${SLOT}/share/scan-view
+ fi
+
+ # install pre-generated manpages
+ if ! use doc; then
+ insinto "/usr/lib/llvm/${SLOT}/share/man/man1"
+ doins "${WORKDIR}/x/y/llvm-manpages-${PV}/clang"/*.1
+ fi
+
+ docompress "/usr/lib/llvm/${SLOT}/share/man"
+ # match 'html' non-compression
+ use doc && docompress -x "/usr/share/doc/${PF}/tools-extra"
+ # +x for some reason; TODO: investigate
+ use static-analyzer && fperms a-x "/usr/lib/llvm/${SLOT}/share/man/man1/scan-build.1"
+}
+
+pkg_postinst() {
+ if [[ ${ROOT} == / && -f ${EPREFIX}/usr/share/eselect/modules/compiler-shadow.eselect ]] ; then
+ eselect compiler-shadow update all
+ fi
+}
+
+pkg_postrm() {
+ if [[ ${ROOT} == / && -f ${EPREFIX}/usr/share/eselect/modules/compiler-shadow.eselect ]] ; then
+ eselect compiler-shadow clean all
+ fi
+}
diff --git a/sys-devel/clang/clang-5.0.1.ebuild b/sys-devel/clang/clang-5.0.1.ebuild
new file mode 100644
index 0000000..326b27e
--- /dev/null
+++ b/sys-devel/clang/clang-5.0.1.ebuild
@@ -0,0 +1,333 @@
+# Copyright 1999-2018 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=6
+
+: ${CMAKE_MAKEFILE_GENERATOR:=ninja}
+# (needed due to CMAKE_BUILD_TYPE != Gentoo)
+CMAKE_MIN_VERSION=3.7.0-r1
+PYTHON_COMPAT=( python2_7 )
+
+inherit cmake-utils eapi7-ver flag-o-matic llvm \
+ multilib-minimal pax-utils prefix python-single-r1 toolchain-funcs
+
+MY_P=cfe-${PV/_/}.src
+EXTRA_P=clang-tools-extra-${PV/_/}.src
+LLVM_P=llvm-${PV/_/}.src
+
+DESCRIPTION="C language family frontend for LLVM"
+HOMEPAGE="https://llvm.org/"
+SRC_URI="https://releases.llvm.org/${PV/_//}/${MY_P}.tar.xz
+ https://releases.llvm.org/${PV/_//}/${EXTRA_P}.tar.xz
+ test? ( https://releases.llvm.org/${PV/_//}/${LLVM_P}.tar.xz )
+ !doc? ( https://dev.gentoo.org/~mgorny/dist/llvm/llvm-${PV}-manpages.tar.bz2 )"
+
+# Keep in sync with sys-devel/llvm
+ALL_LLVM_TARGETS=( AArch64 AMDGPU ARM BPF Hexagon Lanai Mips MSP430
+ NVPTX PowerPC Sparc SystemZ X86 XCore )
+ALL_LLVM_TARGETS=( "${ALL_LLVM_TARGETS[@]/#/llvm_targets_}" )
+LLVM_TARGET_USEDEPS=${ALL_LLVM_TARGETS[@]/%/?}
+
+LICENSE="UoI-NCSA"
+SLOT="$(ver_cut 1)"
+KEYWORDS="amd64 ~arm64 x86 ~amd64-fbsd ~amd64-linux ~ppc-macos ~x64-macos ~x86-macos"
+IUSE="debug default-compiler-rt default-libcxx doc hardened +static-analyzer
+ test xml z3 kernel_FreeBSD ${ALL_LLVM_TARGETS[*]}"
+
+RDEPEND="
+ ~sys-devel/llvm-${PV}:${SLOT}=[debug=,${LLVM_TARGET_USEDEPS// /,},${MULTILIB_USEDEP}]
+ static-analyzer? (
+ dev-lang/perl:*
+ z3? ( sci-mathematics/z3:0= )
+ )
+ xml? ( dev-libs/libxml2:2=[${MULTILIB_USEDEP}] )
+ ${PYTHON_DEPS}"
+# configparser-3.2 breaks the build (3.3 or none at all are fine)
+DEPEND="${RDEPEND}
+ doc? ( dev-python/sphinx )
+ xml? ( virtual/pkgconfig )
+ !!<dev-python/configparser-3.3.0.2
+ ${PYTHON_DEPS}"
+RDEPEND="${RDEPEND}
+ !<sys-devel/llvm-4.0.0_rc:0
+ !sys-devel/clang:0"
+PDEPEND="
+ ~sys-devel/clang-runtime-${PV}
+ default-compiler-rt? ( =sys-libs/compiler-rt-${PV%_*}* )
+ default-libcxx? ( >=sys-libs/libcxx-${PV} )"
+
+REQUIRED_USE="${PYTHON_REQUIRED_USE}
+ || ( ${ALL_LLVM_TARGETS[*]} )"
+
+# We need extra level of indirection for CLANG_RESOURCE_DIR
+S=${WORKDIR}/x/y/${MY_P}
+
+# least intrusive of all
+CMAKE_BUILD_TYPE=RelWithDebInfo
+
+# Multilib notes:
+# 1. ABI_* flags control ABIs libclang* is built for only.
+# 2. clang is always capable of compiling code for all ABIs for enabled
+# target. However, you will need appropriate crt* files (installed
+# e.g. by sys-devel/gcc and sys-libs/glibc).
+# 3. ${CHOST}-clang wrappers are always installed for all ABIs included
+# in the current profile (i.e. alike supported by sys-devel/gcc).
+#
+# Therefore: use sys-devel/clang[${MULTILIB_USEDEP}] only if you need
+# multilib clang* libraries (not runtime, not wrappers).
+
+pkg_setup() {
+ LLVM_MAX_SLOT=${SLOT} llvm_pkg_setup
+ python-single-r1_pkg_setup
+}
+
+src_unpack() {
+ # create extra parent dir for CLANG_RESOURCE_DIR
+ mkdir -p x/y || die
+ cd x/y || die
+
+ einfo "Unpacking ${MY_P}.tar.xz ..."
+ tar -xf "${DISTDIR}/${MY_P}.tar.xz" || die
+ einfo "Unpacking ${EXTRA_P}.tar.xz ..."
+ tar -xf "${DISTDIR}/${EXTRA_P}.tar.xz" || die
+
+ mv "${EXTRA_P}" "${S}"/tools/extra || die
+ if use test; then
+ einfo "Unpacking parts of ${LLVM_P}.tar.xz ..."
+ tar -xf "${DISTDIR}/${LLVM_P}.tar.xz" \
+ "${LLVM_P}"/utils/{lit,unittest} || die
+ mv "${LLVM_P}" "${WORKDIR}"/llvm || die
+ fi
+
+ if ! use doc; then
+ einfo "Unpacking llvm-${PV}-manpages.tar.bz2 ..."
+ tar -xf "${DISTDIR}/llvm-${PV}-manpages.tar.bz2" || die
+ fi
+}
+
+src_prepare() {
+ # fix finding compiler-rt libs
+ eapply "${FILESDIR}"/5.0.1/0001-Driver-Use-arch-type-to-find-compiler-rt-libraries-o.patch
+ # fix setting LD_LIBRARY_PATH for tests on *BSD
+ eapply "${FILESDIR}"/5.0.1/0002-test-Fix-clang-test-for-FreeBSD-and-NetBSD.patch
+ # add Prefix include paths for Darwin
+ eapply "${FILESDIR}"/5.0.1/darwin_prefix-include-paths.patch
+ # only used in hardened patches at the moment
+ eapply "${FILESDIR}"/5.0.1/0003-Add-Gentoo-Linux-distro.patch
+
+ cd tools/extra || die
+ # fix setting LD_LIBRARY_PATH for tests on *BSD (extra part)
+ eapply "${FILESDIR}"/5.0.1/extra/0001-Assume-the-shared-library-path-variable-is-LD_LIBRAR.patch
+ cd ../.. || die
+
+ if use hardened; then
+ eapply "${FILESDIR}"/5.0.1/hardened/0001-Use-z-relro-on-Gentoo.patch
+ eapply "${FILESDIR}"/5.0.1/hardened/0002-Enable-Stack-Protector-by-default.patch
+ eapply "${FILESDIR}"/5.0.1/hardened/0003-Enable-PIE-by-default.patch
+ eapply "${FILESDIR}"/5.0.1/hardened/0004-Enable-FORTIFY_SOURCE-macro-by-default.patch
+ eapply "${FILESDIR}"/5.0.1/hardened/0005-Link-with-z-now-by-default-for-Gentoo.patch
+ fi
+
+ cmake-utils_src_prepare
+ eprefixify lib/Frontend/InitHeaderSearch.cpp
+}
+
+multilib_src_configure() {
+ local llvm_version=$(llvm-config --version) || die
+ local clang_version=$(ver_cut 1-3 "${llvm_version}")
+
+ local mycmakeargs=(
+ # ensure that the correct llvm-config is used
+ -DLLVM_CONFIG="$(type -P "${CHOST}-llvm-config")"
+ -DCMAKE_INSTALL_PREFIX="${EPREFIX}/usr/lib/llvm/${SLOT}"
+ -DCMAKE_INSTALL_MANDIR="${EPREFIX}/usr/lib/llvm/${SLOT}/share/man"
+ # relative to bindir
+ -DCLANG_RESOURCE_DIR="../../../../lib/clang/${clang_version}"
+
+ -DBUILD_SHARED_LIBS=ON
+ -DLLVM_TARGETS_TO_BUILD="${LLVM_TARGETS// /;}"
+ -DLLVM_BUILD_TESTS=$(usex test)
+
+ # these are not propagated reliably, so redefine them
+ -DLLVM_ENABLE_EH=ON
+ -DLLVM_ENABLE_RTTI=ON
+
+ -DCMAKE_DISABLE_FIND_PACKAGE_LibXml2=$(usex !xml)
+ # libgomp support fails to find headers without explicit -I
+ # furthermore, it provides only syntax checking
+ -DCLANG_DEFAULT_OPENMP_RUNTIME=libomp
+
+ # override default stdlib and rtlib
+ -DCLANG_DEFAULT_CXX_STDLIB=$(usex default-libcxx libc++ "")
+ -DCLANG_DEFAULT_RTLIB=$(usex default-compiler-rt compiler-rt "")
+
+ -DCLANG_ENABLE_ARCMT=$(usex static-analyzer)
+ -DCLANG_ENABLE_STATIC_ANALYZER=$(usex static-analyzer)
+ # z3 is not multilib-friendly
+ -DCLANG_ANALYZER_BUILD_Z3=$(multilib_native_usex z3)
+ )
+ use test && mycmakeargs+=(
+ -DLLVM_MAIN_SRC_DIR="${WORKDIR}/llvm"
+ )
+
+ if multilib_is_native_abi; then
+ mycmakeargs+=(
+ # normally copied from LLVM_INCLUDE_DOCS but the latter
+ # is lacking value in stand-alone builds
+ -DCLANG_INCLUDE_DOCS=$(usex doc)
+ -DCLANG_TOOLS_EXTRA_INCLUDE_DOCS=$(usex doc)
+ )
+ use doc && mycmakeargs+=(
+ -DLLVM_BUILD_DOCS=ON
+ -DLLVM_ENABLE_SPHINX=ON
+ -DCLANG_INSTALL_SPHINX_HTML_DIR="${EPREFIX}/usr/share/doc/${PF}/html"
+ -DCLANG-TOOLS_INSTALL_SPHINX_HTML_DIR="${EPREFIX}/usr/share/doc/${PF}/tools-extra"
+ -DSPHINX_WARNINGS_AS_ERRORS=OFF
+ )
+ use z3 && mycmakeargs+=(
+ -DZ3_INCLUDE_DIR="${EPREFIX}/usr/include/z3"
+ )
+ else
+ mycmakeargs+=(
+ -DLLVM_TOOL_CLANG_TOOLS_EXTRA_BUILD=OFF
+ )
+ fi
+
+ if [[ -n ${EPREFIX} ]]; then
+ mycmakeargs+=(
+ -DGCC_INSTALL_PREFIX="${EPREFIX}/usr"
+ )
+ fi
+
+ if tc-is-cross-compiler; then
+ [[ -x "/usr/bin/clang-tblgen" ]] \
+ || die "/usr/bin/clang-tblgen not found or usable"
+ mycmakeargs+=(
+ -DCMAKE_CROSSCOMPILING=ON
+ -DCLANG_TABLEGEN=/usr/bin/clang-tblgen
+ )
+ fi
+
+ # LLVM_ENABLE_ASSERTIONS=NO does not guarantee this for us, #614844
+ use debug || local -x CPPFLAGS="${CPPFLAGS} -DNDEBUG"
+ cmake-utils_src_configure
+}
+
+multilib_src_compile() {
+ cmake-utils_src_compile
+
+ # provide a symlink for tests
+ if [[ ! -L ${WORKDIR}/lib/clang ]]; then
+ mkdir -p "${WORKDIR}"/lib || die
+ ln -s "${BUILD_DIR}/$(get_libdir)/clang" "${WORKDIR}"/lib/clang || die
+ fi
+}
+
+multilib_src_test() {
+ # respect TMPDIR!
+ local -x LIT_PRESERVES_TMP=1
+ cmake-utils_src_make check-clang
+ # clang-tidy requires [static-analyzer] and tests are not split
+ # correctly, so they are all disabled when static-analyzer is off
+ if multilib_is_native_abi && use static-analyzer; then
+ cmake-utils_src_make check-clang-tools
+ fi
+}
+
+src_install() {
+ MULTILIB_WRAPPED_HEADERS=(
+ /usr/include/clang/Config/config.h
+ )
+
+ multilib-minimal_src_install
+
+ # Move runtime headers to /usr/lib/clang, where they belong
+ mv "${ED%/}"/usr/include/clangrt "${ED%/}"/usr/lib/clang || die
+ # move (remaining) wrapped headers back
+ mv "${ED%/}"/usr/include "${ED%/}"/usr/lib/llvm/${SLOT}/include || die
+
+ # Apply CHOST and version suffix to clang tools
+ # note: we use two version components here (vs 3 in runtime path)
+ local llvm_version=$(llvm-config --version) || die
+ local clang_version=$(ver_cut 1-2 "${llvm_version}")
+ local clang_full_version=$(ver_cut 1-3 "${llvm_version}")
+ local clang_tools=( clang clang++ clang-cl clang-cpp )
+ local abi i
+
+ # cmake gives us:
+ # - clang-X.Y
+ # - clang -> clang-X.Y
+ # - clang++, clang-cl, clang-cpp -> clang
+ # we want to have:
+ # - clang-X.Y
+ # - clang++-X.Y, clang-cl-X.Y, clang-cpp-X.Y -> clang-X.Y
+ # - clang, clang++, clang-cl, clang-cpp -> clang*-X.Y
+ # also in CHOST variant
+ for i in "${clang_tools[@]:1}"; do
+ rm "${ED%/}/usr/lib/llvm/${SLOT}/bin/${i}" || die
+ dosym "clang-${clang_version}" "/usr/lib/llvm/${SLOT}/bin/${i}-${clang_version}"
+ dosym "${i}-${clang_version}" "/usr/lib/llvm/${SLOT}/bin/${i}"
+ done
+
+ # now create target symlinks for all supported ABIs
+ for abi in $(get_all_abis); do
+ local abi_chost=$(get_abi_CHOST "${abi}")
+ for i in "${clang_tools[@]}"; do
+ dosym "${i}-${clang_version}" \
+ "/usr/lib/llvm/${SLOT}/bin/${abi_chost}-${i}-${clang_version}"
+ dosym "${abi_chost}-${i}-${clang_version}" \
+ "/usr/lib/llvm/${SLOT}/bin/${abi_chost}-${i}"
+ done
+ done
+
+ # Remove unnecessary headers on FreeBSD, bug #417171
+ if use kernel_FreeBSD; then
+ rm "${ED}"usr/lib/clang/${clang_full_version}/include/{std,float,iso,limits,tgmath,varargs}*.h || die
+ fi
+}
+
+multilib_src_install() {
+ cmake-utils_src_install
+
+ # move headers to /usr/include for wrapping & ABI mismatch checks
+ # (also drop the version suffix from runtime headers)
+ rm -rf "${ED%/}"/usr/include || die
+ mv "${ED%/}"/usr/lib/llvm/${SLOT}/include "${ED%/}"/usr/include || die
+ mv "${ED%/}"/usr/lib/llvm/${SLOT}/$(get_libdir)/clang "${ED%/}"/usr/include/clangrt || die
+}
+
+multilib_src_install_all() {
+ python_fix_shebang "${ED}"
+ if use static-analyzer; then
+ python_optimize "${ED}"usr/lib/llvm/${SLOT}/share/scan-view
+ fi
+
+ # install pre-generated manpages
+ if ! use doc; then
+ insinto "/usr/lib/llvm/${SLOT}/share/man/man1"
+ doins "${WORKDIR}/x/y/llvm-${PV}-manpages/clang"/*.1
+ fi
+
+ docompress "/usr/lib/llvm/${SLOT}/share/man"
+ # match 'html' non-compression
+ use doc && docompress -x "/usr/share/doc/${PF}/tools-extra"
+ # +x for some reason; TODO: investigate
+ use static-analyzer && fperms a-x "/usr/lib/llvm/${SLOT}/share/man/man1/scan-build.1"
+}
+
+pkg_postinst() {
+ if [[ ${ROOT} == / && -f ${EPREFIX}/usr/share/eselect/modules/compiler-shadow.eselect ]] ; then
+ eselect compiler-shadow update all
+ fi
+
+ elog "You can find additional utility scripts in:"
+ elog " ${EROOT}/usr/lib/llvm/${SLOT}/share/clang"
+ elog "To use these scripts, you will need Python 2.7. Some of them are vim"
+ elog "integration scripts (with instructions inside)."
+}
+
+pkg_postrm() {
+ if [[ ${ROOT} == / && -f ${EPREFIX}/usr/share/eselect/modules/compiler-shadow.eselect ]] ; then
+ eselect compiler-shadow clean all
+ fi
+}
diff --git a/sys-devel/clang/clang-6.0.0-r1.ebuild b/sys-devel/clang/clang-6.0.0-r1.ebuild
new file mode 100644
index 0000000..fc14879
--- /dev/null
+++ b/sys-devel/clang/clang-6.0.0-r1.ebuild
@@ -0,0 +1,337 @@
+# Copyright 1999-2018 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=6
+
+: ${CMAKE_MAKEFILE_GENERATOR:=ninja}
+# (needed due to CMAKE_BUILD_TYPE != Gentoo)
+CMAKE_MIN_VERSION=3.7.0-r1
+PYTHON_COMPAT=( python2_7 )
+
+inherit cmake-utils eapi7-ver flag-o-matic llvm \
+ multilib-minimal multiprocessing pax-utils prefix python-single-r1 \
+ toolchain-funcs
+
+MY_P=cfe-${PV/_/}.src
+EXTRA_P=clang-tools-extra-${PV/_/}.src
+LLVM_P=llvm-${PV/_/}.src
+
+DESCRIPTION="C language family frontend for LLVM"
+HOMEPAGE="https://llvm.org/"
+SRC_URI="https://releases.llvm.org/${PV/_//}/${MY_P}.tar.xz
+ https://releases.llvm.org/${PV/_//}/${EXTRA_P}.tar.xz
+ test? ( https://releases.llvm.org/${PV/_//}/${LLVM_P}.tar.xz )
+ !doc? ( https://dev.gentoo.org/~mgorny/dist/llvm/llvm-${PV}-manpages.tar.bz2 )"
+
+# Keep in sync with sys-devel/llvm
+ALL_LLVM_TARGETS=( AArch64 AMDGPU ARM BPF Hexagon Lanai Mips MSP430
+ NVPTX PowerPC Sparc SystemZ X86 XCore )
+ALL_LLVM_TARGETS=( "${ALL_LLVM_TARGETS[@]/#/llvm_targets_}" )
+LLVM_TARGET_USEDEPS=${ALL_LLVM_TARGETS[@]/%/?}
+
+LICENSE="UoI-NCSA"
+SLOT="$(ver_cut 1)"
+KEYWORDS="~amd64 ~arm64 ~x86 ~amd64-fbsd ~amd64-linux ~ppc-macos ~x64-macos ~x86-macos"
+IUSE="debug default-compiler-rt default-libcxx doc hardened +static-analyzer
+ test xml z3 kernel_FreeBSD ${ALL_LLVM_TARGETS[*]}"
+RESTRICT="!test? ( test )"
+
+RDEPEND="
+ ~sys-devel/llvm-${PV}:${SLOT}=[debug=,${LLVM_TARGET_USEDEPS// /,},${MULTILIB_USEDEP}]
+ static-analyzer? (
+ dev-lang/perl:*
+ z3? ( sci-mathematics/z3:0= )
+ )
+ xml? ( dev-libs/libxml2:2=[${MULTILIB_USEDEP}] )
+ ${PYTHON_DEPS}"
+# configparser-3.2 breaks the build (3.3 or none at all are fine)
+DEPEND="${RDEPEND}
+ doc? ( dev-python/sphinx )
+ xml? ( virtual/pkgconfig )
+ !!<dev-python/configparser-3.3.0.2
+ ${PYTHON_DEPS}"
+RDEPEND="${RDEPEND}
+ !<sys-devel/llvm-4.0.0_rc:0
+ !sys-devel/clang:0"
+PDEPEND="
+ sys-devel/clang-common
+ ~sys-devel/clang-runtime-${PV}
+ default-compiler-rt? ( =sys-libs/compiler-rt-${PV%_*}* )
+ default-libcxx? ( >=sys-libs/libcxx-${PV} )"
+
+REQUIRED_USE="${PYTHON_REQUIRED_USE}
+ || ( ${ALL_LLVM_TARGETS[*]} )"
+
+# We need extra level of indirection for CLANG_RESOURCE_DIR
+S=${WORKDIR}/x/y/${MY_P}
+
+# least intrusive of all
+CMAKE_BUILD_TYPE=RelWithDebInfo
+
+PATCHES=(
+ # add Prefix include paths for Darwin
+ "${FILESDIR}"/5.0.1/darwin_prefix-include-paths.patch
+
+ # fix Driver crash with CHOST prefix and long command-line
+ # https://bugs.gentoo.org/650082
+ "${FILESDIR}"/6.0.0/0001-Driver-Avoid-invalidated-iterator-in-insertTargetAnd.patch
+ # fix test failure with default-compiler-rt
+ # https://bugs.gentoo.org/650316
+ "${FILESDIR}"/6.0.0/0002-test-Fix-Cross-DSO-CFI-Android-sanitizer-test-for-rt.patch
+
+ # IsGentooLinux() is only used in hardened patches at the moment
+ "${FILESDIR}"/6.0.0/0003-Add-Gentoo-Linux-distro.patch
+)
+HARDENED_PATCHES=(
+ "${FILESDIR}"/6.0.0/hardened/0001-Use-z-relro-on-Gentoo.patch
+ "${FILESDIR}"/6.0.0/hardened/0002-Enable-Stack-Protector-by-default.patch
+ "${FILESDIR}"/6.0.0/hardened/0003-Enable-PIE-by-default.patch
+ "${FILESDIR}"/6.0.0/hardened/0004-Enable-FORTIFY_SOURCE-macro-by-default.patch
+ "${FILESDIR}"/6.0.0/hardened/0005-Link-with-z-now-by-default-for-Gentoo.patch
+)
+
+# Multilib notes:
+# 1. ABI_* flags control ABIs libclang* is built for only.
+# 2. clang is always capable of compiling code for all ABIs for enabled
+# target. However, you will need appropriate crt* files (installed
+# e.g. by sys-devel/gcc and sys-libs/glibc).
+# 3. ${CHOST}-clang wrappers are always installed for all ABIs included
+# in the current profile (i.e. alike supported by sys-devel/gcc).
+#
+# Therefore: use sys-devel/clang[${MULTILIB_USEDEP}] only if you need
+# multilib clang* libraries (not runtime, not wrappers).
+
+pkg_setup() {
+ LLVM_MAX_SLOT=${SLOT} llvm_pkg_setup
+ python-single-r1_pkg_setup
+}
+
+src_unpack() {
+ # create extra parent dir for CLANG_RESOURCE_DIR
+ mkdir -p x/y || die
+ cd x/y || die
+
+ einfo "Unpacking ${MY_P}.tar.xz ..."
+ tar -xf "${DISTDIR}/${MY_P}.tar.xz" || die
+ einfo "Unpacking ${EXTRA_P}.tar.xz ..."
+ tar -xf "${DISTDIR}/${EXTRA_P}.tar.xz" || die
+
+ mv "${EXTRA_P}" "${S}"/tools/extra || die
+ if use test; then
+ einfo "Unpacking parts of ${LLVM_P}.tar.xz ..."
+ tar -xf "${DISTDIR}/${LLVM_P}.tar.xz" \
+ "${LLVM_P}"/utils/{lit,llvm-lit,unittest} || die
+ mv "${LLVM_P}" "${WORKDIR}"/llvm || die
+ fi
+
+ if ! use doc; then
+ einfo "Unpacking llvm-${PV}-manpages.tar.bz2 ..."
+ tar -xf "${DISTDIR}/llvm-${PV}-manpages.tar.bz2" || die
+ fi
+}
+
+src_prepare() {
+ use hardened && eapply "${HARDENED_PATCHES[@]}"
+
+ cmake-utils_src_prepare
+ eprefixify lib/Frontend/InitHeaderSearch.cpp
+}
+
+multilib_src_configure() {
+ local llvm_version=$(llvm-config --version) || die
+ local clang_version=$(ver_cut 1-3 "${llvm_version}")
+
+ local mycmakeargs=(
+ # ensure that the correct llvm-config is used
+ -DLLVM_CONFIG="$(type -P "${CHOST}-llvm-config")"
+ -DCMAKE_INSTALL_PREFIX="${EPREFIX}/usr/lib/llvm/${SLOT}"
+ -DCMAKE_INSTALL_MANDIR="${EPREFIX}/usr/lib/llvm/${SLOT}/share/man"
+ # relative to bindir
+ -DCLANG_RESOURCE_DIR="../../../../lib/clang/${clang_version}"
+
+ -DBUILD_SHARED_LIBS=ON
+ -DLLVM_TARGETS_TO_BUILD="${LLVM_TARGETS// /;}"
+ -DLLVM_BUILD_TESTS=$(usex test)
+
+ # these are not propagated reliably, so redefine them
+ -DLLVM_ENABLE_EH=ON
+ -DLLVM_ENABLE_RTTI=ON
+
+ -DCMAKE_DISABLE_FIND_PACKAGE_LibXml2=$(usex !xml)
+ # libgomp support fails to find headers without explicit -I
+ # furthermore, it provides only syntax checking
+ -DCLANG_DEFAULT_OPENMP_RUNTIME=libomp
+
+ # override default stdlib and rtlib
+ -DCLANG_DEFAULT_CXX_STDLIB=$(usex default-libcxx libc++ "")
+ -DCLANG_DEFAULT_RTLIB=$(usex default-compiler-rt compiler-rt "")
+
+ -DCLANG_ENABLE_ARCMT=$(usex static-analyzer)
+ -DCLANG_ENABLE_STATIC_ANALYZER=$(usex static-analyzer)
+ # z3 is not multilib-friendly
+ -DCLANG_ANALYZER_BUILD_Z3=$(multilib_native_usex z3)
+ )
+ use test && mycmakeargs+=(
+ -DLLVM_MAIN_SRC_DIR="${WORKDIR}/llvm"
+ -DLLVM_LIT_ARGS="-vv;-j;${LIT_JOBS:-$(makeopts_jobs "${MAKEOPTS}" "$(get_nproc)")}"
+ )
+
+ if multilib_is_native_abi; then
+ mycmakeargs+=(
+ # normally copied from LLVM_INCLUDE_DOCS but the latter
+ # is lacking value in stand-alone builds
+ -DCLANG_INCLUDE_DOCS=$(usex doc)
+ -DCLANG_TOOLS_EXTRA_INCLUDE_DOCS=$(usex doc)
+ )
+ use doc && mycmakeargs+=(
+ -DLLVM_BUILD_DOCS=ON
+ -DLLVM_ENABLE_SPHINX=ON
+ -DCLANG_INSTALL_SPHINX_HTML_DIR="${EPREFIX}/usr/share/doc/${PF}/html"
+ -DCLANG-TOOLS_INSTALL_SPHINX_HTML_DIR="${EPREFIX}/usr/share/doc/${PF}/tools-extra"
+ -DSPHINX_WARNINGS_AS_ERRORS=OFF
+ )
+ use z3 && mycmakeargs+=(
+ -DZ3_INCLUDE_DIR="${EPREFIX}/usr/include/z3"
+ )
+ else
+ mycmakeargs+=(
+ -DLLVM_TOOL_CLANG_TOOLS_EXTRA_BUILD=OFF
+ )
+ fi
+
+ if [[ -n ${EPREFIX} ]]; then
+ mycmakeargs+=(
+ -DGCC_INSTALL_PREFIX="${EPREFIX}/usr"
+ )
+ fi
+
+ if tc-is-cross-compiler; then
+ [[ -x "/usr/bin/clang-tblgen" ]] \
+ || die "/usr/bin/clang-tblgen not found or usable"
+ mycmakeargs+=(
+ -DCMAKE_CROSSCOMPILING=ON
+ -DCLANG_TABLEGEN=/usr/bin/clang-tblgen
+ )
+ fi
+
+ # LLVM_ENABLE_ASSERTIONS=NO does not guarantee this for us, #614844
+ use debug || local -x CPPFLAGS="${CPPFLAGS} -DNDEBUG"
+ cmake-utils_src_configure
+}
+
+multilib_src_compile() {
+ cmake-utils_src_compile
+
+ # provide a symlink for tests
+ if [[ ! -L ${WORKDIR}/lib/clang ]]; then
+ mkdir -p "${WORKDIR}"/lib || die
+ ln -s "${BUILD_DIR}/$(get_libdir)/clang" "${WORKDIR}"/lib/clang || die
+ fi
+}
+
+multilib_src_test() {
+ # respect TMPDIR!
+ local -x LIT_PRESERVES_TMP=1
+ cmake-utils_src_make check-clang
+ multilib_is_native_abi && cmake-utils_src_make check-clang-tools
+}
+
+src_install() {
+ MULTILIB_WRAPPED_HEADERS=(
+ /usr/include/clang/Config/config.h
+ )
+
+ multilib-minimal_src_install
+
+ # Move runtime headers to /usr/lib/clang, where they belong
+ mv "${ED%/}"/usr/include/clangrt "${ED%/}"/usr/lib/clang || die
+ # move (remaining) wrapped headers back
+ mv "${ED%/}"/usr/include "${ED%/}"/usr/lib/llvm/${SLOT}/include || die
+
+ # Apply CHOST and version suffix to clang tools
+ # note: we use two version components here (vs 3 in runtime path)
+ local llvm_version=$(llvm-config --version) || die
+ local clang_version=$(ver_cut 1-2 "${llvm_version}")
+ local clang_full_version=$(ver_cut 1-3 "${llvm_version}")
+ local clang_tools=( clang clang++ clang-cl clang-cpp )
+ local abi i
+
+ # cmake gives us:
+ # - clang-X.Y
+ # - clang -> clang-X.Y
+ # - clang++, clang-cl, clang-cpp -> clang
+ # we want to have:
+ # - clang-X.Y
+ # - clang++-X.Y, clang-cl-X.Y, clang-cpp-X.Y -> clang-X.Y
+ # - clang, clang++, clang-cl, clang-cpp -> clang*-X.Y
+ # also in CHOST variant
+ for i in "${clang_tools[@]:1}"; do
+ rm "${ED%/}/usr/lib/llvm/${SLOT}/bin/${i}" || die
+ dosym "clang-${clang_version}" "/usr/lib/llvm/${SLOT}/bin/${i}-${clang_version}"
+ dosym "${i}-${clang_version}" "/usr/lib/llvm/${SLOT}/bin/${i}"
+ done
+
+ # now create target symlinks for all supported ABIs
+ for abi in $(get_all_abis); do
+ local abi_chost=$(get_abi_CHOST "${abi}")
+ for i in "${clang_tools[@]}"; do
+ dosym "${i}-${clang_version}" \
+ "/usr/lib/llvm/${SLOT}/bin/${abi_chost}-${i}-${clang_version}"
+ dosym "${abi_chost}-${i}-${clang_version}" \
+ "/usr/lib/llvm/${SLOT}/bin/${abi_chost}-${i}"
+ done
+ done
+
+ # Remove unnecessary headers on FreeBSD, bug #417171
+ if use kernel_FreeBSD; then
+ rm "${ED}"usr/lib/clang/${clang_full_version}/include/{std,float,iso,limits,tgmath,varargs}*.h || die
+ fi
+}
+
+multilib_src_install() {
+ cmake-utils_src_install
+
+ # move headers to /usr/include for wrapping & ABI mismatch checks
+ # (also drop the version suffix from runtime headers)
+ rm -rf "${ED%/}"/usr/include || die
+ mv "${ED%/}"/usr/lib/llvm/${SLOT}/include "${ED%/}"/usr/include || die
+ mv "${ED%/}"/usr/lib/llvm/${SLOT}/$(get_libdir)/clang "${ED%/}"/usr/include/clangrt || die
+}
+
+multilib_src_install_all() {
+ python_fix_shebang "${ED}"
+ if use static-analyzer; then
+ python_optimize "${ED}"usr/lib/llvm/${SLOT}/share/scan-view
+ fi
+
+ # install pre-generated manpages
+ if ! use doc; then
+ insinto "/usr/lib/llvm/${SLOT}/share/man/man1"
+ doins "${WORKDIR}/x/y/llvm-${PV}-manpages/clang"/*.1
+ fi
+
+ docompress "/usr/lib/llvm/${SLOT}/share/man"
+ # match 'html' non-compression
+ use doc && docompress -x "/usr/share/doc/${PF}/tools-extra"
+ # +x for some reason; TODO: investigate
+ use static-analyzer && fperms a-x "/usr/lib/llvm/${SLOT}/share/man/man1/scan-build.1"
+}
+
+pkg_postinst() {
+ if [[ ${ROOT} == / && -f ${EPREFIX}/usr/share/eselect/modules/compiler-shadow.eselect ]] ; then
+ eselect compiler-shadow update all
+ fi
+
+ elog "You can find additional utility scripts in:"
+ elog " ${EROOT}/usr/lib/llvm/${SLOT}/share/clang"
+ elog "To use these scripts, you will need Python 2.7. Some of them are vim"
+ elog "integration scripts (with instructions inside). The run-clang-tidy.py"
+ elog "scripts requires the following additional package:"
+ elog " dev-python/pyyaml"
+}
+
+pkg_postrm() {
+ if [[ ${ROOT} == / && -f ${EPREFIX}/usr/share/eselect/modules/compiler-shadow.eselect ]] ; then
+ eselect compiler-shadow clean all
+ fi
+}
diff --git a/sys-devel/clang/files/4.0.1/0001-Frontend-Correct-values-of-ATOMIC_-_LOCK_FREE-to-mat.patch b/sys-devel/clang/files/4.0.1/0001-Frontend-Correct-values-of-ATOMIC_-_LOCK_FREE-to-mat.patch
new file mode 100644
index 0000000..f52d445
--- /dev/null
+++ b/sys-devel/clang/files/4.0.1/0001-Frontend-Correct-values-of-ATOMIC_-_LOCK_FREE-to-mat.patch
@@ -0,0 +1,87 @@
+From f1ea62e93cba334828c427146cc2ca7718a9ffb3 Mon Sep 17 00:00:00 2001
+From: Michal Gorny <mgorny@gentoo.org>
+Date: Mon, 9 Jan 2017 20:54:20 +0000
+Subject: [PATCH] [Frontend] Correct values of ATOMIC_*_LOCK_FREE to match
+ builtin
+
+Correct the logic used to set ATOMIC_*_LOCK_FREE preprocessor macros not
+to rely on the ABI alignment of types. Instead, just assume all those
+types are aligned correctly by default since clang uses safe alignment
+for _Atomic types even if the underlying types are aligned to a lower
+boundary by default.
+
+For example, the 'long long' and 'double' types on x86 are aligned to
+32-bit boundary by default. However, '_Atomic long long' and '_Atomic
+double' are aligned to 64-bit boundary, therefore satisfying
+the requirements of lock-free atomic operations.
+
+This fixes PR #19355 by correcting the value of
+__GCC_ATOMIC_LLONG_LOCK_FREE on x86, and therefore also fixing
+the assumption made in libc++ tests. This also fixes PR #30581 by
+applying a consistent logic between the functions used to implement
+both interfaces.
+
+Differential Revision: https://reviews.llvm.org/D28213
+
+git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@291477 91177308-0d34-0410-b5e6-96231b3b80d8
+---
+ lib/Frontend/InitPreprocessor.cpp | 10 ++++------
+ test/Sema/atomic-ops.c | 4 ----
+ 2 files changed, 4 insertions(+), 10 deletions(-)
+
+diff --git a/lib/Frontend/InitPreprocessor.cpp b/lib/Frontend/InitPreprocessor.cpp
+index 17603ada11..4502c92499 100644
+--- a/lib/Frontend/InitPreprocessor.cpp
++++ b/lib/Frontend/InitPreprocessor.cpp
+@@ -286,12 +286,12 @@ static void DefineFastIntType(unsigned TypeWidth, bool IsSigned,
+
+ /// Get the value the ATOMIC_*_LOCK_FREE macro should have for a type with
+ /// the specified properties.
+-static const char *getLockFreeValue(unsigned TypeWidth, unsigned TypeAlign,
+- unsigned InlineWidth) {
++static const char *getLockFreeValue(unsigned TypeWidth, unsigned InlineWidth) {
+ // Fully-aligned, power-of-2 sizes no larger than the inline
+ // width will be inlined as lock-free operations.
+- if (TypeWidth == TypeAlign && (TypeWidth & (TypeWidth - 1)) == 0 &&
+- TypeWidth <= InlineWidth)
++ // Note: we do not need to check alignment since _Atomic(T) is always
++ // appropriately-aligned in clang.
++ if ((TypeWidth & (TypeWidth - 1)) == 0 && TypeWidth <= InlineWidth)
+ return "2"; // "always lock free"
+ // We cannot be certain what operations the lib calls might be
+ // able to implement as lock-free on future processors.
+@@ -881,7 +881,6 @@ static void InitializePredefinedMacros(const TargetInfo &TI,
+ #define DEFINE_LOCK_FREE_MACRO(TYPE, Type) \
+ Builder.defineMacro("__GCC_ATOMIC_" #TYPE "_LOCK_FREE", \
+ getLockFreeValue(TI.get##Type##Width(), \
+- TI.get##Type##Align(), \
+ InlineWidthBits));
+ DEFINE_LOCK_FREE_MACRO(BOOL, Bool);
+ DEFINE_LOCK_FREE_MACRO(CHAR, Char);
+@@ -894,7 +893,6 @@ static void InitializePredefinedMacros(const TargetInfo &TI,
+ DEFINE_LOCK_FREE_MACRO(LLONG, LongLong);
+ Builder.defineMacro("__GCC_ATOMIC_POINTER_LOCK_FREE",
+ getLockFreeValue(TI.getPointerWidth(0),
+- TI.getPointerAlign(0),
+ InlineWidthBits));
+ #undef DEFINE_LOCK_FREE_MACRO
+ }
+diff --git a/test/Sema/atomic-ops.c b/test/Sema/atomic-ops.c
+index 8ebf3eaed4..d3ebdf67db 100644
+--- a/test/Sema/atomic-ops.c
++++ b/test/Sema/atomic-ops.c
+@@ -14,11 +14,7 @@ _Static_assert(__GCC_ATOMIC_WCHAR_T_LOCK_FREE == 2, "");
+ _Static_assert(__GCC_ATOMIC_SHORT_LOCK_FREE == 2, "");
+ _Static_assert(__GCC_ATOMIC_INT_LOCK_FREE == 2, "");
+ _Static_assert(__GCC_ATOMIC_LONG_LOCK_FREE == 2, "");
+-#ifdef __i386__
+-_Static_assert(__GCC_ATOMIC_LLONG_LOCK_FREE == 1, "");
+-#else
+ _Static_assert(__GCC_ATOMIC_LLONG_LOCK_FREE == 2, "");
+-#endif
+ _Static_assert(__GCC_ATOMIC_POINTER_LOCK_FREE == 2, "");
+
+ _Static_assert(__c11_atomic_is_lock_free(1), "");
+--
+2.12.0
+
diff --git a/sys-devel/clang/files/4.0.1/0002-cmake-Support-stand-alone-Sphinx-doxygen-doc-build.patch b/sys-devel/clang/files/4.0.1/0002-cmake-Support-stand-alone-Sphinx-doxygen-doc-build.patch
new file mode 100644
index 0000000..0ecd5bc
--- /dev/null
+++ b/sys-devel/clang/files/4.0.1/0002-cmake-Support-stand-alone-Sphinx-doxygen-doc-build.patch
@@ -0,0 +1,64 @@
+From 8dd12df445c9a35f7b1c0202eb7c74b954b0980d Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= <mgorny@gentoo.org>
+Date: Sun, 21 Aug 2016 23:31:55 +0200
+Subject: [PATCH 7/7] cmake: Support stand-alone Sphinx & doxygen doc build
+
+Copy the necessary options and configuration checks from LLVM to clang,
+to support stand-alone documentation builds.
+
+Patch: https://reviews.llvm.org/D23758
+---
+ CMakeLists.txt | 37 +++++++++++++++++++++++++++++++++++++
+ 1 file changed, 37 insertions(+)
+
+diff --git a/CMakeLists.txt b/CMakeLists.txt
+index 8ed8c10..3f34d8c 100644
+--- a/CMakeLists.txt
++++ b/CMakeLists.txt
+@@ -162,6 +162,43 @@ Please install Python or specify the PYTHON_EXECUTABLE CMake variable.")
+ endif()
+ endif()
+
++ option (LLVM_BUILD_DOCS "Build the llvm documentation." OFF)
++ option (LLVM_INCLUDE_DOCS "Generate build targets for llvm documentation." ON)
++ option (LLVM_ENABLE_DOXYGEN "Use doxygen to generate llvm API documentation." OFF)
++ option (LLVM_ENABLE_SPHINX "Use Sphinx to generate llvm documentation." OFF)
++
++ if (LLVM_ENABLE_DOXYGEN)
++ message(STATUS "Doxygen enabled.")
++ find_package(Doxygen REQUIRED)
++
++ if (DOXYGEN_FOUND)
++ # If we find doxygen and we want to enable doxygen by default create a
++ # global aggregate doxygen target for generating llvm and any/all
++ # subprojects doxygen documentation.
++ if (LLVM_BUILD_DOCS)
++ add_custom_target(doxygen ALL)
++ endif()
++
++ option(LLVM_DOXYGEN_EXTERNAL_SEARCH "Enable doxygen external search." OFF)
++ if (LLVM_DOXYGEN_EXTERNAL_SEARCH)
++ set(LLVM_DOXYGEN_SEARCHENGINE_URL "" CACHE STRING "URL to use for external search.")
++ set(LLVM_DOXYGEN_SEARCH_MAPPINGS "" CACHE STRING "Doxygen Search Mappings")
++ endif()
++ endif()
++ else()
++ message(STATUS "Doxygen disabled.")
++ endif()
++
++ if (LLVM_ENABLE_SPHINX)
++ message(STATUS "Sphinx enabled.")
++ find_package(Sphinx REQUIRED)
++ if (LLVM_BUILD_DOCS)
++ add_custom_target(sphinx ALL)
++ endif()
++ else()
++ message(STATUS "Sphinx disabled.")
++ endif()
++
+ set( CLANG_BUILT_STANDALONE 1 )
+ set(BACKEND_PACKAGE_STRING "LLVM ${LLVM_PACKAGE_VERSION}")
+ else()
+--
+2.9.3
+
diff --git a/sys-devel/clang/files/4.0.1/0003-Add-Gentoo-Linux-distro.patch b/sys-devel/clang/files/4.0.1/0003-Add-Gentoo-Linux-distro.patch
new file mode 100644
index 0000000..eb85ba5
--- /dev/null
+++ b/sys-devel/clang/files/4.0.1/0003-Add-Gentoo-Linux-distro.patch
@@ -0,0 +1,32 @@
+--- a/include/clang/Driver/Distro.h
++++ b/include/clang/Driver/Distro.h
+@@ -26,6 +26,7 @@
+ // NB: Releases of a particular Linux distro should be kept together
+ // in this enum, because some tests are done by integer comparison against
+ // the first and last known member in the family, e.g. IsRedHat().
++ GentooLinux,
+ ArchLinux,
+ DebianLenny,
+ DebianSqueeze,
+@@ -97,6 +98,10 @@
+ /// @name Convenience Predicates
+ /// @{
+
++ bool IsGentooLinux() const {
++ return DistroVal == GentooLinux;
++ }
++
+ bool IsRedhat() const {
+ return DistroVal == Fedora || (DistroVal >= RHEL5 && DistroVal <= RHEL7);
+ }
+--- a/lib/Driver/Distro.cpp
++++ b/lib/Driver/Distro.cpp
+@@ -128,6 +128,9 @@
+ if (VFS.exists("/etc/arch-release"))
+ return Distro::ArchLinux;
+
++ if (VFS.exists("/etc/gentoo-release"))
++ return Distro::GentooLinux;
++
+ return Distro::UnknownDistro;
+ }
diff --git a/sys-devel/clang/files/4.0.1/extra/0001-test-Fix-test-dependencies-when-using-installed-tool.patch b/sys-devel/clang/files/4.0.1/extra/0001-test-Fix-test-dependencies-when-using-installed-tool.patch
new file mode 100644
index 0000000..3779bc6
--- /dev/null
+++ b/sys-devel/clang/files/4.0.1/extra/0001-test-Fix-test-dependencies-when-using-installed-tool.patch
@@ -0,0 +1,48 @@
+From f1355920fbe819c5b1f5a870fc76cffcdd6328f0 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= <mgorny@gentoo.org>
+Date: Fri, 10 Feb 2017 22:44:53 +0100
+Subject: [PATCH 1/2] [test] Fix test dependencies when using installed tools
+
+Use the LLVM_UTILS_PROVIDED variable to determine whether test tool
+dependencies should be exposed for clang-tools-extra tests. If clang is
+being built stand-alone and LLVM test tools (FileCheck, count and not)
+are installed, the top-level CMakeLists.txt of clang sets this variable
+to indicate that they will not be built as a part of this build,
+and therefore no dependencies should be emitted for them. This fixes
+the dependency errors when building clang stand-alone with tests
+enabled.
+---
+ test/CMakeLists.txt | 10 +++++++---
+ 1 file changed, 7 insertions(+), 3 deletions(-)
+
+diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
+index a852ef60..c26bd5c4 100644
+--- a/test/CMakeLists.txt
++++ b/test/CMakeLists.txt
+@@ -31,9 +31,6 @@ if(CLANG_TOOLS_TEST_USE_VG)
+ endif()
+
+ set(CLANG_TOOLS_TEST_DEPS
+- # Base line deps.
+- FileCheck count not
+-
+ # clang-tidy tests require it.
+ clang-headers
+
+@@ -58,6 +55,13 @@ set(CLANG_TOOLS_TEST_DEPS
+ ExtraToolsUnitTests
+ )
+
++if(NOT LLVM_UTILS_PROVIDED)
++ list(APPEND CLANG_TOOLS_TEST_DEPS
++ # Base line deps.
++ FileCheck count not
++ )
++endif()
++
+ add_lit_testsuite(check-clang-tools "Running the Clang extra tools' regression tests"
+ ${CMAKE_CURRENT_BINARY_DIR}
+ DEPENDS ${CLANG_TOOLS_TEST_DEPS}
+--
+2.12.0
+
diff --git a/sys-devel/clang/files/4.0.1/extra/0002-test-Fix-clang-library-dir-in-LD_LIBRARY_PATH-For-st.patch b/sys-devel/clang/files/4.0.1/extra/0002-test-Fix-clang-library-dir-in-LD_LIBRARY_PATH-For-st.patch
new file mode 100644
index 0000000..22f6d56
--- /dev/null
+++ b/sys-devel/clang/files/4.0.1/extra/0002-test-Fix-clang-library-dir-in-LD_LIBRARY_PATH-For-st.patch
@@ -0,0 +1,83 @@
+From f3ff810e81c35133f6a7e463d860bcd4ca30be84 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= <mgorny@gentoo.org>
+Date: Sun, 19 Feb 2017 12:13:04 +0100
+Subject: [PATCH 2/2] [test] Fix clang library dir in LD_LIBRARY_PATH For
+ stand-alone build
+
+Prepend the clang library directory (determined using SHLIBDIR, alike
+in clang) to the LD_LIBRARY_PATH to ensure that just-built clang
+libraries will be used instead of a previous installed version.
+
+When a stand-alone build is performed, LLVM_LIBS_DIR contains the path
+to installed LLVM library directory. The same directory frequently
+contains a previously installed version of clang. SHLIBDIR, on the other
+hand, is always the build-tree directory, and therefore contains
+the freshly built clang libraries.
+
+In a non-stand-alone build, both paths will be the same and therefore
+including them both will not cause any issues.
+---
+ test/Unit/lit.cfg | 9 ++++++---
+ test/lit.cfg | 5 ++++-
+ test/lit.site.cfg.in | 1 +
+ 3 files changed, 11 insertions(+), 4 deletions(-)
+
+diff --git a/test/Unit/lit.cfg b/test/Unit/lit.cfg
+index ff70123c..3a1da187 100644
+--- a/test/Unit/lit.cfg
++++ b/test/Unit/lit.cfg
+@@ -41,14 +41,17 @@ elif platform.system() == 'Windows':
+ shlibpath_var = 'PATH'
+
+ # Point the dynamic loader at dynamic libraries in 'lib'.
++shlibdir = getattr(config, 'shlibdir', None)
++if not shlibdir:
++ lit_config.fatal('No shlibdir set!')
+ llvm_libs_dir = getattr(config, 'llvm_libs_dir', None)
+ if not llvm_libs_dir:
+ lit_config.fatal('No LLVM libs dir set!')
+-shlibpath = os.path.pathsep.join((llvm_libs_dir,
++shlibpath = os.path.pathsep.join((shlibdir, llvm_libs_dir,
+ config.environment.get(shlibpath_var,'')))
+
+ # Win32 seeks DLLs along %PATH%.
+-if sys.platform in ['win32', 'cygwin'] and os.path.isdir(config.shlibdir):
+- shlibpath = os.path.pathsep.join((config.shlibdir, shlibpath))
++if sys.platform in ['win32', 'cygwin'] and os.path.isdir(shlibdir):
++ shlibpath = os.path.pathsep.join((shlibdir, shlibpath))
+
+ config.environment[shlibpath_var] = shlibpath
+diff --git a/test/lit.cfg b/test/lit.cfg
+index bb592936..0e7de849 100644
+--- a/test/lit.cfg
++++ b/test/lit.cfg
+@@ -99,10 +99,13 @@ if clang_tools_binary_dir is not None:
+ clang_tools_dir, llvm_tools_dir, config.environment['PATH']))
+ config.environment['PATH'] = path
+
++ clang_libs_dir = getattr(config, 'clang_libs_dir', None)
++ if not clang_libs_dir:
++ lit_config.fatal('No Clang libs dir set!')
+ llvm_libs_dir = getattr(config, 'llvm_libs_dir', None)
+ if not llvm_libs_dir:
+ lit_config.fatal('No LLVM libs dir set!')
+- path = os.path.pathsep.join((llvm_libs_dir,
++ path = os.path.pathsep.join((clang_libs_dir, llvm_libs_dir,
+ config.environment.get('LD_LIBRARY_PATH','')))
+ config.environment['LD_LIBRARY_PATH'] = path
+
+diff --git a/test/lit.site.cfg.in b/test/lit.site.cfg.in
+index dfd0164c..f310b59a 100644
+--- a/test/lit.site.cfg.in
++++ b/test/lit.site.cfg.in
+@@ -7,6 +7,7 @@ config.llvm_libs_dir = "@LLVM_LIBS_DIR@"
+ config.lit_tools_dir = "@LLVM_LIT_TOOLS_DIR@"
+ config.clang_tools_binary_dir = "@CLANG_TOOLS_BINARY_DIR@"
+ config.clang_tools_dir = "@CLANG_TOOLS_DIR@"
++config.clang_libs_dir = "@SHLIBDIR@"
+ config.python_executable = "@PYTHON_EXECUTABLE@"
+ config.target_triple = "@TARGET_TRIPLE@"
+
+--
+2.12.0
+
diff --git a/sys-devel/clang/files/4.0.1/hardened/0001-Use-z-relro-on-Gentoo.patch b/sys-devel/clang/files/4.0.1/hardened/0001-Use-z-relro-on-Gentoo.patch
new file mode 100644
index 0000000..93e7c6a
--- /dev/null
+++ b/sys-devel/clang/files/4.0.1/hardened/0001-Use-z-relro-on-Gentoo.patch
@@ -0,0 +1,11 @@
+--- a/lib/Driver/ToolChains.cpp
++++ b/lib/Driver/ToolChains.cpp
+@@ -4112,7 +4112,7 @@
+
+ Distro Distro(D.getVFS());
+
+- if (Distro.IsOpenSUSE() || Distro.IsUbuntu()) {
++ if (Distro.IsOpenSUSE() || Distro.IsUbuntu() || Distro.IsGentooLinux()) {
+ ExtraOpts.push_back("-z");
+ ExtraOpts.push_back("relro");
+ }
diff --git a/sys-devel/clang/files/4.0.1/hardened/0002-Enable-Stack-Protector-by-default.patch b/sys-devel/clang/files/4.0.1/hardened/0002-Enable-Stack-Protector-by-default.patch
new file mode 100644
index 0000000..13ac645
--- /dev/null
+++ b/sys-devel/clang/files/4.0.1/hardened/0002-Enable-Stack-Protector-by-default.patch
@@ -0,0 +1,23 @@
+--- a/lib/Driver/ToolChains.cpp
++++ b/lib/Driver/ToolChains.cpp
+@@ -4866,6 +4866,10 @@
+ CmdArgs.push_back("-lunwind");
+ }
+
++unsigned Linux::GetDefaultStackProtectorLevel(bool KernelOrKext) const {
++ return 2;
++}
++
+ /// DragonFly - DragonFly tool chain which can call as(1) and ld(1) directly.
+
+ DragonFly::DragonFly(const Driver &D, const llvm::Triple &Triple,
+--- a/lib/Driver/ToolChains.h
++++ b/lib/Driver/ToolChains.h
+@@ -880,6 +880,7 @@
+ void AddIAMCUIncludeArgs(const llvm::opt::ArgList &DriverArgs,
+ llvm::opt::ArgStringList &CC1Args) const override;
+ bool isPIEDefault() const override;
++ unsigned GetDefaultStackProtectorLevel(bool KernelOrKext) const override;
+ SanitizerMask getSupportedSanitizers() const override;
+ void addProfileRTLibs(const llvm::opt::ArgList &Args,
+ llvm::opt::ArgStringList &CmdArgs) const override;
diff --git a/sys-devel/clang/files/4.0.1/hardened/0003-Enable-PIE-by-default.patch b/sys-devel/clang/files/4.0.1/hardened/0003-Enable-PIE-by-default.patch
new file mode 100644
index 0000000..e1908bc
--- /dev/null
+++ b/sys-devel/clang/files/4.0.1/hardened/0003-Enable-PIE-by-default.patch
@@ -0,0 +1,26 @@
+--- a/lib/Driver/ToolChains.cpp
++++ b/lib/Driver/ToolChains.cpp
+@@ -4721,7 +4721,9 @@
+ }
+ }
+
+-bool Linux::isPIEDefault() const { return getSanitizerArgs().requiresPIE(); }
++bool Linux::isPIEDefault() const {
++ return true;
++}
+
+ SanitizerMask Linux::getSupportedSanitizers() const {
+ const bool IsX86 = getTriple().getArch() == llvm::Triple::x86;
+--- a/lib/Driver/Tools.cpp
++++ b/lib/Driver/Tools.cpp
+@@ -9258,7 +9258,9 @@
+ if (!D.SysRoot.empty())
+ CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot));
+
+- if (IsPIE)
++ if (Args.hasArg(options::OPT_nopie))
++ CmdArgs.push_back("-nopie");
++ else if (IsPIE)
+ CmdArgs.push_back("-pie");
+
+ CmdArgs.push_back("--eh-frame-hdr");
diff --git a/sys-devel/clang/files/4.0.1/hardened/0004-Link-with-z-now-by-default-for-Gentoo.patch b/sys-devel/clang/files/4.0.1/hardened/0004-Link-with-z-now-by-default-for-Gentoo.patch
new file mode 100644
index 0000000..b404db5
--- /dev/null
+++ b/sys-devel/clang/files/4.0.1/hardened/0004-Link-with-z-now-by-default-for-Gentoo.patch
@@ -0,0 +1,14 @@
+--- a/lib/Driver/ToolChains.cpp
++++ b/lib/Driver/ToolChains.cpp
+@@ -4112,6 +4112,11 @@ Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
+
+ Distro Distro(D.getVFS());
+
++ if (Distro.IsGentooLinux()) {
++ ExtraOpts.push_back("-z");
++ ExtraOpts.push_back("now");
++ }
++
+ if (Distro.IsOpenSUSE() || Distro.IsUbuntu() || Distro.IsGentooLinux()) {
+ ExtraOpts.push_back("-z");
+ ExtraOpts.push_back("relro");
diff --git a/sys-devel/clang/files/5.0.1/0001-Driver-Use-arch-type-to-find-compiler-rt-libraries-o.patch b/sys-devel/clang/files/5.0.1/0001-Driver-Use-arch-type-to-find-compiler-rt-libraries-o.patch
new file mode 100644
index 0000000..7d53cbd
--- /dev/null
+++ b/sys-devel/clang/files/5.0.1/0001-Driver-Use-arch-type-to-find-compiler-rt-libraries-o.patch
@@ -0,0 +1,136 @@
+From 19e3dc0ce4949cc7f869b4552c6a7f28cd59c3b7 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= <mgorny@gentoo.org>
+Date: Thu, 17 Nov 2016 14:19:18 +0100
+Subject: [PATCH] [Driver] Use arch type to find compiler-rt libraries (on
+ Linux)
+
+Use llvm::Triple::getArchTypeName() when looking for compiler-rt
+libraries, rather than the exact arch string from the triple. This is
+more correct as it matches the values used when building compiler-rt
+(builtin-config-ix.cmake) which are the subset of the values allowed
+in triples.
+
+For example, this fixes an issue when the compiler set for
+i686-pc-linux-gnu triple would not find an i386 compiler-rt library,
+while this is the exact arch that is detected by compiler-rt. The same
+applies to any other i?86 variant allowed by LLVM.
+
+This also makes the special case for MSVC unnecessary, since now i386
+will be used reliably for all 32-bit x86 variants.
+---
+ lib/Driver/ToolChain.cpp | 5 +----
+ .../usr/i686-unknown-linux/lib/.keep | 0
+ .../usr/lib/gcc/i686-unknown-linux/4.6.0/crtbegin.o | 0
+ test/Driver/linux-ld.c | 21 +++++++++++++++++++++
+ test/Driver/nostdlib.c | 2 +-
+ test/Driver/print-libgcc-file-name-clangrt.c | 10 ++++++++--
+ test/Driver/windows-cross.c | 2 +-
+ 7 files changed, 32 insertions(+), 8 deletions(-)
+ create mode 100644 test/Driver/Inputs/basic_linux_tree/usr/i686-unknown-linux/lib/.keep
+ create mode 100644 test/Driver/Inputs/basic_linux_tree/usr/lib/gcc/i686-unknown-linux/4.6.0/crtbegin.o
+
+diff --git a/lib/Driver/ToolChain.cpp b/lib/Driver/ToolChain.cpp
+index 6adc0386ee..7e4222f087 100644
+--- a/lib/Driver/ToolChain.cpp
++++ b/lib/Driver/ToolChain.cpp
+@@ -283,15 +283,12 @@ static StringRef getArchNameForCompilerRTLib(const ToolChain &TC,
+ const llvm::Triple &Triple = TC.getTriple();
+ bool IsWindows = Triple.isOSWindows();
+
+- if (Triple.isWindowsMSVCEnvironment() && TC.getArch() == llvm::Triple::x86)
+- return "i386";
+-
+ if (TC.getArch() == llvm::Triple::arm || TC.getArch() == llvm::Triple::armeb)
+ return (arm::getARMFloatABI(TC, Args) == arm::FloatABI::Hard && !IsWindows)
+ ? "armhf"
+ : "arm";
+
+- return TC.getArchName();
++ return llvm::Triple::getArchTypeName(TC.getArch());
+ }
+
+ std::string ToolChain::getCompilerRT(const ArgList &Args, StringRef Component,
+diff --git a/test/Driver/Inputs/basic_linux_tree/usr/i686-unknown-linux/lib/.keep b/test/Driver/Inputs/basic_linux_tree/usr/i686-unknown-linux/lib/.keep
+new file mode 100644
+index 0000000000..e69de29bb2
+diff --git a/test/Driver/Inputs/basic_linux_tree/usr/lib/gcc/i686-unknown-linux/4.6.0/crtbegin.o b/test/Driver/Inputs/basic_linux_tree/usr/lib/gcc/i686-unknown-linux/4.6.0/crtbegin.o
+new file mode 100644
+index 0000000000..e69de29bb2
+diff --git a/test/Driver/linux-ld.c b/test/Driver/linux-ld.c
+index e5aa870866..92b199b9d4 100644
+--- a/test/Driver/linux-ld.c
++++ b/test/Driver/linux-ld.c
+@@ -71,6 +71,27 @@
+ // CHECK-LD-RT: libclang_rt.builtins-x86_64.a"
+ //
+ // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
++// RUN: --target=i686-unknown-linux \
++// RUN: --gcc-toolchain="" \
++// RUN: --sysroot=%S/Inputs/basic_linux_tree \
++// RUN: --rtlib=compiler-rt \
++// RUN: | FileCheck --check-prefix=CHECK-LD-RT-I686 %s
++// CHECK-LD-RT-I686-NOT: warning:
++// CHECK-LD-RT-I686: "{{.*}}ld{{(.exe)?}}" "--sysroot=[[SYSROOT:[^"]+]]"
++// CHECK-LD-RT-I686: "--eh-frame-hdr"
++// CHECK-LD-RT-I686: "-m" "elf_i386"
++// CHECK-LD-RT-I686: "-dynamic-linker"
++// CHECK-LD-RT-I686: "{{.*}}/usr/lib/gcc/i686-unknown-linux/4.6.0{{/|\\\\}}crtbegin.o"
++// CHECK-LD-RT-I686: "-L[[SYSROOT]]/usr/lib/gcc/i686-unknown-linux/4.6.0"
++// CHECK-LD-RT-I686: "-L[[SYSROOT]]/usr/lib/gcc/i686-unknown-linux/4.6.0/../../../../i686-unknown-linux/lib"
++// CHECK-LD-RT-I686: "-L[[SYSROOT]]/usr/lib/gcc/i686-unknown-linux/4.6.0/../../.."
++// CHECK-LD-RT-I686: "-L[[SYSROOT]]/lib"
++// CHECK-LD-RT-I686: "-L[[SYSROOT]]/usr/lib"
++// CHECK-LD-RT-I686: libclang_rt.builtins-i386.a"
++// CHECK-LD-RT-I686: "-lc"
++// CHECK-LD-RT-I686: libclang_rt.builtins-i386.a"
++//
++// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
+ // RUN: --target=arm-linux-androideabi \
+ // RUN: --gcc-toolchain="" \
+ // RUN: --sysroot=%S/Inputs/basic_android_tree/sysroot \
+diff --git a/test/Driver/nostdlib.c b/test/Driver/nostdlib.c
+index a9ef665c57..c9793d968c 100644
+--- a/test/Driver/nostdlib.c
++++ b/test/Driver/nostdlib.c
+@@ -27,5 +27,5 @@
+ //
+ // CHECK-LINUX-NOSTDLIB: warning: argument unused during compilation: '--rtlib=compiler-rt'
+ // CHECK-LINUX-NOSTDLIB: "{{(.*[^.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
+-// CHECK-LINUX-NOSTDLIB-NOT: "{{.*}}/Inputs/resource_dir{{/|\\\\}}lib{{/|\\\\}}linux{{/|\\\\}}libclang_rt.builtins-i686.a"
++// CHECK-LINUX-NOSTDLIB-NOT: "{{.*}}/Inputs/resource_dir{{/|\\\\}}lib{{/|\\\\}}linux{{/|\\\\}}libclang_rt.builtins-i386.a"
+ // CHECK-MSVC-NOSTDLIB: warning: argument unused during compilation: '--rtlib=compiler-rt'
+diff --git a/test/Driver/print-libgcc-file-name-clangrt.c b/test/Driver/print-libgcc-file-name-clangrt.c
+index 9f8120c31d..28c758881d 100644
+--- a/test/Driver/print-libgcc-file-name-clangrt.c
++++ b/test/Driver/print-libgcc-file-name-clangrt.c
+@@ -6,6 +6,12 @@
+ // CHECK-CLANGRT-X8664: libclang_rt.builtins-x86_64.a
+
+ // RUN: %clang -rtlib=compiler-rt -print-libgcc-file-name 2>&1 \
++// RUN: --target=i386-pc-linux \
++// RUN: | FileCheck --check-prefix=CHECK-CLANGRT-I386 %s
++// CHECK-CLANGRT-I386: libclang_rt.builtins-i386.a
++
++// Check whether alternate arch values map to the correct library.
++//
++// RUN: %clang -rtlib=compiler-rt -print-libgcc-file-name 2>&1 \
+ // RUN: --target=i686-pc-linux \
+-// RUN: | FileCheck --check-prefix=CHECK-CLANGRT-I686 %s
+-// CHECK-CLANGRT-I686: libclang_rt.builtins-i686.a
++// RUN: | FileCheck --check-prefix=CHECK-CLANGRT-I386 %s
+diff --git a/test/Driver/windows-cross.c b/test/Driver/windows-cross.c
+index 5a2fe52b09..78b4981c9d 100644
+--- a/test/Driver/windows-cross.c
++++ b/test/Driver/windows-cross.c
+@@ -59,7 +59,7 @@
+ // RUN: | FileCheck %s --check-prefix CHECK-SANITIZE-ADDRESS-EXE-X86
+
+ // CHECK-SANITIZE-ADDRESS-EXE-X86: "-fsanitize=address"
+-// CHECK-SANITIZE-ADDRESS-EXE-X86: "{{.*}}clang_rt.asan_dynamic-i686.lib" "{{.*}}clang_rt.asan_dynamic_runtime_thunk-i686.lib" "--undefined" "___asan_seh_interceptor"
++// CHECK-SANITIZE-ADDRESS-EXE-X86: "{{.*}}clang_rt.asan_dynamic-i386.lib" "{{.*}}clang_rt.asan_dynamic_runtime_thunk-i386.lib" "--undefined" "___asan_seh_interceptor"
+
+ // RUN: %clang -### -target armv7-windows-itanium --sysroot %S/Inputs/Windows/ARM/8.1 -B %S/Inputs/Windows/ARM/8.1/usr/bin -fuse-ld=lld-link2 -shared -o shared.dll -fsanitize=tsan -x c++ %s 2>&1 \
+ // RUN: | FileCheck %s --check-prefix CHECK-SANITIZE-TSAN
+--
+2.11.0
+
diff --git a/sys-devel/clang/files/5.0.1/0002-test-Fix-clang-test-for-FreeBSD-and-NetBSD.patch b/sys-devel/clang/files/5.0.1/0002-test-Fix-clang-test-for-FreeBSD-and-NetBSD.patch
new file mode 100644
index 0000000..1751a4f
--- /dev/null
+++ b/sys-devel/clang/files/5.0.1/0002-test-Fix-clang-test-for-FreeBSD-and-NetBSD.patch
@@ -0,0 +1,76 @@
+From 4650c277d616e5d297baf28682eb792e2e0144b1 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= <mgorny@gentoo.org>
+Date: Sun, 1 Apr 2018 23:20:56 +0200
+Subject: [PATCH] [test] Fix clang-test for FreeBSD and NetBSD
+
+Lit tries to inject the shared library paths, but no action is taken
+when platform.system() is not recognized, results in an environment
+variable with an empty name, which is illegal.
+
+The patch fixes this mechanism for FreeBSD and NetBSD, and gives an
+warning on other platforms, so that the latecomers don't have to spend
+time on debugging lit.
+
+Thanks Zhihao Yuan for the patch!
+
+Differential Revision: https://reviews.llvm.org/D39162
+
+git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@316411 91177308-0d34-0410-b5e6-96231b3b80d8
+
+(rebased for release_50 branch)
+---
+ test/Unit/lit.cfg | 41 ++++++++++++++++++++---------------------
+ 1 file changed, 20 insertions(+), 21 deletions(-)
+
+diff --git a/test/Unit/lit.cfg b/test/Unit/lit.cfg
+index 90eb2ac604..2cabf4bba1 100644
+--- a/test/Unit/lit.cfg
++++ b/test/Unit/lit.cfg
+@@ -87,24 +87,23 @@ if config.test_exec_root is None:
+ lit_config.load_config(config, site_cfg)
+ raise SystemExit
+
+-shlibpath_var = ''
+-if platform.system() == 'Linux':
+- shlibpath_var = 'LD_LIBRARY_PATH'
+-elif platform.system() == 'Darwin':
+- shlibpath_var = 'DYLD_LIBRARY_PATH'
+-elif platform.system() == 'Windows':
+- shlibpath_var = 'PATH'
+-
+-# in stand-alone builds, shlibdir is clang's build tree
+-# while llvm_libs_dir is installed LLVM (and possibly older clang)
+-llvm_shlib_dir = getattr(config, 'shlibdir', None)
+-if not llvm_shlib_dir:
+- lit_config.fatal('No shlibdir set!')
+-# Point the dynamic loader at dynamic libraries in 'lib'.
+-llvm_libs_dir = getattr(config, 'llvm_libs_dir', None)
+-if not llvm_libs_dir:
+- lit_config.fatal('No LLVM libs dir set!')
+-shlibpath = os.path.pathsep.join((llvm_shlib_dir, llvm_libs_dir,
+- config.environment.get(shlibpath_var,'')))
+-
+-config.environment[shlibpath_var] = shlibpath
++def find_shlibpath_var():
++ if platform.system() in ['Linux', 'FreeBSD', 'NetBSD']:
++ yield 'LD_LIBRARY_PATH'
++ elif platform.system() == 'Darwin':
++ yield 'DYLD_LIBRARY_PATH'
++ elif platform.system() == 'Windows':
++ yield 'PATH'
++
++for shlibpath_var in find_shlibpath_var():
++ # in stand-alone builds, shlibdir is clang's build tree
++ # while llvm_libs_dir is installed LLVM (and possibly older clang)
++ shlibpath = os.path.pathsep.join(
++ (config.shlibdir,
++ config.llvm_libs_dir,
++ config.environment.get(shlibpath_var, '')))
++ config.environment[shlibpath_var] = shlibpath
++ break
++else:
++ lit_config.warning("unable to inject shared library path on '{}'"
++ .format(platform.system()))
+--
+2.17.0.rc2
+
diff --git a/sys-devel/clang/files/5.0.1/0003-Add-Gentoo-Linux-distro.patch b/sys-devel/clang/files/5.0.1/0003-Add-Gentoo-Linux-distro.patch
new file mode 100644
index 0000000..68770a6
--- /dev/null
+++ b/sys-devel/clang/files/5.0.1/0003-Add-Gentoo-Linux-distro.patch
@@ -0,0 +1,33 @@
+--- a/include/clang/Driver/Distro.h
++++ b/include/clang/Driver/Distro.h
+@@ -26,6 +26,7 @@ public:
+ // NB: Releases of a particular Linux distro should be kept together
+ // in this enum, because some tests are done by integer comparison against
+ // the first and last known member in the family, e.g. IsRedHat().
++ GentooLinux,
+ ArchLinux,
+ DebianLenny,
+ DebianSqueeze,
+@@ -98,6 +99,10 @@ public:
+ /// @name Convenience Predicates
+ /// @{
+
++ bool IsGentooLinux() const {
++ return DistroVal == GentooLinux;
++ }
++
+ bool IsRedhat() const {
+ return DistroVal == Fedora || (DistroVal >= RHEL5 && DistroVal <= RHEL7);
+ }
+--- a/lib/Driver/Distro.cpp
++++ b/lib/Driver/Distro.cpp
+@@ -129,6 +129,9 @@ static Distro::DistroType DetectDistro(vfs::FileSystem &VFS) {
+ if (VFS.exists("/etc/arch-release"))
+ return Distro::ArchLinux;
+
++ if (VFS.exists("/etc/gentoo-release"))
++ return Distro::GentooLinux;
++
+ return Distro::UnknownDistro;
+ }
+
diff --git a/sys-devel/clang/files/5.0.1/darwin_prefix-include-paths.patch b/sys-devel/clang/files/5.0.1/darwin_prefix-include-paths.patch
new file mode 100644
index 0000000..7744b94
--- /dev/null
+++ b/sys-devel/clang/files/5.0.1/darwin_prefix-include-paths.patch
@@ -0,0 +1,18 @@
+--- a/lib/Frontend/InitHeaderSearch.cpp
++++ b/lib/Frontend/InitHeaderSearch.cpp
+@@ -233,6 +233,7 @@
+ case llvm::Triple::Bitrig:
+ break;
+ default:
++ AddPath("@GENTOO_PORTAGE_EPREFIX@/usr/include", System, false);
+ // FIXME: temporary hack: hard-coded paths.
+ AddPath("/usr/local/include", System, false);
+ break;
+@@ -505,6 +506,7 @@
+ // Add the default framework include paths on Darwin.
+ if (HSOpts.UseStandardSystemIncludes) {
+ if (triple.isOSDarwin()) {
++ AddPath("@GENTOO_PORTAGE_EPREFIX@/Frameworks", System, true);
+ AddPath("/System/Library/Frameworks", System, true);
+ AddPath("/Library/Frameworks", System, true);
+ }
diff --git a/sys-devel/clang/files/5.0.1/extra/0001-Assume-the-shared-library-path-variable-is-LD_LIBRAR.patch b/sys-devel/clang/files/5.0.1/extra/0001-Assume-the-shared-library-path-variable-is-LD_LIBRAR.patch
new file mode 100644
index 0000000..cbdb0b8
--- /dev/null
+++ b/sys-devel/clang/files/5.0.1/extra/0001-Assume-the-shared-library-path-variable-is-LD_LIBRAR.patch
@@ -0,0 +1,37 @@
+From 5c5bb3948697f2ca184a03dedd5666eb2de547ba Mon Sep 17 00:00:00 2001
+From: Dimitry Andric <dimitry@andric.com>
+Date: Sat, 20 Jan 2018 14:34:33 +0000
+Subject: [PATCH] Assume the shared library path variable is LD_LIBRARY_PATH on
+ systems except Darwin and Windows. This prevents inserting an environment
+ variable with an empty name (which is illegal and leads to a Python
+ exception) on any of the BSDs.
+
+git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@323040 91177308-0d34-0410-b5e6-96231b3b80d8
+---
+ test/Unit/lit.cfg | 7 +++----
+ 1 file changed, 3 insertions(+), 4 deletions(-)
+
+diff --git a/test/Unit/lit.cfg b/test/Unit/lit.cfg
+index fc63afdb..b40e1cae 100644
+--- a/test/Unit/lit.cfg
++++ b/test/Unit/lit.cfg
+@@ -19,13 +19,12 @@ config.test_exec_root = config.test_source_root
+ # ;-separated list of subdirectories).
+ config.test_format = lit.formats.GoogleTest('.', 'Tests')
+
+-shlibpath_var = ''
+-if platform.system() == 'Linux':
+- shlibpath_var = 'LD_LIBRARY_PATH'
+-elif platform.system() == 'Darwin':
++if platform.system() == 'Darwin':
+ shlibpath_var = 'DYLD_LIBRARY_PATH'
+ elif platform.system() == 'Windows':
+ shlibpath_var = 'PATH'
++else:
++ shlibpath_var = 'LD_LIBRARY_PATH'
+
+ # Point the dynamic loader at dynamic libraries in 'lib'.
+ shlibpath = os.path.pathsep.join((config.shlibdir, config.llvm_libs_dir,
+--
+2.17.0.rc2
+
diff --git a/sys-devel/clang/files/5.0.1/hardened/0001-Use-z-relro-on-Gentoo.patch b/sys-devel/clang/files/5.0.1/hardened/0001-Use-z-relro-on-Gentoo.patch
new file mode 100644
index 0000000..eeda778
--- /dev/null
+++ b/sys-devel/clang/files/5.0.1/hardened/0001-Use-z-relro-on-Gentoo.patch
@@ -0,0 +1,11 @@
+--- a/lib/Driver/ToolChains/Linux.cpp
++++ b/lib/Driver/ToolChains/Linux.cpp
+@@ -210,7 +210,7 @@ Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
+
+ Distro Distro(D.getVFS());
+
+- if (Distro.IsOpenSUSE() || Distro.IsUbuntu()) {
++ if (Distro.IsOpenSUSE() || Distro.IsUbuntu() || Distro.IsGentooLinux()) {
+ ExtraOpts.push_back("-z");
+ ExtraOpts.push_back("relro");
+ }
diff --git a/sys-devel/clang/files/5.0.1/hardened/0002-Enable-Stack-Protector-by-default.patch b/sys-devel/clang/files/5.0.1/hardened/0002-Enable-Stack-Protector-by-default.patch
new file mode 100644
index 0000000..2f5faf5
--- /dev/null
+++ b/sys-devel/clang/files/5.0.1/hardened/0002-Enable-Stack-Protector-by-default.patch
@@ -0,0 +1,25 @@
+--- a/lib/Driver/ToolChains/Linux.cpp
++++ b/lib/Driver/ToolChains/Linux.cpp
+@@ -820,6 +820,10 @@ bool Linux::isPIEDefault() const {
+ getTriple().isMusl() || getSanitizerArgs().requiresPIE();
+ }
+
++unsigned Linux::GetDefaultStackProtectorLevel(bool KernelOrKext) const {
++ return 2;
++}
++
+ SanitizerMask Linux::getSupportedSanitizers() const {
+ const bool IsX86 = getTriple().getArch() == llvm::Triple::x86;
+ const bool IsX86_64 = getTriple().getArch() == llvm::Triple::x86_64;diff --git a/lib/Driver/ToolChains/Linux.cpp b/lib/Driver/ToolChains/Linux.cpp
+diff --git a/lib/Driver/ToolChains/Linux.h b/lib/Driver/ToolChains/Linux.h
+index 9778c1832cc..ddd46a1d587 100644
+--- a/lib/Driver/ToolChains/Linux.h
++++ b/lib/Driver/ToolChains/Linux.h
+@@ -36,6 +36,7 @@ public:
+ void AddIAMCUIncludeArgs(const llvm::opt::ArgList &DriverArgs,
+ llvm::opt::ArgStringList &CC1Args) const override;
+ bool isPIEDefault() const override;
++ unsigned GetDefaultStackProtectorLevel(bool KernelOrKext) const override;
+ SanitizerMask getSupportedSanitizers() const override;
+ void addProfileRTLibs(const llvm::opt::ArgList &Args,
+ llvm::opt::ArgStringList &CmdArgs) const override;
diff --git a/sys-devel/clang/files/5.0.1/hardened/0003-Enable-PIE-by-default.patch b/sys-devel/clang/files/5.0.1/hardened/0003-Enable-PIE-by-default.patch
new file mode 100644
index 0000000..301ee11
--- /dev/null
+++ b/sys-devel/clang/files/5.0.1/hardened/0003-Enable-PIE-by-default.patch
@@ -0,0 +1,24 @@
+--- a/lib/Driver/ToolChains/Gnu.cpp
++++ b/lib/Driver/ToolChains/Gnu.cpp
+@@ -443,7 +443,9 @@ void tools::gnutools::Linker::ConstructJob(Compilation &C, const JobAction &JA,
+ if (!D.SysRoot.empty())
+ CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot));
+
+- if (IsPIE)
++ if (Args.hasArg(options::OPT_nopie))
++ CmdArgs.push_back("-nopie");
++ else if (IsPIE)
+ CmdArgs.push_back("-pie");
+
+ if (Args.hasArg(options::OPT_rdynamic))
+--- a/lib/Driver/ToolChains/Linux.cpp
++++ b/lib/Driver/ToolChains/Linux.cpp
+@@ -819,7 +819,7 @@ void Linux::AddIAMCUIncludeArgs(const ArgList &DriverArgs,
+ }
+ }
+
+-bool Linux::isPIEDefault() const { return getSanitizerArgs().requiresPIE(); }
++bool Linux::isPIEDefault() const { return true; }
+
+ SanitizerMask Linux::getSupportedSanitizers() const {
+ const bool IsX86 = getTriple().getArch() == llvm::Triple::x86;
diff --git a/sys-devel/clang/files/5.0.1/hardened/0004-Enable-FORTIFY_SOURCE-macro-by-default.patch b/sys-devel/clang/files/5.0.1/hardened/0004-Enable-FORTIFY_SOURCE-macro-by-default.patch
new file mode 100644
index 0000000..410bae9
--- /dev/null
+++ b/sys-devel/clang/files/5.0.1/hardened/0004-Enable-FORTIFY_SOURCE-macro-by-default.patch
@@ -0,0 +1,35 @@
+From 68d39575cdff576b85907bea8e42b7ef26384dbb Mon Sep 17 00:00:00 2001
+From: Matthias Dahl <matthias.dahl@binary-island.eu>
+Date: Wed, 20 Sep 2017 16:17:31 +0200
+Subject: [PATCH 3/3] Enable FORTIFY_SOURCE macro by default
+
+FORTIFY_SOURCE only works for optimization levels > 0 and is currently not
+compatible with the address sanitizer, thus the macro is only set if the input
+language is C or C++ and the optimization level > 0 while the address sanitizer
+is not requested.
+---
+ lib/Frontend/CompilerInvocation.cpp | 8 ++++++++
+ 1 file changed, 8 insertions(+)
+
+diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp
+index 0d0869c815d..88c16534103 100644
+--- a/lib/Frontend/CompilerInvocation.cpp
++++ b/lib/Frontend/CompilerInvocation.cpp
+@@ -2694,6 +2694,14 @@ bool CompilerInvocation::CreateFromArgs(CompilerInvocation &Res,
+ !LangOpts.Sanitize.has(SanitizerKind::Address) &&
+ !LangOpts.Sanitize.has(SanitizerKind::Memory);
+
++ // Set the macro before the command line macros are being processed, so it can be
++ // properly unset if required to in case of incompatibilities.
++ if (Res.getCodeGenOpts().OptimizationLevel > 0 &&
++ (DashX.getLanguage() == InputKind::C || DashX.getLanguage() == InputKind::CXX) &&
++ !LangOpts.Sanitize.has(SanitizerKind::Address)) {
++ Res.getPreprocessorOpts().addMacroDef("_FORTIFY_SOURCE=2");
++ }
++
+ // FIXME: ParsePreprocessorArgs uses the FileManager to read the contents of
+ // PCH file and find the original header name. Remove the need to do that in
+ // ParsePreprocessorArgs and remove the FileManager
+--
+2.14.1
+
diff --git a/sys-devel/clang/files/5.0.1/hardened/0005-Link-with-z-now-by-default-for-Gentoo.patch b/sys-devel/clang/files/5.0.1/hardened/0005-Link-with-z-now-by-default-for-Gentoo.patch
new file mode 100644
index 0000000..ff0642f
--- /dev/null
+++ b/sys-devel/clang/files/5.0.1/hardened/0005-Link-with-z-now-by-default-for-Gentoo.patch
@@ -0,0 +1,14 @@
+--- a/lib/Driver/ToolChains/Linux.cpp
++++ b/lib/Driver/ToolChains/Linux.cpp
+@@ -212,6 +212,11 @@ Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
+
+ Distro Distro(D.getVFS());
+
++ if (Distro.IsGentooLinux()) {
++ ExtraOpts.push_back("-z");
++ ExtraOpts.push_back("now");
++ }
++
+ if (Distro.IsOpenSUSE() || Distro.IsUbuntu() || Distro.IsGentooLinux()) {
+ ExtraOpts.push_back("-z");
+ ExtraOpts.push_back("relro");
diff --git a/sys-devel/clang/files/6.0.0/0001-Driver-Avoid-invalidated-iterator-in-insertTargetAnd.patch b/sys-devel/clang/files/6.0.0/0001-Driver-Avoid-invalidated-iterator-in-insertTargetAnd.patch
new file mode 100644
index 0000000..20ba89b
--- /dev/null
+++ b/sys-devel/clang/files/6.0.0/0001-Driver-Avoid-invalidated-iterator-in-insertTargetAnd.patch
@@ -0,0 +1,55 @@
+From 99418eabfbe5378d7a751444856c6c5c656519c4 Mon Sep 17 00:00:00 2001
+From: Serge Pavlov <sepavloff@gmail.com>
+Date: Mon, 19 Mar 2018 16:13:43 +0000
+Subject: [PATCH 1/2] [Driver] Avoid invalidated iterator in
+ insertTargetAndModeArgs
+
+Doing an .insert() can potentially invalidate iterators by reallocating the
+vector's storage. When all the stars align just right, this causes segfaults
+or glibc aborts.
+
+Gentoo Linux bug (crashes while building Chromium): https://bugs.gentoo.org/650082.
+
+Patch by Hector Martin!
+
+Differential Revision: https://reviews.llvm.org/D44607
+
+
+git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@327863 91177308-0d34-0410-b5e6-96231b3b80d8
+---
+ tools/driver/driver.cpp | 9 +++++----
+ 1 file changed, 5 insertions(+), 4 deletions(-)
+
+diff --git a/tools/driver/driver.cpp b/tools/driver/driver.cpp
+index fa757da953..1b614accb2 100644
+--- a/tools/driver/driver.cpp
++++ b/tools/driver/driver.cpp
+@@ -212,20 +212,21 @@ static void insertTargetAndModeArgs(const ParsedClangName &NameParts,
+ // Put target and mode arguments at the start of argument list so that
+ // arguments specified in command line could override them. Avoid putting
+ // them at index 0, as an option like '-cc1' must remain the first.
+- auto InsertionPoint = ArgVector.begin();
+- if (InsertionPoint != ArgVector.end())
++ int InsertionPoint = 0;
++ if (ArgVector.size() > 0)
+ ++InsertionPoint;
+
+ if (NameParts.DriverMode) {
+ // Add the mode flag to the arguments.
+- ArgVector.insert(InsertionPoint,
++ ArgVector.insert(ArgVector.begin() + InsertionPoint,
+ GetStableCStr(SavedStrings, NameParts.DriverMode));
+ }
+
+ if (NameParts.TargetIsValid) {
+ const char *arr[] = {"-target", GetStableCStr(SavedStrings,
+ NameParts.TargetPrefix)};
+- ArgVector.insert(InsertionPoint, std::begin(arr), std::end(arr));
++ ArgVector.insert(ArgVector.begin() + InsertionPoint,
++ std::begin(arr), std::end(arr));
+ }
+ }
+
+--
+2.16.2
+
diff --git a/sys-devel/clang/files/6.0.0/0002-test-Fix-Cross-DSO-CFI-Android-sanitizer-test-for-rt.patch b/sys-devel/clang/files/6.0.0/0002-test-Fix-Cross-DSO-CFI-Android-sanitizer-test-for-rt.patch
new file mode 100644
index 0000000..0c66448
--- /dev/null
+++ b/sys-devel/clang/files/6.0.0/0002-test-Fix-Cross-DSO-CFI-Android-sanitizer-test-for-rt.patch
@@ -0,0 +1,30 @@
+From f81bc3f2d174ac21e576cdddb736524531258fbe Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= <mgorny@gentoo.org>
+Date: Mon, 19 Mar 2018 20:55:47 +0100
+Subject: [PATCH 2/2] [test] Fix Cross-DSO CFI Android sanitizer test for
+ -rtlib=compiler-rt
+
+Fix the CHECK-CFI-CROSS-DSO-ANDROID test to be more precise and match
+specifically 'clang_rt.cfi' rather than any compiler-rt library. This
+fixes the failure when the linker command-line contains
+clang_rt.builtins library due to CLANG_DEFAULT_RTLIB=compiler-rt.
+---
+ test/Driver/sanitizer-ld.c | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/test/Driver/sanitizer-ld.c b/test/Driver/sanitizer-ld.c
+index 0da4255f69..9309450186 100644
+--- a/test/Driver/sanitizer-ld.c
++++ b/test/Driver/sanitizer-ld.c
+@@ -514,7 +514,7 @@
+ // RUN: --sysroot=%S/Inputs/basic_android_tree \
+ // RUN: | FileCheck --check-prefix=CHECK-CFI-CROSS-DSO-ANDROID %s
+ // CHECK-CFI-CROSS-DSO-ANDROID: "{{.*}}ld{{(.exe)?}}"
+-// CHECK-CFI-CROSS-DSO-ANDROID-NOT: libclang_rt.
++// CHECK-CFI-CROSS-DSO-ANDROID-NOT: libclang_rt.cfi
+
+ // Cross-DSO CFI with diagnostics on Android links just the UBSAN runtime.
+ // RUN: %clang -fsanitize=cfi -fsanitize-cfi-cross-dso %s -### -o %t.o 2>&1 \
+--
+2.16.2
+
diff --git a/sys-devel/clang/files/6.0.0/0003-Add-Gentoo-Linux-distro.patch b/sys-devel/clang/files/6.0.0/0003-Add-Gentoo-Linux-distro.patch
new file mode 100644
index 0000000..a11dcfe
--- /dev/null
+++ b/sys-devel/clang/files/6.0.0/0003-Add-Gentoo-Linux-distro.patch
@@ -0,0 +1,33 @@
+--- a/include/clang/Driver/Distro.h
++++ b/include/clang/Driver/Distro.h
+@@ -26,6 +26,7 @@ public:
+ // NB: Releases of a particular Linux distro should be kept together
+ // in this enum, because some tests are done by integer comparison against
+ // the first and last known member in the family, e.g. IsRedHat().
++ GentooLinux,
+ AlpineLinux,
+ ArchLinux,
+ DebianLenny,
+@@ -98,6 +99,10 @@ public:
+ /// @name Convenience Predicates
+ /// @{
+
++ bool IsGentooLinux() const {
++ return DistroVal == GentooLinux;
++ }
++
+ bool IsRedhat() const {
+ return DistroVal == Fedora || (DistroVal >= RHEL5 && DistroVal <= RHEL7);
+ }
+--- a/lib/Driver/Distro.cpp
++++ b/lib/Driver/Distro.cpp
+@@ -129,6 +129,9 @@ static Distro::DistroType DetectDistro(vfs::FileSystem &VFS) {
+ if (VFS.exists("/etc/arch-release"))
+ return Distro::ArchLinux;
+
++ if (VFS.exists("/etc/gentoo-release"))
++ return Distro::GentooLinux;
++
+ return Distro::UnknownDistro;
+ }
+
diff --git a/sys-devel/clang/files/6.0.0/hardened/0001-Use-z-relro-on-Gentoo.patch b/sys-devel/clang/files/6.0.0/hardened/0001-Use-z-relro-on-Gentoo.patch
new file mode 100644
index 0000000..653c933
--- /dev/null
+++ b/sys-devel/clang/files/6.0.0/hardened/0001-Use-z-relro-on-Gentoo.patch
@@ -0,0 +1,11 @@
+--- a/lib/Driver/ToolChains/Linux.cpp
++++ b/lib/Driver/ToolChains/Linux.cpp
+@@ -210,7 +210,7 @@ Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
+
+ Distro Distro(D.getVFS());
+
+- if (Distro.IsOpenSUSE() || Distro.IsUbuntu() || Distro.IsAlpineLinux()) {
++ if (Distro.IsOpenSUSE() || Distro.IsUbuntu() || Distro.IsAlpineLinux() || Distro.IsGentooLinux()) {
+ ExtraOpts.push_back("-z");
+ ExtraOpts.push_back("relro");
+ }
diff --git a/sys-devel/clang/files/6.0.0/hardened/0002-Enable-Stack-Protector-by-default.patch b/sys-devel/clang/files/6.0.0/hardened/0002-Enable-Stack-Protector-by-default.patch
new file mode 100644
index 0000000..2f5faf5
--- /dev/null
+++ b/sys-devel/clang/files/6.0.0/hardened/0002-Enable-Stack-Protector-by-default.patch
@@ -0,0 +1,25 @@
+--- a/lib/Driver/ToolChains/Linux.cpp
++++ b/lib/Driver/ToolChains/Linux.cpp
+@@ -820,6 +820,10 @@ bool Linux::isPIEDefault() const {
+ getTriple().isMusl() || getSanitizerArgs().requiresPIE();
+ }
+
++unsigned Linux::GetDefaultStackProtectorLevel(bool KernelOrKext) const {
++ return 2;
++}
++
+ SanitizerMask Linux::getSupportedSanitizers() const {
+ const bool IsX86 = getTriple().getArch() == llvm::Triple::x86;
+ const bool IsX86_64 = getTriple().getArch() == llvm::Triple::x86_64;diff --git a/lib/Driver/ToolChains/Linux.cpp b/lib/Driver/ToolChains/Linux.cpp
+diff --git a/lib/Driver/ToolChains/Linux.h b/lib/Driver/ToolChains/Linux.h
+index 9778c1832cc..ddd46a1d587 100644
+--- a/lib/Driver/ToolChains/Linux.h
++++ b/lib/Driver/ToolChains/Linux.h
+@@ -36,6 +36,7 @@ public:
+ void AddIAMCUIncludeArgs(const llvm::opt::ArgList &DriverArgs,
+ llvm::opt::ArgStringList &CC1Args) const override;
+ bool isPIEDefault() const override;
++ unsigned GetDefaultStackProtectorLevel(bool KernelOrKext) const override;
+ SanitizerMask getSupportedSanitizers() const override;
+ void addProfileRTLibs(const llvm::opt::ArgList &Args,
+ llvm::opt::ArgStringList &CmdArgs) const override;
diff --git a/sys-devel/clang/files/6.0.0/hardened/0003-Enable-PIE-by-default.patch b/sys-devel/clang/files/6.0.0/hardened/0003-Enable-PIE-by-default.patch
new file mode 100644
index 0000000..2b9ad5e
--- /dev/null
+++ b/sys-devel/clang/files/6.0.0/hardened/0003-Enable-PIE-by-default.patch
@@ -0,0 +1,12 @@
+--- a/lib/Driver/ToolChains/Linux.cpp
++++ b/lib/Driver/ToolChains/Linux.cpp
+@@ -816,8 +816,7 @@ void Linux::AddIAMCUIncludeArgs(const ArgList &DriverArgs,
+ }
+
+ bool Linux::isPIEDefault() const {
+- return (getTriple().isAndroid() && !getTriple().isAndroidVersionLT(16)) ||
+- getTriple().isMusl() || getSanitizerArgs().requiresPIE();
++ return true;
+ }
+
+ unsigned Linux::GetDefaultStackProtectorLevel(bool KernelOrKext) const {
diff --git a/sys-devel/clang/files/6.0.0/hardened/0004-Enable-FORTIFY_SOURCE-macro-by-default.patch b/sys-devel/clang/files/6.0.0/hardened/0004-Enable-FORTIFY_SOURCE-macro-by-default.patch
new file mode 100644
index 0000000..410bae9
--- /dev/null
+++ b/sys-devel/clang/files/6.0.0/hardened/0004-Enable-FORTIFY_SOURCE-macro-by-default.patch
@@ -0,0 +1,35 @@
+From 68d39575cdff576b85907bea8e42b7ef26384dbb Mon Sep 17 00:00:00 2001
+From: Matthias Dahl <matthias.dahl@binary-island.eu>
+Date: Wed, 20 Sep 2017 16:17:31 +0200
+Subject: [PATCH 3/3] Enable FORTIFY_SOURCE macro by default
+
+FORTIFY_SOURCE only works for optimization levels > 0 and is currently not
+compatible with the address sanitizer, thus the macro is only set if the input
+language is C or C++ and the optimization level > 0 while the address sanitizer
+is not requested.
+---
+ lib/Frontend/CompilerInvocation.cpp | 8 ++++++++
+ 1 file changed, 8 insertions(+)
+
+diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp
+index 0d0869c815d..88c16534103 100644
+--- a/lib/Frontend/CompilerInvocation.cpp
++++ b/lib/Frontend/CompilerInvocation.cpp
+@@ -2694,6 +2694,14 @@ bool CompilerInvocation::CreateFromArgs(CompilerInvocation &Res,
+ !LangOpts.Sanitize.has(SanitizerKind::Address) &&
+ !LangOpts.Sanitize.has(SanitizerKind::Memory);
+
++ // Set the macro before the command line macros are being processed, so it can be
++ // properly unset if required to in case of incompatibilities.
++ if (Res.getCodeGenOpts().OptimizationLevel > 0 &&
++ (DashX.getLanguage() == InputKind::C || DashX.getLanguage() == InputKind::CXX) &&
++ !LangOpts.Sanitize.has(SanitizerKind::Address)) {
++ Res.getPreprocessorOpts().addMacroDef("_FORTIFY_SOURCE=2");
++ }
++
+ // FIXME: ParsePreprocessorArgs uses the FileManager to read the contents of
+ // PCH file and find the original header name. Remove the need to do that in
+ // ParsePreprocessorArgs and remove the FileManager
+--
+2.14.1
+
diff --git a/sys-devel/clang/files/6.0.0/hardened/0005-Link-with-z-now-by-default-for-Gentoo.patch b/sys-devel/clang/files/6.0.0/hardened/0005-Link-with-z-now-by-default-for-Gentoo.patch
new file mode 100644
index 0000000..28942ae
--- /dev/null
+++ b/sys-devel/clang/files/6.0.0/hardened/0005-Link-with-z-now-by-default-for-Gentoo.patch
@@ -0,0 +1,11 @@
+--- a/lib/Driver/ToolChains/Linux.cpp
++++ b/lib/Driver/ToolChains/Linux.cpp
+@@ -210,7 +210,7 @@ Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
+
+ Distro Distro(D.getVFS());
+
+- if (Distro.IsAlpineLinux()) {
++ if (Distro.IsAlpineLinux() || Distro.IsGentooLinux()) {
+ ExtraOpts.push_back("-z");
+ ExtraOpts.push_back("now");
+ }
diff --git a/sys-devel/clang/metadata.xml b/sys-devel/clang/metadata.xml
new file mode 100644
index 0000000..04b324c
--- /dev/null
+++ b/sys-devel/clang/metadata.xml
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE pkgmetadata SYSTEM "http://www.gentoo.org/dtd/metadata.dtd">
+<pkgmetadata>
+ <maintainer type="project">
+ <email>llvm@gentoo.org</email>
+ </maintainer>
+ <longdescription>The goal of the Clang project is to create a new C, C++, Objective C and Objective C++ front-end for the LLVM compiler.
+
+Features and Goals
+
+Some of the goals for the project include the following:
+
+End-User Features:
+Fast compiles and low memory use
+Expressive diagnostics
+GCC compatibility
+Utility and Applications:
+
+Modular library based architecture
+Support diverse clients (refactoring, static analysis, code generation, etc)
+Allow tight integration with IDEs
+Use the LLVM BSD License
+Internal Design and Implementation:
+
+A real-world, production quality compiler
+A simple and hackable code base
+A single unified parser for C, Objective C, C++, and Objective C++
+Conformance with C/C++/ObjC and their variants</longdescription>
+ <use>
+ <flag name="default-compiler-rt">Use compiler-rt instead of libgcc as the default rtlib for clang</flag>
+ <flag name="default-libcxx">Use libc++ instead of libstdc++ as the default stdlib for clang</flag>
+ <flag name="static-analyzer">Install the Clang static analyzer</flag>
+ <flag name="z3">Enable the static analyzer constraint manager backend using <pkg>sci-mathematics/z3</pkg></flag>
+ </use>
+</pkgmetadata>
^ permalink raw reply related [relevance 99%]
Results 1-1 of 1 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2018-04-29 14:53 99% [gentoo-commits] proj/musl:master commit in: sys-devel/clang/, sys-devel/clang/files/5.0.1/, Anthony G. Basile
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox