Skip to content

Commit d235700

Browse files
committed
Merge bitcoin/bitcoin#21882: build: Fix undefined reference to __mulodi4
e4c8bb6 build: Fix undefined reference to __mulodi4 (Hennadii Stepanov) Pull request description: When compiling with clang on 32-bit systems the `__mulodi4` symbol is defined in compiler-rt only. Fixes #21294. See more: - https://bugs.llvm.org/show_bug.cgi?id=16404 - https://bugs.llvm.org/show_bug.cgi?id=28629 ACKs for top commit: MarcoFalke: tested-only ACK e4c8bb6 luke-jr: utACK e4c8bb6 fanquake: ACK e4c8bb6 - it's a bit of an awkward workaround to carry, but at-least it's contained to the fuzzers. Tree-SHA512: 93edb4ed568027702b1b9aba953ad50889b834ef97fde3cb99d1ce70076d9c00aa13f95c86b12d6f59b24fa90108d93742f920e15119901a2848fb337ab859a1
2 parents 19434fa + e4c8bb6 commit d235700

File tree

4 files changed

+51
-9
lines changed

4 files changed

+51
-9
lines changed

build-aux/m4/bitcoin_runtime_lib.m4

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# On some platforms clang builtin implementations
2+
# require compiler-rt as a runtime library to use.
3+
#
4+
# See:
5+
# - https://bugs.llvm.org/show_bug.cgi?id=28629
6+
7+
m4_define([_CHECK_RUNTIME_testbody], [[
8+
bool f(long long x, long long y, long long* p)
9+
{
10+
return __builtin_mul_overflow(x, y, p);
11+
}
12+
int main() { return 0; }
13+
]])
14+
15+
AC_DEFUN([CHECK_RUNTIME_LIB], [
16+
17+
AC_LANG_PUSH([C++])
18+
19+
AC_MSG_CHECKING([for __builtin_mul_overflow])
20+
AC_LINK_IFELSE(
21+
[AC_LANG_SOURCE([_CHECK_RUNTIME_testbody])],
22+
[
23+
AC_MSG_RESULT([yes])
24+
AC_DEFINE([HAVE_BUILTIN_MUL_OVERFLOW], [1], [Define if you have a working __builtin_mul_overflow])
25+
],
26+
[
27+
ax_check_save_flags="$LDFLAGS"
28+
LDFLAGS="$LDFLAGS --rtlib=compiler-rt -lgcc_s"
29+
AC_LINK_IFELSE(
30+
[AC_LANG_SOURCE([_CHECK_RUNTIME_testbody])],
31+
[
32+
AC_MSG_RESULT([yes, with additional linker flags])
33+
RUNTIME_LDFLAGS="--rtlib=compiler-rt -lgcc_s"
34+
AC_DEFINE([HAVE_BUILTIN_MUL_OVERFLOW], [1], [Define if you have a working __builtin_mul_overflow])
35+
],
36+
[AC_MSG_RESULT([no])])
37+
LDFLAGS="$ax_check_save_flags"
38+
])
39+
40+
AC_LANG_POP
41+
AC_SUBST([RUNTIME_LDFLAGS])
42+
])

configure.ac

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1752,6 +1752,10 @@ if test x$build_bitcoin_wallet$build_bitcoin_cli$build_bitcoin_tx$build_bitcoin_
17521752
AC_MSG_ERROR([No targets! Please specify at least one of: --with-utils --with-libs --with-daemon --with-gui --enable-bench or --enable-tests])
17531753
fi
17541754

1755+
if test x$enable_fuzz_binary = xyes; then
1756+
CHECK_RUNTIME_LIB
1757+
fi
1758+
17551759
AM_CONDITIONAL([TARGET_DARWIN], [test x$TARGET_OS = xdarwin])
17561760
AM_CONDITIONAL([BUILD_DARWIN], [test x$BUILD_OS = xdarwin])
17571761
AM_CONDITIONAL([TARGET_LINUX], [test x$TARGET_OS = xlinux])

src/Makefile.test.include

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ if ENABLE_FUZZ_BINARY
204204
test_fuzz_fuzz_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES)
205205
test_fuzz_fuzz_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
206206
test_fuzz_fuzz_LDADD = $(FUZZ_SUITE_LD_COMMON)
207-
test_fuzz_fuzz_LDFLAGS = $(FUZZ_SUITE_LDFLAGS_COMMON)
207+
test_fuzz_fuzz_LDFLAGS = $(FUZZ_SUITE_LDFLAGS_COMMON) $(RUNTIME_LDFLAGS)
208208
test_fuzz_fuzz_SOURCES = \
209209
test/fuzz/addition_overflow.cpp \
210210
test/fuzz/addrdb.cpp \

src/test/fuzz/multiplication_overflow.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
// Distributed under the MIT software license, see the accompanying
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

5+
#if defined(HAVE_CONFIG_H)
6+
#include <config/bitcoin-config.h>
7+
#endif
8+
59
#include <test/fuzz/FuzzedDataProvider.h>
610
#include <test/fuzz/fuzz.h>
711
#include <test/fuzz/util.h>
@@ -10,14 +14,6 @@
1014
#include <string>
1115
#include <vector>
1216

13-
#if defined(__has_builtin)
14-
#if __has_builtin(__builtin_mul_overflow)
15-
#define HAVE_BUILTIN_MUL_OVERFLOW
16-
#endif
17-
#elif defined(__GNUC__)
18-
#define HAVE_BUILTIN_MUL_OVERFLOW
19-
#endif
20-
2117
namespace {
2218
template <typename T>
2319
void TestMultiplicationOverflow(FuzzedDataProvider& fuzzed_data_provider)

0 commit comments

Comments
 (0)