summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Marlow <marlowsd@gmail.com>2011-08-03 09:39:48 +0100
committerSimon Marlow <marlowsd@gmail.com>2011-08-03 12:15:33 +0100
commitd146fdbbf8941a8344f0ec300e79dbeabc08d1ea (patch)
tree6927fb013c9bb908129f997da4ee886fe5c93406
parent9babbc8ddb62308762947debfe022635df1fce82 (diff)
downloadhaskell-d146fdbbf8941a8344f0ec300e79dbeabc08d1ea.tar.gz
Followup to #5289 changes: fix searching for dynamic libraries and use
of the RTS addDLL() API on Windows. When searching for DLLs we should include the .dll extension, but addDLL() takes a filename without the extension.
-rw-r--r--compiler/ghci/Linker.lhs4
-rw-r--r--compiler/ghci/ObjLink.lhs19
2 files changed, 18 insertions, 5 deletions
diff --git a/compiler/ghci/Linker.lhs b/compiler/ghci/Linker.lhs
index 63c68c5b35..747edde140 100644
--- a/compiler/ghci/Linker.lhs
+++ b/compiler/ghci/Linker.lhs
@@ -1091,9 +1091,7 @@ searchForLibUsingGcc dflags so dirs = do
mkSOName :: FilePath -> FilePath
mkSOName root
| isDarwinTarget = ("lib" ++ root) <.> "dylib"
- | isWindowsTarget = -- Win32 DLLs have no .dll extension here, because
- -- addDLL tries both foo.dll and foo.drv
- root
+ | isWindowsTarget = root <.> "dll"
| otherwise = ("lib" ++ root) <.> "so"
-- Darwin / MacOS X only: load a framework
diff --git a/compiler/ghci/ObjLink.lhs b/compiler/ghci/ObjLink.lhs
index cd593f7b45..f459145606 100644
--- a/compiler/ghci/ObjLink.lhs
+++ b/compiler/ghci/ObjLink.lhs
@@ -23,6 +23,7 @@ module ObjLink (
import Panic
import BasicTypes ( SuccessFlag, successIf )
import Config ( cLeadingUnderscore )
+import Util
import Control.Monad ( when )
import Foreign.C
@@ -30,7 +31,7 @@ import Foreign ( nullPtr )
import GHC.Exts ( Ptr(..) )
import GHC.IO.Encoding ( fileSystemEncoding )
import qualified GHC.Foreign as GHC
-
+import System.FilePath ( dropExtension )
-- ---------------------------------------------------------------------------
@@ -62,10 +63,24 @@ prefixUnderscore
| cLeadingUnderscore == "YES" = ('_':)
| otherwise = id
+-- | loadDLL loads a dynamic library using the OS's native linker
+-- (i.e. dlopen() on Unix, LoadLibrary() on Windows). It takes either
+-- an absolute pathname to the file, or a relative filename
+-- (e.g. "libfoo.so" or "foo.dll"). In the latter case, loadDLL
+-- searches the standard locations for the appropriate library.
+--
loadDLL :: String -> IO (Maybe String)
-- Nothing => success
-- Just err_msg => failure
-loadDLL str = do
+loadDLL str0 = do
+ let
+ -- On Windows, addDLL takes a filename without an extension, because
+ -- it tries adding both .dll and .drv. To keep things uniform in the
+ -- layers above, loadDLL always takes a filename with an extension, and
+ -- we drop it here on Windows only.
+ str | isWindowsHost = dropExtension str0
+ | otherwise = str0
+ --
maybe_errmsg <- withFileCString str $ \dll -> c_addDLL dll
if maybe_errmsg == nullPtr
then return Nothing