[libcxx] Add support for sanitizers on OS X.
Summary: This patch adds special configuration logic to find the compiler_rt libraries required by sanitizers on OS X. The supported sanitizers are Address and Undefined. Reviewers: mclow.lists Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D11381 git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@242858 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -68,6 +68,32 @@ if (LIBCXX_COVERAGE_LIBRARY)
|
||||
endif()
|
||||
target_link_libraries(cxx ${libraries})
|
||||
|
||||
if (APPLE AND LLVM_USE_SANITIZER)
|
||||
if ("${LLVM_USE_SANITIZER}" STREQUAL "Address")
|
||||
set(LIBFILE "libclang_rt.asan_osx_dynamic.dylib")
|
||||
elseif("${LLVM_USE_SANITIZER}" STREQUAL "Undefined")
|
||||
set(LIBFILE "libclang_rt.ubsan_osx_dynamic.dylib")
|
||||
else()
|
||||
message(WARNING "LLVM_USE_SANITIZER=${LLVM_USE_SANITIZER} is not supported on OS X")
|
||||
endif()
|
||||
if (LIBFILE)
|
||||
execute_process(COMMAND ${CMAKE_CXX_COMPILER} -print-file-name=lib OUTPUT_VARIABLE LIBDIR RESULT_VARIABLE Result)
|
||||
if (NOT ${Result} EQUAL "0")
|
||||
message(FATAL "Failed to find library resource directory")
|
||||
endif()
|
||||
string(STRIP "${LIBDIR}" LIBDIR)
|
||||
set(LIBDIR "${LIBDIR}/darwin/")
|
||||
if (NOT IS_DIRECTORY "${LIBDIR}")
|
||||
message(FATAL_ERROR "Cannot find compiler-rt directory on OS X required for LLVM_USE_SANITIZER")
|
||||
endif()
|
||||
set(LIBCXX_SANITIZER_LIBRARY "${LIBDIR}/${LIBFILE}")
|
||||
set(LIBCXX_SANITIZER_LIBRARY "${LIBCXX_SANITIZER_LIBRARY}" PARENT_SCOPE)
|
||||
message(STATUS "Manually linking compiler-rt library: ${LIBCXX_SANITIZER_LIBRARY}")
|
||||
target_link_libraries(cxx "${LIBCXX_SANITIZER_LIBRARY}")
|
||||
target_link_libraries(cxx "-Wl,-rpath,${LIBDIR}")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
|
||||
# Setup flags.
|
||||
append_if(LIBCXX_COMPILE_FLAGS LIBCXX_HAS_FPIC_FLAG -fPIC)
|
||||
|
||||
Reference in New Issue
Block a user