[compiler-rt] r182383 - [lsan] Change CMakeLists to build the common LSan module for ASan.

Sergey Matveev earthdok at google.com
Tue May 21 07:12:11 PDT 2013


Author: smatveev
Date: Tue May 21 09:12:11 2013
New Revision: 182383

URL: http://llvm.org/viewvc/llvm-project?rev=182383&view=rev
Log:
[lsan] Change CMakeLists to build the common LSan module for ASan.
Also, define CAN_SANITIZE_LEAKS.

Modified:
    compiler-rt/trunk/lib/asan/CMakeLists.txt
    compiler-rt/trunk/lib/lsan/CMakeLists.txt
    compiler-rt/trunk/lib/lsan/lsan_common.cc
    compiler-rt/trunk/lib/lsan/lsan_common.h
    compiler-rt/trunk/lib/lsan/lsan_common_linux.cc

Modified: compiler-rt/trunk/lib/asan/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/CMakeLists.txt?rev=182383&r1=182382&r2=182383&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/CMakeLists.txt (original)
+++ compiler-rt/trunk/lib/asan/CMakeLists.txt Tue May 21 09:12:11 2013
@@ -85,6 +85,7 @@ else()
               $<TARGET_OBJECTS:RTInterception.${arch}>
               $<TARGET_OBJECTS:RTSanitizerCommon.${arch}>
               $<TARGET_OBJECTS:RTSanitizerCommonLibc.${arch}>
+              $<TARGET_OBJECTS:RTLSanCommon.${arch}>
       CFLAGS ${ASAN_CFLAGS}
       DEFS ${ASAN_COMMON_DEFINITIONS}
       SYMS asan.syms)

Modified: compiler-rt/trunk/lib/lsan/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/lsan/CMakeLists.txt?rev=182383&r1=182382&r2=182383&view=diff
==============================================================================
--- compiler-rt/trunk/lib/lsan/CMakeLists.txt (original)
+++ compiler-rt/trunk/lib/lsan/CMakeLists.txt Tue May 21 09:12:11 2013
@@ -3,28 +3,46 @@ include_directories(..)
 set(LSAN_CFLAGS
   ${SANITIZER_COMMON_CFLAGS})
 
+set(LSAN_COMMON_SOURCES
+  lsan_common.cc
+  lsan_common_linux.cc)
+
 set(LSAN_SOURCES
   lsan_interceptors.cc
   lsan_allocator.cc
   lsan_thread.cc
-  lsan.cc
-  lsan_common.cc
-  lsan_common_linux.cc)
+  lsan.cc)
 
 set(LSAN_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR})
 
+# The common files need to build on every arch supported by ASan.
+# (Even if they build into dummy object files.)
+filter_available_targets(LSAN_COMMON_SUPPORTED_ARCH
+  x86_64 i386 powerpc64 powerpc)
+
+# Architectures supported by the standalone LSan.
+filter_available_targets(LSAN_SUPPORTED_ARCH
+  x86_64)
+
 set(LSAN_RUNTIME_LIBRARIES)
 
-# FIXME: support LSan for other arches.
-if(CAN_TARGET_x86_64)
-  set(arch "x86_64")
-  add_compiler_rt_static_runtime(clang_rt.lsan-${arch} ${arch}
-    SOURCES ${LSAN_SOURCES}
-            $<TARGET_OBJECTS:RTInterception.${arch}>
-            $<TARGET_OBJECTS:RTSanitizerCommon.${arch}>
-            $<TARGET_OBJECTS:RTSanitizerCommonLibc.${arch}>
-    CFLAGS ${LSAN_CFLAGS})
-  list(APPEND LSAN_RUNTIME_LIBRARIES clang_rt.lsan-${arch})
+if (NOT APPLE AND NOT ANDROID)
+  foreach(arch ${LSAN_COMMON_SUPPORTED_ARCH})
+    add_compiler_rt_object_library(RTLSanCommon ${arch}
+      SOURCES ${LSAN_COMMON_SOURCES}
+      CFLAGS ${LSAN_CFLAGS})
+  endforeach()
+
+  foreach(arch ${LSAN_SUPPORTED_ARCH})
+    add_compiler_rt_static_runtime(clang_rt.lsan-${arch} ${arch}
+      SOURCES ${LSAN_SOURCES}
+              $<TARGET_OBJECTS:RTInterception.${arch}>
+              $<TARGET_OBJECTS:RTSanitizerCommon.${arch}>
+              $<TARGET_OBJECTS:RTSanitizerCommonLibc.${arch}>
+              $<TARGET_OBJECTS:RTLSanCommon.${arch}>
+      CFLAGS ${LSAN_CFLAGS})
+    list(APPEND LSAN_RUNTIME_LIBRARIES clang_rt.lsan-${arch})
+  endforeach()
 endif()
 
 add_subdirectory(tests)

