[compiler-rt] r295012 - Add cmake build support for lsan on OS X

Francis Ricci via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 13 16:56:53 PST 2017


Author: fjricci
Date: Mon Feb 13 18:56:53 2017
New Revision: 295012

URL: http://llvm.org/viewvc/llvm-project?rev=295012&view=rev
Log:
Add cmake build support for lsan on OS X

Summary:
Adds a new cmake flag 'COMPILER_RT_ENABLE_LSAN_OSX', which enables lsan
compilation and is turned off by default. Patches to fix build errors
when this flag is enabled will be uploaded soon.

This is part of an effort to port LSan to OS X, but LSan on OS X does not
currently work or pass tests currently.

Reviewers: kubamracek, kcc, glider, alekseyshl

Reviewed By: kubamracek

Subscribers: danalbert, srhines, mgorny, llvm-commits

Differential Revision: https://reviews.llvm.org/D29783

Added:
    compiler-rt/trunk/lib/lsan/weak_symbols.txt
Modified:
    compiler-rt/trunk/cmake/config-ix.cmake
    compiler-rt/trunk/lib/asan/CMakeLists.txt
    compiler-rt/trunk/lib/lsan/CMakeLists.txt
    compiler-rt/trunk/lib/lsan/lsan_common.h

Modified: compiler-rt/trunk/cmake/config-ix.cmake
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/cmake/config-ix.cmake?rev=295012&r1=295011&r2=295012&view=diff
==============================================================================
--- compiler-rt/trunk/cmake/config-ix.cmake (original)
+++ compiler-rt/trunk/cmake/config-ix.cmake Mon Feb 13 18:56:53 2017
@@ -164,7 +164,15 @@ set(ALL_SANITIZER_COMMON_SUPPORTED_ARCH
 set(ALL_ASAN_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64}
     ${MIPS32} ${MIPS64} ${PPC64} ${S390X})
 set(ALL_DFSAN_SUPPORTED_ARCH ${X86_64} ${MIPS64} ${ARM64})
-set(ALL_LSAN_SUPPORTED_ARCH ${X86} ${X86_64} ${MIPS64} ${ARM64})
+
+# Darwin does not support 32-bit thread-local storage on ios versions
+# below 9.0. Until the min ios version is bumped to 9.0, lsan will
+# not build for 32-bit darwin targets.
+if(APPLE)
+  set(ALL_LSAN_SUPPORTED_ARCH ${X86_64} ${ARM64})
+else()
+  set(ALL_LSAN_SUPPORTED_ARCH ${X86} ${X86_64} ${MIPS64} ${ARM64})
+endif()
 set(ALL_MSAN_SUPPORTED_ARCH ${X86_64} ${MIPS64} ${ARM64} ${PPC64})
 set(ALL_PROFILE_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64} ${PPC64}
     ${MIPS32} ${MIPS64} ${S390X})
@@ -477,6 +485,13 @@ else()
   set(COMPILER_RT_HAS_LSAN FALSE)
 endif()
 
+if(APPLE)
+  option(COMPILER_RT_ENABLE_LSAN_OSX "Enable building LSan for OS X - Experimental" Off)
+  if(COMPILER_RT_ENABLE_LSAN_OSX)
+    set(COMPILER_RT_HAS_LSAN TRUE)
+  endif()
+endif()
+
 if (COMPILER_RT_HAS_SANITIZER_COMMON AND MSAN_SUPPORTED_ARCH AND
     OS_NAME MATCHES "Linux")
   set(COMPILER_RT_HAS_MSAN TRUE)

