From 7fb886b1b1110de4c79478ac094e64cdcb81f3c8 Mon Sep 17 00:00:00 2001 From: Ben Woosley Date: Sat, 9 Mar 2019 12:32:48 -0500 Subject: [PATCH 1/2] [moveonly] Split glibc sanity_test_fdelt out --- src/Makefile.am | 1 + src/compat/glibc_sanity.cpp | 19 ++----------------- src/compat/glibc_sanity_fdelt.cpp | 23 +++++++++++++++++++++++ 3 files changed, 26 insertions(+), 17 deletions(-) create mode 100644 src/compat/glibc_sanity_fdelt.cpp diff --git a/src/Makefile.am b/src/Makefile.am index 6bc3655cad..dc0863f71b 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -472,6 +472,7 @@ libbitcoin_util_a_SOURCES = \ support/lockedpool.cpp \ chainparamsbase.cpp \ clientversion.cpp \ + compat/glibc_sanity_fdelt.cpp \ compat/glibc_sanity.cpp \ compat/glibcxx_sanity.cpp \ compat/strnlen.cpp \ diff --git a/src/compat/glibc_sanity.cpp b/src/compat/glibc_sanity.cpp index 1ef66e27b4..cc74f28899 100644 --- a/src/compat/glibc_sanity.cpp +++ b/src/compat/glibc_sanity.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2009-2018 The Bitcoin Core developers +// Copyright (c) 2009-2019 The Bitcoin Core developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. @@ -9,7 +9,7 @@ #include #if defined(HAVE_SYS_SELECT_H) -#include +bool sanity_test_fdelt(); #endif extern "C" void* memcpy(void* a, const void* b, size_t c); @@ -41,21 +41,6 @@ bool sanity_test_memcpy() } return true; } - -#if defined(HAVE_SYS_SELECT_H) -// trigger: Call FD_SET to trigger __fdelt_chk. FORTIFY_SOURCE must be defined -// as >0 and optimizations must be set to at least -O2. -// test: Add a file descriptor to an empty fd_set. Verify that it has been -// correctly added. -bool sanity_test_fdelt() -{ - fd_set fds; - FD_ZERO(&fds); - FD_SET(0, &fds); - return FD_ISSET(0, &fds); -} -#endif - } // namespace bool glibc_sanity_test() diff --git a/src/compat/glibc_sanity_fdelt.cpp b/src/compat/glibc_sanity_fdelt.cpp new file mode 100644 index 0000000000..13661d3eef --- /dev/null +++ b/src/compat/glibc_sanity_fdelt.cpp @@ -0,0 +1,23 @@ +// Copyright (c) 2009-2019 The Bitcoin Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#if defined(HAVE_CONFIG_H) +#include +#endif + +#if defined(HAVE_SYS_SELECT_H) +#include + +// trigger: Call FD_SET to trigger __fdelt_chk. FORTIFY_SOURCE must be defined +// as >0 and optimizations must be set to at least -O2. +// test: Add a file descriptor to an empty fd_set. Verify that it has been +// correctly added. +bool sanity_test_fdelt() +{ + fd_set fds; + FD_ZERO(&fds); + FD_SET(0, &fds); + return FD_ISSET(0, &fds); +} +#endif From b4fd0ca9be14c81023db759c405c0f67cfa78166 Mon Sep 17 00:00:00 2001 From: Ben Woosley Date: Sat, 9 Mar 2019 12:37:09 -0500 Subject: [PATCH 2/2] Include cstring for sanity_test_fdelt if required SmartOS FD_ZERO is implemented in a way that requires an external declaration of memcpy. We can not simply include cstring in the existing file because sanity_test_memcpy is attempting to replace memcpy, but we can do so here, now that the fdelt test is split out. --- configure.ac | 33 +++++++++++++++++++++++++++++++ src/compat/glibc_sanity_fdelt.cpp | 3 +++ 2 files changed, 36 insertions(+) diff --git a/configure.ac b/configure.ac index a3ba8ce808..579aeed49d 100644 --- a/configure.ac +++ b/configure.ac @@ -758,6 +758,39 @@ fi AC_CHECK_HEADERS([endian.h sys/endian.h byteswap.h stdio.h stdlib.h unistd.h strings.h sys/types.h sys/stat.h sys/select.h sys/prctl.h]) +# FD_ZERO may be dependent on a declaration of memcpy, e.g. in SmartOS +# check that it fails to build without memcpy, then that it builds with +AC_MSG_CHECKING(FD_ZERO memcpy dependence) +AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ + #include + #if HAVE_SYS_SELECT_H + #include + #endif + ]],[[ + #if HAVE_SYS_SELECT_H + fd_set fds; + FD_ZERO(&fds); + #endif + ]])], + [ AC_MSG_RESULT(no) ], + [ + AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ + #include + #if HAVE_SYS_SELECT_H + #include + #endif + ]], [[ + #if HAVE_SYS_SELECT_H + fd_set fds; + FD_ZERO(&fds); + #endif + ]])], + [ AC_MSG_RESULT(yes); AC_DEFINE(HAVE_CSTRING_DEPENDENT_FD_ZERO, 1, [Define this symbol if FD_ZERO is dependent of a memcpy declaration being available]) ], + [ AC_MSG_ERROR(failed with cstring include) ] + ) + ] +) + AC_CHECK_DECLS([getifaddrs, freeifaddrs],,, [#include #include ] diff --git a/src/compat/glibc_sanity_fdelt.cpp b/src/compat/glibc_sanity_fdelt.cpp index 13661d3eef..87140d0c71 100644 --- a/src/compat/glibc_sanity_fdelt.cpp +++ b/src/compat/glibc_sanity_fdelt.cpp @@ -7,6 +7,9 @@ #endif #if defined(HAVE_SYS_SELECT_H) +#ifdef HAVE_CSTRING_DEPENDENT_FD_ZERO +#include +#endif #include // trigger: Call FD_SET to trigger __fdelt_chk. FORTIFY_SOURCE must be defined