From 63c475cd4da31c2abb522454460b7643d0807c70 Mon Sep 17 00:00:00 2001 From: Juan Carrano Date: Wed, 28 Aug 2019 18:40:38 +0200 Subject: [PATCH] toolchain/cflags: enable dwarf compression. Use the -gz option to compress ELF sections containing DWARF information. This saves around 50% of disk space, without any side effects. See https://gcc.gnu.org/onlinedocs/gcc-9.2.0/gcc/Debugging-Options.html#Debugging-Options for more infomation on this option. Some platforms have an outdated toolchain that does not support -gz so the flag is blacklisted there. Even then, the results are quite impressive. I used @cladmi's `buildtest` branch (https://github.com/cladmi/RIOT/tree/wip/du/buildtest) with this change and compiled the `examples/default` application: ``` $ BUILD_IN_DOCKER=1 DOCKER="sudo docker" make -C examples/default buildtest-indocker ``` The size was obtained with: ``` $ find output -name "*.bin.bindirsize" -type f -exec tail -n1 '{}' \; | cut -f 1 | awk '{s+=$1} END {printf "%.0f", s}' ``` Results: - Vanilla: 10328112 KB (~10GB). - with -gz: 4982788 KB (~5GB). This was inspired by #8496. --- cpu/esp32/Makefile.include | 1 + cpu/esp8266/Makefile.include | 1 + makefiles/arch/atmega.inc.mk | 1 + makefiles/arch/mips.inc.mk | 1 + makefiles/arch/msp430.inc.mk | 1 + makefiles/cflags.inc.mk | 5 +++++ 6 files changed, 10 insertions(+) diff --git a/cpu/esp32/Makefile.include b/cpu/esp32/Makefile.include index 1b2c85c7ff..8b6931d373 100644 --- a/cpu/esp32/Makefile.include +++ b/cpu/esp32/Makefile.include @@ -108,6 +108,7 @@ CFLAGS += -fdata-sections -ffunction-sections -fzero-initialized-in-bss OPTIONAL_CFLAGS_BLACKLIST += -Wformat-overflow OPTIONAL_CFLAGS_BLACKLIST += -Wformat-truncation +OPTIONAL_CFLAGS_BLACKLIST += -gz ASFLAGS += --longcalls --text-section-literals diff --git a/cpu/esp8266/Makefile.include b/cpu/esp8266/Makefile.include index 55915b0e5b..ac38b4a1af 100644 --- a/cpu/esp8266/Makefile.include +++ b/cpu/esp8266/Makefile.include @@ -162,3 +162,4 @@ endif OPTIONAL_CFLAGS_BLACKLIST += -fdiagnostics-color OPTIONAL_CFLAGS_BLACKLIST += -Wformat-overflow OPTIONAL_CFLAGS_BLACKLIST += -Wformat-truncation +OPTIONAL_CFLAGS_BLACKLIST += -gz diff --git a/makefiles/arch/atmega.inc.mk b/makefiles/arch/atmega.inc.mk index 5789a00a1b..0ea8d8609c 100644 --- a/makefiles/arch/atmega.inc.mk +++ b/makefiles/arch/atmega.inc.mk @@ -53,3 +53,4 @@ endif OPTIONAL_CFLAGS_BLACKLIST += -Wformat-overflow OPTIONAL_CFLAGS_BLACKLIST += -Wformat-truncation +OPTIONAL_CFLAGS_BLACKLIST += -gz diff --git a/makefiles/arch/mips.inc.mk b/makefiles/arch/mips.inc.mk index 27053bff0c..4d66af419a 100644 --- a/makefiles/arch/mips.inc.mk +++ b/makefiles/arch/mips.inc.mk @@ -69,3 +69,4 @@ export LINKFLAGS += -Wl,--gc-sections OPTIONAL_CFLAGS_BLACKLIST += -Wformat-overflow OPTIONAL_CFLAGS_BLACKLIST += -Wformat-truncation +OPTIONAL_CFLAGS_BLACKLIST += -gz diff --git a/makefiles/arch/msp430.inc.mk b/makefiles/arch/msp430.inc.mk index 31b75020f9..bf3e1a6d0d 100644 --- a/makefiles/arch/msp430.inc.mk +++ b/makefiles/arch/msp430.inc.mk @@ -18,3 +18,4 @@ export LINKFLAGS += $(CFLAGS_CPU) $(CFLAGS_DBG) $(CFLAGS_OPT) -Wl,--gc-sections OPTIONAL_CFLAGS_BLACKLIST += -fdiagnostics-color OPTIONAL_CFLAGS_BLACKLIST += -Wformat-overflow OPTIONAL_CFLAGS_BLACKLIST += -Wformat-truncation +OPTIONAL_CFLAGS_BLACKLIST += -gz diff --git a/makefiles/cflags.inc.mk b/makefiles/cflags.inc.mk index 96627d22f4..4f1b163963 100644 --- a/makefiles/cflags.inc.mk +++ b/makefiles/cflags.inc.mk @@ -38,6 +38,11 @@ endif # Forbid common symbols to prevent accidental aliasing. CFLAGS += -fno-common +# Compress debug info. This saves approximately 50% of disk usage. +# It has no effect if debugging information is not emitted, so it can be left +# on unconditionally. +OPTIONAL_CFLAGS += -gz + # Enable all default warnings and all extra warnings CFLAGS += -Wall -Wextra # Enable additional checks for printf/scanf format strings