Drop custom logic for Scav_thr and Evac_thr (#497)
[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 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
63 -- from rts/dist/build/Apply.dyn_o not allowed in slidable image
64 --
65 -- and lots of these warnings:
66 --
67 -- ld: warning codegen in _stg_ap_pppv_fast (offset 0x0000005E) prevents image
68 -- from loading in dyld shared cache
69 --
70 -- On Solaris we get errors like:
71 --
72 -- Text relocation remains referenced
73 -- against symbol offset in file
74 -- .rodata (section) 0x11 rts/dist/build/Apply.dyn_o
75 -- ...
76 -- ld: fatal: relocations remain against allocatable but non-writable sections
77 -- collect2: ld returned 1 exit status
78 speedHack :: Action Bool
79 speedHack = do
80 i386 <- anyTargetArch ["i386"]
81 goodOS <- not <$> anyTargetOs ["darwin", "solaris2"]
82 return $ i386 && goodOS
83
84 rtsPackageArgs :: Args
85 rtsPackageArgs = package rts ? do
86 projectVersion <- getSetting ProjectVersion
87 hostPlatform <- getSetting HostPlatform
88 hostArch <- getSetting HostArch
89 hostOs <- getSetting HostOs
90 hostVendor <- getSetting HostVendor
91 buildPlatform <- getSetting BuildPlatform
92 buildArch <- getSetting BuildArch
93 buildOs <- getSetting BuildOs
94 buildVendor <- getSetting BuildVendor
95 targetPlatform <- getSetting TargetPlatform
96 targetArch <- getSetting TargetArch
97 targetOs <- getSetting TargetOs
98 targetVendor <- getSetting TargetVendor
99 ghcUnreg <- expr $ yesNo <$> flag GhcUnregisterised
100 ghcEnableTNC <- expr $ yesNo <$> ghcEnableTablesNextToCode
101 way <- getWay
102 path <- getBuildPath
103 top <- expr topDirectory
104 libffiName <- expr libffiLibraryName
105 ffiIncludeDir <- getSetting FfiIncludeDir
106 ffiLibraryDir <- getSetting FfiLibDir
107 ghclibDir <- expr installGhcLibDir
108 destDir <- expr getDestDir
109 let cArgs = mconcat
110 [ arg "-Irts"
111 , rtsWarnings
112 , arg $ "-I" ++ path
113 , flag UseSystemFfi ? arg ("-I" ++ ffiIncludeDir)
114 , arg $ "-DRtsWay=\"rts_" ++ show way ++ "\""
115 -- RTS *must* be compiled with optimisations. The INLINE_HEADER macro
116 -- requires that functions are inlined to work as expected. Inlining
117 -- only happens for optimised builds. Otherwise we can assume that
118 -- there is a non-inlined variant to use instead. But RTS does not
119 -- provide non-inlined alternatives and hence needs the function to
120 -- be inlined. See https://github.com/snowleopard/hadrian/issues/90.
121 , arg "-O2"
122
123 , Debug `wayUnit` way ? arg "-DDEBUG"
124 , way `elem` [debug, debugDynamic] ? arg "-DTICKY_TICKY"
125 , Profiling `wayUnit` way ? arg "-DPROFILING"
126 , Threaded `wayUnit` way ? arg "-DTHREADED_RTS"
127
128 , inputs ["//RtsMessages.c", "//Trace.c"] ?
129 arg ("-DProjectVersion=" ++ show projectVersion)
130
131 , input "//RtsUtils.c" ? pure
132 [ "-DProjectVersion=" ++ show projectVersion
133 , "-DHostPlatform=" ++ show hostPlatform
134 , "-DHostArch=" ++ show hostArch
135 , "-DHostOS=" ++ show hostOs
136 , "-DHostVendor=" ++ show hostVendor
137 , "-DBuildPlatform=" ++ show buildPlatform
138 , "-DBuildArch=" ++ show buildArch
139 , "-DBuildOS=" ++ show buildOs
140 , "-DBuildVendor=" ++ show buildVendor
141 , "-DTargetPlatform=" ++ show targetPlatform
142 , "-DTargetArch=" ++ show targetArch
143 , "-DTargetOS=" ++ show targetOs
144 , "-DTargetVendor=" ++ show targetVendor
145 , "-DGhcUnregisterised=" ++ show ghcUnreg
146 , "-DGhcEnableTablesNextToCode=" ++ show ghcEnableTNC ]
147
148 , inputs ["//Evac.c", "//Evac_thr.c"] ? arg "-funroll-loops"
149
150 , speedHack ?
151 inputs [ "//Evac.c", "//Evac_thr.c"
152 , "//Scav.c", "//Scav_thr.c"
153 , "//Compact.c", "//GC.c" ] ? arg "-fno-PIC"
154 -- -static is also necessary for these bits, otherwise the NCG
155 -- generates dynamic references:
156 , speedHack ?
157 inputs [ "//Updates.c", "//StgMiscClosures.c"
158 , "//PrimOps.c", "//Apply.c"
159 , "//AutoApply.c" ] ? pure ["-fno-PIC", "-static"]
160
161 -- inlining warnings happen in Compact
162 , inputs ["//Compact.c"] ? arg "-Wno-inline"
163
164 -- emits warnings about call-clobbered registers on x86_64
165 , inputs [ "//RetainerProfile.c", "//StgCRun.c"
166 , "//win32/ConsoleHandler.c", "//win32/ThrIOManager.c"] ? arg "-w"
167 , inputs ["//RetainerSet.c"] ? arg "-Wno-format"
168 -- The above warning suppression flags are a temporary kludge.
169 -- While working on this module you are encouraged to remove it and fix
170 -- any warnings in the module. See:
171 -- http://ghc.haskell.org/trac/ghc/wiki/WorkingConventions#Warnings
172
173 , (not <$> flag GccIsClang) ?
174 inputs ["//Compact.c"] ? arg "-finline-limit=2500"
175
176 , input "//StgCRun.c" ? windowsHost ? arg "-Wno-return-local-addr"
177 , input "//RetainerProfile.c" ? flag GccIsClang ?
178 arg "-Wno-incompatible-pointer-types"
179 , windowsHost ? arg ("-DWINVER=" ++ windowsVersion)
180
181 -- libffi's ffi.h triggers various warnings
182 , inputs [ "//Interpreter.c", "//Storage.c", "//Adjustor.c" ] ?
183 arg "-Wno-strict-prototypes"
184 , inputs ["//Interpreter.c", "//Adjustor.c", "//sm/Storage.c"] ?
185 anyTargetArch ["powerpc"] ? arg "-Wno-undef" ]
186
187 mconcat
188 [ builder (Cc FindCDependencies) ? cArgs
189 , builder (Ghc CompileCWithGhc) ? map ("-optc" ++) <$> cArgs
190 , builder Ghc ? arg "-Irts"
191
192 , builder HsCpp ? pure
193 [ "-DTOP=" ++ show top
194 , "-DFFI_INCLUDE_DIR=" ++ show ffiIncludeDir
195 , "-DFFI_LIB_DIR=" ++ show ffiLibraryDir
196 , "-DFFI_LIB=" ++ show libffiName ]
197
198 , builder HsCpp ?
199 input "//package.conf.in" ?
200 output "//package.conf.install.raw" ?
201 pure [ "-DINSTALLING"
202 , "-DLIB_DIR=\"" ++ destDir ++ ghclibDir ++ "\""
203 , "-DINCLUDE_DIR=\"" ++ destDir ++ ghclibDir -/- "include\"" ]
204
205 , builder HsCpp ? flag HaveLibMingwEx ? arg "-DHAVE_LIBMINGWEX" ]
206
207 -- See @rts/ghc.mk@.
208 rtsWarnings :: Args
209 rtsWarnings = mconcat
210 [ arg "-Wall"
211 , arg "-Wextra"
212 , arg "-Wstrict-prototypes"
213 , arg "-Wmissing-prototypes"
214 , arg "-Wmissing-declarations"
215 , arg "-Winline"
216 , arg "-Waggregate-return"
217 , arg "-Wpointer-arith"
218 , arg "-Wmissing-noreturn"
219 , arg "-Wnested-externs"
220 , arg "-Wredundant-decls"
221 , arg "-Wundef"
222 , arg "-fno-strict-aliasing" ]