diff --git a/configure.ac b/configure.ac index 0a85c94705..10a5a83026 100644 --- a/configure.ac +++ b/configure.ac @@ -345,6 +345,11 @@ AC_ARG_WITH([boost-process], [boost_process=$withval], [boost_process=no]) +AC_ARG_ENABLE([lto], + [AS_HELP_STRING([--enable-lto],[build using LTO (default is no)])], + [enable_lto=$enableval], + [enable_lto=no]) + AC_LANG_PUSH([C++]) dnl Check for a flag to turn compiler warnings into errors. This is helpful for checks which may @@ -403,6 +408,11 @@ else fi fi +if test "x$enable_lto" = "xyes"; then + AX_CHECK_COMPILE_FLAG([-flto], [LTO_CXXFLAGS="$LTO_CXXFLAGS -flto"], [AC_MSG_ERROR([compile failed with -flto])], [$CXXFLAG_WERROR]) + AX_CHECK_LINK_FLAG([-flto], [LTO_LDFLAGS="$LTO_LDFLAGS -flto"], [AC_MSG_ERROR([link failed with -flto])], [$CXXFLAG_WERROR]) +fi + if test "x$enable_stacktraces" != xno; then AC_CHECK_HEADERS([execinfo.h], [], [enable_stacktraces=no]) fi @@ -1898,6 +1908,8 @@ AC_SUBST(GPROF_LDFLAGS) AC_SUBST(HARDENED_CXXFLAGS) AC_SUBST(HARDENED_CPPFLAGS) AC_SUBST(HARDENED_LDFLAGS) +AC_SUBST(LTO_CXXFLAGS) +AC_SUBST(LTO_LDFLAGS) AC_SUBST(PIC_FLAGS) AC_SUBST(PIE_FLAGS) AC_SUBST(SANITIZER_CXXFLAGS) @@ -1997,6 +2009,7 @@ echo " crash hooks enabled = $enable_crashhooks" echo " miner enabled = $enable_miner" echo " gprof enabled = $enable_gprof" echo " werror = $enable_werror" +echo " LTO = $enable_lto" echo echo " target os = $host_os" echo " build os = $build_os" @@ -2005,7 +2018,7 @@ echo " CC = $CC" echo " CFLAGS = $PTHREAD_CFLAGS $CFLAGS" echo " CPPFLAGS = $DEBUG_CPPFLAGS $HARDENED_CPPFLAGS $CPPFLAGS" echo " CXX = $CXX" -echo " CXXFLAGS = $DEBUG_CXXFLAGS $HARDENED_CXXFLAGS $WARN_CXXFLAGS $NOWARN_CXXFLAGS $ERROR_CXXFLAGS $GPROF_CXXFLAGS $CXXFLAGS" -echo " LDFLAGS = $PTHREAD_LIBS $HARDENED_LDFLAGS $GPROF_LDFLAGS $LDFLAGS" +echo " CXXFLAGS = $LTO_CXXFLAGS $DEBUG_CXXFLAGS $HARDENED_CXXFLAGS $WARN_CXXFLAGS $NOWARN_CXXFLAGS $ERROR_CXXFLAGS $GPROF_CXXFLAGS $CXXFLAGS" +echo " LDFLAGS = $LTO_LDFLAGS $PTHREAD_LIBS $HARDENED_LDFLAGS $GPROF_LDFLAGS $LDFLAGS" echo " ARFLAGS = $ARFLAGS" echo diff --git a/src/Makefile.am b/src/Makefile.am index 65bf28035a..38f51fada8 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -9,8 +9,8 @@ print-%: FORCE DIST_SUBDIRS = secp256k1 -AM_LDFLAGS = $(LIBTOOL_LDFLAGS) $(HARDENED_LDFLAGS) $(GPROF_LDFLAGS) $(SANITIZER_LDFLAGS) -AM_CXXFLAGS = $(DEBUG_CXXFLAGS) $(HARDENED_CXXFLAGS) $(WARN_CXXFLAGS) $(NOWARN_CXXFLAGS) $(ERROR_CXXFLAGS) $(GPROF_CXXFLAGS) $(SANITIZER_CXXFLAGS) +AM_LDFLAGS = $(LIBTOOL_LDFLAGS) $(HARDENED_LDFLAGS) $(GPROF_LDFLAGS) $(SANITIZER_LDFLAGS) $(LTO_LDFLAGS) +AM_CXXFLAGS = $(DEBUG_CXXFLAGS) $(HARDENED_CXXFLAGS) $(WARN_CXXFLAGS) $(NOWARN_CXXFLAGS) $(ERROR_CXXFLAGS) $(GPROF_CXXFLAGS) $(SANITIZER_CXXFLAGS) $(LTO_CXXFLAGS) AM_CPPFLAGS = $(DEBUG_CPPFLAGS) $(HARDENED_CPPFLAGS) AM_LIBTOOLFLAGS = --preserve-dup-deps PTHREAD_FLAGS = $(PTHREAD_CFLAGS) $(PTHREAD_LIBS) @@ -142,11 +142,10 @@ BITCOIN_CORE_H = \ bech32.h \ bip324.h \ blockencodings.h \ - bloom.h \ + common/bloom.h \ cachemap.h \ cachemultimap.h \ blockfilter.h \ - bloom.h \ chain.h \ chainparams.h \ chainparamsbase.h \ @@ -161,6 +160,7 @@ BITCOIN_CORE_H = \ coinjoin/server.h \ coinjoin/util.h \ coins.h \ + common/bloom.h \ compat.h \ compat/assumptions.h \ compat/byteswap.h \ @@ -258,7 +258,6 @@ BITCOIN_CORE_H = \ memusage.h \ merkleblock.h \ messagesigner.h \ - miner.h \ minisketchwrapper.h \ net.h \ net_permissions.h \ @@ -275,6 +274,7 @@ BITCOIN_CORE_H = \ node/connection_types.h \ node/context.h \ node/eviction.h \ + node/miner.h \ node/psbt.h \ node/transaction.h \ node/ui_interface.h \ @@ -494,7 +494,6 @@ libbitcoin_server_a_SOURCES = \ masternode/payments.cpp \ masternode/sync.cpp \ masternode/utils.cpp \ - miner.cpp \ minisketchwrapper.cpp \ net.cpp \ netfulfilledman.cpp \ @@ -507,6 +506,7 @@ libbitcoin_server_a_SOURCES = \ node/context.cpp \ node/eviction.cpp \ node/interfaces.cpp \ + node/miner.cpp \ node/psbt.cpp \ node/transaction.cpp \ node/ui_interface.cpp \ @@ -699,11 +699,11 @@ crypto_libbitcoin_crypto_arm_shani_a_SOURCES = crypto/sha256_arm_shani.cpp libbitcoin_consensus_a_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) libbitcoin_consensus_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS) libbitcoin_consensus_a_SOURCES = \ - amount.h \ arith_uint256.cpp \ arith_uint256.h \ bls/bls.cpp \ bls/bls.h \ + consensus/amount.h \ consensus/merkle.cpp \ consensus/merkle.h \ consensus/params.h \ @@ -743,9 +743,9 @@ libbitcoin_common_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS) libbitcoin_common_a_SOURCES = \ base58.cpp \ bech32.cpp \ - bloom.cpp \ chainparams.cpp \ coins.cpp \ + common/bloom.cpp \ compressor.cpp \ core_read.cpp \ core_write.cpp \ diff --git a/src/addressindex.h b/src/addressindex.h index b5cbcefc1f..55dbc8284a 100644 --- a/src/addressindex.h +++ b/src/addressindex.h @@ -8,7 +8,7 @@ #ifndef BITCOIN_ADDRESSINDEX_H #define BITCOIN_ADDRESSINDEX_H -#include +#include #include #include #include diff --git a/src/banman.h b/src/banman.h index a8afc34e82..1c534f653f 100644 --- a/src/banman.h +++ b/src/banman.h @@ -6,7 +6,7 @@ #define BITCOIN_BANMAN_H #include -#include +#include #include #include // For banmap_t #include diff --git a/src/bench/rollingbloom.cpp b/src/bench/rollingbloom.cpp index 28167767db..30bc1d5fdf 100644 --- a/src/bench/rollingbloom.cpp +++ b/src/bench/rollingbloom.cpp @@ -4,7 +4,7 @@ #include -#include +#include static void RollingBloom(benchmark::Bench& bench) { diff --git a/src/coinjoin/common.h b/src/coinjoin/common.h index 165664c3d1..def3ffc83a 100644 --- a/src/coinjoin/common.h +++ b/src/coinjoin/common.h @@ -5,7 +5,7 @@ #ifndef BITCOIN_COINJOIN_COMMON_H #define BITCOIN_COINJOIN_COMMON_H -#include +#include #include #include diff --git a/src/coinjoin/options.h b/src/coinjoin/options.h index 5c48a84a6e..8782df0e1b 100644 --- a/src/coinjoin/options.h +++ b/src/coinjoin/options.h @@ -5,7 +5,8 @@ #ifndef BITCOIN_COINJOIN_OPTIONS_H #define BITCOIN_COINJOIN_OPTIONS_H -#include +#include + #include #include diff --git a/src/bloom.cpp b/src/common/bloom.cpp similarity index 99% rename from src/bloom.cpp rename to src/common/bloom.cpp index 50cf719495..6fc86cf72a 100644 --- a/src/bloom.cpp +++ b/src/common/bloom.cpp @@ -2,7 +2,7 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#include +#include #include #include diff --git a/src/bloom.h b/src/common/bloom.h similarity index 98% rename from src/bloom.h rename to src/common/bloom.h index f0630650db..8a206f2fd4 100644 --- a/src/bloom.h +++ b/src/common/bloom.h @@ -2,8 +2,8 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#ifndef BITCOIN_BLOOM_H -#define BITCOIN_BLOOM_H +#ifndef BITCOIN_COMMON_BLOOM_H +#define BITCOIN_COMMON_BLOOM_H #include #include @@ -133,4 +133,4 @@ private: int nHashFuncs; }; -#endif // BITCOIN_BLOOM_H +#endif // BITCOIN_COMMON_BLOOM_H diff --git a/src/amount.h b/src/consensus/amount.h similarity index 77% rename from src/amount.h rename to src/consensus/amount.h index 47968e80b1..96566ea13f 100644 --- a/src/amount.h +++ b/src/consensus/amount.h @@ -3,15 +3,16 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#ifndef BITCOIN_AMOUNT_H -#define BITCOIN_AMOUNT_H +#ifndef BITCOIN_CONSENSUS_AMOUNT_H +#define BITCOIN_CONSENSUS_AMOUNT_H -#include +#include /** Amount in satoshis (Can be negative) */ typedef int64_t CAmount; -static const CAmount COIN = 100000000; +/** The amount of satoshis in one BTC. */ +static constexpr CAmount COIN = 100000000; /** No amount larger than this (in satoshi) is valid. * @@ -22,7 +23,7 @@ static const CAmount COIN = 100000000; * critical; in unusual circumstances like a(nother) overflow bug that allowed * for the creation of coins out of thin air modification could lead to a fork. * */ -static const CAmount MAX_MONEY = 21000000 * COIN; +static constexpr CAmount MAX_MONEY = 21000000 * COIN; inline bool MoneyRange(const CAmount& nValue) { return (nValue >= 0 && nValue <= MAX_MONEY); } -#endif // BITCOIN_AMOUNT_H +#endif // BITCOIN_CONSENSUS_AMOUNT_H diff --git a/src/consensus/consensus.h b/src/consensus/consensus.h index 12087eda43..adc95252cf 100644 --- a/src/consensus/consensus.h +++ b/src/consensus/consensus.h @@ -26,7 +26,5 @@ static const int COINBASE_MATURITY = 100; /** Flags for nSequence and nLockTime locks */ /** Interpret sequence numbers as relative lock-time constraints. */ static constexpr unsigned int LOCKTIME_VERIFY_SEQUENCE = (1 << 0); -/** Use GetMedianTimePast() instead of nTime for end point timestamp. */ -static constexpr unsigned int LOCKTIME_MEDIAN_TIME_PAST = (1 << 1); #endif // BITCOIN_CONSENSUS_CONSENSUS_H diff --git a/src/consensus/tx_check.cpp b/src/consensus/tx_check.cpp index 6300879914..3908f483d0 100644 --- a/src/consensus/tx_check.cpp +++ b/src/consensus/tx_check.cpp @@ -7,6 +7,7 @@ #include #include +#include #include #include diff --git a/src/consensus/tx_verify.h b/src/consensus/tx_verify.h index 4fbae4c540..76bbe68311 100644 --- a/src/consensus/tx_verify.h +++ b/src/consensus/tx_verify.h @@ -5,7 +5,7 @@ #ifndef BITCOIN_CONSENSUS_TX_VERIFY_H #define BITCOIN_CONSENSUS_TX_VERIFY_H -#include +#include #include #include diff --git a/src/core_io.h b/src/core_io.h index a24d7d5d7f..c416dd8501 100644 --- a/src/core_io.h +++ b/src/core_io.h @@ -5,7 +5,7 @@ #ifndef BITCOIN_CORE_IO_H #define BITCOIN_CORE_IO_H -#include +#include #include #include diff --git a/src/core_write.cpp b/src/core_write.cpp index a2cdf68aa4..35f9bc2555 100644 --- a/src/core_write.cpp +++ b/src/core_write.cpp @@ -4,6 +4,7 @@ #include +#include #include #include #include diff --git a/src/evo/dmn_types.h b/src/evo/dmn_types.h index edc36187dd..d532c6b3a6 100644 --- a/src/evo/dmn_types.h +++ b/src/evo/dmn_types.h @@ -5,7 +5,7 @@ #ifndef BITCOIN_EVO_DMN_TYPES_H #define BITCOIN_EVO_DMN_TYPES_H -#include +#include #include #include diff --git a/src/governance/classes.h b/src/governance/classes.h index 3e42f2bdf0..030ae5f050 100644 --- a/src/governance/classes.h +++ b/src/governance/classes.h @@ -4,7 +4,7 @@ #ifndef BITCOIN_GOVERNANCE_CLASSES_H #define BITCOIN_GOVERNANCE_CLASSES_H -#include +#include #include #include