Skip to content

Commit 17d4ff5

Browse files
committed
Merge branch 'master' of github.com:input-output-hk/haskell.nix into circuithub
2 parents 18f2028 + 2c99ded commit 17d4ff5

File tree

265 files changed

+18794
-985
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

265 files changed

+18794
-985
lines changed

.github/workflows/pipeline.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,13 +227,20 @@ jobs:
227227
- name: "Check that the haskell.nix roots do not require IFDs"
228228
run: nix build .#roots.x86_64-linux --accept-flake-config --option allow-import-from-derivation false
229229

230-
hydra-without-remote-builders:
230+
hydra-without-remote-builders-ghc8107:
231231
runs-on: [self-hosted, linux]
232232
steps:
233233
- uses: actions/checkout@v4
234-
- name: "Check that evaluation of hydra jobs works without using remote builders"
234+
- name: "Check that evaluation of hydra jobs works without using remote builders for GHC 8.10.7"
235235
run: nix path-info --derivation .#requiredJobs.x86_64-darwin.required-unstable-ghc8107-native --show-trace --builders ''
236236

237+
hydra-without-remote-builders-ghc9101:
238+
runs-on: [self-hosted, linux]
239+
steps:
240+
- uses: actions/checkout@v4
241+
- name: "Check that evaluation of hydra jobs works without using remote builders for GHC 9.10.1"
242+
run: nix path-info --derivation .#requiredJobs.x86_64-darwin.required-unstable-ghc9101-native --show-trace --builders ''
243+
237244
hix-cabal:
238245
runs-on: [self-hosted, linux]
239246
steps:

