From 623469de5d307ee6d762ad30988ffbfbc53741b6 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Tue, 22 Feb 2011 19:36:24 +0000 Subject: [build] Eliminate unused sections at link-time Use -ffunction-sections, -fdata-sections, and --gc-sections to automatically prune out any unreferenced sections. This saves around 744 bytes (uncompressed) from the rtl8139.rom build. Signed-off-by: Michael Brown --- src/Makefile.housekeeping | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/Makefile.housekeeping') diff --git a/src/Makefile.housekeeping b/src/Makefile.housekeeping index d18b65cc..c4350671 100644 --- a/src/Makefile.housekeeping +++ b/src/Makefile.housekeeping @@ -415,6 +415,19 @@ CFLAGS += -finstrument-functions CFLAGS += -finstrument-functions-exclude-file-list=core/fnrec.c endif +# Enable per-item sections and section garbage collection. Note that +# some older versions of gcc support -fdata-sections but treat it as +# implying -fno-common, which would break our build. +# +ifeq ($(CCTYPE),gcc) +DS_TEST = $(ECHO) 'char x;' | \ + $(CC) -fdata-sections -S -x c - -o - 2>/dev/null | \ + grep -E '\.comm' > /dev/null +DS_FLAGS := $(shell $(DS_TEST) && $(ECHO) '-fdata-sections') +CFLAGS += -ffunction-sections $(DS_FLAGS) +endif +LDFLAGS += --gc-sections + # compiler.h is needed for our linking and debugging system # CFLAGS += -include compiler.h -- cgit v1.2.3-55-g7522