[Git][ghc/ghc][wip/23944] driver: Only run a dynamic-too pipeline if object files are going to be generated

Zubin (@wz1000) gitlab at gitlab.haskell.org
Wed Dec 6 11:47:27 UTC 2023



Zubin pushed to branch wip/23944 at Glasgow Haskell Compiler / GHC


Commits:
2b69d69e by Zubin Duggal at 2023-12-06T17:17:20+05:30
driver: Only run a dynamic-too pipeline if object files are going to be generated

Otherwise we run into a panic in hscMaybeWriteIface: "Unexpected DT_Dyn state
when writing simple interface" when dynamic-too is enabled

We could remove the panic and just write the interface even if the state is `DT_Dyn`,
but it seems pointless to run the pipeline twice when `hscMaybeWriteIface` is already
designed to write both `hi` and `dyn_hi` files if dynamic-too is enabled.

Fixes #23944.

- - - - -


1 changed file:

- compiler/GHC/Driver/Pipeline.hs


Changes:

=====================================
compiler/GHC/Driver/Pipeline.hs
=====================================
@@ -788,7 +788,15 @@ hscBackendPipeline pipe_env hsc_env mod_sum result =
   if backendGeneratesCode (backend (hsc_dflags hsc_env)) then
     do
       res <- hscGenBackendPipeline pipe_env hsc_env mod_sum result
-      when (gopt Opt_BuildDynamicToo (hsc_dflags hsc_env)) $ do
+      -- Only run dynamic-too if the backend generates object files
+      -- See Note [Writing interface files]
+      -- If we are writing a simple interface (not . backendWritesFiles), then
+      -- hscMaybeWriteIface in the regular pipeline will write both the hi and
+      -- dyn_hi files. This way we can avoid running the pipeline twice and
+      -- generating a duplicate linkable.
+      -- We must not run the backend a second time with `dynamicNow` enable because
+      -- all the work has already been done in the first pipeline.
+      when (gopt Opt_BuildDynamicToo (hsc_dflags hsc_env) && backendWritesFiles (backend (hsc_dflags hsc_env)) ) $ do
           let dflags' = setDynamicNow (hsc_dflags hsc_env) -- set "dynamicNow"
           () <$ hscGenBackendPipeline pipe_env (hscSetFlags dflags' hsc_env) mod_sum result
       return res



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

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/2b69d69e56a8e6e1456f29bdda357ee14e3bc77c
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/20231206/cf1d0eff/attachment-0001.html>


More information about the ghc-commits mailing list