Skip to content

Commit bbe53f6

Browse files
committed
Merge pull request #4042
05c20a5 build: add symbol for upcoming gcc 4.9's libstdc++ (Cory Fields) 49a3352 gitian-linux: --enable-glibc-back-compat (Warren Togami) d5aab70 build: add an option for enabling glibc back-compat (Cory Fields) ffc6b67 build: add glibc/libstdc++ back-compat stubs (Cory Fields)
2 parents 91c601c + 05c20a5 commit bbe53f6

File tree

5 files changed

+134
-14
lines changed

5 files changed

+134
-14
lines changed

configure.ac

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,12 @@ AC_ARG_ENABLE([lcov],
108108
[use_lcov=yes],
109109
[use_lcov=no])
110110

111+
AC_ARG_ENABLE([glibc-back-compat],
112+
[AS_HELP_STRING([--enable-glibc-back-compat],
113+
[enable backwards compatibility with glibc and libstdc++])],
114+
[use_glibc_compat=$enableval],
115+
[use_glibc_compat=no])
116+
111117
AC_ARG_WITH([protoc-bindir],[AS_HELP_STRING([--with-protoc-bindir=BIN_DIR],[specify protoc bin path])], [protoc_bin_path=$withval], [])
112118

113119

@@ -319,6 +325,21 @@ fi
319325

320326
AX_CHECK_LINK_FLAG([[-Wl,--large-address-aware]], [LDFLAGS="$LDFLAGS -Wl,--large-address-aware"])
321327

328+
if test x$use_glibc_compat != xno; then
329+
330+
#__fdelt_chk's params and return type have changed from long unsigned int to long int.
331+
# See which one is present here.
332+
AC_MSG_CHECKING(__fdelt_chk type)
333+
AC_TRY_COMPILE([#define __USE_FORTIFY_LEVEL 2
334+
#include <sys/select.h>
335+
extern "C" long unsigned int __fdelt_warn(long unsigned int);],[],
336+
[ fdelt_type="long unsigned int"],
337+
[ fdelt_type="long int"])
338+
AC_MSG_RESULT($fdelt_type)
339+
AC_DEFINE_UNQUOTED(FDELT_TYPE, $fdelt_type,[parameter and return value type for __fdelt_chk])
340+
341+
fi
342+
322343
if test x$use_hardening != xno; then
323344
AX_CHECK_COMPILE_FLAG([-Wstack-protector],[HARDENED_CXXFLAGS="$HARDENED_CXXFLAGS -Wstack-protector"])
324345
AX_CHECK_COMPILE_FLAG([-fstack-protector-all],[HARDENED_CXXFLAGS="$HARDENED_CXXFLAGS -fstack-protector-all"])
@@ -691,6 +712,7 @@ AM_CONDITIONAL([USE_QRCODE], [test x$use_qr = xyes])
691712
AM_CONDITIONAL([USE_LCOV],[test x$use_lcov == xyes])
692713
AM_CONDITIONAL([USE_COMPARISON_TOOL],[test x$use_comparison_tool != xno])
693714
AM_CONDITIONAL([USE_COMPARISON_TOOL_REORG_TESTS],[test x$use_comparison_tool_reorg_test != xno])
715+
AM_CONDITIONAL([GLIBC_BACK_COMPAT],[test x$use_glibc_compat = xyes])
694716

695717
AC_DEFINE(CLIENT_VERSION_MAJOR, _CLIENT_VERSION_MAJOR, [Major version])
696718
AC_DEFINE(CLIENT_VERSION_MINOR, _CLIENT_VERSION_MINOR, [Minor version])

contrib/gitian-descriptors/gitian-linux.yml

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ script: |
4141
cd ../build
4242
4343
function do_configure {
44-
./configure "$@" --enable-upnp-default --prefix=$STAGING --with-protoc-bindir=$STAGING/host/bin --with-boost=$STAGING --disable-maintainer-mode --disable-dependency-tracking PKG_CONFIG_PATH="$STAGING/lib/pkgconfig" CPPFLAGS="-I$STAGING/include ${OPTFLAGS}" LDFLAGS="-L$STAGING/lib ${OPTFLAGS}" CXXFLAGS="-frandom-seed=bitcoin ${OPTFLAGS}" BOOST_CHRONO_EXTRALIBS="-lrt"
44+
./configure "$@" --enable-upnp-default --prefix=$STAGING --with-protoc-bindir=$STAGING/host/bin --with-boost=$STAGING --disable-maintainer-mode --disable-dependency-tracking PKG_CONFIG_PATH="$STAGING/lib/pkgconfig" CPPFLAGS="-I$STAGING/include ${OPTFLAGS}" LDFLAGS="-L$STAGING/lib ${OPTFLAGS}" CXXFLAGS="-frandom-seed=bitcoin ${OPTFLAGS}" BOOST_CHRONO_EXTRALIBS="-lrt" --enable-glibc-back-compat
4545
}
4646
#
4747
cd bitcoin
@@ -60,19 +60,6 @@ script: |
6060
make $MAKEOPTS install-strip
6161
make $MAKEOPTS clean
6262
63-
# Build fully static versions of bitcoind and bitcoin-cli for older Linux distros
64-
STATIC_BINDIR="$HOME/bindir.static"
65-
mkdir -p $STATIC_BINDIR
66-
# For 32-bit, -pie cannot be used with -static, as invalid executables are generated
67-
# For 64-bit, -pie with -static causes a link error
68-
# Disable hardening in configure and manually pass 'static-safe' hardening flags
69-
OPTFLAGS='-O2 -static -Wstack-protector -fstack-protector-all -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -Wl,-z,relro -Wl,-z,now'
70-
do_configure --bindir=$STATIC_BINDIR --disable-tests --enable-upnp-default --without-gui --disable-hardening
71-
make $MAKEOPTS
72-
make $MAKEOPTS install-strip
73-
cp $STATIC_BINDIR/bitcoind $BINDIR/bitcoind.static
74-
cp $STATIC_BINDIR/bitcoin-cli $BINDIR/bitcoin-cli.static
75-
7663
# sort distribution tar file and normalize user/group/mtime information for deterministic output
7764
mkdir -p $OUTDIR/src
7865
rm -rf $TEMPDIR

