From b6879ce94cd24e4d76e60ad52c648edb5af221a5 Mon Sep 17 00:00:00 2001 From: Alexey Samsonov Date: Thu, 27 Sep 2012 09:50:19 +0000 Subject: [PATCH] [TSan] move replacement for new/delete back into tsan_interceptors llvm-svn: 164764 --- compiler-rt/lib/tsan/rtl/CMakeLists.txt | 1 - compiler-rt/lib/tsan/rtl/Makefile.old | 2 - compiler-rt/lib/tsan/rtl/tsan_interceptors.cc | 48 +++++++++++++++++- compiler-rt/lib/tsan/rtl/tsan_new_delete.cc | 70 --------------------------- compiler-rt/lib/tsan/rtl/tsan_rtl.h | 1 - 5 files changed, 46 insertions(+), 76 deletions(-) delete mode 100644 compiler-rt/lib/tsan/rtl/tsan_new_delete.cc diff --git a/compiler-rt/lib/tsan/rtl/CMakeLists.txt b/compiler-rt/lib/tsan/rtl/CMakeLists.txt index 4131a85..2538f99 100644 --- a/compiler-rt/lib/tsan/rtl/CMakeLists.txt +++ b/compiler-rt/lib/tsan/rtl/CMakeLists.txt @@ -8,7 +8,6 @@ set(TSAN_SOURCES tsan_md5.cc tsan_mman.cc tsan_mutex.cc - tsan_new_delete.cc tsan_printf.cc tsan_report.cc tsan_rtl.cc diff --git a/compiler-rt/lib/tsan/rtl/Makefile.old b/compiler-rt/lib/tsan/rtl/Makefile.old index d674a2e..89ce832 100644 --- a/compiler-rt/lib/tsan/rtl/Makefile.old +++ b/compiler-rt/lib/tsan/rtl/Makefile.old @@ -42,8 +42,6 @@ LIBTSAN_OBJ=$(patsubst %.cc,%.o,$(LIBTSAN_SRC)) \ %_linux.o: %_linux.cc Makefile.old $(LIBTSAN_HEADERS) $(CXX) $(CXXFLAGS) $(INCLUDES) -c $< -%_new_delete.o: %_new_delete.cc Makefile.old $(LIBTSAN_HEADERS) - $(CXX) $(CXXFLAGS) $(INCLUDES) -c $< %.o: %.cc Makefile.old $(LIBTSAN_HEADERS) $(CXX) $(CXXFLAGS) $(INCLUDES) $(NO_SYSROOT) -c $< %.o: $(INTERCEPTION)/%.cc Makefile.old $(LIBTSAN_HEADERS) diff --git a/compiler-rt/lib/tsan/rtl/tsan_interceptors.cc b/compiler-rt/lib/tsan/rtl/tsan_interceptors.cc index 5f4375b..0327299 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_interceptors.cc +++ b/compiler-rt/lib/tsan/rtl/tsan_interceptors.cc @@ -14,6 +14,7 @@ #include "sanitizer_common/sanitizer_atomic.h" #include "sanitizer_common/sanitizer_libc.h" #include "sanitizer_common/sanitizer_placement_new.h" +#include "sanitizer_common/sanitizer_stacktrace.h" #include "tsan_interceptors.h" #include "tsan_interface.h" #include "tsan_platform.h" @@ -99,6 +100,10 @@ const sighandler_t SIG_ERR = (sighandler_t)-1; const int SA_SIGINFO = 4; const int SIG_SETMASK = 2; +namespace std { +struct nothrow_t {}; +} // namespace std + static sigaction_t sigactions[kSigCount]; namespace __tsan { @@ -330,6 +335,47 @@ TSAN_INTERCEPTOR(void, cfree, void *p) { user_free(thr, pc, p); } +#define OPERATOR_NEW_BODY(mangled_name) \ + void *p = 0; \ + { \ + SCOPED_INTERCEPTOR_RAW(mangled_name, size); \ + p = user_alloc(thr, pc, size); \ + } \ + invoke_malloc_hook(p, size); \ + return p; + +void *operator new(__sanitizer::uptr size) { + OPERATOR_NEW_BODY(_Znwm); +} +void *operator new[](__sanitizer::uptr size) { + OPERATOR_NEW_BODY(_Znam); +} +void *operator new(__sanitizer::uptr size, std::nothrow_t const&) { + OPERATOR_NEW_BODY(_ZnwmRKSt9nothrow_t); +} +void *operator new[](__sanitizer::uptr size, std::nothrow_t const&) { + OPERATOR_NEW_BODY(_ZnamRKSt9nothrow_t); +} + +#define OPERATOR_DELETE_BODY(mangled_name) \ + if (ptr == 0) return; \ + invoke_free_hook(ptr); \ + SCOPED_INTERCEPTOR_RAW(mangled_name, ptr); \ + user_free(thr, pc, ptr); + +void operator delete(void *ptr) { + OPERATOR_DELETE_BODY(_ZdlPv); +} +void operator delete[](void *ptr) { + OPERATOR_DELETE_BODY(_ZdlPvRKSt9nothrow_t); +} +void operator delete(void *ptr, std::nothrow_t const&) { + OPERATOR_DELETE_BODY(_ZdaPv); +} +void operator delete[](void *ptr, std::nothrow_t const&) { + OPERATOR_DELETE_BODY(_ZdaPvRKSt9nothrow_t); +} + TSAN_INTERCEPTOR(uptr, strlen, const char *s) { SCOPED_TSAN_INTERCEPTOR(strlen, s); uptr len = internal_strlen(s); @@ -1343,8 +1389,6 @@ void InitializeInterceptors() { TSAN_INTERCEPT(pvalloc); TSAN_INTERCEPT(posix_memalign); - ReplaceOperatorsNewAndDelete(); - TSAN_INTERCEPT(strlen); TSAN_INTERCEPT(memset); TSAN_INTERCEPT(memcpy); diff --git a/compiler-rt/lib/tsan/rtl/tsan_new_delete.cc b/compiler-rt/lib/tsan/rtl/tsan_new_delete.cc deleted file mode 100644 index 0b418aa..0000000 --- a/compiler-rt/lib/tsan/rtl/tsan_new_delete.cc +++ /dev/null @@ -1,70 +0,0 @@ -//===-- tsan_new_delete.cc ------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// -// This file is a part of ThreadSanitizer (TSan), a race detector. -// -// Interceptors for operators new and delete. -//===----------------------------------------------------------------------===// - -#include "tsan_interceptors.h" -#include "tsan_mman.h" -#include "tsan_rtl.h" - -#include -#include - -namespace __tsan { -// This function is a no-op. We need it to make sure that object file -// with our replacements will actually be loaded from static TSan -// run-time library at link-time. -void ReplaceOperatorsNewAndDelete() { } -} - -using namespace __tsan; // NOLINT - -#define OPERATOR_NEW_BODY(mangled_name) \ - void *p = 0; \ - { \ - SCOPED_INTERCEPTOR_RAW(mangled_name, size); \ - p = user_alloc(thr, pc, size); \ - } \ - invoke_malloc_hook(p, size); \ - return p; - -void *operator new(size_t size) throw(std::bad_alloc) { - OPERATOR_NEW_BODY(_Znwm); -} -void *operator new[](size_t size) throw(std::bad_alloc) { - OPERATOR_NEW_BODY(_Znam); -} -void *operator new(size_t size, std::nothrow_t const&) throw() { - OPERATOR_NEW_BODY(_ZnwmRKSt9nothrow_t); -} -void *operator new[](size_t size, std::nothrow_t const&) throw() { - OPERATOR_NEW_BODY(_ZnamRKSt9nothrow_t); -} - -#define OPERATOR_DELETE_BODY(mangled_name) \ - if (ptr == 0) return; \ - invoke_free_hook(ptr); \ - SCOPED_INTERCEPTOR_RAW(mangled_name, ptr); \ - user_free(thr, pc, ptr); - -void operator delete(void *ptr) throw() { - OPERATOR_DELETE_BODY(_ZdlPv); -} -void operator delete[](void *ptr) throw() { - OPERATOR_DELETE_BODY(_ZdlPvRKSt9nothrow_t); -} -void operator delete(void *ptr, std::nothrow_t const&) throw() { - OPERATOR_DELETE_BODY(_ZdaPv); -} -void operator delete[](void *ptr, std::nothrow_t const&) throw() { - OPERATOR_DELETE_BODY(_ZdaPvRKSt9nothrow_t); -} diff --git a/compiler-rt/lib/tsan/rtl/tsan_rtl.h b/compiler-rt/lib/tsan/rtl/tsan_rtl.h index af9597f..a56025e 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_rtl.h +++ b/compiler-rt/lib/tsan/rtl/tsan_rtl.h @@ -436,7 +436,6 @@ void ALWAYS_INLINE INLINE StatInc(ThreadState *thr, StatType typ, u64 n = 1) { void InitializeShadowMemory(); void InitializeInterceptors(); void InitializeDynamicAnnotations(); -void ReplaceOperatorsNewAndDelete(); void ReportRace(ThreadState *thr); bool OutputReport(const ScopedReport &srep, -- 2.7.4