build: add option to enable LTO for all packages
authorStijn Tintel <stijn@linux-ipv6.be>
Thu, 28 Jul 2022 16:04:16 +0000 (18:04 +0200)
committerStijn Tintel <stijn@linux-ipv6.be>
Tue, 4 Oct 2022 17:35:46 +0000 (20:35 +0300)
Signed-off-by: Stijn Tintel <stijn@linux-ipv6.be>
config/Config-build.in
include/package.mk

index c2303637cb1eb5f6227880599cc9629592748b50..d842fa26a59ea91daf03d455025985ab1ad038ff 100644 (file)
@@ -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
index 368bf0d7cac1eff4b8ab33d62aa6b7f1e3c8bbc8..257e4d253b9731e759fa597df82ee77b8c13fa58 100644 (file)
@@ -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