[compiler-rt] [rtsan] Intercept aligned_alloc on all versions of OSX if available on build machine (PR #112780)

Chris Apple via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 18 10:11:10 PDT 2024


================
@@ -120,13 +120,17 @@ TEST(TestRtsanInterceptors, VallocDiesWhenRealtime) {
   ExpectNonRealtimeSurvival(Func);
 }
 
-#if SANITIZER_INTERCEPT_ALIGNED_ALLOC
 TEST(TestRtsanInterceptors, AlignedAllocDiesWhenRealtime) {
-  auto Func = []() { EXPECT_NE(nullptr, aligned_alloc(16, 32)); };
-  ExpectRealtimeDeath(Func, "aligned_alloc");
-  ExpectNonRealtimeSurvival(Func);
-}
+#if SANITIZER_APPLE
+  if (__builtin_available(macOS 10.15, *)) {
----------------
cjappl wrote:

Great find on those docs, I'll spend some time digging through them.

Taking the very first naive crack at it, it appears to have similar errors (please enclose in __builtin_available).

That was repro'd applying this patch:

```
diff --git a/compiler-rt/lib/rtsan/tests/rtsan_test_interceptors.cpp b/compiler-rt/lib/rtsan/tests/rtsan_test_interceptors.cpp
index fb227a1d1bc0..ad5c52fe7afc 100644
--- a/compiler-rt/lib/rtsan/tests/rtsan_test_interceptors.cpp
+++ b/compiler-rt/lib/rtsan/tests/rtsan_test_interceptors.cpp
@@ -120,9 +120,11 @@ TEST(TestRtsanInterceptors, VallocDiesWhenRealtime) {
   ExpectNonRealtimeSurvival(Func);
 }

+extern void* aligned_alloc(size_t, size_t) __attribute__((weak_import));
+
 TEST(TestRtsanInterceptors, AlignedAllocDiesWhenRealtime) {
 #if SANITIZER_APPLE
-  if (__builtin_available(macOS 10.15, *)) {
+  if (aligned_alloc != nullptr)
 #endif // SANITIZER_APPLE
     auto Func = []() { EXPECT_NE(nullptr, aligned_alloc(16, 32)); };
     ExpectRealtimeDeath(Func, "aligned_alloc");
```

https://github.com/llvm/llvm-project/pull/112780


More information about the llvm-commits mailing list