From owner-svn-src-all@freebsd.org Thu Mar 5 18:20:16 2020 Return-Path: Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 8B14126FEBB; Thu, 5 Mar 2020 18:20:16 +0000 (UTC) (envelope-from dim@FreeBSD.org) Received: from smtp.freebsd.org (smtp.freebsd.org [96.47.72.83]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "smtp.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 48YJvM2YH6z3GCY; Thu, 5 Mar 2020 18:20:15 +0000 (UTC) (envelope-from dim@FreeBSD.org) Received: from tensor.andric.com (tensor.andric.com [IPv6:2001:470:7a58:1::1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "tensor.andric.com", Issuer "Let's Encrypt Authority X3" (verified OK)) (Authenticated sender: dim) by smtp.freebsd.org (Postfix) with ESMTPSA id 93643847; Thu, 5 Mar 2020 18:20:14 +0000 (UTC) (envelope-from dim@FreeBSD.org) Received: from [IPv6:2001:470:7a58::44b2:892b:3322:a46d] (unknown [IPv6:2001:470:7a58:0:44b2:892b:3322:a46d]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by tensor.andric.com (Postfix) with ESMTPSA id B89A62D14E; Thu, 5 Mar 2020 19:20:11 +0100 (CET) From: Dimitry Andric Message-Id: <1A13B93C-7D87-4210-AD3D-2B198C166CE1@FreeBSD.org> Content-Type: multipart/signed; boundary="Apple-Mail=_9C327041-3969-41C0-B571-F25708D80573"; protocol="application/pgp-signature"; micalg=pgp-sha1 Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.11\)) Subject: Re: svn commit: r358655 - head/sbin/mount_nfs Date: Thu, 5 Mar 2020 19:19:59 +0100 In-Reply-To: <20200305174411.GV5741@FreeBSD.org> Cc: Slawa Olhovchenkov , svn-src-head , svn-src-all , src-committers@freebsd.org To: Gleb Smirnoff References: <202003042227.024MRGsW072613@repo.freebsd.org> <244e28ea-1217-cefc-354e-02ecb201637a@FreeBSD.org> <20200305163350.GU5741@FreeBSD.org> <20200305172454.GJ8028@zxy.spb.ru> <20200305173515.GK8028@zxy.spb.ru> <20200305174411.GV5741@FreeBSD.org> X-Mailer: Apple Mail (2.3445.104.11) X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 05 Mar 2020 18:20:16 -0000 --Apple-Mail=_9C327041-3969-41C0-B571-F25708D80573 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii On 5 Mar 2020, at 18:44, Gleb Smirnoff wrote: >=20 > On Thu, Mar 05, 2020 at 08:35:15PM +0300, Slawa Olhovchenkov wrote: > S> > > D> sbin/mount_nfs/mount_nfs.c:549:10: error: cast from 'char *' = to 'struct > S> > > D> if_msghdr *' increases required alignment from 1 to 4 > S> > > D> [-Werror,-Wcast-align] > S> > > D> ifm =3D (struct if_msghdr *)buf; > S> > > D> ^~~~~~~~~~~~~~~~~~~~~~~ > S> > > D> 1 error generated. > S> > > D> > S> > > D> In practice I don't think the buffer can ever get = misaligned, so can you > S> > > D> please add a NO_WCAST_ALIGN=3D to the Makefile? > S> > > > S> > > route(8) handles the same problem via intermediate (void *) = cast. What is > S> > > preferred way to solve the problem? Change compiler flags file = wide, or > S> > > just through (void *) cast? > S> > > S> > Copy to aligned buffer or got SIGBUS on some architectures? > S> > S> char buf[2048] __aligned(__alignof(struct if_msghdr)); > S> > S> resolve this watning. >=20 > Thanks, Slawa! I think this is the most elegant solution. Why don't just declare the buffer as: struct if_msghdr buf; and then do: nread =3D read(s, &buf, sizeof buf); ? You are never reading more than one if_msghdr anyway, and then there is no need to cast anything. -Dimitry --Apple-Mail=_9C327041-3969-41C0-B571-F25708D80573 Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=signature.asc Content-Type: application/pgp-signature; name=signature.asc Content-Description: Message signed with OpenPGP -----BEGIN PGP SIGNATURE----- Version: GnuPG/MacGPG2 v2.2 iF0EARECAB0WIQR6tGLSzjX8bUI5T82wXqMKLiCWowUCXmFCzwAKCRCwXqMKLiCW o+ZEAJwLg7kEAdqiUVSNjAK2vAzAeqZ1CACeOlYaTkNlVV9/9u4Hz8rthtlJdm8= =jHHx -----END PGP SIGNATURE----- --Apple-Mail=_9C327041-3969-41C0-B571-F25708D80573--