Re: Removing dependency to wsock32.lib when compiling code on WIndows

From: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
To: Noah Misch <noah(at)leadboat(dot)com>
Cc: Jeff Janes <jeff(dot)janes(at)gmail(dot)com>, Magnus Hagander <magnus(at)hagander(dot)net>, MauMau <maumau307(at)gmail(dot)com>, PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Removing dependency to wsock32.lib when compiling code on WIndows
Date: 2014-08-22 07:58:47
Message-ID: CAB7nPqRTYGUVCQOWE=O6A8yA0S4ROyx9Kaqr1v+XPnhgYiihvw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri, Aug 15, 2014 at 8:00 PM, Noah Misch <noah(at)leadboat(dot)com> wrote:
>
> On Fri, Aug 15, 2014 at 12:49:36AM -0700, Michael Paquier wrote:
> > Btw, how do you determine if MSVC is using HAVE_GETADDRINFO? Is it
> > decided by the inclusion of getaddrinfo.c in @pgportfiles of
> > Mkvdbuild.pm?
>
> src/include/pg_config.h.win32 dictates it, and we must keep @pgportfiles
> synchronized with the former's verdict.
Thanks.

Looking more into that, I am seeing that MinGW-32 is failing to find socket
at configure, contrary to MinGW-64.

Here is what happens for MinGW-64 at configure:
configure:7638: checking for library containing socket
[...]
configure:7669: x86_64-w64-mingw32-gcc -o conftest.exe -Wall
-Wmissing-prototypes -Wpointer-arith \
-Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute
-Wformat-security -fno-stri\
ct-aliasing -fwrapv -fexcess-precision=standard -g
-I./src/include/port/win32 -DEXEC_BACKEND -Wl\
,--allow-multiple-definition -Wl,--disable-auto-import conftest.c -lws2_32
-lm >&5
configure:7669: $? = 0
configure:7686: result: -lws2_32

And for MinGW-32:
configure:7638: checking for library containing socket
[...]
configure:7669: gcc -o conftest.exe -Wall -Wmissing-prototypes
-Wpointer-arith -Wdeclaration-after\
-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security
-fno-strict-aliasing -fwrapv\
-fexcess-precision=standard -g -I./src/include/port/win32
-DEXEC_BACKEND -Wl,--allow-multiple-d\
efinition -Wl,--disable-auto-import conftest.c -lws2_32 -lm >&5
C:\Users\ioltas\AppData\Local\Temp\cciNV1Y8.o: In function `main':
c:\Users\ioltas\git\postgres/conftest.c:33: undefined reference to `socket'
collect2.exe: error: ld returned 1 exit status
configure:7669: $? = 1
[...]
configure:7686: result: no

Now, what happens is that if configure finds socket within ws2_32 it adds
it to LIBS, making this variable look like that:
- MinGW-32: LIBS="-lm "
- MinGW-64: LIBS="-lm -lws2_32"
And as LIBS is used afterwards to check the presence of several functions,
including getaddrinfo, those different values of LIBS make HAVE_GETADDRINFO
set to different values in MinGW-32 and 64, respectively undefined and
defined.

I am not sure which way is better, do we want HAVE_GETADDRINFO or
!HAVE_GETADDRINFO in all Windows builds? If we choose the former, we'll
need to understand why -lws2_32 is not added to LIBS for MinGW-32. If we
choose the latter, we would need to remove -lws2_32 from LIBS with MinGW-64
for consistency with MinGW-32 I think.

Either way, currently MSVC uses !HAVE_GETADDRINFO. So in bonus to this
anamysis, the patch attached makes possible the use of HAVE_GETADDRINFO.
This could be needed for the final solution we seek.

Note that the undef gai_strerror in src/include/port/win32/sys/socket.h has
been added in 2005 by this commit:
commit: a310a1d80c6535774115838010f9c337d08d45cc
author: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
date: Fri, 26 Aug 2005 03:15:12 +0000
Some more mop-up for Windows IPv6 support. Andrew Dunstan

I don't know the opinions of the others, but removing a tweak like this one
may not be a bad thing to simplify code.

Regards,
--
Michael

Attachment Content-Type Size
20140822_getaddrinfo_msvc.patch text/x-patch 1.5 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Amit Kapila 2014-08-22 08:35:15 Re: option -T in pg_basebackup doesn't work on windows
Previous Message Andres Freund 2014-08-22 07:34:42 Re: Proposal to add a QNX 6.5 port to PostgreSQL