From 3ee028f131db0ea78bfde0961a3fca7b9e95b193 Mon Sep 17 00:00:00 2001 From: Cory Fields Date: Mon, 23 Feb 2015 17:48:57 -0500 Subject: [PATCH 1/6] build: disable reduced exports by default This is really a packager's option. While it's helpful to encourage devs to test this option for daily builds, it's not reliable in several real-world use-cases. Some older libstdc++ runtimes (freebsd 9, debian wheezy, for example) fail to properly catch exceptions due to mismatched type_info. See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=19664 for more info. --- configure.ac | 37 +++++++++---------------------------- 1 file changed, 9 insertions(+), 28 deletions(-) diff --git a/configure.ac b/configure.ac index 85e3d1d66..9dd3f17d8 100644 --- a/configure.ac +++ b/configure.ac @@ -115,9 +115,9 @@ AC_ARG_ENABLE([hardening], AC_ARG_ENABLE([reduce-exports], [AS_HELP_STRING([--enable-reduce-exports], - [attempt to reduce exported symbols in the resulting executables (default is yes)])], + [attempt to reduce exported symbols in the resulting executables (default is no)])], [use_reduce_exports=$enableval], - [use_reduce_exports=auto]) + [use_reduce_exports=no]) AC_ARG_ENABLE([ccache], [AS_HELP_STRING([--enable-ccache], @@ -473,20 +473,12 @@ AC_LINK_IFELSE([AC_LANG_SOURCE([ if test x$use_reduce_exports = xyes; then AC_MSG_ERROR([Cannot find a working visibility attribute. Use --disable-reduced-exports.]) fi - AC_MSG_WARN([Cannot find a working visibility attribute. Disabling reduced exports.]) - use_reduce_exports=no ] ) -if test x$use_reduce_exports != xno; then +if test x$use_reduce_exports = xyes; then AX_CHECK_COMPILE_FLAG([-fvisibility=hidden],[RE_CXXFLAGS="-fvisibility=hidden"], - [ - if test x$use_reduce_exports = xyes; then - AC_MSG_ERROR([Cannot set default symbol visibility. Use --disable-reduced-exports.]) - fi - AC_MSG_WARN([Cannot set default symbol visibility. Disabling reduced exports.]) - use_reduce_exports=no - ]) + [AC_MSG_ERROR([Cannot set default symbol visibility. Use --disable-reduced-exports.])]) fi LEVELDB_CPPFLAGS= @@ -533,7 +525,7 @@ AX_BOOST_THREAD AX_BOOST_CHRONO -if test x$use_reduce_exports != xno; then +if test x$use_reduce_exports = xyes; then AC_MSG_CHECKING([for working boost reduced exports]) TEMP_CPPFLAGS="$CPPFLAGS" CPPFLAGS="$BOOST_CPPFLAGS $CPPFLAGS" @@ -547,25 +539,14 @@ if test x$use_reduce_exports != xno; then #endif ]])],[ AC_MSG_RESULT(yes) - ],[: - if test x$use_reduce_exports = xauto; then - use_reduce_exports=no - else - if test x$use_reduce_exports = xyes; then - AC_MSG_ERROR([boost versions < 1.49 are known to be broken with reduced exports. Use --disable-reduced-exports.]) - fi - fi - AC_MSG_RESULT(no) - AC_MSG_WARN([boost versions < 1.49 are known to have symbol visibility issues. Disabling reduced exports.]) + ],[ + AC_MSG_ERROR([boost versions < 1.49 are known to be broken with reduced exports. Use --disable-reduced-exports.]) ]) CPPFLAGS="$TEMP_CPPFLAGS" fi - -elif test x$use_reduce_exports = xauto; then - use_reduce_exports=yes fi -if test x$use_reduce_exports != xno; then +if test x$use_reduce_exports = xyes; then CXXFLAGS="$CXXFLAGS $RE_CXXFLAGS" AX_CHECK_LINK_FLAG([[-Wl,--exclude-libs,ALL]], [RELDFLAGS="-Wl,--exclude-libs,ALL"]) fi @@ -827,7 +808,7 @@ else fi AC_MSG_CHECKING([whether to reduce exports]) -if test x$use_reduce_exports != xno; then +if test x$use_reduce_exports = xyes; then AC_MSG_RESULT([yes]) else AC_MSG_RESULT([no]) From aa3673064c5cc2009d4a75d0ab8a553e99861ccb Mon Sep 17 00:00:00 2001 From: Cory Fields Date: Mon, 23 Feb 2015 17:56:15 -0500 Subject: [PATCH 2/6] build: remove libstdc++ backwards-compat Backwards-compatibility for libstdc++ is not limited to straightforward abi changes. Symbol visibility also needs to be taken into consideration, and that really can't be addressed simply. Instead, just static-link libstdc++ for backwards-compat. --- configure.ac | 2 +- src/Makefile.am | 2 - src/compat/glibcxx_compat.cpp | 94 ----------------------------------- 3 files changed, 1 insertion(+), 97 deletions(-) delete mode 100644 src/compat/glibcxx_compat.cpp diff --git a/configure.ac b/configure.ac index 9dd3f17d8..006c5f38a 100644 --- a/configure.ac +++ b/configure.ac @@ -133,7 +133,7 @@ AC_ARG_ENABLE([lcov], AC_ARG_ENABLE([glibc-back-compat], [AS_HELP_STRING([--enable-glibc-back-compat], - [enable backwards compatibility with glibc and libstdc++])], + [enable backwards compatibility with glibc])], [use_glibc_compat=$enableval], [use_glibc_compat=no]) diff --git a/src/Makefile.am b/src/Makefile.am index 7644f6b32..37dfd5dba 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -280,7 +280,6 @@ libbitcoin_util_a_SOURCES = \ if GLIBC_BACK_COMPAT libbitcoin_util_a_SOURCES += compat/glibc_compat.cpp -libbitcoin_util_a_SOURCES += compat/glibcxx_compat.cpp endif # cli: shared between bitcoin-cli and bitcoin-qt @@ -372,7 +371,6 @@ libbitcoinconsensus_la_SOURCES = \ if GLIBC_BACK_COMPAT libbitcoinconsensus_la_SOURCES += compat/glibc_compat.cpp - libbitcoinconsensus_la_SOURCES += compat/glibcxx_compat.cpp endif libbitcoinconsensus_la_LDFLAGS = -no-undefined $(RELDFLAGS) diff --git a/src/compat/glibcxx_compat.cpp b/src/compat/glibcxx_compat.cpp deleted file mode 100644 index 4f2771e57..000000000 --- a/src/compat/glibcxx_compat.cpp +++ /dev/null @@ -1,94 +0,0 @@ -// Copyright (c) 2009-2014 The Bitcoin Core developers -// Distributed under the MIT software license, see the accompanying -// file COPYING or http://www.opensource.org/licenses/mit-license.php. - -#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 {} - -length_error::~length_error() _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; - } -} - -void __throw_out_of_range_fmt(const char*, ...) __attribute__((__noreturn__)); -void __throw_out_of_range_fmt(const char* err, ...) -{ - // Safe and over-simplified version. Ignore the format and print it as-is. - __throw_out_of_range(err); -} - -} // namespace std From 06715165f9215a954c0b5d0b15037aecff8b1d74 Mon Sep 17 00:00:00 2001 From: Cory Fields Date: Mon, 23 Feb 2015 18:18:08 -0500 Subject: [PATCH 3/6] build: change reduce exports/static libstdc++ options for gitian and travis For Gitian releases: - Windows builds remain unchanged. libstdc++ was already linked statically. - OSX builds remain unchanged. libstdc++ is tied to the SDK and not worth messing with. - Linux builds now statically link libstdc++. For Travis: - Match the previous behavior by adding --enable-reduce-exports as necessary. - Use static libstdc++ for the full Linux build. --- .travis.yml | 14 +++++++------- contrib/gitian-descriptors/gitian-linux.yml | 2 +- contrib/gitian-descriptors/gitian-osx.yml | 2 +- contrib/gitian-descriptors/gitian-win.yml | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/.travis.yml b/.travis.yml index 3c995be9a..e08e78dab 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,19 +25,19 @@ matrix: fast_finish: true include: - compiler: ": ARM" - env: HOST=arm-linux-gnueabihf PACKAGES="g++-arm-linux-gnueabihf" DEP_OPTS="NO_QT=1" GOAL="install" BITCOIN_CONFIG="--enable-glibc-back-compat" + env: HOST=arm-linux-gnueabihf PACKAGES="g++-arm-linux-gnueabihf" DEP_OPTS="NO_QT=1" GOAL="install" BITCOIN_CONFIG="--enable-glibc-back-compat --enable-reduce-exports" - compiler: ": bitcoind" - env: HOST=x86_64-unknown-linux-gnu PACKAGES="bc" DEP_OPTS="NO_QT=1 NO_UPNP=1 DEBUG=1" RUN_TESTS=true GOAL="install" BITCOIN_CONFIG="--enable-glibc-back-compat CPPFLAGS=-DDEBUG_LOCKORDER" + env: HOST=x86_64-unknown-linux-gnu PACKAGES="bc" DEP_OPTS="NO_QT=1 NO_UPNP=1 DEBUG=1" RUN_TESTS=true GOAL="install" BITCOIN_CONFIG="--enable-glibc-back-compat --enable-reduce-exports CPPFLAGS=-DDEBUG_LOCKORDER" - compiler: ": No wallet" - env: HOST=x86_64-unknown-linux-gnu DEP_OPTS="NO_WALLET=1" RUN_TESTS=true GOAL="install" BITCOIN_CONFIG="--enable-glibc-back-compat" + env: HOST=x86_64-unknown-linux-gnu DEP_OPTS="NO_WALLET=1" RUN_TESTS=true GOAL="install" BITCOIN_CONFIG="--enable-glibc-back-compat --enable-reduce-exports" - compiler: ": 32-bit + dash" - env: HOST=i686-pc-linux-gnu PACKAGES="g++-multilib bc" RUN_TESTS=true GOAL="install" BITCOIN_CONFIG="--enable-glibc-back-compat" USE_SHELL="/bin/dash" + env: HOST=i686-pc-linux-gnu PACKAGES="g++-multilib bc" RUN_TESTS=true GOAL="install" BITCOIN_CONFIG="--enable-glibc-back-compat --enable-reduce-exports LDFLAGS=-static-libstdc++" USE_SHELL="/bin/dash" - compiler: ": Cross-Mac" - env: HOST=x86_64-apple-darwin11 PACKAGES="cmake libcap-dev libz-dev libbz2-dev" OSX_SDK=10.9 GOAL="deploy" + env: HOST=x86_64-apple-darwin11 PACKAGES="cmake libcap-dev libz-dev libbz2-dev" BITCOIN_CONFIG="--enable-reduce-exports" OSX_SDK=10.9 GOAL="deploy" - compiler: ": Win64" - env: HOST=x86_64-w64-mingw32 PACKAGES="nsis gcc-mingw-w64-x86-64 g++-mingw-w64-x86-64 binutils-mingw-w64-x86-64 mingw-w64-dev wine bc" RUN_TESTS=true GOAL="deploy" BITCOIN_CONFIG="--enable-gui" MAKEJOBS="-j2" + env: HOST=x86_64-w64-mingw32 PACKAGES="nsis gcc-mingw-w64-x86-64 g++-mingw-w64-x86-64 binutils-mingw-w64-x86-64 mingw-w64-dev wine bc" RUN_TESTS=true GOAL="deploy" BITCOIN_CONFIG="--enable-gui --enable-reduce-exports" MAKEJOBS="-j2" - compiler: ": Win32" - env: HOST=i686-w64-mingw32 PACKAGES="nsis gcc-mingw-w64-i686 g++-mingw-w64-i686 binutils-mingw-w64-i686 mingw-w64-dev wine bc" RUN_TESTS=true GOAL="deploy" BITCOIN_CONFIG="--enable-gui" MAKEJOBS="-j2" + env: HOST=i686-w64-mingw32 PACKAGES="nsis gcc-mingw-w64-i686 g++-mingw-w64-i686 binutils-mingw-w64-i686 mingw-w64-dev wine bc" RUN_TESTS=true GOAL="deploy" BITCOIN_CONFIG="--enable-gui --enable-reduce-exports" MAKEJOBS="-j2" install: - if [ -n "$PACKAGES" ]; then travis_retry sudo apt-get update; fi - if [ -n "$PACKAGES" ]; then travis_retry sudo apt-get install --no-install-recommends --no-upgrade -qq $PACKAGES; fi diff --git a/contrib/gitian-descriptors/gitian-linux.yml b/contrib/gitian-descriptors/gitian-linux.yml index 80de6770c..10463c871 100644 --- a/contrib/gitian-descriptors/gitian-linux.yml +++ b/contrib/gitian-descriptors/gitian-linux.yml @@ -23,7 +23,7 @@ files: [] script: | WRAP_DIR=$HOME/wrapped HOSTS="i686-pc-linux-gnu x86_64-unknown-linux-gnu" - CONFIGFLAGS="--enable-upnp-default --enable-glibc-back-compat" + CONFIGFLAGS="--enable-upnp-default --enable-glibc-back-compat --enable-reduce-exports LDFLAGS=-static-libstdc++" FAKETIME_HOST_PROGS="" FAKETIME_PROGS="date ar ranlib nm strip" diff --git a/contrib/gitian-descriptors/gitian-osx.yml b/contrib/gitian-descriptors/gitian-osx.yml index 43eb79d84..b401482c7 100644 --- a/contrib/gitian-descriptors/gitian-osx.yml +++ b/contrib/gitian-descriptors/gitian-osx.yml @@ -27,7 +27,7 @@ files: script: | WRAP_DIR=$HOME/wrapped HOSTS="x86_64-apple-darwin11" - CONFIGFLAGS="--enable-upnp-default GENISOIMAGE=$WRAP_DIR/genisoimage" + CONFIGFLAGS="--enable-upnp-default --enable-reduce-exports GENISOIMAGE=$WRAP_DIR/genisoimage" FAKETIME_HOST_PROGS="" FAKETIME_PROGS="ar ranlib date dmg genisoimage" diff --git a/contrib/gitian-descriptors/gitian-win.yml b/contrib/gitian-descriptors/gitian-win.yml index f0459ee94..2d72f7b6e 100644 --- a/contrib/gitian-descriptors/gitian-win.yml +++ b/contrib/gitian-descriptors/gitian-win.yml @@ -26,7 +26,7 @@ files: [] script: | WRAP_DIR=$HOME/wrapped HOSTS="x86_64-w64-mingw32 i686-w64-mingw32" - CONFIGFLAGS="--enable-upnp-default" + CONFIGFLAGS="--enable-upnp-default --enable-reduce-exports" FAKETIME_HOST_PROGS="g++ ar ranlib nm windres strip" FAKETIME_PROGS="date makensis zip" From c95ac83e5115a2e9f1c29df6a3839d6788b4eafd Mon Sep 17 00:00:00 2001 From: Cory Fields Date: Mon, 23 Feb 2015 19:43:25 -0500 Subject: [PATCH 4/6] gitian: fix x86_64 build with static libstdc++ --- contrib/gitian-descriptors/gitian-linux.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/contrib/gitian-descriptors/gitian-linux.yml b/contrib/gitian-descriptors/gitian-linux.yml index 10463c871..dde4af349 100644 --- a/contrib/gitian-descriptors/gitian-linux.yml +++ b/contrib/gitian-descriptors/gitian-linux.yml @@ -15,6 +15,7 @@ packages: - "faketime" - "bsdmainutils" - "binutils-gold" +- "libstdc++6-4.6-pic" reference_datetime: "2013-06-01 00:00:00" remotes: - "url": "https://github.com/bitcoin/bitcoin.git" @@ -69,6 +70,14 @@ script: | make ${MAKEOPTS} -C ${BASEPREFIX} HOST="${i}" done + # Ubuntu precise hack: Not an issue in later versions. + # Precise's libstdc++.a is non-pic. There's an optional libstdc++6-4.6-pic + # package which provides libstdc++_pic.a, but the linker can't find it. + # Symlink it to a path that will be included in our link-line so that the + # linker picks it up before the default libstdc++.a. + # This is only necessary for 64bit. + ln -s /usr/lib/gcc/x86_64-linux-gnu/4.6/libstdc++_pic.a ${BASEPREFIX}/x86_64-unknown-linux-gnu/lib/libstdc++.a + # Create the release tarball using (arbitrarily) the first host ./autogen.sh ./configure --prefix=${BASEPREFIX}/`echo "${HOSTS}" | awk '{print $1;}'` From 3448b132c4150509eec9bf585552d1994fd32090 Mon Sep 17 00:00:00 2001 From: Cory Fields Date: Mon, 23 Feb 2015 20:18:54 -0500 Subject: [PATCH 5/6] build: fix typo in configure help --- configure.ac | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/configure.ac b/configure.ac index 006c5f38a..67a0cc28e 100644 --- a/configure.ac +++ b/configure.ac @@ -471,14 +471,14 @@ AC_LINK_IFELSE([AC_LANG_SOURCE([ [ AC_MSG_RESULT(no) if test x$use_reduce_exports = xyes; then - AC_MSG_ERROR([Cannot find a working visibility attribute. Use --disable-reduced-exports.]) + AC_MSG_ERROR([Cannot find a working visibility attribute. Use --disable-reduce-exports.]) fi ] ) if test x$use_reduce_exports = xyes; then AX_CHECK_COMPILE_FLAG([-fvisibility=hidden],[RE_CXXFLAGS="-fvisibility=hidden"], - [AC_MSG_ERROR([Cannot set default symbol visibility. Use --disable-reduced-exports.])]) + [AC_MSG_ERROR([Cannot set default symbol visibility. Use --disable-reduce-exports.])]) fi LEVELDB_CPPFLAGS= @@ -540,7 +540,7 @@ if test x$use_reduce_exports = xyes; then ]])],[ AC_MSG_RESULT(yes) ],[ - AC_MSG_ERROR([boost versions < 1.49 are known to be broken with reduced exports. Use --disable-reduced-exports.]) + AC_MSG_ERROR([boost versions < 1.49 are known to be broken with reduced exports. Use --disable-reduce-exports.]) ]) CPPFLAGS="$TEMP_CPPFLAGS" fi From d23b0a271163d187eb362164d375148fdd752148 Mon Sep 17 00:00:00 2001 From: Cory Fields Date: Wed, 25 Feb 2015 14:01:02 -0500 Subject: [PATCH 6/6] depends: always use static qt5 for linux --- depends/Makefile | 1 - depends/README.usage | 1 - depends/packages/packages.mk | 7 +------ 3 files changed, 1 insertion(+), 8 deletions(-) diff --git a/depends/Makefile b/depends/Makefile index e2ef7ee49..05ef33f2e 100644 --- a/depends/Makefile +++ b/depends/Makefile @@ -6,7 +6,6 @@ SDK_PATH ?= $(BASEDIR)/SDKs NO_QT ?= NO_WALLET ?= NO_UPNP ?= -USE_LINUX_STATIC_QT5 ?= FALLBACK_DOWNLOAD_PATH ?= https://bitcoincore.org/depends-sources BUILD = $(shell ./config.guess) diff --git a/depends/README.usage b/depends/README.usage index f5aa5314a..24e1231d8 100644 --- a/depends/README.usage +++ b/depends/README.usage @@ -23,7 +23,6 @@ NO_QT: Don't download/build/cache qt and its dependencies NO_WALLET: Don't download/build/cache libs needed to enable the wallet NO_UPNP: Don't download/build/cache packages needed for enabling upnp DEBUG: disable some optimizations and enable more runtime checking -USE_LINUX_STATIC_QT5: Build a static qt5 rather than shared qt4. Linux only. If some packages are not built, for example 'make NO_WALLET=1', the appropriate options will be passed to bitcoin's configure. In this case, --disable-wallet. diff --git a/depends/packages/packages.mk b/depends/packages/packages.mk index 08fd8a524..03908aba5 100644 --- a/depends/packages/packages.mk +++ b/depends/packages/packages.mk @@ -4,15 +4,10 @@ native_packages := native_ccache native_comparisontool qt_native_packages = native_protobuf qt_packages = qrencode protobuf -qt46_linux_packages = qt46 expat dbus libxcb xcb_proto libXau xproto freetype libX11 xextproto libXext xtrans libICE libSM -qt5_linux_packages= qt expat dbus libxcb xcb_proto libXau xproto freetype fontconfig libX11 xextproto libXext xtrans - +qt_linux_packages= qt expat dbus libxcb xcb_proto libXau xproto freetype fontconfig libX11 xextproto libXext xtrans qt_darwin_packages=qt qt_mingw32_packages=qt -qt_linux_$(USE_LINUX_STATIC_QT5):=$(qt5_linux_packages) -qt_linux_:=$(qt46_linux_packages) -qt_linux_packages:=$(qt_linux_$(USE_LINUX_STATIC_QT5)) wallet_packages=bdb