From 986c78f448780feab4e97f7884c8e1949a848f65 Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Thu, 27 Aug 2015 16:47:38 +1000 Subject: [PATCH] Compile with -ffunction-sectons -fdata-sections, link with -gc-sections This seems to shrink code size by abou 3.5%. Not sure if there are any downsides. --- common.mk | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/common.mk b/common.mk index 323d13d..3a0e691 100644 --- a/common.mk +++ b/common.mk @@ -94,9 +94,19 @@ OWN_LIBC ?= 1 # Note: you will need a recent esp ENTRY_SYMBOL ?= call_user_start +# Set this to zero if you don't want individual function & data sections +# (some code may be slightly slower, linking will be slighty slower, +# but compiled code size will come down a small amount.) +SPLIT_SECTIONS ?= 1 + CFLAGS = -Wall -Werror -Wl,-EL -nostdlib -mlongcalls -mtext-section-literals -std=gnu99 $(CPPFLAGS) LDFLAGS = -nostdlib -Wl,--no-check-sections -Wl,-L$(BUILD_DIR)sdklib -Wl,-L$(ROOT)lib -u $(ENTRY_SYMBOL) -Wl,-static -Wl,-Map=build/${PROGRAM}.map $(EXTRA_LDFLAGS) +ifeq ($(SPLIT_SECTIONS),1) + CFLAGS += -ffunction-sections -fdata-sections + LDFLAGS += -Wl,-gc-sections +endif + ifeq ($(FLAVOR),debug) CFLAGS += -g -O0 LDFLAGS += -g -O0