Skip to content

Instantly share code, notes, and snippets.

@stintel
Created October 17, 2018 17:05
Show Gist options
  • Save stintel/95c253019bc666f3ebd29dffbe194472 to your computer and use it in GitHub Desktop.
Save stintel/95c253019bc666f3ebd29dffbe194472 to your computer and use it in GitHub Desktop.
stdin
diff --git a/config/Config-build.in b/config/Config-build.in
index a082a5e0e2..7aced23a97 100644
--- a/config/Config-build.in
+++ b/config/Config-build.in
@@ -84,6 +84,14 @@ menu "Global build settings"
Useful for release builds, so that kernel issues can be debugged offline
later.
+ config PKG_LTO
+ bool
+ prompt "Build packages with LTO"
+ default n
+ help
+ If enabled, packages are built with link-time optimization.
+
+
menu "Kernel build options"
source "config/Config-kernel.in"
diff --git a/include/package.mk b/include/package.mk
index a03db11119..2240a1349a 100644
--- a/include/package.mk
+++ b/include/package.mk
@@ -16,6 +16,7 @@ PKG_INSTALL_DIR ?= $(PKG_BUILD_DIR)/ipkg-install
PKG_BUILD_PARALLEL ?=
PKG_USE_MIPS16 ?= 1
PKG_IREMAP ?= 1
+PKG_LTO ?= 1
MAKE_J:=$(if $(MAKE_JOBSERVER),$(MAKE_JOBSERVER) $(if $(filter 3.% 4.0 4.1,$(MAKE_VERSION)),-j))
@@ -35,6 +36,16 @@ ifeq ($(strip $(PKG_IREMAP)),1)
TARGET_CFLAGS += $(IREMAP_CFLAGS)
endif
+ifdef CONFIG_PKG_LTO
+ ifeq ($(strip $(PKG_LTO)),1)
+ TARGET_CFLAGS += -flto=jobserver
+ TARGET_LDFLAGS += -flto=jobserver
+ else
+ TARGET_CFLAGS += -fno-lto
+ TARGET_LDFLAGS += -fno-lto
+ endif
+endif
+
include $(INCLUDE_DIR)/hardening.mk
include $(INCLUDE_DIR)/prereq.mk
include $(INCLUDE_DIR)/unpack.mk
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment