Skip to content

Commit

Permalink
Dead code and data elimination
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
npiggin authored and stewartsmith committed Feb 6, 2017
1 parent 4ebde13 commit 2bec353
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
2 changes: 2 additions & 0 deletions Makefile
Expand Up @@ -44,6 +44,8 @@ STACK_CHECK ?= $(DEBUG)
LITTLE_ENDIAN ?= 0
# ELF v2 ABI is more efficient and compact
ELF_ABI_v2 ?= $(LITTLE_ENDIAN)
# Discard unreferenced code and data at link-time
DEAD_CODE_ELIMINATION ?= 0

#
# Where is the source directory, must be a full path (no ~)
Expand Down
10 changes: 9 additions & 1 deletion Makefile.main
Expand Up @@ -48,7 +48,7 @@ VALGRIND=valgrind -q --show-reachable=yes --error-exitcode=99

# Target options

OPTS=-Os -ffunction-sections
OPTS=-Os
DBG=-g

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

ifeq ($(DEAD_CODE_ELIMINATION),1)
CFLAGS += -ffunction-sections -fdata-sections
endif

ifeq ($(SKIBOOT_GCOV),1)
CFLAGS += -fprofile-arcs -ftest-coverage -DSKIBOOT_GCOV=1
endif
Expand Down Expand Up @@ -112,6 +116,10 @@ LDRFLAGS=-melf64ppc
# Debug stuff
#LDFLAGS += -Wl,-v -Wl,-Map,foomap

ifeq ($(DEAD_CODE_ELIMINATION),1)
LDFLAGS += -Wl,--gc-sections
endif

AFLAGS := -D__ASSEMBLY__ -mbig-endian -m64
ifeq ($(ELF_ABI_v2),1)
AFLAGS += $(call try-cflag,$(CC),-mabi=elfv2)
Expand Down
5 changes: 2 additions & 3 deletions skiboot.lds.S
Expand Up @@ -85,8 +85,8 @@ SECTIONS
. = ALIGN(0x10);
.init : {
__ctors_start = .;
*(.ctors)
*(.init_array)
KEEP(*(.ctors))
KEEP(*(.init_array))
__ctors_end = .;
}

Expand Down Expand Up @@ -143,7 +143,6 @@ SECTIONS
__sym_map_start = . ;
KEEP(*(.sym_map))
__sym_map_end = . ;
KEEP(*(.sym_map))
}

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

0 comments on commit 2bec353

Please sign in to comment.