From owner-freebsd-arch@FreeBSD.ORG Tue Aug 28 14:10:36 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 292B6106566C for ; Tue, 28 Aug 2012 14:10:36 +0000 (UTC) (envelope-from andrey@zonov.org) Received: from mail-lpp01m010-f54.google.com (mail-lpp01m010-f54.google.com [209.85.215.54]) by mx1.freebsd.org (Postfix) with ESMTP id 8F71B8FC14 for ; Tue, 28 Aug 2012 14:10:35 +0000 (UTC) Received: by lage12 with SMTP id e12so3872007lag.13 for ; Tue, 28 Aug 2012 07:10:34 -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=10xJHBw8RkGGD/4lwitH9KlSVaI+qtHLyntReqoprsI=; b=kpHMMs5qJH08G6EiVlNq1KeB0/bNKHnr3ADUHetpEXhHjDHuwFtV31fHWx3gzC9mYF g2hMD4opwOQ6f+JKGi9jGZe5oZu4XOLViJB9iVWKdZ0FSCY6kiqIdeG/vcyANszLWoA5 jBcj1WNbFjT4ucpvIhiXuRMBByN7ohCtSt8/6xuKZ8/2DsE+1OaLdpZ8xT74PvqDUqjq 023ibUC7F/Tl0Z/C4xImL7lajlbubJJ7PZZEBQEvNERzFb2A4smGZ9xOFA97j74O8eeV k4YhY/LNDT0M7y8RfWqZ+hsjY3oS8doyiKODhKLeQFSj5CTsqphNszTatf9yo5IQ2e8b QpdA== Received: by 10.152.112.138 with SMTP id iq10mr18737959lab.13.1346163034166; Tue, 28 Aug 2012 07:10:34 -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 xx8sm22205012lab.10.2012.08.28.07.10.32 (version=SSLv3 cipher=OTHER); Tue, 28 Aug 2012 07:10:33 -0700 (PDT) Sender: Andrey Zonov Message-ID: <503CD157.50306@FreeBSD.org> Date: Tue, 28 Aug 2012 18:10:31 +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: Konstantin Belousov References: <503C8809.3050507@FreeBSD.org> <503CCF6E.7080208@FreeBSD.org> <20120828140646.GP33100@deviant.kiev.zoral.com.ua> In-Reply-To: <20120828140646.GP33100@deviant.kiev.zoral.com.ua> X-Enigmail-Version: 1.4.3 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="------------enigDDAEA3B6B075123B90F271DA" X-Gm-Message-State: ALoCoQlCLeDyEreVIs0V15sGaD8hMN0FA/telOnJ86KSxTbuMWalJwfnkz4yKHGvxGv8IyEweVqw 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:10:36 -0000 This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enigDDAEA3B6B075123B90F271DA Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable On 8/28/12 6:06 PM, Konstantin Belousov wrote: > On Tue, Aug 28, 2012 at 06:02:22PM +0400, Andrey Zonov wrote: >> On 8/28/12 5:12 PM, Warner Losh wrote: >>> >>> On Aug 28, 2012, at 2:57 AM, Andrey Zonov wrote: >>> >>>> 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 lin= es >>>> >>>> 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 warnin= g >>>> should be emitted on most machines (even on i386's, alignment checki= ng >>>> might be on) and the correct fix would involve validation phoff befo= re >>>> using it. >>>> >>>> Is this fix correct? >>> >>> 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. J= ust casting like this defeats the purpose of the check and will break on = other architectures. >>> >>> Warner >>> >> >> 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); > 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. >=20 Ooops, you are totally right. --=20 Andrey Zonov --------------enigDDAEA3B6B075123B90F271DA 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 iQEcBAEBAgAGBQJQPNFXAAoJEBWLemxX/CvTyNMH/07DQY9SEqLzWCicIpF5l8Lo 5S97NSBUee97EMaBeI+vs3oWNp2tpl8klcil6GKg5731rhfWG7uwMToV8wBZL1jW fo2xdyUZjV2WgEw0s88uBjXLGhjmYtGu5aMBqTDjeszF+at47IbdGjoAO754GYfe 90gNj8NZyJz9o2xBeyeh7jr8bLylx7OlW9FNLRp7cap1kE3kVe3SG4Uo3CPxdn0I AfZ2bBNhHq0IKBfF++YKMtqCQWTrFAxumUiBy/eNcgGo5LlYDX3g9Oqivm7oDiy8 KY4VIF0Fc/uNeojaKwLJOp2nRy157q9jIRJfYDcmv3oam3gJfEwFok15gFyStW4= =k3PF -----END PGP SIGNATURE----- --------------enigDDAEA3B6B075123B90F271DA--