[compiler-rt] ed7f3f5 - tsan: move shadow stack into ThreadState
Dmitry Vyukov via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 27 03:54:00 PDT 2021
Author: Dmitry Vyukov
Date: 2021-09-27T12:53:02+02:00
New Revision: ed7f3f5bc99a60b5a5232cb14ffa428a6fc84741
URL: https://github.com/llvm/llvm-project/commit/ed7f3f5bc99a60b5a5232cb14ffa428a6fc84741
DIFF: https://github.com/llvm/llvm-project/commit/ed7f3f5bc99a60b5a5232cb14ffa428a6fc84741.diff
LOG: tsan: move shadow stack into ThreadState
Currently the shadow stack is located in the trace memory mapping.
The new tsan runtime will remove the trace memory mapping.
Move the shadow stack into ThreadState as a preparation step.
Reviewed By: melver
Differential Revision: https://reviews.llvm.org/D110519
Added:
Modified:
compiler-rt/lib/tsan/rtl/tsan_rtl.cpp
compiler-rt/lib/tsan/rtl/tsan_rtl.h
compiler-rt/lib/tsan/rtl/tsan_rtl_thread.cpp
compiler-rt/lib/tsan/tests/unit/tsan_stack_test.cpp
Removed:
################################################################################
diff --git a/compiler-rt/lib/tsan/rtl/tsan_rtl.cpp b/compiler-rt/lib/tsan/rtl/tsan_rtl.cpp
index 19e0f56de630..23fc49defc8a 100644
--- a/compiler-rt/lib/tsan/rtl/tsan_rtl.cpp
+++ b/compiler-rt/lib/tsan/rtl/tsan_rtl.cpp
@@ -145,6 +145,16 @@ ThreadState::ThreadState(Context *ctx, Tid tid, int unique_id, u64 epoch,
last_sleep_clock(tid)
#endif
{
+#if !SANITIZER_GO
+ shadow_stack_pos = shadow_stack;
+ shadow_stack_end = shadow_stack + kShadowStackSize;
+#else
+ // Setup dynamic shadow stack.
+ const int kInitStackSize = 8;
+ shadow_stack = (uptr *)Alloc(kInitStackSize * sizeof(uptr));
+ shadow_stack_pos = shadow_stack;
+ shadow_stack_end = shadow_stack + kInitStackSize;
+#endif
}
#if !SANITIZER_GO
diff --git a/compiler-rt/lib/tsan/rtl/tsan_rtl.h b/compiler-rt/lib/tsan/rtl/tsan_rtl.h
index 3a5c129509cd..b3d2463e3fa6 100644
--- a/compiler-rt/lib/tsan/rtl/tsan_rtl.h
+++ b/compiler-rt/lib/tsan/rtl/tsan_rtl.h
@@ -159,10 +159,12 @@ struct ThreadState {
#if !SANITIZER_GO
IgnoreSet mop_ignore_set;
IgnoreSet sync_ignore_set;
-#endif
- // C/C++ uses fixed size shadow stack embed into Trace.
+ // C/C++ uses fixed size shadow stack.
+ uptr shadow_stack[kShadowStackSize];
+#else
// Go uses malloc-allocated shadow stack with dynamic size.
uptr *shadow_stack;
+#endif
uptr *shadow_stack_end;
uptr *shadow_stack_pos;
RawShadow *racy_shadow_addr;
diff --git a/compiler-rt/lib/tsan/rtl/tsan_rtl_thread.cpp b/compiler-rt/lib/tsan/rtl/tsan_rtl_thread.cpp
index 70575754ef70..89178a1699ba 100644
--- a/compiler-rt/lib/tsan/rtl/tsan_rtl_thread.cpp
+++ b/compiler-rt/lib/tsan/rtl/tsan_rtl_thread.cpp
@@ -190,17 +190,6 @@ void ThreadContext::OnStarted(void *arg) {
new (thr)
ThreadState(ctx, tid, unique_id, epoch0, reuse_count, args->stk_addr,
args->stk_size, args->tls_addr, args->tls_size);
-#if !SANITIZER_GO
- thr->shadow_stack = &ThreadTrace(thr->tid)->shadow_stack[0];
- thr->shadow_stack_pos = thr->shadow_stack;
- thr->shadow_stack_end = thr->shadow_stack + kShadowStackSize;
-#else
- // Setup dynamic shadow stack.
- const int kInitStackSize = 8;
- thr->shadow_stack = (uptr *)Alloc(kInitStackSize * sizeof(uptr));
- thr->shadow_stack_pos = thr->shadow_stack;
- thr->shadow_stack_end = thr->shadow_stack + kInitStackSize;
-#endif
if (common_flags()->detect_deadlocks)
thr->dd_lt = ctx->dd->CreateLogicalThread(unique_id);
thr->fast_state.SetHistorySize(flags()->history_size);
diff --git a/compiler-rt/lib/tsan/tests/unit/tsan_stack_test.cpp b/compiler-rt/lib/tsan/tests/unit/tsan_stack_test.cpp
index f2ee1265c31b..23590caa3019 100644
--- a/compiler-rt/lib/tsan/tests/unit/tsan_stack_test.cpp
+++ b/compiler-rt/lib/tsan/tests/unit/tsan_stack_test.cpp
@@ -19,10 +19,6 @@ namespace __tsan {
template <typename StackTraceTy>
static void TestStackTrace(StackTraceTy *trace) {
ThreadState thr(0, 0, 0, 0, 0, 0, 0, 0, 0);
- uptr stack[128];
- thr.shadow_stack = &stack[0];
- thr.shadow_stack_pos = &stack[0];
- thr.shadow_stack_end = &stack[128];
ObtainCurrentStack(&thr, 0, trace);
EXPECT_EQ(0U, trace->size);
@@ -48,13 +44,8 @@ static void TestStackTrace(StackTraceTy *trace) {
template<typename StackTraceTy>
static void TestTrim(StackTraceTy *trace) {
ThreadState thr(0, 0, 0, 0, 0, 0, 0, 0, 0);
- const uptr kShadowStackSize = 2 * kStackTraceMax;
- uptr stack[kShadowStackSize];
- thr.shadow_stack = &stack[0];
- thr.shadow_stack_pos = &stack[0];
- thr.shadow_stack_end = &stack[kShadowStackSize];
- for (uptr i = 0; i < kShadowStackSize; ++i)
+ for (uptr i = 0; i < 2 * kStackTraceMax; ++i)
*thr.shadow_stack_pos++ = 100 + i;
ObtainCurrentStack(&thr, 0, trace);
More information about the llvm-commits
mailing list