Subject: bug#22959: Emacs on Windows depends on libwinpthreads

From: Eli Zaretskii <[email-masked]>
Date: Sun, 17 Apr 2016 19:42:59 +0300

> From: Fabrice Popineau <[email-masked]>
> Date: Sun, 17 Apr 2016 17:25:23 +0200
> Cc: [email-masked]
> 
> >From config.log:
> 
> configure:24643: checking for library containing clock_gettime
> configure:24674: gcc -I ../emacs/nt/inc -o conftest.exe -I/mingw64/include
> -fomit-frame-pointer -O3 -g0 -mtune=corei7 -mtune=generic
>  -I/mingw64/include -L/mingw64/lib conftest.c   >&5
> configure:24674: $? = 0
> configure:24691: result: none required
> configure:24703: checking for clock_gettime
> configure:24703: gcc -I ../emacs/nt/inc -o conftest.exe -I/mingw64/include
> -fomit-frame-pointer -O3 -g0 -mtune=corei7 -mtune=generic
>  -I/mingw64/include -L/mingw64/lib conftest.c   >&5
> configure:24703: $? = 0
> configure:24703: result: yes
> configure:24703: checking for clock_settime
> configure:24703: gcc -I ../emacs/nt/inc -o conftest.exe -I/mingw64/include
> -fomit-frame-pointer -O3 -g0 -mtune=corei7 -mtune=generic
>  -I/mingw64/include -L/mingw64/lib conftest.c   >&5
> configure:24703: $? = 0
> configure:24703: result: yes
> 
> Testing with a very short C file, it seems that libwinpthread-1.dll is
> linked in by default and may be gets removed by the linker if no symbol is
> referenced.

So this is the reason for what you see: evidently, MinGW64 considers
libwinpthread DLL a necessary part of a MinGW64 linking.

We can easily prevent Emacs (in nt/mingw-cfg.site) from pulling
clock_gettime from libwinpthread, if we decide to do that.  But since
MinGW64 programs are evidently supposed to depend on that library, I
question the need for exempting just Emacs from this rule.

> I have asked for clarifications on the msys2 list.

I'm not sure they are the right crowd, it could be MinGW64 developers,
like Kai Tietz.

> Anyway, I am afraid that some 3rd party libraries would require it anyway.
> For example, --with-rsvg triggers the -pthread compile flag:
> 
> config.status:S["RSVG_CFLAGS"]="-pthread -mms-bitfields
> -I/mingw64/include/librsvg-2.0 -I/mingw64/include/gdk-pixbuf-2.0
> -I/mingw64/include/libpng16 -I/mingw64/include/cairo -I/min"\

That's not the same: the librsvg dependency is not a static one,
i.e. Emacs will start up even if libwinpthread is not available, it
just won't be able to display SVG images.  By contrast, the dependency
you are talking about is _static_, recorded at link time; Emacs will
refuse to start if the DLL is not present.

> and the dll list is:
> 
> /c/Local/Emacs/bin/libasprintf-0.dll*

Shouldn't be needed.

> /c/Local/Emacs/bin/libp11-kit-0.dll*

You should tell whoever build that GnuTLS to omit libp11-kit, it's
generally useless on Windows, certainly with Emacs.

> /c/Local/Emacs/bin/libgnutlsxx-28.dll*

Shouldn't be required, as long as Emacs is not a C++ program.

> /c/Local/Emacs/bin/libcharset-1.dll*

Shouldn't be required.

>  /c/Local/Emacs/bin/libpangoft2-1.0-0.dll*
> /c/Local/Emacs/bin/libgraphite2.dll*
> /c/Local/Emacs/bin/libfontconfig-1.dll*
> /c/Local/Emacs/bin/libfreetype-6.dll*

Whoever built Cairo didn't take care of disabling features unneeded on
Windows for librsvg.  The result is a very fat build of Cairo, for no
good reason.

> /c/Local/Emacs/bin/libpcre-1.dll*
> /c/Local/Emacs/bin/libexpat-1.dll*
> /c/Local/Emacs/bin/libharfbuzz-0.dll*

Are these also from librsvg dependencies?  If so, they are just
ballast, AFAIK.

> /c/Local/Emacs/bin/libfftw3-3.dll*

Which library needs this one?

>  /c/Local/Emacs/bin/libidn-11.dll*

Which library needs this one?

>  /c/Local/Emacs/bin/libstdc++-6.dll*

??? Why?  Emacs is not a C++ program.  In any case, using
"-static-libstdc++" should fix this, I think.

> /c/Local/Emacs/bin/libgcc_s_seh-1.dll*

Use -static-libgcc (and ask library maintainers to avoid this
dependency).

>  /c/Local/Emacs/bin/liblcms2-2.dll*

Which library needs this?

> /c/Local/Emacs/bin/libtiffxx-5.dll*

This is for C++ program, AFAIK.

> /c/Local/Emacs/bin/libgettextpo-0.dll*

Shouldn't be needed.

> /c/Local/Emacs/bin/liblqr-1-0.dll*

What is this library?

> /c/Local/Emacs/bin/libltdl-7.dll*

Which library needs this one?