]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Add a configure option to enable LTO 12441/head
authorRemi Gacogne <remi.gacogne@powerdns.com>
Fri, 20 Jan 2023 11:41:32 +0000 (12:41 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Fri, 20 Jan 2023 11:41:32 +0000 (12:41 +0100)
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.

configure.ac
m4/pdns_enable_lto.m4 [new file with mode: 0644]
pdns/dnsdistdist/configure.ac
pdns/dnsdistdist/m4/pdns_enable_lto.m4 [new symlink]
pdns/recursordist/configure.ac
pdns/recursordist/m4/pdns_enable_lto.m4 [new symlink]

index 09dffb59e041dacfa86feaf3c537261e5bafa581..fcc37fe3bcb1b29333f1f40c0d5f88e59657b983 100644 (file)
@@ -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 (file)
index 0000000..ea21956
--- /dev/null
@@ -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 <stdio.h>]],[])])
+    ])
+
+    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 <stdio.h>]],[])])
+    ])
+
+    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 <stdio.h>]],[])])
+    ])
+
+  ], [])
+
+  AC_MSG_CHECKING([whether link-time optimization is supported])
+  AC_MSG_RESULT([$enable_lto])
+])
index 18c3e157df5b4f7a1ab52928b4e2e2bf74be9027..363599686e338c42008efb0329e1d539897c2ae6 100644 (file)
@@ -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 (symlink)
index 0000000..0165907
--- /dev/null
@@ -0,0 +1 @@
+../../../m4/pdns_enable_lto.m4
\ No newline at end of file
index e97a0ac6f416fa884ca289c91578cc47c1c623ec..e6fc5c4527656697227f3b314556d46a0bf13193 100644 (file)
@@ -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 (symlink)
index 0000000..0165907
--- /dev/null
@@ -0,0 +1 @@
+../../../m4/pdns_enable_lto.m4
\ No newline at end of file