summaryrefslogtreecommitdiff
path: root/lib/sanitizer_common/sanitizer_common.cc
diff options
context:
space:
mode:
authorKuba Brecka <kuba.brecka@gmail.com>2016-05-12 12:49:53 +0000
committerKuba Brecka <kuba.brecka@gmail.com>2016-05-12 12:49:53 +0000
commiteaa8017bf73529dd9818abfb40967bce06043124 (patch)
treed522714f6a8e36c2ec2eb6902d5553fb09c27d5f /lib/sanitizer_common/sanitizer_common.cc
parentbb7ed380c4844be2c96852cf59538a28cf6eaa49 (diff)
[sanitizer] Break infinite recursion in case of recursive failed CHECKs
While debugging ASan and TSan, I sometimes get a recursion during a failed CHECK processing. CheckFailed can call a lot of code (printing, unwinding a stack trace, symbolicating, ...) and this can fail another CHECK. This means I sometimes see a crash due to a infinite recursion stack overflow. Let's stop after 10 failed CHECKs and just kill the process immediately. I also added a Sleep(2) call before the trap, so that other threads still get a chance to print their failed CHECKs. Differential Revision: http://reviews.llvm.org/D20047 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@269288 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/sanitizer_common/sanitizer_common.cc')
-rw-r--r--lib/sanitizer_common/sanitizer_common.cc8
1 files changed, 8 insertions, 0 deletions
diff --git a/lib/sanitizer_common/sanitizer_common.cc b/lib/sanitizer_common/sanitizer_common.cc
index 576875f22..fda143e63 100644
--- a/lib/sanitizer_common/sanitizer_common.cc
+++ b/lib/sanitizer_common/sanitizer_common.cc
@@ -153,8 +153,16 @@ void SetCheckFailedCallback(CheckFailedCallbackType callback) {
CheckFailedCallback = callback;
}
+const int kSecondsToSleepWhenRecursiveCheckFailed = 2;
+
void NORETURN CheckFailed(const char *file, int line, const char *cond,
u64 v1, u64 v2) {
+ static atomic_uint32_t num_calls;
+ if (atomic_fetch_add(&num_calls, 1, memory_order_relaxed) > 10) {
+ SleepForSeconds(kSecondsToSleepWhenRecursiveCheckFailed);
+ Trap();
+ }
+
if (CheckFailedCallback) {
CheckFailedCallback(file, line, cond, v1, v2);
}