瀏覽代碼

[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>
tags/v1.20.1
Michael Brown 13 年之前
父節點
當前提交
623469de5d

+ 13
- 0
src/Makefile.housekeeping 查看文件

415
 CFLAGS		+= -finstrument-functions-exclude-file-list=core/fnrec.c
415
 CFLAGS		+= -finstrument-functions-exclude-file-list=core/fnrec.c
416
 endif
416
 endif
417
 
417
 
418
+# Enable per-item sections and section garbage collection.  Note that
419
+# some older versions of gcc support -fdata-sections but treat it as
420
+# implying -fno-common, which would break our build.
421
+#
422
+ifeq ($(CCTYPE),gcc)
423
+DS_TEST		= $(ECHO) 'char x;' | \
424
+		  $(CC) -fdata-sections -S -x c - -o - 2>/dev/null | \
425
+		  grep -E '\.comm' > /dev/null
426
+DS_FLAGS	:= $(shell $(DS_TEST) && $(ECHO) '-fdata-sections')
427
+CFLAGS		+= -ffunction-sections $(DS_FLAGS)
428
+endif
429
+LDFLAGS		+= --gc-sections
430
+
418
 # compiler.h is needed for our linking and debugging system
431
 # compiler.h is needed for our linking and debugging system
419
 #
432
 #
420
 CFLAGS		+= -include compiler.h
433
 CFLAGS		+= -include compiler.h

+ 6
- 2
src/arch/i386/scripts/i386-kir.lds 查看文件

68
 
68
 
69
     .text16 : AT ( _text16_load_offset + __text16 ) {
69
     .text16 : AT ( _text16_load_offset + __text16 ) {
70
 	__text16 = .;
70
 	__text16 = .;
71
-	*(.text.null_trap)
71
+	KEEP(*(.text.null_trap))
72
+	KEEP(*(.text.null_trap.*))
72
 	*(.text16)
73
 	*(.text16)
73
 	*(.text16.*)
74
 	*(.text16.*)
74
 	*(.text)
75
 	*(.text)
97
 	*(.data16.*)
98
 	*(.data16.*)
98
 	*(.data)
99
 	*(.data)
99
 	*(.data.*)
100
 	*(.data.*)
100
-	*(SORT(.tbl.*))		/* Various tables.  See include/tables.h */
101
+	KEEP(*(SORT(.tbl.*)))	/* Various tables.  See include/tables.h */
101
 	_edata16_progbits = .;
102
 	_edata16_progbits = .;
102
     }
103
     }
103
     .bss16 : AT ( _data16_load_offset + __bss16 ) {
104
     .bss16 : AT ( _data16_load_offset + __bss16 ) {
129
 
130
 
130
     /DISCARD/ : {
131
     /DISCARD/ : {
131
 	*(.comment)
132
 	*(.comment)
133
+	*(.comment.*)
132
 	*(.note)
134
 	*(.note)
135
+	*(.note.*)
133
 	*(.discard)
136
 	*(.discard)
137
+	*(.discard.*)
134
     }
138
     }
135
 
139
 
136
     /*
140
     /*

+ 9
- 5
src/arch/i386/scripts/i386.lds 查看文件

49
 
49
 
50
     .text16.early 0x0 : AT ( _text16_early_lma ) {
50
     .text16.early 0x0 : AT ( _text16_early_lma ) {
51
 	_text16 = .;
51
 	_text16 = .;
52
-	*(.text16.null)
52
+	KEEP(*(.text16.null))
53
+	KEEP(*(.text16.null.*))
53
 	. += 1;				/* Prevent NULL being valid */
54
 	. += 1;				/* Prevent NULL being valid */
54
 	*(.text16.early)
55
 	*(.text16.early)
55
 	*(.text16.early.*)
56
 	*(.text16.early.*)
98
 
99
 
99
     .textdata 0x0 : AT ( _textdata_lma ) {
100
     .textdata 0x0 : AT ( _textdata_lma ) {
100
 	_textdata = .;
101
 	_textdata = .;
101
-	*(.text.null_trap)
102
+	KEEP(*(.text.null_trap))
103
+	KEEP(*(.text.null_trap.*))
102
 	. += 1;				/* Prevent NULL being valid */
104
 	. += 1;				/* Prevent NULL being valid */
103
 	*(.text)
105
 	*(.text)
104
 	*(.text.*)
106
 	*(.text.*)
106
 	*(.rodata.*)
108
 	*(.rodata.*)
107
 	*(.data)
109
 	*(.data)
108
 	*(.data.*)
110
 	*(.data.*)
109
-	*(SORT(.tbl.*))		/* Various tables.  See include/tables.h */
111
+	KEEP(*(SORT(.tbl.*)))	/* Various tables.  See include/tables.h */
110
 	_mtextdata = .;
112
 	_mtextdata = .;
111
     } .bss.textdata (NOLOAD) : AT ( _end_lma ) {
113
     } .bss.textdata (NOLOAD) : AT ( _end_lma ) {
112
 	*(.bss)
114
 	*(.bss)
126
 
128
 
127
     .zinfo 0x0 : AT ( _zinfo_lma ) {
129
     .zinfo 0x0 : AT ( _zinfo_lma ) {
128
 	_zinfo = .;
130
 	_zinfo = .;
129
-	*(.zinfo)
130
-	*(.zinfo.*)
131
+	KEEP(*(.zinfo))
132
+	KEEP(*(.zinfo.*))
131
 	_mzinfo = .;
133
 	_mzinfo = .;
132
     } .bss.zinfo (NOLOAD) : AT ( _end_lma ) {
134
     } .bss.zinfo (NOLOAD) : AT ( _end_lma ) {
133
 	_ezinfo = .;
135
 	_ezinfo = .;
143
     .weak 0x0 : AT ( _end_lma ) {
145
     .weak 0x0 : AT ( _end_lma ) {
144
 	_weak = .;
146
 	_weak = .;
145
 	*(.weak)
147
 	*(.weak)
148
+	*(.weak.*)
146
 	_eweak = .;
149
 	_eweak = .;
147
     }
150
     }
148
     _assert = ASSERT ( ( _weak == _eweak ), ".weak is non-zero length" );
151
     _assert = ASSERT ( ( _weak == _eweak ), ".weak is non-zero length" );
165
 	*(.einfo)
168
 	*(.einfo)
166
 	*(.einfo.*)
169
 	*(.einfo.*)
167
 	*(.discard)
170
 	*(.discard)
171
+	*(.discard.*)
168
     }
172
     }
169
 
173
 
170
     /*
174
     /*

+ 3
- 1
src/arch/i386/scripts/linux.lds 查看文件

51
 		_data = .;
51
 		_data = .;
52
 		*(.data)
52
 		*(.data)
53
 		*(.data.*)
53
 		*(.data.*)
54
-		*(SORT(.tbl.*))		/* Various tables.  See include/tables.h */
54
+		KEEP(*(SORT(.tbl.*)))
55
 		_edata = .;
55
 		_edata = .;
56
 	}
56
 	}
57
 
57
 
77
 	.weak 0x0 : {
77
 	.weak 0x0 : {
78
 		_weak = .;
78
 		_weak = .;
79
 		*(.weak)
79
 		*(.weak)
80
+		*(.weak.*)
80
 		_eweak = .;
81
 		_eweak = .;
81
 	}
82
 	}
82
 	_assert = ASSERT ( ( _weak == _eweak ), ".weak is non-zero length" );
83
 	_assert = ASSERT ( ( _weak == _eweak ), ".weak is non-zero length" );
97
 		*(.rel)
98
 		*(.rel)
98
 		*(.rel.*)
99
 		*(.rel.*)
99
 		*(.discard)
100
 		*(.discard)
101
+		*(.discard.*)
100
 	}
102
 	}
101
 }
