qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] SLIRP warning messages displayed while compiling


From: Eric Blake
Subject: Re: [Qemu-devel] SLIRP warning messages displayed while compiling
Date: Mon, 14 Aug 2017 11:05:14 -0500
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1

On 08/12/2017 10:38 AM, Philippe Mathieu-Daudé wrote:
> Hi Eric,
> 
> On 08/12/2017 08:41 AM, Eric Blake wrote:
>> Here's an idea:  Instead of using struct ip6 { ... } QEMU_PACKED, use
>>
>> struct ip6 {
>> ...
>> };
>> QEMU_BUG_ON(sizeof(struct ip6) != 32);
>>
>> so that the compiler explicitly chokes if it introduced any padding, and
>> then we know all our accesses are naturally aligned which shuts up the
>> warning.
> 
> Following your suggestion I tried:
> 
> #define QEMU_BUG_STRUCT_UNALIGNED(s) \
>         QEMU_BUILD_BUG_ON(sizeof(s) != sizeof(s QEMU_PACKED))

I don't think gcc likes that (you can't just add attribute packed in
arbitrary places, but only where the type is declared).

> 
> QEMU_BUG_STRUCT_UNALIGNED(struct ip6);
> 
> but this gives:
> 
> qemu/slirp/ip6.h:157:1: warning: 'packed' attribute ignored when parsing
> type [-Wignored-attributes]
> QEMU_BUG_STRUCT_UNALIGNED(struct ip6);
> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Indeed, there's the evidence that your attempt at a shortcut didn't
work. My proposal was to put in a hard-coded number, rather than try to
make the compiler compute two variants of the type and check that they
occupy the same space (although I agree with your idea that if you CAN
get the compiler to do that, it's nicer than hand-computing the number
to compare against).

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]