From: Remi Gacogne Date: Fri, 20 Jan 2023 11:41:32 +0000 (+0100) Subject: Add a configure option to enable LTO X-Git-Tag: dnsdist-1.8.0-rc1~87^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F12441%2Fhead;p=thirdparty%2Fpdns.git Add a configure option to enable LTO The supported options are: - thin: this is the recommended option for clang, as it is more scalable. It automatically determines the number of CPU cores to use. It requires support in the linker as well. - auto: this is the recommended option for GCC, and a valid fallback for clang when 'thin' is not supported. It automatically determines the number of CPU cores to use as well. - yes: this translates to '-flto', which will use a single CPU core in most cases, but is a valid fallback. - no: LTO is disabled. --- diff --git a/configure.ac b/configure.ac index 09dffb59e0..fcc37fe3bc 100644 --- a/configure.ac +++ b/configure.ac @@ -310,6 +310,7 @@ AC_SUBST([PROGRAM_LDFLAGS]) PDNS_ENABLE_COVERAGE PDNS_ENABLE_SANITIZERS PDNS_ENABLE_MALLOC_TRACE +PDNS_ENABLE_LTO AC_SUBST(LIBS) diff --git a/m4/pdns_enable_lto.m4 b/m4/pdns_enable_lto.m4 new file mode 100644 index 0000000000..ea21956708 --- /dev/null +++ b/m4/pdns_enable_lto.m4 @@ -0,0 +1,47 @@ +AC_DEFUN([PDNS_ENABLE_LTO],[ + AC_ARG_ENABLE([lto], + AS_HELP_STRING([--enable-lto], [enable Link-Time Optimizations (LTO) support @<:@default=no@:>@]), + [enable_lto=$enableval], + [enable_lto=no] + ) + + AS_IF([test "x$enable_lto" != "xno"], [ + + OLD_CXXFLAGS="$CXXFLAGS" + OLD_LDFLAGS="$LDFLAGS" + CXXFLAGS="-Wall -W -Werror $CXXFLAGS" + + dnl If thin is not supported, we try to fallback to auto + AS_IF([test "x$enable_lto" == "xthin"], [ + gl_COMPILER_OPTION_IF([-flto=thin], [ + CFLAGS="-flto=thin $CFLAGS" + CXXFLAGS="-flto=thin $OLD_CXXFLAGS" + LDFLAGS="-flto=thin $OLD_LDFLAGS" + ], [enable_lto=auto], + [AC_LANG_PROGRAM([[#include ]],[])]) + ]) + + dnl If auto is not supported, we try to fallback -flto + AS_IF([test "x$enable_lto" == "xauto"], [ + gl_COMPILER_OPTION_IF([-flto=auto], [ + CFLAGS="-flto=auto $CFLAGS" + CXXFLAGS="-flto=auto $OLD_CXXFLAGS" + LDFLAGS="-flto=auto $OLD_LDFLAGS" + ], [enable_lto=yes], + [AC_LANG_PROGRAM([[#include ]],[])]) + ]) + + AS_IF([test "x$enable_lto" == "xyes"], [ + gl_COMPILER_OPTION_IF([-flto], [ + CFLAGS="-flto $CFLAGS" + CXXFLAGS="-flto $OLD_CXXFLAGS" + LDFLAGS="-flto $OLD_LDFLAGS" + ], [enable_lto=no], + [AC_LANG_PROGRAM([[#include ]],[])]) + ]) + + ], []) + + AC_MSG_CHECKING([whether link-time optimization is supported]) + AC_MSG_RESULT([$enable_lto]) +]) diff --git a/pdns/dnsdistdist/configure.ac b/pdns/dnsdistdist/configure.ac index 18c3e157df..363599686e 100644 --- a/pdns/dnsdistdist/configure.ac +++ b/pdns/dnsdistdist/configure.ac @@ -120,6 +120,7 @@ AS_IF([test "x$enable_hardening" != "xno"], [ ]) PDNS_ENABLE_SANITIZERS +PDNS_ENABLE_LTO PDNS_CHECK_PYTHON_VENV diff --git a/pdns/dnsdistdist/m4/pdns_enable_lto.m4 b/pdns/dnsdistdist/m4/pdns_enable_lto.m4 new file mode 120000 index 0000000000..01659075c0 --- /dev/null +++ b/pdns/dnsdistdist/m4/pdns_enable_lto.m4 @@ -0,0 +1 @@ +../../../m4/pdns_enable_lto.m4 \ No newline at end of file diff --git a/pdns/recursordist/configure.ac b/pdns/recursordist/configure.ac index e97a0ac6f4..e6fc5c4527 100644 --- a/pdns/recursordist/configure.ac +++ b/pdns/recursordist/configure.ac @@ -151,8 +151,10 @@ AS_IF([test "x$enable_hardening" != "xno"], [ ]) PDNS_ENABLE_SANITIZERS +PDNS_ENABLE_LTO PDNS_ENABLE_MALLOC_TRACE PDNS_ENABLE_VALGRIND + AX_AVAILABLE_SYSTEMD AX_CHECK_SYSTEMD_FEATURES AM_CONDITIONAL([HAVE_SYSTEMD], [ test x"$systemd" = "xy" ]) diff --git a/pdns/recursordist/m4/pdns_enable_lto.m4 b/pdns/recursordist/m4/pdns_enable_lto.m4 new file mode 120000 index 0000000000..01659075c0 --- /dev/null +++ b/pdns/recursordist/m4/pdns_enable_lto.m4 @@ -0,0 +1 @@ +../../../m4/pdns_enable_lto.m4 \ No newline at end of file