Received: from list by lists.gnu.org with archive (Exim 4.71) id 1ZFPvF-00085F-Ny for mharc-grub-devel@gnu.org; Wed, 15 Jul 2015 12:52:41 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50423) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZFPvD-000853-E8 for grub-devel@gnu.org; Wed, 15 Jul 2015 12:52:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZFPv7-000731-5l for grub-devel@gnu.org; Wed, 15 Jul 2015 12:52:39 -0400 Received: from mail-wi0-f172.google.com ([209.85.212.172]:32974) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZFPv6-00071z-TL for grub-devel@gnu.org; Wed, 15 Jul 2015 12:52:33 -0400 Received: by widic2 with SMTP id ic2so7872629wid.0 for ; Wed, 15 Jul 2015 09:52:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:date:from:to:subject:message-id:references :mime-version:content-type:content-disposition :content-transfer-encoding:in-reply-to:user-agent; bh=pkKsWFTnkhxiOIa4MvdDwivHgrXb8LqTG5pelofl1sU=; b=XDYUVPv/D1VAe1tN+QDoCjZ39JMdFZQgUoOO7pxa7LAAN/M9/AmbICECkn+e7RTDQ5 gSYWpb9yvflOVX8suw/bSvIePW9OpdgM/fHeZVKxqYaXF/K4PqQ9S+ScYGt6CrrhUjWl x18EnFF8T8ZoB1xOxtDsz233wGDB/fa59z1iWV5P7k8TfphgHZXbgOqpTiYyGmeqDdYD IAUNqhVriz2gdVwqnFzvm4A/8HRYkvn2ZD/DzvJx86hCe9j+lcY4+6CmDGQk/iGsd/VM HQVE5dONv9YgTocWXGrOs3sVE4h59UuuT0r9PRrJhGayd1h40dpccgN3SQ6/0y3LspA0 SWLQ== X-Gm-Message-State: ALoCoQkt8V3dY8if4rD/CTnWiLoeyYKDSmkciwTOm0NZu6eCdqEJHuagmdgfDVxmWY6rWy8VGKGY X-Received: by 10.180.206.229 with SMTP id lr5mr1985757wic.86.1436979151078; Wed, 15 Jul 2015 09:52:31 -0700 (PDT) Received: from bivouac.eciton.net (bivouac.eciton.net. [2a00:1098:0:86:1000:23:0:2]) by smtp.gmail.com with ESMTPSA id ib9sm8777924wjb.2.2015.07.15.09.52.29 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Wed, 15 Jul 2015 09:52:30 -0700 (PDT) Date: Wed, 15 Jul 2015 17:52:28 +0100 From: Leif Lindholm To: The development of GNU GRUB Subject: Re: [PATCH] zfs: fix compilation failure with clang due to alignment Message-ID: <20150715165228.GH8790@bivouac.eciton.net> References: <1435950347-20073-1-git-send-email-arvidjaar@gmail.com> <20150707171713.GB8790@bivouac.eciton.net> <55A680A6.8000707@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <55A680A6.8000707@gmail.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.85.212.172 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: The development of GNU GRUB List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 15 Jul 2015 16:52:41 -0000 On Wed, Jul 15, 2015 at 05:47:50PM +0200, Vladimir 'φ-coder/phcoder' Serbinenko wrote: > Go ahead The below was more of an RFC than something committable - are you OK with me splitting the types.h changes out as a separate patch? > On 07.07.2015 19:17, Leif Lindholm wrote: > > On Fri, Jul 03, 2015 at 10:05:47PM +0300, Andrei Borzenkov wrote: > >> I do not claim I understand why clang complains, but this patch does > >> fix it. > >> > >> fs/xfs.c:452:25: error: cast from 'struct grub_xfs_btree_node *' to > >> 'grub_uint64_t *' (aka 'unsigned long long *') increases required > >> alignment from 1 to 8 [-Werror,-Wcast-align] > >> grub_uint64_t *keys = (grub_uint64_t *)(leaf + 1); > >> ^~~~~~~~~~~~~~~~~~~~~~~~~~~ > >> 1 error generated. > >> > >> --- > >> > >> Jan, do you have any idea what's wrong and whether this is proper fix? > >> Or should I raise it with clang? > > > > Well, the problem is that struct grub_xfs_btree_node is defined with > > GRUB_PACKED - forcing a 1-byte alignment requirement as opposed to the > > 8-byte requirement that would naturally be enforced by the struct > > contents. And apparently clang objects to this, whereas gcc thinks > > everything is fine ... even though -Wcast-align is explicitly used. > > > > Now, grub_xfs_btree_keys() is only called by grub_xfs_read_block(), > > where it is immediately stuffed back into another 8-byte aligned > > pointer. And then the alignment is immediately discarded again by > > casting it to a (char *) for an arithmetic operation. > > > > If the alignment is indeed not required, it may be worth explicitly > > marking that pointer as one to a potentially unaligned location. > > But we don't currently appear to have a GRUB_UNALIGNED macro, to match > > the GRUB_PACKED for structs. Should we? > > > > If so, something like the following could be added to your patch for a > > more complete fix: > > --- a/grub-core/fs/xfs.c > > +++ b/grub-core/fs/xfs.c > > @@ -488,7 +488,7 @@ grub_xfs_read_block (grub_fshelp_node_t node, > > grub_disk_addr_t fileblock) > > if (node->inode.format == XFS_INODE_FORMAT_BTREE) > > { > > struct grub_xfs_btree_root *root; > > - const grub_uint64_t *keys; > > + const grub_uint64_t *keys GRUB_UNALIGNED; > > int recoffset; > > > > leaf = grub_malloc (node->data->bsize); > > diff --git a/include/grub/types.h b/include/grub/types.h > > index e732efb..720e236 100644 > > --- a/include/grub/types.h > > +++ b/include/grub/types.h > > @@ -30,6 +30,8 @@ > > #define GRUB_PACKED __attribute__ ((packed)) > > #endif > > > > +#define GRUB_UNALIGNED __attribute__ ((aligned (1))) > > + > > #ifdef GRUB_BUILD > > # define GRUB_CPU_SIZEOF_VOID_P BUILD_SIZEOF_VOID_P > > # define GRUB_CPU_SIZEOF_LONG BUILD_SIZEOF_LONG > > > > / > > Leif > > > >> grub-core/fs/xfs.c | 6 +++--- > >> 1 file changed, 3 insertions(+), 3 deletions(-) > >> > >> diff --git a/grub-core/fs/xfs.c b/grub-core/fs/xfs.c > >> index 7249291..ea8cf7e 100644 > >> --- a/grub-core/fs/xfs.c > >> +++ b/grub-core/fs/xfs.c > >> @@ -445,14 +445,14 @@ grub_xfs_next_de(struct grub_xfs_data *data, struct grub_xfs_dir2_entry *de) > >> return (struct grub_xfs_dir2_entry *)(((char *)de) + ALIGN_UP(size, 8)); > >> } > >> > >> -static grub_uint64_t * > >> +static void * > >> grub_xfs_btree_keys(struct grub_xfs_data *data, > >> struct grub_xfs_btree_node *leaf) > >> { > >> - grub_uint64_t *keys = (grub_uint64_t *)(leaf + 1); > >> + char *keys = (char *)leaf + sizeof (*leaf); > >> > >> if (data->hascrc) > >> - keys += 6; /* skip crc, uuid, ... */ > >> + keys += 6 * sizeof (grub_uint64_t); /* skip crc, uuid, ... */ > >> return keys; > >> } > >> > >> -- > >> tg: (7a21030..) u/xfs-clang-align (depends on: master) > >> > >> _______________________________________________ > >> Grub-devel mailing list > >> Grub-devel@gnu.org > >> https://lists.gnu.org/mailman/listinfo/grub-devel > > > > _______________________________________________ > > Grub-devel mailing list > > Grub-devel@gnu.org > > https://lists.gnu.org/mailman/listinfo/grub-devel > > > > > _______________________________________________ > Grub-devel mailing list > Grub-devel@gnu.org > https://lists.gnu.org/mailman/listinfo/grub-devel