[tsan] Disable randomized address space on linux aarch64.
authorYabin Cui <yabinc@google.com>
Tue, 22 Mar 2016 17:16:26 +0000 (17:16 +0000)
committerYabin Cui <yabinc@google.com>
Tue, 22 Mar 2016 17:16:26 +0000 (17:16 +0000)
Summary:
After patch https://lkml.org/lkml/2015/12/21/340 is introduced in
linux kernel, the random gap between stack and heap is increased
from 128M to 36G on 39-bit aarch64. And it is almost impossible
to cover this big range. So I think we need to disable randomized
virtual space on aarch64 linux.

Reviewers: kcc, llvm-commits, eugenis, zatrazz, dvyukov, rengolin

Subscribers: rengolin, aemerson, tberghammer, danalbert, srhines, enh

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

llvm-svn: 264068

compiler-rt/lib/tsan/rtl/tsan_platform_linux.cc

index 3e962fc..aa36fc4 100644 (file)
@@ -36,6 +36,7 @@
 #include <string.h>
 #include <stdarg.h>
 #include <sys/mman.h>
+#include <sys/personality.h>
 #include <sys/syscall.h>
 #include <sys/socket.h>
 #include <sys/time.h>
@@ -291,6 +292,20 @@ void InitializePlatform() {
       SetAddressSpaceUnlimited();
       reexec = true;
     }
+    // After patch "arm64: mm: support ARCH_MMAP_RND_BITS." is introduced in
+    // linux kernel, the random gap between stack and mapped area is increased
+    // from 128M to 36G on 39-bit aarch64. As it is almost impossible to cover
+    // this big range, we should disable randomized virtual space on aarch64.
+#if defined(__aarch64__)
+    int old_personality = personality(0xffffffff);
+    if (old_personality != -1 && (old_personality & ADDR_NO_RANDOMIZE) == 0) {
+      Report("WARNING: Program is run with randomized virtual address space,"
+             " which wouldn't work with ThreadSanitizer.\n");
+      Report("Re-execing with fixed virtual address space.\n");
+      CHECK(personality(old_personality | ADDR_NO_RANDOMIZE) != -1);
+      reexec = true;
+    }
+#endif
     if (reexec)
       ReExec();
   }