From owner-freebsd-arch@FreeBSD.ORG Tue Aug 28 14:02:29 2012 Return-Path: Delivered-To: freebsd-arch@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 3AA94106566B for ; Tue, 28 Aug 2012 14:02:29 +0000 (UTC) (envelope-from andrey@zonov.org) Received: from mail-lb0-f182.google.com (mail-lb0-f182.google.com [209.85.217.182]) by mx1.freebsd.org (Postfix) with ESMTP id 9C67E8FC16 for ; Tue, 28 Aug 2012 14:02:28 +0000 (UTC) Received: by lbbgg13 with SMTP id gg13so3854770lbb.13 for ; Tue, 28 Aug 2012 07:02:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=sender:message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:x-enigmail-version:content-type :x-gm-message-state; bh=EmGS27ndmxzBRipFqW0CO+tzpy6q2y3u/+3whMVoaro=; b=niZMgagmfHqsdg6JY3X6GLqC6KSA/rOVZmPfKrx4kEE++FvzWRCuoSOOodXgXuCRNX KQef/ge3zLQPAIqT6hU4dAqTCrqAiyXEi7ghqn1YYuNEL1YTTsk0A3xF12yPGlMDinvY uLQ94iQ9v85uWG6AOowA4vBgLNSkQXxbtbYNAtJeqUAtgHjUcdCTGQVC07GqwsXcoc65 xwmCWCOlwkko4urNxzYnDlmk0h7+J0HIZVaWss+SUKIHbe3WEX8T1DG25ZsIj34+kk7e d/jBLMXkTQ467QzugpEDCdA1kHsPPO4honXyNYtGVTs+ektPXQC1KGK5raFQ5/LRJDS5 fkiA== Received: by 10.152.112.136 with SMTP id iq8mr18687949lab.18.1346162547227; Tue, 28 Aug 2012 07:02:27 -0700 (PDT) Received: from zont-osx.local (ppp95-165-143-86.pppoe.spdop.ru. [95.165.143.86]) by mx.google.com with ESMTPS id y4sm2151756lbg.5.2012.08.28.07.02.26 (version=SSLv3 cipher=OTHER); Tue, 28 Aug 2012 07:02:26 -0700 (PDT) Sender: Andrey Zonov Message-ID: <503CCF6E.7080208@FreeBSD.org> Date: Tue, 28 Aug 2012 18:02:22 +0400 From: Andrey Zonov User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:14.0) Gecko/20120713 Thunderbird/14.0 MIME-Version: 1.0 To: Warner Losh References: <503C8809.3050507@FreeBSD.org> In-Reply-To: X-Enigmail-Version: 1.4.3 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="------------enigC0AA8BFED6D1E4FEBC86BF53" X-Gm-Message-State: ALoCoQl7X+Qtvip6KH09o1NxJyLKATsvTRcP1jXZFaMf3NYNdbdJqKt7eYzxwn63NEsUS08tsbke 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:02:29 -0000 This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enigC0AA8BFED6D1E4FEBC86BF53 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable 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. Jus= t casting like this defeats the purpose of the check and will break on ot= her architectures. >=20 > Warner >=20 What do you say about this one? 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); bzero(&a, sizeof(a)); for (i =3D 0; i < phnum; i++) { type =3D xe32toh(p[i].p_type); I can build elf2aout without warnings on amd64 in 'buildenv' for all targets. >> 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 *)(void *)((char *)e + phoff); >> bzero(&a, sizeof(a)); >> for (i =3D 0; i < phnum; i++) { >> type =3D xe32toh(p[i].p_type); >> >> >> --=20 >> Andrey Zonov >> >=20 --=20 Andrey Zonov --------------enigC0AA8BFED6D1E4FEBC86BF53 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG/MacGPG2 v2.0.18 (Darwin) Comment: GPGTools - http://gpgtools.org iQEcBAEBAgAGBQJQPM9wAAoJEBWLemxX/CvTx3YH/RMywLzQHvj1Q4gjdmElavnh v11NF5TNplZxMB5RR/7cY202Jw3GOIV4Jeei1ElqNS1tmBjALtO0h1ROfaGbTGki C8Hb8L/U+Te0TZjI8VSpvv3CwmG99iZNjrxtrIg0RXRmWcAzb7su81eKqrmDhdWl r/YehA6gg4Y2ePWRL2Sq0DLJNMPwTwSjNxJZI82MzJAlBDJlqGSP/PDi+u1maIY6 k1LoNoVnb4MMoBRVZ/pa6KgD3BgSxumPCU5DOl9Nm2k3Xb61mmwBN1aiXrMjjSpJ 7MDvWRcpzU78b4cFNFLtWywTrdpZTEWr1fUPF5rMLcwMqPrVikky2VzHEInVDnQ= =DEZE -----END PGP SIGNATURE----- --------------enigC0AA8BFED6D1E4FEBC86BF53--