merge bitcoin#21882: Fix undefined reference to __mulodi4

This commit is contained in:
Kittywhiskers Van Gogh 2022-10-16 01:06:10 +05:30 committed by PastaPastaPasta
parent 41eba6beef
commit 6851dbf908
4 changed files with 51 additions and 9 deletions

View File

@ -0,0 +1,42 @@
# On some platforms clang builtin implementations
# require compiler-rt as a runtime library to use.
#
# See:
# - https://bugs.llvm.org/show_bug.cgi?id=28629
m4_define([_CHECK_RUNTIME_testbody], [[
bool f(long long x, long long y, long long* p)
{
return __builtin_mul_overflow(x, y, p);
}
int main() { return 0; }
]])
AC_DEFUN([CHECK_RUNTIME_LIB], [
AC_LANG_PUSH([C++])
AC_MSG_CHECKING([for __builtin_mul_overflow])
AC_LINK_IFELSE(
[AC_LANG_SOURCE([_CHECK_RUNTIME_testbody])],
[
AC_MSG_RESULT([yes])
AC_DEFINE([HAVE_BUILTIN_MUL_OVERFLOW], [1], [Define if you have a working __builtin_mul_overflow])
],
[
ax_check_save_flags="$LDFLAGS"
LDFLAGS="$LDFLAGS --rtlib=compiler-rt -lgcc_s"
AC_LINK_IFELSE(
[AC_LANG_SOURCE([_CHECK_RUNTIME_testbody])],
[
AC_MSG_RESULT([yes, with additional linker flags])
RUNTIME_LDFLAGS="--rtlib=compiler-rt -lgcc_s"
AC_DEFINE([HAVE_BUILTIN_MUL_OVERFLOW], [1], [Define if you have a working __builtin_mul_overflow])
],
[AC_MSG_RESULT([no])])
LDFLAGS="$ax_check_save_flags"
])
AC_LANG_POP
AC_SUBST([RUNTIME_LDFLAGS])
])

View File

@ -1702,6 +1702,10 @@ if test x$build_bitcoin_wallet$build_bitcoin_cli$build_bitcoin_tx$build_bitcoind
AC_MSG_ERROR([No targets! Please specify at least one of: --with-utils --with-libs --with-daemon --with-gui --enable-bench or --enable-tests]) AC_MSG_ERROR([No targets! Please specify at least one of: --with-utils --with-libs --with-daemon --with-gui --enable-bench or --enable-tests])
fi fi
if test x$enable_fuzz_binary = xyes; then
CHECK_RUNTIME_LIB
fi
AM_CONDITIONAL([TARGET_DARWIN], [test x$TARGET_OS = xdarwin]) AM_CONDITIONAL([TARGET_DARWIN], [test x$TARGET_OS = xdarwin])
AM_CONDITIONAL([BUILD_DARWIN], [test x$BUILD_OS = xdarwin]) AM_CONDITIONAL([BUILD_DARWIN], [test x$BUILD_OS = xdarwin])
AM_CONDITIONAL([TARGET_WINDOWS], [test x$TARGET_OS = xwindows]) AM_CONDITIONAL([TARGET_WINDOWS], [test x$TARGET_OS = xwindows])

View File

@ -202,7 +202,7 @@ FUZZ_SUITE_LDFLAGS_COMMON = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS) $(
test_fuzz_fuzz_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) test_fuzz_fuzz_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES)
test_fuzz_fuzz_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS) test_fuzz_fuzz_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
test_fuzz_fuzz_LDADD = $(FUZZ_SUITE_LD_COMMON) test_fuzz_fuzz_LDADD = $(FUZZ_SUITE_LD_COMMON)
test_fuzz_fuzz_LDFLAGS = $(FUZZ_SUITE_LDFLAGS_COMMON) test_fuzz_fuzz_LDFLAGS = $(FUZZ_SUITE_LDFLAGS_COMMON) $(RUNTIME_LDFLAGS)
test_fuzz_fuzz_SOURCES = \ test_fuzz_fuzz_SOURCES = \
test/fuzz/addition_overflow.cpp \ test/fuzz/addition_overflow.cpp \
test/fuzz/addrdb.cpp \ test/fuzz/addrdb.cpp \

View File

@ -2,6 +2,10 @@
// Distributed under the MIT software license, see the accompanying // Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
#if defined(HAVE_CONFIG_H)
#include <config/bitcoin-config.h>
#endif
#include <test/fuzz/FuzzedDataProvider.h> #include <test/fuzz/FuzzedDataProvider.h>
#include <test/fuzz/fuzz.h> #include <test/fuzz/fuzz.h>
#include <test/fuzz/util.h> #include <test/fuzz/util.h>
@ -10,14 +14,6 @@
#include <string> #include <string>
#include <vector> #include <vector>
#if defined(__has_builtin)
#if __has_builtin(__builtin_mul_overflow)
#define HAVE_BUILTIN_MUL_OVERFLOW
#endif
#elif defined(__GNUC__) && (__GNUC__ >= 5)
#define HAVE_BUILTIN_MUL_OVERFLOW
#endif
namespace { namespace {
template <typename T> template <typename T>
void TestMultiplicationOverflow(FuzzedDataProvider& fuzzed_data_provider) void TestMultiplicationOverflow(FuzzedDataProvider& fuzzed_data_provider)