From: Xi Ruoyao Date: Tue, 23 May 2017 16:11:57 +0000 (+0000) Subject: PR libstdc++/67578 Implement non-trivial std::random_device::entropy X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=78aa76df40b581bbc79a8ada55e437845b88d764;p=gcc.git PR libstdc++/67578 Implement non-trivial std::random_device::entropy 2017-05-23 Xi Ruoyao Jonathan Wakely PR libstdc++/67578 * acinclude.m4: Bump libtool_VERSION. * config/abi/pre/gnu.ver: Create GLIBCXX_3.4.24 with new symbol. * config.h.in: Regenerate. * configure: Regenerate. * configure.ac: Add test for . * doc/xml/manual/abi.xml: Document new library version. * include/bits/random.h (random_device::entropy) [_GLIBCXX_USE_RANDOM_TR1]: Add call to new _M_getentropy member. (random_device::_M_getentropy): Declare. * src/c++11/random.cc (random_device::_M_getentropy): Define. * testsuite/util/testsuite_abi.cc: Add GLIBCXX_3.4.24 to known versions, and make it the latest version. Co-Authored-By: Jonathan Wakely From-SVN: r248374 --- diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 5b34ccf1166..536e710f1ef 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,20 @@ +2017-05-23 Xi Ruoyao + Jonathan Wakely + + PR libstdc++/67578 + * acinclude.m4: Bump libtool_VERSION. + * config/abi/pre/gnu.ver: Create GLIBCXX_3.4.24 with new symbol. + * config.h.in: Regenerate. + * configure: Regenerate. + * configure.ac: Add test for . + * doc/xml/manual/abi.xml: Document new library version. + * include/bits/random.h (random_device::entropy) + [_GLIBCXX_USE_RANDOM_TR1]: Add call to new _M_getentropy member. + (random_device::_M_getentropy): Declare. + * src/c++11/random.cc (random_device::_M_getentropy): Define. + * testsuite/util/testsuite_abi.cc: Add GLIBCXX_3.4.24 to known + versions, and make it the latest version. + 2017-05-23 Xi Ruoyao PR libstdc++/67214 diff --git a/libstdc++-v3/acinclude.m4 b/libstdc++-v3/acinclude.m4 index 61c8cb29084..baeea67c459 100644 --- a/libstdc++-v3/acinclude.m4 +++ b/libstdc++-v3/acinclude.m4 @@ -3750,7 +3750,7 @@ changequote([,])dnl fi # For libtool versioning info, format is CURRENT:REVISION:AGE -libtool_VERSION=6:23:0 +libtool_VERSION=6:24:0 # Everything parsed; figure out what files and settings to use. case $enable_symvers in diff --git a/libstdc++-v3/config.h.in b/libstdc++-v3/config.h.in index f1527d9938b..e31e054c024 100644 --- a/libstdc++-v3/config.h.in +++ b/libstdc++-v3/config.h.in @@ -267,6 +267,9 @@ /* Define if futex syscall is available. */ #undef HAVE_LINUX_FUTEX +/* Define to 1 if you have the header file. */ +#undef HAVE_LINUX_RANDOM_H + /* Define to 1 if you have the header file. */ #undef HAVE_LOCALE_H diff --git a/libstdc++-v3/config/abi/pre/gnu.ver b/libstdc++-v3/config/abi/pre/gnu.ver index 268fb9479a9..48e2ec870fc 100644 --- a/libstdc++-v3/config/abi/pre/gnu.ver +++ b/libstdc++-v3/config/abi/pre/gnu.ver @@ -1967,6 +1967,13 @@ GLIBCXX_3.4.23 { } GLIBCXX_3.4.22; +GLIBCXX_3.4.24 { + + # std::random_device::_M_getentropy() const + _ZNKSt13random_device13_M_getentropyEv; + +} GLIBCXX_3.4.23; + # Symbols in the support library (libsupc++) have their own tag. CXXABI_1.3 { diff --git a/libstdc++-v3/configure b/libstdc++-v3/configure index 7c10c9e42df..282b4617db8 100755 --- a/libstdc++-v3/configure +++ b/libstdc++-v3/configure @@ -21795,7 +21795,7 @@ for ac_header in endian.h execinfo.h float.h fp.h ieeefp.h inttypes.h \ locale.h machine/endian.h machine/param.h nan.h stdint.h stdlib.h string.h \ strings.h sys/ipc.h sys/isa_defs.h sys/machine.h sys/param.h \ sys/resource.h sys/sem.h sys/stat.h sys/time.h sys/types.h unistd.h \ -wchar.h wctype.h +wchar.h wctype.h linux/random.h do : as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` ac_fn_c_check_header_mongrel "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default" @@ -79268,7 +79268,7 @@ $as_echo "$as_me: WARNING: === Symbol versioning will be disabled." >&2;} fi # For libtool versioning info, format is CURRENT:REVISION:AGE -libtool_VERSION=6:23:0 +libtool_VERSION=6:24:0 # Everything parsed; figure out what files and settings to use. case $enable_symvers in diff --git a/libstdc++-v3/configure.ac b/libstdc++-v3/configure.ac index 8e973503be0..270dcbaf723 100644 --- a/libstdc++-v3/configure.ac +++ b/libstdc++-v3/configure.ac @@ -237,7 +237,7 @@ AC_CHECK_HEADERS([endian.h execinfo.h float.h fp.h ieeefp.h inttypes.h \ locale.h machine/endian.h machine/param.h nan.h stdint.h stdlib.h string.h \ strings.h sys/ipc.h sys/isa_defs.h sys/machine.h sys/param.h \ sys/resource.h sys/sem.h sys/stat.h sys/time.h sys/types.h unistd.h \ -wchar.h wctype.h]) +wchar.h wctype.h linux/random.h]) # Only do link tests if native. Else, hardcode. if $GLIBCXX_IS_NATIVE; then diff --git a/libstdc++-v3/doc/xml/manual/abi.xml b/libstdc++-v3/doc/xml/manual/abi.xml index d086d9ecf2d..d17f06e25fb 100644 --- a/libstdc++-v3/doc/xml/manual/abi.xml +++ b/libstdc++-v3/doc/xml/manual/abi.xml @@ -266,6 +266,7 @@ compatible. GCC 5.1.0: libstdc++.so.6.0.21 GCC 6.1.0: libstdc++.so.6.0.22 GCC 7.1.0: libstdc++.so.6.0.23 + GCC 8.0.0: libstdc++.so.6.0.24 Note 1: Error should be libstdc++.so.3.0.3. @@ -334,6 +335,7 @@ compatible. GCC 5.1.0: GLIBCXX_3.4.21, CXXABI_1.3.9 GCC 6.1.0: GLIBCXX_3.4.22, CXXABI_1.3.10 GCC 7.1.0: GLIBCXX_3.4.23, CXXABI_1.3.11 + GCC 8.0.0: GLIBCXX_3.4.24, CXXABI_1.3.11 diff --git a/libstdc++-v3/include/bits/random.h b/libstdc++-v3/include/bits/random.h index d39cc3e0666..bb761ec8fb0 100644 --- a/libstdc++-v3/include/bits/random.h +++ b/libstdc++-v3/include/bits/random.h @@ -1603,7 +1603,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION double entropy() const noexcept - { return 0.0; } + { +#ifdef _GLIBCXX_USE_RANDOM_TR1 + return this->_M_getentropy(); +#else + return 0.0; +#endif + } result_type operator()() @@ -1627,6 +1633,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION result_type _M_getval(); result_type _M_getval_pretr1(); + double _M_getentropy() const noexcept; union { diff --git a/libstdc++-v3/src/c++11/random.cc b/libstdc++-v3/src/c++11/random.cc index df798742fce..5011cf2bb6b 100644 --- a/libstdc++-v3/src/c++11/random.cc +++ b/libstdc++-v3/src/c++11/random.cc @@ -38,6 +38,14 @@ # include #endif +#ifdef _GLIBCXX_HAVE_SYS_IOCTL_H +# include +#endif + +#ifdef _GLIBCXX_HAVE_LINUX_RANDOM_H +# include +#endif + namespace std _GLIBCXX_VISIBILITY(default) { namespace @@ -161,6 +169,33 @@ namespace std _GLIBCXX_VISIBILITY(default) return _M_mt(); } + double + random_device::_M_getentropy() const noexcept + { +#if defined _GLIBCXX_HAVE_SYS_IOCTL_H && defined RNDGETENTCNT + if (!_M_file) + return 0.0; + + const int fd = fileno(static_cast(_M_file)); + if (fd < 0) + return 0.0; + + int ent; + if (ioctl(fd, RNDGETENTCNT, &ent) < 0) + return 0.0; + + if (ent < 0) + return 0.0; + + if (static_cast(ent) > sizeof(result_type) * 8) + return static_cast(sizeof(result_type) * 8); + + return static_cast(ent); +#else + return 0.0; +#endif + } + template class mersenne_twister_engine< uint_fast32_t, 32, 624, 397, 31, diff --git a/libstdc++-v3/testsuite/util/testsuite_abi.cc b/libstdc++-v3/testsuite/util/testsuite_abi.cc index f5fc594d194..ee7572ea244 100644 --- a/libstdc++-v3/testsuite/util/testsuite_abi.cc +++ b/libstdc++-v3/testsuite/util/testsuite_abi.cc @@ -204,6 +204,7 @@ check_version(symbol& test, bool added) known_versions.push_back("GLIBCXX_LDBL_3.4.21"); known_versions.push_back("GLIBCXX_3.4.22"); known_versions.push_back("GLIBCXX_3.4.23"); + known_versions.push_back("GLIBCXX_3.4.24"); known_versions.push_back("CXXABI_1.3"); known_versions.push_back("CXXABI_LDBL_1.3"); known_versions.push_back("CXXABI_1.3.1"); @@ -234,7 +235,7 @@ check_version(symbol& test, bool added) test.version_status = symbol::incompatible; // Check that added symbols are added in the latest pre-release version. - bool latestp = (test.version_name == "GLIBCXX_3.4.23" + bool latestp = (test.version_name == "GLIBCXX_3.4.24" || test.version_name == "CXXABI_1.3.11" || test.version_name == "CXXABI_FLOAT128" || test.version_name == "CXXABI_TM_1");