[Git][ghc/ghc][wip/hadrian-cross-stage2] 3 commits: Remove cross predicates
Matthew Pickering (@mpickering)
gitlab at gitlab.haskell.org
Mon Sep 25 10:25:21 UTC 2023
Matthew Pickering pushed to branch wip/hadrian-cross-stage2 at Glasgow Haskell Compiler / GHC
Commits:
79c4201d by Matthew Pickering at 2023-09-25T11:07:31+01:00
Remove cross predicates
- - - - -
70ae71d6 by Matthew Pickering at 2023-09-25T11:24:43+01:00
Propagate some more Stage0 variables to host file
- - - - -
a8b1774c by Matthew Pickering at 2023-09-25T11:24:51+01:00
clean
- - - - -
12 changed files:
- configure.ac
- hadrian/cfg/default.host.target.in
- hadrian/src/Expression.hs
- hadrian/src/Flavour.hs
- hadrian/src/Oracles/Setting.hs
- hadrian/src/Packages.hs
- hadrian/src/Rules/BinaryDist.hs
- hadrian/src/Rules/CabalReinstall.hs
- hadrian/src/Rules/Program.hs
- hadrian/src/Settings/Builders/Hsc2Hs.hs
- hadrian/src/Settings/Flavours/Performance.hs
- m4/prep_target_file.m4
Changes:
=====================================
configure.ac
=====================================
@@ -233,6 +233,13 @@ if test "$WithGhc" != ""; then
BOOTSTRAPPING_GHC_INFO_FIELD([SUPPORT_SMP_STAGE0],[Support SMP])
BOOTSTRAPPING_GHC_INFO_FIELD([RTS_WAYS_STAGE0],[RTS ways])
+
+ BOOTSTRAPPING_GHC_INFO_FIELD([LdHasNoCompactUnwind_STAGE0],[ld supports compact unwind])
+ BOOTSTRAPPING_GHC_INFO_FIELD([LdIsGNULd_STAGE0],[ld is GNU ld])
+ BOOTSTRAPPING_GHC_INFO_FIELD([LdHasFilelist_STAGE0],[ld supports filelist])
+
+ BOOTSTRAPPING_GHC_INFO_FIELD([CONF_GCC_SUPPORTS_NO_PIE_STAGE0],[C compiler supports -no-pie])
+
dnl Check whether or not the bootstrapping GHC has a threaded RTS. This
dnl determines whether or not we can have a threaded stage 1.
dnl See Note [Linking ghc-bin against threaded stage0 RTS] in
=====================================
hadrian/cfg/default.host.target.in
=====================================
@@ -18,10 +18,10 @@ Target
, tgtHsCPreprocessor = HsCpp {hsCppProgram = Program {prgPath = "@CC_STAGE0@", prgFlags = @HaskellCPPArgsList@}}
, tgtCCompilerLink = CcLink
{ ccLinkProgram = Program {prgPath = "@CC_STAGE0@", prgFlags = @CONF_GCC_LINKER_OPTS_STAGE0List@}
-, ccLinkSupportsNoPie = False
-, ccLinkSupportsCompactUnwind = False
-, ccLinkSupportsFilelist = False
-, ccLinkIsGnu = False
+, ccLinkSupportsNoPie = @CONF_GCC_SUPPORTS_NO_PIE_STAGE0Bool@
+, ccLinkSupportsCompactUnwind = @LdHasNoCompactUnwind_STAGE0Bool@
+, ccLinkSupportsFilelist = @LdHasFilelist_STAGE0Bool@
+, ccLinkIsGnu = @LdIsGNULd_STAGE0Bool@
}
, tgtAr = Ar
=====================================
hadrian/src/Expression.hs
=====================================
@@ -10,7 +10,7 @@ module Expression (
-- ** Predicates
(?), stage, stage0, stage1, stage2, notStage0, buildingCompilerStage,
buildingCompilerStage', threadedBootstrapper,
- package, notPackage, packageOneOf, cross, notCross,
+ package, notPackage, packageOneOf,
libraryPackage, builder, way, input, inputs, output, outputs,
-- ** Evaluation
@@ -163,11 +163,3 @@ cabalFlag pred flagName = do
ifM (toPredicate pred) (arg flagName) (arg $ "-"<>flagName)
infixr 3 `cabalFlag`
-
-
--- MP: Delete this
-cross :: Predicate
-cross = expr (flag CrossCompiling)
-
-notCross :: Predicate
-notCross = notM cross
=====================================
hadrian/src/Flavour.hs
=====================================
@@ -162,7 +162,7 @@ enableDebugInfo = addArgs $ notStage0 ? mconcat
-- | Enable the ticky-ticky profiler in stage2 GHC
enableTickyGhc :: Flavour -> Flavour
enableTickyGhc f =
- (addArgs (orM [stage1, cross] ? mconcat
+ (addArgs (stage1 ? mconcat
[ builder (Ghc CompileHs) ? tickyArgs
, builder (Ghc LinkHs) ? tickyArgs
]) f) { ghcThreaded = (< Stage2) }
=====================================
hadrian/src/Oracles/Setting.hs
=====================================
@@ -22,8 +22,6 @@ import Hadrian.Oracles.TextFile
import Hadrian.Oracles.Path
import Control.Monad.Trans (lift)
import Control.Monad.Trans.Maybe (runMaybeT)
-import Debug.Trace
-import GHC.Stack
import Base
@@ -264,11 +262,10 @@ queryTarget s f = expr (f <$> targetStage s)
queryTargetTarget :: Stage -> (Target -> a) -> Action a
queryTargetTarget s f = f <$> targetStage s
--- | Whether the StageN compiler is a cross-compiler or not.
-crossStage :: HasCallStack => Stage -> Action Bool
+-- | A 'Stage' is a cross-stage if the produced compiler is a cross-compiler.
+crossStage :: Stage -> Action Bool
crossStage st = do
st_target <- targetStage (succStage st)
st_host <- targetStage st
- traceShowM (targetPlatformTriple st_target, targetPlatformTriple st_host, st)
return (targetPlatformTriple st_target /= targetPlatformTriple st_host)
=====================================
hadrian/src/Packages.hs
=====================================
@@ -25,7 +25,6 @@ import Hadrian.Utilities
import Base
import Context
-import Oracles.Flag
import Oracles.Setting
import GHC.Toolchain.Target (targetPlatformTriple)
=====================================
hadrian/src/Rules/BinaryDist.hs
=====================================
@@ -126,14 +126,35 @@ installTo relocatable prefix = do
runBuilderWithCmdOptions env (Make bindistFilesDir) ["install"] [] []
-buildBinDistDir :: FilePath -> Stage -> Stage -> Action ()
-buildBinDistDir root library_stage executable_stage = do
+data BindistConfig = BindistConfig { library_stage :: Stage -- ^ The stage compiler which builds the libraries
+ , executable_stage :: Stage -- ^ The stage compiler which builds the executables
+ }
+
+-- | A bindist for when the host = target, non cross-compilation setting.
+-- Both the libraries and final executables are built with stage1 compiler.
+normalBindist :: BindistConfig
+normalBindist = BindistConfig { library_stage = Stage1, executable_stage = Stage1 }
+
+-- | A bindist which contains a cross compiler (when host /= target)
+-- The cross compiler is produced by the stage1 compiler, but then we must compile
+-- all the boot libraries with the cross compiler (hence stage2 for libraries)
+crossBindist :: BindistConfig
+crossBindist = BindistConfig { library_stage = Stage2, executable_stage = Stage1 }
+
+-- | A bindist which contains executables for the target, which produce code for the
+-- target. These are produced as "Stage3" build products, produced by a stage2 cross compiler.
+targetBindist :: BindistConfig
+targetBindist = BindistConfig { library_stage = Stage2, executable_stage = Stage2 }
+
+
+buildBinDistDir :: FilePath -> BindistConfig -> Action ()
+buildBinDistDir root conf at BindistConfig{..} = do
-- We 'need' all binaries and libraries
lib_pkgs <- stagePackages library_stage
- (lib_targets, _) <- partitionEithers <$> mapM (pkgTarget library_stage executable_stage) lib_pkgs
+ (lib_targets, _) <- partitionEithers <$> mapM (pkgTarget conf) lib_pkgs
bin_pkgs <- stagePackages executable_stage
- (_, bin_targets) <- partitionEithers <$> mapM (pkgTarget library_stage executable_stage) bin_pkgs
+ (_, bin_targets) <- partitionEithers <$> mapM (pkgTarget conf) bin_pkgs
liftIO $ print (library_stage, executable_stage, lib_targets, bin_targets)
@@ -301,9 +322,16 @@ bindistRules = do
installPrefix <- fromMaybe (error prefixErr) <$> cmdPrefix
installTo NotRelocatable installPrefix
- phony "binary-dist-dir" $ buildBinDistDir root Stage1 Stage1
- phony "binary-dist-cross" $ buildBinDistDir root Stage2 Stage1
- phony "binary-dist-dir-stage3" $ buildBinDistDir root Stage2 Stage2
+ phony "binary-dist-dir" $ do
+ -- A "normal" bindist doesn't make sense when cross compiled because there would be
+ -- libraries built for the host, but the distributed compiler would produce files for
+ -- the target.
+ cross <- flag CrossCompiling
+ if cross
+ then need ["binary-dist-dir-cross"]
+ else buildBinDistDir root normalBindist
+ phony "binary-dist-dir-cross" $ buildBinDistDir root crossBindist
+ phony "binary-dist-dir-stage3" $ buildBinDistDir root targetBindist
let buildBinDist compressor = do
win_target <- isWinTarget Stage2
@@ -411,8 +439,8 @@ bindistInstallFiles =
-- for all libraries and programs that are needed for a complete build.
-- For libraries, it returns the path to the @.conf@ file in the package
-- database. For programs, it returns the path to the compiled executable.
-pkgTarget :: Stage -> Stage -> Package -> Action (Either FilePath (Package, FilePath))
-pkgTarget library_stage executable_stage pkg
+pkgTarget :: BindistConfig -> Package -> Action (Either FilePath (Package, FilePath))
+pkgTarget BindistConfig{..} pkg
| isLibrary pkg = Left <$> pkgConfFile (vanillaContext library_stage pkg)
| otherwise = do
path <- programPath =<< programContext executable_stage pkg
=====================================
hadrian/src/Rules/CabalReinstall.hs
=====================================
@@ -48,7 +48,7 @@ cabalBuildRules = do
priority 2.0 $ root -/- "stage-cabal" -/- "bin" -/- ".stamp" %> \stamp -> do
-- We 'need' all binaries and libraries
all_pkgs <- stagePackages Stage1
- (lib_targets, bin_targets) <- partitionEithers <$> mapM (pkgTarget Stage1 Stage1) all_pkgs
+ (lib_targets, bin_targets) <- partitionEithers <$> mapM (pkgTarget normalBindist) all_pkgs
cross <- flag CrossCompiling
iserv_targets <- if cross then pure [] else iservBins
need (lib_targets ++ (map (\(_, p) -> p) (bin_targets ++ iserv_targets)))
=====================================
hadrian/src/Rules/Program.hs
=====================================
@@ -100,11 +100,8 @@ buildProgram bin ctx@(Context{..}) rs = do
registerPackages =<< contextDependencies ctx
cross <- flag CrossCompiling
- -- For cross compiler, copy @stage0/bin/<pgm>@ to @stage1/bin/@.
case (cross, stage) of
- --(True, s) | s > stage0InTree -> do
- -- srcDir <- buildRoot <&> (-/- (stageString stage0InTree -/- "bin"))
- -- copyFile (srcDir -/- takeFileName bin) bin
+ -- MP: Why do we copy these? Seems like we should just build them again.
(False, s) | s > stage0InTree && (package `elem` [touchy, unlit]) -> do
srcDir <- stageLibPath stage0InTree <&> (-/- "bin")
copyFile (srcDir -/- takeFileName bin) bin
=====================================
hadrian/src/Settings/Builders/Hsc2Hs.hs
=====================================
@@ -24,11 +24,11 @@ hsc2hsBuilderArgs = builder Hsc2Hs ? do
tmpl <- (top -/-) <$> expr (templateHscPath stage0Boot)
mconcat [ arg $ "--cc=" ++ ccPath
, arg $ "--ld=" ++ ccPath
- , notM (isWinTarget stage) ? notM (flag CrossCompiling) ? arg "--cross-safe"
+ , notM (isWinTarget stage) ? notM (crossStage stage) ? arg "--cross-safe"
, pure $ map ("-I" ++) (words gmpDir)
, map ("--cflag=" ++) <$> getCFlags
, map ("--lflag=" ++) <$> getLFlags
- , notStage0 ? flag CrossCompiling ? arg "--cross-compile"
+ , notStage0 ? crossStage stage ? arg "--cross-compile"
, stage0 ? arg ("--cflag=-D" ++ hArch ++ "_HOST_ARCH=1")
, stage0 ? arg ("--cflag=-D" ++ hOs ++ "_HOST_OS=1" )
, notStage0 ? arg ("--cflag=-D" ++ tArch ++ "_HOST_ARCH=1")
@@ -42,7 +42,7 @@ hsc2hsBuilderArgs = builder Hsc2Hs ? do
-- they are constant and end up as constants in the assembly.
-- See #12849
-- MP: Wrong use of CrossCompiling
- , flag CrossCompiling ? isWinTarget stage ? arg "--via-asm"
+ , crossStage stage ? isWinTarget stage ? arg "--via-asm"
, arg =<< getInput
, arg "-o", arg =<< getOutput ]
=====================================
hadrian/src/Settings/Flavours/Performance.hs
=====================================
@@ -13,10 +13,10 @@ performanceFlavour = splitSections $ defaultFlavour
performanceArgs :: Args
performanceArgs = sourceArgs SourceArgs
{ hsDefault = pure ["-O", "-H64m"]
- , hsLibrary = orM [notStage0, cross] ? arg "-O2"
+ , hsLibrary = notStage0 ? arg "-O2"
, hsCompiler = pure ["-O2"]
, hsGhc = mconcat
- [ andM [stage0, notCross] ? arg "-O"
- , orM [notStage0, cross] ? arg "-O2"
+ [ stage0 ? arg "-O"
+ , notStage0 ? arg "-O2"
]
}
=====================================
m4/prep_target_file.m4
=====================================
@@ -160,6 +160,11 @@ AC_DEFUN([PREP_TARGET_FILE],[
PREP_LIST([CONF_CXX_OPTS_STAGE0])
PREP_LIST([CONF_GCC_LINKER_OPTS_STAGE0])
+ PREP_BOOLEAN([LdHasNoCompactUnwind_STAGE0])
+ PREP_BOOLEAN([LdIsGNULd_STAGE0])
+ PREP_BOOLEAN([LdHasFilelist_STAGE0])
+ PREP_BOOLEAN([CONF_GCC_SUPPORTS_NO_PIE_STAGE0])
+
if test -z "$MergeObjsCmd"; then
MergeObjsCmdMaybe=Nothing
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/1a90b7be89b1f29d0f050190e9f1276975fcb46b...a8b1774c446d8dab3e7d96729fd195a000cf03dc
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/1a90b7be89b1f29d0f050190e9f1276975fcb46b...a8b1774c446d8dab3e7d96729fd195a000cf03dc
You're receiving this email because of your account on gitlab.haskell.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20230925/7a687070/attachment-0001.html>
More information about the ghc-commits
mailing list