[arch-commits] Commit in llvm/trunk (3 files)

Evangelos Foutras foutrelis at archlinux.org
Sat Oct 31 12:13:58 UTC 2015


    Date: Saturday, October 31, 2015 @ 13:13:58
  Author: foutrelis
Revision: 249890

upgpkg: llvm 3.7.0-5

Add upstream memory sanitizer patches for new memory mapping in Linux 4.1 (FS#46913).

Added:
  llvm/trunk/0001-New-MSan-mapping-layout-compiler-rt-part.patch
  llvm/trunk/0001-New-MSan-mapping-layout-llvm-part.patch
Modified:
  llvm/trunk/PKGBUILD

-----------------------------------------------------+
 0001-New-MSan-mapping-layout-compiler-rt-part.patch |  142 ++++++++++++++++++
 0001-New-MSan-mapping-layout-llvm-part.patch        |  115 ++++++++++++++
 PKGBUILD                                            |   10 +
 3 files changed, 266 insertions(+), 1 deletion(-)

Added: 0001-New-MSan-mapping-layout-compiler-rt-part.patch
===================================================================
--- 0001-New-MSan-mapping-layout-compiler-rt-part.patch	                        (rev 0)
+++ 0001-New-MSan-mapping-layout-compiler-rt-part.patch	2015-10-31 12:13:58 UTC (rev 249890)
@@ -0,0 +1,142 @@
+From 0bee2d927c97454e629b0789c7f4e3d509cf4178 Mon Sep 17 00:00:00 2001
+From: Evgeniy Stepanov <eugeni.stepanov at gmail.com>
+Date: Thu, 8 Oct 2015 21:35:34 +0000
+Subject: [PATCH] New MSan mapping layout (compiler-rt part).
+
+This is an implementation of
+https://github.com/google/sanitizers/issues/579
+
+It has a number of advantages over the current mapping:
+* Works for non-PIE executables.
+* Does not require ASLR; as a consequence, debugging MSan programs in
+  gdb no longer requires "set disable-randomization off".
+* Supports linux kernels >=4.1.2.
+* The code is marginally faster and smaller.
+
+This is an ABI break. We never really promised ABI stability, but
+this patch includes a courtesy escape hatch: a compile-time macro
+that reverts back to the old mapping layout.
+
+git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@249754 91177308-0d34-0410-b5e6-96231b3b80d8
+---
+ lib/msan/msan.h                                    | 23 ++++++++++++++++++++++
+ lib/msan/msan_allocator.cc                         |  8 +++++++-
+ test/msan/mmap.cc                                  |  4 +++-
+ test/msan/strlen_of_shadow.cc                      |  2 +-
+ .../TestCases/Posix/decorate_proc_maps.cc          |  4 ++--
+ 5 files changed, 36 insertions(+), 5 deletions(-)
+
+diff --git a/lib/msan/msan.h b/lib/msan/msan.h
+index 3776fa9..2d77983 100644
+--- a/lib/msan/msan.h
++++ b/lib/msan/msan.h
+@@ -135,6 +135,7 @@ const MappingDesc kMemoryLayout[] = {
+ 
+ #elif SANITIZER_LINUX && SANITIZER_WORDSIZE == 64
+ 
++#ifdef MSAN_LINUX_X86_64_OLD_MAPPING
+ // Requries PIE binary and ASLR enabled.
+ // Main thread stack and DSOs at 0x7f0000000000 (sometimes 0x7e0000000000).
+ // Heap at 0x600000000000.
+@@ -146,6 +147,28 @@ const MappingDesc kMemoryLayout[] = {
+ 
+ #define MEM_TO_SHADOW(mem) (((uptr)(mem)) & ~0x400000000000ULL)
+ #define SHADOW_TO_ORIGIN(mem) (((uptr)(mem)) + 0x200000000000ULL)
++#else  // MSAN_LINUX_X86_64_OLD_MAPPING
++// 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, 0x010000000000ULL, MappingDesc::APP, "app-1"},
++    {0x010000000000ULL, 0x100000000000ULL, MappingDesc::SHADOW, "shadow-2"},
++    {0x100000000000ULL, 0x110000000000ULL, MappingDesc::INVALID, "invalid"},
++    {0x110000000000ULL, 0x200000000000ULL, MappingDesc::ORIGIN, "origin-2"},
++    {0x200000000000ULL, 0x300000000000ULL, MappingDesc::SHADOW, "shadow-3"},
++    {0x300000000000ULL, 0x400000000000ULL, MappingDesc::ORIGIN, "origin-3"},
++    {0x400000000000ULL, 0x500000000000ULL, MappingDesc::INVALID, "invalid"},
++    {0x500000000000ULL, 0x510000000000ULL, MappingDesc::SHADOW, "shadow-1"},
++    {0x510000000000ULL, 0x600000000000ULL, MappingDesc::APP, "app-2"},
++    {0x600000000000ULL, 0x610000000000ULL, MappingDesc::ORIGIN, "origin-1"},
++    {0x610000000000ULL, 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)
++#endif  // MSAN_LINUX_X86_64_OLD_MAPPING
+ 
+ #else
+ #error "Unsupported platform"
+diff --git a/lib/msan/msan_allocator.cc b/lib/msan/msan_allocator.cc
+index 865a458..b7d3947 100644
+--- a/lib/msan/msan_allocator.cc
++++ b/lib/msan/msan_allocator.cc
+@@ -49,15 +49,21 @@ struct MsanMapUnmapCallback {
+   typedef SizeClassAllocator32<0, SANITIZER_MMAP_RANGE_SIZE, sizeof(Metadata),
+                                SizeClassMap, kRegionSizeLog, ByteMap,
+                                MsanMapUnmapCallback> PrimaryAllocator;
++
+ #elif defined(__x86_64__)
++#if SANITIZER_LINUX && !defined(MSAN_LINUX_X86_64_OLD_MAPPING)
++  static const uptr kAllocatorSpace = 0x700000000000ULL;
++#else
+   static const uptr kAllocatorSpace = 0x600000000000ULL;
+-  static const uptr kAllocatorSize   = 0x80000000000;  // 8T.
++#endif
++  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;
++
+ #elif defined(__powerpc64__)
+   static const uptr kAllocatorSpace = 0x300000000000;
+   static const uptr kAllocatorSize  = 0x020000000000;  // 2T
+diff --git a/test/msan/mmap.cc b/test/msan/mmap.cc
+index 250ce34..962836c 100644
+--- a/test/msan/mmap.cc
++++ b/test/msan/mmap.cc
+@@ -15,7 +15,9 @@ bool AddrIsApp(void *p) {
+ #if defined(__FreeBSD__) && defined(__x86_64__)
+   return addr < 0x010000000000ULL || addr >= 0x600000000000ULL;
+ #elif defined(__x86_64__)
+-  return addr >= 0x600000000000ULL;
++  return (addr >= 0x000000000000ULL && addr < 0x010000000000ULL) ||
++         (addr >= 0x510000000000ULL && addr < 0x600000000000ULL) ||
++         (addr >= 0x700000000000ULL && addr < 0x800000000000ULL);
+ #elif defined(__mips64)
+   return addr >= 0x00e000000000ULL;
+ #elif defined(__powerpc64__)
+diff --git a/test/msan/strlen_of_shadow.cc b/test/msan/strlen_of_shadow.cc
+index fee9223..0594f00 100644
+--- a/test/msan/strlen_of_shadow.cc
++++ b/test/msan/strlen_of_shadow.cc
+@@ -12,7 +12,7 @@
+ 
+ const char *mem_to_shadow(const char *p) {
+ #if defined(__x86_64__)
+-  return (char *)((uintptr_t)p & ~0x400000000000ULL);
++  return (char *)((uintptr_t)p ^ 0x500000000000ULL);
+ #elif defined (__mips64)
+   return (char *)((uintptr_t)p & ~0x4000000000ULL);
+ #elif defined(__powerpc64__)
+diff --git a/test/sanitizer_common/TestCases/Posix/decorate_proc_maps.cc b/test/sanitizer_common/TestCases/Posix/decorate_proc_maps.cc
+index 8744c3f..36d4df5 100644
+--- a/test/sanitizer_common/TestCases/Posix/decorate_proc_maps.cc
++++ b/test/sanitizer_common/TestCases/Posix/decorate_proc_maps.cc
+@@ -47,8 +47,8 @@ int main(void) {
+ // CHECK-asan: rw-p {{.*}} [high shadow]
+ 
+ // CHECK-msan: ---p {{.*}} [invalid]
+-// CHECK-msan: rw-p {{.*}} [shadow]
+-// CHECK-msan: ---p {{.*}} [origin]
++// CHECK-msan: rw-p {{.*}} [shadow{{.*}}]
++// CHECK-msan: ---p {{.*}} [origin{{.*}}]
+ 
+ // CHECK-tsan: rw-p {{.*}} [shadow]
+ // CHECK-tsan: rw-p {{.*}} [meta shadow]
+-- 
+2.6.1
+

Added: 0001-New-MSan-mapping-layout-llvm-part.patch
===================================================================
--- 0001-New-MSan-mapping-layout-llvm-part.patch	                        (rev 0)
+++ 0001-New-MSan-mapping-layout-llvm-part.patch	2015-10-31 12:13:58 UTC (rev 249890)
@@ -0,0 +1,115 @@
+From 2c87d24da09ecd2c14c38a0b4f7a0e3f332b08ee Mon Sep 17 00:00:00 2001
+From: Evgeniy Stepanov <eugeni.stepanov at gmail.com>
+Date: Thu, 8 Oct 2015 21:35:26 +0000
+Subject: [PATCH] New MSan mapping layout (llvm part).
+
+This is an implementation of
+https://github.com/google/sanitizers/issues/579
+
+It has a number of advantages over the current mapping:
+* Works for non-PIE executables.
+* Does not require ASLR; as a consequence, debugging MSan programs in
+  gdb no longer requires "set disable-randomization off".
+* Supports linux kernels >=4.1.2.
+* The code is marginally faster and smaller.
+
+This is an ABI break. We never really promised ABI stability, but
+this patch includes a courtesy escape hatch: a compile-time macro
+that reverts back to the old mapping layout.
+
+git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@249753 91177308-0d34-0410-b5e6-96231b3b80d8
+---
+ lib/Transforms/Instrumentation/MemorySanitizer.cpp | 22 +++++++++++++++-------
+ .../MemorySanitizer/origin-alignment.ll            | 10 ++++++----
+ 2 files changed, 21 insertions(+), 11 deletions(-)
+
+diff --git a/lib/Transforms/Instrumentation/MemorySanitizer.cpp b/lib/Transforms/Instrumentation/MemorySanitizer.cpp
+index 9d4c7de..bc6da5a 100644
+--- a/lib/Transforms/Instrumentation/MemorySanitizer.cpp
++++ b/lib/Transforms/Instrumentation/MemorySanitizer.cpp
+@@ -232,10 +232,17 @@ static const MemoryMapParams Linux_I386_MemoryMapParams = {
+ 
+ // x86_64 Linux
+ static const MemoryMapParams Linux_X86_64_MemoryMapParams = {
++#ifdef MSAN_LINUX_X86_64_OLD_MAPPING
+   0x400000000000,  // AndMask
+   0,               // XorMask (not used)
+   0,               // ShadowBase (not used)
+   0x200000000000,  // OriginBase
++#else
++  0,               // AndMask (not used)
++  0x500000000000,  // XorMask
++  0,               // ShadowBase (not used)
++  0x100000000000,  // OriginBase
++#endif
+ };
+ 
+ // mips64 Linux
+@@ -926,16 +933,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;
+   }
+ 
+diff --git a/test/Instrumentation/MemorySanitizer/origin-alignment.ll b/test/Instrumentation/MemorySanitizer/origin-alignment.ll
+index ce0dbfc..562d194 100644
+--- a/test/Instrumentation/MemorySanitizer/origin-alignment.ll
++++ b/test/Instrumentation/MemorySanitizer/origin-alignment.ll
+@@ -24,7 +24,7 @@ entry:
+ ; CHECK-ORIGINS1: [[ORIGIN:%[01-9a-z]+]] = load {{.*}} @__msan_param_origin_tls
+ ; CHECK-ORIGINS2: [[ORIGIN0:%[01-9a-z]+]] = load {{.*}} @__msan_param_origin_tls
+ ; CHECK-ORIGINS2: [[ORIGIN:%[01-9a-z]+]] = call i32 @__msan_chain_origin(i32 [[ORIGIN0]])
+-; CHECK: store i32 [[ORIGIN]],  i32* inttoptr (i64 add (i64 and (i64 ptrtoint {{.*}} to i32*), align 8
++; CHECK: store i32 [[ORIGIN]], i32* inttoptr (i64 add (i64 xor (i64 ptrtoint (i8* @a8 to i64), i64 {{.*}}), i64 {{.*}}) to i32*), align 8
+ ; CHECK: ret void
+ 
+ 
+@@ -39,7 +39,7 @@ entry:
+ ; CHECK-ORIGINS1: [[ORIGIN:%[01-9a-z]+]] = load {{.*}} @__msan_param_origin_tls
+ ; CHECK-ORIGINS2: [[ORIGIN0:%[01-9a-z]+]] = load {{.*}} @__msan_param_origin_tls
+ ; CHECK-ORIGINS2: [[ORIGIN:%[01-9a-z]+]] = call i32 @__msan_chain_origin(i32 [[ORIGIN0]])
+-; CHECK: store i32 [[ORIGIN]],  i32* inttoptr (i64 add (i64 and (i64 ptrtoint {{.*}} to i32*), align 4
++; CHECK: store i32 [[ORIGIN]], i32* inttoptr (i64 add (i64 xor (i64 ptrtoint (i8* @a4 to i64), i64 {{.*}}), i64 {{.*}}) to i32*), align 4
+ ; CHECK: ret void
+ 
+ 
+@@ -54,7 +54,8 @@ entry:
+ ; CHECK-ORIGINS1: [[ORIGIN:%[01-9a-z]+]] = load {{.*}} @__msan_param_origin_tls
+ ; CHECK-ORIGINS2: [[ORIGIN0:%[01-9a-z]+]] = load {{.*}} @__msan_param_origin_tls
+ ; CHECK-ORIGINS2: [[ORIGIN:%[01-9a-z]+]] = call i32 @__msan_chain_origin(i32 [[ORIGIN0]])
+-; CHECK: store i32 [[ORIGIN]],  i32* inttoptr (i64 and (i64 add (i64 and (i64 ptrtoint {{.*}} i64 -4) to i32*), align 4
++; CHECK: store i32 [[ORIGIN]],  i32* inttoptr (i64 and (i64 add (i64 xor (i64 ptrtoint (i8* @a2 to i64), i64 {{.*}}), i64 {{.*}}), i64 -4) to i32*), align 4
++
+ ; CHECK: ret void
+ 
+ 
+@@ -69,5 +70,6 @@ entry:
+ ; CHECK-ORIGINS1: [[ORIGIN:%[01-9a-z]+]] = load {{.*}} @__msan_param_origin_tls
+ ; CHECK-ORIGINS2: [[ORIGIN0:%[01-9a-z]+]] = load {{.*}} @__msan_param_origin_tls
+ ; CHECK-ORIGINS2: [[ORIGIN:%[01-9a-z]+]] = call i32 @__msan_chain_origin(i32 [[ORIGIN0]])
+-; CHECK: store i32 [[ORIGIN]],  i32* inttoptr (i64 and (i64 add (i64 and (i64 ptrtoint {{.*}} i64 -4) to i32*), align 4
++; CHECK: store i32 [[ORIGIN]], i32* inttoptr (i64 and (i64 add (i64 xor (i64 ptrtoint (i8* @a1 to i64), i64 {{.*}}), i64 {{.*}}), i64 -4) to i32*), align 4
++
+ ; CHECK: ret void
+-- 
+2.6.1
+

Modified: PKGBUILD
===================================================================
--- PKGBUILD	2015-10-31 11:05:14 UTC (rev 249889)
+++ PKGBUILD	2015-10-31 12:13:58 UTC (rev 249890)
@@ -12,7 +12,7 @@
 pkgname=('llvm' 'llvm-libs' 'llvm-ocaml' 'lldb' 'clang' 'clang-analyzer'
          'clang-tools-extra')
 pkgver=3.7.0
-pkgrel=4
+pkgrel=5
 _ocaml_ver=4.02.3
 arch=('i686' 'x86_64')
 url="http://llvm.org/"
@@ -31,6 +31,8 @@
         llvm-3.7.0-export-more-symbols.patch
         clang-tools-extra-3.7.0-install-clang-query.patch
         lldb-3.7.0-avoid-linking-to-libLLVM.patch
+        0001-New-MSan-mapping-layout-llvm-part.patch
+        0001-New-MSan-mapping-layout-compiler-rt-part.patch
         llvm-Config-llvm-config.h)
 sha256sums=('ab45895f9dcdad1e140a3a79fd709f64b05ad7364e308c0e582c5b02e9cc3153'
             'SKIP'
@@ -46,6 +48,8 @@
             'a1c9f36b97c639666ab6a1bd647a08a027e93e3d3cfd6f5af9c36e757599ce81'
             '3abf85430c275ecb8dbb526ecb82b1c9f4b4f782a8a43b5a06d040ec0baba7e7'
             '2d53b6ed4c7620eeade87e7761b98093a0434801ddd599056daed7881141fb01'
+            'c5f4e329143bef36b623ba5daf311b5a73fa99ab05fed4ba506c1c3bc4cf5ee7'
+            'f44e8fe3cef9b6f706d651f443922261e1dcf53bcaabdd0ac7edb1758e4bc44d'
             '597dc5968c695bbdbb0eac9e8eb5117fcd2773bc91edf5ec103ecffffab8bc48')
 validpgpkeys=('11E521D646982372EB577A1F8F0871F202119294'
               'B6C8F98282B944E3B0D5C2530FC3042E345AD05D')
@@ -77,6 +81,10 @@
   # https://llvm.org/bugs/show_bug.cgi?id=24953
   patch -d tools/lldb -Np1 <../lldb-3.7.0-avoid-linking-to-libLLVM.patch
 
+  # https://llvm.org/bugs/show_bug.cgi?id=24155
+  patch -Np1 -i ../0001-New-MSan-mapping-layout-llvm-part.patch
+  patch -d projects/compiler-rt -Np1 <../0001-New-MSan-mapping-layout-compiler-rt-part.patch
+
   # Use Python 2
   find tools/lldb -name Makefile -exec sed -i 's/python-config/python2-config/' {} +
   sed -i 's|/usr/bin/env python|&2|' \



More information about the arch-commits mailing list