Index: compiler-rt/CMakeLists.txt =================================================================== --- compiler-rt/CMakeLists.txt +++ compiler-rt/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. +set(SANITIZER_GTEST_CXX "default" CACHE STRING + "Specify C++ library to use for gtest.") +set(CXXLIBS none default libstdc++ libc++) +set_property(CACHE SANITIZER_GTEST_CXX PROPERTY STRINGS ;${CXXLIBS}) +handle_default_cxx_lib(SANITIZER_GTEST_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_GTEST_CXX_LIBNAME STREQUAL "libc++") + append_libcxx_libs(SANITIZER_GTEST_CXX) +elseif (SANITIZER_GTEST_CXX_LIBNAME STREQUAL "libstdc++") + append_list_if(COMPILER_RT_HAS_LIBSTDCXX stdc++ SANITIZER_GTEST_CXX_LIBRARIES) endif() # Warnings to turn off for all libraries, not just sanitizers. Index: compiler-rt/lib/asan/CMakeLists.txt =================================================================== --- compiler-rt/lib/asan/CMakeLists.txt +++ compiler-rt/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/lib/fuzzer/tests/CMakeLists.txt =================================================================== --- compiler-rt/lib/fuzzer/tests/CMakeLists.txt +++ compiler-rt/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_GTEST_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/lib/hwasan/CMakeLists.txt =================================================================== --- compiler-rt/lib/hwasan/CMakeLists.txt +++ compiler-rt/lib/hwasan/CMakeLists.txt @@ -55,7 +55,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/lib/scudo/CMakeLists.txt =================================================================== --- compiler-rt/lib/scudo/CMakeLists.txt +++ compiler-rt/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/lib/scudo/standalone/tests/CMakeLists.txt =================================================================== --- compiler-rt/lib/scudo/standalone/tests/CMakeLists.txt +++ compiler-rt/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_GTEST_CXX_LIBRARIES}) + list(APPEND LINK_FLAGS -l${lib}) +endforeach() +list(APPEND LINK_FLAGS -pthread) set(TEST_HEADERS) foreach (header ${SCUDO_HEADERS}) Index: compiler-rt/lib/tsan/dd/CMakeLists.txt =================================================================== --- compiler-rt/lib/tsan/dd/CMakeLists.txt +++ compiler-rt/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/lib/ubsan/CMakeLists.txt =================================================================== --- compiler-rt/lib/ubsan/CMakeLists.txt +++ compiler-rt/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/lib/xray/tests/CMakeLists.txt =================================================================== --- compiler-rt/lib/xray/tests/CMakeLists.txt +++ compiler-rt/lib/xray/tests/CMakeLists.txt @@ -47,9 +47,10 @@ endfunction() set(XRAY_TEST_ARCH ${XRAY_SUPPORTED_ARCH}) -set(XRAY_UNITTEST_LINK_FLAGS - ${CMAKE_THREAD_LIBS_INIT} - -l${SANITIZER_CXX_ABI_LIBRARY}) +set(XRAY_UNITTEST_LINK_FLAGS ${CMAKE_THREAD_LIBS_INIT}) +foreach(lib ${SANITIZER_GTEST_CXX_LIBRARIES}) + list(APPEND XRAY_UNITTEST_LINK_FLAGS -l${lib}) +endforeach() if (NOT APPLE) # Needed by LLVMSupport.