diff --git a/compiler-rt/lib/scudo/standalone/CMakeLists.txt b/compiler-rt/lib/scudo/standalone/CMakeLists.txt --- a/compiler-rt/lib/scudo/standalone/CMakeLists.txt +++ b/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) @@ -28,7 +30,7 @@ list(APPEND SCUDO_CFLAGS -O3) endif() -set(SCUDO_LINK_FLAGS) +set(SCUDO_LINK_FLAGS ${LLVM_ATOMIC_LIB}) list(APPEND SCUDO_LINK_FLAGS -Wl,-z,defs,-z,now,-z,relro) @@ -153,10 +155,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} diff --git a/compiler-rt/lib/scudo/standalone/tests/CMakeLists.txt b/compiler-rt/lib/scudo/standalone/tests/CMakeLists.txt --- a/compiler-rt/lib/scudo/standalone/tests/CMakeLists.txt +++ b/compiler-rt/lib/scudo/standalone/tests/CMakeLists.txt @@ -37,13 +37,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 diff --git a/llvm/cmake/modules/CheckAtomic.cmake b/llvm/cmake/modules/CheckAtomic.cmake --- a/llvm/cmake/modules/CheckAtomic.cmake +++ b/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.