about summary refs log tree commit diff
path: root/nixpkgs/pkgs/development/compilers/llvm
diff options
context:
space:
mode:
Diffstat (limited to 'nixpkgs/pkgs/development/compilers/llvm')
-rw-r--r--nixpkgs/pkgs/development/compilers/llvm/10/bintools/default.nix34
-rw-r--r--nixpkgs/pkgs/development/compilers/llvm/10/compiler-rt/default.nix2
-rw-r--r--nixpkgs/pkgs/development/compilers/llvm/10/default.nix4
-rw-r--r--nixpkgs/pkgs/development/compilers/llvm/10/libcxxabi/default.nix4
-rw-r--r--nixpkgs/pkgs/development/compilers/llvm/11/bintools/default.nix34
-rw-r--r--nixpkgs/pkgs/development/compilers/llvm/11/compiler-rt/codesign.patch33
-rw-r--r--nixpkgs/pkgs/development/compilers/llvm/11/compiler-rt/default.nix2
-rw-r--r--nixpkgs/pkgs/development/compilers/llvm/11/default.nix4
-rw-r--r--nixpkgs/pkgs/development/compilers/llvm/11/libcxxabi/default.nix4
-rw-r--r--nixpkgs/pkgs/development/compilers/llvm/11/libcxxabi/no-threads.patch12
-rw-r--r--nixpkgs/pkgs/development/compilers/llvm/11/libcxxabi/wasm.patch16
-rw-r--r--nixpkgs/pkgs/development/compilers/llvm/12/bintools/default.nix34
-rw-r--r--nixpkgs/pkgs/development/compilers/llvm/12/compiler-rt/codesign.patch33
-rw-r--r--nixpkgs/pkgs/development/compilers/llvm/12/compiler-rt/default.nix2
-rw-r--r--nixpkgs/pkgs/development/compilers/llvm/12/default.nix17
-rw-r--r--nixpkgs/pkgs/development/compilers/llvm/12/libcxxabi/default.nix2
-rw-r--r--nixpkgs/pkgs/development/compilers/llvm/12/libcxxabi/wasm.patch16
-rw-r--r--nixpkgs/pkgs/development/compilers/llvm/13/bintools/default.nix35
-rw-r--r--nixpkgs/pkgs/development/compilers/llvm/13/default.nix17
-rw-r--r--nixpkgs/pkgs/development/compilers/llvm/13/libcxxabi/default.nix2
-rw-r--r--nixpkgs/pkgs/development/compilers/llvm/13/libcxxabi/wasm.patch16
-rw-r--r--nixpkgs/pkgs/development/compilers/llvm/14/bintools/default.nix35
-rw-r--r--nixpkgs/pkgs/development/compilers/llvm/14/default.nix17
-rw-r--r--nixpkgs/pkgs/development/compilers/llvm/14/libcxxabi/default.nix2
-rw-r--r--nixpkgs/pkgs/development/compilers/llvm/14/libcxxabi/wasm.patch16
-rw-r--r--nixpkgs/pkgs/development/compilers/llvm/15/bintools/default.nix37
-rw-r--r--nixpkgs/pkgs/development/compilers/llvm/15/default.nix17
-rw-r--r--nixpkgs/pkgs/development/compilers/llvm/15/libcxxabi/default.nix2
-rw-r--r--nixpkgs/pkgs/development/compilers/llvm/15/libcxxabi/wasm.patch16
-rw-r--r--nixpkgs/pkgs/development/compilers/llvm/16/bintools/default.nix37
-rw-r--r--nixpkgs/pkgs/development/compilers/llvm/16/default.nix17
-rw-r--r--nixpkgs/pkgs/development/compilers/llvm/16/libcxxabi/default.nix2
-rw-r--r--nixpkgs/pkgs/development/compilers/llvm/16/libcxxabi/wasm.patch16
-rw-r--r--nixpkgs/pkgs/development/compilers/llvm/5/clang/default.nix2
-rw-r--r--nixpkgs/pkgs/development/compilers/llvm/6/clang/default.nix2
-rw-r--r--nixpkgs/pkgs/development/compilers/llvm/6/clang/purity.patch30
-rw-r--r--nixpkgs/pkgs/development/compilers/llvm/7/bintools/default.nix34
-rw-r--r--nixpkgs/pkgs/development/compilers/llvm/7/clang/default.nix2
-rw-r--r--nixpkgs/pkgs/development/compilers/llvm/7/clang/purity.patch30
-rw-r--r--nixpkgs/pkgs/development/compilers/llvm/7/compiler-rt/codesign.patch33
-rw-r--r--nixpkgs/pkgs/development/compilers/llvm/7/compiler-rt/default.nix2
-rw-r--r--nixpkgs/pkgs/development/compilers/llvm/7/default.nix2
-rw-r--r--nixpkgs/pkgs/development/compilers/llvm/8/bintools/default.nix34
-rw-r--r--nixpkgs/pkgs/development/compilers/llvm/8/clang/default.nix2
-rw-r--r--nixpkgs/pkgs/development/compilers/llvm/8/clang/purity.patch30
-rw-r--r--nixpkgs/pkgs/development/compilers/llvm/8/compiler-rt/codesign.patch33
-rw-r--r--nixpkgs/pkgs/development/compilers/llvm/8/compiler-rt/default.nix2
-rw-r--r--nixpkgs/pkgs/development/compilers/llvm/8/default.nix2
-rw-r--r--nixpkgs/pkgs/development/compilers/llvm/8/libcxxabi/default.nix2
-rw-r--r--nixpkgs/pkgs/development/compilers/llvm/8/libcxxabi/no-threads.patch12
-rw-r--r--nixpkgs/pkgs/development/compilers/llvm/8/libcxxabi/wasm.patch16
-rw-r--r--nixpkgs/pkgs/development/compilers/llvm/9/bintools/default.nix34
-rw-r--r--nixpkgs/pkgs/development/compilers/llvm/9/compiler-rt/codesign.patch33
-rw-r--r--nixpkgs/pkgs/development/compilers/llvm/9/compiler-rt/default.nix2
-rw-r--r--nixpkgs/pkgs/development/compilers/llvm/9/default.nix2
-rw-r--r--nixpkgs/pkgs/development/compilers/llvm/9/libcxxabi/default.nix4
-rw-r--r--nixpkgs/pkgs/development/compilers/llvm/9/libcxxabi/no-threads.patch12
-rw-r--r--nixpkgs/pkgs/development/compilers/llvm/9/libcxxabi/wasm.patch16
-rw-r--r--nixpkgs/pkgs/development/compilers/llvm/common/bintools.nix48
-rw-r--r--nixpkgs/pkgs/development/compilers/llvm/common/clang/5-8-purity.patch (renamed from nixpkgs/pkgs/development/compilers/llvm/5/clang/purity.patch)0
-rw-r--r--nixpkgs/pkgs/development/compilers/llvm/common/compiler-rt/7-12-codesign.patch (renamed from nixpkgs/pkgs/development/compilers/llvm/10/compiler-rt/codesign.patch)0
-rw-r--r--nixpkgs/pkgs/development/compilers/llvm/common/libcxxabi/no-threads.patch (renamed from nixpkgs/pkgs/development/compilers/llvm/10/libcxxabi/no-threads.patch)0
-rw-r--r--nixpkgs/pkgs/development/compilers/llvm/common/libcxxabi/wasm.patch (renamed from nixpkgs/pkgs/development/compilers/llvm/10/libcxxabi/wasm.patch)0
-rw-r--r--nixpkgs/pkgs/development/compilers/llvm/common/lldb.nix69
-rw-r--r--nixpkgs/pkgs/development/compilers/llvm/git/bintools/default.nix37
-rw-r--r--nixpkgs/pkgs/development/compilers/llvm/git/default.nix27
-rw-r--r--nixpkgs/pkgs/development/compilers/llvm/git/libcxxabi/default.nix2
-rw-r--r--nixpkgs/pkgs/development/compilers/llvm/git/libcxxabi/wasm.patch16
-rw-r--r--nixpkgs/pkgs/development/compilers/llvm/git/lldb/default.nix144
69 files changed, 174 insertions, 1079 deletions
diff --git a/nixpkgs/pkgs/development/compilers/llvm/10/bintools/default.nix b/nixpkgs/pkgs/development/compilers/llvm/10/bintools/default.nix
deleted file mode 100644
index 38002439c205..000000000000
--- a/nixpkgs/pkgs/development/compilers/llvm/10/bintools/default.nix
+++ /dev/null
@@ -1,34 +0,0 @@
-{ lib, runCommand, stdenv, llvm, lld, version }:
-
-let
-  prefix = lib.optionalString (stdenv.hostPlatform != stdenv.targetPlatform) "${stdenv.targetPlatform.config}-";
-in runCommand "llvm-binutils-${version}" {
-  preferLocalBuild = true;
-  passthru = {
-    isLLVM = true;
-  };
-} ''
-   mkdir -p $out/bin
-   for prog in ${lld}/bin/*; do
-     ln -s $prog $out/bin/${prefix}$(basename $prog)
-   done
-   for prog in ${llvm}/bin/*; do
-     ln -sf $prog $out/bin/${prefix}$(basename $prog)
-   done
-
-   ln -s ${llvm}/bin/llvm-ar $out/bin/${prefix}ar
-   ln -s ${llvm}/bin/llvm-ar $out/bin/${prefix}dlltool
-   ln -s ${llvm}/bin/llvm-ar $out/bin/${prefix}ranlib
-   ln -s ${llvm}/bin/llvm-cxxfilt $out/bin/${prefix}c++filt
-   ln -s ${llvm}/bin/llvm-dwp $out/bin/${prefix}dwp
-   ln -s ${llvm}/bin/llvm-nm $out/bin/${prefix}nm
-   ln -s ${llvm}/bin/llvm-objcopy $out/bin/${prefix}objcopy
-   ln -s ${llvm}/bin/llvm-objcopy $out/bin/${prefix}strip
-   ln -s ${llvm}/bin/llvm-objdump $out/bin/${prefix}objdump
-   ln -s ${llvm}/bin/llvm-readobj $out/bin/${prefix}readelf
-   ln -s ${llvm}/bin/llvm-size $out/bin/${prefix}size
-   ln -s ${llvm}/bin/llvm-strings $out/bin/${prefix}strings
-   ln -s ${llvm}/bin/llvm-symbolizer $out/bin/${prefix}addr2line
-
-   ln -s ${lld}/bin/lld $out/bin/${prefix}ld
-''
diff --git a/nixpkgs/pkgs/development/compilers/llvm/10/compiler-rt/default.nix b/nixpkgs/pkgs/development/compilers/llvm/10/compiler-rt/default.nix
index 6aed5d219a57..3702509d7756 100644
--- a/nixpkgs/pkgs/development/compilers/llvm/10/compiler-rt/default.nix
+++ b/nixpkgs/pkgs/development/compilers/llvm/10/compiler-rt/default.nix
@@ -55,7 +55,7 @@ stdenv.mkDerivation {
   outputs = [ "out" "dev" ];
 
   patches = [
-    ./codesign.patch # Revert compiler-rt commit that makes codesign mandatory
+    ../../common/compiler-rt/7-12-codesign.patch # Revert compiler-rt commit that makes codesign mandatory
     ./find-darwin-sdk-version.patch # don't test for macOS being >= 10.15
     ./gnu-install-dirs.patch
     ../../common/compiler-rt/libsanitizer-no-cyclades-11.patch
diff --git a/nixpkgs/pkgs/development/compilers/llvm/10/default.nix b/nixpkgs/pkgs/development/compilers/llvm/10/default.nix
index c1ea3a86342f..37c32e425c63 100644
--- a/nixpkgs/pkgs/development/compilers/llvm/10/default.nix
+++ b/nixpkgs/pkgs/development/compilers/llvm/10/default.nix
@@ -137,7 +137,7 @@ let
         ./lldb/procfs.patch
         ./lldb/gnu-install-dirs.patch
       ];
-      inherit llvm_meta release_version;
+      inherit llvm_meta;
     };
 
     # Below, is the LLVM bootstrapping logic. It handles building a
@@ -147,7 +147,7 @@ let
     # doesn’t support like LLVM. Probably we should move to some other
     # file.
 
-    bintools-unwrapped = callPackage ./bintools {};
+    bintools-unwrapped = callPackage ../common/bintools.nix { };
 
     bintoolsNoLibc = wrapBintoolsWith {
       bintools = tools.bintools-unwrapped;
diff --git a/nixpkgs/pkgs/development/compilers/llvm/10/libcxxabi/default.nix b/nixpkgs/pkgs/development/compilers/llvm/10/libcxxabi/default.nix
index d59191dfd724..c4eba56a6b81 100644
--- a/nixpkgs/pkgs/development/compilers/llvm/10/libcxxabi/default.nix
+++ b/nixpkgs/pkgs/development/compilers/llvm/10/libcxxabi/default.nix
@@ -19,11 +19,11 @@ stdenv.mkDerivation {
   '' + lib.optionalString stdenv.hostPlatform.isMusl ''
     patch -p1 -d $(ls -d libcxx-*) -i ${../../libcxx-0001-musl-hacks.patch}
   '' + lib.optionalString stdenv.hostPlatform.isWasm ''
-    patch -p1 -d $(ls -d llvm-*) -i ${./wasm.patch}
+    patch -p1 -d $(ls -d llvm-*) -i ${../../common/libcxxabi/wasm.patch}
   '';
 
   patches = [
-    ./no-threads.patch
+    ../../common/libcxxabi/no-threads.patch
     ./gnu-install-dirs.patch
   ];
 
diff --git a/nixpkgs/pkgs/development/compilers/llvm/11/bintools/default.nix b/nixpkgs/pkgs/development/compilers/llvm/11/bintools/default.nix
deleted file mode 100644
index 38002439c205..000000000000
--- a/nixpkgs/pkgs/development/compilers/llvm/11/bintools/default.nix
+++ /dev/null
@@ -1,34 +0,0 @@
-{ lib, runCommand, stdenv, llvm, lld, version }:
-
-let
-  prefix = lib.optionalString (stdenv.hostPlatform != stdenv.targetPlatform) "${stdenv.targetPlatform.config}-";
-in runCommand "llvm-binutils-${version}" {
-  preferLocalBuild = true;
-  passthru = {
-    isLLVM = true;
-  };
-} ''
-   mkdir -p $out/bin
-   for prog in ${lld}/bin/*; do
-     ln -s $prog $out/bin/${prefix}$(basename $prog)
-   done
-   for prog in ${llvm}/bin/*; do
-     ln -sf $prog $out/bin/${prefix}$(basename $prog)
-   done
-
-   ln -s ${llvm}/bin/llvm-ar $out/bin/${prefix}ar
-   ln -s ${llvm}/bin/llvm-ar $out/bin/${prefix}dlltool
-   ln -s ${llvm}/bin/llvm-ar $out/bin/${prefix}ranlib
-   ln -s ${llvm}/bin/llvm-cxxfilt $out/bin/${prefix}c++filt
-   ln -s ${llvm}/bin/llvm-dwp $out/bin/${prefix}dwp
-   ln -s ${llvm}/bin/llvm-nm $out/bin/${prefix}nm
-   ln -s ${llvm}/bin/llvm-objcopy $out/bin/${prefix}objcopy
-   ln -s ${llvm}/bin/llvm-objcopy $out/bin/${prefix}strip
-   ln -s ${llvm}/bin/llvm-objdump $out/bin/${prefix}objdump
-   ln -s ${llvm}/bin/llvm-readobj $out/bin/${prefix}readelf
-   ln -s ${llvm}/bin/llvm-size $out/bin/${prefix}size
-   ln -s ${llvm}/bin/llvm-strings $out/bin/${prefix}strings
-   ln -s ${llvm}/bin/llvm-symbolizer $out/bin/${prefix}addr2line
-
-   ln -s ${lld}/bin/lld $out/bin/${prefix}ld
-''
diff --git a/nixpkgs/pkgs/development/compilers/llvm/11/compiler-rt/codesign.patch b/nixpkgs/pkgs/development/compilers/llvm/11/compiler-rt/codesign.patch
deleted file mode 100644
index 3cc12b94b200..000000000000
--- a/nixpkgs/pkgs/development/compilers/llvm/11/compiler-rt/codesign.patch
+++ /dev/null
@@ -1,33 +0,0 @@
-From 3dec5f3475a26aeb4678627795c4b67c6b7b4785 Mon Sep 17 00:00:00 2001
-From: Will Dietz <w@wdtz.org>
-Date: Tue, 19 Sep 2017 13:13:06 -0500
-Subject: [PATCH] remove codesign use on Apple, disable ios sim testing that
- needs it
-
----
- cmake/Modules/AddCompilerRT.cmake |  8 ------
- test/asan/CMakeLists.txt          | 52 ---------------------------------------
- test/tsan/CMakeLists.txt          | 47 -----------------------------------
- 3 files changed, 107 deletions(-)
-
-diff --git a/cmake/Modules/AddCompilerRT.cmake b/cmake/Modules/AddCompilerRT.cmake
-index bc5fb9ff7..b64eb4246 100644
---- a/cmake/Modules/AddCompilerRT.cmake
-+++ b/cmake/Modules/AddCompilerRT.cmake
-@@ -210,14 +210,6 @@ function(add_compiler_rt_runtime name type)
-         set_target_properties(${libname} PROPERTIES IMPORT_PREFIX "")
-         set_target_properties(${libname} PROPERTIES IMPORT_SUFFIX ".lib")
-       endif()
--      if(APPLE)
--        # Ad-hoc sign the dylibs
--        add_custom_command(TARGET ${libname}
--          POST_BUILD  
--          COMMAND codesign --sign - $<TARGET_FILE:${libname}>
--          WORKING_DIRECTORY ${COMPILER_RT_LIBRARY_OUTPUT_DIR}
--        )
--      endif()
-     endif()
-     install(TARGETS ${libname}
-       ARCHIVE DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR}
-2.14.1
-
diff --git a/nixpkgs/pkgs/development/compilers/llvm/11/compiler-rt/default.nix b/nixpkgs/pkgs/development/compilers/llvm/11/compiler-rt/default.nix
index aaea3bf9e0d2..38dc7a0fbdc8 100644
--- a/nixpkgs/pkgs/development/compilers/llvm/11/compiler-rt/default.nix
+++ b/nixpkgs/pkgs/development/compilers/llvm/11/compiler-rt/default.nix
@@ -56,7 +56,7 @@ stdenv.mkDerivation {
   outputs = [ "out" "dev" ];
 
   patches = [
-    ./codesign.patch # Revert compiler-rt commit that makes codesign mandatory
+    ../../common/compiler-rt/7-12-codesign.patch # Revert compiler-rt commit that makes codesign mandatory
     ./X86-support-extension.patch # Add support for i486 i586 i686 by reusing i386 config
     ./gnu-install-dirs.patch
     # ld-wrapper dislikes `-rpath-link //nix/store`, so we normalize away the
diff --git a/nixpkgs/pkgs/development/compilers/llvm/11/default.nix b/nixpkgs/pkgs/development/compilers/llvm/11/default.nix
index acb649cdab0b..6ce7d86c835e 100644
--- a/nixpkgs/pkgs/development/compilers/llvm/11/default.nix
+++ b/nixpkgs/pkgs/development/compilers/llvm/11/default.nix
@@ -152,7 +152,7 @@ let
         ./lldb/procfs.patch
         ./lldb/gnu-install-dirs.patch
       ];
-      inherit llvm_meta release_version;
+      inherit llvm_meta;
     };
 
     # Below, is the LLVM bootstrapping logic. It handles building a
@@ -162,7 +162,7 @@ let
     # doesn’t support like LLVM. Probably we should move to some other
     # file.
 
-    bintools-unwrapped = callPackage ./bintools {};
+    bintools-unwrapped = callPackage ../common/bintools.nix { };
 
     bintoolsNoLibc = wrapBintoolsWith {
       bintools = tools.bintools-unwrapped;
diff --git a/nixpkgs/pkgs/development/compilers/llvm/11/libcxxabi/default.nix b/nixpkgs/pkgs/development/compilers/llvm/11/libcxxabi/default.nix
index 77f7e1411885..8a0a18f67822 100644
--- a/nixpkgs/pkgs/development/compilers/llvm/11/libcxxabi/default.nix
+++ b/nixpkgs/pkgs/development/compilers/llvm/11/libcxxabi/default.nix
@@ -22,11 +22,11 @@ stdenv.mkDerivation {
   '' + lib.optionalString stdenv.hostPlatform.isMusl ''
     patch -p1 -d libcxx -i ${../../libcxx-0001-musl-hacks.patch}
   '' + lib.optionalString stdenv.hostPlatform.isWasm ''
-    patch -p1 -d llvm -i ${./wasm.patch}
+    patch -p1 -d llvm -i ${../../common/libcxxabi/wasm.patch}
   '';
 
   patches = [
-    ./no-threads.patch
+    ../../common/libcxxabi/no-threads.patch
     ./gnu-install-dirs.patch
   ];
 
diff --git a/nixpkgs/pkgs/development/compilers/llvm/11/libcxxabi/no-threads.patch b/nixpkgs/pkgs/development/compilers/llvm/11/libcxxabi/no-threads.patch
deleted file mode 100644
index 787f3e16500e..000000000000
--- a/nixpkgs/pkgs/development/compilers/llvm/11/libcxxabi/no-threads.patch
+++ /dev/null
@@ -1,12 +0,0 @@
-diff --git a/CMakeLists.txt b/CMakeLists.txt
-index 4138acf..41b4763 100644
---- a/CMakeLists.txt
-+++ b/CMakeLists.txt
-@@ -362,6 +362,7 @@ if (NOT LIBCXXABI_ENABLE_THREADS)
-                         " is also set to ON.")
-   endif()
-   add_definitions(-D_LIBCXXABI_HAS_NO_THREADS)
-+  add_definitions(-D_LIBCPP_HAS_NO_THREADS)
- endif()
- 
- if (LIBCXXABI_HAS_EXTERNAL_THREAD_API)
diff --git a/nixpkgs/pkgs/development/compilers/llvm/11/libcxxabi/wasm.patch b/nixpkgs/pkgs/development/compilers/llvm/11/libcxxabi/wasm.patch
deleted file mode 100644
index 4ebfe46aa813..000000000000
--- a/nixpkgs/pkgs/development/compilers/llvm/11/libcxxabi/wasm.patch
+++ /dev/null
@@ -1,16 +0,0 @@
-diff --git a/cmake/modules/HandleLLVMOptions.cmake b/cmake/modules/HandleLLVMOptions.cmake
-index 15497d405e0..33f7f18193a 100644
---- a/cmake/modules/HandleLLVMOptions.cmake
-+++ b/cmake/modules/HandleLLVMOptions.cmake
-@@ -127,7 +127,10 @@ else(WIN32)
-       set(LLVM_HAVE_LINK_VERSION_SCRIPT 1)
-     endif()
-   else(FUCHSIA OR UNIX)
--    MESSAGE(SEND_ERROR "Unable to determine platform")
-+    if(${CMAKE_SYSTEM_NAME} MATCHES "Wasi")
-+    else()
-+      MESSAGE(SEND_ERROR "Unable to determine platform")
-+    endif()
-   endif(FUCHSIA OR UNIX)
- endif(WIN32)
- 
diff --git a/nixpkgs/pkgs/development/compilers/llvm/12/bintools/default.nix b/nixpkgs/pkgs/development/compilers/llvm/12/bintools/default.nix
deleted file mode 100644
index 38002439c205..000000000000
--- a/nixpkgs/pkgs/development/compilers/llvm/12/bintools/default.nix
+++ /dev/null
@@ -1,34 +0,0 @@
-{ lib, runCommand, stdenv, llvm, lld, version }:
-
-let
-  prefix = lib.optionalString (stdenv.hostPlatform != stdenv.targetPlatform) "${stdenv.targetPlatform.config}-";
-in runCommand "llvm-binutils-${version}" {
-  preferLocalBuild = true;
-  passthru = {
-    isLLVM = true;
-  };
-} ''
-   mkdir -p $out/bin
-   for prog in ${lld}/bin/*; do
-     ln -s $prog $out/bin/${prefix}$(basename $prog)
-   done
-   for prog in ${llvm}/bin/*; do
-     ln -sf $prog $out/bin/${prefix}$(basename $prog)
-   done
-
-   ln -s ${llvm}/bin/llvm-ar $out/bin/${prefix}ar
-   ln -s ${llvm}/bin/llvm-ar $out/bin/${prefix}dlltool
-   ln -s ${llvm}/bin/llvm-ar $out/bin/${prefix}ranlib
-   ln -s ${llvm}/bin/llvm-cxxfilt $out/bin/${prefix}c++filt
-   ln -s ${llvm}/bin/llvm-dwp $out/bin/${prefix}dwp
-   ln -s ${llvm}/bin/llvm-nm $out/bin/${prefix}nm
-   ln -s ${llvm}/bin/llvm-objcopy $out/bin/${prefix}objcopy
-   ln -s ${llvm}/bin/llvm-objcopy $out/bin/${prefix}strip
-   ln -s ${llvm}/bin/llvm-objdump $out/bin/${prefix}objdump
-   ln -s ${llvm}/bin/llvm-readobj $out/bin/${prefix}readelf
-   ln -s ${llvm}/bin/llvm-size $out/bin/${prefix}size
-   ln -s ${llvm}/bin/llvm-strings $out/bin/${prefix}strings
-   ln -s ${llvm}/bin/llvm-symbolizer $out/bin/${prefix}addr2line
-
-   ln -s ${lld}/bin/lld $out/bin/${prefix}ld
-''
diff --git a/nixpkgs/pkgs/development/compilers/llvm/12/compiler-rt/codesign.patch b/nixpkgs/pkgs/development/compilers/llvm/12/compiler-rt/codesign.patch
deleted file mode 100644
index 3cc12b94b200..000000000000
--- a/nixpkgs/pkgs/development/compilers/llvm/12/compiler-rt/codesign.patch
+++ /dev/null
@@ -1,33 +0,0 @@
-From 3dec5f3475a26aeb4678627795c4b67c6b7b4785 Mon Sep 17 00:00:00 2001
-From: Will Dietz <w@wdtz.org>
-Date: Tue, 19 Sep 2017 13:13:06 -0500
-Subject: [PATCH] remove codesign use on Apple, disable ios sim testing that
- needs it
-
----
- cmake/Modules/AddCompilerRT.cmake |  8 ------
- test/asan/CMakeLists.txt          | 52 ---------------------------------------
- test/tsan/CMakeLists.txt          | 47 -----------------------------------
- 3 files changed, 107 deletions(-)
-
-diff --git a/cmake/Modules/AddCompilerRT.cmake b/cmake/Modules/AddCompilerRT.cmake
-index bc5fb9ff7..b64eb4246 100644
---- a/cmake/Modules/AddCompilerRT.cmake
-+++ b/cmake/Modules/AddCompilerRT.cmake
-@@ -210,14 +210,6 @@ function(add_compiler_rt_runtime name type)
-         set_target_properties(${libname} PROPERTIES IMPORT_PREFIX "")
-         set_target_properties(${libname} PROPERTIES IMPORT_SUFFIX ".lib")
-       endif()
--      if(APPLE)
--        # Ad-hoc sign the dylibs
--        add_custom_command(TARGET ${libname}
--          POST_BUILD  
--          COMMAND codesign --sign - $<TARGET_FILE:${libname}>
--          WORKING_DIRECTORY ${COMPILER_RT_LIBRARY_OUTPUT_DIR}
--        )
--      endif()
-     endif()
-     install(TARGETS ${libname}
-       ARCHIVE DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR}
-2.14.1
-
diff --git a/nixpkgs/pkgs/development/compilers/llvm/12/compiler-rt/default.nix b/nixpkgs/pkgs/development/compilers/llvm/12/compiler-rt/default.nix
index 82c190fa0d64..02c20016bad0 100644
--- a/nixpkgs/pkgs/development/compilers/llvm/12/compiler-rt/default.nix
+++ b/nixpkgs/pkgs/development/compilers/llvm/12/compiler-rt/default.nix
@@ -57,7 +57,7 @@ stdenv.mkDerivation {
   outputs = [ "out" "dev" ];
 
   patches = [
-    ./codesign.patch # Revert compiler-rt commit that makes codesign mandatory
+    ../../common/compiler-rt/7-12-codesign.patch # Revert compiler-rt commit that makes codesign mandatory
     ./X86-support-extension.patch # Add support for i486 i586 i686 by reusing i386 config
     ./gnu-install-dirs.patch
     # ld-wrapper dislikes `-rpath-link //nix/store`, so we normalize away the
diff --git a/nixpkgs/pkgs/development/compilers/llvm/12/default.nix b/nixpkgs/pkgs/development/compilers/llvm/12/default.nix
index e390149f0dad..b976dd2ee67a 100644
--- a/nixpkgs/pkgs/development/compilers/llvm/12/default.nix
+++ b/nixpkgs/pkgs/development/compilers/llvm/12/default.nix
@@ -139,19 +139,20 @@ let
       src = fetch "lldb" "0g3pj1m3chafavpr35r9fynm85y2hdyla6klj0h28khxs2613i78";
       patches =
         let
-          resourceDirPatch = callPackage ({ runCommand, libclang }: (runCommand "resource-dir.patch"
-            {
-              clangLibDir = "${libclang.lib}/lib";
-            } ''
-            substitute '${./lldb/resource-dir.patch}' "$out" --subst-var clangLibDir
-          '')) { };
+          resourceDirPatch = callPackage
+            ({ substituteAll, libclang }: substituteAll
+              {
+                src = ./lldb/resource-dir.patch;
+                clangLibDir = "${libclang.lib}/lib";
+              })
+            { };
         in
         [
           ./lldb/procfs.patch
           resourceDirPatch
           ./lldb/gnu-install-dirs.patch
         ];
-      inherit llvm_meta release_version;
+      inherit llvm_meta;
     };
 
     # Below, is the LLVM bootstrapping logic. It handles building a
@@ -161,7 +162,7 @@ let
     # doesn’t support like LLVM. Probably we should move to some other
     # file.
 
-    bintools-unwrapped = callPackage ./bintools {};
+    bintools-unwrapped = callPackage ../common/bintools.nix { };
 
     bintoolsNoLibc = wrapBintoolsWith {
       bintools = tools.bintools-unwrapped;
diff --git a/nixpkgs/pkgs/development/compilers/llvm/12/libcxxabi/default.nix b/nixpkgs/pkgs/development/compilers/llvm/12/libcxxabi/default.nix
index bab39a5272c8..78a4a68d6a16 100644
--- a/nixpkgs/pkgs/development/compilers/llvm/12/libcxxabi/default.nix
+++ b/nixpkgs/pkgs/development/compilers/llvm/12/libcxxabi/default.nix
@@ -22,7 +22,7 @@ stdenv.mkDerivation {
   '' + lib.optionalString stdenv.hostPlatform.isMusl ''
     patch -p1 -d libcxx -i ${../../libcxx-0001-musl-hacks.patch}
   '' + lib.optionalString stdenv.hostPlatform.isWasm ''
-    patch -p1 -d llvm -i ${./wasm.patch}
+    patch -p1 -d llvm -i ${../../common/libcxxabi/wasm.patch}
   '';
 
   patches = [
diff --git a/nixpkgs/pkgs/development/compilers/llvm/12/libcxxabi/wasm.patch b/nixpkgs/pkgs/development/compilers/llvm/12/libcxxabi/wasm.patch
deleted file mode 100644
index 4ebfe46aa813..000000000000
--- a/nixpkgs/pkgs/development/compilers/llvm/12/libcxxabi/wasm.patch
+++ /dev/null
@@ -1,16 +0,0 @@
-diff --git a/cmake/modules/HandleLLVMOptions.cmake b/cmake/modules/HandleLLVMOptions.cmake
-index 15497d405e0..33f7f18193a 100644
---- a/cmake/modules/HandleLLVMOptions.cmake
-+++ b/cmake/modules/HandleLLVMOptions.cmake
-@@ -127,7 +127,10 @@ else(WIN32)
-       set(LLVM_HAVE_LINK_VERSION_SCRIPT 1)
-     endif()
-   else(FUCHSIA OR UNIX)
--    MESSAGE(SEND_ERROR "Unable to determine platform")
-+    if(${CMAKE_SYSTEM_NAME} MATCHES "Wasi")
-+    else()
-+      MESSAGE(SEND_ERROR "Unable to determine platform")
-+    endif()
-   endif(FUCHSIA OR UNIX)
- endif(WIN32)
- 
diff --git a/nixpkgs/pkgs/development/compilers/llvm/13/bintools/default.nix b/nixpkgs/pkgs/development/compilers/llvm/13/bintools/default.nix
deleted file mode 100644
index b69f4bd12917..000000000000
--- a/nixpkgs/pkgs/development/compilers/llvm/13/bintools/default.nix
+++ /dev/null
@@ -1,35 +0,0 @@
-{ lib, runCommand, stdenv, llvm, lld, version }:
-
-let
-  prefix = lib.optionalString (stdenv.hostPlatform != stdenv.targetPlatform) "${stdenv.targetPlatform.config}-";
-in runCommand "llvm-binutils-${version}" {
-  preferLocalBuild = true;
-  passthru = {
-    isLLVM = true;
-  };
-} ''
-   mkdir -p $out/bin
-   for prog in ${lld}/bin/*; do
-     ln -s $prog $out/bin/${prefix}$(basename $prog)
-   done
-   for prog in ${llvm}/bin/*; do
-     ln -sf $prog $out/bin/${prefix}$(basename $prog)
-   done
-
-   ln -s ${llvm}/bin/llvm-ar $out/bin/${prefix}ar
-   ln -s ${llvm}/bin/llvm-ar $out/bin/${prefix}dlltool
-   ln -s ${llvm}/bin/llvm-ar $out/bin/${prefix}ranlib
-   ln -s ${llvm}/bin/llvm-cxxfilt $out/bin/${prefix}c++filt
-   ln -s ${llvm}/bin/llvm-dwp $out/bin/${prefix}dwp
-   ln -s ${llvm}/bin/llvm-nm $out/bin/${prefix}nm
-   ln -s ${llvm}/bin/llvm-objcopy $out/bin/${prefix}objcopy
-   ln -s ${llvm}/bin/llvm-objcopy $out/bin/${prefix}strip
-   ln -s ${llvm}/bin/llvm-objdump $out/bin/${prefix}objdump
-   ln -s ${llvm}/bin/llvm-rc $out/bin/${prefix}windres
-   ln -s ${llvm}/bin/llvm-readobj $out/bin/${prefix}readelf
-   ln -s ${llvm}/bin/llvm-size $out/bin/${prefix}size
-   ln -s ${llvm}/bin/llvm-strings $out/bin/${prefix}strings
-   ln -s ${llvm}/bin/llvm-symbolizer $out/bin/${prefix}addr2line
-
-   ln -s ${lld}/bin/lld $out/bin/${prefix}ld
-''
diff --git a/nixpkgs/pkgs/development/compilers/llvm/13/default.nix b/nixpkgs/pkgs/development/compilers/llvm/13/default.nix
index 0432dcd14316..3cf7cd711ebe 100644
--- a/nixpkgs/pkgs/development/compilers/llvm/13/default.nix
+++ b/nixpkgs/pkgs/development/compilers/llvm/13/default.nix
@@ -138,12 +138,13 @@ let
     lldb = callPackage ../common/lldb.nix {
       patches =
         let
-          resourceDirPatch = callPackage ({ runCommand, libclang }: (runCommand "resource-dir.patch"
-            {
-              clangLibDir = "${libclang.lib}/lib";
-            } ''
-            substitute '${./lldb/resource-dir.patch}' "$out" --subst-var clangLibDir
-          '')) { };
+          resourceDirPatch = callPackage
+            ({ substituteAll, libclang }: substituteAll
+              {
+                src = ./lldb/resource-dir.patch;
+                clangLibDir = "${libclang.lib}/lib";
+              })
+            { };
         in
         [
           ./lldb/procfs.patch
@@ -164,7 +165,7 @@ let
             && !stdenv.targetPlatform.isAarch64
             && (lib.versionOlder darwin.apple_sdk.sdk.version "11.0")
         ) ./lldb/cpu_subtype_arm64e_replacement.patch;
-      inherit llvm_meta release_version;
+      inherit llvm_meta;
     };
 
     # Below, is the LLVM bootstrapping logic. It handles building a
@@ -174,7 +175,7 @@ let
     # doesn’t support like LLVM. Probably we should move to some other
     # file.
 
-    bintools-unwrapped = callPackage ./bintools {};
+    bintools-unwrapped = callPackage ../common/bintools.nix { };
 
     bintoolsNoLibc = wrapBintoolsWith {
       bintools = tools.bintools-unwrapped;
diff --git a/nixpkgs/pkgs/development/compilers/llvm/13/libcxxabi/default.nix b/nixpkgs/pkgs/development/compilers/llvm/13/libcxxabi/default.nix
index b1b57b3050ad..50f09831e974 100644
--- a/nixpkgs/pkgs/development/compilers/llvm/13/libcxxabi/default.nix
+++ b/nixpkgs/pkgs/development/compilers/llvm/13/libcxxabi/default.nix
@@ -16,7 +16,7 @@ stdenv.mkDerivation rec {
   postUnpack = lib.optionalString stdenv.isDarwin ''
     export TRIPLE=x86_64-apple-darwin
   '' + lib.optionalString stdenv.hostPlatform.isWasm ''
-    patch -p1 -d llvm -i ${./wasm.patch}
+    patch -p1 -d llvm -i ${../../common/libcxxabi/wasm.patch}
   '';
 
   patches = [
diff --git a/nixpkgs/pkgs/development/compilers/llvm/13/libcxxabi/wasm.patch b/nixpkgs/pkgs/development/compilers/llvm/13/libcxxabi/wasm.patch
deleted file mode 100644
index 4ebfe46aa813..000000000000
--- a/nixpkgs/pkgs/development/compilers/llvm/13/libcxxabi/wasm.patch
+++ /dev/null
@@ -1,16 +0,0 @@
-diff --git a/cmake/modules/HandleLLVMOptions.cmake b/cmake/modules/HandleLLVMOptions.cmake
-index 15497d405e0..33f7f18193a 100644
---- a/cmake/modules/HandleLLVMOptions.cmake
-+++ b/cmake/modules/HandleLLVMOptions.cmake
-@@ -127,7 +127,10 @@ else(WIN32)
-       set(LLVM_HAVE_LINK_VERSION_SCRIPT 1)
-     endif()
-   else(FUCHSIA OR UNIX)
--    MESSAGE(SEND_ERROR "Unable to determine platform")
-+    if(${CMAKE_SYSTEM_NAME} MATCHES "Wasi")
-+    else()
-+      MESSAGE(SEND_ERROR "Unable to determine platform")
-+    endif()
-   endif(FUCHSIA OR UNIX)
- endif(WIN32)
- 
diff --git a/nixpkgs/pkgs/development/compilers/llvm/14/bintools/default.nix b/nixpkgs/pkgs/development/compilers/llvm/14/bintools/default.nix
deleted file mode 100644
index b69f4bd12917..000000000000
--- a/nixpkgs/pkgs/development/compilers/llvm/14/bintools/default.nix
+++ /dev/null
@@ -1,35 +0,0 @@
-{ lib, runCommand, stdenv, llvm, lld, version }:
-
-let
-  prefix = lib.optionalString (stdenv.hostPlatform != stdenv.targetPlatform) "${stdenv.targetPlatform.config}-";
-in runCommand "llvm-binutils-${version}" {
-  preferLocalBuild = true;
-  passthru = {
-    isLLVM = true;
-  };
-} ''
-   mkdir -p $out/bin
-   for prog in ${lld}/bin/*; do
-     ln -s $prog $out/bin/${prefix}$(basename $prog)
-   done
-   for prog in ${llvm}/bin/*; do
-     ln -sf $prog $out/bin/${prefix}$(basename $prog)
-   done
-
-   ln -s ${llvm}/bin/llvm-ar $out/bin/${prefix}ar
-   ln -s ${llvm}/bin/llvm-ar $out/bin/${prefix}dlltool
-   ln -s ${llvm}/bin/llvm-ar $out/bin/${prefix}ranlib
-   ln -s ${llvm}/bin/llvm-cxxfilt $out/bin/${prefix}c++filt
-   ln -s ${llvm}/bin/llvm-dwp $out/bin/${prefix}dwp
-   ln -s ${llvm}/bin/llvm-nm $out/bin/${prefix}nm
-   ln -s ${llvm}/bin/llvm-objcopy $out/bin/${prefix}objcopy
-   ln -s ${llvm}/bin/llvm-objcopy $out/bin/${prefix}strip
-   ln -s ${llvm}/bin/llvm-objdump $out/bin/${prefix}objdump
-   ln -s ${llvm}/bin/llvm-rc $out/bin/${prefix}windres
-   ln -s ${llvm}/bin/llvm-readobj $out/bin/${prefix}readelf
-   ln -s ${llvm}/bin/llvm-size $out/bin/${prefix}size
-   ln -s ${llvm}/bin/llvm-strings $out/bin/${prefix}strings
-   ln -s ${llvm}/bin/llvm-symbolizer $out/bin/${prefix}addr2line
-
-   ln -s ${lld}/bin/lld $out/bin/${prefix}ld
-''
diff --git a/nixpkgs/pkgs/development/compilers/llvm/14/default.nix b/nixpkgs/pkgs/development/compilers/llvm/14/default.nix
index 75a52b609605..b9a74e0f070a 100644
--- a/nixpkgs/pkgs/development/compilers/llvm/14/default.nix
+++ b/nixpkgs/pkgs/development/compilers/llvm/14/default.nix
@@ -139,12 +139,13 @@ let
     lldb = callPackage ../common/lldb.nix {
       patches =
         let
-          resourceDirPatch = callPackage ({ runCommand, libclang }: (runCommand "resource-dir.patch"
-            {
-              clangLibDir = "${libclang.lib}/lib";
-            } ''
-            substitute '${./lldb/resource-dir.patch}' "$out" --subst-var clangLibDir
-          '')) { };
+          resourceDirPatch = callPackage
+            ({ substituteAll, libclang }: substituteAll
+              {
+                src = ./lldb/resource-dir.patch;
+                clangLibDir = "${libclang.lib}/lib";
+              })
+            { };
         in
         [
           ./lldb/procfs.patch
@@ -165,7 +166,7 @@ let
             && !stdenv.targetPlatform.isAarch64
             && (lib.versionOlder darwin.apple_sdk.sdk.version "11.0")
         ) ./lldb/cpu_subtype_arm64e_replacement.patch;
-      inherit llvm_meta release_version;
+      inherit llvm_meta;
     };
 
     # Below, is the LLVM bootstrapping logic. It handles building a
@@ -175,7 +176,7 @@ let
     # doesn’t support like LLVM. Probably we should move to some other
     # file.
 
-    bintools-unwrapped = callPackage ./bintools {};
+    bintools-unwrapped = callPackage ../common/bintools.nix { };
 
     bintoolsNoLibc = wrapBintoolsWith {
       bintools = tools.bintools-unwrapped;
diff --git a/nixpkgs/pkgs/development/compilers/llvm/14/libcxxabi/default.nix b/nixpkgs/pkgs/development/compilers/llvm/14/libcxxabi/default.nix
index 30cc34a8c0e6..0f7cec3695d6 100644
--- a/nixpkgs/pkgs/development/compilers/llvm/14/libcxxabi/default.nix
+++ b/nixpkgs/pkgs/development/compilers/llvm/14/libcxxabi/default.nix
@@ -27,7 +27,7 @@ stdenv.mkDerivation rec {
   postUnpack = lib.optionalString stdenv.isDarwin ''
     export TRIPLE=x86_64-apple-darwin
   '' + lib.optionalString stdenv.hostPlatform.isWasm ''
-    patch -p1 -d llvm -i ${./wasm.patch}
+    patch -p1 -d llvm -i ${../../common/libcxxabi/wasm.patch}
   '';
 
   patches = [
diff --git a/nixpkgs/pkgs/development/compilers/llvm/14/libcxxabi/wasm.patch b/nixpkgs/pkgs/development/compilers/llvm/14/libcxxabi/wasm.patch
deleted file mode 100644
index 4ebfe46aa813..000000000000
--- a/nixpkgs/pkgs/development/compilers/llvm/14/libcxxabi/wasm.patch
+++ /dev/null
@@ -1,16 +0,0 @@
-diff --git a/cmake/modules/HandleLLVMOptions.cmake b/cmake/modules/HandleLLVMOptions.cmake
-index 15497d405e0..33f7f18193a 100644
---- a/cmake/modules/HandleLLVMOptions.cmake
-+++ b/cmake/modules/HandleLLVMOptions.cmake
-@@ -127,7 +127,10 @@ else(WIN32)
-       set(LLVM_HAVE_LINK_VERSION_SCRIPT 1)
-     endif()
-   else(FUCHSIA OR UNIX)
--    MESSAGE(SEND_ERROR "Unable to determine platform")
-+    if(${CMAKE_SYSTEM_NAME} MATCHES "Wasi")
-+    else()
-+      MESSAGE(SEND_ERROR "Unable to determine platform")
-+    endif()
-   endif(FUCHSIA OR UNIX)
- endif(WIN32)
- 
diff --git a/nixpkgs/pkgs/development/compilers/llvm/15/bintools/default.nix b/nixpkgs/pkgs/development/compilers/llvm/15/bintools/default.nix
deleted file mode 100644
index c7b20dd28e23..000000000000
--- a/nixpkgs/pkgs/development/compilers/llvm/15/bintools/default.nix
+++ /dev/null
@@ -1,37 +0,0 @@
-{ lib, runCommand, stdenv, llvm, lld, version }:
-
-let
-  prefix = lib.optionalString (stdenv.hostPlatform != stdenv.targetPlatform) "${stdenv.targetPlatform.config}-";
-in runCommand "llvm-binutils-${version}" {
-  preferLocalBuild = true;
-  passthru = {
-    isLLVM = true;
-  };
-} ''
-   mkdir -p $out/bin
-   for prog in ${lld}/bin/*; do
-     ln -s $prog $out/bin/${prefix}$(basename $prog)
-   done
-   for prog in ${llvm}/bin/*; do
-     ln -sf $prog $out/bin/${prefix}$(basename $prog)
-   done
-
-   ln -s ${llvm}/bin/llvm-ar $out/bin/${prefix}ar
-   ln -s ${llvm}/bin/llvm-ar $out/bin/${prefix}dlltool
-   ln -s ${llvm}/bin/llvm-ar $out/bin/${prefix}ranlib
-   ln -s ${llvm}/bin/llvm-cxxfilt $out/bin/${prefix}c++filt
-   ln -s ${llvm}/bin/llvm-debuginfod $out/bin/${prefix}debuginfod
-   ln -s ${llvm}/bin/llvm-debuginfod-find $out/bin/${prefix}debuginfod-find
-   ln -s ${llvm}/bin/llvm-dwp $out/bin/${prefix}dwp
-   ln -s ${llvm}/bin/llvm-nm $out/bin/${prefix}nm
-   ln -s ${llvm}/bin/llvm-objcopy $out/bin/${prefix}objcopy
-   ln -s ${llvm}/bin/llvm-objcopy $out/bin/${prefix}strip
-   ln -s ${llvm}/bin/llvm-objdump $out/bin/${prefix}objdump
-   ln -s ${llvm}/bin/llvm-rc $out/bin/${prefix}windres
-   ln -s ${llvm}/bin/llvm-readobj $out/bin/${prefix}readelf
-   ln -s ${llvm}/bin/llvm-size $out/bin/${prefix}size
-   ln -s ${llvm}/bin/llvm-strings $out/bin/${prefix}strings
-   ln -s ${llvm}/bin/llvm-symbolizer $out/bin/${prefix}addr2line
-
-   ln -s ${lld}/bin/lld $out/bin/${prefix}ld
-''
diff --git a/nixpkgs/pkgs/development/compilers/llvm/15/default.nix b/nixpkgs/pkgs/development/compilers/llvm/15/default.nix
index f244987353b9..863d31874ec8 100644
--- a/nixpkgs/pkgs/development/compilers/llvm/15/default.nix
+++ b/nixpkgs/pkgs/development/compilers/llvm/15/default.nix
@@ -187,12 +187,13 @@ in let
     lldb = callPackage ../common/lldb.nix {
       patches =
         let
-          resourceDirPatch = callPackage ({ runCommand, libclang }: (runCommand "resource-dir.patch"
-            {
-              clangLibDir = "${libclang.lib}/lib";
-            } ''
-            substitute '${./lldb/resource-dir.patch}' "$out" --subst-var clangLibDir
-          '')) { };
+          resourceDirPatch = callPackage
+            ({ substituteAll, libclang }: substituteAll
+              {
+                src = ./lldb/resource-dir.patch;
+                clangLibDir = "${libclang.lib}/lib";
+              })
+            { };
         in
         [
           ./lldb/procfs.patch
@@ -213,7 +214,7 @@ in let
             && !stdenv.targetPlatform.isAarch64
             && (lib.versionOlder darwin.apple_sdk.sdk.version "11.0")
         ) ./lldb/cpu_subtype_arm64e_replacement.patch;
-      inherit llvm_meta release_version;
+      inherit llvm_meta;
     };
 
     # Below, is the LLVM bootstrapping logic. It handles building a
@@ -223,7 +224,7 @@ in let
     # doesn’t support like LLVM. Probably we should move to some other
     # file.
 
-    bintools-unwrapped = callPackage ./bintools {};
+    bintools-unwrapped = callPackage ../common/bintools.nix { };
 
     bintoolsNoLibc = wrapBintoolsWith {
       bintools = tools.bintools-unwrapped;
diff --git a/nixpkgs/pkgs/development/compilers/llvm/15/libcxxabi/default.nix b/nixpkgs/pkgs/development/compilers/llvm/15/libcxxabi/default.nix
index 77ba2d2d008a..04bfee14aa18 100644
--- a/nixpkgs/pkgs/development/compilers/llvm/15/libcxxabi/default.nix
+++ b/nixpkgs/pkgs/development/compilers/llvm/15/libcxxabi/default.nix
@@ -29,7 +29,7 @@ stdenv.mkDerivation rec {
   postUnpack = lib.optionalString stdenv.isDarwin ''
     export TRIPLE=x86_64-apple-darwin
   '' + lib.optionalString stdenv.hostPlatform.isWasm ''
-    patch -p1 -d llvm -i ${./wasm.patch}
+    patch -p1 -d llvm -i ${../../common/libcxxabi/wasm.patch}
   '';
 
   prePatch = ''
diff --git a/nixpkgs/pkgs/development/compilers/llvm/15/libcxxabi/wasm.patch b/nixpkgs/pkgs/development/compilers/llvm/15/libcxxabi/wasm.patch
deleted file mode 100644
index 4ebfe46aa813..000000000000
--- a/nixpkgs/pkgs/development/compilers/llvm/15/libcxxabi/wasm.patch
+++ /dev/null
@@ -1,16 +0,0 @@
-diff --git a/cmake/modules/HandleLLVMOptions.cmake b/cmake/modules/HandleLLVMOptions.cmake
-index 15497d405e0..33f7f18193a 100644
---- a/cmake/modules/HandleLLVMOptions.cmake
-+++ b/cmake/modules/HandleLLVMOptions.cmake
-@@ -127,7 +127,10 @@ else(WIN32)
-       set(LLVM_HAVE_LINK_VERSION_SCRIPT 1)
-     endif()
-   else(FUCHSIA OR UNIX)
--    MESSAGE(SEND_ERROR "Unable to determine platform")
-+    if(${CMAKE_SYSTEM_NAME} MATCHES "Wasi")
-+    else()
-+      MESSAGE(SEND_ERROR "Unable to determine platform")
-+    endif()
-   endif(FUCHSIA OR UNIX)
- endif(WIN32)
- 
diff --git a/nixpkgs/pkgs/development/compilers/llvm/16/bintools/default.nix b/nixpkgs/pkgs/development/compilers/llvm/16/bintools/default.nix
deleted file mode 100644
index c7b20dd28e23..000000000000
--- a/nixpkgs/pkgs/development/compilers/llvm/16/bintools/default.nix
+++ /dev/null
@@ -1,37 +0,0 @@
-{ lib, runCommand, stdenv, llvm, lld, version }:
-
-let
-  prefix = lib.optionalString (stdenv.hostPlatform != stdenv.targetPlatform) "${stdenv.targetPlatform.config}-";
-in runCommand "llvm-binutils-${version}" {
-  preferLocalBuild = true;
-  passthru = {
-    isLLVM = true;
-  };
-} ''
-   mkdir -p $out/bin
-   for prog in ${lld}/bin/*; do
-     ln -s $prog $out/bin/${prefix}$(basename $prog)
-   done
-   for prog in ${llvm}/bin/*; do
-     ln -sf $prog $out/bin/${prefix}$(basename $prog)
-   done
-
-   ln -s ${llvm}/bin/llvm-ar $out/bin/${prefix}ar
-   ln -s ${llvm}/bin/llvm-ar $out/bin/${prefix}dlltool
-   ln -s ${llvm}/bin/llvm-ar $out/bin/${prefix}ranlib
-   ln -s ${llvm}/bin/llvm-cxxfilt $out/bin/${prefix}c++filt
-   ln -s ${llvm}/bin/llvm-debuginfod $out/bin/${prefix}debuginfod
-   ln -s ${llvm}/bin/llvm-debuginfod-find $out/bin/${prefix}debuginfod-find
-   ln -s ${llvm}/bin/llvm-dwp $out/bin/${prefix}dwp
-   ln -s ${llvm}/bin/llvm-nm $out/bin/${prefix}nm
-   ln -s ${llvm}/bin/llvm-objcopy $out/bin/${prefix}objcopy
-   ln -s ${llvm}/bin/llvm-objcopy $out/bin/${prefix}strip
-   ln -s ${llvm}/bin/llvm-objdump $out/bin/${prefix}objdump
-   ln -s ${llvm}/bin/llvm-rc $out/bin/${prefix}windres
-   ln -s ${llvm}/bin/llvm-readobj $out/bin/${prefix}readelf
-   ln -s ${llvm}/bin/llvm-size $out/bin/${prefix}size
-   ln -s ${llvm}/bin/llvm-strings $out/bin/${prefix}strings
-   ln -s ${llvm}/bin/llvm-symbolizer $out/bin/${prefix}addr2line
-
-   ln -s ${lld}/bin/lld $out/bin/${prefix}ld
-''
diff --git a/nixpkgs/pkgs/development/compilers/llvm/16/default.nix b/nixpkgs/pkgs/development/compilers/llvm/16/default.nix
index 94d0e7d30b58..9dbe65ed68da 100644
--- a/nixpkgs/pkgs/development/compilers/llvm/16/default.nix
+++ b/nixpkgs/pkgs/development/compilers/llvm/16/default.nix
@@ -192,12 +192,13 @@ in let
       '') { };
       patches =
         let
-          resourceDirPatch = callPackage ({ runCommand, libclang }: (runCommand "resource-dir.patch"
-            {
-              clangLibDir = "${libclang.lib}/lib";
-            } ''
-            substitute '${./lldb/resource-dir.patch}' "$out" --subst-var clangLibDir
-          '')) { };
+          resourceDirPatch = callPackage
+            ({ substituteAll, libclang }: substituteAll
+              {
+                src = ./lldb/resource-dir.patch;
+                clangLibDir = "${libclang.lib}/lib";
+              })
+            { };
         in
         [
           # FIXME: do we need this? ./procfs.patch
@@ -218,7 +219,7 @@ in let
             && !stdenv.targetPlatform.isAarch64
             && (lib.versionOlder darwin.apple_sdk.sdk.version "11.0")
         ) ./lldb/cpu_subtype_arm64e_replacement.patch;
-      inherit llvm_meta release_version;
+      inherit llvm_meta;
     };
 
     # Below, is the LLVM bootstrapping logic. It handles building a
@@ -228,7 +229,7 @@ in let
     # doesn’t support like LLVM. Probably we should move to some other
     # file.
 
-    bintools-unwrapped = callPackage ./bintools {};
+    bintools-unwrapped = callPackage ../common/bintools.nix { };
 
     bintoolsNoLibc = wrapBintoolsWith {
       bintools = tools.bintools-unwrapped;
diff --git a/nixpkgs/pkgs/development/compilers/llvm/16/libcxxabi/default.nix b/nixpkgs/pkgs/development/compilers/llvm/16/libcxxabi/default.nix
index 77ba2d2d008a..04bfee14aa18 100644
--- a/nixpkgs/pkgs/development/compilers/llvm/16/libcxxabi/default.nix
+++ b/nixpkgs/pkgs/development/compilers/llvm/16/libcxxabi/default.nix
@@ -29,7 +29,7 @@ stdenv.mkDerivation rec {
   postUnpack = lib.optionalString stdenv.isDarwin ''
     export TRIPLE=x86_64-apple-darwin
   '' + lib.optionalString stdenv.hostPlatform.isWasm ''
-    patch -p1 -d llvm -i ${./wasm.patch}
+    patch -p1 -d llvm -i ${../../common/libcxxabi/wasm.patch}
   '';
 
   prePatch = ''
diff --git a/nixpkgs/pkgs/development/compilers/llvm/16/libcxxabi/wasm.patch b/nixpkgs/pkgs/development/compilers/llvm/16/libcxxabi/wasm.patch
deleted file mode 100644
index 4ebfe46aa813..000000000000
--- a/nixpkgs/pkgs/development/compilers/llvm/16/libcxxabi/wasm.patch
+++ /dev/null
@@ -1,16 +0,0 @@
-diff --git a/cmake/modules/HandleLLVMOptions.cmake b/cmake/modules/HandleLLVMOptions.cmake
-index 15497d405e0..33f7f18193a 100644
---- a/cmake/modules/HandleLLVMOptions.cmake
-+++ b/cmake/modules/HandleLLVMOptions.cmake
-@@ -127,7 +127,10 @@ else(WIN32)
-       set(LLVM_HAVE_LINK_VERSION_SCRIPT 1)
-     endif()
-   else(FUCHSIA OR UNIX)
--    MESSAGE(SEND_ERROR "Unable to determine platform")
-+    if(${CMAKE_SYSTEM_NAME} MATCHES "Wasi")
-+    else()
-+      MESSAGE(SEND_ERROR "Unable to determine platform")
-+    endif()
-   endif(FUCHSIA OR UNIX)
- endif(WIN32)
- 
diff --git a/nixpkgs/pkgs/development/compilers/llvm/5/clang/default.nix b/nixpkgs/pkgs/development/compilers/llvm/5/clang/default.nix
index 6e968a6bd2a6..70ffb3e0dd19 100644
--- a/nixpkgs/pkgs/development/compilers/llvm/5/clang/default.nix
+++ b/nixpkgs/pkgs/development/compilers/llvm/5/clang/default.nix
@@ -41,7 +41,7 @@ let
     ];
 
     patches = [
-      ./purity.patch
+      ../../common/clang/5-8-purity.patch
       ./gnu-install-dirs.patch
       (substituteAll {
         src = ./LLVMgold-path.patch;
diff --git a/nixpkgs/pkgs/development/compilers/llvm/6/clang/default.nix b/nixpkgs/pkgs/development/compilers/llvm/6/clang/default.nix
index baf601ffbfc2..bc69f1c99cf4 100644
--- a/nixpkgs/pkgs/development/compilers/llvm/6/clang/default.nix
+++ b/nixpkgs/pkgs/development/compilers/llvm/6/clang/default.nix
@@ -41,7 +41,7 @@ let
     ];
 
     patches = [
-      ./purity.patch
+      ../../common/clang/5-8-purity.patch
       ./gnu-install-dirs.patch
       (substituteAll {
         src = ../../clang-6-10-LLVMgold-path.patch;
diff --git a/nixpkgs/pkgs/development/compilers/llvm/6/clang/purity.patch b/nixpkgs/pkgs/development/compilers/llvm/6/clang/purity.patch
deleted file mode 100644
index b30d0d0b5d5b..000000000000
--- a/nixpkgs/pkgs/development/compilers/llvm/6/clang/purity.patch
+++ /dev/null
@@ -1,30 +0,0 @@
-From 4add81bba40dcec62c4ea4481be8e35ac53e89d8 Mon Sep 17 00:00:00 2001
-From: Will Dietz <w@wdtz.org>
-Date: Thu, 18 May 2017 11:56:12 -0500
-Subject: [PATCH] "purity" patch for 5.0
-
----
- lib/Driver/ToolChains/Gnu.cpp | 7 -------
- 1 file changed, 7 deletions(-)
-
-diff --git a/lib/Driver/ToolChains/Gnu.cpp b/lib/Driver/ToolChains/Gnu.cpp
-index fe3c0191bb..c6a482bece 100644
---- a/lib/Driver/ToolChains/Gnu.cpp
-+++ b/lib/Driver/ToolChains/Gnu.cpp
-@@ -494,13 +494,6 @@ void tools::gnutools::Linker::ConstructJob(Compilation &C, const JobAction &JA,
-   if (!Args.hasArg(options::OPT_static)) {
-     if (Args.hasArg(options::OPT_rdynamic))
-       CmdArgs.push_back("-export-dynamic");
--
--    if (!Args.hasArg(options::OPT_shared)) {
--      const std::string Loader =
--          D.DyldPrefix + ToolChain.getDynamicLinker(Args);
--      CmdArgs.push_back("-dynamic-linker");
--      CmdArgs.push_back(Args.MakeArgString(Loader));
--    }
-   }
- 
-   CmdArgs.push_back("-o");
--- 
-2.11.0
-
diff --git a/nixpkgs/pkgs/development/compilers/llvm/7/bintools/default.nix b/nixpkgs/pkgs/development/compilers/llvm/7/bintools/default.nix
deleted file mode 100644
index 38002439c205..000000000000
--- a/nixpkgs/pkgs/development/compilers/llvm/7/bintools/default.nix
+++ /dev/null
@@ -1,34 +0,0 @@
-{ lib, runCommand, stdenv, llvm, lld, version }:
-
-let
-  prefix = lib.optionalString (stdenv.hostPlatform != stdenv.targetPlatform) "${stdenv.targetPlatform.config}-";
-in runCommand "llvm-binutils-${version}" {
-  preferLocalBuild = true;
-  passthru = {
-    isLLVM = true;
-  };
-} ''
-   mkdir -p $out/bin
-   for prog in ${lld}/bin/*; do
-     ln -s $prog $out/bin/${prefix}$(basename $prog)
-   done
-   for prog in ${llvm}/bin/*; do
-     ln -sf $prog $out/bin/${prefix}$(basename $prog)
-   done
-
-   ln -s ${llvm}/bin/llvm-ar $out/bin/${prefix}ar
-   ln -s ${llvm}/bin/llvm-ar $out/bin/${prefix}dlltool
-   ln -s ${llvm}/bin/llvm-ar $out/bin/${prefix}ranlib
-   ln -s ${llvm}/bin/llvm-cxxfilt $out/bin/${prefix}c++filt
-   ln -s ${llvm}/bin/llvm-dwp $out/bin/${prefix}dwp
-   ln -s ${llvm}/bin/llvm-nm $out/bin/${prefix}nm
-   ln -s ${llvm}/bin/llvm-objcopy $out/bin/${prefix}objcopy
-   ln -s ${llvm}/bin/llvm-objcopy $out/bin/${prefix}strip
-   ln -s ${llvm}/bin/llvm-objdump $out/bin/${prefix}objdump
-   ln -s ${llvm}/bin/llvm-readobj $out/bin/${prefix}readelf
-   ln -s ${llvm}/bin/llvm-size $out/bin/${prefix}size
-   ln -s ${llvm}/bin/llvm-strings $out/bin/${prefix}strings
-   ln -s ${llvm}/bin/llvm-symbolizer $out/bin/${prefix}addr2line
-
-   ln -s ${lld}/bin/lld $out/bin/${prefix}ld
-''
diff --git a/nixpkgs/pkgs/development/compilers/llvm/7/clang/default.nix b/nixpkgs/pkgs/development/compilers/llvm/7/clang/default.nix
index c3f2bcb73ffe..136a69e72161 100644
--- a/nixpkgs/pkgs/development/compilers/llvm/7/clang/default.nix
+++ b/nixpkgs/pkgs/development/compilers/llvm/7/clang/default.nix
@@ -45,7 +45,7 @@ let
     ];
 
     patches = [
-      ./purity.patch
+      ../../common/clang/5-8-purity.patch
       # make clang -xhip use $PATH to find executables
       ./HIP-use-PATH-7.patch
       # Backport for the `--unwindlib=[libgcc|compiler-rt]` flag, which is
diff --git a/nixpkgs/pkgs/development/compilers/llvm/7/clang/purity.patch b/nixpkgs/pkgs/development/compilers/llvm/7/clang/purity.patch
deleted file mode 100644
index b30d0d0b5d5b..000000000000
--- a/nixpkgs/pkgs/development/compilers/llvm/7/clang/purity.patch
+++ /dev/null
@@ -1,30 +0,0 @@
-From 4add81bba40dcec62c4ea4481be8e35ac53e89d8 Mon Sep 17 00:00:00 2001
-From: Will Dietz <w@wdtz.org>
-Date: Thu, 18 May 2017 11:56:12 -0500
-Subject: [PATCH] "purity" patch for 5.0
-
----
- lib/Driver/ToolChains/Gnu.cpp | 7 -------
- 1 file changed, 7 deletions(-)
-
-diff --git a/lib/Driver/ToolChains/Gnu.cpp b/lib/Driver/ToolChains/Gnu.cpp
-index fe3c0191bb..c6a482bece 100644
---- a/lib/Driver/ToolChains/Gnu.cpp
-+++ b/lib/Driver/ToolChains/Gnu.cpp
-@@ -494,13 +494,6 @@ void tools::gnutools::Linker::ConstructJob(Compilation &C, const JobAction &JA,
-   if (!Args.hasArg(options::OPT_static)) {
-     if (Args.hasArg(options::OPT_rdynamic))
-       CmdArgs.push_back("-export-dynamic");
--
--    if (!Args.hasArg(options::OPT_shared)) {
--      const std::string Loader =
--          D.DyldPrefix + ToolChain.getDynamicLinker(Args);
--      CmdArgs.push_back("-dynamic-linker");
--      CmdArgs.push_back(Args.MakeArgString(Loader));
--    }
-   }
- 
-   CmdArgs.push_back("-o");
--- 
-2.11.0
-
diff --git a/nixpkgs/pkgs/development/compilers/llvm/7/compiler-rt/codesign.patch b/nixpkgs/pkgs/development/compilers/llvm/7/compiler-rt/codesign.patch
deleted file mode 100644
index 3cc12b94b200..000000000000
--- a/nixpkgs/pkgs/development/compilers/llvm/7/compiler-rt/codesign.patch
+++ /dev/null
@@ -1,33 +0,0 @@
-From 3dec5f3475a26aeb4678627795c4b67c6b7b4785 Mon Sep 17 00:00:00 2001
-From: Will Dietz <w@wdtz.org>
-Date: Tue, 19 Sep 2017 13:13:06 -0500
-Subject: [PATCH] remove codesign use on Apple, disable ios sim testing that
- needs it
-
----
- cmake/Modules/AddCompilerRT.cmake |  8 ------
- test/asan/CMakeLists.txt          | 52 ---------------------------------------
- test/tsan/CMakeLists.txt          | 47 -----------------------------------
- 3 files changed, 107 deletions(-)
-
-diff --git a/cmake/Modules/AddCompilerRT.cmake b/cmake/Modules/AddCompilerRT.cmake
-index bc5fb9ff7..b64eb4246 100644
---- a/cmake/Modules/AddCompilerRT.cmake
-+++ b/cmake/Modules/AddCompilerRT.cmake
-@@ -210,14 +210,6 @@ function(add_compiler_rt_runtime name type)
-         set_target_properties(${libname} PROPERTIES IMPORT_PREFIX "")
-         set_target_properties(${libname} PROPERTIES IMPORT_SUFFIX ".lib")
-       endif()
--      if(APPLE)
--        # Ad-hoc sign the dylibs
--        add_custom_command(TARGET ${libname}
--          POST_BUILD  
--          COMMAND codesign --sign - $<TARGET_FILE:${libname}>
--          WORKING_DIRECTORY ${COMPILER_RT_LIBRARY_OUTPUT_DIR}
--        )
--      endif()
-     endif()
-     install(TARGETS ${libname}
-       ARCHIVE DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR}
-2.14.1
-
diff --git a/nixpkgs/pkgs/development/compilers/llvm/7/compiler-rt/default.nix b/nixpkgs/pkgs/development/compilers/llvm/7/compiler-rt/default.nix
index a644229ff07c..7354397d2bf0 100644
--- a/nixpkgs/pkgs/development/compilers/llvm/7/compiler-rt/default.nix
+++ b/nixpkgs/pkgs/development/compilers/llvm/7/compiler-rt/default.nix
@@ -56,7 +56,7 @@ stdenv.mkDerivation {
   patches = [
     # https://github.com/llvm/llvm-project/commit/947f9692440836dcb8d88b74b69dd379d85974ce
     ../../common/compiler-rt/glibc.patch
-    ./codesign.patch # Revert compiler-rt commit that makes codesign mandatory
+    ../../common/compiler-rt/7-12-codesign.patch # Revert compiler-rt commit that makes codesign mandatory
     ./gnu-install-dirs.patch
     ../../common/compiler-rt/libsanitizer-no-cyclades-9.patch
   ] ++ lib.optional (useLLVM) ./crtbegin-and-end.patch
diff --git a/nixpkgs/pkgs/development/compilers/llvm/7/default.nix b/nixpkgs/pkgs/development/compilers/llvm/7/default.nix
index 5c20086ce846..0607b5ebf42c 100644
--- a/nixpkgs/pkgs/development/compilers/llvm/7/default.nix
+++ b/nixpkgs/pkgs/development/compilers/llvm/7/default.nix
@@ -149,7 +149,7 @@ let
     # doesn’t support like LLVM. Probably we should move to some other
     # file.
 
-    bintools-unwrapped = callPackage ./bintools {};
+    bintools-unwrapped = callPackage ../common/bintools.nix { };
 
     bintoolsNoLibc = wrapBintoolsWith {
       bintools = tools.bintools-unwrapped;
diff --git a/nixpkgs/pkgs/development/compilers/llvm/8/bintools/default.nix b/nixpkgs/pkgs/development/compilers/llvm/8/bintools/default.nix
deleted file mode 100644
index 38002439c205..000000000000
--- a/nixpkgs/pkgs/development/compilers/llvm/8/bintools/default.nix
+++ /dev/null
@@ -1,34 +0,0 @@
-{ lib, runCommand, stdenv, llvm, lld, version }:
-
-let
-  prefix = lib.optionalString (stdenv.hostPlatform != stdenv.targetPlatform) "${stdenv.targetPlatform.config}-";
-in runCommand "llvm-binutils-${version}" {
-  preferLocalBuild = true;
-  passthru = {
-    isLLVM = true;
-  };
-} ''
-   mkdir -p $out/bin
-   for prog in ${lld}/bin/*; do
-     ln -s $prog $out/bin/${prefix}$(basename $prog)
-   done
-   for prog in ${llvm}/bin/*; do
-     ln -sf $prog $out/bin/${prefix}$(basename $prog)
-   done
-
-   ln -s ${llvm}/bin/llvm-ar $out/bin/${prefix}ar
-   ln -s ${llvm}/bin/llvm-ar $out/bin/${prefix}dlltool
-   ln -s ${llvm}/bin/llvm-ar $out/bin/${prefix}ranlib
-   ln -s ${llvm}/bin/llvm-cxxfilt $out/bin/${prefix}c++filt
-   ln -s ${llvm}/bin/llvm-dwp $out/bin/${prefix}dwp
-   ln -s ${llvm}/bin/llvm-nm $out/bin/${prefix}nm
-   ln -s ${llvm}/bin/llvm-objcopy $out/bin/${prefix}objcopy
-   ln -s ${llvm}/bin/llvm-objcopy $out/bin/${prefix}strip
-   ln -s ${llvm}/bin/llvm-objdump $out/bin/${prefix}objdump
-   ln -s ${llvm}/bin/llvm-readobj $out/bin/${prefix}readelf
-   ln -s ${llvm}/bin/llvm-size $out/bin/${prefix}size
-   ln -s ${llvm}/bin/llvm-strings $out/bin/${prefix}strings
-   ln -s ${llvm}/bin/llvm-symbolizer $out/bin/${prefix}addr2line
-
-   ln -s ${lld}/bin/lld $out/bin/${prefix}ld
-''
diff --git a/nixpkgs/pkgs/development/compilers/llvm/8/clang/default.nix b/nixpkgs/pkgs/development/compilers/llvm/8/clang/default.nix
index 0d0af5ab6aa6..994f9bd967c4 100644
--- a/nixpkgs/pkgs/development/compilers/llvm/8/clang/default.nix
+++ b/nixpkgs/pkgs/development/compilers/llvm/8/clang/default.nix
@@ -45,7 +45,7 @@ let
     ];
 
     patches = [
-      ./purity.patch
+      ../../common/clang/5-8-purity.patch
       ./xpc.patch
       # Backport for -static-pie, which the latter touches, and which is nice in
       # its own right.
diff --git a/nixpkgs/pkgs/development/compilers/llvm/8/clang/purity.patch b/nixpkgs/pkgs/development/compilers/llvm/8/clang/purity.patch
deleted file mode 100644
index b30d0d0b5d5b..000000000000
--- a/nixpkgs/pkgs/development/compilers/llvm/8/clang/purity.patch
+++ /dev/null
@@ -1,30 +0,0 @@
-From 4add81bba40dcec62c4ea4481be8e35ac53e89d8 Mon Sep 17 00:00:00 2001
-From: Will Dietz <w@wdtz.org>
-Date: Thu, 18 May 2017 11:56:12 -0500
-Subject: [PATCH] "purity" patch for 5.0
-
----
- lib/Driver/ToolChains/Gnu.cpp | 7 -------
- 1 file changed, 7 deletions(-)
-
-diff --git a/lib/Driver/ToolChains/Gnu.cpp b/lib/Driver/ToolChains/Gnu.cpp
-index fe3c0191bb..c6a482bece 100644
---- a/lib/Driver/ToolChains/Gnu.cpp
-+++ b/lib/Driver/ToolChains/Gnu.cpp
-@@ -494,13 +494,6 @@ void tools::gnutools::Linker::ConstructJob(Compilation &C, const JobAction &JA,
-   if (!Args.hasArg(options::OPT_static)) {
-     if (Args.hasArg(options::OPT_rdynamic))
-       CmdArgs.push_back("-export-dynamic");
--
--    if (!Args.hasArg(options::OPT_shared)) {
--      const std::string Loader =
--          D.DyldPrefix + ToolChain.getDynamicLinker(Args);
--      CmdArgs.push_back("-dynamic-linker");
--      CmdArgs.push_back(Args.MakeArgString(Loader));
--    }
-   }
- 
-   CmdArgs.push_back("-o");
--- 
-2.11.0
-
diff --git a/nixpkgs/pkgs/development/compilers/llvm/8/compiler-rt/codesign.patch b/nixpkgs/pkgs/development/compilers/llvm/8/compiler-rt/codesign.patch
deleted file mode 100644
index 3cc12b94b200..000000000000
--- a/nixpkgs/pkgs/development/compilers/llvm/8/compiler-rt/codesign.patch
+++ /dev/null
@@ -1,33 +0,0 @@
-From 3dec5f3475a26aeb4678627795c4b67c6b7b4785 Mon Sep 17 00:00:00 2001
-From: Will Dietz <w@wdtz.org>
-Date: Tue, 19 Sep 2017 13:13:06 -0500
-Subject: [PATCH] remove codesign use on Apple, disable ios sim testing that
- needs it
-
----
- cmake/Modules/AddCompilerRT.cmake |  8 ------
- test/asan/CMakeLists.txt          | 52 ---------------------------------------
- test/tsan/CMakeLists.txt          | 47 -----------------------------------
- 3 files changed, 107 deletions(-)
-
-diff --git a/cmake/Modules/AddCompilerRT.cmake b/cmake/Modules/AddCompilerRT.cmake
-index bc5fb9ff7..b64eb4246 100644
---- a/cmake/Modules/AddCompilerRT.cmake
-+++ b/cmake/Modules/AddCompilerRT.cmake
-@@ -210,14 +210,6 @@ function(add_compiler_rt_runtime name type)
-         set_target_properties(${libname} PROPERTIES IMPORT_PREFIX "")
-         set_target_properties(${libname} PROPERTIES IMPORT_SUFFIX ".lib")
-       endif()
--      if(APPLE)
--        # Ad-hoc sign the dylibs
--        add_custom_command(TARGET ${libname}
--          POST_BUILD  
--          COMMAND codesign --sign - $<TARGET_FILE:${libname}>
--          WORKING_DIRECTORY ${COMPILER_RT_LIBRARY_OUTPUT_DIR}
--        )
--      endif()
-     endif()
-     install(TARGETS ${libname}
-       ARCHIVE DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR}
-2.14.1
-
diff --git a/nixpkgs/pkgs/development/compilers/llvm/8/compiler-rt/default.nix b/nixpkgs/pkgs/development/compilers/llvm/8/compiler-rt/default.nix
index 80f70ac64a0f..26cb5aa30617 100644
--- a/nixpkgs/pkgs/development/compilers/llvm/8/compiler-rt/default.nix
+++ b/nixpkgs/pkgs/development/compilers/llvm/8/compiler-rt/default.nix
@@ -56,7 +56,7 @@ stdenv.mkDerivation {
   patches = [
     # https://github.com/llvm/llvm-project/commit/947f9692440836dcb8d88b74b69dd379d85974ce
     ../../common/compiler-rt/glibc.patch
-    ./codesign.patch # Revert compiler-rt commit that makes codesign mandatory
+    ../../common/compiler-rt/7-12-codesign.patch # Revert compiler-rt commit that makes codesign mandatory
     ./gnu-install-dirs.patch
     ../../common/compiler-rt/libsanitizer-no-cyclades-9.patch
   ] ++ lib.optional (useLLVM) ./crtbegin-and-end.patch
diff --git a/nixpkgs/pkgs/development/compilers/llvm/8/default.nix b/nixpkgs/pkgs/development/compilers/llvm/8/default.nix
index c24c84754e32..5beb8afb2ee9 100644
--- a/nixpkgs/pkgs/development/compilers/llvm/8/default.nix
+++ b/nixpkgs/pkgs/development/compilers/llvm/8/default.nix
@@ -150,7 +150,7 @@ let
     # doesn’t support like LLVM. Probably we should move to some other
     # file.
 
-    bintools-unwrapped = callPackage ./bintools {};
+    bintools-unwrapped = callPackage ../common/bintools.nix { };
 
     bintoolsNoLibc = wrapBintoolsWith {
       bintools = tools.bintools-unwrapped;
diff --git a/nixpkgs/pkgs/development/compilers/llvm/8/libcxxabi/default.nix b/nixpkgs/pkgs/development/compilers/llvm/8/libcxxabi/default.nix
index ebf8a5c702ee..885d85b8c3e7 100644
--- a/nixpkgs/pkgs/development/compilers/llvm/8/libcxxabi/default.nix
+++ b/nixpkgs/pkgs/development/compilers/llvm/8/libcxxabi/default.nix
@@ -23,7 +23,7 @@ stdenv.mkDerivation {
   '';
 
   patches = [
-    ./no-threads.patch
+    ../../common/libcxxabi/no-threads.patch
     ./gnu-install-dirs.patch
   ];
 
diff --git a/nixpkgs/pkgs/development/compilers/llvm/8/libcxxabi/no-threads.patch b/nixpkgs/pkgs/development/compilers/llvm/8/libcxxabi/no-threads.patch
deleted file mode 100644
index 787f3e16500e..000000000000
--- a/nixpkgs/pkgs/development/compilers/llvm/8/libcxxabi/no-threads.patch
+++ /dev/null
@@ -1,12 +0,0 @@
-diff --git a/CMakeLists.txt b/CMakeLists.txt
-index 4138acf..41b4763 100644
---- a/CMakeLists.txt
-+++ b/CMakeLists.txt
-@@ -362,6 +362,7 @@ if (NOT LIBCXXABI_ENABLE_THREADS)
-                         " is also set to ON.")
-   endif()
-   add_definitions(-D_LIBCXXABI_HAS_NO_THREADS)
-+  add_definitions(-D_LIBCPP_HAS_NO_THREADS)
- endif()
- 
- if (LIBCXXABI_HAS_EXTERNAL_THREAD_API)
diff --git a/nixpkgs/pkgs/development/compilers/llvm/8/libcxxabi/wasm.patch b/nixpkgs/pkgs/development/compilers/llvm/8/libcxxabi/wasm.patch
deleted file mode 100644
index 4ebfe46aa813..000000000000
--- a/nixpkgs/pkgs/development/compilers/llvm/8/libcxxabi/wasm.patch
+++ /dev/null
@@ -1,16 +0,0 @@
-diff --git a/cmake/modules/HandleLLVMOptions.cmake b/cmake/modules/HandleLLVMOptions.cmake
-index 15497d405e0..33f7f18193a 100644
---- a/cmake/modules/HandleLLVMOptions.cmake
-+++ b/cmake/modules/HandleLLVMOptions.cmake
-@@ -127,7 +127,10 @@ else(WIN32)
-       set(LLVM_HAVE_LINK_VERSION_SCRIPT 1)
-     endif()
-   else(FUCHSIA OR UNIX)
--    MESSAGE(SEND_ERROR "Unable to determine platform")
-+    if(${CMAKE_SYSTEM_NAME} MATCHES "Wasi")
-+    else()
-+      MESSAGE(SEND_ERROR "Unable to determine platform")
-+    endif()
-   endif(FUCHSIA OR UNIX)
- endif(WIN32)
- 
diff --git a/nixpkgs/pkgs/development/compilers/llvm/9/bintools/default.nix b/nixpkgs/pkgs/development/compilers/llvm/9/bintools/default.nix
deleted file mode 100644
index 38002439c205..000000000000
--- a/nixpkgs/pkgs/development/compilers/llvm/9/bintools/default.nix
+++ /dev/null
@@ -1,34 +0,0 @@
-{ lib, runCommand, stdenv, llvm, lld, version }:
-
-let
-  prefix = lib.optionalString (stdenv.hostPlatform != stdenv.targetPlatform) "${stdenv.targetPlatform.config}-";
-in runCommand "llvm-binutils-${version}" {
-  preferLocalBuild = true;
-  passthru = {
-    isLLVM = true;
-  };
-} ''
-   mkdir -p $out/bin
-   for prog in ${lld}/bin/*; do
-     ln -s $prog $out/bin/${prefix}$(basename $prog)
-   done
-   for prog in ${llvm}/bin/*; do
-     ln -sf $prog $out/bin/${prefix}$(basename $prog)
-   done
-
-   ln -s ${llvm}/bin/llvm-ar $out/bin/${prefix}ar
-   ln -s ${llvm}/bin/llvm-ar $out/bin/${prefix}dlltool
-   ln -s ${llvm}/bin/llvm-ar $out/bin/${prefix}ranlib
-   ln -s ${llvm}/bin/llvm-cxxfilt $out/bin/${prefix}c++filt
-   ln -s ${llvm}/bin/llvm-dwp $out/bin/${prefix}dwp
-   ln -s ${llvm}/bin/llvm-nm $out/bin/${prefix}nm
-   ln -s ${llvm}/bin/llvm-objcopy $out/bin/${prefix}objcopy
-   ln -s ${llvm}/bin/llvm-objcopy $out/bin/${prefix}strip
-   ln -s ${llvm}/bin/llvm-objdump $out/bin/${prefix}objdump
-   ln -s ${llvm}/bin/llvm-readobj $out/bin/${prefix}readelf
-   ln -s ${llvm}/bin/llvm-size $out/bin/${prefix}size
-   ln -s ${llvm}/bin/llvm-strings $out/bin/${prefix}strings
-   ln -s ${llvm}/bin/llvm-symbolizer $out/bin/${prefix}addr2line
-
-   ln -s ${lld}/bin/lld $out/bin/${prefix}ld
-''
diff --git a/nixpkgs/pkgs/development/compilers/llvm/9/compiler-rt/codesign.patch b/nixpkgs/pkgs/development/compilers/llvm/9/compiler-rt/codesign.patch
deleted file mode 100644
index 3cc12b94b200..000000000000
--- a/nixpkgs/pkgs/development/compilers/llvm/9/compiler-rt/codesign.patch
+++ /dev/null
@@ -1,33 +0,0 @@
-From 3dec5f3475a26aeb4678627795c4b67c6b7b4785 Mon Sep 17 00:00:00 2001
-From: Will Dietz <w@wdtz.org>
-Date: Tue, 19 Sep 2017 13:13:06 -0500
-Subject: [PATCH] remove codesign use on Apple, disable ios sim testing that
- needs it
-
----
- cmake/Modules/AddCompilerRT.cmake |  8 ------
- test/asan/CMakeLists.txt          | 52 ---------------------------------------
- test/tsan/CMakeLists.txt          | 47 -----------------------------------
- 3 files changed, 107 deletions(-)
-
-diff --git a/cmake/Modules/AddCompilerRT.cmake b/cmake/Modules/AddCompilerRT.cmake
-index bc5fb9ff7..b64eb4246 100644
---- a/cmake/Modules/AddCompilerRT.cmake
-+++ b/cmake/Modules/AddCompilerRT.cmake
-@@ -210,14 +210,6 @@ function(add_compiler_rt_runtime name type)
-         set_target_properties(${libname} PROPERTIES IMPORT_PREFIX "")
-         set_target_properties(${libname} PROPERTIES IMPORT_SUFFIX ".lib")
-       endif()
--      if(APPLE)
--        # Ad-hoc sign the dylibs
--        add_custom_command(TARGET ${libname}
--          POST_BUILD  
--          COMMAND codesign --sign - $<TARGET_FILE:${libname}>
--          WORKING_DIRECTORY ${COMPILER_RT_LIBRARY_OUTPUT_DIR}
--        )
--      endif()
-     endif()
-     install(TARGETS ${libname}
-       ARCHIVE DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR}
-2.14.1
-
diff --git a/nixpkgs/pkgs/development/compilers/llvm/9/compiler-rt/default.nix b/nixpkgs/pkgs/development/compilers/llvm/9/compiler-rt/default.nix
index 0398b126ab58..d03fcbc7f708 100644
--- a/nixpkgs/pkgs/development/compilers/llvm/9/compiler-rt/default.nix
+++ b/nixpkgs/pkgs/development/compilers/llvm/9/compiler-rt/default.nix
@@ -56,7 +56,7 @@ stdenv.mkDerivation {
   patches = [
     # https://github.com/llvm/llvm-project/commit/947f9692440836dcb8d88b74b69dd379d85974ce
     ../../common/compiler-rt/glibc.patch
-    ./codesign.patch # Revert compiler-rt commit that makes codesign mandatory
+    ../../common/compiler-rt/7-12-codesign.patch # Revert compiler-rt commit that makes codesign mandatory
     ./gnu-install-dirs.patch
     ../../common/compiler-rt/libsanitizer-no-cyclades-9.patch
     # Fix build on armv6l
diff --git a/nixpkgs/pkgs/development/compilers/llvm/9/default.nix b/nixpkgs/pkgs/development/compilers/llvm/9/default.nix
index 4ec802a4f289..9f79dc5cce7f 100644
--- a/nixpkgs/pkgs/development/compilers/llvm/9/default.nix
+++ b/nixpkgs/pkgs/development/compilers/llvm/9/default.nix
@@ -150,7 +150,7 @@ let
     # doesn’t support like LLVM. Probably we should move to some other
     # file.
 
-    bintools-unwrapped = callPackage ./bintools {};
+    bintools-unwrapped = callPackage ../common/bintools.nix { };
 
     bintoolsNoLibc = wrapBintoolsWith {
       bintools = tools.bintools-unwrapped;
diff --git a/nixpkgs/pkgs/development/compilers/llvm/9/libcxxabi/default.nix b/nixpkgs/pkgs/development/compilers/llvm/9/libcxxabi/default.nix
index f19bfb157ce9..24d89b1a2da5 100644
--- a/nixpkgs/pkgs/development/compilers/llvm/9/libcxxabi/default.nix
+++ b/nixpkgs/pkgs/development/compilers/llvm/9/libcxxabi/default.nix
@@ -19,11 +19,11 @@ stdenv.mkDerivation {
   '' + lib.optionalString stdenv.hostPlatform.isMusl ''
     patch -p1 -d $(ls -d libcxx-*) -i ${../../libcxx-0001-musl-hacks.patch}
   '' + lib.optionalString stdenv.hostPlatform.isWasm ''
-    patch -p1 -d $(ls -d llvm-*) -i ${./wasm.patch}
+    patch -p1 -d $(ls -d llvm-*) -i ${../../common/libcxxabi/wasm.patch}
   '';
 
   patches = [
-    ./no-threads.patch
+    ../../common/libcxxabi/no-threads.patch
     ./gnu-install-dirs.patch
   ];
 
diff --git a/nixpkgs/pkgs/development/compilers/llvm/9/libcxxabi/no-threads.patch b/nixpkgs/pkgs/development/compilers/llvm/9/libcxxabi/no-threads.patch
deleted file mode 100644
index 787f3e16500e..000000000000
--- a/nixpkgs/pkgs/development/compilers/llvm/9/libcxxabi/no-threads.patch
+++ /dev/null
@@ -1,12 +0,0 @@
-diff --git a/CMakeLists.txt b/CMakeLists.txt
-index 4138acf..41b4763 100644
---- a/CMakeLists.txt
-+++ b/CMakeLists.txt
-@@ -362,6 +362,7 @@ if (NOT LIBCXXABI_ENABLE_THREADS)
-                         " is also set to ON.")
-   endif()
-   add_definitions(-D_LIBCXXABI_HAS_NO_THREADS)
-+  add_definitions(-D_LIBCPP_HAS_NO_THREADS)
- endif()
- 
- if (LIBCXXABI_HAS_EXTERNAL_THREAD_API)
diff --git a/nixpkgs/pkgs/development/compilers/llvm/9/libcxxabi/wasm.patch b/nixpkgs/pkgs/development/compilers/llvm/9/libcxxabi/wasm.patch
deleted file mode 100644
index 4ebfe46aa813..000000000000
--- a/nixpkgs/pkgs/development/compilers/llvm/9/libcxxabi/wasm.patch
+++ /dev/null
@@ -1,16 +0,0 @@
-diff --git a/cmake/modules/HandleLLVMOptions.cmake b/cmake/modules/HandleLLVMOptions.cmake
-index 15497d405e0..33f7f18193a 100644
---- a/cmake/modules/HandleLLVMOptions.cmake
-+++ b/cmake/modules/HandleLLVMOptions.cmake
-@@ -127,7 +127,10 @@ else(WIN32)
-       set(LLVM_HAVE_LINK_VERSION_SCRIPT 1)
-     endif()
-   else(FUCHSIA OR UNIX)
--    MESSAGE(SEND_ERROR "Unable to determine platform")
-+    if(${CMAKE_SYSTEM_NAME} MATCHES "Wasi")
-+    else()
-+      MESSAGE(SEND_ERROR "Unable to determine platform")
-+    endif()
-   endif(FUCHSIA OR UNIX)
- endif(WIN32)
- 
diff --git a/nixpkgs/pkgs/development/compilers/llvm/common/bintools.nix b/nixpkgs/pkgs/development/compilers/llvm/common/bintools.nix
new file mode 100644
index 000000000000..a60060e86891
--- /dev/null
+++ b/nixpkgs/pkgs/development/compilers/llvm/common/bintools.nix
@@ -0,0 +1,48 @@
+{ lib, runCommand, stdenv, llvm, lld, version, release_version }:
+
+let
+  targetPrefix = lib.optionalString (stdenv.hostPlatform != stdenv.targetPlatform) "${stdenv.targetPlatform.config}-";
+in
+runCommand "llvm-binutils-${version}"
+{
+  preferLocalBuild = true;
+  passthru = {
+    isLLVM = true;
+  };
+}
+  (''
+    mkdir -p $out/bin
+    for prog in ${lld}/bin/*; do
+      ln -s $prog $out/bin/${targetPrefix}$(basename $prog)
+    done
+    for prog in ${llvm}/bin/*; do
+      ln -sf $prog $out/bin/${targetPrefix}$(basename $prog)
+    done
+
+    llvmBin="${llvm}/bin"
+
+    ln -s $llvmBin/llvm-ar $out/bin/${targetPrefix}ar
+    ln -s $llvmBin/llvm-ar $out/bin/${targetPrefix}dlltool
+    ln -s $llvmBin/llvm-ar $out/bin/${targetPrefix}ranlib
+    ln -s $llvmBin/llvm-cxxfilt $out/bin/${targetPrefix}c++filt
+    ln -s $llvmBin/llvm-dwp $out/bin/${targetPrefix}dwp
+    ln -s $llvmBin/llvm-nm $out/bin/${targetPrefix}nm
+    ln -s $llvmBin/llvm-objcopy $out/bin/${targetPrefix}objcopy
+    ln -s $llvmBin/llvm-objcopy $out/bin/${targetPrefix}strip
+    ln -s $llvmBin/llvm-objdump $out/bin/${targetPrefix}objdump
+    ln -s $llvmBin/llvm-readobj $out/bin/${targetPrefix}readelf
+    ln -s $llvmBin/llvm-size $out/bin/${targetPrefix}size
+    ln -s $llvmBin/llvm-strings $out/bin/${targetPrefix}strings
+    ln -s $llvmBin/llvm-symbolizer $out/bin/${targetPrefix}addr2line
+
+    if [ -e "$llvmBin/llvm-debuginfod" ]; then
+      ln -s $llvmBin/llvm-debuginfod $out/bin/${targetPrefix}debuginfod
+      ln -s $llvmBin/llvm-debuginfod-find $out/bin/${targetPrefix}debuginfod-find
+    fi
+
+    ln -s ${lld}/bin/lld $out/bin/${targetPrefix}ld
+
+    # Only >=13 show GNU windres compatible in help
+  '' + lib.optionalString (lib.versionAtLeast release_version "13") ''
+    ln -s $llvmBin/llvm-rc $out/bin/${targetPrefix}windres
+  '')
diff --git a/nixpkgs/pkgs/development/compilers/llvm/5/clang/purity.patch b/nixpkgs/pkgs/development/compilers/llvm/common/clang/5-8-purity.patch
index b30d0d0b5d5b..b30d0d0b5d5b 100644
--- a/nixpkgs/pkgs/development/compilers/llvm/5/clang/purity.patch
+++ b/nixpkgs/pkgs/development/compilers/llvm/common/clang/5-8-purity.patch
diff --git a/nixpkgs/pkgs/development/compilers/llvm/10/compiler-rt/codesign.patch b/nixpkgs/pkgs/development/compilers/llvm/common/compiler-rt/7-12-codesign.patch
index 3cc12b94b200..3cc12b94b200 100644
--- a/nixpkgs/pkgs/development/compilers/llvm/10/compiler-rt/codesign.patch
+++ b/nixpkgs/pkgs/development/compilers/llvm/common/compiler-rt/7-12-codesign.patch
diff --git a/nixpkgs/pkgs/development/compilers/llvm/10/libcxxabi/no-threads.patch b/nixpkgs/pkgs/development/compilers/llvm/common/libcxxabi/no-threads.patch
index 787f3e16500e..787f3e16500e 100644
--- a/nixpkgs/pkgs/development/compilers/llvm/10/libcxxabi/no-threads.patch
+++ b/nixpkgs/pkgs/development/compilers/llvm/common/libcxxabi/no-threads.patch
diff --git a/nixpkgs/pkgs/development/compilers/llvm/10/libcxxabi/wasm.patch b/nixpkgs/pkgs/development/compilers/llvm/common/libcxxabi/wasm.patch
index 4ebfe46aa813..4ebfe46aa813 100644
--- a/nixpkgs/pkgs/development/compilers/llvm/10/libcxxabi/wasm.patch
+++ b/nixpkgs/pkgs/development/compilers/llvm/common/libcxxabi/wasm.patch
diff --git a/nixpkgs/pkgs/development/compilers/llvm/common/lldb.nix b/nixpkgs/pkgs/development/compilers/llvm/common/lldb.nix
index 82ad9c304ea6..1f5d4a1e3385 100644
--- a/nixpkgs/pkgs/development/compilers/llvm/common/lldb.nix
+++ b/nixpkgs/pkgs/development/compilers/llvm/common/lldb.nix
@@ -45,25 +45,21 @@ stdenv.mkDerivation (rec {
 
   outputs = [ "out" "lib" "dev" ];
 
-  sourceRoot =
-    if lib.versionOlder release_version "13" then null
-    else "${src.name}/${pname}";
+  sourceRoot = lib.optional (lib.versionAtLeast release_version "13") "${src.name}/${pname}";
 
   nativeBuildInputs = [
     cmake
-  ] ++ lib.optionals (lib.versionAtLeast release_version "15") [
-    ninja
-  ] ++ [
     python3
     which
     swig
     lit
     makeWrapper
-  ] ++ lib.optionals (lib.versionAtLeast release_version "14") [
     lua5_3
   ] ++ lib.optionals enableManpages [
     python3.pkgs.sphinx
     python3.pkgs.recommonmark
+  ] ++ lib.optionals (lib.versionAtLeast release_version "14") [
+    ninja
   ];
 
   buildInputs = [
@@ -87,11 +83,13 @@ stdenv.mkDerivation (rec {
   #
   # See here for context:
   # https://github.com/NixOS/nixpkgs/pull/194634#issuecomment-1272129132
-  ++ lib.optional (
+  ++ lib.optional
+    (
       stdenv.targetPlatform.isDarwin
-      && !stdenv.targetPlatform.isAarch64
-      && (lib.versionAtLeast release_version "15")
-    ) (
+        && !stdenv.targetPlatform.isAarch64
+        && (lib.versionAtLeast release_version "15")
+    )
+    (
       runCommand "bsm-audit-session-header" { } ''
         install -Dm444 \
           "${lib.getDev darwin.apple_sdk.sdk}/include/bsm/audit_session.h" \
@@ -104,7 +102,7 @@ stdenv.mkDerivation (rec {
   cmakeFlags = [
     "-DLLDB_INCLUDE_TESTS=${if doCheck then "YES" else "NO"}"
     "-DLLVM_ENABLE_RTTI=OFF"
-    "-DClang_DIR=${libclang.dev}/lib/cmake"
+    "-DClang_DIR=${lib.getDev libclang}/lib/cmake"
     "-DLLVM_EXTERNAL_LIT=${lit}/bin/lit"
   ] ++ lib.optionals stdenv.isDarwin [
     "-DLLDB_USE_SYSTEM_DEBUGSERVER=ON"
@@ -127,28 +125,21 @@ stdenv.mkDerivation (rec {
   ];
 
   doCheck = false;
+  doInstallCheck = lib.versionOlder release_version "15";
 
   # TODO: cleanup with mass-rebuild
-  installCheckPhase =
-    if ((lib.versions.major release_version) == "14") then ''
-      if [ ! -e $lib/${python3.sitePackages}/lldb/_lldb*.so ] ; then
-          echo "ERROR: python files not installed where expected!";
-          return 1;
-      fi
-      if [ ! -e "$lib/lib/lua/${lua5_3.luaversion}/lldb.so" ] ; then
-          echo "ERROR: lua files not installed where expected!";
-          return 1;
-      fi
-    '' else if (((lib.versions.major release_version) == "15") || (lib.versions.major release_version) == "16") then ''
-      if [ ! -e "$lib/${python3.sitePackages}/lldb/_lldb.so" ] ; then
-          return 1;
-      fi
-    '' else ''
-      if [ ! -e "$lib/${python3.sitePackages}/lldb/_lldb.so" ] ; then
-          echo "ERROR: python files not installed where expected!";
-          return 1;
-      fi
-    '';
+  installCheckPhase = ''
+    if [ ! -e $lib/${python3.sitePackages}/lldb/_lldb*.so ] ; then
+        echo "ERROR: python files not installed where expected!";
+        return 1;
+    fi
+  '' # Something lua is built on older versions but this file doesn't exist.
+  + lib.optionalString (lib.versionAtLeast release_version "14") ''
+    if [ ! -e "$lib/lib/lua/${lua5_3.luaversion}/lldb.so" ] ; then
+        echo "ERROR: lua files not installed where expected!";
+        return 1;
+    fi
+  '';
 
   postInstall = ''
     wrapProgram $out/bin/lldb --prefix PYTHONPATH : $lib/${python3.sitePackages}/
@@ -157,7 +148,7 @@ stdenv.mkDerivation (rec {
     # vscode:
     install -D ../tools/lldb-vscode/package.json $out/share/vscode/extensions/llvm-org.lldb-vscode-0.1.0/package.json
     mkdir -p $out/share/vscode/extensions/llvm-org.lldb-vscode-0.1.0/bin
-    ln -s $out/bin/${if (lib.versionOlder release_version "12") then "llvm-vscode" else "lldb-vscode"} $out/share/vscode/extensions/llvm-org.lldb-vscode-0.1.0/bin
+    ln -s $out/bin/*-vscode $out/share/vscode/extensions/llvm-org.lldb-vscode-0.1.0/bin
   '';
 
   meta = llvm_meta // {
@@ -174,17 +165,15 @@ stdenv.mkDerivation (rec {
       (lib.versionOlder release_version "11" && stdenv.isDarwin && stdenv.isAarch64)
         || (((lib.versions.major release_version) == "13") && stdenv.isDarwin);
   };
-} // lib.optionalAttrs (lib.versionOlder release_version "15") {
-  doInstallCheck = true;
 } // lib.optionalAttrs enableManpages {
   pname = "lldb-manpages";
 
-  buildPhase =
-    if lib.versionOlder release_version "15" then ''
-      make ${if (lib.versionOlder release_version "12") then "docs-man" else "docs-lldb-man"}
-    '' else null;
+  buildPhase = lib.optionalString (lib.versionOlder release_version "15") ''
+    make ${if (lib.versionOlder release_version "12") then "docs-man" else "docs-lldb-man"}
+  '';
+
 
-  ninjaFlags = if lib.versionAtLeast release_version "15" then [ "docs-lldb-man" ] else null;
+  ninjaFlags = lib.optionals (lib.versionAtLeast release_version "15") [ "docs-lldb-man" ];
 
   propagatedBuildInputs = [ ];
 
diff --git a/nixpkgs/pkgs/development/compilers/llvm/git/bintools/default.nix b/nixpkgs/pkgs/development/compilers/llvm/git/bintools/default.nix
deleted file mode 100644
index c7b20dd28e23..000000000000
--- a/nixpkgs/pkgs/development/compilers/llvm/git/bintools/default.nix
+++ /dev/null
@@ -1,37 +0,0 @@
-{ lib, runCommand, stdenv, llvm, lld, version }:
-
-let
-  prefix = lib.optionalString (stdenv.hostPlatform != stdenv.targetPlatform) "${stdenv.targetPlatform.config}-";
-in runCommand "llvm-binutils-${version}" {
-  preferLocalBuild = true;
-  passthru = {
-    isLLVM = true;
-  };
-} ''
-   mkdir -p $out/bin
-   for prog in ${lld}/bin/*; do
-     ln -s $prog $out/bin/${prefix}$(basename $prog)
-   done
-   for prog in ${llvm}/bin/*; do
-     ln -sf $prog $out/bin/${prefix}$(basename $prog)
-   done
-
-   ln -s ${llvm}/bin/llvm-ar $out/bin/${prefix}ar
-   ln -s ${llvm}/bin/llvm-ar $out/bin/${prefix}dlltool
-   ln -s ${llvm}/bin/llvm-ar $out/bin/${prefix}ranlib
-   ln -s ${llvm}/bin/llvm-cxxfilt $out/bin/${prefix}c++filt
-   ln -s ${llvm}/bin/llvm-debuginfod $out/bin/${prefix}debuginfod
-   ln -s ${llvm}/bin/llvm-debuginfod-find $out/bin/${prefix}debuginfod-find
-   ln -s ${llvm}/bin/llvm-dwp $out/bin/${prefix}dwp
-   ln -s ${llvm}/bin/llvm-nm $out/bin/${prefix}nm
-   ln -s ${llvm}/bin/llvm-objcopy $out/bin/${prefix}objcopy
-   ln -s ${llvm}/bin/llvm-objcopy $out/bin/${prefix}strip
-   ln -s ${llvm}/bin/llvm-objdump $out/bin/${prefix}objdump
-   ln -s ${llvm}/bin/llvm-rc $out/bin/${prefix}windres
-   ln -s ${llvm}/bin/llvm-readobj $out/bin/${prefix}readelf
-   ln -s ${llvm}/bin/llvm-size $out/bin/${prefix}size
-   ln -s ${llvm}/bin/llvm-strings $out/bin/${prefix}strings
-   ln -s ${llvm}/bin/llvm-symbolizer $out/bin/${prefix}addr2line
-
-   ln -s ${lld}/bin/lld $out/bin/${prefix}ld
-''
diff --git a/nixpkgs/pkgs/development/compilers/llvm/git/default.nix b/nixpkgs/pkgs/development/compilers/llvm/git/default.nix
index 04f17d5edab6..930b716881e8 100644
--- a/nixpkgs/pkgs/development/compilers/llvm/git/default.nix
+++ b/nixpkgs/pkgs/development/compilers/llvm/git/default.nix
@@ -184,11 +184,28 @@ in let
       inherit llvm_meta;
     };
 
-    lldb = callPackage ./lldb {
+    lldb = callPackage ../common/lldb.nix {
+      src = callPackage ({ runCommand }: runCommand "lldb-src-${version}" {} ''
+        mkdir -p "$out"
+        cp -r ${monorepoSrc}/cmake "$out"
+        cp -r ${monorepoSrc}/lldb "$out"
+      '') { };
+      patches =
+        let
+          resourceDirPatch = callPackage
+            ({ substituteAll, libclang }: substituteAll
+              {
+                src = ./lldb/resource-dir.patch;
+                clangLibDir = "${libclang.lib}/lib";
+              })
+            { };
+        in
+        [
+          ./lldb/procfs.patch # FIXME: do we need this?
+          resourceDirPatch
+          ./lldb/gnu-install-dirs.patch
+        ];
       inherit llvm_meta;
-      inherit (darwin) libobjc bootstrap_cmds;
-      inherit (darwin.apple_sdk.libs) xpc;
-      inherit (darwin.apple_sdk.frameworks) Foundation Carbon Cocoa;
     };
 
     # Below, is the LLVM bootstrapping logic. It handles building a
@@ -198,7 +215,7 @@ in let
     # doesn’t support like LLVM. Probably we should move to some other
     # file.
 
-    bintools-unwrapped = callPackage ./bintools {};
+    bintools-unwrapped = callPackage ../common/bintools.nix { };
 
     bintoolsNoLibc = wrapBintoolsWith {
       bintools = tools.bintools-unwrapped;
diff --git a/nixpkgs/pkgs/development/compilers/llvm/git/libcxxabi/default.nix b/nixpkgs/pkgs/development/compilers/llvm/git/libcxxabi/default.nix
index 362de957886d..6987e6b0ca3c 100644
--- a/nixpkgs/pkgs/development/compilers/llvm/git/libcxxabi/default.nix
+++ b/nixpkgs/pkgs/development/compilers/llvm/git/libcxxabi/default.nix
@@ -29,7 +29,7 @@ stdenv.mkDerivation rec {
   postUnpack = lib.optionalString stdenv.isDarwin ''
     export TRIPLE=x86_64-apple-darwin
   '' + lib.optionalString stdenv.hostPlatform.isWasm ''
-    patch -p1 -d llvm -i ${./wasm.patch}
+    patch -p1 -d llvm -i ${../../common/libcxxabi/wasm.patch}
   '';
 
   prePatch = ''
diff --git a/nixpkgs/pkgs/development/compilers/llvm/git/libcxxabi/wasm.patch b/nixpkgs/pkgs/development/compilers/llvm/git/libcxxabi/wasm.patch
deleted file mode 100644
index 4ebfe46aa813..000000000000
--- a/nixpkgs/pkgs/development/compilers/llvm/git/libcxxabi/wasm.patch
+++ /dev/null
@@ -1,16 +0,0 @@
-diff --git a/cmake/modules/HandleLLVMOptions.cmake b/cmake/modules/HandleLLVMOptions.cmake
-index 15497d405e0..33f7f18193a 100644
---- a/cmake/modules/HandleLLVMOptions.cmake
-+++ b/cmake/modules/HandleLLVMOptions.cmake
-@@ -127,7 +127,10 @@ else(WIN32)
-       set(LLVM_HAVE_LINK_VERSION_SCRIPT 1)
-     endif()
-   else(FUCHSIA OR UNIX)
--    MESSAGE(SEND_ERROR "Unable to determine platform")
-+    if(${CMAKE_SYSTEM_NAME} MATCHES "Wasi")
-+    else()
-+      MESSAGE(SEND_ERROR "Unable to determine platform")
-+    endif()
-   endif(FUCHSIA OR UNIX)
- endif(WIN32)
- 
diff --git a/nixpkgs/pkgs/development/compilers/llvm/git/lldb/default.nix b/nixpkgs/pkgs/development/compilers/llvm/git/lldb/default.nix
deleted file mode 100644
index a02c5ca4b136..000000000000
--- a/nixpkgs/pkgs/development/compilers/llvm/git/lldb/default.nix
+++ /dev/null
@@ -1,144 +0,0 @@
-{ lib, stdenv, llvm_meta
-, runCommand
-, monorepoSrc
-, cmake
-, ninja
-, zlib
-, ncurses
-, swig
-, which
-, libedit
-, libxml2
-, libllvm
-, libclang
-, python3
-, version
-, libobjc
-, xpc
-, Foundation
-, bootstrap_cmds
-, Carbon
-, Cocoa
-, lit
-, makeWrapper
-, enableManpages ? false
-, lua5_3
-}:
-
-stdenv.mkDerivation (rec {
-  pname = "lldb";
-  inherit version;
-
-  src = runCommand "${pname}-src-${version}" {} ''
-    mkdir -p "$out"
-    cp -r ${monorepoSrc}/cmake "$out"
-    cp -r ${monorepoSrc}/${pname} "$out"
-  '';
-
-  sourceRoot = "${src.name}/${pname}";
-
-  patches = [
-    ./procfs.patch
-    (runCommand "resource-dir.patch" {
-      clangLibDir = "${libclang.lib}/lib";
-    } ''
-      substitute '${./resource-dir.patch}' "$out" --subst-var clangLibDir
-    '')
-    ./gnu-install-dirs.patch
-  ];
-
-  outputs = [ "out" "lib" "dev" ];
-
-  nativeBuildInputs = [
-    cmake ninja python3 which swig lit makeWrapper lua5_3
-  ] ++ lib.optionals enableManpages [
-    python3.pkgs.sphinx python3.pkgs.recommonmark
-  ];
-
-  buildInputs = [
-    ncurses
-    zlib
-    libedit
-    libxml2
-    libllvm
-  ] ++ lib.optionals stdenv.isDarwin [
-    libobjc
-    xpc
-    Foundation
-    bootstrap_cmds
-    Carbon
-    Cocoa
-  ];
-
-  hardeningDisable = [ "format" ];
-
-  cmakeFlags = [
-    "-DLLDB_INCLUDE_TESTS=${if doCheck then "YES" else "NO"}"
-    "-DLLVM_ENABLE_RTTI=OFF"
-    "-DClang_DIR=${libclang.dev}/lib/cmake"
-    "-DLLVM_EXTERNAL_LIT=${lit}/bin/lit"
-  ] ++ lib.optionals stdenv.isDarwin [
-    "-DLLDB_USE_SYSTEM_DEBUGSERVER=ON"
-  ] ++ lib.optionals (!stdenv.isDarwin) [
-    "-DLLDB_CODESIGN_IDENTITY=" # codesigning makes nondeterministic
-  ] ++ lib.optionals enableManpages [
-    "-DLLVM_ENABLE_SPHINX=ON"
-    "-DSPHINX_OUTPUT_MAN=ON"
-    "-DSPHINX_OUTPUT_HTML=OFF"
-  ] ++ lib.optionals doCheck [
-    "-DLLDB_TEST_C_COMPILER=${stdenv.cc}/bin/${stdenv.cc.targetPrefix}cc"
-    "-DLLDB_TEST_CXX_COMPILER=${stdenv.cc}/bin/${stdenv.cc.targetPrefix}c++"
-  ];
-
-  doCheck = false;
-
-  installCheckPhase = ''
-    if [ ! -e "$lib/${python3.sitePackages}/lldb/_lldb.so" ] ; then
-        return 1;
-    fi
-  '';
-
-  postInstall = ''
-    wrapProgram $out/bin/lldb --prefix PYTHONPATH : $lib/${python3.sitePackages}/
-
-    # Editor support
-    # vscode:
-    install -D ../tools/lldb-vscode/package.json $out/share/vscode/extensions/llvm-org.lldb-vscode-0.1.0/package.json
-    mkdir -p $out/share/vscode/extensions/llvm-org.lldb-vscode-0.1.0/bin
-    ln -s $out/bin/lldb-vscode $out/share/vscode/extensions/llvm-org.lldb-vscode-0.1.0/bin
-  '';
-
-  meta = llvm_meta // {
-    homepage = "https://lldb.llvm.org/";
-    description = "A next-generation high-performance debugger";
-    longDescription = ''
-      LLDB is a next generation, high-performance debugger. It is built as a set
-      of reusable components which highly leverage existing libraries in the
-      larger LLVM Project, such as the Clang expression parser and LLVM
-      disassembler.
-    '';
-  };
-} // lib.optionalAttrs enableManpages {
-  pname = "lldb-manpages";
-
-  ninjaFlags = [ "docs-lldb-man" ];
-
-  propagatedBuildInputs = [];
-
-  # manually install lldb man page
-  installPhase = ''
-    mkdir -p $out/share/man/man1
-    install docs/man/lldb.1 -t $out/share/man/man1/
-  '';
-
-  postPatch = null;
-  postInstall = null;
-
-  outputs = [ "out" ];
-
-  doCheck = false;
-
-  meta = llvm_meta // {
-    description = "man pages for LLDB ${version}";
-  };
-})