[compiler-rt] r208609 - [ASan] Split static ASan runtime in two parts: asan and asan_cxx.

Alexey Samsonov samsonov at google.com
Mon May 12 11:39:23 PDT 2014


Author: samsonov
Date: Mon May 12 13:39:22 2014
New Revision: 208609

URL: http://llvm.org/viewvc/llvm-project?rev=208609&view=rev
Log:
[ASan] Split static ASan runtime in two parts: asan and asan_cxx.

asan_cxx containts replacements for new/delete operators, and should
only be linked in C++ mode. We plan to start building this part
with exception support to make new more standard-compliant.

See https://code.google.com/p/address-sanitizer/issues/detail?id=295
for more details.

Modified:
    compiler-rt/trunk/lib/asan/CMakeLists.txt
    compiler-rt/trunk/lib/asan/Makefile.mk
    compiler-rt/trunk/lib/asan/asan_internal.h
    compiler-rt/trunk/lib/asan/asan_new_delete.cc
    compiler-rt/trunk/lib/asan/asan_rtl.cc
    compiler-rt/trunk/lib/asan/tests/CMakeLists.txt
    compiler-rt/trunk/make/platform/clang_darwin.mk
    compiler-rt/trunk/make/platform/clang_linux.mk

Modified: compiler-rt/trunk/lib/asan/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/CMakeLists.txt?rev=208609&r1=208608&r2=208609&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/CMakeLists.txt (original)
+++ compiler-rt/trunk/lib/asan/CMakeLists.txt Mon May 12 13:39:22 2014
@@ -18,7 +18,6 @@ set(ASAN_SOURCES
   asan_malloc_linux.cc
   asan_malloc_mac.cc
   asan_malloc_win.cc
-  asan_new_delete.cc
   asan_poisoning.cc
   asan_posix.cc
   asan_report.cc
@@ -28,6 +27,9 @@ set(ASAN_SOURCES
   asan_thread.cc
   asan_win.cc)
 
+set(ASAN_CXX_SOURCES
+  asan_new_delete.cc)
+
 set(ASAN_PREINIT_SOURCES
   asan_preinit.cc)
 
@@ -70,12 +72,12 @@ if(APPLE)
   foreach(os ${SANITIZER_COMMON_SUPPORTED_DARWIN_OS})
     add_compiler_rt_darwin_object_library(RTAsan ${os}
       ARCH ${ASAN_SUPPORTED_ARCH}
-      SOURCES ${ASAN_SOURCES}
+      SOURCES ${ASAN_SOURCES} ${ASAN_CXX_SOURCES}
       CFLAGS ${ASAN_CFLAGS}
       DEFS ${ASAN_COMMON_DEFINITIONS})
   endforeach()
 elseif(ANDROID)
-  add_library(RTAsan.arm.android OBJECT ${ASAN_SOURCES})
+  add_library(RTAsan.arm.android OBJECT ${ASAN_SOURCES} ${ASAN_CXX_SOURCES})
   set_target_compile_flags(RTAsan.arm.android ${ASAN_CFLAGS})
   set_property(TARGET RTAsan.arm.android APPEND PROPERTY
     COMPILE_DEFINITIONS ${ASAN_COMMON_DEFINITIONS})
@@ -84,12 +86,16 @@ else()
     add_compiler_rt_object_library(RTAsan ${arch}
       SOURCES ${ASAN_SOURCES} CFLAGS ${ASAN_CFLAGS}
       DEFS ${ASAN_COMMON_DEFINITIONS})
+    add_compiler_rt_object_library(RTAsan_cxx ${arch}
+      SOURCES ${ASAN_CXX_SOURCES} CFLAGS ${ASAN_CFLAGS}
+      DEFS ${ASAN_COMMON_DEFINITIONS})
     add_compiler_rt_object_library(RTAsan_preinit ${arch}
       SOURCES ${ASAN_PREINIT_SOURCES} CFLAGS ${ASAN_CFLAGS}
       DEFS ${ASAN_COMMON_DEFINITIONS})
     if (COMPILER_RT_BUILD_SHARED_ASAN)
       add_compiler_rt_object_library(RTAsan_dynamic ${arch}
-        SOURCES ${ASAN_SOURCES} CFLAGS ${ASAN_DYNAMIC_CFLAGS}
+        SOURCES ${ASAN_SOURCES} ${ASAN_CXX_SOURCES}
+        CFLAGS ${ASAN_DYNAMIC_CFLAGS}
         DEFS ${ASAN_DYNAMIC_DEFINITIONS})
     endif()
   endforeach()
@@ -142,6 +148,12 @@ else()
       DEFS ${ASAN_COMMON_DEFINITIONS})
     add_dependencies(asan clang_rt.asan-${arch})
 
