at master 2.7 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 dc700cec9bec..671dc7046604 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@@ -39,6 +42,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 a85eb737dba0..a23cf4d494f6 100644 50--- a/lib/scudo/standalone/tests/CMakeLists.txt 51+++ b/lib/scudo/standalone/tests/CMakeLists.txt 52@@ -47,7 +47,7 @@ set(SCUDO_UNITTEST_LINK_FLAGS 53 ${SANITIZER_TEST_CXX_LIBRARIES}) 54 list(APPEND SCUDO_UNITTEST_LINK_FLAGS -pthread -no-pie) 55 56-append_list_if(COMPILER_RT_HAS_LIBATOMIC -latomic SCUDO_UNITTEST_LINK_FLAGS) 57+append_list_if((HAVE_CXX_ATOMICS_WITH_LIB OR HAVE_CXX_ATOMICS64_WITH_LIB) -latomic SCUDO_UNITTEST_LINK_FLAGS) 58 59 set(SCUDO_TEST_HEADERS 60 scudo_unit_test.h 612.38.1 62