diff --git a/Makefile b/Makefile index d4a097f72751..157eda2f3043 100644 --- a/Makefile +++ b/Makefile @@ -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 ~) diff --git a/Makefile.main b/Makefile.main index 5656cb72a15d..6a69b65d485d 100644 --- a/Makefile.main +++ b/Makefile.main @@ -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 @@ -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 @@ -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) diff --git a/skiboot.lds.S b/skiboot.lds.S index 7d3d0cf39c21..4a5dabe3c79b 100644 --- a/skiboot.lds.S +++ b/skiboot.lds.S @@ -85,8 +85,8 @@ SECTIONS . = ALIGN(0x10); .init : { __ctors_start = .; - *(.ctors) - *(.init_array) + KEEP(*(.ctors)) + KEEP(*(.init_array)) __ctors_end = .; } @@ -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 */