From: Thomas Huth <thuth@redhat.com>
To: Peter Maydell <peter.maydell@linaro.org>, Kevin Wolf <kwolf@redhat.com>
Cc: QEMU Developers <qemu-devel@nongnu.org>,
Fam Zheng <fam@euphon.net>, Qemu-block <qemu-block@nongnu.org>,
QEMU Trivial <qemu-trivial@nongnu.org>,
Max Reitz <mreitz@redhat.com>,
Satheesh Rajendran <sathnaga@linux.vnet.ibm.com>
Subject: Re: [Qemu-devel] [PATCH] block/nvme: Remove QEMU_PACKED from naturally aligned NVMeRegs struct
Date: Mon, 25 Feb 2019 16:28:43 +0100 [thread overview]
Message-ID: <8b979054-595e-e697-beb1-d45f1537c64d@redhat.com> (raw)
In-Reply-To: <CAFEAcA9bbZKeM=-P7mh90-QH35Kn_oR-D0yTUbteKg8JEV+Tgw@mail.gmail.com>
On 25/02/2019 15.30, Peter Maydell wrote:
> On Mon, 25 Feb 2019 at 14:09, Kevin Wolf <kwolf@redhat.com> 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.
Thomas
prev parent reply other threads:[~2019-02-25 15:29 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-25 11:59 [Qemu-devel] [PATCH] block/nvme: Remove QEMU_PACKED from naturally aligned NVMeRegs struct Thomas Huth
2019-02-25 12:51 ` Peter Maydell
2019-02-25 14:09 ` Kevin Wolf
2019-02-25 14:30 ` Peter Maydell
2019-02-25 15:28 ` Thomas Huth [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=8b979054-595e-e697-beb1-d45f1537c64d@redhat.com \
--to=thuth@redhat.com \
--cc=fam@euphon.net \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-trivial@nongnu.org \
--cc=sathnaga@linux.vnet.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).