[Git][ghc/ghc][wip/andreask/lsp-crash] Enable -fkeep-cafs for both static and dynamic builds.

Andreas Klebinger (@AndreasK) gitlab at gitlab.haskell.org
Thu Dec 15 14:44:32 UTC 2022



Andreas Klebinger pushed to branch wip/andreask/lsp-crash at Glasgow Haskell Compiler / GHC


Commits:
bf502f34 by Andreas Klebinger at 2022-12-15T15:42:57+01:00
Enable -fkeep-cafs for both static and dynamic builds.

We used to use keepCAFsForGHCi.c to force -fkeep-cafs by using a
__attribute__((constructor)) function.

Besides being an odd choice this broke for static builds where
the constructor function was never called. Yuk.

So instead we now just tell cabal to compile the relevant files with
-fkeep-cafs.

- - - - -


6 changed files:

- − compiler/cbits/keepCAFsForGHCi.c
- compiler/ghc.cabal.in
- ghc/ghc-bin.cabal.in
- hadrian/src/Packages.hs
- − utils/iserv/cbits/iservmain.c
- utils/iserv/iserv.cabal.in


Changes:

=====================================
compiler/cbits/keepCAFsForGHCi.c deleted
=====================================
@@ -1,15 +0,0 @@
-#include <Rts.h>
-
-// This file is only included in the dynamic library.
-// It contains an __attribute__((constructor)) function (run prior to main())
-// which sets the keepCAFs flag in the RTS, before any Haskell code is run.
-// This is required so that GHCi can use dynamic libraries instead of HSxyz.o
-// files.
-
-static void keepCAFsForGHCi(void) __attribute__((constructor));
-
-static void keepCAFsForGHCi(void)
-{
-    keepCAFs = 1;
-}
-


=====================================
compiler/ghc.cabal.in
=====================================
@@ -150,7 +150,6 @@ Library
     c-sources:
         cbits/cutils.c
         cbits/genSym.c
-        cbits/keepCAFsForGHCi.c
 
     hs-source-dirs:
         .


=====================================
ghc/ghc-bin.cabal.in
=====================================
@@ -52,6 +52,7 @@ Executable ghc
                  -Wnoncanonical-monoid-instances
                  -rtsopts=all
                  "-with-rtsopts=-K512M -H -I5 -T"
+                 -fkeep-cafs
 
     if flag(internal-interpreter)
         -- NB: this is never built by the bootstrapping GHC+libraries


=====================================
hadrian/src/Packages.hs
=====================================
@@ -210,7 +210,7 @@ timeoutPath = "testsuite/timeout/install-inplace/bin/timeout" <.> exe
 -- TODO: Can we extract this information from Cabal files?
 -- | Some program packages should not be linked with Haskell main function.
 nonHsMainPackage :: Package -> Bool
-nonHsMainPackage = (`elem` [hp2ps, iserv, touchy, unlit, ghciWrapper])
+nonHsMainPackage = (`elem` [hp2ps, touchy, unlit, ghciWrapper])
 
 -- TODO: Combine this with 'programName'.
 -- | Path to the @autogen@ directory generated by 'buildAutogenFiles'.


=====================================
utils/iserv/cbits/iservmain.c deleted
=====================================
@@ -1,29 +0,0 @@
-#include <ghcversion.h>
-#if MIN_VERSION_GLASGOW_HASKELL(9,3,0,0)
-#  include <rts/PosixSource.h>
-#else // PosixSource.h not yet exposed, hacky inline for now.
-#  include <ghcplatform.h>
-#  if defined(solaris2_HOST_OS)
-#  define _POSIX_C_SOURCE 200112L
-#  define _XOPEN_SOURCE   600
-#  else
-#  define _POSIX_C_SOURCE 200809L
-#  define _XOPEN_SOURCE   700
-#  endif
-#endif
-#include <Rts.h>
-
-#include <HsFFI.h>
-
-int main (int argc, char *argv[])
-{
-    RtsConfig conf = defaultRtsConfig;
-
-    // We never know what symbols GHC will look up in the future, so
-    // we must retain CAFs for running interpreted code.
-    conf.keep_cafs = 1;
-
-    conf.rts_opts_enabled = RtsOptsAll;
-    extern StgClosure ZCMain_main_closure;
-    hs_main(argc, argv, &ZCMain_main_closure, conf);
-}


=====================================
utils/iserv/iserv.cabal.in
=====================================
@@ -28,9 +28,8 @@ cabal-version: >=1.10
 
 Executable iserv
     Default-Language: Haskell2010
-    ghc-options: -no-hs-main
+    ghc-options: -fkeep-cafs -rtsopts
     Main-Is: Main.hs
-    C-Sources: cbits/iservmain.c
     Hs-Source-Dirs: src
     include-dirs: .
     Build-Depends: array      >= 0.5 && < 0.6,



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/bf502f344693d979ac726fc7da08f0fe4f7c76b9

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/bf502f344693d979ac726fc7da08f0fe4f7c76b9
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20221215/b719613c/attachment-0001.html>


More information about the ghc-commits mailing list