@@ -65,6 +65,13 @@ let self =
65
65
# necessary fix for iOS: https://www.reddit.com/r/haskell/comments/4ttdz1/building_an_osxi386_to_iosarm64_cross_compiler/d5qvd67/
66
66
disableLargeAddressSpace ? stdenv . targetPlatform . isDarwin && stdenv . targetPlatform . isAarch64
67
67
68
+ , useLdGold ?
69
+ # might be better check to see if cc is clang/llvm?
70
+ # use gold as the linker on linux to improve link times
71
+ # do not use it on musl due to a ld.gold bug. See: <https://sourceware.org/bugzilla/show_bug.cgi?id=22266>.
72
+ ( stdenv . targetPlatform . isLinux && ! stdenv . targetPlatform . isAndroid && ! stdenv . targetPlatform . isMusl )
73
+ || stdenv . targetPlatform . isAarch32
74
+
68
75
, ghc-version ? src-spec . version
69
76
, ghc-version-date ? null
70
77
, src-spec
@@ -187,10 +194,11 @@ let
187
194
"--enable-bootstrap-with-devel-snapshot"
188
195
] ++ lib . optionals ( disableLargeAddressSpace ) [
189
196
"--disable-large-address-space"
190
- ] ++ lib . optionals ( targetPlatform . isAarch32 ) [
197
+ ] ++ lib . optionals useLdGold [
191
198
"CFLAGS=-fuse-ld=gold"
192
199
"CONF_GCC_LINKER_OPTS_STAGE1=-fuse-ld=gold"
193
200
"CONF_GCC_LINKER_OPTS_STAGE2=-fuse-ld=gold"
201
+ "CONF_LD_LINKER_OPTS_STAGE2=-fuse-ld=gold" # See: <https://gitlab.haskell.org/ghc/ghc/-/issues/22550#note_466656>
194
202
] ++ lib . optionals enableDWARF [
195
203
"--enable-dwarf-unwind"
196
204
"--with-libdw-includes=${ lib . getDev elfutils } /include"
@@ -285,13 +293,17 @@ stdenv.mkDerivation (rec {
285
293
export CC="${ targetCC } /bin/${ targetCC . targetPrefix } cc"
286
294
export CXX="${ targetCC } /bin/${ targetCC . targetPrefix } c++"
287
295
# Use gold to work around https://sourceware.org/bugzilla/show_bug.cgi?id=16177
288
- export LD="${ targetCC . bintools } /bin/${ targetCC . bintools . targetPrefix } ld${ lib . optionalString targetPlatform . isAarch32 ".gold" } "
296
+ export LD="${ targetCC . bintools } /bin/${ targetCC . bintools . targetPrefix } ld${ lib . optionalString useLdGold ".gold" } "
289
297
export AS="${ targetCC . bintools . bintools } /bin/${ targetCC . bintools . targetPrefix } as"
290
298
export AR="${ targetCC . bintools . bintools } /bin/${ targetCC . bintools . targetPrefix } ar"
291
299
export NM="${ targetCC . bintools . bintools } /bin/${ targetCC . bintools . targetPrefix } nm"
292
300
export RANLIB="${ targetCC . bintools . bintools } /bin/${ targetCC . bintools . targetPrefix } ranlib"
293
301
export READELF="${ targetCC . bintools . bintools } /bin/${ targetCC . bintools . targetPrefix } readelf"
294
302
export STRIP="${ targetCC . bintools . bintools } /bin/${ targetCC . bintools . targetPrefix } strip"
303
+ '' + lib . optionalString ( targetPlatform == hostPlatform && useLdGold )
304
+ # set LD explicitly if we want gold even if we aren't cross compiling
305
+ ''
306
+ export LD="${ targetCC . bintools } /bin/ld.gold"
295
307
'' + lib . optionalString ( targetPlatform . isWindows ) ''
296
308
export DllWrap="${ targetCC . bintools . bintools } /bin/${ targetCC . bintools . targetPrefix } dllwrap"
297
309
export Windres="${ targetCC . bintools . bintools } /bin/${ targetCC . bintools . targetPrefix } windres"
0 commit comments