Index: lib/CMakeLists.txt =================================================================== --- lib/CMakeLists.txt +++ lib/CMakeLists.txt @@ -68,6 +68,32 @@ 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) Index: test/libcxx/test/config.py =================================================================== --- test/libcxx/test/config.py +++ test/libcxx/test/config.py @@ -623,6 +623,8 @@ '-fno-sanitize-recover'] self.cxx.compile_flags += ['-O3'] self.config.available_features.add('ubsan') + if self.target_info.platform() == 'darwin': + self.config.available_features.add('sanitizer-new-delete') elif san == 'Thread': self.cxx.flags += ['-fsanitize=thread'] self.config.available_features.add('tsan') @@ -630,6 +632,10 @@ else: self.lit_config.fatal('unsupported value for ' '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): self.generate_coverage = self.get_lit_bool('generate_coverage', False) Index: test/lit.site.cfg.in =================================================================== --- test/lit.site.cfg.in +++ test/lit.site.cfg.in @@ -16,6 +16,7 @@ config.enable_monotonic_clock = "@LIBCXX_ENABLE_MONOTONIC_CLOCK@" config.cxx_abi = "@LIBCXX_CXX_ABI_LIBNAME@" config.use_sanitizer = "@LLVM_USE_SANITIZER@" +config.sanitizer_library = "@LIBCXX_SANITIZER_LIBRARY@" config.abi_library_path = "@LIBCXX_CXX_ABI_LIBRARY_PATH@" config.configuration_variant = "@LIBCXX_LIT_VARIANT@" config.target_triple = "@LIBCXX_TARGET_TRIPLE@"