Modified: compiler-rt/trunk/lib/asan/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/CMakeLists.txt?rev=295012&r1=295011&r2=295012&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/CMakeLists.txt (original)
+++ compiler-rt/trunk/lib/asan/CMakeLists.txt Mon Feb 13 18:56:53 2017
@@ -36,6 +36,11 @@ set(ASAN_PREINIT_SOURCES
 include_directories(..)
 
 set(ASAN_CFLAGS ${SANITIZER_COMMON_CFLAGS})
+
+# FIXME(fjricci) - remove this once lsan for darwin is fully enabled
+if(APPLE AND COMPILER_RT_HAS_LSAN)
+  set(ASAN_CFLAGS ${ASAN_CFLAGS} -DCAN_SANITIZE_LEAKS_MAC=1)
+endif()
 append_rtti_flag(OFF ASAN_CFLAGS)
 
 set(ASAN_DYNAMIC_LINK_FLAGS)
@@ -107,6 +112,7 @@ add_compiler_rt_component(asan)
 
 if(APPLE)
   add_weak_symbols("asan" WEAK_SYMBOL_LINK_FLAGS)
+  add_weak_symbols("lsan" WEAK_SYMBOL_LINK_FLAGS)
   add_weak_symbols("ubsan" WEAK_SYMBOL_LINK_FLAGS)
   add_weak_symbols("sanitizer_common" WEAK_SYMBOL_LINK_FLAGS)
 

Modified: compiler-rt/trunk/lib/lsan/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/lsan/CMakeLists.txt?rev=295012&r1=295011&r2=295012&view=diff
==============================================================================
--- compiler-rt/trunk/lib/lsan/CMakeLists.txt (original)
+++ compiler-rt/trunk/lib/lsan/CMakeLists.txt Mon Feb 13 18:56:53 2017
@@ -17,6 +17,10 @@ set(LSAN_SOURCES
 
 set(LSAN_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR})
 
+# FIXME(fjricci) - remove this once lsan for darwin is fully enabled
+if(APPLE AND COMPILER_RT_HAS_LSAN)
+  set(LSAN_CFLAGS ${LSAN_CFLAGS} -DCAN_SANITIZE_LEAKS_MAC=1)
+endif()
 add_compiler_rt_object_libraries(RTLSanCommon
     OS ${SANITIZER_COMMON_SUPPORTED_OS}
     ARCHS ${LSAN_COMMON_SUPPORTED_ARCH}
@@ -25,16 +29,34 @@ add_compiler_rt_object_libraries(RTLSanC
 
 if(COMPILER_RT_HAS_LSAN)
   add_compiler_rt_component(lsan)
-  foreach(arch ${LSAN_SUPPORTED_ARCH})
+  if(APPLE)
+    add_weak_symbols("lsan" WEAK_SYMBOL_LINK_FLAGS)
+    add_weak_symbols("sanitizer_common" WEAK_SYMBOL_LINK_FLAGS)
+
     add_compiler_rt_runtime(clang_rt.lsan
-      STATIC
-      ARCHS ${arch}
+      SHARED
+      OS ${SANITIZER_COMMON_SUPPORTED_OS}
+      ARCHS ${LSAN_SUPPORTED_ARCH}
       SOURCES ${LSAN_SOURCES}
-              $<TARGET_OBJECTS:RTInterception.${arch}>
-              $<TARGET_OBJECTS:RTSanitizerCommon.${arch}>
-              $<TARGET_OBJECTS:RTSanitizerCommonLibc.${arch}>
-              $<TARGET_OBJECTS:RTLSanCommon.${arch}>
+      OBJECT_LIBS RTLSanCommon
+                  RTInterception
+                  RTSanitizerCommon
+                  RTSanitizerCommonLibc
       CFLAGS ${LSAN_CFLAGS}
+      LINK_FLAGS ${WEAK_SYMBOL_LINK_FLAGS}
       PARENT_TARGET lsan)
-  endforeach()
+  else()
+    foreach(arch ${LSAN_SUPPORTED_ARCH})
+      add_compiler_rt_runtime(clang_rt.lsan
+        STATIC
+        ARCHS ${arch}
+        SOURCES ${LSAN_SOURCES}
+                $<TARGET_OBJECTS:RTInterception.${arch}>
+                $<TARGET_OBJECTS:RTSanitizerCommon.${arch}>
+                $<TARGET_OBJECTS:RTSanitizerCommonLibc.${arch}>
+                $<TARGET_OBJECTS:RTLSanCommon.${arch}>
+        CFLAGS ${LSAN_CFLAGS}
+        PARENT_TARGET lsan)
+    endforeach()
+  endif()
 endif()

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=295012&r1=295011&r2=295012&view=diff
==============================================================================
--- compiler-rt/trunk/lib/lsan/lsan_common.h (original)
+++ compiler-rt/trunk/lib/lsan/lsan_common.h Mon Feb 13 18:56:53 2017
@@ -30,8 +30,9 @@
 // To enable LeakSanitizer on new architecture, one need to implement
 // internal_clone function as well as (probably) adjust TLS machinery for
 // new architecture inside sanitizer library.
-#if (SANITIZER_LINUX && !SANITIZER_ANDROID) && (SANITIZER_WORDSIZE == 64) \
-     && (defined(__x86_64__) ||  defined(__mips64) ||  defined(__aarch64__))
+#if (SANITIZER_LINUX && !SANITIZER_ANDROID || CAN_SANITIZE_LEAKS_MAC) \
+     && (SANITIZER_WORDSIZE == 64) && (defined(__x86_64__) \
+     ||  defined(__mips64) ||  defined(__aarch64__))
 #define CAN_SANITIZE_LEAKS 1
 #elif SANITIZER_LINUX && !SANITIZER_ANDROID && defined(__i386__)
 #define CAN_SANITIZE_LEAKS 1

Added: compiler-rt/trunk/lib/lsan/weak_symbols.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/lsan/weak_symbols.txt?rev=295012&view=auto
==============================================================================
--- compiler-rt/trunk/lib/lsan/weak_symbols.txt (added)
+++ compiler-rt/trunk/lib/lsan/weak_symbols.txt Mon Feb 13 18:56:53 2017
@@ -0,0 +1,2 @@
+___lsan_default_suppressions
+___lsan_is_turned_off




More information about the llvm-commits mailing list