Skip to content

[rtsan] Intercept aligned_alloc on all versions of OSX if available on build machine #112780

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 5 commits into from
Oct 28, 2024
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
17 changes: 12 additions & 5 deletions compiler-rt/lib/rtsan/tests/rtsan_test_interceptors_posix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,20 @@ TEST(TestRtsanInterceptors, VallocDiesWhenRealtime) {
ExpectNonRealtimeSurvival(Func);
}

#if SANITIZER_INTERCEPT_ALIGNED_ALLOC
#if __has_builtin(__builtin_available) && SANITIZER_APPLE
#define ALIGNED_ALLOC_AVAILABLE() (__builtin_available(macOS 10.15, *))
#else
// We are going to assume this is true until we hit systems where it isn't
#define ALIGNED_ALLOC_AVAILABLE() (true)
#endif

TEST(TestRtsanInterceptors, AlignedAllocDiesWhenRealtime) {
auto Func = []() { EXPECT_NE(nullptr, aligned_alloc(16, 32)); };
ExpectRealtimeDeath(Func, "aligned_alloc");
ExpectNonRealtimeSurvival(Func);
if (ALIGNED_ALLOC_AVAILABLE()) {
auto Func = []() { EXPECT_NE(nullptr, aligned_alloc(16, 32)); };
ExpectRealtimeDeath(Func, "aligned_alloc");
ExpectNonRealtimeSurvival(Func);
}
}
#endif

// free_sized and free_aligned_sized (both C23) are not yet supported
TEST(TestRtsanInterceptors, FreeDiesWhenRealtime) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,25 @@
#define SI_NOT_MAC 1
#endif

#if SANITIZER_APPLE
# include <Availability.h>

// aligned_alloc was introduced in OSX 10.15
// Linking will fail when using an older SDK
# if defined(__MAC_10_15)
// macOS 10.15 is greater than our minimal deployment target. To ensure we
// generate a weak reference so the dylib continues to work on older
// systems, we need to forward declare the intercepted function as "weak
// imports".
SANITIZER_WEAK_IMPORT void *aligned_alloc(__sanitizer::usize __alignment,
__sanitizer::usize __size);
# define SI_MAC_SDK_10_15_AVAILABLE 1
# else
# define SI_MAC_SDK_10_15_AVAILABLE 0
# endif // defined(__MAC_10_15)

#endif // SANITIZER_APPLE

#if SANITIZER_IOS
#define SI_IOS 1
#else
Expand Down Expand Up @@ -503,7 +522,8 @@
#define SANITIZER_INTERCEPT_PVALLOC (SI_GLIBC || SI_ANDROID)
#define SANITIZER_INTERCEPT_CFREE (SI_GLIBC && !SANITIZER_RISCV64)
#define SANITIZER_INTERCEPT_REALLOCARRAY SI_POSIX
#define SANITIZER_INTERCEPT_ALIGNED_ALLOC (!SI_MAC)
#define SANITIZER_INTERCEPT_ALIGNED_ALLOC \
(!SI_MAC || SI_MAC_SDK_10_15_AVAILABLE)
#define SANITIZER_INTERCEPT_MALLOC_USABLE_SIZE (!SI_MAC && !SI_NETBSD)
#define SANITIZER_INTERCEPT_MCHECK_MPROBE SI_LINUX_NOT_ANDROID
#define SANITIZER_INTERCEPT_WCSLEN 1
Expand Down
Loading