From owner-svn-src-all@FreeBSD.ORG Tue Oct 9 16:33:39 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 EA81DDCE for ; Tue, 9 Oct 2012 16:33:38 +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 5E6278FC19 for ; Tue, 9 Oct 2012 16:33:37 +0000 (UTC) Received: by mail-la0-f54.google.com with SMTP id e12so3837050lag.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=gs/3cypaC2ddyWa/nRxtC0fHgs3gLVlfhcwy20z9TfRUVr3X0u3ewNwXSwCgEqGvaM 6b11WrM9QmVhSiTYnBUqnCLm86jdSHDr4/NlhsHVNsTo4SVeUo+OXlyo42hT/hBhHuqG Y/lMl553BRB47gpw1ncwKbVXdHAqQftHvX2ZM3g69omkepXJK6jYEQ1kpZDrqPremN73 YRcw8r3WaCP4z4LvpO+EXJzfpNc0CpuMOo6QozB5EjyiDV4wSd8ZPXPl3d5OBlkVhc7s T15ANxPjBm/UeEg46B3mb/V137psbfEW1oS7HogW4m24g79yO5gnta0VO5tmeedyZTjg aC/g== 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: ALoCoQnjBOQgzjU63ty7oG43zQQF+aMybBBFg/l5HTivzdYeOttNw5Ad4w1cQulG30JreyCRfhA8 Cc: svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org 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 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; > } > >