build: add a config knob to enable LTO for all packages
authorAndre Heider <a.heider@gmail.com>
Sat, 28 Jan 2023 14:24:37 +0000 (15:24 +0100)
committerChristian Marangi <ansuelsmth@gmail.com>
Tue, 21 Mar 2023 17:28:24 +0000 (18:28 +0100)
This enables LTO for all packages which haven't opted-out.

Signed-off-by: Andre Heider <a.heider@gmail.com>
config/Config-build.in
include/package.mk

index f93ad37586c5a4c0339fe4e43159344d594f6e23..df2d9101ca99c91fc8cf727f81bd636f67994fa1 100644 (file)
@@ -152,6 +152,13 @@ menu "Global build settings"
                  garbage collection capabilites.
                  Packages can choose to opt-out via setting PKG_BUILD_FLAGS:=no-gc-sections
 
+       config USE_LTO
+               bool
+               prompt "Use the link-time optimizer for all packages (EXPERIMENTAL)"
+               help
+                 Adds LTO flags to the CFLAGS and LDFLAGS.
+                 Packages can choose to opt-out via setting PKG_BUILD_FLAGS:=no-lto
+
        config IPV6
                def_bool y
 
index 687f74edc1cf1b7b82d0462b488e163056759512..d80f3bce49f4c946f9d6c814c976e9f31f6cdb0b 100644 (file)
@@ -56,7 +56,7 @@ ifeq ($(call pkg_build_flag,gc-sections,$(if $(CONFIG_USE_GC_SECTIONS),1,0)),1)
   TARGET_CXXFLAGS+= -ffunction-sections -fdata-sections
   TARGET_LDFLAGS+= -Wl,--gc-sections
 endif
-ifeq ($(call pkg_build_flag,lto,0),1)
+ifeq ($(call pkg_build_flag,lto,$(if $(CONFIG_USE_LTO),1,0)),1)
   TARGET_CFLAGS+= -flto=auto -fno-fat-lto-objects
   TARGET_CXXFLAGS+= -flto=auto -fno-fat-lto-objects
   TARGET_LDFLAGS+= -flto=auto -fuse-linker-plugin