|
| 1 | +Submodule libraries/Cabal contains modified content |
| 2 | +diff --git a/libraries/Cabal/Cabal/src/Distribution/Simple/Program/Ld.hs b/libraries/Cabal/Cabal/src/Distribution/Simple/Program/Ld.hs |
| 3 | +index 68b5a391a..f4979bf5f 100644 |
| 4 | +--- a/libraries/Cabal/Cabal/src/Distribution/Simple/Program/Ld.hs |
| 5 | ++++ b/libraries/Cabal/Cabal/src/Distribution/Simple/Program/Ld.hs |
| 6 | +@@ -21,7 +21,7 @@ import Distribution.Compat.Prelude |
| 7 | + import Distribution.Simple.Compiler (arResponseFilesSupported) |
| 8 | + import Distribution.Simple.LocalBuildInfo (LocalBuildInfo(..)) |
| 9 | + import Distribution.Simple.Program.ResponseFile |
| 10 | +- ( withResponseFile ) |
| 11 | ++ ( withResponseFile, withLinkerScript ) |
| 12 | + import Distribution.Simple.Program.Run |
| 13 | + ( ProgramInvocation, programInvocation, multiStageProgramInvocation |
| 14 | + , runProgramInvocation ) |
| 15 | +@@ -31,6 +31,8 @@ import Distribution.Simple.Setup |
| 16 | + ( fromFlagOrDefault, configUseResponseFiles ) |
| 17 | + import Distribution.Simple.Utils |
| 18 | + ( defaultTempFileOptions ) |
| 19 | ++import Distribution.System |
| 20 | ++ ( OS(..), Platform(..) ) |
| 21 | + import Distribution.Verbosity |
| 22 | + ( Verbosity ) |
| 23 | + |
| 24 | +@@ -50,7 +52,71 @@ combineObjectFiles verbosity lbi ld target files = do |
| 25 | + -- have a slight problem. What we have to do is link files in batches into |
| 26 | + -- a temp object file and then include that one in the next batch. |
| 27 | + |
| 28 | +- let simpleArgs = ["-r", "-o", target] |
| 29 | ++ let linkerScriptELF = unlines $ |
| 30 | ++ [ "/* Linker script to undo -split-sections and merge all sections together when " |
| 31 | ++ , " * linking relocatable object files for GHCi. " |
| 32 | ++ , " * ld -r normally retains the individual sections, which is what you would want " |
| 33 | ++ , " * if the intention is to eventually link into a binary with --gc-sections, but " |
| 34 | ++ , " * it doesn't have a flag for directly doing what we want. */ " |
| 35 | ++ , "SECTIONS " |
| 36 | ++ , "{ " |
| 37 | ++ , " .text : { " |
| 38 | ++ , " *(.text*) " |
| 39 | ++ , " } " |
| 40 | ++ , " .rodata.cst16 : { " |
| 41 | ++ , " *(.rodata.cst16*) " |
| 42 | ++ , " } " |
| 43 | ++ , " .rodata : { " |
| 44 | ++ , " *(.rodata*) " |
| 45 | ++ , " } " |
| 46 | ++ , " .data.rel.ro : { " |
| 47 | ++ , " *(.data.rel.ro*) " |
| 48 | ++ , " } " |
| 49 | ++ , " .data : { " |
| 50 | ++ , " *(.data*) " |
| 51 | ++ , " } " |
| 52 | ++ , " .bss : { " |
| 53 | ++ , " *(.bss*) " |
| 54 | ++ , " } " |
| 55 | ++ , "} " |
| 56 | ++ ] |
| 57 | ++ |
| 58 | ++ linkerScriptPE = unlines $ |
| 59 | ++ [ "/* Linker script to undo -split-sections and merge all sections together when " |
| 60 | ++ , " * linking relocatable object files for GHCi. " |
| 61 | ++ , " * ld -r normally retains the individual sections, which is what you would want " |
| 62 | ++ , " * if the intention is to eventually link into a binary with --gc-sections, but " |
| 63 | ++ , " * it doesn't have a flag for directly doing what we want. */ " |
| 64 | ++ , "SECTIONS " |
| 65 | ++ , "{ " |
| 66 | ++ , " .text : { " |
| 67 | ++ , " *(.text$*) " |
| 68 | ++ , " } " |
| 69 | ++ , " .rdata : { " |
| 70 | ++ , " *(.rdata$*) " |
| 71 | ++ , " } " |
| 72 | ++ , " .data : { " |
| 73 | ++ , " *(.data$*) " |
| 74 | ++ , " } " |
| 75 | ++ , " .pdata : { " |
| 76 | ++ , " *(.pdata$*) " |
| 77 | ++ , " } " |
| 78 | ++ , " .xdata : { " |
| 79 | ++ , " *(.xdata$*) " |
| 80 | ++ , " } " |
| 81 | ++ , " .bss : { " |
| 82 | ++ , " *(.bss$*) " |
| 83 | ++ , " } " |
| 84 | ++ , "} " |
| 85 | ++ ] |
| 86 | ++ linkerScript = case hostOS of |
| 87 | ++ Windows -> linkerScriptPE |
| 88 | ++ _ -> linkerScriptELF |
| 89 | ++ linkerScriptArgs = case hostOS of |
| 90 | ++ Windows -> [] |
| 91 | ++ _ -> ["-T"] |
| 92 | ++ |
| 93 | ++ simpleArgs = ["-r", "-o", target] |
| 94 | + |
| 95 | + initialArgs = ["-r", "-o", target] |
| 96 | + middleArgs = ["-r", "-o", target, tmpfile] |
| 97 | +@@ -63,9 +129,9 @@ combineObjectFiles verbosity lbi ld target files = do |
| 98 | + |
| 99 | + targetDir = takeDirectory target |
| 100 | + |
| 101 | +- invokeWithResponesFile :: FilePath -> ProgramInvocation |
| 102 | +- invokeWithResponesFile atFile = |
| 103 | +- programInvocation ld $ simpleArgs ++ ['@' : atFile] |
| 104 | ++ invokeWithLinkerScriptAndResponesFile :: FilePath -> FilePath -> ProgramInvocation |
| 105 | ++ invokeWithLinkerScriptAndResponesFile script atFile = |
| 106 | ++ programInvocation ld $ simpleArgs ++ linkerScriptArgs ++ [ script, '@' : atFile] |
| 107 | + |
| 108 | + oldVersionManualOverride = |
| 109 | + fromFlagOrDefault False $ configUseResponseFiles $ configFlags lbi |
| 110 | +@@ -78,10 +144,13 @@ combineObjectFiles verbosity lbi ld target files = do |
| 111 | + then |
| 112 | + run $ multiStageProgramInvocation simple (initial, middle, final) files |
| 113 | + else |
| 114 | +- withResponseFile verbosity defaultTempFileOptions targetDir "ld.rsp" Nothing files $ |
| 115 | +- \path -> runProgramInvocation verbosity $ invokeWithResponesFile path |
| 116 | ++ withLinkerScript verbosity defaultTempFileOptions targetDir "merge_sections.ld" Nothing linkerScript $ |
| 117 | ++ \scriptPath -> withResponseFile verbosity defaultTempFileOptions targetDir "ld.rsp" Nothing files $ |
| 118 | ++ \path -> runProgramInvocation verbosity $ invokeWithLinkerScriptAndResponesFile scriptPath path |
| 119 | + |
| 120 | + where |
| 121 | ++ Platform _hostArch hostOS = hostPlatform lbi |
| 122 | ++ |
| 123 | + tmpfile = target <.> "tmp" -- perhaps should use a proper temp file |
| 124 | + |
| 125 | + run :: [ProgramInvocation] -> IO () |
| 126 | +diff --git a/libraries/Cabal/Cabal/src/Distribution/Simple/Program/ResponseFile.hs b/libraries/Cabal/Cabal/src/Distribution/Simple/Program/ResponseFile.hs |
| 127 | +index e5ef41412..3b038e6b1 100644 |
| 128 | +--- a/libraries/Cabal/Cabal/src/Distribution/Simple/Program/ResponseFile.hs |
| 129 | ++++ b/libraries/Cabal/Cabal/src/Distribution/Simple/Program/ResponseFile.hs |
| 130 | +@@ -10,7 +10,7 @@ |
| 131 | + -- Created : 23 July 2017 |
| 132 | + ---------------------------------------------------------------------------- |
| 133 | + |
| 134 | +-module Distribution.Simple.Program.ResponseFile (withResponseFile) where |
| 135 | ++module Distribution.Simple.Program.ResponseFile (withResponseFile, withLinkerScript) where |
| 136 | + |
| 137 | + import Prelude () |
| 138 | + import System.IO (TextEncoding, hSetEncoding, hPutStr, hClose) |
| 139 | +@@ -39,6 +39,25 @@ withResponseFile verbosity tmpFileOpts workDir fileNameTemplate encoding argumen |
| 140 | + debug verbosity $ ">>> " ++ responseFileName |
| 141 | + f responseFileName |
| 142 | + |
| 143 | ++withLinkerScript |
| 144 | ++ :: Verbosity |
| 145 | ++ -> TempFileOptions |
| 146 | ++ -> FilePath |
| 147 | ++ -> FilePath |
| 148 | ++ -> Maybe TextEncoding |
| 149 | ++ -> String |
| 150 | ++ -> (FilePath -> IO a) |
| 151 | ++ -> IO a |
| 152 | ++withLinkerScript verbosity tmpFileOpts workDir fileNameTemplate encoding linkerScript f = |
| 153 | ++ withTempFileEx tmpFileOpts workDir fileNameTemplate $ \linkerScriptName hf -> do |
| 154 | ++ traverse_ (hSetEncoding hf) encoding |
| 155 | ++ hPutStr hf linkerScript |
| 156 | ++ hClose hf |
| 157 | ++ debug verbosity $ linkerScriptName ++ " contents: <<<" |
| 158 | ++ debug verbosity linkerScript |
| 159 | ++ debug verbosity $ ">>> " ++ linkerScriptName |
| 160 | ++ f linkerScriptName |
| 161 | ++ |
| 162 | + -- Support a gcc-like response file syntax. Each separate |
| 163 | + -- argument and its possible parameter(s), will be separated in the |
| 164 | + -- response file by an actual newline; all other whitespace, |
| 165 | +@@ -56,5 +75,3 @@ escapeResponseFileArg = reverse . foldl' escape [] |
| 166 | + '"' -> c:'\\':cs |
| 167 | + _ | isSpace c -> c:'\\':cs |
| 168 | + | otherwise -> c:cs |
| 169 | +- |
| 170 | +- |
0 commit comments