Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 12 Nov 2006 15:42:30 +0100
From:      Giorgos Keramidas <keramida@freebsd.org>
To:        Ruslan Ermilov <ru@freebsd.org>, arm@freebsd.org, current@freebsd.org
Subject:   Re: [head tinderbox] failure on arm/arm
Message-ID:  <20061112144230.GC2331@kobe.laptop>
In-Reply-To: <20061112142710.GE91556@wombat.fafoe.narf.at> <20061112140010.GA47660@rambler-co.ru>
References:  <20061112133929.9194773068@freebsd-current.sentex.ca> <20061112140010.GA47660@rambler-co.ru> <20061112142710.GE91556@wombat.fafoe.narf.at> <20061112133929.9194773068@freebsd-current.sentex.ca> <20061112140010.GA47660@rambler-co.ru>

next in thread | previous in thread | raw e-mail | index | archive | help
On 2006-11-12 17:00, Ruslan Ermilov <ru@freebsd.org> wrote:
> > /src/lib/libelf/elf_rand.c: In function `elf_rand':
> > /src/lib/libelf/elf_rand.c:47: warning: cast increases required alignment of target type
> > *** Error code 1
> >
> > Stop in /src/lib/libelf.
> > *** Error code 1
>
> This looks like a GCC bug to me.  The following code snippet,
> when compiled on FreeBSD/arm, causes a -Wcast-align warning
> which doesn't look right:
>
> %%%
> $ cat a.c
> struct foo {
> 	char x;
> };
>
> struct foo *
> bubu(char *s)
> {
>
> 	return (struct foo *)s;
> }
> $ cc -c -Wcast-align a.c
> a.c: In function `bubu':
> a.c:9: warning: cast increases required alignment of target type
> %%%
>
> (None of other supported architecutes see the issue here.)

You can't cast any random (char *) pointer to a pointer of a type which
is (potentially) larger than 1 byte.  It's the same sort of warning you
will get if you try to:

    char ch[] = "\x00\x00\x00\x00";
    char *p = &(ch[0]);
    unsigned long *lptr = (unsigned long *)p;

You cannot guarantee that `ch' is stored in an address that is properly
aligned for (unsigned long), and this is what GCC warns about here.

On 2006-11-12 15:27, Stefan Farfeleder <stefan@fafoe.narf.at> wrote:
> What is sizeof(struct foo)?  If it's > 1 it makes sense.

Exactly :)




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20061112144230.GC2331>