[libcxxabi] r344191 - [libcxxabi] Allow building with sanitizers enabled

Louis Dionne ldionne at apple.com
Wed Oct 10 15:00:59 PDT 2018


Author: ldionne
Date: Wed Oct 10 15:00:58 2018
New Revision: 344191

URL: http://llvm.org/viewvc/llvm-project?rev=344191&view=rev
Log:
[libcxxabi] Allow building with sanitizers enabled

Summary:
I copied the sanitizer-related logic in libcxx/lib/CMakeLists.txt. In
the future, it would be great to avoid duplicating this logic in the
compiler, libc++ and libc++abi.

Reviewers: EricWF

Subscribers: mgorny, christof, dexonsmith, libcxx-commits, davide

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

Modified:
    libcxxabi/trunk/src/CMakeLists.txt
    libcxxabi/trunk/test/lit.site.cfg.in

Modified: libcxxabi/trunk/src/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/src/CMakeLists.txt?rev=344191&r1=344190&r2=344191&view=diff
==============================================================================
--- libcxxabi/trunk/src/CMakeLists.txt (original)
+++ libcxxabi/trunk/src/CMakeLists.txt Wed Oct 10 15:00:58 2018
@@ -102,6 +102,31 @@ if ( APPLE )
       "-compatibility_version 1"
       "-install_name /usr/lib/libc++abi.1.dylib")
   endif()
+
+  if (LLVM_USE_SANITIZER)
+    if (("${LLVM_USE_SANITIZER}" STREQUAL "Address") OR
+        ("${LLVM_USE_SANITIZER}" STREQUAL "Address;Undefined") OR
+        ("${LLVM_USE_SANITIZER}" STREQUAL "Undefined;Address"))
+      set(LIBFILE "libclang_rt.asan_osx_dynamic.dylib")
+    elseif("${LLVM_USE_SANITIZER}" STREQUAL "Undefined")
+      set(LIBFILE "libclang_rt.ubsan_osx_dynamic.dylib")
+    elseif("${LLVM_USE_SANITIZER}" STREQUAL "Thread")
+      set(LIBFILE "libclang_rt.tsan_osx_dynamic.dylib")
+    else()
+      message(WARNING "LLVM_USE_SANITIZER=${LLVM_USE_SANITIZER} is not supported on OS X")
+    endif()
+    if (LIBFILE)
+      find_compiler_rt_dir(LIBDIR)
+      if (NOT IS_DIRECTORY "${LIBDIR}")
+        message(FATAL_ERROR "Cannot find compiler-rt directory on OS X required for LLVM_USE_SANITIZER")
+      endif()
+      set(LIBCXXABI_SANITIZER_LIBRARY "${LIBDIR}/${LIBFILE}")
+      set(LIBCXXABI_SANITIZER_LIBRARY "${LIBCXXABI_SANITIZER_LIBRARY}" PARENT_SCOPE)
+      message(STATUS "Manually linking compiler-rt library: ${LIBCXXABI_SANITIZER_LIBRARY}")
+      add_library_flags("${LIBCXXABI_SANITIZER_LIBRARY}")
+      add_link_flags("-Wl,-rpath,${LIBDIR}")
+    endif()
+  endif()
 endif()
 
 split_list(LIBCXXABI_COMPILE_FLAGS)

Modified: libcxxabi/trunk/test/lit.site.cfg.in
URL: http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/test/lit.site.cfg.in?rev=344191&r1=344190&r2=344191&view=diff
==============================================================================
--- libcxxabi/trunk/test/lit.site.cfg.in (original)
+++ libcxxabi/trunk/test/lit.site.cfg.in Wed Oct 10 15:00:58 2018
@@ -11,6 +11,7 @@ config.cxx_library_root         = "@LIBC
 config.llvm_unwinder            = "@LIBCXXABI_USE_LLVM_UNWINDER@"
 config.enable_threads           = "@LIBCXXABI_ENABLE_THREADS@"
 config.use_sanitizer            = "@LLVM_USE_SANITIZER@"
+config.sanitizer_library        = "@LIBCXXABI_SANITIZER_LIBRARY@"
 config.enable_32bit             = "@LIBCXXABI_BUILD_32_BITS@"
 config.target_info              = "@LIBCXXABI_TARGET_INFO@"
 config.executor                 = "@LIBCXXABI_EXECUTOR@"




More information about the libcxx-commits mailing list