Date: prev next · Thread: first prev next last
2011 Archives by date, by thread · List index


Hello,

I created patch, which allows link-time optimization (--enable-lto)
for shared libraries, you need at least gcc-4.5 (I'm not checking for
version in configure).
gcc-4.5 is not really good for lto but I was able to install
LibreOffice with lto enabled. I don't know what should I try to test
if it is really faster and how much.
Building is slower because gcc is compiling sources twice ? or
something like that. But real problem is that lto is memory expensive.
We could gain more with bigger libraries but it's not possible with
gcc-4.5, I'm afraid.
Unfortunately I was not able to install gcc-4.6, so I don't know if
it's better but it should.

You can use gold as linker for elf libraries, it's really faster but
linking phase it's not that much.
Most of the time is running lto1 executable and it eat cca 2GB RAM
when optimizing sw library. (cca 4,5 minutes for me)

So it is possible but not in parallel. And not for really big libraries.
I am hoping it will be much better with gcc-4.6.

ok to push ? For sure there could be better message at least in configure.

Best regards,

Matúš
From 4090637176c5b0b763c7c1f7900bc6011286bf61 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Mat=C3=BA=C5=A1=20Kukan?= <matus.kukan@gmail.com>
Date: Fri, 19 Aug 2011 23:06:13 +0200
Subject: [PATCH] enable using link-time optimization

This commit enables LTO for all shared libraries.
Build takes much longer. Use just with gcc-4.5 or later.
---
 configure.in                     |   19 +++++++++++++++++++
 set_soenv.in                     |    1 +
 solenv/gbuild/platform/macosx.mk |    8 ++++++++
 solenv/gbuild/platform/unxgcc.mk |    7 +++++++
 4 files changed, 35 insertions(+), 0 deletions(-)

diff --git a/configure.in b/configure.in
index cbd835c..b8e0c51 100755
--- a/configure.in
+++ b/configure.in
@@ -244,6 +244,13 @@ AC_ARG_ENABLE(dbgutil,
         [Include additional debugging utilities, such as assertions, object
          counting, etc. Larger build. Independent from --enable-debug]))
 
+AC_ARG_ENABLE(lto,
+    AS_HELP_STRING([--enable-lto],
+        [Enable link-time optimization. Suitable for product builds.
+         Building takes longer but libraries are optimized for speed.
+         (possible only with gcc-4.5 or later,
+          better to use gcc-4.6 and 'gold' as linker)]))
+
 AC_ARG_ENABLE(crashdump,
     AS_HELP_STRING([--enable-crashdump],
         [Enable the crashdump feature.]))
@@ -2229,6 +2236,18 @@ AC_SUBST(PRODUCT)
 AC_SUBST(PROFULLSWITCH)
 AC_SUBST(PROEXT)
 
+# Set the ENABLE_LTO variable
+# ===================================================================
+AC_MSG_CHECKING([whether to use link-time optimization])
+if test -n "$enable_lto" -a "$enable_lto" != "no"; then
+    ENABLE_LTO="TRUE"
+    AC_MSG_RESULT([yes])
+else
+    ENABLE_LTO=""
+    AC_MSG_RESULT([no])
+fi
+AC_SUBST(ENABLE_LTO)
+
 dnl whether to include symbols into final build.
 dnl ===================================================================
 AC_MSG_CHECKING([whether to include symbols])
diff --git a/set_soenv.in b/set_soenv.in
index 7e4441f..88e5188 100755
--- a/set_soenv.in
+++ b/set_soenv.in
@@ -1841,6 +1841,7 @@ ToFile( "MINGWCXX",          "@MINGWCXX@",       "e" );
 ToFile( "MINGWSTRIP",        "@MINGWSTRIP@",     "e" );
 ToFile( "WITH_STLPORT",      "@WITH_STLPORT@", "e" );
 ToFile( "ALLOC",             "@ALLOC@",          "e" );
+ToFile( "ENABLE_LTO",        "@ENABLE_LTO@",        "e" );
 ToFile( "ENABLE_SYMBOLS",    "@ENABLE_SYMBOLS@",    "e" );
 ToFile( "DISABLE_STRIP",     "@DISABLE_STRIP@",     "e" );
 ToFile( "LFS_CFLAGS",        "@LFS_CFLAGS@",     "e" );
diff --git a/solenv/gbuild/platform/macosx.mk b/solenv/gbuild/platform/macosx.mk
index 5f9fe9e..49e0127 100644
--- a/solenv/gbuild/platform/macosx.mk
+++ b/solenv/gbuild/platform/macosx.mk
@@ -119,6 +119,10 @@ gb_CFLAGS_WERROR := -Werror
 gb_CXXFLAGS_WERROR := -Werror
 endif
 
