Cygwin 64bits gcc produces erroneous constants with the win32 headers.

Nicolas Noble nicolas@nobis-crew.org
Fri Apr 15 19:05:00 GMT 2016


I originally entered a bug on msys2's bug tracker, but it turns out
they only repackage cygwin packages, and I have verified this is an
issue on cygwin too, so I am now sending that report here.

Original entry:

https://github.com/Alexpux/MSYS2-packages/issues/555



Basically, the 64 bits "gcc-core" and "w32api-headers" cygwin packages
aren't really compatible with each others. As far as I understand,
this isn't an issue already documented here:
https://cygwin.com/faq-nochunks.html#faq.programming.win32-api
.

The 64 bits gcc that gets compiled in has sizeof(long) == 8. This
causes various troubles with the win32 api headers. These troubles
don't exist with the mingw64 compiler which has sizeof(long) == 4.

Here's an example of what I'm talking about. In the winsock API, the
FIONBIO ioctl command constant is computed using sizeof(u_long) (the
relevance of such method isn't discussed here). Using Visual Studio,
or mingw64's gcc, the value of FIONBIO is always 0x8004667e. But using
cygwin's gcc, when producing a 64 bits binary, the value of that
constant becomes 0x8008667e, which is an invalid ioctl command.

Either cygwin's gcc should have sizeof(long) == 4, or the
w32api-headers package should be fixed to replace long references with
something that is 32 bits in the locations that are relevant, such as
the computation of such constants. For that specific problem for
instance, all the lines such as

#define FIONBIO _IOW('f',126,u_long)

should become something like

#define FIONBIO _IOW('f',126,uint32_t)

I have attached a sample code, and its output when compiled using
cygwin 64 bits. The same code compiled with mingw gcc or Visual Studio
will always produces proper results all the time.

Here's the output in cygwin:

nnoble@NNOBLE0-W ~
$ gcc -o test-code test-code.c -lws2_32
nnoble@NNOBLE0-W ~
$ file test-code.exe
test-code.exe: PE32+ executable (console) x86-64, for MS Windows
nnoble@NNOBLE0-W ~
$ ./test-code.exe
Calling WSAIoctl with FIONBIO = 8008667e - sizeof(param1) = 8
WSAIoctl failed with error: -1
Calling WSAIoctl with FIONBIO = 8008667e - sizeof(param2) = 4
WSAIoctl failed with error: -1
Calling WSAIoctl with FIONBIO_PROPER = 8004667e - sizeof(param1) = 8
Success.
Calling WSAIoctl with FIONBIO_PROPER = 8004667e - sizeof(param2) = 4
Success.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: cygcheck.out
Type: application/octet-stream
Size: 22721 bytes
Desc: not available
URL: <http://cygwin.com/pipermail/cygwin/attachments/20160415/1708858b/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test-code.c
Type: text/x-csrc
Size: 2338 bytes
Desc: not available
URL: <http://cygwin.com/pipermail/cygwin/attachments/20160415/1708858b/attachment.bin>
-------------- next part --------------
--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple


More information about the Cygwin mailing list