Received: from eggs.gnu.org ([2001:4830:134:3::10]:36108) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aLFlL-0004VQ-4O for qemu-devel@nongnu.org; Mon, 18 Jan 2016 14:46:52 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aLFlH-0001Wk-T0 for qemu-devel@nongnu.org; Mon, 18 Jan 2016 14:46:51 -0500 Received: from mail-ig0-x232.google.com ([2607:f8b0:4001:c05::232]:34178) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aLFlH-0001Wg-MB for qemu-devel@nongnu.org; Mon, 18 Jan 2016 14:46:47 -0500 Received: by mail-ig0-x232.google.com with SMTP id ik10so62393188igb.1 for ; Mon, 18 Jan 2016 11:46:47 -0800 (PST) Mime-Version: 1.0 (Apple Message framework v1084) Content-Type: text/plain; charset=us-ascii From: Programmingkid In-Reply-To: Date: Mon, 18 Jan 2016 14:46:44 -0500 Content-Transfer-Encoding: quoted-printable Message-Id: <3250EA09-DA61-41B2-A956-6CCE8D2C51F1@gmail.com> References: <5525054B-A7E2-4538-9F68-9E606B85B1B7@gmail.com> <569C224B.2040102@redhat.com> <1866CB23-7966-4F68-8925-2C3888753883@gmail.com> <569D24D2.3000800@redhat.com> Subject: Re: [Qemu-devel] CMSG_SPACE() causing compile time error on Mac OS X List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Maydell , Eric Blake Cc: Paolo Bonzini , qemu-devel qemu-devel On Jan 18, 2016, at 12:59 PM, Peter Maydell wrote: > On 18 January 2016 at 17:45, Eric Blake wrote: >> On 01/17/2016 04:45 PM, Programmingkid wrote: >>>> What's the definition of the CMSG_SPACE macro under OS X? >>>>=20 >>>> Paolo >>>=20 >>> #define CMSG_SPACE(l) = (__DARWIN_ALIGN32(sizeof(struct cmsghdr)) + __DARWIN_ALIGN32(l)) >>=20 >> And the definition of __DARWIN_ALIGN32()? >>=20 >> It looks like the definition is not properly resulting in a = compile-time >> constant, and therefore the warning about the initializer is = resulting >> because you can't initialize a dynamically-sized array. But you = still >> haven't shown us why the headers are resulting in a non-constant = size. >=20 > FWIW, on my OSX system (OSX 10.10.5, Xcode 7.1), compiling the test > program with >=20 > gcc -Wall -E -o /tmp/varray.S /tmp/varray.c >=20 > shows that the array definition expands to >=20 > char control[(((__darwin_size_t)((char > *)(__darwin_size_t)(sizeof(struct cmsghdr)) + (sizeof(__uint32_t) - > 1)) &~ (sizeof(__uint32_t) - 1)) + ((__darwin_size_t)((char > *)(__darwin_size_t)(sizeof(int) * 16) + (sizeof(__uint32_t) - 1)) &~ > (sizeof(__uint32_t) - 1)))] =3D { 0 }; >=20 > the relevant macro definitions being > #define __DARWIN_ALIGNBYTES (sizeof(__darwin_size_t) - 1) > #define __DARWIN_ALIGN32(p) ((__darwin_size_t)((char > *)(__darwin_size_t)(p) + __DARWIN_ALIGNBYTES32) &~ > __DARWIN_ALIGNBYTES32) >=20 >=20 > this is with a 'gcc' that gcc --version reports as > Configured with: > --prefix=3D/Applications/Xcode.app/Contents/Developer/usr > --with-gxx-include-dir=3D/usr/include/c++/4.2.1 > Apple LLVM version 7.0.0 (clang-700.1.76) > Target: x86_64-apple-darwin14.5.0 > Thread model: posix >=20 > and which claims itself to be 4.2.1 by the printout from the test > program (ie it's clang under the hood). That is interesting. I would have thought Apple would have upgrade their = GCC compatibility version by now.=20 >=20 > I don't get any compiler warnings from > gcc -Wall -O2 -o /tmp/varray /tmp/varray.c >=20 > I don't know what the difference between my setup and John's is > (likely an older clang version). >=20 > thanks > -- PMM A patch by Daniel P. Berrange successfully fixes this problem.=20 http://patchwork.ozlabs.org/patch/569500/ diff --git a/io/channel-socket.c b/io/channel-socket.c index eaa411f..bc117b1 100644 --- a/io/channel-socket.c +++ b/io/channel-socket.c @@ -493,10 +495,12 @@ static ssize_t = qio_channel_socket_writev(QIOChannel *ioc, QIOChannelSocket *sioc =3D QIO_CHANNEL_SOCKET(ioc); ssize_t ret; struct msghdr msg =3D { NULL, }; - char control[CMSG_SPACE(sizeof(int) * SOCKET_MAX_FDS)] =3D { 0 }; + char control[CMSG_SPACE(sizeof(int) * SOCKET_MAX_FDS)]; size_t fdsize =3D sizeof(int) * nfds; struct cmsghdr *cmsg; =20 + memset(control, 0, CMSG_SPACE(sizeof(int) * SOCKET_MAX_FDS)); + msg.msg_iov =3D (struct iovec *)iov; msg.msg_iovlen =3D niov; =20