Index: compiler-rt/trunk/CMakeLists.txt =================================================================== --- compiler-rt/trunk/CMakeLists.txt +++ compiler-rt/trunk/CMakeLists.txt @@ -197,26 +197,38 @@ endif() pythonize_bool(SANITIZER_CAN_USE_CXXABI) +macro(handle_default_cxx_lib var) + if (${var} STREQUAL "default") + if (APPLE OR CMAKE_SYSTEM_NAME MATCHES "FreeBSD") + set(${var}_LIBNAME "libc++") + set(${var}_SYSTEM 1) + elseif (FUCHSIA) + set(${var}_LIBNAME "libc++") + set(${var}_INTREE 1) + else() + set(${var}_LIBNAME "libstdc++") + set(${var}_SYSTEM 1) + endif() + else() + set(${var}_LIBNAME "${${var}}") + set(${var}_SYSTEM 1) + endif() +endmacro() + +# This is either directly the C++ ABI library or the full C++ library +# which pulls in the ABI transitively. set(SANITIZER_CXX_ABI "default" CACHE STRING "Specify C++ ABI library to use.") -set(CXXABIS none default libstdc++ libc++) +set(CXXABIS none default libstdc++ libc++ libcxxabi) set_property(CACHE SANITIZER_CXX_ABI PROPERTY STRINGS ;${CXXABIS}) +handle_default_cxx_lib(SANITIZER_CXX_ABI) -if (SANITIZER_CXX_ABI STREQUAL "default") - if (APPLE OR CMAKE_SYSTEM_NAME MATCHES "FreeBSD") - set(SANITIZER_CXX_ABI_LIBNAME "libc++") - set(SANITIZER_CXX_ABI_SYSTEM 1) - elseif (FUCHSIA) - set(SANITIZER_CXX_ABI_LIBNAME "libc++") - set(SANITIZER_CXX_ABI_INTREE 1) - else() - set(SANITIZER_CXX_ABI_LIBNAME "libstdc++") - set(SANITIZER_CXX_ABI_SYSTEM 1) - endif() -else() - set(SANITIZER_CXX_ABI_LIBNAME "${SANITIZER_CXX_ABI}") - set(SANITIZER_CXX_ABI_SYSTEM 1) -endif() +# This needs to be a full C++ library for linking gtest and unit tests. +set(SANITIZER_TEST_CXX "default" CACHE STRING + "Specify C++ library to use for tests.") +set(CXXLIBS none default libstdc++ libc++) +set_property(CACHE SANITIZER_TEST_CXX PROPERTY STRINGS ;${CXXLIBS}) +handle_default_cxx_lib(SANITIZER_TEST_CXX) set(DEFAULT_SANITIZER_USE_STATIC_LLVM_UNWINDER OFF) if (FUCHSIA) @@ -412,26 +424,36 @@ list(APPEND SANITIZER_COMMON_LINK_LIBS zircon) endif() -if (SANITIZER_CXX_ABI_LIBNAME STREQUAL "libc++") - if (SANITIZER_CXX_ABI_INTREE) +macro(append_libcxx_libs var) + if (${var}_INTREE) if (SANITIZER_USE_STATIC_LLVM_UNWINDER AND (TARGET unwind_static OR HAVE_LIBUNWIND)) - list(APPEND SANITIZER_CXX_ABI_LIBRARY unwind_static) + list(APPEND ${var}_LIBRARIES unwind_static) elseif (TARGET unwind_shared OR HAVE_LIBUNWIND) - list(APPEND SANITIZER_CXX_ABI_LIBRARY unwind_shared) + list(APPEND ${var}_LIBRARIES unwind_shared) endif() if (SANITIZER_USE_STATIC_CXX_ABI AND (TARGET cxxabi_static OR HAVE_LIBCXXABI)) - list(APPEND SANITIZER_CXX_ABI_LIBRARY cxxabi_static) + list(APPEND ${var}_LIBRARIES cxxabi_static) elseif (TARGET cxxabi_shared OR HAVE_LIBCXXABI) - list(APPEND SANITIZER_CXX_ABI_LIBRARY cxxabi_shared) + list(APPEND ${var}_LIBRARIES cxxabi_shared) endif() else() - append_list_if(COMPILER_RT_HAS_LIBCXX c++ SANITIZER_CXX_ABI_LIBRARY) + append_list_if(COMPILER_RT_HAS_LIBCXX c++ ${var}_LIBRARIES) endif() +endmacro() + +if (SANITIZER_CXX_ABI_LIBNAME STREQUAL "libc++") + append_libcxx_libs(SANITIZER_CXX_ABI) elseif (SANITIZER_CXX_ABI_LIBNAME STREQUAL "libcxxabi") - list(APPEND SANITIZER_CXX_ABI_LIBRARY "c++abi") + list(APPEND SANITIZER_CXX_ABI_LIBRARIES "c++abi") elseif (SANITIZER_CXX_ABI_LIBNAME STREQUAL "libstdc++") - append_list_if(COMPILER_RT_HAS_LIBSTDCXX stdc++ SANITIZER_CXX_ABI_LIBRARY) + append_list_if(COMPILER_RT_HAS_LIBSTDCXX stdc++ SANITIZER_CXX_ABI_LIBRARIES) +endif() + +if (SANITIZER_TEST_CXX_LIBNAME STREQUAL "libc++") + append_libcxx_libs(SANITIZER_TEST_CXX) +elseif (SANITIZER_TEST_CXX_LIBNAME STREQUAL "libstdc++") + append_list_if(COMPILER_RT_HAS_LIBSTDCXX stdc++ SANITIZER_TEST_CXX_LIBRARIES) endif() # Warnings to turn off for all libraries, not just sanitizers. Index: compiler-rt/trunk/lib/asan/CMakeLists.txt =================================================================== --- compiler-rt/trunk/lib/asan/CMakeLists.txt +++ compiler-rt/trunk/lib/asan/CMakeLists.txt @@ -92,7 +92,7 @@ -ftls-model=initial-exec ASAN_DYNAMIC_CFLAGS) append_list_if(MSVC /DEBUG ASAN_DYNAMIC_LINK_FLAGS) -set(ASAN_DYNAMIC_LIBS ${SANITIZER_CXX_ABI_LIBRARY} ${SANITIZER_COMMON_LINK_LIBS}) +set(ASAN_DYNAMIC_LIBS ${SANITIZER_CXX_ABI_LIBRARIES} ${SANITIZER_COMMON_LINK_LIBS}) append_list_if(COMPILER_RT_HAS_LIBDL dl ASAN_DYNAMIC_LIBS) append_list_if(COMPILER_RT_HAS_LIBRT rt ASAN_DYNAMIC_LIBS) Index: compiler-rt/trunk/lib/fuzzer/tests/CMakeLists.txt =================================================================== --- compiler-rt/trunk/lib/fuzzer/tests/CMakeLists.txt +++ compiler-rt/trunk/lib/fuzzer/tests/CMakeLists.txt @@ -17,10 +17,11 @@ set(LIBFUZZER_UNITTEST_LINK_FLAGS ${COMPILER_RT_UNITTEST_LINK_FLAGS}) list(APPEND LIBFUZZER_UNITTEST_LINK_FLAGS --driver-mode=g++) -if(APPLE OR CMAKE_SYSTEM_NAME STREQUAL "FreeBSD") - list(APPEND LIBFUZZER_UNITTEST_LINK_FLAGS -lc++ -lpthread) -elseif(NOT WIN32) - list(APPEND LIBFUZZER_UNITTEST_LINK_FLAGS -lstdc++ -lpthread) +foreach(lib ${SANITIZER_TEST_CXX_LIBRARIES}) + list(APPEND LIBFUZZER_UNITTEST_LINK_FLAGS -l${lib}) +endforeach() +if(NOT WIN32) + list(APPEND LIBFUZZER_UNITTEST_LINK_FLAGS -lpthread) endif() if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux" AND COMPILER_RT_LIBCXX_PATH) Index: compiler-rt/trunk/lib/hwasan/CMakeLists.txt =================================================================== --- compiler-rt/trunk/lib/hwasan/CMakeLists.txt +++ compiler-rt/trunk/lib/hwasan/CMakeLists.txt @@ -56,7 +56,7 @@ -ftls-model=initial-exec HWASAN_DYNAMIC_CFLAGS) append_list_if(MSVC /DEBUG HWASAN_DYNAMIC_LINK_FLAGS) -set(HWASAN_DYNAMIC_LIBS ${SANITIZER_CXX_ABI_LIBRARY} ${SANITIZER_COMMON_LINK_LIBS}) +set(HWASAN_DYNAMIC_LIBS ${SANITIZER_CXX_ABI_LIBRARIES} ${SANITIZER_COMMON_LINK_LIBS}) append_list_if(COMPILER_RT_HAS_LIBDL dl HWASAN_DYNAMIC_LIBS) append_list_if(COMPILER_RT_HAS_LIBRT rt HWASAN_DYNAMIC_LIBS) Index: compiler-rt/trunk/lib/scudo/CMakeLists.txt =================================================================== --- compiler-rt/trunk/lib/scudo/CMakeLists.txt +++ compiler-rt/trunk/lib/scudo/CMakeLists.txt @@ -37,7 +37,7 @@ list(APPEND SCUDO_CFLAGS -nostdinc++) list(APPEND SCUDO_DYNAMIC_LINK_FLAGS -nostdlib++) else() - list(APPEND SCUDO_DYNAMIC_LIBS ${SANITIZER_CXX_ABI_LIBRARY}) + list(APPEND SCUDO_DYNAMIC_LIBS ${SANITIZER_CXX_ABI_LIBRARIES}) list(APPEND SCUDO_OBJECT_LIBS RTSanitizerCommonCoverage RTSanitizerCommonSymbolizer Index: compiler-rt/trunk/lib/scudo/standalone/tests/CMakeLists.txt =================================================================== --- compiler-rt/trunk/lib/scudo/standalone/tests/CMakeLists.txt +++ compiler-rt/trunk/lib/scudo/standalone/tests/CMakeLists.txt @@ -15,7 +15,11 @@ set(SCUDO_TEST_ARCH ${SCUDO_SUPPORTED_ARCH}) # gtests requires c++ -set(LINK_FLAGS -lstdc++ -pthread) +set(LINK_FLAGS) +foreach(lib ${SANITIZER_TEST_CXX_LIBRARIES}) + list(APPEND LINK_FLAGS -l${lib}) +endforeach() +list(APPEND LINK_FLAGS -pthread) set(TEST_HEADERS) foreach (header ${SCUDO_HEADERS}) Index: compiler-rt/trunk/lib/tsan/dd/CMakeLists.txt =================================================================== --- compiler-rt/trunk/lib/tsan/dd/CMakeLists.txt +++ compiler-rt/trunk/lib/tsan/dd/CMakeLists.txt @@ -10,7 +10,7 @@ dd_interceptors.cc ) -set(DD_LINKLIBS ${SANITIZER_CXX_ABI_LIBRARY} ${SANITIZER_COMMON_LINK_LIBS}) +set(DD_LINKLIBS ${SANITIZER_CXX_ABI_LIBRARIES} ${SANITIZER_COMMON_LINK_LIBS}) append_list_if(COMPILER_RT_HAS_LIBDL dl DD_LINKLIBS) append_list_if(COMPILER_RT_HAS_LIBRT rt DD_LINKLIBS) Index: compiler-rt/trunk/lib/tsan/tests/CMakeLists.txt =================================================================== --- compiler-rt/trunk/lib/tsan/tests/CMakeLists.txt +++ compiler-rt/trunk/lib/tsan/tests/CMakeLists.txt @@ -14,6 +14,12 @@ -DGTEST_HAS_RTTI=0) set(TSAN_TEST_ARCH ${TSAN_SUPPORTED_ARCH}) + +set(LINK_FLAGS) +foreach(lib ${SANITIZER_TEST_CXX_LIBRARIES}) + list(APPEND LINK_FLAGS -l${lib}) +endforeach() + if(APPLE) # Create a static library for test dependencies. @@ -33,12 +39,12 @@ darwin_filter_host_archs(TSAN_SUPPORTED_ARCH TSAN_TEST_ARCH) list(APPEND TSAN_UNITTEST_CFLAGS ${DARWIN_osx_CFLAGS}) - set(LINK_FLAGS "-lc++") list(APPEND LINK_FLAGS ${DARWIN_osx_LINK_FLAGS}) add_weak_symbols("ubsan" LINK_FLAGS) add_weak_symbols("sanitizer_common" LINK_FLAGS) else() - set(LINK_FLAGS "-fsanitize=thread;-lstdc++;-lm") + list(APPEND LINK_FLAGS -fsanitize=thread) + list(APPEND LINK_FLAGS -lm) endif() set(TSAN_RTL_HEADERS) Index: compiler-rt/trunk/lib/ubsan/CMakeLists.txt =================================================================== --- compiler-rt/trunk/lib/ubsan/CMakeLists.txt +++ compiler-rt/trunk/lib/ubsan/CMakeLists.txt @@ -52,7 +52,7 @@ append_rtti_flag(ON UBSAN_CXXFLAGS) append_list_if(SANITIZER_CAN_USE_CXXABI -DUBSAN_CAN_USE_CXXABI UBSAN_CXXFLAGS) -set(UBSAN_DYNAMIC_LIBS ${SANITIZER_CXX_ABI_LIBRARY} ${SANITIZER_COMMON_LINK_LIBS}) +set(UBSAN_DYNAMIC_LIBS ${SANITIZER_CXX_ABI_LIBRARIES} ${SANITIZER_COMMON_LINK_LIBS}) append_list_if(COMPILER_RT_HAS_LIBDL dl UBSAN_DYNAMIC_LIBS) append_list_if(COMPILER_RT_HAS_LIBLOG log UBSAN_DYNAMIC_LIBS) Index: compiler-rt/trunk/lib/xray/tests/CMakeLists.txt =================================================================== --- compiler-rt/trunk/lib/xray/tests/CMakeLists.txt +++ compiler-rt/trunk/lib/xray/tests/CMakeLists.txt @@ -47,8 +47,7 @@ endfunction() set(XRAY_TEST_ARCH ${XRAY_SUPPORTED_ARCH}) -set(XRAY_UNITTEST_LINK_FLAGS - ${CMAKE_THREAD_LIBS_INIT}) +set(XRAY_UNITTEST_LINK_FLAGS ${CMAKE_THREAD_LIBS_INIT}) if (NOT APPLE) # Needed by LLVMSupport. @@ -80,7 +79,9 @@ append_list_if(COMPILER_RT_HAS_LIBEXECINFO -lexecinfo XRAY_UNITTEST_LINK_FLAGS) endif() -list(APPEND XRAY_UNITTEST_LINK_FLAGS -l${SANITIZER_CXX_ABI_LIBRARY}) +foreach(lib ${SANITIZER_TEST_CXX_LIBRARIES}) + list(APPEND XRAY_UNITTEST_LINK_FLAGS -l${lib}) +endforeach() macro(add_xray_unittest testname) cmake_parse_arguments(TEST "" "" "SOURCES;HEADERS" ${ARGN})