Skip to content

Commit aaf0611

Browse files
Try #1450:
2 parents 45a9357 + f2fd8ba commit aaf0611

File tree

9 files changed

+282
-7
lines changed

9 files changed

+282
-7
lines changed

ci.nix

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
|| (system == "x86_64-darwin" && __elem compiler-nix-name ["ghc8107"]))) {
6464
inherit (lib.systems.examples) ghcjs;
6565
} // lib.optionalAttrs (system == "x86_64-linux" &&
66-
nixpkgsName == "unstable" && (__elem compiler-nix-name ["ghc8107"])) {
66+
nixpkgsName == "unstable" && (__elem compiler-nix-name ["ghc8107" "ghc902" "ghc922"])) {
6767
# Windows cross compilation is currently broken on macOS
6868
inherit (lib.systems.examples) mingwW64;
6969
} // lib.optionalAttrs (system == "x86_64-linux" && nixpkgsName == "unstable" && compiler-nix-name == "ghc8107") {

compiler/ghc/default.nix

+19-2
Original file line numberDiff line numberDiff line change
@@ -384,13 +384,30 @@ stdenv.mkDerivation (rec {
384384
dontStrip = true;
385385
dontPatchELF = true;
386386
noAuditTmpdir = true;
387-
} // lib.optionalAttrs stdenv.buildPlatform.isDarwin {
387+
} // lib.optionalAttrs (stdenv.buildPlatform.isDarwin || stdenv.targetPlatform.isWindows) {
388388
# ghc install on macOS wants to run `xattr -r -c`
389389
# The macOS version fails because it wants python 2.
390390
# The nix version of xattr does not support those args.
391391
# Luckily setting the path to something that does not exist will skip the step.
392-
preBuild = ''
392+
preBuild = lib.optionalString stdenv.buildPlatform.isDarwin ''
393393
export XATTR=$(mktemp -d)/nothing
394+
''
395+
# We need to point at a stand in `windows.h` header file so that the RTS headers can
396+
# work on the hostPlatform. We also need to work around case sensitve file system issues.
397+
+ lib.optionalString stdenv.targetPlatform.isWindows ''
398+
export NIX_CFLAGS_COMPILE_${
399+
# We want this only to apply to the non windows hostPlatform (the
400+
# windows gcc cross compiler has a full `windows.h`).
401+
# This matches the way `suffixSalt` is calculated in nixpkgs.
402+
# See https://github.com/NixOS/nixpkgs/blob/8411006d6bcd7f6e6a8a1a80ce8fcdccdd16c6ab/pkgs/build-support/cc-wrapper/default.nix#L58
403+
lib.replaceStrings ["-" "."] ["_" "_"] stdenv.hostPlatform.config
404+
}+=" -I${../windows/include}"
405+
if [[ -f libraries/base/include/winio_structs.h ]]; then
406+
substituteInPlace libraries/base/include/winio_structs.h --replace Windows.h windows.h
407+
fi
408+
if [[ -f rts/win32/ThrIOManager.c ]]; then
409+
substituteInPlace rts/win32/ThrIOManager.c --replace rts\\OSThreads.h rts/OSThreads.h
410+
fi
394411
'';
395412
});
396413
in self

compiler/windows/include/synchapi.h

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#include <windows.h>

compiler/windows/include/windows.h

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Just enoough windows.h stuff to make rts headers usable when building GHC cross compiler.
2+
// See compiler/ghc/default.nix for where this is used.
3+
#ifndef _WINDOWS_
4+
#define _WINDOWS_
5+
6+
#define __stdcall
7+
8+
typedef unsigned long DWORD;
9+
typedef void * PVOID;
10+
11+
typedef struct _RTL_CONDITION_VARIABLE { PVOID Ptr; } RTL_CONDITION_VARIABLE;
12+
typedef RTL_CONDITION_VARIABLE CONDITION_VARIABLE;
13+
14+
typedef struct _RTL_SRWLOCK { PVOID Ptr; } RTL_SRWLOCK;
15+
typedef RTL_SRWLOCK SRWLOCK;
16+
17+
#endif
18+

overlays/bootstrap.nix

