david/ipxe
david
/
ipxe
Archived
1
0
Fork 0

[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:
Michael Brown 2011-02-22 19:36:24 +00:00
parent f3c72660a7
commit 623469de5d
6 changed files with 37 additions and 10 deletions

View File

@ -415,6 +415,19 @@ CFLAGS += -finstrument-functions
CFLAGS += -finstrument-functions-exclude-file-list=core/fnrec.c CFLAGS += -finstrument-functions-exclude-file-list=core/fnrec.c
endif 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 # compiler.h is needed for our linking and debugging system
# #
CFLAGS += -include compiler.h CFLAGS += -include compiler.h

View File

@ -68,7 +68,8 @@ SECTIONS {
.text16 : AT ( _text16_load_offset + __text16 ) { .text16 : AT ( _text16_load_offset + __text16 ) {
__text16 = .; __text16 = .;
*(.text.null_trap) KEEP(*(.text.null_trap))
KEEP(*(.text.null_trap.*))
*(.text16) *(.text16)
*(.text16.*) *(.text16.*)
*(.text) *(.text)
@ -97,7 +98,7 @@ SECTIONS {
*(.data16.*) *(.data16.*)
*(.data) *(.data)
*(.data.*) *(.data.*)
*(SORT(.tbl.*)) /* Various tables. See include/tables.h */ KEEP(*(SORT(.tbl.*))) /* Various tables. See include/tables.h */
_edata16_progbits = .; _edata16_progbits = .;
} }
.bss16 : AT ( _data16_load_offset + __bss16 ) { .bss16 : AT ( _data16_load_offset + __bss16 ) {
@ -129,8 +130,11 @@ SECTIONS {
/DISCARD/ : { /DISCARD/ : {
*(.comment) *(.comment)
*(.comment.*)
*(.note) *(.note)
*(.note.*)
*(.discard) *(.discard)
*(.discard.*)
} }
/* /*

View File

@ -49,7 +49,8 @@ SECTIONS {
.text16.early 0x0 : AT ( _text16_early_lma ) { .text16.early 0x0 : AT ( _text16_early_lma ) {
_text16 = .; _text16 = .;
*(.text16.null) KEEP(*(.text16.null))
KEEP(*(.text16.null.*))
. += 1; /* Prevent NULL being valid */ . += 1; /* Prevent NULL being valid */
*(.text16.early) *(.text16.early)
*(.text16.early.*) *(.text16.early.*)
@ -98,7 +99,8 @@ SECTIONS {
.textdata 0x0 : AT ( _textdata_lma ) { .textdata 0x0 : AT ( _textdata_lma ) {
_textdata = .; _textdata = .;
*(.text.null_trap) KEEP(*(.text.null_trap))
KEEP(*(.text.null_trap.*))
. += 1; /* Prevent NULL being valid */ . += 1; /* Prevent NULL being valid */
*(.text) *(.text)
*(.text.*) *(.text.*)
@ -106,7 +108,7 @@ SECTIONS {
*(.rodata.*) *(.rodata.*)
*(.data) *(.data)
*(.data.*) *(.data.*)
*(SORT(.tbl.*)) /* Various tables. See include/tables.h */ KEEP(*(SORT(.tbl.*))) /* Various tables. See include/tables.h */
_mtextdata = .; _mtextdata = .;
} .bss.textdata (NOLOAD) : AT ( _end_lma ) { } .bss.textdata (NOLOAD) : AT ( _end_lma ) {
*(.bss) *(.bss)
@ -126,8 +128,8 @@ SECTIONS {
.zinfo 0x0 : AT ( _zinfo_lma ) { .zinfo 0x0 : AT ( _zinfo_lma ) {
_zinfo = .; _zinfo = .;
*(.zinfo) KEEP(*(.zinfo))
*(.zinfo.*) KEEP(*(.zinfo.*))
_mzinfo = .; _mzinfo = .;
} .bss.zinfo (NOLOAD) : AT ( _end_lma ) { } .bss.zinfo (NOLOAD) : AT ( _end_lma ) {
_ezinfo = .; _ezinfo = .;
@ -143,6 +145,7 @@ SECTIONS {
.weak 0x0 : AT ( _end_lma ) { .weak 0x0 : AT ( _end_lma ) {
_weak = .; _weak = .;
*(.weak) *(.weak)
*(.weak.*)
_eweak = .; _eweak = .;
} }
_assert = ASSERT ( ( _weak == _eweak ), ".weak is non-zero length" ); _assert = ASSERT ( ( _weak == _eweak ), ".weak is non-zero length" );
@ -165,6 +168,7 @@ SECTIONS {
*(.einfo) *(.einfo)
*(.einfo.*) *(.einfo.*)
*(.discard) *(.discard)
*(.discard.*)
} }
/* /*

View File

@ -51,7 +51,7 @@ SECTIONS {
_data = .; _data = .;
*(.data) *(.data)
*(.data.*) *(.data.*)
*(SORT(.tbl.*)) /* Various tables. See include/tables.h */ KEEP(*(SORT(.tbl.*)))
_edata = .; _edata = .;
} }
@ -77,6 +77,7 @@ SECTIONS {
.weak 0x0 : { .weak 0x0 : {
_weak = .; _weak = .;
*(.weak) *(.weak)
*(.weak.*)
_eweak = .; _eweak = .;
} }
_assert = ASSERT ( ( _weak == _eweak ), ".weak is non-zero length" ); _assert = ASSERT ( ( _weak == _eweak ), ".weak is non-zero length" );
@ -97,5 +98,6 @@ SECTIONS {
*(.rel) *(.rel)
*(.rel.*) *(.rel.*)
*(.discard) *(.discard)
*(.discard.*)
} }
} }

View File

@ -54,7 +54,7 @@ SECTIONS {
_data = .; _data = .;
*(.data) *(.data)
*(.data.*) *(.data.*)
*(SORT(.tbl.*)) /* Various tables. See include/tables.h */ KEEP(*(SORT(.tbl.*))) /* Various tables. See include/tables.h */
_edata = .; _edata = .;
} }
@ -80,6 +80,7 @@ SECTIONS {
.weak 0x0 : { .weak 0x0 : {
_weak = .; _weak = .;
*(.weak) *(.weak)
*(.weak.*)
_eweak = .; _eweak = .;
} }
_assert = ASSERT ( ( _weak == _eweak ), ".weak is non-zero length" ); _assert = ASSERT ( ( _weak == _eweak ), ".weak is non-zero length" );
@ -102,5 +103,6 @@ SECTIONS {
*(.einfo) *(.einfo)
*(.einfo.*) *(.einfo.*)
*(.discard) *(.discard)
*(.discard.*)
} }
} }

View File

@ -51,7 +51,7 @@ SECTIONS {
_data = .; _data = .;
*(.data) *(.data)
*(.data.*) *(.data.*)
*(SORT(.tbl.*)) /* Various tables. See include/tables.h */ KEEP(*(SORT(.tbl.*)))
_edata = .; _edata = .;
} }
@ -77,6 +77,7 @@ SECTIONS {
.weak 0x0 : { .weak 0x0 : {
_weak = .; _weak = .;
*(.weak) *(.weak)
*(.weak.*)
_eweak = .; _eweak = .;
} }
_assert = ASSERT ( ( _weak == _eweak ), ".weak is non-zero length" ); _assert = ASSERT ( ( _weak == _eweak ), ".weak is non-zero length" );
@ -97,5 +98,6 @@ SECTIONS {
*(.rel) *(.rel)
*(.rel.*) *(.rel.*)
*(.discard) *(.discard)
*(.discard.*)
} }
} }