[compiler-rt] Reland "[rtsan] Intercept aligned_alloc on all versions of OSX if available on the build machine" (PR #114153)
Chris Apple via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 29 18:08:37 PDT 2024
================
@@ -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"
----------------
cjappl wrote:
https://developer.apple.com/library/archive/documentation/MacOSX/Conceptual/BPFrameworks/Concepts/WeakLinking.html
This documentation may be helpful.
My understanding below:
If code that is **built** on a build machine that is aware of `aligned_alloc`, and the binary has a function that calls it "unguarded":
```cpp
int main()
{
aligned_alloc(alignof(int), sizeof(int));
}
```
It will crash when it **runs** on systems that do not have this function defined (OSX < 10.15)
You can get around this by guarding it:
```
int main()
{
if (__builtin_available(macOS 10.15, *))
aligned_alloc(alignof(int), sizeof(int));
else
malloc(sizeof(int));
}
```
In this PR we add aligned_alloc as a weak import so it will link on our build machine, if the build machine is 10.15 or greater (aware of the symbol `__MAC_10_15`). This is necessary because the OS version we build for is min version 10.13.
We define the interceptor function, and turn of the unguarded warning, so if a client machine has `aligned_alloc` it will be intercepted.
If the client machine does not have `aligned_alloc` (<10.15), it will not have `aligned_alloc` (a little circular logic, for you), and we will never intercept anything, so us defining this interceptor will have no effect and cause no issue
https://github.com/llvm/llvm-project/pull/114153
More information about the llvm-commits
mailing list