From: Felix Fietkau Date: Wed, 11 Jul 2018 16:30:03 +0000 (+0200) Subject: busybox: compile with LTO enabled X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=8c11133c9de632dca69c8464f911d8e2716effe2;p=openwrt%2Fstaging%2Frmilecki.git busybox: compile with LTO enabled In the default configuration on MIPS, it reduces the .ipk size from 214k to 207k Signed-off-by: Felix Fietkau --- diff --git a/package/utils/busybox/Makefile b/package/utils/busybox/Makefile index e8d71670af7..315dd42f8d2 100644 --- a/package/utils/busybox/Makefile +++ b/package/utils/busybox/Makefile @@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=busybox PKG_VERSION:=1.28.4 -PKG_RELEASE:=2 +PKG_RELEASE:=3 PKG_FLAGS:=essential PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.bz2 @@ -20,7 +20,6 @@ PKG_HASH:=e3c14a3699dc7e82fed397392957afc78e37bdf25398ac38ead6e84621b2ae6a PKG_BUILD_DEPENDS:=BUSYBOX_USE_LIBRPC:librpc BUSYBOX_CONFIG_PAM:libpam PKG_BUILD_PARALLEL:=1 PKG_CHECK_FORMAT_SECURITY:=0 -PKG_INSTALL:=1 #Busybox use it's own PIE config flag and LDFLAGS are used with ld, not gcc. PKG_ASLR_PIE:=0 @@ -75,7 +74,10 @@ endef export KCONFIG_NOTIMESTAMP=1 +ifndef CONFIG_USE_MUSL LDLIBS:=m crypt +endif + LDLIBS += $(call BUSYBOX_IF_ENABLED,PAM,pam pam_misc pthread) ifdef CONFIG_BUSYBOX_USE_LIBRPC LDLIBS += rpc @@ -84,24 +86,32 @@ ifeq ($(CONFIG_USE_GLIBC),y) LDLIBS += $(call BUSYBOX_IF_ENABLED,NSLOOKUP_OPENWRT,resolv) endif +TARGET_CFLAGS += -flto +TARGET_LDFLAGS += -flto=jobserver -fuse-linker-plugin + MAKE_VARS := MAKE_FLAGS += \ EXTRA_CFLAGS="$(TARGET_CFLAGS) $(TARGET_CPPFLAGS)" \ EXTRA_LDFLAGS="$(TARGET_LDFLAGS)" \ LDLIBS="$(LDLIBS)" \ + LD="$(TARGET_CC)" \ SKIP_STRIP=y ifneq ($(findstring c,$(OPENWRT_VERBOSE)),) MAKE_FLAGS += V=1 endif -MAKE_INSTALL_FLAGS += CONFIG_PREFIX="$(PKG_INSTALL_DIR)" - - define Build/Configure grep 'CONFIG_BUSYBOX_$(BUSYBOX_SYM)' $(TOPDIR)/.config | sed -e "s,\\(# \)\\?CONFIG_BUSYBOX_$(BUSYBOX_SYM)_\\(.*\\),\\1CONFIG_\\2,g" > $(PKG_BUILD_DIR)/.config yes 'n' | $(MAKE) -C $(PKG_BUILD_DIR) $(MAKE_FLAGS) oldconfig endef +define Build/Compile + $(call Build/Compile/Default, \ + CONFIG_PREFIX="$(PKG_INSTALL_DIR)" \ + all install \ + ) +endef + define Package/busybox/install $(INSTALL_DIR) $(1)/etc/init.d $(CP) $(PKG_INSTALL_DIR)/* $(1)/ diff --git a/package/utils/busybox/patches/120-lto-jobserver.patch b/package/utils/busybox/patches/120-lto-jobserver.patch new file mode 100644 index 00000000000..99c5b512017 --- /dev/null +++ b/package/utils/busybox/patches/120-lto-jobserver.patch @@ -0,0 +1,27 @@ +--- a/scripts/Kbuild.include ++++ b/scripts/Kbuild.include +@@ -130,7 +130,7 @@ make-cmd = $(subst \#,\\\#,$(subst $$,$$ + # + if_changed = $(if $(strip $(filter-out $(PHONY),$?) \ + $(call arg-check, $(cmd_$(1)), $(cmd_$@)) ), \ +- @set -e; \ ++ +@set -e; \ + $(echo-cmd) $(cmd_$(1)); \ + echo 'cmd_$@ := $(make-cmd)' > $(@D)/.$(@F).cmd) + +@@ -139,7 +139,7 @@ if_changed = $(if $(strip $(filter-out $ + if_changed_dep = $(if $(strip $(filter-out $(PHONY),$?) \ + $(filter-out FORCE $(wildcard $^),$^) \ + $(call arg-check, $(cmd_$(1)), $(cmd_$@)) ), \ +- @set -e; \ ++ +@set -e; \ + $(echo-cmd) $(cmd_$(1)); \ + scripts/basic/fixdep $(depfile) $@ '$(make-cmd)' > $(@D)/.$(@F).tmp; \ + rm -f $(depfile); \ +@@ -150,5 +150,5 @@ if_changed_dep = $(if $(strip $(filter-o + # and if so will execute $(rule_foo) + if_changed_rule = $(if $(strip $(filter-out $(PHONY),$?) \ + $(call arg-check, $(cmd_$(1)), $(cmd_$@)) ),\ +- @set -e; \ ++ +@set -e; \ + $(rule_$(1)))