Adding size relevant build options
cover Adding size relevant build options
Hi,
I was talking with Marek and Simon about build options which may be size relevant. The first change is to allow the linker to check for unused code sections. The second change is to let the compiler use get the whole source code instead of only one source file during the final compilation step (ok, it is originally the link step).
These changes reduce the size on an amd64 (default Debian settings with -O2) by around 25%. The size reduction on MIPSel (default OpenWRT settings with -Os) were only by 6%-10%. Marek were still interested and asked me to submit the changes.
Kind regards,
Sven
PATCH 1/9 alfred: Add CFLAGS to the linker step
The GCC manual states for different parameters that the options for compilation must also be used when linking. The options for compilation are stored in CFLAGS and added to LINK.o to fix the behavior.
Option which need this are for example -fPIC/-fPIE or -flto.
--- Makefile | 2 +- vis/Makefile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
Makefile +1 -1
@@ -42,7 +42,7 @@ RM ?= rm -f INSTALL ?= install MKDIR ?= mkdir -p COMPILE.c = $(Q_CC)$(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c -LINK.o = $(Q_LD)$(CC) $(LDFLAGS) $(TARGET_ARCH) +LINK.o = $(Q_LD)$(CC) $(CFLAGS) $(LDFLAGS) $(TARGET_ARCH) # standard install paths PREFIX = /usr/local
vis/Makefile +1 -1
@@ -42,7 +42,7 @@ RM ?= rm -f INSTALL ?= install MKDIR ?= mkdir -p COMPILE.c = $(Q_CC)$(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c -LINK.o = $(Q_LD)$(CC) $(LDFLAGS) $(TARGET_ARCH) +LINK.o = $(Q_LD)$(CC) $(CFLAGS) $(LDFLAGS) $(TARGET_ARCH) # standard install paths PREFIX = /usr/local
Signature · 1 line
1.8.2.1
Simon Wunderlich
AppliedRe: [B.A.T.M.A.N.] [PATCH 1/9] alfred: Add CFLAGS to the linker step
Quoted 11 lines · Sven Eckelmann
The GCC manual states for different parameters that the options for compilation must also be used when linking. The options for compilation are stored in CFLAGS and added to LINK.o to fix the behavior.
Option which need this are for example -fPIC/-fPIE or -flto.
Signed-off-by Sven Eckelmann <[email protected]>--- Makefile | 2 +- vis/Makefile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
Applied in revision c693d67.
Thanks,
Simon
PATCH 2/9 batctl: Add CFLAGS to the linker step
In reply to Sven EckelmannThe GCC manual states for different parameters that the options for compilation must also be used when linking. The options for compilation are stored in CFLAGS and added to LINK.o to fix the behavior.
Option which need this are for example -fPIC/-fPIE or -flto.
--- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Makefile +1 -1
@@ -53,7 +53,7 @@ RM ?= rm -f INSTALL ?= install MKDIR ?= mkdir -p COMPILE.c = $(Q_CC)$(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c -LINK.o = $(Q_LD)$(CC) $(LDFLAGS) $(TARGET_ARCH) +LINK.o = $(Q_LD)$(CC) $(CFLAGS) $(LDFLAGS) $(TARGET_ARCH) # standard install paths PREFIX = /usr/local
Signature · 1 line
1.8.2.1
Marek Lindner
AppliedRe: [B.A.T.M.A.N.] [PATCH 2/9] batctl: Add CFLAGS to the linker step
Quoted 9 lines · On Tuesday, May 07, 2013 20:51:02 Sven Eckelmann wrote:
The GCC manual states for different parameters that the options for compilation must also be used when linking. The options for compilation are stored in CFLAGS and added to LINK.o to fix the behavior.
Option which need this are for example -fPIC/-fPIE or -flto.
Signed-off-by Sven Eckelmann <[email protected]>--- Makefile | 2 +-
Applied in revision b80d07f.
Thanks,
Marek
PATCH 3/9 batmand: Add CFLAGS to the linker step
In reply to Sven EckelmannThe GCC manual states for different parameters that the options for compilation must also be used when linking. The options for compilation are stored in CFLAGS and added to LINK.o to fix the behavior.
Option which need this are for example -fPIC/-fPIE or -flto.
--- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Makefile +1 -1
@@ -57,7 +57,7 @@ RM ?= rm -f INSTALL ?= install MKDIR ?= mkdir -p COMPILE.c = $(Q_CC)$(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c -LINK.o = $(Q_LD)$(CC) $(LDFLAGS) $(TARGET_ARCH) +LINK.o = $(Q_LD)$(CC) $(CFLAGS) $(LDFLAGS) $(TARGET_ARCH) # standard install paths PREFIX = /usr/local
Signature · 1 line
1.8.2.1
PATCH 4/9 vis: Add CFLAGS to the linker step
In reply to Sven EckelmannThe GCC manual states for different parameters that the options for compilation must also be used when linking. The options for compilation are stored in CFLAGS and added to LINK.o to fix the behavior.
Option which need this are for example -fPIC/-fPIE or -flto.
--- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Makefile +1 -1
@@ -43,7 +43,7 @@ RM ?= rm -f INSTALL ?= install MKDIR ?= mkdir -p COMPILE.c = $(Q_CC)$(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c -LINK.o = $(Q_LD)$(CC) $(LDFLAGS) $(TARGET_ARCH) +LINK.o = $(Q_LD)$(CC) $(CFLAGS) $(LDFLAGS) $(TARGET_ARCH) # standard install paths PREFIX = /usr/local
Signature · 1 line
1.8.2.1
PATCH 5/9 alfred: Use section garbage collection to reduce binary size
In reply to Sven EckelmannThe linker can identify unused sections of a binary when each symbol is stored in a separate section. This mostly removes the unused debugfs function and reduces the size by ~5% on mipsel.
--- alfred/Makefile | 3 +++ 1 file changed, 3 insertions(+)
alfred/Makefile +3 -0
@@ -44,6 +44,9 @@ endef MAKE_ALFRED_FLAGS=\ CONFIG_ALFRED_VIS=$(if $(CONFIG_PACKAGE_ALFRED_VIS),y,n) +TARGET_CFLAGS += -ffunction-sections -fdata-sections +TARGET_LDFLAGS += -Wl,--gc-sections + define Build/Compile CFLAGS="$(TARGET_CPPFLAGS) $(TARGET_CFLAGS)" \ LDFLAGS="$(TARGET_LDFLAGS)" \
Signature · 1 line
1.8.2.1
Simon Wunderlich
AppliedRe: [B.A.T.M.A.N.] [PATCH 5/9] alfred: Use section garbage collection to reduce binary size
Quoted 8 lines · Sven Eckelmann
The linker can identify unused sections of a binary when each symbol is stored in a separate section. This mostly removes the unused debugfs function and reduces the size by ~5% on mipsel.
Signed-off-by Sven Eckelmann <[email protected]>--- alfred/Makefile | 3 +++ 1 file changed, 3 insertions(+)
Applied in revision fa23641 (alfred package feed).
Thanks,
Simon
PATCH 5/9 batman-adv-devel: Enable Link-time optimization
In reply to Sven EckelmannLink-time optimization allows to move parts of the optimization from the single source file to the global source view. This is done by emitting the GIMPLE representation in each object file and analyzing it again during the link step.
This reduces the binary size by around 6% on mipsel (this includes parts which were also removed by garbage collection).
--- batman-adv-devel/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
batman-adv-devel/Makefile +2 -2
@@ -76,8 +76,8 @@ MAKE_BATCTL_ARGS += \ STRIP="/bin/true" \ batctl install -TARGET_CFLAGS += -ffunction-sections -fdata-sections -TARGET_LDFLAGS += -Wl,--gc-sections +TARGET_CFLAGS += -ffunction-sections -fdata-sections -flto +TARGET_LDFLAGS += -Wl,--gc-sections -fuse-linker-plugin ifneq ($(DEVELOPER)$(CONFIG_KMOD_BATMAN_ADV_DEVEL_BATCTL),) define Download/batctl
Signature · 1 line
1.8.2.1
Marek Lindner
AppliedRe: [B.A.T.M.A.N.] [PATCH 5/9] batman-adv-devel: Enable Link-time optimization
Quoted 5 lines · On Tuesday, May 07, 2013 20:51:09 Sven Eckelmann wrote:
Link-time optimization allows to move parts of the optimization from the single source file to the global source view. This is done by emitting the GIMPLE representation in each object file and analyzing it again during the link step.
Quoted 7 lines
This reduces the binary size by around 6% on mipsel (this includes parts which were also removed by garbage collection).
Signed-off-by Sven Eckelmann <[email protected]>--- batman-adv-devel/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
Applied in revision e25de79.
Thanks,
Marek
PATCH 6/9 alfred: Enable Link-time optimization
In reply to Sven EckelmannLink-time optimization allows to move parts of the optimization from the single source file to the global source view. This is done by emitting the GIMPLE representation in each object file and analyzing it again during the link step.
This reduces the binary size by around 10% on mipsel (this includes parts which were also removed by garbage collection).
--- alfred/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
alfred/Makefile +2 -2
@@ -44,8 +44,8 @@ endef MAKE_ALFRED_FLAGS=\ CONFIG_ALFRED_VIS=$(if $(CONFIG_PACKAGE_ALFRED_VIS),y,n) -TARGET_CFLAGS += -ffunction-sections -fdata-sections -TARGET_LDFLAGS += -Wl,--gc-sections +TARGET_CFLAGS += -ffunction-sections -fdata-sections -flto +TARGET_LDFLAGS += -Wl,--gc-sections -fuse-linker-plugin define Build/Compile CFLAGS="$(TARGET_CPPFLAGS) $(TARGET_CFLAGS)" \
Signature · 1 line
1.8.2.1
Simon Wunderlich
AppliedRe: [B.A.T.M.A.N.] [PATCH 6/9] alfred: Enable Link-time optimization
Quoted 4 lines · Sven Eckelmann
Link-time optimization allows to move parts of the optimization from the single source file to the global source view. This is done by emitting the GIMPLE representation in each object file and analyzing it again during the link step.
Quoted 8 lines
This reduces the binary size by around 10% on mipsel (this includes parts which were also removed by garbage collection).
Signed-off-by Sven Eckelmann <[email protected]>--- alfred/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
Applied in revision bbc581c (alfred package feed).
Thanks,
Simon
PATCH 7/9 batman-adv-devel: Add missing TARGET_* flags to batctl compile
In reply to Sven EckelmannThe compilation step of batctl completely dropped the TARGET_CFLAGS, TARGET_CPPFLAGS and TARGET_LDFLAGS and therefore weren't compiled and linked with the flags given by the OpenWRT build environment.
--- batman-adv-devel/Makefile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
batman-adv-devel/Makefile +3 -1
@@ -85,7 +85,9 @@ $(eval $(call Download,batctl)) BATCTL_EXTRACT = tar xzf "$(DL_DIR)/$(PKG_BATCTL_FNAME)" -C "$(BUILD_DIR)/$(PKG_NAME)" BATCTL_PATCH = $(call Build/DoPatch,"$(PKG_BATCTL_BUILD_DIR)","$(PATCH_DIR)","*batctl*") -BATCTL_BUILD = $(MAKE) -C $(PKG_BATCTL_BUILD_DIR) $(MAKE_BATCTL_ARGS) +BATCTL_BUILD = CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" \ + LDFLAGS="$(TARGET_LDFLAGS)" \ + $(MAKE) -C $(PKG_BATCTL_BUILD_DIR) $(MAKE_BATCTL_ARGS) BATCTL_INSTALL = $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/local/sbin/batctl $(1)/usr/sbin/ endif
Signature · 1 line
1.8.2.1
Re: [B.A.T.M.A.N.] [PATCH 7/9] batman-adv-devel: Add missing TARGET_* flags to batctl compile
Quoted 3 lines · On Tuesday, May 07, 2013 20:51:07 Sven Eckelmann wrote:
The compilation step of batctl completely dropped the
TARGET_CFLAGS,TARGET_CPPFLAGSandTARGET_LDFLAGSand therefore weren't compiled and linked with the flags given by the OpenWRT build environment.
It seems you missed the meaning of MAKE_BATCTL_ARGS ? This variable contains TARGET_CFLAGS already. We apparently are missing TARGET_CPPFLAGS and TARGET_LDFLAGS. Do you want to resend and make the necessary changes to MAKE_BATCTL_ARGS ?
Cheers,
Marek
Re: [B.A.T.M.A.N.] [PATCH 7/9] batman-adv-devel: Add missing TARGET_* flags to batctl compile
Quoted 9 lines · On Wednesday 08 May 2013 13:11:57 Marek Lindner wrote:
Quoted 3 lines · On Tuesday, May 07, 2013 20:51:07 Sven Eckelmann wrote:
The compilation step of batctl completely dropped the
TARGET_CFLAGS,TARGET_CPPFLAGSandTARGET_LDFLAGSand therefore weren't compiled and linked with the flags given by the OpenWRT build environment.It seems you missed the meaning of
MAKE_BATCTL_ARGS? This variable containsTARGET_CFLAGSalready. We apparently are missingTARGET_CPPFLAGSandTARGET_LDFLAGS. Do you want to resend and make the necessary changes toMAKE_BATCTL_ARGS?
I didn't felt like fixing your other problems too, but sent two other patches resolving the MAKE_BATCTL_ARGS problem. See
[Bonus-PATCH 10/9] batman-adv-devel: Don't overwrite batctl's CFLAGS [Bonus-PATCH 11/9] batman-adv-devel: Remove unused parameters from MAKE_BATCTL_ARGS
Kind regards,
Sven
Re: [B.A.T.M.A.N.] [PATCH 7/9] batman-adv-devel: Add missing TARGET_* flags to batctl compile
Quoted 11 lines · On Wednesday, May 08, 2013 15:24:50 Sven Eckelmann wrote:
Quoted 9 lines · On Wednesday 08 May 2013 13:11:57 Marek Lindner wrote:
Quoted 3 lines · On Tuesday, May 07, 2013 20:51:07 Sven Eckelmann wrote:
The compilation step of batctl completely dropped the
TARGET_CFLAGS,TARGET_CPPFLAGSandTARGET_LDFLAGSand therefore weren't compiled and linked with the flags given by the OpenWRT build environment.It seems you missed the meaning of
MAKE_BATCTL_ARGS? This variable containsTARGET_CFLAGSalready. We apparently are missingTARGET_CPPFLAGSandTARGET_LDFLAGS. Do you want to resend and make the necessary changes toMAKE_BATCTL_ARGS?
Quoted 5 lines
I didn't felt like fixing your other problems too, but sent two other patches resolving the
MAKE_BATCTL_ARGSproblem. See [Bonus-PATCH 10/9] batman-adv-devel: Don't overwrite batctl's CFLAGS [Bonus-PATCH 11/9] batman-adv-devel: Remove unused parameters fromMAKE_BATCTL_ARGS
Applied with minor modifications in revision f41a85c.
Thanks for the explanations as to why that is helpful.
Thanks,
Marek
PATCH 8/9 batman-adv-devel: Use section garbage collection to reduce binary size
In reply to Sven EckelmannThe linker can identify unused sections of a binary when each symbol is stored in a separate section. This mostly removes unused linker sections and reduces the size by ~3% on mipsel.
--- batman-adv-devel/Makefile | 3 +++ 1 file changed, 3 insertions(+)
batman-adv-devel/Makefile +3 -0
@@ -76,6 +76,9 @@ MAKE_BATCTL_ARGS += \ STRIP="/bin/true" \ batctl install +TARGET_CFLAGS += -ffunction-sections -fdata-sections +TARGET_LDFLAGS += -Wl,--gc-sections + ifneq ($(DEVELOPER)$(CONFIG_KMOD_BATMAN_ADV_DEVEL_BATCTL),) define Download/batctl FILE:=$(PKG_BATCTL_FNAME)
Signature · 1 line
1.8.2.1
Marek Lindner
AppliedRe: [B.A.T.M.A.N.] [PATCH 8/9] batman-adv-devel: Use section garbage collection to reduce binary size
Quoted 8 lines · On Tuesday, May 07, 2013 20:51:08 Sven Eckelmann wrote:
The linker can identify unused sections of a binary when each symbol is stored in a separate section. This mostly removes unused linker sections and reduces the size by ~3% on mipsel.
Signed-off-by Sven Eckelmann <[email protected]>--- batman-adv-devel/Makefile | 3 +++ 1 file changed, 3 insertions(+)
Applied in revision 3e056f3.
Thanks,
Marek