Skip to content

Commit 1e19198

Browse files
committed
Merge remote-tracking branch 'origin/master' into hkm/embed-file
2 parents 4c5f268 + 2e2b43f commit 1e19198

File tree

134 files changed

+13510
-787
lines changed

Some content is hidden

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

134 files changed

+13510
-787
lines changed

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.

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: 25 additions & 5 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
@@ -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
});

flake.lock

Lines changed: 33 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,8 @@
1010
nixpkgs-2211 = { url = "github:NixOS/nixpkgs/nixpkgs-22.11-darwin"; };
1111
nixpkgs-2305 = { url = "github:NixOS/nixpkgs/nixpkgs-23.05-darwin"; };
1212
nixpkgs-2311 = { url = "github:NixOS/nixpkgs/nixpkgs-23.11-darwin"; };
13-
# The libsodium bump in 85c6e70b555fe892a049fa3d9dce000dc23a9562 breaks th-dll tests.
14-
# And later it breaks in th-dll due to some change in the windows libs. We should probably
15-
# drop unsable.
16-
nixpkgs-unstable = { url = "github:NixOS/nixpkgs?rev=47585496bcb13fb72e4a90daeea2f434e2501998"; }; # nixpkgs-unstable };
13+
nixpkgs-2405 = { url = "github:NixOS/nixpkgs/nixpkgs-24.05-darwin"; };
14+
nixpkgs-unstable = { url = "github:NixOS/nixpkgs/nixpkgs-unstable"; };
1715
flake-compat = { url = "github:input-output-hk/flake-compat/hkm/gitlab-fix"; flake = false; };
1816
"hls-1.10" = { url = "github:haskell/haskell-language-server/1.10.0.0"; flake = false; };
1917
"hls-2.0" = { url = "github:haskell/haskell-language-server/2.0.0.1"; flake = false; };
@@ -85,6 +83,7 @@
8583
, nixpkgs-2211
8684
, nixpkgs-2305
8785
, nixpkgs-2311
86+
, nixpkgs-2405
8887
, flake-compat
8988
, ...
9089
}@inputs:

lib/call-cabal-project-to-nix.nix

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,9 +268,14 @@ let
268268
sourceRepos = sourceReposBuild;
269269
inherit (repoResult) repos extra-hackages;
270270
makeFixedProjectFile = ''
271+
HOME=$(mktemp -d)
271272
cp -f ${evalPackages.writeText "cabal.project" sourceRepoFixedProjectFile} ./cabal.project
272273
chmod +w -R ./cabal.project
273-
'';
274+
'' + pkgs.lib.strings.concatStrings (
275+
map (f: ''
276+
git config --global --add safe.directory ${f.location}/.git
277+
'') sourceReposEval
278+
);
274279
# This will be used to replace refernces to the minimal git repos with just the index
275280
# of the repo. The index will be used in lib/import-and-filter-project.nix to
276281
# lookup the correct repository in `sourceReposBuild`. This avoids having

lib/pkgconf-nixpkgs-map.nix

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ pkgs:
66

77
# Only include derivations that exist in the current pkgs.
88
# This allows us to use this mapping to be used in allPkgConfigWrapper.
9-
# See ./overlas
9+
# See ./overlays
1010
lookupAttrsIn = x: __mapAttrs (_pname: names:
11-
# The first entry is should be used for the version by allPkgConfigWrapper
12-
# so we need it to be present.
13-
if __length names != 0 && x ? ${__head names}
14-
then
15-
pkgs.lib.concatMap (
16-
name: if x ? ${name} then [ x.${name} ] else []) names
17-
else []);
11+
# The first entry is should be used for the version by allPkgConfigWrapper
12+
# so we need it to be present.
13+
with lib; optionals (__length names != 0 && x ? ${__head names})
14+
(concatMap
15+
(name: optionals (x ? ${name})
16+
(let p = __tryEval (x.${name}); in optional p.success p.value))
17+
names));
1818
in lookupAttrsIn pkgs ({
1919
# Based on https://github.com/NixOS/cabal2nix/blob/11c68fdc79461fb74fa1dfe2217c3709168ad752/src/Distribution/Nixpkgs/Haskell/FromCabal/Name.hs#L23
2020

0 commit comments

Comments
 (0)