haskell / network

Low-level networking interface
http://hackage.haskell.org/package/network
Other
325 stars 187 forks source link

Will not build without msghdr.msg_control #536

Closed yobson closed 2 years ago

yobson commented 2 years ago

I'm trying to boostrap cabal 3.6.2.0 on OmniOS and it is failing to build the network package

Configuring network-3.1.2.2...
configure: WARNING: unrecognized options: --with-compiler, --with-hc-pkg
checking build system type... x86_64-pc-solaris2.11
checking host system type... x86_64-pc-solaris2.11
checking for gcc... /usr/bin/gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether /usr/bin/gcc accepts -g... yes
checking for /usr/bin/gcc option to accept ISO C89... none needed
checking for an ANSI C-conforming const... yes
checking how to run the C preprocessor... /usr/bin/gcc -E
checking for grep that handles long lines and -e... /usr/bin/ggrep
checking for egrep... /usr/bin/ggrep -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking limits.h usability... yes
checking limits.h presence... yes
checking for limits.h... yes
checking for stdlib.h... (cached) yes
checking for unistd.h... (cached) yes
checking for sys/types.h... (cached) yes
checking fcntl.h usability... yes
checking fcntl.h presence... yes
checking for fcntl.h... yes
checking sys/uio.h usability... yes
checking sys/uio.h presence... yes
checking for sys/uio.h... yes
checking sys/socket.h usability... yes
checking sys/socket.h presence... yes
checking for sys/socket.h... yes
checking netinet/in.h usability... yes
checking netinet/in.h presence... yes
checking for netinet/in.h... yes
checking netinet/tcp.h usability... yes
checking netinet/tcp.h presence... yes
checking for netinet/tcp.h... yes
checking sys/un.h usability... yes
checking sys/un.h presence... yes
checking for sys/un.h... yes
checking arpa/inet.h usability... yes
checking arpa/inet.h presence... yes
checking for arpa/inet.h... yes
checking netdb.h usability... yes
checking netdb.h presence... yes
checking for netdb.h... yes
checking net/if.h usability... yes
checking net/if.h presence... yes
checking for net/if.h... yes
checking netioapi.h usability... no
checking netioapi.h presence... no
checking for netioapi.h... no
checking for struct ucred... no
checking for gai_strerror... no
checking for gethostent... no
checking for accept4... no
checking for getpeereid... no
checking whether AI_ADDRCONFIG is declared... yes
checking whether AI_ALL is declared... yes
checking whether AI_NUMERICSERV is declared... yes
checking whether AI_V4MAPPED is declared... yes
checking whether IPV6_V6ONLY is declared... yes
checking whether IPPROTO_IP is declared... yes
checking whether IPPROTO_TCP is declared... yes
checking whether IPPROTO_IPV6 is declared... yes
checking whether SO_PEERCRED is declared... no
checking for struct msghdr.msg_control... no
checking for struct msghdr.msg_accrights... yes
checking for struct sockaddr.sa_len... no
configure: creating ./network.buildinfo
configure: creating ./config.status
config.status: creating include/HsNetworkConfig.h
config.status: include/HsNetworkConfig.h is unchanged
configure: WARNING: unrecognized options: --with-compiler, --with-hc-pkg
bootstrap: running cwd=_build/unpacked/network-3.1.2.2 /home/james/gits/cabal/_build/dists/network-3.1.2.2/setup/Setup build --builddir=/home/james/gits/cabal/_build/dists/network-3.1.2.2
Preprocessing library for network-3.1.2.2..
compiling /home/james/gits/cabal/_build/dists/network-3.1.2.2/build/Network/Socket/Posix/MsgHdr_hsc_make.c failed (exit code 1)
rsp file was: "/home/james/gits/cabal/_build/dists/network-3.1.2.2/build/Network/Socket/Posix/hsc2hscall1381-0.rsp"
command was: /usr/bin/gcc -c /home/james/gits/cabal/_build/dists/network-3.1.2.2/build/Network/Socket/Posix/MsgHdr_hsc_make.c -o /home/james/gits/cabal/_build/dists/network-3.1.2.2/build/Network/Socket/Posix/MsgHdr_hsc_make.o -m64 -m64 -m64 -D__GLASGOW_HASKELL__=810 -Dsolaris2_BUILD_OS=1 -Dx86_64_BUILD_ARCH=1 -Dsolaris2_HOST_OS=1 -Dx86_64_HOST_ARCH=1 -Iinclude -I/home/james/gits/cabal/_build/dists/network-3.1.2.2/build/include -I/home/james/gits/cabal/_build/dists/network-3.1.2.2/build/autogen -I/home/james/gits/cabal/_build/dists/network-3.1.2.2/build/global-autogen -include /home/james/gits/cabal/_build/dists/network-3.1.2.2/build/autogen/cabal_macros.h -I/usr/local/lib/ghc-8.10.7/unix-2.7.2.2/include -I/usr/local/lib/ghc-8.10.7/time-1.9.3/include -I/usr/local/lib/ghc-8.10.7/bytestring-0.10.12.0/include -I/usr/local/lib/ghc-8.10.7/base-4.14.3.0/include -I/usr/local/lib/ghc-8.10.7/integer-gmp-1.0.3.0/include -I/usr/local/lib/ghc-8.10.7/include -I/usr/local/lib/ghc-8.10.7/include/
error: In file included from /usr/local/lib/ghc-8.10.7/template-hsc.h:11,
                 from /home/james/gits/cabal/_build/dists/network-3.1.2.2/build/Network/Socket/Posix/MsgHdr_hsc_make.c:1:
