summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichał Górny <mgorny@gentoo.org>2016-08-22 15:43:14 +0200
committerMichał Górny <mgorny@gentoo.org>2016-08-22 17:11:50 +0200
commit11d093e4ec16f42e733d605dccf3100d4bb435ba (patch)
tree430bb5398c01766b2874e1226a187749ffa98f69 /sys-devel/llvm/files/3.7.1
parentsys-devel/clang: Enable stand-alone builds against sys-devel/llvm (diff)
downloadgentoo-11d093e4ec16f42e733d605dccf3100d4bb435ba.tar.gz
gentoo-11d093e4ec16f42e733d605dccf3100d4bb435ba.tar.bz2
gentoo-11d093e4ec16f42e733d605dccf3100d4bb435ba.zip
sys-devel/llvm: Group all patches by newest version applicable
Diffstat (limited to 'sys-devel/llvm/files/3.7.1')
-rw-r--r--sys-devel/llvm/files/3.7.1/clang/0001-Install-clang-runtime-into-usr-lib-without-suffix.patch52
-rw-r--r--sys-devel/llvm/files/3.7.1/clang/ccc-analyzer-isystem.patch18
-rw-r--r--sys-devel/llvm/files/3.7.1/clang/gentoo-install.patch48
-rw-r--r--sys-devel/llvm/files/3.7.1/compiler-rt/arm_march_flags.patch16
-rw-r--r--sys-devel/llvm/files/3.7.1/compiler-rt/msan-fix.patch86
-rw-r--r--sys-devel/llvm/files/3.7.1/lldb/python.patch23
-rw-r--r--sys-devel/llvm/files/3.7.1/lldb/tinfo.patch12
-rw-r--r--sys-devel/llvm/files/3.7.1/llvm-config-0.patch83
-rw-r--r--sys-devel/llvm/files/3.7.1/llvm-config-1.patch453
-rw-r--r--sys-devel/llvm/files/3.7.1/llvm-config-2.patch113
-rw-r--r--sys-devel/llvm/files/3.7.1/llvm-config-3.patch29
-rw-r--r--sys-devel/llvm/files/3.7.1/msan-fix.patch79
12 files changed, 1012 insertions, 0 deletions
diff --git a/sys-devel/llvm/files/3.7.1/clang/0001-Install-clang-runtime-into-usr-lib-without-suffix.patch b/sys-devel/llvm/files/3.7.1/clang/0001-Install-clang-runtime-into-usr-lib-without-suffix.patch
new file mode 100644
index 000000000000..904a72a358a9
--- /dev/null
+++ b/sys-devel/llvm/files/3.7.1/clang/0001-Install-clang-runtime-into-usr-lib-without-suffix.patch
@@ -0,0 +1,52 @@
+From b28503def986bcbc388a04be0d51cbe80bc59506 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= <mgorny@gentoo.org>
+Date: Tue, 9 Jun 2015 12:11:50 +0200
+Subject: [PATCH] Install clang runtime into /usr/lib (without suffix)
+
+---
+ lib/Driver/Driver.cpp | 3 +--
+ lib/Frontend/CompilerInvocation.cpp | 3 +--
+ lib/Headers/CMakeLists.txt | 2 +-
+ 3 files changed, 3 insertions(+), 5 deletions(-)
+
+diff --git a/lib/Driver/Driver.cpp b/lib/Driver/Driver.cpp
+index a04a1f8..418d46a 100644
+--- a/tools/clang/lib/Driver/Driver.cpp
++++ b/tools/clang//lib/Driver/Driver.cpp
+@@ -66,8 +66,7 @@ Driver::Driver(StringRef ClangExecutable, StringRef DefaultTargetTriple,
+ if (ClangResourceDir != "") {
+ llvm::sys::path::append(P, ClangResourceDir);
+ } else {
+- StringRef ClangLibdirSuffix(CLANG_LIBDIR_SUFFIX);
+- llvm::sys::path::append(P, "..", Twine("lib") + ClangLibdirSuffix, "clang",
++ llvm::sys::path::append(P, "..", "lib", "clang",
+ CLANG_VERSION_STRING);
+ }
+ ResourceDir = P.str();
+diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp
+index 9485767..0b9ecbd 100644
+--- a/tools/clang/lib/Frontend/CompilerInvocation.cpp
++++ b/tools/clang/lib/Frontend/CompilerInvocation.cpp
+@@ -1053,8 +1053,7 @@ std::string CompilerInvocation::GetResourcesPath(const char *Argv0,
+ if (ClangResourceDir != "") {
+ llvm::sys::path::append(P, ClangResourceDir);
+ } else {
+- StringRef ClangLibdirSuffix(CLANG_LIBDIR_SUFFIX);
+- llvm::sys::path::append(P, "..", Twine("lib") + ClangLibdirSuffix, "clang",
++ llvm::sys::path::append(P, "..", "lib", "clang",
+ CLANG_VERSION_STRING);
+ }
+
+diff --git a/lib/Headers/CMakeLists.txt b/lib/Headers/CMakeLists.txt
+index 29a738e..3769d23 100644
+--- a/tools/clang/lib/Headers/CMakeLists.txt
++++ b/tools/clang/lib/Headers/CMakeLists.txt
+@@ -93,4 +93,4 @@ set_target_properties(clang-headers PROPERTIES FOLDER "Misc")
+ install(
+ FILES ${files} ${CMAKE_CURRENT_BINARY_DIR}/arm_neon.h
+ PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
+- DESTINATION lib${LLVM_LIBDIR_SUFFIX}/clang/${CLANG_VERSION}/include)
++ DESTINATION lib/clang/${CLANG_VERSION}/include)
+--
+2.4.3
+
diff --git a/sys-devel/llvm/files/3.7.1/clang/ccc-analyzer-isystem.patch b/sys-devel/llvm/files/3.7.1/clang/ccc-analyzer-isystem.patch
new file mode 100644
index 000000000000..78ca922b6366
--- /dev/null
+++ b/sys-devel/llvm/files/3.7.1/clang/ccc-analyzer-isystem.patch
@@ -0,0 +1,18 @@
+https://bugs.gentoo.org/586168
+
+Index: tools/clang/tools/scan-build/ccc-analyzer
+===================================================================
+--- a/tools/clang/tools/scan-build/ccc-analyzer (revision 250980)
++++ b/tools/clang/tools/scan-build/ccc-analyzer (working copy)
+@@ -586,9 +586,9 @@
+ }
+
+ # Compile mode flags.
+- if ($Arg =~ /^-[D,I,U,isystem](.*)$/) {
++ if ($Arg =~ /^-(D|I|U|isystem)(.*)$/) {
+ my $Tmp = $Arg;
+- if ($1 eq '') {
++ if ($2 eq '') {
+ # FIXME: Check if we are going off the end.
+ ++$i;
+ $Tmp = $Arg . $ARGV[$i];
diff --git a/sys-devel/llvm/files/3.7.1/clang/gentoo-install.patch b/sys-devel/llvm/files/3.7.1/clang/gentoo-install.patch
new file mode 100644
index 000000000000..6d76ba9660ce
--- /dev/null
+++ b/sys-devel/llvm/files/3.7.1/clang/gentoo-install.patch
@@ -0,0 +1,48 @@
+---
+ tools/clang/lib/Driver/Tools.cpp | 2 +-
+ tools/clang/tools/scan-build/scan-build | 4 ++--
+ tools/clang/tools/scan-view/scan-view | 2 +-
+ 3 files changed, 4 insertions(+), 4 deletions(-)
+
+diff --git a/tools/clang/lib/Driver/Tools.cpp b/tools/clang/lib/Driver/Tools.cpp
+index 187ed38..55bcd99 100644
+--- a/tools/clang/lib/Driver/Tools.cpp
++++ b/tools/clang/lib/Driver/Tools.cpp
+diff --git a/tools/clang/tools/scan-build/scan-build b/tools/clang/tools/scan-build/scan-build
+index 0f119f6..58f78d9 100755
+--- a/tools/clang/tools/scan-build/scan-build
++++ b/tools/clang/tools/scan-build/scan-build
+@@ -419,7 +419,7 @@
+
+ my $Dir = shift;
+
+- my $JS = Cwd::realpath("$RealBin/sorttable.js");
++ my $JS = Cwd::realpath("@EPREFIX@/usr/share/llvm/sorttable.js");
+
+ DieDiag("Cannot find 'sorttable.js'.\n")
+ if (! -r $JS);
+@@ -429,7 +429,7 @@
+ DieDiag("Could not copy 'sorttable.js' to '$Dir'.\n")
+ if (! -r "$Dir/sorttable.js");
+
+- my $CSS = Cwd::realpath("$RealBin/scanview.css");
++ my $CSS = Cwd::realpath("@EPREFIX@/usr/share/llvm/scanview.css");
+
+ DieDiag("Cannot find 'scanview.css'.\n")
+ if (! -r $CSS);
+diff --git a/tools/clang/tools/scan-view/scan-view b/tools/clang/tools/scan-view/scan-view
+index fb27da6..1f8ddb8 100755
+--- a/tools/clang/tools/scan-view/scan-view
++++ b/tools/clang/tools/scan-view/scan-view
+@@ -54,7 +54,7 @@ def start_browser(port, options):
+ webbrowser.open(url)
+
+ def run(port, options, root):
+- import ScanView
++ from clang import ScanView
+ try:
+ print 'Starting scan-view at: http://%s:%d'%(options.host,
+ port)
+--
+1.8.4.4
+
diff --git a/sys-devel/llvm/files/3.7.1/compiler-rt/arm_march_flags.patch b/sys-devel/llvm/files/3.7.1/compiler-rt/arm_march_flags.patch
new file mode 100644
index 000000000000..943a8407f123
--- /dev/null
+++ b/sys-devel/llvm/files/3.7.1/compiler-rt/arm_march_flags.patch
@@ -0,0 +1,16 @@
+diff -Naur llvm-3.7.0.src.orig/projects/compiler-rt/cmake/config-ix.cmake llvm-3.7.0.src/projects/compiler-rt/cmake/config-ix.cmake
+--- llvm-3.7.0.src.orig/projects/compiler-rt/cmake/config-ix.cmake 2015-07-30 06:28:50.000000000 +0200
++++ llvm-3.7.0.src/projects/compiler-rt/cmake/config-ix.cmake 2015-10-27 17:10:47.365847079 +0100
+@@ -209,12 +209,6 @@
+ test_target_arch(mips "" "-mips32r2" "--target=mips-linux-gnu")
+ test_target_arch(mips64 "" "-mips64r2" "-mabi=n64")
+ endif()
+- elseif("${COMPILER_RT_TEST_TARGET_ARCH}" MATCHES "arm")
+- test_target_arch(arm "" "-march=armv7-a")
+- elseif("${COMPILER_RT_TEST_TARGET_ARCH}" MATCHES "aarch32")
+- test_target_arch(aarch32 "" "-march=armv8-a")
+- elseif("${COMPILER_RT_TEST_TARGET_ARCH}" MATCHES "aarch64")
+- test_target_arch(aarch64 "" "-march=armv8-a")
+ endif()
+ set(COMPILER_RT_OS_SUFFIX "")
+ endif()
diff --git a/sys-devel/llvm/files/3.7.1/compiler-rt/msan-fix.patch b/sys-devel/llvm/files/3.7.1/compiler-rt/msan-fix.patch
new file mode 100644
index 000000000000..3854a18497b1
--- /dev/null
+++ b/sys-devel/llvm/files/3.7.1/compiler-rt/msan-fix.patch
@@ -0,0 +1,86 @@
+From 5dad120f9c9bc74c73edadb0467d8df81ae46066 Mon Sep 17 00:00:00 2001
+From: "H.J. Lu" <hjl.tools@gmail.com>
+Date: Wed, 5 Aug 2015 05:34:27 -0700
+Subject: [PATCH 08/13] Apply split-layout-compiler-rt.patch
+
+https://llvm.org/bugs/show_bug.cgi?id=24155
+---
+ lib/msan/msan.h | 30 ++++++++++++++++++++----------
+ lib/msan/msan_allocator.cc | 12 +++++++++++-
+ 2 files changed, 31 insertions(+), 11 deletions(-)
+
+diff --git a/lib/msan/msan.h b/lib/msan/msan.h
+index cd8bc19..6251b38 100644
+--- a/lib/msan/msan.h
++++ b/lib/msan/msan.h
+@@ -94,17 +94,27 @@ const MappingDesc kMemoryLayout[] = {
+
+ #elif SANITIZER_LINUX && SANITIZER_WORDSIZE == 64
+
+-// Requries PIE binary and ASLR enabled.
+-// Main thread stack and DSOs at 0x7f0000000000 (sometimes 0x7e0000000000).
+-// Heap at 0x600000000000.
++// All of the following configurations are supported.
++// ASLR disabled: main executable and DSOs at 0x555550000000
++// PIE and ASLR: main executable and DSOs at 0x7f0000000000
++// non-PIE: main executable below 0x100000000, DSOs at 0x7f0000000000
++// Heap at 0x700000000000.
+ const MappingDesc kMemoryLayout[] = {
+- {0x000000000000ULL, 0x200000000000ULL, MappingDesc::INVALID, "invalid"},
+- {0x200000000000ULL, 0x400000000000ULL, MappingDesc::SHADOW, "shadow"},
+- {0x400000000000ULL, 0x600000000000ULL, MappingDesc::ORIGIN, "origin"},
+- {0x600000000000ULL, 0x800000000000ULL, MappingDesc::APP, "app"}};
+-
+-#define MEM_TO_SHADOW(mem) (((uptr)(mem)) & ~0x400000000000ULL)
+-#define SHADOW_TO_ORIGIN(mem) (((uptr)(mem)) + 0x200000000000ULL)
++ {0x000000000000ULL, 0x050000000000ULL, MappingDesc::APP, "app-1"},
++ {0x050000000000ULL, 0x100000000000ULL, MappingDesc::SHADOW, "shadow-2"},
++ {0x100000000000ULL, 0x150000000000ULL, MappingDesc::INVALID, "invalid"},
++ {0x150000000000ULL, 0x200000000000ULL, MappingDesc::ORIGIN, "origin-2"},
++ {0x200000000000ULL, 0x300000000000ULL, MappingDesc::SHADOW, "shadow-3"},
++ {0x300000000000ULL, 0x400000000000ULL, MappingDesc::ORIGIN, "origin-3"},
++ {0x400000000000ULL, 0x500000000000ULL, MappingDesc::INVALID, "invalid"},
++ {0x500000000000ULL, 0x550000000000ULL, MappingDesc::SHADOW, "shadow-1"},
++ {0x550000000000ULL, 0x600000000000ULL, MappingDesc::APP, "app-2"},
++ {0x600000000000ULL, 0x650000000000ULL, MappingDesc::ORIGIN, "origin-1"},
++ {0x650000000000ULL, 0x700000000000ULL, MappingDesc::INVALID, "invalid"},
++ {0x700000000000ULL, 0x800000000000ULL, MappingDesc::APP, "app-3"}};
++
++#define MEM_TO_SHADOW(mem) (((uptr)(mem)) ^ 0x500000000000ULL)
++#define SHADOW_TO_ORIGIN(mem) (((uptr)(mem)) + 0x100000000000ULL)
+
+ #else
+ #error "Unsupported platform"
+diff --git a/lib/msan/msan_allocator.cc b/lib/msan/msan_allocator.cc
+index 6df3566..e588bf8 100644
+--- a/lib/msan/msan_allocator.cc
++++ b/lib/msan/msan_allocator.cc
+@@ -49,7 +49,8 @@ struct MsanMapUnmapCallback {
+ typedef SizeClassAllocator32<0, SANITIZER_MMAP_RANGE_SIZE, sizeof(Metadata),
+ SizeClassMap, kRegionSizeLog, ByteMap,
+ MsanMapUnmapCallback> PrimaryAllocator;
+-#elif defined(__x86_64__)
++
++#elif SANITIZER_FREEBSD && SANITIZER_WORDSIZE == 64
+ static const uptr kAllocatorSpace = 0x600000000000ULL;
+ static const uptr kAllocatorSize = 0x80000000000; // 8T.
+ static const uptr kMetadataSize = sizeof(Metadata);
+@@ -67,6 +68,15 @@ struct MsanMapUnmapCallback {
+ typedef SizeClassAllocator64<kAllocatorSpace, kAllocatorSize, kMetadataSize,
+ DefaultSizeClassMap,
+ MsanMapUnmapCallback> PrimaryAllocator;
++#elif SANITIZER_LINUX && SANITIZER_WORDSIZE == 64
++ static const uptr kAllocatorSpace = 0x700000000000ULL;
++ static const uptr kAllocatorSize = 0x80000000000; // 8T.
++ static const uptr kMetadataSize = sizeof(Metadata);
++ static const uptr kMaxAllowedMallocSize = 8UL << 30;
++
++ typedef SizeClassAllocator64<kAllocatorSpace, kAllocatorSize, kMetadataSize,
++ DefaultSizeClassMap,
++ MsanMapUnmapCallback> PrimaryAllocator;
+ #endif
+ typedef SizeClassAllocatorLocalCache<PrimaryAllocator> AllocatorCache;
+ typedef LargeMmapAllocator<MsanMapUnmapCallback> SecondaryAllocator;
+--
+2.6.4
+
diff --git a/sys-devel/llvm/files/3.7.1/lldb/python.patch b/sys-devel/llvm/files/3.7.1/lldb/python.patch
new file mode 100644
index 000000000000..1a958271e187
--- /dev/null
+++ b/sys-devel/llvm/files/3.7.1/lldb/python.patch
@@ -0,0 +1,23 @@
+diff -Naur llvm-3.7.0.src.orig/tools/lldb/scripts/Python/finishSwigPythonLLDB.py llvm-3.7.0.src/tools/lldb/scripts/Python/finishSwigPythonLLDB.py
+--- llvm-3.7.0.src.orig/tools/lldb/scripts/Python/finishSwigPythonLLDB.py 2015-06-04 05:12:37.000000000 +0200
++++ llvm-3.7.0.src/tools/lldb/scripts/Python/finishSwigPythonLLDB.py 2015-10-11 19:19:54.074935710 +0200
+@@ -371,14 +371,14 @@
+ strLibFileExtn = ".dylib";
+ else:
+ strLibFileExtn = ".so";
+- strSrc = os.path.join("lib", "liblldb" + strLibFileExtn);
++ strSrc = os.path.join("GENTOO_LIBDIR", "liblldb" + strLibFileExtn);
+
+- if eOSType != utilsOsType.EnumOsType.Windows:
++# if eOSType != utilsOsType.EnumOsType.Windows:
+ # Create a symlink to the "lib" directory, to ensure liblldb's RPATH is
+ # effective.
+- bOk, strErrMsg = make_symlink( vDictArgs, vstrFrameworkPythonDir, "lib", os.path.join("../lib") );
+- if not bOk:
+- return (bOk, strErrMsg)
++# bOk, strErrMsg = make_symlink( vDictArgs, vstrFrameworkPythonDir, "lib", os.path.join("../lib") );
++# if not bOk:
++# return (bOk, strErrMsg)
+
+ bOk, strErrMsg = make_symlink( vDictArgs, vstrFrameworkPythonDir, strSrc, strTarget );
+
diff --git a/sys-devel/llvm/files/3.7.1/lldb/tinfo.patch b/sys-devel/llvm/files/3.7.1/lldb/tinfo.patch
new file mode 100644
index 000000000000..626498c57eea
--- /dev/null
+++ b/sys-devel/llvm/files/3.7.1/lldb/tinfo.patch
@@ -0,0 +1,12 @@
+--- a/tools/lldb/cmake/LLDBDependencies.cmake 2015/09/16 20:13:53 247841
++++ b/tools/lldb/cmake/LLDBDependencies.cmake 2015/09/16 20:14:01 247842
+@@ -141,6 +141,9 @@
+ endif()
+ if (NOT LLDB_DISABLE_CURSES)
+ list(APPEND LLDB_SYSTEM_LIBS panel ncurses)
++ if(LLVM_ENABLE_TERMINFO AND HAVE_TERMINFO)
++ list(APPEND LLDB_SYSTEM_LIBS ${TERMINFO_LIBS})
++ endif()
+ endif()
+ endif()
+ # On FreeBSD backtrace() is provided by libexecinfo, not libc.
diff --git a/sys-devel/llvm/files/3.7.1/llvm-config-0.patch b/sys-devel/llvm/files/3.7.1/llvm-config-0.patch
new file mode 100644
index 000000000000..87f9ff8c5ad7
--- /dev/null
+++ b/sys-devel/llvm/files/3.7.1/llvm-config-0.patch
@@ -0,0 +1,83 @@
+From a59464503a7e059ddfd3fb4308753b692d03d996 Mon Sep 17 00:00:00 2001
+From: Tom Stellard <thomas.stellard@amd.com>
+Date: Wed, 9 Sep 2015 16:39:30 +0000
+Subject: [PATCH 1/4] llvm-config: Add --build-system option
+
+Summary:
+This can be used for distinguishing between cmake and autoconf builds.
+Users may need this in order to handle inconsistencies between the
+outputs of the two build systems.
+
+Reviewers: echristo, chandlerc, beanz
+
+Subscribers: llvm-commits
+
+Differential Revision: http://reviews.llvm.org/D11838
+
+git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@247159 91177308-0d34-0410-b5e6-96231b3b80d8
+---
+ tools/llvm-config/BuildVariables.inc.in | 1 +
+ tools/llvm-config/CMakeLists.txt | 2 ++
+ tools/llvm-config/Makefile | 2 ++
+ tools/llvm-config/llvm-config.cpp | 3 +++
+ 4 files changed, 8 insertions(+)
+
+diff --git a/tools/llvm-config/BuildVariables.inc.in b/tools/llvm-config/BuildVariables.inc.in
+index 3f51f49..0f28fad 100644
+--- a/tools/llvm-config/BuildVariables.inc.in
++++ b/tools/llvm-config/BuildVariables.inc.in
+@@ -26,3 +26,4 @@
+ #define LLVM_LIBDIR_SUFFIX "@LLVM_LIBDIR_SUFFIX@"
+ #define LLVM_TARGETS_BUILT "@LLVM_TARGETS_BUILT@"
+ #define LLVM_SYSTEM_LIBS "@LLVM_SYSTEM_LIBS@"
++#define LLVM_BUILD_SYSTEM "@LLVM_BUILD_SYSTEM@"
+diff --git a/tools/llvm-config/CMakeLists.txt b/tools/llvm-config/CMakeLists.txt
+index edbd8c9..dd53460 100644
+--- a/tools/llvm-config/CMakeLists.txt
++++ b/tools/llvm-config/CMakeLists.txt
+@@ -24,6 +24,8 @@ set(LLVM_OBJ_ROOT ${LLVM_BINARY_DIR})
+ set(LLVM_CPPFLAGS "${CMAKE_CPP_FLAGS} ${CMAKE_CPP_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} ${LLVM_DEFINITIONS}")
+ set(LLVM_CFLAGS "${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} ${LLVM_DEFINITIONS}")
+ set(LLVM_CXXFLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} ${COMPILE_FLAGS} ${LLVM_DEFINITIONS}")
++set(LLVM_BUILD_SYSTEM cmake)
++
+ # Use the C++ link flags, since they should be a superset of C link flags.
+ set(LLVM_LDFLAGS "${CMAKE_CXX_LINK_FLAGS}")
+ set(LLVM_BUILDMODE ${CMAKE_BUILD_TYPE})
+diff --git a/tools/llvm-config/Makefile b/tools/llvm-config/Makefile
+index 1ff8b6f..c2b5e8f 100644
+--- a/tools/llvm-config/Makefile
++++ b/tools/llvm-config/Makefile
+@@ -65,6 +65,8 @@ $(ObjDir)/BuildVariables.inc: $(BUILDVARIABLES_SRCPATH) Makefile $(ObjDir)/.dir
+ >> temp.sed
+ $(Verb) $(ECHO) 's/@LLVM_TARGETS_BUILT@/$(subst /,\/,$(TARGETS_TO_BUILD))/' \
+ >> temp.sed
++ $(Verb) $(ECHO) 's/@LLVM_BUILD_SYSTEM@/autoconf/' \
++ >> temp.sed
+ $(Verb) $(SED) -f temp.sed < $< > $@
+ $(Verb) $(RM) temp.sed
+
+diff --git a/tools/llvm-config/llvm-config.cpp b/tools/llvm-config/llvm-config.cpp
+index 879b9ab..4ce8f10 100644
+--- a/tools/llvm-config/llvm-config.cpp
++++ b/tools/llvm-config/llvm-config.cpp
+@@ -157,6 +157,7 @@ Options:\n\
+ --host-target Target triple used to configure LLVM.\n\
+ --build-mode Print build mode of LLVM tree (e.g. Debug or Release).\n\
+ --assertion-mode Print assertion mode of LLVM tree (ON or OFF).\n\
++ --build-system Print the build system used to build LLVM (autoconf or cmake).\n\
+ Typical components:\n\
+ all All LLVM libraries (default).\n\
+ engine Either a native JIT or a bitcode interpreter.\n";
+@@ -323,6 +324,8 @@ int main(int argc, char **argv) {
+ #else
+ OS << "ON\n";
+ #endif
++ } else if (Arg == "--build-system") {
++ OS << LLVM_BUILD_SYSTEM << '\n';
+ } else if (Arg == "--obj-root") {
+ OS << ActivePrefix << '\n';
+ } else if (Arg == "--src-root") {
+--
+2.7.4
+
diff --git a/sys-devel/llvm/files/3.7.1/llvm-config-1.patch b/sys-devel/llvm/files/3.7.1/llvm-config-1.patch
new file mode 100644
index 000000000000..214a3bbbc0e2
--- /dev/null
+++ b/sys-devel/llvm/files/3.7.1/llvm-config-1.patch
@@ -0,0 +1,453 @@
+From 55433193c56e6b2e0792c3ca1b0ef3881ab01138 Mon Sep 17 00:00:00 2001
+From: Richard Diamond <wichard@vitalitystudios.com>
+Date: Mon, 9 Nov 2015 23:15:38 +0000
+Subject: [PATCH 2/4] Fix `llvm-config` to adapt to the install environment.
+
+Summary:
+This patch does a couple of things:
+
+ - Adds a new argument `--shared-mode` which accepts a list of components and prints whether or not the provided components need to be linked statically or shared.
+ - Fixes `--libnames` when CMake BUILD_SHARED_LIBS is used.
+ - Fixes `--libnames`, `--libs`, and `--libfiles` for dylib when static components aren't installed.
+ - Fixes `--libnames`, `--libs`, `--libfiles`, and `--components` to use LLVM_DYLIB_COMPONENTS as the component manifest for dylib linking.
+ - Uses the host platform's usual convention for filename extensions and such, instead of always defaulting to Unix-izms.
+
+Because I don't own a Mac, I am not able to test the Mac platform dependent stuff locally. If someone would be willing to run a build for me on their machine (unless there's a better option), I'd appreciate it.
+
+Reviewers: jfb, brad.king, whitequark, beanz
+
+Subscribers: beanz, jauhien, llvm-commits
+
+Differential Revision: http://reviews.llvm.org/D13198
+
+git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@252532 91177308-0d34-0410-b5e6-96231b3b80d8
+---
+ bindings/ocaml/Makefile.ocaml | 2 +
+ tools/llvm-config/BuildVariables.inc.in | 3 +
+ tools/llvm-config/CMakeLists.txt | 5 +
+ tools/llvm-config/llvm-config.cpp | 265 +++++++++++++++++++++++++++++---
+ 4 files changed, 253 insertions(+), 22 deletions(-)
+
+diff --git a/bindings/ocaml/Makefile.ocaml b/bindings/ocaml/Makefile.ocaml
+index 1f65a7b..22b96a2 100644
+--- a/bindings/ocaml/Makefile.ocaml
++++ b/bindings/ocaml/Makefile.ocaml
+@@ -277,6 +277,8 @@ uninstall-local:: uninstall-deplibs
+
+ build-deplibs: $(OutputLibs)
+
++$(OcamlDir)/%.so: $(LibDir)/%.so
++ $(Verb) ln -sf $< $@
+ $(OcamlDir)/%.a: $(LibDir)/%.a
+ $(Verb) ln -sf $< $@
+
+diff --git a/tools/llvm-config/BuildVariables.inc.in b/tools/llvm-config/BuildVariables.inc.in
+index 0f28fad..e384838 100644
+--- a/tools/llvm-config/BuildVariables.inc.in
++++ b/tools/llvm-config/BuildVariables.inc.in
+@@ -27,3 +27,6 @@
+ #define LLVM_TARGETS_BUILT "@LLVM_TARGETS_BUILT@"
+ #define LLVM_SYSTEM_LIBS "@LLVM_SYSTEM_LIBS@"
+ #define LLVM_BUILD_SYSTEM "@LLVM_BUILD_SYSTEM@"
++#define LLVM_ENABLE_DYLIB "@LLVM_BUILD_LLVM_DYLIB@"
++#define LLVM_ENABLE_SHARED "@LLVM_ENABLE_SHARED@"
++#define LLVM_DYLIB_COMPONENTS "@LLVM_DYLIB_COMPONENTS@"
+diff --git a/tools/llvm-config/CMakeLists.txt b/tools/llvm-config/CMakeLists.txt
+index dd53460..173f6dc 100644
+--- a/tools/llvm-config/CMakeLists.txt
++++ b/tools/llvm-config/CMakeLists.txt
+@@ -30,6 +30,11 @@ set(LLVM_BUILD_SYSTEM cmake)
+ set(LLVM_LDFLAGS "${CMAKE_CXX_LINK_FLAGS}")
+ set(LLVM_BUILDMODE ${CMAKE_BUILD_TYPE})
+ set(LLVM_SYSTEM_LIBS ${SYSTEM_LIBS})
++if(BUILD_SHARED_LIBS)
++ set(LLVM_ENABLE_SHARED ON)
++else()
++ set(LLVM_ENABLE_SHARED OFF)
++endif()
+ string(REPLACE ";" " " LLVM_TARGETS_BUILT "${LLVM_TARGETS_TO_BUILD}")
+ configure_file(${BUILDVARIABLES_SRCPATH} ${BUILDVARIABLES_OBJPATH} @ONLY)
+
+diff --git a/tools/llvm-config/llvm-config.cpp b/tools/llvm-config/llvm-config.cpp
+index 4ce8f10..51efbd8 100644
+--- a/tools/llvm-config/llvm-config.cpp
++++ b/tools/llvm-config/llvm-config.cpp
+@@ -30,6 +30,7 @@
+ #include <cstdlib>
+ #include <set>
+ #include <vector>
++#include <unordered_set>
+
+ using namespace llvm;
+
+@@ -51,12 +52,16 @@ using namespace llvm;
+ /// \param Name - The component to traverse.
+ /// \param ComponentMap - A prebuilt map of component names to descriptors.
+ /// \param VisitedComponents [in] [out] - The set of already visited components.
+-/// \param RequiredLibs [out] - The ordered list of required libraries.
++/// \param RequiredLibs [out] - The ordered list of required
++/// libraries.
++/// \param GetComponentNames - Get the component names instead of the
++/// library name.
+ static void VisitComponent(StringRef Name,
+ const StringMap<AvailableComponent*> &ComponentMap,
+ std::set<AvailableComponent*> &VisitedComponents,
+ std::vector<StringRef> &RequiredLibs,
+- bool IncludeNonInstalled) {
++ bool IncludeNonInstalled, bool GetComponentNames,
++ const std::string *ActiveLibDir, bool *HasMissing) {
+ // Lookup the component.
+ AvailableComponent *AC = ComponentMap.lookup(Name);
+ assert(AC && "Invalid component name!");
+@@ -74,12 +79,22 @@ static void VisitComponent(StringRef Name,
+ // Otherwise, visit all the dependencies.
+ for (unsigned i = 0; AC->RequiredLibraries[i]; ++i) {
+ VisitComponent(AC->RequiredLibraries[i], ComponentMap, VisitedComponents,
+- RequiredLibs, IncludeNonInstalled);
++ RequiredLibs, IncludeNonInstalled, GetComponentNames,
++ ActiveLibDir, HasMissing);
++ }
++
++ if (GetComponentNames) {
++ RequiredLibs.push_back(Name);
++ return;
+ }
+
+ // Add to the required library list.
+- if (AC->Library)
++ if (AC->Library) {
++ if (!IncludeNonInstalled && HasMissing && !*HasMissing && ActiveLibDir) {
++ *HasMissing = !sys::fs::exists(*ActiveLibDir + "/" + AC->Library);
++ }
+ RequiredLibs.push_back(AC->Library);
++ }
+ }
+
+ /// \brief Compute the list of required libraries for a given list of
+@@ -91,9 +106,12 @@ static void VisitComponent(StringRef Name,
+ /// are required to link the given components.
+ /// \param IncludeNonInstalled - Whether non-installed components should be
+ /// reported.
++/// \param GetComponentNames - True if one would prefer the component names.
+ static void ComputeLibsForComponents(const std::vector<StringRef> &Components,
+ std::vector<StringRef> &RequiredLibs,
+- bool IncludeNonInstalled) {
++ bool IncludeNonInstalled, bool GetComponentNames,
++ const std::string *ActiveLibDir,
++ bool *HasMissing) {
+ std::set<AvailableComponent*> VisitedComponents;
+
+ // Build a map of component names to information.
+@@ -116,7 +134,8 @@ static void ComputeLibsForComponents(const std::vector<StringRef> &Components,
+ }
+
+ VisitComponent(ComponentLower, ComponentMap, VisitedComponents,
+- RequiredLibs, IncludeNonInstalled);
++ RequiredLibs, IncludeNonInstalled, GetComponentNames,
++ ActiveLibDir, HasMissing);
+ }
+
+ // The list is now ordered with leafs first, we want the libraries to printed
+@@ -157,6 +176,7 @@ Options:\n\
+ --host-target Target triple used to configure LLVM.\n\
+ --build-mode Print build mode of LLVM tree (e.g. Debug or Release).\n\
+ --assertion-mode Print assertion mode of LLVM tree (ON or OFF).\n\
++ --shared-mode Print how the provided components can be collectively linked (`shared` or `static`).\n\
+ --build-system Print the build system used to build LLVM (autoconf or cmake).\n\
+ Typical components:\n\
+ all All LLVM libraries (default).\n\
+@@ -172,10 +192,38 @@ std::string GetExecutablePath(const char *Argv0) {
+ return llvm::sys::fs::getMainExecutable(Argv0, P);
+ }
+
++/// \brief Expand the semi-colon delimited LLVM_DYLIB_COMPONENTS into
++/// the full list of components.
++std::vector<StringRef> GetAllDyLibComponents(const bool IsInDevelopmentTree,
++ const bool GetComponentNames) {
++ std::vector<StringRef> DyLibComponents;
++ {
++ StringRef DyLibComponentsStr(LLVM_DYLIB_COMPONENTS);
++ size_t Offset = 0;
++ while (true) {
++ const size_t NextOffset = DyLibComponentsStr.find(';', Offset);
++ DyLibComponents.push_back(DyLibComponentsStr.substr(Offset, NextOffset));
++ if (NextOffset == std::string::npos) {
++ break;
++ }
++ Offset = NextOffset + 1;
++ }
++
++ assert(DyLibComponents.size() > 0);
++ }
++
++ std::vector<StringRef> Components;
++ ComputeLibsForComponents(DyLibComponents, Components,
++ /*IncludeNonInstalled=*/IsInDevelopmentTree,
++ GetComponentNames, nullptr, nullptr);
++
++ return std::move(Components);
++}
++
+ int main(int argc, char **argv) {
+ std::vector<StringRef> Components;
+ bool PrintLibs = false, PrintLibNames = false, PrintLibFiles = false;
+- bool PrintSystemLibs = false;
++ bool PrintSystemLibs = false, PrintSharedMode = false;
+ bool HasAnyOption = false;
+
+ // llvm-config is designed to support being run both from a development tree
+@@ -270,6 +318,108 @@ int main(int argc, char **argv) {
+ ActiveIncludeOption = "-I" + ActiveIncludeDir;
+ }
+
++ /// We only use `shared library` mode in cases where the static library form
++ /// of the components provided are not available; note however that this is
++ /// skipped if we're run from within the build dir. However, once installed,
++ /// we still need to provide correct output when the static archives are
++ /// removed or, as in the case of CMake's `BUILD_SHARED_LIBS`, never present
++ /// in the first place. This can't be done at configure/build time.
++
++ StringRef SharedExt, SharedVersionedExt, SharedDir, SharedPrefix, StaticExt,
++ StaticPrefix, StaticDir = "lib";
++ const Triple HostTriple(Triple::normalize(LLVM_DEFAULT_TARGET_TRIPLE));
++ if (HostTriple.isOSWindows()) {
++ SharedExt = "dll";
++ SharedVersionedExt = PACKAGE_VERSION ".dll";
++ StaticExt = "a";
++ SharedDir = ActiveBinDir;
++ StaticDir = ActiveLibDir;
++ StaticPrefix = SharedPrefix = "";
++ } else if (HostTriple.isOSDarwin()) {
++ SharedExt = "dylib";
++ SharedVersionedExt = PACKAGE_VERSION ".dylib";
++ StaticExt = "a";
++ StaticDir = SharedDir = ActiveLibDir;
++ StaticPrefix = SharedPrefix = "lib";
++ } else {
++ // default to the unix values:
++ SharedExt = "so";
++ SharedVersionedExt = PACKAGE_VERSION ".so";
++ StaticExt = "a";
++ StaticDir = SharedDir = ActiveLibDir;
++ StaticPrefix = SharedPrefix = "lib";
++ }
++
++ const bool BuiltDyLib = (std::strcmp(LLVM_ENABLE_DYLIB, "ON") == 0);
++
++ enum { CMake, AutoConf } ConfigTool;
++ if (std::strcmp(LLVM_BUILD_SYSTEM, "cmake") == 0) {
++ ConfigTool = CMake;
++ } else {
++ ConfigTool = AutoConf;
++ }
++
++ /// CMake style shared libs, ie each component is in a shared library.
++ const bool BuiltSharedLibs =
++ (ConfigTool == CMake && std::strcmp(LLVM_ENABLE_SHARED, "ON") == 0);
++
++ bool DyLibExists = false;
++ const std::string DyLibName =
++ (SharedPrefix + "LLVM-" + SharedVersionedExt).str();
++
++ if (BuiltDyLib) {
++ DyLibExists = sys::fs::exists(SharedDir + "/" + DyLibName);
++ }
++
++ /// Get the component's library name without the lib prefix and the
++ /// extension. Returns true if Lib is in a recognized format.
++ auto GetComponentLibraryNameSlice = [&](const StringRef &Lib,
++ StringRef &Out) {
++ if (Lib.startswith("lib")) {
++ unsigned FromEnd;
++ if (Lib.endswith(StaticExt)) {
++ FromEnd = StaticExt.size() + 1;
++ } else if (Lib.endswith(SharedExt)) {
++ FromEnd = SharedExt.size() + 1;
++ } else {
++ FromEnd = 0;
++ }
++
++ if (FromEnd != 0) {
++ Out = Lib.slice(3, Lib.size() - FromEnd);
++ return true;
++ }
++ }
++
++ return false;
++ };
++ /// Maps Unixizms to the host platform.
++ auto GetComponentLibraryFileName = [&](const StringRef &Lib,
++ const bool ForceShared) {
++ std::string LibFileName = Lib;
++ StringRef LibName;
++ if (GetComponentLibraryNameSlice(Lib, LibName)) {
++ if (BuiltSharedLibs || ForceShared) {
++ LibFileName = (SharedPrefix + LibName + "." + SharedExt).str();
++ } else {
++ // default to static
++ LibFileName = (StaticPrefix + LibName + "." + StaticExt).str();
++ }
++ }
++
++ return LibFileName;
++ };
++ /// Get the full path for a possibly shared component library.
++ auto GetComponentLibraryPath = [&](const StringRef &Name,
++ const bool ForceShared) {
++ auto LibFileName = GetComponentLibraryFileName(Name, ForceShared);
++ if (BuiltSharedLibs || ForceShared) {
++ return (SharedDir + "/" + LibFileName).str();
++ } else {
++ return (StaticDir + "/" + LibFileName).str();
++ }
++ };
++
+ raw_ostream &OS = outs();
+ for (int i = 1; i != argc; ++i) {
+ StringRef Arg = argv[i];
+@@ -303,13 +453,33 @@ int main(int argc, char **argv) {
+ } else if (Arg == "--libfiles") {
+ PrintLibFiles = true;
+ } else if (Arg == "--components") {
++ /// If there are missing static archives and a dylib was
++ /// built, print LLVM_DYLIB_COMPONENTS instead of everything
++ /// in the manifest.
++ std::vector<StringRef> Components;
+ for (unsigned j = 0; j != array_lengthof(AvailableComponents); ++j) {
+ // Only include non-installed components when in a development tree.
+ if (!AvailableComponents[j].IsInstalled && !IsInDevelopmentTree)
+ continue;
+
+- OS << ' ';
+- OS << AvailableComponents[j].Name;
++ Components.push_back(AvailableComponents[j].Name);
++ if (AvailableComponents[j].Library && !IsInDevelopmentTree) {
++ if (DyLibExists &&
++ !sys::fs::exists(GetComponentLibraryPath(
++ AvailableComponents[j].Library, false))) {
++ Components = GetAllDyLibComponents(IsInDevelopmentTree, true);
++ std::sort(Components.begin(), Components.end());
++ break;
++ }
++ }
++ }
++
++ for (unsigned I = 0; I < Components.size(); ++I) {
++ if (I) {
++ OS << ' ';
++ }
++
++ OS << Components[I];
+ }
+ OS << '\n';
+ } else if (Arg == "--targets-built") {
+@@ -324,6 +494,8 @@ int main(int argc, char **argv) {
+ #else
+ OS << "ON\n";
+ #endif
++ } else if (Arg == "--shared-mode") {
++ PrintSharedMode = true;
+ } else if (Arg == "--build-system") {
+ OS << LLVM_BUILD_SYSTEM << '\n';
+ } else if (Arg == "--obj-root") {
+@@ -341,35 +513,84 @@ int main(int argc, char **argv) {
+ if (!HasAnyOption)
+ usage();
+
+- if (PrintLibs || PrintLibNames || PrintLibFiles || PrintSystemLibs) {
++ if (PrintLibs || PrintLibNames || PrintLibFiles || PrintSystemLibs ||
++ PrintSharedMode) {
++
++ if (PrintSharedMode && BuiltSharedLibs) {
++ OS << "shared\n";
++ return 0;
++ }
++
+ // If no components were specified, default to "all".
+ if (Components.empty())
+ Components.push_back("all");
+
+ // Construct the list of all the required libraries.
+ std::vector<StringRef> RequiredLibs;
++ bool HasMissing = false;
+ ComputeLibsForComponents(Components, RequiredLibs,
+- /*IncludeNonInstalled=*/IsInDevelopmentTree);
++ /*IncludeNonInstalled=*/IsInDevelopmentTree, false,
++ &ActiveLibDir, &HasMissing);
++
++ if (PrintSharedMode) {
++ std::unordered_set<std::string> FullDyLibComponents;
++ std::vector<StringRef> DyLibComponents =
++ GetAllDyLibComponents(IsInDevelopmentTree, false);
++
++ for (auto &Component : DyLibComponents) {
++ FullDyLibComponents.insert(Component);
++ }
++ DyLibComponents.clear();
++
++ for (auto &Lib : RequiredLibs) {
++ if (!FullDyLibComponents.count(Lib)) {
++ OS << "static\n";
++ return 0;
++ }
++ }
++ FullDyLibComponents.clear();
++
++ if (HasMissing && DyLibExists) {
++ OS << "shared\n";
++ return 0;
++ } else {
++ OS << "static\n";
++ return 0;
++ }
++ }
+
+ if (PrintLibs || PrintLibNames || PrintLibFiles) {
+- for (unsigned i = 0, e = RequiredLibs.size(); i != e; ++i) {
+- StringRef Lib = RequiredLibs[i];
+- if (i)
+- OS << ' ';
+
++ auto PrintForLib = [&](const StringRef &Lib, const bool ForceShared) {
+ if (PrintLibNames) {
+- OS << Lib;
++ OS << GetComponentLibraryFileName(Lib, ForceShared);
+ } else if (PrintLibFiles) {
+- OS << ActiveLibDir << '/' << Lib;
++ OS << GetComponentLibraryPath(Lib, ForceShared);
+ } else if (PrintLibs) {
+ // If this is a typical library name, include it using -l.
+- if (Lib.startswith("lib") && Lib.endswith(".a")) {
+- OS << "-l" << Lib.slice(3, Lib.size()-2);
+- continue;
++ StringRef LibName;
++ if (Lib.startswith("lib")) {
++ if (GetComponentLibraryNameSlice(Lib, LibName)) {
++ OS << "-l" << LibName;
++ } else {
++ OS << "-l:" << GetComponentLibraryFileName(Lib, ForceShared);
++ }
++ } else {
++ // Otherwise, print the full path.
++ OS << GetComponentLibraryPath(Lib, ForceShared);
+ }
++ }
++ };
++
++ if (HasMissing && DyLibExists) {
++ PrintForLib(DyLibName, true);
++ } else {
++ for (unsigned i = 0, e = RequiredLibs.size(); i != e; ++i) {
++ StringRef Lib = RequiredLibs[i];
++ if (i)
++ OS << ' ';
+
+- // Otherwise, print the full path.
+- OS << ActiveLibDir << '/' << Lib;
++ PrintForLib(Lib, false);
+ }
+ }
+ OS << '\n';
+--
+2.7.4
+
diff --git a/sys-devel/llvm/files/3.7.1/llvm-config-2.patch b/sys-devel/llvm/files/3.7.1/llvm-config-2.patch
new file mode 100644
index 000000000000..2895d38d7a2c
--- /dev/null
+++ b/sys-devel/llvm/files/3.7.1/llvm-config-2.patch
@@ -0,0 +1,113 @@
+From 4abc261d14c886c21d24f639293a60ce45c1dca3 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= <mgorny@gentoo.org>
+Date: Wed, 2 Dec 2015 16:04:56 +0100
+Subject: [PATCH 3/4] llvm-config: Clean up exported values, update for shared
+ linking
+
+Gentoo-specific fixup for llvm-config, including:
+- wiping build-specific CFLAGS, CXXFLAGS,
+- updating library suffixes for shared libs,
+- wiping --system-libs for shared linking,
+- banning --obj-root and --src-root due to no sources installed,
+- making --build-mode return "Release" rather than "Gentoo".
+
+Thanks to Steven Newbury for the initial patch.
+
+Bug: https://bugs.gentoo.org/565358
+Bug: https://bugs.gentoo.org/501684
+---
+ tools/llvm-config/CMakeLists.txt | 11 ++++++++---
+ tools/llvm-config/llvm-config.cpp | 20 +++++++++++++++-----
+ utils/llvm-build/llvmbuild/main.py | 4 +++-
+ 3 files changed, 26 insertions(+), 9 deletions(-)
+
+diff --git a/tools/llvm-config/CMakeLists.txt b/tools/llvm-config/CMakeLists.txt
+index 173f6dc..013ea8c 100644
+--- a/tools/llvm-config/CMakeLists.txt
++++ b/tools/llvm-config/CMakeLists.txt
+@@ -22,14 +22,19 @@ get_property(COMPILE_FLAGS TARGET llvm-config PROPERTY COMPILE_FLAGS)
+ set(LLVM_SRC_ROOT ${LLVM_MAIN_SRC_DIR})
+ set(LLVM_OBJ_ROOT ${LLVM_BINARY_DIR})
+ set(LLVM_CPPFLAGS "${CMAKE_CPP_FLAGS} ${CMAKE_CPP_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} ${LLVM_DEFINITIONS}")
+-set(LLVM_CFLAGS "${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} ${LLVM_DEFINITIONS}")
+-set(LLVM_CXXFLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} ${COMPILE_FLAGS} ${LLVM_DEFINITIONS}")
++# Just use CMAKE_CPP_FLAGS for CFLAGS and CXXFLAGS, otherwise compiler
++# specific flags will be set when we don't know what compiler will be used
++# with external project utilising llvm-config. C++ Standard is required.
++# TODO: figure out if we can remove -std=c++11 and move it to revdeps.
++set(LLVM_CFLAGS "${CMAKE_CPP_FLAGS} ${CMAKE_C_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} ${LLVM_DEFINITIONS}")
++set(LLVM_CXXFLAGS "${CMAKE_CPP_FLAGS} -std=c++11 ${CMAKE_CXX_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} ${LLVM_DEFINITIONS}")
+ set(LLVM_BUILD_SYSTEM cmake)
+
+ # Use the C++ link flags, since they should be a superset of C link flags.
+ set(LLVM_LDFLAGS "${CMAKE_CXX_LINK_FLAGS}")
+ set(LLVM_BUILDMODE ${CMAKE_BUILD_TYPE})
+-set(LLVM_SYSTEM_LIBS ${SYSTEM_LIBS})
++# We don't do static libs, so we don't need to supply any system-libs
++set(LLVM_SYSTEM_LIBS "")
+ if(BUILD_SHARED_LIBS)
+ set(LLVM_ENABLE_SHARED ON)
+ else()
+diff --git a/tools/llvm-config/llvm-config.cpp b/tools/llvm-config/llvm-config.cpp
+index 51efbd8..315e5e1 100644
+--- a/tools/llvm-config/llvm-config.cpp
++++ b/tools/llvm-config/llvm-config.cpp
+@@ -487,7 +487,8 @@ int main(int argc, char **argv) {
+ } else if (Arg == "--host-target") {
+ OS << Triple::normalize(LLVM_DEFAULT_TARGET_TRIPLE) << '\n';
+ } else if (Arg == "--build-mode") {
+- OS << build_mode << '\n';
++ // force Release since we force non-standard Gentoo build mode
++ OS << "Release" << '\n';
+ } else if (Arg == "--assertion-mode") {
+ #if defined(NDEBUG)
+ OS << "OFF\n";
+@@ -498,10 +499,19 @@ int main(int argc, char **argv) {
+ PrintSharedMode = true;
+ } else if (Arg == "--build-system") {
+ OS << LLVM_BUILD_SYSTEM << '\n';
+- } else if (Arg == "--obj-root") {
+- OS << ActivePrefix << '\n';
+- } else if (Arg == "--src-root") {
+- OS << LLVM_SRC_ROOT << '\n';
++ } else if (Arg == "--obj-root" || Arg == "--src-root") {
++ if (IsInDevelopmentTree) {
++ if (Arg == "--obj-root") {
++ OS << ActivePrefix << '\n';
++ } else {
++ OS << LLVM_SRC_ROOT << '\n';
++ }
++ } else {
++ // sources are not installed
++ llvm::errs() << "llvm-config: sources not installed, "
++ << Arg << " not available\n";
++ exit(1);
++ }
+ } else {
+ usage();
+ }
+diff --git a/utils/llvm-build/llvmbuild/main.py b/utils/llvm-build/llvmbuild/main.py
+index 353741f..4ba5e91 100644
+--- a/utils/llvm-build/llvmbuild/main.py
++++ b/utils/llvm-build/llvmbuild/main.py
+@@ -393,6 +393,8 @@ subdirectories = %s
+ //
+ //===----------------------------------------------------------------------===//
+
++#include "llvm/Config/config.h"
++
+ """)
+ f.write('struct AvailableComponent {\n')
+ f.write(' /// The name of the component.\n')
+@@ -413,7 +415,7 @@ subdirectories = %s
+ if library_name is None:
+ library_name_as_cstr = '0'
+ else:
+- library_name_as_cstr = '"lib%s.a"' % library_name
++ library_name_as_cstr = '"lib%s" LTDL_SHLIB_EXT' % library_name
+ f.write(' { "%s", %s, %d, { %s } },\n' % (
+ name, library_name_as_cstr, is_installed,
+ ', '.join('"%s"' % dep
+--
+2.7.4
+
diff --git a/sys-devel/llvm/files/3.7.1/llvm-config-3.patch b/sys-devel/llvm/files/3.7.1/llvm-config-3.patch
new file mode 100644
index 000000000000..7a1547e255dc
--- /dev/null
+++ b/sys-devel/llvm/files/3.7.1/llvm-config-3.patch
@@ -0,0 +1,29 @@
+From 9308d1858852bdc6f099025ca0482d7b3a32a9aa Mon Sep 17 00:00:00 2001
+From: NAKAMURA Takumi <geek4civic@gmail.com>
+Date: Wed, 10 Feb 2016 01:12:55 +0000
+Subject: [PATCH 4/4] llvm-config: Quick fix for cross compilation. Don't be
+ confsed between host and target. It has been there since r252532.
+
+FIXME: The clause may use conditions of host compiler, not HOST_TRIPLE.
+
+git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@260343 91177308-0d34-0410-b5e6-96231b3b80d8
+---
+ tools/llvm-config/llvm-config.cpp | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/tools/llvm-config/llvm-config.cpp b/tools/llvm-config/llvm-config.cpp
+index 315e5e1..346c9d9 100644
+--- a/tools/llvm-config/llvm-config.cpp
++++ b/tools/llvm-config/llvm-config.cpp
+@@ -327,7 +327,7 @@ int main(int argc, char **argv) {
+
+ StringRef SharedExt, SharedVersionedExt, SharedDir, SharedPrefix, StaticExt,
+ StaticPrefix, StaticDir = "lib";
+- const Triple HostTriple(Triple::normalize(LLVM_DEFAULT_TARGET_TRIPLE));
++ const Triple HostTriple(Triple::normalize(LLVM_HOST_TRIPLE));
+ if (HostTriple.isOSWindows()) {
+ SharedExt = "dll";
+ SharedVersionedExt = PACKAGE_VERSION ".dll";
+--
+2.7.4
+
diff --git a/sys-devel/llvm/files/3.7.1/msan-fix.patch b/sys-devel/llvm/files/3.7.1/msan-fix.patch
new file mode 100644
index 000000000000..e44baa8a5164
--- /dev/null
+++ b/sys-devel/llvm/files/3.7.1/msan-fix.patch
@@ -0,0 +1,79 @@
+From 8b0f2fff6e080c053e4fd94d44a694768b8c156e Mon Sep 17 00:00:00 2001
+From: "H.J. Lu" <hjl.tools@gmail.com>
+Date: Wed, 5 Aug 2015 05:35:26 -0700
+Subject: [PATCH 78/84] Apply split-layout-llvm.patch
+
+https://llvm.org/bugs/show_bug.cgi?id=24155
+---
+ lib/Transforms/Instrumentation/MemorySanitizer.cpp | 31 ++++++++++++++++------
+ 1 file changed, 23 insertions(+), 8 deletions(-)
+
+diff --git a/lib/Transforms/Instrumentation/MemorySanitizer.cpp b/lib/Transforms/Instrumentation/MemorySanitizer.cpp
+index 286a563..2ab8bfc 100644
+--- a/lib/Transforms/Instrumentation/MemorySanitizer.cpp
++++ b/lib/Transforms/Instrumentation/MemorySanitizer.cpp
+@@ -194,6 +194,12 @@ static cl::opt<bool> ClCheckConstantShadow("msan-check-constant-shadow",
+ static const char *const kMsanModuleCtorName = "msan.module_ctor";
+ static const char *const kMsanInitName = "__msan_init";
+
++static cl::opt<bool> ClSplitLayout(
++ "msan-split-layout", cl::desc(
++ "use experimental memory layout compatible with "
++ "non-pie and non-aslr execution"),
++ cl::Hidden, cl::init(true));
++
+ namespace {
+
+ // Memory map parameters used in application-to-shadow address calculation.
+@@ -228,6 +234,13 @@ static const MemoryMapParams Linux_X86_64_MemoryMapParams = {
+ 0x200000000000, // OriginBase
+ };
+
++static const MemoryMapParams Linux_X86_64_Split_MemoryMapParams = {
++ 0, // AndMask (not used)
++ 0x500000000000, // XorMask
++ 0, // ShadowBase (not used)
++ 0x100000000000, // OriginBase
++};
++
+ // mips64 Linux
+ static const MemoryMapParams Linux_MIPS64_MemoryMapParams = {
+ 0x004000000000, // AndMask
+@@ -483,7 +496,8 @@ bool MemorySanitizer::doInitialization(Module &M) {
+ case Triple::Linux:
+ switch (TargetTriple.getArch()) {
+ case Triple::x86_64:
+- MapParams = Linux_X86_MemoryMapParams.bits64;
++ MapParams = ClSplitLayout ? &Linux_X86_64_Split_MemoryMapParams
++ : Linux_X86_MemoryMapParams.bits64;
+ break;
+ case Triple::x86:
+ MapParams = Linux_X86_MemoryMapParams.bits32;
+@@ -893,16 +907,17 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
+ ///
+ /// Offset = (Addr & ~AndMask) ^ XorMask
+ Value *getShadowPtrOffset(Value *Addr, IRBuilder<> &IRB) {
++ Value *OffsetLong = IRB.CreatePointerCast(Addr, MS.IntptrTy);
++
+ uint64_t AndMask = MS.MapParams->AndMask;
+- assert(AndMask != 0 && "AndMask shall be specified");
+- Value *OffsetLong =
+- IRB.CreateAnd(IRB.CreatePointerCast(Addr, MS.IntptrTy),
+- ConstantInt::get(MS.IntptrTy, ~AndMask));
++ if (AndMask)
++ OffsetLong =
++ IRB.CreateAnd(OffsetLong, ConstantInt::get(MS.IntptrTy, ~AndMask));
+
+ uint64_t XorMask = MS.MapParams->XorMask;
+- if (XorMask != 0)
+- OffsetLong = IRB.CreateXor(OffsetLong,
+- ConstantInt::get(MS.IntptrTy, XorMask));
++ if (XorMask)
++ OffsetLong =
++ IRB.CreateXor(OffsetLong, ConstantInt::get(MS.IntptrTy, XorMask));
+ return OffsetLong;
+ }
+
+--
+2.6.4
+