diff --git a/compiler-rt/lib/msan/msan.h b/compiler-rt/lib/msan/msan.h --- a/compiler-rt/lib/msan/msan.h +++ b/compiler-rt/lib/msan/msan.h @@ -382,21 +382,25 @@ } // namespace __msan -#define MSAN_MALLOC_HOOK(ptr, size) \ - do { \ - if (&__sanitizer_malloc_hook) { \ - UnpoisonParam(2); \ - __sanitizer_malloc_hook(ptr, size); \ - } \ - RunMallocHooks(ptr, size); \ +#define MSAN_MALLOC_HOOK(ptr, size) \ + do { \ + if (!IsInSymbolizer()) { \ + if (&__sanitizer_malloc_hook) { \ + UnpoisonParam(2); \ + __sanitizer_malloc_hook(ptr, size); \ + } \ + RunMallocHooks(ptr, size); \ + } \ } while (false) -#define MSAN_FREE_HOOK(ptr) \ - do { \ - if (&__sanitizer_free_hook) { \ - UnpoisonParam(1); \ - __sanitizer_free_hook(ptr); \ - } \ - RunFreeHooks(ptr); \ +#define MSAN_FREE_HOOK(ptr) \ + do { \ + if (!IsInSymbolizer()) { \ + if (&__sanitizer_free_hook) { \ + UnpoisonParam(1); \ + __sanitizer_free_hook(ptr); \ + } \ + RunFreeHooks(ptr); \ + } \ } while (false) #endif // MSAN_H diff --git a/compiler-rt/test/msan/Linux/malloc_hooks.cpp b/compiler-rt/test/msan/Linux/malloc_hooks.cpp new file mode 100644 --- /dev/null +++ b/compiler-rt/test/msan/Linux/malloc_hooks.cpp @@ -0,0 +1,33 @@ +// RUN: %clangxx_msan -O0 -g %s -o %t && %run %t + +#include +#include +#include +#include + +int hooks; +extern "C" { + +void __sanitizer_malloc_hook(const volatile void *ptr, size_t sz) { ++hooks; } + +void __sanitizer_free_hook(const volatile void *ptr) { ++hooks; } + +} // extern "C" + +void MallocHook(const volatile void *ptr, size_t sz) { ++hooks; } +void FreeHook(const volatile void *ptr) { ++hooks; } + +int main() { + int before; + + before = hooks; + __sanitizer_print_stack_trace(); + assert(before == hooks); + + __sanitizer_install_malloc_and_free_hooks(MallocHook, FreeHook); + before = hooks; + __sanitizer_print_stack_trace(); + assert(before == hooks); + + return 0; +}