BUGLOG

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
This file contains bugs we find while working on haskell.nix. The format is as
2+
follow:
3+
<separator: 80 * '-'>
4+
YYYY-MM-DD: nix-job name
5+
6+
<error>
7+
8+
<discussion>
9+
10+
--------------------------------------------------------------------------------
11+
2024-04-09 x86_64-linux.R2305.ghc8107.mingwW64.ghc
12+
13+
/build/ghc62733_0/ghc_1.s:50:0: error:
14+
Error: CFI instruction used without previous .cfi_startproc
15+
|
16+
50 | .cfi_escape 0x16, 0x07, 0x04, 0x77, 152, 65
17+
| ^
18+
`x86_64-w64-mingw32-cc' failed in phase `Assembler'. (Exit code: 1)
19+
make[1]: *** [rts/ghc.mk:325: rts/dist/build/StgCRun.o] Error 1
20+
21+
The source for this is
22+
> https://github.com/ghc/ghc/blob/1f02b7430b2fbab403d7ffdde9cfd006e884678e/rts/StgCRun.c#L433
23+
24+
It appears that GCC C17 12.2.0 does _not_ emit .cfi_startproc / .cfi_endprocs
25+
whereas GCC C17 13.2.0 _does_. Specificall x86_64-w64-mingw32-cc. So this might
26+
be a cross compilation issue.
27+
28+
The -g is hardcoded in
29+
https://github.com/ghc/ghc/blob/1f02b7430b2fbab403d7ffdde9cfd006e884678e/mk/config.mk.in#L361
30+
31+
Turns out, this was disabled for anything but linux in https://github.com/ghc/ghc/commit/5b08e0c06e038448a63aa9bd7f163b23d824ba4b,
32+
hence we backport that patch to GHC-8.10 when targeting windows (to prevent mass rebuilds for
33+
other archs).
34+
35+
--------------------------------------------------------------------------------
36+
2024-04-10 x86_64-linux.R2305.ghc902.mingwW64.ghc
37+
38+
make[1]: *** [utils/hsc2hs/ghc.mk:22: utils/hsc2hs/dist-install/build/tmp/hsc2hs.exe] Error 1
39+
utils/runghc/dist-install/build/Main.o:fake:(.text+0x2a): relocation truncated to fit: R_X86_64_32S against `.text'
40+
utils/runghc/dist-install/build/Main.o:fake:(.text+0x46): relocation truncated to fit: IMAGE_REL_AMD64_ADDR32 against `.data'
41+
utils/runghc/dist-install/build/Main.o:fake:(.text+0x8b): relocation truncated to fit: R_X86_64_32S against symbol `stg_bh_upd_frame_info' defined in .text section in /build/ghc-9.0.2/rts/dist/build/libHSrts.a(Updates.o)
42+
utils/runghc/dist-install/build/Main.o:fake:(.text+0x95): relocation truncated to fit: IMAGE_REL_AMD64_ADDR32 against `.rdata'
43+
utils/runghc/dist-install/build/Main.o:fake:(.text+0xe3): relocation truncated to fit: R_X86_64_32S against symbol `stg_bh_upd_frame_info' defined in .text section in /build/ghc-9.0.2/rts/dist/build/libHSrts.a(Updates.o)
44+
utils/runghc/dist-install/build/Main.o:fake:(.text+0xed): relocation truncated to fit: IMAGE_REL_AMD64_ADDR32 against `.rdata'
45+
utils/runghc/dist-install/build/Main.o:fake:(.text+0x13b): relocation truncated to fit: R_X86_64_32S against symbol `stg_bh_upd_frame_info' defined in .text section in /build/ghc-9.0.2/rts/dist/build/libHSrts.a(Updates.o)
46+
utils/runghc/dist-install/build/Main.o:fake:(.text+0x145): relocation truncated to fit: IMAGE_REL_AMD64_ADDR32 against `.rdata'
47+
utils/runghc/dist-install/build/Main.o:fake:(.text+0x193): relocation truncated to fit: R_X86_64_32S against symbol `stg_bh_upd_frame_info' defined in .text section in /build/ghc-9.0.2/rts/dist/build/libHSrts.a(Updates.o)
48+
utils/runghc/dist-install/build/Main.o:fake:(.text+0x19d): relocation truncated to fit: IMAGE_REL_AMD64_ADDR32 against `.rdata'
49+
utils/runghc/dist-install/build/Main.o:fake:(.text+0x1eb): additional relocation overflows omitted from the output
50+
51+
We notice `fake`, which is GHC failing to provide .file identifier in the source.
52+
We also see lots of R_X64_64_32S relocations, which are signed 32bit relocations.
53+
These fall with ASLR and high entropy base images from later binutils.
54+
55+
The underlying issue is that GHC emits _absolute_ label loads (mov $... reg), instead
56+
of %rpi or other relative loads. This then leads to the linker emitting 32bit
57+
absolute relocation. With the final image being potentially loaded into high memory
58+
(e.g. dynamic base, and the base image being set to some high address), the linker
59+
starts falling over itself, because it simply can't resolve those absolute addresses
60+
in the 32bit slots.
61+
62+
This was fixed in GHC upstream in https://gitlab.haskell.org/ghc/ghc/-/merge_requests/7449,
63+
while the patch in haskell.nix is a bit more pedestrian and just sets PIC on windows to
64+
always be on, and then uses the PIC pipeline.
65+
66+
--------------------------------------------------------------------------------
67+
2024-06-18 x86_64-linux.unstable.ghc9101.ucrt64.tests.th-dlls-minimal.build
68+
69+
0024:err:seh:call_stack_handlers invalid frame 00007FFFFF68EF18 (0000000000022000-0000000000220000)
70+
0024:err:seh:NtRaiseException Exception frame is not in stack limits => unable to dispatch exception.
71+
iserv-proxy: {handle: <socket: 11>}: GHCi.Message.remoteCall: end of file
72+
73+
This is due to GHC mislinking GNU import libraries (dll.a). What happens is that
74+
GHC ends up creating GOT entries for function calls instead of PLT entries. The
75+
loader/linker in GHC for Windows has logic to lazy load .dll's as referenced. For
76+
this symbols get a dependency symbol attached, this could be a symbol indicating
77+
the DLL that needs to be loaded. While walking the dependencies to find the dll to
78+
load (or in some cases just the dependent symbol, not the dll), we override the
79+
symbol type with the one of the dependent symbol. This however means we'll
80+
override the type of a symbol with the DATA type each time the symbol leads to a
81+
dllInstance to be loaded. Subsequently we end up creating a GOT entry instead of
82+
a PLT entry for the symbol, irrepsective of the original symbol being a code or
83+
data symbol. If code symbols end up getting GOT stubs, we see the above crash as
84+
the control flow jumps to the location of the stub, and instead of a PLT/jump
85+
island just lands in the address of the target symbol, which is in most cases
86+
non-sensical machine code.

