Subject: Re: bug#70914: 29.3; Crashes often on Windows

From: Simen Endsjø <[email-masked]>
Date: Sat, 18 May 2024 23:45:12 +0200

> The libgccjit issue is unlikely to be a factor, since it is not used
> in a build without native-compilation, and you say such a build also
> crashes in the same way.

Yes, probably not an issue. The without-native-compilation also crashes after
removing emacs from the path and verifying only dlls from mingw, system32 and
similar is loaded.

> What bugs me is why only you see these crashes?  Emacs is used on
> MS-Windows by many people, but no one has yet reported such crashes,
> certainly not in the unoptimized build.

I have not encountered any other problems with the hardware or software. But as
you say, this strongly points towards something very wrong with just my system.
Strangely it only apparently only affects emacs. Emacs is the only big mingw
program I use though.

Could also be a really odd edge-case. The crashes are pretty deterministic
when debugging it seems (just too bad there isn't a stack trace), but when
running normally I'm having a harder time triggering the bug. Sometimes I can
use emacs for several days, other times it crashes many times a day.

> Hmm... does your MinGW installation produce programs linked against
> UCRT or against MSVCRT?  I see both loaded, which looks strange to me.

Ref https://www.msys2.org/docs/environments/
MSVC (Microsoft Visual C++ Runtime) is legacy and UCRT (Universal C Runtime) is
a newer, but backwards compatible, runtime? I haven't paid any attention to this
at all, so maybe I've destroyed my msys install? I just reinstalled msys
though, so it's pretty bare-bones:

    $ paclist mingw64
    mingw-w64-x86_64-SDL2 2.30.2-1
    mingw-w64-x86_64-aom 3.9.0-2
    mingw-w64-x86_64-binutils 2.42-2
    mingw-w64-x86_64-brotli 1.1.0-1
    mingw-w64-x86_64-bzip2 1.0.8-3
    mingw-w64-x86_64-c-ares 1.28.1-1
    mingw-w64-x86_64-ca-certificates 20240203-1
    mingw-w64-x86_64-cairo 1.18.0-2
    mingw-w64-x86_64-crt-git 11.0.0.r744.ge5ac8c550-1
    mingw-w64-x86_64-crypto++ 8.9.0-1
    mingw-w64-x86_64-curl 8.7.1-1
    mingw-w64-x86_64-dav1d 1.4.1-1
    mingw-w64-x86_64-djvulibre 3.5.28-3
    mingw-w64-x86_64-expat 2.6.2-1
    mingw-w64-x86_64-fftw 3.3.10-5
    mingw-w64-x86_64-flif 0.4-2
    mingw-w64-x86_64-fontconfig 2.15.0-2
    mingw-w64-x86_64-freeglut 3.4.0-2
    mingw-w64-x86_64-freetype 2.13.2-1
    mingw-w64-x86_64-fribidi 1.0.13-1
    mingw-w64-x86_64-gcc 14.1.0-3
    mingw-w64-x86_64-gcc-libs 14.1.0-3
    mingw-w64-x86_64-gdb 14.2-1
    mingw-w64-x86_64-gdb-multiarch 14.2-1
    mingw-w64-x86_64-gdk-pixbuf2 2.42.10-4
    mingw-w64-x86_64-gettext-runtime 0.22.5-2
    mingw-w64-x86_64-giflib 5.2.2-1
    mingw-w64-x86_64-glib2 2.80.0-1
    mingw-w64-x86_64-gmp 6.3.0-2
    mingw-w64-x86_64-gnutls 3.8.5-2
    mingw-w64-x86_64-graphite2 1.3.14-3
    mingw-w64-x86_64-gsfonts 20200910-3
    mingw-w64-x86_64-harfbuzz 8.4.0-1
    mingw-w64-x86_64-headers-git 11.0.0.r744.ge5ac8c550-1
    mingw-w64-x86_64-imagemagick 7.1.1.31-1
    mingw-w64-x86_64-isl 0.26-1
    mingw-w64-x86_64-jansson 2.14-2
    mingw-w64-x86_64-jasper 4.2.1-1
    mingw-w64-x86_64-jbigkit 2.1-5
    mingw-w64-x86_64-kvazaar 2.3.1-1
    mingw-w64-x86_64-lcms2 2.16-1
    mingw-w64-x86_64-lerc 4.0.0-1
    mingw-w64-x86_64-libdatrie 0.2.13-3
    mingw-w64-x86_64-libde265 1.0.15-1
    mingw-w64-x86_64-libdeflate 1.20-1
    mingw-w64-x86_64-libffi 3.4.6-1
    mingw-w64-x86_64-libgccjit 14.1.0-3
    mingw-w64-x86_64-libheif 1.17.6-3
    mingw-w64-x86_64-libiconv 1.17-4
    mingw-w64-x86_64-libidn2 2.3.7-2
    mingw-w64-x86_64-libjpeg-turbo 3.0.2-1
    mingw-w64-x86_64-liblqr 0.4.2-5
    mingw-w64-x86_64-libltdl 2.4.7-2
    mingw-w64-x86_64-libmangle-git 11.0.0.r744.ge5ac8c550-1
    mingw-w64-x86_64-libpng 1.6.43-1
    mingw-w64-x86_64-libpsl 0.21.5-2
    mingw-w64-x86_64-libraqm 0.10.1-1
    mingw-w64-x86_64-libraw 0.21.2-3
    mingw-w64-x86_64-librsvg 2.58.0-1
    mingw-w64-x86_64-libssh2 1.11.0-2
    mingw-w64-x86_64-libsystre 1.0.1-5
    mingw-w64-x86_64-libtasn1 4.19.0-1
    mingw-w64-x86_64-libthai 0.1.29-3
    mingw-w64-x86_64-libtiff 4.6.0-1
    mingw-w64-x86_64-libtre-git r177.07e66d0-2
    mingw-w64-x86_64-libunistring 1.2-1
    mingw-w64-x86_64-libwebp 1.4.0-1
    mingw-w64-x86_64-libwinpthread-git 11.0.0.r744.ge5ac8c550-1
    mingw-w64-x86_64-libwmf 0.2.13-1
    mingw-w64-x86_64-libxml2 2.12.7-1
    mingw-w64-x86_64-lzo2 2.10-2
    mingw-w64-x86_64-make 4.4.1-2
    mingw-w64-x86_64-mpc 1.3.1-2
    mingw-w64-x86_64-mpdecimal 4.0.0-1
    mingw-w64-x86_64-mpfr 4.2.1-2
    mingw-w64-x86_64-ncurses 6.4.20231217-1
    mingw-w64-x86_64-nettle 3.9.1-1
    mingw-w64-x86_64-nghttp2 1.61.0-1
    mingw-w64-x86_64-nspr 4.35-2
    mingw-w64-x86_64-nss 3.99-1
    mingw-w64-x86_64-openjpeg2 2.5.2-1
    mingw-w64-x86_64-openssl 3.3.0-1
    mingw-w64-x86_64-p11-kit 0.25.3-2
    mingw-w64-x86_64-pango 1.52.2-1
    mingw-w64-x86_64-pcre2 10.43-2
    mingw-w64-x86_64-pixman 0.43.4-1
    mingw-w64-x86_64-pkgconf 1~2.2.0-1
    mingw-w64-x86_64-poppler 24.01.0-2
    mingw-w64-x86_64-poppler-data 0.4.12-1
    mingw-w64-x86_64-python 3.11.9-1
    mingw-w64-x86_64-python-packaging 23.2-1
    mingw-w64-x86_64-rav1e 0.7.1-2
    mingw-w64-x86_64-readline 8.2.010-1
    mingw-w64-x86_64-sqlite3 3.45.2-1
    mingw-w64-x86_64-svt-av1 2.0.0-1
    mingw-w64-x86_64-tcl 8.6.13-1
    mingw-w64-x86_64-termcap 1.3.1-7
    mingw-w64-x86_64-tk 8.6.13-1
    mingw-w64-x86_64-tools-git 11.0.0.r744.ge5ac8c550-1
    mingw-w64-x86_64-tree-sitter 0.22.6-1
    mingw-w64-x86_64-ttf-dejavu 2.37-4
    mingw-w64-x86_64-tzdata 2024a-1
    mingw-w64-x86_64-vulkan-loader 1.3.280.0-1
    mingw-w64-x86_64-windows-default-manifest 6.4-4
    mingw-w64-x86_64-wineditline 2.206-1
    mingw-w64-x86_64-winpthreads-git 11.0.0.r744.ge5ac8c550-1
    mingw-w64-x86_64-winstorecompat-git 11.0.0.r744.ge5ac8c550-1
    mingw-w64-x86_64-x265 3.5-3
    mingw-w64-x86_64-xpm-nox 4.2.0-8
    mingw-w64-x86_64-xxhash 0.8.2-2
    mingw-w64-x86_64-xz 5.6.1-2
    mingw-w64-x86_64-zlib 1.3.1-1
    mingw-w64-x86_64-zstd 1.5.6-2

    $ paclist ucrt64
    mingw-w64-ucrt-x86_64-binutils 2.42-2
    mingw-w64-ucrt-x86_64-crt-git 11.0.0.r744.ge5ac8c550-1
    mingw-w64-ucrt-x86_64-gcc 14.1.0-3
    mingw-w64-ucrt-x86_64-gcc-libs 14.1.0-3
    mingw-w64-ucrt-x86_64-gettext-runtime 0.22.5-2
    mingw-w64-ucrt-x86_64-gmp 6.3.0-2
    mingw-w64-ucrt-x86_64-headers-git 11.0.0.r744.ge5ac8c550-1
    mingw-w64-ucrt-x86_64-isl 0.26-1
    mingw-w64-ucrt-x86_64-libiconv 1.17-4
    mingw-w64-ucrt-x86_64-libwinpthread-git 11.0.0.r744.ge5ac8c550-1
    mingw-w64-ucrt-x86_64-mpc 1.3.1-2
    mingw-w64-ucrt-x86_64-mpfr 4.2.1-2
    mingw-w64-ucrt-x86_64-windows-default-manifest 6.4-4
    mingw-w64-ucrt-x86_64-winpthreads-git 11.0.0.r744.ge5ac8c550-1
    mingw-w64-ucrt-x86_64-zlib 1.3.1-1
    mingw-w64-ucrt-x86_64-zstd 1.5.6-2

I removed all ucrt packages (pacman -R), and did a new build in a new directory,
but ucrtbase is still required.

    $ pwd
    /d/tmp/emacs-bug-70914

    $ ldd emacs-extra-checks-no-ucrt/src/emacs.exe
            ntdll.dll => /c/WINDOWS/SYSTEM32/ntdll.dll (0x7fffef730000)
            KERNEL32.DLL => /c/WINDOWS/System32/KERNEL32.DLL (0x7fffedae0000)
            KERNELBASE.dll => /c/WINDOWS/System32/KERNELBASE.dll
(0x7fffed0b0000)
            ADVAPI32.dll => /c/WINDOWS/System32/ADVAPI32.dll (0x7fffedbb0000)
            msvcrt.dll => /c/WINDOWS/System32/msvcrt.dll (0x7fffedd50000)
            sechost.dll => /c/WINDOWS/System32/sechost.dll (0x7fffeeca0000)
            bcrypt.dll => /c/WINDOWS/System32/bcrypt.dll (0x7fffecad0000)
            RPCRT4.dll => /c/WINDOWS/System32/RPCRT4.dll (0x7fffed610000)
            comdlg32.dll => /c/WINDOWS/System32/comdlg32.dll (0x7fffeeba0000)
            COMCTL32.dll =>
/c/WINDOWS/WinSxS/amd64_microsoft.windows.common-controls_6595b64144ccf1df_6.0.22621.3527_none_270e469b73872a76/COMCTL32.dll
(0x7fffd3370000)
            msvcp_win.dll => /c/WINDOWS/System32/msvcp_win.dll (0x7fffece30000)
            GDI32.dll => /c/WINDOWS/System32/GDI32.dll (0x7fffedab0000)
            ucrtbase.dll => /c/WINDOWS/System32/ucrtbase.dll (0x7fffecd10000)
            win32u.dll => /c/WINDOWS/System32/win32u.dll (0x7fffecb70000)
            gdi32full.dll => /c/WINDOWS/System32/gdi32full.dll (0x7fffeced0000)
            combase.dll => /c/WINDOWS/System32/combase.dll (0x7fffef1f0000)
            USER32.dll => /c/WINDOWS/System32/USER32.dll (0x7fffeee10000)
            shcore.dll => /c/WINDOWS/System32/shcore.dll (0x7fffef5f0000)
            SHLWAPI.dll => /c/WINDOWS/System32/SHLWAPI.dll (0x7fffeda50000)
            SHELL32.dll => /c/WINDOWS/System32/SHELL32.dll (0x7fffee340000)
            ole32.dll => /c/WINDOWS/System32/ole32.dll (0x7fffed460000)
            MPR.dll => /c/WINDOWS/SYSTEM32/MPR.dll (0x7fffd9050000)
            USP10.dll => /c/WINDOWS/SYSTEM32/USP10.dll (0x7fffb4410000)
            libwinpthread-1.dll => /mingw64/bin/libwinpthread-1.dll
(0x7fff8d650000)
            libgmp-10.dll => /mingw64/bin/libgmp-10.dll (0x7fff65240000)
            WINSPOOL.DRV => /c/WINDOWS/SYSTEM32/WINSPOOL.DRV (0x7fffd66a0000)
            WINMM.dll => /c/WINDOWS/SYSTEM32/WINMM.dll (0x7fffe9da0000)

It still crashes, and I still get zero addresses.

    Reading symbols from
D:\tmp\emacs-bug-70914\emacs-extra-checks-no-ucrt\simendsjo-build\bin\emacs.exe...
    (gdb) run --init-directory=d:/.emacs.d
    Starting program:
D:\tmp\emacs-bug-70914\emacs-extra-checks-no-ucrt\simendsjo-build\bin\emacs.exe
--init-directory=d:/.emacs.d
    (...)
    Thread 1 received signal SIGSEGV, Segmentation fault.
    0x0000000000000000 in ?? ()

> Let's ask Emacs to help us some more, okay?  Please reconfigure like
> this:
>
>   CFLAGS='-O0 -gdwarf-4 -g3' ./configure --without-native-compilation \
>     --enable-checking='yes,glyphs' --enable-check-lisp-object-type \
>     --with-modules --without-dbus --without-compress-install \
>     --with-sqlite3 --with-tree-sitter
>
> then rebuild, and see if the extra checking code catches some problems
> before they become SIGSEGV due to zero address.

The above was done using these extra check flags:

    system-configuration-options is a variable defined in emacs.c.

    Value
    "--prefix=/d/tmp/emacs-bug-70914/emacs-extra-checks-no-ucrt/simendsjo-build
--without-native-compilation --enable-checking=yes,glyphs
--enable-check-lisp-object-type --with-modules --without-dbus
--without-compress-install --with-sqlite3 --with-tree-sitter
'CFLAGS=-O0 -gdwarf-4 -g3 -Wno-error=implicit-function-declaration'"

On Sat, May 18, 2024 at 9:46 PM Eli Zaretskii <[email-masked]> wrote:
>
> > From: Simen Endsjø <[email-masked]>
> > Date: Sat, 18 May 2024 20:47:32 +0200
> > Cc: Corwin Brust <[email-masked]>, [email-masked]
> >
> > I don't see this when running my own compiled emacs, but it might be something
> > on my end. I had the gnu ftp version in my path before mingw. When loading
> > emacs, the emacs supplied libraries were used, but libgccjit is loaded from
> > mingw as it is not shipped with emacs. Could something like this be the source
> > of my problems?
> >
> > But when removing that path from my PATH and using a self-compiled emacs, I
> > still get the same zero stackframe even though I see all libraries are loaded
> > from mingw where I compiled emacs. So maybe just a red herring?
>
> The libgccjit issue is unlikely to be a factor, since it is not used
> in a build without native-compilation, and you say such a build also
> crashes in the same way.
>
> What bugs me is why only you see these crashes?  Emacs is used on
> MS-Windows by many people, but no one has yet reported such crashes,
> certainly not in the unoptimized build.
>
> Let's ask Emacs to help us some more, okay?  Please reconfigure like
> this:
>
>   CFLAGS='-O0 -gdwarf-4 -g3' ./configure --without-native-compilation \
>     --enable-checking='yes,glyphs' --enable-check-lisp-object-type \
>     --with-modules --without-dbus --without-compress-install \
>     --with-sqlite3 --with-tree-sitter
>
> then rebuild, and see if the extra checking code catches some problems
> before they become SIGSEGV due to zero address.