[compiler-rt] r367567 - compiler-rt: Rename .cc file in lib/tsan/{benchmarks, dd, go} to .cpp
Nico Weber via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 1 07:30:49 PDT 2019
Author: nico
Date: Thu Aug 1 07:30:49 2019
New Revision: 367567
URL: http://llvm.org/viewvc/llvm-project?rev=367567&view=rev
Log:
compiler-rt: Rename .cc file in lib/tsan/{benchmarks,dd,go} to .cpp
Like r367463, but for tsan/{benchmarks,dd,go}.
The files benchmarks aren't referenced in the build anywhere and where added
in 2012 with the comment "no Makefiles yet".
Added:
compiler-rt/trunk/lib/tsan/benchmarks/func_entry_exit.cpp
- copied unchanged from r367566, compiler-rt/trunk/lib/tsan/benchmarks/func_entry_exit.cc
compiler-rt/trunk/lib/tsan/benchmarks/mini_bench_local.cpp
- copied unchanged from r367566, compiler-rt/trunk/lib/tsan/benchmarks/mini_bench_local.cc
compiler-rt/trunk/lib/tsan/benchmarks/mini_bench_shared.cpp
- copied unchanged from r367566, compiler-rt/trunk/lib/tsan/benchmarks/mini_bench_shared.cc
compiler-rt/trunk/lib/tsan/benchmarks/mop.cpp
- copied unchanged from r367566, compiler-rt/trunk/lib/tsan/benchmarks/mop.cc
compiler-rt/trunk/lib/tsan/benchmarks/start_many_threads.cpp
- copied unchanged from r367566, compiler-rt/trunk/lib/tsan/benchmarks/start_many_threads.cc
compiler-rt/trunk/lib/tsan/benchmarks/vts_many_threads_bench.cpp
- copied unchanged from r367566, compiler-rt/trunk/lib/tsan/benchmarks/vts_many_threads_bench.cc
compiler-rt/trunk/lib/tsan/dd/dd_interceptors.cpp
- copied, changed from r367566, compiler-rt/trunk/lib/tsan/dd/dd_interceptors.cc
compiler-rt/trunk/lib/tsan/dd/dd_rtl.cpp
- copied, changed from r367566, compiler-rt/trunk/lib/tsan/dd/dd_rtl.cc
compiler-rt/trunk/lib/tsan/go/tsan_go.cpp
- copied, changed from r367566, compiler-rt/trunk/lib/tsan/go/tsan_go.cc
Removed:
compiler-rt/trunk/lib/tsan/benchmarks/func_entry_exit.cc
compiler-rt/trunk/lib/tsan/benchmarks/mini_bench_local.cc
compiler-rt/trunk/lib/tsan/benchmarks/mini_bench_shared.cc
compiler-rt/trunk/lib/tsan/benchmarks/mop.cc
compiler-rt/trunk/lib/tsan/benchmarks/start_many_threads.cc
compiler-rt/trunk/lib/tsan/benchmarks/vts_many_threads_bench.cc
compiler-rt/trunk/lib/tsan/dd/dd_interceptors.cc
compiler-rt/trunk/lib/tsan/dd/dd_rtl.cc
compiler-rt/trunk/lib/tsan/go/tsan_go.cc
Modified:
compiler-rt/trunk/lib/tsan/dd/CMakeLists.txt
compiler-rt/trunk/lib/tsan/go/build.bat
compiler-rt/trunk/lib/tsan/go/buildgo.sh
Removed: compiler-rt/trunk/lib/tsan/benchmarks/func_entry_exit.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/benchmarks/func_entry_exit.cc?rev=367566&view=auto
==============================================================================
--- compiler-rt/trunk/lib/tsan/benchmarks/func_entry_exit.cc (original)
+++ compiler-rt/trunk/lib/tsan/benchmarks/func_entry_exit.cc (removed)
@@ -1,20 +0,0 @@
-// Synthetic benchmark for __tsan_func_entry/exit (spends ~75% there).
-
-void foo(bool x);
-
-int main() {
- volatile int kRepeat1 = 1 << 30;
- const int kRepeat = kRepeat1;
- for (int i = 0; i < kRepeat; i++)
- foo(false);
-}
-
-__attribute__((noinline)) void bar(volatile bool x) {
- if (x)
- foo(x);
-}
-
-__attribute__((noinline)) void foo(bool x) {
- if (__builtin_expect(x, false))
- bar(x);
-}
Removed: compiler-rt/trunk/lib/tsan/benchmarks/mini_bench_local.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/benchmarks/mini_bench_local.cc?rev=367566&view=auto
==============================================================================
--- compiler-rt/trunk/lib/tsan/benchmarks/mini_bench_local.cc (original)
+++ compiler-rt/trunk/lib/tsan/benchmarks/mini_bench_local.cc (removed)
@@ -1,49 +0,0 @@
-// Mini-benchmark for tsan: non-shared memory writes.
-#include <pthread.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <assert.h>
-
-int len;
-int *a;
-const int kNumIter = 1000;
-
-__attribute__((noinline))
-void Run(int idx) {
- for (int i = 0, n = len; i < n; i++)
- a[i + idx * n] = i;
-}
-
-void *Thread(void *arg) {
- long idx = (long)arg;
- printf("Thread %ld started\n", idx);
- for (int i = 0; i < kNumIter; i++)
- Run(idx);
- printf("Thread %ld done\n", idx);
- return 0;
-}
-
-int main(int argc, char **argv) {
- int n_threads = 0;
- if (argc != 3) {
- n_threads = 4;
- len = 1000000;
- } else {
- n_threads = atoi(argv[1]);
- assert(n_threads > 0 && n_threads <= 32);
- len = atoi(argv[2]);
- }
- printf("%s: n_threads=%d len=%d iter=%d\n",
- __FILE__, n_threads, len, kNumIter);
- a = new int[n_threads * len];
- pthread_t *t = new pthread_t[n_threads];
- for (int i = 0; i < n_threads; i++) {
- pthread_create(&t[i], 0, Thread, (void*)i);
- }
- for (int i = 0; i < n_threads; i++) {
- pthread_join(t[i], 0);
- }
- delete [] t;
- delete [] a;
- return 0;
-}
Removed: compiler-rt/trunk/lib/tsan/benchmarks/mini_bench_shared.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/benchmarks/mini_bench_shared.cc?rev=367566&view=auto
==============================================================================
--- compiler-rt/trunk/lib/tsan/benchmarks/mini_bench_shared.cc (original)
+++ compiler-rt/trunk/lib/tsan/benchmarks/mini_bench_shared.cc (removed)
@@ -1,51 +0,0 @@
-// Mini-benchmark for tsan: shared memory reads.
-#include <pthread.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <assert.h>
-
-int len;
-int *a;
-const int kNumIter = 1000;
-
-__attribute__((noinline))
-void Run(int idx) {
- for (int i = 0, n = len; i < n; i++)
- if (a[i] != i) abort();
-}
-
-void *Thread(void *arg) {
- long idx = (long)arg;
- printf("Thread %ld started\n", idx);
- for (int i = 0; i < kNumIter; i++)
- Run(idx);
- printf("Thread %ld done\n", idx);
- return 0;
-}
-
-int main(int argc, char **argv) {
- int n_threads = 0;
- if (argc != 3) {
- n_threads = 4;
- len = 1000000;
- } else {
- n_threads = atoi(argv[1]);
- assert(n_threads > 0 && n_threads <= 32);
- len = atoi(argv[2]);
- }
- printf("%s: n_threads=%d len=%d iter=%d\n",
- __FILE__, n_threads, len, kNumIter);
- a = new int[len];
- for (int i = 0, n = len; i < n; i++)
- a[i] = i;
- pthread_t *t = new pthread_t[n_threads];
- for (int i = 0; i < n_threads; i++) {
- pthread_create(&t[i], 0, Thread, (void*)i);
- }
- for (int i = 0; i < n_threads; i++) {
- pthread_join(t[i], 0);
- }
- delete [] t;
- delete [] a;
- return 0;
-}
Removed: compiler-rt/trunk/lib/tsan/benchmarks/mop.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/benchmarks/mop.cc?rev=367566&view=auto
==============================================================================
--- compiler-rt/trunk/lib/tsan/benchmarks/mop.cc (original)
+++ compiler-rt/trunk/lib/tsan/benchmarks/mop.cc (removed)
@@ -1,80 +0,0 @@
-// Synthetic benchmark for __tsan_read/write{1,2,4,8}.
-// As compared to mini_bench_local/shared.cc this benchmark passes through
-// deduplication logic (ContainsSameAccess).
-// First argument is access size (1, 2, 4, 8). Second optional arg switches
-// from writes to reads.
-
-#include <pthread.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <linux/futex.h>
-#include <sys/syscall.h>
-#include <sys/time.h>
-
-template<typename T, bool write>
-void* thread(void *arg) {
- const int kSize = 2 << 10;
- static volatile long data[kSize];
- static volatile long turn;
- const int kRepeat = 1 << 17;
- const int id = !!arg;
- for (int i = 0; i < kRepeat; i++) {
- for (;;) {
- int t = __atomic_load_n(&turn, __ATOMIC_ACQUIRE);
- if (t == id)
- break;
- syscall(SYS_futex, &turn, FUTEX_WAIT, t, 0, 0, 0);
- }
- for (int j = 0; j < kSize; j++) {
- if (write) {
- ((volatile T*)&data[j])[0] = 1;
- ((volatile T*)&data[j])[sizeof(T) == 8 ? 0 : 1] = 1;
- } else {
- T v0 = ((volatile T*)&data[j])[0];
- T v1 = ((volatile T*)&data[j])[sizeof(T) == 8 ? 0 : 1];
- (void)v0;
- (void)v1;
- }
- }
- __atomic_store_n(&turn, 1 - id, __ATOMIC_RELEASE);
- syscall(SYS_futex, &turn, FUTEX_WAKE, 0, 0, 0, 0);
- }
- return 0;
-}
-
-template<typename T, bool write>
-void test() {
- pthread_t th;
- pthread_create(&th, 0, thread<T, write>, (void*)1);
- thread<T, write>(0);
- pthread_join(th, 0);
-}
-
-template<bool write>
-void testw(int size) {
- switch (size) {
- case 1: return test<char, write>();
- case 2: return test<short, write>();
- case 4: return test<int, write>();
- case 8: return test<long long, write>();
- }
-}
-
-int main(int argc, char** argv) {
- int size = 8;
- bool write = true;
- if (argc > 1) {
- size = atoi(argv[1]);
- if (size != 1 && size != 2 && size != 4 && size != 8)
- size = 8;
- }
- if (argc > 2)
- write = false;
- printf("%s%d\n", write ? "write" : "read", size);
- if (write)
- testw<true>(size);
- else
- testw<false>(size);
- return 0;
-}
Removed: compiler-rt/trunk/lib/tsan/benchmarks/start_many_threads.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/benchmarks/start_many_threads.cc?rev=367566&view=auto
==============================================================================
--- compiler-rt/trunk/lib/tsan/benchmarks/start_many_threads.cc (original)
+++ compiler-rt/trunk/lib/tsan/benchmarks/start_many_threads.cc (removed)
@@ -1,52 +0,0 @@
-// Mini-benchmark for creating a lot of threads.
-//
-// Some facts:
-// a) clang -O1 takes <15ms to start N=500 threads,
-// consuming ~4MB more RAM than N=1.
-// b) clang -O1 -ftsan takes ~26s to start N=500 threads,
-// eats 5GB more RAM than N=1 (which is somewhat expected but still a lot)
-// but then it consumes ~4GB of extra memory when the threads shut down!
-// (definitely not in the barrier_wait interceptor)
-// Also, it takes 26s to run with N=500 vs just 1.1s to run with N=1.
-#include <assert.h>
-#include <pthread.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-
-pthread_barrier_t all_threads_ready;
-
-void* Thread(void *unused) {
- pthread_barrier_wait(&all_threads_ready);
- return 0;
-}
-
-int main(int argc, char **argv) {
- int n_threads;
- if (argc == 1) {
- n_threads = 100;
- } else if (argc == 2) {
- n_threads = atoi(argv[1]);
- } else {
- printf("Usage: %s n_threads\n", argv[0]);
- return 1;
- }
- printf("%s: n_threads=%d\n", __FILE__, n_threads);
-
- pthread_barrier_init(&all_threads_ready, NULL, n_threads + 1);
-
- pthread_t *t = new pthread_t[n_threads];
- for (int i = 0; i < n_threads; i++) {
- int status = pthread_create(&t[i], 0, Thread, (void*)i);
- assert(status == 0);
- }
- // sleep(5); // FIXME: simplify measuring the memory usage.
- pthread_barrier_wait(&all_threads_ready);
- for (int i = 0; i < n_threads; i++) {
- pthread_join(t[i], 0);
- }
- // sleep(5); // FIXME: simplify measuring the memory usage.
- delete [] t;
-
- return 0;
-}
Removed: compiler-rt/trunk/lib/tsan/benchmarks/vts_many_threads_bench.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/benchmarks/vts_many_threads_bench.cc?rev=367566&view=auto
==============================================================================
--- compiler-rt/trunk/lib/tsan/benchmarks/vts_many_threads_bench.cc (original)
+++ compiler-rt/trunk/lib/tsan/benchmarks/vts_many_threads_bench.cc (removed)
@@ -1,120 +0,0 @@
-// Mini-benchmark for tsan VTS worst case performance
-// Idea:
-// 1) Spawn M + N threads (M >> N)
-// We'll call the 'M' threads as 'garbage threads'.
-// 2) Make sure all threads have created thus no TIDs were reused
-// 3) Join the garbage threads
-// 4) Do many sync operations on the remaining N threads
-//
-// It turns out that due to O(M+N) VTS complexity the (4) is much slower with
-// when N is large.
-//
-// Some numbers:
-// a) clang++ native O1 with n_iterations=200kk takes
-// 5s regardless of M
-// clang++ tsanv2 O1 with n_iterations=20kk takes
-// 23.5s with M=200
-// 11.5s with M=1
-// i.e. tsanv2 is ~23x to ~47x slower than native, depends on M.
-// b) g++ native O1 with n_iterations=200kk takes
-// 5.5s regardless of M
-// g++ tsanv1 O1 with n_iterations=2kk takes
-// 39.5s with M=200
-// 20.5s with M=1
-// i.e. tsanv1 is ~370x to ~720x slower than native, depends on M.
-
-#include <assert.h>
-#include <pthread.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-class __attribute__((aligned(64))) Mutex {
- public:
- Mutex() { pthread_mutex_init(&m_, NULL); }
- ~Mutex() { pthread_mutex_destroy(&m_); }
- void Lock() { pthread_mutex_lock(&m_); }
- void Unlock() { pthread_mutex_unlock(&m_); }
-
- private:
- pthread_mutex_t m_;
-};
-
-const int kNumMutexes = 1024;
-Mutex mutexes[kNumMutexes];
-
-int n_threads, n_iterations;
-
-pthread_barrier_t all_threads_ready, main_threads_ready;
-
-void* GarbageThread(void *unused) {
- pthread_barrier_wait(&all_threads_ready);
- return 0;
-}
-
-void *Thread(void *arg) {
- long idx = (long)arg;
- pthread_barrier_wait(&all_threads_ready);
-
- // Wait for the main thread to join the garbage threads.
- pthread_barrier_wait(&main_threads_ready);
-
- printf("Thread %ld go!\n", idx);
- int offset = idx * kNumMutexes / n_threads;
- for (int i = 0; i < n_iterations; i++) {
- mutexes[(offset + i) % kNumMutexes].Lock();
- mutexes[(offset + i) % kNumMutexes].Unlock();
- }
- printf("Thread %ld done\n", idx);
- return 0;
-}
-
-int main(int argc, char **argv) {
- int n_garbage_threads;
- if (argc == 1) {
- n_threads = 2;
- n_garbage_threads = 200;
- n_iterations = 20000000;
- } else if (argc == 4) {
- n_threads = atoi(argv[1]);
- assert(n_threads > 0 && n_threads <= 32);
- n_garbage_threads = atoi(argv[2]);
- assert(n_garbage_threads > 0 && n_garbage_threads <= 16000);
- n_iterations = atoi(argv[3]);
- } else {
- printf("Usage: %s n_threads n_garbage_threads n_iterations\n", argv[0]);
- return 1;
- }
- printf("%s: n_threads=%d n_garbage_threads=%d n_iterations=%d\n",
- __FILE__, n_threads, n_garbage_threads, n_iterations);
-
- pthread_barrier_init(&all_threads_ready, NULL, n_garbage_threads + n_threads + 1);
- pthread_barrier_init(&main_threads_ready, NULL, n_threads + 1);
-
- pthread_t *t = new pthread_t[n_threads];
- {
- pthread_t *g_t = new pthread_t[n_garbage_threads];
- for (int i = 0; i < n_garbage_threads; i++) {
- int status = pthread_create(&g_t[i], 0, GarbageThread, NULL);
- assert(status == 0);
- }
- for (int i = 0; i < n_threads; i++) {
- int status = pthread_create(&t[i], 0, Thread, (void*)i);
- assert(status == 0);
- }
- pthread_barrier_wait(&all_threads_ready);
- printf("All threads started! Killing the garbage threads.\n");
- for (int i = 0; i < n_garbage_threads; i++) {
- pthread_join(g_t[i], 0);
- }
- delete [] g_t;
- }
- printf("Resuming the main threads.\n");
- pthread_barrier_wait(&main_threads_ready);
-
-
- for (int i = 0; i < n_threads; i++) {
- pthread_join(t[i], 0);
- }
- delete [] t;
- return 0;
-}
Modified: compiler-rt/trunk/lib/tsan/dd/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/dd/CMakeLists.txt?rev=367567&r1=367566&r2=367567&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/dd/CMakeLists.txt (original)
+++ compiler-rt/trunk/lib/tsan/dd/CMakeLists.txt Thu Aug 1 07:30:49 2019
@@ -6,9 +6,9 @@ set(DD_CFLAGS ${SANITIZER_COMMON_CFLAGS}
append_rtti_flag(OFF DD_CFLAGS)
set(DD_SOURCES
- dd_rtl.cc
- dd_interceptors.cc
-)
+ dd_rtl.cpp
+ dd_interceptors.cpp
+ )
set(DD_LINKLIBS ${SANITIZER_CXX_ABI_LIBRARIES} ${SANITIZER_COMMON_LINK_LIBS})
Removed: compiler-rt/trunk/lib/tsan/dd/dd_interceptors.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/dd/dd_interceptors.cc?rev=367566&view=auto
==============================================================================
--- compiler-rt/trunk/lib/tsan/dd/dd_interceptors.cc (original)
+++ compiler-rt/trunk/lib/tsan/dd/dd_interceptors.cc (removed)
@@ -1,328 +0,0 @@
-//===-- dd_interceptors.cc ------------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-#include "dd_rtl.h"
-#include "interception/interception.h"
-#include "sanitizer_common/sanitizer_procmaps.h"
-#include <pthread.h>
-#include <stdlib.h>
-
-using namespace __dsan;
-
-__attribute__((tls_model("initial-exec")))
-static __thread Thread *thr;
-__attribute__((tls_model("initial-exec")))
-static __thread volatile int initing;
-static bool inited;
-static uptr g_data_start;
-static uptr g_data_end;
-
-static bool InitThread() {
- if (initing)
- return false;
- if (thr != 0)
- return true;
- initing = true;
- if (!inited) {
- inited = true;
- Initialize();
- }
- thr = (Thread*)InternalAlloc(sizeof(*thr));
- internal_memset(thr, 0, sizeof(*thr));
- ThreadInit(thr);
- initing = false;
- return true;
-}
-
-INTERCEPTOR(int, pthread_mutex_destroy, pthread_mutex_t *m) {
- InitThread();
- MutexDestroy(thr, (uptr)m);
- return REAL(pthread_mutex_destroy)(m);
-}
-
-INTERCEPTOR(int, pthread_mutex_lock, pthread_mutex_t *m) {
- InitThread();
- MutexBeforeLock(thr, (uptr)m, true);
- int res = REAL(pthread_mutex_lock)(m);
- MutexAfterLock(thr, (uptr)m, true, false);
- return res;
-}
-
-INTERCEPTOR(int, pthread_mutex_trylock, pthread_mutex_t *m) {
- InitThread();
- int res = REAL(pthread_mutex_trylock)(m);
- if (res == 0)
- MutexAfterLock(thr, (uptr)m, true, true);
- return res;
-}
-
-INTERCEPTOR(int, pthread_mutex_unlock, pthread_mutex_t *m) {
- InitThread();
- MutexBeforeUnlock(thr, (uptr)m, true);
- return REAL(pthread_mutex_unlock)(m);
-}
-
-INTERCEPTOR(int, pthread_spin_destroy, pthread_spinlock_t *m) {
- InitThread();
- int res = REAL(pthread_spin_destroy)(m);
- MutexDestroy(thr, (uptr)m);
- return res;
-}
-
-INTERCEPTOR(int, pthread_spin_lock, pthread_spinlock_t *m) {
- InitThread();
- MutexBeforeLock(thr, (uptr)m, true);
- int res = REAL(pthread_spin_lock)(m);
- MutexAfterLock(thr, (uptr)m, true, false);
- return res;
-}
-
-INTERCEPTOR(int, pthread_spin_trylock, pthread_spinlock_t *m) {
- InitThread();
- int res = REAL(pthread_spin_trylock)(m);
- if (res == 0)
- MutexAfterLock(thr, (uptr)m, true, true);
- return res;
-}
-
-INTERCEPTOR(int, pthread_spin_unlock, pthread_spinlock_t *m) {
- InitThread();
- MutexBeforeUnlock(thr, (uptr)m, true);
- return REAL(pthread_spin_unlock)(m);
-}
-
-INTERCEPTOR(int, pthread_rwlock_destroy, pthread_rwlock_t *m) {
- InitThread();
- MutexDestroy(thr, (uptr)m);
- return REAL(pthread_rwlock_destroy)(m);
-}
-
-INTERCEPTOR(int, pthread_rwlock_rdlock, pthread_rwlock_t *m) {
- InitThread();
- MutexBeforeLock(thr, (uptr)m, false);
- int res = REAL(pthread_rwlock_rdlock)(m);
- MutexAfterLock(thr, (uptr)m, false, false);
- return res;
-}
-
-INTERCEPTOR(int, pthread_rwlock_tryrdlock, pthread_rwlock_t *m) {
- InitThread();
- int res = REAL(pthread_rwlock_tryrdlock)(m);
- if (res == 0)
- MutexAfterLock(thr, (uptr)m, false, true);
- return res;
-}
-
-INTERCEPTOR(int, pthread_rwlock_timedrdlock, pthread_rwlock_t *m,
- const timespec *abstime) {
- InitThread();
- int res = REAL(pthread_rwlock_timedrdlock)(m, abstime);
- if (res == 0)
- MutexAfterLock(thr, (uptr)m, false, true);
- return res;
-}
-
-INTERCEPTOR(int, pthread_rwlock_wrlock, pthread_rwlock_t *m) {
- InitThread();
- MutexBeforeLock(thr, (uptr)m, true);
- int res = REAL(pthread_rwlock_wrlock)(m);
- MutexAfterLock(thr, (uptr)m, true, false);
- return res;
-}
-
-INTERCEPTOR(int, pthread_rwlock_trywrlock, pthread_rwlock_t *m) {
- InitThread();
- int res = REAL(pthread_rwlock_trywrlock)(m);
- if (res == 0)
- MutexAfterLock(thr, (uptr)m, true, true);
- return res;
-}
-
-INTERCEPTOR(int, pthread_rwlock_timedwrlock, pthread_rwlock_t *m,
- const timespec *abstime) {
- InitThread();
- int res = REAL(pthread_rwlock_timedwrlock)(m, abstime);
- if (res == 0)
- MutexAfterLock(thr, (uptr)m, true, true);
- return res;
-}
-
-INTERCEPTOR(int, pthread_rwlock_unlock, pthread_rwlock_t *m) {
- InitThread();
- MutexBeforeUnlock(thr, (uptr)m, true); // note: not necessary write unlock
- return REAL(pthread_rwlock_unlock)(m);
-}
-
-static pthread_cond_t *init_cond(pthread_cond_t *c, bool force = false) {
- atomic_uintptr_t *p = (atomic_uintptr_t*)c;
- uptr cond = atomic_load(p, memory_order_acquire);
- if (!force && cond != 0)
- return (pthread_cond_t*)cond;
- void *newcond = malloc(sizeof(pthread_cond_t));
- internal_memset(newcond, 0, sizeof(pthread_cond_t));
- if (atomic_compare_exchange_strong(p, &cond, (uptr)newcond,
- memory_order_acq_rel))
- return (pthread_cond_t*)newcond;
- free(newcond);
- return (pthread_cond_t*)cond;
-}
-
-INTERCEPTOR(int, pthread_cond_init, pthread_cond_t *c,
- const pthread_condattr_t *a) {
- InitThread();
- pthread_cond_t *cond = init_cond(c, true);
- return REAL(pthread_cond_init)(cond, a);
-}
-
-INTERCEPTOR(int, pthread_cond_wait, pthread_cond_t *c, pthread_mutex_t *m) {
- InitThread();
- pthread_cond_t *cond = init_cond(c);
- MutexBeforeUnlock(thr, (uptr)m, true);
- MutexBeforeLock(thr, (uptr)m, true);
- int res = REAL(pthread_cond_wait)(cond, m);
- MutexAfterLock(thr, (uptr)m, true, false);
- return res;
-}
-
-INTERCEPTOR(int, pthread_cond_timedwait, pthread_cond_t *c, pthread_mutex_t *m,
- const timespec *abstime) {
- InitThread();
- pthread_cond_t *cond = init_cond(c);
- MutexBeforeUnlock(thr, (uptr)m, true);
- MutexBeforeLock(thr, (uptr)m, true);
- int res = REAL(pthread_cond_timedwait)(cond, m, abstime);
- MutexAfterLock(thr, (uptr)m, true, false);
- return res;
-}
-
-INTERCEPTOR(int, pthread_cond_signal, pthread_cond_t *c) {
- InitThread();
- pthread_cond_t *cond = init_cond(c);
- return REAL(pthread_cond_signal)(cond);
-}
-
-INTERCEPTOR(int, pthread_cond_broadcast, pthread_cond_t *c) {
- InitThread();
- pthread_cond_t *cond = init_cond(c);
- return REAL(pthread_cond_broadcast)(cond);
-}
-
-INTERCEPTOR(int, pthread_cond_destroy, pthread_cond_t *c) {
- InitThread();
- pthread_cond_t *cond = init_cond(c);
- int res = REAL(pthread_cond_destroy)(cond);
- free(cond);
- atomic_store((atomic_uintptr_t*)c, 0, memory_order_relaxed);
- return res;
-}
-
-// for symbolizer
-INTERCEPTOR(char*, realpath, const char *path, char *resolved_path) {
- InitThread();
- return REAL(realpath)(path, resolved_path);
-}
-
-INTERCEPTOR(SSIZE_T, read, int fd, void *ptr, SIZE_T count) {
- InitThread();
- return REAL(read)(fd, ptr, count);
-}
-
-INTERCEPTOR(SSIZE_T, pread, int fd, void *ptr, SIZE_T count, OFF_T offset) {
- InitThread();
- return REAL(pread)(fd, ptr, count, offset);
-}
-
-extern "C" {
-void __dsan_before_mutex_lock(uptr m, int writelock) {
- if (!InitThread())
- return;
- MutexBeforeLock(thr, m, writelock);
-}
-
-void __dsan_after_mutex_lock(uptr m, int writelock, int trylock) {
- if (!InitThread())
- return;
- MutexAfterLock(thr, m, writelock, trylock);
-}
-
-void __dsan_before_mutex_unlock(uptr m, int writelock) {
- if (!InitThread())
- return;
- MutexBeforeUnlock(thr, m, writelock);
-}
-
-void __dsan_mutex_destroy(uptr m) {
- if (!InitThread())
- return;
- // if (m >= g_data_start && m < g_data_end)
- // return;
- MutexDestroy(thr, m);
-}
-} // extern "C"
-
-namespace __dsan {
-
-static void InitDataSeg() {
- MemoryMappingLayout proc_maps(true);
- char name[128];
- MemoryMappedSegment segment(name, ARRAY_SIZE(name));
- bool prev_is_data = false;
- while (proc_maps.Next(&segment)) {
- bool is_data = segment.offset != 0 && segment.filename[0] != 0;
- // BSS may get merged with [heap] in /proc/self/maps. This is not very
- // reliable.
- bool is_bss = segment.offset == 0 &&
- (segment.filename[0] == 0 ||
- internal_strcmp(segment.filename, "[heap]") == 0) &&
- prev_is_data;
- if (g_data_start == 0 && is_data) g_data_start = segment.start;
- if (is_bss) g_data_end = segment.end;
- prev_is_data = is_data;
- }
- VPrintf(1, "guessed data_start=%p data_end=%p\n", g_data_start, g_data_end);
- CHECK_LT(g_data_start, g_data_end);
- CHECK_GE((uptr)&g_data_start, g_data_start);
- CHECK_LT((uptr)&g_data_start, g_data_end);
-}
-
-void InitializeInterceptors() {
- INTERCEPT_FUNCTION(pthread_mutex_destroy);
- INTERCEPT_FUNCTION(pthread_mutex_lock);
- INTERCEPT_FUNCTION(pthread_mutex_trylock);
- INTERCEPT_FUNCTION(pthread_mutex_unlock);
-
- INTERCEPT_FUNCTION(pthread_spin_destroy);
- INTERCEPT_FUNCTION(pthread_spin_lock);
- INTERCEPT_FUNCTION(pthread_spin_trylock);
- INTERCEPT_FUNCTION(pthread_spin_unlock);
-
- INTERCEPT_FUNCTION(pthread_rwlock_destroy);
- INTERCEPT_FUNCTION(pthread_rwlock_rdlock);
- INTERCEPT_FUNCTION(pthread_rwlock_tryrdlock);
- INTERCEPT_FUNCTION(pthread_rwlock_timedrdlock);
- INTERCEPT_FUNCTION(pthread_rwlock_wrlock);
- INTERCEPT_FUNCTION(pthread_rwlock_trywrlock);
- INTERCEPT_FUNCTION(pthread_rwlock_timedwrlock);
- INTERCEPT_FUNCTION(pthread_rwlock_unlock);
-
- INTERCEPT_FUNCTION_VER(pthread_cond_init, "GLIBC_2.3.2");
- INTERCEPT_FUNCTION_VER(pthread_cond_signal, "GLIBC_2.3.2");
- INTERCEPT_FUNCTION_VER(pthread_cond_broadcast, "GLIBC_2.3.2");
- INTERCEPT_FUNCTION_VER(pthread_cond_wait, "GLIBC_2.3.2");
- INTERCEPT_FUNCTION_VER(pthread_cond_timedwait, "GLIBC_2.3.2");
- INTERCEPT_FUNCTION_VER(pthread_cond_destroy, "GLIBC_2.3.2");
-
- // for symbolizer
- INTERCEPT_FUNCTION(realpath);
- INTERCEPT_FUNCTION(read);
- INTERCEPT_FUNCTION(pread);
-
- InitDataSeg();
-}
-
-} // namespace __dsan
Copied: compiler-rt/trunk/lib/tsan/dd/dd_interceptors.cpp (from r367566, compiler-rt/trunk/lib/tsan/dd/dd_interceptors.cc)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/dd/dd_interceptors.cpp?p2=compiler-rt/trunk/lib/tsan/dd/dd_interceptors.cpp&p1=compiler-rt/trunk/lib/tsan/dd/dd_interceptors.cc&r1=367566&r2=367567&rev=367567&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/dd/dd_interceptors.cc (original)
+++ compiler-rt/trunk/lib/tsan/dd/dd_interceptors.cpp Thu Aug 1 07:30:49 2019
@@ -1,4 +1,4 @@
-//===-- dd_interceptors.cc ------------------------------------------------===//
+//===-- dd_interceptors.cpp -----------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Removed: compiler-rt/trunk/lib/tsan/dd/dd_rtl.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/dd/dd_rtl.cc?rev=367566&view=auto
==============================================================================
--- compiler-rt/trunk/lib/tsan/dd/dd_rtl.cc (original)
+++ compiler-rt/trunk/lib/tsan/dd/dd_rtl.cc (removed)
@@ -1,158 +0,0 @@
-//===-- dd_rtl.cc ---------------------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-#include "dd_rtl.h"
-#include "sanitizer_common/sanitizer_common.h"
-#include "sanitizer_common/sanitizer_placement_new.h"
-#include "sanitizer_common/sanitizer_flags.h"
-#include "sanitizer_common/sanitizer_flag_parser.h"
-#include "sanitizer_common/sanitizer_stacktrace.h"
-#include "sanitizer_common/sanitizer_stackdepot.h"
-
-namespace __dsan {
-
-static Context *ctx;
-
-static u32 CurrentStackTrace(Thread *thr, uptr skip) {
- BufferedStackTrace stack;
- thr->ignore_interceptors = true;
- stack.Unwind(1000, 0, 0, 0, 0, 0, false);
- thr->ignore_interceptors = false;
- if (stack.size <= skip)
- return 0;
- return StackDepotPut(StackTrace(stack.trace + skip, stack.size - skip));
-}
-
-static void PrintStackTrace(Thread *thr, u32 stk) {
- StackTrace stack = StackDepotGet(stk);
- thr->ignore_interceptors = true;
- stack.Print();
- thr->ignore_interceptors = false;
-}
-
-static void ReportDeadlock(Thread *thr, DDReport *rep) {
- if (rep == 0)
- return;
- BlockingMutexLock lock(&ctx->report_mutex);
- Printf("==============================\n");
- Printf("WARNING: lock-order-inversion (potential deadlock)\n");
- for (int i = 0; i < rep->n; i++) {
- Printf("Thread %d locks mutex %llu while holding mutex %llu:\n",
- rep->loop[i].thr_ctx, rep->loop[i].mtx_ctx1, rep->loop[i].mtx_ctx0);
- PrintStackTrace(thr, rep->loop[i].stk[1]);
- if (rep->loop[i].stk[0]) {
- Printf("Mutex %llu was acquired here:\n",
- rep->loop[i].mtx_ctx0);
- PrintStackTrace(thr, rep->loop[i].stk[0]);
- }
- }
- Printf("==============================\n");
-}
-
-Callback::Callback(Thread *thr)
- : thr(thr) {
- lt = thr->dd_lt;
- pt = thr->dd_pt;
-}
-
-u32 Callback::Unwind() {
- return CurrentStackTrace(thr, 3);
-}
-
-static void InitializeFlags() {
- Flags *f = flags();
-
- // Default values.
- f->second_deadlock_stack = false;
-
- SetCommonFlagsDefaults();
- {
- // Override some common flags defaults.
- CommonFlags cf;
- cf.CopyFrom(*common_flags());
- cf.allow_addr2line = true;
- OverrideCommonFlags(cf);
- }
-
- // Override from command line.
- FlagParser parser;
- RegisterFlag(&parser, "second_deadlock_stack", "", &f->second_deadlock_stack);
- RegisterCommonFlags(&parser);
- parser.ParseStringFromEnv("DSAN_OPTIONS");
- SetVerbosity(common_flags()->verbosity);
-}
-
-void Initialize() {
- static u64 ctx_mem[sizeof(Context) / sizeof(u64) + 1];
- ctx = new(ctx_mem) Context();
-
- InitializeInterceptors();
- InitializeFlags();
- ctx->dd = DDetector::Create(flags());
-}
-
-void ThreadInit(Thread *thr) {
- static atomic_uintptr_t id_gen;
- uptr id = atomic_fetch_add(&id_gen, 1, memory_order_relaxed);
- thr->dd_pt = ctx->dd->CreatePhysicalThread();
- thr->dd_lt = ctx->dd->CreateLogicalThread(id);
-}
-
-void ThreadDestroy(Thread *thr) {
- ctx->dd->DestroyPhysicalThread(thr->dd_pt);
- ctx->dd->DestroyLogicalThread(thr->dd_lt);
-}
-
-void MutexBeforeLock(Thread *thr, uptr m, bool writelock) {
- if (thr->ignore_interceptors)
- return;
- Callback cb(thr);
- {
- MutexHashMap::Handle h(&ctx->mutex_map, m);
- if (h.created())
- ctx->dd->MutexInit(&cb, &h->dd);
- ctx->dd->MutexBeforeLock(&cb, &h->dd, writelock);
- }
- ReportDeadlock(thr, ctx->dd->GetReport(&cb));
-}
-
-void MutexAfterLock(Thread *thr, uptr m, bool writelock, bool trylock) {
- if (thr->ignore_interceptors)
- return;
- Callback cb(thr);
- {
- MutexHashMap::Handle h(&ctx->mutex_map, m);
- if (h.created())
- ctx->dd->MutexInit(&cb, &h->dd);
- ctx->dd->MutexAfterLock(&cb, &h->dd, writelock, trylock);
- }
- ReportDeadlock(thr, ctx->dd->GetReport(&cb));
-}
-
-void MutexBeforeUnlock(Thread *thr, uptr m, bool writelock) {
- if (thr->ignore_interceptors)
- return;
- Callback cb(thr);
- {
- MutexHashMap::Handle h(&ctx->mutex_map, m);
- ctx->dd->MutexBeforeUnlock(&cb, &h->dd, writelock);
- }
- ReportDeadlock(thr, ctx->dd->GetReport(&cb));
-}
-
-void MutexDestroy(Thread *thr, uptr m) {
- if (thr->ignore_interceptors)
- return;
- Callback cb(thr);
- MutexHashMap::Handle h(&ctx->mutex_map, m, true);
- if (!h.exists())
- return;
- ctx->dd->MutexDestroy(&cb, &h->dd);
-}
-
-} // namespace __dsan
Copied: compiler-rt/trunk/lib/tsan/dd/dd_rtl.cpp (from r367566, compiler-rt/trunk/lib/tsan/dd/dd_rtl.cc)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/dd/dd_rtl.cpp?p2=compiler-rt/trunk/lib/tsan/dd/dd_rtl.cpp&p1=compiler-rt/trunk/lib/tsan/dd/dd_rtl.cc&r1=367566&r2=367567&rev=367567&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/dd/dd_rtl.cc (original)
+++ compiler-rt/trunk/lib/tsan/dd/dd_rtl.cpp Thu Aug 1 07:30:49 2019
@@ -1,4 +1,4 @@
-//===-- dd_rtl.cc ---------------------------------------------------------===//
+//===-- dd_rtl.cpp --------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Modified: compiler-rt/trunk/lib/tsan/go/build.bat
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/go/build.bat?rev=367567&r1=367566&r2=367567&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/go/build.bat (original)
+++ compiler-rt/trunk/lib/tsan/go/build.bat Thu Aug 1 07:30:49 2019
@@ -1,4 +1,4 @@
-type tsan_go.cc ..\rtl\tsan_interface_atomic.cpp ..\rtl\tsan_clock.cpp ..\rtl\tsan_flags.cpp ..\rtl\tsan_md5.cpp ..\rtl\tsan_mutex.cpp ..\rtl\tsan_report.cpp ..\rtl\tsan_rtl.cpp ..\rtl\tsan_rtl_mutex.cpp ..\rtl\tsan_rtl_report.cpp ..\rtl\tsan_rtl_thread.cpp ..\rtl\tsan_rtl_proc.cpp ..\rtl\tsan_stat.cpp ..\rtl\tsan_suppressions.cpp ..\rtl\tsan_sync.cpp ..\rtl\tsan_stack_trace.cpp ..\..\sanitizer_common\sanitizer_allocator.cpp ..\..\sanitizer_common\sanitizer_common.cpp ..\..\sanitizer_common\sanitizer_flags.cpp ..\..\sanitizer_common\sanitizer_stacktrace.cpp ..\..\sanitizer_common\sanitizer_libc.cpp ..\..\sanitizer_common\sanitizer_printf.cpp ..\..\sanitizer_common\sanitizer_suppressions.cpp ..\..\sanitizer_common\sanitizer_thread_registry.cpp ..\rtl\tsan_platform_windows.cpp ..\..\sanitizer_common\sanitizer_win.cpp ..\..\sanitizer_common\sanitizer_deadlock_detector1.cpp ..\..\sanitizer_common\sanitizer_stackdepot.cpp ..\..\sanitizer_common\sanitizer_persistent_allocator.cpp ..\..\sanitizer_common\sanitizer_flag_parser.cpp ..\..\sanitizer_common\sanitizer_symbolizer.cpp ..\..\sanitizer_common\sanitizer_termination.cpp > gotsan.cc
+type tsan_go.cpp ..\rtl\tsan_interface_atomic.cpp ..\rtl\tsan_clock.cpp ..\rtl\tsan_flags.cpp ..\rtl\tsan_md5.cpp ..\rtl\tsan_mutex.cpp ..\rtl\tsan_report.cpp ..\rtl\tsan_rtl.cpp ..\rtl\tsan_rtl_mutex.cpp ..\rtl\tsan_rtl_report.cpp ..\rtl\tsan_rtl_thread.cpp ..\rtl\tsan_rtl_proc.cpp ..\rtl\tsan_stat.cpp ..\rtl\tsan_suppressions.cpp ..\rtl\tsan_sync.cpp ..\rtl\tsan_stack_trace.cpp ..\..\sanitizer_common\sanitizer_allocator.cpp ..\..\sanitizer_common\sanitizer_common.cpp ..\..\sanitizer_common\sanitizer_flags.cpp ..\..\sanitizer_common\sanitizer_stacktrace.cpp ..\..\sanitizer_common\sanitizer_libc.cpp ..\..\sanitizer_common\sanitizer_printf.cpp ..\..\sanitizer_common\sanitizer_suppressions.cpp ..\..\sanitizer_common\sanitizer_thread_registry.cpp ..\rtl\tsan_platform_windows.cpp ..\..\sanitizer_common\sanitizer_win.cpp ..\..\sanitizer_common\sanitizer_deadlock_detector1.cpp ..\..\sanitizer_common\sanitizer_stackdepot.cpp ..\..\sanitizer_common\sanitizer_persistent_allocator.cpp ..\..\sanitizer_common\sanitizer_flag_parser.cpp ..\..\sanitizer_common\sanitizer_symbolizer.cpp ..\..\sanitizer_common\sanitizer_termination.cpp > gotsan.cpp
-gcc -c -o race_windows_amd64.syso gotsan.cc -I..\rtl -I..\.. -I..\..\sanitizer_common -I..\..\..\include -m64 -Wall -fno-exceptions -fno-rtti -DSANITIZER_GO=1 -Wno-error=attributes -Wno-attributes -Wno-format -Wno-maybe-uninitialized -DSANITIZER_DEBUG=0 -O3 -fomit-frame-pointer -std=c++11
+gcc -c -o race_windows_amd64.syso gotsan.cpp -I..\rtl -I..\.. -I..\..\sanitizer_common -I..\..\..\include -m64 -Wall -fno-exceptions -fno-rtti -DSANITIZER_GO=1 -Wno-error=attributes -Wno-attributes -Wno-format -Wno-maybe-uninitialized -DSANITIZER_DEBUG=0 -O3 -fomit-frame-pointer -std=c++11
Modified: compiler-rt/trunk/lib/tsan/go/buildgo.sh
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/go/buildgo.sh?rev=367567&r1=367566&r2=367567&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/go/buildgo.sh (original)
+++ compiler-rt/trunk/lib/tsan/go/buildgo.sh Thu Aug 1 07:30:49 2019
@@ -3,7 +3,7 @@
set -e
SRCS="
- tsan_go.cc
+ tsan_go.cpp
../rtl/tsan_clock.cpp
../rtl/tsan_external.cpp
../rtl/tsan_flags.cpp
@@ -144,9 +144,9 @@ fi
SRCS="$SRCS $ADD_SRCS"
-rm -f $DIR/gotsan.cc
+rm -f $DIR/gotsan.cpp
for F in $SRCS; do
- cat $F >> $DIR/gotsan.cc
+ cat $F >> $DIR/gotsan.cpp
done
FLAGS=" -I../rtl -I../.. -I../../sanitizer_common -I../../../include -std=c++11 -Wall -fno-exceptions -fno-rtti -DSANITIZER_GO=1 -DSANITIZER_DEADLOCK_DETECTOR_VERSION=2 $OSCFLAGS $ARCHCFLAGS"
@@ -162,9 +162,9 @@ else
fi
if [ "$SILENT" != "1" ]; then
- echo $CC gotsan.cc -c -o $DIR/race_$SUFFIX.syso $FLAGS $CFLAGS
+ echo $CC gotsan.cpp -c -o $DIR/race_$SUFFIX.syso $FLAGS $CFLAGS
fi
-$CC $DIR/gotsan.cc -c -o $DIR/race_$SUFFIX.syso $FLAGS $CFLAGS
+$CC $DIR/gotsan.cpp -c -o $DIR/race_$SUFFIX.syso $FLAGS $CFLAGS
$CC $OSCFLAGS $ARCHCFLAGS test.c $DIR/race_$SUFFIX.syso -g -o $DIR/test $OSLDFLAGS $LDFLAGS
Removed: compiler-rt/trunk/lib/tsan/go/tsan_go.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/go/tsan_go.cc?rev=367566&view=auto
==============================================================================
--- compiler-rt/trunk/lib/tsan/go/tsan_go.cc (original)
+++ compiler-rt/trunk/lib/tsan/go/tsan_go.cc (removed)
@@ -1,283 +0,0 @@
-//===-- tsan_go.cc --------------------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-//
-// ThreadSanitizer runtime for Go language.
-//
-//===----------------------------------------------------------------------===//
-
-#include "tsan_rtl.h"
-#include "tsan_symbolize.h"
-#include "sanitizer_common/sanitizer_common.h"
-#include <stdlib.h>
-
-namespace __tsan {
-
-void InitializeInterceptors() {
-}
-
-void InitializeDynamicAnnotations() {
-}
-
-bool IsExpectedReport(uptr addr, uptr size) {
- return false;
-}
-
-void *internal_alloc(MBlockType typ, uptr sz) {
- return InternalAlloc(sz);
-}
-
-void internal_free(void *p) {
- InternalFree(p);
-}
-
-// Callback into Go.
-static void (*go_runtime_cb)(uptr cmd, void *ctx);
-
-enum {
- CallbackGetProc = 0,
- CallbackSymbolizeCode = 1,
- CallbackSymbolizeData = 2,
-};
-
-struct SymbolizeCodeContext {
- uptr pc;
- char *func;
- char *file;
- uptr line;
- uptr off;
- uptr res;
-};
-
-SymbolizedStack *SymbolizeCode(uptr addr) {
- SymbolizedStack *s = SymbolizedStack::New(addr);
- SymbolizeCodeContext cbctx;
- internal_memset(&cbctx, 0, sizeof(cbctx));
- cbctx.pc = addr;
- go_runtime_cb(CallbackSymbolizeCode, &cbctx);
- if (cbctx.res) {
- AddressInfo &info = s->info;
- info.module_offset = cbctx.off;
- info.function = internal_strdup(cbctx.func ? cbctx.func : "??");
- info.file = internal_strdup(cbctx.file ? cbctx.file : "-");
- info.line = cbctx.line;
- info.column = 0;
- }
- return s;
-}
-
-struct SymbolizeDataContext {
- uptr addr;
- uptr heap;
- uptr start;
- uptr size;
- char *name;
- char *file;
- uptr line;
- uptr res;
-};
-
-ReportLocation *SymbolizeData(uptr addr) {
- SymbolizeDataContext cbctx;
- internal_memset(&cbctx, 0, sizeof(cbctx));
- cbctx.addr = addr;
- go_runtime_cb(CallbackSymbolizeData, &cbctx);
- if (!cbctx.res)
- return 0;
- if (cbctx.heap) {
- MBlock *b = ctx->metamap.GetBlock(cbctx.start);
- if (!b)
- return 0;
- ReportLocation *loc = ReportLocation::New(ReportLocationHeap);
- loc->heap_chunk_start = cbctx.start;
- loc->heap_chunk_size = b->siz;
- loc->tid = b->tid;
- loc->stack = SymbolizeStackId(b->stk);
- return loc;
- } else {
- ReportLocation *loc = ReportLocation::New(ReportLocationGlobal);
- loc->global.name = internal_strdup(cbctx.name ? cbctx.name : "??");
- loc->global.file = internal_strdup(cbctx.file ? cbctx.file : "??");
- loc->global.line = cbctx.line;
- loc->global.start = cbctx.start;
- loc->global.size = cbctx.size;
- return loc;
- }
-}
-
-static ThreadState *main_thr;
-static bool inited;
-
-static Processor* get_cur_proc() {
- if (UNLIKELY(!inited)) {
- // Running Initialize().
- // We have not yet returned the Processor to Go, so we cannot ask it back.
- // Currently, Initialize() does not use the Processor, so return nullptr.
- return nullptr;
- }
- Processor *proc;
- go_runtime_cb(CallbackGetProc, &proc);
- return proc;
-}
-
-Processor *ThreadState::proc() {
- return get_cur_proc();
-}
-
-extern "C" {
-
-static ThreadState *AllocGoroutine() {
- ThreadState *thr = (ThreadState*)internal_alloc(MBlockThreadContex,
- sizeof(ThreadState));
- internal_memset(thr, 0, sizeof(*thr));
- return thr;
-}
-
-void __tsan_init(ThreadState **thrp, Processor **procp,
- void (*cb)(uptr cmd, void *cb)) {
- go_runtime_cb = cb;
- ThreadState *thr = AllocGoroutine();
- main_thr = *thrp = thr;
- Initialize(thr);
- *procp = thr->proc1;
- inited = true;
-}
-
-void __tsan_fini() {
- // FIXME: Not necessary thread 0.
- ThreadState *thr = main_thr;
- int res = Finalize(thr);
- exit(res);
-}
-
-void __tsan_map_shadow(uptr addr, uptr size) {
- MapShadow(addr, size);
-}
-
-void __tsan_read(ThreadState *thr, void *addr, void *pc) {
- MemoryRead(thr, (uptr)pc, (uptr)addr, kSizeLog1);
-}
-
-void __tsan_read_pc(ThreadState *thr, void *addr, uptr callpc, uptr pc) {
- if (callpc != 0)
- FuncEntry(thr, callpc);
- MemoryRead(thr, (uptr)pc, (uptr)addr, kSizeLog1);
- if (callpc != 0)
- FuncExit(thr);
-}
-
-void __tsan_write(ThreadState *thr, void *addr, void *pc) {
- MemoryWrite(thr, (uptr)pc, (uptr)addr, kSizeLog1);
-}
-
-void __tsan_write_pc(ThreadState *thr, void *addr, uptr callpc, uptr pc) {
- if (callpc != 0)
- FuncEntry(thr, callpc);
- MemoryWrite(thr, (uptr)pc, (uptr)addr, kSizeLog1);
- if (callpc != 0)
- FuncExit(thr);
-}
-
-void __tsan_read_range(ThreadState *thr, void *addr, uptr size, uptr pc) {
- MemoryAccessRange(thr, (uptr)pc, (uptr)addr, size, false);
-}
-
-void __tsan_write_range(ThreadState *thr, void *addr, uptr size, uptr pc) {
- MemoryAccessRange(thr, (uptr)pc, (uptr)addr, size, true);
-}
-
-void __tsan_func_enter(ThreadState *thr, void *pc) {
- FuncEntry(thr, (uptr)pc);
-}
-
-void __tsan_func_exit(ThreadState *thr) {
- FuncExit(thr);
-}
-
-void __tsan_malloc(ThreadState *thr, uptr pc, uptr p, uptr sz) {
- CHECK(inited);
- if (thr && pc)
- ctx->metamap.AllocBlock(thr, pc, p, sz);
- MemoryResetRange(0, 0, (uptr)p, sz);
-}
-
-void __tsan_free(uptr p, uptr sz) {
- ctx->metamap.FreeRange(get_cur_proc(), p, sz);
-}
-
-void __tsan_go_start(ThreadState *parent, ThreadState **pthr, void *pc) {
- ThreadState *thr = AllocGoroutine();
- *pthr = thr;
- int goid = ThreadCreate(parent, (uptr)pc, 0, true);
- ThreadStart(thr, goid, 0, ThreadType::Regular);
-}
-
-void __tsan_go_end(ThreadState *thr) {
- ThreadFinish(thr);
- internal_free(thr);
-}
-
-void __tsan_proc_create(Processor **pproc) {
- *pproc = ProcCreate();
-}
-
-void __tsan_proc_destroy(Processor *proc) {
- ProcDestroy(proc);
-}
-
-void __tsan_acquire(ThreadState *thr, void *addr) {
- Acquire(thr, 0, (uptr)addr);
-}
-
-void __tsan_release(ThreadState *thr, void *addr) {
- ReleaseStore(thr, 0, (uptr)addr);
-}
-
-void __tsan_release_merge(ThreadState *thr, void *addr) {
- Release(thr, 0, (uptr)addr);
-}
-
-void __tsan_finalizer_goroutine(ThreadState *thr) {
- AcquireGlobal(thr, 0);
-}
-
-void __tsan_mutex_before_lock(ThreadState *thr, uptr addr, uptr write) {
- if (write)
- MutexPreLock(thr, 0, addr);
- else
- MutexPreReadLock(thr, 0, addr);
-}
-
-void __tsan_mutex_after_lock(ThreadState *thr, uptr addr, uptr write) {
- if (write)
- MutexPostLock(thr, 0, addr);
- else
- MutexPostReadLock(thr, 0, addr);
-}
-
-void __tsan_mutex_before_unlock(ThreadState *thr, uptr addr, uptr write) {
- if (write)
- MutexUnlock(thr, 0, addr);
- else
- MutexReadUnlock(thr, 0, addr);
-}
-
-void __tsan_go_ignore_sync_begin(ThreadState *thr) {
- ThreadIgnoreSyncBegin(thr, 0);
-}
-
-void __tsan_go_ignore_sync_end(ThreadState *thr) {
- ThreadIgnoreSyncEnd(thr, 0);
-}
-
-void __tsan_report_count(u64 *pn) {
- Lock lock(&ctx->report_mtx);
- *pn = ctx->nreported;
-}
-
-} // extern "C"
-} // namespace __tsan
Copied: compiler-rt/trunk/lib/tsan/go/tsan_go.cpp (from r367566, compiler-rt/trunk/lib/tsan/go/tsan_go.cc)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/go/tsan_go.cpp?p2=compiler-rt/trunk/lib/tsan/go/tsan_go.cpp&p1=compiler-rt/trunk/lib/tsan/go/tsan_go.cc&r1=367566&r2=367567&rev=367567&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/go/tsan_go.cc (original)
+++ compiler-rt/trunk/lib/tsan/go/tsan_go.cpp Thu Aug 1 07:30:49 2019
@@ -1,4 +1,4 @@
-//===-- tsan_go.cc --------------------------------------------------------===//
+//===-- tsan_go.cpp -------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
More information about the llvm-commits
mailing list