diff --git a/compiler-rt/lib/tsan/rtl/CMakeLists.txt b/compiler-rt/lib/tsan/rtl/CMakeLists.txt index 4131a85868d0..2538f99b9b19 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 d674a2ecd22a..89ce8322123d 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 5f4375b8be68..03272993e0f7 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 0b418aad46a5..000000000000 --- 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 af9597f338a0..a56025ef48bd 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,