Skip to content

Commit 2bec353

Browse files
npigginstewartsmith
authored andcommitted
Dead code and data elimination
Add an experimental option to do basic dead code and data elimintation with -ffunction-sections/-fdata-sections/--gc-sections. This saves about 80kB of text/data. Also remove the use of of -ffunction-sections by default. This predates git history, but I don't think there is a good reason to use it without --gc-sections. The GCC manual says: Only use these options when there are significant benefits from doing so. When you specify these options, the assembler and linker create larger object and executable files and are also slower. You cannot use gprof on all systems if you specify this option, and you may have problems with debugging if you specify both this option and -g. Signed-off-by: Nicholas Piggin <npiggin@gmail.com> Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
1 parent 4ebde13 commit 2bec353

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ STACK_CHECK ?= $(DEBUG)
4444
LITTLE_ENDIAN ?= 0
4545
# ELF v2 ABI is more efficient and compact
4646
ELF_ABI_v2 ?= $(LITTLE_ENDIAN)
47+
# Discard unreferenced code and data at link-time
48+
DEAD_CODE_ELIMINATION ?= 0
4749

4850
#
4951
# Where is the source directory, must be a full path (no ~)

Makefile.main

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ VALGRIND=valgrind -q --show-reachable=yes --error-exitcode=99
4848

4949
# Target options
5050

51-
OPTS=-Os -ffunction-sections
51+
OPTS=-Os
5252
DBG=-g
5353

5454
CPPFLAGS := -I$(SRC)/include -Iinclude -MMD -include $(SRC)/include/config.h
@@ -78,6 +78,10 @@ else
7878
CFLAGS += $(call try-cflag,$(CC),-mabi=elfv1)
7979
endif
8080

81+
ifeq ($(DEAD_CODE_ELIMINATION),1)
82+
CFLAGS += -ffunction-sections -fdata-sections
83+
endif
84+
8185
ifeq ($(SKIBOOT_GCOV),1)
8286
CFLAGS += -fprofile-arcs -ftest-coverage -DSKIBOOT_GCOV=1
8387
endif
@@ -112,6 +116,10 @@ LDRFLAGS=-melf64ppc
112116
# Debug stuff
113117
#LDFLAGS += -Wl,-v -Wl,-Map,foomap
114118

119+
ifeq ($(DEAD_CODE_ELIMINATION),1)
120+
LDFLAGS += -Wl,--gc-sections
121+
endif
122+
115123
AFLAGS := -D__ASSEMBLY__ -mbig-endian -m64
116124
ifeq ($(ELF_ABI_v2),1)
117125
AFLAGS += $(call try-cflag,$(CC),-mabi=elfv2)

skiboot.lds.S

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ SECTIONS
8585
. = ALIGN(0x10);
8686
.init : {
8787
__ctors_start = .;
88-
*(.ctors)
89-
*(.init_array)
88+
KEEP(*(.ctors))
89+
KEEP(*(.init_array))
9090
__ctors_end = .;
9191
}
9292

@@ -143,7 +143,6 @@ SECTIONS
143143
__sym_map_start = . ;
144144
KEEP(*(.sym_map))
145145
__sym_map_end = . ;
146-
KEEP(*(.sym_map))
147146
}
148147

149148
/* We locate the BSS at 2M to leave room for the symbol map */

0 commit comments

Comments
 (0)