Makefile: enable LTO

This rearranges Makefile a bit and enables Link Time Optimisation
which leads to a smaller code (77724 text with gcc 4.7.3).

Unconditionally adding -ggdb3 doesn't affect code size anyhow as all
the debugging info is stored in separate sections.

Build-tested only.

Signed-off-by: Paul Fertser <fercerpav@gmail.com>

Conflicts:

	Makefile
This commit is contained in:
Paul Fertser 2014-07-19 22:44:05 +04:00 committed by Dominic Clifton
parent 53623d4d7f
commit f218d3c040
1 changed files with 15 additions and 10 deletions

View File

@ -335,9 +335,21 @@ SIZE = arm-none-eabi-size
# Tool options. # Tool options.
# #
BASE_CFLAGS = $(ARCH_FLAGS) \ ifeq ($(DEBUG),GDB)
OPTIMIZE = -O0
LTO_FLAGS = $(OPTIMIZE)
else
OPTIMIZE = -Os
LTO_FLAGS = -flto -fuse-linker-plugin $(OPTIMIZE)
endif
DEBUG_FLAGS = -ggdb3
CFLAGS = $(ARCH_FLAGS) \
$(LTO_FLAGS) \
$(addprefix -D,$(OPTIONS)) \ $(addprefix -D,$(OPTIONS)) \
$(addprefix -I,$(INCLUDE_DIRS)) \ $(addprefix -I,$(INCLUDE_DIRS)) \
$(DEBUG_FLAGS) \
-Wall \ -Wall \
-ffunction-sections \ -ffunction-sections \
-fdata-sections \ -fdata-sections \
@ -354,6 +366,8 @@ ASFLAGS = $(ARCH_FLAGS) \
# XXX Map/crossref output? # XXX Map/crossref output?
LDFLAGS = -lm \ LDFLAGS = -lm \
$(ARCH_FLAGS) \ $(ARCH_FLAGS) \
$(LTO_FLAGS) \
$(DEBUG_FLAGS) \
-static \ -static \
-Wl,-gc-sections,-Map,$(TARGET_MAP) \ -Wl,-gc-sections,-Map,$(TARGET_MAP) \
-T$(LD_SCRIPT) -T$(LD_SCRIPT)
@ -369,15 +383,6 @@ ifeq ($(filter $(TARGET),$(VALID_TARGETS)),)
$(error Target '$(TARGET)' is not valid, must be one of $(VALID_TARGETS)) $(error Target '$(TARGET)' is not valid, must be one of $(VALID_TARGETS))
endif endif
ifeq ($(DEBUG),GDB)
CFLAGS = $(BASE_CFLAGS) \
-ggdb \
-O0
else
CFLAGS = $(BASE_CFLAGS) \
-Os
endif
TARGET_HEX = $(BIN_DIR)/$(FORKNAME)_$(TARGET).hex TARGET_HEX = $(BIN_DIR)/$(FORKNAME)_$(TARGET).hex
TARGET_ELF = $(OBJECT_DIR)/$(FORKNAME)_$(TARGET).elf TARGET_ELF = $(OBJECT_DIR)/$(FORKNAME)_$(TARGET).elf