From owner-svn-src-head@FreeBSD.ORG Tue Oct 9 17:50:56 2012 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 41E73673 for ; Tue, 9 Oct 2012 17:50:56 +0000 (UTC) (envelope-from lists@eitanadler.com) Received: from mail-pa0-f54.google.com (mail-pa0-f54.google.com [209.85.220.54]) by mx1.freebsd.org (Postfix) with ESMTP id B635B8FC1C for ; Tue, 9 Oct 2012 17:50:55 +0000 (UTC) Received: by mail-pa0-f54.google.com with SMTP id bi1so6028253pad.13 for ; Tue, 09 Oct 2012 10:50:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=eitanadler.com; s=0xdeadbeef; h=mime-version:sender:in-reply-to:references:from:date :x-google-sender-auth:message-id:subject:to:cc:content-type :content-transfer-encoding; bh=4H6sWTB4mfNgbxTFgiovJd1tP1gB+y91aqb70kaDMAU=; b=rXtDJJstmMwi2Hx8f2l10b0V8NBIwNoiRS5mPPlCBEKYJJjMbJOvZqtYdQVTYk9KlN 8GK5l+kEOYSGsJ2LHaAmSoQgNgjtZHddBENAqCbfS1pkc32wgFHu3VSuKQyWvfDmi0hX E9KhZbWzgSGJHJdTvddXF29DJ9RQaxRDRapqw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date :x-google-sender-auth:message-id:subject:to:cc:content-type :content-transfer-encoding:x-gm-message-state; bh=4H6sWTB4mfNgbxTFgiovJd1tP1gB+y91aqb70kaDMAU=; b=a1BPBd3obxBshlofAgN11EJqU4rrDro46c94YLnk9QQiup8aGQfIJ4s2aUcDNCP6fV Yd4JEIxYuK6NlDnw4aQQwhrOm4Pk4kkEyBbPXaYbBGqNgmwmBQfdA78cQ+HZgOTK8Vjw Iip9dLFiW3duvd7FZLkZpdKj+gVglPAGDATj2tTrEoV8xwgBWckHDY3x5lUXx+HN0dkX OjmBWzlE0cJ34Rm1RVhWzjk+dHgkVQghvDtQ5WKWHIdxNSPqffvrKWQoE7Z0n4L/WabP d70iw58t2olWLbcifBCGz5sSrDa7N84layKpTrPkt1NLp4ymaGcotS78VISfW9dnFQox ILaw== Received: by 10.66.81.103 with SMTP id z7mr54602824pax.57.1349805055046; Tue, 09 Oct 2012 10:50:55 -0700 (PDT) MIME-Version: 1.0 Sender: lists@eitanadler.com Received: by 10.66.161.163 with HTTP; Tue, 9 Oct 2012 10:50:24 -0700 (PDT) In-Reply-To: <977E1107-46D4-476F-A04D-AEFD87D1DE53@FreeBSD.org> References: <201210091425.q99EPFS6020787@svn.freebsd.org> <507451DE.9060909@freebsd.org> <977E1107-46D4-476F-A04D-AEFD87D1DE53@FreeBSD.org> From: Eitan Adler Date: Tue, 9 Oct 2012 13:50:24 -0400 X-Google-Sender-Auth: oeThPxwWbcEA7rcNU2ZeyC6BuKo Message-ID: Subject: Re: svn commit: r241373 - head/lib/libc/stdlib To: David Chisnall Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Gm-Message-State: ALoCoQlIKZAuUEurM+xEP+56qpJ/ucQOAL7l/Vju4OgTgN9QUL5ND3KlebKU/qnJ8MOWWF1qSL4U Cc: svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org, Andrey Chernov X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 09 Oct 2012 17:50:56 -0000 On 9 October 2012 13:16, David Chisnall wrote: > On 9 Oct 2012, at 17:33, Andrey Chernov wrote: > >> Do you check assembler output for _both_ cases? >> In my testing clang and gcc xor's 'junk' properly in case it have >> 'volatile' keyword (as in srandomdev()) and elide it without 'volatile'. >> IMHO this change should be backed out for srandomdev() and adding >> 'volatile' for sranddev() instead. > > In it's original form, it is very dangerous - the whole expression reduce= s to undefined and so the LLVM IR for the call is: > > call void @srand(i32 undef) > > The back end is then free to use any value for the call argument, includi= ng any register value or 0. In fact, the backend is free to jump to a random location and potentially kill kittens. There is *no* guarantee when it comes to undefined behavior. > Adding the volatile means that we are doing an XOR with a value left on t= he stack. If this is early on in the application, then it is most likely t= o be 0. If it's later on, then there may be a value here, but it's still n= ot very likely to be something particularly unpredictable. volatile only helps by mistake because clang is overly aggressive is turning off optimizers. The code is still undefined. --=20 Eitan Adler Source & Ports committer X11, Bugbusting teams