summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichał Górny <mgorny@gentoo.org>2015-12-27 23:47:38 +0100
committerMichał Górny <mgorny@gentoo.org>2015-12-27 23:51:59 +0100
commit4ea0768355d83631d0baf5c7de9b712ea2ebe12a (patch)
tree15fa6bc310c84f248d57d749f59db7c1442f2bbd /sys-devel/llvm/files
parentdev-util/plan9port: add prefix support, bug #567260 (diff)
downloadgentoo-4ea0768355d83631d0baf5c7de9b712ea2ebe12a.tar.gz
gentoo-4ea0768355d83631d0baf5c7de9b712ea2ebe12a.tar.bz2
gentoo-4ea0768355d83631d0baf5c7de9b712ea2ebe12a.zip
sys-devel/llvm: Backport msan fix for 4.1+ kernels, bug #569894
Diffstat (limited to 'sys-devel/llvm/files')
-rw-r--r--sys-devel/llvm/files/compiler-rt-3.7-msan-fix.patch86
-rw-r--r--sys-devel/llvm/files/llvm-3.7-msan-fix.patch79
2 files changed, 165 insertions, 0 deletions
diff --git a/sys-devel/llvm/files/compiler-rt-3.7-msan-fix.patch b/sys-devel/llvm/files/compiler-rt-3.7-msan-fix.patch
new file mode 100644
index 00000000000..3854a18497b
--- /dev/null
+++ b/sys-devel/llvm/files/compiler-rt-3.7-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/llvm-3.7-msan-fix.patch b/sys-devel/llvm/files/llvm-3.7-msan-fix.patch
new file mode 100644
index 00000000000..e44baa8a516
--- /dev/null
+++ b/sys-devel/llvm/files/llvm-3.7-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
+