[dfsan] Add origin ABI wrappers for thread/signal/fork
This is a part of https://reviews.llvm.org/D95835.
See https://github.com/llvm/llvm-project/commit/bb91e02efd00eda04296069a83228c8d9db105b7 about the similar issue of fork in MSan's origin tracking.
Reviewed By: morehouse
Differential Revision: https://reviews.llvm.org/D98359
diff --git a/compiler-rt/test/dfsan/atomic.cpp b/compiler-rt/test/dfsan/atomic.cpp
index 7d4dc04..459bf31 100644
--- a/compiler-rt/test/dfsan/atomic.cpp
+++ b/compiler-rt/test/dfsan/atomic.cpp
@@ -1,4 +1,7 @@
// RUN: %clangxx_dfsan -mllvm -dfsan-fast-16-labels=true %s -fno-exceptions -o %t && %run %t
+// RUN: %clangxx_dfsan -DORIGIN_TRACKING -mllvm -dfsan-track-origins=1 -mllvm -dfsan-fast-16-labels=true %s -fno-exceptions -o %t && %run %t
+//
+// REQUIRES: x86_64-target-arch
//
// Use -fno-exceptions to turn off exceptions to avoid instrumenting
// __cxa_begin_catch, std::terminate and __gxx_personality_v0.
@@ -14,31 +17,45 @@
std::atomic<int> atomic_i{0};
+struct arg_struct {
+ size_t index;
+ dfsan_origin origin;
+};
+
static void *ThreadFn(void *arg) {
- if ((size_t)arg % 2) {
+ if (((arg_struct *)arg)->index % 2) {
int i = 10;
dfsan_set_label(8, (void *)&i, sizeof(i));
atomic_i.store(i, std::memory_order_relaxed);
-
return 0;
}
int j = atomic_i.load();
assert(dfsan_get_label(j) == 0 || dfsan_get_label(j) == 2);
-
+#ifdef ORIGIN_TRACKING
+ if (dfsan_get_label(j) == 2)
+ assert(dfsan_get_init_origin(&j) == ((arg_struct *)arg)->origin);
+#endif
return 0;
}
int main(void) {
int i = 10;
dfsan_set_label(2, (void *)&i, sizeof(i));
+#ifdef ORIGIN_TRACKING
+ dfsan_origin origin = dfsan_get_origin(i);
+#endif
atomic_i.store(i, std::memory_order_relaxed);
const int kNumThreads = 24;
pthread_t t[kNumThreads];
+ arg_struct args[kNumThreads];
for (int i = 0; i < kNumThreads; ++i) {
- pthread_create(&t[i], 0, ThreadFn, (void *)i);
+ args[i].index = i;
+#ifdef ORIGIN_TRACKING
+ args[i].origin = origin;
+#endif
+ pthread_create(&t[i], 0, ThreadFn, (void *)(args + i));
}
- for (int i = 0; i < kNumThreads; ++i) {
+ for (int i = 0; i < kNumThreads; ++i)
pthread_join(t[i], 0);
- }
return 0;
}