From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([209.51.188.92]:40306) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gyIBk-0006gp-Je for qemu-devel@nongnu.org; Mon, 25 Feb 2019 10:29:05 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gyIBd-0005SP-Cv for qemu-devel@nongnu.org; Mon, 25 Feb 2019 10:29:00 -0500 References: <1551095970-14645-1-git-send-email-thuth@redhat.com> <20190225140935.GE6320@linux.fritz.box> From: Thomas Huth Message-ID: <8b979054-595e-e697-beb1-d45f1537c64d@redhat.com> Date: Mon, 25 Feb 2019 16:28:43 +0100 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH] block/nvme: Remove QEMU_PACKED from naturally aligned NVMeRegs struct List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Maydell , Kevin Wolf Cc: QEMU Developers , Fam Zheng , Qemu-block , QEMU Trivial , Max Reitz , Satheesh Rajendran On 25/02/2019 15.30, Peter Maydell wrote: > On Mon, 25 Feb 2019 at 14:09, Kevin Wolf 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 #include 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