[openwrt/openwrt] build: add a config knob to enable LTO for all packages

LEDE Commits lede-commits at lists.infradead.org
Tue Mar 21 10:28:42 PDT 2023


ansuel pushed a commit to openwrt/openwrt.git, branch master:
https://git.openwrt.org/9ea7019ffd60ab3ef5a5654116fbc339f856482c

commit 9ea7019ffd60ab3ef5a5654116fbc339f856482c
Author: Andre Heider <a.heider at gmail.com>
AuthorDate: Sat Jan 28 15:24:37 2023 +0100

    build: add a config knob to enable LTO for all packages
    
    This enables LTO for all packages which haven't opted-out.
    
    Signed-off-by: Andre Heider <a.heider at gmail.com>
---
 config/Config-build.in | 7 +++++++
 include/package.mk     | 2 +-
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/config/Config-build.in b/config/Config-build.in
index f93ad37586..df2d9101ca 100644
--- a/config/Config-build.in
+++ b/config/Config-build.in
@@ -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
 
diff --git a/include/package.mk b/include/package.mk
index 687f74edc1..d80f3bce49 100644
--- a/include/package.mk
+++ b/include/package.mk
@@ -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




More information about the lede-commits mailing list