From owner-svn-src-all@FreeBSD.ORG Tue Oct 9 17:50:56 2012 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 027AC671 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 B62948FC1A for ; Tue, 9 Oct 2012 17:50:55 +0000 (UTC) Received: by mail-pa0-f54.google.com with SMTP id bi1so6028252pad.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=Vrbj7SNni6ky7ad3fkzLvVXoif4wruGiiRl0hf7qORIl8ap3fg+ZrwVbUjMg2v/hFb aXXAO0HoH4x/D9GUE+CcSVFZgXW8+4+XujXHQHMpv26cSMcWfs1ImSElGIOyu1LWUhcx 8mxkLXbAlOXDd/B2jlb4tgfRieWDX1TXurpe/aXgNnVIj52GCfQv/res46esBaSwsPEJ NTn5EDW/uk2ziXjUG+bZaz5G90ecmOUYkdQxn0tFABw5AYm8HtnGorUt7x970+sLYdxv DxLQlasf8jW4vLFEvxdSkLn+RmJzMU7QxaQ0MflTDXIZ0DBIGMDD2wdzdiWGOE7gkECS j9iQ== 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: ALoCoQl6ucR8pxcn4D3tQvv/ZCBShdajGjYobRiD6eHkL4Fcfqb+of5Ai0ikksGUAtf4cw8dQsTJ Cc: svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org, Andrey Chernov X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.14 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: 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