Get the malloc tests working under ASan.
They just need a different name for the real malloc implementations.
Change-Id: Iee1aac1133113d628fd3f9f1ed0335d66c6def24
Reviewed-on: https://boringssl-review.googlesource.com/11400
Commit-Queue: David Benjamin <davidben@google.com>
Reviewed-by: Adam Langley <agl@google.com>
diff --git a/crypto/test/malloc.cc b/crypto/test/malloc.cc
index 898f2a7..47ee6da 100644
--- a/crypto/test/malloc.cc
+++ b/crypto/test/malloc.cc
@@ -26,13 +26,9 @@
// This file isn't built on ARM or Aarch64 because we link statically in those
// builds and trying to override malloc in a static link doesn't work. It also
-// requires glibc. It's also disabled on ASan builds as this interferes with
-// ASan's malloc interceptor.
-//
-// TODO(davidben): See if this and ASan's and MSan's interceptors can be made to
-// coexist.
+// requires glibc.
#if defined(__linux__) && defined(OPENSSL_GLIBC) && !defined(OPENSSL_ARM) && \
- !defined(OPENSSL_AARCH64) && !defined(OPENSSL_ASAN)
+ !defined(OPENSSL_AARCH64)
#include <errno.h>
#include <signal.h>
@@ -58,10 +54,24 @@
static int in_call = 0;
extern "C" {
+
+#if defined(OPENSSL_ASAN)
+#define REAL_MALLOC __interceptor_malloc
+#define REAL_CALLOC __interceptor_calloc
+#define REAL_REALLOC __interceptor_realloc
+#define REAL_FREE __interceptor_free
+#else
+#define REAL_MALLOC __libc_malloc
+#define REAL_CALLOC __libc_calloc
+#define REAL_REALLOC __libc_realloc
+#define REAL_FREE __libc_free
+#endif
+
/* These are other names for the standard allocation functions. */
-extern void *__libc_malloc(size_t size);
-extern void *__libc_calloc(size_t num_elems, size_t size);
-extern void *__libc_realloc(void *ptr, size_t size);
+extern void *REAL_MALLOC(size_t size);
+extern void *REAL_CALLOC(size_t num_elems, size_t size);
+extern void *REAL_REALLOC(void *ptr, size_t size);
+extern void REAL_FREE(void *ptr);
}
static void exit_handler(void) {
@@ -124,7 +134,7 @@
return NULL;
}
- return __libc_malloc(size);
+ return REAL_MALLOC(size);
}
void *calloc(size_t num_elems, size_t size) {
@@ -133,7 +143,7 @@
return NULL;
}
- return __libc_calloc(num_elems, size);
+ return REAL_CALLOC(num_elems, size);
}
void *realloc(void *ptr, size_t size) {
@@ -142,7 +152,11 @@
return NULL;
}
- return __libc_realloc(ptr, size);
+ return REAL_REALLOC(ptr, size);
+}
+
+void free(void *ptr) {
+ REAL_FREE(ptr);
}
} // extern "C"