+4-1
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ in {
154154
++ until "9.2" ./patches/ghc/ghc-8.4.3-Cabal2201-no-hackage-tests.patch # ?
155155
++ until "8.10" ./patches/ghc/MR948--32bit-cross-th.patch # https://gitlab.haskell.org/ghc/ghc/merge_requests/948 -- open
156156
++ fromUntil "8.8" "9.2" ./patches/ghc/cabal-host.patch # https://github.com/haskell/cabal/issues/5887
157+
++ fromUntil "9.2" "9.3" ./patches/ghc/ghc-9.2-cabal-host.patch # https://github.com/haskell/cabal/issues/5887
157158
++ fromUntil "8.6.4" "8.8" ./patches/ghc/ghc-8.6.4-prim-no-arm-atomics.patch
158159
++ fromUntil "8.6.4" "8.8" ./patches/ghc/global-offset-table.patch
159160
++ fromUntil "8.6.4" "8.8" ./patches/ghc/global-offset-table-2.patch
@@ -194,6 +195,7 @@ in {
194195
++ fromUntil "8.10.3" "8.10.5" ./patches/ghc/ghc-8.10.3-ubxt.patch
195196
++ fromUntil "8.10.5" "8.11" ./patches/ghc/ghc-8.10.5-ubxt.patch
196197
++ fromUntil "8.6.4" "9.2" ./patches/ghc/Cabal-3886.patch
198+
++ fromUntil "9.2" "9.3" ./patches/ghc/ghc-9.2-Cabal-3886.patch
197199

198200
++ fromUntil "8.10.3" "8.10.5" ./patches/ghc/ghc-8.10.3-rts-make-markLiveObject-thread-safe.patch
199201
++ final.lib.optionals final.targetPlatform.isWindows
@@ -210,7 +212,8 @@ in {
210212
++ fromUntil "8.10" "9.3" ./patches/ghc/MR6654-nonmoving-maxmem.patch # https://gitlab.haskell.org/ghc/ghc/-/merge_requests/6654
211213
++ fromUntil "8.10" "8.10.8" ./patches/ghc/MR6617-nonmoving-mvar.patch # https://gitlab.haskell.org/ghc/ghc/-/merge_requests/6617
212214
++ fromUntil "8.10" "8.10.8" ./patches/ghc/MR6595-nonmoving-mutvar.patch # https://gitlab.haskell.org/ghc/ghc/-/merge_requests/6595
213-
++ fromUntil "8.10" "9.2" ./patches/ghc/ghc-8.10-global-unique-counters-in-rts.patch # backport of https://gitlab.haskell.org/ghc/ghc/-/commit/9a28680d2e23e7b25dd7254a439aea31dfae32d5
215+
++ fromUntil "8.10" "9.2" ./patches/ghc/ghc-8.10-global-unique-counters-in-rts.patch # backport of https://gitlab.haskell.org/ghc/ghc/-/commit/9a28680d2e23e7b25dd7254a439aea31dfae32d5
216+
++ fromUntil "9.2" "9.3" ./patches/ghc/ghc-9.2-global-unique-counters-in-rts.patch # backport of https://gitlab.haskell.org/ghc/ghc/-/commit/9a28680d2e23e7b25dd7254a439aea31dfae32d5
214217
++ fromUntil "8.10" "8.10.8" ./patches/ghc/issue-18708.patch # https://gitlab.haskell.org/ghc/ghc/-/merge_requests/6554
215218
# the following is a partial reversal of https://gitlab.haskell.org/ghc/ghc/-/merge_requests/4391, to address haskell.nix#1227
216219
++ final.lib.optional (versionAtLeast "8.10" && versionLessThan "9.0" && final.targetPlatform.isAarch64) ./patches/ghc/mmap-next.patch
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
Submodule libraries/Cabal contains modified content
2+
diff --git a/libraries/Cabal/Cabal/src/Distribution/Simple/Program/Ld.hs b/libraries/Cabal/Cabal/src/Distribution/Simple/Program/Ld.hs
3+
index 68b5a391a..f4979bf5f 100644
4+
--- a/libraries/Cabal/Cabal/src/Distribution/Simple/Program/Ld.hs
5+
+++ b/libraries/Cabal/Cabal/src/Distribution/Simple/Program/Ld.hs
6+
@@ -21,7 +21,7 @@ import Distribution.Compat.Prelude
7+
import Distribution.Simple.Compiler (arResponseFilesSupported)
8+
import Distribution.Simple.LocalBuildInfo (LocalBuildInfo(..))
9+
import Distribution.Simple.Program.ResponseFile
10+
- ( withResponseFile )
11+
+ ( withResponseFile, withLinkerScript )
12+
import Distribution.Simple.Program.Run
13+
( ProgramInvocation, programInvocation, multiStageProgramInvocation
14+
, runProgramInvocation )
15+
@@ -31,6 +31,8 @@ import Distribution.Simple.Setup
16+
( fromFlagOrDefault, configUseResponseFiles )
17+
import Distribution.Simple.Utils
18+
( defaultTempFileOptions )
19+
+import Distribution.System
20+
+ ( OS(..), Platform(..) )
21+
import Distribution.Verbosity
22+
( Verbosity )
23+
24+
@@ -50,7 +52,71 @@ combineObjectFiles verbosity lbi ld target files = do
25+
-- have a slight problem. What we have to do is link files in batches into
26+
-- a temp object file and then include that one in the next batch.
27+
28+
- let simpleArgs = ["-r", "-o", target]
29+
+ let linkerScriptELF = unlines $
30+
+ [ "/* Linker script to undo -split-sections and merge all sections together when "
31+
+ , " * linking relocatable object files for GHCi. "
32+
+ , " * ld -r normally retains the individual sections, which is what you would want "
33+
+ , " * if the intention is to eventually link into a binary with --gc-sections, but "
34+
+ , " * it doesn't have a flag for directly doing what we want. */ "
35+
+ , "SECTIONS "
36+
+ , "{ "
37+
+ , " .text : { "
38+
+ , " *(.text*) "
39+
+ , " } "
40+
+ , " .rodata.cst16 : { "
41+
+ , " *(.rodata.cst16*) "
42+
+ , " } "
43+
+ , " .rodata : { "
44+
+ , " *(.rodata*) "
45+
+ , " } "
46+
+ , " .data.rel.ro : { "
47+
+ , " *(.data.rel.ro*) "
48+
+ , " } "
49+
+ , " .data : { "
50+
+ , " *(.data*) "
51+
+ , " } "
52+
+ , " .bss : { "
53+
+ , " *(.bss*) "
54+
+ , " } "
55+
+ , "} "
56+
+ ]
57+
+
58+
+ linkerScriptPE = unlines $
59+
+ [ "/* Linker script to undo -split-sections and merge all sections together when "
60+
+ , " * linking relocatable object files for GHCi. "
61+
+ , " * ld -r normally retains the individual sections, which is what you would want "
62+
+ , " * if the intention is to eventually link into a binary with --gc-sections, but "
63+
+ , " * it doesn't have a flag for directly doing what we want. */ "
64+
+ , "SECTIONS "
65+
+ , "{ "
66+
+ , " .text : { "
67+
+ , " *(.text$*) "
68+
+ , " } "
69+
+ , " .rdata : { "
70+
+ , " *(.rdata$*) "
71+
+ , " } "
72+
+ , " .data : { "
73+
+ , " *(.data$*) "
74+
+ , " } "
75+
+ , " .pdata : { "
76+
+ , " *(.pdata$*) "
77+
+ , " } "
78+
+ , " .xdata : { "
79+
+ , " *(.xdata$*) "
80+
+ , " } "
81+
+ , " .bss : { "
82+
+ , " *(.bss$*) "
83+
+ , " } "
84+
+ , "} "
85+
+ ]
86+
+ linkerScript = case hostOS of
87+
+ Windows -> linkerScriptPE
88+
+ _ -> linkerScriptELF
89+
+ linkerScriptArgs = case hostOS of
90+
+ Windows -> []
91+
+ _ -> ["-T"]
92+
+
93+
+ simpleArgs = ["-r", "-o", target]
94+
95+
initialArgs = ["-r", "-o", target]
96+
middleArgs = ["-r", "-o", target, tmpfile]
97+
@@ -63,9 +129,9 @@ combineObjectFiles verbosity lbi ld target files = do
98+
99+
targetDir = takeDirectory target
100+
101+
- invokeWithResponesFile :: FilePath -> ProgramInvocation
102+
- invokeWithResponesFile atFile =
103+
- programInvocation ld $ simpleArgs ++ ['@' : atFile]
104+
+ invokeWithLinkerScriptAndResponesFile :: FilePath -> FilePath -> ProgramInvocation
105+
+ invokeWithLinkerScriptAndResponesFile script atFile =
106+
+ programInvocation ld $ simpleArgs ++ linkerScriptArgs ++ [ script, '@' : atFile]
107+
108+
oldVersionManualOverride =
109+
fromFlagOrDefault False $ configUseResponseFiles $ configFlags lbi
110+
@@ -78,10 +144,13 @@ combineObjectFiles verbosity lbi ld target files = do
111+
then
112+
run $ multiStageProgramInvocation simple (initial, middle, final) files
113+
else
114+
- withResponseFile verbosity defaultTempFileOptions targetDir "ld.rsp" Nothing files $
115+
- \path -> runProgramInvocation verbosity $ invokeWithResponesFile path
116+
+ withLinkerScript verbosity defaultTempFileOptions targetDir "merge_sections.ld" Nothing linkerScript $
117+
+ \scriptPath -> withResponseFile verbosity defaultTempFileOptions targetDir "ld.rsp" Nothing files $
118+
+ \path -> runProgramInvocation verbosity $ invokeWithLinkerScriptAndResponesFile scriptPath path
119+
120+
where
121+
+ Platform _hostArch hostOS = hostPlatform lbi
122+
+
123+
tmpfile = target <.> "tmp" -- perhaps should use a proper temp file
124+
125+
run :: [ProgramInvocation] -> IO ()
126+
diff --git a/libraries/Cabal/Cabal/src/Distribution/Simple/Program/ResponseFile.hs b/libraries/Cabal/Cabal/src/Distribution/Simple/Program/ResponseFile.hs
127+
index e5ef41412..3b038e6b1 100644
128+
--- a/libraries/Cabal/Cabal/src/Distribution/Simple/Program/ResponseFile.hs
129+
+++ b/libraries/Cabal/Cabal/src/Distribution/Simple/Program/ResponseFile.hs
130+
@@ -10,7 +10,7 @@
131+
-- Created : 23 July 2017
132+
----------------------------------------------------------------------------
133+
134+
-module Distribution.Simple.Program.ResponseFile (withResponseFile) where
135+
+module Distribution.Simple.Program.ResponseFile (withResponseFile, withLinkerScript) where
136+
137+
import Prelude ()
138+
import System.IO (TextEncoding, hSetEncoding, hPutStr, hClose)
139+
@@ -39,6 +39,25 @@ withResponseFile verbosity tmpFileOpts workDir fileNameTemplate encoding argumen
140+
debug verbosity $ ">>> " ++ responseFileName
141+
f responseFileName
142+
143+
+withLinkerScript
144+
+ :: Verbosity
145+
+ -> TempFileOptions
146+
+ -> FilePath
147+
+ -> FilePath
148+
+ -> Maybe TextEncoding
149+
+ -> String
150+
+ -> (FilePath -> IO a)
151+
+ -> IO a
152+
+withLinkerScript verbosity tmpFileOpts workDir fileNameTemplate encoding linkerScript f =
153+
+ withTempFileEx tmpFileOpts workDir fileNameTemplate $ \linkerScriptName hf -> do
154+
+ traverse_ (hSetEncoding hf) encoding
155+
+ hPutStr hf linkerScript
156+
+ hClose hf
157+
+ debug verbosity $ linkerScriptName ++ " contents: <<<"
158+
+ debug verbosity linkerScript
159+
+ debug verbosity $ ">>> " ++ linkerScriptName
160+
+ f linkerScriptName
161+
+
162+
-- Support a gcc-like response file syntax. Each separate
163+
-- argument and its possible parameter(s), will be separated in the
164+
-- response file by an actual newline; all other whitespace,
165+
@@ -56,5 +75,3 @@ escapeResponseFileArg = reverse . foldl' escape []
166+
'"' -> c:'\\':cs
167+
_ | isSpace c -> c:'\\':cs
168+
| otherwise -> c:cs
169+
-
170+
-
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
diff --git a/libraries/Cabal/Cabal/src/Distribution/Simple.hs b/libraries/Cabal/Cabal/src/Distribution/Simple.hs
2+
index e632acc88..1a687bb2e 100644
3+
--- a/libraries/Cabal/Cabal/src/Distribution/Simple.hs
4+
+++ b/libraries/Cabal/Cabal/src/Distribution/Simple.hs
5+
@@ -755,7 +755,7 @@ runConfigureScript verbosity backwardsCompatHack flags lbi = do
6+
[("PATH", Just pathEnv) | not (null extraPath)]
7+
hp = hostPlatform lbi
8+
maybeHostFlag = if hp == buildPlatform then [] else ["--host=" ++ show (pretty hp)]
9+
- args' = configureFile':args ++ ["CC=" ++ ccProgShort] ++ maybeHostFlag
10+
+ args' = configureFile':maybeHostFlag ++ args ++ ["CC=" ++ ccProgShort]
11+
shProg = simpleProgram "sh"
12+
progDb = modifyProgramSearchPath
13+
(\p -> map ProgramSearchPathDir extraPath ++ p) emptyProgramDb
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
diff --git a/compiler/cbits/genSym.c b/compiler/cbits/genSym.c
2+
index 8a47d77f27..eed2b4f142 100644
3+
--- a/compiler/cbits/genSym.c
4+
+++ b/compiler/cbits/genSym.c
5+
@@ -1,9 +1,15 @@
6+
#include <Rts.h>
7+
#include <assert.h>
8+
#include "Unique.h"
9+
+#include "ghcversion.h"
10+
11+
+// These global variables have been moved into the RTS. It allows them to be
12+
+// shared with plugins even if two different instances of the GHC library are
13+
+// loaded at the same time (#19940)
14+
+#if !MIN_VERSION_GLASGOW_HASKELL(9,3,0,0)
15+
HsInt ghc_unique_counter = 0;
16+
HsInt ghc_unique_inc = 1;
17+
+#endif
18+
19+
#define UNIQUE_BITS (sizeof (HsInt) * 8 - UNIQUE_TAG_BITS)
20+
#define UNIQUE_MASK ((1ULL << UNIQUE_BITS) - 1)
21+
diff --git a/includes/rts/Globals.h b/includes/rts/Globals.h
22+
index 8d8df48b21..bd3aa637db 100644
23+
--- a/includes/rts/Globals.h
24+
+++ b/includes/rts/Globals.h
25+
@@ -32,3 +32,5 @@ mkStoreAccessorPrototype(LibHSghcFastStringTable)
26+
mkStoreAccessorPrototype(LibHSghcGlobalHasPprDebug)
27+
mkStoreAccessorPrototype(LibHSghcGlobalHasNoDebugOutput)
28+
mkStoreAccessorPrototype(LibHSghcGlobalHasNoStateHack)
29+
+extern HsInt ghc_unique_counter;
30+
+extern HsInt ghc_unique_inc;
31+
diff --git a/rts/Globals.c b/rts/Globals.c
32+
index 5569ee7910..848581e4d2 100644
33+
--- a/rts/Globals.c
34+
+++ b/rts/Globals.c
35+
@@ -107,3 +107,6 @@ mkStoreAccessor(LibHSghcFastStringTable)
36+
mkStoreAccessor(LibHSghcGlobalHasPprDebug)
37+
mkStoreAccessor(LibHSghcGlobalHasNoDebugOutput)
38+
mkStoreAccessor(LibHSghcGlobalHasNoStateHack)
39+
+
40+
+HsInt ghc_unique_counter = 0;
41+
+HsInt ghc_unique_inc = 1;
42+
diff --git a/rts/RtsSymbols.c b/rts/RtsSymbols.c
43+
index 987755651d..5a6ec21152 100644
44+
--- a/rts/RtsSymbols.c
45+
+++ b/rts/RtsSymbols.c
46+
@@ -679,6 +679,8 @@ extern char **environ;
47+
SymI_HasProto(getOrSetLibHSghcGlobalHasPprDebug) \
48+
SymI_HasProto(getOrSetLibHSghcGlobalHasNoDebugOutput) \
49+
SymI_HasProto(getOrSetLibHSghcGlobalHasNoStateHack) \
50+
+ SymI_HasProto(ghc_unique_counter) \
51+
+ SymI_HasProto(ghc_unique_inc) \
52+
SymI_HasProto(genericRaise) \
53+
SymI_HasProto(getProgArgv) \
54+
SymI_HasProto(getFullProgArgv) \

0 commit comments

Comments
 (0)