103
 }

+ 3
- 1
src/arch/x86/scripts/efi.lds 查看文件

54
 	_data = .;
54
 	_data = .;
55
 	*(.data)
55
 	*(.data)
56
 	*(.data.*)
56
 	*(.data.*)
57
-	*(SORT(.tbl.*))		/* Various tables.  See include/tables.h */
57
+	KEEP(*(SORT(.tbl.*)))	/* Various tables.  See include/tables.h */
58
 	_edata = .;
58
 	_edata = .;
59
     }
59
     }
60
 
60
 
80
     .weak 0x0 : {
80
     .weak 0x0 : {
81
 	_weak = .;
81
 	_weak = .;
82
 	*(.weak)
82
 	*(.weak)
83
+	*(.weak.*)
83
 	_eweak = .;
84
 	_eweak = .;
84
     }
85
     }
85
     _assert = ASSERT ( ( _weak == _eweak ), ".weak is non-zero length" );
86
     _assert = ASSERT ( ( _weak == _eweak ), ".weak is non-zero length" );
102
 	*(.einfo)
103
 	*(.einfo)
103
 	*(.einfo.*)
104
 	*(.einfo.*)
104
 	*(.discard)
105
 	*(.discard)
106
+	*(.discard.*)
105
     }
107
     }
106
 }
108
 }

+ 3
- 1
src/arch/x86_64/scripts/linux.lds 查看文件

51
 		_data = .;
51
 		_data = .;
52
 		*(.data)
52
 		*(.data)
53
 		*(.data.*)
53
 		*(.data.*)
54
-		*(SORT(.tbl.*))		/* Various tables.  See include/tables.h */
54
+		KEEP(*(SORT(.tbl.*)))
55
 		_edata = .;
55
 		_edata = .;
56
 	}
56
 	}
57
 
57
 
77
 	.weak 0x0 : {
77
 	.weak 0x0 : {
78
 		_weak = .;
78
 		_weak = .;
79
 		*(.weak)
79
 		*(.weak)
80
+		*(.weak.*)
80
 		_eweak = .;
81
 		_eweak = .;
81
 	}
82
 	}
82
 	_assert = ASSERT ( ( _weak == _eweak ), ".weak is non-zero length" );
83
 	_assert = ASSERT ( ( _weak == _eweak ), ".weak is non-zero length" );
97
 		*(.rel)
98
 		*(.rel)
98
 		*(.rel.*)
99
 		*(.rel.*)
99
 		*(.discard)
100
 		*(.discard)
101
+		*(.discard.*)
100
 	}
102
 	}
101
 }
103
 }

Loading…
取消
儲存