[commit: ghc] wip/nfs-locking: Work on command lines for compiling stage 2 GHC. (159903e)

git at git.haskell.org git at git.haskell.org
Thu Oct 26 23:23:23 UTC 2017


Repository : ssh://git@git.haskell.org/ghc

On branch  : wip/nfs-locking
Link       : http://ghc.haskell.org/trac/ghc/changeset/159903e948cb8d3497235e4dd2c0f2c1ddde3227/ghc

>---------------------------------------------------------------

commit 159903e948cb8d3497235e4dd2c0f2c1ddde3227
Author: Andrey Mokhov <andrey.mokhov at gmail.com>
Date:   Wed Dec 9 02:00:09 2015 +0000

    Work on command lines for compiling stage 2 GHC.


>---------------------------------------------------------------

159903e948cb8d3497235e4dd2c0f2c1ddde3227
 src/Settings/Builders/Ghc.hs      | 108 +++++++++++++++++++++++++++++++++++++-
 src/Settings/Builders/GhcCabal.hs |  20 ++++---
 2 files changed, 119 insertions(+), 9 deletions(-)

diff --git a/src/Settings/Builders/Ghc.hs b/src/Settings/Builders/Ghc.hs
index 8ab4357..8d1a30f 100644
--- a/src/Settings/Builders/Ghc.hs
+++ b/src/Settings/Builders/Ghc.hs
@@ -1,10 +1,13 @@
-module Settings.Builders.Ghc (ghcArgs, ghcMArgs, commonGhcArgs) where
+module Settings.Builders.Ghc (
+    ghcArgs, ghcMArgs, ghcLinkArgs, commonGhcArgs
+    ) where
 
 import Expression
 import Oracles
 import GHC
 import Predicates (package, stagedBuilder, splitObjects, stage0, notStage0)
 import Settings
+import Settings.Builders.GhcCabal
 
 -- TODO: add support for -dyno
 -- TODO: consider adding a new builder for programs (e.g. GhcLink?)
@@ -17,6 +20,8 @@ ghcArgs = stagedBuilder Ghc ? do
     output <- getOutput
     way    <- getWay
     let buildObj = ("//*." ++ osuf way) ?== output || ("//*." ++ obootsuf way) ?== output
+    libs    <- getPkgDataList DepExtraLibs
+    libDirs <- getPkgDataList DepLibDirs
     mconcat [ commonGhcArgs
             , arg "-H32m"
             , stage0    ? arg "-O"
@@ -25,6 +30,9 @@ ghcArgs = stagedBuilder Ghc ? do
             , arg "-fwarn-tabs"
             , buildObj ? splitObjects ? arg "-split-objs"
             , package ghc ? arg "-no-hs-main"
+            , not buildObj ? arg "-no-auto-link-packages"
+            , not buildObj ? append [ "-optl-l" ++ lib | lib <- libs    ]
+            , not buildObj ? append [ "-optl-L" ++ dir | dir <- libDirs ]
             , buildObj ? arg "-c"
             , append =<< getInputs
             , arg "-o", arg =<< getOutput ]
@@ -116,3 +124,101 @@ includeGhcArgs = do
 -- define libraries/ghc-prim_PACKAGE_MAGIC
 -- libraries/ghc-prim_dist-install_MODULES := $$(filter-out GHC.Prim,$$(libraries/ghc-prim_dist-install_MODULES))
 -- endef
