build: add lto configure option #10800

Open
wants to merge 2 commits into
from
Jump to file or symbol
Failed to load files and symbols.
+23 −9
Split
View
@@ -205,6 +205,12 @@ AC_ARG_ENABLE([werror],
[enable_werror=$enableval],
[enable_werror=no])
+AC_ARG_ENABLE([lto],
+ [AS_HELP_STRING([--enable-lto],
+ [enable link-time-optimization (default is no)])],
+ [enable_lto=$enableval],
+ [enable_lto=no])
+
AC_LANG_PUSH([C++])
AX_CHECK_COMPILE_FLAG([-Werror],[CXXFLAG_WERROR="-Werror"],[CXXFLAG_WERROR=""])
@@ -219,6 +225,12 @@ if test "x$enable_debug" = xyes; then
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_COMPILE_FLAG([$LTO_CXXFLAGS -fno-fat-lto-objects],[LTO_CXXFLAGS="$LTO_CXXFLAGS -fno-fat-lto-objects"],,[[$CXXFLAG_WERROR]])
+ AX_CHECK_LINK_FLAG([-flto],[LTO_LDFLAGS="$LTO_LDFLAGS -flto"],[AC_MSG_ERROR(link failed with -flto)],[[$CXXFLAG_WERROR]])
+fi
+
ERROR_CXXFLAGS=
if test "x$enable_werror" = "xyes"; then
if test "x$CXXFLAG_WERROR" = "x"; then
@@ -1159,6 +1171,8 @@ AC_SUBST(BITCOIN_CLI_NAME)
AC_SUBST(BITCOIN_TX_NAME)
AC_SUBST(RELDFLAGS)
+AC_SUBST(LTO_CXXFLAGS)
+AC_SUBST(LTO_LDFLAGS)
AC_SUBST(ERROR_CXXFLAGS)
AC_SUBST(HARDENED_CXXFLAGS)
AC_SUBST(HARDENED_CPPFLAGS)
View
@@ -4,8 +4,8 @@
DIST_SUBDIRS = secp256k1 univalue
-AM_LDFLAGS = $(PTHREAD_CFLAGS) $(LIBTOOL_LDFLAGS) $(HARDENED_LDFLAGS)
-AM_CXXFLAGS = $(HARDENED_CXXFLAGS) $(ERROR_CXXFLAGS)
+AM_LDFLAGS = $(PTHREAD_CFLAGS) $(LIBTOOL_LDFLAGS) $(HARDENED_LDFLAGS) $(LTO_LDFLAGS)
+AM_CXXFLAGS = $(HARDENED_CXXFLAGS) $(ERROR_CXXFLAGS) $(LTO_CXXFLAGS)
AM_CPPFLAGS = $(HARDENED_CPPFLAGS)
EXTRA_LIBRARIES =
View
@@ -548,16 +548,16 @@ fs::path GetDefaultDataDir()
#endif
}
-static fs::path pathCached;
-static fs::path pathCachedNetSpecific;
+static fs::path::string_type pathCached;
+static fs::path::string_type pathCachedNetSpecific;
static CCriticalSection csPathCached;
-const fs::path &GetDataDir(bool fNetSpecific)
+fs::path GetDataDir(bool fNetSpecific)
{
LOCK(csPathCached);
- fs::path &path = fNetSpecific ? pathCachedNetSpecific : pathCached;
+ fs::path path = fNetSpecific ? pathCachedNetSpecific : pathCached;
// This can be called during exceptions by LogPrintf(), so we cache the
// value so we don't have to do memory allocations after that.
@@ -585,8 +585,8 @@ void ClearDatadirCache()
{
LOCK(csPathCached);
- pathCached = fs::path();
- pathCachedNetSpecific = fs::path();
+ pathCached = fs::path().native();
+ pathCachedNetSpecific = fs::path().native();
}
fs::path GetConfigFile(const std::string& confPath)
View
@@ -169,7 +169,7 @@ void AllocateFileRange(FILE *file, unsigned int offset, unsigned int length);
bool RenameOver(fs::path src, fs::path dest);
bool TryCreateDirectories(const fs::path& p);
fs::path GetDefaultDataDir();
-const fs::path &GetDataDir(bool fNetSpecific = true);
+fs::path GetDataDir(bool fNetSpecific = true);
void ClearDatadirCache();
fs::path GetConfigFile(const std::string& confPath);
#ifndef WIN32