From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 85613 invoked by alias); 14 Aug 2018 20:18:32 -0000 Mailing-List: contact fortran-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: fortran-owner@gcc.gnu.org Received: (qmail 85449 invoked by uid 89); 14 Aug 2018 20:18:31 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,KAM_LAZY_DOMAIN_SECURITY autolearn=ham version=3.3.2 spammy=sk:i386-pc, sk:i386pc, sk:sparcs, sk:sparc-s X-HELO: smtp.CeBiTec.Uni-Bielefeld.DE Received: from smtp.CeBiTec.Uni-Bielefeld.DE (HELO smtp.CeBiTec.Uni-Bielefeld.DE) (129.70.160.84) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 14 Aug 2018 20:18:29 +0000 Received: from localhost (localhost.CeBiTec.Uni-Bielefeld.DE [127.0.0.1]) by smtp.CeBiTec.Uni-Bielefeld.DE (Postfix) with ESMTP id 05A415C1; Tue, 14 Aug 2018 22:18:25 +0200 (CEST) Received: from smtp.CeBiTec.Uni-Bielefeld.DE ([127.0.0.1]) by localhost (malfoy.CeBiTec.Uni-Bielefeld.DE [127.0.0.1]) (amavisd-new, port 10024) with LMTP id jWrwSNHEZRb3; Tue, 14 Aug 2018 22:18:21 +0200 (CEST) Received: from manam.CeBiTec.Uni-Bielefeld.DE (p54ACF870.dip0.t-ipconnect.de [84.172.248.112]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.CeBiTec.Uni-Bielefeld.DE (Postfix) with ESMTPSA id 5A6395BF; Tue, 14 Aug 2018 22:18:21 +0200 (CEST) From: Rainer Orth To: Janne Blomqvist Cc: Jakub Jelinek , Fortran List , GCC Patches Subject: Re: [PATCH] Use getentropy() for seeding PRNG References: <20180803131903.24303-1-blomqvist.janne@gmail.com> <20180803132827.GO17988@tucnak> Date: Tue, 14 Aug 2018 20:18:00 -0000 In-Reply-To: (Janne Blomqvist's message of "Mon, 13 Aug 2018 13:12:12 +0300") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (usg-unix-v) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-SW-Source: 2018-08/txt/msg00064.txt.bz2 --=-=-= Content-Type: text/plain Content-length: 3038 Hi Janne, > PING > > On Fri, Aug 3, 2018 at 5:05 PM, Janne Blomqvist > wrote: > >> On Fri, Aug 3, 2018 at 4:28 PM, Jakub Jelinek wrote: >> >>> On Fri, Aug 03, 2018 at 04:19:03PM +0300, Janne Blomqvist wrote: >>> > --- a/libgfortran/intrinsics/random.c >>> > +++ b/libgfortran/intrinsics/random.c >>> > @@ -309,12 +309,9 @@ getosrandom (void *buf, size_t buflen) >>> > for (size_t i = 0; i < buflen / sizeof (unsigned int); i++) >>> > rand_s (&b[i]); >>> > return buflen; >>> > +#elif defined(HAVE_GETENTROPY) >>> > + return getentropy (buf, buflen); >>> > #else >>> >>> I wonder if it wouldn't be better to use getentropy only if it is >>> successful >>> and fall back to whatever you were doing before. >>> >>> E.g. on Linux, I believe getentropy in glibc just uses the getrandom >>> syscall, which has only been introduced in Linux kernel 3.17. >>> >> >> Yes, that is my understanding as well. >> >> >>> So, if somebody is running glibc 2.25 or later on kernel < 3.17, it will >>> fail, even though reads from /dev/urandom could work. >>> >> >> Hmm, fair enough. So replace the random.c part of the patch with >> >> diff --git a/libgfortran/intrinsics/random.c b/libgfortran/intrinsics/ >> random.c >> index 234c5ff95fd..229fa6995c0 100644 >> --- a/libgfortran/intrinsics/random.c >> +++ b/libgfortran/intrinsics/random.c >> @@ -310,11 +310,10 @@ getosrandom (void *buf, size_t buflen) >> rand_s (&b[i]); >> return buflen; >> #else >> - /* >> - TODO: When glibc adds a wrapper for the getrandom() system call >> - on Linux, one could use that. >> - >> - TODO: One could use getentropy() on OpenBSD. */ >> +#ifdef HAVE_GETENTROPY >> + if (getentropy (buf, buflen) == 0) >> + return 0; >> +#endif >> int flags = O_RDONLY; >> #ifdef O_CLOEXEC >> flags |= O_CLOEXEC; >> >> >> >> Just to be sure, I regtested this slightly modified patch as well. Ok for >> trunk? the patch broke Solaris 11.3+ bootstrap: /vol/gcc/src/hg/trunk/local/libgfortran/intrinsics/random.c: In function 'getosrandom': /vol/gcc/src/hg/trunk/local/libgfortran/intrinsics/random.c:314:7: error: implicit declaration of function 'getentropy'; did you mean 'get_nprocs'? [-Werror=implicit-function-declaration] 314 | if (getentropy (buf, buflen) == 0) | ^~~~~~~~~~ | get_nprocs According to the manpage, one needs to include to get the getentropy declaration. Fixed as follows. Bootstraps on i386-pc-solaris2.11, i386-pc-solaris2.10 (which lacks getentropy), sparc-sun-solaris2.11, and x86_64-pc-linux-gnu still running, but all already into make check. Ok for mainline? Rainer -- ----------------------------------------------------------------------------- Rainer Orth, Center for Biotechnology, Bielefeld University 2018-08-14 Rainer Orth * configure.ac: Check for . * configure, config.h.in: Regenerate. * intrinsics/random.c [HAVE_SYS_RANDOM_H]: Include . --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=sol2-libgfortran-getentropy.patch Content-length: 1160 # HG changeset patch # Parent 8cc4b3b19e87eb3221d688c25887efd199d44f89 Include for getentropy on Solaris diff --git a/libgfortran/configure.ac b/libgfortran/configure.ac --- a/libgfortran/configure.ac +++ b/libgfortran/configure.ac @@ -275,8 +275,9 @@ AC_TYPE_UINTPTR_T AC_CHECK_TYPES([ptrdiff_t]) # check header files (we assume C89 is available, so don't check for that) -AC_CHECK_HEADERS_ONCE(unistd.h sys/time.h sys/times.h sys/resource.h \ -sys/types.h sys/stat.h sys/wait.h floatingpoint.h ieeefp.h fenv.h fptrap.h \ +AC_CHECK_HEADERS_ONCE(unistd.h sys/random.h sys/time.h sys/times.h \ +sys/resource.h sys/types.h sys/stat.h sys/wait.h \ +floatingpoint.h ieeefp.h fenv.h fptrap.h \ fpxcp.h pwd.h complex.h xlocale.h) GCC_HEADER_STDINT(gstdint.h) diff --git a/libgfortran/intrinsics/random.c b/libgfortran/intrinsics/random.c --- a/libgfortran/intrinsics/random.c +++ b/libgfortran/intrinsics/random.c @@ -37,6 +37,9 @@ see the files COPYING3 and COPYING.RUNTI #include #include #include "time_1.h" +#ifdef HAVE_SYS_RANDOM_H +#include +#endif #ifdef __MINGW32__ #define HAVE_GETPID 1 --=-=-=--