From a56bb19a9dc303a50ef12d83cd24c2395bf81076 Mon Sep 17 00:00:00 2001 From: Ben Wolsieffer Date: Wed, 7 Dec 2022 21:25:46 -0500 Subject: [PATCH] [scudo][standalone] Use CheckAtomic to decide to link to libatomic Standalone scudo uses the atomic operation builtin functions, which require linking to libatomic on some platforms. Currently, this is done in an ad-hoc manner. MIPS platforms always link to libatomic, and the tests are always linked to it as well. libatomic is required on base ARMv6 (but not ARMv6K), but it is currently not linked, causing the build to fail. This patch replaces this ad-hoc logic with the CheckAtomic CMake module already used in other parts of LLVM. The CheckAtomic module checks whether std::atomic requires libatomic, which is not strictly the same as checking the atomic builtins, but should have the same results as far as I know. If this is problematic, a custom version of CheckAtomic could be used to specifically test the builtins. --- compiler-rt/lib/scudo/standalone/CMakeLists.txt | 7 +++++++ compiler-rt/lib/scudo/standalone/tests/CMakeLists.txt | 4 +--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/scudo/standalone/CMakeLists.txt b/lib/scudo/standalone/CMakeLists.txt index ae5c354768c8..eb27374ca520 100644 --- a/lib/scudo/standalone/CMakeLists.txt +++ b/lib/scudo/standalone/CMakeLists.txt @@ -1,5 +1,8 @@ add_compiler_rt_component(scudo_standalone) +include(DetermineGCCCompatible) +include(CheckAtomic) + include_directories(../.. include) set(SCUDO_CFLAGS) @@ -34,6 +37,10 @@ list(APPEND SCUDO_LINK_FLAGS -Wl,-z,defs,-z,now,-z,relro) list(APPEND SCUDO_LINK_FLAGS -ffunction-sections -fdata-sections -Wl,--gc-sections) +if(HAVE_CXX_ATOMICS_WITH_LIB OR HAVE_CXX_ATOMICS64_WITH_LIB) + list(APPEND SCUDO_LINK_FLAGS -latomic) +endif() + # We don't use the C++ standard library, so avoid including it by mistake. append_list_if(COMPILER_RT_HAS_NOSTDLIBXX_FLAG -nostdlib++ SCUDO_LINK_FLAGS) diff --git a/lib/scudo/standalone/tests/CMakeLists.txt b/lib/scudo/standalone/tests/CMakeLists.txt index 6d0936cbb5c1..70a5a7e959c1 100644 --- a/lib/scudo/standalone/tests/CMakeLists.txt +++ b/lib/scudo/standalone/tests/CMakeLists.txt @@ -38,9 +38,7 @@ set(LINK_FLAGS ${SANITIZER_TEST_CXX_LIBRARIES} ) list(APPEND LINK_FLAGS -pthread) -# Linking against libatomic is required with some compilers -check_library_exists(atomic __atomic_load_8 "" COMPILER_RT_HAS_LIBATOMIC) -if (COMPILER_RT_HAS_LIBATOMIC) +if(HAVE_CXX_ATOMICS_WITH_LIB OR HAVE_CXX_ATOMICS64_WITH_LIB) list(APPEND LINK_FLAGS -latomic) endif() -- 2.38.1