[compiler-rt] r359286 - [lsan] Use SANITIZER_WORDSIZE when selecting ByteMap

Vitaly Buka via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 26 01:24:38 PDT 2019


Author: vitalybuka
Date: Fri Apr 26 01:24:38 2019
New Revision: 359286

URL: http://llvm.org/viewvc/llvm-project?rev=359286&view=rev
Log:
[lsan] Use SANITIZER_WORDSIZE when selecting ByteMap

Originally this code was added for 64-bit platform and it was never update.
Add static_assert to validate type of ByteMap.

Modified:
    compiler-rt/trunk/lib/lsan/lsan_allocator.h
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator_internal.h
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator_primary32.h
    compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_allocator_test.cc
    compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.h

Modified: compiler-rt/trunk/lib/lsan/lsan_allocator.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/lsan/lsan_allocator.h?rev=359286&r1=359285&r2=359286&view=diff
==============================================================================
--- compiler-rt/trunk/lib/lsan/lsan_allocator.h (original)
+++ compiler-rt/trunk/lib/lsan/lsan_allocator.h Fri Apr 26 01:24:38 2019
@@ -53,9 +53,15 @@ struct ChunkMetadata {
     defined(__arm__)
 static const uptr kRegionSizeLog = 20;
 static const uptr kNumRegions = SANITIZER_MMAP_RANGE_SIZE >> kRegionSizeLog;
+
+#if SANITIZER_WORDSIZE == 32
+template <typename AddressSpaceView>
+using ByteMapASVT = FlatByteMap<kNumRegions, AddressSpaceView>;
+#elif SANITIZER_WORDSIZE == 64
 template <typename AddressSpaceView>
 using ByteMapASVT =
     TwoLevelByteMap<(kNumRegions >> 12), 1 << 12, AddressSpaceView>;
+#endif
 
 template <typename AddressSpaceViewTy>
 struct AP32 {

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator_internal.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator_internal.h?rev=359286&r1=359285&r2=359286&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator_internal.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator_internal.h Fri Apr 26 01:24:38 2019
@@ -27,7 +27,7 @@ static const uptr kInternalAllocatorNumR
     SANITIZER_MMAP_RANGE_SIZE >> kInternalAllocatorRegionSizeLog;
 #if SANITIZER_WORDSIZE == 32
 typedef FlatByteMap<kInternalAllocatorNumRegions> ByteMap;
-#else
+#elif SANITIZER_WORDSIZE == 64
 typedef TwoLevelByteMap<(kInternalAllocatorNumRegions >> 12), 1 << 12> ByteMap;
 #endif
 struct AP32 {

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator_primary32.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator_primary32.h?rev=359286&r1=359285&r2=359286&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator_primary32.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_allocator_primary32.h Fri Apr 26 01:24:38 2019
@@ -41,6 +41,7 @@ struct SizeClassAllocator32FlagMasks {
   enum {
     kRandomShuffleChunks = 1,
     kUseSeparateSizeClassForBatch = 2,
+    kForTest = 4,
   };
 };
 
@@ -56,7 +57,20 @@ class SizeClassAllocator32 {
   typedef typename Params::ByteMap ByteMap;
   typedef typename Params::MapUnmapCallback MapUnmapCallback;
 
+#if SANITIZER_WORDSIZE == 32
+  using BM = FlatByteMap<(Params::kSpaceSize >> Params::kRegionSizeLog),
+                         AddressSpaceView>;
+#elif SANITIZER_WORDSIZE == 64
+  using BM =
+      TwoLevelByteMap<((Params::kSpaceSize >> Params::kRegionSizeLog) >> 12),
+                      1 << 12, AddressSpaceView>;
+#endif
+  static_assert((Params::kFlags & SizeClassAllocator32FlagMasks::kForTest) ||
+                    is_same<BM, ByteMap>::value,
+                "Unexpected ByteMap type");
+
   static_assert(
+
       is_same<typename ByteMap::AddressSpaceView, AddressSpaceView>::value,
       "AddressSpaceView type mismatch");
 

Modified: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_allocator_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_allocator_test.cc?rev=359286&r1=359285&r2=359286&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_allocator_test.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_allocator_test.cc Fri Apr 26 01:24:38 2019
@@ -59,7 +59,7 @@ struct AP64 {  // Allocator Params. Shor
   static const uptr kMetadataSize = 16;
   typedef ::SizeClassMap SizeClassMap;
   typedef NoOpMapUnmapCallback MapUnmapCallback;
-  static const uptr kFlags = 0;
+  static const uptr kFlags = SizeClassAllocator32FlagMasks::kForTest;
   using AddressSpaceView = AddressSpaceViewTy;
 };
 
@@ -70,7 +70,7 @@ struct AP64Dyn {
   static const uptr kMetadataSize = 16;
   typedef ::SizeClassMap SizeClassMap;
   typedef NoOpMapUnmapCallback MapUnmapCallback;
-  static const uptr kFlags = 0;
+  static const uptr kFlags = SizeClassAllocator32FlagMasks::kForTest;
   using AddressSpaceView = AddressSpaceViewTy;
 };
 
@@ -81,7 +81,7 @@ struct AP64Compact {
   static const uptr kMetadataSize = 16;
   typedef CompactSizeClassMap SizeClassMap;
   typedef NoOpMapUnmapCallback MapUnmapCallback;
-  static const uptr kFlags = 0;
+  static const uptr kFlags = SizeClassAllocator32FlagMasks::kForTest;
   using AddressSpaceView = AddressSpaceViewTy;
 };
 
@@ -92,7 +92,7 @@ struct AP64VeryCompact {
   static const uptr kMetadataSize = 16;
   typedef VeryCompactSizeClassMap SizeClassMap;
   typedef NoOpMapUnmapCallback MapUnmapCallback;
-  static const uptr kFlags = 0;
+  static const uptr kFlags = SizeClassAllocator32FlagMasks::kForTest;
   using AddressSpaceView = AddressSpaceViewTy;
 };
 
@@ -103,7 +103,7 @@ struct AP64Dense {
   static const uptr kMetadataSize = 16;
   typedef DenseSizeClassMap SizeClassMap;
   typedef NoOpMapUnmapCallback MapUnmapCallback;
-  static const uptr kFlags = 0;
+  static const uptr kFlags = SizeClassAllocator32FlagMasks::kForTest;
   using AddressSpaceView = AddressSpaceViewTy;
 };
 
@@ -155,7 +155,7 @@ struct AP32Compact {
   using AddressSpaceView = AddressSpaceViewTy;
   using ByteMap = FlatByteMap<kFlatByteMapSize, AddressSpaceView>;
   typedef NoOpMapUnmapCallback MapUnmapCallback;
-  static const uptr kFlags = 0;
+  static const uptr kFlags = SizeClassAllocator32FlagMasks::kForTest;
 };
 template <typename AddressSpaceView>
 using Allocator32CompactASVT =
@@ -302,7 +302,8 @@ struct AP32SeparateBatches {
   using ByteMap = FlatByteMap<kFlatByteMapSize, AddressSpaceView>;
   typedef NoOpMapUnmapCallback MapUnmapCallback;
   static const uptr kFlags =
-      SizeClassAllocator32FlagMasks::kUseSeparateSizeClassForBatch;
+      SizeClassAllocator32FlagMasks::kUseSeparateSizeClassForBatch |
+      SizeClassAllocator32FlagMasks::kForTest;
 };
 template <typename AddressSpaceView>
 using Allocator32SeparateBatchesASVT =
@@ -438,7 +439,7 @@ struct AP64WithCallback {
   static const uptr kMetadataSize = 16;
   typedef ::SizeClassMap SizeClassMap;
   typedef TestMapUnmapCallback MapUnmapCallback;
-  static const uptr kFlags = 0;
+  static const uptr kFlags = SizeClassAllocator32FlagMasks::kForTest;
   using AddressSpaceView = AddressSpaceViewTy;
 };
 
@@ -476,7 +477,7 @@ struct AP32WithCallback {
   using AddressSpaceView = AddressSpaceViewTy;
   using ByteMap = FlatByteMap<kFlatByteMapSize, AddressSpaceView>;
   typedef TestMapUnmapCallback MapUnmapCallback;
-  static const uptr kFlags = 0;
+  static const uptr kFlags = SizeClassAllocator32FlagMasks::kForTest;
 };
 
 TEST(SanitizerCommon, SizeClassAllocator32MapUnmapCallback) {
@@ -1039,7 +1040,7 @@ struct AP64_SpecialSizeClassMap {
   static const uptr kMetadataSize = 0;
   typedef SpecialSizeClassMap SizeClassMap;
   typedef NoOpMapUnmapCallback MapUnmapCallback;
-  static const uptr kFlags = 0;
+  static const uptr kFlags = SizeClassAllocator32FlagMasks::kForTest;
   using AddressSpaceView = AddressSpaceViewTy;
 };
 

Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.h?rev=359286&r1=359285&r2=359286&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.h (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.h Fri Apr 26 01:24:38 2019
@@ -69,7 +69,7 @@ struct AP32 {
   using AddressSpaceView = LocalAddressSpaceView;
   using ByteMap = __tsan::ByteMap;
   typedef __tsan::MapUnmapCallback MapUnmapCallback;
-  static const uptr kFlags = 0;
+  static const uptr kFlags = SizeClassAllocator32FlagMasks::kForTest;
 };
 typedef SizeClassAllocator32<AP32> PrimaryAllocator;
 #else
@@ -79,7 +79,7 @@ struct AP64 {  // Allocator64 parameters
   static const uptr kMetadataSize = 0;
   typedef DefaultSizeClassMap SizeClassMap;
   typedef __tsan::MapUnmapCallback MapUnmapCallback;
-  static const uptr kFlags = 0;
+  static const uptr kFlags = SizeClassAllocator32FlagMasks::kForTest;
   using AddressSpaceView = LocalAddressSpaceView;
 };
 typedef SizeClassAllocator64<AP64> PrimaryAllocator;




More information about the llvm-commits mailing list