From 85c92ff372a9f90f52628e4890012f4e1e76cb81 Mon Sep 17 00:00:00 2001 From: Lubomir Rintel Date: Wed, 18 May 2016 20:49:36 +0200 Subject: [PATCH 1/7] build: use the glib cflags when checking the compiler flags Some of the checks include glib headers. --- m4/compiler_warnings.m4 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/m4/compiler_warnings.m4 b/m4/compiler_warnings.m4 index 77dcc7a50d..e952e3afbe 100644 --- a/m4/compiler_warnings.m4 +++ b/m4/compiler_warnings.m4 @@ -2,7 +2,7 @@ dnl Check whether a particular compiler flag works with code provided, dnl disable it in CFLAGS if the check fails. AC_DEFUN([NM_COMPILER_WARNING], [ CFLAGS_SAVED="$CFLAGS" - CFLAGS="$CFLAGS -Werror -W$1" + CFLAGS="$CFLAGS $GLIB_CFLAGS -Werror $1" AC_MSG_CHECKING(whether -W$1 works) AC_COMPILE_IFELSE([AC_LANG_SOURCE([[]])], [ From 5f849faa15c8010d95211ec7d2d5fecde95430da Mon Sep 17 00:00:00 2001 From: Lubomir Rintel Date: Wed, 18 May 2016 20:47:27 +0200 Subject: [PATCH 2/7] platform: fix the typedef-redefinition warnings The configure script disabled the warning by accident. --- src/platform/nm-platform.h | 2 -- src/platform/nmp-object.h | 1 - 2 files changed, 3 deletions(-) diff --git a/src/platform/nm-platform.h b/src/platform/nm-platform.h index ae12aa8e95..88cedeffa1 100644 --- a/src/platform/nm-platform.h +++ b/src/platform/nm-platform.h @@ -49,8 +49,6 @@ /******************************************************************/ -typedef struct _NMPlatform NMPlatform; - /* workaround for older libnl version, that does not define these flags. */ #ifndef IFA_F_MANAGETEMPADDR #define IFA_F_MANAGETEMPADDR 0x100 diff --git a/src/platform/nmp-object.h b/src/platform/nmp-object.h index 062d01d29d..d295f7a078 100644 --- a/src/platform/nmp-object.h +++ b/src/platform/nmp-object.h @@ -94,7 +94,6 @@ typedef enum { /*< skip >*/ NMP_CACHE_ID_TYPE_MAX = __NMP_CACHE_ID_TYPE_MAX - 1, } NMPCacheIdType; -typedef struct _NMPObject NMPObject; typedef struct _NMPCacheId NMPCacheId; struct _NMPCacheId { From 071b4fca613f6f20233be244f8945f081bc01744 Mon Sep 17 00:00:00 2001 From: Lubomir Rintel Date: Wed, 18 May 2016 17:19:03 +0200 Subject: [PATCH 3/7] build: prefer LTO-aware ar and ranlib This actually fixes --with-lto. --- configure.ac | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/configure.ac b/configure.ac index 01696ebaa4..be271c1159 100644 --- a/configure.ac +++ b/configure.ac @@ -35,6 +35,10 @@ AC_PROG_CXX AC_PROG_LN_S +# Prefer gcc-* variants; the ones libtool would choose don't work with LTO +AC_CHECK_TOOLS(AR, [gcc-ar ar], false) +AC_CHECK_TOOLS(RANLIB, [gcc-ranlib ranlib], :) + dnl Initialize libtool LT_PREREQ([2.2]) LT_INIT([disable-static]) From 84d90b71aef634976725aaff827a2584e89a23d2 Mon Sep 17 00:00:00 2001 From: Lubomir Rintel Date: Wed, 18 May 2016 17:20:11 +0200 Subject: [PATCH 4/7] daemon: disable external visibility for nmdbus_* symbols The generated code includes too much code that's not actually used. LTO would drop it once it's not exported. --- src/NetworkManager.ver | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/NetworkManager.ver b/src/NetworkManager.ver index b4397b9c20..c91affcb5f 100644 --- a/src/NetworkManager.ver +++ b/src/NetworkManager.ver @@ -1,6 +1,7 @@ { global: - nm*; + nm_*; + nmp_*; _nm*; NM*; _NM*; From 3b0dd0a55c713ecff752e363038ae056e43a8125 Mon Sep 17 00:00:00 2001 From: Lubomir Rintel Date: Wed, 18 May 2016 19:34:02 +0200 Subject: [PATCH 5/7] trivial: rename compiler_warnings.m4 to compiler_options.m4 We'll use that for more compiler feature-checking macros. --- m4/{compiler_warnings.m4 => compiler_options.m4} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename m4/{compiler_warnings.m4 => compiler_options.m4} (100%) diff --git a/m4/compiler_warnings.m4 b/m4/compiler_options.m4 similarity index 100% rename from m4/compiler_warnings.m4 rename to m4/compiler_options.m4 From 6d91c14b0030b63e1d5adc0a31837eff8b26537d Mon Sep 17 00:00:00 2001 From: Lubomir Rintel Date: Wed, 18 May 2016 20:49:30 +0200 Subject: [PATCH 6/7] build: add macro to check the compiler flag support Also, fold duplicate chunks together. --- m4/compiler_options.m4 | 43 ++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/m4/compiler_options.m4 b/m4/compiler_options.m4 index e952e3afbe..3d2e4dbefc 100644 --- a/m4/compiler_options.m4 +++ b/m4/compiler_options.m4 @@ -1,17 +1,17 @@ -dnl Check whether a particular compiler flag works with code provided, -dnl disable it in CFLAGS if the check fails. -AC_DEFUN([NM_COMPILER_WARNING], [ +AC_DEFUN([_NM_COMPILER_FLAG], [ CFLAGS_SAVED="$CFLAGS" CFLAGS="$CFLAGS $GLIB_CFLAGS -Werror $1" - AC_MSG_CHECKING(whether -W$1 works) + AC_MSG_CHECKING([whether $1 works as expected]) AC_COMPILE_IFELSE([AC_LANG_SOURCE([[]])], [ AC_COMPILE_IFELSE([AC_LANG_SOURCE([[$2]])], [ AC_MSG_RESULT(yes) - CFLAGS="$CFLAGS_SAVED -W$1" + CFLAGS="$CFLAGS_SAVED" + $3 ],[ AC_MSG_RESULT(no) - CFLAGS="$CFLAGS_SAVED -Wno-$1" + CFLAGS="$CFLAGS_SAVED" + $4 ]) ],[ AC_MSG_RESULT(not supported) @@ -19,6 +19,21 @@ AC_DEFUN([NM_COMPILER_WARNING], [ ]) ]) +dnl Check whether a particular compiler flag is supported, +dnl add it to CFLAGS if it is +AC_DEFUN([NM_COMPILER_FLAG], [ + _NM_COMPILER_FLAG([$1], [], [ + CFLAGS="$CFLAGS $1" + $2 + ], [$3]) +]) + +dnl Check whether a particular warning is not emitted with code provided, +dnl disable it in CFLAGS if the check fails. +AC_DEFUN([NM_COMPILER_WARNING], [ + _NM_COMPILER_FLAG([-W$1], [$2], [CFLAGS="$CFLAGS -W$1"], [CFLAGS="$CFLAGS -Wno-$1"]) +]) + AC_DEFUN([NM_COMPILER_WARNINGS], [AC_ARG_ENABLE(more-warnings, AS_HELP_STRING([--enable-more-warnings], [Possible values: no/yes/error]), @@ -40,7 +55,6 @@ if test "$GCC" = "yes" -a "$set_more_warnings" != "no"; then dnl attach it to the CFLAGS. NM_COMPILER_WARNING([unknown-warning-option], []) - CFLAGS_SAVED="$CFLAGS" CFLAGS_MORE_WARNINGS="-Wall -std=gnu89" if test "x$set_more_warnings" = xerror; then @@ -57,22 +71,11 @@ if test "$GCC" = "yes" -a "$set_more_warnings" != "no"; then -Wpointer-arith -Winit-self \ -Wmissing-include-dirs -Wno-pragmas; do dnl GCC 4.4 does not warn when checking for -Wno-* flags (https://gcc.gnu.org/wiki/FAQ#wnowarning) - CFLAGS="-Werror $CFLAGS_MORE_WARNINGS $(printf '%s' "$option" | sed 's/^-Wno-/-W/') $CFLAGS_SAVED" - AC_MSG_CHECKING([whether compiler understands $option]) - AC_TRY_COMPILE([], [], - has_option=yes, - has_option=no,) - if test $has_option != no; then - CFLAGS_MORE_WARNINGS="$CFLAGS_MORE_WARNINGS $option" - fi - AC_MSG_RESULT($has_option) - unset has_option + _NM_COMPILER_FLAG([$(printf '%s' "$option" | sed 's/^-Wno-/-W/')], [], + [CFLAGS_MORE_WARNINGS="$CFLAGS_MORE_WARNINGS $option"], []) done unset option - CFLAGS="$CFLAGS_SAVED" - unset CFLAGS_SAVED - dnl Disable warnings triggered by known compiler problems dnl https://bugzilla.gnome.org/show_bug.cgi?id=745821 From c8f65e95fdc2bfddeb071816915dcbe462068b2b Mon Sep 17 00:00:00 2001 From: Lubomir Rintel Date: Wed, 18 May 2016 20:19:05 +0200 Subject: [PATCH 7/7] build: garbage collect unused symbols by default GCC can place each symbols into separate sections making it possible for ld to discard unneeded sections (and thus symbols afterwards). This achieves almost the same size benefits as LTO without the huge performance penalty (and the undefined behavior with -g). The cost of more section headers in .o files seems to be negligible. Before: 359.73user 71.94system 1:29.67elapsed 481%CPU (0avgtext+0avgdata 137948maxresident)k text data bss dec hex filename 2772228 74848 9272 2856348 2b959c src/NetworkManager With LTO: 740.37user 94.89system 4:13.83elapsed 329%CPU (0avgtext+0avgdata 118316maxresident)k text data bss dec hex filename 2435437 74224 8704 2518365 266d5d src/NetworkManager With --gc-sections: 365.63user 72.34system 1:30.12elapsed 485%CPU (0avgtext+0avgdata 138016maxresident)k text data bss dec hex filename 2498498 74040 8408 2580946 2761d2 src/NetworkManager --- configure.ac | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/configure.ac b/configure.ac index be271c1159..50384f320e 100644 --- a/configure.ac +++ b/configure.ac @@ -935,6 +935,16 @@ else enable_lto='no' fi +AC_ARG_ENABLE(ld-gc, AS_HELP_STRING([--enable-ld-gc], [Enable garbage collection of unused symbols on linking (default: auto)])) +if (test "${enable_ld_gc}" != "no"); then + NM_COMPILER_FLAG([-fdata-sections -ffunction-sections -Wl,--gc-sections], [enable_ld_gc='yes'], [ + if (test "${enable_ld_gc}" = "yes"); then + AC_MSG_ERROR([Unused symbol eviction requested but not supported.]) + else + enable_ld_gc='no' + fi + ]) +fi dnl ------------------------- dnl Vala bindings @@ -1194,5 +1204,6 @@ echo " more-asserts: $more_asserts" echo " valgrind: $with_valgrind $with_valgrind_suppressions" echo " code coverage: $enable_code_coverage" echo " LTO: $enable_lto" +echo " linker garbage collection: $enable_ld_gc" echo " JSON validation: $enable_json_validation" echo