Always enable the archive-loading code
authorIan Lynagh <igloo@earth.li>
Sat, 27 Nov 2010 17:30:00 +0000 (17:30 +0000)
committerIan Lynagh <igloo@earth.li>
Sat, 27 Nov 2010 17:30:00 +0000 (17:30 +0000)
If the GHCi .o lib doesn't exist, load the .a instead

compiler/ghc.mk
compiler/ghci/Linker.lhs
compiler/main/DynFlags.hs
mk/config.mk.in
rts/Linker.c
rts/ghc.mk
rules/build-package-data.mk
rules/build-package-way.mk
utils/ghc-cabal/ghc-cabal.hs

index 0f419c6..60a65d4 100644 (file)
@@ -136,12 +136,6 @@ ifeq "$(RelocatableBuild)" "YES"
 else
        @echo 'cRelocatableBuild     = False'                               >> $@
 endif
 else
        @echo 'cRelocatableBuild     = False'                               >> $@
 endif
-       @echo 'cUseArchivesForGhci   :: Bool'                               >> $@
-ifeq "$(UseArchivesForGhci)" "YES"
-       @echo 'cUseArchivesForGhci   = True'                                >> $@
-else
-       @echo 'cUseArchivesForGhci   = False'                               >> $@
-endif
        @echo 'cLibFFI               :: Bool'                               >> $@
 ifeq "$(UseLibFFIForAdjustors)" "YES"
        @echo 'cLibFFI               = True'                                >> $@
        @echo 'cLibFFI               :: Bool'                               >> $@
 ifeq "$(UseLibFFIForAdjustors)" "YES"
        @echo 'cLibFFI               = True'                                >> $@
@@ -363,10 +357,9 @@ compiler_CONFIGURE_OPTS += --ghc-option=-DNO_REGS
 endif
 
 # If we're profiling GHC then we want lots of SCCs, so -auto-all
 endif
 
 # If we're profiling GHC then we want lots of SCCs, so -auto-all
-# We also don't want to waste time building the non-profiling library,
-# either normally or for ghci. Unfortunately this means that we have to
-# tell ghc-pkg --force as it gets upset when libHSghc-6.9.a doesn't
-# exist.
+# We also don't want to waste time building the non-profiling library.
+# Unfortunately this means that we have to tell ghc-pkg --force as it
+# gets upset when libHSghc-6.9.a doesn't exist.
 ifeq "$(GhcProfiled)" "YES"
 compiler_stage2_CONFIGURE_OPTS += --ghc-option=-auto-all
 # We seem to still build the vanilla libraries even if we say
 ifeq "$(GhcProfiled)" "YES"
 compiler_stage2_CONFIGURE_OPTS += --ghc-option=-auto-all
 # We seem to still build the vanilla libraries even if we say
@@ -375,7 +368,6 @@ compiler_stage2_CONFIGURE_OPTS += --ghc-option=-auto-all
 # their absence when we register the package. So for now, we just
 # leave the vanilla libraries enabled.
 # compiler_stage2_CONFIGURE_OPTS += --disable-library-vanilla
 # their absence when we register the package. So for now, we just
 # leave the vanilla libraries enabled.
 # compiler_stage2_CONFIGURE_OPTS += --disable-library-vanilla
-compiler_stage2_CONFIGURE_OPTS += --disable-library-for-ghci
 compiler_stage2_CONFIGURE_OPTS += --ghc-pkg-option=--force
 endif
 
 compiler_stage2_CONFIGURE_OPTS += --ghc-pkg-option=--force
 endif
 
@@ -472,6 +464,16 @@ $(eval $(call build-package,compiler,stage1,0))
 $(eval $(call build-package,compiler,stage2,1))
 $(eval $(call build-package,compiler,stage3,2))
 
 $(eval $(call build-package,compiler,stage2,1))
 $(eval $(call build-package,compiler,stage3,2))
 