+
+
+-- # Options for passing to plain ld
+-- $1_$2_$3_ALL_LD_OPTS = \
+--  $$(WAY_$3_LD_OPTS) \
+--  $$($1_$2_DIST_LD_OPTS) \
+--  $$($1_$2_$3_LD_OPTS) \
+--  $$($1_$2_EXTRA_LD_OPTS) \
+--  $$(EXTRA_LD_OPTS)
+
+-- # Options for passing to GHC when we use it for linking
+-- $1_$2_$3_GHC_LD_OPTS = \
+--  $$(addprefix -optl, $$($1_$2_$3_ALL_LD_OPTS)) \
+--  $$($1_$2_$3_MOST_HC_OPTS)
+
+-- TODO: add support for TargetElf and darwin
+-- ifeq "$3" "dyn"
+-- ifneq "$4" "0"
+-- ifeq "$$(TargetElf)" "YES"
+-- $1_$2_$3_GHC_LD_OPTS += \
+--     -fno-use-rpaths \
+--     $$(foreach d,$$($1_$2_TRANSITIVE_DEP_LIB_NAMES),-optl-Wl$$(comma)-rpath -optl-Wl$$(comma)'$$$$ORIGIN/../$$d') -optl-Wl,-zorigin
+-- else ifeq "$$(TargetOS_CPP)" "darwin"
+-- $1_$2_$3_GHC_LD_OPTS += \
+--     -fno-use-rpaths \
+--     $$(foreach d,$$($1_$2_TRANSITIVE_DEP_LIB_NAMES),-optl-Wl$$(comma)-rpath -optl-Wl$$(comma)'@loader_path/../$$d')
+
+-- ifeq "$$($1_$2_$$($1_$2_PROGRAM_WAY)_HS_OBJS)" ""
+-- # We don't want to link the GHC RTS into C-only programs. There's no
+-- # point, and it confuses the test that all GHC-compiled programs
+-- # were compiled with the right GHC.
+-- $1_$2_$$($1_$2_PROGRAM_WAY)_GHC_LD_OPTS += -no-auto-link-packages -no-hs-main
+-- endif
+
+ghcLinkArgs :: Args
+ghcLinkArgs = mempty
+    -- way  <- getRtsWays
+    -- path <- getTargetPath
+    -- mconcat [ commonGhcArgs
+    --         , (way == dynamic) ? needDll0Args ?
+    --           arg $ "-dll-split " ++ path -/- "dll-split"
+    --         , appendSubD "-optl" (getSettingList . ConfLdLinkerArgs =<< getStage)
+    --         , appendSubD "-optl-L" (lift $ pkgDataList DepLibDirs)
+    --         , appendSubD "-optl-l" (lift $ pkgDataList DepExtraLibs)
+    --         , splitObjects ? arg "-split-objs"
+    --         , package ghc ? arg "-no-hs-main"
+    --         , append =<< getInputs
+    --         , arg "-o", arg =<< getOutput ]
+
+
+-- # Link a dynamic library
+-- # On windows we have to supply the extra libs this one links to when building it.
+-- ifeq "$$(HostOS_CPP)" "mingw32"
+-- $$($1_$2_$3_LIB) : $$($1_$2_$3_ALL_OBJS) $$(ALL_RTS_LIBS) $$($1_$2_$3_DEPS_LIBS)
+-- ifneq "$$($1_$2_$3_LIB0)" ""
+--     $$(call build-dll,$1,$2,$3,
+--    -L$1/$2/build -l$$($1_$2_$3_LIB0_ROOT),
+--    $$(filter-out $$($1_$2_dll0_HS_OBJS),$$($1_$2_$3_HS_OBJS))
+--    $$($1_$2_$3_NON_HS_OBJS),$$@)
+-- else
+--     $$(call build-dll,$1,$2,$3,,$$($1_$2_$3_HS_OBJS) $$($1_$2_$3_NON_HS_OBJS),$$@)
+-- endif
+
+-- ifneq "$$($1_$2_$3_LIB0)" ""
+-- $$($1_$2_$3_LIB) : $$($1_$2_$3_LIB0)
+-- $$($1_$2_$3_LIB0) : $$($1_$2_$3_ALL_OBJS) $$(ALL_RTS_LIBS) $$($1_$2_$3_DEPS_LIBS)
+--     $$(call build-dll,$1,$2,$3,,$$($1_$2_dll0_HS_OBJS) $$($1_$2_$3_NON_HS_OBJS),$$($1_$2_$3_LIB0))
+-- endif
+
+
+
+-- # $1 = dir
+-- # $2 = distdir
+-- # $3 = way
+-- # $4 = extra flags
+-- # $5 = object files to link
+-- # $6 = output filename
+-- define build-dll
+--     $(call cmd,$1_$2_HC) $($1_$2_$3_ALL_HC_OPTS) $($1_$2_$3_GHC_LD_OPTS) $4 $5 \
+--         -shared -dynamic -dynload deploy \
+--         $(addprefix -l,$($1_$2_EXTRA_LIBRARIES)) \
+--         -no-auto-link-packages \
+--         -o $6
+-- # Now check that the DLL doesn't have too many symbols. See trac #5987.
+--     SYMBOLS=`$(OBJDUMP) -p $6 | sed -n "1,/^.Ordinal\/Name Pointer/ D; p; /^$$/ q" | tail -n +2 | wc -l`; echo "Number of symbols in $6: $$SYMBOLS"
+--     case `$(OBJDUMP) -p $6 | sed -n "1,/^.Ordinal\/Name Pointer/ D; p; /^$$/ q" | grep "\[ *0\]" | wc -l` in 1) echo DLL $6 OK;; 0) echo No symbols in DLL $6; exit 1;; [0-9]*) echo Too many symbols in DLL $6; $(OBJDUMP) -p $6 | sed -n "1,/^.Ordinal\/Name Pointer/ D; p; /^$$/ q" | tail; exit 1;; *) echo bad DLL $6; exit 1;; esac
+-- endef
+
+
+
+-- TODO: add -dynamic-too?
+-- # $1_$2_$3_ALL_HC_OPTS: this is all the options we will pass to GHC
+-- # for a given ($1,$2,$3).
+-- $1_$2_$3_ALL_HC_OPTS = \
+--  -hisuf $$($3_hisuf) -osuf  $$($3_osuf) -hcsuf $$($3_hcsuf) \
+--  $$($1_$2_$3_MOST_DIR_HC_OPTS) \
+--  $$(if $$(findstring YES,$$($1_$2_SplitObjs)),$$(if $$(findstring dyn,$3),,-split-objs),) \
+--  $$(if $$(findstring YES,$$($1_$2_DYNAMIC_TOO)),$$(if $$(findstring v,$3),-dynamic-too))
diff --git a/src/Settings/Builders/GhcCabal.hs b/src/Settings/Builders/GhcCabal.hs
index df4af2b..793a7f7 100644
--- a/src/Settings/Builders/GhcCabal.hs
+++ b/src/Settings/Builders/GhcCabal.hs
@@ -1,6 +1,6 @@
 module Settings.Builders.GhcCabal (
     cabalArgs, ghcCabalHsColourArgs, bootPackageDbArgs, customPackageArgs,
-    ccArgs, cppArgs, ccWarnings, argStagedSettingList
+    ccArgs, cppArgs, ccWarnings, argStagedSettingList, needDll0
     ) where
 
 import Expression
