[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:
parent
40766f70a4
commit
938c96ef53
@ -68,6 +68,32 @@ if (LIBCXX_COVERAGE_LIBRARY)
|
|||||||
endif()
|
endif()
|
||||||
target_link_libraries(cxx ${libraries})
|
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.
|
# Setup flags.
|
||||||
append_if(LIBCXX_COMPILE_FLAGS LIBCXX_HAS_FPIC_FLAG -fPIC)
|
append_if(LIBCXX_COMPILE_FLAGS LIBCXX_HAS_FPIC_FLAG -fPIC)
|
||||||
|
@ -623,6 +623,8 @@ class Configuration(object):
|
|||||||
'-fno-sanitize-recover']
|
'-fno-sanitize-recover']
|
||||||
self.cxx.compile_flags += ['-O3']
|
self.cxx.compile_flags += ['-O3']
|
||||||
self.config.available_features.add('ubsan')
|
self.config.available_features.add('ubsan')
|
||||||
|
if self.target_info.platform() == 'darwin':
|
||||||
|
self.config.available_features.add('sanitizer-new-delete')
|
||||||
elif san == 'Thread':
|
elif san == 'Thread':
|
||||||
self.cxx.flags += ['-fsanitize=thread']
|
self.cxx.flags += ['-fsanitize=thread']
|
||||||
self.config.available_features.add('tsan')
|
self.config.available_features.add('tsan')
|
||||||
@ -630,6 +632,10 @@ class Configuration(object):
|
|||||||
else:
|
else:
|
||||||
self.lit_config.fatal('unsupported value for '
|
self.lit_config.fatal('unsupported value for '
|
||||||
'use_sanitizer: {0}'.format(san))
|
'use_sanitizer: {0}'.format(san))
|
||||||
|
san_lib = self.get_lit_conf('sanitizer_library')
|
||||||
|
if san_lib:
|
||||||
|
self.cxx.link_flags += [
|
||||||
|
san_lib, '-Wl,-rpath,%s' % os.path.dirname(san_lib)]
|
||||||
|
|
||||||
def configure_coverage(self):
|
def configure_coverage(self):
|
||||||
self.generate_coverage = self.get_lit_bool('generate_coverage', False)
|
self.generate_coverage = self.get_lit_bool('generate_coverage', False)
|
||||||
|
@ -16,6 +16,7 @@ config.enable_thread_unsafe_c_functions = "@LIBCXX_ENABLE_THREAD_UNSAFE_C_FUNCTI
|
|||||||
config.enable_monotonic_clock = "@LIBCXX_ENABLE_MONOTONIC_CLOCK@"
|
config.enable_monotonic_clock = "@LIBCXX_ENABLE_MONOTONIC_CLOCK@"
|
||||||
config.cxx_abi = "@LIBCXX_CXX_ABI_LIBNAME@"
|
config.cxx_abi = "@LIBCXX_CXX_ABI_LIBNAME@"
|
||||||
config.use_sanitizer = "@LLVM_USE_SANITIZER@"
|
config.use_sanitizer = "@LLVM_USE_SANITIZER@"
|
||||||
|
config.sanitizer_library = "@LIBCXX_SANITIZER_LIBRARY@"
|
||||||
config.abi_library_path = "@LIBCXX_CXX_ABI_LIBRARY_PATH@"
|
config.abi_library_path = "@LIBCXX_CXX_ABI_LIBRARY_PATH@"
|
||||||
config.configuration_variant = "@LIBCXX_LIT_VARIANT@"
|
config.configuration_variant = "@LIBCXX_LIT_VARIANT@"
|
||||||
config.target_triple = "@LIBCXX_TARGET_TRIPLE@"
|
config.target_triple = "@LIBCXX_TARGET_TRIPLE@"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user