compiler-rt: apply armv6l patches to llvm >= 15 where applicable (#333922)

authored by Guillaume Girol and committed by GitHub 07c89965 ae51a986

+154 -6
+65
pkgs/development/compilers/llvm/15/compiler-rt/armv6-scudo-libatomic.patch
··· 1 + From a56bb19a9dc303a50ef12d83cd24c2395bf81076 Mon Sep 17 00:00:00 2001 2 + From: Ben Wolsieffer <benwolsieffer@gmail.com> 3 + Date: Wed, 7 Dec 2022 21:25:46 -0500 4 + Subject: [PATCH] [scudo][standalone] Use CheckAtomic to decide to link to 5 + libatomic 6 + 7 + Standalone scudo uses the atomic operation builtin functions, which require 8 + linking to libatomic on some platforms. Currently, this is done in an ad-hoc 9 + manner. MIPS platforms always link to libatomic, and the tests are always linked 10 + to it as well. libatomic is required on base ARMv6 (but not ARMv6K), but it is 11 + currently not linked, causing the build to fail. 12 + 13 + This patch replaces this ad-hoc logic with the CheckAtomic CMake module already 14 + used in other parts of LLVM. The CheckAtomic module checks whether std::atomic 15 + requires libatomic, which is not strictly the same as checking the atomic 16 + builtins, but should have the same results as far as I know. If this is 17 + problematic, a custom version of CheckAtomic could be used to specifically test 18 + the 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 + 24 + diff --git a/lib/scudo/standalone/CMakeLists.txt b/lib/scudo/standalone/CMakeLists.txt 25 + index 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) 48 + diff --git a/lib/scudo/standalone/tests/CMakeLists.txt b/lib/scudo/standalone/tests/CMakeLists.txt 49 + index 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 + -- 64 + 2.38.1 65 +
+62
pkgs/development/compilers/llvm/19/compiler-rt/armv6-scudo-libatomic.patch
··· 1 + From a56bb19a9dc303a50ef12d83cd24c2395bf81076 Mon Sep 17 00:00:00 2001 2 + From: Ben Wolsieffer <benwolsieffer@gmail.com> 3 + Date: Wed, 7 Dec 2022 21:25:46 -0500 4 + Subject: [PATCH] [scudo][standalone] Use CheckAtomic to decide to link to 5 + libatomic 6 + 7 + Standalone scudo uses the atomic operation builtin functions, which require 8 + linking to libatomic on some platforms. Currently, this is done in an ad-hoc 9 + manner. MIPS platforms always link to libatomic, and the tests are always linked 10 + to it as well. libatomic is required on base ARMv6 (but not ARMv6K), but it is 11 + currently not linked, causing the build to fail. 12 + 13 + This patch replaces this ad-hoc logic with the CheckAtomic CMake module already 14 + used in other parts of LLVM. The CheckAtomic module checks whether std::atomic 15 + requires libatomic, which is not strictly the same as checking the atomic 16 + builtins, but should have the same results as far as I know. If this is 17 + problematic, a custom version of CheckAtomic could be used to specifically test 18 + the 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 + 24 + diff --git a/lib/scudo/standalone/CMakeLists.txt b/lib/scudo/standalone/CMakeLists.txt 25 + index 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) 48 + diff --git a/lib/scudo/standalone/tests/CMakeLists.txt b/lib/scudo/standalone/tests/CMakeLists.txt 49 + index 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 61 + 2.38.1 62 +
pkgs/development/compilers/llvm/common/compiler-rt/armv6-scudo-libatomic.patch pkgs/development/compilers/llvm/14/compiler-rt/armv6-scudo-libatomic.patch
+27 -6
pkgs/development/compilers/llvm/common/default.nix
··· 192 192 path = ../12; 193 193 } 194 194 ]; 195 + "compiler-rt/armv6-scudo-libatomic.patch" = [ 196 + { 197 + after = "19"; 198 + path = ../19; 199 + } 200 + { 201 + after = "15"; 202 + before = "19"; 203 + path = ../15; 204 + } 205 + { 206 + before = "15"; 207 + path = ../14; 208 + } 209 + ]; 195 210 "compiler-rt/armv7l.patch" = [ 196 211 { 197 212 before = "15"; ··· 935 950 lib.optional (lib.versionOlder metadata.release_version "18") 936 951 # Prevent a compilation error on darwin 937 952 (metadata.getVersionFile "compiler-rt/darwin-targetconditionals.patch") 938 - ++ 939 - lib.optional (lib.versionAtLeast metadata.release_version "15") 940 - # See: https://github.com/NixOS/nixpkgs/pull/186575 941 - ./compiler-rt/darwin-plistbuddy-workaround.patch 953 + ++ lib.optionals (lib.versionAtLeast metadata.release_version "15") [ 954 + # See: https://github.com/NixOS/nixpkgs/pull/186575 955 + ./compiler-rt/darwin-plistbuddy-workaround.patch 956 + ] 942 957 ++ 943 958 lib.optional (lib.versions.major metadata.release_version == "15") 944 959 # See: https://github.com/NixOS/nixpkgs/pull/194634#discussion_r999829893 ··· 949 964 # Fix build on armv6l 950 965 ./compiler-rt/armv6-mcr-dmb.patch 951 966 ./compiler-rt/armv6-sync-ops-no-thumb.patch 952 - ./compiler-rt/armv6-no-ldrexd-strexd.patch 967 + ] 968 + ++ lib.optionals (lib.versionOlder metadata.release_version "18") [ 969 + # Fix build on armv6l 953 970 ./compiler-rt/armv6-scudo-no-yield.patch 954 - ./compiler-rt/armv6-scudo-libatomic.patch 971 + ] 972 + ++ [ 973 + # Fix build on armv6l 974 + ./compiler-rt/armv6-no-ldrexd-strexd.patch 975 + (metadata.getVersionFile "compiler-rt/armv6-scudo-libatomic.patch") 955 976 ] 956 977 ++ lib.optional (lib.versionAtLeast metadata.release_version "19") (fetchpatch { 957 978 url = "https://github.com/llvm/llvm-project/pull/99837/commits/14ae0a660a38e1feb151928a14f35ff0f4487351.patch";