Skip to content

Commit 1e127da

Browse files
committed
[PR] vitalybuka - move aligned_alloc def up to all interceptors
1 parent f2c3523 commit 1e127da

File tree

3 files changed

+27
-16
lines changed

3 files changed

+27
-16
lines changed

compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -461,19 +461,6 @@ INTERCEPTOR(void *, valloc, SIZE_T size) {
461461
return REAL(valloc)(size);
462462
}
463463

464-
// aligned_alloc was introduced in OSX 10.15
465-
// Linking will fail when using an older SDK
466-
#if SANITIZER_APPLE && defined(__MAC_10_15)
467-
// macOS 10.15 is greater than our minimal deployment target. To ensure we
468-
// generate a weak reference so the dylib continues to work on older
469-
// systems, we need to forward declare the intercepted function as "weak
470-
// imports".
471-
SANITIZER_WEAK_IMPORT void *aligned_alloc(SIZE_T __alignment, SIZE_T __size);
472-
473-
#undef SANITIZER_INTERCEPT_ALIGNED_ALLOC
474-
#define SANITIZER_INTERCEPT_ALIGNED_ALLOC 1
475-
#endif // SANITIZER_APPLE && defined(__MAC_10_15)
476-
477464
#if SANITIZER_INTERCEPT_ALIGNED_ALLOC
478465
INTERCEPTOR(void *, aligned_alloc, SIZE_T alignment, SIZE_T size) {
479466
__rtsan_notify_intercepted_call("aligned_alloc");

compiler-rt/lib/rtsan/tests/rtsan_test_interceptors_posix.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,10 @@ TEST(TestRtsanInterceptors, VallocDiesWhenRealtime) {
121121
}
122122

123123
#if __has_builtin(__builtin_available) && SANITIZER_APPLE
124-
#define ALIGNED_ALLOC_AVAILABLE() __builtin_available(macOS 10.15, *)
124+
#define ALIGNED_ALLOC_AVAILABLE() (__builtin_available(macOS 10.15, *))
125125
#else
126126
// We are going to assume this is true until we hit systems where it isn't
127-
#define ALIGNED_ALLOC_AVAILABLE() true
127+
#define ALIGNED_ALLOC_AVAILABLE() (true)
128128
#endif
129129

130130
TEST(TestRtsanInterceptors, AlignedAllocDiesWhenRealtime) {

compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@
8484
#define SI_NOT_MAC 1
8585
#endif
8686

87+
#if SANITIZER_APPLE
88+
# include <Availability.h>
89+
#endif
90+
8791
#if SANITIZER_IOS
8892
#define SI_IOS 1
8993
#else
@@ -503,7 +507,27 @@
503507
#define SANITIZER_INTERCEPT_PVALLOC (SI_GLIBC || SI_ANDROID)
504508
#define SANITIZER_INTERCEPT_CFREE (SI_GLIBC && !SANITIZER_RISCV64)
505509
#define SANITIZER_INTERCEPT_REALLOCARRAY SI_POSIX
506-
#define SANITIZER_INTERCEPT_ALIGNED_ALLOC (!SI_MAC)
510+
511+
#if SANITIZER_APPLE && defined(__MAC_10_15)
512+
# define SI_MAC_SDK_10_15_AVAILABLE 1
513+
#else
514+
# define SI_MAC_SDK_10_15_AVAILABLE 0
515+
#endif // SANITIZER_APPLE && defined(__MAC_10_15)
516+
517+
// aligned_alloc was introduced in OSX 10.15
518+
// Linking will fail when using an older SDK
519+
#if SI_MAC_SDK_10_15_AVAILABLE
520+
// macOS 10.15 is greater than our minimal deployment target. To ensure we
521+
// generate a weak reference so the dylib continues to work on older
522+
// systems, we need to forward declare the intercepted function as "weak
523+
// imports".
524+
SANITIZER_WEAK_IMPORT void *aligned_alloc(__sanitizer::usize __alignment,
525+
__sanitizer::usize __size);
526+
#endif // SI_MAC_SDK_10_15_AVAILABLE
527+
528+
#define SANITIZER_INTERCEPT_ALIGNED_ALLOC \
529+
(!SI_MAC || SI_MAC_SDK_10_15_AVAILABLE)
530+
507531
#define SANITIZER_INTERCEPT_MALLOC_USABLE_SIZE (!SI_MAC && !SI_NETBSD)
508532
#define SANITIZER_INTERCEPT_MCHECK_MPROBE SI_LINUX_NOT_ANDROID
509533
#define SANITIZER_INTERCEPT_WCSLEN 1

0 commit comments

Comments
 (0)