Skip to content

Commit

Permalink
Makefile: turn on Link-Time-Optimization (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukefahr authored Oct 10, 2017
1 parent 06b9b7b commit 2c8cdcf
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions platforms/m3/prc_v17/software/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
################################################################################

CFLAGS :=
CLDFLAGS :=
ASFLAGS :=

##########################
Expand All @@ -13,14 +14,13 @@ ASFLAGS :=
#CFLAGS += -Wall -Wextra -Werror -mthumb -mcpu=cortex-m0 -ffreestanding
# Don't care about the warnings not compiling. It's annoying.
CFLAGS += -Os -Wall -Wextra -mthumb -mcpu=cortex-m0 -ffreestanding -fdata-sections -ffunction-sections -g
LDFLAGS += -Os -static -S -nostartfiles --gc-sections -e _start #-dead_strip #-why_live read_mbus_register_RADv4
#LDFLAGS += -Os -static -S -nostartfiles -nodefaultlibs -nostdlib --gc-sections -e _start #-dead_strip #-why_live read_mbus_register_RADv4
# turn on Link-time-optimization
CFLAGS += -flto
CLDFLAGS = -static -nostdlib -Wl,--gc-sections --entry=_start
# no longer usling standard linker, as it can't do LTO, using gcc instead
#LDFLAGS += -Os -static -S -nostartfiles --gc-sections -e _start #-dead_strip #-why_live read_mbus_register_RADv4
ASFLAGS += -mthumb --warn -mcpu=cortex-m0

# Experiments in not linking unused sections
#CFLAGS += -fvtable-gc -fdata-sections -ffunction-sections -Wl,-static -Wl,--gc-sections -s
#LDFLAGS += -nostartfiles -nodefaultlibs -nostdlib

# Attempt to divine ARM toolchain
SHELL=/bin/bash
CROSS_COMPILE=$(shell if `hash arm-linux-gnueabi-gcc >& /dev/null`; then echo arm-linux-gnueabi; elif `hash arm-linux-gnu-gcc >& /dev/null`; then echo arm-linux-gnu; elif `hash arm-none-linux-gnueabi-gcc >& /dev/null`; then echo arm-none-linux-gnueabi; elif `hash arm-none-eabi-gcc >& /dev/null`; then echo arm-none-eabi; else echo -n ""; fi)
Expand Down Expand Up @@ -74,11 +74,13 @@ HEXS := $(foreach var,$(DIRS),$(var)/$(var).hex)
ELFS := $(foreach var,$(DIRS),$(var)/$(var).elf)
LSTS := $(foreach var,$(DIRS),$(var)/$(var).lst)

GCCLIB := $(shell arm-none-eabi-gcc -print-libgcc-file-name | tr -d '\r')

.PRECIOUS: $(LIBS) $(BINS) $(ELFS)

.PHONY: all

all: $(HEXS) $(LSTS)
all: libs/memmap $(HEXS) $(LSTS)

$(DIRS):
$(MAKE) $@/$@.hex
Expand All @@ -103,11 +105,13 @@ $(DIRS):
%.bin: %.elf
$(OBJCOPY) -O binary $< $@

#Uses GCC (not LD) to do the linking to make use of LTO
# Mind the order here to align -T$^
%.elf: COBJ=$(patsubst %.c,%.o,$(wildcard $(dir $@)*.c))
%.elf: SOBJ=$(patsubst %.s,%.o,$(wildcard $(dir $@)*.s))
%.elf: libs/memmap $(LIBS) $$(COBJ) $$(SOBJ)
$(LD) $(LDFLAGS) -T$^ "$$(echo $$(arm-none-eabi-gcc -print-libgcc-file-name) | tr -d '\r')" -o $@
%.elf: $(LIBS) $$(COBJ) $$(SOBJ)
$(CC) $(CFLAGS) $(CLDFLAGS) -Tlibs/memmap \
-Wl,--start-group $^ $(GCCLIB) -Wl,--end-group -o $@
$(OBJDUMP) -Sd $@ > $*.asm

.PRECIOUS: %.elf %.o
Expand Down

0 comments on commit 2c8cdcf

Please sign in to comment.