Sfoglia il codice sorgente

[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 anni fa
parent
commit
623469de5d

+ 13
- 0
src/Makefile.housekeeping Vedi File

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

+ 6
- 2
src/arch/i386/scripts/i386-kir.lds Vedi File

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

+ 9
- 5
src/arch/i386/scripts/i386.lds Vedi File

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

+ 3
- 1
src/arch/i386/scripts/linux.lds Vedi File

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

+ 3
- 1
src/arch/x86/scripts/efi.lds Vedi File

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

+ 3
- 1
src/arch/x86_64/scripts/linux.lds Vedi File

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

Loading…
Annulla
Salva