From 5b0cfe93b6cdaf2e0383ed8edaa867430d7e6e4e Mon Sep 17 00:00:00 2001 From: Roland McGrath Date: Fri, 2 Oct 2020 18:12:57 -0700 Subject: [PATCH] Revert "[lsan] Share platform allocator settings between ASan and LSan" This reverts commit 1c897e9d72979730f7555e77dd54fe892a461637. It broke builds for 32-bit targets. Differential Revision: https://reviews.llvm.org/D88768 --- compiler-rt/lib/asan/asan_allocator.h | 51 +++++++++++++++++-------- compiler-rt/lib/lsan/lsan_allocator.h | 51 ++++++++++++++++--------- compiler-rt/lib/lsan/lsan_common.h | 71 +++++++++-------------------------- 3 files changed, 86 insertions(+), 87 deletions(-) diff --git a/compiler-rt/lib/asan/asan_allocator.h b/compiler-rt/lib/asan/asan_allocator.h index c5f6de1..612799f 100644 --- a/compiler-rt/lib/asan/asan_allocator.h +++ b/compiler-rt/lib/asan/asan_allocator.h @@ -15,20 +15,13 @@ #define ASAN_ALLOCATOR_H #include "asan_flags.h" -#include "asan_interceptors.h" #include "asan_internal.h" -#include "lsan/lsan_common.h" +#include "asan_interceptors.h" #include "sanitizer_common/sanitizer_allocator.h" #include "sanitizer_common/sanitizer_list.h" namespace __asan { -// These are defined in lsan_common.h because they are shared between the asan -// allocator and the standalone lsan allocator. -using __lsan::AllocatorSizeClassMap; -using __lsan::kAllocatorSize; -using __lsan::kAllocatorSpace; - enum AllocType { FROM_MALLOC = 1, // Memory block came from malloc, calloc, realloc, etc. FROM_NEW = 2, // Memory block came from operator new. @@ -104,9 +97,9 @@ AsanChunkView FindHeapChunkByAddress(uptr address); AsanChunkView FindHeapChunkByAllocBeg(uptr address); // List of AsanChunks with total size. -class AsanChunkFifoList : public IntrusiveList { +class AsanChunkFifoList: public IntrusiveList { public: - explicit AsanChunkFifoList(LinkerInitialized) {} + explicit AsanChunkFifoList(LinkerInitialized) { } AsanChunkFifoList() { clear(); } void Push(AsanChunk *n); void PushList(AsanChunkFifoList *q); @@ -116,7 +109,6 @@ class AsanChunkFifoList : public IntrusiveList { IntrusiveList::clear(); size_ = 0; } - private: uptr size_; }; @@ -126,9 +118,39 @@ struct AsanMapUnmapCallback { void OnUnmap(uptr p, uptr size) const; }; -using SizeClassMap = AllocatorSizeClassMap; - #if SANITIZER_CAN_USE_ALLOCATOR64 +# if SANITIZER_FUCHSIA +const uptr kAllocatorSpace = ~(uptr)0; +const uptr kAllocatorSize = 0x40000000000ULL; // 4T. +typedef DefaultSizeClassMap SizeClassMap; +# elif defined(__powerpc64__) +const uptr kAllocatorSpace = ~(uptr)0; +const uptr kAllocatorSize = 0x20000000000ULL; // 2T. +typedef DefaultSizeClassMap SizeClassMap; +# elif defined(__aarch64__) && SANITIZER_ANDROID +// Android needs to support 39, 42 and 48 bit VMA. +const uptr kAllocatorSpace = ~(uptr)0; +const uptr kAllocatorSize = 0x2000000000ULL; // 128G. +typedef VeryCompactSizeClassMap SizeClassMap; +# elif defined(__aarch64__) +// AArch64/SANITIZER_CAN_USE_ALLOCATOR64 is only for 42-bit VMA +// so no need to different values for different VMA. +const uptr kAllocatorSpace = 0x10000000000ULL; +const uptr kAllocatorSize = 0x10000000000ULL; // 3T. +typedef DefaultSizeClassMap SizeClassMap; +#elif defined(__sparc__) +const uptr kAllocatorSpace = ~(uptr)0; +const uptr kAllocatorSize = 0x20000000000ULL; // 2T. +typedef DefaultSizeClassMap SizeClassMap; +# elif SANITIZER_WINDOWS +const uptr kAllocatorSpace = ~(uptr)0; +const uptr kAllocatorSize = 0x8000000000ULL; // 500G +typedef DefaultSizeClassMap SizeClassMap; +# else +const uptr kAllocatorSpace = 0x600000000000ULL; +const uptr kAllocatorSize = 0x40000000000ULL; // 4T. +typedef DefaultSizeClassMap SizeClassMap; +# endif template struct AP64 { // Allocator64 parameters. Deliberately using a short name. static const uptr kSpaceBeg = kAllocatorSpace; @@ -157,7 +179,7 @@ struct AP32 { static const uptr kFlags = 0; }; template -using PrimaryAllocatorASVT = SizeClassAllocator32>; +using PrimaryAllocatorASVT = SizeClassAllocator32 >; using PrimaryAllocator = PrimaryAllocatorASVT; #endif // SANITIZER_CAN_USE_ALLOCATOR64 @@ -173,7 +195,6 @@ struct AsanThreadLocalMallocStorage { uptr quarantine_cache[16]; AllocatorCache allocator_cache; void CommitBack(); - private: // These objects are allocated via mmap() and are zero-initialized. AsanThreadLocalMallocStorage() {} diff --git a/compiler-rt/lib/lsan/lsan_allocator.h b/compiler-rt/lib/lsan/lsan_allocator.h index 7ee84e2..17e13cd 100644 --- a/compiler-rt/lib/lsan/lsan_allocator.h +++ b/compiler-rt/lib/lsan/lsan_allocator.h @@ -14,10 +14,10 @@ #ifndef LSAN_ALLOCATOR_H #define LSAN_ALLOCATOR_H -#include "lsan_common.h" #include "sanitizer_common/sanitizer_allocator.h" #include "sanitizer_common/sanitizer_common.h" #include "sanitizer_common/sanitizer_internal_defs.h" +#include "lsan_common.h" namespace __lsan { @@ -28,7 +28,7 @@ void *Reallocate(const StackTrace &stack, void *p, uptr new_size, uptr alignment); uptr GetMallocUsableSize(const void *p); -template +template void ForEachChunk(const Callable &callback); void GetAllocatorCacheRange(uptr *begin, uptr *end); @@ -49,21 +49,8 @@ struct ChunkMetadata { u32 stack_trace_id; }; -#if SANITIZER_CAN_USE_ALLOCATOR64 -template -struct AP64 { // Allocator64 parameters. Deliberately using a short name. - static const uptr kSpaceBeg = kAllocatorSpace; - static const uptr kSpaceSize = kAllocatorSize; - static const uptr kMetadataSize = sizeof(ChunkMetadata); - typedef AllocatorSizeClassMap SizeClassMap; - typedef NoOpMapUnmapCallback MapUnmapCallback; - static const uptr kFlags = 0; - using AddressSpaceView = AddressSpaceViewTy; -}; -template -using PrimaryAllocatorASVT = SizeClassAllocator64>; -using PrimaryAllocator = PrimaryAllocatorASVT; -#else // !SANITIZER_CAN_USE_ALLOCATOR64 +#if defined(__mips64) || defined(__aarch64__) || defined(__i386__) || \ + defined(__arm__) template struct AP32 { static const uptr kSpaceBeg = 0; @@ -78,7 +65,35 @@ struct AP32 { template using PrimaryAllocatorASVT = SizeClassAllocator32>; using PrimaryAllocator = PrimaryAllocatorASVT; -#endif // SANITIZER_CAN_USE_ALLOCATOR64 +#elif defined(__x86_64__) || defined(__powerpc64__) || defined(__s390x__) +# if SANITIZER_FUCHSIA +const uptr kAllocatorSpace = ~(uptr)0; +const uptr kAllocatorSize = 0x40000000000ULL; // 4T. +# elif defined(__powerpc64__) +const uptr kAllocatorSpace = 0xa0000000000ULL; +const uptr kAllocatorSize = 0x20000000000ULL; // 2T. +#elif defined(__s390x__) +const uptr kAllocatorSpace = 0x40000000000ULL; +const uptr kAllocatorSize = 0x40000000000ULL; // 4T. +# else +const uptr kAllocatorSpace = 0x600000000000ULL; +const uptr kAllocatorSize = 0x40000000000ULL; // 4T. +# endif +template +struct AP64 { // Allocator64 parameters. Deliberately using a short name. + static const uptr kSpaceBeg = kAllocatorSpace; + static const uptr kSpaceSize = kAllocatorSize; + static const uptr kMetadataSize = sizeof(ChunkMetadata); + typedef DefaultSizeClassMap SizeClassMap; + typedef NoOpMapUnmapCallback MapUnmapCallback; + static const uptr kFlags = 0; + using AddressSpaceView = AddressSpaceViewTy; +}; + +template +using PrimaryAllocatorASVT = SizeClassAllocator64>; +using PrimaryAllocator = PrimaryAllocatorASVT; +#endif template using AllocatorASVT = CombinedAllocator>; diff --git a/compiler-rt/lib/lsan/lsan_common.h b/compiler-rt/lib/lsan/lsan_common.h index c5ea1eb..3434bee 100644 --- a/compiler-rt/lib/lsan/lsan_common.h +++ b/compiler-rt/lib/lsan/lsan_common.h @@ -37,7 +37,8 @@ #elif defined(__i386__) && \ (SANITIZER_LINUX && !SANITIZER_ANDROID || SANITIZER_MAC) #define CAN_SANITIZE_LEAKS 1 -#elif defined(__arm__) && SANITIZER_LINUX && !SANITIZER_ANDROID +#elif defined(__arm__) && \ + SANITIZER_LINUX && !SANITIZER_ANDROID #define CAN_SANITIZE_LEAKS 1 #elif SANITIZER_NETBSD || SANITIZER_FUCHSIA #define CAN_SANITIZE_LEAKS 1 @@ -49,50 +50,10 @@ namespace __sanitizer { class FlagParser; class ThreadRegistry; struct DTLS; -} // namespace __sanitizer +} namespace __lsan { -// The platform-specific allocator parameters are shared by both -// asan_allocator.h and lsan_allocator.h. -#if SANITIZER_CAN_USE_ALLOCATOR64 -#if SANITIZER_FUCHSIA -constexpr uptr kAllocatorSpace = ~(uptr)0; -constexpr uptr kAllocatorSize = 0x40000000000ULL; // 4T. -using AllocatorSizeClassMap = DefaultSizeClassMap; -#elif defined(__powerpc64__) -constexpr uptr kAllocatorSpace = ~(uptr)0; -constexpr uptr kAllocatorSize = 0x20000000000ULL; // 2T. -using AllocatorSizeClassMap = DefaultSizeClassMap; -#elif defined(__aarch64__) && SANITIZER_ANDROID -// Android needs to support 39, 42 and 48 bit VMA. -constexpr uptr kAllocatorSpace = ~(uptr)0; -constexpr uptr kAllocatorSize = 0x2000000000ULL; // 128G. -using AllocatorSizeClassMap = VeryCompactSizeClassMap; -#elif defined(__aarch64__) -// AArch64/SANITIZER_CAN_USE_ALLOCATOR64 is only for 42-bit VMA -// so no need to different values for different VMA. -constexpr uptr kAllocatorSpace = 0x10000000000ULL; -constexpr uptr kAllocatorSize = 0x10000000000ULL; // 3T. -using AllocatorSizeClassMap = DefaultSizeClassMap; -#elif defined(__sparc__) -constexpr uptr kAllocatorSpace = ~(uptr)0; -constexpr uptr kAllocatorSize = 0x20000000000ULL; // 2T. -using AllocatorSizeClassMap = DefaultSizeClassMap; -#elif SANITIZER_WINDOWS -// On Windows 64-bit there is no easy way to find a large enough fixed address -// space that is always available. Thus, a dynamically allocated address space -// is used instead (i.e. ~(uptr)0). -constexpr uptr kAllocatorSpace = ~(uptr)0; -constexpr uptr kAllocatorSize = 0x8000000000ULL; // 500G -using AllocatorSizeClassMap = DefaultSizeClassMap; -#else -constexpr uptr kAllocatorSpace = 0x600000000000ULL; -constexpr uptr kAllocatorSize = 0x40000000000ULL; // 4T. -using AllocatorSizeClassMap = DefaultSizeClassMap; -#endif -#endif // SANITIZER_CAN_USE_ALLOCATOR64 - // Chunk tags. enum ChunkTag { kDirectlyLeaked = 0, // default @@ -101,7 +62,7 @@ enum ChunkTag { kIgnored = 3 }; -const u32 kInvalidTid = (u32)-1; +const u32 kInvalidTid = (u32) -1; struct Flags { #define LSAN_FLAG(Type, Name, DefaultValue, Description) Type Name; @@ -109,7 +70,9 @@ struct Flags { #undef LSAN_FLAG void SetDefaults(); - uptr pointer_alignment() const { return use_unaligned ? 1 : sizeof(uptr); } + uptr pointer_alignment() const { + return use_unaligned ? 1 : sizeof(uptr); + } }; extern Flags lsan_flags; @@ -176,13 +139,14 @@ struct CheckForLeaksParam { InternalMmapVector const *GetRootRegions(); void ScanRootRegion(Frontier *frontier, RootRegion const ®ion, uptr region_begin, uptr region_end, bool is_readable); -void ForEachExtraStackRangeCb(uptr begin, uptr end, void *arg); +void ForEachExtraStackRangeCb(uptr begin, uptr end, void* arg); // Run stoptheworld while holding any platform-specific locks, as well as the // allocator and thread registry locks. void LockStuffAndStopTheWorld(StopTheWorldCallback callback, - CheckForLeaksParam *argument); + CheckForLeaksParam* argument); -void ScanRangeForPointers(uptr begin, uptr end, Frontier *frontier, +void ScanRangeForPointers(uptr begin, uptr end, + Frontier *frontier, const char *region_type, ChunkTag tag); void ScanGlobalRange(uptr begin, uptr end, Frontier *frontier); @@ -296,7 +260,6 @@ class LsanMetadata { void set_tag(ChunkTag value); uptr requested_size() const; u32 stack_trace_id() const; - private: void *metadata_; }; @@ -304,14 +267,14 @@ class LsanMetadata { } // namespace __lsan extern "C" { -SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE const char * -__lsan_default_options(); +SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE +const char *__lsan_default_options(); -SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE int -__lsan_is_turned_off(); +SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE +int __lsan_is_turned_off(); -SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE const char * -__lsan_default_suppressions(); +SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE +const char *__lsan_default_suppressions(); } // extern "C" #endif // LSAN_COMMON_H -- 2.7.4