File tree Expand file tree Collapse file tree 4 files changed +51
-9
lines changed
Expand file tree Collapse file tree 4 files changed +51
-9
lines changed Original file line number Diff line number Diff line change 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+ ] )
Original file line number Diff line number Diff line change @@ -1773,6 +1773,10 @@ if test x$build_bitcoin_wallet$build_bitcoin_cli$build_bitcoin_tx$build_bitcoin_
17731773 AC_MSG_ERROR ( [ No targets! Please specify at least one of: --with-utils --with-libs --with-daemon --with-gui --enable-bench or --enable-tests] )
17741774fi
17751775
1776+ if test x$enable_fuzz_binary = xyes; then
1777+ CHECK_RUNTIME_LIB
1778+ fi
1779+
17761780AM_CONDITIONAL([ TARGET_DARWIN] , [ test x$TARGET_OS = xdarwin] )
17771781AM_CONDITIONAL([ BUILD_DARWIN] , [ test x$BUILD_OS = xdarwin] )
17781782AM_CONDITIONAL([ TARGET_LINUX] , [ test x$TARGET_OS = xlinux] )
Original file line number Diff line number Diff line change @@ -200,7 +200,7 @@ if ENABLE_FUZZ_BINARY
200200test_fuzz_fuzz_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES)
201201test_fuzz_fuzz_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
202202test_fuzz_fuzz_LDADD = $(FUZZ_SUITE_LD_COMMON)
203- test_fuzz_fuzz_LDFLAGS = $(FUZZ_SUITE_LDFLAGS_COMMON)
203+ test_fuzz_fuzz_LDFLAGS = $(FUZZ_SUITE_LDFLAGS_COMMON) $(RUNTIME_LDFLAGS)
204204test_fuzz_fuzz_SOURCES = \
205205 test/fuzz/addition_overflow.cpp \
206206 test/fuzz/addrdb.cpp \
Original file line number Diff line number Diff line change 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>
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-
2117namespace {
2218template <typename T>
2319void TestMultiplicationOverflow (FuzzedDataProvider& fuzzed_data_provider)
You can’t perform that action at this time.
0 commit comments