[compiler-rt] r200703 - [libsanitizer] Workaround for https://code.google.com/p/address-sanitizer/issues/detail?id=261
Alexander Potapenko
glider at google.com
Mon Feb 3 08:42:29 PST 2014
Author: glider
Date: Mon Feb 3 10:42:29 2014
New Revision: 200703
URL: http://llvm.org/viewvc/llvm-project?rev=200703&view=rev
Log:
[libsanitizer] Workaround for https://code.google.com/p/address-sanitizer/issues/detail?id=261
If pthread_get_stacksize_np() returns 512K for the main thread on Mavericks, obtain the stack size from the current stack rlimit.
Modified:
compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h
compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux_libcdep.cc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h?rev=200703&r1=200702&r2=200703&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h Mon Feb 3 10:42:29 2014
@@ -31,6 +31,8 @@ const uptr kCacheLineSize = 64;
const uptr kMaxPathLength = 512;
+const uptr kMaxThreadStackSize = 1 << 30; // 1Gb
+
extern const char *SanitizerToolName; // Can be changed by the tool.
uptr GetPageSize();
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux_libcdep.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux_libcdep.cc?rev=200703&r1=200702&r2=200703&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux_libcdep.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux_libcdep.cc Mon Feb 3 10:42:29 2014
@@ -62,7 +62,6 @@ int internal_sigaction(int signum, const
void GetThreadStackTopAndBottom(bool at_initialization, uptr *stack_top,
uptr *stack_bottom) {
- static const uptr kMaxThreadStackSize = 1 << 30; // 1Gb
CHECK(stack_top);
CHECK(stack_bottom);
if (at_initialization) {
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc?rev=200703&r1=200702&r2=200703&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_mac.cc Mon Feb 3 10:42:29 2014
@@ -144,6 +144,20 @@ void GetThreadStackTopAndBottom(bool at_
CHECK(stack_top);
CHECK(stack_bottom);
uptr stacksize = pthread_get_stacksize_np(pthread_self());
+ // pthread_get_stacksize_np() returns an incorrect stack size for the main
+ // thread on Mavericks. See
+ // https://code.google.com/p/address-sanitizer/issues/detail?id=261
+ if ((GetMacosVersion() == MACOS_VERSION_MAVERICKS) && at_initialization &&
+ stacksize == (1 << 19)) {
+ struct rlimit rl;
+ CHECK_EQ(getrlimit(RLIMIT_STACK, &rl), 0);
+ // Most often rl.rlim_cur will be the desired 8M.
+ if (rl.rlim_cur < kMaxThreadStackSize) {
+ stacksize = rl.rlim_cur;
+ } else {
+ stacksize = kMaxThreadStackSize;
+ }
+ }
void *stackaddr = pthread_get_stackaddr_np(pthread_self());
*stack_top = (uptr)stackaddr;
*stack_bottom = *stack_top - stacksize;
More information about the llvm-commits
mailing list