@@ -0,0 +1,107 @@
1+From 67738db10010fd28a8e997b5c8f83ea591b88a0e Mon Sep 17 00:00:00 2001
2+From: Travis Whitaker <pi.boy.travis@gmail.com>
3+Date: Wed, 6 May 2020 04:14:47 +0000
4+Subject: [PATCH] Build a threaded stage 1 if the bootstrapping GHC supports
5+ it.
6+
7+---
8+ compiler/ghc.mk | 6 ++++++
9+ configure.ac | 15 +++++++++++++++
10+ ghc/ghc.mk | 9 ++++++++-
11+ mk/config.mk.in | 3 +++
12+ 8 files changed, 98 insertions(+), 21 deletions(-)
13+
14+diff --git a/compiler/ghc.mk b/compiler/ghc.mk
15+index 6a2dadc820..6e86b73e8d 100644
16+--- a/compiler/ghc.mk
17++++ b/compiler/ghc.mk
18+@@ -194,6 +194,12 @@ ifeq "$(GhcThreaded)" "YES"
19+ compiler_stage2_CONFIGURE_OPTS += --ghc-option=-optc-DTHREADED_RTS
20+ endif
21+
22++# If the bootstrapping GHC supplies the threaded RTS, then we can have a
23++# threaded stage 1 too.
24++ifeq "$(GhcThreadedRts)" "YES"
25++compiler_stage1_CONFIGURE_OPTS += --ghc-option=-optc-DTHREADED_RTS
26++endif
27++
28+ ifeq "$(GhcWithNativeCodeGen)" "YES"
29+ compiler_stage1_CONFIGURE_OPTS += --flags=ncg
30+ compiler_stage2_CONFIGURE_OPTS += --flags=ncg
31+diff --git a/configure.ac b/configure.ac
32+index a621814700..bac2cfde5e 100644
33+--- a/configure.ac
34++++ b/configure.ac
35+@@ -124,6 +124,9 @@ AC_ARG_VAR(CC_STAGE0, [C compiler command (bootstrap)])
36+ AC_ARG_VAR(LD_STAGE0, [Linker command (bootstrap)])
37+ AC_ARG_VAR(AR_STAGE0, [Archive command (bootstrap)])
38+
39++dnl RTS ways supplied by the bootstrapping compiler.
40++AC_ARG_VAR(RTS_WAYS_STAGE0, [RTS ways])
41++
42+ if test "$WithGhc" != ""; then
43+ FPTOOLS_GHC_VERSION([GhcVersion], [GhcMajVersion], [GhcMinVersion], [GhcPatchLevel])dnl
44+
45+@@ -151,6 +154,17 @@ if test "$WithGhc" != ""; then
46+ fi
47+ BOOTSTRAPPING_GHC_INFO_FIELD([AR_OPTS_STAGE0],[ar flags])
48+ BOOTSTRAPPING_GHC_INFO_FIELD([ArSupportsAtFile_STAGE0],[ar supports at file])
49++ BOOTSTRAPPING_GHC_INFO_FIELD([RTS_WAYS_STAGE0],[RTS ways])
50++
51++ dnl Check whether or not the bootstrapping GHC has a threaded RTS. This
52++ dnl determines whether or not we can have a threaded stage 1.
53++ dnl See Note [Linking ghc-bin against threaded stage0 RTS] in
54++ dnl hadrian/src/Settings/Packages.hs for details.
55++ if echo ${RTS_WAYS_STAGE0} | grep '.*thr.*' 2>&1 >/dev/null; then
56++ AC_SUBST(GhcThreadedRts, YES)
57++ else
58++ AC_SUBST(GhcThreadedRts, NO)
59++ fi
60+ fi
61+
62+ dnl ** Must have GHC to build GHC
63+@@ -1454,6 +1468,7 @@ Configure completed successfully.
64+ echo "\
65+ Bootstrapping using : $WithGhc
66+ which is version : $GhcVersion
67++ with threaded RTS? : $GhcThreadedRts
68+ "
69+
70+ if test "x$CcLlvmBackend" = "xYES"; then
71+diff --git a/ghc/ghc.mk b/ghc/ghc.mk
72+index 8c112a054f..5512d50710 100644
73+--- a/ghc/ghc.mk
74++++ b/ghc/ghc.mk
75+@@ -66,8 +66,15 @@ else
76+ ghc_stage2_CONFIGURE_OPTS += -f-threaded
77+ ghc_stage3_CONFIGURE_OPTS += -f-threaded
78+ endif
79+-# Stage-0 compiler isn't guaranteed to have a threaded RTS.
80++
81++# If stage 0 supplies a threaded RTS, we can use it for stage 1.
82++# See Note [Linking ghc-bin against threaded stage0 RTS] in
83++# hadrian/src/Settings/Packages.hs for details.
84++ifeq "$(GhcThreadedRts)" "YES"
85++ghc_stage1_MORE_HC_OPTS += -threaded
86++else
87+ ghc_stage1_CONFIGURE_OPTS += -f-threaded
88++endif
89+
90+ ifeq "$(GhcProfiled)" "YES"
91+ ghc_stage2_PROGRAM_WAY = p
92+diff --git a/mk/config.mk.in b/mk/config.mk.in
93+index 791dc5acc0..250d41ebe6 100644
94+--- a/mk/config.mk.in
95++++ b/mk/config.mk.in
96+@@ -199,6 +199,9 @@ endif
97+ # `GhcUnregisterised` mode doesn't allow that.
98+ GhcWithSMP := $(strip $(if $(filter YESNO, $(ArchSupportsSMP)$(GhcUnregisterised)),YES,NO))
99+
100++# Whether or not the bootstrapping GHC supplies a threaded RTS.
101++GhcThreadedRts = @GhcThreadedRts@
102++
103+ # Whether to include GHCi in the compiler. Depends on whether the RTS linker
104+ # has support for this OS/ARCH combination.
105+
106+--
107+2.25.0