Modified: compiler-rt/trunk/lib/lsan/lsan_common.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/lsan/lsan_common.cc?rev=182383&r1=182382&r2=182383&view=diff
==============================================================================
--- compiler-rt/trunk/lib/lsan/lsan_common.cc (original)
+++ compiler-rt/trunk/lib/lsan/lsan_common.cc Tue May 21 09:12:11 2013
@@ -21,7 +21,7 @@
 #include "sanitizer_common/sanitizer_stoptheworld.h"
 
 namespace __lsan {
-
+#if CAN_SANITIZE_LEAKS
 Flags lsan_flags;
 
 static void InitializeFlags() {
@@ -381,5 +381,8 @@ void LeakReport::PrintLargest(uptr max_l
            remaining > 1 ? "s" : "");
   }
 }
-
+#else  // CAN_SANITIZE_LEAKS
+void InitCommonLsan() {}
+void DoLeakCheck() {}
+#endif  // CAN_SANITIZE_LEAKS
 }  // namespace __lsan

Modified: compiler-rt/trunk/lib/lsan/lsan_common.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/lsan/lsan_common.h?rev=182383&r1=182382&r2=182383&view=diff
==============================================================================
--- compiler-rt/trunk/lib/lsan/lsan_common.h (original)
+++ compiler-rt/trunk/lib/lsan/lsan_common.h Tue May 21 09:12:11 2013
@@ -17,8 +17,15 @@
 
 #include "sanitizer_common/sanitizer_common.h"
 #include "sanitizer_common/sanitizer_internal_defs.h"
+#include "sanitizer_common/sanitizer_platform.h"
 #include "sanitizer_common/sanitizer_symbolizer.h"
 
+#if SANITIZER_LINUX && defined(__x86_64__)
+#define CAN_SANITIZE_LEAKS 1
+#else
+#define CAN_SANITIZE_LEAKS 0
+#endif
+
 namespace __lsan {
 
 // Chunk tags.

Modified: compiler-rt/trunk/lib/lsan/lsan_common_linux.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/lsan/lsan_common_linux.cc?rev=182383&r1=182382&r2=182383&view=diff
==============================================================================
--- compiler-rt/trunk/lib/lsan/lsan_common_linux.cc (original)
+++ compiler-rt/trunk/lib/lsan/lsan_common_linux.cc Tue May 21 09:12:11 2013
@@ -13,9 +13,9 @@
 //===----------------------------------------------------------------------===//
 
 #include "sanitizer_common/sanitizer_platform.h"
-#if SANITIZER_LINUX
 #include "lsan_common.h"
 
+#if CAN_SANITIZE_LEAKS && SANITIZER_LINUX
 #include <link.h>
 
 #include "sanitizer_common/sanitizer_common.h"
@@ -120,4 +120,4 @@ void ProcessPlatformSpecificAllocations(
 }
 
 }  // namespace __lsan
-#endif  // SANITIZER_LINUX
+#endif  // CAN_SANITIZE_LEAKS && SANITIZER_LINUX





More information about the llvm-commits mailing list