Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Use ld.gold in dev shells #1868

Merged
merged 10 commits into from
Mar 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 1 addition & 10 deletions builder/comp-builder.nix
Original file line number Diff line number Diff line change
Expand Up @@ -179,16 +179,7 @@ let
[ "--with-gcc=${stdenv.cc.targetPrefix}cc"
] ++
# BINTOOLS
(if stdenv.hostPlatform.isLinux && !stdenv.hostPlatform.isAndroid # might be better check to see if cc is clang/llvm?
# use gold as the linker on linux to improve link times
then [
"--with-ld=${stdenv.cc.bintools.targetPrefix}ld.gold"
"--ghc-option=-optl-fuse-ld=gold"
"--ld-option=-fuse-ld=gold"
] else [
"--with-ld=${stdenv.cc.bintools.targetPrefix}ld"
]
) ++ [
[
"--with-ar=${stdenv.cc.bintools.targetPrefix}ar"
"--with-strip=${stdenv.cc.bintools.targetPrefix}strip"
]
Expand Down
16 changes: 14 additions & 2 deletions compiler/ghc/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ let self =
# necessary fix for iOS: https://www.reddit.com/r/haskell/comments/4ttdz1/building_an_osxi386_to_iosarm64_cross_compiler/d5qvd67/
disableLargeAddressSpace ? stdenv.targetPlatform.isDarwin && stdenv.targetPlatform.isAarch64

, useLdGold ?
# might be better check to see if cc is clang/llvm?
# use gold as the linker on linux to improve link times
# do not use it on musl due to a ld.gold bug. See: <https://sourceware.org/bugzilla/show_bug.cgi?id=22266>.
(stdenv.targetPlatform.isLinux && !stdenv.targetPlatform.isAndroid && !stdenv.targetPlatform.isMusl)
|| stdenv.targetPlatform.isAarch32
Comment on lines +72 to +73
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After looking closer at this, I believe this is wrong. We do not unconditionally enable this in aarch32.
I believe the || stdenv.targetPlatform.isAarch32 should go.


, ghc-version ? src-spec.version
, ghc-version-date ? null
, src-spec
Expand Down Expand Up @@ -187,10 +194,11 @@ let
"--enable-bootstrap-with-devel-snapshot"
] ++ lib.optionals (disableLargeAddressSpace) [
"--disable-large-address-space"
] ++ lib.optionals (targetPlatform.isAarch32) [
] ++ lib.optionals useLdGold [
"CFLAGS=-fuse-ld=gold"
"CONF_GCC_LINKER_OPTS_STAGE1=-fuse-ld=gold"
"CONF_GCC_LINKER_OPTS_STAGE2=-fuse-ld=gold"
"CONF_LD_LINKER_OPTS_STAGE2=-fuse-ld=gold" # See: <https://gitlab.haskell.org/ghc/ghc/-/issues/22550#note_466656>
] ++ lib.optionals enableDWARF [
"--enable-dwarf-unwind"
"--with-libdw-includes=${lib.getDev elfutils}/include"
Expand Down Expand Up @@ -285,13 +293,17 @@ stdenv.mkDerivation (rec {
export CC="${targetCC}/bin/${targetCC.targetPrefix}cc"
export CXX="${targetCC}/bin/${targetCC.targetPrefix}c++"
# Use gold to work around https://sourceware.org/bugzilla/show_bug.cgi?id=16177
export LD="${targetCC.bintools}/bin/${targetCC.bintools.targetPrefix}ld${lib.optionalString targetPlatform.isAarch32 ".gold"}"
export LD="${targetCC.bintools}/bin/${targetCC.bintools.targetPrefix}ld${lib.optionalString useLdGold ".gold"}"
export AS="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}as"
export AR="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}ar"
export NM="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}nm"
export RANLIB="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}ranlib"
export READELF="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}readelf"
export STRIP="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}strip"
'' + lib.optionalString (targetPlatform == hostPlatform && useLdGold)
# set LD explicitly if we want gold even if we aren't cross compiling
''
export LD="${targetCC.bintools}/bin/ld.gold"
'' + lib.optionalString (targetPlatform.isWindows) ''
export DllWrap="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}dllwrap"
export Windres="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}windres"
Expand Down