Skip to content

Building threaded stage1 fails if stage0 is unregisterized

Summary

In 67738db1 a threaded stage1 is build, if stage0 supports threaded RTS ways. In case stage0 is unregisterized, then the following error shows up:

In file included from includes/Stg.h:318,

                 from /tmp/ghc3147608_0/ghc_3.hc:3:0: error: 

includes/stg/Regs.h:442:2: error:
     error: #error BaseReg must be in a register for THREADED_RTS
      442 | #error BaseReg must be in a register for THREADED_RTS
          |  ^~~~~
    |
442 | #error BaseReg must be in a register for THREADED_RTS
    |  ^
`gcc' failed in phase `C Compiler'. (Exit code: 1)

This results from

#if defined(THREADED_RTS) && !defined(NOSMP)
#error BaseReg must be in a register for THREADED_RTS
#endif

In my case the stage0 compiler has the following properties:

$ ghc --info
[...]
 ,("Unregisterised","YES")
[...]
 ,("Support SMP","NO")
 ,("RTS ways","l debug thr thr_debug thr_l thr_p dyn debug_dyn thr_dyn thr_debug_dyn l_dyn thr_l_dyn thr_debug_p debug_p")
[...]

A quick and dirty fix for me is:

diff --git a/configure.ac b/configure.ac
index bac2cfde..eaa3c8e2 100644
--- a/configure.ac
+++ b/configure.ac
@@ -154,13 +154,14 @@ if test "$WithGhc" != ""; then
   fi
   BOOTSTRAPPING_GHC_INFO_FIELD([AR_OPTS_STAGE0],[ar flags])
   BOOTSTRAPPING_GHC_INFO_FIELD([ArSupportsAtFile_STAGE0],[ar supports at file])
+  BOOTSTRAPPING_GHC_INFO_FIELD([SUPPORT_SMP_STAGE0],[Support SMP])
   BOOTSTRAPPING_GHC_INFO_FIELD([RTS_WAYS_STAGE0],[RTS ways])
 
   dnl Check whether or not the bootstrapping GHC has a threaded RTS. This
   dnl determines whether or not we can have a threaded stage 1.
   dnl See Note [Linking ghc-bin against threaded stage0 RTS] in
   dnl hadrian/src/Settings/Packages.hs for details.
-  if echo ${RTS_WAYS_STAGE0} | grep '.*thr.*' 2>&1 >/dev/null; then
+  if test ${SUPPORT_SMP_STAGE0} == "YES" && echo ${RTS_WAYS_STAGE0} | grep '.*thr.*' 2>&1 >/dev/null; then
       AC_SUBST(GhcThreadedRts, YES)
   else
       AC_SUBST(GhcThreadedRts, NO)

I'm not sure what combination of {unregisterized,SMP,threaded-RTS-ways} we actually require. To me it looks like that unregisterized implies SMP=NO but leaves threaded-RTS-ways open. So my quick and dirty fix might be enough? On the other hand I'm wondering why threaded ways are build in the first place for an unregisterized GHC which even has SMP=NO. Maybe a proper fix would be to not build threaded ways in this case? Thoughts?

Environment

  • GHC version used: 8.10.1
  • Operating System: Fedora 31
  • System Architecture: s390x
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information