[sanitizer] Move {,__}pthread_mutex_{lock,unlock} interceptors to tsan
authorFangrui Song <i@maskray.me>
Wed, 4 Jan 2023 20:04:19 +0000 (12:04 -0800)
committerFangrui Song <i@maskray.me>
Wed, 4 Jan 2023 20:04:19 +0000 (12:04 -0800)
commitfb32a69855341630a7084364c66083264e1d18bf
treea9b3c0ea08e682fee232f0b9183dec93b977b88b
parentce43e2f07477a166712b7ee4a89fbc65d2ed56ad
[sanitizer] Move {,__}pthread_mutex_{lock,unlock} interceptors to tsan

These interceptors are pure forwarders for other sanitizers. Move them beside
tsan-specific pthread_mutex_{trylock,timedlock} interceptors.

While here, guard `__pthread_mutex_{lock,unlock}` (D46793) under `#if !__GLIBC_PREREQ(2, 34)`.

In glibc>=2.34 [1], `__pthread_mutex_{lock,unlock}` only have non-default-version definitions
(unversioned `__pthread_mutex_lock` causes a linker error. Program preloading is not expected).
In glibc>=2.36 [2], `dlsym(RTLD_NEXT, "__pthread_mutex_lock")` returns nullptr, so the interceptor won't work.

Fix https://github.com/llvm/llvm-project/issues/59820

[1]: https://sourceware.org/git/?p=glibc.git;a=commit;h=99f841c441feeaa9a3d97fd91bb3d6ec8073c982
[2]: https://sourceware.org/git/?p=glibc.git;a=commit;h=efa7936e4c91b1c260d03614bb26858fbb8a0204

Reviewed By: melver, vitalybuka

Differential Revision: https://reviews.llvm.org/D140957
compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h
compiler-rt/lib/tsan/rtl-old/tsan_interceptors_posix.cpp
compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp