Skip to content

Commit 457148a

Browse files
committed
guix: fix GCC 10.3.0 + mingw-w64 setjmp/longjmp issues
This commit backports a patch to the GCC 10.3.0 we build for Windows cross-compilation in Guix. The commit has been backported to the GCC releases/gcc-10 branch, but hasn't yet made it into a release. The patch corrects a regression from an earlier GCC commit, see: https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=357c4350680bf29f0c7a115424e3da11c53b5582 and https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=074226d5aa86cd3de517014acfe34c7f69a2ccc7, related to the way newer versions of mingw-w64 implement setjmp/longjmp. Ultimately this was causing a crash for us when Windows users were viewing the network traffic tab inside the GUI. After some period, long enough that a buffer would need reallocating, a call into FreeTypes gray_record_cell() would result in a call to ft_longjmp (longjmp), which would then trigger a crash. Fixes: bitcoin-core/gui#582. See also: https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=e8d1ca7d2c344a411779892616c423e157f4aea8. https://bugreports.qt.io/browse/QTBUG-93476.
1 parent f60a63c commit 457148a

File tree

2 files changed

+72
-3
lines changed

2 files changed

+72
-3
lines changed

contrib/guix/manifest.scm

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,17 +162,18 @@ desirable for building Bitcoin Core release binaries."
162162
(define (make-gcc-with-pthreads gcc)
163163
(package-with-extra-configure-variable gcc "--enable-threads" "posix"))
164164

165-
(define (make-mingw-w64-cross-gcc-vmov-alignment cross-gcc)
165+
(define (make-mingw-w64-cross-gcc cross-gcc)
166166
(package-with-extra-patches cross-gcc
167-
(search-our-patches "vmov-alignment.patch")))
167+
(search-our-patches "vmov-alignment.patch"
168+
"gcc-broken-longjmp.patch")))
168169

169170
(define (make-mingw-pthreads-cross-toolchain target)
170171
"Create a cross-compilation toolchain package for TARGET"
171172
(let* ((xbinutils (cross-binutils target))
172173
(pthreads-xlibc mingw-w64-x86_64-winpthreads)
173174
(pthreads-xgcc (make-gcc-with-pthreads
174175
(cross-gcc target
175-
#:xgcc (make-ssp-fixed-gcc (make-mingw-w64-cross-gcc-vmov-alignment base-gcc))
176+
#:xgcc (make-ssp-fixed-gcc (make-mingw-w64-cross-gcc base-gcc))
176177
#:xbinutils xbinutils
177178
#:libc pthreads-xlibc))))
178179
;; Define a meta-package that propagates the resulting XBINUTILS, XLIBC, and
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
commit eb5698897c52702498938592d7f76e67d126451f
2+
Author: Eric Botcazou <[email protected]>
3+
Date: Wed May 5 22:48:51 2021 +0200
4+
5+
Fix PR target/100402
6+
7+
This is a regression for 64-bit Windows present from mainline down to the 9
8+
branch and introduced by the fix for PR target/99234. Again SEH, but with
9+
a twist related to the way MinGW implements setjmp/longjmp, which turns out
10+
to be piggybacked on SEH with recent versions of MinGW, i.e. the longjmp
11+
performs a bona-fide unwinding of the stack, because it calls RtlUnwindEx
12+
with the second argument initially passed to setjmp, which is the result of
13+
__builtin_frame_address (0) in the MinGW header file:
14+
15+
define setjmp(BUF) _setjmp((BUF), __builtin_frame_address (0))
16+
17+
This means that we directly expose the frame pointer to the SEH machinery
18+
here (unlike with regular exception handling where we use an intermediate
19+
CFA) and thus that we cannot do whatever we want with it. The old code
20+
would leave it unaligned, i.e. not multiple of 16, whereas the new code
21+
aligns it, but this breaks for some reason; at least it appears that a
22+
.seh_setframe directive with 0 as second argument always works, so the
23+
fix aligns it this way.
24+
25+
gcc/
26+
PR target/100402
27+
* config/i386/i386.c (ix86_compute_frame_layout): For a SEH target,
28+
always return the establisher frame for __builtin_frame_address (0).
29+
gcc/testsuite/
30+
* gcc.c-torture/execute/20210505-1.c: New test.
31+
32+
diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
33+
index 2f838840e96..06ad1b2274e 100644
34+
--- a/gcc/config/i386/i386.c
35+
+++ b/gcc/config/i386/i386.c
36+
@@ -6356,12 +6356,29 @@ ix86_compute_frame_layout (void)
37+
area, see the SEH code in config/i386/winnt.c for the rationale. */
38+
frame->hard_frame_pointer_offset = frame->sse_reg_save_offset;
39+
40+
- /* If we can leave the frame pointer where it is, do so. Also, return
41+
+ /* If we can leave the frame pointer where it is, do so; however return
42+
the establisher frame for __builtin_frame_address (0) or else if the
43+
- frame overflows the SEH maximum frame size. */
44+
+ frame overflows the SEH maximum frame size.
45+
+
46+
+ Note that the value returned by __builtin_frame_address (0) is quite
47+
+ constrained, because setjmp is piggybacked on the SEH machinery with
48+
+ recent versions of MinGW:
49+
+
50+
+ # elif defined(__SEH__)
51+
+ # if defined(__aarch64__) || defined(_ARM64_)
52+
+ # define setjmp(BUF) _setjmp((BUF), __builtin_sponentry())
53+
+ # elif (__MINGW_GCC_VERSION < 40702)
54+
+ # define setjmp(BUF) _setjmp((BUF), mingw_getsp())
55+
+ # else
56+
+ # define setjmp(BUF) _setjmp((BUF), __builtin_frame_address (0))
57+
+ # endif
58+
+
59+
+ and the second argument passed to _setjmp, if not null, is forwarded
60+
+ to the TargetFrame parameter of RtlUnwindEx by longjmp (after it has
61+
+ built an ExceptionRecord on the fly describing the setjmp buffer). */
62+
const HOST_WIDE_INT diff
63+
= frame->stack_pointer_offset - frame->hard_frame_pointer_offset;
64+
- if (diff <= 255)
65+
+ if (diff <= 255 && !crtl->accesses_prior_frames)
66+
{
67+
/* The resulting diff will be a multiple of 16 lower than 255,
68+
i.e. at most 240 as required by the unwind data structure. */

0 commit comments

Comments
 (0)