From 67a39618eb5920aea3bf67b58a0952c87c2703a6 Mon Sep 17 00:00:00 2001 From: Robert Quattlebaum Date: Thu, 17 May 2012 10:27:31 -0700 Subject: [PATCH] cpu/avr: Make sure that GCC removes all unused symbols. This magic comes from the `--gc-sections` linker flag, which turns on garbage collection for unused input sections. The compiler flags `-ffunction-sections` and `-fdata-sections` make sure that each function and each static data definition have their own section. The result is that GCC can prune away all unused symbols, reducing the size of the resulting executable. These optimizations may be disabled by setting the Makefile variable `SMALL` to zero. --- cpu/avr/Makefile.avr | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/cpu/avr/Makefile.avr b/cpu/avr/Makefile.avr index 5325cef6d..264408066 100644 --- a/cpu/avr/Makefile.avr +++ b/cpu/avr/Makefile.avr @@ -106,6 +106,15 @@ endif LDFLAGS += -mmcu=$(MCU) -Wl,-Map=contiki-$(TARGET).map \ -Wl,--section-start=.bootloader=$(BOOTLOADER_START) +SMALL ?= 1 + +### These flags help significantly reduce the code size +ifeq ($(SMALL),1) +CFLAGS += -ffunction-sections +CFLAGS += -fdata-sections +LDFLAGS += -Wl,--gc-sections +endif # SMALL + ### Setup directory search path for source files CONTIKI_TARGET_DIRS_CONCAT = ${addprefix $(CONTIKI)/platform/$(TARGET)/, \