Commit 58ac9c8f authored by Erik de Castro Lopo's avatar Erik de Castro Lopo

LlvmCodeGen cross-compiling fixes (#9895)

Summary:
* Throw an error when cross-compiling without a target definition.
  When cross compiling via LLVM, a target 'datalayout' and 'triple' must
  be defined or LLVM will generate code for the compile host instead of
  the compile target.

* Add aarch64-unknown-linux-gnu target.
  The datalayout and triple lines were found by using clang to compile a
  small C program and -emit-llvm to get the LLVM IR output.
Signed-off-by: Erik de Castro Lopo's avatarErik de Castro Lopo <erikd@mega-nerd.com>

Test Plan: validate

Reviewers: rwbarton, carter, hvr, bgamari, austin

Reviewed By: austin

Subscribers: carter, thomie, garious

Differential Revision: https://phabricator.haskell.org/D585

GHC Trac Issues: #9895
parent 0cc0cc86
......@@ -68,9 +68,19 @@ moduleLayout = sdocWithPlatform $ \platform ->
Platform { platformArch = ArchARM64, platformOS = OSiOS } ->
text "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-n32:64-S128\""
$+$ text "target triple = \"arm64-apple-ios7.0.0\""
Platform { platformArch = ArchARM64, platformOS = OSLinux } ->
text "target datalayout = \"e-m:e-i64:64-i128:128-n32:64-S128\""
$+$ text "target triple = \"aarch64-unknown-linux-gnu\""
_ ->
-- FIX: Other targets
empty
if platformIsCrossCompiling platform
then panic "LlvmCodeGen.Ppr: Cross compiling without valid target info."
else empty
-- If you see the above panic, GHC is missing the required target datalayout
-- and triple information. You can obtain this info by compiling a simple
-- 'hello world' C program with the clang C compiler eg:
-- clang hello.c -emit-llvm -o hello.ll
-- and the first two lines of hello.ll should provide the 'target datalayout'
-- and 'target triple' lines required.
-- | Pretty print LLVM data code
......
......@@ -221,6 +221,7 @@ initSysTools mbMinusB
Just v -> return v
Nothing -> pgmError ("Failed to read " ++ show key ++ " value " ++ show xs)
Nothing -> pgmError ("No entry for " ++ show key ++ " in " ++ show settingsFile)
crossCompiling <- getBooleanSetting "cross compiling"
targetArch <- readSetting "target arch"
targetOS <- readSetting "target os"
targetWordSize <- readSetting "target word size"
......@@ -309,7 +310,8 @@ initSysTools mbMinusB
platformUnregisterised = targetUnregisterised,
platformHasGnuNonexecStack = targetHasGnuNonexecStack,
platformHasIdentDirective = targetHasIdentDirective,
platformHasSubsectionsViaSymbols = targetHasSubsectionsViaSymbols
platformHasSubsectionsViaSymbols = targetHasSubsectionsViaSymbols,
platformIsCrossCompiling = crossCompiling
}
return $ Settings {
......
......@@ -31,7 +31,8 @@ data Platform
platformUnregisterised :: Bool,
platformHasGnuNonexecStack :: Bool,
platformHasIdentDirective :: Bool,
platformHasSubsectionsViaSymbols :: Bool
platformHasSubsectionsViaSymbols :: Bool,
platformIsCrossCompiling :: Bool
}
deriving (Read, Show, Eq)
......
......@@ -18,6 +18,7 @@
("windres command", "@SettingsWindresCommand@"),
("libtool command", "@SettingsLibtoolCommand@"),
("perl command", "@SettingsPerlCommand@"),
("cross compiling", "@CrossCompiling@"),
("target os", "@HaskellTargetOs@"),
("target arch", "@HaskellTargetArch@"),
("target word size", "@WordSize@"),
......
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