Bug fix in the new HscMain code.
[ghc-hetmet.git] / ghc / compiler / ghci / Linker.lhs
index f8a8c8b..15786f4 100644 (file)
@@ -29,7 +29,6 @@ import ByteCodeAsm    ( CompiledByteCode(..), bcoFreeNames, UnlinkedBCO(..))
 
 import Packages
 import DriverPhases    ( isObjectFilename, isDynLibFilename )
-import Util            ( getFileSuffix )
 import Finder          ( findModule, findObjectLinkableMaybe, FindResult(..) )
 import HscTypes
 import Name            ( Name, nameModule, isExternalName, isWiredInName )
@@ -41,7 +40,7 @@ import DynFlags               ( DynFlags(..), getOpts )
 import BasicTypes      ( SuccessFlag(..), succeeded, failed )
 import Outputable
 import Panic            ( GhcException(..) )
-import Util             ( zipLazy, global )
+import Util             ( zipLazy, global, joinFileExt, joinFileName, suffixOf )
 import StaticFlags     ( v_Ld_inputs )
 import ErrUtils         ( debugTraceMsg )
 
@@ -624,12 +623,9 @@ unload dflags linkables
        new_pls <- unload_wkr dflags linkables pls
        writeIORef v_PersistentLinkerState new_pls
 
-       debugTraceMsg dflags 3 (showSDoc
-               (text "unload: retaining objs" <+> ppr (objs_loaded new_pls)))
-       debugTraceMsg dflags 3 (showSDoc
-               (text "unload: retaining bcos" <+> ppr (bcos_loaded new_pls)))
-
-               return ()
+       debugTraceMsg dflags 3 (text "unload: retaining objs" <+> ppr (objs_loaded new_pls))
+       debugTraceMsg dflags 3 (text "unload: retaining bcos" <+> ppr (bcos_loaded new_pls))
+       return ()
 
 unload_wkr :: DynFlags
            -> [Linkable]               -- stable linkables
@@ -760,8 +756,19 @@ linkPackage :: DynFlags -> PackageConfig -> IO ()
 linkPackage dflags pkg
    = do 
         let dirs      =  Packages.libraryDirs pkg
-        let libs      =  Packages.hsLibraries pkg ++ Packages.extraLibraries pkg
-                               ++ [ lib | '-':'l':lib <- Packages.ldOptions pkg ]
+
+        let libs      =  Packages.hsLibraries pkg
+        -- Because of slight differences between the GHC dynamic linker and
+        -- the native system linker some packages have to link with a
+        -- different list of libraries when using GHCi. Examples include: libs
+        -- that are actually gnu ld scripts, and the possability that the .a
+        -- libs do not exactly match the .so/.dll equivalents. So if the
+        -- package file provides an "extra-ghci-libraries" field then we use
+        -- that instead of the "extra-libraries" field.
+                      ++ (if null (Packages.extraGHCiLibraries pkg)
+                            then Packages.extraLibraries pkg
+                            else Packages.extraGHCiLibraries pkg)
+                      ++ [ lib | '-':'l':lib <- Packages.ldOptions pkg ]
         classifieds   <- mapM (locateOneObj dirs) libs
 
         -- Complication: all the .so's must be loaded before any of the .o's.