at master 2.8 kB view raw
1From a56bb19a9dc303a50ef12d83cd24c2395bf81076 Mon Sep 17 00:00:00 2001 2From: Ben Wolsieffer <benwolsieffer@gmail.com> 3Date: Wed, 7 Dec 2022 21:25:46 -0500 4Subject: [PATCH] [scudo][standalone] Use CheckAtomic to decide to link to 5 libatomic 6 7Standalone scudo uses the atomic operation builtin functions, which require 8linking to libatomic on some platforms. Currently, this is done in an ad-hoc 9manner. MIPS platforms always link to libatomic, and the tests are always linked 10to it as well. libatomic is required on base ARMv6 (but not ARMv6K), but it is 11currently not linked, causing the build to fail. 12 13This patch replaces this ad-hoc logic with the CheckAtomic CMake module already 14used in other parts of LLVM. The CheckAtomic module checks whether std::atomic 15requires libatomic, which is not strictly the same as checking the atomic 16builtins, but should have the same results as far as I know. If this is 17problematic, a custom version of CheckAtomic could be used to specifically test 18the builtins. 19--- 20 compiler-rt/lib/scudo/standalone/CMakeLists.txt | 7 +++++++ 21 compiler-rt/lib/scudo/standalone/tests/CMakeLists.txt | 4 +--- 22 2 files changed, 8 insertions(+), 3 deletions(-) 23 24diff --git a/lib/scudo/standalone/CMakeLists.txt b/lib/scudo/standalone/CMakeLists.txt 25index ae5c354768c8..eb27374ca520 100644 26--- a/lib/scudo/standalone/CMakeLists.txt 27+++ b/lib/scudo/standalone/CMakeLists.txt 28@@ -1,5 +1,8 @@ 29 add_compiler_rt_component(scudo_standalone) 30 31+include(DetermineGCCCompatible) 32+include(CheckAtomic) 33+ 34 include_directories(../.. include) 35 36 set(SCUDO_CFLAGS) 37@@ -34,6 +37,10 @@ list(APPEND SCUDO_LINK_FLAGS -Wl,-z,defs,-z,now,-z,relro) 38 39 list(APPEND SCUDO_LINK_FLAGS -ffunction-sections -fdata-sections -Wl,--gc-sections) 40 41+if(HAVE_CXX_ATOMICS_WITH_LIB OR HAVE_CXX_ATOMICS64_WITH_LIB) 42+ list(APPEND SCUDO_LINK_FLAGS -latomic) 43+endif() 44+ 45 # We don't use the C++ standard library, so avoid including it by mistake. 46 append_list_if(COMPILER_RT_HAS_NOSTDLIBXX_FLAG -nostdlib++ SCUDO_LINK_FLAGS) 47 append_list_if(CXX_SUPPORTS_UNWINDLIB_NONE_FLAG --unwindlib=none SCUDO_LINK_FLAGS) 48diff --git a/lib/scudo/standalone/tests/CMakeLists.txt b/lib/scudo/standalone/tests/CMakeLists.txt 49index 8200cd2588b3..73b3e9403c35 100644 50--- a/lib/scudo/standalone/tests/CMakeLists.txt 51+++ b/lib/scudo/standalone/tests/CMakeLists.txt 52@@ -39,9 +39,7 @@ set(SCUDO_UNITTEST_LINK_FLAGS 53 ${COMPILER_RT_UNWINDER_LINK_LIBS} 54 ${SANITIZER_TEST_CXX_LIBRARIES}) 55 list(APPEND SCUDO_UNITTEST_LINK_FLAGS -pthread -no-pie) 56-# Linking against libatomic is required with some compilers 57-check_library_exists(atomic __atomic_load_8 "" COMPILER_RT_HAS_LIBATOMIC) 58-if (COMPILER_RT_HAS_LIBATOMIC) 59+if (HAVE_CXX_ATOMICS_WITH_LIB OR HAVE_CXX_ATOMICS64_WITH_LIB) 60 list(APPEND SCUDO_UNITTEST_LINK_FLAGS -latomic) 61 endif() 62 63-- 642.38.1 65