[llvm-commits] [compiler-rt] r157611 - in /compiler-rt/trunk: lib/Makefile.mk lib/asan/Makefile.old lib/asan/asan_internal.h lib/asan/asan_rtl.cc lib/sanitizer_common/ lib/sanitizer_common/Makefile.mk lib/sanitizer_common/mini_libc.cc lib/sanitizer_common/mini_libc.h lib/tsan/Makefile.old lib/tsan/rtl/Makefile.old lib/tsan/rtl/tsan_rtl.cc make/platform/clang_darwin.mk make/platform/clang_linux.mk

Kostya Serebryany kcc at google.com
Tue May 29 05:18:19 PDT 2012


Author: kcc
Date: Tue May 29 07:18:18 2012
New Revision: 157611

URL: http://llvm.org/viewvc/llvm-project?rev=157611&view=rev
Log:
[asan,tsan] Add a new directory compiler-rt/lib/sanitizer_common
which will contain code shared between asan and tsan run-times.

Naming is hard. If you can suggest a better name for the directory -- speak up.


Added:
    compiler-rt/trunk/lib/sanitizer_common/
    compiler-rt/trunk/lib/sanitizer_common/Makefile.mk
    compiler-rt/trunk/lib/sanitizer_common/mini_libc.cc
    compiler-rt/trunk/lib/sanitizer_common/mini_libc.h
Modified:
    compiler-rt/trunk/lib/Makefile.mk
    compiler-rt/trunk/lib/asan/Makefile.old
    compiler-rt/trunk/lib/asan/asan_internal.h
    compiler-rt/trunk/lib/asan/asan_rtl.cc
    compiler-rt/trunk/lib/tsan/Makefile.old
    compiler-rt/trunk/lib/tsan/rtl/Makefile.old
    compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.cc
    compiler-rt/trunk/make/platform/clang_darwin.mk
    compiler-rt/trunk/make/platform/clang_linux.mk

Modified: compiler-rt/trunk/lib/Makefile.mk
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/Makefile.mk?rev=157611&r1=157610&r2=157611&view=diff
==============================================================================
--- compiler-rt/trunk/lib/Makefile.mk (original)
+++ compiler-rt/trunk/lib/Makefile.mk Tue May 29 07:18:18 2012
@@ -17,6 +17,7 @@
 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

Modified: compiler-rt/trunk/lib/asan/Makefile.old
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/Makefile.old?rev=157611&r1=157610&r2=157611&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/Makefile.old (original)
+++ compiler-rt/trunk/lib/asan/Makefile.old Tue May 29 07:18:18 2012
@@ -170,42 +170,24 @@
 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 @@
 
 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.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)/interception/mach_override/%$(SUFF).o: ../interception/mach_override/%.c $(MAKEFILE)
-	$(CC) $(RTL_COMMON) -o $@ -g $<
+$(BIN)/%$(SUFF).o: $(COMMON)/%.cc $(RTL_HDR) $(MAKEFILE)
+	$(CXX) $(RTL_COMMON_FLAGS) -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 @@
 	$(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
 

Modified: compiler-rt/trunk/lib/asan/asan_internal.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_internal.h?rev=157611&r1=157610&r2=157611&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_internal.h (original)
+++ compiler-rt/trunk/lib/asan/asan_internal.h Tue May 29 07:18:18 2012
@@ -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

Modified: compiler-rt/trunk/lib/asan/asan_rtl.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_rtl.cc?rev=157611&r1=157610&r2=157611&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_rtl.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_rtl.cc Tue May 29 07:18:18 2012
@@ -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 @@
 
 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.

Added: compiler-rt/trunk/lib/sanitizer_common/Makefile.mk
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/Makefile.mk?rev=157611&view=auto
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/Makefile.mk (added)
+++ compiler-rt/trunk/lib/sanitizer_common/Makefile.mk Tue May 29 07:18:18 2012
@@ -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=%)

Added: compiler-rt/trunk/lib/sanitizer_common/mini_libc.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/mini_libc.cc?rev=157611&view=auto
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/mini_libc.cc (added)
+++ compiler-rt/trunk/lib/sanitizer_common/mini_libc.cc Tue May 29 07:18:18 2012
@@ -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

Added: compiler-rt/trunk/lib/sanitizer_common/mini_libc.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/mini_libc.h?rev=157611&view=auto
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/mini_libc.h (added)
+++ compiler-rt/trunk/lib/sanitizer_common/mini_libc.h Tue May 29 07:18:18 2012
@@ -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

Modified: compiler-rt/trunk/lib/tsan/Makefile.old
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/Makefile.old?rev=157611&r1=157610&r2=157611&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/Makefile.old (original)
+++ compiler-rt/trunk/lib/tsan/Makefile.old Tue May 29 07:18:18 2012
@@ -68,7 +68,7 @@
 	./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:

Modified: compiler-rt/trunk/lib/tsan/rtl/Makefile.old
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/Makefile.old?rev=157611&r1=157610&r2=157611&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/Makefile.old (original)
+++ compiler-rt/trunk/lib/tsan/rtl/Makefile.old Tue May 29 07:18:18 2012
@@ -4,6 +4,8 @@
 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 @@
 
 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_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_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=$(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)

Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.cc?rev=157611&r1=157610&r2=157611&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_rtl.cc Tue May 29 07:18:18 2012
@@ -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 @@
 }
 
 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 @@
 }
 
 void Initialize(ThreadState *thr) {
+  MiniLibcStub();
   // Thread safe because done before all threads exist.
   static bool is_initialized = false;
   if (is_initialized)

Modified: compiler-rt/trunk/make/platform/clang_darwin.mk
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/make/platform/clang_darwin.mk?rev=157611&r1=157610&r2=157611&view=diff
==============================================================================
--- compiler-rt/trunk/make/platform/clang_darwin.mk (original)
+++ compiler-rt/trunk/make/platform/clang_darwin.mk Tue May 29 07:18:18 2012
@@ -144,7 +144,8 @@
 FUNCTIONS.profile_osx := GCDAProfiling
 FUNCTIONS.profile_ios := GCDAProfiling
 
-FUNCTIONS.asan_osx := $(AsanFunctions) $(InterceptionFunctions)
+FUNCTIONS.asan_osx := $(AsanFunctions) $(InterceptionFunctions) \
+                                       $(SanitizerCommonFunctions)
 
 CCKEXT_COMMON_FUNCTIONS := \
 	absvdi2 \

Modified: compiler-rt/trunk/make/platform/clang_linux.mk
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/make/platform/clang_linux.mk?rev=157611&r1=157610&r2=157611&view=diff
==============================================================================
--- compiler-rt/trunk/make/platform/clang_linux.mk (original)
+++ compiler-rt/trunk/make/platform/clang_linux.mk Tue May 29 07:18:18 2012
@@ -79,9 +79,12 @@
 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





More information about the llvm-commits mailing list