Skip to content

Commit 16361e6

Browse files
angermanhamishmack
andauthored
GHC also fix hadrian always build PIC is specifcied. (#2135)
* GHC also fix hadrian always build PIC is specifcied. * ifdLevel 0 * ifdLevel 1 * ifdLevel 2 * ifdLevel 3 --------- Co-authored-by: Hamish Mackenzie <[email protected]>
1 parent 5014b2d commit 16361e6

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

compiler/ghc/default.nix

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,11 @@ let self =
6464
# necessary fix for iOS: https://www.reddit.com/r/haskell/comments/4ttdz1/building_an_osxi386_to_iosarm64_cross_compiler/d5qvd67/
6565
disableLargeAddressSpace ? stdenv.targetPlatform.isDarwin && stdenv.targetPlatform.isAarch64
6666

67-
, useLdGold ?
67+
, useLdGold ?
6868
# might be better check to see if cc is clang/llvm?
6969
# use gold as the linker on linux to improve link times
7070
# do not use it on musl due to a ld.gold bug. See: <https://sourceware.org/bugzilla/show_bug.cgi?id=22266>.
71-
(stdenv.targetPlatform.isLinux && !stdenv.targetPlatform.isAndroid && !stdenv.targetPlatform.isMusl)
71+
(stdenv.targetPlatform.isLinux && !stdenv.targetPlatform.isAndroid && !stdenv.targetPlatform.isMusl)
7272

7373
, ghc-version ? src-spec.version
7474
, ghc-version-date ? null
@@ -311,7 +311,11 @@ let
311311
# For cross compilers only the RTS should be built with -mno-outline-atomics
312312
+ lib.optionalString (!hostPlatform.isAarch64 && targetPlatform.isLinux && targetPlatform.isAarch64)
313313
" '*.rts.ghc.c.opts += -optc-mno-outline-atomics'"
314-
# The following is required if we build on aarch64-darwin for aarch64-iOS. Otherwise older
314+
+ lib.optionalString enableRelocatedStaticLibs
315+
" '*.*.ghc.*.opts += -fPIC' '*.*.cc.*.opts += -fPIC'"
316+
+ lib.optionalString (enableRelocatedStaticLibs && targetPlatform.isx86_64 && !targetPlatform.isWindows)
317+
" '*.*.ghc.*.opts += -fexternal-dynamic-refs'"
318+
# The following is required if we build on aarch64-darwin for aarch64-iOS. Otherwise older
315319
# iPhones/iPads/... won't understand the compiled code, as the compiler will emit LDSETALH
316320
# + lib.optionalString (targetPlatform.???) "'*.rts.ghc.c.opts += -optc-mcpu=apple-a7 -optc-march=armv8-a+norcpc'"
317321
# For GHC versions in the 9.x range that don't support the +native_bignum flavour transformer yet
@@ -403,7 +407,7 @@ stdenv.mkDerivation (rec {
403407
'' + lib.optionalString (stdenv.targetPlatform.linker == "cctools") ''
404408
export OTOOL="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}otool"
405409
export INSTALL_NAME_TOOL="${bintoolsFor.install_name_tool}/bin/${bintoolsFor.install_name_tool.targetPrefix}install_name_tool"
406-
'') + lib.optionalString (targetPlatform == hostPlatform && useLdGold)
410+
'') + lib.optionalString (targetPlatform == hostPlatform && useLdGold)
407411
# set LD explicitly if we want gold even if we aren't cross compiling
408412
''
409413
export LD="${targetCC.bintools}/bin/ld.gold"
@@ -779,9 +783,9 @@ stdenv.mkDerivation (rec {
779783
'';
780784

781785
# Hadrian's installation only works for native compilers, and is broken for cross compilers.
782-
# However Hadrian produces mostly relocatable installs anyway, so we can simply copy
786+
# However Hadrian produces mostly relocatable installs anyway, so we can simply copy
783787
# stage1/{bin, lib, share} into the destination as the copy phase.
784-
788+
785789
installPhase =
786790
if installStage1
787791
then ''

0 commit comments

Comments
 (0)