Enable memory sanitizer for PPC64

Summary:
This patch adds basic memory sanitizer support for PPC64. PR23219.

I have further patches ready to enable it in LLVM and Clang, and to fix
most of the many failing tests in check-msan.

Reviewers: kcc, willschm, samsonov, wschmidt, eugenis

Reviewed By: eugenis

Subscribers: wschmidt, llvm-commits

Differential Revision: http://reviews.llvm.org/D10648

llvm-svn: 240623
This commit is contained in:
Jay Foad 2015-06-25 06:22:31 +00:00
parent 88e0f9206b
commit 8677baf024
7 changed files with 41 additions and 1 deletions

View File

@ -251,7 +251,8 @@ filter_available_targets(ASAN_SUPPORTED_ARCH
x86_64 i386 i686 powerpc64 powerpc64le arm mips mipsel mips64 mips64el)
filter_available_targets(DFSAN_SUPPORTED_ARCH x86_64 mips64 mips64el)
filter_available_targets(LSAN_SUPPORTED_ARCH x86_64 mips64 mips64el)
filter_available_targets(MSAN_SUPPORTED_ARCH x86_64 mips64 mips64el)
filter_available_targets(MSAN_SUPPORTED_ARCH x86_64 mips64 mips64el
powerpc64 powerpc64le)
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 mips64 mips64el)

View File

@ -52,6 +52,25 @@ const MappingDesc kMemoryLayout[] = {
#define MEM_TO_SHADOW(mem) (((uptr)(mem)) & ~0x4000000000ULL)
#define SHADOW_TO_ORIGIN(shadow) (((uptr)(shadow)) + 0x002000000000)
#elif SANITIZER_LINUX && defined(__powerpc64__)
const MappingDesc kMemoryLayout[] = {
{0x000000000000ULL, 0x000100000000ULL, MappingDesc::APP, "low memory"},
{0x000100000000ULL, 0x080000000000ULL, MappingDesc::INVALID, "invalid"},
{0x080000000000ULL, 0x180100000000ULL, MappingDesc::SHADOW, "shadow"},
{0x180100000000ULL, 0x1C0000000000ULL, MappingDesc::INVALID, "invalid"},
{0x1C0000000000ULL, 0x2C0100000000ULL, MappingDesc::ORIGIN, "origin"},
{0x2C0100000000ULL, 0x300000000000ULL, MappingDesc::INVALID, "invalid"},
{0x300000000000ULL, 0x400000000000ULL, MappingDesc::APP, "high memory"}};
// Maps low and high app ranges to contiguous space with zero base:
// Low: 0000 0000 0000 - 0000 ffff ffff -> 1000 0000 0000 - 1000 ffff ffff
// High: 3000 0000 0000 - 3fff ffff ffff -> 0000 0000 0000 - 0fff ffff ffff
#define LINEARIZE_MEM(mem) \
(((uptr)(mem) & ~0x200000000000ULL) ^ 0x100000000000ULL)
#define MEM_TO_SHADOW(mem) (LINEARIZE_MEM((mem)) + 0x080000000000ULL)
#define SHADOW_TO_ORIGIN(shadow) (((uptr)(shadow)) + 0x140000000000ULL)
#elif SANITIZER_FREEBSD && SANITIZER_WORDSIZE == 64
// Low memory: main binary, MAP_32BIT mappings and modules

View File

@ -55,6 +55,15 @@ struct MsanMapUnmapCallback {
static const uptr kMetadataSize = sizeof(Metadata);
static const uptr kMaxAllowedMallocSize = 8UL << 30;
typedef SizeClassAllocator64<kAllocatorSpace, kAllocatorSize, kMetadataSize,
DefaultSizeClassMap,
MsanMapUnmapCallback> PrimaryAllocator;
#elif defined(__powerpc64__)
static const uptr kAllocatorSpace = 0x300000000000;
static const uptr kAllocatorSize = 0x020000000000; // 2T
static const uptr kMetadataSize = sizeof(Metadata);
static const uptr kMaxAllowedMallocSize = 2UL << 30; // 2G
typedef SizeClassAllocator64<kAllocatorSpace, kAllocatorSize, kMetadataSize,
DefaultSizeClassMap,
MsanMapUnmapCallback> PrimaryAllocator;

View File

@ -20,6 +20,8 @@ namespace __sanitizer {
uptr StackTrace::GetNextInstructionPc(uptr pc) {
#if defined(__mips__)
return pc + 8;
#elif defined(__powerpc__)
return pc + 4;
#else
return pc + 1;
#endif

View File

@ -16,6 +16,8 @@ bool AddrIsApp(void *p) {
return addr >= 0x600000000000ULL;
#elif defined(__mips64)
return addr >= 0x00e000000000ULL;
#elif defined(__powerpc64__)
return addr < 0x000100000000ULL || addr >= 0x300000000000ULL;
#endif
}

View File

@ -24,6 +24,9 @@ int main(void) {
#elif defined (__mips64)
uintptr_t hint = 0x4f00000000ULL;
const uintptr_t app_start = 0x6000000000ULL;
#elif defined (__powerpc64__)
uintptr_t hint = 0x2f0000000000ULL;
const uintptr_t app_start = 0x300000000000ULL;
#endif
uintptr_t p = (uintptr_t)mmap(
(void *)hint, 4096, PROT_WRITE,

View File

@ -13,6 +13,10 @@ const char *mem_to_shadow(const char *p) {
return (char *)((uintptr_t)p & ~0x400000000000ULL);
#elif defined (__mips64)
return (char *)((uintptr_t)p & ~0x4000000000ULL);
#elif defined(__powerpc64__)
#define LINEARIZE_MEM(mem) \
(((uintptr_t)(mem) & ~0x200000000000ULL) ^ 0x100000000000ULL)
return (char *)(LINEARIZE_MEM(p) + 0x080000000000ULL);
#endif
}