[TSan] move replacement for new/delete back into tsan_interceptors

llvm-svn: 164764
This commit is contained in:
Alexey Samsonov 2012-09-27 09:50:19 +00:00
parent 7b4cd228aa
commit b6879ce94c
5 changed files with 46 additions and 76 deletions

View File

@ -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

View File

@ -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)

View File

@ -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);

View File

@ -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);
}

View File

@ -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,