summaryrefslogtreecommitdiff
path: root/compiler
diff options
context:
space:
mode:
authorZiyang Liu <unsafeFixIO@gmail.com>2021-10-08 22:25:04 -0700
committerMarge Bot <ben+marge-bot@smart-cactus.org>2021-10-14 14:32:57 -0400
commit557d26fabacbbf4e47480feae385f20761e1096f (patch)
treee3f7da1d7ce4cef87357b314c1d500c2c5ed02d6 /compiler
parent7f2ce0d6bc1404d6d91b3d8560efddc208f46a24 (diff)
downloadhaskell-557d26fabacbbf4e47480feae385f20761e1096f.tar.gz
Suggest -dynamic-too in failNonStd when applicable
I encountered an error that says ``` Cannot load -dynamic objects when GHC is built the normal way To fix this, either: (1) Use -fexternal-interpreter, or (2) Build the program twice: once the normal way, and then with -dynamic using -osuf to set a different object file suffix. ``` Or it could say ``` (2) Use -dynamic-too ```
Diffstat (limited to 'compiler')
-rw-r--r--compiler/GHC/Linker/Loader.hs38
1 files changed, 26 insertions, 12 deletions
diff --git a/compiler/GHC/Linker/Loader.hs b/compiler/GHC/Linker/Loader.hs
index ef15615656..3cdee27863 100644
--- a/compiler/GHC/Linker/Loader.hs
+++ b/compiler/GHC/Linker/Loader.hs
@@ -628,24 +628,38 @@ checkNonStdWay dflags interp srcspan
normalObjectSuffix :: String
normalObjectSuffix = phaseInputExt StopLn
+data Way' = Normal | Prof | Dyn
+
failNonStd :: DynFlags -> SrcSpan -> IO (Maybe FilePath)
failNonStd dflags srcspan = dieWith dflags srcspan $
- text "Cannot load" <+> compWay <+>
- text "objects when GHC is built" <+> ghciWay $$
+ text "Cannot load" <+> pprWay' compWay <+>
+ text "objects when GHC is built" <+> pprWay' ghciWay $$
text "To fix this, either:" $$
text " (1) Use -fexternal-interpreter, or" $$
- text " (2) Build the program twice: once" <+>
- ghciWay <> text ", and then" $$
- text " with" <+> compWay <+>
- text "using -osuf to set a different object file suffix."
+ buildTwiceMsg
where compWay
- | ways dflags `hasWay` WayDyn = text "-dynamic"
- | ways dflags `hasWay` WayProf = text "-prof"
- | otherwise = text "normal"
+ | ways dflags `hasWay` WayDyn = Dyn
+ | ways dflags `hasWay` WayProf = Prof
+ | otherwise = Normal
ghciWay
- | hostIsDynamic = text "with -dynamic"
- | hostIsProfiled = text "with -prof"
- | otherwise = text "the normal way"
+ | hostIsDynamic = Dyn
+ | hostIsProfiled = Prof
+ | otherwise = Normal
+ buildTwiceMsg = case (ghciWay, compWay) of
+ (Normal, Dyn) -> dynamicTooMsg
+ (Dyn, Normal) -> dynamicTooMsg
+ _ ->
+ text " (2) Build the program twice: once" <+>
+ pprWay' ghciWay <> text ", and then" $$
+ text " " <> pprWay' compWay <+>
+ text "using -osuf to set a different object file suffix."
+ dynamicTooMsg = text " (2) Use -dynamic-too," <+>
+ text "and use -osuf and -dynosuf to set object file suffixes as needed."
+ pprWay' :: Way' -> SDoc
+ pprWay' way = text $ case way of
+ Normal -> "the normal way"
+ Prof -> "with -prof"
+ Dyn -> "with -dynamic"
getLinkDeps :: HscEnv -> HomePackageTable
-> LoaderState