From 3109a8b4325e77c0147f275ac8ab97e3029fa005 Mon Sep 17 00:00:00 2001 From: Stijn Tintel Date: Thu, 28 Jul 2022 18:04:16 +0200 Subject: [PATCH] build: add option to enable LTO for all packages Signed-off-by: Stijn Tintel --- config/Config-build.in | 8 ++++++++ include/package.mk | 7 +++++++ 2 files changed, 15 insertions(+) diff --git a/config/Config-build.in b/config/Config-build.in index c2303637cb..d842fa26a5 100644 --- a/config/Config-build.in +++ b/config/Config-build.in @@ -156,6 +156,14 @@ menu "Global build settings" config IPV6 def_bool y + config LTO + bool + prompt "Build packages with LTO" + default n + help + Builds packages with link time optimization. + Can be disabled per package with PKG_LTO:=0. + comment "Stripping options" choice diff --git a/include/package.mk b/include/package.mk index 368bf0d7ca..257e4d253b 100644 --- a/include/package.mk +++ b/include/package.mk @@ -34,6 +34,13 @@ ifeq ($(strip $(PKG_IREMAP)),1) IREMAP_CFLAGS = $(call iremap,$(PKG_BUILD_DIR),$(notdir $(PKG_BUILD_DIR))) TARGET_CFLAGS += $(IREMAP_CFLAGS) endif +ifdef CONFIG_LTO + ifneq ($(strip $(PKG_LTO)),0) + TARGET_CFLAGS += -flto + TARGET_CXXFLAGS += -flto + TARGET_LDFLAGS += -flto=jobserver + endif +endif include $(INCLUDE_DIR)/hardening.mk include $(INCLUDE_DIR)/prereq.mk -- 2.30.2