From 9718bb394b842feab4e622b7e28d9c45cecaacf0 Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Tue, 30 Nov 2021 14:13:18 +0300 Subject: [PATCH] build/ci: Fix --enable-glibc-back-compat and its usage (#4592) * build: Fix `--enable-glibc-back-compat` Compiling on Ubuntu 20.04 results in binaries that can't be run on older systems we still support (e.g. Ubuntu 16.04) and `contrib/devtools/symbol-check.py` complains about it. Available versions for `log` for example: $ objdump -T /lib/x86_64-linux-gnu/libm.so.6 | egrep -w 'log' 00000000000431b0 g DF .text 0000000000000039 GLIBC_2.29 log 0000000000012360 g DF .text 0000000000000066 (GLIBC_2.2.5) log (i.e. the default one is 2.29) This commit fixes the issue by picking the version we support instead of the default one. Before: $ objdump -T dashd | egrep -w 'log' 0000000000000000 DF *UND* 0000000000000000 GLIBC_2.29 log After: $ objdump -T dashd | egrep -w 'log' 0000000000000000 DF *UND* 0000000000000000 GLIBC_2.2.5 log * ci: Add `make check-symbols` to the `build` step * ci: Do not specify `--enable-glibc-back-compat` for non-release builds * ci: Set correct LDFLAGS for the release build * doc: Update docs to mention the need for `LDFLAGS=-static-libstdc++` when compiling for same host but different distro * ci: Add `--with-sanitizers=undefined` back to `linux64` build --- ci/build_src.sh | 1 + ci/matrix.sh | 12 ++++---- doc/build-generic.md | 2 +- src/Makefile.am | 2 ++ src/compat/glibc_compat.cpp | 57 +++++++++++++++++++++++++++++++------ 5 files changed, 59 insertions(+), 15 deletions(-) diff --git a/ci/build_src.sh b/ci/build_src.sh index 693363a24b..df1b661257 100755 --- a/ci/build_src.sh +++ b/ci/build_src.sh @@ -52,3 +52,4 @@ cd dashcore-$BUILD_TARGET ./configure --cache-file=../config.cache $BITCOIN_CONFIG_ALL $BITCOIN_CONFIG || ( cat config.log && false) make $MAKEJOBS $GOAL || ( echo "Build failure. Verbose build follows." && make $GOAL V=1 ; false ) +make $MAKEJOBS -C src check-symbols diff --git a/ci/matrix.sh b/ci/matrix.sh index 38e1c5c852..c40c88d51f 100755 --- a/ci/matrix.sh +++ b/ci/matrix.sh @@ -40,7 +40,7 @@ if [ "$BUILD_TARGET" = "arm-linux" ]; then export CHECK_DOC=1 # -Wno-psabi is to disable ABI warnings: "note: parameter passing for argument of type ... changed in GCC 7.1" # This could be removed once the ABI change warning does not show up by default - export BITCOIN_CONFIG="--enable-glibc-back-compat --enable-reduce-exports --enable-suppress-external-warnings --enable-werror CXXFLAGS=-Wno-psabi" + export BITCOIN_CONFIG="--enable-reduce-exports --enable-suppress-external-warnings --enable-werror CXXFLAGS=-Wno-psabi" export RUN_UNITTESTS=false export RUN_INTEGRATIONTESTS=false elif [ "$BUILD_TARGET" = "win64" ]; then @@ -50,30 +50,30 @@ elif [ "$BUILD_TARGET" = "win64" ]; then export DIRECT_WINE_EXEC_TESTS=true elif [ "$BUILD_TARGET" = "linux32" ]; then export HOST=i686-pc-linux-gnu - export BITCOIN_CONFIG="--enable-zmq --disable-bip70 --enable-glibc-back-compat --enable-reduce-exports --enable-crash-hooks LDFLAGS=-static-libstdc++" + export BITCOIN_CONFIG="--enable-zmq --disable-bip70 --enable-reduce-exports --enable-crash-hooks" export USE_SHELL="/bin/dash" export PYZMQ=true elif [ "$BUILD_TARGET" = "linux64" ]; then export HOST=x86_64-unknown-linux-gnu export DEP_OPTS="NO_UPNP=1 DEBUG=1" - export BITCOIN_CONFIG="--enable-zmq --enable-glibc-back-compat --enable-reduce-exports --enable-crash-hooks --with-sanitizers=undefined" + export BITCOIN_CONFIG="--enable-zmq --enable-reduce-exports --enable-crash-hooks --with-sanitizers=undefined" export CPPFLAGS="-DDEBUG_LOCKORDER -DENABLE_DASH_DEBUG -DARENA_DEBUG" export PYZMQ=true elif [ "$BUILD_TARGET" = "linux64_cxx17" ]; then export HOST=x86_64-unknown-linux-gnu export DEP_OPTS="NO_UPNP=1 DEBUG=1" - export BITCOIN_CONFIG="--enable-zmq --enable-glibc-back-compat --enable-reduce-exports --enable-crash-hooks --enable-c++17 --enable-suppress-external-warnings --enable-werror --with-sanitizers=undefined" + export BITCOIN_CONFIG="--enable-zmq --enable-reduce-exports --enable-crash-hooks --enable-c++17 --enable-suppress-external-warnings --enable-werror --with-sanitizers=undefined" export CPPFLAGS="-DDEBUG_LOCKORDER -DENABLE_DASH_DEBUG -DARENA_DEBUG" export PYZMQ=true export RUN_INTEGRATIONTESTS=false elif [ "$BUILD_TARGET" = "linux64_nowallet" ]; then export HOST=x86_64-unknown-linux-gnu export DEP_OPTS="NO_WALLET=1" - export BITCOIN_CONFIG="--enable-glibc-back-compat --enable-reduce-exports" + export BITCOIN_CONFIG="--enable-reduce-exports" elif [ "$BUILD_TARGET" = "linux64_release" ]; then export HOST=x86_64-unknown-linux-gnu export DEP_OPTS="NO_UPNP=1" - export BITCOIN_CONFIG="--enable-zmq --enable-glibc-back-compat --enable-reduce-exports" + export BITCOIN_CONFIG="--enable-zmq --enable-glibc-back-compat --enable-reduce-exports LDFLAGS=-static-libstdc++" export PYZMQ=true elif [ "$BUILD_TARGET" = "mac" ]; then export HOST=x86_64-apple-darwin19 diff --git a/doc/build-generic.md b/doc/build-generic.md index fa7b7775f2..0a53072755 100644 --- a/doc/build-generic.md +++ b/doc/build-generic.md @@ -55,7 +55,7 @@ Please replace `` with your local system's `host-platform-triplet`. The fo If you want to cross-compile for another platform, choose the appropriate `` and make sure to build the dependencies with the same host before. -If you want to build for the same host but different distro, add `--enable-glibc-back-compat` when calling `./configure`. +If you want to build for the same host but different distro, add `--enable-glibc-back-compat LDFLAGS=-static-libstdc++` when calling `./configure`. ccache diff --git a/src/Makefile.am b/src/Makefile.am index 029c1a93ce..410113a8a9 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -685,6 +685,8 @@ libdash_util_a_SOURCES = \ if GLIBC_BACK_COMPAT libdash_util_a_SOURCES += compat/glibc_compat.cpp AM_LDFLAGS += -Wl,--wrap=log2f -Wl,--wrap=__divmoddi4 +AM_LDFLAGS += -Wl,--wrap=exp -Wl,--wrap=exp2 -Wl,--wrap=fcntl +AM_LDFLAGS += -Wl,--wrap=log -Wl,--wrap=log2 -Wl,--wrap=pow endif # cli: shared between dash-cli and dash-qt diff --git a/src/compat/glibc_compat.cpp b/src/compat/glibc_compat.cpp index 5ccc14ea01..6a04d77e9d 100644 --- a/src/compat/glibc_compat.cpp +++ b/src/compat/glibc_compat.cpp @@ -6,6 +6,7 @@ #include #endif +#include #include #include @@ -58,19 +59,59 @@ extern "C" int64_t __wrap___divmoddi4(int64_t u, int64_t v, int64_t* rp) } #endif +extern "C" float exp_old(float x); +extern "C" float exp2_old(float x); +extern "C" float log_old(float x); +extern "C" float log2_old(float x); extern "C" float log2f_old(float x); +extern "C" float pow_old(float x, float y); +extern "C" int fcntl_old(int fd, int cmd, ...); + #ifdef __i386__ -__asm(".symver log2f_old,log2f@GLIBC_2.1"); +#define SYMVER "GLIBC_2.1" #elif defined(__amd64__) -__asm(".symver log2f_old,log2f@GLIBC_2.2.5"); +#define SYMVER "GLIBC_2.2.5" #elif defined(__arm__) -__asm(".symver log2f_old,log2f@GLIBC_2.4"); +#define SYMVER "GLIBC_2.4" #elif defined(__aarch64__) -__asm(".symver log2f_old,log2f@GLIBC_2.17"); +#define SYMVER "GLIBC_2.17" #elif defined(__riscv) -__asm(".symver log2f_old,log2f@GLIBC_2.27"); -#endif -extern "C" float __wrap_log2f(float x) +#define SYMVER "GLIBC_2.27" +#endif // __i386__ + +#define SYMVER_OLD(FUNC) __asm__(".symver " #FUNC "_old," #FUNC "@" SYMVER) + +SYMVER_OLD(exp2); +SYMVER_OLD(log2); +SYMVER_OLD(log2f); + +#ifdef __i386__ +#undef SYMVER +#undef SYMVER_OLD +#define SYMVER "GLIBC_2.0" +#define SYMVER_OLD(FUNC) __asm__(".symver " #FUNC "_old," #FUNC "@" SYMVER) +#endif // __i386__ + +SYMVER_OLD(exp); +SYMVER_OLD(log); +SYMVER_OLD(pow); +SYMVER_OLD(fcntl); + +extern "C" float __wrap_exp(float x) { return exp_old(x); } +extern "C" float __wrap_exp2(float x) { return exp2_old(x); } +extern "C" float __wrap_log(float x) { return log_old(x); } +extern "C" float __wrap_log2(float x) { return log2_old(x); } +extern "C" float __wrap_log2f(float x) { return log2f_old(x); } +extern "C" float __wrap_pow(float x, float y) { return pow_old(x, y); } + +extern "C" int __wrap_fcntl(int fd, int cmd, ...) { - return log2f_old(x); + va_list va; + void *arg; + + va_start(va, cmd); + arg = va_arg(va, void *); + va_end(va); + + return fcntl_old(fd, cmd, arg); }