src/Makefile.am

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,11 @@ libbitcoin_common_a_SOURCES = \
136136
version.cpp \
137137
$(BITCOIN_CORE_H)
138138

139+
if GLIBC_BACK_COMPAT
140+
libbitcoin_common_a_SOURCES += compat/glibc_compat.cpp
141+
libbitcoin_common_a_SOURCES += compat/glibcxx_compat.cpp
142+
endif
143+
139144
libbitcoin_cli_a_SOURCES = \
140145
rpcclient.cpp \
141146
$(BITCOIN_CORE_H)

src/compat/glibc_compat.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include "bitcoin-config.h"
2+
#include <cstddef>
3+
#include <sys/select.h>
4+
5+
// Prior to GLIBC_2.14, memcpy was aliased to memmove.
6+
extern "C" void* memmove(void* a, const void* b, size_t c);
7+
extern "C" void* memcpy(void* a, const void* b, size_t c)
8+
{
9+
return memmove(a, b, c);
10+
}
11+
12+
extern "C" void __chk_fail (void) __attribute__((__noreturn__));
13+
extern "C" FDELT_TYPE __fdelt_warn(FDELT_TYPE a)
14+
{
15+
if (a >= FD_SETSIZE)
16+
__chk_fail ();
17+
return a / __NFDBITS;
18+
}
19+
extern "C" FDELT_TYPE __fdelt_chk(FDELT_TYPE) __attribute__((weak, alias("__fdelt_warn")));

src/compat/glibcxx_compat.cpp

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
#include <cstddef>
2+
#include <istream>
3+
#include <stdexcept>
4+
#include <typeinfo>
5+
6+
#ifndef _GLIBCXX_USE_NOEXCEPT
7+
#define _GLIBCXX_USE_NOEXCEPT throw()
8+
#endif
9+
10+
namespace std {
11+
12+
const char* bad_exception::what() const throw()
13+
{
14+
return "std::bad_exception";
15+
}
16+
17+
const char* bad_cast::what() const throw()
18+
{
19+
return "std::bad_cast";
20+
}
21+
22+
const char* bad_alloc::what() const throw()
23+
{
24+
return "std::bad_alloc";
25+
}
26+
27+
namespace __detail
28+
{
29+
struct _List_node_base
30+
{
31+
void _M_hook(std::__detail::_List_node_base* const __position) throw () __attribute__((used))
32+
{
33+
_M_next = __position;
34+
_M_prev = __position->_M_prev;
35+
__position->_M_prev->_M_next = this;
36+
__position->_M_prev = this;
37+
}
38+
void _M_unhook() __attribute__((used))
39+
{
40+
_List_node_base* const __next_node = _M_next;
41+
_List_node_base* const __prev_node = _M_prev;
42+
__prev_node->_M_next = __next_node;
43+
__next_node->_M_prev = __prev_node;
44+
}
45+
_List_node_base* _M_next;
46+
_List_node_base* _M_prev;
47+
};
48+
} // namespace detail
49+
50+
template ostream& ostream::_M_insert(bool);
51+
template ostream& ostream::_M_insert(long);
52+
template ostream& ostream::_M_insert(double);
53+
template ostream& ostream::_M_insert(unsigned long);
54+
template ostream& ostream::_M_insert(const void*);
55+
template ostream& __ostream_insert(ostream&, const char*, streamsize);
56+
template istream& istream::_M_extract(long&);
57+
template istream& istream::_M_extract(unsigned short&);
58+
59+
out_of_range::~out_of_range() _GLIBCXX_USE_NOEXCEPT { }
60+
61+
// Used with permission.
62+
// See: https://github.com/madlib/madlib/commit/c3db418c0d34d6813608f2137fef1012ce03043d
63+
64+
void
65+
ctype<char>::_M_widen_init() const {
66+
char __tmp[sizeof(_M_widen)];
67+
for (unsigned __i = 0; __i < sizeof(_M_widen); ++__i)
68+
__tmp[__i] = __i;
69+
do_widen(__tmp, __tmp + sizeof(__tmp), _M_widen);
70+
71+
_M_widen_ok = 1;
72+
// Set _M_widen_ok to 2 if memcpy can't be used.
73+
for (unsigned __i = 0; __i < sizeof(_M_widen); ++__i)
74+
if (__tmp[__i] != _M_widen[__i]) {
75+
_M_widen_ok = 2;
76+
break;
77+
}
78+
}
79+
80+
void __throw_out_of_range_fmt(const char*, ...) __attribute__((__noreturn__));
81+
void __throw_out_of_range_fmt(const char* err, ...)
82+
{
83+
// Safe and over-simplified version. Ignore the format and print it as-is.
84+
__throw_out_of_range(err);
85+
}
86+
87+
}// namespace std

0 commit comments

Comments
 (0)