@cryptotaxi247 / netdata-1 / commits / a2b6ad678

check if -flto can build executables before enabling it

Costa Tsaousis (ktsaou) committed Mar 12, 2017 at 00:57 UTC a2b6ad6782b46f97a092addfa082e19e11053a9b
3 files changed +61 -17
Makefile.am
+14 -2
@@ -23,8 +23,18 @@ EXTRA_DIST = \
23 .eslintignore \
24 .eslintrc \
25 .travis \
26 - m4/ax_check_enable_debug.m4 \
27 - m4/ax_c_statement_expressions.m4 \
26 + m4/jemalloc.m4 \
27 + m4/ax_c___atomic.m4 \
28 + m4/ax_check_enable_debug.m4 \
29 + m4/ax_c_mallinfo.m4 \
30 + m4/ax_gcc_func_attribute.m4 \
31 + m4/ax_check_compile_flag.m4 \
32 + m4/ax_c_statement_expressions.m4 \
33 + m4/ax_pthread.m4 \
34 + m4/ax_c_lto.m4 \
35 + m4/ax_c_mallopt.m4 \
36 + m4/tcmalloc.m4 \
37 + m4/ax_c__generic.m4 \
38 autogen.sh \
39 README.md \
40 LICENSE.md \
@@ -48,6 +58,8 @@ SUBDIRS = \
58 dist_noinst_DATA= \
59 diagrams/config.puml \
60 diagrams/registry.puml \
61 + diagrams/netdata-for-ephemeral-nodes.xml \
62 + diagrams/netdata-proxies-example.xml \
63 configs.signatures \
64 Dockerfile \
65 netdata.spec \
configure.ac
+26 -15
@@ -256,21 +256,6 @@ if test "${SSE_CANDIDATE}" = "yes" -a "${enable_x86_sse}" = "yes"; then
256 AX_CHECK_COMPILE_FLAG(${opt}, [CFLAGS="${CFLAGS} ${opt}"], [])
257 fi
258
259 -if test "${enable_lto}" != "no"; then
260 - opt="-flto"
261 - AX_CHECK_COMPILE_FLAG(${opt}, [have_lto=yes], [have_lto=no])
262 -fi
263 -test "${enable_lto}" = "yes" -a "${have_lto}" != "yes" && \
264 - AC_MSG_ERROR([LTO is required but is not available.])
265 -AC_MSG_CHECKING([if LTO should be enabled])
266 -if test "${enable_lto}" != "no" -a "${have_lto}" = "yes"; then
267 - enable_lto="yes"
268 - CFLAGS="${CFLAGS} -flto"
269 -else
270 - enable_lto="no"
271 -fi
272 -AC_MSG_RESULT([${enable_lto}])
273 -
259 if test "${GCC}" = "yes"; then
260 AC_DEFINE_UNQUOTED([likely(x)], [__builtin_expect(!!(x), 1)], [gcc branch optimization])
261 AC_DEFINE_UNQUOTED([unlikely(x)], [__builtin_expect(!!(x), 0)], [gcc branch optimization])
@@ -410,6 +395,32 @@ AC_MSG_RESULT([${enable_plugin_nfacct}])
395 AM_CONDITIONAL([ENABLE_PLUGIN_NFACCT], [test "${enable_plugin_nfacct}" = "yes"])
396
397
398 +# -----------------------------------------------------------------------------
399 +# Link-Time-Optimization
400 +
401 +if test "${enable_lto}" != "no"; then
402 + opt="-flto"
403 + AX_CHECK_COMPILE_FLAG(${opt}, [have_lto=yes], [have_lto=no])
404 +fi
405 +if test "${have_lto}" = "yes"; then
406 + oCFLAGS="${CFLAGS}"
407 + CFLAGS="${CFLAGS} -flto ${OPTIONAL_MATH_CLFAGS} ${OPTIONAL_NFACCT_CLFAGS} ${OPTIONAL_ZLIB_CLFAGS} ${OPTIONAL_UUID_CLFAGS} ${OPTIONAL_LIBCAP_CFLAGS} ${OPTIONAL_IPMIMONITORING_CFLAGS}"
408 + AC_C_LTO
409 + CFLAGS="${oCFLAGS}"
410 + test "${ac_cv_c_lto}" = "no" && have_lto="no"
411 +fi
412 +test "${enable_lto}" = "yes" -a "${have_lto}" != "yes" && \
413 + AC_MSG_ERROR([LTO is required but is not available.])
414 +AC_MSG_CHECKING([if LTO should be enabled])
415 +if test "${enable_lto}" != "no" -a "${have_lto}" = "yes"; then
416 + enable_lto="yes"
417 + CFLAGS="${CFLAGS} -flto"
418 +else
419 + enable_lto="no"
420 +fi
421 +AC_MSG_RESULT([${enable_lto}])
422 +
423 +
424 # -----------------------------------------------------------------------------
425
426 AC_DEFINE_UNQUOTED([NETDATA_USER], ["${with_user}"], [use this user to drop privileged])
m4/ax_c_lto.m4 new
+21
@@ -0,0 +1,21 @@
1 +# AC_C_LTO
2 +# -------------
3 +# Define HAVE_LTO if -flto works.
4 +AN_IDENTIFIER([lto], [AC_C_LTO])
5 +AC_DEFUN([AC_C_LTO],
6 +[AC_CACHE_CHECK([if -flto builds executables], ac_cv_c_lto,
7 +[AC_RUN_IFELSE(
8 + [AC_LANG_SOURCE(
9 + [[#include <stdio.h>
10 + int main(int argc, char **argv) {
11 + return 0;
12 + }
13 + ]])],
14 + [ac_cv_c_lto=yes],
15 + [ac_cv_c_lto=no],
16 + [ac_cv_c_lto=no])])
17 +if test $ac_cv_c_lto = yes; then
18 + AC_DEFINE([HAVE_LTO], 1,
19 + [Define to 1 if -flto works.])
20 +fi
21 +])# AC_C_LTO