[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] CMSG_SPACE() causing compile time error on Mac OS X
From: |
Programmingkid |
Subject: |
Re: [Qemu-devel] CMSG_SPACE() causing compile time error on Mac OS X |
Date: |
Mon, 18 Jan 2016 14:46:44 -0500 |
On Jan 18, 2016, at 12:59 PM, Peter Maydell wrote:
> On 18 January 2016 at 17:45, Eric Blake <address@hidden> wrote:
>> On 01/17/2016 04:45 PM, Programmingkid wrote:
>>>> What's the definition of the CMSG_SPACE macro under OS X?
>>>>
>>>> Paolo
>>>
>>> #define CMSG_SPACE(l) (__DARWIN_ALIGN32(sizeof(struct
>>> cmsghdr)) + __DARWIN_ALIGN32(l))
>>
>> And the definition of __DARWIN_ALIGN32()?
>>
>> 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.
>
> FWIW, on my OSX system (OSX 10.10.5, Xcode 7.1), compiling the test
> program with
>
> gcc -Wall -E -o /tmp/varray.S /tmp/varray.c
>
> shows that the array definition expands to
>
> 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)))] = { 0 };
>
> 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)
>
>
> this is with a 'gcc' that gcc --version reports as
> Configured with:
> --prefix=/Applications/Xcode.app/Contents/Developer/usr
> --with-gxx-include-dir=/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
>
> 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.
>
> I don't get any compiler warnings from
> gcc -Wall -O2 -o /tmp/varray /tmp/varray.c
>
> I don't know what the difference between my setup and John's is
> (likely an older clang version).
>
> thanks
> -- PMM
A patch by Daniel P. Berrange successfully fixes this problem.
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 = QIO_CHANNEL_SOCKET(ioc);
ssize_t ret;
struct msghdr msg = { NULL, };
- char control[CMSG_SPACE(sizeof(int) * SOCKET_MAX_FDS)] = { 0 };
+ char control[CMSG_SPACE(sizeof(int) * SOCKET_MAX_FDS)];
size_t fdsize = sizeof(int) * nfds;
struct cmsghdr *cmsg;
+ memset(control, 0, CMSG_SPACE(sizeof(int) * SOCKET_MAX_FDS));
+
msg.msg_iov = (struct iovec *)iov;
msg.msg_iovlen = niov;
- [Qemu-devel] CMSG_SPACE() causing compile time error on Mac OS X, Programmingkid, 2016/01/17
- Re: [Qemu-devel] CMSG_SPACE() causing compile time error on Mac OS X, Paolo Bonzini, 2016/01/17
- Re: [Qemu-devel] CMSG_SPACE() causing compile time error on Mac OS X, Programmingkid, 2016/01/17
- Re: [Qemu-devel] CMSG_SPACE() causing compile time error on Mac OS X, Programmingkid, 2016/01/18
- Re: [Qemu-devel] CMSG_SPACE() causing compile time error on Mac OS X, Peter Maydell, 2016/01/18
- Re: [Qemu-devel] CMSG_SPACE() causing compile time error on Mac OS X, Programmingkid, 2016/01/18
- Re: [Qemu-devel] CMSG_SPACE() causing compile time error on Mac OS X, Peter Maydell, 2016/01/18
- Re: [Qemu-devel] CMSG_SPACE() causing compile time error on Mac OS X, Programmingkid, 2016/01/18
- Re: [Qemu-devel] CMSG_SPACE() causing compile time error on Mac OS X, Programmingkid, 2016/01/19
Re: [Qemu-devel] CMSG_SPACE() causing compile time error on Mac OS X, Daniel P. Berrange, 2016/01/18