Skip to content

Commit 6d33293

Browse files
committed
PR: Match TSan's way of interception pthread_cond_*
1 parent 6c75d36 commit 6d33293

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
#include "interception/interception.h"
1717
#include "sanitizer_common/sanitizer_allocator_dlsym.h"
18+
#include "sanitizer_common/sanitizer_glibc_version.h"
1819
#include "sanitizer_common/sanitizer_platform_interceptors.h"
1920

2021
#include "interception/interception.h"
@@ -46,17 +47,6 @@
4647

4748
using namespace __sanitizer;
4849

49-
#if defined(__x86_64__) || defined(__mips__) || SANITIZER_PPC64V1 || \
50-
defined(__s390x__)
51-
#define PTHREAD_ABI_BASE "GLIBC_2.3.2"
52-
#elif defined(__aarch64__) || SANITIZER_PPC64V2
53-
#define PTHREAD_ABI_BASE "GLIBC_2.17"
54-
#elif SANITIZER_LOONGARCH64
55-
#define PTHREAD_ABI_BASE "GLIBC_2.36"
56-
#elif SANITIZER_RISCV64
57-
#define PTHREAD_ABI_BASE "GLIBC_2.27"
58-
#endif
59-
6050
DECLARE_REAL_AND_INTERCEPTOR(void *, malloc, usize size)
6151
DECLARE_REAL_AND_INTERCEPTOR(void, free, void *ptr)
6252

@@ -1701,12 +1691,24 @@ void __rtsan::InitializeInterceptors() {
17011691
INTERCEPT_FUNCTION(pthread_mutex_unlock);
17021692
INTERCEPT_FUNCTION(pthread_join);
17031693

1704-
INTERCEPT_FUNCTION_VER(pthread_cond_init, PTHREAD_ABI_BASE);
1705-
INTERCEPT_FUNCTION_VER(pthread_cond_signal, PTHREAD_ABI_BASE);
1706-
INTERCEPT_FUNCTION_VER(pthread_cond_broadcast, PTHREAD_ABI_BASE);
1707-
INTERCEPT_FUNCTION_VER(pthread_cond_wait, PTHREAD_ABI_BASE);
1708-
INTERCEPT_FUNCTION_VER(pthread_cond_timedwait, PTHREAD_ABI_BASE);
1709-
INTERCEPT_FUNCTION_VER(pthread_cond_destroy, PTHREAD_ABI_BASE);
1694+
// See the comment in tsan_interceptors_posix.cpp.
1695+
#if SANITIZER_GLIBC && !__GLIBC_PREREQ(2, 36) && \
1696+
(defined(__x86_64__) || defined(__mips__) || SANITIZER_PPC64V1 || \
1697+
defined(__s390x__))
1698+
INTERCEPT_FUNCTION_VER(pthread_cond_init, "GLIBC_2.3.2");
1699+
INTERCEPT_FUNCTION_VER(pthread_cond_signal, "GLIBC_2.3.2");
1700+
INTERCEPT_FUNCTION_VER(pthread_cond_broadcast, "GLIBC_2.3.2");
1701+
INTERCEPT_FUNCTION_VER(pthread_cond_wait, "GLIBC_2.3.2");
1702+
INTERCEPT_FUNCTION_VER(pthread_cond_timedwait, "GLIBC_2.3.2");
1703+
INTERCEPT_FUNCTION_VER(pthread_cond_destroy, "GLIBC_2.3.2");
1704+
#else
1705+
INTERCEPT_FUNCTION(pthread_cond_init);
1706+
INTERCEPT_FUNCTION(pthread_cond_signal);
1707+
INTERCEPT_FUNCTION(pthread_cond_broadcast);
1708+
INTERCEPT_FUNCTION(pthread_cond_wait);
1709+
INTERCEPT_FUNCTION(pthread_cond_timedwait);
1710+
INTERCEPT_FUNCTION(pthread_cond_destroy);
1711+
#endif
17101712

17111713
INTERCEPT_FUNCTION(pthread_rwlock_rdlock);
17121714
INTERCEPT_FUNCTION(pthread_rwlock_unlock);

0 commit comments

Comments
 (0)