diff --git a/package/binutils/Config.in.host b/package/binutils/Config.in.host index d0ed84e059..4049cf6a3e 100644 --- a/package/binutils/Config.in.host +++ b/package/binutils/Config.in.host @@ -38,6 +38,9 @@ config BR2_BINUTILS_VERSION default "2.24" if BR2_BINUTILS_VERSION_2_24 default "2.25" if BR2_BINUTILS_VERSION_2_25 +config BR2_BINUTILS_ENABLE_LTO + bool + config BR2_BINUTILS_EXTRA_CONFIG_OPTIONS string "Additional binutils options" default "" diff --git a/package/binutils/binutils.mk b/package/binutils/binutils.mk index 9e992533f3..ac62f1f0d2 100644 --- a/package/binutils/binutils.mk +++ b/package/binutils/binutils.mk @@ -96,5 +96,9 @@ BINUTILS_PRE_PATCH_HOOKS += BINUTILS_XTENSA_PRE_PATCH HOST_BINUTILS_PRE_PATCH_HOOKS += BINUTILS_XTENSA_PRE_PATCH endif +ifeq ($(BR2_BINUTILS_ENABLE_LTO),y) +HOST_BINUTILS_CONF_OPTS += --enable-plugins --enable-lto +endif + $(eval $(autotools-package)) $(eval $(host-autotools-package)) diff --git a/package/gcc/Config.in.host b/package/gcc/Config.in.host index e07d881444..1a5281ca5b 100644 --- a/package/gcc/Config.in.host +++ b/package/gcc/Config.in.host @@ -116,6 +116,13 @@ config BR2_GCC_ENABLE_TLS Enable the compiler to generate code for accessing thread local storage variables +config BR2_GCC_ENABLE_LTO + bool "Enable compiler link-time-optimization support" + select BR2_BINUTILS_ENABLE_LTO + help + This option enables link-time optimization (LTO) support in + gcc. + config BR2_GCC_ENABLE_OPENMP bool "Enable compiler OpenMP support" depends on !BR2_PTHREADS_NONE && !BR2_arc && !BR2_microblaze diff --git a/package/gcc/gcc.mk b/package/gcc/gcc.mk index ffac15c786..b5d2ddba1e 100644 --- a/package/gcc/gcc.mk +++ b/package/gcc/gcc.mk @@ -132,6 +132,10 @@ else HOST_GCC_COMMON_CONF_OPTS += --disable-tls endif +ifeq ($(BR2_GCC_ENABLE_LTO),y) +HOST_GCC_COMMON_CONF_OPTS += --enable-plugins --enable-lto +endif + ifeq ($(BR2_GCC_ENABLE_LIBMUDFLAP),y) HOST_GCC_COMMON_CONF_OPTS += --enable-libmudflap else diff --git a/toolchain/toolchain-external/toolchain-external.mk b/toolchain/toolchain-external/toolchain-external.mk index 78138d370a..612c49d2e1 100644 --- a/toolchain/toolchain-external/toolchain-external.mk +++ b/toolchain/toolchain-external/toolchain-external.mk @@ -647,12 +647,20 @@ endif # Build toolchain wrapper for preprocessor, C and C++ compiler and setup # symlinks for everything else. Skip gdb symlink when we are building our # own gdb to prevent two gdb's in output/host/usr/bin. +# When the link-time-optimazation flag '-flto' is used, then the compiler +# and binutils have to support lto. ar/ranlib need to be called with the +# lto plugin. The wrappers *-gcc-ar and *-gcc-ranlib provided by GCC could +# be used as drop-ins for ar/runlib when Makefiles are used which do not +# pass the lto arguments. define TOOLCHAIN_EXTERNAL_INSTALL_WRAPPER $(Q)$(call MESSAGE,"Building ext-toolchain wrapper") mkdir -p $(HOST_DIR)/usr/bin; cd $(HOST_DIR)/usr/bin; \ for i in $(TOOLCHAIN_EXTERNAL_CROSS)*; do \ base=$${i##*/}; \ case "$$base" in \ + *-ar|*-ranlib|*-nm) \ + ln -sf $$(echo $$i | sed 's%^$(HOST_DIR)%../..%') .; \ + ;; \ *cc|*cc-*|*++|*++-*|*cpp) \ ln -sf ext-toolchain-wrapper $$base; \ ;; \