8000 stm32/Makefile: Enable link-time-optimisation via LTO=1 make option. · alphaFred/micropython@e76d88b · GitHub
[go: up one dir, main page]

Skip to content

Commit e76d88b

Browse files
projectgusdpgeorge
authored andcommitted
stm32/Makefile: Enable link-time-optimisation via LTO=1 make option.
When tested, this reduces default MP binary sizes by approx 2-2.5%, and very marginally increases performance in benchmarks. Build times seem very similar to non-LTO when using gcc 12. See micropython#8733 for further discussion. Signed-off-by: Angus Gratton <gus@projectgus.com>
1 parent 2c01537 commit e76d88b

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

ports/stm32/Makefile

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,22 @@ CFLAGS += -fsingle-precision-constant
9696
endif
9797
endif
9898

99-
LDFLAGS = -nostdlib -L $(LD_DIR) $(addprefix -T,$(LD_FILES)) -Map=$(@:.elf=.map) --cref
100-
LDFLAGS += --defsym=_estack_reserve=8
99+
LDFLAGS = -nostdlib -L $(LD_DIR) $(addprefix -T,$(LD_FILES)) -Wl,-Map=$(@:.elf=.map) -Wl,--cref
100+
LDFLAGS += -Wl,--defsym=_estack_reserve=8
101101
LIBS += "$(shell $(CC) $(CFLAGS) -print-libgcc-file-name)"
102102

103103
# Remove uncalled code from the final image.
104104
CFLAGS += -fdata-sections -ffunction-sections
105-
LDFLAGS += --gc-sections
105+
LDFLAGS += -Wl,--gc-sections
106+
107+
ifeq ($(LTO),1)
108+
CFLAGS += -flto=auto
109+
# LTO requires passing compiler flags to the linker as it will run the assembler.
110+
# To avoid risk of missing something relevant, pass all flags except for preprocessor args
111+
LDFLAGS += $(filter-out -I%,$(filter-out -D%,$(CFLAGS)))
112+
113+
$(BUILD)/stm32_it.o $(BUILD)/pendsv.o: CFLAGS += -fno-lto
114+
endif
106115

107116
# Debugging/Optimization
108117
ifeq ($(DEBUG), 1)
@@ -592,7 +601,7 @@ endef
592601

593602
define GENERATE_ELF
594603
$(ECHO) "LINK $(1)"
595-
$(Q)$(LD) $(LDFLAGS) -o $(1) $(2) $(LDFLAGS_MOD) $(LIBS)
604+
$(Q)$(CC) $(LDFLAGS) -o $(1) $(2) $(LDFLAGS_MOD) $(LIBS)
596605
$(Q)$(SIZE) $(1)
597606
$(if $(filter-out $(TEXT0_ADDR),0x08000000), \
598607
$(ECHO) "INFO: this build requires mboot to be installed first")

0 commit comments

Comments
 (0)
0