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
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 sven@narfation.org --- Makefile | 2 +- vis/Makefile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/Makefile b/Makefile index 268a156..aeee2e8 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/vis/Makefile b/vis/Makefile index 5ec0423..8585f9a 100644 --- a/vis/Makefile +++ b/vis/Makefile @@ -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
On Tue, May 07, 2013 at 02:51:01PM +0200, 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 sven@narfation.org
Makefile | 2 +- vis/Makefile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
Applied in revision c693d67.
Thanks, Simon
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 sven@narfation.org --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Makefile b/Makefile index 61b24c6..1961298 100755 --- a/Makefile +++ b/Makefile @@ -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
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 sven@narfation.org
Makefile | 2 +-
Applied in revision b80d07f.
Thanks, Marek
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 sven@narfation.org --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Makefile b/Makefile index ce1e198..721f20b 100755 --- a/Makefile +++ b/Makefile @@ -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
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 sven@narfation.org --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Makefile b/Makefile index c4220f5..0d49c7e 100755 --- a/Makefile +++ b/Makefile @@ -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
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 sven@narfation.org --- alfred/Makefile | 3 +++ 1 file changed, 3 insertions(+)
diff --git a/alfred/Makefile b/alfred/Makefile index 4578c3b..ab19325 100644 --- a/alfred/Makefile +++ b/alfred/Makefile @@ -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)" \
On Tue, May 07, 2013 at 02:51:05PM +0200, Sven Eckelmann wrote:
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 sven@narfation.org
alfred/Makefile | 3 +++ 1 file changed, 3 insertions(+)
Applied in revision fa23641 (alfred package feed).
Thanks, Simon
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.
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 sven@narfation.org --- alfred/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/alfred/Makefile b/alfred/Makefile index ab19325..2656d1c 100644 --- a/alfred/Makefile +++ b/alfred/Makefile @@ -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)" \
On Tue, May 07, 2013 at 02:51:06PM +0200, 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.
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 sven@narfation.org
alfred/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
Applied in revision bbc581c (alfred package feed).
Thanks, Simon
The 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.
Signed-off-by: Sven Eckelmann sven@narfation.org --- batman-adv-devel/Makefile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/batman-adv-devel/Makefile b/batman-adv-devel/Makefile index 0958f38..b9e2650 100644 --- a/batman-adv-devel/Makefile +++ b/batman-adv-devel/Makefile @@ -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
On Tuesday, May 07, 2013 20:51:07 Sven Eckelmann wrote:
The 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.
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
On Wednesday 08 May 2013 13:11:57 Marek Lindner wrote:
On Tuesday, May 07, 2013 20:51:07 Sven Eckelmann wrote:
The 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.
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 ?
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
On Wednesday, May 08, 2013 15:24:50 Sven Eckelmann wrote:
On Wednesday 08 May 2013 13:11:57 Marek Lindner wrote:
On Tuesday, May 07, 2013 20:51:07 Sven Eckelmann wrote:
The 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.
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 ?
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
Applied with minor modifications in revision f41a85c.
Thanks for the explanations as to why that is helpful.
Thanks, Marek
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 sven@narfation.org --- batman-adv-devel/Makefile | 3 +++ 1 file changed, 3 insertions(+)
diff --git a/batman-adv-devel/Makefile b/batman-adv-devel/Makefile index b9e2650..6dc66b8 100644 --- a/batman-adv-devel/Makefile +++ b/batman-adv-devel/Makefile @@ -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)
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 sven@narfation.org
batman-adv-devel/Makefile | 3 +++ 1 file changed, 3 insertions(+)
Applied in revision 3e056f3.
Thanks, Marek
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.
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 sven@narfation.org --- batman-adv-devel/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/batman-adv-devel/Makefile b/batman-adv-devel/Makefile index 6dc66b8..cad95c6 100644 --- a/batman-adv-devel/Makefile +++ b/batman-adv-devel/Makefile @@ -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
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.
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 sven@narfation.org
batman-adv-devel/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
Applied in revision e25de79.
Thanks, Marek
b.a.t.m.a.n@lists.open-mesh.org