|
| 1 | +diff --git a/compiler/nativeGen/AsmCodeGen.hs b/compiler/nativeGen/AsmCodeGen.hs |
| 2 | +index 7357273..196acc8 100644 |
| 3 | +--- a/compiler/nativeGen/AsmCodeGen.hs |
| 4 | ++++ b/compiler/nativeGen/AsmCodeGen.hs |
| 5 | +@@ -321,6 +321,13 @@ nativeCodeGen' dflags this_mod modLoc ncgImpl h us cmms |
| 6 | + -- Pretty if it weren't for the fact that we do lots of little |
| 7 | + -- printDocs here (in order to do codegen in constant space). |
| 8 | + bufh <- newBufHandle h |
| 9 | ++ let Module _u nm = this_mod |
| 10 | ++ -- emit file prolue. Including file meta inforamtion. e.g. The |
| 11 | ++ -- current name of the compile file. This may show up during linking, |
| 12 | ++ -- and thus having the proper file name is essential. |
| 13 | ++ _ <- emitNativeCode dflags bufh $ |
| 14 | ++ text "\t.file \"" <> ftext (moduleNameFS nm) <> text ".hs\"" |
| 15 | ++ |
| 16 | + let ngs0 = NGS [] [] [] [] [] [] emptyUFM mapEmpty |
| 17 | + (ngs, us', a) <- cmmNativeGenStream dflags this_mod modLoc ncgImpl bufh us |
| 18 | + cmms ngs0 |
| 19 | +diff --git a/compiler/nativeGen/PIC.hs b/compiler/nativeGen/PIC.hs |
| 20 | +index 7ea68e1..af8cba2 100644 |
| 21 | +--- a/compiler/nativeGen/PIC.hs |
| 22 | ++++ b/compiler/nativeGen/PIC.hs |
| 23 | +@@ -156,10 +156,17 @@ cmmMakeDynamicReference dflags referenceKind lbl |
| 24 | + cmmMakePicReference :: DynFlags -> CLabel -> CmmExpr |
| 25 | + cmmMakePicReference dflags lbl |
| 26 | + |
| 27 | +- -- Windows doesn't need PIC, |
| 28 | +- -- everything gets relocated at runtime |
| 29 | ++ -- Windows used to be absolute 32bit only (small code model) |
| 30 | ++ -- however with ASLR, and high entropy base images, we assume |
| 31 | ++ -- everything to be RIP relative. This basically for windows |
| 32 | ++ -- we want always PIC relative addressing. |
| 33 | + | OSMinGW32 <- platformOS $ targetPlatform dflags |
| 34 | +- = CmmLit $ CmmLabel lbl |
| 35 | ++ = CmmMachOp (MO_Add (wordWidth dflags)) |
| 36 | ++ [ CmmReg (CmmGlobal PicBaseReg) |
| 37 | ++ , CmmLit $ picRelative dflags |
| 38 | ++ (platformArch $ targetPlatform dflags) |
| 39 | ++ (platformOS $ targetPlatform dflags) |
| 40 | ++ lbl ] |
| 41 | + |
| 42 | + | OSAIX <- platformOS $ targetPlatform dflags |
| 43 | + = CmmMachOp (MO_Add W32) |
| 44 | +@@ -453,6 +460,8 @@ picRelative _ arch os lbl |
| 45 | + |
| 46 | + in result |
| 47 | + |
| 48 | ++picRelative _ ArchX86_64 OSMinGW32 lbl = CmmLabel lbl |
| 49 | ++ |
| 50 | + picRelative _ _ _ _ |
| 51 | + = panic "PositionIndependentCode.picRelative undefined for this platform" |
| 52 | + |
| 53 | +diff --git a/compiler/nativeGen/X86/CodeGen.hs b/compiler/nativeGen/X86/CodeGen.hs |
| 54 | +index e319931..3909a23 100644 |
| 55 | +--- a/compiler/nativeGen/X86/CodeGen.hs |
| 56 | ++++ b/compiler/nativeGen/X86/CodeGen.hs |
| 57 | +@@ -343,6 +343,13 @@ stmtToInstrs bid stmt = do |
| 58 | + lbl <- mkAsmTempLabel <$> getUniqueM |
| 59 | + return $ unitOL $ UNWIND lbl tbl |
| 60 | + |
| 61 | ++ CmmAssign reg src@(CmmLit lit) |
| 62 | ++ | isFloatType ty -> assignReg_FltCode format reg src |
| 63 | ++ | is32Bit && isWord64 ty -> assignReg_I64Code reg src |
| 64 | ++ | otherwise -> assignReg_IntCode format reg src |
| 65 | ++ where ty = cmmRegType dflags reg |
| 66 | ++ format = cmmTypeFormat ty |
| 67 | ++ |
| 68 | + CmmAssign reg src |
| 69 | + | isFloatType ty -> assignReg_FltCode format reg src |
| 70 | + | is32Bit && isWord64 ty -> assignReg_I64Code reg src |
| 71 | +@@ -350,6 +357,13 @@ stmtToInstrs bid stmt = do |
| 72 | + where ty = cmmRegType dflags reg |
| 73 | + format = cmmTypeFormat ty |
| 74 | + |
| 75 | ++ CmmStore addr src@(CmmLit lit) |
| 76 | ++ | isFloatType ty -> assignMem_FltCode format addr src |
| 77 | ++ | is32Bit && isWord64 ty -> assignMem_I64Code addr src |
| 78 | ++ | otherwise -> assignMem_IntCode format addr src |
| 79 | ++ where ty = cmmExprType dflags src |
| 80 | ++ format = cmmTypeFormat ty |
| 81 | ++ |
| 82 | + CmmStore addr src |
| 83 | + | isFloatType ty -> assignMem_FltCode format addr src |
| 84 | + | is32Bit && isWord64 ty -> assignMem_I64Code addr src |
| 85 | +@@ -3409,7 +3423,12 @@ outOfLineCmmOp bid mop res args |
| 86 | + genSwitch :: DynFlags -> CmmExpr -> SwitchTargets -> NatM InstrBlock |
| 87 | + |
| 88 | + genSwitch dflags expr targets |
| 89 | +- | positionIndependent dflags |
| 90 | ++ -- Windows is a bit odd. It's virtually PIC on x86_64, by preference of |
| 91 | ++ -- %rip relative addressing to produce the appropriate IMAGE relative |
| 92 | ++ -- relocations. Absolute relocations start to fail with binutils switching |
| 93 | ++ -- to default to high entropy ASLR and dynamic base. For most things, we can |
| 94 | ++ -- simply consider Windows to be PIC on x86_64. |
| 95 | ++ | positionIndependent dflags || (platformOS $ targetPlatform dflags) == OSMinGW32 |
| 96 | + = do |
| 97 | + (reg,e_code) <- getNonClobberedReg (cmmOffset dflags expr offset) |
| 98 | + -- getNonClobberedReg because it needs to survive across t_code |
0 commit comments