From ff3f173e87b9f265a70f834b860c37dbe7256965 Mon Sep 17 00:00:00 2001 From: Alexey Samsonov Date: Mon, 17 Sep 2012 09:14:11 +0000 Subject: [TSan] If we detect an unlimited stack, try to re-exec with limited stack llvm-svn: 164021 --- compiler-rt/lib/tsan/rtl/tsan_platform_linux.cc | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'compiler-rt/lib/tsan') diff --git a/compiler-rt/lib/tsan/rtl/tsan_platform_linux.cc b/compiler-rt/lib/tsan/rtl/tsan_platform_linux.cc index 4a9172d8497..eaaf96e2190 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_platform_linux.cc +++ b/compiler-rt/lib/tsan/rtl/tsan_platform_linux.cc @@ -202,6 +202,17 @@ const char *InitializePlatform() { lim.rlim_max = 0; setrlimit(RLIMIT_CORE, (rlimit*)&lim); } + // TSan doesn't play well with unlimited stack size (as stack + // overlaps with shadow memory). If we detect unlimited stack size, + // we re-exec the program with limited stack size as a best effort. + if (StackSizeIsUnlimited()) { + const uptr kMaxStackSize = 32 * 1024 * 1024; // 32 Mb + Report("WARNING: Program is run with unlimited stack size, which " + "wouldn't work with ThreadSanitizer.\n"); + Report("Re-execing with stack size limited to %zd bytes.\n", kMaxStackSize); + SetStackSizeLimitInBytes(kMaxStackSize); + ReExec(); + } #ifndef TSAN_GO CheckPIE(); -- cgit v1.2.1