@@ -212,18 +212,22 @@ appendCcArgs xs = do
             , builder GhcCabal   ? appendSub "--configure-option=CFLAGS" xs
             , builder GhcCabal   ? appendSub "--gcc-options" xs ]
 
+needDll0 :: Stage -> Package -> Action Bool
+needDll0 stage pkg = do
+    windows <- windowsHost
+    return $ windows && pkg == compiler && stage == Stage1
+
 -- This is a positional argument, hence:
 -- * if it is empty, we need to emit one empty string argument;
 -- * otherwise, we must collapse it into one space-separated string.
 dll0Args :: Args
 dll0Args = do
-    windows <- lift windowsHost
-    pkg     <- getPackage
-    stage   <- getStage
-    let needDll0Args = windows && pkg == compiler && stage == Stage1
-    ghci    <- lift ghcWithInterpreter
-    arg . unwords . concat $ [ modules     | needDll0Args         ]
-                          ++ [ ghciModules | needDll0Args && ghci ] -- see #9552
+    stage <- getStage
+    pkg   <- getPackage
+    dll0  <- lift $ needDll0 stage pkg
+    ghci  <- lift ghcWithInterpreter
+    arg . unwords . concat $ [ modules     | dll0         ]
+                          ++ [ ghciModules | dll0 && ghci ] -- see #9552
   where
     modules = [ "Annotations"
               , "ApiAnnotation"



More information about the ghc-commits mailing list