[compiler-rt] 9766ce4 - [lsan] Add `thread_suspend_fail` flag
Vitaly Buka via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 4 23:19:15 PDT 2024
Author: Vitaly Buka
Date: 2024-10-04T22:53:37-07:00
New Revision: 9766ce4db57212646f135fe7033972a7a51aef4d
URL: https://github.com/llvm/llvm-project/commit/9766ce4db57212646f135fe7033972a7a51aef4d
DIFF: https://github.com/llvm/llvm-project/commit/9766ce4db57212646f135fe7033972a7a51aef4d.diff
LOG: [lsan] Add `thread_suspend_fail` flag
Added:
Modified:
compiler-rt/lib/lsan/lsan_common.cpp
compiler-rt/lib/lsan/lsan_flags.inc
Removed:
################################################################################
diff --git a/compiler-rt/lib/lsan/lsan_common.cpp b/compiler-rt/lib/lsan/lsan_common.cpp
index 183df6e5ca14bd..966e74d7ffbb52 100644
--- a/compiler-rt/lib/lsan/lsan_common.cpp
+++ b/compiler-rt/lib/lsan/lsan_common.cpp
@@ -702,7 +702,7 @@ static void ReportUnsuspendedThreads(const SuspendedThreadsList &) {}
# else // !SANITIZER_FUCHSIA
-static void ReportUnsuspendedThreads(
+static bool ReportUnsuspendedThreads(
const SuspendedThreadsList &suspended_threads) {
InternalMmapVector<tid_t> threads(suspended_threads.ThreadCount());
for (uptr i = 0; i < suspended_threads.ThreadCount(); ++i)
@@ -713,13 +713,17 @@ static void ReportUnsuspendedThreads(
InternalMmapVector<tid_t> unsuspended;
GetRunningThreadsLocked(&unsuspended);
+ bool succeded = true;
for (auto os_id : unsuspended) {
uptr i = InternalLowerBound(threads, os_id);
- if (i >= threads.size() || threads[i] != os_id)
+ if (i >= threads.size() || threads[i] != os_id) {
+ succeded = false;
Report(
"Running thread %zu was not suspended. False leaks are possible.\n",
os_id);
+ }
}
+ return succeded;
}
# endif // !SANITIZER_FUCHSIA
@@ -729,7 +733,18 @@ static void CheckForLeaksCallback(const SuspendedThreadsList &suspended_threads,
CheckForLeaksParam *param = reinterpret_cast<CheckForLeaksParam *>(arg);
CHECK(param);
CHECK(!param->success);
- ReportUnsuspendedThreads(suspended_threads);
+ if (!ReportUnsuspendedThreads(suspended_threads)) {
+ switch (flags()->thread_suspend_fail) {
+ case 0:
+ param->success = true;
+ return;
+ case 1:
+ break;
+ case 2:
+ // Will crash on return.
+ return;
+ }
+ }
ClassifyAllChunks(suspended_threads, ¶m->frontier, param->caller_tid,
param->caller_sp);
ForEachChunk(CollectLeaksCb, ¶m->leaks);
diff --git a/compiler-rt/lib/lsan/lsan_flags.inc b/compiler-rt/lib/lsan/lsan_flags.inc
index 9350f4bcdc34b3..b7f28223b8189b 100644
--- a/compiler-rt/lib/lsan/lsan_flags.inc
+++ b/compiler-rt/lib/lsan/lsan_flags.inc
@@ -44,3 +44,7 @@ LSAN_FLAG(bool, use_poisoned, false,
LSAN_FLAG(bool, log_pointers, false, "Debug logging")
LSAN_FLAG(bool, log_threads, false, "Debug logging")
LSAN_FLAG(const char *, suppressions, "", "Suppressions file name.")
+LSAN_FLAG(int, thread_suspend_fail, 1,
+ "Behaviour if thread suspendion all thread (0 - "
+ "abandon leak checking, 1 - continue with leak checking (reported "
+ "leaks can be false), 2 - crash (for debugging LSAN)).")
\ No newline at end of file
More information about the llvm-commits
mailing list