By default, use the dynamic way for programs in the GHC tree
authorIan Lynagh <ian@well-typed.com>
Wed, 13 Mar 2013 21:29:27 +0000 (21:29 +0000)
committerIan Lynagh <ian@well-typed.com>
Fri, 15 Mar 2013 00:49:49 +0000 (00:49 +0000)
In particular, this means that GHCi will use DLLs, rather than loading
object files itself.

14 files changed:
compiler/ghc.mk
compiler/ghci/Linker.lhs
compiler/main/DynFlags.hs
compiler/utils/Util.lhs
ghc.mk
mk/build.mk.sample
mk/config.mk.in
mk/validate-settings.mk
rts/Linker.c
rts/ghc.mk
rules/build-package-data.mk
rules/build-package-way.mk
rules/build-prog.mk
rules/shell-wrapper.mk

index 0c68d6d..54d828b 100644 (file)
@@ -111,6 +111,12 @@ ifeq "$(UseLibFFIForAdjustors)" "YES"
 else
        @echo 'cLibFFI               = False'                               >> $@
 endif
+       @echo 'cDYNAMIC_GHC_PROGRAMS :: Bool'                               >> $@
+ifeq "$(DYNAMIC_GHC_PROGRAMS)" "YES"
+       @echo 'cDYNAMIC_GHC_PROGRAMS = True'                                >> $@
+else
+       @echo 'cDYNAMIC_GHC_PROGRAMS = False'                               >> $@
+endif
        @echo done.
 
 # -----------------------------------------------------------------------------
