Skip to content

Commit 4c663a8

Browse files
committed
[TSan][Apple] Fix interceptor build error
In certain cases, the SDK headers declare `OSSpinLock*` APIs as macros (instead of functions), so users can be transparently forwarded to non-deprecated APIs. When enabled, building of TSan interceptors failed because these macros interfere with the interceptor machinery, i.e., they prevent proper forward declaration of intercepted APIs. In a previous change [1], we misattributed this to the deprecation of `OSSpinLock*` APIs. [1] ae484c2 rdar://143193907
1 parent 7293455 commit 4c663a8

File tree

2 files changed

+12
-46
lines changed

2 files changed

+12
-46
lines changed

compiler-rt/lib/tsan/rtl/tsan_interceptors_mac.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
# include "tsan_interceptors.h"
2626
# include "tsan_interface.h"
2727
# include "tsan_interface_ann.h"
28-
# include "tsan_spinlock_defs_mac.h"
2928

3029
# if defined(__has_include) && __has_include(<xpc/xpc.h>)
3130
# include <xpc/xpc.h>
@@ -196,6 +195,17 @@ TSAN_INTERCEPTOR(void *, OSAtomicFifoDequeue, OSFifoQueueHead *list,
196195

197196
# endif
198197

198+
// If `OSSPINLOCK_USE_INLINED=1` is set, then SDK headers don't declare these
199+
// as functions, but macros that call non-deprecated APIs. Undefine these
200+
// macros so they don't interfere with the interceptor machinery.
201+
# undef OSSpinLockLock
202+
# undef OSSpinLockTry
203+
# undef OSSpinLockUnlock
204+
205+
# pragma clang diagnostic push
206+
// OSSpinLock* functions are deprecated.
207+
# pragma clang diagnostic ignored "-Wdeprecated-declarations"
208+
199209
TSAN_INTERCEPTOR(void, OSSpinLockLock, volatile OSSpinLock *lock) {
200210
CHECK(!cur_thread()->is_dead);
201211
if (!cur_thread()->is_inited) {
@@ -227,6 +237,7 @@ TSAN_INTERCEPTOR(void, OSSpinLockUnlock, volatile OSSpinLock *lock) {
227237
Release(thr, pc, (uptr)lock);
228238
REAL(OSSpinLockUnlock)(lock);
229239
}
240+
# pragma clang diagnostic pop // OSSpinLock* deprecation
230241

231242
TSAN_INTERCEPTOR(void, os_lock_lock, void *lock) {
232243
CHECK(!cur_thread()->is_dead);

compiler-rt/lib/tsan/rtl/tsan_spinlock_defs_mac.h

Lines changed: 0 additions & 45 deletions
This file was deleted.

0 commit comments

Comments
 (0)