[compiler-rt] [sanitizer_common][asan] Implement address sanitizer on AIX: interceptors (5/6) (PR #131870)

Jake Egan via llvm-commits llvm-commits at lists.llvm.org
Tue May 6 06:52:28 PDT 2025


https://github.com/jakeegan updated https://github.com/llvm/llvm-project/pull/131870

>From 1c2952c42322c0822a5d6fb0f5e38aa0f56ad8e3 Mon Sep 17 00:00:00 2001
From: Jake Egan <jake.egan at ibm.com>
Date: Tue, 18 Mar 2025 01:46:07 -0400
Subject: [PATCH 01/15] [sanitizer_common] Implement interceptors for AIX

---
 compiler-rt/lib/interception/CMakeLists.txt   |  2 +
 compiler-rt/lib/interception/interception.h   | 19 ++++++-
 .../lib/interception/interception_aix.cpp     | 45 ++++++++++++++++
 .../lib/interception/interception_aix.h       | 36 +++++++++++++
 .../sanitizer_common_interceptors.inc         | 52 ++++++++++++++-----
 .../sanitizer_common_interceptors_ioctl.inc   |  2 +
 ...izer_common_interceptors_memintrinsics.inc |  2 +
 .../sanitizer_platform_interceptors.h         | 52 ++++++++++++-------
 .../sanitizer_redefine_builtins.h             |  2 +-
 9 files changed, 178 insertions(+), 34 deletions(-)
 create mode 100644 compiler-rt/lib/interception/interception_aix.cpp
 create mode 100644 compiler-rt/lib/interception/interception_aix.h

diff --git a/compiler-rt/lib/interception/CMakeLists.txt b/compiler-rt/lib/interception/CMakeLists.txt
index fe7fa27fbc78b..57c8c8ba20141 100644
--- a/compiler-rt/lib/interception/CMakeLists.txt
+++ b/compiler-rt/lib/interception/CMakeLists.txt
@@ -1,6 +1,7 @@
 # Build for the runtime interception helper library.
 
 set(INTERCEPTION_SOURCES
+  interception_aix.cpp
   interception_linux.cpp
   interception_mac.cpp
   interception_win.cpp
@@ -9,6 +10,7 @@ set(INTERCEPTION_SOURCES
 
 set(INTERCEPTION_HEADERS
   interception.h
+  interception_aix.h
   interception_linux.h
   interception_mac.h
   interception_win.h
diff --git a/compiler-rt/lib/interception/interception.h b/compiler-rt/lib/interception/interception.h
index 3cb6b446638e0..3a20cfb04dcd6 100644
--- a/compiler-rt/lib/interception/interception.h
+++ b/compiler-rt/lib/interception/interception.h
@@ -19,7 +19,7 @@
 
 #if !SANITIZER_LINUX && !SANITIZER_FREEBSD && !SANITIZER_APPLE &&    \
     !SANITIZER_NETBSD && !SANITIZER_WINDOWS && !SANITIZER_FUCHSIA && \
-    !SANITIZER_SOLARIS
+    !SANITIZER_SOLARIS && !SANITIZER_AIX
 #  error "Interception doesn't work on this operating system."
 #endif
 
@@ -168,6 +168,16 @@ const interpose_substitution substitution_##func_name[]             \
     extern "C" ret_type func(__VA_ARGS__);
 # define DECLARE_WRAPPER_WINAPI(ret_type, func, ...)  \
     extern "C" __declspec(dllimport) ret_type __stdcall func(__VA_ARGS__);
+#elif SANITIZER_AIX
+#  define WRAP(x) __interceptor_##x
+#  define TRAMPOLINE(x) WRAP(x)
+// # define WRAPPER_NAME(x) "__interceptor_" #x
+#  define INTERCEPTOR_ATTRIBUTE __attribute__((visibility("default")))
+// AIX's linker will not select the weak symbol, so don't use weak for the
+// interceptors.
+#  define DECLARE_WRAPPER(ret_type, func, ...) \
+    extern "C" ret_type func(__VA_ARGS__)      \
+        __attribute__((alias("__interceptor_" #func), visibility("default")));
 #elif !SANITIZER_FUCHSIA  // LINUX, FREEBSD, NETBSD, SOLARIS
 # define INTERCEPTOR_ATTRIBUTE __attribute__((visibility("default")))
 # if ASM_INTERCEPTOR_TRAMPOLINE_SUPPORT
@@ -367,7 +377,12 @@ inline void DoesNotSupportStaticLinking() {}
 
 #define INCLUDED_FROM_INTERCEPTION_LIB
 
-#if SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_NETBSD || \
+#if SANITIZER_AIX
+# include "interception_aix.h"
+# define INTERCEPT_FUNCTION(func) INTERCEPT_FUNCTION_AIX(func)
+# define INTERCEPT_FUNCTION_VER(func, symver) INTERCEPT_FUNCTION_AIX(func)
+
+#elif SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_NETBSD || \
     SANITIZER_SOLARIS
 
 # include "interception_linux.h"
diff --git a/compiler-rt/lib/interception/interception_aix.cpp b/compiler-rt/lib/interception/interception_aix.cpp
new file mode 100644
index 0000000000000..953bbad96eb47
--- /dev/null
+++ b/compiler-rt/lib/interception/interception_aix.cpp
@@ -0,0 +1,45 @@
+//===-- interception_aix.cpp ------------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This file is a part of AddressSanitizer, an address sanity checker.
+//
+// AIX-specific interception methods.
+//===----------------------------------------------------------------------===//
+
+#include "interception.h"
+#include "sanitizer_common/sanitizer_common.h"
+
+#if SANITIZER_AIX
+
+#  include <dlfcn.h>  // for dlsym()
+
+namespace __interception {
+
+static void *GetFuncAddr(const char *name, uptr wrapper_addr) {
+  // AIX dlsym can only defect the functions that are exported, so
+  // on AIX, we can not intercept some basic functions like memcpy.
+  // FIXME: if we are going to ship dynamic asan library, we may need to search
+  // all the loaded modules with RTLD_DEFAULT if RTLD_NEXT failed.
+  void *addr = dlsym(RTLD_NEXT, name);
+
+  // In case `name' is not loaded, dlsym ends up finding the actual wrapper.
+  // We don't want to intercept the wrapper and have it point to itself.
+  if ((uptr)addr == wrapper_addr)
+    addr = nullptr;
+  return addr;
+}
+
+bool InterceptFunction(const char *name, uptr *ptr_to_real, uptr func,
+                       uptr wrapper) {
+  void *addr = GetFuncAddr(name, wrapper);
+  *ptr_to_real = (uptr)addr;
+  return addr && (func == wrapper);
+}
+
+}  // namespace __interception
+#endif  // SANITIZER_AIX
diff --git a/compiler-rt/lib/interception/interception_aix.h b/compiler-rt/lib/interception/interception_aix.h
new file mode 100644
index 0000000000000..08d17caeb6a8d
--- /dev/null
+++ b/compiler-rt/lib/interception/interception_aix.h
@@ -0,0 +1,36 @@
+//===-- interception_aix.h --------------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This file is a part of AddressSanitizer, an address sanity checker.
+//
+// AIX-specific interception methods.
+//===----------------------------------------------------------------------===//
+
+#if SANITIZER_AIX
+
+#  if !defined(INCLUDED_FROM_INTERCEPTION_LIB)
+#    error \
+        "interception_aix.h should be included from interception library only"
+#  endif
+
+#  ifndef INTERCEPTION_AIX_H
+#    define INTERCEPTION_AIX_H
+
+namespace __interception {
+bool InterceptFunction(const char *name, uptr *ptr_to_real, uptr func,
+                       uptr wrapper);
+}  // namespace __interception
+
+#    define INTERCEPT_FUNCTION_AIX(func)                \
+      ::__interception::InterceptFunction(              \
+          #func, (::__interception::uptr *)&REAL(func), \
+          (::__interception::uptr) & (func),            \
+          (::__interception::uptr)&WRAP(func))
+
+#  endif  // INTERCEPTION_AIX_H
+#endif    // SANITIZER_AIX
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
index 24a8a2d4dc55b..a71981282f615 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
@@ -480,7 +480,7 @@ INTERCEPTOR(char*, textdomain, const char *domainname) {
 #define INIT_TEXTDOMAIN
 #endif
 
-#if SANITIZER_INTERCEPT_STRCMP || SANITIZER_INTERCEPT_MEMCMP
+#if SANITIZER_INTERCEPT_MEMCMP
 static inline int CharCmpX(unsigned char c1, unsigned char c2) {
   return (c1 == c2) ? 0 : (c1 < c2) ? -1 : 1;
 }
@@ -953,7 +953,7 @@ INTERCEPTOR(double, frexp, double x, int *exp) {
 #define INIT_FREXP
 #endif  // SANITIZER_INTERCEPT_FREXP
 
-#if SANITIZER_INTERCEPT_FREXPF_FREXPL
+#if SANITIZER_INTERCEPT_FREXPF
 INTERCEPTOR(float, frexpf, float x, int *exp) {
   void *ctx;
   COMMON_INTERCEPTOR_ENTER(ctx, frexpf, x, exp);
@@ -963,6 +963,12 @@ INTERCEPTOR(float, frexpf, float x, int *exp) {
   return res;
 }
 
+#define INIT_FREXPF COMMON_INTERCEPT_FUNCTION(frexpf);
+#else
+#define INIT_FREXPF
+#endif
+
+#if SANITIZER_INTERCEPT_FREXPL
 INTERCEPTOR(long double, frexpl, long double x, int *exp) {
   void *ctx;
   COMMON_INTERCEPTOR_ENTER(ctx, frexpl, x, exp);
@@ -972,12 +978,10 @@ INTERCEPTOR(long double, frexpl, long double x, int *exp) {
   return res;
 }
 
-#define INIT_FREXPF_FREXPL           \
-  COMMON_INTERCEPT_FUNCTION(frexpf); \
-  COMMON_INTERCEPT_FUNCTION_LDBL(frexpl)
+#define INIT_FREXPL COMMON_INTERCEPT_FUNCTION_LDBL(frexpl)
 #else
-#define INIT_FREXPF_FREXPL
-#endif  // SANITIZER_INTERCEPT_FREXPF_FREXPL
+#define INIT_FREXPL
+#endif
 
 #if SI_POSIX
 static void write_iovec(void *ctx, struct __sanitizer_iovec *iovec,
@@ -1346,7 +1350,8 @@ INTERCEPTOR(unsigned long, time, unsigned long *t) {
 #if SANITIZER_INTERCEPT_LOCALTIME_AND_FRIENDS
 static void unpoison_tm(void *ctx, __sanitizer_tm *tm) {
   COMMON_INTERCEPTOR_WRITE_RANGE(ctx, tm, sizeof(*tm));
-#if !SANITIZER_SOLARIS
+// AIX tm struct does not have tm_zone field.
+#if !SANITIZER_SOLARIS && !SANITIZER_AIX
   if (tm->tm_zone) {
     // Can not use COMMON_INTERCEPTOR_WRITE_RANGE here, because tm->tm_zone
     // can point to shared memory and tsan would report a data race.
@@ -1731,8 +1736,10 @@ INTERCEPTOR(int, __vsprintf_chk, char *str, int flag, SIZE_T size_to,
 VSPRINTF_INTERCEPTOR_IMPL(vsprintf, str, format, ap)
 #endif
 
+#if SANITIZER_INTERCEPT_VASPRINTF
 INTERCEPTOR(int, vasprintf, char **strp, const char *format, va_list ap)
 VASPRINTF_INTERCEPTOR_IMPL(vasprintf, strp, format, ap)
+#endif
 
 #if SANITIZER_INTERCEPT_ISOC99_PRINTF
 INTERCEPTOR(int, __isoc99_vprintf, const char *format, va_list ap)
@@ -1783,8 +1790,10 @@ INTERCEPTOR(int, __snprintf_chk, char *str, SIZE_T size, int flag,
 FORMAT_INTERCEPTOR_IMPL(__snprintf_chk, vsnprintf, str, size, format)
 #endif
 
+#if SANITIZER_INTERCEPT_ASPRINTF
 INTERCEPTOR(int, asprintf, char **strp, const char *format, ...)
 FORMAT_INTERCEPTOR_IMPL(asprintf, vasprintf, strp, format)
+#endif
 
 #if SANITIZER_INTERCEPT_ISOC99_PRINTF
 INTERCEPTOR(int, __isoc99_printf, const char *format, ...)
@@ -1807,17 +1816,29 @@ FORMAT_INTERCEPTOR_IMPL(__isoc99_snprintf, __isoc99_vsnprintf, str, size,
 #endif  // SANITIZER_INTERCEPT_PRINTF
 
 #if SANITIZER_INTERCEPT_PRINTF
+#if SANITIZER_AIX
+#define INIT_PRINTF                     \
+  COMMON_INTERCEPT_FUNCTION_LDBL(printf);    \
+  COMMON_INTERCEPT_FUNCTION_LDBL(sprintf);   \
+  COMMON_INTERCEPT_FUNCTION_LDBL(snprintf);  \
+  COMMON_INTERCEPT_FUNCTION_LDBL(fprintf);   \
+  COMMON_INTERCEPT_FUNCTION_LDBL(vprintf);   \
+  COMMON_INTERCEPT_FUNCTION_LDBL(vsprintf);  \
+  COMMON_INTERCEPT_FUNCTION_LDBL(vsnprintf); \
+  COMMON_INTERCEPT_FUNCTION_LDBL(vfprintf);
+#else
 #define INIT_PRINTF                     \
   COMMON_INTERCEPT_FUNCTION_LDBL(printf);    \
   COMMON_INTERCEPT_FUNCTION_LDBL(sprintf);   \
   COMMON_INTERCEPT_FUNCTION_LDBL(snprintf);  \
-  COMMON_INTERCEPT_FUNCTION_LDBL(asprintf);  \
   COMMON_INTERCEPT_FUNCTION_LDBL(fprintf);   \
   COMMON_INTERCEPT_FUNCTION_LDBL(vprintf);   \
   COMMON_INTERCEPT_FUNCTION_LDBL(vsprintf);  \
   COMMON_INTERCEPT_FUNCTION_LDBL(vsnprintf); \
+  COMMON_INTERCEPT_FUNCTION_LDBL(asprintf);  \
   COMMON_INTERCEPT_FUNCTION_LDBL(vasprintf); \
   COMMON_INTERCEPT_FUNCTION_LDBL(vfprintf);
+#endif
 #else
 #define INIT_PRINTF
 #endif
@@ -3901,7 +3922,10 @@ INTERCEPTOR(SIZE_T, wcrtomb, char *dest, wchar_t src, void *ps) {
   if (res != ((SIZE_T)-1)) {
     CHECK_LE(res, sizeof(local_dest));
     COMMON_INTERCEPTOR_WRITE_RANGE(ctx, dest, res);
-    REAL(memcpy)(dest, local_dest, res);
+    if (!SANITIZER_AIX)
+      REAL(memcpy)(dest, local_dest, res);
+    else
+      internal_memcpy(dest, local_dest, res);
   }
   return res;
 }
@@ -3923,7 +3947,10 @@ INTERCEPTOR(int, wctomb, char *dest, wchar_t src) {
   if (res != -1) {
     CHECK_LE(res, sizeof(local_dest));
     COMMON_INTERCEPTOR_WRITE_RANGE(ctx, dest, res);
-    REAL(memcpy)(dest, local_dest, res);
+    if (!SANITIZER_AIX)
+      REAL(memcpy)(dest, local_dest, res);
+    else
+      internal_memcpy(dest, local_dest, res);
   }
   return res;
 }
@@ -10329,7 +10356,8 @@ static void InitializeCommonInterceptors() {
   INIT_PRINTF_L;
   INIT_ISOC99_PRINTF;
   INIT_FREXP;
-  INIT_FREXPF_FREXPL;
+  INIT_FREXPF;
+  INIT_FREXPL;
   INIT_GETPWNAM_AND_FRIENDS;
   INIT_GETPWNAM_R_AND_FRIENDS;
   INIT_GETPWENT;
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors_ioctl.inc b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors_ioctl.inc
index 49ec4097c900b..5b23039954a43 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors_ioctl.inc
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors_ioctl.inc
@@ -73,7 +73,9 @@ static void ioctl_table_fill() {
   _(TIOCNXCL, NONE, 0);
   _(TIOCOUTQ, WRITE, sizeof(int));
   _(TIOCPKT, READ, sizeof(int));
+#if !SANITIZER_AIX
   _(TIOCSCTTY, NONE, 0);
+#endif
   _(TIOCSETD, READ, sizeof(int));
   _(TIOCSPGRP, READ, pid_t_sz);
   _(TIOCSTI, READ, sizeof(char));
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors_memintrinsics.inc b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors_memintrinsics.inc
index 1565a494140f6..e542a6c7b438a 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors_memintrinsics.inc
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors_memintrinsics.inc
@@ -36,6 +36,8 @@
 #define PLATFORM_HAS_DIFFERENT_MEMCPY_AND_MEMMOVE 0
 #elif SANITIZER_WINDOWS64
 #define PLATFORM_HAS_DIFFERENT_MEMCPY_AND_MEMMOVE 0
+#elif SANITIZER_AIX
+#define PLATFORM_HAS_DIFFERENT_MEMCPY_AND_MEMMOVE 0
 #else
 #define PLATFORM_HAS_DIFFERENT_MEMCPY_AND_MEMMOVE 1
 #endif  // SANITIZER_APPLE
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h b/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h
index febd233bb1e3c..43a37037c971d 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h
@@ -139,6 +139,12 @@ SANITIZER_WEAK_IMPORT void *aligned_alloc(__sanitizer::usize __alignment,
 #define SI_SOLARIS 0
 #endif
 
+#if SANITIZER_AIX
+#define SI_NOT_AIX 0
+#else
+#define SI_NOT_AIX 1
+#endif
+
 #if SANITIZER_SOLARIS32
 #define SI_SOLARIS32 1
 #else
@@ -159,20 +165,20 @@ SANITIZER_WEAK_IMPORT void *aligned_alloc(__sanitizer::usize __alignment,
 
 #define SANITIZER_INTERCEPT_STRLEN SI_NOT_FUCHSIA
 #define SANITIZER_INTERCEPT_STRNLEN (SI_NOT_MAC && SI_NOT_FUCHSIA)
-#define SANITIZER_INTERCEPT_STRCMP SI_NOT_FUCHSIA
+#define SANITIZER_INTERCEPT_STRCMP (SI_NOT_FUCHSIA && SI_NOT_AIX)
 #define SANITIZER_INTERCEPT_STRSTR SI_NOT_FUCHSIA
-#define SANITIZER_INTERCEPT_STRCASESTR SI_POSIX
+#define SANITIZER_INTERCEPT_STRCASESTR (SI_POSIX && SI_NOT_AIX)
 #define SANITIZER_INTERCEPT_STRTOK SI_NOT_FUCHSIA
 #define SANITIZER_INTERCEPT_STRCHR SI_NOT_FUCHSIA
-#define SANITIZER_INTERCEPT_STRCHRNUL SI_POSIX_NOT_MAC
+#define SANITIZER_INTERCEPT_STRCHRNUL (SI_POSIX_NOT_MAC && SI_NOT_AIX)
 #define SANITIZER_INTERCEPT_STRRCHR SI_NOT_FUCHSIA
 #define SANITIZER_INTERCEPT_STRSPN SI_NOT_FUCHSIA
 #define SANITIZER_INTERCEPT_STRPBRK SI_NOT_FUCHSIA
 #define SANITIZER_INTERCEPT_TEXTDOMAIN SI_LINUX_NOT_ANDROID || SI_SOLARIS
 #define SANITIZER_INTERCEPT_STRCASECMP SI_POSIX
 #define SANITIZER_INTERCEPT_MEMSET 1
-#define SANITIZER_INTERCEPT_MEMMOVE 1
-#define SANITIZER_INTERCEPT_MEMCPY 1
+#define SANITIZER_INTERCEPT_MEMMOVE SI_NOT_AIX
+#define SANITIZER_INTERCEPT_MEMCPY SI_NOT_AIX
 #define SANITIZER_INTERCEPT_MEMCMP SI_NOT_FUCHSIA
 #define SANITIZER_INTERCEPT_BCMP \
   SANITIZER_INTERCEPT_MEMCMP &&  \
@@ -231,6 +237,8 @@ SANITIZER_WEAK_IMPORT void *aligned_alloc(__sanitizer::usize __alignment,
 #define SANITIZER_INTERCEPT_ISOC99_SCANF SI_GLIBC
 
 #ifndef SANITIZER_INTERCEPT_PRINTF
+#define SANITIZER_INTERCEPT_ASPRINTF SI_NOT_AIX
+#define SANITIZER_INTERCEPT_VASPRINTF SI_NOT_AIX
 #define SANITIZER_INTERCEPT_PRINTF SI_POSIX
 #define SANITIZER_INTERCEPT_PRINTF_L (SI_FREEBSD || SI_NETBSD)
 #define SANITIZER_INTERCEPT_ISOC99_PRINTF SI_GLIBC
@@ -239,8 +247,10 @@ SANITIZER_WEAK_IMPORT void *aligned_alloc(__sanitizer::usize __alignment,
 #define SANITIZER_INTERCEPT___PRINTF_CHK \
   (SANITIZER_INTERCEPT_PRINTF && SI_GLIBC)
 
-#define SANITIZER_INTERCEPT_FREXP SI_NOT_FUCHSIA
-#define SANITIZER_INTERCEPT_FREXPF_FREXPL SI_POSIX
+// AIX libc does not export FREXP and FREXP.
+#define SANITIZER_INTERCEPT_FREXP (SI_NOT_FUCHSIA && SI_NOT_AIX)
+#define SANITIZER_INTERCEPT_FREXPF (SI_POSIX && SI_NOT_AIX)
+#define SANITIZER_INTERCEPT_FREXPL SI_POSIX
 
 #define SANITIZER_INTERCEPT_GETPWNAM_AND_FRIENDS SI_POSIX
 #define SANITIZER_INTERCEPT_GETPWNAM_R_AND_FRIENDS \
@@ -289,7 +299,7 @@ SANITIZER_WEAK_IMPORT void *aligned_alloc(__sanitizer::usize __alignment,
 #define SANITIZER_INTERCEPT_ACCEPT4 \
   (SI_LINUX_NOT_ANDROID || SI_NETBSD || SI_FREEBSD)
 #define SANITIZER_INTERCEPT_PACCEPT SI_NETBSD
-#define SANITIZER_INTERCEPT_MODF SI_POSIX
+#define SANITIZER_INTERCEPT_MODF (SI_POSIX && SI_NOT_AIX)
 #define SANITIZER_INTERCEPT_RECVMSG SI_POSIX
 #define SANITIZER_INTERCEPT_SENDMSG SI_POSIX
 #define SANITIZER_INTERCEPT_RECVMMSG SI_LINUX
@@ -324,8 +334,9 @@ SANITIZER_WEAK_IMPORT void *aligned_alloc(__sanitizer::usize __alignment,
 #define SANITIZER_INTERCEPT___WCSXFRM_L SI_LINUX
 #define SANITIZER_INTERCEPT_WCSNRTOMBS \
   (SI_FREEBSD || SI_NETBSD || SI_MAC || SI_LINUX_NOT_ANDROID || SI_SOLARIS)
-#define SANITIZER_INTERCEPT_WCRTOMB \
-  (SI_FREEBSD || SI_NETBSD || SI_MAC || SI_LINUX_NOT_ANDROID || SI_SOLARIS)
+#define SANITIZER_INTERCEPT_WCRTOMB                                           \
+  (SI_FREEBSD || SI_NETBSD || SI_MAC || SI_LINUX_NOT_ANDROID || SI_SOLARIS || \
+   !SI_NOT_AIX)
 #define SANITIZER_INTERCEPT_WCTOMB \
   (SI_FREEBSD || SI_NETBSD || SI_MAC || SI_LINUX_NOT_ANDROID || SI_SOLARIS)
 #define SANITIZER_INTERCEPT_TCGETATTR SI_LINUX_NOT_ANDROID || SI_SOLARIS
@@ -365,7 +376,8 @@ SANITIZER_WEAK_IMPORT void *aligned_alloc(__sanitizer::usize __alignment,
 #define SANITIZER_INTERCEPT_GETMNTENT_R SI_LINUX_NOT_ANDROID
 #define SANITIZER_INTERCEPT_STATFS \
   (SI_FREEBSD || SI_MAC || SI_LINUX_NOT_ANDROID || SI_SOLARIS)
-#define SANITIZER_INTERCEPT_STATFS64 SI_GLIBC && SANITIZER_HAS_STATFS64
+#define SANITIZER_INTERCEPT_STATFS64 \
+  ((SI_GLIBC || !SI_NOT_AIX) && SANITIZER_HAS_STATFS64)
 #define SANITIZER_INTERCEPT_STATVFS \
   (SI_FREEBSD || SI_NETBSD || SI_LINUX_NOT_ANDROID)
 #define SANITIZER_INTERCEPT_STATVFS64 SI_GLIBC
@@ -414,10 +426,10 @@ SANITIZER_WEAK_IMPORT void *aligned_alloc(__sanitizer::usize __alignment,
 #define SANITIZER_INTERCEPT_TTYNAME_R SI_POSIX
 #define SANITIZER_INTERCEPT_TEMPNAM SI_POSIX
 #define SANITIZER_INTERCEPT_SINCOS SI_LINUX || SI_SOLARIS
-#define SANITIZER_INTERCEPT_REMQUO SI_POSIX
-#define SANITIZER_INTERCEPT_REMQUOL (SI_POSIX && !SI_NETBSD)
-#define SANITIZER_INTERCEPT_LGAMMA SI_POSIX
-#define SANITIZER_INTERCEPT_LGAMMAL (SI_POSIX && !SI_NETBSD)
+#define SANITIZER_INTERCEPT_REMQUO (SI_POSIX && SI_NOT_AIX)
+#define SANITIZER_INTERCEPT_REMQUOL (SI_POSIX && !SI_NETBSD && SI_NOT_AIX)
+#define SANITIZER_INTERCEPT_LGAMMA (SI_POSIX && SI_NOT_AIX)
+#define SANITIZER_INTERCEPT_LGAMMAL (SI_POSIX && !SI_NETBSD && SI_NOT_AIX)
 #define SANITIZER_INTERCEPT_LGAMMA_R (SI_FREEBSD || SI_LINUX || SI_SOLARIS)
 #define SANITIZER_INTERCEPT_LGAMMAL_R SI_LINUX_NOT_ANDROID || SI_SOLARIS
 #define SANITIZER_INTERCEPT_DRAND48_R SI_GLIBC
@@ -502,9 +514,11 @@ SANITIZER_WEAK_IMPORT void *aligned_alloc(__sanitizer::usize __alignment,
 #define SI_STAT_LINUX (SI_LINUX && __GLIBC_PREREQ(2, 33))
 #define SANITIZER_INTERCEPT_STAT                                        \
   (SI_FREEBSD || SI_MAC || SI_ANDROID || SI_NETBSD || SI_SOLARIS ||     \
-   SI_STAT_LINUX)
-#define SANITIZER_INTERCEPT_STAT64 SI_STAT_LINUX && SANITIZER_HAS_STAT64
-#define SANITIZER_INTERCEPT_LSTAT (SI_NETBSD || SI_FREEBSD || SI_STAT_LINUX)
+   SI_STAT_LINUX || !SI_NOT_AIX)
+#define SANITIZER_INTERCEPT_STAT64 \
+  ((SI_STAT_LINUX || !SI_NOT_AIX) && SANITIZER_HAS_STAT64)
+#define SANITIZER_INTERCEPT_LSTAT \
+  (SI_NETBSD || SI_FREEBSD || SI_STAT_LINUX || !SI_NOT_AIX)
 #define SANITIZER_INTERCEPT___XSTAT \
   ((!SANITIZER_INTERCEPT_STAT && SI_POSIX) || SI_STAT_LINUX)
 #define SANITIZER_INTERCEPT___XSTAT64 SI_GLIBC
@@ -572,7 +586,7 @@ SANITIZER_WEAK_IMPORT void *aligned_alloc(__sanitizer::usize __alignment,
 #define SANITIZER_INTERCEPT_PROTOENT_R SI_GLIBC
 #define SANITIZER_INTERCEPT_NETENT (SI_LINUX || SI_NETBSD || SI_FREEBSD)
 #define SANITIZER_INTERCEPT_SETVBUF \
-  (SI_NETBSD || SI_FREEBSD || SI_LINUX || SI_MAC)
+  (SI_NETBSD || SI_FREEBSD || SI_LINUX || SI_MAC || !SI_NOT_AIX)
 #define SANITIZER_INTERCEPT_GETMNTINFO (SI_NETBSD || SI_FREEBSD || SI_MAC)
 #define SANITIZER_INTERCEPT_MI_VECTOR_HASH SI_NETBSD
 #define SANITIZER_INTERCEPT_GETVFSSTAT SI_NETBSD
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_redefine_builtins.h b/compiler-rt/lib/sanitizer_common/sanitizer_redefine_builtins.h
index 41e0613d6fc13..bda0f04687693 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_redefine_builtins.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_redefine_builtins.h
@@ -15,7 +15,7 @@
 #    define SANITIZER_REDEFINE_BUILTINS_H
 
 // The asm hack only works with GCC and Clang.
-#    if !defined(_WIN32)
+#    if !defined(_WIN32) && !defined(_AIX)
 
 asm(R"(
     .set memcpy, __sanitizer_internal_memcpy

>From 549b1349d8dee96a27ec6914b1d4c3de47633d3a Mon Sep 17 00:00:00 2001
From: Jake Egan <jake.egan at ibm.com>
Date: Mon, 24 Mar 2025 08:10:46 -0400
Subject: [PATCH 02/15] Define SANITIZER_AIX temporarily to build

---
 compiler-rt/lib/sanitizer_common/sanitizer_platform.h | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform.h b/compiler-rt/lib/sanitizer_common/sanitizer_platform.h
index 57966403c92a9..75ee3c0d90f00 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_platform.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform.h
@@ -31,6 +31,12 @@
 #  define SANITIZER_LINUX 0
 #endif
 
+#if defined(_AIX)
+#  define SANITIZER_AIX 1
+#else
+#  define SANITIZER_AIX 0
+#endif
+
 #if defined(__GLIBC__)
 #  define SANITIZER_GLIBC 1
 #else

>From d3301a31329316ad0d736f72a76c5449a93fa09d Mon Sep 17 00:00:00 2001
From: Jake Egan <jake.egan at ibm.com>
Date: Mon, 24 Mar 2025 08:44:12 -0400
Subject: [PATCH 03/15] Revert "Define SANITIZER_AIX temporarily to build"

This reverts commit 549b1349d8dee96a27ec6914b1d4c3de47633d3a.
---
 compiler-rt/lib/sanitizer_common/sanitizer_platform.h | 6 ------
 1 file changed, 6 deletions(-)

diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform.h b/compiler-rt/lib/sanitizer_common/sanitizer_platform.h
index 75ee3c0d90f00..57966403c92a9 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_platform.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform.h
@@ -31,12 +31,6 @@
 #  define SANITIZER_LINUX 0
 #endif
 
-#if defined(_AIX)
-#  define SANITIZER_AIX 1
-#else
-#  define SANITIZER_AIX 0
-#endif
-
 #if defined(__GLIBC__)
 #  define SANITIZER_GLIBC 1
 #else

>From 6ffa232c78cb559d200594cf547f5591a9b492a8 Mon Sep 17 00:00:00 2001
From: Jake Egan <jake.egan at ibm.com>
Date: Mon, 24 Mar 2025 08:48:07 -0400
Subject: [PATCH 04/15] convert to preprocessor directives

---
 .../sanitizer_common/sanitizer_common_interceptors.inc | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
index a71981282f615..35876084f8107 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
@@ -3922,10 +3922,11 @@ INTERCEPTOR(SIZE_T, wcrtomb, char *dest, wchar_t src, void *ps) {
   if (res != ((SIZE_T)-1)) {
     CHECK_LE(res, sizeof(local_dest));
     COMMON_INTERCEPTOR_WRITE_RANGE(ctx, dest, res);
-    if (!SANITIZER_AIX)
+#if !SANITIZER_AIX
       REAL(memcpy)(dest, local_dest, res);
-    else
+#else
       internal_memcpy(dest, local_dest, res);
+#endif
   }
   return res;
 }
@@ -3947,10 +3948,11 @@ INTERCEPTOR(int, wctomb, char *dest, wchar_t src) {
   if (res != -1) {
     CHECK_LE(res, sizeof(local_dest));
     COMMON_INTERCEPTOR_WRITE_RANGE(ctx, dest, res);
-    if (!SANITIZER_AIX)
+#if !SANITIZER_AIX
       REAL(memcpy)(dest, local_dest, res);
-    else
+#else
       internal_memcpy(dest, local_dest, res);
+#endif
   }
   return res;
 }

>From 4890013338967f16053c160d36b4c8d8581aff0f Mon Sep 17 00:00:00 2001
From: Jake Egan <jake.egan at ibm.com>
Date: Tue, 1 Apr 2025 10:12:35 -0400
Subject: [PATCH 05/15] Fix formatting

---
 compiler-rt/lib/interception/interception.h   | 12 +--
 .../lib/interception/interception_aix.h       |  2 +-
 .../sanitizer_common_interceptors.inc         | 88 +++++++++----------
 .../sanitizer_common_interceptors_ioctl.inc   |  4 +-
 ...izer_common_interceptors_memintrinsics.inc |  2 +-
 .../sanitizer_platform_interceptors.h         | 18 ++--
 6 files changed, 63 insertions(+), 63 deletions(-)

diff --git a/compiler-rt/lib/interception/interception.h b/compiler-rt/lib/interception/interception.h
index 3a20cfb04dcd6..8e1bc176e72e3 100644
--- a/compiler-rt/lib/interception/interception.h
+++ b/compiler-rt/lib/interception/interception.h
@@ -378,16 +378,16 @@ inline void DoesNotSupportStaticLinking() {}
 #define INCLUDED_FROM_INTERCEPTION_LIB
 
 #if SANITIZER_AIX
-# include "interception_aix.h"
-# define INTERCEPT_FUNCTION(func) INTERCEPT_FUNCTION_AIX(func)
-# define INTERCEPT_FUNCTION_VER(func, symver) INTERCEPT_FUNCTION_AIX(func)
+#  include "interception_aix.h"
+#  define INTERCEPT_FUNCTION(func) INTERCEPT_FUNCTION_AIX(func)
+#  define INTERCEPT_FUNCTION_VER(func, symver) INTERCEPT_FUNCTION_AIX(func)
 
 #elif SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_NETBSD || \
     SANITIZER_SOLARIS
 
-# include "interception_linux.h"
-# define INTERCEPT_FUNCTION(func) INTERCEPT_FUNCTION_LINUX_OR_FREEBSD(func)
-# define INTERCEPT_FUNCTION_VER(func, symver) \
+#  include "interception_linux.h"
+#  define INTERCEPT_FUNCTION(func) INTERCEPT_FUNCTION_LINUX_OR_FREEBSD(func)
+#  define INTERCEPT_FUNCTION_VER(func, symver) \
     INTERCEPT_FUNCTION_VER_LINUX_OR_FREEBSD(func, symver)
 #elif SANITIZER_APPLE
 # include "interception_mac.h"
diff --git a/compiler-rt/lib/interception/interception_aix.h b/compiler-rt/lib/interception/interception_aix.h
index 08d17caeb6a8d..b86ae89f50461 100644
--- a/compiler-rt/lib/interception/interception_aix.h
+++ b/compiler-rt/lib/interception/interception_aix.h
@@ -30,7 +30,7 @@ bool InterceptFunction(const char *name, uptr *ptr_to_real, uptr func,
       ::__interception::InterceptFunction(              \
           #func, (::__interception::uptr *)&REAL(func), \
           (::__interception::uptr) & (func),            \
-          (::__interception::uptr)&WRAP(func))
+          (::__interception::uptr) & WRAP(func))
 
 #  endif  // INTERCEPTION_AIX_H
 #endif    // SANITIZER_AIX
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
index 35876084f8107..0403872802f55 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
@@ -963,9 +963,9 @@ INTERCEPTOR(float, frexpf, float x, int *exp) {
   return res;
 }
 
-#define INIT_FREXPF COMMON_INTERCEPT_FUNCTION(frexpf);
+#  define INIT_FREXPF COMMON_INTERCEPT_FUNCTION(frexpf);
 #else
-#define INIT_FREXPF
+#  define INIT_FREXPF
 #endif
 
 #if SANITIZER_INTERCEPT_FREXPL
@@ -978,9 +978,9 @@ INTERCEPTOR(long double, frexpl, long double x, int *exp) {
   return res;
 }
 
-#define INIT_FREXPL COMMON_INTERCEPT_FUNCTION_LDBL(frexpl)
+#  define INIT_FREXPL COMMON_INTERCEPT_FUNCTION_LDBL(frexpl)
 #else
-#define INIT_FREXPL
+#  define INIT_FREXPL
 #endif
 
 #if SI_POSIX
@@ -1351,7 +1351,7 @@ INTERCEPTOR(unsigned long, time, unsigned long *t) {
 static void unpoison_tm(void *ctx, __sanitizer_tm *tm) {
   COMMON_INTERCEPTOR_WRITE_RANGE(ctx, tm, sizeof(*tm));
 // AIX tm struct does not have tm_zone field.
-#if !SANITIZER_SOLARIS && !SANITIZER_AIX
+#  if !SANITIZER_SOLARIS && !SANITIZER_AIX
   if (tm->tm_zone) {
     // Can not use COMMON_INTERCEPTOR_WRITE_RANGE here, because tm->tm_zone
     // can point to shared memory and tsan would report a data race.
@@ -1736,12 +1736,12 @@ INTERCEPTOR(int, __vsprintf_chk, char *str, int flag, SIZE_T size_to,
 VSPRINTF_INTERCEPTOR_IMPL(vsprintf, str, format, ap)
 #endif
 
-#if SANITIZER_INTERCEPT_VASPRINTF
+#  if SANITIZER_INTERCEPT_VASPRINTF
 INTERCEPTOR(int, vasprintf, char **strp, const char *format, va_list ap)
 VASPRINTF_INTERCEPTOR_IMPL(vasprintf, strp, format, ap)
-#endif
+#  endif
 
-#if SANITIZER_INTERCEPT_ISOC99_PRINTF
+#  if SANITIZER_INTERCEPT_ISOC99_PRINTF
 INTERCEPTOR(int, __isoc99_vprintf, const char *format, va_list ap)
 VPRINTF_INTERCEPTOR_IMPL(__isoc99_vprintf, format, ap)
 
@@ -1790,12 +1790,12 @@ INTERCEPTOR(int, __snprintf_chk, char *str, SIZE_T size, int flag,
 FORMAT_INTERCEPTOR_IMPL(__snprintf_chk, vsnprintf, str, size, format)
 #endif
 
-#if SANITIZER_INTERCEPT_ASPRINTF
+#  if SANITIZER_INTERCEPT_ASPRINTF
 INTERCEPTOR(int, asprintf, char **strp, const char *format, ...)
 FORMAT_INTERCEPTOR_IMPL(asprintf, vasprintf, strp, format)
-#endif
+#  endif
 
-#if SANITIZER_INTERCEPT_ISOC99_PRINTF
+#  if SANITIZER_INTERCEPT_ISOC99_PRINTF
 INTERCEPTOR(int, __isoc99_printf, const char *format, ...)
 FORMAT_INTERCEPTOR_IMPL(__isoc99_printf, __isoc99_vprintf, format)
 
@@ -1816,29 +1816,29 @@ FORMAT_INTERCEPTOR_IMPL(__isoc99_snprintf, __isoc99_vsnprintf, str, size,
 #endif  // SANITIZER_INTERCEPT_PRINTF
 
 #if SANITIZER_INTERCEPT_PRINTF
-#if SANITIZER_AIX
-#define INIT_PRINTF                     \
-  COMMON_INTERCEPT_FUNCTION_LDBL(printf);    \
-  COMMON_INTERCEPT_FUNCTION_LDBL(sprintf);   \
-  COMMON_INTERCEPT_FUNCTION_LDBL(snprintf);  \
-  COMMON_INTERCEPT_FUNCTION_LDBL(fprintf);   \
-  COMMON_INTERCEPT_FUNCTION_LDBL(vprintf);   \
-  COMMON_INTERCEPT_FUNCTION_LDBL(vsprintf);  \
-  COMMON_INTERCEPT_FUNCTION_LDBL(vsnprintf); \
-  COMMON_INTERCEPT_FUNCTION_LDBL(vfprintf);
-#else
-#define INIT_PRINTF                     \
-  COMMON_INTERCEPT_FUNCTION_LDBL(printf);    \
-  COMMON_INTERCEPT_FUNCTION_LDBL(sprintf);   \
-  COMMON_INTERCEPT_FUNCTION_LDBL(snprintf);  \
-  COMMON_INTERCEPT_FUNCTION_LDBL(fprintf);   \
-  COMMON_INTERCEPT_FUNCTION_LDBL(vprintf);   \
-  COMMON_INTERCEPT_FUNCTION_LDBL(vsprintf);  \
-  COMMON_INTERCEPT_FUNCTION_LDBL(vsnprintf); \
-  COMMON_INTERCEPT_FUNCTION_LDBL(asprintf);  \
-  COMMON_INTERCEPT_FUNCTION_LDBL(vasprintf); \
-  COMMON_INTERCEPT_FUNCTION_LDBL(vfprintf);
-#endif
+#  if SANITIZER_AIX
+#    define INIT_PRINTF                          \
+      COMMON_INTERCEPT_FUNCTION_LDBL(printf);    \
+      COMMON_INTERCEPT_FUNCTION_LDBL(sprintf);   \
+      COMMON_INTERCEPT_FUNCTION_LDBL(snprintf);  \
+      COMMON_INTERCEPT_FUNCTION_LDBL(fprintf);   \
+      COMMON_INTERCEPT_FUNCTION_LDBL(vprintf);   \
+      COMMON_INTERCEPT_FUNCTION_LDBL(vsprintf);  \
+      COMMON_INTERCEPT_FUNCTION_LDBL(vsnprintf); \
+      COMMON_INTERCEPT_FUNCTION_LDBL(vfprintf);
+#  else
+#    define INIT_PRINTF                          \
+      COMMON_INTERCEPT_FUNCTION_LDBL(printf);    \
+      COMMON_INTERCEPT_FUNCTION_LDBL(sprintf);   \
+      COMMON_INTERCEPT_FUNCTION_LDBL(snprintf);  \
+      COMMON_INTERCEPT_FUNCTION_LDBL(fprintf);   \
+      COMMON_INTERCEPT_FUNCTION_LDBL(vprintf);   \
+      COMMON_INTERCEPT_FUNCTION_LDBL(vsprintf);  \
+      COMMON_INTERCEPT_FUNCTION_LDBL(vsnprintf); \
+      COMMON_INTERCEPT_FUNCTION_LDBL(asprintf);  \
+      COMMON_INTERCEPT_FUNCTION_LDBL(vasprintf); \
+      COMMON_INTERCEPT_FUNCTION_LDBL(vfprintf);
+#  endif
 #else
 #define INIT_PRINTF
 #endif
@@ -3922,11 +3922,11 @@ INTERCEPTOR(SIZE_T, wcrtomb, char *dest, wchar_t src, void *ps) {
   if (res != ((SIZE_T)-1)) {
     CHECK_LE(res, sizeof(local_dest));
     COMMON_INTERCEPTOR_WRITE_RANGE(ctx, dest, res);
-#if !SANITIZER_AIX
-      REAL(memcpy)(dest, local_dest, res);
-#else
-      internal_memcpy(dest, local_dest, res);
-#endif
+#  if !SANITIZER_AIX
+    REAL(memcpy)(dest, local_dest, res);
+#  else
+    internal_memcpy(dest, local_dest, res);
+#  endif
   }
   return res;
 }
@@ -3948,11 +3948,11 @@ INTERCEPTOR(int, wctomb, char *dest, wchar_t src) {
   if (res != -1) {
     CHECK_LE(res, sizeof(local_dest));
     COMMON_INTERCEPTOR_WRITE_RANGE(ctx, dest, res);
-#if !SANITIZER_AIX
-      REAL(memcpy)(dest, local_dest, res);
-#else
-      internal_memcpy(dest, local_dest, res);
-#endif
+#  if !SANITIZER_AIX
+    REAL(memcpy)(dest, local_dest, res);
+#  else
+    internal_memcpy(dest, local_dest, res);
+#  endif
   }
   return res;
 }
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors_ioctl.inc b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors_ioctl.inc
index 5b23039954a43..ea77707c2e64e 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors_ioctl.inc
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors_ioctl.inc
@@ -73,9 +73,9 @@ static void ioctl_table_fill() {
   _(TIOCNXCL, NONE, 0);
   _(TIOCOUTQ, WRITE, sizeof(int));
   _(TIOCPKT, READ, sizeof(int));
-#if !SANITIZER_AIX
+#  if !SANITIZER_AIX
   _(TIOCSCTTY, NONE, 0);
-#endif
+#  endif
   _(TIOCSETD, READ, sizeof(int));
   _(TIOCSPGRP, READ, pid_t_sz);
   _(TIOCSTI, READ, sizeof(char));
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors_memintrinsics.inc b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors_memintrinsics.inc
index e542a6c7b438a..42d387e37ec98 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors_memintrinsics.inc
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors_memintrinsics.inc
@@ -37,7 +37,7 @@
 #elif SANITIZER_WINDOWS64
 #define PLATFORM_HAS_DIFFERENT_MEMCPY_AND_MEMMOVE 0
 #elif SANITIZER_AIX
-#define PLATFORM_HAS_DIFFERENT_MEMCPY_AND_MEMMOVE 0
+#  define PLATFORM_HAS_DIFFERENT_MEMCPY_AND_MEMMOVE 0
 #else
 #define PLATFORM_HAS_DIFFERENT_MEMCPY_AND_MEMMOVE 1
 #endif  // SANITIZER_APPLE
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h b/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h
index 43a37037c971d..14e0290aae496 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h
@@ -140,9 +140,9 @@ SANITIZER_WEAK_IMPORT void *aligned_alloc(__sanitizer::usize __alignment,
 #endif
 
 #if SANITIZER_AIX
-#define SI_NOT_AIX 0
+#  define SI_NOT_AIX 0
 #else
-#define SI_NOT_AIX 1
+#  define SI_NOT_AIX 1
 #endif
 
 #if SANITIZER_SOLARIS32
@@ -237,11 +237,11 @@ SANITIZER_WEAK_IMPORT void *aligned_alloc(__sanitizer::usize __alignment,
 #define SANITIZER_INTERCEPT_ISOC99_SCANF SI_GLIBC
 
 #ifndef SANITIZER_INTERCEPT_PRINTF
-#define SANITIZER_INTERCEPT_ASPRINTF SI_NOT_AIX
-#define SANITIZER_INTERCEPT_VASPRINTF SI_NOT_AIX
-#define SANITIZER_INTERCEPT_PRINTF SI_POSIX
-#define SANITIZER_INTERCEPT_PRINTF_L (SI_FREEBSD || SI_NETBSD)
-#define SANITIZER_INTERCEPT_ISOC99_PRINTF SI_GLIBC
+#  define SANITIZER_INTERCEPT_ASPRINTF SI_NOT_AIX
+#  define SANITIZER_INTERCEPT_VASPRINTF SI_NOT_AIX
+#  define SANITIZER_INTERCEPT_PRINTF SI_POSIX
+#  define SANITIZER_INTERCEPT_PRINTF_L (SI_FREEBSD || SI_NETBSD)
+#  define SANITIZER_INTERCEPT_ISOC99_PRINTF SI_GLIBC
 #endif
 
 #define SANITIZER_INTERCEPT___PRINTF_CHK \
@@ -512,8 +512,8 @@ SANITIZER_WEAK_IMPORT void *aligned_alloc(__sanitizer::usize __alignment,
 #define SANITIZER_INTERCEPT_EVENTFD_READ_WRITE (SI_LINUX || SI_FREEBSD)
 
 #define SI_STAT_LINUX (SI_LINUX && __GLIBC_PREREQ(2, 33))
-#define SANITIZER_INTERCEPT_STAT                                        \
-  (SI_FREEBSD || SI_MAC || SI_ANDROID || SI_NETBSD || SI_SOLARIS ||     \
+#define SANITIZER_INTERCEPT_STAT                                    \
+  (SI_FREEBSD || SI_MAC || SI_ANDROID || SI_NETBSD || SI_SOLARIS || \
    SI_STAT_LINUX || !SI_NOT_AIX)
 #define SANITIZER_INTERCEPT_STAT64 \
   ((SI_STAT_LINUX || !SI_NOT_AIX) && SANITIZER_HAS_STAT64)

>From dcde67013a3e5cb300f79634ac445a849ada5889 Mon Sep 17 00:00:00 2001
From: Jake Egan <jake.egan at ibm.com>
Date: Wed, 23 Apr 2025 09:47:59 -0400
Subject: [PATCH 06/15] Add asan interceptor part

---
 compiler-rt/lib/asan/asan_allocator.cpp       |  7 ++-
 compiler-rt/lib/asan/asan_interceptors.cpp    | 48 ++++++++++++++++++-
 compiler-rt/lib/asan/asan_interceptors.h      | 31 ++++++++++--
 .../asan/asan_interceptors_memintrinsics.cpp  |  4 +-
 compiler-rt/lib/asan/asan_malloc_linux.cpp    | 21 +++++++-
 5 files changed, 103 insertions(+), 8 deletions(-)

diff --git a/compiler-rt/lib/asan/asan_allocator.cpp b/compiler-rt/lib/asan/asan_allocator.cpp
index 3a55c2af65653..c09d0fea34572 100644
--- a/compiler-rt/lib/asan/asan_allocator.cpp
+++ b/compiler-rt/lib/asan/asan_allocator.cpp
@@ -770,11 +770,16 @@ struct Allocator {
       u8 chunk_state = atomic_load(&m->chunk_state, memory_order_acquire);
       if (chunk_state != CHUNK_ALLOCATED)
         ReportInvalidFree(old_ptr, chunk_state, stack);
-      CHECK_NE(REAL(memcpy), nullptr);
       uptr memcpy_size = Min(new_size, m->UsedSize());
       // If realloc() races with free(), we may start copying freed memory.
       // However, we will report racy double-free later anyway.
+#if !SANITIZER_AIX
+      CHECK_NE(REAL(memcpy), nullptr);
       REAL(memcpy)(new_ptr, old_ptr, memcpy_size);
+#else
+      // AIX does not intercept memcpy, we have to use internal_memcpy here.
+      internal_memcpy(new_ptr, old_ptr, memcpy_size);
+#endif
       Deallocate(old_ptr, 0, 0, stack, FROM_MALLOC);
     }
     return new_ptr;
diff --git a/compiler-rt/lib/asan/asan_interceptors.cpp b/compiler-rt/lib/asan/asan_interceptors.cpp
index 247ea1b92f1f4..f73591190fedb 100644
--- a/compiler-rt/lib/asan/asan_interceptors.cpp
+++ b/compiler-rt/lib/asan/asan_interceptors.cpp
@@ -56,6 +56,7 @@ namespace __asan {
 #  define ASAN_READ_STRING(ctx, s, n) \
     ASAN_READ_STRING_OF_LEN((ctx), (s), internal_strlen(s), (n))
 
+#if SANITIZER_INTERCEPT_STRCAT || SANITIZER_INTERCEPT_STRCPY
 static inline uptr MaybeRealStrnlen(const char *s, uptr maxlen) {
 #if SANITIZER_INTERCEPT_STRNLEN
   if (REAL(strnlen)) {
@@ -64,6 +65,7 @@ static inline uptr MaybeRealStrnlen(const char *s, uptr maxlen) {
 #endif
   return internal_strnlen(s, maxlen);
 }
+#endif
 
 void SetThreadName(const char *name) {
   AsanThread *t = GetCurrentThread();
@@ -275,7 +277,12 @@ INTERCEPTOR(int, pthread_create, void *thread, void *attr,
 #    endif
     asanThreadArgRetval().Create(detached, {start_routine, arg}, [&]() -> uptr {
       result = REAL(pthread_create)(thread, attr, asan_thread_start, t);
+// AIX pthread_t is unsigned int.
+#if SANITIZER_AIX
+      return result ? 0 : *(unsigned int *)(thread);
+#else
       return result ? 0 : *(uptr *)(thread);
+#endif
     });
   }
   if (result != 0) {
@@ -432,10 +439,12 @@ INTERCEPTOR(int, swapcontext, struct ucontext_t *oucp,
 #define siglongjmp __siglongjmp14
 #endif
 
+#if ASAN_INTERCEPT_LONGJMP
 INTERCEPTOR(void, longjmp, void *env, int val) {
   __asan_handle_no_return();
   REAL(longjmp)(env, val);
 }
+#endif
 
 #if ASAN_INTERCEPT__LONGJMP
 INTERCEPTOR(void, _longjmp, void *env, int val) {
@@ -508,6 +517,7 @@ DEFINE_REAL(char*, index, const char *string, int c)
 
 // For both strcat() and strncat() we need to check the validity of |to|
 // argument irrespective of the |from| length.
+#if SANITIZER_INTERCEPT_STRCAT
   INTERCEPTOR(char *, strcat, char *to, const char *from) {
     void *ctx;
     ASAN_INTERCEPTOR_ENTER(ctx, strcat);
@@ -528,6 +538,7 @@ DEFINE_REAL(char*, index, const char *string, int c)
     }
     return REAL(strcat)(to, from);
   }
+#endif
 
 INTERCEPTOR(char*, strncat, char *to, const char *from, usize size) {
   void *ctx;
@@ -548,6 +559,7 @@ INTERCEPTOR(char*, strncat, char *to, const char *from, usize size) {
   return REAL(strncat)(to, from, size);
 }
 
+#if SANITIZER_INTERCEPT_STRCPY
 INTERCEPTOR(char *, strcpy, char *to, const char *from) {
   void *ctx;
   ASAN_INTERCEPTOR_ENTER(ctx, strcpy);
@@ -569,6 +581,7 @@ INTERCEPTOR(char *, strcpy, char *to, const char *from) {
   }
   return REAL(strcpy)(to, from);
 }
+#endif
 
 // Windows doesn't always define the strdup identifier,
 // and when it does it's a macro defined to either _strdup
@@ -596,9 +609,16 @@ INTERCEPTOR(char*, strdup, const char *s) {
   GET_STACK_TRACE_MALLOC;
   void *new_mem = asan_malloc(length + 1, &stack);
   if (new_mem) {
+#  if SANITIZER_AIX
+    // memcpy is a static function defined in libc.a on AIX. It can not be
+    // intercepted, so REAL(memcpy) is null on AIX. Use internal_memcpy instead.
+    internal_memcpy(new_mem, s, length + 1);
+#  else
     REAL(memcpy)(new_mem, s, length + 1);
+#  endif
   }
   return reinterpret_cast<char*>(new_mem);
+
 }
 
 #  if ASAN_INTERCEPT___STRDUP
@@ -614,12 +634,17 @@ INTERCEPTOR(char*, __strdup, const char *s) {
   GET_STACK_TRACE_MALLOC;
   void *new_mem = asan_malloc(length + 1, &stack);
   if (new_mem) {
+#if SANITIZER_AIX
+    internal_memcpy(new_mem, s, length + 1);
+#else
     REAL(memcpy)(new_mem, s, length + 1);
+#endif
   }
   return reinterpret_cast<char*>(new_mem);
 }
 #endif // ASAN_INTERCEPT___STRDUP
 
+#if SANITIZER_INTERCEPT_STRCPY
 INTERCEPTOR(char*, strncpy, char *to, const char *from, usize size) {
   void *ctx;
   ASAN_INTERCEPTOR_ENTER(ctx, strncpy);
@@ -632,6 +657,7 @@ INTERCEPTOR(char*, strncpy, char *to, const char *from, usize size) {
   }
   return REAL(strncpy)(to, from, size);
 }
+#endif
 
 template <typename Fn>
 static ALWAYS_INLINE auto StrtolImpl(void *ctx, Fn real, const char *nptr,
@@ -743,6 +769,14 @@ static void AtCxaAtexit(void *unused) {
 }
 #endif
 
+#if ASAN_INTERCEPT_EXIT
+INTERCEPTOR(void, exit, int status) {
+  AsanInitFromRtl();
+  StopInitOrderChecking();
+  REAL(exit)(status);
+}
+#endif
+
 #if ASAN_INTERCEPT___CXA_ATEXIT
 INTERCEPTOR(int, __cxa_atexit, void (*func)(void *), void *arg,
             void *dso_handle) {
@@ -804,10 +838,14 @@ void InitializeAsanInterceptors() {
   InitializeSignalInterceptors();
 
   // Intercept str* functions.
+#if SANITIZER_INTERCEPT_STRCAT
   ASAN_INTERCEPT_FUNC(strcat);
-  ASAN_INTERCEPT_FUNC(strcpy);
   ASAN_INTERCEPT_FUNC(strncat);
+#endif
+#if SANITIZER_INTERCEPT_STRCPY
+  ASAN_INTERCEPT_FUNC(strcpy);
   ASAN_INTERCEPT_FUNC(strncpy);
+#endif
   ASAN_INTERCEPT_FUNC(strdup);
 #  if ASAN_INTERCEPT___STRDUP
   ASAN_INTERCEPT_FUNC(__strdup);
@@ -826,8 +864,10 @@ void InitializeAsanInterceptors() {
   ASAN_INTERCEPT_FUNC(__isoc23_strtoll);
 #  endif
 
-  // Intecept jump-related functions.
+  // Intercept jump-related functions.
+#if ASAN_INTERCEPT_LONGJMP
   ASAN_INTERCEPT_FUNC(longjmp);
+#endif
 
 #  if ASAN_INTERCEPT_SWAPCONTEXT
   ASAN_INTERCEPT_FUNC(swapcontext);
@@ -894,6 +934,10 @@ void InitializeAsanInterceptors() {
   ASAN_INTERCEPT_FUNC(atexit);
 #endif
 
+#if ASAN_INTERCEPT_EXIT
+  ASAN_INTERCEPT_FUNC(exit);
+#endif
+
 #if ASAN_INTERCEPT_PTHREAD_ATFORK
   ASAN_INTERCEPT_FUNC(pthread_atfork);
 #endif
diff --git a/compiler-rt/lib/asan/asan_interceptors.h b/compiler-rt/lib/asan/asan_interceptors.h
index 3e2386eaf8092..8ccdfee8c442c 100644
--- a/compiler-rt/lib/asan/asan_interceptors.h
+++ b/compiler-rt/lib/asan/asan_interceptors.h
@@ -31,10 +31,20 @@ void InitializePlatformInterceptors();
 // really defined to replace libc functions.
 #if !SANITIZER_FUCHSIA
 
+#if !SANITIZER_AIX
+# define ASAN_INTERCEPT_LONGJMP 1
+#else
+# define ASAN_INTERCEPT_LONGJMP 0
+#endif
+
 // Use macro to describe if specific function should be
 // intercepted on a given platform.
 #if !SANITIZER_WINDOWS
+#if !SANITIZER_AIX
 # define ASAN_INTERCEPT__LONGJMP 1
+#else
+# define ASAN_INTERCEPT__LONGJMP 0
+#endif
 # define ASAN_INTERCEPT_INDEX 1
 # define ASAN_INTERCEPT_PTHREAD_CREATE 1
 #else
@@ -56,7 +66,7 @@ void InitializePlatformInterceptors();
 # define ASAN_INTERCEPT_SWAPCONTEXT 0
 #endif
 
-#if !SANITIZER_WINDOWS
+#if !SANITIZER_WINDOWS && !SANITIZER_AIX
 # define ASAN_INTERCEPT_SIGLONGJMP 1
 #else
 # define ASAN_INTERCEPT_SIGLONGJMP 0
@@ -84,12 +94,18 @@ void InitializePlatformInterceptors();
 # define ASAN_INTERCEPT__UNWIND_SJLJ_RAISEEXCEPTION 0
 #endif
 
-#if !SANITIZER_WINDOWS
+#if !SANITIZER_WINDOWS && !SANITIZER_AIX
 # define ASAN_INTERCEPT___CXA_ATEXIT 1
 #else
 # define ASAN_INTERCEPT___CXA_ATEXIT 0
 #endif
 
+#if SANITIZER_AIX
+# define ASAN_INTERCEPT_EXIT 1
+#else
+# define ASAN_INTERCEPT_EXIT 0
+#endif
+
 #if SANITIZER_NETBSD
 # define ASAN_INTERCEPT_ATEXIT 1
 #else
@@ -110,6 +126,15 @@ void InitializePlatformInterceptors();
 # define ASAN_INTERCEPT_TRYJOIN 0
 #endif
 
+#if SANITIZER_AIX
+#define SANITIZER_INTERCEPT_STRCAT 0
+#define SANITIZER_INTERCEPT_STRCPY 0
+#else
+#define SANITIZER_INTERCEPT_STRCAT 1
+#define SANITIZER_INTERCEPT_STRCPY 1
+#endif
+
+
 #if SANITIZER_LINUX &&                                                \
     (defined(__arm__) || defined(__aarch64__) || defined(__i386__) || \
      defined(__x86_64__) || SANITIZER_RISCV64 || SANITIZER_LOONGARCH64)
@@ -117,7 +142,7 @@ void InitializePlatformInterceptors();
 #else
 # define ASAN_INTERCEPT_VFORK 0
 #endif
-
+`
 #if SANITIZER_NETBSD
 # define ASAN_INTERCEPT_PTHREAD_ATFORK 1
 #else
diff --git a/compiler-rt/lib/asan/asan_interceptors_memintrinsics.cpp b/compiler-rt/lib/asan/asan_interceptors_memintrinsics.cpp
index bdf328f892063..170d91e47e4cc 100644
--- a/compiler-rt/lib/asan/asan_interceptors_memintrinsics.cpp
+++ b/compiler-rt/lib/asan/asan_interceptors_memintrinsics.cpp
@@ -25,6 +25,7 @@ using namespace __asan;
 // memcpy is called during __asan_init() from the internals of printf(...).
 // We do not treat memcpy with to==from as a bug.
 // See http://llvm.org/bugs/show_bug.cgi?id=11763.
+// AIX does not intercept memcpy, so we have to use internal_memcpy.
 #define ASAN_MEMCPY_IMPL(ctx, to, from, size)                 \
   do {                                                        \
     if (LIKELY(replace_intrin_cached)) {                      \
@@ -36,7 +37,8 @@ using namespace __asan;
     } else if (UNLIKELY(!AsanInited())) {                     \
       return internal_memcpy(to, from, size);                 \
     }                                                         \
-    return REAL(memcpy)(to, from, size);                      \
+    return SANITIZER_AIX ? internal_memcpy(to, from, size) :  \
+      REAL(memcpy)(to, from, size);                           \
   } while (0)
 
 // memset is called inside Printf.
diff --git a/compiler-rt/lib/asan/asan_malloc_linux.cpp b/compiler-rt/lib/asan/asan_malloc_linux.cpp
index 3d6b03fefab70..5646a718d3ea0 100644
--- a/compiler-rt/lib/asan/asan_malloc_linux.cpp
+++ b/compiler-rt/lib/asan/asan_malloc_linux.cpp
@@ -14,8 +14,9 @@
 //===----------------------------------------------------------------------===//
 
 #include "sanitizer_common/sanitizer_platform.h"
+// FIXME: rename this file, this is not just for Linux now, see FUCHSIA and AIX.
 #if SANITIZER_FREEBSD || SANITIZER_FUCHSIA || SANITIZER_LINUX || \
-    SANITIZER_NETBSD || SANITIZER_SOLARIS
+    SANITIZER_NETBSD || SANITIZER_SOLARIS || SANITIZER_AIX
 
 #  include "asan_allocator.h"
 #  include "asan_interceptors.h"
@@ -61,6 +62,24 @@ INTERCEPTOR(void, cfree, void *ptr) {
 }
 #endif // SANITIZER_INTERCEPT_CFREE
 
+#if SANITIZER_AIX
+INTERCEPTOR(void*, vec_malloc, uptr size) {
+  if (DlsymAlloc::Use())
+    return DlsymAlloc::Allocate(size);
+  AsanInitFromRtl();
+  GET_STACK_TRACE_MALLOC;
+  return asan_malloc(size, &stack);
+}
+
+INTERCEPTOR(void*, vec_calloc, uptr nmemb, uptr size) {
+  if (DlsymAlloc::Use())
+    return DlsymAlloc::Callocate(nmemb, size);
+  AsanInitFromRtl();
+  GET_STACK_TRACE_MALLOC;
+  return asan_calloc(nmemb, size, &stack);
+}
+#endif
+
 INTERCEPTOR(void*, malloc, uptr size) {
   if (DlsymAlloc::Use())
     return DlsymAlloc::Allocate(size);

>From 878a567e6e851fef9b268e3e939df26eedc1f730 Mon Sep 17 00:00:00 2001
From: Jake Egan <jake.egan at ibm.com>
Date: Sun, 27 Apr 2025 13:50:06 -0400
Subject: [PATCH 07/15] Remove typo

---
 compiler-rt/lib/asan/asan_interceptors.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/compiler-rt/lib/asan/asan_interceptors.h b/compiler-rt/lib/asan/asan_interceptors.h
index 8ccdfee8c442c..9ad72e71cef97 100644
--- a/compiler-rt/lib/asan/asan_interceptors.h
+++ b/compiler-rt/lib/asan/asan_interceptors.h
@@ -142,7 +142,7 @@ void InitializePlatformInterceptors();
 #else
 # define ASAN_INTERCEPT_VFORK 0
 #endif
-`
+
 #if SANITIZER_NETBSD
 # define ASAN_INTERCEPT_PTHREAD_ATFORK 1
 #else

>From 7cc64a1969e2b18edb9f0645f0a6af3af04c82e1 Mon Sep 17 00:00:00 2001
From: Jake Egan <jake.egan at ibm.com>
Date: Sun, 27 Apr 2025 18:34:25 -0400
Subject: [PATCH 08/15] Fix undeclared identifier

---
 compiler-rt/lib/asan/asan_interceptors_memintrinsics.cpp | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/compiler-rt/lib/asan/asan_interceptors_memintrinsics.cpp b/compiler-rt/lib/asan/asan_interceptors_memintrinsics.cpp
index 170d91e47e4cc..6842962e00466 100644
--- a/compiler-rt/lib/asan/asan_interceptors_memintrinsics.cpp
+++ b/compiler-rt/lib/asan/asan_interceptors_memintrinsics.cpp
@@ -37,8 +37,11 @@ using namespace __asan;
     } else if (UNLIKELY(!AsanInited())) {                     \
       return internal_memcpy(to, from, size);                 \
     }                                                         \
-    return SANITIZER_AIX ? internal_memcpy(to, from, size) :  \
-      REAL(memcpy)(to, from, size);                           \
+#if !SANITIZER_AIX
+    return REAL(memcpy)(to, from, size);                      \
+#else
+    return internal_memcpy(to, from, size);                   \
+#endif
   } while (0)
 
 // memset is called inside Printf.

>From 4159aa9325c6897bc464cb5828ffcfe81b4638ea Mon Sep 17 00:00:00 2001
From: Jake Egan <jake.egan at ibm.com>
Date: Sun, 27 Apr 2025 18:43:59 -0400
Subject: [PATCH 09/15] Correct backslash mistake

---
 compiler-rt/lib/asan/asan_interceptors_memintrinsics.cpp | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/compiler-rt/lib/asan/asan_interceptors_memintrinsics.cpp b/compiler-rt/lib/asan/asan_interceptors_memintrinsics.cpp
index 6842962e00466..eabf9c08383b0 100644
--- a/compiler-rt/lib/asan/asan_interceptors_memintrinsics.cpp
+++ b/compiler-rt/lib/asan/asan_interceptors_memintrinsics.cpp
@@ -36,11 +36,11 @@ using namespace __asan;
       ASAN_WRITE_RANGE(ctx, to, size);                        \
     } else if (UNLIKELY(!AsanInited())) {                     \
       return internal_memcpy(to, from, size);                 \
-    }                                                         \
+    }
 #if !SANITIZER_AIX
-    return REAL(memcpy)(to, from, size);                      \
+    return REAL(memcpy)(to, from, size);
 #else
-    return internal_memcpy(to, from, size);                   \
+    return internal_memcpy(to, from, size);
 #endif
   } while (0)
 

>From b0098db6739adac57e81f11ab1e37cb294459026 Mon Sep 17 00:00:00 2001
From: Jake Egan <jake.egan at ibm.com>
Date: Sun, 27 Apr 2025 19:56:06 -0400
Subject: [PATCH 10/15] Fix return

---
 .../asan/asan_interceptors_memintrinsics.cpp   | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/compiler-rt/lib/asan/asan_interceptors_memintrinsics.cpp b/compiler-rt/lib/asan/asan_interceptors_memintrinsics.cpp
index eabf9c08383b0..4ac4768852caf 100644
--- a/compiler-rt/lib/asan/asan_interceptors_memintrinsics.cpp
+++ b/compiler-rt/lib/asan/asan_interceptors_memintrinsics.cpp
@@ -22,10 +22,18 @@
 
 using namespace __asan;
 
+// AIX does not intercept memcpy, so we have to use internal_memcpy.
+#if !SANITIZER_AIX
+  #define ASAN_MEMCPY_RETURN(to, from, size) \
+    return REAL(memcpy)(to, from, size)
+#else
+  #define ASAN_MEMCPY_RETURN(to, from, size) \
+    return internal_memcpy(to, from, size)
+#endif
+
 // memcpy is called during __asan_init() from the internals of printf(...).
 // We do not treat memcpy with to==from as a bug.
 // See http://llvm.org/bugs/show_bug.cgi?id=11763.
-// AIX does not intercept memcpy, so we have to use internal_memcpy.
 #define ASAN_MEMCPY_IMPL(ctx, to, from, size)                 \
   do {                                                        \
     if (LIKELY(replace_intrin_cached)) {                      \
@@ -36,12 +44,8 @@ using namespace __asan;
       ASAN_WRITE_RANGE(ctx, to, size);                        \
     } else if (UNLIKELY(!AsanInited())) {                     \
       return internal_memcpy(to, from, size);                 \
-    }
-#if !SANITIZER_AIX
-    return REAL(memcpy)(to, from, size);
-#else
-    return internal_memcpy(to, from, size);
-#endif
+    }                                                         \
+    ASAN_MEMCPY_RETURN(to, from, size);                       \
   } while (0)
 
 // memset is called inside Printf.

>From b159f20b73f46a8a6f29d8b6d1c02111bca1d2f9 Mon Sep 17 00:00:00 2001
From: Jake Egan <jake.egan at ibm.com>
Date: Sun, 27 Apr 2025 20:17:39 -0400
Subject: [PATCH 11/15] Fix formatting

---
 compiler-rt/lib/asan/asan_interceptors.cpp    |  59 +++---
 compiler-rt/lib/asan/asan_interceptors.h      | 173 +++++++++---------
 .../asan/asan_interceptors_memintrinsics.cpp  |   5 +-
 compiler-rt/lib/asan/asan_malloc_linux.cpp    |  11 +-
 4 files changed, 122 insertions(+), 126 deletions(-)

diff --git a/compiler-rt/lib/asan/asan_interceptors.cpp b/compiler-rt/lib/asan/asan_interceptors.cpp
index f73591190fedb..57b866b29bd00 100644
--- a/compiler-rt/lib/asan/asan_interceptors.cpp
+++ b/compiler-rt/lib/asan/asan_interceptors.cpp
@@ -56,7 +56,7 @@ namespace __asan {
 #  define ASAN_READ_STRING(ctx, s, n) \
     ASAN_READ_STRING_OF_LEN((ctx), (s), internal_strlen(s), (n))
 
-#if SANITIZER_INTERCEPT_STRCAT || SANITIZER_INTERCEPT_STRCPY
+#  if SANITIZER_INTERCEPT_STRCAT || SANITIZER_INTERCEPT_STRCPY
 static inline uptr MaybeRealStrnlen(const char *s, uptr maxlen) {
 #if SANITIZER_INTERCEPT_STRNLEN
   if (REAL(strnlen)) {
@@ -65,7 +65,7 @@ static inline uptr MaybeRealStrnlen(const char *s, uptr maxlen) {
 #endif
   return internal_strnlen(s, maxlen);
 }
-#endif
+#  endif
 
 void SetThreadName(const char *name) {
   AsanThread *t = GetCurrentThread();
@@ -278,11 +278,11 @@ INTERCEPTOR(int, pthread_create, void *thread, void *attr,
     asanThreadArgRetval().Create(detached, {start_routine, arg}, [&]() -> uptr {
       result = REAL(pthread_create)(thread, attr, asan_thread_start, t);
 // AIX pthread_t is unsigned int.
-#if SANITIZER_AIX
+#    if SANITIZER_AIX
       return result ? 0 : *(unsigned int *)(thread);
-#else
+#    else
       return result ? 0 : *(uptr *)(thread);
-#endif
+#    endif
     });
   }
   if (result != 0) {
@@ -439,14 +439,14 @@ INTERCEPTOR(int, swapcontext, struct ucontext_t *oucp,
 #define siglongjmp __siglongjmp14
 #endif
 
-#if ASAN_INTERCEPT_LONGJMP
+#  if ASAN_INTERCEPT_LONGJMP
 INTERCEPTOR(void, longjmp, void *env, int val) {
   __asan_handle_no_return();
   REAL(longjmp)(env, val);
 }
-#endif
+#  endif
 
-#if ASAN_INTERCEPT__LONGJMP
+#  if ASAN_INTERCEPT__LONGJMP
 INTERCEPTOR(void, _longjmp, void *env, int val) {
   __asan_handle_no_return();
   REAL(_longjmp)(env, val);
@@ -517,7 +517,7 @@ DEFINE_REAL(char*, index, const char *string, int c)
 
 // For both strcat() and strncat() we need to check the validity of |to|
 // argument irrespective of the |from| length.
-#if SANITIZER_INTERCEPT_STRCAT
+#  if SANITIZER_INTERCEPT_STRCAT
   INTERCEPTOR(char *, strcat, char *to, const char *from) {
     void *ctx;
     ASAN_INTERCEPTOR_ENTER(ctx, strcat);
@@ -538,7 +538,7 @@ DEFINE_REAL(char*, index, const char *string, int c)
     }
     return REAL(strcat)(to, from);
   }
-#endif
+#  endif
 
 INTERCEPTOR(char*, strncat, char *to, const char *from, usize size) {
   void *ctx;
@@ -559,7 +559,7 @@ INTERCEPTOR(char*, strncat, char *to, const char *from, usize size) {
   return REAL(strncat)(to, from, size);
 }
 
-#if SANITIZER_INTERCEPT_STRCPY
+#  if SANITIZER_INTERCEPT_STRCPY
 INTERCEPTOR(char *, strcpy, char *to, const char *from) {
   void *ctx;
   ASAN_INTERCEPTOR_ENTER(ctx, strcpy);
@@ -581,7 +581,7 @@ INTERCEPTOR(char *, strcpy, char *to, const char *from) {
   }
   return REAL(strcpy)(to, from);
 }
-#endif
+#  endif
 
 // Windows doesn't always define the strdup identifier,
 // and when it does it's a macro defined to either _strdup
@@ -618,7 +618,6 @@ INTERCEPTOR(char*, strdup, const char *s) {
 #  endif
   }
   return reinterpret_cast<char*>(new_mem);
-
 }
 
 #  if ASAN_INTERCEPT___STRDUP
@@ -634,17 +633,17 @@ INTERCEPTOR(char*, __strdup, const char *s) {
   GET_STACK_TRACE_MALLOC;
   void *new_mem = asan_malloc(length + 1, &stack);
   if (new_mem) {
-#if SANITIZER_AIX
+#    if SANITIZER_AIX
     internal_memcpy(new_mem, s, length + 1);
-#else
+#    else
     REAL(memcpy)(new_mem, s, length + 1);
-#endif
+#    endif
   }
   return reinterpret_cast<char*>(new_mem);
 }
 #endif // ASAN_INTERCEPT___STRDUP
 
-#if SANITIZER_INTERCEPT_STRCPY
+#  if SANITIZER_INTERCEPT_STRCPY
 INTERCEPTOR(char*, strncpy, char *to, const char *from, usize size) {
   void *ctx;
   ASAN_INTERCEPTOR_ENTER(ctx, strncpy);
@@ -657,7 +656,7 @@ INTERCEPTOR(char*, strncpy, char *to, const char *from, usize size) {
   }
   return REAL(strncpy)(to, from, size);
 }
-#endif
+#  endif
 
 template <typename Fn>
 static ALWAYS_INLINE auto StrtolImpl(void *ctx, Fn real, const char *nptr,
@@ -769,15 +768,15 @@ static void AtCxaAtexit(void *unused) {
 }
 #endif
 
-#if ASAN_INTERCEPT_EXIT
+#  if ASAN_INTERCEPT_EXIT
 INTERCEPTOR(void, exit, int status) {
   AsanInitFromRtl();
   StopInitOrderChecking();
   REAL(exit)(status);
 }
-#endif
+#  endif
 
-#if ASAN_INTERCEPT___CXA_ATEXIT
+#  if ASAN_INTERCEPT___CXA_ATEXIT
 INTERCEPTOR(int, __cxa_atexit, void (*func)(void *), void *arg,
             void *dso_handle) {
   if (SANITIZER_APPLE && UNLIKELY(!AsanInited()))
@@ -838,14 +837,14 @@ void InitializeAsanInterceptors() {
   InitializeSignalInterceptors();
 
   // Intercept str* functions.
-#if SANITIZER_INTERCEPT_STRCAT
+#  if SANITIZER_INTERCEPT_STRCAT
   ASAN_INTERCEPT_FUNC(strcat);
   ASAN_INTERCEPT_FUNC(strncat);
-#endif
-#if SANITIZER_INTERCEPT_STRCPY
+#  endif
+#  if SANITIZER_INTERCEPT_STRCPY
   ASAN_INTERCEPT_FUNC(strcpy);
   ASAN_INTERCEPT_FUNC(strncpy);
-#endif
+#  endif
   ASAN_INTERCEPT_FUNC(strdup);
 #  if ASAN_INTERCEPT___STRDUP
   ASAN_INTERCEPT_FUNC(__strdup);
@@ -865,9 +864,9 @@ void InitializeAsanInterceptors() {
 #  endif
 
   // Intercept jump-related functions.
-#if ASAN_INTERCEPT_LONGJMP
+#  if ASAN_INTERCEPT_LONGJMP
   ASAN_INTERCEPT_FUNC(longjmp);
-#endif
+#  endif
 
 #  if ASAN_INTERCEPT_SWAPCONTEXT
   ASAN_INTERCEPT_FUNC(swapcontext);
@@ -934,11 +933,11 @@ void InitializeAsanInterceptors() {
   ASAN_INTERCEPT_FUNC(atexit);
 #endif
 
-#if ASAN_INTERCEPT_EXIT
+#  if ASAN_INTERCEPT_EXIT
   ASAN_INTERCEPT_FUNC(exit);
-#endif
+#  endif
 
-#if ASAN_INTERCEPT_PTHREAD_ATFORK
+#  if ASAN_INTERCEPT_PTHREAD_ATFORK
   ASAN_INTERCEPT_FUNC(pthread_atfork);
 #endif
 
diff --git a/compiler-rt/lib/asan/asan_interceptors.h b/compiler-rt/lib/asan/asan_interceptors.h
index 9ad72e71cef97..bc647419e0050 100644
--- a/compiler-rt/lib/asan/asan_interceptors.h
+++ b/compiler-rt/lib/asan/asan_interceptors.h
@@ -31,22 +31,22 @@ void InitializePlatformInterceptors();
 // really defined to replace libc functions.
 #if !SANITIZER_FUCHSIA
 
-#if !SANITIZER_AIX
-# define ASAN_INTERCEPT_LONGJMP 1
-#else
-# define ASAN_INTERCEPT_LONGJMP 0
-#endif
+#  if !SANITIZER_AIX
+#    define ASAN_INTERCEPT_LONGJMP 1
+#  else
+#    define ASAN_INTERCEPT_LONGJMP 0
+#  endif
 
 // Use macro to describe if specific function should be
 // intercepted on a given platform.
 #if !SANITIZER_WINDOWS
-#if !SANITIZER_AIX
-# define ASAN_INTERCEPT__LONGJMP 1
-#else
-# define ASAN_INTERCEPT__LONGJMP 0
-#endif
-# define ASAN_INTERCEPT_INDEX 1
-# define ASAN_INTERCEPT_PTHREAD_CREATE 1
+#    if !SANITIZER_AIX
+#      define ASAN_INTERCEPT__LONGJMP 1
+#    else
+#      define ASAN_INTERCEPT__LONGJMP 0
+#    endif
+#    define ASAN_INTERCEPT_INDEX 1
+#    define ASAN_INTERCEPT_PTHREAD_CREATE 1
 #else
 # define ASAN_INTERCEPT__LONGJMP 0
 # define ASAN_INTERCEPT_INDEX 0
@@ -66,88 +66,87 @@ void InitializePlatformInterceptors();
 # define ASAN_INTERCEPT_SWAPCONTEXT 0
 #endif
 
-#if !SANITIZER_WINDOWS && !SANITIZER_AIX
-# define ASAN_INTERCEPT_SIGLONGJMP 1
-#else
-# define ASAN_INTERCEPT_SIGLONGJMP 0
-#endif
-
-#if SANITIZER_GLIBC
-# define ASAN_INTERCEPT___LONGJMP_CHK 1
-#else
-# define ASAN_INTERCEPT___LONGJMP_CHK 0
-#endif
-
-#if ASAN_HAS_EXCEPTIONS && !SANITIZER_SOLARIS && !SANITIZER_NETBSD && \
-    (!SANITIZER_WINDOWS || (defined(__MINGW32__) && defined(__i386__)))
-# define ASAN_INTERCEPT___CXA_THROW 1
-# define ASAN_INTERCEPT___CXA_RETHROW_PRIMARY_EXCEPTION 1
-# if defined(_GLIBCXX_SJLJ_EXCEPTIONS) || (SANITIZER_IOS && defined(__arm__))
-#  define ASAN_INTERCEPT__UNWIND_SJLJ_RAISEEXCEPTION 1
-# else
-#  define ASAN_INTERCEPT__UNWIND_RAISEEXCEPTION 1
-# endif
-#else
-# define ASAN_INTERCEPT___CXA_THROW 0
-# define ASAN_INTERCEPT___CXA_RETHROW_PRIMARY_EXCEPTION 0
-# define ASAN_INTERCEPT__UNWIND_RAISEEXCEPTION 0
-# define ASAN_INTERCEPT__UNWIND_SJLJ_RAISEEXCEPTION 0
-#endif
-
-#if !SANITIZER_WINDOWS && !SANITIZER_AIX
-# define ASAN_INTERCEPT___CXA_ATEXIT 1
-#else
-# define ASAN_INTERCEPT___CXA_ATEXIT 0
-#endif
-
-#if SANITIZER_AIX
-# define ASAN_INTERCEPT_EXIT 1
-#else
-# define ASAN_INTERCEPT_EXIT 0
-#endif
+#  if !SANITIZER_WINDOWS && !SANITIZER_AIX
+#    define ASAN_INTERCEPT_SIGLONGJMP 1
+#  else
+#    define ASAN_INTERCEPT_SIGLONGJMP 0
+#  endif
 
-#if SANITIZER_NETBSD
-# define ASAN_INTERCEPT_ATEXIT 1
-#else
-# define ASAN_INTERCEPT_ATEXIT 0
-#endif
+#  if SANITIZER_GLIBC
+#    define ASAN_INTERCEPT___LONGJMP_CHK 1
+#  else
+#    define ASAN_INTERCEPT___LONGJMP_CHK 0
+#  endif
+
+#  if ASAN_HAS_EXCEPTIONS && !SANITIZER_SOLARIS && !SANITIZER_NETBSD && \
+      (!SANITIZER_WINDOWS || (defined(__MINGW32__) && defined(__i386__)))
+#    define ASAN_INTERCEPT___CXA_THROW 1
+#    define ASAN_INTERCEPT___CXA_RETHROW_PRIMARY_EXCEPTION 1
+#    if defined(_GLIBCXX_SJLJ_EXCEPTIONS) || (SANITIZER_IOS && defined(__arm__))
+#      define ASAN_INTERCEPT__UNWIND_SJLJ_RAISEEXCEPTION 1
+#    else
+#      define ASAN_INTERCEPT__UNWIND_RAISEEXCEPTION 1
+#    endif
+#  else
+#    define ASAN_INTERCEPT___CXA_THROW 0
+#    define ASAN_INTERCEPT___CXA_RETHROW_PRIMARY_EXCEPTION 0
+#    define ASAN_INTERCEPT__UNWIND_RAISEEXCEPTION 0
+#    define ASAN_INTERCEPT__UNWIND_SJLJ_RAISEEXCEPTION 0
+#  endif
+
+#  if !SANITIZER_WINDOWS && !SANITIZER_AIX
+#    define ASAN_INTERCEPT___CXA_ATEXIT 1
+#  else
+#    define ASAN_INTERCEPT___CXA_ATEXIT 0
+#  endif
 
-#if SANITIZER_GLIBC
-# define ASAN_INTERCEPT___STRDUP 1
-#else
-# define ASAN_INTERCEPT___STRDUP 0
-#endif
+#  if SANITIZER_AIX
+#    define ASAN_INTERCEPT_EXIT 1
+#  else
+#    define ASAN_INTERCEPT_EXIT 0
+#  endif
 
-#if SANITIZER_GLIBC && ASAN_INTERCEPT_PTHREAD_CREATE
-# define ASAN_INTERCEPT_TIMEDJOIN 1
-# define ASAN_INTERCEPT_TRYJOIN 1
-#else
-# define ASAN_INTERCEPT_TIMEDJOIN 0
-# define ASAN_INTERCEPT_TRYJOIN 0
-#endif
+#  if SANITIZER_NETBSD
+#    define ASAN_INTERCEPT_ATEXIT 1
+#  else
+#    define ASAN_INTERCEPT_ATEXIT 0
+#  endif
 
-#if SANITIZER_AIX
-#define SANITIZER_INTERCEPT_STRCAT 0
-#define SANITIZER_INTERCEPT_STRCPY 0
-#else
-#define SANITIZER_INTERCEPT_STRCAT 1
-#define SANITIZER_INTERCEPT_STRCPY 1
-#endif
+#  if SANITIZER_GLIBC
+#    define ASAN_INTERCEPT___STRDUP 1
+#  else
+#    define ASAN_INTERCEPT___STRDUP 0
+#  endif
 
+#  if SANITIZER_GLIBC && ASAN_INTERCEPT_PTHREAD_CREATE
+#    define ASAN_INTERCEPT_TIMEDJOIN 1
+#    define ASAN_INTERCEPT_TRYJOIN 1
+#  else
+#    define ASAN_INTERCEPT_TIMEDJOIN 0
+#    define ASAN_INTERCEPT_TRYJOIN 0
+#  endif
 
-#if SANITIZER_LINUX &&                                                \
-    (defined(__arm__) || defined(__aarch64__) || defined(__i386__) || \
-     defined(__x86_64__) || SANITIZER_RISCV64 || SANITIZER_LOONGARCH64)
-# define ASAN_INTERCEPT_VFORK 1
-#else
-# define ASAN_INTERCEPT_VFORK 0
-#endif
+#  if SANITIZER_AIX
+#    define SANITIZER_INTERCEPT_STRCAT 0
+#    define SANITIZER_INTERCEPT_STRCPY 0
+#  else
+#    define SANITIZER_INTERCEPT_STRCAT 1
+#    define SANITIZER_INTERCEPT_STRCPY 1
+#  endif
+
+#  if SANITIZER_LINUX &&                                                \
+      (defined(__arm__) || defined(__aarch64__) || defined(__i386__) || \
+       defined(__x86_64__) || SANITIZER_RISCV64 || SANITIZER_LOONGARCH64)
+#    define ASAN_INTERCEPT_VFORK 1
+#  else
+#    define ASAN_INTERCEPT_VFORK 0
+#  endif
 
-#if SANITIZER_NETBSD
-# define ASAN_INTERCEPT_PTHREAD_ATFORK 1
-#else
-# define ASAN_INTERCEPT_PTHREAD_ATFORK 0
-#endif
+#  if SANITIZER_NETBSD
+#    define ASAN_INTERCEPT_PTHREAD_ATFORK 1
+#  else
+#    define ASAN_INTERCEPT_PTHREAD_ATFORK 0
+#  endif
 
 DECLARE_REAL(int, memcmp, const void *a1, const void *a2, SIZE_T size)
 DECLARE_REAL(char*, strchr, const char *str, int c)
diff --git a/compiler-rt/lib/asan/asan_interceptors_memintrinsics.cpp b/compiler-rt/lib/asan/asan_interceptors_memintrinsics.cpp
index 4ac4768852caf..008622c415fa6 100644
--- a/compiler-rt/lib/asan/asan_interceptors_memintrinsics.cpp
+++ b/compiler-rt/lib/asan/asan_interceptors_memintrinsics.cpp
@@ -24,10 +24,9 @@ using namespace __asan;
 
 // AIX does not intercept memcpy, so we have to use internal_memcpy.
 #if !SANITIZER_AIX
-  #define ASAN_MEMCPY_RETURN(to, from, size) \
-    return REAL(memcpy)(to, from, size)
+#  define ASAN_MEMCPY_RETURN(to, from, size) return REAL(memcpy)(to, from, size)
 #else
-  #define ASAN_MEMCPY_RETURN(to, from, size) \
+#  define ASAN_MEMCPY_RETURN(to, from, size) \
     return internal_memcpy(to, from, size)
 #endif
 
diff --git a/compiler-rt/lib/asan/asan_malloc_linux.cpp b/compiler-rt/lib/asan/asan_malloc_linux.cpp
index eaf37718a185d..e2014fe53cac7 100644
--- a/compiler-rt/lib/asan/asan_malloc_linux.cpp
+++ b/compiler-rt/lib/asan/asan_malloc_linux.cpp
@@ -16,8 +16,7 @@
 #include "sanitizer_common/sanitizer_platform.h"
 // FIXME: rename this file, this is not just for Linux now, see FUCHSIA and AIX.
 #if SANITIZER_FREEBSD || SANITIZER_FUCHSIA || SANITIZER_LINUX || \
-    SANITIZER_NETBSD || SANITIZER_SOLARIS || SANITIZER_HAIKU ||  \
-    SANITIZER_AIX
+    SANITIZER_NETBSD || SANITIZER_SOLARIS || SANITIZER_HAIKU || SANITIZER_AIX
 
 #  include "asan_allocator.h"
 #  include "asan_interceptors.h"
@@ -63,8 +62,8 @@ INTERCEPTOR(void, cfree, void *ptr) {
 }
 #endif // SANITIZER_INTERCEPT_CFREE
 
-#if SANITIZER_AIX
-INTERCEPTOR(void*, vec_malloc, uptr size) {
+#  if SANITIZER_AIX
+INTERCEPTOR(void *, vec_malloc, uptr size) {
   if (DlsymAlloc::Use())
     return DlsymAlloc::Allocate(size);
   AsanInitFromRtl();
@@ -72,14 +71,14 @@ INTERCEPTOR(void*, vec_malloc, uptr size) {
   return asan_malloc(size, &stack);
 }
 
-INTERCEPTOR(void*, vec_calloc, uptr nmemb, uptr size) {
+INTERCEPTOR(void *, vec_calloc, uptr nmemb, uptr size) {
   if (DlsymAlloc::Use())
     return DlsymAlloc::Callocate(nmemb, size);
   AsanInitFromRtl();
   GET_STACK_TRACE_MALLOC;
   return asan_calloc(nmemb, size, &stack);
 }
-#endif
+#  endif
 
 INTERCEPTOR(void*, malloc, uptr size) {
   if (DlsymAlloc::Use())

>From 67317ad15d9c2e78cbba5d5d339c9c05d9d0f023 Mon Sep 17 00:00:00 2001
From: Jake Egan <jake.egan at ibm.com>
Date: Mon, 28 Apr 2025 00:36:29 -0400
Subject: [PATCH 12/15] Move misplaced endif

---
 compiler-rt/lib/asan/asan_interceptors.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/compiler-rt/lib/asan/asan_interceptors.cpp b/compiler-rt/lib/asan/asan_interceptors.cpp
index 57b866b29bd00..7e43cc0baff47 100644
--- a/compiler-rt/lib/asan/asan_interceptors.cpp
+++ b/compiler-rt/lib/asan/asan_interceptors.cpp
@@ -538,7 +538,6 @@ DEFINE_REAL(char*, index, const char *string, int c)
     }
     return REAL(strcat)(to, from);
   }
-#  endif
 
 INTERCEPTOR(char*, strncat, char *to, const char *from, usize size) {
   void *ctx;
@@ -558,6 +557,7 @@ INTERCEPTOR(char*, strncat, char *to, const char *from, usize size) {
   }
   return REAL(strncat)(to, from, size);
 }
+#  endif
 
 #  if SANITIZER_INTERCEPT_STRCPY
 INTERCEPTOR(char *, strcpy, char *to, const char *from) {

>From 16a2d818182e904061d6b232d8bc7f238cc64b43 Mon Sep 17 00:00:00 2001
From: Jake Egan <jake.egan at ibm.com>
Date: Mon, 5 May 2025 19:24:12 -0400
Subject: [PATCH 13/15] Split code to different PRs

---
 compiler-rt/lib/interception/CMakeLists.txt   |  2 -
 compiler-rt/lib/interception/interception.h   | 25 ++-----
 .../lib/interception/interception_aix.cpp     | 45 -----------
 .../lib/interception/interception_aix.h       | 36 ---------
 .../sanitizer_common_interceptors.inc         | 74 ++++++-------------
 .../sanitizer_common_interceptors_ioctl.inc   | 10 ---
 ...izer_common_interceptors_memintrinsics.inc |  2 -
 .../sanitizer_platform_interceptors.h         | 62 ++++++----------
 .../sanitizer_redefine_builtins.h             |  2 +-
 9 files changed, 52 insertions(+), 206 deletions(-)
 delete mode 100644 compiler-rt/lib/interception/interception_aix.cpp
 delete mode 100644 compiler-rt/lib/interception/interception_aix.h

diff --git a/compiler-rt/lib/interception/CMakeLists.txt b/compiler-rt/lib/interception/CMakeLists.txt
index 57c8c8ba20141..fe7fa27fbc78b 100644
--- a/compiler-rt/lib/interception/CMakeLists.txt
+++ b/compiler-rt/lib/interception/CMakeLists.txt
@@ -1,7 +1,6 @@
 # Build for the runtime interception helper library.
 
 set(INTERCEPTION_SOURCES
-  interception_aix.cpp
   interception_linux.cpp
   interception_mac.cpp
   interception_win.cpp
@@ -10,7 +9,6 @@ set(INTERCEPTION_SOURCES
 
 set(INTERCEPTION_HEADERS
   interception.h
-  interception_aix.h
   interception_linux.h
   interception_mac.h
   interception_win.h
diff --git a/compiler-rt/lib/interception/interception.h b/compiler-rt/lib/interception/interception.h
index 9fe7d3db308bf..25480120e7ad6 100644
--- a/compiler-rt/lib/interception/interception.h
+++ b/compiler-rt/lib/interception/interception.h
@@ -19,7 +19,7 @@
 
 #if !SANITIZER_LINUX && !SANITIZER_FREEBSD && !SANITIZER_APPLE &&    \
     !SANITIZER_NETBSD && !SANITIZER_WINDOWS && !SANITIZER_FUCHSIA && \
-    !SANITIZER_SOLARIS && !SANITIZER_HAIKU && !SANITIZER_AIX
+    !SANITIZER_SOLARIS && !SANITIZER_HAIKU
 #  error "Interception doesn't work on this operating system."
 #endif
 
@@ -168,16 +168,6 @@ const interpose_substitution substitution_##func_name[]             \
     extern "C" ret_type func(__VA_ARGS__);
 # define DECLARE_WRAPPER_WINAPI(ret_type, func, ...)  \
     extern "C" __declspec(dllimport) ret_type __stdcall func(__VA_ARGS__);
-#elif SANITIZER_AIX
-#  define WRAP(x) __interceptor_##x
-#  define TRAMPOLINE(x) WRAP(x)
-// # define WRAPPER_NAME(x) "__interceptor_" #x
-#  define INTERCEPTOR_ATTRIBUTE __attribute__((visibility("default")))
-// AIX's linker will not select the weak symbol, so don't use weak for the
-// interceptors.
-#  define DECLARE_WRAPPER(ret_type, func, ...) \
-    extern "C" ret_type func(__VA_ARGS__)      \
-        __attribute__((alias("__interceptor_" #func), visibility("default")));
 #elif !SANITIZER_FUCHSIA  // LINUX, FREEBSD, NETBSD, SOLARIS
 # define INTERCEPTOR_ATTRIBUTE __attribute__((visibility("default")))
 # if ASM_INTERCEPTOR_TRAMPOLINE_SUPPORT
@@ -377,17 +367,12 @@ inline void DoesNotSupportStaticLinking() {}
 
 #define INCLUDED_FROM_INTERCEPTION_LIB
 
-#if SANITIZER_AIX
-#  include "interception_aix.h"
-#  define INTERCEPT_FUNCTION(func) INTERCEPT_FUNCTION_AIX(func)
-#  define INTERCEPT_FUNCTION_VER(func, symver) INTERCEPT_FUNCTION_AIX(func)
-
-#elif SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_NETBSD || \
+#if SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_NETBSD || \
     SANITIZER_SOLARIS || SANITIZER_HAIKU
 
-#  include "interception_linux.h"
-#  define INTERCEPT_FUNCTION(func) INTERCEPT_FUNCTION_LINUX_OR_FREEBSD(func)
-#  define INTERCEPT_FUNCTION_VER(func, symver) \
+# include "interception_linux.h"
+# define INTERCEPT_FUNCTION(func) INTERCEPT_FUNCTION_LINUX_OR_FREEBSD(func)
+# define INTERCEPT_FUNCTION_VER(func, symver) \
     INTERCEPT_FUNCTION_VER_LINUX_OR_FREEBSD(func, symver)
 #elif SANITIZER_APPLE
 # include "interception_mac.h"
diff --git a/compiler-rt/lib/interception/interception_aix.cpp b/compiler-rt/lib/interception/interception_aix.cpp
deleted file mode 100644
index 953bbad96eb47..0000000000000
--- a/compiler-rt/lib/interception/interception_aix.cpp
+++ /dev/null
@@ -1,45 +0,0 @@
-//===-- interception_aix.cpp ------------------------------------*- C++ -*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-//
-// This file is a part of AddressSanitizer, an address sanity checker.
-//
-// AIX-specific interception methods.
-//===----------------------------------------------------------------------===//
-
-#include "interception.h"
-#include "sanitizer_common/sanitizer_common.h"
-
-#if SANITIZER_AIX
-
-#  include <dlfcn.h>  // for dlsym()
-
-namespace __interception {
-
-static void *GetFuncAddr(const char *name, uptr wrapper_addr) {
-  // AIX dlsym can only defect the functions that are exported, so
-  // on AIX, we can not intercept some basic functions like memcpy.
-  // FIXME: if we are going to ship dynamic asan library, we may need to search
-  // all the loaded modules with RTLD_DEFAULT if RTLD_NEXT failed.
-  void *addr = dlsym(RTLD_NEXT, name);
-
-  // In case `name' is not loaded, dlsym ends up finding the actual wrapper.
-  // We don't want to intercept the wrapper and have it point to itself.
-  if ((uptr)addr == wrapper_addr)
-    addr = nullptr;
-  return addr;
-}
-
-bool InterceptFunction(const char *name, uptr *ptr_to_real, uptr func,
-                       uptr wrapper) {
-  void *addr = GetFuncAddr(name, wrapper);
-  *ptr_to_real = (uptr)addr;
-  return addr && (func == wrapper);
-}
-
-}  // namespace __interception
-#endif  // SANITIZER_AIX
diff --git a/compiler-rt/lib/interception/interception_aix.h b/compiler-rt/lib/interception/interception_aix.h
deleted file mode 100644
index b86ae89f50461..0000000000000
--- a/compiler-rt/lib/interception/interception_aix.h
+++ /dev/null
@@ -1,36 +0,0 @@
-//===-- interception_aix.h --------------------------------------*- C++ -*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-//
-// This file is a part of AddressSanitizer, an address sanity checker.
-//
-// AIX-specific interception methods.
-//===----------------------------------------------------------------------===//
-
-#if SANITIZER_AIX
-
-#  if !defined(INCLUDED_FROM_INTERCEPTION_LIB)
-#    error \
-        "interception_aix.h should be included from interception library only"
-#  endif
-
-#  ifndef INTERCEPTION_AIX_H
-#    define INTERCEPTION_AIX_H
-
-namespace __interception {
-bool InterceptFunction(const char *name, uptr *ptr_to_real, uptr func,
-                       uptr wrapper);
-}  // namespace __interception
-
-#    define INTERCEPT_FUNCTION_AIX(func)                \
-      ::__interception::InterceptFunction(              \
-          #func, (::__interception::uptr *)&REAL(func), \
-          (::__interception::uptr) & (func),            \
-          (::__interception::uptr) & WRAP(func))
-
-#  endif  // INTERCEPTION_AIX_H
-#endif    // SANITIZER_AIX
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
index bdbd9b7637f9f..5a15d75f0c86a 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
@@ -480,7 +480,7 @@ INTERCEPTOR(char*, textdomain, const char *domainname) {
 #define INIT_TEXTDOMAIN
 #endif
 
-#if SANITIZER_INTERCEPT_MEMCMP
+#if SANITIZER_INTERCEPT_STRCMP || SANITIZER_INTERCEPT_MEMCMP
 static inline int CharCmpX(unsigned char c1, unsigned char c2) {
   return (c1 == c2) ? 0 : (c1 < c2) ? -1 : 1;
 }
@@ -953,7 +953,7 @@ INTERCEPTOR(double, frexp, double x, int *exp) {
 #define INIT_FREXP
 #endif  // SANITIZER_INTERCEPT_FREXP
 
-#if SANITIZER_INTERCEPT_FREXPF
+#if SANITIZER_INTERCEPT_FREXPF_FREXPL
 INTERCEPTOR(float, frexpf, float x, int *exp) {
   void *ctx;
   COMMON_INTERCEPTOR_ENTER(ctx, frexpf, x, exp);
@@ -963,12 +963,6 @@ INTERCEPTOR(float, frexpf, float x, int *exp) {
   return res;
 }
 
-#  define INIT_FREXPF COMMON_INTERCEPT_FUNCTION(frexpf);
-#else
-#  define INIT_FREXPF
-#endif
-
-#if SANITIZER_INTERCEPT_FREXPL
 INTERCEPTOR(long double, frexpl, long double x, int *exp) {
   void *ctx;
   COMMON_INTERCEPTOR_ENTER(ctx, frexpl, x, exp);
@@ -978,10 +972,12 @@ INTERCEPTOR(long double, frexpl, long double x, int *exp) {
   return res;
 }
 
-#  define INIT_FREXPL COMMON_INTERCEPT_FUNCTION_LDBL(frexpl)
+#define INIT_FREXPF_FREXPL           \
+  COMMON_INTERCEPT_FUNCTION(frexpf); \
+  COMMON_INTERCEPT_FUNCTION_LDBL(frexpl)
 #else
-#  define INIT_FREXPL
-#endif
+#define INIT_FREXPF_FREXPL
+#endif  // SANITIZER_INTERCEPT_FREXPF_FREXPL
 
 #if SI_POSIX
 static void write_iovec(void *ctx, struct __sanitizer_iovec *iovec,
@@ -1350,8 +1346,7 @@ INTERCEPTOR(unsigned long, time, unsigned long *t) {
 #if SANITIZER_INTERCEPT_LOCALTIME_AND_FRIENDS
 static void unpoison_tm(void *ctx, __sanitizer_tm *tm) {
   COMMON_INTERCEPTOR_WRITE_RANGE(ctx, tm, sizeof(*tm));
-// AIX tm struct does not have tm_zone field.
-#  if !SANITIZER_SOLARIS && !SANITIZER_AIX
+#if !SANITIZER_SOLARIS
   if (tm->tm_zone) {
     // Can not use COMMON_INTERCEPTOR_WRITE_RANGE here, because tm->tm_zone
     // can point to shared memory and tsan would report a data race.
@@ -1736,12 +1731,10 @@ INTERCEPTOR(int, __vsprintf_chk, char *str, int flag, SIZE_T size_to,
 VSPRINTF_INTERCEPTOR_IMPL(vsprintf, str, format, ap)
 #endif
 
-#  if SANITIZER_INTERCEPT_VASPRINTF
 INTERCEPTOR(int, vasprintf, char **strp, const char *format, va_list ap)
 VASPRINTF_INTERCEPTOR_IMPL(vasprintf, strp, format, ap)
-#  endif
 
-#  if SANITIZER_INTERCEPT_ISOC99_PRINTF
+#if SANITIZER_INTERCEPT_ISOC99_PRINTF
 INTERCEPTOR(int, __isoc99_vprintf, const char *format, va_list ap)
 VPRINTF_INTERCEPTOR_IMPL(__isoc99_vprintf, format, ap)
 
@@ -1790,12 +1783,10 @@ INTERCEPTOR(int, __snprintf_chk, char *str, SIZE_T size, int flag,
 FORMAT_INTERCEPTOR_IMPL(__snprintf_chk, vsnprintf, str, size, format)
 #endif
 
-#  if SANITIZER_INTERCEPT_ASPRINTF
 INTERCEPTOR(int, asprintf, char **strp, const char *format, ...)
 FORMAT_INTERCEPTOR_IMPL(asprintf, vasprintf, strp, format)
-#  endif
 
-#  if SANITIZER_INTERCEPT_ISOC99_PRINTF
+#if SANITIZER_INTERCEPT_ISOC99_PRINTF
 INTERCEPTOR(int, __isoc99_printf, const char *format, ...)
 FORMAT_INTERCEPTOR_IMPL(__isoc99_printf, __isoc99_vprintf, format)
 
@@ -1816,29 +1807,17 @@ FORMAT_INTERCEPTOR_IMPL(__isoc99_snprintf, __isoc99_vsnprintf, str, size,
 #endif  // SANITIZER_INTERCEPT_PRINTF
 
 #if SANITIZER_INTERCEPT_PRINTF
-#  if SANITIZER_AIX
-#    define INIT_PRINTF                          \
-      COMMON_INTERCEPT_FUNCTION_LDBL(printf);    \
-      COMMON_INTERCEPT_FUNCTION_LDBL(sprintf);   \
-      COMMON_INTERCEPT_FUNCTION_LDBL(snprintf);  \
-      COMMON_INTERCEPT_FUNCTION_LDBL(fprintf);   \
-      COMMON_INTERCEPT_FUNCTION_LDBL(vprintf);   \
-      COMMON_INTERCEPT_FUNCTION_LDBL(vsprintf);  \
-      COMMON_INTERCEPT_FUNCTION_LDBL(vsnprintf); \
-      COMMON_INTERCEPT_FUNCTION_LDBL(vfprintf);
-#  else
-#    define INIT_PRINTF                          \
-      COMMON_INTERCEPT_FUNCTION_LDBL(printf);    \
-      COMMON_INTERCEPT_FUNCTION_LDBL(sprintf);   \
-      COMMON_INTERCEPT_FUNCTION_LDBL(snprintf);  \
-      COMMON_INTERCEPT_FUNCTION_LDBL(fprintf);   \
-      COMMON_INTERCEPT_FUNCTION_LDBL(vprintf);   \
-      COMMON_INTERCEPT_FUNCTION_LDBL(vsprintf);  \
-      COMMON_INTERCEPT_FUNCTION_LDBL(vsnprintf); \
-      COMMON_INTERCEPT_FUNCTION_LDBL(asprintf);  \
-      COMMON_INTERCEPT_FUNCTION_LDBL(vasprintf); \
-      COMMON_INTERCEPT_FUNCTION_LDBL(vfprintf);
-#  endif
+#define INIT_PRINTF                     \
+  COMMON_INTERCEPT_FUNCTION_LDBL(printf);    \
+  COMMON_INTERCEPT_FUNCTION_LDBL(sprintf);   \
+  COMMON_INTERCEPT_FUNCTION_LDBL(snprintf);  \
+  COMMON_INTERCEPT_FUNCTION_LDBL(asprintf);  \
+  COMMON_INTERCEPT_FUNCTION_LDBL(fprintf);   \
+  COMMON_INTERCEPT_FUNCTION_LDBL(vprintf);   \
+  COMMON_INTERCEPT_FUNCTION_LDBL(vsprintf);  \
+  COMMON_INTERCEPT_FUNCTION_LDBL(vsnprintf); \
+  COMMON_INTERCEPT_FUNCTION_LDBL(vasprintf); \
+  COMMON_INTERCEPT_FUNCTION_LDBL(vfprintf);
 #else
 #define INIT_PRINTF
 #endif
@@ -3938,11 +3917,7 @@ INTERCEPTOR(SIZE_T, wcrtomb, char *dest, wchar_t src, void *ps) {
   if (res != ((SIZE_T)-1)) {
     CHECK_LE(res, sizeof(local_dest));
     COMMON_INTERCEPTOR_WRITE_RANGE(ctx, dest, res);
-#  if !SANITIZER_AIX
     REAL(memcpy)(dest, local_dest, res);
-#  else
-    internal_memcpy(dest, local_dest, res);
-#  endif
   }
   return res;
 }
@@ -3964,11 +3939,7 @@ INTERCEPTOR(int, wctomb, char *dest, wchar_t src) {
   if (res != -1) {
     CHECK_LE(res, sizeof(local_dest));
     COMMON_INTERCEPTOR_WRITE_RANGE(ctx, dest, res);
-#  if !SANITIZER_AIX
     REAL(memcpy)(dest, local_dest, res);
-#  else
-    internal_memcpy(dest, local_dest, res);
-#  endif
   }
   return res;
 }
@@ -10440,8 +10411,7 @@ static void InitializeCommonInterceptors() {
   INIT_ISOC99_PRINTF;
   INIT_SETPROCTITLE;
   INIT_FREXP;
-  INIT_FREXPF;
-  INIT_FREXPL;
+  INIT_FREXPF_FREXPL;
   INIT_GETPWNAM_AND_FRIENDS;
   INIT_GETPWNAM_R_AND_FRIENDS;
   INIT_GETPWENT;
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors_ioctl.inc b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors_ioctl.inc
index 8eb0d3492535b..bc8f02826c614 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors_ioctl.inc
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors_ioctl.inc
@@ -79,9 +79,7 @@ static void ioctl_table_fill() {
   _(TIOCMSET, READ, sizeof(int));
   _(TIOCNXCL, NONE, 0);
   _(TIOCOUTQ, WRITE, sizeof(int));
-#  if !SANITIZER_AIX
   _(TIOCSCTTY, NONE, 0);
-#  endif
   _(TIOCSPGRP, READ, pid_t_sz);
   _(TIOCSWINSZ, READ, struct_winsize_sz);
 
@@ -344,17 +342,9 @@ static void ioctl_table_fill() {
   _(SOUND_PCM_WRITE_CHANNELS, WRITE, sizeof(int));
   _(SOUND_PCM_WRITE_FILTER, WRITE, sizeof(int));
   _(TCFLSH, NONE, 0);
-#if SANITIZER_GLIBC
-  _(TCGETA, WRITE, struct_termio_sz);
-#endif
   _(TCGETS, WRITE, struct_termios_sz);
   _(TCSBRK, NONE, 0);
   _(TCSBRKP, NONE, 0);
-#if SANITIZER_GLIBC
-  _(TCSETA, READ, struct_termio_sz);
-  _(TCSETAF, READ, struct_termio_sz);
-  _(TCSETAW, READ, struct_termio_sz);
-#endif
   _(TCSETS, READ, struct_termios_sz);
   _(TCSETSF, READ, struct_termios_sz);
   _(TCSETSW, READ, struct_termios_sz);
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors_memintrinsics.inc b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors_memintrinsics.inc
index 42d387e37ec98..1565a494140f6 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors_memintrinsics.inc
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors_memintrinsics.inc
@@ -36,8 +36,6 @@
 #define PLATFORM_HAS_DIFFERENT_MEMCPY_AND_MEMMOVE 0
 #elif SANITIZER_WINDOWS64
 #define PLATFORM_HAS_DIFFERENT_MEMCPY_AND_MEMMOVE 0
-#elif SANITIZER_AIX
-#  define PLATFORM_HAS_DIFFERENT_MEMCPY_AND_MEMMOVE 0
 #else
 #define PLATFORM_HAS_DIFFERENT_MEMCPY_AND_MEMMOVE 1
 #endif  // SANITIZER_APPLE
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h b/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h
index edd656c393f83..b8f2f738e7478 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h
@@ -141,12 +141,6 @@ SANITIZER_WEAK_IMPORT void *aligned_alloc(__sanitizer::usize __alignment,
 #define SI_SOLARIS 0
 #endif
 
-#if SANITIZER_AIX
-#  define SI_NOT_AIX 0
-#else
-#  define SI_NOT_AIX 1
-#endif
-
 #if SANITIZER_SOLARIS32
 #define SI_SOLARIS32 1
 #else
@@ -167,20 +161,20 @@ SANITIZER_WEAK_IMPORT void *aligned_alloc(__sanitizer::usize __alignment,
 
 #define SANITIZER_INTERCEPT_STRLEN SI_NOT_FUCHSIA
 #define SANITIZER_INTERCEPT_STRNLEN (SI_NOT_MAC && SI_NOT_FUCHSIA)
-#define SANITIZER_INTERCEPT_STRCMP (SI_NOT_FUCHSIA && SI_NOT_AIX)
+#define SANITIZER_INTERCEPT_STRCMP SI_NOT_FUCHSIA
 #define SANITIZER_INTERCEPT_STRSTR SI_NOT_FUCHSIA
-#define SANITIZER_INTERCEPT_STRCASESTR (SI_POSIX && SI_NOT_AIX)
+#define SANITIZER_INTERCEPT_STRCASESTR SI_POSIX
 #define SANITIZER_INTERCEPT_STRTOK SI_NOT_FUCHSIA
 #define SANITIZER_INTERCEPT_STRCHR SI_NOT_FUCHSIA
-#define SANITIZER_INTERCEPT_STRCHRNUL (SI_POSIX_NOT_MAC && SI_NOT_AIX)
+#define SANITIZER_INTERCEPT_STRCHRNUL SI_POSIX_NOT_MAC
 #define SANITIZER_INTERCEPT_STRRCHR SI_NOT_FUCHSIA
 #define SANITIZER_INTERCEPT_STRSPN SI_NOT_FUCHSIA
 #define SANITIZER_INTERCEPT_STRPBRK SI_NOT_FUCHSIA
 #define SANITIZER_INTERCEPT_TEXTDOMAIN SI_LINUX_NOT_ANDROID || SI_SOLARIS
 #define SANITIZER_INTERCEPT_STRCASECMP SI_POSIX
 #define SANITIZER_INTERCEPT_MEMSET 1
-#define SANITIZER_INTERCEPT_MEMMOVE SI_NOT_AIX
-#define SANITIZER_INTERCEPT_MEMCPY SI_NOT_AIX
+#define SANITIZER_INTERCEPT_MEMMOVE 1
+#define SANITIZER_INTERCEPT_MEMCPY 1
 #define SANITIZER_INTERCEPT_MEMCMP SI_NOT_FUCHSIA
 #define SANITIZER_INTERCEPT_BCMP \
   SANITIZER_INTERCEPT_MEMCMP &&  \
@@ -239,11 +233,9 @@ SANITIZER_WEAK_IMPORT void *aligned_alloc(__sanitizer::usize __alignment,
 #define SANITIZER_INTERCEPT_ISOC99_SCANF SI_GLIBC
 
 #ifndef SANITIZER_INTERCEPT_PRINTF
-#  define SANITIZER_INTERCEPT_ASPRINTF SI_NOT_AIX
-#  define SANITIZER_INTERCEPT_VASPRINTF SI_NOT_AIX
-#  define SANITIZER_INTERCEPT_PRINTF SI_POSIX
-#  define SANITIZER_INTERCEPT_PRINTF_L (SI_FREEBSD || SI_NETBSD)
-#  define SANITIZER_INTERCEPT_ISOC99_PRINTF SI_GLIBC
+#define SANITIZER_INTERCEPT_PRINTF SI_POSIX
+#define SANITIZER_INTERCEPT_PRINTF_L (SI_FREEBSD || SI_NETBSD)
+#define SANITIZER_INTERCEPT_ISOC99_PRINTF SI_GLIBC
 #endif
 
 #define SANITIZER_INTERCEPT_SETPROCTITLE (SI_FREEBSD || SI_NETBSD)
@@ -251,10 +243,8 @@ SANITIZER_WEAK_IMPORT void *aligned_alloc(__sanitizer::usize __alignment,
 #define SANITIZER_INTERCEPT___PRINTF_CHK \
   (SANITIZER_INTERCEPT_PRINTF && SI_GLIBC)
 
-// AIX libc does not export FREXP and FREXP.
-#define SANITIZER_INTERCEPT_FREXP (SI_NOT_FUCHSIA && SI_NOT_AIX)
-#define SANITIZER_INTERCEPT_FREXPF (SI_POSIX && SI_NOT_AIX)
-#define SANITIZER_INTERCEPT_FREXPL SI_POSIX
+#define SANITIZER_INTERCEPT_FREXP SI_NOT_FUCHSIA
+#define SANITIZER_INTERCEPT_FREXPF_FREXPL SI_POSIX
 
 #define SANITIZER_INTERCEPT_GETPWNAM_AND_FRIENDS SI_POSIX
 #define SANITIZER_INTERCEPT_GETPWNAM_R_AND_FRIENDS \
@@ -303,7 +293,7 @@ SANITIZER_WEAK_IMPORT void *aligned_alloc(__sanitizer::usize __alignment,
 #define SANITIZER_INTERCEPT_ACCEPT4 \
   (SI_LINUX_NOT_ANDROID || SI_NETBSD || SI_FREEBSD)
 #define SANITIZER_INTERCEPT_PACCEPT SI_NETBSD
-#define SANITIZER_INTERCEPT_MODF (SI_POSIX && SI_NOT_AIX)
+#define SANITIZER_INTERCEPT_MODF SI_POSIX
 #define SANITIZER_INTERCEPT_RECVMSG SI_POSIX
 #define SANITIZER_INTERCEPT_SENDMSG SI_POSIX
 #define SANITIZER_INTERCEPT_RECVMMSG SI_LINUX
@@ -338,9 +328,8 @@ SANITIZER_WEAK_IMPORT void *aligned_alloc(__sanitizer::usize __alignment,
 #define SANITIZER_INTERCEPT___WCSXFRM_L SI_LINUX
 #define SANITIZER_INTERCEPT_WCSNRTOMBS \
   (SI_FREEBSD || SI_NETBSD || SI_MAC || SI_LINUX_NOT_ANDROID || SI_SOLARIS)
-#define SANITIZER_INTERCEPT_WCRTOMB                                           \
-  (SI_FREEBSD || SI_NETBSD || SI_MAC || SI_LINUX_NOT_ANDROID || SI_SOLARIS || \
-   !SI_NOT_AIX)
+#define SANITIZER_INTERCEPT_WCRTOMB \
+  (SI_FREEBSD || SI_NETBSD || SI_MAC || SI_LINUX_NOT_ANDROID || SI_SOLARIS)
 #define SANITIZER_INTERCEPT_WCTOMB \
   (SI_FREEBSD || SI_NETBSD || SI_MAC || SI_LINUX_NOT_ANDROID || SI_SOLARIS)
 #define SANITIZER_INTERCEPT_TCGETATTR SI_LINUX_NOT_ANDROID || SI_SOLARIS
@@ -380,8 +369,7 @@ SANITIZER_WEAK_IMPORT void *aligned_alloc(__sanitizer::usize __alignment,
 #define SANITIZER_INTERCEPT_GETMNTENT_R SI_LINUX_NOT_ANDROID
 #define SANITIZER_INTERCEPT_STATFS \
   (SI_FREEBSD || SI_MAC || SI_LINUX_NOT_ANDROID || SI_SOLARIS)
-#define SANITIZER_INTERCEPT_STATFS64 \
-  ((SI_GLIBC || !SI_NOT_AIX) && SANITIZER_HAS_STATFS64)
+#define SANITIZER_INTERCEPT_STATFS64 SI_GLIBC && SANITIZER_HAS_STATFS64
 #define SANITIZER_INTERCEPT_STATVFS \
   (SI_FREEBSD || SI_NETBSD || SI_LINUX_NOT_ANDROID)
 #define SANITIZER_INTERCEPT_STATVFS64 SI_GLIBC
@@ -430,10 +418,10 @@ SANITIZER_WEAK_IMPORT void *aligned_alloc(__sanitizer::usize __alignment,
 #define SANITIZER_INTERCEPT_TTYNAME_R SI_POSIX
 #define SANITIZER_INTERCEPT_TEMPNAM SI_POSIX
 #define SANITIZER_INTERCEPT_SINCOS SI_LINUX || SI_SOLARIS
-#define SANITIZER_INTERCEPT_REMQUO (SI_POSIX && SI_NOT_AIX)
-#define SANITIZER_INTERCEPT_REMQUOL (SI_POSIX && !SI_NETBSD && SI_NOT_AIX)
-#define SANITIZER_INTERCEPT_LGAMMA (SI_POSIX && SI_NOT_AIX)
-#define SANITIZER_INTERCEPT_LGAMMAL (SI_POSIX && !SI_NETBSD && SI_NOT_AIX)
+#define SANITIZER_INTERCEPT_REMQUO SI_POSIX
+#define SANITIZER_INTERCEPT_REMQUOL (SI_POSIX && !SI_NETBSD)
+#define SANITIZER_INTERCEPT_LGAMMA SI_POSIX
+#define SANITIZER_INTERCEPT_LGAMMAL (SI_POSIX && !SI_NETBSD)
 #define SANITIZER_INTERCEPT_LGAMMA_R (SI_FREEBSD || SI_LINUX || SI_SOLARIS)
 #define SANITIZER_INTERCEPT_LGAMMAL_R SI_LINUX_NOT_ANDROID || SI_SOLARIS
 #define SANITIZER_INTERCEPT_DRAND48_R SI_GLIBC
@@ -516,13 +504,11 @@ SANITIZER_WEAK_IMPORT void *aligned_alloc(__sanitizer::usize __alignment,
 #define SANITIZER_INTERCEPT_EVENTFD_READ_WRITE (SI_LINUX || SI_FREEBSD)
 
 #define SI_STAT_LINUX (SI_LINUX && __GLIBC_PREREQ(2, 33))
-#define SANITIZER_INTERCEPT_STAT                                    \
-  (SI_FREEBSD || SI_MAC || SI_ANDROID || SI_NETBSD || SI_SOLARIS || \
-   SI_STAT_LINUX || !SI_NOT_AIX)
-#define SANITIZER_INTERCEPT_STAT64 \
-  ((SI_STAT_LINUX || !SI_NOT_AIX) && SANITIZER_HAS_STAT64)
-#define SANITIZER_INTERCEPT_LSTAT \
-  (SI_NETBSD || SI_FREEBSD || SI_STAT_LINUX || !SI_NOT_AIX)
+#define SANITIZER_INTERCEPT_STAT                                        \
+  (SI_FREEBSD || SI_MAC || SI_ANDROID || SI_NETBSD || SI_SOLARIS ||     \
+   SI_STAT_LINUX)
+#define SANITIZER_INTERCEPT_STAT64 SI_STAT_LINUX && SANITIZER_HAS_STAT64
+#define SANITIZER_INTERCEPT_LSTAT (SI_NETBSD || SI_FREEBSD || SI_STAT_LINUX)
 #define SANITIZER_INTERCEPT___XSTAT \
   ((!SANITIZER_INTERCEPT_STAT && SI_POSIX) || SI_STAT_LINUX)
 #define SANITIZER_INTERCEPT___XSTAT64 SI_GLIBC
@@ -591,7 +577,7 @@ SANITIZER_WEAK_IMPORT void *aligned_alloc(__sanitizer::usize __alignment,
 #define SANITIZER_INTERCEPT_PROTOENT_R SI_GLIBC
 #define SANITIZER_INTERCEPT_NETENT (SI_LINUX || SI_NETBSD || SI_FREEBSD)
 #define SANITIZER_INTERCEPT_SETVBUF \
-  (SI_NETBSD || SI_FREEBSD || SI_LINUX || SI_MAC || !SI_NOT_AIX)
+  (SI_NETBSD || SI_FREEBSD || SI_LINUX || SI_MAC)
 #define SANITIZER_INTERCEPT_GETMNTINFO (SI_NETBSD || SI_FREEBSD || SI_MAC)
 #define SANITIZER_INTERCEPT_MI_VECTOR_HASH SI_NETBSD
 #define SANITIZER_INTERCEPT_GETVFSSTAT SI_NETBSD
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_redefine_builtins.h b/compiler-rt/lib/sanitizer_common/sanitizer_redefine_builtins.h
index bda0f04687693..41e0613d6fc13 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_redefine_builtins.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_redefine_builtins.h
@@ -15,7 +15,7 @@
 #    define SANITIZER_REDEFINE_BUILTINS_H
 
 // The asm hack only works with GCC and Clang.
-#    if !defined(_WIN32) && !defined(_AIX)
+#    if !defined(_WIN32)
 
 asm(R"(
     .set memcpy, __sanitizer_internal_memcpy

>From 0935ed2cdda2ec08bbf53d65e9819110d954241c Mon Sep 17 00:00:00 2001
From: Jake Egan <jake.egan at ibm.com>
Date: Mon, 5 May 2025 19:46:09 -0400
Subject: [PATCH 14/15] Use proper naming convention

---
 compiler-rt/lib/asan/asan_interceptors.cpp | 10 +++++-----
 compiler-rt/lib/asan/asan_interceptors.h   |  8 ++++----
 2 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/compiler-rt/lib/asan/asan_interceptors.cpp b/compiler-rt/lib/asan/asan_interceptors.cpp
index 7e43cc0baff47..b6510e76766d4 100644
--- a/compiler-rt/lib/asan/asan_interceptors.cpp
+++ b/compiler-rt/lib/asan/asan_interceptors.cpp
@@ -56,7 +56,7 @@ namespace __asan {
 #  define ASAN_READ_STRING(ctx, s, n) \
     ASAN_READ_STRING_OF_LEN((ctx), (s), internal_strlen(s), (n))
 
-#  if SANITIZER_INTERCEPT_STRCAT || SANITIZER_INTERCEPT_STRCPY
+#  if ASAN_INTERCEPT_STRCAT || ASAN_INTERCEPT_STRCPY
 static inline uptr MaybeRealStrnlen(const char *s, uptr maxlen) {
 #if SANITIZER_INTERCEPT_STRNLEN
   if (REAL(strnlen)) {
@@ -517,7 +517,7 @@ DEFINE_REAL(char*, index, const char *string, int c)
 
 // For both strcat() and strncat() we need to check the validity of |to|
 // argument irrespective of the |from| length.
-#  if SANITIZER_INTERCEPT_STRCAT
+#  if ASAN_INTERCEPT_STRCAT
   INTERCEPTOR(char *, strcat, char *to, const char *from) {
     void *ctx;
     ASAN_INTERCEPTOR_ENTER(ctx, strcat);
@@ -559,7 +559,7 @@ INTERCEPTOR(char*, strncat, char *to, const char *from, usize size) {
 }
 #  endif
 
-#  if SANITIZER_INTERCEPT_STRCPY
+#  if ASAN_INTERCEPT_STRCPY
 INTERCEPTOR(char *, strcpy, char *to, const char *from) {
   void *ctx;
   ASAN_INTERCEPTOR_ENTER(ctx, strcpy);
@@ -837,11 +837,11 @@ void InitializeAsanInterceptors() {
   InitializeSignalInterceptors();
 
   // Intercept str* functions.
-#  if SANITIZER_INTERCEPT_STRCAT
+#  if ASAN_INTERCEPT_STRCAT
   ASAN_INTERCEPT_FUNC(strcat);
   ASAN_INTERCEPT_FUNC(strncat);
 #  endif
-#  if SANITIZER_INTERCEPT_STRCPY
+#  if ASAN_INTERCEPT_STRCPY
   ASAN_INTERCEPT_FUNC(strcpy);
   ASAN_INTERCEPT_FUNC(strncpy);
 #  endif
diff --git a/compiler-rt/lib/asan/asan_interceptors.h b/compiler-rt/lib/asan/asan_interceptors.h
index bc647419e0050..5c4854008a04e 100644
--- a/compiler-rt/lib/asan/asan_interceptors.h
+++ b/compiler-rt/lib/asan/asan_interceptors.h
@@ -127,11 +127,11 @@ void InitializePlatformInterceptors();
 #  endif
 
 #  if SANITIZER_AIX
-#    define SANITIZER_INTERCEPT_STRCAT 0
-#    define SANITIZER_INTERCEPT_STRCPY 0
+#    define ASAN_INTERCEPT_STRCAT 0
+#    define ASAN_INTERCEPT_STRCPY 0
 #  else
-#    define SANITIZER_INTERCEPT_STRCAT 1
-#    define SANITIZER_INTERCEPT_STRCPY 1
+#    define ASAN_INTERCEPT_STRCAT 1
+#    define ASAN_INTERCEPT_STRCPY 1
 #  endif
 
 #  if SANITIZER_LINUX &&                                                \

>From 30d1f126c169e8e7a7a098d723377563d9324bb2 Mon Sep 17 00:00:00 2001
From: Jake Egan <jake.egan at ibm.com>
Date: Mon, 5 May 2025 19:47:23 -0400
Subject: [PATCH 15/15] Move return

---
 compiler-rt/lib/asan/asan_interceptors_memintrinsics.cpp | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/compiler-rt/lib/asan/asan_interceptors_memintrinsics.cpp b/compiler-rt/lib/asan/asan_interceptors_memintrinsics.cpp
index 008622c415fa6..5bf676e9bab00 100644
--- a/compiler-rt/lib/asan/asan_interceptors_memintrinsics.cpp
+++ b/compiler-rt/lib/asan/asan_interceptors_memintrinsics.cpp
@@ -24,10 +24,9 @@ using namespace __asan;
 
 // AIX does not intercept memcpy, so we have to use internal_memcpy.
 #if !SANITIZER_AIX
-#  define ASAN_MEMCPY_RETURN(to, from, size) return REAL(memcpy)(to, from, size)
+#  define ASAN_MEMCPY_RETURN(to, from, size) REAL(memcpy)(to, from, size)
 #else
-#  define ASAN_MEMCPY_RETURN(to, from, size) \
-    return internal_memcpy(to, from, size)
+#  define ASAN_MEMCPY_RETURN(to, from, size) internal_memcpy(to, from, size)
 #endif
 
 // memcpy is called during __asan_init() from the internals of printf(...).
@@ -44,7 +43,7 @@ using namespace __asan;
     } else if (UNLIKELY(!AsanInited())) {                     \
       return internal_memcpy(to, from, size);                 \
     }                                                         \
-    ASAN_MEMCPY_RETURN(to, from, size);                       \
+    return ASAN_MEMCPY_RETURN(to, from, size);                \
   } while (0)
 
 // memset is called inside Printf.



More information about the llvm-commits mailing list