[compiler-rt] r354198 - [compiler-rt] Cleanup usage of C++ ABI library

Jonas Hahnfeld via llvm-commits llvm-commits at lists.llvm.org
Sat Feb 16 00:34:27 PST 2019


Author: hahnfeld
Date: Sat Feb 16 00:34:26 2019
New Revision: 354198

URL: http://llvm.org/viewvc/llvm-project?rev=354198&view=rev
Log:
[compiler-rt] Cleanup usage of C++ ABI library

Add missed value "libcxxabi" and introduce SANITIZER_TEST_CXX for linking
unit tests. This needs to be a full C++ library and cannot be libcxxabi.

Recommit r354132 which I reverted in r354153 because it broke a sanitizer
bot. This was because of the "fixes" for pthread linking, so I've removed
these changes.

Differential Revision: https://reviews.llvm.org/D58012

Modified:
    compiler-rt/trunk/CMakeLists.txt
    compiler-rt/trunk/lib/asan/CMakeLists.txt
    compiler-rt/trunk/lib/fuzzer/tests/CMakeLists.txt
    compiler-rt/trunk/lib/hwasan/CMakeLists.txt
    compiler-rt/trunk/lib/scudo/CMakeLists.txt
    compiler-rt/trunk/lib/scudo/standalone/tests/CMakeLists.txt
    compiler-rt/trunk/lib/tsan/dd/CMakeLists.txt
    compiler-rt/trunk/lib/tsan/tests/CMakeLists.txt
    compiler-rt/trunk/lib/ubsan/CMakeLists.txt
    compiler-rt/trunk/lib/xray/tests/CMakeLists.txt

Modified: compiler-rt/trunk/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/CMakeLists.txt?rev=354198&r1=354197&r2=354198&view=diff
==============================================================================
--- compiler-rt/trunk/CMakeLists.txt (original)
+++ compiler-rt/trunk/CMakeLists.txt Sat Feb 16 00:34:26 2019
@@ -197,26 +197,38 @@ if (cxxabi_supported AND SANITIZER_ALLOW
 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 @@ if("${CMAKE_SYSTEM_NAME}" STREQUAL "Fuch
   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.

Modified: compiler-rt/trunk/lib/asan/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/CMakeLists.txt?rev=354198&r1=354197&r2=354198&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/CMakeLists.txt (original)
+++ compiler-rt/trunk/lib/asan/CMakeLists.txt Sat Feb 16 00:34:26 2019
@@ -92,7 +92,7 @@ append_list_if(COMPILER_RT_HAS_FTLS_MODE
   -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)

Modified: compiler-rt/trunk/lib/fuzzer/tests/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/fuzzer/tests/CMakeLists.txt?rev=354198&r1=354197&r2=354198&view=diff
==============================================================================
--- compiler-rt/trunk/lib/fuzzer/tests/CMakeLists.txt (original)
+++ compiler-rt/trunk/lib/fuzzer/tests/CMakeLists.txt Sat Feb 16 00:34:26 2019
@@ -17,10 +17,11 @@ set_target_properties(FuzzerUnitTests PR
 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)

Modified: compiler-rt/trunk/lib/hwasan/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/hwasan/CMakeLists.txt?rev=354198&r1=354197&r2=354198&view=diff
==============================================================================
--- compiler-rt/trunk/lib/hwasan/CMakeLists.txt (original)
+++ compiler-rt/trunk/lib/hwasan/CMakeLists.txt Sat Feb 16 00:34:26 2019
@@ -56,7 +56,7 @@ append_list_if(COMPILER_RT_HAS_FTLS_MODE
   -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)

Modified: compiler-rt/trunk/lib/scudo/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/scudo/CMakeLists.txt?rev=354198&r1=354197&r2=354198&view=diff
==============================================================================
--- compiler-rt/trunk/lib/scudo/CMakeLists.txt (original)
+++ compiler-rt/trunk/lib/scudo/CMakeLists.txt Sat Feb 16 00:34:26 2019
@@ -37,7 +37,7 @@ if (FUCHSIA)
   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

Modified: compiler-rt/trunk/lib/scudo/standalone/tests/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/scudo/standalone/tests/CMakeLists.txt?rev=354198&r1=354197&r2=354198&view=diff
==============================================================================
--- compiler-rt/trunk/lib/scudo/standalone/tests/CMakeLists.txt (original)
+++ compiler-rt/trunk/lib/scudo/standalone/tests/CMakeLists.txt Sat Feb 16 00:34:26 2019
@@ -15,7 +15,11 @@ set(SCUDO_UNITTEST_CFLAGS
 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})

Modified: compiler-rt/trunk/lib/tsan/dd/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/dd/CMakeLists.txt?rev=354198&r1=354197&r2=354198&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/dd/CMakeLists.txt (original)
+++ compiler-rt/trunk/lib/tsan/dd/CMakeLists.txt Sat Feb 16 00:34:26 2019
@@ -10,7 +10,7 @@ set(DD_SOURCES
   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)

Modified: compiler-rt/trunk/lib/tsan/tests/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/tests/CMakeLists.txt?rev=354198&r1=354197&r2=354198&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/tests/CMakeLists.txt (original)
+++ compiler-rt/trunk/lib/tsan/tests/CMakeLists.txt Sat Feb 16 00:34:26 2019
@@ -14,6 +14,12 @@ set(TSAN_UNITTEST_CFLAGS
   -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 @@ if(APPLE)
   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)

Modified: compiler-rt/trunk/lib/ubsan/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/ubsan/CMakeLists.txt?rev=354198&r1=354197&r2=354198&view=diff
==============================================================================
--- compiler-rt/trunk/lib/ubsan/CMakeLists.txt (original)
+++ compiler-rt/trunk/lib/ubsan/CMakeLists.txt Sat Feb 16 00:34:26 2019
@@ -52,7 +52,7 @@ set(UBSAN_CXXFLAGS ${SANITIZER_COMMON_CF
 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)

Modified: compiler-rt/trunk/lib/xray/tests/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/xray/tests/CMakeLists.txt?rev=354198&r1=354197&r2=354198&view=diff
==============================================================================
--- compiler-rt/trunk/lib/xray/tests/CMakeLists.txt (original)
+++ compiler-rt/trunk/lib/xray/tests/CMakeLists.txt Sat Feb 16 00:34:26 2019
@@ -47,8 +47,7 @@ function(get_xray_lib_for_arch arch lib)
 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 @@ if (NOT APPLE)
   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})




More information about the llvm-commits mailing list