about summary refs log tree commit diff
path: root/pkgs/development/compilers
diff options
context:
space:
mode:
authorgithub-actions[bot]2024-04-13 00:02:05 +0000
committerGitHub2024-04-13 00:02:05 +0000
commit5a301eda678bb41e7c0a6ed5cd1056be5030f4e0 (patch)
tree5b00aa24e5c1299c50573c8ddc354044040fe4ee /pkgs/development/compilers
parentd6a31576e124f4c2d7e8c525d61d0802c6f83550 (diff)
parentcfd6b5fc90b15709b780a5a1619695a88505a176 (diff)
Merge master into staging-next
Diffstat (limited to 'pkgs/development/compilers')
-rw-r--r--pkgs/development/compilers/dmd/binary.nix77
-rw-r--r--pkgs/development/compilers/dmd/bootstrap.nix9
-rw-r--r--pkgs/development/compilers/dmd/default.nix5
-rw-r--r--pkgs/development/compilers/dmd/generic.nix227
-rw-r--r--pkgs/development/compilers/llvm/12/default.nix24
-rw-r--r--pkgs/development/compilers/llvm/12/libunwind/default.nix37
-rw-r--r--pkgs/development/compilers/llvm/12/openmp/default.nix48
-rw-r--r--pkgs/development/compilers/llvm/13/default.nix20
-rw-r--r--pkgs/development/compilers/llvm/13/libunwind/default.nix33
-rw-r--r--pkgs/development/compilers/llvm/13/lld/default.nix55
-rw-r--r--pkgs/development/compilers/llvm/13/openmp/default.nix53
-rw-r--r--pkgs/development/compilers/llvm/14/default.nix17
-rw-r--r--pkgs/development/compilers/llvm/14/libunwind/default.nix47
-rw-r--r--pkgs/development/compilers/llvm/14/lld/default.nix58
-rw-r--r--pkgs/development/compilers/llvm/14/openmp/default.nix69
-rw-r--r--pkgs/development/compilers/llvm/15/default.nix17
-rw-r--r--pkgs/development/compilers/llvm/15/libunwind/default.nix67
-rw-r--r--pkgs/development/compilers/llvm/15/lld/default.nix57
-rw-r--r--pkgs/development/compilers/llvm/15/openmp/default.nix74
-rw-r--r--pkgs/development/compilers/llvm/16/default.nix18
-rw-r--r--pkgs/development/compilers/llvm/16/libunwind/default.nix67
-rw-r--r--pkgs/development/compilers/llvm/16/lld/default.nix58
-rw-r--r--pkgs/development/compilers/llvm/16/openmp/default.nix74
-rw-r--r--pkgs/development/compilers/llvm/17/default.nix15
-rw-r--r--pkgs/development/compilers/llvm/17/libunwind/default.nix63
-rw-r--r--pkgs/development/compilers/llvm/17/lld/default.nix58
-rw-r--r--pkgs/development/compilers/llvm/18/default.nix13
-rw-r--r--pkgs/development/compilers/llvm/18/libunwind/default.nix54
-rw-r--r--pkgs/development/compilers/llvm/18/lld/default.nix57
-rw-r--r--pkgs/development/compilers/llvm/18/openmp/default.nix73
-rw-r--r--pkgs/development/compilers/llvm/common/libunwind/default.nix87
-rw-r--r--pkgs/development/compilers/llvm/common/lld/default.nix (renamed from pkgs/development/compilers/llvm/12/lld/default.nix)55
-rw-r--r--pkgs/development/compilers/llvm/common/openmp/default.nix (renamed from pkgs/development/compilers/llvm/17/openmp/default.nix)72
-rw-r--r--pkgs/development/compilers/llvm/git/compiler-rt/default.nix2
-rw-r--r--pkgs/development/compilers/llvm/git/default.nix19
-rw-r--r--pkgs/development/compilers/llvm/git/libunwind/default.nix54
-rw-r--r--pkgs/development/compilers/llvm/git/lld/default.nix57
-rw-r--r--pkgs/development/compilers/llvm/git/llvm/default.nix4
-rw-r--r--pkgs/development/compilers/llvm/git/openmp/default.nix73
39 files changed, 285 insertions, 1682 deletions
diff --git a/pkgs/development/compilers/dmd/binary.nix b/pkgs/development/compilers/dmd/binary.nix
deleted file mode 100644
index 3a5d6b76cec8..000000000000
--- a/pkgs/development/compilers/dmd/binary.nix
+++ /dev/null
@@ -1,77 +0,0 @@
-{ lib, stdenv, fetchurl, curl, tzdata, autoPatchelfHook, fixDarwinDylibNames, glibc
-, version, hashes }:
-
-let
-  inherit (stdenv) hostPlatform;
-  OS = if hostPlatform.isDarwin then "osx" else hostPlatform.parsed.kernel.name;
-  MODEL = toString hostPlatform.parsed.cpu.bits;
-in
-
-# On linux pargets like `pkgsLLVM.dmd` `cc` does not expose `libgcc`
-# and can't build `dmd`.
-assert hostPlatform.isLinux -> (stdenv.cc.cc ? libgcc);
-stdenv.mkDerivation {
-  pname = "dmd-bootstrap";
-  inherit version;
-
-  src = fetchurl rec {
-    name = "dmd.${version}.${OS}.tar.xz";
-    url = "http://downloads.dlang.org/releases/2.x/${version}/${name}";
-    sha256 = hashes.${OS} or (throw "missing bootstrap sha256 for OS ${OS}");
-  };
-
-  dontConfigure = true;
-  dontBuild = true;
-
-  nativeBuildInputs = lib.optionals hostPlatform.isLinux [
-    autoPatchelfHook
-  ] ++ lib.optionals hostPlatform.isDarwin [
-    fixDarwinDylibNames
-  ];
-  propagatedBuildInputs = [
-    curl
-    tzdata
-  ] ++ lib.optionals hostPlatform.isLinux [
-    glibc
-    stdenv.cc.cc.libgcc
-  ];
-
-  installPhase = ''
-    runHook preInstall
-
-    mkdir -p $out
-
-    # try to copy model-specific binaries into bin first
-    mv ${OS}/bin${MODEL} $out/bin || true
-
-    mv src license.txt ${OS}/* $out/
-
-    # move man into place
-    mkdir -p $out/share
-    mv man $out/share/
-
-    # move docs into place
-    mkdir -p $out/share/doc
-    mv html/d $out/share/doc/
-
-    # fix paths in dmd.conf (one level less)
-    substituteInPlace $out/bin/dmd.conf --replace "/../../" "/../"
-
-    runHook postInstall
-  '';
-
-  # Stripping on Darwin started to break libphobos2.a
-  # Undefined symbols for architecture x86_64:
-  #   "_rt_envvars_enabled", referenced from:
-  #       __D2rt6config16rt_envvarsOptionFNbNiAyaMDFNbNiQkZQnZQq in libphobos2.a(config_99a_6c3.o)
-  dontStrip = hostPlatform.isDarwin;
-
-  meta = with lib; {
-    description = "Digital Mars D Compiler Package";
-    # As of 2.075 all sources and binaries use the boost license
-    license = licenses.boost;
-    maintainers = [ maintainers.lionello ];
-    homepage = "https://dlang.org/";
-    platforms = [ "x86_64-darwin" "i686-linux" "x86_64-linux" ];
-  };
-}
diff --git a/pkgs/development/compilers/dmd/bootstrap.nix b/pkgs/development/compilers/dmd/bootstrap.nix
deleted file mode 100644
index 16aa5ed4d404..000000000000
--- a/pkgs/development/compilers/dmd/bootstrap.nix
+++ /dev/null
@@ -1,9 +0,0 @@
-{ callPackage }:
-callPackage ./binary.nix {
-  version = "2.090.1";
-  hashes = {
-    # Get these from `nix-prefetch-url http://downloads.dlang.org/releases/2.x/2.090.1/dmd.2.090.1.linux.tar.xz` etc..
-    osx = "sha256-9HwGVO/8jfZ6aTiDIUi8w4C4Ukry0uUS8ACP3Ig8dmU=";
-    linux = "sha256-ByCrIA4Nt7i9YT0L19VXIL1IqIp+iObcZux407amZu4=";
-  };
-}
diff --git a/pkgs/development/compilers/dmd/default.nix b/pkgs/development/compilers/dmd/default.nix
deleted file mode 100644
index bdc9fafd4f06..000000000000
--- a/pkgs/development/compilers/dmd/default.nix
+++ /dev/null
@@ -1,5 +0,0 @@
-import ./generic.nix {
-  version = "2.106.1";
-  dmdSha256 = "sha256-vjYa/Pxrz7J2htXT+fa+xaeen/Vxne++lELbHTSXBK8=";
-  phobosSha256 = "sha256-yRL9ub3u4mREG9PVxBvgQ/LDXD57RadPTZ2h08qyh/s=";
-}
diff --git a/pkgs/development/compilers/dmd/generic.nix b/pkgs/development/compilers/dmd/generic.nix
deleted file mode 100644
index 88fabd9c83fb..000000000000
--- a/pkgs/development/compilers/dmd/generic.nix
+++ /dev/null
@@ -1,227 +0,0 @@
-{ version
-, dmdSha256
-, phobosSha256
-}:
-
-{ stdenv
-, lib
-, fetchFromGitHub
-, removeReferencesTo
-, makeWrapper
-, which
-, writeTextFile
-, curl
-, tzdata
-, gdb
-, Foundation
-, callPackage
-, targetPackages
-, fetchpatch
-, bash
-, installShellFiles
-, git
-, unzip
-, dmdBootstrap ? callPackage ./bootstrap.nix { }
-, dmd_bin ? "${dmdBootstrap}/bin"
-}:
-
-let
-  dmdConfFile = writeTextFile {
-    name = "dmd.conf";
-    text = (lib.generators.toINI { } {
-      Environment = {
-        DFLAGS = ''-I@out@/include/dmd -L-L@out@/lib -fPIC ${lib.optionalString (!targetPackages.stdenv.cc.isClang) "-L--export-dynamic"}'';
-      };
-    });
-  };
-
-  bits = builtins.toString stdenv.hostPlatform.parsed.cpu.bits;
-  osname =
-    if stdenv.isDarwin then
-      "osx"
-    else
-      stdenv.hostPlatform.parsed.kernel.name;
-
-  pathToDmd = "\${NIX_BUILD_TOP}/dmd/generated/${osname}/release/${bits}/dmd";
-in
-
-stdenv.mkDerivation rec {
-  pname = "dmd";
-  inherit version;
-
-  enableParallelBuilding = true;
-
-  srcs = [
-    (fetchFromGitHub {
-      owner = "dlang";
-      repo = "dmd";
-      rev = "v${version}";
-      sha256 = dmdSha256;
-      name = "dmd";
-    })
-    (fetchFromGitHub {
-      owner = "dlang";
-      repo = "phobos";
-      rev = "v${version}";
-      sha256 = phobosSha256;
-      name = "phobos";
-    })
-  ];
-
-  sourceRoot = ".";
-
-  # https://issues.dlang.org/show_bug.cgi?id=19553
-  hardeningDisable = [ "fortify" ];
-
-  patches = lib.optionals (lib.versionOlder version "2.088.0") [
-    # Migrates D1-style operator overloads in DMD source, to allow building with
-    # a newer DMD
-    (fetchpatch {
-      url = "https://github.com/dlang/dmd/commit/c4d33e5eb46c123761ac501e8c52f33850483a8a.patch";
-      stripLen = 1;
-      extraPrefix = "dmd/";
-      sha256 = "sha256-N21mAPfaTo+zGCip4njejasraV5IsWVqlGR5eOdFZZE=";
-    })
-  ];
-
-  postPatch = ''
-    patchShebangs dmd/compiler/test/{runnable,fail_compilation,compilable,tools}{,/extra-files}/*.sh
-
-    rm dmd/compiler/test/runnable/gdb1.d
-    rm dmd/compiler/test/runnable/gdb10311.d
-    rm dmd/compiler/test/runnable/gdb14225.d
-    rm dmd/compiler/test/runnable/gdb14276.d
-    rm dmd/compiler/test/runnable/gdb14313.d
-    rm dmd/compiler/test/runnable/gdb14330.d
-    rm dmd/compiler/test/runnable/gdb15729.sh
-    rm dmd/compiler/test/runnable/gdb4149.d
-    rm dmd/compiler/test/runnable/gdb4181.d
-    rm dmd/compiler/test/compilable/ddocYear.d
-
-    # Disable tests that rely on objdump whitespace until fixed upstream:
-    #   https://issues.dlang.org/show_bug.cgi?id=23317
-    rm dmd/compiler/test/runnable/cdvecfill.sh
-    rm dmd/compiler/test/compilable/cdcmp.d
-  ''
-
-  + lib.optionalString (lib.versionAtLeast version "2.089.0" && lib.versionOlder version "2.092.2") ''
-    rm dmd/compiler/test/dshell/test6952.d
-  '' + lib.optionalString (lib.versionAtLeast version "2.092.2") ''
-    substituteInPlace dmd/compiler/test/dshell/test6952.d --replace "/usr/bin/env bash" "${bash}/bin/bash"
-  ''
-
-  + lib.optionalString stdenv.isLinux ''
-    substituteInPlace phobos/std/socket.d --replace "assert(ih.addrList[0] == 0x7F_00_00_01);" ""
-  '' + lib.optionalString stdenv.isDarwin ''
-    substituteInPlace phobos/std/socket.d --replace "foreach (name; names)" "names = []; foreach (name; names)"
-  '';
-
-  nativeBuildInputs = [
-    makeWrapper
-    which
-    installShellFiles
-  ] ++ lib.optionals (lib.versionOlder version "2.088.0") [
-    git
-  ];
-
-  buildInputs = [
-    curl
-    tzdata
-  ] ++ lib.optionals stdenv.isDarwin [
-    Foundation
-  ];
-
-  nativeCheckInputs = [
-    gdb
-  ] ++ lib.optionals (lib.versionOlder version "2.089.0") [
-    unzip
-  ];
-
-  buildFlags = [
-    "BUILD=release"
-    "ENABLE_RELEASE=1"
-    "PIC=1"
-  ];
-
-  # Build and install are based on http://wiki.dlang.org/Building_DMD
-  buildPhase = ''
-    runHook preBuild
-
-    export buildJobs=$NIX_BUILD_CORES
-    if [ -z $enableParallelBuilding ]; then
-      buildJobs=1
-    fi
-
-    ${dmd_bin}/rdmd dmd/compiler/src/build.d -j$buildJobs HOST_DMD=${dmd_bin}/dmd $buildFlags
-    make -C dmd/druntime -f posix.mak DMD=${pathToDmd} $buildFlags -j$buildJobs
-    echo ${tzdata}/share/zoneinfo/ > TZDatabaseDirFile
-    echo ${lib.getLib curl}/lib/libcurl${stdenv.hostPlatform.extensions.sharedLibrary} > LibcurlPathFile
-    make -C phobos -f posix.mak $buildFlags -j$buildJobs DMD=${pathToDmd} DFLAGS="-version=TZDatabaseDir -version=LibcurlPath -J$PWD"
-
-    runHook postBuild
-  '';
-
-  doCheck = true;
-
-  checkFlags = buildFlags;
-
-  # many tests are disbled because they are failing
-
-  # NOTE: Purity check is disabled for checkPhase because it doesn't fare well
-  # with the DMD linker. See https://github.com/NixOS/nixpkgs/issues/97420
-  checkPhase = ''
-    runHook preCheck
-
-    export checkJobs=$NIX_BUILD_CORES
-    if [ -z $enableParallelChecking ]; then
-      checkJobs=1
-    fi
-
-    NIX_ENFORCE_PURITY= \
-      make -C dmd/compiler/test $checkFlags CC=$CXX SHELL=$SHELL -j$checkJobs N=$checkJobs
-
-    NIX_ENFORCE_PURITY= \
-      make -C phobos -f posix.mak unittest $checkFlags -j$checkJobs DFLAGS="-version=TZDatabaseDir -version=LibcurlPath -J$PWD"
-
-    runHook postCheck
-  '';
-
-  installPhase = ''
-    runHook preInstall
-
-    install -Dm755 ${pathToDmd} $out/bin/dmd
-
-    installManPage dmd/docs/man/man*/*
-
-    mkdir -p $out/include/dmd
-    cp -r {dmd/druntime/import/*,phobos/{std,etc}} $out/include/dmd/
-
-    mkdir $out/lib
-    cp phobos/generated/${osname}/release/${bits}/libphobos2.* $out/lib/
-
-    wrapProgram $out/bin/dmd \
-      --prefix PATH ":" "${targetPackages.stdenv.cc}/bin" \
-      --set-default CC "${targetPackages.stdenv.cc}/bin/cc"
-
-    substitute ${dmdConfFile} "$out/bin/dmd.conf" --subst-var out
-
-    runHook postInstall
-  '';
-
-  preFixup = ''
-    find $out/bin -type f -exec ${removeReferencesTo}/bin/remove-references-to -t ${dmd_bin}/dmd '{}' +
-  '';
-
-  disallowedReferences = [ dmdBootstrap ];
-
-  meta = with lib; {
-    description = "Official reference compiler for the D language";
-    mainProgram = "dmd";
-    homepage = "https://dlang.org/";
-    # Everything is now Boost licensed, even the backend.
-    # https://github.com/dlang/dmd/pull/6680
-    license = licenses.boost;
-    maintainers = with maintainers; [ lionello dukc jtbx ];
-    platforms = [ "x86_64-linux" "i686-linux" "x86_64-darwin" ];
-  };
-}
diff --git a/pkgs/development/compilers/llvm/12/default.nix b/pkgs/development/compilers/llvm/12/default.nix
index bd87dc5f34f0..d8b673c70f22 100644
--- a/pkgs/development/compilers/llvm/12/default.nix
+++ b/pkgs/development/compilers/llvm/12/default.nix
@@ -1,5 +1,6 @@
 { lowPrio, newScope, pkgs, lib, stdenv, cmake
 , preLibcCrossHeaders
+, fetchpatch
 , libxml2, python3, isl, fetchurl, overrideCC, wrapCCWith, wrapBintoolsWith
 , buildLlvmTools # tools, but from the previous stage, for cross
 , targetLlvmLibraries # libraries, but from the next stage, for cross
@@ -114,7 +115,11 @@ let
       extraBuildCommands = mkExtraBuildCommands cc;
     };
 
-    lld = callPackage ./lld {
+    lld = callPackage ../common/lld {
+      src = fetch "lld" "0qg3fgc7wj34hdkqn21y03zcmsdd01szhhm1hfki63iifrm3y2v9";
+      patches = [
+        ./lld/gnu-install-dirs.patch
+      ];
       inherit llvm_meta;
       inherit (libraries) libunwind;
     };
@@ -258,13 +263,24 @@ let
       stdenv = overrideCC stdenv buildLlvmTools.clangNoLibcxx;
     };
 
-    libunwind = callPackage ./libunwind {
+    libunwind = callPackage ../common/libunwind {
+      src = fetch "libunwind" "192ww6n81lj2mb9pj4043z79jp3cf58a9c2qrxjwm5c3a64n1shb";
+      patches = [
+        ./libunwind/gnu-install-dirs.patch
+      ];
       inherit llvm_meta;
-      inherit (buildLlvmTools) llvm;
       stdenv = overrideCC stdenv buildLlvmTools.clangNoLibcxx;
     };
 
-    openmp = callPackage ./openmp {
+    openmp = callPackage ../common/openmp {
+      src = fetch "openmp" "14dh0r6h2xh747ffgnsl4z08h0ri04azi9vf79cbz7ma1r27kzk0";
+      patches = [
+        # Fix cross.
+        (fetchpatch {
+          url = "https://github.com/llvm/llvm-project/commit/5e2358c781b85a18d1463fd924d2741d4ae5e42e.patch";
+          hash = "sha256-UxIlAifXnexF/MaraPW0Ut6q+sf3e7y1fMdEv1q103A=";
+        })
+      ];
       inherit llvm_meta targetLlvm;
     };
   });
diff --git a/pkgs/development/compilers/llvm/12/libunwind/default.nix b/pkgs/development/compilers/llvm/12/libunwind/default.nix
deleted file mode 100644
index 95e0962b4689..000000000000
--- a/pkgs/development/compilers/llvm/12/libunwind/default.nix
+++ /dev/null
@@ -1,37 +0,0 @@
-{ lib, stdenv, llvm_meta, version, fetch, libcxx, llvm, cmake
-, enableShared ? !stdenv.hostPlatform.isStatic
-}:
-
-stdenv.mkDerivation rec {
-  pname = "libunwind";
-  inherit version;
-
-  src = fetch pname "192ww6n81lj2mb9pj4043z79jp3cf58a9c2qrxjwm5c3a64n1shb";
-
-  postUnpack = ''
-    ln -s ${libcxx.src}/libcxx .
-    ln -s ${libcxx.src}/llvm .
-  '';
-
-  patches = [
-    ./gnu-install-dirs.patch
-  ];
-
-  outputs = [ "out" "dev" ];
-
-  nativeBuildInputs = [ cmake ];
-
-  cmakeFlags = lib.optional (!enableShared) "-DLIBUNWIND_ENABLE_SHARED=OFF";
-
-  meta = llvm_meta // {
-    # Details: https://github.com/llvm/llvm-project/blob/main/libunwind/docs/index.rst
-    homepage = "https://clang.llvm.org/docs/Toolchain.html#unwind-library";
-    description = "LLVM's unwinder library";
-    longDescription = ''
-      The unwind library provides a family of _Unwind_* functions implementing
-      the language-neutral stack unwinding portion of the Itanium C++ ABI (Level
-      I). It is a dependency of the C++ ABI library, and sometimes is a
-      dependency of other runtimes.
-    '';
-  };
-}
diff --git a/pkgs/development/compilers/llvm/12/openmp/default.nix b/pkgs/development/compilers/llvm/12/openmp/default.nix
deleted file mode 100644
index 6040f3d1621a..000000000000
--- a/pkgs/development/compilers/llvm/12/openmp/default.nix
+++ /dev/null
@@ -1,48 +0,0 @@
-{ lib
-, stdenv
-, llvm_meta
-, fetch
-, fetchpatch
-, cmake
-, llvm
-, targetLlvm
-, perl
-, version
-}:
-
-stdenv.mkDerivation rec {
-  pname = "openmp";
-  inherit version;
-
-  src = fetch pname "14dh0r6h2xh747ffgnsl4z08h0ri04azi9vf79cbz7ma1r27kzk0";
-
-  patches = [
-    # Fix cross.
-    (fetchpatch {
-      url = "https://github.com/llvm/llvm-project/commit/5e2358c781b85a18d1463fd924d2741d4ae5e42e.patch";
-      hash = "sha256-UxIlAifXnexF/MaraPW0Ut6q+sf3e7y1fMdEv1q103A=";
-    })
-  ];
-
-  patchFlags = [ "-p2" ];
-
-  nativeBuildInputs = [ cmake perl ];
-  buildInputs = [
-    (if stdenv.buildPlatform == stdenv.hostPlatform then llvm else targetLlvm)
-  ];
-
-  meta = llvm_meta // {
-    homepage = "https://openmp.llvm.org/";
-    description = "Support for the OpenMP language";
-    longDescription = ''
-      The OpenMP subproject of LLVM contains the components required to build an
-      executable OpenMP program that are outside the compiler itself.
-      Contains the code for the runtime library against which code compiled by
-      "clang -fopenmp" must be linked before it can run and the library that
-      supports offload to target devices.
-    '';
-    # "All of the code is dual licensed under the MIT license and the UIUC
-    # License (a BSD-like license)":
-    license = with lib.licenses; [ mit ncsa ];
-  };
-}
diff --git a/pkgs/development/compilers/llvm/13/default.nix b/pkgs/development/compilers/llvm/13/default.nix
index 429dfe5f1f3e..e93fb1bf2944 100644
--- a/pkgs/development/compilers/llvm/13/default.nix
+++ b/pkgs/development/compilers/llvm/13/default.nix
@@ -1,5 +1,6 @@
 { lowPrio, newScope, pkgs, lib, stdenv, cmake
 , preLibcCrossHeaders
+, fetchpatch
 , libxml2, python3, isl, fetchFromGitHub, overrideCC, wrapCCWith, wrapBintoolsWith
 , buildLlvmTools # tools, but from the previous stage, for cross
 , targetLlvmLibraries # libraries, but from the next stage, for cross
@@ -139,7 +140,10 @@ in let
       extraBuildCommands = mkExtraBuildCommands cc;
     };
 
-    lld = callPackage ./lld {
+    lld = callPackage ../common/lld {
+      patches = [
+        ./lld/gnu-install-dirs.patch
+      ];
       inherit llvm_meta;
     };
 
@@ -296,12 +300,22 @@ in let
       monorepoSrc = src;
     };
 
-    libunwind = callPackage ./libunwind {
+    libunwind = callPackage ../common/libunwind {
+      patches = [
+        ./libunwind/gnu-install-dirs.patch
+      ];
       inherit llvm_meta;
       stdenv = overrideCC stdenv buildLlvmTools.clangNoLibcxx;
     };
 
-    openmp = callPackage ./openmp {
+    openmp = callPackage ../common/openmp {
+      patches = [
+        # Fix cross.
+        (fetchpatch {
+          url = "https://github.com/llvm/llvm-project/commit/5e2358c781b85a18d1463fd924d2741d4ae5e42e.patch";
+          hash = "sha256-UxIlAifXnexF/MaraPW0Ut6q+sf3e7y1fMdEv1q103A=";
+        })
+      ];
       inherit llvm_meta targetLlvm;
     };
   });
diff --git a/pkgs/development/compilers/llvm/13/libunwind/default.nix b/pkgs/development/compilers/llvm/13/libunwind/default.nix
deleted file mode 100644
index d837bc60de37..000000000000
--- a/pkgs/development/compilers/llvm/13/libunwind/default.nix
+++ /dev/null
@@ -1,33 +0,0 @@
-{ lib, stdenv, llvm_meta, version, src, cmake
-, enableShared ? !stdenv.hostPlatform.isStatic
-}:
-
-stdenv.mkDerivation rec {
-  pname = "libunwind";
-  inherit version;
-
-  inherit src;
-  sourceRoot = "${src.name}/${pname}";
-
-  patches = [
-    ./gnu-install-dirs.patch
-  ];
-
-  outputs = [ "out" "dev" ];
-
-  nativeBuildInputs = [ cmake ];
-
-  cmakeFlags = lib.optional (!enableShared) "-DLIBUNWIND_ENABLE_SHARED=OFF";
-
-  meta = llvm_meta // {
-    # Details: https://github.com/llvm/llvm-project/blob/main/libunwind/docs/index.rst
-    homepage = "https://clang.llvm.org/docs/Toolchain.html#unwind-library";
-    description = "LLVM's unwinder library";
-    longDescription = ''
-      The unwind library provides a family of _Unwind_* functions implementing
-      the language-neutral stack unwinding portion of the Itanium C++ ABI (Level
-      I). It is a dependency of the C++ ABI library, and sometimes is a
-      dependency of other runtimes.
-    '';
-  };
-}
diff --git a/pkgs/development/compilers/llvm/13/lld/default.nix b/pkgs/development/compilers/llvm/13/lld/default.nix
deleted file mode 100644
index d506f396f65c..000000000000
--- a/pkgs/development/compilers/llvm/13/lld/default.nix
+++ /dev/null
@@ -1,55 +0,0 @@
-{ lib, stdenv, llvm_meta
-, buildLlvmTools
-, src
-, cmake
-, libxml2
-, libllvm
-, version
-}:
-
-stdenv.mkDerivation rec {
-  pname = "lld";
-  inherit version;
-
-  inherit src;
-  sourceRoot = "${src.name}/${pname}";
-
-  patches = [
-    ./gnu-install-dirs.patch
-  ];
-
-  # On Darwin the llvm-config is perhaps not working fine as the
-  # LLVM_MAIN_SRC_DIR is not getting set correctly, and the build fails as the
-  # include path is not correct.
-  postPatch = lib.optionalString stdenv.isDarwin ''
-    substituteInPlace MachO/CMakeLists.txt --replace \
-      '(''${LLVM_MAIN_SRC_DIR}/' '(../'
-  '';
-
-  nativeBuildInputs = [ cmake ];
-  buildInputs = [ libllvm libxml2 ];
-
-  cmakeFlags = [
-    "-DLLVM_CONFIG_PATH=${libllvm.dev}/bin/llvm-config${lib.optionalString (stdenv.hostPlatform != stdenv.buildPlatform) "-native"}"
-  ] ++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [
-    "-DLLVM_TABLEGEN_EXE=${buildLlvmTools.llvm}/bin/llvm-tblgen"
-  ];
-
-  # Musl's default stack size is too small for lld to be able to link Firefox.
-  LDFLAGS = lib.optionalString stdenv.hostPlatform.isMusl "-Wl,-z,stack-size=2097152";
-
-  outputs = [ "out" "lib" "dev" ];
-
-  meta = llvm_meta // {
-    homepage = "https://lld.llvm.org/";
-    description = "The LLVM linker (unwrapped)";
-    longDescription = ''
-      LLD is a linker from the LLVM project that is a drop-in replacement for
-      system linkers and runs much faster than them. It also provides features
-      that are useful for toolchain developers.
-      The linker supports ELF (Unix), PE/COFF (Windows), Mach-O (macOS), and
-      WebAssembly in descending order of completeness. Internally, LLD consists
-      of several different linkers.
-    '';
-  };
-}
diff --git a/pkgs/development/compilers/llvm/13/openmp/default.nix b/pkgs/development/compilers/llvm/13/openmp/default.nix
deleted file mode 100644
index 7b461df438f9..000000000000
--- a/pkgs/development/compilers/llvm/13/openmp/default.nix
+++ /dev/null
@@ -1,53 +0,0 @@
-{ lib
-, stdenv
-, llvm_meta
-, src
-, fetchpatch
-, cmake
-, llvm
-, targetLlvm
-, perl
-, version
-}:
-
-stdenv.mkDerivation rec {
-  pname = "openmp";
-  inherit version;
-
-  inherit src;
-  sourceRoot = "${src.name}/${pname}";
-
-  patches = [
-    # Fix cross.
-    (fetchpatch {
-      url = "https://github.com/llvm/llvm-project/commit/5e2358c781b85a18d1463fd924d2741d4ae5e42e.patch";
-      hash = "sha256-UxIlAifXnexF/MaraPW0Ut6q+sf3e7y1fMdEv1q103A=";
-    })
-  ];
-
-  patchFlags = [ "-p2" ];
-
-  nativeBuildInputs = [ cmake perl ];
-  buildInputs = [
-    (if stdenv.buildPlatform == stdenv.hostPlatform then llvm else targetLlvm)
-  ];
-
-  cmakeFlags = [
-    "-DLIBOMPTARGET_BUILD_AMDGCN_BCLIB=OFF" # Building the AMDGCN device RTL currently fails
-  ];
-
-  meta = llvm_meta // {
-    homepage = "https://openmp.llvm.org/";
-    description = "Support for the OpenMP language";
-    longDescription = ''
-      The OpenMP subproject of LLVM contains the components required to build an
-      executable OpenMP program that are outside the compiler itself.
-      Contains the code for the runtime library against which code compiled by
-      "clang -fopenmp" must be linked before it can run and the library that
-      supports offload to target devices.
-    '';
-    # "All of the code is dual licensed under the MIT license and the UIUC
-    # License (a BSD-like license)":
-    license = with lib.licenses; [ mit ncsa ];
-  };
-}
diff --git a/pkgs/development/compilers/llvm/14/default.nix b/pkgs/development/compilers/llvm/14/default.nix
index 6dcdcfa92584..687deb6ead89 100644
--- a/pkgs/development/compilers/llvm/14/default.nix
+++ b/pkgs/development/compilers/llvm/14/default.nix
@@ -136,7 +136,11 @@ in let
       extraBuildCommands = mkExtraBuildCommands cc;
     };
 
-    lld = callPackage ./lld {
+    lld = callPackage ../common/lld {
+      patches = [
+        ./lld/gnu-install-dirs.patch
+        ./lld/fix-root-src-dir.patch
+      ];
       inherit llvm_meta;
     };
 
@@ -294,12 +298,19 @@ in let
       stdenv = overrideCC stdenv buildLlvmTools.clangNoLibcxx;
     };
 
-    libunwind = callPackage ./libunwind {
+    libunwind = callPackage ../common/libunwind {
+      patches = [
+        ./libunwind/gnu-install-dirs.patch
+      ];
       inherit llvm_meta;
       stdenv = overrideCC stdenv buildLlvmTools.clangNoLibcxx;
     };
 
-    openmp = callPackage ./openmp {
+    openmp = callPackage ../common/openmp {
+      patches = [
+        ./openmp/gnu-install-dirs.patch
+        ./openmp/run-lit-directly.patch
+      ];
       inherit llvm_meta targetLlvm;
     };
   });
diff --git a/pkgs/development/compilers/llvm/14/libunwind/default.nix b/pkgs/development/compilers/llvm/14/libunwind/default.nix
deleted file mode 100644
index c6d9eda5e474..000000000000
--- a/pkgs/development/compilers/llvm/14/libunwind/default.nix
+++ /dev/null
@@ -1,47 +0,0 @@
-{ lib, stdenv, llvm_meta, version
-, monorepoSrc, runCommand
-, cmake
-, enableShared ? !stdenv.hostPlatform.isStatic
-}:
-
-stdenv.mkDerivation rec {
-  pname = "libunwind";
-  inherit version;
-
-  # I am not so comfortable giving libc++ and friends the whole monorepo as
-  # requested, so I filter it to what is needed.
-  src = runCommand "${pname}-src-${version}" {} ''
-    mkdir -p "$out"
-    cp -r ${monorepoSrc}/cmake "$out"
-    cp -r ${monorepoSrc}/${pname} "$out"
-    mkdir -p "$out/libcxx"
-    cp -r ${monorepoSrc}/libcxx/cmake "$out/libcxx"
-    cp -r ${monorepoSrc}/libcxx/utils "$out/libcxx"
-    mkdir -p "$out/llvm"
-    cp -r ${monorepoSrc}/llvm/cmake "$out/llvm"
-  '';
-
-  sourceRoot = "${src.name}/${pname}";
-
-  patches = [
-    ./gnu-install-dirs.patch
-  ];
-
-  outputs = [ "out" "dev" ];
-
-  nativeBuildInputs = [ cmake ];
-
-  cmakeFlags = lib.optional (!enableShared) "-DLIBUNWIND_ENABLE_SHARED=OFF";
-
-  meta = llvm_meta // {
-    # Details: https://github.com/llvm/llvm-project/blob/main/libunwind/docs/index.rst
-    homepage = "https://clang.llvm.org/docs/Toolchain.html#unwind-library";
-    description = "LLVM's unwinder library";
-    longDescription = ''
-      The unwind library provides a family of _Unwind_* functions implementing
-      the language-neutral stack unwinding portion of the Itanium C++ ABI (Level
-      I). It is a dependency of the C++ ABI library, and sometimes is a
-      dependency of other runtimes.
-    '';
-  };
-}
diff --git a/pkgs/development/compilers/llvm/14/lld/default.nix b/pkgs/development/compilers/llvm/14/lld/default.nix
deleted file mode 100644
index 02ca4c802487..000000000000
--- a/pkgs/development/compilers/llvm/14/lld/default.nix
+++ /dev/null
@@ -1,58 +0,0 @@
-{ lib, stdenv, llvm_meta
-, buildLlvmTools
-, monorepoSrc, runCommand
-, cmake
-, libxml2
-, libllvm
-, version
-}:
-
-stdenv.mkDerivation rec {
-  pname = "lld";
-  inherit version;
-
-  # Blank llvm dir just so relative path works
-  src = runCommand "${pname}-src-${version}" {} ''
-    mkdir -p "$out"
-    cp -r ${monorepoSrc}/cmake "$out"
-    cp -r ${monorepoSrc}/${pname} "$out"
-    mkdir -p "$out/libunwind"
-    cp -r ${monorepoSrc}/libunwind/include "$out/libunwind"
-    mkdir -p "$out/llvm"
-  '';
-
-  sourceRoot = "${src.name}/${pname}";
-
-  patches = [
-    ./gnu-install-dirs.patch
-    # On Darwin the llvm-config is perhaps not working fine as the
-    # LLVM_MAIN_SRC_DIR is not getting set correctly, and the build fails as
-    # the include path is not correct.
-    ./fix-root-src-dir.patch
-  ];
-
-  nativeBuildInputs = [ cmake ];
-  buildInputs = [ libllvm libxml2 ];
-
-  cmakeFlags = lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [
-    "-DLLVM_TABLEGEN_EXE=${buildLlvmTools.llvm}/bin/llvm-tblgen"
-  ];
-
-  # Musl's default stack size is too small for lld to be able to link Firefox.
-  LDFLAGS = lib.optionalString stdenv.hostPlatform.isMusl "-Wl,-z,stack-size=2097152";
-
-  outputs = [ "out" "lib" "dev" ];
-
-  meta = llvm_meta // {
-    homepage = "https://lld.llvm.org/";
-    description = "The LLVM linker (unwrapped)";
-    longDescription = ''
-      LLD is a linker from the LLVM project that is a drop-in replacement for
-      system linkers and runs much faster than them. It also provides features
-      that are useful for toolchain developers.
-      The linker supports ELF (Unix), PE/COFF (Windows), Mach-O (macOS), and
-      WebAssembly in descending order of completeness. Internally, LLD consists
-      of several different linkers.
-    '';
-  };
-}
diff --git a/pkgs/development/compilers/llvm/14/openmp/default.nix b/pkgs/development/compilers/llvm/14/openmp/default.nix
deleted file mode 100644
index d1c6a46b4d69..000000000000
--- a/pkgs/development/compilers/llvm/14/openmp/default.nix
+++ /dev/null
@@ -1,69 +0,0 @@
-{ lib
-, stdenv
-, llvm_meta
-, monorepoSrc
-, runCommand
-, cmake
-, llvm
-, targetLlvm
-, lit
-, clang-unwrapped
-, perl
-, pkg-config
-, version
-}:
-
-stdenv.mkDerivation rec {
-  pname = "openmp";
-  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 = [
-    ./gnu-install-dirs.patch
-    ./run-lit-directly.patch
-  ];
-
-  outputs = [ "out" "dev" ];
-
-  nativeBuildInputs = [ cmake perl pkg-config lit ];
-  buildInputs = [
-    (if stdenv.buildPlatform == stdenv.hostPlatform then llvm else targetLlvm)
-  ];
-
-  # Unsup:Pass:XFail:Fail
-  # 26:267:16:8
-  doCheck = false;
-  checkTarget = "check-openmp";
-
-  preCheck = ''
-    patchShebangs ../tools/archer/tests/deflake.bash
-  '';
-
-  cmakeFlags = [
-    "-DCLANG_TOOL=${clang-unwrapped}/bin/clang"
-    "-DOPT_TOOL=${llvm}/bin/opt"
-    "-DLINK_TOOL=${llvm}/bin/llvm-link"
-  ];
-
-  meta = llvm_meta // {
-    homepage = "https://openmp.llvm.org/";
-    description = "Support for the OpenMP language";
-    longDescription = ''
-      The OpenMP subproject of LLVM contains the components required to build an
-      executable OpenMP program that are outside the compiler itself.
-      Contains the code for the runtime library against which code compiled by
-      "clang -fopenmp" must be linked before it can run and the library that
-      supports offload to target devices.
-    '';
-    # "All of the code is dual licensed under the MIT license and the UIUC
-    # License (a BSD-like license)":
-    license = with lib.licenses; [ mit ncsa ];
-  };
-}
diff --git a/pkgs/development/compilers/llvm/15/default.nix b/pkgs/development/compilers/llvm/15/default.nix
index dcafd2970d00..52ab1783b876 100644
--- a/pkgs/development/compilers/llvm/15/default.nix
+++ b/pkgs/development/compilers/llvm/15/default.nix
@@ -141,7 +141,10 @@ in let
       extraBuildCommands = mkExtraBuildCommands cc;
     };
 
-    lld = callPackage ./lld {
+    lld = callPackage ../common/lld {
+      patches = [
+        ./lld/gnu-install-dirs.patch
+      ];
       inherit llvm_meta;
     };
 
@@ -312,12 +315,20 @@ in let
       stdenv = overrideCC stdenv buildLlvmTools.clangNoLibcxx;
     };
 
-    libunwind = callPackage ./libunwind {
+    libunwind = callPackage ../common/libunwind {
+      patches = [
+        ./libunwind/gnu-install-dirs.patch
+      ];
       inherit llvm_meta;
       stdenv = overrideCC stdenv buildLlvmTools.clangNoLibcxx;
     };
 
-    openmp = callPackage ./openmp {
+    openmp = callPackage ../common/openmp {
+      patches = [
+        ./openmp/fix-find-tool.patch
+        ./openmp/gnu-install-dirs.patch
+        ./openmp/run-lit-directly.patch
+      ];
       inherit llvm_meta targetLlvm;
     };
   });
diff --git a/pkgs/development/compilers/llvm/15/libunwind/default.nix b/pkgs/development/compilers/llvm/15/libunwind/default.nix
deleted file mode 100644
index 1b677a7a2c0d..000000000000
--- a/pkgs/development/compilers/llvm/15/libunwind/default.nix
+++ /dev/null
@@ -1,67 +0,0 @@
-{ lib, stdenv, llvm_meta, version
-, monorepoSrc, runCommand
-, cmake
-, ninja
-, python3
-, enableShared ? !stdenv.hostPlatform.isStatic
-}:
-
-stdenv.mkDerivation rec {
-  pname = "libunwind";
-  inherit version;
-
-  # I am not so comfortable giving libc++ and friends the whole monorepo as
-  # requested, so I filter it to what is needed.
-  src = runCommand "${pname}-src-${version}" {} ''
-    mkdir -p "$out"
-    cp -r ${monorepoSrc}/cmake "$out"
-    cp -r ${monorepoSrc}/${pname} "$out"
-    mkdir -p "$out/libcxx"
-    cp -r ${monorepoSrc}/libcxx/cmake "$out/libcxx"
-    cp -r ${monorepoSrc}/libcxx/utils "$out/libcxx"
-    mkdir -p "$out/llvm"
-    cp -r ${monorepoSrc}/llvm/cmake "$out/llvm"
-    cp -r ${monorepoSrc}/llvm/utils "$out/llvm"
-    cp -r ${monorepoSrc}/runtimes "$out"
-  '';
-
-  sourceRoot = "${src.name}/runtimes";
-
-  prePatch = ''
-    cd ../${pname}
-    chmod -R u+w .
-  '';
-
-  patches = [
-    ./gnu-install-dirs.patch
-  ];
-
-  postPatch = ''
-    cd ../runtimes
-  '';
-
-  postInstall = lib.optionalString (enableShared && !stdenv.hostPlatform.isDarwin) ''
-    # libcxxabi wants to link to libunwind_shared.so (?).
-    ln -s $out/lib/libunwind.so $out/lib/libunwind_shared.so
-  '';
-
-  outputs = [ "out" "dev" ];
-
-  nativeBuildInputs = [ cmake ninja python3 ];
-
-  cmakeFlags = [
-    "-DLLVM_ENABLE_RUNTIMES=libunwind"
-  ] ++ lib.optional (!enableShared) "-DLIBUNWIND_ENABLE_SHARED=OFF";
-
-  meta = llvm_meta // {
-    # Details: https://github.com/llvm/llvm-project/blob/main/libunwind/docs/index.rst
-    homepage = "https://clang.llvm.org/docs/Toolchain.html#unwind-library";
-    description = "LLVM's unwinder library";
-    longDescription = ''
-      The unwind library provides a family of _Unwind_* functions implementing
-      the language-neutral stack unwinding portion of the Itanium C++ ABI (Level
-      I). It is a dependency of the C++ ABI library, and sometimes is a
-      dependency of other runtimes.
-    '';
-  };
-}
diff --git a/pkgs/development/compilers/llvm/15/lld/default.nix b/pkgs/development/compilers/llvm/15/lld/default.nix
deleted file mode 100644
index cc18aee76a44..000000000000
--- a/pkgs/development/compilers/llvm/15/lld/default.nix
+++ /dev/null
@@ -1,57 +0,0 @@
-{ lib, stdenv, llvm_meta
-, buildLlvmTools
-, monorepoSrc, runCommand
-, cmake
-, ninja
-, libxml2
-, libllvm
-, version
-}:
-
-stdenv.mkDerivation rec {
-  pname = "lld";
-  inherit version;
-
-  # Blank llvm dir just so relative path works
-  src = runCommand "${pname}-src-${version}" {} ''
-    mkdir -p "$out"
-    cp -r ${monorepoSrc}/cmake "$out"
-    cp -r ${monorepoSrc}/${pname} "$out"
-    mkdir -p "$out/libunwind"
-    cp -r ${monorepoSrc}/libunwind/include "$out/libunwind"
-    mkdir -p "$out/llvm"
-  '';
-
-  sourceRoot = "${src.name}/${pname}";
-
-  patches = [
-    ./gnu-install-dirs.patch
-  ];
-
-  nativeBuildInputs = [ cmake ninja ];
-  buildInputs = [ libllvm libxml2 ];
-
-  cmakeFlags = [
-    "-DLLD_INSTALL_PACKAGE_DIR=${placeholder "dev"}/lib/cmake/lld"
-  ] ++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [
-    "-DLLVM_TABLEGEN_EXE=${buildLlvmTools.llvm}/bin/llvm-tblgen"
-  ];
-
-  # Musl's default stack size is too small for lld to be able to link Firefox.
-  LDFLAGS = lib.optionalString stdenv.hostPlatform.isMusl "-Wl,-z,stack-size=2097152";
-
-  outputs = [ "out" "lib" "dev" ];
-
-  meta = llvm_meta // {
-    homepage = "https://lld.llvm.org/";
-    description = "The LLVM linker (unwrapped)";
-    longDescription = ''
-      LLD is a linker from the LLVM project that is a drop-in replacement for
-      system linkers and runs much faster than them. It also provides features
-      that are useful for toolchain developers.
-      The linker supports ELF (Unix), PE/COFF (Windows), Mach-O (macOS), and
-      WebAssembly in descending order of completeness. Internally, LLD consists
-      of several different linkers.
-    '';
-  };
-}
diff --git a/pkgs/development/compilers/llvm/15/openmp/default.nix b/pkgs/development/compilers/llvm/15/openmp/default.nix
deleted file mode 100644
index d51335436ad2..000000000000
--- a/pkgs/development/compilers/llvm/15/openmp/default.nix
+++ /dev/null
@@ -1,74 +0,0 @@
-{ lib
-, stdenv
-, llvm_meta
-, monorepoSrc
-, runCommand
-, cmake
-, ninja
-, llvm
-, targetLlvm
-, lit
-, clang-unwrapped
-, perl
-, pkg-config
-, xcbuild
-, version
-}:
-
-stdenv.mkDerivation rec {
-  pname = "openmp";
-  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 = [
-    ./fix-find-tool.patch
-    ./gnu-install-dirs.patch
-    ./run-lit-directly.patch
-  ];
-
-  outputs = [ "out" "dev" ];
-
-  nativeBuildInputs = [ cmake ninja perl pkg-config lit ];
-  buildInputs = [
-    (if stdenv.buildPlatform == stdenv.hostPlatform then llvm else targetLlvm)
-  ];
-
-  nativeCheckInputs = lib.optional stdenv.hostPlatform.isDarwin xcbuild.xcrun;
-
-  # Unsup:Pass:XFail:Fail
-  # 26:267:16:8
-  doCheck = false;
-  checkTarget = "check-openmp";
-
-  preCheck = ''
-    patchShebangs ../tools/archer/tests/deflake.bash
-  '';
-
-  cmakeFlags = [
-    "-DCLANG_TOOL=${clang-unwrapped}/bin/clang"
-    "-DOPT_TOOL=${llvm}/bin/opt"
-    "-DLINK_TOOL=${llvm}/bin/llvm-link"
-  ];
-
-  meta = llvm_meta // {
-    homepage = "https://openmp.llvm.org/";
-    description = "Support for the OpenMP language";
-    longDescription = ''
-      The OpenMP subproject of LLVM contains the components required to build an
-      executable OpenMP program that are outside the compiler itself.
-      Contains the code for the runtime library against which code compiled by
-      "clang -fopenmp" must be linked before it can run and the library that
-      supports offload to target devices.
-    '';
-    # "All of the code is dual licensed under the MIT license and the UIUC
-    # License (a BSD-like license)":
-    license = with lib.licenses; [ mit ncsa ];
-  };
-}
diff --git a/pkgs/development/compilers/llvm/16/default.nix b/pkgs/development/compilers/llvm/16/default.nix
index 46d17c193fc9..168c288d49a3 100644
--- a/pkgs/development/compilers/llvm/16/default.nix
+++ b/pkgs/development/compilers/llvm/16/default.nix
@@ -141,7 +141,11 @@ in let
       extraBuildCommands = mkExtraBuildCommands cc;
     };
 
-    lld = callPackage ./lld {
+    lld = callPackage ../common/lld {
+      patches = [
+        ./lld/gnu-install-dirs.patch
+        ./lld/add-table-base.patch
+      ];
       inherit llvm_meta;
     };
 
@@ -327,12 +331,20 @@ in let
       stdenv = overrideCC stdenv buildLlvmTools.clangNoLibcxx;
     };
 
-    libunwind = callPackage ./libunwind {
+    libunwind = callPackage ../common/libunwind {
+      patches = [
+        ./libunwind/gnu-install-dirs.patch
+      ];
       inherit llvm_meta;
       stdenv = overrideCC stdenv buildLlvmTools.clangNoLibcxx;
     };
 
-    openmp = callPackage ./openmp {
+    openmp = callPackage ../common/openmp {
+      patches = [
+        ./openmp/fix-find-tool.patch
+        ./openmp/gnu-install-dirs.patch
+        ./openmp/run-lit-directly.patch
+      ];
       inherit llvm_meta targetLlvm;
     };
   });
diff --git a/pkgs/development/compilers/llvm/16/libunwind/default.nix b/pkgs/development/compilers/llvm/16/libunwind/default.nix
deleted file mode 100644
index 1b677a7a2c0d..000000000000
--- a/pkgs/development/compilers/llvm/16/libunwind/default.nix
+++ /dev/null
@@ -1,67 +0,0 @@
-{ lib, stdenv, llvm_meta, version
-, monorepoSrc, runCommand
-, cmake
-, ninja
-, python3
-, enableShared ? !stdenv.hostPlatform.isStatic
-}:
-
-stdenv.mkDerivation rec {
-  pname = "libunwind";
-  inherit version;
-
-  # I am not so comfortable giving libc++ and friends the whole monorepo as
-  # requested, so I filter it to what is needed.
-  src = runCommand "${pname}-src-${version}" {} ''
-    mkdir -p "$out"
-    cp -r ${monorepoSrc}/cmake "$out"
-    cp -r ${monorepoSrc}/${pname} "$out"
-    mkdir -p "$out/libcxx"
-    cp -r ${monorepoSrc}/libcxx/cmake "$out/libcxx"
-    cp -r ${monorepoSrc}/libcxx/utils "$out/libcxx"
-    mkdir -p "$out/llvm"
-    cp -r ${monorepoSrc}/llvm/cmake "$out/llvm"
-    cp -r ${monorepoSrc}/llvm/utils "$out/llvm"
-    cp -r ${monorepoSrc}/runtimes "$out"
-  '';
-
-  sourceRoot = "${src.name}/runtimes";
-
-  prePatch = ''
-    cd ../${pname}
-    chmod -R u+w .
-  '';
-
-  patches = [
-    ./gnu-install-dirs.patch
-  ];
-
-  postPatch = ''
-    cd ../runtimes
-  '';
-
-  postInstall = lib.optionalString (enableShared && !stdenv.hostPlatform.isDarwin) ''
-    # libcxxabi wants to link to libunwind_shared.so (?).
-    ln -s $out/lib/libunwind.so $out/lib/libunwind_shared.so
-  '';
-
-  outputs = [ "out" "dev" ];
-
-  nativeBuildInputs = [ cmake ninja python3 ];
-
-  cmakeFlags = [
-    "-DLLVM_ENABLE_RUNTIMES=libunwind"
-  ] ++ lib.optional (!enableShared) "-DLIBUNWIND_ENABLE_SHARED=OFF";
-
-  meta = llvm_meta // {
-    # Details: https://github.com/llvm/llvm-project/blob/main/libunwind/docs/index.rst
-    homepage = "https://clang.llvm.org/docs/Toolchain.html#unwind-library";
-    description = "LLVM's unwinder library";
-    longDescription = ''
-      The unwind library provides a family of _Unwind_* functions implementing
-      the language-neutral stack unwinding portion of the Itanium C++ ABI (Level
-      I). It is a dependency of the C++ ABI library, and sometimes is a
-      dependency of other runtimes.
-    '';
-  };
-}
diff --git a/pkgs/development/compilers/llvm/16/lld/default.nix b/pkgs/development/compilers/llvm/16/lld/default.nix
deleted file mode 100644
index 84943e8effce..000000000000
--- a/pkgs/development/compilers/llvm/16/lld/default.nix
+++ /dev/null
@@ -1,58 +0,0 @@
-{ lib, stdenv, llvm_meta
-, buildLlvmTools
-, monorepoSrc, runCommand
-, cmake
-, ninja
-, libxml2
-, libllvm
-, version
-}:
-
-stdenv.mkDerivation rec {
-  pname = "lld";
-  inherit version;
-
-  # Blank llvm dir just so relative path works
-  src = runCommand "${pname}-src-${version}" {} ''
-    mkdir -p "$out"
-    cp -r ${monorepoSrc}/cmake "$out"
-    cp -r ${monorepoSrc}/${pname} "$out"
-    mkdir -p "$out/libunwind"
-    cp -r ${monorepoSrc}/libunwind/include "$out/libunwind"
-    mkdir -p "$out/llvm"
-  '';
-
-  sourceRoot = "${src.name}/${pname}";
-
-  patches = [
-    ./gnu-install-dirs.patch
-    ./add-table-base.patch
-  ];
-
-  nativeBuildInputs = [ cmake ninja ];
-  buildInputs = [ libllvm libxml2 ];
-
-  cmakeFlags = [
-    "-DLLD_INSTALL_PACKAGE_DIR=${placeholder "dev"}/lib/cmake/lld"
-  ] ++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [
-    "-DLLVM_TABLEGEN_EXE=${buildLlvmTools.llvm}/bin/llvm-tblgen"
-  ];
-
-  # Musl's default stack size is too small for lld to be able to link Firefox.
-  LDFLAGS = lib.optionalString stdenv.hostPlatform.isMusl "-Wl,-z,stack-size=2097152";
-
-  outputs = [ "out" "lib" "dev" ];
-
-  meta = llvm_meta // {
-    homepage = "https://lld.llvm.org/";
-    description = "The LLVM linker (unwrapped)";
-    longDescription = ''
-      LLD is a linker from the LLVM project that is a drop-in replacement for
-      system linkers and runs much faster than them. It also provides features
-      that are useful for toolchain developers.
-      The linker supports ELF (Unix), PE/COFF (Windows), Mach-O (macOS), and
-      WebAssembly in descending order of completeness. Internally, LLD consists
-      of several different linkers.
-    '';
-  };
-}
diff --git a/pkgs/development/compilers/llvm/16/openmp/default.nix b/pkgs/development/compilers/llvm/16/openmp/default.nix
deleted file mode 100644
index d51335436ad2..000000000000
--- a/pkgs/development/compilers/llvm/16/openmp/default.nix
+++ /dev/null
@@ -1,74 +0,0 @@
-{ lib
-, stdenv
-, llvm_meta
-, monorepoSrc
-, runCommand
-, cmake
-, ninja
-, llvm
-, targetLlvm
-, lit
-, clang-unwrapped
-, perl
-, pkg-config
-, xcbuild
-, version
-}:
-
-stdenv.mkDerivation rec {
-  pname = "openmp";
-  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 = [
-    ./fix-find-tool.patch
-    ./gnu-install-dirs.patch
-    ./run-lit-directly.patch
-  ];
-
-  outputs = [ "out" "dev" ];
-
-  nativeBuildInputs = [ cmake ninja perl pkg-config lit ];
-  buildInputs = [
-    (if stdenv.buildPlatform == stdenv.hostPlatform then llvm else targetLlvm)
-  ];
-
-  nativeCheckInputs = lib.optional stdenv.hostPlatform.isDarwin xcbuild.xcrun;
-
-  # Unsup:Pass:XFail:Fail
-  # 26:267:16:8
-  doCheck = false;
-  checkTarget = "check-openmp";
-
-  preCheck = ''
-    patchShebangs ../tools/archer/tests/deflake.bash
-  '';
-
-  cmakeFlags = [
-    "-DCLANG_TOOL=${clang-unwrapped}/bin/clang"
-    "-DOPT_TOOL=${llvm}/bin/opt"
-    "-DLINK_TOOL=${llvm}/bin/llvm-link"
-  ];
-
-  meta = llvm_meta // {
-    homepage = "https://openmp.llvm.org/";
-    description = "Support for the OpenMP language";
-    longDescription = ''
-      The OpenMP subproject of LLVM contains the components required to build an
-      executable OpenMP program that are outside the compiler itself.
-      Contains the code for the runtime library against which code compiled by
-      "clang -fopenmp" must be linked before it can run and the library that
-      supports offload to target devices.
-    '';
-    # "All of the code is dual licensed under the MIT license and the UIUC
-    # License (a BSD-like license)":
-    license = with lib.licenses; [ mit ncsa ];
-  };
-}
diff --git a/pkgs/development/compilers/llvm/17/default.nix b/pkgs/development/compilers/llvm/17/default.nix
index fb3e967cc39b..70571b30b3a6 100644
--- a/pkgs/development/compilers/llvm/17/default.nix
+++ b/pkgs/development/compilers/llvm/17/default.nix
@@ -136,7 +136,11 @@ in let
       extraBuildCommands = mkExtraBuildCommands cc;
     };
 
-    lld = callPackage ./lld {
+    lld = callPackage ../common/lld {
+      patches = [
+        ./lld/gnu-install-dirs.patch
+        ./lld/add-table-base.patch
+      ];
       inherit llvm_meta;
     };
 
@@ -312,12 +316,17 @@ in let
       stdenv = overrideCC stdenv buildLlvmTools.clangNoLibcxx;
     };
 
-    libunwind = callPackage ./libunwind {
+    libunwind = callPackage ../common/libunwind {
       inherit llvm_meta;
       stdenv = overrideCC stdenv buildLlvmTools.clangNoLibcxx;
     };
 
-    openmp = callPackage ./openmp {
+    openmp = callPackage ../common/openmp {
+      patches = [
+        ./openmp/fix-find-tool.patch
+        ./openmp/gnu-install-dirs.patch
+        ./openmp/run-lit-directly.patch
+      ];
       inherit llvm_meta targetLlvm;
     };
   });
diff --git a/pkgs/development/compilers/llvm/17/libunwind/default.nix b/pkgs/development/compilers/llvm/17/libunwind/default.nix
deleted file mode 100644
index a3c8e2594f5a..000000000000
--- a/pkgs/development/compilers/llvm/17/libunwind/default.nix
+++ /dev/null
@@ -1,63 +0,0 @@
-{ lib, stdenv, llvm_meta, version
-, monorepoSrc, runCommand
-, cmake
-, ninja
-, python3
-, enableShared ? !stdenv.hostPlatform.isStatic
-}:
-
-stdenv.mkDerivation rec {
-  pname = "libunwind";
-  inherit version;
-
-  # I am not so comfortable giving libc++ and friends the whole monorepo as
-  # requested, so I filter it to what is needed.
-  src = runCommand "${pname}-src-${version}" {} ''
-    mkdir -p "$out"
-    cp -r ${monorepoSrc}/cmake "$out"
-    cp -r ${monorepoSrc}/${pname} "$out"
-    mkdir -p "$out/libcxx"
-    cp -r ${monorepoSrc}/libcxx/cmake "$out/libcxx"
-    cp -r ${monorepoSrc}/libcxx/utils "$out/libcxx"
-    mkdir -p "$out/llvm"
-    cp -r ${monorepoSrc}/llvm/cmake "$out/llvm"
-    cp -r ${monorepoSrc}/llvm/utils "$out/llvm"
-    cp -r ${monorepoSrc}/runtimes "$out"
-  '';
-
-  sourceRoot = "${src.name}/runtimes";
-
-  prePatch = ''
-    cd ../${pname}
-    chmod -R u+w .
-  '';
-
-  postPatch = ''
-    cd ../runtimes
-  '';
-
-  postInstall = lib.optionalString (enableShared && !stdenv.hostPlatform.isDarwin) ''
-    # libcxxabi wants to link to libunwind_shared.so (?).
-    ln -s $out/lib/libunwind.so $out/lib/libunwind_shared.so
-  '';
-
-  outputs = [ "out" "dev" ];
-
-  nativeBuildInputs = [ cmake ninja python3 ];
-
-  cmakeFlags = [
-    "-DLLVM_ENABLE_RUNTIMES=libunwind"
-  ] ++ lib.optional (!enableShared) "-DLIBUNWIND_ENABLE_SHARED=OFF";
-
-  meta = llvm_meta // {
-    # Details: https://github.com/llvm/llvm-project/blob/main/libunwind/docs/index.rst
-    homepage = "https://clang.llvm.org/docs/Toolchain.html#unwind-library";
-    description = "LLVM's unwinder library";
-    longDescription = ''
-      The unwind library provides a family of _Unwind_* functions implementing
-      the language-neutral stack unwinding portion of the Itanium C++ ABI (Level
-      I). It is a dependency of the C++ ABI library, and sometimes is a
-      dependency of other runtimes.
-    '';
-  };
-}
diff --git a/pkgs/development/compilers/llvm/17/lld/default.nix b/pkgs/development/compilers/llvm/17/lld/default.nix
deleted file mode 100644
index 84943e8effce..000000000000
--- a/pkgs/development/compilers/llvm/17/lld/default.nix
+++ /dev/null
@@ -1,58 +0,0 @@
-{ lib, stdenv, llvm_meta
-, buildLlvmTools
-, monorepoSrc, runCommand
-, cmake
-, ninja
-, libxml2
-, libllvm
-, version
-}:
-
-stdenv.mkDerivation rec {
-  pname = "lld";
-  inherit version;
-
-  # Blank llvm dir just so relative path works
-  src = runCommand "${pname}-src-${version}" {} ''
-    mkdir -p "$out"
-    cp -r ${monorepoSrc}/cmake "$out"
-    cp -r ${monorepoSrc}/${pname} "$out"
-    mkdir -p "$out/libunwind"
-    cp -r ${monorepoSrc}/libunwind/include "$out/libunwind"
-    mkdir -p "$out/llvm"
-  '';
-
-  sourceRoot = "${src.name}/${pname}";
-
-  patches = [
-    ./gnu-install-dirs.patch
-    ./add-table-base.patch
-  ];
-
-  nativeBuildInputs = [ cmake ninja ];
-  buildInputs = [ libllvm libxml2 ];
-
-  cmakeFlags = [
-    "-DLLD_INSTALL_PACKAGE_DIR=${placeholder "dev"}/lib/cmake/lld"
-  ] ++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [
-    "-DLLVM_TABLEGEN_EXE=${buildLlvmTools.llvm}/bin/llvm-tblgen"
-  ];
-
-  # Musl's default stack size is too small for lld to be able to link Firefox.
-  LDFLAGS = lib.optionalString stdenv.hostPlatform.isMusl "-Wl,-z,stack-size=2097152";
-
-  outputs = [ "out" "lib" "dev" ];
-
-  meta = llvm_meta // {
-    homepage = "https://lld.llvm.org/";
-    description = "The LLVM linker (unwrapped)";
-    longDescription = ''
-      LLD is a linker from the LLVM project that is a drop-in replacement for
-      system linkers and runs much faster than them. It also provides features
-      that are useful for toolchain developers.
-      The linker supports ELF (Unix), PE/COFF (Windows), Mach-O (macOS), and
-      WebAssembly in descending order of completeness. Internally, LLD consists
-      of several different linkers.
-    '';
-  };
-}
diff --git a/pkgs/development/compilers/llvm/18/default.nix b/pkgs/development/compilers/llvm/18/default.nix
index 5f7f67438f0f..d5c2140e33e4 100644
--- a/pkgs/development/compilers/llvm/18/default.nix
+++ b/pkgs/development/compilers/llvm/18/default.nix
@@ -136,7 +136,10 @@ in let
       extraBuildCommands = mkExtraBuildCommands cc;
     };
 
-    lld = callPackage ./lld {
+    lld = callPackage ../common/lld {
+      patches = [
+        ./lld/gnu-install-dirs.patch
+      ];
       inherit llvm_meta;
     };
 
@@ -312,12 +315,16 @@ in let
       stdenv = overrideCC stdenv buildLlvmTools.clangNoLibcxx;
     };
 
-    libunwind = callPackage ./libunwind {
+    libunwind = callPackage ../common/libunwind {
       inherit llvm_meta;
       stdenv = overrideCC stdenv buildLlvmTools.clangNoLibcxx;
     };
 
-    openmp = callPackage ./openmp {
+    openmp = callPackage ../common/openmp {
+      patches = [
+        ./openmp/fix-find-tool.patch
+        ./openmp/run-lit-directly.patch
+      ];
       inherit llvm_meta targetLlvm;
     };
   });
diff --git a/pkgs/development/compilers/llvm/18/libunwind/default.nix b/pkgs/development/compilers/llvm/18/libunwind/default.nix
deleted file mode 100644
index e67823ffb85c..000000000000
--- a/pkgs/development/compilers/llvm/18/libunwind/default.nix
+++ /dev/null
@@ -1,54 +0,0 @@
-{ lib, stdenv, llvm_meta, version
-, monorepoSrc, runCommand
-, cmake
-, ninja
-, python3
-, enableShared ? !stdenv.hostPlatform.isStatic
-}:
-
-stdenv.mkDerivation rec {
-  pname = "libunwind";
-  inherit version;
-
-  # I am not so comfortable giving libc++ and friends the whole monorepo as
-  # requested, so I filter it to what is needed.
-  src = runCommand "${pname}-src-${version}" {} ''
-    mkdir -p "$out"
-    cp -r ${monorepoSrc}/cmake "$out"
-    cp -r ${monorepoSrc}/${pname} "$out"
-    mkdir -p "$out/libcxx"
-    cp -r ${monorepoSrc}/libcxx/cmake "$out/libcxx"
-    cp -r ${monorepoSrc}/libcxx/utils "$out/libcxx"
-    mkdir -p "$out/llvm"
-    cp -r ${monorepoSrc}/llvm/cmake "$out/llvm"
-    cp -r ${monorepoSrc}/llvm/utils "$out/llvm"
-    cp -r ${monorepoSrc}/runtimes "$out"
-  '';
-
-  sourceRoot = "${src.name}/runtimes";
-
-  postInstall = lib.optionalString (enableShared && !stdenv.hostPlatform.isDarwin) ''
-    # libcxxabi wants to link to libunwind_shared.so (?).
-    ln -s $out/lib/libunwind.so $out/lib/libunwind_shared.so
-  '';
-
-  outputs = [ "out" "dev" ];
-
-  nativeBuildInputs = [ cmake ninja python3 ];
-
-  cmakeFlags = [
-    "-DLLVM_ENABLE_RUNTIMES=libunwind"
-  ] ++ lib.optional (!enableShared) "-DLIBUNWIND_ENABLE_SHARED=OFF";
-
-  meta = llvm_meta // {
-    # Details: https://github.com/llvm/llvm-project/blob/main/libunwind/docs/index.rst
-    homepage = "https://clang.llvm.org/docs/Toolchain.html#unwind-library";
-    description = "LLVM's unwinder library";
-    longDescription = ''
-      The unwind library provides a family of _Unwind_* functions implementing
-      the language-neutral stack unwinding portion of the Itanium C++ ABI (Level
-      I). It is a dependency of the C++ ABI library, and sometimes is a
-      dependency of other runtimes.
-    '';
-  };
-}
diff --git a/pkgs/development/compilers/llvm/18/lld/default.nix b/pkgs/development/compilers/llvm/18/lld/default.nix
deleted file mode 100644
index 24ff0933dd1d..000000000000
--- a/pkgs/development/compilers/llvm/18/lld/default.nix
+++ /dev/null
@@ -1,57 +0,0 @@
-{ lib, stdenv, llvm_meta
-, buildLlvmTools
-, monorepoSrc, runCommand
-, cmake
-, ninja
-, libxml2
-, libllvm
-, version
-}:
-
-stdenv.mkDerivation rec {
-  pname = "lld";
-  inherit version;
-
-  # Blank llvm dir just so relative path works
-  src = runCommand "${pname}-src-${version}" {} ''
-    mkdir -p "$out"
-    cp -r ${monorepoSrc}/cmake "$out"
-    cp -r ${monorepoSrc}/${pname} "$out"
-    mkdir -p "$out/libunwind"
-    cp -r ${monorepoSrc}/libunwind/include "$out/libunwind"
-    mkdir -p "$out/llvm"
-  '';
-
-  sourceRoot = "${src.name}/${pname}";
-
-  nativeBuildInputs = [ cmake ninja ];
-  buildInputs = [ libllvm libxml2 ];
-
-  patches = [
-    ./gnu-install-dirs.patch
-  ];
-
-  cmakeFlags = [
-    "-DLLD_INSTALL_PACKAGE_DIR=${placeholder "dev"}/lib/cmake/lld"
-  ] ++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [
-    "-DLLVM_TABLEGEN_EXE=${buildLlvmTools.llvm}/bin/llvm-tblgen"
-  ];
-
-  # Musl's default stack size is too small for lld to be able to link Firefox.
-  LDFLAGS = lib.optionalString stdenv.hostPlatform.isMusl "-Wl,-z,stack-size=2097152";
-
-  outputs = [ "out" "lib" "dev" ];
-
-  meta = llvm_meta // {
-    homepage = "https://lld.llvm.org/";
-    description = "The LLVM linker (unwrapped)";
-    longDescription = ''
-      LLD is a linker from the LLVM project that is a drop-in replacement for
-      system linkers and runs much faster than them. It also provides features
-      that are useful for toolchain developers.
-      The linker supports ELF (Unix), PE/COFF (Windows), Mach-O (macOS), and
-      WebAssembly in descending order of completeness. Internally, LLD consists
-      of several different linkers.
-    '';
-  };
-}
diff --git a/pkgs/development/compilers/llvm/18/openmp/default.nix b/pkgs/development/compilers/llvm/18/openmp/default.nix
deleted file mode 100644
index e1c3c2379af2..000000000000
--- a/pkgs/development/compilers/llvm/18/openmp/default.nix
+++ /dev/null
@@ -1,73 +0,0 @@
-{ lib
-, stdenv
-, llvm_meta
-, monorepoSrc
-, runCommand
-, cmake
-, ninja
-, llvm
-, targetLlvm
-, lit
-, clang-unwrapped
-, perl
-, pkg-config
-, xcbuild
-, version
-}:
-
-stdenv.mkDerivation rec {
-  pname = "openmp";
-  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 = [
-    ./fix-find-tool.patch
-    ./run-lit-directly.patch
-  ];
-
-  outputs = [ "out" "dev" ];
-
-  nativeBuildInputs = [ cmake ninja perl pkg-config lit ];
-  buildInputs = [
-    (if stdenv.buildPlatform == stdenv.hostPlatform then llvm else targetLlvm)
-  ];
-
-  nativeCheckInputs = lib.optional stdenv.hostPlatform.isDarwin xcbuild.xcrun;
-
-  # Unsup:Pass:XFail:Fail
-  # 26:267:16:8
-  doCheck = false;
-  checkTarget = "check-openmp";
-
-  preCheck = ''
-    patchShebangs ../tools/archer/tests/deflake.bash
-  '';
-
-  cmakeFlags = [
-    "-DCLANG_TOOL=${clang-unwrapped}/bin/clang"
-    "-DOPT_TOOL=${llvm}/bin/opt"
-    "-DLINK_TOOL=${llvm}/bin/llvm-link"
-  ];
-
-  meta = llvm_meta // {
-    homepage = "https://openmp.llvm.org/";
-    description = "Support for the OpenMP language";
-    longDescription = ''
-      The OpenMP subproject of LLVM contains the components required to build an
-      executable OpenMP program that are outside the compiler itself.
-      Contains the code for the runtime library against which code compiled by
-      "clang -fopenmp" must be linked before it can run and the library that
-      supports offload to target devices.
-    '';
-    # "All of the code is dual licensed under the MIT license and the UIUC
-    # License (a BSD-like license)":
-    license = with lib.licenses; [ mit ncsa ];
-  };
-}
diff --git a/pkgs/development/compilers/llvm/common/libunwind/default.nix b/pkgs/development/compilers/llvm/common/libunwind/default.nix
new file mode 100644
index 000000000000..515914e6acb6
--- /dev/null
+++ b/pkgs/development/compilers/llvm/common/libunwind/default.nix
@@ -0,0 +1,87 @@
+{ lib
+, stdenv
+, release_version
+, patches ? []
+, src ? null
+, llvm_meta
+, version
+, monorepoSrc ? null
+, runCommand
+, cmake
+, ninja
+, python3
+, libcxx
+, enableShared ? !stdenv.hostPlatform.isStatic
+}:
+let
+  pname = "libunwind";
+  src' = if monorepoSrc != null then
+    runCommand "${pname}-src-${version}" {} (''
+      mkdir -p "$out"
+      cp -r ${monorepoSrc}/cmake "$out"
+      cp -r ${monorepoSrc}/${pname} "$out"
+      mkdir -p "$out/libcxx"
+      cp -r ${monorepoSrc}/libcxx/cmake "$out/libcxx"
+      cp -r ${monorepoSrc}/libcxx/utils "$out/libcxx"
+      mkdir -p "$out/llvm"
+      cp -r ${monorepoSrc}/llvm/cmake "$out/llvm"
+    '' + lib.optionalString (lib.versionAtLeast release_version "15") ''
+      cp -r ${monorepoSrc}/llvm/utils "$out/llvm"
+      cp -r ${monorepoSrc}/runtimes "$out"
+    '') else src;
+
+  hasPatches = builtins.length patches > 0;
+
+  postUnpack = lib.optionalString (lib.versions.major release_version == "12") ''
+    ln -s ${libcxx.src}/libcxx .
+    ln -s ${libcxx.src}/llvm .
+  '';
+
+  prePatch = lib.optionalString (lib.versionAtLeast release_version "15" && (hasPatches || lib.versionOlder release_version "18")) ''
+    cd ../${pname}
+    chmod -R u+w .
+  '';
+
+  postPatch = lib.optionalString (lib.versionAtLeast release_version "15" && (hasPatches || lib.versionOlder release_version "18")) ''
+    cd ../runtimes
+  '';
+
+  postInstall = lib.optionalString (enableShared && !stdenv.hostPlatform.isDarwin) ''
+    # libcxxabi wants to link to libunwind_shared.so (?).
+    ln -s $out/lib/libunwind.so $out/lib/libunwind_shared.so
+  '';
+in
+stdenv.mkDerivation (rec {
+  inherit pname version patches;
+
+  src = src';
+
+  sourceRoot =
+    if lib.versionOlder release_version "13" then null
+    else if lib.versionAtLeast release_version "15" then "${src.name}/runtimes"
+    else "${src.name}/${pname}";
+
+  outputs = [ "out" "dev" ];
+
+  nativeBuildInputs = [ cmake ] ++ lib.optionals (lib.versionAtLeast release_version "15") [
+    ninja python3
+  ];
+
+  cmakeFlags = lib.optional (lib.versionAtLeast release_version "15") "-DLLVM_ENABLE_RUNTIMES=libunwind"
+    ++ lib.optional (!enableShared) "-DLIBUNWIND_ENABLE_SHARED=OFF";
+
+  meta = llvm_meta // {
+    # Details: https://github.com/llvm/llvm-project/blob/main/libunwind/docs/index.rst
+    homepage = "https://clang.llvm.org/docs/Toolchain.html#unwind-library";
+    description = "LLVM's unwinder library";
+    longDescription = ''
+      The unwind library provides a family of _Unwind_* functions implementing
+      the language-neutral stack unwinding portion of the Itanium C++ ABI (Level
+      I). It is a dependency of the C++ ABI library, and sometimes is a
+      dependency of other runtimes.
+    '';
+  };
+} // (if postUnpack != "" then { inherit postUnpack; } else {})
+  // (if (lib.versionAtLeast release_version "15") then { inherit postInstall; } else {})
+  // (if prePatch != "" then { inherit prePatch; } else {})
+  // (if postPatch != "" then { inherit postPatch; } else {}))
diff --git a/pkgs/development/compilers/llvm/12/lld/default.nix b/pkgs/development/compilers/llvm/common/lld/default.nix
index 01b7e410aa07..be296be91e77 100644
--- a/pkgs/development/compilers/llvm/12/lld/default.nix
+++ b/pkgs/development/compilers/llvm/common/lld/default.nix
@@ -1,35 +1,58 @@
-{ lib, stdenv, llvm_meta
+{ lib
+, stdenv
+, llvm_meta
+, release_version
+, patches ? []
 , buildLlvmTools
-, fetch
-, libunwind
+, monorepoSrc ? null
+, src ? null
+, libunwind ? null
+, runCommand
 , cmake
+, ninja
 , libxml2
 , libllvm
 , version
 }:
-
-stdenv.mkDerivation rec {
+let
   pname = "lld";
-  inherit version;
-
-  src = fetch pname "0qg3fgc7wj34hdkqn21y03zcmsdd01szhhm1hfki63iifrm3y2v9";
-
-  patches = [
-    ./gnu-install-dirs.patch
-  ];
+  src' =
+    if monorepoSrc != null then
+      runCommand "lld-src-${version}" {} ''
+        mkdir -p "$out"
+        cp -r ${monorepoSrc}/cmake "$out"
+        cp -r ${monorepoSrc}/${pname} "$out"
+        mkdir -p "$out/libunwind"
+        cp -r ${monorepoSrc}/libunwind/include "$out/libunwind"
+        mkdir -p "$out/llvm"
+      '' else src;
 
-  postPatch = ''
+  postPatch = lib.optionalString (lib.versions.major release_version == "12") ''
     substituteInPlace MachO/CMakeLists.txt --replace \
       '(''${LLVM_MAIN_SRC_DIR}/' '('
     mkdir -p libunwind/include
     tar -xf "${libunwind.src}" --wildcards -C libunwind/include --strip-components=2 "libunwind-*/include/"
+  '' + lib.optionalString (lib.versions.major release_version == "13" && stdenv.isDarwin) ''
+    substituteInPlace MachO/CMakeLists.txt --replace \
+      '(''${LLVM_MAIN_SRC_DIR}/' '(../'
   '';
+in
+stdenv.mkDerivation (rec {
+  inherit pname version patches;
+
+  src = src';
+
+  sourceRoot =
+    if lib.versionOlder release_version "13" then null
+    else "${src.name}/${pname}";
 
-  nativeBuildInputs = [ cmake ];
+  nativeBuildInputs = [ cmake ] ++ lib.optional (lib.versionAtLeast release_version "15") ninja;
   buildInputs = [ libllvm libxml2 ];
 
-  cmakeFlags = [
+  cmakeFlags = lib.optionals (lib.versionOlder release_version "14") [
     "-DLLVM_CONFIG_PATH=${libllvm.dev}/bin/llvm-config${lib.optionalString (stdenv.hostPlatform != stdenv.buildPlatform) "-native"}"
+  ] ++ lib.optionals (lib.versionAtLeast release_version "15") [
+    "-DLLD_INSTALL_PACKAGE_DIR=${placeholder "dev"}/lib/cmake/lld"
   ] ++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [
     "-DLLVM_TABLEGEN_EXE=${buildLlvmTools.llvm}/bin/llvm-tblgen"
   ];
@@ -51,4 +74,4 @@ stdenv.mkDerivation rec {
       of several different linkers.
     '';
   };
-}
+} // (if (postPatch == "" && lib.versions.major release_version != "13") then {} else { inherit postPatch; }))
diff --git a/pkgs/development/compilers/llvm/17/openmp/default.nix b/pkgs/development/compilers/llvm/common/openmp/default.nix
index d51335436ad2..7d9d813f024c 100644
--- a/pkgs/development/compilers/llvm/17/openmp/default.nix
+++ b/pkgs/development/compilers/llvm/common/openmp/default.nix
@@ -1,7 +1,10 @@
 { lib
 , stdenv
 , llvm_meta
-, monorepoSrc
+, release_version
+, patches ? []
+, monorepoSrc ? null
+, src ? null
 , runCommand
 , cmake
 , ninja
@@ -14,44 +17,47 @@
 , xcbuild
 , version
 }:
-
-stdenv.mkDerivation rec {
+let
   pname = "openmp";
-  inherit version;
+  src' =
+    if monorepoSrc != null then
+      runCommand "${pname}-src-${version}" {} ''
+        mkdir -p "$out"
+        cp -r ${monorepoSrc}/cmake "$out"
+        cp -r ${monorepoSrc}/${pname} "$out"
+      '' else src;
+in
+stdenv.mkDerivation (rec {
+  inherit pname version patches;
 
-  src = runCommand "${pname}-src-${version}" {} ''
-    mkdir -p "$out"
-    cp -r ${monorepoSrc}/cmake "$out"
-    cp -r ${monorepoSrc}/${pname} "$out"
-  '';
+  src = src';
 
-  sourceRoot = "${src.name}/${pname}";
+  sourceRoot =
+    if lib.versionOlder release_version "13" then null
+    else "${src.name}/${pname}";
 
-  patches = [
-    ./fix-find-tool.patch
-    ./gnu-install-dirs.patch
-    ./run-lit-directly.patch
-  ];
+  outputs = [ "out" ]
+    ++ lib.optionals (lib.versionAtLeast release_version "14") [ "dev" ];
 
-  outputs = [ "out" "dev" ];
+  patchFlags =
+    if lib.versionOlder release_version "14" then [ "-p2" ]
+    else null;
+
+  nativeBuildInputs = [
+    cmake
+  ] ++ lib.optionals (lib.versionAtLeast release_version "15") [
+    ninja
+  ] ++ [ perl ] ++ lib.optionals (lib.versionAtLeast release_version "14") [
+    pkg-config lit
+  ];
 
-  nativeBuildInputs = [ cmake ninja perl pkg-config lit ];
   buildInputs = [
     (if stdenv.buildPlatform == stdenv.hostPlatform then llvm else targetLlvm)
   ];
 
-  nativeCheckInputs = lib.optional stdenv.hostPlatform.isDarwin xcbuild.xcrun;
-
-  # Unsup:Pass:XFail:Fail
-  # 26:267:16:8
-  doCheck = false;
-  checkTarget = "check-openmp";
-
-  preCheck = ''
-    patchShebangs ../tools/archer/tests/deflake.bash
-  '';
-
-  cmakeFlags = [
+  cmakeFlags = lib.optionals (lib.versions.major release_version == "13") [
+    "-DLIBOMPTARGET_BUILD_AMDGCN_BCLIB=OFF" # Building the AMDGCN device RTL fails
+  ] ++ lib.optionals (lib.versionAtLeast release_version "14") [
     "-DCLANG_TOOL=${clang-unwrapped}/bin/clang"
     "-DOPT_TOOL=${llvm}/bin/opt"
     "-DLINK_TOOL=${llvm}/bin/llvm-link"
@@ -71,4 +77,10 @@ stdenv.mkDerivation rec {
     # License (a BSD-like license)":
     license = with lib.licenses; [ mit ncsa ];
   };
-}
+} // (lib.optionalAttrs (lib.versionAtLeast release_version "14") {
+  doCheck = false;
+  checkTarget = "check-openmp";
+  preCheck = ''
+    patchShebangs ../tools/archer/tests/deflake.bash
+  '';
+}))
diff --git a/pkgs/development/compilers/llvm/git/compiler-rt/default.nix b/pkgs/development/compilers/llvm/git/compiler-rt/default.nix
index f51316beb570..606ae2868893 100644
--- a/pkgs/development/compilers/llvm/git/compiler-rt/default.nix
+++ b/pkgs/development/compilers/llvm/git/compiler-rt/default.nix
@@ -81,6 +81,8 @@ stdenv.mkDerivation {
     # `COMPILER_RT_DEFAULT_TARGET_ONLY` does not apply to Darwin:
     # https://github.com/llvm/llvm-project/blob/27ef42bec80b6c010b7b3729ed0528619521a690/compiler-rt/cmake/base-config-ix.cmake#L153
     "-DCOMPILER_RT_ENABLE_IOS=OFF"
+  ] ++ lib.optionals (lib.versionAtLeast version "19" && stdenv.isDarwin && lib.versionOlder stdenv.hostPlatform.darwinMinVersion "10.13") [
+    "-DSANITIZER_MIN_OSX_VERSION=10.10"
   ];
 
   outputs = [ "out" "dev" ];
diff --git a/pkgs/development/compilers/llvm/git/default.nix b/pkgs/development/compilers/llvm/git/default.nix
index bd21a75b8c2f..d578c2a290e2 100644
--- a/pkgs/development/compilers/llvm/git/default.nix
+++ b/pkgs/development/compilers/llvm/git/default.nix
@@ -19,9 +19,9 @@
 # LLVM release information; specify one of these but not both:
 , gitRelease ? {
     version = "19.0.0-git";
-    rev = "65058a8d732c3c41664a4dad1a1ae2a504d5c98e";
-    rev-version = "19.0.0-unstable-2024-03-16";
-    sha256 = "sha256-xV33kx/8OZ2KLtaz25RmudDrlIX7nScauTykf87jyTE=";
+    rev = "cebf77fb936a7270c7e3fa5c4a7e76216321d385";
+    rev-version = "19.0.0-unstable-2024-04-07";
+    sha256 = "sha256-616tscgsiFgHQcXW4KzK5srrudYizQFnJVM6K0qRf+I=";
 }
   # i.e.:
   # {
@@ -141,7 +141,10 @@ in let
       extraBuildCommands = mkExtraBuildCommands cc;
     };
 
-    lld = callPackage ./lld {
+    lld = callPackage ../common/lld {
+      patches = [
+        ./lld/gnu-install-dirs.patch
+      ];
       inherit llvm_meta;
     };
 
@@ -317,12 +320,16 @@ in let
       stdenv = overrideCC stdenv buildLlvmTools.clangNoLibcxx;
     };
 
-    libunwind = callPackage ./libunwind {
+    libunwind = callPackage ../common/libunwind {
       inherit llvm_meta;
       stdenv = overrideCC stdenv buildLlvmTools.clangNoLibcxx;
     };
 
-    openmp = callPackage ./openmp {
+    openmp = callPackage ../common/openmp {
+      patches = [
+        ./openmp/fix-find-tool.patch
+        ./openmp/run-lit-directly.patch
+      ];
       inherit llvm_meta targetLlvm;
     };
   });
diff --git a/pkgs/development/compilers/llvm/git/libunwind/default.nix b/pkgs/development/compilers/llvm/git/libunwind/default.nix
deleted file mode 100644
index e67823ffb85c..000000000000
--- a/pkgs/development/compilers/llvm/git/libunwind/default.nix
+++ /dev/null
@@ -1,54 +0,0 @@
-{ lib, stdenv, llvm_meta, version
-, monorepoSrc, runCommand
-, cmake
-, ninja
-, python3
-, enableShared ? !stdenv.hostPlatform.isStatic
-}:
-
-stdenv.mkDerivation rec {
-  pname = "libunwind";
-  inherit version;
-
-  # I am not so comfortable giving libc++ and friends the whole monorepo as
-  # requested, so I filter it to what is needed.
-  src = runCommand "${pname}-src-${version}" {} ''
-    mkdir -p "$out"
-    cp -r ${monorepoSrc}/cmake "$out"
-    cp -r ${monorepoSrc}/${pname} "$out"
-    mkdir -p "$out/libcxx"
-    cp -r ${monorepoSrc}/libcxx/cmake "$out/libcxx"
-    cp -r ${monorepoSrc}/libcxx/utils "$out/libcxx"
-    mkdir -p "$out/llvm"
-    cp -r ${monorepoSrc}/llvm/cmake "$out/llvm"
-    cp -r ${monorepoSrc}/llvm/utils "$out/llvm"
-    cp -r ${monorepoSrc}/runtimes "$out"
-  '';
-
-  sourceRoot = "${src.name}/runtimes";
-
-  postInstall = lib.optionalString (enableShared && !stdenv.hostPlatform.isDarwin) ''
-    # libcxxabi wants to link to libunwind_shared.so (?).
-    ln -s $out/lib/libunwind.so $out/lib/libunwind_shared.so
-  '';
-
-  outputs = [ "out" "dev" ];
-
-  nativeBuildInputs = [ cmake ninja python3 ];
-
-  cmakeFlags = [
-    "-DLLVM_ENABLE_RUNTIMES=libunwind"
-  ] ++ lib.optional (!enableShared) "-DLIBUNWIND_ENABLE_SHARED=OFF";
-
-  meta = llvm_meta // {
-    # Details: https://github.com/llvm/llvm-project/blob/main/libunwind/docs/index.rst
-    homepage = "https://clang.llvm.org/docs/Toolchain.html#unwind-library";
-    description = "LLVM's unwinder library";
-    longDescription = ''
-      The unwind library provides a family of _Unwind_* functions implementing
-      the language-neutral stack unwinding portion of the Itanium C++ ABI (Level
-      I). It is a dependency of the C++ ABI library, and sometimes is a
-      dependency of other runtimes.
-    '';
-  };
-}
diff --git a/pkgs/development/compilers/llvm/git/lld/default.nix b/pkgs/development/compilers/llvm/git/lld/default.nix
deleted file mode 100644
index 24ff0933dd1d..000000000000
--- a/pkgs/development/compilers/llvm/git/lld/default.nix
+++ /dev/null
@@ -1,57 +0,0 @@
-{ lib, stdenv, llvm_meta
-, buildLlvmTools
-, monorepoSrc, runCommand
-, cmake
-, ninja
-, libxml2
-, libllvm
-, version
-}:
-
-stdenv.mkDerivation rec {
-  pname = "lld";
-  inherit version;
-
-  # Blank llvm dir just so relative path works
-  src = runCommand "${pname}-src-${version}" {} ''
-    mkdir -p "$out"
-    cp -r ${monorepoSrc}/cmake "$out"
-    cp -r ${monorepoSrc}/${pname} "$out"
-    mkdir -p "$out/libunwind"
-    cp -r ${monorepoSrc}/libunwind/include "$out/libunwind"
-    mkdir -p "$out/llvm"
-  '';
-
-  sourceRoot = "${src.name}/${pname}";
-
-  nativeBuildInputs = [ cmake ninja ];
-  buildInputs = [ libllvm libxml2 ];
-
-  patches = [
-    ./gnu-install-dirs.patch
-  ];
-
-  cmakeFlags = [
-    "-DLLD_INSTALL_PACKAGE_DIR=${placeholder "dev"}/lib/cmake/lld"
-  ] ++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [
-    "-DLLVM_TABLEGEN_EXE=${buildLlvmTools.llvm}/bin/llvm-tblgen"
-  ];
-
-  # Musl's default stack size is too small for lld to be able to link Firefox.
-  LDFLAGS = lib.optionalString stdenv.hostPlatform.isMusl "-Wl,-z,stack-size=2097152";
-
-  outputs = [ "out" "lib" "dev" ];
-
-  meta = llvm_meta // {
-    homepage = "https://lld.llvm.org/";
-    description = "The LLVM linker (unwrapped)";
-    longDescription = ''
-      LLD is a linker from the LLVM project that is a drop-in replacement for
-      system linkers and runs much faster than them. It also provides features
-      that are useful for toolchain developers.
-      The linker supports ELF (Unix), PE/COFF (Windows), Mach-O (macOS), and
-      WebAssembly in descending order of completeness. Internally, LLD consists
-      of several different linkers.
-    '';
-  };
-}
diff --git a/pkgs/development/compilers/llvm/git/llvm/default.nix b/pkgs/development/compilers/llvm/git/llvm/default.nix
index a9732763e9d7..8987103e22fe 100644
--- a/pkgs/development/compilers/llvm/git/llvm/default.nix
+++ b/pkgs/development/compilers/llvm/git/llvm/default.nix
@@ -214,10 +214,6 @@ stdenv.mkDerivation (rec {
     # TODO(@rrbutani): fix/follow-up
     substituteInPlace unittests/TargetParser/Host.cpp \
       --replace "getMacOSHostVersion" "DISABLED_getMacOSHostVersion"
-
-    # This test fails with a `dysmutil` crash; have not yet dug into what's
-    # going on here (TODO(@rrbutani)).
-    rm test/tools/dsymutil/ARM/obfuscated.test
   '' + ''
     # FileSystem permissions tests fail with various special bits
     substituteInPlace unittests/Support/CMakeLists.txt \
diff --git a/pkgs/development/compilers/llvm/git/openmp/default.nix b/pkgs/development/compilers/llvm/git/openmp/default.nix
deleted file mode 100644
index e1c3c2379af2..000000000000
--- a/pkgs/development/compilers/llvm/git/openmp/default.nix
+++ /dev/null
@@ -1,73 +0,0 @@
-{ lib
-, stdenv
-, llvm_meta
-, monorepoSrc
-, runCommand
-, cmake
-, ninja
-, llvm
-, targetLlvm
-, lit
-, clang-unwrapped
-, perl
-, pkg-config
-, xcbuild
-, version
-}:
-
-stdenv.mkDerivation rec {
-  pname = "openmp";
-  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 = [
-    ./fix-find-tool.patch
-    ./run-lit-directly.patch
-  ];
-
-  outputs = [ "out" "dev" ];
-
-  nativeBuildInputs = [ cmake ninja perl pkg-config lit ];
-  buildInputs = [
-    (if stdenv.buildPlatform == stdenv.hostPlatform then llvm else targetLlvm)
-  ];
-
-  nativeCheckInputs = lib.optional stdenv.hostPlatform.isDarwin xcbuild.xcrun;
-
-  # Unsup:Pass:XFail:Fail
-  # 26:267:16:8
-  doCheck = false;
-  checkTarget = "check-openmp";
-
-  preCheck = ''
-    patchShebangs ../tools/archer/tests/deflake.bash
-  '';
-
-  cmakeFlags = [
-    "-DCLANG_TOOL=${clang-unwrapped}/bin/clang"
-    "-DOPT_TOOL=${llvm}/bin/opt"
-    "-DLINK_TOOL=${llvm}/bin/llvm-link"
-  ];
-
-  meta = llvm_meta // {
-    homepage = "https://openmp.llvm.org/";
-    description = "Support for the OpenMP language";
-    longDescription = ''
-      The OpenMP subproject of LLVM contains the components required to build an
-      executable OpenMP program that are outside the compiler itself.
-      Contains the code for the runtime library against which code compiled by
-      "clang -fopenmp" must be linked before it can run and the library that
-      supports offload to target devices.
-    '';
-    # "All of the code is dual licensed under the MIT license and the UIUC
-    # License (a BSD-like license)":
-    license = with lib.licenses; [ mit ncsa ];
-  };
-}