MsgHdr.hsc: In function 'main':
/usr/local/lib/ghc-8.10.7/template-hsc.h:82:24: error: 'struct msghdr' has no member named 'msg_control'
   82 |                 (long) offsetof (t, f));
      |                        ^~~~~~~~
MsgHdr.hsc:35:5: note: in expansion of macro 'hsc_peek'
/usr/local/lib/ghc-8.10.7/template-hsc.h:82:24: error: 'struct msghdr' has no member named 'msg_controllen'
   82 |                 (long) offsetof (t, f));
      |                        ^~~~~~~~
MsgHdr.hsc:36:5: note: in expansion of macro 'hsc_peek'
/usr/local/lib/ghc-8.10.7/template-hsc.h:82:24: error: 'struct msghdr' has no member named 'msg_flags'
   82 |                 (long) offsetof (t, f));
      |                        ^~~~~~~~
MsgHdr.hsc:37:5: note: in expansion of macro 'hsc_peek'
/usr/local/lib/ghc-8.10.7/template-hsc.h:86:24: error: 'struct msghdr' has no member named 'msg_control'
   86 |                 (long) offsetof (t, f));
      |                        ^~~~~~~~
MsgHdr.hsc:49:5: note: in expansion of macro 'hsc_poke'
/usr/local/lib/ghc-8.10.7/template-hsc.h:86:24: error: 'struct msghdr' has no member named 'msg_controllen'
   86 |                 (long) offsetof (t, f));
      |                        ^~~~~~~~
MsgHdr.hsc:50:5: note: in expansion of macro 'hsc_poke'
/usr/local/lib/ghc-8.10.7/template-hsc.h:86:24: error: 'struct msghdr' has no member named 'msg_flags'
   86 |                 (long) offsetof (t, f));
      |                        ^~~~~~~~
MsgHdr.hsc:51:5: note: in expansion of macro 'hsc_poke'

What's interesting is that it checks weather msghdr has the msg_control member, and correctly determines that it doesn't, but then continues assuming that it's there.

Should it fail on configure? Or should it build differently? Also, is this a failure on the part of cabal?

EDIT: Investigation continues

in Network/Socket/Posix/MsgHdr.hsc, We have the following:

  peek p = do
    name       <- (#peek struct msghdr, msg_name)       p
    nameLen    <- (#peek struct msghdr, msg_namelen)    p
    iov        <- (#peek struct msghdr, msg_iov)        p
    iovLen     <- (#peek struct msghdr, msg_iovlen)     p
    ctrl       <- (#peek struct msghdr, msg_control)    p
    ctrlLen    <- (#peek struct msghdr, msg_controllen) p
    flags      <- (#peek struct msghdr, msg_flags)      p
    return $ MsgHdr name nameLen iov iovLen ctrl ctrlLen flags

poke p mh = do
    -- We need to zero the msg_control, msg_controllen, and msg_flags
    -- fields, but they only exist on some platforms (e.g. not on
    -- Solaris).  Instead of using CPP, we zero the entire struct.
    zeroMemory p (#const sizeof(struct msghdr))
    (#poke struct msghdr, msg_name)       p (msgName       mh)
    (#poke struct msghdr, msg_namelen)    p (msgNameLen    mh)
    (#poke struct msghdr, msg_iov)        p (msgIov        mh)
    (#poke struct msghdr, msg_iovlen)     p (msgIovLen     mh)
    (#poke struct msghdr, msg_control)    p (msgCtrl       mh)
    (#poke struct msghdr, msg_controllen) p (msgCtrlLen    mh)
    (#poke struct msghdr, msg_flags)      p (msgFlags      mh)

The comment makes me feel as if thought was given to solaris based OSs, but not a full implementation.

I don't know much about this code base, but could we guard on the CPP def HAVE_STRUCT_MSGHDR_MSG_CONTROL just the lines that break on solaris without breaking anything? If so, I'm happy to write a patch

James

kazu-yamamoto commented 2 years ago

Please send a PR.

kazu-yamamoto commented 2 years ago

The PR should be sent after #535 is resolved. I don't want to modify the same part with two ways at the same time.

yobson commented 2 years ago

I've tested with a newer version of the network package and it is resolved already!