From d9dc867c091f1b1495736fc926f9ec825e55afe1 Mon Sep 17 00:00:00 2001 From: Moritz Angermann Date: Tue, 9 Apr 2024 07:01:27 +0000 Subject: [PATCH] [win] fix Error: CFI instruction used without previous .cfi_startproc --- BUGLOG | 35 ++++++++++ overlays/bootstrap.nix | 1 + ...e0c06e038448a63aa9bd7f163b23d824ba4b.patch | 66 +++++++++++++++++++ 3 files changed, 102 insertions(+) create mode 100644 BUGLOG create mode 100644 overlays/patches/ghc/5b08e0c06e038448a63aa9bd7f163b23d824ba4b.patch diff --git a/BUGLOG b/BUGLOG new file mode 100644 index 0000000000..5d781b522a --- /dev/null +++ b/BUGLOG @@ -0,0 +1,35 @@ +This file contains bugs we find while working on haskell.nix. The format is as +follow: + +YYYY-MM-DD: nix-job name + + + + + +-------------------------------------------------------------------------------- +2024-04-09 x86_64-linux.R2305.ghc8107.mingwW64.ghc + +/build/ghc62733_0/ghc_1.s:50:0: error: + Error: CFI instruction used without previous .cfi_startproc + | +50 | .cfi_escape 0x16, 0x07, 0x04, 0x77, 152, 65 + | ^ +`x86_64-w64-mingw32-cc' failed in phase `Assembler'. (Exit code: 1) +make[1]: *** [rts/ghc.mk:325: rts/dist/build/StgCRun.o] Error 1 + +The source for this is +> https://github.com/ghc/ghc/blob/1f02b7430b2fbab403d7ffdde9cfd006e884678e/rts/StgCRun.c#L433 + +It appears that GCC C17 12.2.0 does _not_ emit .cfi_startproc / .cfi_endprocs +whereas GCC C17 13.2.0 _does_. Specificall x86_64-w64-mingw32-cc. So this might +be a cross compilation issue. + +The -g is hardcoded in +https://github.com/ghc/ghc/blob/1f02b7430b2fbab403d7ffdde9cfd006e884678e/mk/config.mk.in#L361 + +Turns out, this was disabled for anything but linux in https://github.com/ghc/ghc/commit/5b08e0c06e038448a63aa9bd7f163b23d824ba4b, +hence we backport that patch to GHC-8.10 when targeting windows (to prevent mass rebuilds for +other archs). + +-------------------------------------------------------------------------------- diff --git a/overlays/bootstrap.nix b/overlays/bootstrap.nix index 1307108768..82771193f7 100644 --- a/overlays/bootstrap.nix +++ b/overlays/bootstrap.nix @@ -253,6 +253,7 @@ in { ++ final.lib.optional (versionAtLeast "8.10" && versionLessThan "9.4" && final.stdenv.targetPlatform != final.stdenv.hostPlatform) ./patches/ghc/ghc-make-stage-1-lib-ghc.patch ++ final.lib.optional (versionAtLeast "8.10" && versionLessThan "9.0" && final.stdenv.targetPlatform.isAarch64) ./patches/ghc/ghc-8.10-better-symbol-addr-debug.patch ++ final.lib.optional (versionAtLeast "8.10" && versionLessThan "9.0" && final.stdenv.targetPlatform.isAarch64) ./patches/ghc/ghc-8.10-aarch64-handle-none-rela.patch + ++ final.lib.optional (versionAtLeast "8.10" && versionLessThan "9.0" && final.stdenv.targetPlatform.isWindows) ./patches/ghc/5b08e0c06e038448a63aa9bd7f163b23d824ba4b.patch ++ final.lib.optional (versionAtLeast "9.0" && final.stdenv.targetPlatform.isAarch64) ./patches/ghc/ghc-9.0-better-symbol-addr-debug.patch ++ final.lib.optional (versionAtLeast "9.0" && final.stdenv.targetPlatform.isAarch64) ./patches/ghc/ghc-9.0-aarch64-handle-none-rela.patch ++ final.lib.optional (versionAtLeast "9.6.3" && versionLessThan "9.6.4" && final.stdenv.targetPlatform.isWindows) ./patches/ghc/ghc-9.6-hadrian-splitsections.patch diff --git a/overlays/patches/ghc/5b08e0c06e038448a63aa9bd7f163b23d824ba4b.patch b/overlays/patches/ghc/5b08e0c06e038448a63aa9bd7f163b23d824ba4b.patch new file mode 100644 index 0000000000..5ed25cb5ec --- /dev/null +++ b/overlays/patches/ghc/5b08e0c06e038448a63aa9bd7f163b23d824ba4b.patch @@ -0,0 +1,66 @@ +From 5b08e0c06e038448a63aa9bd7f163b23d824ba4b Mon Sep 17 00:00:00 2001 +From: Ben Gamari +Date: Mon, 3 Feb 2020 09:27:42 -0500 +Subject: [PATCH] StgCRun: Enable unwinding only on Linux + +It's broken on macOS due and SmartOS due to assembler differences +(#15207) so let's be conservative in enabling it. Also, refactor things +to make the intent clearer. +--- + rts/StgCRun.c | 15 +++++++++++---- + 1 file changed, 11 insertions(+), 4 deletions(-) + +diff --git a/rts/StgCRun.c b/rts/StgCRun.c +index 2600f1e569ca..55a3bf0c2d97 100644 +--- a/rts/StgCRun.c ++++ b/rts/StgCRun.c +@@ -29,6 +29,13 @@ + #include "PosixSource.h" + #include "ghcconfig.h" + ++// Enable DWARF Call-Frame Information (used for stack unwinding) on Linux. ++// This is not supported on Darwin and SmartOS due to assembler differences ++// (#15207). ++#if defined(linux_HOST_OS) ++#define ENABLE_UNWINDING ++#endif ++ + #if defined(sparc_HOST_ARCH) || defined(USE_MINIINTERPRETER) + /* include Stg.h first because we want real machine regs in here: we + * have to get the value of R1 back from Stg land to C land intact. +@@ -405,7 +412,7 @@ StgRunIsImplementedInAssembler(void) + "movq %%xmm15,136(%%rax)\n\t" + #endif + +-#if !defined(darwin_HOST_OS) ++#if defined(ENABLE_UNWINDING) + /* + * Let the unwinder know where we saved the registers + * See Note [Unwinding foreign exports on x86-64]. +@@ -444,7 +451,7 @@ StgRunIsImplementedInAssembler(void) + #error "RSP_DELTA too big" + #endif + "\n\t" +-#endif /* !defined(darwin_HOST_OS) */ ++#endif /* defined(ENABLE_UNWINDING) */ + + /* + * Set BaseReg +@@ -519,7 +526,7 @@ StgRunIsImplementedInAssembler(void) + "i"(RESERVED_C_STACK_BYTES + STG_RUN_STACK_FRAME_SIZE + /* rip relative to cfa */) + +-#if !defined(darwin_HOST_OS) ++#if defined(ENABLE_UNWINDING) + , "i"((RSP_DELTA & 127) | (128 * ((RSP_DELTA >> 7) > 0))) + /* signed LEB128-encoded delta from rsp - byte 1 */ + #if (RSP_DELTA >> 7) > 0 +@@ -538,7 +545,7 @@ StgRunIsImplementedInAssembler(void) + #endif + #undef RSP_DELTA + +-#endif /* !defined(darwin_HOST_OS) */ ++#endif /* defined(ENABLE_UNWINDING) */ + + ); + /*