diff options
author | Vitaly Buka <vitalybuka@google.com> | 2019-04-26 04:20:27 +0000 |
---|---|---|
committer | Vitaly Buka <vitalybuka@google.com> | 2019-04-26 04:20:27 +0000 |
commit | 3db2a7a04f8775ebbf52c0ec1679540c1d730cb0 (patch) | |
tree | 68bb340cf7d1cc510774a782773b5c6930b7a564 /compiler-rt | |
parent | 98b70f6705f5aefb9fadb4b2e23db9dc5f3d12ef (diff) | |
download | bcm5719-llvm-3db2a7a04f8775ebbf52c0ec1679540c1d730cb0.tar.gz bcm5719-llvm-3db2a7a04f8775ebbf52c0ec1679540c1d730cb0.zip |
[lsan] Use SANITIZER_WORDSIZE when selecting ByteMap
Originally this code as added for 64-bit platform and was never changed.
Add static_assert to make sure that we have correct map on all platforms.
llvm-svn: 359269
Diffstat (limited to 'compiler-rt')
5 files changed, 34 insertions, 13 deletions
diff --git a/compiler-rt/lib/lsan/lsan_allocator.h b/compiler-rt/lib/lsan/lsan_allocator.h index 2d6b21a0301..e3bdfe8fe1c 100644 --- a/compiler-rt/lib/lsan/lsan_allocator.h +++ b/compiler-rt/lib/lsan/lsan_allocator.h @@ -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 { diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_allocator_internal.h b/compiler-rt/lib/sanitizer_common/sanitizer_allocator_internal.h index c5250b97095..7066e35813d 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_allocator_internal.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_allocator_internal.h @@ -27,7 +27,7 @@ static const uptr kInternalAllocatorNumRegions = 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 { diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_allocator_primary32.h b/compiler-rt/lib/sanitizer_common/sanitizer_allocator_primary32.h index 26b19d03731..dc7e5dd5398 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_allocator_primary32.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_allocator_primary32.h @@ -41,6 +41,7 @@ struct SizeClassAllocator32FlagMasks { // Bit masks. 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, MapUnmapCallback>; +#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"); diff --git a/compiler-rt/lib/sanitizer_common/tests/sanitizer_allocator_test.cc b/compiler-rt/lib/sanitizer_common/tests/sanitizer_allocator_test.cc index ec130f3d572..0173254eb52 100644 --- a/compiler-rt/lib/sanitizer_common/tests/sanitizer_allocator_test.cc +++ b/compiler-rt/lib/sanitizer_common/tests/sanitizer_allocator_test.cc @@ -59,7 +59,7 @@ struct AP64 { // Allocator Params. Short name for shorter demangled names.. 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; }; diff --git a/compiler-rt/lib/tsan/rtl/tsan_rtl.h b/compiler-rt/lib/tsan/rtl/tsan_rtl.h index c618e50ae6f..a3568c33974 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_rtl.h +++ b/compiler-rt/lib/tsan/rtl/tsan_rtl.h @@ -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. Deliberately using a short name. 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; |