Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC
Commits:
-
02a7c18a
by Cheng Shao at 2025-09-30T18:41:27-04:00
-
aa0ca5e3
by Cheng Shao at 2025-09-30T18:41:27-04:00
-
69503668
by Cheng Shao at 2025-09-30T18:41:27-04:00
9 changed files:
- compiler/GHC.hs
- compiler/GHC/Driver/Session.hs
- compiler/GHC/Linker/Loader.hs
- compiler/GHC/Runtime/Interpreter/Types.hs
- hadrian/src/Settings/Packages.hs
- libraries/ghci/GHCi/ObjLink.hs
- + testsuite/tests/ghci-wasm/T26431.hs
- + testsuite/tests/ghci-wasm/T26431.stdout
- testsuite/tests/ghci-wasm/all.T
Changes:
| ... | ... | @@ -716,17 +716,14 @@ setTopSessionDynFlags dflags = do |
| 716 | 716 | |
| 717 | 717 | -- see Note [Target code interpreter]
|
| 718 | 718 | interp <- if
|
| 719 | +#if !defined(wasm32_HOST_ARCH)
|
|
| 719 | 720 | -- Wasm dynamic linker
|
| 720 | 721 | | ArchWasm32 <- platformArch $ targetPlatform dflags
|
| 721 | 722 | -> do
|
| 722 | 723 | s <- liftIO $ newMVar InterpPending
|
| 723 | 724 | loader <- liftIO Loader.uninitializedLoader
|
| 724 | 725 | dyld <- liftIO $ makeAbsolute $ topDir dflags </> "dyld.mjs"
|
| 725 | -#if defined(wasm32_HOST_ARCH)
|
|
| 726 | - let libdir = sorry "cannot spawn child process on wasm"
|
|
| 727 | -#else
|
|
| 728 | 726 | libdir <- liftIO $ last <$> Loader.getGccSearchDirectory logger dflags "libraries"
|
| 729 | -#endif
|
|
| 730 | 727 | let profiled = ways dflags `hasWay` WayProf
|
| 731 | 728 | way_tag = if profiled then "_p" else ""
|
| 732 | 729 | let cfg =
|
| ... | ... | @@ -747,6 +744,7 @@ setTopSessionDynFlags dflags = do |
| 747 | 744 | wasmInterpUnitState = ue_homeUnitState $ hsc_unit_env hsc_env
|
| 748 | 745 | }
|
| 749 | 746 | pure $ Just $ Interp (ExternalInterp $ ExtWasm $ ExtInterpState cfg s) loader lookup_cache
|
| 747 | +#endif
|
|
| 750 | 748 | |
| 751 | 749 | -- JavaScript interpreter
|
| 752 | 750 | | ArchJavaScript <- platformArch (targetPlatform dflags)
|
| ... | ... | @@ -3763,12 +3763,17 @@ makeDynFlagsConsistent dflags |
| 3763 | 3763 | -- only supports dynamic code
|
| 3764 | 3764 | | LinkInMemory <- ghcLink dflags
|
| 3765 | 3765 | , sTargetRTSLinkerOnlySupportsSharedLibs $ settings dflags
|
| 3766 | +#if defined(HAVE_INTERNAL_INTERPRETER)
|
|
| 3767 | + , not (ways dflags `hasWay` WayDyn)
|
|
| 3768 | +#else
|
|
| 3766 | 3769 | , not (ways dflags `hasWay` WayDyn && gopt Opt_ExternalInterpreter dflags)
|
| 3770 | +#endif
|
|
| 3767 | 3771 | = flip loopNoWarn "Forcing dynamic way because target RTS linker only supports dynamic code" $
|
| 3768 | - -- See checkOptions, -fexternal-interpreter is
|
|
| 3769 | - -- required when using --interactive with a non-standard
|
|
| 3770 | - -- way (-prof, -static, or -dynamic).
|
|
| 3772 | +#if !defined(HAVE_INTERNAL_INTERPRETER)
|
|
| 3773 | + -- Force -fexternal-interpreter if internal-interpreter is not
|
|
| 3774 | + -- available at this stage
|
|
| 3771 | 3775 | setGeneralFlag' Opt_ExternalInterpreter $
|
| 3776 | +#endif
|
|
| 3772 | 3777 | addWay' WayDyn dflags
|
| 3773 | 3778 | |
| 3774 | 3779 | | LinkInMemory <- ghcLink dflags
|
| ... | ... | @@ -1614,6 +1614,9 @@ gccSearchDirCache = unsafePerformIO $ newIORef [] |
| 1614 | 1614 | -- which dominate a large percentage of startup time on Windows.
|
| 1615 | 1615 | getGccSearchDirectory :: Logger -> DynFlags -> String -> IO [FilePath]
|
| 1616 | 1616 | getGccSearchDirectory logger dflags key = do
|
| 1617 | +#if defined(wasm32_HOST_ARCH)
|
|
| 1618 | + pure []
|
|
| 1619 | +#else
|
|
| 1617 | 1620 | cache <- readIORef gccSearchDirCache
|
| 1618 | 1621 | case lookup key cache of
|
| 1619 | 1622 | Just x -> return x
|
| ... | ... | @@ -1640,6 +1643,7 @@ getGccSearchDirectory logger dflags key = do |
| 1640 | 1643 | x:_ -> case break (=='=') x of
|
| 1641 | 1644 | (_ , []) -> []
|
| 1642 | 1645 | (_, (_:xs)) -> xs
|
| 1646 | +#endif
|
|
| 1643 | 1647 | |
| 1644 | 1648 | -- | Get a list of system search directories, this to alleviate pressure on
|
| 1645 | 1649 | -- the findSysDll function.
|
| ... | ... | @@ -214,7 +214,7 @@ data JSInterpConfig = JSInterpConfig |
| 214 | 214 | |
| 215 | 215 | data WasmInterpConfig = WasmInterpConfig
|
| 216 | 216 | { wasmInterpDyLD :: !FilePath -- ^ Location of dyld.mjs script
|
| 217 | - , wasmInterpLibDir :: FilePath -- ^ wasi-sdk sysroot libdir containing libc.so, etc
|
|
| 217 | + , wasmInterpLibDir :: !FilePath -- ^ wasi-sdk sysroot libdir containing libc.so, etc
|
|
| 218 | 218 | , wasmInterpOpts :: ![String] -- ^ Additional command line arguments for iserv
|
| 219 | 219 | |
| 220 | 220 | -- wasm ghci browser mode
|
| ... | ... | @@ -82,15 +82,18 @@ packageArgs = do |
| 82 | 82 | ]
|
| 83 | 83 | |
| 84 | 84 | , builder (Cabal Flags) ? mconcat
|
| 85 | - -- For the ghc library, internal-interpreter only makes
|
|
| 86 | - -- sense when we're not cross compiling. For cross GHC,
|
|
| 87 | - -- external interpreter is used for loading target code
|
|
| 88 | - -- and internal interpreter is supposed to load native
|
|
| 89 | - -- code for plugins (!7377), however it's unfinished work
|
|
| 90 | - -- (#14335) and completely untested in CI for cross
|
|
| 91 | - -- backends at the moment, so we might as well disable it
|
|
| 92 | - -- for cross GHC.
|
|
| 93 | - [ andM [expr (ghcWithInterpreter stage), notCross] `cabalFlag` "internal-interpreter"
|
|
| 85 | + -- In order to enable internal-interpreter for the ghc
|
|
| 86 | + -- library:
|
|
| 87 | + --
|
|
| 88 | + -- 1. ghcWithInterpreter must be True ("Use interpreter" =
|
|
| 89 | + -- "YES")
|
|
| 90 | + -- 2. For non-cross case it can be enabled
|
|
| 91 | + -- 3. For cross case, disable for stage0 since that runs
|
|
| 92 | + -- on the host and must rely on external interpreter to
|
|
| 93 | + -- load target code, otherwise enable for stage1 since
|
|
| 94 | + -- that runs on the target and can use target's own
|
|
| 95 | + -- ghci object linker
|
|
| 96 | + [ andM [expr (ghcWithInterpreter stage), orM [notCross, stage1]] `cabalFlag` "internal-interpreter"
|
|
| 94 | 97 | , orM [ notM cross, haveCurses ] `cabalFlag` "terminfo"
|
| 95 | 98 | , arg "-build-tool-depends"
|
| 96 | 99 | , flag UseLibzstd `cabalFlag` "with-libzstd"
|
| ... | ... | @@ -113,8 +113,7 @@ foreign import javascript unsafe "__ghc_wasm_jsffi_dyld.lookupSymbol($1)" |
| 113 | 113 | js_lookupSymbol :: JSString -> IO (Ptr a)
|
| 114 | 114 | |
| 115 | 115 | lookupSymbolInDLL :: Ptr LoadedDLL -> String -> IO (Maybe (Ptr a))
|
| 116 | -lookupSymbolInDLL _ sym =
|
|
| 117 | - throwIO $ ErrorCall $ "lookupSymbolInDLL: unsupported on wasm for " <> sym
|
|
| 116 | +lookupSymbolInDLL _ _ = pure Nothing
|
|
| 118 | 117 | |
| 119 | 118 | resolveObjs :: IO Bool
|
| 120 | 119 | resolveObjs = pure True
|
| 1 | +import Control.Exception
|
|
| 2 | +import Control.Monad.IO.Class
|
|
| 3 | +import Data.Maybe
|
|
| 4 | +import GHC
|
|
| 5 | +import GHC.Plugins
|
|
| 6 | +import GHC.Runtime.Interpreter
|
|
| 7 | +import System.Environment.Blank
|
|
| 8 | + |
|
| 9 | +main :: IO ()
|
|
| 10 | +main = do
|
|
| 11 | + [libdir] <- getArgs
|
|
| 12 | + defaultErrorHandler defaultFatalMessager defaultFlushOut $
|
|
| 13 | + runGhc (Just libdir) $
|
|
| 14 | + do
|
|
| 15 | + dflags0 <- getSessionDynFlags
|
|
| 16 | + let dflags1 =
|
|
| 17 | + dflags0
|
|
| 18 | + { ghcMode = CompManager,
|
|
| 19 | + backend = interpreterBackend,
|
|
| 20 | + ghcLink = LinkInMemory
|
|
| 21 | + }
|
|
| 22 | + logger <- getLogger
|
|
| 23 | + (dflags2, _, _) <-
|
|
| 24 | + parseDynamicFlags logger dflags1 $
|
|
| 25 | + map noLoc ["-package", "ghc"]
|
|
| 26 | + _ <- setSessionDynFlags dflags2
|
|
| 27 | + addTarget =<< guessTarget "hello.hs" Nothing Nothing
|
|
| 28 | + _ <- load LoadAllTargets
|
|
| 29 | + setContext
|
|
| 30 | + [ IIDecl $ simpleImportDecl $ mkModuleName "Prelude",
|
|
| 31 | + IIDecl $ simpleImportDecl $ mkModuleName "Main"
|
|
| 32 | + ]
|
|
| 33 | + hsc_env <- getSession
|
|
| 34 | + fhv <- compileExprRemote "main"
|
|
| 35 | + liftIO $ evalIO (fromJust $ hsc_interp hsc_env) fhv |
| 1 | +main = putStrLn "hello world" |
| ... | ... | @@ -10,3 +10,11 @@ test('T26430', [ |
| 10 | 10 | extra_hc_opts('-L. -lT26430B')]
|
| 11 | 11 | , compile_and_run, ['']
|
| 12 | 12 | )
|
| 13 | + |
|
| 14 | +test('T26431', [
|
|
| 15 | + extra_files(['../../../.gitlab/hello.hs']),
|
|
| 16 | + extra_hc_opts('-package ghc'),
|
|
| 17 | + extra_run_opts(f'"{config.libdir}"'),
|
|
| 18 | + ignore_stderr]
|
|
| 19 | +, compile_and_run, ['']
|
|
| 20 | +) |