[commit: ghc] master: LlvmCodeGen cross-compiling fixes (#9895) (58ac9c8)
git at git.haskell.org
git at git.haskell.org
Mon Dec 29 00:23:11 UTC 2014
Repository : ssh://git@git.haskell.org/ghc
On branch : master
Link : http://ghc.haskell.org/trac/ghc/changeset/58ac9c8f6e986bac817ad08d5a2fd11cd167f029/ghc
>---------------------------------------------------------------
commit 58ac9c8f6e986bac817ad08d5a2fd11cd167f029
Author: Erik de Castro Lopo <erikd at mega-nerd.com>
Date: Sat Dec 27 21:11:52 2014 +1100
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 <erikd at 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
>---------------------------------------------------------------
58ac9c8f6e986bac817ad08d5a2fd11cd167f029
compiler/llvmGen/LlvmCodeGen/Ppr.hs | 14 ++++++++++++--
compiler/main/SysTools.hs | 4 +++-
compiler/utils/Platform.hs | 3 ++-
settings.in | 1 +
4 files changed, 18 insertions(+), 4 deletions(-)
diff --git a/compiler/llvmGen/LlvmCodeGen/Ppr.hs b/compiler/llvmGen/LlvmCodeGen/Ppr.hs
index ed21685..5dd27ab 100644
--- a/compiler/llvmGen/LlvmCodeGen/Ppr.hs
+++ b/compiler/llvmGen/LlvmCodeGen/Ppr.hs
@@ -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
diff --git a/compiler/main/SysTools.hs b/compiler/main/SysTools.hs
index 7b6c82f..e4520e1 100644
--- a/compiler/main/SysTools.hs
+++ b/compiler/main/SysTools.hs
@@ -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 {
diff --git a/compiler/utils/Platform.hs b/compiler/utils/Platform.hs
index 39903ea..8f9a8de 100644
--- a/compiler/utils/Platform.hs
+++ b/compiler/utils/Platform.hs
@@ -31,7 +31,8 @@ data Platform
platformUnregisterised :: Bool,
platformHasGnuNonexecStack :: Bool,
platformHasIdentDirective :: Bool,
- platformHasSubsectionsViaSymbols :: Bool
+ platformHasSubsectionsViaSymbols :: Bool,
+ platformIsCrossCompiling :: Bool
}
deriving (Read, Show, Eq)
diff --git a/settings.in b/settings.in
index 1bcb4ae..e8cdad3 100644
--- a/settings.in
+++ b/settings.in
@@ -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@"),
More information about the ghc-commits
mailing list