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