5a76eae1b2dafdcb8e919fd829c0ce4c4a7bf64c
[hadrian.git] / src / Settings / Packages / Rts.hs
1 module Settings.Packages.Rts (rtsPackageArgs, rtsLibffiLibrary) where
2
3 import Base
4 import GHC
5 import Oracles.Config.Flag
6 import Oracles.Config.Setting
7 import Predicate
8 import Settings
9 import Settings.Path
10
11 rtsLibffiLibraryName :: Action FilePath
12 rtsLibffiLibraryName = do
13 useSystemFfi <- flag UseSystemFfi
14 windows <- windowsHost
15 return $ case (useSystemFfi, windows) of
16 (True , False) -> "ffi"
17 (False, False) -> "Cffi"
18 (_ , True ) -> "Cffi-6"
19
20 rtsLibffiLibrary :: Way -> Action FilePath
21 rtsLibffiLibrary way = do
22 name <- rtsLibffiLibraryName
23 suf <- libsuf way
24 return $ rtsBuildPath -/- "lib" ++ name ++ suf
25
26 rtsPackageArgs :: Args
27 rtsPackageArgs = package rts ? do
28 let yesNo = expr . fmap (\x -> if x then "YES" else "NO")
29 projectVersion <- getSetting ProjectVersion
30 hostPlatform <- getSetting HostPlatform
31 hostArch <- getSetting HostArch
32 hostOs <- getSetting HostOs
33 hostVendor <- getSetting HostVendor
34 buildPlatform <- getSetting BuildPlatform
35 buildArch <- getSetting BuildArch
36 buildOs <- getSetting BuildOs
37 buildVendor <- getSetting BuildVendor
38 targetPlatform <- getSetting TargetPlatform
39 targetArch <- getSetting TargetArch
40 targetOs <- getSetting TargetOs
41 targetVendor <- getSetting TargetVendor
42 ghcUnreg <- yesNo $ flag GhcUnregisterised
43 ghcEnableTNC <- yesNo ghcEnableTablesNextToCode
44 way <- getWay
45 path <- getBuildPath
46 top <- getTopDirectory
47 libffiName <- expr rtsLibffiLibraryName
48 ffiIncludeDir <- getSetting FfiIncludeDir
49 ffiLibraryDir <- getSetting FfiLibDir
50 ghclibDir <- expr installGhcLibDir
51 mconcat
52 [ builder Cc ? mconcat
53 [ arg "-Irts"
54 , arg $ "-I" ++ path
55 , arg $ "-DRtsWay=\"rts_" ++ show way ++ "\""
56 -- rts *must* be compiled with optimisations. The INLINE_HEADER macro
57 -- requires that functions are inlined to work as expected. Inlining
58 -- only happens for optimised builds. Otherwise we can assume that
59 -- there is a non-inlined variant to use instead. But rts does not
60 -- provide non-inlined alternatives and hence needs the function to
61 -- be inlined. See also #90.
62 , arg "-O2"
63
64 , Debug `wayUnit` way ? arg "-DDEBUG"
65 , way `elem` [debug, debugDynamic] ? arg "-DTICKY_TICKY"
66 , Profiling `wayUnit` way ? arg "-DPROFILING"
67 , Threaded `wayUnit` way ? arg "-DTHREADED_RTS"
68
69 , inputs ["//RtsMessages.c", "//Trace.c"] ?
70 arg ("-DProjectVersion=" ++ show projectVersion)
71
72 , input "//RtsUtils.c" ? append
73 [ "-DProjectVersion=" ++ show projectVersion
74 , "-DHostPlatform=" ++ show hostPlatform
75 , "-DHostArch=" ++ show hostArch
76 , "-DHostOS=" ++ show hostOs
77 , "-DHostVendor=" ++ show hostVendor
78 , "-DBuildPlatform=" ++ show buildPlatform
79 , "-DBuildArch=" ++ show buildArch
80 , "-DBuildOS=" ++ show buildOs
81 , "-DBuildVendor=" ++ show buildVendor
82 , "-DTargetPlatform=" ++ show targetPlatform
83 , "-DTargetArch=" ++ show targetArch
84 , "-DTargetOS=" ++ show targetOs
85 , "-DTargetVendor=" ++ show targetVendor
86 , "-DGhcUnregisterised=" ++ show ghcUnreg
87 , "-DGhcEnableTablesNextToCode=" ++ show ghcEnableTNC ]
88
89 , inputs ["//Evac.c", "//Evac_thr.c"] ? arg "-funroll-loops"
90
91 , inputs ["//Evac_thr.c", "//Scav_thr.c"] ?
92 append [ "-DPARALLEL_GC", "-Irts/sm" ]
93
94 , input "//StgCRun.c" ? windowsHost ? arg "-Wno-return-local-addr"
95 , input "//RetainerProfile.c" ? flag GccIsClang ?
96 append [ "-Wno-incompatible-pointer-types" ]
97 ]
98
99 , builder Ghc ? arg "-Irts"
100
101 , builder HsCpp ? append
102 [ "-DTOP=" ++ show top
103 , "-DFFI_INCLUDE_DIR=" ++ show ffiIncludeDir
104 , "-DFFI_LIB_DIR=" ++ show ffiLibraryDir
105 , "-DFFI_LIB=" ++ show libffiName ]
106
107 , builder HsCpp ?
108 input "//package.conf.in" ?
109 output "//package.conf.install.raw" ?
110 append
111 [ "-DINSTALLING"
112 , "-DLIB_DIR=\"" ++ destDir ++ ghclibDir ++ "\""
113 , "-DINCLUDE_DIR=\"" ++ destDir ++ ghclibDir -/- "include\""
114 ]
115 ]
116
117 -- # If we're compiling on windows, enforce that we only support XP+
118 -- # Adding this here means it doesn't have to be done in individual .c files
119 -- # and also centralizes the versioning.
120 -- ifeq "$$(TargetOS_CPP)" "mingw32"
121 -- rts_dist_$1_CC_OPTS += -DWINVER=$(rts_WINVER)
122 -- endif
123
124 -- #-----------------------------------------------------------------------------
125 -- # Use system provided libffi
126
127 -- ifeq "$(UseSystemLibFFI)" "YES"
128
129 -- rts_PACKAGE_CPP_OPTS += -DFFI_INCLUDE_DIR=$(FFIIncludeDir)
130 -- rts_PACKAGE_CPP_OPTS += -DFFI_LIB_DIR=$(FFILibDir)
131 -- rts_PACKAGE_CPP_OPTS += '-DFFI_LIB='
132
133 -- endif
134
135 -- #-----------------------------------------------------------------------------
136 -- # Add support for reading DWARF debugging information, if available
137
138 -- ifeq "$(GhcRtsWithLibdw)" "YES"
139 -- rts_CC_OPTS += -DUSE_LIBDW
140 -- rts_PACKAGE_CPP_OPTS += -DUSE_LIBDW
141 -- endif
142
143 -- # If -DDEBUG is in effect, adjust package conf accordingly..
144 -- ifneq "$(strip $(filter -optc-DDEBUG,$(GhcRtsHcOpts)))" ""
145 -- rts_PACKAGE_CPP_OPTS += -DDEBUG
146 -- endif
147
148 -- ifeq "$(HaveLibMingwEx)" "YES"
149 -- rts_PACKAGE_CPP_OPTS += -DHAVE_LIBMINGWEX
150 -- endif
151
152
153
154 -- #-----------------------------------------------------------------------------
155 -- # Flags for compiling specific files
156 -- #
157 -- #
158
159 -- # Compile various performance-critical pieces *without* -fPIC -dynamic
160 -- # even when building a shared library. If we don't do this, then the
161 -- # GC runs about 50% slower on x86 due to the overheads of PIC. The
162 -- # cost of doing this is a little runtime linking and less sharing, but
163 -- # not much.
164 -- #
165 -- # On x86_64 this doesn't work, because all objects in a shared library
166 -- # must be compiled with -fPIC (since the 32-bit relocations generated
167 -- # by the default small memory can't be resolved at runtime). So we
168 -- # only do this on i386.
169 -- #
170 -- # This apparently doesn't work on OS X (Darwin) nor on Solaris.
171 -- # On Darwin we get errors of the form
172 -- #
173 -- # 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
174 -- #
175 -- # and lots of these warnings:
176 -- #
177 -- # ld: warning codegen in _stg_ap_pppv_fast (offset 0x0000005E) prevents image from loading in dyld shared cache
178 -- #
179 -- # On Solaris we get errors like:
180 -- #
181 -- # Text relocation remains referenced
182 -- # against symbol offset in file
183 -- # .rodata (section) 0x11 rts/dist/build/Apply.dyn_o
184 -- # ...
185 -- # ld: fatal: relocations remain against allocatable but non-writable sections
186 -- # collect2: ld returned 1 exit status
187
188 -- ifeq "$(TargetArch_CPP)" "i386"
189 -- i386_SPEED_HACK := "YES"
190 -- ifeq "$(TargetOS_CPP)" "darwin"
191 -- i386_SPEED_HACK := "NO"
192 -- endif
193 -- ifeq "$(TargetOS_CPP)" "solaris2"
194 -- i386_SPEED_HACK := "NO"
195 -- endif
196 -- endif
197
198 -- ifeq "$(TargetArch_CPP)" "i386"
199 -- ifeq "$(i386_SPEED_HACK)" "YES"
200 -- rts/sm/Evac_HC_OPTS += -fno-PIC
201 -- rts/sm/Evac_thr_HC_OPTS += -fno-PIC
202 -- rts/sm/Scav_HC_OPTS += -fno-PIC
203 -- rts/sm/Scav_thr_HC_OPTS += -fno-PIC
204 -- rts/sm/Compact_HC_OPTS += -fno-PIC
205 -- rts/sm/GC_HC_OPTS += -fno-PIC
206
207 -- # -static is also necessary for these bits, otherwise the NCG
208 -- # -generates dynamic references:
209 -- rts/Updates_HC_OPTS += -fno-PIC -static
210 -- rts/StgMiscClosures_HC_OPTS += -fno-PIC -static
211 -- rts/PrimOps_HC_OPTS += -fno-PIC -static
212 -- rts/Apply_HC_OPTS += -fno-PIC -static
213 -- rts/dist/build/AutoApply_HC_OPTS += -fno-PIC -static
214 -- endif
215 -- endif
216
217 -- # add CFLAGS for libffi
218 -- # ffi.h triggers prototype warnings, so disable them here:
219 -- ifeq "$(UseSystemLibFFI)" "YES"
220 -- LIBFFI_CFLAGS = $(addprefix -I,$(FFIIncludeDir))
221 -- else
222 -- LIBFFI_CFLAGS =
223 -- endif
224 -- rts/Interpreter_CC_OPTS += -Wno-strict-prototypes $(LIBFFI_CFLAGS)
225 -- rts/Adjustor_CC_OPTS += -Wno-strict-prototypes $(LIBFFI_CFLAGS)
226 -- rts/sm/Storage_CC_OPTS += -Wno-strict-prototypes $(LIBFFI_CFLAGS)
227
228 -- # inlining warnings happen in Compact
229 -- rts/sm/Compact_CC_OPTS += -Wno-inline
230
231 -- # emits warnings about call-clobbered registers on x86_64
232 -- rts/StgCRun_CC_OPTS += -w
233
234 -- rts/RetainerProfile_CC_OPTS += -w
235 -- rts/RetainerSet_CC_OPTS += -Wno-format
236 -- # On Windows:
237 -- rts/win32/ConsoleHandler_CC_OPTS += -w
238 -- rts/win32/ThrIOManager_CC_OPTS += -w
239 -- # The above warning suppression flags are a temporary kludge.
240 -- # While working on this module you are encouraged to remove it and fix
241 -- # any warnings in the module. See
242 -- # http://ghc.haskell.org/trac/ghc/wiki/WorkingConventions#Warnings
243 -- # for details
244
245 -- # Without this, thread_obj will not be inlined (at least on x86 with GCC 4.1.0)
246 -- ifneq "$(CC_CLANG_BACKEND)" "1"
247 -- rts/sm/Compact_CC_OPTS += -finline-limit=2500
248 -- endif