From owner-freebsd-arch@FreeBSD.ORG Tue Aug 28 13:12:20 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 230DC1065673 for ; Tue, 28 Aug 2012 13:12:20 +0000 (UTC) (envelope-from imp@bsdimp.com) Received: from mail-iy0-f182.google.com (mail-iy0-f182.google.com [209.85.210.182]) by mx1.freebsd.org (Postfix) with ESMTP id D61D78FC16 for ; Tue, 28 Aug 2012 13:12:19 +0000 (UTC) Received: by ialo14 with SMTP id o14so13523509ial.13 for ; Tue, 28 Aug 2012 06:12:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=sender:subject:mime-version:content-type:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to:x-mailer :x-gm-message-state; bh=E/knWnBt3ho5KsYPmjtbhIS6TCisnVxzJrTW/+MsABk=; b=geDfvKUxXo+8BXmnFs7d4Selhr36ZZL3mTLspeZrOiN351iESzBRK83bsocPVeYeto Sn+MSH+jzxQl7fmLTTDWr7buf6/5FnYFiiL+I5VOtXjlTIds77fS9tD7r5bUsIhaS34x vQymReOopbznUomKJCWtC9I2h5pigrnmy6N9ocmxpC6hPo9C4J4Hkt+UeI6AUpfOheDH iE50i80JMy2unUu41V3cTW1Yj49W3YTR0GGPo5lWgAHqTwreQC6+xL7AiTes6Z06rqWr J8xx7LWJ70ehtZ/rdOT5uznuiMb/KwlTS3Y9i4UzNudRRbsdcspu/t4c/07oCiMv3JPw 9jyw== Received: by 10.50.220.169 with SMTP id px9mr13478929igc.8.1346159539140; Tue, 28 Aug 2012 06:12:19 -0700 (PDT) Received: from 63.imp.bsdimp.com (50-78-194-198-static.hfc.comcastbusiness.net. [50.78.194.198]) by mx.google.com with ESMTPS id va9sm3111303igb.17.2012.08.28.06.12.16 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 28 Aug 2012 06:12:16 -0700 (PDT) Sender: Warner Losh Mime-Version: 1.0 (Apple Message framework v1084) Content-Type: text/plain; charset=us-ascii From: Warner Losh In-Reply-To: <503C8809.3050507@FreeBSD.org> Date: Tue, 28 Aug 2012 07:12:15 -0600 Content-Transfer-Encoding: quoted-printable Message-Id: References: <503C8809.3050507@FreeBSD.org> To: Andrey Zonov X-Mailer: Apple Mail (2.1084) X-Gm-Message-State: ALoCoQkFJv2V1LwoUIRu4SqhMAsP32QSwAigGlvOLFicBmUbdCfVuGT4L5rR30InpqN5X42/tqBv 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 13:12:20 -0000 On Aug 28, 2012, at 2:57 AM, Andrey Zonov wrote: > 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? 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. Warner > 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 >=20 > --=20 > Andrey Zonov >=20