diff options
| author | Erik de Castro Lopo <erikd@mega-nerd.com> | 2014-12-27 21:11:52 +1100 |
|---|---|---|
| committer | Erik de Castro Lopo <erikd@mega-nerd.com> | 2014-12-29 10:42:53 +1100 |
| commit | 58ac9c8f6e986bac817ad08d5a2fd11cd167f029 (patch) | |
| tree | 3a8889d2ae51f3301629f29fddfb1b43c01dc861 | |
| parent | 0cc0cc8688ddb53db65a73d7d562e9564cfad22b (diff) | |
| download | haskell-58ac9c8f6e986bac817ad08d5a2fd11cd167f029.tar.gz | |
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@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
| -rw-r--r-- | compiler/llvmGen/LlvmCodeGen/Ppr.hs | 14 | ||||
| -rw-r--r-- | compiler/main/SysTools.hs | 4 | ||||
| -rw-r--r-- | compiler/utils/Platform.hs | 3 | ||||
| -rw-r--r-- | 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 ed21685b55..5dd27ab33b 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 7b6c82f2d9..e4520e1f29 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 39903eacb3..8f9a8debad 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 1bcb4aebc9..e8cdad34f8 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@"), |
