Skip to content

Commit d7b8a32

Browse files
angermanhamishmack
andauthored
Fix th-dlls for windows (input-output-hk#2049)
* [win] fix linker null deref * Only 9.6+ then. * More custom 9.4 patches * msvcrt before mingwex * Update bootstrap.nix * Bring back msvcrt symbols * 🤦 * 9.4 msvcrt where we have mingwx * Ok, then drop it instead * Fix file name * Update patch bounds * ifdLevel 1 * ifdLevel 3 * Possible fix for windows ghc 9.4.7 th-dlls * Skip macOS th-dll tests * Run tests for GHC head * Fix no-urct patch so it applies * ghc-patches are applied before booting * ifdLevel 1 * ifdLevel 2 * ifdLevel 3 * Fix crypton-x509-system on windows * Disable still broken tests --------- Co-authored-by: Hamish Mackenzie <[email protected]>
1 parent 15bf10a commit d7b8a32

13 files changed

+205
-10
lines changed

ci.nix

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,17 +105,17 @@
105105
)) {
106106
inherit (lib.systems.examples) ghcjs;
107107
} // lib.optionalAttrs (nixpkgsName == "unstable"
108-
&& ((system == "x86_64-linux" && builtins.elem compiler-nix-name ["ghc8107" "ghc902" "ghc926" "ghc927" "ghc928" "ghc947" "ghc962" (ghc980X nixpkgs) (ghc980X nixpkgs)])
108+
&& ((system == "x86_64-linux" && builtins.elem compiler-nix-name ["ghc8107" "ghc902" "ghc926" "ghc927" "ghc928" "ghc947" "ghc962" (ghc980X nixpkgs) (ghc99X nixpkgs)])
109109
|| (system == "x86_64-darwin" && builtins.elem compiler-nix-name []))) { # TODO add ghc versions when we have more darwin build capacity
110110
inherit (lib.systems.examples) mingwW64;
111-
} // lib.optionalAttrs (system == "x86_64-linux" && nixpkgsName == "unstable" && builtins.elem compiler-nix-name ["ghc8107" "ghc902" "ghc922" "ghc923" "ghc924" "ghc926" "ghc927" "ghc928" "ghc947" "ghc962" (ghc980X nixpkgs) (ghc980X nixpkgs)]) {
111+
} // lib.optionalAttrs (system == "x86_64-linux" && nixpkgsName == "unstable" && builtins.elem compiler-nix-name ["ghc8107" "ghc902" "ghc922" "ghc923" "ghc924" "ghc926" "ghc927" "ghc928" "ghc947" "ghc962" (ghc980X nixpkgs) (ghc99X nixpkgs)]) {
112112
# Musl cross only works on linux
113113
# aarch64 cross only works on linux
114114
inherit (lib.systems.examples) musl64 aarch64-multiplatform;
115115
} // lib.optionalAttrs (system == "x86_64-linux" && nixpkgsName == "unstable" && builtins.elem compiler-nix-name ["ghc927" "ghc928"]) {
116116
# TODO fix this for the compilers we build with hadrian (ghc >=9.4)
117117
inherit (lib.systems.examples) aarch64-multiplatform-musl;
118-
} // lib.optionalAttrs (system == "aarch64-linux" && nixpkgsName == "unstable" && builtins.elem compiler-nix-name ["ghc927" "ghc928" "ghc947" "ghc962" (ghc980X nixpkgs) (ghc980X nixpkgs)]) {
118+
} // lib.optionalAttrs (system == "aarch64-linux" && nixpkgsName == "unstable" && builtins.elem compiler-nix-name ["ghc927" "ghc928" "ghc947" "ghc962" (ghc980X nixpkgs) (ghc99X nixpkgs)]) {
119119
inherit (lib.systems.examples) aarch64-multiplatform-musl;
120120
};
121121
isDisabled = d: d.meta.disabled or false;

