Skip to contentSkip to conversation

binutils, gcc: add support for GCC flag -flto

PATCH New Peter Kümmel 2 participants 2 messages Dec 20, 2014 – Feb 3, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 binutils, gcc: add support for GCC flag -flto

---
 package/binutils/Config.in                         | 5 +++++
 package/binutils/binutils.mk                       | 8 ++++++++
 package/gcc/Config.in.host                         | 6 ++++++
 package/gcc/gcc.mk                                 | 4 ++++
 toolchain/toolchain-external/toolchain-external.mk | 3 +++
 5 files changed, 26 insertions(+)
package/binutils/Config.in +5 -0
index 64d0a09..a5d2cc9 100644
@@ -19,6 +19,11 @@ config BR2_PACKAGE_BINUTILS_TARGET
 
 	  http://www.gnu.org/software/binutils/
 
+config BR2_PACKAGE_BINUTILS_ENABLE_LTO
+	bool "Enable support for link-time-optimization"
+	help
+	  Enable lto support. Allows passing a lto plugin to ar and ranlib.
+
 endif
 
 comment "binutils needs a toolchain w/ wchar"
package/binutils/binutils.mk +8 -0
index 9a9bb94..3916cad 100644
@@ -96,5 +96,13 @@ BINUTILS_PRE_PATCH_HOOKS += BINUTILS_XTENSA_PRE_PATCH
 HOST_BINUTILS_PRE_PATCH_HOOKS += BINUTILS_XTENSA_PRE_PATCH
 endif
 
+ifeq ($(BR2_PACKAGE_BINUTILS_ENABLE_LTO),y)
+BINUTILS_CONF_OPTS += --enable-plugins --enable-lto
+endif
+
+ifeq ($(BR2_GCC_ENABLE_LTO),y)
+HOST_BINUTILS_CONF_OPTS += --enable-plugins --enable-lto
+endif
+
 $(eval $(autotools-package))
 $(eval $(host-autotools-package))
package/gcc/Config.in.host +6 -0
index 0750807..4e0c2ae 100644
@@ -128,6 +128,12 @@ 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"
+	help
+	  Since version 4.5 GCC supports lto. Build GCC with lto support enabled.
+	  Needed when -flto should be used.
+
 config BR2_GCC_ENABLE_OPENMP
 	bool "Enable compiler OpenMP support"
 	depends on !BR2_PTHREADS_NONE && !BR2_avr32 && !BR2_arc && !BR2_microblaze
package/gcc/gcc.mk +4 -0
index cdd71aa..8eaa91d 100644
@@ -127,6 +127,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
toolchain/toolchain-external/toolchain-external.mk +3 -0
index b07b16c..8baf561 100644
@@ -643,6 +643,9 @@ define TOOLCHAIN_EXTERNAL_INSTALL_WRAPPER
 	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; \
 			;; \
Signature · 1 line
1.9.1
#1 lore raw

PATCH 1/1 binutils, gcc: add support for GCC flag -flto

Dear Peter K?mmel,

We reviewed your patch during the Buildroot meeting, here is some feedback.

For such a non-trivial feature, having an empty commit log is a bit weird. Can you write down some more details in the commit log?

package/binutils/Config.in config BR2_PACKAGE_BINUTILS_TARGET · line 26

Quoted 13 lines · Peter K?mmel
package/binutils/Config.in +5 -0
index 64d0a09..a5d2cc9 100644
@@ -19,6 +19,11 @@ config BR2_PACKAGE_BINUTILS_TARGET
 
 	  http://www.gnu.org/software/binutils/
 
+config BR2_PACKAGE_BINUTILS_ENABLE_LTO
+	bool "Enable support for link-time-optimization"
+	help
+	  Enable lto support. Allows passing a lto plugin to ar and ranlib.
+

We believe this is not needed, as we don't support development on the target. Even though we have a target binutils package for binutils libraries (used by oprofile or other things), or because sometimes using objdump on the target might be useful, we generally don't support development on the target, so having the option of enabling LTO in the target binutils is not very useful.

package/binutils/Config.in config BR2_PACKAGE_BINUTILS_TARGET · line 29

Quoted 3 lines
package/binutils/Config.in +3 -0
+ifeq ($(BR2_PACKAGE_BINUTILS_ENABLE_LTO),y)
+BINUTILS_CONF_OPTS += --enable-plugins --enable-lto
+endif

So this chunk would no longer be needed.

package/binutils/Config.in config BR2_PACKAGE_BINUTILS_TARGET

Quoted 4 lines
package/binutils/Config.in +4 -0
+
+ifeq ($(BR2_GCC_ENABLE_LTO),y)
+HOST_BINUTILS_CONF_OPTS += --enable-plugins --enable-lto
+endif

This looks fine.

Quoted 8 lines
package/binutils/Config.in +1 -0
+
 $(eval $(autotools-package))
 $(eval $(host-autotools-package))
package/gcc/Config.in.host +0 -0
index 0750807..4e0c2ae 100644

package/gcc/Config.in.host config BR2_GCC_ENABLE_TLS · line 135

Quoted 8 lines
package/gcc/Config.in.host +5 -0
@@ -128,6 +128,12 @@ 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"
+	help
+	  Since version 4.5 GCC supports lto. Build GCC with lto support enabled.
+	  Needed when -flto should be used.

Since it's only supported since GCC 4.5, then maybe make it 'depends on !BR2_GCC_VERSION_4_2_2_AVR32_2_1_5'.

package/gcc/Config.in.host config BR2_GCC_ENABLE_TLS · line 138

Quoted 3 lines
package/gcc/Config.in.host +3 -0
+ifeq ($(BR2_GCC_ENABLE_LTO),y)
+HOST_GCC_COMMON_CONF_OPTS += --enable-plugins --enable-lto
+endif

Looks fine.

Quoted 9 lines
package/gcc/Config.in.host +1 -0
+
 ifeq ($(BR2_GCC_ENABLE_LIBMUDFLAP),y)
 HOST_GCC_COMMON_CONF_OPTS += --enable-libmudflap
 else
toolchain/toolchain-external/toolchain-external.mk +0 -0
index b07b16c..8baf561 100644

toolchain/toolchain-external/toolchain-external.mk define TOOLCHAIN_EXTERNAL_INSTALL_WRAPPER · line 648

Quoted 6 lines
toolchain/toolchain-external/toolchain-external.mk +3 -0
@@ -643,6 +643,9 @@ define TOOLCHAIN_EXTERNAL_INSTALL_WRAPPER
 	for i in $(TOOLCHAIN_EXTERNAL_CROSS)*; do \
 		base=$${i##*/}; \
 		case "$$base" in \
+		*-ar|*-ranlib|*-nm) \
+			ln -sf $$(echo $$i | sed 's%^$(HOST_DIR)%../..%') .; \
+			;; \

Please add a comment here in the code to explain why this is happening. During the review, we had to find a previous version of your patch with a more detailed commit log to understand what was going on.

I'll mark your patch as 'Changes Requested' in patchwork, so please resend an updated version otherwise we will forget about it. Thanks a lot!

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com