Skip to content

Commit

Permalink
Added LTO
Browse files Browse the repository at this point in the history
  • Loading branch information
NicoHood authored and abcminiuser committed Dec 31, 2017
1 parent f668c8a commit d5394d5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
4 changes: 4 additions & 0 deletions DMBS/gcc.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ be assumed.
<td>JUMP_TABLES</td>
<td>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`.</td>
</tr>
<tr>
<td>LTO</td>
<td>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`.</td>
</tr>
<tr>
<td>OBJDIR</td>
<td>Directory to store the intermediate object files, as they are generated from the source files. Default is `obj`.</td>
Expand Down
11 changes: 10 additions & 1 deletion DMBS/gcc.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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 +=

Expand All @@ -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)))
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d5394d5

Please sign in to comment.