summaryrefslogtreecommitdiff
path: root/env/nixpkgs-patches/539430.diff
blob: 9c4ec0798204d780a5afd0ee08b20a62fd2c0a47 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
diff --git a/pkgs/development/compilers/llvm/common/compiler-rt/default.nix b/pkgs/development/compilers/llvm/common/compiler-rt/default.nix
index 567462e3eba68..da799c93d08e0 100644
--- a/pkgs/development/compilers/llvm/common/compiler-rt/default.nix
+++ b/pkgs/development/compilers/llvm/common/compiler-rt/default.nix
@@ -36,7 +36,8 @@
   # implementation of the routines instead of the implementation
   # using ad-hoc mutexes (which doesn't depend on libc at all).
   # Use of pthreads helps code play better with sanitizers.
-  withAtomicsPthread ? lib.versionAtLeast release_version "19" && stdenv.cc.libc != null,
+  withAtomicsPthread ?
+    lib.versionAtLeast release_version "19" && stdenv.cc.libc != null && !stdenv.hostPlatform.isMinGW,
 
   # In recent releases, the compiler-rt build seems to produce
   # many `libclang_rt*` libraries, but not a single unified
@@ -214,7 +215,7 @@ stdenv.mkDerivation (finalAttrs: {
       # Fixes https://github.com/NixOS/nixpkgs/issues/393603
       (lib.cmakeBool "COMPILER_RT_DISABLE_AARCH64_FMV" true)
   ++ lib.optionals withAtomics [
-    (lib.cmakeBool "COMPILER_RT_EXCLUDE_ATOMIC_BUILTIN" (!withAtomicsLib))
+    (lib.cmakeBool "COMPILER_RT_EXCLUDE_ATOMIC_BUILTIN" withAtomicsLib)
     (lib.cmakeBool "COMPILER_RT_BUILD_STANDALONE_LIBATOMIC" withAtomicsLib)
     (lib.cmakeBool "COMPILER_RT_LIBATOMIC_USE_PTHREAD" withAtomicsPthread)
   ]
@@ -291,11 +292,21 @@ stdenv.mkDerivation (finalAttrs: {
     + lib.optionalString forceLinkCompilerRt ''
       ln -s $out/lib/*/libclang_rt.builtins-*.a $out/lib/libcompiler_rt.a
     ''
-    + lib.optionalString (withAtomics && withAtomicsLib) ''
-      ln -s $out/lib/*/libclang_rt.atomic-*.so $out/lib/libatomic.so
-      # create a link with the original soname as well, so it's found at runtime
-      ln -s $out/lib/*/libclang_rt.atomic-*.so $out/lib/
-    '';
+    + lib.optionalString (withAtomics && withAtomicsLib) (
+      let
+        isMinGW = stdenv.hostPlatform.isMinGW;
+        sharedLibrary = stdenv.hostPlatform.extensions.sharedLibrary;
+        linkLibrarySuffix = lib.optionalString isMinGW ".a";
+        runtimeDirectory = if isMinGW then "$out/bin" else "$out/lib";
+        atomicLibrary = "libclang_rt.atomic" + lib.optionalString isMinGW "_dynamic" + "-*${sharedLibrary}";
+      in
+      ''
+        mkdir -p ${runtimeDirectory}
+        ln -s $out/lib/*/${atomicLibrary}${linkLibrarySuffix} $out/lib/libatomic${sharedLibrary}${linkLibrarySuffix}
+        # Link the original runtime name where the loader searches for shared libraries.
+        ln -s $out/lib/*/${atomicLibrary} ${runtimeDirectory}/
+      ''
+    );
 
   meta = llvm_meta // {
     homepage = "https://compiler-rt.llvm.org/";
diff --git a/pkgs/development/compilers/llvm/common/default.nix b/pkgs/development/compilers/llvm/common/default.nix
index af2e39dced099..9afc972ce7c31 100644
--- a/pkgs/development/compilers/llvm/common/default.nix
+++ b/pkgs/development/compilers/llvm/common/default.nix
@@ -308,9 +308,11 @@ makeScopeWithSplicing' {
           && stdenv.targetPlatform.useLLVM or false
         ) "-lunwind"
         ++ lib.optional stdenv.targetPlatform.isWasm "-fno-exceptions";
-        nixSupport.cc-ldflags = lib.optionals (
-          !stdenv.targetPlatform.isWasm && !stdenv.targetPlatform.isFreeBSD
-        ) [ "-L${targetLlvmPackages.libunwind}/lib" ];
+        nixSupport.cc-ldflags =
+          lib.optionals (!stdenv.targetPlatform.isWasm && !stdenv.targetPlatform.isFreeBSD) [
+            "-L${targetLlvmPackages.libunwind}/lib"
+          ]
+          ++ lib.optional stdenv.targetPlatform.isMinGW "-L${targetLlvmPackages.compiler-rt}/lib";
       };
 
       clangWithLibcAndBasicRtAndLibcxx = wrapCCWith rec {
@@ -424,6 +426,11 @@ makeScopeWithSplicing' {
 
       compiler-rt-no-libc = callPackage ./compiler-rt {
         doFakeLibgcc = stdenv.hostPlatform.useLLVM or false;
+        # This runtime is used to bootstrap the libc-capable toolchain.  Keep
+        # atomics in builtins.a until that toolchain can link the shared atomic
+        # runtime against libc (and pthreads, when enabled).
+        withAtomicsLib = false;
+        withAtomicsPthread = false;
         stdenv =
           # Darwin needs to use a bootstrap stdenv to avoid an infinite recursion when cross-compiling.
           if stdenv.hostPlatform.isDarwin then