From owner-svn-src-head@FreeBSD.ORG Tue Oct 9 16:33:39 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 4E3D9DCF for ; Tue, 9 Oct 2012 16:33:39 +0000 (UTC) (envelope-from ache@vniz.net) Received: from mail-la0-f54.google.com (mail-la0-f54.google.com [209.85.215.54]) by mx1.freebsd.org (Postfix) with ESMTP id 5E6788FC1A for ; Tue, 9 Oct 2012 16:33:37 +0000 (UTC) Received: by mail-la0-f54.google.com with SMTP id e12so3837049lag.13 for ; Tue, 09 Oct 2012 09:33:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=sender:message-id:disposition-notification-to:date:from:user-agent :mime-version:to:cc:subject:references:in-reply-to:openpgp :content-type:content-transfer-encoding:x-gm-message-state; bh=7E7OarEG0pKxEk5veo8pPVkb9NIFp9mdnpFrlTCcMQw=; b=N4zFL5C37Y+gsPkUV8nFayy+YLBorg0QnnA6fhkMgPEqYVumLWRbEetEeWfqONfWmQ IV2pgiFyKBo+fu7eMp9yn/56BzxloX3CTeKGkNqC9v8f+Uj/uFRvuvOLthTRjntyUabk RMwiyVbsOSF0L756XYtYADj0Q2j/e/rNCZvj8N8M6VctGx5EfgJawEVWvW4k/RTAnT9u RPA/1PLAKRekhxTdD9F+ER7LSOr/z4HAOoGtA/ZunI036669jawr/UdTt35976poLwcn dlsV+dKsjJgaJU3gQwEIiAqVBnryxikOuMDUkEZdLc0t3jlNdKSKmd3FOANbeNR0zpFx Ws2A== Received: by 10.152.132.168 with SMTP id ov8mr17273806lab.0.1349800416762; Tue, 09 Oct 2012 09:33:36 -0700 (PDT) Received: from [192.168.1.2] ([89.169.140.97]) by mx.google.com with ESMTPS id h8sm6159426lbk.0.2012.10.09.09.33.36 (version=SSLv3 cipher=OTHER); Tue, 09 Oct 2012 09:33:36 -0700 (PDT) Sender: "Chernov, Andrey" Message-ID: <507451DE.9060909@freebsd.org> Date: Tue, 09 Oct 2012 20:33:34 +0400 From: Andrey Chernov User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:15.0) Gecko/20120907 Thunderbird/15.0.1 MIME-Version: 1.0 To: Eitan Adler Subject: Re: svn commit: r241373 - head/lib/libc/stdlib References: <201210091425.q99EPFS6020787@svn.freebsd.org> In-Reply-To: <201210091425.q99EPFS6020787@svn.freebsd.org> OpenPGP: id=964474DD Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Gm-Message-State: ALoCoQnmWqO4BACyYZME+VOHQG8yPrb5jkRSZsyKIcj8UZpeYCaVfAv/ed6hVTMU93NuEO6zI1Kc Cc: svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org 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 16:33:39 -0000 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. On 09.10.2012 18:25, Eitan Adler wrote: > Author: eadler > Date: Tue Oct 9 14:25:14 2012 > New Revision: 241373 > URL: http://svn.freebsd.org/changeset/base/241373 > > Log: > Remove undefined behavior from sranddev() and > srandomdev(). This doesn't actually work > with any modern C compiler: > > In particular, both clang and modern gcc > verisons silently elide any xor operation > with 'junk'. > > Approved by: secteam > MFC after: 3 days > > Modified: > head/lib/libc/stdlib/rand.c > head/lib/libc/stdlib/random.c > > Modified: head/lib/libc/stdlib/rand.c > ============================================================================== > --- head/lib/libc/stdlib/rand.c Tue Oct 9 13:21:08 2012 (r241372) > +++ head/lib/libc/stdlib/rand.c Tue Oct 9 14:25:14 2012 (r241373) > @@ -130,10 +130,9 @@ sranddev() > > if (!done) { > struct timeval tv; > - unsigned long junk; > > gettimeofday(&tv, NULL); > - srand((getpid() << 16) ^ tv.tv_sec ^ tv.tv_usec ^ junk); > + srand((getpid() << 16) ^ tv.tv_sec ^ tv.tv_usec); > } > } > > > Modified: head/lib/libc/stdlib/random.c > ============================================================================== > --- head/lib/libc/stdlib/random.c Tue Oct 9 13:21:08 2012 (r241372) > +++ head/lib/libc/stdlib/random.c Tue Oct 9 14:25:14 2012 (r241373) > @@ -312,10 +312,9 @@ srandomdev(void) > > if (!done) { > struct timeval tv; > - volatile unsigned long junk; > > gettimeofday(&tv, NULL); > - srandom((getpid() << 16) ^ tv.tv_sec ^ tv.tv_usec ^ junk); > + srandom((getpid() << 16) ^ tv.tv_sec ^ tv.tv_usec); > return; > } > >