Skip to content

Commit

Permalink
[MSan] [MIPS] Adding support for MIPS64 (patch by Mohit Bhakkad).
Browse files Browse the repository at this point in the history
Reviewed at http://reviews.llvm.org/D5906

llvm-svn: 222388
  • Loading branch information
vonosmas committed Nov 19, 2014
1 parent be6dd81 commit de13018
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 12 deletions.
2 changes: 1 addition & 1 deletion compiler-rt/cmake/config-ix.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 2 additions & 3 deletions compiler-rt/lib/msan/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}>
Expand All @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions compiler-rt/lib/msan/msan.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
24 changes: 18 additions & 6 deletions compiler-rt/lib/msan/msan_allocator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 6 additions & 0 deletions compiler-rt/lib/msan/msan_linux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion compiler-rt/lib/msan/msan_report.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand Down
2 changes: 2 additions & 0 deletions compiler-rt/lib/sanitizer_common/sanitizer_platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion compiler-rt/lib/sanitizer_common/sanitizer_posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
1 change: 1 addition & 0 deletions compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
Expand Down

0 comments on commit de13018

Please sign in to comment.