From owner-freebsd-arch@FreeBSD.ORG Tue Aug 28 14:07:25 2012 Return-Path: Delivered-To: freebsd-arch@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id CAEAD1065676; Tue, 28 Aug 2012 14:07:25 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from mail.zoral.com.ua (mx0.zoral.com.ua [91.193.166.200]) by mx1.freebsd.org (Postfix) with ESMTP id 5EEE38FC19; Tue, 28 Aug 2012 14:07:25 +0000 (UTC) Received: from skuns.kiev.zoral.com.ua (localhost [127.0.0.1]) by mail.zoral.com.ua (8.14.2/8.14.2) with ESMTP id q7SE6w0C017253; Tue, 28 Aug 2012 17:06:58 +0300 (EEST) (envelope-from kostikbel@gmail.com) Received: from deviant.kiev.zoral.com.ua (kostik@localhost [127.0.0.1]) by deviant.kiev.zoral.com.ua (8.14.5/8.14.5) with ESMTP id q7SE6kGa065649; Tue, 28 Aug 2012 17:06:46 +0300 (EEST) (envelope-from kostikbel@gmail.com) Received: (from kostik@localhost) by deviant.kiev.zoral.com.ua (8.14.5/8.14.5/Submit) id q7SE6kGV065648; Tue, 28 Aug 2012 17:06:46 +0300 (EEST) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: deviant.kiev.zoral.com.ua: kostik set sender to kostikbel@gmail.com using -f Date: Tue, 28 Aug 2012 17:06:46 +0300 From: Konstantin Belousov To: Andrey Zonov Message-ID: <20120828140646.GP33100@deviant.kiev.zoral.com.ua> References: <503C8809.3050507@FreeBSD.org> <503CCF6E.7080208@FreeBSD.org> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="V5RPc/ioYsxrZT/b" Content-Disposition: inline In-Reply-To: <503CCF6E.7080208@FreeBSD.org> User-Agent: Mutt/1.4.2.3i X-Virus-Scanned: clamav-milter 0.95.2 at skuns.kiev.zoral.com.ua X-Virus-Status: Clean X-Spam-Status: No, score=-4.0 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 autolearn=ham version=3.2.5 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on skuns.kiev.zoral.com.ua Cc: freebsd-arch@freebsd.org Subject: Re: warning: cast increases required alignment of target type X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 28 Aug 2012 14:07:26 -0000 --V5RPc/ioYsxrZT/b Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Aug 28, 2012 at 06:02:22PM +0400, Andrey Zonov wrote: > On 8/28/12 5:12 PM, Warner Losh wrote: > >=20 > > On Aug 28, 2012, at 2:57 AM, Andrey Zonov wrote: > >=20 > >> Hi, > >> > >> Does anyone know how to correctly fix this warning for > >> arm/ia64/mips/sparc64? > >> > >> usr.bin/elf2aout/elf2aout.c: In function 'main': > >> usr.bin/elf2aout/elf2aout.c:129: warning: cast increases required > >> alignment of target type > >> > >> I found this explanation from bde, but still don't understand how to > >> correctly fix this issue. > >> > >> ----------------------------------------------------------------------= -- > >> r99799 | bde | 2002-07-11 22:06:09 +0400 (Thu, 11 Jul 2002) | 10 lines > >> > >> 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. > >> > >> Is this fix correct? > >=20 > > No. You need to tell the compiler that e has the alignment you think i= t 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. > >=20 > > Warner > >=20 >=20 > What do you say about this one? >=20 > Index: usr.bin/elf2aout/elf2aout.c > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > --- usr.bin/elf2aout/elf2aout.c (revision 239611) > +++ usr.bin/elf2aout/elf2aout.c (working copy) > @@ -126,7 +126,7 @@ > entry =3D xe64toh(e->e_entry); > phoff =3D xe64toh(e->e_phoff); > phnum =3D xe16toh(e->e_phnum); > - p =3D (Elf64_Phdr *)((char *)e + phoff); > + p =3D (Elf64_Phdr *)(e + phoff); This is plain wrong. Pointer arithmetic steps over the object's count, not the char count. You end up incrementing the pointer by sizeof(Elf64_Ehdr) * phoff. --V5RPc/ioYsxrZT/b Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.12 (FreeBSD) iEYEARECAAYFAlA80HUACgkQC3+MBN1Mb4gN/wCeIqW6V9e4laTixzkB+x3mEJGJ prwAn2l9tWplARTgmDer/lRXQ98UyQLU =+2F4 -----END PGP SIGNATURE----- --V5RPc/ioYsxrZT/b--