Index: cmake/config-ix.cmake =================================================================== --- cmake/config-ix.cmake +++ cmake/config-ix.cmake @@ -175,7 +175,7 @@ # 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) filter_available_targets(PROFILE_SUPPORTED_ARCH x86_64 i386 i686 arm mips mips64 mipsel mips64el aarch64) filter_available_targets(TSAN_SUPPORTED_ARCH x86_64) filter_available_targets(UBSAN_SUPPORTED_ARCH x86_64 i386 i686 arm aarch64 mips mipsel) Index: lib/msan/CMakeLists.txt =================================================================== --- lib/msan/CMakeLists.txt +++ lib/msan/CMakeLists.txt @@ -22,8 +22,7 @@ # 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} $ @@ -36,7 +35,7 @@ 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) Index: lib/msan/msan.h =================================================================== --- lib/msan/msan.h +++ lib/msan/msan.h @@ -25,12 +25,21 @@ # define MSAN_REPLACE_OPERATORS_NEW_AND_DELETE 1 #endif +#if defined(__mips64__) && (SANITIZER_WORDSIZE == 64) +#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) +#else #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; Index: lib/msan/msan.cc =================================================================== --- lib/msan/msan.cc +++ lib/msan/msan.cc @@ -508,10 +508,15 @@ } static void* get_tls_base() { + // as this is only relevant for architecture supporting msandr +#ifdef __x86_64__ u64 p; asm("mov %%fs:0, %0" : "=r"(p) ::); return (void*)p; +#else + return 0; +#endif /* __x86_64__ */ } int __msan_get_retval_tls_offset() { Index: lib/msan/msan_allocator.cc =================================================================== --- lib/msan/msan_allocator.cc +++ lib/msan/msan_allocator.cc @@ -40,10 +40,16 @@ } }; +#if defined(__mips64__) && (SANITIZER_WORDSIZE == 64) +static const uptr kAllocatorSpace = 0xf00000000ULL; +static const uptr kAllocatorSize = 0xf00000000; +static const uptr kMaxAllowedMallocSize = 1UL << 37; +#else static const uptr kAllocatorSpace = 0x600000000000ULL; static const uptr kAllocatorSize = 0x80000000000; // 8T. -static const uptr kMetadataSize = sizeof(Metadata); static const uptr kMaxAllowedMallocSize = 8UL << 30; +#endif +static const uptr kMetadataSize = sizeof(Metadata); typedef SizeClassAllocator64= 2^32 + COMPILER_CHECK((kRegionSize) >= (1ULL << (40 / 2))); +#else // kRegionSize must be >= 2^32. COMPILER_CHECK((kRegionSize) >= (1ULL << (SANITIZER_WORDSIZE / 2))); +#endif // Populate the free list with at most this number of bytes at once // or with one element if its size is greater. static const uptr kPopulateSize = 1 << 14; Index: lib/sanitizer_common/sanitizer_platform.h =================================================================== --- lib/sanitizer_common/sanitizer_platform.h +++ lib/sanitizer_common/sanitizer_platform.h @@ -57,7 +57,7 @@ #define SANITIZER_POSIX (SANITIZER_FREEBSD || SANITIZER_LINUX || SANITIZER_MAC) -#if __LP64__ || defined(_WIN64) +#if __LP64__ || defined(_WIN64) || defined(__mips64__) # define SANITIZER_WORDSIZE 64 #else # define SANITIZER_WORDSIZE 32 @@ -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) +#elseif defined(__mips64__) +# 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 Index: lib/sanitizer_common/sanitizer_posix.cc =================================================================== --- lib/sanitizer_common/sanitizer_posix.cc +++ lib/sanitizer_common/sanitizer_posix.cc @@ -89,6 +89,8 @@ return (1ULL << 46) - 1; // 0x00003fffffffffffUL # elif defined(__aarch64__) return (1ULL << 39) - 1; +# elif defined(__mips64__) + return (1ULL << 40) - 1; // 0x000000ffffffffffUL; # else return (1ULL << 47) - 1; // 0x00007fffffffffffUL; # endif