Skip to content

[TSan][Apple] Fix interceptor build error #124351

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions compiler-rt/lib/tsan/rtl/tsan_interceptors_mac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
# include "tsan_interceptors.h"
# include "tsan_interface.h"
# include "tsan_interface_ann.h"
# include "tsan_spinlock_defs_mac.h"

# if defined(__has_include) && __has_include(<xpc/xpc.h>)
# include <xpc/xpc.h>
Expand Down Expand Up @@ -96,8 +95,7 @@ static constexpr morder kMacFailureOrder = mo_relaxed;
m_orig(int32_t, uint32_t, a32, f##32##OrigBarrier, \
__tsan_atomic32_##tsan_atomic_f, kMacOrderBarrier)

# pragma clang diagnostic push
// OSAtomic* functions are deprecated.
# pragma clang diagnostic push // OSAtomic* deprecation
# pragma clang diagnostic ignored "-Wdeprecated-declarations"
OSATOMIC_INTERCEPTORS_ARITHMETIC(OSAtomicAdd, fetch_add,
OSATOMIC_INTERCEPTOR_PLUS_X)
Expand All @@ -111,6 +109,7 @@ OSATOMIC_INTERCEPTORS_BITWISE(OSAtomicAnd, fetch_and,
OSATOMIC_INTERCEPTOR_PLUS_X, OSATOMIC_INTERCEPTOR)
OSATOMIC_INTERCEPTORS_BITWISE(OSAtomicXor, fetch_xor,
OSATOMIC_INTERCEPTOR_PLUS_X, OSATOMIC_INTERCEPTOR)
# pragma clang diagnostic pop // OSAtomic* deprecation
Copy link
Collaborator Author

@yln yln Jan 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing pop here deactivated deprecation checking for the rest of the file. @cachemeifyoucan
I added it and fixed the remaining warnings.

Alternatively, we could put the # pragma clang diagnostic ignored "-Wdeprecated-declarations" at the start of the file to intentionally disable deprecation warnings for the entire file and relief ourselves from some tedium.
@vitalybuka, any style preferences?


# define OSATOMIC_INTERCEPTORS_CAS(f, tsan_atomic_f, tsan_t, t) \
TSAN_INTERCEPTOR(bool, f, t old_value, t new_value, t volatile *ptr) { \
Expand All @@ -128,8 +127,7 @@ OSATOMIC_INTERCEPTORS_BITWISE(OSAtomicXor, fetch_xor,
kMacOrderBarrier, kMacFailureOrder); \
}

# pragma clang diagnostic push
// OSAtomicCompareAndSwap* functions are deprecated.
# pragma clang diagnostic push // OSAtomicCompareAndSwap* deprecation
# pragma clang diagnostic ignored "-Wdeprecated-declarations"
OSATOMIC_INTERCEPTORS_CAS(OSAtomicCompareAndSwapInt, __tsan_atomic32, a32, int)
OSATOMIC_INTERCEPTORS_CAS(OSAtomicCompareAndSwapLong, __tsan_atomic64, a64,
Expand All @@ -140,7 +138,7 @@ OSATOMIC_INTERCEPTORS_CAS(OSAtomicCompareAndSwap32, __tsan_atomic32, a32,
int32_t)
OSATOMIC_INTERCEPTORS_CAS(OSAtomicCompareAndSwap64, __tsan_atomic64, a64,
int64_t)
# pragma clang diagnostic pop
# pragma clang diagnostic pop // OSAtomicCompareAndSwap* deprecation

# define OSATOMIC_INTERCEPTOR_BITOP(f, op, clear, mo) \
TSAN_INTERCEPTOR(bool, f, uint32_t n, volatile void *ptr) { \
Expand All @@ -156,9 +154,12 @@ OSATOMIC_INTERCEPTORS_CAS(OSAtomicCompareAndSwap64, __tsan_atomic64, a64,
OSATOMIC_INTERCEPTOR_BITOP(f, op, clear, kMacOrderNonBarrier) \
OSATOMIC_INTERCEPTOR_BITOP(f##Barrier, op, clear, kMacOrderBarrier)

# pragma clang diagnostic push // OSAtomicTestAnd* deprecation
# pragma clang diagnostic ignored "-Wdeprecated-declarations"
OSATOMIC_INTERCEPTORS_BITOP(OSAtomicTestAndSet, __tsan_atomic8_fetch_or, false)
OSATOMIC_INTERCEPTORS_BITOP(OSAtomicTestAndClear, __tsan_atomic8_fetch_and,
true)
# pragma clang diagnostic pop // OSAtomicTestAnd* deprecation

TSAN_INTERCEPTOR(void, OSAtomicEnqueue, OSQueueHead *list, void *item,
size_t offset) {
Expand Down Expand Up @@ -196,6 +197,16 @@ TSAN_INTERCEPTOR(void *, OSAtomicFifoDequeue, OSFifoQueueHead *list,

# endif

// If `OSSPINLOCK_USE_INLINED=1` is set, then SDK headers don't declare these
// as functions, but macros that call non-deprecated APIs. Undefine these
// macros so they don't interfere with the interceptor machinery.
# undef OSSpinLockLock
# undef OSSpinLockTry
# undef OSSpinLockUnlock

# pragma clang diagnostic push // OSSpinLock* deprecation
# pragma clang diagnostic ignored "-Wdeprecated-declarations"

TSAN_INTERCEPTOR(void, OSSpinLockLock, volatile OSSpinLock *lock) {
CHECK(!cur_thread()->is_dead);
if (!cur_thread()->is_inited) {
Expand Down Expand Up @@ -227,6 +238,7 @@ TSAN_INTERCEPTOR(void, OSSpinLockUnlock, volatile OSSpinLock *lock) {
Release(thr, pc, (uptr)lock);
REAL(OSSpinLockUnlock)(lock);
}
# pragma clang diagnostic pop // OSSpinLock* deprecation

TSAN_INTERCEPTOR(void, os_lock_lock, void *lock) {
CHECK(!cur_thread()->is_dead);
Expand Down
45 changes: 0 additions & 45 deletions compiler-rt/lib/tsan/rtl/tsan_spinlock_defs_mac.h

This file was deleted.

Loading