[compiler-rt] b4db2a5 - [sanitizer] Fix StackDepotPrintAll
Vitaly Buka via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 12 10:57:49 PDT 2021
Author: Vitaly Buka
Date: 2021-10-12T10:57:40-07:00
New Revision: b4db2a500dca7a427736bc7074023b7c303d5c9d
URL: https://github.com/llvm/llvm-project/commit/b4db2a500dca7a427736bc7074023b7c303d5c9d
DIFF: https://github.com/llvm/llvm-project/commit/b4db2a500dca7a427736bc7074023b7c303d5c9d.diff
LOG: [sanitizer] Fix StackDepotPrintAll
unlock corrupted backets by using s set by loop to nullptr.
Also StackDepot supports iterating without locking.
Reviewed By: dvyukov
Differential Revision: https://reviews.llvm.org/D111599
Added:
Modified:
compiler-rt/lib/sanitizer_common/sanitizer_stackdepotbase.h
compiler-rt/lib/sanitizer_common/tests/sanitizer_stackdepot_test.cpp
Removed:
################################################################################
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_stackdepotbase.h b/compiler-rt/lib/sanitizer_common/sanitizer_stackdepotbase.h
index b7f47b4566abc..309be54a7b349 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_stackdepotbase.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_stackdepotbase.h
@@ -180,14 +180,12 @@ template <class Node, int kReservedBits, int kTabSizeLog>
void StackDepotBase<Node, kReservedBits, kTabSizeLog>::PrintAll() {
for (int i = 0; i < kTabSize; ++i) {
atomic_uintptr_t *p = &tab[i];
- lock(p);
- uptr v = atomic_load(p, memory_order_relaxed);
+ uptr v = atomic_load(p, memory_order_consume);
Node *s = (Node *)(v & ~1UL);
for (; s; s = s->link) {
Printf("Stack for id %u:\n", s->id);
s->load().Print();
}
- unlock(p, s);
}
}
diff --git a/compiler-rt/lib/sanitizer_common/tests/sanitizer_stackdepot_test.cpp b/compiler-rt/lib/sanitizer_common/tests/sanitizer_stackdepot_test.cpp
index 998bda60055df..bc461d621867f 100644
--- a/compiler-rt/lib/sanitizer_common/tests/sanitizer_stackdepot_test.cpp
+++ b/compiler-rt/lib/sanitizer_common/tests/sanitizer_stackdepot_test.cpp
@@ -86,6 +86,22 @@ TEST(SanitizerCommon, Maybe_StackDepotPrint) {
"Stack for id .*#0 0x1.*#1 0x2.*#2 0x3.*#3 0x4.*#4 0x8.*#5 0x9.*");
}
+TEST(SanitizerCommon, StackDepotPrintNoLock) {
+ u32 n = 2000;
+ std::vector<u32> idx2id(n);
+ for (u32 i = 0; i < n; ++i) {
+ uptr array[] = {0x111, 0x222, i, 0x444, 0x777};
+ StackTrace s(array, ARRAY_SIZE(array));
+ idx2id[i] = StackDepotPut(s);
+ }
+ StackDepotPrintAll();
+ for (u32 i = 1; i < n; ++i) {
+ uptr array[] = {0x111, 0x222, i, 0x444, 0x777};
+ StackTrace s(array, ARRAY_SIZE(array));
+ CHECK_EQ(idx2id[i], StackDepotPut(s));
+ }
+}
+
TEST(SanitizerCommon, StackDepotReverseMap) {
uptr array1[] = {1, 2, 3, 4, 5};
uptr array2[] = {7, 1, 3, 0};
More information about the llvm-commits
mailing list