[Top][All Lists]

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

Re: [Qemu-trivial] [PATCH] block/nvme: Remove QEMU_PACKED from naturally

From: Thomas Huth
Subject: Re: [Qemu-trivial] [PATCH] block/nvme: Remove QEMU_PACKED from naturally aligned NVMeRegs struct
Date: Mon, 25 Feb 2019 16:28:43 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.5.0

On 25/02/2019 15.30, Peter Maydell wrote:
> On Mon, 25 Feb 2019 at 14:09, Kevin Wolf <address@hidden> wrote:
>> Though I'm not sure why a compiler should warn if packed and non-packed
>> result in the exact same layout anyway...
> Packed implies "and any time you see a pointer to this struct
> it might not be aligned". Non-packed implies "you can assume
> that the base of the struct is aligned".

Right. FWIW, consider this small program:

#include <stdio.h>
#include <stdint.h>

typedef struct {
    uint64_t a;
    uint64_t b;
    uint64_t c;
    uint64_t d;
} __attribute__((packed)) s1_t;

struct {
    char x;
    s1_t s1;
} s2;

int main()
    printf("address of s2.s1.d = %p\n", &s2.s1.d);
    return 0;

Though all members of s1_t look like they are naturally aligned, I get
an odd pointer for one of its members in this case.

So passing along that pointer to other functions will certainly cause
crashes on architectures like Sparc, thus the compiler warning is indeed
justified here.


reply via email to

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