[PATCH] conf: force 8 byte alignment for virObjectEvent

Eric Blake eblake at redhat.com
Wed Jun 3 15:44:15 UTC 2020

On 6/3/20 5:22 AM, Daniel P. Berrangé wrote:

> Forcing 8-byte alignment on virObjectEventPtr removes the
> alignment increase during casts to subclasses.
> Signed-off-by: Daniel P. Berrangé <berrange at redhat.com>
> ---
> Technically a build-breaker, but since we don't have any existing
> usage of __attribute__((aligned)), I wanted to get a second opinion
> on this approach.
> One alternative approach would be to switch one of the current "int"
> fields in virObjectEvent to "long long".

> -struct _virObjectEvent {
> +struct  __attribute__((aligned(4))) _virObjectEvent {
>       virObject parent;
>       int eventID;
>       virObjectMeta meta;

As in this, although it makes the struct larger on 32-bit platforms 
(which may in turn affect cache usage):

struct _virObjectEvent {
     virObject parent;
     long long eventID;

Another possibility: use the extension of unnamed unions (but if we're 
going to rely on gcc extensions, __attribute__ is nicer than unnamed 

struct _virObjectEvent {
     union {
         virObject parent;
         long long alignment_;
     int eventID;

We already limit ourselves to gcc and clang because of 
__attribute__((cleanup)), so I don't see any problem with your approach.

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

More information about the libvir-list mailing list