From a2b6ad6782b46f97a092addfa082e19e11053a9b Mon Sep 17 00:00:00 2001 From: "Costa Tsaousis (ktsaou)" Date: Sun, 12 Mar 2017 00:57:51 +0200 Subject: [PATCH] check if -flto can build executables before enabling it --- Makefile.am | 16 ++++++++++++++-- configure.ac | 41 ++++++++++++++++++++++++++--------------- m4/ax_c_lto.m4 | 21 +++++++++++++++++++++ 3 files changed, 61 insertions(+), 17 deletions(-) create mode 100644 m4/ax_c_lto.m4 diff --git a/Makefile.am b/Makefile.am index e78bbbbd..3ccf82f8 100644 --- a/Makefile.am +++ b/Makefile.am @@ -23,8 +23,18 @@ EXTRA_DIST = \ .eslintignore \ .eslintrc \ .travis \ - m4/ax_check_enable_debug.m4 \ - m4/ax_c_statement_expressions.m4 \ + m4/jemalloc.m4 \ + m4/ax_c___atomic.m4 \ + m4/ax_check_enable_debug.m4 \ + m4/ax_c_mallinfo.m4 \ + m4/ax_gcc_func_attribute.m4 \ + m4/ax_check_compile_flag.m4 \ + m4/ax_c_statement_expressions.m4 \ + m4/ax_pthread.m4 \ + m4/ax_c_lto.m4 \ + m4/ax_c_mallopt.m4 \ + m4/tcmalloc.m4 \ + m4/ax_c__generic.m4 \ autogen.sh \ README.md \ LICENSE.md \ @@ -48,6 +58,8 @@ SUBDIRS = \ dist_noinst_DATA= \ diagrams/config.puml \ diagrams/registry.puml \ + diagrams/netdata-for-ephemeral-nodes.xml \ + diagrams/netdata-proxies-example.xml \ configs.signatures \ Dockerfile \ netdata.spec \ diff --git a/configure.ac b/configure.ac index f4d7e425..3eeedc4a 100644 --- a/configure.ac +++ b/configure.ac @@ -256,21 +256,6 @@ if test "${SSE_CANDIDATE}" = "yes" -a "${enable_x86_sse}" = "yes"; then AX_CHECK_COMPILE_FLAG(${opt}, [CFLAGS="${CFLAGS} ${opt}"], []) fi -if test "${enable_lto}" != "no"; then - opt="-flto" - AX_CHECK_COMPILE_FLAG(${opt}, [have_lto=yes], [have_lto=no]) -fi -test "${enable_lto}" = "yes" -a "${have_lto}" != "yes" && \ - AC_MSG_ERROR([LTO is required but is not available.]) -AC_MSG_CHECKING([if LTO should be enabled]) -if test "${enable_lto}" != "no" -a "${have_lto}" = "yes"; then - enable_lto="yes" - CFLAGS="${CFLAGS} -flto" -else - enable_lto="no" -fi -AC_MSG_RESULT([${enable_lto}]) - if test "${GCC}" = "yes"; then AC_DEFINE_UNQUOTED([likely(x)], [__builtin_expect(!!(x), 1)], [gcc branch optimization]) AC_DEFINE_UNQUOTED([unlikely(x)], [__builtin_expect(!!(x), 0)], [gcc branch optimization]) @@ -410,6 +395,32 @@ AC_MSG_RESULT([${enable_plugin_nfacct}]) AM_CONDITIONAL([ENABLE_PLUGIN_NFACCT], [test "${enable_plugin_nfacct}" = "yes"]) +# ----------------------------------------------------------------------------- +# Link-Time-Optimization + +if test "${enable_lto}" != "no"; then + opt="-flto" + AX_CHECK_COMPILE_FLAG(${opt}, [have_lto=yes], [have_lto=no]) +fi +if test "${have_lto}" = "yes"; then + oCFLAGS="${CFLAGS}" + CFLAGS="${CFLAGS} -flto ${OPTIONAL_MATH_CLFAGS} ${OPTIONAL_NFACCT_CLFAGS} ${OPTIONAL_ZLIB_CLFAGS} ${OPTIONAL_UUID_CLFAGS} ${OPTIONAL_LIBCAP_CFLAGS} ${OPTIONAL_IPMIMONITORING_CFLAGS}" + AC_C_LTO + CFLAGS="${oCFLAGS}" + test "${ac_cv_c_lto}" = "no" && have_lto="no" +fi +test "${enable_lto}" = "yes" -a "${have_lto}" != "yes" && \ + AC_MSG_ERROR([LTO is required but is not available.]) +AC_MSG_CHECKING([if LTO should be enabled]) +if test "${enable_lto}" != "no" -a "${have_lto}" = "yes"; then + enable_lto="yes" + CFLAGS="${CFLAGS} -flto" +else + enable_lto="no" +fi +AC_MSG_RESULT([${enable_lto}]) + + # ----------------------------------------------------------------------------- AC_DEFINE_UNQUOTED([NETDATA_USER], ["${with_user}"], [use this user to drop privileged]) diff --git a/m4/ax_c_lto.m4 b/m4/ax_c_lto.m4 new file mode 100644 index 00000000..94552773 --- /dev/null +++ b/m4/ax_c_lto.m4 @@ -0,0 +1,21 @@ +# AC_C_LTO +# ------------- +# Define HAVE_LTO if -flto works. +AN_IDENTIFIER([lto], [AC_C_LTO]) +AC_DEFUN([AC_C_LTO], +[AC_CACHE_CHECK([if -flto builds executables], ac_cv_c_lto, +[AC_RUN_IFELSE( + [AC_LANG_SOURCE( + [[#include + int main(int argc, char **argv) { + return 0; + } + ]])], + [ac_cv_c_lto=yes], + [ac_cv_c_lto=no], + [ac_cv_c_lto=no])]) +if test $ac_cv_c_lto = yes; then + AC_DEFINE([HAVE_LTO], 1, + [Define to 1 if -flto works.]) +fi +])# AC_C_LTO -- 2.39.2