299d1da9a5f4c0a5515ab8c858797d8d0b6fc4ff
[ghc.git] / src / Settings / Packages / Rts.hs
1 module Settings.Packages.Rts (
2 rtsContext, rtsBuildPath, rtsConfIn, rtsPackageArgs, rtsLibffiLibrary
3 ) where
4
5 import Base
6 import Expression
7 import Oracles.Flag
8 import Oracles.Setting
9 import Settings
10
11 -- | RTS is considered a Stage1 package. This determines RTS build directory.
12 rtsContext :: Context
13 rtsContext = vanillaContext Stage1 rts
14
15 -- | Path to the RTS build directory.
16 rtsBuildPath :: Action FilePath
17 rtsBuildPath = buildPath rtsContext
18
19 -- | Path to RTS package configuration file, to be processed by HsCpp.
20 rtsConfIn :: FilePath
21 rtsConfIn = pkgPath rts -/- "package.conf.in"
22
23 -- These numbers can be found at:
24 -- https://msdn.microsoft.com/en-us/library/windows/desktop/aa383745(v=vs.85).aspx
25 -- If we're compiling on windows, enforce that we only support Vista SP1+
26 -- Adding this here means it doesn't have to be done in individual .c files
27 -- and also centralizes the versioning.
28 -- | Minimum supported Windows version.
29 windowsVersion :: String
30 windowsVersion = "0x06000100"
31
32 libffiLibraryName :: Action FilePath
33 libffiLibraryName = do
34 useSystemFfi <- flag UseSystemFfi
35 windows <- windowsHost
36 return $ case (useSystemFfi, windows) of
37 (True , False) -> "ffi"
38 (False, False) -> "Cffi"
39 (_ , True ) -> "Cffi-6"
40
41 rtsLibffiLibrary :: Way -> Action FilePath
42 rtsLibffiLibrary way = do
43 name <- libffiLibraryName
44 suf <- libsuf way
45 rtsPath <- rtsBuildPath
46 return $ rtsPath -/- "lib" ++ name ++ suf
47
48 -- Compile various performance-critical pieces *without* -fPIC -dynamic
49 -- even when building a shared library. If we don't do this, then the
50 -- GC runs about 50% slower on x86 due to the overheads of PIC. The
51 -- cost of doing this is a little runtime linking and less sharing, but
52 -- not much.
53 --
54 -- On x86_64 this doesn't work, because all objects in a shared library
55 -- must be compiled with -fPIC (since the 32-bit relocations generated
56 -- by the default small memory can't be resolved at runtime). So we
57 -- only do this on i386.
58 --
59 -- This apparently doesn't work on OS X (Darwin) nor on Solaris.
60 -- On Darwin we get errors of the form
61 --
62 -- ld: absolute addressing (perhaps -mdynamic-no-pic) used in _stg_ap_0_fast from rts/dist/build/Apply.dyn_o not allowed in slidable image
63 --
64 -- and lots of these warnings:
65 --
66 -- ld: warning codegen in _stg_ap_pppv_fast (offset 0x0000005E) prevents image from loading in dyld shared cache
67 --
68 -- On Solaris we get errors like:
69 --
70 -- Text relocation remains referenced
71 -- against symbol offset in file
72 -- .rodata (section) 0x11 rts/dist/build/Apply.dyn_o
73 -- ...
74 -- ld: fatal: relocations remain against allocatable but non-writable sections
75 -- collect2: ld returned 1 exit status
76 speedHack :: Action Bool
77 speedHack = do
78 i386 <- anyTargetArch ["i386"]
79 goodOS <- not <$> anyTargetOs ["darwin", "solaris2"]
80 return $ i386 && goodOS
81
82 rtsPackageArgs :: Args
83 rtsPackageArgs = package rts ? do
84 projectVersion <- getSetting ProjectVersion
85 hostPlatform <- getSetting HostPlatform
86 hostArch <- getSetting HostArch
87 hostOs <- getSetting HostOs
88 hostVendor <- getSetting HostVendor
89 buildPlatform <- getSetting BuildPlatform
90 buildArch <- getSetting BuildArch
91 buildOs <- getSetting BuildOs
92 buildVendor <- getSetting BuildVendor
93 targetPlatform <- getSetting TargetPlatform
94 targetArch <- getSetting TargetArch
95 targetOs <- getSetting TargetOs
96 targetVendor <- getSetting TargetVendor
97 ghcUnreg <- expr $ yesNo <$> flag GhcUnregisterised
98 ghcEnableTNC <- expr $ yesNo <$> ghcEnableTablesNextToCode
99 way <- getWay
100 path <- getBuildPath
101 top <- expr topDirectory
102 libffiName <- expr libffiLibraryName
103 ffiIncludeDir <- getSetting FfiIncludeDir
104 ffiLibraryDir <- getSetting FfiLibDir
105 ghclibDir <- expr installGhcLibDir
106 destDir <- expr getDestDir
107 let cArgs = mconcat
108 [ arg "-Irts"
109 , arg $ "-I" ++ path
110 , flag UseSystemFfi ? arg ("-I" ++ ffiIncludeDir)
111 , arg $ "-DRtsWay=\"rts_" ++ show way ++ "\""
112 -- RTS *must* be compiled with optimisations. The INLINE_HEADER macro
113 -- requires that functions are inlined to work as expected. Inlining
114 -- only happens for optimised builds. Otherwise we can assume that
115 -- there is a non-inlined variant to use instead. But RTS does not
116 -- provide non-inlined alternatives and hence needs the function to
117 -- be inlined. See https://github.com/snowleopard/hadrian/issues/90.
118 , arg "-O2"
119
120 , Debug `wayUnit` way ? arg "-DDEBUG"
121 , way `elem` [debug, debugDynamic] ? arg "-DTICKY_TICKY"
122 , Profiling `wayUnit` way ? arg "-DPROFILING"
123 , Threaded `wayUnit` way ? arg "-DTHREADED_RTS"
124
125 , inputs ["//RtsMessages.c", "//Trace.c"] ?
126 arg ("-DProjectVersion=" ++ show projectVersion)
127
128 , input "//RtsUtils.c" ? pure
129 [ "-DProjectVersion=" ++ show projectVersion
130 , "-DHostPlatform=" ++ show hostPlatform
131 , "-DHostArch=" ++ show hostArch
132 , "-DHostOS=" ++ show hostOs
133 , "-DHostVendor=" ++ show hostVendor
134 , "-DBuildPlatform=" ++ show buildPlatform
135 , "-DBuildArch=" ++ show buildArch
136 , "-DBuildOS=" ++ show buildOs
137 , "-DBuildVendor=" ++ show buildVendor
138 , "-DTargetPlatform=" ++ show targetPlatform
139 , "-DTargetArch=" ++ show targetArch
140 , "-DTargetOS=" ++ show targetOs
141 , "-DTargetVendor=" ++ show targetVendor
142 , "-DGhcUnregisterised=" ++ show ghcUnreg
143 , "-DGhcEnableTablesNextToCode=" ++ show ghcEnableTNC ]
144
145 , inputs ["//Evac.c", "//Evac_thr.c"] ? arg "-funroll-loops"
146
147 , speedHack ?
148 inputs [ "//Evac.c", "//Evac_thr.c"
149 , "//Scav.c", "//Scav_thr.c"
150 , "//Compact.c", "//GC.c" ] ? arg "-fno-PIC"
151 -- -static is also necessary for these bits, otherwise the NCG
152 -- generates dynamic references:
153 , speedHack ?
154 inputs [ "//Updates.c", "//StgMiscClosures.c"
155 , "//PrimOps.c", "//Apply.c"
156 , "//AutoApply.c" ] ? pure ["-fno-PIC", "-static"]
157
158 -- inlining warnings happen in Compact
159 , inputs ["//Compact.c"] ? arg "-Wno-inline"
160
161 -- emits warnings about call-clobbered registers on x86_64
162 , inputs [ "//RetainerProfile.c", "//StgCRun.c"
163 , "//win32/ConsoleHandler.c", "//win32/ThrIOManager.c"] ? arg "-w"
164 , inputs ["//RetainerSet.c"] ? arg "-Wno-format"
165 -- The above warning suppression flags are a temporary kludge.
166 -- While working on this module you are encouraged to remove it and fix
167 -- any warnings in the module. See:
168 -- http://ghc.haskell.org/trac/ghc/wiki/WorkingConventions#Warnings
169
170 , (not <$> flag GccIsClang) ?
171 inputs ["//Compact.c"] ? arg "-finline-limit=2500"
172
173 , inputs ["//Evac_thr.c", "//Scav_thr.c"] ?
174 pure ["-DPARALLEL_GC", "-Irts/sm"]
175
176 , input "//StgCRun.c" ? windowsHost ? arg "-Wno-return-local-addr"
177 , input "//RetainerProfile.c" ? flag GccIsClang ?
178 arg "-Wno-incompatible-pointer-types"
179 , inputs [ "//Interpreter.c", "//Storage.c", "//Adjustor.c" ] ?
180 arg "-Wno-strict-prototypes"
181 , windowsHost ? arg ("-DWINVER=" ++ windowsVersion) ]
182 mconcat
183 [ builder (Cc FindCDependencies) ? cArgs
184 , builder (Ghc CompileCWithGhc) ? map ("-optc" ++) <$> cArgs
185 , builder Ghc ? arg "-Irts"
186
187 , builder HsCpp ? pure
188 [ "-DTOP=" ++ show top
189 , "-DFFI_INCLUDE_DIR=" ++ show ffiIncludeDir
190 , "-DFFI_LIB_DIR=" ++ show ffiLibraryDir
191 , "-DFFI_LIB=" ++ show libffiName ]
192
193 , builder HsCpp ?
194 input "//package.conf.in" ?
195 output "//package.conf.install.raw" ?
196 pure [ "-DINSTALLING"
197 , "-DLIB_DIR=\"" ++ destDir ++ ghclibDir ++ "\""
198 , "-DINCLUDE_DIR=\"" ++ destDir ++ ghclibDir -/- "include\"" ]
199
200 , builder HsCpp ? flag HaveLibMingwEx ? arg "-DHAVE_LIBMINGWEX" ]