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