From 975cb511eeb6d8f1fd8b4636fdc58574f042b069 Mon Sep 17 00:00:00 2001 From: Cory Fields Date: Wed, 9 Apr 2014 22:40:33 -0400 Subject: [PATCH] build: add glibc/libstdc++ back-compat stubs glibc/libstdc++ have added new symbols in later releases. When running a new binary against an older glibc, the run-time linker is unable to resolve the new symbols and the binary refuses to run. This can be fixed by adding our own versions of those functions, so that the build-time linker does not emit undefined symbols for them. This enables our binary releases to work on older Linux distros, while not incurring the downsides of a fully static binary. --- src/compat/glibc_compat.cpp | 19 +++++++++ src/compat/glibcxx_compat.cpp | 80 +++++++++++++++++++++++++++++++++++ 2 files changed, 99 insertions(+) create mode 100644 src/compat/glibc_compat.cpp create mode 100644 src/compat/glibcxx_compat.cpp diff --git a/src/compat/glibc_compat.cpp b/src/compat/glibc_compat.cpp new file mode 100644 index 000000000..5b73e6051 --- /dev/null +++ b/src/compat/glibc_compat.cpp @@ -0,0 +1,19 @@ +#include "bitcoin-config.h" +#include +#include + +// Prior to GLIBC_2.14, memcpy was aliased to memmove. +extern "C" void* memmove(void* a, const void* b, size_t c); +extern "C" void* memcpy(void* a, const void* b, size_t c) +{ + return memmove(a, b, c); +} + +extern "C" void __chk_fail (void) __attribute__((__noreturn__)); +extern "C" FDELT_TYPE __fdelt_warn(FDELT_TYPE a) +{ + if (a >= FD_SETSIZE) + __chk_fail (); + return a / __NFDBITS; +} +extern "C" FDELT_TYPE __fdelt_chk(FDELT_TYPE) __attribute__((weak, alias("__fdelt_warn"))); diff --git a/src/compat/glibcxx_compat.cpp b/src/compat/glibcxx_compat.cpp new file mode 100644 index 000000000..6e04f6745 --- /dev/null +++ b/src/compat/glibcxx_compat.cpp @@ -0,0 +1,80 @@ +#include +#include +#include +#include + +#ifndef _GLIBCXX_USE_NOEXCEPT + #define _GLIBCXX_USE_NOEXCEPT throw() +#endif + +namespace std { + +const char* bad_exception::what() const throw() +{ + return "std::bad_exception"; +} + +const char* bad_cast::what() const throw() +{ + return "std::bad_cast"; +} + +const char* bad_alloc::what() const throw() +{ + return "std::bad_alloc"; +} + +namespace __detail +{ +struct _List_node_base +{ + void _M_hook(std::__detail::_List_node_base* const __position) throw () __attribute__((used)) + { + _M_next = __position; + _M_prev = __position->_M_prev; + __position->_M_prev->_M_next = this; + __position->_M_prev = this; + } + void _M_unhook() __attribute__((used)) + { + _List_node_base* const __next_node = _M_next; + _List_node_base* const __prev_node = _M_prev; + __prev_node->_M_next = __next_node; + __next_node->_M_prev = __prev_node; + } + _List_node_base* _M_next; + _List_node_base* _M_prev; +}; +} // namespace detail + +template ostream& ostream::_M_insert(bool); +template ostream& ostream::_M_insert(long); +template ostream& ostream::_M_insert(double); +template ostream& ostream::_M_insert(unsigned long); +template ostream& ostream::_M_insert(const void*); +template ostream& __ostream_insert(ostream&, const char*, streamsize); +template istream& istream::_M_extract(long&); +template istream& istream::_M_extract(unsigned short&); + +out_of_range::~out_of_range() _GLIBCXX_USE_NOEXCEPT { } + +// Used with permission. +// See: https://github.com/madlib/madlib/commit/c3db418c0d34d6813608f2137fef1012ce03043d + +void +ctype::_M_widen_init() const { + char __tmp[sizeof(_M_widen)]; + for (unsigned __i = 0; __i < sizeof(_M_widen); ++__i) + __tmp[__i] = __i; + do_widen(__tmp, __tmp + sizeof(__tmp), _M_widen); + + _M_widen_ok = 1; + // Set _M_widen_ok to 2 if memcpy can't be used. + for (unsigned __i = 0; __i < sizeof(_M_widen); ++__i) + if (__tmp[__i] != _M_widen[__i]) { + _M_widen_ok = 2; + break; + } +} + +}// namespace std