From 99fc4d3d1636c81dad5b9c9c4537347c44fa5065 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Fri, 30 Dec 2022 19:43:19 -0800 Subject: [PATCH] [msan] Remove non-working MSAN_LINUX_X86_64_OLD_MAPPING r249754 (2015) added this macro (not set anywhere) for an escape hatch. This old layout has been non-working for many years (Linux arch/x86/include/asm/elf.h ELF_ET_DYN_BASE is outside the APP range): FATAL: Code 0x558547327980 is out of application range. Non-PIE build? FATAL: MemorySanitizer can not mmap the shadow memory. FATAL: Make sure to compile with -fPIE and to link with -pie. FATAL: Disabling ASLR is known to cause this error. FATAL: If running under GDB, try 'set disable-randomization off'. Non-pie doesn't work either. --- compiler-rt/lib/msan/msan.h | 14 -------------- compiler-rt/lib/msan/msan_allocator.cpp | 3 +-- llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp | 7 ------- 3 files changed, 1 insertion(+), 23 deletions(-) diff --git a/compiler-rt/lib/msan/msan.h b/compiler-rt/lib/msan/msan.h index 3d53f90..5d8ea52 100644 --- a/compiler-rt/lib/msan/msan.h +++ b/compiler-rt/lib/msan/msan.h @@ -170,19 +170,6 @@ const MappingDesc kMemoryLayout[] = { #elif SANITIZER_NETBSD || (SANITIZER_LINUX && SANITIZER_WORDSIZE == 64) -#ifdef MSAN_LINUX_X86_64_OLD_MAPPING -// Requires PIE binary and ASLR enabled. -// Main thread stack and DSOs at 0x7f0000000000 (sometimes 0x7e0000000000). -// Heap at 0x600000000000. -const MappingDesc kMemoryLayout[] = { - {0x000000000000ULL, 0x200000000000ULL, MappingDesc::INVALID, "invalid"}, - {0x200000000000ULL, 0x400000000000ULL, MappingDesc::SHADOW, "shadow"}, - {0x400000000000ULL, 0x600000000000ULL, MappingDesc::ORIGIN, "origin"}, - {0x600000000000ULL, 0x800000000000ULL, MappingDesc::APP, "app"}}; - -#define MEM_TO_SHADOW(mem) (((uptr)(mem)) & ~0x400000000000ULL) -#define SHADOW_TO_ORIGIN(mem) (((uptr)(mem)) + 0x200000000000ULL) -#else // MSAN_LINUX_X86_64_OLD_MAPPING // All of the following configurations are supported. // ASLR disabled: main executable and DSOs at 0x555550000000 // PIE and ASLR: main executable and DSOs at 0x7f0000000000 @@ -203,7 +190,6 @@ const MappingDesc kMemoryLayout[] = { {0x700000000000ULL, 0x800000000000ULL, MappingDesc::APP, "app-3"}}; #define MEM_TO_SHADOW(mem) (((uptr)(mem)) ^ 0x500000000000ULL) #define SHADOW_TO_ORIGIN(mem) (((uptr)(mem)) + 0x100000000000ULL) -#endif // MSAN_LINUX_X86_64_OLD_MAPPING #else #error "Unsupported platform" diff --git a/compiler-rt/lib/msan/msan_allocator.cpp b/compiler-rt/lib/msan/msan_allocator.cpp index 051a9cb..53f47bd 100644 --- a/compiler-rt/lib/msan/msan_allocator.cpp +++ b/compiler-rt/lib/msan/msan_allocator.cpp @@ -59,8 +59,7 @@ struct AP32 { }; typedef SizeClassAllocator32 PrimaryAllocator; #elif defined(__x86_64__) -#if SANITIZER_NETBSD || \ - (SANITIZER_LINUX && !defined(MSAN_LINUX_X86_64_OLD_MAPPING)) +#if SANITIZER_NETBSD || SANITIZER_LINUX static const uptr kAllocatorSpace = 0x700000000000ULL; #else static const uptr kAllocatorSpace = 0x600000000000ULL; diff --git a/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp b/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp index e9939c9..ff65400 100644 --- a/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp +++ b/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp @@ -396,17 +396,10 @@ static const MemoryMapParams Linux_I386_MemoryMapParams = { // x86_64 Linux static const MemoryMapParams Linux_X86_64_MemoryMapParams = { -#ifdef MSAN_LINUX_X86_64_OLD_MAPPING - 0x400000000000, // AndMask - 0, // XorMask (not used) - 0, // ShadowBase (not used) - 0x200000000000, // OriginBase -#else 0, // AndMask (not used) 0x500000000000, // XorMask 0, // ShadowBase (not used) 0x100000000000, // OriginBase -#endif }; // mips64 Linux -- 2.7.4