From f2c5d76ab4b254060f4d52ccd3e0d2cf422e91f3 Mon Sep 17 00:00:00 2001 From: yinchuang Date: Tue, 8 Oct 2024 08:26:49 +0000 Subject: [PATCH] =?UTF-8?q?=E5=9B=9E=E9=80=80=20'Pull=20Request=20!602=20:?= =?UTF-8?q?=20[Tsan]=20Support=20hook=20call=5Fonce=20for=20ohos'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- compiler-rt/lib/tsan/rtl/CMakeLists.txt | 10 +---- .../lib/tsan/rtl/tsan_interceptors_posix.cpp | 44 ------------------- compiler-rt/test/tsan/libcxx_call_once.cpp | 27 ------------ 3 files changed, 2 insertions(+), 79 deletions(-) delete mode 100644 compiler-rt/test/tsan/libcxx_call_once.cpp diff --git a/compiler-rt/lib/tsan/rtl/CMakeLists.txt b/compiler-rt/lib/tsan/rtl/CMakeLists.txt index 3b225fb2d09c..057e53a00d91 100644 --- a/compiler-rt/lib/tsan/rtl/CMakeLists.txt +++ b/compiler-rt/lib/tsan/rtl/CMakeLists.txt @@ -14,16 +14,12 @@ set(TSAN_DYNAMIC_LINK_LIBS ${SANITIZER_CXX_ABI_LIBRARIES} ${SANITIZER_COMMON_LIN #OHOS_LOCAL set(TSAN_DYNAMIC_LINK_FLAGS ${SANITIZER_COMMON_LINK_FLAGS}) -#OHOS_LOCAL -set(TSAN_STATIC_FLAGS "") - #OHOS_LOCAL begin if(OHOS) # Put tsan library in the global group so that libraries which don't depend on tsan can also find symbols from tsan. if (COMPILER_RT_HAS_Z_GLOBAL) list(APPEND TSAN_DYNAMIC_LINK_FLAGS -Wl,-z,global) endif() - list(APPEND TSAN_STATIC_FLAGS "-DTSAN_STATIC") endif() #OHOS_LOCAL end @@ -259,8 +255,7 @@ else() $ $ ADDITIONAL_HEADERS ${TSAN_HEADERS} - #OHOS_LOCAL - CFLAGS ${TSAN_RTL_CFLAGS} ${TSAN_STATIC_FLAGS} + CFLAGS ${TSAN_RTL_CFLAGS} PARENT_TARGET tsan) add_compiler_rt_runtime(clang_rt.tsan_cxx STATIC @@ -268,8 +263,7 @@ else() SOURCES ${TSAN_CXX_SOURCES} $ ADDITIONAL_HEADERS ${TSAN_HEADERS} - #OHOS_LOCAL - CFLAGS ${TSAN_RTL_CFLAGS} ${TSAN_STATIC_FLAGS} + CFLAGS ${TSAN_RTL_CFLAGS} PARENT_TARGET tsan) list(APPEND TSAN_RUNTIME_LIBRARIES clang_rt.tsan-${arch} clang_rt.tsan_cxx-${arch}) diff --git a/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp b/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp index ab6380ee396c..595c7715b6af 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp +++ b/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp @@ -25,9 +25,6 @@ #include "interception/interception.h" #include "tsan_interceptors.h" #include "tsan_interface.h" -#if SANITIZER_OHOS -#include "tsan_interface_ann.h" -#endif #include "tsan_platform.h" #include "tsan_suppressions.h" #include "tsan_rtl.h" @@ -1972,42 +1969,6 @@ TSAN_INTERCEPTOR(int, pthread_sigmask, int how, const __sanitizer_sigset_t *set, return REAL(pthread_sigmask)(how, set, oldset); } -#if SANITIZER_OHOS && !TSAN_STATIC -// OHOS_LOCAL begin -struct call_once_callback_args { - void (*orig_func)(void *arg); - void *orig_arg; - void *flag; -}; - -void call_once_callback_wrapper(void *arg) { - call_once_callback_args *new_args = (call_once_callback_args *)arg; - new_args->orig_func(new_args->orig_arg); - __tsan_release(new_args->flag); -} - -// This adds a libc++ interceptor for: -// void __call_once(volatile unsigned long&, void*, void(*)(void*)); -// Tsan can't see the atomic operation in this interface. To avoid false -// positives, we intercept it and do an explicit Release after the user code. -TSAN_INTERCEPTOR(void, _ZNSt3__h11__call_onceERVmPvPFvS2_E, void *flag, - void *arg, void (*func)(void *arg)) { - call_once_callback_args new_args = {func, arg, flag}; - REAL(_ZNSt3__h11__call_onceERVmPvPFvS2_E)(flag, &new_args, - call_once_callback_wrapper); -}; - -// For __call_once in libc++_shared.so. -TSAN_INTERCEPTOR(void, _ZNSt4__n111__call_onceERVmPvPFvS2_E, void *flag, - void *arg, void (*func)(void *arg)) { - call_once_callback_args new_args = {func, arg, flag}; - REAL(_ZNSt4__n111__call_onceERVmPvPFvS2_E)(flag, &new_args, - call_once_callback_wrapper); -}; - -// OHOS_LOCAL end -#endif - namespace __tsan { static void ReportErrnoSpoiling(ThreadState *thr, uptr pc, int sig) { @@ -3001,11 +2962,6 @@ void InitializeInterceptors() { #endif #endif -#if SANITIZER_OHOS && !TSAN_STATIC - TSAN_INTERCEPT(_ZNSt3__h11__call_onceERVmPvPFvS2_E); - TSAN_INTERCEPT(_ZNSt4__n111__call_onceERVmPvPFvS2_E); -#endif - TSAN_MAYBE_INTERCEPT__LWP_EXIT; TSAN_MAYBE_INTERCEPT_THR_EXIT; diff --git a/compiler-rt/test/tsan/libcxx_call_once.cpp b/compiler-rt/test/tsan/libcxx_call_once.cpp deleted file mode 100644 index 3e9e20a8e47d..000000000000 --- a/compiler-rt/test/tsan/libcxx_call_once.cpp +++ /dev/null @@ -1,27 +0,0 @@ -// RUN: %clangxx_tsan %s -o %t && %run %t 2>&1 | FileCheck %s - -// REQUIRES: ohos_family - -#include -#include - -static int global = 0; -static std::once_flag flag; - -static void thread_func() { - std::call_once(flag, [] { global = 1; }); - fprintf(stderr, "global = %d.\n", global); -} - -int main() { - fprintf(stderr, "Begin.\n"); - std::thread t1(thread_func); - std::thread t2(thread_func); - t1.join(); - t2.join(); - fprintf(stderr, "End.\n"); -} - -// CHECK: Begin. -// CHECK-NOT: WARNING: ThreadSanitizer -// CHECK: End. -- Gitee