summaryrefslogtreecommitdiffstats
path: root/src/Makefile.housekeeping
diff options
context:
space:
mode:
authorMichael Brown2011-02-22 20:36:24 +0100
committerMichael Brown2011-02-22 22:02:00 +0100
commit623469de5d307ee6d762ad30988ffbfbc53741b6 (patch)
treec30f937ccd76d6b1f824a126afd331590dda7e32 /src/Makefile.housekeeping
parent[int13] Add missing "static" modifier (diff)
downloadipxe-623469de5d307ee6d762ad30988ffbfbc53741b6.tar.gz
ipxe-623469de5d307ee6d762ad30988ffbfbc53741b6.tar.xz
ipxe-623469de5d307ee6d762ad30988ffbfbc53741b6.zip
[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 <mcb30@ipxe.org>
Diffstat (limited to 'src/Makefile.housekeeping')
-rw-r--r--src/Makefile.housekeeping13
1 files changed, 13 insertions, 0 deletions
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