[PATCH] D11381: [libcxx] Add support for sanitizers on OS X.
Eric Fiselier
eric at efcs.ca
Mon Jul 20 19:29:01 PDT 2015
EricWF created this revision.
EricWF added a reviewer: mclow.lists.
EricWF added a subscriber: cfe-commits.
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.
http://reviews.llvm.org/D11381
Files:
lib/CMakeLists.txt
test/libcxx/test/config.py
test/lit.site.cfg.in
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@"
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: 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)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D11381.30229.patch
Type: text/x-patch
Size: 3245 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150721/2e2e8253/attachment.bin>
More information about the cfe-commits
mailing list