build.nix

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ in rec {
6262
inherit evalPackages;
6363
src = pkgs.haskell-nix.sources."hls-2.2";
6464
};
65-
} // pkgs.lib.optionalAttrs (ghcFromTo "9.0" "9.9") {
66-
"hls-28" = tool compiler-nix-name "haskell-language-server" {
65+
} // pkgs.lib.optionalAttrs (ghcFromTo "9.0" "9.11") {
66+
"hls-29" = tool compiler-nix-name "haskell-language-server" {
6767
inherit evalPackages;
68-
src = pkgs.haskell-nix.sources."hls-2.8";
68+
src = pkgs.haskell-nix.sources."hls-2.9";
6969
};
7070
})
7171
);

builder/default.nix

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#
1414
# tl;dr: the builder must not re-introduce any reference to the build plan.
1515

16-
{ pkgs, buildPackages, evalPackages, stdenv, lib, haskellLib, ghc, compiler-nix-name, fetchurl, nonReinstallablePkgs, hsPkgs, compiler }:
16+
{ pkgs, buildPackages, pkgsBuildBuild, evalPackages, stdenv, lib, haskellLib, ghc, compiler-nix-name, fetchurl, nonReinstallablePkgs, hsPkgs, compiler }:
1717

1818
let
1919
# Builds a single component of a package.
@@ -64,13 +64,7 @@ let
6464
then pkgs.path
6565
else pkgs.haskell-nix.sources.nixpkgs-2205;
6666
nixpkgsHoogle = import (nixpkgs + /pkgs/development/haskell-modules/hoogle.nix);
67-
in { packages ? [], hoogle ? pkgs.buildPackages.haskell-nix.tool "ghc928" "hoogle" {
68-
inherit evalPackages;
69-
version = "5.0.18.3";
70-
# index-state = pkgs.haskell-nix.internalHackageIndexState;
71-
index-state = "2023-06-05T00:00:00Z";
72-
}
73-
}:
67+
in { packages ? [], hoogle }:
7468
let
7569
haskellPackages = {
7670
# For musl we can use haddock from the buildGHC
@@ -85,7 +79,7 @@ let
8579

8680
# Same as haskellPackages.shellFor in nixpkgs.
8781
shellFor = haskellLib.weakCallPackage pkgs ./shell-for.nix {
88-
inherit hsPkgs ghcForComponent makeConfigFiles hoogleLocal haskellLib buildPackages evalPackages compiler;
82+
inherit hsPkgs ghcForComponent makeConfigFiles hoogleLocal haskellLib pkgsBuildBuild evalPackages compiler;
8983
inherit (buildPackages) glibcLocales;
9084
};
9185

builder/shell-for.nix

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{ lib, stdenv, mkShell, glibcLocales, pkgconfig, ghcForComponent, makeConfigFiles, hsPkgs, hoogleLocal, haskellLib, buildPackages, evalPackages, compiler }:
1+
{ lib, stdenv, mkShell, glibcLocales, pkgconfig, ghcForComponent, makeConfigFiles, hsPkgs, hoogleLocal, haskellLib, pkgsBuildBuild, evalPackages, compiler }:
22

33
{ # `packages` function selects packages that will be worked on in the shell itself.
44
# These packages will not be built by `shellFor`, but their
@@ -142,21 +142,17 @@ let
142142
pname = p.identifier.name;
143143
haddockDir = p.haddockDir;
144144
};
145-
in hoogleLocal ({
145+
in hoogleLocal {
146146
packages = map docPackage (haskellLib.flatLibDepends component);
147147

148-
# Need to add hoogle to hsPkgs.
149-
# inherit (hsPkgs) hoogle;
150-
} // (
151-
lib.optionalAttrs (args ? tools && args.tools ? hoogle) {
152-
hoogle = buildPackages.haskell-nix.hackage-tool (
153-
haskellLib.versionOrModToMods args.tools.hoogle ++ [{
148+
hoogle = pkgsBuildBuild.haskell-nix.hackage-tool (
149+
lib.optionals (args ? tools && args.tools ? hoogle) (haskellLib.versionOrModToMods args.tools.hoogle)
150+
++ [{
154151
name = "hoogle";
155152
compiler-nix-name = compiler.nix-name;
156153
inherit evalPackages;
157154
}]);
158-
}
159-
));
155+
};
160156

161157
mkDrvArgs = builtins.removeAttrs args ["packages" "components" "additional" "withHoogle" "tools"];
162158
in
@@ -168,12 +164,12 @@ in
168164
nativeBuildInputs = [ ghcEnv.drv ]
169165
++ nativeBuildInputs
170166
++ mkDrvArgs.nativeBuildInputs or []
171-
++ lib.attrValues (buildPackages.haskell-nix.tools' evalPackages compiler.nix-name tools)
167+
++ lib.attrValues (pkgsBuildBuild.haskell-nix.tools' evalPackages compiler.nix-name tools)
172168
# If this shell is a cross compilation shell include
173169
# wrapper script for running cabal build with appropriate args.
174170
# Includes `--with-compiler` in case the `cabal.project` file has `with-compiler:` in it.
175171
++ lib.optional (ghcEnv.targetPrefix != "") (
176-
buildPackages.writeShellScriptBin "${ghcEnv.targetPrefix}cabal" ''
172+
pkgsBuildBuild.writeShellScriptBin "${ghcEnv.targetPrefix}cabal" ''
177173
exec cabal \
178174
--with-ghc=${ghcEnv.targetPrefix}ghc \
179175
--with-compiler=${ghcEnv.targetPrefix}ghc \

ci.nix

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,22 @@
2222
"R2211" = inputs.nixpkgs-2211;
2323
"R2305" = inputs.nixpkgs-2305;
2424
"R2311" = inputs.nixpkgs-2311;
25+
"R2405" = inputs.nixpkgs-2405;
2526
"unstable" = inputs.nixpkgs-unstable;
2627
};
2728

2829
nixpkgsArgs = {
2930
# set checkMaterialization as per top-level argument
3031
overlays = [
3132
haskellNix.overlay
32-
(_final: prev: {
33+
(final: prev: {
3334
haskell-nix = prev.haskell-nix // {
3435
inherit checkMaterialization;
36+
extraPkgconfigMappings = prev.haskell-nix.extraPkgconfigMappings or {} // {
37+
"libsodium" = [ "libsodium-18" ];
38+
};
3539
};
40+
libsodium-18 = (final.callPackage (inputs.nixpkgs-2311 + "/pkgs/development/libraries/libsodium") {}).overrideAttrs (_: { dontDisableStatic = true; });
3641
})
3742
];
3843
# Needed for dwarf tests
@@ -56,7 +61,7 @@
5661
# cabal-install and nix-tools plans. When removing a ghc version
5762
# from here (so that is no longer cached) also remove ./materialized/ghcXXX.
5863
# Update supported-ghc-versions.md to reflect any changes made here.
59-
nixpkgs.lib.optionalAttrs (nixpkgsName == "R2311") {
64+
nixpkgs.lib.optionalAttrs (nixpkgsName == "R2405") {
6065
ghc94 = false;
6166
ghc96 = false;
6267
ghc98 = false;
@@ -120,8 +125,6 @@ dimension "Nixpkgs version" nixpkgsVersions (nixpkgsName: pinnedNixpkgsSrc:
120125
ghc = pkgs.buildPackages.haskell-nix.compiler.${compiler-nix-name};
121126
} // pkgs.lib.optionalAttrs runTests {
122127
inherit (build) tests tools maintainer-scripts maintainer-script-cache;
123-
} // pkgs.lib.optionalAttrs (ifdLevel >= 2) {
124-
inherit (pkgs.haskell-nix.iserv-proxy-exes.${compiler-nix-name}) iserv-proxy;
125128
} // pkgs.lib.optionalAttrs (ifdLevel >= 3) {
126129
hello = (pkgs.haskell-nix.hackage-package { name = "hello"; version = "1.0.0.2"; inherit evalPackages compiler-nix-name; }).getComponent "exe:hello";
127130
});

compiler/ghc/default.nix

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,9 @@ let
251251
compiler-nix-name =
252252
if builtins.compareVersions ghc-version "9.4.7" < 0
253253
then "ghc928"
254-
else "ghc962";
254+
else if buildPackages.haskell.compiler ? ghc964
255+
then "ghc964"
256+
else "ghc962";
255257
in
256258
buildPackages.haskell-nix.tool compiler-nix-name "hadrian" {
257259
compilerSelection = p: p.haskell.compiler;
@@ -272,7 +274,9 @@ let
272274
then ../../materialized/${compiler-nix-name}/hadrian-ghc981
273275
else if builtins.compareVersions ghc-version "9.9" < 0
274276
then ../../materialized/${compiler-nix-name}/hadrian-ghc98
275-
else ../../materialized/${compiler-nix-name}/hadrian-ghc99;
277+
else if builtins.compareVersions ghc-version "9.11" < 0
278+
then ../../materialized/${compiler-nix-name}/hadrian-ghc910
279+
else null;
276280
modules = [{
277281
reinstallableLibGhc = false;
278282
# Apply the patches in a way that does not require using something
@@ -652,7 +656,7 @@ stdenv.mkDerivation (rec {
652656
# We could add `configured-src` as an output of the ghc derivation, but
653657
# having it as its own derivation means it can be accessed quickly without
654658
# building GHC.
655-
raw-src = stdenv.mkDerivation {
659+
raw-src = evalPackages: evalPackages.stdenv.mkDerivation {
656660
name = name + "-raw-src";
657661
inherit
658662
version
@@ -701,11 +705,16 @@ stdenv.mkDerivation (rec {
701705
${hadrian}/bin/hadrian ${hadrianArgs} _build/stage0/compiler/build/$a
702706
cp _build/stage0/compiler/build/$a compiler/GHC/Builtin/$a
703707
done
704-
'' + lib.optionalString stdenv.isDarwin ''
708+
'' + lib.optionalString (stdenv.isDarwin && (__tryEval libcxxabi).success) ''
705709
substituteInPlace mk/system-cxx-std-lib-1.0.conf \
706710
--replace 'dynamic-library-dirs:' 'dynamic-library-dirs: ${libcxx}/lib ${libcxxabi}/lib'
707711
find . -name 'system*.conf*'
708712
cat mk/system-cxx-std-lib-1.0.conf
713+
'' + lib.optionalString (stdenv.isDarwin && !(__tryEval libcxxabi).success) ''
714+
substituteInPlace mk/system-cxx-std-lib-1.0.conf \
715+
--replace 'dynamic-library-dirs:' 'dynamic-library-dirs: ${libcxx}/lib'
716+
find . -name 'system*.conf*'
717+
cat mk/system-cxx-std-lib-1.0.conf
709718
'' + lib.optionalString (installStage1 && stdenv.targetPlatform.isMusl) ''
710719
substituteInPlace hadrian/cfg/system.config \
711720
--replace 'cross-compiling = YES' \
@@ -786,11 +795,16 @@ stdenv.mkDerivation (rec {
786795
export XATTR=$(mktemp -d)/nothing
787796
'';
788797
} // lib.optionalAttrs useHadrian {
789-
postConfigure = lib.optionalString stdenv.isDarwin ''
798+
postConfigure = lib.optionalString (stdenv.isDarwin && (__tryEval libcxxabi).success) ''
790799
substituteInPlace mk/system-cxx-std-lib-1.0.conf \
791800
--replace 'dynamic-library-dirs:' 'dynamic-library-dirs: ${libcxx}/lib ${libcxxabi}/lib'
792801
find . -name 'system*.conf*'
793802
cat mk/system-cxx-std-lib-1.0.conf
803+
'' + lib.optionalString (stdenv.isDarwin && !(__tryEval libcxxabi).success) ''
804+
substituteInPlace mk/system-cxx-std-lib-1.0.conf \
805+
--replace 'dynamic-library-dirs:' 'dynamic-library-dirs: ${libcxx}/lib'
806+
find . -name 'system*.conf*'
807+
cat mk/system-cxx-std-lib-1.0.conf
794808
'' + lib.optionalString (installStage1 && !haskell-nix.haskellLib.isCrossTarget && stdenv.targetPlatform.isMusl) ''
795809
substituteInPlace hadrian/cfg/system.config \
796810
--replace 'cross-compiling = YES' \
@@ -850,12 +864,18 @@ stdenv.mkDerivation (rec {
850864
${hadrian}/bin/hadrian ${hadrianArgs} binary-dist-dir
851865
cd _build/bindist/ghc-*
852866
./configure --prefix=$out ${lib.concatStringsSep " " configureFlags}
853-
${lib.optionalString stdenv.isDarwin ''
867+
${lib.optionalString (stdenv.isDarwin && (__tryEval libcxxabi).success) ''
854868
substituteInPlace mk/system-cxx-std-lib-1.0.conf \
855869
--replace 'dynamic-library-dirs:' 'dynamic-library-dirs: ${libcxx}/lib ${libcxxabi}/lib'
856870
substituteInPlace lib/package.conf.d/system-cxx-std-lib-1.0.conf \
857871
--replace 'dynamic-library-dirs:' 'dynamic-library-dirs: ${libcxx}/lib ${libcxxabi}/lib'
858872
''}
873+
${lib.optionalString (stdenv.isDarwin && !(__tryEval libcxxabi).success) ''
874+
substituteInPlace mk/system-cxx-std-lib-1.0.conf \
875+
--replace 'dynamic-library-dirs:' 'dynamic-library-dirs: ${libcxx}/lib'
876+
substituteInPlace lib/package.conf.d/system-cxx-std-lib-1.0.conf \
877+
--replace 'dynamic-library-dirs:' 'dynamic-library-dirs: ${libcxx}/lib'
878+
''}
859879
mkdir -p utils
860880
cp -r ../../../utils/completion utils
861881
make install

default.nix

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,12 @@ self // {
8888
pkgs-2305 = import self.inputs.nixpkgs-2305 (nixpkgsArgs // {
8989
localSystem = { inherit system; };
9090
});
91+
pkgs-2311 = import self.inputs.nixpkgs-2311 (nixpkgsArgs // {
92+
localSystem = { inherit system; };
93+
});
94+
pkgs-2405 = import self.inputs.nixpkgs-2405 (nixpkgsArgs // {
95+
localSystem = { inherit system; };
96+
});
9197
pkgs-unstable = import self.inputs.nixpkgs-unstable (nixpkgsArgs // {
9298
localSystem = { inherit system; };
9399
});

0 commit comments

Comments
 (0)