Index: lib/tsan/rtl/tsan_platform_linux.cc =================================================================== --- lib/tsan/rtl/tsan_platform_linux.cc +++ lib/tsan/rtl/tsan_platform_linux.cc @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #include @@ -263,6 +264,20 @@ #endif } +static uptr GetHeapEnd() { + MemoryMappingLayout proc_maps(true); + uptr heap_end = 0; + uptr start, end, prot; + while (proc_maps.Next(&start, &end, 0, 0, 0, &prot)) { + // Omit stack + if (start <= (uptr)&heap_end && (uptr)&heap_end < end) + continue; + if (end > heap_end) + heap_end = end; + } + return heap_end; +} + void InitializePlatform() { DisableCoreDumperIfNecessary(); @@ -291,6 +306,16 @@ SetAddressSpaceUnlimited(); reexec = true; } + int old_personality = personality(0xffffffff); + if (old_personality != -1 && (old_personality & ADDR_NO_RANDOMIZE) == 0) { + if (GetHeapEnd() < HeapMemEnd()) { + Report("WARNING: Program is run with randomized virtual address space," + " and uses heap space out of that assumed by ThreadSanitizer.\n"); + Report("Re-execing with fixed virtual address space.\n"); + CHECK(personality(old_personality | ADDR_NO_RANDOMIZE) != -1); + reexec = true; + } + } if (reexec) ReExec(); }