diff options
author | Alexey Samsonov <vonosmas@gmail.com> | 2014-11-19 21:42:33 +0000 |
---|---|---|
committer | Alexey Samsonov <vonosmas@gmail.com> | 2014-11-19 21:42:33 +0000 |
commit | d62165f7c1661a7a4c13b094d82fc3325573365b (patch) | |
tree | f9bdda64e9414eea756ece15ee86653cbed1a6ab | |
parent | 732f63be80ae3b50335d1372ce865279f43ac762 (diff) |
[MSan] [MIPS] Adding support for MIPS64 (patch by Mohit Bhakkad).
Reviewed at http://reviews.llvm.org/D5906
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@222388 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | cmake/config-ix.cmake | 2 | ||||
-rw-r--r-- | lib/msan/CMakeLists.txt | 5 | ||||
-rw-r--r-- | lib/msan/msan.h | 9 | ||||
-rw-r--r-- | lib/msan/msan_allocator.cc | 24 | ||||
-rw-r--r-- | lib/msan/msan_linux.cc | 6 | ||||
-rw-r--r-- | lib/msan/msan_report.cc | 2 | ||||
-rw-r--r-- | lib/sanitizer_common/sanitizer_platform.h | 2 | ||||
-rw-r--r-- | lib/sanitizer_common/sanitizer_posix.cc | 2 | ||||
-rw-r--r-- | lib/sanitizer_common/sanitizer_stacktrace.cc | 8 | ||||
-rw-r--r-- | lib/sanitizer_common/sanitizer_stacktrace.h | 1 |
10 files changed, 49 insertions, 12 deletions
diff --git a/cmake/config-ix.cmake b/cmake/config-ix.cmake index 85cc3cf49..90ab7fb9b 100644 --- a/cmake/config-ix.cmake +++ b/cmake/config-ix.cmake @@ -179,7 +179,7 @@ filter_available_targets(LSAN_SUPPORTED_ARCH x86_64) # by other sanitizers (even if they build into dummy object files). filter_available_targets(LSAN_COMMON_SUPPORTED_ARCH ${SANITIZER_COMMON_SUPPORTED_ARCH}) -filter_available_targets(MSAN_SUPPORTED_ARCH x86_64) +filter_available_targets(MSAN_SUPPORTED_ARCH x86_64 mips64 mips64el) filter_available_targets(PROFILE_SUPPORTED_ARCH x86_64 i386 i686 arm mips mips64 mipsel mips64el aarch64 powerpc64 powerpc64le) filter_available_targets(TSAN_SUPPORTED_ARCH x86_64) diff --git a/lib/msan/CMakeLists.txt b/lib/msan/CMakeLists.txt index 9d1bacb84..90d9face1 100644 --- a/lib/msan/CMakeLists.txt +++ b/lib/msan/CMakeLists.txt @@ -22,8 +22,7 @@ set(MSAN_RUNTIME_LIBRARIES) # Static runtime library. add_custom_target(msan) -set(arch "x86_64") -if(CAN_TARGET_${arch}) +foreach(arch ${MSAN_SUPPORTED_ARCH}) add_compiler_rt_runtime(clang_rt.msan-${arch} ${arch} STATIC SOURCES ${MSAN_RTL_SOURCES} $<TARGET_OBJECTS:RTInterception.${arch}> @@ -36,7 +35,7 @@ if(CAN_TARGET_${arch}) add_sanitizer_rt_symbols(clang_rt.msan-${arch} msan.syms.extra) add_dependencies(msan clang_rt.msan-${arch}-symbols) endif() -endif() +endforeach() add_compiler_rt_resource_file(msan_blacklist msan_blacklist.txt) add_dependencies(msan msan_blacklist) diff --git a/lib/msan/msan.h b/lib/msan/msan.h index f01940bc9..aed873824 100644 --- a/lib/msan/msan.h +++ b/lib/msan/msan.h @@ -25,12 +25,21 @@ # define MSAN_REPLACE_OPERATORS_NEW_AND_DELETE 1 #endif +#if defined(__mips64) +#define MEM_TO_SHADOW(mem) (((uptr)mem) & ~0x4000000000ULL) +#define SHADOW_TO_ORIGIN(shadow) (((uptr)shadow) + 0x2000000000ULL) +#define MEM_TO_ORIGIN(mem) (SHADOW_TO_ORIGIN(MEM_TO_SHADOW(mem))) +#define MEM_IS_APP(mem) ((uptr)mem >= 0xe000000000ULL) +#define MEM_IS_SHADOW(mem) \ + ((uptr)mem >= 0xa000000000ULL && (uptr)mem <= 0xc000000000ULL) +#elif defined(__x86_64__) #define MEM_TO_SHADOW(mem) (((uptr)mem) & ~0x400000000000ULL) #define SHADOW_TO_ORIGIN(shadow) (((uptr)shadow) + 0x200000000000ULL) #define MEM_TO_ORIGIN(mem) (SHADOW_TO_ORIGIN(MEM_TO_SHADOW(mem))) #define MEM_IS_APP(mem) ((uptr)mem >= 0x600000000000ULL) #define MEM_IS_SHADOW(mem) \ ((uptr)mem >= 0x200000000000ULL && (uptr)mem <= 0x400000000000ULL) +#endif // These constants must be kept in sync with the ones in MemorySanitizer.cc. const int kMsanParamTlsSize = 800; diff --git a/lib/msan/msan_allocator.cc b/lib/msan/msan_allocator.cc index cabc94c02..aa1ea1d05 100644 --- a/lib/msan/msan_allocator.cc +++ b/lib/msan/msan_allocator.cc @@ -40,14 +40,26 @@ struct MsanMapUnmapCallback { } }; -static const uptr kAllocatorSpace = 0x600000000000ULL; -static const uptr kAllocatorSize = 0x80000000000; // 8T. -static const uptr kMetadataSize = sizeof(Metadata); -static const uptr kMaxAllowedMallocSize = 8UL << 30; - -typedef SizeClassAllocator64<kAllocatorSpace, kAllocatorSize, kMetadataSize, +#if defined(__mips64) + static const uptr kMaxAllowedMallocSize = 2UL << 30; + static const uptr kRegionSizeLog = 20; + static const uptr kNumRegions = SANITIZER_MMAP_RANGE_SIZE >> kRegionSizeLog; + typedef TwoLevelByteMap<(kNumRegions >> 12), 1 << 12> ByteMap; + typedef CompactSizeClassMap SizeClassMap; + + typedef SizeClassAllocator32<0, SANITIZER_MMAP_RANGE_SIZE, sizeof(Metadata), + SizeClassMap, kRegionSizeLog, ByteMap, + MsanMapUnmapCallback> PrimaryAllocator; +#elif defined(__x86_64__) + static const uptr kAllocatorSpace = 0x600000000000ULL; + 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; typedef CombinedAllocator<PrimaryAllocator, AllocatorCache, diff --git a/lib/msan/msan_linux.cc b/lib/msan/msan_linux.cc index a8fbabb01..2a970c041 100644 --- a/lib/msan/msan_linux.cc +++ b/lib/msan/msan_linux.cc @@ -35,8 +35,14 @@ namespace __msan { +#if defined(__mips64) +static const uptr kMemBeg = 0xe000000000; +static const uptr kMemEnd = 0xffffffffff; +#elif defined(__x86_64__) static const uptr kMemBeg = 0x600000000000; static const uptr kMemEnd = 0x7fffffffffff; +#endif + static const uptr kShadowBeg = MEM_TO_SHADOW(kMemBeg); static const uptr kShadowEnd = MEM_TO_SHADOW(kMemEnd); static const uptr kBad1Beg = 0; diff --git a/lib/msan/msan_report.cc b/lib/msan/msan_report.cc index 0f306375d..f4978c70b 100644 --- a/lib/msan/msan_report.cc +++ b/lib/msan/msan_report.cc @@ -53,7 +53,7 @@ static void DescribeStackOrigin(const char *so, uptr pc) { if (pc) { // For some reason function address in LLVM IR is 1 less then the address // of the first instruction. - pc += 1; + pc = StackTrace::GetNextInstructionPc(pc); StackTrace(&pc, 1).Print(); } } diff --git a/lib/sanitizer_common/sanitizer_platform.h b/lib/sanitizer_common/sanitizer_platform.h index abede8b38..6f8cd30bf 100644 --- a/lib/sanitizer_common/sanitizer_platform.h +++ b/lib/sanitizer_common/sanitizer_platform.h @@ -94,6 +94,8 @@ // but will consume more memory for TwoLevelByteMap. #if defined(__aarch64__) # define SANITIZER_MMAP_RANGE_SIZE FIRST_32_SECOND_64(1ULL << 32, 1ULL << 39) +#elif defined(__mips__) +# define SANITIZER_MMAP_RANGE_SIZE FIRST_32_SECOND_64(1ULL << 32, 1ULL << 40) #else # define SANITIZER_MMAP_RANGE_SIZE FIRST_32_SECOND_64(1ULL << 32, 1ULL << 47) #endif diff --git a/lib/sanitizer_common/sanitizer_posix.cc b/lib/sanitizer_common/sanitizer_posix.cc index 527c24ee7..eb2497b4d 100644 --- a/lib/sanitizer_common/sanitizer_posix.cc +++ b/lib/sanitizer_common/sanitizer_posix.cc @@ -89,7 +89,7 @@ uptr GetMaxVirtualAddress() { # elif defined(__aarch64__) return (1ULL << 39) - 1; # elif defined(__mips64) - return (1ULL << 40) - 1; + return (1ULL << 40) - 1; // 0x000000ffffffffffUL; # else return (1ULL << 47) - 1; // 0x00007fffffffffffUL; # endif diff --git a/lib/sanitizer_common/sanitizer_stacktrace.cc b/lib/sanitizer_common/sanitizer_stacktrace.cc index 04acd5c87..cf061fb8c 100644 --- a/lib/sanitizer_common/sanitizer_stacktrace.cc +++ b/lib/sanitizer_common/sanitizer_stacktrace.cc @@ -32,6 +32,14 @@ uptr StackTrace::GetPreviousInstructionPc(uptr pc) { #endif } +uptr StackTrace::GetNextInstructionPc(uptr pc) { +#if defined(__mips__) + return pc + 8; +#else + return pc + 1; +#endif +} + uptr StackTrace::GetCurrentPc() { return GET_CALLER_PC(); } diff --git a/lib/sanitizer_common/sanitizer_stacktrace.h b/lib/sanitizer_common/sanitizer_stacktrace.h index 6279e1557..e755c052c 100644 --- a/lib/sanitizer_common/sanitizer_stacktrace.h +++ b/lib/sanitizer_common/sanitizer_stacktrace.h @@ -58,6 +58,7 @@ struct StackTrace { static uptr GetCurrentPc(); static uptr GetPreviousInstructionPc(uptr pc); + static uptr GetNextInstructionPc(uptr pc); typedef bool (*SymbolizeCallback)(const void *pc, char *out_buffer, int out_size); }; |