···11+From a56bb19a9dc303a50ef12d83cd24c2395bf81076 Mon Sep 17 00:00:00 2001
22+From: Ben Wolsieffer <benwolsieffer@gmail.com>
33+Date: Wed, 7 Dec 2022 21:25:46 -0500
44+Subject: [PATCH] [scudo][standalone] Use CheckAtomic to decide to link to
55+ libatomic
66+77+Standalone scudo uses the atomic operation builtin functions, which require
88+linking to libatomic on some platforms. Currently, this is done in an ad-hoc
99+manner. MIPS platforms always link to libatomic, and the tests are always linked
1010+to it as well. libatomic is required on base ARMv6 (but not ARMv6K), but it is
1111+currently not linked, causing the build to fail.
1212+1313+This patch replaces this ad-hoc logic with the CheckAtomic CMake module already
1414+used in other parts of LLVM. The CheckAtomic module checks whether std::atomic
1515+requires libatomic, which is not strictly the same as checking the atomic
1616+builtins, but should have the same results as far as I know. If this is
1717+problematic, a custom version of CheckAtomic could be used to specifically test
1818+the builtins.
1919+---
2020+ compiler-rt/lib/scudo/standalone/CMakeLists.txt | 7 +++++++
2121+ compiler-rt/lib/scudo/standalone/tests/CMakeLists.txt | 4 +---
2222+ 2 files changed, 8 insertions(+), 3 deletions(-)
2323+2424+diff --git a/lib/scudo/standalone/CMakeLists.txt b/lib/scudo/standalone/CMakeLists.txt
2525+index ae5c354768c8..eb27374ca520 100644
2626+--- a/lib/scudo/standalone/CMakeLists.txt
2727++++ b/lib/scudo/standalone/CMakeLists.txt
2828+@@ -1,5 +1,8 @@
2929+ add_compiler_rt_component(scudo_standalone)
3030+3131++include(DetermineGCCCompatible)
3232++include(CheckAtomic)
3333++
3434+ include_directories(../.. include)
3535+3636+ set(SCUDO_CFLAGS)
3737+@@ -34,6 +37,10 @@ list(APPEND SCUDO_LINK_FLAGS -Wl,-z,defs,-z,now,-z,relro)
3838+3939+ list(APPEND SCUDO_LINK_FLAGS -ffunction-sections -fdata-sections -Wl,--gc-sections)
4040+4141++if(HAVE_CXX_ATOMICS_WITH_LIB OR HAVE_CXX_ATOMICS64_WITH_LIB)
4242++ list(APPEND SCUDO_LINK_FLAGS -latomic)
4343++endif()
4444++
4545+ # We don't use the C++ standard library, so avoid including it by mistake.
4646+ append_list_if(COMPILER_RT_HAS_NOSTDLIBXX_FLAG -nostdlib++ SCUDO_LINK_FLAGS)
4747+ append_list_if(CXX_SUPPORTS_UNWINDLIB_NONE_FLAG --unwindlib=none SCUDO_LINK_FLAGS)
4848+diff --git a/lib/scudo/standalone/tests/CMakeLists.txt b/lib/scudo/standalone/tests/CMakeLists.txt
4949+index 8200cd2588b3..73b3e9403c35 100644
5050+--- a/lib/scudo/standalone/tests/CMakeLists.txt
5151++++ b/lib/scudo/standalone/tests/CMakeLists.txt
5252+@@ -39,9 +39,7 @@ set(SCUDO_UNITTEST_LINK_FLAGS
5353+ ${COMPILER_RT_UNWINDER_LINK_LIBS}
5454+ ${SANITIZER_TEST_CXX_LIBRARIES})
5555+ list(APPEND SCUDO_UNITTEST_LINK_FLAGS -pthread -no-pie)
5656+-# Linking against libatomic is required with some compilers
5757+-check_library_exists(atomic __atomic_load_8 "" COMPILER_RT_HAS_LIBATOMIC)
5858+-if (COMPILER_RT_HAS_LIBATOMIC)
5959++if (HAVE_CXX_ATOMICS_WITH_LIB OR HAVE_CXX_ATOMICS64_WITH_LIB)
6060+ list(APPEND SCUDO_UNITTEST_LINK_FLAGS -latomic)
6161+ endif()
6262+6363+--
6464+2.38.1
6565+
···11+From a56bb19a9dc303a50ef12d83cd24c2395bf81076 Mon Sep 17 00:00:00 2001
22+From: Ben Wolsieffer <benwolsieffer@gmail.com>
33+Date: Wed, 7 Dec 2022 21:25:46 -0500
44+Subject: [PATCH] [scudo][standalone] Use CheckAtomic to decide to link to
55+ libatomic
66+77+Standalone scudo uses the atomic operation builtin functions, which require
88+linking to libatomic on some platforms. Currently, this is done in an ad-hoc
99+manner. MIPS platforms always link to libatomic, and the tests are always linked
1010+to it as well. libatomic is required on base ARMv6 (but not ARMv6K), but it is
1111+currently not linked, causing the build to fail.
1212+1313+This patch replaces this ad-hoc logic with the CheckAtomic CMake module already
1414+used in other parts of LLVM. The CheckAtomic module checks whether std::atomic
1515+requires libatomic, which is not strictly the same as checking the atomic
1616+builtins, but should have the same results as far as I know. If this is
1717+problematic, a custom version of CheckAtomic could be used to specifically test
1818+the builtins.
1919+---
2020+ compiler-rt/lib/scudo/standalone/CMakeLists.txt | 7 +++++++
2121+ compiler-rt/lib/scudo/standalone/tests/CMakeLists.txt | 4 +---
2222+ 2 files changed, 8 insertions(+), 3 deletions(-)
2323+2424+diff --git a/lib/scudo/standalone/CMakeLists.txt b/lib/scudo/standalone/CMakeLists.txt
2525+index dc700cec9bec..671dc7046604 100644
2626+--- a/lib/scudo/standalone/CMakeLists.txt
2727++++ b/lib/scudo/standalone/CMakeLists.txt
2828+@@ -1,5 +1,8 @@
2929+ add_compiler_rt_component(scudo_standalone)
3030+3131++include(DetermineGCCCompatible)
3232++include(CheckAtomic)
3333++
3434+ include_directories(../.. include)
3535+3636+ set(SCUDO_CFLAGS)
3737+@@ -39,6 +42,10 @@ list(APPEND SCUDO_LINK_FLAGS -Wl,-z,defs,-z,now,-z,relro)
3838+3939+ list(APPEND SCUDO_LINK_FLAGS -ffunction-sections -fdata-sections -Wl,--gc-sections)
4040+4141++if(HAVE_CXX_ATOMICS_WITH_LIB OR HAVE_CXX_ATOMICS64_WITH_LIB)
4242++ list(APPEND SCUDO_LINK_FLAGS -latomic)
4343++endif()
4444++
4545+ # We don't use the C++ standard library, so avoid including it by mistake.
4646+ append_list_if(COMPILER_RT_HAS_NOSTDLIBXX_FLAG -nostdlib++ SCUDO_LINK_FLAGS)
4747+ append_list_if(CXX_SUPPORTS_UNWINDLIB_NONE_FLAG --unwindlib=none SCUDO_LINK_FLAGS)
4848+diff --git a/lib/scudo/standalone/tests/CMakeLists.txt b/lib/scudo/standalone/tests/CMakeLists.txt
4949+index a85eb737dba0..a23cf4d494f6 100644
5050+--- a/lib/scudo/standalone/tests/CMakeLists.txt
5151++++ b/lib/scudo/standalone/tests/CMakeLists.txt
5252+@@ -47,7 +47,7 @@ set(SCUDO_UNITTEST_LINK_FLAGS
5353+ ${SANITIZER_TEST_CXX_LIBRARIES})
5454+ list(APPEND SCUDO_UNITTEST_LINK_FLAGS -pthread -no-pie)
5555+5656+-append_list_if(COMPILER_RT_HAS_LIBATOMIC -latomic SCUDO_UNITTEST_LINK_FLAGS)
5757++append_list_if((HAVE_CXX_ATOMICS_WITH_LIB OR HAVE_CXX_ATOMICS64_WITH_LIB) -latomic SCUDO_UNITTEST_LINK_FLAGS)
5858+5959+ set(SCUDO_TEST_HEADERS
6060+ scudo_unit_test.h
6161+2.38.1
6262+