Skip to content

Commit

Permalink
[win] fix Error: CFI instruction used without previous .cfi_startproc
Browse files Browse the repository at this point in the history
  • Loading branch information
angerman committed Apr 9, 2024
1 parent c9b9ab5 commit d9dc867
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 0 deletions.
35 changes: 35 additions & 0 deletions BUGLOG
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
This file contains bugs we find while working on haskell.nix. The format is as
follow:
<separator: 80 * '-'>
YYYY-MM-DD: nix-job name

<error>

<discussion>

--------------------------------------------------------------------------------
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).

--------------------------------------------------------------------------------
1 change: 1 addition & 0 deletions overlays/bootstrap.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
From 5b08e0c06e038448a63aa9bd7f163b23d824ba4b Mon Sep 17 00:00:00 2001
From: Ben Gamari <[email protected]>
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) */

);
/*

0 comments on commit d9dc867

Please sign in to comment.