+ifeq ($(ENABLE_LTO),TRUE)
+gb_Library_LTOFLAGS := -flto
+endif
+
 gb_LinkTarget_EXCEPTIONFLAGS := \
        -DEXCEPTIONS_ON \
        -fexceptions \
@@ -172,6 +176,7 @@ $(call gb_Helper_abbreviate_dirs,\
        mkdir -p $(dir $(1)) $(dir $(4)) && \
        $(gb_CC) \
                $(DEFS) \
+               $(if $(filter Library,$(TARGETTYPE)),$(gb_Library_LTOFLAGS)) \
                $(T_CFLAGS) \
                -c $(3) \
                -o $(1) \
@@ -191,6 +196,7 @@ $(call gb_Helper_abbreviate_dirs,\
        mkdir -p $(dir $(1)) $(dir $(4)) && \
        $(gb_CXX) \
                $(DEFS) \
+               $(if $(filter Library,$(TARGETTYPE)),$(gb_Library_LTOFLAGS)) \
                $(T_CXXFLAGS) \
                -c $(3) \
                -o $(1) \
@@ -290,12 +296,14 @@ $(call gb_Helper_abbreviate_dirs,\
        $(PERL) $(SOLARENV)/bin/macosx-dylib-link-list.pl \
                $(if $(filter Executable,$(TARGETTYPE)),$(gb_Executable_TARGETTYPEFLAGS)) \
                $(if $(filter Library CppunitTest,$(TARGETTYPE)),$(gb_Library_TARGETTYPEFLAGS)) \
+               $(if $(filter Library,$(TARGETTYPE)),$(gb_Library_LTOFLAGS)) \
                $(subst \d,$$,$(RPATH)) \
                $(T_LDFLAGS) \
                $(patsubst lib%.dylib,-l%,$(foreach lib,$(LINKED_LIBS),$(call 
gb_Library_get_filename,$(lib)))) > $${DYLIB_FILE} && \
        $(gb_CXX) \
                $(if $(filter Executable,$(TARGETTYPE)),$(gb_Executable_TARGETTYPEFLAGS)) \
                $(if $(filter Library CppunitTest,$(TARGETTYPE)),$(gb_Library_TARGETTYPEFLAGS)) \
+               $(if $(filter Library,$(TARGETTYPE)),$(gb_Library_LTOFLAGS)) \
                $(subst \d,$$,$(RPATH)) \
                $(T_LDFLAGS) \
                $(call gb_LinkTarget__get_liblinkflags,$(LINKED_LIBS)) \
diff --git a/solenv/gbuild/platform/unxgcc.mk b/solenv/gbuild/platform/unxgcc.mk
index 74276dd..89a5ceb 100644
--- a/solenv/gbuild/platform/unxgcc.mk
+++ b/solenv/gbuild/platform/unxgcc.mk
@@ -121,6 +121,10 @@ ifeq ($(HAVE_CXX0X),TRUE)
 gb_CXXFLAGS += -std=c++0x -Wno-deprecated-declarations
 endif
 
+ifeq ($(ENABLE_LTO),TRUE)
+gb_Library_LTOFLAGS := -flto
+endif
+
 ifneq ($(strip $(SYSBASE)),)
 gb_CXXFLAGS += --sysroot=$(SYSBASE)
 gb_CFLAGS += --sysroot=$(SYSBASE)
@@ -195,6 +199,7 @@ $(call gb_Helper_abbreviate_dirs,\
        mkdir -p $(dir $(1)) $(dir $(4)) && \
        $(gb_CC) \
                $(DEFS) \
+               $(if $(filter Library,$(TARGETTYPE)),$(gb_Library_LTOFLAGS)) \
                $(T_CFLAGS) \
                -c $(3) \
                -o $(1) \
@@ -214,6 +219,7 @@ $(call gb_Helper_abbreviate_dirs,\
        mkdir -p $(dir $(1)) $(dir $(4)) && \
        $(gb_CXX) \
                $(DEFS) \
+               $(if $(filter Library,$(TARGETTYPE)),$(gb_Library_LTOFLAGS)) \
                $(T_CXXFLAGS) \
                -c $(3) \
                -o $(1) \
@@ -278,6 +284,7 @@ $(call gb_Helper_abbreviate_dirs,\
        mkdir -p $(dir $(1)) && \
        $(gb_CXX) \
                $(if $(filter Library CppunitTest,$(TARGETTYPE)),$(gb_Library_TARGETTYPEFLAGS)) \
+               $(if $(filter Library,$(TARGETTYPE)),$(gb_Library_LTOFLAGS)) \
                $(subst \d,$$,$(RPATH)) \
                $(T_LDFLAGS) \
                $(foreach object,$(COBJECTS),$(call gb_CObject_get_target,$(object))) \
-- 
1.7.1


Context


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.