diff options
author | Alexey Samsonov <samsonov@google.com> | 2012-09-27 09:50:19 +0000 |
---|---|---|
committer | Alexey Samsonov <samsonov@google.com> | 2012-09-27 09:50:19 +0000 |
commit | 7eff311e3e969ae084aadba7d7812591e34d08ab (patch) | |
tree | 9134f4d1586092d9cb152b4d76a6b7b7eeb74957 /lib/tsan/rtl | |
parent | ce31aa700275ab17aa42db0d1d175abddc89eb2e (diff) | |
download | compiler-rt-7eff311e3e969ae084aadba7d7812591e34d08ab.tar.gz |
[TSan] move replacement for new/delete back into tsan_interceptors
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@164764 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/tsan/rtl')
-rw-r--r-- | lib/tsan/rtl/CMakeLists.txt | 1 | ||||
-rw-r--r-- | lib/tsan/rtl/Makefile.old | 2 | ||||
-rw-r--r-- | lib/tsan/rtl/tsan_interceptors.cc | 48 | ||||
-rw-r--r-- | lib/tsan/rtl/tsan_new_delete.cc | 70 | ||||
-rw-r--r-- | lib/tsan/rtl/tsan_rtl.h | 1 |
5 files changed, 46 insertions, 76 deletions
diff --git a/lib/tsan/rtl/CMakeLists.txt b/lib/tsan/rtl/CMakeLists.txt index 4131a8586..2538f99b9 100644 --- a/lib/tsan/rtl/CMakeLists.txt +++ b/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/lib/tsan/rtl/Makefile.old b/lib/tsan/rtl/Makefile.old index d674a2ecd..89ce83221 100644 --- a/lib/tsan/rtl/Makefile.old +++ b/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/lib/tsan/rtl/tsan_interceptors.cc b/lib/tsan/rtl/tsan_interceptors.cc index 5f4375b8b..03272993e 100644 --- a/lib/tsan/rtl/tsan_interceptors.cc +++ b/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/lib/tsan/rtl/tsan_new_delete.cc b/lib/tsan/rtl/tsan_new_delete.cc deleted file mode 100644 index 0b418aad4..000000000 --- a/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 <stddef.h> -#include <new> - -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/lib/tsan/rtl/tsan_rtl.h b/lib/tsan/rtl/tsan_rtl.h index af9597f33..a56025ef4 100644 --- a/lib/tsan/rtl/tsan_rtl.h +++ b/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, |