Index: compiler-rt/lib/scudo/standalone/CMakeLists.txt =================================================================== --- compiler-rt/lib/scudo/standalone/CMakeLists.txt +++ compiler-rt/lib/scudo/standalone/CMakeLists.txt @@ -1,5 +1,7 @@ add_compiler_rt_component(scudo_standalone) +include(CheckAtomic) + include_directories(../.. include) set(SCUDO_CFLAGS) @@ -33,7 +35,7 @@ append_list_if(COMPILER_RT_HAS_WTHREAD_SAFETY_FLAG -Werror=thread-safety SCUDO_CFLAGS) -set(SCUDO_LINK_FLAGS) +set(SCUDO_LINK_FLAGS ${LLVM_ATOMIC_LIB}) list(APPEND SCUDO_LINK_FLAGS -Wl,-z,defs,-z,now,-z,relro) @@ -185,10 +187,6 @@ append_list_if(FUCHSIA zircon SCUDO_LINK_LIBS) -if(COMPILER_RT_DEFAULT_TARGET_ARCH MATCHES "mips|mips64|mipsel|mips64el") - list(APPEND SCUDO_LINK_LIBS atomic) -endif() - if(COMPILER_RT_HAS_SCUDO_STANDALONE) add_compiler_rt_object_libraries(RTScudoStandalone ARCHS ${SCUDO_STANDALONE_SUPPORTED_ARCH} 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 @@ -43,13 +43,9 @@ set(SCUDO_UNITTEST_LINK_FLAGS ${COMPILER_RT_UNITTEST_LINK_FLAGS} ${COMPILER_RT_UNWINDER_LINK_LIBS} - ${SANITIZER_TEST_CXX_LIBRARIES}) + ${SANITIZER_TEST_CXX_LIBRARIES} + ${LLVM_ATOMIC_LIB}) list(APPEND SCUDO_UNITTEST_LINK_FLAGS -pthread -no-pie) -# Linking against libatomic is required with some compilers -check_library_exists(atomic __atomic_load_8 "" COMPILER_RT_HAS_LIBATOMIC) -if (COMPILER_RT_HAS_LIBATOMIC) - list(APPEND SCUDO_UNITTEST_LINK_FLAGS -latomic) -endif() set(SCUDO_TEST_HEADERS scudo_unit_test.h Index: llvm/cmake/modules/CheckAtomic.cmake =================================================================== --- llvm/cmake/modules/CheckAtomic.cmake +++ llvm/cmake/modules/CheckAtomic.cmake @@ -2,6 +2,7 @@ INCLUDE(CheckCXXSourceCompiles) INCLUDE(CheckLibraryExists) +INCLUDE(DetermineGCCCompatible) # Sometimes linking against libatomic is required for atomic ops, if # the platform doesn't support lock-free atomics.