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