Skip to content

Commit dd8cf82

Browse files
committed
Merge #15146: Solve SmartOS FD_ZERO build issue
b4fd0ca Include cstring for sanity_test_fdelt if required (Ben Woosley) 7fb886b [moveonly] Split glibc sanity_test_fdelt out (Ben Woosley) Pull request description: 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. Instead split glibc_sanity into fdelt and memcpy files, and include <cstring> in glibc_sanity/fdelt.cpp. Fixes #13581, see also #13619 ACKs for top commit: laanwj: Code review an lightly tested (but not on SmartOS) ACK b4fd0ca Tree-SHA512: 231306da291ad9eca8ba91bea1e9c27b6c2e96e484d1602e1c2cf27761202f9287ce0bc19fefd000943d2b449d0e5929cd39e2f7e09cf930d89fa520228ccbec
2 parents 72d30d6 + b4fd0ca commit dd8cf82

File tree

4 files changed

+62
-17
lines changed

4 files changed

+62
-17
lines changed

configure.ac

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -777,6 +777,39 @@ fi
777777

778778
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])
779779

780+
# FD_ZERO may be dependent on a declaration of memcpy, e.g. in SmartOS
781+
# check that it fails to build without memcpy, then that it builds with
782+
AC_MSG_CHECKING(FD_ZERO memcpy dependence)
783+
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
784+
#include <cstddef>
785+
#if HAVE_SYS_SELECT_H
786+
#include <sys/select.h>
787+
#endif
788+
]],[[
789+
#if HAVE_SYS_SELECT_H
790+
fd_set fds;
791+
FD_ZERO(&fds);
792+
#endif
793+
]])],
794+
[ AC_MSG_RESULT(no) ],
795+
[
796+
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
797+
#include <cstring>
798+
#if HAVE_SYS_SELECT_H
799+
#include <sys/select.h>
800+
#endif
801+
]], [[
802+
#if HAVE_SYS_SELECT_H
803+
fd_set fds;
804+
FD_ZERO(&fds);
805+
#endif
806+
]])],
807+
[ 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]) ],
808+
[ AC_MSG_ERROR(failed with cstring include) ]
809+
)
810+
]
811+
)
812+
780813
AC_CHECK_DECLS([getifaddrs, freeifaddrs],,,
781814
[#include <sys/types.h>
782815
#include <ifaddrs.h>]

src/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,7 @@ libbitcoin_util_a_SOURCES = \
484484
support/lockedpool.cpp \
485485
chainparamsbase.cpp \
486486
clientversion.cpp \
487+
compat/glibc_sanity_fdelt.cpp \
487488
compat/glibc_sanity.cpp \
488489
compat/glibcxx_sanity.cpp \
489490
compat/strnlen.cpp \

src/compat/glibc_sanity.cpp

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2009-2018 The Bitcoin Core developers
1+
// Copyright (c) 2009-2019 The Bitcoin Core developers
22
// Distributed under the MIT software license, see the accompanying
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

@@ -9,7 +9,7 @@
99
#include <cstddef>
1010

1111
#if defined(HAVE_SYS_SELECT_H)
12-
#include <sys/select.h>
12+
bool sanity_test_fdelt();
1313
#endif
1414

1515
extern "C" void* memcpy(void* a, const void* b, size_t c);
@@ -41,21 +41,6 @@ bool sanity_test_memcpy()
4141
}
4242
return true;
4343
}
44-
45-
#if defined(HAVE_SYS_SELECT_H)
46-
// trigger: Call FD_SET to trigger __fdelt_chk. FORTIFY_SOURCE must be defined
47-
// as >0 and optimizations must be set to at least -O2.
48-
// test: Add a file descriptor to an empty fd_set. Verify that it has been
49-
// correctly added.
50-
bool sanity_test_fdelt()
51-
{
52-
fd_set fds;
53-
FD_ZERO(&fds);
54-
FD_SET(0, &fds);
55-
return FD_ISSET(0, &fds);
56-
}
57-
#endif
58-
5944
} // namespace
6045

6146
bool glibc_sanity_test()

src/compat/glibc_sanity_fdelt.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright (c) 2009-2019 The Bitcoin Core developers
2+
// Distributed under the MIT software license, see the accompanying
3+
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4+
5+
#if defined(HAVE_CONFIG_H)
6+
#include <config/bitcoin-config.h>
7+
#endif
8+
9+
#if defined(HAVE_SYS_SELECT_H)
10+
#ifdef HAVE_CSTRING_DEPENDENT_FD_ZERO
11+
#include <cstring>
12+
#endif
13+
#include <sys/select.h>
14+
15+
// trigger: Call FD_SET to trigger __fdelt_chk. FORTIFY_SOURCE must be defined
16+
// as >0 and optimizations must be set to at least -O2.
17+
// test: Add a file descriptor to an empty fd_set. Verify that it has been
18+
// correctly added.
19+
bool sanity_test_fdelt()
20+
{
21+
fd_set fds;
22+
FD_ZERO(&fds);
23+
FD_SET(0, &fds);
24+
return FD_ISSET(0, &fds);
25+
}
26+
#endif

0 commit comments

Comments
 (0)