+# after build-package, because that adds --enable-library-for-ghci
+# to compiler_stage*_CONFIGURE_OPTS:
+# We don't build the GHCi library for the ghc package. We can load it
+# the .a file instead, and as object splitting isn't on for the ghc
+# package this isn't much slower.However, not building the package saves
+# a significant chunk of disk space.
+compiler_stage1_CONFIGURE_OPTS += --disable-library-for-ghci
+compiler_stage2_CONFIGURE_OPTS += --disable-library-for-ghci
+compiler_stage3_CONFIGURE_OPTS += --disable-library-for-ghci
+
 # after build-package, because that sets compiler_stage1_HC_OPTS:
 compiler_stage1_HC_OPTS += $(GhcStage1HcOpts)
 compiler_stage2_HC_OPTS += $(GhcStage2HcOpts)
 # after build-package, because that sets compiler_stage1_HC_OPTS:
 compiler_stage1_HC_OPTS += $(GhcStage1HcOpts)
 compiler_stage2_HC_OPTS += $(GhcStage2HcOpts)
index cc90cb5..29228b1 100644 (file)
@@ -1106,41 +1106,28 @@ loadFrameworks pkg
 locateOneObj :: [FilePath] -> String -> IO LibrarySpec
 locateOneObj dirs lib
   | not isDynamicGhcLib
 locateOneObj :: [FilePath] -> String -> IO LibrarySpec
 locateOneObj dirs lib
   | not isDynamicGhcLib
-    -- When the GHC package was not compiled as dynamic library 
-    -- (=DYNAMIC not set), we search for .o libraries.
-  = do mb_libSpec <- if cUseArchivesForGhci
-                     then do mb_arch_path <- findFile mk_arch_path dirs
-                             case mb_arch_path of
-                                 Just arch_path ->
-                                     return (Just (Archive arch_path))
-                                 Nothing ->
-                                     return Nothing
-                     else do mb_obj_path <- findFile mk_obj_path dirs
-                             case mb_obj_path of
-                                 Just obj_path ->
-                                     return (Just (Object obj_path))
-                                 Nothing ->
-                                     return Nothing
-       case mb_libSpec of
-          Just ls -> return ls
-          Nothing -> return (DLL lib)
-
+    -- When the GHC package was not compiled as dynamic library
+    -- (=DYNAMIC not set), we search for .o libraries or, if they
+    -- don't exist, .a libraries.
+  = findObject `orElse` findArchive `orElse` assumeDll
   | otherwise
     -- When the GHC package was compiled as dynamic library (=DYNAMIC set),
     -- we search for .so libraries first.
   | otherwise
     -- When the GHC package was compiled as dynamic library (=DYNAMIC set),
     -- we search for .so libraries first.
-  = do { mb_lib_path <- findFile mk_dyn_lib_path dirs
-       ; case mb_lib_path of
-           Just _ -> return (DLL dyn_lib_name)
-           Nothing       ->
-                do { mb_obj_path <- findFile mk_obj_path dirs
-                   ; case mb_obj_path of
-                       Just obj_path -> return (Object obj_path)
-                       Nothing       -> return (DLL lib) }}            -- We assume
+  = findDll `orElse` findObject `orElse` findArchive `orElse` assumeDll
    where
      mk_obj_path dir = dir </> (lib <.> "o")
      mk_arch_path dir = dir </> ("lib" ++ lib <.> "a")
      dyn_lib_name = lib ++ "-ghc" ++ cProjectVersion
      mk_dyn_lib_path dir = dir </> mkSOName dyn_lib_name
    where
      mk_obj_path dir = dir </> (lib <.> "o")
      mk_arch_path dir = dir </> ("lib" ++ lib <.> "a")
      dyn_lib_name = lib ++ "-ghc" ++ cProjectVersion
      mk_dyn_lib_path dir = dir </> mkSOName dyn_lib_name