+    add_compiler_rt_runtime(clang_rt.asan_cxx-${arch} ${arch} STATIC
+      SOURCES $<TARGET_OBJECTS:RTAsan_cxx.${arch}>
+      CFLAGS ${ASAN_CFLAGS}
+      DEFS ${ASAN_COMMON_DEFINITIONS})
+    add_dependencies(asan clang_rt.asan_cxx-${arch})
+
     if (COMPILER_RT_BUILD_SHARED_ASAN)
       add_compiler_rt_runtime(clang_rt.asan-preinit-${arch} ${arch} STATIC
         SOURCES $<TARGET_OBJECTS:RTAsan_preinit.${arch}>
@@ -160,6 +172,8 @@ else()
     endif()
 
     if (UNIX AND NOT ${arch} STREQUAL "i386")
+      add_sanitizer_rt_symbols(clang_rt.asan_cxx-${arch})
+      add_dependencies(asan clang_rt.asan_cxx-${arch}-symbols)
       add_sanitizer_rt_symbols(clang_rt.asan-${arch} asan.syms.extra)
       add_dependencies(asan clang_rt.asan-${arch}-symbols)
     endif()

Modified: compiler-rt/trunk/lib/asan/Makefile.mk
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/Makefile.mk?rev=208609&r1=208608&r2=208609&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/Makefile.mk (original)
+++ compiler-rt/trunk/lib/asan/Makefile.mk Mon May 12 13:39:22 2014
@@ -11,6 +11,8 @@ ModuleName := asan
 SubDirs := 
 
 CCSources := $(foreach file,$(wildcard $(Dir)/*.cc),$(notdir $(file)))
+CXXOnlySources := asan_new_delete.cc
+COnlySources := $(filter-out $(CXXOnlySources),$(CCSources))
 SSources := $(foreach file,$(wildcard $(Dir)/*.S),$(notdir $(file)))
 Sources := $(CCSources) $(SSources)
 ObjNames := $(CCSources:%.cc=%.o) $(SSources:%.S=%.o)
@@ -23,4 +25,5 @@ Dependencies += $(wildcard $(Dir)/../int
 Dependencies += $(wildcard $(Dir)/../sanitizer_common/*.h)
 
 # Define a convenience variable for all the asan functions.
-AsanFunctions := $(CCSources:%.cc=%) $(SSources:%.S=%)
+AsanFunctions := $(COnlySources:%.cc=%) $(SSources:%.S=%)
+AsanCXXFunctions := $(CXXOnlySources:%.cc=%)

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=208609&r1=208608&r2=208609&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_internal.h (original)
+++ compiler-rt/trunk/lib/asan/asan_internal.h Mon May 12 13:39:22 2014
@@ -71,7 +71,6 @@ void AsanInitFromRtl();
 // asan_rtl.cc
 void NORETURN ShowStatsAndAbort();
 
-void ReplaceOperatorsNewAndDelete();
 // asan_malloc_linux.cc / asan_malloc_mac.cc
 void ReplaceSystemMalloc();
 

Modified: compiler-rt/trunk/lib/asan/asan_new_delete.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_new_delete.cc?rev=208609&r1=208608&r2=208609&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_new_delete.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_new_delete.cc Mon May 12 13:39:22 2014
@@ -20,13 +20,6 @@
 
 #include <stddef.h>
 
-namespace __asan {
-// This function is a no-op. We need it to make sure that object file
-// with our replacements will actually be loaded from static ASan
-// run-time library at link-time.
-void ReplaceOperatorsNewAndDelete() { }
-}
-
 using namespace __asan;  // NOLINT
 
 // This code has issues on OSX.

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=208609&r1=208608&r2=208609&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_rtl.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_rtl.cc Mon May 12 13:39:22 2014
@@ -595,7 +595,6 @@ static void AsanInitInternal() {
   InitializeAsanInterceptors();
 
   ReplaceSystemMalloc();
-  ReplaceOperatorsNewAndDelete();
 
   uptr shadow_start = kLowShadowBeg;
   if (kLowShadowBeg)

Modified: compiler-rt/trunk/lib/asan/tests/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/tests/CMakeLists.txt?rev=208609&r1=208608&r2=208609&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/tests/CMakeLists.txt (original)
+++ compiler-rt/trunk/lib/asan/tests/CMakeLists.txt Mon May 12 13:39:22 2014
@@ -48,7 +48,7 @@ set(ASAN_UNITTEST_INSTRUMENTED_CFLAGS
 )
 
 # Unit tests require libstdc++.
-set(ASAN_UNITTEST_COMMON_LINKFLAGS -lstdc++)
+set(ASAN_UNITTEST_COMMON_LINKFLAGS --driver-mode=g++ -lstdc++)
 # x86_64 FreeBSD 9.2 additionally requires libc++ to build the tests.
 if(CMAKE_SYSTEM MATCHES "FreeBSD-9.2-RELEASE")
   list(APPEND ASAN_UNITTEST_COMMON_LINKFLAGS "-lc++")
@@ -181,6 +181,7 @@ macro(add_asan_tests_for_arch_and_kind a
   else()
     set(ASAN_TEST_RUNTIME_OBJECTS
       $<TARGET_OBJECTS:RTAsan.${arch}>
+      $<TARGET_OBJECTS:RTAsan_cxx.${arch}>
       $<TARGET_OBJECTS:RTInterception.${arch}>
       $<TARGET_OBJECTS:RTLSanCommon.${arch}>
       $<TARGET_OBJECTS:RTSanitizerCommon.${arch}>

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=208609&r1=208608&r2=208609&view=diff
==============================================================================
--- compiler-rt/trunk/make/platform/clang_darwin.mk (original)
+++ compiler-rt/trunk/make/platform/clang_darwin.mk Mon May 12 13:39:22 2014
@@ -227,11 +227,13 @@ FUNCTIONS.profile_osx := GCDAProfiling I
                          InstrProfilingRuntime
 FUNCTIONS.profile_ios := $(FUNCTIONS.profile_osx)
 
-FUNCTIONS.asan_osx_dynamic := $(AsanFunctions) $(InterceptionFunctions) \
+FUNCTIONS.asan_osx_dynamic := $(AsanFunctions) $(AsanCXXFunctions) \
+                              $(InterceptionFunctions) \
                               $(SanitizerCommonFunctions) \
 	                      $(AsanDynamicFunctions)
 
-FUNCTIONS.asan_iossim_dynamic := $(AsanFunctions) $(InterceptionFunctions) \
+FUNCTIONS.asan_iossim_dynamic := $(AsanFunctions) $(AsanCXXFunctions) \
+                                 $(InterceptionFunctions) \
                                  $(SanitizerCommonFunctions) \
 	                         $(AsanDynamicFunctions)
 

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=208609&r1=208608&r2=208609&view=diff
==============================================================================
--- compiler-rt/trunk/make/platform/clang_linux.mk (original)
+++ compiler-rt/trunk/make/platform/clang_linux.mk Mon May 12 13:39:22 2014
@@ -49,23 +49,27 @@ endif
 
 # Build runtime libraries for i386.
 ifeq ($(call contains,$(SupportedArches),i386),true)
-Configs += full-i386 profile-i386 san-i386 asan-i386 ubsan-i386 ubsan_cxx-i386
+Configs += full-i386 profile-i386 san-i386 asan-i386 asan_cxx-i386 \
+	   ubsan-i386 ubsan_cxx-i386
 Arch.full-i386 := i386
 Arch.profile-i386 := i386
 Arch.san-i386 := i386
 Arch.asan-i386 := i386
+Arch.asan_cxx-i386 := i386
 Arch.ubsan-i386 := i386
 Arch.ubsan_cxx-i386 := i386
 endif
 
 # Build runtime libraries for x86_64.
 ifeq ($(call contains,$(SupportedArches),x86_64),true)
-Configs += full-x86_64 profile-x86_64 san-x86_64 asan-x86_64 tsan-x86_64 \
-           msan-x86_64 ubsan-x86_64 ubsan_cxx-x86_64 dfsan-x86_64 lsan-x86_64
+Configs += full-x86_64 profile-x86_64 san-x86_64 asan-x86_64 asan_cxx-x86_64 \
+	   tsan-x86_64 msan-x86_64 ubsan-x86_64 ubsan_cxx-x86_64 dfsan-x86_64 \
+	   lsan-x86_64
 Arch.full-x86_64 := x86_64
 Arch.profile-x86_64 := x86_64
 Arch.san-x86_64 := x86_64
 Arch.asan-x86_64 := x86_64
+Arch.asan_cxx-x86_64 := x86_64
 Arch.tsan-x86_64 := x86_64
 Arch.msan-x86_64 := x86_64
 Arch.ubsan-x86_64 := x86_64
@@ -96,6 +100,8 @@ CFLAGS.san-i386 := $(CFLAGS) -m32 $(SANI
 CFLAGS.san-x86_64 := $(CFLAGS) -m64 $(SANITIZER_CFLAGS) -fno-rtti
 CFLAGS.asan-i386 := $(CFLAGS) -m32 $(SANITIZER_CFLAGS) -fno-rtti
 CFLAGS.asan-x86_64 := $(CFLAGS) -m64 $(SANITIZER_CFLAGS) -fno-rtti
+CFLAGS.asan_cxx-i386 := $(CFLAGS) -m32 $(SANITIZER_CFLAGS) -fno-rtti
+CFLAGS.asan_cxx-x86_64 := $(CFLAGS) -m64 $(SANITIZER_CFLAGS) -fno-rtti
 CFLAGS.tsan-x86_64 := $(CFLAGS) -m64 $(SANITIZER_CFLAGS) -fno-rtti
 CFLAGS.msan-x86_64 := $(CFLAGS) -m64 $(SANITIZER_CFLAGS) -fno-rtti
 CFLAGS.ubsan-i386 := $(CFLAGS) -m32 $(SANITIZER_CFLAGS) -fno-rtti
@@ -131,8 +137,11 @@ FUNCTIONS.asan-i386 := $(AsanFunctions)
                                         $(SanitizerCommonFunctions)
 FUNCTIONS.asan-x86_64 := $(AsanFunctions) $(InterceptionFunctions) \
                          $(SanitizerCommonFunctions) $(LsanCommonFunctions)
-FUNCTIONS.asan-arm-android := $(AsanFunctions) $(InterceptionFunctions) \
-                                          $(SanitizerCommonFunctions)
+FUNCTIONS.asan_cxx-i386 := $(AsanCXXFunctions)
+FUNCTIONS.asan_cxx-x86_64 := $(AsanCXXFunctions)
+FUNCTIONS.asan-arm-android := $(AsanFunctions) $(AsanCXXFunctions) \
+                              $(InterceptionFunctions) \
+                              $(SanitizerCommonFunctions)
 FUNCTIONS.tsan-x86_64 := $(TsanFunctions) $(InterceptionFunctions) \
                                           $(SanitizerCommonFunctions)
 FUNCTIONS.msan-x86_64 := $(MsanFunctions) $(InterceptionFunctions) \





More information about the llvm-commits mailing list