From patchwork Mon Jul 22 12:07:49 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 260643 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "localhost", Issuer "www.qmailtoaster.com" (not verified)) by ozlabs.org (Postfix) with ESMTPS id B49662C008C for ; Mon, 22 Jul 2013 22:08:19 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:cc:subject:content-type; q=dns; s=default; b=uxvRrFKL7ApO49BjUUZtUbjpitp0UT67IpbnjYiZts2 dbwjub2UiFQ8oA16PknqVxUtyBQx3Lq5jTjcAeAHV80BuRSYipAnQD3ju0X+BsXp WaFp9jYGq7uC4XNtlzLpkMW60wyIOGDkOU50fZP9NalZpsePFbBoXHSMiIhXYjWQ = DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:cc:subject:content-type; s=default; bh=s33q5gLeBL07mlpHeFpMaugT+mc=; b=xXX/6MMsJjUzMybvp trWWSDp7anJTuG1CFxwBjcRa/Gq0MaIR66tZRubWxVJbVZAgkuJgkZaNKgP6UMJ4 V1bQ4m3AcZ/I8CO7V/OhO0lki3BITmoMRVz12obTETVnrIkT0ZRqn2BGkz5dCVam GBhuJON7ytLubsqo/ATQ5b3sLU= Received: (qmail 31346 invoked by alias); 22 Jul 2013 12:08:02 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 31299 invoked by uid 89); 22 Jul 2013 12:08:02 -0000 X-Spam-SWARE-Status: No, score=-2.5 required=5.0 tests=AWL, BAYES_50, FSL_NEW_HELO_USER, RCVD_IN_DNSWL_MED, RCVD_IN_HOSTKARMA_NO, RCVD_IN_HOSTKARMA_W, RDNS_NONE, SPF_PASS, TW_SF, UNPARSEABLE_RELAY autolearn=no version=3.3.1 X-Spam-User: qpsmtpd, 2 recipients Received: from Unknown (HELO userp1040.oracle.com) (156.151.31.81) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Mon, 22 Jul 2013 12:08:01 +0000 Received: from acsinet22.oracle.com (acsinet22.oracle.com [141.146.126.238]) by userp1040.oracle.com (Sentrion-MTA-4.3.1/Sentrion-MTA-4.3.1) with ESMTP id r6MC7qhB012835 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 22 Jul 2013 12:07:53 GMT Received: from aserz7021.oracle.com (aserz7021.oracle.com [141.146.126.230]) by acsinet22.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id r6MC7qKJ015354 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 22 Jul 2013 12:07:52 GMT Received: from abhmt101.oracle.com (abhmt101.oracle.com [141.146.116.53]) by aserz7021.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id r6MC7pVG017969; Mon, 22 Jul 2013 12:07:51 GMT Received: from poldo4.casa (/79.43.214.158) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 22 Jul 2013 05:07:51 -0700 Message-ID: <51ED2095.9000403@oracle.com> Date: Mon, 22 Jul 2013 14:07:49 +0200 From: Paolo Carlini User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130620 Thunderbird/17.0.7 MIME-Version: 1.0 To: "gcc-patches@gcc.gnu.org" CC: libstdc++ Subject: [v3] libstdc++/57920 X-Virus-Found: No Hi, see audit trail for details. I tested on x86_64-linux (with/without _GLIBCXX_X86_RDRAND artificially undefined) the below straightforward patch and checked by hand the strace. I'm going to apply it soon. Thanks, Paolo. /////////////////// 2013-07-22 Paolo Carlini PR c++/57920 * src/c++11/random.cc (random_device::_M_getval): If possible, use read instead of std::fread. * include/std/random: Do not include unnecessarily. Index: include/std/random =================================================================== --- include/std/random (revision 201122) +++ include/std/random (working copy) @@ -36,7 +36,6 @@ #else #include -#include #include #include #include Index: src/c++11/random.cc =================================================================== --- src/c++11/random.cc (revision 201122) +++ src/c++11/random.cc (working copy) @@ -30,7 +30,12 @@ # include #endif +#include +#ifdef _GLIBCXX_HAVE_UNISTD_H +# include +#endif + namespace std _GLIBCXX_VISIBILITY(default) { @@ -126,8 +131,12 @@ #endif result_type __ret; +#ifdef _GLIBCXX_HAVE_UNISTD_H + read(fileno(_M_file), reinterpret_cast(&__ret), sizeof(result_type)); +#else std::fread(reinterpret_cast(&__ret), sizeof(result_type), 1, _M_file); +#endif return __ret; }