diff --git a/compiler-rt/lib/msan/msan.cc b/compiler-rt/lib/msan/msan.cc index e0d1b6cef8cf..e0bff8203120 100644 --- a/compiler-rt/lib/msan/msan.cc +++ b/compiler-rt/lib/msan/msan.cc @@ -240,8 +240,10 @@ void __msan_init() { if (!InitShadow(/* prot1 */false, /* prot2 */true, /* map_shadow */true, __msan_track_origins)) { // FIXME: prot1 = false is only required when running under DR. - Printf("FATAL: MemorySanitizer can not mmap the shadow memory\n"); + Printf("FATAL: MemorySanitizer can not mmap the shadow memory.\n"); Printf("FATAL: Make sure to compile with -fPIE and to link with -pie.\n"); + Printf("FATAL: Disabling ASLR is known to cause this error.\n"); + Printf("FATAL: If running under GDB, try 'set disable-randomization off'.\n"); DumpProcessMap(); Die(); } diff --git a/compiler-rt/lib/msan/msan_linux.cc b/compiler-rt/lib/msan/msan_linux.cc index aea29453c321..b51f63633108 100644 --- a/compiler-rt/lib/msan/msan_linux.cc +++ b/compiler-rt/lib/msan/msan_linux.cc @@ -51,6 +51,12 @@ bool InitShadow(bool prot1, bool prot2, bool map_shadow, bool init_origins) { Printf("Bad1 : %p %p\n", kBad1Beg, kBad1End); } + if (!MemoryRangeIsAvailable(kShadowBeg, + init_origins ? kOriginsEnd : kShadowEnd)) { + Printf("FATAL: Shadow memory range is not available.\n"); + return false; + } + if (prot1 && !Mprotect(kBad1Beg, kBad1End - kBad1Beg)) return false; if (prot2 && !Mprotect(kBad2Beg, kBad2End - kBad2Beg))