@@ -483,6 +489,10 @@ $(foreach way,$(compiler_stage3_WAYS),\
 # switch off the recompilation checker for that module:
 compiler/prelude/PrimOp_HC_OPTS  += -fforce-recomp
 
+ifeq "$(DYNAMIC_GHC_PROGRAMS)" "YES"
+compiler/utils/Util_HC_OPTS += -DDYNAMIC_GHC_PROGRAMS
+endif
+
 # LibFFI.hs #includes ffi.h
 ifneq "$(UseSystemLibFFI)" "YES"
 compiler/stage2/build/LibFFI.hs : $(libffi_HEADERS)
index 151c5cb..3d568ea 100644 (file)
@@ -414,14 +414,14 @@ preloadLib dflags lib_paths framework_paths lib_spec
     preload_static _paths name
        = do b <- doesFileExist name
             if not b then return False
-                     else do if dYNAMIC_BY_DEFAULT dflags
+                     else do if cDYNAMIC_GHC_PROGRAMS
                                  then dynLoadObjs dflags [name]
                                  else loadObj name
                              return True
     preload_static_archive _paths name
        = do b <- doesFileExist name
             if not b then return False
-                     else do if dYNAMIC_BY_DEFAULT dflags
+                     else do if cDYNAMIC_GHC_PROGRAMS
                                  then panic "Loading archives not supported"
                                  else loadArchive name
                              return True
@@ -485,9 +485,8 @@ dieWith dflags span msg = throwGhcExceptionIO (ProgramError (showSDoc dflags (mk
 checkNonStdWay :: DynFlags -> SrcSpan -> IO Bool
 checkNonStdWay dflags srcspan = do
   let tag = buildTag dflags
-      dynamicByDefault = dYNAMIC_BY_DEFAULT dflags
-  if (null tag && not dynamicByDefault) ||
-     (tag == "dyn" && dynamicByDefault)
+  if (null tag && not cDYNAMIC_GHC_PROGRAMS) ||
+     (tag == "dyn" && cDYNAMIC_GHC_PROGRAMS)
       then return False
     -- see #3604: object files compiled for way "dyn" need to link to the
     -- dynamic packages, so we can't load them into a statically-linked GHCi.
@@ -638,10 +637,9 @@ getLinkDeps hsc_env hpt pls replace_osuf span mods
                 let file_base = reverse (drop (length osuf + 1) (reverse file))
                     dyn_file = file_base <.> "dyn_o"
                     new_file = file_base <.> normalObjectSuffix
-                -- Note that even if dYNAMIC_BY_DEFAULT is on, we might
-                -- still have dynamic object files called .o, so we need
-                -- to try both filenames.
-                use_dyn <- if dYNAMIC_BY_DEFAULT dflags
+                -- When looking for dynamic object files, we try both
+                -- .dyn_o and .o, with a preference for the former.
+                use_dyn <- if cDYNAMIC_GHC_PROGRAMS
                            then do doesFileExist dyn_file
                            else return False
                 if use_dyn
@@ -790,7 +788,7 @@ dynLinkObjs dflags pls objs = do
             unlinkeds                = concatMap linkableUnlinked new_objs
             wanted_objs              = map nameOfObject unlinkeds
 
-        if dYNAMIC_BY_DEFAULT dflags
+        if cDYNAMIC_GHC_PROGRAMS
             then do dynLoadObjs dflags wanted_objs
                     return (pls, Succeeded)
             else do mapM_ loadObj wanted_objs
@@ -1185,7 +1183,7 @@ locateLib dflags is_hs dirs lib
     --
   = findDll `orElse` findArchive `orElse` tryGcc `orElse` assumeDll
 
-  | not isDynamicGhcLib
+  | not cDYNAMIC_GHC_PROGRAMS
     -- 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.
@@ -1194,13 +1192,11 @@ locateLib dflags is_hs dirs lib
   | otherwise
     -- When the GHC package was compiled as dynamic library (=DYNAMIC set),
     -- we search for .so libraries first.
-  = findHSDll `orElse` findDynObject `orElse` findDynArchive `orElse`
-                       findObject    `orElse` findArchive `orElse` assumeDll
+  = findHSDll `orElse` findDynObject `orElse` assumeDll
    where
      mk_obj_path      dir = dir </> (lib <.> "o")
      mk_dyn_obj_path  dir = dir </> (lib <.> "dyn_o")
      mk_arch_path     dir = dir </> ("lib" ++ lib <.> "a")
-     mk_dyn_arch_path dir = dir </> ("lib" ++ lib <.> "dyn_a")
 
      hs_dyn_lib_name = lib ++ "-ghc" ++ cProjectVersion
      mk_hs_dyn_lib_path dir = dir </> mkSOName platform hs_dyn_lib_name
@@ -1209,10 +1205,8 @@ locateLib dflags is_hs dirs lib
      mk_dyn_lib_path dir = dir </> so_name
 
      findObject     = liftM (fmap Object)  $ findFile mk_obj_path        dirs
-     findDynObject  = do putStrLn "In findDynObject"
-                         liftM (fmap Object)  $ findFile mk_dyn_obj_path    dirs
+     findDynObject  = liftM (fmap Object)  $ findFile mk_dyn_obj_path    dirs
      findArchive    = liftM (fmap Archive) $ findFile mk_arch_path       dirs
-     findDynArchive = liftM (fmap Archive) $ findFile mk_dyn_arch_path   dirs
      findHSDll      = liftM (fmap DLLPath) $ findFile mk_hs_dyn_lib_path dirs
      findDll        = liftM (fmap DLLPath) $ findFile mk_dyn_lib_path    dirs
      tryGcc         = liftM (fmap DLLPath) $ searchForLibUsingGcc dflags so_name dirs
index 162568c..876d2ea 100644 (file)
@@ -3344,6 +3344,8 @@ compilerInfo dflags
        ("RTS ways",                    cGhcRTSWays),
        ("Dynamic by default",          if dYNAMIC_BY_DEFAULT dflags
                                        then "YES" else "NO"),
+       ("GHC Dynamic",                 if cDYNAMIC_GHC_PROGRAMS
+                                       then "YES" else "NO"),
        ("Leading underscore",          cLeadingUnderscore),
        ("Debug on",                    show debugIsOn),
        ("LibDir",                      topDir dflags),
index f9927de..90a2077 100644 (file)
@@ -9,7 +9,7 @@
 module Util (
         -- * Flags dependent on the compiler build
         ghciSupported, debugIsOn, ncgDebugIsOn,
-        ghciTablesNextToCode, isDynamicGhcLib,
+        ghciTablesNextToCode,
         isWindowsHost, isDarwinHost,
 
         -- * General list processing
@@ -179,13 +179,6 @@ ghciTablesNextToCode = True
 ghciTablesNextToCode = False
 #endif
 
-isDynamicGhcLib :: Bool
-#ifdef DYNAMIC
-isDynamicGhcLib = True
-#else
-isDynamicGhcLib = False
-#endif
-
 isWindowsHost :: Bool
 #ifdef mingw32_HOST_OS
 isWindowsHost = True
diff --git a/ghc.mk b/ghc.mk
index 6d0b379..5843d81 100644 (file)
--- a/ghc.mk
+++ b/ghc.mk
@@ -128,13 +128,13 @@ include mk/ways.mk
 include mk/custom-settings.mk
 
 ifeq "$(findstring clean,$(MAKECMDGOALS))" ""
-ifeq "$(DYNAMIC_BY_DEFAULT)" "YES"
+ifeq "$(DYNAMIC_GHC_PROGRAMS)" "YES"
 ifeq "$(findstring dyn,$(GhcLibWays))" ""
-$(error dyn is not in $$(GhcLibWays), but $$(DYNAMIC_BY_DEFAULT) is YES)
+$(error dyn is not in $$(GhcLibWays), but $$(DYNAMIC_GHC_PROGRAMS) is YES)
 endif
 else
 ifeq "$(findstring v,$(GhcLibWays))" ""
-$(error v is not in $$(GhcLibWays), and $$(DYNAMIC_BY_DEFAULT) is not YES)
+$(error v is not in $$(GhcLibWays), and $$(DYNAMIC_GHC_PROGRAMS) is not YES)
 endif
 endif
 ifeq "$(GhcProfiled)" "YES"
@@ -196,7 +196,7 @@ include rules/way-prelims.mk
 $(foreach way,$(ALL_WAYS),\
   $(eval $(call way-prelims,$(way))))
 
-ifeq "$(DYNAMIC_BY_DEFAULT)" "YES"
+ifeq "$(DYNAMIC_GHC_PROGRAMS)" "YES"
 GHCI_WAY = dyn
 HADDOCK_WAY = dyn
 else
@@ -438,7 +438,7 @@ SUPERSIZE_INSTALL_PACKAGES += $(addprefix libraries/,$(PACKAGES_STAGE2))
 INSTALL_DYNLIBS  :=
 ifeq "$(InstallExtraPackages)" "NO"
 INSTALL_PACKAGES := $(REGULAR_INSTALL_PACKAGES)
-ifeq "$(DYNAMIC_BY_DEFAULT)" "YES"
+ifeq "$(DYNAMIC_GHC_PROGRAMS)" "YES"
 INSTALL_DYNLIBS := $(REGULAR_INSTALL_DYNLIBS)
 endif
 else
@@ -1260,7 +1260,7 @@ bootstrapping-files: $(libffi_HEADERS)
 ifeq "$(HADDOCK_DOCS)" "YES"
 BINDIST_HADDOCK_FLAG = --with-haddock="$(BINDIST_PREFIX)/bin/haddock"
 endif
-ifeq "$(DYNAMIC_BY_DEFAULT)" "YES"
+ifeq "$(DYNAMIC_GHC_PROGRAMS)" "YES"
 BINDIST_LIBRARY_FLAGS = --enable-shared --disable-library-vanilla
 else
 BINDIST_LIBRARY_FLAGS = --enable-library-vanilla --disable-shared
index e055b49..338eefb 100644 (file)
@@ -33,7 +33,7 @@
 # A development build, working on the stage 2 compiler:
 #BuildFlavour = devel2
 
-GhcLibWays = $(if $(filter $(DYNAMIC_BY_DEFAULT),YES),dyn,v)
+GhcLibWays = $(if $(filter $(DYNAMIC_GHC_PROGRAMS),YES),dyn,v)
 
 # Uncomment this to get prettier build output.
 # Please use V = 1 when reporting GHC bugs.
index 7409e40..a69541a 100644 (file)
@@ -124,8 +124,15 @@ endif
 # cabal-install's that are in the wild don't handle it properly.
 DYNAMIC_BY_DEFAULT = NO
 
+# If building both v and dyn ways, then use -dynamic-too to build them.
+# This makes the build faster.
 DYNAMIC_TOO = YES
 
+# Use the dynamic way when building programs in the GHC tree. In
+# particular, this means that GHCi will use DLLs rather than loading
+# object files directly.
+DYNAMIC_GHC_PROGRAMS = YES
+
 # Build a compiler that will build *unregisterised* libraries and
 # binaries by default.  Unregisterised code is supposed to compile and
 # run without any support for architecture-specific assembly mangling,
@@ -168,7 +175,7 @@ ArchSupportsGHCi=$(strip $(patsubst $(TargetArch_CPP), YES, $(findstring $(Targe
 ifeq "$(OsSupportsGHCi)$(ArchSupportsGHCi)" "YESYES"
 GhcWithInterpreter=YES
 else 
-GhcWithInterpreter=$(if $(findstring YES,$(DYNAMIC_BY_DEFAULT)),YES,NO)
+GhcWithInterpreter=$(if $(findstring YES,$(DYNAMIC_GHC_PROGRAMS)),YES,NO)
 endif
 
 # GhcEnableTablesNextToCode tells us whether the target architecture
index e2f66f2..f6370e9 100644 (file)
@@ -37,8 +37,8 @@ GhcStage2HcOpts += -O -dcore-lint
 GhcLibHcOpts    += -O -dcore-lint
 
 # We define DefaultFastGhcLibWays in this style so that the value is
-# correct even if the user alters DYNAMIC_BY_DEFAULT
-DefaultFastGhcLibWays = $(if $(filter $(DYNAMIC_BY_DEFAULT),YES),dyn,v)
+# correct even if the user alters DYNAMIC_GHC_PROGRAMS
+DefaultFastGhcLibWays = $(if $(filter $(DYNAMIC_GHC_PROGRAMS),YES),dyn,v)
 DefaultProfGhcLibWays = $(if $(filter $(GhcProfiled),YES),p,)
 
 ifeq "$(ValidateSpeed)" "FAST"
index cf4f350..db27c3f 100644 (file)
 // warnings like
 //    error: function might be possible candidate for attribute ‘noreturn’
 // from gcc:
-#ifdef DYNAMIC_BY_DEFAULT
-int dynamicByDefault = 1;
+#ifdef DYNAMIC_GHC_PROGRAMS
+int dynamicGhcPrograms = 1;
 #else
-int dynamicByDefault = 0;
+int dynamicGhcPrograms = 0;
 #endif
 
 /* Hash table mapping symbol names to Symbol */
@@ -2116,8 +2116,8 @@ loadArchive( pathchar *path )
     IF_DEBUG(linker, debugBelch("loadArchive: start\n"));
     IF_DEBUG(linker, debugBelch("loadArchive: Loading archive `%" PATH_FMT" '\n", path));
 
-    if (dynamicByDefault) {
-        barf("loadArchive called, but using dynlibs by default (%s)", path);
+    if (dynamicGhcPrograms) {
+        barf("loadArchive called, but using dynamic GHC (%s)", path);
     }
 
     gnuFileIndex = NULL;
@@ -2511,8 +2511,8 @@ loadObj( pathchar *path )
 #endif
    IF_DEBUG(linker, debugBelch("loadObj %" PATH_FMT "\n", path));
 
-   if (dynamicByDefault) {
-       barf("loadObj called, but using dynlibs by default (%s)", path);
+   if (dynamicGhcPrograms) {
+       barf("loadObj called, but using dynamic GHC (%s)", path);
    }
 
    initLinker();
index 3dc3990..09c2874 100644 (file)
@@ -329,8 +329,8 @@ rts/RtsUtils_CC_OPTS += -DTargetVendor=\"$(TargetVendor_CPP)\"
 rts/RtsUtils_CC_OPTS += -DGhcUnregisterised=\"$(GhcUnregisterised)\"
 rts/RtsUtils_CC_OPTS += -DGhcEnableTablesNextToCode=\"$(GhcEnableTablesNextToCode)\"
 
-ifeq "$(DYNAMIC_BY_DEFAULT)" "YES"
-rts/Linker_CC_OPTS += -DDYNAMIC_BY_DEFAULT
+ifeq "$(DYNAMIC_GHC_PROGRAMS)" "YES"
+rts/Linker_CC_OPTS += -DDYNAMIC_GHC_PROGRAMS
 endif
 
 # Compile various performance-critical pieces *without* -fPIC -dynamic
index bcd863f..cf67baf 100644 (file)
@@ -22,7 +22,7 @@ $1_$2_CONFIGURE_OPTS += --disable-library-for-ghci
 ifeq "$$(filter v,$$($1_$2_WAYS))" "v"
 $1_$2_CONFIGURE_OPTS += --enable-library-vanilla
 ifeq "$$(GhcWithInterpreter)" "YES"
-ifneq "$$(DYNAMIC_BY_DEFAULT)" "YES"
+ifneq "$$(DYNAMIC_GHC_PROGRAMS)" "YES"
 $1_$2_CONFIGURE_OPTS += --enable-library-for-ghci
 endif
 endif
index 8a0dc64..bae73e3 100644 (file)
@@ -119,7 +119,7 @@ BINDIST_LIBS += $$($1_$2_$3_LIB0)
 endif
 
 # Build the GHCi library
-ifeq "$$(DYNAMIC_BY_DEFAULT)" "YES"
+ifeq "$$(DYNAMIC_GHC_PROGRAMS)" "YES"
 $1_$2_GHCI_LIB = $$($1_$2_dyn_LIB)
 else
 ifeq "$3" "v"
index 5973159..81f2ef2 100644 (file)
@@ -64,7 +64,7 @@ else ifneq "$$($1_$2_INSTALL_INPLACE)" "YES"
 $1_$2_WANT_INPLACE_WRAPPER = NO
 else ifeq "$$($1_$2_SHELL_WRAPPER)" "YES"
 $1_$2_WANT_INPLACE_WRAPPER = YES
-else ifeq "$$(DYNAMIC_BY_DEFAULT)" "YES"
+else ifeq "$$(DYNAMIC_GHC_PROGRAMS)" "YES"
 $1_$2_WANT_INPLACE_WRAPPER = YES
 else
 $1_$2_WANT_INPLACE_WRAPPER = NO
@@ -136,7 +136,7 @@ $(call shell-wrapper,$1,$2)
 ifeq "$$($1_$2_PROGRAM_WAY)" ""
 ifeq "$3" "0"
 $1_$2_PROGRAM_WAY = v
-else ifeq "$$(DYNAMIC_BY_DEFAULT)" "YES"
+else ifeq "$$(DYNAMIC_GHC_PROGRAMS)" "YES"
 $1_$2_PROGRAM_WAY = dyn
 else
 $1_$2_PROGRAM_WAY = v
index 687c408..4f6795d 100644 (file)
@@ -44,7 +44,7 @@ $$(INPLACE_WRAPPER): $$($1_$2_INPLACE)
        echo 'pgmgcc="$$(WhatGccIsCalled)"'                                  >> $$@
        $$($1_$2_SHELL_WRAPPER_EXTRA)
        $$($1_$2_INPLACE_SHELL_WRAPPER_EXTRA)
-ifeq "$$(DYNAMIC_BY_DEFAULT)" "YES"
+ifeq "$$(DYNAMIC_GHC_PROGRAMS)" "YES"
        echo '$$(call prependLibraryPath,$$($1_$2_DEP_LIB_DIRS_SEARCHPATH))' >> $$@
 endif
 ifeq "$$($1_$2_SHELL_WRAPPER)" "YES"
@@ -99,7 +99,7 @@ BINDIST_EXTRAS += $$($1_$2_BINDIST_WRAPPER)
 $$($1_$2_BINDIST_WRAPPER): $1/$2/build/tmp/$$($1_$2_PROG)
        $$(call removeFiles,                                                  $$@)
        echo '#!$$(SHELL)'                                                 >> $$@
-ifeq "$$(DYNAMIC_BY_DEFAULT)" "YES"
+ifeq "$$(DYNAMIC_GHC_PROGRAMS)" "YES"
        echo '$$(call prependLibraryPath,$$($1_$2_DEP_LIB_REL_DIRS_SEARCHPATH))' >> $$@
 endif
        echo 'exec "$$<" $$$${1+"$$$$@"}'                                  >> $$@