Subject: Re: bug#19813: 24.4; emacs crashes on exit

From: Eli Zaretskii <[email-masked]>
Date: Mon, 09 Feb 2015 17:41:22 +0200

> Date: Mon, 9 Feb 2015 04:03:24 -0500
> From: Test User <[email-masked]>
> 
>     The problem is not with libgcc_s_dw2-1.dll, the problem is with some
>     other DLL that loads it, typically zlib1.dll or some image library.
> 
> I built emacs with -shared-libgcc in LDFLAGS and the problem went away.

That is one solution, but it is not the best one, IMO.  E.g., you
cannot move this binary to another machine without also copying
libgcc_s_dw2-1.dll with it.

The best solution is to replace the DLL(s) you have that depend on
libgcc_s_dw2-1.dll with DLLs that offer the same functionality, but do
not depend on libgcc_s_dw2-1.dll.  See below for a specific
recommendation.

> Thanks. You can close the bug if you have not already done so.

Done.

> On my main system (where the problem occurs), there is no zlib1.dll in
> /mingw/bin. I built it myself, and it does *not* have a dependency on libgcc_s_dw2-1.dll. On my virtual machine (where I did not have the problem),
> there is a zlib1.dll supplied by MinGW, and it *does* depend on
> libgcc_s_dw2-1.dll.
> 
> The only DLL loaded when emacs runs that depends on libgcc_s_dw2-1.dll
> is libharfbuzz-0.dll, which is not loaded with `emacs -Q'.

That figures: "emacs -Q" refrains from showing the splash-screen
image, which causes Emacs to load a suitable image library.  In your
case, that library is librsvg for showing the SVG variant of the
splash screen.  And the librsvg DLLs you have include
libharfbuzz-0.dll, which depends on libgcc_s_dw2-1.dll, and triggers
the problem.

In general, no MinGW DLLs distributed as binaries should depend on
libgcc_s_dw2-1.dll, for several reasons:

  . Each end-user machine that has GCC installed will have this DLL on
    PATH, which creates a small "DLL hell" when you install other
    versions of that DLL, possibly from other GCC versions

  . Loading libgcc_s_dw2-1.dll by some other DLL (as opposed to by the
    main program itself) triggers these crashes (due to a known bug in
    the machinery that supports C++ exceptions between DLLs)

  . For the person who uploads the precompiled binaries of the DLLs,
    the dependency on libgcc_s_dw2-1.dll is a terrible PITA, because
    GPL requires to provide its sources, i.e. the entire 80-MB source
    tarball of the full GCC package

You can find DLLs that are never dependent on libgcc_s_dw2-1.dll here:

  http://sourceforge.net/projects/ezwinports/files/?source=navbar

That collection includes librsvg, zlib, and all the other libraries
required by Emacs.  (Btw, the librsvg build there is much smaller than
the one you use, because it excludes every feature not useful on
Windows, like Fontconfig, Freetype, and Harfbuzz.)