[compiler-rt] [asan] Adjust interception compatibility for AIX (PR #131870)

Hubert Tong via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 18 22:16:35 PST 2025


================
@@ -17,16 +17,60 @@
 #if SANITIZER_AIX
 
 #  include <dlfcn.h>  // for dlsym()
+#  include <stddef.h>  // for size_t
+
+#  if SANITIZER_WORDSIZE == 64
+#    define STRCPY_STR "___strcpy64"
+#    define MEMCPY_STR "___memcpy64"
+#    define MEMMOVE_STR "___memmove64"
+#  else
+#    define STRCPY_STR "___strcpy"
+#    define MEMCPY_STR "___memcpy"
+#    define MEMMOVE_STR "___memmove"
+#  endif
 
 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.
+char* ___strcpy(char*, const char*) __asm__(STRCPY_STR);
+char* ___memcpy(char*, const char*, size_t) __asm__(MEMCPY_STR);
+char* ___memmove(char*, const char*, size_t) __asm__(MEMMOVE_STR);
+
+char* real_strcpy_wrapper(char* s1, const char* s2) {
+  return (char*)___strcpy(s1, s2);
+}
+
+char* real_memcpy_wrapper(char* s1, const char* s2, size_t n) {
+  return (char*)___memcpy(s1, s2, n);
+}
+
+char* real_memmove_wrapper(char* s1, const char* s2, size_t n) {
+  return (char*)___memmove(s1, s2, n);
+}
----------------
hubert-reinterpretcast wrote:

These functions should be `static`.
```suggestion
static char* real_strcpy_wrapper(char* s1, const char* s2) {
  return (char*)___strcpy(s1, s2);
}

static char* real_memcpy_wrapper(char* s1, const char* s2, size_t n) {
  return (char*)___memcpy(s1, s2, n);
}

static char* real_memmove_wrapper(char* s1, const char* s2, size_t n) {
  return (char*)___memmove(s1, s2, n);
}
```

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


More information about the llvm-commits mailing list