From owner-freebsd-current@FreeBSD.ORG Sun Dec 1 14:11:01 2013 Return-Path: Delivered-To: current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 567A3952; Sun, 1 Dec 2013 14:11:01 +0000 (UTC) Received: from tensor.andric.com (tensor.andric.com [IPv6:2001:7b8:3a7:1:2d0:b7ff:fea0:8c26]) (using TLSv1 with cipher ADH-CAMELLIA256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 12DC016E9; Sun, 1 Dec 2013 14:11:01 +0000 (UTC) Received: from [IPv6:2001:7b8:3a7::d491:85a3:d731:bb13] (unknown [IPv6:2001:7b8:3a7:0:d491:85a3:d731:bb13]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) by tensor.andric.com (Postfix) with ESMTPSA id 1EFD15C43; Sun, 1 Dec 2013 15:10:56 +0100 (CET) Content-Type: multipart/signed; boundary="Apple-Mail=_159D4490-6D58-409D-9F58-776BB4665676"; protocol="application/pgp-signature"; micalg=pgp-sha1 Mime-Version: 1.0 (Mac OS X Mail 7.0 \(1822\)) Subject: Re: RFC: (Unconditionally) enable -fno-strict-overflow for kernel builds From: Dimitry Andric In-Reply-To: Date: Sun, 1 Dec 2013 15:10:45 +0100 Message-Id: References: <20131130135616.GA59496@kib.kiev.ua> To: Adrian Chadd X-Mailer: Apple Mail (2.1822) Cc: Konstantin Belousov , "current@freebsd.org" X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 01 Dec 2013 14:11:01 -0000 --Apple-Mail=_159D4490-6D58-409D-9F58-776BB4665676 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=iso-8859-1 On 01 Dec 2013, at 01:33, Adrian Chadd wrote: > On 30 November 2013 15:25, Dimitry Andric wrote: ... >> Basically, if you rely on undefined behavior, you are inventing your own >> de facto language, which is *not* C. That is fine with me, but let's >> not pretend the FreeBSD kernel is written in C then. :-) > > Are you able to have clang/llvm/gcc tell us where/when code is relying > on undefined behaviour? So we can, like, fix them? Not in the most general sense, since that would amount to solving the halting problem. But there are some tools that can help quite a lot. I guess Coverity can already cover quite a lot of cases, and there is also the STACK tool from MIT: http://css.csail.mit.edu/stack/ It would be really nice to have this in ports. Another mechanism is run-time detection, e.g. the undefined behavior sanitizer and other sanitizers: http://clang.llvm.org/docs/UsersManual.html#controlling-code-generation some of which have also been ported to gcc, see: http://gcc.gnu.org/gcc-4.9/changes.html However, these have not been completely ported to FreeBSD yet, and come at a (sometimes large) run-time cost. Still a lot less than valgrind, though. :-) Also, for use in the kernel, the run-time support would have to be ported separately to the kernel environment. > If there was a way to lint this stuff then yes, please lint it. > > Otherwise we don't have the tools to know whether we're doing sane > things or not. > > (Same with things like strict aliasing..) Yes, the comparison with strict aliasing is spot-on. A lot of code has been written that is not aliasing safe, and if it is too much effort to fix it, using -fno-strict-aliasing is a reasonable workaround. Note this option can prevent a lot of very useful optimizations, but if you do not particularly care (for example if you are waiting for slow hardware anyway), it is fine to use it. -Dimitry --Apple-Mail=_159D4490-6D58-409D-9F58-776BB4665676 Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=signature.asc Content-Type: application/pgp-signature; name=signature.asc Content-Description: Message signed with OpenPGP using GPGMail -----BEGIN PGP SIGNATURE----- Version: GnuPG/MacGPG2 v2.0.22 (Darwin) iEYEARECAAYFAlKbQ2kACgkQsF6jCi4glqOmawCaAhMUbWSkuCS5aEowsaXbsk1D vigAn1PjUXbAXJUl5ay3I05V9PmPbCL6 =rKnu -----END PGP SIGNATURE----- --Apple-Mail=_159D4490-6D58-409D-9F58-776BB4665676--