From d5394d5f869eb5e440c2747cec9661cf1caf3bd0 Mon Sep 17 00:00:00 2001 From: NicoHood Date: Wed, 23 Aug 2017 20:15:33 +0200 Subject: [PATCH] Added LTO --- DMBS/gcc.md | 4 ++++ DMBS/gcc.mk | 11 ++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/DMBS/gcc.md b/DMBS/gcc.md index d28fd9a..f7f3480 100644 --- a/DMBS/gcc.md +++ b/DMBS/gcc.md @@ -151,6 +151,10 @@ be assumed. JUMP_TABLES Boolean, if `Y` jump tables will be enabled to slightly reduce the resulting binary's size - note that this can cause incorrect jumps if the binary is relocated after compilation, such as for a bootloader. Default is `N`. + + LTO + Boolean, if `Y` link time optimization will be enabled to reduce the resulting binary's size. For larger projects you might also want to add `-mcall-prologues` to the `CC_FLAGS`. Default is `N`. + OBJDIR Directory to store the intermediate object files, as they are generated from the source files. Default is `obj`. diff --git a/DMBS/gcc.mk b/DMBS/gcc.mk index 35ff221..a811139 100644 --- a/DMBS/gcc.mk +++ b/DMBS/gcc.mk @@ -9,7 +9,9 @@ DMBS_BUILD_MODULES += GCC DMBS_BUILD_TARGETS += size symbol-sizes all lib elf bin hex lss clean mostlyclean DMBS_BUILD_MANDATORY_VARS += TARGET ARCH MCU SRC -DMBS_BUILD_OPTIONAL_VARS += COMPILER_PATH OPTIMIZATION C_STANDARD CPP_STANDARD F_CPU C_FLAGS CPP_FLAGS ASM_FLAGS CC_FLAGS LD_FLAGS OBJDIR OBJECT_FILES DEBUG_TYPE DEBUG_LEVEL LINKER_RELAXATIONS JUMP_TABLES +DMBS_BUILD_OPTIONAL_VARS += COMPILER_PATH OPTIMIZATION C_STANDARD CPP_STANDARD F_CPU C_FLAGS +DMBS_BUILD_OPTIONAL_VARS += CPP_FLAGS ASM_FLAGS CC_FLAGS LD_FLAGS OBJDIR OBJECT_FILES DEBUG_TYPE +DMBS_BUILD_OPTIONAL_VARS += DEBUG_LEVEL LINKER_RELAXATIONS JUMP_TABLES LTO DMBS_BUILD_PROVIDED_VARS += DMBS_BUILD_PROVIDED_MACROS += @@ -33,6 +35,7 @@ DEBUG_FORMAT ?= dwarf-2 DEBUG_LEVEL ?= 2 LINKER_RELAXATIONS ?= Y JUMP_TABLES ?= N +LTO ?= N # Sanity check user supplied values $(foreach MANDATORY_VAR, $(DMBS_BUILD_MANDATORY_VARS), $(call ERROR_IF_UNSET, $(MANDATORY_VAR))) @@ -47,6 +50,7 @@ $(call ERROR_IF_EMPTY, DEBUG_FORMAT) $(call ERROR_IF_EMPTY, DEBUG_LEVEL) $(call ERROR_IF_NONBOOL, LINKER_RELAXATIONS) $(call ERROR_IF_NONBOOL, JUMP_TABLES) +$(call ERROR_IF_NONBOOL, LTO) # Determine the utility prefix to use for the selected architecture ifeq ($(ARCH), AVR8) @@ -126,6 +130,11 @@ ifeq ($(JUMP_TABLES), N) # in a pseudo-random jump target. BASE_CC_FLAGS += -fno-jump-tables endif +ifeq ($(LTO), Y) + # Enable link time optimization to reduce overall flash size. + BASE_CC_FLAGS += -flto -fuse-linker-plugin + BASE_LD_FLAGS += -flto -fuse-linker-plugin +endif # Additional language specific compiler flags BASE_C_FLAGS := -x c -O$(OPTIMIZATION) -std=$(C_STANDARD) -Wstrict-prototypes