[Git][ghc/ghc][wip/t23912] Add -fforce-relink flag

Matthew Pickering (@mpickering) gitlab at gitlab.haskell.org
Thu Sep 7 13:29:31 UTC 2023



Matthew Pickering pushed to branch wip/t23912 at Glasgow Haskell Compiler / GHC


Commits:
497a0a87 by Matthew Pickering at 2023-09-07T14:29:20+01:00
Add -fforce-relink flag

Due to bugs like #23724 it could be useful to override the relinking
checker. The only way to do this at the moment is to use -fforce-recomp,
which is a very big hammer.

It is useful to provide a flag which just causes the linking step
to always happen if there are any more issues in this area.

Fixes #23912

- - - - -


7 changed files:

- compiler/GHC/Driver/Flags.hs
- compiler/GHC/Driver/Pipeline.hs
- compiler/GHC/Driver/Session.hs
- docs/users_guide/separate_compilation.rst
- testsuite/tests/driver/Makefile
- + testsuite/tests/driver/T23912.stdout
- testsuite/tests/driver/all.T


Changes:

=====================================
compiler/GHC/Driver/Flags.hs
=====================================
@@ -339,6 +339,7 @@ data GeneralFlag
    -- misc opts
    | Opt_Pp
    | Opt_ForceRecomp
+   | Opt_ForceRelink
    | Opt_IgnoreOptimChanges
    | Opt_IgnoreHpcChanges
    | Opt_ExcessPrecision


=====================================
compiler/GHC/Driver/Pipeline.hs
=====================================
@@ -436,9 +436,8 @@ link' logger tmpfs fc dflags unit_env batch_attempt_linking mHscMessager hpt
             exe_file  = exeFileName arch_os staticLink (outputFile_ dflags)
 
         linking_needed <- linkingNeeded logger dflags unit_env staticLink linkables pkg_deps
-
         forM_ mHscMessager $ \hscMessage -> hscMessage linking_needed
-        if not (gopt Opt_ForceRecomp dflags) && (linking_needed == UpToDate)
+        if linking_needed == UpToDate
            then do debugTraceMsg logger 2 (text exe_file <+> text "is up to date, linking not required.")
                    return Succeeded
            else do
@@ -474,10 +473,11 @@ linkJSBinary logger fc dflags unit_env obj_files pkg_deps = do
   jsLinkBinary fc lc_cfg cfg extra_js logger dflags unit_env obj_files pkg_deps
 
 linkingNeeded :: Logger -> DynFlags -> UnitEnv -> Bool -> [Linkable] -> [UnitId] -> IO RecompileRequired
+linkingNeeded _ dflags _ _ _ _ | gopt Opt_ForceRelink dflags = return (NeedsRecompile MustCompile)
 linkingNeeded logger dflags unit_env staticLink linkables pkg_deps = do
         -- if the modification time on the executable is later than the
         -- modification times on all of the objects and libraries, then omit
-        -- linking (unless the -fforce-recomp flag was given).
+        -- linking (unless the -fforce-recomp or -fforce-relink flag was given).
   let platform   = ue_platform unit_env
       unit_state = ue_units unit_env
       arch_os    = platformArchOS platform


=====================================
compiler/GHC/Driver/Session.hs
=====================================
@@ -2370,6 +2370,7 @@ fFlagsDeps = [
   flagSpec "family-application-cache"         Opt_FamAppCache,
   flagSpec "float-in"                         Opt_FloatIn,
   flagSpec "force-recomp"                     Opt_ForceRecomp,
+  flagSpec "force-relink"                     Opt_ForceRelink,
   flagSpec "ignore-optim-changes"             Opt_IgnoreOptimChanges,
   flagSpec "ignore-hpc-changes"               Opt_IgnoreHpcChanges,
   flagSpec "full-laziness"                    Opt_FullLaziness,
@@ -2777,6 +2778,7 @@ impliedGFlags = [(Opt_DeferTypeErrors, turnOn, Opt_DeferTypedHoles)
                 ,(Opt_ByteCodeAndObjectCode, turnOn, Opt_WriteIfSimplifiedCore)
                 ,(Opt_InfoTableMap, turnOn, Opt_InfoTableMapWithStack)
                 ,(Opt_InfoTableMap, turnOn, Opt_InfoTableMapWithFallback)
+                ,(Opt_ForceRecomp, turnOn, Opt_ForceRelink)
                 ] ++ validHoleFitsImpliedGFlags
 
 -- General flags that are switched on/off when other general flags are switched


=====================================
docs/users_guide/separate_compilation.rst
=====================================
@@ -663,6 +663,21 @@ The recompilation checker
     existing ``.o`` file in place, if it can be determined that the
     module does not need to be recompiled.
 
+    This flag implies :ghc-flag:`-fforce-relink`.
+
+.. ghc-flag:: -fforce-relink
+    :shortdesc: Turn off relinking checking.
+    :type: dynamic
+    :reverse: -fno-force-relink
+    :category: recompilation
+    :since: 9.10.1
+
+    Turn off relinking checking (which is on by default). Normally in ``--make``
+    mode we try to avoid linking if we can determine that linking is not required.
+
+    This can be useful if there is a bug in the relinking checking but you don't
+    want to use the much bigger hammer provided by :ghc-flag:`-fforce-recomp`.
+
 .. ghc-flag:: -fignore-optim-changes
     :shortdesc: Do not recompile modules just to match changes to
         optimisation flags. This is especially useful for avoiding


=====================================
testsuite/tests/driver/Makefile
=====================================
@@ -809,4 +809,12 @@ T23339B:
 	# Check that the file is kept and is the right one
 	find . -name "*.c" -exec cat {} \; | grep "init__ip_init"
 
+T23912:
+	$(RM) T23912.hi
+	$(RM) T23912$(OBJSUFFIX)
+	$(RM) -rf "$(PWD)/tmp"
+	mkdir -p tmp
+	"$(TEST_HC)" -tmpdir "$(PWD)/tmp" $(TEST_HC_OPTS) -v0 T23912.hs -fforce-relink
+	"$(TEST_HC)" -tmpdir "$(PWD)/tmp" $(TEST_HC_OPTS) -v1 T23912.hs -fforce-relink
+
 


=====================================
testsuite/tests/driver/T23912.stdout
=====================================
@@ -0,0 +1 @@
+[2 of 2] Linking T23912


=====================================
testsuite/tests/driver/all.T
=====================================
@@ -324,3 +324,4 @@ test('T22669', req_interp, makefile_test, [])
 test('T23339', req_c, makefile_test, [])
 test('T23339B', [extra_files(['T23339.hs']), req_c], makefile_test, [])
 test('T23613', normal, compile_and_run, ['-this-unit-id=foo'])
+test('T23912', normal, makefile_test, ['T23912'])



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

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/497a0a87e64454985797cda6169e4895114d5549
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/20230907/3e0eb084/attachment-0001.html>


More information about the ghc-commits mailing list