Index: compiler-rt/include/sanitizer/allocator_interface.h =================================================================== --- compiler-rt/include/sanitizer/allocator_interface.h +++ compiler-rt/include/sanitizer/allocator_interface.h @@ -82,7 +82,6 @@ Currently available with ASan only. */ void __sanitizer_purge_allocator(void); - #ifdef __cplusplus } // extern "C" #endif Index: compiler-rt/include/sanitizer/hwasan_interface.h =================================================================== --- compiler-rt/include/sanitizer/hwasan_interface.h +++ compiler-rt/include/sanitizer/hwasan_interface.h @@ -26,6 +26,21 @@ void __hwasan_enable_allocator_tagging(void); void __hwasan_disable_allocator_tagging(void); + int __sanitizer_posix_memalign(void **memptr, size_t alignment, size_t size); + void * __sanitizer_memalign(size_t alignment, size_t size); + void * __sanitizer_aligned_alloc(size_t alignment, size_t size); + void * __sanitizer___libc_memalign(size_t alignment, size_t size); + void * __sanitizer_valloc(size_t size); + void * __sanitizer_pvalloc(size_t size); + void __sanitizer_free(void *ptr); + void __sanitizer_cfree(void *ptr); + size_t __sanitizer_malloc_usable_size(const void *ptr); + struct mallinfo __sanitizer_mallinfo(); + int __sanitizer_mallopt(int cmd, int value); + void __sanitizer_malloc_stats(void); + void * __sanitizer_calloc(size_t nmemb, size_t size); + void * __sanitizer_realloc(void *ptr, size_t size); + void * __sanitizer_malloc(size_t size); #ifdef __cplusplus } // extern "C" #endif Index: compiler-rt/lib/hwasan/hwasan_interceptors.cc =================================================================== --- compiler-rt/lib/hwasan/hwasan_interceptors.cc +++ compiler-rt/lib/hwasan/hwasan_interceptors.cc @@ -128,6 +128,25 @@ CHECK_UNPOISONED((x), \ common_flags()->strict_string_checks ? (len) + 1 : (n) ) +#define SANITIZER_ALIAS(RET, FN, ARGS...) \ + extern "C" SANITIZER_INTERFACE_ATTRIBUTE RET __sanitizer_##FN(ARGS) \ + ALIAS(WRAPPER_NAME(FN)); + +SANITIZER_ALIAS(int, posix_memalign, void **memptr, SIZE_T alignment, SIZE_T size); +SANITIZER_ALIAS(void *, memalign, SIZE_T alignment, SIZE_T size); +SANITIZER_ALIAS(void *, aligned_alloc, SIZE_T alignment, SIZE_T size); +SANITIZER_ALIAS(void *, __libc_memalign, SIZE_T alignment, SIZE_T size); +SANITIZER_ALIAS(void *, valloc, SIZE_T size); +SANITIZER_ALIAS(void *, pvalloc, SIZE_T size); +SANITIZER_ALIAS(void, free, void *ptr); +SANITIZER_ALIAS(void, cfree, void *ptr); +SANITIZER_ALIAS(uptr, malloc_usable_size, const void *ptr); +SANITIZER_ALIAS(void, mallinfo, __sanitizer_struct_mallinfo *sret); +SANITIZER_ALIAS(int, mallopt, int cmd, int value); +SANITIZER_ALIAS(void, malloc_stats, void); +SANITIZER_ALIAS(void *, calloc, SIZE_T nmemb, SIZE_T size); +SANITIZER_ALIAS(void *, realloc, void *ptr, SIZE_T size); +SANITIZER_ALIAS(void *, malloc, SIZE_T size); INTERCEPTOR(int, posix_memalign, void **memptr, SIZE_T alignment, SIZE_T size) { GET_MALLOC_STACK_TRACE; @@ -200,11 +219,11 @@ // temporary! The following is equivalent on all supported platforms but // aarch64 (which uses a different register for sret value). We have a test // to confirm that. -INTERCEPTOR(void, mallinfo, __sanitizer_mallinfo *sret) { +INTERCEPTOR(void, mallinfo, __sanitizer_struct_mallinfo *sret) { #ifdef __aarch64__ uptr r8; asm volatile("mov %0,x8" : "=r" (r8)); - sret = reinterpret_cast<__sanitizer_mallinfo*>(r8); + sret = reinterpret_cast<__sanitizer_struct_mallinfo*>(r8); #endif REAL(memset)(sret, 0, sizeof(*sret)); } Index: compiler-rt/lib/msan/msan_interceptors.cc =================================================================== --- compiler-rt/lib/msan/msan_interceptors.cc +++ compiler-rt/lib/msan/msan_interceptors.cc @@ -249,11 +249,11 @@ // temporary! The following is equivalent on all supported platforms but // aarch64 (which uses a different register for sret value). We have a test // to confirm that. -INTERCEPTOR(void, mallinfo, __sanitizer_mallinfo *sret) { +INTERCEPTOR(void, mallinfo, __sanitizer_struct_mallinfo *sret) { #ifdef __aarch64__ uptr r8; asm volatile("mov %0,x8" : "=r" (r8)); - sret = reinterpret_cast<__sanitizer_mallinfo*>(r8); + sret = reinterpret_cast<__sanitizer_struct_mallinfo*>(r8); #endif REAL(memset)(sret, 0, sizeof(*sret)); __msan_unpoison(sret, sizeof(*sret)); Index: compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h =================================================================== --- compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h +++ compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h @@ -187,13 +187,13 @@ #endif // SANITIZER_LINUX || SANITIZER_FREEBSD #if SANITIZER_ANDROID - struct __sanitizer_mallinfo { + struct __sanitizer_struct_mallinfo { uptr v[10]; }; #endif #if SANITIZER_LINUX && !SANITIZER_ANDROID - struct __sanitizer_mallinfo { + struct __sanitizer_struct_mallinfo { int v[10]; }; Index: compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cc =================================================================== --- compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cc +++ compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cc @@ -1206,7 +1206,7 @@ #endif #if SANITIZER_LINUX -COMPILER_CHECK(sizeof(__sanitizer_mallinfo) == sizeof(struct mallinfo)); +COMPILER_CHECK(sizeof(__sanitizer_struct_mallinfo) == sizeof(struct mallinfo)); #endif #if !SANITIZER_ANDROID Index: compiler-rt/test/hwasan/TestCases/sanitizer_malloc.cc =================================================================== --- /dev/null +++ compiler-rt/test/hwasan/TestCases/sanitizer_malloc.cc @@ -0,0 +1,29 @@ +// Test allocator aliases. +// +// RUN: %clangxx_hwasan -O0 %s -o %t && %run %t + +#include + +int main() { + void *volatile sink; + sink = (void *)&__sanitizer_posix_memalign; + sink = (void *)&__sanitizer_memalign; + sink = (void *)&__sanitizer_aligned_alloc; + sink = (void *)&__sanitizer___libc_memalign; + sink = (void *)&__sanitizer_valloc; + sink = (void *)&__sanitizer_pvalloc; + sink = (void *)&__sanitizer_free; + sink = (void *)&__sanitizer_cfree; + sink = (void *)&__sanitizer_malloc_usable_size; + sink = (void *)&__sanitizer_mallinfo; + sink = (void *)&__sanitizer_mallopt; + sink = (void *)&__sanitizer_malloc_stats; + sink = (void *)&__sanitizer_calloc; + sink = (void *)&__sanitizer_realloc; + sink = (void *)&__sanitizer_malloc; + + // sanity check + void *p = __sanitizer_malloc(100); + p = __sanitizer_realloc(p, 200); + __sanitizer_free(p); +}