[systemd-devel] [PATCH] build-sys: do proper LTO with GCC without needing fat objects

Jan Alexander Steffens (heftig) jan.steffens at gmail.com
Thu Jun 5 14:49:40 PDT 2014


commit 235c6e6 added `-ffat-lto-objects` in order to work around
GCC 4.9's new default of disabling such objects.

However, this also means LTO doesn't optimize across static
libraries — and never did so in the past, either.

Use the GCC wrappers for the binutils tools `nm`, `ranlib` and `ar`
in order to resolve this dilemma and link-time optimize properly.
---
 Makefile.am  | 4 ++--
 configure.ac | 6 +++++-
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index a2a01d0..a6e2b66 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -5237,7 +5237,7 @@ valgrind-tests: $(TESTS)
 	done
 
 exported-%: %
-	$(AM_V_GEN)nm -g --defined-only $(builddir)/.libs/$(<:.la=.so) 2>&1 /dev/null | grep " T " | cut -d" " -f3 > $@
+	$(AM_V_GEN)$(NM) -g --defined-only $(builddir)/.libs/$(<:.la=.so) 2>&1 /dev/null | grep " T " | cut -d" " -f3 > $@
 
 exported: $(addprefix exported-, $(lib_LTLIBRARIES))
 	$(AM_V_GEN)cat $^ > $@
@@ -5257,7 +5257,7 @@ ALL_OBJECTS:=$(foreach v,$(OBJECT_VARIABLES),$($(v)))
 
 undefined defined: $(ALL_OBJECTS)
 	$(AM_V_GEN)for f in $(ALL_OBJECTS) ; do \
-		nm -g --$@-only `echo $(builddir)/"$$f" | sed -e 's,\([^/]*\).lo$$,.libs/\1.o,'` ; \
+		$(NM) -g --$@-only `echo $(builddir)/"$$f" | sed -e 's,\([^/]*\).lo$$,.libs/\1.o,'` ; \
 	done | cut -c 20- | cut -d @ -f 1 | sort -u > $@
 
 CLEANFILES += \
diff --git a/configure.ac b/configure.ac
index 3252e65..08d4e85 100644
--- a/configure.ac
+++ b/configure.ac
@@ -42,6 +42,10 @@ AS_IF([test "x$host_cpu" = "xmips" || test "x$host_cpu" = "xmipsel" ||
        test "x$host_cpu" = "xmips64" || test "x$host_cpu" = "xmips64el"],
       [AC_DEFINE(ARCH_MIPS, [], [Whether on mips arch])])
 
+AC_CHECK_TOOLS([RANLIB], [gcc-ranlib ranlib], [ranlib])
+AC_CHECK_TOOLS([AR], [gcc-ar ar], [ar])
+AC_CHECK_TOOLS([NM], [gcc-nm nm], [nm])
+
 LT_PREREQ(2.2)
 LT_INIT([disable-static])
 
@@ -178,7 +182,7 @@ CC_CHECK_FLAGS_APPEND([with_cflags], [CFLAGS], [\
         --param=ssp-buffer-size=4])
 AS_CASE([$CFLAGS], [*-O[[12345\ ]]*],
         [CC_CHECK_FLAGS_APPEND([with_cflags], [CFLAGS], [\
-               -flto -ffat-lto-objects])],
+               -flto])],
         [AC_MSG_RESULT([skipping -flto, optimization not enabled])])
 AC_SUBST([OUR_CFLAGS], "$with_cflags $sanitizer_cflags")
 
-- 
2.0.0



More information about the systemd-devel mailing list