Skip to content
This repository has been archived by the owner on Jan 2, 2021. It is now read-only.

Dynamically load libm on Linux for each new session #723

Merged
merged 1 commit into from
Sep 3, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions session-loader/Development/IDE/Session.hs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import System.Info
import System.IO

import GHC
import GHCi
import DynFlags
import HscTypes
import Linker
Expand Down Expand Up @@ -179,6 +180,23 @@ loadSession dir = do
-> IO ([NormalizedFilePath],(IdeResult HscEnvEq,[FilePath]))
session args@(hieYaml, _cfp, _opts, _libDir) = do
(hscEnv, new, old_deps) <- packageSetup args

-- Whenever we spin up a session on Linux, dynamically load libm.so.6
-- in. We need this in case the binary is statically linked, in which
-- case the interactive session will fail when trying to load
-- ghc-prim, which happens whenever Template Haskell is being
-- evaluated or haskell-language-server's eval plugin tries to run
-- some code. If the binary is dynamically linked, then this will have
-- no effect.
-- See https://github.com/haskell/haskell-language-server/issues/221
when (os == "linux") $ do
initObjLinker hscEnv
res <- loadDLL hscEnv "libm.so.6"
case res of
Nothing -> pure ()
Just err -> hPutStrLn stderr $
"Error dynamically loading libm.so.6:\n" <> err

-- Make a map from unit-id to DynFlags, this is used when trying to
-- resolve imports. (especially PackageImports)
let uids = map (\ci -> (componentUnitId ci, componentDynFlags ci)) (new : old_deps)
Expand Down