Sven Tennie pushed to branch wip/romes/hadrian-cross-stage2-rebase_SVEN_FIXED at Glasgow Haskell Compiler / GHC Commits: fca890d0 by Sven Tennie at 2025-10-31T13:47:36+01:00 Libffi - no LD for cross host stages - - - - - 2 changed files: - hadrian/src/Oracles/Setting.hs - hadrian/src/Rules/Libffi.hs Changes: ===================================== hadrian/src/Oracles/Setting.hs ===================================== @@ -7,7 +7,7 @@ module Oracles.Setting ( -- * Helpers ghcCanonVersion, cmdLineLengthLimit, targetSupportsRPaths, topDirectory, libsuf, ghcVersionStage, bashPath, targetStage, crossStage, queryTarget, queryTargetTarget, - ghcWithInterpreter, + ghcWithInterpreter, isHostStage, -- ** Target platform things anyTargetOs, anyTargetArch, anyHostOs, @@ -247,10 +247,12 @@ libsuf st way -- Build libraries for this stage targetting this Target -- For example, we want to build RTS with stage1 for the host target as we produce a host executable with stage1 (which cross-compiles to stage2) targetStage :: Stage -> Action Target -targetStage (Stage0 {}) = getHostTarget -targetStage (Stage1 {}) = getHostTarget -targetStage (Stage2 {}) = getTargetTarget -targetStage (Stage3 {}) = getTargetTarget +targetStage stage | isHostStage stage = getHostTarget +targetStage _ = getTargetTarget + +isHostStage :: Stage -> Bool +isHostStage stage | stage <= Stage1 = True +isHostStage _ = False queryTarget :: Stage -> (Target -> a) -> (Expr c b a) queryTarget s f = expr (f <$> targetStage s) @@ -264,4 +266,3 @@ crossStage st = do st_target <- targetStage (succStage st) st_host <- targetStage st return (targetPlatformTriple st_target /= targetPlatformTriple st_host) - ===================================== hadrian/src/Rules/Libffi.hs ===================================== @@ -129,54 +129,21 @@ fixLibffiMakefile top = -- TODO: check code duplication w.r.t. ConfCcArgs configureEnvironment :: Stage -> Action [CmdOption] -configureEnvironment stage@Stage1 = do - -- TODO: This case should not exist: Strip and Objdump should be staged! - context <- libffiContext stage - cFlags <- interpretInContext context $ mconcat - [ cArgs - , getStagedCCFlags ] - ldFlags <- interpretInContext context ldArgs - winTarget <- isWinTarget (succStage stage) - sequence $ [ builderEnvironment "CC" $ Cc CompileC stage - , builderEnvironment "CXX" $ Cc CompileC stage - , builderEnvironment "AR" (Ar Unpack stage) - , builderEnvironment "NM" (Nm stage) - , builderEnvironment "RANLIB" (Ranlib stage) - -- , remBuilderEnvironment "OBJDUMP" - -- , remBuilderEnvironment "STRIP" - , return . AddEnv "CFLAGS" $ unwords cFlags ++ " -w" - , return . AddEnv "LDFLAGS" $ unwords ldFlags ++ " -w" - , return . AddEnv "OBJDUMP" $ "objdump" - , return . AddEnv "STRIP" $ "strip" ] - ++ (if winTarget then - -- TODO: Use staged LD for winTarget. This is only a hack because the wrong staged LD was provided. - [remBuilderEnvironment "LD"] - else - [ -- TODO: This should be the staged LD, but that points to gcc and not ld. With the current gcc as linker config, libffi doesn't build shared libs. - remBuilderEnvironment "LD" - ]) - configureEnvironment stage = do context <- libffiContext stage - cFlags <- interpretInContext context $ mconcat - [ cArgs - , getStagedCCFlags ] - ldFlags <- interpretInContext context ldArgs - winTarget <- isWinTarget stage + cFlags <- interpretInContext context getStagedCCFlags + isCross <- flag CrossCompiling sequence $ [ builderEnvironment "CC" $ Cc CompileC stage - , builderEnvironment "CXX" $ Cc CompileC stage - , builderEnvironment "AR" (Ar Unpack stage) - , builderEnvironment "NM" (Nm stage) - , builderEnvironment "RANLIB" (Ranlib stage) - , return . AddEnv "CFLAGS" $ unwords cFlags ++ " -w" - , return . AddEnv "LDFLAGS" $ unwords ldFlags ++ " -w" ] - ++ (if winTarget then - -- TODO: We should use the staged LD here. Unfortunately, that differs from what's expected via $LD. - [] - else - [ -- TODO: This should be the staged LD, but that points to GCC and not LD. - -- builderEnvironment "LD" (Ld stage) - ]) + , builderEnvironment "CXX" $ Cc CompileC stage + , builderEnvironment "AR" $ Ar Unpack stage + , builderEnvironment "NM" $ Nm stage + , builderEnvironment "RANLIB" $ Ranlib stage + , return . AddEnv "CFLAGS" $ unwords cFlags ++ " -w" + , return . AddEnv "LDFLAGS" $ "-w" ] ++ + -- When we're building a cross-compiler, we have to be careful + -- which environment variables are propagated for the non-target + -- stages. + (if isHostStage stage && isCross then [remBuilderEnvironment "LD"] else []) -- Need the libffi archive and `trackAllow` all files in the build directory. -- See [Libffi indicating inputs]. View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/fca890d0913f6b5e60d91fe34bd4f788... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/fca890d0913f6b5e60d91fe34bd4f788... You're receiving this email because of your account on gitlab.haskell.org.