[compiler-rt] rtsan: Support free_sized and free_aligned_sized from C23 (PR #145085)
Justin King via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 1 06:00:59 PDT 2025
================
@@ -869,6 +869,48 @@ INTERCEPTOR(void, free, void *ptr) {
return REAL(free)(ptr);
}
+#if SANITIZER_INTERCEPT_FREE_SIZED
+INTERCEPTOR(void, free_sized, void *ptr, SIZE_T size) {
+ if (DlsymAlloc::PointerIsMine(ptr))
+ return DlsymAlloc::Free(ptr);
+
+ // According to the C and C++ standard, freeing a nullptr is guaranteed to be
+ // a no-op (and thus real-time safe). This can be confirmed for looking at
+ // __libc_free in the glibc source.
+ if (ptr != nullptr)
+ __rtsan_notify_intercepted_call("free_sized");
+
+ if (REAL(free_sized))
----------------
jcking wrote:
On ELF-based systems, like Linux, the interception code doesn't require that the underlying real function actually exist. This will result in the real function pointer being `nullptr`. In that case, we forward to `free` which we assume exists or we have bigger problems.
https://github.com/llvm/llvm-project/pull/145085
More information about the llvm-commits
mailing list