Ticket #8974: ghc-w64-llvm34_v2.patch

File ghc-w64-llvm34_v2.patch, 4.7 KB (added by awson, 5 years ago)
  • ghc/compiler/llvmGen/LlvmCodeGen/Data.hs

    diff -urN a/ghc/compiler/llvmGen/LlvmCodeGen/Data.hs b/ghc/compiler/llvmGen/LlvmCodeGen/Data.hs
    a b  
    1414import BlockId
    1515import CLabel
    1616import Cmm
     17import Platform
    1718
    1819import FastString
    1920import qualified Outputable
     
    118119    var1 <- genStaticLit (CmmLabel l1)
    119120    var2 <- genStaticLit (CmmLabel l2)
    120121    let var = LMSub var1 var2
    121         offset = LMStaticLit $ LMIntLit (toInteger off) (llvmWord dflags)
    122     return $ LMAdd var offset
     122        word = llvmWord dflags
     123        offset = LMStaticLit $ LMIntLit (toInteger off) word
     124        res = LMAdd var offset
     125    platform <- getLlvmPlatform
     126    case platform of
     127      -- #8974. Windows PEi386 can't handle 64-bit relocs.
     128      -- So we insert magic (GUID) string member right before
     129      -- the struct member we want to rewrite and padding
     130      -- 32-bit 0 after it.
     131      -- Later the mangler will remove this magic number and
     132      -- rewrite next member from ".quad" to ".long".
     133      --
     134      -- I first tried to not use any magic and to convert
     135      -- 64-bit pointers to 32-bit integers directly
     136      -- replacing LMPtoI p (LMInt 64) with LMPtoI p (LMInt 32)
     137      -- but thus LLVM-emitted assembly is inconstistent with
     138      -- changes the mangler introduce after.
     139      Platform { platformArch = ArchX86_64, platformOS = OSMinGW32 }
     140        -> let
     141             magicTy = LMArray 37 (LMInt 8)
     142             magic = LMStaticStr (mkFastString "5a7d765f-89a1-406a-ad4b-87ca8e3d6723") magicTy
     143             i32ty = LMInt 32
     144             pad = LMStaticLit (LMIntLit 0 i32ty)
     145           in return $ LMStaticStruc [magic, res, pad] $ LMStruct [magicTy, word, i32ty]
     146      _ -> return res
    123147
    124148genStaticLit (CmmBlock b) = genStaticLit $ CmmLabel $ infoTblLbl b
    125149
  • ghc/compiler/llvmGen/LlvmCodeGen/Ppr.hs

    diff -urN a/ghc/compiler/llvmGen/LlvmCodeGen/Ppr.hs b/ghc/compiler/llvmGen/LlvmCodeGen/Ppr.hs
    a b  
    4949    Platform { platformArch = ArchX86_64, platformOS = OSLinux } ->
    5050        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-s0:64:64-f80:128:128-n8:16:32:64\""
    5151        $+$ text "target triple = \"x86_64-linux-gnu\""
     52    Platform { platformArch = ArchX86_64, platformOS = OSMinGW32 } ->
     53        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-s0:64:64-f80:128:128-n8:16:32:64-S128\""
     54        $+$ text "target triple = \"x86_64-w64-mingw32\"" -- 3.4. For 3.5svn we need 'windows-gnu' instead of 'mingw32' here.
    5255    Platform { platformArch = ArchARM {}, platformOS = OSLinux } ->
    5356        text "target datalayout = \"e-p:32:32:32-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:64:128-a0:0:64-n32\""
    5457        $+$ text "target triple = \"arm-unknown-linux-gnueabi\""
  • ghc/compiler/llvmGen/LlvmMangler.hs

    diff -urN a/ghc/compiler/llvmGen/LlvmMangler.hs b/ghc/compiler/llvmGen/LlvmMangler.hs
    a b  
    77
    88module LlvmMangler ( llvmFixupAsm ) where
    99
    10 import DynFlags ( DynFlags )
     10import DynFlags ( DynFlags, targetPlatform )
    1111import ErrUtils ( showPass )
    1212import LlvmCodeGen.Ppr ( infoSection )
     13import Platform
    1314
    1415import Control.Exception
    1516import Control.Monad ( when )
     
    5152    w <- openBinaryFile f2 WriteMode
    5253    ss <- readSections r w
    5354    hClose r
    54     let fixed = (map rewriteAVX . fixTables) ss
     55    let
     56      fixPtrCast =
     57        case targetPlatform dflags of
     58          Platform { platformArch = ArchX86_64, platformOS = OSMinGW32 } -> map rewritePtrCast
     59          _ -> id
     60      fixed = (fixPtrCast . map rewriteAVX . fixTables) ss
    5561    mapM_ (writeSection w) fixed
    5662    hClose w
    5763    return ()
     
    102108    B.hPutStrLn w hdr
    103109  B.hPutStrLn w cts
    104110
     111-- We don't guard this function with any platform-dependent
     112-- ifdefs because we anticipate future dynamic selection
     113-- of compilation target
     114rewritePtrCast :: Section -> Section
     115rewritePtrCast (hdr, cts) = (hdr, replace magic_plus_p_quad p_long cts)
     116  where
     117    magic_plus_p_quad, p_long :: B.ByteString
     118    magic_plus_p_quad = B.pack "\t.asciz\t\"5a7d765f-89a1-406a-ad4b-87ca8e3d6723\"\r\n\t.quad"
     119    p_long = B.pack "\t.long"
     120
    105121#if REWRITE_AVX
    106122rewriteAVX :: Section -> Section
    107123rewriteAVX = rewriteVmovaps . rewriteVmovdqa