mirror of
https://github.com/ipxe/ipxe
synced 2025-12-20 03:55:46 +03:00
[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>
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user