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>
This commit is contained in:
David Benjamin 2016-03-27 11:11:19 -04:00 committed by Adam Langley
parent 1b0bd28275
commit 7b9bbd9639

View File

@ -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 char failure_enabled = 0, break_on_fail = 0;
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 @@ void *malloc(size_t size) {
return NULL;
}
return __libc_malloc(size);
return REAL_MALLOC(size);
}
void *calloc(size_t num_elems, size_t size) {
@ -133,7 +143,7 @@ void *calloc(size_t num_elems, size_t size) {
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 @@ void *realloc(void *ptr, size_t size) {
return NULL;
}
return __libc_realloc(ptr, size);
return REAL_REALLOC(ptr, size);
}
void free(void *ptr) {
REAL_FREE(ptr);
}
} // extern "C"