diff options
-rw-r--r-- | compiler-rt/lib/Makefile.mk | 1 | ||||
-rw-r--r-- | compiler-rt/lib/asan/Makefile.old | 71 | ||||
-rw-r--r-- | compiler-rt/lib/asan/asan_internal.h | 2 | ||||
-rw-r--r-- | compiler-rt/lib/asan/asan_rtl.cc | 2 | ||||
-rw-r--r-- | compiler-rt/lib/sanitizer_common/Makefile.mk | 22 | ||||
-rw-r--r-- | compiler-rt/lib/sanitizer_common/mini_libc.cc | 20 | ||||
-rw-r--r-- | compiler-rt/lib/sanitizer_common/mini_libc.h | 28 | ||||
-rw-r--r-- | compiler-rt/lib/tsan/Makefile.old | 2 | ||||
-rw-r--r-- | compiler-rt/lib/tsan/rtl/Makefile.old | 70 | ||||
-rw-r--r-- | compiler-rt/lib/tsan/rtl/tsan_rtl.cc | 3 | ||||
-rw-r--r-- | compiler-rt/make/platform/clang_darwin.mk | 3 | ||||
-rw-r--r-- | compiler-rt/make/platform/clang_linux.mk | 9 |
12 files changed, 131 insertions, 102 deletions
diff --git a/compiler-rt/lib/Makefile.mk b/compiler-rt/lib/Makefile.mk index e20d3c8be7a..791921a8006 100644 --- a/compiler-rt/lib/Makefile.mk +++ b/compiler-rt/lib/Makefile.mk @@ -17,6 +17,7 @@ SubDirs += i386 ppc x86_64 arm SubDirs += asan SubDirs += interception SubDirs += profile +SubDirs += sanitizer_common SubDirs += tsan # FIXME: We don't currently support building an atomic library, and as it must diff --git a/compiler-rt/lib/asan/Makefile.old b/compiler-rt/lib/asan/Makefile.old index 52872cba0bd..f954310783e 100644 --- a/compiler-rt/lib/asan/Makefile.old +++ b/compiler-rt/lib/asan/Makefile.old @@ -170,42 +170,24 @@ ifeq ($(ASAN_COMPILER), gcc) endif INTERCEPTION=../interception +MACH_OVERRIDE=$(INTERCEPTION)/mach_override +COMMON=../sanitizer_common -RTL_HDR=asan_allocator.h \ - asan_internal.h \ - asan_interceptors.h \ - asan_interface.h \ - asan_lock.h \ - asan_mapping.h \ - asan_procmaps.h \ - asan_stack.h \ - asan_stats.h \ - asan_thread.h \ - asan_thread_registry.h \ - $(INTERCEPTION)/interception.h \ - $(INTERCEPTION)/interception_linux.h \ - $(INTERCEPTION)/interception_mac.h \ - $(INTERCEPTION)/mach_override/mach_override.h - -LIBASAN_OBJ=$(BIN)/asan_rtl$(SUFF).o \ - $(BIN)/asan_allocator$(SUFF).o \ - $(BIN)/asan_globals$(SUFF).o \ - $(BIN)/asan_interceptors$(SUFF).o \ - $(BIN)/asan_linux$(SUFF).o \ - $(BIN)/asan_mac$(SUFF).o \ - $(BIN)/asan_malloc_linux$(SUFF).o \ - $(BIN)/asan_malloc_mac$(SUFF).o \ - $(BIN)/asan_new_delete$(SUFF).o \ - $(BIN)/asan_poisoning$(SUFF).o \ - $(BIN)/asan_posix$(SUFF).o \ - $(BIN)/asan_printf$(SUFF).o \ - $(BIN)/asan_stack$(SUFF).o \ - $(BIN)/asan_stats$(SUFF).o \ - $(BIN)/asan_thread$(SUFF).o \ - $(BIN)/asan_thread_registry$(SUFF).o \ - $(BIN)/interception/interception_linux$(SUFF).o \ - $(BIN)/interception/interception_mac$(SUFF).o \ - $(BIN)/interception/mach_override/mach_override$(SUFF).o +RTL_HDR=$(wildcard *.h) \ + $(wildcard $(INTERCEPTION)/*.h) \ + $(wildcard $(MACH_OVERRIDE)/*.h) \ + $(wildcard $(COMMON)/*.h) + +LIBTSAN_SRC=$(wildcard *.cc) +INTERCEPTION_SRC=$(wildcard $(INTERCEPTION)/*.cc) +MACH_OVERRIDE_SRC=$(wildcard $(MACH_OVERRIDE)/*.c) +COMMON_SRC=$(wildcard $(COMMON)/*.cc) + + +LIBASAN_OBJ=$(patsubst %.cc,$(BIN)/%$(SUFF).o,$(LIBTSAN_SRC)) \ + $(patsubst $(INTERCEPTION)/%.cc,$(BIN)/%$(SUFF).o,$(INTERCEPTION_SRC)) \ + $(patsubst $(COMMON)/%.cc,$(BIN)/%$(SUFF).o,$(COMMON_SRC)) \ + $(patsubst $(MACH_OVERRIDE)/%.c,$(BIN)/%$(SUFF).o,$(MACH_OVERRIDE_SRC)) GTEST_ROOT=third_party/googletest GTEST_INCLUDE=-I$(GTEST_ROOT)/include @@ -237,8 +219,6 @@ lib32: mk_bin_dir: mkdir -p $(BIN) - mkdir -p $(BIN)/interception - mkdir -p $(BIN)/interception/mach_override clang: cd ../ && llvm/rebuild_clang_and_asan.sh > /dev/null @@ -268,17 +248,20 @@ $(BIN)/%_test$(SUFF).o: tests/%_test.cc $(RTL_HDR) $(MAKEFILE) $(BIN)/%_test$(SUFF).o: tests/%_test.mm $(RTL_HDR) $(MAKEFILE) $(ASAN_CXX) $(GTEST_INCLUDE) -I. -g -c $< -O2 -o $@ -ObjC $(PIE) $(CFLAGS) -RTL_COMMON=$(PIE) $(CFLAGS) -fPIC -c -O2 -fno-exceptions -funwind-tables \ +RTL_COMMON_FLAGS=$(PIE) $(CFLAGS) -fPIC -c -O2 -fno-exceptions -funwind-tables \ -Ithird_party -I.. $(ASAN_FLAGS) -$(BIN)/interception/%$(SUFF).o: ../interception/%.cc $(MAKEFILE) - $(CXX) $(RTL_COMMON) -o $@ -g $< +$(BIN)/%$(SUFF).o: $(INTERCEPTION)/%.cc $(RTL_HDR) $(MAKEFILE) + $(CXX) $(RTL_COMMON_FLAGS) -o $@ -g $< + +$(BIN)/%$(SUFF).o: $(COMMON)/%.cc $(RTL_HDR) $(MAKEFILE) + $(CXX) $(RTL_COMMON_FLAGS) -o $@ -g $< -$(BIN)/interception/mach_override/%$(SUFF).o: ../interception/mach_override/%.c $(MAKEFILE) - $(CC) $(RTL_COMMON) -o $@ -g $< +$(BIN)/%$(SUFF).o: $(MACH_OVERRIDE)/%.c $(RTL_HDR) $(MAKEFILE) + $(CC) $(RTL_COMMON_FLAGS) -o $@ -g $< $(BIN)/%$(SUFF).o: %.cc $(RTL_HDR) $(MAKEFILE) - $(CXX) $(RTL_COMMON) -o $@ -g $< \ + $(CXX) $(RTL_COMMON_FLAGS) -o $@ -g $< \ -DASAN_NEEDS_SEGV=$(ASAN_NEEDS_SEGV) \ -DASAN_HAS_EXCEPTIONS=$(ASAN_HAS_EXCEPTIONS) \ -DASAN_FLEXIBLE_MAPPING_AND_OFFSET=$(ASAN_FLEXIBLE_MAPPING_AND_OFFSET) @@ -337,7 +320,7 @@ $(GTEST_LIB): $(MAKE) -f ../make/Makefile CXXFLAGS="$(PIE) $(CFLAGS) -g -w" \ CXX="$(CLANG_CXX)" -RTL_LINT_FITLER=-readability/casting,-readability/check,-build/include,-build/header_guard,-build/class,-legal/copyright +RTL_LINT_FITLER=-readability/casting,-readability/check,-build/include,-build/header_guard,-build/class,-legal/copyright,-build/namespaces # TODO(kcc): remove these filters one by one TEST_LINT_FITLER=-readability/casting,-build/include,-legal/copyright,-whitespace/newline,-runtime/sizeof,-runtime/int,-runtime/printf diff --git a/compiler-rt/lib/asan/asan_internal.h b/compiler-rt/lib/asan/asan_internal.h index 99e1f51bc92..358b545ad45 100644 --- a/compiler-rt/lib/asan/asan_internal.h +++ b/compiler-rt/lib/asan/asan_internal.h @@ -14,6 +14,8 @@ #ifndef ASAN_INTERNAL_H #define ASAN_INTERNAL_H +#include "sanitizer_common/mini_libc.h" + #if !defined(__linux__) && !defined(__APPLE__) && !defined(_WIN32) # error "This operating system is not supported by AddressSanitizer" #endif diff --git a/compiler-rt/lib/asan/asan_rtl.cc b/compiler-rt/lib/asan/asan_rtl.cc index bcdbf24f93f..d0a9cd57d73 100644 --- a/compiler-rt/lib/asan/asan_rtl.cc +++ b/compiler-rt/lib/asan/asan_rtl.cc @@ -23,6 +23,7 @@ #include "asan_thread_registry.h" namespace __asan { +using namespace __sanitizer; // -------------------------- Flags ------------------------- {{{1 static const size_t kMallocContextSize = 30; @@ -495,6 +496,7 @@ static void ParseAsanOptions(const char *options) { void __asan_init() { if (asan_inited) return; + MiniLibcStub(); // FIXME: remove me once mini libc build is tested properly. asan_init_is_running = true; // Make sure we are not statically linked. diff --git a/compiler-rt/lib/sanitizer_common/Makefile.mk b/compiler-rt/lib/sanitizer_common/Makefile.mk new file mode 100644 index 00000000000..da83c2d6b3b --- /dev/null +++ b/compiler-rt/lib/sanitizer_common/Makefile.mk @@ -0,0 +1,22 @@ +#===- lib/sanitizer_common/Makefile.mk ---------------------*- Makefile -*--===# +# +# The LLVM Compiler Infrastructure +# +# This file is distributed under the University of Illinois Open Source +# License. See LICENSE.TXT for details. +# +#===------------------------------------------------------------------------===# + +ModuleName := sanitizer_common +SubDirs := + +Sources := $(foreach file,$(wildcard $(Dir)/*.cc),$(notdir $(file))) +ObjNames := $(Sources:%.cc=%.o) + +Implementation := Generic + +# FIXME: use automatic dependencies? +Dependencies := $(wildcard $(Dir)/*.h) + +# Define a convenience variable for all the sanitizer_common functions. +SanitizerCommonFunctions := $(Sources:%.cc=%) diff --git a/compiler-rt/lib/sanitizer_common/mini_libc.cc b/compiler-rt/lib/sanitizer_common/mini_libc.cc new file mode 100644 index 00000000000..1190dd52f0b --- /dev/null +++ b/compiler-rt/lib/sanitizer_common/mini_libc.cc @@ -0,0 +1,20 @@ +//===-- mini_libc.cc --------------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file is shared between AddressSanitizer and ThreadSanitizer +// run-time libraries. See mini_libc.h for details. +//===----------------------------------------------------------------------===// +#include "mini_libc.h" + +namespace __sanitizer { + +void MiniLibcStub() { +} + +} // namespace __sanitizer diff --git a/compiler-rt/lib/sanitizer_common/mini_libc.h b/compiler-rt/lib/sanitizer_common/mini_libc.h new file mode 100644 index 00000000000..5a59c8f61da --- /dev/null +++ b/compiler-rt/lib/sanitizer_common/mini_libc.h @@ -0,0 +1,28 @@ +//===-- mini_libc.h ---------------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file is shared between AddressSanitizer and ThreadSanitizer +// run-time libraries. +// These tools can not use some of the libc functions directly because those +// functions are intercepted. Instead, we implement a tiny subset of libc here. +// +// We also define several basic types here to avoid using system headers +// as the latter complicate portability of this low-level code. +//===----------------------------------------------------------------------===// +#ifndef MINILIBC_H +#define MINILIBC_H + +// No code hete yet. Will move more code in the next changes. +namespace __sanitizer { + +void MiniLibcStub(); + +} // namespace __sanitizer + +#endif // MINILIBC_H diff --git a/compiler-rt/lib/tsan/Makefile.old b/compiler-rt/lib/tsan/Makefile.old index 3819c622d3d..5800f5993de 100644 --- a/compiler-rt/lib/tsan/Makefile.old +++ b/compiler-rt/lib/tsan/Makefile.old @@ -68,7 +68,7 @@ presubmit: ./check_analyze.sh @ echo PRESUBMIT PASSED -RTL_LINT_FITLER=-legal/copyright,-build/include,-readability/casting,-build/header_guard +RTL_LINT_FITLER=-legal/copyright,-build/include,-readability/casting,-build/header_guard,-build/namespaces lint: lint_tsan lint_tests lint_tsan: diff --git a/compiler-rt/lib/tsan/rtl/Makefile.old b/compiler-rt/lib/tsan/rtl/Makefile.old index 1041ed8d66b..9b79f576d4a 100644 --- a/compiler-rt/lib/tsan/rtl/Makefile.old +++ b/compiler-rt/lib/tsan/rtl/Makefile.old @@ -4,6 +4,8 @@ ifeq ($(DEBUG), 0) endif # For interception. FIXME: move interception one level higher. +INTERCEPTION=../../interception +COMMON=../../sanitizer_common INCLUDES= -I../.. EXTRA_CXXFLAGS=-fno-exceptions NO_SYSROOT=--sysroot=. @@ -25,65 +27,27 @@ endif all: libtsan.a -LIBTSAN_HEADERS=tsan_allocator.h \ - tsan_atomic.h \ - tsan_clock.h \ - tsan_compiler.h \ - tsan_defs.h \ - tsan_interface.h \ - tsan_interface_ann.h \ - tsan_interface_inl.h \ - tsan_mman.h \ - tsan_platform.h \ - tsan_mutex.h \ - tsan_report.h \ - tsan_placement_new.h \ - tsan_rtl.h \ - tsan_suppressions.h \ - tsan_symbolize.h \ - tsan_sync.h \ - tsan_trace.h \ - tsan_vector.h +LIBTSAN_HEADERS=$(wildcard *.h) \ + $(wildcard $(INTERCEPTION)/*.h) \ + $(wildcard $(COMMON)/*.h) +LIBTSAN_SRC=$(wildcard *.cc) +LIBTSAN_ASM_SRC=$(wildcard *.S) +INTERCEPTION_SRC=$(wildcard $(INTERCEPTION)/*.cc) +COMMON_SRC=$(wildcard $(COMMON)/*.cc) -LIBTSAN_OBJ=tsan_allocator.o \ - tsan_clock.o \ - tsan_flags.o \ - tsan_mutex.o \ - tsan_interceptors.o \ - tsan_interface.o \ - tsan_interface_ann.o \ - tsan_interface_atomic.o \ - tsan_md5.o \ - tsan_mman.o \ - tsan_platform_linux.o \ - tsan_report.o \ - tsan_printf.o \ - tsan_rtl.o \ - tsan_rtl_amd64.o \ - tsan_rtl_mutex.o \ - tsan_rtl_report.o \ - tsan_rtl_thread.o \ - tsan_stat.o \ - tsan_suppressions.o \ - tsan_sync.o \ - interception_linux.o - -ifneq ($(TSAN_SYMB_NULL), ) - LIBTSAN_OBJ+=tsan_symbolize_null.o -else ifneq ($(TSAN_SYMB_LLDB), ) - LIBTSAN_OBJ+=tsan_symbolize_lldb_linux.o -else - LIBTSAN_OBJ+=tsan_symbolize_addr2line_linux.o -endif +LIBTSAN_OBJ=$(patsubst %.cc,%.o,$(LIBTSAN_SRC)) \ + $(patsubst %.S,%.o,$(LIBTSAN_ASM_SRC)) \ + $(patsubst $(INTERCEPTION)/%.cc,%.o,$(INTERCEPTION_SRC)) \ + $(patsubst $(COMMON)/%.cc,%.o,$(COMMON_SRC)) %_linux.o: %_linux.cc Makefile.old $(LIBTSAN_HEADERS) $(CXX) $(CXXFLAGS) $(INCLUDES) -c $< - %.o: %.cc Makefile.old $(LIBTSAN_HEADERS) $(CXX) $(CXXFLAGS) $(INCLUDES) $(NO_SYSROOT) -c $< - -%.o: ../../interception/%.cc - $(CXX) $(CXXFLAGS) $(INCLUDES) -c $< -o $@ +%.o: $(INTERCEPTION)/%.cc Makefile.old $(LIBTSAN_HEADERS) + $(CXX) $(CXXFLAGS) $(INCLUDES) -c $< -o $@ +%.o: $(COMMON)/%.cc Makefile.old $(LIBTSAN_HEADERS) + $(CXX) $(CXXFLAGS) $(INCLUDES) -c $< -o $@ libtsan.a: $(LIBTSAN_OBJ) ar ru $@ $(LIBTSAN_OBJ) diff --git a/compiler-rt/lib/tsan/rtl/tsan_rtl.cc b/compiler-rt/lib/tsan/rtl/tsan_rtl.cc index 2a2fcc3c6c5..a9c18e20968 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_rtl.cc +++ b/compiler-rt/lib/tsan/rtl/tsan_rtl.cc @@ -12,6 +12,7 @@ // Main file (entry points) for the TSan run-time. //===----------------------------------------------------------------------===// +#include "sanitizer_common/mini_libc.h" #include "tsan_defs.h" #include "tsan_platform.h" #include "tsan_rtl.h" @@ -28,6 +29,7 @@ extern "C" void __tsan_resume() { } namespace __tsan { +using namespace __sanitizer; THREADLOCAL char cur_thread_placeholder[sizeof(ThreadState)] ALIGN(64); static char ctx_placeholder[sizeof(Context)] ALIGN(64); @@ -154,6 +156,7 @@ static void InitializeMemoryFlush() { } void Initialize(ThreadState *thr) { + MiniLibcStub(); // Thread safe because done before all threads exist. static bool is_initialized = false; if (is_initialized) diff --git a/compiler-rt/make/platform/clang_darwin.mk b/compiler-rt/make/platform/clang_darwin.mk index 472592e16df..96fc942e1e0 100644 --- a/compiler-rt/make/platform/clang_darwin.mk +++ b/compiler-rt/make/platform/clang_darwin.mk @@ -144,7 +144,8 @@ FUNCTIONS.osx := mulosi4 mulodi4 muloti4 FUNCTIONS.profile_osx := GCDAProfiling FUNCTIONS.profile_ios := GCDAProfiling -FUNCTIONS.asan_osx := $(AsanFunctions) $(InterceptionFunctions) +FUNCTIONS.asan_osx := $(AsanFunctions) $(InterceptionFunctions) \ + $(SanitizerCommonFunctions) CCKEXT_COMMON_FUNCTIONS := \ absvdi2 \ diff --git a/compiler-rt/make/platform/clang_linux.mk b/compiler-rt/make/platform/clang_linux.mk index 261edf0ec41..f2b049f8c93 100644 --- a/compiler-rt/make/platform/clang_linux.mk +++ b/compiler-rt/make/platform/clang_linux.mk @@ -79,9 +79,12 @@ FUNCTIONS.full-i386 := $(CommonFunctions) $(ArchFunctions.i386) FUNCTIONS.full-x86_64 := $(CommonFunctions) $(ArchFunctions.x86_64) FUNCTIONS.profile-i386 := GCDAProfiling FUNCTIONS.profile-x86_64 := GCDAProfiling -FUNCTIONS.asan-i386 := $(AsanFunctions) $(InterceptionFunctions) -FUNCTIONS.asan-x86_64 := $(AsanFunctions) $(InterceptionFunctions) -FUNCTIONS.tsan-x86_64 := $(TsanFunctions) $(InterceptionFunctions) +FUNCTIONS.asan-i386 := $(AsanFunctions) $(InterceptionFunctions) \ + $(SanitizerCommonFunctions) +FUNCTIONS.asan-x86_64 := $(AsanFunctions) $(InterceptionFunctions) \ + $(SanitizerCommonFunctions) +FUNCTIONS.tsan-x86_64 := $(TsanFunctions) $(InterceptionFunctions) \ + $(SanitizerCommonFunctions) # Always use optimized variants. OPTIMIZED := 1 |