Commit 11fcb10a authored by dterei's avatar dterei

Fix #5636: Use clang as assembler on OSX when LLVM >= 3.0

LLVM doesn't support the OS X system assembler anymore so we must use
their assembler through clang. Also improved error messages when various
LLVM tools can't be run.
parent f7d99de6
......@@ -1172,7 +1172,21 @@ runPhase SplitMangle input_fn dflags
runPhase As input_fn dflags
= do
let as_opts = getOpts dflags opt_a
-- LLVM from version 3.0 onwards doesn't support the OS X system
-- assembler, so we use clang as the assembler instead. (#5636)
let whichAsProg | hscTarget dflags == HscLlvm &&
platformOS (targetPlatform dflags) == OSDarwin
= do
llvmVer <- io $ figureLlvmVersion dflags
return $ case llvmVer of
Just n | n >= 30 -> SysTools.runClang
_ -> SysTools.runAs
| otherwise
= return SysTools.runAs
as_prog <- whichAsProg
let as_opts = getOpts dflags opt_a
let cmdline_include_paths = includePaths dflags
next_phase <- maybeMergeStub
......@@ -1182,7 +1196,7 @@ runPhase As input_fn dflags
-- might be a hierarchical module.
io $ createDirectoryHierarchy (takeDirectory output_fn)
io $ SysTools.runAs dflags
io $ as_prog dflags
(map SysTools.Option as_opts
++ [ SysTools.Option ("-I" ++ p) | p <- cmdline_include_paths ]
......
......@@ -448,6 +448,7 @@ data DynFlags = DynFlags {
ghcMode :: GhcMode,
ghcLink :: GhcLink,
hscTarget :: HscTarget,
settings :: Settings,
hscOutName :: String, -- ^ Name of the output file
extCoreName :: String, -- ^ Name of the .hcr output file
verbosity :: Int, -- ^ Verbosity level: see Note [Verbosity levels]
......@@ -518,8 +519,6 @@ data DynFlags = DynFlags {
pluginModNames :: [ModuleName],
pluginModNameOpts :: [(ModuleName,String)],
settings :: Settings,
-- For ghc -M
depMakefile :: FilePath,
depIncludePkgDeps :: Bool,
......
......@@ -21,6 +21,7 @@ module SysTools (
runWindres,
runLlvmOpt,
runLlvmLlc,
runClang,
figureLlvmVersion,
readElfSection,
......@@ -473,6 +474,22 @@ runLlvmLlc dflags args = do
let (p,args0) = pgm_lc dflags
runSomething dflags "LLVM Compiler" p (args0++args)
-- | Run the clang compiler (used as an assembler for the LLVM
-- backend on OS X as LLVM doesn't support the OS X system
-- assembler)
runClang :: DynFlags -> [Option] -> IO ()
runClang dflags args = do
-- we simply assume its available on the PATH
let clang = "clang"
Exception.catch (do
runSomething dflags "Clang (Assembler)" clang args
)
(\(err :: SomeException) -> do
putMsg dflags $ text $ "Error running clang! you need clang installed"
++ " to use the LLVM backend"
throw err
)
-- | Figure out which version of LLVM we are running this session
figureLlvmVersion :: DynFlags -> IO (Maybe Int)
figureLlvmVersion dflags = do
......@@ -504,9 +521,13 @@ figureLlvmVersion dflags = do
return $ Just v
)
(\err -> do
putMsg dflags $ text $ "Error (" ++ show err ++ ")"
putMsg dflags $ text "Warning: Couldn't figure out LLVM version!"
putMsg dflags $ text "Make sure you have installed LLVM"
debugTraceMsg dflags 2
(text "Error (figuring out LLVM version):" <+>
text (show err))
putMsg dflags $ vcat
[ text "Warning:", nest 9 $
text "Couldn't figure out LLVM version!" $$
text "Make sure you have installed LLVM"]
return Nothing)
return ver
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment