LlvmCodeGen cross-compiling fixes (#9895)
authorErik de Castro Lopo <erikd@mega-nerd.com>
Sat, 27 Dec 2014 10:11:52 +0000 (21:11 +1100)
committerErik de Castro Lopo <erikd@mega-nerd.com>
Sun, 28 Dec 2014 23:42:53 +0000 (10:42 +1100)
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

compiler/llvmGen/LlvmCodeGen/Ppr.hs
compiler/main/SysTools.hs
compiler/utils/Platform.hs
settings.in

index ed21685..5dd27ab 100644 (file)
@@ -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
index 7b6c82f..e4520e1 100644 (file)
@@ -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 {
index 39903ea..8f9a8de 100644 (file)
@@ -31,7 +31,8 @@ data Platform
               platformUnregisterised           :: Bool,
               platformHasGnuNonexecStack       :: Bool,
               platformHasIdentDirective        :: Bool,
-              platformHasSubsectionsViaSymbols :: Bool
+              platformHasSubsectionsViaSymbols :: Bool,
+              platformIsCrossCompiling         :: Bool
           }
         deriving (Read, Show, Eq)
 
index 1bcb4ae..e8cdad3 100644 (file)
@@ -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@"),