overlays/bootstrap.nix

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,17 @@ in {
193193
# by another crt.
194194
++ final.lib.optionals (final.stdenv.targetPlatform.isWindows) (fromUntil "8.10" "9.8" ./patches/ghc/win-linker-no-ucrt.patch)
195195
# Nixos/nixpkgs is mscvrt for now, thus we must disable ucrt in ghc, otherwise we end up with broken linking.
196-
++ final.lib.optionals (final.stdenv.targetPlatform.isWindows) (fromUntil "9.6" "9.8" ./patches/ghc/no-ucrt.patch)
196+
++ final.lib.optionals (final.stdenv.targetPlatform.isWindows) (fromUntil "9.4.1" "9.6" ./patches/ghc/no-ucrt-9.4.patch)
197+
++ final.lib.optionals (final.stdenv.targetPlatform.isWindows) (fromUntil "9.6.1" "9.8" ./patches/ghc/no-ucrt-9.6.patch)
198+
++ final.lib.optionals (final.stdenv.targetPlatform.isWindows) (fromUntil "9.8" "9.9" ./patches/ghc/no-ucrt-9.8.patch)
199+
++ final.lib.optionals (final.stdenv.targetPlatform.isWindows) (fromUntil "9.9" "9.10" ./patches/ghc/no-ucrt-9.9.patch)
200+
++ final.lib.optionals (final.stdenv.targetPlatform.isWindows) (fromUntil "9.4.7" "9.5" ./patches/ghc/revert-289547580b6f2808ee123f106c3118b716486d5b.patch)
201+
++ final.lib.optionals (final.stdenv.targetPlatform.isWindows) (fromUntil "9.8.0" "9.10" ./patches/ghc/revert-289547580b6f2808ee123f106c3118b716486d5b.patch)
197202
# the following is needed for cardano-prelude as it uses closure_sizeW :-/
198-
++ final.lib.optionals (final.stdenv.targetPlatform.isWindows) (fromUntil "9.6" "9.8" ./patches/ghc/win-add-closure_sizeW-to-rtssyms.patch)
203+
++ final.lib.optionals (final.stdenv.targetPlatform.isWindows) (fromUntil "9.6" "9.10" ./patches/ghc/win-add-closure_sizeW-to-rtssyms.patch)
204+
++ final.lib.optionals (final.stdenv.targetPlatform.isWindows) (fromUntil "9.4.1" "9.6" ./patches/ghc/win-linker-no-null-deref-9.4.patch)
205+
++ final.lib.optionals (final.stdenv.targetPlatform.isWindows) (fromUntil "9.4.1" "9.6" ./patches/ghc/ghc-9.4-drop-mingwex-from-base.patch)
206+
++ final.lib.optionals (final.stdenv.targetPlatform.isWindows) (fromUntil "9.6.1" "9.8" ./patches/ghc/win-linker-no-null-deref.patch)
199207
++ fromUntil "9.4.5" "9.4.8" ./patches/ghc/ghc-9.4.5-include-order-fix.patch
200208
++ fromUntil "9.6.2" "9.8" ./patches/ghc/ghc-9.4.5-include-order-fix.patch
201209
++ fromUntil "9.6.1" "9.10" ./patches/ghc/MR10116.patch
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
diff --git a/crypton-x509-system.cabal b/crypton-x509-system.cabal
2+
index 95a21a1..8b23b3d 100644
3+
--- a/crypton-x509-system.cabal
4+
+++ b/crypton-x509-system.cabal
5+
@@ -32,7 +32,7 @@ Library
6+
if os(windows)
7+
cpp-options: -DWINDOWS
8+
Build-Depends: Win32, asn1-encoding
9+
- extra-libraries: Crypt32
10+
+ extra-libraries: crypt32
11+
Exposed-modules: System.X509.Win32
12+
if os(OSX)
13+
cpp-options: -DMACOSX
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
diff --git a/libraries/base/base.cabal b/libraries/base/base.cabal
2+
index 4df1bae..8e20826 100644
3+
--- a/libraries/base/base.cabal
4+
+++ b/libraries/base/base.cabal
5+
@@ -390,7 +390,7 @@ Library
6+
-- advapi32: provides advanced kernel functions
7+
extra-libraries:
8+
wsock32, user32, shell32, mingw32, kernel32, advapi32,
9+
- mingwex, ws2_32, shlwapi, ole32, rpcrt4, ntdll
10+
+ ws2_32, shlwapi, ole32, rpcrt4, ntdll
11+
-- Minimum supported Windows version.
12+
-- These numbers can be found at:
13+
-- https://msdn.microsoft.com/en-us/library/windows/desktop/aa383745(v=vs.85).aspx
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
diff --git a/libraries/ghc-prim/ghc-prim.cabal b/libraries/ghc-prim/ghc-prim.cabal
2+
index 5393363..4f5db98 100644
3+
--- a/libraries/ghc-prim/ghc-prim.cabal
4+
+++ b/libraries/ghc-prim/ghc-prim.cabal
5+
@@ -73,7 +73,7 @@ Library
6+
-- mingw32 which is required by mingwex.
7+
-- user32: provides access to apis to modify user components (UI etc)
8+
-- on Windows. Required because of mingw32.
9+
- extra-libraries: user32, mingw32, mingwex, ucrt
10+
+ extra-libraries: user32, mingw32, msvcrt, mingwex
11+
12+
if os(linux)
13+
-- we need libm, but for musl and other's we might need libc, as libm
14+
diff --git a/m4/fp_setup_windows_toolchain.m4 b/m4/fp_setup_windows_toolchain.m4
15+
index 1f44a38..122a205 100644
16+
--- a/m4/fp_setup_windows_toolchain.m4
17+
+++ b/m4/fp_setup_windows_toolchain.m4
18+
@@ -86,7 +86,7 @@ AC_DEFUN([FP_SETUP_WINDOWS_TOOLCHAIN],[
19+
# Signal that we are linking against UCRT with the _UCRT macro. This is
20+
# necessary to ensure correct behavior when MinGW-w64 headers are in the
21+
# header include path (#22159).
22+
- cflags="--rtlib=compiler-rt -D_UCRT"
23+
+ cflags=""
24+
CFLAGS="$cflags"
25+
CONF_CC_OPTS_STAGE1="$cflags"
26+
CONF_CC_OPTS_STAGE2="$cflags"
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
diff --git a/libraries/ghc-prim/ghc-prim.cabal b/libraries/ghc-prim/ghc-prim.cabal.in
2+
index 5393363..4f5db98 100644
3+
--- a/libraries/ghc-prim/ghc-prim.cabal.in
4+
+++ b/libraries/ghc-prim/ghc-prim.cabal.in
5+
@@ -73,7 +73,7 @@ Library
6+
-- mingw32 which is required by mingwex.
7+
-- user32: provides access to apis to modify user components (UI etc)
8+
-- on Windows. Required because of mingw32.
9+
- extra-libraries: user32, mingw32, mingwex, ucrt
10+
+ extra-libraries: user32, mingw32, msvcrt, mingwex
11+
12+
if os(linux)
13+
-- we need libm, but for musl and other's we might need libc, as libm
14+
diff --git a/m4/fp_setup_windows_toolchain.m4 b/m4/fp_setup_windows_toolchain.m4
15+
index 1f44a38..122a205 100644
16+
--- a/m4/fp_setup_windows_toolchain.m4
17+
+++ b/m4/fp_setup_windows_toolchain.m4
18+
@@ -86,7 +86,7 @@ AC_DEFUN([FP_SETUP_WINDOWS_TOOLCHAIN],[
19+
# Signal that we are linking against UCRT with the _UCRT macro. This is
20+
# necessary to ensure correct behavior when MinGW-w64 headers are in the
21+
# header include path (#22159).
22+
- cflags="--rtlib=compiler-rt -D_UCRT"
23+
+ cflags=""
24+
CFLAGS="$cflags"
25+
CONF_CC_OPTS_STAGE1="$cflags"
26+
CONF_CC_OPTS_STAGE2="$cflags"
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
diff --git a/libraries/ghc-prim/ghc-prim.cabal b/libraries/ghc-prim/ghc-prim.cabal.in
2+
index 5393363..4f5db98 100644
3+
--- a/libraries/ghc-prim/ghc-prim.cabal.in
4+
+++ b/libraries/ghc-prim/ghc-prim.cabal.in
5+
@@ -73,7 +73,7 @@ Library
6+
-- mingw32 which is required by mingwex.
7+
-- user32: provides access to apis to modify user components (UI etc)
8+
-- on Windows. Required because of mingw32.
9+
- extra-libraries: user32, mingw32, mingwex, ucrt
10+
+ extra-libraries: user32, mingw32, msvcrt, mingwex
11+
12+
if os(linux)
13+
-- we need libm, but for musl and other's we might need libc, as libm
14+
diff --git a/m4/fp_setup_windows_toolchain.m4 b/m4/fp_setup_windows_toolchain.m4
15+
index 1f44a38..122a205 100644
16+
--- a/m4/fp_setup_windows_toolchain.m4
17+
+++ b/m4/fp_setup_windows_toolchain.m4
18+
@@ -86,7 +86,7 @@ AC_DEFUN([FP_SETUP_WINDOWS_TOOLCHAIN],[
19+
# Signal that we are linking against UCRT with the _UCRT macro. This is
20+
# necessary to ensure correct behavior when MinGW-w64 headers are in the
21+
# header include path (#22159).
22+
- cflags="--rtlib=compiler-rt -D_UCRT"
23+
+ cflags=""
24+
CFLAGS="$cflags -I$mingwinclude"
25+
CONF_CC_OPTS_STAGE1="$cflags -I$mingwinclude"
26+
CONF_CC_OPTS_STAGE2="$cflags -I$mingwinclude"
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
From 289547580b6f2808ee123f106c3118b716486d5b Mon Sep 17 00:00:00 2001
2+
From: Ryan Scott <[email protected]>
3+
Date: Fri, 28 Apr 2023 07:55:33 -0400
4+
Subject: [PATCH] RtsSymbols.c: Remove mingwex symbol stubs
5+
6+
As of !9475, the RTS now links against `ucrt` instead of `msvcrt` on Windows,
7+
which means that the RTS no longer needs to declare stubs for the `__mingw_*`
8+
family of symbols. Let's remove these stubs to avoid confusion.
9+
10+
Fixes #23309.
11+
---
12+
rts/RtsSymbols.c | 8 +-------
13+
1 file changed, 1 insertion(+), 7 deletions(-)
14+
15+
diff --git a/rts/RtsSymbols.c b/rts/RtsSymbols.c
16+
index 70b72ce602e..a0167c323f5 100644
17+
--- a/rts/RtsSymbols.c
18+
+++ b/rts/RtsSymbols.c
19+
@@ -176,11 +176,17 @@ extern char **environ;
20+
/* see Note [Symbols for MinGW's printf] */ \
21+
SymI_HasProto(_lock_file) \
22+
SymI_HasProto(_unlock_file) \
23+
+ SymI_HasProto(__mingw_vsnwprintf) \
24+
+ /* ^^ Need to figure out why this is needed. */ \
25+
/* See Note [_iob_func symbol] */ \
26+
RTS_WIN64_ONLY(SymI_HasProto_redirect( \
27+
__imp___acrt_iob_func, __rts_iob_func, STRENGTH_WEAK, SYM_TYPE_INDIRECT_DATA)) \
28+
RTS_WIN32_ONLY(SymI_HasProto_redirect( \
29+
+ __imp____acrt_iob_func, __rts_iob_func, STRENGTH_WEAK, SYM_TYPE_INDIRECT_DATA)) \
30+
+ SymI_HasProto(__mingw_vsnwprintf) \
31+
+ /* ^^ Need to figure out why this is needed. */ \
32+
+ SymI_HasProto(__mingw_vfprintf) \
33+
+ /* ^^ Need to figure out why this is needed. */
34+
- __imp____acrt_iob_func, __rts_iob_func, STRENGTH_WEAK, SYM_TYPE_INDIRECT_DATA))
35+
#else
36+
#define RTS_MINGW_ONLY_SYMBOLS /**/
37+
#endif
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
diff --git a/rts/linker/PEi386.c b/rts/linker/PEi386.c
2+
index beee293..e05ecdb 100644
3+
--- a/rts/linker/PEi386.c
4+
+++ b/rts/linker/PEi386.c
5+
@@ -1818,16 +1818,10 @@ ocGetNames_PEi386 ( ObjectCode* oc )
6+
7+
uint32_t targetSecNumber = getSymSectionNumber (info, targetSym);
8+
Section *targetSection;
9+
- switch (targetSecNumber) {
10+
- case PE_SECTION_UNDEFINED:
11+
- case PE_SECTION_ABSOLUTE:
12+
- case PE_SECTION_DEBUG:
13+
- targetSection = NULL;
14+
- break;
15+
- default:
16+
- targetSection = &oc->sections[targetSecNumber-1];
17+
+ if(targetSecNumber > 0) {
18+
+ Section *targetSection = &oc->sections[targetSecNumber-1];
19+
+ addr = (SymbolAddr*) ((size_t) targetSection->start + getSymValue(info, targetSym));
20+
}
21+
- addr = (SymbolAddr*) ((size_t) targetSection->start + getSymValue(info, targetSym));
22+
}
23+
else if ( secNumber == IMAGE_SYM_UNDEFINED && symValue > 0) {
24+
/* This symbol isn't in any section at all, ie, global bss.

0 commit comments

Comments
 (0)