Re: A suspicious warning in sys/boot/zfs/zfsimpl.c

From: Dimitry Andric <dim_at_FreeBSD.org>
Date: Sun, 02 Dec 2012 16:57:49 +0100
On 2012-12-02 01:37, Garrett Cooper wrote:
> On Sat, Dec 1, 2012 at 3:05 AM, Andriy Gapon <avg_at_freebsd.org> wrote:
>> I believe that there is no actual problem there.
>
>      It's probably bugs with clang dealing with alignment problems.

Which bugs?


> These warnings (and others) go largely unnoticed because of the fact
> that -Werror isn't on on sys/boot. I filed kern/173932 for that and
> have been grinding away on warnings for the past couple days in my
> spare time -- with my local modifications sys/boot compiles with
> -Werror now with gcc, but not clang.
> Thanks,
> -Garrett
>
> /store/freebsd/head/sys/boot/i386/zfsboot/zfsboot.c:101:24: error:
> tentative definition of variable with internal linkage has incomplete
> non-array type 'struct zfsmount'
> [-Werror,-Wtentative-definition-incomplete-type]
> static struct zfsmount zfsmount;
>                         ^
> /store/freebsd/head/sys/boot/i386/zfsboot/zfsboot.c:101:15: note:
> forward declaration of 'struct zfsmount'
> static struct zfsmount zfsmount;
>                ^

This is just a programming error: struct zfsmount is declared in
zfsimpl.c, but that file is included on line 151, so 50 lines after the
static variable definition.

Either the include should be moved up, or the definition moved down.


> In file included from /store/freebsd/head/sys/boot/i386/zfsboot/zfsboot.c:151:
> In file included from
> /store/freebsd/head/sys/boot/i386/zfsboot/../../zfs/zfsimpl.c:38:
> /store/freebsd/head/sys/boot/i386/zfsboot/../../../cddl/boot/zfs/zfssubr.c:207:9:
> error: cast from 'char *' to 'zio_eck_t *' (aka 'struct zio_eck *')
> increases required alignment from 1 to 4 [-Werror,-Wcast-align]
>                  eck = (zio_eck_t *)((char *)data + size) - 1;
>                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Clang is right here, the alignment *is* being increased.  However, on
x86, there is no problem with it, so the warning can be ignored.  On the
other hand, if the code should be portable to alignment-sensitive
arches, the code should be fixed.  The same holds for all the other
alignment warnings.

The difference between gcc and clang is that gcc never seems to warn
about alignment issues on x86.  You must compile the code with a gcc
targeting an alignment-sensitive arch, to get any warnings.  Clang
always warns, when using -Wcast-align.
Received on Sun Dec 02 2012 - 14:57:52 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:40:32 UTC