Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 28 Aug 2012 16:28:51 +0300
From:      Konstantin Belousov <kostikbel@gmail.com>
To:        Warner Losh <imp@bsdimp.com>
Cc:        Andrey Zonov <zont@freebsd.org>, freebsd-arch@freebsd.org
Subject:   Re: warning: cast increases required alignment of target type
Message-ID:  <20120828132851.GN33100@deviant.kiev.zoral.com.ua>
In-Reply-To: <CDF0AE44-1CB2-42F7-BE60-DD2E4697A374@bsdimp.com>
References:  <503C8809.3050507@FreeBSD.org> <CDF0AE44-1CB2-42F7-BE60-DD2E4697A374@bsdimp.com>

next in thread | previous in thread | raw e-mail | index | archive | help

--rNtzt+pFA3UwHi4l
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Tue, Aug 28, 2012 at 07:12:15AM -0600, Warner Losh wrote:
>=20
> On Aug 28, 2012, at 2:57 AM, Andrey Zonov wrote:
>=20
> > Hi,
> >=20
> > Does anyone know how to correctly fix this warning for
> > arm/ia64/mips/sparc64?
> >=20
> > usr.bin/elf2aout/elf2aout.c: In function 'main':
> > usr.bin/elf2aout/elf2aout.c:129: warning: cast increases required
> > alignment of target type
> >=20
> > I found this explanation from bde, but still don't understand how to
> > correctly fix this issue.
> >=20
> > ------------------------------------------------------------------------
> > r99799 | bde | 2002-07-11 22:06:09 +0400 (Thu, 11 Jul 2002) | 10 lines
> >=20
> > Set NO_WERROR to ignore the following warning which is emitted on
> > alphas:
> >    .../elf2aout.c:130: warning: cast increases required alignment of
> >    target type
> > The warning is about casting ((char *)e + phoff) to a struct pointer,
> > where e is aligned but phoff might be garbage, so I think the warning
> > should be emitted on most machines (even on i386's, alignment checking
> > might be on) and the correct fix would involve validation phoff before
> > using it.
> >=20
> > Is this fix correct?
>=20
> No. You need to tell the compiler that e has the alignment you think
> it has so that it can check to make sure that you are actually right.
> Just casting like this defeats the purpose of the check and will break
> on other architectures.

Does compiler ever checks the alignment ? I thought that it is hardware that
performs (transparent) checks, like elfags.AC bit on x86.

IMO hardware checks are good enough, since having program headers
not aligned as required by ELF standard/ABI means that incoming ELF file
is corrupted.

Note that the same code is present in
libexec/rtld-elf/map_object.c:map_object(), and there it might indeed
make sense to introduce manual check for the alignment, to avoid hw
triggering trap. Instead, rtld could gracefully refuse to load the
mis-formed object.

--rNtzt+pFA3UwHi4l
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (FreeBSD)

iEYEARECAAYFAlA8x5IACgkQC3+MBN1Mb4hQkQCg8otcSRnQ3zwehPQZ/04vvYk5
rq8AoNiZm03DkLPOMCjl4SZHV8YpeVMU
=RdCC
-----END PGP SIGNATURE-----

--rNtzt+pFA3UwHi4l--



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