Skip to content

lib:Cabal - do not use GHC to configure LD. #10970

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions Cabal/src/Distribution/Simple/GHC.hs
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,10 @@ configure verbosity hcPath hcPkgPath conf0 = do
, compilerProperties = ghcInfoMap
}
compPlatform = Internal.targetPlatform ghcInfo
-- configure gcc and ld
progdb4 = Internal.configureToolchain implInfo ghcProg ghcInfoMap progdb3
-- configure gcc and ld
-- similarly to how we need ghc above, we need to know the c compiler
-- generally named `gcc` in cabal, to configure other programs, e.g. ld.
progdb4 <- Internal.configureToolchain verbosity implInfo ghcProg ghcInfoMap progdb3
return (comp, compPlatform, progdb4)

-- | Given something like /usr/local/bin/ghc-6.6.1(.exe) we try and find
Expand Down
82 changes: 46 additions & 36 deletions Cabal/src/Distribution/Simple/GHC/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -100,37 +100,48 @@ targetPlatform ghcInfo = platformFromTriple =<< lookup "Target platform" ghcInfo

-- | Adjust the way we find and configure gcc and ld
configureToolchain
:: GhcImplInfo
:: Verbosity
-> GhcImplInfo
-> ConfiguredProgram
-> Map String String
-> ProgramDb
-> ProgramDb
configureToolchain _implInfo ghcProg ghcInfo =
addKnownProgram
gccProgram
{ programFindLocation = findProg gccProgramName extraGccPath
, programPostConf = configureGcc
}
. addKnownProgram
gppProgram
{ programFindLocation = findProg gppProgramName extraGppPath
, programPostConf = configureGpp
}
. addKnownProgram
ldProgram
{ programFindLocation = findProg ldProgramName extraLdPath
, programPostConf = \v cp ->
-- Call any existing configuration first and then add any new configuration
configureLd v =<< programPostConf ldProgram v cp
}
. addKnownProgram
arProgram
{ programFindLocation = findProg arProgramName extraArPath
}
. addKnownProgram
stripProgram
{ programFindLocation = findProg stripProgramName extraStripPath
}
-> IO ProgramDb
configureToolchain verbosity0 _implInfo ghcProg ghcInfo db = do
-- this is a bit of a hack. We have a dependency of ld on gcc.
-- ld needs to compile a c program, to check an ld feature.
-- we _could_ use ghc as a c frontend, but we do not pass all
-- of the db stack appropriately, and thus we can run into situations
-- where GHC will fail if it's stricter in its wired-in-unit
-- selction and has the wrong db stack. However we don't need
-- ghc to compile a _test_ c program. So we configure `gcc`
-- first and then use `gcc` (the generic c compiler in cabal
-- terminology) to compile the test program.
let db' =
flip addKnownProgram db $
gccProgram
{ programFindLocation = findProg gccProgramName extraGccPath
, programPostConf = configureGcc
}
(gccProg, db'') <- requireProgram verbosity0 gccProgram db'
return $
flip addKnownPrograms db'' $
[ gppProgram
{ programFindLocation = findProg gppProgramName extraGppPath
, programPostConf = configureGpp
}
, ldProgram
{ programFindLocation = findProg ldProgramName extraLdPath
, programPostConf = \v cp ->
-- Call any existing configuration first and then add any new configuration
configureLd gccProg v =<< programPostConf ldProgram v cp
}
, arProgram
{ programFindLocation = findProg arProgramName extraArPath
}
, stripProgram
{ programFindLocation = findProg stripProgramName extraStripPath
}
]
where
compilerDir, base_dir, mingwBinDir :: FilePath
compilerDir = takeDirectory (programPath ghcProg)
Expand Down Expand Up @@ -230,27 +241,26 @@ configureToolchain _implInfo ghcProg ghcInfo =
++ cxxFlags
}

configureLd :: Verbosity -> ConfiguredProgram -> IO ConfiguredProgram
configureLd v ldProg = do
ldProg' <- configureLd' v ldProg
configureLd :: ConfiguredProgram -> Verbosity -> ConfiguredProgram -> IO ConfiguredProgram
configureLd gccProg v ldProg = do
ldProg' <- configureLd' gccProg v ldProg
return
ldProg'
{ programDefaultArgs = programDefaultArgs ldProg' ++ ldLinkerFlags
}

-- we need to find out if ld supports the -x flag
configureLd' :: Verbosity -> ConfiguredProgram -> IO ConfiguredProgram
configureLd' verbosity ldProg = do
configureLd' :: ConfiguredProgram -> Verbosity -> ConfiguredProgram -> IO ConfiguredProgram
configureLd' gccProg verbosity ldProg = do
ldx <- withTempFile ".c" $ \testcfile testchnd ->
withTempFile ".o" $ \testofile testohnd -> do
hPutStrLn testchnd "int foo() { return 0; }"
hClose testchnd
hClose testohnd
runProgram
verbosity
ghcProg
[ "-hide-all-packages"
, "-c"
gccProg
[ "-c"
, testcfile
, "-o"
, testofile
Expand Down
Loading