References: <1475060898-21462-1-git-send-email-steffan@...1856...> <29580155-6d16-3a15-d409-b2a52cf1e7be@...2080...> From: David Sommerseth Message-ID: <007153b7-099b-0b86-0aa1-a70e9d8d1495@...2080...> Date: Fri, 11 Nov 2016 13:21:28 +0100 MIME-Version: 1.0 In-Reply-To: <29580155-6d16-3a15-d409-b2a52cf1e7be@...2080...> Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="hmq2tj9pqxtr1os52uqOGPkKnFChp48pW" Subject: Re: [Openvpn-devel] [PATCH] Don't deference type-punned pointers Reply-To: openvpn-devel@lists.sourceforge.net List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Steffan Karger , openvpn-devel@lists.sourceforge.net This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --hmq2tj9pqxtr1os52uqOGPkKnFChp48pW Content-Type: multipart/mixed; boundary="6tKcirmTpI14TjCvrcoFVslAvWnWEBur8"; protected-headers="v1" From: David Sommerseth Reply-To: openvpn-devel@lists.sourceforge.net To: Steffan Karger , openvpn-devel@lists.sourceforge.net Message-ID: <007153b7-099b-0b86-0aa1-a70e9d8d1495@...2080...> Subject: Re: [Openvpn-devel] [PATCH] Don't deference type-punned pointers References: <1475060898-21462-1-git-send-email-steffan@...1856...> <29580155-6d16-3a15-d409-b2a52cf1e7be@...2080...> In-Reply-To: <29580155-6d16-3a15-d409-b2a52cf1e7be@...2080...> --6tKcirmTpI14TjCvrcoFVslAvWnWEBur8 Content-Type: text/plain; charset="windows-1252" Content-Transfer-Encoding: quoted-printable On 11/11/16 13:14, David Sommerseth wrote: > On 28/09/16 13:08, Steffan Karger wrote: >> Fixes compiler warnings (undefined behavior) by making the copy >> explicit to comply to strict aliasing rules. With newer GCC the >> old code could actually lead to undefined behaviour. >>=20 >> See e.g. http://blog.regehr.org/archives/959. >>=20 >> Signed-off-by: Steffan Karger ---=20 >> src/openvpn/mroute.h | 12 ++++++++---- 1 file changed, 8 >> insertions(+), 4 deletions(-) >>=20 >=20 > I've taken another stab on this one, read up [1,2,3] more carefully > on strict aliasing , type punning and undefined behaviours in > compilers. I do consider fixing this important, despite it might > not be strictly needed with today's compilers [4], we don't know if > and how this undefined behaviour will change in a future compiler > update - despite the risk of doing so is very low in our case. >=20 > The last time I looked at this, I identified that the assembly > being generated by the compiler is pretty much the same and it uses > some simple and mov instructions. In addition I also have a > better understanding why the code ends up as the same result, as > we're just storing an "fresh" integer value to the address > extracted via the dereferencing - and not manipulating data > extracted from that address and putting something else back, so the > compiler's optimizer won't be able to mess this up too badly. >=20 > When considering that the optimized code will be most optimal > regardless if we use type punning and breaking strict alias or we > will use memcpy() in the C code, it makes little sense to me to not > fix this warning. Today's compilers are truly clever in this aspect > when being asked to optimise variable assignments with static > lengths. >=20 > So all in all, I am willing to give this a full ACK now. However,=20 > compiling this with gcc and the common CFLAGS on RHEL and Fedora, > more issues related to strict aliasing appeared. With clang, there > were no more warnings with this patch. I think it would be good to > resolve the gcc issues as well. The issues located are found in > the attachment. >=20 >=20 > [1] > > >=20 [2] > [3]=20 > > >=20 [4] I've tested with gcc-4.8.5 (Red Hat 4.8.5-4) and clang-3.4.2 on > EL7.2 Just for the record, I'm using the following CFLAGS: CFLAGS=3D"-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=3D2 -fexceptions \ -fstack-protector --param=3Dssp-buffer-size=3D4" --=20 kind regards, David Sommerseth OpenVPN Technologies, Inc --6tKcirmTpI14TjCvrcoFVslAvWnWEBur8-- --hmq2tj9pqxtr1os52uqOGPkKnFChp48pW Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.22 (GNU/Linux) iQIcBAEBAgAGBQJYJbfIAAoJEIbPlEyWcf3y8FUP/izpzqCXDCHGGHpFJdI0B7A2 jcidphbqXjQdDQCdLBVY1/Y7IloG/nkpzgJdD6+E7vMmVZnz0FKx+fv9jY/bOerC D2vWGYVRtf2FrITdoP5yo903ryrr1HqZ7ziUNddA/pJwPPrX6OPHrKNCcziHvTGV C8K7MLPd4CDQZzW3n2ihqdngPeaHLvIDJvwhyPoDW2ucMll8KkTuSBkp0Xwdt8QR NzTGfjFyPn5GcOmXe7Dm1+2akmjBK+GN3U6taCwNXKmkfPHs20/fO9E1QyPqYda7 MBSiu7MynZqdvTZC+swFZ3SDA9fqX3HAbusPR3ZMhf01krIM+9ZQRhJi2z9zi6np DoHFoM+qV2JoOyh6jy8KCRQjTiWgdwsHwO5U411u6KUaQZigyU3AkESErqgh1S3v uI/C4WTJWOkgbvqqBNMG3cOqUB/GNiPmYtHyHLWKxA85C/m5DCL2Q9M1QZY1SFqQ njr4UDNL8VzLnP5+M2P7Wa6E+VAIWI+r1NAXoK0baJsN2Vlr0JOMWujR09+GgT9S gpafifTIIKtZ+Obp+32HH6lawUKjeNsJ02pKusexh3ssmLH0nKEN6GXYC+O8CuWr niiWwQFQx5u90/8hTqFuWXZAm5QDFGUcwLS41TyoInNO6oojXZ8Vns+UJH9fKkgr Xb5jutyVfY90yQpN1SDP =flA6 -----END PGP SIGNATURE----- --hmq2tj9pqxtr1os52uqOGPkKnFChp48pW--