[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
Tue Oct 29 06:46:50 PDT 2024


cjappl wrote:

@wrotki -  a few thoughts here, wondering if I can get your input.

First, I can't repro this issue still. Strangely I do get the warning in the unit tests (which is why I used __builtin_available in the tests) but not in the source. It appears I'm just using the default sanitizer min OSX version (10.13)

Second, what if we just disabled this warning for aligned_alloc? (took this original patch, and additionally)

```diff
diff --git a/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp b/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp
index 890d6c11c407..7be1f07733f0 100644
--- a/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp
+++ b/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp
@@ -464,10 +464,13 @@ INTERCEPTOR(void *, valloc, SIZE_T size) {
 }

 #if SANITIZER_INTERCEPT_ALIGNED_ALLOC
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wunguarded-availability-new"
 INTERCEPTOR(void *, aligned_alloc, SIZE_T alignment, SIZE_T size) {
   __rtsan_notify_intercepted_call("aligned_alloc");
   return REAL(aligned_alloc)(alignment, size);
 }
+#pragma clang diagnostic pop
 #define RTSAN_MAYBE_INTERCEPT_ALIGNED_ALLOC INTERCEPT_FUNCTION(aligned_alloc)
 #else
 #define RTSAN_MAYBE_INTERCEPT_ALIGNED_ALLOC

```

Why is this OK? 

(Theory) 
We know that it will never be called on systems that do not have `aligned_alloc` defined because the client OSX won't provide it. This function **is** actually guarded on OS's lower than 10.15 because `aligned_alloc` declaration won't exist on that version. There will be no way to call this function from code.


Third (as a completely different thought)

This approach was cribbed from the tsan approach, which pre-declares some libdispatch API only available in 10.14. However, it seems as if your build bot has been happy with it. So far, I haven't been able to see the difference between my approach and the tsan approach, maybe there is some clue there you can see?

The code I based this off of is here:
https://github.com/llvm/llvm-project/blob/f7669ba3d9443bc95dd63fa25beea13e6265fdc5/compiler-rt/lib/tsan/rtl/tsan_interceptors_libdispatch.cpp#L226-L247

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


More information about the llvm-commits mailing list