+     findObject  = liftM (fmap Object)  $ findFile mk_obj_path  dirs
+     findArchive = liftM (fmap Archive) $ findFile mk_arch_path dirs
+     findDll     = liftM (fmap DLL)     $ findFile mk_dyn_lib_path dirs
+     assumeDll   = return (DLL lib)
+     infixr `orElse`
+     f `orElse` g = do m <- f
+                       case m of
+                           Just x -> return x
+                           Nothing -> g
 
 -- ----------------------------------------------------------------------------
 -- Loading a dyanmic library (dlopen()-ish on Unix, LoadLibrary-ish on Win32)
 
 -- ----------------------------------------------------------------------------
 -- Loading a dyanmic library (dlopen()-ish on Unix, LoadLibrary-ish on Win32)
index 7a4607a..df51f94 100644 (file)
@@ -2285,7 +2285,6 @@ compilerInfo = [("Project name",                String cProjectName),
                 ("Object splitting",            String cSplitObjs),
                 ("Have native code generator",  String cGhcWithNativeCodeGen),
                 ("Have llvm code generator",    String cGhcWithLlvmCodeGen),
                 ("Object splitting",            String cSplitObjs),
                 ("Have native code generator",  String cGhcWithNativeCodeGen),
                 ("Have llvm code generator",    String cGhcWithLlvmCodeGen),
-                ("Use archives for ghci",       String (show cUseArchivesForGhci)),
                 ("Support SMP",                 String cGhcWithSMP),
                 ("Unregisterised",              String cGhcUnregisterised),
                 ("Tables next to code",         String cGhcEnableTablesNextToCode),
                 ("Support SMP",                 String cGhcWithSMP),
                 ("Unregisterised",              String cGhcUnregisterised),
                 ("Tables next to code",         String cGhcEnableTablesNextToCode),
index 495b251..fd6ee47 100644 (file)
@@ -190,12 +190,6 @@ else
 UseLibFFIForAdjustors=YES
 endif
 
 UseLibFFIForAdjustors=YES
 endif
 
-ifeq "$(findstring $(HostOS_CPP), darwin)" ""
-UseArchivesForGhci = NO
-else
-UseArchivesForGhci = YES
-endif
-
 # On Windows we normally want to make a relocatable bindist, to we
 # ignore flags like libdir
 ifeq "$(Windows)" "YES"
 # On Windows we normally want to make a relocatable bindist, to we
 # ignore flags like libdir
 ifeq "$(Windows)" "YES"
index 657c2c3..6ce16d9 100644 (file)
@@ -1670,7 +1670,6 @@ mkOc( char *path, char *image, int imageSize,
    return oc;
 }
 
    return oc;
 }
 
-#if defined(USE_ARCHIVES_FOR_GHCI)
 HsInt
 loadArchive( char *path )
 {
 HsInt
 loadArchive( char *path )
 {
@@ -1765,11 +1764,16 @@ loadArchive( char *path )
 
            /* We can't mmap from the archive directly, as object
               files need to be 8-byte aligned but files in .ar
 
            /* We can't mmap from the archive directly, as object
               files need to be 8-byte aligned but files in .ar
-              archives are 2-byte aligned, and if we malloc the
-              memory then we can be given memory above 2^32, so we
-              mmap some anonymous memory and use that. We could
-              do better here. */
+              archives are 2-byte aligned. When possible we use mmap
+              to get some anonymous memory, as on 64-bit platforms if
+              we use malloc then we can be given memory above 2^32.
+              In the mmap case we're probably wasting lots of space;
+              we could do better. */
+#ifdef USE_MMAP
            image = mmapForLinker(imageSize, MAP_ANONYMOUS, -1);
            image = mmapForLinker(imageSize, MAP_ANONYMOUS, -1);
+#else
+           image = stgMallocBytes(imageSize, "loadArchive(image)");
+#endif
            n = fread ( image, 1, imageSize, f );
            if (n != imageSize)
                barf("loadObj: error whilst reading `%s'", path);
            n = fread ( image, 1, imageSize, f );
            if (n != imageSize)
                barf("loadObj: error whilst reading `%s'", path);
@@ -1817,12 +1821,6 @@ loadArchive( char *path )
    stgFree(file);
    return 1;
 }
    stgFree(file);
    return 1;
 }
-#else
-HsInt GNU_ATTRIBUTE(__noreturn__)
-loadArchive( char *path STG_UNUSED ) {
-    barf("loadArchive: not enabled");
-}
-#endif
 
 /* -----------------------------------------------------------------------------
  * Load an obj (populate the global symbol table, but don't resolve yet)
 
 /* -----------------------------------------------------------------------------
  * Load an obj (populate the global symbol table, but don't resolve yet)
index 2bd67de..55a11ba 100644 (file)
@@ -246,10 +246,6 @@ ifeq "$(UseLibFFIForAdjustors)" "YES"
 rts_CC_OPTS += -DUSE_LIBFFI_FOR_ADJUSTORS
 endif
 
 rts_CC_OPTS += -DUSE_LIBFFI_FOR_ADJUSTORS
 endif
 
-ifeq "$(UseArchivesForGhci)" "YES"
-rts_CC_OPTS += -DUSE_ARCHIVES_FOR_GHCI
-endif
-
 # Mac OS X: make sure we compile for the right OS version
 rts_CC_OPTS += $(MACOSX_DEPLOYMENT_CC_OPTS)
 rts_HC_OPTS += $(addprefix -optc, $(MACOSX_DEPLOYMENT_CC_OPTS))
 # Mac OS X: make sure we compile for the right OS version
 rts_CC_OPTS += $(MACOSX_DEPLOYMENT_CC_OPTS)
 rts_HC_OPTS += $(addprefix -optc, $(MACOSX_DEPLOYMENT_CC_OPTS))
index 2ed47e1..9b8474a 100644 (file)
@@ -25,7 +25,7 @@ ifeq "$$(filter dyn,$$(GhcLibWays))" "dyn"
 $1_$2_CONFIGURE_OPTS += --enable-shared
 endif
 
 $1_$2_CONFIGURE_OPTS += --enable-shared
 endif
 
-ifeq "$$(GhcWithInterpreter) $$(UseArchivesForGhci)" "YES NO"
+ifeq "$$(GhcWithInterpreter)" "YES"
 $1_$2_CONFIGURE_OPTS += --enable-library-for-ghci
 else
 $1_$2_CONFIGURE_OPTS += --disable-library-for-ghci
 $1_$2_CONFIGURE_OPTS += --enable-library-for-ghci
 else
 $1_$2_CONFIGURE_OPTS += --disable-library-for-ghci
index d829a00..ed81d6d 100644 (file)
@@ -102,19 +102,23 @@ endif
 # Build the GHCi library
 ifeq "$3" "v"
 $1_$2_GHCI_LIB = $1/$2/build/HS$$($1_PACKAGE)-$$($1_$2_VERSION).$$($3_osuf)
 # Build the GHCi library
 ifeq "$3" "v"
 $1_$2_GHCI_LIB = $1/$2/build/HS$$($1_PACKAGE)-$$($1_$2_VERSION).$$($3_osuf)
+ifeq "$$($1_$2_BUILD_GHCI_LIB)" "YES"
 # Don't put bootstrapping packages in the bindist
 ifneq "$4" "0"
 # Don't put bootstrapping packages in the bindist
 ifneq "$4" "0"
-ifeq "$$(UseArchivesForGhci)" "NO"
 BINDIST_LIBS += $$($1_$2_GHCI_LIB)
 endif
 endif
 $$($1_$2_GHCI_LIB) : $$($1_$2_$3_HS_OBJS) $$($1_$2_$3_CMM_OBJS) $$($1_$2_$3_C_OBJS) $$($1_$2_$3_S_OBJS) $$($1_$2_EXTRA_OBJS)
        "$$(LD)" -r -o $$@ $$(EXTRA_LD_OPTS) $$($1_$2_$3_HS_OBJS) $$($1_$2_$3_CMM_OBJS) $$($1_$2_$3_C_OBJS) $$($1_$2_$3_S_OBJS) `$$($1_$2_$3_MKSTUBOBJS)` $$($1_$2_EXTRA_OBJS)
 
 BINDIST_LIBS += $$($1_$2_GHCI_LIB)
 endif
 endif
 $$($1_$2_GHCI_LIB) : $$($1_$2_$3_HS_OBJS) $$($1_$2_$3_CMM_OBJS) $$($1_$2_$3_C_OBJS) $$($1_$2_$3_S_OBJS) $$($1_$2_EXTRA_OBJS)
        "$$(LD)" -r -o $$@ $$(EXTRA_LD_OPTS) $$($1_$2_$3_HS_OBJS) $$($1_$2_$3_CMM_OBJS) $$($1_$2_$3_C_OBJS) $$($1_$2_$3_S_OBJS) `$$($1_$2_$3_MKSTUBOBJS)` $$($1_$2_EXTRA_OBJS)
 
-ifeq "$$(UseArchivesForGhci)" "NO"
+ifeq "$$($1_$2_BUILD_GHCI_LIB)" "YES"
+# Don't bother making ghci libs for bootstrapping packages
+ifneq "$4" "0"
+# $$(info Here $1 $2 $$($1_$2_BUILD_GHCI_LIB) Q1)
 $(call all-target,$1_$2,$$($1_$2_GHCI_LIB))
 endif
 endif
 $(call all-target,$1_$2,$$($1_$2_GHCI_LIB))
 endif
 endif
+endif
 
 endef
 
 
 endef
 
index cce40c5..81b47db 100644 (file)
@@ -372,7 +372,8 @@ generate config_args distdir directory
                 variablePrefix ++ "_DEP_CC_OPTS = "    ++ unwords (forDeps Installed.ccOptions),
                 variablePrefix ++ "_DEP_LIB_DIRS = "   ++ unwords (wrap $ forDeps Installed.libraryDirs),
                 variablePrefix ++ "_DEP_EXTRA_LIBS = " ++ unwords (forDeps Installed.extraLibraries),
                 variablePrefix ++ "_DEP_CC_OPTS = "    ++ unwords (forDeps Installed.ccOptions),
                 variablePrefix ++ "_DEP_LIB_DIRS = "   ++ unwords (wrap $ forDeps Installed.libraryDirs),
                 variablePrefix ++ "_DEP_EXTRA_LIBS = " ++ unwords (forDeps Installed.extraLibraries),
-                variablePrefix ++ "_DEP_LD_OPTS = "    ++ unwords (forDeps Installed.ldOptions)]
+                variablePrefix ++ "_DEP_LD_OPTS = "    ++ unwords (forDeps Installed.ldOptions),
+                variablePrefix ++ "_BUILD_GHCI_LIB = " ++ boolToYesNo (withGHCiLib lbi)]
       writeFile (distdir ++ "/package-data.mk") $ unlines xs
       writeFile (distdir ++ "/haddock-prologue.txt") $ 
           if null (description pd) then synopsis pd
       writeFile (distdir ++ "/package-data.mk") $ unlines xs
       writeFile (distdir ++ "/haddock-prologue.txt") $ 
           if null (description pd) then synopsis pd
@@ -380,3 +381,5 @@ generate config_args distdir directory
   where
      escape = foldr (\c xs -> if c == '#' then '\\':'#':xs else c:xs) []
      wrap = map (\s -> "\'" ++ s ++ "\'")
   where
      escape = foldr (\c xs -> if c == '#' then '\\':'#':xs else c:xs) []
      wrap = map (\s -> "\'" ++ s ++ "\'")
+     boolToYesNo True = "YES"
+     boolToYesNo False = "NO"